* Copyright (c) 2000-2003, Index Data
* See the file LICENSE for details.
*
- * $Id: zoom-c.c,v 1.19 2003-02-14 19:10:00 adam Exp $
+ * $Id: zoom-c.c,v 1.35 2003-05-20 08:22:33 adam Exp $
*
* ZOOM layer for C, connections, result sets, queries.
*/
#include <string.h>
#include "zoom-p.h"
+#include <yaz/yaz-util.h>
#include <yaz/xmalloc.h>
#include <yaz/otherinfo.h>
#include <yaz/log.h>
{
ZOOM_Event event = c->m_queue_front;
if (!event)
+ {
+ c->last_event = ZOOM_EVENT_NONE;
return 0;
+ }
assert (c->m_queue_back);
c->m_queue_front = event->prev;
if (c->m_queue_front)
return event;
}
-static void set_bib1_error (ZOOM_connection c, int error)
+
+static void set_dset_error (ZOOM_connection c, int error,
+ const char *dset,
+ const char *addinfo, const char *addinfo2)
{
xfree (c->addinfo);
c->addinfo = 0;
c->error = error;
- c->diagset = "Bib-1";
+ c->diagset = dset;
+ if (addinfo && addinfo2)
+ {
+ c->addinfo = xmalloc(strlen(addinfo) + strlen(addinfo2) + 2);
+ strcpy(c->addinfo, addinfo);
+ strcat(c->addinfo, addinfo2);
+ }
+ else if (addinfo)
+ c->addinfo = xstrdup(addinfo);
+ if (error)
+ yaz_log(LOG_DEBUG, "Error %s %s:%d %s %s",
+ c->host_port ? c->host_port : "<>", dset, error,
+ addinfo ? addinfo : "",
+ addinfo2 ? addinfo2 : "");
}
+#if HAVE_XML2
+static void set_HTTP_error (ZOOM_connection c, int error,
+ const char *addinfo, const char *addinfo2)
+{
+ set_dset_error(c, error, "HTTP", addinfo, addinfo2);
+}
+#endif
+
static void set_ZOOM_error (ZOOM_connection c, int error,
const char *addinfo)
{
- xfree (c->addinfo);
- c->addinfo = 0;
- c->error = error;
- c->diagset = "ZOOM";
- if (addinfo)
- c->addinfo = xstrdup(addinfo);
+ set_dset_error(c, error, "ZOOM", addinfo, 0);
}
static void clear_error (ZOOM_connection c)
switch (task->which)
{
case ZOOM_TASK_SEARCH:
+
ZOOM_resultset_destroy (task->u.search.resultset);
break;
case ZOOM_TASK_RETRIEVE:
c->lang = 0;
xfree (c->host_port);
- xfree (c->path);
if (portnum)
{
char hostn[128];
s->z_query = 0;
s->sort_spec = 0;
s->odr = odr_createmem (ODR_ENCODE);
+ s->query_string = 0;
return s;
}
ZOOM_API(int)
ZOOM_query_prefix(ZOOM_query s, const char *str)
{
+ s->query_string = odr_strdup(s->odr, str);
s->z_query = (Z_Query *) odr_malloc (s->odr, sizeof(*s->z_query));
s->z_query->which = Z_Query_type_1;
s->z_query->u.type_1 = p_query_rpn(s->odr, PROTO_Z3950, str);
{
Z_External *ext;
+ s->query_string = odr_strdup(s->odr, str);
+
ext = (Z_External *) odr_malloc(s->odr, sizeof(*ext));
ext->direct_reference = odr_getoidbystr(s->odr, "1.2.840.10003.16.2");
ext->indirect_reference = 0;
ext->descriptor = 0;
ext->which = Z_External_CQL;
- ext->u.cql = odr_strdup(s->odr, str);
+ ext->u.cql = s->query_string;
s->z_query = (Z_Query *) odr_malloc (s->odr, sizeof(*s->z_query));
s->z_query->which = Z_Query_type_104;
s->z_query->u.type_104 = ext;
+
return 0;
}
ZOOM_options_destroy (c->options);
ZOOM_connection_remove_tasks (c);
xfree (c->host_port);
+ xfree (c->path);
xfree (c->proxy);
xfree (c->charset);
xfree (c->lang);
r->start = 0;
r->piggyback = 1;
r->setname = 0;
+ r->schema = 0;
r->count = 0;
+ r->step = 0;
r->record_cache = 0;
r->r_sort_spec = 0;
- r->z_query = 0;
- r->search = 0;
+ r->query = 0;
r->connection = 0;
r->next = 0;
return r;
const char *cp;
r->r_sort_spec = q->sort_spec;
- r->z_query = q->z_query;
- r->search = q;
+ r->query = q;
r->options = ZOOM_options_create_with_parent(c->options);
r->start = ZOOM_options_get_int(r->options, "start", 0);
r->count = ZOOM_options_get_int(r->options, "count", 0);
+ r->step = ZOOM_options_get_int(r->options, "step", 0);
r->piggyback = ZOOM_options_get_bool (r->options, "piggyback", 1);
cp = ZOOM_options_get (r->options, "setname");
if (cp)
- r->setname = xstrdup (cp);
+ r->setname = xstrdup(cp);
+ cp = ZOOM_options_get (r->options, "schema");
+ if (cp)
+ r->schema = xstrdup(cp);
r->connection = c;
r->next = c->resultsets;
c->resultsets = r;
+ if (c->host_port && c->proto == PROTO_HTTP)
+ {
+ if (!c->cs)
+ {
+ yaz_log(LOG_DEBUG, "NO COMSTACK");
+ ZOOM_connection_add_task(c, ZOOM_TASK_CONNECT);
+ }
+ else
+ {
+ yaz_log(LOG_DEBUG, "PREPARE FOR RECONNECT");
+ c->reconnect_ok = 1;
+ }
+ }
+
task = ZOOM_connection_add_task (c, ZOOM_TASK_SEARCH);
task->u.search.resultset = r;
ZOOM_resultset_addref (r);
rp = &(*rp)->next;
}
}
- ZOOM_query_destroy (r->search);
+ ZOOM_query_destroy (r->query);
ZOOM_options_destroy (r->options);
odr_destroy (r->odr);
xfree (r->setname);
+ xfree (r->schema);
xfree (r);
}
}
{
ZOOM_task task;
ZOOM_connection c;
+ const char *cp;
if (!r)
return;
c = r->connection;
if (!c)
return;
+
+ if (c->host_port && c->proto == PROTO_HTTP)
+ {
+ if (!c->cs)
+ {
+ yaz_log(LOG_DEBUG, "NO COMSTACK");
+ ZOOM_connection_add_task(c, ZOOM_TASK_CONNECT);
+ }
+ else
+ {
+ yaz_log(LOG_DEBUG, "PREPARE FOR RECONNECT");
+ c->reconnect_ok = 1;
+ }
+ }
task = ZOOM_connection_add_task (c, ZOOM_TASK_RETRIEVE);
task->u.retrieve.resultset = r;
task->u.retrieve.start = start;
task->u.retrieve.count = count;
+ cp = ZOOM_options_get (r->options, "schema");
+ if (cp)
+ {
+ if (!r->schema || strcmp(r->schema, cp))
+ {
+ xfree(r->schema);
+ r->schema = xstrdup(cp);
+ }
+ }
+
ZOOM_resultset_addref (r);
if (!r->connection->async || force_sync)
yaz_log (LOG_DEBUG, "do_connect host=%s", effective_host);
assert (!c->cs);
+ c->cs = cs_create_host (effective_host, 0, &add);
+
+ if (c->cs && c->cs->protocol == PROTO_HTTP)
+ {
+#if HAVE_XML2
+ const char *path = 0;
- if (memcmp(c->host_port, "http:", 5) == 0)
- {
-#if HAVE_XSLT
- const char *path;
- c->proto = PROTO_SRW;
- effective_host = c->host_port + 5;
- if (*effective_host == '/')
- effective_host++;
- if (*effective_host == '/')
- effective_host++;
- if (!(path = strchr(effective_host, '/')))
- path = "/";
+ c->proto = PROTO_HTTP;
+ cs_get_host_args(c->host_port, &path);
xfree(c->path);
- c->path = xstrdup(path);
+ c->path = xmalloc(strlen(path)+2);
+ c->path[0] = '/';
+ strcpy (c->path+1, path);
#else
- c->state = STATE_IDLE;
set_ZOOM_error(c, ZOOM_ERROR_UNSUPPORTED_PROTOCOL, "SRW");
+ do_close(c);
return zoom_complete;
#endif
}
- c->cs = cs_create_host (effective_host, 0, &add);
-
if (c->cs)
{
int ret = cs_connect (c->cs, add);
return send_APDU (c, apdu);
}
-#if HAVE_XSLT
-static zoom_ret send_srw (ZOOM_connection c, Z_SRW_searchRetrieve *sr)
+#if HAVE_XML2
+static zoom_ret send_srw (ZOOM_connection c, Z_SRW_PDU *sr)
{
+ char ctype[50];
Z_SOAP_Handler h[2] = {
{"http://www.loc.gov/zing/srw/v1.0/", 0, (Z_SOAP_fun) yaz_srw_codec},
{0, 0, 0}
gdu = z_get_HTTP_Request(c->odr_out);
gdu->u.HTTP_Request->path = c->path;
+
+ if (c->host_port)
+ {
+ const char *cp0 = strstr(c->host_port, "://");
+ const char *cp1 = 0;
+ if (cp0)
+ cp0 = cp0+3;
+ else
+ cp0 = c->host_port;
+
+ cp1 = strchr(cp0, '/');
+ if (!cp1)
+ cp1 = cp0+strlen(cp0);
+
+ if (cp0 && cp1)
+ {
+ char *h = odr_malloc(c->odr_out, cp1 - cp0 + 1);
+ memcpy (h, cp0, cp1 - cp0);
+ h[cp1-cp0] = '\0';
+ z_HTTP_header_add(c->odr_out, &gdu->u.HTTP_Request->headers,
+ "host", h);
+ }
+ }
+
+ strcpy(ctype, "text/xml");
+ if (c->charset && strlen(c->charset) < 20)
+ {
+ strcat(ctype, "; charset=");
+ strcat(ctype, c->charset);
+ }
z_HTTP_header_add(c->odr_out, &gdu->u.HTTP_Request->headers,
- "Content-Type", "text/xml");
+ "Content-Type", ctype);
z_HTTP_header_add(c->odr_out, &gdu->u.HTTP_Request->headers,
"SOAPAction", "\"\"");
p->which = Z_SOAP_generic;
p->u.generic->p = sr;
p->ns = "http://schemas.xmlsoap.org/soap/envelope/";
- ret = z_soap_codec(o, &p,
- &gdu->u.HTTP_Request->content_buf,
- &gdu->u.HTTP_Request->content_len, h);
+ ret = z_soap_codec_enc(o, &p,
+ &gdu->u.HTTP_Request->content_buf,
+ &gdu->u.HTTP_Request->content_len, h,
+ c->charset);
if (!z_GDU(c->odr_out, &gdu, 0, 0))
return zoom_complete;
}
#endif
-#if HAVE_XSLT
+#if HAVE_XML2
static zoom_ret ZOOM_connection_srw_send_search(ZOOM_connection c)
{
- ZOOM_resultset resultset;
- Z_SRW_searchRetrieve *sr = yaz_srw_get(c->odr_out,
- Z_SRW_searchRetrieve_request);
+ int i;
+ ZOOM_resultset resultset = 0;
+ Z_SRW_PDU *sr = 0;
+ const char *recordPacking = 0;
+ if (c->error) /* don't continue on error */
+ return zoom_complete;
assert (c->tasks);
- assert (c->tasks->which == ZOOM_TASK_SEARCH);
-
- resultset = c->tasks->u.search.resultset;
- assert(resultset);
- assert (resultset->z_query);
+ if (c->tasks->which == ZOOM_TASK_SEARCH)
+ {
+ resultset = c->tasks->u.search.resultset;
+ resultset->setname = xstrdup ("default");
+ ZOOM_options_set (resultset->options, "setname", resultset->setname);
+ }
+ else if(c->tasks->which == ZOOM_TASK_RETRIEVE)
+ {
+ resultset = c->tasks->u.retrieve.resultset;
- if (resultset->z_query->which == Z_Query_type_104
- && resultset->z_query->u.type_104->which == Z_External_CQL)
- sr->u.request->query = resultset->z_query->u.type_104->u.cql;
- else
- sr->u.request->query = "dc.title = computer";
+ resultset->start = c->tasks->u.retrieve.start;
+ resultset->count = c->tasks->u.retrieve.count;
+
+ if (resultset->start >= resultset->size)
+ return zoom_complete;
+ if (resultset->start + resultset->count > resultset->size)
+ resultset->count = resultset->size - resultset->start;
+
+ for (i = 0; i<resultset->count; i++)
+ {
+ ZOOM_record rec =
+ record_cache_lookup (resultset, i + resultset->start);
+ if (!rec)
+ break;
+ }
+ if (i == resultset->count)
+ return zoom_complete;
+ }
+ assert(resultset->query);
+
+ sr = yaz_srw_get(c->odr_out, Z_SRW_searchRetrieve_request);
+ if (resultset->query->z_query->which == Z_Query_type_104
+ && resultset->query->z_query->u.type_104->which == Z_External_CQL)
+ {
+
+ sr->u.request->query_type = Z_SRW_query_type_cql;
+ sr->u.request->query.cql =resultset->query->z_query->u.type_104->u.cql;
+ }
+ else if (resultset->query->z_query->which == Z_Query_type_1 &&
+ resultset->query->z_query->u.type_1)
+ {
+ sr->u.request->query_type = Z_SRW_query_type_pqf;
+ sr->u.request->query.pqf = resultset->query->query_string;
+ }
+ else
+ {
+ set_ZOOM_error(c, ZOOM_ERROR_UNSUPPORTED_QUERY, 0);
+ return zoom_complete;
+ }
sr->u.request->startRecord = odr_intdup (c->odr_out, resultset->start + 1);
- sr->u.request->maximumRecords = odr_intdup (c->odr_out, resultset->count);
-
+ sr->u.request->maximumRecords = odr_intdup (
+ c->odr_out, resultset->step>0 ? resultset->step : resultset->count);
+ sr->u.request->recordSchema = resultset->schema;
+
+ recordPacking = ZOOM_resultset_option_get (resultset, "recordPacking");
+
+ if (recordPacking)
+ sr->u.request->recordPacking = odr_strdup(c->odr_out, recordPacking);
+
return send_srw(c, sr);
}
#else
const char *elementSetName;
const char *smallSetElementSetName;
const char *mediumSetElementSetName;
- const char *schema;
assert (c->tasks);
assert (c->tasks->which == ZOOM_TASK_SEARCH);
ZOOM_options_get (r->options, "smallSetElementSetName");
mediumSetElementSetName =
ZOOM_options_get (r->options, "mediumSetElementSetName");
- schema =
- ZOOM_options_get (r->options, "schema");
if (!smallSetElementSetName)
smallSetElementSetName = elementSetName;
mediumSetElementSetName = elementSetName;
assert (r);
- assert (r->z_query);
+ assert (r->query);
/* prepare query for the search request */
- search_req->query = r->z_query;
+ search_req->query = r->query->z_query;
search_req->databaseNames =
set_DatabaseNames (c, r->options, &search_req->num_databaseNames);
*search_req->mediumSetPresentNumber = mspn;
}
else if (r->start == 0 && r->count > 0
- && r->piggyback && !r->r_sort_spec && !schema)
+ && r->piggyback && !r->r_sort_spec && !r->schema)
{
/* Regular piggyback - do it unless we're going to do sort */
*search_req->largeSetLowerBound = 2000000000;
*search_req->smallSetUpperBound = 0;
- *search_req->mediumSetPresentNumber = r->count;
+ *search_req->mediumSetPresentNumber = r->step>0 ? r->step : r->count;
smallSetElementSetName = 0;
}
else
return;
}
r = p->u.defaultFormat;
- c->diagset = yaz_z3950oid_to_str(r->diagnosticSetId, &oclass);
-
switch (r->which)
{
case Z_DefaultDiagFormat_v2Addinfo:
addinfo = r->u.v3Addinfo;
break;
}
- if (addinfo)
- c->addinfo = xstrdup (addinfo);
- c->error = *r->condition;
+ set_dset_error(c, *r->condition,
+ yaz_z3950oid_to_str(r->diagnosticSetId, &oclass),
+ addinfo, 0);
}
ZOOM_API(ZOOM_record)
ZOOM_API(ZOOM_record)
ZOOM_resultset_record (ZOOM_resultset r, size_t pos)
{
- ZOOM_resultset_retrieve (r, 1, pos, 1);
- return ZOOM_resultset_record_immediate (r, pos);
+ ZOOM_record rec = ZOOM_resultset_record_immediate(r, pos);
+
+ if (!rec)
+ {
+ ZOOM_resultset_retrieve (r, 1, pos, 1);
+ rec = ZOOM_resultset_record_immediate (r, pos);
+ }
+ return rec;
}
ZOOM_API(void)
if (len) *len = 5;
return "GRS-1";
}
+ else if (r->which == Z_External_OPAC)
+ {
+ if (len) *len = 4;
+ return "OPAC";
+ }
return 0;
}
else if (!strcmp (type, "raw"))
return 0;
}
-static void record_cache_add (ZOOM_resultset r, Z_NamePlusRecord *npr, int pos)
+static int strcmp_null(const char *v1, const char *v2)
+{
+ if (!v1 && !v2)
+ return 0;
+ if (!v1 || !v2)
+ return -1;
+ return strcmp(v1, v2);
+}
+
+static void record_cache_add (ZOOM_resultset r, Z_NamePlusRecord *npr,
+ int pos)
{
ZOOM_record_cache rc;
const char *elementSetName =
const char *syntax =
ZOOM_resultset_option_get (r, "preferredRecordSyntax");
+ ZOOM_Event event = ZOOM_Event_create(ZOOM_EVENT_RECV_RECORD);
+ ZOOM_connection_put_event(r->connection, event);
+
for (rc = r->record_cache; rc; rc = rc->next)
{
if (pos == rc->pos)
{
- if ((!elementSetName && !rc->elementSetName)
- || (elementSetName && rc->elementSetName &&
- !strcmp (elementSetName, rc->elementSetName)))
- {
- if ((!syntax && !rc->syntax)
- || (syntax && rc->syntax &&
- !strcmp (syntax, rc->syntax)))
- {
- /* not destroying rc->npr (it's handled by nmem )*/
- rc->rec.npr = npr;
- /* keeping wrbuf_marc too */
- return;
- }
- }
+ if (strcmp_null(r->schema, rc->schema))
+ continue;
+ if (strcmp_null(elementSetName,rc->elementSetName))
+ continue;
+ if (strcmp_null(syntax, rc->syntax))
+ continue;
+ /* not destroying rc->npr (it's handled by nmem )*/
+ rc->rec.npr = npr;
+ /* keeping wrbuf_marc too */
+ return;
}
}
rc = (ZOOM_record_cache) odr_malloc (r->odr, sizeof(*rc));
else
rc->syntax = 0;
+ if (r->schema)
+ rc->schema = odr_strdup (r->odr, r->schema);
+ else
+ rc->schema = 0;
+
rc->pos = pos;
rc->next = r->record_cache;
r->record_cache = rc;
{
if (pos == rc->pos)
{
- if ((!elementSetName && !rc->elementSetName)
- || (elementSetName && rc->elementSetName &&
- !strcmp (elementSetName, rc->elementSetName)))
- {
- if ((!syntax && !rc->syntax)
- || (syntax && rc->syntax &&
- !strcmp (syntax, rc->syntax)))
- return &rc->rec;
- }
+ if (strcmp_null(r->schema, rc->schema))
+ continue;
+ if (strcmp_null(elementSetName,rc->elementSetName))
+ continue;
+ if (strcmp_null(syntax, rc->syntax))
+ continue;
+ return &rc->rec;
}
}
return 0;
static void handle_search_response (ZOOM_connection c, Z_SearchResponse *sr)
{
ZOOM_resultset resultset;
-
+ ZOOM_Event event;
+
yaz_log (LOG_DEBUG, "got search response");
-
+
if (!c->tasks || c->tasks->which != ZOOM_TASK_SEARCH)
return ;
+
+ event = ZOOM_Event_create(ZOOM_EVENT_RECV_SEARCH);
+ ZOOM_connection_put_event(c, event);
resultset = c->tasks->u.search.resultset;
int i = 0;
const char *syntax = 0;
const char *elementSetName = 0;
- const char *schema = 0;
ZOOM_resultset resultset;
if (!c->tasks)
syntax = ZOOM_resultset_option_get (resultset, "preferredRecordSyntax");
elementSetName = ZOOM_resultset_option_get (resultset, "elementSetName");
- schema = ZOOM_resultset_option_get (resultset, "schema");
if (c->error) /* don't continue on error */
return zoom_complete;
resultset->start += i;
resultset->count -= i;
*req->resultSetStartPoint = resultset->start + 1;
- *req->numberOfRecordsRequested = resultset->count;
+ *req->numberOfRecordsRequested = resultset->step>0 ?
+ resultset->step : resultset->count;
assert (*req->numberOfRecordsRequested > 0);
if (syntax && *syntax)
req->preferredRecordSyntax =
yaz_str_to_z3950oid (c->odr_out, CLASS_RECSYN, syntax);
- if (schema && *schema)
+ if (resultset->schema && *resultset->schema)
{
Z_RecordComposition *compo = (Z_RecordComposition *)
odr_malloc (c->odr_out, sizeof(*compo));
compo->u.complex->generic = (Z_Specification *)
odr_malloc(c->odr_out, sizeof(*compo->u.complex->generic));
- compo->u.complex->generic->which = Z_Specification_oid;
- compo->u.complex->generic->u.oid = (Odr_oid *)
- yaz_str_to_z3950oid (c->odr_out, CLASS_SCHEMA, schema);
+ compo->u.complex->generic->which = Z_Schema_oid;
+ compo->u.complex->generic->schema.oid = (Odr_oid *)
+ yaz_str_to_z3950oid (c->odr_out, CLASS_SCHEMA, resultset->schema);
- if (!compo->u.complex->generic->u.oid)
+ if (!compo->u.complex->generic->schema.oid)
{
/* OID wasn't a schema! Try record syntax instead. */
- compo->u.complex->generic->u.oid = (Odr_oid *)
- yaz_str_to_z3950oid (c->odr_out, CLASS_RECSYN, schema);
+ compo->u.complex->generic->schema.oid = (Odr_oid *)
+ yaz_str_to_z3950oid (c->odr_out, CLASS_RECSYN, resultset->schema);
}
if (elementSetName && *elementSetName)
{
req->u.esRequest->notToKeep = (Z_IOOriginPartNotToKeep *)
odr_malloc(p->odr_out,sizeof(Z_IOOriginPartNotToKeep));
- req->u.esRequest->notToKeep->resultSetItem = (Z_IOResultSetItem *)
- odr_malloc(p->odr_out, sizeof(Z_IOResultSetItem));
-
str = ZOOM_options_get(p->options, "itemorder-setname");
if (!str)
str = "default";
- req->u.esRequest->notToKeep->resultSetItem->resultSetId =
- nmem_strdup (p->odr_out->mem, str);
- req->u.esRequest->notToKeep->resultSetItem->item =
- (int *) odr_malloc(p->odr_out, sizeof(int));
+
+ if (!*str)
+ req->u.esRequest->notToKeep->resultSetItem = 0;
+ else
+ {
+ req->u.esRequest->notToKeep->resultSetItem = (Z_IOResultSetItem *)
+ odr_malloc(p->odr_out, sizeof(Z_IOResultSetItem));
+
+ req->u.esRequest->notToKeep->resultSetItem->resultSetId =
+ nmem_strdup (p->odr_out->mem, str);
+ req->u.esRequest->notToKeep->resultSetItem->item =
+ (int *) odr_malloc(p->odr_out, sizeof(int));
- str = ZOOM_options_get(p->options, "itemorder-item");
- *req->u.esRequest->notToKeep->resultSetItem->item =
- (str ? atoi(str) : 1);
-
+ str = ZOOM_options_get(p->options, "itemorder-item");
+ *req->u.esRequest->notToKeep->resultSetItem->item =
+ (str ? atoi(str) : 1);
+ }
req->u.esRequest->notToKeep->itemRequest = encode_ill_request(p);
return req;
return ZOOM_options_get (p->options, key);
}
-#if HAVE_GSOAP
-static zoom_ret ZOOM_srw_search(ZOOM_connection c, ZOOM_resultset r,
- const char *cql)
-{
- int ret;
- struct xcql__operandType *xQuery = 0;
- char *action = 0;
- xsd__integer startRecord = r->start + 1;
- xsd__integer maximumRecord = r->count;
- const char *schema = ZOOM_resultset_option_get (r, "schema");
- struct zs__searchRetrieveResponse res;
- xsd__string recordPacking = 0;
-
-
- if (!schema)
- schema = "http://www.loc.gov/marcxml/";
-
- ret = soap_call_zs__searchRetrieveRequest(c->soap, c->host_port,
- action,
- &r->z_query->u.type_104->u.cql,
- xQuery,
- 0, 0,
- &startRecord, &maximumRecord,
- (char **) &schema,
- &recordPacking,
- &res);
- if (ret != SOAP_OK)
- {
- const char **s = soap_faultdetail(c->soap);
- xfree (c->addinfo);
- c->addinfo = 0;
- if (s && *s)
- c->addinfo = xstrdup(*s);
- c->diagset = "SOAP";
- c->error = ret;
- }
- else
- {
- if (res.diagnostics.__sizeDiagnostics > 0)
- {
- int i = 0;
- xfree (c->addinfo);
- c->addinfo = 0;
- c->diagset = "SRW";
- c->error = res.diagnostics.diagnostic[i]->code;
- if (res.diagnostics.diagnostic[i]->details)
- c->addinfo =
- xstrdup(res.diagnostics.diagnostic[i]->details);
-
- }
- else
- {
- int i;
- r->size = res.numberOfRecords;
- if (res.resultSetId)
- r->setname = xstrdup(res.resultSetId);
- for (i = 0; i < res.records.__sizeRecords; i++)
- {
- char *rdata = res.records.record[i]->recordData;
- if (rdata)
- {
- Z_NamePlusRecord *npr =
- odr_malloc(r->odr, sizeof(*npr));
- Z_External *ext =
- z_ext_record(r->odr, VAL_TEXT_XML,
- rdata, strlen(rdata));
- npr->databaseName = 0;
- npr->which = Z_NamePlusRecord_databaseRecord;
- npr->u.databaseRecord = ext;
- record_cache_add (r, npr, r->start + i);
- }
- }
- }
- }
- return zoom_complete;
-}
-#endif
ZOOM_API(void)
ZOOM_package_option_set (ZOOM_package p, const char *key,
}
task->running = 1;
ret = zoom_complete;
-#if 0
- if (c->proto == PROTO_SRW)
- {
- ZOOM_resultset resultset;
- switch (task->which)
- {
- case ZOOM_TASK_SEARCH:
- resultset = c->tasks->u.search.resultset;
- if (resultset->z_query &&
- resultset->z_query->which == Z_Query_type_104
- && resultset->z_query->u.type_104->which == Z_External_CQL)
- ret = ZOOM_srw_search(c, resultset,
- resultset->z_query->u.type_104->u.cql);
- break;
- case ZOOM_TASK_RETRIEVE:
- resultset = c->tasks->u.retrieve.resultset;
- resultset->start = c->tasks->u.retrieve.start;
- resultset->count = c->tasks->u.retrieve.count;
-
- if (resultset->start >= resultset->size)
- return zoom_complete;
- if (resultset->start + resultset->count > resultset->size)
- resultset->count = resultset->size - resultset->start;
-
- if (resultset->z_query &&
- resultset->z_query->which == Z_Query_type_104
- && resultset->z_query->u.type_104->which == Z_External_CQL)
- ret = ZOOM_srw_search(c, resultset,
- resultset->z_query->u.type_104->u.cql);
- break;
- }
-#endif
if (c->cs || task->which == ZOOM_TASK_CONNECT)
{
switch (task->which)
{
case ZOOM_TASK_SEARCH:
- if (c->proto == PROTO_SRW)
+ if (c->proto == PROTO_HTTP)
ret = ZOOM_connection_srw_send_search(c);
else
ret = ZOOM_connection_send_search(c);
break;
case ZOOM_TASK_RETRIEVE:
- ret = send_present (c);
+ if (c->proto == PROTO_HTTP)
+ ret = ZOOM_connection_srw_send_search(c);
+ else
+ ret = send_present (c);
break;
case ZOOM_TASK_CONNECT:
ret = do_connect(c);
}
}
+#if HAVE_XML2
+static void handle_srw_response(ZOOM_connection c,
+ Z_SRW_searchRetrieveResponse *res)
+{
+ ZOOM_resultset resultset = 0;
+ int i;
+ NMEM nmem;
+ ZOOM_Event event;
+
+ if (!c->tasks)
+ return;
+
+ if (c->tasks->which == ZOOM_TASK_SEARCH)
+ resultset = c->tasks->u.search.resultset;
+ else if (c->tasks->which == ZOOM_TASK_RETRIEVE)
+ resultset = c->tasks->u.retrieve.resultset;
+ else
+ return ;
+
+ event = ZOOM_Event_create(ZOOM_EVENT_RECV_SEARCH);
+ ZOOM_connection_put_event(c, event);
+
+ resultset->size = 0;
+
+ yaz_log(LOG_DEBUG, "got SRW response OK");
+
+ if (res->numberOfRecords)
+ resultset->size = *res->numberOfRecords;
+
+ for (i = 0; i<res->num_records; i++)
+ {
+ int pos;
+
+ 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 = resultset->start + 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 =
+ yaz_oidval_to_z3950oid(c->odr_in, CLASS_RECSYN, VAL_TEXT_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 =
+ res->records[i].recordData_buf;
+ npr->u.databaseRecord->u.octet_aligned->len =
+ npr->u.databaseRecord->u.octet_aligned->size =
+ res->records[i].recordData_len;
+ record_cache_add (resultset, npr, pos);
+ }
+ if (res->num_diagnostics > 0)
+ {
+ set_dset_error(c, *res->diagnostics[0].code, "SRW",
+ res->diagnostics[0].details, 0);
+ }
+ nmem = odr_extract_mem(c->odr_in);
+ nmem_transfer(resultset->odr->mem, nmem);
+ nmem_destroy(nmem);
+}
+#endif
+
+#if HAVE_XML2
static void handle_http(ZOOM_connection c, Z_HTTP_Response *hres)
{
+ int ret = -1;
+ const char *content_type = z_HTTP_header_lookup(hres->headers,
+ "Content-Type");
+ const char *connection_head = z_HTTP_header_lookup(hres->headers,
+ "Connection");
c->mask = 0;
yaz_log (LOG_DEBUG, "handle_http");
+
+ if (content_type && !yaz_strcmp_del("text/xml", content_type, "; "))
+ {
+ Z_SOAP *soap_package = 0;
+ ODR o = odr_createmem(ODR_DECODE);
+ Z_SOAP_Handler soap_handlers[2] = {
+ {"http://www.loc.gov/zing/srw/v1.0/", 0,
+ (Z_SOAP_fun) yaz_srw_codec},
+ {0, 0, 0}
+ };
+ ret = z_soap_codec(o, &soap_package,
+ &hres->content_buf, &hres->content_len,
+ soap_handlers);
+ if (!ret && soap_package->which == Z_SOAP_generic &&
+ soap_package->u.generic->no == 0)
+ {
+ Z_SRW_PDU *sr = soap_package->u.generic->p;
+ if (sr->which == Z_SRW_searchRetrieve_response)
+ handle_srw_response(c, sr->u.response);
+ else
+ ret = -1;
+ }
+ else if (!ret && (soap_package->which == Z_SOAP_fault
+ || soap_package->which == Z_SOAP_error))
+ {
+ set_HTTP_error(c, hres->code,
+ soap_package->u.fault->fault_code,
+ soap_package->u.fault->fault_string);
+ }
+ else
+ ret = -1;
+ odr_destroy(o);
+ }
+ if (ret)
+ {
+ if (hres->code != 200)
+ set_HTTP_error(c, hres->code, 0, 0);
+ else
+ set_ZOOM_error(c, ZOOM_ERROR_DECODE, 0);
+ do_close (c);
+ }
ZOOM_connection_remove_task(c);
+ if (!strcmp(hres->version, "1.0"))
+ {
+ /* HTTP 1.0: only if Keep-Alive we stay alive.. */
+ if (!connection_head || strcmp(connection_head, "Keep-Alive"))
+ do_close(c);
+ }
+ else
+ {
+ /* HTTP 1.1: only if no close we stay alive .. */
+ if (connection_head && !strcmp(connection_head, "close"))
+ do_close(c);
+ }
}
+#endif
static int do_read (ZOOM_connection c)
{
{
Z_GDU *gdu;
ZOOM_Event event;
+
odr_reset (c->odr_in);
odr_setbuf (c->odr_in, c->buf_in, r, 0);
event = ZOOM_Event_create (ZOOM_EVENT_RECV_APDU);
else if (gdu->which == Z_GDU_Z3950)
handle_apdu (c, gdu->u.z3950);
else if (gdu->which == Z_GDU_HTTP_Response)
+ {
+#if HAVE_XML2
handle_http (c, gdu->u.HTTP_Response);
+#else
+ set_ZOOM_error(c, ZOOM_ERROR_DECODE, 0);
+ do_close (c);
+#endif
+ }
c->reconnect_ok = 0;
}
return 1;
yaz_log (LOG_DEBUG, "reconnect write");
c->tasks->running = 0;
ZOOM_connection_insert_task (c, ZOOM_TASK_CONNECT);
- return zoom_complete;
+ return zoom_pending;
}
if (c->state == STATE_CONNECTING)
set_ZOOM_error(c, ZOOM_ERROR_CONNECT, 0);
return "Timeout";
case ZOOM_ERROR_UNSUPPORTED_PROTOCOL:
return "Unsupported protocol";
+ case ZOOM_ERROR_UNSUPPORTED_QUERY:
+ return "Unsupported query type";
default:
return diagbib1_str (error);
}
int error = c->error;
if (cp)
{
- if (!c->diagset)
+ if (!c->diagset || !strcmp(c->diagset, "ZOOM"))
+ *cp = ZOOM_diag_str(error);
+ else if (!strcmp(c->diagset, "HTTP"))
+ *cp = z_HTTP_errmsg(c->error);
+ else if (!strcmp(c->diagset, "Bib-1"))
*cp = ZOOM_diag_str(error);
-#if HAVE_GSOAP
else if (!strcmp(c->diagset, "SRW"))
- *cp = yaz_srw_diag_str(error);
- else if (c->soap && !strcmp(c->diagset, "SOAP"))
- {
- const char **s = soap_faultstring(c->soap);
- if (s && *s)
- *cp = *s;
- else
- *cp = "unknown";
- }
-#endif
+ *cp = yaz_diag_srw_str(c->error);
else
- *cp = ZOOM_diag_str(error);
+ *cp = "Unknown error and diagnostic set";
}
if (addinfo)
*addinfo = c->addinfo ? c->addinfo : "";