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