Changeset b75671d for protocols/twitter


Ignore:
Timestamp:
2015-06-17T22:47:26Z (9 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Children:
b441614
Parents:
d832164 (diff), 2f99f23 (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 remote-tracking branch 'origin/master' into parson

Location:
protocols/twitter
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • protocols/twitter/twitter.c

    rd832164 rb75671d  
    469469        g_regex_match(regex, msg, 0, &match_info);
    470470        while (g_match_info_matches(match_info)) {
    471                 gchar *url = g_match_info_fetch(match_info, 2);
     471                gchar *s, *url;
     472
     473                url = g_match_info_fetch(match_info, 2);
    472474                url_len_diff += target_len - g_utf8_strlen(url, -1);
     475
    473476                /* Add another character for https://t.co/... URLs */
    474                 if (g_match_info_fetch(match_info, 3) != NULL) {
     477                if ((s = g_match_info_fetch(match_info, 3))) {
    475478                        url_len_diff += 1;
     479                        g_free(s);
    476480                }
    477481                g_free(url);
     
    483487}
    484488
    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");
     489int twitter_message_len(gchar *msg, int target_len)
     490{
    489491        int url_len_diff = 0;
    490492
     
    493495        }
    494496
    495         if (max == 0 || (len = g_utf8_strlen(msg, -1) + url_len_diff) <= max) {
     497        return g_utf8_strlen(msg, -1) + url_len_diff;
     498}
     499
     500static 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) {
    496507                return TRUE;
    497508        }
     
    852863}
    853864
    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 
    869865bee_user_t twitter_log_local_user;
    870866
     
    896892                        arg++;
    897893                }
    898                 if (twitter_parse_id(arg, 16, &id) && id < TWITTER_LOG_LENGTH) {
     894                if (parse_int64(arg, 16, &id) && id < TWITTER_LOG_LENGTH) {
    899895                        bu = td->log[id].bu;
    900896                        id = td->log[id].id;
    901                 } else if (twitter_parse_id(arg, 10, &id)) {
     897                } else if (parse_int64(arg, 10, &id)) {
    902898                        /* Allow normal tweet IDs as well; not a very useful
    903899                           feature but it's always been there. Just ignore
     
    10161012                        twitter_log(ic, "Tweet `%s' does not exist", cmd[1]);
    10171013                } else {
    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);
     1014                        twitter_status_show_url(ic, id);
    10231015                }
    10241016                goto eof;
  • protocols/twitter/twitter_lib.c

    rd832164 rb75671d  
    15781578        g_free(args[1]);
    15791579}
     1580
     1581static void twitter_http_status_show_url(struct http_request *req)
     1582{
     1583        struct im_connection *ic = req->data;
     1584        json_value *parsed, *id;
     1585        const char *name;
     1586
     1587        // Check if the connection is still active.
     1588        if (!g_slist_find(twitter_connections, ic)) {
     1589                return;
     1590        }
     1591
     1592        if (!(parsed = twitter_parse_response(ic, req))) {
     1593                return;
     1594        }
     1595
     1596        /* for the parson branch:
     1597        name = json_object_dotget_string(json_object(parsed), "user.screen_name");
     1598        id = json_object_get_integer(json_object(parsed), "id");
     1599        */
     1600
     1601        name = json_o_str(json_o_get(parsed, "user"), "screen_name");
     1602        id = json_o_get(parsed, "id");
     1603
     1604        if (name && id && id->type == json_integer) {
     1605                twitter_log(ic, "https://twitter.com/%s/status/%" G_GUINT64_FORMAT, name, id->u.integer);
     1606        } else {
     1607                twitter_log(ic, "Error: could not fetch tweet url.");
     1608        }
     1609
     1610        json_value_free(parsed);
     1611}
     1612
     1613void twitter_status_show_url(struct im_connection *ic, guint64 id)
     1614{
     1615        char *url = g_strdup_printf("%s%" G_GUINT64_FORMAT "%s", TWITTER_STATUS_SHOW_URL, id, ".json");
     1616        twitter_http(ic, url, twitter_http_status_show_url, ic, 0, NULL, 0);
     1617        g_free(url);
     1618}
  • protocols/twitter/twitter_lib.h

    rd832164 rb75671d  
    9696void twitter_report_spam(struct im_connection *ic, char *screen_name);
    9797void twitter_favourite_tweet(struct im_connection *ic, guint64 id);
     98void twitter_status_show_url(struct im_connection *ic, guint64 id);
    9899
    99100#endif //_TWITTER_LIB_H
Note: See TracChangeset for help on using the changeset viewer.