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