1 | /********************************************************************\ |
---|
2 | * BitlBee -- An IRC to other IM-networks gateway * |
---|
3 | * * |
---|
4 | * Copyright 2002-2010 Wilmer van der Gaast and others * |
---|
5 | \********************************************************************/ |
---|
6 | |
---|
7 | /* |
---|
8 | * nogaim |
---|
9 | * |
---|
10 | * Gaim without gaim - for BitlBee |
---|
11 | * |
---|
12 | * This file contains functions called by the Gaim IM-modules. It's written |
---|
13 | * from scratch for BitlBee and doesn't contain any code from Gaim anymore |
---|
14 | * (except for the function names). |
---|
15 | */ |
---|
16 | |
---|
17 | /* |
---|
18 | This program is free software; you can redistribute it and/or modify |
---|
19 | it under the terms of the GNU General Public License as published by |
---|
20 | the Free Software Foundation; either version 2 of the License, or |
---|
21 | (at your option) any later version. |
---|
22 | |
---|
23 | This program is distributed in the hope that it will be useful, |
---|
24 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
25 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
26 | GNU General Public License for more details. |
---|
27 | |
---|
28 | You should have received a copy of the GNU General Public License with |
---|
29 | the Debian GNU/Linux distribution in /usr/share/common-licenses/GPL; |
---|
30 | if not, write to the Free Software Foundation, Inc., 59 Temple Place, |
---|
31 | Suite 330, Boston, MA 02111-1307 USA |
---|
32 | */ |
---|
33 | |
---|
34 | #define BITLBEE_CORE |
---|
35 | #include <ctype.h> |
---|
36 | |
---|
37 | #include "nogaim.h" |
---|
38 | #include "chat.h" |
---|
39 | |
---|
40 | static int remove_chat_buddy_silent( struct groupchat *b, const char *handle ); |
---|
41 | |
---|
42 | GSList *connections; |
---|
43 | |
---|
44 | #ifdef WITH_PLUGINS |
---|
45 | gboolean load_plugin(char *path) |
---|
46 | { |
---|
47 | void (*init_function) (void); |
---|
48 | |
---|
49 | GModule *mod = g_module_open(path, G_MODULE_BIND_LAZY); |
---|
50 | |
---|
51 | if(!mod) { |
---|
52 | log_message(LOGLVL_ERROR, "Can't find `%s', not loading (%s)\n", path, g_module_error()); |
---|
53 | return FALSE; |
---|
54 | } |
---|
55 | |
---|
56 | if(!g_module_symbol(mod,"init_plugin",(gpointer *) &init_function)) { |
---|
57 | log_message(LOGLVL_WARNING, "Can't find function `init_plugin' in `%s'\n", path); |
---|
58 | return FALSE; |
---|
59 | } |
---|
60 | |
---|
61 | init_function(); |
---|
62 | |
---|
63 | return TRUE; |
---|
64 | } |
---|
65 | |
---|
66 | void load_plugins(void) |
---|
67 | { |
---|
68 | GDir *dir; |
---|
69 | GError *error = NULL; |
---|
70 | |
---|
71 | dir = g_dir_open(global.conf->plugindir, 0, &error); |
---|
72 | |
---|
73 | if (dir) { |
---|
74 | const gchar *entry; |
---|
75 | char *path; |
---|
76 | |
---|
77 | while ((entry = g_dir_read_name(dir))) { |
---|
78 | path = g_build_filename(global.conf->plugindir, entry, NULL); |
---|
79 | if(!path) { |
---|
80 | log_message(LOGLVL_WARNING, "Can't build path for %s\n", entry); |
---|
81 | continue; |
---|
82 | } |
---|
83 | |
---|
84 | load_plugin(path); |
---|
85 | |
---|
86 | g_free(path); |
---|
87 | } |
---|
88 | |
---|
89 | g_dir_close(dir); |
---|
90 | } |
---|
91 | } |
---|
92 | #endif |
---|
93 | |
---|
94 | /* nogaim.c */ |
---|
95 | |
---|
96 | GList *protocols = NULL; |
---|
97 | |
---|
98 | void register_protocol (struct prpl *p) |
---|
99 | { |
---|
100 | protocols = g_list_append(protocols, p); |
---|
101 | } |
---|
102 | |
---|
103 | struct prpl *find_protocol(const char *name) |
---|
104 | { |
---|
105 | GList *gl; |
---|
106 | |
---|
107 | for( gl = protocols; gl; gl = gl->next ) |
---|
108 | { |
---|
109 | struct prpl *proto = gl->data; |
---|
110 | |
---|
111 | if( g_strcasecmp( proto->name, name ) == 0 ) |
---|
112 | return proto; |
---|
113 | } |
---|
114 | |
---|
115 | return NULL; |
---|
116 | } |
---|
117 | |
---|
118 | /* nogaim.c */ |
---|
119 | void nogaim_init() |
---|
120 | { |
---|
121 | extern void msn_initmodule(); |
---|
122 | extern void oscar_initmodule(); |
---|
123 | extern void byahoo_initmodule(); |
---|
124 | extern void jabber_initmodule(); |
---|
125 | extern void purple_initmodule(); |
---|
126 | |
---|
127 | #ifdef WITH_MSN |
---|
128 | msn_initmodule(); |
---|
129 | #endif |
---|
130 | |
---|
131 | #ifdef WITH_OSCAR |
---|
132 | oscar_initmodule(); |
---|
133 | #endif |
---|
134 | |
---|
135 | #ifdef WITH_YAHOO |
---|
136 | byahoo_initmodule(); |
---|
137 | #endif |
---|
138 | |
---|
139 | #ifdef WITH_JABBER |
---|
140 | jabber_initmodule(); |
---|
141 | #endif |
---|
142 | |
---|
143 | #ifdef WITH_PURPLE |
---|
144 | purple_initmodule(); |
---|
145 | #endif |
---|
146 | |
---|
147 | #ifdef WITH_PLUGINS |
---|
148 | load_plugins(); |
---|
149 | #endif |
---|
150 | } |
---|
151 | |
---|
152 | GSList *get_connections() { return connections; } |
---|
153 | |
---|
154 | /* multi.c */ |
---|
155 | |
---|
156 | struct im_connection *imcb_new( account_t *acc ) |
---|
157 | { |
---|
158 | struct im_connection *ic; |
---|
159 | |
---|
160 | ic = g_new0( struct im_connection, 1 ); |
---|
161 | |
---|
162 | ic->irc = acc->irc; |
---|
163 | ic->acc = acc; |
---|
164 | acc->ic = ic; |
---|
165 | |
---|
166 | connections = g_slist_append( connections, ic ); |
---|
167 | |
---|
168 | return( ic ); |
---|
169 | } |
---|
170 | |
---|
171 | void imc_free( struct im_connection *ic ) |
---|
172 | { |
---|
173 | account_t *a; |
---|
174 | |
---|
175 | /* Destroy the pointer to this connection from the account list */ |
---|
176 | for( a = ic->irc->accounts; a; a = a->next ) |
---|
177 | if( a->ic == ic ) |
---|
178 | { |
---|
179 | a->ic = NULL; |
---|
180 | break; |
---|
181 | } |
---|
182 | |
---|
183 | connections = g_slist_remove( connections, ic ); |
---|
184 | g_free( ic ); |
---|
185 | } |
---|
186 | |
---|
187 | static void serv_got_crap( struct im_connection *ic, char *format, ... ) |
---|
188 | { |
---|
189 | va_list params; |
---|
190 | char *text; |
---|
191 | account_t *a; |
---|
192 | |
---|
193 | va_start( params, format ); |
---|
194 | text = g_strdup_vprintf( format, params ); |
---|
195 | va_end( params ); |
---|
196 | |
---|
197 | if( ( g_strcasecmp( set_getstr( &ic->irc->set, "strip_html" ), "always" ) == 0 ) || |
---|
198 | ( ( ic->flags & OPT_DOES_HTML ) && set_getbool( &ic->irc->set, "strip_html" ) ) ) |
---|
199 | strip_html( text ); |
---|
200 | |
---|
201 | /* Try to find a different connection on the same protocol. */ |
---|
202 | for( a = ic->irc->accounts; a; a = a->next ) |
---|
203 | if( a->prpl == ic->acc->prpl && a->ic != ic ) |
---|
204 | break; |
---|
205 | |
---|
206 | /* If we found one, include the screenname in the message. */ |
---|
207 | if( a ) |
---|
208 | irc_usermsg( ic->irc, "%s(%s) - %s", ic->acc->prpl->name, ic->acc->user, text ); |
---|
209 | else |
---|
210 | irc_usermsg( ic->irc, "%s - %s", ic->acc->prpl->name, text ); |
---|
211 | |
---|
212 | g_free( text ); |
---|
213 | } |
---|
214 | |
---|
215 | void imcb_log( struct im_connection *ic, char *format, ... ) |
---|
216 | { |
---|
217 | va_list params; |
---|
218 | char *text; |
---|
219 | |
---|
220 | va_start( params, format ); |
---|
221 | text = g_strdup_vprintf( format, params ); |
---|
222 | va_end( params ); |
---|
223 | |
---|
224 | if( ic->flags & OPT_LOGGED_IN ) |
---|
225 | serv_got_crap( ic, "%s", text ); |
---|
226 | else |
---|
227 | serv_got_crap( ic, "Logging in: %s", text ); |
---|
228 | |
---|
229 | g_free( text ); |
---|
230 | } |
---|
231 | |
---|
232 | void imcb_error( struct im_connection *ic, char *format, ... ) |
---|
233 | { |
---|
234 | va_list params; |
---|
235 | char *text; |
---|
236 | |
---|
237 | va_start( params, format ); |
---|
238 | text = g_strdup_vprintf( format, params ); |
---|
239 | va_end( params ); |
---|
240 | |
---|
241 | if( ic->flags & OPT_LOGGED_IN ) |
---|
242 | serv_got_crap( ic, "Error: %s", text ); |
---|
243 | else |
---|
244 | serv_got_crap( ic, "Couldn't log in: %s", text ); |
---|
245 | |
---|
246 | g_free( text ); |
---|
247 | } |
---|
248 | |
---|
249 | static gboolean send_keepalive( gpointer d, gint fd, b_input_condition cond ) |
---|
250 | { |
---|
251 | struct im_connection *ic = d; |
---|
252 | |
---|
253 | if( ic->acc->prpl->keepalive ) |
---|
254 | ic->acc->prpl->keepalive( ic ); |
---|
255 | |
---|
256 | return TRUE; |
---|
257 | } |
---|
258 | |
---|
259 | void imcb_connected( struct im_connection *ic ) |
---|
260 | { |
---|
261 | irc_t *irc = ic->irc; |
---|
262 | struct chat *c; |
---|
263 | user_t *u; |
---|
264 | |
---|
265 | /* MSN servers sometimes redirect you to a different server and do |
---|
266 | the whole login sequence again, so these "late" calls to this |
---|
267 | function should be handled correctly. (IOW, ignored) */ |
---|
268 | if( ic->flags & OPT_LOGGED_IN ) |
---|
269 | return; |
---|
270 | |
---|
271 | u = user_find( ic->irc, ic->irc->nick ); |
---|
272 | |
---|
273 | imcb_log( ic, "Logged in" ); |
---|
274 | |
---|
275 | ic->keepalive = b_timeout_add( 60000, send_keepalive, ic ); |
---|
276 | ic->flags |= OPT_LOGGED_IN; |
---|
277 | |
---|
278 | /* Necessary to send initial presence status, even if we're not away. */ |
---|
279 | imc_away_send_update( ic ); |
---|
280 | |
---|
281 | /* Apparently we're connected successfully, so reset the |
---|
282 | exponential backoff timer. */ |
---|
283 | ic->acc->auto_reconnect_delay = 0; |
---|
284 | |
---|
285 | for( c = irc->chatrooms; c; c = c->next ) |
---|
286 | { |
---|
287 | if( c->acc != ic->acc ) |
---|
288 | continue; |
---|
289 | |
---|
290 | if( set_getbool( &c->set, "auto_join" ) ) |
---|
291 | chat_join( irc, c, NULL ); |
---|
292 | } |
---|
293 | } |
---|
294 | |
---|
295 | gboolean auto_reconnect( gpointer data, gint fd, b_input_condition cond ) |
---|
296 | { |
---|
297 | account_t *a = data; |
---|
298 | |
---|
299 | a->reconnect = 0; |
---|
300 | account_on( a->irc, a ); |
---|
301 | |
---|
302 | return( FALSE ); /* Only have to run the timeout once */ |
---|
303 | } |
---|
304 | |
---|
305 | void cancel_auto_reconnect( account_t *a ) |
---|
306 | { |
---|
307 | b_event_remove( a->reconnect ); |
---|
308 | a->reconnect = 0; |
---|
309 | } |
---|
310 | |
---|
311 | void imc_logout( struct im_connection *ic, int allow_reconnect ) |
---|
312 | { |
---|
313 | irc_t *irc = ic->irc; |
---|
314 | user_t *t, *u; |
---|
315 | account_t *a; |
---|
316 | int delay; |
---|
317 | |
---|
318 | /* Nested calls might happen sometimes, this is probably the best |
---|
319 | place to catch them. */ |
---|
320 | if( ic->flags & OPT_LOGGING_OUT ) |
---|
321 | return; |
---|
322 | else |
---|
323 | ic->flags |= OPT_LOGGING_OUT; |
---|
324 | |
---|
325 | imcb_log( ic, "Signing off.." ); |
---|
326 | |
---|
327 | b_event_remove( ic->keepalive ); |
---|
328 | ic->keepalive = 0; |
---|
329 | ic->acc->prpl->logout( ic ); |
---|
330 | b_event_remove( ic->inpa ); |
---|
331 | |
---|
332 | g_free( ic->away ); |
---|
333 | ic->away = NULL; |
---|
334 | |
---|
335 | u = irc->users; |
---|
336 | while( u ) |
---|
337 | { |
---|
338 | if( u->ic == ic ) |
---|
339 | { |
---|
340 | t = u->next; |
---|
341 | user_del( irc, u->nick ); |
---|
342 | u = t; |
---|
343 | } |
---|
344 | else |
---|
345 | u = u->next; |
---|
346 | } |
---|
347 | |
---|
348 | query_del_by_conn( ic->irc, ic ); |
---|
349 | |
---|
350 | for( a = irc->accounts; a; a = a->next ) |
---|
351 | if( a->ic == ic ) |
---|
352 | break; |
---|
353 | |
---|
354 | if( !a ) |
---|
355 | { |
---|
356 | /* Uhm... This is very sick. */ |
---|
357 | } |
---|
358 | else if( allow_reconnect && set_getbool( &irc->set, "auto_reconnect" ) && |
---|
359 | set_getbool( &a->set, "auto_reconnect" ) && |
---|
360 | ( delay = account_reconnect_delay( a ) ) > 0 ) |
---|
361 | { |
---|
362 | imcb_log( ic, "Reconnecting in %d seconds..", delay ); |
---|
363 | a->reconnect = b_timeout_add( delay * 1000, auto_reconnect, a ); |
---|
364 | } |
---|
365 | |
---|
366 | imc_free( ic ); |
---|
367 | } |
---|
368 | |
---|
369 | |
---|
370 | /* dialogs.c */ |
---|
371 | |
---|
372 | void imcb_ask( struct im_connection *ic, char *msg, void *data, |
---|
373 | query_callback doit, query_callback dont ) |
---|
374 | { |
---|
375 | query_add( ic->irc, ic, msg, doit, dont, data ); |
---|
376 | } |
---|
377 | |
---|
378 | |
---|
379 | /* list.c */ |
---|
380 | |
---|
381 | void imcb_add_buddy( struct im_connection *ic, char *handle, char *group ) |
---|
382 | { |
---|
383 | user_t *u; |
---|
384 | char nick[MAX_NICK_LENGTH+1], *s; |
---|
385 | irc_t *irc = ic->irc; |
---|
386 | |
---|
387 | if( user_findhandle( ic, handle ) ) |
---|
388 | { |
---|
389 | if( set_getbool( &irc->set, "debug" ) ) |
---|
390 | imcb_log( ic, "User already exists, ignoring add request: %s", handle ); |
---|
391 | |
---|
392 | return; |
---|
393 | |
---|
394 | /* Buddy seems to exist already. Let's ignore this request then... |
---|
395 | Eventually subsequent calls to this function *should* be possible |
---|
396 | when a buddy is in multiple groups. But for now BitlBee doesn't |
---|
397 | even support groups so let's silently ignore this for now. */ |
---|
398 | } |
---|
399 | |
---|
400 | memset( nick, 0, MAX_NICK_LENGTH + 1 ); |
---|
401 | strcpy( nick, nick_get( ic->acc, handle ) ); |
---|
402 | |
---|
403 | u = user_add( ic->irc, nick ); |
---|
404 | |
---|
405 | // if( !realname || !*realname ) realname = nick; |
---|
406 | // u->realname = g_strdup( realname ); |
---|
407 | |
---|
408 | if( ( s = strchr( handle, '@' ) ) ) |
---|
409 | { |
---|
410 | u->host = g_strdup( s + 1 ); |
---|
411 | u->user = g_strndup( handle, s - handle ); |
---|
412 | } |
---|
413 | else if( ic->acc->server ) |
---|
414 | { |
---|
415 | u->host = g_strdup( ic->acc->server ); |
---|
416 | u->user = g_strdup( handle ); |
---|
417 | |
---|
418 | /* s/ /_/ ... important for AOL screennames */ |
---|
419 | for( s = u->user; *s; s ++ ) |
---|
420 | if( *s == ' ' ) |
---|
421 | *s = '_'; |
---|
422 | } |
---|
423 | else |
---|
424 | { |
---|
425 | u->host = g_strdup( ic->acc->prpl->name ); |
---|
426 | u->user = g_strdup( handle ); |
---|
427 | } |
---|
428 | |
---|
429 | u->ic = ic; |
---|
430 | u->handle = g_strdup( handle ); |
---|
431 | if( group ) u->group = g_strdup( group ); |
---|
432 | u->send_handler = buddy_send_handler; |
---|
433 | u->last_typing_notice = 0; |
---|
434 | } |
---|
435 | |
---|
436 | struct buddy *imcb_find_buddy( struct im_connection *ic, char *handle ) |
---|
437 | { |
---|
438 | static struct buddy b[1]; |
---|
439 | user_t *u; |
---|
440 | |
---|
441 | u = user_findhandle( ic, handle ); |
---|
442 | |
---|
443 | if( !u ) |
---|
444 | return( NULL ); |
---|
445 | |
---|
446 | memset( b, 0, sizeof( b ) ); |
---|
447 | strncpy( b->name, handle, 80 ); |
---|
448 | strncpy( b->show, u->realname, BUDDY_ALIAS_MAXLEN ); |
---|
449 | b->present = u->online; |
---|
450 | b->ic = u->ic; |
---|
451 | |
---|
452 | return( b ); |
---|
453 | } |
---|
454 | |
---|
455 | void imcb_rename_buddy( struct im_connection *ic, char *handle, char *realname ) |
---|
456 | { |
---|
457 | user_t *u = user_findhandle( ic, handle ); |
---|
458 | |
---|
459 | if( !u || !realname ) return; |
---|
460 | |
---|
461 | if( g_strcasecmp( u->realname, realname ) != 0 ) |
---|
462 | { |
---|
463 | if( u->realname != u->nick ) g_free( u->realname ); |
---|
464 | |
---|
465 | u->realname = g_strdup( realname ); |
---|
466 | |
---|
467 | if( ( ic->flags & OPT_LOGGED_IN ) && set_getbool( &ic->irc->set, "display_namechanges" ) ) |
---|
468 | imcb_log( ic, "User `%s' changed name to `%s'", u->nick, u->realname ); |
---|
469 | } |
---|
470 | } |
---|
471 | |
---|
472 | void imcb_remove_buddy( struct im_connection *ic, char *handle, char *group ) |
---|
473 | { |
---|
474 | user_t *u; |
---|
475 | |
---|
476 | if( ( u = user_findhandle( ic, handle ) ) ) |
---|
477 | user_del( ic->irc, u->nick ); |
---|
478 | } |
---|
479 | |
---|
480 | /* Mainly meant for ICQ (and now also for Jabber conferences) to allow IM |
---|
481 | modules to suggest a nickname for a handle. */ |
---|
482 | void imcb_buddy_nick_hint( struct im_connection *ic, char *handle, char *nick ) |
---|
483 | { |
---|
484 | user_t *u = user_findhandle( ic, handle ); |
---|
485 | char newnick[MAX_NICK_LENGTH+1], *orig_nick; |
---|
486 | |
---|
487 | if( u && !u->online && !nick_saved( ic->acc, handle ) ) |
---|
488 | { |
---|
489 | /* Only do this if the person isn't online yet (which should |
---|
490 | be the case if we just added it) and if the user hasn't |
---|
491 | assigned a nickname to this buddy already. */ |
---|
492 | |
---|
493 | strncpy( newnick, nick, MAX_NICK_LENGTH ); |
---|
494 | newnick[MAX_NICK_LENGTH] = 0; |
---|
495 | |
---|
496 | /* Some processing to make sure this string is a valid IRC nickname. */ |
---|
497 | nick_strip( newnick ); |
---|
498 | if( set_getbool( &ic->irc->set, "lcnicks" ) ) |
---|
499 | nick_lc( newnick ); |
---|
500 | |
---|
501 | if( strcmp( u->nick, newnick ) != 0 ) |
---|
502 | { |
---|
503 | /* Only do this if newnick is different from the current one. |
---|
504 | If rejoining a channel, maybe we got this nick already |
---|
505 | (and dedupe would only add an underscore. */ |
---|
506 | nick_dedupe( ic->acc, handle, newnick ); |
---|
507 | |
---|
508 | /* u->nick will be freed halfway the process, so it can't be |
---|
509 | passed as an argument. */ |
---|
510 | orig_nick = g_strdup( u->nick ); |
---|
511 | user_rename( ic->irc, orig_nick, newnick ); |
---|
512 | g_free( orig_nick ); |
---|
513 | } |
---|
514 | } |
---|
515 | } |
---|
516 | |
---|
517 | |
---|
518 | struct imcb_ask_cb_data |
---|
519 | { |
---|
520 | struct im_connection *ic; |
---|
521 | char *handle; |
---|
522 | }; |
---|
523 | |
---|
524 | static void imcb_ask_auth_cb_no( void *data ) |
---|
525 | { |
---|
526 | struct imcb_ask_cb_data *cbd = data; |
---|
527 | |
---|
528 | cbd->ic->acc->prpl->auth_deny( cbd->ic, cbd->handle ); |
---|
529 | |
---|
530 | g_free( cbd->handle ); |
---|
531 | g_free( cbd ); |
---|
532 | } |
---|
533 | |
---|
534 | static void imcb_ask_auth_cb_yes( void *data ) |
---|
535 | { |
---|
536 | struct imcb_ask_cb_data *cbd = data; |
---|
537 | |
---|
538 | cbd->ic->acc->prpl->auth_allow( cbd->ic, cbd->handle ); |
---|
539 | |
---|
540 | g_free( cbd->handle ); |
---|
541 | g_free( cbd ); |
---|
542 | } |
---|
543 | |
---|
544 | void imcb_ask_auth( struct im_connection *ic, const char *handle, const char *realname ) |
---|
545 | { |
---|
546 | struct imcb_ask_cb_data *data = g_new0( struct imcb_ask_cb_data, 1 ); |
---|
547 | char *s, *realname_ = NULL; |
---|
548 | |
---|
549 | if( realname != NULL ) |
---|
550 | realname_ = g_strdup_printf( " (%s)", realname ); |
---|
551 | |
---|
552 | s = g_strdup_printf( "The user %s%s wants to add you to his/her buddy list.", |
---|
553 | handle, realname_ ?: "" ); |
---|
554 | |
---|
555 | g_free( realname_ ); |
---|
556 | |
---|
557 | data->ic = ic; |
---|
558 | data->handle = g_strdup( handle ); |
---|
559 | query_add( ic->irc, ic, s, imcb_ask_auth_cb_yes, imcb_ask_auth_cb_no, data ); |
---|
560 | } |
---|
561 | |
---|
562 | |
---|
563 | static void imcb_ask_add_cb_no( void *data ) |
---|
564 | { |
---|
565 | g_free( ((struct imcb_ask_cb_data*)data)->handle ); |
---|
566 | g_free( data ); |
---|
567 | } |
---|
568 | |
---|
569 | static void imcb_ask_add_cb_yes( void *data ) |
---|
570 | { |
---|
571 | struct imcb_ask_cb_data *cbd = data; |
---|
572 | |
---|
573 | cbd->ic->acc->prpl->add_buddy( cbd->ic, cbd->handle, NULL ); |
---|
574 | |
---|
575 | return imcb_ask_add_cb_no( data ); |
---|
576 | } |
---|
577 | |
---|
578 | void imcb_ask_add( struct im_connection *ic, const char *handle, const char *realname ) |
---|
579 | { |
---|
580 | struct imcb_ask_cb_data *data = g_new0( struct imcb_ask_cb_data, 1 ); |
---|
581 | char *s; |
---|
582 | |
---|
583 | /* TODO: Make a setting for this! */ |
---|
584 | if( user_findhandle( ic, handle ) != NULL ) |
---|
585 | return; |
---|
586 | |
---|
587 | s = g_strdup_printf( "The user %s is not in your buddy list yet. Do you want to add him/her now?", handle ); |
---|
588 | |
---|
589 | data->ic = ic; |
---|
590 | data->handle = g_strdup( handle ); |
---|
591 | query_add( ic->irc, ic, s, imcb_ask_add_cb_yes, imcb_ask_add_cb_no, data ); |
---|
592 | } |
---|
593 | |
---|
594 | |
---|
595 | /* server.c */ |
---|
596 | |
---|
597 | void imcb_buddy_status( struct im_connection *ic, const char *handle, int flags, const char *state, const char *message ) |
---|
598 | { |
---|
599 | user_t *u; |
---|
600 | int oa, oo; |
---|
601 | |
---|
602 | u = user_findhandle( ic, (char*) handle ); |
---|
603 | |
---|
604 | if( !u ) |
---|
605 | { |
---|
606 | if( g_strcasecmp( set_getstr( &ic->irc->set, "handle_unknown" ), "add" ) == 0 ) |
---|
607 | { |
---|
608 | imcb_add_buddy( ic, (char*) handle, NULL ); |
---|
609 | u = user_findhandle( ic, (char*) handle ); |
---|
610 | } |
---|
611 | else |
---|
612 | { |
---|
613 | if( set_getbool( &ic->irc->set, "debug" ) || g_strcasecmp( set_getstr( &ic->irc->set, "handle_unknown" ), "ignore" ) != 0 ) |
---|
614 | { |
---|
615 | imcb_log( ic, "imcb_buddy_status() for unknown handle %s:", handle ); |
---|
616 | imcb_log( ic, "flags = %d, state = %s, message = %s", flags, |
---|
617 | state ? state : "NULL", message ? message : "NULL" ); |
---|
618 | } |
---|
619 | |
---|
620 | return; |
---|
621 | } |
---|
622 | } |
---|
623 | |
---|
624 | oa = u->away != NULL; |
---|
625 | oo = u->online; |
---|
626 | |
---|
627 | if( u->away ) |
---|
628 | { |
---|
629 | g_free( u->away ); |
---|
630 | u->away = NULL; |
---|
631 | } |
---|
632 | |
---|
633 | if( ( flags & OPT_LOGGED_IN ) && !u->online ) |
---|
634 | { |
---|
635 | irc_spawn( ic->irc, u ); |
---|
636 | u->online = 1; |
---|
637 | } |
---|
638 | else if( !( flags & OPT_LOGGED_IN ) && u->online ) |
---|
639 | { |
---|
640 | struct groupchat *c; |
---|
641 | |
---|
642 | irc_kill( ic->irc, u ); |
---|
643 | u->online = 0; |
---|
644 | |
---|
645 | /* Remove him/her from the groupchats to prevent PART messages after he/she QUIT already */ |
---|
646 | for( c = ic->groupchats; c; c = c->next ) |
---|
647 | remove_chat_buddy_silent( c, handle ); |
---|
648 | } |
---|
649 | |
---|
650 | if( flags & OPT_AWAY ) |
---|
651 | { |
---|
652 | if( state && message ) |
---|
653 | { |
---|
654 | u->away = g_strdup_printf( "%s (%s)", state, message ); |
---|
655 | } |
---|
656 | else if( state ) |
---|
657 | { |
---|
658 | u->away = g_strdup( state ); |
---|
659 | } |
---|
660 | else if( message ) |
---|
661 | { |
---|
662 | u->away = g_strdup( message ); |
---|
663 | } |
---|
664 | else |
---|
665 | { |
---|
666 | u->away = g_strdup( "Away" ); |
---|
667 | } |
---|
668 | } |
---|
669 | /* else waste_any_state_information_for_now(); */ |
---|
670 | |
---|
671 | /* LISPy... */ |
---|
672 | if( ( set_getbool( &ic->irc->set, "away_devoice" ) ) && /* Don't do a thing when user doesn't want it */ |
---|
673 | ( u->online ) && /* Don't touch offline people */ |
---|
674 | ( ( ( u->online != oo ) && !u->away ) || /* Voice joining people */ |
---|
675 | ( ( u->online == oo ) && ( oa == !u->away ) ) ) ) /* (De)voice people changing state */ |
---|
676 | { |
---|
677 | char *from; |
---|
678 | |
---|
679 | if( set_getbool( &ic->irc->set, "simulate_netsplit" ) ) |
---|
680 | { |
---|
681 | from = g_strdup( ic->irc->myhost ); |
---|
682 | } |
---|
683 | else |
---|
684 | { |
---|
685 | from = g_strdup_printf( "%s!%s@%s", ic->irc->mynick, ic->irc->mynick, |
---|
686 | ic->irc->myhost ); |
---|
687 | } |
---|
688 | irc_write( ic->irc, ":%s MODE %s %cv %s", from, ic->irc->channel, |
---|
689 | u->away?'-':'+', u->nick ); |
---|
690 | g_free( from ); |
---|
691 | } |
---|
692 | } |
---|
693 | |
---|
694 | void imcb_buddy_msg( struct im_connection *ic, char *handle, char *msg, uint32_t flags, time_t sent_at ) |
---|
695 | { |
---|
696 | irc_t *irc = ic->irc; |
---|
697 | char *wrapped; |
---|
698 | user_t *u; |
---|
699 | |
---|
700 | u = user_findhandle( ic, handle ); |
---|
701 | |
---|
702 | if( !u ) |
---|
703 | { |
---|
704 | char *h = set_getstr( &irc->set, "handle_unknown" ); |
---|
705 | |
---|
706 | if( g_strcasecmp( h, "ignore" ) == 0 ) |
---|
707 | { |
---|
708 | if( set_getbool( &irc->set, "debug" ) ) |
---|
709 | imcb_log( ic, "Ignoring message from unknown handle %s", handle ); |
---|
710 | |
---|
711 | return; |
---|
712 | } |
---|
713 | else if( g_strncasecmp( h, "add", 3 ) == 0 ) |
---|
714 | { |
---|
715 | int private = set_getbool( &irc->set, "private" ); |
---|
716 | |
---|
717 | if( h[3] ) |
---|
718 | { |
---|
719 | if( g_strcasecmp( h + 3, "_private" ) == 0 ) |
---|
720 | private = 1; |
---|
721 | else if( g_strcasecmp( h + 3, "_channel" ) == 0 ) |
---|
722 | private = 0; |
---|
723 | } |
---|
724 | |
---|
725 | imcb_add_buddy( ic, handle, NULL ); |
---|
726 | u = user_findhandle( ic, handle ); |
---|
727 | u->is_private = private; |
---|
728 | } |
---|
729 | else |
---|
730 | { |
---|
731 | imcb_log( ic, "Message from unknown handle %s:", handle ); |
---|
732 | u = user_find( irc, irc->mynick ); |
---|
733 | } |
---|
734 | } |
---|
735 | |
---|
736 | if( ( g_strcasecmp( set_getstr( &ic->irc->set, "strip_html" ), "always" ) == 0 ) || |
---|
737 | ( ( ic->flags & OPT_DOES_HTML ) && set_getbool( &ic->irc->set, "strip_html" ) ) ) |
---|
738 | strip_html( msg ); |
---|
739 | |
---|
740 | wrapped = word_wrap( msg, 425 ); |
---|
741 | irc_msgfrom( irc, u->nick, wrapped ); |
---|
742 | g_free( wrapped ); |
---|
743 | } |
---|
744 | |
---|
745 | void imcb_buddy_typing( struct im_connection *ic, char *handle, uint32_t flags ) |
---|
746 | { |
---|
747 | user_t *u; |
---|
748 | |
---|
749 | if( !set_getbool( &ic->irc->set, "typing_notice" ) ) |
---|
750 | return; |
---|
751 | |
---|
752 | if( ( u = user_findhandle( ic, handle ) ) ) |
---|
753 | { |
---|
754 | char buf[256]; |
---|
755 | |
---|
756 | g_snprintf( buf, 256, "\1TYPING %d\1", ( flags >> 8 ) & 3 ); |
---|
757 | irc_privmsg( ic->irc, u, "PRIVMSG", ic->irc->nick, NULL, buf ); |
---|
758 | } |
---|
759 | } |
---|
760 | |
---|
761 | struct groupchat *imcb_chat_new( struct im_connection *ic, const char *handle ) |
---|
762 | { |
---|
763 | struct groupchat *c; |
---|
764 | |
---|
765 | /* This one just creates the conversation structure, user won't see anything yet */ |
---|
766 | |
---|
767 | if( ic->groupchats ) |
---|
768 | { |
---|
769 | for( c = ic->groupchats; c->next; c = c->next ); |
---|
770 | c = c->next = g_new0( struct groupchat, 1 ); |
---|
771 | } |
---|
772 | else |
---|
773 | ic->groupchats = c = g_new0( struct groupchat, 1 ); |
---|
774 | |
---|
775 | c->ic = ic; |
---|
776 | c->title = g_strdup( handle ); |
---|
777 | c->channel = g_strdup_printf( "&chat_%03d", ic->irc->c_id++ ); |
---|
778 | c->topic = g_strdup_printf( "BitlBee groupchat: \"%s\". Please keep in mind that root-commands won't work here. Have fun!", c->title ); |
---|
779 | |
---|
780 | if( set_getbool( &ic->irc->set, "debug" ) ) |
---|
781 | imcb_log( ic, "Creating new conversation: (id=%p,handle=%s)", c, handle ); |
---|
782 | |
---|
783 | return c; |
---|
784 | } |
---|
785 | |
---|
786 | void imcb_chat_free( struct groupchat *c ) |
---|
787 | { |
---|
788 | struct im_connection *ic = c->ic; |
---|
789 | struct groupchat *l; |
---|
790 | GList *ir; |
---|
791 | |
---|
792 | if( set_getbool( &ic->irc->set, "debug" ) ) |
---|
793 | imcb_log( ic, "You were removed from conversation %p", c ); |
---|
794 | |
---|
795 | if( c ) |
---|
796 | { |
---|
797 | if( c->joined ) |
---|
798 | { |
---|
799 | user_t *u, *r; |
---|
800 | |
---|
801 | r = user_find( ic->irc, ic->irc->mynick ); |
---|
802 | irc_privmsg( ic->irc, r, "PRIVMSG", c->channel, "", "Cleaning up channel, bye!" ); |
---|
803 | |
---|
804 | u = user_find( ic->irc, ic->irc->nick ); |
---|
805 | irc_kick( ic->irc, u, c->channel, r ); |
---|
806 | /* irc_part( ic->irc, u, c->channel ); */ |
---|
807 | } |
---|
808 | |
---|
809 | /* Find the previous chat in the linked list. */ |
---|
810 | for( l = ic->groupchats; l && l->next != c; l = l->next ); |
---|
811 | |
---|
812 | if( l ) |
---|
813 | l->next = c->next; |
---|
814 | else |
---|
815 | ic->groupchats = c->next; |
---|
816 | |
---|
817 | for( ir = c->in_room; ir; ir = ir->next ) |
---|
818 | g_free( ir->data ); |
---|
819 | g_list_free( c->in_room ); |
---|
820 | g_free( c->channel ); |
---|
821 | g_free( c->title ); |
---|
822 | g_free( c->topic ); |
---|
823 | g_free( c ); |
---|
824 | } |
---|
825 | } |
---|
826 | |
---|
827 | void imcb_chat_msg( struct groupchat *c, char *who, char *msg, uint32_t flags, time_t sent_at ) |
---|
828 | { |
---|
829 | struct im_connection *ic = c->ic; |
---|
830 | char *wrapped; |
---|
831 | user_t *u; |
---|
832 | |
---|
833 | /* Gaim sends own messages through this too. IRC doesn't want this, so kill them */ |
---|
834 | if( g_strcasecmp( who, ic->acc->user ) == 0 ) |
---|
835 | return; |
---|
836 | |
---|
837 | u = user_findhandle( ic, who ); |
---|
838 | |
---|
839 | if( ( g_strcasecmp( set_getstr( &ic->irc->set, "strip_html" ), "always" ) == 0 ) || |
---|
840 | ( ( ic->flags & OPT_DOES_HTML ) && set_getbool( &ic->irc->set, "strip_html" ) ) ) |
---|
841 | strip_html( msg ); |
---|
842 | |
---|
843 | wrapped = word_wrap( msg, 425 ); |
---|
844 | if( c && u ) |
---|
845 | { |
---|
846 | irc_privmsg( ic->irc, u, "PRIVMSG", c->channel, "", wrapped ); |
---|
847 | } |
---|
848 | else |
---|
849 | { |
---|
850 | imcb_log( ic, "Message from/to conversation %s@%p (unknown conv/user): %s", who, c, wrapped ); |
---|
851 | } |
---|
852 | g_free( wrapped ); |
---|
853 | } |
---|
854 | |
---|
855 | void imcb_chat_log( struct groupchat *c, char *format, ... ) |
---|
856 | { |
---|
857 | irc_t *irc = c->ic->irc; |
---|
858 | va_list params; |
---|
859 | char *text; |
---|
860 | user_t *u; |
---|
861 | |
---|
862 | va_start( params, format ); |
---|
863 | text = g_strdup_vprintf( format, params ); |
---|
864 | va_end( params ); |
---|
865 | |
---|
866 | u = user_find( irc, irc->mynick ); |
---|
867 | |
---|
868 | irc_privmsg( irc, u, "PRIVMSG", c->channel, "System message: ", text ); |
---|
869 | |
---|
870 | g_free( text ); |
---|
871 | } |
---|
872 | |
---|
873 | void imcb_chat_topic( struct groupchat *c, char *who, char *topic, time_t set_at ) |
---|
874 | { |
---|
875 | struct im_connection *ic = c->ic; |
---|
876 | user_t *u = NULL; |
---|
877 | |
---|
878 | if( who == NULL) |
---|
879 | u = user_find( ic->irc, ic->irc->mynick ); |
---|
880 | else if( g_strcasecmp( who, ic->acc->user ) == 0 ) |
---|
881 | u = user_find( ic->irc, ic->irc->nick ); |
---|
882 | else |
---|
883 | u = user_findhandle( ic, who ); |
---|
884 | |
---|
885 | if( ( g_strcasecmp( set_getstr( &ic->irc->set, "strip_html" ), "always" ) == 0 ) || |
---|
886 | ( ( ic->flags & OPT_DOES_HTML ) && set_getbool( &ic->irc->set, "strip_html" ) ) ) |
---|
887 | strip_html( topic ); |
---|
888 | |
---|
889 | g_free( c->topic ); |
---|
890 | c->topic = g_strdup( topic ); |
---|
891 | |
---|
892 | if( c->joined && u ) |
---|
893 | irc_write( ic->irc, ":%s!%s@%s TOPIC %s :%s", u->nick, u->user, u->host, c->channel, topic ); |
---|
894 | } |
---|
895 | |
---|
896 | |
---|
897 | /* buddy_chat.c */ |
---|
898 | |
---|
899 | void imcb_chat_add_buddy( struct groupchat *b, char *handle ) |
---|
900 | { |
---|
901 | user_t *u = user_findhandle( b->ic, handle ); |
---|
902 | int me = 0; |
---|
903 | |
---|
904 | if( set_getbool( &b->ic->irc->set, "debug" ) ) |
---|
905 | imcb_log( b->ic, "User %s added to conversation %p", handle, b ); |
---|
906 | |
---|
907 | /* It might be yourself! */ |
---|
908 | if( b->ic->acc->prpl->handle_cmp( handle, b->ic->acc->user ) == 0 ) |
---|
909 | { |
---|
910 | u = user_find( b->ic->irc, b->ic->irc->nick ); |
---|
911 | if( !b->joined ) |
---|
912 | irc_join( b->ic->irc, u, b->channel ); |
---|
913 | b->joined = me = 1; |
---|
914 | } |
---|
915 | |
---|
916 | /* Most protocols allow people to join, even when they're not in |
---|
917 | your contact list. Try to handle that here */ |
---|
918 | if( !u ) |
---|
919 | { |
---|
920 | imcb_add_buddy( b->ic, handle, NULL ); |
---|
921 | u = user_findhandle( b->ic, handle ); |
---|
922 | } |
---|
923 | |
---|
924 | /* Add the handle to the room userlist, if it's not 'me' */ |
---|
925 | if( !me ) |
---|
926 | { |
---|
927 | if( b->joined ) |
---|
928 | irc_join( b->ic->irc, u, b->channel ); |
---|
929 | b->in_room = g_list_append( b->in_room, g_strdup( handle ) ); |
---|
930 | } |
---|
931 | } |
---|
932 | |
---|
933 | /* This function is one BIG hack... :-( EREWRITE */ |
---|
934 | void imcb_chat_remove_buddy( struct groupchat *b, char *handle, char *reason ) |
---|
935 | { |
---|
936 | user_t *u; |
---|
937 | int me = 0; |
---|
938 | |
---|
939 | if( set_getbool( &b->ic->irc->set, "debug" ) ) |
---|
940 | imcb_log( b->ic, "User %s removed from conversation %p (%s)", handle, b, reason ? reason : "" ); |
---|
941 | |
---|
942 | /* It might be yourself! */ |
---|
943 | if( g_strcasecmp( handle, b->ic->acc->user ) == 0 ) |
---|
944 | { |
---|
945 | if( b->joined == 0 ) |
---|
946 | return; |
---|
947 | |
---|
948 | u = user_find( b->ic->irc, b->ic->irc->nick ); |
---|
949 | b->joined = 0; |
---|
950 | me = 1; |
---|
951 | } |
---|
952 | else |
---|
953 | { |
---|
954 | u = user_findhandle( b->ic, handle ); |
---|
955 | } |
---|
956 | |
---|
957 | if( me || ( remove_chat_buddy_silent( b, handle ) && b->joined && u ) ) |
---|
958 | irc_part( b->ic->irc, u, b->channel ); |
---|
959 | } |
---|
960 | |
---|
961 | static int remove_chat_buddy_silent( struct groupchat *b, const char *handle ) |
---|
962 | { |
---|
963 | GList *i; |
---|
964 | |
---|
965 | /* Find the handle in the room userlist and shoot it */ |
---|
966 | i = b->in_room; |
---|
967 | while( i ) |
---|
968 | { |
---|
969 | if( g_strcasecmp( handle, i->data ) == 0 ) |
---|
970 | { |
---|
971 | g_free( i->data ); |
---|
972 | b->in_room = g_list_remove( b->in_room, i->data ); |
---|
973 | return( 1 ); |
---|
974 | } |
---|
975 | |
---|
976 | i = i->next; |
---|
977 | } |
---|
978 | |
---|
979 | return( 0 ); |
---|
980 | } |
---|
981 | |
---|
982 | |
---|
983 | /* Misc. BitlBee stuff which shouldn't really be here */ |
---|
984 | |
---|
985 | char *set_eval_away_devoice( set_t *set, char *value ) |
---|
986 | { |
---|
987 | irc_t *irc = set->data; |
---|
988 | int st; |
---|
989 | |
---|
990 | if( !is_bool( value ) ) |
---|
991 | return SET_INVALID; |
---|
992 | |
---|
993 | st = bool2int( value ); |
---|
994 | |
---|
995 | /* Horror.... */ |
---|
996 | |
---|
997 | if( st != set_getbool( &irc->set, "away_devoice" ) ) |
---|
998 | { |
---|
999 | char list[80] = ""; |
---|
1000 | user_t *u = irc->users; |
---|
1001 | int i = 0, count = 0; |
---|
1002 | char pm; |
---|
1003 | char v[80]; |
---|
1004 | |
---|
1005 | if( st ) |
---|
1006 | pm = '+'; |
---|
1007 | else |
---|
1008 | pm = '-'; |
---|
1009 | |
---|
1010 | while( u ) |
---|
1011 | { |
---|
1012 | if( u->ic && u->online && !u->away ) |
---|
1013 | { |
---|
1014 | if( ( strlen( list ) + strlen( u->nick ) ) >= 79 ) |
---|
1015 | { |
---|
1016 | for( i = 0; i < count; v[i++] = 'v' ); v[i] = 0; |
---|
1017 | irc_write( irc, ":%s MODE %s %c%s%s", |
---|
1018 | irc->myhost, |
---|
1019 | irc->channel, pm, v, list ); |
---|
1020 | |
---|
1021 | *list = 0; |
---|
1022 | count = 0; |
---|
1023 | } |
---|
1024 | |
---|
1025 | sprintf( list + strlen( list ), " %s", u->nick ); |
---|
1026 | count ++; |
---|
1027 | } |
---|
1028 | u = u->next; |
---|
1029 | } |
---|
1030 | |
---|
1031 | /* $v = 'v' x $i */ |
---|
1032 | for( i = 0; i < count; v[i++] = 'v' ); v[i] = 0; |
---|
1033 | irc_write( irc, ":%s MODE %s %c%s%s", irc->myhost, |
---|
1034 | irc->channel, pm, v, list ); |
---|
1035 | } |
---|
1036 | |
---|
1037 | return value; |
---|
1038 | } |
---|
1039 | |
---|
1040 | |
---|
1041 | |
---|
1042 | |
---|
1043 | /* The plan is to not allow straight calls to prpl functions anymore, but do |
---|
1044 | them all from some wrappers. We'll start to define some down here: */ |
---|
1045 | |
---|
1046 | int imc_buddy_msg( struct im_connection *ic, char *handle, char *msg, int flags ) |
---|
1047 | { |
---|
1048 | char *buf = NULL; |
---|
1049 | int st; |
---|
1050 | |
---|
1051 | if( ( ic->flags & OPT_DOES_HTML ) && ( g_strncasecmp( msg, "<html>", 6 ) != 0 ) ) |
---|
1052 | { |
---|
1053 | buf = escape_html( msg ); |
---|
1054 | msg = buf; |
---|
1055 | } |
---|
1056 | |
---|
1057 | st = ic->acc->prpl->buddy_msg( ic, handle, msg, flags ); |
---|
1058 | g_free( buf ); |
---|
1059 | |
---|
1060 | return st; |
---|
1061 | } |
---|
1062 | |
---|
1063 | int imc_chat_msg( struct groupchat *c, char *msg, int flags ) |
---|
1064 | { |
---|
1065 | char *buf = NULL; |
---|
1066 | |
---|
1067 | if( ( c->ic->flags & OPT_DOES_HTML ) && ( g_strncasecmp( msg, "<html>", 6 ) != 0 ) ) |
---|
1068 | { |
---|
1069 | buf = escape_html( msg ); |
---|
1070 | msg = buf; |
---|
1071 | } |
---|
1072 | |
---|
1073 | c->ic->acc->prpl->chat_msg( c, msg, flags ); |
---|
1074 | g_free( buf ); |
---|
1075 | |
---|
1076 | return 1; |
---|
1077 | } |
---|
1078 | |
---|
1079 | static char *imc_away_state_find( GList *gcm, char *away, char **message ); |
---|
1080 | |
---|
1081 | int imc_away_send_update( struct im_connection *ic ) |
---|
1082 | { |
---|
1083 | char *away, *msg; |
---|
1084 | |
---|
1085 | away = set_getstr( &ic->acc->set, "away" ) ? |
---|
1086 | : set_getstr( &ic->irc->set, "away" ); |
---|
1087 | if( away && *away ) |
---|
1088 | { |
---|
1089 | GList *m = ic->acc->prpl->away_states( ic ); |
---|
1090 | msg = ic->acc->flags & ACC_FLAG_AWAY_MESSAGE ? away : NULL; |
---|
1091 | away = imc_away_state_find( m, away, &msg ) ? : m->data; |
---|
1092 | } |
---|
1093 | else if( ic->acc->flags & ACC_FLAG_STATUS_MESSAGE ) |
---|
1094 | { |
---|
1095 | away = NULL; |
---|
1096 | msg = set_getstr( &ic->acc->set, "status" ) ? |
---|
1097 | : set_getstr( &ic->irc->set, "status" ); |
---|
1098 | } |
---|
1099 | |
---|
1100 | ic->acc->prpl->set_away( ic, away, msg ); |
---|
1101 | |
---|
1102 | return 1; |
---|
1103 | } |
---|
1104 | |
---|
1105 | static char *imc_away_alias_list[8][5] = |
---|
1106 | { |
---|
1107 | { "Away from computer", "Away", "Extended away", NULL }, |
---|
1108 | { "NA", "N/A", "Not available", NULL }, |
---|
1109 | { "Busy", "Do not disturb", "DND", "Occupied", NULL }, |
---|
1110 | { "Be right back", "BRB", NULL }, |
---|
1111 | { "On the phone", "Phone", "On phone", NULL }, |
---|
1112 | { "Out to lunch", "Lunch", "Food", NULL }, |
---|
1113 | { "Invisible", "Hidden" }, |
---|
1114 | { NULL } |
---|
1115 | }; |
---|
1116 | |
---|
1117 | static char *imc_away_state_find( GList *gcm, char *away, char **message ) |
---|
1118 | { |
---|
1119 | GList *m; |
---|
1120 | int i, j; |
---|
1121 | |
---|
1122 | for( m = gcm; m; m = m->next ) |
---|
1123 | if( g_strncasecmp( m->data, away, strlen( m->data ) ) == 0 ) |
---|
1124 | { |
---|
1125 | /* At least the Yahoo! module works better if message |
---|
1126 | contains no data unless it adds something to what |
---|
1127 | we have in state already. */ |
---|
1128 | if( strlen( m->data ) == strlen( away ) ) |
---|
1129 | *message = NULL; |
---|
1130 | |
---|
1131 | return m->data; |
---|
1132 | } |
---|
1133 | |
---|
1134 | for( i = 0; *imc_away_alias_list[i]; i ++ ) |
---|
1135 | { |
---|
1136 | int keep_message; |
---|
1137 | |
---|
1138 | for( j = 0; imc_away_alias_list[i][j]; j ++ ) |
---|
1139 | if( g_strncasecmp( away, imc_away_alias_list[i][j], strlen( imc_away_alias_list[i][j] ) ) == 0 ) |
---|
1140 | { |
---|
1141 | keep_message = strlen( away ) != strlen( imc_away_alias_list[i][j] ); |
---|
1142 | break; |
---|
1143 | } |
---|
1144 | |
---|
1145 | if( !imc_away_alias_list[i][j] ) /* If we reach the end, this row */ |
---|
1146 | continue; /* is not what we want. Next! */ |
---|
1147 | |
---|
1148 | /* Now find an entry in this row which exists in gcm */ |
---|
1149 | for( j = 0; imc_away_alias_list[i][j]; j ++ ) |
---|
1150 | { |
---|
1151 | for( m = gcm; m; m = m->next ) |
---|
1152 | if( g_strcasecmp( imc_away_alias_list[i][j], m->data ) == 0 ) |
---|
1153 | { |
---|
1154 | if( !keep_message ) |
---|
1155 | *message = NULL; |
---|
1156 | |
---|
1157 | return imc_away_alias_list[i][j]; |
---|
1158 | } |
---|
1159 | } |
---|
1160 | |
---|
1161 | /* No need to look further, apparently this state doesn't |
---|
1162 | have any good alias for this protocol. */ |
---|
1163 | break; |
---|
1164 | } |
---|
1165 | |
---|
1166 | return NULL; |
---|
1167 | } |
---|
1168 | |
---|
1169 | void imc_add_allow( struct im_connection *ic, char *handle ) |
---|
1170 | { |
---|
1171 | if( g_slist_find_custom( ic->permit, handle, (GCompareFunc) ic->acc->prpl->handle_cmp ) == NULL ) |
---|
1172 | { |
---|
1173 | ic->permit = g_slist_prepend( ic->permit, g_strdup( handle ) ); |
---|
1174 | } |
---|
1175 | |
---|
1176 | ic->acc->prpl->add_permit( ic, handle ); |
---|
1177 | } |
---|
1178 | |
---|
1179 | void imc_rem_allow( struct im_connection *ic, char *handle ) |
---|
1180 | { |
---|
1181 | GSList *l; |
---|
1182 | |
---|
1183 | if( ( l = g_slist_find_custom( ic->permit, handle, (GCompareFunc) ic->acc->prpl->handle_cmp ) ) ) |
---|
1184 | { |
---|
1185 | g_free( l->data ); |
---|
1186 | ic->permit = g_slist_delete_link( ic->permit, l ); |
---|
1187 | } |
---|
1188 | |
---|
1189 | ic->acc->prpl->rem_permit( ic, handle ); |
---|
1190 | } |
---|
1191 | |
---|
1192 | void imc_add_block( struct im_connection *ic, char *handle ) |
---|
1193 | { |
---|
1194 | if( g_slist_find_custom( ic->deny, handle, (GCompareFunc) ic->acc->prpl->handle_cmp ) == NULL ) |
---|
1195 | { |
---|
1196 | ic->deny = g_slist_prepend( ic->deny, g_strdup( handle ) ); |
---|
1197 | } |
---|
1198 | |
---|
1199 | ic->acc->prpl->add_deny( ic, handle ); |
---|
1200 | } |
---|
1201 | |
---|
1202 | void imc_rem_block( struct im_connection *ic, char *handle ) |
---|
1203 | { |
---|
1204 | GSList *l; |
---|
1205 | |
---|
1206 | if( ( l = g_slist_find_custom( ic->deny, handle, (GCompareFunc) ic->acc->prpl->handle_cmp ) ) ) |
---|
1207 | { |
---|
1208 | g_free( l->data ); |
---|
1209 | ic->deny = g_slist_delete_link( ic->deny, l ); |
---|
1210 | } |
---|
1211 | |
---|
1212 | ic->acc->prpl->rem_deny( ic, handle ); |
---|
1213 | } |
---|
1214 | |
---|
1215 | void imcb_clean_handle( struct im_connection *ic, char *handle ) |
---|
1216 | { |
---|
1217 | /* Accepts a handle and does whatever is necessary to make it |
---|
1218 | BitlBee-friendly. Currently this means removing everything |
---|
1219 | outside 33-127 (ASCII printable excl spaces), @ (only one |
---|
1220 | is allowed) and ! and : */ |
---|
1221 | char out[strlen(handle)+1]; |
---|
1222 | int s, d; |
---|
1223 | |
---|
1224 | s = d = 0; |
---|
1225 | while( handle[s] ) |
---|
1226 | { |
---|
1227 | if( handle[s] > ' ' && handle[s] != '!' && handle[s] != ':' && |
---|
1228 | ( handle[s] & 0x80 ) == 0 ) |
---|
1229 | { |
---|
1230 | if( handle[s] == '@' ) |
---|
1231 | { |
---|
1232 | /* See if we got an @ already? */ |
---|
1233 | out[d] = 0; |
---|
1234 | if( strchr( out, '@' ) ) |
---|
1235 | continue; |
---|
1236 | } |
---|
1237 | |
---|
1238 | out[d++] = handle[s]; |
---|
1239 | } |
---|
1240 | s ++; |
---|
1241 | } |
---|
1242 | out[d] = handle[s]; |
---|
1243 | |
---|
1244 | strcpy( handle, out ); |
---|
1245 | } |
---|