GNUnet 0.22.2
getopt_helpers.c File Reference
#include "platform.h"
#include "gnunet_util_lib.h"
Include dependency graph for getopt_helpers.c:

Go to the source code of this file.

Data Structures

struct  Base32Context
 Closure for set_base32(). More...
 

Macros

#define LOG(kind, ...)   GNUNET_log_from (kind, "util-getopt", __VA_ARGS__)
 
#define BORDER   29
 At what offset does the help text start? More...
 

Functions

static enum GNUNET_GenericReturnValue print_version (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, void *scls, const char *option, const char *value)
 Print out program version (implements –version). More...
 
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_version (const char *version)
 Define the option to print the version of the application (-v option) More...
 
static enum GNUNET_GenericReturnValue format_help (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, void *scls, const char *option, const char *value)
 Print out details on command line options (implements –help). More...
 
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_help (const struct GNUNET_OS_ProjectData *pd, const char *about)
 Defining the option to print the command line help text (-h option). More...
 
static enum GNUNET_GenericReturnValue increment_value (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, void *scls, const char *option, const char *value)
 Set an option of type 'unsigned int' from the command line. More...
 
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_increment_uint (char shortName, const char *name, const char *description, unsigned int *val)
 Increment val each time the option flag is given by one. More...
 
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_verbose (unsigned int *level)
 Define the '-V' verbosity option. More...
 
static enum GNUNET_GenericReturnValue set_one (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, void *scls, const char *option, const char *value)
 Set an option of type 'int' from the command line to 1 if the given option is present. More...
 
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_flag (char shortName, const char *name, const char *description, int *val)
 Allow user to specify a flag (which internally means setting an integer to 1/GNUNET_YES/GNUNET_OK. More...
 
static enum GNUNET_GenericReturnValue set_string (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, void *scls, const char *option, const char *value)
 Set an option of type 'char *' from the command line. More...
 
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_string (char shortName, const char *name, const char *argumentHelp, const char *description, char **str)
 Allow user to specify a string. More...
 
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_loglevel (char **level)
 Define the '-L' log level option. More...
 
static enum GNUNET_GenericReturnValue set_filename (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, void *scls, const char *option, const char *value)
 Set an option of type 'char *' from the command line with filename expansion a la GNUNET_STRINGS_filename_expand(). More...
 
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_filename (char shortName, const char *name, const char *argumentHelp, const char *description, char **str)
 Allow user to specify a filename (automatically path expanded). More...
 
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_logfile (char **logfn)
 Allow user to specify log file name (-l option) More...
 
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_cfgfile (char **fn)
 Allow user to specify configuration file name (-c option) More...
 
static enum GNUNET_GenericReturnValue set_ulong (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, void *scls, const char *option, const char *value)
 Set an option of type 'unsigned long long' from the command line. More...
 
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_ulong (char shortName, const char *name, const char *argumentHelp, const char *description, unsigned long long *val)
 Allow user to specify an unsigned long long. More...
 
static enum GNUNET_GenericReturnValue set_timetravel_time (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, void *scls, const char *option, const char *value)
 Set an option of type 'struct GNUNET_TIME_Relative' from the command line. More...
 
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_timetravel (char shortName, const char *name)
 Allow user to specify a long long with an offset to add to the current system time to construct the time seen by the application. More...
 
static enum GNUNET_GenericReturnValue set_relative_time (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, void *scls, const char *option, const char *value)
 Set an option of type 'struct GNUNET_TIME_Relative' from the command line. More...
 
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_relative_time (char shortName, const char *name, const char *argumentHelp, const char *description, struct GNUNET_TIME_Relative *val)
 Allow user to specify a struct GNUNET_TIME_Relative (using human-readable "fancy" time). More...
 
static enum GNUNET_GenericReturnValue set_absolute_time (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, void *scls, const char *option, const char *value)
 Set an option of type 'struct GNUNET_TIME_Absolute' from the command line. More...
 
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_absolute_time (char shortName, const char *name, const char *argumentHelp, const char *description, struct GNUNET_TIME_Absolute *val)
 Allow user to specify a struct GNUNET_TIME_Absolute (using human-readable "fancy" time). More...
 
static enum GNUNET_GenericReturnValue set_timestamp (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, void *scls, const char *option, const char *value)
 Set an option of type 'struct GNUNET_TIME_Timestamp' from the command line. More...
 
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_timestamp (char shortName, const char *name, const char *argumentHelp, const char *description, struct GNUNET_TIME_Timestamp *val)
 Allow user to specify a struct GNUNET_TIME_Timestamp (using human-readable "fancy" time). More...
 
static enum GNUNET_GenericReturnValue set_uint (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, void *scls, const char *option, const char *value)
 Set an option of type 'unsigned int' from the command line. More...
 
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_uint (char shortName, const char *name, const char *argumentHelp, const char *description, unsigned int *val)
 Allow user to specify an unsigned int. More...
 
static enum GNUNET_GenericReturnValue set_uint16 (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, void *scls, const char *option, const char *value)
 Set an option of type 'uint16_t' from the command line. More...
 
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_uint16 (char shortName, const char *name, const char *argumentHelp, const char *description, uint16_t *val)
 Allow user to specify an uint16_t. More...
 
static enum GNUNET_GenericReturnValue set_base32 (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, void *scls, const char *option, const char *value)
 Set an option of type 'unsigned int' from the command line. More...
 
static void free_bc (void *cls)
 Helper function to clean up after GNUNET_GETOPT_option_base32_fixed_size. More...
 
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_base32_fixed_size (char shortName, const char *name, const char *argumentHelp, const char *description, void *val, size_t val_size)
 Allow user to specify a binary value using Crockford Base32 encoding. More...
 
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_mandatory (struct GNUNET_GETOPT_CommandLineOption opt)
 Make the given option mandatory. More...
 
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_exclusive (struct GNUNET_GETOPT_CommandLineOption opt)
 Make the given option mutually exclusive with other options. More...
 

Macro Definition Documentation

◆ LOG

#define LOG (   kind,
  ... 
)    GNUNET_log_from (kind, "util-getopt", __VA_ARGS__)

Definition at line 30 of file getopt_helpers.c.

◆ BORDER

#define BORDER   29

At what offset does the help text start?

Definition at line 79 of file getopt_helpers.c.

Function Documentation

◆ print_version()

static enum GNUNET_GenericReturnValue print_version ( struct GNUNET_GETOPT_CommandLineProcessorContext ctx,
void *  scls,
const char *  option,
const char *  value 
)
static

Print out program version (implements –version).

Parameters
ctxcommand line processing context
sclsadditional closure (points to version string)
optionname of the option
valuenot used (NULL)
Returns
GNUNET_NO (do not continue, not an error)

Definition at line 43 of file getopt_helpers.c.

47{
48 const char *version = scls;
49
50 (void) option;
51 (void) value;
52 printf ("%s v%s\n",
53 ctx->binaryName,
54 version);
55 return GNUNET_NO;
56}
static struct GNUNET_FS_Handle * ctx
static char * value
Value of the record to add/remove.
@ GNUNET_NO

References ctx, GNUNET_NO, and value.

Referenced by GNUNET_GETOPT_option_version().

Here is the caller graph for this function:

◆ format_help()

static enum GNUNET_GenericReturnValue format_help ( struct GNUNET_GETOPT_CommandLineProcessorContext ctx,
void *  scls,
const char *  option,
const char *  value 
)
static

Print out details on command line options (implements –help).

Parameters
ctxcommand line processing context
sclsadditional closure (points to about text)
optionname of the option
valuenot used (NULL)
Returns
GNUNET_NO (do not continue, not an error)

Definition at line 91 of file getopt_helpers.c.

95{
96 const struct GNUNET_OS_ProjectData *pd = scls;
97 const char *about = NULL;
98 size_t slen;
99 unsigned int i;
100 int j;
101 size_t ml;
102 size_t p;
103 char *scp;
104 const char *trans;
105 const struct GNUNET_GETOPT_CommandLineOption *opt;
106
107 (void) option;
108 (void) value;
109 opt = ctx->allOptions;
110 for (i=0; NULL != opt[i].description; i++)
111 {
112 /* we hacked the about argument into our own argumentHelp! */
113 if ('h' == opt[i].shortName)
114 about = opt[i].argumentHelp;
115 }
116 if (NULL != about)
117 {
118 printf ("%s\n%s\n",
119 ctx->binaryOptions,
120 gettext (about));
121 printf (_ (
122 "Arguments mandatory for long options are also mandatory for short options.\n"));
123 }
124 for (i=0; NULL != opt[i].description; i++)
125 {
126 if (opt[i].shortName == '\0')
127 printf (" ");
128 else
129 printf (" -%c, ", opt[i].shortName);
130 printf ("--%s", opt[i].name);
131 slen = 8 + strlen (opt[i].name);
132 if ( (NULL != opt[i].argumentHelp) &&
133 ('h' != opt[i].shortName) )
134 {
135 printf ("=%s", opt[i].argumentHelp);
136 slen += 1 + strlen (opt[i].argumentHelp);
137 }
138 if (slen > BORDER)
139 {
140 printf ("\n%*s", BORDER, "");
141 slen = BORDER;
142 }
143 if (slen < BORDER)
144 {
145 printf ("%*s", (int) (BORDER - slen), "");
146 slen = BORDER;
147 }
148 if (0 < strlen (opt[i].description))
149 trans = gettext (opt[i].description);
150 else
151 trans = "";
152 ml = strlen (trans);
153 p = 0;
154OUTER:
155 while (ml - p > 78 - slen)
156 {
157 for (j = p + 78 - slen; j > (int) p; j--)
158 {
159 if (isspace ((unsigned char) trans[j]))
160 {
161 scp = GNUNET_malloc (j - p + 1);
162 GNUNET_memcpy (scp, &trans[p], j - p);
163 scp[j - p] = '\0';
164 printf ("%s\n%*s", scp, BORDER + 2, "");
165 GNUNET_free (scp);
166 p = j + 1;
167 slen = BORDER + 2;
168 goto OUTER;
169 }
170 }
171 /* could not find space to break line */
172 scp = GNUNET_malloc (78 - slen + 1);
173 GNUNET_memcpy (scp, &trans[p], 78 - slen);
174 scp[78 - slen] = '\0';
175 printf ("%s\n%*s", scp, BORDER + 2, "");
176 GNUNET_free (scp);
177 slen = BORDER + 2;
178 p = p + 78 - slen;
179 }
180 /* print rest */
181 if (p < ml)
182 printf ("%s\n", &trans[p]);
183 if (strlen (trans) == 0)
184 printf ("\n");
185 }
186 printf ("\n"
187 "Report bugs to %s.\n"
188 "Home page: %s\n",
189 pd->bug_email,
190 pd->homepage);
191
192 if (0 != pd->is_gnu)
193 printf ("General help using GNU software: http://www.gnu.org/gethelp/\n");
194
195 return GNUNET_NO;
196}
#define BORDER
At what offset does the help text start?
#define gettext(Msgid)
Definition: gettext.h:50
static char * name
Name (label) of the records to list.
static struct GNUNET_OS_Process * p
Helper process we started.
Definition: gnunet-uri.c:38
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
#define _(String)
GNU gettext support macro.
Definition: platform.h:178
Definition of a command line option.
const char * description
Help text for the option (description)
const char * argumentHelp
Name of the argument for the user in help text.
const char shortName
Short name of the option.
Project-specific data used to help the OS subsystem find installation paths.
const char * bug_email
E-mail address for reporting bugs.
int is_gnu
Non-zero means this project is part of GNU.
const char * homepage
Project homepage.

References _, GNUNET_GETOPT_CommandLineOption::argumentHelp, BORDER, GNUNET_OS_ProjectData::bug_email, ctx, GNUNET_GETOPT_CommandLineOption::description, gettext, GNUNET_free, GNUNET_malloc, GNUNET_memcpy, GNUNET_NO, GNUNET_OS_ProjectData::homepage, consensus-simulation::int, GNUNET_OS_ProjectData::is_gnu, name, p, GNUNET_GETOPT_CommandLineOption::shortName, and value.

Referenced by GNUNET_GETOPT_option_help().

Here is the caller graph for this function:

◆ increment_value()

static enum GNUNET_GenericReturnValue increment_value ( struct GNUNET_GETOPT_CommandLineProcessorContext ctx,
void *  scls,
const char *  option,
const char *  value 
)
static

Set an option of type 'unsigned int' from the command line.

Each time the option flag is given, the value is incremented by one. A pointer to this function should be passed as part of the 'struct GNUNET_GETOPT_CommandLineOption' array to initialize options of this type. It should be followed by a pointer to a value of type 'int'.

Parameters
ctxcommand line processing context
sclsadditional closure (will point to the 'unsigned int')
optionname of the option
valuenot used (NULL)
Returns
GNUNET_OK

Definition at line 233 of file getopt_helpers.c.

237{
238 unsigned int *val = scls;
239
240 (void) ctx;
241 (void) option;
242 (void) value;
243 (*val)++;
244 return GNUNET_OK;
245}
@ GNUNET_OK

References ctx, GNUNET_OK, GNUNET_GETOPT_CommandLineOption::scls, and value.

Referenced by GNUNET_GETOPT_option_increment_uint(), and GNUNET_GETOPT_option_verbose().

Here is the caller graph for this function:

◆ set_one()

static enum GNUNET_GenericReturnValue set_one ( struct GNUNET_GETOPT_CommandLineProcessorContext ctx,
void *  scls,
const char *  option,
const char *  value 
)
static

Set an option of type 'int' from the command line to 1 if the given option is present.

A pointer to this function should be passed as part of the 'struct GNUNET_GETOPT_CommandLineOption' array to initialize options of this type. It should be followed by a pointer to a value of type 'int'.

Parameters
ctxcommand line processing context
sclsadditional closure (will point to the 'int')
optionname of the option
valuenot used (NULL)
Returns
GNUNET_OK

Definition at line 297 of file getopt_helpers.c.

301{
302 int *val = scls;
303
304 (void) ctx;
305 (void) option;
306 (void) value;
307 *val = 1;
308 return GNUNET_OK;
309}

References ctx, GNUNET_OK, GNUNET_GETOPT_CommandLineOption::scls, and value.

Referenced by GNUNET_GETOPT_option_flag().

Here is the caller graph for this function:

◆ set_string()

static enum GNUNET_GenericReturnValue set_string ( struct GNUNET_GETOPT_CommandLineProcessorContext ctx,
void *  scls,
const char *  option,
const char *  value 
)
static

Set an option of type 'char *' from the command line.

A pointer to this function should be passed as part of the 'struct GNUNET_GETOPT_CommandLineOption' array to initialize options of this type. It should be followed by a pointer to a value of type 'char *', which will be allocated with the requested string.

Parameters
ctxcommand line processing context
sclsadditional closure (will point to the 'char *', which will be allocated)
optionname of the option
valueactual value of the option (a string)
Returns
GNUNET_OK

Definition at line 345 of file getopt_helpers.c.

349{
350 char **val = scls;
351
352 (void) ctx;
353 (void) option;
354 GNUNET_assert (NULL != value);
355 GNUNET_free (*val);
356 *val = GNUNET_strdup (value);
357 return GNUNET_OK;
358}
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.

References ctx, GNUNET_assert, GNUNET_free, GNUNET_OK, GNUNET_strdup, GNUNET_GETOPT_CommandLineOption::scls, and value.

Referenced by GNUNET_GETOPT_option_loglevel(), and GNUNET_GETOPT_option_string().

Here is the caller graph for this function:

◆ set_filename()

static enum GNUNET_GenericReturnValue set_filename ( struct GNUNET_GETOPT_CommandLineProcessorContext ctx,
void *  scls,
const char *  option,
const char *  value 
)
static

Set an option of type 'char *' from the command line with filename expansion a la GNUNET_STRINGS_filename_expand().

Parameters
ctxcommand line processing context
sclsadditional closure (will point to the char *, which will be allocated)
optionname of the option
valueactual value of the option (a string)
Returns
GNUNET_OK

Definition at line 411 of file getopt_helpers.c.

415{
416 char **val = scls;
417
418 (void) ctx;
419 (void) option;
420 GNUNET_assert (NULL != value);
421 GNUNET_free (*val);
423 return GNUNET_OK;
424}
char * GNUNET_STRINGS_filename_expand(const char *fil)
Complete filename (a la shell) from abbrevition.
Definition: strings.c:504

References ctx, GNUNET_assert, GNUNET_free, GNUNET_OK, GNUNET_STRINGS_filename_expand(), GNUNET_GETOPT_CommandLineOption::scls, and value.

Referenced by GNUNET_GETOPT_option_cfgfile(), GNUNET_GETOPT_option_filename(), and GNUNET_GETOPT_option_logfile().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_ulong()

static enum GNUNET_GenericReturnValue set_ulong ( struct GNUNET_GETOPT_CommandLineProcessorContext ctx,
void *  scls,
const char *  option,
const char *  value 
)
static

Set an option of type 'unsigned long long' from the command line.

A pointer to this function should be passed as part of the 'struct GNUNET_GETOPT_CommandLineOption' array to initialize options of this type. It should be followed by a pointer to a value of type 'unsigned long long'.

Parameters
ctxcommand line processing context
sclsadditional closure (will point to the 'unsigned long long')
optionname of the option
valueactual value of the option as a string.
Returns
GNUNET_OK if parsing the value worked

Definition at line 497 of file getopt_helpers.c.

501{
502 unsigned long long *val = scls;
503 char dummy[2];
504
505 (void) ctx;
506 if (1 != sscanf (value, "%llu%1s", val, dummy))
507 {
508 fprintf (stderr,
509 _ ("You must pass a number to the `%s' option.\n"),
510 option);
511 return GNUNET_SYSERR;
512 }
513 return GNUNET_OK;
514}
static struct in_addr dummy
Target "dummy" address of the packet we pretend to respond to.
@ GNUNET_SYSERR

References _, ctx, dummy, GNUNET_OK, GNUNET_SYSERR, GNUNET_GETOPT_CommandLineOption::scls, and value.

Referenced by GNUNET_GETOPT_option_ulong().

Here is the caller graph for this function:

◆ set_timetravel_time()

static enum GNUNET_GenericReturnValue set_timetravel_time ( struct GNUNET_GETOPT_CommandLineProcessorContext ctx,
void *  scls,
const char *  option,
const char *  value 
)
static

Set an option of type 'struct GNUNET_TIME_Relative' from the command line.

A pointer to this function should be passed as part of the 'struct GNUNET_GETOPT_CommandLineOption' array to initialize options of this type. It should be followed by a pointer to a value of type 'struct GNUNET_TIME_Relative'.

Parameters
ctxcommand line processing context
sclsadditional closure (will point to the 'struct GNUNET_TIME_Relative')
optionname of the option
valueactual value of the option as a string.
Returns
GNUNET_OK if parsing the value worked

Definition at line 552 of file getopt_helpers.c.

556{
557 long long delta;
558 long long minus;
559 struct GNUNET_TIME_Relative rt;
560
561 (void) scls;
562 (void) ctx;
563 while (isspace (value[0]))
564 value++;
565 minus = 1;
566 if (value[0] == '-')
567 {
568 minus = -1;
569 value++;
570 }
571 else if (value[0] == '+')
572 {
573 value++;
574 }
575 if (GNUNET_OK !=
577 &rt))
578 {
579 fprintf (stderr,
580 _ (
581 "You must pass a relative time (optionally with sign) to the `%s' option.\n"),
582 option);
583 return GNUNET_SYSERR;
584 }
585 if (rt.rel_value_us > LLONG_MAX)
586 {
587 fprintf (stderr,
588 _ ("Value given for time travel `%s' option is too big.\n"),
589 option);
590 return GNUNET_SYSERR;
591 }
592 delta = (long long) rt.rel_value_us;
593 delta *= minus;
595 return GNUNET_OK;
596}
enum GNUNET_GenericReturnValue GNUNET_STRINGS_fancy_time_to_relative(const char *fancy_time, struct GNUNET_TIME_Relative *rtime)
Convert a given fancy human-readable time to our internal representation.
Definition: strings.c:259
void GNUNET_TIME_set_offset(long long offset)
Set the timestamp offset for this instance.
Definition: time.c:49
static struct GNUNET_TIME_Relative delta
Definition: speedup.c:36
Time for relative time used by GNUnet, in microseconds.
uint64_t rel_value_us
The actual value.

References _, ctx, delta, GNUNET_OK, GNUNET_STRINGS_fancy_time_to_relative(), GNUNET_SYSERR, GNUNET_TIME_set_offset(), GNUNET_TIME_Relative::rel_value_us, and value.

Referenced by GNUNET_GETOPT_option_timetravel().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_relative_time()

static enum GNUNET_GenericReturnValue set_relative_time ( struct GNUNET_GETOPT_CommandLineProcessorContext ctx,
void *  scls,
const char *  option,
const char *  value 
)
static

Set an option of type 'struct GNUNET_TIME_Relative' from the command line.

A pointer to this function should be passed as part of the 'struct GNUNET_GETOPT_CommandLineOption' array to initialize options of this type. It should be followed by a pointer to a value of type 'struct GNUNET_TIME_Relative'.

Parameters
ctxcommand line processing context
sclsadditional closure (will point to the 'struct GNUNET_TIME_Relative')
optionname of the option
valueactual value of the option as a string.
Returns
GNUNET_OK if parsing the value worked

Definition at line 631 of file getopt_helpers.c.

635{
636 struct GNUNET_TIME_Relative *val = scls;
637
638 (void) ctx;
640 {
641 fprintf (stderr,
642 _ ("You must pass relative time to the `%s' option.\n"),
643 option);
644 return GNUNET_SYSERR;
645 }
646 return GNUNET_OK;
647}

References _, ctx, GNUNET_OK, GNUNET_STRINGS_fancy_time_to_relative(), GNUNET_SYSERR, and value.

Referenced by GNUNET_GETOPT_option_relative_time().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_absolute_time()

static enum GNUNET_GenericReturnValue set_absolute_time ( struct GNUNET_GETOPT_CommandLineProcessorContext ctx,
void *  scls,
const char *  option,
const char *  value 
)
static

Set an option of type 'struct GNUNET_TIME_Absolute' from the command line.

A pointer to this function should be passed as part of the 'struct GNUNET_GETOPT_CommandLineOption' array to initialize options of this type. It should be followed by a pointer to a value of type 'struct GNUNET_TIME_Absolute'.

Parameters
ctxcommand line processing context
sclsadditional closure (will point to the struct GNUNET_TIME_Absolute)
optionname of the option
valueactual value of the option as a string.
Returns
GNUNET_OK if parsing the value worked

Definition at line 685 of file getopt_helpers.c.

689{
690 struct GNUNET_TIME_Absolute *val = scls;
691
692 (void) ctx;
694 {
695 fprintf (stderr,
696 _ ("You must pass absolute time to the `%s' option.\n"),
697 option);
698 return GNUNET_SYSERR;
699 }
700 return GNUNET_OK;
701}
enum GNUNET_GenericReturnValue GNUNET_STRINGS_fancy_time_to_absolute(const char *fancy_time, struct GNUNET_TIME_Absolute *atime)
Convert a given fancy human-readable time to our internal representation.
Definition: strings.c:301
Time for absolute times used by GNUnet, in microseconds.

References _, ctx, GNUNET_OK, GNUNET_STRINGS_fancy_time_to_absolute(), GNUNET_SYSERR, and value.

Referenced by GNUNET_GETOPT_option_absolute_time().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_timestamp()

static enum GNUNET_GenericReturnValue set_timestamp ( struct GNUNET_GETOPT_CommandLineProcessorContext ctx,
void *  scls,
const char *  option,
const char *  value 
)
static

Set an option of type 'struct GNUNET_TIME_Timestamp' from the command line.

A pointer to this function should be passed as part of the 'struct GNUNET_GETOPT_CommandLineOption' array to initialize options of this type. It should be followed by a pointer to a value of type 'struct GNUNET_TIME_Absolute'.

Parameters
ctxcommand line processing context
sclsadditional closure (will point to the struct GNUNET_TIME_Absolute)
optionname of the option
valueactual value of the option as a string.
Returns
GNUNET_OK if parsing the value worked

Definition at line 739 of file getopt_helpers.c.

743{
744 struct GNUNET_TIME_Timestamp *t = scls;
745 struct GNUNET_TIME_Absolute abs;
746
747 (void) ctx;
748 if (GNUNET_OK !=
750 &abs))
751 {
752 fprintf (stderr,
753 _ ("You must pass a timestamp to the `%s' option.\n"),
754 option);
755 return GNUNET_SYSERR;
756 }
757 if (0 != abs.abs_value_us % GNUNET_TIME_UNIT_SECONDS.rel_value_us)
758 {
759 fprintf (stderr,
760 _ ("The maximum precision allowed for timestamps is seconds.\n"));
761 return GNUNET_SYSERR;
762 }
763 t->abs_time = abs;
764 return GNUNET_OK;
765}
static struct GNUNET_SCHEDULER_Task * t
Main task.
#define GNUNET_TIME_UNIT_SECONDS
One second.
Time for timestamps used by GNUnet, in microseconds rounded to seconds.

References _, GNUNET_TIME_Absolute::abs_value_us, ctx, GNUNET_OK, GNUNET_STRINGS_fancy_time_to_absolute(), GNUNET_SYSERR, GNUNET_TIME_UNIT_SECONDS, t, and value.

Referenced by GNUNET_GETOPT_option_timestamp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_uint()

static enum GNUNET_GenericReturnValue set_uint ( struct GNUNET_GETOPT_CommandLineProcessorContext ctx,
void *  scls,
const char *  option,
const char *  value 
)
static

Set an option of type 'unsigned int' from the command line.

A pointer to this function should be passed as part of the 'struct GNUNET_GETOPT_CommandLineOption' array to initialize options of this type. It should be followed by a pointer to a value of type 'unsigned int'.

Parameters
ctxcommand line processing context
sclsadditional closure (will point to the 'unsigned int')
optionname of the option
valueactual value of the option as a string.
Returns
GNUNET_OK if parsing the value worked

Definition at line 803 of file getopt_helpers.c.

807{
808 unsigned int *val = scls;
809 char dummy[2];
810
811 (void) ctx;
812 if ('-' == *value)
813 {
814 fprintf (stderr,
815 _ (
816 "Your input for the '%s' option has to be a non negative number\n"),
817 option);
818 return GNUNET_SYSERR;
819 }
820 if (1 != sscanf (value, "%u%1s", val, dummy))
821 {
822 fprintf (stderr,
823 _ ("You must pass a number to the `%s' option.\n"),
824 option);
825 return GNUNET_SYSERR;
826 }
827 return GNUNET_OK;
828}

References _, ctx, dummy, GNUNET_OK, GNUNET_SYSERR, GNUNET_GETOPT_CommandLineOption::scls, and value.

Referenced by GNUNET_GETOPT_option_uint().

Here is the caller graph for this function:

◆ set_uint16()

static enum GNUNET_GenericReturnValue set_uint16 ( struct GNUNET_GETOPT_CommandLineProcessorContext ctx,
void *  scls,
const char *  option,
const char *  value 
)
static

Set an option of type 'uint16_t' from the command line.

A pointer to this function should be passed as part of the 'struct GNUNET_GETOPT_CommandLineOption' array to initialize options of this type. It should be followed by a pointer to a value of type 'uint16_t'.

Parameters
ctxcommand line processing context
sclsadditional closure (will point to the 'unsigned int')
optionname of the option
valueactual value of the option as a string.
Returns
GNUNET_OK if parsing the value worked

Definition at line 866 of file getopt_helpers.c.

870{
871 uint16_t *val = scls;
872 unsigned int v;
873 char dummy[2];
874
875 (void) ctx;
876 if (1 != sscanf (value, "%u%1s", &v, dummy))
877 {
878 fprintf (stderr,
879 _ ("You must pass a number to the `%s' option.\n"),
880 option);
881 return GNUNET_SYSERR;
882 }
883 if (v > UINT16_MAX)
884 {
885 fprintf (stderr,
886 _ ("You must pass a number below %u to the `%s' option.\n"),
887 (unsigned int) UINT16_MAX,
888 option);
889 return GNUNET_SYSERR;
890 }
891 *val = (uint16_t) v;
892 return GNUNET_OK;
893}

References _, ctx, dummy, GNUNET_OK, GNUNET_SYSERR, GNUNET_GETOPT_CommandLineOption::scls, and value.

Referenced by GNUNET_GETOPT_option_uint16().

Here is the caller graph for this function:

◆ set_base32()

static enum GNUNET_GenericReturnValue set_base32 ( struct GNUNET_GETOPT_CommandLineProcessorContext ctx,
void *  scls,
const char *  option,
const char *  value 
)
static

Set an option of type 'unsigned int' from the command line.

A pointer to this function should be passed as part of the 'struct GNUNET_GETOPT_CommandLineOption' array to initialize options of this type. It should be followed by a pointer to a value of type 'unsigned int'.

Parameters
ctxcommand line processing context
sclsadditional closure (will point to the 'unsigned int')
optionname of the option
valueactual value of the option as a string.
Returns
GNUNET_OK if parsing the value worked

Definition at line 948 of file getopt_helpers.c.

952{
953 struct Base32Context *bc = scls;
954
955 (void) ctx;
957 strlen (value),
958 bc->val,
959 bc->val_size))
960 {
961 fprintf (
962 stderr,
963 _ (
964 "Argument `%s' malformed. Expected base32 (Crockford) encoded value.\n")
965 ,
966 option);
967 return GNUNET_SYSERR;
968 }
969 return GNUNET_OK;
970}
enum GNUNET_GenericReturnValue GNUNET_STRINGS_string_to_data(const char *enc, size_t enclen, void *out, size_t out_size)
Convert CrockfordBase32 encoding back to data.
Definition: strings.c:812
Closure for set_base32().
void * val
Value to initialize (already allocated)
size_t val_size
Number of bytes expected for val.

References _, ctx, GNUNET_OK, GNUNET_STRINGS_string_to_data(), GNUNET_SYSERR, Base32Context::val, Base32Context::val_size, and value.

Referenced by GNUNET_GETOPT_option_base32_fixed_size().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ free_bc()

static void free_bc ( void *  cls)
static

Helper function to clean up after GNUNET_GETOPT_option_base32_fixed_size.

Parameters
clsvalue to GNUNET_free()

Definition at line 980 of file getopt_helpers.c.

981{
982 GNUNET_free (cls);
983}

References GNUNET_free.

Referenced by GNUNET_GETOPT_option_base32_fixed_size().

Here is the caller graph for this function: