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