Changes in root_commands.c [823de9d:2ea8736]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
root_commands.c
r823de9d r2ea8736 29 29 #include "bitlbee.h" 30 30 #include "help.h" 31 #include "otr.h"32 31 33 32 #include <string.h> … … 79 78 } 80 79 80 #define MIN_ARGS( x, y... ) \ 81 do \ 82 { \ 83 int blaat; \ 84 for( blaat = 0; blaat <= x; blaat ++ ) \ 85 if( cmd[blaat] == NULL ) \ 86 { \ 87 irc_usermsg( irc, "Not enough parameters given (need %d).", x ); \ 88 return y; \ 89 } \ 90 } while( 0 ) 91 81 92 void root_command( irc_t *irc, char *cmd[] ) 82 93 { … … 89 100 if( g_strcasecmp( commands[i].command, cmd[0] ) == 0 ) 90 101 { 91 if( !cmd[commands[i].required_parameters] ) 92 { 93 irc_usermsg( irc, "Not enough parameters given (need %d)", commands[i].required_parameters ); 94 return; 95 } 102 MIN_ARGS( commands[i].required_parameters ); 103 96 104 commands[i].execute( irc, cmd ); 97 105 return; … … 251 259 } 252 260 261 typedef set_t** (*cmd_set_findhead)( irc_t*, char* ); 262 typedef int (*cmd_set_checkflags)( irc_t*, set_t *set ); 263 264 static int cmd_set_real( irc_t *irc, char **cmd, cmd_set_findhead findhead, cmd_set_checkflags checkflags ) 265 { 266 char *set_full = NULL, *set_name = NULL, *tmp; 267 set_t **head; 268 269 if( cmd[1] && g_strncasecmp( cmd[1], "-del", 4 ) == 0 ) 270 { 271 MIN_ARGS( 2, 0 ); 272 set_full = cmd[2]; 273 } 274 else 275 set_full = cmd[1]; 276 277 if( findhead == NULL ) 278 { 279 set_name = set_full; 280 281 head = &irc->set; 282 } 283 else 284 { 285 char *id; 286 287 if( ( tmp = strchr( set_full, '/' ) ) ) 288 { 289 id = g_strndup( set_full, ( tmp - set_full ) ); 290 set_name = tmp + 1; 291 } 292 else 293 { 294 id = g_strdup( set_full ); 295 } 296 297 if( ( head = findhead( irc, id ) ) == NULL ) 298 { 299 g_free( id ); 300 irc_usermsg( irc, "Could not find setting." ); 301 return 0; 302 } 303 g_free( id ); 304 } 305 306 if( cmd[1] && cmd[2] && set_name ) 307 { 308 set_t *s = set_find( head, set_name ); 309 int st; 310 311 if( s && checkflags && checkflags( irc, s ) == 0 ) 312 return 0; 313 314 if( g_strncasecmp( cmd[1], "-del", 4 ) == 0 ) 315 st = set_reset( head, set_name ); 316 else 317 st = set_setstr( head, set_name, cmd[2] ); 318 319 if( set_getstr( head, set_name ) == NULL ) 320 { 321 if( st ) 322 irc_usermsg( irc, "Setting changed successfully" ); 323 else 324 irc_usermsg( irc, "Failed to change setting" ); 325 } 326 else 327 { 328 cmd_showset( irc, head, set_name ); 329 } 330 } 331 else if( set_name ) 332 { 333 cmd_showset( irc, head, set_name ); 334 } 335 else 336 { 337 set_t *s = *head; 338 while( s ) 339 { 340 cmd_showset( irc, &s, s->key ); 341 s = s->next; 342 } 343 } 344 345 return 1; 346 } 347 348 static set_t **cmd_account_set_findhead( irc_t *irc, char *id ) 349 { 350 account_t *a; 351 352 if( ( a = account_get( irc, id ) ) ) 353 return &a->set; 354 else 355 return NULL; 356 } 357 358 static int cmd_account_set_checkflags( irc_t *irc, set_t *s ) 359 { 360 account_t *a = s->data; 361 362 if( a->ic && s && s->flags & ACC_SET_OFFLINE_ONLY ) 363 { 364 irc_usermsg( irc, "This setting can only be changed when the account is %s-line", "off" ); 365 return 0; 366 } 367 else if( !a->ic && s && s->flags & ACC_SET_ONLINE_ONLY ) 368 { 369 irc_usermsg( irc, "This setting can only be changed when the account is %s-line", "on" ); 370 return 0; 371 } 372 373 return 1; 374 } 375 253 376 static void cmd_account( irc_t *irc, char **cmd ) 254 377 { … … 265 388 struct prpl *prpl; 266 389 267 if( cmd[2] == NULL || cmd[3] == NULL || cmd[4] == NULL ) 268 { 269 irc_usermsg( irc, "Not enough parameters" ); 270 return; 271 } 272 273 prpl = find_protocol(cmd[2]); 390 MIN_ARGS( 4 ); 391 392 prpl = find_protocol( cmd[2] ); 274 393 275 394 if( prpl == NULL ) … … 288 407 289 408 irc_usermsg( irc, "Account successfully added" ); 290 291 if(otr_check_for_key(a)) {292 irc_usermsg(irc, "otr: you will be notified when it completes");293 }294 409 } 295 410 else if( g_strcasecmp( cmd[1], "del" ) == 0 ) 296 411 { 297 if( !cmd[2] ) 298 { 299 irc_usermsg( irc, "Not enough parameters given (need %d)", 2 ); 300 } 301 else if( !( a = account_get( irc, cmd[2] ) ) ) 412 MIN_ARGS( 2 ); 413 414 if( !( a = account_get( irc, cmd[2] ) ) ) 302 415 { 303 416 irc_usermsg( irc, "Invalid account" ); … … 427 540 else if( g_strcasecmp( cmd[1], "set" ) == 0 ) 428 541 { 429 char *acc_handle, *set_name = NULL, *tmp; 430 431 if( !cmd[2] ) 432 { 433 irc_usermsg( irc, "Not enough parameters given (need %d)", 2 ); 434 return; 435 } 436 437 if( g_strncasecmp( cmd[2], "-del", 4 ) == 0 ) 438 acc_handle = g_strdup( cmd[3] ); 439 else 440 acc_handle = g_strdup( cmd[2] ); 441 442 if( !acc_handle ) 443 { 444 irc_usermsg( irc, "Not enough parameters given (need %d)", 3 ); 445 return; 446 } 447 448 if( ( tmp = strchr( acc_handle, '/' ) ) ) 449 { 450 *tmp = 0; 451 set_name = tmp + 1; 452 } 453 454 if( ( a = account_get( irc, acc_handle ) ) == NULL ) 455 { 456 g_free( acc_handle ); 457 irc_usermsg( irc, "Invalid account" ); 458 return; 459 } 460 461 if( cmd[3] && set_name ) 462 { 463 set_t *s = set_find( &a->set, set_name ); 464 int st; 465 466 if( a->ic && s && s->flags & ACC_SET_OFFLINE_ONLY ) 467 { 468 g_free( acc_handle ); 469 irc_usermsg( irc, "This setting can only be changed when the account is %s-line", "off" ); 470 return; 471 } 472 else if( !a->ic && s && s->flags & ACC_SET_ONLINE_ONLY ) 473 { 474 g_free( acc_handle ); 475 irc_usermsg( irc, "This setting can only be changed when the account is %s-line", "on" ); 476 return; 477 } 478 479 if( g_strncasecmp( cmd[2], "-del", 4 ) == 0 ) 480 st = set_reset( &a->set, set_name ); 481 else 482 st = set_setstr( &a->set, set_name, cmd[3] ); 483 484 if( set_getstr( &a->set, set_name ) == NULL ) 485 { 486 if( st ) 487 irc_usermsg( irc, "Setting changed successfully" ); 488 else 489 irc_usermsg( irc, "Failed to change setting" ); 490 } 491 else 492 { 493 cmd_showset( irc, &a->set, set_name ); 494 } 495 } 496 else if( set_name ) 497 { 498 cmd_showset( irc, &a->set, set_name ); 499 } 500 else 501 { 502 set_t *s = a->set; 503 while( s ) 504 { 505 cmd_showset( irc, &s, s->key ); 506 s = s->next; 507 } 508 } 509 510 g_free( acc_handle ); 511 } 512 else 513 { 514 irc_usermsg( irc, "Unknown command: account %s. Please use \x02help commands\x02 to get a list of available commands.", cmd[1] ); 542 MIN_ARGS( 2 ); 543 544 cmd_set_real( irc, cmd + 1, cmd_account_set_findhead, cmd_account_set_checkflags ); 545 } 546 else 547 { 548 irc_usermsg( irc, "Unknown command: %s %s. Please use \x02help commands\x02 to get a list of available commands.", "account", cmd[1] ); 515 549 } 516 550 } … … 523 557 if( g_strcasecmp( cmd[1], "-tmp" ) == 0 ) 524 558 { 559 MIN_ARGS( 3 ); 525 560 add_on_server = 0; 526 561 cmd ++; … … 842 877 static void cmd_set( irc_t *irc, char **cmd ) 843 878 { 844 char *set_name = cmd[1]; 845 846 if( cmd[1] && cmd[2] ) 847 { 848 int st; 849 850 if( g_strncasecmp( cmd[1], "-del", 4 ) == 0 ) 851 { 852 st = set_reset( &irc->set, cmd[2] ); 853 set_name = cmd[2]; 854 } 855 else 856 { 857 st = set_setstr( &irc->set, cmd[1], cmd[2] ); 858 } 859 860 /* Normally we just show the variable's new/unchanged 861 value as feedback to the user, but this has always 862 caused confusion when changing the password. Give 863 other feedback instead: */ 864 if( set_getstr( &irc->set, set_name ) == NULL ) 865 { 866 if( st ) 867 irc_usermsg( irc, "Setting changed successfully" ); 868 else 869 irc_usermsg( irc, "Failed to change setting" ); 870 } 871 else 872 { 873 cmd_showset( irc, &irc->set, set_name ); 874 } 875 } 876 else if( set_name ) 877 { 878 cmd_showset( irc, &irc->set, set_name ); 879 880 if( strchr( set_name, '/' ) ) 881 irc_usermsg( irc, "Warning: / found in setting name, you're probably looking for the `account set' command." ); 882 } 883 else 884 { 885 set_t *s = irc->set; 886 while( s ) 887 { 888 cmd_showset( irc, &s, s->key ); 889 s = s->next; 890 } 891 } 879 cmd_set_real( irc, cmd, NULL, NULL ); 892 880 } 893 881 … … 1012 1000 static void cmd_join_chat( irc_t *irc, char **cmd ) 1013 1001 { 1002 irc_usermsg( irc, "This command is now obsolete. " 1003 "Please try the `chat' command instead." ); 1004 } 1005 1006 static set_t **cmd_chat_set_findhead( irc_t *irc, char *id ) 1007 { 1008 struct chat *c; 1009 1010 if( ( c = chat_get( irc, id ) ) ) 1011 return &c->set; 1012 else 1013 return NULL; 1014 } 1015 1016 static void cmd_chat( irc_t *irc, char **cmd ) 1017 { 1018 account_t *acc; 1019 struct chat *c; 1020 1021 if( g_strcasecmp( cmd[1], "add" ) == 0 ) 1022 { 1023 char *channel, *s; 1024 1025 MIN_ARGS( 3 ); 1026 1027 if( !( acc = account_get( irc, cmd[2] ) ) ) 1028 { 1029 irc_usermsg( irc, "Invalid account" ); 1030 return; 1031 } 1032 1033 if( cmd[4] == NULL ) 1034 { 1035 channel = g_strdup( cmd[3] ); 1036 if( ( s = strchr( channel, '@' ) ) ) 1037 *s = 0; 1038 } 1039 else 1040 { 1041 channel = g_strdup( cmd[4] ); 1042 } 1043 1044 if( strchr( CTYPES, channel[0] ) == NULL ) 1045 { 1046 s = g_strdup_printf( "%c%s", CTYPES[0], channel ); 1047 g_free( channel ); 1048 channel = s; 1049 } 1050 1051 if( ( c = chat_add( irc, acc, cmd[3], channel ) ) ) 1052 irc_usermsg( irc, "Chatroom added successfully." ); 1053 else 1054 irc_usermsg( irc, "Could not add chatroom." ); 1055 1056 g_free( channel ); 1057 } 1058 else if( g_strcasecmp( cmd[1], "list" ) == 0 ) 1059 { 1060 int i = 0; 1061 1062 if( strchr( irc->umode, 'b' ) ) 1063 irc_usermsg( irc, "Chatroom list:" ); 1064 1065 for( c = irc->chatrooms; c; c = c->next ) 1066 { 1067 irc_usermsg( irc, "%2d. %s(%s) %s, %s", i, c->acc->prpl->name, 1068 c->acc->user, c->handle, c->channel ); 1069 1070 i ++; 1071 } 1072 irc_usermsg( irc, "End of chatroom list" ); 1073 } 1074 else if( g_strcasecmp( cmd[1], "set" ) == 0 ) 1075 { 1076 MIN_ARGS( 2 ); 1077 1078 cmd_set_real( irc, cmd + 1, cmd_chat_set_findhead, NULL ); 1079 } 1080 else if( g_strcasecmp( cmd[1], "del" ) == 0 ) 1081 { 1082 MIN_ARGS( 2 ); 1083 1084 if( ( c = chat_get( irc, cmd[2] ) ) ) 1085 { 1086 chat_del( irc, c ); 1087 } 1088 else 1089 { 1090 irc_usermsg( irc, "Could not remove chat." ); 1091 } 1092 } 1093 else if( g_strcasecmp( cmd[1], "with" ) == 0 ) 1094 { 1095 user_t *u; 1096 1097 MIN_ARGS( 2 ); 1098 1099 if( ( u = user_find( irc, cmd[2] ) ) && u->ic && u->ic->acc->prpl->chat_with ) 1100 { 1101 if( !u->ic->acc->prpl->chat_with( u->ic, u->handle ) ) 1102 { 1103 irc_usermsg( irc, "(Possible) failure while trying to open " 1104 "a groupchat with %s.", u->nick ); 1105 } 1106 } 1107 else 1108 { 1109 irc_usermsg( irc, "Can't open a groupchat with %s.", cmd[2] ); 1110 } 1111 } 1112 else 1113 { 1114 irc_usermsg( irc, "Unknown command: %s %s. Please use \x02help commands\x02 to get a list of available commands.", "chat", cmd[1] ); 1115 } 1116 1117 1118 1119 #if 0 1014 1120 account_t *a; 1015 1121 struct im_connection *ic; … … 1037 1143 if( cmd[3] ) 1038 1144 { 1039 if( cmd[3][0] != '#' && cmd[3][0] != '&')1145 if( strchr( CTYPES, cmd[3][0] ) == NULL ) 1040 1146 channel = g_strdup_printf( "&%s", cmd[3] ); 1041 1147 else … … 1080 1186 g_free( channel ); 1081 1187 } 1188 #endif 1082 1189 } 1083 1190 … … 1102 1209 { "qlist", 0, cmd_qlist, 0 }, 1103 1210 { "join_chat", 2, cmd_join_chat, 0 }, 1104 { " otr", 1, cmd_otr, 0 },1211 { "chat", 1, cmd_chat, 0 }, 1105 1212 { NULL } 1106 1213 };
Note: See TracChangeset
for help on using the changeset viewer.