4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd.
6 * Contact: MyoungJune Park <mj2004.park@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
21 #include <setting-common-data-slp-setting.h>
22 #include <Elementary.h>
25 #include <openssl/sha.h>
27 #include <sys/types.h>
32 #include <libxml/xmlmemory.h>
33 #include <libxml/parser.h>
50 typedef struct VconfNode VconfNode;
53 int key; /** vconf id definded in Setting app */
54 const char* vconf_key; /** vconf string defined in libslp-setting */
55 vconftype type; /** BOOL, INT, STRING */
56 vconfval value; /** variable by union */
57 void (*export)(VconfNode* pnode); /** method for exporting current state */
61 // export function for each vconf key
62 void export_default(VconfNode* node)
64 SETTING_TRACE("key : %s ",node->vconf_key);
68 /** bool vconf table */
69 static VconfNode g_btable[] = {
71 {BOOL_SLP_SETTING_POWER_ON_LOCK, VCONFKEY_SETAPPL_STATE_POWER_ON_LOCK_BOOL, eBOOL, {0}, export_default}, // node[0]
72 {BOOL_SLP_SETTING_SIMPLE_PASSWORD, VCONFKEY_SETAPPL_STATE_SIMPLE_PASSWORD_BOOL, eBOOL, {0}, export_default}, // node[0]
74 {BOOL_SLP_SETTING_AUTOMATIC_TIME_UPDATE, VCONFKEY_SETAPPL_STATE_AUTOMATIC_TIME_UPDATE_BOOL, eBOOL,{0}, export_default},
76 {BOOL_SLP_SETTING_TICKER_NOTI_MESSAGES, VCONFKEY_SETAPPL_STATE_TICKER_NOTI_MESSAGES_BOOL, eBOOL,{0}, export_default},
77 {BOOL_SLP_SETTING_TICKER_NOTI_EMAIL, VCONFKEY_SETAPPL_STATE_TICKER_NOTI_EMAIL_BOOL, eBOOL,{0}, export_default},
78 {BOOL_SLP_SETTING_TICKER_NOTI_IM, VCONFKEY_SETAPPL_STATE_TICKER_NOTI_IM_BOOL, eBOOL,{0}, export_default},
79 {BOOL_SLP_SETTING_TICKER_NOTI_FACEBOOK, VCONFKEY_SETAPPL_STATE_TICKER_NOTI_FACEBOOK_BOOL, eBOOL,{0}, export_default},
80 {BOOL_SLP_SETTING_TICKER_NOTI_TWITTER, VCONFKEY_SETAPPL_STATE_TICKER_NOTI_TWITTER_BOOL, eBOOL,{0}, export_default},
82 {BOOL_SLP_SETTING_TRANSACTION_TRACKING, VCONFKEY_SETAPPL_STATE_TRANSACTION_TRACKING_BOOL, eBOOL,{0}, export_default},
84 {BOOL_SLP_SETTING_NOTI_DISPLAY_CONTENT_MESSASGES, VCONFKEY_TICKER_NOTI_DISPLAY_CONTENT_MESSASGES, eBOOL, {0}, export_default},
85 {BOOL_SLP_SETTING_NOTI_DISPLAY_CONTENT_EMAIL, VCONFKEY_TICKER_NOTI_DISPLAY_CONTENT_EMAIL, eBOOL, {0}, export_default},
86 {BOOL_SLP_SETTING_NOTI_DISPLAY_CONTENT_IM, VCONFKEY_TICKER_NOTI_DISPLAY_CONTENT_IM, eBOOL, {0}, export_default},
87 {BOOL_SLP_SETTING_NOTI_DISPLAY_CONTENT_FACEBOOK, VCONFKEY_TICKER_NOTI_DISPLAY_CONTENT_FACEBOOK, eBOOL, {0}, export_default},
88 {BOOL_SLP_SETTING_NOTI_DISPLAY_CONTENT_TWITTER, VCONFKEY_TICKER_NOTI_DISPLAY_CONTENT_TWITTER, eBOOL, {0}, export_default},
90 {BOOL_SLP_SETTING_EXPIRY_REMINDER, VCONFKEY_SETAPPL_STATE_EXPIRY_REMINDER_BOOL, eBOOL,{0}, export_default},
92 {BOOL_SLP_SETTING_FLIGHT_MODE, VCONFKEY_SETAPPL_FLIGHT_MODE_BOOL, eBOOL,{0}, export_default},
93 {BOOL_SLP_SETTING_DATA_ROAMING, VCONFKEY_SETAPPL_STATE_DATA_ROAMING_BOOL, eBOOL,{0}, export_default},
94 {BOOL_SLP_SETTING_NFC_STATUS,VCONFKEY_NFC_STATE, eBOOL, {0}, export_default},
96 {BOOL_SLP_SETTING_USE_PACKET_DATA, VCONFKEY_3G_ENABLE, eBOOL,{0}, export_default},
97 {BOOL_SLP_SETTING_ACCESSIBILITY_ACCESSIBILITY, VCONFKEY_SETAPPL_ACCESSIBILITY_ACCESSIBILITY, eBOOL,{0}, export_default},
98 {BOOL_SLP_SETTING_ACCESSIBILITY_HIGH_CONTRAST, VCONFKEY_SETAPPL_ACCESSIBILITY_HIGH_CONTRAST, eBOOL,{0}, export_default},
99 {BOOL_SLP_SETTING_ACCESSIBILITY_SCREEN_ZOOM, VCONFKEY_SETAPPL_ACCESSIBILITY_SCREEN_ZOOM, eBOOL,{0}, export_default},
100 {BOOL_SLP_SETTING_ACCESSIBILITY_ASSISTIVE_LIGHT, VCONFKEY_SETAPPL_ACCESSIBILITY_TORCH_LIGHT, eBOOL,{0}, export_default},
101 {BOOL_SLP_SETTING_ACCESSIBILITY_MONO_AUDIO, VCONFKEY_SETAPPL_ACCESSIBILITY_MONO_AUDIO, eBOOL,{0}, export_default},
102 {BOOL_SLP_SETTING_ACCESSIBILITY_LED_NOTIFY, VCONFKEY_SETAPPL_ACCESSIBILITY_LED_NOTIFY, eBOOL,{0}, export_default},
103 {BOOL_SLP_SETTING_ACCESSIBILITY_ACCEPT_CALL, VCONFKEY_CISSAPPL_ANSWERING_KEY_BOOL, eBOOL,{0}, export_default},
104 {BOOL_SLP_SETTING_ACCESSIBILITY_POWERKEY_END_CALLS, VCONFKEY_CISSAPPL_POWER_KEY_ENDS_CALL_BOOL, eBOOL,{0}, export_default},
107 {BOOL_SLP_SETTING_DATAUSAGE_MOBILE_DATA_BOOL, VCONFKEY_SETAPPL_MOBILE_DATA_BOOL, eBOOL, {0}, export_default},
108 {BOOL_SLP_SETTING_DATAUSAGE_DISABLE_MOBILE_DATA_AT_LIMIT_BOOL, VCONFKEY_SETAPPL_DISABLE_MOBILE_DATA_AT_LIMIT_BOOL, eBOOL, {0}, export_default},
109 {BOOL_SLP_SETTING_DATAUSAGE_RESTRICT_BG_DATA_BOOL, VCONFKEY_SETAPPL_RESTRICT_BG_DATA_BOOL, eBOOL, {0}, export_default},
110 {BOOL_SLP_SETTING_DATAUSAGE_SHOW_WIFI_USAGE_BOOL, VCONFKEY_SETAPPL_SHOW_WIFI_USAGE_BOOL, eBOOL, {0}, export_default},
111 //------------------------------------------------------------------------------------------------
112 {SETTING_BOOL_SLP_LIST_MAX, NULL, eBOOL, {0}, export_default},
116 /** int vconf table */
117 static VconfNode g_itable[] = {
118 {INT_SLP_SETTING_LCD_BRIGHTNESS, VCONFKEY_SETAPPL_LCD_BRIGHTNESS, eINT, {0}, export_default},
119 {INT_SLP_SETTING_LCD_TIMEOUT_NORMAL,VCONFKEY_SETAPPL_LCD_TIMEOUT_NORMAL, eINT, {0}, export_default},
120 {INT_SLP_SETTING_LCD_TIMEOUT_NORMAL_BACKUP,VCONFKEY_LCD_TIMEOUT_NORMAL_BACKUP, eINT, {0}, export_default},
122 {INT_SLP_SETTING_AUTOMATIC_BRIGHTNESS, VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, eINT,{0}, export_default},
124 {INT_SLP_SETTING_SELECT_NETWORK,VCONFKEY_SETAPPL_SELECT_NETWORK_INT, eINT, {0}, export_default},
125 {INT_SLP_SETTING_NETWORK_MODE,VCONFKEY_SETAPPL_NETWORK_MODE_INT, eINT, {0}, export_default},
126 {INT_SLP_SETTING_REGIONFORMAT_TIME1224,VCONFKEY_REGIONFORMAT_TIME1224, eINT, {0}, export_default},
127 {INT_SLP_SETTING_DATE_FORMAT,VCONFKEY_SETAPPL_DATE_FORMAT_INT, eINT, {0}, export_default},
128 {INT_SLP_SETTING_WEEK_FORMAT,VCONFKEY_SETAPPL_WEEKOFDAY_FORMAT_INT, eINT, {0}, export_default},
129 /* CALL_ALERT_TYPE */
130 {INT_SLP_SETTING_CALL_ALERT_TYPE, NULL, eINT, {0}, export_default},
131 {INT_SLP_SETTING_NORMAL_CALL_ALERT_TYPE, NULL, eINT, {0}, export_default},
132 {INT_SLP_SETTING_SILENT_CALL_ALERT_TYPE, NULL, eINT, {0}, export_default},
133 {INT_SLP_SETTING_DRIVING_CALL_ALERT_TYPE, NULL, eINT, {0}, export_default},
134 {INT_SLP_SETTING_MEETING_CALL_ALERT_TYPE, NULL, eINT, {0}, export_default},
135 {INT_SLP_SETTING_OUTDOOR_CALL_ALERT_TYPE, NULL, eINT, {0}, export_default},
137 {INT_SLP_SETTING_CALL_ALERT_VIB, VCONFKEY_SETAPPL_CALL_VIBRATION_PATTERN_INT, eINT, {0}, export_default},
138 {INT_SLP_SETTING_NORMAL_CALL_ALERT_VIB, NULL, eINT, {0}, export_default},
139 {INT_SLP_SETTING_SILENT_CALL_ALERT_VIB, NULL, eINT, {0}, export_default},
140 {INT_SLP_SETTING_DRIVING_CALL_ALERT_VIB, NULL, eINT, {0}, export_default},
141 {INT_SLP_SETTING_MEETING_CALL_ALERT_VIB, NULL, eINT, {0}, export_default},
142 {INT_SLP_SETTING_OUTDOOR_CALL_ALERT_VIB, NULL, eINT, {0}, export_default},
145 {INT_SLP_SETTING_CALL_ALERT_VOLUME, NULL, eINT, {0}, export_default},
147 {INT_SLP_SETTING_MSG_ALERT_TYPE, NULL, eINT, {0}, export_default},
148 {INT_SLP_SETTING_NORMAL_MSG_ALERT_TYPE, NULL, eINT, {0}, export_default},
149 {INT_SLP_SETTING_SILENT_MSG_ALERT_TYPE, NULL, eINT, {0}, export_default},
150 {INT_SLP_SETTING_DRIVING_MSG_ALERT_TYPE, NULL, eINT, {0}, export_default},
151 {INT_SLP_SETTING_MEETING_MSG_ALERT_TYPE, NULL, eINT, {0}, export_default},
152 {INT_SLP_SETTING_OUTDOOR_MSG_ALERT_TYPE, NULL, eINT, {0}, export_default},
154 {INT_SLP_SETTING_MSG_ALERT_VIB, NULL, eINT, {0}, export_default},
155 {INT_SLP_SETTING_NORMAL_MSG_ALERT_VIB, NULL, eINT, {0}, export_default},
156 {INT_SLP_SETTING_SILENT_MSG_ALERT_VIB, NULL, eINT, {0}, export_default},
157 {INT_SLP_SETTING_DRIVING_MSG_ALERT_VIB, NULL, eINT, {0}, export_default},
158 {INT_SLP_SETTING_MEETING_MSG_ALERT_VIB, NULL, eINT, {0}, export_default},
159 {INT_SLP_SETTING_OUTDOOR_MSG_ALERT_VIB, NULL, eINT, {0}, export_default},
162 {INT_SLP_SETTING_MSG_ALERT_REPEAT,VCONFKEY_SETAPPL_NOTI_MSG_ALERT_REP_TYPE_INT, eINT, {0}, export_default},
163 {INT_SLP_SETTING_EMAIL_ALERT_REPEAT,VCONFKEY_SETAPPL_NOTI_EMAIL_ALERT_REP_TYPE_INT, eINT, {0}, export_default},
166 {INT_SLP_SETTING_MSG_ALERT_VOLUME, NULL, eINT, {0}, export_default},
167 {INT_SLP_SETTING_SYS_TOUCH_SOUND, NULL, eINT, {0}, export_default},
168 {INT_SLP_SETTING_SYS_TOUCH_SOUND_VOLUME, NULL, eINT, {0}, export_default},
169 {INT_SLP_SETTING_FONT_SIZE,VCONFKEY_SETAPPL_FONT_SIZE_INT, eINT, {0}, export_default},
170 {INT_SLP_SETTING_FONT_TYPE,VCONFKEY_SETAPPL_FONT_TYPE_INT, eINT, {0}, export_default},
171 {INT_SLP_SETTING_LANG,VCONFKEY_SETAPPL_LANG_INT, eINT, {0}, export_default},
172 {INT_SLP_SETTING_BT_STATUS,VCONFKEY_BT_STATUS, eINT, {0}, export_default},
173 {INT_SLP_SETTING_WIFI_STATUS,VCONFKEY_WIFI_STATE, eINT, {0}, export_default},
174 {INT_SLP_SETTING_MOBILE_AP_STATUS,VCONFKEY_MOBILE_HOTSPOT_MODE, eINT, {0}, export_default},
175 {INT_SLP_SETTING_ROAMING_NETWORK,VCONFKEY_SETAPPL_ROAMING_NETWORK_INT, eINT, {0}, export_default},
176 {INT_SLP_SETTING_USB_MODE,VCONFKEY_SETAPPL_USB_MODE_INT, eINT, {0}, export_default},
177 #ifdef UNUSED_VCONFKEY
178 {INT_SLP_SETTING_TASKSWITCHER_VIEWTYPE,VCONFKEY_TASKSWITCHER_VIEWTYPE, eINT, {0}, export_default},
181 {INT_SLP_SETTING_DEFAULT_MEM_WAP,VCONFKEY_SETAPPL_DEFAULT_MEM_WAP_INT, eINT, {0}, export_default},
182 {INT_SLP_SETTING_DEFAULT_MEM_BLUETOOTH,VCONFKEY_SETAPPL_DEFAULT_MEM_BLUETOOTH_INT, eINT, {0}, export_default},
183 {INT_SLP_SETTING_DEFAULT_MEM_CAMERA,VCONFKEY_SETAPPL_DEFAULT_MEM_CAMERA_INT, eINT, {0}, export_default},
184 {INT_SLP_SETTING_DEFAULT_MEM_VOICE_RECORDER,VCONFKEY_SETAPPL_DEFAULT_MEM_VOICE_RECORDER_INT, eINT, {0}, export_default},
185 {INT_SLP_SETTING_DEFAULT_MEM_FM_RADIO,VCONFKEY_SETAPPL_DEFAULT_MEM_FM_RADIO_INT, eINT, {0}, export_default},
186 {INT_SLP_SETTING_DEFAULT_MEM_ALL_SHARE,VCONFKEY_SETAPPL_DEFAULT_MEM_ALL_SHARE_INT, eINT, {0}, export_default},
187 {INT_SLP_SETTING_DEFAULT_MEM_ADOBE_AIR,VCONFKEY_SETAPPL_DEFAULT_MEM_ADOBE_AIR_INT, eINT, {0}, export_default},
188 {INT_SLP_SETTING_DEFAULT_MEM_DVB_H,VCONFKEY_SETAPPL_DEFAULT_MEM_DVB_H_INT, eINT, {0}, export_default},
191 {INT_SLP_SETTING_SIM_SLOT,VCONFKEY_TELEPHONY_SIM_SLOT, eINT, {0}, export_default},
192 {INT_SLP_SETTING_PHONE_LOCK_ATTEMPTS_LEFT,VCONFKEY_SETAPPL_PHONE_LOCK_ATTEMPTS_LEFT_INT, eINT, {0}, export_default},
193 {INT_SLP_SETTING_SIM_LOCK_ATTEMPTS_LEFT,VCONFKEY_SETAPPL_SIM_LOCK_ATTEMPTS_LEFT_INT, eINT, {0}, export_default},
195 // accessibility setting
196 {INT_SLP_SETTING_ACCESSIBILITY_ENABLE_AUTO_ANSWER, VCONFKEY_CISSAPPL_ANSWERING_MODE_INT, eINT,{0}, export_default},
197 {INT_SLP_SETTING_ACCESSIBILITY_FONT_SIZE, VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, eINT, {0}, export_default},
198 #if SUPPORT_FONT_STYLE
199 {INT_SLP_SETTING_ACCESSIBILITY_FONT_STYLE,VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_STYLE, eINT, {0}, export_default},
201 {INT_SLP_SETTING_ACCESSIBILITY_AUTO_ANSWER, VCONFKEY_CISSAPPL_ANSWERING_MODE_TIME_INT, eINT, {0}, export_default},
202 {INT_SLP_SETTING_ACCESSIBILITY_POWER_KEY_HOLD, VCONFKEY_SETAPPL_ACCESSIBILITY_POWER_KEY_HOLD, eINT, {0}, export_default},
205 {INT_SLP_SETTING_POWERSAVING_AT, VCONFKEY_SETAPPL_PWRSV_CUSTMODE_AT, eINT, {0}, export_default},
206 {INT_SLP_SETTING_POWERSAVING_SCREEN_TIMEOUT, VCONFKEY_SETAPPL_PWRSV_CUSTMODE_BLTIME, eINT, {0}, export_default},
207 {INT_SLP_SETTING_DEVOPTION_BGPROCESS, VCONFKEY_SETAPPL_DEVOPTION_BGPROCESS, eINT, {0}, export_default},
209 {INT_SLP_SETTING_DATAUSAGE_DATA_EACH_MONTH_INT, VCONFKEY_SETAPPL_DATA_EACH_MONTH_INT, eINT, {0}, export_default},
210 {SETTING_INT_SLP_LIST_MAX, NULL, eINT, {0}, export_default},
214 /** string vconf table */
215 static VconfNode g_stable[] = {
216 /* password code - special processing */
217 { STR_SLP_LIST_PHONE_PASSWORD, NULL, eSTRING,{0}, export_default },
218 { STR_SLP_SETTING_PHONE_LOCK_TIMESTAMP,VCONFKEY_SETAPPL_PHONE_LOCK_TIMESTAMP_STR, eSTRING,{0}, export_default },
219 { STR_SLP_SETTING_SIM_LOCK_TIMESTAMP,VCONFKEY_SETAPPL_SIM_LOCK_TIMESTAMP_STR, eSTRING,{0}, export_default },
220 { STR_SLP_SETTING_SELECT_NUM,VCONFKEY_SETAPPL_SELECTED_NUM, eSTRING,{0}, export_default },
221 { STR_SLP_LIST_MAX, NULL, eSTRING, {0}, export_default},
224 void setting_export()
228 for (i=0;i<SETTING_BOOL_SLP_LIST_MAX;i++) {
229 SETTING_TRACE("exporting bool keys : %s ", g_btable[i].vconf_key );
230 // run export function --> store data into XML
231 g_btable[i].export(&g_btable[i]);
234 for (i=0;i<SETTING_INT_SLP_LIST_MAX;i++) {
235 SETTING_TRACE("exporting int keys : %s ", g_itable[i].vconf_key );
236 // run export function --> store data into XML
237 g_itable[i].export(&g_itable[i]);
240 for (i=0;i<STR_SLP_LIST_MAX;i++) {
241 SETTING_TRACE("exporting string keys : %s ", g_stable[i].vconf_key );
242 // run export function --> store data into XML
243 g_stable[i].export(&g_stable[i]);
247 int set_vconf(VconfNode node,VconfNode *result)
257 SETTING_TRACE("begin case eINT[%s=\"%d\"]", node.vconf_key, node.value.b);
258 ret = vconf_set_bool(node.vconf_key, node.value.b);
259 result->type = eBOOL;
260 result->value.b = node.value.b;
263 SETTING_TRACE("begin case eINT[%s=\"%d\"]", node.vconf_key, node.value.i);
264 ret = vconf_set_int(node.vconf_key, node.value.i);
266 result->value.i = node.value.i;
269 if (node.key == STR_SLP_LIST_PHONE_PASSWORD) {
270 ret = setting_store_init_password(node.value.c);
272 SETTING_TRACE("begin case eINT[%s=\"%s\"]", node.vconf_key, node.value.c);
273 ret = vconf_set_str(node.vconf_key, node.value.c);
275 result->type = eSTRING;
276 result->value.c = node.value.c;
279 SETTING_TRACE_ERROR(">>>>>>>>>> node.type is NOT DEFINED");
285 SETTING_TRACE_ERROR(">>>>>>>>>> Failed to set vconf");
287 //SETTING_TRACE("KEY:%d VCONF_KEY=%s TYPE=%d VALUE=%d ", result->key, result->vconf_key, result->type, result->value.i);
292 int get_vconf(VconfNode node, VconfNode* result)
296 char md_result[SHA256_DIGEST_LENGTH];
297 memset(md_result, 0x0, SHA256_DIGEST_LENGTH);
305 ret = vconf_get_bool(node.vconf_key, (int *)(&(node.value.b)));
306 result->type = eBOOL;
307 result->value.b = node.value.b;
310 ret = vconf_get_int(node.vconf_key, &(node.value.i));
312 result->value.i = node.value.i;
315 if (node.key == STR_SLP_LIST_PHONE_PASSWORD)
317 node.value.c = (char*)malloc(sizeof(char) * SHA256_DIGEST_LENGTH);
319 memset(node.value.c, 0x0, SHA256_DIGEST_LENGTH);
321 SETTING_TRACE_ERROR(" malloc filed : eSTRING, node.value.c ");
322 ret = SETTING_RETURN_FAIL;
326 if (setting_read_password(md_result) == 0) {
327 memcpy(node.value.c, md_result, SHA256_DIGEST_LENGTH); /* un-safe */
329 result->type = eSTRING;
330 result->value.c = node.value.c;
331 ret = SETTING_RETURN_SUCCESS;
334 ret = SETTING_RETURN_FAIL;
338 node.value.c = vconf_get_str(node.vconf_key);
339 SETTING_TRACE("string type ---> %s ", node.value.c);
340 result->type = eSTRING;
341 result->value.c = node.value.c;
342 ret = SETTING_RETURN_SUCCESS;
346 SETTING_TRACE_ERROR(">>>>>>>>>>>>>>>>>>>>>>> get vconf ERROR : %s ", node.vconf_key );
352 int setting_set_bool_slp_key(setting_bool_slp_list key, int value, int *err)
355 int ret = SETTING_RETURN_FAIL;
358 if (key < 0 || key >= SETTING_BOOL_SLP_LIST_MAX) {
359 *err = SETTING_GENERAL_ERR_WRONG_PARAMETER;
364 g_btable[key].value.b = value;
365 ret = set_vconf(g_btable[key],&result);
367 SETTING_TRACE("setting_set_bool ::: KEY:%d VCONF_KEY=%s TYPE=%d VALUE=%d ", result.key, result.vconf_key, result.type, result.value.b);
372 int setting_get_bool_slp_key(setting_bool_slp_list key, int *value, int *err)
375 int ret = SETTING_RETURN_FAIL;
378 if (key < 0 || key >= SETTING_BOOL_SLP_LIST_MAX) {
379 *err = SETTING_GENERAL_ERR_WRONG_PARAMETER;
380 SETTING_TRACE_ERROR(" <<<<<<<< key is invalid >>>>>>>>>>>>> ");
384 ret = get_vconf(g_btable[key], &result);
385 //*value = g_btable[key].value.b;
386 *value = result.value.b;
391 int setting_set_int_slp_key(setting_int_slp_list key, int value, int *err)
394 int ret = SETTING_RETURN_FAIL;
397 if (key < 0 || key >= SETTING_INT_SLP_LIST_MAX) {
398 *err = SETTING_GENERAL_ERR_WRONG_PARAMETER;
399 SETTING_TRACE(">>> key is invalid ");
404 g_itable[key].value.i = value;
405 ret = set_vconf(g_itable[key],&result);
407 SETTING_TRACE("setting_set_int ::: KEY:%d VCONF_KEY=%s TYPE=%d VALUE=%d ", result.key, result.vconf_key, result.type, result.value.i);
412 /* return -1: fail cannot use err to check the result, return value instead*/
413 int setting_get_int_slp_key(setting_int_slp_list key, int *value, int *err)
416 int ret = SETTING_RETURN_FAIL;
419 if (key < 0 || key >= SETTING_INT_SLP_LIST_MAX) {
420 *err = SETTING_GENERAL_ERR_WRONG_PARAMETER;
425 ret = get_vconf(g_itable[key], &result);
426 //*value = g_itable[key].value.i;
427 *value = result.value.i;
434 int setting_get_string_slp_key(setting_str_slp_list key, char *value, int *err)
437 int ret = SETTING_RETURN_FAIL;
440 if (key < 0 || key >= STR_SLP_LIST_MAX || NULL == value) {
441 *err = SETTING_GENERAL_ERR_WRONG_PARAMETER;
445 /** @todo check memory leack when passwork checking */
447 ret = get_vconf(g_stable[key], &result);
451 safeCopyStr(value, result.value.c, strlen(result.value.c));
452 SETTING_TRACE(">>>>>>>> %s <<<<<<<<", value);
453 FREE(result.value.c);
455 SETTING_TRACE("get_vconf is failed");
462 int setting_set_string_slp_key(setting_str_slp_list key, char *value, int *err)
464 int ret = SETTING_RETURN_FAIL;
467 if (key < 0 || key >= STR_SLP_LIST_MAX) {
468 *err = SETTING_GENERAL_ERR_WRONG_PARAMETER;
473 g_stable[key].value.c = value;
474 ret = set_vconf(g_stable[key], &result);
475 g_stable[key].value.c = "";
477 SETTING_TRACE("setting_set_str ::: KEY:%d VCONF_KEY=%s TYPE=%d VALUE=%d ", result.key, result.vconf_key, result.type, result.value.c);
482 /** @todo don't use i18n string directly. */
483 static const setting_lang_entry lang_table[] = {
484 { "auto", "Automatic"},
485 { "ko_KR.UTF-8", "한국어"},
486 { "en_US.UTF-8", "English"},
487 { "zh_CN.UTF-8", "简体中文"},
488 { "zh_HK.UTF-8", "繁體中文(香港)"},
489 { "zh_TW.UTF-8", "繁體中文(台灣)"},
490 { "de_DE.UTF-8", "Deutsch"},
491 { "nl_NL.UTF-8", "Nederlands"},
492 { "es_ES.UTF-8", "Español"},
493 { "pt_PT.UTF-8", "Português"},
494 { "el_GR.UTF-8", "Eλληνικά"},
495 { "it_IT.UTF-8", "Italiano"},
496 { "fr_FR.UTF-8", "Français"},
497 { "tr_TR.UTF-8", "Türkçe"},
498 { "ja_JP.UTF-8", "にほんご"},
499 { "ru_RU.UTF-8", "Россию"},
502 setting_lang_entry* setting_get_language_table()
504 return (setting_lang_entry*)lang_table;
508 #define LANGLIST_FILE_DIR_PATH "/opt/data/setting/"
509 #define LANGLIST_FILE_PATH LANGLIST_FILE_DIR_PATH"langlist.xml"
511 static void _parseLangListXML(char* docname); // internal
512 static void __tree_walk_langlist(xmlNodePtr cur); // internal
514 static Eina_List* s_langlist; // internal
523 _parseLangListXML(LANGLIST_FILE_PATH);
530 Eina_List* setting_get_language_list()
532 if (NULL == s_langlist)
540 int _langlist_destroy()
543 Eina_List *li = s_langlist;
544 setting_lang_entry* node;
546 node = (setting_lang_entry*) eina_list_data_get(li);
549 SETTING_TRACE("destroy nodes : locale : %s title : %s", node->locale, node->title);
550 G_FREE(node->locale);
554 li = eina_list_next(li);
556 s_langlist = eina_list_free(s_langlist); // returns NULL
561 void setting_get_language_list_destroy()
566 static void _parseLangListXML(char* docname)
572 doc = xmlParseFile(docname);
575 fprintf(stderr,"Document not parsed successfully. \n");
579 cur = xmlDocGetRootElement(doc);
581 fprintf(stderr,"empty document\n");
586 printf("ROOT NODE : %s \n", cur->name);
587 // make sure root node is "settings"
588 if (xmlStrcmp(cur->name, (const xmlChar *) "langlist")) {
589 SETTING_TRACE("document of the wrong type, root node != settings");
594 cur = cur->xmlChildrenNode;
595 __tree_walk_langlist(cur);
597 /* save tree to file */
599 //xmlSaveFormatFile (docname, doc, 1);
606 static void __tree_walk_langlist(xmlNodePtr cur)
609 xmlNode *cur_node = NULL;
614 for (cur_node = cur; cur_node;cur_node = cur_node->next) {
615 if (cur_node->type == XML_ELEMENT_NODE) {
617 SETTING_TRACE(" name=%s title=%s number=%s \n", xmlGetProp(cur_node, (const xmlChar *)"id"), xmlGetProp(cur_node, (const xmlChar *)"string"), xmlGetProp(cur_node, (const xmlChar *)"no"));
618 id = (char *)g_strdup((char*)xmlGetProp(cur_node, (const xmlChar *)"id"));
619 string = (char *)g_strdup((char*) xmlGetProp(cur_node, (const xmlChar *)"string"));
620 number = atoi((char*) xmlGetProp(cur_node, (const xmlChar *)"no"));
621 SETTING_TRACE(">>>> locale: %s title: %s", (char*)id, (char*)string);
623 setting_lang_entry* pitem = (setting_lang_entry*)calloc(1, sizeof(setting_lang_entry));
625 pitem->title = string;
626 pitem->number = number;
628 s_langlist = eina_list_append(s_langlist, pitem);
632 //-----------------------------------------------------------------------------------------------
633 //-----------------------------------------------------------------------------------------------
635 //setting_lang_entry*
637 //////////////////////////////////////////////////////////////////////////////////////////
638 int setting_store_init_password(char *in)
642 char md[SHA256_DIGEST_LENGTH] = {0,};
644 int ret = SETTING_RETURN_FAIL;
646 SHA256_Init(&context);
647 SHA256_Update(&context, (char *)in, strlen(in));
648 SHA256_Final((unsigned char *)md, &context);
651 SETTING_TRACE("input: [%s]\n", in);
652 SETTING_TRACE("output: [");
653 for (i = 0; i < SHA256_DIGEST_LENGTH; i++)
654 SETTING_TRACE("%02x", md[i]);
655 SETTING_TRACE("]\n");
658 /* create a file or store a data */
662 fp = fopen(PWD_FILE, "w+");
664 ret_fw = fwrite(md, 1, SHA256_DIGEST_LENGTH, fp);
665 SETTING_TRACE_DEBUG("fwrite() wrote %d chars.", ret_fw);
666 if(ret_fw == SHA256_DIGEST_LENGTH)
670 ret = SETTING_RETURN_SUCCESS;
674 SETTING_TRACE("ERR: pwd file is not exist \n");
680 int setting_read_password(char *md_result)
685 fp = fopen(PWD_FILE, "r");
687 int size = fread(md_result, sizeof(char), SHA256_DIGEST_LENGTH, fp);
688 if (size != SHA256_DIGEST_LENGTH) {
689 SETTING_TRACE_ERROR("fread failed");
693 SETTING_TRACE("ERR: pwd file is not exist \n");
694 return SETTING_RETURN_FAIL;
698 SETTING_TRACE("output from file: [");
699 for (i = 0; i < SHA256_DIGEST_LENGTH; i++)
700 SETTING_TRACE("%02x", md_result[i]);
701 SETTING_TRACE("]\n");
707 int setting_compare_password(char *md_result, const char *in_later)
710 SHA256_CTX context_later;
711 char md_later[SHA256_DIGEST_LENGTH];
712 int ret = SETTING_RETURN_FAIL;
714 SHA256_Init(&context_later);
715 SHA256_Update(&context_later, (char *)in_later, strlen(in_later));
716 SHA256_Final((unsigned char *)md_later, &context_later);
718 SETTING_TRACE(" :[ %25s ]", in_later);
720 if (0 == memcmp(md_later, md_result, SHA256_DIGEST_LENGTH)) {
721 SETTING_TRACE("two passwords are same \n");
724 SETTING_TRACE("two passwords are different \n");
729 void setting_destory_listen_list(Eina_List **listened_list)
731 if (listened_list && *listened_list)
733 Vconf_Change_Node *node = NULL;
734 Eina_List *li = *listened_list;
736 node = (Vconf_Change_Node *) eina_list_data_get(li);
739 SETTING_TRACE("Deregister callback[%p] of %s", node->cb, node->in_key);
740 if (node->in_key && node->cb) {
741 (void)vconf_ignore_key_changed(node->in_key, node->cb);
745 li = eina_list_next(li);
747 *listened_list = eina_list_free(*listened_list);
751 bool setting_add_listen_node(Eina_List **listened_list,const char *vconf, vconf_callback_fn cb, void *data)
753 Vconf_Change_Node *node = calloc(1, sizeof(Vconf_Change_Node));
755 if (node && vconf && cb)
757 node->in_key = vconf;
759 node->cb_data = data;
761 if(0 == vconf_notify_key_changed(vconf, cb, data))
763 SETTING_TRACE("Register callback[%p] of %s", node->cb, node->in_key);
764 *listened_list = eina_list_append(*listened_list, node);
768 SETTING_TRACE_ERROR("Failed to register callback[%p] of %s", node->cb, node->in_key);