2 * Copyright (C) 1995-2005, Index Data ApS
3 * See the file LICENSE for details.
5 * $Id: srwutil.c,v 1.42 2006-06-05 18:08:10 adam Exp $
9 * \brief Implements SRW/SRU utilities.
14 #include <yaz/yaz-iconv.h>
16 static int hex_digit (int ch)
18 if (ch >= '0' && ch <= '9')
20 else if (ch >= 'a' && ch <= 'f')
22 else if (ch >= 'A' && ch <= 'F')
27 void encode_uri_char(char *dst, char ch)
31 else if ((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z') ||
32 (ch >= '0' && ch <= '9'))
40 sprintf(dst+1, "%02X", (unsigned char ) ch);
44 void yaz_array_to_uri(char **path, ODR o, char **name, char **value)
46 size_t i, szp = 0, sz = 0;
47 for(i = 0; name[i]; i++)
48 sz += strlen(name[i]) + 3 + strlen(value[i]) * 3;
49 *path = odr_malloc(o, sz);
51 for(i = 0; name[i]; i++)
56 ilen = strlen(name[i]);
57 memcpy(*path+szp, name[i], ilen);
60 for (j = 0; value[i][j]; j++)
64 encode_uri_char(vstr, value[i][j]);
66 memcpy(*path+szp, vstr, vlen);
73 int yaz_uri_array(const char *path, ODR o, char ***name, char ***val)
83 while ((cp = strchr(cp, '&')))
88 *name = odr_malloc(o, no * sizeof(char*));
89 *val = odr_malloc(o, no * sizeof(char*));
91 for (no = 0; *path; no++)
93 const char *p1 = strchr(path, '=');
99 (*name)[no] = odr_malloc(o, (p1-path)+1);
100 memcpy((*name)[no], path, p1-path);
101 (*name)[no][p1-path] = '\0';
104 p1 = strchr(path, '&');
106 p1 = strlen(path) + path;
107 (*val)[no] = ret = odr_malloc(o, p1 - path + 1);
108 while (*path && *path != '&')
115 else if (*path == '%' && path[1] && path[2])
117 ret[i++] = hex_digit (path[1])*16 + hex_digit (path[2]);
133 char *yaz_uri_val(const char *path, const char *name, ODR o)
135 size_t nlen = strlen(name);
139 while (path && *path)
141 const char *p1 = strchr(path, '=');
144 if ((size_t)(p1 - path) == nlen && !memcmp(path, name, nlen))
150 p1 = strchr(path, '&');
152 p1 = strlen(path) + path;
153 ret = (char *) odr_malloc(o, p1 - path + 1);
154 while (*path && *path != '&')
161 else if (*path == '%' && path[1] && path[2])
163 ret[i++] = hex_digit (path[1])*16 + hex_digit (path[2]);
172 path = strchr(p1, '&');
179 static int yaz_base64decode(const char *in, char *out)
181 const char *map = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
182 "abcdefghijklmnopqrstuvwxyz0123456789+/";
184 int len = strlen(in);
191 if (!(p = strchr(map, in[0])))
195 if (!(p = strchr(map, in[1])))
199 *(out++) = i0 << 2 | i1 >> 4;
203 if (!(p = strchr(map, in[2])))
207 *(out++) = i1 << 4 | i2 >> 2;
211 if (!(p = strchr(map, in[3])))
215 *(out++) = i2 << 6 | i3;
226 * Look for authentication tokens in HTTP Basic parameters or in x-username/x-password
227 * parameters. Added by SH.
229 static void yaz_srw_decodeauth(Z_SRW_PDU *sr, Z_HTTP_Request *hreq, char *username,
230 char *password, ODR decode)
232 const char *basic = z_HTTP_header_lookup(hreq->headers, "Authorization");
235 sr->username = username;
237 sr->password = password;
242 char ubuf[256] = "", pbuf[256] = "", *p;
243 if (strncmp(basic, "Basic ", 6))
247 if (!len || len > 256)
249 olen = yaz_base64decode(basic, out);
250 /* Format of out should be username:password at this point */
252 if ((p = strchr(ubuf, ':'))) {
258 sr->username = odr_strdup(decode, ubuf);
260 sr->password = odr_strdup(decode, pbuf);
264 void yaz_uri_val_int(const char *path, const char *name, ODR o, int **intp)
266 const char *v = yaz_uri_val(path, name, o);
268 *intp = odr_intdup(o, atoi(v));
271 void yaz_mk_srw_diagnostic(ODR o, Z_SRW_diagnostic *d,
272 const char *uri, const char *message,
275 d->uri = odr_strdup(o, uri);
277 d->message = odr_strdup(o, message);
281 d->details = odr_strdup(o, details);
286 void yaz_mk_std_diagnostic(ODR o, Z_SRW_diagnostic *d,
287 int code, const char *details)
291 sprintf(uri, "info:srw/diagnostic/1/%d", code);
292 yaz_mk_srw_diagnostic(o, d, uri, 0, details);
295 void yaz_add_srw_diagnostic_uri(ODR o, Z_SRW_diagnostic **d,
296 int *num, const char *uri,
297 const char *message, const char *details)
299 Z_SRW_diagnostic *d_new;
300 d_new = (Z_SRW_diagnostic *) odr_malloc (o, (*num + 1)* sizeof(**d));
302 memcpy (d_new, *d, *num *sizeof(**d));
305 yaz_mk_srw_diagnostic(o, *d + *num, uri, message, details);
309 void yaz_add_srw_diagnostic(ODR o, Z_SRW_diagnostic **d,
310 int *num, int code, const char *addinfo)
314 sprintf(uri, "info:srw/diagnostic/1/%d", code);
315 yaz_add_srw_diagnostic_uri(o, d, num, uri, 0, addinfo);
318 int yaz_srw_decode(Z_HTTP_Request *hreq, Z_SRW_PDU **srw_pdu,
319 Z_SOAP **soap_package, ODR decode, char **charset)
321 if (!strcmp(hreq->method, "POST"))
323 const char *content_type = z_HTTP_header_lookup(hreq->headers,
326 (!yaz_strcmp_del("text/xml", content_type, "; ") ||
327 !yaz_strcmp_del("application/soap+xml", content_type, "; ") ||
328 !yaz_strcmp_del("text/plain", content_type, "; ")))
330 char *db = "Default";
331 const char *p0 = hreq->path, *p1;
333 const char *charset_p = 0;
335 static Z_SOAP_Handler soap_handlers[4] = {
337 {"http://www.loc.gov/zing/srw/", 0,
338 (Z_SOAP_fun) yaz_srw_codec},
339 {"http://www.loc.gov/zing/srw/v1.0/", 0,
340 (Z_SOAP_fun) yaz_srw_codec},
341 {"http://www.loc.gov/zing/srw/update/", 0,
342 (Z_SOAP_fun) yaz_ucp_codec},
349 p1 = strchr(p0, '?');
351 p1 = p0 + strlen(p0);
354 db = (char*) odr_malloc(decode, p1 - p0 + 1);
355 memcpy (db, p0, p1 - p0);
359 if (charset && (charset_p = strstr(content_type, "; charset=")))
363 while (i < 20 && charset_p[i] &&
364 !strchr("; \n\r", charset_p[i]))
366 *charset = (char*) odr_malloc(decode, i+1);
367 memcpy(*charset, charset_p, i);
368 (*charset)[i] = '\0';
370 ret = z_soap_codec(decode, soap_package,
371 &hreq->content_buf, &hreq->content_len,
373 if (ret == 0 && (*soap_package)->which == Z_SOAP_generic)
375 *srw_pdu = (Z_SRW_PDU*) (*soap_package)->u.generic->p;
377 if ((*srw_pdu)->which == Z_SRW_searchRetrieve_request &&
378 (*srw_pdu)->u.request->database == 0)
379 (*srw_pdu)->u.request->database = db;
381 if ((*srw_pdu)->which == Z_SRW_explain_request &&
382 (*srw_pdu)->u.explain_request->database == 0)
383 (*srw_pdu)->u.explain_request->database = db;
385 if ((*srw_pdu)->which == Z_SRW_scan_request &&
386 (*srw_pdu)->u.scan_request->database == 0)
387 (*srw_pdu)->u.scan_request->database = db;
389 if ((*srw_pdu)->which == Z_SRW_update_request &&
390 (*srw_pdu)->u.update_request->database == 0)
391 (*srw_pdu)->u.update_request->database = db;
401 static int yaz_sru_integer_decode(ODR odr, const char *pname,
402 const char *valstr, int **valp,
403 Z_SRW_diagnostic **diag, int *num_diag)
409 if (sscanf(valstr, "%d", &ival) != 1)
411 yaz_add_srw_diagnostic(odr, diag, num_diag, 6, pname);
414 *valp = odr_intdup(odr, ival);
418 http://www.loc.gov/z3950/agency/zing/srw/service.html
420 int yaz_sru_decode(Z_HTTP_Request *hreq, Z_SRW_PDU **srw_pdu,
421 Z_SOAP **soap_package, ODR decode, char **charset,
422 Z_SRW_diagnostic **diag, int *num_diag)
425 static Z_SOAP_Handler soap_handlers[2] = {
426 {"http://www.loc.gov/zing/srw/", 0,
427 (Z_SOAP_fun) yaz_srw_codec},
431 const char *content_type = z_HTTP_header_lookup(hreq->headers,
434 SRU GET: allow any content type.
435 SRU POST: we support "application/x-www-form-urlencoded";
436 not "multipart/form-data" .
438 if (!strcmp(hreq->method, "GET")
440 (!strcmp(hreq->method, "POST")
442 !yaz_strcmp_del("application/x-www-form-urlencoded",
447 char *db = "Default";
448 const char *p0 = hreq->path, *p1;
450 const char *operation = 0;
457 char *stylesheet = 0;
458 char *scanClause = 0;
459 char *pScanClause = 0;
460 char *recordXPath = 0;
461 char *recordSchema = 0;
462 char *recordPacking = "xml"; /* xml packing is default for SRU */
463 char *maximumRecords = 0;
464 char *startRecord = 0;
465 char *maximumTerms = 0;
466 char *responsePosition = 0;
467 char *extraRequestData = 0;
476 p1 = strchr(p0, '?');
478 p1 = p0 + strlen(p0);
481 db = (char*) odr_malloc(decode, p1 - p0 + 1);
482 memcpy (db, p0, p1 - p0);
485 if (!strcmp(hreq->method, "POST"))
486 p1 = hreq->content_buf;
487 yaz_uri_array(p1, decode, &uri_name, &uri_val);
492 for (i = 0; uri_name[i]; i++)
494 char *n = uri_name[i];
495 char *v = uri_val[i];
496 if (!strcmp(n, "query"))
498 else if (!strcmp(n, "x-pquery"))
500 else if (!strcmp(n, "x-username"))
502 else if (!strcmp(n, "x-password"))
504 else if (!strcmp(n, "operation"))
506 else if (!strcmp(n, "stylesheet"))
508 else if (!strcmp(n, "sortKeys"))
510 else if (!strcmp(n, "recordXPath"))
512 else if (!strcmp(n, "recordSchema"))
514 else if (!strcmp(n, "recordPacking"))
516 else if (!strcmp(n, "version"))
518 else if (!strcmp(n, "scanClause"))
520 else if (!strcmp(n, "x-pScanClause"))
522 else if (!strcmp(n, "maximumRecords"))
524 else if (!strcmp(n, "startRecord"))
526 else if (!strcmp(n, "maximumTerms"))
528 else if (!strcmp(n, "responsePosition"))
529 responsePosition = v;
530 else if (!strcmp(n, "extraRequestData"))
531 extraRequestData = v;
533 yaz_add_srw_diagnostic(decode, diag, num_diag, 8, n);
539 yaz_add_srw_diagnostic(decode, diag, num_diag, 7, "version");
542 if (strcmp(version, "1.1"))
543 yaz_add_srw_diagnostic(decode, diag, num_diag, 5, "1.1");
547 yaz_add_srw_diagnostic(decode, diag, num_diag, 7, "operation");
548 operation = "explain";
550 if (!strcmp(operation, "searchRetrieve"))
552 Z_SRW_PDU *sr = yaz_srw_get(decode, Z_SRW_searchRetrieve_request);
554 sr->srw_version = version;
556 yaz_srw_decodeauth(sr, hreq, username, password, decode);
559 sr->u.request->query_type = Z_SRW_query_type_cql;
560 sr->u.request->query.cql = query;
564 sr->u.request->query_type = Z_SRW_query_type_pqf;
565 sr->u.request->query.pqf = pQuery;
568 yaz_add_srw_diagnostic(decode, diag, num_diag, 7, "query");
572 sr->u.request->sort_type = Z_SRW_sort_type_sort;
573 sr->u.request->sort.sortKeys = sortKeys;
575 sr->u.request->recordXPath = recordXPath;
576 sr->u.request->recordSchema = recordSchema;
577 sr->u.request->recordPacking = recordPacking;
578 sr->u.request->stylesheet = stylesheet;
580 yaz_sru_integer_decode(decode, "maximumRecords", maximumRecords,
581 &sr->u.request->maximumRecords,
584 yaz_sru_integer_decode(decode, "startRecord", startRecord,
585 &sr->u.request->startRecord,
588 sr->u.request->database = db;
590 (*soap_package) = odr_malloc(decode, sizeof(**soap_package));
591 (*soap_package)->which = Z_SOAP_generic;
593 (*soap_package)->u.generic =
594 odr_malloc(decode, sizeof(*(*soap_package)->u.generic));
596 (*soap_package)->u.generic->p = sr;
597 (*soap_package)->u.generic->ns = soap_handlers[0].ns;
598 (*soap_package)->u.generic->no = 0;
600 (*soap_package)->ns = "SRU";
604 else if (!strcmp(operation, "explain"))
606 /* Transfer SRU explain parameters to common struct */
607 /* http://www.loc.gov/z3950/agency/zing/srw/explain.html */
608 Z_SRW_PDU *sr = yaz_srw_get(decode, Z_SRW_explain_request);
610 sr->srw_version = version;
611 yaz_srw_decodeauth(sr, hreq, username, password, decode);
613 sr->u.explain_request->recordPacking = recordPacking;
614 sr->u.explain_request->database = db;
616 sr->u.explain_request->stylesheet = stylesheet;
618 (*soap_package) = odr_malloc(decode, sizeof(**soap_package));
619 (*soap_package)->which = Z_SOAP_generic;
621 (*soap_package)->u.generic =
622 odr_malloc(decode, sizeof(*(*soap_package)->u.generic));
624 (*soap_package)->u.generic->p = sr;
625 (*soap_package)->u.generic->ns = soap_handlers[0].ns;
626 (*soap_package)->u.generic->no = 0;
628 (*soap_package)->ns = "SRU";
632 else if (!strcmp(operation, "scan"))
634 /* Transfer SRU scan parameters to common struct */
635 /* http://www.loc.gov/z3950/agency/zing/srw/scan.html */
636 Z_SRW_PDU *sr = yaz_srw_get(decode, Z_SRW_scan_request);
638 sr->srw_version = version;
640 yaz_srw_decodeauth(sr, hreq, username, password, decode);
644 sr->u.scan_request->query_type = Z_SRW_query_type_cql;
645 sr->u.scan_request->scanClause.cql = scanClause;
647 else if (pScanClause)
649 sr->u.scan_request->query_type = Z_SRW_query_type_pqf;
650 sr->u.scan_request->scanClause.pqf = pScanClause;
653 yaz_add_srw_diagnostic(decode, diag, num_diag, 7,
655 sr->u.scan_request->database = db;
657 yaz_sru_integer_decode(decode, "maximumTerms",
659 &sr->u.scan_request->maximumTerms,
662 yaz_sru_integer_decode(decode, "responsePosition",
664 &sr->u.scan_request->responsePosition,
667 sr->u.scan_request->stylesheet = stylesheet;
669 (*soap_package) = odr_malloc(decode, sizeof(**soap_package));
670 (*soap_package)->which = Z_SOAP_generic;
672 (*soap_package)->u.generic =
673 odr_malloc(decode, sizeof(*(*soap_package)->u.generic));
675 (*soap_package)->u.generic->p = sr;
676 (*soap_package)->u.generic->ns = soap_handlers[0].ns;
677 (*soap_package)->u.generic->no = 0;
679 (*soap_package)->ns = "SRU";
685 /* unsupported operation ... */
686 /* Act as if we received a explain request and throw diagnostic. */
688 Z_SRW_PDU *sr = yaz_srw_get(decode, Z_SRW_explain_request);
690 sr->srw_version = version;
692 sr->u.explain_request->recordPacking = recordPacking;
693 sr->u.explain_request->database = db;
695 sr->u.explain_request->stylesheet = stylesheet;
697 (*soap_package) = odr_malloc(decode, sizeof(**soap_package));
698 (*soap_package)->which = Z_SOAP_generic;
700 (*soap_package)->u.generic =
701 odr_malloc(decode, sizeof(*(*soap_package)->u.generic));
703 (*soap_package)->u.generic->p = sr;
704 (*soap_package)->u.generic->ns = soap_handlers[0].ns;
705 (*soap_package)->u.generic->no = 0;
707 (*soap_package)->ns = "SRU";
709 yaz_add_srw_diagnostic(decode, diag, num_diag, 4, operation);
718 Z_SRW_extra_record *yaz_srw_get_extra_record(ODR o)
720 Z_SRW_extra_record *res = (Z_SRW_extra_record *)
721 odr_malloc(o, sizeof(*res));
723 res->recordReviewCode = 0;
724 res->recordReviewNote = 0;
726 res->nonDupRecordId = 0;
727 res->recordLockStatus = 0;
728 res->recordOldVersion = 0;
732 Z_SRW_PDU *yaz_srw_get(ODR o, int which)
734 Z_SRW_PDU *sr = (Z_SRW_PDU *) odr_malloc(o, sizeof(*o));
738 sr->srw_version = odr_strdup(o, "1.1");
742 case Z_SRW_searchRetrieve_request:
743 sr->u.request = (Z_SRW_searchRetrieveRequest *)
744 odr_malloc(o, sizeof(*sr->u.request));
745 sr->u.request->query_type = Z_SRW_query_type_cql;
746 sr->u.request->query.cql = 0;
747 sr->u.request->sort_type = Z_SRW_sort_type_none;
748 sr->u.request->sort.none = 0;
749 sr->u.request->startRecord = 0;
750 sr->u.request->maximumRecords = 0;
751 sr->u.request->recordSchema = 0;
752 sr->u.request->recordPacking = 0;
753 sr->u.request->recordXPath = 0;
754 sr->u.request->database = 0;
755 sr->u.request->resultSetTTL = 0;
756 sr->u.request->stylesheet = 0;
758 case Z_SRW_searchRetrieve_response:
759 sr->u.response = (Z_SRW_searchRetrieveResponse *)
760 odr_malloc(o, sizeof(*sr->u.response));
761 sr->u.response->numberOfRecords = 0;
762 sr->u.response->resultSetId = 0;
763 sr->u.response->resultSetIdleTime = 0;
764 sr->u.response->records = 0;
765 sr->u.response->num_records = 0;
766 sr->u.response->diagnostics = 0;
767 sr->u.response->num_diagnostics = 0;
768 sr->u.response->nextRecordPosition = 0;
769 sr->u.response->extra_records = 0;
771 case Z_SRW_explain_request:
772 sr->u.explain_request = (Z_SRW_explainRequest *)
773 odr_malloc(o, sizeof(*sr->u.explain_request));
774 sr->u.explain_request->recordPacking = 0;
775 sr->u.explain_request->database = 0;
776 sr->u.explain_request->stylesheet = 0;
778 case Z_SRW_explain_response:
779 sr->u.explain_response = (Z_SRW_explainResponse *)
780 odr_malloc(o, sizeof(*sr->u.explain_response));
781 sr->u.explain_response->record.recordData_buf = 0;
782 sr->u.explain_response->record.recordData_len = 0;
783 sr->u.explain_response->record.recordSchema = 0;
784 sr->u.explain_response->record.recordPosition = 0;
785 sr->u.explain_response->record.recordPacking =
786 Z_SRW_recordPacking_string;
787 sr->u.explain_response->diagnostics = 0;
788 sr->u.explain_response->num_diagnostics = 0;
789 sr->u.explain_response->extra_record = 0;
791 case Z_SRW_scan_request:
792 sr->u.scan_request = (Z_SRW_scanRequest *)
793 odr_malloc(o, sizeof(*sr->u.scan_request));
794 sr->u.scan_request->database = 0;
795 sr->u.scan_request->stylesheet = 0;
796 sr->u.scan_request->maximumTerms = 0;
797 sr->u.scan_request->responsePosition = 0;
798 sr->u.scan_request->query_type = Z_SRW_query_type_cql;
799 sr->u.scan_request->scanClause.cql = 0;
801 case Z_SRW_scan_response:
802 sr->u.scan_response = (Z_SRW_scanResponse *)
803 odr_malloc(o, sizeof(*sr->u.scan_response));
804 sr->u.scan_response->terms = 0;
805 sr->u.scan_response->num_terms = 0;
806 sr->u.scan_response->diagnostics = 0;
807 sr->u.scan_response->num_diagnostics = 0;
809 case Z_SRW_update_request:
810 sr->u.update_request = (Z_SRW_updateRequest *)
811 odr_malloc(o, sizeof(*sr->u.update_request));
812 sr->u.update_request->database = 0;
813 sr->u.update_request->stylesheet = 0;
814 sr->u.update_request->record.recordSchema = 0;
815 sr->u.update_request->record.recordPacking = Z_SRW_recordPacking_XML;
816 sr->u.update_request->recordId = 0;
817 sr->u.update_request->recordVersion = 0;
818 sr->u.update_request->recordOldVersion = 0;
819 sr->u.update_request->record.recordData_buf = 0;
820 sr->u.update_request->record.recordData_len = 0;
821 sr->u.update_request->extra_record = 0;
822 sr->u.update_request->extraRequestData = 0;
823 sr->u.request->database = 0;
825 case Z_SRW_update_response:
826 sr->u.update_response = (Z_SRW_updateResponse *)
827 odr_malloc(o, sizeof(*sr->u.update_response));
828 sr->u.update_response->operationStatus = 0;
829 sr->u.update_response->recordId = 0;
830 sr->u.update_response->recordVersion = 0;
831 sr->u.update_response->recordChecksum = 0;
832 sr->u.update_response->record.recordData_buf = 0;
833 sr->u.update_response->record.recordData_len = 0;
834 sr->u.update_response->record.recordSchema = 0;
835 sr->u.update_response->record.recordPacking =
836 Z_SRW_recordPacking_XML;
837 sr->u.update_response->extra_record = 0;
838 sr->u.update_response->extraResponseData = 0;
839 sr->u.update_response->diagnostics = 0;
840 sr->u.update_response->num_diagnostics = 0;
846 static int srw_bib1_map[] = {
856 108, 10, /* Malformed query : Syntax error */
886 100, 1, /* bad map */
934 205, 1, /* bad map */
935 206, 1, /* bad map */
937 208, 1, /* bad map */
948 218, 1, /* bad map */
949 219, 1, /* bad map */
950 220, 1, /* bad map */
951 221, 1, /* bad map */
953 223, 1, /* bad map */
954 224, 1, /* bad map */
955 225, 1, /* bad map */
956 226, 1, /* bad map */
958 228, 1, /* bad map */
963 233, 1, /* bad map */
964 234, 1, /* bad map */
970 240, 1, /* bad map */
971 241, 1, /* bad map */
973 243, 1, /* bad map */
978 1001, 1, /* bad map */
979 1002, 1, /* bad map */
980 1003, 1, /* bad map */
981 1004, 1, /* bad map */
982 1005, 1, /* bad map */
983 1006, 1, /* bad map */
1015 int yaz_diag_bib1_to_srw (int code)
1017 const int *p = srw_bib1_map;
1027 int yaz_diag_srw_to_bib1(int code)
1029 const int *p = srw_bib1_map;
1039 static void add_val_int(ODR o, char **name, char **value, int *i,
1040 char *a_name, int *val)
1045 value[*i] = odr_malloc(o, 30);
1046 sprintf(value[*i], "%d", *val);
1051 static void add_val_str(ODR o, char **name, char **value, int *i,
1052 char *a_name, char *val)
1062 static int yaz_get_sru_parms(const Z_SRW_PDU *srw_pdu, ODR encode,
1063 char **name, char **value)
1066 add_val_str(encode, name, value, &i, "version", srw_pdu->srw_version);
1067 name[i] = "operation";
1068 switch(srw_pdu->which)
1070 case Z_SRW_searchRetrieve_request:
1071 value[i++] = "searchRetrieve";
1072 switch(srw_pdu->u.request->query_type)
1074 case Z_SRW_query_type_cql:
1075 add_val_str(encode, name, value, &i, "query",
1076 srw_pdu->u.request->query.cql);
1078 case Z_SRW_query_type_pqf:
1079 add_val_str(encode, name, value, &i, "x-pquery",
1080 srw_pdu->u.request->query.pqf);
1082 case Z_SRW_query_type_xcql:
1083 add_val_str(encode, name, value, &i, "x-cql",
1084 srw_pdu->u.request->query.xcql);
1087 switch(srw_pdu->u.request->sort_type)
1089 case Z_SRW_sort_type_none:
1091 case Z_SRW_sort_type_sort:
1092 add_val_str(encode, name, value, &i, "sortKeys",
1093 srw_pdu->u.request->sort.sortKeys);
1096 add_val_int(encode, name, value, &i, "startRecord",
1097 srw_pdu->u.request->startRecord);
1098 add_val_int(encode, name, value, &i, "maximumRecords",
1099 srw_pdu->u.request->maximumRecords);
1100 add_val_str(encode, name, value, &i, "recordSchema",
1101 srw_pdu->u.request->recordSchema);
1102 add_val_str(encode, name, value, &i, "recordPacking",
1103 srw_pdu->u.request->recordPacking);
1104 add_val_str(encode, name, value, &i, "recordXPath",
1105 srw_pdu->u.request->recordXPath);
1106 add_val_str(encode, name, value, &i, "stylesheet",
1107 srw_pdu->u.request->stylesheet);
1108 add_val_int(encode, name, value, &i, "resultSetTTL",
1109 srw_pdu->u.request->resultSetTTL);
1111 case Z_SRW_explain_request:
1112 value[i++] = "explain";
1113 add_val_str(encode, name, value, &i, "stylesheet",
1114 srw_pdu->u.explain_request->stylesheet);
1116 case Z_SRW_scan_request:
1117 value[i++] = "scan";
1119 switch(srw_pdu->u.scan_request->query_type)
1121 case Z_SRW_query_type_cql:
1122 add_val_str(encode, name, value, &i, "scanClause",
1123 srw_pdu->u.scan_request->scanClause.cql);
1125 case Z_SRW_query_type_pqf:
1126 add_val_str(encode, name, value, &i, "x-pScanClause",
1127 srw_pdu->u.scan_request->scanClause.pqf);
1129 case Z_SRW_query_type_xcql:
1130 add_val_str(encode, name, value, &i, "x-cqlScanClause",
1131 srw_pdu->u.scan_request->scanClause.xcql);
1134 add_val_int(encode, name, value, &i, "responsePosition",
1135 srw_pdu->u.scan_request->responsePosition);
1136 add_val_int(encode, name, value, &i, "maximumTerms",
1137 srw_pdu->u.scan_request->maximumTerms);
1138 add_val_str(encode, name, value, &i, "stylesheet",
1139 srw_pdu->u.scan_request->stylesheet);
1141 case Z_SRW_update_request:
1142 value[i++] = "update";
1151 int yaz_sru_get_encode(Z_HTTP_Request *hreq, Z_SRW_PDU *srw_pdu,
1152 ODR encode, const char *charset)
1154 char *name[30], *value[30]; /* definite upper limit for SRU params */
1158 if (yaz_get_sru_parms(srw_pdu, encode, name, value))
1160 yaz_array_to_uri(&uri_args, encode, name, value);
1162 hreq->method = "GET";
1164 path = odr_malloc(encode, strlen(hreq->path) + strlen(uri_args) + 3);
1165 sprintf(path, "%s?%s", hreq->path, uri_args);
1168 z_HTTP_header_add_content_type(encode, &hreq->headers,
1169 "text/xml", charset);
1173 int yaz_sru_post_encode(Z_HTTP_Request *hreq, Z_SRW_PDU *srw_pdu,
1174 ODR encode, const char *charset)
1176 char *name[30], *value[30]; /* definite upper limit for SRU params */
1179 if (yaz_get_sru_parms(srw_pdu, encode, name, value))
1182 yaz_array_to_uri(&uri_args, encode, name, value);
1184 hreq->method = "POST";
1186 hreq->content_buf = uri_args;
1187 hreq->content_len = strlen(uri_args);
1189 z_HTTP_header_add_content_type(encode, &hreq->headers,
1190 "application/x-www-form-urlencoded",
1195 int yaz_sru_soap_encode(Z_HTTP_Request *hreq, Z_SRW_PDU *srw_pdu,
1196 ODR odr, const char *charset)
1198 Z_SOAP_Handler handlers[2] = {
1199 {"http://www.loc.gov/zing/srw/", 0, (Z_SOAP_fun) yaz_srw_codec},
1202 Z_SOAP *p = (Z_SOAP*) odr_malloc(odr, sizeof(*p));
1203 z_HTTP_header_add_content_type(odr,
1205 "text/xml", charset);
1207 z_HTTP_header_add(odr, &hreq->headers,
1208 "SOAPAction", "\"\"");
1209 p->which = Z_SOAP_generic;
1210 p->u.generic = (Z_SOAP_Generic *) odr_malloc(odr, sizeof(*p->u.generic));
1211 p->u.generic->no = 0;
1212 p->u.generic->ns = 0;
1213 p->u.generic->p = srw_pdu;
1214 p->ns = "http://schemas.xmlsoap.org/soap/envelope/";
1216 return z_soap_codec_enc(odr, &p,
1218 &hreq->content_len, handlers,
1225 * indent-tabs-mode: nil
1227 * vim: shiftwidth=4 tabstop=8 expandtab