diff options
author | Max Kellermann <max@duempel.org> | 2008-10-26 21:12:56 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2008-10-26 21:12:56 +0100 |
commit | 1437a56a11d15d703599d005bf37e8351403dc68 (patch) | |
tree | dcf33580a51937822314e6c0fe5eae7de849745e /src | |
parent | d401589edfcbabbfb5cc4256217eab4d04f34d9a (diff) | |
download | mpd-1437a56a11d15d703599d005bf37e8351403dc68.tar.gz mpd-1437a56a11d15d703599d005bf37e8351403dc68.tar.xz mpd-1437a56a11d15d703599d005bf37e8351403dc68.zip |
input_curl: added local variable "value"
Replaced the local variable "colon" (which had only temporary meaning)
with the variable "value". It is a pointer to the first byte of the
header value.
Diffstat (limited to 'src')
-rw-r--r-- | src/input_curl.c | 36 |
1 files changed, 22 insertions, 14 deletions
diff --git a/src/input_curl.c b/src/input_curl.c index 42c66c236..afc8f9377 100644 --- a/src/input_curl.c +++ b/src/input_curl.c @@ -279,35 +279,43 @@ static size_t input_curl_headerfunction(void *ptr, size_t size, size_t nmemb, void *stream) { struct input_stream *is = stream; - const char *header = ptr, *end, *colon; + const char *header = ptr, *end, *value; char name[64]; size *= nmemb; end = header + size; - colon = memchr(header, ':', size); - if (colon == NULL || (size_t)(colon - header) >= sizeof(name)) + value = memchr(header, ':', size); + if (value == NULL || (size_t)(value - header) >= sizeof(name)) return size; - memcpy(name, header, colon - header); - name[colon - header] = 0; + memcpy(name, header, value - header); + name[value - header] = 0; + + /* skip the colon */ + + ++value; + + /* strip the value */ + + while (value < end && g_ascii_isspace(*value)) + ++value; + + while (end > value && g_ascii_isspace(end[-1])) + --end; if (strcasecmp(name, "accept-ranges") == 0) is->seekable = true; else if (strcasecmp(name, "content-length") == 0) { - char value[64]; - - header = colon + 1; - while (header < end && header[0] == ' ') - ++header; + char buffer[64]; - if ((size_t)(end - header) >= sizeof(value)) + if ((size_t)(end - header) >= sizeof(buffer)) return size; - memcpy(value, header, end - header); - value[end - header] = 0; + memcpy(buffer, value, end - value); + buffer[end - value] = 0; - is->size = is->offset + g_ascii_strtoull(value, NULL, 10); + is->size = is->offset + g_ascii_strtoull(buffer, NULL, 10); } return size; |