- Timestamp:
- 2016-11-20T08:40:36Z (8 years ago)
- Children:
- 3f44e43
- Parents:
- ba52ac5 (diff), 9f03c47 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Location:
- lib
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/http_client.c
rba52ac5 r537d9b9 95 95 request = g_strdup_printf("GET %s HTTP/1.0\r\n" 96 96 "Host: %s\r\n" 97 "User-Agent: BitlBee " BITLBEE_VERSION " " ARCH "/" CPU "\r\n"97 "User-Agent: BitlBee " BITLBEE_VERSION "\r\n" 98 98 "\r\n", url->file, url->host); 99 99 -
lib/misc.c
rba52ac5 r537d9b9 549 549 } 550 550 551 /* Word wrapping. Yes, I know this isn't UTF-8 clean. I'm willing to take the risk. */552 551 char *word_wrap(const char *msg, int line_len) 553 552 { … … 582 581 } 583 582 if (i == 0) { 584 g_string_append_len(ret, msg, line_len); 583 const char *end; 584 size_t len; 585 586 g_utf8_validate(msg, line_len, &end); 587 588 len = (end != msg) ? end - msg : line_len; 589 590 g_string_append_len(ret, msg, len); 585 591 g_string_append_c(ret, '\n'); 586 msg += l ine_len;592 msg += len; 587 593 } 588 594 } … … 787 793 return string; 788 794 } 795 796 /* Returns a string that is exactly 'char_len' utf8 characters long (not bytes), 797 * padded to the right with spaces or truncated with the 'ellipsis' parameter 798 * if specified (can be NULL). 799 * Returns a newly allocated string, or NULL on invalid parameters. */ 800 char *str_pad_and_truncate(const char *string, long char_len, const char *ellipsis) 801 { 802 size_t string_len = strlen(string); 803 size_t ellipsis_len = (ellipsis) ? strlen(ellipsis) : 0; 804 long orig_len = g_utf8_strlen(string, -1); 805 806 g_return_val_if_fail(char_len > ellipsis_len, NULL); 807 808 if (orig_len > char_len) { 809 char *ret = g_malloc(string_len + 1); 810 g_utf8_strncpy(ret, string, char_len - ellipsis_len); 811 if (ellipsis) { 812 g_strlcat(ret, ellipsis, string_len); 813 } 814 return ret; 815 } else if (orig_len < char_len) { 816 return g_strdup_printf("%s%*s", string, (int) (char_len - orig_len), ""); 817 } else { 818 return g_strdup(string); 819 } 820 } -
lib/misc.h
rba52ac5 r537d9b9 151 151 G_MODULE_EXPORT gboolean parse_int64(char *string, int base, guint64 *number); 152 152 G_MODULE_EXPORT char *str_reject_chars(char *string, const char *reject, char replacement); 153 G_MODULE_EXPORT char *str_pad_and_truncate(const char *string, long char_len, const char *ellipsis); 153 154 154 155 #endif -
lib/proxy.c
rba52ac5 r537d9b9 87 87 } 88 88 89 /* calls phb->func safely by ensuring that the phb struct doesn't exist in the 90 * case that proxy_disconnect() is called down there */ 91 static gboolean phb_connected(struct PHB *phb, gint source) 92 { 93 /* save func and data here */ 94 b_event_handler func = phb->func; 95 gpointer data = phb->data; 96 97 /* free the struct so that it can't be freed by the callback */ 98 phb_free(phb, TRUE); 99 100 /* if any proxy_disconnect() call happens here, it will use the 101 * fd (still open), look it up in the hash table, get NULL, and 102 * proceed to close the fd and do nothing else */ 103 func(data, source, B_EV_IO_READ); 104 105 return FALSE; 106 } 107 89 108 static gboolean proxy_connected(gpointer data, gint source, b_input_condition cond) 90 109 { … … 125 144 phb->proxy_func(phb->proxy_data, source, B_EV_IO_READ); 126 145 } else { 127 phb->func(phb->data, source, B_EV_IO_READ); 128 phb_free(phb, TRUE); 146 phb_connected(phb, source); 129 147 } 130 148 … … 222 240 if ((memcmp(HTTP_GOODSTRING, inputline, strlen(HTTP_GOODSTRING)) == 0) || 223 241 (memcmp(HTTP_GOODSTRING2, inputline, strlen(HTTP_GOODSTRING2)) == 0)) { 224 phb->func(phb->data, source, B_EV_IO_READ); 225 return phb_free(phb, TRUE); 242 return phb_connected(phb, source); 226 243 } 227 244 … … 295 312 memset(packet, 0, sizeof(packet)); 296 313 if (read(source, packet, 9) >= 4 && packet[1] == 90) { 297 phb->func(phb->data, source, B_EV_IO_READ); 298 return phb_free(phb, TRUE); 314 return phb_connected(phb, source); 299 315 } 300 316 … … 384 400 } 385 401 386 phb->func(phb->data, source, B_EV_IO_READ); 387 return phb_free(phb, TRUE); 402 return phb_connected(phb, source); 388 403 } 389 404 -
lib/sha1.c
rba52ac5 r537d9b9 24 24 #define HMAC_BLOCK_SIZE 64 25 25 26 /* BitlBee addition: */ 27 void sha1_hmac(const char *key_, size_t key_len, const char *payload, size_t payload_len, guint8 digest[SHA1_HASH_SIZE])26 void b_hmac(GChecksumType checksum_type, const char *key_, size_t key_len, 27 const char *payload, size_t payload_len, guint8 **digest) 28 28 { 29 sha1_state_t sha1; 30 guint8 hash[SHA1_HASH_SIZE]; 29 GChecksum *checksum; 30 size_t hash_len; 31 guint8 *hash; 31 32 guint8 key[HMAC_BLOCK_SIZE + 1]; 32 33 int i; 34 35 hash_len = g_checksum_type_get_length(checksum_type); 36 37 if (hash_len == (size_t) -1) { 38 return; 39 } 40 41 hash = g_malloc(hash_len); 33 42 34 43 if (key_len == 0) { … … 43 52 memset(key, 0, HMAC_BLOCK_SIZE + 1); 44 53 if (key_len > HMAC_BLOCK_SIZE) { 45 sha1_init(&sha1); 46 sha1_append(&sha1, (guint8 *) key_, key_len); 47 sha1_finish(&sha1, key); 54 checksum = g_checksum_new(checksum_type); 55 g_checksum_update(checksum, (guint8 *) key_, key_len); 56 g_checksum_get_digest(checksum, key, &hash_len); 57 g_checksum_free(checksum); 48 58 } else { 49 59 memcpy(key, key_, key_len); … … 51 61 52 62 /* Inner part: H(K XOR 0x36, text) */ 53 sha1_init(&sha1);63 checksum = g_checksum_new(checksum_type); 54 64 for (i = 0; i < HMAC_BLOCK_SIZE; i++) { 55 65 key[i] ^= 0x36; 56 66 } 57 sha1_append(&sha1, key, HMAC_BLOCK_SIZE); 58 sha1_append(&sha1, (const guint8 *) payload, payload_len); 59 sha1_finish(&sha1, hash); 67 g_checksum_update(checksum, key, HMAC_BLOCK_SIZE); 68 g_checksum_update(checksum, (const guint8 *) payload, payload_len); 69 g_checksum_get_digest(checksum, hash, &hash_len); 70 g_checksum_free(checksum); 60 71 61 72 /* Final result: H(K XOR 0x5C, inner stuff) */ 62 sha1_init(&sha1);73 checksum = g_checksum_new(checksum_type); 63 74 for (i = 0; i < HMAC_BLOCK_SIZE; i++) { 64 75 key[i] ^= 0x36 ^ 0x5c; 65 76 } 66 sha1_append(&sha1, key, HMAC_BLOCK_SIZE); 67 sha1_append(&sha1, hash, SHA1_HASH_SIZE); 68 sha1_finish(&sha1, digest); 77 g_checksum_update(checksum, key, HMAC_BLOCK_SIZE); 78 g_checksum_update(checksum, hash, hash_len); 79 g_checksum_get_digest(checksum, *digest, &hash_len); 80 g_checksum_free(checksum); 81 82 g_free(hash); 69 83 } 84 85 void sha1_hmac(const char *key_, size_t key_len, const char *payload, size_t payload_len, guint8 digest[SHA1_HASH_SIZE]) 86 { 87 b_hmac(G_CHECKSUM_SHA1, key_, key_len, payload, payload_len, &digest); 88 } 89 70 90 71 91 /* I think this follows the scheme described on: -
lib/ssl_gnutls.c
rba52ac5 r537d9b9 42 42 #include <limits.h> 43 43 44 #if defined(ULONG_MAX) && ULONG_MAX > 4294967295UL45 #define GNUTLS_STUPID_CAST (long)46 #else47 #define GNUTLS_STUPID_CAST (int)48 #endif49 50 44 #define SSLDEBUG 0 51 45 … … 335 329 336 330 sock_make_nonblocking(conn->fd); 337 gnutls_transport_set_ptr(conn->session, (gnutls_transport_ptr_t) GNUTLS_STUPID_CASTconn->fd);331 gnutls_transport_set_ptr(conn->session, (gnutls_transport_ptr_t) (long) conn->fd); 338 332 339 333 ssl_cache_resume(conn); -
lib/ssl_openssl.c
rba52ac5 r537d9b9 67 67 SSL_library_init(); 68 68 69 meth = TLSv1_client_method();69 meth = SSLv23_client_method(); 70 70 ssl_ctx = SSL_CTX_new(meth); 71 SSL_CTX_set_options(ssl_ctx, SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3); 71 72 72 73 initialized = TRUE;
Note: See TracChangeset
for help on using the changeset viewer.