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