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))) {
130 *value = strdup(string);
138 if (*value == NULL && default_node) {
139 cur = default_node->xmlChildrenNode;
141 for (cur_node = cur; cur_node; cur_node = cur_node->next) {
142 if (cur_node->type == XML_ELEMENT_NODE) {
143 id = (char *)xmlGetProp(cur_node, (const xmlChar*)"id");
144 string = (char *) xmlGetProp(cur_node, (const xmlChar*)"string");
146 if (!strncmp(id, id_field, strlen(id_field))) {
148 *value = strdup(string);
161 LOGE("cannot find %s field from %s file!!!", id_field, xml_file_path);
163 return SYSTEM_INFO_ERROR_IO_ERROR;
166 if (*value == NULL) {
167 LOGE("OUT_OF_MEMORY(0x%08x)", SYSTEM_INFO_ERROR_OUT_OF_MEMORY);
169 return SYSTEM_INFO_ERROR_OUT_OF_MEMORY;
173 return SYSTEM_INFO_ERROR_NONE;
176 int system_info_get_value_from_config_xml(char *feature_tag, const char *name_field, char *type_field, char **value)
178 xmlDocPtr doc = NULL;
179 xmlNodePtr cur = NULL;
180 xmlNodePtr model_node = NULL;
181 xmlNode *cur_node = NULL;
186 doc = xmlParseFile(CONFIG_FILE_PATH);
189 LOGE("cannot file open %s file!!!", CONFIG_FILE_PATH);
190 return SYSTEM_INFO_ERROR_IO_ERROR;
193 cur = xmlDocGetRootElement(doc);
195 LOGE("empty document %s file!!!", CONFIG_FILE_PATH);
197 return SYSTEM_INFO_ERROR_IO_ERROR;
200 for (cur_node = cur; cur_node; cur_node = cur_node->next) {
201 if (!xmlStrcmp(cur->name, (const xmlChar*)MODEL_CONFIG_TAG))
206 LOGE("cannot find %s root element file!!!", MODEL_CONFIG_TAG);
208 return SYSTEM_INFO_ERROR_IO_ERROR;
211 cur = cur->xmlChildrenNode;
213 for (cur_node = cur; cur_node; cur_node = cur_node->next) {
214 if (!xmlStrcmp(cur_node->name, (const xmlChar*)feature_tag))
215 model_node = cur_node;
218 if (model_node == NULL) {
219 LOGE("cannot find %s field from %s file!!!", name_field, CONFIG_FILE_PATH);
221 return SYSTEM_INFO_ERROR_IO_ERROR;
225 cur = model_node->xmlChildrenNode;
227 for (cur_node = cur; cur_node; cur_node = cur_node->next) {
228 if (cur_node->type == XML_ELEMENT_NODE) {
229 name = (char *)xmlGetProp(cur_node, (const xmlChar*)"name");
230 type = (char *)xmlGetProp(cur_node, (const xmlChar*)"type");
232 if (!strncmp(name, name_field, strlen(name_field))) {
233 if (strncmp(type, type_field, strlen(type_field))) {
234 LOGE("INVALID_PARAMETER(0x%08x) : invalid output param", SYSTEM_INFO_ERROR_INVALID_PARAMETER);
238 return SYSTEM_INFO_ERROR_INVALID_PARAMETER;
240 string = (char *)xmlNodeListGetString(doc, cur_node->xmlChildrenNode, 1);
242 *value = strdup(string);
256 LOGE("cannot find %s field from %s file!!!", name_field, CONFIG_FILE_PATH);
258 return SYSTEM_INFO_ERROR_IO_ERROR;
261 if (*value == NULL) {
262 LOGE("OUT_OF_MEMORY(0x%08x)", SYSTEM_INFO_ERROR_OUT_OF_MEMORY);
264 return SYSTEM_INFO_ERROR_OUT_OF_MEMORY;
268 return SYSTEM_INFO_ERROR_NONE;