Mercurial > hg > nnchat
comparison main.c @ 431:a9b20b31cae1
More code cleanups, this time using clang with excessive warnings enabled.
Also re-added util.h, that was missing. Oops.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 24 May 2012 20:57:06 +0300 |
parents | aaadf6cea6be |
children | 966c521e0954 |
comparison
equal
deleted
inserted
replaced
430:aaadf6cea6be | 431:a9b20b31cae1 |
---|---|
839 | 839 |
840 | 840 |
841 typedef struct | 841 typedef struct |
842 { | 842 { |
843 char *cmd; | 843 char *cmd; |
844 ssize_t len; | 844 size_t len; |
845 int (*handler)(nn_conn_t *); | 845 int (*handler)(nn_conn_t *); |
846 } nn_protocolcmd_t; | 846 } nn_protocolcmd_t; |
847 | 847 |
848 | 848 |
849 static nn_protocolcmd_t protoCmds[] = | 849 static nn_protocolcmd_t protoCmds[] = |
850 { | 850 { |
851 { "<USER>", -1, nnproto_parse_user }, | 851 { "<USER>", 0, nnproto_parse_user }, |
852 { "<LOGIN_", -1, nnproto_parse_login }, | 852 { "<LOGIN_", 0, nnproto_parse_login }, |
853 { "<DELETE_USER>", -1, nnproto_parse_delete_user }, | 853 { "<DELETE_USER>", 0, nnproto_parse_delete_user }, |
854 { "<ADD_USER>", -1, nnproto_parse_add_user }, | 854 { "<ADD_USER>", 0, nnproto_parse_add_user }, |
855 { "<NUMCLIENTS>", -1, nnproto_parse_num_clients }, | 855 { "<NUMCLIENTS>", 0, nnproto_parse_num_clients }, |
856 { "<BOOT />", -1, nnproto_parse_boot }, | 856 { "<BOOT />", 0, nnproto_parse_boot }, |
857 }; | 857 }; |
858 | 858 |
859 static const int nprotoCmds = sizeof(protoCmds) / sizeof(protoCmds[0]); | 859 static const int nprotoCmds = sizeof(protoCmds) / sizeof(protoCmds[0]); |
860 | 860 |
861 | 861 |
962 } | 962 } |
963 else | 963 else |
964 { | 964 { |
965 // Just list whomever is in ignore now | 965 // Just list whomever is in ignore now |
966 qlist_t *user = setIgnoreList; | 966 qlist_t *user = setIgnoreList; |
967 ssize_t nuser = th_llist_length(setIgnoreList); | 967 size_t nuser = th_llist_length(setIgnoreList); |
968 char *result = th_strdup_printf("Users ignored (%d): ", nuser); | 968 char *result = th_strdup_printf("Users ignored (%d): ", nuser); |
969 while (user != NULL) | 969 while (user != NULL) |
970 { | 970 { |
971 if (user->data != NULL) | 971 if (user->data != NULL) |
972 { | 972 { |
1147 | 1147 |
1148 typedef struct | 1148 typedef struct |
1149 { | 1149 { |
1150 char *cmd; | 1150 char *cmd; |
1151 int flags; | 1151 int flags; |
1152 ssize_t len; | 1152 size_t len; |
1153 int (*handler)(nn_conn_t *, char *buf); | 1153 int (*handler)(nn_conn_t *, char *buf); |
1154 } nn_usercmd_t; | 1154 } nn_usercmd_t; |
1155 | 1155 |
1156 | 1156 |
1157 static nn_usercmd_t userCmds[] = | 1157 static nn_usercmd_t userCmds[] = |
1158 { | 1158 { |
1159 // Server side commands, we just implement completion | 1159 // Server side commands, we just implement completion |
1160 { "me", CMDARG_STRING, -1, NULL }, | 1160 { "me", CMDARG_STRING, 0, NULL }, |
1161 { "status", CMDARG_STRING, -1, NULL }, | 1161 { "status", CMDARG_STRING, 0, NULL }, |
1162 { "list", CMDARG_NONE, -1, nncmd_list_all_users }, | 1162 { "list", CMDARG_NONE, 0, nncmd_list_all_users }, |
1163 | 1163 |
1164 // List internal username list | 1164 // List internal username list |
1165 { "who", CMDARG_NONE, -1, nncmd_names }, | 1165 { "who", CMDARG_NONE, 0, nncmd_names }, |
1166 { "names", CMDARG_NONE, -1, nncmd_names }, | 1166 { "names", CMDARG_NONE, 0, nncmd_names }, |
1167 | 1167 |
1168 { "w", CMDARG_NICK, -1, nncmd_open_profile }, | 1168 { "w", CMDARG_NICK, 0, nncmd_open_profile }, |
1169 { "profile", CMDARG_NICK, -1, nncmd_open_profile }, | 1169 { "profile", CMDARG_NICK, 0, nncmd_open_profile }, |
1170 | 1170 |
1171 { "query", CMDARG_NICK, -1, nncmd_open_query }, | 1171 { "query", CMDARG_NICK, 0, nncmd_open_query }, |
1172 { "close", CMDARG_OPTIONAL, -1, nncmd_close_query }, | 1172 { "close", CMDARG_OPTIONAL, 0, nncmd_close_query }, |
1173 { "win", CMDARG_OPTIONAL, -1, nncmd_window_info }, | 1173 { "win", CMDARG_OPTIONAL, 0, nncmd_window_info }, |
1174 | 1174 |
1175 { "ignore", CMDARG_NICK, -1, nncmd_ignore }, | 1175 { "ignore", CMDARG_NICK, 0, nncmd_ignore }, |
1176 { "color", CMDARG_STRING, -1, nncmd_set_color }, | 1176 { "color", CMDARG_STRING, 0, nncmd_set_color }, |
1177 { "save", CMDARG_NONE, -1, nncmd_save_config }, | 1177 { "save", CMDARG_NONE, 0, nncmd_save_config }, |
1178 }; | 1178 }; |
1179 | 1179 |
1180 static const int nuserCmds = sizeof(userCmds) / sizeof(userCmds[0]); | 1180 static const int nuserCmds = sizeof(userCmds) / sizeof(userCmds[0]); |
1181 | 1181 |
1182 | 1182 |
1272 // If current window is not the main room window, send private | 1272 // If current window is not the main room window, send private |
1273 if (currWin != chatWindows[0]) | 1273 if (currWin != chatWindows[0]) |
1274 { | 1274 { |
1275 if (currWin->id != NULL) | 1275 if (currWin->id != NULL) |
1276 { | 1276 { |
1277 char *tmp, *msg = th_strdup_printf("/prv -to %s -msg %s", currWin->id, buf); | 1277 char *msg = th_strdup_printf("/prv -to %s -msg %s", currWin->id, buf); |
1278 if (msg == NULL) return -3; | 1278 if (msg == NULL) return -3; |
1279 tmp = nn_dblencode_str(msg); | 1279 tmp = nn_dblencode_str(msg); |
1280 if (tmp == NULL) | 1280 if (tmp == NULL) |
1281 { | 1281 { |
1282 th_free(msg); | 1282 th_free(msg); |
1343 static char *previous = NULL, *pattern = NULL; | 1343 static char *previous = NULL, *pattern = NULL; |
1344 BOOL again = FALSE, hasSeparator = FALSE, | 1344 BOOL again = FALSE, hasSeparator = FALSE, |
1345 newPattern = FALSE, hasSpace = FALSE, isCommand; | 1345 newPattern = FALSE, hasSpace = FALSE, isCommand; |
1346 char *str = buf->data; | 1346 char *str = buf->data; |
1347 int mode = 0; | 1347 int mode = 0; |
1348 ssize_t endPos, startPos = buf->pos; | 1348 size_t endPos, startPos = buf->pos; |
1349 | 1349 |
1350 // previous word | 1350 // previous word |
1351 if (startPos >= 2 && str[startPos - 1] == ' ' && str[startPos - 2] != ' ') | 1351 if (startPos >= 2 && str[startPos - 1] == ' ' && str[startPos - 2] != ' ') |
1352 { | 1352 { |
1353 startPos -= 2; | 1353 startPos -= 2; |
1446 { | 1446 { |
1447 nn_user_t *user = nn_user_match(nnUsers, pattern, previous, again); | 1447 nn_user_t *user = nn_user_match(nnUsers, pattern, previous, again); |
1448 | 1448 |
1449 if (user) | 1449 if (user) |
1450 { | 1450 { |
1451 int i; | 1451 size_t i; |
1452 char *c = user->name; | 1452 char *c = user->name; |
1453 if (optDebug) | 1453 if (optDebug) |
1454 printMsg(currWin, "match='%s' / prev='%s'\n", user->name, previous); | 1454 printMsg(currWin, "match='%s' / prev='%s'\n", user->name, previous); |
1455 | 1455 |
1456 for (i = startPos; i <= endPos; i++) | 1456 for (i = startPos; i <= endPos; i++) |
1560 | 1560 |
1561 | 1561 |
1562 char *promptRequester(WINDOW *win, const char *info, BOOL allowEmpty) | 1562 char *promptRequester(WINDOW *win, const char *info, BOOL allowEmpty) |
1563 { | 1563 { |
1564 char tmpBuf[512], *ptr; | 1564 char tmpBuf[512], *ptr; |
1565 ssize_t pos; | 1565 size_t pos; |
1566 int curVis = curs_set(1); | 1566 int curVis = curs_set(1); |
1567 | 1567 |
1568 echo(); | 1568 echo(); |
1569 waddstr(win, info); | 1569 waddstr(win, info); |
1570 wgetnstr(win, tmpBuf, sizeof(tmpBuf) - 1); | 1570 wgetnstr(win, tmpBuf, sizeof(tmpBuf) - 1); |