Ignore:
Timestamp:
2015-05-04T21:58:50Z (9 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Children:
5726a0d
Parents:
531eabd (diff), 5ca1416 (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:

Catch up with master.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • protocols/twitter/twitter.c

    r531eabd rb1dc403  
    852852}
    853853
     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
     869bee_user_t twitter_log_local_user;
     870
    854871/** Convert the given bitlbee tweet ID, bitlbee username, or twitter tweet ID
    855872 *  into a twitter tweet ID.
     
    879896                        arg++;
    880897                }
    881                 if (sscanf(arg, "%" G_GINT64_MODIFIER "x", &id) == 1 &&
    882                     id < TWITTER_LOG_LENGTH) {
     898                if (twitter_parse_id(arg, 16, &id) && id < TWITTER_LOG_LENGTH) {
    883899                        bu = td->log[id].bu;
    884900                        id = td->log[id].id;
    885                         /* Beware of dangling pointers! */
    886                         if (!g_slist_find(ic->bee->users, bu)) {
    887                                 bu = NULL;
    888                         }
    889                 } else if (sscanf(arg, "%" G_GINT64_MODIFIER "d", &id) == 1) {
     901                } else if (twitter_parse_id(arg, 10, &id)) {
    890902                        /* Allow normal tweet IDs as well; not a very useful
    891903                           feature but it's always been there. Just ignore
     
    897909        }
    898910        if (bu_) {
     911                if (bu == &twitter_log_local_user) {
     912                        /* HACK alert. There's no bee_user object for the local
     913                         * user so just fake one for the few cmds that need it. */
     914                        twitter_log_local_user.handle = td->user;
     915                } else {
     916                        /* Beware of dangling pointers! */
     917                        if (!g_slist_find(ic->bee->users, bu)) {
     918                                bu = NULL;
     919                        }
     920                }
    899921                *bu_ = bu;
    900922        }
     
    9891011                in_reply_to = id;
    9901012                allow_post = TRUE;
     1013        } else if (g_strcasecmp(cmd[0], "url") == 0) {
     1014                id = twitter_message_id_from_command_arg(ic, cmd[1], &bu);
     1015                if (!id) {
     1016                        twitter_log(ic, "Tweet `%s' does not exist", cmd[1]);
     1017                } 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);
     1023                }
     1024                goto eof;
     1025
    9911026        } else if (g_strcasecmp(cmd[0], "post") == 0) {
    9921027                message += 5;
Note: See TracChangeset for help on using the changeset viewer.