Changeset 89c11e7
- Timestamp:
- 2010-04-12T23:54:55Z (15 years ago)
- Branches:
- master
- Children:
- 7b59872
- Parents:
- 24b8bbb
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
dcc.c
r24b8bbb r89c11e7 504 504 * 505 505 */ 506 file_transfer_t *dcc_request( struct im_connection *ic, char *line)506 file_transfer_t *dcc_request( struct im_connection *ic, char* const* ctcp ) 507 507 { 508 508 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;516 509 file_transfer_t *ft; 517 510 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 { 536 518 char *filename, *host, *port; 537 size_t filesize;538 519 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' ) 542 526 { 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] ) ) }; 557 528 host = inet_ntoa( ipaddr ); 558 529 } else 559 530 { 560 531 /* Contains non-numbers, hopefully an IPV6 address */ 561 host = input + pmatch[7].rm_so;532 host = ctcp[3]; 562 533 } 563 534 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] ); 569 537 570 538 memset( &hints, 0, sizeof ( struct addrinfo ) ); … … 574 542 if ( ( gret = getaddrinfo( host, port, &hints, &rp ) ) ) 575 543 { 576 g_free( input );577 544 imcb_log( ic, "DCC: getaddrinfo() failed with %s " 578 545 "when parsing incoming 'DCC SEND': " … … 588 555 589 556 freeaddrinfo( rp ); 590 g_free( input );591 557 592 558 irc->file_transfers = g_slist_prepend( irc->file_transfers, ft ); … … 594 560 return ft; 595 561 } 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" ); 598 564 599 565 return NULL; -
dcc.h
r24b8bbb r89c11e7 98 98 void dcc_canceled( file_transfer_t *file, char *reason ); 99 99 gboolean dccs_send_write( file_transfer_t *file, char *data, unsigned int data_size ); 100 file_transfer_t *dcc_request( struct im_connection *ic, char *line);100 file_transfer_t *dcc_request( struct im_connection *ic, char* const* ctcp ); 101 101 void dcc_finish( file_transfer_t *file ); 102 102 void dcc_close( file_transfer_t *file ); -
irc_im.c
r24b8bbb r89c11e7 211 211 } 212 212 213 static gboolean bee_irc_user_ctcp( irc_user_t *iu, char *const *ctcp ) 214 { 215 if( ctcp[1] && g_strcasecmp( ctcp[0], "DCC" ) == 0 216 && g_strcasecmp( ctcp[1], "SEND" ) == 0 ) 217 { 218 if( iu->bu && iu->bu->ic && iu->bu->ic->acc->prpl->transfer_request ) 219 { 220 file_transfer_t *ft = dcc_request( iu->bu->ic, ctcp ); 221 if ( ft ) 222 iu->bu->ic->acc->prpl->transfer_request( iu->bu->ic, ft, iu->bu->handle ); 223 224 return TRUE; 225 } 226 } 227 228 return FALSE; 229 } 230 213 231 static const struct irc_user_funcs irc_user_im_funcs = { 214 232 bee_irc_user_privmsg, 233 bee_irc_user_ctcp, 215 234 }; -
lib/misc.c
r24b8bbb r89c11e7 655 655 q = *s = 0; 656 656 } 657 cmd[k] = NULL; 657 658 /* Full zero-padding for easier argc checking. */ 659 while( k <= IRC_MAX_ARGS ) 660 cmd[k++] = NULL; 658 661 659 662 return cmd;
Note: See TracChangeset
for help on using the changeset viewer.