Revert. Use int for record length (for retrieval)
[idzebra-moved-to-github.git] / include / idzebra / recctrl.h
1 /* $Id: recctrl.h,v 1.24 2006-06-13 20:03:33 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 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 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 #include <idzebra/zebramap.h>
34
35 YAZ_BEGIN_CDECL
36
37 /* 1 */
38 #define ZEBRA_XPATH_ELM_BEGIN "_XPATH_BEGIN"
39
40 /* 2 */
41 #define ZEBRA_XPATH_ELM_END   "_XPATH_END"
42
43 /* 1016 */
44 #define ZEBRA_XPATH_CDATA     "_XPATH_CDATA"
45
46 /* 3 */
47 #define ZEBRA_XPATH_ATTR_NAME       "_XPATH_ATTR_NAME"
48
49 /* 1015 */
50 #define ZEBRA_XPATH_ATTR_CDATA      "_XPATH_ATTR_CDATA"
51
52 /* single word entity */
53 typedef struct {
54     unsigned index_type;
55     const char *index_name;
56     const char *term_buf;
57     int  term_len;
58     zint seqno;
59     zint record_id;
60     zint section_id;
61     ZebraMaps zebra_maps;
62     struct recExtractCtrl *extractCtrl;
63 } RecWord;
64
65 /* Extract record control */
66 struct recExtractCtrl {
67     void      *fh;                    /* File handle and read function     */
68     int       (*readf)(void *fh, char *buf, size_t count);
69     off_t     (*seekf)(void *fh, off_t offset);  /* seek function          */
70     off_t     (*tellf)(void *fh);                /* tell function          */
71     void      (*endf)(void *fh, off_t offset);   /* end of record position */
72     off_t     offset;                            /* start offset           */
73     void      (*init)(struct recExtractCtrl *p, RecWord *w);
74     void      *clientData;
75     void      (*tokenAdd)(RecWord *w);
76     void      (*setStoreData)(struct recExtractCtrl *p, void *buf, size_t size);
77     ZebraMaps zebra_maps;
78     int       first_record;
79     int       flagShowRecords;
80     int       seqno[256];
81     char      match_criteria[256];
82     zint      staticrank;
83     void      (*schemaAdd)(struct recExtractCtrl *p, Odr_oid *oid);
84     data1_handle dh;
85     void      *handle;
86 };
87
88 /* Retrieve record control */
89 struct recRetrieveCtrl {
90     /* Input parameters ... */
91     Res       res;                    /* Resource pool                     */
92     ODR       odr;                    /* ODR used to create response       */
93     void     *fh;                     /* File descriptor and read function */
94     int       (*readf)(void *fh, char *buf, size_t count);
95     off_t     (*seekf)(void *fh, off_t offset);
96     off_t     (*tellf)(void *fh);
97     oid_value input_format;           /* Preferred record syntax           */
98     Z_RecordComposition *comp;        /* formatting instructions           */
99     char      *encoding;              /* preferred character encoding      */
100     zint      localno;                /* local id of record                */
101     int       score;                  /* score 0-1000 or -1 if none        */
102     zint      staticrank;             /* static rank >= 0,  0 if none */
103     int       recordSize;             /* size of record in bytes */
104     char      *fname;                 /* name of file (or NULL if internal) */
105     data1_handle dh;
106     zebra_snippets *hit_snippet;
107     zebra_snippets *doc_snippet;
108     
109     /* response */
110     oid_value  output_format;
111     void       *rec_buf;
112     int        rec_len;
113     int        diagnostic;
114     char       *addinfo;
115 };
116
117 typedef struct recType *RecType;
118
119 struct recType
120 {
121     int version;
122     char *name;                           /* Name of record type */
123     void *(*init)(Res res, RecType recType);  /* Init function - called once */
124     ZEBRA_RES (*config)(void *clientData, Res res, const char *args); /* Config */
125     void (*destroy)(void *clientData);    /* Destroy function */
126     int  (*extract)(void *clientData,
127                     struct recExtractCtrl *ctrl);   /* Extract proc */
128     int  (*retrieve)(void *clientData,
129                      struct recRetrieveCtrl *ctrl); /* Retrieve proc */
130 };
131
132 #define RECCTRL_EXTRACT_OK    0
133 #define RECCTRL_EXTRACT_EOF   1
134 #define RECCTRL_EXTRACT_ERROR_GENERIC 2
135 #define RECCTRL_EXTRACT_ERROR_NO_SUCH_FILTER 3
136
137 typedef struct recTypeClass *RecTypeClass;
138 typedef struct recTypes *RecTypes;
139
140 YAZ_EXPORT
141 RecTypeClass recTypeClass_create (Res res, NMEM nmem);
142
143 YAZ_EXPORT
144 void recTypeClass_load_modules(RecTypeClass *rts, NMEM nmem,
145                                const char *module_path);
146
147 YAZ_EXPORT
148 RecTypeClass recTypeClass_add_modules(Res res, NMEM nmem,
149                                       const char *module_path);
150
151 YAZ_EXPORT
152 void recTypeClass_destroy(RecTypeClass rtc);
153
154 YAZ_EXPORT
155 void recTypeClass_info(RecTypeClass rtc, void *cd,
156                        void (*cb)(void *cd, const char *s));
157
158 YAZ_EXPORT
159 RecTypes recTypes_init(RecTypeClass rtc, data1_handle dh);
160
161 YAZ_EXPORT
162 void recTypes_destroy(RecTypes recTypes);
163
164 YAZ_EXPORT
165 void recTypes_default_handlers(RecTypes recTypes, Res res);
166
167 YAZ_EXPORT
168 RecType recType_byName(RecTypes rts, Res res, const char *name,
169                        void **clientDataP);
170
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