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