+ if (!strcmp(h->name, "Set-Cookie"))
+ {
+ char *cp;
+
+ if (!(cp = strchr(h->value, ';')))
+ cp = h->value + strlen(h->value);
+ if (cp - h->value >= 1)
+ {
+ combined_cookies = xrealloc(combined_cookies, combined_cookies_len + cp - h->value + 3);
+ memcpy(combined_cookies+combined_cookies_len, h->value, cp - h->value);
+ combined_cookies[combined_cookies_len + cp - h->value] = '\0';
+ strcat(combined_cookies,"; ");
+ combined_cookies_len = strlen(combined_cookies);
+ }
+ }
+ }
+ if (combined_cookies_len)
+ {
+ z_HTTP_header_add(out, &gdu->u.HTTP_Request->headers, "Cookie", combined_cookies);
+ xfree(combined_cookies);
+ }
+
+ if (auth)
+ {
+ if (auth->which == Z_IdAuthentication_open)
+ {
+ char **darray;
+ int num;
+ nmem_strsplit(out->mem, "/", auth->u.open, &darray, &num);
+ if (num >= 1)
+ username = darray[0];
+ if (num >= 2)
+ password = darray[1];
+ }
+ else if (auth->which == Z_IdAuthentication_idPass)
+ {
+ username = auth->u.idPass->userId;
+ password = auth->u.idPass->password;
+ }
+ }
+
+ if (username && password)
+ {
+ z_HTTP_header_add_basic_auth(out, &gdu->u.HTTP_Request->headers,
+ username, password);
+ }
+
+ return send_gdu(gdu);
+}
+#endif
+
+#if YAZ_HAVE_XML2
+static char *encode_SRW_term(ODR o, const char *q)
+{
+ const char *in_charset = "ISO-8859-1";
+ WRBUF w = wrbuf_alloc();
+ yaz_iconv_t cd;
+ char *res;
+ if (outputCharset)
+ in_charset = outputCharset;
+ cd = yaz_iconv_open("UTF-8", in_charset);
+ if (!cd)
+ {
+ wrbuf_destroy(w);
+ return odr_strdup(o, q);
+ }
+ wrbuf_iconv_write(w, cd, q, strlen(q));
+ if (wrbuf_len(w))
+ res = odr_strdup(o, wrbuf_cstr(w));
+ else
+ res = odr_strdup(o, q);
+ yaz_iconv_close(cd);
+ wrbuf_destroy(w);
+ return res;
+}
+
+
+static int send_SRW_scanRequest(const char *arg, Odr_int *pos, int num)
+{
+ Z_SRW_PDU *sr = 0;
+
+ /* regular requestse .. */
+ sr = yaz_srw_get_pdu(out, Z_SRW_scan_request, sru_version);
+
+ switch (queryType)
+ {
+ case QueryType_CQL:
+ sr->u.scan_request->query_type = Z_SRW_query_type_cql;
+ sr->u.scan_request->scanClause.cql = encode_SRW_term(out, arg);
+ break;
+ case QueryType_Prefix:
+ sr->u.scan_request->query_type = Z_SRW_query_type_pqf;
+ sr->u.scan_request->scanClause.pqf = encode_SRW_term(out, arg);
+ break;
+ default:
+ printf("Only CQL and PQF supported in SRW\n");
+ return 0;