/*
- Copyright 2015, 2016, 2017 IoT.bzh
+ Copyright (C) 2015-2018 IoT.bzh
author: José Bollo <jose.bollo@iot.bzh>
struct afm_apps applications;
};
+/*
+ * The default language
+ */
+static char *default_lang;
+
/*
* Release the data of the afm_apps object 'apps'.
*/
/* 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 (;;) {
break;
switch (st) {
case 0:
+ /* state 0: begin of a line */
if (c == ';' || c == '#') {
st = 3; /* removes lines starting with ; or # */
break;
st = 1;
/*@fallthrough@*/
case 1:
+ /* state 1: emitting a normal line */
if (c == '\\')
st = 2;
else {
}
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;
tmp = afudb->applications;
afudb->applications = updt.applications;
apps_put(&tmp);
- afm_udb_addref(afudb);
+ afm_udb_unref(afudb);
return 0;
error:
apps_put(&updt.applications);
- afm_udb_addref(afudb);
+ afm_udb_unref(afudb);
return -1;
}
+void afm_udb_set_default_lang(const char *lang)
+{
+ char *oldval = default_lang;
+ default_lang = lang ? strdup(lang) : NULL;
+ free(oldval);
+}
+
/*
* Get the list of the applications private data of the afm_udb object 'afudb'.
* The list is returned as a JSON-array that must be released using
* 'json_object_put'.
* Returns NULL in case of error.
*/
-struct json_object *afm_udb_applications_public(struct afm_udb *afudb, int uid)
+struct json_object *afm_udb_applications_public(struct afm_udb *afudb, int uid, const char *lang)
{
return json_object_get(afudb->applications.pubarr);
}
* 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, int uid)
+static struct json_object *get_no_case(struct json_object *object, const char *id, int uid, const char *lang)
{
struct json_object *result;
struct json_object_iter i;
*/
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, uid);
+ return get_no_case(afudb->applications.prvobj, id, uid, NULL);
}
/*
* Returns NULL in case of error.
*/
struct json_object *afm_udb_get_application_public(struct afm_udb *afudb,
- const char *id, int uid)
+ const char *id, int uid, const char *lang)
{
- return get_no_case(afudb->applications.pubobj, id, uid);
+ return get_no_case(afudb->applications.pubobj, id, uid, lang);
}