4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
7 * Jaeho Lee <jaeho81.lee@samsung.com>
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
29 #include <glib-object.h>
34 #include <sys/types.h>
37 /* For multi-user support */
38 #include <tzplatform_config.h>
40 #define HEYNOTI_PREFIX tzplatform_mkpath(TZ_SYS_SHARE, "noti")
44 const int SHARED_PERM = 0666;
45 const int USER_PERM = 0644;
47 static int is_app = FALSE;
51 static GOptionEntry entries[] = {
52 {"application", 'a', 0, G_OPTION_ARG_NONE, &is_app,
53 "allow for application", NULL},
58 static void __print_help(const char *cmd)
60 fprintf(stderr, "Usage:\n");
61 fprintf(stderr, "\n");
62 fprintf(stderr, "[Set heynoti key]\n");
64 " %s set <KEY NAME>\n", cmd);
65 fprintf(stderr, "\n");
66 fprintf(stderr, " Ex) %s set heynoti_test\n", cmd);
67 fprintf(stderr, "\n");
68 fprintf(stderr, " <OPTIONS>\n");
70 " -a : Allow application to publish the key.\n");
71 fprintf(stderr, "\n");
72 fprintf(stderr, " Ex) %s set heynoti_test2 -a\n", cmd);
73 fprintf(stderr, "\n");
74 // fprintf(stderr, " %s unset <KEY NAME>\n", cmd);
75 // fprintf(stderr, "\n");
76 // fprintf(stderr, " Ex) %s unset heynoti_test\n", cmd);
77 // fprintf(stderr, "\n");
80 static int __make_file_path(char *pszKey, char *pszBuf)
82 snprintf(pszBuf, BUFSIZE, "%s/%s", HEYNOTI_PREFIX, pszKey);
86 int main(int argc, char **argv)
88 char szFilePath[BUFSIZE] = { 0, };
92 GOptionContext *context;
95 context = g_option_context_new("- vconf library tool");
96 g_option_context_add_main_entries(context, entries, NULL);
97 g_option_context_set_help_enabled(context, FALSE);
98 g_option_context_set_ignore_unknown_options(context, TRUE);
100 if (!g_option_context_parse(context, &argc, &argv, &error)) {
101 g_print("option parsing failed: %s\n", error->message);
106 __print_help(argv[0]);
110 if (!strncmp(argv[1], "set", 3)) {
112 __print_help(argv[0]);
117 /* Start DAC *************************************/
120 "Error!\t Only root user can use '-g or -u' option\n");
124 if (__make_file_path(argv[2], szFilePath)) {
125 fprintf(stderr, "Error!\t Bad prefix\n");
128 /* End DAC ***************************************/
131 /* Start File creation ********************************/
137 if ((fd = open(szFilePath, O_RDONLY)) == -1) {
138 if ((fd = open(szFilePath, O_CREAT, 0644)) < 0) {
147 /* End File creation **********************************/
149 } else if (!strncmp(argv[1], "unset", 5)) {
151 if (__make_file_path(argv[2], szFilePath)) {
152 fprintf(stderr, "Error!\t Bad key string\n");
156 if (remove(szFilePath)) {
157 fprintf(stderr, "Error!\t fail to remove file\n");
162 __print_help(argv[0]);
164 fprintf(stderr, "%s is a invalid command\n", argv[1]);