Compare commits
2 Commits
00764d6a3c
...
81aac8bb57
Author | SHA1 | Date |
---|---|---|
Fufu Fang | 81aac8bb57 | |
Mattias Runge-Broberg | 35a213942c |
|
@ -164,10 +164,10 @@ static int Meta_read(Cache *cf)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sizeof(long) != fread(&cf->time, sizeof(long), 1, fp) ||
|
if (sizeof(long) != fread(&cf->time, sizeof(long), 1, fp) ||
|
||||||
sizeof(off_t) != fread(&cf->content_length, sizeof(off_t), 1, fp) ||
|
sizeof(off_t) != fread(&cf->content_length, sizeof(off_t), 1, fp) ||
|
||||||
sizeof(int) != fread(&cf->blksz, sizeof(int), 1, fp) ||
|
sizeof(int) != fread(&cf->blksz, sizeof(int), 1, fp) ||
|
||||||
sizeof(long) != fread(&cf->segbc, sizeof(long), 1, fp) ||
|
sizeof(long) != fread(&cf->segbc, sizeof(long), 1, fp) ||
|
||||||
ferror(fp)) {
|
ferror(fp)) {
|
||||||
lprintf(error, "error reading core metadata!\n");
|
lprintf(error, "error reading core metadata!\n");
|
||||||
return EIO;
|
return EIO;
|
||||||
}
|
}
|
||||||
|
|
44
src/link.c
44
src/link.c
|
@ -286,7 +286,7 @@ LinkTable *LinkSystem_init(const char *url)
|
||||||
* This is where the '/' should be
|
* This is where the '/' should be
|
||||||
*/
|
*/
|
||||||
ROOT_LINK_OFFSET = strnlen(url, MAX_PATH_LEN) -
|
ROOT_LINK_OFFSET = strnlen(url, MAX_PATH_LEN) -
|
||||||
((url[url_len] == '/') ? 1 : 0);
|
((url[url_len] == '/') ? 1 : 0);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* --------------------- Enable cache system --------------------
|
* --------------------- Enable cache system --------------------
|
||||||
|
@ -474,7 +474,7 @@ static void LinkTable_fill(LinkTable *linktbl)
|
||||||
spaces in them!). If we only escaped it, and there were already
|
spaces in them!). If we only escaped it, and there were already
|
||||||
encoded characters in it, then that would break the link. */
|
encoded characters in it, then that would break the link. */
|
||||||
char *unescaped_path = curl_easy_unescape(c, this_link->linkpath, 0,
|
char *unescaped_path = curl_easy_unescape(c, this_link->linkpath, 0,
|
||||||
NULL);
|
NULL);
|
||||||
char *escaped_path = curl_easy_escape(c, unescaped_path, 0);
|
char *escaped_path = curl_easy_escape(c, unescaped_path, 0);
|
||||||
curl_free(unescaped_path);
|
curl_free(unescaped_path);
|
||||||
/* Our code does the wrong thing if there's a trailing slash that's been
|
/* Our code does the wrong thing if there's a trailing slash that's been
|
||||||
|
@ -704,7 +704,10 @@ int LinkTable_disk_save(LinkTable *linktbl, const char *dirn)
|
||||||
/* This is necessary to get the compiler on some platforms to stop
|
/* This is necessary to get the compiler on some platforms to stop
|
||||||
complaining about the fact that we're not using the return value of
|
complaining about the fact that we're not using the return value of
|
||||||
fread, when we know we aren't and that's fine. */
|
fread, when we know we aren't and that's fine. */
|
||||||
static inline void ignore_value(int i) { (void) i; }
|
static inline void ignore_value(int i)
|
||||||
|
{
|
||||||
|
(void) i;
|
||||||
|
}
|
||||||
|
|
||||||
LinkTable *LinkTable_disk_open(const char *dirn)
|
LinkTable *LinkTable_disk_open(const char *dirn)
|
||||||
{
|
{
|
||||||
|
@ -799,6 +802,8 @@ LinkTable *path_to_Link_LinkTable_new(const char *path)
|
||||||
if (!next_table) {
|
if (!next_table) {
|
||||||
if (CONFIG.mode == NORMAL) {
|
if (CONFIG.mode == NORMAL) {
|
||||||
next_table = LinkTable_new(tmp_link->f_url);
|
next_table = LinkTable_new(tmp_link->f_url);
|
||||||
|
} else if (CONFIG.mode == SINGLE) {
|
||||||
|
next_table = single_LinkTable_new(tmp_link->f_url);
|
||||||
} else if (CONFIG.mode == SONIC) {
|
} else if (CONFIG.mode == SONIC) {
|
||||||
if (!CONFIG.sonic_id3) {
|
if (!CONFIG.sonic_id3) {
|
||||||
next_table = sonic_LinkTable_new_index(tmp_link->sonic.id);
|
next_table = sonic_LinkTable_new_index(tmp_link->sonic.id);
|
||||||
|
@ -808,7 +813,7 @@ LinkTable *path_to_Link_LinkTable_new(const char *path)
|
||||||
tmp_link->sonic.id);
|
tmp_link->sonic.id);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
lprintf(fatal, "Invalid CONFIG.mode\n");
|
lprintf(fatal, "Invalid CONFIG.mode: %d\n", CONFIG.mode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (link) {
|
if (link) {
|
||||||
|
@ -981,7 +986,7 @@ static CURL *Link_download_curl_setup(Link *link, size_t req_size, off_t offset,
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t start = offset;
|
size_t start = offset;
|
||||||
size_t end = start + req_size;
|
size_t end = start + req_size - 1;
|
||||||
|
|
||||||
char range_str[64];
|
char range_str[64];
|
||||||
snprintf(range_str, sizeof(range_str), "%lu-%lu", start, end);
|
snprintf(range_str, sizeof(range_str), "%lu-%lu", start, end);
|
||||||
|
@ -1030,8 +1035,8 @@ range requests\n");
|
||||||
lprintf(error, "%s", curl_easy_strerror(ret));
|
lprintf(error, "%s", curl_easy_strerror(ret));
|
||||||
}
|
}
|
||||||
if ((http_resp != HTTP_OK) &&
|
if ((http_resp != HTTP_OK) &&
|
||||||
(http_resp != HTTP_PARTIAL_CONTENT) &&
|
(http_resp != HTTP_PARTIAL_CONTENT) &&
|
||||||
(http_resp != HTTP_RANGE_NOT_SATISFIABLE)) {
|
(http_resp != HTTP_RANGE_NOT_SATISFIABLE)) {
|
||||||
char *url;
|
char *url;
|
||||||
curl_easy_getinfo(curl, CURLINFO_EFFECTIVE_URL, &url);
|
curl_easy_getinfo(curl, CURLINFO_EFFECTIVE_URL, &url);
|
||||||
lprintf(warning, "Could not download %s, HTTP %ld\n", url, http_resp);
|
lprintf(warning, "Could not download %s, HTTP %ld\n", url, http_resp);
|
||||||
|
@ -1061,6 +1066,13 @@ long Link_download(Link *link, char *output_buf, size_t req_size, off_t offset)
|
||||||
header.curr_size = 0;
|
header.curr_size = 0;
|
||||||
header.data = NULL;
|
header.data = NULL;
|
||||||
|
|
||||||
|
if (offset + req_size > link->content_length) {
|
||||||
|
lprintf(error,
|
||||||
|
"requested size too large, req_size: %lu, recv: %ld, content-length: %ld\n",
|
||||||
|
req_size, recv, link->content_length);
|
||||||
|
req_size = link->content_length - offset;
|
||||||
|
}
|
||||||
|
|
||||||
CURL *curl = Link_download_curl_setup(link, req_size, offset, &header, &ts);
|
CURL *curl = Link_download_curl_setup(link, req_size, offset, &header, &ts);
|
||||||
|
|
||||||
transfer_blocking(curl);
|
transfer_blocking(curl);
|
||||||
|
@ -1096,7 +1108,7 @@ long path_download(const char *path, char *output_buf, size_t req_size,
|
||||||
return Link_download(link, output_buf, req_size, offset);
|
return Link_download(link, output_buf, req_size, offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void make_link_relative(const char *page_url, char *link_url)
|
static void make_link_relative(const char *page_url, char *link_url)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
Some servers make the links to subdirectories absolute (in URI terms:
|
Some servers make the links to subdirectories absolute (in URI terms:
|
||||||
|
@ -1139,14 +1151,14 @@ static void make_link_relative(const char *page_url, char *link_url)
|
||||||
page_url++;
|
page_url++;
|
||||||
}
|
}
|
||||||
if (slashes_left_to_find) {
|
if (slashes_left_to_find) {
|
||||||
if (slashes_left_to_find == 1 && ! *page_url)
|
if (slashes_left_to_find == 1 && ! *page_url)
|
||||||
/* We're at the top level of the web site and the user entered the URL
|
/* We're at the top level of the web site and the user entered the URL
|
||||||
without a trailing slash. */
|
without a trailing slash. */
|
||||||
page_url = "/";
|
page_url = "/";
|
||||||
else
|
else
|
||||||
/* Well, that's odd. Let's return rather than trying to dig ourselves
|
/* Well, that's odd. Let's return rather than trying to dig ourselves
|
||||||
deeper into whatever hole we're in. */
|
deeper into whatever hole we're in. */
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
/* The page URL is no longer the full page_url, it's just the part after
|
/* The page URL is no longer the full page_url, it's just the part after
|
||||||
the host name. */
|
the host name. */
|
||||||
|
|
Loading…
Reference in New Issue