else
{
bool trash = false;
- int test = tr_ctorGetDeleteSource (ctor, &trash);
+ const bool test = tr_ctorGetDeleteSource (ctor, &trash);
tr_logAddInfo ("Parsing .torrent file successful \"%s\"", file);
- if (!test && trash)
+ if (test && trash)
{
tr_error * error = NULL;
GTK_RESPONSE_CANCEL,
-1);
- if (tr_ctorGetDownloadDir (ctor, TR_FORCE, &str))
+ if (!tr_ctorGetDownloadDir (ctor, TR_FORCE, &str))
g_assert_not_reached ();
g_assert (str);
/* torrent priority row */
row++;
w = data->run_check;
- if (tr_ctorGetPaused (ctor, TR_FORCE, &flag))
+ if (!tr_ctorGetPaused (ctor, TR_FORCE, &flag))
g_assert_not_reached ();
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w), !flag);
gtk_grid_attach (grid, w, 0, row, 2, 1);
/* "trash .torrent file" row */
row++;
w = data->trash_check;
- if (tr_ctorGetDeleteSource (ctor, &flag))
+ if (!tr_ctorGetDeleteSource (ctor, &flag))
g_assert_not_reached ();
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w), flag);
gtk_grid_attach (grid, w, 0, row, 2, 1);
static void
core_apply_defaults (tr_ctor * ctor)
{
- if (tr_ctorGetPaused (ctor, TR_FORCE, NULL))
+ if (!tr_ctorGetPaused (ctor, TR_FORCE, NULL))
tr_ctorSetPaused (ctor, TR_FORCE, !gtr_pref_flag_get (TR_KEY_start_added_torrents));
- if (tr_ctorGetDeleteSource (ctor, NULL))
+ if (!tr_ctorGetDeleteSource (ctor, NULL))
tr_ctorSetDeleteSource (ctor, gtr_pref_flag_get (TR_KEY_trash_original_torrent_files));
- if (tr_ctorGetPeerLimit (ctor, TR_FORCE, NULL))
+ if (!tr_ctorGetPeerLimit (ctor, TR_FORCE, NULL))
tr_ctorSetPeerLimit (ctor, TR_FORCE, gtr_pref_int_get (TR_KEY_peer_limit_per_torrent));
- if (tr_ctorGetDownloadDir (ctor, TR_FORCE, NULL))
+ if (!tr_ctorGetDownloadDir (ctor, TR_FORCE, NULL))
tr_ctorSetDownloadDir (ctor, TR_FORCE, gtr_pref_string_get (TR_KEY_download_dir));
}
return byteCount;
}
+
unsigned int
tr_bandwidthClamp (const tr_bandwidth * b,
tr_direction dir,
****
***/
+#ifndef NDEBUG
+
static bool
-tr_bitfieldIsValid (const tr_bitfield * b UNUSED)
+tr_bitfieldIsValid (const tr_bitfield * b)
{
assert (b != NULL);
assert ((b->alloc_count == 0) == (b->bits == 0));
return true;
}
+#endif
+
size_t
tr_bitfieldCountTrueBits (const tr_bitfield * b)
{
err = flushContiguous (cache, pos, getBlockRun (cache, pos, NULL));
}
- return err;
+ return err;
}
int
}
}
-static int
+static bool
canSendCommand (const struct tr_natpmp * nat)
{
return tr_time () >= nat->command_time;
++l->depth;
}
-int
+bool
tr_lockHave (const tr_lock * l)
{
return (l->depth > 0) &&
void tr_lockUnlock (tr_lock *);
/** @brief return nonzero if the specified lock is locked */
-int tr_lockHave (const tr_lock *);
+bool tr_lockHave (const tr_lock *);
/* @} */
}
}
- return numAdded;
+ return numAdded;
}
{
bool isPaused;
- if (!tr_ctorGetPaused (ctor, mode, &isPaused))
+ if (tr_ctorGetPaused (ctor, mode, &isPaused))
{
tor->isRunning = !isPaused;
ret |= TR_FR_RUN;
}
if (fields & TR_FR_MAX_PEERS)
- if (!tr_ctorGetPeerLimit (ctor, mode, &tor->maxConnectedPeers))
+ if (tr_ctorGetPeerLimit (ctor, mode, &tor->maxConnectedPeers))
ret |= TR_FR_MAX_PEERS;
if (fields & TR_FR_DOWNLOAD_DIR)
{
const char * path;
- if (!tr_ctorGetDownloadDir (ctor, mode, &path) && path && *path)
+ if (tr_ctorGetDownloadDir (ctor, mode, &path) && path && *path)
{
ret |= TR_FR_DOWNLOAD_DIR;
tr_free (tor->downloadDir);
ctor->isSet_delete = true;
}
-int
+bool
tr_ctorGetDeleteSource (const tr_ctor * ctor, bool * setme)
{
- int err = 0;
+ bool ret = true;
if (!ctor->isSet_delete)
- err = 1;
+ ret = false;
else if (setme)
- *setme = ctor->doDelete ? 1 : 0;
+ *setme = ctor->doDelete;
- return err;
+ return ret;
}
/***
ctor->saveInOurTorrentsDir = saveInOurTorrentsDir;
}
-int
+bool
tr_ctorGetSave (const tr_ctor * ctor)
{
return ctor && ctor->saveInOurTorrentsDir;
ctor->incompleteDir = tr_strdup (directory);
}
-int
+bool
tr_ctorGetPeerLimit (const tr_ctor * ctor,
tr_ctorMode mode,
uint16_t * setmeCount)
{
- int err = 0;
+ bool ret = true;
const struct optional_args * args = &ctor->optionalArgs[mode];
if (!args->isSet_connected)
- err = 1;
+ ret = false;
else if (setmeCount)
*setmeCount = args->peerLimit;
- return err;
+ return ret;
}
-int
+bool
tr_ctorGetPaused (const tr_ctor * ctor, tr_ctorMode mode, bool * setmeIsPaused)
{
- int err = 0;
+ bool ret = true;
const struct optional_args * args = &ctor->optionalArgs[mode];
if (!args->isSet_paused)
- err = 1;
+ ret = false;
else if (setmeIsPaused)
*setmeIsPaused = args->isPaused;
- return err;
+ return ret;
}
-int
+bool
tr_ctorGetDownloadDir (const tr_ctor * ctor,
tr_ctorMode mode,
const char ** setmeDownloadDir)
{
- int err = 0;
+ bool ret = true;
const struct optional_args * args = &ctor->optionalArgs[mode];
if (!args->isSet_downloadDir)
- err = 1;
+ ret = false;
else if (setmeDownloadDir)
*setmeDownloadDir = args->downloadDir;
- return err;
+ return ret;
}
-int
+bool
tr_ctorGetIncompleteDir (const tr_ctor * ctor,
const char ** setmeIncompleteDir)
{
- int err = 0;
+ bool ret = true;
if (ctor->incompleteDir == NULL)
- err = 1;
+ ret = false;
else
*setmeIncompleteDir = ctor->incompleteDir;
- return err;
+ return ret;
}
-int
+bool
tr_ctorGetMetainfo (const tr_ctor * ctor,
const tr_variant ** setme)
{
- int err = 0;
+ bool ret = true;
if (!ctor->isSet_metainfo)
- err = 1;
+ ret = false;
else if (setme)
*setme = &ctor->metainfo;
- return err;
+ return ret;
}
tr_session*
}
}
- assert (ret == NULL || *len > 0);
+ assert (ret == NULL || *len > 0);
- return ret;
+ return ret;
}
void
file->lastPiece = getBytePiece (info, lastByte);
}
-static int
+static bool
pieceHasFile (tr_piece_index_t piece,
const tr_file * file)
{
tor->info.hash, SHA_DIGEST_LENGTH,
NULL);
- if (!tr_ctorGetDownloadDir (ctor, TR_FORCE, &dir) ||
- !tr_ctorGetDownloadDir (ctor, TR_FALLBACK, &dir))
- tor->downloadDir = tr_strdup (dir);
+ if (tr_ctorGetDownloadDir (ctor, TR_FORCE, &dir) ||
+ tr_ctorGetDownloadDir (ctor, TR_FALLBACK, &dir))
+ tor->downloadDir = tr_strdup (dir);
- if (tr_ctorGetIncompleteDir (ctor, &dir))
+ if (!tr_ctorGetIncompleteDir (ctor, &dir))
dir = tr_sessionGetIncompleteDir (session);
if (tr_sessionIsIncompleteDirEnabled (session))
tor->incompleteDir = tr_strdup (dir);
if (tr_ctorGetSave (ctor))
{
const tr_variant * val;
- if (!tr_ctorGetMetainfo (ctor, &val))
+ if (tr_ctorGetMetainfo (ctor, &val))
{
const char * path = tor->info.torrent;
const int err = tr_variantToFile (val, TR_VARIANT_FMT_BENC, path);
setmeInfo = &tmp;
memset (setmeInfo, 0, sizeof (tr_info));
- if (tr_ctorGetMetainfo (ctor, &metainfo))
+ if (!tr_ctorGetMetainfo (ctor, &metainfo))
return TR_PARSE_ERR;
didParse = tr_metainfoParse (session, metainfo, setmeInfo,
void tr_ctorSetSave (tr_ctor * ctor,
bool saveMetadataInOurTorrentsDir);
-int tr_ctorGetSave (const tr_ctor * ctor);
+bool tr_ctorGetSave (const tr_ctor * ctor);
void tr_ctorInitTorrentPriorities (const tr_ctor * ctor, tr_torrent * tor);
size_t len, len6;
};
-static int
+static bool
bootstrap_done (tr_session *session, int af)
{
int status;
return tr_dhtEnabled (ss) ? ss->udp_port : 0;
}
-int
+bool
tr_dhtAddNode (tr_session * ss,
const tr_address * address,
tr_port port,
int af = address->type == TR_AF_INET ? AF_INET : AF_INET6;
if (!tr_dhtEnabled (ss))
- return 0;
+ return false;
/* Since we don't want to abuse our bootstrap nodes,
* we don't ping them if the DHT is in a good state. */
if (bootstrap) {
if (tr_dhtStatus (ss, af, NULL) >= TR_DHT_FIREWALLED)
- return 0;
+ return false;
}
if (address->type == TR_AF_INET) {
memcpy (&sin.sin_addr, &address->addr.addr4, 4);
sin.sin_port = htons (port);
dht_ping_node ((struct sockaddr*)&sin, sizeof (sin));
- return 1;
+ return true;
} else if (address->type == TR_AF_INET6) {
struct sockaddr_in6 sin6;
memset (&sin6, 0, sizeof (sin6));
memcpy (&sin6.sin6_addr, &address->addr.addr6, 16);
sin6.sin6_port = htons (port);
dht_ping_node ((struct sockaddr*)&sin6, sizeof (sin6));
- return 1;
+ return true;
}
- return 0;
+ return false;
}
const char *
tr_port tr_dhtPort (tr_session *);
int tr_dhtStatus (tr_session *, int af, int * setme_nodeCount);
const char *tr_dhtPrintableStatus (int status);
-int tr_dhtAddNode (tr_session *, const tr_address *, tr_port, bool bootstrap);
+bool tr_dhtAddNode (tr_session *, const tr_address *, tr_port, bool bootstrap);
void tr_dhtUpkeep (tr_session *);
void tr_dhtCallback (unsigned char *buf, int buflen,
struct sockaddr *from, socklen_t fromlen,
* - assemble search string "\r\nName: " and locate position
* - copy back value from end to next "\r\n"
*/
-static int lpd_extractParam (const char* const str, const char* const name, int n, char* const val)
+static bool lpd_extractParam (const char* const str, const char* const name, int n, char* const val)
{
/* configure maximum length of search string here */
enum { maxLength = 30 };
assert (val != NULL);
if (strlen (name) > maxLength - strlen (CRLF ": "))
- return 0;
+ return false;
/* compose the string token to search for */
tr_snprintf (sstr, maxLength, CRLF "%s: ", name);
pos = strstr (str, sstr);
if (pos == NULL)
- return 0; /* search was not successful */
+ return false; /* search was not successful */
{
const char* const beg = pos + strlen (sstr);
}
/* we successfully returned the value string */
- return 1;
+ return true;
}
/**
/* save the effort to check Host, which seems to be optional anyway */
- if (lpd_extractParam (params, "Port", maxValueLen, value) == 0)
+ if (!lpd_extractParam (params, "Port", maxValueLen, value))
return 0;
/* determine announced peer port, refuse if value too large */
peer->port = htons (peerPort);
res = -1; /* signal caller side-effect to peer->port via return != 0 */
- if (lpd_extractParam (params, "Infohash", maxHashLen, hashString) == 0)
+ if (!lpd_extractParam (params, "Infohash", maxHashLen, hashString))
return res;
tor = tr_torrentFindFromHashString (session, hashString);
/** @brief Get this peer constructor's peer limit */
-int tr_ctorGetPeerLimit (const tr_ctor * ctor,
+bool tr_ctorGetPeerLimit (const tr_ctor * ctor,
tr_ctorMode mode,
uint16_t * setmeCount);
/** @brief Get the "isPaused" flag from this peer constructor */
-int tr_ctorGetPaused (const tr_ctor * ctor,
+bool tr_ctorGetPaused (const tr_ctor * ctor,
tr_ctorMode mode,
bool * setmeIsPaused);
/** @brief Get the download path from this peer constructor */
-int tr_ctorGetDownloadDir (const tr_ctor * ctor,
+bool tr_ctorGetDownloadDir (const tr_ctor * ctor,
tr_ctorMode mode,
const char ** setmeDownloadDir);
/** @brief Get the incomplete directory from this peer constructor */
-int tr_ctorGetIncompleteDir (const tr_ctor * ctor,
+bool tr_ctorGetIncompleteDir (const tr_ctor * ctor,
const char ** setmeIncompleteDir);
/** @brief Get the metainfo from this peer constructor */
-int tr_ctorGetMetainfo (const tr_ctor * ctor,
+bool tr_ctorGetMetainfo (const tr_ctor * ctor,
const struct tr_variant ** setme);
/** @brief Get the "delete .torrent file" flag from this peer constructor */
-int tr_ctorGetDeleteSource (const tr_ctor * ctor,
+bool tr_ctorGetDeleteSource (const tr_ctor * ctor,
bool * setmeDoDelete);
/** @brief Get the tr_session poiner from this peer constructor */
return ret;
}
-static int
+static bool
is_rfc2396_alnum (uint8_t ch)
{
return ('0' <= ch && ch <= '9')