1 #include <libubox/blobmsg.h>
7 static void example_header_done(struct uclient *cl)
12 printf("Headers: \n");
13 blobmsg_for_each_attr(cur, cl->meta, rem) {
14 printf("%s=%s\n", blobmsg_name(cur), (char *) blobmsg_data(cur));
17 printf("Contents:\n");
20 static void example_read_data(struct uclient *cl)
26 len = uclient_read(cl, buf, sizeof(buf));
30 write(STDOUT_FILENO, buf, len);
34 static void example_request_sm(struct uclient *cl)
41 uclient_http_set_request_type(cl, "HEAD");
46 uclient_http_set_request_type(cl, "GET");
56 static void example_eof(struct uclient *cl)
58 example_request_sm(cl);
61 static const struct uclient_cb cb = {
62 .header_done = example_header_done,
63 .data_read = example_read_data,
64 .data_eof = example_eof,
67 int main(int argc, char **argv)
72 fprintf(stderr, "Usage: %s <URL>\n", argv[0]);
77 cl = uclient_new(argv[1], &cb);
79 fprintf(stderr, "Failed to allocate uclient context\n");
82 example_request_sm(cl);