/*
- * Copyright (c) 2000-2003, Index Data
+ * Copyright (c) 2000-2004, Index Data
* See the file LICENSE for details.
*
- * $Id: zoom-c.c,v 1.10 2003-12-04 12:57:30 adam Exp $
+ * $Id: zoom-c.c,v 1.18 2004-01-12 12:10:17 adam Exp $
*
* ZOOM layer for C, connections, result sets, queries.
*/
ZOOM_options_get(c->options, "implementationName"),
odr_prepend(c->odr_out, "ZOOM-C", ireq->implementationName));
- version = odr_strdup(c->odr_out, "$Revision: 1.10 $");
+ version = odr_strdup(c->odr_out, "$Revision: 1.18 $");
if (strlen(version) > 10) /* check for unexpanded CVS strings */
version[strlen(version)-2] = '\0';
ireq->implementationVersion = odr_prepend(c->odr_out,
{
char ctype[50];
Z_SOAP_Handler h[2] = {
- {"http://www.loc.gov/zing/srw/v1.0/", 0, (Z_SOAP_fun) yaz_srw_codec},
+ {"http://www.loc.gov/zing/srw/", 0, (Z_SOAP_fun) yaz_srw_codec},
{0, 0, 0}
};
ODR o = odr_createmem(ODR_ENCODE);
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)
+{
+ char to[40];
+ char from[40];
+ yaz_iconv_t cd = 0;
+ yaz_marc_t mt = yaz_marc_create();
+
+ *from = '\0';
+ strcpy(to, "UTF-8");
+ 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 (*from && *to)
+ {
+ cd = yaz_iconv_open(to, from);
+ 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 (len)
+ *len = wrbuf_len(rec->wrbuf_marc);
+ return wrbuf_buf(rec->wrbuf_marc);
+ }
+ yaz_marc_destroy(mt);
+ if (cd)
+ yaz_iconv_close(cd);
+ return 0;
+}
+
static const char *record_iconv_return(ZOOM_record rec, int *len,
const char *buf, int sz,
const char *record_charset)
{
char type[40];
char charset[40];
+ char xpath[512];
const char *cp;
int i;
Z_NamePlusRecord *npr;
}
type[i] = '\0';
charset[0] = '\0';
- if (type_spec[i] == ';')
+ while (type_spec[i] == ';')
{
i++;
while (type_spec[i] == ' ')
}
charset[i] = '\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';
+ }
+ while (type_spec[i] == ' ')
+ i++;
+ }
if (!strcmp (type, "database"))
{
if (len)
charset);
else if (r->which == Z_External_octet)
{
- yaz_marc_t mt;
+ const char *ret_buf;
switch (ent->value)
{
case VAL_SOIF:
case VAL_APPLICATION_XML:
break;
default:
- if (!rec->wrbuf_marc)
- rec->wrbuf_marc = wrbuf_alloc();
-
- mt = yaz_marc_create();
- wrbuf_rewind (rec->wrbuf_marc);
- if (yaz_marc_decode_wrbuf (
- mt, (const char *) r->u.octet_aligned->buf,
- r->u.octet_aligned->len,
- rec->wrbuf_marc) > 0)
- {
- yaz_marc_destroy(mt);
- return record_iconv_return(rec, len,
- wrbuf_buf(rec->wrbuf_marc),
- wrbuf_len(rec->wrbuf_marc),
- charset);
- }
- yaz_marc_destroy(mt);
+ 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,
charset);
else if (r->which == Z_External_octet)
{
- yaz_marc_t mt;
+ const char *ret_buf;
int marc_decode_type = YAZ_MARC_MARCXML;
if (!strcmp(type, "oai"))
case VAL_APPLICATION_XML:
break;
default:
- if (!rec->wrbuf_marc)
- rec->wrbuf_marc = wrbuf_alloc();
- wrbuf_rewind (rec->wrbuf_marc);
- mt = yaz_marc_create();
-
- yaz_marc_xml(mt, YAZ_MARC_MARCXML);
- if (yaz_marc_decode_wrbuf (
- mt, (const char *) r->u.octet_aligned->buf,
- r->u.octet_aligned->len,
- rec->wrbuf_marc) > 0)
- {
- yaz_marc_destroy(mt);
- return record_iconv_return(rec, len,
- wrbuf_buf(rec->wrbuf_marc),
- wrbuf_len(rec->wrbuf_marc),
- charset);
- }
- yaz_marc_destroy(mt);
+ 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,
if (t->displayTerm)
{
- term = (const char *) t->term->u.general->buf;
+ term = t->displayTerm;
*len = strlen(term);
}
else if (t->term->which == Z_Term_general)
if (content_type && !yaz_strcmp_del("text/xml", content_type, "; "))
{
Z_SOAP *soap_package = 0;
- ODR o = odr_createmem(ODR_DECODE);
+ ODR o = c->odr_in;
Z_SOAP_Handler soap_handlers[2] = {
- {"http://www.loc.gov/zing/srw/v1.0/", 0,
+ {"http://www.loc.gov/zing/srw/", 0,
(Z_SOAP_fun) yaz_srw_codec},
{0, 0, 0}
};
}
else
ret = -1;
- odr_destroy(o);
}
if (ret)
{