* Copyright (c) 2000-2004, Index Data
* See the file LICENSE for details.
*
- * $Id: zoom-c.c,v 1.25 2004-02-23 09:26:11 adam Exp $
- *
- * ZOOM layer for C, connections, result sets, queries.
+ * $Id: zoom-c.c,v 1.31 2004-10-15 00:19:01 adam Exp $
+ */
+/**
+ * \file zoom-c.c
+ * \brief Implements ZOOM C interface.
*/
+
#include <assert.h>
#include <string.h>
#include "zoom-p.h"
}
if (addinfo && addinfo2)
{
- c->addinfo = xmalloc(strlen(addinfo) + strlen(addinfo2) + 2);
+ c->addinfo = (char*) xmalloc(strlen(addinfo) + strlen(addinfo2) + 2);
strcpy(c->addinfo, addinfo);
strcat(c->addinfo, addinfo2);
}
switch (task->which)
{
case ZOOM_TASK_SEARCH:
-
ZOOM_resultset_destroy (task->u.search.resultset);
break;
case ZOOM_TASK_RETRIEVE:
}
}
+static void get_cert(ZOOM_connection c)
+{
+ char *cert_buf;
+ int cert_len;
+
+ if (cs_get_peer_certificate_x509(c->cs, &cert_buf, &cert_len))
+ {
+ ZOOM_connection_option_setl(c, "sslPeerCert",
+ cert_buf, cert_len);
+ xfree(cert_buf);
+ }
+}
+
static zoom_ret do_connect (ZOOM_connection c)
{
void *add;
yaz_log (LOG_DEBUG, "do_connect host=%s", effective_host);
- assert (!c->cs);
+ if (c->cs)
+ cs_close(c->cs);
c->cs = cs_create_host (effective_host, 0, &add);
if (c->cs && c->cs->protocol == PROTO_HTTP)
c->proto = PROTO_HTTP;
cs_get_host_args(c->host_port, &path);
xfree(c->path);
- c->path = xmalloc(strlen(path)+2);
+ c->path = (char*) xmalloc(strlen(path)+2);
c->path[0] = '/';
strcpy (c->path+1, path);
#else
{
ZOOM_Event event = ZOOM_Event_create(ZOOM_EVENT_CONNECT);
ZOOM_connection_put_event(c, event);
+ get_cert(c);
if (c->proto == PROTO_Z3950)
ZOOM_connection_send_init(c);
else
ZOOM_options_get(c->options, "implementationName"),
odr_prepend(c->odr_out, "ZOOM-C", ireq->implementationName));
- version = odr_strdup(c->odr_out, "$Revision: 1.25 $");
+ version = odr_strdup(c->odr_out, "$Revision: 1.31 $");
if (strlen(version) > 10) /* check for unexpanded CVS strings */
version[strlen(version)-2] = '\0';
ireq->implementationVersion = odr_prepend(c->odr_out,
};
ODR o = odr_createmem(ODR_ENCODE);
int ret;
- Z_SOAP *p = odr_malloc(o, sizeof(*p));
+ Z_SOAP *p = (Z_SOAP*) odr_malloc(o, sizeof(*p));
Z_GDU *gdu;
ZOOM_Event event;
if (cp0 && cp1)
{
- char *h = odr_malloc(c->odr_out, cp1 - cp0 + 1);
+ char *h = (char*) 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,
z_HTTP_header_add(c->odr_out, &gdu->u.HTTP_Request->headers,
"SOAPAction", "\"\"");
p->which = Z_SOAP_generic;
- p->u.generic = odr_malloc(o, sizeof(*p->u.generic));
+ p->u.generic = (Z_SOAP_Generic *) odr_malloc(o, sizeof(*p->u.generic));
p->u.generic->no = 0;
p->u.generic->ns = 0;
p->u.generic->p = sr;
i++;
if (!strncmp(type_spec+i, "charset=", 8))
{
- cp = type_spec+i+8;
- for (i = 0; cp[i] && i < sizeof(charset)-1; i++)
+ int j = 0;
+ i = i + 8; /* skip charset= */
+ for (j = 0; type_spec[i] && j < sizeof(charset)-1; i++, j++)
{
- if (cp[i] == ';' || cp[i] == ' ')
+ if (type_spec[i] == ';' || type_spec[i] == ' ')
break;
- charset[i] = cp[i];
+ charset[j] = cp[i];
}
- charset[i] = '\0';
+ charset[j] = '\0';
}
else if (!strncmp(type_spec+i, "xpath=", 6))
{
- cp = type_spec+i+6;
- for (i = 0; cp[i] && i < sizeof(xpath)-1; i++)
- xpath[i] = cp[i];
- xpath[i] = '\0';
+ 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';
}
while (type_spec[i] == ' ')
i++;
}
if (r->which == Z_External_sutrs)
return record_iconv_return(rec, len,
- r->u.sutrs->buf, r->u.sutrs->len,
+ (char*) r->u.sutrs->buf,
+ r->u.sutrs->len,
charset);
else if (r->which == Z_External_octet)
{
odr_malloc (p->odr_out, sizeof(Odr_oct));
notToKeep->elements[0]->u.opaque->size =
notToKeep->elements[0]->u.opaque->len = strlen(recordIdOpaque);
- notToKeep->elements[0]->u.opaque->buf =
+ notToKeep->elements[0]->u.opaque->buf = (unsigned char*)
odr_strdup(p->odr_out, recordIdOpaque);
}
else if (recordIdNumber)
apdu->u.extendedServicesRequest->taskSpecificParameters = r;
}
}
- if (!strcmp(type, "create")) /* create database */
+ else if (!strcmp(type, "create")) /* create database */
{
apdu = create_admin_package(p, Z_ESAdminOriginPartToKeep_create,
0, 0);
}
- if (!strcmp(type, "drop")) /* drop database */
+ else if (!strcmp(type, "drop")) /* drop database */
{
apdu = create_admin_package(p, Z_ESAdminOriginPartToKeep_drop,
0, 0);
}
- if (!strcmp(type, "update")) /* update record(s) */
+ else if (!strcmp(type, "commit")) /* commit changes */
+ {
+ apdu = create_admin_package(p, Z_ESAdminOriginPartToKeep_commit,
+ 0, 0);
+ }
+ else if (!strcmp(type, "update")) /* update record(s) */
{
apdu = create_update_package(p);
}
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 =
+ npr->u.databaseRecord->u.octet_aligned->buf = (unsigned char*)
res->records[i].recordData_buf;
npr->u.databaseRecord->u.octet_aligned->len =
npr->u.databaseRecord->u.octet_aligned->size =
if (!ret && soap_package->which == Z_SOAP_generic &&
soap_package->u.generic->no == 0)
{
- Z_SRW_PDU *sr = soap_package->u.generic->p;
+ Z_SRW_PDU *sr = (Z_SRW_PDU*) soap_package->u.generic->p;
if (sr->which == Z_SRW_searchRetrieve_response)
handle_srw_response(c, sr->u.response);
else
ZOOM_API(void)
ZOOM_connection_option_set (ZOOM_connection c, const char *key,
- const char *val)
+ const char *val)
{
ZOOM_options_set (c->options, key, val);
}
+ZOOM_API(void)
+ZOOM_connection_option_setl (ZOOM_connection c, const char *key,
+ const char *val, int len)
+{
+ ZOOM_options_setl (c->options, key, val, len);
+}
+
ZOOM_API(const char *)
ZOOM_resultset_option_get (ZOOM_resultset r, const char *key)
{
else if (ret == 0)
{
ZOOM_connection_put_event (c, event);
+ get_cert(c);
if (c->proto == PROTO_Z3950)
ZOOM_connection_send_init(c);
else