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 "bitlbee.h" |
---|
25 | #include "help.h" |
---|
26 | |
---|
27 | #include <stdarg.h> |
---|
28 | |
---|
29 | #include <glib.h> |
---|
30 | #include <purple.h> |
---|
31 | |
---|
32 | GSList *purple_connections; |
---|
33 | |
---|
34 | /* This makes me VERY sad... :-( But some libpurple callbacks come in without |
---|
35 | any context so this is the only way to get that. Don't want to support |
---|
36 | libpurple in daemon mode anyway. */ |
---|
37 | static irc_t *local_irc; |
---|
38 | |
---|
39 | static struct im_connection *purple_ic_by_pa( PurpleAccount *pa ) |
---|
40 | { |
---|
41 | GSList *i; |
---|
42 | |
---|
43 | for( i = purple_connections; i; i = i->next ) |
---|
44 | if( ((struct im_connection *)i->data)->proto_data == pa ) |
---|
45 | return i->data; |
---|
46 | |
---|
47 | return NULL; |
---|
48 | } |
---|
49 | |
---|
50 | static struct im_connection *purple_ic_by_gc( PurpleConnection *gc ) |
---|
51 | { |
---|
52 | return purple_ic_by_pa( purple_connection_get_account( gc ) ); |
---|
53 | } |
---|
54 | |
---|
55 | static void purple_init( account_t *acc ) |
---|
56 | { |
---|
57 | PurplePlugin *prpl = purple_plugins_find_with_id( (char*) acc->prpl->data ); |
---|
58 | PurplePluginProtocolInfo *pi = prpl->info->extra_info; |
---|
59 | GList *i; |
---|
60 | |
---|
61 | for( i = pi->protocol_options; i; i = i->next ) |
---|
62 | { |
---|
63 | PurpleAccountOption *o = i->data; |
---|
64 | const char *name; |
---|
65 | char *def = NULL; |
---|
66 | set_eval eval = NULL; |
---|
67 | set_t *s; |
---|
68 | |
---|
69 | name = purple_account_option_get_setting( o ); |
---|
70 | |
---|
71 | switch( purple_account_option_get_type( o ) ) |
---|
72 | { |
---|
73 | case PURPLE_PREF_STRING: |
---|
74 | def = g_strdup( purple_account_option_get_default_string( o ) ); |
---|
75 | break; |
---|
76 | |
---|
77 | case PURPLE_PREF_INT: |
---|
78 | def = g_strdup_printf( "%d", purple_account_option_get_default_int( o ) ); |
---|
79 | eval = set_eval_int; |
---|
80 | break; |
---|
81 | |
---|
82 | case PURPLE_PREF_BOOLEAN: |
---|
83 | if( purple_account_option_get_default_bool( o ) ) |
---|
84 | def = g_strdup( "true" ); |
---|
85 | else |
---|
86 | def = g_strdup( "false" ); |
---|
87 | eval = set_eval_bool; |
---|
88 | break; |
---|
89 | |
---|
90 | default: |
---|
91 | fprintf( stderr, "Setting with unknown type: %s (%d)\n", name, purple_account_option_get_type( o ) ); |
---|
92 | name = NULL; |
---|
93 | } |
---|
94 | |
---|
95 | if( name != NULL ) |
---|
96 | { |
---|
97 | s = set_add( &acc->set, name, def, eval, acc ); |
---|
98 | s->flags |= ACC_SET_OFFLINE_ONLY; |
---|
99 | g_free( def ); |
---|
100 | } |
---|
101 | } |
---|
102 | } |
---|
103 | |
---|
104 | static void purple_sync_settings( account_t *acc, PurpleAccount *pa ) |
---|
105 | { |
---|
106 | PurplePlugin *prpl = purple_plugins_find_with_id( pa->protocol_id ); |
---|
107 | PurplePluginProtocolInfo *pi = prpl->info->extra_info; |
---|
108 | GList *i; |
---|
109 | |
---|
110 | for( i = pi->protocol_options; i; i = i->next ) |
---|
111 | { |
---|
112 | PurpleAccountOption *o = i->data; |
---|
113 | const char *name; |
---|
114 | set_t *s; |
---|
115 | |
---|
116 | name = purple_account_option_get_setting( o ); |
---|
117 | s = set_find( &acc->set, name ); |
---|
118 | if( s->value == NULL ) |
---|
119 | continue; |
---|
120 | |
---|
121 | switch( purple_account_option_get_type( o ) ) |
---|
122 | { |
---|
123 | case PURPLE_PREF_STRING: |
---|
124 | purple_account_set_string( pa, name, set_getstr( &acc->set, name ) ); |
---|
125 | break; |
---|
126 | |
---|
127 | case PURPLE_PREF_INT: |
---|
128 | purple_account_set_int( pa, name, set_getint( &acc->set, name ) ); |
---|
129 | break; |
---|
130 | |
---|
131 | case PURPLE_PREF_BOOLEAN: |
---|
132 | purple_account_set_bool( pa, name, set_getbool( &acc->set, name ) ); |
---|
133 | break; |
---|
134 | |
---|
135 | default: |
---|
136 | break; |
---|
137 | } |
---|
138 | } |
---|
139 | } |
---|
140 | |
---|
141 | static void purple_login( account_t *acc ) |
---|
142 | { |
---|
143 | struct im_connection *ic = imcb_new( acc ); |
---|
144 | PurpleAccount *pa; |
---|
145 | |
---|
146 | if( local_irc != NULL && local_irc != acc->irc ) |
---|
147 | { |
---|
148 | irc_usermsg( acc->irc, "Daemon mode detected. Do *not* try to use libpurple in daemon mode! " |
---|
149 | "Please use inetd or ForkDaemon mode instead." ); |
---|
150 | return; |
---|
151 | } |
---|
152 | local_irc = acc->irc; |
---|
153 | |
---|
154 | /* For now this is needed in the _connected() handlers if using |
---|
155 | GLib event handling, to make sure we're not handling events |
---|
156 | on dead connections. */ |
---|
157 | purple_connections = g_slist_prepend( purple_connections, ic ); |
---|
158 | |
---|
159 | ic->proto_data = pa = purple_account_new( acc->user, (char*) acc->prpl->data ); |
---|
160 | purple_account_set_password( pa, acc->pass ); |
---|
161 | purple_sync_settings( acc, pa ); |
---|
162 | |
---|
163 | purple_account_set_enabled( pa, "BitlBee", TRUE ); |
---|
164 | } |
---|
165 | |
---|
166 | static void purple_logout( struct im_connection *ic ) |
---|
167 | { |
---|
168 | PurpleAccount *pa = ic->proto_data; |
---|
169 | |
---|
170 | purple_account_set_enabled( pa, "BitlBee", FALSE ); |
---|
171 | purple_connections = g_slist_remove( purple_connections, ic ); |
---|
172 | purple_accounts_remove( pa ); |
---|
173 | } |
---|
174 | |
---|
175 | static int purple_buddy_msg( struct im_connection *ic, char *who, char *message, int flags ) |
---|
176 | { |
---|
177 | PurpleConversation *conv; |
---|
178 | |
---|
179 | if( ( conv = purple_find_conversation_with_account( PURPLE_CONV_TYPE_IM, |
---|
180 | who, ic->proto_data ) ) == NULL ) |
---|
181 | { |
---|
182 | conv = purple_conversation_new( PURPLE_CONV_TYPE_IM, |
---|
183 | ic->proto_data, who ); |
---|
184 | } |
---|
185 | |
---|
186 | purple_conv_im_send( purple_conversation_get_im_data( conv ), message ); |
---|
187 | |
---|
188 | return 1; |
---|
189 | } |
---|
190 | |
---|
191 | static GList *purple_away_states( struct im_connection *ic ) |
---|
192 | { |
---|
193 | PurpleAccount *pa = ic->proto_data; |
---|
194 | GList *st, *ret = NULL; |
---|
195 | |
---|
196 | for( st = purple_account_get_status_types( pa ); st; st = st->next ) |
---|
197 | ret = g_list_append( ret, (void*) purple_status_type_get_name( st->data ) ); |
---|
198 | |
---|
199 | return ret; |
---|
200 | } |
---|
201 | |
---|
202 | static void purple_set_away( struct im_connection *ic, char *state_txt, char *message ) |
---|
203 | { |
---|
204 | PurpleAccount *pa = ic->proto_data; |
---|
205 | GList *status_types = purple_account_get_status_types( pa ), *st; |
---|
206 | PurpleStatusType *pst = NULL; |
---|
207 | |
---|
208 | for( st = status_types; st; st = st->next ) |
---|
209 | { |
---|
210 | pst = st->data; |
---|
211 | |
---|
212 | if( g_strcasecmp( state_txt, purple_status_type_get_name( pst ) ) == 0 ) |
---|
213 | break; |
---|
214 | } |
---|
215 | |
---|
216 | purple_account_set_status( pa, st ? purple_status_type_get_id( pst ) : "away", |
---|
217 | TRUE, "message", message, NULL ); |
---|
218 | } |
---|
219 | |
---|
220 | static void purple_add_buddy( struct im_connection *ic, char *who, char *group ) |
---|
221 | { |
---|
222 | PurpleBuddy *pb; |
---|
223 | |
---|
224 | pb = purple_buddy_new( (PurpleAccount*) ic->proto_data, who, NULL ); |
---|
225 | purple_blist_add_buddy( pb, NULL, NULL, NULL ); |
---|
226 | purple_account_add_buddy( (PurpleAccount*) ic->proto_data, pb ); |
---|
227 | } |
---|
228 | |
---|
229 | static void purple_remove_buddy( struct im_connection *ic, char *who, char *group ) |
---|
230 | { |
---|
231 | PurpleBuddy *pb; |
---|
232 | |
---|
233 | pb = purple_find_buddy( (PurpleAccount*) ic->proto_data, who ); |
---|
234 | if( pb != NULL ) |
---|
235 | { |
---|
236 | purple_account_remove_buddy( (PurpleAccount*) ic->proto_data, pb, NULL ); |
---|
237 | purple_blist_remove_buddy( pb ); |
---|
238 | } |
---|
239 | } |
---|
240 | |
---|
241 | static void purple_keepalive( struct im_connection *ic ) |
---|
242 | { |
---|
243 | } |
---|
244 | |
---|
245 | static int purple_send_typing( struct im_connection *ic, char *who, int flags ) |
---|
246 | { |
---|
247 | PurpleTypingState state = PURPLE_NOT_TYPING; |
---|
248 | PurpleConversation *conv; |
---|
249 | |
---|
250 | if( flags & OPT_TYPING ) |
---|
251 | state = PURPLE_TYPING; |
---|
252 | else if( flags & OPT_THINKING ) |
---|
253 | state = PURPLE_TYPED; |
---|
254 | |
---|
255 | if( ( conv = purple_find_conversation_with_account( PURPLE_CONV_TYPE_IM, |
---|
256 | who, ic->proto_data ) ) == NULL ) |
---|
257 | { |
---|
258 | purple_conv_im_set_typing_state( purple_conversation_get_im_data( conv ), state ); |
---|
259 | return 1; |
---|
260 | } |
---|
261 | else |
---|
262 | { |
---|
263 | return 0; |
---|
264 | } |
---|
265 | } |
---|
266 | |
---|
267 | static void purple_ui_init(); |
---|
268 | |
---|
269 | static PurpleCoreUiOps bee_core_uiops = |
---|
270 | { |
---|
271 | NULL, |
---|
272 | NULL, |
---|
273 | purple_ui_init, |
---|
274 | NULL, |
---|
275 | }; |
---|
276 | |
---|
277 | static void prplcb_conn_progress( PurpleConnection *gc, const char *text, size_t step, size_t step_count ) |
---|
278 | { |
---|
279 | struct im_connection *ic = purple_ic_by_gc( gc ); |
---|
280 | |
---|
281 | imcb_log( ic, "%s", text ); |
---|
282 | } |
---|
283 | |
---|
284 | static void prplcb_conn_connected( PurpleConnection *gc ) |
---|
285 | { |
---|
286 | struct im_connection *ic = purple_ic_by_gc( gc ); |
---|
287 | |
---|
288 | imcb_connected( ic ); |
---|
289 | |
---|
290 | if( gc->flags & PURPLE_CONNECTION_HTML ) |
---|
291 | ic->flags |= OPT_DOES_HTML; |
---|
292 | } |
---|
293 | |
---|
294 | static void prplcb_conn_disconnected( PurpleConnection *gc ) |
---|
295 | { |
---|
296 | struct im_connection *ic = purple_ic_by_gc( gc ); |
---|
297 | |
---|
298 | if( ic != NULL ) |
---|
299 | { |
---|
300 | imc_logout( ic, TRUE ); |
---|
301 | } |
---|
302 | } |
---|
303 | |
---|
304 | static void prplcb_conn_notice( PurpleConnection *gc, const char *text ) |
---|
305 | { |
---|
306 | struct im_connection *ic = purple_ic_by_gc( gc ); |
---|
307 | |
---|
308 | if( ic != NULL ) |
---|
309 | imcb_log( ic, "%s", text ); |
---|
310 | } |
---|
311 | |
---|
312 | static void prplcb_conn_report_disconnect_reason( PurpleConnection *gc, PurpleConnectionError reason, const char *text ) |
---|
313 | { |
---|
314 | struct im_connection *ic = purple_ic_by_gc( gc ); |
---|
315 | |
---|
316 | /* PURPLE_CONNECTION_ERROR_NAME_IN_USE means concurrent login, |
---|
317 | should probably handle that. */ |
---|
318 | if( ic != NULL ) |
---|
319 | imcb_error( ic, "%s", text ); |
---|
320 | } |
---|
321 | |
---|
322 | static PurpleConnectionUiOps bee_conn_uiops = |
---|
323 | { |
---|
324 | prplcb_conn_progress, |
---|
325 | prplcb_conn_connected, |
---|
326 | prplcb_conn_disconnected, |
---|
327 | prplcb_conn_notice, |
---|
328 | NULL, |
---|
329 | NULL, |
---|
330 | NULL, |
---|
331 | prplcb_conn_report_disconnect_reason, |
---|
332 | }; |
---|
333 | |
---|
334 | static void prplcb_blist_new( PurpleBlistNode *node ) |
---|
335 | { |
---|
336 | PurpleBuddy *bud = (PurpleBuddy*) node; |
---|
337 | |
---|
338 | if( node->type == PURPLE_BLIST_BUDDY_NODE ) |
---|
339 | { |
---|
340 | struct im_connection *ic = purple_ic_by_pa( bud->account ); |
---|
341 | |
---|
342 | if( ic == NULL ) |
---|
343 | return; |
---|
344 | |
---|
345 | imcb_add_buddy( ic, bud->name, NULL ); |
---|
346 | if( bud->server_alias ) |
---|
347 | { |
---|
348 | imcb_rename_buddy( ic, bud->name, bud->server_alias ); |
---|
349 | imcb_buddy_nick_hint( ic, bud->name, bud->server_alias ); |
---|
350 | } |
---|
351 | } |
---|
352 | } |
---|
353 | |
---|
354 | static void prplcb_blist_update( PurpleBuddyList *list, PurpleBlistNode *node ) |
---|
355 | { |
---|
356 | PurpleBuddy *bud = (PurpleBuddy*) node; |
---|
357 | |
---|
358 | if( node->type == PURPLE_BLIST_BUDDY_NODE ) |
---|
359 | { |
---|
360 | struct im_connection *ic = purple_ic_by_pa( bud->account ); |
---|
361 | PurpleStatus *as; |
---|
362 | int flags = 0; |
---|
363 | |
---|
364 | if( ic == NULL ) |
---|
365 | return; |
---|
366 | |
---|
367 | if( bud->server_alias ) |
---|
368 | imcb_rename_buddy( ic, bud->name, bud->server_alias ); |
---|
369 | |
---|
370 | flags |= purple_presence_is_online( bud->presence ) ? OPT_LOGGED_IN : 0; |
---|
371 | flags |= purple_presence_is_available( bud->presence ) ? 0 : OPT_AWAY; |
---|
372 | |
---|
373 | as = purple_presence_get_active_status( bud->presence ); |
---|
374 | |
---|
375 | imcb_buddy_status( ic, bud->name, flags, purple_status_get_name( as ), |
---|
376 | purple_status_get_attr_string( as, "message" ) ); |
---|
377 | } |
---|
378 | } |
---|
379 | |
---|
380 | static void prplcb_blist_remove( PurpleBuddyList *list, PurpleBlistNode *node ) |
---|
381 | { |
---|
382 | PurpleBuddy *bud = (PurpleBuddy*) node; |
---|
383 | |
---|
384 | /* |
---|
385 | if( node->type == PURPLE_BLIST_BUDDY_NODE ) |
---|
386 | { |
---|
387 | struct im_connection *ic = purple_ic_by_pa( bud->account ); |
---|
388 | |
---|
389 | if( ic == NULL ) |
---|
390 | return; |
---|
391 | |
---|
392 | imcb_remove_buddy( ic, bud->name, NULL ); |
---|
393 | } |
---|
394 | */ |
---|
395 | } |
---|
396 | |
---|
397 | static PurpleBlistUiOps bee_blist_uiops = |
---|
398 | { |
---|
399 | NULL, |
---|
400 | prplcb_blist_new, |
---|
401 | NULL, |
---|
402 | prplcb_blist_update, |
---|
403 | prplcb_blist_remove, |
---|
404 | }; |
---|
405 | |
---|
406 | static void prplcb_conv_im( PurpleConversation *conv, const char *who, const char *message, PurpleMessageFlags flags, time_t mtime ) |
---|
407 | { |
---|
408 | struct im_connection *ic = purple_ic_by_pa( conv->account ); |
---|
409 | |
---|
410 | /* ..._SEND means it's an outgoing message, no need to echo those. */ |
---|
411 | if( !( flags & PURPLE_MESSAGE_SEND ) ) |
---|
412 | imcb_buddy_msg( ic, (char*) who, (char*) message, 0, mtime ); |
---|
413 | } |
---|
414 | |
---|
415 | static PurpleConversationUiOps bee_conv_uiops = |
---|
416 | { |
---|
417 | NULL, /* create_conversation */ |
---|
418 | NULL, /* destroy_conversation */ |
---|
419 | NULL, /* write_chat */ |
---|
420 | prplcb_conv_im, /* write_im */ |
---|
421 | NULL, /* write_conv */ |
---|
422 | NULL, /* chat_add_users */ |
---|
423 | NULL, /* chat_rename_user */ |
---|
424 | NULL, /* chat_remove_users */ |
---|
425 | NULL, /* chat_update_user */ |
---|
426 | NULL, /* present */ |
---|
427 | NULL, /* has_focus */ |
---|
428 | NULL, /* custom_smiley_add */ |
---|
429 | NULL, /* custom_smiley_write */ |
---|
430 | NULL, /* custom_smiley_close */ |
---|
431 | NULL, /* send_confirm */ |
---|
432 | }; |
---|
433 | |
---|
434 | struct prplcb_request_action_data |
---|
435 | { |
---|
436 | void *user_data, *bee_data; |
---|
437 | PurpleRequestActionCb yes, no; |
---|
438 | int yes_i, no_i; |
---|
439 | }; |
---|
440 | |
---|
441 | static void prplcb_request_action_yes( void *data ) |
---|
442 | { |
---|
443 | struct prplcb_request_action_data *pqad = data; |
---|
444 | |
---|
445 | pqad->yes( pqad->user_data, pqad->yes_i ); |
---|
446 | g_free( pqad ); |
---|
447 | } |
---|
448 | |
---|
449 | static void prplcb_request_action_no( void *data ) |
---|
450 | { |
---|
451 | struct prplcb_request_action_data *pqad = data; |
---|
452 | |
---|
453 | pqad->no( pqad->user_data, pqad->no_i ); |
---|
454 | g_free( pqad ); |
---|
455 | } |
---|
456 | |
---|
457 | static void *prplcb_request_action( const char *title, const char *primary, const char *secondary, |
---|
458 | int default_action, PurpleAccount *account, const char *who, |
---|
459 | PurpleConversation *conv, void *user_data, size_t action_count, |
---|
460 | va_list actions ) |
---|
461 | { |
---|
462 | struct prplcb_request_action_data *pqad; |
---|
463 | int i; |
---|
464 | char *q; |
---|
465 | |
---|
466 | pqad = g_new0( struct prplcb_request_action_data, 1 ); |
---|
467 | |
---|
468 | for( i = 0; i < action_count; i ++ ) |
---|
469 | { |
---|
470 | char *caption; |
---|
471 | void *fn; |
---|
472 | |
---|
473 | caption = va_arg( actions, char* ); |
---|
474 | fn = va_arg( actions, void* ); |
---|
475 | |
---|
476 | if( strcmp( caption, "Accept" ) == 0 ) |
---|
477 | { |
---|
478 | pqad->yes = fn; |
---|
479 | pqad->yes_i = i; |
---|
480 | } |
---|
481 | else if( strcmp( caption, "Reject" ) == 0 ) |
---|
482 | { |
---|
483 | pqad->no = fn; |
---|
484 | pqad->no_i = i; |
---|
485 | } |
---|
486 | } |
---|
487 | |
---|
488 | pqad->user_data = user_data; |
---|
489 | |
---|
490 | q = g_strdup_printf( "Request: %s\n\n%s\n\n%s", title, primary, secondary ); |
---|
491 | pqad->bee_data = query_add( local_irc, purple_ic_by_pa( account ), q, |
---|
492 | prplcb_request_action_yes, prplcb_request_action_no, pqad ); |
---|
493 | |
---|
494 | g_free( q ); |
---|
495 | |
---|
496 | return pqad; |
---|
497 | } |
---|
498 | |
---|
499 | static PurpleRequestUiOps bee_request_uiops = |
---|
500 | { |
---|
501 | NULL, |
---|
502 | NULL, |
---|
503 | prplcb_request_action, |
---|
504 | NULL, |
---|
505 | NULL, |
---|
506 | NULL, |
---|
507 | NULL, |
---|
508 | }; |
---|
509 | |
---|
510 | static void prplcb_debug_print( PurpleDebugLevel level, const char *category, const char *arg_s ) |
---|
511 | { |
---|
512 | fprintf( stderr, "DEBUG %s: %s", category, arg_s ); |
---|
513 | } |
---|
514 | |
---|
515 | static PurpleDebugUiOps bee_debug_uiops = |
---|
516 | { |
---|
517 | prplcb_debug_print, |
---|
518 | }; |
---|
519 | |
---|
520 | static guint prplcb_ev_timeout_add( guint interval, GSourceFunc func, gpointer udata ) |
---|
521 | { |
---|
522 | return b_timeout_add( interval, (b_event_handler) func, udata ); |
---|
523 | } |
---|
524 | |
---|
525 | static guint prplcb_ev_input_add( int fd, PurpleInputCondition cond, PurpleInputFunction func, gpointer udata ) |
---|
526 | { |
---|
527 | return b_input_add( fd, cond | B_EV_FLAG_FORCE_REPEAT, (b_event_handler) func, udata ); |
---|
528 | } |
---|
529 | |
---|
530 | static gboolean prplcb_ev_remove( guint id ) |
---|
531 | { |
---|
532 | b_event_remove( (gint) id ); |
---|
533 | return TRUE; |
---|
534 | } |
---|
535 | |
---|
536 | static PurpleEventLoopUiOps glib_eventloops = |
---|
537 | { |
---|
538 | prplcb_ev_timeout_add, |
---|
539 | prplcb_ev_remove, |
---|
540 | prplcb_ev_input_add, |
---|
541 | prplcb_ev_remove, |
---|
542 | }; |
---|
543 | |
---|
544 | static void purple_ui_init() |
---|
545 | { |
---|
546 | purple_blist_set_ui_ops( &bee_blist_uiops ); |
---|
547 | purple_connections_set_ui_ops( &bee_conn_uiops ); |
---|
548 | purple_conversations_set_ui_ops( &bee_conv_uiops ); |
---|
549 | purple_request_set_ui_ops( &bee_request_uiops ); |
---|
550 | //purple_debug_set_ui_ops( &bee_debug_uiops ); |
---|
551 | } |
---|
552 | |
---|
553 | void purple_initmodule() |
---|
554 | { |
---|
555 | struct prpl funcs; |
---|
556 | GList *prots; |
---|
557 | GString *help; |
---|
558 | |
---|
559 | if( B_EV_IO_READ != PURPLE_INPUT_READ || |
---|
560 | B_EV_IO_WRITE != PURPLE_INPUT_WRITE ) |
---|
561 | { |
---|
562 | /* FIXME FIXME FIXME FIXME FIXME :-) */ |
---|
563 | exit( 1 ); |
---|
564 | } |
---|
565 | |
---|
566 | purple_util_set_user_dir("/tmp"); |
---|
567 | purple_debug_set_enabled(FALSE); |
---|
568 | purple_core_set_ui_ops(&bee_core_uiops); |
---|
569 | purple_eventloop_set_ui_ops(&glib_eventloops); |
---|
570 | if( !purple_core_init( "BitlBee") ) |
---|
571 | { |
---|
572 | /* Initializing the core failed. Terminate. */ |
---|
573 | fprintf( stderr, "libpurple initialization failed.\n" ); |
---|
574 | abort(); |
---|
575 | } |
---|
576 | |
---|
577 | /* This seems like stateful shit we don't want... */ |
---|
578 | purple_set_blist(purple_blist_new()); |
---|
579 | purple_blist_load(); |
---|
580 | |
---|
581 | /* Meh? */ |
---|
582 | purple_prefs_load(); |
---|
583 | |
---|
584 | memset( &funcs, 0, sizeof( funcs ) ); |
---|
585 | funcs.login = purple_login; |
---|
586 | funcs.init = purple_init; |
---|
587 | funcs.logout = purple_logout; |
---|
588 | funcs.buddy_msg = purple_buddy_msg; |
---|
589 | funcs.away_states = purple_away_states; |
---|
590 | funcs.set_away = purple_set_away; |
---|
591 | funcs.add_buddy = purple_add_buddy; |
---|
592 | funcs.remove_buddy = purple_remove_buddy; |
---|
593 | funcs.keepalive = purple_keepalive; |
---|
594 | funcs.send_typing = purple_send_typing; |
---|
595 | funcs.handle_cmp = g_strcasecmp; |
---|
596 | |
---|
597 | help = g_string_new("BitlBee libpurple module supports the following IM protocols:\n"); |
---|
598 | |
---|
599 | for( prots = purple_plugins_get_protocols(); prots; prots = prots->next ) |
---|
600 | { |
---|
601 | PurplePlugin *prot = prots->data; |
---|
602 | struct prpl *ret; |
---|
603 | |
---|
604 | ret = g_memdup( &funcs, sizeof( funcs ) ); |
---|
605 | ret->name = ret->data = prot->info->id; |
---|
606 | if( strncmp( ret->name, "prpl-", 5 ) == 0 ) |
---|
607 | ret->name += 5; |
---|
608 | register_protocol( ret ); |
---|
609 | |
---|
610 | g_string_append_printf( help, "\n* %s (%s)", ret->name, prot->info->name ); |
---|
611 | |
---|
612 | if( g_strcasecmp( prot->info->id, "prpl-aim" ) == 0 ) |
---|
613 | { |
---|
614 | ret = g_memdup( &funcs, sizeof( funcs ) ); |
---|
615 | ret->name = "oscar"; |
---|
616 | ret->data = prot->info->id; |
---|
617 | register_protocol( ret ); |
---|
618 | } |
---|
619 | } |
---|
620 | |
---|
621 | help_add_mem( &global.help, "purple", help->str ); |
---|
622 | g_string_free( help, TRUE ); |
---|
623 | } |
---|