#define _E(fmt, args...) SLOGE(fmt, ##args)
#define _I(fmt, args...) SLOGI(fmt, ##args)
-
#define ARRAY_SIZE(name) (sizeof(name)/sizeof(name[0]))
#define KEY_MAX 256
return 0;
}
+static int db_get_value(GDBM_FILE *db, char *tag, char *name, char *type, char *value, int val_len)
+{
+ datum d_key;
+ datum d_data;
+ char key[KEY_MAX];
+
+ if (!db || !*db || !tag || !name || !type || !value)
+ return -EINVAL;
+
+ if (name == strstr(name, KEY_PREFIX))
+ snprintf(key, sizeof(key), "%s:%s:%s", name, type, tag);
+ else
+ snprintf(key, sizeof(key), "%s%s:%s:%s", KEY_PREFIX, name, type, tag);
+
+ d_key.dptr = key;
+ d_key.dsize = strlen(key) + 1;
+
+ d_data = gdbm_fetch(*db, d_key);
+ if (!d_data.dptr) {
+ _E("Failed to find key (%s, %s)", key, type);
+ return -gdbm_errno;
+ }
+
+ snprintf(value, val_len, "%s", d_data.dptr);
+ free(d_data.dptr);
+
+ _I("DB: value (key:%s,value:%s) is fetched", key, value);
+
+ return 0;
+}
+
+static int db_set_value_specific_runtime(GDBM_FILE *db, char *tag, char *name, char *type, char *value, int lang)
+{
+ char value_intg[LANG_MAX];
+ int ret;
+
+ ret = db_get_value(db, tag, name, type, value_intg, LANG_MAX);
+ if (ret != 0)
+ return ret;
+
+ value_intg[lang] = (value[0] == 't' ? 'T' : 'F');
+ ret = db_set_value(db, tag, name, type, value_intg, sizeof(value_intg));
+
+ return ret;
+}
+
static int db_set_value_foreach_runtime(GDBM_FILE *db, xmlNode *node,
char *tag, char *name, char *type, char *value)
{
printf(" -h --help Show this help\n");
printf(" -k --key=KEY System info key to update\n");
printf(" -t --type=TYPE System info type to update (int/bool/double/string)\n");
+ printf(" -l --lang=LANG System info specific language target (capi/webapi/csapi)\n");
printf(" -g --tag=TAG System info tag to update (platform/custom)\n");
printf(" -v --value=VALUE System info value to update\n");
}
char tag[KEY_MAX] = {0};
char value[KEY_MAX] = {0};
char value_bool[LANG_MAX] = {0};
+ enum language lang = LANG_MAX;
+ int rt;
struct option long_options[] = {
{ "key", required_argument, 0, 0 },
case 'v':
snprintf(value, sizeof(value), "%s", optarg);
break;
+ case 'l':
+ for (rt = 0; rt < LANG_MAX; rt++) {
+ if (!runtime[rt].xml_prop)
+ break;
+ if (!strncmp(optarg, runtime[rt].xml_prop, RT_PREFIX)) {
+ lang = runtime[rt].lang;
+ break;
+ }
+ }
+ if (!runtime[rt].xml_prop) {
+ printf("Invalid language (%s)\n", optarg);
+ return 0;
+ }
+ break;
case 'h':
default:
show_help();
printf("Invalid Parameter: no value\n");
failed = true;
}
+ if ((lang != LANG_MAX) && (strncmp(type, "bool", 4))) {
+ printf("Invalid Parameter: lang parameter supports for just bool type\n");
+ failed = true;
+ }
if (failed)
return -EINVAL;
- _I("Request to update: key(%s), type(%s), tag(%s), value(%s)",
- key, type, tag, value);
+ if (lang == LANG_MAX)
+ _I("Request to update: key(%s), type(%s), tag(%s), value(%s)",
+ key, type, tag, value);
+ else
+ _I("Request to update for specific lang(%s): key(%s), type(%s), tag(%s), value(%s)",
+ runtime[lang].xml_prop, key, type, tag, value);
/* http://www.gnu.org.ua/software/gdbm/manual/html_node/Open.html
* If flags is set to ‘GDBM_WRITER’,
}
if (!strncmp(type, "bool", 4)) {
- memset(value_bool, value[0] == 't' ? 'T' : 'F', LANG_MAX);
- ret = db_set_value(&db, tag, key, type, value_bool, LANG_MAX);
+ if (lang == LANG_MAX) {
+ memset(value_bool, value[0] == 't' ? 'T' : 'F', LANG_MAX);
+ ret = db_set_value(&db, tag, key, type, value_bool, LANG_MAX);
+ } else
+ ret = db_set_value_specific_runtime(&db, tag, key, type, value, lang);
} else
ret = db_set_value(&db, tag, key, type, value, strlen(value));
+
if (ret != 0)
_E("Failed to set value (%d)", ret);