source: protocols/twitter/twitter.c @ b61c74c

Last change on this file since b61c74c was b61c74c, checked in by Wilmer van der Gaast <wilmer@…>, at 2012-09-15T16:24:52Z

Merge Twitter favourite command from Flexo/#983. Leaving out the unfavourite
command for reasons given there.

At this point there are loads of command and stuff is getting a little messy
maybe.. :-/

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