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