comparison th_network.c @ 457:85fa3d333556

Actually, revert the boolean changes .. meh.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 02 Jan 2018 23:09:29 +0200
parents 347bfd3e017e
children e4ce60239d16
comparison
equal deleted inserted replaced
456:1bf886fa9db5 457:85fa3d333556
8 #include "th_network.h" 8 #include "th_network.h"
9 #include "th_string.h" 9 #include "th_string.h"
10 #include <errno.h> 10 #include <errno.h>
11 11
12 12
13 static bool th_network_inited = false; 13 static BOOL th_network_inited = FALSE;
14 static th_llist_t *th_conn_list = NULL; 14 static th_llist_t *th_conn_list = NULL;
15 15
16 16
17 enum 17 enum
18 { 18 {
112 112
113 return res; 113 return res;
114 } 114 }
115 115
116 116
117 bool th_base_conn_init(th_base_conn_t *base, ssize_t bufsize) 117 BOOL th_base_conn_init(th_base_conn_t *base, ssize_t bufsize)
118 { 118 {
119 // Allocate connection data buffer 119 // Allocate connection data buffer
120 base->bufsize = (bufsize <= 0) ? TH_CONNBUF_SIZE : bufsize; 120 base->bufsize = (bufsize <= 0) ? TH_CONNBUF_SIZE : bufsize;
121 if ((base->buf = th_malloc(base->bufsize)) == NULL) 121 if ((base->buf = th_malloc(base->bufsize)) == NULL)
122 return false; 122 return FALSE;
123 123
124 return true; 124 return TRUE;
125 } 125 }
126 126
127 127
128 th_conn_t * th_conn_new( 128 th_conn_t * th_conn_new(
129 void (*errfunc)(th_conn_t *conn, int err, const char *msg), 129 void (*errfunc)(th_conn_t *conn, int err, const char *msg),
148 148
149 return conn; 149 return conn;
150 } 150 }
151 151
152 152
153 static bool th_get_addr(struct in_addr *addr, struct hostent *hst) 153 static BOOL th_get_addr(struct in_addr *addr, struct hostent *hst)
154 { 154 {
155 if (hst != NULL) 155 if (hst != NULL)
156 { 156 {
157 *addr = *(struct in_addr *) (hst->h_addr_list[0]); 157 *addr = *(struct in_addr *) (hst->h_addr_list[0]);
158 return true; 158 return TRUE;
159 } 159 }
160 else 160 else
161 { 161 {
162 addr->s_addr = 0; 162 addr->s_addr = 0;
163 return false; 163 return FALSE;
164 } 164 }
165 } 165 }
166 166
167 167
168 int th_conn_set_proxy(th_conn_t *conn, int type, int port, const char *host, int auth_type) 168 int th_conn_set_proxy(th_conn_t *conn, int type, int port, const char *host, int auth_type)
318 th_conn_err(conn, err, 318 th_conn_err(conn, err,
319 "Invalid proxy settings for SOCKS 4, unsupported address type requested.\n"); 319 "Invalid proxy settings for SOCKS 4, unsupported address type requested.\n");
320 goto out; 320 goto out;
321 } 321 }
322 322
323 th_growbuf_puts(&buf, conn->proxy.userid, true); 323 th_growbuf_puts(&buf, conn->proxy.userid, TRUE);
324 if (conn->proxy.addr_type == TH_PROXY_ADDR_DOMAIN) 324 if (conn->proxy.addr_type == TH_PROXY_ADDR_DOMAIN)
325 th_growbuf_puts(&buf, host, true); 325 th_growbuf_puts(&buf, host, TRUE);
326 326
327 // Send request 327 // Send request
328 if ((err = th_conn_proxy_send(conn, &buf)) != THERR_OK) 328 if ((err = th_conn_proxy_send(conn, &buf)) != THERR_OK)
329 goto out; 329 goto out;
330 330
462 th_conn_msg(conn, THLOG_INFO, "Attempting SOCKS 5 user/pass authentication.\n"); 462 th_conn_msg(conn, THLOG_INFO, "Attempting SOCKS 5 user/pass authentication.\n");
463 th_growbuf_clear(&buf); 463 th_growbuf_clear(&buf);
464 464
465 th_growbuf_put_u8(&buf, 0x01); 465 th_growbuf_put_u8(&buf, 0x01);
466 th_growbuf_put_u8(&buf, strlen(conn->proxy.userid)); 466 th_growbuf_put_u8(&buf, strlen(conn->proxy.userid));
467 th_growbuf_puts(&buf, conn->proxy.userid, false); 467 th_growbuf_puts(&buf, conn->proxy.userid, FALSE);
468 th_growbuf_put_u8(&buf, strlen(conn->proxy.passwd)); 468 th_growbuf_put_u8(&buf, strlen(conn->proxy.passwd));
469 th_growbuf_puts(&buf, conn->proxy.passwd, false); 469 th_growbuf_puts(&buf, conn->proxy.passwd, FALSE);
470 470
471 // Send request 471 // Send request
472 if ((err = th_conn_proxy_send(conn, &buf)) != THERR_OK) 472 if ((err = th_conn_proxy_send(conn, &buf)) != THERR_OK)
473 goto out; 473 goto out;
474 474
826 826
827 return TH_CONN_NO_DATA; 827 return TH_CONN_NO_DATA;
828 } 828 }
829 829
830 830
831 bool th_conn_check(th_conn_t *conn) 831 BOOL th_conn_check(th_conn_t *conn)
832 { 832 {
833 if (conn == NULL) 833 if (conn == NULL)
834 return false; 834 return FALSE;
835 835
836 return conn->err == 0 && conn->status == TH_CONN_OPEN; 836 return conn->err == 0 && conn->status == TH_CONN_OPEN;
837 } 837 }
838 838
839 839
848 THERR("Could not initialize WinSock library (err=%d).\n", err); 848 THERR("Could not initialize WinSock library (err=%d).\n", err);
849 return THERR_INIT_FAIL; 849 return THERR_INIT_FAIL;
850 } 850 }
851 #endif 851 #endif
852 852
853 th_network_inited = true; 853 th_network_inited = TRUE;
854 854
855 th_conn_list = NULL; 855 th_conn_list = NULL;
856 856
857 return THERR_OK; 857 return THERR_OK;
858 } 858 }
874 #ifdef TH_PLAT_WINDOWS 874 #ifdef TH_PLAT_WINDOWS
875 WSACleanup(); 875 WSACleanup();
876 #endif 876 #endif
877 } 877 }
878 878
879 th_network_inited = false; 879 th_network_inited = FALSE;
880 } 880 }
881 881
882 882
883 bool th_conn_buf_check(th_conn_t *conn, size_t n) 883 BOOL th_conn_buf_check(th_conn_t *conn, size_t n)
884 { 884 {
885 return conn && (conn->base.ptr + n <= conn->base.in_ptr); 885 return conn && (conn->base.ptr + n <= conn->base.in_ptr);
886 } 886 }
887 887
888 888
889 bool th_conn_buf_skip(th_conn_t *conn, size_t n) 889 BOOL th_conn_buf_skip(th_conn_t *conn, size_t n)
890 { 890 {
891 if (th_conn_buf_check(conn, n)) 891 if (th_conn_buf_check(conn, n))
892 { 892 {
893 conn->base.ptr += n; 893 conn->base.ptr += n;
894 return true; 894 return TRUE;
895 } 895 }
896 else 896 else
897 return false; 897 return FALSE;
898 } 898 }
899 899
900 900
901 int th_conn_buf_strncmp(th_conn_t *conn, const char *str, const size_t n) 901 int th_conn_buf_strncmp(th_conn_t *conn, const char *str, const size_t n)
902 { 902 {