1 #ifndef __LIBUBOX_UCLIENT_H
2 #define __LIBUBOX_UCLIENT_H
4 #include <libubox/blob.h>
5 #include <libubox/ustream.h>
6 #include <libubox/ustream-ssl.h>
9 struct uclient_backend;
11 enum uclient_error_code {
12 UCLIENT_ERROR_UNKNOWN,
13 UCLIENT_ERROR_CONNECT,
14 UCLIENT_ERROR_SSL_INVALID_CERT,
15 UCLIENT_ERROR_SSL_CN_MISMATCH,
19 const struct uclient_backend *backend;
20 const struct uclient_cb *cb;
22 struct uclient_url *url;
28 struct blob_attr *meta;
30 struct uloop_timeout timeout;
34 void (*data_read)(struct uclient *cl);
35 void (*data_sent)(struct uclient *cl);
36 void (*data_eof)(struct uclient *cl);
37 void (*header_done)(struct uclient *cl);
38 void (*error)(struct uclient *cl, int code);
41 struct uclient *uclient_new(const char *url, const struct uclient_cb *cb);
42 void uclient_free(struct uclient *cl);
44 int uclient_connect_url(struct uclient *cl, const char *url_str);
46 static inline int uclient_connect(struct uclient *cl)
48 return uclient_connect_url(cl, NULL);
52 int uclient_read(struct uclient *cl, char *buf, int len);
53 int uclient_write(struct uclient *cl, char *buf, int len);
54 int uclient_request(struct uclient *cl);
57 extern const struct uclient_backend uclient_backend_http;
59 int uclient_http_set_header(struct uclient *cl, const char *name, const char *value);
60 int uclient_http_reset_headers(struct uclient *cl, const char *name, const char *value);
61 int uclient_http_set_request_type(struct uclient *cl, const char *type);
62 bool uclient_http_redirect(struct uclient *cl);
64 int uclient_http_set_ssl_ctx(struct uclient *cl, struct ustream_ssl_ctx *ctx, bool require_validation);