X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fwgtpkg-unit.c;h=e01faa9116f3fe505da716b856a2922c1e453bde;hb=6008a3ec4d1c0ed5df338b7c5f0775585ab51cfb;hp=fe58c09d98abebfd969c22a30257110d8a1f129a;hpb=971d4e96d6b14c01e8eae4f6e9910bc5859adfb1;p=src%2Fapp-framework-main.git diff --git a/src/wgtpkg-unit.c b/src/wgtpkg-unit.c index fe58c09..e01faa9 100644 --- a/src/wgtpkg-unit.c +++ b/src/wgtpkg-unit.c @@ -1,5 +1,5 @@ /* - Copyright 2016, 2017 IoT.bzh + Copyright (C) 2016-2019 IoT.bzh author: José Bollo @@ -28,7 +28,7 @@ #include #include - + #include "verbose.h" #include "utils-file.h" @@ -38,6 +38,7 @@ #include "utils-systemd.h" #include "wgtpkg-unit.h" +#include "wgt-strings.h" #if 0 #include @@ -54,7 +55,7 @@ static char *template; * When returning 1 and 'after' isn't NULL, the pointer to the * first character after the pettern in 'text' is stored in 'after'. * The characters '\n' and ' ' have a special meaning in the search: - * * '\n': matches any space or tabs (including none) followed + * * '\n': matches any space or tabs (including none) followed * either by '\n' or '\0' (end of the string) * * ' ': matches any space or tabs but at least one. */ @@ -373,13 +374,36 @@ int unit_generator_open_template(const char *filename) static int add_metadata(struct json_object *jdesc, const struct unitconf *conf) { - char portstr[30]; + struct json_object *targets, *targ; + 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->new_afid) { + afid = 0; + port = 0; + } else { + afid = conf->new_afid(); + if (afid < 0) + return afid; + port = conf->base_http_ports + afid; + } + 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; + } + } - sprintf(portstr, "%d", conf->port); return j_add_many_strings_m(jdesc, "#metadata.install-dir", conf->installdir, "#metadata.icons-dir", conf->icondir, - "#metadata.http-port", portstr, NULL) ? 0 : -1; }