source: protocols/twitter/twitter.c @ 1b221e0

Last change on this file since 1b221e0 was 1b221e0, checked in by Geert Mulders <g.c.w.m.mulders@…>, at 2009-12-01T21:08:02Z

Added twitter-module.

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