X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=src%2Fsrwutil.c;h=6284831064d7bb16b0561513f7d9561eaed6c546;hp=7d1da02da88e010d74ac073625ebab3bcd7a6834;hb=8a980f7051e22ca1e4fac0395ed7f8647cd9eda3;hpb=ee6ab2ee3a9ee1a8c65d7272ec7fba1d886f5af0 diff --git a/src/srwutil.c b/src/srwutil.c index 7d1da02..6284831 100644 --- a/src/srwutil.c +++ b/src/srwutil.c @@ -1,5 +1,5 @@ /* This file is part of the YAZ toolkit. - * Copyright (C) 1995-2008 Index Data + * Copyright (C) 1995-2009 Index Data * See the file LICENSE for details. */ /** @@ -9,6 +9,7 @@ #include #include +#include #include static int hex_digit (int ch) @@ -175,6 +176,7 @@ char *yaz_uri_val(const char *path, const char *name, ODR o) return 0; } +#if YAZ_HAVE_XML2 static int yaz_base64decode(const char *in, char *out) { const char *map = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" @@ -220,6 +222,7 @@ static int yaz_base64decode(const char *in, char *out) *out = '\0'; return olen; } +#endif int yaz_srw_check_content_type(Z_HTTP_Response *hres) { @@ -239,6 +242,7 @@ 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) { @@ -273,8 +277,9 @@ static void yaz_srw_decodeauth(Z_SRW_PDU *sr, Z_HTTP_Request *hreq, 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) @@ -339,6 +344,34 @@ void yaz_add_sru_update_diagnostic(ODR o, Z_SRW_diagnostic **d, } +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, "\n" + " info:srw/diagnostic/1/%d\n", code); + if (details) + sprintf(record->recordData_buf + strlen(record->recordData_buf), + "
%s
\n", details); + if (message) + sprintf(record->recordData_buf + strlen(record->recordData_buf), + " %s\n", message); + sprintf(record->recordData_buf + strlen(record->recordData_buf), + "
\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) @@ -428,8 +461,9 @@ int yaz_srw_decode(Z_HTTP_Request *hreq, Z_SRW_PDU **srw_pdu, 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) { @@ -451,6 +485,7 @@ static int yaz_sru_decode_integer(ODR odr, const char *pname, *valp = odr_intdup(odr, ival); return 1; } +#endif /** http://www.loc.gov/z3950/agency/zing/srw/service.html @@ -572,7 +607,7 @@ int yaz_sru_decode(Z_HTTP_Request *hreq, Z_SRW_PDU **srw_pdu, 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; @@ -1162,13 +1197,13 @@ int yaz_diag_srw_to_bib1(int code) } 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)++; } } @@ -1420,7 +1455,7 @@ void yaz_encode_sru_extra(Z_SRW_PDU *sr, ODR odr, const char *extra_args) 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; @@ -1436,6 +1471,7 @@ void yaz_encode_sru_extra(Z_SRW_PDU *sr, ODR odr, const char *extra_args) /* * Local variables: * c-basic-offset: 4 + * c-file-style: "Stroustrup" * indent-tabs-mode: nil * End: * vim: shiftwidth=4 tabstop=8 expandtab