2 * Copyright (C) 1995-1999, Index Data
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.15 2002-04-04 14:14:13 adam
8 * Multiple registers (alpha early)
10 * Revision 1.14 2001/01/22 11:41:41 adam
11 * Added support for raw retrieval (element set name "R").
13 * Revision 1.13 2000/03/20 19:08:36 adam
14 * Added remote record import using Z39.50 extended services and Segment
17 * Revision 1.12 2000/03/15 15:00:30 adam
18 * First work on threaded version.
20 * Revision 1.11 1999/10/29 10:00:00 adam
21 * Fixed minor bug where database name wasn't set in zebra_record_fetch.
23 * Revision 1.10 1999/05/26 07:49:13 adam
26 * Revision 1.9 1999/05/20 12:57:18 adam
27 * Implemented TCL filter. Updated recctrl system.
29 * Revision 1.8 1999/03/09 16:27:49 adam
30 * More work on SDRKit integration.
32 * Revision 1.7 1999/03/02 16:15:43 quinn
33 * Added "tagsysno" and "tagrank" directives to zebra.cfg.
35 * Revision 1.6 1999/02/18 15:01:25 adam
38 * Revision 1.5 1999/02/17 11:29:56 adam
39 * Fixed in record_fetch. Minor updates to API.
41 * Revision 1.4 1999/02/02 14:51:07 adam
42 * Updated WIN32 code specific sections. Changed header.
44 * Revision 1.3 1998/10/28 10:54:40 adam
47 * Revision 1.2 1998/10/16 08:14:33 adam
48 * Updated record control system.
50 * Revision 1.1 1998/03/05 08:45:13 adam
51 * New result set model and modular ranking system. Moved towards
52 * descent server API. System information stored as "SGML" records.
69 int zebra_record_ext_read (void *fh, char *buf, size_t count)
71 struct zebra_fetch_control *fc = (struct zebra_fetch_control *) fh;
72 return read (fc->fd, buf, count);
75 off_t zebra_record_ext_seek (void *fh, off_t offset)
77 struct zebra_fetch_control *fc = (struct zebra_fetch_control *) fh;
78 return lseek (fc->fd, offset + fc->record_offset, SEEK_SET);
81 off_t zebra_record_ext_tell (void *fh)
83 struct zebra_fetch_control *fc = (struct zebra_fetch_control *) fh;
84 return lseek (fc->fd, 0, SEEK_CUR) - fc->record_offset;
87 off_t zebra_record_int_seek (void *fh, off_t offset)
89 struct zebra_fetch_control *fc = (struct zebra_fetch_control *) fh;
90 return (off_t) (fc->record_int_pos = offset);
93 off_t zebra_record_int_tell (void *fh)
95 struct zebra_fetch_control *fc = (struct zebra_fetch_control *) fh;
96 return (off_t) fc->record_int_pos;
99 int zebra_record_int_read (void *fh, char *buf, size_t count)
101 struct zebra_fetch_control *fc = (struct zebra_fetch_control *) fh;
102 int l = fc->record_int_len - fc->record_int_pos;
105 l = (l < (int) count) ? l : count;
106 memcpy (buf, fc->record_int_buf + fc->record_int_pos, l);
107 fc->record_int_pos += l;
111 void zebra_record_int_end (void *fh, off_t off)
113 struct zebra_fetch_control *fc = (struct zebra_fetch_control *) fh;
114 fc->offset_end = off;
117 int zebra_record_fetch (ZebraHandle zh, int sysno, int score, ODR stream,
118 oid_value input_format, Z_RecordComposition *comp,
119 oid_value *output_format, char **rec_bufp,
120 int *rec_lenp, char **basenamep)
123 char *fname, *file_type, *basename;
125 struct recRetrieveCtrl retrieveCtrl;
127 struct zebra_fetch_control fc;
128 RecordAttr *recordAttr;
131 rec = rec_get (zh->reg->records, sysno);
134 logf (LOG_DEBUG, "rec_get fail on sysno=%d", sysno);
138 recordAttr = rec_init_attr (zh->reg->zei, rec);
140 file_type = rec->info[recInfo_fileType];
141 fname = rec->info[recInfo_filename];
142 basename = rec->info[recInfo_databaseName];
143 *basenamep = (char *) odr_malloc (stream, strlen(basename)+1);
144 strcpy (*basenamep, basename);
146 if (comp && comp->which == Z_RecordComp_simple &&
147 comp->u.simple->which == Z_ElementSetNames_generic)
149 if (!strcmp (comp->u.simple->u.generic, "R"))
152 if (!(rt = recType_byName (zh->reg->recTypes,
153 file_type, subType, &clientData)))
155 logf (LOG_WARN, "Retrieve: Cannot handle type %s", file_type);
158 logf (LOG_DEBUG, "retrieve localno=%d score=%d", sysno, score);
159 retrieveCtrl.fh = &fc;
161 if (rec->size[recInfo_storeData] > 0)
163 retrieveCtrl.readf = zebra_record_int_read;
164 retrieveCtrl.seekf = zebra_record_int_seek;
165 retrieveCtrl.tellf = zebra_record_int_tell;
166 fc.record_int_len = rec->size[recInfo_storeData];
167 fc.record_int_buf = rec->info[recInfo_storeData];
168 fc.record_int_pos = 0;
169 logf (LOG_DEBUG, "Internal retrieve. %d bytes", fc.record_int_len);
173 if ((fc.fd = open (fname, O_BINARY|O_RDONLY)) == -1)
175 logf (LOG_WARN|LOG_ERRNO, "Retrieve fail; missing file: %s",
180 fc.record_offset = recordAttr->recordOffset;
182 retrieveCtrl.readf = zebra_record_ext_read;
183 retrieveCtrl.seekf = zebra_record_ext_seek;
184 retrieveCtrl.tellf = zebra_record_ext_tell;
186 zebra_record_ext_seek (retrieveCtrl.fh, 0);
188 retrieveCtrl.subType = subType;
189 retrieveCtrl.localno = sysno;
190 retrieveCtrl.score = score;
191 retrieveCtrl.recordSize = recordAttr->recordSize;
192 retrieveCtrl.odr = stream;
193 retrieveCtrl.input_format = retrieveCtrl.output_format = input_format;
194 retrieveCtrl.comp = comp;
195 retrieveCtrl.diagnostic = 0;
196 retrieveCtrl.dh = zh->reg->dh;
197 retrieveCtrl.res = zh->res;
198 (*rt->retrieve)(clientData, &retrieveCtrl);
199 *output_format = retrieveCtrl.output_format;
200 *rec_bufp = (char *) retrieveCtrl.rec_buf;
201 *rec_lenp = retrieveCtrl.rec_len;
206 return retrieveCtrl.diagnostic;