Added new fundamental filter 'xslt'. This filter reads XML records
[idzebra-moved-to-github.git] / include / idzebra / recctrl.h
1 /* $Id: recctrl.h,v 1.10 2005-04-28 08:20:39 adam Exp $
2    Copyright (C) 1995-2005
3    Index Data ApS
4
5 This file is part of the Zebra server.
6
7 Zebra is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
10 version.
11
12 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15 for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with Zebra; see the file LICENSE.zebra.  If not, write to the
19 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA.
21 */
22
23 #ifndef RECCTRL_H
24 #define RECCTRL_H
25
26 #include <sys/types.h>
27 #include <yaz/proto.h>
28 #include <yaz/oid.h>
29 #include <yaz/odr.h>
30 #include <idzebra/res.h>
31 #include <idzebra/data1.h>
32 #include <idzebra/zebramap.h>
33
34 YAZ_BEGIN_CDECL
35
36 /* single word entity */
37 typedef struct {
38     int  attrSet;
39     int  attrUse;
40     unsigned reg_type;
41     char *attrStr;
42     char *term_buf;
43     int  term_len;
44     zint seqno;
45     zint record_id;
46     zint section_id;
47     ZebraMaps zebra_maps;
48     struct recExtractCtrl *extractCtrl;
49 } RecWord;
50
51 /* Extract record control */
52 struct recExtractCtrl {
53     void      *fh;                    /* File handle and read function     */
54     int       (*readf)(void *fh, char *buf, size_t count);
55     off_t     (*seekf)(void *fh, off_t offset);  /* seek function          */
56     off_t     (*tellf)(void *fh);                /* tell function          */
57     void      (*endf)(void *fh, off_t offset);   /* end of record position */
58     off_t     offset;                            /* start offset           */
59     void      (*init)(struct recExtractCtrl *p, RecWord *w);
60     void      *clientData;
61     void      (*tokenAdd)(RecWord *w);
62     void      (*setStoreData)(struct recExtractCtrl *p, void *buf, size_t size);
63     ZebraMaps zebra_maps;
64     int       first_record;
65     int       flagShowRecords;
66     int       seqno[256];
67     char      match_criteria[256];
68     void      (*schemaAdd)(struct recExtractCtrl *p, Odr_oid *oid);
69     data1_handle dh;
70     void      *handle;
71 };
72
73 /* Retrieve record control */
74 struct recRetrieveCtrl {
75     /* Input parameters ... */
76     Res       res;                    /* Resource pool                     */
77     ODR       odr;                    /* ODR used to create response       */
78     void     *fh;                     /* File descriptor and read function */
79     int       (*readf)(void *fh, char *buf, size_t count);
80     off_t     (*seekf)(void *fh, off_t offset);
81     off_t     (*tellf)(void *fh);
82     oid_value input_format;           /* Preferred record syntax           */
83     Z_RecordComposition *comp;        /* formatting instructions           */
84     char      *encoding;              /* preferred character encoding      */
85     zint      localno;                /* local id of record                */
86     int       score;                  /* score 0-1000 or -1 if none        */
87     int       recordSize;             /* size of record in bytes */
88     char      *fname;                 /* name of file (or NULL if internal) */
89     data1_handle dh;
90     
91     /* response */
92     oid_value  output_format;
93     void       *rec_buf;
94     int        rec_len;
95     int        diagnostic;
96     char       *addinfo;
97 };
98
99 typedef struct recType *RecType;
100
101 struct recType
102 {
103     int version;
104     char *name;                           /* Name of record type */
105     void *(*init)(Res res, RecType recType);  /* Init function - called once */
106     void (*config)(void *clientData, Res res, const char *args); /* Config */
107     void (*destroy)(void *clientData);    /* Destroy function */
108     int  (*extract)(void *clientData,
109                     struct recExtractCtrl *ctrl);   /* Extract proc */
110     int  (*retrieve)(void *clientData,
111                      struct recRetrieveCtrl *ctrl); /* Retrieve proc */
112 };
113
114 #define RECCTRL_EXTRACT_OK    0
115 #define RECCTRL_EXTRACT_EOF   1
116 #define RECCTRL_EXTRACT_ERROR_GENERIC 2
117 #define RECCTRL_EXTRACT_ERROR_NO_SUCH_FILTER 3
118
119 typedef struct recTypeClass *RecTypeClass;
120 typedef struct recTypes *RecTypes;
121
122 YAZ_EXPORT
123 RecTypeClass recTypeClass_create (Res res, NMEM nmem);
124
125 YAZ_EXPORT
126 void recTypeClass_destroy(RecTypeClass rtc);
127
128 YAZ_EXPORT
129 void recTypeClass_info(RecTypeClass rtc, void *cd,
130                        void (*cb)(void *cd, const char *s));
131
132 YAZ_EXPORT
133 RecTypes recTypes_init(RecTypeClass rtc, data1_handle dh);
134
135 YAZ_EXPORT
136 void recTypes_destroy(RecTypes recTypes);
137
138 YAZ_EXPORT
139 void recTypes_default_handlers(RecTypes recTypes, Res res);
140
141 YAZ_EXPORT
142 RecType recType_byName(RecTypes rts, Res res, const char *name,
143                        void **clientDataP);
144
145
146 YAZ_END_CDECL
147
148 #endif