static char* makeURL( tr_webseed * w, const tr_file * file ) { char * ret; struct evbuffer * out = evbuffer_new( ); const char * url = w->url; const size_t url_len = strlen( url ); evbuffer_add( out, url, url_len ); /* if url ends with a '/', add the torrent name */ if( url[url_len - 1] == '/' && file->name ) tr_http_escape( out, file->name, strlen(file->name), FALSE ); ret = tr_strndup( EVBUFFER_DATA( out ), EVBUFFER_LENGTH( out ) ); evbuffer_free( out ); return ret; }
static char* announce_url_new (const tr_session * session, const tr_announce_request * req) { const char * str; const unsigned char * ipv6; struct evbuffer * buf = evbuffer_new (); char escaped_info_hash[SHA_DIGEST_LENGTH*3 + 1]; tr_http_escape_sha1 (escaped_info_hash, req->info_hash); evbuffer_expand (buf, 1024); evbuffer_add_printf (buf, "%s" "%c" "info_hash=%s" "&peer_id=%*.*s" "&port=%d" "&uploaded=%" PRIu64 "&downloaded=%" PRIu64 "&left=%" PRIu64 "&numwant=%d" "&key=%x" "&compact=1" "&supportcrypto=1", req->url, strchr (req->url, '?') ? '&' : '?', escaped_info_hash, PEER_ID_LEN, PEER_ID_LEN, req->peer_id, req->port, req->up, req->down, req->leftUntilComplete, req->numwant, req->key); if (session->encryptionMode == TR_ENCRYPTION_REQUIRED) evbuffer_add_printf (buf, "&requirecrypto=1"); if (req->corrupt) evbuffer_add_printf (buf, "&corrupt=%" PRIu64, req->corrupt); str = get_event_string (req); if (str && *str) evbuffer_add_printf (buf, "&event=%s", str); str = req->tracker_id_str; if (str && *str) evbuffer_add_printf (buf, "&trackerid=%s", str); /* There are two incompatible techniques for announcing an IPv6 address. BEP-7 suggests adding an "ipv6=" parameter to the announce URL, while OpenTracker requires that peers announce twice, once over IPv4 and once over IPv6. To be safe, we should do both: add the "ipv6=" parameter and announce twice. At any rate, we're already computing our IPv6 address (for the LTEP handshake), so this comes for free. */ ipv6 = tr_globalIPv6 (); if (ipv6) { char ipv6_readable[INET6_ADDRSTRLEN]; evutil_inet_ntop (AF_INET6, ipv6, ipv6_readable, INET6_ADDRSTRLEN); evbuffer_add_printf (buf, "&ipv6="); tr_http_escape (buf, ipv6_readable, -1, true); } return evbuffer_free_to_str (buf); }