(trunk) update web.h's API s.t. there's an explicit function to use when downloading webseed content.

This commit is contained in:
Jordan Lee 2013-04-13 20:25:28 +00:00
parent 6bcdd93e45
commit 96786b7fa1
7 changed files with 75 additions and 42 deletions

View File

@ -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);

View File

@ -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);
}
}

View File

@ -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);
}

View File

@ -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
{

View File

@ -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 ().
*

View File

@ -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);

View File

@ -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);
}
}