source: protocols/purple/purple.c @ 796da03

Last change on this file since 796da03 was 796da03, checked in by Wilmer van der Gaast <wilmer@…>, at 2009-10-04T23:28:11Z

Something that compiles and runs, but otherwise utterly useless. Added a
protocols/purple/ module and included it in the build system. Already picks
up all the supported protocols and adds them individually.

  • Property mode set to 100644
File size: 6.9 KB
Line 
1/***************************************************************************\
2*                                                                           *
3*  BitlBee - An IRC to IM gateway                                           *
4*  libpurple module - Main file                                             *
5*                                                                           *
6*  Copyright 2009 Wilmer van der Gaast <wilmer@gaast.net>                   *
7*                                                                           *
8*  This program is free software; you can redistribute it and/or modify     *
9*  it under the terms of the GNU General Public License as published by     *
10*  the Free Software Foundation; either version 2 of the License, or        *
11*  (at your option) any later version.                                      *
12*                                                                           *
13*  This program 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            *
16*  GNU General Public License for more details.                             *
17*                                                                           *
18*  You should have received a copy of the GNU General Public License along  *
19*  with this program; if not, write to the Free Software Foundation, Inc.,  *
20*  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.              *
21*                                                                           *
22\***************************************************************************/
23
24#include <glib.h>
25#include <purple.h>
26
27#include "bitlbee.h"
28
29GSList *purple_connections;
30
31#undef g_io_add_watch
32#undef g_io_add_watch_full
33#undef g_timeout_add
34#undef g_source_remove
35
36/**
37 * The following eventloop functions are used in both pidgin and purple-text. If your
38 * application uses glib mainloop, you can safely use this verbatim.
39 */
40#define PURPLE_GLIB_READ_COND  (G_IO_IN | G_IO_HUP | G_IO_ERR)
41#define PURPLE_GLIB_WRITE_COND (G_IO_OUT | G_IO_HUP | G_IO_ERR | G_IO_NVAL)
42
43typedef struct _PurpleGLibIOClosure {
44        PurpleInputFunction function;
45        guint result;
46        gpointer data;
47} PurpleGLibIOClosure;
48
49static void purple_glib_io_destroy(gpointer data)
50{
51        g_free(data);
52}
53
54static gboolean purple_glib_io_invoke(GIOChannel *source, GIOCondition condition, gpointer data)
55{
56        PurpleGLibIOClosure *closure = data;
57        PurpleInputCondition purple_cond = 0;
58
59        if (condition & PURPLE_GLIB_READ_COND)
60                purple_cond |= PURPLE_INPUT_READ;
61        if (condition & PURPLE_GLIB_WRITE_COND)
62                purple_cond |= PURPLE_INPUT_WRITE;
63
64        closure->function(closure->data, g_io_channel_unix_get_fd(source),
65                          purple_cond);
66
67        return TRUE;
68}
69
70static guint glib_input_add(gint fd, PurpleInputCondition condition, PurpleInputFunction function,
71                                                           gpointer data)
72{
73        PurpleGLibIOClosure *closure = g_new0(PurpleGLibIOClosure, 1);
74        GIOChannel *channel;
75        GIOCondition cond = 0;
76
77        closure->function = function;
78        closure->data = data;
79
80        if (condition & PURPLE_INPUT_READ)
81                cond |= PURPLE_GLIB_READ_COND;
82        if (condition & PURPLE_INPUT_WRITE)
83                cond |= PURPLE_GLIB_WRITE_COND;
84
85        channel = g_io_channel_unix_new(fd);
86        closure->result = g_io_add_watch_full(channel, G_PRIORITY_DEFAULT, cond,
87                                              purple_glib_io_invoke, closure, purple_glib_io_destroy);
88
89        g_io_channel_unref(channel);
90        return closure->result;
91}
92
93static PurpleEventLoopUiOps glib_eventloops = 
94{
95        g_timeout_add,
96        g_source_remove,
97        glib_input_add,
98        g_source_remove,
99        NULL,
100#if GLIB_CHECK_VERSION(2,14,0)
101        g_timeout_add_seconds,
102#else
103        NULL,
104#endif
105
106        /* padding */
107        NULL,
108        NULL,
109        NULL
110};
111
112static PurpleCoreUiOps bee_core_uiops = 
113{
114        NULL,
115        NULL,
116        NULL, //null_ui_init,
117        NULL,
118
119        /* padding */
120        NULL,
121        NULL,
122        NULL,
123        NULL
124};
125
126static PurpleConversationUiOps bee_conv_uiops = 
127{
128        NULL,                      /* create_conversation  */
129        NULL,                      /* destroy_conversation */
130        NULL,                      /* write_chat           */
131        NULL,                      /* write_im             */
132        NULL, //null_write_conv,           /* write_conv           */
133        NULL,                      /* chat_add_users       */
134        NULL,                      /* chat_rename_user     */
135        NULL,                      /* chat_remove_users    */
136        NULL,                      /* chat_update_user     */
137        NULL,                      /* present              */
138        NULL,                      /* has_focus            */
139        NULL,                      /* custom_smiley_add    */
140        NULL,                      /* custom_smiley_write  */
141        NULL,                      /* custom_smiley_close  */
142        NULL,                      /* send_confirm         */
143        NULL,
144        NULL,
145        NULL,
146        NULL
147};
148
149static void purple_init( account_t *acc )
150{
151        set_t *s;
152        char str[16];
153       
154}
155
156static void purple_login( account_t *acc )
157{
158        struct im_connection *ic = imcb_new( acc );
159        struct ns_srv_reply *srv = NULL;
160        char *connect_to, *s;
161        int i;
162       
163        /* For now this is needed in the _connected() handlers if using
164           GLib event handling, to make sure we're not handling events
165           on dead connections. */
166        purple_connections = g_slist_prepend( purple_connections, ic );
167       
168}
169
170static void purple_logout( struct im_connection *ic )
171{
172        purple_connections = g_slist_remove( purple_connections, ic );
173}
174
175static int purple_buddy_msg( struct im_connection *ic, char *who, char *message, int flags )
176{
177}
178
179static GList *purple_away_states( struct im_connection *ic )
180{
181}
182
183static void purple_set_away( struct im_connection *ic, char *state_txt, char *message )
184{
185}
186
187static void purple_add_buddy( struct im_connection *ic, char *who, char *group )
188{
189}
190
191static void purple_remove_buddy( struct im_connection *ic, char *who, char *group )
192{
193}
194
195static void purple_keepalive( struct im_connection *ic )
196{
197}
198
199static int purple_send_typing( struct im_connection *ic, char *who, int typing )
200{
201}
202
203void purple_initmodule()
204{
205        GList *prots;
206       
207        purple_util_set_user_dir("/tmp");
208        purple_debug_set_enabled(FALSE);
209        purple_core_set_ui_ops(&bee_core_uiops);
210        purple_eventloop_set_ui_ops(&glib_eventloops);
211        if( !purple_core_init( "BitlBee") )
212        {
213                /* Initializing the core failed. Terminate. */
214                fprintf( stderr, "libpurple initialization failed.\n" );
215                abort();
216        }
217       
218        /* This seems like stateful shit we don't want... */
219        purple_set_blist(purple_blist_new());
220        purple_blist_load();
221       
222        /* Meh? */
223        purple_prefs_load();
224       
225        for( prots = purple_plugins_get_protocols(); prots; prots = prots->next )
226        {
227                struct prpl *ret = g_new0( struct prpl, 1 );
228                PurplePlugin *prot = prots->data;
229               
230                ret->name = prot->info->id;
231                ret->login = purple_login;
232                ret->init = purple_init;
233                ret->logout = purple_logout;
234                ret->buddy_msg = purple_buddy_msg;
235                ret->away_states = purple_away_states;
236                ret->set_away = purple_set_away;
237                ret->add_buddy = purple_add_buddy;
238                ret->remove_buddy = purple_remove_buddy;
239                ret->keepalive = purple_keepalive;
240                ret->send_typing = purple_send_typing;
241                ret->handle_cmp = g_strcasecmp;
242               
243                register_protocol( ret );
244        }
245}
Note: See TracBrowser for help on using the repository browser.