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);
+ tr_http_escape (buf, ipv6_readable, TR_BAD_SIZE, true);
}
return evbuffer_free_to_str (buf, NULL);
if (!variant_loaded)
fprintf (stderr, "%s", "Announce response was not in benc format\n");
else {
- int i, len;
+ size_t i, len;
char * str = tr_variantToStr (&benc, TR_VARIANT_FMT_JSON, &len);
fprintf (stderr, "%s", "Announce response:\n< ");
for (i=0; i<len; ++i)
if (!variant_loaded)
fprintf (stderr, "%s", "Scrape response was not in benc format\n");
else {
- int i, len;
+ size_t i, len;
char * str = tr_variantToStr (&top, TR_VARIANT_FMT_JSON, &len);
fprintf (stderr, "%s", "Scrape response:\n< ");
for (i=0; i<len; ++i)
static const int base32LookupLen = sizeof (base32Lookup) / sizeof (base32Lookup[0]);
static void
-base32_to_sha1 (uint8_t * out, const char * in, const int inlen)
+base32_to_sha1 (uint8_t * out, const char * in, const size_t inlen)
{
- const int outlen = 20;
- int i, index, offset;
+ const size_t outlen = 20;
+ size_t i, index, offset;
memset (out, 0, 20);
const char * delim = strchr (key, '=');
const char * val = delim == NULL ? NULL : delim + 1;
const char * next = strchr (delim == NULL ? key : val, '&');
- int keylen, vallen;
+ size_t keylen, vallen;
if (delim != NULL)
- keylen = delim - key;
+ keylen = (size_t) (delim - key);
else if (next != NULL)
- keylen = next - key;
+ keylen = (size_t) (next - key);
else
keylen = strlen (key);
if (val == NULL)
vallen = 0;
else if (next != NULL)
- vallen = next - val;
+ vallen = (size_t) (next - val);
else
vallen = strlen (val);
if ((keylen==2) && !memcmp (key, "xt", 2) && val && !memcmp (val, "urn:btih:", 9))
{
const char * hash = val + 9;
- const int hashlen = vallen - 9;
+ const size_t hashlen = vallen - 9;
if (hashlen == 40)
{
tr_metainfoParseImpl (const tr_session * session,
tr_info * inf,
bool * hasInfoDict,
- int * infoDictLength,
- const tr_variant * meta_in)
+ size_t * infoDictLength,
+ const tr_variant * meta_in)
{
int64_t i;
size_t len;
}
else
{
- int len;
+ size_t len;
char * bstr = tr_variantToStr (infoDict, TR_VARIANT_FMT_BENC, &len);
tr_sha1 (inf->hash, bstr, len, NULL);
tr_sha1_to_hex (inf->hashString, inf->hash);
const tr_variant * meta_in,
tr_info * inf,
bool * hasInfoDict,
- int * infoDictLength)
+ size_t * infoDictLength)
{
const char * badTag = tr_metainfoParseImpl (session,
inf,
const tr_variant * variant,
tr_info * setmeInfo,
bool * setmeHasInfoDict,
- int * setmeInfoDictLength);
+ size_t * setmeInfoDictLength);
void tr_metainfoRemoveSaved (const tr_session * session,
const tr_info * info);
&& popNextMetadataRequest (msgs, &piece))
{
char * data;
- int dataLen;
+ size_t dataLen;
bool ok = false;
data = tr_torrentGetMetadataPiece (msgs->torrent, piece, &dataLen);
if (magnet_info == NULL)
err = -1;
else {
- int len;
+ size_t len;
tr_variant tmp;
char * str;
}
}
-static int
+static size_t
findInfoDictOffset (const tr_torrent * tor)
{
size_t fileLen;
uint8_t * fileContents;
- int offset = 0;
+ size_t offset = 0;
/* load the file, and find the info dict's offset inside the file */
if ((fileContents = tr_loadFile (tor->info.torrent, &fileLen, NULL)))
if (tr_variantDictFindDict (&top, TR_KEY_info, &infoDict))
{
- int infoLen;
+ size_t infoLen;
char * infoContents = tr_variantToStr (infoDict, TR_VARIANT_FMT_BENC, &infoLen);
const uint8_t * i = (const uint8_t*) tr_memmem ((char*)fileContents, fileLen, infoContents, infoLen);
offset = i != NULL ? i - fileContents : 0;
}
void*
-tr_torrentGetMetadataPiece (tr_torrent * tor, int piece, int * len)
+tr_torrentGetMetadataPiece (tr_torrent * tor, int piece, size_t * len)
{
char * ret = NULL;
ensureInfoDictOffsetIsCached (tor);
assert (tor->infoDictLength > 0);
- assert (tor->infoDictOffset >= 0);
fd = tr_sys_file_open (tor->info.torrent, TR_SYS_FILE_READ, 0, NULL);
if (fd != TR_BAD_SYS_FILE)
{
- const int o = piece * METADATA_PIECE_SIZE;
+ const size_t o = piece * METADATA_PIECE_SIZE;
if (tr_sys_file_seek (fd, tor->infoDictOffset + o, TR_SEEK_SET, NULL, NULL))
{
- const int l = o + METADATA_PIECE_SIZE <= tor->infoDictLength
- ? METADATA_PIECE_SIZE
- : tor->infoDictLength - o;
+ const size_t l = o + METADATA_PIECE_SIZE <= tor->infoDictLength
+ ? METADATA_PIECE_SIZE
+ : tor->infoDictLength - o;
if (0<l && l<=METADATA_PIECE_SIZE)
{
char * buf = tr_new (char, l);
uint64_t n;
- if (tr_sys_file_read (fd, buf, l, &n, NULL) && n == (unsigned int) l)
+ if (tr_sys_file_read (fd, buf, l, &n, NULL) && n == l)
{
*len = l;
ret = buf;
{
bool hasInfo;
tr_info info;
- int infoDictLength;
+ size_t infoDictLength;
/* remove any old .torrent and .resume files */
tr_sys_path_remove (path, NULL);
if (name && *name)
{
evbuffer_add_printf (s, "%s", "&dn=");
- tr_http_escape (s, name, -1, true);
+ tr_http_escape (s, name, TR_BAD_SIZE, true);
}
for (i=0; i<inf->trackerCount; ++i)
{
evbuffer_add_printf (s, "%s", "&tr=");
- tr_http_escape (s, inf->trackers[i].announce, -1, true);
+ tr_http_escape (s, inf->trackers[i].announce, TR_BAD_SIZE, true);
}
for (i=0; i<inf->webseedCount; i++)
{
evbuffer_add_printf (s, "%s", "&ws=");
- tr_http_escape (s, inf->webseeds[i], -1, true);
+ tr_http_escape (s, inf->webseeds[i], TR_BAD_SIZE, true);
}
return evbuffer_free_to_str (s, NULL);
METADATA_PIECE_SIZE = (1024 * 16)
};
-void* tr_torrentGetMetadataPiece (tr_torrent * tor, int piece, int * len);
+void* tr_torrentGetMetadataPiece (tr_torrent * tor, int piece, size_t * len);
void tr_torrentSetMetadataPiece (tr_torrent * tor, int piece, const void * data, int len);
torrentParseImpl (const tr_ctor * ctor,
tr_info * setmeInfo,
bool * setmeHasInfo,
- int * dictLength,
+ size_t * dictLength,
int * setme_duplicate_id)
{
bool doFree;
tr_torrent *
tr_torrentNew (const tr_ctor * ctor, int * setme_error, int * setme_duplicate_id)
{
- int len;
+ size_t len;
bool hasInfo;
tr_info tmpInfo;
tr_parse_result r;
char * incompleteDir;
/* Length, in bytes, of the "info" dict in the .torrent file. */
- int infoDictLength;
+ size_t infoDictLength;
/* Offset, in bytes, of the beginning of the "info" dict in the .torrent file.
*
* Used by the torrent-magnet code for serving metainfo to peers.
* This field is lazy-generated and might not be initialized yet. */
- int infoDictOffset;
+ size_t infoDictOffset;
/* Where the files are now.
* This pointer will be equal to downloadDir or incompleteDir */
const char * end = NULL;
char * saved;
const size_t len = strlen (str);
- int savedLen;
+ size_t savedLen;
int err;
err = tr_variantFromBencFull (&val, str, len, NULL, &end);
char buf[512];
const char * end;
int err;
- int len;
+ size_t len;
int64_t i;
char * saved;
testStackSmash (void)
{
int i;
- int len;
+ size_t len;
int err;
char * in;
const char * end;
const char * strVal;
double realVal;
bool boolVal;
- int len;
+ size_t len;
char * benc;
const char * end;
size_t strLen;
}
char*
-tr_variantToStr (const tr_variant * v, tr_variant_fmt fmt, int * len)
+tr_variantToStr (const tr_variant * v, tr_variant_fmt fmt, size_t * len)
{
struct evbuffer * buf = tr_variantToBuf (v, fmt);
- size_t n;
- char * ret = evbuffer_free_to_str (buf, &n);
- if (len != NULL)
- *len = (int) n;
- return ret;
+ return evbuffer_free_to_str (buf, len);
}
int
char* tr_variantToStr (const tr_variant * variant,
tr_variant_fmt fmt,
- int * len);
+ size_t * len);
struct evbuffer * tr_variantToBuf (const tr_variant * variant,
tr_variant_fmt fmt);
void
tr_http_escape (struct evbuffer * out,
const char * str,
- int len,
+ size_t len,
bool escape_slashes)
{
- const char * end;
+ if (str == NULL)
+ return;
- if ((len < 0) && (str != NULL))
+ if (len == TR_BAD_SIZE)
len = strlen (str);
- for (end=str+len; str && str!=end; ++str)
+ for (const char * end = str + len; str != end; ++str)
{
if ((*str == ',') || (*str == '-')
|| (*str == '.')
}
char *
-tr_http_unescape (const char * str, int len)
+tr_http_unescape (const char * str, size_t len)
{
char * tmp = curl_unescape (str, len);
char * ret = tr_strdup (tmp);
void tr_webGetTaskInfo (struct tr_web_task * task, tr_web_task_info info, void * dst);
-void tr_http_escape (struct evbuffer *out, const char *str, int len, bool escape_slashes);
+void tr_http_escape (struct evbuffer *out, const char *str, size_t len, bool escape_slashes);
void tr_http_escape_sha1 (char * out, const uint8_t * sha1_digest);
-char* tr_http_unescape (const char * str, int len);
+char* tr_http_unescape (const char * str, size_t len);
#ifdef __cplusplus
}
if (!mySessionId.isEmpty ())
request.setRawHeader (TR_RPC_SESSION_ID_HEADER, mySessionId.toUtf8 ());
- int rawJsonDataLength;
+ size_t rawJsonDataLength;
char * rawJsonData = tr_variantToStr (json.get (), TR_VARIANT_FMT_JSON_LEAN, &rawJsonDataLength);
QByteArray jsonData (rawJsonData, rawJsonDataLength);
tr_free (rawJsonData);