tizen 2.4 release
[apps/home/settings.git] / setting-common / src / setting-common-data-slp-setting.c
1 /*
2  * setting
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd.
5  *
6  * Contact: MyoungJune Park <mj2004.park@samsung.com>
7  *
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
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
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.
19  *
20  */
21 #include <setting-common-data-slp-setting.h>
22 #include <Elementary.h>
23 #include <stdio.h>
24 #include <string.h>
25 #include <openssl/sha.h>
26
27 #include <sys/types.h>
28 #include <sys/stat.h>
29 #include <fcntl.h>
30
31 #include <stdlib.h>
32 #include <libxml/xmlmemory.h>
33 #include <libxml/parser.h>
34 #include <libxml/tree.h>
35 #include <glib.h>
36
37 #include <glib.h>
38 #include <json-glib/json-glib.h>
39
40 #define SETTING_DATA_DIR_PATH "/opt/apps/org.tizen.setting/data/"
41 #define SETTING_CFG_JSON_FILE_PATH      SETTING_DATA_DIR_PATH"exported.json"
42 #define EXPORT_FILE             SETTING_DATA_DIR_PATH"setting_export.xml"
43
44
45 typedef enum {
46     eBOOL,
47     eINT,
48     eSTRING,
49 } vconftype;
50
51 typedef union {
52         int i;
53         bool b;
54         char *c;
55 } vconfval;
56
57
58 typedef struct VconfNode VconfNode;
59 struct VconfNode {
60         const char *public_key;                                 /** key for importing & exporting */
61         const char *public_groupkey;                    /** category for importing & exporting */
62         /*------------------------------------------------------------------------------------- */
63         int key;                                                                /** vconf id definded in Setting app */
64         const char *vconf_key;                                  /** vconf string defined in libslp-setting */
65         vconftype type;                                                 /** BOOL, INT, STRING */
66         vconfval value;                                                 /** variable by union */
67         void (*export)(VconfNode *pnode, void *data);           /** method for exporting current state */
68         void (*import)(VconfNode *pnode, void *data);           /** method for importing state from cloud */
69 };
70
71 int get_vconf(VconfNode node, VconfNode *result);
72 int set_vconf(VconfNode node, VconfNode *result);
73
74 static VconfNode *g_sortedarr;
75
76 /* export function for each vconf key */
77 EXPORT_PUBLIC
78 void export_default(VconfNode *node, void *root)
79 {
80
81         xmlNodePtr *root_node = (xmlNodePtr *)root;
82
83         if (node) {
84                 char *val = NULL;
85                 char *type = NULL;
86
87                 char arr[1024];
88                 if (node->vconf_key == NULL) return; /* NO DOTHING IF null */
89                 VconfNode result;
90                 switch (node->type) {
91                         case eBOOL:
92                                 SETTING_TRACE("EXPORTING key : %s : %d : %d", node->vconf_key, node->type, node->value.b);
93                                 /* call vconf_get */
94
95                                 get_vconf(*node, &result);
96
97                                 val = "boolval";
98                                 type = "bool";
99                                 if (result.value.b)
100                                         val = "true";
101                                 else
102                                         val = "false";
103
104                                 break;
105                         case eINT:
106                                 SETTING_TRACE("EXPORTING key : %s : %d : %d", node->vconf_key, node->type, node->value.i);
107                                 /* call vconf_get */
108                                 get_vconf(*node, &result);
109                                 type = "int";
110
111                                 SETTING_TRACE(">>(%d)<<", result.value.i);
112                                 sprintf(arr, "%d", result.value.i);
113                                 /*node->value.i */
114                                 val = arr;
115                                 break;
116                         case eSTRING:
117                                 SETTING_TRACE("EXPORTING key : %s : %d : %s", node->vconf_key, node->type, node->value.c);
118                                 /* call vconf_get */
119                                 get_vconf(*node, &result);
120                                 val = result.value.c;
121                                 type = "string";
122                                 break;
123                 }
124
125                 xmlNodePtr xmlnode = xmlNewChild(*root_node, NULL, BAD_CAST "config", BAD_CAST val);
126                 xmlNewProp(xmlnode, BAD_CAST "key", BAD_CAST node->vconf_key);
127                 xmlNewProp(xmlnode, BAD_CAST "type", BAD_CAST type);
128                 xmlAddChild(*root_node, xmlnode);
129         }
130 }
131
132 /*----------------------------------------------------------------------------------------------- */
133
134 /* export function for each vconf key */
135 EXPORT_PUBLIC
136 void export_json(VconfNode *node, void *root)
137 {
138         JsonArray *array = (JsonArray *)root;
139
140         if (node) {
141                 char *val = NULL;
142                 /*char *type = NULL; */
143
144                 char arr[1024];
145                 if (node->vconf_key == NULL) return; /* NO DOTHING IF null */
146                 VconfNode result;
147                 switch (node->type) {
148                         case eBOOL:
149                                 SETTING_TRACE("EXPORTING key : %s : %d : %d", node->vconf_key, node->type, node->value.b);
150                                 /* call vconf_get */
151
152                                 get_vconf(*node, &result);
153
154                                 val = "boolval";
155                                 /*type = "bool"; */
156                                 if (result.value.b)
157                                         val = "true";
158                                 else
159                                         val = "false";
160
161                                 break;
162                         case eINT:
163                                 SETTING_TRACE("EXPORTING key : %s : %d : %d", node->vconf_key, node->type, node->value.i);
164                                 /* call vconf_get */
165                                 get_vconf(*node, &result);
166                                 /*type = "int"; */
167
168                                 SETTING_TRACE(">>(%d)<<", result.value.i);
169                                 sprintf(arr, "%d", result.value.i);
170                                 /*node->value.i */
171                                 val = arr;
172                                 break;
173                         case eSTRING:
174                                 SETTING_TRACE("EXPORTING key : %s : %d : %s", node->vconf_key, node->type, node->value.c);
175                                 /* call vconf_get */
176                                 get_vconf(*node, &result);
177                                 val = result.value.c;
178                                 /*type = "string"; */
179                                 break;
180                 }
181
182                 JsonNode *item = json_node_new(JSON_NODE_OBJECT);
183                 JsonObject *obj = json_object_new();
184
185                 json_node_take_object(item, obj);
186                 json_object_set_string_member(obj, "key", node->public_key);
187                 json_object_set_string_member(obj, "value", val);
188                 json_array_add_element(array, item);
189         }
190 }
191
192 /* /opt/usr/data/setting/aaa.xml */
193 /* import function for each vconf key */
194 EXPORT_PUBLIC
195 void import_default(VconfNode *node, void *data)
196 {
197         /*xmlNodePtr* root_node =(xmlNodePtr*)data; */
198
199         switch (node->type) {
200                 case eBOOL:
201                         SETTING_TRACE("IMPORTING key : %s : %d : %d", node->vconf_key, node->type, node->value);
202                         break;
203                 case eINT:
204                         SETTING_TRACE("IMPORTING key : %s : %d : %d", node->vconf_key, node->type, node->value);
205                         break;
206                 case eSTRING:
207                         SETTING_TRACE("IMPORTING key : %s : %d : %s", node->vconf_key, node->type, node->value);
208                         break;
209         }
210 }
211
212 /** bool vconf table */
213 static VconfNode g_btable[] = {
214
215         {"power_on_lock", "security", BOOL_SLP_SETTING_POWER_ON_LOCK, VCONFKEY_SETAPPL_STATE_POWER_ON_LOCK_BOOL, eBOOL, {0}, export_json, import_default}, /* node[0] */
216         {"simple_password", "security", BOOL_SLP_SETTING_SIMPLE_PASSWORD, VCONFKEY_SETAPPL_STATE_SIMPLE_PASSWORD_BOOL, eBOOL, {0}, export_json, import_default}, /* node[0] */
217
218         {"automatic_time", "datetime", BOOL_SLP_SETTING_AUTOMATIC_TIME_UPDATE, VCONFKEY_SETAPPL_STATE_AUTOMATIC_TIME_UPDATE_BOOL, eBOOL, {0}, export_json, import_default},
219
220         {"filight_mode", "connectivity", BOOL_SLP_SETTING_FLIGHT_MODE, VCONFKEY_TELEPHONY_FLIGHT_MODE, eBOOL, {0}, export_json, import_default},
221         {"net_restriction_mode", "connectivity", BOOL_SLP_SETTING_NET_RESTRICTION_MODE, VCONFKEY_SETAPPL_NETWORK_RESTRICT_MODE, eBOOL, {0}, export_json, import_default},
222         {"data_roaming", "connectivity", BOOL_SLP_SETTING_DATA_ROAMING, VCONFKEY_SETAPPL_STATE_DATA_ROAMING_BOOL, eBOOL, {0}, export_json, import_default},
223         {"nfc_mode", "connectivity", BOOL_SLP_SETTING_NFC_STATUS, VCONFKEY_NFC_STATE, eBOOL, {0}, export_json, import_default},
224
225         {"use_packetdata", "connectivity", BOOL_SLP_SETTING_USE_PACKET_DATA, VCONFKEY_3G_ENABLE, eBOOL, {0}, export_json, import_default},
226         {"high_contract", "accessibility", BOOL_SLP_SETTING_ACCESSIBILITY_HIGH_CONTRAST, VCONFKEY_SETAPPL_ACCESSIBILITY_HIGH_CONTRAST, eBOOL, {0}, export_json, import_default},
227         {"screen_zoom", "accessibility", BOOL_SLP_SETTING_ACCESSIBILITY_SCREEN_ZOOM, VCONFKEY_SETAPPL_ACCESSIBILITY_SCREEN_ZOOM, eBOOL, {0}, export_json, import_default},
228         {"assistive_light", "accessibility", BOOL_SLP_SETTING_ACCESSIBILITY_ASSISTIVE_LIGHT, VCONFKEY_SETAPPL_ACCESSIBILITY_TORCH_LIGHT, eBOOL, {0}, export_json, import_default},
229         {"mono_audio", "accessibility", BOOL_SLP_SETTING_ACCESSIBILITY_MONO_AUDIO, VCONFKEY_SETAPPL_ACCESSIBILITY_MONO_AUDIO, eBOOL, {0}, export_json, import_default},
230         {"turn_off_all_sounds", "accessibility", BOOL_SLP_SETTING_ACCESSIBILITY_TURN_OFF_ALL_SOUNDS, VCONFKEY_SETAPPL_ACCESSIBILITY_TURN_OFF_ALL_SOUNDS, eBOOL, {0}, export_json, import_default},
231         {"led_notify", "accessibility", BOOL_SLP_SETTING_ACCESSIBILITY_LED_NOTIFY, VCONFKEY_SETAPPL_ACCESSIBILITY_LED_NOTIFY, eBOOL, {0}, export_json, import_default},
232         {"accept_call", "accessibility", BOOL_SLP_SETTING_ACCESSIBILITY_ACCEPT_CALL, VCONFKEY_CISSAPPL_ANSWERING_KEY_BOOL, eBOOL, {0}, export_json, import_default},
233         {"powerkey_end_calls", "accessibility", BOOL_SLP_SETTING_ACCESSIBILITY_POWERKEY_END_CALLS, VCONFKEY_CISSAPPL_POWER_KEY_ENDS_CALL_BOOL, eBOOL, {0}, export_json, import_default},
234         {"easy_touch_mode", "accessibility", BOOL_SLP_SETTING_ACCESSIBILITY_EASY_TOUCH_MODE, VCONFKEY_SETAPPL_EASY_TOUCH_MODE_BOOL, eBOOL, {0}, export_json, import_default},
235         {"rapid_key_input", "accessibility", BOOL_SLP_SETTING_ACCESSIBILITY_RAPID_KEY_INPUT, VCONFKEY_SETAPPL_ACCESSIBILITY_RAPID_KEY_INPUT, eBOOL, {0}, export_json, import_default},
236
237         /*datausage */
238         {"data_usage_limit_bool", "datausage", BOOL_SLP_SETTING_DATAUSAGE_SET_DATA_USAGE_LIMIT_BOOL, VCONFKEY_SETAPPL_SET_DATA_USAGE_LIMIT_BOOL, eBOOL, {0}, export_json, import_default},
239         {"data_usage_limit_roaming_bool", "datausage", BOOL_SLP_SETTING_DATAUSAGE_SET_DATA_USAGE_LIMIT_ROAMING_BOOL, VCONFKEY_SETAPPL_SET_DATA_USAGE_LIMIT_ROAMING_BOOL, eBOOL, {0}, export_json, import_default},
240
241         /* motion */
242         {"motion_activation", "motion", BOOL_SLP_SETTING_MOTION_ACTIVATION, VCONFKEY_SETAPPL_MOTION_ACTIVATION, eBOOL, {0}, export_json, import_default},
243         {"use_pick_up_call", "motion", BOOL_SLP_SETTING_MOTION_USE_PICK_UP_CALL, VCONFKEY_SETAPPL_USE_PICK_UP_CALL, eBOOL, {0}, export_json, import_default},
244         {"use_pick_up", "motion", BOOL_SLP_SETTING_MOTION_USE_PICK_UP, VCONFKEY_SETAPPL_USE_PICK_UP, eBOOL, {0}, export_json, import_default},
245         {"use_double_tap", "motion", BOOL_SLP_SETTING_MOTION_USE_DOUBLE_TAP, VCONFKEY_SETAPPL_USE_DOUBLE_TAP, eBOOL, {0}, export_json, import_default},
246         {"use_tilt", "motion", BOOL_SLP_SETTING_MOTION_USE_TILT, VCONFKEY_SETAPPL_USE_TILT, eBOOL, {0}, export_json, import_default},
247         {"use_panning", "motion", BOOL_SLP_SETTING_MOTION_USE_PANNING, VCONFKEY_SETAPPL_USE_PANNING, eBOOL, {0}, export_json, import_default},
248         {"use_panning_browser", "motion", BOOL_SLP_SETTING_MOTION_USE_PANNING_BROWSER, VCONFKEY_SETAPPL_USE_PANNING_BROWSER, eBOOL, {0}, export_json, import_default},
249         {"use_shake", "motion", BOOL_SLP_SETTING_MOTION_USE_SHAKE, VCONFKEY_SETAPPL_USE_SHAKE, eBOOL, {0}, export_json, import_default},
250         {"use_turn_over", "motion", BOOL_SLP_SETTING_MOTION_USE_TURN_OVER, VCONFKEY_SETAPPL_USE_TURN_OVER, eBOOL, {0}, export_json, import_default},
251         {"tab_twist", "motion", BOOL_SLP_SETTING_MOTION_TAP_TWIST, VCONFKEY_SETAPPL_TAP_TWIST, eBOOL, {0}, export_json, import_default},
252         {"use_mute_pause", "motion", BOOL_SLP_SETTING_MOTION_USE_MUTE_PAUSE, VCONFKEY_SETAPPL_USE_MUTE_PAUSE, eBOOL, {0}, export_json, import_default},
253         /*---- */
254         {NULL, "groupname", SETTING_BOOL_SLP_LIST_MAX, NULL, eBOOL, {0}, export_json, import_default},
255 };
256
257
258 /** int vconf table */
259 static VconfNode g_itable[] = {
260         {"lcd_brightness", "display", INT_SLP_SETTING_LCD_BRIGHTNESS, VCONFKEY_SETAPPL_LCD_BRIGHTNESS, eINT, {0}, export_json, import_default},
261         {"lcd_timeout_normal", "display", INT_SLP_SETTING_LCD_TIMEOUT_NORMAL, VCONFKEY_SETAPPL_LCD_TIMEOUT_NORMAL, eINT, {0}, export_json, import_default},
262         {"lcd_timeout_normal_backup", "display", INT_SLP_SETTING_LCD_TIMEOUT_NORMAL_BACKUP, VCONFKEY_LCD_TIMEOUT_NORMAL_BACKUP, eINT, {0}, export_json, import_default},
263
264         {"automatic_brightness", "display", INT_SLP_SETTING_AUTOMATIC_BRIGHTNESS, VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, eINT, {0}, export_json, import_default},
265
266         {"select_network", "network", INT_SLP_SETTING_SELECT_NETWORK, VCONFKEY_SETAPPL_SELECT_NETWORK_INT, eINT, {0}, export_json, import_default},
267         {"network_mode", "network", INT_SLP_SETTING_NETWORK_MODE, VCONFKEY_SETAPPL_NETWORK_MODE_INT, eINT, {0}, export_json, import_default},
268         {"regionformat_time1224", "datetime", INT_SLP_SETTING_REGIONFORMAT_TIME1224, VCONFKEY_REGIONFORMAT_TIME1224, eINT, {0}, export_json, import_default},
269         {"dateformat", "datetime", INT_SLP_SETTING_DATE_FORMAT, VCONFKEY_SETAPPL_DATE_FORMAT_INT, eINT, {0}, export_json, import_default},
270         {"weekformat", "datetime", INT_SLP_SETTING_WEEK_FORMAT, VCONFKEY_SETAPPL_WEEKOFDAY_FORMAT_INT, eINT, {0}, export_json, import_default},
271
272         /* CALL_ALERT_VIB */
273         {"call_alert_vib", "sound", INT_SLP_SETTING_CALL_ALERT_VIB, VCONFKEY_SETAPPL_CALL_VIBRATION_PATTERN_INT, eINT, {0}, export_json, import_default},
274
275         /*****/
276         {"msg_alert_repeat", "sound", INT_SLP_SETTING_MSG_ALERT_REPEAT, VCONFKEY_SETAPPL_NOTI_MSG_ALERT_REP_TYPE_INT, eINT, {0}, export_json, import_default},
277
278         /*****/
279         {"language_index", "display", INT_SLP_SETTING_LANG, VCONFKEY_SETAPPL_LANG_INT, eINT, {0}, export_json, import_default},
280         {"bluetooth_switch", "connectivity", INT_SLP_SETTING_BT_STATUS, VCONFKEY_BT_STATUS, eINT, {0}, export_json, import_default},
281         {"wifi_state", "connectivity", INT_SLP_SETTING_WIFI_STATUS, VCONFKEY_WIFI_STATE, eINT, {0}, export_json, import_default},
282         {"mobile_hotspot_mode", "connectivity", INT_SLP_SETTING_MOBILE_AP_STATUS, VCONFKEY_MOBILE_HOTSPOT_MODE, eINT, {0}, export_json, import_default},
283         {"roaming_network", "connectivity", INT_SLP_SETTING_ROAMING_NETWORK, VCONFKEY_SETAPPL_ROAMING_NETWORK_INT, eINT, {0}, export_json, import_default},
284         {"usb_mode", "connectivity", INT_SLP_SETTING_USB_MODE, VCONFKEY_SETAPPL_USB_MODE_INT, eINT, {0}, export_json, import_default},
285
286         /* memory */
287         {"mem_bluetooth", "memory", INT_SLP_SETTING_DEFAULT_MEM_BLUETOOTH, VCONFKEY_SETAPPL_DEFAULT_MEM_BLUETOOTH_INT, eINT, {0}, export_json, import_default},
288         {"mem_wifidirect", "memory", INT_SLP_SETTING_DEFAULT_MEM_WIFIDIRECT, VCONFKEY_SETAPPL_DEFAULT_MEM_WIFI_DIRECT_INT, eINT, {0}, export_json, import_default},
289         {"mem_installapplications", "memory", INT_SLP_SETTING_DEFAULT_MEM_INSTALLAPPLICATIONS, VCONFKEY_SETAPPL_DEFAULT_MEM_INSTALL_APPLICATIONS_INT, eINT, {0}, export_json, import_default},
290
291         /* other module */
292         {"sim_slot", "security", INT_SLP_SETTING_SIM_SLOT, VCONFKEY_TELEPHONY_SIM_SLOT, eINT, {0}, export_json, import_default},
293         {"phone_lock_attempt", "security", INT_SLP_SETTING_PHONE_LOCK_ATTEMPTS_LEFT, VCONFKEY_SETAPPL_PHONE_LOCK_ATTEMPTS_LEFT_INT, eINT, {0}, export_json, import_default},
294         {"sime_lock_attempt", "security", INT_SLP_SETTING_SIM_LOCK_ATTEMPTS_LEFT, VCONFKEY_SETAPPL_SIM_LOCK_ATTEMPTS_LEFT_INT, eINT, {0}, export_json, import_default},
295
296         /* accessibility setting */
297         {"font_size", "accessibility", INT_SLP_SETTING_ACCESSIBILITY_FONT_SIZE, VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, eINT, {0}, export_json, import_default},
298 #if SUPPORT_FONT_STYLE
299         {"font_style", "accessibility", INT_SLP_SETTING_ACCESSIBILITY_FONT_STYLE, VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_STYLE, eINT, {0}, export_json, import_default},
300 #endif
301         {"sound_balance", "accessibility", INT_SLP_SETTING_ACCESSIBILITY_SOUND_BALANCE, VCONFKEY_SETAPPL_SOUND_BALANCE_INT, eINT, {0}, export_json, import_default},
302
303         /*powersaving */
304         {"bgprocess", "developeroptions", INT_SLP_SETTING_DEVOPTION_BGPROCESS, VCONFKEY_SETAPPL_DEVOPTION_BGPROCESS, eINT, {0}, export_json, import_default},
305
306         /* data usage */
307         {"usage_cycle", "datausage", INT_SLP_SETTING_DATAUSAGE_DATA_USAGE_CYCLE_INT, VCONFKEY_SETAPPL_DATA_USAGE_CYCLE_INT, eINT, {0}, export_json, import_default},
308         {"each_month", "datausage", INT_SLP_SETTING_DATAUSAGE_DATA_EACH_MONTH_INT, VCONFKEY_SETAPPL_DATA_EACH_MONTH_INT, eINT, {0}, export_json, import_default},
309         {"each_month_app", "datausage", INT_SLP_SETTING_DATAUSAGE_DATA_EACH_MONTH_APP_INT, VCONFKEY_SETAPPL_DATA_EACH_MONTH_APP_INT, eINT, {0}, export_json, import_default},
310
311         /* accessories */
312         {"display/touchkey_light_duration", "display", INT_SLP_SETTING_TOUCHKEY_LIGHT_DURATION_INT, VCONFKEY_SETAPPL_TOUCHKEY_LIGHT_DURATION, eINT, {0}, export_json, import_default},
313         {"display/screen_capture_destination", "display", INT_SLP_SETTING_SCREEN_CAPTURE_DESTINATION_INT, VCONFKEY_SETAPPL_SCREEN_CAPTURE_DESTINATION, eINT, {0}, export_json, import_default},
314         /*---- */
315         {NULL, "groupkey", SETTING_INT_SLP_LIST_MAX, NULL, eINT, {0}, export_json, import_default},
316
317 };
318
319
320 /** string vconf table */
321 static VconfNode g_stable[] = {
322         /* password code - special processing */
323         {"phone_password", "security",  STR_SLP_LIST_PHONE_PASSWORD, NULL, eSTRING, {0}, export_json, import_default },
324         {"phonelock_timestamp", "security",     STR_SLP_SETTING_PHONE_LOCK_TIMESTAMP, VCONFKEY_SETAPPL_PHONE_LOCK_TIMESTAMP_STR, eSTRING, {0}, export_json, import_default },
325         {"simlock_timestamp", "security",       STR_SLP_SETTING_SIM_LOCK_TIMESTAMP, VCONFKEY_SETAPPL_SIM_LOCK_TIMESTAMP_STR, eSTRING, {0}, export_json, import_default },
326         {"selected_phonenum", "about",  STR_SLP_SETTING_SELECT_NUM, VCONFKEY_SETAPPL_SELECTED_NUM, eSTRING, {0}, export_json, import_default },
327         /*---- */
328         {NULL, "groupkey",      STR_SLP_LIST_MAX, NULL, eSTRING, {0}, export_json, import_default},
329 };
330
331
332 /**
333  * import
334  */
335 int sync_adapter_restore_set_data(void *data, unsigned long long size)
336 {
337
338         /*if(size <=  0) */
339         /*      SETTING_TRACE("error"); */
340
341         /*SETTING_TRACE("%s: data is %s", __func__, (char *)data); */
342         /*SETTING_TRACE("%s: size is %lld", __func__, size); */
343         return 0;
344 }
345
346
347
348 static int getconfsize()
349 {
350         /*---- */
351         int bcount = sizeof(g_btable) / sizeof(g_btable[0]) - 1;
352         int icount = sizeof(g_itable) / sizeof(g_itable[0]) - 1;
353         int scount = sizeof(g_stable) / sizeof(g_stable[0]) - 1; /* why?? buggy */
354         int total = bcount + icount + scount;
355
356         return total;
357 }
358
359 /**
360  * leaf node
361  *
362  * g_sortedarr from caller
363  */
364 void __foreach_attr(JsonObject *object, const gchar *public_key, JsonNode *member_node, gpointer user_data)
365 {
366         char *public_groupname = (char *)user_data;
367         char *retstr = (char *)json_object_get_string_member(object, public_key);
368
369         /*SETTING_TRACE(" public_groupname : %s", public_groupname); */
370
371         /* LOOKUP(group, key) ----> vconf_key */
372         int total = getconfsize();
373
374         int i;
375         static int ncount = 0;
376         int run = 1;
377         for (i = 0; i < total && run == 1; i++) {
378                 /*SETTING_TRACE(" >> g_sortedarr[%d].public_groupkey : %s",i, g_sortedarr[i].public_groupkey ); */
379                 /*SETTING_TRACE(" >> g_sortedarr[%d].public_key : %s",i, g_sortedarr[i].public_key ); */
380                 /*SETTING_TRACE(" >> public_key : %s",public_key ); */
381
382                 if (g_sortedarr[i].public_groupkey &&
383                     safeStrCmp(g_sortedarr[i].public_groupkey, public_groupname) == 0 &&
384                     g_sortedarr[i].public_key &&
385                     safeStrCmp(g_sortedarr[i].public_key, public_key) == 0) {
386                         ncount += 1;
387                         SETTING_TRACE(" FOUND ---> group name %s : public key %s --- vconf key (%s) - type (%d) -- strval : [%s] ", g_sortedarr[i].public_groupkey, g_sortedarr[i].public_key, g_sortedarr[i].vconf_key, g_sortedarr[i].type, retstr);
388
389                         /* set value from vconf (key/value) */
390                         /* retstr */
391                         VconfNode result;
392                         switch (g_sortedarr[i].type) {
393                                 case eBOOL:
394                                         /* "true"  --> 1  "false" --> 0 */
395                                         if (retstr && safeStrCmp(retstr, "true") == 0) {
396                                                 g_sortedarr[i].value.b = 1;
397                                         }       else if (retstr && safeStrCmp(retstr, "false") == 0) {
398                                                 g_sortedarr[i].value.b = 0;
399                                         }
400                                         break;
401
402                                 case eINT: {
403                                                 int num = -1;
404                                                 /* "111" --> 1111 */
405                                                 if (retstr)
406                                                         num = atoi(retstr);
407                                                 g_sortedarr[i].value.i = num;
408                                         }
409                                         break;
410
411                                 case eSTRING:
412                                         /* "hello world"  --> "hello world" */
413                                         if (retstr)
414                                                 g_sortedarr[i].value.c = retstr;
415                                         else
416                                                 g_sortedarr[i].value.c = "";    /* error handler */
417                                         break;
418
419                         }
420
421                         if (g_sortedarr[i].vconf_key)
422                                 set_vconf(g_sortedarr[i], &result);
423                         else {
424                                 SETTING_TRACE("vconf key is NULL");
425                         }
426
427                         run = 0; /* stop loop */
428                 }
429         }
430         SETTING_TRACE(" n - FOUND %d ", ncount);
431 }
432
433 void __func_cb(JsonObject *object, const gchar *member_name, JsonNode *member_node, gpointer user_data)
434 {
435         /*JsonArray *array = json_node_get_array(member_node); */
436         /*SETTING_TRACE(" ----> member name : %s ", member_name); */
437         JsonObject *child = json_object_get_object_member(object, member_name);
438         json_object_foreach_member(child, __foreach_attr, (gpointer)member_name);
439 }
440
441 int __compareByCategory(const void *arg1, const void *arg2)
442 {
443         char *str1 = (char *)(((VconfNode *)arg1)->public_groupkey);
444         char *str2 = (char *)(((VconfNode *)arg2)->public_groupkey);
445
446         if (!str1 || !str2) return -1;
447
448         return safeStrCmp(str1, str2);
449 }
450
451 EXPORT_PUBLIC
452 void setting_import_json(status_handler_fp fp, void *data)
453 {
454         SETTING_TRACE_BEGIN;
455         /*--------------------------------------------------------------------------------- */
456         JsonParser *parser;
457         JsonNode *root;
458         GError *error;
459
460         /*---- */
461         int bcount = sizeof(g_btable) / sizeof(g_btable[0]) - 1;
462         int icount = sizeof(g_itable) / sizeof(g_itable[0]) - 1;
463         int scount = sizeof(g_stable) / sizeof(g_stable[0]) - 1; /* why?? buggy */
464         int total = bcount + icount + scount;
465         SETTING_TRACE(" >>> total : %d ", total);
466
467         VconfNode *arr3 = (VconfNode *)malloc(sizeof(VconfNode)*total);
468         if (!arr3) return;
469         memcpy(arr3, g_btable, sizeof(VconfNode)*(bcount));
470         memcpy(&arr3[bcount - 1], g_itable, sizeof(g_itable));
471         memcpy(&arr3[bcount - 1 + icount - 1], g_stable, sizeof(g_stable));
472         qsort(arr3, total, sizeof(VconfNode), __compareByCategory);
473         /*---- */
474
475         g_sortedarr = arr3;
476
477         parser = json_parser_new();
478
479         error = NULL;
480         json_parser_load_from_file(parser, SETTING_CFG_JSON_FILE_PATH, &error);
481         if (error) {
482                 SETTING_TRACE("Unable to parse `%s': %s", SETTING_CFG_JSON_FILE_PATH, error->message);
483                 g_error_free(error);
484                 g_object_unref(parser);
485                 return;
486         }
487
488         root = json_parser_get_root(parser);
489         /* manipulate the object tree and then exit */
490
491         JsonObject *obj1 = json_node_get_object(root);
492         if (json_object_has_member(obj1, "value")) {
493                 JsonNode *node = json_object_get_member(obj1, "value");
494                 JsonObject *object2 = json_node_get_object(node);
495                 json_object_foreach_member(object2, __func_cb, NULL);   /* with g_sortedarr */
496         }
497         g_object_unref(parser);
498
499         FREE(arr3);
500         g_sortedarr = NULL;
501 }
502
503 /**
504  * setting --> cloud : JSON
505  *
506  * int status_handler(int total, int current,  void* data);
507  */
508 EXPORT_PUBLIC
509 char *setting_export_json(status_handler_fp fp, void *data)
510 {
511         JsonNode *root = NULL;
512
513         root = json_node_new(JSON_NODE_OBJECT);
514         JsonObject *top = json_object_new();
515         json_node_take_object(root, top);
516
517         json_object_set_string_member(top, "key", "SETTINGS_359617040746834_8592d887-8b97-406e-9cf9-03aebc045f81");
518
519         int bcount = sizeof(g_btable) / sizeof(g_btable[0]) - 1;
520         int icount = sizeof(g_itable) / sizeof(g_itable[0]) - 1;
521         int scount = sizeof(g_stable) / sizeof(g_stable[0]) - 1; /* why?? buggy */
522
523         int total = bcount + icount + scount;
524
525         JsonNode *topnode = json_node_new(JSON_NODE_OBJECT);
526         JsonObject *topobj = json_object_new();
527         json_node_take_object(topnode, topobj);
528
529         json_object_set_member(top, "value", topnode);
530
531         VconfNode *arr3 = (VconfNode *)malloc(sizeof(VconfNode)*total);
532         if (!arr3) return NULL;
533         memcpy(arr3, g_btable, sizeof(VconfNode)*(bcount));
534         memcpy(&arr3[bcount - 1], g_itable, sizeof(g_itable));
535         memcpy(&arr3[bcount - 1 + icount - 1], g_stable, sizeof(g_stable));
536         qsort(arr3, total, sizeof(VconfNode), __compareByCategory);
537
538         char *public_groupkey = "";
539
540         /*JsonArray* array = NULL; */
541         JsonObject *obj = NULL;
542         JsonNode *node = NULL;
543
544         int i;
545         for (i = 0; i < total; i++) {
546                 if (arr3[i].public_key) {
547                         if (public_groupkey && safeStrCmp(public_groupkey, arr3[i].public_groupkey) != 0) {
548                                 public_groupkey = (char *)(arr3[i].public_groupkey);
549                                 /*array = json_array_new(); */
550                                 obj = json_object_new();
551                                 node = json_node_new(JSON_NODE_OBJECT);
552                                 json_node_take_object(node, obj);
553                                 json_object_set_member(topobj, public_groupkey, node);
554                                 /*json_array_add_element(array, node); */
555                         }
556
557                         /* get data from vconf */
558                         /* get vconf_get */
559                         char *val = NULL;
560                         char arr[1024];
561                         VconfNode result;
562                         switch (arr3[i].type) {
563                                 case eBOOL:
564                                         get_vconf(arr3[i], &result);
565                                         if (result.value.b)
566                                                 val = "true";
567                                         else
568                                                 val = "false";
569                                         break;
570                                 case eINT:
571                                         get_vconf(arr3[i], &result);
572                                         sprintf(arr, "%d", result.value.i);
573                                         val = arr;
574                                         /*if (val == NULL) val = "-100"; */
575                                         break;
576                                 case eSTRING:
577                                         get_vconf(arr3[i], &result);
578                                         val = result.value.c;
579                                         if (val == NULL) val = "";
580                                         break;
581                                 default:
582                                         val = "error";
583                         }
584
585                         json_object_set_string_member(obj, arr3[i].public_key, val);
586                 }
587         }
588
589         /* save data to a file */
590         GError *error = NULL;
591         JsonGenerator *generator = json_generator_new();
592         json_generator_set_root(generator, root/*node*/);
593
594         gsize len;
595         char *buf = (char *)json_generator_to_data(generator, &len);
596
597         g_object_set(generator, "pretty", TRUE, NULL);   /*write file in indent format */
598         gboolean ret = json_generator_to_file(generator, SETTING_CFG_JSON_FILE_PATH, &error);
599         g_object_unref(generator);
600
601         if (FALSE == ret) {
602                 SETTING_TRACE_ERROR("Error writing file %s!", SETTING_CFG_JSON_FILE_PATH);
603                 /*return FALSE; */
604         }
605
606         json_node_free(root);
607         FREE(arr3);
608
609         return buf;
610 }
611
612 int set_vconf(VconfNode node, VconfNode *result)
613 {
614         /*SETTING_TRACE_BEGIN; */
615         int ret = -1 ;
616         /*node.key */
617         /*node.vconf_key */
618         *result = node;
619         switch (node.type) {
620                 case eBOOL:
621                         /*SETTING_TRACE("begin case eBOOL[%s=\"%d\"]", node.vconf_key, node.value.b); */
622                         ret = vconf_set_bool(node.vconf_key, node.value.b);
623                         result->type = eBOOL;
624                         result->value.b = node.value.b;
625                         break;
626                 case eINT:
627                         /*SETTING_TRACE("begin case eINT[%s=\"%d\"]", node.vconf_key, node.value.i); */
628                         ret = vconf_set_int(node.vconf_key, node.value.i);
629                         result->type = eINT;
630                         result->value.i = node.value.i;
631                         break;
632                 case eSTRING:
633                         if (node.key == STR_SLP_LIST_PHONE_PASSWORD) {
634                                 ret = setting_store_init_password(node.value.c);
635                         } else {
636                                 /*SETTING_TRACE("begin case eSTRING[%s=\"%s\"]", node.vconf_key, node.value.c); */
637                                 ret = vconf_set_str(node.vconf_key, node.value.c);
638                         }
639                         result->type = eSTRING;
640                         result->value.c = node.value.c;
641                         break;
642                 default:
643                         SETTING_TRACE_ERROR(">>>>>>>>>> node.type is NOT DEFINED");
644                         break;
645         }
646
647         if (0 != ret) {
648                 SETTING_TRACE_ERROR(">>>>>>>>>> Failed to set vconf[%s]", node.vconf_key);
649         }
650         /*SETTING_TRACE("KEY:%d VCONF_KEY=%s TYPE=%d VALUE=%d ", result->key, result->vconf_key, result->type, result->value.i); */
651         return ret;
652 }
653
654
655 int get_vconf(VconfNode node, VconfNode *result)
656 {
657         int ret = -1 ;
658
659         char md_result[SHA256_DIGEST_LENGTH];
660         memset(md_result, 0x0, SHA256_DIGEST_LENGTH);
661
662
663         *result = node;
664
665         switch (node.type) {
666                 case eBOOL:
667                         ret = vconf_get_bool(node.vconf_key, (int *)(&(node.value.b)));
668                         result->type = eBOOL;
669                         result->value.b = node.value.b;
670                         break;
671                 case eINT:
672                         ret = vconf_get_int(node.vconf_key, &(node.value.i));
673                         result->type = eINT;
674                         result->value.i = node.value.i;
675                         break;
676                 case eSTRING:
677                         if (node.key == STR_SLP_LIST_PHONE_PASSWORD) {
678                                 node.value.c = (char *)malloc(sizeof(char)*SHA256_DIGEST_LENGTH);
679                                 if (node.value.c) {
680                                         memset(node.value.c, 0x0, SHA256_DIGEST_LENGTH);
681                                 } else {
682                                         SETTING_TRACE_ERROR(" malloc filed : eSTRING, node.value.c ");
683                                         ret = SETTING_RETURN_FAIL;
684                                         goto endtag;
685                                 }
686
687                                 if (setting_read_password(md_result) == 0) {
688                                         safeCopyStr(node.value.c, md_result, SHA256_DIGEST_LENGTH); /*  un-safe */
689
690                                         result->type = eSTRING;
691                                         result->value.c = node.value.c;
692                                         ret = SETTING_RETURN_SUCCESS;
693                                 } else {
694                                         /*do nothing */
695                                         ret = SETTING_RETURN_FAIL;
696                                         goto endtag;
697                                 }
698                         } else {
699                                 node.value.c = vconf_get_str(node.vconf_key);
700                                 SETTING_TRACE("string type ---> %s ", node.value.c);
701                                 result->type = eSTRING;
702                                 result->value.c = node.value.c;
703                                 ret = SETTING_RETURN_SUCCESS;
704                         }
705                         break;
706                 default:
707                         SETTING_TRACE_ERROR(">>>>>>>>>>>>>>>>>>>>>>> get vconf ERROR : %s ", node.vconf_key);
708         }
709 endtag:
710         return ret;
711 }
712
713 EXPORT_PUBLIC
714 int setting_set_bool_slp_key(setting_bool_slp_list key, int value, int *err)
715 {
716         /*SETTING_TRACE_BEGIN; */
717         int ret = SETTING_RETURN_FAIL;
718
719         /* error check */
720         if (key < 0 || key >= SETTING_BOOL_SLP_LIST_MAX) {
721                 *err = SETTING_GENERAL_ERR_WRONG_PARAMETER;
722                 return ret;
723         }
724
725         VconfNode result;
726         g_btable[key].value.b = value;
727         ret = set_vconf(g_btable[key], &result);
728
729         SETTING_TRACE("setting_set_bool ::: KEY:%d VCONF_KEY=%s TYPE=%d VALUE=%d ", result.key, result.vconf_key, result.type, result.value.b);
730         return ret;
731 }
732
733 EXPORT_PUBLIC
734 int setting_get_bool_slp_key(setting_bool_slp_list key, int *value, int *err)
735 {
736         /*SETTING_TRACE_BEGIN; */
737         int ret = SETTING_RETURN_FAIL;
738
739         /* error check */
740         if (key < 0 || key >= SETTING_BOOL_SLP_LIST_MAX) {
741                 *err = SETTING_GENERAL_ERR_WRONG_PARAMETER;
742                 SETTING_TRACE_ERROR(" <<<<<<<< key is invalid >>>>>>>>>>>>> ");
743                 return ret;
744         }
745         VconfNode result;
746         ret = get_vconf(g_btable[key], &result);
747         /**value = g_btable[key].value.b; */
748         *value = result.value.b;
749         return ret;
750 }
751
752 EXPORT_PUBLIC
753 int setting_set_int_slp_key(setting_int_slp_list key, int value, int *err)
754 {
755         /*SETTING_TRACE_BEGIN; */
756         int ret = SETTING_RETURN_FAIL;
757
758         /* error check */
759         if (key < 0 || key >= SETTING_INT_SLP_LIST_MAX) {
760                 *err = SETTING_GENERAL_ERR_WRONG_PARAMETER;
761                 SETTING_TRACE(">>> key is invalid ");
762                 return ret;
763         }
764
765         VconfNode result;
766         g_itable[key].value.i = value;
767         ret = set_vconf(g_itable[key], &result);
768         *err = ret;
769         SETTING_TRACE_DEBUG("setting_set_int ::: KEY:%d VCONF_KEY=%s TYPE=%d VALUE=%d ", result.key, result.vconf_key, result.type, result.value.i);
770         return ret;
771 }
772
773 /* return -1: fail  cannot use err to check the result, return value instead*/
774 EXPORT_PUBLIC
775 int setting_get_int_slp_key(setting_int_slp_list key, int *value, int *err)
776 {
777         /*SETTING_TRACE_BEGIN; */
778         int ret = SETTING_RETURN_FAIL;
779
780         /* error check */
781         if (key < 0 || key >= SETTING_INT_SLP_LIST_MAX) {
782                 *err = SETTING_GENERAL_ERR_WRONG_PARAMETER;
783                 return ret;
784         }
785
786         VconfNode result;
787         ret = get_vconf(g_itable[key], &result);
788         /**value = g_itable[key].value.i; */
789         *value = result.value.i;
790
791         *err = ret;
792         return ret;
793 }
794
795 EXPORT_PUBLIC
796 int setting_get_string_slp_key(setting_str_slp_list key, char *value, int *err)
797 {
798         /*SETTING_TRACE_BEGIN; */
799         int ret = SETTING_RETURN_FAIL;
800
801         /* error check */
802         if (key < 0 || key >= STR_SLP_LIST_MAX || NULL == value) {
803                 *err = SETTING_GENERAL_ERR_WRONG_PARAMETER;
804                 return ret;
805         }
806
807         /** @todo check memory leack when passwork checking */
808         VconfNode result;
809         ret = get_vconf(g_stable[key], &result);
810
811         if (ret >= 0) {
812                 safeCopyStr(value, result.value.c, strlen(result.value.c));
813                 SETTING_TRACE(">>>>>>>> %s <<<<<<<<", value);
814                 FREE(result.value.c);
815         } else {
816                 SETTING_TRACE("get_vconf is failed");
817         }
818         *err = ret;
819         return ret;
820 }
821
822 EXPORT_PUBLIC
823 int setting_set_string_slp_key(setting_str_slp_list key, char *value, int *err)
824 {
825         int ret = SETTING_RETURN_FAIL;
826
827         /* error check */
828         if (key < 0 || key >= STR_SLP_LIST_MAX) {
829                 *err = SETTING_GENERAL_ERR_WRONG_PARAMETER;
830                 return ret;
831         }
832
833         VconfNode result;
834         g_stable[key].value.c = value;
835         ret = set_vconf(g_stable[key], &result);
836         g_stable[key].value.c = "";
837
838         SETTING_TRACE("setting_set_str ::: KEY:%d VCONF_KEY=%s TYPE=%d VALUE=%d ", result.key, result.vconf_key, result.type, result.value.c);
839         *err = ret;
840         return ret;
841 }
842
843 /** @todo don't use i18n string directly. */
844 static const setting_lang_entry lang_table[] = {
845         {       "auto",                 "Automatic"},
846         {       "ko_KR.UTF-8",  "한국어"},
847         {       "en_US.UTF-8",  "English"},
848         {       "zh_CN.UTF-8",  "简体中文"},
849         {       "zh_HK.UTF-8",  "繁體中文(香港)"},
850         {       "zh_TW.UTF-8",  "繁體中文(台灣)"},
851         {       "de_DE.UTF-8",  "Deutsch"},
852         {       "nl_NL.UTF-8",  "Nederlands"},
853         {       "es_ES.UTF-8",  "Español"},
854         {       "pt_PT.UTF-8",  "Português"},
855         {       "el_GR.UTF-8",  "Eλληνικά"},
856         {       "it_IT.UTF-8",  "Italiano"},
857         {       "fr_FR.UTF-8",  "Français"},
858         {       "tr_TR.UTF-8",  "Türkçe"},
859         {       "ja_JP.UTF-8",  "にほんご"},
860         {       "ru_RU.UTF-8",  "Россию"},
861 };
862
863 setting_lang_entry *setting_get_language_table()
864 {
865         return (setting_lang_entry *)lang_table;
866 }
867
868
869 static void _parseLangListXML(char *docname);   /* internal */
870 static void __tree_walk_langlist(xmlNodePtr cur); /* internal */
871
872 static Eina_List *s_langlist;                                   /* internal */
873
874 /* do it once */
875 int _langlist_load(char *path)
876 {
877         SETTING_TRACE_BEGIN;
878         SETTING_TRACE("language list path: %s ", path);
879
880         if (!s_langlist) {
881                 _parseLangListXML(path);
882         }
883
884         return 0;
885 }
886
887 /* singleton */
888 EXPORT_PUBLIC
889 Eina_List *setting_get_language_list()
890 {
891         if (NULL == s_langlist) {
892                 _langlist_load(LANGLIST_FILE_PATH);
893         }
894
895         return s_langlist;
896 }
897
898 /* singleton */
899 EXPORT_PUBLIC
900 Eina_List *setting_get_language_list2(char *path)
901 {
902         if (NULL == s_langlist) {
903                 _langlist_load(path);
904         }
905
906         return s_langlist;
907 }
908
909
910 int _langlist_destroy()
911 {
912         SETTING_TRACE_BEGIN;
913         Eina_List *li = s_langlist;
914         setting_lang_entry *node;
915         while (li) {
916                 node = (setting_lang_entry *) eina_list_data_get(li);
917                 if (node) {
918                         /*SETTING_TRACE("destroy nodes : locale : %s title : %s", node->locale, node->title); */
919                         G_FREE(node->locale);
920                         G_FREE(node->title);
921                         G_FREE(node->mcc);
922                         FREE(node);
923                 }
924                 li = eina_list_next(li);
925         }
926         s_langlist = eina_list_free(s_langlist);                /* returns NULL */
927
928         return 0;
929 }
930
931 EXPORT_PUBLIC
932 void  setting_get_language_list_destroy()
933 {
934         _langlist_destroy();
935 }
936
937 static void _parseLangListXML(char *docname)
938 {
939         SETTING_TRACE_BEGIN;
940         xmlDocPtr doc;
941         xmlNodePtr cur;
942
943         doc = xmlParseFile(docname);
944
945         if (doc == NULL) {
946                 fprintf(stderr, "Document not parsed successfully. \n");
947                 return;
948         }
949
950         cur = xmlDocGetRootElement(doc);
951         if (cur == NULL) {
952                 fprintf(stderr, "empty document\n");
953                 xmlFreeDoc(doc);
954                 return;
955         }
956
957         /*SETTING_TRACE("ROOT NODE : %s ", cur->name); */
958         /* make sure root node is "settings" */
959         if (xmlStrcmp(cur->name, (const xmlChar*) "langlist")) {
960                 SETTING_TRACE("document of the wrong type, root node != settings");
961                 xmlFreeDoc(doc);
962                 return;
963         }
964
965         cur = cur->xmlChildrenNode;
966         __tree_walk_langlist(cur);
967
968         /* save tree to file */
969         if (doc != NULL) {
970                 /*xmlSaveFormatFile (docname, doc, 1); */
971                 xmlFreeDoc(doc);
972         }
973         /*xmlFreeDoc(doc); */
974         return;
975 }
976
977 static void __tree_walk_langlist(xmlNodePtr cur)
978 {
979         SETTING_TRACE_BEGIN;
980         xmlNode *cur_node = NULL;
981         char *id;
982         char *string;
983         char *mcc = NULL;
984         /*int number = 1; */
985
986         for (cur_node = cur; cur_node; cur_node = cur_node->next) {
987                 if (cur_node->type == XML_ELEMENT_NODE) {
988
989                         /*SETTING_TRACE(" name=%s title=%s \n", xmlGetProp(cur_node, (const xmlChar *)"id"), xmlGetProp(cur_node, (const xmlChar *)"string")); */
990                         id = (char *)g_strdup((char *)xmlGetProp(cur_node, (const xmlChar*)"id"));
991                         string = (char *)g_strdup((char *) xmlGetProp(cur_node, (const xmlChar*)"string"));
992                         /*SETTING_TRACE_DEBUG("lang: %s", xmlGetProp(cur_node, (const xmlChar *)"lang")); */
993                         mcc = (char *)g_strdup((char *) xmlGetProp(cur_node, (const xmlChar*)"mcc"));
994                         /*number = atoi((char*) xmlGetProp(cur_node, (const xmlChar *)"no")); */
995
996                         setting_lang_entry *pitem = (setting_lang_entry *)calloc(1, sizeof(setting_lang_entry));
997                         if (pitem) {
998                                 pitem->locale = id;
999                                 pitem->title = string;
1000                                 pitem->mcc = mcc;
1001                                 /*pitem->number = number++; */
1002                                 /*SETTING_TRACE_DEBUG("no=%d", pitem->number); */
1003                                 /*SETTING_TRACE_DEBUG(">>>> locale: %s title: %s mcc: %s", pitem->locale, pitem->title, pitem->mcc); */
1004                                 s_langlist = eina_list_append(s_langlist, pitem);
1005                         }
1006                 }
1007         }
1008 }
1009 /*----------------------------------------------------------------------------------------------- */
1010 /*----------------------------------------------------------------------------------------------- */
1011
1012 /*setting_lang_entry* */
1013
1014 /*//////////////////////////////////////////////////////////////////////////////////////// */
1015 int setting_store_init_password(char *in)
1016 {
1017
1018         SHA256_CTX context;
1019         char md[SHA256_DIGEST_LENGTH] = {0,};
1020         /* int i = 0; */
1021         int ret = SETTING_RETURN_FAIL;
1022
1023         SHA256_Init(&context);
1024         SHA256_Update(&context, (char *)in, strlen(in));
1025         SHA256_Final((unsigned char *)md, &context);
1026
1027 #ifdef DEBUG
1028         SETTING_TRACE("input: [%s]\n", in);
1029         SETTING_TRACE("output: [");
1030         for (i = 0; i < SHA256_DIGEST_LENGTH; i++)
1031                 SETTING_TRACE("%02x", md[i]);
1032         SETTING_TRACE("]\n");
1033 #endif
1034
1035         /*  create a file or store a data */
1036         /*  store_password */
1037         FILE *fp = NULL;
1038         int ret_fw = 0;
1039         fp = fopen(PWD_FILE, "w+");
1040         if (fp) {
1041                 ret_fw = fwrite(md, 1, SHA256_DIGEST_LENGTH, fp);
1042                 SETTING_TRACE_DEBUG("fwrite() wrote %d chars.", ret_fw);
1043                 if (ret_fw == SHA256_DIGEST_LENGTH) {
1044                         fflush(fp);
1045                         fsync(fp->_fileno);
1046                         ret = SETTING_RETURN_SUCCESS;
1047                 }
1048                 fclose(fp);
1049         } else {
1050                 SETTING_TRACE("ERR: pwd file is not exist \n");
1051         }
1052
1053         return ret;
1054 }
1055
1056 int setting_read_password(char *md_result)
1057 {
1058         SETTING_TRACE_BEGIN;
1059         /* int i; */
1060         FILE *fp = NULL;
1061         fp = fopen(PWD_FILE, "r");
1062         if (fp) {
1063                 int size = fread(md_result, sizeof(char), SHA256_DIGEST_LENGTH, fp);
1064                 if (size != SHA256_DIGEST_LENGTH) {
1065                         SETTING_TRACE_ERROR("fread failed");
1066                 }
1067                 fclose(fp);
1068         } else {
1069                 SETTING_TRACE("ERR: pwd file is not exist \n");
1070                 return SETTING_RETURN_FAIL;
1071         }
1072
1073 #ifdef DEBUG
1074         SETTING_TRACE("output from file: [");
1075         for (i = 0; i < SHA256_DIGEST_LENGTH; i++)
1076                 SETTING_TRACE("%02x", md_result[i]);
1077         SETTING_TRACE("]\n");
1078 #endif
1079         SETTING_TRACE_END;
1080         return 0;
1081 }
1082
1083 int setting_compare_password(char *md_result, const char *in_later)
1084 {
1085         SETTING_TRACE_BEGIN;
1086         SHA256_CTX context_later;
1087         char md_later[SHA256_DIGEST_LENGTH];
1088         int ret = SETTING_RETURN_FAIL;
1089
1090         SHA256_Init(&context_later);
1091         SHA256_Update(&context_later, (char *)in_later, strlen(in_later));
1092         SHA256_Final((unsigned char *)md_later, &context_later);
1093
1094         SETTING_TRACE(" :[ %25s ]", in_later);
1095
1096         if (0 == memcmp(md_later, md_result, SHA256_DIGEST_LENGTH)) {
1097                 SETTING_TRACE("two passwords are same \n");
1098                 ret = 0;
1099         } else {
1100                 SETTING_TRACE("two passwords are different \n");
1101         }
1102         return ret;
1103 }
1104
1105 EXPORT_PUBLIC
1106 void setting_destory_listen_list(Eina_List **listened_list)
1107 {
1108         if (listened_list && *listened_list) {
1109                 Vconf_Change_Node *node = NULL;
1110                 Eina_List *li = *listened_list;
1111                 while (li) {
1112                         node = (Vconf_Change_Node *) eina_list_data_get(li);
1113                         if (node) {
1114                                 /*SETTING_TRACE("Deregister callback[%p] of %s", node->cb, node->in_key); */
1115                                 if (node->in_key && node->cb) {
1116                                         (void)vconf_ignore_key_changed(node->in_key, node->cb);
1117                                         FREE(node);
1118                                 }
1119                         }
1120                         li = eina_list_next(li);
1121                 }
1122                 *listened_list = eina_list_free(*listened_list);
1123         }
1124 }
1125
1126 EXPORT_PUBLIC
1127 bool setting_add_listen_node(Eina_List **listened_list, const char *vconf, vconf_callback_fn cb, void *data)
1128 {
1129         Vconf_Change_Node *node = calloc(1, sizeof(Vconf_Change_Node));
1130         bool ret = TRUE;
1131         if (node && vconf && cb) {
1132                 node->in_key = vconf;
1133                 node->cb = cb;
1134                 node->cb_data = data;
1135
1136                 if (0 == vconf_notify_key_changed(vconf, cb, data)) {
1137                         /*SETTING_TRACE("Register callback[%p] of %s", node->cb, node->in_key); */
1138                         *listened_list = eina_list_append(*listened_list, node);
1139                 } else {
1140                         SETTING_TRACE_ERROR("Failed to register callback[%p] of %s", node->cb, node->in_key);
1141                         ret = FALSE;
1142                 }
1143         }
1144         FREE(node);
1145         return ret;
1146 }
1147