]> granicus.if.org Git - transmission/commitdiff
Add more booleans to the picture
authorMike Gelfand <mikedld@mikedld.com>
Sun, 31 May 2015 22:13:31 +0000 (22:13 +0000)
committerMike Gelfand <mikedld@mikedld.com>
Sun, 31 May 2015 22:13:31 +0000 (22:13 +0000)
19 files changed:
daemon/daemon.c
gtk/open-dialog.c
gtk/tr-core.c
libtransmission/bandwidth.c
libtransmission/bitfield.c
libtransmission/cache.c
libtransmission/natpmp.c
libtransmission/platform.c
libtransmission/platform.h
libtransmission/resume.c
libtransmission/torrent-ctor.c
libtransmission/torrent-magnet.c
libtransmission/torrent.c
libtransmission/torrent.h
libtransmission/tr-dht.c
libtransmission/tr-dht.h
libtransmission/tr-lpd.c
libtransmission/transmission.h
libtransmission/web.c

index 4380670f15329bf113a95c87246619249d2b37ec..7ec97158041fc6b2d05a7874ff98752f7ee2e040 100644 (file)
@@ -201,11 +201,11 @@ onFileAdded (tr_session * session, const char * dir, const char * file)
         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;
 
index b0764645b47065f32130559296911037c21e4f8e..61cef2b493ab22974d50fae5fc3c890f3283206e 100644 (file)
@@ -289,7 +289,7 @@ gtr_torrent_options_dialog_new (GtkWindow * parent, TrCore * core, tr_ctor * cto
                                            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);
 
@@ -375,7 +375,7 @@ gtr_torrent_options_dialog_new (GtkWindow * parent, TrCore * core, tr_ctor * cto
   /* 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);
@@ -383,7 +383,7 @@ gtr_torrent_options_dialog_new (GtkWindow * parent, TrCore * core, tr_ctor * cto
   /* "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);
index 4c346d2590b51d8d98e5f3ad1d2d0bd454576d0f..96340b0c0c95344c49f89fa1647c00b3065c0c34 100644 (file)
@@ -1171,16 +1171,16 @@ core_add_ctor (TrCore * core, tr_ctor * ctor,
 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));
 }
 
index 845c0d99e22abcdb4c84452cc22cba5bee5cdc97..9a1c52fa4765a7521a0736a5e94a8057773ee352 100644 (file)
@@ -346,6 +346,7 @@ bandwidthClamp (const tr_bandwidth  * b,
 
   return byteCount;
 }
+
 unsigned int
 tr_bandwidthClamp (const tr_bandwidth  * b,
                    tr_direction          dir,
index bfa0995b7729a267a4c0288c470af50b6ed9b621..d69e082033a03308c152f20907b11e155bfd4260 100644 (file)
@@ -146,8 +146,10 @@ tr_bitfieldHas (const tr_bitfield * b, size_t n)
 ****
 ***/
 
+#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));
@@ -156,6 +158,8 @@ tr_bitfieldIsValid (const tr_bitfield * b UNUSED)
   return true;
 }
 
+#endif
+
 size_t
 tr_bitfieldCountTrueBits (const tr_bitfield * b)
 {
index 909cffd1d538055f0c4f88595c50b8462a81af9c..0e18afd74743b315f9ea17e2510012ef9898137a 100644 (file)
@@ -453,7 +453,7 @@ tr_cacheFlushFile (tr_cache * cache, tr_torrent * torrent, tr_file_index_t i)
       err = flushContiguous (cache, pos, getBlockRun (cache, pos, NULL));
     }
 
-    return err;
+  return err;
 }
 
 int
index 1e8813048fbef2fbdc85bf39fd846d9e54e17718..d5ec7c343b3cc534cc93c0dec7d78c8e37e9daaa 100644 (file)
@@ -98,7 +98,7 @@ tr_natpmpClose (tr_natpmp * nat)
     }
 }
 
-static int
+static bool
 canSendCommand (const struct tr_natpmp * nat)
 {
     return tr_time () >= nat->command_time;
index f4f9ca0ce48455e79afb5a536a678f95831beac7..ec700f271af106b35e78d6f317058471df9d2d34 100644 (file)
@@ -192,7 +192,7 @@ tr_lockLock (tr_lock * l)
   ++l->depth;
 }
 
-int
+bool
 tr_lockHave (const tr_lock * l)
 {
   return (l->depth > 0) &&
index f1f112ebc95bd34a39201edbe21f7480985bf220..b9abd1b73859fbdb643bf9b9597e211f1b360ecb 100644 (file)
@@ -75,7 +75,7 @@ void tr_lockLock (tr_lock *);
 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 *);
 
 /* @} */
 
index 29902454f98ec6668f80bf7b65fdd56be3b99f72..6a8b52bbc17336ab8444f7109435e6d2324cec6d 100644 (file)
@@ -77,7 +77,7 @@ addPeers (tr_torrent * tor, const uint8_t * buf, int buflen)
         }
     }
 
-    return numAdded;
+  return numAdded;
 }
 
 
@@ -872,7 +872,7 @@ setFromCtor (tr_torrent * tor, uint64_t fields, const tr_ctor * ctor, int mode)
     {
       bool isPaused;
 
-      if (!tr_ctorGetPaused (ctor, mode, &isPaused))
+      if (tr_ctorGetPaused (ctor, mode, &isPaused))
         {
           tor->isRunning = !isPaused;
           ret |= TR_FR_RUN;
@@ -880,14 +880,14 @@ setFromCtor (tr_torrent * tor, uint64_t fields, const tr_ctor * ctor, int mode)
     }
 
   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);
index 21b18fa3510896bb2144b866cc3518e49e18f549..134b37503cad950db28c62fc5c7094914bbac232 100644 (file)
@@ -258,17 +258,17 @@ tr_ctorSetDeleteSource (tr_ctor * ctor, bool deleteSource)
     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;
 }
 
 /***
@@ -283,7 +283,7 @@ tr_ctorSetSave (tr_ctor * ctor, bool saveInOurTorrentsDir)
     ctor->saveInOurTorrentsDir = saveInOurTorrentsDir;
 }
 
-int
+bool
 tr_ctorGetSave (const tr_ctor * ctor)
 {
     return ctor && ctor->saveInOurTorrentsDir;
@@ -349,78 +349,78 @@ tr_ctorSetIncompleteDir (tr_ctor * ctor, const char * directory)
     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*
index 8b40bc1d25ed90cf3fb5ef8c9da79bfd0a5a68df..a2d0619c3b22e3232543ca0209704428a5d8d5d8 100644 (file)
@@ -192,9 +192,9 @@ tr_torrentGetMetadataPiece (tr_torrent * tor, int piece, int * len)
         }
     }
 
-    assert (ret == NULL || *len > 0);
+  assert (ret == NULL || *len > 0);
 
-    return ret;
+  return ret;
 }
 
 void
index 35d5217ee3624568bb3b6eb071633da143f2c8a1..eb0e27d3814d050d9ba3d79d7a901e7602755579 100644 (file)
@@ -632,7 +632,7 @@ initFilePieces (tr_info *       info,
   file->lastPiece = getBytePiece (info, lastByte);
 }
 
-static int
+static bool
 pieceHasFile (tr_piece_index_t piece,
               const tr_file *  file)
 {
@@ -872,11 +872,11 @@ torrentInit (tr_torrent * tor, const tr_ctor * ctor)
            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);
@@ -952,7 +952,7 @@ torrentInit (tr_torrent * tor, const tr_ctor * ctor)
   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);
@@ -996,7 +996,7 @@ torrentParseImpl (const tr_ctor  * ctor,
     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,
index 60a4c0839f836da55a5e7e2f8cbc8be718062fcf..c4e8d77b9d36a971dfd2bc21369369408875adcb 100644 (file)
@@ -31,7 +31,7 @@ void        tr_torrentFree (tr_torrent * tor);
 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);
 
index 3bb665cc6290de1b2434c3e1d041c8aa90d28f14..305de71d905016294120b00ff2493c52726db2cb 100644 (file)
@@ -77,7 +77,7 @@ struct bootstrap_closure {
     size_t len, len6;
 };
 
-static int
+static bool
 bootstrap_done (tr_session *session, int af)
 {
     int status;
@@ -460,7 +460,7 @@ tr_dhtPort (tr_session *ss)
     return tr_dhtEnabled (ss) ? ss->udp_port : 0;
 }
 
-int
+bool
 tr_dhtAddNode (tr_session       * ss,
                const tr_address * address,
                tr_port            port,
@@ -469,14 +469,14 @@ tr_dhtAddNode (tr_session       * ss,
     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) {
@@ -486,7 +486,7 @@ tr_dhtAddNode (tr_session       * ss,
         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));
@@ -494,10 +494,10 @@ tr_dhtAddNode (tr_session       * ss,
         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 *
index 7a28e3cc6bef85508ef3fa5c3abdaf9e66f5afd3..a6b101264c0f562fc9432e255667b7830bd41efa 100644 (file)
@@ -42,7 +42,7 @@ bool tr_dhtEnabled (const tr_session *);
 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,
index 0af708ea8269e29252394d76ec5e5e70bf197b32..09733f42c8b60cd33689adcfd96019e6e529dce4 100644 (file)
@@ -211,7 +211,7 @@ static const char* lpd_extractHeader (const char* s, struct lpd_protocolVersion*
 *   - 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 };
@@ -222,14 +222,14 @@ static int lpd_extractParam (const char* const str, const char* const name, int
     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);
@@ -248,7 +248,7 @@ static int lpd_extractParam (const char* const str, const char* const name, int
     }
 
     /* we successfully returned the value string */
-    return 1;
+    return true;
 }
 
 /**
@@ -512,7 +512,7 @@ static int tr_lpdConsiderAnnounce (tr_pex* peer, const char* const msg)
 
         /* 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 */
@@ -522,7 +522,7 @@ static int tr_lpdConsiderAnnounce (tr_pex* peer, const char* const msg)
         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);
index 91e8d67eb412db9ae48c44fe27e246368f519eff..95492fe29ba604ee1386795723551e9a9b1047b6 100644 (file)
@@ -1011,30 +1011,30 @@ void        tr_ctorSetFilesWanted (tr_ctor                * ctor,
 
 
 /** @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 */
index 6e6eca8d09b8f827b1b6adb1af253bfdac71b38c..0572b14e3d7d76440ee577d290ec2fd8ad91f492 100644 (file)
@@ -638,7 +638,7 @@ tr_http_unescape (const char * str, int len)
   return ret;
 }
 
-static int
+static bool
 is_rfc2396_alnum (uint8_t ch)
 {
   return ('0' <= ch && ch <= '9')