Changeset 89c11e7 for dcc.c


Ignore:
Timestamp:
2010-04-12T23:54:55Z (14 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
7b59872
Parents:
24b8bbb
Message:

Restored CTCP/DCC hooks for outgoing file transfers.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • dcc.c

    r24b8bbb r89c11e7  
    504504 *
    505505 */
    506 file_transfer_t *dcc_request( struct im_connection *ic, char *line )
     506file_transfer_t *dcc_request( struct im_connection *ic, char* const* ctcp )
    507507{
    508508        irc_t *irc = (irc_t *) ic->bee->ui_data;
    509         char *pattern = "SEND"
    510                 " (([^\"][^ ]*)|\"(([^\"]|\\\")*)\")"
    511                 " (([0-9]*)|([^ ]*))"
    512                 " ([0-9]*)"
    513                 " ([0-9]*)\001";
    514         regmatch_t pmatch[10];
    515         regex_t re;
    516509        file_transfer_t *ft;
    517510        dcc_file_transfer_t *df;
    518         char errbuf[256];
    519         int regerrcode, gret;
    520 
    521         if( ( regerrcode = regcomp( &re, pattern, REG_EXTENDED ) ) ||
    522             ( regerrcode = regexec( &re, line, 10, pmatch, 0 ) ) ) {
    523                 regerror( regerrcode,&re,errbuf,sizeof( errbuf ) );
    524                 imcb_log( ic,
    525                           "DCC: error parsing 'DCC SEND': %s, line: %s",
    526                           errbuf, line );
    527                 return NULL;
    528         }
    529 
    530         if( ( pmatch[1].rm_so > 0 ) &&
    531             ( pmatch[5].rm_so > 0 ) &&
    532             ( pmatch[8].rm_so > 0 ) &&
    533             ( pmatch[9].rm_so > 0 ) )
    534         {
    535                 char *input = g_strdup( line );
     511        int gret;
     512        size_t filesize;
     513       
     514        if( ctcp[5] != NULL &&
     515            sscanf( ctcp[4], "%zd", &filesize ) == 1 && /* Just int. validation. */
     516            sscanf( ctcp[5], "%zd", &filesize ) == 1 )
     517        {
    536518                char *filename, *host, *port;
    537                 size_t filesize;
    538519                struct addrinfo hints, *rp;
    539 
    540                 /* "filename" or filename */
    541                 if ( pmatch[2].rm_so > 0 )
     520               
     521                filename = ctcp[2];
     522               
     523                host = ctcp[3];
     524                while( *host && isdigit( *host ) ) host++; /* Just digits? */
     525                if( *host == '\0' )
    542526                {
    543                         input[pmatch[2].rm_eo] = '\0';
    544                         filename = input + pmatch[2].rm_so;
    545                 } else
    546                 {
    547                         input[pmatch[3].rm_eo] = '\0';
    548                         filename = input + pmatch[3].rm_so;
    549                 }
    550                        
    551                 input[pmatch[5].rm_eo] = '\0';
    552 
    553                 /* number means ipv4, something else means ipv6 */
    554                 if ( pmatch[6].rm_so > 0 )
    555                 {
    556                         struct in_addr ipaddr = { .s_addr = htonl( strtoul( input + pmatch[5].rm_so, NULL, 10 ) ) };
     527                        struct in_addr ipaddr = { .s_addr = htonl( atoll( ctcp[3] ) ) };
    557528                        host = inet_ntoa( ipaddr );
    558529                } else
    559530                {
    560531                        /* Contains non-numbers, hopefully an IPV6 address */
    561                         host = input + pmatch[7].rm_so;
     532                        host = ctcp[3];
    562533                }
    563534
    564                 input[pmatch[8].rm_eo] = '\0';
    565                 input[pmatch[9].rm_eo] = '\0';
    566 
    567                 port = input + pmatch[8].rm_so;
    568                 filesize = atoll( input + pmatch[9].rm_so );
     535                port = ctcp[4];
     536                filesize = atoll( ctcp[5] );
    569537
    570538                memset( &hints, 0, sizeof ( struct addrinfo ) );
     
    574542                if ( ( gret = getaddrinfo( host, port, &hints, &rp ) ) )
    575543                {
    576                         g_free( input );
    577544                        imcb_log( ic, "DCC: getaddrinfo() failed with %s "
    578545                                  "when parsing incoming 'DCC SEND': "
     
    588555
    589556                freeaddrinfo( rp );
    590                 g_free( input );
    591557
    592558                irc->file_transfers = g_slist_prepend( irc->file_transfers, ft );
     
    594560                return ft;
    595561        }
    596 
    597         imcb_log( ic, "DCC: couldnt parse 'DCC SEND' line: %s", line );
     562        else
     563                imcb_log( ic, "DCC: couldnt parse `DCC SEND' line" );
    598564
    599565        return NULL;
Note: See TracChangeset for help on using the changeset viewer.