/* This file is part of the YAZ toolkit.
- * Copyright (C) 1995-2008 Index Data
+ * Copyright (C) 1995-2010 Index Data
* See the file LICENSE for details.
*/
/**
static zoom_ret do_write_ex(ZOOM_connection c, char *buf_out, int len_out);
static char *cql2pqf(ZOOM_connection c, const char *cql);
+ZOOM_API(const char *) ZOOM_get_event_str(int event)
+{
+ static const char *ar[] = {
+ "NONE",
+ "CONNECT",
+ "SEND_DATA",
+ "RECV_DATA",
+ "TIMEOUT",
+ "UNKNOWN",
+ "SEND_APDU",
+ "RECV_APDU",
+ "RECV_RECORD",
+ "RECV_SEARCH",
+ "END"
+ };
+ return ar[event];
+}
/*
* This wrapper is just for logging failed lookups. It would be nicer
yaz_log(YLOG_LOG, "connect p=%p", task);
break;
case ZOOM_TASK_SCAN:
- yaz_log(YLOG_LOG, "scant p=%p", task);
+ yaz_log(YLOG_LOG, "scan p=%p", task);
break;
}
}
c->odr_in = odr_createmem(ODR_DECODE);
c->odr_out = odr_createmem(ODR_ENCODE);
+ c->odr_print = 0;
c->async = 0;
c->support_named_resultsets = 0;
set_ZOOM_error(c, ZOOM_ERROR_NONE, 0);
ZOOM_connection_remove_tasks(c);
+ if (c->odr_print)
+ {
+ odr_setprint(c->odr_print, 0); /* prevent destroy from fclose'ing */
+ odr_destroy(c->odr_print);
+ }
+ if (ZOOM_options_get_bool(c->options, "apdulog", 0))
+ {
+ c->odr_print = odr_createmem(ODR_PRINT);
+ odr_setprint(c->odr_print, yaz_log_file());
+ }
+ else
+ c->odr_print = 0;
+
if (c->cs)
{
yaz_log(log_details, "%p ZOOM_connection_connect reconnect ok", c);
xfree(c->diagset);
odr_destroy(c->odr_in);
odr_destroy(c->odr_out);
+ if (c->odr_print)
+ {
+ odr_setprint(c->odr_print, 0); /* prevent destroy from fclose'ing */
+ odr_destroy(c->odr_print);
+ }
ZOOM_options_destroy(c->options);
ZOOM_connection_remove_tasks(c);
ZOOM_connection_remove_events(c);
task->u.search.resultset = r;
task->u.search.start = start;
task->u.search.count = count;
+ task->u.search.recv_search_fired = 0;
syntax = ZOOM_options_get(r->options, "preferredRecordSyntax");
task->u.search.syntax = syntax ? xstrdup(syntax) : 0;
return 0;
}
+static void ZOOM_record_release(ZOOM_record rec)
+{
+ if (!rec)
+ return;
+ if (rec->wrbuf)
+ wrbuf_destroy(rec->wrbuf);
+#if YAZ_HAVE_XML2
+ if (rec->xml_mem)
+ xmlFree(rec->xml_mem);
+#endif
+ if (rec->odr)
+ odr_destroy(rec->odr);
+}
+
ZOOM_API(void)
ZOOM_resultset_cache_reset(ZOOM_resultset r)
{
ZOOM_record_cache rc;
for (rc = r->record_hash[i]; rc; rc = rc->next)
{
- if (rc->rec.wrbuf_marc)
- wrbuf_destroy(rc->rec.wrbuf_marc);
- if (rc->rec.wrbuf_iconv)
- wrbuf_destroy(rc->rec.wrbuf_iconv);
- if (rc->rec.wrbuf_opac)
- wrbuf_destroy(rc->rec.wrbuf_opac);
+ ZOOM_record_release(&rc->rec);
}
r->record_hash[i] = 0;
}
ZOOM_API(size_t)
ZOOM_resultset_size(ZOOM_resultset r)
{
- yaz_log(log_details, "ZOOM_resultset_size r=%p count=%d",
+ yaz_log(log_details, "ZOOM_resultset_size r=%p count=" ODR_INT_PRINTF,
r, r->size);
return r->size;
}
if (c->cs && c->cs->protocol == PROTO_HTTP)
{
#if YAZ_HAVE_XML2
- const char *path = 0;
+ const char *db = 0;
c->proto = PROTO_HTTP;
- cs_get_host_args(c->host_port, &path);
+ cs_get_host_args(c->host_port, &db);
xfree(c->path);
- c->path = (char*) xmalloc(strlen(path)+2);
- c->path[0] = '/';
- strcpy(c->path+1, path);
+
+ c->path = xmalloc(strlen(db) * 3 + 2);
+ yaz_encode_sru_dbpath_buf(c->path, db);
#else
set_ZOOM_error(c, ZOOM_ERROR_UNSUPPORTED_PROTOCOL, "SRW");
do_close(c);
odr_reset(out);
return -1;
}
+ if (c->odr_print)
+ z_APDU(c->odr_print, &a, 0, 0);
yaz_log(log_details, "%p encoding_APDU encoding OK", c);
return 0;
}
Z_InitRequest *ireq = apdu->u.initRequest;
Z_IdAuthentication *auth = (Z_IdAuthentication *)
odr_malloc(c->odr_out, sizeof(*auth));
- char *version;
ODR_MASK_SET(ireq->options, Z_Options_search);
ODR_MASK_SET(ireq->options, Z_Options_present);
ODR_MASK_SET(ireq->protocolVersion, Z_ProtocolVersion_2);
ODR_MASK_SET(ireq->protocolVersion, Z_ProtocolVersion_3);
- /* Index Data's Z39.50 Implementor Id is 81 */
ireq->implementationId =
odr_prepend(c->odr_out,
ZOOM_options_get(c->options, "implementationId"),
- odr_prepend(c->odr_out, "81", ireq->implementationId));
+ ireq->implementationId);
ireq->implementationName =
odr_prepend(c->odr_out,
odr_prepend(c->odr_out, "ZOOM-C",
ireq->implementationName));
- version = odr_strdup(c->odr_out, "$Revision: 1.154 $");
- if (strlen(version) > 10) /* check for unexpanded CVS strings */
- version[strlen(version)-2] = '\0';
ireq->implementationVersion =
odr_prepend(c->odr_out,
ZOOM_options_get(c->options, "implementationVersion"),
- odr_prepend(c->odr_out, &version[11],
- ireq->implementationVersion));
+ ireq->implementationVersion);
*ireq->maximumRecordSize = c->maximum_record_size;
*ireq->preferredMessageSize = c->preferred_message_size;
{
Z_GDU *gdu;
ZOOM_Event event;
-
- gdu = z_get_HTTP_Request_host_path(c->odr_out, c->host_port, c->path);
+ const char *database = ZOOM_options_get(c->options, "databaseName");
+ char *fdatabase = 0;
+
+ if (database)
+ fdatabase = yaz_encode_sru_dbpath_odr(c->odr_out, database);
+ gdu = z_get_HTTP_Request_host_path(c->odr_out, c->host_port,
+ fdatabase ? fdatabase : c->path);
if (c->sru_mode == zoom_sru_get)
{
}
if (!z_GDU(c->odr_out, &gdu, 0, 0))
return zoom_complete;
+ if (c->odr_print)
+ z_GDU(c->odr_print, &gdu, 0, 0);
c->buf_out = odr_getbuf(c->odr_out, &c->len_out, 0);
event = ZOOM_Event_create(ZOOM_EVENT_SEND_APDU);
}
#endif
-
-static Z_SRW_PDU *ZOOM_srw_get_pdu(ZOOM_connection c, int type) {
+#if YAZ_HAVE_XML2
+static Z_SRW_PDU *ZOOM_srw_get_pdu(ZOOM_connection c, int type)
+{
Z_SRW_PDU *sr = yaz_srw_get_pdu(c->odr_out, type, c->sru_version);
sr->username = c->user;
sr->password = c->password;
return sr;
}
+#endif
#if YAZ_HAVE_XML2
static zoom_ret ZOOM_connection_srw_send_search(ZOOM_connection c)
{
case ZOOM_TASK_SEARCH:
resultset = c->tasks->u.search.resultset;
- resultset->setname = xstrdup("default");
+ if (!resultset->setname)
+ resultset->setname = xstrdup("default");
ZOOM_options_set(resultset->options, "setname", resultset->setname);
start = &c->tasks->u.search.start;
count = &c->tasks->u.search.count;
start = &c->tasks->u.retrieve.start;
count = &c->tasks->u.retrieve.count;
-
+
if (*start >= resultset->size)
return zoom_complete;
if (*start + *count > resultset->size)
}
sr->u.request->startRecord = odr_intdup(c->odr_out, *start + 1);
sr->u.request->maximumRecords = odr_intdup(
- c->odr_out, resultset->step>0 ? resultset->step : *count);
+ c->odr_out, (resultset->step > 0 && resultset->step < *count) ?
+ resultset->step : *count);
sr->u.request->recordSchema = resultset->schema;
option_val = ZOOM_resultset_option_get(resultset, "recordPacking");
yaz_iconv_t cd = yaz_iconv_open(cp, "UTF-8");
if (cd)
{
+ int r;
search_req->query = yaz_copy_Z_Query(search_req->query,
c->odr_out);
- yaz_query_charset_convert_rpnquery(search_req->query->u.type_1,
- c->odr_out, cd);
+ r = yaz_query_charset_convert_rpnquery_check(
+ search_req->query->u.type_1,
+ c->odr_out, cd);
yaz_iconv_close(cd);
+ if (r)
+ { /* query could not be char converted */
+ set_ZOOM_error(c, ZOOM_ERROR_INVALID_QUERY, 0);
+ return zoom_complete;
+ }
}
}
}
nrec = (ZOOM_record) xmalloc(sizeof(*nrec));
nrec->odr = odr_createmem(ODR_DECODE);
- nrec->wrbuf_marc = 0;
- nrec->wrbuf_iconv = 0;
- nrec->wrbuf_opac = 0;
+ nrec->wrbuf = 0;
+#if YAZ_HAVE_XML2
+ nrec->xml_mem = 0;
+ nrec->xml_size = 0;
+#endif
odr_setbuf(nrec->odr, buf, size, 0);
z_NamePlusRecord(nrec->odr, &nrec->npr, 0, 0);
ZOOM_API(void)
ZOOM_record_destroy(ZOOM_record rec)
{
- if (!rec)
- return;
- if (rec->wrbuf_marc)
- wrbuf_destroy(rec->wrbuf_marc);
- if (rec->wrbuf_iconv)
- wrbuf_destroy(rec->wrbuf_iconv);
- if (rec->wrbuf_opac)
- wrbuf_destroy(rec->wrbuf_opac);
- odr_destroy(rec->odr);
+ ZOOM_record_release(rec);
xfree(rec);
}
-static const char *marc_iconv_return(ZOOM_record rec, int marc_type,
- int *len,
- const char *buf, int sz,
- const char *record_charset)
+
+static yaz_iconv_t iconv_create_charset(const char *record_charset)
{
char to[40];
char from[40];
yaz_iconv_t cd = 0;
- yaz_marc_t mt = yaz_marc_create();
*from = '\0';
strcpy(to, "UTF-8");
{
/* Use "from,to" or just "from" */
const char *cp = strchr(record_charset, ',');
- int clen = strlen(record_charset);
+ size_t clen = strlen(record_charset);
if (cp && cp[1])
{
strncpy( to, cp+1, sizeof(to)-1);
strncpy(from, record_charset, clen);
from[clen] = '\0';
}
-
if (*from && *to)
- {
cd = yaz_iconv_open(to, from);
- yaz_marc_iconv(mt, cd);
- }
+ return cd;
+}
+
+static const char *return_marc_record(ZOOM_record rec, int marc_type,
+ int *len,
+ const char *buf, int sz,
+ const char *record_charset)
+{
+ yaz_iconv_t cd = iconv_create_charset(record_charset);
+ yaz_marc_t mt = yaz_marc_create();
+ const char *ret_string = 0;
+ if (cd)
+ yaz_marc_iconv(mt, cd);
yaz_marc_xml(mt, marc_type);
- if (!rec->wrbuf_marc)
- rec->wrbuf_marc = wrbuf_alloc();
- wrbuf_rewind(rec->wrbuf_marc);
- if (yaz_marc_decode_wrbuf(mt, buf, sz, rec->wrbuf_marc) > 0)
- {
- yaz_marc_destroy(mt);
- if (cd)
- yaz_iconv_close(cd);
+ if (!rec->wrbuf)
+ rec->wrbuf = wrbuf_alloc();
+ wrbuf_rewind(rec->wrbuf);
+ if (yaz_marc_decode_wrbuf(mt, buf, sz, rec->wrbuf) > 0)
+ {
if (len)
- *len = wrbuf_len(rec->wrbuf_marc);
- return wrbuf_cstr(rec->wrbuf_marc);
+ *len = wrbuf_len(rec->wrbuf);
+ ret_string = wrbuf_cstr(rec->wrbuf);
}
yaz_marc_destroy(mt);
if (cd)
yaz_iconv_close(cd);
- return 0;
+ return ret_string;
}
-static const char *record_iconv_return(ZOOM_record rec, int *len,
- const char *buf, int sz,
- const char *record_charset)
+static const char *return_opac_record(ZOOM_record rec, int marc_type,
+ int *len,
+ Z_OPACRecord *opac_rec,
+ const char *record_charset)
{
- char to[40];
- char from[40];
- yaz_iconv_t cd = 0;
+ yaz_iconv_t cd = iconv_create_charset(record_charset);
+ yaz_marc_t mt = yaz_marc_create();
- *from = '\0';
- strcpy(to, "UTF-8");
+ if (cd)
+ yaz_marc_iconv(mt, cd);
+ yaz_marc_xml(mt, marc_type);
- if (record_charset && *record_charset)
- {
- /* Use "from,to" or just "from" */
- const char *cp = strchr(record_charset, ',');
- int clen = strlen(record_charset);
- if (cp && cp[1])
- {
- strncpy( to, cp+1, sizeof(to)-1);
- to[sizeof(to)-1] = '\0';
- clen = cp - record_charset;
- }
- if (clen > sizeof(from)-1)
- clen = sizeof(from)-1;
-
- if (clen)
- strncpy(from, record_charset, clen);
- from[clen] = '\0';
- }
+ if (!rec->wrbuf)
+ rec->wrbuf = wrbuf_alloc();
+ wrbuf_rewind(rec->wrbuf);
+
+ yaz_opac_decode_wrbuf(mt, opac_rec, rec->wrbuf);
+ yaz_marc_destroy(mt);
+
+ if (cd)
+ yaz_iconv_close(cd);
+ if (len)
+ *len = wrbuf_len(rec->wrbuf);
+ return wrbuf_cstr(rec->wrbuf);
+}
+
+static const char *return_string_record(ZOOM_record rec, int *len,
+ const char *buf, int sz,
+ const char *record_charset)
+{
+ yaz_iconv_t cd = iconv_create_charset(record_charset);
- if (*from && *to && (cd = yaz_iconv_open(to, from)))
+ if (cd)
{
- if (!rec->wrbuf_iconv)
- rec->wrbuf_iconv = wrbuf_alloc();
+ if (!rec->wrbuf)
+ rec->wrbuf = wrbuf_alloc();
- wrbuf_rewind(rec->wrbuf_iconv);
+ wrbuf_rewind(rec->wrbuf);
- wrbuf_iconv_write(rec->wrbuf_iconv, cd, buf, sz);
- wrbuf_iconv_reset(rec->wrbuf_iconv, cd);
+ wrbuf_iconv_write(rec->wrbuf, cd, buf, sz);
+ wrbuf_iconv_reset(rec->wrbuf, cd);
- buf = wrbuf_cstr(rec->wrbuf_iconv);
- sz = wrbuf_len(rec->wrbuf_iconv);
+ buf = wrbuf_cstr(rec->wrbuf);
+ sz = wrbuf_len(rec->wrbuf);
yaz_iconv_close(cd);
}
if (len)
return buf;
}
+static const char *return_record(ZOOM_record rec, int *len,
+ Z_NamePlusRecord *npr,
+ int marctype, const char *charset)
+{
+ Z_External *r = (Z_External *) npr->u.databaseRecord;
+ const Odr_oid *oid = r->direct_reference;
+
+ /* render bibliographic record .. */
+ if (r->which == Z_External_OPAC)
+ {
+ return return_opac_record(rec, marctype, len,
+ r->u.opac, charset);
+ }
+ if (r->which == Z_External_sutrs)
+ return return_string_record(rec, len,
+ (char*) r->u.sutrs->buf,
+ r->u.sutrs->len,
+ charset);
+ else if (r->which == Z_External_octet)
+ {
+ if (yaz_oid_is_iso2709(oid))
+ {
+ const char *ret_buf = return_marc_record(
+ rec, marctype, len,
+ (const char *) r->u.octet_aligned->buf,
+ r->u.octet_aligned->len,
+ charset);
+ if (ret_buf)
+ return ret_buf;
+ /* bad ISO2709. Return fail unless raw (ISO2709) is wanted */
+ if (marctype != YAZ_MARC_ISO2709)
+ return 0;
+ }
+ return return_string_record(rec, len,
+ (const char *) r->u.octet_aligned->buf,
+ r->u.octet_aligned->len,
+ charset);
+ }
+ else if (r->which == Z_External_grs1)
+ {
+ if (!rec->wrbuf)
+ rec->wrbuf = wrbuf_alloc();
+ wrbuf_rewind(rec->wrbuf);
+ yaz_display_grs1(rec->wrbuf, r->u.grs1, 0);
+ return return_string_record(rec, len,
+ wrbuf_buf(rec->wrbuf),
+ wrbuf_len(rec->wrbuf),
+ charset);
+ }
+ return 0;
+}
+
ZOOM_API(int)
ZOOM_record_error(ZOOM_record rec, const char **cp,
return 0;
}
+static const char *get_record_format(ZOOM_record rec, int *len,
+ Z_NamePlusRecord *npr,
+ int marctype, const char *charset,
+ const char *format)
+{
+ const char *res = return_record(rec, len, npr, marctype, charset);
+#if YAZ_HAVE_XML2
+ if (*format == '1' && len)
+ {
+ /* try to XML format res */
+ xmlDocPtr doc;
+ xmlKeepBlanksDefault(0); /* get get xmlDocFormatMemory to work! */
+ doc = xmlParseMemory(res, *len);
+ if (doc)
+ {
+ if (rec->xml_mem)
+ xmlFree(rec->xml_mem);
+ xmlDocDumpFormatMemory(doc, &rec->xml_mem, &rec->xml_size, 1);
+ xmlFreeDoc(doc);
+ res = (char *) rec->xml_mem;
+ *len = rec->xml_size;
+ }
+ }
+#endif
+ return res;
+}
+
+
ZOOM_API(const char *)
ZOOM_record_get(ZOOM_record rec, const char *type_spec, int *len)
{
char type[40];
char charset[40];
- char xpath[512];
+ char format[3];
const char *cp;
- int i;
+ size_t i;
Z_NamePlusRecord *npr;
if (len)
return 0;
cp = type_spec;
- for (i = 0; cp[i] && i < sizeof(type)-1; i++)
- {
- if (cp[i] == ';' || cp[i] == ' ')
- break;
+ for (i = 0; cp[i] && cp[i] != ';' && cp[i] != ' ' && i < sizeof(type)-1;
+ i++)
type[i] = cp[i];
- }
type[i] = '\0';
charset[0] = '\0';
- while (type_spec[i] == ';')
+ format[0] = '\0';
+ while (1)
{
+ while (cp[i] == ' ')
+ i++;
+ if (cp[i] != ';')
+ break;
i++;
- while (type_spec[i] == ' ')
+ while (cp[i] == ' ')
i++;
- if (!strncmp(type_spec+i, "charset=", 8))
+ if (!strncmp(cp + i, "charset=", 8))
{
- int j = 0;
+ size_t j = 0;
i = i + 8; /* skip charset= */
- for (j = 0; type_spec[i] && j < sizeof(charset)-1; i++, j++)
+ for (j = 0; cp[i] && cp[i] != ';' && cp[i] != ' '; i++)
{
- if (type_spec[i] == ';' || type_spec[i] == ' ')
- break;
- charset[j] = cp[i];
+ if (j < sizeof(charset)-1)
+ charset[j++] = cp[i];
}
charset[j] = '\0';
}
- else if (!strncmp(type_spec+i, "xpath=", 6))
+ else if (!strncmp(cp + i, "format=", 7))
{
- int j = 0;
- i = i + 6;
- for (j = 0; type_spec[i] && j < sizeof(xpath)-1; i++, j++)
- xpath[j] = cp[i];
- xpath[j] = '\0';
+ size_t j = 0;
+ i = i + 7;
+ for (j = 0; cp[i] && cp[i] != ';' && cp[i] != ' '; i++)
+ {
+ if (j < sizeof(format)-1)
+ format[j++] = cp[i];
+ }
+ format[j] = '\0';
}
- while (type_spec[i] == ' ')
- i++;
}
if (!strcmp(type, "database"))
{
/* from now on - we have a database record .. */
if (!strcmp(type, "render"))
{
- Z_External *r = (Z_External *) npr->u.databaseRecord;
- const Odr_oid *oid = r->direct_reference;
-
- /* render bibliographic record .. */
- if (r->which == Z_External_OPAC)
- {
- r = r->u.opac->bibliographicRecord;
- if (!r)
- return 0;
- oid = r->direct_reference;
- }
- if (r->which == Z_External_sutrs)
- return record_iconv_return(rec, len,
- (char*) r->u.sutrs->buf,
- r->u.sutrs->len,
- charset);
- else if (r->which == Z_External_octet)
- {
- if (yaz_oid_is_iso2709(oid))
- {
- const char *ret_buf = marc_iconv_return(
- rec, YAZ_MARC_LINE, len,
- (const char *) r->u.octet_aligned->buf,
- r->u.octet_aligned->len,
- charset);
- if (ret_buf)
- return ret_buf;
- }
- return record_iconv_return(rec, len,
- (const char *) r->u.octet_aligned->buf,
- r->u.octet_aligned->len,
- charset);
- }
- else if (r->which == Z_External_grs1)
- {
- if (!rec->wrbuf_marc)
- rec->wrbuf_marc = wrbuf_alloc();
- wrbuf_rewind(rec->wrbuf_marc);
- yaz_display_grs1(rec->wrbuf_marc, r->u.grs1, 0);
- return record_iconv_return(rec, len,
- wrbuf_buf(rec->wrbuf_marc),
- wrbuf_len(rec->wrbuf_marc),
- charset);
- }
- return 0;
+ return get_record_format(rec, len, npr, YAZ_MARC_LINE, charset, format);
}
else if (!strcmp(type, "xml"))
{
- Z_External *r = (Z_External *) npr->u.databaseRecord;
- const Odr_oid *oid = r->direct_reference;
-
- /* render bibliographic record .. */
- if (r->which == Z_External_OPAC)
- {
- r = r->u.opac->bibliographicRecord;
- if (!r)
- return 0;
- oid = r->direct_reference;
- }
-
- if (r->which == Z_External_sutrs)
- return record_iconv_return(rec, len,
- (const char *) r->u.sutrs->buf,
- r->u.sutrs->len,
- charset);
- else if (r->which == Z_External_octet)
- {
- int marc_decode_type = YAZ_MARC_MARCXML;
- if (yaz_oid_is_iso2709(oid))
- {
- const char *ret_buf = marc_iconv_return(
- rec, marc_decode_type, len,
- (const char *) r->u.octet_aligned->buf,
- r->u.octet_aligned->len,
- charset);
- if (ret_buf)
- return ret_buf;
- }
- return record_iconv_return(rec, len,
- (const char *) r->u.octet_aligned->buf,
- r->u.octet_aligned->len,
- charset);
- }
- else if (r->which == Z_External_grs1)
- {
- if (len) *len = 5;
- return "GRS-1";
- }
- return 0;
+ return get_record_format(rec, len, npr, YAZ_MARC_MARCXML, charset,
+ format);
+ }
+ else if (!strcmp(type, "txml"))
+ {
+ return get_record_format(rec, len, npr, YAZ_MARC_TMARCXML, charset,
+ format);
}
else if (!strcmp(type, "raw"))
{
- Z_External *r = (Z_External *) npr->u.databaseRecord;
-
- if (r->which == Z_External_sutrs)
- {
- if (len) *len = r->u.sutrs->len;
- return (const char *) r->u.sutrs->buf;
- }
- else if (r->which == Z_External_octet)
- {
- if (len) *len = r->u.octet_aligned->len;
- return (const char *) r->u.octet_aligned->buf;
- }
- else /* grs-1, explain, OPAC, ... */
- {
- if (len) *len = -1;
- return (const char *) npr->u.databaseRecord;
- }
- return 0;
+ return get_record_format(rec, len, npr, YAZ_MARC_ISO2709, charset,
+ format);
}
- else if (!strcmp (type, "ext"))
+ else if (!strcmp(type, "ext"))
{
if (len) *len = -1;
return (const char *) npr->u.databaseRecord;
}
- else if (!strcmp (type, "opac"))
-
+ else if (!strcmp(type, "opac"))
{
- Z_External *r = (Z_External *) npr->u.databaseRecord;
- if (r->which == Z_External_OPAC)
- {
- if (!rec->wrbuf_opac)
- rec->wrbuf_opac = wrbuf_alloc();
- wrbuf_rewind(rec->wrbuf_opac);
- yaz_display_OPAC(rec->wrbuf_opac, r->u.opac, 0);
- return record_iconv_return(rec, len,
- wrbuf_buf(rec->wrbuf_opac),
- wrbuf_len(rec->wrbuf_opac),
- charset);
- }
+ if (npr->u.databaseRecord->which == Z_External_OPAC)
+ return get_record_format(rec, len, npr, YAZ_MARC_MARCXML, charset,
+ format);
}
return 0;
}
{
rc = (ZOOM_record_cache) odr_malloc(r->odr, sizeof(*rc));
rc->rec.odr = 0;
- rc->rec.wrbuf_marc = 0;
- rc->rec.wrbuf_iconv = 0;
- rc->rec.wrbuf_opac = 0;
+ rc->rec.wrbuf = 0;
+#if YAZ_HAVE_XML2
+ rc->rec.xml_mem = 0;
+#endif
rc->elementSetName = odr_strdup_null(r->odr, elementSetName);
rc->syntax = odr_strdup_null(r->odr, syntax);
yaz_log(log_details, "%p send_present skip=%d", c, i);
*req->resultSetStartPoint = *start + 1;
- *req->numberOfRecordsRequested = resultset->step>0 ?
- resultset->step : *count;
+
+ if (resultset->step > 0 && resultset->step < *count)
+ *req->numberOfRecordsRequested = resultset->step;
+ else
+ *req->numberOfRecordsRequested = *count;
+
if (*req->numberOfRecordsRequested + *start > resultset->size)
*req->numberOfRecordsRequested = resultset->size - *start;
assert(*req->numberOfRecordsRequested > 0);
}
static void ZOOM_scanset_term_x(ZOOM_scanset scan, size_t pos,
- int *occ,
+ size_t *occ,
const char **value_term, size_t *value_len,
const char **disp_term, size_t *disp_len)
{
*disp_len = 0;
*occ = 0;
- if (pos >= noent || pos < 0)
+ if (pos >= noent)
return;
if (scan->scan_response)
{
ZOOM_API(const char *)
ZOOM_scanset_term(ZOOM_scanset scan, size_t pos,
- int *occ, int *len)
+ size_t *occ, size_t *len)
{
const char *value_term = 0;
size_t value_len = 0;
ZOOM_API(const char *)
ZOOM_scanset_display_term(ZOOM_scanset scan, size_t pos,
- int *occ, int *len)
+ size_t *occ, size_t *len)
{
const char *value_term = 0;
size_t value_len = 0;
req->u.esRequest->notToKeep->resultSetItem->resultSetId =
odr_strdup(p->odr_out, str);
req->u.esRequest->notToKeep->resultSetItem->item =
- (int *) odr_malloc(p->odr_out, sizeof(int));
+ odr_intdup(p->odr_out, 0);
str = ZOOM_options_get(p->options, "itemorder-item");
*req->u.esRequest->notToKeep->resultSetItem->item =
}
#if YAZ_HAVE_XML2
-static void handle_srw_response(ZOOM_connection c,
- Z_SRW_searchRetrieveResponse *res)
+static zoom_ret handle_srw_response(ZOOM_connection c,
+ Z_SRW_searchRetrieveResponse *res)
{
ZOOM_resultset resultset = 0;
int i;
NMEM nmem;
ZOOM_Event event;
- int *start;
+ int *start, *count;
const char *syntax, *elementSetName;
if (!c->tasks)
- return;
+ return zoom_complete;
switch(c->tasks->which)
{
case ZOOM_TASK_SEARCH:
resultset = c->tasks->u.search.resultset;
start = &c->tasks->u.search.start;
+ count = &c->tasks->u.search.count;
syntax = c->tasks->u.search.syntax;
elementSetName = c->tasks->u.search.elementSetName;
+
+ if (!c->tasks->u.search.recv_search_fired)
+ {
+ event = ZOOM_Event_create(ZOOM_EVENT_RECV_SEARCH);
+ ZOOM_connection_put_event(c, event);
+ c->tasks->u.search.recv_search_fired = 1;
+ }
break;
case ZOOM_TASK_RETRIEVE:
resultset = c->tasks->u.retrieve.resultset;
start = &c->tasks->u.retrieve.start;
+ count = &c->tasks->u.retrieve.count;
syntax = c->tasks->u.retrieve.syntax;
elementSetName = c->tasks->u.retrieve.elementSetName;
break;
default:
- return;
+ return zoom_complete;
}
- event = ZOOM_Event_create(ZOOM_EVENT_RECV_SEARCH);
- ZOOM_connection_put_event(c, event);
resultset->size = 0;
ZOOM_resultset_option_set(resultset, "resultSetId", res->resultSetId);
yaz_log(log_details, "%p handle_srw_response got SRW response OK", c);
-
- if (res->numberOfRecords)
- resultset->size = *res->numberOfRecords;
- for (i = 0; i<res->num_records; i++)
+ if (res->num_diagnostics > 0)
{
- int pos;
- Z_SRW_record *sru_rec;
- Z_SRW_diagnostic *diag = 0;
- int num_diag;
-
- Z_NamePlusRecord *npr = (Z_NamePlusRecord *)
- odr_malloc(c->odr_in, sizeof(Z_NamePlusRecord));
-
- if (res->records[i].recordPosition &&
- *res->records[i].recordPosition > 0)
- pos = *res->records[i].recordPosition - 1;
- else
- pos = *start + i;
-
- sru_rec = &res->records[i];
-
- npr->databaseName = 0;
- npr->which = Z_NamePlusRecord_databaseRecord;
- npr->u.databaseRecord = (Z_External *)
- odr_malloc(c->odr_in, sizeof(Z_External));
- npr->u.databaseRecord->descriptor = 0;
- npr->u.databaseRecord->direct_reference =
- odr_oiddup(c->odr_in, yaz_oid_recsyn_xml);
- npr->u.databaseRecord->which = Z_External_octet;
-
- npr->u.databaseRecord->u.octet_aligned = (Odr_oct *)
- odr_malloc(c->odr_in, sizeof(Odr_oct));
- npr->u.databaseRecord->u.octet_aligned->buf = (unsigned char*)
- sru_rec->recordData_buf;
- npr->u.databaseRecord->u.octet_aligned->len =
- npr->u.databaseRecord->u.octet_aligned->size =
- sru_rec->recordData_len;
-
- if (sru_rec->recordSchema
- && !strcmp(sru_rec->recordSchema,
- "info:srw/schema/1/diagnostics-v1.1"))
+ set_SRU_error(c, &res->diagnostics[0]);
+ }
+ else
+ {
+ if (res->numberOfRecords)
+ resultset->size = *res->numberOfRecords;
+ for (i = 0; i<res->num_records; i++)
{
- sru_decode_surrogate_diagnostics(sru_rec->recordData_buf,
- sru_rec->recordData_len,
- &diag, &num_diag,
- resultset->odr);
+ int pos;
+ Z_SRW_record *sru_rec;
+ Z_SRW_diagnostic *diag = 0;
+ int num_diag;
+
+ Z_NamePlusRecord *npr = (Z_NamePlusRecord *)
+ odr_malloc(c->odr_in, sizeof(Z_NamePlusRecord));
+
+ if (res->records[i].recordPosition &&
+ *res->records[i].recordPosition > 0)
+ pos = *res->records[i].recordPosition - 1;
+ else
+ pos = *start + i;
+
+ sru_rec = &res->records[i];
+
+ npr->databaseName = 0;
+ npr->which = Z_NamePlusRecord_databaseRecord;
+ npr->u.databaseRecord = (Z_External *)
+ odr_malloc(c->odr_in, sizeof(Z_External));
+ npr->u.databaseRecord->descriptor = 0;
+ npr->u.databaseRecord->direct_reference =
+ odr_oiddup(c->odr_in, yaz_oid_recsyn_xml);
+ npr->u.databaseRecord->which = Z_External_octet;
+
+ npr->u.databaseRecord->u.octet_aligned = (Odr_oct *)
+ odr_malloc(c->odr_in, sizeof(Odr_oct));
+ npr->u.databaseRecord->u.octet_aligned->buf = (unsigned char*)
+ sru_rec->recordData_buf;
+ npr->u.databaseRecord->u.octet_aligned->len =
+ npr->u.databaseRecord->u.octet_aligned->size =
+ sru_rec->recordData_len;
+
+ if (sru_rec->recordSchema
+ && !strcmp(sru_rec->recordSchema,
+ "info:srw/schema/1/diagnostics-v1.1"))
+ {
+ sru_decode_surrogate_diagnostics(sru_rec->recordData_buf,
+ sru_rec->recordData_len,
+ &diag, &num_diag,
+ resultset->odr);
+ }
+ record_cache_add(resultset, npr, pos, syntax, elementSetName,
+ sru_rec->recordSchema, diag);
}
- record_cache_add(resultset, npr, pos, syntax, elementSetName,
- sru_rec->recordSchema, diag);
+ *count -= i;
+ *start += i;
+ if (*count + *start > resultset->size)
+ *count = resultset->size - *start;
+ if (*count < 0)
+ *count = 0;
+
+ nmem = odr_extract_mem(c->odr_in);
+ nmem_transfer(odr_getmem(resultset->odr), nmem);
+ nmem_destroy(nmem);
+
+ if (*count > 0)
+ return ZOOM_connection_srw_send_search(c);
}
- if (res->num_diagnostics > 0)
- set_SRU_error(c, &res->diagnostics[0]);
- nmem = odr_extract_mem(c->odr_in);
- nmem_transfer(odr_getmem(resultset->odr), nmem);
- nmem_destroy(nmem);
+ return zoom_complete;
}
#endif
#if YAZ_HAVE_XML2
static void handle_http(ZOOM_connection c, Z_HTTP_Response *hres)
{
+ zoom_ret cret = zoom_complete;
int ret = -1;
const char *addinfo = 0;
const char *connection_head = z_HTTP_header_lookup(hres->headers,
Z_SRW_PDU *sr = (Z_SRW_PDU*) soap_package->u.generic->p;
ZOOM_options_set(c->options, "sru_version", sr->srw_version);
+ ZOOM_options_setl(c->options, "sru_extra_response_data",
+ sr->extraResponseData_buf, sr->extraResponseData_len);
if (sr->which == Z_SRW_searchRetrieve_response)
- handle_srw_response(c, sr->u.response);
+ cret = handle_srw_response(c, sr->u.response);
else if (sr->which == Z_SRW_scan_response)
handle_srw_scan_response(c, sr->u.scan_response);
else
set_ZOOM_error(c, ZOOM_ERROR_DECODE, addinfo);
do_close(c);
}
- ZOOM_connection_remove_task(c);
+ if (cret == zoom_complete)
+ ZOOM_connection_remove_task(c);
if (!strcmp(hres->version, "1.0"))
{
/* HTTP 1.0: only if Keep-Alive we stay alive.. */
}
do_close(c);
}
- else if (gdu->which == Z_GDU_Z3950)
- recv_apdu(c, gdu->u.z3950);
- else if (gdu->which == Z_GDU_HTTP_Response)
+ else
{
+ if (c->odr_print)
+ z_GDU(c->odr_print, &gdu, 0, 0);
+ if (gdu->which == Z_GDU_Z3950)
+ recv_apdu(c, gdu->u.z3950);
+ else if (gdu->which == Z_GDU_HTTP_Response)
+ {
#if YAZ_HAVE_XML2
- handle_http(c, gdu->u.HTTP_Response);
+ handle_http(c, gdu->u.HTTP_Response);
#else
- set_ZOOM_error(c, ZOOM_ERROR_DECODE, 0);
- do_close(c);
+ set_ZOOM_error(c, ZOOM_ERROR_DECODE, 0);
+ do_close(c);
#endif
+ }
}
c->reconnect_ok = 0;
}
return ZOOM_options_get_int(c->options, "timeout", 30);
}
+ZOOM_API(void) ZOOM_connection_close(ZOOM_connection c)
+{
+ do_close(c);
+}
+
/*
* Local variables:
* c-basic-offset: 4
+ * c-file-style: "Stroustrup"
* indent-tabs-mode: nil
* End:
* vim: shiftwidth=4 tabstop=8 expandtab