make uclient_backend_http visible to allow the client to test for it
[project/uclient.git] / uclient.h
1 #ifndef __LIBUBOX_UCLIENT_H
2 #define __LIBUBOX_UCLIENT_H
3
4 #include <libubox/blob.h>
5 #include <libubox/ustream.h>
6 #include <libubox/ustream-ssl.h>
7
8 struct uclient_cb;
9 struct uclient_backend;
10
11 struct uclient {
12         const struct uclient_backend *backend;
13         const struct uclient_cb *cb;
14
15         struct uclient_url *url;
16         void *priv;
17
18         bool eof;
19         bool error;
20         int status_code;
21         struct blob_attr *meta;
22
23         struct uloop_timeout timeout;
24 };
25
26 struct uclient_cb {
27         void (*data_read)(struct uclient *cl);
28         void (*data_sent)(struct uclient *cl);
29         void (*data_eof)(struct uclient *cl);
30         void (*header_done)(struct uclient *cl);
31         void (*error)(struct uclient *cl);
32 };
33
34 struct uclient *uclient_new(const char *url, const struct uclient_cb *cb);
35 void uclient_free(struct uclient *cl);
36
37 int uclient_connect_url(struct uclient *cl, const char *url_str);
38
39 static inline int uclient_connect(struct uclient *cl)
40 {
41         return uclient_connect_url(cl, NULL);
42 }
43
44
45 int uclient_read(struct uclient *cl, char *buf, int len);
46 int uclient_write(struct uclient *cl, char *buf, int len);
47 int uclient_request(struct uclient *cl);
48
49 /* HTTP */
50 extern const struct uclient_backend uclient_backend_http;
51
52 int uclient_http_set_header(struct uclient *cl, const char *name, const char *value);
53 int uclient_http_reset_headers(struct uclient *cl, const char *name, const char *value);
54 int uclient_http_set_request_type(struct uclient *cl, const char *type);
55
56 #endif