input/curl: pass std::string&& to HeaderReceived()

Code simplification.
This commit is contained in:
Max Kellermann 2014-03-15 22:02:59 +01:00
parent 23eacbd132
commit 64f31f70f9
1 changed files with 8 additions and 25 deletions

View File

@ -209,8 +209,7 @@ struct CurlInputStream {
*/ */
void FreeEasyIndirect(); void FreeEasyIndirect();
void HeaderReceived(const char *name, void HeaderReceived(const char *name, std::string &&value);
const char *value, const char *end);
size_t DataReceived(const void *ptr, size_t size); size_t DataReceived(const void *ptr, size_t size);
@ -899,29 +898,20 @@ input_curl_eof(gcc_unused InputStream *is)
} }
inline void inline void
CurlInputStream::HeaderReceived(const char *name, CurlInputStream::HeaderReceived(const char *name, std::string &&value)
const char *value, const char *end)
{ {
if (StringEqualsCaseASCII(name, "accept-ranges")) { if (StringEqualsCaseASCII(name, "accept-ranges")) {
/* a stream with icy-metadata is not seekable */ /* a stream with icy-metadata is not seekable */
if (!icy.IsDefined()) if (!icy.IsDefined())
base.seekable = true; base.seekable = true;
} else if (StringEqualsCaseASCII(name, "content-length")) { } else if (StringEqualsCaseASCII(name, "content-length")) {
char buffer[64]; base.size = base.offset + ParseUint64(value.c_str());
if ((size_t)(end - value) >= sizeof(buffer))
return;
memcpy(buffer, value, end - value);
buffer[end - value] = 0;
base.size = base.offset + ParseUint64(buffer);
} else if (StringEqualsCaseASCII(name, "content-type")) { } else if (StringEqualsCaseASCII(name, "content-type")) {
base.mime.assign(value, end); base.mime = std::move(value);
} else if (StringEqualsCaseASCII(name, "icy-name") || } else if (StringEqualsCaseASCII(name, "icy-name") ||
StringEqualsCaseASCII(name, "ice-name") || StringEqualsCaseASCII(name, "ice-name") ||
StringEqualsCaseASCII(name, "x-audiocast-name")) { StringEqualsCaseASCII(name, "x-audiocast-name")) {
meta_name.assign(value, end); meta_name = std::move(value);
delete tag; delete tag;
@ -930,17 +920,10 @@ CurlInputStream::HeaderReceived(const char *name,
tag = tag_builder.CommitNew(); tag = tag_builder.CommitNew();
} else if (StringEqualsCaseASCII(name, "icy-metaint")) { } else if (StringEqualsCaseASCII(name, "icy-metaint")) {
char buffer[64]; if (icy.IsDefined())
size_t icy_metaint;
if ((size_t)(end - value) >= sizeof(buffer) ||
icy.IsDefined())
return; return;
memcpy(buffer, value, end - value); size_t icy_metaint = ParseUint64(value.c_str());
buffer[end - value] = 0;
icy_metaint = ParseUint64(buffer);
FormatDebug(curl_domain, "icy-metaint=%zu", icy_metaint); FormatDebug(curl_domain, "icy-metaint=%zu", icy_metaint);
if (icy_metaint > 0) { if (icy_metaint > 0) {
@ -985,7 +968,7 @@ input_curl_headerfunction(void *ptr, size_t size, size_t nmemb, void *stream)
while (end > value && IsWhitespaceOrNull(end[-1])) while (end > value && IsWhitespaceOrNull(end[-1]))
--end; --end;
c.HeaderReceived(name, value, end); c.HeaderReceived(name, std::string(value, end));
return size; return size;
} }