-/*
- * Copyright (C) 1995-2007, Index Data ApS
+/* This file is part of the YAZ toolkit.
+ * Copyright (C) 1995-2009 Index Data
* See the file LICENSE for details.
- *
- * $Id: srwutil.c,v 1.65 2008-01-28 09:51:02 adam Exp $
*/
/**
* \file srwutil.c
#include <stdlib.h>
#include <yaz/srw.h>
+#include <yaz/matchstr.h>
#include <yaz/yaz-iconv.h>
static int hex_digit (int ch)
return 0;
}
+#if YAZ_HAVE_XML2
static int yaz_base64decode(const char *in, char *out)
{
const char *map = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
*out = '\0';
return olen;
}
+#endif
int yaz_srw_check_content_type(Z_HTTP_Response *hres)
{
* Look for authentication tokens in HTTP Basic parameters or in x-username/x-password
* parameters. Added by SH.
*/
+#if YAZ_HAVE_XML2
static void yaz_srw_decodeauth(Z_SRW_PDU *sr, Z_HTTP_Request *hreq,
char *username, char *password, ODR decode)
{
sr->password = odr_strdup(decode, pbuf);
}
}
+#endif
-void yaz_uri_val_int(const char *path, const char *name, ODR o, int **intp)
+void yaz_uri_val_int(const char *path, const char *name, ODR o, Odr_int **intp)
{
const char *v = yaz_uri_val(path, name, o);
if (v)
}
+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)
return 2;
}
+#if YAZ_HAVE_XML2
static int yaz_sru_decode_integer(ODR odr, const char *pname,
- const char *valstr, int **valp,
+ const char *valstr, Odr_int **valp,
Z_SRW_diagnostic **diag, int *num_diag,
int min_value)
{
*valp = odr_intdup(odr, ival);
return 1;
}
+#endif
/**
http://www.loc.gov/z3950/agency/zing/srw/service.html
Z_SRW_extra_arg **l = &extra_args;
while (*l)
l = &(*l)->next;
- *l = odr_malloc(decode, sizeof(**l));
+ *l = (Z_SRW_extra_arg *) odr_malloc(decode, sizeof(**l));
(*l)->name = odr_strdup(decode, n);
(*l)->value = odr_strdup(decode, v);
(*l)->next = 0;
}
static void add_val_int(ODR o, char **name, char **value, int *i,
- char *a_name, int *val)
+ char *a_name, Odr_int *val)
{
if (val)
{
name[*i] = a_name;
- value[*i] = (char *) odr_malloc(o, 30);
- sprintf(value[*i], "%d", *val);
+ value[*i] = (char *) odr_malloc(o, 40);
+ sprintf(value[*i], ODR_INT_PRINTF, *val);
(*i)++;
}
}
while (*name)
{
- *ea = odr_malloc(odr, sizeof(**ea));
+ *ea = (Z_SRW_extra_arg *) odr_malloc(odr, sizeof(**ea));
(*ea)->name = *name;
(*ea)->value = *val;
ea = &(*ea)->next;
/*
* Local variables:
* c-basic-offset: 4
+ * c-file-style: "Stroustrup"
* indent-tabs-mode: nil
* End:
* vim: shiftwidth=4 tabstop=8 expandtab