Changes in root_commands.c [0baed0d:6fd4d46]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
root_commands.c
r0baed0d r6fd4d46 26 26 #define BITLBEE_CORE 27 27 #include "commands.h" 28 #include "crypting.h"29 28 #include "bitlbee.h" 30 29 #include "help.h" … … 33 32 #include <string.h> 34 33 35 void root_command_string( irc_t *irc, user_t *u, char *command, int flags ) 36 { 37 char *cmd[IRC_MAX_ARGS]; 38 char *s; 39 int k; 40 char q = 0; 41 42 memset( cmd, 0, sizeof( cmd ) ); 43 cmd[0] = command; 44 k = 1; 45 for( s = command; *s && k < ( IRC_MAX_ARGS - 1 ); s ++ ) 46 if( *s == ' ' && !q ) 47 { 48 *s = 0; 49 while( *++s == ' ' ); 50 if( *s == '"' || *s == '\'' ) 51 { 52 q = *s; 53 s ++; 54 } 55 if( *s ) 56 { 57 cmd[k++] = s; 58 s --; 59 } 60 else 61 { 62 break; 63 } 64 } 65 else if( *s == '\\' && ( ( !q && s[1] ) || ( q && q == s[1] ) ) ) 66 { 67 char *cpy; 68 69 for( cpy = s; *cpy; cpy ++ ) 70 cpy[0] = cpy[1]; 71 } 72 else if( *s == q ) 73 { 74 q = *s = 0; 75 } 76 cmd[k] = NULL; 77 78 root_command( irc, cmd ); 34 void root_command_string( irc_t *irc, char *command ) 35 { 36 root_command( irc, split_command_parts( command ) ); 79 37 } 80 38 … … 93 51 void root_command( irc_t *irc, char *cmd[] ) 94 52 { 95 int i ;53 int i, len; 96 54 97 55 if( !cmd[0] ) 98 56 return; 99 57 58 len = strlen( cmd[0] ); 100 59 for( i = 0; commands[i].command; i++ ) 101 if( g_strcasecmp( commands[i].command, cmd[0] ) == 0 ) 102 { 60 if( g_strncasecmp( commands[i].command, cmd[0], len ) == 0 ) 61 { 62 if( commands[i+1].command && 63 g_strncasecmp( commands[i+1].command, cmd[0], len ) == 0 ) 64 /* Only match on the first letters if the match is unique. */ 65 break; 66 103 67 MIN_ARGS( commands[i].required_parameters ); 104 68 … … 162 126 irc->status |= USTATUS_IDENTIFIED; 163 127 irc_umode_set( irc, "+R", 1 ); 164 if( set_getbool( &irc-> set, "auto_connect" ) )128 if( set_getbool( &irc->b->set, "auto_connect" ) ) 165 129 cmd_account( irc, account_on ); 166 130 break; … … 202 166 storage_status_t status; 203 167 204 status = storage_remove (irc-> nick, cmd[1]);168 status = storage_remove (irc->user->nick, cmd[1]); 205 169 switch (status) { 206 170 case STORAGE_NO_SUCH_USER: … … 214 178 irc->status &= ~USTATUS_IDENTIFIED; 215 179 irc_umode_set( irc, "-R", 1 ); 216 irc_usermsg( irc, "Account `%s' removed", irc-> nick );180 irc_usermsg( irc, "Account `%s' removed", irc->user->nick ); 217 181 break; 218 182 default: … … 222 186 } 223 187 224 struct cmd_account_del_data 225 { 226 account_t *a; 227 irc_t *irc; 228 }; 229 230 void cmd_account_del_yes( void *data ) 231 { 232 struct cmd_account_del_data *cad = data; 233 account_t *a; 234 235 for( a = cad->irc->accounts; a && a != cad->a; a = a->next ); 236 237 if( a == NULL ) 238 { 239 irc_usermsg( cad->irc, "Account already deleted" ); 240 } 241 else if( a->ic ) 242 { 243 irc_usermsg( cad->irc, "Account is still logged in, can't delete" ); 244 } 245 else 246 { 247 account_del( cad->irc, a ); 248 irc_usermsg( cad->irc, "Account deleted" ); 249 } 250 g_free( data ); 251 } 252 253 void cmd_account_del_no( void *data ) 254 { 255 g_free( data ); 188 static void cmd_save( irc_t *irc, char **cmd ) 189 { 190 if( ( irc->status & USTATUS_IDENTIFIED ) == 0 ) 191 irc_usermsg( irc, "Please create an account first" ); 192 else if( storage_save( irc, NULL, TRUE ) == STORAGE_OK ) 193 irc_usermsg( irc, "Configuration saved" ); 194 else 195 irc_usermsg( irc, "Configuration could not be saved!" ); 256 196 } 257 197 … … 286 226 set_name = set_full; 287 227 288 head = &irc-> set;228 head = &irc->b->set; 289 229 } 290 230 else … … 357 297 account_t *a; 358 298 359 if( ( a = account_get( irc , id ) ) )299 if( ( a = account_get( irc->b, id ) ) ) 360 300 return &a->set; 361 301 else … … 405 345 } 406 346 407 a = account_add( irc , prpl, cmd[3], cmd[4] );347 a = account_add( irc->b, prpl, cmd[3], cmd[4] ); 408 348 if( cmd[5] ) 409 349 { … … 419 359 MIN_ARGS( 2 ); 420 360 421 if( !( a = account_get( irc , cmd[2] ) ) )361 if( !( a = account_get( irc->b, cmd[2] ) ) ) 422 362 { 423 363 irc_usermsg( irc, "Invalid account" ); … … 429 369 else 430 370 { 431 struct cmd_account_del_data *cad; 432 char *msg; 433 434 cad = g_malloc( sizeof( struct cmd_account_del_data ) ); 435 cad->a = a; 436 cad->irc = irc; 437 438 msg = g_strdup_printf( "If you remove this account (%s(%s)), BitlBee will " 439 "also forget all your saved nicknames. If you want " 440 "to change your username/password, use the `account " 441 "set' command. Are you sure you want to delete this " 442 "account?", a->prpl->name, a->user ); 443 query_add( irc, NULL, msg, cmd_account_del_yes, cmd_account_del_no, cad ); 444 g_free( msg ); 371 account_del( irc->b, a ); 372 irc_usermsg( irc, "Account deleted" ); 445 373 } 446 374 } … … 452 380 irc_usermsg( irc, "Account list:" ); 453 381 454 for( a = irc-> accounts; a; a = a->next )382 for( a = irc->b->accounts; a; a = a->next ) 455 383 { 456 384 char *con; … … 475 403 if( cmd[2] ) 476 404 { 477 if( ( a = account_get( irc , cmd[2] ) ) )405 if( ( a = account_get( irc->b, cmd[2] ) ) ) 478 406 { 479 407 if( a->ic ) … … 484 412 else 485 413 { 486 account_on( irc , a );414 account_on( irc->b, a ); 487 415 } 488 416 } … … 495 423 else 496 424 { 497 if ( irc->accounts ) { 425 if ( irc->b->accounts ) 426 { 498 427 irc_usermsg( irc, "Trying to get all accounts connected..." ); 499 428 500 for( a = irc-> accounts; a; a = a->next )429 for( a = irc->b->accounts; a; a = a->next ) 501 430 if( !a->ic && a->auto_connect ) 502 account_on( irc , a );431 account_on( irc->b, a ); 503 432 } 504 433 else … … 514 443 irc_usermsg( irc, "Deactivating all active (re)connections..." ); 515 444 516 for( a = irc-> accounts; a; a = a->next )445 for( a = irc->b->accounts; a; a = a->next ) 517 446 { 518 447 if( a->ic ) 519 account_off( irc , a );448 account_off( irc->b, a ); 520 449 else if( a->reconnect ) 521 450 cancel_auto_reconnect( a ); 522 451 } 523 452 } 524 else if( ( a = account_get( irc , cmd[2] ) ) )453 else if( ( a = account_get( irc->b, cmd[2] ) ) ) 525 454 { 526 455 if( a->ic ) 527 456 { 528 account_off( irc , a );457 account_off( irc->b, a ); 529 458 } 530 459 else if( a->reconnect ) … … 569 498 } 570 499 571 if( !( a = account_get( irc , cmd[1] ) ) )500 if( !( a = account_get( irc->b, cmd[1] ) ) ) 572 501 { 573 502 irc_usermsg( irc, "Invalid account" ); … … 587 516 return; 588 517 } 589 else if( user_find( irc, cmd[3] ) )518 else if( irc_user_by_name( irc, cmd[3] ) ) 590 519 { 591 520 irc_usermsg( irc, "The requested nick `%s' already exists", cmd[3] ); … … 601 530 a->ic->acc->prpl->add_buddy( a->ic, cmd[2], NULL ); 602 531 else 603 /* Yeah, officially this is a call-*back*... So if we just 604 called add_buddy, we'll wait for the IM server to respond 605 before we do this. */ 606 imcb_add_buddy( a->ic, cmd[2], NULL ); 532 /* Only for add -tmp. For regular adds, this callback will 533 be called once the IM server confirms. */ 534 bee_user_new( irc->b, a->ic, cmd[2] ); 607 535 608 536 irc_usermsg( irc, "Adding `%s' to your contact list", cmd[2] ); 537 } 538 539 static void cmd_remove( irc_t *irc, char **cmd ) 540 { 541 irc_user_t *iu; 542 bee_user_t *bu; 543 char *s; 544 545 if( !( iu = irc_user_by_name( irc, cmd[1] ) ) || !( bu = iu->bu ) ) 546 { 547 irc_usermsg( irc, "Buddy `%s' not found", cmd[1] ); 548 return; 549 } 550 s = g_strdup( bu->handle ); 551 552 bu->ic->acc->prpl->remove_buddy( bu->ic, bu->handle, NULL ); 553 nick_del( bu->ic->acc, bu->handle ); 554 //TODO(wilmer): bee_user_free() and/or let the IM mod do it? irc_user_free( irc, cmd[1] ); 555 556 irc_usermsg( irc, "Buddy `%s' (nick %s) removed from contact list", s, cmd[1] ); 557 g_free( s ); 558 559 return; 609 560 } 610 561 … … 616 567 if( !cmd[2] ) 617 568 { 618 user_t *u = user_find( irc, cmd[1] );619 if( ! u || !u->ic)569 irc_user_t *iu = irc_user_by_name( irc, cmd[1] ); 570 if( !iu || !iu->bu ) 620 571 { 621 572 irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] ); 622 573 return; 623 574 } 624 ic = u->ic;625 cmd[2] = u->handle;626 } 627 else if( !( a = account_get( irc , cmd[1] ) ) )575 ic = iu->bu->ic; 576 cmd[2] = iu->bu->handle; 577 } 578 else if( !( a = account_get( irc->b, cmd[1] ) ) ) 628 579 { 629 580 irc_usermsg( irc, "Invalid account" ); … … 648 599 static void cmd_rename( irc_t *irc, char **cmd ) 649 600 { 650 user_t *u; 651 652 if( g_strcasecmp( cmd[1], irc->nick ) == 0 ) 601 irc_user_t *iu; 602 603 iu = irc_user_by_name( irc, cmd[1] ); 604 605 if( iu == NULL ) 606 { 607 irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] ); 608 } 609 else if( iu == irc->user ) 653 610 { 654 611 irc_usermsg( irc, "Nick `%s' can't be changed", cmd[1] ); 655 612 } 656 else if( g_strcasecmp( cmd[1], irc->channel ) == 0 ) 657 { 658 if( strchr( CTYPES, cmd[2][0] ) && nick_ok( cmd[2] + 1 ) ) 659 { 660 u = user_find( irc, irc->nick ); 661 662 irc_part( irc, u, irc->channel ); 663 g_free( irc->channel ); 664 irc->channel = g_strdup( cmd[2] ); 665 irc_join( irc, u, irc->channel ); 666 667 if( strcmp( cmd[0], "set_rename" ) != 0 ) 668 set_setstr( &irc->set, "control_channel", cmd[2] ); 669 } 670 } 671 else if( user_find( irc, cmd[2] ) && ( nick_cmp( cmd[1], cmd[2] ) != 0 ) ) 613 else if( !nick_ok( cmd[2] ) ) 614 { 615 irc_usermsg( irc, "Nick `%s' is invalid", cmd[2] ); 616 } 617 else if( irc_user_by_name( irc, cmd[2] ) ) 672 618 { 673 619 irc_usermsg( irc, "Nick `%s' already exists", cmd[2] ); 674 620 } 675 else if( !nick_ok( cmd[2] ) ) 676 { 677 irc_usermsg( irc, "Nick `%s' is invalid", cmd[2] ); 678 } 679 else if( !( u = user_find( irc, cmd[1] ) ) ) 680 { 681 irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] ); 682 } 683 else 684 { 685 user_rename( irc, cmd[1], cmd[2] ); 686 irc_write( irc, ":%s!%s@%s NICK %s", cmd[1], u->user, u->host, cmd[2] ); 687 if( g_strcasecmp( cmd[1], irc->mynick ) == 0 ) 688 { 689 g_free( irc->mynick ); 690 irc->mynick = g_strdup( cmd[2] ); 691 621 else 622 { 623 if( !irc_user_set_nick( iu, cmd[2] ) ) 624 { 625 irc_usermsg( irc, "Error while changing nick" ); 626 return; 627 } 628 629 if( iu == irc->root ) 630 { 692 631 /* If we're called internally (user did "set root_nick"), 693 632 let's not go O(INF). :-) */ 694 633 if( strcmp( cmd[0], "set_rename" ) != 0 ) 695 set_setstr( &irc-> set, "root_nick", cmd[2] );696 } 697 else if( u->send_handler == buddy_send_handler)698 { 699 nick_set( u->ic->acc,u->handle, cmd[2] );634 set_setstr( &irc->b->set, "root_nick", cmd[2] ); 635 } 636 else if( iu->bu ) 637 { 638 nick_set( iu->bu->ic->acc, iu->bu->handle, cmd[2] ); 700 639 } 701 640 … … 704 643 } 705 644 645 #if 0 706 646 char *set_eval_root_nick( set_t *set, char *new_nick ) 707 647 { … … 731 671 return strcmp( irc->channel, new_name ) == 0 ? new_name : SET_INVALID; 732 672 } 733 734 static void cmd_remove( irc_t *irc, char **cmd ) 735 { 736 user_t *u; 737 char *s; 738 739 if( !( u = user_find( irc, cmd[1] ) ) || !u->ic ) 740 { 741 irc_usermsg( irc, "Buddy `%s' not found", cmd[1] ); 742 return; 743 } 744 s = g_strdup( u->handle ); 745 746 u->ic->acc->prpl->remove_buddy( u->ic, u->handle, NULL ); 747 nick_del( u->ic->acc, u->handle ); 748 user_del( irc, cmd[1] ); 749 750 irc_usermsg( irc, "Buddy `%s' (nick %s) removed from contact list", s, cmd[1] ); 751 g_free( s ); 752 753 return; 754 } 673 #endif 755 674 756 675 static void cmd_block( irc_t *irc, char **cmd ) … … 759 678 account_t *a; 760 679 761 if( !cmd[2] && ( a = account_get( irc , cmd[1] ) ) && a->ic )680 if( !cmd[2] && ( a = account_get( irc->b, cmd[1] ) ) && a->ic ) 762 681 { 763 682 char *format; … … 772 691 for( l = a->ic->deny; l; l = l->next ) 773 692 { 774 user_t *u = user_findhandle( a->ic, l->data ); 775 irc_usermsg( irc, format, l->data, u ? u->nick : "(none)" ); 693 bee_user_t *bu = bee_user_by_handle( irc->b, a->ic, l->data ); 694 irc_user_t *iu = bu ? bu->ui_data : NULL; 695 irc_usermsg( irc, format, l->data, iu ? iu->nick : "(none)" ); 776 696 } 777 697 irc_usermsg( irc, "End of list." ); … … 781 701 else if( !cmd[2] ) 782 702 { 783 user_t *u = user_find( irc, cmd[1] );784 if( ! u || !u->ic)703 irc_user_t *iu = irc_user_by_name( irc, cmd[1] ); 704 if( !iu || !iu->bu ) 785 705 { 786 706 irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] ); 787 707 return; 788 708 } 789 ic = u->ic;790 cmd[2] = u->handle;791 } 792 else if( !( a = account_get( irc , cmd[1] ) ) )709 ic = iu->bu->ic; 710 cmd[2] = iu->bu->handle; 711 } 712 else if( !( a = account_get( irc->b, cmd[1] ) ) ) 793 713 { 794 714 irc_usermsg( irc, "Invalid account" ); … … 818 738 account_t *a; 819 739 820 if( !cmd[2] && ( a = account_get( irc , cmd[1] ) ) && a->ic )740 if( !cmd[2] && ( a = account_get( irc->b, cmd[1] ) ) && a->ic ) 821 741 { 822 742 char *format; … … 831 751 for( l = a->ic->permit; l; l = l->next ) 832 752 { 833 user_t *u = user_findhandle( a->ic, l->data ); 834 irc_usermsg( irc, format, l->data, u ? u->nick : "(none)" ); 753 bee_user_t *bu = bee_user_by_handle( irc->b, a->ic, l->data ); 754 irc_user_t *iu = bu ? bu->ui_data : NULL; 755 irc_usermsg( irc, format, l->data, iu ? iu->nick : "(none)" ); 835 756 } 836 757 irc_usermsg( irc, "End of list." ); … … 840 761 else if( !cmd[2] ) 841 762 { 842 user_t *u = user_find( irc, cmd[1] );843 if( ! u || !u->ic)763 irc_user_t *iu = irc_user_by_name( irc, cmd[1] ); 764 if( !iu || !iu->bu ) 844 765 { 845 766 irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] ); 846 767 return; 847 768 } 848 ic = u->ic;849 cmd[2] = u->handle;850 } 851 else if( !( a = account_get( irc , cmd[1] ) ) )769 ic = iu->bu->ic; 770 cmd[2] = iu->bu->handle; 771 } 772 else if( !( a = account_get( irc->b, cmd[1] ) ) ) 852 773 { 853 774 irc_usermsg( irc, "Invalid account" ); … … 916 837 } 917 838 918 static void cmd_save( irc_t *irc, char **cmd )919 {920 if( ( irc->status & USTATUS_IDENTIFIED ) == 0 )921 irc_usermsg( irc, "Please create an account first" );922 else if( storage_save( irc, NULL, TRUE ) == STORAGE_OK )923 irc_usermsg( irc, "Configuration saved" );924 else925 irc_usermsg( irc, "Configuration could not be saved!" );926 }927 928 839 static void cmd_blist( irc_t *irc, char **cmd ) 929 840 { 930 841 int online = 0, away = 0, offline = 0; 931 user_t *u;842 GSList *l; 932 843 char s[256]; 933 844 char *format; … … 950 861 format = "%-16.16s %-40.40s %s"; 951 862 952 irc_usermsg( irc, format, "Nick", "User/Host/Network", "Status" ); 953 954 for( u = irc->users; u; u = u->next ) if( u->ic && u->online && !u->away ) 955 { 863 irc_usermsg( irc, format, "Nick", "Handle/Account", "Status" ); 864 865 for( l = irc->users; l; l = l->next ) 866 { 867 irc_user_t *iu = l->data; 868 bee_user_t *bu = iu->bu; 869 870 if( !bu || ( bu->flags & ( BEE_USER_ONLINE | BEE_USER_AWAY ) ) != BEE_USER_ONLINE ) 871 continue; 872 956 873 if( online == 1 ) 957 874 { 958 875 char st[256] = "Online"; 959 876 960 if( u->status_msg )961 g_snprintf( st, sizeof( st ) - 1, "Online (%s)", u->status_msg );877 if( bu->status_msg ) 878 g_snprintf( st, sizeof( st ) - 1, "Online (%s)", bu->status_msg ); 962 879 963 g_snprintf( s, sizeof( s ) - 1, "%s @%s %s(%s)", u->user, u->host, u->ic->acc->prpl->name,u->ic->acc->user );964 irc_usermsg( irc, format, u->nick, s, st );880 g_snprintf( s, sizeof( s ) - 1, "%s %s(%s)", bu->handle, bu->ic->acc->prpl->name, bu->ic->acc->user ); 881 irc_usermsg( irc, format, iu->nick, s, st ); 965 882 } 966 883 … … 968 885 } 969 886 970 for( u = irc->users; u; u = u->next ) if( u->ic && u->online && u->away ) 971 { 887 for( l = irc->users; l; l = l->next ) 888 { 889 irc_user_t *iu = l->data; 890 bee_user_t *bu = iu->bu; 891 892 if( !bu || !( bu->flags & BEE_USER_ONLINE ) || !( bu->flags & BEE_USER_AWAY ) ) 893 continue; 894 972 895 if( away == 1 ) 973 896 { 974 g_snprintf( s, sizeof( s ) - 1, "%s @%s %s(%s)", u->user, u->host, u->ic->acc->prpl->name,u->ic->acc->user );975 irc_usermsg( irc, format, u->nick, s, u->away);897 g_snprintf( s, sizeof( s ) - 1, "%s %s(%s)", bu->handle, bu->ic->acc->prpl->name, bu->ic->acc->user ); 898 irc_usermsg( irc, format, iu->nick, s, irc_user_get_away( iu ) ); 976 899 } 977 900 n_away ++; 978 901 } 979 902 980 for( u = irc->users; u; u = u->next ) if( u->ic && !u->online ) 981 { 903 for( l = irc->users; l; l = l->next ) 904 { 905 irc_user_t *iu = l->data; 906 bee_user_t *bu = iu->bu; 907 908 if( !bu || bu->flags & BEE_USER_ONLINE ) 909 continue; 910 982 911 if( offline == 1 ) 983 912 { 984 g_snprintf( s, sizeof( s ) - 1, "%s @%s %s(%s)", u->user, u->host, u->ic->acc->prpl->name,u->ic->acc->user );985 irc_usermsg( irc, format, u->nick, s, "Offline" );913 g_snprintf( s, sizeof( s ) - 1, "%s %s(%s)", bu->handle, bu->ic->acc->prpl->name, bu->ic->acc->user ); 914 irc_usermsg( irc, format, iu->nick, s, "Offline" ); 986 915 } 987 916 n_offline ++; … … 989 918 990 919 irc_usermsg( irc, "%d buddies (%d available, %d away, %d offline)", n_online + n_away + n_offline, n_online, n_away, n_offline ); 991 }992 993 static void cmd_nick( irc_t *irc, char **cmd )994 {995 account_t *a;996 997 if( !cmd[1] || !( a = account_get( irc, cmd[1] ) ) )998 {999 irc_usermsg( irc, "Invalid account");1000 }1001 else if( !( a->ic && ( a->ic->flags & OPT_LOGGED_IN ) ) )1002 {1003 irc_usermsg( irc, "That account is not on-line" );1004 }1005 else if ( !cmd[2] )1006 {1007 irc_usermsg( irc, "Your name is `%s'" , a->ic->displayname ? a->ic->displayname : "NULL" );1008 }1009 else if ( !a->prpl->set_my_name )1010 {1011 irc_usermsg( irc, "Command `%s' not supported by this protocol", cmd[0] );1012 }1013 else1014 {1015 irc_usermsg( irc, "Setting your name to `%s'", cmd[2] );1016 1017 a->prpl->set_my_name( a->ic, cmd[2] );1018 }1019 920 } 1020 921 … … 1039 940 } 1040 941 1041 static void cmd_join_chat( irc_t *irc, char **cmd ) 1042 { 1043 irc_usermsg( irc, "This command is now obsolete. " 1044 "Please try the `chat' command instead." ); 1045 } 1046 942 #if 0 1047 943 static set_t **cmd_chat_set_findhead( irc_t *irc, char *id ) 1048 944 { … … 1156 1052 } 1157 1053 } 1158 1054 #endif 1055 1056 static void cmd_transfer( irc_t *irc, char **cmd ) 1057 { 1058 GSList *files = irc->file_transfers; 1059 enum { LIST, REJECT, CANCEL }; 1060 int subcmd = LIST; 1061 int fid; 1062 1063 if( !files ) 1064 { 1065 irc_usermsg( irc, "No pending transfers" ); 1066 return; 1067 } 1068 1069 if( cmd[1] && ( strcmp( cmd[1], "reject" ) == 0 ) ) 1070 { 1071 subcmd = REJECT; 1072 } 1073 else if( cmd[1] && ( strcmp( cmd[1], "cancel" ) == 0 ) && 1074 cmd[2] && ( sscanf( cmd[2], "%d", &fid ) == 1 ) ) 1075 { 1076 subcmd = CANCEL; 1077 } 1078 1079 for( ; files; files = g_slist_next( files ) ) 1080 { 1081 file_transfer_t *file = files->data; 1082 1083 switch( subcmd ) { 1084 case LIST: 1085 if ( file->status == FT_STATUS_LISTENING ) 1086 irc_usermsg( irc, 1087 "Pending file(id %d): %s (Listening...)", file->local_id, file->file_name); 1088 else 1089 { 1090 int kb_per_s = 0; 1091 time_t diff = time( NULL ) - file->started ? : 1; 1092 if ( ( file->started > 0 ) && ( file->bytes_transferred > 0 ) ) 1093 kb_per_s = file->bytes_transferred / 1024 / diff; 1094 1095 irc_usermsg( irc, 1096 "Pending file(id %d): %s (%10zd/%zd kb, %d kb/s)", file->local_id, file->file_name, 1097 file->bytes_transferred/1024, file->file_size/1024, kb_per_s); 1098 } 1099 break; 1100 case REJECT: 1101 if( file->status == FT_STATUS_LISTENING ) 1102 { 1103 irc_usermsg( irc, "Rejecting file transfer for %s", file->file_name ); 1104 imcb_file_canceled( file->ic, file, "Denied by user" ); 1105 } 1106 break; 1107 case CANCEL: 1108 if( file->local_id == fid ) 1109 { 1110 irc_usermsg( irc, "Canceling file transfer for %s", file->file_name ); 1111 imcb_file_canceled( file->ic, file, "Canceled by user" ); 1112 } 1113 break; 1114 } 1115 } 1116 } 1117 1118 /* IMPORTANT: Keep this list sorted! The short command logic needs that. */ 1159 1119 const command_t commands[] = { 1120 { "account", 1, cmd_account, 0 }, 1121 { "add", 2, cmd_add, 0 }, 1122 { "allow", 1, cmd_allow, 0 }, 1123 { "blist", 0, cmd_blist, 0 }, 1124 { "block", 1, cmd_block, 0 }, 1125 { "drop", 1, cmd_drop, 0 }, 1126 { "ft", 0, cmd_transfer, 0 }, 1160 1127 { "help", 0, cmd_help, 0 }, 1161 1128 { "identify", 1, cmd_identify, 0 }, 1129 { "info", 1, cmd_info, 0 }, 1130 { "no", 0, cmd_yesno, 0 }, 1131 { "qlist", 0, cmd_qlist, 0 }, 1162 1132 { "register", 1, cmd_register, 0 }, 1163 { "drop", 1, cmd_drop, 0 }, 1164 { "account", 1, cmd_account, 0 }, 1165 { "add", 2, cmd_add, 0 }, 1166 { "info", 1, cmd_info, 0 }, 1133 { "remove", 1, cmd_remove, 0 }, 1167 1134 { "rename", 2, cmd_rename, 0 }, 1168 { "remove", 1, cmd_remove, 0 },1169 { "block", 1, cmd_block, 0 },1170 { "allow", 1, cmd_allow, 0 },1171 1135 { "save", 0, cmd_save, 0 }, 1172 1136 { "set", 0, cmd_set, 0 }, 1137 { "transfer", 0, cmd_transfer, 0 }, 1173 1138 { "yes", 0, cmd_yesno, 0 }, 1174 { "no", 0, cmd_yesno, 0 }, 1175 { "blist", 0, cmd_blist, 0 }, 1176 { "nick", 1, cmd_nick, 0 }, 1177 { "qlist", 0, cmd_qlist, 0 }, 1178 { "join_chat", 2, cmd_join_chat, 0 }, 1139 #if 0 1179 1140 { "chat", 1, cmd_chat, 0 }, 1141 #endif 1180 1142 { NULL } 1181 1143 };
Note: See TracChangeset
for help on using the changeset viewer.