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