diff options
Diffstat (limited to 'tinyNET/src/tnet_proxy_plugin.c')
-rwxr-xr-x | tinyNET/src/tnet_proxy_plugin.c | 152 |
1 files changed, 80 insertions, 72 deletions
diff --git a/tinyNET/src/tnet_proxy_plugin.c b/tinyNET/src/tnet_proxy_plugin.c index dbcd143..1555dce 100755 --- a/tinyNET/src/tnet_proxy_plugin.c +++ b/tinyNET/src/tnet_proxy_plugin.c @@ -34,17 +34,17 @@ const tnet_proxy_node_plugin_def_t* __tnet_proxy_node_plugins[TNET_PROXY_NODE_MA tsk_bool_t tnet_proxy_node_is_nettransport_supported(enum tnet_proxy_type_e proxy_type, enum tnet_socket_type_e socket_type) { switch (proxy_type) { - case tnet_proxy_type_http: + case tnet_proxy_type_http: case tnet_proxy_type_https: - return TNET_SOCKET_TYPE_IS_STREAM(socket_type); - - case tnet_proxy_type_socks4: - case tnet_proxy_type_socks4a: - return TNET_SOCKET_TYPE_IS_STREAM(socket_type) && TNET_SOCKET_TYPE_IS_IPV4(socket_type); - case tnet_proxy_type_socks5: // SOCKS5 adds support for UDP and IPv6 - return TNET_SOCKET_TYPE_IS_STREAM(socket_type) || TNET_SOCKET_TYPE_IS_DGRAM(socket_type);// for now we don't support socks for UDP (just like a browser) - default: - return tsk_false; + return TNET_SOCKET_TYPE_IS_STREAM(socket_type); + + case tnet_proxy_type_socks4: + case tnet_proxy_type_socks4a: + return TNET_SOCKET_TYPE_IS_STREAM(socket_type) && TNET_SOCKET_TYPE_IS_IPV4(socket_type); + case tnet_proxy_type_socks5: // SOCKS5 adds support for UDP and IPv6 + return TNET_SOCKET_TYPE_IS_STREAM(socket_type) || TNET_SOCKET_TYPE_IS_DGRAM(socket_type);// for now we don't support socks for UDP (just like a browser) + default: + return tsk_false; } } @@ -61,12 +61,12 @@ int tnet_proxy_node_configure(tnet_proxy_node_t* self, ...) { va_list ap; int ret = 0; - + if (!self) { TSK_DEBUG_ERROR("Invalid parameter"); return -1; } - + va_start(ap, self); ret = tnet_proxy_node_configure_2(self, &ap); va_end(ap); @@ -77,73 +77,81 @@ int tnet_proxy_node_configure_2(tnet_proxy_node_t* self, va_list* app) { int ret = 0; tnet_proxy_node_param_type_t ptype; - + if (!self || !app) { TSK_DEBUG_ERROR("Invalid parameter"); return -1; } - + while ((ptype = va_arg(*app, tnet_proxy_node_param_type_t)) != tnet_proxy_node_param_type_null) { switch (ptype) { - case tnet_proxy_node_param_type_destination_address: - case tnet_proxy_node_param_type_proxy_address: { - // (const char*)(HOST_STR), (int)(PORT_INT) - const char* HOST_STR = va_arg(*app, const char*); - int PORT_INT = va_arg(*app, int); - if (PORT_INT < 1 || PORT_INT > 0xFFF) { - TSK_DEBUG_ERROR("Invalid value for port number: %d", PORT_INT); - ret = -3; - goto bail; - } - if (ptype == tnet_proxy_node_param_type_destination_address) { - tsk_strupdate(&self->dst_host, HOST_STR); - self->dst_port = (tnet_port_t)PORT_INT; - } - else { - tsk_strupdate(&self->proxy_host, HOST_STR); - self->proxy_port = (tnet_port_t)PORT_INT; - } - break; + case tnet_proxy_node_param_type_destination_address: + case tnet_proxy_node_param_type_proxy_address: { + // (const char*)(HOST_STR), (int)(PORT_INT) + const char* HOST_STR = va_arg(*app, const char*); + int PORT_INT = va_arg(*app, int); + if (PORT_INT < 1 || PORT_INT > 0xFFF) { + TSK_DEBUG_ERROR("Invalid value for port number: %d", PORT_INT); + ret = -3; + goto bail; } - case tnet_proxy_node_param_type_ipv6: { - /* (tsk_bool_t)(IPV6_BOOL) */ - self->ipv6 = va_arg(*app, tsk_bool_t); - break; + if (ptype == tnet_proxy_node_param_type_destination_address) { + tsk_strupdate(&self->dst_host, HOST_STR); + self->dst_port = (tnet_port_t)PORT_INT; } - case tnet_proxy_node_param_type_credentials: { - /* (const char*)(LOGIN_STR), (const char*)(PASSWORD_STR) */ - const char* LOGIN_STR = va_arg(*app, const char*); - const char* PASSWORD_STR = va_arg(*app, const char*); - tsk_strupdate(&self->login, LOGIN_STR); - tsk_strupdate(&self->password, PASSWORD_STR); - break; - } - case tnet_proxy_node_param_type_socket: { - /* (tnet_fd_t)(FD_FD), (enum tnet_socket_type_e)(type) */ - self->socket.fd = va_arg(*app, tnet_fd_t); - self->socket.type = va_arg(*app, enum tnet_socket_type_e); - break; + else { + tsk_strupdate(&self->proxy_host, HOST_STR); + self->proxy_port = (tnet_port_t)PORT_INT; } + break; + } + case tnet_proxy_node_param_type_ipv6: { + /* (tsk_bool_t)(IPV6_BOOL) */ + self->ipv6 = va_arg(*app, tsk_bool_t); + break; + } + case tnet_proxy_node_param_type_credentials: { + /* (const char*)(LOGIN_STR), (const char*)(PASSWORD_STR) */ + const char* LOGIN_STR = va_arg(*app, const char*); + const char* PASSWORD_STR = va_arg(*app, const char*); + tsk_strupdate(&self->login, LOGIN_STR); + tsk_strupdate(&self->password, PASSWORD_STR); + break; + } + case tnet_proxy_node_param_type_socket: { + /* (tnet_fd_t)(FD_FD), (enum tnet_socket_type_e)(type) */ + self->socket.fd = va_arg(*app, tnet_fd_t); + self->socket.type = va_arg(*app, enum tnet_socket_type_e); + break; + } #if TNET_UNDER_APPLE - case tnet_proxy_node_param_type_cfstreams: { - /* (CFReadStreamRef)(READ_CFSTREAM), (CFWriteStreamRef)(WRITE_CFSTREAM) */ - CFReadStreamRef READ_CFSTREAM = va_arg(*app, CFReadStreamRef); - CFWriteStreamRef WRITE_CFSTREAM = va_arg(*app, CFWriteStreamRef); - if (self->cf_read_stream) CFRelease(self->cf_read_stream), self->cf_read_stream = tsk_null; - if (self->cf_write_stream) CFRelease(self->cf_write_stream), self->cf_write_stream = tsk_null; - if (READ_CFSTREAM) self->cf_read_stream = (CFReadStreamRef)CFRetain(READ_CFSTREAM); - if (WRITE_CFSTREAM) self->cf_write_stream = (CFWriteStreamRef)CFRetain(WRITE_CFSTREAM); - break; + case tnet_proxy_node_param_type_cfstreams: { + /* (CFReadStreamRef)(READ_CFSTREAM), (CFWriteStreamRef)(WRITE_CFSTREAM) */ + CFReadStreamRef READ_CFSTREAM = va_arg(*app, CFReadStreamRef); + CFWriteStreamRef WRITE_CFSTREAM = va_arg(*app, CFWriteStreamRef); + if (self->cf_read_stream) { + CFRelease(self->cf_read_stream), self->cf_read_stream = tsk_null; } -#endif /* TNET_UNDER_APPLE */ - default: { - TSK_DEBUG_ERROR("%d not valid param type", ptype); - ret = -2; - goto bail; + if (self->cf_write_stream) { + CFRelease(self->cf_write_stream), self->cf_write_stream = tsk_null; + } + if (READ_CFSTREAM) { + self->cf_read_stream = (CFReadStreamRef)CFRetain(READ_CFSTREAM); } + if (WRITE_CFSTREAM) { + self->cf_write_stream = (CFWriteStreamRef)CFRetain(WRITE_CFSTREAM); + } + break; + } +#endif /* TNET_UNDER_APPLE */ + default: { + TSK_DEBUG_ERROR("%d not valid param type", ptype); + ret = -2; + goto bail; + } } } - + bail: return ret; } @@ -210,16 +218,16 @@ int tnet_proxy_node_plugin_register(const tnet_proxy_node_plugin_def_t* plugin) TSK_DEBUG_ERROR("Invalid parameter"); return -1; } - + /* add or replace the plugin */ for (i = 0; i<TNET_PROXY_NODE_MAX_PLUGINS; i++) { - if (!__tnet_proxy_node_plugins[i] || (__tnet_proxy_node_plugins[i] == plugin)){ + if (!__tnet_proxy_node_plugins[i] || (__tnet_proxy_node_plugins[i] == plugin)) { __tnet_proxy_node_plugins[i] = plugin; TSK_DEBUG_INFO("Register network proxy node plugin: %s", plugin->desc); return 0; } } - + TSK_DEBUG_ERROR("There are already %d network proxy node plugins.", TNET_PROXY_NODE_MAX_PLUGINS); return -2; } @@ -232,7 +240,7 @@ int tnet_proxy_node_plugin_unregister(const tnet_proxy_node_plugin_def_t* plugin TSK_DEBUG_ERROR("Invalid Parameter"); return -1; } - + /* find the plugin to unregister */ for (i = 0; i<TNET_PROXY_NODE_MAX_PLUGINS && __tnet_proxy_node_plugins[i]; i++) { if (__tnet_proxy_node_plugins[i] == plugin) { @@ -242,7 +250,7 @@ int tnet_proxy_node_plugin_unregister(const tnet_proxy_node_plugin_def_t* plugin break; } } - + /* compact */ if (found) { for (; i<(TNET_PROXY_NODE_MAX_PLUGINS - 1); i++) { @@ -262,8 +270,8 @@ tsk_size_t tnet_proxy_node_plugin_registry_count() { tsk_size_t count; for(count = 0; - count < TNET_PROXY_NODE_MAX_PLUGINS && __tnet_proxy_node_plugins[count]; - ++count) ; + count < TNET_PROXY_NODE_MAX_PLUGINS && __tnet_proxy_node_plugins[count]; + ++count) ; return count; } |