Changeset 18ff38f


Ignore:
Timestamp:
2008-03-29T23:15:04Z (16 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
5ecf96b
Parents:
a199d33
Message:

Be more liberal with accepted line endings. ERC on Windows likes to use
"\r\r\n", for example, and until now BitlBee only chopped off the \r\n,
leaving the first \r as part of the command, which means it couldn't log
in to BitlBee at all. (Bad character in nickname.)

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • irc.c

    ra199d33 r18ff38f  
    297297                        char conv[IRC_MAX_LINE+1];
    298298                       
    299                         /* [WvG] Because irc_tokenize splits at every newline, the lines[] list
    300                             should end with an empty string. This is why this actually works.
    301                             Took me a while to figure out, Maurits. :-P */
     299                        /* [WvG] If the last line isn't empty, it's an incomplete line and we
     300                           should wait for the rest to come in before processing it. */
    302301                        if( lines[i+1] == NULL )
    303302                        {
     
    369368char **irc_tokenize( char *buffer )
    370369{
    371         int i, j;
     370        int i, j, n = 3;
    372371        char **lines;
    373372
    374         /* Count the number of elements we're gonna need. */
    375         for( i = 0, j = 1; buffer[i] != '\0'; i ++ )
    376         {
    377                 if( buffer[i] == '\n' )
    378                         if( buffer[i+1] != '\r' && buffer[i+1] != '\n' )
    379                                 j ++;
    380         }
    381        
    382         /* Allocate j+1 elements. */
    383         lines = g_new( char *, j + 1 );
     373        /* Allocate n+1 elements. */
     374        lines = g_new( char *, n + 1 );
     375       
     376        lines[0] = buffer;
     377       
     378        /* Split the buffer in several strings, and accept any kind of line endings,
     379         * knowing that ERC on Windows may send something interesting like \r\r\n,
     380         * and surely there must be clients that think just \n is enough... */
     381        for( i = 0, j = 0; buffer[i] != '\0'; i ++ )
     382        {
     383                if( buffer[i] == '\r' || buffer[i] == '\n' )
     384                {
     385                        while( buffer[i] == '\r' || buffer[i] == '\n' )
     386                                buffer[i++] = '\0';
     387                       
     388                        lines[++j] = buffer + i;
     389                       
     390                        if( j >= n )
     391                        {
     392                                n *= 2;
     393                                lines = g_renew( char *, lines, n + 1 );
     394                        }
     395
     396                        if( buffer[i] == '\0' )
     397                                break;
     398                }
     399        }
    384400       
    385401        /* NULL terminate our list. */
    386         lines[j] = NULL;
    387        
    388         lines[0] = buffer;
    389        
    390         /* Split the buffer in several strings, using \r\n as our seperator, where \r is optional.
    391          * Although this is not in the RFC, some braindead ircds (newnet's) use this, so some clients might too.
    392          */
    393         for( i = 0, j = 0; buffer[i] != '\0'; i ++)
    394         {
    395                 if( buffer[i] == '\n' )
    396                 {
    397                         buffer[i] = '\0';
    398                        
    399                         if( i > 0 && buffer[i-1] == '\r' )
    400                                 buffer[i-1] = '\0';
    401                         if( buffer[i+1] != '\r' && buffer[i+1] != '\n' )
    402                                 lines[++j] = buffer + i + 1;
    403                 }
    404         }
    405        
    406         return( lines );
     402        lines[++j] = NULL;
     403       
     404        return lines;
    407405}
    408406
  • tests/check_irc.c

    ra199d33 r18ff38f  
    3737        irc = irc_new(g_io_channel_unix_get_fd(ch1));
    3838
    39         fail_unless(g_io_channel_write_chars(ch2, "NICK bla\r\n"
    40                         "USER a a a a\r\n", -1, NULL, NULL) == G_IO_STATUS_NORMAL);
     39        fail_unless(g_io_channel_write_chars(ch2, "NICK bla\r\r\n"
     40                        "USER a a a a\n", -1, NULL, NULL) == G_IO_STATUS_NORMAL);
    4141        fail_unless(g_io_channel_flush(ch2, NULL) == G_IO_STATUS_NORMAL);
    4242
Note: See TracChangeset for help on using the changeset viewer.