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>
40 const int SHARED_PERM = 0666;
41 const int USER_PERM = 0644;
43 const char *HEYNOTI_PREFIX = "/opt/share/noti";
45 static int is_app = FALSE;
47 static int user_id = 5000;
50 static GOptionEntry entries[] = {
51 {"application", 'a', 0, G_OPTION_ARG_NONE, &is_app,
52 "allow for application", NULL},
57 static void __print_help(const char *cmd)
59 fprintf(stderr, "Usage:\n");
60 fprintf(stderr, "\n");
61 fprintf(stderr, "[Set heynoti key]\n");
63 " %s set <KEY NAME>\n", cmd);
64 fprintf(stderr, "\n");
65 fprintf(stderr, " Ex) %s set heynoti_test\n", cmd);
66 fprintf(stderr, "\n");
67 fprintf(stderr, " <OPTIONS>\n");
69 " -a : Allow application to publish the key.\n");
70 fprintf(stderr, "\n");
71 fprintf(stderr, " Ex) %s set heynoti_test2 -a\n", cmd);
72 fprintf(stderr, "\n");
73 // fprintf(stderr, " %s unset <KEY NAME>\n", cmd);
74 // fprintf(stderr, "\n");
75 // fprintf(stderr, " Ex) %s unset heynoti_test\n", cmd);
76 // fprintf(stderr, "\n");
79 static int __make_file_path(char *pszKey, char *pszBuf)
81 snprintf(pszBuf, BUFSIZE, "%s/%s", HEYNOTI_PREFIX, pszKey);
85 int main(int argc, char **argv)
87 char szFilePath[BUFSIZE] = { 0, };
91 GOptionContext *context;
94 context = g_option_context_new("- vconf library tool");
95 g_option_context_add_main_entries(context, entries, NULL);
96 g_option_context_set_help_enabled(context, FALSE);
97 g_option_context_set_ignore_unknown_options(context, TRUE);
99 if (!g_option_context_parse(context, &argc, &argv, &error)) {
100 g_print("option parsing failed: %s\n", error->message);
105 __print_help(argv[0]);
109 if (!strncmp(argv[1], "set", 3)) {
111 __print_help(argv[0]);
116 /* Start DAC *************************************/
119 "Error!\t Only root user can use '-g or -u' option\n");
123 if (__make_file_path(argv[2], szFilePath)) {
124 fprintf(stderr, "Error!\t Bad prefix\n");
127 /* End DAC ***************************************/
130 /* Start File creation ********************************/
136 if ((fd = open(szFilePath, O_RDONLY)) == -1) {
137 if ((fd = open(szFilePath, O_CREAT, 0644)) < 0) {
146 /* End File creation **********************************/
148 } else if (!strncmp(argv[1], "unset", 5)) {
150 if (__make_file_path(argv[2], szFilePath)) {
151 fprintf(stderr, "Error!\t Bad key string\n");
155 if (remove(szFilePath)) {
156 fprintf(stderr, "Error!\t fail to remove file\n");
161 __print_help(argv[0]);
163 fprintf(stderr, "%s is a invalid command\n", argv[1]);