source: protocols/twitter/twitter.c @ 62d2cfb

Last change on this file since 62d2cfb was 62d2cfb, checked in by Geert Mulders <g.c.w.m.mulders@…>, at 2010-03-25T21:31:27Z

Added option to get tweeds either through groupchat or privmes.

  • Property mode set to 100644
File size: 6.1 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 "twitter.h"
26#include "twitter_http.h"
27#include "twitter_lib.h"
28
29
30/**
31 * Main loop function
32 */
33gboolean twitter_main_loop(gpointer data, gint fd, b_input_condition cond)
34{
35        struct im_connection *ic = data;
36        // Check if we are still logged in...
37        if ((ic->flags & OPT_LOGGED_IN) != OPT_LOGGED_IN)
38                return 0;
39
40        // If the user uses multiple private message windows we need to get the
41        // users buddies.
42        if (!set_getbool( &ic->acc->set, "use_groupchat" ))
43                twitter_get_statuses_friends(ic, -1);
44
45        // Do stuff..
46        twitter_get_home_timeline(ic, -1);
47
48        // If we are still logged in run this function again after timeout.
49        return (ic->flags & OPT_LOGGED_IN) == OPT_LOGGED_IN;
50}
51
52
53static void twitter_init( account_t *acc )
54{
55        set_t *s;
56        s = set_add( &acc->set, "use_groupchat", "false", set_eval_bool, acc );
57}
58
59/**
60 * Login method. Since the twitter API works with seperate HTTP request we
61 * only save the user and pass to the twitter_data object.
62 */
63static void twitter_login( account_t *acc )
64{
65        struct im_connection *ic = imcb_new( acc );
66        struct twitter_data *td = g_new0( struct twitter_data, 1 );
67
68        td->user = acc->user;
69        td->pass = acc->pass;
70        td->home_timeline_id = 0;
71
72        ic->proto_data = td;
73
74        // Set the status to logged in.
75        ic->flags = OPT_LOGGED_IN;
76
77        // Run this once. After this queue the main loop function.
78        twitter_main_loop(ic, -1, 0);
79
80        // Queue the main_loop
81        b_timeout_add(60000, twitter_main_loop, ic);
82
83        imcb_log( ic, "Connecting to twitter" );
84        imcb_connected(ic);
85
86        twitter_connections = g_slist_append( twitter_connections, ic );
87}
88
89/**
90 * Logout method. Just free the twitter_data.
91 */
92static void twitter_logout( struct im_connection *ic )
93{
94        struct twitter_data *td = ic->proto_data;
95       
96        // Set the status to logged out.
97        ic->flags = 0;
98
99        if( td )
100        {
101                g_free( td );
102        }
103
104        twitter_connections = g_slist_remove( twitter_connections, ic );
105}
106
107/**
108 *
109 */
110static int twitter_buddy_msg( struct im_connection *ic, char *who, char *message, int away )
111{
112        // Let's just update the status.
113//      if ( g_strcasecmp(who, ic->acc->user) == 0 )
114                twitter_post_status(ic, message);
115//      else
116//              twitter_direct_messages_new(ic, who, message);
117        return( 0 );
118}
119
120/**
121 *
122 */
123static GList *twitter_away_states( struct im_connection *ic )
124{
125        static GList *l = NULL;
126        return l;
127}
128
129static void twitter_set_away( struct im_connection *ic, char *state, char *message )
130{
131}
132
133static void twitter_set_my_name( struct im_connection *ic, char *info )
134{
135}
136
137static void twitter_get_info(struct im_connection *ic, char *who) 
138{
139}
140
141static void twitter_add_buddy( struct im_connection *ic, char *who, char *group )
142{
143}
144
145static void twitter_remove_buddy( struct im_connection *ic, char *who, char *group )
146{
147}
148
149static void twitter_chat_msg( struct groupchat *c, char *message, int flags )
150{
151}
152
153static void twitter_chat_invite( struct groupchat *c, char *who, char *message )
154{
155}
156
157static void twitter_chat_leave( struct groupchat *c )
158{
159}
160
161static struct groupchat *twitter_chat_with( struct im_connection *ic, char *who )
162{
163        return NULL;
164}
165
166static void twitter_keepalive( struct im_connection *ic )
167{
168}
169
170static void twitter_add_permit( struct im_connection *ic, char *who )
171{
172}
173
174static void twitter_rem_permit( struct im_connection *ic, char *who )
175{
176}
177
178static void twitter_add_deny( struct im_connection *ic, char *who )
179{
180}
181
182static void twitter_rem_deny( struct im_connection *ic, char *who )
183{
184}
185
186static int twitter_send_typing( struct im_connection *ic, char *who, int typing )
187{
188        return( 1 );
189}
190
191//static char *twitter_set_display_name( set_t *set, char *value )
192//{
193//      return value;
194//}
195
196void twitter_initmodule()
197{
198        struct prpl *ret = g_new0(struct prpl, 1);
199       
200        ret->name = "twitter";
201        ret->login = twitter_login;
202        ret->init = twitter_init;
203        ret->logout = twitter_logout;
204        ret->buddy_msg = twitter_buddy_msg;
205        ret->away_states = twitter_away_states;
206        ret->set_away = twitter_set_away;
207        ret->get_info = twitter_get_info;
208        ret->set_my_name = twitter_set_my_name;
209        ret->add_buddy = twitter_add_buddy;
210        ret->remove_buddy = twitter_remove_buddy;
211        ret->chat_msg = twitter_chat_msg;
212        ret->chat_invite = twitter_chat_invite;
213        ret->chat_leave = twitter_chat_leave;
214        ret->chat_with = twitter_chat_with;
215        ret->keepalive = twitter_keepalive;
216        ret->add_permit = twitter_add_permit;
217        ret->rem_permit = twitter_rem_permit;
218        ret->add_deny = twitter_add_deny;
219        ret->rem_deny = twitter_rem_deny;
220        ret->send_typing = twitter_send_typing;
221        ret->handle_cmp = g_strcasecmp;
222
223        register_protocol(ret);
224
225        // Initialise the twitter_connections GSList.
226        twitter_connections = NULL;
227}
228
Note: See TracBrowser for help on using the repository browser.