source: irc.c @ 2231302

Last change on this file since 2231302 was 2231302, checked in by Wilmer van der Gaast <wilmer@…>, at 2007-11-05T22:59:49Z

Merging from Jelmer.

  • Property mode set to 100644
File size: 30.1 KB
RevLine 
[b7d3cc34]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 big hairy IRCd part of the project                               */
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#define BITLBEE_CORE
27#include "bitlbee.h"
28#include "crypting.h"
[2face62]29#include "ipc.h"
[b7d3cc34]30
[ba9edaa]31static gboolean irc_userping( gpointer _irc, int fd, b_input_condition cond );
[b7d3cc34]32
33GSList *irc_connection_list = NULL;
34
[0383943]35static char *passchange( set_t *set, char *value )
[c2295f7]36{
[0383943]37        irc_t *irc = set->data;
38       
[88086db]39        irc_setpass( irc, value );
40        irc_usermsg( irc, "Password successfully changed" );
41        return NULL;
[c2295f7]42}
43
[b7d3cc34]44irc_t *irc_new( int fd )
45{
[e4d6271]46        irc_t *irc;
[e9b755e]47        struct sockaddr_storage sock;
[7435ccf]48        socklen_t socklen = sizeof( sock );
[e4d6271]49       
50        irc = g_new0( irc_t, 1 );
[b7d3cc34]51       
52        irc->fd = fd;
[a0d04d6]53        sock_make_nonblocking( irc->fd );
54       
[ba9edaa]55        irc->r_watch_source_id = b_input_add( irc->fd, GAIM_INPUT_READ, bitlbee_io_current_client_read, irc );
[b7d3cc34]56       
57        irc->status = USTATUS_OFFLINE;
58        irc->last_pong = gettime();
59       
60        irc->userhash = g_hash_table_new( g_str_hash, g_str_equal );
61        irc->watches = g_hash_table_new( g_str_hash, g_str_equal );
62       
63        strcpy( irc->umode, UMODE );
64        irc->mynick = g_strdup( ROOT_NICK );
65        irc->channel = g_strdup( ROOT_CHAN );
66       
67        if( global.conf->hostname )
68        {
69                irc->myhost = g_strdup( global.conf->hostname );
70        }
[7435ccf]71        else if( getsockname( irc->fd, (struct sockaddr*) &sock, &socklen ) == 0 ) 
[b7d3cc34]72        {
[2231302]73                char buf[NI_MAXHOST+1];
[e9b755e]74
[2231302]75                if( getnameinfo( (struct sockaddr *) &sock, socklen, buf,
76                                 NI_MAXHOST, NULL, -1, 0 ) == 0 )
77                {
78                        irc->myhost = g_strdup( ipv6_unwrap( buf ) );
79                }
80                else
81                {
[e9b755e]82                        /* Rare, but possible. */
[2231302]83                        strncpy( irc->myhost, "localhost.localdomain", NI_MAXHOST );
[e9b755e]84                }
[b7d3cc34]85        }
86       
[7435ccf]87        if( getpeername( irc->fd, (struct sockaddr*) &sock, &socklen ) == 0 )
[b7d3cc34]88        {
[2231302]89                char buf[NI_MAXHOST+1];
[e9b755e]90
[2231302]91                if( getnameinfo( (struct sockaddr *)&sock, socklen, buf,
92                                 NI_MAXHOST, NULL, -1, 0 ) == 0 )
93                {
[2a6ca4f]94                        irc->host = g_strdup( ipv6_unwrap( buf ) );
[2231302]95                }
96                else
97                {
[e9b755e]98                        /* Rare, but possible. */
[2231302]99                        strncpy( irc->host, "localhost.localdomain", NI_MAXHOST );
[e9b755e]100                }
[b7d3cc34]101        }
102       
103        if( global.conf->ping_interval > 0 && global.conf->ping_timeout > 0 )
[ba9edaa]104                irc->ping_source_id = b_timeout_add( global.conf->ping_interval * 1000, irc_userping, irc );
[b7d3cc34]105       
106        irc_write( irc, ":%s NOTICE AUTH :%s", irc->myhost, "BitlBee-IRCd initialized, please go on" );
107
108        irc_connection_list = g_slist_append( irc_connection_list, irc );
109       
[5c9512f]110        set_add( &irc->set, "away_devoice", "true",  set_eval_away_devoice, irc );
111        set_add( &irc->set, "auto_connect", "true", set_eval_bool, irc );
112        set_add( &irc->set, "auto_reconnect", "false", set_eval_bool, irc );
113        set_add( &irc->set, "auto_reconnect_delay", "300", set_eval_int, irc );
114        set_add( &irc->set, "buddy_sendbuffer", "false", set_eval_bool, irc );
115        set_add( &irc->set, "buddy_sendbuffer_delay", "200", set_eval_int, irc );
[8d32b9e]116        set_add( &irc->set, "charset", "utf-8", set_eval_charset, irc );
[5c9512f]117        set_add( &irc->set, "debug", "false", set_eval_bool, irc );
118        set_add( &irc->set, "default_target", "root", NULL, irc );
119        set_add( &irc->set, "display_namechanges", "false", set_eval_bool, irc );
120        set_add( &irc->set, "handle_unknown", "root", NULL, irc );
121        set_add( &irc->set, "lcnicks", "true", set_eval_bool, irc );
122        set_add( &irc->set, "ops", "both", set_eval_ops, irc );
123        set_add( &irc->set, "password", NULL, passchange, irc );
124        set_add( &irc->set, "private", "true", set_eval_bool, irc );
125        set_add( &irc->set, "query_order", "lifo", NULL, irc );
126        set_add( &irc->set, "save_on_quit", "true", set_eval_bool, irc );
[1186382]127        set_add( &irc->set, "simulate_netsplit", "true", set_eval_bool, irc );
[5c9512f]128        set_add( &irc->set, "strip_html", "true", NULL, irc );
129        set_add( &irc->set, "to_char", ": ", set_eval_to_char, irc );
130        set_add( &irc->set, "typing_notice", "false", set_eval_bool, irc );
[b7d3cc34]131       
132        conf_loaddefaults( irc );
133       
134        return( irc );
135}
136
[f73b969]137/* immed=1 makes this function pretty much equal to irc_free(), except that
138   this one will "log". In case the connection is already broken and we
139   shouldn't try to write to it. */
[fc50d48]140void irc_abort( irc_t *irc, int immed, char *format, ... )
[c1826c6]141{
[fc50d48]142        if( format != NULL )
143        {
[f73b969]144                va_list params;
[fc50d48]145                char *reason;
146               
147                va_start( params, format );
[f73b969]148                reason = g_strdup_vprintf( format, params );
[fc50d48]149                va_end( params );
150               
151                if( !immed )
152                        irc_write( irc, "ERROR :Closing link: %s", reason );
153               
154                ipc_to_master_str( "OPERMSG :Client exiting: %s@%s [%s]\r\n",
[f73b969]155                                   irc->nick ? irc->nick : "(NONE)", irc->host, reason );
[fc50d48]156               
157                g_free( reason );
158        }
159        else
160        {
161                if( !immed )
162                        irc_write( irc, "ERROR :Closing link" );
163               
164                ipc_to_master_str( "OPERMSG :Client exiting: %s@%s [%s]\r\n",
[f73b969]165                                   irc->nick ? irc->nick : "(NONE)", irc->host, "No reason given" );
[fc50d48]166        }
167       
[79e826a]168        irc->status |= USTATUS_SHUTDOWN;
[fc50d48]169        if( irc->sendbuffer && !immed )
[c1826c6]170        {
[fc50d48]171                /* We won't read from this socket anymore. Instead, we'll connect a timer
172                   to it that should shut down the connection in a second, just in case
173                   bitlbee_.._write doesn't do it first. */
174               
[ba9edaa]175                b_event_remove( irc->r_watch_source_id );
176                irc->r_watch_source_id = b_timeout_add( 1000, (b_event_handler) irc_free, irc );
[c1826c6]177        }
178        else
179        {
180                irc_free( irc );
181        }
182}
183
[36fa9bd]184static gboolean irc_free_hashkey( gpointer key, gpointer value, gpointer data )
[b7d3cc34]185{
186        g_free( key );
187       
188        return( TRUE );
189}
190
191/* Because we have no garbage collection, this is quite annoying */
192void irc_free(irc_t * irc)
193{
[5b52a48]194        account_t *account;
[b7d3cc34]195        user_t *user, *usertmp;
196        help_t *helpnode, *helpnodetmp;
197       
198        log_message( LOGLVL_INFO, "Destroying connection with fd %d", irc->fd );
199       
[d5ccd83]200        if( irc->status & USTATUS_IDENTIFIED && set_getbool( &irc->set, "save_on_quit" ) ) 
[b73ac9c]201                if( storage_save( irc, TRUE ) != STORAGE_OK )
[b7d3cc34]202                        irc_usermsg( irc, "Error while saving settings!" );
203       
[bd9b00f]204        closesocket( irc->fd );
205       
[b7d3cc34]206        if( irc->ping_source_id > 0 )
[ba9edaa]207                b_event_remove( irc->ping_source_id );
208        b_event_remove( irc->r_watch_source_id );
[b7d3cc34]209        if( irc->w_watch_source_id > 0 )
[ba9edaa]210                b_event_remove( irc->w_watch_source_id );
[9c62a7c]211       
[b7d3cc34]212        irc_connection_list = g_slist_remove( irc_connection_list, irc );
213       
[55cc2be3]214        for (account = irc->accounts; account; account = account->next) {
[0da65d5]215                if (account->ic) {
[c2fb3809]216                        imc_logout(account->ic, TRUE);
[c99af3a]217                } else if (account->reconnect) {
[6adcb6c6]218                        cancel_auto_reconnect(account);
[c99af3a]219                }
[55cc2be3]220        }
[b7d3cc34]221       
222        g_free(irc->sendbuffer);
223        g_free(irc->readbuffer);
224       
225        g_free(irc->nick);
226        g_free(irc->user);
227        g_free(irc->host);
228        g_free(irc->realname);
229        g_free(irc->password);
230       
231        g_free(irc->myhost);
232        g_free(irc->mynick);
233       
234        g_free(irc->channel);
235       
236        while (irc->queries != NULL)
237                query_del(irc, irc->queries);
238       
[5b52a48]239        while (irc->accounts)
[0da65d5]240                if (irc->accounts->ic == NULL)
[f959495]241                        account_del(irc, irc->accounts);
242                else
243                        /* Nasty hack, but account_del() doesn't work in this
244                           case and we don't want infinite loops, do we? ;-) */
245                        irc->accounts = irc->accounts->next;
[5b52a48]246       
247        while (irc->set)
248                set_del(&irc->set, irc->set->key);
[b7d3cc34]249       
250        if (irc->users != NULL) {
251                user = irc->users;
252                while (user != NULL) {
253                        g_free(user->nick);
254                        g_free(user->away);
255                        g_free(user->handle);
256                        if(user->user!=user->nick) g_free(user->user);
257                        if(user->host!=user->nick) g_free(user->host);
258                        if(user->realname!=user->nick) g_free(user->realname);
[ba9edaa]259                        b_event_remove(user->sendbuf_timer);
[b7d3cc34]260                                       
261                        usertmp = user;
262                        user = user->next;
263                        g_free(usertmp);
264                }
265        }
266       
[36fa9bd]267        g_hash_table_foreach_remove(irc->userhash, irc_free_hashkey, NULL);
[b7d3cc34]268        g_hash_table_destroy(irc->userhash);
269       
[36fa9bd]270        g_hash_table_foreach_remove(irc->watches, irc_free_hashkey, NULL);
[b7d3cc34]271        g_hash_table_destroy(irc->watches);
272       
273        if (irc->help != NULL) {
274                helpnode = irc->help;
275                while (helpnode != NULL) {
276                        g_free(helpnode->string);
277                       
278                        helpnodetmp = helpnode;
279                        helpnode = helpnode->next;
280                        g_free(helpnodetmp);
281                }
282        }
283        g_free(irc);
284       
[d25f6fc]285        if( global.conf->runmode == RUNMODE_INETD || global.conf->runmode == RUNMODE_FORKDAEMON )
[ba9edaa]286                b_main_quit();
[b7d3cc34]287}
288
[7cad7b4]289/* USE WITH CAUTION!
290   Sets pass without checking */
291void irc_setpass (irc_t *irc, const char *pass) 
292{
[6e1fed7]293        g_free (irc->password);
[7cad7b4]294       
295        if (pass) {
296                irc->password = g_strdup (pass);
297        } else {
298                irc->password = NULL;
299        }
300}
301
[f73b969]302void irc_process( irc_t *irc )
[b7d3cc34]303{
[e27661d]304        char **lines, *temp, **cmd, *cs;
[b7d3cc34]305        int i;
306
[de3e100]307        if( irc->readbuffer != NULL )
308        {
309                lines = irc_tokenize( irc->readbuffer );
310               
311                for( i = 0; *lines[i] != '\0'; i ++ )
312                {
[7d31002]313                        char conv[IRC_MAX_LINE+1];
314                       
[e27661d]315                        /* [WvG] Because irc_tokenize splits at every newline, the lines[] list
316                            should end with an empty string. This is why this actually works.
317                            Took me a while to figure out, Maurits. :-P */
[de3e100]318                        if( lines[i+1] == NULL )
319                        {
[b7d3cc34]320                                temp = g_strdup( lines[i] );
321                                g_free( irc->readbuffer );
322                                irc->readbuffer = temp;
[de3e100]323                                i ++;
[b7d3cc34]324                                break;
[e27661d]325                        }
326                       
[5c9512f]327                        if( ( cs = set_getstr( &irc->set, "charset" ) ) && ( g_strcasecmp( cs, "utf-8" ) != 0 ) )
[e27661d]328                        {
329                                conv[IRC_MAX_LINE] = 0;
330                                if( do_iconv( cs, "UTF-8", lines[i], conv, 0, IRC_MAX_LINE - 2 ) != -1 )
[7d31002]331                                        lines[i] = conv;
[e27661d]332                        }
[de3e100]333                       
[0431ea1]334                        if( ( cmd = irc_parse_line( lines[i] ) ) == NULL )
[de3e100]335                                continue;
[f73b969]336                        irc_exec( irc, cmd );
337                       
338                        g_free( cmd );
339                       
340                        /* Shouldn't really happen, but just in case... */
341                        if( !g_slist_find( irc_connection_list, irc ) )
[de3e100]342                        {
[b7d3cc34]343                                g_free( lines );
[f73b969]344                                return;
[b7d3cc34]345                        }
346                }
[de3e100]347               
348                if( lines[i] != NULL )
349                {
350                        g_free( irc->readbuffer );
[0431ea1]351                        irc->readbuffer = NULL;
[b7d3cc34]352                }
[de3e100]353               
[b7d3cc34]354                g_free( lines );
355        }
356}
357
[e27661d]358/* Splits a long string into separate lines. The array is NULL-terminated and, unless the string
359   contains an incomplete line at the end, ends with an empty string. */
[b7d3cc34]360char **irc_tokenize( char *buffer )
361{
362        int i, j;
363        char **lines;
364
365        /* Count the number of elements we're gonna need. */
[de3e100]366        for( i = 0, j = 1; buffer[i] != '\0'; i ++ )
367        {
368                if( buffer[i] == '\n' )
369                        if( buffer[i+1] != '\r' && buffer[i+1] != '\n' )
370                                j ++;
[b7d3cc34]371        }
372       
373        /* Allocate j+1 elements. */
[de3e100]374        lines = g_new( char *, j + 1 );
[b7d3cc34]375       
376        /* NULL terminate our list. */ 
[de3e100]377        lines[j] = NULL;
[b7d3cc34]378       
[de3e100]379        lines[0] = buffer;
[b7d3cc34]380       
381        /* Split the buffer in several strings, using \r\n as our seperator, where \r is optional.
382         * Although this is not in the RFC, some braindead ircds (newnet's) use this, so some clients might too.
383         */
[de3e100]384        for( i = 0, j = 0; buffer[i] != '\0'; i ++)
385        {
386                if( buffer[i] == '\n' )
387                {
388                        buffer[i] = '\0';
389                       
390                        if( i > 0 && buffer[i-1] == '\r' )
391                                buffer[i-1] = '\0';
392                        if( buffer[i+1] != '\r' && buffer[i+1] != '\n' )
393                                lines[++j] = buffer + i + 1;
[b7d3cc34]394                }
395        }
[de3e100]396       
397        return( lines );
[b7d3cc34]398}
399
[e27661d]400/* Split an IRC-style line into little parts/arguments. */
[0431ea1]401char **irc_parse_line( char *line )
[b7d3cc34]402{
403        int i, j;
404        char **cmd;
405       
406        /* Move the line pointer to the start of the command, skipping spaces and the optional prefix. */
[de3e100]407        if( line[0] == ':' )
408        {
409                for( i = 0; line[i] != ' '; i ++ );
410                line = line + i;
[b7d3cc34]411        }
[de3e100]412        for( i = 0; line[i] == ' '; i ++ );
413        line = line + i;
414       
[b7d3cc34]415        /* If we're already at the end of the line, return. If not, we're going to need at least one element. */
[de3e100]416        if( line[0] == '\0')
417                return NULL;
418       
419        /* Count the number of char **cmd elements we're going to need. */
420        j = 1;
421        for( i = 0; line[i] != '\0'; i ++ )
422        {
423                if( line[i] == ' ' )
424                {
425                        j ++;
[b7d3cc34]426                       
[de3e100]427                        if( line[i+1] == ':' )
428                                break;
429                }
[b7d3cc34]430        }       
431
432        /* Allocate the space we need. */
[de3e100]433        cmd = g_new( char *, j + 1 );
434        cmd[j] = NULL;
[b7d3cc34]435       
436        /* Do the actual line splitting, format is:
437         * Input: "PRIVMSG #bitlbee :foo bar"
438         * Output: cmd[0]=="PRIVMSG", cmd[1]=="#bitlbee", cmd[2]=="foo bar", cmd[3]==NULL
439         */
440
[de3e100]441        cmd[0] = line;
442        for( i = 0, j = 0; line[i] != '\0'; i ++ )
[b7d3cc34]443        {
[de3e100]444                if( line[i] == ' ' )
[b7d3cc34]445                {
[de3e100]446                        line[i] = '\0';
447                        cmd[++j] = line + i + 1;
[b7d3cc34]448                       
[de3e100]449                        if( line[i+1] == ':' )
[b7d3cc34]450                        {
[de3e100]451                                cmd[j] ++;
[b7d3cc34]452                                break;
453                        }
454                }
455        }
456       
[de3e100]457        return cmd;
[b7d3cc34]458}
459
[e27661d]460/* Converts such an array back into a command string. Mainly used for the IPC code right now. */
[74c119d]461char *irc_build_line( char **cmd )
462{
463        int i, len;
464        char *s;
[b7d3cc34]465       
[74c119d]466        if( cmd[0] == NULL )
467                return NULL;
[b7d3cc34]468       
[74c119d]469        len = 1;
470        for( i = 0; cmd[i]; i ++ )
471                len += strlen( cmd[i] ) + 1;
472       
473        if( strchr( cmd[i-1], ' ' ) != NULL )
474                len ++;
475       
476        s = g_new0( char, len + 1 );
477        for( i = 0; cmd[i]; i ++ )
[b7d3cc34]478        {
[74c119d]479                if( cmd[i+1] == NULL && strchr( cmd[i], ' ' ) != NULL )
480                        strcat( s, ":" );
[b7d3cc34]481               
[74c119d]482                strcat( s, cmd[i] );
[b7d3cc34]483               
[74c119d]484                if( cmd[i+1] )
485                        strcat( s, " " );
[b7d3cc34]486        }
[74c119d]487        strcat( s, "\r\n" );
[b7d3cc34]488       
[74c119d]489        return s;
[b7d3cc34]490}
491
492void irc_reply( irc_t *irc, int code, char *format, ... )
493{
494        char text[IRC_MAX_LINE];
495        va_list params;
496       
497        va_start( params, format );
498        g_vsnprintf( text, IRC_MAX_LINE, format, params );
499        va_end( params );
500        irc_write( irc, ":%s %03d %s %s", irc->myhost, code, irc->nick?irc->nick:"*", text );
501       
502        return;
503}
504
505int irc_usermsg( irc_t *irc, char *format, ... )
506{
507        char text[1024];
508        va_list params;
509        char is_private = 0;
510        user_t *u;
511       
512        u = user_find( irc, irc->mynick );
[dd89a55]513        is_private = u->is_private;
[b7d3cc34]514       
515        va_start( params, format );
516        g_vsnprintf( text, sizeof( text ), format, params );
517        va_end( params );
518       
519        return( irc_msgfrom( irc, u->nick, text ) );
520}
521
522void irc_write( irc_t *irc, char *format, ... ) 
523{
524        va_list params;
525
526        va_start( params, format );
527        irc_vawrite( irc, format, params );     
528        va_end( params );
529
530        return;
531
532}
533
534void irc_vawrite( irc_t *irc, char *format, va_list params )
535{
536        int size;
[d783e48]537        char line[IRC_MAX_LINE+1], *cs;
538               
[0356ae3]539        /* Don't try to write anything new anymore when shutting down. */
[5898ef8]540        if( irc->status & USTATUS_SHUTDOWN )
[b7d3cc34]541                return;
[d783e48]542       
543        line[IRC_MAX_LINE] = 0;
544        g_vsnprintf( line, IRC_MAX_LINE - 2, format, params );
545       
[b7d3cc34]546        strip_newlines( line );
[5c9512f]547        if( ( cs = set_getstr( &irc->set, "charset" ) ) && ( g_strcasecmp( cs, "utf-8" ) != 0 ) )
[d783e48]548        {
549                char conv[IRC_MAX_LINE+1];
550               
551                conv[IRC_MAX_LINE] = 0;
552                if( do_iconv( "UTF-8", cs, line, conv, 0, IRC_MAX_LINE - 2 ) != -1 )
553                        strcpy( line, conv );
554        }
[b7d3cc34]555        strcat( line, "\r\n" );
[d783e48]556       
[a0d04d6]557        if( irc->sendbuffer != NULL )
558        {
[b7d3cc34]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        }
[a0d04d6]563        else
[b7d3cc34]564        {
[a0d04d6]565                irc->sendbuffer = g_strdup(line);
[b7d3cc34]566        }
567       
[a0d04d6]568        if( irc->w_watch_source_id == 0 )
[0356ae3]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. */
[bbb6ffb]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 );
[0356ae3]579        }
[a0d04d6]580       
[b7d3cc34]581        return;
582}
583
[22d41a2]584void irc_write_all( int now, char *format, ... )
[b7d3cc34]585{
586        va_list params;
587        GSList *temp;   
[22d41a2]588       
[b7d3cc34]589        va_start( params, format );
[22d41a2]590       
[b7d3cc34]591        temp = irc_connection_list;
[22d41a2]592        while( temp != NULL )
593        {
594                irc_t *irc = temp->data;
595               
596                if( now )
597                {
598                        g_free( irc->sendbuffer );
599                        irc->sendbuffer = g_strdup( "\r\n" );
600                }
[b7d3cc34]601                irc_vawrite( temp->data, format, params );
[22d41a2]602                if( now )
603                {
[a0d04d6]604                        bitlbee_io_current_client_write( irc, irc->fd, GAIM_INPUT_WRITE );
[22d41a2]605                }
[b7d3cc34]606                temp = temp->next;
607        }
[22d41a2]608       
[b7d3cc34]609        va_end( params );
610        return;
611} 
612
613void irc_names( irc_t *irc, char *channel )
614{
[3f9440d]615        user_t *u;
616        char namelist[385] = "";
[0da65d5]617        struct groupchat *c = NULL;
[04026d4]618        char *ops = set_getstr( &irc->set, "ops" );
[b7d3cc34]619       
[2f13222]620        /* RFCs say there is no error reply allowed on NAMES, so when the
[b7d3cc34]621           channel is invalid, just give an empty reply. */
622       
[3f9440d]623        if( g_strcasecmp( channel, irc->channel ) == 0 )
[b7d3cc34]624        {
[3f9440d]625                for( u = irc->users; u; u = u->next ) if( u->online )
[b7d3cc34]626                {
[3f9440d]627                        if( strlen( namelist ) + strlen( u->nick ) > sizeof( namelist ) - 4 )
[b7d3cc34]628                        {
[3f9440d]629                                irc_reply( irc, 353, "= %s :%s", channel, namelist );
630                                *namelist = 0;
[b7d3cc34]631                        }
[3f9440d]632                       
[0da65d5]633                        if( u->ic && !u->away && set_getbool( &irc->set, "away_devoice" ) )
[3f9440d]634                                strcat( namelist, "+" );
[a93e3c8]635                        else if( ( strcmp( u->nick, irc->mynick ) == 0 && ( strcmp( ops, "root" ) == 0 || strcmp( ops, "both" ) == 0 ) ) ||
636                                 ( strcmp( u->nick, irc->nick ) == 0 && ( strcmp( ops, "user" ) == 0 || strcmp( ops, "both" ) == 0 ) ) )
637                                strcat( namelist, "@" );
[3f9440d]638                       
639                        strcat( namelist, u->nick );
640                        strcat( namelist, " " );
[b7d3cc34]641                }
642        }
[fa29d093]643        else if( ( c = chat_by_channel( channel ) ) )
[b7d3cc34]644        {
645                GList *l;
[3f9440d]646               
647                /* root and the user aren't in the channel userlist but should
648                   show up in /NAMES, so list them first: */
649                sprintf( namelist, "%s%s %s%s ", strcmp( ops, "root" ) == 0 || strcmp( ops, "both" ) ? "@" : "", irc->mynick,
650                                                 strcmp( ops, "user" ) == 0 || strcmp( ops, "both" ) ? "@" : "", irc->nick );
[b7d3cc34]651               
[0da65d5]652                for( l = c->in_room; l; l = l->next ) if( ( u = user_findhandle( c->ic, l->data ) ) )
[3f9440d]653                {
654                        if( strlen( namelist ) + strlen( u->nick ) > sizeof( namelist ) - 4 )
655                        {
656                                irc_reply( irc, 353, "= %s :%s", channel, namelist );
657                                *namelist = 0;
658                        }
659                       
660                        strcat( namelist, u->nick );
661                        strcat( namelist, " " );
662                }
[b7d3cc34]663        }
664       
[3f9440d]665        if( *namelist )
666                irc_reply( irc, 353, "= %s :%s", channel, namelist );
667       
[b7d3cc34]668        irc_reply( irc, 366, "%s :End of /NAMES list", channel );
669}
670
[edf9657]671int irc_check_login( irc_t *irc )
[b7d3cc34]672{
[edf9657]673        if( irc->user && irc->nick )
674        {
[3af70b0]675                if( global.conf->authmode == AUTHMODE_CLOSED && !( irc->status & USTATUS_AUTHORIZED ) )
[b7d3cc34]676                {
[edf9657]677                        irc_reply( irc, 464, ":This server is password-protected." );
678                        return 0;
[b7d3cc34]679                }
[edf9657]680                else
[b7d3cc34]681                {
[edf9657]682                        irc_login( irc );
683                        return 1;
[b7d3cc34]684                }
[edf9657]685        }
686        else
687        {
688                /* More information needed. */
689                return 0;
690        }
[b7d3cc34]691}
692
693void irc_login( irc_t *irc )
694{
695        user_t *u;
696       
697        irc_reply( irc,   1, ":Welcome to the BitlBee gateway, %s", irc->nick );
698        irc_reply( irc,   2, ":Host %s is running BitlBee " BITLBEE_VERSION " " ARCH "/" CPU ".", irc->myhost );
699        irc_reply( irc,   3, ":%s", IRCD_INFO );
[238f828]700        irc_reply( irc,   4, "%s %s %s %s", irc->myhost, BITLBEE_VERSION, UMODES UMODES_PRIV, CMODES );
[578d627]701        irc_reply( irc,   5, "PREFIX=(ov)@+ CHANTYPES=#& CHANMODES=,,,%s NICKLEN=%d NETWORK=BitlBee CASEMAPPING=rfc1459 MAXTARGETS=1 WATCH=128 :are supported by this server", CMODES, MAX_NICK_LENGTH - 1 );
[b7d3cc34]702        irc_motd( irc );
[2f13222]703        irc->umode[0] = '\0';
[238f828]704        irc_umode_set( irc, "+" UMODE, 1 );
[b7d3cc34]705
706        u = user_add( irc, irc->mynick );
707        u->host = g_strdup( irc->myhost );
708        u->realname = g_strdup( ROOT_FN );
709        u->online = 1;
710        u->send_handler = root_command_string;
711        u->is_private = 0; /* [SH] The channel is root's personal playground. */
712        irc_spawn( irc, u );
713       
714        u = user_add( irc, NS_NICK );
715        u->host = g_strdup( irc->myhost );
716        u->realname = g_strdup( ROOT_FN );
717        u->online = 0;
718        u->send_handler = root_command_string;
719        u->is_private = 1; /* [SH] NickServ is not in the channel, so should always /query. */
720       
721        u = user_add( irc, irc->nick );
722        u->user = g_strdup( irc->user );
723        u->host = g_strdup( irc->host );
724        u->realname = g_strdup( irc->realname );
725        u->online = 1;
726        irc_spawn( irc, u );
727       
[5e2615a]728        irc_usermsg( irc, "Welcome to the BitlBee gateway!\n\nIf you've never used BitlBee before, please do read the help information using the \x02help\x02 command. Lots of FAQs are answered there." );
[b7d3cc34]729       
[bd9b00f]730        if( global.conf->runmode == RUNMODE_FORKDAEMON || global.conf->runmode == RUNMODE_DAEMON )
[2face62]731                ipc_to_master_str( "CLIENT %s %s :%s\r\n", irc->host, irc->nick, irc->realname );
732       
[79e826a]733        irc->status |= USTATUS_LOGGED_IN;
[b7d3cc34]734}
735
736void irc_motd( irc_t *irc )
737{
738        int fd;
739       
740        fd = open( global.conf->motdfile, O_RDONLY );
741        if( fd == -1 )
742        {
743                irc_reply( irc, 422, ":We don't need MOTDs." );
744        }
745        else
746        {
747                char linebuf[80];       /* Max. line length for MOTD's is 79 chars. It's what most IRC networks seem to do. */
748                char *add, max;
749                int len;
750               
751                linebuf[79] = len = 0;
752                max = sizeof( linebuf ) - 1;
753               
754                irc_reply( irc, 375, ":- %s Message Of The Day - ", irc->myhost );
755                while( read( fd, linebuf + len, 1 ) == 1 )
756                {
757                        if( linebuf[len] == '\n' || len == max )
758                        {
759                                linebuf[len] = 0;
760                                irc_reply( irc, 372, ":- %s", linebuf );
761                                len = 0;
762                        }
763                        else if( linebuf[len] == '%' )
764                        {
765                                read( fd, linebuf + len, 1 );
766                                if( linebuf[len] == 'h' )
767                                        add = irc->myhost;
768                                else if( linebuf[len] == 'v' )
769                                        add = BITLBEE_VERSION;
770                                else if( linebuf[len] == 'n' )
771                                        add = irc->nick;
772                                else
773                                        add = "%";
774                               
775                                strncpy( linebuf + len, add, max - len );
776                                while( linebuf[++len] );
777                        }
778                        else if( len < max )
779                        {
780                                len ++;
781                        }
782                }
783                irc_reply( irc, 376, ":End of MOTD" );
[d990997]784                close( fd );
[b7d3cc34]785        }
786}
787
788void irc_topic( irc_t *irc, char *channel )
789{
790        if( g_strcasecmp( channel, irc->channel ) == 0 )
791        {
792                irc_reply( irc, 332, "%s :%s", channel, CONTROL_TOPIC );
793        }
794        else
795        {
[0da65d5]796                struct groupchat *c = chat_by_channel( channel );
[b7d3cc34]797               
798                if( c )
799                        irc_reply( irc, 332, "%s :BitlBee groupchat: \"%s\". Please keep in mind that root-commands won't work here. Have fun!", channel, c->title );
800                else
[fc630f9]801                        irc_reply( irc, 331, "%s :No topic for this channel", channel );
[b7d3cc34]802        }
803}
804
[238f828]805void irc_umode_set( irc_t *irc, char *s, int allow_priv )
[b7d3cc34]806{
[238f828]807        /* allow_priv: Set to 0 if s contains user input, 1 if you want
808           to set a "privileged" mode (+o, +R, etc). */
[b7d3cc34]809        char m[256], st = 1, *t;
810        int i;
[2f13222]811        char changes[512], *p, st2 = 2;
812        char badflag = 0;
[b7d3cc34]813       
814        memset( m, 0, sizeof( m ) );
815       
816        for( t = irc->umode; *t; t ++ )
817                m[(int)*t] = 1;
[2f13222]818
819        p = changes;
[b7d3cc34]820        for( t = s; *t; t ++ )
821        {
822                if( *t == '+' || *t == '-' )
823                        st = *t == '+';
[238f828]824                else if( st == 0 || ( strchr( UMODES, *t ) || ( allow_priv && strchr( UMODES_PRIV, *t ) ) ) )
[2f13222]825                {
826                        if( m[(int)*t] != st)
827                        {
828                                if( st != st2 )
829                                        st2 = st, *p++ = st ? '+' : '-';
830                                *p++ = *t;
831                        }
[b7d3cc34]832                        m[(int)*t] = st;
[2f13222]833                }
834                else
835                        badflag = 1;
[b7d3cc34]836        }
[2f13222]837        *p = '\0';
[b7d3cc34]838       
839        memset( irc->umode, 0, sizeof( irc->umode ) );
840       
841        for( i = 0; i < 256 && strlen( irc->umode ) < ( sizeof( irc->umode ) - 1 ); i ++ )
[238f828]842                if( m[i] )
[b7d3cc34]843                        irc->umode[strlen(irc->umode)] = i;
844       
[2f13222]845        if( badflag )
846                irc_reply( irc, 501, ":Unknown MODE flag" );
847        /* Deliberately no !user@host on the prefix here */
848        if( *changes )
849                irc_write( irc, ":%s MODE %s %s", irc->nick, irc->nick, changes );
[b7d3cc34]850}
851
852void irc_spawn( irc_t *irc, user_t *u )
853{
854        irc_join( irc, u, irc->channel );
855}
856
857void irc_join( irc_t *irc, user_t *u, char *channel )
858{
859        char *nick;
860       
861        if( ( g_strcasecmp( channel, irc->channel ) != 0 ) || user_find( irc, irc->nick ) )
862                irc_write( irc, ":%s!%s@%s JOIN :%s", u->nick, u->user, u->host, channel );
863       
864        if( nick_cmp( u->nick, irc->nick ) == 0 )
865        {
866                irc_write( irc, ":%s MODE %s +%s", irc->myhost, channel, CMODE );
867                irc_names( irc, channel );
868                irc_topic( irc, channel );
869        }
870       
871        nick = g_strdup( u->nick );
872        nick_lc( nick );
873        if( g_hash_table_lookup( irc->watches, nick ) )
874        {
[fc630f9]875                irc_reply( irc, 600, "%s %s %s %d :%s", u->nick, u->user, u->host, (int) time( NULL ), "logged online" );
[b7d3cc34]876        }
877        g_free( nick );
878}
879
880void irc_part( irc_t *irc, user_t *u, char *channel )
881{
882        irc_write( irc, ":%s!%s@%s PART %s :%s", u->nick, u->user, u->host, channel, "" );
883}
884
885void irc_kick( irc_t *irc, user_t *u, char *channel, user_t *kicker )
886{
887        irc_write( irc, ":%s!%s@%s KICK %s %s :%s", kicker->nick, kicker->user, kicker->host, channel, u->nick, "" );
888}
889
890void irc_kill( irc_t *irc, user_t *u )
891{
[fb62f81f]892        char *nick, *s;
[0a3c243]893        char reason[128];
[fb62f81f]894       
[1186382]895        if( u->ic && u->ic->flags & OPT_LOGGING_OUT && set_getbool( &irc->set, "simulate_netsplit" ) )
[fb62f81f]896        {
[0da65d5]897                if( u->ic->acc->server )
[fb62f81f]898                        g_snprintf( reason, sizeof( reason ), "%s %s", irc->myhost,
[0da65d5]899                                    u->ic->acc->server );
[c2fb3809]900                else if( ( s = strchr( u->ic->acc->user, '@' ) ) )
[fb62f81f]901                        g_snprintf( reason, sizeof( reason ), "%s %s", irc->myhost,
902                                    s + 1 );
903                else
904                        g_snprintf( reason, sizeof( reason ), "%s %s.%s", irc->myhost,
[0da65d5]905                                    u->ic->acc->prpl->name, irc->myhost );
[fb62f81f]906               
907                /* proto_opt might contain garbage after the : */
908                if( ( s = strchr( reason, ':' ) ) )
909                        *s = 0;
910        }
911        else
912        {
913                strcpy( reason, "Leaving..." );
914        }
[b7d3cc34]915       
[fb62f81f]916        irc_write( irc, ":%s!%s@%s QUIT :%s", u->nick, u->user, u->host, reason );
[b7d3cc34]917       
918        nick = g_strdup( u->nick );
919        nick_lc( nick );
920        if( g_hash_table_lookup( irc->watches, nick ) )
921        {
[fc630f9]922                irc_reply( irc, 601, "%s %s %s %d :%s", u->nick, u->user, u->host, (int) time( NULL ), "logged offline" );
[b7d3cc34]923        }
924        g_free( nick );
925}
926
927int irc_send( irc_t *irc, char *nick, char *s, int flags )
928{
[0da65d5]929        struct groupchat *c = NULL;
[b7d3cc34]930        user_t *u = NULL;
931       
[94281ef]932        if( *nick == '#' || *nick == '&' )
[b7d3cc34]933        {
[fa29d093]934                if( !( c = chat_by_channel( nick ) ) )
[b7d3cc34]935                {
936                        irc_reply( irc, 403, "%s :Channel does not exist", nick );
937                        return( 0 );
938                }
939        }
940        else
941        {
942                u = user_find( irc, nick );
943               
944                if( !u )
945                {
946                        if( irc->is_private )
947                                irc_reply( irc, 401, "%s :Nick does not exist", nick );
948                        else
949                                irc_usermsg( irc, "Nick `%s' does not exist!", nick );
950                        return( 0 );
951                }
952        }
953       
954        if( *s == 1 && s[strlen(s)-1] == 1 )
955        {
956                if( g_strncasecmp( s + 1, "ACTION", 6 ) == 0 )
957                {
958                        if( s[7] == ' ' ) s ++;
959                        s += 3;
960                        *(s++) = '/';
961                        *(s++) = 'm';
962                        *(s++) = 'e';
963                        *(s++) = ' ';
964                        s -= 4;
965                        s[strlen(s)-1] = 0;
966                }
967                else if( g_strncasecmp( s + 1, "VERSION", 7 ) == 0 )
968                {
969                        u = user_find( irc, irc->mynick );
970                        irc_privmsg( irc, u, "NOTICE", irc->nick, "", "\001VERSION BitlBee " BITLBEE_VERSION " " ARCH "/" CPU "\001" );
971                        return( 1 );
972                }
973                else if( g_strncasecmp( s + 1, "PING", 4 ) == 0 )
974                {
975                        u = user_find( irc, irc->mynick );
976                        irc_privmsg( irc, u, "NOTICE", irc->nick, "", s );
977                        return( 1 );
978                }
979                else if( g_strncasecmp( s + 1, "TYPING", 6 ) == 0 )
980                {
[0da65d5]981                        if( u && u->ic && u->ic->acc->prpl->send_typing && strlen( s ) >= 10 )
[b7d3cc34]982                        {
983                                time_t current_typing_notice = time( NULL );
984                               
985                                if( current_typing_notice - u->last_typing_notice >= 5 )
986                                {
[df1fb67]987                                        u->ic->acc->prpl->send_typing( u->ic, u->handle, ( s[8] - '0' ) << 8 );
[b7d3cc34]988                                        u->last_typing_notice = current_typing_notice;
989                                }
990                        }
991                        return( 1 );
992                }
993                else
994                {
995                        irc_usermsg( irc, "Non-ACTION CTCP's aren't supported" );
996                        return( 0 );
997                }
998        }
999       
1000        if( u )
1001        {
1002                /* For the next message, we probably do have to send new notices... */
1003                u->last_typing_notice = 0;
1004                u->is_private = irc->is_private;
1005               
1006                if( u->is_private )
1007                {
1008                        if( !u->online )
1009                                irc_reply( irc, 301, "%s :%s", u->nick, "User is offline" );
1010                        else if( u->away )
1011                                irc_reply( irc, 301, "%s :%s", u->nick, u->away );
1012                }
1013               
1014                if( u->send_handler )
[f73b969]1015                {
1016                        u->send_handler( irc, u, s, flags );
1017                        return 1;
1018                }
[b7d3cc34]1019        }
[0da65d5]1020        else if( c && c->ic && c->ic->acc && c->ic->acc->prpl )
[b7d3cc34]1021        {
[84b045d]1022                return( imc_chat_msg( c, s, 0 ) );
[b7d3cc34]1023        }
1024       
1025        return( 0 );
1026}
1027
[ba9edaa]1028static gboolean buddy_send_handler_delayed( gpointer data, gint fd, b_input_condition cond )
[b7d3cc34]1029{
1030        user_t *u = data;
1031       
[226fce1]1032        /* Shouldn't happen, but just to be sure. */
1033        if( u->sendbuf_len < 2 )
1034                return FALSE;
1035       
[b7d3cc34]1036        u->sendbuf[u->sendbuf_len-2] = 0; /* Cut off the last newline */
[84b045d]1037        imc_buddy_msg( u->ic, u->handle, u->sendbuf, u->sendbuf_flags );
[b7d3cc34]1038       
1039        g_free( u->sendbuf );
1040        u->sendbuf = NULL;
1041        u->sendbuf_len = 0;
1042        u->sendbuf_timer = 0;
1043        u->sendbuf_flags = 0;
1044       
[ba9edaa]1045        return FALSE;
[b7d3cc34]1046}
1047
[f73b969]1048void buddy_send_handler( irc_t *irc, user_t *u, char *msg, int flags )
[b7d3cc34]1049{
[0da65d5]1050        if( !u || !u->ic ) return;
[b7d3cc34]1051       
[d5ccd83]1052        if( set_getbool( &irc->set, "buddy_sendbuffer" ) && set_getint( &irc->set, "buddy_sendbuffer_delay" ) > 0 )
[b7d3cc34]1053        {
[834ff44]1054                int delay;
1055               
[b7d3cc34]1056                if( u->sendbuf_len > 0 && u->sendbuf_flags != flags)
1057                {
[226fce1]1058                        /* Flush the buffer */
[ba9edaa]1059                        b_event_remove( u->sendbuf_timer );
1060                        buddy_send_handler_delayed( u, -1, 0 );
[b7d3cc34]1061                }
1062
1063                if( u->sendbuf_len == 0 )
1064                {
1065                        u->sendbuf_len = strlen( msg ) + 2;
[226fce1]1066                        u->sendbuf = g_new( char, u->sendbuf_len );
[b7d3cc34]1067                        u->sendbuf[0] = 0;
1068                        u->sendbuf_flags = flags;
1069                }
1070                else
1071                {
1072                        u->sendbuf_len += strlen( msg ) + 1;
[226fce1]1073                        u->sendbuf = g_renew( char, u->sendbuf, u->sendbuf_len );
[b7d3cc34]1074                }
1075               
1076                strcat( u->sendbuf, msg );
1077                strcat( u->sendbuf, "\n" );
1078               
[5c9512f]1079                delay = set_getint( &irc->set, "buddy_sendbuffer_delay" );
[834ff44]1080                if( delay <= 5 )
1081                        delay *= 1000;
1082               
[b7d3cc34]1083                if( u->sendbuf_timer > 0 )
[ba9edaa]1084                        b_event_remove( u->sendbuf_timer );
1085                u->sendbuf_timer = b_timeout_add( delay, buddy_send_handler_delayed, u );
[b7d3cc34]1086        }
1087        else
1088        {
[84b045d]1089                imc_buddy_msg( u->ic, u->handle, msg, flags );
[b7d3cc34]1090        }
1091}
1092
1093int irc_privmsg( irc_t *irc, user_t *u, char *type, char *to, char *prefix, char *msg )
1094{
1095        char last = 0;
1096        char *s = msg, *line = msg;
1097       
1098        /* The almighty linesplitter .. woohoo!! */
1099        while( !last )
1100        {
1101                if( *s == '\r' && *(s+1) == '\n' )
1102                        *(s++) = 0;
1103                if( *s == '\n' )
1104                {
1105                        last = s[1] == 0;
1106                        *s = 0;
1107                }
1108                else
1109                {
1110                        last = s[0] == 0;
1111                }
1112                if( *s == 0 )
1113                {
1114                        if( g_strncasecmp( line, "/me ", 4 ) == 0 && ( !prefix || !*prefix ) && g_strcasecmp( type, "PRIVMSG" ) == 0 )
1115                        {
1116                                irc_write( irc, ":%s!%s@%s %s %s :\001ACTION %s\001", u->nick, u->user, u->host,
1117                                           type, to, line + 4 );
1118                        }
1119                        else
1120                        {
1121                                irc_write( irc, ":%s!%s@%s %s %s :%s%s", u->nick, u->user, u->host,
[25d1be7]1122                                           type, to, prefix ? prefix : "", line );
[b7d3cc34]1123                        }
1124                        line = s + 1;
1125                }
1126                s ++;
1127        }
1128       
1129        return( 1 );
1130}
1131
1132int irc_msgfrom( irc_t *irc, char *nick, char *msg )
1133{
1134        user_t *u = user_find( irc, nick );
1135        static char *prefix = NULL;
1136       
1137        if( !u ) return( 0 );
1138        if( prefix && *prefix ) g_free( prefix );
1139       
1140        if( !u->is_private && nick_cmp( u->nick, irc->mynick ) != 0 )
1141        {
1142                int len = strlen( irc->nick) + 3;
1143                prefix = g_new (char, len );
[5c9512f]1144                g_snprintf( prefix, len, "%s%s", irc->nick, set_getstr( &irc->set, "to_char" ) );
[b7d3cc34]1145                prefix[len-1] = 0;
1146        }
1147        else
1148        {
1149                prefix = "";
1150        }
1151       
1152        return( irc_privmsg( irc, u, "PRIVMSG", u->is_private ? irc->nick : irc->channel, prefix, msg ) );
1153}
1154
1155int irc_noticefrom( irc_t *irc, char *nick, char *msg )
1156{
1157        user_t *u = user_find( irc, nick );
1158       
1159        if( u )
1160                return( irc_privmsg( irc, u, "NOTICE", irc->nick, "", msg ) );
1161        else
1162                return( 0 );
1163}
1164
1165/* Returns 0 if everything seems to be okay, a number >0 when there was a
1166   timeout. The number returned is the number of seconds we received no
1167   pongs from the user. When not connected yet, we don't ping but drop the
1168   connection when the user fails to connect in IRC_LOGIN_TIMEOUT secs. */
[ba9edaa]1169static gboolean irc_userping( gpointer _irc, gint fd, b_input_condition cond )
[b7d3cc34]1170{
1171        irc_t *irc = _irc;
1172        int rv = 0;
1173       
[3af70b0]1174        if( !( irc->status & USTATUS_LOGGED_IN ) )
[b7d3cc34]1175        {
1176                if( gettime() > ( irc->last_pong + IRC_LOGIN_TIMEOUT ) )
1177                        rv = gettime() - irc->last_pong;
1178        }
1179        else
1180        {
1181                if( ( gettime() > ( irc->last_pong + global.conf->ping_interval ) ) && !irc->pinging )
1182                {
1183                        irc_write( irc, "PING :%s", IRC_PING_STRING );
1184                        irc->pinging = 1;
1185                }
1186                else if( gettime() > ( irc->last_pong + global.conf->ping_timeout ) )
1187                {
1188                        rv = gettime() - irc->last_pong;
1189                }
1190        }
1191       
1192        if( rv > 0 )
1193        {
[f73b969]1194                irc_abort( irc, 0, "Ping Timeout: %d seconds", rv );
[b7d3cc34]1195                return FALSE;
1196        }
1197       
1198        return TRUE;
1199}
Note: See TracBrowser for help on using the repository browser.