-/*
- * Copyright (C) 1995-2007, Index Data ApS
+/* This file is part of the YAZ toolkit.
+ * Copyright (C) 1995-2008 Index Data
* See the file LICENSE for details.
- *
- * $Id: srwutil.c,v 1.64 2007-09-07 17:41:47 mike Exp $
*/
/**
* \file srwutil.c
}
}
-static void yaz_array_to_uri_ex(char **path, ODR o, char **name, char **value,
- const char *extra_args)
+static void yaz_array_to_uri(char **path, ODR o, char **name, char **value)
{
- size_t i, szp = 0, sz = extra_args ? 1+strlen(extra_args) : 1;
+ size_t i, szp = 0, sz = 1;
for(i = 0; name[i]; i++)
sz += strlen(name[i]) + 3 + strlen(value[i]) * 3;
*path = (char *) odr_malloc(o, sz);
szp += vlen;
}
}
- if (extra_args)
- {
- if (i)
- (*path)[szp++] = '&';
- memcpy(*path + szp, extra_args, strlen(extra_args));
- szp += strlen(extra_args);
- }
(*path)[szp] = '\0';
}
-void yaz_array_to_uri(char **path, ODR o, char **name, char **value)
-{
- yaz_array_to_uri_ex(path, o, name, value, 0);
-}
-
-int yaz_uri_array(const char *path, ODR o, char ***name, char ***val)
+int yaz_uri_to_array(const char *path, ODR o, char ***name, char ***val)
{
int no = 2;
const char *cp;
}
+void yaz_mk_sru_surrogate(ODR o, Z_SRW_record *record, int pos,
+ int code, const char *details)
+{
+ const char *message = yaz_diag_srw_str(code);
+ int len = 200;
+ if (message)
+ len += strlen(message);
+ if (details)
+ len += strlen(details);
+
+ record->recordData_buf = (char *) odr_malloc(o, len);
+
+ sprintf(record->recordData_buf, "<diagnostic "
+ "xmlns=\"http://www.loc.gov/zing/srw/diagnostic/\">\n"
+ " <uri>info:srw/diagnostic/1/%d</uri>\n", code);
+ if (details)
+ sprintf(record->recordData_buf + strlen(record->recordData_buf),
+ " <details>%s</details>\n", details);
+ if (message)
+ sprintf(record->recordData_buf + strlen(record->recordData_buf),
+ " <message>%s</message>\n", message);
+ sprintf(record->recordData_buf + strlen(record->recordData_buf),
+ "</diagnostic>\n");
+ record->recordData_len = strlen(record->recordData_buf);
+ record->recordPosition = odr_intdup(o, pos);
+ record->recordSchema = "info:srw/schema/1/diagnostics-v1.1";
+}
+
static void grab_charset(ODR o, const char *content_type, char **charset)
{
if (charset)
char *maximumTerms = 0;
char *responsePosition = 0;
char *extraRequestData = 0;
+ Z_SRW_extra_arg *extra_args = 0;
#endif
char **uri_name;
char **uri_val;
}
if (!strcmp(hreq->method, "POST"))
p1 = hreq->content_buf;
- yaz_uri_array(p1, decode, &uri_name, &uri_val);
+ yaz_uri_to_array(p1, decode, &uri_name, &uri_val);
#if YAZ_HAVE_XML2
if (uri_name)
{
responsePosition = v;
else if (!strcmp(n, "extraRequestData"))
extraRequestData = v;
+ else if (n[0] == 'x' && n[1] == '-')
+ {
+ Z_SRW_extra_arg **l = &extra_args;
+ while (*l)
+ l = &(*l)->next;
+ *l = odr_malloc(decode, sizeof(**l));
+ (*l)->name = odr_strdup(decode, n);
+ (*l)->value = odr_strdup(decode, v);
+ (*l)->next = 0;
+ }
else
yaz_add_srw_diagnostic(decode, diag, num_diag,
YAZ_SRW_UNSUPP_PARAMETER, n);
Z_SRW_PDU *sr = yaz_srw_get(decode, Z_SRW_searchRetrieve_request);
sr->srw_version = version;
+ sr->extra_args = extra_args;
*srw_pdu = sr;
yaz_srw_decodeauth(sr, hreq, username, password, decode);
if (query)
Z_SRW_PDU *sr = yaz_srw_get(decode, Z_SRW_explain_request);
sr->srw_version = version;
+ sr->extra_args = extra_args;
yaz_srw_decodeauth(sr, hreq, username, password, decode);
*srw_pdu = sr;
sr->u.explain_request->recordPacking = recordPacking;
Z_SRW_PDU *sr = yaz_srw_get(decode, Z_SRW_scan_request);
sr->srw_version = version;
+ sr->extra_args = extra_args;
*srw_pdu = sr;
yaz_srw_decodeauth(sr, hreq, username, password, decode);
}
static int yaz_get_sru_parms(const Z_SRW_PDU *srw_pdu, ODR encode,
- char **name, char **value)
+ char **name, char **value, int max_names)
{
int i = 0;
add_val_str(encode, name, value, &i, "version", srw_pdu->srw_version);
default:
return -1;
}
+ if (srw_pdu->extra_args)
+ {
+ Z_SRW_extra_arg *ea = srw_pdu->extra_args;
+ for (; ea && i < max_names-1; ea = ea->next)
+ {
+ name[i] = ea->name;
+ value[i] = ea->value;
+ i++;
+ }
+ }
name[i++] = 0;
+
return 0;
}
z_HTTP_header_add_basic_auth(encode, &hreq->headers,
srw_pdu->username, srw_pdu->password);
- if (yaz_get_sru_parms(srw_pdu, encode, name, value))
+ if (yaz_get_sru_parms(srw_pdu, encode, name, value, 30))
return -1;
- yaz_array_to_uri_ex(&uri_args, encode, name, value, srw_pdu->extra_args);
+ yaz_array_to_uri(&uri_args, encode, name, value);
hreq->method = "GET";
path = (char *)
- odr_malloc(encode, strlen(hreq->path) + strlen(uri_args) + 4
- +(srw_pdu->extra_args ? strlen(srw_pdu->extra_args) : 0));
+ odr_malloc(encode, strlen(hreq->path) + strlen(uri_args) + 4);
sprintf(path, "%s?%s", hreq->path, uri_args);
hreq->path = path;
z_HTTP_header_add_basic_auth(encode, &hreq->headers,
srw_pdu->username, srw_pdu->password);
- if (yaz_get_sru_parms(srw_pdu, encode, name, value))
+ if (yaz_get_sru_parms(srw_pdu, encode, name, value, 30))
return -1;
- yaz_array_to_uri_ex(&uri_args, encode, name, value, srw_pdu->extra_args);
+ yaz_array_to_uri(&uri_args, encode, name, value);
hreq->method = "POST";
return -1;
}
+void yaz_encode_sru_extra(Z_SRW_PDU *sr, ODR odr, const char *extra_args)
+{
+ if (extra_args)
+ {
+ char **name;
+ char **val;
+ Z_SRW_extra_arg **ea = &sr->extra_args;
+ yaz_uri_to_array(extra_args, odr, &name, &val);
+
+ while (*name)
+ {
+ *ea = odr_malloc(odr, sizeof(**ea));
+ (*ea)->name = *name;
+ (*ea)->value = *val;
+ ea = &(*ea)->next;
+ val++;
+ name++;
+ }
+ *ea = 0;
+ }
+}
+
+
+
/*
* Local variables:
* c-basic-offset: 4