From: Jordan Lee Date: Sat, 13 Apr 2013 20:25:28 +0000 (+0000) Subject: (trunk) update web.h's API s.t. there's an explicit function to use when downloading... X-Git-Tag: 2.80~32 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=96786b7fa1ae458ae3f4f000cec6684b22f0073f;p=transmission (trunk) update web.h's API s.t. there's an explicit function to use when downloading webseed content. --- diff --git a/cli/cli.c b/cli/cli.c index 06609fb52..a1eca56d7 100644 --- a/cli/cli.c +++ b/cli/cli.c @@ -294,7 +294,7 @@ main (int argc, char ** argv) } else if (!memcmp (torrentPath, "http", 4)) { - tr_webRun (h, torrentPath, NULL, NULL, onTorrentFileDownloaded, ctor); + tr_webRun (h, torrentPath, onTorrentFileDownloaded, ctor); waitingOnWeb = true; while (waitingOnWeb) tr_wait_msec (1000); diff --git a/gtk/favicon.c b/gtk/favicon.c index 5ead99901..ec9df77a2 100644 --- a/gtk/favicon.c +++ b/gtk/favicon.c @@ -111,7 +111,7 @@ favicon_web_done_idle_cb (gpointer vfav) fav->contents = NULL; fav->len = 0; - tr_webRun (fav->session, url, NULL, NULL, favicon_web_done_cb, fav); + tr_webRun (fav->session, url, favicon_web_done_cb, fav); g_free (url); } } @@ -167,7 +167,7 @@ gtr_get_favicon (tr_session * session, data->host = g_strdup (host); data->type = 0; - tr_webRun (session, url, NULL, NULL, favicon_web_done_cb, data); + tr_webRun (session, url, favicon_web_done_cb, data); g_free (url); } } diff --git a/libtransmission/announcer-http.c b/libtransmission/announcer-http.c index 8b7d413d8..f0c46dc4f 100644 --- a/libtransmission/announcer-http.c +++ b/libtransmission/announcer-http.c @@ -304,7 +304,7 @@ tr_tracker_http_announce (tr_session * session, tr_strlcpy (d->log_name, request->log_name, sizeof (d->log_name)); dbgmsg (request->log_name, "Sending announce to libcurl: \"%s\"", url); - tr_webRun (session, url, NULL, NULL, on_announce_done, d); + tr_webRun (session, url, on_announce_done, d); tr_free (url); } @@ -479,7 +479,7 @@ tr_tracker_http_scrape (tr_session * session, tr_strlcpy (d->log_name, request->log_name, sizeof (d->log_name)); dbgmsg (request->log_name, "Sending scrape to libcurl: \"%s\"", url); - tr_webRun (session, url, NULL, NULL, on_scrape_done, d); + tr_webRun (session, url, on_scrape_done, d); tr_free (url); } diff --git a/libtransmission/rpcimpl.c b/libtransmission/rpcimpl.c index 9fb03ab7c..1b3cc0523 100644 --- a/libtransmission/rpcimpl.c +++ b/libtransmission/rpcimpl.c @@ -1400,7 +1400,7 @@ portTest (tr_session * session, { const int port = tr_sessionGetPeerPort (session); char * url = tr_strdup_printf ("http://portcheck.transmissionbt.com/%d", port); - tr_webRun (session, url, NULL, NULL, portTested, idle_data); + tr_webRun (session, url, portTested, idle_data); tr_free (url); return NULL; } @@ -1500,11 +1500,11 @@ gotNewBlocklist (tr_session * session, static const char* blocklistUpdate (tr_session * session, - tr_variant * args_in UNUSED, - tr_variant * args_out UNUSED, + tr_variant * args_in UNUSED, + tr_variant * args_out UNUSED, struct tr_rpc_idle_data * idle_data) { - tr_webRun (session, session->blocklist_url, NULL, NULL, gotNewBlocklist, idle_data); + tr_webRun (session, session->blocklist_url, gotNewBlocklist, idle_data); return NULL; } @@ -1689,7 +1689,7 @@ torrentAdd (tr_session * session, struct add_torrent_idle_data * d = tr_new0 (struct add_torrent_idle_data, 1); d->data = idle_data; d->ctor = ctor; - tr_webRun (session, filename, NULL, cookies, gotMetadataFromURL, d); + tr_webRunWithCookies (session, filename, cookies, gotMetadataFromURL, d); } else { diff --git a/libtransmission/web.c b/libtransmission/web.c index 9fcc96f2f..1f546cd98 100644 --- a/libtransmission/web.c +++ b/libtransmission/web.c @@ -26,6 +26,7 @@ #include "transmission.h" #include "log.h" #include "net.h" /* tr_address */ +#include "torrent.h" #include "platform.h" /* mutex */ #include "session.h" #include "trevent.h" /* tr_runInEventThread () */ @@ -62,6 +63,7 @@ enum struct tr_web_task { + int torrentId; long code; long timeout_secs; bool did_connect; @@ -234,29 +236,17 @@ task_finish_func (void * vtask) ***** ****/ -struct tr_web_task * -tr_webRun (tr_session * session, - const char * url, - const char * range, - const char * cookies, - tr_web_done_func done_func, - void * done_func_user_data) -{ - return tr_webRunWithBuffer (session, url, range, cookies, - done_func, done_func_user_data, - NULL); -} - static void tr_webThreadFunc (void * vsession); -struct tr_web_task * -tr_webRunWithBuffer (tr_session * session, - const char * url, - const char * range, - const char * cookies, - tr_web_done_func done_func, - void * done_func_user_data, - struct evbuffer * buffer) +static struct tr_web_task * +tr_webRunImpl (tr_session * session, + int torrentId, + const char * url, + const char * range, + const char * cookies, + tr_web_done_func done_func, + void * done_func_user_data, + struct evbuffer * buffer) { struct tr_web_task * task = NULL; @@ -272,6 +262,7 @@ tr_webRunWithBuffer (tr_session * session, task = tr_new0 (struct tr_web_task, 1); task->session = session; + task->torrentId = torrentId; task->url = tr_strdup (url); task->range = tr_strdup (range); task->cookies = tr_strdup (cookies); @@ -289,6 +280,44 @@ tr_webRunWithBuffer (tr_session * session, return task; } +struct tr_web_task * +tr_webRunWithCookies (tr_session * session, + const char * url, + const char * cookies, + tr_web_done_func done_func, + void * done_func_user_data) +{ + return tr_webRunImpl (session, -1, url, + NULL, cookies, + done_func, done_func_user_data, + NULL); +} + +struct tr_web_task * +tr_webRun (tr_session * session, + const char * url, + tr_web_done_func done_func, + void * done_func_user_data) +{ + return tr_webRunWithCookies (session, url, NULL, + done_func, done_func_user_data); +} + + +struct tr_web_task * +tr_webRunWebseed (tr_torrent * tor, + const char * url, + const char * range, + tr_web_done_func done_func, + void * done_func_user_data, + struct evbuffer * buffer) +{ + return tr_webRunImpl (tor->session, tr_torrentId (tor), url, + range, NULL, + done_func, done_func_user_data, + buffer); +} + /** * Portability wrapper for select (). * diff --git a/libtransmission/web.h b/libtransmission/web.h index 59ad7c71a..dc45a59c4 100644 --- a/libtransmission/web.h +++ b/libtransmission/web.h @@ -51,20 +51,23 @@ const char * tr_webGetResponseStr (long response_code); struct tr_web_task * tr_webRun (tr_session * session, const char * url, - const char * range, - const char * cookies, tr_web_done_func done_func, void * done_func_user_data); +struct tr_web_task * tr_webRunWithCookies (tr_session * session, + const char * url, + const char * cookies, + tr_web_done_func done_func, + void * done_func_user_data); + struct evbuffer; -struct tr_web_task * tr_webRunWithBuffer (tr_session * session, - const char * url, - const char * range, - const char * cookies, - tr_web_done_func done_func, - void * done_func_user_data, - struct evbuffer * buffer); +struct tr_web_task * tr_webRunWebseed (tr_torrent * tor, + const char * url, + const char * range, + tr_web_done_func done_func, + void * done_func_user_data, + struct evbuffer * buffer); void tr_webGetTaskInfo (struct tr_web_task * task, tr_web_task_info info, void * dst); diff --git a/libtransmission/webseed.c b/libtransmission/webseed.c index f3ed278e2..0c904a86e 100644 --- a/libtransmission/webseed.c +++ b/libtransmission/webseed.c @@ -498,8 +498,9 @@ task_request_next_chunk (struct tr_webseed_task * t) tr_snprintf (range, sizeof range, "%"PRIu64"-%"PRIu64, file_offset, file_offset + this_pass - 1); - t->web_task = tr_webRunWithBuffer (w->session, urls[file_index], - range, NULL, web_response_func, t, t->content); + + t->web_task = tr_webRunWebseed (tor, urls[file_index], range, + web_response_func, t, t->content); } }