1 | /********************************************************************\ |
---|
2 | * BitlBee -- An IRC to other IM-networks gateway * |
---|
3 | * * |
---|
4 | * Copyright 2002-2004 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 | * Copyright 2002-2004 Wilmer van der Gaast <lintux@lintux.cx> |
---|
17 | */ |
---|
18 | |
---|
19 | /* |
---|
20 | This program is free software; you can redistribute it and/or modify |
---|
21 | it under the terms of the GNU General Public License as published by |
---|
22 | the Free Software Foundation; either version 2 of the License, or |
---|
23 | (at your option) any later version. |
---|
24 | |
---|
25 | This program is distributed in the hope that it will be useful, |
---|
26 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
27 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
28 | GNU General Public License for more details. |
---|
29 | |
---|
30 | You should have received a copy of the GNU General Public License with |
---|
31 | the Debian GNU/Linux distribution in /usr/share/common-licenses/GPL; |
---|
32 | if not, write to the Free Software Foundation, Inc., 59 Temple Place, |
---|
33 | Suite 330, Boston, MA 02111-1307 USA |
---|
34 | */ |
---|
35 | |
---|
36 | #define BITLBEE_CORE |
---|
37 | #include "nogaim.h" |
---|
38 | #include <ctype.h> |
---|
39 | #include <iconv.h> |
---|
40 | |
---|
41 | static char *proto_away_alias[7][5] = |
---|
42 | { |
---|
43 | { "Away from computer", "Away", "Extended away", NULL }, |
---|
44 | { "NA", "N/A", "Not available", NULL }, |
---|
45 | { "Busy", "Do not disturb", "DND", "Occupied", NULL }, |
---|
46 | { "Be right back", "BRB", NULL }, |
---|
47 | { "On the phone", "Phone", "On phone", NULL }, |
---|
48 | { "Out to lunch", "Lunch", "Food", NULL }, |
---|
49 | { NULL } |
---|
50 | }; |
---|
51 | static char *proto_away_alias_find( GList *gcm, char *away ); |
---|
52 | |
---|
53 | static int remove_chat_buddy_silent( struct conversation *b, char *handle ); |
---|
54 | |
---|
55 | GSList *connections; |
---|
56 | |
---|
57 | gboolean load_plugin(char *path) |
---|
58 | { |
---|
59 | void (*init_function) (void); |
---|
60 | |
---|
61 | GModule *mod = g_module_open(path, G_MODULE_BIND_LAZY); |
---|
62 | |
---|
63 | if(!mod) { |
---|
64 | log_message(LOGLVL_ERROR, "Can't find `%s', not loading", path); |
---|
65 | return FALSE; |
---|
66 | } |
---|
67 | |
---|
68 | if(!g_module_symbol(mod,"init_plugin",(gpointer *) &init_function)) { |
---|
69 | log_message(LOGLVL_WARNING, "Can't find function `init_plugin' in `%s'\n", path); |
---|
70 | return FALSE; |
---|
71 | } |
---|
72 | |
---|
73 | init_function(); |
---|
74 | |
---|
75 | return TRUE; |
---|
76 | } |
---|
77 | |
---|
78 | /* nogaim.c */ |
---|
79 | |
---|
80 | GList *protocols = NULL; |
---|
81 | |
---|
82 | void register_protocol (struct prpl *p) |
---|
83 | { |
---|
84 | protocols = g_list_append(protocols, p); |
---|
85 | } |
---|
86 | |
---|
87 | |
---|
88 | struct prpl *find_protocol(const char *name) |
---|
89 | { |
---|
90 | GList *gl; |
---|
91 | for (gl = protocols; gl; gl = gl->next) |
---|
92 | { |
---|
93 | struct prpl *proto = gl->data; |
---|
94 | if(!g_strcasecmp(proto->name, name)) |
---|
95 | return proto; |
---|
96 | } |
---|
97 | return NULL; |
---|
98 | } |
---|
99 | |
---|
100 | /* nogaim.c */ |
---|
101 | void nogaim_init() |
---|
102 | { |
---|
103 | GDir *dir; |
---|
104 | GError *error = NULL; |
---|
105 | |
---|
106 | #ifdef WITH_MSN |
---|
107 | extern void msn_init(); |
---|
108 | msn_init(); |
---|
109 | #endif |
---|
110 | |
---|
111 | #ifdef WITH_OSCAR |
---|
112 | extern void oscar_init(); |
---|
113 | oscar_init(); |
---|
114 | #endif |
---|
115 | |
---|
116 | #ifdef WITH_YAHOO |
---|
117 | extern void byahoo_init(); |
---|
118 | byahoo_init(); |
---|
119 | #endif |
---|
120 | |
---|
121 | #ifdef WITH_JABBER |
---|
122 | extern void jabber_init(); |
---|
123 | jabber_init(); |
---|
124 | #endif |
---|
125 | |
---|
126 | dir = g_dir_open(PLUGINDIR, 0, &error); |
---|
127 | |
---|
128 | if (dir) { |
---|
129 | const gchar *entry; |
---|
130 | char *path; |
---|
131 | |
---|
132 | while ((entry = g_dir_read_name(dir))) { |
---|
133 | path = g_build_filename(PLUGINDIR, entry, NULL); |
---|
134 | if(!path) { |
---|
135 | log_message(LOGLVL_WARNING, "Can't build path for %s\n", entry); |
---|
136 | continue; |
---|
137 | } |
---|
138 | |
---|
139 | load_plugin(path); |
---|
140 | |
---|
141 | g_free(path); |
---|
142 | } |
---|
143 | |
---|
144 | g_dir_close(dir); |
---|
145 | } |
---|
146 | } |
---|
147 | |
---|
148 | GSList *get_connections() { return connections; } |
---|
149 | |
---|
150 | int proto_away( struct gaim_connection *gc, char *away ) |
---|
151 | { |
---|
152 | GList *m, *ms; |
---|
153 | char *s; |
---|
154 | |
---|
155 | if( !away ) away = ""; |
---|
156 | ms = m = gc->prpl->away_states( gc ); |
---|
157 | |
---|
158 | while( m ) |
---|
159 | { |
---|
160 | if( *away ) |
---|
161 | { |
---|
162 | if( g_strncasecmp( m->data, away, strlen( m->data ) ) == 0 ) |
---|
163 | break; |
---|
164 | } |
---|
165 | else |
---|
166 | { |
---|
167 | if( g_strcasecmp( m->data, "Available" ) == 0 ) |
---|
168 | break; |
---|
169 | if( g_strcasecmp( m->data, "Online" ) == 0 ) |
---|
170 | break; |
---|
171 | } |
---|
172 | m = m->next; |
---|
173 | } |
---|
174 | |
---|
175 | if( m ) |
---|
176 | { |
---|
177 | gc->prpl->set_away( gc, m->data, *away ? away : NULL ); |
---|
178 | } |
---|
179 | else |
---|
180 | { |
---|
181 | s = proto_away_alias_find( ms, away ); |
---|
182 | if( s ) |
---|
183 | { |
---|
184 | gc->prpl->set_away( gc, s, away ); |
---|
185 | if( set_getint( gc->irc, "debug" ) ) |
---|
186 | serv_got_crap( gc, "Setting away state to %s", s ); |
---|
187 | } |
---|
188 | else |
---|
189 | gc->prpl->set_away( gc, GAIM_AWAY_CUSTOM, away ); |
---|
190 | } |
---|
191 | |
---|
192 | g_list_free( ms ); |
---|
193 | |
---|
194 | return( 1 ); |
---|
195 | } |
---|
196 | |
---|
197 | static char *proto_away_alias_find( GList *gcm, char *away ) |
---|
198 | { |
---|
199 | GList *m; |
---|
200 | int i, j; |
---|
201 | |
---|
202 | for( i = 0; *proto_away_alias[i]; i ++ ) |
---|
203 | { |
---|
204 | for( j = 0; proto_away_alias[i][j]; j ++ ) |
---|
205 | if( g_strncasecmp( away, proto_away_alias[i][j], strlen( proto_away_alias[i][j] ) ) == 0 ) |
---|
206 | break; |
---|
207 | |
---|
208 | if( !proto_away_alias[i][j] ) /* If we reach the end, this row */ |
---|
209 | continue; /* is not what we want. Next! */ |
---|
210 | |
---|
211 | /* Now find an entry in this row which exists in gcm */ |
---|
212 | for( j = 0; proto_away_alias[i][j]; j ++ ) |
---|
213 | { |
---|
214 | m = gcm; |
---|
215 | while( m ) |
---|
216 | { |
---|
217 | if( g_strcasecmp( proto_away_alias[i][j], m->data ) == 0 ) |
---|
218 | return( proto_away_alias[i][j] ); |
---|
219 | m = m->next; |
---|
220 | } |
---|
221 | } |
---|
222 | } |
---|
223 | |
---|
224 | return( NULL ); |
---|
225 | } |
---|
226 | |
---|
227 | /* multi.c */ |
---|
228 | |
---|
229 | struct gaim_connection *new_gaim_conn( struct aim_user *user ) |
---|
230 | { |
---|
231 | struct gaim_connection *gc; |
---|
232 | account_t *a; |
---|
233 | |
---|
234 | gc = g_new0( struct gaim_connection, 1 ); |
---|
235 | |
---|
236 | gc->prpl = user->prpl; |
---|
237 | g_snprintf( gc->username, sizeof( gc->username ), "%s", user->username ); |
---|
238 | g_snprintf( gc->password, sizeof( gc->password ), "%s", user->password ); |
---|
239 | /* [MD] BUGFIX: don't set gc->irc to the global IRC, but use the one from the struct aim_user. |
---|
240 | * This fixes daemon mode breakage where IRC doesn't point to the currently active connection. |
---|
241 | */ |
---|
242 | gc->irc=user->irc; |
---|
243 | |
---|
244 | connections = g_slist_append( connections, gc ); |
---|
245 | |
---|
246 | user->gc = gc; |
---|
247 | gc->user = user; |
---|
248 | |
---|
249 | // Find the account_t so we can set its gc pointer |
---|
250 | for( a = gc->irc->accounts; a; a = a->next ) |
---|
251 | if( ( struct aim_user * ) a->gc == user ) |
---|
252 | { |
---|
253 | a->gc = gc; |
---|
254 | break; |
---|
255 | } |
---|
256 | |
---|
257 | return( gc ); |
---|
258 | } |
---|
259 | |
---|
260 | void destroy_gaim_conn( struct gaim_connection *gc ) |
---|
261 | { |
---|
262 | account_t *a; |
---|
263 | |
---|
264 | /* Destroy the pointer to this connection from the account list */ |
---|
265 | for( a = gc->irc->accounts; a; a = a->next ) |
---|
266 | if( a->gc == gc ) |
---|
267 | { |
---|
268 | a->gc = NULL; |
---|
269 | break; |
---|
270 | } |
---|
271 | |
---|
272 | connections = g_slist_remove( connections, gc ); |
---|
273 | g_free( gc->user ); |
---|
274 | g_free( gc ); |
---|
275 | } |
---|
276 | |
---|
277 | void set_login_progress( struct gaim_connection *gc, int step, char *msg ) |
---|
278 | { |
---|
279 | serv_got_crap( gc, "Logging in: %s", msg ); |
---|
280 | } |
---|
281 | |
---|
282 | /* Errors *while* logging in */ |
---|
283 | void hide_login_progress( struct gaim_connection *gc, char *msg ) |
---|
284 | { |
---|
285 | serv_got_crap( gc, "Login error: %s", msg ); |
---|
286 | } |
---|
287 | |
---|
288 | /* Errors *after* logging in */ |
---|
289 | void hide_login_progress_error( struct gaim_connection *gc, char *msg ) |
---|
290 | { |
---|
291 | serv_got_crap( gc, "Logged out: %s", msg ); |
---|
292 | } |
---|
293 | |
---|
294 | void serv_got_crap( struct gaim_connection *gc, char *format, ... ) |
---|
295 | { |
---|
296 | va_list params; |
---|
297 | char text[1024], buf[1024], acc_id[33]; |
---|
298 | char *msg; |
---|
299 | account_t *a; |
---|
300 | |
---|
301 | va_start( params, format ); |
---|
302 | g_vsnprintf( text, sizeof( text ), format, params ); |
---|
303 | va_end( params ); |
---|
304 | |
---|
305 | if( g_strncasecmp( set_getstr( gc->irc, "charset" ), "none", 4 ) != 0 && |
---|
306 | do_iconv( "UTF8", set_getstr( gc->irc, "charset" ), text, buf, 0, 1024 ) != -1 ) |
---|
307 | msg = buf; |
---|
308 | else |
---|
309 | msg = text; |
---|
310 | |
---|
311 | if( ( g_strcasecmp( set_getstr( gc->irc, "strip_html" ), "always" ) == 0 ) || |
---|
312 | ( ( gc->flags & OPT_CONN_HTML ) && set_getint( gc->irc, "strip_html" ) ) ) |
---|
313 | strip_html( msg ); |
---|
314 | |
---|
315 | /* Try to find a different connection on the same protocol. */ |
---|
316 | for( a = gc->irc->accounts; a; a = a->next ) |
---|
317 | if( a->prpl == gc->prpl && a->gc != gc ) |
---|
318 | break; |
---|
319 | |
---|
320 | /* If we found one, add the screenname to the acc_id. */ |
---|
321 | if( a ) |
---|
322 | g_snprintf( acc_id, 32, "%s(%s)", gc->prpl->name, gc->username ); |
---|
323 | else |
---|
324 | g_snprintf( acc_id, 32, "%s", gc->prpl->name ); |
---|
325 | |
---|
326 | irc_usermsg( gc->irc, "%s - %s", acc_id, msg ); |
---|
327 | } |
---|
328 | |
---|
329 | static gboolean send_keepalive( gpointer d ) |
---|
330 | { |
---|
331 | struct gaim_connection *gc = d; |
---|
332 | |
---|
333 | if( gc->prpl && gc->prpl->keepalive ) |
---|
334 | gc->prpl->keepalive( gc ); |
---|
335 | |
---|
336 | return TRUE; |
---|
337 | } |
---|
338 | |
---|
339 | void account_online( struct gaim_connection *gc ) |
---|
340 | { |
---|
341 | user_t *u; |
---|
342 | |
---|
343 | /* MSN servers sometimes redirect you to a different server and do |
---|
344 | the whole login sequence again, so subsequent calls to this |
---|
345 | function should be handled correctly. (IOW, ignored) */ |
---|
346 | if( gc->flags & OPT_LOGGED_IN ) |
---|
347 | return; |
---|
348 | |
---|
349 | u = user_find( gc->irc, gc->irc->nick ); |
---|
350 | |
---|
351 | serv_got_crap( gc, "Logged in" ); |
---|
352 | |
---|
353 | gc->keepalive = g_timeout_add( 60000, send_keepalive, gc ); |
---|
354 | gc->flags |= OPT_LOGGED_IN; |
---|
355 | |
---|
356 | if( u && u->away ) proto_away( gc, u->away ); |
---|
357 | |
---|
358 | if( !strcmp(gc->prpl->name, "icq") ) |
---|
359 | { |
---|
360 | for( u = gc->irc->users; u; u = u->next ) |
---|
361 | if( u->gc == gc ) |
---|
362 | break; |
---|
363 | |
---|
364 | if( u == NULL ) |
---|
365 | serv_got_crap( gc, "\x02""***\x02"" BitlBee now supports ICQ server-side contact lists. " |
---|
366 | "See \x02""help import_buddies\x02"" for more information." ); |
---|
367 | } |
---|
368 | } |
---|
369 | |
---|
370 | gboolean auto_reconnect( gpointer data ) |
---|
371 | { |
---|
372 | account_t *a = data; |
---|
373 | |
---|
374 | a->reconnect = 0; |
---|
375 | account_on( a->irc, a ); |
---|
376 | |
---|
377 | return( FALSE ); /* Only have to run the timeout once */ |
---|
378 | } |
---|
379 | |
---|
380 | void cancel_auto_reconnect( account_t *a ) |
---|
381 | { |
---|
382 | while( g_source_remove_by_user_data( (gpointer) a ) ); |
---|
383 | a->reconnect = 0; |
---|
384 | } |
---|
385 | |
---|
386 | void account_offline( struct gaim_connection *gc ) |
---|
387 | { |
---|
388 | gc->wants_to_die = TRUE; |
---|
389 | signoff( gc ); |
---|
390 | } |
---|
391 | |
---|
392 | void signoff( struct gaim_connection *gc ) |
---|
393 | { |
---|
394 | irc_t *irc = gc->irc; |
---|
395 | user_t *t, *u = irc->users; |
---|
396 | account_t *a; |
---|
397 | |
---|
398 | serv_got_crap( gc, "Signing off.." ); |
---|
399 | |
---|
400 | gaim_input_remove( gc->keepalive ); |
---|
401 | gc->keepalive = 0; |
---|
402 | gc->prpl->close( gc ); |
---|
403 | gaim_input_remove( gc->inpa ); |
---|
404 | |
---|
405 | while( u ) |
---|
406 | { |
---|
407 | if( u->gc == gc ) |
---|
408 | { |
---|
409 | t = u->next; |
---|
410 | user_del( irc, u->nick ); |
---|
411 | u = t; |
---|
412 | } |
---|
413 | else |
---|
414 | u = u->next; |
---|
415 | } |
---|
416 | |
---|
417 | query_del_by_gc( gc->irc, gc ); |
---|
418 | |
---|
419 | for( a = irc->accounts; a; a = a->next ) |
---|
420 | if( a->gc == gc ) |
---|
421 | break; |
---|
422 | |
---|
423 | if( !a ) |
---|
424 | { |
---|
425 | /* Uhm... This is very sick. */ |
---|
426 | } |
---|
427 | else if( !gc->wants_to_die && set_getint( irc, "auto_reconnect" ) ) |
---|
428 | { |
---|
429 | int delay = set_getint( irc, "auto_reconnect_delay" ); |
---|
430 | serv_got_crap( gc, "Reconnecting in %d seconds..", delay ); |
---|
431 | |
---|
432 | a->reconnect = 1; |
---|
433 | g_timeout_add( delay * 1000, auto_reconnect, a ); |
---|
434 | } |
---|
435 | |
---|
436 | destroy_gaim_conn( gc ); |
---|
437 | } |
---|
438 | |
---|
439 | |
---|
440 | /* dialogs.c */ |
---|
441 | |
---|
442 | void do_error_dialog( struct gaim_connection *gc, char *msg, char *title ) |
---|
443 | { |
---|
444 | serv_got_crap( gc, "Error: %s", msg ); |
---|
445 | } |
---|
446 | |
---|
447 | void do_ask_dialog( struct gaim_connection *gc, char *msg, void *data, void *doit, void *dont ) |
---|
448 | { |
---|
449 | query_add( gc->irc, gc, msg, doit, dont, data ); |
---|
450 | } |
---|
451 | |
---|
452 | |
---|
453 | /* list.c */ |
---|
454 | |
---|
455 | int bud_list_cache_exists( struct gaim_connection *gc ) |
---|
456 | { |
---|
457 | return( 0 ); |
---|
458 | } |
---|
459 | |
---|
460 | void do_import( struct gaim_connection *gc, void *null ) |
---|
461 | { |
---|
462 | return; |
---|
463 | } |
---|
464 | |
---|
465 | void add_buddy( struct gaim_connection *gc, char *group, char *handle, char *realname ) |
---|
466 | { |
---|
467 | user_t *u; |
---|
468 | char nick[MAX_NICK_LENGTH+1]; |
---|
469 | char *s; |
---|
470 | irc_t *irc = gc->irc; |
---|
471 | |
---|
472 | if( set_getint( irc, "debug" ) && 0 ) /* This message is too useless */ |
---|
473 | serv_got_crap( gc, "Receiving user add from handle: %s", handle ); |
---|
474 | |
---|
475 | if( user_findhandle( gc, handle ) ) |
---|
476 | { |
---|
477 | if( set_getint( irc, "debug" ) ) |
---|
478 | serv_got_crap( gc, "User already exists, ignoring add request: %s", handle ); |
---|
479 | |
---|
480 | return; |
---|
481 | |
---|
482 | /* Buddy seems to exist already. Let's ignore this request then... */ |
---|
483 | } |
---|
484 | |
---|
485 | memset( nick, 0, MAX_NICK_LENGTH + 1 ); |
---|
486 | strcpy( nick, nick_get( gc->irc, handle, gc->prpl, realname ) ); |
---|
487 | |
---|
488 | u = user_add( gc->irc, nick ); |
---|
489 | |
---|
490 | if( !realname || !*realname ) realname = nick; |
---|
491 | u->realname = g_strdup( realname ); |
---|
492 | |
---|
493 | if( ( s = strchr( handle, '@' ) ) ) |
---|
494 | { |
---|
495 | u->host = g_strdup( s + 1 ); |
---|
496 | u->user = g_strndup( handle, s - handle ); |
---|
497 | } |
---|
498 | else if( gc->user->proto_opt[0] && *gc->user->proto_opt[0] ) |
---|
499 | { |
---|
500 | u->host = g_strdup( gc->user->proto_opt[0] ); |
---|
501 | u->user = g_strdup( handle ); |
---|
502 | |
---|
503 | /* s/ /_/ ... important for AOL screennames */ |
---|
504 | for( s = u->user; *s; s ++ ) |
---|
505 | if( *s == ' ' ) |
---|
506 | *s = '_'; |
---|
507 | } |
---|
508 | else |
---|
509 | { |
---|
510 | u->host = g_strdup( gc->user->prpl->name ); |
---|
511 | u->user = g_strdup( handle ); |
---|
512 | } |
---|
513 | |
---|
514 | u->gc = gc; |
---|
515 | u->handle = g_strdup( handle ); |
---|
516 | u->send_handler = buddy_send_handler; |
---|
517 | u->last_typing_notice = 0; |
---|
518 | } |
---|
519 | |
---|
520 | struct buddy *find_buddy( struct gaim_connection *gc, char *handle ) |
---|
521 | { |
---|
522 | static struct buddy b[1]; |
---|
523 | user_t *u; |
---|
524 | |
---|
525 | u = user_findhandle( gc, handle ); |
---|
526 | |
---|
527 | if( !u ) |
---|
528 | return( NULL ); |
---|
529 | |
---|
530 | memset( b, 0, sizeof( b ) ); |
---|
531 | strncpy( b->name, handle, 80 ); |
---|
532 | strncpy( b->show, u->realname, BUDDY_ALIAS_MAXLEN ); |
---|
533 | b->present = u->online; |
---|
534 | b->gc = u->gc; |
---|
535 | |
---|
536 | return( b ); |
---|
537 | } |
---|
538 | |
---|
539 | void do_export( struct gaim_connection *gc ) |
---|
540 | { |
---|
541 | return; |
---|
542 | } |
---|
543 | |
---|
544 | void signoff_blocked( struct gaim_connection *gc ) |
---|
545 | { |
---|
546 | return; /* Make all blocked users look invisible (TODO?) */ |
---|
547 | } |
---|
548 | |
---|
549 | |
---|
550 | void serv_buddy_rename( struct gaim_connection *gc, char *handle, char *realname ) |
---|
551 | { |
---|
552 | user_t *u = user_findhandle( gc, handle ); |
---|
553 | char *name, buf[1024]; |
---|
554 | |
---|
555 | if( !u ) return; |
---|
556 | |
---|
557 | /* Convert all UTF-8 */ |
---|
558 | if( g_strncasecmp( set_getstr( gc->irc, "charset" ), "none", 4 ) != 0 && |
---|
559 | do_iconv( "UTF-8", set_getstr( gc->irc, "charset" ), realname, buf, 0, sizeof( buf ) ) != -1 ) |
---|
560 | name = buf; |
---|
561 | else |
---|
562 | name = realname; |
---|
563 | |
---|
564 | if( g_strcasecmp( u->realname, name ) != 0 ) |
---|
565 | { |
---|
566 | if( u->realname != u->nick ) g_free( u->realname ); |
---|
567 | |
---|
568 | u->realname = g_strdup( name ); |
---|
569 | |
---|
570 | if( ( gc->flags & OPT_LOGGED_IN ) && set_getint( gc->irc, "display_namechanges" ) ) |
---|
571 | serv_got_crap( gc, "User `%s' changed name to `%s'", u->nick, u->realname ); |
---|
572 | } |
---|
573 | } |
---|
574 | |
---|
575 | |
---|
576 | /* prpl.c */ |
---|
577 | |
---|
578 | void show_got_added( struct gaim_connection *gc, char *id, char *handle, const char *realname, const char *msg ) |
---|
579 | { |
---|
580 | return; |
---|
581 | } |
---|
582 | |
---|
583 | |
---|
584 | /* server.c */ |
---|
585 | |
---|
586 | void serv_got_update( struct gaim_connection *gc, char *handle, int loggedin, int evil, time_t signon, time_t idle, int type, guint caps ) |
---|
587 | { |
---|
588 | user_t *u; |
---|
589 | int oa, oo; |
---|
590 | |
---|
591 | u = user_findhandle( gc, handle ); |
---|
592 | |
---|
593 | if( !u ) |
---|
594 | { |
---|
595 | if( g_strcasecmp( set_getstr( gc->irc, "handle_unknown" ), "add" ) == 0 ) |
---|
596 | { |
---|
597 | add_buddy( gc, NULL, handle, NULL ); |
---|
598 | u = user_findhandle( gc, handle ); |
---|
599 | } |
---|
600 | else |
---|
601 | { |
---|
602 | if( set_getint( gc->irc, "debug" ) || g_strcasecmp( set_getstr( gc->irc, "handle_unknown" ), "ignore" ) != 0 ) |
---|
603 | { |
---|
604 | serv_got_crap( gc, "serv_got_update() for handle %s:", handle ); |
---|
605 | serv_got_crap( gc, "loggedin = %d, type = %d", loggedin, type ); |
---|
606 | } |
---|
607 | |
---|
608 | return; |
---|
609 | } |
---|
610 | return; |
---|
611 | } |
---|
612 | |
---|
613 | oa = u->away != NULL; |
---|
614 | oo = u->online; |
---|
615 | |
---|
616 | if( u->away ) |
---|
617 | { |
---|
618 | g_free( u->away ); |
---|
619 | u->away = NULL; |
---|
620 | } |
---|
621 | |
---|
622 | if( loggedin && !u->online ) |
---|
623 | { |
---|
624 | irc_spawn( gc->irc, u ); |
---|
625 | u->online = 1; |
---|
626 | } |
---|
627 | else if( !loggedin && u->online ) |
---|
628 | { |
---|
629 | struct conversation *c; |
---|
630 | |
---|
631 | irc_kill( gc->irc, u ); |
---|
632 | u->online = 0; |
---|
633 | |
---|
634 | /* Remove him/her from the conversations to prevent PART messages after he/she QUIT already */ |
---|
635 | for( c = gc->conversations; c; c = c->next ) |
---|
636 | remove_chat_buddy_silent( c, handle ); |
---|
637 | } |
---|
638 | |
---|
639 | if( ( type & UC_UNAVAILABLE ) && ( !strcmp(gc->prpl->name, "oscar") || !strcmp(gc->prpl->name, "icq")) ) |
---|
640 | { |
---|
641 | u->away = g_strdup( "Away" ); |
---|
642 | } |
---|
643 | else if( ( type & UC_UNAVAILABLE ) && ( !strcmp(gc->prpl->name, "jabber") ) ) |
---|
644 | { |
---|
645 | if( type & UC_DND ) |
---|
646 | u->away = g_strdup( "Do Not Disturb" ); |
---|
647 | else if( type & UC_XA ) |
---|
648 | u->away = g_strdup( "Extended Away" ); |
---|
649 | else // if( type & UC_AWAY ) |
---|
650 | u->away = g_strdup( "Away" ); |
---|
651 | } |
---|
652 | else if( ( type & UC_UNAVAILABLE ) && gc->prpl->get_status_string ) |
---|
653 | { |
---|
654 | u->away = g_strdup( gc->prpl->get_status_string( gc, type ) ); |
---|
655 | } |
---|
656 | else |
---|
657 | u->away = NULL; |
---|
658 | |
---|
659 | /* LISPy... */ |
---|
660 | if( ( set_getint( gc->irc, "away_devoice" ) ) && /* Don't do a thing when user doesn't want it */ |
---|
661 | ( u->online ) && /* Don't touch offline people */ |
---|
662 | ( ( ( u->online != oo ) && !u->away ) || /* Voice joining people */ |
---|
663 | ( ( u->online == oo ) && ( oa == !u->away ) ) ) ) /* (De)voice people changing state */ |
---|
664 | { |
---|
665 | irc_write( gc->irc, ":%s!%s@%s MODE %s %cv %s", gc->irc->mynick, gc->irc->mynick, gc->irc->myhost, |
---|
666 | gc->irc->channel, u->away?'-':'+', u->nick ); |
---|
667 | } |
---|
668 | } |
---|
669 | |
---|
670 | void serv_got_im( struct gaim_connection *gc, char *handle, char *msg, guint32 flags, time_t mtime, gint len ) |
---|
671 | { |
---|
672 | irc_t *irc = gc->irc; |
---|
673 | user_t *u; |
---|
674 | char buf[8192]; |
---|
675 | |
---|
676 | u = user_findhandle( gc, handle ); |
---|
677 | |
---|
678 | if( !u ) |
---|
679 | { |
---|
680 | char *h = set_getstr( irc, "handle_unknown" ); |
---|
681 | |
---|
682 | if( g_strcasecmp( h, "ignore" ) == 0 ) |
---|
683 | { |
---|
684 | if( set_getint( irc, "debug" ) ) |
---|
685 | serv_got_crap( gc, "Ignoring message from unknown handle %s", handle ); |
---|
686 | |
---|
687 | return; |
---|
688 | } |
---|
689 | else if( g_strncasecmp( h, "add", 3 ) == 0 ) |
---|
690 | { |
---|
691 | int private = set_getint( irc, "private" ); |
---|
692 | |
---|
693 | if( h[3] ) |
---|
694 | { |
---|
695 | if( g_strcasecmp( h + 3, "_private" ) == 0 ) |
---|
696 | private = 1; |
---|
697 | else if( g_strcasecmp( h + 3, "_channel" ) == 0 ) |
---|
698 | private = 0; |
---|
699 | } |
---|
700 | |
---|
701 | add_buddy( gc, NULL, handle, NULL ); |
---|
702 | u = user_findhandle( gc, handle ); |
---|
703 | u->is_private = private; |
---|
704 | } |
---|
705 | else |
---|
706 | { |
---|
707 | serv_got_crap( gc, "Message from unknown handle %s:", handle ); |
---|
708 | u = user_find( irc, irc->mynick ); |
---|
709 | } |
---|
710 | } |
---|
711 | |
---|
712 | if( ( g_strcasecmp( set_getstr( gc->irc, "strip_html" ), "always" ) == 0 ) || |
---|
713 | ( ( gc->flags & OPT_CONN_HTML ) && set_getint( gc->irc, "strip_html" ) ) ) |
---|
714 | strip_html( msg ); |
---|
715 | |
---|
716 | if( g_strncasecmp( set_getstr( irc, "charset" ), "none", 4 ) != 0 && |
---|
717 | do_iconv( "UTF-8", set_getstr( irc, "charset" ), msg, buf, 0, 8192 ) != -1 ) |
---|
718 | msg = buf; |
---|
719 | |
---|
720 | while( strlen( msg ) > 425 ) |
---|
721 | { |
---|
722 | char tmp, *nl; |
---|
723 | |
---|
724 | tmp = msg[425]; |
---|
725 | msg[425] = 0; |
---|
726 | |
---|
727 | /* If there's a newline/space in this string, split up there, |
---|
728 | looks a bit prettier. */ |
---|
729 | if( ( nl = strrchr( msg, '\n' ) ) || ( nl = strchr( msg, ' ' ) ) ) |
---|
730 | { |
---|
731 | msg[425] = tmp; |
---|
732 | tmp = *nl; |
---|
733 | *nl = 0; |
---|
734 | } |
---|
735 | |
---|
736 | irc_msgfrom( irc, u->nick, msg ); |
---|
737 | |
---|
738 | /* Move on. */ |
---|
739 | if( nl ) |
---|
740 | { |
---|
741 | *nl = tmp; |
---|
742 | msg = nl + 1; |
---|
743 | } |
---|
744 | else |
---|
745 | { |
---|
746 | msg[425] = tmp; |
---|
747 | msg += 425; |
---|
748 | } |
---|
749 | } |
---|
750 | irc_msgfrom( irc, u->nick, msg ); |
---|
751 | } |
---|
752 | |
---|
753 | void serv_got_typing( struct gaim_connection *gc, char *handle, int timeout ) |
---|
754 | { |
---|
755 | user_t *u; |
---|
756 | |
---|
757 | if( !set_getint( gc->irc, "typing_notice" ) ) |
---|
758 | return; |
---|
759 | |
---|
760 | if( ( u = user_findhandle( gc, handle ) ) ) |
---|
761 | irc_msgfrom( gc->irc, u->nick, "\1TYPING 1\1" ); |
---|
762 | } |
---|
763 | |
---|
764 | void serv_got_chat_left( struct gaim_connection *gc, int id ) |
---|
765 | { |
---|
766 | struct conversation *c, *l = NULL; |
---|
767 | GList *ir; |
---|
768 | |
---|
769 | if( set_getint( gc->irc, "debug" ) ) |
---|
770 | serv_got_crap( gc, "You were removed from conversation %d", (int) id ); |
---|
771 | |
---|
772 | for( c = gc->conversations; c && c->id != id; c = (l=c)->next ); |
---|
773 | |
---|
774 | if( c ) |
---|
775 | { |
---|
776 | if( c->joined ) |
---|
777 | { |
---|
778 | user_t *u, *r; |
---|
779 | |
---|
780 | r = user_find( gc->irc, gc->irc->mynick ); |
---|
781 | irc_privmsg( gc->irc, r, "PRIVMSG", c->channel, "", "Cleaning up channel, bye!" ); |
---|
782 | |
---|
783 | u = user_find( gc->irc, gc->irc->nick ); |
---|
784 | irc_kick( gc->irc, u, c->channel, r ); |
---|
785 | /* irc_part( gc->irc, u, c->channel ); */ |
---|
786 | } |
---|
787 | |
---|
788 | if( l ) |
---|
789 | l->next = c->next; |
---|
790 | else |
---|
791 | gc->conversations = c->next; |
---|
792 | |
---|
793 | for( ir = c->in_room; ir; ir = ir->next ) |
---|
794 | g_free( ir->data ); |
---|
795 | g_list_free( c->in_room ); |
---|
796 | g_free( c->channel ); |
---|
797 | g_free( c->title ); |
---|
798 | g_free( c ); |
---|
799 | } |
---|
800 | } |
---|
801 | |
---|
802 | void serv_got_chat_in( struct gaim_connection *gc, int id, char *who, int whisper, char *msg, time_t mtime ) |
---|
803 | { |
---|
804 | struct conversation *c; |
---|
805 | user_t *u; |
---|
806 | char buf[8192]; |
---|
807 | |
---|
808 | /* Gaim sends own messages through this too. IRC doesn't want this, so kill them */ |
---|
809 | if( g_strcasecmp( who, gc->user->username ) == 0 ) |
---|
810 | return; |
---|
811 | |
---|
812 | u = user_findhandle( gc, who ); |
---|
813 | for( c = gc->conversations; c && c->id != id; c = c->next ); |
---|
814 | |
---|
815 | if( ( g_strcasecmp( set_getstr( gc->irc, "strip_html" ), "always" ) == 0 ) || |
---|
816 | ( ( gc->flags & OPT_CONN_HTML ) && set_getint( gc->irc, "strip_html" ) ) ) |
---|
817 | strip_html( msg ); |
---|
818 | |
---|
819 | if( g_strncasecmp( set_getstr( gc->irc, "charset" ), "none", 4 ) != 0 && |
---|
820 | do_iconv( "UTF-8", set_getstr( gc->irc, "charset" ), msg, buf, 0, 8192 ) != -1 ) |
---|
821 | msg = buf; |
---|
822 | |
---|
823 | if( c && u ) |
---|
824 | irc_privmsg( gc->irc, u, "PRIVMSG", c->channel, "", msg ); |
---|
825 | else |
---|
826 | serv_got_crap( gc, "Message from/to conversation %s@%d (unknown conv/user): %s", who, id, msg ); |
---|
827 | } |
---|
828 | |
---|
829 | struct conversation *serv_got_joined_chat( struct gaim_connection *gc, int id, char *handle ) |
---|
830 | { |
---|
831 | struct conversation *c; |
---|
832 | char *s; |
---|
833 | |
---|
834 | /* This one just creates the conversation structure, user won't see anything yet */ |
---|
835 | |
---|
836 | if( gc->conversations ) |
---|
837 | { |
---|
838 | for( c = gc->conversations; c->next; c = c->next ); |
---|
839 | c = c->next = g_new0( struct conversation, 1 ); |
---|
840 | } |
---|
841 | else |
---|
842 | gc->conversations = c = g_new0( struct conversation, 1); |
---|
843 | |
---|
844 | c->id = id; |
---|
845 | c->gc = gc; |
---|
846 | c->title = g_strdup( handle ); |
---|
847 | |
---|
848 | s = g_new( char, 16 ); |
---|
849 | sprintf( s, "&chat_%03d", gc->irc->c_id++ ); |
---|
850 | c->channel = g_strdup( s ); |
---|
851 | g_free( s ); |
---|
852 | |
---|
853 | if( set_getint( gc->irc, "debug" ) ) |
---|
854 | serv_got_crap( gc, "Creating new conversation: (id=%d,handle=%s)", id, handle ); |
---|
855 | |
---|
856 | return( c ); |
---|
857 | } |
---|
858 | |
---|
859 | void serv_finish_login( struct gaim_connection *gc ) |
---|
860 | { |
---|
861 | return; |
---|
862 | } |
---|
863 | |
---|
864 | |
---|
865 | /* buddy_chat.c */ |
---|
866 | |
---|
867 | void add_chat_buddy( struct conversation *b, char *handle ) |
---|
868 | { |
---|
869 | user_t *u = user_findhandle( b->gc, handle ); |
---|
870 | int me = 0; |
---|
871 | |
---|
872 | if( set_getint( b->gc->irc, "debug" ) ) |
---|
873 | serv_got_crap( b->gc, "User %s added to conversation %d", handle, b->id ); |
---|
874 | |
---|
875 | /* It might be yourself! */ |
---|
876 | if( b->gc->prpl->cmp_buddynames( handle, b->gc->user->username ) == 0 ) |
---|
877 | { |
---|
878 | u = user_find( b->gc->irc, b->gc->irc->nick ); |
---|
879 | if( !b->joined ) |
---|
880 | irc_join( b->gc->irc, u, b->channel ); |
---|
881 | b->joined = me = 1; |
---|
882 | } |
---|
883 | |
---|
884 | /* Most protocols allow people to join, even when they're not in |
---|
885 | your contact list. Try to handle that here */ |
---|
886 | if( !u ) |
---|
887 | { |
---|
888 | add_buddy( b->gc, NULL, handle, NULL ); |
---|
889 | u = user_findhandle( b->gc, handle ); |
---|
890 | } |
---|
891 | |
---|
892 | /* Add the handle to the room userlist, if it's not 'me' */ |
---|
893 | if( !me ) |
---|
894 | { |
---|
895 | if( b->joined ) |
---|
896 | irc_join( b->gc->irc, u, b->channel ); |
---|
897 | b->in_room = g_list_append( b->in_room, g_strdup( handle ) ); |
---|
898 | } |
---|
899 | } |
---|
900 | |
---|
901 | void remove_chat_buddy( struct conversation *b, char *handle, char *reason ) |
---|
902 | { |
---|
903 | user_t *u; |
---|
904 | int me = 0; |
---|
905 | |
---|
906 | if( set_getint( b->gc->irc, "debug" ) ) |
---|
907 | serv_got_crap( b->gc, "User %s removed from conversation %d (%s)", handle, b->id, reason ? reason : "" ); |
---|
908 | |
---|
909 | /* It might be yourself! */ |
---|
910 | if( g_strcasecmp( handle, b->gc->user->username ) == 0 ) |
---|
911 | { |
---|
912 | u = user_find( b->gc->irc, b->gc->irc->nick ); |
---|
913 | b->joined = 0; |
---|
914 | me = 1; |
---|
915 | } |
---|
916 | else |
---|
917 | { |
---|
918 | u = user_findhandle( b->gc, handle ); |
---|
919 | } |
---|
920 | |
---|
921 | if( remove_chat_buddy_silent( b, handle ) ) |
---|
922 | if( ( b->joined || me ) && u ) |
---|
923 | irc_part( b->gc->irc, u, b->channel ); |
---|
924 | } |
---|
925 | |
---|
926 | static int remove_chat_buddy_silent( struct conversation *b, char *handle ) |
---|
927 | { |
---|
928 | GList *i; |
---|
929 | |
---|
930 | /* Find the handle in the room userlist and shoot it */ |
---|
931 | i = b->in_room; |
---|
932 | while( i ) |
---|
933 | { |
---|
934 | if( g_strcasecmp( handle, i->data ) == 0 ) |
---|
935 | { |
---|
936 | g_free( i->data ); |
---|
937 | b->in_room = g_list_remove( b->in_room, i->data ); |
---|
938 | return( 1 ); |
---|
939 | } |
---|
940 | |
---|
941 | i = i->next; |
---|
942 | } |
---|
943 | |
---|
944 | return( 0 ); |
---|
945 | } |
---|
946 | |
---|
947 | |
---|
948 | /* prefs.c */ |
---|
949 | |
---|
950 | /* Necessary? */ |
---|
951 | void build_block_list() |
---|
952 | { |
---|
953 | return; |
---|
954 | } |
---|
955 | |
---|
956 | void build_allow_list() |
---|
957 | { |
---|
958 | return; |
---|
959 | } |
---|
960 | |
---|
961 | |
---|
962 | /* Misc. BitlBee stuff which shouldn't really be here */ |
---|
963 | |
---|
964 | struct conversation *conv_findchannel( char *channel ) |
---|
965 | { |
---|
966 | struct gaim_connection *gc; |
---|
967 | struct conversation *c; |
---|
968 | GSList *l; |
---|
969 | |
---|
970 | /* This finds the connection which has a conversation which belongs to this channel */ |
---|
971 | for( l = connections; l; l = l->next ) |
---|
972 | { |
---|
973 | gc = l->data; |
---|
974 | for( c = gc->conversations; c && g_strcasecmp( c->channel, channel ) != 0; c = c->next ); |
---|
975 | if( c ) |
---|
976 | return( c ); |
---|
977 | } |
---|
978 | |
---|
979 | return( NULL ); |
---|
980 | } |
---|
981 | |
---|
982 | char *set_eval_away_devoice( irc_t *irc, set_t *set, char *value ) |
---|
983 | { |
---|
984 | int st; |
---|
985 | |
---|
986 | if( ( g_strcasecmp( value, "true" ) == 0 ) || ( g_strcasecmp( value, "yes" ) == 0 ) || ( g_strcasecmp( value, "on" ) == 0 ) ) |
---|
987 | st = 1; |
---|
988 | else if( ( g_strcasecmp( value, "false" ) == 0 ) || ( g_strcasecmp( value, "no" ) == 0 ) || ( g_strcasecmp( value, "off" ) == 0 ) ) |
---|
989 | st = 0; |
---|
990 | else if( sscanf( value, "%d", &st ) != 1 ) |
---|
991 | return( NULL ); |
---|
992 | |
---|
993 | st = st != 0; |
---|
994 | |
---|
995 | /* Horror.... */ |
---|
996 | |
---|
997 | if( st != set_getint( irc, "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->gc && 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!%s@%s MODE %s %c%s%s", |
---|
1018 | irc->mynick, irc->mynick, 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!%s@%s MODE %s %c%s%s", irc->mynick, irc->mynick, irc->myhost, |
---|
1034 | irc->channel, pm, v, list ); |
---|
1035 | } |
---|
1036 | |
---|
1037 | return( set_eval_bool( irc, set, value ) ); |
---|
1038 | } |
---|
1039 | |
---|
1040 | int serv_send_im( irc_t *irc, user_t *u, char *msg, int flags ) |
---|
1041 | { |
---|
1042 | char buf[8192]; |
---|
1043 | |
---|
1044 | if( g_strncasecmp( set_getstr( irc, "charset" ), "none", 4 ) != 0 && |
---|
1045 | do_iconv( set_getstr( irc, "charset" ), "UTF-8", msg, buf, 0, 8192 ) != -1 ) |
---|
1046 | msg = buf; |
---|
1047 | |
---|
1048 | if( ( u->gc->flags & OPT_CONN_HTML ) && ( g_strncasecmp( msg, "<html>", 6 ) != 0 ) ) |
---|
1049 | { |
---|
1050 | char *html; |
---|
1051 | |
---|
1052 | html = escape_html( msg ); |
---|
1053 | strncpy( buf, html, 8192 ); |
---|
1054 | g_free( html ); |
---|
1055 | |
---|
1056 | msg = buf; |
---|
1057 | } |
---|
1058 | |
---|
1059 | return( ((struct gaim_connection *)u->gc)->prpl->send_im( u->gc, u->handle, msg, strlen( msg ), flags ) ); |
---|
1060 | } |
---|
1061 | |
---|
1062 | int serv_send_chat( irc_t *irc, struct gaim_connection *gc, int id, char *msg ) |
---|
1063 | { |
---|
1064 | char buf[8192]; |
---|
1065 | |
---|
1066 | if( g_strncasecmp( set_getstr( irc, "charset" ), "none", 4 ) != 0 && |
---|
1067 | do_iconv( set_getstr( irc, "charset" ), "UTF-8", msg, buf, 0, 8192 ) != -1 ) |
---|
1068 | msg = buf; |
---|
1069 | |
---|
1070 | if( gc->flags & OPT_CONN_HTML) { |
---|
1071 | char * html = escape_html(msg); |
---|
1072 | strncpy(buf, html, 8192); |
---|
1073 | g_free(html); |
---|
1074 | } |
---|
1075 | |
---|
1076 | return( gc->prpl->chat_send( gc, id, msg ) ); |
---|
1077 | } |
---|
1078 | |
---|
1079 | /* Convert from one charset to another. |
---|
1080 | |
---|
1081 | from_cs, to_cs: Source and destination charsets |
---|
1082 | src, dst: Source and destination strings |
---|
1083 | size: Size if src. 0 == use strlen(). strlen() is not reliable for UNICODE/UTF16 strings though. |
---|
1084 | maxbuf: Maximum number of bytes to write to dst |
---|
1085 | |
---|
1086 | Returns the number of bytes written to maxbuf or -1 on an error. |
---|
1087 | */ |
---|
1088 | signed int do_iconv( char *from_cs, char *to_cs, char *src, char *dst, size_t size, size_t maxbuf ) |
---|
1089 | { |
---|
1090 | iconv_t cd; |
---|
1091 | size_t res; |
---|
1092 | size_t inbytesleft, outbytesleft; |
---|
1093 | char *inbuf = src; |
---|
1094 | char *outbuf = dst; |
---|
1095 | |
---|
1096 | cd = iconv_open( to_cs, from_cs ); |
---|
1097 | if( cd == (iconv_t) -1 ) |
---|
1098 | return( -1 ); |
---|
1099 | |
---|
1100 | inbytesleft = size ? size : strlen( src ); |
---|
1101 | outbytesleft = maxbuf - 1; |
---|
1102 | res = iconv( cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft ); |
---|
1103 | *outbuf = '\0'; |
---|
1104 | iconv_close( cd ); |
---|
1105 | |
---|
1106 | if( res == (size_t) -1 ) |
---|
1107 | return( -1 ); |
---|
1108 | else |
---|
1109 | return( outbuf - dst ); |
---|
1110 | } |
---|
1111 | |
---|
1112 | char *set_eval_charset( irc_t *irc, set_t *set, char *value ) |
---|
1113 | { |
---|
1114 | iconv_t cd; |
---|
1115 | |
---|
1116 | if ( g_strncasecmp( value, "none", 4 ) == 0 ) |
---|
1117 | return( value ); |
---|
1118 | |
---|
1119 | cd = iconv_open( "UTF-8", value ); |
---|
1120 | if( cd == (iconv_t) -1 ) |
---|
1121 | return( NULL ); |
---|
1122 | |
---|
1123 | iconv_close( cd ); |
---|
1124 | return( value ); |
---|
1125 | } |
---|