1 /* This case tests whether HTTP server can work well with multipart/form-data.
2 * server packet size 800
3 * client packet size 1400
4 * pkt size is bigger than 1500 to cause client/server fragmentation.
5 */
6
7 /* Here is the packet content. */
8 /* First two bytes of Content-Disposition is replaced with CRLF */
9 /*
10 ------------------------------4ebf00fbcf09
11
12 ntent-Disposition: form-data; name="example"
13
14 testtest(repeat 49 times)
15 ------------------------------4ebf00fbcf09
16 Content-Disposition: form-data; name="example2"
17
18 test2test2(repeat 35 times)
19 ------------------------------4ebf00fbcf09
20 Content-Disposition: form-data; name="example3"
21
22 test3test3(repeat 39 times)
23 ------------------------------4ebf00fbcf09
24 Content-Disposition: form-data; name="example4"
25
26 test4test4(repeat 51times)
27 ------------------------------4ebf00fbcf09
28 Content-Disposition: form-data; name="example5"
29
30 test5(repeat 54times)
31 ------------------------------4ebf00fbcf09--
32 */
33
34 /* length1 = 196,
35 * length2 = 175,
36 * length3 = 195,
37 * length4 = 205
38 * length5 = 220.
39 * */
40
41 #include "tx_api.h"
42 #include "nx_api.h"
43 #include "fx_api.h"
44
45 extern void test_control_return(UINT);
46 #if defined(NX_HTTP_MULTIPART_ENABLE) && !defined(NX_DISABLE_IPV4)
47 #include "nxd_http_client.h"
48 #include "nxd_http_server.h"
49
50 #define DEMO_STACK_SIZE 4096
51
52 /* This is a HTTP get packet captured by wireshark. HEAD index.html*/
53 static char pkt[] = {
54 0x50, 0x4f, 0x53, 0x54, 0x20, 0x2f, 0x20, 0x48, /* POST / H */
55 0x54, 0x54, 0x50, 0x2f, 0x31, 0x2e, 0x31, 0x0d, /* TTP/1.1. */
56 0x0a, 0x55, 0x73, 0x65, 0x72, 0x2d, 0x41, 0x67, /* .User-Ag */
57 0x65, 0x6e, 0x74, 0x3a, 0x20, 0x63, 0x75, 0x72, /* ent: cur */
58 0x6c, 0x2f, 0x37, 0x2e, 0x33, 0x32, 0x2e, 0x30, /* l/7.32.0 */
59 0x0d, 0x0a, 0x48, 0x6f, 0x73, 0x74, 0x3a, 0x20, /* ..Host: */
60 0x31, 0x39, 0x32, 0x2e, 0x31, 0x36, 0x38, 0x2e, /* 192.168. */
61 0x30, 0x2e, 0x31, 0x32, 0x33, 0x0d, 0x0a, 0x41, /* 0.123..A */
62 0x63, 0x63, 0x65, 0x70, 0x74, 0x3a, 0x20, 0x2a, /* ccept: * */
63 0x2f, 0x2a, 0x0d, 0x0a, 0x43, 0x6f, 0x6e, 0x74, /* *..Cont */
64 0x65, 0x6e, 0x74, 0x2d, 0x54, 0x79, 0x70, 0x65, /* ent-Type */
65 0x3a, 0x20, 0x6d, 0x75, 0x6c, 0x74, 0x69, 0x70, /* : multip */
66 0x61, 0x72, 0x74, 0x2f, 0x66, 0x6f, 0x72, 0x6d, /* art/form */
67 0x2d, 0x64, 0x61, 0x74, 0x61, 0x3b, 0x20, 0x62, /* -data; b */
68 0x6f, 0x75, 0x6e, 0x64, 0x61, 0x72, 0x79, 0x3d, /* oundary= */
69 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, /* -------- */
70 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, /* -------- */
71 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, /* -------- */
72 0x2d, 0x2d, 0x2d, 0x2d, 0x34, 0x65, 0x62, 0x66, /* ----4ebf */
73 0x30, 0x30, 0x66, 0x62, 0x63, 0x66, 0x30, 0x39, /* 00fbcf09 */
74 0x0d, 0x0a, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, /* ..Conten */
75 0x74, 0x2d, 0x4c, 0x65, 0x6e, 0x67, 0x74, 0x68, /* t-Length */
76 0x3a, 0x20, 0x31, 0x35, 0x32, 0x31, 0x0d, 0x0a, /* : 1521.. */
77 0x45, 0x78, 0x70, 0x65, 0x63, 0x74, 0x3a, 0x20, /* Expect: */
78 0x31, 0x30, 0x30, 0x2d, 0x63, 0x6f, 0x6e, 0x74, /* 100-cont */
79 0x69, 0x6e, 0x75, 0x65, 0x0d, 0x0a, 0x0d, 0x0a, /* inue.... */
80 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, /* -------- */
81 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, /* -------- */
82 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, /* -------- */
83 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x34, 0x65, /* ------4e */
84 0x62, 0x66, 0x30, 0x30, 0x66, 0x62, 0x63, 0x66, /* bf00fbcf */
85 0x30, 0x39, 0x0d, 0x0a, 0x0d, 0x0a, 0x6e, 0x74, /* 09..Cont */
86 0x65, 0x6e, 0x74, 0x2d, 0x44, 0x69, 0x73, 0x70, /* ent-Disp */
87 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x3a, /* osition: */
88 0x20, 0x66, 0x6f, 0x72, 0x6d, 0x2d, 0x64, 0x61, /* form-da */
89 0x74, 0x61, 0x3b, 0x20, 0x6e, 0x61, 0x6d, 0x65, /* ta; name */
90 0x3d, 0x22, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, /* ="exampl */
91 0x65, 0x22, 0x0d, 0x0a, 0x0d, 0x0a, 0x74, 0x65, /* e"....te */
92 0x73, 0x74, 0x74, 0x65, 0x73, 0x74, 0x74, 0x65, /* sttestte */
93 0x73, 0x74, 0x74, 0x65, 0x73, 0x74, 0x74, 0x65, /* sttestte */
94 0x73, 0x74, 0x74, 0x65, 0x73, 0x74, 0x74, 0x65, /* sttestte */
95 0x73, 0x74, 0x74, 0x65, 0x73, 0x74, 0x74, 0x65, /* sttestte */
96 0x73, 0x74, 0x74, 0x65, 0x73, 0x74, 0x74, 0x65, /* sttestte */
97 0x73, 0x74, 0x74, 0x65, 0x73, 0x74, 0x74, 0x65, /* sttestte */
98 0x73, 0x74, 0x74, 0x65, 0x73, 0x74, 0x74, 0x65, /* sttestte */
99 0x73, 0x74, 0x74, 0x65, 0x73, 0x74, 0x74, 0x65, /* sttestte */
100 0x73, 0x74, 0x74, 0x65, 0x73, 0x74, 0x74, 0x65, /* sttestte */
101 0x73, 0x74, 0x74, 0x65, 0x73, 0x74, 0x74, 0x65, /* sttestte */
102 0x73, 0x74, 0x74, 0x65, 0x73, 0x74, 0x74, 0x65, /* sttestte */
103 0x73, 0x74, 0x74, 0x65, 0x73, 0x74, 0x74, 0x65, /* sttestte */
104 0x73, 0x74, 0x74, 0x65, 0x73, 0x74, 0x74, 0x65, /* sttestte */
105 0x73, 0x74, 0x74, 0x65, 0x73, 0x74, 0x74, 0x65, /* sttestte */
106 0x73, 0x74, 0x74, 0x65, 0x73, 0x74, 0x74, 0x65, /* sttestte */
107 0x73, 0x74, 0x74, 0x65, 0x73, 0x74, 0x74, 0x65, /* sttestte */
108 0x73, 0x74, 0x74, 0x65, 0x73, 0x74, 0x74, 0x65, /* sttestte */
109 0x73, 0x74, 0x74, 0x65, 0x73, 0x74, 0x74, 0x65, /* sttestte */
110 0x73, 0x74, 0x74, 0x65, 0x73, 0x74, 0x74, 0x65, /* sttestte */
111 0x73, 0x74, 0x74, 0x65, 0x73, 0x74, 0x74, 0x65, /* sttestte */
112 0x73, 0x74, 0x74, 0x65, 0x73, 0x74, 0x74, 0x65, /* sttestte */
113 0x73, 0x74, 0x74, 0x65, 0x73, 0x74, 0x74, 0x65, /* sttestte */
114 0x73, 0x74, 0x74, 0x65, 0x73, 0x74, 0x74, 0x65, /* sttestte */
115 0x73, 0x74, 0x74, 0x65, 0x73, 0x74, 0x74, 0x65, /* sttestte */
116 0x73, 0x74, 0x0d, 0x0a, 0x2d, 0x2d, 0x2d, 0x2d, /* st..---- */
117 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, /* -------- */
118 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, /* -------- */
119 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, /* -------- */
120 0x2d, 0x2d, 0x34, 0x65, 0x62, 0x66, 0x30, 0x30, /* --4ebf00 */
121 0x66, 0x62, 0x63, 0x66, 0x30, 0x39, 0x0d, 0x0a, /* fbcf09.. */
122 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x2d, /* Content- */
123 0x44, 0x69, 0x73, 0x70, 0x6f, 0x73, 0x69, 0x74, /* Disposit */
124 0x69, 0x6f, 0x6e, 0x3a, 0x20, 0x66, 0x6f, 0x72, /* ion: for */
125 0x6d, 0x2d, 0x64, 0x61, 0x74, 0x61, 0x3b, 0x20, /* m-data; */
126 0x6e, 0x61, 0x6d, 0x65, 0x3d, 0x22, 0x65, 0x78, /* name="ex */
127 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x32, 0x22, 0x0d, /* ample2". */
128 0x0a, 0x0d, 0x0a, 0x74, 0x65, 0x73, 0x74, 0x32, /* ...test2 */
129 0x74, 0x65, 0x73, 0x74, 0x32, 0x74, 0x65, 0x73, /* test2tes */
130 0x74, 0x32, 0x74, 0x65, 0x73, 0x74, 0x32, 0x74, /* t2test2t */
131 0x65, 0x73, 0x74, 0x32, 0x74, 0x65, 0x73, 0x74, /* est2test */
132 0x32, 0x74, 0x65, 0x73, 0x74, 0x32, 0x74, 0x65, /* 2test2te */
133 0x73, 0x74, 0x32, 0x74, 0x65, 0x73, 0x74, 0x32, /* st2test2 */
134 0x74, 0x65, 0x73, 0x74, 0x32, 0x74, 0x65, 0x73, /* test2tes */
135 0x74, 0x32, 0x74, 0x65, 0x73, 0x74, 0x32, 0x74, /* t2test2t */
136 0x65, 0x73, 0x74, 0x32, 0x74, 0x65, 0x73, 0x74, /* est2test */
137 0x32, 0x74, 0x65, 0x73, 0x74, 0x32, 0x74, 0x65, /* 2test2te */
138 0x73, 0x74, 0x32, 0x74, 0x65, 0x73, 0x74, 0x32, /* st2test2 */
139 0x74, 0x65, 0x73, 0x74, 0x32, 0x74, 0x65, 0x73, /* test2tes */
140 0x74, 0x32, 0x74, 0x65, 0x73, 0x74, 0x32, 0x74, /* t2test2t */
141 0x65, 0x73, 0x74, 0x32, 0x74, 0x65, 0x73, 0x74, /* est2test */
142 0x32, 0x74, 0x65, 0x73, 0x74, 0x32, 0x74, 0x65, /* 2test2te */
143 0x73, 0x74, 0x32, 0x74, 0x65, 0x73, 0x74, 0x32, /* st2test2 */
144 0x74, 0x65, 0x73, 0x74, 0x32, 0x74, 0x65, 0x73, /* test2tes */
145 0x74, 0x32, 0x74, 0x65, 0x73, 0x74, 0x32, 0x74, /* t2test2t */
146 0x65, 0x73, 0x74, 0x32, 0x74, 0x65, 0x73, 0x74, /* est2test */
147 0x32, 0x74, 0x65, 0x73, 0x74, 0x32, 0x74, 0x65, /* 2test2te */
148 0x73, 0x74, 0x32, 0x74, 0x65, 0x73, 0x74, 0x32, /* st2test2 */
149 0x74, 0x65, 0x73, 0x74, 0x32, 0x74, 0x65, 0x73, /* test2tes */
150 0x74, 0x32, 0x0d, 0x0a, 0x2d, 0x2d, 0x2d, 0x2d, /* t2..---- */
151 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, /* -------- */
152 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, /* -------- */
153 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, /* -------- */
154 0x2d, 0x2d, 0x34, 0x65, 0x62, 0x66, 0x30, 0x30, /* --4ebf00 */
155 0x66, 0x62, 0x63, 0x66, 0x30, 0x39, 0x0d, 0x0a, /* fbcf09.. */
156 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x2d, /* Content- */
157 0x44, 0x69, 0x73, 0x70, 0x6f, 0x73, 0x69, 0x74, /* Disposit */
158 0x69, 0x6f, 0x6e, 0x3a, 0x20, 0x66, 0x6f, 0x72, /* ion: for */
159 0x6d, 0x2d, 0x64, 0x61, 0x74, 0x61, 0x3b, 0x20, /* m-data; */
160 0x6e, 0x61, 0x6d, 0x65, 0x3d, 0x22, 0x65, 0x78, /* name="ex */
161 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x33, 0x22, 0x0d, /* ample3". */
162 0x0a, 0x0d, 0x0a, 0x74, 0x65, 0x73, 0x74, 0x33, /* ...test3 */
163 0x74, 0x65, 0x73, 0x74, 0x33, 0x74, 0x65, 0x73, /* test3tes */
164 0x74, 0x33, 0x74, 0x65, 0x73, 0x74, 0x33, 0x74, /* t3test3t */
165 0x65, 0x73, 0x74, 0x33, 0x74, 0x65, 0x73, 0x74, /* est3test */
166 0x33, 0x74, 0x65, 0x73, 0x74, 0x33, 0x74, 0x65, /* 3test3te */
167 0x73, 0x74, 0x33, 0x74, 0x65, 0x73, 0x74, 0x33, /* st3test3 */
168 0x74, 0x65, 0x73, 0x74, 0x33, 0x74, 0x65, 0x73, /* test3tes */
169 0x74, 0x33, 0x74, 0x65, 0x73, 0x74, 0x33, 0x74, /* t3test3t */
170 0x65, 0x73, 0x74, 0x33, 0x74, 0x65, 0x73, 0x74, /* est3test */
171 0x33, 0x74, 0x65, 0x73, 0x74, 0x33, 0x74, 0x65, /* 3test3te */
172 0x73, 0x74, 0x33, 0x74, 0x65, 0x73, 0x74, 0x33, /* st3test3 */
173 0x74, 0x65, 0x73, 0x74, 0x33, 0x74, 0x65, 0x73, /* test3tes */
174 0x74, 0x33, 0x74, 0x65, 0x73, 0x74, 0x33, 0x74, /* t3test3t */
175 0x65, 0x73, 0x74, 0x33, 0x74, 0x65, 0x73, 0x74, /* est3test */
176 0x33, 0x74, 0x65, 0x73, 0x74, 0x33, 0x74, 0x65, /* 3test3te */
177 0x73, 0x74, 0x33, 0x74, 0x65, 0x73, 0x74, 0x33, /* st3test3 */
178 0x74, 0x65, 0x73, 0x74, 0x33, 0x74, 0x65, 0x73, /* test3tes */
179 0x74, 0x33, 0x74, 0x65, 0x73, 0x74, 0x33, 0x74, /* t3test3t */
180 0x65, 0x73, 0x74, 0x33, 0x74, 0x65, 0x73, 0x74, /* est3test */
181 0x33, 0x74, 0x65, 0x73, 0x74, 0x33, 0x74, 0x65, /* 3test3te */
182 0x73, 0x74, 0x33, 0x74, 0x65, 0x73, 0x74, 0x33, /* st3test3 */
183 0x74, 0x65, 0x73, 0x74, 0x33, 0x74, 0x65, 0x73, /* test3tes */
184 0x74, 0x33, 0x74, 0x65, 0x73, 0x74, 0x33, 0x74, /* t3test3t */
185 0x65, 0x73, 0x74, 0x33, 0x74, 0x65, 0x73, 0x74, /* est3test */
186 0x33, 0x74, 0x65, 0x73, 0x74, 0x33, 0x0d, 0x0a, /* 3test3.. */
187 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, /* -------- */
188 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, /* -------- */
189 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, /* -------- */
190 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x34, 0x65, /* ------4e */
191 0x62, 0x66, 0x30, 0x30, 0x66, 0x62, 0x63, 0x66, /* bf00fbcf */
192 0x30, 0x39, 0x0d, 0x0a, 0x43, 0x6f, 0x6e, 0x74, /* 09..Cont */
193 0x65, 0x6e, 0x74, 0x2d, 0x44, 0x69, 0x73, 0x70, /* ent-Disp */
194 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x3a, /* osition: */
195 0x20, 0x66, 0x6f, 0x72, 0x6d, 0x2d, 0x64, 0x61, /* form-da */
196 0x74, 0x61, 0x3b, 0x20, 0x6e, 0x61, 0x6d, 0x65, /* ta; name */
197 0x3d, 0x22, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, /* ="exampl */
198 0x65, 0x34, 0x22, 0x0d, 0x0a, 0x0d, 0x0a, 0x74, /* e4"....t */
199 0x65, 0x73, 0x74, 0x34, 0x74, 0x65, 0x73, 0x74, /* est4test */
200 0x34, 0x74, 0x65, 0x73, 0x74, 0x34, 0x74, 0x65, /* 4test4te */
201 0x73, 0x74, 0x34, 0x74, 0x65, 0x73, 0x74, 0x34, /* st4test4 */
202 0x74, 0x65, 0x73, 0x74, 0x34, 0x74, 0x65, 0x73, /* test4tes */
203 0x74, 0x34, 0x74, 0x65, 0x73, 0x74, 0x34, 0x74, /* t4test4t */
204 0x65, 0x73, 0x74, 0x34, 0x74, 0x65, 0x73, 0x74, /* est4test */
205 0x34, 0x74, 0x65, 0x73, 0x74, 0x34, 0x74, 0x65, /* 4test4te */
206 0x73, 0x74, 0x34, 0x74, 0x65, 0x73, 0x74, 0x34, /* st4test4 */
207 0x74, 0x65, 0x73, 0x74, 0x34, 0x74, 0x65, 0x73, /* test4tes */
208 0x74, 0x34, 0x74, 0x65, 0x73, 0x74, 0x34, 0x74, /* t4test4t */
209 0x65, 0x73, 0x74, 0x34, 0x74, 0x65, 0x73, 0x74, /* est4test */
210 0x34, 0x74, 0x65, 0x73, 0x74, 0x34, 0x74, 0x65, /* 4test4te */
211 0x73, 0x74, 0x34, 0x74, 0x65, 0x73, 0x74, 0x34, /* st4test4 */
212 0x74, 0x65, 0x73, 0x74, 0x34, 0x74, 0x65, 0x73, /* test4tes */
213 0x74, 0x34, 0x74, 0x65, 0x73, 0x74, 0x34, 0x74, /* t4test4t */
214 0x65, 0x73, 0x74, 0x34, 0x74, 0x65, 0x73, 0x74, /* est4test */
215 0x34, 0x74, 0x65, 0x73, 0x74, 0x34, 0x74, 0x65, /* 4test4te */
216 0x73, 0x74, 0x34, 0x74, 0x65, 0x73, 0x74, 0x34, /* st4test4 */
217 0x74, 0x65, 0x73, 0x74, 0x34, 0x74, 0x65, 0x73, /* test4tes */
218 0x74, 0x34, 0x74, 0x65, 0x73, 0x74, 0x34, 0x74, /* t4test4t */
219 0x65, 0x73, 0x74, 0x34, 0x74, 0x65, 0x73, 0x74, /* est4test */
220 0x34, 0x74, 0x65, 0x73, 0x74, 0x34, 0x74, 0x65, /* 4test4te */
221 0x73, 0x74, 0x34, 0x74, 0x65, 0x73, 0x74, 0x34, /* st4test4 */
222 0x74, 0x65, 0x73, 0x74, 0x34, 0x74, 0x65, 0x73, /* test4tes */
223 0x74, 0x34, 0x74, 0x65, 0x73, 0x74, 0x34, 0x74, /* t4test4t */
224 0x65, 0x73, 0x74, 0x34, 0x0d, 0x0a, 0x2d, 0x2d, /* est4..-- */
225 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, /* -------- */
226 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, /* -------- */
227 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, /* -------- */
228 0x2d, 0x2d, 0x2d, 0x2d, 0x34, 0x65, 0x62, 0x66, /* ----4ebf */
229 0x30, 0x30, 0x66, 0x62, 0x63, 0x66, 0x30, 0x39, /* 00fbcf09 */
230 0x0d, 0x0a, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, /* ..Conten */
231 0x74, 0x2d, 0x44, 0x69, 0x73, 0x70, 0x6f, 0x73, /* t-Dispos */
232 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x3a, 0x20, 0x66, /* ition: f */
233 0x6f, 0x72, 0x6d, 0x2d, 0x64, 0x61, 0x74, 0x61, /* orm-data */
234 0x3b, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x3d, 0x22, /* ; name=" */
235 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x35, /* example5 */
236 0x22, 0x0d, 0x0a, 0x0d, 0x0a, 0x74, 0x65, 0x73, /* "....tes */
237 0x74, 0x35, 0x74, 0x65, 0x73, 0x74, 0x35, 0x74, /* t5test5t */
238 0x65, 0x73, 0x74, 0x35, 0x74, 0x65, 0x73, 0x74, /* est5test */
239 0x35, 0x74, 0x65, 0x73, 0x74, 0x35, 0x74, 0x65, /* 5test5te */
240 0x73, 0x74, 0x35, 0x74, 0x65, 0x73, 0x74, 0x35, /* st5test5 */
241 0x74, 0x65, 0x73, 0x74, 0x35, 0x74, 0x65, 0x73, /* test5tes */
242 0x74, 0x35, 0x74, 0x65, 0x73, 0x74, 0x35, 0x74, /* t5test5t */
243 0x65, 0x73, 0x74, 0x35, 0x74, 0x65, 0x73, 0x74, /* est5test */
244 0x35, 0x74, 0x65, 0x73, 0x74, 0x35, 0x74, 0x65, /* 5test5te */
245 0x73, 0x74, 0x35, 0x74, 0x65, 0x73, 0x74, 0x35, /* st5test5 */
246 0x74, 0x65, 0x73, 0x74, 0x35, 0x74, 0x65, 0x73, /* test5tes */
247 0x74, 0x35, 0x74, 0x65, 0x73, 0x74, 0x35, 0x74, /* t5test5t */
248 0x65, 0x73, 0x74, 0x35, 0x74, 0x65, 0x73, 0x74, /* est5test */
249 0x35, 0x74, 0x65, 0x73, 0x74, 0x35, 0x74, 0x65, /* 5test5te */
250 0x73, 0x74, 0x35, 0x74, 0x65, 0x73, 0x74, 0x35, /* st5test5 */
251 0x74, 0x65, 0x73, 0x74, 0x35, 0x74, 0x65, 0x73, /* test5tes */
252 0x74, 0x35, 0x74, 0x65, 0x73, 0x74, 0x35, 0x74, /* t5test5t */
253 0x65, 0x73, 0x74, 0x35, 0x74, 0x65, 0x73, 0x74, /* est5test */
254 0x35, 0x74, 0x65, 0x73, 0x74, 0x35, 0x74, 0x65, /* 5test5te */
255 0x73, 0x74, 0x35, 0x74, 0x65, 0x73, 0x74, 0x35, /* st5test5 */
256 0x74, 0x65, 0x73, 0x74, 0x35, 0x74, 0x65, 0x73, /* test5tes */
257 0x74, 0x35, 0x74, 0x65, 0x73, 0x74, 0x35, 0x74, /* t5test5t */
258 0x65, 0x73, 0x74, 0x35, 0x74, 0x65, 0x73, 0x74, /* est5test */
259 0x35, 0x74, 0x65, 0x73, 0x74, 0x35, 0x74, 0x65, /* 5test5te */
260 0x73, 0x74, 0x35, 0x74, 0x65, 0x73, 0x74, 0x35, /* st5test5 */
261 0x74, 0x65, 0x73, 0x74, 0x35, 0x74, 0x65, 0x73, /* test5tes */
262 0x74, 0x35, 0x74, 0x65, 0x73, 0x74, 0x35, 0x74, /* t5test5t */
263 0x65, 0x73, 0x74, 0x35, 0x74, 0x65, 0x73, 0x74, /* est5test */
264 0x35, 0x0d, 0x0a, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, /* 5..----- */
265 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, /* -------- */
266 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, /* -------- */
267 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, /* -------- */
268 0x2d, 0x34, 0x65, 0x62, 0x66, 0x30, 0x30, 0x66, /* -4ebf00f */
269 0x62, 0x63, 0x66, 0x30, 0x39, 0x2d, 0x2d, 0x0d, /* bcf09--. */
270 0x0a /* . */
271 };
272
273
274 /* Set up FileX and file memory resources. */
275 static CHAR *ram_disk_memory;
276 static FX_MEDIA ram_disk;
277
278 /* Define device drivers. */
279 extern void _fx_ram_driver(FX_MEDIA *media_ptr);
280 extern void _nx_ram_network_driver_1024(NX_IP_DRIVER *driver_req_ptr);
281
282 static UINT my_get_notify(NX_HTTP_SERVER *server_ptr, UINT request_type, CHAR *resource, NX_PACKET *packet_ptr);
283
284 /* Set up the HTTP client global variables. */
285
286 #define CLIENT_PACKET_SIZE 1400
287
288 static TX_THREAD client_thread;
289 static NX_PACKET_POOL client_pool;
290 static NX_IP client_ip;
291 static UINT error_counter;
292
293 static NX_TCP_SOCKET client_socket;
294
295 /* Set up the HTTP server global variables */
296
297 #define SERVER_PACKET_SIZE 800
298
299 static NX_HTTP_SERVER my_server;
300 static NX_PACKET_POOL server_pool;
301 static TX_THREAD server_thread;
302 static NX_IP server_ip;
303 #ifdef __PRODUCT_NETXDUO__
304 static NXD_ADDRESS server_ip_address;
305 #else
306 static ULONG server_ip_address;
307 #endif
308
309 static UINT multipart_flag;
310
311 static void thread_client_entry(ULONG thread_input);
312 static void thread_server_entry(ULONG thread_input);
313
314 #define HTTP_SERVER_ADDRESS IP_ADDRESS(192,168,0,105)
315 #define HTTP_CLIENT_ADDRESS IP_ADDRESS(192,168,0,123)
316
317 #ifdef CTEST
test_application_define(void * first_unused_memory)318 VOID test_application_define(void *first_unused_memory)
319 #else
320 void netx_http_multipart_underflow_test_application_define(void *first_unused_memory)
321 #endif
322 {
323
324 CHAR *pointer;
325 UINT status;
326
327 error_counter = 0;
328
329 /* Setup the working pointer. */
330 pointer = (CHAR *) first_unused_memory;
331
332 /* Create a helper thread for the server. */
333 tx_thread_create(&server_thread, "HTTP Server thread", thread_server_entry, 0,
334 pointer, DEMO_STACK_SIZE,
335 4, 4, TX_NO_TIME_SLICE, TX_AUTO_START);
336
337 pointer = pointer + DEMO_STACK_SIZE;
338
339 /* Initialize the NetX system. */
340 nx_system_initialize();
341
342 /* Create the server packet pool. */
343 status = nx_packet_pool_create(&server_pool, "HTTP Server Packet Pool", SERVER_PACKET_SIZE,
344 pointer, SERVER_PACKET_SIZE*8);
345 pointer = pointer + SERVER_PACKET_SIZE * 8;
346 if (status)
347 error_counter++;
348
349 /* Create an IP instance. */
350 status = nx_ip_create(&server_ip, "HTTP Server IP", HTTP_SERVER_ADDRESS,
351 0xFFFFFF00UL, &server_pool, _nx_ram_network_driver_1024,
352 pointer, 4096, 1);
353 pointer = pointer + 4096;
354 if (status)
355 error_counter++;
356
357 /* Enable ARP and supply ARP cache memory for the server IP instance. */
358 status = nx_arp_enable(&server_ip, (void *) pointer, 1024);
359 pointer = pointer + 1024;
360 if (status)
361 error_counter++;
362
363 /* Enable TCP traffic. */
364 status = nx_tcp_enable(&server_ip);
365 if (status)
366 error_counter++;
367
368 /* Set up the server's IPv4 address here. */
369 #ifdef __PRODUCT_NETXDUO__
370 server_ip_address.nxd_ip_address.v4 = HTTP_SERVER_ADDRESS;
371 server_ip_address.nxd_ip_version = NX_IP_VERSION_V4;
372 #else
373 server_ip_address = HTTP_SERVER_ADDRESS;
374 #endif
375
376 /* Create the HTTP Server. */
377 status = nx_http_server_create(&my_server, "My HTTP Server", &server_ip, &ram_disk,
378 pointer, 2048, &server_pool, NX_NULL, my_get_notify);
379 pointer = pointer + 2048;
380 if (status)
381 error_counter++;
382
383 /* Save the memory pointer for the RAM disk. */
384 ram_disk_memory = pointer;
385
386 /* Create the HTTP Client thread. */
387 status = tx_thread_create(&client_thread, "HTTP Client", thread_client_entry, 0,
388 pointer, DEMO_STACK_SIZE,
389 6, 6, TX_NO_TIME_SLICE, TX_AUTO_START);
390 pointer = pointer + DEMO_STACK_SIZE;
391 if (status)
392 error_counter++;
393
394 /* Create the Client packet pool. */
395 status = nx_packet_pool_create(&client_pool, "HTTP Client Packet Pool", CLIENT_PACKET_SIZE,
396 pointer, CLIENT_PACKET_SIZE*8);
397 pointer = pointer + CLIENT_PACKET_SIZE * 8;
398 if (status)
399 error_counter++;
400
401 /* Create an IP instance. */
402 status = nx_ip_create(&client_ip, "HTTP Client IP", HTTP_CLIENT_ADDRESS,
403 0xFFFFFF00UL, &client_pool, _nx_ram_network_driver_1024,
404 pointer, 2048, 1);
405 pointer = pointer + 2048;
406 if (status)
407 error_counter++;
408
409 status = nx_arp_enable(&client_ip, (void *) pointer, 1024);
410 pointer = pointer + 2048;
411 if (status)
412 error_counter++;
413
414 /* Enable TCP traffic. */
415 status = nx_tcp_enable(&client_ip);
416 if (status)
417 error_counter++;
418
419 }
420
421
thread_client_entry(ULONG thread_input)422 void thread_client_entry(ULONG thread_input)
423 {
424
425 UINT status;
426 NX_PACKET *recv_packet;
427 NX_PACKET *my_packet;
428 CHAR *buffer_ptr;
429
430 multipart_flag = 0;
431
432 /* Create a socket. */
433 status = nx_tcp_socket_create(&client_ip, &client_socket, "Client Socket",
434 NX_IP_NORMAL, NX_FRAGMENT_OKAY, NX_IP_TIME_TO_LIVE, 1024,
435 NX_NULL, NX_NULL);
436 if(status)
437 error_counter++;
438
439 /* Bind the socket. */
440 status = nx_tcp_client_socket_bind(&client_socket, 50295, 1 * NX_IP_PERIODIC_RATE);
441 if(status)
442 error_counter++;
443
444 /* Call connect to send an SYN. */
445 status = nx_tcp_client_socket_connect(&client_socket, HTTP_SERVER_ADDRESS, 80, 2 * NX_IP_PERIODIC_RATE);
446 if(status)
447 error_counter++;
448
449 /* Allocate a packet. */
450 status = nx_packet_allocate(&client_pool, &my_packet, NX_TCP_PACKET, 1 * NX_IP_PERIODIC_RATE);
451 if(status)
452 error_counter++;
453
454 /* Write HEAD packet into the packet payload. */
455 status = nx_packet_data_append(my_packet, pkt, sizeof(pkt), &client_pool, 1 * NX_IP_PERIODIC_RATE);
456 if(status)
457 error_counter++;
458
459 /* Send the packet out. */
460 status = nx_tcp_socket_send(&client_socket, my_packet, 1 * NX_IP_PERIODIC_RATE);
461 if(status)
462 error_counter++;
463
464 /* Receive the response from http server. */
465 status = nx_tcp_socket_receive(&client_socket, &recv_packet, 1 * NX_IP_PERIODIC_RATE);
466 if(status)
467 error_counter++;
468 else
469 {
470 buffer_ptr = (CHAR *)recv_packet ->nx_packet_prepend_ptr;
471
472 /* Check the status, If success , it should be 200. */
473 if((buffer_ptr[9] != '2') || (buffer_ptr[10] != '0') || (buffer_ptr[11] != '0'))
474 error_counter++;
475
476 nx_packet_release(recv_packet);
477 }
478
479 tx_thread_sleep(1 * NX_IP_PERIODIC_RATE);
480
481 if((error_counter) || (multipart_flag != 1))
482 {
483 printf("ERROR!\n");
484 test_control_return(1);
485 }
486 else
487 {
488 printf("SUCCESS!\n");
489 test_control_return(0);
490 }
491
492 }
493
494
495 /* Define the helper HTTP server thread. */
thread_server_entry(ULONG thread_input)496 void thread_server_entry(ULONG thread_input)
497 {
498
499 UINT status;
500
501 /* Print out test information banner. */
502 printf("NetX Test: HTTP Multipart Underflow Test.............................");
503
504 /* Check for earlier error. */
505 if(error_counter)
506 {
507 printf("ERROR!\n");
508 test_control_return(1);
509 }
510
511 /* OK to start the HTTP Server. */
512 status = nx_http_server_start(&my_server);
513 if(status)
514 error_counter++;
515
516 tx_thread_sleep(2 * NX_IP_PERIODIC_RATE);
517
518 status = nx_http_server_delete(&my_server);
519 if(status)
520 error_counter++;
521
522 }
523
my_get_notify(NX_HTTP_SERVER * server_ptr,UINT request_type,CHAR * resource,NX_PACKET * packet_ptr)524 UINT my_get_notify(NX_HTTP_SERVER *server_ptr, UINT request_type, CHAR *resource, NX_PACKET *packet_ptr)
525 {
526
527 ULONG offset, total_length;
528 ULONG length;
529 UCHAR buffer[1440];
530 UINT count = 0;
531 UINT status;
532 NX_PACKET *response_pkt;
533
534 /* Set first 5 bytes to 0. */
535 buffer[0] = 0xFF;
536 buffer[1] = 0xFF;
537 buffer[2] = 0xFF;
538 buffer[3] = 0xFF;
539 buffer[4] = 0xFF;
540
541 /* Process multipart data. */
542 if(request_type == NX_HTTP_SERVER_POST_REQUEST)
543 {
544 while(nx_http_server_get_entity_header(server_ptr, &packet_ptr, buffer + 5, sizeof(buffer) - 5) == NX_SUCCESS)
545 {
546 if ((buffer[0] & buffer[1] & buffer[2] & buffer[3] & buffer[4]) != 0xFF)
547 {
548
549 /* Detected underflow. */
550 error_counter++;
551 }
552
553 multipart_flag = 1;
554
555 /* Send the result. */
556 total_length = 0;
557 count++;
558
559 while(nx_http_server_get_entity_content(server_ptr, &packet_ptr, &offset, &length) == NX_SUCCESS)
560 {
561 /* Print content data. */
562 nx_packet_data_extract_offset(packet_ptr, offset, buffer + 5, length, &length);
563 buffer[length + 5] = 0;
564 total_length += length;
565 }
566
567 /* Check the data length. */
568 /* if((count == 1) && (total_length != 196))
569 error_counter++; */
570 if((count == 2) && (total_length != 175))
571 error_counter++;
572 else if((count == 3) && (total_length != 195))
573 error_counter++;
574 else if((count == 4) && (total_length != 205))
575 error_counter++;
576 else if((count == 5) && (total_length != 220))
577 error_counter++;
578
579 }
580
581 /* Generate HTTP header. */
582 status = nx_http_server_callback_generate_response_header(server_ptr, &response_pkt, NX_HTTP_STATUS_OK, 800, "text/html", "Server: NetXDuo HTTP 5.3\r\n");
583 if(status == NX_SUCCESS)
584 {
585 if(nx_http_server_callback_packet_send(server_ptr, response_pkt))
586 nx_packet_release(response_pkt);
587 }
588 else
589 error_counter++;
590 }
591 else
592 return NX_SUCCESS;
593
594 return(NX_HTTP_CALLBACK_COMPLETED);
595 }
596 #else
597
598 #ifdef CTEST
test_application_define(void * first_unused_memory)599 VOID test_application_define(void *first_unused_memory)
600 #else
601 void netx_http_multipart_underflow_test_application_define(void *first_unused_memory)
602 #endif
603 {
604
605 printf("NetX Test: HTTP Multipart Underflow Test.............................N/A\n");
606 test_control_return(3);
607 }
608 #endif
609
610