X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fuclient.git;a=blobdiff_plain;f=uclient-example.c;h=c8f0b1b7847dcab44bba4df7e9e7af6f139b6e2f;hp=b66468a7fb7a598be5ad8506ebb1a965afbfa776;hb=8bbe2130890db78856bb5731fa3e16a71d549bfe;hpb=c280d54e1bc79de4424fabc3fad011cc15587b81 diff --git a/uclient-example.c b/uclient-example.c index b66468a..c8f0b1b 100644 --- a/uclient-example.c +++ b/uclient-example.c @@ -1,4 +1,6 @@ #include +#include +#include #include "uclient.h" @@ -7,12 +9,12 @@ static void example_header_done(struct uclient *cl) struct blob_attr *cur; int rem; - fprintf(stderr, "Headers: \n"); + printf("Headers (%d): \n", cl->status_code); blobmsg_for_each_attr(cur, cl->meta, rem) { - fprintf(stderr, "%s=%s\n", blobmsg_name(cur), (char *) blobmsg_data(cur)); + printf("%s=%s\n", blobmsg_name(cur), (char *) blobmsg_data(cur)); } - fprintf(stderr, "Contents:\n"); + printf("Contents:\n"); } static void example_read_data(struct uclient *cl) @@ -25,7 +27,7 @@ static void example_read_data(struct uclient *cl) if (!len) return; - fwrite(buf, len, 1, stderr); + write(STDOUT_FILENO, buf, len); } } @@ -53,6 +55,14 @@ static void example_request_sm(struct uclient *cl) static void example_eof(struct uclient *cl) { + static int retries; + + if (retries < 10 && uclient_http_redirect(cl)) { + retries++; + return; + } + + retries = 0; example_request_sm(cl); }