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