aboutsummaryrefslogtreecommitdiff
path: root/src/util/gnunet-uri.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/gnunet-uri.c')
-rw-r--r--src/util/gnunet-uri.c149
1 files changed, 75 insertions, 74 deletions
diff --git a/src/util/gnunet-uri.c b/src/util/gnunet-uri.c
index 33ff7b1e6..75667b30f 100644
--- a/src/util/gnunet-uri.c
+++ b/src/util/gnunet-uri.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file util/gnunet-uri.c 22 * @file util/gnunet-uri.c
@@ -49,15 +49,15 @@ static struct GNUNET_DISK_PipeHandle *sigpipe;
49 * @param cls closure, NULL 49 * @param cls closure, NULL
50 */ 50 */
51static void 51static void
52maint_child_death (void *cls) 52maint_child_death(void *cls)
53{ 53{
54 enum GNUNET_OS_ProcessStatusType type; 54 enum GNUNET_OS_ProcessStatusType type;
55 55
56 (void) cls; 56 (void)cls;
57 if ((GNUNET_OK != GNUNET_OS_process_status (p, &type, &exit_code)) || 57 if ((GNUNET_OK != GNUNET_OS_process_status(p, &type, &exit_code)) ||
58 (type != GNUNET_OS_PROCESS_EXITED)) 58 (type != GNUNET_OS_PROCESS_EXITED))
59 GNUNET_break (0 == GNUNET_OS_process_kill (p, GNUNET_TERM_SIG)); 59 GNUNET_break(0 == GNUNET_OS_process_kill(p, GNUNET_TERM_SIG));
60 GNUNET_OS_process_destroy (p); 60 GNUNET_OS_process_destroy(p);
61} 61}
62 62
63 63
@@ -70,10 +70,10 @@ maint_child_death (void *cls)
70 * @param cfg configuration 70 * @param cfg configuration
71 */ 71 */
72static void 72static void
73run (void *cls, 73run(void *cls,
74 char *const *args, 74 char *const *args,
75 const char *cfgfile, 75 const char *cfgfile,
76 const struct GNUNET_CONFIGURATION_Handle *cfg) 76 const struct GNUNET_CONFIGURATION_Handle *cfg)
77{ 77{
78 const char *uri; 78 const char *uri;
79 const char *slash; 79 const char *slash;
@@ -81,52 +81,52 @@ run (void *cls,
81 char *program; 81 char *program;
82 struct GNUNET_SCHEDULER_Task *rt; 82 struct GNUNET_SCHEDULER_Task *rt;
83 83
84 (void) cls; 84 (void)cls;
85 (void) cfgfile; 85 (void)cfgfile;
86 if (NULL == (uri = args[0])) 86 if (NULL == (uri = args[0]))
87 { 87 {
88 fprintf (stderr, _ ("No URI specified on command line\n")); 88 fprintf(stderr, _("No URI specified on command line\n"));
89 return; 89 return;
90 } 90 }
91 if (0 != strncasecmp ("gnunet://", uri, strlen ("gnunet://"))) 91 if (0 != strncasecmp("gnunet://", uri, strlen("gnunet://")))
92 { 92 {
93 fprintf (stderr, 93 fprintf(stderr,
94 _ ("Invalid URI: does not start with `%s'\n"), 94 _("Invalid URI: does not start with `%s'\n"),
95 "gnunet://"); 95 "gnunet://");
96 return; 96 return;
97 } 97 }
98 uri += strlen ("gnunet://"); 98 uri += strlen("gnunet://");
99 if (NULL == (slash = strchr (uri, '/'))) 99 if (NULL == (slash = strchr(uri, '/')))
100 { 100 {
101 fprintf (stderr, _ ("Invalid URI: fails to specify subsystem\n")); 101 fprintf(stderr, _("Invalid URI: fails to specify subsystem\n"));
102 return; 102 return;
103 } 103 }
104 subsystem = GNUNET_strndup (uri, slash - uri); 104 subsystem = GNUNET_strndup(uri, slash - uri);
105 if (GNUNET_OK != 105 if (GNUNET_OK !=
106 GNUNET_CONFIGURATION_get_value_string (cfg, "uri", subsystem, &program)) 106 GNUNET_CONFIGURATION_get_value_string(cfg, "uri", subsystem, &program))
107 { 107 {
108 fprintf (stderr, _ ("No handler known for subsystem `%s'\n"), subsystem); 108 fprintf(stderr, _("No handler known for subsystem `%s'\n"), subsystem);
109 GNUNET_free (subsystem); 109 GNUNET_free(subsystem);
110 return; 110 return;
111 } 111 }
112 GNUNET_free (subsystem); 112 GNUNET_free(subsystem);
113 rt = GNUNET_SCHEDULER_add_read_file ( 113 rt = GNUNET_SCHEDULER_add_read_file(
114 GNUNET_TIME_UNIT_FOREVER_REL, 114 GNUNET_TIME_UNIT_FOREVER_REL,
115 GNUNET_DISK_pipe_handle (sigpipe, GNUNET_DISK_PIPE_END_READ), 115 GNUNET_DISK_pipe_handle(sigpipe, GNUNET_DISK_PIPE_END_READ),
116 &maint_child_death, 116 &maint_child_death,
117 NULL); 117 NULL);
118 p = GNUNET_OS_start_process (GNUNET_NO, 118 p = GNUNET_OS_start_process(GNUNET_NO,
119 0, 119 0,
120 NULL, 120 NULL,
121 NULL, 121 NULL,
122 NULL, 122 NULL,
123 program, 123 program,
124 program, 124 program,
125 args[0], 125 args[0],
126 NULL); 126 NULL);
127 GNUNET_free (program); 127 GNUNET_free(program);
128 if (NULL == p) 128 if (NULL == p)
129 GNUNET_SCHEDULER_cancel (rt); 129 GNUNET_SCHEDULER_cancel(rt);
130} 130}
131 131
132 132
@@ -135,17 +135,17 @@ run (void *cls,
135 * respective handler by writing to the trigger pipe. 135 * respective handler by writing to the trigger pipe.
136 */ 136 */
137static void 137static void
138sighandler_child_death () 138sighandler_child_death()
139{ 139{
140 static char c; 140 static char c;
141 int old_errno = errno; /* back-up errno */ 141 int old_errno = errno; /* back-up errno */
142 142
143 GNUNET_break ( 143 GNUNET_break(
144 1 == 144 1 ==
145 GNUNET_DISK_file_write (GNUNET_DISK_pipe_handle (sigpipe, 145 GNUNET_DISK_file_write(GNUNET_DISK_pipe_handle(sigpipe,
146 GNUNET_DISK_PIPE_END_WRITE), 146 GNUNET_DISK_PIPE_END_WRITE),
147 &c, 147 &c,
148 sizeof (c))); 148 sizeof(c)));
149 errno = old_errno; /* restore errno */ 149 errno = old_errno; /* restore errno */
150} 150}
151 151
@@ -158,32 +158,33 @@ sighandler_child_death ()
158 * @return 0 ok, 1 on error 158 * @return 0 ok, 1 on error
159 */ 159 */
160int 160int
161main (int argc, char *const *argv) 161main(int argc, char *const *argv)
162{ 162{
163 static const struct GNUNET_GETOPT_CommandLineOption options[] = { 163 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
164 GNUNET_GETOPT_OPTION_END}; 164 GNUNET_GETOPT_OPTION_END
165 };
165 struct GNUNET_SIGNAL_Context *shc_chld; 166 struct GNUNET_SIGNAL_Context *shc_chld;
166 int ret; 167 int ret;
167 168
168 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) 169 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv))
169 return 2; 170 return 2;
170 sigpipe = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_NO, GNUNET_NO); 171 sigpipe = GNUNET_DISK_pipe(GNUNET_NO, GNUNET_NO, GNUNET_NO, GNUNET_NO);
171 GNUNET_assert (sigpipe != NULL); 172 GNUNET_assert(sigpipe != NULL);
172 shc_chld = 173 shc_chld =
173 GNUNET_SIGNAL_handler_install (GNUNET_SIGCHLD, &sighandler_child_death); 174 GNUNET_SIGNAL_handler_install(GNUNET_SIGCHLD, &sighandler_child_death);
174 ret = GNUNET_PROGRAM_run (argc, 175 ret = GNUNET_PROGRAM_run(argc,
175 argv, 176 argv,
176 "gnunet-uri URI", 177 "gnunet-uri URI",
177 gettext_noop ( 178 gettext_noop(
178 "Perform default-actions for GNUnet URIs"), 179 "Perform default-actions for GNUnet URIs"),
179 options, 180 options,
180 &run, 181 &run,
181 NULL); 182 NULL);
182 GNUNET_SIGNAL_handler_uninstall (shc_chld); 183 GNUNET_SIGNAL_handler_uninstall(shc_chld);
183 shc_chld = NULL; 184 shc_chld = NULL;
184 GNUNET_DISK_pipe_close (sigpipe); 185 GNUNET_DISK_pipe_close(sigpipe);
185 sigpipe = NULL; 186 sigpipe = NULL;
186 GNUNET_free ((void *) argv); 187 GNUNET_free((void *)argv);
187 return ((GNUNET_OK == ret) && (0 == exit_code)) ? 0 : 1; 188 return ((GNUNET_OK == ret) && (0 == exit_code)) ? 0 : 1;
188} 189}
189 190