Changes in root_commands.c [0baed0d:24b8bbb]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
root_commands.c
r0baed0d r24b8bbb 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 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!" ); 196 } 197 224 198 struct cmd_account_del_data 225 199 { … … 233 207 account_t *a; 234 208 235 for( a = cad->irc-> accounts; a && a != cad->a; a = a->next );209 for( a = cad->irc->b->accounts; a && a != cad->a; a = a->next ); 236 210 237 211 if( a == NULL ) … … 245 219 else 246 220 { 247 account_del( cad->irc , a );221 account_del( cad->irc->b, a ); 248 222 irc_usermsg( cad->irc, "Account deleted" ); 249 223 } … … 286 260 set_name = set_full; 287 261 288 head = &irc-> set;262 head = &irc->b->set; 289 263 } 290 264 else … … 357 331 account_t *a; 358 332 359 if( ( a = account_get( irc , id ) ) )333 if( ( a = account_get( irc->b, id ) ) ) 360 334 return &a->set; 361 335 else … … 405 379 } 406 380 407 a = account_add( irc , prpl, cmd[3], cmd[4] );381 a = account_add( irc->b, prpl, cmd[3], cmd[4] ); 408 382 if( cmd[5] ) 409 383 { … … 419 393 MIN_ARGS( 2 ); 420 394 421 if( !( a = account_get( irc , cmd[2] ) ) )395 if( !( a = account_get( irc->b, cmd[2] ) ) ) 422 396 { 423 397 irc_usermsg( irc, "Invalid account" ); … … 441 415 "set' command. Are you sure you want to delete this " 442 416 "account?", a->prpl->name, a->user ); 443 query_add( irc, NULL, msg, cmd_account_del_yes, cmd_account_del_no, cad );417 //query_add( irc, NULL, msg, cmd_account_del_yes, cmd_account_del_no, cad ); 444 418 g_free( msg ); 445 419 } … … 452 426 irc_usermsg( irc, "Account list:" ); 453 427 454 for( a = irc-> accounts; a; a = a->next )428 for( a = irc->b->accounts; a; a = a->next ) 455 429 { 456 430 char *con; … … 475 449 if( cmd[2] ) 476 450 { 477 if( ( a = account_get( irc , cmd[2] ) ) )451 if( ( a = account_get( irc->b, cmd[2] ) ) ) 478 452 { 479 453 if( a->ic ) … … 484 458 else 485 459 { 486 account_on( irc , a );460 account_on( irc->b, a ); 487 461 } 488 462 } … … 495 469 else 496 470 { 497 if ( irc->accounts ) { 471 if ( irc->b->accounts ) 472 { 498 473 irc_usermsg( irc, "Trying to get all accounts connected..." ); 499 474 500 for( a = irc-> accounts; a; a = a->next )475 for( a = irc->b->accounts; a; a = a->next ) 501 476 if( !a->ic && a->auto_connect ) 502 account_on( irc , a );477 account_on( irc->b, a ); 503 478 } 504 479 else … … 514 489 irc_usermsg( irc, "Deactivating all active (re)connections..." ); 515 490 516 for( a = irc-> accounts; a; a = a->next )491 for( a = irc->b->accounts; a; a = a->next ) 517 492 { 518 493 if( a->ic ) 519 account_off( irc , a );494 account_off( irc->b, a ); 520 495 else if( a->reconnect ) 521 496 cancel_auto_reconnect( a ); 522 497 } 523 498 } 524 else if( ( a = account_get( irc , cmd[2] ) ) )499 else if( ( a = account_get( irc->b, cmd[2] ) ) ) 525 500 { 526 501 if( a->ic ) 527 502 { 528 account_off( irc , a );503 account_off( irc->b, a ); 529 504 } 530 505 else if( a->reconnect ) … … 569 544 } 570 545 571 if( !( a = account_get( irc , cmd[1] ) ) )546 if( !( a = account_get( irc->b, cmd[1] ) ) ) 572 547 { 573 548 irc_usermsg( irc, "Invalid account" ); … … 587 562 return; 588 563 } 589 else if( user_find( irc, cmd[3] ) )564 else if( irc_user_by_name( irc, cmd[3] ) ) 590 565 { 591 566 irc_usermsg( irc, "The requested nick `%s' already exists", cmd[3] ); … … 601 576 a->ic->acc->prpl->add_buddy( a->ic, cmd[2], NULL ); 602 577 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 ); 578 /* Only for add -tmp. For regular adds, this callback will 579 be called once the IM server confirms. */ 580 bee_user_new( irc->b, a->ic, cmd[2] ); 607 581 608 582 irc_usermsg( irc, "Adding `%s' to your contact list", cmd[2] ); 583 } 584 585 static void cmd_remove( irc_t *irc, char **cmd ) 586 { 587 irc_user_t *iu; 588 bee_user_t *bu; 589 char *s; 590 591 if( !( iu = irc_user_by_name( irc, cmd[1] ) ) || !( bu = iu->bu ) ) 592 { 593 irc_usermsg( irc, "Buddy `%s' not found", cmd[1] ); 594 return; 595 } 596 s = g_strdup( bu->handle ); 597 598 bu->ic->acc->prpl->remove_buddy( bu->ic, bu->handle, NULL ); 599 nick_del( bu->ic->acc, bu->handle ); 600 //TODO(wilmer): bee_user_free() and/or let the IM mod do it? irc_user_free( irc, cmd[1] ); 601 602 irc_usermsg( irc, "Buddy `%s' (nick %s) removed from contact list", s, cmd[1] ); 603 g_free( s ); 604 605 return; 609 606 } 610 607 … … 616 613 if( !cmd[2] ) 617 614 { 618 user_t *u = user_find( irc, cmd[1] );619 if( ! u || !u->ic)615 irc_user_t *iu = irc_user_by_name( irc, cmd[1] ); 616 if( !iu || !iu->bu ) 620 617 { 621 618 irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] ); 622 619 return; 623 620 } 624 ic = u->ic;625 cmd[2] = u->handle;626 } 627 else if( !( a = account_get( irc , cmd[1] ) ) )621 ic = iu->bu->ic; 622 cmd[2] = iu->bu->handle; 623 } 624 else if( !( a = account_get( irc->b, cmd[1] ) ) ) 628 625 { 629 626 irc_usermsg( irc, "Invalid account" ); … … 648 645 static void cmd_rename( irc_t *irc, char **cmd ) 649 646 { 650 user_t *u; 651 652 if( g_strcasecmp( cmd[1], irc->nick ) == 0 ) 647 irc_user_t *iu; 648 649 iu = irc_user_by_name( irc, cmd[1] ); 650 651 if( iu == NULL ) 652 { 653 irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] ); 654 } 655 else if( iu == irc->user ) 653 656 { 654 657 irc_usermsg( irc, "Nick `%s' can't be changed", cmd[1] ); 655 658 } 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 ) ) 659 else if( !nick_ok( cmd[2] ) ) 660 { 661 irc_usermsg( irc, "Nick `%s' is invalid", cmd[2] ); 662 } 663 else if( irc_user_by_name( irc, cmd[2] ) ) 672 664 { 673 665 irc_usermsg( irc, "Nick `%s' already exists", cmd[2] ); 674 666 } 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 667 else 668 { 669 if( !irc_user_set_nick( iu, cmd[2] ) ) 670 { 671 irc_usermsg( irc, "Error while changing nick" ); 672 return; 673 } 674 675 if( iu == irc->root ) 676 { 692 677 /* If we're called internally (user did "set root_nick"), 693 678 let's not go O(INF). :-) */ 694 679 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] );680 set_setstr( &irc->b->set, "root_nick", cmd[2] ); 681 } 682 else if( iu->bu ) 683 { 684 nick_set( iu->bu->ic->acc, iu->bu->handle, cmd[2] ); 700 685 } 701 686 … … 704 689 } 705 690 691 #if 0 706 692 char *set_eval_root_nick( set_t *set, char *new_nick ) 707 693 { … … 730 716 731 717 return strcmp( irc->channel, new_name ) == 0 ? new_name : SET_INVALID; 732 }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 718 } 755 719 … … 872 836 } 873 837 } 838 #endif 874 839 875 840 static void cmd_yesno( irc_t *irc, char **cmd ) … … 916 881 } 917 882 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 else 925 irc_usermsg( irc, "Configuration could not be saved!" ); 926 } 927 883 #if 0 928 884 static void cmd_blist( irc_t *irc, char **cmd ) 929 885 { … … 991 947 } 992 948 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 }1020 1021 949 static void cmd_qlist( irc_t *irc, char **cmd ) 1022 950 { … … 1037 965 else 1038 966 irc_usermsg( irc, "%d, BitlBee: %s", num, q->question ); 1039 }1040 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 967 } 1046 968 … … 1157 1079 } 1158 1080 1081 static void cmd_transfer( irc_t *irc, char **cmd ) 1082 { 1083 GSList *files = irc->file_transfers; 1084 enum { LIST, REJECT, CANCEL }; 1085 int subcmd = LIST; 1086 int fid; 1087 1088 if( !files ) 1089 { 1090 irc_usermsg( irc, "No pending transfers" ); 1091 return; 1092 } 1093 1094 if( cmd[1] && ( strcmp( cmd[1], "reject" ) == 0 ) ) 1095 { 1096 subcmd = REJECT; 1097 } 1098 else if( cmd[1] && ( strcmp( cmd[1], "cancel" ) == 0 ) && 1099 cmd[2] && ( sscanf( cmd[2], "%d", &fid ) == 1 ) ) 1100 { 1101 subcmd = CANCEL; 1102 } 1103 1104 for( ; files; files = g_slist_next( files ) ) 1105 { 1106 file_transfer_t *file = files->data; 1107 1108 switch( subcmd ) { 1109 case LIST: 1110 if ( file->status == FT_STATUS_LISTENING ) 1111 irc_usermsg( irc, 1112 "Pending file(id %d): %s (Listening...)", file->local_id, file->file_name); 1113 else 1114 { 1115 int kb_per_s = 0; 1116 time_t diff = time( NULL ) - file->started ? : 1; 1117 if ( ( file->started > 0 ) && ( file->bytes_transferred > 0 ) ) 1118 kb_per_s = file->bytes_transferred / 1024 / diff; 1119 1120 irc_usermsg( irc, 1121 "Pending file(id %d): %s (%10zd/%zd kb, %d kb/s)", file->local_id, file->file_name, 1122 file->bytes_transferred/1024, file->file_size/1024, kb_per_s); 1123 } 1124 break; 1125 case REJECT: 1126 if( file->status == FT_STATUS_LISTENING ) 1127 { 1128 irc_usermsg( irc, "Rejecting file transfer for %s", file->file_name ); 1129 imcb_file_canceled( file, "Denied by user" ); 1130 } 1131 break; 1132 case CANCEL: 1133 if( file->local_id == fid ) 1134 { 1135 irc_usermsg( irc, "Canceling file transfer for %s", file->file_name ); 1136 imcb_file_canceled( file, "Canceled by user" ); 1137 } 1138 break; 1139 } 1140 } 1141 } 1142 #endif 1143 1144 /* IMPORTANT: Keep this list sorted! The short command logic needs that. */ 1159 1145 const command_t commands[] = { 1146 { "account", 1, cmd_account, 0 }, 1147 { "add", 2, cmd_add, 0 }, 1148 { "drop", 1, cmd_drop, 0 }, 1160 1149 { "help", 0, cmd_help, 0 }, 1161 1150 { "identify", 1, cmd_identify, 0 }, 1151 { "info", 1, cmd_info, 0 }, 1152 { "no", 0, cmd_yesno, 0 }, 1162 1153 { "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 }, 1154 { "remove", 1, cmd_remove, 0 }, 1167 1155 { "rename", 2, cmd_rename, 0 }, 1168 { "remove", 1, cmd_remove, 0 },1169 { "block", 1, cmd_block, 0 },1170 { "allow", 1, cmd_allow, 0 },1171 1156 { "save", 0, cmd_save, 0 }, 1172 1157 { "set", 0, cmd_set, 0 }, 1173 1158 { "yes", 0, cmd_yesno, 0 }, 1174 { "no", 0, cmd_yesno, 0 }, 1159 #if 0 1160 { "allow", 1, cmd_allow, 0 }, 1175 1161 { "blist", 0, cmd_blist, 0 }, 1176 { "nick", 1, cmd_nick, 0 }, 1162 { "block", 1, cmd_block, 0 }, 1163 { "chat", 1, cmd_chat, 0 }, 1164 { "ft", 0, cmd_transfer, 0 }, 1165 { "join_chat", 2, cmd_join_chat, 0 }, 1177 1166 { "qlist", 0, cmd_qlist, 0 }, 1178 { " join_chat", 2, cmd_join_chat,0 },1179 { "chat", 1, cmd_chat, 0 }, 1167 { "transfer", 0, cmd_transfer, 0 }, 1168 #endif 1180 1169 { NULL } 1181 1170 };
Note: See TracChangeset
for help on using the changeset viewer.