void
tr_tracker_http_scrape (tr_session               * session,
                        const tr_scrape_request  * request,
                        tr_scrape_response_func    response_func,
                        void                     * response_func_user_data)
{
    int i;
    struct scrape_data * d;
    char * url = scrape_url_new (request);

    d = tr_new0 (struct scrape_data, 1);
    d->response.url = tr_strdup (request->url);
    d->response_func = response_func;
    d->response_func_user_data = response_func_user_data;
    d->response.row_count = request->info_hash_count;
    for (i=0; i<d->response.row_count; ++i)
    {
        memcpy (d->response.rows[i].info_hash, request->info_hash[i], SHA_DIGEST_LENGTH);
        d->response.rows[i].seeders = -1;
        d->response.rows[i].leechers = -1;
        d->response.rows[i].downloads = -1;
    }
    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, on_scrape_done, d);

    tr_free (url);
}
Esempio n. 2
0
void
tr_tracker_http_scrape( tr_session               * session,
                        const tr_scrape_request  * request,
                        tr_scrape_response_func    response_func,
                        void                     * response_func_user_data )
{
    int i;
    struct scrape_data * d;
    struct evbuffer * buf = scrape_url_new( request );
    const char * url = (const char *) evbuffer_pullup( buf, -1 );

    d = tr_new0( struct scrape_data, 1 );
    d->response.url = tr_strdup( request->url );
    d->response_func = response_func;
    d->response_func_user_data = response_func_user_data;
    d->response.row_count = request->info_hash_count;
    for( i=0; i<d->response.row_count; ++i )
        memcpy( d->response.rows[i].info_hash, request->info_hash[i], SHA_DIGEST_LENGTH );
    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 );

    evbuffer_free( buf );
}
Esempio n. 3
0
static void
requestNextChunk( tr_webseed * w )
{
    tr_torrent * tor = tr_torrentFindFromHash( w->session, w->hash );

    if( tor != NULL )
    {
        const tr_info * inf = tr_torrentInfo( tor );
        const uint32_t have = EVBUFFER_LENGTH( w->content );
        const uint32_t left = w->byteCount - have;
        const uint32_t pieceOffset = w->pieceOffset + have;
        tr_file_index_t fileIndex;
        uint64_t fileOffset;
        uint32_t thisPass;
        char * url;
        char * range;

        tr_ioFindFileLocation( tor, w->pieceIndex, pieceOffset,
                               &fileIndex, &fileOffset );
        thisPass = MIN( left, inf->files[fileIndex].length - fileOffset );

        url = makeURL( w, &inf->files[fileIndex] );
/*fprintf( stderr, "url is [%s]\n", url );*/
        range = tr_strdup_printf( "%"PRIu64"-%"PRIu64, fileOffset, fileOffset + thisPass - 1 );
/*fprintf( stderr, "range is [%s] ... we want %lu total, we have %lu, so %lu are left, and we're asking for %lu this time\n", range, (unsigned long)w->byteCount, (unsigned long)have, (unsigned long)left, (unsigned long)thisPass );*/
        tr_webRun( w->session, url, range, webResponseFunc, w );
        tr_free( range );
        tr_free( url );
    }
}
Esempio n. 4
0
static gboolean
favicon_web_done_idle_cb (gpointer vfav)
{
    GdkPixbuf * pixbuf = NULL;
    gboolean finished = FALSE;
    struct favicon_data * fav = vfav;

    if (fav->len > 0) /* we got something... try to make a pixbuf from it */
    {
        favicon_save_to_cache (fav->host, fav->contents, fav->len);
        pixbuf = favicon_load_from_cache (fav->host);
        finished = pixbuf != NULL;
    }

    if (!finished) /* no pixbuf yet... */
    {
        if (++fav->type == IMAGE_TYPES) /* failure */
        {
            finished = TRUE;
        }
        else /* keep trying */
        {
            char * url = get_url (fav->host, fav->type);

            g_free (fav->contents);
            fav->contents = NULL;
            fav->len = 0;

            tr_webRun (fav->session, url, NULL, NULL, favicon_web_done_cb, fav);
            g_free (url);
        }
    }

    if (finished)
    {
        fav->func (pixbuf, fav->data);
        g_free (fav->host);
        g_free (fav->contents);
        g_free (fav);
    }

    return FALSE;
}
Esempio n. 5
0
void
tr_tracker_http_announce( tr_session                 * session,
                          const tr_announce_request  * request,
                          tr_announce_response_func    response_func,
                          void                       * response_func_user_data )
{
    struct announce_data * d;
    struct evbuffer * buf = announce_url_new( session, request );
    const char * url = (const char *) evbuffer_pullup( buf, -1 );

    d = tr_new0( struct announce_data, 1 );
    d->response_func = response_func;
    d->response_func_user_data = response_func_user_data;
    memcpy( d->response.info_hash, request->info_hash, SHA_DIGEST_LENGTH );
    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 );

    evbuffer_free( buf );
}
void
tr_tracker_http_announce (tr_session                 * session,
                          const tr_announce_request  * request,
                          tr_announce_response_func    response_func,
                          void                       * response_func_user_data)
{
    struct announce_data * d;
    char * url = announce_url_new (session, request);

    d = tr_new0 (struct announce_data, 1);
    d->response.seeders = -1;
    d->response.leechers = -1;
    d->response.downloads = -1;
    d->response_func = response_func;
    d->response_func_user_data = response_func_user_data;
    memcpy (d->response.info_hash, request->info_hash, SHA_DIGEST_LENGTH);
    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, on_announce_done, d);

    tr_free (url);
}