2 * Copyright (C) 1995-1999, Index Data
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.13 2000-03-20 19:08:36 adam
8 * Added remote record import using Z39.50 extended services and Segment
11 * Revision 1.12 2000/03/15 15:00:30 adam
12 * First work on threaded version.
14 * Revision 1.11 1999/10/29 10:00:00 adam
15 * Fixed minor bug where database name wasn't set in zebra_record_fetch.
17 * Revision 1.10 1999/05/26 07:49:13 adam
20 * Revision 1.9 1999/05/20 12:57:18 adam
21 * Implemented TCL filter. Updated recctrl system.
23 * Revision 1.8 1999/03/09 16:27:49 adam
24 * More work on SDRKit integration.
26 * Revision 1.7 1999/03/02 16:15:43 quinn
27 * Added "tagsysno" and "tagrank" directives to zebra.cfg.
29 * Revision 1.6 1999/02/18 15:01:25 adam
32 * Revision 1.5 1999/02/17 11:29:56 adam
33 * Fixed in record_fetch. Minor updates to API.
35 * Revision 1.4 1999/02/02 14:51:07 adam
36 * Updated WIN32 code specific sections. Changed header.
38 * Revision 1.3 1998/10/28 10:54:40 adam
41 * Revision 1.2 1998/10/16 08:14:33 adam
42 * Updated record control system.
44 * Revision 1.1 1998/03/05 08:45:13 adam
45 * New result set model and modular ranking system. Moved towards
46 * descent server API. System information stored as "SGML" records.
72 int zebra_record_ext_read (void *fh, char *buf, size_t count)
74 struct zebra_fetch_control *fc = (struct zebra_fetch_control *) fh;
75 return read (fc->fd, buf, count);
78 off_t zebra_record_ext_seek (void *fh, off_t offset)
80 struct zebra_fetch_control *fc = (struct zebra_fetch_control *) fh;
81 return lseek (fc->fd, offset + fc->record_offset, SEEK_SET);
84 off_t zebra_record_ext_tell (void *fh)
86 struct zebra_fetch_control *fc = (struct zebra_fetch_control *) fh;
87 return lseek (fc->fd, 0, SEEK_CUR) - fc->record_offset;
90 off_t zebra_record_int_seek (void *fh, off_t offset)
92 struct zebra_fetch_control *fc = (struct zebra_fetch_control *) fh;
93 return (off_t) (fc->record_int_pos = offset);
96 off_t zebra_record_int_tell (void *fh)
98 struct zebra_fetch_control *fc = (struct zebra_fetch_control *) fh;
99 return (off_t) fc->record_int_pos;
102 int zebra_record_int_read (void *fh, char *buf, size_t count)
104 struct zebra_fetch_control *fc = (struct zebra_fetch_control *) fh;
105 int l = fc->record_int_len - fc->record_int_pos;
108 l = (l < (int) count) ? l : count;
109 memcpy (buf, fc->record_int_buf + fc->record_int_pos, l);
110 fc->record_int_pos += l;
114 void zebra_record_int_end (void *fh, off_t off)
116 struct zebra_fetch_control *fc = (struct zebra_fetch_control *) fh;
117 fc->offset_end = off;
120 int zebra_record_fetch (ZebraHandle zh, int sysno, int score, ODR stream,
121 oid_value input_format, Z_RecordComposition *comp,
122 oid_value *output_format, char **rec_bufp,
123 int *rec_lenp, char **basenamep)
126 char *fname, *file_type, *basename;
128 struct recRetrieveCtrl retrieveCtrl;
130 struct zebra_fetch_control fc;
131 RecordAttr *recordAttr;
134 rec = rec_get (zh->service->records, sysno);
137 logf (LOG_DEBUG, "rec_get fail on sysno=%d", sysno);
141 recordAttr = rec_init_attr (zh->service->zei, rec);
143 file_type = rec->info[recInfo_fileType];
144 fname = rec->info[recInfo_filename];
145 basename = rec->info[recInfo_databaseName];
146 *basenamep = (char *) odr_malloc (stream, strlen(basename)+1);
147 strcpy (*basenamep, basename);
149 if (!(rt = recType_byName (zh->service->recTypes,
150 file_type, subType, &clientData)))
152 logf (LOG_WARN, "Retrieve: Cannot handle type %s", file_type);
155 logf (LOG_DEBUG, "retrieve localno=%d score=%d", sysno, score);
156 retrieveCtrl.fh = &fc;
158 if (rec->size[recInfo_storeData] > 0)
160 retrieveCtrl.readf = zebra_record_int_read;
161 retrieveCtrl.seekf = zebra_record_int_seek;
162 retrieveCtrl.tellf = zebra_record_int_tell;
163 fc.record_int_len = rec->size[recInfo_storeData];
164 fc.record_int_buf = rec->info[recInfo_storeData];
165 fc.record_int_pos = 0;
166 logf (LOG_DEBUG, "Internal retrieve. %d bytes", fc.record_int_len);
170 if ((fc.fd = open (fname, O_BINARY|O_RDONLY)) == -1)
172 logf (LOG_WARN|LOG_ERRNO, "Retrieve fail; missing file: %s",
177 fc.record_offset = recordAttr->recordOffset;
179 retrieveCtrl.readf = zebra_record_ext_read;
180 retrieveCtrl.seekf = zebra_record_ext_seek;
181 retrieveCtrl.tellf = zebra_record_ext_tell;
183 zebra_record_ext_seek (retrieveCtrl.fh, 0);
185 retrieveCtrl.subType = subType;
186 retrieveCtrl.localno = sysno;
187 retrieveCtrl.score = score;
188 retrieveCtrl.recordSize = recordAttr->recordSize;
189 retrieveCtrl.odr = stream;
190 retrieveCtrl.input_format = retrieveCtrl.output_format = input_format;
191 retrieveCtrl.comp = comp;
192 retrieveCtrl.diagnostic = 0;
193 retrieveCtrl.dh = zh->service->dh;
194 retrieveCtrl.res = zh->service->res;
195 (*rt->retrieve)(clientData, &retrieveCtrl);
196 *output_format = retrieveCtrl.output_format;
197 *rec_bufp = (char *) retrieveCtrl.rec_buf;
198 *rec_lenp = retrieveCtrl.rec_len;
203 return retrieveCtrl.diagnostic;