source: irc.c @ fb117aee

Last change on this file since fb117aee was fb117aee, checked in by Wilmer van der Gaast <wilmer@…>, at 2010-04-02T02:29:45Z

Cleaned lots of compiler warnings so I can get some signal again.

  • Property mode set to 100644
File size: 19.4 KB
Line 
1  /********************************************************************\
2  * BitlBee -- An IRC to other IM-networks gateway                     *
3  *                                                                    *
4  * Copyright 2002-2004 Wilmer van der Gaast and others                *
5  \********************************************************************/
6
7/* The IRC-based UI (for now the only one)                              */
8
9/*
10  This program is free software; you can redistribute it and/or modify
11  it under the terms of the GNU General Public License as published by
12  the Free Software Foundation; either version 2 of the License, or
13  (at your option) any later version.
14
15  This program is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  GNU General Public License for more details.
19
20  You should have received a copy of the GNU General Public License with
21  the Debian GNU/Linux distribution in /usr/share/common-licenses/GPL;
22  if not, write to the Free Software Foundation, Inc., 59 Temple Place,
23  Suite 330, Boston, MA  02111-1307  USA
24*/
25
26#include "bitlbee.h"
27#include "ipc.h"
28
29GSList *irc_connection_list;
30
31static gboolean irc_userping( gpointer _irc, gint fd, b_input_condition cond );
32static char *set_eval_charset( set_t *set, char *value );
33
34irc_t *irc_new( int fd )
35{
36        irc_t *irc;
37        struct sockaddr_storage sock;
38        socklen_t socklen = sizeof( sock );
39        char *host = NULL, *myhost = NULL;
40        irc_user_t *iu;
41        set_t *s;
42        bee_t *b;
43       
44        irc = g_new0( irc_t, 1 );
45       
46        irc->fd = fd;
47        sock_make_nonblocking( irc->fd );
48       
49        irc->r_watch_source_id = b_input_add( irc->fd, GAIM_INPUT_READ, bitlbee_io_current_client_read, irc );
50       
51        irc->status = USTATUS_OFFLINE;
52        irc->last_pong = gettime();
53       
54        irc->nick_user_hash = g_hash_table_new( g_str_hash, g_str_equal );
55        irc->watches = g_hash_table_new( g_str_hash, g_str_equal );
56       
57        irc->iconv = (GIConv) -1;
58        irc->oconv = (GIConv) -1;
59       
60        if( global.conf->hostname )
61        {
62                myhost = g_strdup( global.conf->hostname );
63        }
64        else if( getsockname( irc->fd, (struct sockaddr*) &sock, &socklen ) == 0 ) 
65        {
66                char buf[NI_MAXHOST+1];
67
68                if( getnameinfo( (struct sockaddr *) &sock, socklen, buf,
69                                 NI_MAXHOST, NULL, 0, 0 ) == 0 )
70                {
71                        myhost = g_strdup( ipv6_unwrap( buf ) );
72                }
73        }
74       
75        if( getpeername( irc->fd, (struct sockaddr*) &sock, &socklen ) == 0 )
76        {
77                char buf[NI_MAXHOST+1];
78
79                if( getnameinfo( (struct sockaddr *)&sock, socklen, buf,
80                                 NI_MAXHOST, NULL, 0, 0 ) == 0 )
81                {
82                        host = g_strdup( ipv6_unwrap( buf ) );
83                }
84        }
85       
86        if( host == NULL )
87                host = g_strdup( "localhost.localdomain" );
88        if( myhost == NULL )
89                myhost = g_strdup( "localhost.localdomain" );
90       
91        if( global.conf->ping_interval > 0 && global.conf->ping_timeout > 0 )
92                irc->ping_source_id = b_timeout_add( global.conf->ping_interval * 1000, irc_userping, irc );
93
94        irc_connection_list = g_slist_append( irc_connection_list, irc );
95       
96        b = irc->b = bee_new();
97        b->ui_data = irc;
98        b->ui = &irc_ui_funcs;
99       
100        s = set_add( &b->set, "away_devoice", "true", NULL/*set_eval_away_devoice*/, irc );
101        s = set_add( &b->set, "buddy_sendbuffer", "false", set_eval_bool, irc );
102        s = set_add( &b->set, "buddy_sendbuffer_delay", "200", set_eval_int, irc );
103        s = set_add( &b->set, "charset", "utf-8", set_eval_charset, irc );
104        //s = set_add( &b->set, "control_channel", irc->channel, NULL/*set_eval_control_channel*/, irc );
105        s = set_add( &b->set, "default_target", "root", NULL, irc );
106        s = set_add( &b->set, "display_namechanges", "false", set_eval_bool, irc );
107        s = set_add( &b->set, "handle_unknown", "root", NULL, irc );
108        s = set_add( &b->set, "lcnicks", "true", set_eval_bool, irc );
109        s = set_add( &b->set, "ops", "both", NULL/*set_eval_ops*/, irc );
110        s = set_add( &b->set, "private", "true", set_eval_bool, irc );
111        s = set_add( &b->set, "query_order", "lifo", NULL, irc );
112        s = set_add( &b->set, "root_nick", ROOT_NICK, NULL/*set_eval_root_nick*/, irc );
113        s = set_add( &b->set, "simulate_netsplit", "true", set_eval_bool, irc );
114        s = set_add( &b->set, "to_char", ": ", set_eval_to_char, irc );
115        s = set_add( &b->set, "typing_notice", "false", set_eval_bool, irc );
116
117        irc->root = iu = irc_user_new( irc, ROOT_NICK );
118        iu->host = g_strdup( myhost );
119        iu->fullname = g_strdup( ROOT_FN );
120        iu->f = &irc_user_root_funcs;
121       
122        iu = irc_user_new( irc, NS_NICK );
123        iu->host = g_strdup( myhost );
124        iu->fullname = g_strdup( ROOT_FN );
125        iu->f = &irc_user_root_funcs;
126       
127        irc->user = g_new0( irc_user_t, 1 );
128        irc->user->host = g_strdup( host );
129       
130        conf_loaddefaults( irc );
131       
132        /* Evaluator sets the iconv/oconv structures. */
133        set_eval_charset( set_find( &b->set, "charset" ), set_getstr( &b->set, "charset" ) );
134       
135        irc_write( irc, ":%s NOTICE AUTH :%s", irc->root->host, "BitlBee-IRCd initialized, please go on" );
136       
137        g_free( myhost );
138        g_free( host );
139       
140        return irc;
141}
142
143/* immed=1 makes this function pretty much equal to irc_free(), except that
144   this one will "log". In case the connection is already broken and we
145   shouldn't try to write to it. */
146void irc_abort( irc_t *irc, int immed, char *format, ... )
147{
148        if( format != NULL )
149        {
150                va_list params;
151                char *reason;
152               
153                va_start( params, format );
154                reason = g_strdup_vprintf( format, params );
155                va_end( params );
156               
157                if( !immed )
158                        irc_write( irc, "ERROR :Closing link: %s", reason );
159               
160                ipc_to_master_str( "OPERMSG :Client exiting: %s@%s [%s]\r\n",
161                                   irc->user->nick ? irc->user->nick : "(NONE)", irc->root->host, reason );
162               
163                g_free( reason );
164        }
165        else
166        {
167                if( !immed )
168                        irc_write( irc, "ERROR :Closing link" );
169               
170                ipc_to_master_str( "OPERMSG :Client exiting: %s@%s [%s]\r\n",
171                                   irc->user->nick ? irc->user->nick : "(NONE)", irc->root->host, "No reason given" );
172        }
173       
174        irc->status |= USTATUS_SHUTDOWN;
175        if( irc->sendbuffer && !immed )
176        {
177                /* Set up a timeout event that should shut down the connection
178                   in a second, just in case ..._write doesn't do it first. */
179               
180                b_event_remove( irc->r_watch_source_id );
181                irc->r_watch_source_id = 0;
182               
183                b_event_remove( irc->ping_source_id );
184                irc->ping_source_id = b_timeout_add( 1000, (b_event_handler) irc_free, irc );
185        }
186        else
187        {
188                irc_free( irc );
189        }
190}
191
192static gboolean irc_free_hashkey( gpointer key, gpointer value, gpointer data );
193
194void irc_free( irc_t * irc )
195{
196        log_message( LOGLVL_INFO, "Destroying connection with fd %d", irc->fd );
197       
198        /*
199        if( irc->status & USTATUS_IDENTIFIED && set_getbool( &irc->b->set, "save_on_quit" ) )
200                if( storage_save( irc, NULL, TRUE ) != STORAGE_OK )
201                        irc_usermsg( irc, "Error while saving settings!" );
202        */
203       
204        irc_connection_list = g_slist_remove( irc_connection_list, irc );
205       
206        /*
207        while( irc->queries != NULL )
208                query_del( irc, irc->queries );
209        */
210       
211        while( irc->users )
212        {
213                irc_user_t *iu = irc->users->data;
214                irc_user_free( irc, iu->nick );
215        }
216       
217        while( irc->channels )
218                irc_channel_free( irc->channels->data );
219       
220        if( irc->ping_source_id > 0 )
221                b_event_remove( irc->ping_source_id );
222        if( irc->r_watch_source_id > 0 )
223                b_event_remove( irc->r_watch_source_id );
224        if( irc->w_watch_source_id > 0 )
225                b_event_remove( irc->w_watch_source_id );
226       
227        closesocket( irc->fd );
228        irc->fd = -1;
229       
230        g_hash_table_foreach_remove( irc->nick_user_hash, irc_free_hashkey, NULL );
231        g_hash_table_destroy( irc->nick_user_hash );
232       
233        g_hash_table_foreach_remove( irc->watches, irc_free_hashkey, NULL );
234        g_hash_table_destroy( irc->watches );
235       
236        if( irc->iconv != (GIConv) -1 )
237                g_iconv_close( irc->iconv );
238        if( irc->oconv != (GIConv) -1 )
239                g_iconv_close( irc->oconv );
240       
241        g_free( irc->sendbuffer );
242        g_free( irc->readbuffer );
243       
244        g_free( irc->password );
245       
246        g_free( irc );
247       
248        if( global.conf->runmode == RUNMODE_INETD ||
249            global.conf->runmode == RUNMODE_FORKDAEMON ||
250            ( global.conf->runmode == RUNMODE_DAEMON &&
251              global.listen_socket == -1 &&
252              irc_connection_list == NULL ) )
253                b_main_quit();
254}
255
256static gboolean irc_free_hashkey( gpointer key, gpointer value, gpointer data )
257{
258        g_free( key );
259       
260        return( TRUE );
261}
262
263static char **irc_splitlines( char *buffer );
264
265void irc_process( irc_t *irc )
266{
267        char **lines, *temp, **cmd;
268        int i;
269
270        if( irc->readbuffer != NULL )
271        {
272                lines = irc_splitlines( irc->readbuffer );
273               
274                for( i = 0; *lines[i] != '\0'; i ++ )
275                {
276                        char *conv = NULL;
277                       
278                        /* [WvG] If the last line isn't empty, it's an incomplete line and we
279                           should wait for the rest to come in before processing it. */
280                        if( lines[i+1] == NULL )
281                        {
282                                temp = g_strdup( lines[i] );
283                                g_free( irc->readbuffer );
284                                irc->readbuffer = temp;
285                                i ++;
286                                break;
287                        }
288                       
289                        if( irc->iconv != (GIConv) -1 )
290                        {
291                                gsize bytes_read, bytes_written;
292                               
293                                conv = g_convert_with_iconv( lines[i], -1, irc->iconv,
294                                                             &bytes_read, &bytes_written, NULL );
295                               
296                                if( conv == NULL || bytes_read != strlen( lines[i] ) )
297                                {
298                                        /* GLib can do strange things if things are not in the expected charset,
299                                           so let's be a little bit paranoid here: */
300                                        if( irc->status & USTATUS_LOGGED_IN )
301                                        {
302                                                irc_usermsg( irc, "Error: Charset mismatch detected. The charset "
303                                                                  "setting is currently set to %s, so please make "
304                                                                  "sure your IRC client will send and accept text in "
305                                                                  "that charset, or tell BitlBee which charset to "
306                                                                  "expect by changing the charset setting. See "
307                                                                  "`help set charset' for more information. Your "
308                                                                  "message was ignored.",
309                                                                  set_getstr( &irc->b->set, "charset" ) );
310                                               
311                                                g_free( conv );
312                                                conv = NULL;
313                                        }
314                                        else
315                                        {
316                                                irc_write( irc, ":%s NOTICE AUTH :%s", irc->root->host,
317                                                           "Warning: invalid characters received at login time." );
318                                               
319                                                conv = g_strdup( lines[i] );
320                                                for( temp = conv; *temp; temp ++ )
321                                                        if( *temp & 0x80 )
322                                                                *temp = '?';
323                                        }
324                                }
325                                lines[i] = conv;
326                        }
327                       
328                        if( lines[i] && ( cmd = irc_parse_line( lines[i] ) ) )
329                        {
330                                irc_exec( irc, cmd );
331                                g_free( cmd );
332                        }
333                       
334                        g_free( conv );
335                       
336                        /* Shouldn't really happen, but just in case... */
337                        if( !g_slist_find( irc_connection_list, irc ) )
338                        {
339                                g_free( lines );
340                                return;
341                        }
342                }
343               
344                if( lines[i] != NULL )
345                {
346                        g_free( irc->readbuffer );
347                        irc->readbuffer = NULL;
348                }
349               
350                g_free( lines );
351        }
352}
353
354/* Splits a long string into separate lines. The array is NULL-terminated
355   and, unless the string contains an incomplete line at the end, ends with
356   an empty string. Could use g_strsplit() but this one does it in-place.
357   (So yes, it's destructive.) */
358static char **irc_splitlines( char *buffer )
359{
360        int i, j, n = 3;
361        char **lines;
362
363        /* Allocate n+1 elements. */
364        lines = g_new( char *, n + 1 );
365       
366        lines[0] = buffer;
367       
368        /* Split the buffer in several strings, and accept any kind of line endings,
369         * knowing that ERC on Windows may send something interesting like \r\r\n,
370         * and surely there must be clients that think just \n is enough... */
371        for( i = 0, j = 0; buffer[i] != '\0'; i ++ )
372        {
373                if( buffer[i] == '\r' || buffer[i] == '\n' )
374                {
375                        while( buffer[i] == '\r' || buffer[i] == '\n' )
376                                buffer[i++] = '\0';
377                       
378                        lines[++j] = buffer + i;
379                       
380                        if( j >= n )
381                        {
382                                n *= 2;
383                                lines = g_renew( char *, lines, n + 1 );
384                        }
385
386                        if( buffer[i] == '\0' )
387                                break;
388                }
389        }
390       
391        /* NULL terminate our list. */ 
392        lines[++j] = NULL;
393       
394        return lines;
395}
396
397/* Split an IRC-style line into little parts/arguments. */
398char **irc_parse_line( char *line )
399{
400        int i, j;
401        char **cmd;
402       
403        /* Move the line pointer to the start of the command, skipping spaces and the optional prefix. */
404        if( line[0] == ':' )
405        {
406                for( i = 0; line[i] && line[i] != ' '; i ++ );
407                line = line + i;
408        }
409        for( i = 0; line[i] == ' '; i ++ );
410        line = line + i;
411       
412        /* If we're already at the end of the line, return. If not, we're going to need at least one element. */
413        if( line[0] == '\0')
414                return NULL;
415       
416        /* Count the number of char **cmd elements we're going to need. */
417        j = 1;
418        for( i = 0; line[i] != '\0'; i ++ )
419        {
420                if( line[i] == ' ' )
421                {
422                        j ++;
423                       
424                        if( line[i+1] == ':' )
425                                break;
426                }
427        }       
428
429        /* Allocate the space we need. */
430        cmd = g_new( char *, j + 1 );
431        cmd[j] = NULL;
432       
433        /* Do the actual line splitting, format is:
434         * Input: "PRIVMSG #bitlbee :foo bar"
435         * Output: cmd[0]=="PRIVMSG", cmd[1]=="#bitlbee", cmd[2]=="foo bar", cmd[3]==NULL
436         */
437
438        cmd[0] = line;
439        for( i = 0, j = 0; line[i] != '\0'; i ++ )
440        {
441                if( line[i] == ' ' )
442                {
443                        line[i] = '\0';
444                        cmd[++j] = line + i + 1;
445                       
446                        if( line[i+1] == ':' )
447                        {
448                                cmd[j] ++;
449                                break;
450                        }
451                }
452        }
453       
454        return cmd;
455}
456
457/* Converts such an array back into a command string. Mainly used for the IPC code right now. */
458char *irc_build_line( char **cmd )
459{
460        int i, len;
461        char *s;
462       
463        if( cmd[0] == NULL )
464                return NULL;
465       
466        len = 1;
467        for( i = 0; cmd[i]; i ++ )
468                len += strlen( cmd[i] ) + 1;
469       
470        if( strchr( cmd[i-1], ' ' ) != NULL )
471                len ++;
472       
473        s = g_new0( char, len + 1 );
474        for( i = 0; cmd[i]; i ++ )
475        {
476                if( cmd[i+1] == NULL && strchr( cmd[i], ' ' ) != NULL )
477                        strcat( s, ":" );
478               
479                strcat( s, cmd[i] );
480               
481                if( cmd[i+1] )
482                        strcat( s, " " );
483        }
484        strcat( s, "\r\n" );
485       
486        return s;
487}
488
489void irc_write( irc_t *irc, char *format, ... ) 
490{
491        va_list params;
492
493        va_start( params, format );
494        irc_vawrite( irc, format, params );     
495        va_end( params );
496
497        return;
498}
499
500void irc_write_all( int now, char *format, ... )
501{
502        va_list params;
503        GSList *temp;   
504       
505        va_start( params, format );
506       
507        temp = irc_connection_list;
508        while( temp != NULL )
509        {
510                irc_t *irc = temp->data;
511               
512                if( now )
513                {
514                        g_free( irc->sendbuffer );
515                        irc->sendbuffer = g_strdup( "\r\n" );
516                }
517                irc_vawrite( temp->data, format, params );
518                if( now )
519                {
520                        bitlbee_io_current_client_write( irc, irc->fd, GAIM_INPUT_WRITE );
521                }
522                temp = temp->next;
523        }
524       
525        va_end( params );
526        return;
527} 
528
529void irc_vawrite( irc_t *irc, char *format, va_list params )
530{
531        int size;
532        char line[IRC_MAX_LINE+1];
533               
534        /* Don't try to write anything new anymore when shutting down. */
535        if( irc->status & USTATUS_SHUTDOWN )
536                return;
537       
538        memset( line, 0, sizeof( line ) );
539        g_vsnprintf( line, IRC_MAX_LINE - 2, format, params );
540        strip_newlines( line );
541       
542        if( irc->oconv != (GIConv) -1 )
543        {
544                gsize bytes_read, bytes_written;
545                char *conv;
546               
547                conv = g_convert_with_iconv( line, -1, irc->oconv,
548                                             &bytes_read, &bytes_written, NULL );
549
550                if( bytes_read == strlen( line ) )
551                        strncpy( line, conv, IRC_MAX_LINE - 2 );
552               
553                g_free( conv );
554        }
555        g_strlcat( line, "\r\n", IRC_MAX_LINE + 1 );
556       
557        if( irc->sendbuffer != NULL )
558        {
559                size = strlen( irc->sendbuffer ) + strlen( line );
560                irc->sendbuffer = g_renew ( char, irc->sendbuffer, size + 1 );
561                strcpy( ( irc->sendbuffer + strlen( irc->sendbuffer ) ), line );
562        }
563        else
564        {
565                irc->sendbuffer = g_strdup(line);
566        }
567       
568        if( irc->w_watch_source_id == 0 )
569        {
570                /* If the buffer is empty we can probably write, so call the write event handler
571                   immediately. If it returns TRUE, it should be called again, so add the event to
572                   the queue. If it's FALSE, we emptied the buffer and saved ourselves some work
573                   in the event queue. */
574                /* Really can't be done as long as the code doesn't do error checking very well:
575                if( bitlbee_io_current_client_write( irc, irc->fd, GAIM_INPUT_WRITE ) ) */
576               
577                /* So just always do it via the event handler. */
578                irc->w_watch_source_id = b_input_add( irc->fd, GAIM_INPUT_WRITE, bitlbee_io_current_client_write, irc );
579        }
580       
581        return;
582}
583
584int irc_check_login( irc_t *irc )
585{
586        if( irc->user->user && irc->user->nick )
587        {
588                if( global.conf->authmode == AUTHMODE_CLOSED && !( irc->status & USTATUS_AUTHORIZED ) )
589                {
590                        irc_send_num( irc, 464, ":This server is password-protected." );
591                        return 0;
592                }
593                else
594                {
595                        irc_channel_t *ic;
596                        irc_user_t *iu = irc->user;
597                       
598                        irc->user = irc_user_new( irc, iu->nick );
599                        irc->user->user = iu->user;
600                        irc->user->host = iu->host;
601                        irc->user->fullname = iu->fullname;
602                        irc->user->f = &irc_user_self_funcs;
603                        g_free( iu->nick );
604                        g_free( iu );
605                       
606                        if( global.conf->runmode == RUNMODE_FORKDAEMON || global.conf->runmode == RUNMODE_DAEMON )
607                                ipc_to_master_str( "CLIENT %s %s :%s\r\n", irc->user->host, irc->user->nick, irc->user->fullname );
608                       
609                        irc->status |= USTATUS_LOGGED_IN;
610                       
611                        /* This is for bug #209 (use PASS to identify to NickServ). */
612                        if( irc->password != NULL )
613                        {
614                                char *send_cmd[] = { "identify", g_strdup( irc->password ), NULL };
615                               
616                                /*irc_setpass( irc, NULL );*/
617                                /*root_command( irc, send_cmd );*/
618                                g_free( send_cmd[1] );
619                        }
620                       
621                        irc_send_login( irc );
622                       
623                        irc->umode[0] = '\0';
624                        irc_umode_set( irc, "+" UMODE, TRUE );
625                       
626                        ic = irc_channel_new( irc, ROOT_CHAN );
627                        irc_channel_set_topic( ic, CONTROL_TOPIC, irc->root );
628                        irc_channel_add_user( ic, irc->user );
629                       
630                        irc->last_root_cmd = g_strdup( ROOT_CHAN );
631                       
632                        return 1;
633                }
634        }
635        else
636        {
637                /* More information needed. */
638                return 0;
639        }
640}
641
642void irc_umode_set( irc_t *irc, const char *s, gboolean allow_priv )
643{
644        /* allow_priv: Set to 0 if s contains user input, 1 if you want
645           to set a "privileged" mode (+o, +R, etc). */
646        char m[128], st = 1;
647        const char *t;
648        int i;
649        char changes[512], *p, st2 = 2;
650        char badflag = 0;
651       
652        memset( m, 0, sizeof( m ) );
653       
654        for( t = irc->umode; *t; t ++ )
655                if( *t < sizeof( m ) )
656                        m[(int)*t] = 1;
657       
658        p = changes;
659        for( t = s; *t; t ++ )
660        {
661                if( *t == '+' || *t == '-' )
662                        st = *t == '+';
663                else if( ( st == 0 && ( !strchr( UMODES_KEEP, *t ) || allow_priv ) ) ||
664                         ( st == 1 && strchr( UMODES, *t ) ) ||
665                         ( st == 1 && allow_priv && strchr( UMODES_PRIV, *t ) ) )
666                {
667                        if( m[(int)*t] != st)
668                        {
669                                if( st != st2 )
670                                        st2 = st, *p++ = st ? '+' : '-';
671                                *p++ = *t;
672                        }
673                        m[(int)*t] = st;
674                }
675                else
676                        badflag = 1;
677        }
678        *p = '\0';
679       
680        memset( irc->umode, 0, sizeof( irc->umode ) );
681       
682        for( i = 'A'; i <= 'z' && strlen( irc->umode ) < ( sizeof( irc->umode ) - 1 ); i ++ )
683                if( m[i] )
684                        irc->umode[strlen(irc->umode)] = i;
685       
686        if( badflag )
687                irc_send_num( irc, 501, ":Unknown MODE flag" );
688        if( *changes )
689                irc_write( irc, ":%s!%s@%s MODE %s :%s", irc->user->nick,
690                           irc->user->user, irc->user->host, irc->user->nick,
691                           changes );
692}
693
694
695/* Returns 0 if everything seems to be okay, a number >0 when there was a
696   timeout. The number returned is the number of seconds we received no
697   pongs from the user. When not connected yet, we don't ping but drop the
698   connection when the user fails to connect in IRC_LOGIN_TIMEOUT secs. */
699static gboolean irc_userping( gpointer _irc, gint fd, b_input_condition cond )
700{
701        irc_t *irc = _irc;
702        int rv = 0;
703       
704        if( !( irc->status & USTATUS_LOGGED_IN ) )
705        {
706                if( gettime() > ( irc->last_pong + IRC_LOGIN_TIMEOUT ) )
707                        rv = gettime() - irc->last_pong;
708        }
709        else
710        {
711                if( ( gettime() > ( irc->last_pong + global.conf->ping_interval ) ) && !irc->pinging )
712                {
713                        irc_write( irc, "PING :%s", IRC_PING_STRING );
714                        irc->pinging = 1;
715                }
716                else if( gettime() > ( irc->last_pong + global.conf->ping_timeout ) )
717                {
718                        rv = gettime() - irc->last_pong;
719                }
720        }
721       
722        if( rv > 0 )
723        {
724                irc_abort( irc, 0, "Ping Timeout: %d seconds", rv );
725                return FALSE;
726        }
727       
728        return TRUE;
729}
730
731
732static char *set_eval_charset( set_t *set, char *value )
733{
734        irc_t *irc = set->data;
735        GIConv ic, oc;
736
737        if( g_strcasecmp( value, "none" ) == 0 )
738                value = g_strdup( "utf-8" );
739
740        if( ( ic = g_iconv_open( "utf-8", value ) ) == (GIConv) -1 )
741        {
742                return NULL;
743        }
744        if( ( oc = g_iconv_open( value, "utf-8" ) ) == (GIConv) -1 )
745        {
746                g_iconv_close( ic );
747                return NULL;
748        }
749       
750        if( irc->iconv != (GIConv) -1 )
751                g_iconv_close( irc->iconv );
752        if( irc->oconv != (GIConv) -1 )
753                g_iconv_close( irc->oconv );
754       
755        irc->iconv = ic;
756        irc->oconv = oc;
757
758        return value;
759}
Note: See TracBrowser for help on using the repository browser.