GNUnet 0.26.2-45-gb0324da85
 
Loading...
Searching...
No Matches
gnunet-uri.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2012 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
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/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
27#include "platform.h"
28#include "gnunet_util_lib.h"
29
33static long unsigned int exit_code = 0;
34
38static struct GNUNET_Process *p;
39
44
45
52static void
54{
56
57 (void) cls;
58 if ((GNUNET_OK !=
60 false,
61 &type,
62 &exit_code)) ||
68}
69
70
79static void
80run (void *cls,
81 char *const *args,
82 const char *cfgfile,
83 const struct GNUNET_CONFIGURATION_Handle *cfg)
84{
85 const char *uri;
86 const char *slash;
87 char *program;
88 struct GNUNET_SCHEDULER_Task *rt;
89
90 (void) cls;
91 (void) cfgfile;
92 if (NULL == (uri = args[0]))
93 {
94 fprintf (stderr,
95 _ ("No URI specified on command line\n"));
96 return;
97 }
98 if (0 != strncasecmp ("gnunet://",
99 uri,
100 strlen ("gnunet://")))
101 {
102 fprintf (stderr,
103 _ ("Invalid URI: does not start with `%s'\n"),
104 "gnunet://");
105 return;
106 }
107 uri += strlen ("gnunet://");
108 if (NULL == (slash = strchr (uri, '/')))
109 {
110 fprintf (stderr,
111 _ ("Invalid URI: fails to specify subsystem\n"));
112 return;
113 }
114
115 {
116 char *subsystem;
117
119 slash - uri);
120 if (GNUNET_OK !=
122 "uri",
123 subsystem,
124 &program))
125 {
126 fprintf (stderr,
127 _ ("No handler known for subsystem `%s'\n"),
128 subsystem);
130 return;
131 }
133 }
138 NULL);
140 if (GNUNET_OK !=
142 program,
143 program,
144 args[0],
145 NULL))
146 {
148 p = NULL;
150 }
151 GNUNET_free (program);
152}
153
154
159static void
161{
162 static char c;
163 int old_errno = errno; /* back-up errno */
164
166 1 ==
170 &c,
171 sizeof(c)));
172 errno = old_errno; /* restore errno */
173}
174
175
183int
184main (int argc,
185 char *const *argv)
186{
187 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
189 };
191 int ret;
192
194 GNUNET_assert (sigpipe != NULL);
195 shc_chld =
199 argc,
200 argv,
201 "gnunet-uri URI",
203 "Perform default-actions for GNUnet URIs"),
204 options,
205 &run,
206 NULL);
208 shc_chld = NULL;
210 sigpipe = NULL;
211 return ((GNUNET_OK == ret) && (0 == exit_code)) ? 0 : 1;
212}
213
214
215/* end of gnunet-uri.c */
struct GNUNET_GETOPT_CommandLineOption options[]
Definition 002.c:5
static struct GNUNET_SIGNAL_Context * shc_chld
int main()
Program to simulate results from GCP_get_desirability_of_path() for various plausible inputs.
#define gettext_noop(String)
Definition gettext.h:74
static int ret
Final status code.
Definition gnunet-arm.c:93
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition gnunet-arm.c:108
static uint32_t type
Type string converted to DNS type value.
static struct GNUNET_FS_Uri * uri
Value of URI provided on command-line (when not publishing a file but just creating UBlocks to refer ...
static char * subsystem
Set to subsystem that we're going to get stats for (or NULL for all).
static void maint_child_death(void *cls)
Task triggered whenever we receive a SIGCHLD (child process died) or when user presses CTRL-C.
Definition gnunet-uri.c:53
static struct GNUNET_DISK_PipeHandle * sigpipe
Pipe used to communicate shutdown via signal.
Definition gnunet-uri.c:43
static void sighandler_child_death()
Signal handler called for SIGCHLD.
Definition gnunet-uri.c:160
static long unsigned int exit_code
Handler exit code.
Definition gnunet-uri.c:33
static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
Main function that will be run by the scheduler.
Definition gnunet-uri.c:80
static struct GNUNET_Process * p
Helper process we started.
Definition gnunet-uri.c:38
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_string(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be a string.
const struct GNUNET_DISK_FileHandle * GNUNET_DISK_pipe_handle(const struct GNUNET_DISK_PipeHandle *p, enum GNUNET_DISK_PipeEnd n)
Get the handle to a particular pipe end.
Definition disk.c:1703
ssize_t GNUNET_DISK_file_write(const struct GNUNET_DISK_FileHandle *h, const void *buffer, size_t n)
Write a buffer to a file.
Definition disk.c:745
struct GNUNET_DISK_PipeHandle * GNUNET_DISK_pipe(enum GNUNET_DISK_PipeFlags pf)
Creates an interprocess channel.
Definition disk.c:1524
enum GNUNET_GenericReturnValue GNUNET_DISK_pipe_close(struct GNUNET_DISK_PipeHandle *p)
Closes an interprocess channel.
Definition disk.c:1671
@ GNUNET_DISK_PF_NONE
No special options, use non-blocking read/write operations.
@ GNUNET_DISK_PIPE_END_WRITE
The writing-end of a pipe.
@ GNUNET_DISK_PIPE_END_READ
The reading-end of a pipe.
#define GNUNET_GETOPT_OPTION_END
Marker for the end of the list of options.
@ GNUNET_OK
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
#define GNUNET_strndup(a, length)
Wrapper around GNUNET_xstrndup_.
#define GNUNET_free(ptr)
Wrapper around free.
const struct GNUNET_OS_ProjectData * GNUNET_OS_project_data_gnunet(void)
Return default project data used by 'libgnunetutil' for GNUnet.
enum GNUNET_GenericReturnValue GNUNET_process_run_command_va(struct GNUNET_Process *p, const char *filename,...)
Set the command and start a process.
Definition os_process.c:903
enum GNUNET_GenericReturnValue GNUNET_process_wait(struct GNUNET_Process *proc, bool blocking, enum GNUNET_OS_ProcessStatusType *type, unsigned long *code)
Wait for a process to terminate.
void GNUNET_process_destroy(struct GNUNET_Process *proc)
Cleans up process structure contents (OS-dependent) and deallocates it.
Definition os_process.c:363
GNUNET_OS_ProcessStatusType
Process status types.
enum GNUNET_GenericReturnValue GNUNET_process_kill(struct GNUNET_Process *proc, int sig)
Sends a signal to the process.
Definition os_process.c:307
struct GNUNET_Process * GNUNET_process_create(enum GNUNET_OS_InheritStdioFlags std_inheritance)
Create a process handle.
Definition os_process.c:462
@ GNUNET_OS_INHERIT_STD_NONE
No standard streams should be inherited.
@ GNUNET_OS_PROCESS_EXITED
The process exited with a return code.
enum GNUNET_GenericReturnValue GNUNET_PROGRAM_run(const struct GNUNET_OS_ProjectData *pd, int argc, char *const *argv, const char *binaryName, const char *binaryHelp, const struct GNUNET_GETOPT_CommandLineOption *options, GNUNET_PROGRAM_Main task, void *task_cls)
Run a standard GNUnet command startup sequence (initialize loggers and configuration,...
Definition program.c:407
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_read_file(struct GNUNET_TIME_Relative delay, const struct GNUNET_DISK_FileHandle *rfd, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when the specified file descriptor is ready f...
Definition scheduler.c:1667
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition scheduler.c:986
struct GNUNET_SIGNAL_Context * GNUNET_SIGNAL_handler_install(int signal, GNUNET_SIGNAL_Handler handler)
Install a signal handler that will be run if the given signal is received.
Definition signal.c:52
void GNUNET_SIGNAL_handler_uninstall(struct GNUNET_SIGNAL_Context *ctx)
Uninstall a previously installed signal handler.
Definition signal.c:78
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
#define _(String)
GNU gettext support macro.
Definition platform.h:179
#define GNUNET_SIGCHLD
Definition platform.h:42
#define GNUNET_TERM_SIG
The termination signal.
Definition platform.h:235
Handle used to manage a pipe.
Definition disk.c:69
Definition of a command line option.
Entry in list of pending tasks.
Definition scheduler.c:141