3c452514ed5d1349ecd6e71bbe23c120ea69e0dd
[idzebra-moved-to-github.git] / include / idzebra / recctrl.h
1 /* $Id: recctrl.h,v 1.28 2006-08-16 13:16:35 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 /* single word entity */
52 typedef struct {
53     unsigned index_type;
54     const char *index_name;
55     const char *term_buf;
56     int  term_len;
57     zint seqno;
58     zint segment;
59     zint record_id;
60     zint section_id;
61     struct recExtractCtrl *extractCtrl;
62 } RecWord;
63
64 /* Extract record control */
65 struct recExtractCtrl {
66     void      *fh;                    /* File handle and read function     */
67     int       (*readf)(void *fh, char *buf, size_t count);
68     off_t     (*seekf)(void *fh, off_t offset);  /* seek function          */
69     off_t     (*tellf)(void *fh);                /* tell function          */
70     void      (*endf)(void *fh, off_t offset);   /* end of record position */
71     off_t     offset;                            /* start offset           */
72     void      (*init)(struct recExtractCtrl *p, RecWord *w);
73     void      *clientData;
74     void      (*tokenAdd)(RecWord *w);
75     void      (*setStoreData)(struct recExtractCtrl *p, void *buf, size_t size);
76     int       first_record;
77     int       flagShowRecords;
78     int       seqno[256];
79     char      match_criteria[256];
80     zint      staticrank;
81     void      (*schemaAdd)(struct recExtractCtrl *p, Odr_oid *oid);
82     data1_handle dh;
83     void      *handle;
84 };
85
86 /* Retrieve record control */
87 struct recRetrieveCtrl {
88     /* Input parameters ... */
89     Res       res;                    /* Resource pool                     */
90     ODR       odr;                    /* ODR used to create response       */
91     void     *fh;                     /* File descriptor and read function */
92     int       (*readf)(void *fh, char *buf, size_t count);
93     off_t     (*seekf)(void *fh, off_t offset);
94     off_t     (*tellf)(void *fh);
95     oid_value input_format;           /* Preferred record syntax           */
96     Z_RecordComposition *comp;        /* formatting instructions           */
97     char      *encoding;              /* preferred character encoding      */
98     zint      localno;                /* local id of record                */
99     int       score;                  /* score 0-1000 or -1 if none        */
100     zint      staticrank;             /* static rank >= 0,  0 if none */
101     int       recordSize;             /* size of record in bytes */
102     char      *fname;                 /* name of file (or NULL if internal) */
103     data1_handle dh;
104     zebra_snippets *hit_snippet;
105     zebra_snippets *doc_snippet;
106     
107     /* response */
108     oid_value  output_format;
109     void       *rec_buf;
110     int        rec_len;
111     int        diagnostic;
112     char       *addinfo;
113 };
114
115 typedef struct recType *RecType;
116
117 struct recType
118 {
119     int version;
120     char *name;                           /* Name of record type */
121     void *(*init)(Res res, RecType recType);  /* Init function - called once */
122     ZEBRA_RES (*config)(void *clientData, Res res, const char *args); /* Config */
123     void (*destroy)(void *clientData);    /* Destroy function */
124     int  (*extract)(void *clientData,
125                     struct recExtractCtrl *ctrl);   /* Extract proc */
126     int  (*retrieve)(void *clientData,
127                      struct recRetrieveCtrl *ctrl); /* Retrieve proc */
128 };
129
130 #define RECCTRL_EXTRACT_OK    0
131 #define RECCTRL_EXTRACT_EOF   1
132 #define RECCTRL_EXTRACT_ERROR_GENERIC 2
133 #define RECCTRL_EXTRACT_ERROR_NO_SUCH_FILTER 3
134
135 typedef struct recTypeClass *RecTypeClass;
136 typedef struct recTypes *RecTypes;
137
138 YAZ_EXPORT
139 RecTypeClass recTypeClass_create (Res res, NMEM nmem);
140
141 YAZ_EXPORT
142 void recTypeClass_load_modules(RecTypeClass *rts, NMEM nmem,
143                                const char *module_path);
144
145 YAZ_EXPORT
146 RecTypeClass recTypeClass_add_modules(Res res, NMEM nmem,
147                                       const char *module_path);
148
149 YAZ_EXPORT
150 void recTypeClass_destroy(RecTypeClass rtc);
151
152 YAZ_EXPORT
153 void recTypeClass_info(RecTypeClass rtc, void *cd,
154                        void (*cb)(void *cd, const char *s));
155
156 YAZ_EXPORT
157 RecTypes recTypes_init(RecTypeClass rtc, data1_handle dh);
158
159 YAZ_EXPORT
160 void recTypes_destroy(RecTypes recTypes);
161
162 YAZ_EXPORT
163 void recTypes_default_handlers(RecTypes recTypes, Res res);
164
165 YAZ_EXPORT
166 RecType recType_byName(RecTypes rts, Res res, const char *name,
167                        void **clientDataP);
168
169
170 #define KEY_SEGMENT_SIZE 1024
171
172 YAZ_END_CDECL
173
174 #endif
175 /*
176  * Local variables:
177  * c-basic-offset: 4
178  * indent-tabs-mode: nil
179  * End:
180  * vim: shiftwidth=4 tabstop=8 expandtab
181  */
182