annotate th_network.h @ 121:8c39e8e90dbd

More work on proxy handling.
author Matti Hamalainen <ccr@tnsp.org>
date Sun, 22 Jun 2014 02:12:17 +0300
parents bfae4758fa6f
children aa2d608fb3f3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
102
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 /*
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
2 * Simple TCP network connection handling
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
3 * Programmed and designed by Matti 'ccr' Hamalainen
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
4 * (C) Copyright 2013-2014 Tecnic Software productions (TNSP)
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
5 *
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
6 * Please read file 'COPYING' for information on license and distribution.
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7 */
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8 #ifndef TH_NETWORK_H
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
9 #define TH_NETWORK_H
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
10
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
11 #include <stdio.h>
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
12 #include <unistd.h>
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
13 #include "th_types.h"
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
14 #include "th_util.h"
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
15
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
16
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17 #ifdef __WIN32
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
18 #define __OBJC_BOOL // A nasty hack
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
19 #include <windows.h>
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
20 #include <winsock.h>
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
21 typedef uint16_t in_port_t;
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
22 typedef uint32_t in_addr_t;
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
23 #else
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
24 #include <sys/select.h>
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
25 #include <sys/socket.h>
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
26 #ifdef HAVE_NETINET_IN_H
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
27 #include <netinet/in.h>
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
28 #endif
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
29 #include <arpa/inet.h>
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
30 #include <netdb.h>
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
31 #endif
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
32
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
33
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
34 #ifdef __cplusplus
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
35 extern "C" {
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
36 #endif
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
37
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
38 /* Global defines
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
39 */
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
40 #define TH_CONNBUF_SIZE (64 * 1024)
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
41 #define TH_DELAY_USEC (15 * 1000)
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
42 #define TH_DUMP_BYTES 16
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
43
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
44
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
45 enum
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
46 {
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
47 TH_CONN_UNINIT = 0,
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
48 TH_CONN_PROXY_NEG,
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
49 TH_CONN_OPEN,
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
50 TH_CONN_CLOSED,
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
51
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
52 TH_CONN_ERROR,
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
53 TH_CONN_DATA_AVAIL,
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
54 TH_CONN_NO_DATA,
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
55 };
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
56
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
57 enum
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
58 {
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
59 TH_PROXY_NONE = 0,
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
60 TH_PROXY_SOCKS4,
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
61 TH_PROXY_SOCKS4A,
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
62 TH_PROXY_SOCKS5,
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
63
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
64 TH_PROXY_LAST
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
65 };
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
66
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
67 enum
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
68 {
121
8c39e8e90dbd More work on proxy handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
69 TH_PROXY_ADDR_IPV4 = 0,
8c39e8e90dbd More work on proxy handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
70 TH_PROXY_ADDR_DOMAIN,
8c39e8e90dbd More work on proxy handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
71 TH_PROXY_ADDR_IPV6,
8c39e8e90dbd More work on proxy handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
72 };
8c39e8e90dbd More work on proxy handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
73
8c39e8e90dbd More work on proxy handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
74 enum
8c39e8e90dbd More work on proxy handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
75 {
102
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
76 TH_PROXY_AUTH_NONE,
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
77 TH_PROXY_AUTH_USER,
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
78 };
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
79
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
80 enum
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
81 {
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
82 TH_PROXY_CMD_CONNECT = 1,
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
83 TH_PROXY_CMD_BIND = 2,
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
84 TH_PROXY_CMD_ASSOC_UDP = 3,
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
85 };
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
86
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
87
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
88 typedef struct _th_conn_t
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
89 {
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
90 // Proxy settings and data
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
91 struct
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
92 {
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
93 char *host;
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
94 struct hostent *hst;
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
95 int type, auth_type;
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
96 int port;
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
97 struct in_addr addr;
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
98 char *userid, *passwd;
121
8c39e8e90dbd More work on proxy handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
99 int mode, addr_type;
102
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
100 } proxy;
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
101
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
102 // Target host data
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
103 char *host;
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
104 struct hostent *hst;
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
105 int port;
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
106
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
107 // Socket data
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
108 int socket;
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
109 struct in_addr addr;
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
110 fd_set sockfds;
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
111
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
112 // Error handling and status message functors
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
113 void (*errfunc)(struct _th_conn_t *conn, int err, const char *msg);
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
114 void (*msgfunc)(struct _th_conn_t *conn, int loglevel, const char *msg);
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
115
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
116 int err;
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
117 int status;
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
118
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
119 // Data buffer
103
f7bec3f7181d Change connection creation API to specify incoming buffer size.
Matti Hamalainen <ccr@tnsp.org>
parents: 102
diff changeset
120 char *buf, *ptr, *in_ptr;
f7bec3f7181d Change connection creation API to specify incoming buffer size.
Matti Hamalainen <ccr@tnsp.org>
parents: 102
diff changeset
121 ssize_t bufsize, got_bytes, total_bytes;
102
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
122
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
123 void *node;
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
124 } th_conn_t;
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
125
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
126
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
127 int th_network_init();
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
128 void th_network_close(void);
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
129
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
130 struct hostent *th_resolve_host(th_conn_t *conn, const char *name);
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
131 th_conn_t * th_conn_new(
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
132 void (*errfunc)(th_conn_t *conn, int err, const char *msg),
103
f7bec3f7181d Change connection creation API to specify incoming buffer size.
Matti Hamalainen <ccr@tnsp.org>
parents: 102
diff changeset
133 void (*msgfunc)(th_conn_t *conn, int loglevel, const char *msg),
f7bec3f7181d Change connection creation API to specify incoming buffer size.
Matti Hamalainen <ccr@tnsp.org>
parents: 102
diff changeset
134 ssize_t bufsize);
102
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
135
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
136 void th_conn_err(th_conn_t *conn, int err, const char *fmt, ...);
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
137 void th_conn_msg(th_conn_t *conn, int loglevel, const char *fmt, ...);
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
138
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
139 int th_conn_set_proxy(th_conn_t *conn, int type, int port, const char *host, int auth_type);
121
8c39e8e90dbd More work on proxy handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
140 int th_conn_set_proxy_mode(th_conn_t *conn, const int mode);
8c39e8e90dbd More work on proxy handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
141 int th_conn_set_proxy_addr_type(th_conn_t *conn, const int atype);
102
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
142 int th_conn_set_proxy_auth_user(th_conn_t *conn, const char *userid, const char *passwd);
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
143 int th_conn_open(th_conn_t *conn, const int port, const char *host);
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
144 int th_conn_close(th_conn_t *);
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
145 void th_conn_free(th_conn_t *);
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
146 void th_conn_reset(th_conn_t *);
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
147
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
148 int th_conn_pull(th_conn_t *);
116
bc540c5bfaf9 More work on network module.
Matti Hamalainen <ccr@tnsp.org>
parents: 105
diff changeset
149 int th_conn_send_buf(th_conn_t *, const void *buf, const size_t len);
117
bfae4758fa6f More work on network module.
Matti Hamalainen <ccr@tnsp.org>
parents: 116
diff changeset
150 int th_conn_send_growbuf(th_conn_t *, th_growbuf_t *buf);
102
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
151 BOOL th_conn_check(th_conn_t *);
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
152
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
153
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
154 BOOL th_conn_buf_check(th_conn_t *conn, size_t n);
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
155 BOOL th_conn_buf_skip(th_conn_t *conn, size_t n);
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
156 int th_conn_buf_strncmp(th_conn_t *conn, const char *str, const size_t n);
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
157 int th_conn_buf_strcmp(th_conn_t *conn, const char *str);
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
158 char * th_conn_buf_strstr(th_conn_t *conn, const char *str);
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
159
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
160 void th_conn_dump_buffer(FILE *f, th_conn_t *conn);
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
161
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
162
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
163 #ifdef __cplusplus
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
164 }
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
165 #endif
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
166 #endif /* TH_NETWORK_H */