diff options
author | Mamadou DIOP <bossiel@yahoo.fr> | 2015-08-17 01:56:35 +0200 |
---|---|---|
committer | Mamadou DIOP <bossiel@yahoo.fr> | 2015-08-17 01:56:35 +0200 |
commit | 631fffee8a28b1bec5ed1f1d26a20e0135967f99 (patch) | |
tree | 74afe3bf3efe15aa82bcd0272b2b0f4d48c2d837 /tinyNET/test | |
parent | 7908865936604036e6f200f1b5e069f8752f3a3a (diff) | |
download | doubango-631fffee8a28b1bec5ed1f1d26a20e0135967f99.zip doubango-631fffee8a28b1bec5ed1f1d26a20e0135967f99.tar.gz |
-
Diffstat (limited to 'tinyNET/test')
-rw-r--r-- | tinyNET/test/droid-makefile | 28 | ||||
-rw-r--r-- | tinyNET/test/stdafx.c | 23 | ||||
-rw-r--r-- | tinyNET/test/stdafx.h | 35 | ||||
-rw-r--r-- | tinyNET/test/targetver.h | 33 | ||||
-rw-r--r-- | tinyNET/test/test.c | 121 | ||||
-rw-r--r-- | tinyNET/test/test.vcproj | 418 | ||||
-rw-r--r-- | tinyNET/test/test_auth.h | 28 | ||||
-rw-r--r-- | tinyNET/test/test_dhcp.h | 118 | ||||
-rw-r--r-- | tinyNET/test/test_dhcp6.h | 48 | ||||
-rw-r--r-- | tinyNET/test/test_dns.h | 224 | ||||
-rw-r--r-- | tinyNET/test/test_ice.h | 238 | ||||
-rw-r--r-- | tinyNET/test/test_ifaces.h | 99 | ||||
-rw-r--r-- | tinyNET/test/test_nat.h | 211 | ||||
-rw-r--r-- | tinyNET/test/test_sockets.h | 61 | ||||
-rw-r--r-- | tinyNET/test/test_stun.h | 255 | ||||
-rw-r--r-- | tinyNET/test/test_tls.h | 105 | ||||
-rw-r--r-- | tinyNET/test/test_transport.h | 217 |
17 files changed, 2262 insertions, 0 deletions
diff --git a/tinyNET/test/droid-makefile b/tinyNET/test/droid-makefile new file mode 100644 index 0000000..0273af6 --- /dev/null +++ b/tinyNET/test/droid-makefile @@ -0,0 +1,28 @@ +APP := test + +CFLAGS := $(CFLAGS_COMMON) -I../src -I../../tinySAK/src +LDFLAGS := $(LDFLAGS_COMMON) -Wl,-Bsymbolic,--whole-archive -l$(PROJECT) -ltinySAK -Wl,--entry=main + +all: $(APP) + +OBJS += $(APP).o + +$(APP): $(OBJS) + $(CC) $(LDFLAGS) -o $@ $^ + +%.o: %.c + $(CC) -c $(INCLUDE) $(CFLAGS) $< -o $@ + +install: $(APP) + $(ANDROID_SDK_ROOT)/tools/adb push $(APP) $(EXEC_DIR)/$(APP) + $(ANDROID_SDK_ROOT)/tools/adb shell chmod 777 $(EXEC_DIR)/$(APP) + +run: + $(ANDROID_SDK_ROOT)/tools/adb shell $(EXEC_DIR)/$(APP) + +#dbg: +# $(MAKE) $(MAKEFILE) DEBUG="-g -DDEBUG" +# $(MAKE) $(MAKEFILE) install + +clean: + @rm -f $(OBJS) $(APP)
\ No newline at end of file diff --git a/tinyNET/test/stdafx.c b/tinyNET/test/stdafx.c new file mode 100644 index 0000000..4cac236 --- /dev/null +++ b/tinyNET/test/stdafx.c @@ -0,0 +1,23 @@ +/* Copyright (C) 2014 Mamadou DIOP. +* +* This file is part of Open Source Doubango Framework. +* +* DOUBANGO is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* DOUBANGO is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Lesser General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with DOUBANGO. +* +*/ + +#include "stdafx.h" + +// TODO: reference any additional headers you need in STDAFX.H +// and not in this file diff --git a/tinyNET/test/stdafx.h b/tinyNET/test/stdafx.h new file mode 100644 index 0000000..92f1061 --- /dev/null +++ b/tinyNET/test/stdafx.h @@ -0,0 +1,35 @@ +/* Copyright (C) 2014 Mamadou DIOP. +* +* This file is part of Open Source Doubango Framework. +* +* DOUBANGO is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* DOUBANGO is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Lesser General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with DOUBANGO. +* +*/ + +#ifndef TEST_TNET_STDAFX_H +#define TEST_TNET_STDAFX_H + +#ifdef WIN32 +#include "targetver.h" +#endif + +#include <stdio.h> +#include <string.h> +//#include <tchar.h> + + + +// TODO: reference additional headers your program requires here + +#endif /* TEST_TNET_STDAFX_H */ diff --git a/tinyNET/test/targetver.h b/tinyNET/test/targetver.h new file mode 100644 index 0000000..21af608 --- /dev/null +++ b/tinyNET/test/targetver.h @@ -0,0 +1,33 @@ +/* Copyright (C) 2014 Mamadou DIOP. +* +* This file is part of Open Source Doubango Framework. +* +* DOUBANGO is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* DOUBANGO is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Lesser General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with DOUBANGO. +* +*/ +#ifndef TNET_TEST_TARGETVER_H +#define TNET_TEST_TARGETVER_H + +// The following macros define the minimum required platform. The minimum required platform +// is the earliest version of Windows, Internet Explorer etc. that has the necessary features to run +// your application. The macros work by enabling all features available on platform versions up to and +// including the version specified. + +// Modify the following defines if you have to target a platform prior to the ones specified below. +// Refer to MSDN for the latest info on corresponding values for different platforms. +#ifndef _WIN32_WINNT // Specifies that the minimum required platform is Windows Vista. +#define _WIN32_WINNT 0x0501 // Change this to the appropriate value to target other versions of Windows. +#endif + +#endif /* TNET_TEST_TARGETVER_H */
\ No newline at end of file diff --git a/tinyNET/test/test.c b/tinyNET/test/test.c new file mode 100644 index 0000000..64e0349 --- /dev/null +++ b/tinyNET/test/test.c @@ -0,0 +1,121 @@ +/* Copyright (C) 2014 Mamadou DIOP. +* +* This file is part of Open Source Doubango Framework. +* +* DOUBANGO is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* DOUBANGO is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Lesser General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with DOUBANGO. +* +*/ +#include "stdafx.h" + +#define BAIL_IF_ERR(expr) { int _ret_; if ((_ret_) = (expr)) { TSK_DEBUG_ERROR("Error %d", (_ret_)); goto bail; } } + +#include "tsk.h" + +#include "tinynet.h" + +#include "test_sockets.h" +#include "test_transport.h" +#include "test_auth.h" +#include "test_stun.h" +#include "test_nat.h" +#include "test_ifaces.h" +#include "test_dns.h" +#include "test_ice.h" +#include "test_dhcp.h" +#include "test_dhcp6.h" +#include "test_tls.h" + +#define RUN_TEST_LOOP 0 + +#define RUN_TEST_ALL 0 +#define RUN_TEST_SOCKETS 0 /* FIXME: Android */ +#define RUN_TEST_TRANSPORT 0 +#define RUN_TEST_AUTH 0 +#define RUN_TEST_STUN 0 +#define RUN_TEST_ICE 1 +#define RUN_TEST_NAT 0 +#define RUN_TEST_IFACES 0 +#define RUN_TEST_DNS 0 +#define RUN_TEST_DHCP 0 +#define RUN_TEST_DHCP6 0 +#define RUN_TEST_TLS 0 + +#ifdef _WIN32_WCE +int _tmain(int argc, _TCHAR* argv[]) +#else +int main() +#endif +{ + /* Startup the network stack. */ + if(tnet_startup()){ + return -1; + } + +#if RUN_TEST_LOOP + for(;;) +#endif + { + +#if RUN_TEST_ALL || RUN_TEST_SOCKETS + test_sockets(); +#endif + +#if RUN_TEST_ALL || RUN_TEST_TRANSPORT + test_transport(); +#endif + +#if RUN_TEST_ALL || RUN_TEST_AUTH + test_auth(); +#endif + +#if RUN_TEST_ALL || RUN_TEST_STUN + test_stun(); +#endif + +#if RUN_TEST_ALL || RUN_TEST_ICE + test_ice(); +#endif + +#if RUN_TEST_ALL || RUN_TEST_NAT + test_nat(); +#endif + +#if RUN_TEST_ALL || RUN_TEST_IFACES + test_ifaces(); +#endif + +#if RUN_TEST_ALL || RUN_TEST_DNS + test_dns(); +#endif + +#if RUN_TEST_ALL || RUN_TEST_DHCP + test_dhcp(); +#endif + +#if RUN_TEST_ALL || RUN_TEST_DHCP6 + test_dhcp6(); +#endif + +#if RUN_TEST_ALL || RUN_TEST_TLS + test_tls(); +#endif + + } + + /* Cleanup the network stack */ + tnet_cleanup(); + + return 0; +} + diff --git a/tinyNET/test/test.vcproj b/tinyNET/test/test.vcproj new file mode 100644 index 0000000..6b4162c --- /dev/null +++ b/tinyNET/test/test.vcproj @@ -0,0 +1,418 @@ +<?xml version="1.0" encoding="Windows-1252"?> +<VisualStudioProject + ProjectType="Visual C++" + Version="9.00" + Name="test" + ProjectGUID="{2189FB5C-B2B2-4ED2-8A78-64853B55DAD5}" + RootNamespace="test" + Keyword="Win32Proj" + TargetFrameworkVersion="196613" + > + <Platforms> + <Platform + Name="Win32" + /> + <Platform + Name="Windows Mobile 5.0 Pocket PC SDK (ARMV4I)" + /> + </Platforms> + <ToolFiles> + </ToolFiles> + <Configurations> + <Configuration + Name="Debug|Win32" + OutputDirectory="$(SolutionDir)$(ConfigurationName)" + IntermediateDirectory="$(ConfigurationName)" + ConfigurationType="1" + CharacterSet="1" + > + <Tool + Name="VCPreBuildEventTool" + /> + <Tool + Name="VCCustomBuildTool" + /> + <Tool + Name="VCXMLDataGeneratorTool" + /> + <Tool + Name="VCWebServiceProxyGeneratorTool" + /> + <Tool + Name="VCMIDLTool" + /> + <Tool + Name="VCCLCompilerTool" + Optimization="0" + AdditionalIncludeDirectories="..\..\thirdparties\win32\include;"$(SolutionDir)\src";..\..\tinySAK\src" + PreprocessorDefinitions="DEBUG_LEVEL=DEBUG_LEVEL_INFO;WIN32;_DEBUG;_CONSOLE" + MinimalRebuild="true" + BasicRuntimeChecks="3" + RuntimeLibrary="3" + UsePrecompiledHeader="0" + WarningLevel="3" + WarnAsError="true" + DebugInformationFormat="4" + CompileAs="1" + /> + <Tool + Name="VCManagedResourceCompilerTool" + /> + <Tool + Name="VCResourceCompilerTool" + /> + <Tool + Name="VCPreLinkEventTool" + /> + <Tool + Name="VCLinkerTool" + AdditionalDependencies="$(OutDir)\tinySAK.lib $(OutDir)\tinyNET.lib ws2_32.lib" + LinkIncremental="2" + GenerateDebugInformation="true" + SubSystem="1" + TargetMachine="1" + /> + <Tool + Name="VCALinkTool" + /> + <Tool + Name="VCManifestTool" + /> + <Tool + Name="VCXDCMakeTool" + /> + <Tool + Name="VCBscMakeTool" + /> + <Tool + Name="VCFxCopTool" + /> + <Tool + Name="VCAppVerifierTool" + /> + <Tool + Name="VCPostBuildEventTool" + /> + </Configuration> + <Configuration + Name="Debug|Windows Mobile 5.0 Pocket PC SDK (ARMV4I)" + OutputDirectory=""$(SolutionDir)$(ConfigurationName)\wce"" + IntermediateDirectory=""$(SolutionDir)$(ConfigurationName)"" + ConfigurationType="1" + CharacterSet="1" + > + <Tool + Name="VCPreBuildEventTool" + /> + <Tool + Name="VCCustomBuildTool" + /> + <Tool + Name="VCXMLDataGeneratorTool" + /> + <Tool + Name="VCWebServiceProxyGeneratorTool" + /> + <Tool + Name="VCMIDLTool" + TargetEnvironment="1" + /> + <Tool + Name="VCCLCompilerTool" + ExecutionBucket="7" + Optimization="0" + AdditionalIncludeDirectories=""$(DOUBANGO_HOME)\thirdparties\win32\include";"$(SolutionDir)\src";"$(DOUBANGO_HOME)\tinySAK\src"" + PreprocessorDefinitions="DEBUG_LEVEL=DEBUG_LEVEL_INFO;_CONSOLE;_DEBUG;_WIN32_WCE=$(CEVER);UNDER_CE;$(PLATFORMDEFINES);WINCE;DEBUG;$(ARCHFAM);$(_ARCHFAM_)" + MinimalRebuild="true" + RuntimeLibrary="3" + UsePrecompiledHeader="0" + WarningLevel="3" + DebugInformationFormat="3" + CompileAs="1" + /> + <Tool + Name="VCManagedResourceCompilerTool" + /> + <Tool + Name="VCResourceCompilerTool" + /> + <Tool + Name="VCPreLinkEventTool" + /> + <Tool + Name="VCLinkerTool" + AdditionalDependencies="$(OutDir)\tinySAK.lib $(OutDir)\tinyNET.lib" + LinkIncremental="2" + GenerateDebugInformation="true" + SubSystem="8" + EntryPointSymbol="mainWCRTStartup" + TargetMachine="0" + /> + <Tool + Name="VCALinkTool" + /> + <Tool + Name="VCXDCMakeTool" + /> + <Tool + Name="VCBscMakeTool" + /> + <Tool + Name="VCFxCopTool" + /> + <Tool + Name="VCCodeSignTool" + /> + <Tool + Name="VCPostBuildEventTool" + /> + <DeploymentTool + ForceDirty="-1" + RemoteDirectory="" + RegisterOutput="0" + AdditionalFiles="" + /> + <DebuggerTool + /> + </Configuration> + <Configuration + Name="Release|Win32" + OutputDirectory="$(SolutionDir)$(ConfigurationName)" + IntermediateDirectory="$(ConfigurationName)" + ConfigurationType="1" + CharacterSet="1" + WholeProgramOptimization="1" + > + <Tool + Name="VCPreBuildEventTool" + /> + <Tool + Name="VCCustomBuildTool" + /> + <Tool + Name="VCXMLDataGeneratorTool" + /> + <Tool + Name="VCWebServiceProxyGeneratorTool" + /> + <Tool + Name="VCMIDLTool" + /> + <Tool + Name="VCCLCompilerTool" + Optimization="2" + EnableIntrinsicFunctions="true" + PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE" + RuntimeLibrary="2" + EnableFunctionLevelLinking="true" + UsePrecompiledHeader="0" + WarningLevel="3" + DebugInformationFormat="3" + CompileAs="1" + /> + <Tool + Name="VCManagedResourceCompilerTool" + /> + <Tool + Name="VCResourceCompilerTool" + /> + <Tool + Name="VCPreLinkEventTool" + /> + <Tool + Name="VCLinkerTool" + LinkIncremental="1" + GenerateDebugInformation="true" + SubSystem="1" + OptimizeReferences="2" + EnableCOMDATFolding="2" + TargetMachine="1" + /> + <Tool + Name="VCALinkTool" + /> + <Tool + Name="VCManifestTool" + /> + <Tool + Name="VCXDCMakeTool" + /> + <Tool + Name="VCBscMakeTool" + /> + <Tool + Name="VCFxCopTool" + /> + <Tool + Name="VCAppVerifierTool" + /> + <Tool + Name="VCPostBuildEventTool" + /> + </Configuration> + <Configuration + Name="Release|Windows Mobile 5.0 Pocket PC SDK (ARMV4I)" + OutputDirectory="$(SolutionDir)Windows Mobile 5.0 Pocket PC SDK (ARMV4I)\$(ConfigurationName)" + IntermediateDirectory="Windows Mobile 5.0 Pocket PC SDK (ARMV4I)\$(ConfigurationName)" + ConfigurationType="1" + CharacterSet="1" + WholeProgramOptimization="1" + > + <Tool + Name="VCPreBuildEventTool" + /> + <Tool + Name="VCCustomBuildTool" + /> + <Tool + Name="VCXMLDataGeneratorTool" + /> + <Tool + Name="VCWebServiceProxyGeneratorTool" + /> + <Tool + Name="VCMIDLTool" + TargetEnvironment="1" + /> + <Tool + Name="VCCLCompilerTool" + ExecutionBucket="7" + Optimization="2" + EnableIntrinsicFunctions="true" + PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE" + RuntimeLibrary="2" + EnableFunctionLevelLinking="true" + UsePrecompiledHeader="0" + WarningLevel="3" + DebugInformationFormat="3" + CompileAs="1" + /> + <Tool + Name="VCManagedResourceCompilerTool" + /> + <Tool + Name="VCResourceCompilerTool" + /> + <Tool + Name="VCPreLinkEventTool" + /> + <Tool + Name="VCLinkerTool" + LinkIncremental="1" + GenerateDebugInformation="true" + SubSystem="1" + OptimizeReferences="2" + EnableCOMDATFolding="2" + TargetMachine="0" + /> + <Tool + Name="VCALinkTool" + /> + <Tool + Name="VCXDCMakeTool" + /> + <Tool + Name="VCBscMakeTool" + /> + <Tool + Name="VCFxCopTool" + /> + <Tool + Name="VCCodeSignTool" + /> + <Tool + Name="VCPostBuildEventTool" + /> + <DeploymentTool + ForceDirty="-1" + RemoteDirectory="" + RegisterOutput="0" + AdditionalFiles="" + /> + <DebuggerTool + /> + </Configuration> + </Configurations> + <References> + </References> + <Files> + <Filter + Name="Source Files" + Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx" + UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}" + > + <File + RelativePath=".\stdafx.c" + > + </File> + <File + RelativePath=".\test.c" + > + </File> + </Filter> + <Filter + Name="Header Files" + Filter="h;hpp;hxx;hm;inl;inc;xsd" + UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}" + > + <File + RelativePath=".\stdafx.h" + > + </File> + <File + RelativePath=".\targetver.h" + > + </File> + </Filter> + <Filter + Name="tests" + > + <File + RelativePath=".\test_auth.h" + > + </File> + <File + RelativePath=".\test_dhcp.h" + > + </File> + <File + RelativePath=".\test_dhcp6.h" + > + </File> + <File + RelativePath=".\test_dns.h" + > + </File> + <File + RelativePath=".\test_ice.h" + > + </File> + <File + RelativePath=".\test_ifaces.h" + > + </File> + <File + RelativePath=".\test_nat.h" + > + </File> + <File + RelativePath=".\test_sockets.h" + > + </File> + <File + RelativePath=".\test_stun.h" + > + </File> + <File + RelativePath=".\test_tls.h" + > + </File> + <File + RelativePath=".\test_transport.h" + > + </File> + </Filter> + </Files> + <Globals> + </Globals> +</VisualStudioProject> diff --git a/tinyNET/test/test_auth.h b/tinyNET/test/test_auth.h new file mode 100644 index 0000000..5d51cd6 --- /dev/null +++ b/tinyNET/test/test_auth.h @@ -0,0 +1,28 @@ +/* Copyright (C) 2014 Mamadou DIOP. +* +* This file is part of Open Source Doubango Framework. +* +* DOUBANGO is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* DOUBANGO is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Lesser General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with DOUBANGO. +* +*/ +#ifndef TNET_TEST_AUTH_H +#define TNET_TEST_AUTH_H + +void test_auth() +{ + +} + +#endif /* TNET_TEST_AUTH_H */ + diff --git a/tinyNET/test/test_dhcp.h b/tinyNET/test/test_dhcp.h new file mode 100644 index 0000000..c74e99c --- /dev/null +++ b/tinyNET/test/test_dhcp.h @@ -0,0 +1,118 @@ +/* Copyright (C) 2014 Mamadou DIOP. +* +* This file is part of Open Source Doubango Framework. +* +* DOUBANGO is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* DOUBANGO is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Lesser General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with DOUBANGO. +* +*/ +#ifndef TNET_TEST_DHCP_H +#define TNET_TEST_DHCP_H + + + +void test_dhcp_discover(tnet_dhcp_ctx_t *ctx) +{ +} + +void test_dhcp_offer(tnet_dhcp_ctx_t *ctx) +{ +} + +void test_dhcp_request(tnet_dhcp_ctx_t *ctx) +{ +} + +void test_dhcp_inform(tnet_dhcp_ctx_t *ctx) +{ + tnet_dhcp_params_t *params = tsk_null; + tnet_dhcp_reply_t *reply = tsk_null; + + params = tnet_dhcp_params_create(); + tnet_dhcp_params_add_code(params, dhcp_code_SIP_Servers_DHCP_Option); /* SIP Servers */ + tnet_dhcp_params_add_code(params, dhcp_code_Domain_Server); /* DNS Server */ + + reply = tnet_dhcp_query_inform(ctx, params); + + if(reply && !TNET_DHCP_MESSAGE_IS_REPLY(reply)){ + TSK_DEBUG_ERROR("DHCP request is not expected in response to a request."); + goto bail; + } + + if(reply){ + switch(reply->type) + { + case dhcp_type_ack: + { + tsk_list_item_t *item; + TSK_DEBUG_INFO("DHCP response type ==> ACK."); + + tsk_list_foreach(item, reply->options) + { + const tnet_dhcp_option_t *option = item->data; + + /* SIP SERVERS */ + if(option->code == dhcp_code_SIP_Servers_DHCP_Option) + { + tsk_list_item_t *item2; + const tnet_dhcp_option_sip_t *option_sip4 = (const tnet_dhcp_option_sip_t*)option;; + tsk_list_foreach(item2, option_sip4->servers) + { + const tsk_string_t *str = item2->data; + TSK_DEBUG_INFO("DHCP-SIP_SERVER ==>%s", str->value); + } + } + + /* DNS SERVERS */ + if(option->code == dhcp_code_Domain_Server) + { + tsk_list_item_t *item2; + const tnet_dhcp_option_dns_t *option_dns = (const tnet_dhcp_option_dns_t*)option;; + tsk_list_foreach(item2, option_dns->servers) + { + const tsk_string_t *str = item2->data; + TSK_DEBUG_INFO("DHCP-DNS_SERVER ==>%s", str->value); + } + } + } + break; + } + + default: + { + break; + } + } + } + else + { + TSK_DEBUG_ERROR("DHCP reply is NULL."); + goto bail; + } + +bail: + TSK_OBJECT_SAFE_FREE(reply); + TSK_OBJECT_SAFE_FREE(params); + + //tsk_thread_sleep(1000); +} + +void test_dhcp() +{ + tnet_dhcp_ctx_t *ctx = tnet_dhcp_ctx_create(); + test_dhcp_inform(ctx); + + TSK_OBJECT_SAFE_FREE(ctx); +} + +#endif /* TNET_TEST_DHCP_H */ diff --git a/tinyNET/test/test_dhcp6.h b/tinyNET/test/test_dhcp6.h new file mode 100644 index 0000000..c96fd96 --- /dev/null +++ b/tinyNET/test/test_dhcp6.h @@ -0,0 +1,48 @@ +/* Copyright (C) 2014 Mamadou DIOP. +* +* This file is part of Open Source Doubango Framework. +* +* DOUBANGO is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* DOUBANGO is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Lesser General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with DOUBANGO. +* +*/ +#ifndef TNET_TEST_DHCP6_H +#define TNET_TEST_DHCP6_H + + + +void test_dhcp6_requestinfo(tnet_dhcp6_ctx_t *ctx) +{ + tnet_dhcp6_option_orequest_t *orequest = tnet_dhcp6_option_orequest_create_null(); + tnet_dhcp6_reply_t* reply = 0; + + tnet_dhcp6_option_orequest_add_code(orequest, 24); + tnet_dhcp6_option_orequest_add_code(orequest, 23); + tnet_dhcp6_option_orequest_add_code(orequest, 21); /* SIP Servers Domain Name List */ + tnet_dhcp6_option_orequest_add_code(orequest, 22); /* SIP Servers IPv6 Address List */ + + reply = tnet_dhcp6_requestinfo(ctx, orequest); + + TSK_OBJECT_SAFE_FREE(orequest); + TSK_OBJECT_SAFE_FREE(reply); +} + +void test_dhcp6() +{ + tnet_dhcp6_ctx_t *ctx = tnet_dhcp6_ctx_create(); + test_dhcp6_requestinfo(ctx); + + TSK_OBJECT_SAFE_FREE(ctx); +} + +#endif /* TNET_TEST_DHCP6_H */ diff --git a/tinyNET/test/test_dns.h b/tinyNET/test/test_dns.h new file mode 100644 index 0000000..f2ab145 --- /dev/null +++ b/tinyNET/test/test_dns.h @@ -0,0 +1,224 @@ +/* Copyright (C) 2014 Mamadou DIOP. +* +* This file is part of Open Source Doubango Framework. +* +* DOUBANGO is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* DOUBANGO is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Lesser General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with DOUBANGO. +* +*/ +#ifndef TNET_TEST_DNS_H +#define TNET_TEST_DNS_H + +//#include "tnet_utils.h" /* tnet_address_t */ + +void test_dns_query() +{ + tnet_dns_ctx_t *ctx = tnet_dns_ctx_create(); + tnet_dns_response_t *response = tsk_null; + const tsk_list_item_t* item; + const tnet_dns_rr_t* rr; + + //if((response = tnet_dns_resolve(ctx, "_sip._udp.sip2sip.info", qclass_in, qtype_srv))) + if((response = tnet_dns_resolve(ctx, "sip2sip.info", qclass_in, qtype_naptr))) + { + if(TNET_DNS_RESPONSE_IS_SUCCESS(response)){ + TSK_DEBUG_INFO("We got a success response from the DNS server."); + // loop through the answers + tsk_list_foreach(item, response->Answers){ + rr = item->data; + if(rr->qtype == qtype_naptr){ + const tnet_dns_naptr_t *naptr = (const tnet_dns_naptr_t*)rr; + + TSK_DEBUG_INFO("order=%u pref=%u flags=%s services=%s regexp=%s replacement=%s", + naptr->order, + naptr->preference, + naptr->flags, + naptr->services, + naptr->regexp, + naptr->replacement); + } + } + } + else{ + TSK_DEBUG_ERROR("We got an error response from the DNS server. Erro code: %u", response->Header.RCODE); + } + } + + tnet_dns_cache_clear(ctx); + + TSK_OBJECT_SAFE_FREE(response); + TSK_OBJECT_SAFE_FREE(ctx); + + + tsk_thread_sleep(2000); +} + +void test_dns_srv() +{ + tnet_dns_ctx_t *ctx = tnet_dns_ctx_create(); + char* hostname = 0; + tnet_port_t port = 0; + + if(!tnet_dns_query_srv(ctx, "_sip._udp.sip2sip.info", &hostname, &port)){ + TSK_DEBUG_INFO("DNS SRV succeed ==> hostname=%s and port=%u", hostname, port); + } + + TSK_FREE(hostname); + TSK_OBJECT_SAFE_FREE(ctx); + + tsk_thread_sleep(2000); +} + +void test_dns_naptr_srv() +{ + tnet_dns_ctx_t *ctx = tnet_dns_ctx_create(); + char* hostname = tsk_null; + tnet_port_t port = 0; + + if(!tnet_dns_query_naptr_srv(ctx, "sip2sip.info", "SIP+D2U", &hostname, &port)){ + TSK_DEBUG_INFO("DNS NAPTR+SRV succeed ==> hostname=%s and port=%u", hostname, port); + } + + TSK_FREE(hostname); + TSK_OBJECT_SAFE_FREE(ctx); + + tsk_thread_sleep(2000); +} + +void test_enum() +{ + tnet_dns_ctx_t *ctx = tnet_dns_ctx_create(); + tnet_dns_response_t* response = tsk_null; +// const tsk_list_item_t* item; +// const tnet_dns_naptr_t* record; + char* uri = tsk_null; + const char* e164num = "+1-800-555-5555"; + //const char* e164num = "+33660188661"; + + //tnet_dns_add_server(ctx, "192.168.16.9"); + + //if((uri = tnet_dns_enum_2(ctx, "E2U+SIP", e164num, "e164.org"))){ + if((uri = tnet_dns_enum_2(ctx, "E2U+SIP", e164num, "e164.org"))){ + TSK_DEBUG_INFO("URI=%s", uri); + TSK_FREE(uri); + } + else{ + TSK_DEBUG_ERROR("ENUM(%s) failed", e164num); + } + + /*if((response = tnet_dns_enum(ctx, "+1-800-555-5555", "e164.org"))){ + if(TNET_DNS_RESPONSE_IS_SUCCESS(response)){ + TSK_DEBUG_INFO("We got a success response from the DNS server."); + // loop through the answers + tsk_list_foreach(item, response->Answers){ + record = item->data; + + TSK_DEBUG_INFO("order=%u pref=%u flags=%s services=%s regexp=%s replacement=%s", + record->order, + record->preference, + record->flags, + record->services, + record->regexp, + record->replacement); + } + } + else{ + TSK_DEBUG_ERROR("We got an error response from the DNS server. Erro code: %u", response->Header.RCODE); + } + }*/ + + + TSK_OBJECT_SAFE_FREE(response); + TSK_OBJECT_SAFE_FREE(ctx); + + tsk_thread_sleep(2000); +} + + +typedef struct regexp_test_s{ + const char* e164num; + const char* regexp; + const char* xres; +} +regexp_test_t; + +regexp_test_t regexp_tests[] = { + "+18005551234", "!^.*$!sip:customer-service@example.com!i", "sip:customer-service@example.com", + "+18005551234", "!^.*$!mailto:information@example.com!i", "mailto:information@example.com", + + "+18005555555", "!^\\+1800(.*)$!sip:1641641800\\1@tollfree.sip-happens.com!", "sip:16416418005555555@tollfree.sip-happens.com", + "+18005555555", "!^\\+1800(.*)$!sip:1641641800\\1@sip.tollfreegateway.com!", "sip:16416418005555555@sip.tollfreegateway.com", + + "+468971234", "!^+46(.*)$!ldap://ldap.telco.se/cn=0\\1!", "ldap://ldap.telco.se/cn=08971234", + "+468971234", "!^+46(.*)$!mailto:spam@paf.se!", "mailto:spam@paf.se", + + "urn:cid:199606121851.1@bar.example.com", "!!^urn:cid:.+@([^\\.]+\\.)(.*)$!\\2!i", "example.com", +}; + +void test_regex() +{ + char* ret; + size_t i; + + for(i=0; i< sizeof(regexp_tests)/sizeof(regexp_test_t); i++) + { + if((ret = tnet_dns_regex_parse(regexp_tests[i].e164num, regexp_tests[i].regexp))){ + TSK_DEBUG_INFO("ENUM(%s) = %s", regexp_tests[i].e164num, ret); + if(!tsk_strequals(ret, regexp_tests[i].xres)){ + TSK_DEBUG_ERROR("Failed to match ENUM(%s)", regexp_tests[i].e164num); + } + TSK_FREE(ret); + } + else{ + TSK_DEBUG_ERROR("Failed to parse ENUM(%s)", regexp_tests[i].e164num); + } + + TSK_DEBUG_INFO("---------"); + } +} + +void test_resolvconf() +{ + tnet_addresses_L_t * servers; + const tnet_address_t* address; + const tsk_list_item_t* item; + const char* path = "C:\\tmp\\resolv32.conf"; + //const char* path = "C:\\tmp\\resolv.conf"; + //const char* path = "/etc/resolv.conf"; + + if((servers = tnet_dns_resolvconf_parse(path))){ + tsk_list_foreach(item, servers){ + address = item->data; + + TSK_DEBUG_INFO("DNS Server host=%s Family=%d", address->ip, address->family); + } + + TSK_OBJECT_SAFE_FREE(servers); + } + else{ + TSK_DEBUG_ERROR("Failed to parse DNS servers from %s.", path); + } +} + +void test_dns() +{ + test_dns_naptr_srv(); + //test_dns_srv(); + //test_dns_query(); + //test_enum(); + //test_regex(); + //test_resolvconf(); +} + + +#endif /* TNET_TEST_DNS_H */ diff --git a/tinyNET/test/test_ice.h b/tinyNET/test/test_ice.h new file mode 100644 index 0000000..023a2c2 --- /dev/null +++ b/tinyNET/test/test_ice.h @@ -0,0 +1,238 @@ +/* Copyright (C) 2014 Mamadou DIOP. +* +* This file is part of Open Source Doubango Framework. +* +* DOUBANGO is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* DOUBANGO is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Lesser General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with DOUBANGO. +* +*/ + +#ifndef TNET_TEST_ICE_H +#define TNET_TEST_ICE_H + +#undef kStunUsrName +#undef kStunPwd + +#define kStunUsrName "bossiel@yahoo.fr" +#define kStunPwd "tinynet" +#define kStunServerIP "ns313841.ovh.net" /*"numb.viagenie.ca"*/ /*stun.ekiga.net*/ + +#define kSkipHosts 1 +#define kSkipReflexives 1 // server reflexive: STUN +#define kSkipPeers 1 // peer reflexive +#define kSkipRelays 0 // relays: TURN + +#define kTurnTrue 1 +#define kStunTrue 1 +#define kTurnFalse 0 +#define kStunFalse 0 + +static const tsk_bool_t use_rtcp = tsk_false; + +static struct tnet_ice_ctx_s *p_ice_ctx1 = tsk_null; +static struct tnet_ice_ctx_s *p_ice_ctx2 = tsk_null; + +static void test_ice_print_local_candidates(const struct tnet_ice_ctx_s *pc_ctx) +{ + tsk_size_t index = 0; + const tnet_ice_candidate_t* candidate; + char* p_str = tsk_null; + + while ((candidate = tnet_ice_ctx_get_local_candidate_at(pc_ctx, index++))) { + tsk_strcat_2(&p_str, "%s\r\n", tnet_ice_candidate_tostring((tnet_ice_candidate_t*)candidate)); + } + TSK_DEBUG_INFO("ICE LOCAL CANDIDATES:\n%s", p_str); + TSK_FREE(p_str); +} + +static char* test_ice_get_local_candidates(const struct tnet_ice_ctx_s *pc_ctx) +{ + tsk_size_t index = 0; + const tnet_ice_candidate_t* candidate; + char* p_str = tsk_null; + + while ((candidate = tnet_ice_ctx_get_local_candidate_at(pc_ctx, index++))) { + if (kSkipHosts && candidate->type_e == tnet_ice_cand_type_host) { + continue; + } + if (kSkipReflexives && candidate->type_e == tnet_ice_cand_type_srflx) { + continue; + } + if (kSkipRelays && candidate->type_e == tnet_ice_cand_type_relay) { + continue; + } + if (kSkipPeers && candidate->type_e == tnet_ice_cand_type_prflx) { + continue; + } + tsk_strcat_2(&p_str, "%s\r\n", tnet_ice_candidate_tostring((tnet_ice_candidate_t*)candidate)); + } + return p_str; +} + +static int test_ice_rtp_callback(const void* callback_data, const uint8_t* data_ptr, tsk_size_t data_size, tnet_fd_t local_fd, const struct sockaddr_storage* remote_addr) +{ + struct tnet_ice_ctx_s *p_ice_ctx = (struct tnet_ice_ctx_s *)callback_data; + + TSK_DEBUG_INFO("\n\nICE rtp callback (incoming data): %.*s\n\n", data_size, data_ptr); + +#if 0 + tnet_ice_ctx_send_turn_rtp(p_ice_ctx, data_ptr, data_size); +#endif + + return 0; +} + +static int test_ice_state_callback(const tnet_ice_event_t *e) +{ + struct tnet_ice_ctx_s *p_ice_ctx = (struct tnet_ice_ctx_s *)e->ctx; + int ret = 0; + + TSK_DEBUG_INFO("ICE state callback: %s", e->phrase); + + switch(e->type) + { + case tnet_ice_event_type_gathering_completed: + { + test_ice_print_local_candidates(p_ice_ctx); + if (p_ice_ctx == p_ice_ctx1) { + if ((ret = tnet_ice_ctx_start(p_ice_ctx2))) { + goto bail; + } + } + else { + const tnet_ice_candidate_t* candidate; + char* p_cand; + + p_cand = test_ice_get_local_candidates(p_ice_ctx2); + candidate = tnet_ice_ctx_get_local_candidate_first(p_ice_ctx2); + ret = tnet_ice_ctx_set_remote_candidates(p_ice_ctx1, p_cand, candidate->ufrag, candidate->pwd, tsk_true, tsk_false); + if (ret == 0) { + TSK_FREE(p_cand); + p_cand = test_ice_get_local_candidates(p_ice_ctx1); + candidate = tnet_ice_ctx_get_local_candidate_first(p_ice_ctx1); + ret = tnet_ice_ctx_set_remote_candidates(p_ice_ctx2, p_cand, candidate->ufrag, candidate->pwd, tsk_false, tsk_false); + TSK_FREE(p_cand); + } + } + break; + } + + case tnet_ice_event_type_conncheck_succeed: + { + const char kTurnData[] = "TURN data to send for testing"; + const tnet_ice_candidate_t *candidate_offer, *candidate_answer_src, *candidate_answer_dest; + + // === RTP === // + ret = tnet_ice_ctx_get_nominated_symetric_candidates(p_ice_ctx, TNET_ICE_CANDIDATE_COMPID_RTP, &candidate_offer, &candidate_answer_src, &candidate_answer_dest); + if (ret == 0) { + TSK_DEBUG_INFO("Nominated candidate(RTP): Offer=[[%s]], AnswerSrc=[[%s]], AnswerDest=[[%s]]", + tnet_ice_candidate_tostring((tnet_ice_candidate_t*)candidate_offer), + tnet_ice_candidate_tostring((tnet_ice_candidate_t*)candidate_answer_src), + tnet_ice_candidate_tostring((tnet_ice_candidate_t*)candidate_answer_dest)); + + if (tnet_ice_ctx_is_turn_rtp_active(p_ice_ctx)) { + tnet_ice_ctx_send_turn_rtp(p_ice_ctx, kTurnData, sizeof(kTurnData)); + } + } + // === RTCP === // + if (use_rtcp) { + ret = tnet_ice_ctx_get_nominated_symetric_candidates(p_ice_ctx, TNET_ICE_CANDIDATE_COMPID_RTCP, &candidate_offer, &candidate_answer_src, &candidate_answer_dest); + if (ret == 0) { + TSK_DEBUG_INFO("Nominated candidate(RTCP): Offer=[[%s]], AnswerSrc=[[%s]], AnswerDest=[[%s]]", + tnet_ice_candidate_tostring((tnet_ice_candidate_t*)candidate_offer), + tnet_ice_candidate_tostring((tnet_ice_candidate_t*)candidate_answer_src), + tnet_ice_candidate_tostring((tnet_ice_candidate_t*)candidate_answer_dest)); + if (tnet_ice_ctx_is_turn_rtcp_active(p_ice_ctx)) { + tnet_ice_ctx_send_turn_rtcp(p_ice_ctx, kTurnData, sizeof(kTurnData)); + } + } + } + break; + } + } + +bail: + return ret; +} + +void test_ice() +{ + int ret; + static const tsk_bool_t use_ipv6 = tsk_false; + static const tsk_bool_t use_ice_jingle = tsk_false; + static const tsk_bool_t use_video = tsk_false; + + if (!(p_ice_ctx1 = tnet_ice_ctx_create(use_ice_jingle, use_ipv6, use_rtcp, use_video, test_ice_state_callback, tsk_null))) { + goto bail; + } + if (!(p_ice_ctx2 = tnet_ice_ctx_create(use_ice_jingle, use_ipv6, use_rtcp, use_video, test_ice_state_callback, tsk_null))) { + goto bail; + } + if ((ret = tnet_ice_ctx_set_turn_enabled(p_ice_ctx1, 1))) { + goto bail; + } + if ((ret = tnet_ice_ctx_set_turn_enabled(p_ice_ctx2, 1))) { + goto bail; + } + if ((ret = tnet_ice_ctx_set_stun_enabled(p_ice_ctx1, 1))) { + goto bail; + } + if ((ret = tnet_ice_ctx_set_stun_enabled(p_ice_ctx2, 1))) { + goto bail; + } + if ((ret = tnet_ice_ctx_set_userdata(p_ice_ctx1, p_ice_ctx1))) { + goto bail; + } + if ((ret = tnet_ice_ctx_set_userdata(p_ice_ctx2, p_ice_ctx2))) { + goto bail; + } + if ((ret = tnet_ice_ctx_rtp_callback(p_ice_ctx1, test_ice_rtp_callback, p_ice_ctx1))) { + goto bail; + } + if ((ret = tnet_ice_ctx_rtp_callback(p_ice_ctx2, test_ice_rtp_callback, p_ice_ctx2))) { + goto bail; + } +#if 0 //@deprecated + if ((ret = tnet_ice_ctx_set_stun(p_ice_ctx1, kStunServerIP, 3478, kStunSoftware, kStunUsrName, kStunPwd))) { + goto bail; + } + if ((ret = tnet_ice_ctx_set_stun(p_ice_ctx2, kStunServerIP, 3478, kStunSoftware, kStunUsrName, kStunPwd))) { + goto bail; + } +#else + tnet_ice_ctx_add_server(p_ice_ctx1, "udp", kStunServerIP, 3478, kTurnFalse, kStunTrue, kStunUsrName, kStunPwd); // STUN-UDP + tnet_ice_ctx_add_server(p_ice_ctx1, "tcp", kStunServerIP, 3478, kTurnTrue, kStunFalse, kStunUsrName, kStunPwd); // TURN-TCP + tnet_ice_ctx_add_server(p_ice_ctx2, "udp", kStunServerIP, 3478, kTurnFalse, kStunTrue, kStunUsrName, kStunPwd); // STUN-UDP + tnet_ice_ctx_add_server(p_ice_ctx2, "tcp", kStunServerIP, 3478, kTurnTrue, kStunFalse, kStunUsrName, kStunPwd); // TURN-TCP +#endif + if ((ret = tnet_ice_ctx_start(p_ice_ctx1))) { + goto bail; + } + // start ctx2 when we finish gathering ctx1's candidates + //if ((ret = tnet_ice_ctx_start(p_ice_ctx2))) { + // goto bail; + //} + + getchar(); + + // ret = tnet_ice_ctx_stop(p_ice_ctx1); + // ret = tnet_ice_ctx_stop(p_ice_ctx2); + +bail: + TSK_OBJECT_SAFE_FREE(p_ice_ctx1); + TSK_OBJECT_SAFE_FREE(p_ice_ctx2); +} + + +#endif /* TNET_TEST_ICE_H */ + diff --git a/tinyNET/test/test_ifaces.h b/tinyNET/test/test_ifaces.h new file mode 100644 index 0000000..2fd4e43 --- /dev/null +++ b/tinyNET/test/test_ifaces.h @@ -0,0 +1,99 @@ +/* Copyright (C) 2014 Mamadou DIOP. +* +* This file is part of Open Source Doubango Framework. +* +* DOUBANGO is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* DOUBANGO is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Lesser General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with DOUBANGO. +* +*/ +#ifndef TNET_TEST_IFACES_H +#define TNET_TEST_IFACES_H + +void test_faces_bestsource() +{ + tnet_ip_t source; + + // IPv6 + if(!tnet_getbestsource("fe80::fe4c:3ea1", 5060, tnet_socket_type_udp_ipv6, &source)){ + TSK_DEBUG_INFO("Best IPv6 source is [%s]", source); + } + else{ + TSK_DEBUG_ERROR("Failed to get best IPv6 source."); + } + // IPv6 + if(!tnet_getbestsource("2a01:e35:8b32:7050:212:f0ff:fe4c:3ea1", 5060, tnet_socket_type_udp_ipv6, &source)){ + TSK_DEBUG_INFO("Best IPv6 source is [%s]", source); + } + else{ + TSK_DEBUG_ERROR("Failed to get best IPv6 source."); + } + // IPv4 + if(!tnet_getbestsource("192.168.0.11", 5060, tnet_socket_type_udp_ipv4, &source)){ + TSK_DEBUG_INFO("Best IPv4 source is [%s]", source); + } + else{ + TSK_DEBUG_ERROR("Failed to get best IPv4 source."); + } +} + +void test_ifaces_dump_ifaces() +{ + tnet_interfaces_L_t* ifaces = tnet_get_interfaces(); + tsk_list_item_t *item; + + tsk_list_foreach(item, ifaces) + { + const tnet_interface_t *iface = item->data; + TSK_DEBUG_INFO("Interface: %s", iface->description); + } + + TSK_OBJECT_SAFE_FREE(ifaces); +} + +void test_ifaces_dump_addresses() +{ + tnet_addresses_L_t* addresses = tnet_get_addresses_all(); + tsk_list_item_t *item; + + tsk_list_foreach(item, addresses) + { + const tnet_address_t *address = item->data; + if(address->anycast) + { + TSK_DEBUG_INFO("ANYCAST address: %s", address->ip); + } + else if(address->unicast) + { + TSK_DEBUG_INFO("UNICAST address: %s", address->ip); + } + else if(address->multicast) + { + TSK_DEBUG_INFO("MULTICAST address: %s", address->ip); + } + else if(address->dnsserver) + { + TSK_DEBUG_INFO("DNSSERVER address: %s", address->ip); + } + } + + TSK_OBJECT_SAFE_FREE(addresses); +} + +void test_ifaces() +{ + test_faces_bestsource(); + test_ifaces_dump_ifaces(); + test_ifaces_dump_addresses(); +} + +#endif /* TNET_TEST_IFACES_H */ diff --git a/tinyNET/test/test_nat.h b/tinyNET/test/test_nat.h new file mode 100644 index 0000000..1a9bd68 --- /dev/null +++ b/tinyNET/test/test_nat.h @@ -0,0 +1,211 @@ +/* Copyright (C) 2014 Mamadou DIOP. +* +* This file is part of Open Source Doubango Framework. +* +* DOUBANGO is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* DOUBANGO is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Lesser General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with DOUBANGO. +* +*/ +#ifndef TNET_TEST_NAT_H +#define TNET_TEST_NAT_H + +#define STUN_SERVER_IP "ns313841.ovh.net" // "numb.viagenie.ca" /* stun.ekiga.net, */ +#define STUN_USERNAME "bossiel@yahoo.fr" +#define STUN_PASSWORD "tinynet" +#define STUN_SERVER_PORT TNET_STUN_TCP_UDP_DEFAULT_PORT +#define STUN_SERVER_PROTO tnet_socket_type_udp_ipv4 + +void test_nat_stun() +{ + tnet_socket_t *socket1 = 0, *socket2 = 0; + struct tnet_nat_ctx_s *context = 0; + + tnet_stun_binding_id_t bind_id1, bind_id2; + + char* public_ip1 = 0, *public_ip2 = 0; + tnet_port_t public_port1 = 0, public_port2 = 0; + + if(!(socket1 = tnet_socket_create(TNET_SOCKET_HOST_ANY, TNET_SOCKET_PORT_ANY, STUN_SERVER_PROTO)) + || !(socket2 = tnet_socket_create(TNET_SOCKET_HOST_ANY, TNET_SOCKET_PORT_ANY, STUN_SERVER_PROTO))) { + goto bail; + } + + context = tnet_nat_context_create(STUN_SERVER_PROTO, STUN_USERNAME, STUN_PASSWORD); + + if(tnet_nat_set_server_address(context, STUN_SERVER_IP)) { + TSK_DEBUG_ERROR("Failed to set STUN/TURN address."); + goto bail; + } + + // == BIND == // + bind_id1 = tnet_nat_stun_bind(context, socket1->fd); + bind_id2 = tnet_nat_stun_bind(context, socket2->fd); + + if(!bind_id1 || !bind_id2) { + TSK_DEBUG_ERROR("Failed to get public IP/port using stun"); + goto bail; + } + + if (tnet_nat_stun_get_reflexive_address(context, bind_id1, &public_ip1, &public_port1) == 0) { + TSK_DEBUG_INFO("Public IP1/Port1 ==> %s:%u", public_ip1, public_port1); + } + + if (tnet_nat_stun_get_reflexive_address(context, bind_id2, &public_ip2, &public_port2) == 0) { + TSK_DEBUG_INFO("Public IP2/Port2 ==> %s:%u", public_ip2, public_port2); + } + + // == UNBIND == // + tnet_nat_stun_unbind(context, bind_id1); + tnet_nat_stun_unbind(context, bind_id2); + +bail: + TSK_OBJECT_SAFE_FREE(socket1); + TSK_OBJECT_SAFE_FREE(socket2); + + TSK_FREE(public_ip1); + TSK_FREE(public_ip1); + + TSK_OBJECT_SAFE_FREE(context); +} + +void test_nat_turn() +{ +// tnet_socket_t *socket1 = 0, *socket2 = 0; +// struct tnet_nat_ctx_s *context = 0; +// tnet_turn_allocation_id_t alloc_id1, alloc_id2; +// +// char* public_ip1 = 0, *public_ip2 = 0; +// tnet_port_t public_port1 = 0, public_port2 = 0; +// +// tnet_turn_channel_binding_id_t channel_id; +// +// int ret; +// +// if(!(socket1 = tnet_socket_create(TNET_SOCKET_HOST_ANY, TNET_SOCKET_PORT_ANY, STUN_SERVER_PROTO)) +// || !(socket2 = tnet_socket_create(TNET_SOCKET_HOST_ANY, TNET_SOCKET_PORT_ANY, STUN_SERVER_PROTO))) +// { +// goto bail; +// } +// +// context = tnet_nat_context_create(STUN_SERVER_PROTO, STUN_USERNAME, STUN_PASSWORD); +// ((tnet_nat_context_t*)context)->enable_evenport = 0; +// ((tnet_nat_context_t*)context)->enable_fingerprint = 0; +// ((tnet_nat_context_t*)context)->enable_dontfrag = 0; +// ((tnet_nat_context_t*)context)->enable_integrity = 0; +// +// if(tnet_nat_set_server_address(context, STUN_SERVER_IP)) +// { +// TSK_DEBUG_ERROR("Failed to set STUN/TURN address."); +// goto bail; +// } +// +// /* == ALLOC +// */ +// alloc_id1 = tnet_nat_turn_allocate(context, socket1->fd); +// alloc_id2 = tnet_nat_turn_allocate(context, socket2->fd); +// if(!TNET_TURN_IS_VALID_ALLOCATION_ID(alloc_id1) || !TNET_TURN_IS_VALID_ALLOCATION_ID(alloc_id2)) +// { +// TSK_DEBUG_ERROR("TURN allocation failed."); +// goto bail; +// } +// else +// { +// TSK_DEBUG_INFO("TURN allocation succeeded and id1=%llu and id2=%llu", alloc_id1, alloc_id2); +// } +// +// tsk_thread_sleep(2000); +// +// /* == RETRIEVE STUN SERVER REFLEXIVE ADDRESSES +// */ +// if(!tnet_nat_turn_get_reflexive_address(context, alloc_id1, &public_ip1, &public_port1)) +// { +// TSK_DEBUG_INFO("Public IP1/Port1 ==> %s:%u", public_ip1, public_port1); +// } +// +// if(!tnet_nat_turn_get_reflexive_address(context, alloc_id2, &public_ip2, &public_port2)) +// { +// TSK_DEBUG_INFO("Public IP2/Port2 ==> %s:%u", public_ip2, public_port2); +// } +// +// /* == CREATE PERMISSION +// */ +// //tnet_nat_turn_add_permission(context, alloc_id1, "192.168.0.11", 300); +// +// /* == CHANNEL BINDING +// */ +// { +// /* Try to bind (channel binding) to the socket1 to socket2 */ +// struct sockaddr_storage peer; +// if((ret = tnet_sockaddr_init(public_ip2, public_port2, STUN_SERVER_PROTO, &peer))) +// { +// TSK_DEBUG_ERROR("Failed to init peer with error code %d.", ret); +// } +// else +// { +// channel_id = tnet_nat_turn_channel_bind(context, alloc_id1,&peer); +// if(TNET_TURN_IS_VALID_CHANNEL_BINDING_ID(channel_id)) +// { +// TSK_DEBUG_INFO("TURN channel binding succeeded."); +// +// /* Try to send data using the newly create channel */ +// if(tnet_nat_turn_channel_senddata(context, channel_id, "Doubango", strlen("Doubango"))) +// { +// TSK_DEBUG_ERROR("Failed to send data using channel id [%u].", channel_id); +// } +// else +// { +// TSK_DEBUG_INFO("Data successfuly sent using channel if[%u].", channel_id); +// } +// } +// else +// { +// TSK_DEBUG_ERROR("TURN channel binding failed."); +// } +// } +// } +// +// tsk_thread_sleep(2000); +// +// /* == UNALLOC +// */ +// if((ret = tnet_nat_turn_unallocate(context, alloc_id1)) || (ret = tnet_nat_turn_unallocate(context, alloc_id2))) +// { +// TSK_DEBUG_ERROR("TURN unallocation failed with error code: %d.", ret); +// goto bail; +// } +// else +// { +// TSK_DEBUG_INFO("TURN unallocation succeeded."); +// } +// +//bail: +// TSK_OBJECT_SAFE_FREE(socket1); +// TSK_OBJECT_SAFE_FREE(socket2); +// +// TSK_FREE(public_ip1); +// TSK_FREE(public_ip1); +// +// TSK_OBJECT_SAFE_FREE(context); +} + + +void test_nat() +{ + test_nat_stun(); + //test_nat_turn(); + //tsk_thread_sleep(1000); +} + + + +#endif /* TNET_TEST_NAT_H */ diff --git a/tinyNET/test/test_sockets.h b/tinyNET/test/test_sockets.h new file mode 100644 index 0000000..3edd1bd --- /dev/null +++ b/tinyNET/test/test_sockets.h @@ -0,0 +1,61 @@ +/* Copyright (C) 2014 Mamadou DIOP. +* +* This file is part of Open Source Doubango Framework. +* +* DOUBANGO is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* DOUBANGO is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Lesser General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with DOUBANGO. +* +*/ +#ifndef TNET_TEST_SOCKETS_H +#define TNET_TEST_SOCKETS_H + +void test_sockets() +{ + int test; + tnet_socket_tcp_t * tcp_socket; + tnet_socket_type_t type = tnet_socket_type_udp_ipv4; + struct sockaddr_storage to; + + TNET_SOCKET_TYPE_SET_IPV4(type); + TNET_SOCKET_TYPE_SET_IPV6(type); + TNET_SOCKET_TYPE_SET_IPV4Only(type); + TNET_SOCKET_TYPE_SET_IPV6Only(type); + TNET_SOCKET_TYPE_SET_IPV6Only(type); + TNET_SOCKET_TYPE_SET_IPV4(type); + TNET_SOCKET_TYPE_SET_IPV6(type); + + TNET_SOCKET_TYPE_SET_TLS(type); + TNET_SOCKET_TYPE_SET_UDP(type); + TNET_SOCKET_TYPE_SET_SCTP(type); + TNET_SOCKET_TYPE_SET_TCP(type); + + tcp_socket = tnet_socket_create(TNET_SOCKET_HOST_ANY, TNET_SOCKET_PORT_ANY, type); + + if(!TNET_SOCKET_IS_VALID(tcp_socket)) + { + TSK_OBJECT_SAFE_FREE(tcp_socket); + return; + } + + //if(!(test = tnet_sockaddr_init("www.google.com", 80, type, &to))){ + // test = tnet_sockfd_connetto(tcp_socket->fd, (const struct sockaddr_storage *)&to); + //} + + if(!(test = tnet_sockaddr_init("ipv6.google.com", 80, type, &to))){ + test = tnet_sockfd_connectto(tcp_socket->fd, (const struct sockaddr_storage *)&to); + } + + TSK_OBJECT_SAFE_FREE(tcp_socket); +} + +#endif /* TNET_TEST_SOCKETS_H */ diff --git a/tinyNET/test/test_stun.h b/tinyNET/test/test_stun.h new file mode 100644 index 0000000..58fc9b1 --- /dev/null +++ b/tinyNET/test/test_stun.h @@ -0,0 +1,255 @@ +/* Copyright (C) 2014 Mamadou DIOP. +* +* This file is part of Open Source Doubango Framework. +* +* DOUBANGO is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* DOUBANGO is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Lesser General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with DOUBANGO. +* +*/ +#ifndef TNET_TEST_STUN_H +#define TNET_TEST_STUN_H + +#include "stun/tnet_stun_pkt.h" +#include "stun/tnet_stun_utils.h" +#include "turn/tnet_turn_session.h" + +#define kStunUsrName "bossiel@yahoo.fr" +#define kStunPwd "tinynet" +#define kStunServerIP "ns313841.ovh.net" /*"numb.viagenie.ca"*/ +#define kStunServerPort kStunPortDefaultTcpUdp +#define kStunServerProto tnet_socket_type_udp_ipv4 +#define kTurnPeerIP "192.168.0.37" +#define kTurnPeerPort 2020 + +#define TNET_TEST_STUN_SEND_BUFF_TO(buff_ptr, buff_size, IP, PORT) \ + { \ + struct sockaddr_storage addr_to; \ + tnet_socket_t* socket = tnet_socket_create(0, 0, kStunServerProto); \ + tnet_sockaddr_init((IP), (PORT), kStunServerProto, &addr_to); \ + tnet_sockfd_sendto(socket->fd, (const struct sockaddr *)&addr_to, (buff_ptr), (buff_size)); \ + TSK_OBJECT_SAFE_FREE(socket); \ + } +#define TNET_TEST_STUN_SEND_BUFF(buff_ptr, buff_size) TNET_TEST_STUN_SEND_BUFF_TO((buff_ptr), (buff_size), kStunServerIP, kStunServerPort) + +uint8_t __parse_buff_write_ptr[1200]; +static const tsk_size_t __parse_buff_write_size = sizeof(__parse_buff_write_ptr)/sizeof(__parse_buff_write_ptr[0]); +uint8_t __parse_buff_read_ptr[1200]; +static const tsk_size_t __parse_buff_read_size = sizeof(__parse_buff_read_ptr)/sizeof(__parse_buff_read_ptr[0]); + +// http://tools.ietf.org/html/draft-ietf-behave-stun-test-vectors-04 + +static int test_stun_buff_cmp(const uint8_t* pc_buf1_ptr, tsk_size_t n_buff1_size, const uint8_t* pc_buf2_ptr, tsk_size_t n_buff2_size) +{ + int ret; + tsk_size_t u; + if (!pc_buf1_ptr || !pc_buf2_ptr || (n_buff1_size != n_buff2_size)) { + return -1; + } + for (u = 0; u < n_buff1_size; ++u) { + if ((ret = (pc_buf1_ptr[u] - pc_buf2_ptr[u]))) { + return ret; + } + } + return 0; +} + +static void test_stun_parser() +{ + tnet_stun_pkt_t* p_pkt = tsk_null; + tsk_size_t n_written_bytes, n_read_bytes; + static const char* __pc_mapped_addr_ipv4 = "192.168.0.37"; + static const char* __pc_mapped_addr_ipv6 = "fdf8:f53b:82e4::53"; + static const uint16_t __u_mapped_addr_port = 5060; + static const char __pc_username[] = "Mamadou DIOP"; + static const uint16_t __u_username = sizeof(__pc_username); + static const char __pc_integrity[TSK_SHA1_DIGEST_SIZE] = { 0 }; + static const uint16_t __u_integrity = sizeof(__pc_integrity); + static const uint32_t __u_fingerprint = 19831983; + static const uint8_t __u_error_class = 4; // (4 * 100) = 404 + static const uint8_t __u_error_number = 4; // + 4 = 404 + static const char* __pc_error_reason = "Not Found"; + tnet_stun_addr_t addr_ipv4, addr_ipv6; + static const char __pc_realm[] = "doubango.org"; + static const uint16_t __u_realm = sizeof(__pc_realm); + static const char __pc_nonce[128] = { 0 }; + static const uint16_t __u_nonce = sizeof(__pc_nonce); + static const char __pc_software[] = "tinyNET 2.0"; + static const uint16_t __u_software = sizeof(__pc_software); + static const uint32_t __u_life_time = 600; + static const uint32_t __u_req_transport = 17; // UDP + + (n_read_bytes); + + BAIL_IF_ERR(tnet_stun_pkt_create_empty(tnet_stun_pkt_type_binding_request, &p_pkt)); + BAIL_IF_ERR(tnet_stun_utils_inet_pton_v4(__pc_mapped_addr_ipv4, &addr_ipv4)); + BAIL_IF_ERR(tnet_stun_utils_inet_pton_v6(__pc_mapped_addr_ipv6, &addr_ipv6)); + BAIL_IF_ERR(tnet_stun_pkt_attrs_add(p_pkt, + TNET_STUN_PKT_ATTR_ADD_MAPPED_ADDRESS_V4(__u_mapped_addr_port, &addr_ipv4), + TNET_STUN_PKT_ATTR_ADD_MAPPED_ADDRESS_V6(__u_mapped_addr_port, &addr_ipv6), + TNET_STUN_PKT_ATTR_ADD_XOR_MAPPED_ADDRESS_V4(__u_mapped_addr_port, &addr_ipv4), + TNET_STUN_PKT_ATTR_ADD_XOR_MAPPED_ADDRESS_V6(__u_mapped_addr_port, &addr_ipv6), + TNET_STUN_PKT_ATTR_ADD_USERNAME_ZT(__pc_username), + TNET_STUN_PKT_ATTR_ADD_MESSAGE_INTEGRITY(__pc_integrity, __u_integrity), + TNET_STUN_PKT_ATTR_ADD_ERROR_CODE(__u_error_class, __u_error_number, __pc_error_reason), + TNET_STUN_PKT_ATTR_ADD_ERROR_CODE_TRY_ALTERNATE(), + TNET_STUN_PKT_ATTR_ADD_ERROR_CODE_BAD_REQUEST(), + TNET_STUN_PKT_ATTR_ADD_ERROR_CODE_UNAUTHORIZED(), + TNET_STUN_PKT_ATTR_ADD_ERROR_CODE_UNKNOWN_ATTRIBUTE(), + TNET_STUN_PKT_ATTR_ADD_ERROR_CODE_STALE_NONCE(), + TNET_STUN_PKT_ATTR_ADD_ERROR_CODE_SERVER_ERROR(), + TNET_STUN_PKT_ATTR_ADD_REALM_ZT(__pc_realm), + TNET_STUN_PKT_ATTR_ADD_NONCE(__pc_nonce, __u_nonce), + + TNET_STUN_PKT_ATTR_ADD_UNKNOWN_ATTRS( + TNET_STUN_PKT_ATTR_ADD_UNKNOWN_ATTRS_VAL(0x0001), // MAPPED-ADDRESS + TNET_STUN_PKT_ATTR_ADD_UNKNOWN_ATTRS_VAL(0x0006), // USERNAME + TNET_STUN_PKT_ATTR_ADD_UNKNOWN_ATTRS_VAL(0x0007), // PASSWORD + TNET_STUN_PKT_ATTR_ADD_NULL()), + + TNET_STUN_PKT_ATTR_ADD_SOFTWARE_ZT(__pc_software), + TNET_STUN_PKT_ATTR_ADD_ALTERNATE_SERVER_V4(__u_mapped_addr_port, &addr_ipv4), + TNET_STUN_PKT_ATTR_ADD_ALTERNATE_SERVER_V6(__u_mapped_addr_port, &addr_ipv6), + TNET_STUN_PKT_ATTR_ADD_LIFETIME(__u_life_time), + TNET_STUN_PKT_ATTR_ADD_REQUESTED_TRANSPORT(__u_req_transport), + TNET_STUN_PKT_ATTR_ADD_DONT_FRAGMENT(), + + TNET_STUN_PKT_ATTR_ADD_FINGERPRINT(__u_fingerprint), + TNET_STUN_PKT_ATTR_ADD_NULL())); + BAIL_IF_ERR(tnet_stun_pkt_write_with_padding(p_pkt, __parse_buff_write_ptr, __parse_buff_write_size, &n_written_bytes)); + TNET_TEST_STUN_SEND_BUFF(__parse_buff_write_ptr, n_written_bytes); + + TSK_OBJECT_SAFE_FREE(p_pkt); + BAIL_IF_ERR(tnet_stun_pkt_read(__parse_buff_write_ptr, n_written_bytes, &p_pkt)); + BAIL_IF_ERR(tnet_stun_pkt_write_with_padding(p_pkt, __parse_buff_read_ptr, __parse_buff_read_size, &n_read_bytes)); + //TNET_TEST_STUN_SEND_BUFF(__parse_buff_read_ptr, n_read_bytes); + + BAIL_IF_ERR(test_stun_buff_cmp(__parse_buff_write_ptr, n_written_bytes, __parse_buff_read_ptr, n_read_bytes)); + TSK_DEBUG_INFO("test_stun_parser...OK"); + +bail: + TSK_OBJECT_SAFE_FREE(p_pkt); +} + +static struct tnet_turn_session_s* __pc_ss1 = tsk_null; +static struct tnet_turn_session_s* __pc_ss2 = tsk_null; +static char* __p_rel_ip_ss1 = tsk_null; +static uint16_t __u_rel_port_ss1 = 0; +static tsk_bool_t __b_rel_ipv6_ss1 = 0; +static tnet_turn_peer_id_t __u_peer_id1 = kTurnPeerIdInvalid; +static char* __p_rel_ip_ss2 = tsk_null; +static uint16_t __u_rel_port_ss2 = 0; +static tsk_bool_t __b_rel_ipv6_ss2 = 0; +static tnet_turn_peer_id_t __u_peer_id2 = kTurnPeerIdInvalid; + +static int _test_turn_session_callback(const struct tnet_turn_session_event_xs *e) +{ + const struct tnet_turn_session_s* pc_ss = (const struct tnet_turn_session_s*)e->pc_usr_data; + int ret = 0; + switch (e->e_type) { + case tnet_turn_session_event_type_alloc_ok: + { + uint16_t *pu_port = (pc_ss == __pc_ss2) ? &__u_rel_port_ss1 : &__u_rel_port_ss2; + char** pp_ip = (pc_ss == __pc_ss2) ? &__p_rel_ip_ss1 : &__p_rel_ip_ss2; + tsk_bool_t *pb_ipv6 = (pc_ss == __pc_ss2) ? &__b_rel_ipv6_ss1 : &__b_rel_ipv6_ss2; + tnet_turn_peer_id_t *pu_peer_id = (pc_ss == __pc_ss2) ? &__u_peer_id2 : &__u_peer_id1; + + BAIL_IF_ERR(tnet_turn_session_get_relayed_addr(pc_ss, pp_ip, pu_port, pb_ipv6)); + // BAIL_IF_ERR(tnet_turn_session_get_srflx_addr(pc_ss, pu_port, &u_port, &b_ipv6)); // get my own server reflexive address (in order to send data to myself) + BAIL_IF_ERR(tnet_turn_session_createpermission((struct tnet_turn_session_s*)pc_ss, *pp_ip, *pu_port, pu_peer_id)); // Input = ADDR(remote.candidate.relay) + break; + } + case tnet_turn_session_event_type_alloc_nok: + { + TSK_DEBUG_INFO("*** TURN ALLOC NOK ***"); + break; + } + case tnet_turn_session_event_type_perm_ok: + { + static const char __pc_data[] = { "TURN Sample Data (Send Indication)" }; + int i; + tnet_turn_peer_id_t u_peer_id = (pc_ss == __pc_ss2) ? __u_peer_id2 : __u_peer_id1; + // Bind a channel (not required). If succeed, will be used to save data. + tnet_turn_session_chanbind((struct tnet_turn_session_s*)pc_ss, u_peer_id); + // Send data (will use channel if one is active. Otherwise (no channel), SendIndications will be used) + for (i = 0; i < 10; ++i) { + BAIL_IF_ERR(tnet_turn_session_send_data((struct tnet_turn_session_s*)pc_ss, u_peer_id, __pc_data, sizeof(__pc_data))); + } + break; + } + case tnet_turn_session_event_type_perm_nok: + { + TSK_DEBUG_INFO("*** TURN PERM NOK ***"); + break; + } + case tnet_turn_session_event_type_chanbind_ok: + { + static const char __pc_data[] = { "TURN Sample Data (ChannelData)" }; + int i; + tnet_turn_peer_id_t u_peer_id = (pc_ss == __pc_ss2) ? __u_peer_id2 : __u_peer_id1; + for (i = 0; i < 10; ++i) { + BAIL_IF_ERR(tnet_turn_session_send_data((struct tnet_turn_session_s*)pc_ss, u_peer_id, __pc_data, sizeof(__pc_data))); + } + break; + } + case tnet_turn_session_event_type_chanbind_nok: + { + TSK_DEBUG_INFO("*** TURN CHANBIND NOK ***"); + break; + } + case tnet_turn_session_event_type_recv_data: + { + TSK_DEBUG_INFO("RECV DATA:%.*s", e->data.u_data_size, (const char*)e->data.pc_data_ptr); + break; + } + default: + { + break; + } + } +bail: + return ret; +} + +static void test_turn_session() +{ + BAIL_IF_ERR(tnet_turn_session_create_udp_ipv4(tnet_turn_transport_udp, kStunServerIP, kStunServerPort, &__pc_ss1)); + BAIL_IF_ERR(tnet_turn_session_set_callback(__pc_ss1, _test_turn_session_callback, __pc_ss1)); + BAIL_IF_ERR(tnet_turn_session_set_cred(__pc_ss1, kStunUsrName, kStunPwd)); + BAIL_IF_ERR(tnet_turn_session_prepare(__pc_ss1)); + BAIL_IF_ERR(tnet_turn_session_start(__pc_ss1)); + + BAIL_IF_ERR(tnet_turn_session_create_udp_ipv4(tnet_turn_transport_udp, kStunServerIP, kStunServerPort, &__pc_ss2)); + BAIL_IF_ERR(tnet_turn_session_set_callback(__pc_ss2, _test_turn_session_callback, __pc_ss2)); + BAIL_IF_ERR(tnet_turn_session_set_cred(__pc_ss2, kStunUsrName, kStunPwd)); + BAIL_IF_ERR(tnet_turn_session_prepare(__pc_ss2)); + BAIL_IF_ERR(tnet_turn_session_start(__pc_ss2)); + + BAIL_IF_ERR(tnet_turn_session_allocate(__pc_ss1)); + BAIL_IF_ERR(tnet_turn_session_allocate(__pc_ss2)); + + TSK_DEBUG_INFO("*** Press ENTER to continue ***"); + getchar(); + +bail: + TSK_OBJECT_SAFE_FREE(__pc_ss1); + TSK_OBJECT_SAFE_FREE(__pc_ss2); +} + + +static void test_stun() +{ + //test_stun_parser(); + test_turn_session(); +} + +#endif /* TNET_TEST_STUN_H */ diff --git a/tinyNET/test/test_tls.h b/tinyNET/test/test_tls.h new file mode 100644 index 0000000..48ae865 --- /dev/null +++ b/tinyNET/test/test_tls.h @@ -0,0 +1,105 @@ +/* Copyright (C) 2014 Mamadou DIOP. +* +* This file is part of Open Source Doubango Framework. +* +* DOUBANGO is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* DOUBANGO is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Lesser General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with DOUBANGO. +* +*/ +#ifndef TNET_TEST_TLS_H +#define TNET_TEST_TLS_H + +#define TEST_TLS_REMOTE_IP "192.168.16.225" +#define TEST_TLS_REMOTE_PORT 4061 + +#define TLS_TEST_SIP_MESSAGE \ + "REGISTER sip:micromethod.com SIP/2.0\r\n" \ + "Via: SIP/2.0/%s %s:%d;rport;branch=z9hG4bK1245420841406%d\r\n" \ + "From: <sip:mamadou@micromethod.com>;tag=29358\r\n" \ + "To: <sip:mamadou@micromethod.com>\r\n" \ + "Call-ID: M-fa53180346f7f55ceb8d8670f9223dbb\r\n" \ + "CSeq: 201 REGISTER\r\n" \ + "Max-Forwards: 70\r\n" \ + "Contact: <sip:mamadou@%s:%d;transport=%s>\r\n" \ + "Expires: 10\r\n" \ + "\r\n" + +static int tnet_tls_cb(const tnet_transport_event_t* e) +{ + switch(e->type){ + case event_data: + { + TSK_DEBUG_INFO("--- TLS ---\n%s\n", (const char*)e->data); + break; + } + case event_closed: + case event_connected: + default: + { + break; + } + } + return 0; +} + + +void test_tls() +{ + tnet_transport_handle_t *transport = tnet_transport_create(TNET_SOCKET_HOST_ANY, TNET_SOCKET_PORT_ANY, tnet_socket_type_tls_ipv4, "TLS/IPV4 TRANSPORT"); + + tnet_ip_t ip; + tnet_port_t port; + tnet_fd_t fd = TNET_INVALID_FD; + + if(tnet_transport_start(transport)){ + TSK_DEBUG_ERROR("Failed to create %s.", tnet_transport_get_description(transport)); + return; + } + + /* Set our callback function */ + tnet_transport_set_callback(transport, tnet_tls_cb, "callbackdata"); + + + + /* Connect to the SIP Registrar */ + if((fd = tnet_transport_connectto_2(transport, TEST_TLS_REMOTE_IP, TEST_TLS_REMOTE_PORT)) == TNET_INVALID_FD){ + TSK_DEBUG_ERROR("Failed to connect %s.", tnet_transport_get_description(transport)); + return; + } + + if(tnet_sockfd_waitUntilWritable(fd, TNET_CONNECT_TIMEOUT)){ + TSK_DEBUG_ERROR("%d milliseconds elapsed and the socket is still not connected.", TNET_CONNECT_TIMEOUT); + tnet_transport_remove_socket(transport, &fd); + return; + } + + /* Send our SIP message */ + { + char* message = 0; + tnet_transport_get_ip_n_port(transport, fd, &ip, &port); + tsk_sprintf(&message, TLS_TEST_SIP_MESSAGE, "TLS", ip, port, port, ip, port, "tls"); + + if(!tnet_transport_send(transport, fd, message, strlen(message))) + { + TSK_DEBUG_ERROR("Failed to send data using TCP/IPv4 transport."); + TSK_FREE(message); + return; + } + TSK_FREE(message); + } + + TSK_OBJECT_SAFE_FREE(transport); +} + +#endif /* TNET_TEST_TLS_H */ + diff --git a/tinyNET/test/test_transport.h b/tinyNET/test/test_transport.h new file mode 100644 index 0000000..b52b554 --- /dev/null +++ b/tinyNET/test/test_transport.h @@ -0,0 +1,217 @@ +/* Copyright (C) 2014 Mamadou DIOP. +* +* This file is part of Open Source Doubango Framework. +* +* DOUBANGO is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* DOUBANGO is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Lesser General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with DOUBANGO. +* +*/ +#ifndef TNET_TEST_TRANSPORT_H +#define TNET_TEST_TRANSPORT_H + +//#define REMOTE_IP4 "proxy.sipthor.net"//"192.168.0.15" +#define REMOTE_IP4 "192.168.0.13" +#define REMOTE_IP6 "2a01:e35:8632:7050:6122:2706:2124:32cb" +#define REMOTE_IP REMOTE_IP4 +#define REMOTE_PORT 5083 + +#if defined(ANDROID) /* FIXME */ +# define LOCAL_IP4 "10.0.2.15" +#else +# define LOCAL_IP4 TNET_SOCKET_HOST_ANY +#endif +#define LOCAL_IP6 TNET_SOCKET_HOST_ANY + +#if defined(ANDROID) +# define LOCAL_PORT 5060 +#else +# define LOCAL_PORT TNET_SOCKET_PORT_ANY +#endif + +#define SIP_MESSAGE \ + "REGISTER sip:micromethod.com SIP/2.0\r\n" \ + "Via: SIP/2.0/%s %s:%d;rport;branch=z9hG4bK1245420841406%d\r\n" \ + "From: <sip:mamadou@micromethod.com>;tag=29358\r\n" \ + "To: <sip:mamadou@micromethod.com>\r\n" \ + "Call-ID: M-fa53180346f7f55ceb8d8670f9223dbb\r\n" \ + "CSeq: 201 REGISTER\r\n" \ + "Max-Forwards: 70\r\n" \ + "Contact: <sip:mamadou@%s:%d;transport=%s>\r\n" \ + "Expires: 10\r\n" \ + "\r\n" + + +static int tnet_tcp_cb(const tnet_transport_event_t* e) +{ + switch(e->type){ + case event_data: + { + TSK_DEBUG_INFO("--- TCP ---\n%s\n", (const char*)e->data); + break; + } + case event_closed: + case event_connected: + default: + { + break; + } + } + return 0; +} + +static int tnet_udp_cb(const tnet_transport_event_t* e) +{ + switch(e->type){ + case event_data: + { + TSK_DEBUG_INFO("--- UDP ---\n%s\n", (const char*)e->data); + break; + } + case event_closed: + case event_connected: + default: break; + + } + return 0; +} + +void test_transport_tcp_ipv4(tnet_transport_handle_t *transport) +{ + //tnet_socket_type_t type = tnet_socket_type_tcp_ipv4; + tnet_ip_t ip; + tnet_port_t port; + tnet_fd_t fd = TNET_INVALID_FD; + + /* Set our callback function */ + tnet_transport_set_callback(transport, tnet_tcp_cb, "callbackdata"); + + if(tnet_transport_start(transport)){ + TSK_DEBUG_ERROR("Failed to create %s.", tnet_transport_get_description(transport)); + return; + } + + /* Connect to the SIP Registrar */ + if((fd = tnet_transport_connectto_2(transport, REMOTE_IP, REMOTE_PORT)) == TNET_INVALID_FD){ + TSK_DEBUG_ERROR("Failed to connect %s.", tnet_transport_get_description(transport)); + return; + } + + if(tnet_sockfd_waitUntilWritable(fd, TNET_CONNECT_TIMEOUT)){ + TSK_DEBUG_ERROR("%d milliseconds elapsed and the socket is still not connected.", TNET_CONNECT_TIMEOUT); + tnet_transport_remove_socket(transport, &fd); + return; + } + + + /* Send our SIP message */ + { + char* message = 0; + tnet_transport_get_ip_n_port(transport, fd, &ip, &port); + tsk_sprintf(&message, SIP_MESSAGE, "TCP", ip, port, port, ip, port, "tcp"); + + if(!tnet_transport_send(transport, fd, message, strlen(message))) + { + TSK_DEBUG_ERROR("Failed to send data using %s.", tnet_transport_get_description(transport)); + TSK_FREE(message); + return; + } + TSK_FREE(message); + } + +} + + +int test_transport_udp_ipv4(tnet_transport_handle_t *transport) +{ + //tnet_socket_type_t type = tnet_socket_type_udp_ipv4; + tnet_ip_t ip; + tnet_port_t port; + tnet_fd_t fd = TNET_INVALID_FD; + + /* Set our callback function */ + tnet_transport_set_callback(transport, tnet_udp_cb, "callbackdata"); + + if(tnet_transport_start(transport)){ + TSK_DEBUG_ERROR("Failed to create %s.", tnet_transport_get_description(transport)); + return -1; + } + + /* Connect to our SIP REGISTRAR */ + if((fd = tnet_transport_connectto_2(transport, REMOTE_IP, REMOTE_PORT)) == TNET_INVALID_FD){ + TSK_DEBUG_ERROR("Failed to connect %s.", tnet_transport_get_description(transport)); + //tnet_transport_shutdown(transport); + return -2; + } + + if(tnet_sockfd_waitUntilWritable(fd, TNET_CONNECT_TIMEOUT)){ + TSK_DEBUG_ERROR("%d milliseconds elapsed and the socket is still not connected.", TNET_CONNECT_TIMEOUT); + tnet_transport_remove_socket(transport, &fd); + return -3; + } + + //tsk_thread_sleep(2000); + + /* Send our SIP message */ + /*while(1)*/{ + char* message = 0; + tnet_transport_get_ip_n_port(transport, fd, &ip, &port); + //memset(ip, 0, sizeof(ip)); + //memcpy(ip, "192.168.0.12", 12); + tsk_sprintf(&message, SIP_MESSAGE, "UDP", ip, port, port, ip, port, "udp"); + + if(!tnet_transport_send(transport, fd, message, strlen(message))) + { + TSK_DEBUG_ERROR("Failed to send data using %s.", tnet_transport_get_description(transport)); + //tnet_transport_shutdown(transport); + TSK_FREE(message); + return -4; + } + TSK_FREE(message); + } + + return 0; +} + +void test_transport() +{ +#define TEST_TCP 1 +#define TEST_UDP 0 + + +#if TEST_UDP + tnet_transport_handle_t *udp = tnet_transport_create(LOCAL_IP4, LOCAL_PORT, tnet_socket_type_udp_ipv4, "UDP/IPV4 TRANSPORT"); + test_transport_udp_ipv4(udp); +#endif + +#if TEST_TCP + tnet_transport_handle_t *tcp = tnet_transport_create(LOCAL_IP4, LOCAL_PORT, tnet_socket_type_tcp_ipv4, "TCP/IPV4 TRANSPORT"); + test_transport_tcp_ipv4(tcp); +#endif + +//#if defined(ANDROID) + tsk_thread_sleep(1000000); +//#else + getchar(); +//#endif + +#if TEST_UDP + TSK_OBJECT_SAFE_FREE(udp); +#endif + +#if TEST_TCP + TSK_OBJECT_SAFE_FREE(tcp); +#endif +} + + +#endif /* TNET_TEST_TRANSPORT_H*/ |