X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fuclient.git;a=blobdiff_plain;f=uclient-utils.c;h=a375eeacb33eceb0925d947da156f3e722d5f94d;hp=66a4f15fcf2a423d99b798c13ef3a6196a8a9763;hb=6853a3eeae3eede58e7989e3b4a94a58699a0d73;hpb=7401d5c1100a35dd5eafa602fad6d334dea98225 diff --git a/uclient-utils.c b/uclient-utils.c index 66a4f15..a375eea 100644 --- a/uclient-utils.c +++ b/uclient-utils.c @@ -1,3 +1,20 @@ +/* + * uclient - ustream based protocol client library + * + * Copyright (C) 2014 Felix Fietkau + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ #include #include #include @@ -143,3 +160,25 @@ void http_digest_calculate_response(char *dest, const struct http_digest_data *d http_create_hash(dest, h_a2_strings, ARRAY_SIZE(h_a2_strings)); http_create_hash(dest, resp_strings, ARRAY_SIZE(resp_strings)); } + +char *uclient_get_url_filename(const char *url, const char *default_name) +{ + const char *str; + int len = strcspn(url, ";&"); + + while (len > 0 && url[len - 1] == '/') + len--; + + for (str = url + len - 1; str >= url; str--) { + if (*str == '/') + break; + } + + str++; + len -= str - url; + + if (len > 0) + return strncpy(calloc(1, len + 1), str, len); + + return strdup(default_name); +}