X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Fsrwutil.c;h=b115ffc2369f99bc134651d97afad163c962ad1c;hb=4c0c2dd79acdadfda1e7fcb85309604d4f59bd02;hp=bb2da66a9485d7050442d95d68febef69d9e95a6;hpb=2ede0bb278b22c8ce1cdd48e9a11a5924d433763;p=yaz-moved-to-github.git diff --git a/src/srwutil.c b/src/srwutil.c index bb2da66..b115ffc 100644 --- a/src/srwutil.c +++ b/src/srwutil.c @@ -1,8 +1,8 @@ /* - * Copyright (C) 1995-2006, Index Data ApS + * Copyright (C) 1995-2007, Index Data ApS * See the file LICENSE for details. * - * $Id: srwutil.c,v 1.54 2006-12-06 21:35:58 adam Exp $ + * $Id: srwutil.c,v 1.59 2007-05-24 10:18:36 adam Exp $ */ /** * \file srwutil.c @@ -28,8 +28,9 @@ void encode_uri_char(char *dst, char ch) { if (ch == ' ') strcpy(dst, "+"); + /* mark = "-" | "_" | "." | "!" | "~" | "*" | "'" | "(" | ")" */ else if ((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z') || - (ch >= '0' && ch <= '9')) + (ch >= '0' && ch <= '9') || strchr("-_.!~*'(|)", ch)) { dst[0] = ch; dst[1] = '\0'; @@ -47,7 +48,7 @@ static void yaz_array_to_uri_ex(char **path, ODR o, char **name, char **value, size_t i, szp = 0, sz = extra_args ? 1+strlen(extra_args) : 1; for(i = 0; name[i]; i++) sz += strlen(name[i]) + 3 + strlen(value[i]) * 3; - *path = odr_malloc(o, sz); + *path = (char *) odr_malloc(o, sz); for(i = 0; name[i]; i++) { @@ -98,8 +99,8 @@ int yaz_uri_array(const char *path, ODR o, char ***name, char ***val) cp++; no++; } - *name = odr_malloc(o, no * sizeof(char*)); - *val = odr_malloc(o, no * sizeof(char*)); + *name = (char **) odr_malloc(o, no * sizeof(char*)); + *val = (char **) odr_malloc(o, no * sizeof(char*)); for (no = 0; *path; no++) { @@ -109,7 +110,7 @@ int yaz_uri_array(const char *path, ODR o, char ***name, char ***val) if (!p1) break; - (*name)[no] = odr_malloc(o, (p1-path)+1); + (*name)[no] = (char *) odr_malloc(o, (p1-path)+1); memcpy((*name)[no], path, p1-path); (*name)[no][p1-path] = '\0'; @@ -117,7 +118,7 @@ int yaz_uri_array(const char *path, ODR o, char ***name, char ***val) p1 = strchr(path, '&'); if (!p1) p1 = strlen(path) + path; - (*val)[no] = ret = odr_malloc(o, p1 - path + 1); + (*val)[no] = ret = (char *) odr_malloc(o, p1 - path + 1); while (*path && *path != '&') { if (*path == '+') @@ -235,6 +236,20 @@ static int yaz_base64decode(const char *in, char *out) return olen; } +int yaz_srw_check_content_type(Z_HTTP_Response *hres) +{ + const char *content_type = z_HTTP_header_lookup(hres->headers, + "Content-Type"); + if (content_type) + { + if (!yaz_strcmp_del("text/xml", content_type, "; ")) + return 1; + if (!yaz_strcmp_del("application/xml", content_type, "; ")) + return 1; + } + return 0; +} + /** * Look for authentication tokens in HTTP Basic parameters or in x-username/x-password * parameters. Added by SH. @@ -632,10 +647,11 @@ int yaz_sru_decode(Z_HTTP_Request *hreq, Z_SRW_PDU **srw_pdu, sr->u.request->database = db; - (*soap_package) = odr_malloc(decode, sizeof(**soap_package)); + (*soap_package) = (Z_SOAP *) + odr_malloc(decode, sizeof(**soap_package)); (*soap_package)->which = Z_SOAP_generic; - (*soap_package)->u.generic = + (*soap_package)->u.generic = (Z_SOAP_Generic *) odr_malloc(decode, sizeof(*(*soap_package)->u.generic)); (*soap_package)->u.generic->p = sr; @@ -660,10 +676,11 @@ int yaz_sru_decode(Z_HTTP_Request *hreq, Z_SRW_PDU **srw_pdu, sr->u.explain_request->stylesheet = stylesheet; - (*soap_package) = odr_malloc(decode, sizeof(**soap_package)); + (*soap_package) = (Z_SOAP *) + odr_malloc(decode, sizeof(**soap_package)); (*soap_package)->which = Z_SOAP_generic; - (*soap_package)->u.generic = + (*soap_package)->u.generic = (Z_SOAP_Generic *) odr_malloc(decode, sizeof(*(*soap_package)->u.generic)); (*soap_package)->u.generic->p = sr; @@ -712,10 +729,11 @@ int yaz_sru_decode(Z_HTTP_Request *hreq, Z_SRW_PDU **srw_pdu, sr->u.scan_request->stylesheet = stylesheet; - (*soap_package) = odr_malloc(decode, sizeof(**soap_package)); + (*soap_package) = (Z_SOAP *) + odr_malloc(decode, sizeof(**soap_package)); (*soap_package)->which = Z_SOAP_generic; - (*soap_package)->u.generic = + (*soap_package)->u.generic = (Z_SOAP_Generic *) odr_malloc(decode, sizeof(*(*soap_package)->u.generic)); (*soap_package)->u.generic->p = sr; @@ -740,10 +758,11 @@ int yaz_sru_decode(Z_HTTP_Request *hreq, Z_SRW_PDU **srw_pdu, sr->u.explain_request->stylesheet = stylesheet; - (*soap_package) = odr_malloc(decode, sizeof(**soap_package)); + (*soap_package) = (Z_SOAP *) + odr_malloc(decode, sizeof(**soap_package)); (*soap_package)->which = Z_SOAP_generic; - (*soap_package)->u.generic = + (*soap_package)->u.generic = (Z_SOAP_Generic *) odr_malloc(decode, sizeof(*(*soap_package)->u.generic)); (*soap_package)->u.generic->p = sr; @@ -1109,7 +1128,7 @@ static void add_val_int(ODR o, char **name, char **value, int *i, if (val) { name[*i] = a_name; - value[*i] = odr_malloc(o, 30); + value[*i] = (char *) odr_malloc(o, 30); sprintf(value[*i], "%d", *val); (*i)++; } @@ -1228,9 +1247,10 @@ int yaz_sru_get_encode(Z_HTTP_Request *hreq, Z_SRW_PDU *srw_pdu, hreq->method = "GET"; - path = odr_malloc(encode, strlen(hreq->path) + strlen(uri_args) + 4 - +(srw_pdu->extra_args ? strlen(srw_pdu->extra_args) : 0) - ); + path = (char *) + odr_malloc(encode, strlen(hreq->path) + strlen(uri_args) + 4 + +(srw_pdu->extra_args ? strlen(srw_pdu->extra_args) : 0)); + sprintf(path, "%s?%s", hreq->path, uri_args); hreq->path = path; @@ -1325,11 +1345,11 @@ const char *yaz_srw_pack_to_str(int pack) int yaz_srw_str_to_pack(const char *str) { - if (!strcmp(str, "string")) + if (!yaz_matchstr(str, "string")) return Z_SRW_recordPacking_string; - if (!strcmp(str, "xml")) + if (!yaz_matchstr(str, "xml")) return Z_SRW_recordPacking_XML; - if (!strcmp(str, "url")) + if (!yaz_matchstr(str, "url")) return Z_SRW_recordPacking_URL; return -1; }