X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=src%2Fsrwutil.c;h=d011233075bbb51029988ad2730716f3648a6c1e;hp=baac6a7d6135868b0ebe10a97514a54327814a35;hb=54dc5b4629da5b10c2f3d4e3bdb7cb70c46669a5;hpb=b9db9bc681a9c78da31d0cb89c50f103197cfb65 diff --git a/src/srwutil.c b/src/srwutil.c index baac6a7..d011233 100644 --- a/src/srwutil.c +++ b/src/srwutil.c @@ -8,10 +8,37 @@ */ #include +#include #include #include #include +/** \brief decodes HTTP path (which should hold SRU database) + \param o memory for returned result + \param uri URI path (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 +285,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 +408,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 +1323,6 @@ void yaz_encode_sru_extra(Z_SRW_PDU *sr, ODR odr, const char *extra_args) } - /* * Local variables: * c-basic-offset: 4