auc: update to version 0.2.1
authorDaniel Golle <daniel@makrotopia.org>
Wed, 18 Aug 2021 18:30:56 +0000 (19:30 +0100)
committerDaniel Golle <daniel@makrotopia.org>
Wed, 18 Aug 2021 18:33:41 +0000 (19:33 +0100)
Brings support for future connexion based API.

Signed-off-by: Daniel Golle <daniel@makrotopia.org>
utils/auc/Makefile
utils/auc/src/auc.c

index c8f1d9187a1dc9b2b060806b9062d4bc4610e3ec..b267a8392315249d8f45d4cf5e4afc09a0059bfc 100644 (file)
@@ -5,7 +5,7 @@
 include $(TOPDIR)/rules.mk
 
 PKG_NAME:=auc
-PKG_VERSION:=0.2.0
+PKG_VERSION:=0.2.1
 PKG_RELEASE:=$(AUTORELEASE)
 PKG_LICENSE:=GPL-3.0
 
index 8e8ac14f09483a84c6ed3ac6c15df2b8edaee7e7..5d3a393a5e73d8a3e8be84a3f2cdb561cd6d02ff 100644 (file)
@@ -317,6 +317,7 @@ enum {
        H_LEN,
        H_RANGE,
        H_UNKNOWN_PACKAGE,
+       H_QUEUE_POSITION,
        __H_MAX
 };
 
@@ -324,6 +325,7 @@ static const struct blobmsg_policy header_policy[__H_MAX] = {
        [H_LEN] = { .name = "content-length", .type = BLOBMSG_TYPE_STRING },
        [H_RANGE] = { .name = "content-range", .type = BLOBMSG_TYPE_STRING },
        [H_UNKNOWN_PACKAGE] = { .name = "x-unknown-package", .type = BLOBMSG_TYPE_STRING },
+       [H_QUEUE_POSITION] = { .name = "x-queue-position", .type = BLOBMSG_TYPE_INT32 },
 };
 
 /*
@@ -699,6 +701,12 @@ static void request_done(struct uclient *cl)
 static void header_done_cb(struct uclient *cl)
 {
        struct blob_attr *tb[__H_MAX];
+       struct jsonblobber *jsb = (struct jsonblobber *)cl->priv;
+       struct blob_buf *outbuf = NULL;
+
+       if (jsb)
+               outbuf = jsb->outbuf;
+
        uint64_t resume_offset = 0, resume_end, resume_size;
 
        if (uclient_http_redirect(cl)) {
@@ -778,10 +786,20 @@ static void header_done_cb(struct uclient *cl)
                        fprintf(stderr, "Content-Range header is invalid\n");
                        break;
                }
+       case 201:
        case 202:
                retry = true;
+               if (!outbuf)
+                       break;
+
+               blobmsg_add_u32(outbuf, "status", cl->status_code);
+
+               if (tb[H_QUEUE_POSITION])
+                       blobmsg_add_u32(outbuf, "queue_position", blobmsg_get_u32(tb[H_QUEUE_POSITION]));
+
                break;
        case 200:
+               retry = false;
                if (cl->priv)
                        break;
 
@@ -1747,8 +1765,15 @@ int main(int args, char *argv[]) {
 
                blobmsg_parse(target_policy, __TARGET_MAX, tb, blobmsg_data(tbr[REPLY_OBJECT]), blobmsg_len(tbr[REPLY_OBJECT]));
 
-               if (tb[TARGET_REQUEST_HASH] && tb[TARGET_STATUS]) {
-                       if (status_delay(blobmsg_get_string(tb[TARGET_STATUS]))) {
+               /* for compatibility with old server version, also support status in 200 reply */
+               if (tb[TARGET_STATUS]) {
+                       tmp = blobmsg_get_string(tb[TARGET_STATUS]);
+                       if (status_delay(tmp))
+                               retry = 1;
+               }
+
+               if (tb[TARGET_REQUEST_HASH]) {
+                       if (retry) {
                                if (!retry_delay)
                                        fputs("Requesting build", stderr);
 
@@ -1775,7 +1800,6 @@ int main(int args, char *argv[]) {
                                         blobmsg_get_string(tb[TARGET_REQUEST_HASH]));
                                DPRINTF("polling via GET %s\n", url);
                        }
-                       retry = true;
                        use_get = true;
                } else if (retry_delay) {
                        fputc('\n', stderr);