1 /* This case tests basic GET method. */
2 #include "tx_api.h"
3 #include "nx_api.h"
4 #include "fx_api.h"
5 #include "nx_web_http_client.h"
6 #include "nx_web_http_server.h"
7
8 extern void test_control_return(UINT);
9
10 #if !defined(NX_DISABLE_IPV4)
11
12 #define DEMO_STACK_SIZE 4096
13
14 /* Define device drivers. */
15 extern void _nx_pcap_network_driver(NX_IP_DRIVER*);
16
17 /* Set up the HTTP client global variables. */
18
19 #define CLIENT_PACKET_SIZE (NX_WEB_HTTP_CLIENT_MIN_PACKET_SIZE * 2)
20
21 static TX_THREAD client_thread;
22 static NX_PACKET_POOL client_pool;
23 static NX_WEB_HTTP_CLIENT my_client;
24 static NX_IP client_ip;
25 static UINT error_counter;
26 static NXD_ADDRESS server_ip_address;
27
28 static void thread_client_entry(ULONG thread_input);
29
30 #define GATEWAY_IP_ADDRESS IP_ADDRESS(192, 168, 100, 1)
31 #define HTTP_SERVER_ADDRESS IP_ADDRESS(191, 236, 16, 125)/* http://www.httpwatch.com/httpgallery/chunked/chunkedimage.aspx */
32 #define HTTP_CLIENT_ADDRESS IP_ADDRESS(192, 168, 100, 22)
33 #define CHUNKED_TOTAL_SIZE 33653
34
35 static UINT loop = 1;
36
37 #ifdef CTEST
test_application_define(void * first_unused_memory)38 VOID test_application_define(void *first_unused_memory)
39 #else
40 void netx_web_external_server_chunked_test_application_define(void *first_unused_memory)
41 #endif
42 {
43 CHAR *pointer;
44 UINT status;
45
46
47 error_counter = 0;
48
49 /* Setup the working pointer. */
50 pointer = (CHAR *) first_unused_memory;
51
52 /* Initialize the NetX system. */
53 nx_system_initialize();
54
55 /* Create the HTTP Client thread. */
56 status = tx_thread_create(&client_thread, "HTTP Client", thread_client_entry, 0,
57 pointer, DEMO_STACK_SIZE,
58 NX_WEB_HTTP_SERVER_PRIORITY + 2, NX_WEB_HTTP_SERVER_PRIORITY + 2, TX_NO_TIME_SLICE, TX_AUTO_START);
59 pointer = pointer + DEMO_STACK_SIZE;
60 if (status)
61 error_counter++;
62
63 /* Create the Client packet pool. */
64 status = nx_packet_pool_create(&client_pool, "HTTP Client Packet Pool", CLIENT_PACKET_SIZE,
65 pointer, CLIENT_PACKET_SIZE*16);
66 pointer = pointer + CLIENT_PACKET_SIZE * 16;
67 if (status)
68 error_counter++;
69
70 /* Create an IP instance. */
71 status = nx_ip_create(&client_ip, "HTTP Client IP", HTTP_CLIENT_ADDRESS,
72 0xFFFFFF00UL, &client_pool, _nx_pcap_network_driver,
73 pointer, 2048, 1);
74 pointer = pointer + 2048;
75 if (status)
76 error_counter++;
77
78 status = nx_arp_enable(&client_ip, (void *) pointer, 1024);
79 pointer = pointer + 2048;
80 if (status)
81 error_counter++;
82
83 /* Enable TCP traffic. */
84 status = nx_tcp_enable(&client_ip);
85 if (status)
86 error_counter++;
87 }
88
thread_client_entry(ULONG thread_input)89 void thread_client_entry(ULONG thread_input)
90 {
91 UINT i;
92 UINT status;
93 NX_PACKET *recv_packet;
94 UINT chunked_size = 0;
95
96 printf("NetX Test: Web External Server Chunked Test..........................");
97
98 /* Give IP task and driver a chance to initialize the system. */
99 tx_thread_sleep(NX_IP_PERIODIC_RATE);
100
101 #ifdef GATEWAY_IP_ADDRESS
102 /* Setup gateway for communicating with the outside world. */
103 status = nx_ip_gateway_address_set(&client_ip, GATEWAY_IP_ADDRESS);
104
105 /* Check for errors. */
106 if (status)
107 {
108 printf("Error in setting gateway address: 0x%02x\n", status);
109 return;
110 }
111 #endif
112
113 /* Set server IP address. */
114 server_ip_address.nxd_ip_address.v4 = HTTP_SERVER_ADDRESS;
115 server_ip_address.nxd_ip_version = NX_IP_VERSION_V4;
116
117 /* First loop test HTTP, second loop test HTTPS. */
118 for (i = 0; i < loop ; i++)
119 {
120
121 /* Create an HTTP client instance. */
122 status = nx_web_http_client_create(&my_client, "HTTP Client", &client_ip, &client_pool, 1536);
123
124 /* Check status. */
125 if (status)
126 error_counter++;
127
128 /* Send a GET request. */
129 status = nx_web_http_client_get_start(&my_client, &server_ip_address,
130 NX_WEB_HTTP_SERVER_PORT, "/httpgallery/chunked/chunkedimage.aspx",
131 "www.httpwatch.com",
132 NX_NULL, NX_NULL, NX_WAIT_FOREVER);
133
134 /* Check status. */
135 if (status)
136 error_counter++;
137
138 while (1)
139 {
140
141 /* Get response from server. */
142 status = nx_web_http_client_response_body_get(&my_client, &recv_packet, NX_WAIT_FOREVER);
143
144 if (status)
145 {
146 break;
147 }
148 else
149 {
150 chunked_size += recv_packet -> nx_packet_length;
151 nx_packet_release(recv_packet);
152 }
153 }
154
155 /* Check status. */
156 if ((status != NX_WEB_HTTP_GET_DONE) || (chunked_size != CHUNKED_TOTAL_SIZE))
157 error_counter++;
158 else
159 nx_packet_release(recv_packet);
160
161 /* Check if all the packets are released. */
162 if (client_pool.nx_packet_pool_available != client_pool.nx_packet_pool_total)
163 error_counter++;
164
165 status = nx_web_http_client_delete(&my_client);
166 if (status)
167 error_counter++;
168 }
169
170 if(error_counter)
171 {
172 printf("ERROR!\n");
173 test_control_return(1);
174 }
175 else
176 {
177 printf("SUCCESS!\n");
178 test_control_return(0);
179 }
180 }
181
182 #else
183
184 #ifdef CTEST
test_application_define(void * first_unused_memory)185 VOID test_application_define(void *first_unused_memory)
186 #else
187 void netx_web_external_server_chunked_test_application_define(void *first_unused_memory)
188 #endif
189 {
190
191 /* Print out test information banner. */
192 printf("NetX Test: Web External Server Chunked Test..........................N/A\n");
193
194 test_control_return(3);
195 }
196 #endif
197
198