fix prefix id passing
[project/uclient.git] / uclient-example.c
index b66468a..c8f0b1b 100644 (file)
@@ -1,4 +1,6 @@
 #include <libubox/blobmsg.h>
+#include <unistd.h>
+#include <stdio.h>
 
 #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);
 }