SET(INC_DIR include)
INCLUDE_DIRECTORIES(${INC_DIR})
-SET(requires "dlog capi-base-common iniparser libxml-2.0")
+SET(requires "dlog capi-base-common")
SET(pc_requires "capi-base-common")
INCLUDE(FindPkgConfig)
ADD_DEFINITIONS("-DINFO_FILE_PATH=\"${INFO_FILE_PATH}\"")
ADD_DEFINITIONS("-DTIZEN_ID_PATH=\"${TIZEN_ID_PATH}\"")
ADD_DEFINITIONS("-DLIBPATH=\"${LIB_INSTALL_DIR}\"")
+ADD_DEFINITIONS("-DSYSTEM_INFO_DB_PATH=\"${DB_PATH}\"")
SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -Wl,--rpath=/usr/lib")
aux_source_directory(src SOURCES)
ADD_LIBRARY(${fw_name} SHARED ${SOURCES})
-TARGET_LINK_LIBRARIES(${fw_name} ${${fw_name}_LDFLAGS} "-ldl")
+TARGET_LINK_LIBRARIES(${fw_name} ${${fw_name}_LDFLAGS} "-ldl -lgdbm")
SET_TARGET_PROPERTIES(${fw_name}
PROPERTIES
INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/system_info_intf.h DESTINATION include/plugin)
ADD_SUBDIRECTORY(src/tizenid)
+ADD_SUBDIRECTORY(src/init_db)
IF(UNIX)
* @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);
/**
int (*get_value_external)(const char *tag,
const char *key, const char *type,
char *buf, unsigned int len);
+ int (*get_type_external)(const char *tag,
+ const char *key, char *buf, unsigned int len);
+
} system_info_external_plugin_interface;
#ifdef __cplusplus
#include <stdbool.h>
#include <dlog.h>
+#include "system_info_type.h"
#ifndef API
#define API __attribute__ ((visibility("default")))
#define _E(fmt, args...) SLOGE(fmt, ##args)
#define _I(fmt, args...) SLOGI(fmt, ##args)
-#define PLATFORM_TAG "platform"
-#define CUSTOM_TAG "custom"
+#define TAG_TYPE_PLATFORM_STR "platform"
+#define TAG_TYPE_CUSTOM_STR "custom"
#define BOOL_TYPE "bool"
#define INT_TYPE "int"
#define DBL_TYPE "double"
#define STR_TYPE "string"
-typedef enum {
- SYSTEM_INFO_DATA_TYPE_STRING,
- SYSTEM_INFO_DATA_TYPE_INT,
- SYSTEM_INFO_DATA_TYPE_DOUBLE,
- SYSTEM_INFO_DATA_TYPE_BOOL
-} system_info_data_type_e;
-
-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 system_info_get_file(const char *key, char *value, size_t len);
+int system_info_get_type_file(const char *key, system_info_type_e *type);
int external_get_value(const char *tag, const char *key, const char *type, char **value);
+int external_get_type(const char *tag, const char *key, char **type);
#ifdef __cplusplus
}
/**
* @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 Enumeration of key for system information
*/
typedef enum {
BuildRequires: pkgconfig(openssl)
BuildRequires: pkgconfig(glib-2.0)
BuildRequires: pkgconfig(libtzplatform-config)
+BuildRequires: gdbm-devel
%description
%define config_file_path /etc/config/model-config.xml
%define info_file_path /etc/info.ini
%define tizen_id_path %{TZ_SYS_ETC}/tizenid
+%define db_path %{TZ_SYS_RO_ETC}/system_info_db
%build
MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'`
-DINFO_FILE_PATH=%{info_file_path} \
-DMAJORVER=${MAJORVER} \
-DFULLVER=%{version} \
- -DTIZEN_ID_PATH=%{tizen_id_path}
+ -DTIZEN_ID_PATH=%{tizen_id_path} \
+ -DDB_PATH=%{db_path}
%__make %{?_smp_mflags}
%postun -p /sbin/ldconfig
-
%files
%manifest %{name}.manifest
%license LICENSE
%{_libdir}/libcapi-system-info.so.*
%attr(0744,root,-) /etc/make_info_file.sh
+%{_bindir}/system_info_init_db
#tizenid
%{_bindir}/tizen_id
return -EINVAL;
}
+static int get_type_external(const char *tag,
+ const char *key, char *buf, unsigned int len)
+{
+ int i;
+ int key_len, tag_len;
+
+ if (!tag || !key || !buf)
+ return -EINVAL;
+
+ key_len = strlen(key);
+ tag_len = strlen(tag);
+ if (key_len == 0 || tag_len == 0)
+ return -EINVAL;
+
+ for (i = 0 ; i < ARRAY_SIZE(system_info_key) ; i++) {
+ if (strncmp(system_info_key[i].tag, tag, tag_len))
+ continue;
+ if (strncmp(system_info_key[i].key, key, key_len))
+ continue;
+
+ snprintf(buf, len, "%s", system_info_key[i].type);
+ return 0;
+ }
+
+ LOGE("Failed to find system info key in the plugin (%s)", key);
+ return -EINVAL;
+}
+
const system_info_external_plugin_interface external_plugin = {
.get_value_external = get_value_external,
+ .get_type_external = get_type_external,
};
API const system_info_external_plugin_interface *system_info_get_external_plugin_interface(void)
Variant=$TZ_BUILD_VARIANT;
ID=$ID;
EOF
+
+/usr/bin/system_info_init_db
--- /dev/null
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+SET(INIT_DB "system_info_init_db")
+
+SET(SRCS ${CMAKE_SOURCE_DIR}/src/init_db/system_info_db_init.c)
+
+INCLUDE_DIRECTORIES(include)
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(init_db_pkgs REQUIRED
+ dlog
+ glib-2.0
+ iniparser
+ libxml-2.0
+)
+
+FOREACH(flag ${init_db_pkgs_CFLAGS})
+ SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -g -fno-omit-frame-pointer -finstrument-functions -fpie")
+
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+
+SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie")
+
+ADD_EXECUTABLE(${INIT_DB} ${SRCS})
+TARGET_LINK_LIBRARIES(${INIT_DB} ${init_db_pkgs_LDFLAGS} "-lgdbm")
+
+INSTALL(TARGETS ${INIT_DB} DESTINATION bin)
+#INSTALL(FILES ${CMAKE_SOURCE_DIR}/packaging/system_info_init_db.service DESTINATION lib/systemd/system)
--- /dev/null
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <ctype.h>
+#include <gdbm.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <dlog.h>
+
+#include <system_info.h>
+#include <iniparser.h>
+#include <libxml/xmlmemory.h>
+#include <libxml/parser.h>
+#include <libxml/tree.h>
+
+#include "system_info_private.h"
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+
+#define LOG_TAG "SYSTEM_INFO"
+#define _D(fmt, args...) SLOGD(fmt, ##args)
+#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
+
+#define MODEL_CONFIG_TAG "model-config"
+#define KEY_PREFIX "http://"
+
+static int db_set_value(GDBM_FILE *db, char *tag, char *name, char *type, char *value)
+{
+ char key[KEY_MAX];
+ datum d_key;
+ datum d_data;
+ int ret;
+
+ 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.dptr = value;
+ d_data.dsize = strlen(value) + 1;
+
+ ret = gdbm_store(*db, d_key, d_data, GDBM_REPLACE);
+ if (ret != 0) {
+ _E("Failed to store key (%s, %s, %d)", key, type, gdbm_errno);
+ return -gdbm_errno;
+ }
+
+ gdbm_sync(*db);
+
+ _I("DB: value (key:%s,value:%s) is stored", key, value);
+
+ return 0;
+}
+
+static int system_info_get_values_config_xml(GDBM_FILE *db)
+{
+ xmlDocPtr doc;
+ xmlNodePtr cur;
+ xmlNode *cur_node, *tag_node;
+ char *tag, *name, *type, *value;
+ int ret;
+
+ if (!db || !*db)
+ return -EINVAL;
+
+ 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 = -ENOENT;
+ 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 = -ENOENT;
+ goto out;
+ }
+
+ cur = cur_node->xmlChildrenNode;
+ for (tag_node = cur; tag_node; tag_node = tag_node->next) {
+ if (!xmlStrcmp(tag_node->name, (const xmlChar *)TAG_TYPE_PLATFORM_STR))
+ tag = TAG_TYPE_PLATFORM_STR;
+ else if (!xmlStrcmp(tag_node->name, (const xmlChar *)TAG_TYPE_CUSTOM_STR))
+ tag = TAG_TYPE_CUSTOM_STR;
+ else
+ continue;
+
+ cur = tag_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");
+ if (!name)
+ continue;
+
+ type = (char *)xmlGetProp(cur_node, (const xmlChar*)"type");
+ if (!type) {
+ xmlFree(name);
+ continue;
+ }
+
+ value = (char *)xmlNodeListGetString(doc, cur_node->xmlChildrenNode, 1);
+ if (!value) {
+ xmlFree(name);
+ xmlFree(type);
+ continue;
+ }
+
+ ret = db_set_value(db, tag, name, type, value);
+ if (ret < 0)
+ _E("Failed to set value (%d)", ret);
+
+ xmlFree(name);
+ xmlFree(type);
+ xmlFree(value);
+ }
+ }
+
+ ret = 0;
+
+out:
+ if (doc)
+ xmlFreeDoc(doc);
+ return ret;
+}
+
+static struct build_ini_keys {
+ char *info;
+ char *key;
+} ini_keys[] = {
+ { "version:model", "http://tizen.org/system/build.model" },
+ { "version:build", "http://tizen.org/system/build.string" },
+ { "version:release", "http://tizen.org/system/build.release" },
+ { "build:type", "http://tizen.org/system/build.type" },
+ { "build:date", "http://tizen.org/system/build.date" },
+ { "build:time", "http://tizen.org/system/build.time" },
+ { "build:variant", "http://tizen.org/system/build.variant" },
+ { "build:id", "http://tizen.org/system/build.id" },
+};
+
+static int system_info_get_values_ini(GDBM_FILE *db)
+{
+ dictionary *ini;
+ int i, ret;
+ char *value;
+
+ if (!db || !*db)
+ return -EINVAL;
+
+ ini = iniparser_load(INFO_FILE_PATH);
+ if (!ini) {
+ _E("cannot file open %s file!!!", INFO_FILE_PATH);
+ return -ENOENT;
+ }
+
+ for (i = 0 ; i < ARRAY_SIZE(ini_keys) ; i++) {
+ value = iniparser_getstring(ini, ini_keys[i].info, NULL);
+ if (!value) {
+ _E("NOT found %s", ini_keys[i].info);
+ continue;
+ }
+
+ ret = db_set_value(db, TAG_TYPE_PLATFORM_STR, ini_keys[i].key, STR_TYPE, value);
+ if (ret < 0)
+ _E("Failed to set value (%d)", ret);
+ }
+
+ iniparser_freedict(ini);
+
+ return 0;
+}
+
+int main(int argc, char *argv[])
+{
+ int ret;
+ GDBM_FILE db;
+
+ db = gdbm_open(SYSTEM_INFO_DB_PATH, 0, GDBM_WRCREAT, S_IRUSR | S_IRGRP | S_IROTH, NULL);
+ if (!db) {
+ _E("Failed to open db (%d, %s)", gdbm_errno, gdbm_strerror(gdbm_errno));
+ return -ENOENT;
+ }
+
+ ret = system_info_get_values_config_xml(&db);
+ if (ret < 0)
+ _E("Failed to get keys and values from xml(%d)", ret);
+
+ ret = system_info_get_values_ini(&db);
+ if (ret < 0)
+ _E("Failed to get keys and values from ini(%d)", ret);
+
+ gdbm_close(db);
+
+ return 0;
+}
/*
- * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the License);
* you may not use this file except in compliance with the License.
#include <string.h>
#include <unistd.h>
#include <ctype.h>
+#include <gdbm.h>
+#include <fcntl.h>
+#include <sys/stat.h>
#include <system_info.h>
#include <system_info_private.h>
#include <sys/utsname.h>
+#define ARRAY_SIZE(name) (sizeof(name)/sizeof(name[0]))
+#define KEY_PREFIX "http://"
+
#define SYSTEM_INFO_MAX -1
+#define KEY_MAX 256
+#define STR_MAX 256
+
+enum tag_type {
+ TAG_TYPE_PLATFORM,
+ TAG_TYPE_CUSTOM,
+};
API int system_info_get_value_int(system_info_key_e key, int *value)
{
return SYSTEM_INFO_ERROR_NOT_SUPPORTED;
}
-API int system_info_get_platform_bool(const char *key, bool *value)
+static int db_get_value(enum tag_type tag, const char *key,
+ const char *type, char *value, size_t len)
{
+ char key_internal[KEY_MAX];
+ GDBM_FILE db = NULL;
+ datum d_key;
+ datum d_data;
int ret;
- bool *supported;
- char *string = NULL;
+ char *tag_s;
- supported = (bool *)value;
+ if (!key || !type || !value)
+ 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;
+ switch (tag) {
+ case TAG_TYPE_PLATFORM:
+ tag_s = TAG_TYPE_PLATFORM_STR;
+ break;
+ case TAG_TYPE_CUSTOM:
+ tag_s = TAG_TYPE_CUSTOM_STR;
+ break;
+ default:
+ return -EINVAL;
}
- ret = system_info_get_value_from_config_xml(PLATFORM_TAG, key, BOOL_TYPE, &string);
- if (ret) {
- _E("cannot get %s", key);
- return ret;
+ db = gdbm_open(SYSTEM_INFO_DB_PATH, 0, GDBM_READER, S_IRUSR | S_IRGRP | S_IROTH, NULL);
+ if (!db) {
+ _E("Failed to open db (%d, %s)", gdbm_errno, gdbm_strerror(gdbm_errno));
+ return SYSTEM_INFO_ERROR_IO_ERROR;
}
- if (!strcmp(string, "true") || !strcmp(string, "TRUE"))
- *supported = true;
+ if (strstr(key, KEY_PREFIX) == key)
+ snprintf(key_internal, sizeof(key_internal),
+ "%s:%s:%s", key, type, tag_s);
else
- *supported = false;
-
- free(string);
-
- return SYSTEM_INFO_ERROR_NONE;
-}
-
-API int system_info_get_platform_int(const char *key, int *value)
-{
- int ret;
- int *ret_val;
- char *string = NULL;
+ snprintf(key_internal, sizeof(key_internal),
+ "%s%s:%s:%s", KEY_PREFIX, key, type, tag_s);
- ret_val = (int *)value;
+ d_key.dptr = key_internal;
+ d_key.dsize = strlen(key_internal) + 1;
- 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;
+ d_data = gdbm_fetch(db, d_key);
+ if (!d_data.dptr) {
+ _E("Failed to find key (%s, %s)", key, type);
+ ret = SYSTEM_INFO_ERROR_INVALID_PARAMETER;
+ goto out;
}
- ret = system_info_get_value_from_config_xml(PLATFORM_TAG, key, INT_TYPE, &string);
- if (ret) {
- _E("cannot get %s", key);
- return ret;
- }
+ snprintf(value, len, "%s", d_data.dptr);
+ ret = SYSTEM_INFO_ERROR_NONE;
- *ret_val = atoi(string);
-
- free(string);
-
- return SYSTEM_INFO_ERROR_NONE;
+out:
+ if (db)
+ gdbm_close(db);
+ return ret;
}
-API int system_info_get_platform_double(const char *key, double *value)
+struct sysinfo_type {
+ system_info_type_e type_e;
+ const char *type_str;
+} info_type[] = {
+ { SYSTEM_INFO_BOOL, BOOL_TYPE },
+ { SYSTEM_INFO_INT, INT_TYPE },
+ { SYSTEM_INFO_DOUBLE, DBL_TYPE },
+ { SYSTEM_INFO_STRING, STR_TYPE },
+};
+
+static int system_info_get_type(enum tag_type tag, const char *key,
+ system_info_type_e *type)
{
- int ret;
- double *ret_val;
- char *string = NULL;
+ char key_internal[KEY_MAX];
+ GDBM_FILE db = NULL;
+ datum d_key;
+ datum d_data;
+ int ret, i;
+ char *tag_s;
+
+ if (!key || !type)
+ return SYSTEM_INFO_ERROR_INVALID_PARAMETER;
- ret_val = (double *)value;
+ switch (tag) {
+ case TAG_TYPE_PLATFORM:
+ tag_s = TAG_TYPE_PLATFORM_STR;
+ break;
+ case TAG_TYPE_CUSTOM:
+ tag_s = TAG_TYPE_CUSTOM_STR;
+ break;
+ default:
+ return -EINVAL;
+ }
- 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;
+ db = gdbm_open(SYSTEM_INFO_DB_PATH, 0, GDBM_READER, S_IRUSR | S_IRGRP | S_IROTH, NULL);
+ if (!db) {
+ _E("Failed to open db (%d, %s)", gdbm_errno, gdbm_strerror(gdbm_errno));
return SYSTEM_INFO_ERROR_IO_ERROR;
}
- ret = system_info_get_value_from_config_xml(PLATFORM_TAG, key, DBL_TYPE, &string);
- if (ret) {
- _E("cannot get %s", key);
- return ret;
+ for (i = 0 ; i < ARRAY_SIZE(info_type); i++) {
+ if (strstr(key, KEY_PREFIX) == key)
+ snprintf(key_internal, sizeof(key_internal),
+ "%s:%s:%s", key, info_type[i].type_str, tag_s);
+ else
+ snprintf(key_internal, sizeof(key_internal),
+ "%s%s:%s:%s", KEY_PREFIX, key, info_type[i].type_str, tag_s);
+
+ d_key.dptr = key_internal;
+ d_key.dsize = strlen(key_internal) + 1;
+
+ d_data = gdbm_fetch(db, d_key);
+ if (d_data.dptr) {
+ *type = info_type[i].type_e;
+ ret = SYSTEM_INFO_ERROR_NONE;
+ goto out;
+ }
}
- *ret_val = atof(string);
-
- free(string);
+ if (tag == TAG_TYPE_PLATFORM)
+ ret = system_info_get_type_file(key, type);
+ else
+ ret = SYSTEM_INFO_ERROR_INVALID_PARAMETER;
- return SYSTEM_INFO_ERROR_NONE;
+out:
+ if (db)
+ gdbm_close(db);
+ return ret;
}
-API int system_info_get_platform_string(const char *key, char **value)
+static int system_info_get_bool(enum tag_type tag, const char *key, bool *value)
{
int ret;
- char *string = NULL;
+ char val[8];
+ char *valp;
+ size_t len;
- 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;
- }
+ if (!key || !value)
+ return SYSTEM_INFO_ERROR_INVALID_PARAMETER;
- ret = system_info_get_file(key, (void**)&string);
- if (ret == 0) {
- *value = string;
- return SYSTEM_INFO_ERROR_NONE;
- }
+ ret = db_get_value(tag, key, BOOL_TYPE, val, sizeof(val));
+ if (ret == SYSTEM_INFO_ERROR_NONE)
+ goto out;
- ret = system_info_get_value_from_config_xml(PLATFORM_TAG, key, STR_TYPE, &string);
- if (ret) {
- _E("cannot get %s", key);
- return ret;
+ if (tag == TAG_TYPE_CUSTOM) {
+ ret = external_get_value(TAG_TYPE_CUSTOM_STR, key, BOOL_TYPE, &valp);
+ if (ret == SYSTEM_INFO_ERROR_NONE) {
+ snprintf(val, sizeof(val), "%s", valp);
+ free(valp);
+ goto out;
+ }
}
- *value = string;
+ _E("Invalid key (%s), type:bool", key);
+
+ return SYSTEM_INFO_ERROR_INVALID_PARAMETER;
+
+out:
+ len = strlen(val) + 1;
+ if (!strncmp(val, "true", len) || !strncmp(val, "TRUE", len))
+ *value= true;
+ else
+ *value = false;
return SYSTEM_INFO_ERROR_NONE;
}
-API int system_info_get_custom_bool(const char *key, bool *value)
+static int system_info_get_int(enum tag_type tag, const char *key, int *value)
{
int ret;
- bool *supported;
- char *string = NULL;
+ char val[128];
+ char *valp;
- supported = (bool *)value;
+ if (!key || !value)
+ 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 = db_get_value(tag, key, INT_TYPE, val, sizeof(val));
+ if (ret == SYSTEM_INFO_ERROR_NONE)
+ goto out;
- ret = system_info_get_value_from_config_xml(CUSTOM_TAG, key, BOOL_TYPE, &string);
- if (ret) {
- _I("cannot get %s info from %s!!!", key, CONFIG_FILE_PATH);
- ret = external_get_value(CUSTOM_TAG, key, BOOL_TYPE, &string);
- if (ret) {
- _E("Cannot find key (%s) in the plugin (%d)", key, ret);
- return ret;
+ if (tag == TAG_TYPE_CUSTOM) {
+ ret = external_get_value(TAG_TYPE_CUSTOM_STR, key, INT_TYPE, &valp);
+ if (ret == SYSTEM_INFO_ERROR_NONE) {
+ snprintf(val, sizeof(val), "%s", valp);
+ free(valp);
+ goto out;
}
}
- if (!strcmp(string, "true") || !strcmp(string, "TRUE"))
- *supported = true;
- else
- *supported = false;
+ _E("Invalid key (%s), type:integer", key);
+
+ return SYSTEM_INFO_ERROR_INVALID_PARAMETER;
- free(string);
+out:
+ *value = atoi(val);
return SYSTEM_INFO_ERROR_NONE;
}
-API int system_info_get_custom_int(const char *key, int *value)
+static int system_info_get_double(enum tag_type tag, const char *key, double *value)
{
int ret;
- int *ret_val;
- char *string = NULL;
+ char val[128];
+ char *valp;
- ret_val = (int *)value;
+ if (!key || !value)
+ 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 = db_get_value(tag, key, DBL_TYPE, val, sizeof(val));
+ if (ret == SYSTEM_INFO_ERROR_NONE)
+ goto out;
- ret = system_info_get_value_from_config_xml(CUSTOM_TAG, key, INT_TYPE, &string);
- if (ret) {
- _I("cannot get %s info from %s!!!", key, CONFIG_FILE_PATH);
- ret = external_get_value(CUSTOM_TAG, key, INT_TYPE, &string);
- if (ret) {
- _E("Cannot find key (%s) in the plugin (%d)", key, ret);
- return ret;
+ if (tag == TAG_TYPE_CUSTOM) {
+ ret = external_get_value(TAG_TYPE_CUSTOM_STR, key, DBL_TYPE, &valp);
+ if (ret == SYSTEM_INFO_ERROR_NONE) {
+ snprintf(val, sizeof(val), "%s", valp);
+ free(valp);
+ goto out;
}
}
- *ret_val = atoi(string);
+ _E("Invalid key (%s), type:double", key);
+
+ return SYSTEM_INFO_ERROR_INVALID_PARAMETER;
- free(string);
+out:
+ *value = atof(val);
return SYSTEM_INFO_ERROR_NONE;
}
-API int system_info_get_custom_double(const char *key, double *value)
+static int system_info_get_string(enum tag_type tag, const char *key, char **value)
{
int ret;
- double *ret_val;
- char *string = NULL;
+ char val[STR_MAX];
+ char *string;
+ char *valp;
- ret_val = (double *)value;
+ if (!key || !value)
+ 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 = db_get_value(tag, key, STR_TYPE, val, sizeof(val));
+ if (ret == SYSTEM_INFO_ERROR_NONE)
+ goto out;
+
+ if (tag == TAG_TYPE_PLATFORM) {
+ ret = system_info_get_file(key, val, sizeof(val));
+ if (ret == SYSTEM_INFO_ERROR_NONE)
+ goto out;
}
- ret = system_info_get_value_from_config_xml(CUSTOM_TAG, key, DBL_TYPE, &string);
- if (ret) {
- _I("cannot get %s info from %s!!!", key, CONFIG_FILE_PATH);
- ret = external_get_value(CUSTOM_TAG, key, DBL_TYPE, &string);
- if (ret) {
- _E("Cannot find key (%s) in the plugin (%d)", key, ret);
- return ret;
+ if (tag == TAG_TYPE_CUSTOM) {
+ ret = external_get_value(TAG_TYPE_CUSTOM_STR, key, DBL_TYPE, &valp);
+ if (ret == SYSTEM_INFO_ERROR_NONE) {
+ snprintf(val, sizeof(val), "%s", valp);
+ free(valp);
+ goto out;
}
}
- *ret_val = atof(string);
+ _E("Invalid key (%s) type:string", key);
+
+ return SYSTEM_INFO_ERROR_INVALID_PARAMETER;
+
+out:
+ string = strdup(val);
+ if (!string) {
+ _E("malloc failed");
+ return SYSTEM_INFO_ERROR_OUT_OF_MEMORY;
+ }
- free(string);
+ *value = string;
return SYSTEM_INFO_ERROR_NONE;
}
-API int system_info_get_custom_string(const char *key, char **value)
+API int system_info_get_platform_bool(const char *key, bool *value)
{
- int ret;
- char *string = NULL;
+ return system_info_get_bool(TAG_TYPE_PLATFORM, key, value);
+}
- 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;
- }
+API int system_info_get_platform_int(const char *key, int *value)
+{
+ return system_info_get_int(TAG_TYPE_PLATFORM, key, value);
+}
- ret = system_info_get_value_from_config_xml(CUSTOM_TAG, key, STR_TYPE, &string);
- if (ret) {
- _I("cannot get %s info from %s!!!", key, CONFIG_FILE_PATH);
- ret = external_get_value(CUSTOM_TAG, key, STR_TYPE, &string);
- if (ret) {
- _E("Cannot find key (%s) in the plugin (%d)", key, ret);
- return ret;
- }
- }
+API int system_info_get_platform_double(const char *key, double *value)
+{
+ return system_info_get_double(TAG_TYPE_PLATFORM, key, value);
+}
- *value = string;
+API int system_info_get_platform_string(const char *key, char **value)
+{
+ return system_info_get_string(TAG_TYPE_PLATFORM, key, value);
+}
- return SYSTEM_INFO_ERROR_NONE;
+API int system_info_get_custom_bool(const char *key, bool *value)
+{
+ return system_info_get_bool(TAG_TYPE_CUSTOM, key, value);
}
-static int get_type_from_str(char *type)
+API int system_info_get_custom_int(const char *key, int *value)
{
- size_t len;
+ return system_info_get_int(TAG_TYPE_CUSTOM, key, value);
+}
- if (!type)
- return SYSTEM_INFO_ERROR_INVALID_PARAMETER;
+API int system_info_get_custom_double(const char *key, double *value)
+{
+ return system_info_get_double(TAG_TYPE_CUSTOM, key, value);
+}
- 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;
+API int system_info_get_custom_string(const char *key, char **value)
+{
+ return system_info_get_string(TAG_TYPE_CUSTOM, key, value);
+}
- return SYSTEM_INFO_ERROR_INVALID_PARAMETER;
+API int system_info_get_platform_type(const char *key, system_info_type_e *type)
+{
+ return system_info_get_type(TAG_TYPE_PLATFORM, key, type);
}
-static int system_info_get_type(const char *key,
- const char *tag, system_info_type_e *type)
+API int system_info_get_custom_type(const char *key, system_info_type_e *type)
{
- char type_str[16];
int ret;
+ char *val;
+ size_t len;
- 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(TAG_TYPE_CUSTOM, key, type);
+ if (ret == SYSTEM_INFO_ERROR_NONE)
+ return SYSTEM_INFO_ERROR_NONE;
- ret = system_info_get_type_from_config_xml(tag,
- key, type_str, sizeof(type_str));
+ ret = external_get_type(TAG_TYPE_CUSTOM_STR, key, &val);
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;
+ return SYSTEM_INFO_ERROR_INVALID_PARAMETER;
}
- ret = get_type_from_str(type_str);
- if (ret < 0) {
- _E("Invalid type (key:%s, type:%s)", key, type_str);
+ len = strlen(val) + 1;
+ if (!strncmp(BOOL_TYPE, val, len))
+ *type = SYSTEM_INFO_BOOL;
+ else if (!strncmp(INT_TYPE, val, len))
+ *type = SYSTEM_INFO_INT;
+ else if (!strncmp(DBL_TYPE, val, len))
+ *type = SYSTEM_INFO_DOUBLE;
+ else if (!strncmp(STR_TYPE, val, len))
+ *type = SYSTEM_INFO_STRING;
+ else {
+ _E("Invalid type (%s)", val);
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);
-}
return ret;
}
+
+int external_get_type(const char *tag, const char *key, char **type)
+{
+ void *handle = NULL;
+ int ret;
+ char buf[BUF_MAX];
+ const system_info_external_plugin_interface *plugin;
+ const system_info_external_plugin_interface *(*system_info_get_external_plugin_interface)(void);
+
+
+ if (access(EXTERNAL_SYSTEM_INFO, F_OK) != 0) {
+ _E("No external system info library");
+ return SYSTEM_INFO_ERROR_IO_ERROR;
+ }
+
+ handle = dlopen(EXTERNAL_SYSTEM_INFO, RTLD_NOW);
+ if (!handle) {
+ _E("dlopen(%s) failed(%s)", EXTERNAL_SYSTEM_INFO, dlerror());
+ ret = SYSTEM_INFO_ERROR_IO_ERROR;
+ goto out;
+ }
+
+ system_info_get_external_plugin_interface = dlsym(handle, "system_info_get_external_plugin_interface");
+ if (!system_info_get_external_plugin_interface) {
+ _E("dlsym failed(%s)", dlerror());
+ ret = SYSTEM_INFO_ERROR_IO_ERROR;
+ goto out;
+ }
+
+ plugin = system_info_get_external_plugin_interface();
+ if (!plugin) {
+ _E("Failed to get plugin");
+ ret = SYSTEM_INFO_ERROR_IO_ERROR;
+ goto out;
+ }
+
+ if (plugin->get_type_external == NULL) {
+ _E("Invalid plugin function");
+ ret = SYSTEM_INFO_ERROR_IO_ERROR;
+ goto out;
+ }
+
+ ret = plugin->get_type_external(tag, key, buf, sizeof(buf));
+ if (ret < 0) {
+ _E("Failed to get value from plugin (ret:%d)", ret);
+ ret = SYSTEM_INFO_ERROR_IO_ERROR;
+ goto out;
+ }
+
+ *type = strdup(buf);
+ if (*type == NULL) {
+ _E("strdup() failed");
+ ret = SYSTEM_INFO_ERROR_OUT_OF_MEMORY;
+ goto out;
+ }
+
+ ret = SYSTEM_INFO_ERROR_NONE;
+
+out:
+ if (handle)
+ dlclose(handle);
+
+ return ret;
+}
#include <system_info.h>
#include <system_info_private.h>
-#define SERIAL_TOK_DELIMITER ","
+#define KEY_PREFIX "http://"
+
#define BUF_MAX 256
+#define KEY_MAX 128
#define ARRAY_SIZE(name) (sizeof(name)/sizeof(name[0]))
-static int get_tizenid(char **value)
+static int get_tizenid(char *val, size_t len)
{
char id[BUF_MAX];
FILE *fp;
return SYSTEM_INFO_ERROR_IO_ERROR;
}
- *value = strdup(id);
-
- 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);
-}
-
-static int get_build_id(char **value)
-{
- return system_info_ini_get_string(INFO_FILE_PATH, "build:id", value);
-}
-
-static int get_build_type(char **value)
-{
- return system_info_ini_get_string(INFO_FILE_PATH, "build:type", value);
-}
-
-static int get_build_variant(char **value)
-{
- return system_info_ini_get_string(INFO_FILE_PATH, "build:variant", value);
-}
-
-static int get_build_version_release(char **value)
-{
- return system_info_ini_get_string(INFO_FILE_PATH, "version:release", value);
+ snprintf(val, len, "%s", id);
+ return SYSTEM_INFO_ERROR_NONE;
}
struct system_info_file_key {
const char *key;
- int (*get_value)(char **val);
+ int (*get_value)(char *val, size_t len);
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 },
- { "tizen.org/system/build.id", get_build_id, SYSTEM_INFO_STRING },
- { "tizen.org/system/build.type", get_build_type, SYSTEM_INFO_STRING },
- { "tizen.org/system/build.variant", get_build_variant, SYSTEM_INFO_STRING },
- { "tizen.org/system/build.version.release", get_build_version_release, SYSTEM_INFO_STRING }
+ { "http://tizen.org/system/tizenid", get_tizenid, SYSTEM_INFO_STRING },
};
-int system_info_get_file(const char *key, void **value)
+int system_info_get_file(const char *key, char *value, size_t len)
{
- char *p_key;
- int i, len;
+ char p_key[KEY_MAX];
+ int i;
+ size_t p_len;
if (!key || !value)
- return -EINVAL;
+ return SYSTEM_INFO_ERROR_INVALID_PARAMETER;
- p_key = strstr(key, "http://");
- if (p_key && p_key == key)
- p_key = (char *)key + strlen("http://");
+ if (strstr(key, KEY_PREFIX) == key)
+ snprintf(p_key, sizeof(p_key), "%s", key);
else
- p_key = (char *)key;
+ snprintf(p_key, sizeof(p_key), "%s%s", KEY_PREFIX, key);
- len = strlen(p_key) + 1;
+ p_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);
+ if (!strncmp(p_key, info_file_key[i].key, p_len))
+ return info_file_key[i].get_value(value, len);
- return -ENOENT;
+ return SYSTEM_INFO_ERROR_INVALID_PARAMETER;
}
-int system_info_get_type_file(const char *key)
+int system_info_get_type_file(const char *key, system_info_type_e *type)
{
- char *p_key;
+ char p_key[KEY_MAX];
int i, len;
if (!key)
return SYSTEM_INFO_ERROR_INVALID_PARAMETER;
- p_key = strstr(key, "http://");
- if (p_key && p_key == key)
- p_key = (char *)key + strlen("http://");
+ if (strstr(key, KEY_PREFIX) == key)
+ snprintf(p_key, sizeof(p_key), "%s", key);
else
- p_key = (char *)key;
+ snprintf(p_key, sizeof(p_key), "%s%s", KEY_PREFIX, key);
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;
+ if (strncmp(p_key, info_file_key[i].key, len))
+ continue;
+ *type = info_file_key[i].type;
+ return SYSTEM_INFO_ERROR_NONE;
}
return SYSTEM_INFO_ERROR_INVALID_PARAMETER;
+++ /dev/null
-/*
- * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an AS IS BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <system_info.h>
-#include <system_info_private.h>
-
-#include <iniparser.h>
-
-#include <libxml/xmlmemory.h>
-#include <libxml/parser.h>
-#include <libxml/tree.h>
-
-#define MODEL_CONFIG_TAG "model-config"
-
-int system_info_ini_get_string(char *ini_file, char *key, char **output)
-{
- dictionary *ini;
- char *str;
- char *tmp;
-
- ini = iniparser_load(ini_file);
-
- if (ini == NULL) {
- _E("cannot file open %s file!!!", ini_file);
- return SYSTEM_INFO_ERROR_IO_ERROR;
- }
-
- str = iniparser_getstring(ini, key, NULL);
-
- if (str == NULL) {
- _E("NOT found %s(0x%08x)", key, SYSTEM_INFO_ERROR_IO_ERROR);
- iniparser_freedict(ini);
- return SYSTEM_INFO_ERROR_IO_ERROR;
- }
-
- tmp = strdup(str);
-
- if (tmp == NULL) {
- _E("OUT_OF_MEMORY(0x%08x)", SYSTEM_INFO_ERROR_OUT_OF_MEMORY);
- iniparser_freedict(ini);
- return SYSTEM_INFO_ERROR_OUT_OF_MEMORY;
- }
-
- *output = tmp;
- iniparser_freedict(ini);
-
- return SYSTEM_INFO_ERROR_NONE;
-}
-
-int system_info_get_value_from_config_xml(char *feature_tag, const char *name_field, char *type_field, char **value)
-{
- xmlDocPtr doc = NULL;
- xmlNodePtr cur = NULL;
- xmlNodePtr model_node = NULL;
- xmlNode *cur_node = NULL;
- char *name = NULL, *p_name = NULL;
- char *type = NULL;
- char *string = NULL;
-
- doc = xmlParseFile(CONFIG_FILE_PATH);
-
- if (doc == NULL) {
- _E("cannot file open %s file!!!", CONFIG_FILE_PATH);
- return SYSTEM_INFO_ERROR_IO_ERROR;
- }
-
- cur = xmlDocGetRootElement(doc);
- if (cur == NULL) {
- _E("empty document %s file!!!", CONFIG_FILE_PATH);
- xmlFreeDoc(doc);
- return SYSTEM_INFO_ERROR_IO_ERROR;
- }
-
- for (cur_node = cur; cur_node; cur_node = cur_node->next) {
- if (!xmlStrcmp(cur->name, (const xmlChar*)MODEL_CONFIG_TAG))
- break;
- }
-
- if (cur == NULL) {
- _E("cannot find %s root element file!!!", MODEL_CONFIG_TAG);
- xmlFreeDoc(doc);
- return SYSTEM_INFO_ERROR_IO_ERROR;
- }
-
- cur = cur->xmlChildrenNode;
-
- 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 == NULL) {
- _E("cannot find %s field from %s file!!!", name_field, CONFIG_FILE_PATH);
- xmlFreeDoc(doc);
- return SYSTEM_INFO_ERROR_INVALID_PARAMETER;
- }
-
- if (model_node) {
- cur = model_node->xmlChildrenNode;
-
- for (cur_node = cur; cur_node; cur_node = cur_node->next) {
- if (cur_node->type == XML_ELEMENT_NODE) {
- name = (char *)xmlGetProp(cur_node, (const xmlChar*)"name");
- type = (char *)xmlGetProp(cur_node, (const xmlChar*)"type");
-
- 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;
-
- if (!strncmp(name, p_name, strlen(name))) {
- if (!strncmp(name, p_name, strlen(p_name))) {
- if (strncmp(type, type_field, strlen(type_field))) {
- _E("INVALID_PARAMETER(0x%08x) : invalid output param", SYSTEM_INFO_ERROR_INVALID_PARAMETER);
- free(name);
- free(type);
- xmlFreeDoc(doc);
- return SYSTEM_INFO_ERROR_INVALID_PARAMETER;
- }
- string = (char *)xmlNodeListGetString(doc, cur_node->xmlChildrenNode, 1);
- if (string) {
- *value = strdup(string);
- free(name);
- free(type);
- free(string);
- break;
- }
- }
- }
- free(name);
- free(type);
- }
- }
- }
-
- if (!cur_node) {
- _E("cannot find %s field from %s file!!!", name_field, CONFIG_FILE_PATH);
- xmlFreeDoc(doc);
- return SYSTEM_INFO_ERROR_INVALID_PARAMETER;
- }
-
- if (*value == NULL) {
- _E("OUT_OF_MEMORY(0x%08x)", SYSTEM_INFO_ERROR_OUT_OF_MEMORY);
- xmlFreeDoc(doc);
- return SYSTEM_INFO_ERROR_OUT_OF_MEMORY;
- }
-
- 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;
-}