Mercurial > hg > nnchat
changeset 9:a02659cc5bc8
Cleanup.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 20 Mar 2008 05:13:00 +0000 |
parents | 355d908d9d00 |
children | 53e127854dca |
files | nnchat.c |
diffstat | 1 files changed, 22 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/nnchat.c Thu Mar 20 02:02:04 2008 +0000 +++ b/nnchat.c Thu Mar 20 05:13:00 2008 +0000 @@ -493,26 +493,36 @@ int handleAddUser(int sock, char *str) { - char *s = strstr(str, "</ADD_USER>"); + char *p, *s = strstr(str, "</ADD_USER>"); (void) sock; if (!s) return 1; *s = 0; - printMsg("! %s ADDED.\n", str); + + p = decodeStr1(str); + if (!p) return -1; + + printMsg("! %s ADDED.\n", p); + th_free(p); return 0; } int handleDeleteUser(int sock, char *str) { - char *s = strstr(str, "</DELETE_USER>"); + char *p, *s = strstr(str, "</DELETE_USER>"); (void) sock; if (!s) return 1; *s = 0; - printMsg("! %s DELETED.\n", str); + + p = decodeStr1(str); + if (!p) return -1; + + printMsg("! %s DELETED.\n", p); + th_free(p); return 0; } @@ -700,16 +710,16 @@ tv.tv_usec = SET_SELECT_USEC; tmpfds = sockfds; if ((result = select(tmpSocket+1, &tmpfds, NULL, NULL, &tv)) == -1) { - THERR("Error occured in select(sockfds): %s\n", strerror(errno)); + printMsg("Error occured in select(sockfds): %s\n", strerror(errno)); exitProg = TRUE; } else if (FD_ISSET(tmpSocket, &tmpfds)) { gotBuf = recv(tmpSocket, tmpBuf, sizeof(tmpBuf), 0); if (gotBuf < 0) { - THERR("Error in recv: %s\n", strerror(errno)); + printMsg("Error in recv: %s\n", strerror(errno)); exitProg = TRUE; } else if (gotBuf == 0) { - THERR("Server closed connection.\n"); + printMsg("Server closed connection.\n"); exitProg = TRUE; } else { /* Handle protocol data */ @@ -718,10 +728,10 @@ if (result > 0) { /* Couldn't handle the message for some reason */ - THERR("Could not handle: %s\n", tmpBuf); + printMsg("Could not handle: %s\n", tmpBuf); } else if (result < 0) { /* Fatal error, quit */ - THERR("Fatal error with message: %s\n", tmpBuf); + printMsg("Fatal error with message: %s\n", tmpBuf); exitProg = TRUE; } } @@ -732,19 +742,19 @@ tv.tv_usec = SET_SELECT_USEC; tmpfds = inputfds; if ((result = select(1, &tmpfds, NULL, NULL, &tv)) == -1) { - THERR("Error occured in select(inputfds): %s\n", strerror(errno)); + printMsg("Error occured in select(inputfds): %s\n", strerror(errno)); exitProg = TRUE; } else if (FD_ISSET(0, &tmpfds)) { gotBuf = read(0, tmpBuf, sizeof(tmpBuf)); if (gotBuf < 0) { - THERR("Error in reading stdio.\n"); + printMsg("Error in reading stdio.\n"); exitProg = TRUE; } else { /* Call the user input handler */ result = handleInput(tmpSocket, tmpBuf, gotBuf); if (result < 0) { - THERR("Fatal error handling user input: %s\n", + printMsg("Fatal error handling user input: %s\n", tmpBuf); exitProg = TRUE; }