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 | /* |
---|
383 | PurpleBuddy *bud = (PurpleBuddy*) node; |
---|
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 | PurpleBuddy *buddy; |
---|
410 | |
---|
411 | /* ..._SEND means it's an outgoing message, no need to echo those. */ |
---|
412 | if( flags & PURPLE_MESSAGE_SEND ) |
---|
413 | return; |
---|
414 | |
---|
415 | buddy = purple_find_buddy( conv->account, who ); |
---|
416 | if( buddy != NULL ) |
---|
417 | who = purple_buddy_get_contact_alias( buddy ); |
---|
418 | |
---|
419 | imcb_buddy_msg( ic, (char*) who, (char*) message, 0, mtime ); |
---|
420 | } |
---|
421 | |
---|
422 | static PurpleConversationUiOps bee_conv_uiops = |
---|
423 | { |
---|
424 | NULL, /* create_conversation */ |
---|
425 | NULL, /* destroy_conversation */ |
---|
426 | NULL, /* write_chat */ |
---|
427 | prplcb_conv_im, /* write_im */ |
---|
428 | NULL, /* write_conv */ |
---|
429 | NULL, /* chat_add_users */ |
---|
430 | NULL, /* chat_rename_user */ |
---|
431 | NULL, /* chat_remove_users */ |
---|
432 | NULL, /* chat_update_user */ |
---|
433 | NULL, /* present */ |
---|
434 | NULL, /* has_focus */ |
---|
435 | NULL, /* custom_smiley_add */ |
---|
436 | NULL, /* custom_smiley_write */ |
---|
437 | NULL, /* custom_smiley_close */ |
---|
438 | NULL, /* send_confirm */ |
---|
439 | }; |
---|
440 | |
---|
441 | struct prplcb_request_action_data |
---|
442 | { |
---|
443 | void *user_data, *bee_data; |
---|
444 | PurpleRequestActionCb yes, no; |
---|
445 | int yes_i, no_i; |
---|
446 | }; |
---|
447 | |
---|
448 | static void prplcb_request_action_yes( void *data ) |
---|
449 | { |
---|
450 | struct prplcb_request_action_data *pqad = data; |
---|
451 | |
---|
452 | pqad->yes( pqad->user_data, pqad->yes_i ); |
---|
453 | g_free( pqad ); |
---|
454 | } |
---|
455 | |
---|
456 | static void prplcb_request_action_no( void *data ) |
---|
457 | { |
---|
458 | struct prplcb_request_action_data *pqad = data; |
---|
459 | |
---|
460 | pqad->no( pqad->user_data, pqad->no_i ); |
---|
461 | g_free( pqad ); |
---|
462 | } |
---|
463 | |
---|
464 | static void *prplcb_request_action( const char *title, const char *primary, const char *secondary, |
---|
465 | int default_action, PurpleAccount *account, const char *who, |
---|
466 | PurpleConversation *conv, void *user_data, size_t action_count, |
---|
467 | va_list actions ) |
---|
468 | { |
---|
469 | struct prplcb_request_action_data *pqad; |
---|
470 | int i; |
---|
471 | char *q; |
---|
472 | |
---|
473 | pqad = g_new0( struct prplcb_request_action_data, 1 ); |
---|
474 | |
---|
475 | for( i = 0; i < action_count; i ++ ) |
---|
476 | { |
---|
477 | char *caption; |
---|
478 | void *fn; |
---|
479 | |
---|
480 | caption = va_arg( actions, char* ); |
---|
481 | fn = va_arg( actions, void* ); |
---|
482 | |
---|
483 | if( strcmp( caption, "Accept" ) == 0 ) |
---|
484 | { |
---|
485 | pqad->yes = fn; |
---|
486 | pqad->yes_i = i; |
---|
487 | } |
---|
488 | else if( strcmp( caption, "Reject" ) == 0 ) |
---|
489 | { |
---|
490 | pqad->no = fn; |
---|
491 | pqad->no_i = i; |
---|
492 | } |
---|
493 | } |
---|
494 | |
---|
495 | pqad->user_data = user_data; |
---|
496 | |
---|
497 | q = g_strdup_printf( "Request: %s\n\n%s\n\n%s", title, primary, secondary ); |
---|
498 | pqad->bee_data = query_add( local_irc, purple_ic_by_pa( account ), q, |
---|
499 | prplcb_request_action_yes, prplcb_request_action_no, pqad ); |
---|
500 | |
---|
501 | g_free( q ); |
---|
502 | |
---|
503 | return pqad; |
---|
504 | } |
---|
505 | |
---|
506 | static PurpleRequestUiOps bee_request_uiops = |
---|
507 | { |
---|
508 | NULL, |
---|
509 | NULL, |
---|
510 | prplcb_request_action, |
---|
511 | NULL, |
---|
512 | NULL, |
---|
513 | NULL, |
---|
514 | NULL, |
---|
515 | }; |
---|
516 | |
---|
517 | static void prplcb_debug_print( PurpleDebugLevel level, const char *category, const char *arg_s ) |
---|
518 | { |
---|
519 | fprintf( stderr, "DEBUG %s: %s", category, arg_s ); |
---|
520 | } |
---|
521 | |
---|
522 | static PurpleDebugUiOps bee_debug_uiops = |
---|
523 | { |
---|
524 | prplcb_debug_print, |
---|
525 | }; |
---|
526 | |
---|
527 | static guint prplcb_ev_timeout_add( guint interval, GSourceFunc func, gpointer udata ) |
---|
528 | { |
---|
529 | return b_timeout_add( interval, (b_event_handler) func, udata ); |
---|
530 | } |
---|
531 | |
---|
532 | static guint prplcb_ev_input_add( int fd, PurpleInputCondition cond, PurpleInputFunction func, gpointer udata ) |
---|
533 | { |
---|
534 | return b_input_add( fd, cond | B_EV_FLAG_FORCE_REPEAT, (b_event_handler) func, udata ); |
---|
535 | } |
---|
536 | |
---|
537 | static gboolean prplcb_ev_remove( guint id ) |
---|
538 | { |
---|
539 | b_event_remove( (gint) id ); |
---|
540 | return TRUE; |
---|
541 | } |
---|
542 | |
---|
543 | static PurpleEventLoopUiOps glib_eventloops = |
---|
544 | { |
---|
545 | prplcb_ev_timeout_add, |
---|
546 | prplcb_ev_remove, |
---|
547 | prplcb_ev_input_add, |
---|
548 | prplcb_ev_remove, |
---|
549 | }; |
---|
550 | |
---|
551 | static void purple_ui_init() |
---|
552 | { |
---|
553 | purple_blist_set_ui_ops( &bee_blist_uiops ); |
---|
554 | purple_connections_set_ui_ops( &bee_conn_uiops ); |
---|
555 | purple_conversations_set_ui_ops( &bee_conv_uiops ); |
---|
556 | purple_request_set_ui_ops( &bee_request_uiops ); |
---|
557 | //purple_debug_set_ui_ops( &bee_debug_uiops ); |
---|
558 | } |
---|
559 | |
---|
560 | void purple_initmodule() |
---|
561 | { |
---|
562 | struct prpl funcs; |
---|
563 | GList *prots; |
---|
564 | GString *help; |
---|
565 | |
---|
566 | if( B_EV_IO_READ != PURPLE_INPUT_READ || |
---|
567 | B_EV_IO_WRITE != PURPLE_INPUT_WRITE ) |
---|
568 | { |
---|
569 | /* FIXME FIXME FIXME FIXME FIXME :-) */ |
---|
570 | exit( 1 ); |
---|
571 | } |
---|
572 | |
---|
573 | purple_util_set_user_dir("/tmp"); |
---|
574 | purple_debug_set_enabled(FALSE); |
---|
575 | purple_core_set_ui_ops(&bee_core_uiops); |
---|
576 | purple_eventloop_set_ui_ops(&glib_eventloops); |
---|
577 | if( !purple_core_init( "BitlBee") ) |
---|
578 | { |
---|
579 | /* Initializing the core failed. Terminate. */ |
---|
580 | fprintf( stderr, "libpurple initialization failed.\n" ); |
---|
581 | abort(); |
---|
582 | } |
---|
583 | |
---|
584 | /* This seems like stateful shit we don't want... */ |
---|
585 | purple_set_blist(purple_blist_new()); |
---|
586 | purple_blist_load(); |
---|
587 | |
---|
588 | /* Meh? */ |
---|
589 | purple_prefs_load(); |
---|
590 | |
---|
591 | memset( &funcs, 0, sizeof( funcs ) ); |
---|
592 | funcs.login = purple_login; |
---|
593 | funcs.init = purple_init; |
---|
594 | funcs.logout = purple_logout; |
---|
595 | funcs.buddy_msg = purple_buddy_msg; |
---|
596 | funcs.away_states = purple_away_states; |
---|
597 | funcs.set_away = purple_set_away; |
---|
598 | funcs.add_buddy = purple_add_buddy; |
---|
599 | funcs.remove_buddy = purple_remove_buddy; |
---|
600 | funcs.keepalive = purple_keepalive; |
---|
601 | funcs.send_typing = purple_send_typing; |
---|
602 | funcs.handle_cmp = g_strcasecmp; |
---|
603 | |
---|
604 | help = g_string_new("BitlBee libpurple module supports the following IM protocols:\n"); |
---|
605 | |
---|
606 | for( prots = purple_plugins_get_protocols(); prots; prots = prots->next ) |
---|
607 | { |
---|
608 | PurplePlugin *prot = prots->data; |
---|
609 | struct prpl *ret; |
---|
610 | |
---|
611 | ret = g_memdup( &funcs, sizeof( funcs ) ); |
---|
612 | ret->name = ret->data = prot->info->id; |
---|
613 | if( strncmp( ret->name, "prpl-", 5 ) == 0 ) |
---|
614 | ret->name += 5; |
---|
615 | register_protocol( ret ); |
---|
616 | |
---|
617 | g_string_append_printf( help, "\n* %s (%s)", ret->name, prot->info->name ); |
---|
618 | |
---|
619 | if( g_strcasecmp( prot->info->id, "prpl-aim" ) == 0 ) |
---|
620 | { |
---|
621 | ret = g_memdup( &funcs, sizeof( funcs ) ); |
---|
622 | ret->name = "oscar"; |
---|
623 | ret->data = prot->info->id; |
---|
624 | register_protocol( ret ); |
---|
625 | } |
---|
626 | } |
---|
627 | |
---|
628 | help_add_mem( &global.help, "purple", help->str ); |
---|
629 | g_string_free( help, TRUE ); |
---|
630 | } |
---|