1 /**************************************************************************/
2 /* */
3 /* Copyright (c) Microsoft Corporation. All rights reserved. */
4 /* */
5 /* This software is licensed under the Microsoft Software License */
6 /* Terms for Microsoft Azure RTOS. Full text of the license can be */
7 /* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
8 /* and in the root directory of this software. */
9 /* */
10 /**************************************************************************/
11
12
13 /**************************************************************************/
14 /**************************************************************************/
15 /** */
16 /** NetX Web Component */
17 /** */
18 /** Hypertext Transfer Protocol (HTTP) and */
19 /** Hypertext Transfer Protocol Secure (HTTPS using TLS) */
20 /** */
21 /**************************************************************************/
22 /**************************************************************************/
23
24 #define NX_WEB_HTTP_CLIENT_SOURCE_CODE
25
26 /* Force error checking to be disabled in this module */
27
28 #ifndef NX_DISABLE_ERROR_CHECKING
29 #define NX_DISABLE_ERROR_CHECKING
30 #endif
31
32 /* Include necessary system files. */
33
34 #include "nx_api.h"
35 #include "nx_ip.h"
36 #include "nx_ipv6.h"
37
38 #include "nx_web_http_client.h"
39
40 #include "stdio.h"
41 #include "string.h"
42
43
44 /* Define global HTTPS variables and strings. */
45
46 /* Define status maps. */
47 static NX_WEB_HTTP_CLIENT_STATUS_MAP _nx_web_http_client_status_maps[] =
48 {
49 {"200", NX_SUCCESS},
50 {"100", NX_WEB_HTTP_STATUS_CODE_CONTINUE},
51 {"101", NX_WEB_HTTP_STATUS_CODE_SWITCHING_PROTOCOLS},
52 {"201", NX_WEB_HTTP_STATUS_CODE_CREATED},
53 {"202", NX_WEB_HTTP_STATUS_CODE_ACCEPTED},
54 {"203", NX_WEB_HTTP_STATUS_CODE_NON_AUTH_INFO},
55 {"204", NX_WEB_HTTP_STATUS_CODE_NO_CONTENT},
56 {"205", NX_WEB_HTTP_STATUS_CODE_RESET_CONTENT},
57 {"206", NX_WEB_HTTP_STATUS_CODE_PARTIAL_CONTENT},
58 {"300", NX_WEB_HTTP_STATUS_CODE_MULTIPLE_CHOICES},
59 {"301", NX_WEB_HTTP_STATUS_CODE_MOVED_PERMANETLY},
60 {"302", NX_WEB_HTTP_STATUS_CODE_FOUND},
61 {"303", NX_WEB_HTTP_STATUS_CODE_SEE_OTHER},
62 {"304", NX_WEB_HTTP_STATUS_CODE_NOT_MODIFIED},
63 {"305", NX_WEB_HTTP_STATUS_CODE_USE_PROXY},
64 {"307", NX_WEB_HTTP_STATUS_CODE_TEMPORARY_REDIRECT},
65 {"400", NX_WEB_HTTP_STATUS_CODE_BAD_REQUEST},
66 {"401", NX_WEB_HTTP_STATUS_CODE_UNAUTHORIZED},
67 {"402", NX_WEB_HTTP_STATUS_CODE_PAYMENT_REQUIRED},
68 {"403", NX_WEB_HTTP_STATUS_CODE_FORBIDDEN},
69 {"404", NX_WEB_HTTP_STATUS_CODE_NOT_FOUND},
70 {"405", NX_WEB_HTTP_STATUS_CODE_METHOD_NOT_ALLOWED},
71 {"406", NX_WEB_HTTP_STATUS_CODE_NOT_ACCEPTABLE},
72 {"407", NX_WEB_HTTP_STATUS_CODE_PROXY_AUTH_REQUIRED},
73 {"408", NX_WEB_HTTP_STATUS_CODE_REQUEST_TIMEOUT},
74 {"409", NX_WEB_HTTP_STATUS_CODE_CONFLICT},
75 {"410", NX_WEB_HTTP_STATUS_CODE_GONE},
76 {"411", NX_WEB_HTTP_STATUS_CODE_LENGTH_REQUIRED},
77 {"412", NX_WEB_HTTP_STATUS_CODE_PRECONDITION_FAILED},
78 {"413", NX_WEB_HTTP_STATUS_CODE_ENTITY_TOO_LARGE},
79 {"414", NX_WEB_HTTP_STATUS_CODE_URL_TOO_LARGE},
80 {"415", NX_WEB_HTTP_STATUS_CODE_UNSUPPORTED_MEDIA},
81 {"416", NX_WEB_HTTP_STATUS_CODE_RANGE_NOT_SATISFY},
82 {"417", NX_WEB_HTTP_STATUS_CODE_EXPECTATION_FAILED},
83 {"500", NX_WEB_HTTP_STATUS_CODE_INTERNAL_ERROR},
84 {"501", NX_WEB_HTTP_STATUS_CODE_NOT_IMPLEMENTED},
85 {"502", NX_WEB_HTTP_STATUS_CODE_BAD_GATEWAY},
86 {"503", NX_WEB_HTTP_STATUS_CODE_SERVICE_UNAVAILABLE},
87 {"504", NX_WEB_HTTP_STATUS_CODE_GATEWAY_TIMEOUT},
88 {"505", NX_WEB_HTTP_STATUS_CODE_VERSION_ERROR},
89 };
90
91 static UINT _nx_web_http_client_status_maps_size = sizeof(_nx_web_http_client_status_maps)/sizeof(NX_WEB_HTTP_CLIENT_STATUS_MAP);
92
93 /* Bring in externs for caller checking code. */
94
95 NX_CALLER_CHECKING_EXTERNS
96
97
98 /**************************************************************************/
99 /* */
100 /* FUNCTION RELEASE */
101 /* */
102 /* _nxe_web_http_client_create PORTABLE C */
103 /* 6.1 */
104 /* AUTHOR */
105 /* */
106 /* Yuxin Zhou, Microsoft Corporation */
107 /* */
108 /* DESCRIPTION */
109 /* */
110 /* This function checks for errors in the HTTP client create call. */
111 /* */
112 /* */
113 /* INPUT */
114 /* */
115 /* client_ptr Pointer to HTTP client */
116 /* client_name Name of HTTP client */
117 /* ip_ptr Pointer to IP instance */
118 /* pool_ptr Pointer to packet pool */
119 /* window_size Size of HTTP client rx window */
120 /* http_client_size Size of HTTP client */
121 /* */
122 /* OUTPUT */
123 /* */
124 /* status Completion status */
125 /* */
126 /* CALLS */
127 /* */
128 /* _nx_web_http_client_create Actual client create call */
129 /* */
130 /* CALLED BY */
131 /* */
132 /* Application Code */
133 /* */
134 /* RELEASE HISTORY */
135 /* */
136 /* DATE NAME DESCRIPTION */
137 /* */
138 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
139 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
140 /* resulting in version 6.1 */
141 /* */
142 /**************************************************************************/
_nxe_web_http_client_create(NX_WEB_HTTP_CLIENT * client_ptr,CHAR * client_name,NX_IP * ip_ptr,NX_PACKET_POOL * pool_ptr,ULONG window_size,UINT http_client_size)143 UINT _nxe_web_http_client_create(NX_WEB_HTTP_CLIENT *client_ptr, CHAR *client_name, NX_IP *ip_ptr, NX_PACKET_POOL *pool_ptr, ULONG window_size, UINT http_client_size)
144 {
145
146 NX_PACKET *packet_ptr;
147 UINT status;
148
149
150 /* Check for invalid input pointers. */
151 if ((ip_ptr == NX_NULL) || (ip_ptr -> nx_ip_id != NX_IP_ID) ||
152 (client_ptr == NX_NULL) || (client_ptr -> nx_web_http_client_id == NX_WEB_HTTP_CLIENT_ID) ||
153 (pool_ptr == NX_NULL) || (http_client_size != sizeof(NX_WEB_HTTP_CLIENT)))
154 return(NX_PTR_ERROR);
155
156 /* Pickup a packet from the supplied packet pool. */
157 packet_ptr = pool_ptr -> nx_packet_pool_available_list;
158
159 /* Determine if the packet payload is equal to or greater than the maximum HTTP header supported. */
160 if ((packet_ptr -> nx_packet_data_end - packet_ptr -> nx_packet_data_start) < NX_WEB_HTTP_CLIENT_MIN_PACKET_SIZE)
161 return(NX_WEB_HTTP_POOL_ERROR);
162
163 /* Call actual client create function. */
164 status = _nx_web_http_client_create(client_ptr, client_name, ip_ptr, pool_ptr, window_size);
165
166 /* Return completion status. */
167 return(status);
168 }
169
170
171 /**************************************************************************/
172 /* */
173 /* FUNCTION RELEASE */
174 /* */
175 /* _nx_web_http_client_create PORTABLE C */
176 /* 6.1 */
177 /* AUTHOR */
178 /* */
179 /* Yuxin Zhou, Microsoft Corporation */
180 /* */
181 /* DESCRIPTION */
182 /* */
183 /* This function creates a HTTP client on the specified IP. In doing */
184 /* so this function creates an TCP socket for subsequent HTTP */
185 /* transfers. */
186 /* */
187 /* */
188 /* INPUT */
189 /* */
190 /* client_ptr Pointer to HTTP client */
191 /* client_name Name of HTTP client */
192 /* ip_ptr Pointer to IP instance */
193 /* pool_ptr Pointer to packet pool */
194 /* window_size Size of HTTP client rx window */
195 /* */
196 /* OUTPUT */
197 /* */
198 /* status Completion status */
199 /* */
200 /* CALLS */
201 /* */
202 /* nx_tcp_socket_create Create HTTP client socket */
203 /* */
204 /* CALLED BY */
205 /* */
206 /* Application Code */
207 /* */
208 /* RELEASE HISTORY */
209 /* */
210 /* DATE NAME DESCRIPTION */
211 /* */
212 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
213 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
214 /* resulting in version 6.1 */
215 /* */
216 /**************************************************************************/
_nx_web_http_client_create(NX_WEB_HTTP_CLIENT * client_ptr,CHAR * client_name,NX_IP * ip_ptr,NX_PACKET_POOL * pool_ptr,ULONG window_size)217 UINT _nx_web_http_client_create(NX_WEB_HTTP_CLIENT *client_ptr, CHAR *client_name, NX_IP *ip_ptr, NX_PACKET_POOL *pool_ptr, ULONG window_size)
218 {
219
220 UINT status;
221
222
223 /* Clear the HTTP Client structure. */
224 memset((void *) client_ptr, 0, sizeof(NX_WEB_HTTP_CLIENT));
225
226 /* Create the Client's TCP socket. */
227 status = nx_tcp_socket_create(ip_ptr, &(client_ptr -> nx_web_http_client_socket), client_name,
228 NX_WEB_HTTP_TYPE_OF_SERVICE, NX_WEB_HTTP_FRAGMENT_OPTION, NX_WEB_HTTP_TIME_TO_LIVE,
229 window_size, NX_NULL, NX_NULL);
230
231 /* Determine if an error occurred. */
232 if (status != NX_SUCCESS)
233 {
234
235 /* Yes, return error code. */
236 return(status);
237 }
238
239 /* Save the Client name. */
240 client_ptr -> nx_web_http_client_name = client_name;
241
242 /* Save the IP pointer address. */
243 client_ptr -> nx_web_http_client_ip_ptr = ip_ptr;
244
245 /* Save the packet pool pointer. */
246 client_ptr -> nx_web_http_client_packet_pool_ptr = pool_ptr;
247
248 /* Set the client state to ready to indicate a get or put operation can be done. */
249 client_ptr -> nx_web_http_client_state = NX_WEB_HTTP_CLIENT_STATE_READY;
250
251 /* Set the current method to "NONE". */
252 client_ptr -> nx_web_http_client_method = NX_WEB_HTTP_METHOD_NONE;
253
254 /* Set the Client ID to indicate the HTTP client thread is ready. */
255 client_ptr -> nx_web_http_client_id = NX_WEB_HTTP_CLIENT_ID;
256
257 /* Set the default port the client connects to the HTTP server on (80). */
258 client_ptr -> nx_web_http_client_connect_port = NX_WEB_HTTP_SERVER_PORT;
259
260
261 /* Return successful completion. */
262 return(NX_SUCCESS);
263 }
264
265
266 /**************************************************************************/
267 /* */
268 /* FUNCTION RELEASE */
269 /* */
270 /* _nxe_web_http_client_delete PORTABLE C */
271 /* 6.1 */
272 /* AUTHOR */
273 /* */
274 /* Yuxin Zhou, Microsoft Corporation */
275 /* */
276 /* DESCRIPTION */
277 /* */
278 /* This function checks for errors in the HTTP client delete call. */
279 /* */
280 /* */
281 /* INPUT */
282 /* */
283 /* client_ptr Pointer to HTTP client */
284 /* */
285 /* OUTPUT */
286 /* */
287 /* status Completion status */
288 /* */
289 /* CALLS */
290 /* */
291 /* _nx_web_http_client_delete Actual client delete call */
292 /* */
293 /* CALLED BY */
294 /* */
295 /* Application Code */
296 /* */
297 /* RELEASE HISTORY */
298 /* */
299 /* DATE NAME DESCRIPTION */
300 /* */
301 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
302 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
303 /* resulting in version 6.1 */
304 /* */
305 /**************************************************************************/
_nxe_web_http_client_delete(NX_WEB_HTTP_CLIENT * client_ptr)306 UINT _nxe_web_http_client_delete(NX_WEB_HTTP_CLIENT *client_ptr)
307 {
308
309 UINT status;
310
311
312 /* Check for invalid input pointers. */
313 if ((client_ptr == NX_NULL) || (client_ptr -> nx_web_http_client_id != NX_WEB_HTTP_CLIENT_ID))
314 return(NX_PTR_ERROR);
315
316 /* Check for appropriate caller. */
317 NX_THREADS_ONLY_CALLER_CHECKING
318
319 /* Call actual client delete function. */
320 status = _nx_web_http_client_delete(client_ptr);
321
322 /* Return completion status. */
323 return(status);
324 }
325
326
327 /**************************************************************************/
328 /* */
329 /* FUNCTION RELEASE */
330 /* */
331 /* _nx_web_http_client_delete PORTABLE C */
332 /* 6.1 */
333 /* AUTHOR */
334 /* */
335 /* Yuxin Zhou, Microsoft Corporation */
336 /* */
337 /* DESCRIPTION */
338 /* */
339 /* This function deletes a previously created HTTP client on the */
340 /* specified IP. */
341 /* */
342 /* */
343 /* INPUT */
344 /* */
345 /* client_ptr Pointer to HTTP client */
346 /* */
347 /* OUTPUT */
348 /* */
349 /* status Completion status */
350 /* */
351 /* CALLS */
352 /* */
353 /* nx_tcp_socket_delete Delete the HTTP client socket */
354 /* */
355 /* CALLED BY */
356 /* */
357 /* Application Code */
358 /* */
359 /* RELEASE HISTORY */
360 /* */
361 /* DATE NAME DESCRIPTION */
362 /* */
363 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
364 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
365 /* resulting in version 6.1 */
366 /* */
367 /**************************************************************************/
_nx_web_http_client_delete(NX_WEB_HTTP_CLIENT * client_ptr)368 UINT _nx_web_http_client_delete(NX_WEB_HTTP_CLIENT *client_ptr)
369 {
370
371 #ifdef NX_WEB_HTTPS_ENABLE
372
373 /* End TLS session if using HTTPS. */
374 if (client_ptr->nx_web_http_client_is_https)
375 {
376 nx_secure_tls_session_end(&(client_ptr -> nx_web_http_client_tls_session), NX_WAIT_FOREVER);
377 nx_secure_tls_session_delete(&(client_ptr -> nx_web_http_client_tls_session));
378 }
379 #endif
380
381 /* Disconnect and unbind the socket. */
382 nx_tcp_socket_disconnect(&(client_ptr -> nx_web_http_client_socket), NX_WEB_HTTP_CLIENT_TIMEOUT);
383 nx_tcp_client_socket_unbind(&(client_ptr -> nx_web_http_client_socket));
384
385 /* Delete the TCP socket. */
386 nx_tcp_socket_delete(&(client_ptr -> nx_web_http_client_socket));
387
388 /* Clear the client ID to indicate the HTTP client is no longer ready. */
389 client_ptr -> nx_web_http_client_id = 0;
390
391 /* Release request packet. */
392 if (client_ptr -> nx_web_http_client_request_packet_ptr)
393 {
394 nx_packet_release(client_ptr -> nx_web_http_client_request_packet_ptr);
395 client_ptr -> nx_web_http_client_request_packet_ptr = NX_NULL;
396 }
397
398 /* Release response packet. */
399 if (client_ptr -> nx_web_http_client_response_packet)
400 {
401 nx_packet_release(client_ptr -> nx_web_http_client_response_packet);
402 client_ptr -> nx_web_http_client_response_packet = NX_NULL;
403 }
404
405 /* Clear out the entire structure in case it is used again. */
406 memset(client_ptr, 0, sizeof(NX_WEB_HTTP_CLIENT));
407
408 /* Return successful completion. */
409 return(NX_SUCCESS);
410 }
411
412 /**************************************************************************/
413 /* */
414 /* FUNCTION RELEASE */
415 /* */
416 /* _nx_web_http_client_content_type_header_add PORTABLE C */
417 /* 6.1 */
418 /* AUTHOR */
419 /* */
420 /* Yuxin Zhou, Microsoft Corporation */
421 /* */
422 /* DESCRIPTION */
423 /* */
424 /* This internal function is used to add the Content-Type HTTP header */
425 /* to an outgoing request. It determines the resource type from the */
426 /* resource string and then adds the complete header to the current */
427 /* HTTP request packet allocated in the control block. */
428 /* */
429 /* */
430 /* INPUT */
431 /* */
432 /* client_ptr Pointer to HTTP client */
433 /* resource Server resource name */
434 /* wait_option Timeout for called functions */
435 /* */
436 /* OUTPUT */
437 /* */
438 /* status Completion status */
439 /* */
440 /* CALLS */
441 /* */
442 /* _nx_web_http_client_type_get Get resource content type */
443 /* _nx_web_http_client_request_header_add */
444 /* Add header to request packet */
445 /* */
446 /* CALLED BY */
447 /* */
448 /* */
449 /* */
450 /* RELEASE HISTORY */
451 /* */
452 /* DATE NAME DESCRIPTION */
453 /* */
454 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
455 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
456 /* resulting in version 6.1 */
457 /* */
458 /**************************************************************************/
_nx_web_http_client_content_type_header_add(NX_WEB_HTTP_CLIENT * client_ptr,CHAR * resource,ULONG wait_option)459 UINT _nx_web_http_client_content_type_header_add(NX_WEB_HTTP_CLIENT *client_ptr, CHAR *resource, ULONG wait_option)
460 {
461 UINT j;
462 CHAR string1[20];
463
464 /* Now build the content-type entry. */
465 j = _nx_web_http_client_type_get(resource, string1);
466 _nx_web_http_client_request_header_add(client_ptr, "Content-Type", 12, string1, j, wait_option);
467
468 return(NX_SUCCESS);
469 }
470
471
472 /**************************************************************************/
473 /* */
474 /* FUNCTION RELEASE */
475 /* */
476 /* _nx_web_http_client_content_length_header_add PORTABLE C */
477 /* 6.1 */
478 /* AUTHOR */
479 /* */
480 /* Yuxin Zhou, Microsoft Corporation */
481 /* */
482 /* DESCRIPTION */
483 /* */
484 /* This internal function is used to add the Content-Length HTTP */
485 /* header to an outgoing request. It converts the passed-in length */
486 /* value to an HTTP string and then adds the complete header to the */
487 /* current HTTP request packet allocated in the control block. */
488 /* */
489 /* */
490 /* INPUT */
491 /* */
492 /* client_ptr Pointer to HTTP client */
493 /* total_bytes Content length value */
494 /* wait_option Timeout for called functions */
495 /* */
496 /* OUTPUT */
497 /* */
498 /* status Completion status */
499 /* */
500 /* CALLS */
501 /* */
502 /* _nx_web_http_client_number_convert Convert length to string */
503 /* _nx_web_http_client_request_header_add */
504 /* Add header to request packet */
505 /* */
506 /* CALLED BY */
507 /* */
508 /* */
509 /* */
510 /* RELEASE HISTORY */
511 /* */
512 /* DATE NAME DESCRIPTION */
513 /* */
514 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
515 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
516 /* resulting in version 6.1 */
517 /* */
518 /**************************************************************************/
_nx_web_http_client_content_length_header_add(NX_WEB_HTTP_CLIENT * client_ptr,ULONG total_bytes,ULONG wait_option)519 UINT _nx_web_http_client_content_length_header_add(NX_WEB_HTTP_CLIENT *client_ptr, ULONG total_bytes, ULONG wait_option)
520 {
521 UINT j;
522 CHAR string1[20];
523
524 /* Now build the content-length entry. */
525 j = _nx_web_http_client_number_convert(total_bytes, string1);
526 _nx_web_http_client_request_header_add(client_ptr, "Content-Length", 14, string1, j, wait_option);
527
528 return(NX_SUCCESS);
529 }
530
531
532 /**************************************************************************/
533 /* */
534 /* FUNCTION RELEASE */
535 /* */
536 /* _nxe_web_http_client_get_start PORTABLE C */
537 /* 6.1 */
538 /* AUTHOR */
539 /* */
540 /* Yuxin Zhou, Microsoft Corporation */
541 /* */
542 /* DESCRIPTION */
543 /* */
544 /* This function checks for errors in the HTTP Duo client get start */
545 /* call. */
546 /* */
547 /* */
548 /* INPUT */
549 /* */
550 /* client_ptr Pointer to HTTP client */
551 /* server_ip IP duo address of HTTP Server */
552 /* resource Pointer to resource (URL) */
553 /* host Pointer to Host */
554 /* username Pointer to username */
555 /* password Pointer to password */
556 /* wait_option Suspension option */
557 /* */
558 /* OUTPUT */
559 /* */
560 /* status Completion status */
561 /* */
562 /* CALLS */
563 /* */
564 /* _nx_web_http_client_get_start Actual client get start call */
565 /* */
566 /* CALLED BY */
567 /* */
568 /* Application Code */
569 /* */
570 /* RELEASE HISTORY */
571 /* */
572 /* DATE NAME DESCRIPTION */
573 /* */
574 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
575 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
576 /* resulting in version 6.1 */
577 /* */
578 /**************************************************************************/
_nxe_web_http_client_get_start(NX_WEB_HTTP_CLIENT * client_ptr,NXD_ADDRESS * server_ip,UINT server_port,CHAR * resource,CHAR * host,CHAR * username,CHAR * password,ULONG wait_option)579 UINT _nxe_web_http_client_get_start(NX_WEB_HTTP_CLIENT *client_ptr, NXD_ADDRESS *server_ip, UINT server_port,
580 CHAR *resource, CHAR *host, CHAR *username, CHAR *password,
581 ULONG wait_option)
582 {
583
584 UINT status;
585
586
587 /* Check for invalid input pointers. */
588 if ((client_ptr == NX_NULL) || (client_ptr -> nx_web_http_client_id != NX_WEB_HTTP_CLIENT_ID) ||
589 (resource == NX_NULL) || !server_ip || (host == NX_NULL))
590 return(NX_PTR_ERROR);
591
592 /* Check for appropriate caller. */
593 NX_THREADS_ONLY_CALLER_CHECKING
594
595 /* Call actual GET start routine. */
596 status = _nx_web_http_client_get_start(client_ptr, server_ip, server_port, resource,
597 host, username, password, wait_option);
598
599 /* Return completion status. */
600 return(status);
601 }
602
603 /**************************************************************************/
604 /* */
605 /* FUNCTION RELEASE */
606 /* */
607 /* _nx_web_http_client_get_start PORTABLE C */
608 /* 6.1 */
609 /* AUTHOR */
610 /* */
611 /* Yuxin Zhou, Microsoft Corporation */
612 /* */
613 /* DESCRIPTION */
614 /* */
615 /* This function processes the application GET request. The specified */
616 /* resource (URL) is requested from the HTTP Server at the specified */
617 /* IP address. The response is processed by calling */
618 /* nx_web_http_client_response_body_get. */
619 /* */
620 /* */
621 /* INPUT */
622 /* */
623 /* client_ptr Pointer to HTTP client */
624 /* server_ip HTTP Server IP address */
625 /* resource Pointer to resource (URL) */
626 /* host Pointer to Host */
627 /* username Pointer to username */
628 /* password Pointer to password */
629 /* wait_option Suspension option */
630 /* */
631 /* OUTPUT */
632 /* */
633 /* status Completion status */
634 /* */
635 /* CALLS */
636 /* */
637 /* _nx_web_http_client_get_start_extended */
638 /* Actual client get start call */
639 /* _nx_utility_string_length_check Check string length */
640 /* */
641 /* CALLED BY */
642 /* */
643 /* Application Code */
644 /* */
645 /* RELEASE HISTORY */
646 /* */
647 /* DATE NAME DESCRIPTION */
648 /* */
649 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
650 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
651 /* resulting in version 6.1 */
652 /* */
653 /**************************************************************************/
_nx_web_http_client_get_start(NX_WEB_HTTP_CLIENT * client_ptr,NXD_ADDRESS * server_ip,UINT server_port,CHAR * resource,CHAR * host,CHAR * username,CHAR * password,ULONG wait_option)654 UINT _nx_web_http_client_get_start(NX_WEB_HTTP_CLIENT *client_ptr, NXD_ADDRESS *server_ip, UINT server_port,
655 CHAR *resource, CHAR *host,
656 CHAR *username, CHAR *password, ULONG wait_option)
657 {
658 UINT temp_resource_length;
659 UINT temp_host_length;
660 UINT temp_username_length = 0;
661 UINT temp_password_length = 0;
662
663 if ((username) && (password))
664 {
665
666 /* Check username and password length. */
667 if (_nx_utility_string_length_check(username, &temp_username_length, NX_WEB_HTTP_MAX_NAME) ||
668 _nx_utility_string_length_check(password, &temp_password_length, NX_WEB_HTTP_MAX_PASSWORD))
669 {
670 return(NX_WEB_HTTP_ERROR);
671 }
672 }
673
674 /* Check resource and host length. */
675 if (_nx_utility_string_length_check(resource, &temp_resource_length, NX_MAX_STRING_LENGTH) ||
676 _nx_utility_string_length_check(host, &temp_host_length, NX_MAX_STRING_LENGTH))
677 {
678 return(NX_WEB_HTTP_ERROR);
679 }
680
681 return(_nx_web_http_client_get_start_extended(client_ptr, server_ip, server_port, resource,
682 temp_resource_length, host, temp_host_length, username,
683 temp_username_length, password, temp_password_length,
684 wait_option));
685
686 }
687
688 /**************************************************************************/
689 /* */
690 /* FUNCTION RELEASE */
691 /* */
692 /* _nxe_web_http_client_get_start_extended PORTABLE C */
693 /* 6.1 */
694 /* AUTHOR */
695 /* */
696 /* Yuxin Zhou, Microsoft Corporation */
697 /* */
698 /* DESCRIPTION */
699 /* */
700 /* This function checks for errors in the HTTP Duo client get start */
701 /* call with string length. */
702 /* */
703 /* */
704 /* INPUT */
705 /* */
706 /* client_ptr Pointer to HTTP client */
707 /* server_ip IP duo address of HTTP Server */
708 /* resource Pointer to resource (URL) */
709 /* resource_length String length of resource */
710 /* host Pointer to Host */
711 /* host_length Length of host */
712 /* username Pointer to username */
713 /* username_length Length of username */
714 /* password Pointer to password */
715 /* password_length Length of password */
716 /* wait_option Suspension option */
717 /* */
718 /* OUTPUT */
719 /* */
720 /* status Completion status */
721 /* */
722 /* CALLS */
723 /* */
724 /* _nx_web_http_client_get_start_extended */
725 /* Actual client get start call */
726 /* */
727 /* CALLED BY */
728 /* */
729 /* Application Code */
730 /* */
731 /* RELEASE HISTORY */
732 /* */
733 /* DATE NAME DESCRIPTION */
734 /* */
735 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
736 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
737 /* resulting in version 6.1 */
738 /* */
739 /**************************************************************************/
_nxe_web_http_client_get_start_extended(NX_WEB_HTTP_CLIENT * client_ptr,NXD_ADDRESS * server_ip,UINT server_port,CHAR * resource,UINT resource_length,CHAR * host,UINT host_length,CHAR * username,UINT username_length,CHAR * password,UINT password_length,ULONG wait_option)740 UINT _nxe_web_http_client_get_start_extended(NX_WEB_HTTP_CLIENT *client_ptr, NXD_ADDRESS *server_ip,
741 UINT server_port, CHAR *resource, UINT resource_length,
742 CHAR *host, UINT host_length, CHAR *username,
743 UINT username_length, CHAR *password,
744 UINT password_length, ULONG wait_option)
745 {
746
747 UINT status;
748
749
750 /* Check for invalid input pointers. */
751 if ((client_ptr == NX_NULL) || (client_ptr -> nx_web_http_client_id != NX_WEB_HTTP_CLIENT_ID) ||
752 (resource == NX_NULL) || !server_ip || (host == NX_NULL))
753 return(NX_PTR_ERROR);
754
755 /* Check for appropriate caller. */
756 NX_THREADS_ONLY_CALLER_CHECKING
757
758 /* Call actual GET start routine. */
759 status = _nx_web_http_client_get_start_extended(client_ptr, server_ip, server_port, resource,
760 resource_length, host, host_length, username,
761 username_length, password, password_length,
762 wait_option);
763
764 /* Return completion status. */
765 return(status);
766 }
767
768 /**************************************************************************/
769 /* */
770 /* FUNCTION RELEASE */
771 /* */
772 /* _nx_web_http_client_get_start_extended PORTABLE C */
773 /* 6.1 */
774 /* AUTHOR */
775 /* */
776 /* Yuxin Zhou, Microsoft Corporation */
777 /* */
778 /* DESCRIPTION */
779 /* */
780 /* This function processes the application GET request. The specified */
781 /* resource (URL) is requested from the HTTP Server at the specified */
782 /* IP address. The response is processed by calling */
783 /* nx_web_http_client_response_body_get. */
784 /* */
785 /* Note: The strings of resource, host, username and password must be */
786 /* NULL-terminated and length of each string matches the length */
787 /* specified in the argument list. */
788 /* */
789 /* */
790 /* INPUT */
791 /* */
792 /* client_ptr Pointer to HTTP client */
793 /* server_ip HTTP Server IP address */
794 /* resource Pointer to resource (URL) */
795 /* resource_length String length of resource */
796 /* host Pointer to Host */
797 /* host_length Length of host */
798 /* username Pointer to username */
799 /* username_length Length of username */
800 /* password Pointer to password */
801 /* password_length Length of password */
802 /* wait_option Suspension option */
803 /* */
804 /* OUTPUT */
805 /* */
806 /* status Completion status */
807 /* */
808 /* CALLS */
809 /* */
810 /* _nx_web_http_client_connect Connect to HTTPS server */
811 /* _nx_web_http_client_request_initialize_extended */
812 /* Initialize HTTP request */
813 /* _nx_web_http_client_request_send Send HTTP request to server */
814 /* */
815 /* CALLED BY */
816 /* */
817 /* Application Code */
818 /* */
819 /* RELEASE HISTORY */
820 /* */
821 /* DATE NAME DESCRIPTION */
822 /* */
823 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
824 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
825 /* resulting in version 6.1 */
826 /* */
827 /**************************************************************************/
_nx_web_http_client_get_start_extended(NX_WEB_HTTP_CLIENT * client_ptr,NXD_ADDRESS * server_ip,UINT server_port,CHAR * resource,UINT resource_length,CHAR * host,UINT host_length,CHAR * username,UINT username_length,CHAR * password,UINT password_length,ULONG wait_option)828 UINT _nx_web_http_client_get_start_extended(NX_WEB_HTTP_CLIENT *client_ptr, NXD_ADDRESS *server_ip,
829 UINT server_port, CHAR *resource, UINT resource_length,
830 CHAR *host, UINT host_length, CHAR *username,
831 UINT username_length, CHAR *password,
832 UINT password_length, ULONG wait_option)
833 {
834
835 UINT status;
836
837 client_ptr->nx_web_http_client_connect_port = server_port;
838
839 /* Connect to the server. */
840 status = _nx_web_http_client_connect(client_ptr, server_ip, client_ptr->nx_web_http_client_connect_port, wait_option);
841
842 /* Check status. */
843 if (status != NX_SUCCESS)
844 {
845 return(status);
846 }
847
848 /* Initialize HTTP request. */
849 status = _nx_web_http_client_request_initialize_extended(client_ptr,
850 NX_WEB_HTTP_METHOD_GET,
851 resource,
852 resource_length,
853 host,
854 host_length,
855 0,
856 NX_FALSE, /* If true, input_size is ignored. */
857 username,
858 username_length,
859 password,
860 password_length,
861 wait_option);
862 /* Check status. */
863 if (status != NX_SUCCESS)
864 {
865 return(status);
866 }
867
868 /* Send the HTTP request we just built. */
869 status = _nx_web_http_client_request_send(client_ptr, wait_option);
870
871 /* Check status. */
872 if (status != NX_SUCCESS)
873 {
874 return(status);
875 }
876
877 /* Enter the GET state. */
878 client_ptr -> nx_web_http_client_state = NX_WEB_HTTP_CLIENT_STATE_GET;
879
880 return(status);
881 }
882
883 #ifdef NX_WEB_HTTPS_ENABLE
884 /**************************************************************************/
885 /* */
886 /* FUNCTION RELEASE */
887 /* */
888 /* _nxe_web_http_client_get_secure_start PORTABLE C */
889 /* 6.1 */
890 /* AUTHOR */
891 /* */
892 /* Yuxin Zhou, Microsoft Corporation */
893 /* */
894 /* DESCRIPTION */
895 /* */
896 /* This function checks for errors in the HTTPS secure GET request */
897 /* processing call. */
898 /* */
899 /* */
900 /* INPUT */
901 /* */
902 /* client_ptr Pointer to HTTP client */
903 /* server_ip HTTP Server IP address */
904 /* resource Pointer to resource (URL) */
905 /* host Pointer to Host */
906 /* username Pointer to username */
907 /* password Pointer to password */
908 /* tls_setup TLS setup callback function */
909 /* wait_option Suspension option */
910 /* */
911 /* OUTPUT */
912 /* */
913 /* status Completion status */
914 /* */
915 /* CALLS */
916 /* */
917 /* _nx_web_http_client_get_secure_start Actual GET request processing */
918 /* */
919 /* CALLED BY */
920 /* */
921 /* Application Code */
922 /* */
923 /* RELEASE HISTORY */
924 /* */
925 /* DATE NAME DESCRIPTION */
926 /* */
927 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
928 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
929 /* resulting in version 6.1 */
930 /* */
931 /**************************************************************************/
_nxe_web_http_client_get_secure_start(NX_WEB_HTTP_CLIENT * client_ptr,NXD_ADDRESS * server_ip,UINT server_port,CHAR * resource,CHAR * host,CHAR * username,CHAR * password,UINT (* tls_setup)(NX_WEB_HTTP_CLIENT * client_ptr,NX_SECURE_TLS_SESSION *),ULONG wait_option)932 UINT _nxe_web_http_client_get_secure_start(NX_WEB_HTTP_CLIENT *client_ptr, NXD_ADDRESS *server_ip, UINT server_port, CHAR *resource,
933 CHAR *host, CHAR *username, CHAR *password,
934 UINT (*tls_setup)(NX_WEB_HTTP_CLIENT *client_ptr, NX_SECURE_TLS_SESSION *),
935 ULONG wait_option)
936 {
937 UINT status;
938
939 /* Check for invalid input pointers. */
940 if ((client_ptr == NX_NULL) || (client_ptr -> nx_web_http_client_id != NX_WEB_HTTP_CLIENT_ID) ||
941 (resource == NX_NULL) || !server_ip || !tls_setup || (host == NX_NULL))
942 return(NX_PTR_ERROR);
943
944 /* Check for appropriate caller. */
945 NX_THREADS_ONLY_CALLER_CHECKING
946
947 /* Call actual GET start routine. */
948 status = _nx_web_http_client_get_secure_start(client_ptr, server_ip, server_port, resource,
949 host, username, password, tls_setup, wait_option);
950
951 /* Return completion status. */
952 return(status);
953 }
954
955
956
957 /**************************************************************************/
958 /* */
959 /* FUNCTION RELEASE */
960 /* */
961 /* _nx_web_http_client_get_secure_start PORTABLE C */
962 /* 6.1 */
963 /* AUTHOR */
964 /* */
965 /* Yuxin Zhou, Microsoft Corporation */
966 /* */
967 /* DESCRIPTION */
968 /* */
969 /* This function processes an application GET request. The specified */
970 /* resource (URL) is requested from the HTTP Server at the specified */
971 /* IP address. This version of the function also requires a TLS setup */
972 /* callback as the request is sent over TLS-secured HTTPS. */
973 /* */
974 /* */
975 /* INPUT */
976 /* */
977 /* client_ptr Pointer to HTTP client */
978 /* server_ip HTTP Server IP address */
979 /* resource Pointer to resource (URL) */
980 /* host Pointer to Host */
981 /* username Pointer to username */
982 /* password Pointer to password */
983 /* tls_setup TLS setup callback function */
984 /* wait_option Suspension option */
985 /* */
986 /* OUTPUT */
987 /* */
988 /* status Completion status */
989 /* */
990 /* CALLS */
991 /* */
992 /* _nx_web_http_client_get_secure_start_extended */
993 /* Actual GET request processing */
994 /* _nx_utility_string_length_check Check string length */
995 /* */
996 /* CALLED BY */
997 /* */
998 /* Application Code */
999 /* */
1000 /* RELEASE HISTORY */
1001 /* */
1002 /* DATE NAME DESCRIPTION */
1003 /* */
1004 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
1005 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
1006 /* resulting in version 6.1 */
1007 /* */
1008 /**************************************************************************/
_nx_web_http_client_get_secure_start(NX_WEB_HTTP_CLIENT * client_ptr,NXD_ADDRESS * server_ip,UINT server_port,CHAR * resource,CHAR * host,CHAR * username,CHAR * password,UINT (* tls_setup)(NX_WEB_HTTP_CLIENT * client_ptr,NX_SECURE_TLS_SESSION *),ULONG wait_option)1009 UINT _nx_web_http_client_get_secure_start(NX_WEB_HTTP_CLIENT *client_ptr, NXD_ADDRESS *server_ip, UINT server_port, CHAR *resource,
1010 CHAR *host, CHAR *username, CHAR *password,
1011 UINT (*tls_setup)(NX_WEB_HTTP_CLIENT *client_ptr, NX_SECURE_TLS_SESSION *),
1012 ULONG wait_option)
1013 {
1014 UINT temp_resource_length;
1015 UINT temp_host_length;
1016 UINT temp_username_length = 0;
1017 UINT temp_password_length = 0;
1018
1019 if ((username) && (password))
1020 {
1021
1022 /* Check username and password length. */
1023 if (_nx_utility_string_length_check(username, &temp_username_length, NX_WEB_HTTP_MAX_NAME) ||
1024 _nx_utility_string_length_check(password, &temp_password_length, NX_WEB_HTTP_MAX_PASSWORD))
1025 {
1026 return(NX_WEB_HTTP_ERROR);
1027 }
1028 }
1029
1030 /* Check resource and host length. */
1031 if (_nx_utility_string_length_check(resource, &temp_resource_length, NX_MAX_STRING_LENGTH) ||
1032 _nx_utility_string_length_check(host, &temp_host_length, NX_MAX_STRING_LENGTH))
1033 {
1034 return(NX_WEB_HTTP_ERROR);
1035 }
1036
1037 return(_nx_web_http_client_get_secure_start_extended(client_ptr, server_ip, server_port,
1038 resource, temp_resource_length, host,
1039 temp_host_length, username,
1040 temp_username_length, password,
1041 temp_password_length, tls_setup,
1042 wait_option));
1043 }
1044
1045 /**************************************************************************/
1046 /* */
1047 /* FUNCTION RELEASE */
1048 /* */
1049 /* _nxe_web_http_client_get_secure_start_extended PORTABLE C */
1050 /* 6.1 */
1051 /* AUTHOR */
1052 /* */
1053 /* Yuxin Zhou, Microsoft Corporation */
1054 /* */
1055 /* DESCRIPTION */
1056 /* */
1057 /* This function checks for errors in the HTTPS secure GET request */
1058 /* processing call. */
1059 /* */
1060 /* */
1061 /* INPUT */
1062 /* */
1063 /* client_ptr Pointer to HTTP client */
1064 /* server_ip IP duo address of HTTP Server */
1065 /* resource Pointer to resource (URL) */
1066 /* resource_length String length of resource */
1067 /* host Pointer to Host */
1068 /* host_length Length of host */
1069 /* username Pointer to username */
1070 /* username_length Length of username */
1071 /* password Pointer to password */
1072 /* password_length Length of password */
1073 /* tls_setup TLS setup callback function */
1074 /* wait_option Suspension option */
1075 /* */
1076 /* OUTPUT */
1077 /* */
1078 /* status Completion status */
1079 /* */
1080 /* CALLS */
1081 /* */
1082 /* _nx_web_http_client_get_secure_start_extended */
1083 /* Actual GET request processing */
1084 /* */
1085 /* CALLED BY */
1086 /* */
1087 /* Application Code */
1088 /* */
1089 /* RELEASE HISTORY */
1090 /* */
1091 /* DATE NAME DESCRIPTION */
1092 /* */
1093 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
1094 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
1095 /* resulting in version 6.1 */
1096 /* */
1097 /**************************************************************************/
_nxe_web_http_client_get_secure_start_extended(NX_WEB_HTTP_CLIENT * client_ptr,NXD_ADDRESS * server_ip,UINT server_port,CHAR * resource,UINT resource_length,CHAR * host,UINT host_length,CHAR * username,UINT username_length,CHAR * password,UINT password_length,UINT (* tls_setup)(NX_WEB_HTTP_CLIENT * client_ptr,NX_SECURE_TLS_SESSION *),ULONG wait_option)1098 UINT _nxe_web_http_client_get_secure_start_extended(NX_WEB_HTTP_CLIENT *client_ptr, NXD_ADDRESS *server_ip, UINT server_port,
1099 CHAR *resource, UINT resource_length, CHAR *host, UINT host_length,
1100 CHAR *username, UINT username_length, CHAR *password, UINT password_length,
1101 UINT (*tls_setup)(NX_WEB_HTTP_CLIENT *client_ptr, NX_SECURE_TLS_SESSION *),
1102 ULONG wait_option)
1103 {
1104 UINT status;
1105
1106 /* Check for invalid input pointers. */
1107 if ((client_ptr == NX_NULL) || (client_ptr -> nx_web_http_client_id != NX_WEB_HTTP_CLIENT_ID) ||
1108 (resource == NX_NULL) || !server_ip || !tls_setup || (host == NX_NULL))
1109 return(NX_PTR_ERROR);
1110
1111 /* Check for appropriate caller. */
1112 NX_THREADS_ONLY_CALLER_CHECKING
1113
1114 /* Call actual GET start routine. */
1115 status = _nx_web_http_client_get_secure_start_extended(client_ptr, server_ip, server_port,
1116 resource, resource_length, host,
1117 host_length, username, username_length,
1118 password, password_length, tls_setup,
1119 wait_option);
1120
1121 /* Return completion status. */
1122 return(status);
1123 }
1124
1125
1126
1127 /**************************************************************************/
1128 /* */
1129 /* FUNCTION RELEASE */
1130 /* */
1131 /* _nx_web_http_client_get_secure_start_extended PORTABLE C */
1132 /* 6.1 */
1133 /* AUTHOR */
1134 /* */
1135 /* Yuxin Zhou, Microsoft Corporation */
1136 /* */
1137 /* DESCRIPTION */
1138 /* */
1139 /* This function processes an application GET request. The specified */
1140 /* resource (URL) is requested from the HTTP Server at the specified */
1141 /* IP address. This version of the function also requires a TLS setup */
1142 /* callback as the request is sent over TLS-secured HTTPS. */
1143 /* */
1144 /* Note: The strings of resource, host, username and password must be */
1145 /* NULL-terminated and length of each string matches the length */
1146 /* specified in the argument list. */
1147 /* */
1148 /* */
1149 /* INPUT */
1150 /* */
1151 /* client_ptr Pointer to HTTP client */
1152 /* server_ip IP duo address of HTTP Server */
1153 /* resource Pointer to resource (URL) */
1154 /* resource_length String length of resource */
1155 /* host Pointer to Host */
1156 /* host_length Length of host */
1157 /* username Pointer to username */
1158 /* username_length Length of username */
1159 /* password Pointer to password */
1160 /* password_length Length of password */
1161 /* tls_setup TLS setup callback function */
1162 /* wait_option Suspension option */
1163 /* */
1164 /* OUTPUT */
1165 /* */
1166 /* status Completion status */
1167 /* */
1168 /* CALLS */
1169 /* */
1170 /* _nx_web_http_client_secure_connect Connect to HTTPS server */
1171 /* _nx_web_http_client_request_initialize_extended */
1172 /* Initialize HTTP request */
1173 /* _nx_web_http_client_request_send Send HTTP request to server */
1174 /* */
1175 /* CALLED BY */
1176 /* */
1177 /* Application Code */
1178 /* */
1179 /* RELEASE HISTORY */
1180 /* */
1181 /* DATE NAME DESCRIPTION */
1182 /* */
1183 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
1184 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
1185 /* resulting in version 6.1 */
1186 /* */
1187 /**************************************************************************/
_nx_web_http_client_get_secure_start_extended(NX_WEB_HTTP_CLIENT * client_ptr,NXD_ADDRESS * server_ip,UINT server_port,CHAR * resource,UINT resource_length,CHAR * host,UINT host_length,CHAR * username,UINT username_length,CHAR * password,UINT password_length,UINT (* tls_setup)(NX_WEB_HTTP_CLIENT * client_ptr,NX_SECURE_TLS_SESSION *),ULONG wait_option)1188 UINT _nx_web_http_client_get_secure_start_extended(NX_WEB_HTTP_CLIENT *client_ptr, NXD_ADDRESS *server_ip, UINT server_port,
1189 CHAR *resource, UINT resource_length, CHAR *host, UINT host_length,
1190 CHAR *username, UINT username_length, CHAR *password, UINT password_length,
1191 UINT (*tls_setup)(NX_WEB_HTTP_CLIENT *client_ptr, NX_SECURE_TLS_SESSION *),
1192 ULONG wait_option)
1193 {
1194
1195 UINT status;
1196
1197 /* Use default HTTPS port. */
1198 client_ptr->nx_web_http_client_connect_port = server_port;
1199
1200 /* Connect to the server. */
1201 status = _nx_web_http_client_secure_connect(client_ptr, server_ip, client_ptr->nx_web_http_client_connect_port, tls_setup, wait_option);
1202
1203 /* Check status. */
1204 if (status != NX_SUCCESS)
1205 {
1206 return(status);
1207 }
1208
1209 /* Initialize HTTP request. */
1210 status = _nx_web_http_client_request_initialize_extended(client_ptr,
1211 NX_WEB_HTTP_METHOD_GET,
1212 resource,
1213 resource_length,
1214 host,
1215 host_length,
1216 0,
1217 NX_FALSE, /* If true, input_size is ignored. */
1218 username,
1219 username_length,
1220 password,
1221 password_length,
1222 wait_option);
1223
1224 /* Check status. */
1225 if (status != NX_SUCCESS)
1226 {
1227 return(status);
1228 }
1229
1230 /* Send the HTTP request we just built. */
1231 status = _nx_web_http_client_request_send(client_ptr, wait_option);
1232
1233 /* Check status. */
1234 if (status != NX_SUCCESS)
1235 {
1236 return(status);
1237 }
1238
1239 /* Enter the GET state. */
1240 client_ptr -> nx_web_http_client_state = NX_WEB_HTTP_CLIENT_STATE_GET;
1241
1242 return(status);
1243 }
1244
1245 #endif /* NX_WEB_HTTPS_ENABLE */
1246
1247 /**************************************************************************/
1248 /* */
1249 /* FUNCTION RELEASE */
1250 /* */
1251 /* _nx_web_http_client_get_server_response PORTABLE C */
1252 /* 6.1 */
1253 /* AUTHOR */
1254 /* */
1255 /* Yuxin Zhou, Microsoft Corporation */
1256 /* */
1257 /* DESCRIPTION */
1258 /* */
1259 /* This function retrieves the initial response from the remote */
1260 /* server. The body of the response is retrieved by the application */
1261 /* by calling the GET response body API. */
1262 /* */
1263 /* */
1264 /* INPUT */
1265 /* */
1266 /* client_ptr Pointer to HTTP client */
1267 /* packet_ptr Pointer to packet */
1268 /* wait_option Suspension option */
1269 /* */
1270 /* OUTPUT */
1271 /* */
1272 /* status Completion status */
1273 /* */
1274 /* CALLS */
1275 /* */
1276 /* _nx_web_http_client_receive Receive packet */
1277 /* nx_packet_data_append Put data into return packet */
1278 /* nx_packet_copy Copy packet data */
1279 /* nx_packet_release Release processed packets */
1280 /* */
1281 /* CALLED BY */
1282 /* */
1283 /* Application Code */
1284 /* */
1285 /* RELEASE HISTORY */
1286 /* */
1287 /* DATE NAME DESCRIPTION */
1288 /* */
1289 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
1290 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
1291 /* resulting in version 6.1 */
1292 /* */
1293 /**************************************************************************/
_nx_web_http_client_get_server_response(NX_WEB_HTTP_CLIENT * client_ptr,NX_PACKET ** packet_ptr,ULONG wait_option)1294 UINT _nx_web_http_client_get_server_response(NX_WEB_HTTP_CLIENT *client_ptr, NX_PACKET **packet_ptr, ULONG wait_option)
1295 {
1296
1297 NX_PACKET *head_packet_ptr;
1298 NX_PACKET *new_packet_ptr;
1299 CHAR *buffer_ptr;
1300 UINT status;
1301 NX_PACKET *work_ptr;
1302 UINT crlf_found = 0;
1303 NX_PACKET *tmp_ptr;
1304
1305
1306 /* Default the return packet pointer to NULL. */
1307 *packet_ptr = NX_NULL;
1308
1309 /* Wait for a response from server. */
1310 status = _nx_web_http_client_receive(client_ptr, &head_packet_ptr, wait_option);
1311
1312 /* Check the return status. */
1313 if (status != NX_SUCCESS)
1314 {
1315
1316 /* Return an error condition. */
1317 return(status);
1318 }
1319
1320 crlf_found = 0;
1321 work_ptr = head_packet_ptr;
1322
1323 /* Build a pointer to the buffer area. */
1324 buffer_ptr = (CHAR *) work_ptr -> nx_packet_prepend_ptr;
1325
1326 do
1327 {
1328
1329 /* See if there is a blank line present in the buffer. */
1330 /* Search the buffer for a cr/lf pair. */
1331 while (buffer_ptr < (CHAR *) work_ptr -> nx_packet_append_ptr)
1332 {
1333 if (!(crlf_found & 1) && (*buffer_ptr == (CHAR)13))
1334 {
1335
1336 /* Found CR. */
1337 crlf_found++;
1338 }
1339 else if((crlf_found & 1) && (*buffer_ptr == (CHAR)10))
1340 {
1341
1342 /* Found LF. */
1343 crlf_found++;
1344 }
1345 else
1346 {
1347
1348 /* Reset the CRLF marker. */
1349 crlf_found = 0;
1350 }
1351
1352 if (crlf_found == 4)
1353 {
1354
1355 /* Yes, we have found the end of the HTTP response header. */
1356
1357 /* Set the return packet pointer. */
1358 *packet_ptr = head_packet_ptr;
1359
1360 /* Return a successful completion. */
1361 return(NX_SUCCESS);
1362 }
1363
1364 /* Move the buffer pointer up. */
1365 buffer_ptr++;
1366 }
1367
1368 /* Determine if the packet has already overflowed into another packet. */
1369
1370 #ifndef NX_DISABLE_PACKET_CHAIN
1371
1372 if (work_ptr -> nx_packet_next != NX_NULL)
1373 {
1374
1375 /* Get the next packet in the chain. */
1376 work_ptr = work_ptr -> nx_packet_next;
1377 buffer_ptr = (CHAR *) work_ptr -> nx_packet_prepend_ptr;
1378 }
1379 else
1380 #endif
1381 {
1382 /* Receive another packet from the HTTP server port. */
1383 status = _nx_web_http_client_receive(client_ptr, &new_packet_ptr, wait_option);
1384
1385 /* Check the return status. */
1386 if (status != NX_SUCCESS)
1387 {
1388
1389 /* Release the current head packet. */
1390 nx_packet_release(head_packet_ptr);
1391
1392 /* Return an error condition. */
1393 return(status);
1394 }
1395
1396 /* Successfully received another packet. Its contents now need to be placed in the head packet. */
1397 tmp_ptr = new_packet_ptr;
1398
1399 #ifndef NX_DISABLE_PACKET_CHAIN
1400 while (tmp_ptr)
1401 {
1402 #endif /* NX_DISABLE_PACKET_CHAIN */
1403
1404 /* Copy the contents of the current packet into the head packet. */
1405 status = nx_packet_data_append(head_packet_ptr, (VOID *) tmp_ptr -> nx_packet_prepend_ptr,
1406 (ULONG)(tmp_ptr -> nx_packet_append_ptr - tmp_ptr -> nx_packet_prepend_ptr),
1407 client_ptr -> nx_web_http_client_packet_pool_ptr, wait_option);
1408
1409 /* Determine if an error occurred. */
1410 if (status != NX_SUCCESS)
1411 {
1412
1413 /* Yes, an error is present. */
1414
1415 /* Release both packets. */
1416 nx_packet_release(head_packet_ptr);
1417 nx_packet_release(new_packet_ptr);
1418
1419 /* Return an error condition. */
1420 return(status);
1421 }
1422
1423 #ifndef NX_DISABLE_PACKET_CHAIN
1424 tmp_ptr = tmp_ptr -> nx_packet_next;
1425 }
1426 #endif /* NX_DISABLE_PACKET_CHAIN */
1427
1428 /* Release the new packet. */
1429 nx_packet_release(new_packet_ptr);
1430 }
1431
1432 } while (status == NX_SUCCESS);
1433
1434 /* Release the packet. */
1435 nx_packet_release(head_packet_ptr);
1436
1437 return(NX_WEB_HTTP_ERROR);
1438 }
1439
1440 /**************************************************************************/
1441 /* */
1442 /* FUNCTION RELEASE */
1443 /* */
1444 /* _nxe_web_http_client_response_body_get PORTABLE C */
1445 /* 6.1 */
1446 /* AUTHOR */
1447 /* */
1448 /* Yuxin Zhou, Microsoft Corporation */
1449 /* */
1450 /* DESCRIPTION */
1451 /* */
1452 /* This function checks for errors in the HTTP client get packet call. */
1453 /* */
1454 /* */
1455 /* INPUT */
1456 /* */
1457 /* client_ptr Pointer to HTTP client */
1458 /* packet_ptr Destination for packet pointer*/
1459 /* wait_option Suspension option */
1460 /* */
1461 /* OUTPUT */
1462 /* */
1463 /* status Completion status */
1464 /* */
1465 /* CALLS */
1466 /* */
1467 /* _nx_web_http_client_response_body_get Actual client get packet call */
1468 /* */
1469 /* CALLED BY */
1470 /* */
1471 /* Application Code */
1472 /* */
1473 /* RELEASE HISTORY */
1474 /* */
1475 /* DATE NAME DESCRIPTION */
1476 /* */
1477 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
1478 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
1479 /* resulting in version 6.1 */
1480 /* */
1481 /**************************************************************************/
_nxe_web_http_client_response_body_get(NX_WEB_HTTP_CLIENT * client_ptr,NX_PACKET ** packet_ptr,ULONG wait_option)1482 UINT _nxe_web_http_client_response_body_get(NX_WEB_HTTP_CLIENT *client_ptr, NX_PACKET **packet_ptr, ULONG wait_option)
1483 {
1484
1485 UINT status;
1486
1487
1488 /* Check for invalid input pointers. */
1489 if ((client_ptr == NX_NULL) || (client_ptr -> nx_web_http_client_id != NX_WEB_HTTP_CLIENT_ID) ||
1490 (packet_ptr == NX_NULL))
1491 return(NX_PTR_ERROR);
1492
1493 /* Check for appropriate caller. */
1494 NX_THREADS_ONLY_CALLER_CHECKING
1495
1496 /* Call actual GET packet routine. */
1497 status = _nx_web_http_client_response_body_get(client_ptr, packet_ptr, wait_option);
1498
1499 /* Return completion status. */
1500 return(status);
1501 }
1502
1503 /**************************************************************************/
1504 /* */
1505 /* FUNCTION RELEASE */
1506 /* */
1507 /* _nx_web_http_client_response_body_get PORTABLE C */
1508 /* 6.1.11 */
1509 /* AUTHOR */
1510 /* */
1511 /* Yuxin Zhou, Microsoft Corporation */
1512 /* */
1513 /* DESCRIPTION */
1514 /* */
1515 /* This function gets a data packet associated with the resource */
1516 /* specified by the previous GET start request. It can be called */
1517 /* repeatedly to get all of the packets for larger resources. */
1518 /* */
1519 /* */
1520 /* INPUT */
1521 /* */
1522 /* client_ptr Pointer to HTTP client */
1523 /* packet_ptr Destination for packet pointer*/
1524 /* wait_option Suspension option */
1525 /* */
1526 /* OUTPUT */
1527 /* */
1528 /* status Completion status */
1529 /* */
1530 /* CALLS */
1531 /* */
1532 /* _nx_web_http_client_receive Receive a resource data packet*/
1533 /* _nx_web_http_client_get_server_response */
1534 /* Get server response header */
1535 /* _nx_web_http_client_content_length_get */
1536 /* Get Content Length value */
1537 /* _nx_web_http_client_process_header_fields */
1538 /* Process HTTP header fields */
1539 /* _nx_web_http_client_error_exit Close HTTP(S) session */
1540 /* _nx_web_http_client_response_chunked_get */
1541 /* Get chunked response packet */
1542 /* */
1543 /* CALLED BY */
1544 /* */
1545 /* Application Code */
1546 /* */
1547 /* RELEASE HISTORY */
1548 /* */
1549 /* DATE NAME DESCRIPTION */
1550 /* */
1551 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
1552 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
1553 /* resulting in version 6.1 */
1554 /* 04-25-2022 Yuxin Zhou Modified comment(s), */
1555 /* released invalid packet, */
1556 /* resulting in version 6.1.11 */
1557 /* */
1558 /**************************************************************************/
_nx_web_http_client_response_body_get(NX_WEB_HTTP_CLIENT * client_ptr,NX_PACKET ** packet_pptr,ULONG wait_option)1559 UINT _nx_web_http_client_response_body_get(NX_WEB_HTTP_CLIENT *client_ptr, NX_PACKET **packet_pptr, ULONG wait_option)
1560 {
1561
1562 UINT status = NX_SUCCESS;
1563 UINT length = 0, offset = 0;
1564 NX_PACKET *response_packet_ptr = NX_NULL;
1565 CHAR *buffer_ptr;
1566 UINT i = 0;
1567 UINT status_code = NX_SUCCESS;
1568
1569
1570 /* Check if the request packet is sent out. */
1571 if ((client_ptr -> nx_web_http_client_state < NX_WEB_HTTP_CLIENT_STATE_GET) ||
1572 (client_ptr -> nx_web_http_client_state > NX_WEB_HTTP_CLIENT_STATE_DELETE))
1573 {
1574 return(NX_WEB_HTTP_ERROR);
1575 }
1576
1577 /* Default the return packet to NULL. */
1578 *packet_pptr = NX_NULL;
1579
1580 /* Check for a response from the Server. */
1581 if (!(client_ptr -> nx_web_http_client_response_header_received))
1582 {
1583
1584 /* Pickup the response from the Server. */
1585 status = _nx_web_http_client_get_server_response(client_ptr, &response_packet_ptr, wait_option);
1586
1587 /* Validate the response packet length. */
1588 if (status == NX_SUCCESS)
1589 {
1590 if (response_packet_ptr -> nx_packet_append_ptr - response_packet_ptr -> nx_packet_prepend_ptr < 12)
1591 {
1592
1593 /* Release invalid packet. */
1594 nx_packet_release(response_packet_ptr);
1595 status = NX_WEB_HTTP_ERROR;
1596 }
1597 }
1598
1599 /* Check for error processing received packet. */
1600 if (status != NX_SUCCESS)
1601 {
1602
1603 if (status != NX_NO_PACKET)
1604 {
1605 /* Disconnect and unbind the socket. */
1606 _nx_web_http_client_error_exit(client_ptr, wait_option);
1607
1608 /* Reenter the READY state. */
1609 client_ptr->nx_web_http_client_state = NX_WEB_HTTP_CLIENT_STATE_READY;
1610 }
1611
1612 return(status);
1613 }
1614
1615 /* Setup pointer to server response. */
1616 buffer_ptr = (CHAR *) response_packet_ptr -> nx_packet_prepend_ptr;
1617
1618 /* Determine which status code is reveived. */
1619 for (i = 0; i < _nx_web_http_client_status_maps_size; i++)
1620 {
1621 if ((buffer_ptr[9] == _nx_web_http_client_status_maps[i].nx_web_http_client_status_string[0]) &&
1622 (buffer_ptr[10] == _nx_web_http_client_status_maps[i].nx_web_http_client_status_string[1]) &&
1623 (buffer_ptr[11] == _nx_web_http_client_status_maps[i].nx_web_http_client_status_string[2]))
1624 {
1625 status_code = _nx_web_http_client_status_maps[i].nx_web_http_client_status_code;
1626 break;
1627 }
1628 }
1629
1630 /* Check the status code. */
1631 if (i == _nx_web_http_client_status_maps_size)
1632 {
1633
1634 /* Received an unknown status code. */
1635 status = NX_WEB_HTTP_REQUEST_UNSUCCESSFUL_CODE;
1636 }
1637 else if (buffer_ptr[9] != '2')
1638 {
1639
1640 /* Received an error status code. */
1641 status = status_code;
1642 }
1643 /* Determine if the request was successful. */
1644 else
1645 {
1646
1647 /* Pickup the content length if it exists. */
1648 length = _nx_web_http_client_content_length_get(client_ptr, response_packet_ptr);
1649
1650 /* Pickup the content offset and process other headers. */
1651 offset = _nx_web_http_client_process_header_fields(client_ptr, response_packet_ptr);
1652
1653 /* Determine if the packet is valid. */
1654 if (!offset ||
1655 (response_packet_ptr -> nx_packet_length < offset) ||
1656 ((response_packet_ptr -> nx_packet_length > (offset + length)) &&
1657 (!client_ptr -> nx_web_http_client_response_chunked)))
1658 {
1659
1660 /* Bad packet length. */
1661 status = NX_WEB_HTTP_BAD_PACKET_LENGTH;
1662 }
1663 else
1664 {
1665
1666 /* Set the flag of response header received. */
1667 client_ptr -> nx_web_http_client_response_header_received = NX_TRUE;
1668
1669 /* Store the total number of bytes to receive.
1670 For HEAD request, just process the response header. */
1671 if (client_ptr -> nx_web_http_client_state != NX_WEB_HTTP_CLIENT_STATE_HEAD)
1672 {
1673 client_ptr -> nx_web_http_client_total_receive_bytes = length;
1674 }
1675 else
1676 {
1677 client_ptr -> nx_web_http_client_total_receive_bytes = 0;
1678 }
1679 client_ptr -> nx_web_http_client_actual_bytes_received = 0;
1680
1681 /* Adjust the pointers to skip over the response header. */
1682 response_packet_ptr -> nx_packet_prepend_ptr = response_packet_ptr -> nx_packet_prepend_ptr + offset;
1683
1684 /* Reduce the length. */
1685 response_packet_ptr -> nx_packet_length = response_packet_ptr -> nx_packet_length - offset;
1686
1687 /* Set for processing chunked response. */
1688 if (client_ptr -> nx_web_http_client_response_chunked)
1689 {
1690 client_ptr -> nx_web_http_client_response_packet = response_packet_ptr;
1691 client_ptr -> nx_web_http_client_chunked_response_remaining_size = response_packet_ptr -> nx_packet_length;
1692 }
1693 }
1694 }
1695 }
1696 else if (!client_ptr -> nx_web_http_client_response_chunked)
1697 {
1698
1699 /* Pickup the response from the Server. */
1700 status = _nx_web_http_client_receive(client_ptr, &response_packet_ptr, wait_option);
1701
1702 /* Check for error processing received packet. */
1703 if (status != NX_SUCCESS)
1704 {
1705
1706 if (status != NX_NO_PACKET)
1707 {
1708
1709 /* Clear the flag of response header received. */
1710 client_ptr->nx_web_http_client_response_header_received = NX_FALSE;
1711
1712 /* Disconnect and unbind the socket. */
1713 _nx_web_http_client_error_exit(client_ptr, wait_option);
1714
1715 /* Reenter the READY state. */
1716 client_ptr->nx_web_http_client_state = NX_WEB_HTTP_CLIENT_STATE_READY;
1717 }
1718
1719 return(status);
1720 }
1721
1722 if (response_packet_ptr -> nx_packet_length > (client_ptr -> nx_web_http_client_total_receive_bytes - client_ptr -> nx_web_http_client_actual_bytes_received))
1723 {
1724
1725 /* Bad packet length. */
1726 status = NX_WEB_HTTP_BAD_PACKET_LENGTH;
1727 }
1728 }
1729
1730 if (status == NX_SUCCESS)
1731 {
1732 if (client_ptr -> nx_web_http_client_response_chunked)
1733 {
1734
1735 /* Process the chunked response. */
1736 status = _nx_web_http_client_response_chunked_get(client_ptr, &response_packet_ptr, wait_option);
1737
1738 if (status == NX_NO_PACKET)
1739 {
1740 return(status);
1741 }
1742 }
1743 else
1744 {
1745
1746 /* Adjust the actual received bytes. */
1747 client_ptr -> nx_web_http_client_actual_bytes_received = client_ptr -> nx_web_http_client_actual_bytes_received +
1748 response_packet_ptr -> nx_packet_length;
1749
1750 /* Determine if the GET packet operation is complete. */
1751 if (client_ptr -> nx_web_http_client_total_receive_bytes == client_ptr -> nx_web_http_client_actual_bytes_received)
1752 {
1753
1754 /* Yes, we are finished. */
1755 status = NX_WEB_HTTP_GET_DONE;
1756 }
1757 }
1758
1759 /* Move the packet pointer into the return pointer. */
1760 *packet_pptr = response_packet_ptr;
1761 }
1762
1763 if (status != NX_SUCCESS)
1764 {
1765
1766 /* Error, break down the connection and return to the caller. */
1767 if ((status != NX_WEB_HTTP_GET_DONE) && response_packet_ptr)
1768 {
1769
1770 /* Release the invalid HTTP packet. */
1771 nx_packet_release(response_packet_ptr);
1772 }
1773
1774 if (client_ptr -> nx_web_http_client_response_chunked)
1775 {
1776
1777 /* If the response is chunked, reset the chunk info. */
1778 if (status != NX_WEB_HTTP_GET_DONE)
1779 {
1780
1781 /* If status is NX_WEB_HTTP_GET_DONE, return this packet. */
1782 nx_packet_release(client_ptr -> nx_web_http_client_response_packet);
1783 }
1784 client_ptr -> nx_web_http_client_response_packet = NX_NULL;
1785 client_ptr -> nx_web_http_client_chunked_response_remaining_size = 0;
1786 client_ptr -> nx_web_http_client_response_chunked = NX_FALSE;
1787 }
1788
1789 /* Clear the flag of response header received. */
1790 client_ptr -> nx_web_http_client_response_header_received = NX_FALSE;
1791
1792 #ifndef NX_WEB_HTTP_KEEPALIVE_DISABLE
1793 if ((status != NX_WEB_HTTP_GET_DONE) || !(client_ptr -> nx_web_http_client_keep_alive))
1794 #endif /* NX_WEB_HTTP_KEEPALIVE_DISABLE */
1795 {
1796
1797 /* Disconnect and unbind the socket. */
1798 _nx_web_http_client_error_exit(client_ptr, wait_option);
1799 }
1800
1801 /* Reenter the READY state. */
1802 client_ptr -> nx_web_http_client_state = NX_WEB_HTTP_CLIENT_STATE_READY;
1803 }
1804
1805 /* Return status. */
1806 return(status);
1807 }
1808
1809 /**************************************************************************/
1810 /* */
1811 /* FUNCTION RELEASE */
1812 /* */
1813 /* _nx_web_http_client_response_read PORTABLE C */
1814 /* 6.1 */
1815 /* AUTHOR */
1816 /* */
1817 /* Yuxin Zhou, Microsoft Corporation */
1818 /* */
1819 /* DESCRIPTION */
1820 /* */
1821 /* This function gets the next data in byte. */
1822 /* */
1823 /* */
1824 /* INPUT */
1825 /* */
1826 /* client_ptr Pointer to HTTP client */
1827 /* data Returned data */
1828 /* wait_option Suspension option */
1829 /* current_packet_pptr Pointer to the packet being */
1830 /* processed */
1831 /* current_data_ptr Pointer to the data will be */
1832 /* processed */
1833 /* */
1834 /* OUTPUT */
1835 /* */
1836 /* status Completion status */
1837 /* */
1838 /* CALLS */
1839 /* */
1840 /* _nx_web_http_client_receive Receive another packet */
1841 /* */
1842 /* CALLED BY */
1843 /* */
1844 /* Application Code */
1845 /* */
1846 /* RELEASE HISTORY */
1847 /* */
1848 /* DATE NAME DESCRIPTION */
1849 /* */
1850 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
1851 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
1852 /* resulting in version 6.1 */
1853 /* */
1854 /**************************************************************************/
_nx_web_http_client_response_read(NX_WEB_HTTP_CLIENT * client_ptr,UCHAR * data,ULONG wait_option,NX_PACKET ** current_packet_pptr,UCHAR ** current_data_pptr)1855 UINT _nx_web_http_client_response_read(NX_WEB_HTTP_CLIENT *client_ptr, UCHAR *data, ULONG wait_option,
1856 NX_PACKET **current_packet_pptr, UCHAR **current_data_pptr)
1857 {
1858 UINT status;
1859
1860 /* If there is no remaining data. */
1861 while (client_ptr -> nx_web_http_client_chunked_response_remaining_size == 0)
1862 {
1863
1864 /* Release the previous received packet. */
1865 if (client_ptr -> nx_web_http_client_response_packet)
1866 {
1867 nx_packet_release(client_ptr -> nx_web_http_client_response_packet);
1868 client_ptr -> nx_web_http_client_response_packet = NX_NULL;
1869 }
1870
1871 /* Receive another packet. */
1872 status = _nx_web_http_client_receive(client_ptr, &(client_ptr -> nx_web_http_client_response_packet), wait_option);
1873 if (status)
1874 {
1875 return(status);
1876 }
1877
1878 /* Update the packet pointer, data pointer and remaining size. */
1879 (*current_packet_pptr) = client_ptr -> nx_web_http_client_response_packet;
1880 (*current_data_pptr) = client_ptr -> nx_web_http_client_response_packet -> nx_packet_prepend_ptr;
1881 client_ptr -> nx_web_http_client_chunked_response_remaining_size = client_ptr -> nx_web_http_client_response_packet -> nx_packet_length;
1882 }
1883
1884 /* Process the packet chain. */
1885 if ((*current_data_pptr) == (*current_packet_pptr) -> nx_packet_append_ptr)
1886 {
1887 #ifndef NX_DISABLE_PACKET_CHAIN
1888 if ((*current_packet_pptr) -> nx_packet_next == NX_NULL)
1889 {
1890 return(NX_INVALID_PACKET);
1891 }
1892
1893 (*current_packet_pptr) = (*current_packet_pptr) -> nx_packet_next;
1894 (*current_data_pptr) = (*current_packet_pptr) -> nx_packet_prepend_ptr;
1895
1896 /* Release the processed packet in the packet chain. */
1897 if (client_ptr -> nx_web_http_client_response_packet)
1898 {
1899 client_ptr -> nx_web_http_client_response_packet -> nx_packet_next = NX_NULL;
1900 nx_packet_release(client_ptr -> nx_web_http_client_response_packet);
1901 client_ptr -> nx_web_http_client_response_packet = (*current_packet_pptr);
1902 }
1903 #else
1904 return(NX_INVALID_PACKET);
1905 #endif /* NX_DISABLE_PACKET_CHAIN */
1906 }
1907
1908 /* Set the returned data. */
1909 *data = *(*current_data_pptr);
1910
1911 /* Update the data pointer and remaining size. */
1912 (*current_data_pptr)++;
1913 client_ptr -> nx_web_http_client_chunked_response_remaining_size--;
1914
1915 return(NX_SUCCESS);
1916 }
1917
1918 /**************************************************************************/
1919 /* */
1920 /* FUNCTION RELEASE */
1921 /* */
1922 /* _nx_web_http_client_response_byte_expect PORTABLE C */
1923 /* 6.1 */
1924 /* AUTHOR */
1925 /* */
1926 /* Yuxin Zhou, Microsoft Corporation */
1927 /* */
1928 /* DESCRIPTION */
1929 /* */
1930 /* This function checks if next byte is the expected data. */
1931 /* */
1932 /* */
1933 /* INPUT */
1934 /* */
1935 /* client_ptr Pointer to HTTP client */
1936 /* data Expected data */
1937 /* wait_option Suspension option */
1938 /* current_packet_pptr Pointer to the packet being */
1939 /* processed */
1940 /* current_data_ptr Pointer to the data will be */
1941 /* processed */
1942 /* */
1943 /* OUTPUT */
1944 /* */
1945 /* status Compare result */
1946 /* */
1947 /* CALLS */
1948 /* */
1949 /* _nx_web_http_client_response_read Get next data */
1950 /* */
1951 /* CALLED BY */
1952 /* */
1953 /* Application Code */
1954 /* */
1955 /* RELEASE HISTORY */
1956 /* */
1957 /* DATE NAME DESCRIPTION */
1958 /* */
1959 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
1960 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
1961 /* resulting in version 6.1 */
1962 /* */
1963 /**************************************************************************/
_nx_web_http_client_response_byte_expect(NX_WEB_HTTP_CLIENT * client_ptr,UCHAR data,ULONG wait_option,NX_PACKET ** current_packet_pptr,UCHAR ** current_data_pptr)1964 UINT _nx_web_http_client_response_byte_expect(NX_WEB_HTTP_CLIENT *client_ptr, UCHAR data, ULONG wait_option,
1965 NX_PACKET **current_packet_pptr, UCHAR **current_data_pptr)
1966 {
1967 UINT status;
1968 UCHAR tmp;
1969
1970 /* Get next data. */
1971 status = _nx_web_http_client_response_read(client_ptr, &tmp, wait_option, current_packet_pptr, current_data_pptr);
1972
1973 if (status)
1974 {
1975 return(status);
1976 }
1977
1978 /* Return the compare result. */
1979 if (tmp != data)
1980 {
1981 return(NX_NOT_FOUND);
1982 }
1983
1984 return(NX_SUCCESS);
1985 }
1986
1987 /**************************************************************************/
1988 /* */
1989 /* FUNCTION RELEASE */
1990 /* */
1991 /* _nx_web_http_client_chunked_size_get PORTABLE C */
1992 /* 6.1 */
1993 /* AUTHOR */
1994 /* */
1995 /* Yuxin Zhou, Microsoft Corporation */
1996 /* */
1997 /* DESCRIPTION */
1998 /* */
1999 /* This function gets the chunk size of the response packet chunk. */
2000 /* */
2001 /* */
2002 /* INPUT */
2003 /* */
2004 /* client_ptr Pointer to HTTP client */
2005 /* chunk_size Returned chunk size */
2006 /* wait_option Suspension option */
2007 /* current_packet_pptr Pointer to the packet being */
2008 /* processed */
2009 /* current_data_ptr Pointer to the data will be */
2010 /* processed */
2011 /* */
2012 /* OUTPUT */
2013 /* */
2014 /* status Completion status */
2015 /* */
2016 /* CALLS */
2017 /* */
2018 /* _nx_web_http_client_chunked_size_get Get chunk size */
2019 /* _nx_web_http_client_response_byte_expect */
2020 /* Check if next byte is expected*/
2021 /* nx_packet_release Release packet */
2022 /* nx_packet_append Append packet data */
2023 /* */
2024 /* CALLED BY */
2025 /* */
2026 /* Application Code */
2027 /* */
2028 /* RELEASE HISTORY */
2029 /* */
2030 /* DATE NAME DESCRIPTION */
2031 /* */
2032 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
2033 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
2034 /* resulting in version 6.1 */
2035 /* */
2036 /**************************************************************************/
_nx_web_http_client_chunked_size_get(NX_WEB_HTTP_CLIENT * client_ptr,UINT * chunk_size,ULONG wait_option,NX_PACKET ** current_packet_pptr,UCHAR ** current_data_pptr)2037 UINT _nx_web_http_client_chunked_size_get(NX_WEB_HTTP_CLIENT *client_ptr, UINT *chunk_size, ULONG wait_option,
2038 NX_PACKET **current_packet_pptr, UCHAR **current_data_pptr)
2039 {
2040 UINT status;
2041 UINT size = 0;
2042 UCHAR tmp;
2043 UINT chunk_extension = 0;
2044
2045 if (client_ptr -> nx_web_http_client_actual_bytes_received < client_ptr -> nx_web_http_client_total_receive_bytes)
2046 {
2047
2048 /* If there are bytes need to receive, set the size need to receive as chunk size. */
2049 *chunk_size = client_ptr -> nx_web_http_client_total_receive_bytes - client_ptr -> nx_web_http_client_actual_bytes_received;
2050 }
2051 else
2052 {
2053
2054 /* Get the chunk size. */
2055 while (1)
2056 {
2057
2058 /* Read next byte from request packet. */
2059 status = _nx_web_http_client_response_read(client_ptr, &tmp, wait_option, current_packet_pptr, current_data_pptr);
2060 if (status)
2061 {
2062 return(status);
2063 }
2064
2065 /* Skip the chunk extension. */
2066 if (chunk_extension && (tmp != '\r'))
2067 {
2068 continue;
2069 }
2070
2071 /* Calculate the size. */
2072 if ((tmp >= 'a') && (tmp <= 'f'))
2073 {
2074 size = (size << 4) + 10 + (UINT)(tmp - 'a');
2075 }
2076 else if ((tmp >= 'A') && (tmp <= 'F'))
2077 {
2078 size = (size << 4) + 10 + (UINT)(tmp - 'A');
2079 }
2080 else if ((tmp >= '0') && (tmp <= '9'))
2081 {
2082 size = (size << 4) + (UINT)(tmp - '0');
2083 }
2084 else if (tmp == '\r')
2085 {
2086
2087 /* Find the end of chunk header. */
2088 break;
2089 }
2090 else if (tmp == ';')
2091 {
2092
2093 /* Find chunk extension. */
2094 chunk_extension = 1;
2095 }
2096 else
2097 {
2098 return(NX_NOT_FOUND);
2099 }
2100 }
2101
2102 /* Expect '\n'. */
2103 status = _nx_web_http_client_response_byte_expect(client_ptr, '\n', wait_option, current_packet_pptr, current_data_pptr);
2104 if (status)
2105 {
2106 return(status);
2107 }
2108
2109 *chunk_size = size;
2110 }
2111
2112 /* If there is no remaining data, receive another packet. */
2113 while (client_ptr -> nx_web_http_client_chunked_response_remaining_size == 0)
2114 {
2115 if (client_ptr -> nx_web_http_client_response_packet)
2116 {
2117 nx_packet_release(client_ptr -> nx_web_http_client_response_packet);
2118 client_ptr -> nx_web_http_client_response_packet = NX_NULL;
2119 }
2120
2121 status = _nx_web_http_client_receive(client_ptr, &(client_ptr -> nx_web_http_client_response_packet), wait_option);
2122 if (status)
2123 {
2124 return(status);
2125 }
2126
2127 /* Update the current request packet, data pointer and remaining size. */
2128 (*current_packet_pptr) = client_ptr -> nx_web_http_client_response_packet;
2129 (*current_data_pptr) = client_ptr -> nx_web_http_client_response_packet -> nx_packet_prepend_ptr;
2130 client_ptr -> nx_web_http_client_chunked_response_remaining_size = client_ptr -> nx_web_http_client_response_packet -> nx_packet_length;
2131 }
2132
2133 return(NX_SUCCESS);
2134 }
2135
2136 /**************************************************************************/
2137 /* */
2138 /* FUNCTION RELEASE */
2139 /* */
2140 /* _nx_web_http_client_response_chunked_get PORTABLE C */
2141 /* 6.1 */
2142 /* AUTHOR */
2143 /* */
2144 /* Yuxin Zhou, Microsoft Corporation */
2145 /* */
2146 /* DESCRIPTION */
2147 /* */
2148 /* This function gets the chunk data from chunked response. */
2149 /* */
2150 /* */
2151 /* INPUT */
2152 /* */
2153 /* client_ptr Pointer to HTTP client */
2154 /* packet_pptr Pointer to the packet */
2155 /* wait_option Suspension option */
2156 /* */
2157 /* OUTPUT */
2158 /* */
2159 /* status Completion status */
2160 /* */
2161 /* CALLS */
2162 /* */
2163 /* _nx_web_http_client_chunked_size_get Get chunk size */
2164 /* _nx_web_http_client_response_byte_expect */
2165 /* Check if next byte is expected*/
2166 /* nx_packet_allocate Allocate packet */
2167 /* nx_packet_append Append packet data */
2168 /* */
2169 /* CALLED BY */
2170 /* */
2171 /* Application Code */
2172 /* */
2173 /* RELEASE HISTORY */
2174 /* */
2175 /* DATE NAME DESCRIPTION */
2176 /* */
2177 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
2178 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
2179 /* resulting in version 6.1 */
2180 /* */
2181 /**************************************************************************/
_nx_web_http_client_response_chunked_get(NX_WEB_HTTP_CLIENT * client_ptr,NX_PACKET ** packet_pptr,ULONG wait_option)2182 UINT _nx_web_http_client_response_chunked_get(NX_WEB_HTTP_CLIENT *client_ptr, NX_PACKET **packet_pptr, ULONG wait_option)
2183 {
2184 UINT status;
2185 UINT chunk_size = 0, length = 0, temp_size = 0;
2186 UINT remaining_size = 0;
2187 NX_PACKET *packet_ptr;
2188 NX_PACKET *current_packet_ptr = NX_NULL;
2189 UCHAR *current_data_ptr = NX_NULL;
2190
2191 /* Set pointer for processing packet data. */
2192 current_packet_ptr = client_ptr -> nx_web_http_client_response_packet;
2193
2194 if (current_packet_ptr)
2195 {
2196
2197 /* Set current data pointer. */
2198 current_data_ptr = current_packet_ptr -> nx_packet_prepend_ptr;
2199 }
2200
2201 /* Get chunk size. */
2202 status = _nx_web_http_client_chunked_size_get(client_ptr, &chunk_size, wait_option, ¤t_packet_ptr, ¤t_data_ptr);
2203 if (status)
2204 {
2205 return(status);
2206 }
2207
2208 /* Check if it's the end. */
2209 if (chunk_size == 0)
2210 {
2211
2212 /* Read CRLF. */
2213 status = _nx_web_http_client_response_byte_expect(client_ptr, '\r', wait_option, ¤t_packet_ptr, ¤t_data_ptr);
2214 if (status)
2215 {
2216 return(status);
2217 }
2218
2219 status = _nx_web_http_client_response_byte_expect(client_ptr, '\n', wait_option, ¤t_packet_ptr, ¤t_data_ptr);
2220 if (status)
2221 {
2222 return(status);
2223 }
2224
2225 /* Return an empty packet. */
2226 client_ptr -> nx_web_http_client_response_packet -> nx_packet_append_ptr = client_ptr -> nx_web_http_client_response_packet -> nx_packet_prepend_ptr;
2227 client_ptr -> nx_web_http_client_response_packet -> nx_packet_length = 0;
2228 *packet_pptr = client_ptr -> nx_web_http_client_response_packet;
2229
2230 return(NX_WEB_HTTP_GET_DONE);
2231 }
2232
2233 /* Set the return packet. */
2234 *packet_pptr = client_ptr -> nx_web_http_client_response_packet;
2235 client_ptr -> nx_web_http_client_response_packet = NX_NULL;
2236 packet_ptr = *packet_pptr;
2237 packet_ptr -> nx_packet_prepend_ptr = current_data_ptr;
2238 remaining_size = client_ptr -> nx_web_http_client_chunked_response_remaining_size;
2239
2240 /* Process the chunk data. */
2241 if (chunk_size <= remaining_size)
2242 {
2243
2244 /* One or more chunk in the remaining data. */
2245 temp_size = chunk_size;
2246
2247 /* Check if the chunk data is all in this packet. */
2248 while (temp_size > (UINT)(current_packet_ptr -> nx_packet_append_ptr - current_data_ptr))
2249 {
2250
2251 #ifndef NX_DISABLE_PACKET_CHAIN
2252 if (current_packet_ptr -> nx_packet_next == NX_NULL)
2253 {
2254 return(NX_INVALID_PACKET);
2255 }
2256
2257 temp_size -= (UINT)(current_packet_ptr -> nx_packet_append_ptr - current_data_ptr);
2258 current_packet_ptr = current_packet_ptr -> nx_packet_next;
2259 current_data_ptr = current_packet_ptr -> nx_packet_prepend_ptr;
2260 #else
2261 return(NX_INVALID_PACKET);
2262 #endif /* NX_DISABLE_PACKET_CHAIN */
2263 }
2264
2265 /* Skip the chunk data. */
2266 current_data_ptr += temp_size;
2267 client_ptr -> nx_web_http_client_chunked_response_remaining_size -= chunk_size;
2268 length = chunk_size;
2269
2270 /* Read CRLF. */
2271 status = _nx_web_http_client_response_byte_expect(client_ptr, '\r', wait_option, ¤t_packet_ptr, ¤t_data_ptr);
2272 if (status)
2273 {
2274 return(status);
2275 }
2276
2277 status = _nx_web_http_client_response_byte_expect(client_ptr, '\n', wait_option, ¤t_packet_ptr, ¤t_data_ptr);
2278 if (status)
2279 {
2280 return(status);
2281 }
2282
2283 /* Check the remaining data. */
2284 if (client_ptr -> nx_web_http_client_chunked_response_remaining_size)
2285 {
2286 if (client_ptr -> nx_web_http_client_response_packet)
2287 {
2288
2289 /* If received new packet, adjust the prepend pointer of this packet. */
2290 client_ptr -> nx_web_http_client_response_packet -> nx_packet_prepend_ptr = current_data_ptr;
2291 }
2292 else
2293 {
2294
2295 /* Copy the remaining data to a new packet. */
2296 /* Allocate a packet. */
2297 status = nx_packet_allocate(client_ptr -> nx_web_http_client_packet_pool_ptr,
2298 &(client_ptr -> nx_web_http_client_response_packet),
2299 0, wait_option);
2300 if (status)
2301 {
2302 return(status);
2303 }
2304
2305 /* Copy the remaining data in current packet to the new packet. */
2306 temp_size = (UINT)(current_packet_ptr -> nx_packet_append_ptr - current_data_ptr);
2307 status = nx_packet_data_append(client_ptr -> nx_web_http_client_response_packet,
2308 current_data_ptr,
2309 temp_size,
2310 client_ptr -> nx_web_http_client_packet_pool_ptr,
2311 wait_option);
2312 if (status)
2313 {
2314 return(status);
2315 }
2316
2317 /* Check if any remaining data not in current packet. */
2318 if (client_ptr -> nx_web_http_client_chunked_response_remaining_size > temp_size)
2319 {
2320 #ifndef NX_DISABLE_PACKET_CHAIN
2321
2322 /* If there are chained packets, append the packets to the new packet. */
2323 if (current_packet_ptr -> nx_packet_next)
2324 {
2325 client_ptr -> nx_web_http_client_response_packet -> nx_packet_next = current_packet_ptr -> nx_packet_next;
2326 client_ptr -> nx_web_http_client_response_packet -> nx_packet_last = current_packet_ptr -> nx_packet_last;
2327 current_packet_ptr -> nx_packet_next = NX_NULL;
2328 }
2329 else
2330 #endif /* NX_DISABLE_PACKET_CHAIN */
2331 {
2332 return(NX_INVALID_PACKET);
2333 }
2334 }
2335 }
2336
2337 /* Update the packet length. */
2338 client_ptr -> nx_web_http_client_response_packet -> nx_packet_length = client_ptr -> nx_web_http_client_chunked_response_remaining_size;
2339 }
2340 }
2341 else
2342 {
2343
2344 /* All the remaining data is in this chunk. */
2345 client_ptr -> nx_web_http_client_chunked_response_remaining_size = 0;
2346 length = remaining_size;
2347 }
2348
2349 /* Set the received bytes. */
2350 client_ptr -> nx_web_http_client_total_receive_bytes = chunk_size;
2351 client_ptr -> nx_web_http_client_actual_bytes_received = length;
2352
2353 #ifndef NX_DISABLE_PACKET_CHAIN
2354 /* Set length of the packet chain header. */
2355 (*packet_pptr) -> nx_packet_length = length;
2356
2357 /* Find the last packet. */
2358 while (packet_ptr -> nx_packet_next &&
2359 (length > (UINT)(packet_ptr -> nx_packet_append_ptr - packet_ptr -> nx_packet_prepend_ptr)))
2360 {
2361 length -= (UINT)(packet_ptr -> nx_packet_append_ptr - packet_ptr -> nx_packet_prepend_ptr);
2362 packet_ptr = packet_ptr -> nx_packet_next;
2363 }
2364
2365 /* Set the last packet. */
2366 (*packet_pptr) -> nx_packet_last = packet_ptr;
2367
2368 /* Maybe the '\r\n' is in another packet, release this packet. */
2369 if (packet_ptr -> nx_packet_next)
2370 {
2371 nx_packet_release(packet_ptr -> nx_packet_next);
2372 packet_ptr -> nx_packet_next = NX_NULL;
2373 }
2374 #endif /* NX_DISABLE_PACKET_CHAIN */
2375
2376 /* Set packet length and append pointer. */
2377 /* If the packet is chained, set the length and append pointer of the last packet. */
2378 packet_ptr -> nx_packet_length = length;
2379 packet_ptr -> nx_packet_append_ptr = packet_ptr -> nx_packet_prepend_ptr + length;
2380
2381 return(NX_SUCCESS);
2382 }
2383
2384 /**************************************************************************/
2385 /* */
2386 /* FUNCTION RELEASE */
2387 /* */
2388 /* _nxe_web_http_client_request_chunked_set PORTABLE C */
2389 /* 6.1 */
2390 /* AUTHOR */
2391 /* */
2392 /* Yuxin Zhou, Microsoft Corporation */
2393 /* */
2394 /* DESCRIPTION */
2395 /* */
2396 /* This function checks for errors in the HTTP request chunked set */
2397 /* API call. */
2398 /* */
2399 /* */
2400 /* INPUT */
2401 /* */
2402 /* */
2403 /* client_ptr Pointer to HTTP client */
2404 /* chunk_size Size of the chunk */
2405 /* packet_ptr Pointer to the packet */
2406 /* */
2407 /* OUTPUT */
2408 /* */
2409 /* status Completion status */
2410 /* */
2411 /* CALLS */
2412 /* */
2413 /* _nx_web_http_client_request_chunked_set */
2414 /* Actual request chunked set */
2415 /* */
2416 /* CALLED BY */
2417 /* */
2418 /* Application Code */
2419 /* */
2420 /* RELEASE HISTORY */
2421 /* */
2422 /* DATE NAME DESCRIPTION */
2423 /* */
2424 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
2425 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
2426 /* resulting in version 6.1 */
2427 /* */
2428 /**************************************************************************/
_nxe_web_http_client_request_chunked_set(NX_WEB_HTTP_CLIENT * client_ptr,UINT chunk_size,NX_PACKET * packet_ptr)2429 UINT _nxe_web_http_client_request_chunked_set(NX_WEB_HTTP_CLIENT *client_ptr, UINT chunk_size, NX_PACKET *packet_ptr)
2430 {
2431 UINT status;
2432
2433 /* Make sure the client instance makes sense. */
2434 if ((client_ptr == NX_NULL) || (packet_ptr == NX_NULL))
2435 {
2436 return(NX_PTR_ERROR);
2437 }
2438
2439 /* Call actual request chunked set function. */
2440 status = _nx_web_http_client_request_chunked_set(client_ptr, chunk_size, packet_ptr);
2441
2442 /* Return success to the caller. */
2443 return(status);
2444 }
2445
2446
2447 /**************************************************************************/
2448 /* */
2449 /* FUNCTION RELEASE */
2450 /* */
2451 /* _nx_web_http_client_request_chunked_set PORTABLE C */
2452 /* 6.1 */
2453 /* AUTHOR */
2454 /* */
2455 /* Yuxin Zhou, Microsoft Corporation */
2456 /* */
2457 /* DESCRIPTION */
2458 /* */
2459 /* This function sets the chunked information of chunked request. */
2460 /* */
2461 /* */
2462 /* INPUT */
2463 /* */
2464 /* client_ptr Pointer to HTTP client */
2465 /* chunk_size Size of the chunk */
2466 /* packet_ptr Pointer to the packet */
2467 /* */
2468 /* OUTPUT */
2469 /* */
2470 /* status Completion status */
2471 /* */
2472 /* CALLS */
2473 /* */
2474 /* nx_packet_data_append Append the packet data */
2475 /* */
2476 /* CALLED BY */
2477 /* */
2478 /* Application Code */
2479 /* */
2480 /* RELEASE HISTORY */
2481 /* */
2482 /* DATE NAME DESCRIPTION */
2483 /* */
2484 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
2485 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
2486 /* resulting in version 6.1 */
2487 /* */
2488 /**************************************************************************/
_nx_web_http_client_request_chunked_set(NX_WEB_HTTP_CLIENT * client_ptr,UINT chunk_size,NX_PACKET * packet_ptr)2489 UINT _nx_web_http_client_request_chunked_set(NX_WEB_HTTP_CLIENT *client_ptr, UINT chunk_size, NX_PACKET *packet_ptr)
2490 {
2491 UINT status;
2492 UINT temp_size, i, j;
2493 CHAR temp_string[10];
2494 CHAR crlf[2] = {13,10};
2495
2496 /* Covert the size to ASCII. */
2497 temp_size = chunk_size;
2498 i = 0;
2499
2500 while (temp_size)
2501 {
2502
2503 for (j = i; j > 0; j--)
2504 {
2505 temp_string[j] = temp_string[j - 1];
2506 }
2507
2508 if ((temp_size & 0x0F) < 10)
2509 {
2510 temp_string[0] = (CHAR)((temp_size & 0x0F) + '0');
2511 }
2512 else
2513 {
2514 temp_string[0] = (CHAR)((temp_size & 0x0F) - 10 + 'a');
2515 }
2516 temp_size = temp_size >> 4;
2517 i++;
2518 }
2519
2520 if (i == 0)
2521 {
2522 temp_string[i++] = '0';
2523 }
2524
2525 /* Place the chunk size in the packet. */
2526 status = nx_packet_data_append(packet_ptr, temp_string, i, client_ptr -> nx_web_http_client_packet_pool_ptr, NX_WAIT_FOREVER);
2527 if (status)
2528 {
2529 return(status);
2530 }
2531
2532 /* Place the CRLF to signal the end of the chunk size. */
2533 status = nx_packet_data_append(packet_ptr, crlf, 2, client_ptr -> nx_web_http_client_packet_pool_ptr, NX_WAIT_FOREVER);
2534 if (status)
2535 {
2536 return(status);
2537 }
2538
2539 /* Set the request chunked flag. */
2540 client_ptr -> nx_web_http_client_request_chunked = NX_TRUE;
2541
2542 /* The total bytes need to transfer is chunk size plus chunk header length. */
2543 client_ptr -> nx_web_http_client_total_transfer_bytes = chunk_size + i + 2;
2544 client_ptr -> nx_web_http_client_actual_bytes_transferred = 0;
2545
2546 return(NX_SUCCESS);
2547 }
2548
2549 /**************************************************************************/
2550 /* */
2551 /* FUNCTION RELEASE */
2552 /* */
2553 /* _nxe_web_http_client_request_packet_send PORTABLE C */
2554 /* 6.1 */
2555 /* AUTHOR */
2556 /* */
2557 /* Yuxin Zhou, Microsoft Corporation */
2558 /* */
2559 /* DESCRIPTION */
2560 /* */
2561 /* This function checks for errors in the HTTP request packet send */
2562 /* API call. */
2563 /* */
2564 /* */
2565 /* INPUT */
2566 /* */
2567 /* client_ptr Pointer to HTTP client */
2568 /* packet_ptr Pointer to the packet */
2569 /* more_data If there are more data to send*/
2570 /* wait_option Suspension option */
2571 /* */
2572 /* OUTPUT */
2573 /* */
2574 /* status Completion status */
2575 /* */
2576 /* CALLS */
2577 /* */
2578 /* _nx_web_http_client_request_packet_send */
2579 /* Actual request packet send */
2580 /* */
2581 /* CALLED BY */
2582 /* */
2583 /* Application Code */
2584 /* */
2585 /* RELEASE HISTORY */
2586 /* */
2587 /* DATE NAME DESCRIPTION */
2588 /* */
2589 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
2590 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
2591 /* resulting in version 6.1 */
2592 /* */
2593 /**************************************************************************/
_nxe_web_http_client_request_packet_send(NX_WEB_HTTP_CLIENT * client_ptr,NX_PACKET * packet_ptr,UINT more_data,ULONG wait_option)2594 UINT _nxe_web_http_client_request_packet_send(NX_WEB_HTTP_CLIENT *client_ptr, NX_PACKET *packet_ptr, UINT more_data, ULONG wait_option)
2595 {
2596 UINT status;
2597
2598 /* Make sure the client instance makes sense. */
2599 if ((client_ptr == NX_NULL) || (packet_ptr == NX_NULL))
2600 {
2601 return(NX_PTR_ERROR);
2602 }
2603
2604 /* Now send the packet to the HTTP server. */
2605 status = _nx_web_http_client_request_packet_send(client_ptr, packet_ptr, more_data, wait_option);
2606
2607 /* Return success to the caller. */
2608 return(status);
2609 }
2610
2611
2612 /**************************************************************************/
2613 /* */
2614 /* FUNCTION RELEASE */
2615 /* */
2616 /* _nx_web_http_client_request_packet_send PORTABLE C */
2617 /* 6.1.12 */
2618 /* AUTHOR */
2619 /* */
2620 /* Yuxin Zhou, Microsoft Corporation */
2621 /* */
2622 /* DESCRIPTION */
2623 /* */
2624 /* This function sends an HTTP request packet to a remote server. */
2625 /* */
2626 /* */
2627 /* INPUT */
2628 /* */
2629 /* client_ptr Pointer to HTTP client */
2630 /* packet_ptr Pointer to the packet */
2631 /* more_data If there are more data to send*/
2632 /* wait_option Suspension option */
2633 /* */
2634 /* OUTPUT */
2635 /* */
2636 /* status Completion status */
2637 /* */
2638 /* CALLS */
2639 /* */
2640 /* _nx_web_http_client_send Send data to server */
2641 /* _nx_web_http_client_error_exit Cleanup and shut down HTTPS */
2642 /* */
2643 /* CALLED BY */
2644 /* */
2645 /* Application Code */
2646 /* */
2647 /* RELEASE HISTORY */
2648 /* */
2649 /* DATE NAME DESCRIPTION */
2650 /* */
2651 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
2652 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
2653 /* resulting in version 6.1 */
2654 /* 07-29-2022 Yuxin Zhou Modified comment(s), fixed */
2655 /* the invalid release issue, */
2656 /* resulting in version 6.1.12 */
2657 /* */
2658 /**************************************************************************/
_nx_web_http_client_request_packet_send(NX_WEB_HTTP_CLIENT * client_ptr,NX_PACKET * packet_ptr,UINT more_data,ULONG wait_option)2659 UINT _nx_web_http_client_request_packet_send(NX_WEB_HTTP_CLIENT *client_ptr, NX_PACKET *packet_ptr, UINT more_data, ULONG wait_option)
2660 {
2661 UINT status;
2662 CHAR crlf[2] = {13,10};
2663 UINT length = packet_ptr -> nx_packet_length;
2664
2665 /* Check the packet length. */
2666 if (client_ptr -> nx_web_http_client_total_transfer_bytes < (client_ptr -> nx_web_http_client_actual_bytes_transferred + length))
2667 {
2668 return(NX_INVALID_PACKET);
2669 }
2670
2671 /* If the request is chunked, add CRLF at the end of the chunk. */
2672 if (client_ptr -> nx_web_http_client_request_chunked)
2673 {
2674
2675 if (client_ptr -> nx_web_http_client_total_transfer_bytes == (client_ptr -> nx_web_http_client_actual_bytes_transferred + length))
2676 {
2677
2678 /* Place an extra CRLF to signal the end of the chunk. */
2679 nx_packet_data_append(packet_ptr, crlf, 2, client_ptr -> nx_web_http_client_packet_pool_ptr, wait_option);
2680
2681 /* If there are no more data to send, append the last chunk. */
2682 if (!more_data)
2683 {
2684 nx_packet_data_append(packet_ptr, "0\r\n\r\n", 5, client_ptr -> nx_web_http_client_packet_pool_ptr, wait_option);
2685 client_ptr -> nx_web_http_client_request_chunked = NX_FALSE;
2686 }
2687 }
2688 }
2689
2690 /* Now send the packet to the HTTP server. */
2691 status = _nx_web_http_client_send(client_ptr, packet_ptr, wait_option);
2692
2693 /* Determine if the send was successful. */
2694 if (status != NX_SUCCESS)
2695 {
2696
2697 /* No, send was not successful. */
2698
2699 /* Disconnect and unbind the socket. */
2700 _nx_web_http_client_error_exit(client_ptr, wait_option);
2701
2702 /* Return an error. */
2703 return(status);
2704 }
2705
2706 /* Update the transferred bytes. */
2707 client_ptr -> nx_web_http_client_actual_bytes_transferred += length;
2708
2709 return(NX_SUCCESS);
2710 }
2711
2712 /**************************************************************************/
2713 /* */
2714 /* FUNCTION RELEASE */
2715 /* */
2716 /* _nxe_web_http_client_put_start PORTABLE C */
2717 /* 6.1 */
2718 /* AUTHOR */
2719 /* */
2720 /* Yuxin Zhou, Microsoft Corporation */
2721 /* */
2722 /* DESCRIPTION */
2723 /* */
2724 /* This function checks for errors in the HTTP Duo Client put start */
2725 /* call. */
2726 /* */
2727 /* */
2728 /* INPUT */
2729 /* */
2730 /* client_ptr Pointer to HTTP client */
2731 /* server_ip IP duo address of HTTP Server */
2732 /* resource Pointer to resource (URL) */
2733 /* host Pointer to Host */
2734 /* username Pointer to username */
2735 /* password Pointer to password */
2736 /* total_bytes Total bytes to send */
2737 /* wait_option Suspension option */
2738 /* */
2739 /* OUTPUT */
2740 /* */
2741 /* status Completion status */
2742 /* */
2743 /* CALLS */
2744 /* */
2745 /* _nx_web_http_client_put_start Actual client put start call */
2746 /* */
2747 /* CALLED BY */
2748 /* */
2749 /* Application Code */
2750 /* */
2751 /* RELEASE HISTORY */
2752 /* */
2753 /* DATE NAME DESCRIPTION */
2754 /* */
2755 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
2756 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
2757 /* resulting in version 6.1 */
2758 /* */
2759 /**************************************************************************/
_nxe_web_http_client_put_start(NX_WEB_HTTP_CLIENT * client_ptr,NXD_ADDRESS * server_ip,UINT server_port,CHAR * resource,CHAR * host,CHAR * username,CHAR * password,ULONG total_bytes,ULONG wait_option)2760 UINT _nxe_web_http_client_put_start(NX_WEB_HTTP_CLIENT *client_ptr, NXD_ADDRESS *server_ip, UINT server_port, CHAR *resource,
2761 CHAR *host, CHAR *username, CHAR *password, ULONG total_bytes, ULONG wait_option)
2762 {
2763
2764 UINT status;
2765
2766
2767 /* Check for invalid input pointers. */
2768 if ((client_ptr == NX_NULL) || (client_ptr -> nx_web_http_client_id != NX_WEB_HTTP_CLIENT_ID) ||
2769 (resource == NX_NULL) || !server_ip || (host == NX_NULL))
2770 return(NX_PTR_ERROR);
2771
2772 /* Check for invalid total bytes. */
2773 if (total_bytes == 0)
2774 return(NX_SIZE_ERROR);
2775
2776 /* Check for appropriate caller. */
2777 NX_THREADS_ONLY_CALLER_CHECKING
2778
2779 /* Call actual PUT start routine. */
2780 status = _nx_web_http_client_put_start(client_ptr, server_ip, server_port, resource, host,
2781 username, password, total_bytes, wait_option);
2782
2783 /* Return completion status. */
2784 return(status);
2785 }
2786
2787
2788
2789 /**************************************************************************/
2790 /* */
2791 /* FUNCTION RELEASE */
2792 /* */
2793 /* _nx_web_http_client_put_start PORTABLE C */
2794 /* 6.1 */
2795 /* AUTHOR */
2796 /* */
2797 /* Yuxin Zhou, Microsoft Corporation */
2798 /* */
2799 /* DESCRIPTION */
2800 /* */
2801 /* This function processes an application PUT request. Transferring the*/
2802 /* specified resource (URL) is started by this routine. The */
2803 /* application must call put packet one or more times to transfer */
2804 /* the resource contents. */
2805 /* */
2806 /* */
2807 /* INPUT */
2808 /* */
2809 /* client_ptr Pointer to HTTP client */
2810 /* server_ip IP address of HTTP Server */
2811 /* resource Pointer to resource (URL) */
2812 /* host Pointer to Host */
2813 /* username Pointer to username */
2814 /* password Pointer to password */
2815 /* total_bytes Total bytes to send */
2816 /* wait_option Suspension option */
2817 /* */
2818 /* OUTPUT */
2819 /* */
2820 /* status Completion status */
2821 /* */
2822 /* CALLS */
2823 /* */
2824 /* _nx_web_http_client_put_start_extended */
2825 /* Actual client put start call */
2826 /* _nx_utility_string_length_check Check string length */
2827 /* */
2828 /* CALLED BY */
2829 /* */
2830 /* Application Code */
2831 /* */
2832 /* RELEASE HISTORY */
2833 /* */
2834 /* DATE NAME DESCRIPTION */
2835 /* */
2836 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
2837 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
2838 /* resulting in version 6.1 */
2839 /* */
2840 /**************************************************************************/
_nx_web_http_client_put_start(NX_WEB_HTTP_CLIENT * client_ptr,NXD_ADDRESS * server_ip,UINT server_port,CHAR * resource,CHAR * host,CHAR * username,CHAR * password,ULONG total_bytes,ULONG wait_option)2841 UINT _nx_web_http_client_put_start(NX_WEB_HTTP_CLIENT *client_ptr, NXD_ADDRESS *server_ip, UINT server_port, CHAR *resource,
2842 CHAR *host, CHAR *username, CHAR *password, ULONG total_bytes, ULONG wait_option)
2843 {
2844 UINT temp_resource_length;
2845 UINT temp_host_length;
2846 UINT temp_username_length = 0;
2847 UINT temp_password_length = 0;
2848
2849 if ((username) && (password))
2850 {
2851
2852 /* Check username and password length. */
2853 if (_nx_utility_string_length_check(username, &temp_username_length, NX_WEB_HTTP_MAX_NAME) ||
2854 _nx_utility_string_length_check(password, &temp_password_length, NX_WEB_HTTP_MAX_PASSWORD))
2855 {
2856 return(NX_WEB_HTTP_ERROR);
2857 }
2858 }
2859
2860 /* Check resource and host length. */
2861 if (_nx_utility_string_length_check(resource, &temp_resource_length, NX_MAX_STRING_LENGTH) ||
2862 _nx_utility_string_length_check(host, &temp_host_length, NX_MAX_STRING_LENGTH))
2863 {
2864 return(NX_WEB_HTTP_ERROR);
2865 }
2866
2867 return(_nx_web_http_client_put_start_extended(client_ptr, server_ip, server_port, resource,
2868 temp_resource_length, host, temp_host_length, username,
2869 temp_username_length, password, temp_password_length,
2870 total_bytes, wait_option));
2871 }
2872
2873 /**************************************************************************/
2874 /* */
2875 /* FUNCTION RELEASE */
2876 /* */
2877 /* _nxe_web_http_client_put_start_extended PORTABLE C */
2878 /* 6.1 */
2879 /* AUTHOR */
2880 /* */
2881 /* Yuxin Zhou, Microsoft Corporation */
2882 /* */
2883 /* DESCRIPTION */
2884 /* */
2885 /* This function checks for errors in the HTTP Duo Client put start */
2886 /* call. */
2887 /* */
2888 /* */
2889 /* INPUT */
2890 /* */
2891 /* client_ptr Pointer to HTTP client */
2892 /* server_ip IP duo address of HTTP Server */
2893 /* resource Pointer to resource (URL) */
2894 /* resource_length String length of resource */
2895 /* host Pointer to Host */
2896 /* host_length Length of host */
2897 /* username Pointer to username */
2898 /* username_length Length of username */
2899 /* password Pointer to password */
2900 /* password_length Length of password */
2901 /* total_bytes Total bytes to send */
2902 /* wait_option Suspension option */
2903 /* */
2904 /* OUTPUT */
2905 /* */
2906 /* status Completion status */
2907 /* */
2908 /* CALLS */
2909 /* */
2910 /* _nx_web_http_client_put_start_extended */
2911 /* Actual client put start call */
2912 /* */
2913 /* CALLED BY */
2914 /* */
2915 /* Application Code */
2916 /* */
2917 /* RELEASE HISTORY */
2918 /* */
2919 /* DATE NAME DESCRIPTION */
2920 /* */
2921 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
2922 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
2923 /* resulting in version 6.1 */
2924 /* */
2925 /**************************************************************************/
_nxe_web_http_client_put_start_extended(NX_WEB_HTTP_CLIENT * client_ptr,NXD_ADDRESS * server_ip,UINT server_port,CHAR * resource,UINT resource_length,CHAR * host,UINT host_length,CHAR * username,UINT username_length,CHAR * password,UINT password_length,ULONG total_bytes,ULONG wait_option)2926 UINT _nxe_web_http_client_put_start_extended(NX_WEB_HTTP_CLIENT *client_ptr, NXD_ADDRESS *server_ip,
2927 UINT server_port, CHAR *resource, UINT resource_length,
2928 CHAR *host, UINT host_length, CHAR *username,
2929 UINT username_length, CHAR *password,
2930 UINT password_length, ULONG total_bytes,
2931 ULONG wait_option)
2932 {
2933
2934 UINT status;
2935
2936
2937 /* Check for invalid input pointers. */
2938 if ((client_ptr == NX_NULL) || (client_ptr -> nx_web_http_client_id != NX_WEB_HTTP_CLIENT_ID) ||
2939 (resource == NX_NULL) || !server_ip || (host == NX_NULL))
2940 return(NX_PTR_ERROR);
2941
2942 /* Check for invalid total bytes. */
2943 if (total_bytes == 0)
2944 return(NX_SIZE_ERROR);
2945
2946 /* Check for appropriate caller. */
2947 NX_THREADS_ONLY_CALLER_CHECKING
2948
2949 /* Call actual PUT start routine. */
2950 status = _nx_web_http_client_put_start_extended(client_ptr, server_ip, server_port, resource,
2951 resource_length, host, host_length, username,
2952 username_length, password, password_length,
2953 total_bytes, wait_option);
2954
2955 /* Return completion status. */
2956 return(status);
2957 }
2958
2959
2960
2961 /**************************************************************************/
2962 /* */
2963 /* FUNCTION RELEASE */
2964 /* */
2965 /* _nx_web_http_client_put_start_extended PORTABLE C */
2966 /* 6.1 */
2967 /* AUTHOR */
2968 /* */
2969 /* Yuxin Zhou, Microsoft Corporation */
2970 /* */
2971 /* DESCRIPTION */
2972 /* */
2973 /* This function processes an application PUT request. Transferring the*/
2974 /* specified resource (URL) is started by this routine. The */
2975 /* application must call put packet one or more times to transfer */
2976 /* the resource contents. */
2977 /* */
2978 /* Note: The strings of resource, host, username and password must be */
2979 /* NULL-terminated and length of each string matches the length */
2980 /* specified in the argument list. */
2981 /* */
2982 /* */
2983 /* INPUT */
2984 /* */
2985 /* client_ptr Pointer to HTTP client */
2986 /* server_ip IP duo address of HTTP Server */
2987 /* resource Pointer to resource (URL) */
2988 /* resource_length String length of resource */
2989 /* host Pointer to Host */
2990 /* host_length Length of host */
2991 /* username Pointer to username */
2992 /* username_length Length of username */
2993 /* password Pointer to password */
2994 /* password_length Length of password */
2995 /* total_bytes Total bytes to send */
2996 /* wait_option Suspension option */
2997 /* */
2998 /* OUTPUT */
2999 /* */
3000 /* status Completion status */
3001 /* */
3002 /* CALLS */
3003 /* */
3004 /* _nx_web_http_client_connect Connect to remote server */
3005 /* _nx_web_http_client_request_initialize_extended */
3006 /* Initialize PUT request */
3007 /* _nx_web_http_client_content_type_header_add */
3008 /* Add content type header */
3009 /* _nx_web_http_client_request_send Send HTTP request to server */
3010 /* _nx_web_http_client_error_exit Shutdown HTTP(S) connection */
3011 /* */
3012 /* CALLED BY */
3013 /* */
3014 /* Application Code */
3015 /* */
3016 /* RELEASE HISTORY */
3017 /* */
3018 /* DATE NAME DESCRIPTION */
3019 /* */
3020 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
3021 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
3022 /* resulting in version 6.1 */
3023 /* */
3024 /**************************************************************************/
_nx_web_http_client_put_start_extended(NX_WEB_HTTP_CLIENT * client_ptr,NXD_ADDRESS * server_ip,UINT server_port,CHAR * resource,UINT resource_length,CHAR * host,UINT host_length,CHAR * username,UINT username_length,CHAR * password,UINT password_length,ULONG total_bytes,ULONG wait_option)3025 UINT _nx_web_http_client_put_start_extended(NX_WEB_HTTP_CLIENT *client_ptr, NXD_ADDRESS *server_ip,
3026 UINT server_port, CHAR *resource, UINT resource_length,
3027 CHAR *host, UINT host_length, CHAR *username,
3028 UINT username_length, CHAR *password,
3029 UINT password_length, ULONG total_bytes,
3030 ULONG wait_option)
3031 {
3032 UINT status;
3033
3034 /* Set the port we are connecting to. */
3035 client_ptr->nx_web_http_client_connect_port = server_port;
3036
3037 /* Connect to the server. */
3038 status = _nx_web_http_client_connect(client_ptr, server_ip, client_ptr->nx_web_http_client_connect_port, wait_option);
3039
3040 /* Check status. */
3041 if (status != NX_SUCCESS)
3042 {
3043 return(status);
3044 }
3045
3046 /* Initialize HTTP request. */
3047 status = _nx_web_http_client_request_initialize_extended(client_ptr,
3048 NX_WEB_HTTP_METHOD_PUT,
3049 resource,
3050 resource_length,
3051 host,
3052 host_length,
3053 total_bytes,
3054 NX_FALSE, /* If true, input_size is ignored. */
3055 username,
3056 username_length,
3057 password,
3058 password_length,
3059 wait_option);
3060
3061 /* Add approproate headers from input data. */
3062 _nx_web_http_client_content_type_header_add(client_ptr, resource, wait_option);
3063
3064 /* Check status. */
3065 if (status != NX_SUCCESS)
3066 {
3067 return(status);
3068 }
3069
3070 /* Send the HTTP request we just built. */
3071 status = _nx_web_http_client_request_send(client_ptr, wait_option);
3072
3073 /* Determine if the send was successful. */
3074 if (status != NX_SUCCESS)
3075 {
3076
3077 /* No, send was not successful. */
3078
3079 /* Disconnect and unbind the socket. */
3080 _nx_web_http_client_error_exit(client_ptr, wait_option);
3081
3082 /* Return an error. */
3083 return(status);
3084 }
3085
3086
3087 /* Store the total number of bytes to send. */
3088 client_ptr -> nx_web_http_client_total_transfer_bytes = total_bytes;
3089 client_ptr -> nx_web_http_client_actual_bytes_transferred = 0;
3090
3091 /* Enter the PUT state. */
3092 client_ptr -> nx_web_http_client_state = NX_WEB_HTTP_CLIENT_STATE_PUT;
3093
3094
3095 return(status);
3096 }
3097
3098
3099 #ifdef NX_WEB_HTTPS_ENABLE
3100 /**************************************************************************/
3101 /* */
3102 /* FUNCTION RELEASE */
3103 /* */
3104 /* _nxe_web_http_client_put_secure_start PORTABLE C */
3105 /* 6.1 */
3106 /* AUTHOR */
3107 /* */
3108 /* Yuxin Zhou, Microsoft Corporation */
3109 /* */
3110 /* DESCRIPTION */
3111 /* */
3112 /* This function checks for errors in the HTTPS secure PUT request */
3113 /* processing call. */
3114 /* */
3115 /* */
3116 /* INPUT */
3117 /* */
3118 /* client_ptr Pointer to HTTP client */
3119 /* server_ip HTTP Server IP address */
3120 /* server_port HTTP Server TCP port */
3121 /* resource Pointer to resource (URL) */
3122 /* host Pointer to Host */
3123 /* username Pointer to username */
3124 /* password Pointer to password */
3125 /* total_bytes Total number of bytes to PUT */
3126 /* tls_setup TLS setup callback function */
3127 /* wait_option Suspension option */
3128 /* */
3129 /* OUTPUT */
3130 /* */
3131 /* status Completion status */
3132 /* */
3133 /* CALLS */
3134 /* */
3135 /* _nxe_web_http_client_put_secure_start Actual PUT request processing */
3136 /* */
3137 /* CALLED BY */
3138 /* */
3139 /* Application Code */
3140 /* */
3141 /* RELEASE HISTORY */
3142 /* */
3143 /* DATE NAME DESCRIPTION */
3144 /* */
3145 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
3146 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
3147 /* resulting in version 6.1 */
3148 /* */
3149 /**************************************************************************/
_nxe_web_http_client_put_secure_start(NX_WEB_HTTP_CLIENT * client_ptr,NXD_ADDRESS * server_ip,UINT server_port,CHAR * resource,CHAR * host,CHAR * username,CHAR * password,ULONG total_bytes,UINT (* tls_setup)(NX_WEB_HTTP_CLIENT * client_ptr,NX_SECURE_TLS_SESSION *),ULONG wait_option)3150 UINT _nxe_web_http_client_put_secure_start(NX_WEB_HTTP_CLIENT *client_ptr, NXD_ADDRESS *server_ip, UINT server_port, CHAR *resource,
3151 CHAR *host, CHAR *username, CHAR *password, ULONG total_bytes,
3152 UINT (*tls_setup)(NX_WEB_HTTP_CLIENT *client_ptr, NX_SECURE_TLS_SESSION *),
3153 ULONG wait_option)
3154 {
3155 UINT status;
3156
3157 /* Check for invalid input pointers. */
3158 if ((client_ptr == NX_NULL) || (client_ptr -> nx_web_http_client_id != NX_WEB_HTTP_CLIENT_ID) ||
3159 (resource == NX_NULL) || !server_ip || !tls_setup || (host == NX_NULL))
3160 return(NX_PTR_ERROR);
3161
3162 /* Check for appropriate caller. */
3163 NX_THREADS_ONLY_CALLER_CHECKING
3164
3165 /* Call actual PUT start routine. */
3166 status = _nx_web_http_client_put_secure_start(client_ptr, server_ip, server_port, resource,
3167 host, username, password,
3168 total_bytes, tls_setup, wait_option);
3169
3170 /* Return completion status. */
3171 return(status);
3172 }
3173
3174
3175 /**************************************************************************/
3176 /* */
3177 /* FUNCTION RELEASE */
3178 /* */
3179 /* _nx_web_http_client_put_secure_start PORTABLE C */
3180 /* 6.1 */
3181 /* AUTHOR */
3182 /* */
3183 /* Yuxin Zhou, Microsoft Corporation */
3184 /* */
3185 /* DESCRIPTION */
3186 /* */
3187 /* This function processes an application PUT request. Transferring the*/
3188 /* specified resource (URL) is started by this routine. The */
3189 /* application must call put packet one or more times to transfer */
3190 /* the resource contents. This version of the function also requires */
3191 /* a TLS setup callback as the data is sent over TLS-secured HTTPS. */
3192 /* */
3193 /* */
3194 /* INPUT */
3195 /* */
3196 /* client_ptr Pointer to HTTP client */
3197 /* server_ip HTTP Server IP address */
3198 /* server_port HTTP Server TCP port */
3199 /* resource Pointer to resource (URL) */
3200 /* host Pointer to Host */
3201 /* username Pointer to username */
3202 /* password Pointer to password */
3203 /* total_bytes Total number of bytes to PUT */
3204 /* tls_setup TLS setup callback function */
3205 /* wait_option Suspension option */
3206 /* */
3207 /* OUTPUT */
3208 /* */
3209 /* status Completion status */
3210 /* */
3211 /* CALLS */
3212 /* */
3213 /* _nx_web_http_client_put_secure_start_extended */
3214 /* Actual PUT request processing */
3215 /* _nx_utility_string_length_check Check string length */
3216 /* */
3217 /* CALLED BY */
3218 /* */
3219 /* Application Code */
3220 /* */
3221 /* RELEASE HISTORY */
3222 /* */
3223 /* DATE NAME DESCRIPTION */
3224 /* */
3225 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
3226 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
3227 /* resulting in version 6.1 */
3228 /* */
3229 /**************************************************************************/
_nx_web_http_client_put_secure_start(NX_WEB_HTTP_CLIENT * client_ptr,NXD_ADDRESS * server_ip,UINT server_port,CHAR * resource,CHAR * host,CHAR * username,CHAR * password,ULONG total_bytes,UINT (* tls_setup)(NX_WEB_HTTP_CLIENT * client_ptr,NX_SECURE_TLS_SESSION *),ULONG wait_option)3230 UINT _nx_web_http_client_put_secure_start(NX_WEB_HTTP_CLIENT *client_ptr, NXD_ADDRESS *server_ip, UINT server_port, CHAR *resource,
3231 CHAR *host, CHAR *username, CHAR *password, ULONG total_bytes,
3232 UINT (*tls_setup)(NX_WEB_HTTP_CLIENT *client_ptr, NX_SECURE_TLS_SESSION *),
3233 ULONG wait_option)
3234 {
3235 UINT temp_resource_length;
3236 UINT temp_host_length;
3237 UINT temp_username_length = 0;
3238 UINT temp_password_length = 0;
3239
3240 if ((username) && (password))
3241 {
3242
3243 /* Check username and password length. */
3244 if (_nx_utility_string_length_check(username, &temp_username_length, NX_WEB_HTTP_MAX_NAME) ||
3245 _nx_utility_string_length_check(password, &temp_password_length, NX_WEB_HTTP_MAX_PASSWORD))
3246 {
3247 return(NX_WEB_HTTP_ERROR);
3248 }
3249 }
3250
3251 /* Check resource and host length. */
3252 if (_nx_utility_string_length_check(resource, &temp_resource_length, NX_MAX_STRING_LENGTH) ||
3253 _nx_utility_string_length_check(host, &temp_host_length, NX_MAX_STRING_LENGTH))
3254 {
3255 return(NX_WEB_HTTP_ERROR);
3256 }
3257
3258 return(_nx_web_http_client_put_secure_start_extended(client_ptr, server_ip, server_port,
3259 resource, temp_resource_length, host,
3260 temp_host_length, username,
3261 temp_username_length, password,
3262 temp_password_length, total_bytes,
3263 tls_setup, wait_option));
3264 }
3265
3266
3267 /**************************************************************************/
3268 /* */
3269 /* FUNCTION RELEASE */
3270 /* */
3271 /* _nxe_web_http_client_put_secure_start_extended PORTABLE C */
3272 /* 6.1 */
3273 /* AUTHOR */
3274 /* */
3275 /* Yuxin Zhou, Microsoft Corporation */
3276 /* */
3277 /* DESCRIPTION */
3278 /* */
3279 /* This function checks for errors in the HTTPS secure PUT request */
3280 /* processing call. */
3281 /* */
3282 /* */
3283 /* INPUT */
3284 /* */
3285 /* client_ptr Pointer to HTTP client */
3286 /* server_ip IP duo address of HTTP Server */
3287 /* resource Pointer to resource (URL) */
3288 /* resource_length String length of resource */
3289 /* host Pointer to Host */
3290 /* host_length Length of host */
3291 /* username Pointer to username */
3292 /* username_length Length of username */
3293 /* password Pointer to password */
3294 /* password_length Length of password */
3295 /* total_bytes Total number of bytes to PUT */
3296 /* tls_setup TLS setup callback function */
3297 /* wait_option Suspension option */
3298 /* */
3299 /* OUTPUT */
3300 /* */
3301 /* status Completion status */
3302 /* */
3303 /* CALLS */
3304 /* */
3305 /* _nx_web_http_client_put_secure_start_extended */
3306 /* Actual PUT request processing */
3307 /* */
3308 /* CALLED BY */
3309 /* */
3310 /* Application Code */
3311 /* */
3312 /* RELEASE HISTORY */
3313 /* */
3314 /* DATE NAME DESCRIPTION */
3315 /* */
3316 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
3317 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
3318 /* resulting in version 6.1 */
3319 /* */
3320 /**************************************************************************/
_nxe_web_http_client_put_secure_start_extended(NX_WEB_HTTP_CLIENT * client_ptr,NXD_ADDRESS * server_ip,UINT server_port,CHAR * resource,UINT resource_length,CHAR * host,UINT host_length,CHAR * username,UINT username_length,CHAR * password,UINT password_length,ULONG total_bytes,UINT (* tls_setup)(NX_WEB_HTTP_CLIENT * client_ptr,NX_SECURE_TLS_SESSION *),ULONG wait_option)3321 UINT _nxe_web_http_client_put_secure_start_extended(NX_WEB_HTTP_CLIENT *client_ptr, NXD_ADDRESS *server_ip, UINT server_port,
3322 CHAR *resource, UINT resource_length, CHAR *host, UINT host_length,
3323 CHAR *username, UINT username_length, CHAR *password,
3324 UINT password_length, ULONG total_bytes,
3325 UINT (*tls_setup)(NX_WEB_HTTP_CLIENT *client_ptr, NX_SECURE_TLS_SESSION *),
3326 ULONG wait_option)
3327 {
3328 UINT status;
3329
3330 /* Check for invalid input pointers. */
3331 if ((client_ptr == NX_NULL) || (client_ptr -> nx_web_http_client_id != NX_WEB_HTTP_CLIENT_ID) ||
3332 (resource == NX_NULL) || !server_ip || !tls_setup || (host == NX_NULL))
3333 return(NX_PTR_ERROR);
3334
3335 /* Check for appropriate caller. */
3336 NX_THREADS_ONLY_CALLER_CHECKING
3337
3338 /* Call actual PUT start routine. */
3339 status = _nx_web_http_client_put_secure_start_extended(client_ptr, server_ip, server_port,
3340 resource, resource_length, host,
3341 host_length, username, username_length,
3342 password, password_length, total_bytes,
3343 tls_setup, wait_option);
3344
3345 /* Return completion status. */
3346 return(status);
3347 }
3348
3349
3350 /**************************************************************************/
3351 /* */
3352 /* FUNCTION RELEASE */
3353 /* */
3354 /* _nx_web_http_client_put_secure_start_extended PORTABLE C */
3355 /* 6.1 */
3356 /* AUTHOR */
3357 /* */
3358 /* Yuxin Zhou, Microsoft Corporation */
3359 /* */
3360 /* DESCRIPTION */
3361 /* */
3362 /* This function processes an application PUT request. Transferring the*/
3363 /* specified resource (URL) is started by this routine. The */
3364 /* application must call put packet one or more times to transfer */
3365 /* the resource contents. This version of the function also requires */
3366 /* a TLS setup callback as the data is sent over TLS-secured HTTPS. */
3367 /* */
3368 /* Note: The strings of resource, host, username and password must be */
3369 /* NULL-terminated and length of each string matches the length */
3370 /* specified in the argument list. */
3371 /* */
3372 /* */
3373 /* INPUT */
3374 /* */
3375 /* client_ptr Pointer to HTTP client */
3376 /* server_ip IP duo address of HTTP Server */
3377 /* resource Pointer to resource (URL) */
3378 /* resource_length String length of resource */
3379 /* host Pointer to Host */
3380 /* host_length Length of host */
3381 /* username Pointer to username */
3382 /* username_length Length of username */
3383 /* password Pointer to password */
3384 /* password_length Length of password */
3385 /* total_bytes Total number of bytes to PUT */
3386 /* tls_setup TLS setup callback function */
3387 /* wait_option Suspension option */
3388 /* */
3389 /* OUTPUT */
3390 /* */
3391 /* status Completion status */
3392 /* */
3393 /* CALLS */
3394 /* */
3395 /* _nx_web_http_client_secure_connect Connect to HTTPS server */
3396 /* _nx_web_http_client_request_initialize_extended */
3397 /* Initialize HTTP request */
3398 /* _nx_web_http_client_content_type_header_add */
3399 /* Add content type header */
3400 /* */
3401 /* _nx_web_http_client_request_send Send HTTP request to server */
3402 /* _nx_web_http_client_error_exit Shutdown HTTPS session */
3403 /* */
3404 /* CALLED BY */
3405 /* */
3406 /* Application Code */
3407 /* */
3408 /* RELEASE HISTORY */
3409 /* */
3410 /* DATE NAME DESCRIPTION */
3411 /* */
3412 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
3413 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
3414 /* resulting in version 6.1 */
3415 /* */
3416 /**************************************************************************/
_nx_web_http_client_put_secure_start_extended(NX_WEB_HTTP_CLIENT * client_ptr,NXD_ADDRESS * server_ip,UINT server_port,CHAR * resource,UINT resource_length,CHAR * host,UINT host_length,CHAR * username,UINT username_length,CHAR * password,UINT password_length,ULONG total_bytes,UINT (* tls_setup)(NX_WEB_HTTP_CLIENT * client_ptr,NX_SECURE_TLS_SESSION *),ULONG wait_option)3417 UINT _nx_web_http_client_put_secure_start_extended(NX_WEB_HTTP_CLIENT *client_ptr, NXD_ADDRESS *server_ip, UINT server_port,
3418 CHAR *resource, UINT resource_length, CHAR *host, UINT host_length,
3419 CHAR *username, UINT username_length, CHAR *password,
3420 UINT password_length, ULONG total_bytes,
3421 UINT (*tls_setup)(NX_WEB_HTTP_CLIENT *client_ptr, NX_SECURE_TLS_SESSION *),
3422 ULONG wait_option)
3423 {
3424 UINT status;
3425
3426
3427 /* Use default HTTPS port. */
3428 client_ptr->nx_web_http_client_connect_port = server_port;
3429
3430 /* Connect to the server. */
3431 status = _nx_web_http_client_secure_connect(client_ptr, server_ip, client_ptr->nx_web_http_client_connect_port, tls_setup, wait_option);
3432
3433 /* Check status. */
3434 if (status != NX_SUCCESS)
3435 {
3436 return(status);
3437 }
3438
3439 /* Initialize HTTP request. */
3440 status = _nx_web_http_client_request_initialize_extended(client_ptr,
3441 NX_WEB_HTTP_METHOD_PUT,
3442 resource,
3443 resource_length,
3444 host,
3445 host_length,
3446 total_bytes,
3447 NX_FALSE, /* If true, input_size is ignored. */
3448 username,
3449 username_length,
3450 password,
3451 password_length,
3452 wait_option);
3453
3454 /* Add approproate headers from input data. */
3455 _nx_web_http_client_content_type_header_add(client_ptr, resource, wait_option);
3456
3457 /* Check status. */
3458 if (status != NX_SUCCESS)
3459 {
3460 return(status);
3461 }
3462
3463 /* Send the HTTP request we just built. */
3464 status = _nx_web_http_client_request_send(client_ptr, wait_option);
3465
3466 /* Determine if the send was successful. */
3467 if (status != NX_SUCCESS)
3468 {
3469
3470 /* No, send was not successful. */
3471
3472 /* Disconnect and unbind the socket. */
3473 _nx_web_http_client_error_exit(client_ptr, wait_option);
3474
3475 /* Return an error. */
3476 return(status);
3477 }
3478
3479
3480 /* Store the total number of bytes to send. */
3481 client_ptr -> nx_web_http_client_total_transfer_bytes = total_bytes;
3482 client_ptr -> nx_web_http_client_actual_bytes_transferred = 0;
3483
3484 /* Enter the PUT state. */
3485 client_ptr -> nx_web_http_client_state = NX_WEB_HTTP_CLIENT_STATE_PUT;
3486
3487 return(status);
3488 }
3489
3490 #endif /* NX_WEB_HTTPS_ENABLE */
3491
3492
3493 /**************************************************************************/
3494 /* */
3495 /* FUNCTION RELEASE */
3496 /* */
3497 /* _nxe_web_http_client_post_start PORTABLE C */
3498 /* 6.1 */
3499 /* AUTHOR */
3500 /* */
3501 /* Yuxin Zhou, Microsoft Corporation */
3502 /* */
3503 /* DESCRIPTION */
3504 /* */
3505 /* This function checks for errors in the HTTP Client POST start */
3506 /* call. */
3507 /* */
3508 /* */
3509 /* INPUT */
3510 /* */
3511 /* client_ptr Pointer to HTTP client */
3512 /* server_ip HTTP Server IP address */
3513 /* server_port HTTP Server TCP port */
3514 /* resource Pointer to resource (URL) */
3515 /* host Pointer to Host */
3516 /* username Pointer to username */
3517 /* password Pointer to password */
3518 /* total_bytes Total number of bytes to POST */
3519 /* wait_option Suspension option */
3520 /* */
3521 /* OUTPUT */
3522 /* */
3523 /* status Completion status */
3524 /* */
3525 /* CALLS */
3526 /* */
3527 /* _nx_web_http_client_post_start Actual client post start call */
3528 /* */
3529 /* CALLED BY */
3530 /* */
3531 /* Application Code */
3532 /* */
3533 /* RELEASE HISTORY */
3534 /* */
3535 /* DATE NAME DESCRIPTION */
3536 /* */
3537 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
3538 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
3539 /* resulting in version 6.1 */
3540 /* */
3541 /**************************************************************************/
_nxe_web_http_client_post_start(NX_WEB_HTTP_CLIENT * client_ptr,NXD_ADDRESS * server_ip,UINT server_port,CHAR * resource,CHAR * host,CHAR * username,CHAR * password,ULONG total_bytes,ULONG wait_option)3542 UINT _nxe_web_http_client_post_start(NX_WEB_HTTP_CLIENT *client_ptr, NXD_ADDRESS *server_ip, UINT server_port, CHAR *resource,
3543 CHAR *host, CHAR *username, CHAR *password, ULONG total_bytes, ULONG wait_option)
3544 {
3545
3546 UINT status;
3547
3548
3549 /* Check for invalid input pointers. */
3550 if ((client_ptr == NX_NULL) || (client_ptr -> nx_web_http_client_id != NX_WEB_HTTP_CLIENT_ID) ||
3551 (resource == NX_NULL) || !server_ip || (host == NX_NULL))
3552 return(NX_PTR_ERROR);
3553
3554 /* Check for invalid total bytes. */
3555 if (total_bytes == 0)
3556 return(NX_SIZE_ERROR);
3557
3558 /* Check for appropriate caller. */
3559 NX_THREADS_ONLY_CALLER_CHECKING
3560
3561 /* Call actual PUT start routine. */
3562 status = _nx_web_http_client_post_start(client_ptr, server_ip, server_port, resource, host,
3563 username, password, total_bytes, wait_option);
3564
3565 /* Return completion status. */
3566 return(status);
3567 }
3568
3569
3570
3571 /**************************************************************************/
3572 /* */
3573 /* FUNCTION RELEASE */
3574 /* */
3575 /* _nx_web_http_client_post_start PORTABLE C */
3576 /* 6.1 */
3577 /* AUTHOR */
3578 /* */
3579 /* Yuxin Zhou, Microsoft Corporation */
3580 /* */
3581 /* DESCRIPTION */
3582 /* */
3583 /* This function processes an application POST request. Transferring */
3584 /* the specified resource (URL) is started by this routine. The */
3585 /* application must call put packet one or more times to transfer */
3586 /* the resource contents. */
3587 /* */
3588 /* */
3589 /* INPUT */
3590 /* */
3591 /* client_ptr Pointer to HTTP client */
3592 /* server_ip IP address of HTTP Server */
3593 /* resource Pointer to resource (URL) */
3594 /* host Pointer to Host */
3595 /* username Pointer to username */
3596 /* password Pointer to password */
3597 /* total_bytes Total number of bytes to POST */
3598 /* wait_option Suspension option */
3599 /* */
3600 /* OUTPUT */
3601 /* */
3602 /* status Completion status */
3603 /* */
3604 /* CALLS */
3605 /* */
3606 /* _nx_web_http_client_post_start_extended */
3607 /* Actual client put start call */
3608 /* _nx_utility_string_length_check Check string length */
3609 /* */
3610 /* CALLED BY */
3611 /* */
3612 /* Application Code */
3613 /* */
3614 /* RELEASE HISTORY */
3615 /* */
3616 /* DATE NAME DESCRIPTION */
3617 /* */
3618 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
3619 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
3620 /* resulting in version 6.1 */
3621 /* */
3622 /**************************************************************************/
_nx_web_http_client_post_start(NX_WEB_HTTP_CLIENT * client_ptr,NXD_ADDRESS * server_ip,UINT server_port,CHAR * resource,CHAR * host,CHAR * username,CHAR * password,ULONG total_bytes,ULONG wait_option)3623 UINT _nx_web_http_client_post_start(NX_WEB_HTTP_CLIENT *client_ptr, NXD_ADDRESS *server_ip, UINT server_port, CHAR *resource,
3624 CHAR *host, CHAR *username, CHAR *password, ULONG total_bytes, ULONG wait_option)
3625 {
3626 UINT temp_resource_length;
3627 UINT temp_host_length;
3628 UINT temp_username_length = 0;
3629 UINT temp_password_length = 0;
3630
3631 if ((username) && (password))
3632 {
3633
3634 /* Check username and password length. */
3635 if (_nx_utility_string_length_check(username, &temp_username_length, NX_WEB_HTTP_MAX_NAME) ||
3636 _nx_utility_string_length_check(password, &temp_password_length, NX_WEB_HTTP_MAX_PASSWORD))
3637 {
3638 return(NX_WEB_HTTP_ERROR);
3639 }
3640 }
3641
3642 /* Check resource and host length. */
3643 if (_nx_utility_string_length_check(resource, &temp_resource_length, NX_MAX_STRING_LENGTH) ||
3644 _nx_utility_string_length_check(host, &temp_host_length, NX_MAX_STRING_LENGTH))
3645 {
3646 return(NX_WEB_HTTP_ERROR);
3647 }
3648
3649 return(_nx_web_http_client_post_start_extended(client_ptr, server_ip, server_port, resource,
3650 temp_resource_length, host, temp_host_length, username,
3651 temp_username_length, password, temp_password_length,
3652 total_bytes, wait_option));
3653 }
3654
3655 /**************************************************************************/
3656 /* */
3657 /* FUNCTION RELEASE */
3658 /* */
3659 /* _nxe_web_http_client_post_start_extended PORTABLE C */
3660 /* 6.1 */
3661 /* AUTHOR */
3662 /* */
3663 /* Yuxin Zhou, Microsoft Corporation */
3664 /* */
3665 /* DESCRIPTION */
3666 /* */
3667 /* This function checks for errors in the HTTP Client POST start */
3668 /* call. */
3669 /* */
3670 /* */
3671 /* INPUT */
3672 /* */
3673 /* client_ptr Pointer to HTTP client */
3674 /* server_ip HTTP Server IP address */
3675 /* server_port HTTP Server TCP port */
3676 /* resource Pointer to resource (URL) */
3677 /* resource_length String length of resource */
3678 /* host Pointer to Host */
3679 /* host_length Length of host */
3680 /* username Pointer to username */
3681 /* username_length Length of username */
3682 /* password Pointer to password */
3683 /* password_length Length of password */
3684 /* total_bytes Total number of bytes to POST */
3685 /* wait_option Suspension option */
3686 /* */
3687 /* OUTPUT */
3688 /* */
3689 /* status Completion status */
3690 /* */
3691 /* CALLS */
3692 /* */
3693 /* _nx_web_http_client_post_start_extended */
3694 /* Actual client post start call */
3695 /* */
3696 /* CALLED BY */
3697 /* */
3698 /* Application Code */
3699 /* */
3700 /* RELEASE HISTORY */
3701 /* */
3702 /* DATE NAME DESCRIPTION */
3703 /* */
3704 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
3705 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
3706 /* resulting in version 6.1 */
3707 /* */
3708 /**************************************************************************/
_nxe_web_http_client_post_start_extended(NX_WEB_HTTP_CLIENT * client_ptr,NXD_ADDRESS * server_ip,UINT server_port,CHAR * resource,UINT resource_length,CHAR * host,UINT host_length,CHAR * username,UINT username_length,CHAR * password,UINT password_length,ULONG total_bytes,ULONG wait_option)3709 UINT _nxe_web_http_client_post_start_extended(NX_WEB_HTTP_CLIENT *client_ptr, NXD_ADDRESS *server_ip,
3710 UINT server_port, CHAR *resource, UINT resource_length,
3711 CHAR *host, UINT host_length, CHAR *username,
3712 UINT username_length, CHAR *password,
3713 UINT password_length, ULONG total_bytes,
3714 ULONG wait_option)
3715 {
3716
3717 UINT status;
3718
3719
3720 /* Check for invalid input pointers. */
3721 if ((client_ptr == NX_NULL) || (client_ptr -> nx_web_http_client_id != NX_WEB_HTTP_CLIENT_ID) ||
3722 (resource == NX_NULL) || !server_ip || (host == NX_NULL))
3723 return(NX_PTR_ERROR);
3724
3725 /* Check for invalid total bytes. */
3726 if (total_bytes == 0)
3727 return(NX_SIZE_ERROR);
3728
3729 /* Check for appropriate caller. */
3730 NX_THREADS_ONLY_CALLER_CHECKING
3731
3732 /* Call actual POST start routine. */
3733 status = _nx_web_http_client_post_start_extended(client_ptr, server_ip, server_port, resource,
3734 resource_length, host, host_length, username,
3735 username_length, password, password_length,
3736 total_bytes, wait_option);
3737
3738 /* Return completion status. */
3739 return(status);
3740 }
3741
3742
3743
3744 /**************************************************************************/
3745 /* */
3746 /* FUNCTION RELEASE */
3747 /* */
3748 /* _nx_web_http_client_post_start_extended PORTABLE C */
3749 /* 6.1 */
3750 /* AUTHOR */
3751 /* */
3752 /* Yuxin Zhou, Microsoft Corporation */
3753 /* */
3754 /* DESCRIPTION */
3755 /* */
3756 /* This function processes an application POST request. Transferring */
3757 /* the specified resource (URL) is started by this routine. The */
3758 /* application must call put packet one or more times to transfer */
3759 /* the resource contents. */
3760 /* */
3761 /* Note: The strings of resource, host, username and password must be */
3762 /* NULL-terminated and length of each string matches the length */
3763 /* specified in the argument list. */
3764 /* */
3765 /* */
3766 /* INPUT */
3767 /* */
3768 /* client_ptr Pointer to HTTP client */
3769 /* server_ip IP address of HTTP Server */
3770 /* resource Pointer to resource (URL) */
3771 /* resource_length String length of resource */
3772 /* host Pointer to Host */
3773 /* host_length Length of host */
3774 /* username Pointer to username */
3775 /* username_length Length of username */
3776 /* password Pointer to password */
3777 /* password_length Length of password */
3778 /* total_bytes Total bytes to send */
3779 /* wait_option Suspension option */
3780 /* */
3781 /* OUTPUT */
3782 /* */
3783 /* status Completion status */
3784 /* */
3785 /* CALLS */
3786 /* */
3787 /* _nx_web_http_client_connect Connect to remote server */
3788 /* _nx_web_http_client_request_initialize_extended */
3789 /* Initialize PUT request */
3790 /* _nx_web_http_client_content_type_header_add */
3791 /* Add content type header */
3792 /* _nx_web_http_client_request_send Send HTTP request to server */
3793 /* _nx_web_http_client_error_exit Shutdown HTTP(S) connection */
3794 /* */
3795 /* CALLED BY */
3796 /* */
3797 /* Application Code */
3798 /* */
3799 /* RELEASE HISTORY */
3800 /* */
3801 /* DATE NAME DESCRIPTION */
3802 /* */
3803 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
3804 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
3805 /* resulting in version 6.1 */
3806 /* */
3807 /**************************************************************************/
_nx_web_http_client_post_start_extended(NX_WEB_HTTP_CLIENT * client_ptr,NXD_ADDRESS * server_ip,UINT server_port,CHAR * resource,UINT resource_length,CHAR * host,UINT host_length,CHAR * username,UINT username_length,CHAR * password,UINT password_length,ULONG total_bytes,ULONG wait_option)3808 UINT _nx_web_http_client_post_start_extended(NX_WEB_HTTP_CLIENT *client_ptr, NXD_ADDRESS *server_ip,
3809 UINT server_port, CHAR *resource, UINT resource_length,
3810 CHAR *host, UINT host_length, CHAR *username,
3811 UINT username_length, CHAR *password,
3812 UINT password_length, ULONG total_bytes,
3813 ULONG wait_option)
3814 {
3815 UINT status;
3816
3817
3818 /* Set the port we are connecting to. */
3819 client_ptr -> nx_web_http_client_connect_port = server_port;
3820
3821 /* Connect to the server. */
3822 status = _nx_web_http_client_connect(client_ptr, server_ip, client_ptr -> nx_web_http_client_connect_port, wait_option);
3823
3824 /* Check status. */
3825 if (status != NX_SUCCESS)
3826 {
3827 return(status);
3828 }
3829
3830 /* Initialize HTTP request. */
3831 status = _nx_web_http_client_request_initialize_extended(client_ptr,
3832 NX_WEB_HTTP_METHOD_POST,
3833 resource,
3834 resource_length,
3835 host,
3836 host_length,
3837 total_bytes,
3838 NX_FALSE, /* If true, input_size is ignored. */
3839 username,
3840 username_length,
3841 password,
3842 password_length,
3843 wait_option);
3844
3845 /* Add approproate headers from input data. */
3846 _nx_web_http_client_content_type_header_add(client_ptr, resource, wait_option);
3847
3848 /* Check status. */
3849 if (status != NX_SUCCESS)
3850 {
3851 return(status);
3852 }
3853
3854 /* Send the HTTP request we just built. */
3855 status = _nx_web_http_client_request_send(client_ptr, wait_option);
3856
3857 /* Determine if the send was successful. */
3858 if (status != NX_SUCCESS)
3859 {
3860
3861 /* No, send was not successful. */
3862
3863 /* Disconnect and unbind the socket. */
3864 _nx_web_http_client_error_exit(client_ptr, wait_option);
3865
3866 /* Return an error. */
3867 return(status);
3868 }
3869
3870
3871 /* Store the total number of bytes to send. */
3872 client_ptr -> nx_web_http_client_total_transfer_bytes = total_bytes;
3873 client_ptr -> nx_web_http_client_actual_bytes_transferred = 0;
3874
3875 /* Enter the POST state. */
3876 client_ptr -> nx_web_http_client_state = NX_WEB_HTTP_CLIENT_STATE_POST;
3877
3878
3879 return(status);
3880 }
3881
3882
3883 #ifdef NX_WEB_HTTPS_ENABLE
3884 /**************************************************************************/
3885 /* */
3886 /* FUNCTION RELEASE */
3887 /* */
3888 /* _nxe_web_http_client_post_secure_start PORTABLE C */
3889 /* 6.1 */
3890 /* AUTHOR */
3891 /* */
3892 /* Yuxin Zhou, Microsoft Corporation */
3893 /* */
3894 /* DESCRIPTION */
3895 /* */
3896 /* This function checks for errors in the HTTPS secure POST request */
3897 /* processing call. */
3898 /* */
3899 /* */
3900 /* INPUT */
3901 /* */
3902 /* client_ptr Pointer to HTTP client */
3903 /* server_ip HTTP Server IP address */
3904 /* server_port HTTP Server TCP port */
3905 /* resource Pointer to resource (URL) */
3906 /* host Pointer to Host */
3907 /* username Pointer to username */
3908 /* password Pointer to password */
3909 /* total_bytes Total number of bytes to POST */
3910 /* tls_setup TLS setup callback function */
3911 /* wait_option Suspension option */
3912 /* */
3913 /* OUTPUT */
3914 /* */
3915 /* status Completion status */
3916 /* */
3917 /* CALLS */
3918 /* */
3919 /* _nxe_web_http_client_post_secure_start */
3920 /* Actual POST processing */
3921 /* */
3922 /* CALLED BY */
3923 /* */
3924 /* Application Code */
3925 /* */
3926 /* RELEASE HISTORY */
3927 /* */
3928 /* DATE NAME DESCRIPTION */
3929 /* */
3930 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
3931 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
3932 /* resulting in version 6.1 */
3933 /* */
3934 /**************************************************************************/
_nxe_web_http_client_post_secure_start(NX_WEB_HTTP_CLIENT * client_ptr,NXD_ADDRESS * server_ip,UINT server_port,CHAR * resource,CHAR * host,CHAR * username,CHAR * password,ULONG total_bytes,UINT (* tls_setup)(NX_WEB_HTTP_CLIENT * client_ptr,NX_SECURE_TLS_SESSION *),ULONG wait_option)3935 UINT _nxe_web_http_client_post_secure_start(NX_WEB_HTTP_CLIENT *client_ptr, NXD_ADDRESS *server_ip, UINT server_port, CHAR *resource,
3936 CHAR *host, CHAR *username, CHAR *password, ULONG total_bytes,
3937 UINT (*tls_setup)(NX_WEB_HTTP_CLIENT *client_ptr, NX_SECURE_TLS_SESSION *),
3938 ULONG wait_option)
3939 {
3940 UINT status;
3941
3942 /* Check for invalid input pointers. */
3943 if ((client_ptr == NX_NULL) || (client_ptr -> nx_web_http_client_id != NX_WEB_HTTP_CLIENT_ID) ||
3944 (resource == NX_NULL) || !server_ip || !tls_setup || (host == NX_NULL))
3945 return(NX_PTR_ERROR);
3946
3947 /* Check for appropriate caller. */
3948 NX_THREADS_ONLY_CALLER_CHECKING
3949
3950 /* Call actual POST start routine. */
3951 status = _nx_web_http_client_post_secure_start(client_ptr, server_ip, server_port, resource, host,
3952 username, password, total_bytes, tls_setup, wait_option);
3953
3954 /* Return completion status. */
3955 return(status);
3956 }
3957
3958
3959
3960 /**************************************************************************/
3961 /* */
3962 /* FUNCTION RELEASE */
3963 /* */
3964 /* _nx_web_http_client_post_secure_start PORTABLE C */
3965 /* 6.1 */
3966 /* AUTHOR */
3967 /* */
3968 /* Yuxin Zhou, Microsoft Corporation */
3969 /* */
3970 /* DESCRIPTION */
3971 /* */
3972 /* This function processes an application POST request. Transferring */
3973 /* the specified resource (URL) is started by this routine. The */
3974 /* application must call put packet one or more times to transfer */
3975 /* the resource contents. This version of the function also requires */
3976 /* a TLS setup callback as the data is sent over TLS-secured HTTPS. */
3977 /* */
3978 /* */
3979 /* INPUT */
3980 /* */
3981 /* client_ptr Pointer to HTTP client */
3982 /* server_ip HTTP Server IP address */
3983 /* server_port HTTP Server TCP port */
3984 /* resource Pointer to resource (URL) */
3985 /* host Pointer to Host */
3986 /* username Pointer to username */
3987 /* password Pointer to password */
3988 /* total_bytes Total number of bytes to POST */
3989 /* tls_setup TLS setup callback function */
3990 /* wait_option Suspension option */
3991 /* */
3992 /* OUTPUT */
3993 /* */
3994 /* status Completion status */
3995 /* _nx_utility_string_length_check Check string length */
3996 /* */
3997 /* CALLS */
3998 /* */
3999 /* _nx_web_http_client_post_secure_start_extended */
4000 /* Actual POST request processing*/
4001 /* */
4002 /* CALLED BY */
4003 /* */
4004 /* Application Code */
4005 /* */
4006 /* RELEASE HISTORY */
4007 /* */
4008 /* DATE NAME DESCRIPTION */
4009 /* */
4010 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
4011 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
4012 /* resulting in version 6.1 */
4013 /* */
4014 /**************************************************************************/
_nx_web_http_client_post_secure_start(NX_WEB_HTTP_CLIENT * client_ptr,NXD_ADDRESS * server_ip,UINT server_port,CHAR * resource,CHAR * host,CHAR * username,CHAR * password,ULONG total_bytes,UINT (* tls_setup)(NX_WEB_HTTP_CLIENT * client_ptr,NX_SECURE_TLS_SESSION *),ULONG wait_option)4015 UINT _nx_web_http_client_post_secure_start(NX_WEB_HTTP_CLIENT *client_ptr, NXD_ADDRESS *server_ip, UINT server_port, CHAR *resource,
4016 CHAR *host, CHAR *username, CHAR *password, ULONG total_bytes,
4017 UINT (*tls_setup)(NX_WEB_HTTP_CLIENT *client_ptr, NX_SECURE_TLS_SESSION *),
4018 ULONG wait_option)
4019 {
4020 UINT temp_resource_length;
4021 UINT temp_host_length;
4022 UINT temp_username_length = 0;
4023 UINT temp_password_length = 0;
4024
4025 if ((username) && (password))
4026 {
4027
4028 /* Check username and password length. */
4029 if (_nx_utility_string_length_check(username, &temp_username_length, NX_WEB_HTTP_MAX_NAME) ||
4030 _nx_utility_string_length_check(password, &temp_password_length, NX_WEB_HTTP_MAX_PASSWORD))
4031 {
4032 return(NX_WEB_HTTP_ERROR);
4033 }
4034 }
4035
4036 /* Check resource and host length. */
4037 if (_nx_utility_string_length_check(resource, &temp_resource_length, NX_MAX_STRING_LENGTH) ||
4038 _nx_utility_string_length_check(host, &temp_host_length, NX_MAX_STRING_LENGTH))
4039 {
4040 return(NX_WEB_HTTP_ERROR);
4041 }
4042
4043 return(_nx_web_http_client_post_secure_start_extended(client_ptr, server_ip, server_port,
4044 resource, temp_resource_length, host,
4045 temp_host_length, username,
4046 temp_username_length, password,
4047 temp_password_length, total_bytes,
4048 tls_setup, wait_option));
4049 }
4050
4051
4052 /**************************************************************************/
4053 /* */
4054 /* FUNCTION RELEASE */
4055 /* */
4056 /* _nxe_web_http_client_post_secure_start_extended PORTABLE C */
4057 /* 6.1 */
4058 /* AUTHOR */
4059 /* */
4060 /* Yuxin Zhou, Microsoft Corporation */
4061 /* */
4062 /* DESCRIPTION */
4063 /* */
4064 /* This function checks for errors in the HTTPS secure POST request */
4065 /* processing call. */
4066 /* */
4067 /* */
4068 /* INPUT */
4069 /* */
4070 /* client_ptr Pointer to HTTP client */
4071 /* server_ip IP duo address of HTTP Server */
4072 /* resource Pointer to resource (URL) */
4073 /* resource_length String length of resource */
4074 /* host Pointer to Host */
4075 /* host_length Length of host */
4076 /* username Pointer to username */
4077 /* username_length Length of username */
4078 /* password Pointer to password */
4079 /* password_length Length of password */
4080 /* total_bytes Total number of bytes to POST */
4081 /* tls_setup TLS setup callback function */
4082 /* wait_option Suspension option */
4083 /* */
4084 /* OUTPUT */
4085 /* */
4086 /* status Completion status */
4087 /* */
4088 /* CALLS */
4089 /* */
4090 /* _nx_web_http_client_post_secure_start_extended */
4091 /* Actual POST request processing*/
4092 /* */
4093 /* CALLED BY */
4094 /* */
4095 /* Application Code */
4096 /* */
4097 /* RELEASE HISTORY */
4098 /* */
4099 /* DATE NAME DESCRIPTION */
4100 /* */
4101 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
4102 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
4103 /* resulting in version 6.1 */
4104 /* */
4105 /**************************************************************************/
_nxe_web_http_client_post_secure_start_extended(NX_WEB_HTTP_CLIENT * client_ptr,NXD_ADDRESS * server_ip,UINT server_port,CHAR * resource,UINT resource_length,CHAR * host,UINT host_length,CHAR * username,UINT username_length,CHAR * password,UINT password_length,ULONG total_bytes,UINT (* tls_setup)(NX_WEB_HTTP_CLIENT * client_ptr,NX_SECURE_TLS_SESSION *),ULONG wait_option)4106 UINT _nxe_web_http_client_post_secure_start_extended(NX_WEB_HTTP_CLIENT *client_ptr, NXD_ADDRESS *server_ip, UINT server_port,
4107 CHAR *resource, UINT resource_length, CHAR *host, UINT host_length,
4108 CHAR *username, UINT username_length, CHAR *password,
4109 UINT password_length, ULONG total_bytes,
4110 UINT (*tls_setup)(NX_WEB_HTTP_CLIENT *client_ptr, NX_SECURE_TLS_SESSION *),
4111 ULONG wait_option)
4112 {
4113 UINT status;
4114
4115 /* Check for invalid input pointers. */
4116 if ((client_ptr == NX_NULL) || (client_ptr -> nx_web_http_client_id != NX_WEB_HTTP_CLIENT_ID) ||
4117 (resource == NX_NULL) || !server_ip || !tls_setup || (host == NX_NULL))
4118 return(NX_PTR_ERROR);
4119
4120 /* Check for appropriate caller. */
4121 NX_THREADS_ONLY_CALLER_CHECKING
4122
4123 /* Call actual POST start routine. */
4124 status = _nx_web_http_client_post_secure_start_extended(client_ptr, server_ip, server_port,
4125 resource, resource_length, host,
4126 host_length, username, username_length,
4127 password, password_length, total_bytes,
4128 tls_setup, wait_option);
4129
4130 /* Return completion status. */
4131 return(status);
4132 }
4133
4134
4135 /**************************************************************************/
4136 /* */
4137 /* FUNCTION RELEASE */
4138 /* */
4139 /* _nx_web_http_client_post_secure_start_extended PORTABLE C */
4140 /* 6.1 */
4141 /* AUTHOR */
4142 /* */
4143 /* Yuxin Zhou, Microsoft Corporation */
4144 /* */
4145 /* DESCRIPTION */
4146 /* */
4147 /* This function processes an application POST request. Transferring */
4148 /* the specified resource (URL) is started by this routine. The */
4149 /* application must call put packet one or more times to transfer */
4150 /* the resource contents. This version of the function also requires */
4151 /* a TLS setup callback as the data is sent over TLS-secured HTTPS. */
4152 /* */
4153 /* Note: The strings of resource, host, username and password must be */
4154 /* NULL-terminated and length of each string matches the length */
4155 /* specified in the argument list. */
4156 /* */
4157 /* */
4158 /* INPUT */
4159 /* */
4160 /* client_ptr Pointer to HTTP client */
4161 /* server_ip IP duo address of HTTP Server */
4162 /* resource Pointer to resource (URL) */
4163 /* resource_length String length of resource */
4164 /* host Pointer to Host */
4165 /* host_length Length of host */
4166 /* username Pointer to username */
4167 /* username_length Length of username */
4168 /* password Pointer to password */
4169 /* password_length Length of password */
4170 /* total_bytes Total number of bytes to POST */
4171 /* tls_setup TLS setup callback function */
4172 /* wait_option Suspension option */
4173 /* */
4174 /* OUTPUT */
4175 /* */
4176 /* status Completion status */
4177 /* */
4178 /* CALLS */
4179 /* */
4180 /* _nx_web_http_client_secure_connect Connect to HTTPS server */
4181 /* _nx_web_http_client_request_initialize_extended */
4182 /* Initialize HTTP request */
4183 /* _nx_web_http_client_request_send Send HTTP request to server */
4184 /* _nx_web_http_client_content_type_header_add */
4185 /* Add content type header */
4186 /* _nx_web_http_client_error_exit Close HTTPS session */
4187 /* */
4188 /* CALLED BY */
4189 /* */
4190 /* Application Code */
4191 /* */
4192 /* RELEASE HISTORY */
4193 /* */
4194 /* DATE NAME DESCRIPTION */
4195 /* */
4196 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
4197 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
4198 /* resulting in version 6.1 */
4199 /* */
4200 /**************************************************************************/
_nx_web_http_client_post_secure_start_extended(NX_WEB_HTTP_CLIENT * client_ptr,NXD_ADDRESS * server_ip,UINT server_port,CHAR * resource,UINT resource_length,CHAR * host,UINT host_length,CHAR * username,UINT username_length,CHAR * password,UINT password_length,ULONG total_bytes,UINT (* tls_setup)(NX_WEB_HTTP_CLIENT * client_ptr,NX_SECURE_TLS_SESSION *),ULONG wait_option)4201 UINT _nx_web_http_client_post_secure_start_extended(NX_WEB_HTTP_CLIENT *client_ptr, NXD_ADDRESS *server_ip, UINT server_port,
4202 CHAR *resource, UINT resource_length, CHAR *host, UINT host_length,
4203 CHAR *username, UINT username_length, CHAR *password,
4204 UINT password_length, ULONG total_bytes,
4205 UINT (*tls_setup)(NX_WEB_HTTP_CLIENT *client_ptr, NX_SECURE_TLS_SESSION *),
4206 ULONG wait_option)
4207 {
4208 UINT status;
4209
4210
4211 /* Use default HTTPS port. */
4212 client_ptr->nx_web_http_client_connect_port = server_port;
4213
4214 /* Connect to the server. */
4215 status = _nx_web_http_client_secure_connect(client_ptr, server_ip, client_ptr->nx_web_http_client_connect_port, tls_setup, wait_option);
4216
4217 /* Check status. */
4218 if (status != NX_SUCCESS)
4219 {
4220 return(status);
4221 }
4222
4223 /* Initialize HTTP request. */
4224 status = _nx_web_http_client_request_initialize_extended(client_ptr,
4225 NX_WEB_HTTP_METHOD_POST,
4226 resource,
4227 resource_length,
4228 host,
4229 host_length,
4230 total_bytes,
4231 NX_FALSE, /* If true, input_size is ignored. */
4232 username,
4233 username_length,
4234 password,
4235 password_length,
4236 wait_option);
4237
4238 /* Add approproate headers from input data. */
4239 _nx_web_http_client_content_type_header_add(client_ptr, resource, wait_option);
4240
4241 /* Check status. */
4242 if (status != NX_SUCCESS)
4243 {
4244 return(status);
4245 }
4246
4247 /* Send the HTTP request we just built. */
4248 status = _nx_web_http_client_request_send(client_ptr, wait_option);
4249
4250 /* Determine if the send was successful. */
4251 if (status != NX_SUCCESS)
4252 {
4253
4254 /* No, send was not successful. */
4255
4256 /* Disconnect and unbind the socket. */
4257 _nx_web_http_client_error_exit(client_ptr, wait_option);
4258
4259 /* Return an error. */
4260 return(status);
4261 }
4262
4263
4264 /* Store the total number of bytes to send. */
4265 client_ptr -> nx_web_http_client_total_transfer_bytes = total_bytes;
4266 client_ptr -> nx_web_http_client_actual_bytes_transferred = 0;
4267
4268 /* Enter the POST state. */
4269 client_ptr -> nx_web_http_client_state = NX_WEB_HTTP_CLIENT_STATE_POST;
4270
4271 return(status);
4272 }
4273
4274 #endif /* NX_WEB_HTTPS_ENABLE */
4275
4276
4277 /**************************************************************************/
4278 /* */
4279 /* FUNCTION RELEASE */
4280 /* */
4281 /* _nxe_web_http_client_head_start PORTABLE C */
4282 /* 6.1 */
4283 /* AUTHOR */
4284 /* */
4285 /* Yuxin Zhou, Microsoft Corporation */
4286 /* */
4287 /* DESCRIPTION */
4288 /* */
4289 /* This function checks for errors in the call to start a HEAD request.*/
4290 /* */
4291 /* */
4292 /* INPUT */
4293 /* */
4294 /* client_ptr Pointer to HTTP client */
4295 /* server_ip IP address of HTTP Server */
4296 /* resource Pointer to resource (URL) */
4297 /* host Pointer to Host */
4298 /* username Pointer to username */
4299 /* password Pointer to password */
4300 /* wait_option Suspension option */
4301 /* */
4302 /* OUTPUT */
4303 /* */
4304 /* status Completion status */
4305 /* */
4306 /* CALLS */
4307 /* */
4308 /* _nx_web_http_client_head_start Actual HEAD request call */
4309 /* */
4310 /* CALLED BY */
4311 /* */
4312 /* Application Code */
4313 /* */
4314 /* RELEASE HISTORY */
4315 /* */
4316 /* DATE NAME DESCRIPTION */
4317 /* */
4318 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
4319 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
4320 /* resulting in version 6.1 */
4321 /* */
4322 /**************************************************************************/
_nxe_web_http_client_head_start(NX_WEB_HTTP_CLIENT * client_ptr,NXD_ADDRESS * server_ip,UINT server_port,CHAR * resource,CHAR * host,CHAR * username,CHAR * password,ULONG wait_option)4323 UINT _nxe_web_http_client_head_start(NX_WEB_HTTP_CLIENT *client_ptr, NXD_ADDRESS *server_ip, UINT server_port,
4324 CHAR *resource, CHAR *host, CHAR *username, CHAR *password,
4325 ULONG wait_option)
4326 {
4327
4328 UINT status;
4329
4330 /* Check for invalid input pointers. */
4331 if ((client_ptr == NX_NULL) || (client_ptr -> nx_web_http_client_id != NX_WEB_HTTP_CLIENT_ID) ||
4332 (resource == NX_NULL) || !server_ip || (host == NX_NULL))
4333 {
4334 return(NX_PTR_ERROR);
4335 }
4336
4337 /* Check for appropriate caller. */
4338 NX_THREADS_ONLY_CALLER_CHECKING
4339
4340 /* Call actual HEAD start routine. */
4341 status = _nx_web_http_client_head_start(client_ptr, server_ip, server_port, resource,
4342 host, username, password, wait_option);
4343
4344 /* Return completion status. */
4345 return(status);
4346 }
4347
4348 /**************************************************************************/
4349 /* */
4350 /* FUNCTION RELEASE */
4351 /* */
4352 /* _nx_web_http_client_head_start PORTABLE C */
4353 /* 6.1 */
4354 /* AUTHOR */
4355 /* */
4356 /* Yuxin Zhou, Microsoft Corporation */
4357 /* */
4358 /* DESCRIPTION */
4359 /* */
4360 /* This function processes an application HEAD request. HEAD is */
4361 /* identical to GET for the HTTP client, so the server response is */
4362 /* processed by calling nx_web_http_client_response_body_get. */
4363 /* */
4364 /* */
4365 /* INPUT */
4366 /* */
4367 /* client_ptr Pointer to HTTP client */
4368 /* server_ip IP address of HTTP Server */
4369 /* resource Pointer to resource (URL) */
4370 /* host Pointer to Host */
4371 /* username Pointer to username */
4372 /* password Pointer to password */
4373 /* wait_option Suspension option */
4374 /* */
4375 /* OUTPUT */
4376 /* */
4377 /* status Completion status */
4378 /* */
4379 /* CALLS */
4380 /* */
4381 /* _nx_web_http_client_head_start_extended */
4382 /* Actual HEAD request call */
4383 /* _nx_utility_string_length_check Check string length */
4384 /* */
4385 /* CALLED BY */
4386 /* */
4387 /* Application Code */
4388 /* */
4389 /* RELEASE HISTORY */
4390 /* */
4391 /* DATE NAME DESCRIPTION */
4392 /* */
4393 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
4394 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
4395 /* resulting in version 6.1 */
4396 /* */
4397 /**************************************************************************/
_nx_web_http_client_head_start(NX_WEB_HTTP_CLIENT * client_ptr,NXD_ADDRESS * server_ip,UINT server_port,CHAR * resource,CHAR * host,CHAR * username,CHAR * password,ULONG wait_option)4398 UINT _nx_web_http_client_head_start(NX_WEB_HTTP_CLIENT *client_ptr, NXD_ADDRESS *server_ip, UINT server_port, CHAR *resource,
4399 CHAR *host, CHAR *username, CHAR *password, ULONG wait_option)
4400 {
4401 UINT temp_resource_length;
4402 UINT temp_host_length;
4403 UINT temp_username_length = 0;
4404 UINT temp_password_length = 0;
4405
4406 if ((username) && (password))
4407 {
4408
4409 /* Check username and password length. */
4410 if (_nx_utility_string_length_check(username, &temp_username_length, NX_WEB_HTTP_MAX_NAME) ||
4411 _nx_utility_string_length_check(password, &temp_password_length, NX_WEB_HTTP_MAX_PASSWORD))
4412 {
4413 return(NX_WEB_HTTP_ERROR);
4414 }
4415 }
4416
4417 /* Check resource and host length. */
4418 if (_nx_utility_string_length_check(resource, &temp_resource_length, NX_MAX_STRING_LENGTH) ||
4419 _nx_utility_string_length_check(host, &temp_host_length, NX_MAX_STRING_LENGTH))
4420 {
4421 return(NX_WEB_HTTP_ERROR);
4422 }
4423
4424 return(_nx_web_http_client_head_start_extended(client_ptr, server_ip, server_port, resource,
4425 temp_resource_length, host, temp_host_length, username,
4426 temp_username_length, password, temp_password_length,
4427 wait_option));
4428
4429 }
4430
4431
4432 /**************************************************************************/
4433 /* */
4434 /* FUNCTION RELEASE */
4435 /* */
4436 /* _nxe_web_http_client_head_start_extended PORTABLE C */
4437 /* 6.1 */
4438 /* AUTHOR */
4439 /* */
4440 /* Yuxin Zhou, Microsoft Corporation */
4441 /* */
4442 /* DESCRIPTION */
4443 /* */
4444 /* This function checks for errors in the call to start a HEAD request.*/
4445 /* */
4446 /* */
4447 /* INPUT */
4448 /* */
4449 /* client_ptr Pointer to HTTP client */
4450 /* server_ip IP duo address of HTTP Server */
4451 /* resource Pointer to resource (URL) */
4452 /* resource_length String length of resource */
4453 /* host Pointer to Host */
4454 /* host_length Length of host */
4455 /* username Pointer to username */
4456 /* username_length Length of username */
4457 /* password Pointer to password */
4458 /* password_length Length of password */
4459 /* wait_option Suspension option */
4460 /* */
4461 /* OUTPUT */
4462 /* */
4463 /* status Completion status */
4464 /* */
4465 /* CALLS */
4466 /* */
4467 /* _nx_web_http_client_head_start_extended */
4468 /* Actual HEAD request call */
4469 /* */
4470 /* CALLED BY */
4471 /* */
4472 /* Application Code */
4473 /* */
4474 /* RELEASE HISTORY */
4475 /* */
4476 /* DATE NAME DESCRIPTION */
4477 /* */
4478 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
4479 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
4480 /* resulting in version 6.1 */
4481 /* */
4482 /**************************************************************************/
_nxe_web_http_client_head_start_extended(NX_WEB_HTTP_CLIENT * client_ptr,NXD_ADDRESS * server_ip,UINT server_port,CHAR * resource,UINT resource_length,CHAR * host,UINT host_length,CHAR * username,UINT username_length,CHAR * password,UINT password_length,ULONG wait_option)4483 UINT _nxe_web_http_client_head_start_extended(NX_WEB_HTTP_CLIENT *client_ptr, NXD_ADDRESS *server_ip,
4484 UINT server_port, CHAR *resource, UINT resource_length,
4485 CHAR *host, UINT host_length, CHAR *username,
4486 UINT username_length, CHAR *password,
4487 UINT password_length, ULONG wait_option)
4488 {
4489
4490 UINT status;
4491
4492 /* Check for invalid input pointers. */
4493 if ((client_ptr == NX_NULL) || (client_ptr -> nx_web_http_client_id != NX_WEB_HTTP_CLIENT_ID) ||
4494 (resource == NX_NULL) || !server_ip || (host == NX_NULL))
4495 {
4496 return(NX_PTR_ERROR);
4497 }
4498
4499 /* Check for appropriate caller. */
4500 NX_THREADS_ONLY_CALLER_CHECKING
4501
4502 /* Call actual HEAD start routine. */
4503 status = _nx_web_http_client_head_start_extended(client_ptr, server_ip, server_port, resource,
4504 resource_length, host, host_length, username,
4505 username_length, password, password_length,
4506 wait_option);
4507
4508 /* Return completion status. */
4509 return(status);
4510 }
4511
4512 /**************************************************************************/
4513 /* */
4514 /* FUNCTION RELEASE */
4515 /* */
4516 /* _nx_web_http_client_head_start_extended PORTABLE C */
4517 /* 6.1 */
4518 /* AUTHOR */
4519 /* */
4520 /* Yuxin Zhou, Microsoft Corporation */
4521 /* */
4522 /* DESCRIPTION */
4523 /* */
4524 /* This function processes an application HEAD request. HEAD is */
4525 /* identical to GET for the HTTP client, so the server response is */
4526 /* processed by calling nx_web_http_client_response_body_get. */
4527 /* */
4528 /* Note: The strings of resource, host, username and password must be */
4529 /* NULL-terminated and length of each string matches the length */
4530 /* specified in the argument list. */
4531 /* */
4532 /* */
4533 /* INPUT */
4534 /* */
4535 /* client_ptr Pointer to HTTP client */
4536 /* server_ip HTTP Server IP address */
4537 /* resource Pointer to resource (URL) */
4538 /* resource_length String length of resource */
4539 /* host Pointer to Host */
4540 /* host_length Length of host */
4541 /* username Pointer to username */
4542 /* username_length Length of username */
4543 /* password Pointer to password */
4544 /* password_length Length of password */
4545 /* wait_option Suspension option */
4546 /* */
4547 /* OUTPUT */
4548 /* */
4549 /* status Completion status */
4550 /* */
4551 /* CALLS */
4552 /* */
4553 /* _nx_web_http_client_connect Connect to remote server */
4554 /* _nx_web_http_client_request_initialize_extended */
4555 /* Initialize HEAD request */
4556 /* _nx_web_http_client_content_type_header_add */
4557 /* Add content type header */
4558 /* _nx_web_http_client_request_send Send HTTP request to server */
4559 /* _nx_web_http_client_error_exit Shutdown HTTP(S) connection */
4560 /* */
4561 /* CALLED BY */
4562 /* */
4563 /* Application Code */
4564 /* */
4565 /* RELEASE HISTORY */
4566 /* */
4567 /* DATE NAME DESCRIPTION */
4568 /* */
4569 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
4570 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
4571 /* resulting in version 6.1 */
4572 /* */
4573 /**************************************************************************/
_nx_web_http_client_head_start_extended(NX_WEB_HTTP_CLIENT * client_ptr,NXD_ADDRESS * server_ip,UINT server_port,CHAR * resource,UINT resource_length,CHAR * host,UINT host_length,CHAR * username,UINT username_length,CHAR * password,UINT password_length,ULONG wait_option)4574 UINT _nx_web_http_client_head_start_extended(NX_WEB_HTTP_CLIENT *client_ptr, NXD_ADDRESS *server_ip,
4575 UINT server_port, CHAR *resource, UINT resource_length,
4576 CHAR *host, UINT host_length, CHAR *username,
4577 UINT username_length, CHAR *password,
4578 UINT password_length, ULONG wait_option)
4579 {
4580 UINT status;
4581
4582 client_ptr->nx_web_http_client_connect_port = server_port;
4583
4584 /* Connect to the server. */
4585 status = _nx_web_http_client_connect(client_ptr, server_ip, client_ptr->nx_web_http_client_connect_port, wait_option);
4586
4587 /* Check status. */
4588 if (status != NX_SUCCESS)
4589 {
4590 return(status);
4591 }
4592
4593 /* Initialize HTTP request. */
4594 status = _nx_web_http_client_request_initialize_extended(client_ptr,
4595 NX_WEB_HTTP_METHOD_HEAD,
4596 resource,
4597 resource_length,
4598 host,
4599 host_length,
4600 0,
4601 NX_FALSE, /* If true, input_size is ignored. */
4602 username,
4603 username_length,
4604 password,
4605 password_length,
4606 wait_option);
4607
4608 /* Check status. */
4609 if (status != NX_SUCCESS)
4610 {
4611 return(status);
4612 }
4613
4614 /* Send the HTTP request we just built. */
4615 status = _nx_web_http_client_request_send(client_ptr, wait_option);
4616
4617 /* Check status. */
4618 if (status != NX_SUCCESS)
4619 {
4620 return(status);
4621 }
4622
4623 /* Enter the HEAD state. */
4624 client_ptr -> nx_web_http_client_state = NX_WEB_HTTP_CLIENT_STATE_HEAD;
4625
4626 return(status);
4627 }
4628
4629 #ifdef NX_WEB_HTTPS_ENABLE
4630 /**************************************************************************/
4631 /* */
4632 /* FUNCTION RELEASE */
4633 /* */
4634 /* _nxe_web_http_client_head_secure_start PORTABLE C */
4635 /* 6.1 */
4636 /* AUTHOR */
4637 /* */
4638 /* Yuxin Zhou, Microsoft Corporation */
4639 /* */
4640 /* DESCRIPTION */
4641 /* */
4642 /* This function checks for errors in the HTTPS secure HEAD request */
4643 /* processing call. */
4644 /* */
4645 /* */
4646 /* INPUT */
4647 /* */
4648 /* client_ptr Pointer to HTTP client */
4649 /* server_ip HTTP Server IP address */
4650 /* resource Pointer to resource (URL) */
4651 /* host Pointer to Host */
4652 /* username Pointer to username */
4653 /* password Pointer to password */
4654 /* tls_setup TLS setup callback function */
4655 /* wait_option Suspension option */
4656 /* */
4657 /* OUTPUT */
4658 /* */
4659 /* status Completion status */
4660 /* */
4661 /* CALLS */
4662 /* */
4663 /* _nx_web_http_client_head_secure_start */
4664 /* Actual HEAD request processing*/
4665 /* */
4666 /* CALLED BY */
4667 /* */
4668 /* Application Code */
4669 /* */
4670 /* RELEASE HISTORY */
4671 /* */
4672 /* DATE NAME DESCRIPTION */
4673 /* */
4674 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
4675 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
4676 /* resulting in version 6.1 */
4677 /* */
4678 /**************************************************************************/
_nxe_web_http_client_head_secure_start(NX_WEB_HTTP_CLIENT * client_ptr,NXD_ADDRESS * server_ip,UINT server_port,CHAR * resource,CHAR * host,CHAR * username,CHAR * password,UINT (* tls_setup)(NX_WEB_HTTP_CLIENT * client_ptr,NX_SECURE_TLS_SESSION *),ULONG wait_option)4679 UINT _nxe_web_http_client_head_secure_start(NX_WEB_HTTP_CLIENT *client_ptr, NXD_ADDRESS *server_ip, UINT server_port, CHAR *resource,
4680 CHAR *host, CHAR *username, CHAR *password,
4681 UINT (*tls_setup)(NX_WEB_HTTP_CLIENT *client_ptr, NX_SECURE_TLS_SESSION *),
4682 ULONG wait_option)
4683 {
4684 UINT status;
4685
4686 /* Check for invalid input pointers. */
4687 if ((client_ptr == NX_NULL) || (client_ptr -> nx_web_http_client_id != NX_WEB_HTTP_CLIENT_ID) ||
4688 (resource == NX_NULL) || !server_ip || !tls_setup || (host == NX_NULL))
4689 return(NX_PTR_ERROR);
4690
4691 /* Check for appropriate caller. */
4692 NX_THREADS_ONLY_CALLER_CHECKING
4693
4694 /* Call actual HEAD start routine. */
4695 status = _nx_web_http_client_head_secure_start(client_ptr, server_ip, server_port, resource,
4696 host, username, password, tls_setup, wait_option);
4697
4698 /* Return completion status. */
4699 return(status);
4700 }
4701
4702
4703
4704 /**************************************************************************/
4705 /* */
4706 /* FUNCTION RELEASE */
4707 /* */
4708 /* _nx_web_http_client_head_secure_start PORTABLE C */
4709 /* 6.1 */
4710 /* AUTHOR */
4711 /* */
4712 /* Yuxin Zhou, Microsoft Corporation */
4713 /* */
4714 /* DESCRIPTION */
4715 /* */
4716 /* This function processes an application HEAD request. The HTTP */
4717 /* header for the specified resource (URL) is requested from the HTTP */
4718 /* Server at the specified IP address and port. This version of the */
4719 /* function also requires a TLS setup callback as the request is sent */
4720 /* over TLS-secured HTTPS. */
4721 /* */
4722 /* */
4723 /* INPUT */
4724 /* */
4725 /* client_ptr Pointer to HTTP client */
4726 /* server_ip HTTP Server IP address */
4727 /* resource Pointer to resource (URL) */
4728 /* host Pointer to Host */
4729 /* username Pointer to username */
4730 /* password Pointer to password */
4731 /* tls_setup TLS setup callback function */
4732 /* wait_option Suspension option */
4733 /* */
4734 /* OUTPUT */
4735 /* */
4736 /* status Completion status */
4737 /* */
4738 /* CALLS */
4739 /* */
4740 /* _nx_web_http_client_head_secure_start_extended */
4741 /* Actual HEAD request processing*/
4742 /* _nx_utility_string_length_check Check string length */
4743 /* */
4744 /* CALLED BY */
4745 /* */
4746 /* Application Code */
4747 /* */
4748 /* RELEASE HISTORY */
4749 /* */
4750 /* DATE NAME DESCRIPTION */
4751 /* */
4752 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
4753 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
4754 /* resulting in version 6.1 */
4755 /* */
4756 /**************************************************************************/
_nx_web_http_client_head_secure_start(NX_WEB_HTTP_CLIENT * client_ptr,NXD_ADDRESS * server_ip,UINT server_port,CHAR * resource,CHAR * host,CHAR * username,CHAR * password,UINT (* tls_setup)(NX_WEB_HTTP_CLIENT * client_ptr,NX_SECURE_TLS_SESSION *),ULONG wait_option)4757 UINT _nx_web_http_client_head_secure_start(NX_WEB_HTTP_CLIENT *client_ptr, NXD_ADDRESS *server_ip, UINT server_port, CHAR *resource,
4758 CHAR *host, CHAR *username, CHAR *password,
4759 UINT (*tls_setup)(NX_WEB_HTTP_CLIENT *client_ptr, NX_SECURE_TLS_SESSION *),
4760 ULONG wait_option)
4761 {
4762 UINT temp_resource_length;
4763 UINT temp_host_length;
4764 UINT temp_username_length = 0;
4765 UINT temp_password_length = 0;
4766
4767 if ((username) && (password))
4768 {
4769
4770 /* Check username and password length. */
4771 if (_nx_utility_string_length_check(username, &temp_username_length, NX_WEB_HTTP_MAX_NAME) ||
4772 _nx_utility_string_length_check(password, &temp_password_length, NX_WEB_HTTP_MAX_PASSWORD))
4773 {
4774 return(NX_WEB_HTTP_ERROR);
4775 }
4776 }
4777
4778 /* Check resource and host length. */
4779 if (_nx_utility_string_length_check(resource, &temp_resource_length, NX_MAX_STRING_LENGTH) ||
4780 _nx_utility_string_length_check(host, &temp_host_length, NX_MAX_STRING_LENGTH))
4781 {
4782 return(NX_WEB_HTTP_ERROR);
4783 }
4784
4785 return(_nx_web_http_client_head_secure_start_extended(client_ptr, server_ip, server_port,
4786 resource, temp_resource_length, host,
4787 temp_host_length, username,
4788 temp_username_length, password,
4789 temp_password_length, tls_setup,
4790 wait_option));
4791 }
4792
4793
4794 /**************************************************************************/
4795 /* */
4796 /* FUNCTION RELEASE */
4797 /* */
4798 /* _nxe_web_http_client_head_secure_start_extended PORTABLE C */
4799 /* 6.1 */
4800 /* AUTHOR */
4801 /* */
4802 /* Yuxin Zhou, Microsoft Corporation */
4803 /* */
4804 /* DESCRIPTION */
4805 /* */
4806 /* This function checks for errors in the HTTPS secure HEAD request */
4807 /* processing call. */
4808 /* */
4809 /* */
4810 /* INPUT */
4811 /* */
4812 /* client_ptr Pointer to HTTP client */
4813 /* server_ip IP duo address of HTTP Server */
4814 /* resource Pointer to resource (URL) */
4815 /* resource_length String length of resource */
4816 /* host Pointer to Host */
4817 /* host_length Length of host */
4818 /* username Pointer to username */
4819 /* username_length Length of username */
4820 /* password Pointer to password */
4821 /* password_length Length of password */
4822 /* tls_setup TLS setup callback function */
4823 /* wait_option Suspension option */
4824 /* */
4825 /* OUTPUT */
4826 /* */
4827 /* status Completion status */
4828 /* */
4829 /* CALLS */
4830 /* */
4831 /* _nx_web_http_client_head_secure_start_extended */
4832 /* Actual HEAD request processing*/
4833 /* */
4834 /* CALLED BY */
4835 /* */
4836 /* Application Code */
4837 /* */
4838 /* RELEASE HISTORY */
4839 /* */
4840 /* DATE NAME DESCRIPTION */
4841 /* */
4842 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
4843 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
4844 /* resulting in version 6.1 */
4845 /* */
4846 /**************************************************************************/
_nxe_web_http_client_head_secure_start_extended(NX_WEB_HTTP_CLIENT * client_ptr,NXD_ADDRESS * server_ip,UINT server_port,CHAR * resource,UINT resource_length,CHAR * host,UINT host_length,CHAR * username,UINT username_length,CHAR * password,UINT password_length,UINT (* tls_setup)(NX_WEB_HTTP_CLIENT * client_ptr,NX_SECURE_TLS_SESSION *),ULONG wait_option)4847 UINT _nxe_web_http_client_head_secure_start_extended(NX_WEB_HTTP_CLIENT *client_ptr, NXD_ADDRESS *server_ip, UINT server_port,
4848 CHAR *resource, UINT resource_length, CHAR *host, UINT host_length,
4849 CHAR *username, UINT username_length, CHAR *password,
4850 UINT password_length,
4851 UINT (*tls_setup)(NX_WEB_HTTP_CLIENT *client_ptr, NX_SECURE_TLS_SESSION *),
4852 ULONG wait_option)
4853 {
4854 UINT status;
4855
4856 /* Check for invalid input pointers. */
4857 if ((client_ptr == NX_NULL) || (client_ptr -> nx_web_http_client_id != NX_WEB_HTTP_CLIENT_ID) ||
4858 (resource == NX_NULL) || !server_ip || !tls_setup || (host == NX_NULL))
4859 return(NX_PTR_ERROR);
4860
4861 /* Check for appropriate caller. */
4862 NX_THREADS_ONLY_CALLER_CHECKING
4863
4864 /* Call actual HEAD start routine. */
4865 status = _nx_web_http_client_head_secure_start_extended(client_ptr, server_ip, server_port,
4866 resource, resource_length, host,
4867 host_length, username, username_length,
4868 password, password_length,
4869 tls_setup, wait_option);
4870
4871 /* Return completion status. */
4872 return(status);
4873 }
4874
4875
4876 /**************************************************************************/
4877 /* */
4878 /* FUNCTION RELEASE */
4879 /* */
4880 /* _nx_web_http_client_head_secure_start_extended PORTABLE C */
4881 /* 6.1 */
4882 /* AUTHOR */
4883 /* */
4884 /* Yuxin Zhou, Microsoft Corporation */
4885 /* */
4886 /* DESCRIPTION */
4887 /* */
4888 /* This function processes an application HEAD request. The HTTP */
4889 /* header for the specified resource (URL) is requested from the HTTP */
4890 /* Server at the specified IP address and port. This version of the */
4891 /* function also requires a TLS setup callback as the request is sent */
4892 /* over TLS-secured HTTPS. */
4893 /* */
4894 /* Note: The strings of resource, host, username and password must be */
4895 /* NULL-terminated and length of each string matches the length */
4896 /* specified in the argument list. */
4897 /* */
4898 /* */
4899 /* INPUT */
4900 /* */
4901 /* client_ptr Pointer to HTTP client */
4902 /* server_ip IP duo address of HTTP Server */
4903 /* resource Pointer to resource (URL) */
4904 /* resource_length String length of resource */
4905 /* host Pointer to Host */
4906 /* host_length Length of host */
4907 /* username Pointer to username */
4908 /* username_length Length of username */
4909 /* password Pointer to password */
4910 /* password_length Length of password */
4911 /* tls_setup TLS setup callback function */
4912 /* wait_option Suspension option */
4913 /* */
4914 /* OUTPUT */
4915 /* */
4916 /* status Completion status */
4917 /* */
4918 /* CALLS */
4919 /* */
4920 /* _nx_web_http_client_secure_connect Connect to HTTPS server */
4921 /* _nx_web_http_client_request_initialize_extended */
4922 /* Initialize HTTP request */
4923 /* _nx_web_http_client_request_send Send HTTP request to server */
4924 /* */
4925 /* CALLED BY */
4926 /* */
4927 /* Application Code */
4928 /* */
4929 /* RELEASE HISTORY */
4930 /* */
4931 /* DATE NAME DESCRIPTION */
4932 /* */
4933 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
4934 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
4935 /* resulting in version 6.1 */
4936 /* */
4937 /**************************************************************************/
_nx_web_http_client_head_secure_start_extended(NX_WEB_HTTP_CLIENT * client_ptr,NXD_ADDRESS * server_ip,UINT server_port,CHAR * resource,UINT resource_length,CHAR * host,UINT host_length,CHAR * username,UINT username_length,CHAR * password,UINT password_length,UINT (* tls_setup)(NX_WEB_HTTP_CLIENT * client_ptr,NX_SECURE_TLS_SESSION *),ULONG wait_option)4938 UINT _nx_web_http_client_head_secure_start_extended(NX_WEB_HTTP_CLIENT *client_ptr, NXD_ADDRESS *server_ip, UINT server_port,
4939 CHAR *resource, UINT resource_length, CHAR *host, UINT host_length,
4940 CHAR *username, UINT username_length, CHAR *password,
4941 UINT password_length,
4942 UINT (*tls_setup)(NX_WEB_HTTP_CLIENT *client_ptr, NX_SECURE_TLS_SESSION *),
4943 ULONG wait_option)
4944 {
4945
4946 UINT status;
4947
4948 /* Use default HTTPS port. */
4949 client_ptr->nx_web_http_client_connect_port = server_port;
4950
4951 /* Connect to the server. */
4952 status = _nx_web_http_client_secure_connect(client_ptr, server_ip, client_ptr->nx_web_http_client_connect_port, tls_setup, wait_option);
4953
4954 /* Check status. */
4955 if (status != NX_SUCCESS)
4956 {
4957 return(status);
4958 }
4959
4960 /* Initialize HTTP request. */
4961 status = _nx_web_http_client_request_initialize_extended(client_ptr,
4962 NX_WEB_HTTP_METHOD_HEAD,
4963 resource,
4964 resource_length,
4965 host,
4966 host_length,
4967 0,
4968 NX_FALSE, /* If true, input_size is ignored. */
4969 username,
4970 username_length,
4971 password,
4972 password_length,
4973 wait_option);
4974
4975 /* Check status. */
4976 if (status != NX_SUCCESS)
4977 {
4978 return(status);
4979 }
4980
4981 /* Send the HTTP request we just built. */
4982 status = _nx_web_http_client_request_send(client_ptr, wait_option);
4983
4984 /* Check status. */
4985 if (status != NX_SUCCESS)
4986 {
4987 return(status);
4988 }
4989
4990 /* Enter the HEAD state. */
4991 client_ptr -> nx_web_http_client_state = NX_WEB_HTTP_CLIENT_STATE_HEAD;
4992
4993 return(status);
4994 }
4995
4996 #endif
4997
4998
4999 /**************************************************************************/
5000 /* */
5001 /* FUNCTION RELEASE */
5002 /* */
5003 /* _nxe_web_http_client_delete_start PORTABLE C */
5004 /* 6.1 */
5005 /* AUTHOR */
5006 /* */
5007 /* Yuxin Zhou, Microsoft Corporation */
5008 /* */
5009 /* DESCRIPTION */
5010 /* */
5011 /* This function checks for errors in the call to start a DELETE */
5012 /* request. */
5013 /* */
5014 /* */
5015 /* INPUT */
5016 /* */
5017 /* client_ptr Pointer to HTTP client */
5018 /* server_ip IP address of HTTP Server */
5019 /* resource Pointer to resource (URL) */
5020 /* host Pointer to Host */
5021 /* username Pointer to username */
5022 /* password Pointer to password */
5023 /* wait_option Suspension option */
5024 /* */
5025 /* OUTPUT */
5026 /* */
5027 /* status Completion status */
5028 /* */
5029 /* CALLS */
5030 /* */
5031 /* _nx_web_http_client_delete_start Actual DELETE request call */
5032 /* */
5033 /* CALLED BY */
5034 /* */
5035 /* Application Code */
5036 /* */
5037 /* RELEASE HISTORY */
5038 /* */
5039 /* DATE NAME DESCRIPTION */
5040 /* */
5041 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
5042 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
5043 /* resulting in version 6.1 */
5044 /* */
5045 /**************************************************************************/
_nxe_web_http_client_delete_start(NX_WEB_HTTP_CLIENT * client_ptr,NXD_ADDRESS * server_ip,UINT server_port,CHAR * resource,CHAR * host,CHAR * username,CHAR * password,ULONG wait_option)5046 UINT _nxe_web_http_client_delete_start(NX_WEB_HTTP_CLIENT *client_ptr, NXD_ADDRESS *server_ip, UINT server_port,
5047 CHAR *resource, CHAR *host, CHAR *username, CHAR *password,
5048 ULONG wait_option)
5049 {
5050
5051 UINT status;
5052
5053 /* Check for invalid input pointers. */
5054 if ((client_ptr == NX_NULL) || (client_ptr -> nx_web_http_client_id != NX_WEB_HTTP_CLIENT_ID) ||
5055 (resource == NX_NULL) || !server_ip || (host == NX_NULL))
5056 {
5057 return(NX_PTR_ERROR);
5058 }
5059
5060 /* Check for appropriate caller. */
5061 NX_THREADS_ONLY_CALLER_CHECKING
5062
5063 /* Call actual DELETE start routine. */
5064 status = _nx_web_http_client_delete_start(client_ptr, server_ip, server_port, resource,
5065 host, username, password, wait_option);
5066
5067 /* Return completion status. */
5068 return(status);
5069 }
5070
5071 /**************************************************************************/
5072 /* */
5073 /* FUNCTION RELEASE */
5074 /* */
5075 /* _nx_web_http_client_delete_start PORTABLE C */
5076 /* 6.1 */
5077 /* AUTHOR */
5078 /* */
5079 /* Yuxin Zhou, Microsoft Corporation */
5080 /* */
5081 /* DESCRIPTION */
5082 /* */
5083 /* This function processes an application DELETE request. DELETE only */
5084 /* receives a simple response which can be processed with */
5085 /* nx_web_http_client_response_body_get. */
5086 /* */
5087 /* */
5088 /* INPUT */
5089 /* */
5090 /* client_ptr Pointer to HTTP client */
5091 /* server_ip IP address of HTTP Server */
5092 /* resource Pointer to resource (URL) */
5093 /* host Pointer to Host */
5094 /* username Pointer to username */
5095 /* password Pointer to password */
5096 /* wait_option Suspension option */
5097 /* */
5098 /* OUTPUT */
5099 /* */
5100 /* status Completion status */
5101 /* */
5102 /* CALLS */
5103 /* */
5104 /* _nx_web_http_client_delete_start_extended */
5105 /* Actual DELETE request call */
5106 /* _nx_utility_string_length_check Check string length */
5107 /* */
5108 /* CALLED BY */
5109 /* */
5110 /* Application Code */
5111 /* */
5112 /* RELEASE HISTORY */
5113 /* */
5114 /* DATE NAME DESCRIPTION */
5115 /* */
5116 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
5117 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
5118 /* resulting in version 6.1 */
5119 /* */
5120 /**************************************************************************/
_nx_web_http_client_delete_start(NX_WEB_HTTP_CLIENT * client_ptr,NXD_ADDRESS * server_ip,UINT server_port,CHAR * resource,CHAR * host,CHAR * username,CHAR * password,ULONG wait_option)5121 UINT _nx_web_http_client_delete_start(NX_WEB_HTTP_CLIENT *client_ptr, NXD_ADDRESS *server_ip, UINT server_port, CHAR *resource,
5122 CHAR *host, CHAR *username, CHAR *password, ULONG wait_option)
5123 {
5124 UINT temp_resource_length;
5125 UINT temp_host_length;
5126 UINT temp_username_length = 0;
5127 UINT temp_password_length = 0;
5128
5129 if ((username) && (password))
5130 {
5131
5132 /* Check username and password length. */
5133 if (_nx_utility_string_length_check(username, &temp_username_length, NX_WEB_HTTP_MAX_NAME) ||
5134 _nx_utility_string_length_check(password, &temp_password_length, NX_WEB_HTTP_MAX_PASSWORD))
5135 {
5136 return(NX_WEB_HTTP_ERROR);
5137 }
5138 }
5139
5140 /* Check resource and host length. */
5141 if (_nx_utility_string_length_check(resource, &temp_resource_length, NX_MAX_STRING_LENGTH) ||
5142 _nx_utility_string_length_check(host, &temp_host_length, NX_MAX_STRING_LENGTH))
5143 {
5144 return(NX_WEB_HTTP_ERROR);
5145 }
5146
5147 return(_nx_web_http_client_delete_start_extended(client_ptr, server_ip, server_port, resource,
5148 temp_resource_length, host, temp_host_length, username,
5149 temp_username_length, password, temp_password_length,
5150 wait_option));
5151
5152 }
5153
5154
5155 /**************************************************************************/
5156 /* */
5157 /* FUNCTION RELEASE */
5158 /* */
5159 /* _nxe_web_http_client_delete_start_extended PORTABLE C */
5160 /* 6.1 */
5161 /* AUTHOR */
5162 /* */
5163 /* Yuxin Zhou, Microsoft Corporation */
5164 /* */
5165 /* DESCRIPTION */
5166 /* */
5167 /* This function checks for errors in the call to start a DELETE */
5168 /* request. */
5169 /* */
5170 /* */
5171 /* INPUT */
5172 /* */
5173 /* client_ptr Pointer to HTTP client */
5174 /* server_ip IP duo address of HTTP Server */
5175 /* resource Pointer to resource (URL) */
5176 /* resource_length String length of resource */
5177 /* host Pointer to Host */
5178 /* host_length Length of host */
5179 /* username Pointer to username */
5180 /* username_length Length of username */
5181 /* password Pointer to password */
5182 /* password_length Length of password */
5183 /* wait_option Suspension option */
5184 /* */
5185 /* OUTPUT */
5186 /* */
5187 /* status Completion status */
5188 /* */
5189 /* CALLS */
5190 /* */
5191 /* _nx_web_http_client_delete_start Actual DELETE request call */
5192 /* */
5193 /* CALLED BY */
5194 /* */
5195 /* Application Code */
5196 /* */
5197 /* RELEASE HISTORY */
5198 /* */
5199 /* DATE NAME DESCRIPTION */
5200 /* */
5201 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
5202 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
5203 /* resulting in version 6.1 */
5204 /* */
5205 /**************************************************************************/
_nxe_web_http_client_delete_start_extended(NX_WEB_HTTP_CLIENT * client_ptr,NXD_ADDRESS * server_ip,UINT server_port,CHAR * resource,UINT resource_length,CHAR * host,UINT host_length,CHAR * username,UINT username_length,CHAR * password,UINT password_length,ULONG wait_option)5206 UINT _nxe_web_http_client_delete_start_extended(NX_WEB_HTTP_CLIENT *client_ptr, NXD_ADDRESS *server_ip,
5207 UINT server_port, CHAR *resource, UINT resource_length,
5208 CHAR *host, UINT host_length, CHAR *username,
5209 UINT username_length, CHAR *password,
5210 UINT password_length, ULONG wait_option)
5211 {
5212
5213 UINT status;
5214
5215 /* Check for invalid input pointers. */
5216 if ((client_ptr == NX_NULL) || (client_ptr -> nx_web_http_client_id != NX_WEB_HTTP_CLIENT_ID) ||
5217 (resource == NX_NULL) || !server_ip || (host == NX_NULL))
5218 {
5219 return(NX_PTR_ERROR);
5220 }
5221
5222 /* Check for appropriate caller. */
5223 NX_THREADS_ONLY_CALLER_CHECKING
5224
5225 /* Call actual DELETE start routine. */
5226 status = _nx_web_http_client_delete_start_extended(client_ptr, server_ip, server_port, resource,
5227 resource_length, host, host_length, username,
5228 username_length, password, password_length,
5229 wait_option);
5230
5231 /* Return completion status. */
5232 return(status);
5233 }
5234
5235
5236 /**************************************************************************/
5237 /* */
5238 /* FUNCTION RELEASE */
5239 /* */
5240 /* _nx_web_http_client_delete_start_extended PORTABLE C */
5241 /* 6.1 */
5242 /* AUTHOR */
5243 /* */
5244 /* Yuxin Zhou, Microsoft Corporation */
5245 /* */
5246 /* DESCRIPTION */
5247 /* */
5248 /* This function processes an application DELETE request. DELETE only */
5249 /* receives a simple response which can be processed with */
5250 /* nx_web_http_client_response_body_get. */
5251 /* */
5252 /* Note: The strings of resource, host, username and password must be */
5253 /* NULL-terminated and length of each string matches the length */
5254 /* specified in the argument list. */
5255 /* */
5256 /* */
5257 /* INPUT */
5258 /* */
5259 /* client_ptr Pointer to HTTP client */
5260 /* server_ip HTTP Server IP address */
5261 /* resource Pointer to resource (URL) */
5262 /* resource_length String length of resource */
5263 /* host Pointer to Host */
5264 /* host_length Length of host */
5265 /* username Pointer to username */
5266 /* username_length Length of username */
5267 /* password Pointer to password */
5268 /* password_length Length of password */
5269 /* wait_option Suspension option */
5270 /* */
5271 /* OUTPUT */
5272 /* */
5273 /* status Completion status */
5274 /* */
5275 /* CALLS */
5276 /* */
5277 /* _nx_web_http_client_connect Connect to remote server */
5278 /* _nx_web_http_client_request_initialize_extended */
5279 /* Initialize DELETE request */
5280 /* _nx_web_http_client_content_type_header_add */
5281 /* Add content type header */
5282 /* _nx_web_http_client_request_send Send HTTP request to server */
5283 /* _nx_web_http_client_error_exit Shutdown HTTP(S) connection */
5284 /* */
5285 /* CALLED BY */
5286 /* */
5287 /* Application Code */
5288 /* */
5289 /* RELEASE HISTORY */
5290 /* */
5291 /* DATE NAME DESCRIPTION */
5292 /* */
5293 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
5294 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
5295 /* resulting in version 6.1 */
5296 /* */
5297 /**************************************************************************/
_nx_web_http_client_delete_start_extended(NX_WEB_HTTP_CLIENT * client_ptr,NXD_ADDRESS * server_ip,UINT server_port,CHAR * resource,UINT resource_length,CHAR * host,UINT host_length,CHAR * username,UINT username_length,CHAR * password,UINT password_length,ULONG wait_option)5298 UINT _nx_web_http_client_delete_start_extended(NX_WEB_HTTP_CLIENT *client_ptr, NXD_ADDRESS *server_ip,
5299 UINT server_port, CHAR *resource, UINT resource_length,
5300 CHAR *host, UINT host_length, CHAR *username,
5301 UINT username_length, CHAR *password,
5302 UINT password_length, ULONG wait_option)
5303 {
5304
5305 UINT status;
5306
5307 client_ptr -> nx_web_http_client_connect_port = server_port;
5308
5309 /* Connect to the server. */
5310 status = _nx_web_http_client_connect(client_ptr, server_ip, client_ptr -> nx_web_http_client_connect_port, wait_option);
5311
5312 /* Check status. */
5313 if (status != NX_SUCCESS)
5314 {
5315 return(status);
5316 }
5317
5318 /* Initialize HTTP request. */
5319 status = _nx_web_http_client_request_initialize_extended(client_ptr,
5320 NX_WEB_HTTP_METHOD_DELETE,
5321 resource,
5322 resource_length,
5323 host,
5324 host_length,
5325 0,
5326 NX_FALSE, /* If true, input_size is ignored. */
5327 username,
5328 username_length,
5329 password,
5330 password_length,
5331 wait_option);
5332
5333 /* Check status. */
5334 if (status != NX_SUCCESS)
5335 {
5336 return(status);
5337 }
5338
5339 /* Send the HTTP request we just built. */
5340 status = _nx_web_http_client_request_send(client_ptr, wait_option);
5341
5342 /* Check status. */
5343 if (status != NX_SUCCESS)
5344 {
5345 return(status);
5346 }
5347
5348 /* Enter the DELETE state. */
5349 client_ptr -> nx_web_http_client_state = NX_WEB_HTTP_CLIENT_STATE_DELETE;
5350
5351 return(status);
5352 }
5353
5354 #ifdef NX_WEB_HTTPS_ENABLE
5355 /**************************************************************************/
5356 /* */
5357 /* FUNCTION RELEASE */
5358 /* */
5359 /* _nxe_web_http_client_delete_secure_start PORTABLE C */
5360 /* 6.1 */
5361 /* AUTHOR */
5362 /* */
5363 /* Yuxin Zhou, Microsoft Corporation */
5364 /* */
5365 /* DESCRIPTION */
5366 /* */
5367 /* This function checks for errors in the HTTPS secure DELETE request */
5368 /* processing call. */
5369 /* */
5370 /* */
5371 /* INPUT */
5372 /* */
5373 /* client_ptr Pointer to HTTP client */
5374 /* server_ip HTTP Server IP address */
5375 /* resource Pointer to resource (URL) */
5376 /* host Pointer to Host */
5377 /* username Pointer to username */
5378 /* password Pointer to password */
5379 /* tls_setup TLS setup callback function */
5380 /* wait_option Suspension option */
5381 /* */
5382 /* OUTPUT */
5383 /* */
5384 /* status Completion status */
5385 /* */
5386 /* CALLS */
5387 /* */
5388 /* _nx_web_http_client_delete_secure_start */
5389 /* Actual DELETE request call */
5390 /* */
5391 /* CALLED BY */
5392 /* */
5393 /* Application Code */
5394 /* */
5395 /* RELEASE HISTORY */
5396 /* */
5397 /* DATE NAME DESCRIPTION */
5398 /* */
5399 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
5400 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
5401 /* resulting in version 6.1 */
5402 /* */
5403 /**************************************************************************/
_nxe_web_http_client_delete_secure_start(NX_WEB_HTTP_CLIENT * client_ptr,NXD_ADDRESS * server_ip,UINT server_port,CHAR * resource,CHAR * host,CHAR * username,CHAR * password,UINT (* tls_setup)(NX_WEB_HTTP_CLIENT * client_ptr,NX_SECURE_TLS_SESSION *),ULONG wait_option)5404 UINT _nxe_web_http_client_delete_secure_start(NX_WEB_HTTP_CLIENT *client_ptr, NXD_ADDRESS *server_ip, UINT server_port, CHAR *resource,
5405 CHAR *host, CHAR *username, CHAR *password,
5406 UINT (*tls_setup)(NX_WEB_HTTP_CLIENT *client_ptr, NX_SECURE_TLS_SESSION *),
5407 ULONG wait_option)
5408 {
5409 UINT status;
5410
5411 /* Check for invalid input pointers. */
5412 if ((client_ptr == NX_NULL) || (client_ptr -> nx_web_http_client_id != NX_WEB_HTTP_CLIENT_ID) ||
5413 (resource == NX_NULL) || !server_ip || !tls_setup || (host == NX_NULL))
5414 return(NX_PTR_ERROR);
5415
5416 /* Check for appropriate caller. */
5417 NX_THREADS_ONLY_CALLER_CHECKING
5418
5419 /* Call actual DELETE start routine. */
5420 status = _nx_web_http_client_delete_secure_start(client_ptr, server_ip, server_port, resource,
5421 host, username, password, tls_setup, wait_option);
5422
5423 /* Return completion status. */
5424 return(status);
5425 }
5426
5427
5428
5429 /**************************************************************************/
5430 /* */
5431 /* FUNCTION RELEASE */
5432 /* */
5433 /* _nx_web_http_client_delete_secure_start PORTABLE C */
5434 /* 6.1 */
5435 /* AUTHOR */
5436 /* */
5437 /* Yuxin Zhou, Microsoft Corporation */
5438 /* */
5439 /* DESCRIPTION */
5440 /* */
5441 /* This function processes an application DELETE request. DELETE only */
5442 /* receives a simple response which can be processed with */
5443 /* nx_web_http_client_response_body_get. This version of the function */
5444 /* also requires a TLS setup callback as the request is sent over */
5445 /* TLS-secured HTTPS. */
5446 /* */
5447 /* */
5448 /* INPUT */
5449 /* */
5450 /* client_ptr Pointer to HTTP client */
5451 /* server_ip HTTP Server IP address */
5452 /* resource Pointer to resource (URL) */
5453 /* host Pointer to Host */
5454 /* username Pointer to username */
5455 /* password Pointer to password */
5456 /* tls_setup TLS setup callback function */
5457 /* wait_option Suspension option */
5458 /* */
5459 /* OUTPUT */
5460 /* */
5461 /* status Completion status */
5462 /* */
5463 /* CALLS */
5464 /* */
5465 /* _nx_web_http_client_delete_secure_start_extended */
5466 /* Actual DELETE processing */
5467 /* _nx_utility_string_length_check Check string length */
5468 /* */
5469 /* CALLED BY */
5470 /* */
5471 /* Application Code */
5472 /* */
5473 /* RELEASE HISTORY */
5474 /* */
5475 /* DATE NAME DESCRIPTION */
5476 /* */
5477 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
5478 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
5479 /* resulting in version 6.1 */
5480 /* */
5481 /**************************************************************************/
_nx_web_http_client_delete_secure_start(NX_WEB_HTTP_CLIENT * client_ptr,NXD_ADDRESS * server_ip,UINT server_port,CHAR * resource,CHAR * host,CHAR * username,CHAR * password,UINT (* tls_setup)(NX_WEB_HTTP_CLIENT * client_ptr,NX_SECURE_TLS_SESSION *),ULONG wait_option)5482 UINT _nx_web_http_client_delete_secure_start(NX_WEB_HTTP_CLIENT *client_ptr, NXD_ADDRESS *server_ip, UINT server_port, CHAR *resource,
5483 CHAR *host, CHAR *username, CHAR *password,
5484 UINT (*tls_setup)(NX_WEB_HTTP_CLIENT *client_ptr, NX_SECURE_TLS_SESSION *),
5485 ULONG wait_option)
5486 {
5487 UINT temp_resource_length;
5488 UINT temp_host_length;
5489 UINT temp_username_length = 0;
5490 UINT temp_password_length = 0;
5491
5492 if ((username) && (password))
5493 {
5494
5495 /* Check username and password length. */
5496 if (_nx_utility_string_length_check(username, &temp_username_length, NX_WEB_HTTP_MAX_NAME) ||
5497 _nx_utility_string_length_check(password, &temp_password_length, NX_WEB_HTTP_MAX_PASSWORD))
5498 {
5499 return(NX_WEB_HTTP_ERROR);
5500 }
5501 }
5502
5503 /* Check resource and host length. */
5504 if (_nx_utility_string_length_check(resource, &temp_resource_length, NX_MAX_STRING_LENGTH) ||
5505 _nx_utility_string_length_check(host, &temp_host_length, NX_MAX_STRING_LENGTH))
5506 {
5507 return(NX_WEB_HTTP_ERROR);
5508 }
5509
5510 return(_nx_web_http_client_delete_secure_start_extended(client_ptr, server_ip, server_port,
5511 resource, temp_resource_length, host,
5512 temp_host_length, username,
5513 temp_username_length, password,
5514 temp_password_length, tls_setup,
5515 wait_option));
5516 }
5517
5518
5519 /**************************************************************************/
5520 /* */
5521 /* FUNCTION RELEASE */
5522 /* */
5523 /* _nxe_web_http_client_delete_secure_start_extended PORTABLE C */
5524 /* 6.1 */
5525 /* AUTHOR */
5526 /* */
5527 /* Yuxin Zhou, Microsoft Corporation */
5528 /* */
5529 /* DESCRIPTION */
5530 /* */
5531 /* This function checks for errors in the HTTPS secure DELETE request */
5532 /* processing call. */
5533 /* */
5534 /* */
5535 /* INPUT */
5536 /* */
5537 /* client_ptr Pointer to HTTP client */
5538 /* server_ip IP duo address of HTTP Server */
5539 /* resource Pointer to resource (URL) */
5540 /* resource_length String length of resource */
5541 /* host Pointer to Host */
5542 /* host_length Length of host */
5543 /* username Pointer to username */
5544 /* username_length Length of username */
5545 /* password Pointer to password */
5546 /* password_length Length of password */
5547 /* tls_setup TLS setup callback function */
5548 /* wait_option Suspension option */
5549 /* */
5550 /* OUTPUT */
5551 /* */
5552 /* status Completion status */
5553 /* */
5554 /* CALLS */
5555 /* */
5556 /* _nx_web_http_client_delete_secure_start_extended */
5557 /* Actual DELETE processing */
5558 /* */
5559 /* CALLED BY */
5560 /* */
5561 /* Application Code */
5562 /* */
5563 /* RELEASE HISTORY */
5564 /* */
5565 /* DATE NAME DESCRIPTION */
5566 /* */
5567 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
5568 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
5569 /* resulting in version 6.1 */
5570 /* */
5571 /**************************************************************************/
_nxe_web_http_client_delete_secure_start_extended(NX_WEB_HTTP_CLIENT * client_ptr,NXD_ADDRESS * server_ip,UINT server_port,CHAR * resource,UINT resource_length,CHAR * host,UINT host_length,CHAR * username,UINT username_length,CHAR * password,UINT password_length,UINT (* tls_setup)(NX_WEB_HTTP_CLIENT * client_ptr,NX_SECURE_TLS_SESSION *),ULONG wait_option)5572 UINT _nxe_web_http_client_delete_secure_start_extended(NX_WEB_HTTP_CLIENT *client_ptr, NXD_ADDRESS *server_ip, UINT server_port,
5573 CHAR *resource, UINT resource_length, CHAR *host, UINT host_length,
5574 CHAR *username, UINT username_length, CHAR *password,
5575 UINT password_length,
5576 UINT (*tls_setup)(NX_WEB_HTTP_CLIENT *client_ptr, NX_SECURE_TLS_SESSION *),
5577 ULONG wait_option)
5578 {
5579 UINT status;
5580
5581 /* Check for invalid input pointers. */
5582 if ((client_ptr == NX_NULL) || (client_ptr -> nx_web_http_client_id != NX_WEB_HTTP_CLIENT_ID) ||
5583 (resource == NX_NULL) || !server_ip || !tls_setup || (host == NX_NULL))
5584 return(NX_PTR_ERROR);
5585
5586 /* Check for appropriate caller. */
5587 NX_THREADS_ONLY_CALLER_CHECKING
5588
5589 /* Call actual DELETE start routine. */
5590 status = _nx_web_http_client_delete_secure_start_extended(client_ptr, server_ip, server_port,
5591 resource, resource_length, host,
5592 host_length, username, username_length,
5593 password, password_length,
5594 tls_setup, wait_option);
5595
5596 /* Return completion status. */
5597 return(status);
5598 }
5599
5600
5601 /**************************************************************************/
5602 /* */
5603 /* FUNCTION RELEASE */
5604 /* */
5605 /* _nx_web_http_client_delete_secure_start_extended PORTABLE C */
5606 /* 6.1 */
5607 /* AUTHOR */
5608 /* */
5609 /* Yuxin Zhou, Microsoft Corporation */
5610 /* */
5611 /* DESCRIPTION */
5612 /* */
5613 /* This function processes an application DELETE request. DELETE only */
5614 /* receives a simple response which can be processed with */
5615 /* nx_web_http_client_response_body_get. This version of the function */
5616 /* also requires a TLS setup callback as the request is sent over */
5617 /* TLS-secured HTTPS. */
5618 /* */
5619 /* Note: The strings of resource, host, username and password must be */
5620 /* NULL-terminated and length of each string matches the length */
5621 /* specified in the argument list. */
5622 /* */
5623 /* */
5624 /* INPUT */
5625 /* */
5626 /* client_ptr Pointer to HTTP client */
5627 /* server_ip IP duo address of HTTP Server */
5628 /* resource Pointer to resource (URL) */
5629 /* resource_length String length of resource */
5630 /* host Pointer to Host */
5631 /* host_length Length of host */
5632 /* username Pointer to username */
5633 /* username_length Length of username */
5634 /* password Pointer to password */
5635 /* password_length Length of password */
5636 /* tls_setup TLS setup callback function */
5637 /* wait_option Suspension option */
5638 /* */
5639 /* OUTPUT */
5640 /* */
5641 /* status Completion status */
5642 /* */
5643 /* CALLS */
5644 /* */
5645 /* _nx_web_http_client_secure_connect Connect to HTTPS server */
5646 /* _nx_web_http_client_request_initialize_extended */
5647 /* Initialize HTTP request */
5648 /* _nx_web_http_client_request_send Send HTTP request to server */
5649 /* */
5650 /* CALLED BY */
5651 /* */
5652 /* Application Code */
5653 /* */
5654 /* RELEASE HISTORY */
5655 /* */
5656 /* DATE NAME DESCRIPTION */
5657 /* */
5658 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
5659 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
5660 /* resulting in version 6.1 */
5661 /* */
5662 /**************************************************************************/
_nx_web_http_client_delete_secure_start_extended(NX_WEB_HTTP_CLIENT * client_ptr,NXD_ADDRESS * server_ip,UINT server_port,CHAR * resource,UINT resource_length,CHAR * host,UINT host_length,CHAR * username,UINT username_length,CHAR * password,UINT password_length,UINT (* tls_setup)(NX_WEB_HTTP_CLIENT * client_ptr,NX_SECURE_TLS_SESSION *),ULONG wait_option)5663 UINT _nx_web_http_client_delete_secure_start_extended(NX_WEB_HTTP_CLIENT *client_ptr, NXD_ADDRESS *server_ip, UINT server_port,
5664 CHAR *resource, UINT resource_length, CHAR *host, UINT host_length,
5665 CHAR *username, UINT username_length, CHAR *password,
5666 UINT password_length,
5667 UINT (*tls_setup)(NX_WEB_HTTP_CLIENT *client_ptr, NX_SECURE_TLS_SESSION *),
5668 ULONG wait_option)
5669 {
5670
5671 UINT status;
5672
5673 /* Use default HTTPS port. */
5674 client_ptr->nx_web_http_client_connect_port = server_port;
5675
5676 /* Connect to the server. */
5677 status = _nx_web_http_client_secure_connect(client_ptr, server_ip, client_ptr->nx_web_http_client_connect_port, tls_setup, wait_option);
5678
5679 /* Check status. */
5680 if (status != NX_SUCCESS)
5681 {
5682 return(status);
5683 }
5684
5685 /* Initialize HTTP request. */
5686 status = _nx_web_http_client_request_initialize_extended(client_ptr,
5687 NX_WEB_HTTP_METHOD_DELETE,
5688 resource,
5689 resource_length,
5690 host,
5691 host_length,
5692 0,
5693 NX_FALSE, /* If true, input_size is ignored. */
5694 username,
5695 username_length,
5696 password,
5697 password_length,
5698 wait_option);
5699
5700 /* Check status. */
5701 if (status != NX_SUCCESS)
5702 {
5703 return(status);
5704 }
5705
5706 /* Send the HTTP request we just built. */
5707 status = _nx_web_http_client_request_send(client_ptr, wait_option);
5708
5709 /* Check status. */
5710 if (status != NX_SUCCESS)
5711 {
5712 return(status);
5713 }
5714
5715 /* Enter the DELETE state. */
5716 client_ptr -> nx_web_http_client_state = NX_WEB_HTTP_CLIENT_STATE_DELETE;
5717
5718 return(status);
5719 }
5720
5721 #endif
5722
5723
5724
5725
5726 /**************************************************************************/
5727 /* */
5728 /* FUNCTION RELEASE */
5729 /* */
5730 /* _nxe_web_http_client_put_packet PORTABLE C */
5731 /* 6.1 */
5732 /* AUTHOR */
5733 /* */
5734 /* Yuxin Zhou, Microsoft Corporation */
5735 /* */
5736 /* DESCRIPTION */
5737 /* */
5738 /* This function checks for errors in the HTTP client put packet call. */
5739 /* */
5740 /* */
5741 /* INPUT */
5742 /* */
5743 /* client_ptr Pointer to HTTP client */
5744 /* packet_ptr Resource data packet pointer */
5745 /* wait_option Suspension option */
5746 /* */
5747 /* OUTPUT */
5748 /* */
5749 /* status Completion status */
5750 /* */
5751 /* CALLS */
5752 /* */
5753 /* _nx_web_http_client_put_packet Actual client put packet call */
5754 /* */
5755 /* CALLED BY */
5756 /* */
5757 /* Application Code */
5758 /* */
5759 /* RELEASE HISTORY */
5760 /* */
5761 /* DATE NAME DESCRIPTION */
5762 /* */
5763 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
5764 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
5765 /* resulting in version 6.1 */
5766 /* */
5767 /**************************************************************************/
_nxe_web_http_client_put_packet(NX_WEB_HTTP_CLIENT * client_ptr,NX_PACKET * packet_ptr,ULONG wait_option)5768 UINT _nxe_web_http_client_put_packet(NX_WEB_HTTP_CLIENT *client_ptr, NX_PACKET *packet_ptr, ULONG wait_option)
5769 {
5770
5771 UINT status;
5772 NXD_ADDRESS *server_ip;
5773 UINT header_size;
5774
5775
5776 /* Check for invalid input pointers. */
5777 if ((client_ptr == NX_NULL) || (client_ptr -> nx_web_http_client_id != NX_WEB_HTTP_CLIENT_ID) ||
5778 (packet_ptr == NX_NULL))
5779 return(NX_PTR_ERROR);
5780
5781 /* Check for appropriate caller. */
5782 NX_THREADS_ONLY_CALLER_CHECKING
5783
5784 /* Get worker variables for use. */
5785 server_ip = &(client_ptr -> nx_web_http_client_server_address);
5786
5787 #ifndef NX_DISABLE_IPV4
5788 if (server_ip -> nxd_ip_version == NX_IP_VERSION_V4)
5789 {
5790 header_size = NX_IPv4_TCP_PACKET;
5791 }
5792 else
5793 #endif /* !NX_DISABLE_IPV4 */
5794
5795 #ifdef FEATURE_NX_IPV6
5796 if (server_ip -> nxd_ip_version == NX_IP_VERSION_V6)
5797 {
5798 header_size = NX_IPv6_TCP_PACKET;
5799 }
5800 else
5801 #endif /* FEATURE_NX_IPV6 */
5802 {
5803 return(NX_NOT_CONNECTED);
5804 }
5805
5806 /* Ensure there is enough room for the TCP packet header. */
5807 if ((UINT)(packet_ptr -> nx_packet_prepend_ptr - packet_ptr -> nx_packet_data_start) < header_size)
5808 {
5809
5810 /* Return an invalid packet error. */
5811 return(NX_INVALID_PACKET);
5812 }
5813
5814 /* Call actual PUT data routine. */
5815 status = _nx_web_http_client_put_packet(client_ptr, packet_ptr, wait_option);
5816
5817 /* Return completion status. */
5818 return(status);
5819 }
5820
5821
5822 /**************************************************************************/
5823 /* */
5824 /* FUNCTION RELEASE */
5825 /* */
5826 /* _nx_web_http_client_put_packet PORTABLE C */
5827 /* 6.1.12 */
5828 /* AUTHOR */
5829 /* */
5830 /* Yuxin Zhou, Microsoft Corporation */
5831 /* */
5832 /* DESCRIPTION */
5833 /* */
5834 /* This function processes a packet of resource data associated with */
5835 /* the previous PUT request. */
5836 /* */
5837 /* */
5838 /* INPUT */
5839 /* */
5840 /* client_ptr Pointer to HTTP client */
5841 /* packet_ptr Resource data packet pointer */
5842 /* wait_option Suspension option */
5843 /* */
5844 /* OUTPUT */
5845 /* */
5846 /* status Completion status */
5847 /* */
5848 /* CALLS */
5849 /* */
5850 /* _nx_web_http_client_receive Check for server response */
5851 /* nx_packet_release Release the packet */
5852 /* _nx_web_http_client_error_exit Shutdown connection */
5853 /* _nx_web_http_client_send Send data to server */
5854 /* */
5855 /* CALLED BY */
5856 /* */
5857 /* Application Code */
5858 /* */
5859 /* RELEASE HISTORY */
5860 /* */
5861 /* DATE NAME DESCRIPTION */
5862 /* */
5863 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
5864 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
5865 /* resulting in version 6.1 */
5866 /* 07-29-2022 Yuxin Zhou Modified comment(s), fixed */
5867 /* the invalid release issue, */
5868 /* resulting in version 6.1.12 */
5869 /* */
5870 /**************************************************************************/
_nx_web_http_client_put_packet(NX_WEB_HTTP_CLIENT * client_ptr,NX_PACKET * packet_ptr,ULONG wait_option)5871 UINT _nx_web_http_client_put_packet(NX_WEB_HTTP_CLIENT *client_ptr, NX_PACKET *packet_ptr, ULONG wait_option)
5872 {
5873
5874 NX_PACKET *response_packet_ptr;
5875 CHAR *buffer_ptr;
5876 UINT length;
5877 UINT status;
5878
5879
5880 /* First, check and see if the client instance is still in the PUT state. */
5881 if (client_ptr -> nx_web_http_client_state != NX_WEB_HTTP_CLIENT_STATE_PUT &&
5882 client_ptr -> nx_web_http_client_state != NX_WEB_HTTP_CLIENT_STATE_POST)
5883 {
5884
5885 /* Client not ready, return error. */
5886 return(NX_WEB_HTTP_NOT_READY);
5887 }
5888
5889 /* Next, check and see if there is a response from the Server. */
5890 status = _nx_web_http_client_receive(client_ptr, &response_packet_ptr, NX_NO_WAIT);
5891
5892 /* Check for an early response from the Server. */
5893 if (status == NX_SUCCESS)
5894 {
5895
5896 /* This is an error condition since the Server should not respond until the PUT is complete. */
5897
5898 /* Setup pointer to server response. */
5899 buffer_ptr = (CHAR *) response_packet_ptr -> nx_packet_prepend_ptr;
5900
5901 /* Determine if it is an authentication error. */
5902 if (((buffer_ptr + 11) < (CHAR *)response_packet_ptr -> nx_packet_append_ptr) &&
5903 (buffer_ptr[9] == '4') && (buffer_ptr[10] == '0') && (buffer_ptr[11] == '1'))
5904 {
5905
5906 /* Inform caller of an authentication error. */
5907 status = NX_WEB_HTTP_AUTHENTICATION_ERROR;
5908 }
5909 else
5910 {
5911
5912 /* Inform caller of general Server failure. */
5913 status = NX_WEB_HTTP_INCOMPLETE_PUT_ERROR;
5914 }
5915
5916 /* Release the packet. */
5917 nx_packet_release(response_packet_ptr);
5918
5919 /* Disconnect and unbind the socket. */
5920 _nx_web_http_client_error_exit(client_ptr, wait_option);
5921
5922 /* Return to the READY state. */
5923 client_ptr -> nx_web_http_client_state = NX_WEB_HTTP_CLIENT_STATE_READY;
5924
5925 /* Return error to caller. */
5926 return(status);
5927 }
5928
5929 /* Otherwise, determine if the packet length fits in the available bytes to send. */
5930 if (packet_ptr -> nx_packet_length >
5931 (client_ptr -> nx_web_http_client_total_transfer_bytes - client_ptr -> nx_web_http_client_actual_bytes_transferred))
5932 {
5933
5934 /* Request doesn't fit into the remaining transfer window. */
5935 return(NX_WEB_HTTP_BAD_PACKET_LENGTH);
5936 }
5937
5938 /* Remember the packet length. */
5939 length = packet_ptr -> nx_packet_length;
5940
5941 /* Now send the packet out. */
5942 status = _nx_web_http_client_send(client_ptr, packet_ptr, wait_option);
5943
5944 /* Determine if the send was successful. */
5945 if (status != NX_SUCCESS)
5946 {
5947
5948 /* No, send was not successful. */
5949
5950 /* Disconnect and unbind the socket. */
5951 _nx_web_http_client_error_exit(client_ptr, wait_option);
5952
5953 /* Return to the READY state. */
5954 client_ptr -> nx_web_http_client_state = NX_WEB_HTTP_CLIENT_STATE_READY;
5955
5956 /* Return an error. */
5957 return(status);
5958 }
5959
5960 /* Otherwise, update the actual bytes transferred. */
5961 client_ptr -> nx_web_http_client_actual_bytes_transferred = client_ptr -> nx_web_http_client_actual_bytes_transferred + length;
5962
5963 /* Return status to caller. */
5964 return(NX_SUCCESS);
5965 }
5966
5967
5968 /**************************************************************************/
5969 /* */
5970 /* FUNCTION RELEASE */
5971 /* */
5972 /* _nx_web_http_client_type_get PORTABLE C */
5973 /* 6.1 */
5974 /* AUTHOR */
5975 /* */
5976 /* Yuxin Zhou, Microsoft Corporation */
5977 /* */
5978 /* DESCRIPTION */
5979 /* */
5980 /* This function derives the type of the resource. */
5981 /* */
5982 /* INPUT */
5983 /* */
5984 /* name Name string */
5985 /* http_type_string Destination HTTP type string */
5986 /* */
5987 /* OUTPUT */
5988 /* */
5989 /* Size Number of bytes in string */
5990 /* */
5991 /* CALLS */
5992 /* */
5993 /* None */
5994 /* */
5995 /* CALLED BY */
5996 /* */
5997 /* _nx_web_http_client_put_start Start the PUT process */
5998 /* */
5999 /* RELEASE HISTORY */
6000 /* */
6001 /* DATE NAME DESCRIPTION */
6002 /* */
6003 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
6004 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
6005 /* resulting in version 6.1 */
6006 /* */
6007 /**************************************************************************/
_nx_web_http_client_type_get(CHAR * name,CHAR * http_type_string)6008 UINT _nx_web_http_client_type_get(CHAR *name, CHAR *http_type_string)
6009 {
6010
6011 UINT i;
6012
6013
6014 /* First find the end of the string. */
6015 i = 0;
6016 while (name[i] != (CHAR) NX_NULL)
6017 {
6018 i++;
6019 }
6020
6021 /* Now look backwards to find the last period that signals the
6022 file extension. */
6023 while ((i) && (name[i] != '.'))
6024 {
6025 i--;
6026 }
6027
6028 /* Position forward again, past the period. */
6029 i++;
6030
6031 /* Now see what HTTP file type to return. */
6032
6033 /* Check for .txt file extension. */
6034 if (((name[i] == 't') || (name[i] == 'T')) &&
6035 ((name[i+1] == 'x') || (name[i+1] == 'X')) &&
6036 ((name[i+2] == 't') || (name[i+2] == 'T')))
6037 {
6038
6039 /* Yes, we have a plain text file. */
6040 http_type_string[0] = 't';
6041 http_type_string[1] = 'e';
6042 http_type_string[2] = 'x';
6043 http_type_string[3] = 't';
6044 http_type_string[4] = '/';
6045 http_type_string[5] = 'p';
6046 http_type_string[6] = 'l';
6047 http_type_string[7] = 'a';
6048 http_type_string[8] = 'i';
6049 http_type_string[9] = 'n';
6050
6051 /* Return the size of the HTTP ASCII type string. */
6052 return(10);
6053 }
6054
6055 /* Check for .htm[l] file extension. */
6056 else if (((name[i] == 'h') || (name[i] == 'H')) &&
6057 ((name[i+1] == 't') || (name[i+1] == 'T')) &&
6058 ((name[i+2] == 'm') || (name[i+2] == 'M')))
6059 {
6060
6061 /* Yes, we have an HTML text file. */
6062 http_type_string[0] = 't';
6063 http_type_string[1] = 'e';
6064 http_type_string[2] = 'x';
6065 http_type_string[3] = 't';
6066 http_type_string[4] = '/';
6067 http_type_string[5] = 'h';
6068 http_type_string[6] = 't';
6069 http_type_string[7] = 'm';
6070 http_type_string[8] = 'l';
6071
6072 /* Return the size of the HTTP ASCII type string. */
6073 return(9);
6074 }
6075
6076 /* Check for .gif file extension. */
6077 else if (((name[i] == 'g') || (name[i] == 'G')) &&
6078 ((name[i+1] == 'i') || (name[i+1] == 'I')) &&
6079 ((name[i+2] == 'f') || (name[i+2] == 'F')))
6080 {
6081
6082 /* Yes, we have a GIF image file. */
6083 http_type_string[0] = 'i';
6084 http_type_string[1] = 'm';
6085 http_type_string[2] = 'a';
6086 http_type_string[3] = 'g';
6087 http_type_string[4] = 'e';
6088 http_type_string[5] = '/';
6089 http_type_string[6] = 'g';
6090 http_type_string[7] = 'i';
6091 http_type_string[8] = 'f';
6092
6093 /* Return the size of the HTTP ASCII type string. */
6094 return(9);
6095 }
6096
6097 /* Check for .xbm file extension. */
6098 else if (((name[i] == 'x') || (name[i] == 'X')) &&
6099 ((name[i+1] == 'b') || (name[i+1] == 'B')) &&
6100 ((name[i+2] == 'm') || (name[i+2] == 'M')))
6101 {
6102
6103 /* Yes, we have a x-xbitmap image file. */
6104 http_type_string[0] = 'i';
6105 http_type_string[1] = 'm';
6106 http_type_string[2] = 'a';
6107 http_type_string[3] = 'g';
6108 http_type_string[4] = 'e';
6109 http_type_string[5] = '/';
6110 http_type_string[6] = 'x';
6111 http_type_string[7] = '-';
6112 http_type_string[8] = 'x';
6113 http_type_string[9] = 'b';
6114 http_type_string[10] = 'i';
6115 http_type_string[11] = 't';
6116 http_type_string[12] = 'm';
6117 http_type_string[13] = 'a';
6118 http_type_string[14] = 'p';
6119
6120 /* Return the size of the HTTP ASCII type string. */
6121 return(15);
6122 }
6123
6124 /* Default to plain text. */
6125 else
6126 {
6127
6128 /* Default to plain text. */
6129 http_type_string[0] = 't';
6130 http_type_string[1] = 'e';
6131 http_type_string[2] = 'x';
6132 http_type_string[3] = 't';
6133 http_type_string[4] = '/';
6134 http_type_string[5] = 'p';
6135 http_type_string[6] = 'l';
6136 http_type_string[7] = 'a';
6137 http_type_string[8] = 'i';
6138 http_type_string[9] = 'n';
6139
6140 /* Return the size of the HTTP ASCII type string. */
6141 return(10);
6142 }
6143 }
6144
6145
6146 /**************************************************************************/
6147 /* */
6148 /* FUNCTION RELEASE */
6149 /* */
6150 /* _nx_web_http_client_content_length_get PORTABLE C */
6151 /* 6.1 */
6152 /* AUTHOR */
6153 /* */
6154 /* Yuxin Zhou, Microsoft Corporation */
6155 /* */
6156 /* DESCRIPTION */
6157 /* */
6158 /* This function returns the content length of the supplied HTTP */
6159 /* response packet. If the packet is no content or the packet is */
6160 /* invalid, a zero is returned. */
6161 /* */
6162 /* */
6163 /* INPUT */
6164 /* */
6165 /* packet_ptr Pointer to HTTP request packet*/
6166 /* */
6167 /* OUTPUT */
6168 /* */
6169 /* client_ptr HTTP client control block */
6170 /* length Length of content */
6171 /* */
6172 /* CALLS */
6173 /* */
6174 /* None */
6175 /* */
6176 /* CALLED BY */
6177 /* */
6178 /* _nx_web_http_client_get_start Start the GET operation */
6179 /* */
6180 /* RELEASE HISTORY */
6181 /* */
6182 /* DATE NAME DESCRIPTION */
6183 /* */
6184 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
6185 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
6186 /* resulting in version 6.1 */
6187 /* */
6188 /**************************************************************************/
_nx_web_http_client_content_length_get(NX_WEB_HTTP_CLIENT * client_ptr,NX_PACKET * packet_ptr)6189 UINT _nx_web_http_client_content_length_get(NX_WEB_HTTP_CLIENT *client_ptr, NX_PACKET *packet_ptr)
6190 {
6191
6192 UINT length;
6193 CHAR *buffer_ptr;
6194 UINT found = NX_FALSE;
6195
6196
6197 NX_PARAMETER_NOT_USED(client_ptr);
6198
6199 /* Default the content length to an invalid value. */
6200 length = 0;
6201
6202 /* Setup pointer to buffer. */
6203 buffer_ptr = (CHAR *)packet_ptr -> nx_packet_prepend_ptr;
6204
6205 /* Find the "Content-length:" token first. */
6206 while ((buffer_ptr+14) < (CHAR *)packet_ptr -> nx_packet_append_ptr)
6207 {
6208
6209 /* Check for the Content-length token. */
6210 if (((*buffer_ptr == 'c') || (*buffer_ptr == 'C')) &&
6211 ((*(buffer_ptr+1) == 'o') || (*(buffer_ptr+1) == 'O')) &&
6212 ((*(buffer_ptr+2) == 'n') || (*(buffer_ptr+2) == 'N')) &&
6213 ((*(buffer_ptr+3) == 't') || (*(buffer_ptr+3) == 'T')) &&
6214 ((*(buffer_ptr+4) == 'e') || (*(buffer_ptr+4) == 'E')) &&
6215 ((*(buffer_ptr+5) == 'n') || (*(buffer_ptr+5) == 'N')) &&
6216 ((*(buffer_ptr+6) == 't') || (*(buffer_ptr+6) == 'T')) &&
6217 (*(buffer_ptr+7) == '-') &&
6218 ((*(buffer_ptr+8) == 'l') || (*(buffer_ptr+8) == 'L')) &&
6219 ((*(buffer_ptr+9) == 'e') || (*(buffer_ptr+9) == 'E')) &&
6220 ((*(buffer_ptr+10) == 'n') || (*(buffer_ptr+10) == 'N')) &&
6221 ((*(buffer_ptr+11) == 'g') || (*(buffer_ptr+11) == 'G')) &&
6222 ((*(buffer_ptr+12) == 't') || (*(buffer_ptr+12) == 'T')) &&
6223 ((*(buffer_ptr+13) == 'h') || (*(buffer_ptr+13) == 'H')) &&
6224 (*(buffer_ptr+14) == ':'))
6225 {
6226
6227 /* Yes, found content-length token. */
6228 found = NX_TRUE;
6229
6230 /* Move past the Content-Length: field. Exit the loop. */
6231 buffer_ptr += 15;
6232 break;
6233 }
6234
6235 /* Move the pointer up to the next character. */
6236 buffer_ptr++;
6237 }
6238
6239 /* Check if found the content-length token. */
6240 if (found != NX_TRUE)
6241 {
6242
6243 /* No, return an invalid length indicating a bad HTTP packet. */
6244 return(length);
6245 }
6246
6247 /* Now skip over white space. */
6248 while ((buffer_ptr < (CHAR *)packet_ptr -> nx_packet_append_ptr) && (*buffer_ptr == ' '))
6249 {
6250 buffer_ptr++;
6251 }
6252
6253 /* Now convert the length into a numeric value. */
6254 while ((buffer_ptr < (CHAR *)packet_ptr -> nx_packet_append_ptr) && (*buffer_ptr >= '0') && (*buffer_ptr <= '9'))
6255 {
6256
6257 /* Update the content length. */
6258 length = length * 10;
6259 length = length + (((UINT) (*buffer_ptr)) - 0x30);
6260
6261 /* Move the buffer pointer forward. */
6262 buffer_ptr++;
6263 }
6264
6265 /* Determine if the content length was picked up properly. */
6266 if ((buffer_ptr >= (CHAR *)packet_ptr -> nx_packet_append_ptr) ||
6267 ((*buffer_ptr != ' ') && (*buffer_ptr != (CHAR)13)))
6268 {
6269
6270 /* Error, set the length to zero. */
6271 length = 0;
6272 }
6273
6274 /* Return the length to the caller. */
6275 return(length);
6276 }
6277
6278
6279 /**************************************************************************/
6280 /* */
6281 /* FUNCTION RELEASE */
6282 /* */
6283 /* _nx_web_http_client_memicmp PORTABLE C */
6284 /* 6.1 */
6285 /* AUTHOR */
6286 /* */
6287 /* Yuxin Zhou, Microsoft Corporation */
6288 /* */
6289 /* DESCRIPTION */
6290 /* */
6291 /* This function compares two pieces of memory case insensitive. */
6292 /* */
6293 /* INPUT */
6294 /* */
6295 /* src Pointer to source */
6296 /* src_length Length of source */
6297 /* dest Pointer to destination */
6298 /* dest_length Length of destination */
6299 /* */
6300 /* OUTPUT */
6301 /* */
6302 /* status Completion status */
6303 /* */
6304 /* CALLS */
6305 /* */
6306 /* None */
6307 /* */
6308 /* CALLED BY */
6309 /* */
6310 /* _nx_web_http_client_process_header_fields */
6311 /* */
6312 /* RELEASE HISTORY */
6313 /* */
6314 /* DATE NAME DESCRIPTION */
6315 /* */
6316 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
6317 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
6318 /* resulting in version 6.1 */
6319 /* */
6320 /**************************************************************************/
_nx_web_http_client_memicmp(UCHAR * src,ULONG src_length,UCHAR * dest,ULONG dest_length)6321 UINT _nx_web_http_client_memicmp(UCHAR *src, ULONG src_length, UCHAR *dest, ULONG dest_length)
6322 {
6323 UCHAR ch;
6324
6325 /* Compare the length. */
6326 if(src_length != dest_length)
6327 return NX_WEB_HTTP_FAILED;
6328
6329 while(src_length)
6330 {
6331
6332 /* Is src lowercase? */
6333 if((*src >= 'a') && (*src <= 'z'))
6334 ch = (UCHAR)(*src - 'a' + 'A');
6335
6336 /* Is src uppercase? */
6337 else if((*src >= 'A') && (*src <= 'Z'))
6338 ch = (UCHAR)(*src - 'A' + 'a');
6339 else
6340 ch = *src;
6341
6342 /* Compare case insensitive. */
6343 if((*src != *dest) && (ch != *dest))
6344 return NX_WEB_HTTP_FAILED;
6345
6346 /* Pickup next character. */
6347 src_length--;
6348 src++;
6349 dest++;
6350 }
6351
6352 return NX_SUCCESS;
6353 }
6354
6355 /**************************************************************************/
6356 /* */
6357 /* FUNCTION RELEASE */
6358 /* */
6359 /* _nx_web_http_client_process_header_fields PORTABLE C */
6360 /* 6.1 */
6361 /* AUTHOR */
6362 /* */
6363 /* Yuxin Zhou, Microsoft Corporation */
6364 /* */
6365 /* DESCRIPTION */
6366 /* */
6367 /* This function processes the HTTP headers received from the remote */
6368 /* server. It also calculates the byte offset to the start of the */
6369 /* HTTP response content area. This area immediately follows the HTTP */
6370 /* response header (which ends with a blank line). */
6371 /* */
6372 /* */
6373 /* INPUT */
6374 /* */
6375 /* packet_ptr Pointer to request packet */
6376 /* */
6377 /* OUTPUT */
6378 /* */
6379 /* Byte Offset (0 implies no content) */
6380 /* */
6381 /* CALLS */
6382 /* */
6383 /* _nx_web_http_client_memicmp Compile two strings */
6384 /* [nx_web_http_client_response_callback] */
6385 /* Application header callback */
6386 /* */
6387 /* CALLED BY */
6388 /* */
6389 /* _nx_web_http_client_get_start Start GET processing */
6390 /* */
6391 /* RELEASE HISTORY */
6392 /* */
6393 /* DATE NAME DESCRIPTION */
6394 /* */
6395 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
6396 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
6397 /* resulting in version 6.1 */
6398 /* */
6399 /**************************************************************************/
_nx_web_http_client_process_header_fields(NX_WEB_HTTP_CLIENT * client_ptr,NX_PACKET * packet_ptr)6400 UINT _nx_web_http_client_process_header_fields(NX_WEB_HTTP_CLIENT *client_ptr, NX_PACKET *packet_ptr)
6401 {
6402
6403 UINT offset;
6404 CHAR *buffer_ptr;
6405 CHAR *field_name;
6406 UINT field_name_length;
6407 CHAR *field_value;
6408 UINT field_value_length;
6409 #ifndef NX_WEB_HTTP_KEEPALIVE_DISABLE
6410 UINT version = 0;
6411 #endif /* NX_WEB_HTTP_KEEPALIVE_DISABLE */
6412
6413
6414 /* Default the content offset to zero. */
6415 offset = 0;
6416 client_ptr -> nx_web_http_client_response_chunked = NX_FALSE;
6417
6418 /* Setup pointer to buffer. */
6419 buffer_ptr = (CHAR *) packet_ptr -> nx_packet_prepend_ptr;
6420
6421 #ifndef NX_WEB_HTTP_KEEPALIVE_DISABLE
6422 if ((buffer_ptr + 7) < (CHAR *) packet_ptr -> nx_packet_append_ptr)
6423 {
6424 version = (UCHAR)((buffer_ptr[5] - '0') << 4) | (UCHAR)(buffer_ptr[7] - '0');
6425 }
6426
6427 /* Is a valid HTTP version found? */
6428 if(version == 0)
6429 {
6430 client_ptr -> nx_web_http_client_keep_alive = NX_FALSE;
6431 return 0;
6432 }
6433
6434 /* Initialize the keepalive flag. */
6435 if(version > 0x10)
6436 client_ptr -> nx_web_http_client_keep_alive = NX_TRUE;
6437 else
6438 client_ptr -> nx_web_http_client_keep_alive = NX_FALSE;
6439 #endif /* NX_WEB_HTTP_KEEPALIVE_DISABLE */
6440
6441 /* Skip over the first HTTP line (e.g. HTTP/1.1 200 OK). */
6442 while(((buffer_ptr+1) < (CHAR *) packet_ptr -> nx_packet_append_ptr) && (*buffer_ptr != (CHAR) 13) && (*(buffer_ptr + 1) != (CHAR) 10))
6443 {
6444 buffer_ptr++;
6445 offset++;
6446 }
6447
6448 /* Skip over the CR,LF. */
6449 buffer_ptr += 2;
6450 offset += 2;
6451
6452 /* Loop until we find the "cr,lf,cr,lf" token. */
6453 while (((buffer_ptr+1) < (CHAR *) packet_ptr -> nx_packet_append_ptr) && (*buffer_ptr != (CHAR) 0))
6454 {
6455
6456 /* Check for the <cr,lf,cr,lf> token. This signals a blank line, which also
6457 specifies the start of the content. */
6458 if ((*buffer_ptr == (CHAR) 13) &&
6459 (*(buffer_ptr+1) == (CHAR) 10))
6460 {
6461
6462 /* Adjust the offset. */
6463 offset = offset + 2;
6464 break;
6465 }
6466
6467
6468 /* We haven't seen the <cr,lf,cr,lf> so we are still processing header data.
6469 * Extract the field name and it's value.
6470 */
6471 field_name = buffer_ptr;
6472 field_name_length = 0;
6473
6474 /* Look for the ':' that separates the field name from its value. */
6475 while(*buffer_ptr != ':')
6476 {
6477 buffer_ptr++;
6478 field_name_length++;
6479 }
6480 offset += field_name_length;
6481
6482 /* Skip ':'. */
6483 buffer_ptr++;
6484 offset++;
6485
6486 /* Now skip over white space. */
6487 while ((buffer_ptr < (CHAR *)packet_ptr -> nx_packet_append_ptr) && (*buffer_ptr == ' '))
6488 {
6489 buffer_ptr++;
6490 offset++;
6491 }
6492
6493 /* Now get the field value. */
6494 field_value = buffer_ptr;
6495 field_value_length = 0;
6496
6497 /* Loop until we see a <CR, LF>. */
6498 while(((buffer_ptr+1) < (CHAR *) packet_ptr -> nx_packet_append_ptr) && (*buffer_ptr != (CHAR) 13) && (*(buffer_ptr+1) != (CHAR) 10))
6499 {
6500 buffer_ptr++;
6501 field_value_length++;
6502 }
6503 offset += field_value_length;
6504
6505 /* Skip over the CR,LF. */
6506 buffer_ptr += 2;
6507 offset += 2;
6508
6509 /* Check if the response packet is chunked. */
6510 if (_nx_web_http_client_memicmp((UCHAR *)field_name, field_name_length, (UCHAR *)"Transfer-Encoding", 17) == 0)
6511 {
6512 if (_nx_web_http_client_memicmp((UCHAR *)field_value, field_value_length, (UCHAR *)"chunked", 7) == 0)
6513 {
6514 client_ptr -> nx_web_http_client_response_chunked = NX_TRUE;
6515 }
6516 }
6517
6518 #ifndef NX_WEB_HTTP_KEEPALIVE_DISABLE
6519
6520 /* If the "connection" field exist, and the value is "keep-alive", set the keep-alive flag to TRUE. */
6521 if (_nx_web_http_client_memicmp((UCHAR *)"connection", 10, (UCHAR *)field_name, field_name_length) == NX_SUCCESS)
6522 {
6523 if (_nx_web_http_client_memicmp((UCHAR *)"keep-alive", 10, (UCHAR *)field_value, field_value_length) == NX_SUCCESS)
6524 {
6525 client_ptr -> nx_web_http_client_keep_alive = NX_TRUE;
6526 }
6527 else if (_nx_web_http_client_memicmp((UCHAR *)"close", 5, (UCHAR *)field_value, field_value_length) == NX_SUCCESS)
6528 {
6529 client_ptr -> nx_web_http_client_keep_alive = NX_FALSE;
6530 }
6531 }
6532 #endif /* NX_WEB_HTTP_KEEPALIVE_DISABLE */
6533
6534 /* Invoke the header callback if present. */
6535 /* If it was set, invoke the application response callback. */
6536 if(client_ptr -> nx_web_http_client_response_callback)
6537 {
6538 client_ptr -> nx_web_http_client_response_callback(client_ptr, field_name, field_name_length, field_value, field_value_length);
6539 }
6540 }
6541
6542 /* Not find the "cr,lf,cr,lf" token. */
6543 if (((buffer_ptr+1) >= (CHAR *) packet_ptr -> nx_packet_append_ptr) || (*buffer_ptr == (CHAR) 0))
6544 {
6545 offset = 0;
6546 }
6547
6548 /* Return the offset to the caller. */
6549 return(offset);
6550 }
6551
6552
6553 /**************************************************************************/
6554 /* */
6555 /* FUNCTION RELEASE */
6556 /* */
6557 /* _nx_web_http_client_number_convert PORTABLE C */
6558 /* 6.1 */
6559 /* AUTHOR */
6560 /* */
6561 /* Yuxin Zhou, Microsoft Corporation */
6562 /* */
6563 /* DESCRIPTION */
6564 /* */
6565 /* This function converts a number into an ASCII string. */
6566 /* */
6567 /* INPUT */
6568 /* */
6569 /* number Unsigned integer number */
6570 /* string Destination string */
6571 /* */
6572 /* OUTPUT */
6573 /* */
6574 /* Size Number of bytes in string */
6575 /* (0 implies an error) */
6576 /* */
6577 /* CALLS */
6578 /* */
6579 /* None */
6580 /* */
6581 /* CALLED BY */
6582 /* */
6583 /* _nx_web_http_client_get_start Start GET processing */
6584 /* _nx_web_http_client_put_start Start PUT processing */
6585 /* */
6586 /* RELEASE HISTORY */
6587 /* */
6588 /* DATE NAME DESCRIPTION */
6589 /* */
6590 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
6591 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
6592 /* resulting in version 6.1 */
6593 /* */
6594 /**************************************************************************/
_nx_web_http_client_number_convert(UINT number,CHAR * string)6595 UINT _nx_web_http_client_number_convert(UINT number, CHAR *string)
6596 {
6597
6598 UINT j;
6599 UINT digit;
6600 UINT size;
6601
6602
6603 /* Default string to return '0'. */
6604 string[0] = '0';
6605
6606 /* Initialize counters. */
6607 size = 0;
6608
6609 /* Loop to convert the number to ASCII. */
6610 while ((size < 10) && (number))
6611 {
6612
6613 /* Shift the current digits over one. */
6614 for (j = size; j != 0; j--)
6615 {
6616
6617 /* Move each digit over one place. */
6618 string[j] = string[j-1];
6619 }
6620
6621 /* Compute the next decimal digit. */
6622 digit = number % 10;
6623
6624 /* Update the input number. */
6625 number = number / 10;
6626
6627 /* Store the new digit in ASCII form. */
6628 string[0] = (CHAR) (digit + 0x30);
6629
6630 /* Increment the size. */
6631 size++;
6632 }
6633
6634 /* Make the string NULL terminated. */
6635 string[size] = (CHAR) NX_NULL;
6636
6637 /* Determine if there is an overflow error. */
6638 if (number)
6639 {
6640
6641 /* Error, return bad values to user. */
6642 size = 0;
6643 string[0] = '0';
6644 }
6645
6646 /* Return size to caller. */
6647 return(size);
6648 }
6649
6650 /**************************************************************************/
6651 /* */
6652 /* FUNCTION RELEASE */
6653 /* */
6654 /* _nxe_web_https_client_connect PORTABLE C */
6655 /* 6.1 */
6656 /* AUTHOR */
6657 /* */
6658 /* Yuxin Zhou, Microsoft Corporation */
6659 /* */
6660 /* DESCRIPTION */
6661 /* */
6662 /* This function checks for errors in the call to connect the HTTP */
6663 /* client to a remote HTTP server. */
6664 /* */
6665 /* */
6666 /* INPUT */
6667 /* */
6668 /* client_ptr Pointer to HTTP client */
6669 /* server_ip Address of remote server */
6670 /* server_port HTTPS port on remote server */
6671 /* wait_option Suspension option */
6672 /* */
6673 /* OUTPUT */
6674 /* */
6675 /* status Completion status */
6676 /* */
6677 /* CALLS */
6678 /* */
6679 /* _nx_web_http_client_connect Actual HTTP connect call */
6680 /* */
6681 /* CALLED BY */
6682 /* */
6683 /* Application Code */
6684 /* */
6685 /* RELEASE HISTORY */
6686 /* */
6687 /* DATE NAME DESCRIPTION */
6688 /* */
6689 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
6690 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
6691 /* resulting in version 6.1 */
6692 /* */
6693 /**************************************************************************/
_nxe_web_http_client_connect(NX_WEB_HTTP_CLIENT * client_ptr,NXD_ADDRESS * server_ip,UINT server_port,ULONG wait_option)6694 UINT _nxe_web_http_client_connect(NX_WEB_HTTP_CLIENT *client_ptr, NXD_ADDRESS *server_ip, UINT server_port, ULONG wait_option)
6695
6696 {
6697 UINT status;
6698
6699 /* Check pointers. */
6700 if(client_ptr == NX_NULL || server_ip == NX_NULL)
6701 {
6702 return(NX_PTR_ERROR);
6703 }
6704
6705 /* Call actual function. */
6706 status = _nx_web_http_client_connect(client_ptr, server_ip, server_port, wait_option);
6707
6708 return(status);
6709 }
6710
6711 /**************************************************************************/
6712 /* */
6713 /* FUNCTION RELEASE */
6714 /* */
6715 /* _nx_web_https_client_connect PORTABLE C */
6716 /* 6.1.5 */
6717 /* AUTHOR */
6718 /* */
6719 /* Yuxin Zhou, Microsoft Corporation */
6720 /* */
6721 /* DESCRIPTION */
6722 /* */
6723 /* This function connects a HTTP client on the specified IP. The TCP */
6724 /* socket is left open following this call, allowing multiple */
6725 /* operations (e.g. GET, PUT, etc.) on this client instance before */
6726 /* closing the HTTP connection. */
6727 /* */
6728 /* Note that multiple operations implies that the HTTP keepalive */
6729 /* header is present and supported by the remote host. Performing a */
6730 /* single operation and then disconnecting the socket is equivalent to */
6731 /* a standard non-keepalive HTTP session. */
6732 /* */
6733 /* */
6734 /* INPUT */
6735 /* */
6736 /* client_ptr Pointer to HTTP client */
6737 /* server_ip Address of remote server */
6738 /* server_port HTTPS port on remote server */
6739 /* wait_option Suspension option */
6740 /* */
6741 /* OUTPUT */
6742 /* */
6743 /* status Completion status */
6744 /* */
6745 /* CALLS */
6746 /* */
6747 /* _nx_web_http_client_cleanup Rest the state */
6748 /* nx_tcp_client_socket_bind Bind TCP client socket */
6749 /* nxd_tcp_client_socket_connect Connect to remote server */
6750 /* nx_tcp_client_socket_unbind Unbind socket on error */
6751 /* */
6752 /* CALLED BY */
6753 /* */
6754 /* Application Code */
6755 /* */
6756 /* RELEASE HISTORY */
6757 /* */
6758 /* DATE NAME DESCRIPTION */
6759 /* */
6760 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
6761 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
6762 /* resulting in version 6.1 */
6763 /* 03-02-2021 Yuxin Zhou Modified comment(s), */
6764 /* supported non-blocking mode,*/
6765 /* resulting in version 6.1.5 */
6766 /* */
6767 /**************************************************************************/
_nx_web_http_client_connect(NX_WEB_HTTP_CLIENT * client_ptr,NXD_ADDRESS * server_ip,UINT server_port,ULONG wait_option)6768 UINT _nx_web_http_client_connect(NX_WEB_HTTP_CLIENT *client_ptr, NXD_ADDRESS *server_ip, UINT server_port, ULONG wait_option)
6769
6770 {
6771
6772 UINT status;
6773
6774 #ifndef NX_WEB_HTTP_KEEPALIVE_DISABLE
6775
6776 /* If keep-alive is true, the client is already connected to the server. */
6777 if (client_ptr -> nx_web_http_client_keep_alive)
6778 {
6779
6780 /* Clean up and reset the state. */
6781 _nx_web_http_client_cleanup(client_ptr);
6782
6783 if (nx_tcp_socket_state_wait(&(client_ptr -> nx_web_http_client_socket), NX_TCP_ESTABLISHED, 0) == NX_SUCCESS)
6784 {
6785
6786 /* No need to reconnect. */
6787 return(NX_SUCCESS);
6788 }
6789 else
6790 {
6791
6792 /* Server disconnected the connection, need to reconnect. */
6793 _nx_web_http_client_error_exit(client_ptr, wait_option);
6794 }
6795 }
6796 #endif /* NX_WEB_HTTP_KEEPALIVE_DISABLE */
6797
6798 /* Determine if the client is in a ready state. */
6799 if (client_ptr -> nx_web_http_client_state != NX_WEB_HTTP_CLIENT_STATE_READY)
6800 {
6801
6802 /* Reset the state. */
6803 _nx_web_http_client_cleanup(client_ptr);
6804 }
6805
6806 /* Attempt to bind the client socket. */
6807 status = nx_tcp_client_socket_bind(&(client_ptr -> nx_web_http_client_socket), NX_ANY_PORT, wait_option);
6808
6809 /* Check status of the bind. */
6810 if ((status != NX_SUCCESS) && (status != NX_ALREADY_BOUND))
6811 {
6812
6813 /* Error binding to a port, return to caller. */
6814 return(status);
6815 }
6816
6817 /* Set the server IP and port. */
6818 #ifdef FEATURE_NX_IPV6
6819 COPY_NXD_ADDRESS(server_ip, &(client_ptr -> nx_web_http_client_server_address));
6820 #else
6821 client_ptr -> nx_web_http_client_server_address.nxd_ip_version = NX_IP_VERSION_V4;
6822 client_ptr -> nx_web_http_client_server_address.nxd_ip_address.v4 = server_ip -> nxd_ip_address.v4;
6823 #endif
6824
6825 client_ptr -> nx_web_http_client_connect_port = server_port;
6826
6827 /* Connect to the HTTPS server with TCP. */
6828 status = nxd_tcp_client_socket_connect(&(client_ptr -> nx_web_http_client_socket), server_ip,
6829 client_ptr -> nx_web_http_client_connect_port, wait_option);
6830
6831 /* Check for connection status. */
6832 if ((status != NX_SUCCESS) && (status != NX_IN_PROGRESS))
6833 {
6834
6835 /* Error, unbind the port and return an error. */
6836 nx_tcp_client_socket_unbind(&(client_ptr -> nx_web_http_client_socket));
6837 }
6838
6839 return(status);
6840 }
6841
6842 #ifdef NX_WEB_HTTPS_ENABLE
6843
6844 /**************************************************************************/
6845 /* */
6846 /* FUNCTION RELEASE */
6847 /* */
6848 /* _nxe_web_https_client_secure_connect PORTABLE C */
6849 /* 6.1 */
6850 /* AUTHOR */
6851 /* */
6852 /* Yuxin Zhou, Microsoft Corporation */
6853 /* */
6854 /* DESCRIPTION */
6855 /* */
6856 /* This function checks for errors in the secure HTTPS connect call. */
6857 /* */
6858 /* */
6859 /* INPUT */
6860 /* */
6861 /* client_ptr Pointer to HTTP client */
6862 /* server_ip Address of remote server */
6863 /* server_port HTTPS port on remote server */
6864 /* tls_setup User-supplied callback */
6865 /* function to set up TLS */
6866 /* parameters. */
6867 /* wait_option Suspension option */
6868 /* */
6869 /* OUTPUT */
6870 /* */
6871 /* status Completion status */
6872 /* */
6873 /* CALLS */
6874 /* */
6875 /* _nxe_web_https_client_secure_connect Actual secure connect call */
6876 /* */
6877 /* CALLED BY */
6878 /* */
6879 /* Application Code */
6880 /* */
6881 /* RELEASE HISTORY */
6882 /* */
6883 /* DATE NAME DESCRIPTION */
6884 /* */
6885 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
6886 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
6887 /* resulting in version 6.1 */
6888 /* */
6889 /**************************************************************************/
_nxe_web_http_client_secure_connect(NX_WEB_HTTP_CLIENT * client_ptr,NXD_ADDRESS * server_ip,UINT server_port,UINT (* tls_setup)(NX_WEB_HTTP_CLIENT * client_ptr,NX_SECURE_TLS_SESSION *),ULONG wait_option)6890 UINT _nxe_web_http_client_secure_connect(NX_WEB_HTTP_CLIENT *client_ptr, NXD_ADDRESS *server_ip, UINT server_port,
6891 UINT (*tls_setup)(NX_WEB_HTTP_CLIENT *client_ptr, NX_SECURE_TLS_SESSION *),
6892 ULONG wait_option)
6893 {
6894 UINT status;
6895
6896
6897 /* Check pointers. */
6898 if(client_ptr == NX_NULL || server_ip == NX_NULL || tls_setup == NX_NULL)
6899 {
6900 return(NX_PTR_ERROR);
6901 }
6902
6903 /* Call actual function. */
6904 status = _nx_web_http_client_secure_connect(client_ptr, server_ip, server_port, tls_setup, wait_option);
6905
6906 return(status);
6907 }
6908
6909 /**************************************************************************/
6910 /* */
6911 /* FUNCTION RELEASE */
6912 /* */
6913 /* _nx_web_https_client_secure_connect PORTABLE C */
6914 /* 6.1 */
6915 /* AUTHOR */
6916 /* */
6917 /* Yuxin Zhou, Microsoft Corporation */
6918 /* */
6919 /* DESCRIPTION */
6920 /* */
6921 /* This function connects a HTTPS client on the specified IP. The TLS */
6922 /* session in the NX_WEB_HTTP_CLIENT structure is initialized using */
6923 /* application-supplied callback. */
6924 /* */
6925 /* */
6926 /* INPUT */
6927 /* */
6928 /* client_ptr Pointer to HTTP client */
6929 /* server_ip Address of remote server */
6930 /* server_port HTTPS port on remote server */
6931 /* tls_setup User-supplied callback */
6932 /* function to set up TLS */
6933 /* parameters. */
6934 /* wait_option Suspension option */
6935 /* */
6936 /* OUTPUT */
6937 /* */
6938 /* status Completion status */
6939 /* */
6940 /* CALLS */
6941 /* */
6942 /* _nx_web_http_client_connect Connect to server with TCP */
6943 /* _nx_secure_tls_session_start Connect to server with TLS */
6944 /* _nx_web_http_client_error_exit Cleanup and shut down HTTPS */
6945 /* */
6946 /* CALLED BY */
6947 /* */
6948 /* Application Code */
6949 /* */
6950 /* RELEASE HISTORY */
6951 /* */
6952 /* DATE NAME DESCRIPTION */
6953 /* */
6954 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
6955 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
6956 /* resulting in version 6.1 */
6957 /* */
6958 /**************************************************************************/
_nx_web_http_client_secure_connect(NX_WEB_HTTP_CLIENT * client_ptr,NXD_ADDRESS * server_ip,UINT server_port,UINT (* tls_setup)(NX_WEB_HTTP_CLIENT * client_ptr,NX_SECURE_TLS_SESSION *),ULONG wait_option)6959 UINT _nx_web_http_client_secure_connect(NX_WEB_HTTP_CLIENT *client_ptr, NXD_ADDRESS *server_ip, UINT server_port,
6960 UINT (*tls_setup)(NX_WEB_HTTP_CLIENT *client_ptr, NX_SECURE_TLS_SESSION *),
6961 ULONG wait_option)
6962 {
6963 UINT status;
6964
6965 #ifndef NX_WEB_HTTP_KEEPALIVE_DISABLE
6966
6967 /* If keep-alive is true, the client is already connected to the server. */
6968 if (client_ptr -> nx_web_http_client_keep_alive &&
6969 (nx_tcp_socket_state_wait(&(client_ptr -> nx_web_http_client_socket), NX_TCP_ESTABLISHED, 0) == NX_SUCCESS))
6970 {
6971
6972 /* Reset the state. */
6973 _nx_web_http_client_cleanup(client_ptr);
6974 return(NX_SUCCESS);
6975 }
6976 #endif /* NX_WEB_HTTP_KEEPALIVE_DISABLE */
6977
6978 /* We have an HTTPS client, mark it as such. */
6979 client_ptr -> nx_web_http_client_is_https = NX_TRUE;
6980
6981 /* Attempt to connect to the HTTPS server using just TCP - we need to establish the TCP socket
6982 before we attempt to perform a TLS handshake for HTTPS. */
6983 status = _nx_web_http_client_connect(client_ptr, server_ip, server_port, wait_option);
6984
6985 if(status != NX_SUCCESS)
6986 {
6987 return(status);
6988 }
6989
6990 /* Call the TLS setup callback to initialize TLS configuration. */
6991 status = (*tls_setup)(client_ptr, &(client_ptr->nx_web_http_client_tls_session));
6992
6993 if(status != NX_SUCCESS)
6994 {
6995
6996 /* Error, unbind the port and return an error. */
6997 _nx_tcp_socket_disconnect(&(client_ptr -> nx_web_http_client_socket), wait_option);
6998 _nx_tcp_client_socket_unbind(&(client_ptr -> nx_web_http_client_socket));
6999 return(status);
7000 }
7001
7002 /* Start TLS session after connecting TCP socket. */
7003 status = _nx_secure_tls_session_start(&(client_ptr -> nx_web_http_client_tls_session), &(client_ptr -> nx_web_http_client_socket), wait_option);
7004
7005 if (status != NX_SUCCESS)
7006 {
7007 /* Error, unbind the port and return an error. */
7008 _nx_web_http_client_error_exit(client_ptr, wait_option);
7009 return(status);
7010 }
7011
7012 /* At this point we have a connection setup with an HTTPS server! */
7013
7014 /* Return successful completion. */
7015 return(NX_SUCCESS);
7016 }
7017
7018 #endif /* NX_WEB_HTTPS_ENABLE */
7019
7020
7021 /**************************************************************************/
7022 /* */
7023 /* FUNCTION RELEASE */
7024 /* */
7025 /* _nxe_web_http_client_request_initialize PORTABLE C */
7026 /* 6.1 */
7027 /* AUTHOR */
7028 /* */
7029 /* Yuxin Zhou, Microsoft Corporation */
7030 /* */
7031 /* DESCRIPTION */
7032 /* */
7033 /* This function checks for errors in the HTTP request initialize call.*/
7034 /* */
7035 /* */
7036 /* INPUT */
7037 /* */
7038 /* client_ptr Pointer to HTTP client */
7039 /* method HTTP request type (e.g. GET) */
7040 /* resource HTTP resource (e.g. URL) */
7041 /* host Pointer to Host */
7042 /* input_size Size of input for PUT/POST */
7043 /* transfer_encoding_chunked Chunked encoding flag */
7044 /* username Username for server access */
7045 /* password Password for server access */
7046 /* wait_option Suspension option */
7047 /* */
7048 /* OUTPUT */
7049 /* */
7050 /* status Completion status */
7051 /* */
7052 /* CALLS */
7053 /* */
7054 /* _nx_web_http_client_request_initialize */
7055 /* Actual request create call */
7056 /* */
7057 /* CALLED BY */
7058 /* */
7059 /* Application Code */
7060 /* */
7061 /* RELEASE HISTORY */
7062 /* */
7063 /* DATE NAME DESCRIPTION */
7064 /* */
7065 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
7066 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
7067 /* resulting in version 6.1 */
7068 /* */
7069 /**************************************************************************/
_nxe_web_http_client_request_initialize(NX_WEB_HTTP_CLIENT * client_ptr,UINT method,CHAR * resource,CHAR * host,UINT input_size,UINT transfer_encoding_chunked,CHAR * username,CHAR * password,UINT wait_option)7070 UINT _nxe_web_http_client_request_initialize(NX_WEB_HTTP_CLIENT *client_ptr,
7071 UINT method, /* GET, PUT, DELETE, POST, HEAD */
7072 CHAR *resource,
7073 CHAR *host,
7074 UINT input_size, /* Used by PUT and POST */
7075 UINT transfer_encoding_chunked, /* If true, input_size is ignored. */
7076 CHAR *username,
7077 CHAR *password,
7078 UINT wait_option)
7079 {
7080 UINT status;
7081
7082 /* Check pointers. We need a control block and a resource but
7083 username and password can be NULL. */
7084 if(client_ptr == NX_NULL || resource == NX_NULL || host == NX_NULL)
7085 {
7086 return(NX_PTR_ERROR);
7087 }
7088
7089 status = NX_SUCCESS;
7090
7091 /* Check methods. */
7092 switch(method)
7093 {
7094 case NX_WEB_HTTP_METHOD_POST:
7095 case NX_WEB_HTTP_METHOD_PUT:
7096 /* PUT and POST need an input size. */
7097 if (!input_size && !transfer_encoding_chunked)
7098 {
7099 status = NX_WEB_HTTP_METHOD_ERROR;
7100 }
7101 break;
7102 case NX_WEB_HTTP_METHOD_GET:
7103 case NX_WEB_HTTP_METHOD_DELETE:
7104 case NX_WEB_HTTP_METHOD_HEAD:
7105 /* These are good as-is. */
7106 break;
7107 case NX_WEB_HTTP_METHOD_NONE:
7108 default:
7109 /* Improper or missing method. */
7110 status = NX_WEB_HTTP_METHOD_ERROR;
7111 }
7112
7113 /* Check status from method creation. */
7114 if(status != NX_SUCCESS)
7115 {
7116 return(status);
7117 }
7118
7119 /* Call actual function. */
7120 status = _nx_web_http_client_request_initialize(client_ptr, method, resource, host, input_size,
7121 transfer_encoding_chunked, username, password,
7122 wait_option);
7123
7124
7125 return(status);
7126 }
7127
7128 /**************************************************************************/
7129 /* */
7130 /* FUNCTION RELEASE */
7131 /* */
7132 /* _nx_web_http_client_request_initialize PORTABLE C */
7133 /* 6.1 */
7134 /* AUTHOR */
7135 /* */
7136 /* Yuxin Zhou, Microsoft Corporation */
7137 /* */
7138 /* DESCRIPTION */
7139 /* */
7140 /* This function initializes an HTTP request using information */
7141 /* supplied by the caller. When a request is initialized, a packet is */
7142 /* allocated internally which can then be modified before sending the */
7143 /* final request to the server. */
7144 /* */
7145 /* */
7146 /* INPUT */
7147 /* */
7148 /* client_ptr Pointer to HTTP client */
7149 /* method HTTP request type (e.g. GET) */
7150 /* resource HTTP resource (e.g. URL) */
7151 /* host Pointer to Host */
7152 /* input_size Size of input for PUT/POST */
7153 /* transfer_encoding_chunked Chunked encoding flag */
7154 /* username Username for server access */
7155 /* password Password for server access */
7156 /* wait_option Suspension option */
7157 /* */
7158 /* OUTPUT */
7159 /* */
7160 /* status Completion status */
7161 /* */
7162 /* CALLS */
7163 /* */
7164 /* _nx_web_http_client_request_initialize_extended */
7165 /* Actual request create call */
7166 /* _nx_utility_string_length_check Check string length */
7167 /* */
7168 /* CALLED BY */
7169 /* */
7170 /* Application Code */
7171 /* */
7172 /* RELEASE HISTORY */
7173 /* */
7174 /* DATE NAME DESCRIPTION */
7175 /* */
7176 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
7177 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
7178 /* resulting in version 6.1 */
7179 /* */
7180 /**************************************************************************/
_nx_web_http_client_request_initialize(NX_WEB_HTTP_CLIENT * client_ptr,UINT method,CHAR * resource,CHAR * host,UINT input_size,UINT transfer_encoding_chunked,CHAR * username,CHAR * password,UINT wait_option)7181 UINT _nx_web_http_client_request_initialize(NX_WEB_HTTP_CLIENT *client_ptr,
7182 UINT method, /* GET, PUT, DELETE, POST, HEAD */
7183 CHAR *resource,
7184 CHAR *host,
7185 UINT input_size, /* Used by PUT and POST */
7186 UINT transfer_encoding_chunked, /* If true, input_size is ignored. */
7187 CHAR *username,
7188 CHAR *password,
7189 UINT wait_option)
7190 {
7191 UINT temp_resource_length;
7192 UINT temp_host_length;
7193 UINT temp_username_length = 0;
7194 UINT temp_password_length = 0;
7195
7196 if ((username) && (password))
7197 {
7198
7199 /* Check username and password length. */
7200 if (_nx_utility_string_length_check(username, &temp_username_length, NX_WEB_HTTP_MAX_NAME) ||
7201 _nx_utility_string_length_check(password, &temp_password_length, NX_WEB_HTTP_MAX_PASSWORD))
7202 {
7203 return(NX_WEB_HTTP_ERROR);
7204 }
7205 }
7206
7207 /* Check resource and host length. */
7208 if (_nx_utility_string_length_check(resource, &temp_resource_length, NX_MAX_STRING_LENGTH) ||
7209 _nx_utility_string_length_check(host, &temp_host_length, NX_MAX_STRING_LENGTH))
7210 {
7211 return(NX_WEB_HTTP_ERROR);
7212 }
7213
7214 return(_nx_web_http_client_request_initialize_extended(client_ptr, method, resource,
7215 temp_resource_length, host, temp_host_length,
7216 input_size, transfer_encoding_chunked,
7217 username, temp_username_length,
7218 password, temp_password_length,
7219 wait_option));
7220 }
7221
7222
7223 /**************************************************************************/
7224 /* */
7225 /* FUNCTION RELEASE */
7226 /* */
7227 /* _nxe_web_http_client_request_initialize_extended PORTABLE C */
7228 /* 6.1 */
7229 /* AUTHOR */
7230 /* */
7231 /* Yuxin Zhou, Microsoft Corporation */
7232 /* */
7233 /* DESCRIPTION */
7234 /* */
7235 /* This function checks for errors in the HTTP request initialize call.*/
7236 /* */
7237 /* INPUT */
7238 /* */
7239 /* client_ptr Pointer to HTTP client */
7240 /* method HTTP request type (e.g. GET) */
7241 /* resource HTTP resource (e.g. URL) */
7242 /* resource_length Length of resource */
7243 /* host Pointer to Host */
7244 /* host_length Length of host */
7245 /* input_size Size of input for PUT/POST */
7246 /* transfer_encoding_chunked Chunked encoding flag */
7247 /* username Username for server access */
7248 /* username_length Length of username */
7249 /* password Password for server access */
7250 /* password_length Length of password */
7251 /* wait_option Suspension option */
7252 /* */
7253 /* OUTPUT */
7254 /* */
7255 /* status Completion status */
7256 /* */
7257 /* CALLS */
7258 /* */
7259 /* _nx_web_http_client_request_initialize_extended */
7260 /* Actual request create call */
7261 /* */
7262 /* CALLED BY */
7263 /* */
7264 /* Application Code */
7265 /* */
7266 /* RELEASE HISTORY */
7267 /* */
7268 /* DATE NAME DESCRIPTION */
7269 /* */
7270 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
7271 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
7272 /* resulting in version 6.1 */
7273 /* */
7274 /**************************************************************************/
_nxe_web_http_client_request_initialize_extended(NX_WEB_HTTP_CLIENT * client_ptr,UINT method,CHAR * resource,UINT resource_length,CHAR * host,UINT host_length,UINT input_size,UINT transfer_encoding_chunked,CHAR * username,UINT username_length,CHAR * password,UINT password_length,UINT wait_option)7275 UINT _nxe_web_http_client_request_initialize_extended(NX_WEB_HTTP_CLIENT *client_ptr,
7276 UINT method, /* GET, PUT, DELETE, POST, HEAD */
7277 CHAR *resource,
7278 UINT resource_length,
7279 CHAR *host,
7280 UINT host_length,
7281 UINT input_size, /* Used by PUT and POST */
7282 UINT transfer_encoding_chunked, /* If true, input_size is ignored. */
7283 CHAR *username,
7284 UINT username_length,
7285 CHAR *password,
7286 UINT password_length,
7287 UINT wait_option)
7288 {
7289 UINT status;
7290
7291 /* Check pointers. We need a control block and a resource but
7292 username and password can be NULL. */
7293 if(client_ptr == NX_NULL || resource == NX_NULL || host == NX_NULL)
7294 {
7295 return(NX_PTR_ERROR);
7296 }
7297
7298 status = NX_SUCCESS;
7299
7300 /* Check methods. */
7301 switch(method)
7302 {
7303 case NX_WEB_HTTP_METHOD_POST:
7304 case NX_WEB_HTTP_METHOD_PUT:
7305 /* PUT and POST need an input size. */
7306 if (!input_size && !transfer_encoding_chunked)
7307 {
7308 status = NX_WEB_HTTP_METHOD_ERROR;
7309 }
7310 break;
7311 case NX_WEB_HTTP_METHOD_GET:
7312 case NX_WEB_HTTP_METHOD_DELETE:
7313 case NX_WEB_HTTP_METHOD_HEAD:
7314 /* These are good as-is. */
7315 break;
7316 case NX_WEB_HTTP_METHOD_NONE:
7317 default:
7318 /* Improper or missing method. */
7319 status = NX_WEB_HTTP_METHOD_ERROR;
7320 }
7321
7322 /* Check status from method creation. */
7323 if(status != NX_SUCCESS)
7324 {
7325 return(status);
7326 }
7327
7328 /* Call actual function. */
7329 status = _nx_web_http_client_request_initialize_extended(client_ptr, method, resource, resource_length,
7330 host, host_length, input_size,
7331 transfer_encoding_chunked, username,
7332 username_length, password, password_length,
7333 wait_option);
7334
7335
7336 return(status);
7337 }
7338
7339 /**************************************************************************/
7340 /* */
7341 /* FUNCTION RELEASE */
7342 /* */
7343 /* _nx_web_http_client_request_initialize_extended PORTABLE C */
7344 /* 6.1.6 */
7345 /* AUTHOR */
7346 /* */
7347 /* Yuxin Zhou, Microsoft Corporation */
7348 /* */
7349 /* DESCRIPTION */
7350 /* */
7351 /* This function initializes an HTTP request using information */
7352 /* supplied by the caller. When a request is initialized, a packet is */
7353 /* allocated internally which can then be modified before sending the */
7354 /* final request to the server. */
7355 /* */
7356 /* Note: The strings of resource, host, username and password must be */
7357 /* NULL-terminated and length of each string matches the length */
7358 /* specified in the argument list. */
7359 /* */
7360 /* */
7361 /* INPUT */
7362 /* */
7363 /* client_ptr Pointer to HTTP client */
7364 /* method HTTP request type (e.g. GET) */
7365 /* resource HTTP resource (e.g. URL) */
7366 /* resource_length Length of resource */
7367 /* host Pointer to Host */
7368 /* host_length Length of host */
7369 /* input_size Size of input for PUT/POST */
7370 /* transfer_encoding_chunked Chunked encoding flag */
7371 /* username Username for server access */
7372 /* username_length Length of username */
7373 /* password Password for server access */
7374 /* password_length Length of password */
7375 /* wait_option Suspension option */
7376 /* */
7377 /* OUTPUT */
7378 /* */
7379 /* status Completion status */
7380 /* */
7381 /* CALLS */
7382 /* */
7383 /* _nx_web_http_client_request_packet_allocate */
7384 /* Allocate a request packet */
7385 /* _nx_web_http_client_error_exit Cleanup and shut down HTTPS */
7386 /* nx_packet_data_append Append packet data */
7387 /* _nx_utility_string_length_check Check string length */
7388 /* */
7389 /* CALLED BY */
7390 /* */
7391 /* Application Code */
7392 /* */
7393 /* RELEASE HISTORY */
7394 /* */
7395 /* DATE NAME DESCRIPTION */
7396 /* */
7397 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
7398 /* 09-30-2020 Yuxin Zhou Modified comment(s), and */
7399 /* verified memcpy use cases, */
7400 /* resulting in version 6.1 */
7401 /* 04-02-2021 Yuxin Zhou Modified comment(s), and */
7402 /* improved the logic of */
7403 /* parsing base64, */
7404 /* resulting in version 6.1.6 */
7405 /* */
7406 /**************************************************************************/
_nx_web_http_client_request_initialize_extended(NX_WEB_HTTP_CLIENT * client_ptr,UINT method,CHAR * resource,UINT resource_length,CHAR * host,UINT host_length,UINT input_size,UINT transfer_encoding_chunked,CHAR * username,UINT username_length,CHAR * password,UINT password_length,UINT wait_option)7407 UINT _nx_web_http_client_request_initialize_extended(NX_WEB_HTTP_CLIENT *client_ptr,
7408 UINT method, /* GET, PUT, DELETE, POST, HEAD */
7409 CHAR *resource,
7410 UINT resource_length,
7411 CHAR *host,
7412 UINT host_length,
7413 UINT input_size, /* Used by PUT and POST */
7414 UINT transfer_encoding_chunked, /* If true, input_size is ignored. */
7415 CHAR *username,
7416 UINT username_length,
7417 CHAR *password,
7418 UINT password_length,
7419 UINT wait_option)
7420 {
7421 UINT status;
7422 NX_PACKET *packet_ptr;
7423 CHAR string1[NX_WEB_HTTP_MAX_NAME + NX_WEB_HTTP_MAX_PASSWORD + 2];
7424 CHAR string2[NX_WEB_HTTP_MAX_STRING + 1];
7425 CHAR crlf[2] = {13,10};
7426 UINT temp_resource_length;
7427 UINT temp_host_length;
7428 UINT temp_username_length = 0;
7429 UINT temp_password_length = 0;
7430 UINT string1_length;
7431 UINT string2_length;
7432
7433 /* If there is old request packet, just release it. */
7434 if (client_ptr -> nx_web_http_client_request_packet_ptr)
7435 {
7436 nx_packet_release(client_ptr -> nx_web_http_client_request_packet_ptr);
7437 client_ptr -> nx_web_http_client_request_packet_ptr = NX_NULL;
7438 }
7439
7440 if ((username) && (password))
7441 {
7442
7443 /* Check username and password length. */
7444 if (_nx_utility_string_length_check(username, &temp_username_length, username_length) ||
7445 _nx_utility_string_length_check(password, &temp_password_length, password_length))
7446 {
7447 return(NX_WEB_HTTP_ERROR);
7448 }
7449
7450 /* Validate string length. */
7451 if ((username_length != temp_username_length) ||
7452 (password_length != temp_password_length))
7453 {
7454 return(NX_WEB_HTTP_ERROR);
7455 }
7456 }
7457
7458 /* Check resource and host length. */
7459 if (_nx_utility_string_length_check(resource, &temp_resource_length, NX_MAX_STRING_LENGTH) ||
7460 _nx_utility_string_length_check(host, &temp_host_length, NX_MAX_STRING_LENGTH))
7461 {
7462 return(NX_WEB_HTTP_ERROR);
7463 }
7464
7465 /* Validate string length. */
7466 if ((resource_length != temp_resource_length) ||
7467 (host_length != temp_host_length))
7468 {
7469 return(NX_WEB_HTTP_ERROR);
7470 }
7471
7472 /* Allocate a packet for the request message. */
7473 status = _nx_web_http_client_request_packet_allocate(client_ptr, &(client_ptr -> nx_web_http_client_request_packet_ptr), wait_option);
7474
7475 /* Check allocation status. */
7476 if (status != NX_SUCCESS)
7477 {
7478 /* Error, unbind the port and return an error. */
7479 _nx_web_http_client_error_exit(client_ptr, wait_option);
7480
7481 return(status);
7482 }
7483
7484 /* Get a working pointer to our newly-allocated packet. */
7485 packet_ptr = client_ptr -> nx_web_http_client_request_packet_ptr;
7486
7487 /* Determine the requested method. */
7488 status = NX_SUCCESS;
7489 client_ptr -> nx_web_http_client_method = method;
7490 switch(method)
7491 {
7492 case NX_WEB_HTTP_METHOD_GET:
7493 /* Build the GET request. */
7494 nx_packet_data_append(packet_ptr, "GET ", 4, client_ptr -> nx_web_http_client_packet_pool_ptr,
7495 wait_option);
7496 break;
7497 case NX_WEB_HTTP_METHOD_PUT:
7498 /* Additional information requested, build the POST request. */
7499 nx_packet_data_append(packet_ptr, "PUT ", 4, client_ptr -> nx_web_http_client_packet_pool_ptr,
7500 wait_option);
7501
7502 /* Store the total number of bytes to send. */
7503 client_ptr -> nx_web_http_client_total_transfer_bytes = input_size;
7504 client_ptr -> nx_web_http_client_actual_bytes_transferred = 0;
7505
7506 break;
7507 case NX_WEB_HTTP_METHOD_POST:
7508 /* Additional information requested, build the POST request. */
7509 nx_packet_data_append(packet_ptr, "POST ", 5, client_ptr -> nx_web_http_client_packet_pool_ptr,
7510 wait_option);
7511
7512 /* Store the total number of bytes to send. */
7513 client_ptr -> nx_web_http_client_total_transfer_bytes = input_size;
7514 client_ptr -> nx_web_http_client_actual_bytes_transferred = 0;
7515
7516 break;
7517 case NX_WEB_HTTP_METHOD_DELETE:
7518 /* Build the DELETE request. */
7519 nx_packet_data_append(packet_ptr, "DELETE ", 7, client_ptr -> nx_web_http_client_packet_pool_ptr,
7520 wait_option);
7521 break;
7522 case NX_WEB_HTTP_METHOD_HEAD:
7523 /* Build the HEAD request. */
7524 nx_packet_data_append(packet_ptr, "HEAD ", 5, client_ptr -> nx_web_http_client_packet_pool_ptr,
7525 wait_option);
7526 break;
7527 case NX_WEB_HTTP_METHOD_NONE:
7528 default:
7529 status = NX_WEB_HTTP_METHOD_ERROR;
7530 break;
7531 }
7532
7533 /* Check status from method creation. */
7534 if(status != NX_SUCCESS)
7535 {
7536
7537 /* Release the request packet. */
7538 nx_packet_release(packet_ptr);
7539 client_ptr -> nx_web_http_client_request_packet_ptr = NX_NULL;
7540 return(status);
7541 }
7542
7543 /* Determine if the resource needs a leading "/". */
7544 if (resource[0] != '/')
7545 {
7546
7547 /* Is this another website e.g. begins with http or https and has a colon? */
7548 if (
7549 ((resource[0] == 'h') || (resource[0] == 'H')) &&
7550 ((resource[1] == 't') || (resource[1] == 'T')) &&
7551 ((resource[2] == 't') || (resource[2] == 'T')) &&
7552 ((resource[3] == 'p') || (resource[3] == 'P')) &&
7553 ( (resource[4] == ':') ||
7554 (((resource[4] == 's') || (resource[4] == 'S')) && (resource[5] == ':')))
7555 )
7556 {
7557
7558 /* Yes, to send this string as is. */
7559 }
7560 else
7561 {
7562
7563 /* Local file URI which needs a leading '/' character. */
7564 nx_packet_data_append(packet_ptr, "/", 1, client_ptr -> nx_web_http_client_packet_pool_ptr, wait_option);
7565 }
7566 }
7567 /* Else URI string refers to root directory file, and has a leading '/' character already. */
7568
7569 /* Place the resource in the header. */
7570 nx_packet_data_append(packet_ptr, resource, resource_length, client_ptr -> nx_web_http_client_packet_pool_ptr,
7571 wait_option);
7572
7573 /* Place the HTTP version in the header. */
7574 nx_packet_data_append(packet_ptr, " HTTP/1.1", 9, client_ptr -> nx_web_http_client_packet_pool_ptr,
7575 wait_option);
7576
7577 /* Place the end of line character in the header. */
7578 nx_packet_data_append(packet_ptr, crlf, 2, client_ptr -> nx_web_http_client_packet_pool_ptr,
7579 wait_option);
7580
7581 /* Place the Host in the header. */
7582 nx_packet_data_append(packet_ptr, "Host: ", 6, client_ptr -> nx_web_http_client_packet_pool_ptr,
7583 wait_option);
7584
7585 if (host_length)
7586 {
7587 nx_packet_data_append(packet_ptr, host, host_length, client_ptr -> nx_web_http_client_packet_pool_ptr,
7588 wait_option);
7589 }
7590 nx_packet_data_append(packet_ptr, crlf, 2, client_ptr -> nx_web_http_client_packet_pool_ptr,
7591 wait_option);
7592
7593 /* Determine if basic authentication is required. */
7594 if ((username) && (password))
7595 {
7596
7597 /* Yes, attempt to build basic authentication. */
7598 nx_packet_data_append(packet_ptr, "Authorization: Basic ", 21, client_ptr -> nx_web_http_client_packet_pool_ptr,
7599 wait_option);
7600
7601 /* Encode and append the "name:password" into next. */
7602
7603 /* Place the name and password in a single string. */
7604
7605 /* Copy the name into the merged string. */
7606 memcpy(string1, username, username_length); /* Use case of memcpy is verified. */
7607
7608 /* Insert the colon. */
7609 string1[username_length] = ':';
7610
7611 /* Copy the password into the merged string. */
7612 memcpy(&string1[username_length + 1], password, password_length); /* Use case of memcpy is verified. */
7613
7614 /* Make combined string NULL terminated. */
7615 string1[username_length + password_length + 1] = NX_NULL;
7616
7617 /* Now encode the username:password string. */
7618 _nx_utility_base64_encode((UCHAR *)string1, username_length + password_length + 1, (UCHAR *)string2, sizeof(string2), &string2_length);
7619 nx_packet_data_append(packet_ptr, string2, string2_length, client_ptr -> nx_web_http_client_packet_pool_ptr, wait_option);
7620 nx_packet_data_append(packet_ptr, crlf, 2, client_ptr -> nx_web_http_client_packet_pool_ptr, wait_option);
7621 }
7622
7623 /* Check to see if a Content-Length field is needed. */
7624 if ((input_size) && (!transfer_encoding_chunked))
7625 {
7626
7627 /* Now build the content-length entry. */
7628 nx_packet_data_append(packet_ptr, "Content-Length: ", 16, client_ptr -> nx_web_http_client_packet_pool_ptr, wait_option);
7629 string1_length = _nx_web_http_client_number_convert(input_size, string1);
7630 nx_packet_data_append(packet_ptr, string1, string1_length, client_ptr -> nx_web_http_client_packet_pool_ptr, wait_option);
7631 nx_packet_data_append(packet_ptr, crlf, 2, client_ptr -> nx_web_http_client_packet_pool_ptr, wait_option);
7632 }
7633
7634 if (transfer_encoding_chunked)
7635 {
7636
7637 /* Place the Transfer Encoding in the header. */
7638 nx_packet_data_append(packet_ptr, "Transfer-Encoding: chunked", 26, client_ptr -> nx_web_http_client_packet_pool_ptr, wait_option);
7639 nx_packet_data_append(packet_ptr, crlf, 2, client_ptr -> nx_web_http_client_packet_pool_ptr, wait_option);
7640 }
7641
7642 return(NX_SUCCESS);
7643 }
7644
7645 /**************************************************************************/
7646 /* */
7647 /* FUNCTION RELEASE */
7648 /* */
7649 /* _nxe_web_http_client_request_header_add PORTABLE C */
7650 /* 6.1 */
7651 /* AUTHOR */
7652 /* */
7653 /* Yuxin Zhou, Microsoft Corporation */
7654 /* */
7655 /* DESCRIPTION */
7656 /* */
7657 /* This function checks for errors when calling the custom header */
7658 /* addition routine. */
7659 /* */
7660 /* */
7661 /* INPUT */
7662 /* */
7663 /* client_ptr Pointer to HTTP client */
7664 /* field_name HTTP header field name */
7665 /* name_length Length of field name string */
7666 /* field_value Value of header field */
7667 /* value_length Length of value string */
7668 /* wait_option Suspension option */
7669 /* */
7670 /* OUTPUT */
7671 /* */
7672 /* status Completion status */
7673 /* */
7674 /* CALLS */
7675 /* */
7676 /* _nx_web_http_client_request_header_add */
7677 /* Actual header add call */
7678 /* */
7679 /* CALLED BY */
7680 /* */
7681 /* Application Code */
7682 /* */
7683 /* RELEASE HISTORY */
7684 /* */
7685 /* DATE NAME DESCRIPTION */
7686 /* */
7687 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
7688 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
7689 /* resulting in version 6.1 */
7690 /* */
7691 /**************************************************************************/
_nxe_web_http_client_request_header_add(NX_WEB_HTTP_CLIENT * client_ptr,CHAR * field_name,UINT name_length,CHAR * field_value,UINT value_length,UINT wait_option)7692 UINT _nxe_web_http_client_request_header_add(NX_WEB_HTTP_CLIENT *client_ptr, CHAR *field_name, UINT name_length,
7693 CHAR *field_value, UINT value_length, UINT wait_option)
7694 {
7695 UINT status;
7696
7697 /* Check pointers. */
7698 if(client_ptr == NX_NULL || field_name == NX_NULL || field_value == NX_NULL)
7699 {
7700 return(NX_PTR_ERROR);
7701 }
7702
7703 /* Call the actual function. */
7704 status = _nx_web_http_client_request_header_add(client_ptr, field_name, name_length,
7705 field_value, value_length, wait_option);
7706
7707 return(status);
7708 }
7709
7710
7711 /**************************************************************************/
7712 /* */
7713 /* FUNCTION RELEASE */
7714 /* */
7715 /* _nx_web_http_client_request_header_add PORTABLE C */
7716 /* 6.1 */
7717 /* AUTHOR */
7718 /* */
7719 /* Yuxin Zhou, Microsoft Corporation */
7720 /* */
7721 /* DESCRIPTION */
7722 /* */
7723 /* This function adds a custom header to an HTTP(S) request that was */
7724 /* previously initialized with nx_web_http_client_request_initialize. */
7725 /* The field name and value are placed directly into the HTTP header */
7726 /* so it is up to the caller to assure that they are valid values. */
7727 /* */
7728 /* */
7729 /* INPUT */
7730 /* */
7731 /* client_ptr Pointer to HTTP client */
7732 /* field_name HTTP header field name */
7733 /* name_length Length of field name string */
7734 /* field_value Value of header field */
7735 /* value_length Length of value string */
7736 /* wait_option Suspension option */
7737 /* */
7738 /* OUTPUT */
7739 /* */
7740 /* status Completion status */
7741 /* */
7742 /* CALLS */
7743 /* */
7744 /* nx_packet_data_append Append data to request packet */
7745 /* */
7746 /* CALLED BY */
7747 /* */
7748 /* Application Code */
7749 /* */
7750 /* RELEASE HISTORY */
7751 /* */
7752 /* DATE NAME DESCRIPTION */
7753 /* */
7754 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
7755 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
7756 /* resulting in version 6.1 */
7757 /* */
7758 /**************************************************************************/
_nx_web_http_client_request_header_add(NX_WEB_HTTP_CLIENT * client_ptr,CHAR * field_name,UINT name_length,CHAR * field_value,UINT value_length,UINT wait_option)7759 UINT _nx_web_http_client_request_header_add(NX_WEB_HTTP_CLIENT *client_ptr, CHAR *field_name, UINT name_length,
7760 CHAR *field_value, UINT value_length, UINT wait_option)
7761 {
7762 NX_PACKET *packet_ptr;
7763 UINT status;
7764 CHAR crlf[2] = {13,10};
7765
7766
7767 /* Make sure a request packet was allocated. */
7768 if(client_ptr -> nx_web_http_client_request_packet_ptr == NX_NULL)
7769 {
7770 return(NX_WEB_HTTP_ERROR);
7771 }
7772
7773 /* Get a working pointer to our newly-allocated packet. */
7774 packet_ptr = client_ptr -> nx_web_http_client_request_packet_ptr;
7775
7776
7777 /* Add custom header fields to request packet. */
7778 status = nx_packet_data_append(packet_ptr, field_name, name_length, client_ptr -> nx_web_http_client_packet_pool_ptr,
7779 wait_option);
7780
7781 if(status != NX_SUCCESS)
7782 {
7783 return(status);
7784 }
7785
7786 status = nx_packet_data_append(packet_ptr, ": ", 2, client_ptr -> nx_web_http_client_packet_pool_ptr,
7787 wait_option);
7788
7789 if(status != NX_SUCCESS)
7790 {
7791 return(status);
7792 }
7793
7794 status = nx_packet_data_append(packet_ptr, field_value, value_length, client_ptr -> nx_web_http_client_packet_pool_ptr,
7795 wait_option);
7796
7797 if(status != NX_SUCCESS)
7798 {
7799 return(status);
7800 }
7801
7802 status = nx_packet_data_append(packet_ptr, crlf, 2, client_ptr -> nx_web_http_client_packet_pool_ptr, wait_option);
7803
7804 return(status);
7805 }
7806
7807 /**************************************************************************/
7808 /* */
7809 /* FUNCTION RELEASE */
7810 /* */
7811 /* _nxe_web_http_client_request_send PORTABLE C */
7812 /* 6.1 */
7813 /* AUTHOR */
7814 /* */
7815 /* Yuxin Zhou, Microsoft Corporation */
7816 /* */
7817 /* DESCRIPTION */
7818 /* */
7819 /* This function checks for errors in the HTTP request send API call. */
7820 /* */
7821 /* */
7822 /* INPUT */
7823 /* */
7824 /* client_ptr Pointer to HTTP client */
7825 /* wait_option Suspension option */
7826 /* */
7827 /* OUTPUT */
7828 /* */
7829 /* status Completion status */
7830 /* */
7831 /* CALLS */
7832 /* */
7833 /* _nxe_web_http_client_request_send Actual request send call */
7834 /* */
7835 /* CALLED BY */
7836 /* */
7837 /* Application Code */
7838 /* */
7839 /* RELEASE HISTORY */
7840 /* */
7841 /* DATE NAME DESCRIPTION */
7842 /* */
7843 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
7844 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
7845 /* resulting in version 6.1 */
7846 /* */
7847 /**************************************************************************/
_nxe_web_http_client_request_send(NX_WEB_HTTP_CLIENT * client_ptr,ULONG wait_option)7848 UINT _nxe_web_http_client_request_send(NX_WEB_HTTP_CLIENT *client_ptr, ULONG wait_option)
7849 {
7850 UINT status;
7851
7852 /* Make sure the client instance makes sense. */
7853 if(client_ptr == NX_NULL)
7854 {
7855 return(NX_PTR_ERROR);
7856 }
7857
7858 /* Now send the packet to the HTTP server. */
7859 status = _nx_web_http_client_request_send(client_ptr, wait_option);
7860
7861 /* Return success to the caller. */
7862 return(status);
7863 }
7864
7865
7866 /**************************************************************************/
7867 /* */
7868 /* FUNCTION RELEASE */
7869 /* */
7870 /* _nx_web_http_client_request_send PORTABLE C */
7871 /* 6.1 */
7872 /* AUTHOR */
7873 /* */
7874 /* Yuxin Zhou, Microsoft Corporation */
7875 /* */
7876 /* DESCRIPTION */
7877 /* */
7878 /* This function sends an HTTP request to a remote server. The request */
7879 /* being sent must have been initialized previously with a call to */
7880 /* nx_web_http_client_request_initialize. */
7881 /* */
7882 /* */
7883 /* INPUT */
7884 /* */
7885 /* client_ptr Pointer to HTTP client */
7886 /* wait_option Suspension option */
7887 /* */
7888 /* OUTPUT */
7889 /* */
7890 /* status Completion status */
7891 /* */
7892 /* CALLS */
7893 /* */
7894 /* nx_packet_data_append Append packet data */
7895 /* nx_packet_release release packet */
7896 /* _nx_web_http_client_error_exit Cleanup and shut down HTTPS */
7897 /* */
7898 /* CALLED BY */
7899 /* */
7900 /* Application Code */
7901 /* */
7902 /* RELEASE HISTORY */
7903 /* */
7904 /* DATE NAME DESCRIPTION */
7905 /* */
7906 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
7907 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
7908 /* resulting in version 6.1 */
7909 /* */
7910 /**************************************************************************/
_nx_web_http_client_request_send(NX_WEB_HTTP_CLIENT * client_ptr,ULONG wait_option)7911 UINT _nx_web_http_client_request_send(NX_WEB_HTTP_CLIENT *client_ptr, ULONG wait_option)
7912 {
7913 UINT status;
7914 NX_PACKET *packet_ptr;
7915 CHAR crlf[2] = {13,10};
7916
7917
7918 /* Make sure a request packet was allocated. */
7919 if(client_ptr -> nx_web_http_client_request_packet_ptr == NX_NULL)
7920 {
7921 return(NX_WEB_HTTP_ERROR);
7922 }
7923
7924 /* Get a pointer to our current request packet. */
7925 packet_ptr = client_ptr -> nx_web_http_client_request_packet_ptr;
7926
7927 /* Clear the request packet pointer. */
7928 client_ptr -> nx_web_http_client_request_packet_ptr = NX_NULL;
7929
7930 /* Place an extra cr/lf to signal the end of the HTTP header. */
7931 nx_packet_data_append(packet_ptr, crlf, 2,
7932 client_ptr -> nx_web_http_client_packet_pool_ptr, wait_option);
7933
7934 /* Now send the packet to the HTTP server. */
7935 status = _nx_web_http_client_send(client_ptr, packet_ptr, wait_option);
7936
7937 /* Determine if the send was successful. */
7938 if (status != NX_SUCCESS)
7939 {
7940
7941 /* No, send was not successful. */
7942
7943 /* Release the packet. */
7944 nx_packet_release(packet_ptr);
7945
7946 /* Disconnect and unbind the socket. */
7947 _nx_web_http_client_error_exit(client_ptr, wait_option);
7948
7949 /* Return an error. */
7950 return(status);
7951 }
7952
7953 /* Set the appropriate state. */
7954 switch(client_ptr -> nx_web_http_client_method)
7955 {
7956 case NX_WEB_HTTP_METHOD_GET:
7957 client_ptr -> nx_web_http_client_state = NX_WEB_HTTP_CLIENT_STATE_GET;
7958 break;
7959 case NX_WEB_HTTP_METHOD_PUT:
7960 client_ptr -> nx_web_http_client_state = NX_WEB_HTTP_CLIENT_STATE_PUT;
7961 break;
7962 case NX_WEB_HTTP_METHOD_POST:
7963 client_ptr -> nx_web_http_client_state = NX_WEB_HTTP_CLIENT_STATE_POST;
7964 break;
7965 case NX_WEB_HTTP_METHOD_DELETE:
7966 client_ptr -> nx_web_http_client_state = NX_WEB_HTTP_CLIENT_STATE_DELETE;
7967 break;
7968 case NX_WEB_HTTP_METHOD_HEAD:
7969 client_ptr -> nx_web_http_client_state = NX_WEB_HTTP_CLIENT_STATE_HEAD;
7970 break;
7971 case NX_WEB_HTTP_METHOD_NONE:
7972 default:
7973 status = NX_WEB_HTTP_METHOD_ERROR;
7974 break;
7975 }
7976
7977
7978 /* Return success to the caller. */
7979 return(status);
7980 }
7981
7982
7983 /**************************************************************************/
7984 /* */
7985 /* FUNCTION RELEASE */
7986 /* */
7987 /* _nxe_web_http_client_request_packet_allocate PORTABLE C */
7988 /* 6.1 */
7989 /* AUTHOR */
7990 /* */
7991 /* Yuxin Zhou, Microsoft Corporation */
7992 /* */
7993 /* DESCRIPTION */
7994 /* */
7995 /* This function checks for errors in the call to allocate packets for */
7996 /* an HTTP(S) client session, as used for PUT and POST operations. */
7997 /* */
7998 /* */
7999 /* INPUT */
8000 /* */
8001 /* client_ptr Pointer to HTTP client */
8002 /* packet_ptr Pointer to allocated packet */
8003 /* wait_option Suspension option */
8004 /* */
8005 /* OUTPUT */
8006 /* */
8007 /* status Completion status */
8008 /* */
8009 /* CALLS */
8010 /* */
8011 /* _nxe_web_http_client_request_packet_allocate */
8012 /* Actual packet allocation call */
8013 /* */
8014 /* CALLED BY */
8015 /* */
8016 /* Application Code */
8017 /* */
8018 /* RELEASE HISTORY */
8019 /* */
8020 /* DATE NAME DESCRIPTION */
8021 /* */
8022 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
8023 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
8024 /* resulting in version 6.1 */
8025 /* */
8026 /**************************************************************************/
_nxe_web_http_client_request_packet_allocate(NX_WEB_HTTP_CLIENT * client_ptr,NX_PACKET ** packet_ptr,UINT wait_option)8027 UINT _nxe_web_http_client_request_packet_allocate(NX_WEB_HTTP_CLIENT *client_ptr, NX_PACKET **packet_ptr,
8028 UINT wait_option)
8029 {
8030 UINT status;
8031
8032 /* Check our pointers. */
8033 if(client_ptr == NX_NULL || packet_ptr == NX_NULL)
8034 {
8035 return(NX_PTR_ERROR);
8036 }
8037
8038 /* Call the actual function. */
8039 status = _nx_web_http_client_request_packet_allocate(client_ptr, packet_ptr, wait_option);
8040
8041 return(status);
8042 }
8043
8044
8045 /**************************************************************************/
8046 /* */
8047 /* FUNCTION RELEASE */
8048 /* */
8049 /* _nx_web_http_client_request_packet_allocate PORTABLE C */
8050 /* 6.1 */
8051 /* AUTHOR */
8052 /* */
8053 /* Yuxin Zhou, Microsoft Corporation */
8054 /* */
8055 /* DESCRIPTION */
8056 /* */
8057 /* This function allocates a packet for Client HTTP(S) requests so */
8058 /* that clients needing to send large amounts of data (such as for */
8059 /* multi-part file upload) can allocated the needed packets and send */
8060 /* them with nx_web_http_client_request_packet_send. Note that the */
8061 /* appropriate headers must have been sent in the initial request. */
8062 /* Headers can be added to the HTTP request with */
8063 /* _nx_web_http_client_request_header_add. */
8064 /* */
8065 /* */
8066 /* INPUT */
8067 /* */
8068 /* client_ptr Pointer to HTTP client */
8069 /* packet_ptr Pointer to allocated packet */
8070 /* wait_option Suspension option */
8071 /* */
8072 /* OUTPUT */
8073 /* */
8074 /* status Completion status */
8075 /* */
8076 /* CALLS */
8077 /* */
8078 /* nx_secure_tls_packet_allocate Allocate a TLS packet */
8079 /* nx_packet_allocate Allocate a TCP packet */
8080 /* */
8081 /* CALLED BY */
8082 /* */
8083 /* Application Code */
8084 /* */
8085 /* RELEASE HISTORY */
8086 /* */
8087 /* DATE NAME DESCRIPTION */
8088 /* */
8089 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
8090 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
8091 /* resulting in version 6.1 */
8092 /* */
8093 /**************************************************************************/
_nx_web_http_client_request_packet_allocate(NX_WEB_HTTP_CLIENT * client_ptr,NX_PACKET ** packet_ptr,UINT wait_option)8094 UINT _nx_web_http_client_request_packet_allocate(NX_WEB_HTTP_CLIENT *client_ptr, NX_PACKET **packet_ptr, UINT wait_option)
8095 {
8096 UINT status;
8097 NXD_ADDRESS *server_ip;
8098
8099 /* Get worker variables for use. */
8100 server_ip = &(client_ptr->nx_web_http_client_server_address);
8101
8102 #ifdef NX_WEB_HTTPS_ENABLE
8103 /* Allocate a packet for the GET (or POST) message. */
8104 if(client_ptr->nx_web_http_client_is_https)
8105 {
8106 status = nx_secure_tls_packet_allocate(&(client_ptr->nx_web_http_client_tls_session), client_ptr -> nx_web_http_client_packet_pool_ptr,
8107 packet_ptr, wait_option);
8108 }
8109 else
8110 #endif
8111 if (server_ip -> nxd_ip_version == NX_IP_VERSION_V4)
8112 {
8113 status = nx_packet_allocate(client_ptr -> nx_web_http_client_packet_pool_ptr,
8114 packet_ptr,
8115 NX_IPv4_TCP_PACKET, wait_option);
8116 }
8117 else
8118 {
8119
8120 status = nx_packet_allocate(client_ptr -> nx_web_http_client_packet_pool_ptr,
8121 packet_ptr,
8122 NX_IPv6_TCP_PACKET, wait_option);
8123 }
8124
8125
8126 return(status);
8127 }
8128
8129 /**************************************************************************/
8130 /* */
8131 /* FUNCTION RELEASE */
8132 /* */
8133 /* _nxe_web_http_client_response_header_callback_set PORTABLE C */
8134 /* 6.1 */
8135 /* AUTHOR */
8136 /* */
8137 /* Yuxin Zhou, Microsoft Corporation */
8138 /* */
8139 /* DESCRIPTION */
8140 /* */
8141 /* This function checks for errors in the set response callback */
8142 /* routine, */
8143 /* */
8144 /* */
8145 /* INPUT */
8146 /* */
8147 /* client_ptr Pointer to HTTP client */
8148 /* callback_function Pointer to callback routine */
8149 /* */
8150 /* OUTPUT */
8151 /* */
8152 /* status Completion status */
8153 /* */
8154 /* CALLS */
8155 /* */
8156 /* _nx_web_http_client_response_header_callback_set */
8157 /* Actual set routine */
8158 /* */
8159 /* CALLED BY */
8160 /* */
8161 /* Application Code */
8162 /* */
8163 /* RELEASE HISTORY */
8164 /* */
8165 /* DATE NAME DESCRIPTION */
8166 /* */
8167 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
8168 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
8169 /* resulting in version 6.1 */
8170 /* */
8171 /**************************************************************************/
_nxe_web_http_client_response_header_callback_set(NX_WEB_HTTP_CLIENT * client_ptr,VOID (* callback_function)(NX_WEB_HTTP_CLIENT * client_ptr,CHAR * field_name,UINT field_name_length,CHAR * field_value,UINT field_value_length))8172 UINT _nxe_web_http_client_response_header_callback_set(NX_WEB_HTTP_CLIENT *client_ptr,
8173 VOID (*callback_function)(NX_WEB_HTTP_CLIENT *client_ptr,
8174 CHAR *field_name,
8175 UINT field_name_length,
8176 CHAR *field_value,
8177 UINT field_value_length))
8178 {
8179 UINT status;
8180
8181
8182 /* Check for NULL pointers. */
8183 if(client_ptr == NX_NULL || callback_function == NX_NULL)
8184 {
8185 return(NX_PTR_ERROR);
8186 }
8187
8188 /* Invoke the real function. */
8189 status = _nx_web_http_client_response_header_callback_set(client_ptr, callback_function);
8190
8191 return(status);
8192 }
8193
8194 /**************************************************************************/
8195 /* */
8196 /* FUNCTION RELEASE */
8197 /* */
8198 /* _nx_web_http_client_response_header_callback_set PORTABLE C */
8199 /* 6.1 */
8200 /* AUTHOR */
8201 /* */
8202 /* Yuxin Zhou, Microsoft Corporation */
8203 /* */
8204 /* DESCRIPTION */
8205 /* */
8206 /* This function sets a callback routine to be invoked when the HTTP */
8207 /* client receives a response from the remote server. The callback */
8208 /* allows the application to process the HTTP headers beyond the */
8209 /* normal processing done by the NetX Web HTTP library. */
8210 /* */
8211 /* */
8212 /* INPUT */
8213 /* */
8214 /* client_ptr Pointer to HTTP client */
8215 /* callback_function Pointer to callback routine */
8216 /* */
8217 /* OUTPUT */
8218 /* */
8219 /* status Completion status */
8220 /* */
8221 /* CALLS */
8222 /* */
8223 /* None */
8224 /* */
8225 /* CALLED BY */
8226 /* */
8227 /* Application Code */
8228 /* */
8229 /* RELEASE HISTORY */
8230 /* */
8231 /* DATE NAME DESCRIPTION */
8232 /* */
8233 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
8234 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
8235 /* resulting in version 6.1 */
8236 /* */
8237 /**************************************************************************/
_nx_web_http_client_response_header_callback_set(NX_WEB_HTTP_CLIENT * client_ptr,VOID (* callback_function)(NX_WEB_HTTP_CLIENT * client_ptr,CHAR * field_name,UINT field_name_length,CHAR * field_value,UINT field_value_length))8238 UINT _nx_web_http_client_response_header_callback_set(NX_WEB_HTTP_CLIENT *client_ptr,
8239 VOID (*callback_function)(NX_WEB_HTTP_CLIENT *client_ptr,
8240 CHAR *field_name,
8241 UINT field_name_length,
8242 CHAR *field_value,
8243 UINT field_value_length))
8244 {
8245
8246 /* Assign the function pointer to the HTTP client. */
8247 client_ptr -> nx_web_http_client_response_callback = callback_function;
8248
8249 return(NX_SUCCESS);
8250 }
8251
8252
8253 /**************************************************************************/
8254 /* */
8255 /* FUNCTION RELEASE */
8256 /* */
8257 /* _nx_web_http_client_send PORTABLE C */
8258 /* 6.1 */
8259 /* AUTHOR */
8260 /* */
8261 /* Yuxin Zhou, Microsoft Corporation */
8262 /* */
8263 /* DESCRIPTION */
8264 /* */
8265 /* This function sends data to the remote server using either the TCP */
8266 /* socket for plain HTTP or the TLS session for HTTPS. */
8267 /* */
8268 /* */
8269 /* INPUT */
8270 /* */
8271 /* client_ptr Pointer to HTTP client */
8272 /* packet_ptr Pointer to packet to send. */
8273 /* wait_option Indicates behavior if packet */
8274 /* cannot be sent. */
8275 /* */
8276 /* OUTPUT */
8277 /* */
8278 /* status Completion status */
8279 /* */
8280 /* CALLS */
8281 /* */
8282 /* nx_secure_tls_session_send Send data using TLS session */
8283 /* nx_secure_tcp_socket_send Send data using TCP socket */
8284 /* */
8285 /* CALLED BY */
8286 /* */
8287 /* _nx_web_http_client_put_packet */
8288 /* _nx_web_http_client_request_send */
8289 /* */
8290 /* RELEASE HISTORY */
8291 /* */
8292 /* DATE NAME DESCRIPTION */
8293 /* */
8294 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
8295 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
8296 /* resulting in version 6.1 */
8297 /* */
8298 /**************************************************************************/
_nx_web_http_client_send(NX_WEB_HTTP_CLIENT * client_ptr,NX_PACKET * packet_ptr,ULONG wait_option)8299 UINT _nx_web_http_client_send(NX_WEB_HTTP_CLIENT *client_ptr, NX_PACKET *packet_ptr, ULONG wait_option)
8300 {
8301
8302 UINT status;
8303
8304 #ifdef NX_WEB_HTTPS_ENABLE
8305 /* End TLS session if using HTTPS. */
8306 if(client_ptr -> nx_web_http_client_is_https)
8307 {
8308 status = nx_secure_tls_session_send(&(client_ptr -> nx_web_http_client_tls_session), packet_ptr, wait_option);
8309 }
8310 else
8311 #endif
8312 {
8313 status = nx_tcp_socket_send(&(client_ptr -> nx_web_http_client_socket), packet_ptr, wait_option);
8314 }
8315
8316 /* Return status. */
8317 return(status);
8318 }
8319
8320
8321 /**************************************************************************/
8322 /* */
8323 /* FUNCTION RELEASE */
8324 /* */
8325 /* _nx_web_http_client_receive PORTABLE C */
8326 /* 6.1 */
8327 /* AUTHOR */
8328 /* */
8329 /* Yuxin Zhou, Microsoft Corporation */
8330 /* */
8331 /* DESCRIPTION */
8332 /* */
8333 /* This function receives data from the remote server using either the */
8334 /* TCP socket for plain HTTP or the TLS session for HTTPS. */
8335 /* */
8336 /* */
8337 /* INPUT */
8338 /* */
8339 /* client_ptr Pointer to HTTP client */
8340 /* packet_ptr Pointer to packet to send. */
8341 /* wait_option Indicates behavior if packet */
8342 /* cannot be received */
8343 /* */
8344 /* OUTPUT */
8345 /* */
8346 /* status Completion status */
8347 /* */
8348 /* CALLS */
8349 /* */
8350 /* nx_secure_tls_session_receive Receive data using TLS */
8351 /* nx_secure_tcp_socket_receive Receive data using TCP */
8352 /* */
8353 /* CALLED BY */
8354 /* */
8355 /* */
8356 /* */
8357 /* RELEASE HISTORY */
8358 /* */
8359 /* DATE NAME DESCRIPTION */
8360 /* */
8361 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
8362 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
8363 /* resulting in version 6.1 */
8364 /* */
8365 /**************************************************************************/
_nx_web_http_client_receive(NX_WEB_HTTP_CLIENT * client_ptr,NX_PACKET ** packet_ptr,ULONG wait_option)8366 UINT _nx_web_http_client_receive(NX_WEB_HTTP_CLIENT *client_ptr, NX_PACKET **packet_ptr, ULONG wait_option)
8367 {
8368
8369 UINT status;
8370
8371 #ifdef NX_WEB_HTTPS_ENABLE
8372 /* End TLS session if using HTTPS. */
8373 if(client_ptr -> nx_web_http_client_is_https)
8374 {
8375 status = nx_secure_tls_session_receive(&(client_ptr -> nx_web_http_client_tls_session), packet_ptr, wait_option);
8376 }
8377 else
8378 #endif
8379 {
8380 status = nx_tcp_socket_receive(&(client_ptr -> nx_web_http_client_socket), packet_ptr, wait_option);
8381 }
8382
8383 /* Return status. */
8384 return(status);
8385 }
8386
8387
8388 /**************************************************************************/
8389 /* */
8390 /* FUNCTION RELEASE */
8391 /* */
8392 /* _nx_web_https_client_error_exit PORTABLE C */
8393 /* 6.1 */
8394 /* AUTHOR */
8395 /* */
8396 /* Yuxin Zhou, Microsoft Corporation */
8397 /* */
8398 /* DESCRIPTION */
8399 /* */
8400 /* This function is used whenever there is an error in the HTTP client */
8401 /* and the port needs to be unbound. If the client is using TLS for */
8402 /* HTTPS, then it also needs to end the TLS session. */
8403 /* */
8404 /* */
8405 /* INPUT */
8406 /* */
8407 /* client_ptr Pointer to HTTP client */
8408 /* error_number Error status in caller */
8409 /* */
8410 /* OUTPUT */
8411 /* */
8412 /* status Completion status */
8413 /* */
8414 /* CALLS */
8415 /* */
8416 /* nx_tcp_client_socket_unbind Unbind TCP port */
8417 /* nx_secure_tls_session_delete Delete TLS session */
8418 /* nx_secure_tls_session_end End TLS session */
8419 /* nx_tcp_socket_disconnect Close TCP socket */
8420 /* */
8421 /* CALLED BY */
8422 /* */
8423 /* */
8424 /* */
8425 /* RELEASE HISTORY */
8426 /* */
8427 /* DATE NAME DESCRIPTION */
8428 /* */
8429 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
8430 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
8431 /* resulting in version 6.1 */
8432 /* */
8433 /**************************************************************************/
_nx_web_http_client_error_exit(NX_WEB_HTTP_CLIENT * client_ptr,UINT wait_option)8434 VOID _nx_web_http_client_error_exit(NX_WEB_HTTP_CLIENT *client_ptr, UINT wait_option)
8435 {
8436 #ifdef NX_WEB_HTTPS_ENABLE
8437 /* End TLS session if using HTTPS. */
8438 if(client_ptr -> nx_web_http_client_is_https)
8439 {
8440 nx_secure_tls_session_end(&(client_ptr -> nx_web_http_client_tls_session), NX_WAIT_FOREVER);
8441 nx_secure_tls_session_delete(&(client_ptr -> nx_web_http_client_tls_session));
8442 }
8443 #endif
8444
8445 nx_tcp_socket_disconnect(&(client_ptr -> nx_web_http_client_socket), wait_option);
8446 nx_tcp_client_socket_unbind(&(client_ptr -> nx_web_http_client_socket));
8447
8448 }
8449
8450
8451 /**************************************************************************/
8452 /* */
8453 /* FUNCTION RELEASE */
8454 /* */
8455 /* _nx_web_https_client_cleanup PORTABLE C */
8456 /* 6.1 */
8457 /* AUTHOR */
8458 /* */
8459 /* Yuxin Zhou, Microsoft Corporation */
8460 /* */
8461 /* DESCRIPTION */
8462 /* */
8463 /* This function is used to clean up the temporary variables and reset */
8464 /* the state. */
8465 /* */
8466 /* */
8467 /* INPUT */
8468 /* */
8469 /* client_ptr Pointer to HTTP client */
8470 /* error_number Error status in caller */
8471 /* */
8472 /* OUTPUT */
8473 /* */
8474 /* None */
8475 /* */
8476 /* CALLS */
8477 /* */
8478 /* _nx_web_http_client_receive Receive a packet from server */
8479 /* */
8480 /* CALLED BY */
8481 /* */
8482 /* */
8483 /* */
8484 /* RELEASE HISTORY */
8485 /* */
8486 /* DATE NAME DESCRIPTION */
8487 /* */
8488 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
8489 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
8490 /* resulting in version 6.1 */
8491 /* */
8492 /**************************************************************************/
_nx_web_http_client_cleanup(NX_WEB_HTTP_CLIENT * client_ptr)8493 VOID _nx_web_http_client_cleanup(NX_WEB_HTTP_CLIENT *client_ptr)
8494 {
8495 UINT status;
8496 NX_PACKET *response_packet_ptr;
8497
8498 /* Receive the early response from server. */
8499 while(1)
8500 {
8501 status = _nx_web_http_client_receive(client_ptr, &response_packet_ptr, NX_NO_WAIT);
8502
8503 if (status)
8504 {
8505 break;
8506 }
8507 else
8508 {
8509 nx_packet_release(response_packet_ptr);
8510 }
8511 }
8512
8513 /* Clean up the temporary variables. */
8514 client_ptr -> nx_web_http_client_total_transfer_bytes = 0;
8515
8516 client_ptr -> nx_web_http_client_actual_bytes_transferred = 0;
8517
8518 client_ptr -> nx_web_http_client_total_receive_bytes = 0;
8519
8520 client_ptr -> nx_web_http_client_actual_bytes_received = 0;
8521
8522 client_ptr -> nx_web_http_client_response_header_received = NX_FALSE;
8523
8524 /* Release the request packet. */
8525 if (client_ptr -> nx_web_http_client_request_packet_ptr)
8526 {
8527 nx_packet_release(client_ptr -> nx_web_http_client_request_packet_ptr);
8528 client_ptr -> nx_web_http_client_request_packet_ptr = NX_NULL;
8529 }
8530
8531 client_ptr -> nx_web_http_client_request_chunked = NX_FALSE;
8532
8533 client_ptr -> nx_web_http_client_response_chunked = NX_FALSE;
8534
8535 client_ptr -> nx_web_http_client_chunked_response_remaining_size = 0;
8536
8537 /* Release the response packet. */
8538 if (client_ptr -> nx_web_http_client_response_packet)
8539 {
8540 nx_packet_release(client_ptr -> nx_web_http_client_response_packet);
8541 client_ptr -> nx_web_http_client_response_packet = NX_NULL;
8542 }
8543
8544 /* Reset the state to ready. */
8545 client_ptr -> nx_web_http_client_state = NX_WEB_HTTP_CLIENT_STATE_READY;
8546 }
8547
8548