From b462b5047a365a76a5be26341e62b69076a33d3a Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Wed, 7 Jan 2004 20:36:44 +0000 Subject: [PATCH] Stylesheet support. --- CHANGELOG | 2 ++ client/client.c | 4 ++-- include/yaz/soap.h | 7 ++++--- include/yaz/srw.h | 3 ++- src/seshigh.c | 11 +++++++---- src/soap.c | 25 ++++++++++++++++++------- src/srw.c | 9 ++++++++- src/srwutil.c | 11 +++++++++-- src/zoom-c.c | 6 +++--- 9 files changed, 55 insertions(+), 23 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index cdadf3c..f06b6b1 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,7 @@ Possible compatibility problems with earlier versions marked with '*'. +Handle user defined stylesheet for SRW/SRU. + --- 2.0.9-3 2004/01/06 Debian/Windows Fix a bug with decoding of XML packed records. diff --git a/client/client.c b/client/client.c index 460503a..907bf3c 100644 --- a/client/client.c +++ b/client/client.c @@ -2,7 +2,7 @@ * Copyright (c) 1995-2004, Index Data * See the file LICENSE for details. * - * $Id: client.c,v 1.221 2004-01-06 13:38:39 adam Exp $ + * $Id: client.c,v 1.222 2004-01-07 20:36:44 adam Exp $ */ #include @@ -1189,7 +1189,7 @@ static int send_srw(Z_SRW_PDU *sr) ret = z_soap_codec_enc(o, &p, &gdu->u.HTTP_Request->content_buf, &gdu->u.HTTP_Request->content_len, h, - charset); + charset, 0); if (z_GDU(out, &gdu, 0, 0)) { diff --git a/include/yaz/soap.h b/include/yaz/soap.h index 09695b5..bfbc46c 100644 --- a/include/yaz/soap.h +++ b/include/yaz/soap.h @@ -2,7 +2,7 @@ * Copyright (c) 2002-2003, Index Data. * See the file LICENSE for details. * - * $Id: soap.h,v 1.5 2003-12-09 12:51:16 adam Exp $ + * $Id: soap.h,v 1.6 2004-01-07 20:36:44 adam Exp $ */ #ifndef YAZ_SOAP_H @@ -49,8 +49,9 @@ YAZ_EXPORT int z_soap_codec(ODR o, Z_SOAP **pp, char **content_buf, int *content_len, Z_SOAP_Handler *handlers); YAZ_EXPORT int z_soap_codec_enc(ODR o, Z_SOAP **pp, - char **content_buf, int *content_len, - Z_SOAP_Handler *handlers, const char *encoding); + char **content_buf, int *content_len, + Z_SOAP_Handler *handlers, const char *encoding, + const char *stylesheet); YAZ_EXPORT int z_soap_error(ODR o, Z_SOAP *p, const char *fault_code, const char *fault_string, diff --git a/include/yaz/srw.h b/include/yaz/srw.h index 1b61e2a..48c4f01 100644 --- a/include/yaz/srw.h +++ b/include/yaz/srw.h @@ -2,7 +2,7 @@ * Copyright (c) 2002-2003, Index Data. * See the file LICENSE for details. * - * $Id: srw.h,v 1.11 2004-01-05 09:34:42 adam Exp $ + * $Id: srw.h,v 1.12 2004-01-07 20:36:44 adam Exp $ */ #ifndef YAZ_SRW_H @@ -75,6 +75,7 @@ typedef struct { typedef struct { char *recordPacking; char *database; + char *stylesheet; } Z_SRW_explainRequest; typedef struct { diff --git a/src/seshigh.c b/src/seshigh.c index 7a8a7aa..63e746c 100644 --- a/src/seshigh.c +++ b/src/seshigh.c @@ -2,7 +2,7 @@ * Copyright (c) 1995-2003, Index Data * See the file LICENSE for details. * - * $Id: seshigh.c,v 1.13 2004-01-05 09:34:42 adam Exp $ + * $Id: seshigh.c,v 1.14 2004-01-07 20:36:44 adam Exp $ */ /* @@ -786,6 +786,7 @@ static void process_http_request(association *assoc, request *req) char *charset = 0; Z_HTTP_Response *hres; int keepalive = 1; + char *stylesheet = 0; r = yaz_srw_decode(hreq, &sr, &soap_package, assoc->decode, &charset); if (r == 2) /* not taken */ @@ -797,7 +798,8 @@ static void process_http_request(association *assoc, request *req) { Z_SRW_PDU *res = yaz_srw_get(assoc->encode, Z_SRW_searchRetrieve_response); - + + stylesheet = sr->u.request->stylesheet; srw_bend_search(assoc, req, sr->u.request, res->u.response, &http_code); if (http_code == 200) @@ -806,6 +808,7 @@ static void process_http_request(association *assoc, request *req) else if (sr->which == Z_SRW_explain_request) { Z_SRW_PDU *res = yaz_srw_get(o, Z_SRW_explain_response); + stylesheet = sr->u.explain_request->stylesheet; srw_bend_explain(assoc, req, sr->u.explain_request, res->u.explain_response, &http_code); if (http_code == 200) @@ -834,7 +837,7 @@ static void process_http_request(association *assoc, request *req) hres = p->u.HTTP_Response; ret = z_soap_codec_enc(assoc->encode, &soap_package, &hres->content_buf, &hres->content_len, - soap_handlers, charset); + soap_handlers, charset, stylesheet); hres->code = http_code; strcpy(ctype, "text/xml"); @@ -1271,7 +1274,7 @@ static Z_APDU *process_initRequest(association *assoc, request *reqb) assoc->init->implementation_name, odr_prepend(assoc->encode, "GFS", resp->implementationName)); - version = odr_strdup(assoc->encode, "$Revision: 1.13 $"); + version = odr_strdup(assoc->encode, "$Revision: 1.14 $"); if (strlen(version) > 10) /* check for unexpanded CVS strings */ version[strlen(version)-2] = '\0'; resp->implementationVersion = odr_prepend(assoc->encode, diff --git a/src/soap.c b/src/soap.c index 96a9ac1..316cae8 100644 --- a/src/soap.c +++ b/src/soap.c @@ -1,8 +1,8 @@ /* - * Copyright (c) 2002-2003, Index Data. + * Copyright (c) 2002-2004, Index Data. * See the file LICENSE for details. * - * $Id: soap.c,v 1.4 2004-01-05 09:34:42 adam Exp $ + * $Id: soap.c,v 1.5 2004-01-07 20:36:44 adam Exp $ */ #include @@ -15,9 +15,10 @@ static const char *soap_v1_1 = "http://schemas.xmlsoap.org/soap/envelope/"; static const char *soap_v1_2 = "http://www.w3.org/2001/06/soap-envelope"; int z_soap_codec_enc(ODR o, Z_SOAP **pp, - char **content_buf, int *content_len, - Z_SOAP_Handler *handlers, - const char *encoding) + char **content_buf, int *content_len, + Z_SOAP_Handler *handlers, + const char *encoding, + const char *stylesheet) { if (o->direction == ODR_DECODE) { @@ -203,6 +204,15 @@ int z_soap_codec_enc(ODR o, Z_SOAP **pp, { xmlDocSetRootElement(doc, body_ptr->children); } + if (stylesheet) + { + char *content = odr_malloc(o, strlen(stylesheet) + 40); + + xmlNodePtr pi, ptr = xmlDocGetRootElement(doc); + sprintf(content, "type=\"text/xsl\" href=\"%s\"", stylesheet); + pi = xmlNewPI("xml-stylesheet", content); + xmlAddPrevSibling(ptr, pi); + } if (1) { xmlChar *buf_out; @@ -224,7 +234,8 @@ int z_soap_codec_enc(ODR o, Z_SOAP **pp, #else int z_soap_codec_enc(ODR o, Z_SOAP **pp, char **content_buf, int *content_len, - Z_SOAP_Handler *handlers, const char *encoding) + Z_SOAP_Handler *handlers, const char *encoding, + const char *stylesheet) { static char *err_xml = "\n" @@ -250,7 +261,7 @@ int z_soap_codec(ODR o, Z_SOAP **pp, char **content_buf, int *content_len, Z_SOAP_Handler *handlers) { - return z_soap_codec_enc(o, pp, content_buf, content_len, handlers, 0); + return z_soap_codec_enc(o, pp, content_buf, content_len, handlers, 0, 0); } int z_soap_error(ODR o, Z_SOAP *p, diff --git a/src/srw.c b/src/srw.c index 3dd2ea3..cf22d06 100644 --- a/src/srw.c +++ b/src/srw.c @@ -2,7 +2,7 @@ * Copyright (c) 2002-2004, Index Data. * See the file LICENSE for details. * - * $Id: srw.c,v 1.14 2004-01-06 11:21:04 adam Exp $ + * $Id: srw.c,v 1.15 2004-01-07 20:36:44 adam Exp $ */ #include @@ -528,11 +528,15 @@ int yaz_srw_codec(ODR o, void * vptr, Z_SRW_PDU **handler_data, req = (*p)->u.explain_request = odr_malloc(o, sizeof(*req)); req->recordPacking = 0; req->database = 0; + req->stylesheet = 0; for (; ptr; ptr = ptr->next) { if (match_xsd_string(ptr, "database", o, &req->database)) ; + else if (match_xsd_string(ptr, "stylesheet", o, + &req->stylesheet)) + ; else if (match_xsd_string(ptr, "recordPacking", o, &req->recordPacking)) ; @@ -709,11 +713,14 @@ int yaz_srw_codec(ODR o, void * vptr, Z_SRW_PDU **handler_data, } else if ((*p)->which == Z_SRW_explain_request) { + Z_SRW_explainRequest *req = (*p)->u.explain_request; xmlNodePtr ptr = xmlNewChild(pptr, 0, "explainRequest", 0); ns_srw = xmlNewNs(ptr, ns, "zs"); xmlSetNs(ptr, ns_srw); add_xsd_string(ptr, "version", (*p)->srw_version); + add_xsd_string(ptr, "recordPacking", req->recordPacking); + add_xsd_string(ptr, "stylesheet", req->stylesheet); } else if ((*p)->which == Z_SRW_explain_response) { diff --git a/src/srwutil.c b/src/srwutil.c index 6124828..581c00d 100644 --- a/src/srwutil.c +++ b/src/srwutil.c @@ -1,8 +1,8 @@ /* - * Copyright (c) 2002-2003, Index Data. + * Copyright (c) 2002-2004, Index Data. * See the file LICENSE for details. * - * $Id: srwutil.c,v 1.5 2004-01-06 11:20:15 adam Exp $ + * $Id: srwutil.c,v 1.6 2004-01-07 20:36:44 adam Exp $ */ #include @@ -163,6 +163,7 @@ int yaz_sru_decode(Z_HTTP_Request *hreq, Z_SRW_PDU **srw_pdu, const char *operation = 0; char *query = 0; char *pQuery = 0; + char *stylesheet = 0; if (charset) *charset = 0; @@ -181,6 +182,7 @@ int yaz_sru_decode(Z_HTTP_Request *hreq, Z_SRW_PDU **srw_pdu, query = yaz_uri_val(p1, "query", decode); pQuery = yaz_uri_val(p1, "pQuery", decode); operation = yaz_uri_val(p1, "operation", decode); + stylesheet = yaz_uri_val(p1, "stylesheet", decode); if (!operation) operation = "explain"; if ((operation && !strcmp(operation, "searchRetrieve")) @@ -207,6 +209,8 @@ int yaz_sru_decode(Z_HTTP_Request *hreq, Z_SRW_PDU **srw_pdu, } sr->u.request->recordSchema = yaz_uri_val(p1, "recordSchema", decode); sr->u.request->recordPacking = yaz_uri_val(p1, "recordPacking", decode); + sr->u.request->stylesheet = stylesheet; + if (!sr->u.request->recordPacking) sr->u.request->recordPacking = "xml"; yaz_uri_val_int(p1, "maximumRecords", decode, @@ -241,6 +245,8 @@ int yaz_sru_decode(Z_HTTP_Request *hreq, Z_SRW_PDU **srw_pdu, sr->u.explain_request->recordPacking = "xml"; sr->u.explain_request->database = db; + sr->u.explain_request->stylesheet = stylesheet; + (*soap_package) = odr_malloc(decode, sizeof(**soap_package)); (*soap_package)->which = Z_SOAP_generic; @@ -302,6 +308,7 @@ Z_SRW_PDU *yaz_srw_get(ODR o, int which) odr_malloc(o, sizeof(*sr->u.explain_request)); sr->u.explain_request->recordPacking = 0; sr->u.explain_request->database = 0; + sr->u.explain_request->stylesheet = 0; break; case Z_SRW_explain_response: sr->u.explain_response = (Z_SRW_explainResponse *) diff --git a/src/zoom-c.c b/src/zoom-c.c index e84c25e..af940a8 100644 --- a/src/zoom-c.c +++ b/src/zoom-c.c @@ -2,7 +2,7 @@ * Copyright (c) 2000-2003, Index Data * See the file LICENSE for details. * - * $Id: zoom-c.c,v 1.15 2003-12-30 00:29:53 adam Exp $ + * $Id: zoom-c.c,v 1.16 2004-01-07 20:36:44 adam Exp $ * * ZOOM layer for C, connections, result sets, queries. */ @@ -918,7 +918,7 @@ static zoom_ret ZOOM_connection_send_init (ZOOM_connection c) ZOOM_options_get(c->options, "implementationName"), odr_prepend(c->odr_out, "ZOOM-C", ireq->implementationName)); - version = odr_strdup(c->odr_out, "$Revision: 1.15 $"); + version = odr_strdup(c->odr_out, "$Revision: 1.16 $"); if (strlen(version) > 10) /* check for unexpanded CVS strings */ version[strlen(version)-2] = '\0'; ireq->implementationVersion = odr_prepend(c->odr_out, @@ -1059,7 +1059,7 @@ static zoom_ret send_srw (ZOOM_connection c, Z_SRW_PDU *sr) ret = z_soap_codec_enc(o, &p, &gdu->u.HTTP_Request->content_buf, &gdu->u.HTTP_Request->content_len, h, - c->charset); + c->charset, 0); if (!z_GDU(c->odr_out, &gdu, 0, 0)) return zoom_complete; -- 1.7.10.4