comparison main.c @ 519:f17d2ab25618

Add option for only allowing private messages from people on a special friend list.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 05 Jun 2012 23:20:52 +0300
parents 8132548e1a07
children ab56ed0d0c25
comparison
equal deleted inserted replaced
518:8132548e1a07 519:f17d2ab25618
48 *optSite = "NN", 48 *optSite = "NN",
49 *optNickSepStr = NULL; 49 *optNickSepStr = NULL;
50 char optNickSep; 50 char optNickSep;
51 BOOL optDaemon = FALSE; 51 BOOL optDaemon = FALSE;
52 FILE *optLogFile = NULL; 52 FILE *optLogFile = NULL;
53 BOOL setIgnoreMode = FALSE; 53 BOOL setIgnoreMode = FALSE,
54 BOOL optDebug = FALSE; 54 optDebug = FALSE,
55 BOOL optLogEnable = FALSE; 55 optLogEnable = FALSE,
56 optOnlyFriendPrv = FALSE;
56 57
57 qlist_t *setIgnoreList = NULL, 58 qlist_t *setIgnoreList = NULL,
59 *setFriendList = NULL,
58 *setIdleMessages = NULL; 60 *setIdleMessages = NULL;
59 nn_userhash_t *nnUsers = NULL; 61 nn_userhash_t *nnUsers = NULL;
60 char *setConfigFile = NULL, 62 char *setConfigFile = NULL,
61 *setBrowser = NULL; 63 *setBrowser = NULL;
62 cfgitem_t *cfg = NULL; 64 cfgitem_t *cfg = NULL;
339 (void) conn; 341 (void) conn;
340 printMsgV(NULL, LOG_STAMP | LOG_WINDOW | LOG_FILE, fmt, ap); 342 printMsgV(NULL, LOG_STAMP | LOG_WINDOW | LOG_FILE, fmt, ap);
341 } 343 }
342 344
343 345
344 BOOL checkIgnoreList(const char *name) 346 BOOL checkNameList(qlist_t *list, const char *name)
345 { 347 {
346 qlist_t *node = setIgnoreList; 348 qlist_t *node;
347 while (node != NULL) 349
350 for (node = list; node != NULL; node = node->next)
348 { 351 {
349 if (th_strcasecmp(name, (char *) node->data) == 0) 352 if (th_strcasecmp(name, (char *) node->data) == 0)
350 return TRUE; 353 return TRUE;
351 node = node->next; 354 }
352 } 355
353 return FALSE; 356 return FALSE;
354 } 357 }
355 358
356 359
357 int nnproto_parse_user(nn_conn_t *conn) 360 int nnproto_parse_user(nn_conn_t *conn)
393 396
394 /* Check if the username is on our ignore list and 397 /* Check if the username is on our ignore list and
395 * that it is not our OWN username! 398 * that it is not our OWN username!
396 */ 399 */
397 isMine = strcmp(name, optUserName) == 0; 400 isMine = strcmp(name, optUserName) == 0;
398 isIgnored = setIgnoreMode && !isMine && checkIgnoreList(name); 401 isIgnored = setIgnoreMode && !isMine && checkNameList(setIgnoreList, name);
399 402
400 // Is it a special control message? 403 // Is it a special control message?
401 if (*msg == '/') 404 if (*msg == '/')
402 { 405 {
403 // Ignore room join/leave messages 406 // Ignore room join/leave messages
422 in_msg = tmp + 2; 425 in_msg = tmp + 2;
423 else 426 else
424 in_msg = ""; 427 in_msg = "";
425 *tmp = 0; 428 *tmp = 0;
426 429
427 isIgnored = setIgnoreMode && checkIgnoreList(in_name); 430 if (!optOnlyFriendPrv || !checkNameList(setFriendList, in_name))
428 win = nnwin_find(in_name);
429
430 if (win != NULL)
431 { 431 {
432 printMsgF(win, isIgnored ? 0 : LOG_WINDOW, 432 isIgnored = setIgnoreMode && checkNameList(setIgnoreList, in_name);
433 "½5½<½%d½%s½5½>½0½ %s\n", 433 win = nnwin_find(in_name);
434 isMine ? 14 : 15, isMine ? optUserName : in_name, in_msg); 434
435 435 if (win != NULL)
436 printMsgF(NULL, LOG_FILE, "½11½%s½0½\n", h); 436 {
437 printMsgF(win, isIgnored ? 0 : LOG_WINDOW,
438 "½5½<½%d½%s½5½>½0½ %s\n",
439 isMine ? 14 : 15, isMine ? optUserName : in_name, in_msg);
440
441 printMsgF(NULL, LOG_FILE, "½11½%s½0½\n", h);
442 }
443 else
444 {
445 printMsgF(NULL, isIgnored ? LOG_FILE : (LOG_WINDOW | LOG_FILE),
446 "½11½%s½0½\n", h);
447 }
437 } 448 }
438 else 449
439 {
440 printMsgF(NULL, isIgnored ? LOG_FILE : (LOG_WINDOW | LOG_FILE),
441 "½11½%s½0½\n", h);
442 }
443 th_free(in_name); 450 th_free(in_name);
444 th_free(h); 451 th_free(h);
445 } 452 }
446 else 453 else
447 { 454 {
675 th_free(enc_name); 682 th_free(enc_name);
676 return 0; 683 return 0;
677 } 684 }
678 685
679 686
680 int nncmd_ignore(nn_conn_t *conn, char *name) 687 int nncmd_change_list(nn_conn_t *conn, const char *listname, qlist_t **list, const char *name)
681 { 688 {
682 (void) conn; 689 (void) conn;
683 690
684 if (name[0]) 691 if (name[0])
685 { 692 {
686 // Add or remove someone to/from ignore 693 // Add or remove someone to/from ignore
687 qlist_t *user = th_llist_find_func(setIgnoreList, name, str_compare); 694 qlist_t *user = th_llist_find_func(*list, name, str_compare);
688 if (user != NULL) 695 if (user != NULL)
689 { 696 {
690 printMsgQ(currWin, "Removed user '%s' from ignore.\n", name); 697 printMsgQ(currWin, "Removed user '%s' from %s list.\n", name, listname);
691 th_llist_delete_node(&setIgnoreList, user); 698 th_llist_delete_node(&setIgnoreList, user);
692 } 699 }
693 else 700 else
694 { 701 {
695 printMsgQ(currWin, "Now ignoring '%s'.\n", name); 702 printMsgQ(currWin, "Added '%s' to %s list.\n", name, listname);
696 th_llist_append(&setIgnoreList, th_strdup(name)); 703 th_llist_append(list, th_strdup(name));
697 } 704 }
698 } 705 }
699 else 706 else
700 { 707 {
701 // Just list whomever is in ignore now 708 // Just list whomever is in ignore now
702 qlist_t *user = setIgnoreList; 709 qlist_t *user = *list;
703 size_t nuser = th_llist_length(setIgnoreList); 710 size_t nuser = th_llist_length(*list);
704 char *result = th_strdup_printf("Users ignored (%d): ", nuser); 711 char *result = th_strdup_printf("Users on %s list (%d): ", listname, nuser);
705 while (user != NULL) 712 while (user != NULL)
706 { 713 {
707 if (user->data != NULL) 714 if (user->data != NULL)
708 { 715 {
709 th_pstr_printf(&result, "%s'%s'", result, (char *) user->data); 716 th_pstr_printf(&result, "%s'%s'", result, (char *) user->data);
718 725
719 return 0; 726 return 0;
720 } 727 }
721 728
722 729
730 int nncmd_ignore(nn_conn_t *conn, char *name)
731 {
732 return nncmd_change_list(conn, "ignore", &setIgnoreList, name);
733 }
734
735
736 int nncmd_friend(nn_conn_t *conn, char *name)
737 {
738 return nncmd_change_list(conn, "friend", &setFriendList, name);
739 }
740
741
723 int nncmd_set_color(nn_conn_t *conn, char *arg) 742 int nncmd_set_color(nn_conn_t *conn, char *arg)
724 { 743 {
725 int val; 744 int val;
726 (void) conn; 745 (void) conn;
727 746
958 { "/query", CMDARG_NICK, 0, nncmd_open_query }, 977 { "/query", CMDARG_NICK, 0, nncmd_open_query },
959 { "/close", CMDARG_OPTIONAL, 0, nncmd_close_query }, 978 { "/close", CMDARG_OPTIONAL, 0, nncmd_close_query },
960 { "/win", CMDARG_OPTIONAL, 0, nncmd_window_info }, 979 { "/win", CMDARG_OPTIONAL, 0, nncmd_window_info },
961 980
962 { "/ignore", CMDARG_OPTIONAL, 0, nncmd_ignore }, 981 { "/ignore", CMDARG_OPTIONAL, 0, nncmd_ignore },
982 { "/friend", CMDARG_OPTIONAL, 0, nncmd_friend },
963 { "/color", CMDARG_STRING, 0, nncmd_set_color }, 983 { "/color", CMDARG_STRING, 0, nncmd_set_color },
964 { "/save", CMDARG_NONE, 0, nncmd_save_config }, 984 { "/save", CMDARG_NONE, 0, nncmd_save_config },
965 }; 985 };
966 986
967 static qlist_t *userCmds = NULL; 987 static qlist_t *userCmds = NULL;
1405 case KEY_F(5): // F5 = Ignore mode 1425 case KEY_F(5): // F5 = Ignore mode
1406 setIgnoreMode = !setIgnoreMode; 1426 setIgnoreMode = !setIgnoreMode;
1407 printMsgQ(currWin, "Ignore mode = %s\n", setIgnoreMode ? "ON" : "OFF"); 1427 printMsgQ(currWin, "Ignore mode = %s\n", setIgnoreMode ? "ON" : "OFF");
1408 break; 1428 break;
1409 1429
1430 case KEY_F(6): // F6 = Ignore mode
1431 optOnlyFriendPrv = !optOnlyFriendPrv;
1432 printMsgQ(currWin, "Only friends allowed to PRV you = %s\n", optOnlyFriendPrv ? "ON" : "OFF");
1433 break;
1434
1410 case 0x03: // ^C = quit 1435 case 0x03: // ^C = quit
1411 case KEY_F(9): // F9 = Quit 1436 case KEY_F(9): // F9 = Quit
1412 printMsg(currWin, "Quitting per user request (%d/0x%x).\n", c, c); 1437 printMsg(currWin, "Quitting per user request (%d/0x%x).\n", c, c);
1413 editState->exitProg = TRUE; 1438 editState->exitProg = TRUE;
1414 break; 1439 break;
1482 1507
1483 th_cfg_add_comment(&tmpcfg, "Default setting of ignore mode"); 1508 th_cfg_add_comment(&tmpcfg, "Default setting of ignore mode");
1484 th_cfg_add_bool(&tmpcfg, "ignore", &setIgnoreMode, setIgnoreMode); 1509 th_cfg_add_bool(&tmpcfg, "ignore", &setIgnoreMode, setIgnoreMode);
1485 th_cfg_add_comment(&tmpcfg, "People to be ignored when ignore mode is enabled"); 1510 th_cfg_add_comment(&tmpcfg, "People to be ignored when ignore mode is enabled");
1486 th_cfg_add_string_list(&tmpcfg, "ignore_list", &setIgnoreList); 1511 th_cfg_add_string_list(&tmpcfg, "ignore_list", &setIgnoreList);
1512
1513 th_cfg_add_comment(&tmpcfg, "Allow only defined friends to private to you");
1514 th_cfg_add_bool(&tmpcfg, "prv_friends", &optOnlyFriendPrv, optOnlyFriendPrv);
1515 th_cfg_add_comment(&tmpcfg, "List of your friends");
1516 th_cfg_add_string_list(&tmpcfg, "friend_list", &setFriendList);
1487 1517
1488 th_cfg_add_comment(&tmpcfg, "Random messages for idle timeout protection. If none are set, plain '.' is used."); 1518 th_cfg_add_comment(&tmpcfg, "Random messages for idle timeout protection. If none are set, plain '.' is used.");
1489 th_cfg_add_string_list(&tmpcfg, "idle_messages", &setIdleMessages); 1519 th_cfg_add_string_list(&tmpcfg, "idle_messages", &setIdleMessages);
1490 1520
1491 th_cfg_add_comment(&tmpcfg, "Character used as nickname auto-completion separator (default is ':')"); 1521 th_cfg_add_comment(&tmpcfg, "Character used as nickname auto-completion separator (default is ':')");