1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
|
/*
* 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,
THTTP_STACK_SET_TLS_ENABLED(tsk_true),
//THTTP_STACK_SET_TLS_CERTS_VERIFY(tsk_false),
//THTTP_STACK_SET_LOCAL_IP("0.0.0.0"),
//THTTP_STACK_SET_LOCAL_PORT(8080),
//THTTP_STACK_SET_PROXY("msp.f-secure.com", 443),
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();
// HTTPS
thttp_action_GET(session, "https://msp.f-secure.com/web-test/common/test.html",
// action-level options
THTTP_ACTION_SET_OPTION(THTTP_ACTION_OPTION_TIMEOUT, "2500"),
// action-level headers
THTTP_ACTION_SET_HEADER("User-Agent", "Doubango"),
THTTP_ACTION_SET_HEADER("Connection", "Keep-Alive"),
THTTP_ACTION_SET_NULL());
getchar();
// IPv6
/*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_ */
|