comparison nnchat.c @ 372:b9f0bdad6285

Use th_strcasecmp() and th_strncasecmp().
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 23 Jun 2011 14:43:10 +0300
parents 461a6befb7c3
children 1617d0a0c58e
comparison
equal deleted inserted replaced
371:080cd5154522 372:b9f0bdad6285
216 int i; 216 int i;
217 217
218 for (i = 0; i < SET_MAX_WINDOWS; i++) 218 for (i = 0; i < SET_MAX_WINDOWS; i++)
219 if (chatWindows[i] != NULL && 219 if (chatWindows[i] != NULL &&
220 chatWindows[i]->id != NULL && 220 chatWindows[i]->id != NULL &&
221 strcasecmp(id, chatWindows[i]->id) == 0) 221 th_strcasecmp(id, chatWindows[i]->id) == 0)
222 return chatWindows[i]; 222 return chatWindows[i];
223 223
224 return NULL; 224 return NULL;
225 } 225 }
226 226
573 573
574 BOOL checkIgnoreList(const char *name) 574 BOOL checkIgnoreList(const char *name)
575 { 575 {
576 qlist_t *node = setIgnoreList; 576 qlist_t *node = setIgnoreList;
577 while (node != NULL) { 577 while (node != NULL) {
578 if (strcasecmp(name, (char *) node->data) == 0) 578 if (th_strcasecmp(name, (char *) node->data) == 0)
579 return TRUE; 579 return TRUE;
580 node = node->next; 580 node = node->next;
581 } 581 }
582 return FALSE; 582 return FALSE;
583 } 583 }
818 return buf; 818 return buf;
819 } 819 }
820 820
821 int compareUsername(const void *s1, const void *s2) 821 int compareUsername(const void *s1, const void *s2)
822 { 822 {
823 return strcasecmp((char *) s1, (char *) s2); 823 return th_strcasecmp((char *) s1, (char *) s2);
824 } 824 }
825 825
826 int handleUserInput(nn_conn_t *conn, char *buf, size_t bufLen) 826 int handleUserInput(nn_conn_t *conn, char *buf, size_t bufLen)
827 { 827 {
828 char *tmpStr, tmpBuf[4096]; 828 char *tmpStr, tmpBuf[4096];
839 839
840 /* Check for special user commands */ 840 /* Check for special user commands */
841 if (*buf == 0) { 841 if (*buf == 0) {
842 return 1; 842 return 1;
843 } 843 }
844 else if (!strncasecmp(buf, "/color ", 7)) { 844 else if (!th_strncasecmp(buf, "/color ", 7)) {
845 /* Change color */ 845 /* Change color */
846 int tmpInt; 846 int tmpInt;
847 if ((tmpInt = th_get_hex_triplet(trimLeft(buf + 7))) < 0) { 847 if ((tmpInt = th_get_hex_triplet(trimLeft(buf + 7))) < 0) {
848 printMsgQ(currWin, "Invalid color value '%s'\n", buf+7); 848 printMsgQ(currWin, "Invalid color value '%s'\n", buf+7);
849 return 1; 849 return 1;
851 optUserColor = tmpInt; 851 optUserColor = tmpInt;
852 printMsgQ(currWin, "Setting color to #%06x\n", optUserColor); 852 printMsgQ(currWin, "Setting color to #%06x\n", optUserColor);
853 nn_conn_send_msg(conn, optUserNameEnc, "%%2FSetFontColor%%20%%2Dcolor%%20%06X", optUserColor); 853 nn_conn_send_msg(conn, optUserNameEnc, "%%2FSetFontColor%%20%%2Dcolor%%20%06X", optUserColor);
854 return 0; 854 return 0;
855 } 855 }
856 else if (!strncasecmp(buf, "/ignore", 7)) { 856 else if (!th_strncasecmp(buf, "/ignore", 7)) {
857 char *name = trimLeft(buf + 7); 857 char *name = trimLeft(buf + 7);
858 if (strlen(name) > 0) { 858 if (strlen(name) > 0) {
859 /* Add or remove someone to/from ignore */ 859 /* Add or remove someone to/from ignore */
860 qlist_t *user = th_llist_find_func(setIgnoreList, name, compareUsername); 860 qlist_t *user = th_llist_find_func(setIgnoreList, name, compareUsername);
861 if (user != NULL) { 861 if (user != NULL) {
881 printMsgQ(currWin, "%s\n", result); 881 printMsgQ(currWin, "%s\n", result);
882 th_free(result); 882 th_free(result);
883 } 883 }
884 return 0; 884 return 0;
885 } 885 }
886 else if (!strncasecmp(buf, "/query", 6)) { 886 else if (!th_strncasecmp(buf, "/query", 6)) {
887 char *name = trimLeft(buf + 6); 887 char *name = trimLeft(buf + 6);
888 if (strlen(name) > 0) { 888 if (strlen(name) > 0) {
889 nn_user_t *user = nn_user_find(nnUsers, nn_username_encode(name)); 889 nn_user_t *user = nn_user_find(nnUsers, nn_username_encode(name));
890 if (user != NULL) { 890 if (user != NULL) {
891 name = nn_username_decode(th_strdup(user->name)); 891 name = nn_username_decode(th_strdup(user->name));
899 printMsgQ(currWin, "To close a PRV query, use /close [username]\n"); 899 printMsgQ(currWin, "To close a PRV query, use /close [username]\n");
900 printMsgQ(currWin, "/close without username will close the current PRV window.\n"); 900 printMsgQ(currWin, "/close without username will close the current PRV window.\n");
901 } 901 }
902 return 0; 902 return 0;
903 } 903 }
904 else if (!strncasecmp(buf, "/win", 4)) { 904 else if (!th_strncasecmp(buf, "/win", 4)) {
905 /* Change color */ 905 /* Change color */
906 char *tmp = trimLeft(buf + 4); 906 char *tmp = trimLeft(buf + 4);
907 if (strlen(tmp) > 0) { 907 if (strlen(tmp) > 0) {
908 int val = atoi(tmp); 908 int val = atoi(tmp);
909 if (val >= 1 && val < SET_MAX_WINDOWS) { 909 if (val >= 1 && val < SET_MAX_WINDOWS) {
917 printMsgQ(currWin, "Window : #%d\n", currWin->num); 917 printMsgQ(currWin, "Window : #%d\n", currWin->num);
918 printMsgQ(currWin, "ID : %s\n", currWin->id); 918 printMsgQ(currWin, "ID : %s\n", currWin->id);
919 } 919 }
920 return 0; 920 return 0;
921 } 921 }
922 else if (!strncasecmp(buf, "/close", 6)) { 922 else if (!th_strncasecmp(buf, "/close", 6)) {
923 char *name = trimLeft(buf + 6); 923 char *name = trimLeft(buf + 6);
924 if (strlen(name) > 0) { 924 if (strlen(name) > 0) {
925 nn_window_t *win = findWindow(name); 925 nn_window_t *win = findWindow(name);
926 if (win != NULL) { 926 if (win != NULL) {
927 closeWindow(win); 927 closeWindow(win);
935 currWin = chatWindows[0]; 935 currWin = chatWindows[0];
936 } 936 }
937 } 937 }
938 return 0; 938 return 0;
939 } 939 }
940 else if (!strncasecmp(buf, "/save", 5)) { 940 else if (!th_strncasecmp(buf, "/save", 5)) {
941 /* Save configuration */ 941 /* Save configuration */
942 FILE *cfgfile = fopen(setConfigFile, "w"); 942 FILE *cfgfile = fopen(setConfigFile, "w");
943 if (cfgfile == NULL) { 943 if (cfgfile == NULL) {
944 printMsgQ(currWin, "Could not create configuration to file '%s': %s\n", 944 printMsgQ(currWin, "Could not create configuration to file '%s': %s\n",
945 setConfigFile, strerror(errno)); 945 setConfigFile, strerror(errno));
950 th_cfg_write(cfgfile, setConfigFile, cfg)); 950 th_cfg_write(cfgfile, setConfigFile, cfg));
951 951
952 fclose(cfgfile); 952 fclose(cfgfile);
953 return 0; 953 return 0;
954 } 954 }
955 else if (!strncasecmp(buf, "/w ", 3)) { 955 else if (!th_strncasecmp(buf, "/w ", 3)) {
956 /* Open given username's profile via firefox in a new tab */ 956 /* Open given username's profile via firefox in a new tab */
957 char *name = trimLeft(buf + 3); 957 char *name = trimLeft(buf + 3);
958 958
959 printMsg(currWin, "Opening profile for: '%s'\n", name); 959 printMsg(currWin, "Opening profile for: '%s'\n", name);
960 960
994 wait(&status); 994 wait(&status);
995 } 995 }
996 #endif 996 #endif
997 return 0; 997 return 0;
998 } 998 }
999 else if (!strncasecmp(buf, "/who", 4)) { 999 else if (!th_strncasecmp(buf, "/who", 4)) {
1000 /* Alias /who to /listallusers */ 1000 /* Alias /who to /listallusers */
1001 snprintf(tmpBuf, sizeof(tmpBuf), "/listallusers"); 1001 snprintf(tmpBuf, sizeof(tmpBuf), "/listallusers");
1002 buf = tmpBuf; 1002 buf = tmpBuf;
1003 } 1003 }
1004 1004
1105 hasSpace = TRUE; 1105 hasSpace = TRUE;
1106 1106
1107 if (newPattern) { 1107 if (newPattern) {
1108 /* Get pattern, check if it matches previous pattern and set 'again' flag */ 1108 /* Get pattern, check if it matches previous pattern and set 'again' flag */
1109 char *npattern = nn_editbuf_get_string(buf, startPos, endPos); 1109 char *npattern = nn_editbuf_get_string(buf, startPos, endPos);
1110 if (pattern && npattern && strcasecmp(npattern, pattern) == 0) 1110 if (pattern && npattern && th_strcasecmp(npattern, pattern) == 0)
1111 again = TRUE; 1111 again = TRUE;
1112 1112
1113 th_free(pattern); 1113 th_free(pattern);
1114 pattern = npattern; 1114 pattern = npattern;
1115 1115