Code Review
/
src
/
app-framework-main.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
review
|
tree
raw
|
inline
| side by side
genconf: set filetype and syntax
[src/app-framework-main.git]
/
src
/
afm-udb.c
diff --git
a/src/afm-udb.c
b/src/afm-udb.c
index
e3d5d77
..
718aa5c
100644
(file)
--- a/
src/afm-udb.c
+++ b/
src/afm-udb.c
@@
-17,6
+17,7
@@
*/
#include <stdlib.h>
*/
#include <stdlib.h>
+#include <stdio.h>
#include <assert.h>
#include <string.h>
#include <errno.h>
#include <assert.h>
#include <string.h>
#include <errno.h>
@@
-33,7
+34,6
@@
#include "afm-udb.h"
#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";
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;
{
struct json_object *priv, *pub, *id;
const char *strid;
+ size_t len;
/* create the application structure */
priv = json_object_new_object();
/* create the application structure */
priv = json_object_new_object();
@@
-234,6
+235,11
@@
static int addunit(
if (!pub)
goto error;
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)
/* 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) {
/* 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 (;;) {
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:
break;
switch (st) {
case 0:
+ /* state 0: begin of a line */
if (c == ';' || c == '#') {
st = 3; /* removes lines starting with ; or # */
break;
if (c == ';' || c == '#') {
st = 3; /* removes lines starting with ; or # */
break;
@@
-293,6
+300,7
@@
enter_state_1:
st = 1;
/*@fallthrough@*/
case 1:
st = 1;
/*@fallthrough@*/
case 1:
+ /* state 1: emitting a normal line */
if (c == '\\')
st = 2;
else {
if (c == '\\')
st = 2;
else {
@@
-302,12
+310,14
@@
enter_state_1:
}
break;
case 2:
}
break;
case 2:
+ /* state 2: character after '\' */
if (c == '\n')
c = ' ';
else
*write++ = '\\';
goto enter_state_1;
case 3:
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;
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)
/* 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);
/* 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);
free(content);
- return
rc
;
+ return
0
;
}
/*
}
/*
@@
-463,7
+475,7
@@
error:
* 'json_object_put'.
* Returns NULL in case of 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);
}
{
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.
*/
* '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);
}
{
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.
*/
* 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;
{
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.
*/
* 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,
* 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
);
}
}