https_client.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // SPDX-License-Identifier: GPL-3.0-or-later
  2. #ifndef NETDATA_HTTPS_CLIENT_H
  3. #define NETDATA_HTTPS_CLIENT_H
  4. #include "libnetdata/libnetdata.h"
  5. typedef enum http_req_type {
  6. HTTP_REQ_GET = 0,
  7. HTTP_REQ_POST,
  8. HTTP_REQ_CONNECT
  9. } http_req_type_t;
  10. typedef struct {
  11. http_req_type_t request_type;
  12. char *host;
  13. int port;
  14. char *url;
  15. time_t timeout_s; //timeout in seconds for the network operation (send/recv)
  16. void *payload;
  17. size_t payload_size;
  18. char *proxy_host;
  19. int proxy_port;
  20. } https_req_t;
  21. typedef struct {
  22. int http_code;
  23. void *payload;
  24. size_t payload_size;
  25. } https_req_response_t;
  26. // Non feature complete URL parser
  27. // feel free to extend when needed
  28. // currently implements only what ACLK
  29. // needs
  30. // proto://host[:port]/path
  31. typedef struct {
  32. char *proto;
  33. char *host;
  34. int port;
  35. char* path;
  36. } url_t;
  37. int url_parse(const char *url, url_t *parsed);
  38. void url_t_destroy(url_t *url);
  39. void https_req_response_free(https_req_response_t *res);
  40. void https_req_response_init(https_req_response_t *res);
  41. #define HTTPS_REQ_RESPONSE_T_INITIALIZER \
  42. { \
  43. .http_code = 0, \
  44. .payload = NULL, \
  45. .payload_size = 0 \
  46. }
  47. #define HTTPS_REQ_T_INITIALIZER \
  48. { \
  49. .request_type = HTTP_REQ_GET, \
  50. .host = NULL, \
  51. .port = 443, \
  52. .url = NULL, \
  53. .timeout_s = 30, \
  54. .payload = NULL, \
  55. .payload_size = 0, \
  56. .proxy_host = NULL, \
  57. .proxy_port = 8080 \
  58. }
  59. int https_request(https_req_t *request, https_req_response_t *response);
  60. #endif /* NETDATA_HTTPS_CLIENT_H */