From: Youngjae Cho Date: Mon, 2 Aug 2021 08:51:59 +0000 (+0900) Subject: tool: allow prefix "http://" for get/set/clear key X-Git-Tag: submit/tizen/20210805.103313~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=67f96e12d4cd9c81b1218873a3ffb15ce24a15bc;p=platform%2Fcore%2Fapi%2Fsystem-info.git tool: allow prefix "http://" for get/set/clear key Change-Id: Ie4c504706d1de818dbf1b84878cb57e95009ea0f Signed-off-by: Youngjae Cho --- diff --git a/tool/system-info-tool-get.c b/tool/system-info-tool-get.c index c6662bd..a448a12 100644 --- a/tool/system-info-tool-get.c +++ b/tool/system-info-tool-get.c @@ -176,11 +176,16 @@ out: return ret; } -void system_info_tool_get(const char *key, bool verbose) +void system_info_tool_get(const char *rawkey, bool verbose) { struct value api; + char key[BUFFER_MAX]; int retval; + retval = convert_raw_key(rawkey, key, sizeof(key)); + if (retval < 0) + return; + retval = system_info_tool_get_api(key, &api); if (retval < 0) return; diff --git a/tool/system-info-tool-set.c b/tool/system-info-tool-set.c index a893b45..1d1f4ed 100644 --- a/tool/system-info-tool-set.c +++ b/tool/system-info-tool-set.c @@ -20,7 +20,7 @@ void system_info_tool_set_help(void) printf(" -C|--clear-all Clear all user-defined keys\n"); } -static int convert_raw_optargs(const char *rawtype, const char *rawvalue, struct value *out) +static int convert_raw_value(const char *rawtype, const char *rawvalue, struct value *out) { system_info_type_e type = string_to_type(rawtype); @@ -229,7 +229,7 @@ static int system_info_tool_init_rw_database(void) int system_info_tool_set(int argc, char *argv[]) { int ret; - char *key; + char key[BUFFER_MAX]; struct value value; /* argv[optind] : key @@ -247,21 +247,25 @@ int system_info_tool_set(int argc, char *argv[]) return -ENOTSUP; } - key = argv[optind]; - ret = convert_raw_optargs(argv[optind + 1], argv[optind + 2], &value); + ret = convert_raw_key(argv[optind], key, sizeof(key)); + if (ret < 0) + return ret; + + ret = convert_raw_value(argv[optind + 1], argv[optind + 2], &value); if (ret < 0) return ret; return system_info_tool_set_entry(key, value); } -int system_info_tool_clear_key(const char *key) +int system_info_tool_clear_key(const char *rawkey) { int retval; int ret; int match = 0; int i; int select; + char key[BUFFER_MAX]; struct cache { int match; @@ -273,6 +277,10 @@ int system_info_tool_clear_key(const char *key) { -1, }, }; + ret = convert_raw_key(rawkey, key, sizeof(key)); + if (ret < 0) + return ret; + for (i = 0; i < SYSTEM_INFO_TYPE_MAX; ++i) { retval = system_info_tool_get_raw(key, i, DB_DEFAULT_RW, &cache[i].dbentry); if (retval == 0) diff --git a/tool/system-info-tool.c b/tool/system-info-tool.c index 538d533..4f031ca 100644 --- a/tool/system-info-tool.c +++ b/tool/system-info-tool.c @@ -7,6 +7,8 @@ #include "system-info-tool-get.h" #include "system-info-tool-set.h" +#define KEY_PREFIX "http://" + int runtime_env = C; const struct db db[DB_END] = { /* { dbpath, dbname, ticker } */ @@ -44,6 +46,24 @@ system_info_type_e string_to_type(const char *type) return SYSTEM_INFO_TYPE_MAX; } +int convert_raw_key(const char *rawkey, char *buffer, int len) +{ + int retval; + + if (!rawkey || !buffer) + return -EINVAL; + + if (strstr(rawkey, KEY_PREFIX) == rawkey) + retval = snprintf(buffer, len, "%s", rawkey + strlen(KEY_PREFIX)); + else + retval = snprintf(buffer, len, "%s", rawkey); + + if (retval >= len) + return -ENAMETOOLONG; + + return 0; +} + void print_value(struct value value) { if (value.type == SYSTEM_INFO_BOOL) diff --git a/tool/system-info-tool.h b/tool/system-info-tool.h index 7b966d2..ce8daa6 100644 --- a/tool/system-info-tool.h +++ b/tool/system-info-tool.h @@ -76,5 +76,6 @@ static inline void free_dbentry(struct dbentry *entry) const char *type_to_string(system_info_type_e type); system_info_type_e string_to_type(const char *type); void print_value(struct value value); +int convert_raw_key(const char *key, char *buffer, int len); #endif