int system_info_get_value_string(system_info_key_e key, char **value);
/**
+ * @internal
+ * @brief It is not decided if it should be opened to public
+ */
+typedef enum {
+ SYSTEM_INFO_BOOL,
+ SYSTEM_INFO_INT,
+ SYSTEM_INFO_DOUBLE,
+ SYSTEM_INFO_STRING,
+} system_info_type_e;
+
+/**
+ * @internal
+ * @brief It is not decided if it should be opened to public
+ */
+int system_info_get_platform_type(const char *key, system_info_type_e *type);
+
+/**
+ * @internal
+ * @brief It is not decided if it should be opened to public
+ */
+int system_info_get_custom_type(const char *key, system_info_type_e *type);
+
+/**
* @}
*/
int system_info_ini_get_string(char *ini_file, char *key, char **output);
int system_info_get_value_from_config_xml(char *feature_tag, const char *name_field, char *type_field, char **value);
-
+int system_info_get_type_from_config_xml(const char *feature_tag,
+ const char *name_field, char *type_field, size_t len);
int system_info_get_file(const char *key, void **value);
+int system_info_get_type_file(const char *key);
int external_get_value(const char *tag, const char *key, const char *type, char **value);
return SYSTEM_INFO_ERROR_NONE;
}
+
+static int get_type_from_str(char *type)
+{
+ size_t len;
+
+ if (!type)
+ return SYSTEM_INFO_ERROR_INVALID_PARAMETER;
+
+ len = strlen(type) + 1;
+ if (!strncmp(BOOL_TYPE, type, len))
+ return SYSTEM_INFO_BOOL;
+ if (!strncmp(INT_TYPE, type, len))
+ return SYSTEM_INFO_INT;
+ if (!strncmp(DBL_TYPE, type, len))
+ return SYSTEM_INFO_DOUBLE;
+ if (!strncmp(STR_TYPE, type, len))
+ return SYSTEM_INFO_STRING;
+
+ return SYSTEM_INFO_ERROR_INVALID_PARAMETER;
+}
+
+static int system_info_get_type(const char *key,
+ const char *tag, system_info_type_e *type)
+{
+ char type_str[16];
+ int ret;
+
+ if (!key || !tag || !type)
+ return SYSTEM_INFO_ERROR_INVALID_PARAMETER;
+
+ if (access(CONFIG_FILE_PATH, R_OK)) {
+ _E("cannot find file %s!!!", CONFIG_FILE_PATH);
+ if (errno == EPERM || errno == EACCES)
+ return SYSTEM_INFO_ERROR_PERMISSION_DENIED;
+ return SYSTEM_INFO_ERROR_IO_ERROR;
+ }
+
+ ret = system_info_get_type_from_config_xml(tag,
+ key, type_str, sizeof(type_str));
+ if (ret != SYSTEM_INFO_ERROR_NONE) {
+ if (!strncmp(tag, PLATFORM_TAG, sizeof(PLATFORM_TAG))) {
+ ret = system_info_get_type_file(key);
+ if (ret >= 0)
+ goto out;
+ }
+ _E("Failed to get type of key (%s)", key);
+ return ret;
+ }
+
+ ret = get_type_from_str(type_str);
+ if (ret < 0) {
+ _E("Invalid type (key:%s, type:%s)", key, type_str);
+ return SYSTEM_INFO_ERROR_INVALID_PARAMETER;
+ }
+
+out:
+ *type = ret;
+
+ return SYSTEM_INFO_ERROR_NONE;
+}
+
+
+API int system_info_get_platform_type(const char *key, system_info_type_e *type)
+{
+ return system_info_get_type(key, PLATFORM_TAG, type);
+}
+
+API int system_info_get_custom_type(const char *key, system_info_type_e *type)
+{
+ return system_info_get_type(key, CUSTOM_TAG, type);
+}
#define SERIAL_TOK_DELIMITER ","
#define BUF_MAX 256
+#define ARRAY_SIZE(name) (sizeof(name)/sizeof(name[0]))
+
static int get_tizenid(char **value)
{
char id[BUF_MAX];
return 0;
}
+static int get_build_date(char **value)
+{
+ return system_info_ini_get_string(INFO_FILE_PATH, "build:date", value);
+}
+
+static int get_build_str(char **value)
+{
+ return system_info_ini_get_string(INFO_FILE_PATH, "version:build", value);
+}
+
+static int get_build_time(char **value)
+{
+ return system_info_ini_get_string(INFO_FILE_PATH, "build:time", value);
+}
+
+struct system_info_file_key {
+ const char *key;
+ int (*get_value)(char **val);
+ system_info_type_e type;
+} info_file_key [] = {
+ { "tizen.org/system/tizenid", get_tizenid, SYSTEM_INFO_STRING },
+ { "tizen.org/system/build.date", get_build_date, SYSTEM_INFO_STRING },
+ { "tizen.org/system/build.string", get_build_str, SYSTEM_INFO_STRING },
+ { "tizen.org/system/build.time", get_build_time, SYSTEM_INFO_STRING },
+};
+
int system_info_get_file(const char *key, void **value)
{
char *p_key;
+ int i, len;
if (!key || !value)
return -EINVAL;
else
p_key = (char *)key;
- if (!strncmp(p_key, "tizen.org/system/tizenid", strlen(p_key)))
- return get_tizenid((char **)value);
+ len = strlen(p_key) + 1;
+ for (i = 0 ; i < ARRAY_SIZE(info_file_key); i++)
+ if (!strncmp(p_key, info_file_key[i].key, len))
+ return info_file_key[i].get_value((char **)value);
+
+ return -ENOENT;
+}
+
+int system_info_get_type_file(const char *key)
+{
+ char *p_key;
+ int i, len;
- if (!strncmp(p_key, "tizen.org/system/build.date", strlen(p_key)))
- return system_info_ini_get_string(INFO_FILE_PATH, "build:date", (char **)value);
+ if (!key)
+ return SYSTEM_INFO_ERROR_INVALID_PARAMETER;
- if (!strncmp(p_key, "tizen.org/system/build.string", strlen(p_key)))
- return system_info_ini_get_string(INFO_FILE_PATH, "version:build", (char **)value);
+ p_key = strstr(key, "http://");
+ if (p_key && p_key == key)
+ p_key = (char *)key + strlen("http://");
+ else
+ p_key = (char *)key;
- if (!strncmp(p_key, "tizen.org/system/build.time", strlen(p_key)))
- return system_info_ini_get_string(INFO_FILE_PATH, "build:time", (char **)value);
+ len = strlen(p_key) + 1;
+ for (i = 0 ; i < ARRAY_SIZE(info_file_key); i++) {
+ if (!strncmp(p_key, info_file_key[i].key, len))
+ return info_file_key[i].type;
+ }
- return -ENOENT;
+ return SYSTEM_INFO_ERROR_INVALID_PARAMETER;
}
xmlFreeDoc(doc);
return SYSTEM_INFO_ERROR_NONE;
}
+
+int system_info_get_type_from_config_xml(const char *feature_tag,
+ const char *name_field, char *type_field, size_t len)
+{
+ xmlDocPtr doc;
+ xmlNodePtr cur, model_node;
+ xmlNode *cur_node;
+ char *name, *p_name, *type;
+ int ret;
+
+ doc = xmlParseFile(CONFIG_FILE_PATH);
+ if (!doc) {
+ _E("cannot file open %s file!!!", CONFIG_FILE_PATH);
+ return SYSTEM_INFO_ERROR_IO_ERROR;
+ }
+
+ cur = xmlDocGetRootElement(doc);
+ if (!cur) {
+ _E("empty document %s file!!!", CONFIG_FILE_PATH);
+ ret = SYSTEM_INFO_ERROR_IO_ERROR;
+ goto out;
+ }
+
+ for (cur_node = cur; cur_node ; cur_node = cur_node->next) {
+ if (!xmlStrcmp(cur->name, (const xmlChar*)MODEL_CONFIG_TAG))
+ break;
+ }
+ if (!cur_node) {
+ _E("cannot find %s root element file!!!", MODEL_CONFIG_TAG);
+ ret = SYSTEM_INFO_ERROR_IO_ERROR;
+ goto out;
+ }
+
+ cur = cur->xmlChildrenNode;
+
+ model_node = NULL;
+ for (cur_node = cur; cur_node; cur_node = cur_node->next) {
+ if (!xmlStrcmp(cur_node->name, (const xmlChar*)feature_tag))
+ model_node = cur_node;
+ }
+ if (!model_node) {
+ _E("cannot find %s field from %s file!!!", name_field, CONFIG_FILE_PATH);
+ ret = SYSTEM_INFO_ERROR_INVALID_PARAMETER;
+ goto out;
+ }
+
+ ret = SYSTEM_INFO_ERROR_INVALID_PARAMETER;
+ cur = model_node->xmlChildrenNode;
+ for (cur_node = cur; cur_node ; cur_node = cur_node->next) {
+ if (cur_node->type != XML_ELEMENT_NODE)
+ continue;
+
+ name = (char *)xmlGetProp(cur_node, (const xmlChar*)"name");
+
+ p_name = strstr(name_field, "http://");
+ if (p_name && p_name == name_field)
+ p_name = (char *)name_field + strlen("http://");
+ else
+ p_name = (char *)name_field;
+
+ ret = strncmp(name, p_name, strlen(name) + 1);
+ xmlFree(name);
+ if (ret != 0)
+ continue;
+
+ type = (char *)xmlGetProp(cur_node, (const xmlChar*)"type");
+ if (!type) {
+ _E("Failed to get type of key (%s)", name_field);
+ ret = SYSTEM_INFO_ERROR_IO_ERROR;
+ goto out;
+ }
+
+ snprintf(type_field, len, "%s", type);
+ xmlFree(type);
+ ret = SYSTEM_INFO_ERROR_NONE;
+ break;
+ }
+
+out:
+ if (doc)
+ xmlFreeDoc(doc);
+ return ret;
+}