uclient.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #ifndef __LIBUBOX_UCLIENT_H
  2. #define __LIBUBOX_UCLIENT_H
  3. #include <libubox/blob.h>
  4. #include <libubox/ustream.h>
  5. #include <libubox/ustream-ssl.h>
  6. struct uclient_cb;
  7. struct uclient_backend;
  8. struct uclient {
  9. const struct uclient_backend *backend;
  10. const struct uclient_cb *cb;
  11. struct uclient_url *url;
  12. void *priv;
  13. bool eof;
  14. bool error;
  15. int status_code;
  16. struct blob_attr *meta;
  17. struct uloop_timeout timeout;
  18. };
  19. struct uclient_cb {
  20. void (*data_read)(struct uclient *cl);
  21. void (*data_sent)(struct uclient *cl);
  22. void (*data_eof)(struct uclient *cl);
  23. void (*header_done)(struct uclient *cl);
  24. void (*error)(struct uclient *cl);
  25. };
  26. struct uclient *uclient_new(const char *url, const struct uclient_cb *cb);
  27. void uclient_free(struct uclient *cl);
  28. int uclient_connect_url(struct uclient *cl, const char *url_str);
  29. static inline int uclient_connect(struct uclient *cl)
  30. {
  31. return uclient_connect_url(cl, NULL);
  32. }
  33. int uclient_read(struct uclient *cl, char *buf, int len);
  34. int uclient_write(struct uclient *cl, char *buf, int len);
  35. int uclient_request(struct uclient *cl);
  36. /* HTTP */
  37. int uclient_http_set_header(struct uclient *cl, const char *name, const char *value);
  38. int uclient_http_reset_headers(struct uclient *cl, const char *name, const char *value);
  39. int uclient_http_set_request_type(struct uclient *cl, const char *type);
  40. #endif