# HG changeset patch # User Matti Hamalainen # Date 1205989980 0 # Node ID a02659cc5bc80a5bea291762cee4d0f6887a3566 # Parent 355d908d9d008fc9ae7d5e672ac356c3a6e285b1 Cleanup. diff -r 355d908d9d00 -r a02659cc5bc8 nnchat.c --- 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, ""); + char *p, *s = strstr(str, ""); (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, ""); + char *p, *s = strstr(str, ""); (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; }