From c9cafe0248d1b5327b376cc49548447d7496e1c6 Mon Sep 17 00:00:00 2001 From: Kunhoon Baik Date: Sat, 22 Jul 2017 10:20:01 +0900 Subject: [PATCH] Enhancement system-init-db for updating specific lang feature Now, system init db tool can update bool value for specific runtime. The feature will be updated according to following command. Whole runtime feature update : -k KEY -t bool -v VALUE C# runtime feature update : -k KEY -t bool -v VALUE -l csapi C runtime feature update : -k KEY -t bool -v VALUE -l capi Web runtime feature update : -k KEY -t bool -v VALUE -l webapi Change-Id: Iad562a040778b4b1b76492ad6f06e6043edee234 --- src/init_db/system_info_db_init.c | 84 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 79 insertions(+), 5 deletions(-) diff --git a/src/init_db/system_info_db_init.c b/src/init_db/system_info_db_init.c index 979dd64..1647e34 100644 --- a/src/init_db/system_info_db_init.c +++ b/src/init_db/system_info_db_init.c @@ -43,7 +43,6 @@ #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 @@ -87,6 +86,52 @@ static int db_set_value(GDBM_FILE *db, char *tag, char *name, char *type, char * 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) { @@ -279,6 +324,7 @@ static void show_help(void) 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"); } @@ -294,6 +340,8 @@ static int system_info_update_db(int argc, char *argv[]) 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 }, @@ -322,6 +370,20 @@ static int system_info_update_db(int argc, char *argv[]) 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(); @@ -346,12 +408,20 @@ static int system_info_update_db(int argc, char *argv[]) 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’, @@ -364,10 +434,14 @@ static int system_info_update_db(int argc, char *argv[]) } 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); -- 2.7.4