Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
download: pass full url to the process callback
  • Loading branch information
perexg committed Nov 19, 2015
1 parent a74e106 commit 04ea0e8
Showing 1 changed file with 3 additions and 24 deletions.
27 changes: 3 additions & 24 deletions src/download.c
Expand Up @@ -96,10 +96,8 @@ static int
download_fetch_complete(http_client_t *hc)
{
download_t *dn = hc->hc_aux;
char *last_url = NULL;
char host_url[512];
char *s, *p;
url_t u, u2;
const char *last_url = NULL;
url_t u;

switch (hc->hc_code) {
case HTTP_STATUS_MOVED:
Expand All @@ -115,33 +113,14 @@ download_fetch_complete(http_client_t *hc)
if (last_url)
last_url++;
}
if ((p = http_arg_get(&hc->hc_args, "Host")) != NULL) {
snprintf(host_url, sizeof(host_url), "%s://%s",
hc->hc_ssl ? "https" : "http", p);
} else if (dn->url) {
s = strdupa(dn->url);
if ((p = strchr(s, '/')) != NULL) {
p++;
if (*p == '/')
p++;
if ((p = strchr(p, '/')) != NULL)
*p = '\0';
}
urlinit(&u2);
if (!urlparse(s, &u2))
snprintf(host_url, sizeof(host_url), "%s", s);
urlreset(&u2);
} else {
host_url[0] = '\0';
}

pthread_mutex_lock(&global_lock);

if (dn->http_client == NULL)
goto out;

if (hc->hc_code == HTTP_STATUS_OK && hc->hc_result == 0 && hc->hc_data_size > 0)
dn->process(dn->aux, last_url, host_url, hc->hc_data, hc->hc_data_size);
dn->process(dn->aux, last_url, hc->hc_url, hc->hc_data, hc->hc_data_size);
else
tvherror(dn->log, "unable to fetch data from url [%d-%d/%zd]",
hc->hc_code, hc->hc_result, hc->hc_data_size);
Expand Down

0 comments on commit 04ea0e8

Please sign in to comment.