parse the http response code
authorFelix Fietkau <nbd@openwrt.org>
Sat, 22 Mar 2014 17:30:09 +0000 (18:30 +0100)
committerFelix Fietkau <nbd@openwrt.org>
Sat, 22 Mar 2014 17:30:09 +0000 (18:30 +0100)
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
uclient-example.c
uclient-http.c

index 07b330dc308edded71541938d1aecab5bf0d75fd..05f344da2316bae4572c909018ae22cb3b5c823a 100644 (file)
@@ -9,7 +9,7 @@ static void example_header_done(struct uclient *cl)
        struct blob_attr *cur;
        int rem;
 
-       printf("Headers: \n");
+       printf("Headers (%d): \n", cl->status_code);
        blobmsg_for_each_attr(cur, cl->meta, rem) {
                printf("%s=%s\n", blobmsg_name(cur), (char *) blobmsg_data(cur));
        }
index c344513d8c7c4722e1a34f3f03e6d016a4eb0f8a..ef44a40645f65fcc54bbef3a81ed692c68798eff 100644 (file)
@@ -501,6 +501,19 @@ static void uclient_parse_http_line(struct uclient_http *uh, char *data)
        char *sep;
 
        if (uh->state == HTTP_STATE_REQUEST_DONE) {
+               char *code;
+
+               /* HTTP/1.1 */
+               strsep(&data, " ");
+
+               code = strsep(&data, " ");
+               if (!code)
+                       goto error;
+
+               uh->uc.status_code = strtoul(code, &sep, 10);
+               if (sep && *sep)
+                       goto error;
+
                uh->state = HTTP_STATE_RECV_HEADERS;
                return;
        }
@@ -524,6 +537,12 @@ static void uclient_parse_http_line(struct uclient_http *uh, char *data)
                sep++;
 
        blobmsg_add_string(&uh->meta, name, sep);
+       return;
+
+error:
+       uh->uc.status_code = 400;
+       uh->eof = true;
+       uclient_notify_eof(uh);
 }
 
 static void __uclient_notify_read(struct uclient_http *uh)