changeset 89:c2d916b340bf

Change some typedef names; Add struct for user list handling.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 06 May 2009 05:05:02 +0300
parents 7bf0915c965e
children 1e0bf7b4fd41
files libnnchat.c libnnchat.h nnchat.c
diffstat 3 files changed, 41 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/libnnchat.c	Mon Apr 27 07:31:10 2009 +0300
+++ b/libnnchat.c	Wed May 06 05:05:02 2009 +0300
@@ -365,9 +365,9 @@
 }
 
 
-ringbuf_t * newRingBuf(const size_t size)
+nn_ringbuf_t * newRingBuf(const size_t size)
 {
-    ringbuf_t *res = th_calloc(1, sizeof(ringbuf_t));
+    nn_ringbuf_t *res = th_calloc(1, sizeof(nn_ringbuf_t));
     
     res->data = (char **) th_malloc(size * sizeof(char *));
     res->size = size;
@@ -377,7 +377,7 @@
 }
 
 
-void freeRingBuf(ringbuf_t *buf)
+void freeRingBuf(nn_ringbuf_t *buf)
 {
     size_t i;
     
@@ -389,7 +389,7 @@
 }
 
 
-void addRingBuf(ringbuf_t *buf, const char *str)
+void addRingBuf(nn_ringbuf_t *buf, const char *str)
 {
     if (buf->n < buf->size) {
         buf->data[buf->n] = th_strdup(str);
@@ -402,7 +402,7 @@
 }
 
 
-int writeBuf(editbuf_t *buf, ssize_t pos, int ch)
+int writeBuf(nn_editbuf_t *buf, ssize_t pos, int ch)
 {
     /* Check arguments */
     if (buf->len+1 >= buf->size) return -3;
@@ -418,7 +418,7 @@
 }
 
 
-int insertBuf(editbuf_t *buf, ssize_t pos, int ch)
+int insertBuf(nn_editbuf_t *buf, ssize_t pos, int ch)
 {
     /* Check arguments */
     if (buf->len+1 >= buf->size) return -3;
@@ -436,7 +436,7 @@
 }
 
 
-int deleteBuf(editbuf_t *buf, ssize_t pos)
+int deleteBuf(nn_editbuf_t *buf, ssize_t pos)
 {
     /* Check arguments */
     if (pos < 0)
@@ -450,16 +450,16 @@
 }
 
 
-void clearBuf(editbuf_t *buf)
+void clearBuf(nn_editbuf_t *buf)
 {
     buf->len = 0;
     buf->pos = 0;
 }
 
 
-editbuf_t * newBuf(ssize_t n)
+nn_editbuf_t * newBuf(ssize_t n)
 {
-    editbuf_t *res = th_calloc(1, sizeof(editbuf_t));
+    nn_editbuf_t *res = th_calloc(1, sizeof(nn_editbuf_t));
     
     res->data = (char *) th_malloc(n);
     res->size = n;
@@ -468,7 +468,7 @@
 }
 
 
-void freeBuf(editbuf_t *buf)
+void freeBuf(nn_editbuf_t *buf)
 {
     if (buf) {
         th_free(buf->data);
@@ -477,9 +477,9 @@
 }
 
 
-editbuf_t * copyBuf(editbuf_t *src)
+nn_editbuf_t * copyBuf(nn_editbuf_t *src)
 {
-    editbuf_t *res;
+    nn_editbuf_t *res;
     
     assert(src != NULL);
     
@@ -495,7 +495,7 @@
 }
 
 
-void setBufPos(editbuf_t *buf, ssize_t pos)
+void setBufPos(nn_editbuf_t *buf, ssize_t pos)
 {
     /* Check arguments */
     if (pos < 0)
--- a/libnnchat.h	Mon Apr 27 07:31:10 2009 +0300
+++ b/libnnchat.h	Wed May 06 05:05:02 2009 +0300
@@ -17,7 +17,7 @@
 #include <netdb.h>
 #endif
 #include <sys/types.h>
-
+#include <time.h>
 #include <errno.h>
 #include "th_string.h"
 
@@ -27,12 +27,17 @@
 typedef struct {
     char **data;
     size_t n, size;
-} ringbuf_t;
+} nn_ringbuf_t;
 
 typedef struct {
     ssize_t pos, len, size;
     char *data;
-} editbuf_t;
+} nn_editbuf_t;
+
+typedef struct {
+    char *name, *encname;
+    time_t lastspoke, joined;
+} nn_user_t;
 
 
 int         openConnection(struct in_addr *addr, const int port);
@@ -40,28 +45,31 @@
 BOOL        sendToSocket(const int sock, char *buf, const size_t bufLen);
 BOOL        sendUserMsg(const int sock, const char *user, const char *fmt, ...);
 
+int         addUser(nn_user_t **list, char *encname);
+int         freeUser(nn_user_t *);
+int         freeUserList(nn_user_t *);
 
 char *      encodeStr1(const char *str);
 char *      decodeStr1(const char *str);
 char *      encodeStr2(const char *str);
 char *      decodeStr2(const char *str);
 char *      stripXMLTags(const char *str);
-
 char *      doubleDecodeStr(const char *str);
 char *      doubleEncodeStr(const char *str);
 
-ringbuf_t * newRingBuf(const size_t size);
-void        freeRingBuf(ringbuf_t *buf);
-void        addRingBuf(ringbuf_t *buf, const char *str);
+
+nn_ringbuf_t * newRingBuf(const size_t size);
+void        freeRingBuf(nn_ringbuf_t *buf);
+void        addRingBuf(nn_ringbuf_t *buf, const char *str);
 
-int         writeBuf(editbuf_t *buf, ssize_t pos, int ch);
-int         insertBuf(editbuf_t *buf, ssize_t pos, int ch);
-int         deleteBuf(editbuf_t *buf, ssize_t pos);
-void        clearBuf(editbuf_t *buf);
-editbuf_t * newBuf(ssize_t n);
-void        freeBuf(editbuf_t *buf);
-editbuf_t * copyBuf(editbuf_t *src);
-void        setBufPos(editbuf_t *buf, ssize_t pos);
+int         writeBuf(nn_editbuf_t *buf, ssize_t pos, int ch);
+int         insertBuf(nn_editbuf_t *buf, ssize_t pos, int ch);
+int         deleteBuf(nn_editbuf_t *buf, ssize_t pos);
+void        clearBuf(nn_editbuf_t *buf);
+nn_editbuf_t * newBuf(ssize_t n);
+void        freeBuf(nn_editbuf_t *buf);
+nn_editbuf_t * copyBuf(nn_editbuf_t *src);
+void        setBufPos(nn_editbuf_t *buf, ssize_t pos);
 
 
 #endif
--- a/nnchat.c	Mon Apr 27 07:31:10 2009 +0300
+++ b/nnchat.c	Wed May 06 05:05:02 2009 +0300
@@ -41,6 +41,7 @@
         *editWin = NULL;
 BOOL    setPrvMode = FALSE;
 
+
 /* Arguments
  */
 optarg_t optList[] = {
@@ -223,7 +224,7 @@
     wrefresh(statusWin);
 }
 
-void printEditBuf(char *str, editbuf_t *buf)
+void printEditBuf(char *str, nn_editbuf_t *buf)
 {
     if (statusWin == NULL || buf == NULL) return;
 
@@ -600,8 +601,8 @@
     struct timeval tv;
     fd_set sockfds;
     char *tmpStr;
-    editbuf_t *editBuf = newBuf(SET_BUFSIZE);
-    editbuf_t *histBuf[SET_MAX_HISTORY+2];
+    nn_editbuf_t *editBuf = newBuf(SET_BUFSIZE);
+    nn_editbuf_t *histBuf[SET_MAX_HISTORY+2];
     int histPos = 0, histMax = 0;
     
     memset(histBuf, 0, sizeof(histBuf));