2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
24 #include <system_info.h>
25 #include <system_info_private.h>
27 #include <iniparser.h>
29 #include <libxml/xmlmemory.h>
30 #include <libxml/parser.h>
31 #include <libxml/tree.h>
37 #define LOG_TAG "CAPI_SYSTEM_INFO"
39 #define MODEL_CONFIG_TAG "model-config"
41 int system_info_ini_get_string(char *ini_file, char *key, char **output)
47 ini = iniparser_load(ini_file);
50 LOGE("cannot file open %s file!!!", ini_file);
51 return SYSTEM_INFO_ERROR_IO_ERROR;
54 str = iniparser_getstr(ini, key);
57 LOGE("NOT found %s(0x%08x)", key, SYSTEM_INFO_ERROR_IO_ERROR);
58 iniparser_freedict(ini);
59 return SYSTEM_INFO_ERROR_IO_ERROR;
65 LOGE("OUT_OF_MEMORY(0x%08x)", SYSTEM_INFO_ERROR_OUT_OF_MEMORY);
66 iniparser_freedict(ini);
67 return SYSTEM_INFO_ERROR_OUT_OF_MEMORY;
71 iniparser_freedict(ini);
73 return SYSTEM_INFO_ERROR_NONE;
76 int system_info_get_value_from_xml(char *xml_file_path, char *model, char *id_field, char **value)
79 xmlNodePtr cur = NULL;
80 xmlNodePtr default_node = NULL;
81 xmlNodePtr model_node = NULL;
82 xmlNode *cur_node = NULL;
86 doc = xmlParseFile(xml_file_path);
89 LOGE("cannot file open %s file!!!", xml_file_path);
90 return SYSTEM_INFO_ERROR_IO_ERROR;
93 cur = xmlDocGetRootElement(doc);
95 LOGE("empty document %s file!!!", xml_file_path);
97 return SYSTEM_INFO_ERROR_IO_ERROR;
100 for (cur_node = cur; cur_node; cur_node = cur_node->next) {
101 if (!xmlStrcmp(cur->name, (const xmlChar*)"sys-info"))
106 LOGE("cannot find %s root element file!!!", "sys-info");
108 return SYSTEM_INFO_ERROR_IO_ERROR;
111 cur = cur->xmlChildrenNode;
113 for (cur_node = cur; cur_node; cur_node = cur_node->next) {
114 if (!xmlStrcmp(cur_node->name, (const xmlChar*)"default"))
115 default_node = cur_node;
116 if (strcmp(model, "default") && !xmlStrcmp(cur_node->name, (const xmlChar*)model))
117 model_node = cur_node;
121 cur = model_node->xmlChildrenNode;
123 for (cur_node = cur; cur_node; cur_node = cur_node->next) {
124 if (cur_node->type == XML_ELEMENT_NODE) {
125 id = (char *)xmlGetProp(cur_node, (const xmlChar*)"id");
126 string = (char *) xmlGetProp(cur_node, (const xmlChar*)"string");
128 if (!strncmp(id, id_field, strlen(id_field))) {
134 *value = strdup(string);
138 if (*value == NULL) {
139 LOGE("OUT_OF_MEMORY(0x%08x)", SYSTEM_INFO_ERROR_OUT_OF_MEMORY);
141 return SYSTEM_INFO_ERROR_OUT_OF_MEMORY;
143 return SYSTEM_INFO_ERROR_NONE;
151 if (*value == NULL && default_node) {
152 cur = default_node->xmlChildrenNode;
154 for (cur_node = cur; cur_node; cur_node = cur_node->next) {
155 if (cur_node->type == XML_ELEMENT_NODE) {
156 id = (char *)xmlGetProp(cur_node, (const xmlChar*)"id");
157 string = (char *) xmlGetProp(cur_node, (const xmlChar*)"string");
159 if (!strncmp(id, id_field, strlen(id_field))) {
165 *value = strdup(string);
169 if (*value == NULL) {
170 LOGE("OUT_OF_MEMORY(0x%08x)", SYSTEM_INFO_ERROR_OUT_OF_MEMORY);
172 return SYSTEM_INFO_ERROR_OUT_OF_MEMORY;
174 return SYSTEM_INFO_ERROR_NONE;
182 LOGE("cannot find %s field from %s file!!!", id_field, xml_file_path);
184 return SYSTEM_INFO_ERROR_IO_ERROR;
187 int system_info_get_value_from_config_xml(char *feature_tag, const char *name_field, char *type_field, char **value)
189 xmlDocPtr doc = NULL;
190 xmlNodePtr cur = NULL;
191 xmlNodePtr model_node = NULL;
192 xmlNode *cur_node = NULL;
197 doc = xmlParseFile(CONFIG_FILE_PATH);
200 LOGE("cannot file open %s file!!!", CONFIG_FILE_PATH);
201 return SYSTEM_INFO_ERROR_IO_ERROR;
204 cur = xmlDocGetRootElement(doc);
206 LOGE("empty document %s file!!!", CONFIG_FILE_PATH);
208 return SYSTEM_INFO_ERROR_IO_ERROR;
211 for (cur_node = cur; cur_node; cur_node = cur_node->next) {
212 if (!xmlStrcmp(cur->name, (const xmlChar*)MODEL_CONFIG_TAG))
217 LOGE("cannot find %s root element file!!!", MODEL_CONFIG_TAG);
219 return SYSTEM_INFO_ERROR_IO_ERROR;
222 cur = cur->xmlChildrenNode;
224 for (cur_node = cur; cur_node; cur_node = cur_node->next) {
225 if (!xmlStrcmp(cur_node->name, (const xmlChar*)feature_tag))
226 model_node = cur_node;
229 if (model_node == NULL) {
230 LOGE("cannot find %s field from %s file!!!", name_field, CONFIG_FILE_PATH);
232 return SYSTEM_INFO_ERROR_IO_ERROR;
236 cur = model_node->xmlChildrenNode;
238 for (cur_node = cur; cur_node; cur_node = cur_node->next) {
239 if (cur_node->type == XML_ELEMENT_NODE) {
240 name = (char *)xmlGetProp(cur_node, (const xmlChar*)"name");
241 type = (char *)xmlGetProp(cur_node, (const xmlChar*)"type");
243 if (!strncmp(name, name_field, strlen(name_field))) {
244 if (strncmp(type, type_field, strlen(type_field))) {
245 LOGE("INVALID_PARAMETER(0x%08x) : invalid output param", SYSTEM_INFO_ERROR_INVALID_PARAMETER);
249 return SYSTEM_INFO_ERROR_INVALID_PARAMETER;
251 string = (char *)xmlNodeListGetString(doc, cur_node->xmlChildrenNode, 1);
253 *value = strdup(string);
267 LOGE("cannot find %s field from %s file!!!", name_field, CONFIG_FILE_PATH);
269 return SYSTEM_INFO_ERROR_IO_ERROR;
272 if (*value == NULL) {
273 LOGE("OUT_OF_MEMORY(0x%08x)", SYSTEM_INFO_ERROR_OUT_OF_MEMORY);
275 return SYSTEM_INFO_ERROR_OUT_OF_MEMORY;
279 return SYSTEM_INFO_ERROR_NONE;