Changeset 537d9b9 for lib


Ignore:
Timestamp:
2016-11-20T08:40:36Z (7 years ago)
Author:
dequis <dx@…>
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.
Message:

Merge master up to commit '9f03c47' into parson

Location:
lib
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • lib/http_client.c

    rba52ac5 r537d9b9  
    9595        request = g_strdup_printf("GET %s HTTP/1.0\r\n"
    9696                                  "Host: %s\r\n"
    97                                   "User-Agent: BitlBee " BITLBEE_VERSION " " ARCH "/" CPU "\r\n"
     97                                  "User-Agent: BitlBee " BITLBEE_VERSION "\r\n"
    9898                                  "\r\n", url->file, url->host);
    9999
  • lib/misc.c

    rba52ac5 r537d9b9  
    549549}
    550550
    551 /* Word wrapping. Yes, I know this isn't UTF-8 clean. I'm willing to take the risk. */
    552551char *word_wrap(const char *msg, int line_len)
    553552{
     
    582581                }
    583582                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);
    585591                        g_string_append_c(ret, '\n');
    586                         msg += line_len;
     592                        msg += len;
    587593                }
    588594        }
     
    787793        return string;
    788794}
     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. */
     800char *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  
    151151G_MODULE_EXPORT gboolean parse_int64(char *string, int base, guint64 *number);
    152152G_MODULE_EXPORT char *str_reject_chars(char *string, const char *reject, char replacement);
     153G_MODULE_EXPORT char *str_pad_and_truncate(const char *string, long char_len, const char *ellipsis);
    153154
    154155#endif
  • lib/proxy.c

    rba52ac5 r537d9b9  
    8787}
    8888
     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 */
     91static 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
    89108static gboolean proxy_connected(gpointer data, gint source, b_input_condition cond)
    90109{
     
    125144                phb->proxy_func(phb->proxy_data, source, B_EV_IO_READ);
    126145        } else {
    127                 phb->func(phb->data, source, B_EV_IO_READ);
    128                 phb_free(phb, TRUE);
     146                phb_connected(phb, source);
    129147        }
    130148
     
    222240        if ((memcmp(HTTP_GOODSTRING, inputline, strlen(HTTP_GOODSTRING)) == 0) ||
    223241            (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);
    226243        }
    227244
     
    295312        memset(packet, 0, sizeof(packet));
    296313        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);
    299315        }
    300316
     
    384400        }
    385401
    386         phb->func(phb->data, source, B_EV_IO_READ);
    387         return phb_free(phb, TRUE);
     402        return phb_connected(phb, source);
    388403}
    389404
  • lib/sha1.c

    rba52ac5 r537d9b9  
    2424#define HMAC_BLOCK_SIZE 64
    2525
    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])
     26void b_hmac(GChecksumType checksum_type, const char *key_, size_t key_len,
     27            const char *payload, size_t payload_len, guint8 **digest)
    2828{
    29         sha1_state_t sha1;
    30         guint8 hash[SHA1_HASH_SIZE];
     29        GChecksum *checksum;
     30        size_t hash_len;
     31        guint8 *hash;
    3132        guint8 key[HMAC_BLOCK_SIZE + 1];
    3233        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);
    3342
    3443        if (key_len == 0) {
     
    4352        memset(key, 0, HMAC_BLOCK_SIZE + 1);
    4453        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);
    4858        } else {
    4959                memcpy(key, key_, key_len);
     
    5161
    5262        /* Inner part: H(K XOR 0x36, text) */
    53         sha1_init(&sha1);
     63        checksum = g_checksum_new(checksum_type);
    5464        for (i = 0; i < HMAC_BLOCK_SIZE; i++) {
    5565                key[i] ^= 0x36;
    5666        }
    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);
    6071
    6172        /* Final result: H(K XOR 0x5C, inner stuff) */
    62         sha1_init(&sha1);
     73        checksum = g_checksum_new(checksum_type);
    6374        for (i = 0; i < HMAC_BLOCK_SIZE; i++) {
    6475                key[i] ^= 0x36 ^ 0x5c;
    6576        }
    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);
    6983}
     84
     85void 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
    7090
    7191/* I think this follows the scheme described on:
  • lib/ssl_gnutls.c

    rba52ac5 r537d9b9  
    4242#include <limits.h>
    4343
    44 #if defined(ULONG_MAX) && ULONG_MAX > 4294967295UL
    45 #define GNUTLS_STUPID_CAST (long)
    46 #else
    47 #define GNUTLS_STUPID_CAST (int)
    48 #endif
    49 
    5044#define SSLDEBUG 0
    5145
     
    335329
    336330        sock_make_nonblocking(conn->fd);
    337         gnutls_transport_set_ptr(conn->session, (gnutls_transport_ptr_t) GNUTLS_STUPID_CAST conn->fd);
     331        gnutls_transport_set_ptr(conn->session, (gnutls_transport_ptr_t) (long) conn->fd);
    338332
    339333        ssl_cache_resume(conn);
  • lib/ssl_openssl.c

    rba52ac5 r537d9b9  
    6767        SSL_library_init();
    6868
    69         meth = TLSv1_client_method();
     69        meth = SSLv23_client_method();
    7070        ssl_ctx = SSL_CTX_new(meth);
     71        SSL_CTX_set_options(ssl_ctx, SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3);
    7172
    7273        initialized = TRUE;
Note: See TracChangeset for help on using the changeset viewer.