diff options
author | José Bollo <jose.bollo@iot.bzh> | 2019-12-03 15:02:57 +0100 |
---|---|---|
committer | José Bollo <jose.bollo@iot.bzh> | 2019-12-03 18:37:21 +0100 |
commit | 6008a3ec4d1c0ed5df338b7c5f0775585ab51cfb (patch) | |
tree | 1ac16f60d411822d149a77379faec0bdd8851d0d /src/wgtpkg-unit.c | |
parent | 50ab763bc31cb9e32bcb7e08e1f2be502fc50a5f (diff) |
Enforce numeric application IDs
This change allows to index applications numerically.
This can be used for various purposes. One of it is
to compute the HTTP port.
Bug-AGL: SPEC-2968
Change-Id: I74531781f3a39d5d4b09eeb907f57f36822e38f0
Signed-off-by: José Bollo <jose.bollo@iot.bzh>
Diffstat (limited to 'src/wgtpkg-unit.c')
-rw-r--r-- | src/wgtpkg-unit.c | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/src/wgtpkg-unit.c b/src/wgtpkg-unit.c index ab0c933..e01faa9 100644 --- a/src/wgtpkg-unit.c +++ b/src/wgtpkg-unit.c @@ -375,22 +375,28 @@ int unit_generator_open_template(const char *filename) static int add_metadata(struct json_object *jdesc, const struct unitconf *conf) { struct json_object *targets, *targ; - char portstr[30]; - int port, i, n; + char portstr[30], afidstr[30]; + int port, afid, i, n; if (json_object_object_get_ex(jdesc, string_targets, &targets)) { n = json_object_array_length(targets); for (i = 0 ; i < n ; i++) { targ = json_object_array_get_idx(targets, i); - if (!conf->port) - strcpy(portstr, "0"); - else { - port = conf->port ? conf->port() : 0; - if (port < 0) - return port; - sprintf(portstr, "%d", port); + if (!conf->new_afid) { + afid = 0; + port = 0; + } else { + afid = conf->new_afid(); + if (afid < 0) + return afid; + port = conf->base_http_ports + afid; } - if (!j_add_string_m(targ, "#metatarget.http-port", portstr)) + sprintf(afidstr, "%d", afid); + sprintf(portstr, "%d", port); + if (!j_add_many_strings_m(targ, + "#metatarget.http-port", portstr, + "#metatarget.afid", afidstr, + NULL)) return -1; } } |