X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fafm-udb.c;h=718aa5c3759a48eeda4695ae43e8e56c305fce5b;hb=66817a088f7b3ccd85117bfe6a610710a728ef09;hp=e3d5d77a44f6d7dd910ea89f4b7a7c4319d7b165;hpb=f2580ca3a5ec951216fe7cb2c092b13e8ffbdbe4;p=src%2Fapp-framework-main.git diff --git a/src/afm-udb.c b/src/afm-udb.c index e3d5d77..718aa5c 100644 --- a/src/afm-udb.c +++ b/src/afm-udb.c @@ -17,6 +17,7 @@ */ #include +#include #include #include #include @@ -33,7 +34,6 @@ #include "afm-udb.h" - static const char x_afm_prefix[] = "X-AFM-"; static const char service_extension[] = ".service"; static const char key_unit_path[] = "-unit-path"; @@ -224,6 +224,7 @@ static int addunit( { struct json_object *priv, *pub, *id; const char *strid; + size_t len; /* create the application structure */ priv = json_object_new_object(); @@ -234,6 +235,11 @@ static int addunit( if (!pub) goto error; + /* make the unit name */ + len = strlen(unitname); + assert(len >= (sizeof service_extension - 1)); + assert(!memcmp(&unitname[len - (sizeof service_extension - 1)], service_extension, sizeof service_extension)); + /* adds the values */ if (add_fields_of_content(priv, pub, content, length) || add_field(priv, pub, key_unit_path, unitpath) @@ -274,7 +280,7 @@ static int read_unit_file(const char *path, char **content, size_t *length) /* read the file */ rc = getfile(path, content, length); if (rc >= 0) { - /* removes any comment and join lines */ + /* removes any comment and join continued lines */ st = 0; read = write = *content; for (;;) { @@ -283,6 +289,7 @@ static int read_unit_file(const char *path, char **content, size_t *length) break; switch (st) { case 0: + /* state 0: begin of a line */ if (c == ';' || c == '#') { st = 3; /* removes lines starting with ; or # */ break; @@ -293,6 +300,7 @@ enter_state_1: st = 1; /*@fallthrough@*/ case 1: + /* state 1: emitting a normal line */ if (c == '\\') st = 2; else { @@ -302,12 +310,14 @@ enter_state_1: } break; case 2: + /* state 2: character after '\' */ if (c == '\n') c = ' '; else *write++ = '\\'; goto enter_state_1; case 3: + /* state 3: inside a comment, wait its end */ if (c == '\n') st = 0; break; @@ -345,12 +355,14 @@ static int update_cb(void *closure, const char *name, const char *path, int isus /* reads the file */ rc = read_unit_file(path, &content, &length); if (rc < 0) - return rc; + return 0; /* process the file */ rc = addunit(&updt->applications, isuser, path, name, content, length); + /* TODO: if (rc < 0) + ERROR("Ignored boggus unit %s (error: %m)", path); */ free(content); - return rc; + return 0; } /* @@ -463,7 +475,7 @@ error: * 'json_object_put'. * Returns NULL in case of error. */ -struct json_object *afm_udb_applications_private(struct afm_udb *afudb) +struct json_object *afm_udb_applications_private(struct afm_udb *afudb, int uid) { return json_object_get(afudb->applications.prvarr); } @@ -474,7 +486,7 @@ struct json_object *afm_udb_applications_private(struct afm_udb *afudb) * 'json_object_put'. * Returns NULL in case of error. */ -struct json_object *afm_udb_applications_public(struct afm_udb *afudb) +struct json_object *afm_udb_applications_public(struct afm_udb *afudb, int uid) { return json_object_get(afudb->applications.pubarr); } @@ -484,7 +496,7 @@ struct json_object *afm_udb_applications_public(struct afm_udb *afudb) * It returns a JSON-object that must be released using 'json_object_put'. * Returns NULL in case of error. */ -static struct json_object *get_no_case(struct json_object *object, const char *id) +static struct json_object *get_no_case(struct json_object *object, const char *id, int uid) { struct json_object *result; struct json_object_iter i; @@ -506,9 +518,9 @@ static struct json_object *get_no_case(struct json_object *object, const char *i * It returns a JSON-object that must be released using 'json_object_put'. * Returns NULL in case of error. */ -struct json_object *afm_udb_get_application_private(struct afm_udb *afudb, const char *id) +struct json_object *afm_udb_get_application_private(struct afm_udb *afudb, const char *id, int uid) { - return get_no_case(afudb->applications.prvobj, id); + return get_no_case(afudb->applications.prvobj, id, uid); } /* @@ -517,9 +529,9 @@ struct json_object *afm_udb_get_application_private(struct afm_udb *afudb, const * Returns NULL in case of error. */ struct json_object *afm_udb_get_application_public(struct afm_udb *afudb, - const char *id) + const char *id, int uid) { - return get_no_case(afudb->applications.pubobj, id); + return get_no_case(afudb->applications.pubobj, id, uid); }