source: protocols/twitter/twitter.c @ c751e51

Last change on this file since c751e51 was e132b60, checked in by Wilmer van der Gaast <wilmer@…>, at 2012-11-11T23:32:47Z

Extend keepalive code to time out connections when pings don't get
acknowledged, using this for Twitter streams and MSN so far.

  • Property mode set to 100644
File size: 20.2 KB
Line 
1/***************************************************************************\
2*                                                                           *
3*  BitlBee - An IRC to IM gateway                                           *
4*  Simple module to facilitate twitter functionality.                       *
5*                                                                           *
6*  Copyright 2009 Geert Mulders <g.c.w.m.mulders@gmail.com>                 *
7*  Copyright 2010-2012 Wilmer van der Gaast <wilmer@gaast.net>              *
8*                                                                           *
9*  This library is free software; you can redistribute it and/or            *
10*  modify it under the terms of the GNU Lesser General Public               *
11*  License as published by the Free Software Foundation, version            *
12*  2.1.                                                                     *
13*                                                                           *
14*  This library is distributed in the hope that it will be useful,          *
15*  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
16*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU        *
17*  Lesser General Public License for more details.                          *
18*                                                                           *
19*  You should have received a copy of the GNU Lesser General Public License *
20*  along with this library; if not, write to the Free Software Foundation,  *
21*  Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA           *
22*                                                                           *
23****************************************************************************/
24
25#include "nogaim.h"
26#include "oauth.h"
27#include "twitter.h"
28#include "twitter_http.h"
29#include "twitter_lib.h"
30#include "url.h"
31
32#define twitter_msg( ic, fmt... ) \
33        do {                                            \
34                struct twitter_data *td = ic->proto_data;   \
35                if( td->timeline_gc )                       \
36                        imcb_chat_log( td->timeline_gc, fmt );  \
37                else                                        \
38                        imcb_log( ic, fmt );                    \
39        } while( 0 );
40
41GSList *twitter_connections = NULL;
42
43/**
44 * Main loop function
45 */
46gboolean twitter_main_loop(gpointer data, gint fd, b_input_condition cond)
47{
48        struct im_connection *ic = data;
49
50        // Check if we are still logged in...
51        if (!g_slist_find(twitter_connections, ic))
52                return 0;
53
54        // Do stuff..
55        twitter_get_timeline(ic, -1);
56
57        // If we are still logged in run this function again after timeout.
58        return (ic->flags & OPT_LOGGED_IN) == OPT_LOGGED_IN;
59}
60
61static void twitter_main_loop_start(struct im_connection *ic)
62{
63        struct twitter_data *td = ic->proto_data;
64
65        imcb_log(ic, "Getting initial statuses");
66
67        // Run this once. After this queue the main loop function.
68        twitter_main_loop(ic, -1, 0);
69       
70        if (set_getbool(&ic->acc->set, "stream")) {
71                /* That fetch was just to get backlog, the stream will give
72                   us the rest. \o/ */
73                twitter_open_stream(ic);
74                ic->flags |= OPT_PONGS;
75        } else {
76                /* Not using the streaming API, so keep polling the old-
77                   fashioned way. :-( */
78                td->main_loop_id =
79                    b_timeout_add(set_getint(&ic->acc->set, "fetch_interval") * 1000,
80                                  twitter_main_loop, ic);
81        }
82}
83
84static void twitter_oauth_start(struct im_connection *ic);
85
86void twitter_login_finish(struct im_connection *ic)
87{
88        struct twitter_data *td = ic->proto_data;
89
90        td->flags &= ~TWITTER_DOING_TIMELINE;
91
92        if (set_getbool(&ic->acc->set, "oauth") && !td->oauth_info)
93                twitter_oauth_start(ic);
94        else if (g_strcasecmp(set_getstr(&ic->acc->set, "mode"), "one") != 0 &&
95                 !(td->flags & TWITTER_HAVE_FRIENDS)) {
96                imcb_log(ic, "Getting contact list");
97                twitter_get_friends_ids(ic, -1);
98                //twitter_get_statuses_friends(ic, -1);
99        } else
100                twitter_main_loop_start(ic);
101}
102
103static const struct oauth_service twitter_oauth = {
104        "https://api.twitter.com/oauth/request_token",
105        "https://api.twitter.com/oauth/access_token",
106        "https://api.twitter.com/oauth/authorize",
107        .consumer_key = "xsDNKJuNZYkZyMcu914uEA",
108        .consumer_secret = "FCxqcr0pXKzsF9ajmP57S3VQ8V6Drk4o2QYtqMcOszo",
109};
110
111static const struct oauth_service identica_oauth = {
112        "https://identi.ca/api/oauth/request_token",
113        "https://identi.ca/api/oauth/access_token",
114        "https://identi.ca/api/oauth/authorize",
115        .consumer_key = "e147ff789fcbd8a5a07963afbb43f9da",
116        .consumer_secret = "c596267f277457ec0ce1ab7bb788d828",
117};
118
119static gboolean twitter_oauth_callback(struct oauth_info *info);
120
121static const struct oauth_service *get_oauth_service(struct im_connection *ic)
122{
123        struct twitter_data *td = ic->proto_data;
124
125        if (strstr(td->url_host, "identi.ca"))
126                return &identica_oauth;
127        else
128                return &twitter_oauth;
129
130        /* Could add more services, or allow configuring your own base URL +
131           API keys. */
132}
133
134static void twitter_oauth_start(struct im_connection *ic)
135{
136        struct twitter_data *td = ic->proto_data;
137
138        imcb_log(ic, "Requesting OAuth request token");
139
140        td->oauth_info = oauth_request_token(get_oauth_service(ic), twitter_oauth_callback, ic);
141
142        /* We need help from the user to complete OAuth login, so don't time
143           out on this login. */
144        ic->flags |= OPT_SLOW_LOGIN;
145}
146
147static gboolean twitter_oauth_callback(struct oauth_info *info)
148{
149        struct im_connection *ic = info->data;
150        struct twitter_data *td;
151
152        if (!g_slist_find(twitter_connections, ic))
153                return FALSE;
154
155        td = ic->proto_data;
156        if (info->stage == OAUTH_REQUEST_TOKEN) {
157                char name[strlen(ic->acc->user) + 9], *msg;
158
159                if (info->request_token == NULL) {
160                        imcb_error(ic, "OAuth error: %s", twitter_parse_error(info->http));
161                        imc_logout(ic, TRUE);
162                        return FALSE;
163                }
164
165                sprintf(name, "%s_%s", td->prefix, ic->acc->user);
166                msg = g_strdup_printf("To finish OAuth authentication, please visit "
167                                      "%s and respond with the resulting PIN code.",
168                                      info->auth_url);
169                imcb_buddy_msg(ic, name, msg, 0, 0);
170                g_free(msg);
171        } else if (info->stage == OAUTH_ACCESS_TOKEN) {
172                if (info->token == NULL || info->token_secret == NULL) {
173                        imcb_error(ic, "OAuth error: %s", twitter_parse_error(info->http));
174                        imc_logout(ic, TRUE);
175                        return FALSE;
176                } else {
177                        const char *sn = oauth_params_get(&info->params, "screen_name");
178
179                        if (sn != NULL && ic->acc->prpl->handle_cmp(sn, ic->acc->user) != 0) {
180                                imcb_log(ic, "Warning: You logged in via OAuth as %s "
181                                         "instead of %s.", sn, ic->acc->user);
182                        }
183                        g_free(td->user);
184                        td->user = g_strdup(sn);
185                }
186
187                /* IM mods didn't do this so far and it's ugly but I should
188                   be able to get away with it... */
189                g_free(ic->acc->pass);
190                ic->acc->pass = oauth_to_string(info);
191
192                twitter_login_finish(ic);
193        }
194
195        return TRUE;
196}
197
198
199static char *set_eval_mode(set_t * set, char *value)
200{
201        if (g_strcasecmp(value, "one") == 0 ||
202            g_strcasecmp(value, "many") == 0 || g_strcasecmp(value, "chat") == 0)
203                return value;
204        else
205                return NULL;
206}
207
208int twitter_url_len_diff(gchar *msg, unsigned int target_len)
209{
210        int url_len_diff = 0;
211
212        static GRegex *regex = NULL;
213        GMatchInfo *match_info;
214
215        if (regex == NULL)
216                regex = g_regex_new("(^|\\s)(http(s)?://[^\\s$]+)", 0, 0, NULL);
217       
218        g_regex_match(regex, msg, 0, &match_info);
219        while (g_match_info_matches(match_info)) {
220                gchar *url = g_match_info_fetch(match_info, 2);
221                url_len_diff += target_len - g_utf8_strlen(url, -1);
222                if (g_match_info_fetch(match_info, 3) != NULL)
223                        url_len_diff += 1;
224                g_free(url);
225                g_match_info_next(match_info, NULL);
226        }
227        g_match_info_free(match_info);
228
229        return url_len_diff;
230}
231
232static gboolean twitter_length_check(struct im_connection *ic, gchar * msg)
233{
234        int max = set_getint(&ic->acc->set, "message_length"), len;
235        int target_len = set_getint(&ic->acc->set, "target_url_length");
236        int url_len_diff = 0;
237   
238        if (target_len > 0)
239                url_len_diff = twitter_url_len_diff(msg, target_len);
240
241        if (max == 0 || (len = g_utf8_strlen(msg, -1) + url_len_diff) <= max)
242                return TRUE;
243
244        imcb_error(ic, "Maximum message length exceeded: %d > %d", len, max);
245
246        return FALSE;
247}
248
249static void twitter_init(account_t * acc)
250{
251        set_t *s;
252        char *def_url;
253        char *def_tul;
254
255        if (strcmp(acc->prpl->name, "twitter") == 0) {
256                def_url = TWITTER_API_URL;
257                def_tul = "20";
258        } else {                /* if( strcmp( acc->prpl->name, "identica" ) == 0 ) */
259                def_url = IDENTICA_API_URL;
260                def_tul = "0";
261        }
262
263        s = set_add(&acc->set, "auto_reply_timeout", "10800", set_eval_int, acc);
264
265        s = set_add(&acc->set, "base_url", def_url, NULL, acc);
266        s->flags |= ACC_SET_OFFLINE_ONLY;
267
268        s = set_add(&acc->set, "commands", "true", set_eval_bool, acc);
269
270        s = set_add(&acc->set, "fetch_interval", "60", set_eval_int, acc);
271        s->flags |= ACC_SET_OFFLINE_ONLY;
272
273        s = set_add(&acc->set, "fetch_mentions", "true", set_eval_bool, acc);
274
275        s = set_add(&acc->set, "message_length", "140", set_eval_int, acc);
276
277        s = set_add(&acc->set, "target_url_length", def_tul, set_eval_int, acc);
278
279        s = set_add(&acc->set, "mode", "chat", set_eval_mode, acc);
280        s->flags |= ACC_SET_OFFLINE_ONLY;
281
282        s = set_add(&acc->set, "oauth", "true", set_eval_oauth, acc);
283
284        s = set_add(&acc->set, "show_ids", "true", set_eval_bool, acc);
285        s->flags |= ACC_SET_OFFLINE_ONLY;
286
287        s = set_add(&acc->set, "show_old_mentions", "20", set_eval_int, acc);
288
289        s = set_add(&acc->set, "strip_newlines", "false", set_eval_bool, acc);
290       
291        s = set_add(&acc->set, "stream", "true", set_eval_bool, acc);
292        s->flags |= ACC_SET_OFFLINE_ONLY;
293}
294
295/**
296 * Login method. Since the twitter API works with seperate HTTP request we
297 * only save the user and pass to the twitter_data object.
298 */
299static void twitter_login(account_t * acc)
300{
301        struct im_connection *ic = imcb_new(acc);
302        struct twitter_data *td;
303        char name[strlen(acc->user) + 9];
304        url_t url;
305        char *s;
306       
307        if (!url_set(&url, set_getstr(&ic->acc->set, "base_url")) ||
308            (url.proto != PROTO_HTTP && url.proto != PROTO_HTTPS)) {
309                imcb_error(ic, "Incorrect API base URL: %s", set_getstr(&ic->acc->set, "base_url"));
310                imc_logout(ic, FALSE);
311                return;
312        }
313
314        imcb_log(ic, "Connecting");
315
316        twitter_connections = g_slist_append(twitter_connections, ic);
317        td = g_new0(struct twitter_data, 1);
318        ic->proto_data = td;
319        td->user = g_strdup(acc->user);
320
321        td->url_ssl = url.proto == PROTO_HTTPS;
322        td->url_port = url.port;
323        td->url_host = g_strdup(url.host);
324        if (strcmp(url.file, "/") != 0)
325                td->url_path = g_strdup(url.file);
326        else {
327                td->url_path = g_strdup("");
328                if (g_str_has_suffix(url.host, "twitter.com"))
329                        /* May fire for people who turned on HTTPS. */
330                        imcb_error(ic, "Warning: Twitter requires a version number in API calls "
331                                       "now. Try resetting the base_url account setting.");
332        }
333       
334        /* Hacky string mangling: Turn identi.ca into identi.ca and api.twitter.com
335           into twitter, and try to be sensible if we get anything else. */
336        td->prefix = g_strdup(url.host);
337        if (g_str_has_suffix(td->prefix, ".com"))
338                td->prefix[strlen(url.host) - 4] = '\0';
339        if ((s = strrchr(td->prefix, '.')) && strlen(s) > 4) {
340                /* If we have at least 3 chars after the last dot, cut off the rest.
341                   (mostly a www/api prefix or sth) */
342                s = g_strdup(s + 1);
343                g_free(td->prefix);
344                td->prefix = s;
345        }
346       
347        if (strstr(acc->pass, "oauth_token="))
348                td->oauth_info = oauth_from_string(acc->pass, get_oauth_service(ic));
349
350        sprintf(name, "%s_%s", td->prefix, acc->user);
351        imcb_add_buddy(ic, name, NULL);
352        imcb_buddy_status(ic, name, OPT_LOGGED_IN, NULL, NULL);
353
354        if (set_getbool(&acc->set, "show_ids"))
355                td->log = g_new0(struct twitter_log_data, TWITTER_LOG_LENGTH);
356
357        twitter_login_finish(ic);
358}
359
360/**
361 * Logout method. Just free the twitter_data.
362 */
363static void twitter_logout(struct im_connection *ic)
364{
365        struct twitter_data *td = ic->proto_data;
366
367        // Set the status to logged out.
368        ic->flags &= ~OPT_LOGGED_IN;
369
370        // Remove the main_loop function from the function queue.
371        b_event_remove(td->main_loop_id);
372
373        if (td->timeline_gc)
374                imcb_chat_free(td->timeline_gc);
375
376        if (td) {
377                http_close(td->stream);
378                oauth_info_free(td->oauth_info);
379                g_free(td->user);
380                g_free(td->prefix);
381                g_free(td->url_host);
382                g_free(td->url_path);
383                g_free(td->log);
384                g_free(td);
385        }
386
387        twitter_connections = g_slist_remove(twitter_connections, ic);
388}
389
390static void twitter_handle_command(struct im_connection *ic, char *message);
391
392/**
393 *
394 */
395static int twitter_buddy_msg(struct im_connection *ic, char *who, char *message, int away)
396{
397        struct twitter_data *td = ic->proto_data;
398        int plen = strlen(td->prefix);
399
400        if (g_strncasecmp(who, td->prefix, plen) == 0 && who[plen] == '_' &&
401            g_strcasecmp(who + plen + 1, ic->acc->user) == 0) {
402                if (set_getbool(&ic->acc->set, "oauth") &&
403                    td->oauth_info && td->oauth_info->token == NULL) {
404                        char pin[strlen(message) + 1], *s;
405
406                        strcpy(pin, message);
407                        for (s = pin + sizeof(pin) - 2; s > pin && isspace(*s); s--)
408                                *s = '\0';
409                        for (s = pin; *s && isspace(*s); s++) {
410                        }
411
412                        if (!oauth_access_token(s, td->oauth_info)) {
413                                imcb_error(ic, "OAuth error: %s",
414                                           "Failed to send access token request");
415                                imc_logout(ic, TRUE);
416                                return FALSE;
417                        }
418                } else
419                        twitter_handle_command(ic, message);
420        } else {
421                twitter_direct_messages_new(ic, who, message);
422        }
423        return (0);
424}
425
426/**
427 *
428 */
429static void twitter_set_my_name(struct im_connection *ic, char *info)
430{
431}
432
433static void twitter_get_info(struct im_connection *ic, char *who)
434{
435}
436
437static void twitter_add_buddy(struct im_connection *ic, char *who, char *group)
438{
439        twitter_friendships_create_destroy(ic, who, 1);
440}
441
442static void twitter_remove_buddy(struct im_connection *ic, char *who, char *group)
443{
444        twitter_friendships_create_destroy(ic, who, 0);
445}
446
447static void twitter_chat_msg(struct groupchat *c, char *message, int flags)
448{
449        if (c && message)
450                twitter_handle_command(c->ic, message);
451}
452
453static void twitter_chat_invite(struct groupchat *c, char *who, char *message)
454{
455}
456
457static void twitter_chat_leave(struct groupchat *c)
458{
459        struct twitter_data *td = c->ic->proto_data;
460
461        if (c != td->timeline_gc)
462                return;         /* WTF? */
463
464        /* If the user leaves the channel: Fine. Rejoin him/her once new
465           tweets come in. */
466        imcb_chat_free(td->timeline_gc);
467        td->timeline_gc = NULL;
468}
469
470static void twitter_keepalive(struct im_connection *ic)
471{
472}
473
474static void twitter_add_permit(struct im_connection *ic, char *who)
475{
476}
477
478static void twitter_rem_permit(struct im_connection *ic, char *who)
479{
480}
481
482static void twitter_add_deny(struct im_connection *ic, char *who)
483{
484}
485
486static void twitter_rem_deny(struct im_connection *ic, char *who)
487{
488}
489
490//static char *twitter_set_display_name( set_t *set, char *value )
491//{
492//      return value;
493//}
494
495static void twitter_buddy_data_add(struct bee_user *bu)
496{
497        bu->data = g_new0(struct twitter_user_data, 1);
498}
499
500static void twitter_buddy_data_free(struct bee_user *bu)
501{
502        g_free(bu->data);
503}
504
505/** Convert the given bitlbee tweet ID, bitlbee username, or twitter tweet ID
506 *  into a twitter tweet ID.
507 *
508 *  Returns 0 if the user provides garbage.
509 */
510static guint64 twitter_message_id_from_command_arg(struct im_connection *ic, struct twitter_data *td, char *arg) {
511        struct twitter_user_data *tud;
512        bee_user_t *bu;
513        guint64 id = 0;
514        if (g_str_has_prefix(arg, "#") &&
515                sscanf(arg + 1, "%" G_GUINT64_FORMAT, &id) == 1) {
516                if (id < TWITTER_LOG_LENGTH && td->log)
517                        id = td->log[id].id;
518        } else if ((bu = bee_user_by_handle(ic->bee, ic, arg)) &&
519                (tud = bu->data) && tud->last_id)
520                id = tud->last_id;
521        else if (sscanf(arg, "%" G_GUINT64_FORMAT, &id) == 1){
522                if (id < TWITTER_LOG_LENGTH && td->log)
523                        id = td->log[id].id;
524        }
525        return id;
526}
527
528static void twitter_handle_command(struct im_connection *ic, char *message)
529{
530        struct twitter_data *td = ic->proto_data;
531        char *cmds, **cmd, *new = NULL;
532        guint64 in_reply_to = 0;
533
534        cmds = g_strdup(message);
535        cmd = split_command_parts(cmds);
536
537        if (cmd[0] == NULL) {
538                g_free(cmds);
539                return;
540        } else if (!set_getbool(&ic->acc->set, "commands")) {
541                /* Not supporting commands. */
542        } else if (g_strcasecmp(cmd[0], "undo") == 0) {
543                guint64 id;
544
545                if (cmd[1] == NULL)
546                        twitter_status_destroy(ic, td->last_status_id);
547                else if (sscanf(cmd[1], "%" G_GUINT64_FORMAT, &id) == 1) {
548                        if (id < TWITTER_LOG_LENGTH && td->log)
549                                id = td->log[id].id;
550                       
551                        twitter_status_destroy(ic, id);
552                } else
553                        twitter_msg(ic, "Could not undo last action");
554
555                g_free(cmds);
556                return;
557        } else if (g_strcasecmp(cmd[0], "favourite") == 0 && cmd[1]) {
558                guint64 id;
559                if ((id = twitter_message_id_from_command_arg(ic, td, cmd[1]))) {
560                        twitter_favourite_tweet(ic, id);
561                } else {
562                        twitter_msg(ic, "Please provide a message ID or username.");
563                }
564                g_free(cmds);
565                return;
566        } else if (g_strcasecmp(cmd[0], "follow") == 0 && cmd[1]) {
567                twitter_add_buddy(ic, cmd[1], NULL);
568                g_free(cmds);
569                return;
570        } else if (g_strcasecmp(cmd[0], "unfollow") == 0 && cmd[1]) {
571                twitter_remove_buddy(ic, cmd[1], NULL);
572                g_free(cmds);
573                return;
574        } else if ((g_strcasecmp(cmd[0], "report") == 0 ||
575                    g_strcasecmp(cmd[0], "spam") == 0) && cmd[1]) {
576                char * screen_name;
577                guint64 id;
578                screen_name = cmd[1];
579                /* Report nominally works on users but look up the user who
580                   posted the given ID if the user wants to do it that way */
581                if (g_str_has_prefix(cmd[1], "#") &&
582                    sscanf(cmd[1] + 1, "%" G_GUINT64_FORMAT, &id) == 1) {
583                        if (id < TWITTER_LOG_LENGTH && td->log) {
584                                if (g_slist_find(ic->bee->users, td->log[id].bu)) {
585                                        screen_name = td->log[id].bu->handle;
586                                }
587                        }
588                }
589                twitter_report_spam(ic, screen_name);
590                g_free(cmds);
591                return;
592        } else if (g_strcasecmp(cmd[0], "rt") == 0 && cmd[1]) {
593                guint64 id = twitter_message_id_from_command_arg(ic, td, cmd[1]);
594
595                td->last_status_id = 0;
596                if (id)
597                        twitter_status_retweet(ic, id);
598                else
599                        twitter_msg(ic, "User `%s' does not exist or didn't "
600                                    "post any statuses recently", cmd[1]);
601
602                g_free(cmds);
603                return;
604        } else if (g_strcasecmp(cmd[0], "reply") == 0 && cmd[1] && cmd[2]) {
605                struct twitter_user_data *tud;
606                bee_user_t *bu = NULL;
607                guint64 id = 0;
608
609                if (g_str_has_prefix(cmd[1], "#") &&
610                    sscanf(cmd[1] + 1, "%" G_GUINT64_FORMAT, &id) == 1 &&
611                    (id < TWITTER_LOG_LENGTH) && td->log) {
612                        bu = td->log[id].bu;
613                        if (g_slist_find(ic->bee->users, bu))
614                                id = td->log[id].id;
615                        else
616                                bu = NULL;
617                } else if ((bu = bee_user_by_handle(ic->bee, ic, cmd[1])) &&
618                    (tud = bu->data) && tud->last_id) {
619                        id = tud->last_id;
620                } else if (sscanf(cmd[1], "%" G_GUINT64_FORMAT, &id) == 1 &&
621                           (id < TWITTER_LOG_LENGTH) && td->log) {
622                        bu = td->log[id].bu;
623                        if (g_slist_find(ic->bee->users, bu))
624                                id = td->log[id].id;
625                        else
626                                bu = NULL;
627                }
628
629                if (!id || !bu) {
630                        twitter_msg(ic, "User `%s' does not exist or didn't "
631                                    "post any statuses recently", cmd[1]);
632                        g_free(cmds);
633                        return;
634                }
635                message = new = g_strdup_printf("@%s %s", bu->handle, message + (cmd[2] - cmd[0]));
636                in_reply_to = id;
637        } else if (g_strcasecmp(cmd[0], "post") == 0) {
638                message += 5;
639        }
640
641        {
642                char *s;
643                bee_user_t *bu;
644
645                if (!twitter_length_check(ic, message)) {
646                        g_free(new);
647                        g_free(cmds);
648                        return;
649                }
650
651                s = cmd[0] + strlen(cmd[0]) - 1;
652                if (!new && s > cmd[0] && (*s == ':' || *s == ',')) {
653                        *s = '\0';
654
655                        if ((bu = bee_user_by_handle(ic->bee, ic, cmd[0]))) {
656                                struct twitter_user_data *tud = bu->data;
657
658                                new = g_strdup_printf("@%s %s", bu->handle,
659                                                      message + (s - cmd[0]) + 2);
660                                message = new;
661
662                                if (time(NULL) < tud->last_time +
663                                    set_getint(&ic->acc->set, "auto_reply_timeout"))
664                                        in_reply_to = tud->last_id;
665                        }
666                }
667
668                /* If the user runs undo between this request and its response
669                   this would delete the second-last Tweet. Prevent that. */
670                td->last_status_id = 0;
671                twitter_post_status(ic, message, in_reply_to);
672                g_free(new);
673        }
674        g_free(cmds);
675}
676
677void twitter_initmodule()
678{
679        struct prpl *ret = g_new0(struct prpl, 1);
680
681        ret->options = OPT_NOOTR;
682        ret->name = "twitter";
683        ret->login = twitter_login;
684        ret->init = twitter_init;
685        ret->logout = twitter_logout;
686        ret->buddy_msg = twitter_buddy_msg;
687        ret->get_info = twitter_get_info;
688        ret->set_my_name = twitter_set_my_name;
689        ret->add_buddy = twitter_add_buddy;
690        ret->remove_buddy = twitter_remove_buddy;
691        ret->chat_msg = twitter_chat_msg;
692        ret->chat_invite = twitter_chat_invite;
693        ret->chat_leave = twitter_chat_leave;
694        ret->keepalive = twitter_keepalive;
695        ret->add_permit = twitter_add_permit;
696        ret->rem_permit = twitter_rem_permit;
697        ret->add_deny = twitter_add_deny;
698        ret->rem_deny = twitter_rem_deny;
699        ret->buddy_data_add = twitter_buddy_data_add;
700        ret->buddy_data_free = twitter_buddy_data_free;
701        ret->handle_cmp = g_strcasecmp;
702
703        register_protocol(ret);
704
705        /* And an identi.ca variant: */
706        ret = g_memdup(ret, sizeof(struct prpl));
707        ret->name = "identica";
708        register_protocol(ret);
709}
Note: See TracBrowser for help on using the repository browser.