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