From 3f9575fcc805981b444e6ad75b1697d06cfed1fa Mon Sep 17 00:00:00 2001 From: Mike Gelfand Date: Sun, 15 Mar 2015 11:43:32 +0000 Subject: [PATCH] Minor type adjustments (incomplete, it takes way too much time) --- libtransmission/announcer-udp.c | 2 +- libtransmission/cache.c | 2 +- libtransmission/clients.c | 10 +-- libtransmission/crypto.c | 4 +- libtransmission/handshake.c | 104 ++++++++++++++++---------------- libtransmission/inout.c | 2 +- libtransmission/log.c | 2 +- libtransmission/log.h | 2 +- libtransmission/peer-io.c | 2 +- 9 files changed, 65 insertions(+), 65 deletions(-) diff --git a/libtransmission/announcer-udp.c b/libtransmission/announcer-udp.c index 47f825a98..43ef63d6b 100644 --- a/libtransmission/announcer-udp.c +++ b/libtransmission/announcer-udp.c @@ -123,7 +123,7 @@ typedef enum tau_action_t; static bool -is_tau_response_message (int action, int msglen) +is_tau_response_message (tau_action_t action, size_t msglen) { if (action == TAU_ACTION_CONNECT) return msglen == 16; if (action == TAU_ACTION_ANNOUNCE) return msglen >= 20; diff --git a/libtransmission/cache.c b/libtransmission/cache.c index 933adfac9..909cffd1d 100644 --- a/libtransmission/cache.c +++ b/libtransmission/cache.c @@ -72,7 +72,7 @@ struct run_info time_t last_block_time; bool is_multi_piece; bool is_piece_done; - unsigned len; + unsigned int len; }; diff --git a/libtransmission/clients.c b/libtransmission/clients.c index a45ee103e..defc49f80 100644 --- a/libtransmission/clients.c +++ b/libtransmission/clients.c @@ -26,15 +26,15 @@ charint (uint8_t ch) return 0; } -static int +static bool getShadowInt (uint8_t ch, int * setme) { const char * str = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.-"; const char * pch = strchr (str, ch); if (!pch) - return 0; + return false; *setme = pch - str; - return 1; + return true; } static int @@ -97,7 +97,7 @@ mainline_style (char * buf, size_t buflen, const char * name, const uint8_t * id tr_snprintf (buf, buflen, "%s %c.%c%c.%c", name, id[1], id[3], id[4], id[6]); } -static int +static bool isMainlineStyle (const uint8_t * peer_id) { /** @@ -110,7 +110,7 @@ isMainlineStyle (const uint8_t * peer_id) && (peer_id[4]=='-' || peer_id[5]=='-'); } -static int +static bool decodeBitCometClient (char * buf, size_t buflen, const uint8_t * id) { int is_bitlord; diff --git a/libtransmission/crypto.c b/libtransmission/crypto.c index 1997ceed6..0321c2523 100644 --- a/libtransmission/crypto.c +++ b/libtransmission/crypto.c @@ -120,7 +120,7 @@ initRC4 (tr_crypto * crypto, void tr_cryptoDecryptInit (tr_crypto * crypto) { - unsigned char discard[1024]; + uint8_t discard[1024]; const char * txt = crypto->isIncoming ? "keyA" : "keyB"; initRC4 (crypto, &crypto->dec_key, txt); @@ -147,7 +147,7 @@ tr_cryptoDecrypt (tr_crypto * crypto, void tr_cryptoEncryptInit (tr_crypto * crypto) { - unsigned char discard[1024]; + uint8_t discard[1024]; const char * txt = crypto->isIncoming ? "keyB" : "keyA"; initRC4 (crypto, &crypto->enc_key, txt); diff --git a/libtransmission/handshake.c b/libtransmission/handshake.c index c307f2f3d..169952ccb 100644 --- a/libtransmission/handshake.c +++ b/libtransmission/handshake.c @@ -62,26 +62,26 @@ enum #ifdef ENABLE_LTEP - #define HANDSHAKE_HAS_LTEP(bits)(((bits)[5] & 0x10) ? 1 : 0) + #define HANDSHAKE_HAS_LTEP(bits)(((bits)[5] & 0x10) != 0) #define HANDSHAKE_SET_LTEP(bits)((bits)[5] |= 0x10) #else - #define HANDSHAKE_HAS_LTEP(bits)(0) + #define HANDSHAKE_HAS_LTEP(bits)(false) #define HANDSHAKE_SET_LTEP(bits)((void)0) #endif #ifdef ENABLE_FAST - #define HANDSHAKE_HAS_FASTEXT(bits)(((bits)[7] & 0x04) ? 1 : 0) + #define HANDSHAKE_HAS_FASTEXT(bits)(((bits)[7] & 0x04) != 0) #define HANDSHAKE_SET_FASTEXT(bits)((bits)[7] |= 0x04) #else - #define HANDSHAKE_HAS_FASTEXT(bits)(0) + #define HANDSHAKE_HAS_FASTEXT(bits)(false) #define HANDSHAKE_SET_FASTEXT(bits)((void)0) #endif #ifdef ENABLE_DHT - #define HANDSHAKE_HAS_DHT(bits)(((bits)[7] & 0x01) ? 1 : 0) + #define HANDSHAKE_HAS_DHT(bits)(((bits)[7] & 0x01) != 0) #define HANDSHAKE_SET_DHT(bits)((bits)[7] |= 0x01) #else - #define HANDSHAKE_HAS_DHT(bits)(0) + #define HANDSHAKE_HAS_DHT(bits)(false) #define HANDSHAKE_SET_DHT(bits)((void)0) #endif @@ -91,34 +91,11 @@ enum #define HANDSHAKE_GET_EXTPREF(reserved) ((reserved)[5] & 0x03) #define HANDSHAKE_SET_EXTPREF(reserved, val)((reserved)[5] |= 0x03 & (val)) -typedef uint8_t handshake_state_t; - -struct tr_handshake -{ - bool haveReadAnythingFromPeer; - bool havePeerID; - bool haveSentBitTorrentHandshake; - tr_peerIo * io; - tr_crypto * crypto; - tr_session * session; - handshake_state_t state; - tr_encryption_mode encryptionMode; - uint16_t pad_c_len; - uint16_t pad_d_len; - uint16_t ia_len; - uint32_t crypto_select; - uint32_t crypto_provide; - uint8_t myReq1[SHA_DIGEST_LENGTH]; - handshakeDoneCB doneCB; - void * doneUserData; - struct event * timeout_timer; -}; - /** *** **/ -enum +typedef enum { /* incoming */ AWAITING_HANDSHAKE, @@ -137,6 +114,28 @@ enum AWAITING_PAD_D, N_STATES +} +handshake_state_t; + +struct tr_handshake +{ + bool haveReadAnythingFromPeer; + bool havePeerID; + bool haveSentBitTorrentHandshake; + tr_peerIo * io; + tr_crypto * crypto; + tr_session * session; + handshake_state_t state; + tr_encryption_mode encryptionMode; + uint16_t pad_c_len; + uint16_t pad_d_len; + uint16_t ia_len; + uint32_t crypto_select; + uint32_t crypto_provide; + uint8_t myReq1[SHA_DIGEST_LENGTH]; + handshakeDoneCB doneCB; + void * doneUserData; + struct event * timeout_timer; }; /** @@ -229,18 +228,19 @@ buildHandshakeMessage (tr_handshake * handshake, uint8_t * buf) return success; } -static int tr_handshakeDone (tr_handshake * handshake, - bool isConnected); +static ReadState tr_handshakeDone (tr_handshake * handshake, + bool isConnected); -enum +typedef enum { HANDSHAKE_OK, HANDSHAKE_ENCRYPTION_WRONG, HANDSHAKE_BAD_TORRENT, HANDSHAKE_PEER_IS_SELF, -}; +} +handshake_parse_err_t; -static int +static handshake_parse_err_t parseHandshake (tr_handshake * handshake, struct evbuffer * inbuf) { @@ -254,7 +254,7 @@ parseHandshake (tr_handshake * handshake, HANDSHAKE_SIZE, evbuffer_get_length (inbuf)); if (evbuffer_get_length (inbuf) < HANDSHAKE_SIZE) - return READ_LATER; + return HANDSHAKE_ENCRYPTION_WRONG; /* confirm the protocol */ tr_peerIoReadBytes (handshake->io, inbuf, name, HANDSHAKE_NAME_LEN); @@ -392,10 +392,10 @@ computeRequestHash (const tr_handshake * handshake, tr_cryptoSecretKeySha1 (handshake->crypto, name, 4, NULL, 0, hash); } -static int +static ReadState readYb (tr_handshake * handshake, struct evbuffer * inbuf) { - int isEncrypted; + bool isEncrypted; uint8_t yb[KEY_LEN]; struct evbuffer * outbuf; size_t needlen = HANDSHAKE_NAME_LEN; @@ -403,7 +403,7 @@ readYb (tr_handshake * handshake, struct evbuffer * inbuf) if (evbuffer_get_length (inbuf) < needlen) return READ_LATER; - isEncrypted = memcmp (evbuffer_pullup (inbuf, HANDSHAKE_NAME_LEN), HANDSHAKE_NAME, HANDSHAKE_NAME_LEN); + isEncrypted = memcmp (evbuffer_pullup (inbuf, HANDSHAKE_NAME_LEN), HANDSHAKE_NAME, HANDSHAKE_NAME_LEN) != 0; if (isEncrypted) { needlen = KEY_LEN; @@ -492,7 +492,7 @@ readYb (tr_handshake * handshake, struct evbuffer * inbuf) return READ_LATER; } -static int +static ReadState readVC (tr_handshake * handshake, struct evbuffer * inbuf) { @@ -526,7 +526,7 @@ readVC (tr_handshake * handshake, return READ_NOW; } -static int +static ReadState readCryptoSelect (tr_handshake * handshake, struct evbuffer * inbuf) { @@ -561,7 +561,7 @@ readCryptoSelect (tr_handshake * handshake, return READ_NOW; } -static int +static ReadState readPadD (tr_handshake * handshake, struct evbuffer * inbuf) { @@ -586,7 +586,7 @@ readPadD (tr_handshake * handshake, **** ***/ -static int +static ReadState readHandshake (tr_handshake * handshake, struct evbuffer * inbuf) { @@ -699,7 +699,7 @@ readHandshake (tr_handshake * handshake, return READ_NOW; } -static int +static ReadState readPeerId (tr_handshake * handshake, struct evbuffer * inbuf) { @@ -726,7 +726,7 @@ readPeerId (tr_handshake * handshake, return tr_handshakeDone (handshake, !connected_to_self); } -static int +static ReadState readYa (tr_handshake * handshake, struct evbuffer * inbuf) { @@ -760,7 +760,7 @@ readYa (tr_handshake * handshake, return READ_NOW; } -static int +static ReadState readPadA (tr_handshake * handshake, struct evbuffer * inbuf) { /* resynchronizing on HASH ('req1',S) */ @@ -782,7 +782,7 @@ readPadA (tr_handshake * handshake, struct evbuffer * inbuf) } } -static int +static ReadState readCryptoProvide (tr_handshake * handshake, struct evbuffer * inbuf) { @@ -852,7 +852,7 @@ readCryptoProvide (tr_handshake * handshake, return READ_NOW; } -static int +static ReadState readPadC (tr_handshake * handshake, struct evbuffer * inbuf) { @@ -876,7 +876,7 @@ readPadC (tr_handshake * handshake, return READ_NOW; } -static int +static ReadState readIA (tr_handshake * handshake, struct evbuffer * inbuf) { @@ -954,11 +954,11 @@ readIA (tr_handshake * handshake, return READ_NOW; } -static int +static ReadState readPayloadStream (tr_handshake * handshake, struct evbuffer * inbuf) { - int i; + handshake_parse_err_t i; const size_t needlen = HANDSHAKE_SIZE; dbgmsg (handshake, "reading payload stream... have %"TR_PRIuSIZE", need %"TR_PRIuSIZE, @@ -1093,7 +1093,7 @@ tr_handshakeFree (tr_handshake * handshake) tr_free (handshake); } -static int +static ReadState tr_handshakeDone (tr_handshake * handshake, bool isOK) { bool success; diff --git a/libtransmission/inout.c b/libtransmission/inout.c index 82a769380..5f580f5da 100644 --- a/libtransmission/inout.c +++ b/libtransmission/inout.c @@ -292,7 +292,7 @@ recalculateHash (tr_torrent * tor, tr_piece_index_t pieceIndex, uint8_t * setme) while (bytesLeft) { - const int len = MIN (bytesLeft, buflen); + const size_t len = MIN (bytesLeft, buflen); success = !tr_cacheReadBlock (tor->session->cache, tor, pieceIndex, offset, len, buffer); if (!success) break; diff --git a/libtransmission/log.c b/libtransmission/log.c index c50bbacb7..16120def3 100644 --- a/libtransmission/log.c +++ b/libtransmission/log.c @@ -139,7 +139,7 @@ tr_logFreeQueue (tr_log_message * list) **/ char* -tr_logGetTimeStr (char * buf, int buflen) +tr_logGetTimeStr (char * buf, size_t buflen) { char tmp[64]; struct tm now_tm; diff --git a/libtransmission/log.h b/libtransmission/log.h index 968480172..71d8b2e3c 100644 --- a/libtransmission/log.h +++ b/libtransmission/log.h @@ -121,7 +121,7 @@ void tr_logAddDeep (const char * file, ...) TR_GNUC_PRINTF (4, 5) TR_GNUC_NONNULL (1,4); /** @brief set the buffer with the current time formatted for deep logging. */ -char* tr_logGetTimeStr (char * buf, int buflen) TR_GNUC_NONNULL (1); +char* tr_logGetTimeStr (char * buf, size_t buflen) TR_GNUC_NONNULL (1); #ifdef __cplusplus } diff --git a/libtransmission/peer-io.c b/libtransmission/peer-io.c index 8e8a619f1..cae762197 100644 --- a/libtransmission/peer-io.c +++ b/libtransmission/peer-io.c @@ -1177,7 +1177,7 @@ tr_peerIoReadBytes (tr_peerIo * io, struct evbuffer * inbuf, void * bytes, size_ break; default: - assert (0); + assert (false); } } -- 2.40.0