- if (freq.errcode == 13 && freq.errstring == 0)
- {
- sprintf (s, "%d", recno);
- freq.errstring = s;
- }
- return diagrec(a, freq.errcode, freq.errstring);
- }
- reclist->records[reclist->num_records] =
- surrogatediagrec(a, freq.basename, freq.errcode,
- freq.errstring);
- reclist->num_records++;
- *next = freq.last_in_set ? 0 : recno + 1;
- continue;
- }
- if (freq.len >= 0)
- this_length = freq.len;
- else
- this_length = odr_total(a->encode) - total_length;
- yaz_log(LOG_DEBUG, " fetched record, len=%d, total=%d",
- this_length, total_length);
- if (this_length + total_length > a->preferredMessageSize)
- {
- /* record is small enough, really */
- if (this_length <= a->preferredMessageSize)
- {
- yaz_log(LOG_DEBUG, " Dropped last normal-sized record");
- *pres = Z_PRES_PARTIAL_2;
- break;
- }
- /* record can only be fetched by itself */
- if (this_length < a->maximumRecordSize)
- {
- yaz_log(LOG_DEBUG, " Record > prefmsgsz");
- if (toget > 1)
- {
- yaz_log(LOG_DEBUG, " Dropped it");
- reclist->records[reclist->num_records] =
- surrogatediagrec(a, freq.basename, 16, 0);
- reclist->num_records++;
- *next = freq.last_in_set ? 0 : recno + 1;
- dumped_records += this_length;
- continue;
- }
- }
- else /* too big entirely */
- {
- yaz_log(LOG_LOG, "Record > maxrcdsz this=%d max=%d", this_length, a->maximumRecordSize);
- reclist->records[reclist->num_records] =
- surrogatediagrec(a, freq.basename, 17, 0);
- reclist->num_records++;
- *next = freq.last_in_set ? 0 : recno + 1;
- dumped_records += this_length;
- continue;
- }
- }
-
- if (!(thisrec = (Z_NamePlusRecord *)
- odr_malloc(a->encode, sizeof(*thisrec))))
- return 0;
- if (!(thisrec->databaseName = (char *)odr_malloc(a->encode,
- strlen(freq.basename) + 1)))
- return 0;
- strcpy(thisrec->databaseName, freq.basename);
- thisrec->which = Z_NamePlusRecord_databaseRecord;
-
- if (freq.output_format_raw)
- {
- struct oident *ident = oid_getentbyoid(freq.output_format_raw);
- freq.output_format = ident->value;
- }
- thisrec->u.databaseRecord = z_ext_record(a->encode, freq.output_format,
- freq.record, freq.len);
- if (!thisrec->u.databaseRecord)
- return 0;
- reclist->records[reclist->num_records] = thisrec;
- reclist->num_records++;
- *next = freq.last_in_set ? 0 : recno + 1;
+ if (freq.errcode == YAZ_BIB1_PRESENT_REQUEST_OUT_OF_RANGE &&
+ freq.errstring == 0)
+ {
+ sprintf (s, "%d", recno);
+ freq.errstring = s;
+ }
+ if (errcode)
+ *errcode = freq.errcode;
+ return diagrec(a, freq.errcode, freq.errstring);
+ }
+ reclist->records[reclist->num_records] =
+ surrogatediagrec(a, freq.basename, freq.errcode,
+ freq.errstring);
+ reclist->num_records++;
+ continue;
+ }
+ if (freq.record == 0) /* no error and no record ? */
+ {
+ *next = 0; /* signal end-of-set and stop */
+ break;
+ }
+ if (freq.len >= 0)
+ this_length = freq.len;
+ else
+ this_length = odr_total(a->encode) - total_length - dumped_records;
+ yaz_log(YLOG_DEBUG, " fetched record, len=%d, total=%d dumped=%d",
+ this_length, total_length, dumped_records);
+ if (a->preferredMessageSize > 0 &&
+ this_length + total_length > a->preferredMessageSize)
+ {
+ /* record is small enough, really */
+ if (this_length <= a->preferredMessageSize && recno > start)
+ {
+ yaz_log(log_requestdetail, " Dropped last normal-sized record");
+ *pres = Z_PresentStatus_partial_2;
+ break;
+ }
+ /* record can only be fetched by itself */
+ if (this_length < a->maximumRecordSize)
+ {
+ yaz_log(log_requestdetail, " Record > prefmsgsz");
+ if (toget > 1)
+ {
+ yaz_log(YLOG_DEBUG, " Dropped it");
+ reclist->records[reclist->num_records] =
+ surrogatediagrec(a, freq.basename, 16, 0);
+ reclist->num_records++;
+ dumped_records += this_length;
+ continue;
+ }
+ }
+ else /* too big entirely */
+ {
+ yaz_log(log_requestdetail, "Record > maxrcdsz this=%d max=%d",
+ this_length, a->maximumRecordSize);
+ reclist->records[reclist->num_records] =
+ surrogatediagrec(a, freq.basename, 17, 0);
+ reclist->num_records++;
+ dumped_records += this_length;
+ continue;
+ }
+ }
+
+ if (!(thisrec = (Z_NamePlusRecord *)
+ odr_malloc(a->encode, sizeof(*thisrec))))
+ return 0;
+ if (freq.basename)
+ thisrec->databaseName = odr_strdup(a->encode, freq.basename);
+ else
+ thisrec->databaseName = 0;
+ thisrec->which = Z_NamePlusRecord_databaseRecord;
+
+ if (freq.output_format_raw)
+ {
+ struct oident *ident = oid_getentbyoid(freq.output_format_raw);
+ freq.output_format = ident->value;
+ }
+ thisrec->u.databaseRecord = z_ext_record(a->encode, freq.output_format,
+ freq.record, freq.len);
+ if (!thisrec->u.databaseRecord)
+ return 0;
+ reclist->records[reclist->num_records] = thisrec;
+ reclist->num_records++;