From 19653e57bf7062c30b9689a9a6fe50d39111b7c7 Mon Sep 17 00:00:00 2001 From: Daniel Golle Date: Fri, 24 Nov 2017 21:38:25 +0100 Subject: [PATCH] auc: update to version 0.0.7 * implement using GET instead of POST requests when waiting for image Signed-off-by: Daniel Golle --- utils/auc/Makefile | 2 +- utils/auc/src/auc.c | 23 ++++++++++++++++++----- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/utils/auc/Makefile b/utils/auc/Makefile index 4e01bad10..5cc328abe 100644 --- a/utils/auc/Makefile +++ b/utils/auc/Makefile @@ -5,7 +5,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=auc -PKG_VERSION:=0.0.6 +PKG_VERSION:=0.0.7 PKG_RELEASE=1 PKG_LICENSE:=GPL-3.0 diff --git a/utils/auc/src/auc.c b/utils/auc/src/auc.c index e6317051b..73d150de1 100644 --- a/utils/auc/src/auc.c +++ b/utils/auc/src/auc.c @@ -13,7 +13,7 @@ */ #define _GNU_SOURCE -#define AUC_VERSION "0.0.6" +#define AUC_VERSION "0.0.7" #include #include @@ -151,6 +151,7 @@ static const struct blobmsg_policy check_policy[__CHECK_MAX] = { * parse download information for the ready image. */ enum { + IMAGE_REQHASH, IMAGE_FILESIZE, IMAGE_URL, IMAGE_CHECKSUM, @@ -160,6 +161,7 @@ enum { }; static const struct blobmsg_policy image_policy[__IMAGE_MAX] = { + [IMAGE_REQHASH] = { .name = "request_hash", .type = BLOBMSG_TYPE_STRING }, [IMAGE_FILESIZE] = { .name = "filesize", .type = BLOBMSG_TYPE_INT32 }, [IMAGE_URL] = { .name = "url", .type = BLOBMSG_TYPE_STRING }, [IMAGE_CHECKSUM] = { .name = "checksum", .type = BLOBMSG_TYPE_STRING }, @@ -167,7 +169,6 @@ static const struct blobmsg_policy image_policy[__IMAGE_MAX] = { [IMAGE_SYSUPGRADE] = { .name = "sysupgrade", .type = BLOBMSG_TYPE_STRING }, }; - /* * load serverurl from UCI */ @@ -682,7 +683,7 @@ static char *md5sum(const char *file) { static int ask_user(void) { - fprintf(stderr, "Are you sure to proceed? [N/y] "); + fprintf(stderr, "Are you sure you want to continue the upgrade process? [N/y] "); if (getchar() != 'y') return -1; return 0; @@ -694,7 +695,7 @@ int main(int args, char *argv[]) { struct ubus_context *ctx = ubus_connect(NULL); uint32_t id; int rc; - int queuepos, valid; + int queuepos, valid, use_get; char url[256]; char *newversion = NULL; struct blob_attr *tb[__IMAGE_MAX]; @@ -818,6 +819,7 @@ int main(int args, char *argv[]) { imagebuilder = 0; building = 0; + use_get = 0; do { retry = 0; @@ -825,9 +827,20 @@ int main(int args, char *argv[]) { if (debug) fprintf(stderr, "requesting:\n%s\n", blobmsg_format_json_indent(reqbuf.head, true, 0)); - server_request(url, &reqbuf, &imgbuf); + server_request(url, use_get?NULL:&reqbuf, &imgbuf); blobmsg_parse(image_policy, __IMAGE_MAX, tb, blob_data(imgbuf.head), blob_len(imgbuf.head)); + if (!use_get && tb[IMAGE_REQHASH]) { + snprintf(url, sizeof(url), "%s/%s/%s", serverurl, + APIOBJ_REQUEST, + blobmsg_get_string(tb[IMAGE_REQHASH])); + if (debug) + fprintf(stderr, "polling via GET %s\n", url); + + retry=1; + use_get=1; + } + if (retry) { blob_buf_free(&imgbuf); blobmsg_buf_init(&imgbuf);