Mercurial > hg > nnchat
annotate libnnchat.h @ 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 | 745f670068dc |
children | 1e0bf7b4fd41 |
rev | line source |
---|---|
62
ff5d74f0d428
Moved some functions to "libnnchat".
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1 /* |
ff5d74f0d428
Moved some functions to "libnnchat".
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2 * NNChat - Custom chat client for NewbieNudes.com chatrooms |
ff5d74f0d428
Moved some functions to "libnnchat".
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
3 * Written by Matti 'ccr' Hämäläinen |
ff5d74f0d428
Moved some functions to "libnnchat".
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
4 * (C) Copyright 2008 Tecnic Software productions (TNSP) |
ff5d74f0d428
Moved some functions to "libnnchat".
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
5 */ |
ff5d74f0d428
Moved some functions to "libnnchat".
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
6 #ifndef LIBNNCHAT_H |
ff5d74f0d428
Moved some functions to "libnnchat".
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
7 #define LIBNNCHAT_H |
ff5d74f0d428
Moved some functions to "libnnchat".
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
8 |
ff5d74f0d428
Moved some functions to "libnnchat".
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
9 #include <stdio.h> |
ff5d74f0d428
Moved some functions to "libnnchat".
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
10 #include <unistd.h> |
64
6a3a917303e4
Some random cleanups, bring back WinSock support.
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
11 #ifdef __WIN32 |
68
3ab7751fdad1
MingW compatibility, with one ugly kludge.
Matti Hamalainen <ccr@tnsp.org>
parents:
65
diff
changeset
|
12 #include <windows.h> |
64
6a3a917303e4
Some random cleanups, bring back WinSock support.
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
13 #include <winsock.h> |
6a3a917303e4
Some random cleanups, bring back WinSock support.
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
14 #else |
62
ff5d74f0d428
Moved some functions to "libnnchat".
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
15 #include <sys/socket.h> |
ff5d74f0d428
Moved some functions to "libnnchat".
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
16 #include <arpa/inet.h> |
ff5d74f0d428
Moved some functions to "libnnchat".
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
17 #include <netdb.h> |
64
6a3a917303e4
Some random cleanups, bring back WinSock support.
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
18 #endif |
6a3a917303e4
Some random cleanups, bring back WinSock support.
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
19 #include <sys/types.h> |
89
c2d916b340bf
Change some typedef names; Add struct for user list handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
78
diff
changeset
|
20 #include <time.h> |
62
ff5d74f0d428
Moved some functions to "libnnchat".
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
21 #include <errno.h> |
ff5d74f0d428
Moved some functions to "libnnchat".
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
22 #include "th_string.h" |
ff5d74f0d428
Moved some functions to "libnnchat".
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
23 |
ff5d74f0d428
Moved some functions to "libnnchat".
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
24 #define SET_BUFSIZE (4096) |
71
3a23c2adfb78
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
68
diff
changeset
|
25 #define SET_ALLOC_SIZE (128) |
62
ff5d74f0d428
Moved some functions to "libnnchat".
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
26 |
65
e763ef5cfd53
Move more functions to libnnchat.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
27 typedef struct { |
71
3a23c2adfb78
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
68
diff
changeset
|
28 char **data; |
3a23c2adfb78
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
68
diff
changeset
|
29 size_t n, size; |
89
c2d916b340bf
Change some typedef names; Add struct for user list handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
78
diff
changeset
|
30 } nn_ringbuf_t; |
65
e763ef5cfd53
Move more functions to libnnchat.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
31 |
e763ef5cfd53
Move more functions to libnnchat.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
32 typedef struct { |
71
3a23c2adfb78
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
68
diff
changeset
|
33 ssize_t pos, len, size; |
3a23c2adfb78
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
68
diff
changeset
|
34 char *data; |
89
c2d916b340bf
Change some typedef names; Add struct for user list handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
78
diff
changeset
|
35 } nn_editbuf_t; |
c2d916b340bf
Change some typedef names; Add struct for user list handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
78
diff
changeset
|
36 |
c2d916b340bf
Change some typedef names; Add struct for user list handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
78
diff
changeset
|
37 typedef struct { |
c2d916b340bf
Change some typedef names; Add struct for user list handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
78
diff
changeset
|
38 char *name, *encname; |
c2d916b340bf
Change some typedef names; Add struct for user list handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
78
diff
changeset
|
39 time_t lastspoke, joined; |
c2d916b340bf
Change some typedef names; Add struct for user list handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
78
diff
changeset
|
40 } nn_user_t; |
65
e763ef5cfd53
Move more functions to libnnchat.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
41 |
e763ef5cfd53
Move more functions to libnnchat.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
42 |
71
3a23c2adfb78
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
68
diff
changeset
|
43 int openConnection(struct in_addr *addr, const int port); |
3a23c2adfb78
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
68
diff
changeset
|
44 void closeConnection(const int sock); |
3a23c2adfb78
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
68
diff
changeset
|
45 BOOL sendToSocket(const int sock, char *buf, const size_t bufLen); |
3a23c2adfb78
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
68
diff
changeset
|
46 BOOL sendUserMsg(const int sock, const char *user, const char *fmt, ...); |
62
ff5d74f0d428
Moved some functions to "libnnchat".
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
47 |
89
c2d916b340bf
Change some typedef names; Add struct for user list handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
78
diff
changeset
|
48 int addUser(nn_user_t **list, char *encname); |
c2d916b340bf
Change some typedef names; Add struct for user list handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
78
diff
changeset
|
49 int freeUser(nn_user_t *); |
c2d916b340bf
Change some typedef names; Add struct for user list handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
78
diff
changeset
|
50 int freeUserList(nn_user_t *); |
62
ff5d74f0d428
Moved some functions to "libnnchat".
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
51 |
71
3a23c2adfb78
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
68
diff
changeset
|
52 char * encodeStr1(const char *str); |
3a23c2adfb78
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
68
diff
changeset
|
53 char * decodeStr1(const char *str); |
3a23c2adfb78
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
68
diff
changeset
|
54 char * encodeStr2(const char *str); |
3a23c2adfb78
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
68
diff
changeset
|
55 char * decodeStr2(const char *str); |
3a23c2adfb78
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
68
diff
changeset
|
56 char * stripXMLTags(const char *str); |
78
745f670068dc
Add functions to simplify code.
Matti Hamalainen <ccr@tnsp.org>
parents:
71
diff
changeset
|
57 char * doubleDecodeStr(const char *str); |
745f670068dc
Add functions to simplify code.
Matti Hamalainen <ccr@tnsp.org>
parents:
71
diff
changeset
|
58 char * doubleEncodeStr(const char *str); |
65
e763ef5cfd53
Move more functions to libnnchat.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
59 |
89
c2d916b340bf
Change some typedef names; Add struct for user list handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
78
diff
changeset
|
60 |
c2d916b340bf
Change some typedef names; Add struct for user list handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
78
diff
changeset
|
61 nn_ringbuf_t * newRingBuf(const size_t size); |
c2d916b340bf
Change some typedef names; Add struct for user list handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
78
diff
changeset
|
62 void freeRingBuf(nn_ringbuf_t *buf); |
c2d916b340bf
Change some typedef names; Add struct for user list handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
78
diff
changeset
|
63 void addRingBuf(nn_ringbuf_t *buf, const char *str); |
65
e763ef5cfd53
Move more functions to libnnchat.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
64 |
89
c2d916b340bf
Change some typedef names; Add struct for user list handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
78
diff
changeset
|
65 int writeBuf(nn_editbuf_t *buf, ssize_t pos, int ch); |
c2d916b340bf
Change some typedef names; Add struct for user list handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
78
diff
changeset
|
66 int insertBuf(nn_editbuf_t *buf, ssize_t pos, int ch); |
c2d916b340bf
Change some typedef names; Add struct for user list handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
78
diff
changeset
|
67 int deleteBuf(nn_editbuf_t *buf, ssize_t pos); |
c2d916b340bf
Change some typedef names; Add struct for user list handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
78
diff
changeset
|
68 void clearBuf(nn_editbuf_t *buf); |
c2d916b340bf
Change some typedef names; Add struct for user list handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
78
diff
changeset
|
69 nn_editbuf_t * newBuf(ssize_t n); |
c2d916b340bf
Change some typedef names; Add struct for user list handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
78
diff
changeset
|
70 void freeBuf(nn_editbuf_t *buf); |
c2d916b340bf
Change some typedef names; Add struct for user list handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
78
diff
changeset
|
71 nn_editbuf_t * copyBuf(nn_editbuf_t *src); |
c2d916b340bf
Change some typedef names; Add struct for user list handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
78
diff
changeset
|
72 void setBufPos(nn_editbuf_t *buf, ssize_t pos); |
62
ff5d74f0d428
Moved some functions to "libnnchat".
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
73 |
ff5d74f0d428
Moved some functions to "libnnchat".
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
74 |
ff5d74f0d428
Moved some functions to "libnnchat".
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
75 #endif |