source: protocols/twitter/twitter.c @ 2fb1262

Last change on this file since 2fb1262 was 1388d30, checked in by Wilmer van der Gaast <wilmer@…>, at 2012-11-11T17:57:20Z

Mostly finished HTTP streaming support: Shrink the buffer and add a
http_close().

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