aboutsummaryrefslogtreecommitdiff
path: root/block/curl.c
diff options
context:
space:
mode:
Diffstat (limited to 'block/curl.c')
-rw-r--r--block/curl.c56
1 files changed, 24 insertions, 32 deletions
diff --git a/block/curl.c b/block/curl.c
index 419f7c8..5467678 100644
--- a/block/curl.c
+++ b/block/curl.c
@@ -29,8 +29,8 @@
#include "qemu/option.h"
#include "block/block-io.h"
#include "block/block_int.h"
-#include "qapi/qmp/qdict.h"
-#include "qapi/qmp/qstring.h"
+#include "qobject/qdict.h"
+#include "qobject/qstring.h"
#include "crypto/secret.h"
#include <curl/curl.h>
#include "qemu/cutils.h"
@@ -210,37 +210,29 @@ static size_t curl_header_cb(void *ptr, size_t size, size_t nmemb, void *opaque)
{
BDRVCURLState *s = opaque;
size_t realsize = size * nmemb;
- const char *header = (char *)ptr;
- const char *end = header + realsize;
- const char *accept_ranges = "accept-ranges:";
- const char *bytes = "bytes";
+ const char *p = ptr;
+ const char *end = p + realsize;
+ const char *t = "accept-ranges : bytes "; /* A lowercase template */
- if (realsize >= strlen(accept_ranges)
- && g_ascii_strncasecmp(header, accept_ranges,
- strlen(accept_ranges)) == 0) {
-
- char *p = strchr(header, ':') + 1;
-
- /* Skip whitespace between the header name and value. */
- while (p < end && *p && g_ascii_isspace(*p)) {
- p++;
- }
-
- if (end - p >= strlen(bytes)
- && strncmp(p, bytes, strlen(bytes)) == 0) {
-
- /* Check that there is nothing but whitespace after the value. */
- p += strlen(bytes);
- while (p < end && *p && g_ascii_isspace(*p)) {
- p++;
- }
-
- if (p == end || !*p) {
- s->accept_range = true;
+ /* check if header matches the "t" template */
+ for (;;) {
+ if (*t == ' ') { /* space in t matches any amount of isspace in p */
+ if (p < end && g_ascii_isspace(*p)) {
+ ++p;
+ } else {
+ ++t;
}
+ } else if (*t && p < end && *t == g_ascii_tolower(*p)) {
+ ++p, ++t;
+ } else {
+ break;
}
}
+ if (!*t && p == end) { /* if we managed to reach ends of both strings */
+ s->accept_range = true;
+ }
+
return realsize;
}
@@ -1034,7 +1026,7 @@ static BlockDriver bdrv_http = {
.instance_size = sizeof(BDRVCURLState),
.bdrv_parse_filename = curl_parse_filename,
- .bdrv_file_open = curl_open,
+ .bdrv_open = curl_open,
.bdrv_close = curl_close,
.bdrv_co_getlength = curl_co_getlength,
@@ -1053,7 +1045,7 @@ static BlockDriver bdrv_https = {
.instance_size = sizeof(BDRVCURLState),
.bdrv_parse_filename = curl_parse_filename,
- .bdrv_file_open = curl_open,
+ .bdrv_open = curl_open,
.bdrv_close = curl_close,
.bdrv_co_getlength = curl_co_getlength,
@@ -1072,7 +1064,7 @@ static BlockDriver bdrv_ftp = {
.instance_size = sizeof(BDRVCURLState),
.bdrv_parse_filename = curl_parse_filename,
- .bdrv_file_open = curl_open,
+ .bdrv_open = curl_open,
.bdrv_close = curl_close,
.bdrv_co_getlength = curl_co_getlength,
@@ -1091,7 +1083,7 @@ static BlockDriver bdrv_ftps = {
.instance_size = sizeof(BDRVCURLState),
.bdrv_parse_filename = curl_parse_filename,
- .bdrv_file_open = curl_open,
+ .bdrv_open = curl_open,
.bdrv_close = curl_close,
.bdrv_co_getlength = curl_co_getlength,