comparison libnnchat.h @ 330:8e509d6546d3

Move nn_strtuple_* functions to libnnchat.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 14 Jun 2011 12:59:03 +0300
parents a8bda904846c
children b54c8545dcb0
comparison
equal deleted inserted replaced
329:c0988ab45afd 330:8e509d6546d3
30 #define NN_CONNBUF_SIZE (64 * 1024) 30 #define NN_CONNBUF_SIZE (64 * 1024)
31 #define NN_NUM_BUCKETS (256) 31 #define NN_NUM_BUCKETS (256)
32 #define NN_DELAY_USEC (15 * 1000) 32 #define NN_DELAY_USEC (15 * 1000)
33 #define NN_BACKBUF_LEN (512) /* Backbuffer size (in lines) */ 33 #define NN_BACKBUF_LEN (512) /* Backbuffer size (in lines) */
34 34
35 typedef struct {
36 ssize_t pos, len, size;
37 char *data;
38 } nn_editbuf_t;
39
40
41 typedef struct _nn_user_t {
42 char *name;
43 time_t lastspoke, joined;
44 struct _nn_user_t *next;
45 } nn_user_t;
46
47
48 typedef struct {
49 nn_user_t *buckets[NN_NUM_BUCKETS];
50 } nn_userhash_t;
51
52 enum { 35 enum {
53 NN_CONN_UNINIT = 0, 36 NN_CONN_UNINIT = 0,
54 NN_CONN_OPEN, 37 NN_CONN_OPEN,
55 NN_CONN_CLOSED 38 NN_CONN_CLOSED
56 }; 39 };
70 char buf[NN_CONNBUF_SIZE + 16]; 53 char buf[NN_CONNBUF_SIZE + 16];
71 char *ptr; 54 char *ptr;
72 ssize_t got; 55 ssize_t got;
73 } nn_conn_t; 56 } nn_conn_t;
74 57
75
76 typedef struct {
77 qringbuf_t *data; /* "Backbuffer" data for this window */
78 int pos; /* Current position in the window, 0 = real time */
79 BOOL dirty;
80
81 char *id; /* Chatter ID, NULL = main window */
82 int num; /* Window number */
83
84 char *buf;
85 size_t len, bufsize;
86 size_t chlen;
87 } nn_window_t;
88
89
90 const char *nn_get_errstr(int err); 58 const char *nn_get_errstr(int err);
91 BOOL nn_network_init(void); 59 BOOL nn_network_init(void);
92 void nn_network_close(void); 60 void nn_network_close(void);
93 61
94 nn_conn_t * nn_conn_open(struct in_addr *addr, const int port); 62 nn_conn_t * nn_conn_open(struct in_addr *addr, const int port);
96 BOOL nn_conn_pull(nn_conn_t *); 64 BOOL nn_conn_pull(nn_conn_t *);
97 BOOL nn_conn_send_buf(nn_conn_t *, const char *buf, const size_t len); 65 BOOL nn_conn_send_buf(nn_conn_t *, const char *buf, const size_t len);
98 BOOL nn_conn_send_msg(nn_conn_t *, const char *user, const char *fmt, ...); 66 BOOL nn_conn_send_msg(nn_conn_t *, const char *user, const char *fmt, ...);
99 BOOL nn_conn_check(nn_conn_t *); 67 BOOL nn_conn_check(nn_conn_t *);
100 68
69
70 typedef struct _nn_user_t {
71 char *name;
72 time_t lastspoke, joined;
73 struct _nn_user_t *next;
74 } nn_user_t;
75
76 typedef struct {
77 nn_user_t *buckets[NN_NUM_BUCKETS];
78 } nn_userhash_t;
101 79
102 nn_userhash_t *nn_userhash_new(void); 80 nn_userhash_t *nn_userhash_new(void);
103 nn_user_t * nn_userhash_foreach(const nn_userhash_t *, int (*func)(const nn_user_t *)); 81 nn_user_t * nn_userhash_foreach(const nn_userhash_t *, int (*func)(const nn_user_t *));
104 nn_user_t * nn_user_match(const nn_userhash_t *list, const char *str, const char *current, BOOL again); 82 nn_user_t * nn_user_match(const nn_userhash_t *list, const char *str, const char *current, BOOL again);
105 int nn_userhash_insert(nn_userhash_t *, const char *name); 83 int nn_userhash_insert(nn_userhash_t *, const char *name);
121 99
122 char * nn_username_encode(char *str); 100 char * nn_username_encode(char *str);
123 char * nn_username_decode(char *str); 101 char * nn_username_decode(char *str);
124 102
125 103
104 typedef struct {
105 ssize_t pos, len, size;
106 char *data;
107 } nn_editbuf_t;
108
126 int nn_editbuf_write(nn_editbuf_t *buf, ssize_t pos, int ch); 109 int nn_editbuf_write(nn_editbuf_t *buf, ssize_t pos, int ch);
127 int nn_editbuf_insert(nn_editbuf_t *buf, ssize_t pos, int ch); 110 int nn_editbuf_insert(nn_editbuf_t *buf, ssize_t pos, int ch);
128 int nn_editbuf_delete(nn_editbuf_t *buf, ssize_t pos); 111 int nn_editbuf_delete(nn_editbuf_t *buf, ssize_t pos);
129 void nn_editbuf_clear(nn_editbuf_t *buf); 112 void nn_editbuf_clear(nn_editbuf_t *buf);
130 nn_editbuf_t * nn_editbuf_new(ssize_t n); 113 nn_editbuf_t * nn_editbuf_new(ssize_t n);
132 nn_editbuf_t * nn_editbuf_copy(nn_editbuf_t *src); 115 nn_editbuf_t * nn_editbuf_copy(nn_editbuf_t *src);
133 void nn_editbuf_setpos(nn_editbuf_t *buf, ssize_t pos); 116 void nn_editbuf_setpos(nn_editbuf_t *buf, ssize_t pos);
134 char * nn_editbuf_get_string(nn_editbuf_t *buf, ssize_t start, ssize_t end); 117 char * nn_editbuf_get_string(nn_editbuf_t *buf, ssize_t start, ssize_t end);
135 118
136 119
120 typedef struct {
121 qringbuf_t *data; /* "Backbuffer" data for this window */
122 int pos; /* Current position in the window, 0 = real time */
123 BOOL dirty;
124
125 char *id; /* Chatter ID, NULL = main window */
126 int num; /* Window number */
127
128 char *buf;
129 size_t len, bufsize;
130 size_t chlen;
131 } nn_window_t;
132
137 nn_window_t *nn_window_new(const char *); 133 nn_window_t *nn_window_new(const char *);
138 void nn_window_free(nn_window_t *); 134 void nn_window_free(nn_window_t *);
139 135
136
137 typedef struct {
138 size_t len;
139 char *str;
140 } nn_strtuple_t;
141
142
143 nn_strtuple_t *nn_strtuple_new(size_t, char *);
144 void nn_strtuple_free(nn_strtuple_t *);
145
140 #endif 146 #endif