GNUnet  0.19.3
getopt_helpers.c File Reference

implements command line that sets option More...

#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 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...
 

Detailed Description

implements command line that sets option

Author
Christian Grothoff

Definition in file getopt_helpers.c.

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 77 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 1 of file getopt_helpers.c.

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

◆ 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 1 of file getopt_helpers.c.

93 {
94  const char *about = scls;
95  size_t slen;
96  unsigned int i;
97  int j;
98  size_t ml;
99  size_t p;
100  char *scp;
101  const char *trans;
102  const struct GNUNET_GETOPT_CommandLineOption *opt;
103  const struct GNUNET_OS_ProjectData *pd;
104 
105  (void) option;
106  (void) value;
107  if (NULL != about)
108  {
109  printf ("%s\n%s\n", ctx->binaryOptions, gettext (about));
110  printf (_ (
111  "Arguments mandatory for long options are also mandatory for short options.\n"));
112  }
113  i = 0;
114  opt = ctx->allOptions;
115  while (NULL != opt[i].description)
116  {
117  if (opt[i].shortName == '\0')
118  printf (" ");
119  else
120  printf (" -%c, ", opt[i].shortName);
121  printf ("--%s", opt[i].name);
122  slen = 8 + strlen (opt[i].name);
123  if (NULL != opt[i].argumentHelp)
124  {
125  printf ("=%s", opt[i].argumentHelp);
126  slen += 1 + strlen (opt[i].argumentHelp);
127  }
128  if (slen > BORDER)
129  {
130  printf ("\n%*s", BORDER, "");
131  slen = BORDER;
132  }
133  if (slen < BORDER)
134  {
135  printf ("%*s", (int) (BORDER - slen), "");
136  slen = BORDER;
137  }
138  if (0 < strlen (opt[i].description))
139  trans = gettext (opt[i].description);
140  else
141  trans = "";
142  ml = strlen (trans);
143  p = 0;
144 OUTER:
145  while (ml - p > 78 - slen)
146  {
147  for (j = p + 78 - slen; j > (int) p; j--)
148  {
149  if (isspace ((unsigned char) trans[j]))
150  {
151  scp = GNUNET_malloc (j - p + 1);
152  GNUNET_memcpy (scp, &trans[p], j - p);
153  scp[j - p] = '\0';
154  printf ("%s\n%*s", scp, BORDER + 2, "");
155  GNUNET_free (scp);
156  p = j + 1;
157  slen = BORDER + 2;
158  goto OUTER;
159  }
160  }
161  /* could not find space to break line */
162  scp = GNUNET_malloc (78 - slen + 1);
163  GNUNET_memcpy (scp, &trans[p], 78 - slen);
164  scp[78 - slen] = '\0';
165  printf ("%s\n%*s", scp, BORDER + 2, "");
166  GNUNET_free (scp);
167  slen = BORDER + 2;
168  p = p + 78 - slen;
169  }
170  /* print rest */
171  if (p < ml)
172  printf ("%s\n", &trans[p]);
173  if (strlen (trans) == 0)
174  printf ("\n");
175  i++;
176  }
178  printf ("\n"
179  "Report bugs to %s.\n"
180  "Home page: %s\n",
181  pd->bug_email,
182  pd->homepage);
183 
184  if (0 != pd->is_gnu)
185  printf ("General help using GNU software: http://www.gnu.org/gethelp/\n");
186 
187  return GNUNET_NO;
188 }
#define BORDER
At what offset does the help text start?
#define gettext(Msgid)
Definition: gettext.h:46
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.
const struct GNUNET_OS_ProjectData * GNUNET_OS_project_data_get(void)
#define _(String)
GNU gettext support macro.
Definition: platform.h:177
const char * name
Definition of a command line 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.

◆ 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 1 of file getopt_helpers.c.

227 {
228  unsigned int *val = scls;
229 
230  (void) ctx;
231  (void) option;
232  (void) value;
233  (*val)++;
234  return GNUNET_OK;
235 }
@ GNUNET_OK

◆ 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 1 of file getopt_helpers.c.

291 {
292  int *val = scls;
293 
294  (void) ctx;
295  (void) option;
296  (void) value;
297  *val = 1;
298  return GNUNET_OK;
299 }

◆ 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 1 of file getopt_helpers.c.

339 {
340  char **val = scls;
341 
342  (void) ctx;
343  (void) option;
344  GNUNET_assert (NULL != value);
345  GNUNET_free (*val);
346  *val = GNUNET_strdup (value);
347  return GNUNET_OK;
348 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.

◆ 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 1 of file getopt_helpers.c.

405 {
406  char **val = scls;
407 
408  (void) ctx;
409  (void) option;
410  GNUNET_assert (NULL != value);
411  GNUNET_free (*val);
413  return GNUNET_OK;
414 }
char * GNUNET_STRINGS_filename_expand(const char *fil)
Complete filename (a la shell) from abbrevition.
Definition: strings.c:494

◆ 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 1 of file getopt_helpers.c.

491 {
492  unsigned long long *val = scls;
493  char dummy[2];
494 
495  (void) ctx;
496  if (1 != sscanf (value, "%llu%1s", val, dummy))
497  {
498  fprintf (stderr,
499  _ ("You must pass a number to the `%s' option.\n"),
500  option);
501  return GNUNET_SYSERR;
502  }
503  return GNUNET_OK;
504 }
static struct in_addr dummy
Target "dummy" address of the packet we pretend to respond to.
@ GNUNET_SYSERR

◆ 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 1 of file getopt_helpers.c.

546 {
547  long long delta;
548  long long minus;
549  struct GNUNET_TIME_Relative rt;
550 
551  (void) scls;
552  (void) ctx;
553  while (isspace (value[0]))
554  value++;
555  minus = 1;
556  if (value[0] == '-')
557  {
558  minus = -1;
559  value++;
560  }
561  else if (value[0] == '+')
562  {
563  value++;
564  }
565  if (GNUNET_OK !=
567  &rt))
568  {
569  fprintf (stderr,
570  _ (
571  "You must pass a relative time (optionally with sign) to the `%s' option.\n"),
572  option);
573  return GNUNET_SYSERR;
574  }
575  if (rt.rel_value_us > LLONG_MAX)
576  {
577  fprintf (stderr,
578  _ ("Value given for time travel `%s' option is too big.\n"),
579  option);
580  return GNUNET_SYSERR;
581  }
582  delta = (long long) rt.rel_value_us;
583  delta *= minus;
585  return GNUNET_OK;
586 }
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:260
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.

◆ 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 1 of file getopt_helpers.c.

625 {
626  struct GNUNET_TIME_Relative *val = scls;
627 
628  (void) ctx;
630  {
631  fprintf (stderr,
632  _ ("You must pass relative time to the `%s' option.\n"),
633  option);
634  return GNUNET_SYSERR;
635  }
636  return GNUNET_OK;
637 }

◆ 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 1 of file getopt_helpers.c.

679 {
680  struct GNUNET_TIME_Absolute *val = scls;
681 
682  (void) ctx;
684  {
685  fprintf (stderr,
686  _ ("You must pass absolute time to the `%s' option.\n"),
687  option);
688  return GNUNET_SYSERR;
689  }
690  return GNUNET_OK;
691 }
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:302
Time for absolute times used by GNUnet, in microseconds.

◆ 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 1 of file getopt_helpers.c.

733 {
734  struct GNUNET_TIME_Timestamp *t = scls;
735  struct GNUNET_TIME_Absolute abs;
736 
737  (void) ctx;
738  if (GNUNET_OK !=
740  &abs))
741  {
742  fprintf (stderr,
743  _ ("You must pass a timestamp to the `%s' option.\n"),
744  option);
745  return GNUNET_SYSERR;
746  }
747  if (0 != abs.abs_value_us % GNUNET_TIME_UNIT_SECONDS.rel_value_us)
748  {
749  fprintf (stderr,
750  _ ("The maximum precision allowed for timestamps is seconds.\n"));
751  return GNUNET_SYSERR;
752  }
753  t->abs_time = abs;
754  return GNUNET_OK;
755 }
static struct GNUNET_SCHEDULER_Task * t
Main task.
#define GNUNET_TIME_UNIT_SECONDS
One second.
Rounded time for timestamps used by GNUnet, in seconds.

◆ 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 1 of file getopt_helpers.c.

797 {
798  unsigned int *val = scls;
799  char dummy[2];
800 
801  (void) ctx;
802  if ('-' == *value)
803  {
804  fprintf (stderr,
805  _ (
806  "Your input for the '%s' option has to be a non negative number\n"),
807  option);
808  return GNUNET_SYSERR;
809  }
810  if (1 != sscanf (value, "%u%1s", val, dummy))
811  {
812  fprintf (stderr,
813  _ ("You must pass a number to the `%s' option.\n"),
814  option);
815  return GNUNET_SYSERR;
816  }
817  return GNUNET_OK;
818 }

◆ 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 1 of file getopt_helpers.c.

860 {
861  uint16_t *val = scls;
862  unsigned int v;
863  char dummy[2];
864 
865  (void) ctx;
866  if (1 != sscanf (value, "%u%1s", &v, dummy))
867  {
868  fprintf (stderr,
869  _ ("You must pass a number to the `%s' option.\n"),
870  option);
871  return GNUNET_SYSERR;
872  }
873  if (v > UINT16_MAX)
874  {
875  fprintf (stderr,
876  _ ("You must pass a number below %u to the `%s' option.\n"),
877  (unsigned int) UINT16_MAX,
878  option);
879  return GNUNET_SYSERR;
880  }
881  *val = (uint16_t) v;
882  return GNUNET_OK;
883 }

◆ 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 1 of file getopt_helpers.c.

942 {
943  struct Base32Context *bc = scls;
944 
945  (void) ctx;
947  strlen (value),
948  bc->val,
949  bc->val_size))
950  {
951  fprintf (
952  stderr,
953  _ (
954  "Argument `%s' malformed. Expected base32 (Crockford) encoded value.\n"),
955  option);
956  return GNUNET_SYSERR;
957  }
958  return GNUNET_OK;
959 }
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:788
Closure for set_base32().
void * val
Value to initialize (already allocated)
size_t val_size
Number of bytes expected for val.

◆ 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 969 of file getopt_helpers.c.

970 {
971  GNUNET_free (cls);
972 }

References GNUNET_free.