2 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
3 * Copyright (C) 2014 Intel Corporation
5 * Author: José Bollo <jose.bollo@open.eurogiciel.org>
6 * Author: 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.
25 #include "vconf-buxton.h"
30 #include <sys/types.h>
39 VCONFTOOL_TYPE_NO = 0x00,
40 VCONFTOOL_TYPE_STRING,
42 VCONFTOOL_TYPE_DOUBLE,
46 static char *guid = NULL;
47 static char *uid = NULL;
48 static char *vconf_type = NULL;
49 static int is_recursive = FALSE;
50 static int is_initialization = FALSE;
51 static int is_forced = FALSE;
52 static int get_num = 0;
54 static GOptionEntry entries[] = {
55 {"type", 't', 0, G_OPTION_ARG_STRING, &vconf_type, "type of value",
56 "int|bool|double|string"},
57 {"recursive", 'r', 0, G_OPTION_ARG_NONE, &is_recursive,
58 "retrieve keys recursively", NULL},
59 {"guid", 'g', 0, G_OPTION_ARG_STRING, &guid, "group permission", NULL},
60 {"uid", 'u', 0, G_OPTION_ARG_STRING, &uid, "user permission", NULL},
61 {"initialization", 'i', 0, G_OPTION_ARG_NONE, &is_initialization,
62 "memory backend initialization", NULL},
63 {"force", 'f', 0, G_OPTION_ARG_NONE, &is_forced,
64 "overwrite vconf values by force", NULL},
68 static void get_operation (const char *input);
69 static void print_keylist (keylist_t * keylist);
75 " %1$s set -t <TYPE> <KEY NAME> <VALUE> <OPTIONS>\n"
76 " <TYPE>=int|bool|double|string\n"
78 " Ex) %1$s set -t string db/testapp/key1 \"This is test\" \n"
81 " any option is ignored! (compatibility)\n"
84 " %1$s get <OPTIONS> <KEY NAME>\n"
87 " -r : retrieve all keys included in sub-directorys \n"
88 " Ex) %1$s get db/testapp/key1\n"
89 " %1$s get db/testapp/\n"
91 "[Unset vconf value]\n"
92 " %1$s unset <KEY NAME>\n"
93 "\n" " Ex) %1$s unset db/testapp/key1\n" "\n"
95 "[Set vconf label (Smack)]\n"
96 " %1$s label <KEY NAME> <SMACK LABEL>\n"
97 "\n" " Ex) %1$s label db/testapp/key1 User::Share\n" "\n";
100 print_help (const char *cmd)
102 fprintf (stderr, usage, cmd);
110 if (!strncasecmp (vconf_type, "int", 3))
111 return VCONFTOOL_TYPE_INT;
112 else if (!strncasecmp (vconf_type, "string", 6))
113 return VCONFTOOL_TYPE_STRING;
114 else if (!strncasecmp (vconf_type, "double", 6))
115 return VCONFTOOL_TYPE_DOUBLE;
116 else if (!strncasecmp (vconf_type, "bool", 4))
117 return VCONFTOOL_TYPE_BOOL;
119 return VCONFTOOL_TYPE_NO;
123 main (int argc, char **argv)
127 GError *error = NULL;
128 GOptionContext *context;
130 context = g_option_context_new ("- vconf library tool");
131 g_option_context_add_main_entries (context, entries, NULL);
132 g_option_context_set_help_enabled (context, FALSE);
133 g_option_context_set_ignore_unknown_options (context, TRUE);
135 if (!g_option_context_parse (context, &argc, &argv, &error))
137 g_print ("option parsing failed: %s\n", error->message);
143 print_help (argv[0]);
147 if (!strcmp (argv[1], "set"))
149 set_type = check_type ();
150 if (argc < 4 || !set_type)
152 print_help (argv[0]);
158 case VCONFTOOL_TYPE_STRING:
159 vconf_set_str (argv[2], argv[3]);
161 case VCONFTOOL_TYPE_INT:
162 vconf_set_int (argv[2], atoi (argv[3]));
164 case VCONFTOOL_TYPE_DOUBLE:
165 vconf_set_dbl (argv[2], atof (argv[3]));
167 case VCONFTOOL_TYPE_BOOL:
168 vconf_set_bool (argv[2], !!atoi (argv[3]));
171 fprintf (stderr, "never reach");
176 else if (!strcmp (argv[1], "get"))
179 get_operation (argv[2]);
181 print_help (argv[0]);
183 else if (!strcmp (argv[1], "unset"))
186 vconf_unset (argv[2]);
188 print_help (argv[0]);
190 else if (!strcmp (argv[1], "label"))
192 if (argv[2] && argv[3])
193 vconf_set_label (argv[2], argv[3]);
195 print_help (argv[0]);
198 fprintf (stderr, "%s is a invalid command\n", argv[1]);
203 get_operation (const char *input)
207 keylist = vconf_keylist_new ();
210 vconf_scan (keylist, input, VCONF_GET_KEY_REC);
214 vconf_keylist_add_null (keylist, input);
215 vconf_refresh (keylist);
217 vconf_keylist_sort (keylist);
218 print_keylist (keylist);
220 printf ("No data\n");
221 vconf_keylist_free (keylist);
225 print_keylist (keylist_t * keylist)
229 vconf_keylist_rewind (keylist);
230 while ((node = vconf_keylist_nextnode (keylist)))
232 switch (vconf_keynode_get_type (node))
235 printf ("%s, value = %d (int)\n",
236 vconf_keynode_get_name (node),
237 vconf_keynode_get_int (node));
240 case VCONF_TYPE_BOOL:
241 printf ("%s, value = %d (bool)\n",
242 vconf_keynode_get_name (node),
243 vconf_keynode_get_bool (node));
246 case VCONF_TYPE_DOUBLE:
247 printf ("%s, value = %f (double)\n",
248 vconf_keynode_get_name (node),
249 vconf_keynode_get_dbl (node));
252 case VCONF_TYPE_STRING:
253 printf ("%s, value = %s (string)\n",
254 vconf_keynode_get_name (node),
255 vconf_keynode_get_str (node));