2 * Copyright (C) 1995-2005, Index Data ApS
3 * See the file LICENSE for details.
5 * $Id: srwutil.c,v 1.39 2006-05-05 20:02:22 quinn 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 = index(map, in[0])))
195 if (!(p = index(map, in[1])))
199 *(out++) = i0 << 2 | i1 >> 4;
203 if (!(p = index(map, in[2])))
207 *(out++) = i1 << 4 | i2 >> 2;
211 if (!(p = index(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 = index(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;
402 http://www.loc.gov/z3950/agency/zing/srw/service.html
404 int yaz_sru_decode(Z_HTTP_Request *hreq, Z_SRW_PDU **srw_pdu,
405 Z_SOAP **soap_package, ODR decode, char **charset,
406 Z_SRW_diagnostic **diag, int *num_diag)
409 static Z_SOAP_Handler soap_handlers[2] = {
410 {"http://www.loc.gov/zing/srw/", 0,
411 (Z_SOAP_fun) yaz_srw_codec},
415 const char *content_type = z_HTTP_header_lookup(hreq->headers,
418 SRU GET: allow any content type.
419 SRU POST: we support "application/x-www-form-urlencoded";
420 not "multipart/form-data" .
422 if (!strcmp(hreq->method, "GET")
424 (!strcmp(hreq->method, "POST")
426 !yaz_strcmp_del("application/x-www-form-urlencoded",
431 char *db = "Default";
432 const char *p0 = hreq->path, *p1;
434 const char *operation = 0;
441 char *stylesheet = 0;
442 char *scanClause = 0;
443 char *pScanClause = 0;
444 char *recordXPath = 0;
445 char *recordSchema = 0;
446 char *recordPacking = "xml"; /* xml packing is default for SRU */
447 char *maximumRecords = 0;
448 char *startRecord = 0;
449 char *maximumTerms = 0;
450 char *responsePosition = 0;
451 char *extraRequestData = 0;
460 p1 = strchr(p0, '?');
462 p1 = p0 + strlen(p0);
465 db = (char*) odr_malloc(decode, p1 - p0 + 1);
466 memcpy (db, p0, p1 - p0);
469 if (!strcmp(hreq->method, "POST"))
470 p1 = hreq->content_buf;
471 yaz_uri_array(p1, decode, &uri_name, &uri_val);
476 for (i = 0; uri_name[i]; i++)
478 char *n = uri_name[i];
479 char *v = uri_val[i];
480 if (!strcmp(n, "query"))
482 else if (!strcmp(n, "x-pquery"))
484 else if (!strcmp(n, "x-username"))
486 else if (!strcmp(n, "x-password"))
488 else if (!strcmp(n, "operation"))
490 else if (!strcmp(n, "stylesheet"))
492 else if (!strcmp(n, "sortKeys"))
494 else if (!strcmp(n, "recordXPath"))
496 else if (!strcmp(n, "recordSchema"))
498 else if (!strcmp(n, "recordPacking"))
500 else if (!strcmp(n, "version"))
502 else if (!strcmp(n, "scanClause"))
504 else if (!strcmp(n, "x-pScanClause"))
506 else if (!strcmp(n, "maximumRecords"))
508 else if (!strcmp(n, "startRecord"))
510 else if (!strcmp(n, "maximumTerms"))
512 else if (!strcmp(n, "responsePosition"))
513 responsePosition = v;
514 else if (!strcmp(n, "extraRequestData"))
515 extraRequestData = v;
517 yaz_add_srw_diagnostic(decode, diag, num_diag, 8, n);
523 yaz_add_srw_diagnostic(decode, diag, num_diag, 7, "version");
526 if (strcmp(version, "1.1"))
527 yaz_add_srw_diagnostic(decode, diag, num_diag, 5, "1.1");
531 yaz_add_srw_diagnostic(decode, diag, num_diag, 7, "operation");
532 operation = "explain";
534 if (!strcmp(operation, "searchRetrieve"))
536 Z_SRW_PDU *sr = yaz_srw_get(decode, Z_SRW_searchRetrieve_request);
538 sr->srw_version = version;
540 yaz_srw_decodeauth(sr, hreq, username, password, decode);
543 sr->u.request->query_type = Z_SRW_query_type_cql;
544 sr->u.request->query.cql = query;
548 sr->u.request->query_type = Z_SRW_query_type_pqf;
549 sr->u.request->query.pqf = pQuery;
552 yaz_add_srw_diagnostic(decode, diag, num_diag, 7, "query");
556 sr->u.request->sort_type = Z_SRW_sort_type_sort;
557 sr->u.request->sort.sortKeys = sortKeys;
559 sr->u.request->recordXPath = recordXPath;
560 sr->u.request->recordSchema = recordSchema;
561 sr->u.request->recordPacking = recordPacking;
562 sr->u.request->stylesheet = stylesheet;
565 sr->u.request->maximumRecords =
566 odr_intdup(decode, atoi(maximumRecords));
568 sr->u.request->startRecord =
569 odr_intdup(decode, atoi(startRecord));
571 sr->u.request->database = db;
573 (*soap_package) = odr_malloc(decode, sizeof(**soap_package));
574 (*soap_package)->which = Z_SOAP_generic;
576 (*soap_package)->u.generic =
577 odr_malloc(decode, sizeof(*(*soap_package)->u.generic));
579 (*soap_package)->u.generic->p = sr;
580 (*soap_package)->u.generic->ns = soap_handlers[0].ns;
581 (*soap_package)->u.generic->no = 0;
583 (*soap_package)->ns = "SRU";
587 else if (!strcmp(operation, "explain"))
589 /* Transfer SRU explain parameters to common struct */
590 /* http://www.loc.gov/z3950/agency/zing/srw/explain.html */
591 Z_SRW_PDU *sr = yaz_srw_get(decode, Z_SRW_explain_request);
593 sr->srw_version = version;
594 yaz_srw_decodeauth(sr, hreq, username, password, decode);
596 sr->u.explain_request->recordPacking = recordPacking;
597 sr->u.explain_request->database = db;
599 sr->u.explain_request->stylesheet = stylesheet;
601 (*soap_package) = odr_malloc(decode, sizeof(**soap_package));
602 (*soap_package)->which = Z_SOAP_generic;
604 (*soap_package)->u.generic =
605 odr_malloc(decode, sizeof(*(*soap_package)->u.generic));
607 (*soap_package)->u.generic->p = sr;
608 (*soap_package)->u.generic->ns = soap_handlers[0].ns;
609 (*soap_package)->u.generic->no = 0;
611 (*soap_package)->ns = "SRU";
615 else if (!strcmp(operation, "scan"))
617 /* Transfer SRU scan parameters to common struct */
618 /* http://www.loc.gov/z3950/agency/zing/srw/scan.html */
619 Z_SRW_PDU *sr = yaz_srw_get(decode, Z_SRW_scan_request);
621 sr->srw_version = version;
623 yaz_srw_decodeauth(sr, hreq, username, password, decode);
627 sr->u.scan_request->query_type = Z_SRW_query_type_cql;
628 sr->u.scan_request->scanClause.cql = scanClause;
630 else if (pScanClause)
632 sr->u.scan_request->query_type = Z_SRW_query_type_pqf;
633 sr->u.scan_request->scanClause.pqf = pScanClause;
636 yaz_add_srw_diagnostic(decode, diag, num_diag, 7,
638 sr->u.scan_request->database = db;
641 sr->u.scan_request->maximumTerms =
642 odr_intdup(decode, atoi(maximumTerms));
643 if (responsePosition)
644 sr->u.scan_request->responsePosition =
645 odr_intdup(decode, atoi(responsePosition));
647 sr->u.scan_request->stylesheet = stylesheet;
649 (*soap_package) = odr_malloc(decode, sizeof(**soap_package));
650 (*soap_package)->which = Z_SOAP_generic;
652 (*soap_package)->u.generic =
653 odr_malloc(decode, sizeof(*(*soap_package)->u.generic));
655 (*soap_package)->u.generic->p = sr;
656 (*soap_package)->u.generic->ns = soap_handlers[0].ns;
657 (*soap_package)->u.generic->no = 0;
659 (*soap_package)->ns = "SRU";
665 /* unsupported operation ... */
666 /* Act as if we received a explain request and throw diagnostic. */
668 Z_SRW_PDU *sr = yaz_srw_get(decode, Z_SRW_explain_request);
670 sr->srw_version = version;
672 sr->u.explain_request->recordPacking = recordPacking;
673 sr->u.explain_request->database = db;
675 sr->u.explain_request->stylesheet = stylesheet;
677 (*soap_package) = odr_malloc(decode, sizeof(**soap_package));
678 (*soap_package)->which = Z_SOAP_generic;
680 (*soap_package)->u.generic =
681 odr_malloc(decode, sizeof(*(*soap_package)->u.generic));
683 (*soap_package)->u.generic->p = sr;
684 (*soap_package)->u.generic->ns = soap_handlers[0].ns;
685 (*soap_package)->u.generic->no = 0;
687 (*soap_package)->ns = "SRU";
689 yaz_add_srw_diagnostic(decode, diag, num_diag, 4, operation);
698 Z_SRW_extra_record *yaz_srw_get_extra_record(ODR o)
700 Z_SRW_extra_record *res = (Z_SRW_extra_record *)
701 odr_malloc(o, sizeof(*res));
703 res->recordReviewCode = 0;
704 res->recordReviewNote = 0;
706 res->nonDupRecordId = 0;
707 res->recordLockStatus = 0;
708 res->recordOldVersion = 0;
712 Z_SRW_PDU *yaz_srw_get(ODR o, int which)
714 Z_SRW_PDU *sr = (Z_SRW_PDU *) odr_malloc(o, sizeof(*o));
718 sr->srw_version = odr_strdup(o, "1.1");
722 case Z_SRW_searchRetrieve_request:
723 sr->u.request = (Z_SRW_searchRetrieveRequest *)
724 odr_malloc(o, sizeof(*sr->u.request));
725 sr->u.request->query_type = Z_SRW_query_type_cql;
726 sr->u.request->query.cql = 0;
727 sr->u.request->sort_type = Z_SRW_sort_type_none;
728 sr->u.request->sort.none = 0;
729 sr->u.request->startRecord = 0;
730 sr->u.request->maximumRecords = 0;
731 sr->u.request->recordSchema = 0;
732 sr->u.request->recordPacking = 0;
733 sr->u.request->recordXPath = 0;
734 sr->u.request->database = 0;
735 sr->u.request->resultSetTTL = 0;
736 sr->u.request->stylesheet = 0;
738 case Z_SRW_searchRetrieve_response:
739 sr->u.response = (Z_SRW_searchRetrieveResponse *)
740 odr_malloc(o, sizeof(*sr->u.response));
741 sr->u.response->numberOfRecords = 0;
742 sr->u.response->resultSetId = 0;
743 sr->u.response->resultSetIdleTime = 0;
744 sr->u.response->records = 0;
745 sr->u.response->num_records = 0;
746 sr->u.response->diagnostics = 0;
747 sr->u.response->num_diagnostics = 0;
748 sr->u.response->nextRecordPosition = 0;
749 sr->u.response->extra_records = 0;
751 case Z_SRW_explain_request:
752 sr->u.explain_request = (Z_SRW_explainRequest *)
753 odr_malloc(o, sizeof(*sr->u.explain_request));
754 sr->u.explain_request->recordPacking = 0;
755 sr->u.explain_request->database = 0;
756 sr->u.explain_request->stylesheet = 0;
758 case Z_SRW_explain_response:
759 sr->u.explain_response = (Z_SRW_explainResponse *)
760 odr_malloc(o, sizeof(*sr->u.explain_response));
761 sr->u.explain_response->record.recordData_buf = 0;
762 sr->u.explain_response->record.recordData_len = 0;
763 sr->u.explain_response->record.recordSchema = 0;
764 sr->u.explain_response->record.recordPosition = 0;
765 sr->u.explain_response->record.recordPacking =
766 Z_SRW_recordPacking_string;
767 sr->u.explain_response->diagnostics = 0;
768 sr->u.explain_response->num_diagnostics = 0;
769 sr->u.explain_response->extra_record = 0;
771 case Z_SRW_scan_request:
772 sr->u.scan_request = (Z_SRW_scanRequest *)
773 odr_malloc(o, sizeof(*sr->u.scan_request));
774 sr->u.scan_request->database = 0;
775 sr->u.scan_request->stylesheet = 0;
776 sr->u.scan_request->maximumTerms = 0;
777 sr->u.scan_request->responsePosition = 0;
778 sr->u.scan_request->query_type = Z_SRW_query_type_cql;
779 sr->u.scan_request->scanClause.cql = 0;
781 case Z_SRW_scan_response:
782 sr->u.scan_response = (Z_SRW_scanResponse *)
783 odr_malloc(o, sizeof(*sr->u.scan_response));
784 sr->u.scan_response->terms = 0;
785 sr->u.scan_response->num_terms = 0;
786 sr->u.scan_response->diagnostics = 0;
787 sr->u.scan_response->num_diagnostics = 0;
789 case Z_SRW_update_request:
790 sr->u.update_request = (Z_SRW_updateRequest *)
791 odr_malloc(o, sizeof(*sr->u.update_request));
792 sr->u.update_request->database = 0;
793 sr->u.update_request->stylesheet = 0;
794 sr->u.update_request->record.recordSchema = 0;
795 sr->u.update_request->record.recordPacking = Z_SRW_recordPacking_XML;
796 sr->u.update_request->recordId = 0;
797 sr->u.update_request->recordVersion = 0;
798 sr->u.update_request->recordOldVersion = 0;
799 sr->u.update_request->record.recordData_buf = 0;
800 sr->u.update_request->record.recordData_len = 0;
801 sr->u.update_request->extra_record = 0;
802 sr->u.update_request->extraRequestData = 0;
803 sr->u.request->database = 0;
805 case Z_SRW_update_response:
806 sr->u.update_response = (Z_SRW_updateResponse *)
807 odr_malloc(o, sizeof(*sr->u.update_response));
808 sr->u.update_response->operationStatus = 0;
809 sr->u.update_response->recordId = 0;
810 sr->u.update_response->recordVersion = 0;
811 sr->u.update_response->recordChecksum = 0;
812 sr->u.update_response->record.recordData_buf = 0;
813 sr->u.update_response->record.recordData_len = 0;
814 sr->u.update_response->record.recordSchema = 0;
815 sr->u.update_response->record.recordPacking =
816 Z_SRW_recordPacking_XML;
817 sr->u.update_response->extra_record = 0;
818 sr->u.update_response->extraResponseData = 0;
819 sr->u.update_response->diagnostics = 0;
820 sr->u.update_response->num_diagnostics = 0;
826 static int srw_bib1_map[] = {
836 108, 10, /* Malformed query : Syntax error */
866 100, 1, /* bad map */
914 205, 1, /* bad map */
915 206, 1, /* bad map */
917 208, 1, /* bad map */
928 218, 1, /* bad map */
929 219, 1, /* bad map */
930 220, 1, /* bad map */
931 221, 1, /* bad map */
933 223, 1, /* bad map */
934 224, 1, /* bad map */
935 225, 1, /* bad map */
936 226, 1, /* bad map */
938 228, 1, /* bad map */
943 233, 1, /* bad map */
944 234, 1, /* bad map */
950 240, 1, /* bad map */
951 241, 1, /* bad map */
953 243, 1, /* bad map */
958 1001, 1, /* bad map */
959 1002, 1, /* bad map */
960 1003, 1, /* bad map */
961 1004, 1, /* bad map */
962 1005, 1, /* bad map */
963 1006, 1, /* bad map */
995 int yaz_diag_bib1_to_srw (int code)
997 const int *p = srw_bib1_map;
1007 int yaz_diag_srw_to_bib1(int code)
1009 const int *p = srw_bib1_map;
1019 static void add_val_int(ODR o, char **name, char **value, int *i,
1020 char *a_name, int *val)
1025 value[*i] = odr_malloc(o, 30);
1026 sprintf(value[*i], "%d", *val);
1031 static void add_val_str(ODR o, char **name, char **value, int *i,
1032 char *a_name, char *val)
1042 static int yaz_get_sru_parms(const Z_SRW_PDU *srw_pdu, ODR encode,
1043 char **name, char **value)
1046 add_val_str(encode, name, value, &i, "version", srw_pdu->srw_version);
1047 name[i] = "operation";
1048 switch(srw_pdu->which)
1050 case Z_SRW_searchRetrieve_request:
1051 value[i++] = "searchRetrieve";
1052 switch(srw_pdu->u.request->query_type)
1054 case Z_SRW_query_type_cql:
1055 add_val_str(encode, name, value, &i, "query",
1056 srw_pdu->u.request->query.cql);
1058 case Z_SRW_query_type_pqf:
1059 add_val_str(encode, name, value, &i, "x-pquery",
1060 srw_pdu->u.request->query.pqf);
1062 case Z_SRW_query_type_xcql:
1063 add_val_str(encode, name, value, &i, "x-cql",
1064 srw_pdu->u.request->query.xcql);
1067 switch(srw_pdu->u.request->sort_type)
1069 case Z_SRW_sort_type_none:
1071 case Z_SRW_sort_type_sort:
1072 add_val_str(encode, name, value, &i, "sortKeys",
1073 srw_pdu->u.request->sort.sortKeys);
1076 add_val_int(encode, name, value, &i, "startRecord",
1077 srw_pdu->u.request->startRecord);
1078 add_val_int(encode, name, value, &i, "maximumRecords",
1079 srw_pdu->u.request->maximumRecords);
1080 add_val_str(encode, name, value, &i, "recordSchema",
1081 srw_pdu->u.request->recordSchema);
1082 add_val_str(encode, name, value, &i, "recordPacking",
1083 srw_pdu->u.request->recordPacking);
1084 add_val_str(encode, name, value, &i, "recordXPath",
1085 srw_pdu->u.request->recordXPath);
1086 add_val_str(encode, name, value, &i, "stylesheet",
1087 srw_pdu->u.request->stylesheet);
1088 add_val_int(encode, name, value, &i, "resultSetTTL",
1089 srw_pdu->u.request->resultSetTTL);
1091 case Z_SRW_explain_request:
1092 value[i++] = "explain";
1093 add_val_str(encode, name, value, &i, "stylesheet",
1094 srw_pdu->u.explain_request->stylesheet);
1096 case Z_SRW_scan_request:
1097 value[i++] = "scan";
1099 switch(srw_pdu->u.scan_request->query_type)
1101 case Z_SRW_query_type_cql:
1102 add_val_str(encode, name, value, &i, "scanClause",
1103 srw_pdu->u.scan_request->scanClause.cql);
1105 case Z_SRW_query_type_pqf:
1106 add_val_str(encode, name, value, &i, "x-pScanClause",
1107 srw_pdu->u.scan_request->scanClause.pqf);
1109 case Z_SRW_query_type_xcql:
1110 add_val_str(encode, name, value, &i, "x-cqlScanClause",
1111 srw_pdu->u.scan_request->scanClause.xcql);
1114 add_val_int(encode, name, value, &i, "responsePosition",
1115 srw_pdu->u.scan_request->responsePosition);
1116 add_val_int(encode, name, value, &i, "maximumTerms",
1117 srw_pdu->u.scan_request->maximumTerms);
1118 add_val_str(encode, name, value, &i, "stylesheet",
1119 srw_pdu->u.scan_request->stylesheet);
1121 case Z_SRW_update_request:
1122 value[i++] = "update";
1131 int yaz_sru_get_encode(Z_HTTP_Request *hreq, Z_SRW_PDU *srw_pdu,
1132 ODR encode, char *charset)
1134 char *name[30], *value[30]; /* definite upper limit for SRU params */
1138 if (yaz_get_sru_parms(srw_pdu, encode, name, value))
1140 yaz_array_to_uri(&uri_args, encode, name, value);
1142 hreq->method = "GET";
1144 path = odr_malloc(encode, strlen(hreq->path) + strlen(uri_args) + 3);
1145 sprintf(path, "%s?%s", hreq->path, uri_args);
1148 z_HTTP_header_add_content_type(encode, &hreq->headers,
1149 "text/xml", charset);
1153 int yaz_sru_post_encode(Z_HTTP_Request *hreq, Z_SRW_PDU *srw_pdu,
1154 ODR encode, char *charset)
1156 char *name[30], *value[30]; /* definite upper limit for SRU params */
1159 if (yaz_get_sru_parms(srw_pdu, encode, name, value))
1162 yaz_array_to_uri(&uri_args, encode, name, value);
1164 hreq->method = "POST";
1166 hreq->content_buf = uri_args;
1167 hreq->content_len = strlen(uri_args);
1169 z_HTTP_header_add_content_type(encode, &hreq->headers,
1170 "application/x-www-form-urlencoded",
1178 * indent-tabs-mode: nil
1180 * vim: shiftwidth=4 tabstop=8 expandtab