4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Hakjoo Ko <hakjoo.ko@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.
27 #include "vconf-internals.h"
30 #include <sys/xattr.h>
34 #define API __attribute__ ((visibility("default")))
37 #define VCONF_ERROR_RETRY_CNT 10
38 #define VCONF_ERROR_RETRY_SLEEP_UTIME 5000
42 #define VCONF_MOUNT_PATH "/opt/var/kdb/db"
43 #define VCONF_MOUNT_PATH_CHECK \
46 IN_SBOX = access("/opt/var/kdb/kdb_first_boot", F_OK) + 2; \
47 if(2==IN_SBOX) return 0;\
50 __thread int is_transaction;
52 #ifdef VCONF_TIMECHECK
53 double correction, startT;
55 double set_start_time(void)
60 gettimeofday(&tv, NULL);
61 curtime = tv.tv_sec * 1000 + (double)tv.tv_usec / 1000;
65 double exec_time(double start)
67 double end = set_start_time();
68 return (end - start - correction);
74 temp_t = set_start_time();
75 correction = exec_time(temp_t);
81 int _vconf_keynode_set_keyname(keynode_t *keynode, const char *keyname)
83 if (keynode->keyname) free(keynode->keyname);
84 keynode->keyname = strndup(keyname, BUF_LEN);
85 retvm_if(keynode->keyname == NULL, VCONF_ERROR, "strndup Fails");
89 static inline void _vconf_keynode_set_dir(keynode_t *keynode)
91 keynode->type = VCONF_TYPE_DIR;
94 static inline void _vconf_keynode_set_value_int(keynode_t *keynode, const int value)
96 keynode->type = VCONF_TYPE_INT;
97 keynode->value.i = value;
100 static inline void _vconf_keynode_set_value_bool(keynode_t *keynode, const int value)
102 keynode->type = VCONF_TYPE_BOOL;
103 keynode->value.b = !!value;
106 static inline void _vconf_keynode_set_value_dbl(keynode_t *keynode, const double value)
108 keynode->type = VCONF_TYPE_DOUBLE;
109 keynode->value.d = value;
112 static inline void _vconf_keynode_set_value_str(keynode_t *keynode, const char *value)
114 keynode->type = VCONF_TYPE_STRING;
115 keynode->value.s = strdup(value);
118 inline void _vconf_keynode_set_null(keynode_t *keynode)
120 keynode->type = VCONF_TYPE_NONE;
121 //keynode->value.d = NULL;
124 static inline keynode_t *_vconf_keynode_next(keynode_t *keynode)
126 return keynode->next;
129 inline keynode_t *_vconf_keynode_new(void)
132 keynode = calloc(1, sizeof(keynode_t));
137 inline void _vconf_keynode_free(keynode_t *keynode)
140 if (keynode->keyname)
141 free(keynode->keyname);
142 if (keynode->type == VCONF_TYPE_STRING && keynode->value.s)
143 free(keynode->value.s);
148 static inline keynode_t *_vconf_keylist_headnode(keylist_t *keylist)
150 return keylist->head;
153 static keynode_t *_vconf_keylist_lookup(keylist_t *keylist, const char *keyname,
154 keynode_t **before_keynode)
156 keynode_t *found_node, *temp_node = NULL;
158 found_node = _vconf_keylist_headnode(keylist);
161 if(found_node->keyname == NULL) {
162 ERR("key node has null keyname");
166 if (!strncmp(keyname, found_node->keyname, strlen(keyname))) {
167 if (before_keynode) {
168 *before_keynode = temp_node;
173 temp_node = found_node;
174 found_node = _vconf_keynode_next(found_node);
180 * This function get Key name of the keynode.
181 * @param[in] keynode The Key
182 * @return Key Name of the keynode
184 API char *vconf_keynode_get_name(keynode_t *keynode)
186 retvm_if(keynode == NULL, NULL, "Invalid argument: keynode is NULL");
187 retvm_if(keynode->keyname == NULL, NULL, "The name of keynode is NULL");
189 return keynode->keyname;
193 * This function get value type of the keynode.
194 * @param[in] keynode The Key
195 * @return Type of the keynode
197 API int vconf_keynode_get_type(keynode_t *keynode)
199 retvm_if(keynode == NULL, VCONF_ERROR, "Invalid argument: keynode is NULL");
201 return keynode->type;
204 API int vconf_keynode_get_int(keynode_t *keynode)
206 retvm_if(keynode == NULL, VCONF_ERROR, "Invalid argument: keynode is NULL");
207 retvm_if(keynode->type != VCONF_TYPE_INT, VCONF_ERROR,
208 "The type(%d) of keynode(%s) is not INT", keynode->type, keynode->keyname);
210 return keynode->value.i;
213 API double vconf_keynode_get_dbl(keynode_t *keynode)
215 retvm_if(keynode == NULL, -1.0, "Invalid argument: keynode is NULL");
216 retvm_if(keynode->type != VCONF_TYPE_DOUBLE, -1.0,
217 "The type(%d) of keynode(%s) is not DBL", keynode->type, keynode->keyname);
219 return keynode->value.d;
223 * This function get Boolean value of the keynode.
224 * @param[in] keynode The Key
225 * @return Boolean value, -1 on error
227 API int vconf_keynode_get_bool(keynode_t *keynode)
229 retvm_if(keynode == NULL, VCONF_ERROR, "Invalid argument: keynode is NULL");
230 retvm_if(keynode->type != VCONF_TYPE_BOOL, VCONF_ERROR,
231 "The type(%d) of keynode(%s) is not BOOL", keynode->type, keynode->keyname);
233 return !!(keynode->value.b);
237 * This function get String value of the keynode.
238 * @param[in] keynode The Key
239 * @return String value, NULL on error
241 API char *vconf_keynode_get_str(keynode_t *keynode)
243 retvm_if(keynode == NULL, NULL, "Invalid argument: keynode is NULL");
244 retvm_if(keynode->type != VCONF_TYPE_STRING, NULL,
245 "The type(%d) of keynode(%s) is not STR", keynode->type, keynode->keyname);
247 return keynode->value.s;
251 * Allocate, initialize and return a new Keylist object.
252 * @return The pointer of New keylist, NULL on error
254 API keylist_t *vconf_keylist_new(void)
257 keylist = calloc(1, sizeof(keylist_t));
263 * This function rewinds the KeyList internal cursor.
264 * @param[in] keylist Key List
265 * @return 0 on success, -1 on error
267 API int vconf_keylist_rewind(keylist_t *keylist)
269 retvm_if(keylist == NULL, VCONF_ERROR, "Invalid argument: keylist is NULL");
271 keylist->cursor = NULL;
277 * A destructor for Keylist objects.
278 * @param[in] keylist Key List
279 * @return 0 on success, -1 on error
281 API int vconf_keylist_free(keylist_t *keylist)
283 keynode_t *keynode, *temp;
285 retvm_if(keylist == NULL, VCONF_ERROR, "Invalid argument: keylist is NULL");
288 keynode = _vconf_keylist_headnode(keylist);
290 temp = _vconf_keynode_next(keynode);
291 _vconf_keynode_free(keynode);
300 * This function look for a Keynode contained in keylist that matches keyname.
301 * @param[in] keylist Key List
302 * @param[in] keyname Key to find
303 * @param[out] return_node pointer of keynode to set
304 * @return Type of the found key
307 vconf_keylist_lookup(keylist_t *keylist,
308 const char *keyname, keynode_t **return_node)
310 keynode_t *found_node;
312 retvm_if(keylist == NULL, VCONF_ERROR, "Invalid argument: keylist is NULL");
313 retvm_if(keyname == NULL, VCONF_ERROR, "Invalid argument: keyname is NULL");
314 retvm_if(return_node == NULL, VCONF_ERROR, "Invalid argument: return_node is NULL");
316 found_node = _vconf_keylist_lookup(keylist, keyname, NULL);
317 if (NULL == found_node)
321 *return_node = found_node;
322 return found_node->type;
326 * This function returns the next Key in a Keylist.
327 * Next key is known by the keylist internal cursor.
328 * @param[in] keylist Key List
329 * @return The next Keynode, NULL on error
331 API keynode_t *vconf_keylist_nextnode(keylist_t *keylist)
333 retvm_if(keylist == NULL, NULL, "Invalid argument: keylist is NULL");
336 keylist->cursor = _vconf_keynode_next(keylist->cursor);
338 keylist->cursor = keylist->head;
340 return keylist->cursor;
344 * This function appends a new Keynode included integer value to the keylist.
345 * If same keyname exist, the keynode will change.
346 * @param[in] keylist Key List
347 * @param[in] keyname Key
348 * @param[in] value The integer value
349 * @return Number of keynode included in the keylist, -1 on error
352 vconf_keylist_add_int(keylist_t *keylist, const char *keyname, const int value)
354 keynode_t *keynode = NULL, *addition = NULL;
356 retvm_if(keylist == NULL, VCONF_ERROR, "Invalid argument: keylist is NULL");
357 retvm_if(keyname == NULL, VCONF_ERROR, "Invalid argument: keyname is NULL");
359 if ((keynode = _vconf_keylist_lookup(keylist, keyname, NULL))) {
360 _vconf_keynode_set_value_int(keynode, value);
363 if ((keynode = _vconf_keylist_headnode(keylist)))
364 while (_vconf_keynode_next(keynode))
365 keynode = _vconf_keynode_next(keynode);
367 addition = calloc(1, sizeof(keynode_t));
368 retvm_if(addition == NULL, VCONF_ERROR, "(maybe)not enought memory");
369 if (!_vconf_keynode_set_keyname(addition, keyname)) {
370 _vconf_keynode_set_value_int(addition, value);
371 if (keylist->head && NULL != keynode)
372 keynode->next = addition;
374 keylist->head = addition;
377 ERR("(maybe)not enought memory");
378 free(addition), addition = NULL;
386 * This function appends a new Keynode included boolean value to the keylist.
387 * If same keyname exist, the keynode will change.
388 * @param[in] keylist Key List
389 * @param[in] keyname Key
390 * @param[in] value The boolean value
391 * @return Number of keynode included in the keylist, -1 on error
394 vconf_keylist_add_bool(keylist_t *keylist, const char *keyname, const int value)
396 keynode_t *keynode = NULL, *addition = NULL;
398 retvm_if(keylist == NULL, VCONF_ERROR, "Invalid argument: keylist is NULL");
399 retvm_if(keyname == NULL, VCONF_ERROR, "Invalid argument: keyname is NULL");
401 if ((keynode = _vconf_keylist_lookup(keylist, keyname, NULL))) {
402 _vconf_keynode_set_value_bool(keynode, value);
405 if ((keynode = _vconf_keylist_headnode(keylist)))
406 while (_vconf_keynode_next(keynode))
407 keynode = _vconf_keynode_next(keynode);
409 addition = calloc(1, sizeof(keynode_t));
410 retvm_if(addition == NULL, VCONF_ERROR, "(maybe)not enought memory");
411 if (!_vconf_keynode_set_keyname(addition, keyname)) {
412 _vconf_keynode_set_value_bool(addition, value);
413 if (keylist->head && NULL != keynode)
414 keynode->next = addition;
416 keylist->head = addition;
419 ERR("(maybe)not enought memory");
420 free(addition), addition = NULL;
428 * This function appends a new Keynode included double value to the keylist.
429 * If same keyname exist, the keynode will change.
430 * @param[in] keylist Key List
431 * @param[in] keyname Key
432 * @param[in] value The double value
433 * @return Number of keynode included in the keylist, -1 on error
436 vconf_keylist_add_dbl(keylist_t *keylist,
437 const char *keyname, const double value)
439 keynode_t *keynode = NULL, *addition = NULL;
441 retvm_if(keylist == NULL, VCONF_ERROR, "Invalid argument: keylist is NULL");
442 retvm_if(keyname == NULL, VCONF_ERROR, "Invalid argument: keyname is NULL");
444 if ((keynode = _vconf_keylist_lookup(keylist, keyname, NULL))) {
445 _vconf_keynode_set_value_dbl(keynode, value);
448 if ((keynode = _vconf_keylist_headnode(keylist)))
449 while (_vconf_keynode_next(keynode))
450 keynode = _vconf_keynode_next(keynode);
452 addition = calloc(1, sizeof(keynode_t));
453 retvm_if(addition == NULL, VCONF_ERROR, "(maybe)not enought memory");
454 if (!_vconf_keynode_set_keyname(addition, keyname)) {
455 _vconf_keynode_set_value_dbl(addition, value);
456 if (keylist->head && NULL != keynode)
457 keynode->next = addition;
459 keylist->head = addition;
462 ERR("(maybe)not enought memory");
463 free(addition), addition = NULL;
471 * This function appends a new Keynode included string value to the keylist.
472 * If same keyname exist, the keynode will change.
473 * @param[in] keylist Key List
474 * @param[in] keyname Key
475 * @param[in] value The pointer of string value
476 * @return Number of keynode included in the keylist, -1 on error
479 vconf_keylist_add_str(keylist_t *keylist,
480 const char *keyname, const char *value)
482 keynode_t *keynode = NULL, *addition = NULL;
484 retvm_if(keylist == NULL, VCONF_ERROR, "Invalid argument: keylist is NULL");
485 retvm_if(keyname == NULL, VCONF_ERROR, "Invalid argument: keyname is NULL");
487 if ((keynode = _vconf_keylist_lookup(keylist, keyname, NULL))) {
488 if (VCONF_TYPE_STRING == keynode->type && keynode->value.s)
489 free(keynode->value.s);
490 _vconf_keynode_set_value_str(keynode, value);
493 if (NULL != (keynode = _vconf_keylist_headnode(keylist)))
494 while (_vconf_keynode_next(keynode))
495 keynode = _vconf_keynode_next(keynode);
497 addition = calloc(1, sizeof(keynode_t));
498 retvm_if(addition == NULL, VCONF_ERROR, "(maybe)not enought memory");
499 if (!_vconf_keynode_set_keyname(addition, keyname)) {
500 _vconf_keynode_set_value_str(addition, value);
501 if (keylist->head && NULL != keynode)
502 keynode->next = addition;
504 keylist->head = addition;
507 ERR("(maybe)not enought memory");
508 free(addition), addition = NULL;
516 * This function Appends a new Keynode to the keylist without value.
518 * @param[in] keylist Key List
519 * @param[in] keyname Key
520 * @return Number of keynode included in the keylist, -1 on error
522 API int vconf_keylist_add_null(keylist_t *keylist, const char *keyname)
524 keynode_t *keynode = NULL, *addition = NULL;
526 retvm_if(keylist == NULL, VCONF_ERROR, "Invalid argument: keylist is NULL");
527 retvm_if(keyname == NULL, VCONF_ERROR, "Invalid argument: keyname is NULL");
529 if (NULL != (keynode = _vconf_keylist_lookup(keylist, keyname, NULL))) {
531 keynode->value.d = 0;
534 if ((keynode = _vconf_keylist_headnode(keylist)))
535 while (_vconf_keynode_next(keynode))
536 keynode = _vconf_keynode_next(keynode);
538 addition = calloc(1, sizeof(keynode_t));
539 retvm_if(addition == NULL, VCONF_ERROR, "(maybe)not enought memory");
540 if (!_vconf_keynode_set_keyname(addition, keyname)) {
541 if (keylist->head && keynode)
542 keynode->next = addition;
544 keylist->head = addition;
547 ERR("(maybe)not enought memory");
548 free(addition), addition = NULL;
556 * This function remove the keynode that matches keyname.
557 * @param[in] keylist the keylist included the keyname
558 * @param[in] keyname key
559 * @return 0 on success, -1(Invalid parameter), -2(Not exist keyname in keylist) on error
561 API int vconf_keylist_del(keylist_t *keylist, const char *keyname)
563 keynode_t *found_node, *before_node = NULL;
565 retvm_if(keylist == NULL, VCONF_ERROR, "Invalid argument: keylist is NULL");
566 retvm_if(keyname == NULL, VCONF_ERROR, "Invalid argument: keyname is NULL");
568 if ((found_node = _vconf_keylist_lookup(keylist, keyname, &before_node))) {
570 before_node->next = found_node->next;
572 /* requested key is headnode of keylist */
573 keylist->head = found_node->next;
576 _vconf_keynode_free(found_node);
584 int _vconf_get_key_prefix(const char *keyname, int *prefix)
586 if (strncmp(keyname, BACKEND_DB_PREFIX, sizeof(BACKEND_DB_PREFIX) - 1) == 0) {
587 *prefix = VCONF_BACKEND_DB;
588 } else if (0 == strncmp(keyname, BACKEND_FILE_PREFIX, sizeof(BACKEND_FILE_PREFIX) - 1)) {
589 *prefix = VCONF_BACKEND_FILE;
590 } else if (0 == strncmp(keyname, BACKEND_MEMORY_PREFIX, sizeof(BACKEND_MEMORY_PREFIX) - 1)) {
591 *prefix = VCONF_BACKEND_MEMORY;
593 ERR("Invalid argument: wrong prefix of key(%s)", keyname);
594 *prefix = VCONF_BACKEND_NULL;
595 return VCONF_ERROR_WRONG_PREFIX;
601 int _vconf_get_key_path(const char *keyname, char *path)
603 if (strncmp(keyname, BACKEND_DB_PREFIX, sizeof(BACKEND_DB_PREFIX) - 1) == 0) {
604 snprintf(path, KEY_PATH, "%s%s", BACKEND_SYSTEM_DIR, keyname);
605 } else if (0 == strncmp(keyname, BACKEND_FILE_PREFIX, sizeof(BACKEND_FILE_PREFIX) - 1)) {
606 snprintf(path, KEY_PATH, "%s%s", BACKEND_SYSTEM_DIR, keyname);
607 } else if (0 == strncmp(keyname, BACKEND_MEMORY_PREFIX, sizeof(BACKEND_MEMORY_PREFIX) - 1)) {
608 snprintf(path, KEY_PATH, "%s%s", BACKEND_MEMORY_DIR, keyname);
610 ERR("Invalid argument: wrong prefix of key(%s)", keyname);
611 return VCONF_ERROR_WRONG_PREFIX;
617 #ifndef DISABLE_RUNTIME_KEY_CREATION
618 static int _vconf_set_key_check_parent_dir(const char* path)
621 struct stat stat_info;
623 char path_buf[KEY_PATH] = {0,};
626 mode_t dir_mode = 0664 | 0111;
628 parent = strrchr(path, '/');
629 strncpy(path_buf, path, parent-path);
630 path_buf[parent-path]=0;
632 exists = stat(path_buf,&stat_info);
634 if(mkdir(path_buf, dir_mode) != 0) {
635 if(errno == ENOENT) {
636 ret = _vconf_set_key_check_parent_dir((const char*)path_buf);
637 if(ret != VCONF_OK) return ret;
638 if(mkdir(path_buf, dir_mode) != 0) {
639 ERR("mkdir error(%d)", errno);
649 static int _vconf_set_key_creation(const char* path)
654 fd = open(path, O_RDWR|O_CREAT, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH);
657 ERR("open(rdwr,create) error\n");
666 static int _vconf_set_file_lock(int fd, short type)
672 l.l_type = type; /*Do read Lock*/
673 l.l_start= 0; /*Start at begin*/
674 l.l_whence = SEEK_SET;
675 l.l_len = 0; /*Do it with whole file*/
676 ret = fcntl(fd, F_SETLKW, &l);
683 static int _vconf_set_read_lock(int fd)
685 return _vconf_set_file_lock(fd, F_RDLCK);
688 static int _vconf_set_write_lock(int fd)
690 return _vconf_set_file_lock(fd, F_WRLCK);
693 static int _vconf_set_unlock(int fd)
695 return _vconf_set_file_lock(fd, F_UNLCK);
698 static void _vconf_acquire_transaction_delay(int ms)
700 struct timeval timeout;
701 timeout.tv_sec = ms / 1000 ;
702 timeout.tv_usec = 1000 * ( ms % 1000 );
704 select(0, 0, 0, 0, &timeout);
707 static int _vconf_db_begin_transaction()
710 VCONF_MOUNT_PATH_CHECK;
712 if(is_transaction == 0) {
715 if(setxattr(VCONF_MOUNT_PATH, "full_db_transaction_start", &value, sizeof(value), 0) == -1)
717 _vconf_acquire_transaction_delay(50);
718 goto transaction_retry;
729 static int _vconf_db_commit_transaction()
732 VCONF_MOUNT_PATH_CHECK;
734 retv_if(is_transaction <= 0, VCONF_ERROR);
736 if(is_transaction == 1) {
738 setxattr(VCONF_MOUNT_PATH, "full_db_transaction_stop", &value, sizeof(value), 0);
747 static int _vconf_db_rollback_transaction()
750 VCONF_MOUNT_PATH_CHECK;
752 retv_if(is_transaction <= 0, VCONF_ERROR);
754 if(is_transaction == 1) {
756 setxattr(VCONF_MOUNT_PATH, "full_db_transaction_rb", &value, sizeof(value), 0);
765 static int _vconf_set_key_filesys(keynode_t *keynode, int prefix)
767 char path[KEY_PATH] = {0,};
770 int func_ret = VCONF_OK;
772 char err_buf[100] = { 0, };
773 int is_write_error = 0;
777 ret = _vconf_get_key_path(keynode->keyname, path);
778 retv_if(ret != VCONF_OK, ret);
780 if( (fp = fopen(path, "w")) == NULL ) {
781 func_ret = VCONF_ERROR_FILE_OPEN;
786 if(prefix != VCONF_BACKEND_DB) {
787 (void) _vconf_set_write_lock(fileno(fp));
789 func_ret = VCONF_ERROR_FILE_LOCK;
796 ret = fwrite((void *)&(keynode->type), sizeof(int), 1, fp);
804 func_ret = VCONF_ERROR_FILE_WRITE;
808 /* write key value */
809 switch(keynode->type)
812 ret = fwrite((void *)&(keynode->value.i), sizeof(int), 1, fp);
813 if(ret <= 0) is_write_error = 1;
815 case VCONF_TYPE_DOUBLE:
816 ret = fwrite((void *)&(keynode->value.d), sizeof(double), 1, fp);
817 if(ret <= 0) is_write_error = 1;
819 case VCONF_TYPE_BOOL:
820 ret = fwrite((void *)&(keynode->value.b), sizeof(int), 1, fp);
821 if(ret <= 0) is_write_error = 1;
823 case VCONF_TYPE_STRING:
824 ret = fprintf(fp,"%s",keynode->value.s);
825 if(ret < strlen(keynode->value.s)) is_write_error = 1;
826 //ret = fwrite((void *)keynode->value.s, sizeof(char), strlen(keynode->value.s), fp);
829 func_ret = VCONF_ERROR_WRONG_TYPE;
839 func_ret = VCONF_ERROR_FILE_WRITE;
843 #ifdef ENABLE_FDATASYNC
844 if(prefix == VCONF_BACKEND_FILE) {
847 ret = fdatasync(fileno(fp));
850 func_ret = VCONF_ERROR_FILE_SYNC;
856 if(prefix != VCONF_BACKEND_DB) {
857 (void) _vconf_set_unlock(fileno(fp));
859 func_ret = VCONF_ERROR_FILE_LOCK;
870 strerror_r(err_no, err_buf, 100);
871 ERR("_vconf_set_key_filesys(%d-%s) step(%d) failed(%d / %s)\n", keynode->type, keynode->keyname, func_ret, err_no, err_buf);
877 static int _vconf_set_key(keynode_t *keynode)
879 int func_ret = VCONF_OK;
886 ret = _vconf_get_key_prefix(keynode->keyname, &prefix);
887 retv_if(ret != VCONF_OK, ret);
889 if(prefix == VCONF_BACKEND_DB) {
890 _vconf_db_begin_transaction();
893 while((ret = _vconf_set_key_filesys(keynode, prefix)) != VCONF_OK)
898 if(ret == VCONF_ERROR_FILE_OPEN)
902 /* file is not exist, make path */
903 #ifndef DISABLE_RUNTIME_KEY_CREATION
907 char path[KEY_PATH] = {0,};
908 rc = _vconf_get_key_path(keynode->keyname, path);
910 ERR("_vconf_get_key_path error");
914 ret = _vconf_set_key_check_parent_dir(path);
916 ERR("_vconf_set_key_check_parent_dir error : %s", path);
920 ret = _vconf_set_key_creation(path);
922 ERR("_vconf_set_key_creation error : %s", path);
925 INFO("%s key is created", keynode->keyname);
937 else if (ret == VCONF_ERROR_FILE_CHMOD)
948 else if (ret == VCONF_ERROR_FILE_LOCK)
961 else if (ret == VCONF_ERROR_FILE_WRITE)
980 if ((is_busy_err == 1) && (retry < VCONF_ERROR_RETRY_CNT)) {
981 ERR("%s : write buf error(%d). write will be retried(%d) , usleep time : %d\n", keynode->keyname, ret, retry, (retry)*VCONF_ERROR_RETRY_SLEEP_UTIME);
982 usleep((retry)*VCONF_ERROR_RETRY_SLEEP_UTIME);
985 ERR("%s : write buf error(%d). break. (%d)\n", keynode->keyname, ret, retry);
986 func_ret = VCONF_ERROR;
991 if(prefix == VCONF_BACKEND_DB) {
992 if(func_ret == VCONF_ERROR) {
993 _vconf_db_rollback_transaction();
995 _vconf_db_commit_transaction();
1003 * This function set the value of given keys
1004 * @param[in] keylist the keylist which should contain changed keys
1005 * @return 0 on success, -1 on error
1007 API int vconf_set(keylist_t *keylist)
1011 keynode_t *got_node;
1013 int func_ret = VCONF_OK;
1017 retvm_if(keylist == NULL, VCONF_ERROR, "Invalid argument: keylist is NULL");
1019 INFO("vconf_set (%d)START", keylist->num);
1021 got_node = _vconf_keylist_headnode(keylist);
1023 retvm_if(got_node == NULL, VCONF_ERROR, "Invalid argument: headnode is NULL");
1025 ret = _vconf_get_key_prefix(got_node->keyname, &prefix);
1026 retv_if(ret != VCONF_OK, ret);
1028 if(prefix == VCONF_BACKEND_DB) {
1029 _vconf_db_begin_transaction();
1032 while (got_node != NULL) {
1033 ret = _vconf_set_key(got_node);
1034 if(ret != VCONF_OK) {
1035 func_ret = VCONF_ERROR;
1038 got_node = _vconf_keynode_next(got_node);
1041 if(prefix == VCONF_BACKEND_DB) {
1042 if(func_ret == VCONF_ERROR) {
1043 _vconf_db_rollback_transaction();
1045 _vconf_db_commit_transaction();
1054 API int vconf_sync_key(const char *in_key)
1059 char path[KEY_PATH] = {0,};
1062 ret = _vconf_get_key_path(in_key, path);
1063 if(ret != VCONF_OK) return VCONF_ERROR;
1065 fd = open(path, O_RDWR);
1066 if(fd == -1) return VCONF_ERROR;
1077 * This function set the integer value of given key
1078 * @param[in] in_key key
1079 * @param[in] intval integer value to set
1080 * @return 0 on success, -1 on error
1082 API int vconf_set_int(const char *in_key, const int intval)
1086 retvm_if(in_key == NULL, VCONF_ERROR, "Invalid argument: key is NULL");
1088 int func_ret = VCONF_OK;
1090 keynode_t* pKeyNode = _vconf_keynode_new();
1091 retvm_if(pKeyNode == NULL, VCONF_ERROR, "key malloc fail");
1093 func_ret = _vconf_keynode_set_keyname(pKeyNode, in_key);
1094 if(func_ret != VCONF_OK) {
1095 _vconf_keynode_free(pKeyNode);
1096 ERR("set key name error");
1099 _vconf_keynode_set_value_int(pKeyNode, intval);
1101 if (_vconf_set_key(pKeyNode) != VCONF_OK) {
1102 ERR("vconf_set_int(%d) : %s(%d) error", getpid(), in_key, intval);
1103 func_ret = VCONF_ERROR;
1105 INFO("vconf_set_int(%d) : %s(%d) success", getpid(), in_key, intval);
1108 _vconf_keynode_free(pKeyNode);
1116 * This function set the boolean value of given key
1117 * @param[in] in_key key
1118 * @param[in] boolval boolean value to set
1119 (Integer value 1 is 'True', and 0 is 'False')
1120 * @return 0 on success, -1 on error
1122 API int vconf_set_bool(const char *in_key, const int boolval)
1126 retvm_if(in_key == NULL, VCONF_ERROR, "Invalid argument: key is NULL");
1128 int func_ret = VCONF_OK;
1129 keynode_t* pKeyNode = _vconf_keynode_new();
1130 retvm_if(pKeyNode == NULL, VCONF_ERROR, "key malloc fail");
1132 func_ret = _vconf_keynode_set_keyname(pKeyNode, in_key);
1133 if(func_ret != VCONF_OK) {
1134 _vconf_keynode_free(pKeyNode);
1135 ERR("set key name error");
1138 _vconf_keynode_set_value_bool(pKeyNode, boolval);
1140 if (_vconf_set_key(pKeyNode) != VCONF_OK) {
1141 ERR("vconf_set_bool(%d) : %s(%d) error", getpid(), in_key, boolval);
1142 func_ret = VCONF_ERROR;
1144 INFO("vconf_set_bool(%d) : %s(%d) success", getpid(), in_key, boolval);
1147 _vconf_keynode_free(pKeyNode);
1155 * This function set the double value of given key
1156 * @param[in] in_key key
1157 * @param[in] dblval double value to set
1158 * @return 0 on success, -1 on error
1160 API int vconf_set_dbl(const char *in_key, const double dblval)
1164 retvm_if(in_key == NULL, VCONF_ERROR, "Invalid argument: key is NULL");
1166 int func_ret = VCONF_OK;
1167 keynode_t* pKeyNode = _vconf_keynode_new();
1168 retvm_if(pKeyNode == NULL, VCONF_ERROR, "key malloc fail");
1170 func_ret = _vconf_keynode_set_keyname(pKeyNode, in_key);
1171 if(func_ret != VCONF_OK) {
1172 _vconf_keynode_free(pKeyNode);
1173 ERR("set key name error");
1176 _vconf_keynode_set_value_dbl(pKeyNode, dblval);
1178 if (_vconf_set_key(pKeyNode) != VCONF_OK) {
1179 ERR("vconf_set_dbl(%d) : %s(%f) error", getpid(), in_key, dblval);
1180 func_ret = VCONF_ERROR;
1182 INFO("vconf_set_dbl(%d) : %s(%f) success", getpid(), in_key, dblval);
1185 _vconf_keynode_free(pKeyNode);
1193 * This function set the string value of given key
1194 * @param[in] in_key key
1195 * @param[in] strval string value to set
1196 * @return 0 on success, -1 on error
1198 API int vconf_set_str(const char *in_key, const char *strval)
1202 retvm_if(in_key == NULL, VCONF_ERROR, "Invalid argument: key is NULL");
1203 retvm_if(strval == NULL, VCONF_ERROR, "Invalid argument: value is NULL");
1205 int func_ret = VCONF_OK;
1206 keynode_t* pKeyNode = _vconf_keynode_new();
1207 retvm_if(pKeyNode == NULL, VCONF_ERROR, "key malloc fail");
1209 func_ret = _vconf_keynode_set_keyname(pKeyNode, in_key);
1210 if(func_ret != VCONF_OK) {
1211 _vconf_keynode_free(pKeyNode);
1212 ERR("set key name error");
1215 _vconf_keynode_set_value_str(pKeyNode, strval);
1217 if (_vconf_set_key(pKeyNode) != VCONF_OK) {
1218 ERR("vconf_set_str(%d) : %s(%s) error", getpid(), in_key, strval);
1219 func_ret = VCONF_ERROR;
1221 INFO("vconf_set_str(%d) : %s(%s) success", getpid(), in_key, strval);
1224 _vconf_keynode_free(pKeyNode);
1232 #ifdef SUPPORT_ELEKTRA_VALUE_FORMAT
1233 /* keyFileUnserialize function of ELEKTRA */
1234 static int _vconf_get_key_elektra_format(keynode_t *keynode, FILE *fp)
1236 char version[10] = {0,};
1237 char type[5] = {0,};
1238 char comment[8] = {0,};
1239 char file_buf[BUF_LEN] = {0,};
1243 char err_buf[100] = { 0, };
1244 int func_ret = VCONF_OK;
1246 INFO("_vconf_get_key_elektra_format start");
1250 if (!fgets(version, sizeof(version), fp))
1257 func_ret = VCONF_ERROR_FILE_FGETS;
1260 if (strncmp(version,"RG",2)) {
1261 func_ret = VCONF_ERROR_WRONG_TYPE;
1265 if (!fgets(type, sizeof(type), fp))
1272 func_ret = VCONF_ERROR_FILE_FGETS;
1276 if (!fgets(comment, sizeof(comment), fp))
1283 func_ret = VCONF_ERROR_FILE_FGETS;
1287 while(fgets(file_buf, sizeof(file_buf), fp))
1290 value_size = value_size + strlen(file_buf);
1291 value = (char *) realloc(value, value_size);
1293 func_ret = VCONF_ERROR_NO_MEM;
1296 strncat(value, file_buf, strlen(file_buf));
1298 value_size = strlen(file_buf) + 1;
1299 value = (char *)malloc(value_size);
1301 func_ret = VCONF_ERROR_NO_MEM;
1304 memset(value, 0x00, value_size);
1305 strncpy(value, file_buf, strlen(file_buf));
1311 func_ret = VCONF_ERROR_FILE_FGETS;
1316 case VCONF_TYPE_INT:
1318 _vconf_keynode_set_value_int(keynode, atoi(value));
1321 case VCONF_TYPE_DOUBLE:
1323 _vconf_keynode_set_value_dbl(keynode, atof(value));
1326 case VCONF_TYPE_BOOL:
1328 _vconf_keynode_set_value_bool(keynode, atoi(value));
1331 case VCONF_TYPE_STRING:
1333 _vconf_keynode_set_value_str(keynode, value);
1338 func_ret = VCONF_ERROR_WRONG_VALUE;
1342 if(atoi(type) == VCONF_TYPE_STRING) {
1343 _vconf_keynode_set_value_str(keynode, "");
1345 func_ret = VCONF_ERROR_WRONG_VALUE;
1352 strerror_r(err_no, err_buf, 100);
1353 ERR("_vconf_set_key_filesys(%d/%s) step(%d) failed(%d / %s)\n", keynode->type, keynode->keyname, func_ret, err_no, err_buf);
1356 if(value) free(value);
1362 static int _vconf_get_key_filesys(keynode_t *keynode, int prefix)
1364 char path[KEY_PATH] = {0,};
1366 int func_ret = VCONF_OK;
1367 char err_buf[100] = { 0, };
1374 ret = _vconf_get_key_path(keynode->keyname, path);
1375 retv_if(ret != VCONF_OK, ret);
1377 if( (fp = fopen(path, "r")) == NULL ) {
1378 func_ret = VCONF_ERROR_FILE_OPEN;
1383 if(prefix != VCONF_BACKEND_DB) {
1384 (void) _vconf_set_read_lock(fileno(fp));
1386 func_ret = VCONF_ERROR_FILE_LOCK;
1392 /* read data type */
1393 if(!fread((void*)&type, sizeof(int), 1, fp)) {
1399 func_ret = VCONF_ERROR_FILE_FREAD;
1403 /* read data value */
1406 case VCONF_TYPE_INT:
1409 if(!fread((void*)&value_int, sizeof(int), 1, fp)) {
1415 func_ret = VCONF_ERROR_FILE_FREAD;
1418 _vconf_keynode_set_value_int(keynode, value_int);
1423 case VCONF_TYPE_DOUBLE:
1425 double value_dbl = 0;
1426 if(!fread((void*)&value_dbl, sizeof(double), 1, fp)) {
1432 func_ret = VCONF_ERROR_FILE_FREAD;
1435 _vconf_keynode_set_value_dbl(keynode, value_dbl);
1440 case VCONF_TYPE_BOOL:
1443 if(!fread((void*)&value_int, sizeof(int), 1, fp)) {
1449 func_ret = VCONF_ERROR_FILE_FREAD;
1452 _vconf_keynode_set_value_bool(keynode, value_int);
1457 case VCONF_TYPE_STRING:
1459 char file_buf[BUF_LEN] = {0,};
1463 while(fgets(file_buf, sizeof(file_buf), fp))
1466 value_size = value_size + strlen(file_buf);
1467 value = (char *) realloc(value, value_size);
1469 func_ret = VCONF_ERROR_NO_MEM;
1472 strncat(value, file_buf, strlen(file_buf));
1474 value_size = strlen(file_buf) + 1;
1475 value = (char *)malloc(value_size);
1477 func_ret = VCONF_ERROR_NO_MEM;
1480 memset(value, 0x00, value_size);
1481 strncpy(value, file_buf, strlen(file_buf));
1487 func_ret = VCONF_ERROR_FILE_FGETS;
1490 _vconf_keynode_set_value_str(keynode, value);
1492 _vconf_keynode_set_value_str(keynode, "");
1501 #ifdef SUPPORT_ELEKTRA_VALUE_FORMAT
1502 func_ret = _vconf_get_key_elektra_format(keynode, fp);
1504 func_ret = VCONF_ERROR_WRONG_TYPE;
1509 if(prefix != VCONF_BACKEND_DB) {
1510 (void) _vconf_set_unlock(fileno(fp));
1512 func_ret = VCONF_ERROR_FILE_LOCK;
1523 strerror_r(err_no, err_buf, 100);
1524 ERR("_vconf_get_key_filesys(%d-%s) step(%d) failed(%d / %s)\n", keynode->type, keynode->keyname, func_ret, err_no, err_buf);
1531 int _vconf_get_key(keynode_t *keynode)
1533 int func_ret = VCONF_OK;
1535 int is_busy_err = 0;
1539 ret = _vconf_get_key_prefix(keynode->keyname, &prefix);
1540 retv_if(ret != VCONF_OK, ret);
1542 if(prefix == VCONF_BACKEND_DB) {
1543 _vconf_db_begin_transaction();
1546 while((ret = _vconf_get_key_filesys(keynode, prefix)) != VCONF_OK)
1551 if(ret == VCONF_ERROR_FILE_OPEN)
1563 else if (ret == VCONF_ERROR_FILE_LOCK)
1576 else if (ret == VCONF_ERROR_FILE_FREAD)
1593 if ((is_busy_err == 1) && (retry < VCONF_ERROR_RETRY_CNT)) {
1594 ERR("%s : read buf error(%d). read will be retried(%d) , %d\n", keynode->keyname, ret, retry, (retry)*VCONF_ERROR_RETRY_SLEEP_UTIME);
1595 usleep((retry)*VCONF_ERROR_RETRY_SLEEP_UTIME);
1598 ERR("%s : read buf error(%d). break\n", keynode->keyname, ret);
1599 func_ret = VCONF_ERROR;
1604 if(prefix == VCONF_BACKEND_DB) {
1605 if(func_ret == VCONF_ERROR) {
1606 _vconf_db_rollback_transaction();
1608 _vconf_db_commit_transaction();
1615 static int _vconf_check_value_integrity(const void *value, int type)
1619 if ((type == VCONF_TYPE_STRING) && (value != NULL)) {
1623 if ((value) && (strlen(value) > 0)) {
1624 if ((type == VCONF_TYPE_INT) ||
1625 (type == VCONF_TYPE_BOOL)||
1626 (type == VCONF_TYPE_DOUBLE)) {
1627 while (*(((char *)value) + i) != '\0') {
1628 if ( !isdigit(*(((char *)value) + i)) ) {
1629 if ((type != VCONF_TYPE_BOOL) &&
1630 (*(((char *)value) + i) != '-')) {
1631 if ((type == VCONF_TYPE_DOUBLE) &&
1632 (*(((char *)value) + i) != '.')) {
1633 ERR("ERROR : vconf value is not digit.");
1644 ERR("ERROR : vconf value is NULL.");
1649 int _vconf_path_is_dir(char* path)
1651 struct stat entryInfo;
1653 if(lstat(path, &entryInfo) == 0 ) {
1654 if( S_ISDIR( entryInfo.st_mode ) ) {
1664 API int vconf_get(keylist_t *keylist, const char *dirpath, get_option_t option)
1667 struct dirent entry;
1668 struct dirent *result = NULL;
1669 char full_file_path[KEY_PATH] = {0,};
1670 char file_path[KEY_PATH] = {0,};
1671 char full_path[KEY_PATH] = {0,};
1672 char err_buf[ERR_LEN] = {0,};
1679 keynode_t *temp_keynode;
1681 retvm_if(keylist == NULL, VCONF_ERROR, "Invalid argument: keylist is null");
1682 retvm_if(dirpath == NULL, VCONF_ERROR, "Invalid argument: dirpath is null");
1684 temp_keynode = _vconf_keylist_headnode(keylist);
1686 if ((NULL != temp_keynode) && (VCONF_GET_KEY != option)) {
1687 ERR("Not support mode : Only VCONF_GET_KEY \
1688 option support To retrieve key with keylist");
1692 if(temp_keynode != NULL) {
1693 while(_vconf_keynode_next(temp_keynode)) {
1694 temp_keynode = _vconf_keynode_next(temp_keynode);
1698 ret = _vconf_get_key_path(dirpath, full_path);
1699 retvm_if(ret != VCONF_OK, ret, "Invalid argument: key is not valid");
1702 ret = _vconf_get_key_prefix(dirpath, &prefix);
1703 retv_if(ret != VCONF_OK, ret);
1705 if(prefix == VCONF_BACKEND_DB) {
1706 _vconf_db_begin_transaction();
1709 is_dir = _vconf_path_is_dir(full_path);
1711 if((dir=opendir(full_path)) == NULL) {
1712 strerror_r(errno, err_buf, ERR_LEN);
1713 ERR("ERROR : open directory(%s) fail(%s)", dirpath, err_buf);
1717 if((readdir_r(dir, &entry, &result)) != 0) {
1718 strerror_r(errno, err_buf, ERR_LEN);
1719 ERR("ERROR : read directory(%s) fail(%s)", dirpath, err_buf);
1720 func_ret = VCONF_ERROR;
1723 while(result != NULL)
1725 if(( strcmp( entry.d_name, ".") == 0 ) || ( strcmp( entry.d_name, "..") == 0 )) {
1729 keynode_t* keynode = _vconf_keynode_new();
1730 if(keynode == NULL) {
1732 ERR("Invalid argument: key malloc fail");
1736 snprintf(file_path, KEY_PATH, "%s/%s", dirpath, entry.d_name);
1737 snprintf(full_file_path, KEY_PATH, "%s/%s", full_path, entry.d_name);
1739 rc = _vconf_path_is_dir(full_file_path);
1740 if(rc != VCONF_ERROR) {
1743 if(option == VCONF_GET_KEY) {
1744 _vconf_keynode_free(keynode);
1747 _vconf_keynode_set_keyname(keynode, file_path);
1748 _vconf_keynode_set_dir(keynode);
1751 _vconf_keynode_set_keyname(keynode, file_path);
1752 _vconf_get_key(keynode);
1755 if (keylist->head && temp_keynode != NULL)
1757 temp_keynode->next = keynode;
1758 temp_keynode = _vconf_keynode_next(temp_keynode);
1761 keylist->head = keynode;
1762 temp_keynode = keylist->head;
1766 _vconf_keynode_free(keynode);
1768 memset(err_buf, 0x00, sizeof(err_buf));
1769 strerror_r(errno, err_buf, sizeof(err_buf));
1770 ERR("ERROR : get path(%s) fail(%s)", file_path, err_buf);
1771 func_ret = VCONF_ERROR;
1775 if((readdir_r(dir, &entry, &result)) != 0) {
1776 memset(err_buf, 0x00, sizeof(err_buf));
1777 strerror_r(errno, err_buf, sizeof(err_buf));
1778 ERR("ERROR : read directory(%s) fail(%s)", dirpath, err_buf);
1779 func_ret = VCONF_ERROR;
1783 if((closedir(dir)) != 0) {
1784 memset(err_buf, 0x00, sizeof(err_buf));
1785 strerror_r(errno, err_buf, sizeof(err_buf));
1786 ERR("ERROR : close directory(%s) fail(%s)", dirpath, err_buf);
1787 func_ret = VCONF_ERROR;
1789 } else if(is_dir == 0) {
1790 keynode_t* keynode = _vconf_keynode_new();
1791 retvm_if(keynode == NULL, VCONF_ERROR, "Invalid argument: key malloc fail");
1793 _vconf_keynode_set_keyname(keynode, dirpath);
1795 _vconf_get_key(keynode);
1797 if (keylist->head && temp_keynode != NULL) {
1798 temp_keynode->next = keynode;
1799 //temp_keynode = _vconf_keynode_next(temp_keynode);
1801 keylist->head = keynode;
1802 temp_keynode = keylist->head;
1808 vconf_keylist_rewind(keylist);
1810 if(prefix == VCONF_BACKEND_DB) {
1811 if(func_ret == VCONF_ERROR) {
1812 _vconf_db_rollback_transaction();
1814 _vconf_db_commit_transaction();
1822 * This function get the integer value of given key
1823 * @param[in] in_key key
1824 * @param[out] intval output buffer
1825 * @return 0 on success, -1 on error
1827 API int vconf_get_int(const char *in_key, int *intval)
1831 retvm_if(in_key == NULL, VCONF_ERROR, "Invalid argument: key is null");
1832 retvm_if(intval == NULL, VCONF_ERROR, "Invalid argument: output buffer is null");
1834 int func_ret = VCONF_OK;
1835 keynode_t* pKeyNode = _vconf_keynode_new();
1836 retvm_if(pKeyNode == NULL, VCONF_ERROR, "key malloc fail");
1838 _vconf_keynode_set_keyname(pKeyNode, in_key);
1840 if (_vconf_get_key(pKeyNode) != VCONF_OK) {
1841 ERR("vconf_get_int(%d) : %s error", getpid(), in_key);
1842 func_ret = VCONF_ERROR;
1844 *intval = vconf_keynode_get_int(pKeyNode);
1845 INFO("vconf_get_int(%d) : %s(%d) success", getpid(), in_key, *intval);
1848 _vconf_keynode_free(pKeyNode);
1856 * This function get the boolean value of given key
1857 * @param[in] in_key key
1858 * @param[out] boolval output buffer
1859 * @return 0 on success, -1 on error
1861 API int vconf_get_bool(const char *in_key, int *boolval)
1865 retvm_if(in_key == NULL, VCONF_ERROR, "Invalid argument: key is null");
1866 retvm_if(boolval == NULL, VCONF_ERROR, "Invalid argument: output buffer is null");
1868 int func_ret = VCONF_OK;
1869 keynode_t* pKeyNode = _vconf_keynode_new();
1870 retvm_if(pKeyNode == NULL, VCONF_ERROR, "key malloc fail");
1872 _vconf_keynode_set_keyname(pKeyNode, in_key);
1874 if (_vconf_get_key(pKeyNode) != VCONF_OK) {
1875 ERR("vconf_get_bool(%d) : %s error", getpid(), in_key);
1876 func_ret = VCONF_ERROR;
1878 *boolval = vconf_keynode_get_bool(pKeyNode);
1879 INFO("vconf_get_bool(%d) : %s(%d) success", getpid(), in_key, *boolval);
1882 _vconf_keynode_free(pKeyNode);
1890 * This function get the double value of given key
1891 * @param[in] in_key key
1892 * @param[out] dblval output buffer
1893 * @return 0 on success, -1 on error
1895 API int vconf_get_dbl(const char *in_key, double *dblval)
1899 retvm_if(in_key == NULL, VCONF_ERROR, "Invalid argument: key is null");
1900 retvm_if(dblval == NULL, VCONF_ERROR, "Invalid argument: output buffer is null");
1902 int func_ret = VCONF_OK;
1903 keynode_t* pKeyNode = _vconf_keynode_new();
1904 retvm_if(pKeyNode == NULL, VCONF_ERROR, "key malloc fail");
1906 _vconf_keynode_set_keyname(pKeyNode, in_key);
1908 if (_vconf_get_key(pKeyNode) != VCONF_OK) {
1909 ERR("vconf_get_dbl(%d) : %s error", getpid(), in_key);
1910 func_ret = VCONF_ERROR;
1912 *dblval = vconf_keynode_get_dbl(pKeyNode);
1913 INFO("vconf_get_dbl(%d) : %s(%f) success", getpid(), in_key, *dblval);
1916 _vconf_keynode_free(pKeyNode);
1924 * This function get the string value of given key
1925 * @param[in] in_key key
1926 * @return pointer of key value on success, NULL on error
1928 API char *vconf_get_str(const char *in_key)
1932 retvm_if(in_key == NULL, NULL, "Invalid argument: key is null");
1934 keynode_t* pKeyNode = _vconf_keynode_new();
1935 retvm_if(pKeyNode == NULL, NULL, "key malloc fail");
1937 _vconf_keynode_set_keyname(pKeyNode, in_key);
1939 char *strval = NULL;
1940 char *tempstr = NULL;
1942 if (_vconf_get_key(pKeyNode) != VCONF_OK) {
1943 ERR("vconf_get_str(%d) : %s error", getpid(), in_key);
1945 tempstr = vconf_keynode_get_str(pKeyNode);
1947 strval = strdup(tempstr);
1948 INFO("vconf_get_str(%d) : %s success", getpid(), in_key);
1951 _vconf_keynode_free(pKeyNode);
1959 * This function unset given key
1960 * @param[in] in_key key
1961 * @return 0 on success, -1 on error
1963 API int vconf_unset(const char *in_key)
1967 char path[KEY_PATH] = {0,};
1969 int err_retry = VCONF_ERROR_RETRY_CNT;
1970 int func_ret = VCONF_OK;
1972 retvm_if(in_key == NULL, VCONF_ERROR, "Invalid argument: key is null");
1974 ret = _vconf_get_key_path(in_key, path);
1975 retvm_if(ret != VCONF_OK, VCONF_ERROR, "Invalid argument: key is not valid");
1980 ERR("vconf_unset error(%d) : %s", errno, in_key);
1981 func_ret = VCONF_ERROR;
1983 func_ret = VCONF_OK;
1986 } while(err_retry--);
1988 INFO("vconf_unset success : %s", in_key);
1996 * This function unset given key recursively
1997 * @param[in] in_dir Directory name for removing
1998 * @return 0 on success, -1 on error
2000 API int vconf_unset_recursive(const char *in_dir)
2005 struct dirent entry;
2006 struct dirent *result = NULL;
2007 char fullpath[KEY_PATH] = {0,};
2008 char dirpath[KEY_PATH] = {0,};
2009 char err_buf[ERR_LEN] = {0,};
2014 retvm_if(in_dir == NULL, VCONF_ERROR, "Invalid argument: dir path is null");
2016 ret = _vconf_get_key_path(in_dir, dirpath);
2017 retvm_if(ret != VCONF_OK, VCONF_ERROR, "Invalid argument: key is not valid");
2019 if((dir=opendir(dirpath)) == NULL) {
2020 strerror_r(errno, err_buf, ERR_LEN);
2021 ERR("ERROR : open directory(%s) fail(%s)", in_dir, err_buf);
2025 if((readdir_r(dir, &entry, &result)) != 0) {
2026 strerror_r(errno, err_buf, ERR_LEN);
2027 ERR("ERROR : read directory(%s) fail(%s)", in_dir, err_buf);
2028 func_ret = VCONF_ERROR;
2031 while(result != NULL)
2033 if(( strcmp( entry.d_name, ".") == 0 ) || ( strcmp( entry.d_name, "..") == 0 )) {
2037 snprintf(fullpath,KEY_PATH, "%s/%s", dirpath, entry.d_name);
2039 ret = _vconf_path_is_dir(fullpath);
2040 if(ret != VCONF_ERROR) {
2042 rc = vconf_unset_recursive(fullpath);
2043 if(rc == VCONF_ERROR)
2044 func_ret = VCONF_ERROR;
2047 rc = remove(fullpath);
2049 memset(err_buf, 0x00, sizeof(err_buf));
2050 strerror_r(errno, err_buf, sizeof(err_buf));
2051 ERR("ERROR : remove path(%s) fail(%s)", in_dir, err_buf);
2052 func_ret = VCONF_ERROR;
2055 memset(err_buf, 0x00, sizeof(err_buf));
2056 strerror_r(errno, err_buf, sizeof(err_buf));
2057 ERR("ERROR : remove path(%s) fail(%s)", in_dir, err_buf);
2058 func_ret = VCONF_ERROR;
2061 if((readdir_r(dir, &entry, &result)) != 0) {
2062 memset(err_buf, 0x00, sizeof(err_buf));
2063 strerror_r(errno, err_buf, sizeof(err_buf));
2064 ERR("ERROR : read directory(%s) fail(%s)", in_dir, err_buf);
2065 func_ret = VCONF_ERROR;
2069 if((closedir(dir)) != 0) {
2070 memset(err_buf, 0x00, sizeof(err_buf));
2071 strerror_r(errno, err_buf, sizeof(err_buf));
2072 ERR("ERROR : close directory(%s) fail(%s)", in_dir, err_buf);
2073 func_ret = VCONF_ERROR;
2076 if(func_ret == VCONF_OK) {
2077 if((remove(in_dir)) == -1) {
2078 memset(err_buf, 0x00, sizeof(err_buf));
2079 strerror_r(errno, err_buf, sizeof(err_buf));
2080 ERR("ERROR : remove path(%s) fail(%s)", in_dir, err_buf);
2081 func_ret = VCONF_ERROR;
2089 API int vconf_notify_key_changed(const char *in_key, vconf_callback_fn cb, void *user_data)
2093 retvm_if(in_key == NULL, VCONF_ERROR, "Invalid argument: key is null");
2094 retvm_if(cb == NULL, VCONF_ERROR, "Invalid argument: cb(%p)", cb);
2096 if (_vconf_kdb_add_notify(in_key, cb, user_data)) {
2097 ERR("vconf_notify_key_changed : key(%s) add notify fail", in_key);
2101 INFO("vconf_notify_key_changed : %s noti is added", in_key);
2108 API int vconf_ignore_key_changed(const char *in_key, vconf_callback_fn cb)
2112 retvm_if(in_key == NULL, VCONF_ERROR, "Invalid argument: key is null");
2113 retvm_if(cb == NULL, VCONF_ERROR, "Invalid argument: cb(%p)", cb);
2115 if (_vconf_kdb_del_notify(in_key, cb)) {
2116 ERR("vconf_ignore_key_changed() failed: key(%s)", in_key);
2120 INFO("vconf_ignore_key_changed : %s noti removed", in_key);
2127 API mode_t vconf_set_permission(mode_t mode)
2129 /* TODO: implement! */
2133 API int vconf_set_key_permission(const char *in_key, const mode_t mode)
2135 /* TODO: implement! */