Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • protocols/twitter/twitter.c

    r1201fcb rc43146d  
    469469        g_regex_match(regex, msg, 0, &match_info);
    470470        while (g_match_info_matches(match_info)) {
    471                 gchar *s, *url;
    472 
    473                 url = g_match_info_fetch(match_info, 2);
     471                gchar *url = g_match_info_fetch(match_info, 2);
    474472                url_len_diff += target_len - g_utf8_strlen(url, -1);
    475 
    476473                /* Add another character for https://t.co/... URLs */
    477                 if ((s = g_match_info_fetch(match_info, 3))) {
     474                if (g_match_info_fetch(match_info, 3) != NULL) {
    478475                        url_len_diff += 1;
    479                         g_free(s);
    480476                }
    481477                g_free(url);
     
    487483}
    488484
    489 int twitter_message_len(gchar *msg, int target_len)
    490 {
     485static gboolean twitter_length_check(struct im_connection *ic, gchar * msg)
     486{
     487        int max = set_getint(&ic->acc->set, "message_length"), len;
     488        int target_len = set_getint(&ic->acc->set, "target_url_length");
    491489        int url_len_diff = 0;
    492490
     
    495493        }
    496494
    497         return g_utf8_strlen(msg, -1) + url_len_diff;
    498 }
    499 
    500 static gboolean twitter_length_check(struct im_connection *ic, gchar * msg)
    501 {
    502         int max = set_getint(&ic->acc->set, "message_length");
    503         int target_len = set_getint(&ic->acc->set, "target_url_length");
    504         int len = twitter_message_len(msg, target_len);
    505 
    506         if (max == 0 || len <= max) {
     495        if (max == 0 || (len = g_utf8_strlen(msg, -1) + url_len_diff) <= max) {
    507496                return TRUE;
    508497        }
     
    863852}
    864853
     854/* Parses a decimal or hex tweet ID, returns TRUE on success */
     855static gboolean twitter_parse_id(char *string, int base, guint64 *id)
     856{
     857        guint64 parsed;
     858        char *endptr;
     859
     860        errno = 0;
     861        parsed = g_ascii_strtoull(string, &endptr, base);
     862        if (errno || endptr == string || *endptr != '\0') {
     863                return FALSE;
     864        }
     865        *id = parsed;
     866        return TRUE;
     867}
     868
    865869bee_user_t twitter_log_local_user;
    866870
     
    892896                        arg++;
    893897                }
    894                 if (parse_int64(arg, 16, &id) && id < TWITTER_LOG_LENGTH) {
     898                if (twitter_parse_id(arg, 16, &id) && id < TWITTER_LOG_LENGTH) {
    895899                        bu = td->log[id].bu;
    896900                        id = td->log[id].id;
    897                 } else if (parse_int64(arg, 10, &id)) {
     901                } else if (twitter_parse_id(arg, 10, &id)) {
    898902                        /* Allow normal tweet IDs as well; not a very useful
    899903                           feature but it's always been there. Just ignore
     
    10121016                        twitter_log(ic, "Tweet `%s' does not exist", cmd[1]);
    10131017                } else {
    1014                         twitter_status_show_url(ic, id);
     1018                        /* More common link is twitter.com/$UID/status/$ID (and that's
     1019                         * what this will 302 to) but can't generate that since for RTs,
     1020                         * bu here points at the retweeter while id contains the id of
     1021                         * the original message. */
     1022                        twitter_log(ic, "https://twitter.com/statuses/%lld", id);
    10151023                }
    10161024                goto eof;
Note: See TracChangeset for help on using the changeset viewer.