Mercurial > hg > nnchat
diff libnnchat.c @ 97:218efd2f0641
Rename functions for clarity.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 17 Nov 2009 19:20:25 +0200 |
parents | 69f9c46e4a94 |
children | b096ae97fc7d |
line wrap: on
line diff
--- a/libnnchat.c Sun Jul 05 16:55:40 2009 +0300 +++ b/libnnchat.c Tue Nov 17 19:20:25 2009 +0200 @@ -28,31 +28,31 @@ return buf; } -int getSocketErrno(void) +int nn_get_socket_errno(void) { return WSAGetLastError(); } -const char *getSocketErrStr(int err) +const char *nn_get_socket_errstr(int err) { static char buf[64]; snprintf(buf, sizeof(buf), "Error #%d", err); return buf; } #else -int getSocketErrno(void) +int nn_get_socket_errno(void) { return errno; } -const char *getSocketErrStr(int err) +const char *nn_get_socket_errstr(int err) { return strerror(err); } #endif -int openConnection(struct in_addr *addr, const int port) +int nn_open_connection(struct in_addr *addr, const int port) { struct sockaddr_in tmpAddr; int sock = -1; @@ -80,7 +80,7 @@ } -void closeConnection(const int sock) +void nn_close_connection(const int sock) { if (sock >= 0) { #ifdef __WIN32 @@ -92,7 +92,7 @@ } -BOOL initNetwork(void) +BOOL nn_network_init(void) { #ifdef __WIN32 /* Initialize WinSock, if needed */ @@ -107,7 +107,7 @@ } -void closeNetwork(void) +void nn_network_close(void) { #ifdef __WIN32 WSACleanup(); @@ -115,7 +115,7 @@ } -BOOL sendToSocket(const int sock, char *buf, const size_t bufLen) +BOOL nn_send_to_socket(const int sock, char *buf, const size_t bufLen) { size_t bufLeft = bufLen; char *bufPtr = buf; @@ -164,7 +164,7 @@ } -char *encodeStr1(const char *str) +char *nn_encode_str1(const char *str) { const char *s = str; char *result; @@ -218,7 +218,7 @@ } -char *decodeStr1(const char *str) +char *nn_decode_str1(const char *str) { const char *s = str; char *result; @@ -280,7 +280,7 @@ } -char *stripXMLTags(const char *str) +char *nn_strip_tags(const char *str) { const char *s = str; char *result; @@ -305,7 +305,7 @@ } -char *encodeStr2(const char *str) +char *nn_encode_str2(const char *str) { const char *s = str; char *result; @@ -336,7 +336,7 @@ } -char *decodeStr2(const char *str) +char *nn_decode_str2(const char *str) { const char *s = str; char *result; @@ -372,35 +372,35 @@ } -char *doubleDecodeStr(const char *str) +char *nn_dbldecode_str(const char *str) { char *res, *tmp; - if ((tmp = decodeStr1(str)) == NULL) + if ((tmp = nn_decode_str1(str)) == NULL) return NULL; - res = decodeStr2(tmp); + res = nn_decode_str2(tmp); th_free(tmp); return res; } -char *doubleEncodeStr(const char *str) +char *nn_dblencode_str(const char *str) { char *res, *tmp; - if ((tmp = encodeStr2(str)) == NULL) + if ((tmp = nn_encode_str2(str)) == NULL) return NULL; - res = encodeStr1(tmp); + res = nn_encode_str1(tmp); th_free(tmp); return res; } -BOOL sendUserMsg(const int sock, const char *user, const char *fmt, ...) +BOOL nn_send_msg(const int sock, const char *user, const char *fmt, ...) { char tmpBuf[SET_BUFSIZE], tmpBuf2[SET_BUFSIZE + 256]; int n; @@ -416,11 +416,11 @@ "<USER>%s</USER><MESSAGE>%s</MESSAGE>", user, tmpBuf); - return sendToSocket(sock, tmpBuf2, strlen(tmpBuf2) + 1); + return nn_send_to_socket(sock, tmpBuf2, strlen(tmpBuf2) + 1); } -nn_ringbuf_t * newRingBuf(const size_t size) +nn_ringbuf_t * nn_ringbuf_new(const size_t size) { nn_ringbuf_t *res = th_calloc(1, sizeof(nn_ringbuf_t)); @@ -432,7 +432,7 @@ } -void freeRingBuf(nn_ringbuf_t *buf) +void nn_ringbuf_free(nn_ringbuf_t *buf) { size_t i; @@ -444,7 +444,7 @@ } -void addRingBuf(nn_ringbuf_t *buf, const char *str) +void nn_ringbuf_add(nn_ringbuf_t *buf, const char *str) { if (buf->n < buf->size) { buf->data[buf->n] = th_strdup(str); @@ -457,7 +457,7 @@ } -int writeBuf(nn_editbuf_t *buf, ssize_t pos, int ch) +int nn_editbuf_write(nn_editbuf_t *buf, ssize_t pos, int ch) { /* Check arguments */ if (buf->len+1 >= buf->size) return -3; @@ -473,7 +473,7 @@ } -int insertBuf(nn_editbuf_t *buf, ssize_t pos, int ch) +int nn_editbuf_insert(nn_editbuf_t *buf, ssize_t pos, int ch) { /* Check arguments */ if (buf->len+1 >= buf->size) return -3; @@ -491,7 +491,7 @@ } -int deleteBuf(nn_editbuf_t *buf, ssize_t pos) +int nn_editbuf_delete(nn_editbuf_t *buf, ssize_t pos) { /* Check arguments */ if (pos < 0) @@ -505,14 +505,14 @@ } -void clearBuf(nn_editbuf_t *buf) +void nn_editbuf_clear(nn_editbuf_t *buf) { buf->len = 0; buf->pos = 0; } -nn_editbuf_t * newBuf(ssize_t n) +nn_editbuf_t * nn_editbuf_new(ssize_t n) { nn_editbuf_t *res = th_calloc(1, sizeof(nn_editbuf_t)); @@ -523,7 +523,7 @@ } -void freeBuf(nn_editbuf_t *buf) +void nn_editbuf_free(nn_editbuf_t *buf) { if (buf) { th_free(buf->data); @@ -532,7 +532,7 @@ } -nn_editbuf_t * copyBuf(nn_editbuf_t *src) +nn_editbuf_t * nn_editbuf_copy(nn_editbuf_t *src) { nn_editbuf_t *res; @@ -540,7 +540,7 @@ if (src == NULL) return NULL; - if ((res = newBuf(src->size)) == NULL) + if ((res = nn_editbuf_new(src->size)) == NULL) return NULL; memcpy(res->data, src->data, src->size); @@ -550,7 +550,7 @@ } -void setBufPos(nn_editbuf_t *buf, ssize_t pos) +void nn_editbuf_setpos(nn_editbuf_t *buf, ssize_t pos) { /* Check arguments */ if (pos < 0) @@ -629,7 +629,7 @@ return -3; user->encname = th_strdup(encname); - user->name = doubleDecodeStr(encname); + user->name = nn_dbldecode_str(encname); if (user->encname == NULL || user->name == NULL) return -4;