mirror of
https://github.com/transmission/transmission.git
synced 2026-05-08 09:39:08 +01:00
Ongoing refactoring (use size_t instead of int)
This commit is contained in:
@@ -114,7 +114,7 @@ announce_url_new (const tr_session * session, const tr_announce_request * req)
|
||||
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);
|
||||
@@ -215,7 +215,7 @@ on_announce_done (tr_session * session,
|
||||
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)
|
||||
@@ -370,7 +370,7 @@ on_scrape_done (tr_session * session,
|
||||
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)
|
||||
|
||||
@@ -41,10 +41,10 @@ static const int base32Lookup[] =
|
||||
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);
|
||||
|
||||
@@ -121,26 +121,26 @@ tr_magnetParse (const char * uri)
|
||||
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)
|
||||
{
|
||||
|
||||
@@ -412,8 +412,8 @@ static const char*
|
||||
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;
|
||||
@@ -468,7 +468,7 @@ tr_metainfoParseImpl (const tr_session * session,
|
||||
}
|
||||
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);
|
||||
@@ -576,7 +576,7 @@ tr_metainfoParse (const tr_session * session,
|
||||
const tr_variant * meta_in,
|
||||
tr_info * inf,
|
||||
bool * hasInfoDict,
|
||||
int * infoDictLength)
|
||||
size_t * infoDictLength)
|
||||
{
|
||||
const char * badTag = tr_metainfoParseImpl (session,
|
||||
inf,
|
||||
|
||||
@@ -21,7 +21,7 @@ bool tr_metainfoParse (const tr_session * session,
|
||||
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);
|
||||
|
||||
@@ -1955,7 +1955,7 @@ fillOutputBuffer (tr_peerMsgs * msgs, time_t now)
|
||||
&& popNextMetadataRequest (msgs, &piece))
|
||||
{
|
||||
char * data;
|
||||
int dataLen;
|
||||
size_t dataLen;
|
||||
bool ok = false;
|
||||
|
||||
data = tr_torrentGetMetadataPiece (msgs->torrent, piece, &dataLen);
|
||||
|
||||
@@ -111,7 +111,7 @@ tr_ctorSetMetainfoFromMagnetLink (tr_ctor * ctor, const char * magnet_link)
|
||||
if (magnet_info == NULL)
|
||||
err = -1;
|
||||
else {
|
||||
int len;
|
||||
size_t len;
|
||||
tr_variant tmp;
|
||||
char * str;
|
||||
|
||||
|
||||
@@ -98,12 +98,12 @@ tr_torrentSetMetadataSizeHint (tr_torrent * tor, int size)
|
||||
}
|
||||
}
|
||||
|
||||
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)))
|
||||
@@ -116,7 +116,7 @@ findInfoDictOffset (const tr_torrent * tor)
|
||||
|
||||
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;
|
||||
@@ -145,7 +145,7 @@ ensureInfoDictOffsetIsCached (tr_torrent * tor)
|
||||
}
|
||||
|
||||
void*
|
||||
tr_torrentGetMetadataPiece (tr_torrent * tor, int piece, int * len)
|
||||
tr_torrentGetMetadataPiece (tr_torrent * tor, int piece, size_t * len)
|
||||
{
|
||||
char * ret = NULL;
|
||||
|
||||
@@ -160,24 +160,23 @@ tr_torrentGetMetadataPiece (tr_torrent * tor, int piece, int * len)
|
||||
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;
|
||||
@@ -259,7 +258,7 @@ tr_torrentSetMetadataPiece (tr_torrent * tor, int piece, const void * data, in
|
||||
{
|
||||
bool hasInfo;
|
||||
tr_info info;
|
||||
int infoDictLength;
|
||||
size_t infoDictLength;
|
||||
|
||||
/* remove any old .torrent and .resume files */
|
||||
tr_sys_path_remove (path, NULL);
|
||||
@@ -391,19 +390,19 @@ tr_torrentInfoGetMagnetLink (const tr_info * inf)
|
||||
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);
|
||||
|
||||
@@ -22,7 +22,7 @@ enum
|
||||
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);
|
||||
|
||||
|
||||
@@ -980,7 +980,7 @@ static tr_parse_result
|
||||
torrentParseImpl (const tr_ctor * ctor,
|
||||
tr_info * setmeInfo,
|
||||
bool * setmeHasInfo,
|
||||
int * dictLength,
|
||||
size_t * dictLength,
|
||||
int * setme_duplicate_id)
|
||||
{
|
||||
bool doFree;
|
||||
@@ -1039,7 +1039,7 @@ tr_torrentParse (const tr_ctor * ctor, tr_info * setmeInfo)
|
||||
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;
|
||||
|
||||
@@ -167,13 +167,13 @@ struct tr_torrent
|
||||
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 */
|
||||
|
||||
@@ -159,7 +159,7 @@ testString (const char * str, bool isGood)
|
||||
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);
|
||||
@@ -195,7 +195,7 @@ testParse (void)
|
||||
char buf[512];
|
||||
const char * end;
|
||||
int err;
|
||||
int len;
|
||||
size_t len;
|
||||
int64_t i;
|
||||
char * saved;
|
||||
|
||||
@@ -435,7 +435,7 @@ static int
|
||||
testStackSmash (void)
|
||||
{
|
||||
int i;
|
||||
int len;
|
||||
size_t len;
|
||||
int err;
|
||||
char * in;
|
||||
const char * end;
|
||||
@@ -509,7 +509,7 @@ testParse2 (void)
|
||||
const char * strVal;
|
||||
double realVal;
|
||||
bool boolVal;
|
||||
int len;
|
||||
size_t len;
|
||||
char * benc;
|
||||
const char * end;
|
||||
size_t strLen;
|
||||
|
||||
@@ -1199,14 +1199,10 @@ tr_variantToBuf (const tr_variant * v, tr_variant_fmt fmt)
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
@@ -116,7 +116,7 @@ int tr_variantToFile (const tr_variant * variant,
|
||||
|
||||
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);
|
||||
|
||||
@@ -607,15 +607,16 @@ tr_webGetResponseStr (long code)
|
||||
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 == '.')
|
||||
@@ -630,7 +631,7 @@ tr_http_escape (struct evbuffer * out,
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
@@ -68,11 +68,11 @@ struct tr_web_task * tr_webRunWebseed (tr_torrent * tor,
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
+1
-1
@@ -142,7 +142,7 @@ RpcClient::sendRequest (TrVariantPtr json)
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user