1 #include <libubox/blobmsg.h>
5 static void example_header_done(struct uclient
*cl
)
10 fprintf(stderr
, "Headers: \n");
11 blobmsg_for_each_attr(cur
, cl
->meta
, rem
) {
12 fprintf(stderr
, "%s=%s\n", blobmsg_name(cur
), (char *) blobmsg_data(cur
));
15 fprintf(stderr
, "Contents:\n");
18 static void example_read_data(struct uclient
*cl
)
24 len
= uclient_read(cl
, buf
, sizeof(buf
));
28 fwrite(buf
, len
, 1, stderr
);
32 static void example_request_sm(struct uclient
*cl
)
39 uclient_http_set_request_type(cl
, "HEAD");
44 uclient_http_set_request_type(cl
, "GET");
54 static void example_eof(struct uclient
*cl
)
56 example_request_sm(cl
);
59 static const struct uclient_cb cb
= {
60 .header_done
= example_header_done
,
61 .data_read
= example_read_data
,
62 .data_eof
= example_eof
,
65 int main(int argc
, char **argv
)
70 fprintf(stderr
, "Usage: %s <URL>\n", argv
[0]);
75 cl
= uclient_new(argv
[1], &cb
);
77 fprintf(stderr
, "Failed to allocate uclient context\n");
80 example_request_sm(cl
);