utils_httpc.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * Tencent is pleased to support the open source community by making IoT Hub
  3. available.
  4. * Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.
  5. * Licensed under the MIT License (the "License"); you may not use this file
  6. except in
  7. * compliance with the License. You may obtain a copy of the License at
  8. * http://opensource.org/licenses/MIT
  9. * Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is
  11. * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  12. KIND,
  13. * either express or implied. See the License for the specific language
  14. governing permissions and
  15. * limitations under the License.
  16. *
  17. */
  18. #ifndef QCLOUD_IOT_UTILS_HTTPC_H_
  19. #define QCLOUD_IOT_UTILS_HTTPC_H_
  20. #ifdef __cplusplus
  21. extern "C" {
  22. #endif
  23. #include <stdbool.h>
  24. #include "network_interface.h"
  25. #define HTTP_PORT 80
  26. #define HTTPS_PORT 443
  27. typedef enum { HTTP_GET, HTTP_POST, HTTP_PUT, HTTP_DELETE, HTTP_HEAD } HttpMethod;
  28. typedef struct {
  29. unsigned char profile_idx;
  30. int remote_port;
  31. int response_code;
  32. char * header;
  33. char * auth_user;
  34. char * auth_password;
  35. qcloud_Network network_stack;
  36. } HTTPClient;
  37. typedef struct {
  38. bool is_more; // if more data to check
  39. bool is_chunked; // if response in chunked data
  40. int retrieve_len; // length of retrieve
  41. int response_content_len; // length of resposne content
  42. int post_buf_len; // post data length
  43. int response_buf_len; // length of response data buffer
  44. char *post_content_type; // type of post content
  45. char *post_buf; // post data buffer
  46. char *response_buf; // response data buffer
  47. } HTTPClientData;
  48. /**
  49. * @brief do one http request
  50. *
  51. * @param client http client
  52. * @param url server url
  53. * @param port server port
  54. * @param ca_crt_dir ca path
  55. * @param method type of request
  56. * @param client_data http data
  57. * @return QCLOUD_RET_SUCCESS for success, or err code for failure
  58. */
  59. int qcloud_http_client_common(HTTPClient *client, const char *url, int port, const char *ca_crt, HttpMethod method,
  60. HTTPClientData *client_data);
  61. int qcloud_http_recv_data(HTTPClient *client, uint32_t timeout_ms, HTTPClientData *client_data);
  62. int qcloud_http_client_connect(HTTPClient *client, const char *url, int port, const char *ca_crt);
  63. void qcloud_http_client_close(HTTPClient *client);
  64. #ifdef __cplusplus
  65. }
  66. #endif
  67. #endif /* QCLOUD_IOT_UTILS_HTTPC_H_ */