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))) {
129 if (!strncmp(id, id_field, strlen(id_field))) {
135 *value = strdup(string);
139 if (*value == NULL) {
140 LOGE("OUT_OF_MEMORY(0x%08x)", SYSTEM_INFO_ERROR_OUT_OF_MEMORY);
142 return SYSTEM_INFO_ERROR_OUT_OF_MEMORY;
144 return SYSTEM_INFO_ERROR_NONE;
153 if (*value == NULL && default_node) {
154 cur = default_node->xmlChildrenNode;
156 for (cur_node = cur; cur_node; cur_node = cur_node->next) {
157 if (cur_node->type == XML_ELEMENT_NODE) {
158 id = (char *)xmlGetProp(cur_node, (const xmlChar*)"id");
159 string = (char *) xmlGetProp(cur_node, (const xmlChar*)"string");
161 if (!strncmp(id, id_field, strlen(id))) {
162 if (!strncmp(id, id_field, strlen(id_field))) {
168 *value = strdup(string);
172 if (*value == NULL) {
173 LOGE("OUT_OF_MEMORY(0x%08x)", SYSTEM_INFO_ERROR_OUT_OF_MEMORY);
175 return SYSTEM_INFO_ERROR_OUT_OF_MEMORY;
177 return SYSTEM_INFO_ERROR_NONE;
186 LOGE("cannot find %s field from %s file!!!", id_field, xml_file_path);
188 return SYSTEM_INFO_ERROR_IO_ERROR;
191 int system_info_get_value_from_config_xml(char *feature_tag, const char *name_field, char *type_field, char **value)
193 xmlDocPtr doc = NULL;
194 xmlNodePtr cur = NULL;
195 xmlNodePtr model_node = NULL;
196 xmlNode *cur_node = NULL;
201 doc = xmlParseFile(CONFIG_FILE_PATH);
204 LOGE("cannot file open %s file!!!", CONFIG_FILE_PATH);
205 return SYSTEM_INFO_ERROR_IO_ERROR;
208 cur = xmlDocGetRootElement(doc);
210 LOGE("empty document %s file!!!", CONFIG_FILE_PATH);
212 return SYSTEM_INFO_ERROR_IO_ERROR;
215 for (cur_node = cur; cur_node; cur_node = cur_node->next) {
216 if (!xmlStrcmp(cur->name, (const xmlChar*)MODEL_CONFIG_TAG))
221 LOGE("cannot find %s root element file!!!", MODEL_CONFIG_TAG);
223 return SYSTEM_INFO_ERROR_IO_ERROR;
226 cur = cur->xmlChildrenNode;
228 for (cur_node = cur; cur_node; cur_node = cur_node->next) {
229 if (!xmlStrcmp(cur_node->name, (const xmlChar*)feature_tag))
230 model_node = cur_node;
233 if (model_node == NULL) {
234 LOGE("cannot find %s field from %s file!!!", name_field, CONFIG_FILE_PATH);
236 return SYSTEM_INFO_ERROR_IO_ERROR;
240 cur = model_node->xmlChildrenNode;
242 for (cur_node = cur; cur_node; cur_node = cur_node->next) {
243 if (cur_node->type == XML_ELEMENT_NODE) {
244 name = (char *)xmlGetProp(cur_node, (const xmlChar*)"name");
245 type = (char *)xmlGetProp(cur_node, (const xmlChar*)"type");
247 if (!strncmp(name, name_field, strlen(name))) {
248 if (!strncmp(name, name_field, strlen(name_field))) {
249 if (strncmp(type, type_field, strlen(type_field))) {
250 LOGE("INVALID_PARAMETER(0x%08x) : invalid output param", SYSTEM_INFO_ERROR_INVALID_PARAMETER);
254 return SYSTEM_INFO_ERROR_INVALID_PARAMETER;
256 string = (char *)xmlNodeListGetString(doc, cur_node->xmlChildrenNode, 1);
258 *value = strdup(string);
273 LOGE("cannot find %s field from %s file!!!", name_field, CONFIG_FILE_PATH);
275 return SYSTEM_INFO_ERROR_IO_ERROR;
278 if (*value == NULL) {
279 LOGE("OUT_OF_MEMORY(0x%08x)", SYSTEM_INFO_ERROR_OUT_OF_MEMORY);
281 return SYSTEM_INFO_ERROR_OUT_OF_MEMORY;
285 return SYSTEM_INFO_ERROR_NONE;