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