Reformat: delete trailing whitespace
[idzebra-moved-to-github.git] / include / idzebra / recctrl.h
1 /* This file is part of the Zebra server.
2    Copyright (C) 1994-2011 Index Data
3
4 Zebra is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
7 version.
8
9 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17
18 */
19
20 #ifndef IDZEBRA_RECCTRL_H
21 #define IDZEBRA_RECCTRL_H
22
23 #include <sys/types.h>
24 #include <yaz/proto.h>
25 #include <yaz/odr.h>
26 #include <idzebra/res.h>
27 #include <idzebra/data1.h>
28 #include <idzebra/snippet.h>
29
30 YAZ_BEGIN_CDECL
31
32 /* 1 */
33 #define ZEBRA_XPATH_ELM_BEGIN "_XPATH_BEGIN"
34
35 /* 2 */
36 #define ZEBRA_XPATH_ELM_END   "_XPATH_END"
37
38 /* 1016 */
39 #define ZEBRA_XPATH_CDATA     "_XPATH_CDATA"
40
41 /* 3 */
42 #define ZEBRA_XPATH_ATTR_NAME       "_XPATH_ATTR_NAME"
43
44 /* 1015 */
45 #define ZEBRA_XPATH_ATTR_CDATA      "_XPATH_ATTR_CDATA"
46
47 /** Indexing token */
48 typedef struct {
49     /** index type, e.g. "w", "p", .. */
50     const char *index_type;
51     /** index name, e.g. "title" */
52     const char *index_name;
53     /** token char data */
54     const char *term_buf;
55     /** length of term_buf */
56     int  term_len;
57     /** sequence number */
58     zint seqno;
59     /** segment number */
60     zint segment;
61     /** record ID */
62     zint record_id;
63     /** section ID */
64     zint section_id;
65     struct recExtractCtrl *extractCtrl;
66 } RecWord;
67
68 /** \brief record reader stream */
69 struct ZebraRecStream {
70     /** client data */
71     void      *fh;
72     /** \brief read function */
73     int       (*readf)(struct ZebraRecStream *s, char *buf, size_t count);
74     /** \brief seek function */
75     off_t     (*seekf)(struct ZebraRecStream *s, off_t offset);
76     /** \brief tell function */
77     off_t     (*tellf)(struct ZebraRecStream *s);
78     /** \brief set and get of record position */
79     off_t     (*endf)(struct ZebraRecStream *s, off_t *offset);
80     /** \brief close and destroy stream */
81     void      (*destroy)(struct ZebraRecStream *s);
82 };
83
84 /** record update action */
85 enum zebra_recctrl_action_t {
86     /** insert record (fail if it exists already) */
87     action_insert = 1,
88     /** replace record (fail it it does not exist) */
89     action_replace,
90     /** delete record (fail if it does not exist) */
91     action_delete,
92     /** insert or replace */
93     action_update,
94     /** delete record (ignore if it does not exist) */
95     action_a_delete
96 };
97
98 /** \brief record extract for indexing */
99 struct recExtractCtrl {
100     struct ZebraRecStream *stream;
101     void      (*init)(struct recExtractCtrl *p, RecWord *w);
102     void      *clientData;
103     void      (*tokenAdd)(RecWord *w);
104     void      (*setStoreData)(struct recExtractCtrl *p, void *buf, size_t size);
105     int       first_record;
106     int       flagShowRecords;
107     char      match_criteria[256];
108     zint      staticrank;
109     void      (*schemaAdd)(struct recExtractCtrl *p, Odr_oid *oid);
110     data1_handle dh;
111     void      *handle;
112     enum zebra_recctrl_action_t action;
113 };
114
115 /* Retrieve record control */
116 struct recRetrieveCtrl {
117     struct ZebraRecStream *stream;
118     /* Input parameters ... */
119     Res       res;                    /* Resource pool                     */
120     ODR       odr;                    /* ODR used to create response       */
121     const Odr_oid * input_format;     /* Preferred record syntax OID       */
122     Z_RecordComposition *comp;        /* formatting instructions           */
123     char      *encoding;              /* preferred character encoding      */
124     zint      localno;                /* local id of record                */
125     int       score;                  /* score 0-1000 or -1 if none        */
126     zint      staticrank;             /* static rank >= 0,  0 if none */
127     int       recordSize;             /* size of record in bytes */
128     char      *fname;                 /* name of file (or NULL if internal) */
129     data1_handle dh;
130
131     /* response */
132     const Odr_oid * output_format;    /* output format OID */
133     void *     rec_buf;
134     int        rec_len;
135     int        diagnostic;
136     char *     addinfo;
137
138     /* special fetch to be included in retrieved response (say snippets) */
139     void *handle;
140     int (*special_fetch)(void *handle, const char *esn,
141                          const Odr_oid *input_format,
142                          const Odr_oid **output_format,
143                          WRBUF result, WRBUF addinfo);
144 };
145
146 typedef struct recType *RecType;
147
148 struct recType
149 {
150     int version;
151     char *name;                           /* Name of record type */
152     void *(*init)(Res res, RecType recType);  /* Init function - called once */
153     ZEBRA_RES (*config)(void *clientData, Res res, const char *args); /* Config */
154     void (*destroy)(void *clientData);    /* Destroy function */
155     int  (*extract)(void *clientData,
156                     struct recExtractCtrl *ctrl);   /* Extract proc */
157     int  (*retrieve)(void *clientData,
158                      struct recRetrieveCtrl *ctrl); /* Retrieve proc */
159 };
160
161 #define RECCTRL_EXTRACT_OK    0
162 #define RECCTRL_EXTRACT_EOF   1
163 #define RECCTRL_EXTRACT_ERROR_GENERIC 2
164 #define RECCTRL_EXTRACT_ERROR_NO_SUCH_FILTER 3
165 #define RECCTRL_EXTRACT_SKIP  4
166
167 typedef struct recTypeClass *RecTypeClass;
168 typedef struct recTypes *RecTypes;
169
170 YAZ_EXPORT
171 RecTypeClass recTypeClass_create (Res res, NMEM nmem);
172
173 YAZ_EXPORT
174 void recTypeClass_load_modules(RecTypeClass *rts, NMEM nmem,
175                                const char *module_path);
176
177 YAZ_EXPORT
178 RecTypeClass recTypeClass_add_modules(Res res, NMEM nmem,
179                                       const char *module_path);
180
181 YAZ_EXPORT
182 void recTypeClass_destroy(RecTypeClass rtc);
183
184 YAZ_EXPORT
185 void recTypeClass_info(RecTypeClass rtc, void *cd,
186                        void (*cb)(void *cd, const char *s));
187
188 YAZ_EXPORT
189 RecTypes recTypes_init(RecTypeClass rtc, data1_handle dh);
190
191 YAZ_EXPORT
192 void recTypes_destroy(RecTypes recTypes);
193
194 YAZ_EXPORT
195 void recTypes_default_handlers(RecTypes recTypes, Res res);
196
197 YAZ_EXPORT
198 RecType recType_byName(RecTypes rts, Res res, const char *name,
199                        void **clientDataP);
200
201 YAZ_END_CDECL
202
203 #endif
204 /*
205  * Local variables:
206  * c-basic-offset: 4
207  * c-file-style: "Stroustrup"
208  * indent-tabs-mode: nil
209  * End:
210  * vim: shiftwidth=4 tabstop=8 expandtab
211  */
212