summaryrefslogtreecommitdiffstats
path: root/tinyHTTP/test
diff options
context:
space:
mode:
Diffstat (limited to 'tinyHTTP/test')
-rw-r--r--tinyHTTP/test/droid-makefile28
-rw-r--r--tinyHTTP/test/stdafx.c26
-rw-r--r--tinyHTTP/test/stdafx.h35
-rw-r--r--tinyHTTP/test/targetver.h18
-rw-r--r--tinyHTTP/test/test.c86
-rw-r--r--tinyHTTP/test/test.vcproj225
-rw-r--r--tinyHTTP/test/test_auth.h141
-rw-r--r--tinyHTTP/test/test_messages.h81
-rw-r--r--tinyHTTP/test/test_stack.h216
-rw-r--r--tinyHTTP/test/test_url.h93
10 files changed, 949 insertions, 0 deletions
diff --git a/tinyHTTP/test/droid-makefile b/tinyHTTP/test/droid-makefile
new file mode 100644
index 0000000..c473992
--- /dev/null
+++ b/tinyHTTP/test/droid-makefile
@@ -0,0 +1,28 @@
+APP := test
+
+CFLAGS := $(CFLAGS_COMMON) -I../include -I../../tinySAK/src -I../../tinyNET/src
+LDFLAGS := $(LDFLAGS_COMMON) -Wl,-Bsymbolic,--whole-archive -l$(PROJECT) -ltinySAK -ltinyNET -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/tinyHTTP/test/stdafx.c b/tinyHTTP/test/stdafx.c
new file mode 100644
index 0000000..df71e1b
--- /dev/null
+++ b/tinyHTTP/test/stdafx.c
@@ -0,0 +1,26 @@
+/*
+* Copyright (C) 2009 Mamadou Diop.
+*
+* Contact: Mamadou Diop <diopmamadou(at)doubango.org>
+*
+* 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/tinyHTTP/test/stdafx.h b/tinyHTTP/test/stdafx.h
new file mode 100644
index 0000000..f296129
--- /dev/null
+++ b/tinyHTTP/test/stdafx.h
@@ -0,0 +1,35 @@
+/*
+* Copyright (C) 2009 Mamadou Diop.
+*
+* Contact: Mamadou Diop <diopmamadou(at)doubango.org>
+*
+* 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_TINYHTTP_STDAFX_H
+#define TEST_TINYHTTP_STDAFX_H
+
+#include "targetver.h"
+
+#include <stdio.h>
+
+#if (defined(_WIN32) || defined(WIN32) || defined(_WIN32_WCE)) && !defined(__SYMBIAN32__)
+#include <tchar.h>
+#endif
+
+// TODO: reference additional headers your program requires here
+#endif /* TEST_TINYHTTP_STDAFX_H */
diff --git a/tinyHTTP/test/targetver.h b/tinyHTTP/test/targetver.h
new file mode 100644
index 0000000..5949a8b
--- /dev/null
+++ b/tinyHTTP/test/targetver.h
@@ -0,0 +1,18 @@
+#ifndef _TEST_TINYHTTP_VER
+#define _TEST_TINYHTTP_VER
+
+#if (defined(_WIN32) || defined(WIN32) || defined(_WIN32_WCE)) && !defined(__SYMBIAN32__)
+// 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 0x0600 // Change this to the appropriate value to target other versions of Windows.
+#endif
+
+#endif
+
+#endif
diff --git a/tinyHTTP/test/test.c b/tinyHTTP/test/test.c
new file mode 100644
index 0000000..8622f10
--- /dev/null
+++ b/tinyHTTP/test/test.c
@@ -0,0 +1,86 @@
+/*
+* Copyright (C) 2009 Mamadou Diop.
+*
+* Contact: Mamadou Diop <diopmamadou(at)doubango.org>
+*
+* 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"
+#include <string.h>
+#include <stdlib.h>
+#include <assert.h>
+
+//#include "tsk.h"
+//#include "tnet.h"
+
+#include "tinyhttp.h"
+
+//#include "thttp.h"
+//#include "tinyHTTP/thttp_message.h"
+//#include "tinyHTTP/auth/thttp_auth.h"
+
+#define LOOP 1
+
+#define RUN_TEST_ALL 0
+#define RUN_TEST_AUTH 0
+#define RUN_TEST_STACK 1
+#define RUN_TEST_URL 0
+#define RUN_TEST_MSGS 0
+
+#include "test_auth.h"
+#include "test_stack.h"
+#include "test_url.h"
+#include "test_messages.h"
+
+
+#ifdef _WIN32_WCE
+int _tmain(int argc, _TCHAR* argv[])
+#else
+int main()
+#endif
+{
+ tnet_startup();
+
+ do{
+ /* Print copyright information */
+ printf("Doubango Project\nCopyright (C) 2009-2010 Mamadou Diop \n\n");
+
+#if RUN_TEST_AUTH || RUN_TEST_ALL
+ test_basic_auth();
+ test_digest_auth();
+#endif
+
+#if RUN_TEST_STACK || RUN_TEST_ALL
+ test_stack();
+#endif
+
+#if RUN_TEST_URL || RUN_TEST_ALL
+ test_url();
+#endif
+
+#if RUN_TEST_MSGS || RUN_TEST_ALL
+ test_messages();
+#endif
+
+ }
+ while(LOOP);
+
+ tnet_cleanup();
+
+ return 0;
+}
+
diff --git a/tinyHTTP/test/test.vcproj b/tinyHTTP/test/test.vcproj
new file mode 100644
index 0000000..6bc1f5f
--- /dev/null
+++ b/tinyHTTP/test/test.vcproj
@@ -0,0 +1,225 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="9.00"
+ Name="test"
+ ProjectGUID="{BE242939-1E65-4875-A3E7-41D8B77D187F}"
+ RootNamespace="test"
+ Keyword="Win32Proj"
+ TargetFrameworkVersion="196613"
+ >
+ <Platforms>
+ <Platform
+ Name="Win32"
+ />
+ </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;..\..\tinyHTTP\include;..\..\tinySAK\src;..\..\tinyNET\src"
+ PreprocessorDefinitions="DEBUG_LEVEL=DEBUG_LEVEL_INFO;WIN32;_DEBUG;_CONSOLE;_WIN32_WINNT 0x0501"
+ MinimalRebuild="true"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="3"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ DebugInformationFormat="4"
+ CompileAs="1"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="$(OutDir)\tinySAK.lib $(OutDir)\tinyHTTP.lib $(OutDir)\tinyNET.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="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>
+ </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"
+ Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
+ UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
+ >
+ <File
+ RelativePath=".\test_auth.h"
+ >
+ </File>
+ <File
+ RelativePath=".\test_messages.h"
+ >
+ </File>
+ <File
+ RelativePath=".\test_stack.h"
+ >
+ </File>
+ <File
+ RelativePath=".\test_url.h"
+ >
+ </File>
+ </Filter>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
diff --git a/tinyHTTP/test/test_auth.h b/tinyHTTP/test/test_auth.h
new file mode 100644
index 0000000..5930a1b
--- /dev/null
+++ b/tinyHTTP/test/test_auth.h
@@ -0,0 +1,141 @@
+/*
+* Copyright (C) 2009 Mamadou Diop.
+*
+* Contact: Mamadou Diop <diopmamadou(at)doubango.org>
+*
+* 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_AUTH_H_
+#define _TEST_AUTH_H_
+
+struct auth_basic_msg
+{
+ const char* userid;
+ const char* password;
+
+ const char* xres;
+};
+
+struct auth_basic_msg auth_basic_msgs[] =
+{
+ { "Aladdin"/*Ali baba*/, "open sesame", "QWxhZGRpbjpvcGVuIHNlc2FtZQ==" },
+};
+
+void test_basic_auth()
+{
+ char *response = tsk_null;
+ size_t i, size;
+
+ for(i=0; i<sizeof(auth_basic_msgs)/sizeof(struct auth_basic_msg); i++)
+ {
+ size = thttp_auth_basic_response(auth_basic_msgs[i].userid, auth_basic_msgs[i].password, &response);
+ if(tsk_striequals(auth_basic_msgs[i].xres, response)){
+ TSK_DEBUG_INFO("[HTTP_BASIC-%d] ==> OK", i);
+ }
+ else{
+ TSK_DEBUG_INFO("[HTTP_BASIC-%d] ==> NOK", i);
+ }
+
+ TSK_FREE(response);
+ }
+}
+
+//========================================================================
+
+
+struct auth_digest_msg
+{
+ const char* username;
+ const char* password;
+ const char* realm;
+ const char* nonce;
+ const char* method;
+ const char* uri;
+ const char* qop;
+ const char* nc;
+ const char* cnonce;
+ const char* opaque;
+ const char* entitybody;
+
+ const char* response;
+};
+
+struct auth_digest_msg auth_digest_msgs[] =
+{
+ {
+ "Mufasa",
+ "Circle Of Life",
+ "testrealm@host.com",
+ "dcd98b7102dd2f0e8b11d0f600bfb0c093",
+ "GET",
+ "/dir/index.html",
+ "auth",
+ "00000001",
+ "0a4f113b",
+ "5ccc069c403ebaf9f0171e9517f40e41",
+ 0,
+
+ "6629fae49393a05397450978507c4ef1"
+ }
+ ,
+
+
+};
+
+void test_digest_auth()
+{
+ tsk_md5string_t response, ha1, ha2;
+ size_t i;
+
+ for(i=0; i<sizeof(auth_digest_msgs)/sizeof(struct auth_digest_msg); i++)
+ {
+ tsk_buffer_t* entitybody;
+ /* HA1 */
+ thttp_auth_digest_HA1(auth_digest_msgs[i].username,
+ auth_digest_msgs[i].realm,
+ auth_digest_msgs[i].password,
+ &ha1);
+
+ /* HA2 */
+ entitybody = tsk_buffer_create(auth_digest_msgs[i].entitybody, strlen(auth_digest_msgs[i].entitybody));
+ thttp_auth_digest_HA2(auth_digest_msgs[i].method,
+ auth_digest_msgs[i].uri,
+ entitybody,
+ auth_digest_msgs[i].qop,
+ &ha2);
+ TSK_OBJECT_SAFE_FREE(entitybody);
+
+ /* RESPONSE */
+ thttp_auth_digest_response(&ha1,
+ auth_digest_msgs[i].nonce,
+ auth_digest_msgs[i].nc,
+ auth_digest_msgs[i].cnonce,
+ auth_digest_msgs[i].qop,
+ &ha2,
+ &response);
+
+ if(tsk_striequals(auth_digest_msgs[i].response, response)){
+ TSK_DEBUG_INFO("[HTTP_DIGEST-%d] ==> OK", i);
+ }
+ else{
+ TSK_DEBUG_INFO("[HTTP_DIGEST-%d] ==> NOK", i);
+ }
+ }
+}
+
+
+#endif /* _TEST_AUTH_H_ */
diff --git a/tinyHTTP/test/test_messages.h b/tinyHTTP/test/test_messages.h
new file mode 100644
index 0000000..a8f5151
--- /dev/null
+++ b/tinyHTTP/test/test_messages.h
@@ -0,0 +1,81 @@
+/*
+* Copyright (C) 2009 Mamadou Diop.
+*
+* Contact: Mamadou Diop <diopmamadou(at)doubango.org>
+*
+* 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_MESSAGES_H_
+#define _TEST_MESSAGES_H_
+
+#define TEST_MSG_200 \
+ "HTTP/1.1 200 OK\r\n" \
+ "Date: Wed, 10 Mar 2010 13:37:13 GMT\r\n" \
+ "Server: Apache\r\n" \
+ "Content-length: 3\r\n" \
+ "Expires: Sat, 07 Aug 2010 13:37:13 +0000\r\n" \
+ "Cache-Control: public\r\n" \
+ "X-Deezer-Cache: HIT\r\n" \
+ "Pragma: \r\n" \
+ "Keep-Alive: timeout=2, max=100\r\n" \
+ "Connection: Keep-Alive\r\n" \
+ "Content-Type: video/flv\r\n" \
+ "\r\n" \
+ "123"
+
+#define TEST_MSG_401 \
+ "HTTP/1.1 401 Unauthorized\r\n" \
+ "Server: Apache-Coyote/1.1\r\n" \
+ "WWW-Authenticate: Digest realm=\"example.com\", qop=\"auth\", nonce=\"f39d20a4dbfbd32d943de9b285d59a30\", opaque=\"c5ad02feb52eb050e464cec3740c0f2e\"\r\n" \
+ "WWW-Authenticate: Basic realm=\"WallyWorld\"\r\n" \
+ "Transfer-Encoding: chunked;test=21;tes7\r\n" \
+ "Date: Wed, 10 Mar 2010 14:20:47 GMT\r\n" \
+ "Etag: W/\"1231-3213213\"\r\n" \
+ "\r\n"
+
+#define TEST_MSG TEST_MSG_401
+
+
+void test_messages()
+{
+ thttp_message_t *message = tsk_null;
+ tsk_ragel_state_t state;
+ int ret;
+ uint8_t c = 'à';
+
+ /* deserialize the message */
+ tsk_ragel_state_init(&state, TEST_MSG, strlen(TEST_MSG));
+ if(!(ret = thttp_message_parse(&state, &message, tsk_true))){
+ tsk_buffer_t *buffer = tsk_buffer_create_null();
+
+ /* serialize the message */
+ thttp_message_serialize(message, buffer);
+ TSK_DEBUG_INFO("HTTP Message=\n%s", TSK_BUFFER_TO_STRING(buffer));
+
+ TSK_OBJECT_SAFE_FREE(buffer);
+ }
+ else{
+ TSK_DEBUG_ERROR("Failed to parse HTTP message.");
+ }
+
+ TSK_OBJECT_SAFE_FREE(message);
+
+ getchar();
+}
+
+#endif /* _TEST_MESSAGES_H_ */
+
diff --git a/tinyHTTP/test/test_stack.h b/tinyHTTP/test/test_stack.h
new file mode 100644
index 0000000..07f5efc
--- /dev/null
+++ b/tinyHTTP/test/test_stack.h
@@ -0,0 +1,216 @@
+/*
+* Copyright (C) 2009 Mamadou Diop.
+*
+* Contact: Mamadou Diop <diopmamadou(at)doubango.org>
+*
+* 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_STACK_H_
+#define _TEST_STACK_H_
+
+int test_stack_callback(const thttp_event_t *httpevent)
+{
+ thttp_session_id_t id = thttp_session_get_id(httpevent->session);
+ switch(httpevent->type){
+ case thttp_event_message: /* New HTTP message */
+ {
+ TSK_DEBUG_INFO("sid=%llu", id);
+ if(THTTP_MESSAGE_IS_RESPONSE(httpevent->message)){
+ const thttp_header_ETag_t* etag;
+ TSK_DEBUG_INFO("=== %d ==> %s", THTTP_RESPONSE_CODE(httpevent->message), THTTP_MESSAGE_CONTENT(httpevent->message));
+ // You can use
+ if((etag = (const thttp_header_ETag_t*)thttp_message_get_header(httpevent->message, thttp_htype_ETag))){
+ TSK_DEBUG_INFO("Etag=%s", etag->value);
+ }
+ }
+ else{
+ if(THTTP_MESSAGE_IS_RESPONSE(httpevent->message)){
+ TSK_DEBUG_INFO("=== code ==> %u", THTTP_RESPONSE_CODE(httpevent->message));
+ }
+ }
+ break;
+ }
+
+ case thttp_event_auth_failed:
+ {
+ TSK_DEBUG_INFO("auth failed sid=%llu", id);
+ break;
+ }
+
+ case thttp_event_closed: /* HTTP connection closed (informational) */
+ {
+ TSK_DEBUG_INFO("closed sid=%llu", id);
+ break;
+ }
+
+ case thttp_event_transport_error: /* HTTP connection closed (informational) */
+ {
+ TSK_DEBUG_INFO("Transport sid=%llu", id);
+ break;
+ }
+ }
+
+ return 0;
+}
+
+#define PAYLOAD "<entry uri=\"sip:samba@micromethod.com\" xmlns=\"urn:ietf:params:xml:ns:resource-lists\">" \
+ "<display-name>samba</display-name>" \
+ "</entry>"
+
+void test_stack()
+{
+ thttp_session_handle_t *session = tsk_null;
+ int ret;
+
+ thttp_stack_handle_t* stack = thttp_stack_create(test_stack_callback,
+#if defined(ANDROID)
+ THTTP_STACK_SET_LOCAL_IP("10.0.2.15"),
+#endif
+ THTTP_STACK_SET_NULL());
+
+ if((ret = thttp_stack_start(stack))){
+ TSK_DEBUG_ERROR("Failed to start the HTTP/HTTPS stack.");
+ goto bail;
+ }
+
+
+ // http://ipv6.google.com/
+ //op = THTTP_OPERATION_CREATE(stack,
+ // THTTP_OPERATION_SET_PARAM("method", "GET"),
+ // THTTP_OPERATION_SET_PARAM("URL", "http://siptest.doubango.org:8080/services/resource-lists/users/sip:mercuro1@doubango.org/index"),
+ //
+ // THTTP_OPERATION_SET_HEADER("Content-Type", "application/resource-lists+xml"),
+ // THTTP_OPERATION_SET_HEADER("Pragma", "No-Cache"),
+ // THTTP_OPERATION_SET_HEADER("Connection", "Keep-Alive"),
+ // THTTP_OPERATION_SET_HEADER("User-Agent", "XDM-client/OMA1.1"),
+ // THTTP_OPERATION_SET_HEADER("X-3GPP-Intended-Identity", "sip:mercuro1@doubango.org"),
+ //
+ // THTTP_OPERATION_SET_NULL());
+ //thttp_operation_perform(op);
+
+ /* creates session */
+ session = thttp_session_create(stack,
+ // session-level options
+ THTTP_SESSION_SET_OPTION(THTTP_SESSION_OPTION_TIMEOUT, "6000"),
+
+ // session-level headers
+ THTTP_SESSION_SET_HEADER("Pragma", "No-Cache"),
+ THTTP_SESSION_SET_HEADER("Connection", "Keep-Alive"),
+ // THTTP_SESSION_SET_HEADER("Connection", "close"),
+ THTTP_SESSION_SET_HEADER("User-Agent", "doubango 1.0"),
+
+ THTTP_SESSION_SET_NULL()); /* MUST always be present */
+
+ //ret = thttp_action_GET(session, "http://siptest.doubango.org:8080/services/resource-lists/users/sip:mercuro1@doubango.org/index",
+ // THTTP_ACTION_SET_HEADER("Content-Type", "application/resource-lists+xml"),
+ //
+ // tsk_null);
+
+ //getchar();
+
+ //thttp_action_GET(session, "http://siptest.doubango.org:8080/services/resource-lists/users/sip:mercuro1@doubango.org/index",
+ // THTTP_ACTION_SET_HEADER("Content-Type", "application/resource-lists+xml"),
+ //
+ // tsk_null);
+
+ //getchar();
+
+
+ thttp_action_GET(session, "http://ipv6.google.com",
+ // action-level options
+ THTTP_ACTION_SET_OPTION(THTTP_ACTION_OPTION_TIMEOUT, "2500"),
+
+ // action-level headers
+ THTTP_ACTION_SET_HEADER("User-Agent", "XDM-client/OMA1.1"),
+ THTTP_ACTION_SET_HEADER("Connection", "Keep-Alive"),
+
+ THTTP_ACTION_SET_NULL());
+ getchar();
+ ret = thttp_action_GET(session, "http://doubango.org",
+ // action-level options
+ THTTP_ACTION_SET_OPTION(THTTP_ACTION_OPTION_TIMEOUT, "2500"),
+
+ THTTP_ACTION_SET_NULL());
+
+ getchar();
+
+ //thttp_action_GET(session, "http://www.google.com",
+ //THTTP_ACTION_SET_HEADER("Content-Type", "application/resource-lists+xml"),
+
+ // THTTP_ACTION_SET_NULL());
+
+ //thttp_action_GET(session, "http://www.doubango.org",
+
+ // THTTP_ACTION_SET_NULL());
+
+ /* Gets resource-lists document */
+ thttp_action_GET(session, "http://siptest.doubango.org:8080/services/resource-lists/users/sip:mercuro1@doubango.org/index",
+ THTTP_ACTION_SET_HEADER("Content-Type", "application/resource-lists+xml"),
+
+ tsk_null);
+
+ getchar();
+
+ //TSK_OBJECT_SAFE_FREE(session);
+
+ //getchar();
+
+ /* Gets xcap-caps document */
+ thttp_action_GET(session, "http://siptest.doubango.org:8080/services/xcap-caps/global/index",
+ THTTP_ACTION_SET_HEADER("Content-Type", "application/xcap-caps+xml"),
+
+ tsk_null);
+
+ getchar();
+
+ thttp_action_GET(session, "http://siptest.doubango.org:8080/services/resource-lists/users/sip:mercuro1@doubango.org/properties-resource-list.xml",
+ THTTP_ACTION_SET_HEADER("Content-Type", "application/resource-lists+xml"),
+
+ tsk_null);
+
+ getchar();
+
+ //thttp_operation_perform(op);
+
+/*
+ op = THTTP_OPERATION_CREATE(stack,
+ THTTP_OPERATION_SET_PARAM("method", "GET"),
+ //THTTP_OPERATION_SET_PARAM("URL", "https://msp.f-secure.com/web-test/common/test.html"),
+ THTTP_OPERATION_SET_PARAM("URL", "http://www.doubango.org"),
+
+ THTTP_OPERATION_SET_HEADER("Pragma", "No-Cache"),
+ THTTP_OPERATION_SET_HEADER("Connection", "Keep-Alive"),
+ THTTP_OPERATION_SET_HEADER("User-Agent", "XDM-client/OMA1.1"),
+
+ THTTP_OPERATION_SET_NULL());
+ thttp_operation_perform(op);
+*/
+ /*thttp_operation_set(op,
+ THTTP_OPERATION_SET_PARAM("method", "HEAD"),
+
+ THTTP_OPERATION_SET_NULL());
+ thttp_operation_perform(op);*/
+
+ getchar();
+bail:
+ TSK_OBJECT_SAFE_FREE(session);
+ TSK_OBJECT_SAFE_FREE(stack);
+}
+
+#endif /* _TEST_STACK_H_ */
+
+
diff --git a/tinyHTTP/test/test_url.h b/tinyHTTP/test/test_url.h
new file mode 100644
index 0000000..12c3b5d
--- /dev/null
+++ b/tinyHTTP/test/test_url.h
@@ -0,0 +1,93 @@
+/*
+* Copyright (C) 2009 Mamadou Diop.
+*
+* Contact: Mamadou Diop <diopmamadou(at)doubango.org>
+*
+* 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 General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with DOUBANGO.
+*
+*/
+#ifndef _TEST_HTTPURL_H
+#define _TEST_HTTPURL_H
+
+#include "tinyhttp/parsers/thttp_parser_url.h"
+
+const char* urls[] =
+{
+
+ //== HTTP:
+ "http://www.doubango.org",
+ "http://www.doubango.org/?p=1",
+ "http://doubango.org:452/test",
+ "http://doubango.org:45/test?p=452",
+
+ //== HTTPS:
+ "https://www.doubango.org",
+ "https://www.doubango.org/?p=1",
+ "https://doubango.org:452/test",
+ "https://doubango.org:45/test?p=452",
+};
+#include "tsk_string.h"
+
+void test_url_tostring(const thttp_url_t *url)
+{
+ char* ret = thttp_url_tostring(url);
+ TSK_DEBUG_INFO("url_to_string=%s", ret);
+ TSK_FREE(ret);
+}
+
+void test_url_parser()
+{
+ int i;
+
+ for(i=0; i<sizeof(urls)/sizeof(const char*); i++)
+ {
+ thttp_url_t *url = thttp_url_parse(urls[i], strlen(urls[i]));
+
+ printf("\n== Parsing {{ %s }} ==\n\n", urls[i]);
+
+ if(url)
+ {
+ printf("scheme: %s\n", url->scheme);
+ printf("host: %s\n", url->host);
+ printf("port: %u\n", url->port);
+ printf("hpath: %s\n", url->hpath);
+ printf("search: %s\n", url->search);
+ printf("host-type: %s\n", url->host_type == thttp_host_ipv4 ? "IPv4" : (url->host_type == thttp_host_ipv6 ? "IPv6" : (url->host_type == thttp_host_hostname ? "HOSTNAME" : "UNKNOWN")) );
+
+ printf("---PARAMS---\n");
+
+ printf("Is-secure: %s\n", THTTP_URL_IS_SECURE(url) ? "YES" : "NO");
+
+ test_url_tostring(url);
+ }
+ else
+ {
+ printf("INVALID HTTP URL.\n");
+ }
+
+ printf("\n\n");
+ getchar();
+
+ TSK_OBJECT_SAFE_FREE(url);
+ }
+}
+
+void test_url()
+{
+ test_url_parser();
+}
+
+#endif /* _TEST_HTTPURL_H */
OpenPOWER on IntegriCloud