Mercurial > hg > nnchat
diff nnchat.c @ 97:218efd2f0641
Rename functions for clarity.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 17 Nov 2009 19:20:25 +0200 |
parents | 7c9538e71c89 |
children | b7c981e27b66 |
line wrap: on
line diff
--- a/nnchat.c Sun Jul 05 16:55:40 2009 +0300 +++ b/nnchat.c Tue Nov 17 19:20:25 2009 +0200 @@ -342,10 +342,10 @@ if (!q) return 3; *q = 0; - s = decodeStr1(s); + s = nn_decode_str1(s); if (!s) return -1; - p = decodeStr1(p); + p = nn_decode_str1(p); if (!p) { th_free(s); return -2; @@ -353,20 +353,20 @@ if (*s == '/') { - t = stripXMLTags(s + 1); + t = nn_strip_tags(s + 1); if (!strncmp(t, "BPRV", 4)) { - h = decodeStr2(t + 1); + h = nn_decode_str2(t + 1); printMsg("½11½%s½0½\n", h); } else { - h = decodeStr2(t); + h = nn_decode_str2(t); printMsg("½9½* %s½0½\n", h); } th_free(h); th_free(t); } else { BOOL isMine = strcmp(p, optUserName) == 0; - t = stripXMLTags(s); - h = decodeStr2(t); + t = nn_strip_tags(s); + h = nn_decode_str2(t); printMsg("½5½<½%d½%s½5½>½0½ %s\n", isMine ? 14 : 15, p, h); th_free(h); th_free(t); @@ -394,7 +394,7 @@ return -2; } else if (!strncmp(str, "SUCCESS", 7)) { printMsg("½2½Login success½0½ - ½3½%s½0½\n", tmpStr); - sendUserMsg(sock, optUserName2, "%%2FRequestUserList"); + nn_send_msg(sock, optUserName2, "%%2FRequestUserList"); return 0; } else return 1; @@ -410,7 +410,7 @@ if (!s) return 1; *s = 0; - p = doubleDecodeStr(str); + p = nn_dbldecode_str(str); if (!p) return -1; printMsg("! ½3½%s½0½ ½2½ADDED.½0½\n", p); @@ -428,7 +428,7 @@ if (!s) return 1; *s = 0; - p = doubleDecodeStr(str); + p = nn_dbldecode_str(str); if (!p) return -1; printMsg("! ½3½%s½0½ ½1½DELETED.½0½\n", p); @@ -507,7 +507,7 @@ } optUserColor = tmpInt; printMsg("Setting color to #%06x\n", optUserColor); - sendUserMsg(sock, optUserName2, "%%2FSetFontColor%%20%%2Dcolor%%20%06X", optUserColor); + nn_send_msg(sock, optUserName2, "%%2FSetFontColor%%20%%2Dcolor%%20%06X", optUserColor); return 0; } else if (!strncmp(buf, "/flood ", 7)) { int i; @@ -515,12 +515,12 @@ snprintf(tmpBuf, sizeof(tmpBuf), "/prv -to %s -msg . .", buf+7); - tmpStr = doubleEncodeStr(tmpBuf); + tmpStr = nn_dblencode_str(tmpBuf); if (!tmpStr) return -2; result = TRUE; for (i = 0; i < 50 && result; i++) { - result = sendUserMsg(sock, optUserName2, "%s", tmpStr); + result = nn_send_msg(sock, optUserName2, "%s", tmpStr); usleep(250); } @@ -547,10 +547,10 @@ /* Send double-encoded */ - tmpStr = doubleEncodeStr(buf); + tmpStr = nn_dblencode_str(buf); if (!tmpStr) return -2; - result = sendUserMsg(sock, optUserName2, "%s", tmpStr); + result = nn_send_msg(sock, optUserName2, "%s", tmpStr); th_free(tmpStr); if (result) return 0; @@ -593,7 +593,7 @@ struct timeval socktv; fd_set sockfds; char *tmpStr; - nn_editbuf_t *editBuf = newBuf(SET_BUFSIZE); + nn_editbuf_t *editBuf = nn_editbuf_new(SET_BUFSIZE); nn_editbuf_t *histBuf[SET_MAX_HISTORY+2]; int histPos = 0, histMax = 0; @@ -629,7 +629,7 @@ } } - if (!initNetwork()) { + if (!nn_network_init()) { THERR("Could not initialize network subsystem.\n"); goto err_exit; } else @@ -650,13 +650,13 @@ /* To emulate the official client, we first make a request for * policy file, even though we don't use it for anything... */ - if ((tmpSocket = openConnection((struct in_addr *) tmpHost->h_addr, 843)) < 0) { + if ((tmpSocket = nn_open_connection((struct in_addr *) tmpHost->h_addr, 843)) < 0) { THERR("Policy file request connection setup failed!\n"); goto err_exit; } tmpStr = "<policy-file-request/>"; - if (sendToSocket(tmpSocket, tmpStr, strlen(tmpStr) + 1) == FALSE) { + if (nn_send_to_socket(tmpSocket, tmpStr, strlen(tmpStr) + 1) == FALSE) { THERR("Failed to send policy file request.\n"); goto err_exit; } else { @@ -665,20 +665,20 @@ gotBuf = recv(tmpSocket, tmpBuf, sizeof(tmpBuf), 0); tmpBuf[gotBuf-1] = 0; THMSG(2, "Probe got: %s\n", tmpBuf); - closeConnection(tmpSocket); + nn_close_connection(tmpSocket); } #endif /* Okay, now do the proper connection ... */ - if ((tmpSocket = openConnection((struct in_addr *) tmpHost->h_addr, optPort)) < 0) { + if ((tmpSocket = nn_open_connection((struct in_addr *) tmpHost->h_addr, optPort)) < 0) { THERR("Main connection setup failed!\n"); goto err_exit; } THMSG(1, "Connected, logging in as '%s', site '%s'.\n", optUserName, optSite); - optUserName2 = doubleEncodeStr(optUserName); - tmpStr = doubleEncodeStr(optSite); - sendUserMsg(tmpSocket, optUserName2, "%%2Flogin%%20%%2Dsite%%20%s%%20%%2Dpassword%%20%s", tmpStr, optPassword); + optUserName2 = nn_dblencode_str(optUserName); + tmpStr = nn_dblencode_str(optSite); + nn_send_msg(tmpSocket, optUserName2, "%%2Flogin%%20%%2Dsite%%20%s%%20%%2Dpassword%%20%s", tmpStr, optPassword); th_free(tmpStr); /* Initialize NCurses */ @@ -720,7 +720,7 @@ if (!initializeWindows()) goto err_exit; - clearBuf(editBuf); + nn_editbuf_clear(editBuf); printEditBuf("", editBuf); updateStatus(insertMode); } @@ -739,10 +739,10 @@ socktv.tv_usec = SET_DELAY_USEC; tmpfds = sockfds; if ((result = select(tmpSocket+1, &tmpfds, NULL, NULL, &socktv)) == -1) { - int res = getSocketErrno(); + int res = nn_get_socket_errno(); if (res != EINTR) { errorMsg("Error occured in select(sockfds): %d, %s\n", - res, getSocketErrStr(res)); + res, nn_get_socket_errstr(res)); isError = TRUE; } } else if (FD_ISSET(tmpSocket, &tmpfds)) { @@ -752,8 +752,8 @@ gotBuf = recv(tmpSocket, tmpBuf, sizeof(tmpBuf), 0); if (gotBuf < 0) { - int res = getSocketErrno(); - errorMsg("Error in recv: %d, %s\n", res, getSocketErrStr(res)); + int res = nn_get_socket_errno(); + errorMsg("Error in recv: %d, %s\n", res, nn_get_socket_errstr(res)); isError = TRUE; } else if (gotBuf == 0) { errorMsg("Server closed connection.\n"); @@ -824,19 +824,19 @@ if (editBuf->len > 0) { if (histMax > 0) { - freeBuf(histBuf[SET_MAX_HISTORY+1]); + nn_editbuf_free(histBuf[SET_MAX_HISTORY+1]); histBuf[SET_MAX_HISTORY+1] = NULL; memmove(&histBuf[2], &histBuf[1], histMax * sizeof(histBuf[0])); } histPos = 0; - histBuf[1] = copyBuf(editBuf); + histBuf[1] = nn_editbuf_copy(editBuf); if (histMax < SET_MAX_HISTORY) histMax++; - insertBuf(editBuf, editBuf->len, 0); + nn_editbuf_insert(editBuf, editBuf->len, 0); result = handleUserInput(tmpSocket, editBuf->data, editBuf->len); - clearBuf(editBuf); + nn_editbuf_clear(editBuf); if (result < 0) { errorMsg("Fatal error handling user input: %s\n", editBuf->data); @@ -859,13 +859,13 @@ case KEY_UP: /* Backwards in input history */ if (histPos == 0) { - freeBuf(histBuf[0]); - histBuf[0] = copyBuf(editBuf); + nn_editbuf_free(histBuf[0]); + histBuf[0] = nn_editbuf_copy(editBuf); } if (histPos < histMax) { histPos++; - freeBuf(editBuf); - editBuf = copyBuf(histBuf[histPos]); + nn_editbuf_free(editBuf); + editBuf = nn_editbuf_copy(histBuf[histPos]); update = TRUE; } break; @@ -873,8 +873,8 @@ case KEY_DOWN: /* Forwards in input history */ if (histPos > 0) { histPos--; - freeBuf(editBuf); - editBuf = copyBuf(histBuf[histPos]); + nn_editbuf_free(editBuf); + editBuf = nn_editbuf_copy(histBuf[histPos]); update = TRUE; } break; @@ -908,25 +908,25 @@ break; case 0x10a: /* F2 = Clear editbuffer */ - clearBuf(editBuf); + nn_editbuf_clear(editBuf); update = TRUE; break; - case KEY_HOME: setBufPos(editBuf, 0); update = TRUE; break; - case KEY_END: setBufPos(editBuf, editBuf->len); update = TRUE; break; - case KEY_LEFT: setBufPos(editBuf, editBuf->pos - 1); update = TRUE; break; - case KEY_RIGHT: setBufPos(editBuf, editBuf->pos + 1); update = TRUE; break; + case KEY_HOME: nn_editbuf_setpos(editBuf, 0); update = TRUE; break; + case KEY_END: nn_editbuf_setpos(editBuf, editBuf->len); update = TRUE; break; + case KEY_LEFT: nn_editbuf_setpos(editBuf, editBuf->pos - 1); update = TRUE; break; + case KEY_RIGHT: nn_editbuf_setpos(editBuf, editBuf->pos + 1); update = TRUE; break; case KEY_BACKSPACE: case 0x08: - deleteBuf(editBuf, editBuf->pos - 1); - setBufPos(editBuf, editBuf->pos - 1); + nn_editbuf_delete(editBuf, editBuf->pos - 1); + nn_editbuf_setpos(editBuf, editBuf->pos - 1); update = TRUE; break; case 0x14a: /* Delete */ - deleteBuf(editBuf, editBuf->pos); + nn_editbuf_delete(editBuf, editBuf->pos); update = TRUE; break; @@ -944,10 +944,10 @@ default: if (isprint(c) || c == 0xe4 || c == 0xf6 || c == 0xc4 || c == 0xd6) { if (insertMode) - insertBuf(editBuf, editBuf->pos, c); + nn_editbuf_insert(editBuf, editBuf->pos, c); else - writeBuf(editBuf, editBuf->pos, c); - setBufPos(editBuf, editBuf->pos + 1); + nn_editbuf_write(editBuf, editBuf->pos, c); + nn_editbuf_setpos(editBuf, editBuf->pos + 1); update = TRUE; } else { printMsg("Unhandled key: 0x%02x\n", c); @@ -966,7 +966,7 @@ if (++updateCount > 10) { time_t tmpTime = time(NULL); if (tmpTime - prevTime > SET_KEEPALIVE) { - sendUserMsg(tmpSocket, optUserName2, "/listallusers"); + nn_send_msg(tmpSocket, optUserName2, "/listallusers"); prevTime = tmpTime; } @@ -975,7 +975,7 @@ printMsg("%s v%s - %s\n", th_prog_name, th_prog_version, th_prog_fullname); printMsg("%s\n", th_prog_author); printMsg("%s\n", th_prog_license); - sendUserMsg(tmpSocket, optUserName2, "%%2FSetFontColor%%20%%2Dcolor%%20%06X", optUserColor); + nn_send_msg(tmpSocket, optUserName2, "%%2FSetFontColor%%20%%2Dcolor%%20%06X", optUserColor); } updateStatus(insertMode); @@ -986,9 +986,9 @@ /* Shutdown */ err_exit: - freeBuf(editBuf); + nn_editbuf_free(editBuf); for (histPos = 0; histPos <= SET_MAX_HISTORY; histPos++) - freeBuf(histBuf[histPos]); + nn_editbuf_free(histBuf[histPos]); if (cursesInit) { if (curVis != ERR) @@ -1003,10 +1003,10 @@ th_free(optUserName2); - closeConnection(tmpSocket); + nn_close_connection(tmpSocket); if (networkInit) - closeNetwork(); + nn_network_close(); THMSG(1, "Connection terminated.\n");