Changes in protocols/twitter/twitter.c [1201fcb:c43146d]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/twitter/twitter.c
r1201fcb rc43146d 469 469 g_regex_match(regex, msg, 0, &match_info); 470 470 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); 474 472 url_len_diff += target_len - g_utf8_strlen(url, -1); 475 476 473 /* 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) { 478 475 url_len_diff += 1; 479 g_free(s);480 476 } 481 477 g_free(url); … … 487 483 } 488 484 489 int twitter_message_len(gchar *msg, int target_len) 490 { 485 static 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"); 491 489 int url_len_diff = 0; 492 490 … … 495 493 } 496 494 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) { 507 496 return TRUE; 508 497 } … … 863 852 } 864 853 854 /* Parses a decimal or hex tweet ID, returns TRUE on success */ 855 static 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 865 869 bee_user_t twitter_log_local_user; 866 870 … … 892 896 arg++; 893 897 } 894 if ( parse_int64(arg, 16, &id) && id < TWITTER_LOG_LENGTH) {898 if (twitter_parse_id(arg, 16, &id) && id < TWITTER_LOG_LENGTH) { 895 899 bu = td->log[id].bu; 896 900 id = td->log[id].id; 897 } else if ( parse_int64(arg, 10, &id)) {901 } else if (twitter_parse_id(arg, 10, &id)) { 898 902 /* Allow normal tweet IDs as well; not a very useful 899 903 feature but it's always been there. Just ignore … … 1012 1016 twitter_log(ic, "Tweet `%s' does not exist", cmd[1]); 1013 1017 } 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); 1015 1023 } 1016 1024 goto eof;
Note: See TracChangeset
for help on using the changeset viewer.