X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Fsrwutil.c;h=e1421042635cb9e5733b540cbc32d1a6e004956a;hb=9773a01f6dae65e5f9c424b3f2bc7454b8270cfc;hp=baac6a7d6135868b0ebe10a97514a54327814a35;hpb=42bf8d7d53e41f6165e0eb889a7377d3482aeabd;p=yaz-moved-to-github.git diff --git a/src/srwutil.c b/src/srwutil.c index baac6a7..e142104 100644 --- a/src/srwutil.c +++ b/src/srwutil.c @@ -1,5 +1,5 @@ /* This file is part of the YAZ toolkit. - * Copyright (C) 1995-2009 Index Data + * Copyright (C) 1995-2010 Index Data * See the file LICENSE for details. */ /** @@ -8,10 +8,38 @@ */ #include +#include #include #include #include +/** \brief decodes HTTP path (which should hold SRU database) + \param n memory for returned result + \param uri URI path (up to but not including ?) + \param len URI len (up to but not including ?) + \returns ODR allocated database +*/ +static char *yaz_decode_sru_dbpath_odr(ODR n, const char *uri, size_t len) +{ + char *ret = odr_malloc(n, strlen(uri) + 1); + yaz_decode_uri_component(ret, uri, len); + return ret; +} + +void yaz_encode_sru_dbpath_buf(char *dst, const char *db) +{ + assert(db); + *dst = '/'; + yaz_encode_uri_component(dst+1, db); +} + +char *yaz_encode_sru_dbpath_odr(ODR out, const char *db) +{ + char *dst = odr_malloc(out, 3 * strlen(db) + 2); + yaz_encode_sru_dbpath_buf(dst, db); + return dst; +} + #if YAZ_HAVE_XML2 static int yaz_base64decode(const char *in, char *out) { @@ -258,12 +286,7 @@ int yaz_srw_decode(Z_HTTP_Request *hreq, Z_SRW_PDU **srw_pdu, if (!p1) p1 = p0 + strlen(p0); if (p1 != p0) - { - db = (char*) odr_malloc(decode, p1 - p0 + 1); - memcpy (db, p0, p1 - p0); - db[p1 - p0] = '\0'; - } - + db = yaz_decode_sru_dbpath_odr(decode, p0, p1 - p0); grab_charset(decode, content_type, charset); ret = z_soap_codec(decode, soap_package, @@ -386,11 +409,7 @@ int yaz_sru_decode(Z_HTTP_Request *hreq, Z_SRW_PDU **srw_pdu, if (!p1) p1 = p0 + strlen(p0); if (p1 != p0) - { - db = (char*) odr_malloc(decode, p1 - p0 + 1); - memcpy (db, p0, p1 - p0); - db[p1 - p0] = '\0'; - } + db = yaz_decode_sru_dbpath_odr(decode, p0, p1 - p0); if (!strcmp(hreq->method, "POST")) p1 = hreq->content_buf; yaz_uri_to_array(p1, decode, &uri_name, &uri_val); @@ -1305,7 +1324,6 @@ void yaz_encode_sru_extra(Z_SRW_PDU *sr, ODR odr, const char *extra_args) } - /* * Local variables: * c-basic-offset: 4