1 /* This case tests the get content length task which should allow zero or more white
2 spaces between field name (Content-Length) and value.
3 */
4 #include "tx_api.h"
5 #include "nx_api.h"
6 #include "fx_api.h"
7 #include "nx_web_http_client.h"
8 #include "nx_web_http_server.h"
9
10 extern void test_control_return(UINT);
11
12 #if !defined(NX_DISABLE_IPV4)
13
14 #include "test_device_cert.c"
15 #include "test_ca_cert.c"
16 #define ca_cert_der test_ca_cert_der
17 #define ca_cert_der_len test_ca_cert_der_len
18
19 #define DEMO_STACK_SIZE 4096
20
21 /* Set up FileX and file memory resources. */
22 static CHAR ram_disk_memory[4096];
23 static FX_MEDIA ram_disk;
24 static UCHAR media_memory[4096];
25
26 static UCHAR server_stack[16000];
27
28 /* Define device drivers. */
29 extern void _fx_ram_driver(FX_MEDIA *media_ptr);
30 extern void _nx_ram_network_driver_1024(NX_IP_DRIVER *driver_req_ptr);
31
32 /* Set up the HTTP client global variables. */
33
34 #define CLIENT_PACKET_SIZE (NX_WEB_HTTP_CLIENT_MIN_PACKET_SIZE * 2)
35
36 static TX_THREAD client_thread;
37 static NX_PACKET_POOL client_pool;
38 static NX_WEB_HTTP_CLIENT my_client;
39 static NX_IP client_ip;
40 static UINT error_counter;
41
42 /* Set up the HTTP server global variables */
43
44 #define SERVER_PACKET_SIZE (NX_WEB_HTTP_SERVER_MIN_PACKET_SIZE * 2)
45
46 static NX_WEB_HTTP_SERVER my_server;
47 static NX_PACKET_POOL server_pool;
48 static TX_THREAD server_thread;
49 static NX_IP server_ip;
50 static NXD_ADDRESS server_ip_address;
51 static UINT http_server_start = 0;
52 static UINT http_client_stop = 0;
53
54 static void thread_client_entry(ULONG thread_input);
55 static void thread_server_entry(ULONG thread_input);
56
57 #define HTTP_SERVER_ADDRESS IP_ADDRESS(192,168,0,105)
58 #define HTTP_CLIENT_ADDRESS IP_ADDRESS(192,168,0,123)
59
60 #ifdef NX_WEB_HTTPS_ENABLE
61 static UINT https_server_start = 0;
62 static UINT https_client_stop = 0;
63 static UINT loop = 2;
64 extern const NX_SECURE_TLS_CRYPTO nx_crypto_tls_ciphers;
65 static CHAR crypto_metadata_server[20000 * NX_WEB_HTTP_SERVER_SESSION_MAX];
66 static CHAR crypto_metadata_client[20000 * NX_WEB_HTTP_SERVER_SESSION_MAX];
67 static UCHAR tls_packet_buffer[18500];
68 static NX_SECURE_X509_CERT certificate;
69 static NX_SECURE_X509_CERT trusted_certificate;
70 static NX_SECURE_X509_CERT remote_certificate, remote_issuer;
71 static UCHAR remote_cert_buffer[2000];
72 static UCHAR remote_issuer_buffer[2000];
73 #else
74 static UINT loop = 1;
75 #endif /* NX_WEB_HTTPS_ENABLE */
76
77 static void http_test_initialize();
78 static UINT server_request_callback(NX_WEB_HTTP_SERVER *server_ptr, UINT request_type, CHAR *resource, NX_PACKET *packet_ptr);
79
80 static char get_response_packet[130] = {
81 0x48, 0x54, /* ......HT */
82 0x54, 0x50, 0x2f, 0x31, 0x2e, 0x30, 0x20, 0x32, /* TP/1.0 2 */
83 0x30, 0x30, 0x20, 0x0d, 0x0a, 0x43, 0x6f, 0x6e, /* 00 ..Con */
84 0x74, 0x65, 0x6e, 0x74, 0x2d, 0x4c, 0x65, 0x6e, /* tent-Len */
85 0x67, 0x74, 0x68, 0x3a, 0x20, 0x34, 0x31, 0x35, /* gth: 415 */
86 0x34, 0x0d, 0x0a, 0x43, 0x6f, 0x6e, 0x74, 0x65, /* 4..Conte */
87 0x6e, 0x74, 0x2d, 0x54, 0x79, 0x70, 0x65, 0x3a, /* nt-Type: */
88 0x20, 0x74, 0x65, 0x78, 0x74, 0x2f, 0x70, 0x6c, /* text/pl */
89 0x61, 0x69, 0x6e, 0x0d, 0x0a, 0x0d, 0x0a, 0x3c, /* ain....< */
90 0x68, 0x74, 0x6d, 0x6c, 0x3e, 0x0d, 0x0a, 0x0d, /* html>... */
91 0x0a, 0x3c, 0x68, 0x65, 0x61, 0x64, 0x3e, 0x0d, /* .<head>. */
92 0x0a, 0x0d, 0x0a, 0x3c, 0x74, 0x69, 0x74, 0x6c, /* ...<titl */
93 0x65, 0x3e, 0x4d, 0x61, 0x69, 0x6e, 0x20, 0x57, /* e>Main W */
94 0x69, 0x6e, 0x64, 0x6f, 0x77, 0x3c, 0x2f, 0x74, /* indow</t */
95 0x69, 0x74, 0x6c, 0x65, 0x3e, 0x0d, 0x0a, 0x3c, /* itle>..< */
96 0x2f, 0x68, 0x65, 0x61, 0x64, 0x3e, 0x0d, 0x0a, /* /head>.. */
97 0x0d, 0x0a, 0x3c, 0x62, 0x6f, 0x64, 0x79, 0x3e, /* ..<body> */
98 };
99 static int get_response_size = 130;
100
101 static char get_response_packet_nospace[129] = {
102 0x48, 0x54, /* ......HT */
103 0x54, 0x50, 0x2f, 0x31, 0x2e, 0x30, 0x20, 0x32, /* TP/1.0 2 */
104 0x30, 0x30, 0x20, 0x0d, 0x0a, 0x43, 0x6f, 0x6e, /* 00 ..Con */
105 0x74, 0x65, 0x6e, 0x74, 0x2d, 0x4c, 0x65, 0x6e, /* tent-Len */
106 0x67, 0x74, 0x68, 0x3a, 0x34, 0x31, 0x35, /* gth:415 */
107 0x34, 0x0d, 0x0a, 0x43, 0x6f, 0x6e, 0x74, 0x65, /* 4..Conte */
108 0x6e, 0x74, 0x2d, 0x54, 0x79, 0x70, 0x65, 0x3a, /* nt-Type: */
109 0x20, 0x74, 0x65, 0x78, 0x74, 0x2f, 0x70, 0x6c, /* text/pl */
110 0x61, 0x69, 0x6e, 0x0d, 0x0a, 0x0d, 0x0a, 0x3c, /* ain....< */
111 0x68, 0x74, 0x6d, 0x6c, 0x3e, 0x0d, 0x0a, 0x0d, /* html>... */
112 0x0a, 0x3c, 0x68, 0x65, 0x61, 0x64, 0x3e, 0x0d, /* .<head>. */
113 0x0a, 0x0d, 0x0a, 0x3c, 0x74, 0x69, 0x74, 0x6c, /* ...<titl */
114 0x65, 0x3e, 0x4d, 0x61, 0x69, 0x6e, 0x20, 0x57, /* e>Main W */
115 0x69, 0x6e, 0x64, 0x6f, 0x77, 0x3c, 0x2f, 0x74, /* indow</t */
116 0x69, 0x74, 0x6c, 0x65, 0x3e, 0x0d, 0x0a, 0x3c, /* itle>..< */
117 0x2f, 0x68, 0x65, 0x61, 0x64, 0x3e, 0x0d, 0x0a, /* /head>.. */
118 0x0d, 0x0a, 0x3c, 0x62, 0x6f, 0x64, 0x79, 0x3e, /* ..<body> */
119 };
120 static int get_response_packet_nospace_size = 129;
121
122 static char get_response_packet_3spaces[132] = {
123 0x48, 0x54, /* ......HT */
124 0x54, 0x50, 0x2f, 0x31, 0x2e, 0x30, 0x20, 0x32, /* TP/1.0 2 */
125 0x30, 0x30, 0x20, 0x0d, 0x0a, 0x43, 0x6f, 0x6e, /* 00 ..Con */
126 0x74, 0x65, 0x6e, 0x74, 0x2d, 0x4c, 0x65, 0x6e, /* tent-Len */
127 0x67, 0x74, 0x68, 0x3a, 0x20, 0x20, 0x20, 0x34, 0x31, 0x35, /* gth: 415 */
128 0x34, 0x0d, 0x0a, 0x43, 0x6f, 0x6e, 0x74, 0x65, /* 4..Conte */
129 0x6e, 0x74, 0x2d, 0x54, 0x79, 0x70, 0x65, 0x3a, /* nt-Type: */
130 0x20, 0x74, 0x65, 0x78, 0x74, 0x2f, 0x70, 0x6c, /* text/pl */
131 0x61, 0x69, 0x6e, 0x0d, 0x0a, 0x0d, 0x0a, 0x3c, /* ain....< */
132 0x68, 0x74, 0x6d, 0x6c, 0x3e, 0x0d, 0x0a, 0x0d, /* html>... */
133 0x0a, 0x3c, 0x68, 0x65, 0x61, 0x64, 0x3e, 0x0d, /* .<head>. */
134 0x0a, 0x0d, 0x0a, 0x3c, 0x74, 0x69, 0x74, 0x6c, /* ...<titl */
135 0x65, 0x3e, 0x4d, 0x61, 0x69, 0x6e, 0x20, 0x57, /* e>Main W */
136 0x69, 0x6e, 0x64, 0x6f, 0x77, 0x3c, 0x2f, 0x74, /* indow</t */
137 0x69, 0x74, 0x6c, 0x65, 0x3e, 0x0d, 0x0a, 0x3c, /* itle>..< */
138 0x2f, 0x68, 0x65, 0x61, 0x64, 0x3e, 0x0d, 0x0a, /* /head>.. */
139 0x0d, 0x0a, 0x3c, 0x62, 0x6f, 0x64, 0x79, 0x3e, /* ..<body> */
140 };
141 static int get_response_packet_3spaces_size = 132;
142
143 static char get_response_packet_nolength[130] = {
144 0x48, 0x54, /* ......HT */
145 0x54, 0x50, 0x2f, 0x31, 0x2e, 0x30, 0x20, 0x32, /* TP/1.0 2 */
146 0x30, 0x30, 0x20, 0x0d, 0x0a, 0x43, 0x6f, 0x6e, /* 00 ..Con */
147 0x74, 0x65, 0x6e, 0x74, 0x2d, 0x4c, 0x65, 0x6e, /* tent-Len */
148 0x67, 0x74, 0x68, 0x3a, 0x20, 0x20, 0x20, 0x20, /* gth: */
149 0x20, 0x0d, 0x0a, 0x43, 0x6f, 0x6e, 0x74, 0x65, /* ..Conte */
150 0x6e, 0x74, 0x2d, 0x54, 0x79, 0x70, 0x65, 0x3a, /* nt-Type: */
151 0x20, 0x74, 0x65, 0x78, 0x74, 0x2f, 0x70, 0x6c, /* text/pl */
152 0x61, 0x69, 0x6e, 0x0d, 0x0a, 0x0d, 0x0a, 0x3c, /* ain....< */
153 0x68, 0x74, 0x6d, 0x6c, 0x3e, 0x0d, 0x0a, 0x0d, /* html>... */
154 0x0a, 0x3c, 0x68, 0x65, 0x61, 0x64, 0x3e, 0x0d, /* .<head>. */
155 0x0a, 0x0d, 0x0a, 0x3c, 0x74, 0x69, 0x74, 0x6c, /* ...<titl */
156 0x65, 0x3e, 0x4d, 0x61, 0x69, 0x6e, 0x20, 0x57, /* e>Main W */
157 0x69, 0x6e, 0x64, 0x6f, 0x77, 0x3c, 0x2f, 0x74, /* indow</t */
158 0x69, 0x74, 0x6c, 0x65, 0x3e, 0x0d, 0x0a, 0x3c, /* itle>..< */
159 0x2f, 0x68, 0x65, 0x61, 0x64, 0x3e, 0x0d, 0x0a, /* /head>.. */
160 0x0d, 0x0a, 0x3c, 0x62, 0x6f, 0x64, 0x79, 0x3e, /* ..<body> */
161 };
162 static int get_response_packet_nolength_size = 130;
163
164 static char get_response_packet_error[10] = {
165 0x48, 0x54, /* ......HT */
166 0x54, 0x50, 0x2f, 0x31, 0x0d, 0x0a, 0x0d, 0x0a, /* TP/1.0 2 */
167 };
168 static int get_response_packet_error_size = 10;
169
170 #define RESPONSE_COUNT 5
171
172 typedef struct HTTP_RESPONSE_STRUCT
173 {
174 char *http_response_pkt_data;
175 int http_response_pkt_size;
176 } HTTP_RESPONSE;
177
178 static HTTP_RESPONSE http_response[RESPONSE_COUNT];
179
180 static UINT packet_number = 0;
181
182 #ifdef CTEST
test_application_define(void * first_unused_memory)183 VOID test_application_define(void *first_unused_memory)
184 #else
185 void netx_web_get_content_length_test_application_define(void *first_unused_memory)
186 #endif
187 {
188 CHAR *pointer;
189 UINT status;
190
191
192 error_counter = 0;
193
194 /* Setup the working pointer. */
195 pointer = (CHAR *) first_unused_memory;
196
197 /* Create a helper thread for the server. */
198 tx_thread_create(&server_thread, "HTTP Server thread", thread_server_entry, 0,
199 pointer, DEMO_STACK_SIZE,
200 NX_WEB_HTTP_SERVER_PRIORITY, NX_WEB_HTTP_SERVER_PRIORITY, TX_NO_TIME_SLICE, TX_AUTO_START);
201
202 pointer = pointer + DEMO_STACK_SIZE;
203
204 /* Initialize the NetX system. */
205 nx_system_initialize();
206
207 /* Create the server packet pool. */
208 status = nx_packet_pool_create(&server_pool, "HTTP Server Packet Pool", SERVER_PACKET_SIZE,
209 pointer, SERVER_PACKET_SIZE*8);
210 pointer = pointer + SERVER_PACKET_SIZE * 8;
211 if (status)
212 error_counter++;
213
214 /* Create an IP instance. */
215 status = nx_ip_create(&server_ip, "HTTP Server IP", HTTP_SERVER_ADDRESS,
216 0xFFFFFF00UL, &server_pool, _nx_ram_network_driver_1024,
217 pointer, 4096, 1);
218 pointer = pointer + 4096;
219 if (status)
220 error_counter++;
221
222 /* Enable ARP and supply ARP cache memory for the server IP instance. */
223 status = nx_arp_enable(&server_ip, (void *) pointer, 1024);
224 pointer = pointer + 1024;
225 if (status)
226 error_counter++;
227
228 /* Enable TCP traffic. */
229 status = nx_tcp_enable(&server_ip);
230 if (status)
231 error_counter++;
232
233 /* Create the HTTP Client thread. */
234 status = tx_thread_create(&client_thread, "HTTP Client", thread_client_entry, 0,
235 pointer, DEMO_STACK_SIZE,
236 NX_WEB_HTTP_SERVER_PRIORITY + 2, NX_WEB_HTTP_SERVER_PRIORITY + 2, TX_NO_TIME_SLICE, TX_AUTO_START);
237 pointer = pointer + DEMO_STACK_SIZE;
238 if (status)
239 error_counter++;
240
241 /* Create the Client packet pool. */
242 status = nx_packet_pool_create(&client_pool, "HTTP Client Packet Pool", CLIENT_PACKET_SIZE,
243 pointer, CLIENT_PACKET_SIZE*8);
244 pointer = pointer + CLIENT_PACKET_SIZE * 8;
245 if (status)
246 error_counter++;
247
248 /* Create an IP instance. */
249 status = nx_ip_create(&client_ip, "HTTP Client IP", HTTP_CLIENT_ADDRESS,
250 0xFFFFFF00UL, &client_pool, _nx_ram_network_driver_1024,
251 pointer, 2048, 1);
252 pointer = pointer + 2048;
253 if (status)
254 error_counter++;
255
256 status = nx_arp_enable(&client_ip, (void *) pointer, 1024);
257 pointer = pointer + 2048;
258 if (status)
259 error_counter++;
260
261 /* Enable TCP traffic. */
262 status = nx_tcp_enable(&client_ip);
263 if (status)
264 error_counter++;
265 }
266
267 #ifdef NX_WEB_HTTPS_ENABLE
268 /* Define the TLS setup callback function. */
tls_setup_callback(NX_WEB_HTTP_CLIENT * client_ptr,NX_SECURE_TLS_SESSION * tls_session)269 static UINT tls_setup_callback(NX_WEB_HTTP_CLIENT *client_ptr, NX_SECURE_TLS_SESSION *tls_session)
270 {
271 UINT status;
272
273
274 /* Initialize and create TLS session. */
275 status = nx_secure_tls_session_create(tls_session, &nx_crypto_tls_ciphers, crypto_metadata_client, sizeof(crypto_metadata_client));
276
277 /* Check status. */
278 if (status)
279 {
280 return(status);
281 }
282
283 /* Allocate space for packet reassembly. */
284 status = nx_secure_tls_session_packet_buffer_set(&(client_ptr -> nx_web_http_client_tls_session), tls_packet_buffer, sizeof(tls_packet_buffer));
285
286 /* Check status. */
287 if (status)
288 {
289 return(status);
290 }
291
292 /* Add a CA Certificate to our trusted store for verifying incoming server certificates. */
293 nx_secure_x509_certificate_initialize(&trusted_certificate, ca_cert_der, ca_cert_der_len, NX_NULL, 0, NULL, 0, NX_SECURE_X509_KEY_TYPE_NONE);
294 nx_secure_tls_trusted_certificate_add(&(client_ptr -> nx_web_http_client_tls_session), &trusted_certificate);
295
296 /* Need to allocate space for the certificate coming in from the remote host. */
297 nx_secure_tls_remote_certificate_allocate(&(client_ptr -> nx_web_http_client_tls_session), &remote_certificate, remote_cert_buffer, sizeof(remote_cert_buffer));
298 nx_secure_tls_remote_certificate_allocate(&(client_ptr -> nx_web_http_client_tls_session), &remote_issuer, remote_issuer_buffer, sizeof(remote_issuer_buffer));
299
300 return(NX_SUCCESS);
301 }
302 #endif /* NX_WEB_HTTPS_ENABLE */
303
thread_client_entry(ULONG thread_input)304 void thread_client_entry(ULONG thread_input)
305 {
306 UINT i, j;
307 UINT status;
308 NX_PACKET *recv_packet;
309
310
311 /* Give IP task and driver a chance to initialize the system. */
312 tx_thread_sleep(NX_IP_PERIODIC_RATE);
313
314 /* Set server IP address. */
315 server_ip_address.nxd_ip_address.v4 = HTTP_SERVER_ADDRESS;
316 server_ip_address.nxd_ip_version = NX_IP_VERSION_V4;
317
318 /* First loop test HTTP, second loop test HTTPS. */
319 for (i = 0; i < loop ; i++)
320 {
321 if (i == 0)
322 {
323
324 /* Wait HTTP server started. */
325 while(!http_server_start)
326 {
327 tx_thread_sleep(NX_IP_PERIODIC_RATE);
328 }
329 }
330 #ifdef NX_WEB_HTTPS_ENABLE
331 else
332 {
333
334 /* Wait HTTPS server started. */
335 while(!https_server_start)
336 {
337 tx_thread_sleep(NX_IP_PERIODIC_RATE);
338 }
339 }
340 #endif /* NX_WEB_HTTPS_ENABLE */
341
342 packet_number = 0;
343
344 for (j = 0; j < RESPONSE_COUNT; j++)
345 {
346
347 /* Create an HTTP client instance. */
348 status = nx_web_http_client_create(&my_client, "HTTP Client", &client_ip, &client_pool, 1536);
349
350 /* Check status. */
351 if (status)
352 error_counter++;
353
354 /* Send a GET request. */
355 if (i == 0)
356 {
357 status = nx_web_http_client_get_start(&my_client, &server_ip_address,
358 NX_WEB_HTTP_SERVER_PORT, "/index.htm",
359 "www.abc.com", "name", "password", NX_WAIT_FOREVER);
360 }
361 #ifdef NX_WEB_HTTPS_ENABLE
362 else
363 {
364 status = nx_web_http_client_get_secure_start(&my_client, &server_ip_address,
365 NX_WEB_HTTPS_SERVER_PORT, "/index.htm",
366 "www.abc.com", "name", "password",
367 tls_setup_callback, NX_WAIT_FOREVER);
368 }
369 #endif /* NX_WEB_HTTPS_ENABLE */
370
371 /* Check status. */
372 if (status)
373 error_counter++;
374
375 /* Get response from server. */
376 status = nx_web_http_client_response_body_get(&my_client, &recv_packet, 1 * NX_IP_PERIODIC_RATE);
377
378 /* Check status. */
379 if ((status != NX_SUCCESS) && (status != NX_WEB_HTTP_GET_DONE) && (j < 3))
380 error_counter++;
381 else if (((status == NX_SUCCESS) || (status == NX_WEB_HTTP_GET_DONE)) && (j > 3))
382 error_counter++;
383
384 if (status == NX_SUCCESS)
385 nx_packet_release(recv_packet);
386
387 status = nx_web_http_client_delete(&my_client);
388 if (status)
389 error_counter++;
390 }
391
392 /* Set the flag. */
393 if (i == 0)
394 {
395 http_client_stop = 1;
396 }
397 #ifdef NX_WEB_HTTPS_ENABLE
398 else
399 {
400 https_client_stop = 1;
401 }
402 #endif /* NX_WEB_HTTPS_ENABLE */
403 }
404 }
405
406
407 /* Define the helper HTTP server thread. */
thread_server_entry(ULONG thread_input)408 void thread_server_entry(ULONG thread_input)
409 {
410 UINT i;
411 UINT status;
412 FX_FILE my_file;
413 UINT server_port = NX_WEB_HTTP_SERVER_PORT;
414
415
416 /* Print out test information banner. */
417 printf("NetX Test: Web Get Content-Length Test...............................");
418
419 /* Check for earlier error. */
420 if(error_counter)
421 {
422 printf("ERROR!\n");
423 test_control_return(1);
424 }
425
426 fx_media_format(&ram_disk,
427 _fx_ram_driver, // Driver entry
428 ram_disk_memory, // RAM disk memory pointer
429 media_memory, // Media buffer pointer
430 sizeof(media_memory), // Media buffer size
431 "MY_RAM_DISK", // Volume Name
432 1, // Number of FATs
433 32, // Directory Entries
434 0, // Hidden sectors
435 256, // Total sectors
436 512, // Sector size
437 8, // Sectors per cluster
438 1, // Heads
439 1); // Sectors per track
440
441 /* Open the RAM disk. */
442 status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, media_memory, sizeof(media_memory)) ;
443 status += fx_file_create(&ram_disk, "index.htm");
444 status += fx_file_open(&ram_disk, &my_file, "index.htm", FX_OPEN_FOR_WRITE);
445 status += fx_file_write(&my_file, "https server", 12);
446 status += fx_file_close(&my_file);
447 if(status)
448 error_counter++;
449
450 /* Give NetX a chance to initialize the system. */
451 tx_thread_sleep(NX_IP_PERIODIC_RATE);
452
453 /* Initialize the test data. */
454 http_test_initialize();
455
456 /* First loop test HTTP, second loop test HTTPS. */
457 for (i = 0; i < loop; i++)
458 {
459
460 if (i == 1)
461 {
462 server_port = NX_WEB_HTTPS_SERVER_PORT;
463 }
464
465 /* Create the HTTP Server. */
466 status = nx_web_http_server_create(&my_server, "My HTTP Server", &server_ip, server_port, &ram_disk,
467 &server_stack, sizeof(server_stack), &server_pool,
468 NX_NULL, server_request_callback);
469 if (status)
470 error_counter++;
471
472 #ifdef NX_WEB_HTTPS_ENABLE
473 /* Set TLS for HTTPS. */
474 if (i == 1)
475 {
476 /* Initialize device certificate (used for all sessions in HTTPS server). */
477 memset(&certificate, 0, sizeof(certificate));
478 nx_secure_x509_certificate_initialize(&certificate, test_device_cert_der, test_device_cert_der_len, NX_NULL, 0, test_device_cert_key_der, test_device_cert_key_der_len, NX_SECURE_X509_KEY_TYPE_RSA_PKCS1_DER);
479
480 /* Setup TLS session data for the TCP server. */
481 status = nx_web_http_server_secure_configure(&my_server, &nx_crypto_tls_ciphers,
482 crypto_metadata_server, sizeof(crypto_metadata_server), tls_packet_buffer, sizeof(tls_packet_buffer),
483 &certificate, NX_NULL, 0, NX_NULL, 0, NX_NULL, 0);
484 if (status)
485 error_counter++;
486 }
487 #endif /* NX_WEB_HTTPS_ENABLE */
488
489 /* OK to start the HTTP Server. */
490 status = nx_web_http_server_start(&my_server);
491 if (status)
492 error_counter++;
493
494 /* Set the flag. */
495 if (i == 0)
496 {
497 http_server_start = 1;
498
499 /* Wait HTTP test finished. */
500 while(!http_client_stop)
501 {
502 tx_thread_sleep(NX_IP_PERIODIC_RATE);
503 }
504 }
505 #ifdef NX_WEB_HTTPS_ENABLE
506 else
507 {
508 https_server_start = 1;
509
510 /* Wait HTTPS test finished. */
511 while(!https_client_stop)
512 {
513 tx_thread_sleep(NX_IP_PERIODIC_RATE);
514 }
515 }
516 #endif /* NX_WEB_HTTPS_ENABLE */
517
518 status = nx_web_http_server_delete(&my_server);
519 if (status)
520 error_counter++;
521 }
522
523 /* Check packet pool. */
524 if (server_pool.nx_packet_pool_available != server_pool.nx_packet_pool_total)
525 {
526 error_counter++;
527 }
528
529 if (client_pool.nx_packet_pool_available != client_pool.nx_packet_pool_total)
530 {
531 error_counter++;
532 }
533
534 if(error_counter)
535 {
536 printf("ERROR!\n");
537 test_control_return(1);
538 }
539 else
540 {
541 printf("SUCCESS!\n");
542 test_control_return(0);
543 }
544 }
545
http_test_initialize()546 static void http_test_initialize()
547 {
548
549 http_response[0].http_response_pkt_data = &get_response_packet[0];
550 http_response[0].http_response_pkt_size = get_response_size;
551
552 http_response[1].http_response_pkt_data = &get_response_packet_nospace[0];
553 http_response[1].http_response_pkt_size = get_response_packet_nospace_size;
554
555 http_response[2].http_response_pkt_data = &get_response_packet_3spaces[0];
556 http_response[2].http_response_pkt_size = get_response_packet_3spaces_size;
557
558 http_response[3].http_response_pkt_data = &get_response_packet_nolength[0];
559 http_response[3].http_response_pkt_size = get_response_packet_nolength_size;
560
561 http_response[4].http_response_pkt_data = &get_response_packet_error[0];
562 http_response[4].http_response_pkt_size = get_response_packet_error_size;
563
564 }
565
566 /* Define the server request callback function. */
server_request_callback(NX_WEB_HTTP_SERVER * server_ptr,UINT request_type,CHAR * resource,NX_PACKET * packet_ptr)567 static UINT server_request_callback(NX_WEB_HTTP_SERVER *server_ptr, UINT request_type, CHAR *resource, NX_PACKET *packet_ptr)
568 {
569 NX_PACKET *response_pkt;
570 UINT status;
571
572 /* Process multipart data. */
573 if(request_type == NX_WEB_HTTP_SERVER_GET_REQUEST)
574 {
575
576 /* Allocate a response packet. */
577 status = nx_web_http_server_response_packet_allocate(server_ptr, &response_pkt, TX_WAIT_FOREVER);
578
579 /* Check status. */
580 if (status)
581 {
582 error_counter++;
583 }
584
585 status = nx_packet_data_append(response_pkt, http_response[packet_number].http_response_pkt_data, http_response[packet_number].http_response_pkt_size,
586 &server_pool, NX_WAIT_FOREVER);
587
588 packet_number++;
589
590 if(status == NX_SUCCESS)
591 {
592 if(nx_web_http_server_callback_packet_send(server_ptr, response_pkt) != NX_SUCCESS)
593 {
594 nx_packet_release(response_pkt);
595 }
596 }
597 }
598 else
599 {
600 /* Indicate we have not processed the response to client yet. */
601 return(NX_SUCCESS);
602 }
603
604 /* Indicate the response to client is transmitted. */
605 return(NX_WEB_HTTP_CALLBACK_COMPLETED);
606 }
607
608 #else
609
610 #ifdef CTEST
test_application_define(void * first_unused_memory)611 VOID test_application_define(void *first_unused_memory)
612 #else
613 void netx_web_get_content_length_test_application_define(void *first_unused_memory)
614 #endif
615 {
616
617 /* Print out test information banner. */
618 printf("NetX Test: Web Get Content-Length Test...............................N/A\n");
619
620 test_control_return(3);
621 }
622 #endif
623