GNUnet  0.10.x
Data Structures | Enumerations | Functions
Strings library

Strings and string handling functions, including malloc and string tokenizing. More...

Data Structures

struct  GNUNET_STRINGS_PortPolicy
 
struct  GNUNET_STRINGS_IPv4NetworkPolicy
 IPV4 network in CIDR notation. More...
 
struct  GNUNET_STRINGS_IPv6NetworkPolicy
 network in CIDR notation for IPV6. More...
 

Enumerations

enum  GNUNET_STRINGS_FilenameCheck { GNUNET_STRINGS_CHECK_EXISTS = 0x00000001, GNUNET_STRINGS_CHECK_IS_DIRECTORY = 0x00000002, GNUNET_STRINGS_CHECK_IS_LINK = 0x00000004, GNUNET_STRINGS_CHECK_IS_ABSOLUTE = 0x00000008 }
 Flags for what we should check a file for. More...
 

Functions

int GNUNET_STRINGS_fancy_size_to_bytes (const char *fancy_size, unsigned long long *size)
 Convert a given fancy human-readable size to bytes. More...
 
int 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. More...
 
char * GNUNET_STRINGS_byte_size_fancy (unsigned long long size)
 Convert a given filesize into a fancy human-readable format. More...
 
char * GNUNET_STRINGS_conv (const char *input, size_t len, const char *input_charset, const char *output_charset)
 Convert the len characters long character sequence given in input that is in the given input charset to a string in given output charset. More...
 
char * GNUNET_STRINGS_to_utf8 (const char *input, size_t len, const char *charset)
 Convert the len characters long character sequence given in input that is in the given charset to UTF-8. More...
 
char * GNUNET_STRINGS_from_utf8 (const char *input, size_t len, const char *charset)
 Convert the len bytes-long UTF-8 string given in input to the given charset. More...
 
void GNUNET_STRINGS_utf8_tolower (const char *input, char *output)
 Convert the utf-8 input string to lower case. More...
 
void GNUNET_STRINGS_utf8_toupper (const char *input, char *output)
 Convert the utf-8 input string to upper case. More...
 
char * GNUNET_STRINGS_filename_expand (const char *fil)
 Complete filename (a la shell) from abbrevition. More...
 
size_t GNUNET_STRINGS_buffer_fill (char *buffer, size_t size, unsigned int count,...)
 Fill a buffer of the given size with count 0-terminated strings (given as varargs). More...
 
unsigned int GNUNET_STRINGS_buffer_tokenize (const char *buffer, size_t size, unsigned int count,...)
 Given a buffer of a given size, find "count" 0-terminated strings in the buffer and assign the count (varargs) of type "const char**" to the locations of the respective strings in the buffer. More...
 
const char * GNUNET_STRINGS_get_short_name (const char *filename)
 "man basename" Returns a pointer to a part of filename (allocates nothing)! More...
 
char * GNUNET_STRINGS_data_to_string (const void *data, size_t size, char *out, size_t out_size)
 Convert binary data to ASCII encoding using CrockfordBase32. More...
 
char * GNUNET_STRINGS_data_to_string_alloc (const void *buf, size_t size)
 Return the base32crockford encoding of the given buffer. More...
 
int GNUNET_STRINGS_string_to_data (const char *enc, size_t enclen, void *out, size_t out_size)
 Convert CrockfordBase32 encoding back to data. More...
 
size_t GNUNET_STRINGS_base64_encode (const void *in, size_t len, char **output)
 Encode into Base64. More...
 
size_t GNUNET_STRINGS_base64_decode (const char *data, size_t len, void **output)
 Decode from Base64. More...
 
char * GNUNET_STRINGS_pp2s (const struct GNUNET_PeerIdentity *pids, unsigned int num_pids)
 Convert a peer path to a human-readable string. More...
 
int GNUNET_STRINGS_parse_uri (const char *path, char **scheme_part, const char **path_part)
 Parse a path that might be an URI. More...
 
int GNUNET_STRINGS_path_is_absolute (const char *filename, int can_be_uri, int *r_is_uri, char **r_uri_scheme)
 Check whether filename is absolute or not, and if it's an URI. More...
 
int GNUNET_STRINGS_check_filename (const char *filename, enum GNUNET_STRINGS_FilenameCheck checks)
 Perform checks on filename. More...
 
int GNUNET_STRINGS_to_address_ipv6 (const char *zt_addr, uint16_t addrlen, struct sockaddr_in6 *r_buf)
 Tries to convert zt_addr string to an IPv6 address. More...
 
int GNUNET_STRINGS_to_address_ipv4 (const char *zt_addr, uint16_t addrlen, struct sockaddr_in *r_buf)
 Tries to convert zt_addr string to an IPv4 address. More...
 
size_t GNUNET_STRINGS_parse_socket_addr (const char *addr, uint8_t *af, struct sockaddr **sa)
 Parse an address given as a string into a struct sockaddr. More...
 
int GNUNET_STRINGS_to_address_ip (const char *addr, uint16_t addrlen, struct sockaddr_storage *r_buf)
 Tries to convert addr string to an IP (v4 or v6) address. More...
 
int GNUNET_STRINGS_get_utf8_args (int argc, char *const *argv, int *u8argc, char *const **u8argv)
 Returns utf-8 encoded arguments. More...
 
size_t GNUNET_strlcpy (char *dst, const char *src, size_t n)
 Like strlcpy but portable. More...
 
struct GNUNET_STRINGS_IPv4NetworkPolicyGNUNET_STRINGS_parse_ipv4_policy (const char *routeListX)
 Parse an IPv4 network policy. More...
 
struct GNUNET_STRINGS_IPv6NetworkPolicyGNUNET_STRINGS_parse_ipv6_policy (const char *routeListX)
 Parse an IPv6 network policy. More...
 

Detailed Description

Strings and string handling functions, including malloc and string tokenizing.

Enumeration Type Documentation

◆ GNUNET_STRINGS_FilenameCheck

Flags for what we should check a file for.

Enumerator
GNUNET_STRINGS_CHECK_EXISTS 

Check that it exists.

GNUNET_STRINGS_CHECK_IS_DIRECTORY 

Check that it is a directory.

GNUNET_STRINGS_CHECK_IS_LINK 

Check that it is a link.

GNUNET_STRINGS_CHECK_IS_ABSOLUTE 

Check that the path is an absolute path.

Definition at line 422 of file gnunet_strings_lib.h.

423 {
427  GNUNET_STRINGS_CHECK_EXISTS = 0x00000001,
428 
433 
437  GNUNET_STRINGS_CHECK_IS_LINK = 0x00000004,
438 
443 };
Check that the path is an absolute path.
Check that it exists.
Check that it is a link.
Check that it is a directory.

Function Documentation

◆ GNUNET_STRINGS_fancy_size_to_bytes()

int GNUNET_STRINGS_fancy_size_to_bytes ( const char *  fancy_size,
unsigned long long *  size 
)

Convert a given fancy human-readable size to bytes.

Parameters
fancy_sizehuman readable string (i.e. 1 MB)
sizeset to the size in bytes
Returns
GNUNET_OK on success, GNUNET_SYSERR on error

Definition at line 317 of file strings.c.

References convert_with_table().

Referenced by get_quota(), GNUNET_ATS_solvers_load_quotas(), GNUNET_CONFIGURATION_get_value_size(), parse_quota(), and print_quotas().

319 {
320  static const struct ConversionTable table[] =
321  {
322  { "B", 1},
323  { "KiB", 1024},
324  { "kB", 1000},
325  { "MiB", 1024 * 1024},
326  { "MB", 1000 * 1000},
327  { "GiB", 1024 * 1024 * 1024},
328  { "GB", 1000 * 1000 * 1000},
329  { "TiB", 1024LL * 1024LL * 1024LL * 1024LL},
330  { "TB", 1000LL * 1000LL * 1000LL * 1024LL},
331  { "PiB", 1024LL * 1024LL * 1024LL * 1024LL * 1024LL},
332  { "PB", 1000LL * 1000LL * 1000LL * 1024LL * 1000LL},
333  { "EiB", 1024LL * 1024LL * 1024LL * 1024LL * 1024LL * 1024LL},
334  { "EB", 1000LL * 1000LL * 1000LL * 1024LL * 1000LL * 1000LL},
335  { NULL, 0}
336  };
337 
338  return convert_with_table (fancy_size,
339  table,
340  size);
341 }
static int convert_with_table(const char *input, const struct ConversionTable *table, unsigned long long *output)
Convert a string of the form "4 X 5 Y" into a numeric value by interpreting "X" and "Y" as units and ...
Definition: strings.c:259
static struct PeerEntry ** table
Table with our interned peer IDs.
Definition: peer.c:55
Unit conversion table entry for 'convert_with_table'.
Definition: strings.c:233
static unsigned int size
Size of the "table".
Definition: peer.c:67
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_STRINGS_fancy_time_to_relative()

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

Parameters
fancy_timehuman readable string (i.e. 1 minute)
rtimeset to the relative time
Returns
GNUNET_OK on success, GNUNET_SYSERR on error

Definition at line 353 of file strings.c.

References convert_with_table(), GNUNET_OK, GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_TIME_Relative::rel_value_us, and ret.

Referenced by get_cred_issuer_cb(), GNUNET_CONFIGURATION_get_value_time(), identity_cb(), main(), parse_expiration(), parse_record(), and set_relative_time().

355 {
356  static const struct ConversionTable table[] =
357  {
358  { "us", 1},
359  { "ms", 1000 },
360  { "s", 1000 * 1000LL },
361  { "second", 1000 * 1000LL },
362  { "seconds", 1000 * 1000LL },
363  { "\"", 1000 * 1000LL },
364  { "m", 60 * 1000 * 1000LL},
365  { "min", 60 * 1000 * 1000LL},
366  { "minute", 60 * 1000 * 1000LL},
367  { "minutes", 60 * 1000 * 1000LL},
368  { "'", 60 * 1000 * 1000LL},
369  { "h", 60 * 60 * 1000 * 1000LL},
370  { "hour", 60 * 60 * 1000 * 1000LL},
371  { "hours", 60 * 60 * 1000 * 1000LL},
372  { "d", 24 * 60 * 60 * 1000LL * 1000LL},
373  { "day", 24 * 60 * 60 * 1000LL * 1000LL},
374  { "days", 24 * 60 * 60 * 1000LL * 1000LL},
375  { "week", 7 * 24 * 60 * 60 * 1000LL * 1000LL},
376  { "weeks", 7 * 24 * 60 * 60 * 1000LL * 1000LL},
377  { "year", 31536000000000LL /* year */ },
378  { "years", 31536000000000LL /* year */ },
379  { "a", 31536000000000LL /* year */ },
380  { NULL, 0}
381  };
382  int ret;
383  unsigned long long val;
384 
385  if (0 == strcasecmp ("forever", fancy_time))
386  {
388  return GNUNET_OK;
389  }
390  ret = convert_with_table (fancy_time,
391  table,
392  &val);
393  rtime->rel_value_us = (uint64_t) val;
394  return ret;
395 }
uint64_t rel_value_us
The actual value.
static int convert_with_table(const char *input, const struct ConversionTable *table, unsigned long long *output)
Convert a string of the form "4 X 5 Y" into a numeric value by interpreting "X" and "Y" as units and ...
Definition: strings.c:259
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
static int ret
Final status code.
Definition: gnunet-arm.c:89
static struct PeerEntry ** table
Table with our interned peer IDs.
Definition: peer.c:55
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
Unit conversion table entry for 'convert_with_table'.
Definition: strings.c:233
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_STRINGS_byte_size_fancy()

char* GNUNET_STRINGS_byte_size_fancy ( unsigned long long  size)

Convert a given filesize into a fancy human-readable format.

Parameters
sizenumber of bytes
Returns
fancy representation of the size (possibly rounded) for humans

Definition at line 174 of file strings.c.

References _, GNUNET_malloc, GNUNET_snprintf(), and ret.

Referenced by progress_cb(), and publish_inspector().

175 {
176  const char *unit = _( /* size unit */ "b");
177  char *ret;
178 
179  if (size > 5 * 1024)
180  {
181  size = size / 1024;
182  unit = "KiB";
183  if (size > 5 * 1024)
184  {
185  size = size / 1024;
186  unit = "MiB";
187  if (size > 5 * 1024)
188  {
189  size = size / 1024;
190  unit = "GiB";
191  if (size > 5 * 1024)
192  {
193  size = size / 1024;
194  unit = "TiB";
195  }
196  }
197  }
198  }
199  ret = GNUNET_malloc (32);
200  GNUNET_snprintf (ret, 32, "%llu %s", size, unit);
201  return ret;
202 }
int GNUNET_snprintf(char *buf, size_t size, const char *format,...)
Like snprintf, just aborts if the buffer is of insufficient size.
static int ret
Final status code.
Definition: gnunet-arm.c:89
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
static unsigned int size
Size of the "table".
Definition: peer.c:67
#define GNUNET_malloc(size)
Wrapper around malloc.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_STRINGS_conv()

char* GNUNET_STRINGS_conv ( const char *  input,
size_t  len,
const char *  input_charset,
const char *  output_charset 
)

Convert the len characters long character sequence given in input that is in the given input charset to a string in given output charset.

Parameters
inputinput string
lennumber of bytes in input
input_charsetcharacter set used for input
output_charsetdesired character set for the return value
Returns
the converted string (0-terminated), if conversion fails, a copy of the orignal string is returned.

Definition at line 454 of file strings.c.

References _, GNUNET_ERROR_TYPE_WARNING, GNUNET_malloc, GNUNET_memcpy, len, LOG, LOG_STRERROR, and ret.

Referenced by GNUNET_STRINGS_from_utf8(), and GNUNET_STRINGS_to_utf8().

458 {
459  char *ret;
460  uint8_t *u8_string;
461  char *encoded_string;
462  size_t u8_string_length;
463  size_t encoded_string_length;
464 
465  u8_string = u8_conv_from_encoding (input_charset,
466  iconveh_error,
467  input, len,
468  NULL, NULL,
469  &u8_string_length);
470  if (NULL == u8_string)
471  {
472  LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "u8_conv_from_encoding");
473  goto fail;
474  }
475  if (0 == strcmp (output_charset, "UTF-8"))
476  {
477  ret = GNUNET_malloc (u8_string_length + 1);
478  GNUNET_memcpy (ret, u8_string, u8_string_length);
479  ret[u8_string_length] = '\0';
480  free (u8_string);
481  return ret;
482  }
483  encoded_string = u8_conv_to_encoding (output_charset, iconveh_error,
484  u8_string, u8_string_length,
485  NULL, NULL,
486  &encoded_string_length);
487  free (u8_string);
488  if (NULL == encoded_string)
489  {
490  LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "u8_conv_to_encoding");
491  goto fail;
492  }
493  ret = GNUNET_malloc (encoded_string_length + 1);
494  GNUNET_memcpy (ret, encoded_string, encoded_string_length);
495  ret[encoded_string_length] = '\0';
496  free (encoded_string);
497  return ret;
498  fail:
500  _("Character sets requested were `%s'->`%s'\n"),
501  "UTF-8", output_charset);
502  ret = GNUNET_malloc (len + 1);
503  GNUNET_memcpy (ret, input, len);
504  ret[len] = '\0';
505  return ret;
506 }
static int ret
Final status code.
Definition: gnunet-arm.c:89
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
#define GNUNET_memcpy(dst, src, n)
#define LOG(kind,...)
Definition: strings.c:37
#define LOG_STRERROR(kind, syscall)
Definition: strings.c:39
#define GNUNET_malloc(size)
Wrapper around malloc.
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
Here is the caller graph for this function:

◆ GNUNET_STRINGS_to_utf8()

char* GNUNET_STRINGS_to_utf8 ( const char *  input,
size_t  len,
const char *  charset 
)

Convert the len characters long character sequence given in input that is in the given charset to UTF-8.

Parameters
inputthe input string (not necessarily 0-terminated)
lenthe number of bytes in the input
charsetcharacter set to convert from
Returns
the converted string (0-terminated)
Parameters
inputthe input string (not necessarily 0-terminated)
lenthe number of bytes in the input
charsetcharacter set to convert from
Returns
the converted string (0-terminated), if conversion fails, a copy of the orignal string is returned.

Definition at line 522 of file strings.c.

References GNUNET_STRINGS_conv().

525 {
526  return GNUNET_STRINGS_conv (input, len, charset, "UTF-8");
527 }
char * GNUNET_STRINGS_conv(const char *input, size_t len, const char *input_charset, const char *output_charset)
Convert the len characters long character sequence given in input that is in the given input charset ...
Definition: strings.c:454
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
Here is the call graph for this function:

◆ GNUNET_STRINGS_from_utf8()

char* GNUNET_STRINGS_from_utf8 ( const char *  input,
size_t  len,
const char *  charset 
)

Convert the len bytes-long UTF-8 string given in input to the given charset.

Parameters
inputthe input string (not necessarily 0-terminated)
lenthe number of bytes in the input
charsetcharacter set to convert to
Returns
the converted string (0-terminated), if conversion fails, a copy of the orignal string is returned.

Definition at line 542 of file strings.c.

References GNUNET_STRINGS_conv().

545 {
546  return GNUNET_STRINGS_conv (input, len, "UTF-8", charset);
547 }
char * GNUNET_STRINGS_conv(const char *input, size_t len, const char *input_charset, const char *output_charset)
Convert the len characters long character sequence given in input that is in the given input charset ...
Definition: strings.c:454
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
Here is the call graph for this function:

◆ GNUNET_STRINGS_utf8_tolower()

void GNUNET_STRINGS_utf8_tolower ( const char *  input,
char *  output 
)

Convert the utf-8 input string to lower case.

Output needs to be allocated appropriately.

Parameters
inputinput string
outputoutput buffer

Convert the utf-8 input string to lower case.

Output needs to be allocated appropriately.

Parameters
inputinput string
outputoutput buffer

Definition at line 558 of file strings.c.

References GNUNET_memcpy, and len.

Referenced by ego_create(), GNUNET_GNSRECORD_string_to_lowercase(), GNUNET_RECLAIM_ATTRIBUTE_claim_new(), handle_collect(), handle_create_message(), handle_delete_message(), handle_get_default_message(), handle_lookup(), handle_rename_message(), handle_set_default_message(), handle_verify(), header_iterator(), and run_with_zone_pkey().

560 {
561  uint8_t *tmp_in;
562  size_t len;
563 
564  tmp_in = u8_tolower ((uint8_t*)input, strlen ((char *) input),
565  NULL, UNINORM_NFD, NULL, &len);
566  GNUNET_memcpy(output, tmp_in, len);
567  output[len] = '\0';
568  free(tmp_in);
569 }
#define GNUNET_memcpy(dst, src, n)
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
Here is the caller graph for this function:

◆ GNUNET_STRINGS_utf8_toupper()

void GNUNET_STRINGS_utf8_toupper ( const char *  input,
char *  output 
)

Convert the utf-8 input string to upper case.

Output needs to be allocated appropriately.

Parameters
inputinput string
outputoutput buffer

Convert the utf-8 input string to upper case.

Output needs to be allocated appropriately.

Parameters
inputinput string
outputoutput buffer

Definition at line 580 of file strings.c.

References GNUNET_memcpy, and len.

Referenced by client_configure_plugin(), GNUNET_CRYPTO_hash_from_string2(), GNUNET_HOSTLIST_client_start(), libgnunet_plugin_ats_mlp_init(), libgnunet_plugin_ats_ril_init(), and load_op_add_address().

582 {
583  uint8_t *tmp_in;
584  size_t len;
585 
586  tmp_in = u8_toupper ((uint8_t*)input, strlen ((char *) input),
587  NULL, UNINORM_NFD, NULL, &len);
588  GNUNET_memcpy (output, tmp_in, len);
589  output[len] = '\0';
590  free (tmp_in);
591 }
#define GNUNET_memcpy(dst, src, n)
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
Here is the caller graph for this function:

◆ GNUNET_STRINGS_filename_expand()

char* GNUNET_STRINGS_filename_expand ( const char *  fil)

Complete filename (a la shell) from abbrevition.

Parameters
filthe name of the file, may contain ~/ or be relative to the current directory
Returns
the full file name, NULL is returned on error
Parameters
filthe name of the file, may contain ~/ or be relative to the current directory
Returns
the full file name, NULL is returned on error

Definition at line 602 of file strings.c.

References _, DIR_SEPARATOR, DIR_SEPARATOR_STR, fn, getenv(), GNUNET_asprintf(), GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_malloc, GNUNET_strdup, len, LOG, LOG_STRERROR, and plibc_conv_to_win_path().

Referenced by check_client_index_start(), GNUNET_CONFIGURATION_get_value_filename(), GNUNET_CONFIGURATION_parse(), GNUNET_CONFIGURATION_write(), GNUNET_DISK_directory_create(), GNUNET_DISK_directory_create_for_file(), GNUNET_DISK_directory_scan(), GNUNET_DISK_file_open(), GNUNET_DISK_file_test(), GNUNET_FS_directory_scan_start(), GNUNET_FS_make_file_reader_context_(), GNUNET_log_setup(), handle_client_index_start(), hash_for_index_cb(), print_option(), and set_filename().

603 {
604  char *buffer;
605 #ifndef MINGW
606  size_t len;
607  char *fm;
608  const char *fil_ptr;
609 #else
610  char *fn;
611  long lRet;
612 #endif
613 
614  if (fil == NULL)
615  return NULL;
616 
617 #ifndef MINGW
618  if (fil[0] == DIR_SEPARATOR)
619  /* absolute path, just copy */
620  return GNUNET_strdup (fil);
621  if (fil[0] == '~')
622  {
623  fm = getenv ("HOME");
624  if (fm == NULL)
625  {
627  _("Failed to expand `$HOME': environment variable `HOME' not set"));
628  return NULL;
629  }
630  fm = GNUNET_strdup (fm);
631  /* do not copy '~' */
632  fil_ptr = fil + 1;
633 
634  /* skip over dir seperator to be consistent */
635  if (fil_ptr[0] == DIR_SEPARATOR)
636  fil_ptr++;
637  }
638  else
639  {
640  /* relative path */
641  fil_ptr = fil;
642  len = 512;
643  fm = NULL;
644  while (1)
645  {
646  buffer = GNUNET_malloc (len);
647  if (getcwd (buffer, len) != NULL)
648  {
649  fm = buffer;
650  break;
651  }
652  if ((errno == ERANGE) && (len < 1024 * 1024 * 4))
653  {
654  len *= 2;
655  GNUNET_free (buffer);
656  continue;
657  }
658  GNUNET_free (buffer);
659  break;
660  }
661  if (fm == NULL)
662  {
664  "getcwd");
665  buffer = getenv ("PWD"); /* alternative */
666  if (buffer != NULL)
667  fm = GNUNET_strdup (buffer);
668  }
669  if (fm == NULL)
670  fm = GNUNET_strdup ("./"); /* give up */
671  }
672  GNUNET_asprintf (&buffer,
673  "%s%s%s",
674  fm,
675  (fm[strlen (fm) - 1] ==
676  DIR_SEPARATOR) ? "" : DIR_SEPARATOR_STR, fil_ptr);
677  GNUNET_free (fm);
678  return buffer;
679 #else
680  fn = GNUNET_malloc (MAX_PATH + 1);
681 
682  if ((lRet = plibc_conv_to_win_path (fil, fn)) != ERROR_SUCCESS)
683  {
684  SetErrnoFromWinError (lRet);
686  "plibc_conv_to_win_path");
687  return NULL;
688  }
689  /* is the path relative? */
690  if ( (0 != strncmp (fn + 1, ":\\", 2)) &&
691  (0 != strncmp (fn, "\\\\", 2)) )
692  {
693  char szCurDir[MAX_PATH + 1];
694 
695  lRet = GetCurrentDirectory (MAX_PATH + 1,
696  szCurDir);
697  if (lRet + strlen (fn) + 1 > (MAX_PATH + 1))
698  {
699  SetErrnoFromWinError (ERROR_BUFFER_OVERFLOW);
701  "GetCurrentDirectory");
702  return NULL;
703  }
704  GNUNET_asprintf (&buffer,
705  "%s\\%s",
706  szCurDir,
707  fn);
708  GNUNET_free (fn);
709  fn = buffer;
710  }
711 
712  return fn;
713 #endif
714 }
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
static char * fn
Filename of the unique file.
#define DIR_SEPARATOR
Definition: plibc.h:631
#define LOG(kind,...)
Definition: strings.c:37
int plibc_conv_to_win_path(const char *pszUnix, char *pszWindows)
char * getenv()
#define LOG_STRERROR(kind, syscall)
Definition: strings.c:39
#define DIR_SEPARATOR_STR
Definition: plibc.h:632
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_STRINGS_buffer_fill()

size_t GNUNET_STRINGS_buffer_fill ( char *  buffer,
size_t  size,
unsigned int  count,
  ... 
)

Fill a buffer of the given size with count 0-terminated strings (given as varargs).

If "buffer" is NULL, only compute the amount of space required (sum of "strlen(arg)+1").

Unlike using "snprintf" with "%s", this function will add 0-terminators after each string. The "GNUNET_string_buffer_tokenize" function can be used to parse the buffer back into individual strings.

Parameters
bufferthe buffer to fill with strings, can be NULL in which case only the necessary amount of space will be calculated
sizenumber of bytes available in buffer
countnumber of strings that follow
...count 0-terminated strings to copy to buffer
Returns
number of bytes written to the buffer (or number of bytes that would have been written)

If "buffer" is NULL, only compute the amount of space required (sum of "strlen(arg)+1").

Unlike using "snprintf" with "%s", this function will add 0-terminators after each string. The #GNUNET_string_buffer_tokenize() function can be used to parse the buffer back into individual strings.

Parameters
bufferthe buffer to fill with strings, can be NULL in which case only the necessary amount of space will be calculated
sizenumber of bytes available in buffer
countnumber of strings that follow
...count 0-terminated strings to copy to buffer
Returns
number of bytes written to the buffer (or number of bytes that would have been written)

Definition at line 64 of file strings.c.

References GNUNET_assert, and GNUNET_memcpy.

Referenced by save(), transmit(), transmit_get(), transmit_set(), and transmit_watch().

65 {
66  size_t needed;
67  size_t slen;
68  const char *s;
69  va_list ap;
70 
71  needed = 0;
72  va_start (ap, count);
73  while (count > 0)
74  {
75  s = va_arg (ap, const char *);
76 
77  slen = strlen (s) + 1;
78  if (buffer != NULL)
79  {
80  GNUNET_assert (needed + slen <= size);
81  GNUNET_memcpy (&buffer[needed], s, slen);
82  }
83  needed += slen;
84  count--;
85  }
86  va_end (ap);
87  return needed;
88 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_memcpy(dst, src, n)
static unsigned int size
Size of the "table".
Definition: peer.c:67
Here is the caller graph for this function:

◆ GNUNET_STRINGS_buffer_tokenize()

unsigned int GNUNET_STRINGS_buffer_tokenize ( const char *  buffer,
size_t  size,
unsigned int  count,
  ... 
)

Given a buffer of a given size, find "count" 0-terminated strings in the buffer and assign the count (varargs) of type "const char**" to the locations of the respective strings in the buffer.

Parameters
bufferthe buffer to parse
sizesize of the buffer
countnumber of strings to locate
...pointers to where to store the strings
Returns
offset of the character after the last 0-termination in the buffer, or 0 on error.
Parameters
bufferthe buffer to parse
sizesize of the buffer
countnumber of strings to locate
Returns
offset of the character after the last 0-termination in the buffer, or 0 on error.

Definition at line 136 of file strings.c.

References start.

Referenced by check_get(), check_set(), check_statistics_value(), check_watch(), handle_get(), handle_set(), handle_statistics_value(), handle_watch(), and process_sblock().

138 {
139  unsigned int start;
140  unsigned int needed;
141  const char **r;
142  va_list ap;
143 
144  needed = 0;
145  va_start (ap, count);
146  while (count > 0)
147  {
148  r = va_arg (ap, const char **);
149 
150  start = needed;
151  while ((needed < size) && (buffer[needed] != '\0'))
152  needed++;
153  if (needed == size)
154  {
155  va_end (ap);
156  return 0; /* error */
157  }
158  *r = &buffer[start];
159  needed++; /* skip 0-termination */
160  count--;
161  }
162  va_end (ap);
163  return needed;
164 }
static int start
Set if we are to start default services (including ARM).
Definition: gnunet-arm.c:39
static unsigned int size
Size of the "table".
Definition: peer.c:67
Here is the caller graph for this function:

◆ GNUNET_STRINGS_get_short_name()

const char* GNUNET_STRINGS_get_short_name ( const char *  filename)

"man basename" Returns a pointer to a part of filename (allocates nothing)!

Parameters
filenamefilename to extract basename from
Returns
short (base) name of the file (that is, everything following the last directory separator in filename. If filename ends with a directory separator, the result will be a zero-length string. If filename has no directory separators, the result is filename itself.

Definition at line 845 of file strings.c.

References DIR_SEPARATOR_STR, and filename.

Referenced by expand_tree(), iter_check_config(), and iter_testbed_path().

846 {
847  const char *short_fn = filename;
848  const char *ss;
849 
850  while (NULL != (ss = strstr (short_fn, DIR_SEPARATOR_STR))
851  && (ss[1] != '\0'))
852  short_fn = 1 + ss;
853  return short_fn;
854 }
static char * filename
#define DIR_SEPARATOR_STR
Definition: plibc.h:632
Here is the caller graph for this function:

◆ GNUNET_STRINGS_data_to_string()

char* GNUNET_STRINGS_data_to_string ( const void *  data,
size_t  size,
char *  out,
size_t  out_size 
)

Convert binary data to ASCII encoding using CrockfordBase32.

Does not append 0-terminator, but returns a pointer to the place where it should be placed, if needed.

Parameters
datadata to encode
sizesize of data (in bytes)
outbuffer to fill
out_sizesize of the buffer. Must be large enough to hold ((size*8) + (((size*8) % 5) > 0 ? 5 - ((size*8) % 5) : 0)) / 5
Returns
pointer to the next byte in 'out' or NULL on error.

Convert binary data to ASCII encoding using CrockfordBase32.

Returns a pointer to the byte after the last byte in the string, that is where the 0-terminator was placed if there was room.

Parameters
datadata to encode
sizesize of data (in bytes)
outbuffer to fill
out_sizesize of the buffer. Must be large enough to hold (size * 8 + 4) / 5 bytes
Returns
pointer to the next byte in out or NULL on error.

32 characters for encoding

Definition at line 924 of file strings.c.

References data, GNUNET_assert, and GNUNET_break.

Referenced by auth_key_to_string(), GNUNET_CRYPTO_ecdsa_private_key_to_string(), GNUNET_CRYPTO_ecdsa_public_key_to_string(), GNUNET_CRYPTO_eddsa_private_key_to_string(), GNUNET_CRYPTO_eddsa_public_key_to_string(), GNUNET_CRYPTO_hash_to_enc(), GNUNET_GNSRECORD_z2s(), GNUNET_sh2s(), GNUNET_STRINGS_data_to_string_alloc(), GNUNET_uuid2s(), output_message(), print_examples_ecdh(), secret_ready_cb(), uri_loc_to_string(), and uri_sks_to_string().

928 {
932  static char *encTable__ = "0123456789ABCDEFGHJKMNPQRSTVWXYZ";
933  unsigned int wpos;
934  unsigned int rpos;
935  unsigned int bits;
936  unsigned int vbit;
937  const unsigned char *udata;
938 
939  udata = data;
940  if (out_size < (size * 8 + 4) / 5)
941  {
942  GNUNET_break (0);
943  return NULL;
944  }
945  vbit = 0;
946  wpos = 0;
947  rpos = 0;
948  bits = 0;
949  while ((rpos < size) || (vbit > 0))
950  {
951  if ((rpos < size) && (vbit < 5))
952  {
953  bits = (bits << 8) | udata[rpos++]; /* eat 8 more bits */
954  vbit += 8;
955  }
956  if (vbit < 5)
957  {
958  bits <<= (5 - vbit); /* zero-padding */
959  GNUNET_assert (vbit == ((size * 8) % 5));
960  vbit = 5;
961  }
962  if (wpos >= out_size)
963  {
964  GNUNET_break (0);
965  return NULL;
966  }
967  out[wpos++] = encTable__[(bits >> (vbit - 5)) & 31];
968  vbit -= 5;
969  }
970  GNUNET_assert (0 == vbit);
971  if (wpos < out_size)
972  out[wpos] = '\0';
973  return &out[wpos];
974 }
#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...
static unsigned int size
Size of the "table".
Definition: peer.c:67
uint32_t data
The data value.
Here is the caller graph for this function:

◆ GNUNET_STRINGS_data_to_string_alloc()

char* GNUNET_STRINGS_data_to_string_alloc ( const void *  buf,
size_t  size 
)

Return the base32crockford encoding of the given buffer.

The returned string will be freshly allocated, and must be free'd with GNUNET_free().

Parameters
bufbuffer with data
sizesize of the buffer buf
Returns
freshly allocated, null-terminated string

The returned string will be freshly allocated, and must be free'd with GNUNET_free().

Parameters
bufferwith data
sizesize of the buffer
Returns
freshly allocated, null-terminated string

Definition at line 988 of file strings.c.

References end, GNUNET_free, GNUNET_malloc, GNUNET_STRINGS_data_to_string(), and len.

Referenced by attr_collect(), attr_store_task(), conversation_value_to_string(), GNUNET_CURL_job_add2(), GNUNET_JSON_from_data(), handle_attribute_delete_message(), issue_ticket(), iter_cb(), lookup_authz_cb(), move_attr_finished(), move_attrs(), OIDC_id_token_new(), oidc_ticket_issue_cb(), process_attrs(), process_record(), RECLAIM_TICKETS_consume(), RECLAIM_TICKETS_revoke(), rvk_move_attr_cb(), ticket_collect(), ticket_issue_cb(), ticket_iter(), and value_to_string().

990 {
991  char *str_buf;
992  size_t len = size * 8;
993  char *end;
994 
995  if (len % 5 > 0)
996  len += 5 - len % 5;
997  len /= 5;
998  str_buf = GNUNET_malloc (len + 1);
999  end = GNUNET_STRINGS_data_to_string (buf, size, str_buf, len);
1000  if (NULL == end)
1001  {
1002  GNUNET_free (str_buf);
1003  return NULL;
1004  }
1005  *end = '\0';
1006  return str_buf;
1007 }
static int end
Set if we are to shutdown all services (including ARM).
Definition: gnunet-arm.c:34
static char buf[2048]
static unsigned int size
Size of the "table".
Definition: peer.c:67
#define GNUNET_malloc(size)
Wrapper around malloc.
char * GNUNET_STRINGS_data_to_string(const void *data, size_t size, char *out, size_t out_size)
Convert binary data to ASCII encoding using Crockford Base32 encoding.
Definition: strings.c:924
#define GNUNET_free(ptr)
Wrapper around free.
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_STRINGS_string_to_data()

int GNUNET_STRINGS_string_to_data ( const char *  enc,
size_t  enclen,
void *  out,
size_t  out_size 
)

Convert CrockfordBase32 encoding back to data.

out_size must match exactly the size of the data before it was encoded.

Parameters
encthe encoding
enclennumber of characters in enc (without 0-terminator, which can be missing)
outlocation where to store the decoded data
out_sizesize of the output buffer out
Returns
GNUNET_OK on success, GNUNET_SYSERR if result has the wrong encoding

Convert CrockfordBase32 encoding back to data.

out_size must match exactly the size of the data before it was encoded.

Parameters
encthe encoding
enclennumber of characters in enc (without 0-terminator, which can be missing)
outlocation where to store the decoded data
out_sizesize of the output buffer out
Returns
GNUNET_OK on success, GNUNET_SYSERR if result has the wrong encoding

Definition at line 1021 of file strings.c.

References getValue__(), GNUNET_break, GNUNET_OK, GNUNET_SYSERR, and ret.

Referenced by check_authorization(), conversation_string_to_value(), delete_attribute_cont(), GNUNET_CONFIGURATION_get_data(), GNUNET_CRYPTO_ecdsa_public_key_from_string(), GNUNET_CRYPTO_eddsa_private_key_from_string(), GNUNET_CRYPTO_eddsa_public_key_from_string(), GNUNET_CRYPTO_hash_from_string2(), GNUNET_HELLO_parse_uri(), lookup_redirect_uri_result(), parse_attr(), parse_fixed_data(), parse_rsa_public_key(), parse_rsa_signature(), parse_ticket(), parse_variable_data(), read_service_conf(), run(), set_base32(), start_process(), string_to_auth_key(), string_to_value(), uri_loc_parse(), and uri_sks_parse().

1023 {
1024  unsigned int rpos;
1025  unsigned int wpos;
1026  unsigned int bits;
1027  unsigned int vbit;
1028  int ret;
1029  int shift;
1030  unsigned char *uout;
1031  unsigned int encoded_len = out_size * 8;
1032 
1033  if (0 == enclen)
1034  {
1035  if (0 == out_size)
1036  return GNUNET_OK;
1037  return GNUNET_SYSERR;
1038  }
1039  uout = out;
1040  wpos = out_size;
1041  rpos = enclen;
1042  if ((encoded_len % 5) > 0)
1043  {
1044  vbit = encoded_len % 5; /* padding! */
1045  shift = 5 - vbit;
1046  bits = (ret = getValue__ (enc[--rpos])) >> shift;
1047  }
1048  else
1049  {
1050  vbit = 5;
1051  shift = 0;
1052  bits = (ret = getValue__ (enc[--rpos]));
1053  }
1054  if ((encoded_len + shift) / 5 != enclen)
1055  return GNUNET_SYSERR;
1056  if (-1 == ret)
1057  return GNUNET_SYSERR;
1058  while (wpos > 0)
1059  {
1060  if (0 == rpos)
1061  {
1062  GNUNET_break (0);
1063  return GNUNET_SYSERR;
1064  }
1065  bits = ((ret = getValue__ (enc[--rpos])) << vbit) | bits;
1066  if (-1 == ret)
1067  return GNUNET_SYSERR;
1068  vbit += 5;
1069  if (vbit >= 8)
1070  {
1071  uout[--wpos] = (unsigned char) bits;
1072  bits >>= 8;
1073  vbit -= 8;
1074  }
1075  }
1076  if ( (0 != rpos) ||
1077  (0 != vbit) )
1078  return GNUNET_SYSERR;
1079  return GNUNET_OK;
1080 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
static int ret
Final status code.
Definition: gnunet-arm.c:89
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static unsigned int getValue__(unsigned char a)
Get the decoded value corresponding to a character according to Crockford Base32 encoding.
Definition: strings.c:865
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
static OpusEncoder * enc
OPUS encoder.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_STRINGS_base64_encode()

size_t GNUNET_STRINGS_base64_encode ( const void *  in,
size_t  len,
char **  output 
)

Encode into Base64.

Parameters
datathe data to encode
lenthe length of the input
outputwhere to write the output (*output should be NULL, is allocated)
Returns
the size of the output
Parameters
inthe data to encode
lenthe length of the input
outputwhere to write the output (*output should be NULL, is allocated)
Returns
the size of the output

Definition at line 2004 of file strings.c.

References cvt, data, FILLCHAR, GNUNET_malloc, len, and ret.

Referenced by api_send(), base64_encode(), credential_to_json(), dns_value_to_string(), GNUNET_CREDENTIAL_credential_to_string(), GNUNET_HELLO_sign_address(), OIDC_access_token_new(), OIDC_id_token_new(), send_cred_response(), and store_and_free_entries().

2007 {
2008  const char *data = in;
2009  size_t ret;
2010  char *opt;
2011 
2012  ret = 0;
2013  opt = GNUNET_malloc (2 + (len * 4 / 3) + 8);
2014  for (size_t i = 0; i < len; ++i)
2015  {
2016  char c;
2017 
2018  c = (data[i] >> 2) & 0x3f;
2019  opt[ret++] = cvt[(int) c];
2020  c = (data[i] << 4) & 0x3f;
2021  if (++i < len)
2022  c |= (data[i] >> 4) & 0x0f;
2023  opt[ret++] = cvt[(int) c];
2024  if (i < len)
2025  {
2026  c = (data[i] << 2) & 0x3f;
2027  if (++i < len)
2028  c |= (data[i] >> 6) & 0x03;
2029  opt[ret++] = cvt[(int) c];
2030  }
2031  else
2032  {
2033  ++i;
2034  opt[ret++] = FILLCHAR;
2035  }
2036  if (i < len)
2037  {
2038  c = data[i] & 0x3f;
2039  opt[ret++] = cvt[(int) c];
2040  }
2041  else
2042  {
2043  opt[ret++] = FILLCHAR;
2044  }
2045  }
2046  *output = opt;
2047  return ret;
2048 }
#define FILLCHAR
******************** Base64 encoding
Definition: strings.c:1989
static int ret
Final status code.
Definition: gnunet-arm.c:89
static char * cvt
Definition: strings.c:1990
uint32_t data
The data value.
#define GNUNET_malloc(size)
Wrapper around malloc.
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
Here is the caller graph for this function:

◆ GNUNET_STRINGS_base64_decode()

size_t GNUNET_STRINGS_base64_decode ( const char *  data,
size_t  len,
void **  out 
)

Decode from Base64.

Parameters
datathe data to encode
lenthe length of the input
[out]outputwhere to write the output (*output should be NULL, is allocated)
Returns
the size of the output
Parameters
datathe data to encode
lenthe length of the input
outputwhere to write the output (*output should be NULL, is allocated)
Returns
the size of the output

Definition at line 2067 of file strings.c.

References CHECK_CRLF, cvtfind, END, FILLCHAR, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_malloc, len, and ret.

Referenced by check_authorization(), database_setup(), dns_string_to_value(), GNUNET_CREDENTIAL_credential_from_string(), GNUNET_HELLO_extract_address(), json_to_credential(), listenAndDistribute(), and OIDC_parse_authz_code().

2070 {
2071  char *output;
2072  size_t ret = 0;
2073 
2074 #define CHECK_CRLF while (data[i] == '\r' || data[i] == '\n') {\
2075  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, "ignoring CR/LF\n"); \
2076  i++; \
2077  if (i >= len) goto END; \
2078  }
2079 
2080  output = GNUNET_malloc ((len * 3 / 4) + 8);
2082  "base64_decode decoding len=%d\n",
2083  (int) len);
2084  for (size_t i = 0; i < len; ++i)
2085  {
2086  char c;
2087  char c1;
2088 
2089  CHECK_CRLF;
2090  if (FILLCHAR == data[i])
2091  break;
2092  c = (char) cvtfind (data[i]);
2093  ++i;
2094  CHECK_CRLF;
2095  c1 = (char) cvtfind (data[i]);
2096  c = (c << 2) | ((c1 >> 4) & 0x3);
2097  output[ret++] = c;
2098  if (++i < len)
2099  {
2100  CHECK_CRLF;
2101  c = data[i];
2102  if (FILLCHAR == c)
2103  break;
2104  c = (char) cvtfind (c);
2105  c1 = ((c1 << 4) & 0xf0) | ((c >> 2) & 0xf);
2106  output[ret++] = c1;
2107  }
2108  if (++i < len)
2109  {
2110  CHECK_CRLF;
2111  c1 = data[i];
2112  if (FILLCHAR == c1)
2113  break;
2114 
2115  c1 = (char) cvtfind (c1);
2116  c = ((c << 6) & 0xc0) | c1;
2117  output[ret++] = c;
2118  }
2119  }
2120 END:
2121  *out = output;
2122  return ret;
2123 }
#define CHECK_CRLF
#define FILLCHAR
******************** Base64 encoding
Definition: strings.c:1989
#define cvtfind(a)
Definition: strings.c:2050
We&#39;re done processing.
static int ret
Final status code.
Definition: gnunet-arm.c:89
#define GNUNET_log(kind,...)
uint32_t data
The data value.
#define GNUNET_malloc(size)
Wrapper around malloc.
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
Here is the caller graph for this function:

◆ GNUNET_STRINGS_pp2s()

char* GNUNET_STRINGS_pp2s ( const struct GNUNET_PeerIdentity pids,
unsigned int  num_pids 
)

Convert a peer path to a human-readable string.

Parameters
pidsarray of PIDs to convert to a string
num_pidslength of the pids array
Returns
string representing the array of pids

Definition at line 99 of file strings.c.

References buf, GNUNET_i2s(), GNUNET_malloc, and GNUNET_snprintf().

Referenced by handle_dht_p2p_put(), handle_dht_p2p_result(), handle_local_result(), and process_client_result().

101 {
102  char *buf;
103  size_t off;
104  size_t plen = num_pids * 5 + 1;
105 
106  off = 0;
107  buf = GNUNET_malloc (plen);
108  for (unsigned int i = 0;
109  i < num_pids;
110  i++)
111  {
112  off += GNUNET_snprintf (&buf[off],
113  plen - off,
114  "%s%s",
115  GNUNET_i2s (&pids[i]),
116  (i == num_pids -1) ? "" : "-");
117  }
118  return buf;
119 }
int GNUNET_snprintf(char *buf, size_t size, const char *format,...)
Like snprintf, just aborts if the buffer is of insufficient size.
static char buf[2048]
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define GNUNET_malloc(size)
Wrapper around malloc.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_STRINGS_parse_uri()

int GNUNET_STRINGS_parse_uri ( const char *  path,
char **  scheme_part,
const char **  path_part 
)

Parse a path that might be an URI.

Parameters
pathpath to parse. Must be NULL-terminated.
[out]scheme_partpointer to a string that represents the URI scheme will be stored. Can be NULL. The string is allocated by the function, and should be freed by GNUNET_free() when it is no longer needed.
path_parta pointer to 'const char *' where a pointer to the path part of the URI will be stored. Can be NULL. Points to the same block of memory as path, and thus must not be freed. Might point to '\0', if path part is zero-length.
Returns
GNUNET_YES if it's an URI, GNUNET_NO otherwise. If 'path' is not an URI, '* scheme_part' and '*path_part' will remain unchanged (if they weren't NULL).
Parameters
pathpath to parse. Must be NULL-terminated.
scheme_parta pointer to 'char *' where a pointer to a string that represents the URI scheme will be stored. Can be NULL. The string is allocated by the function, and should be freed by GNUNET_free() when it is no longer needed.
path_parta pointer to 'const char *' where a pointer to the path part of the URI will be stored. Can be NULL. Points to the same block of memory as 'path', and thus must not be freed. Might point to '\0', if path part is zero-length.
Returns
GNUNET_YES if it's an URI, GNUNET_NO otherwise. If 'path' is not an URI, '* scheme_part' and '*path_part' will remain unchanged (if they weren't NULL).

Definition at line 1100 of file strings.c.

References end, GNUNET_malloc, GNUNET_memcpy, GNUNET_NO, GNUNET_YES, and len.

Referenced by GNUNET_STRINGS_path_is_absolute().

1103 {
1104  size_t len;
1105  size_t i;
1106  int end;
1107  int pp_state = 0;
1108  const char *post_scheme_part = NULL;
1109  len = strlen (path);
1110  for (end = 0, i = 0; !end && i < len; i++)
1111  {
1112  switch (pp_state)
1113  {
1114  case 0:
1115  if ( (path[i] == ':') && (i > 0) )
1116  {
1117  pp_state += 1;
1118  continue;
1119  }
1120  if (!((path[i] >= 'A' && path[i] <= 'Z') || (path[i] >= 'a' && path[i] <= 'z')
1121  || (path[i] >= '0' && path[i] <= '9') || path[i] == '+' || path[i] == '-'
1122  || (path[i] == '.')))
1123  end = 1;
1124  break;
1125  case 1:
1126  case 2:
1127  if (path[i] == '/')
1128  {
1129  pp_state += 1;
1130  continue;
1131  }
1132  end = 1;
1133  break;
1134  case 3:
1135  post_scheme_part = &path[i];
1136  end = 1;
1137  break;
1138  default:
1139  end = 1;
1140  }
1141  }
1142  if (post_scheme_part == NULL)
1143  return GNUNET_NO;
1144  if (scheme_part)
1145  {
1146  *scheme_part = GNUNET_malloc (post_scheme_part - path + 1);
1147  GNUNET_memcpy (*scheme_part, path, post_scheme_part - path);
1148  (*scheme_part)[post_scheme_part - path] = '\0';
1149  }
1150  if (path_part)
1151  *path_part = post_scheme_part;
1152  return GNUNET_YES;
1153 }
static int end
Set if we are to shutdown all services (including ARM).
Definition: gnunet-arm.c:34
#define GNUNET_NO
Definition: gnunet_common.h:81
#define GNUNET_memcpy(dst, src, n)
#define GNUNET_YES
Definition: gnunet_common.h:80
#define GNUNET_malloc(size)
Wrapper around malloc.
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
Here is the caller graph for this function:

◆ GNUNET_STRINGS_path_is_absolute()

int GNUNET_STRINGS_path_is_absolute ( const char *  filename,
int  can_be_uri,
int *  r_is_uri,
char **  r_uri_scheme 
)

Check whether filename is absolute or not, and if it's an URI.

Parameters
filenamefilename to check
can_be_uriGNUNET_YES to check for being URI, GNUNET_NO - to assume it's not URI
r_is_uria pointer to an int that is set to GNUNET_YES if 'filename' is URI and to GNUNET_NO otherwise. Can be NULL. If 'can_be_uri' is not GNUNET_YES, *r_is_uri is set to GNUNET_NO.
r_uri_schemea pointer to a char * that is set to a pointer to URI scheme. The string is allocated by the function, and should be freed with GNUNET_free (). Can be NULL.
Returns
GNUNET_YES if 'filename' is absolute, GNUNET_NO otherwise.

Check whether filename is absolute or not, and if it's an URI.

Parameters
filenamefilename to check
can_be_uriGNUNET_YES to check for being URI, GNUNET_NO - to assume it's not URI
r_is_uria pointer to an int that is set to GNUNET_YES if filename is URI and to GNUNET_NO otherwise. Can be NULL. If can_be_uri is not GNUNET_YES, * r_is_uri is set to GNUNET_NO.
r_uri_schemea pointer to a char * that is set to a pointer to URI scheme. The string is allocated by the function, and should be freed with GNUNET_free(). Can be NULL.
Returns
GNUNET_YES if filename is absolute, GNUNET_NO otherwise.

Definition at line 1171 of file strings.c.

References GNUNET_free_non_null, GNUNET_NO, GNUNET_STRINGS_parse_uri(), GNUNET_YES, len, and uri.

Referenced by GNUNET_OS_check_helper_binary(), GNUNET_OS_get_libexec_binary_path(), GNUNET_OS_get_suid_binary_path(), and GNUNET_STRINGS_check_filename().

1175 {
1176 #if WINDOWS
1177  size_t len;
1178 #endif
1179  const char *post_scheme_path;
1180  int is_uri;
1181  char * uri;
1182  /* consider POSIX paths to be absolute too, even on W32,
1183  * as plibc expansion will fix them for us.
1184  */
1185  if (filename[0] == '/')
1186  return GNUNET_YES;
1187  if (can_be_uri)
1188  {
1189  is_uri = GNUNET_STRINGS_parse_uri (filename, &uri, &post_scheme_path);
1190  if (r_is_uri)
1191  *r_is_uri = is_uri;
1192  if (is_uri)
1193  {
1194  if (r_uri_scheme)
1195  *r_uri_scheme = uri;
1196  else
1197  GNUNET_free_non_null (uri);
1198 #if WINDOWS
1199  len = strlen(post_scheme_path);
1200  /* Special check for file:///c:/blah
1201  * We want to parse 'c:/', not '/c:/'
1202  */
1203  if (post_scheme_path[0] == '/' && len >= 3 && post_scheme_path[2] == ':')
1204  post_scheme_path = &post_scheme_path[1];
1205 #endif
1206  return GNUNET_STRINGS_path_is_absolute (post_scheme_path, GNUNET_NO, NULL, NULL);
1207  }
1208  }
1209  else
1210  {
1211  if (r_is_uri)
1212  *r_is_uri = GNUNET_NO;
1213  }
1214 #if WINDOWS
1215  len = strlen (filename);
1216  if (len >= 3 &&
1217  ((filename[0] >= 'A' && filename[0] <= 'Z')
1218  || (filename[0] >= 'a' && filename[0] <= 'z'))
1219  && filename[1] == ':' && (filename[2] == '/' || filename[2] == '\\'))
1220  return GNUNET_YES;
1221 #endif
1222  return GNUNET_NO;
1223 }
int GNUNET_STRINGS_parse_uri(const char *path, char **scheme_part, const char **path_part)
Parse a path that might be an URI.
Definition: strings.c:1100
int GNUNET_STRINGS_path_is_absolute(const char *filename, int can_be_uri, int *r_is_uri, char **r_uri_scheme)
Check whether filename is absolute or not, and if it&#39;s an URI.
Definition: strings.c:1171
#define GNUNET_NO
Definition: gnunet_common.h:81
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
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 * filename
#define GNUNET_YES
Definition: gnunet_common.h:80
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_STRINGS_check_filename()

int GNUNET_STRINGS_check_filename ( const char *  filename,
enum GNUNET_STRINGS_FilenameCheck  checks 
)

Perform checks on filename.

FIXME: some duplication with "GNUNET_DISK_"-APIs. We should unify those.

Parameters
filenamefile to check
checkschecks to perform
Returns
GNUNET_YES if all checks pass, GNUNET_NO if at least one of them fails, GNUNET_SYSERR when a check can't be performed

Perform checks on filename.

Parameters
filenamefile to check
checkschecks to perform
Returns
GNUNET_YES if all checks pass, GNUNET_NO if at least one of them fails, GNUNET_SYSERR when a check can't be performed

Definition at line 1241 of file strings.c.

References GNUNET_NO, GNUNET_STRINGS_CHECK_EXISTS, GNUNET_STRINGS_CHECK_IS_ABSOLUTE, GNUNET_STRINGS_CHECK_IS_DIRECTORY, GNUNET_STRINGS_CHECK_IS_LINK, GNUNET_STRINGS_path_is_absolute(), GNUNET_SYSERR, GNUNET_YES, S_ISLNK, and STAT.

1243 {
1244  struct stat st;
1245  if ( (NULL == filename) || (filename[0] == '\0') )
1246  return GNUNET_SYSERR;
1247  if (0 != (checks & GNUNET_STRINGS_CHECK_IS_ABSOLUTE))
1249  return GNUNET_NO;
1250  if (0 != (checks & (GNUNET_STRINGS_CHECK_EXISTS
1253  {
1254  if (0 != STAT (filename, &st))
1255  {
1256  if (0 != (checks & GNUNET_STRINGS_CHECK_EXISTS))
1257  return GNUNET_NO;
1258  else
1259  return GNUNET_SYSERR;
1260  }
1261  }
1262  if (0 != (checks & GNUNET_STRINGS_CHECK_IS_DIRECTORY))
1263  if (!S_ISDIR (st.st_mode))
1264  return GNUNET_NO;
1265  if (0 != (checks & GNUNET_STRINGS_CHECK_IS_LINK))
1266  if (!S_ISLNK (st.st_mode))
1267  return GNUNET_NO;
1268  return GNUNET_YES;
1269 }
int GNUNET_STRINGS_path_is_absolute(const char *filename, int can_be_uri, int *r_is_uri, char **r_uri_scheme)
Check whether filename is absolute or not, and if it&#39;s an URI.
Definition: strings.c:1171
Check that the path is an absolute path.
#define GNUNET_NO
Definition: gnunet_common.h:81
#define STAT(p, b)
Definition: plibc.h:663
Check that it exists.
static char * filename
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
#define S_ISLNK(m)
Definition: disk.c:59
#define GNUNET_YES
Definition: gnunet_common.h:80
Check that it is a link.
static struct GNUNET_SCHEDULER_Task * st
The shutdown task.
Check that it is a directory.
Here is the call graph for this function:

◆ GNUNET_STRINGS_to_address_ipv6()

int GNUNET_STRINGS_to_address_ipv6 ( const char *  zt_addr,
uint16_t  addrlen,
struct sockaddr_in6 *  r_buf 
)

Tries to convert zt_addr string to an IPv6 address.

The string is expected to have the format "[ABCD::01]:80".

Parameters
zt_addr0-terminated string. May be mangled by the function.
addrlenlength of zt_addr (not counting 0-terminator).
r_bufa buffer to fill. Initially gets filled with zeroes, then its sin6_port, sin6_family and sin6_addr are set appropriately.
Returns
GNUNET_OK if conversion succeded. GNUNET_SYSERR otherwise, in which case the contents of r_buf are undefined.

The string is expected to have the format "[ABCD::01]:80".

Parameters
zt_addr0-terminated string. May be mangled by the function.
addrlenlength of zt_addr (not counting 0-terminator).
r_bufa buffer to fill. Initially gets filled with zeroes, then its sin6_port, sin6_family and sin6_addr are set appropriately.
Returns
GNUNET_OK if conversion succeded. GNUNET_SYSERR otherwise, in which case the contents of r_buf are undefined.

Definition at line 1285 of file strings.c.

References _, dummy, GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_memcpy, GNUNET_OK, GNUNET_SYSERR, inet_pton(), port, ret, SSCANF, and STRERROR.

Referenced by GNUNET_STRINGS_parse_socket_addr(), and GNUNET_STRINGS_to_address_ip().

1288 {
1289  char zbuf[addrlen + 1];
1290  int ret;
1291  char *port_colon;
1292  unsigned int port;
1293  char dummy[2];
1294 
1295  if (addrlen < 6)
1296  return GNUNET_SYSERR;
1297  GNUNET_memcpy (zbuf, zt_addr, addrlen);
1298  if ('[' != zbuf[0])
1299  {
1301  _("IPv6 address did not start with `['\n"));
1302  return GNUNET_SYSERR;
1303  }
1304  zbuf[addrlen] = '\0';
1305  port_colon = strrchr (zbuf, ':');
1306  if (NULL == port_colon)
1307  {
1309  _("IPv6 address did contain ':' to separate port number\n"));
1310  return GNUNET_SYSERR;
1311  }
1312  if (']' != *(port_colon - 1))
1313  {
1315  _("IPv6 address did contain ']' before ':' to separate port number\n"));
1316  return GNUNET_SYSERR;
1317  }
1318  ret = SSCANF (port_colon,
1319  ":%u%1s",
1320  &port,
1321  dummy);
1322  if ( (1 != ret) || (port > 65535) )
1323  {
1325  _("IPv6 address did contain a valid port number after the last ':'\n"));
1326  return GNUNET_SYSERR;
1327  }
1328  *(port_colon-1) = '\0';
1329  memset (r_buf, 0, sizeof (struct sockaddr_in6));
1330  ret = inet_pton (AF_INET6, &zbuf[1], &r_buf->sin6_addr);
1331  if (ret <= 0)
1332  {
1334  _("Invalid IPv6 address `%s': %s\n"),
1335  &zbuf[1],
1336  STRERROR (errno));
1337  return GNUNET_SYSERR;
1338  }
1339  r_buf->sin6_port = htons (port);
1340  r_buf->sin6_family = AF_INET6;
1341 #if HAVE_SOCKADDR_IN_SIN_LEN
1342  r_buf->sin6_len = (u_char) sizeof (struct sockaddr_in6);
1343 #endif
1344  return GNUNET_OK;
1345 }
static struct in_addr dummy
Target "dummy" address.
#define STRERROR(i)
Definition: plibc.h:676
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
static int ret
Final status code.
Definition: gnunet-arm.c:89
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
#define GNUNET_memcpy(dst, src, n)
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
#define SSCANF
Definition: plibc.h:691
static uint16_t port
Port number.
Definition: gnunet-bcd.c:79
static int inet_pton(int af, const char *cp, struct in_addr *buf)
Convert IPv4 address from text to binary form.
#define GNUNET_log(kind,...)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_STRINGS_to_address_ipv4()

int GNUNET_STRINGS_to_address_ipv4 ( const char *  zt_addr,
uint16_t  addrlen,
struct sockaddr_in *  r_buf 
)

Tries to convert zt_addr string to an IPv4 address.

The string is expected to have the format "1.2.3.4:80".

Parameters
zt_addr0-terminated string. May be mangled by the function.
addrlenlength of zt_addr (not counting 0-terminator).
r_bufa buffer to fill.
Returns
GNUNET_OK if conversion succeded. GNUNET_SYSERR otherwise, in which case the contents of r_buf are undefined.

Tries to convert zt_addr string to an IPv4 address.

The string is expected to have the format "1.2.3.4:80".

Parameters
zt_addr0-terminated string. May be mangled by the function.
addrlenlength of zt_addr (not counting 0-terminator).
r_bufa buffer to fill.
Returns
GNUNET_OK if conversion succeded. GNUNET_SYSERR otherwise, in which case the contents of r_buf are undefined.

Definition at line 1360 of file strings.c.

References dummy, GNUNET_OK, GNUNET_SYSERR, port, and SSCANF.

Referenced by GNUNET_STRINGS_parse_socket_addr(), and GNUNET_STRINGS_to_address_ip().

1363 {
1364  unsigned int temps[4];
1365  unsigned int port;
1366  unsigned int cnt;
1367  char dummy[2];
1368 
1369  if (addrlen < 9)
1370  return GNUNET_SYSERR;
1371  cnt = SSCANF (zt_addr,
1372  "%u.%u.%u.%u:%u%1s",
1373  &temps[0],
1374  &temps[1],
1375  &temps[2],
1376  &temps[3],
1377  &port,
1378  dummy);
1379  if (5 != cnt)
1380  return GNUNET_SYSERR;
1381  for (cnt = 0; cnt < 4; cnt++)
1382  if (temps[cnt] > 0xFF)
1383  return GNUNET_SYSERR;
1384  if (port > 65535)
1385  return GNUNET_SYSERR;
1386  r_buf->sin_family = AF_INET;
1387  r_buf->sin_port = htons (port);
1388  r_buf->sin_addr.s_addr = htonl ((temps[0] << 24) + (temps[1] << 16) +
1389  (temps[2] << 8) + temps[3]);
1390 #if HAVE_SOCKADDR_IN_SIN_LEN
1391  r_buf->sin_len = (u_char) sizeof (struct sockaddr_in);
1392 #endif
1393  return GNUNET_OK;
1394 }
static struct in_addr dummy
Target "dummy" address.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
#define SSCANF
Definition: plibc.h:691
static uint16_t port
Port number.
Definition: gnunet-bcd.c:79
Here is the caller graph for this function:

◆ GNUNET_STRINGS_parse_socket_addr()

size_t GNUNET_STRINGS_parse_socket_addr ( const char *  addr,
uint8_t *  af,
struct sockaddr **  sa 
)

Parse an address given as a string into a struct sockaddr.

Parameters
addrthe address
[out]afset to the parsed address family (i.e. AF_INET)
[out]saset to the parsed address
Returns
0 on error, otherwise number of bytes in sa

Definition at line 1433 of file strings.c.

References GNUNET_free, GNUNET_malloc, GNUNET_OK, GNUNET_strdup, GNUNET_STRINGS_to_address_ipv4(), and GNUNET_STRINGS_to_address_ipv6().

Referenced by run().

1436 {
1437  char *cp = GNUNET_strdup (addr);
1438 
1439  *af = AF_UNSPEC;
1440  if ('[' == *addr)
1441  {
1442  /* IPv6 */
1443  *sa = GNUNET_malloc (sizeof (struct sockaddr_in6));
1444  if (GNUNET_OK !=
1446  strlen (cp),
1447  (struct sockaddr_in6 *) *sa))
1448  {
1449  GNUNET_free (*sa);
1450  *sa = NULL;
1451  GNUNET_free (cp);
1452  return 0;
1453  }
1454  *af = AF_INET6;
1455  GNUNET_free (cp);
1456  return sizeof (struct sockaddr_in6);
1457  }
1458  else
1459  {
1460  /* IPv4 */
1461  *sa = GNUNET_malloc (sizeof (struct sockaddr_in));
1462  if (GNUNET_OK !=
1464  strlen (cp),
1465  (struct sockaddr_in *) *sa))
1466  {
1467  GNUNET_free (*sa);
1468  *sa = NULL;
1469  GNUNET_free (cp);
1470  return 0;
1471  }
1472  *af = AF_INET;
1473  GNUNET_free (cp);
1474  return sizeof (struct sockaddr_in);
1475  }
1476 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
int GNUNET_STRINGS_to_address_ipv4(const char *zt_addr, uint16_t addrlen, struct sockaddr_in *r_buf)
Tries to convert &#39;zt_addr&#39; string to an IPv4 address.
Definition: strings.c:1360
int GNUNET_STRINGS_to_address_ipv6(const char *zt_addr, uint16_t addrlen, struct sockaddr_in6 *r_buf)
Tries to convert zt_addr string to an IPv6 address.
Definition: strings.c:1285
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_STRINGS_to_address_ip()

int GNUNET_STRINGS_to_address_ip ( const char *  addr,
uint16_t  addrlen,
struct sockaddr_storage *  r_buf 
)

Tries to convert addr string to an IP (v4 or v6) address.

Will automatically decide whether to treat 'addr' as v4 or v6 address.

Parameters
addra string, may not be 0-terminated.
addrlennumber of bytes in addr (if addr is 0-terminated, 0-terminator should not be counted towards addrlen).
r_bufa buffer to fill.
Returns
GNUNET_OK if conversion succeded. GNUNET_SYSERR otherwise, in which case the contents of r_buf are undefined.

Will automatically decide whether to treat 'addr' as v4 or v6 address.

Parameters
addra string, may not be 0-terminated.
addrlennumber of bytes in addr (if addr is 0-terminated, 0-terminator should not be counted towards addrlen).
r_bufa buffer to fill.
Returns
GNUNET_OK if conversion succeded. GNUNET_SYSERR otherwise, in which case the contents of r_buf are undefined.

Definition at line 1409 of file strings.c.

References GNUNET_STRINGS_to_address_ipv4(), and GNUNET_STRINGS_to_address_ipv6().

Referenced by http_common_socket_from_address(), tcp_plugin_string_to_address(), and udp_string_to_address().

1412 {
1413  if (addr[0] == '[')
1414  return GNUNET_STRINGS_to_address_ipv6 (addr,
1415  addrlen,
1416  (struct sockaddr_in6 *) r_buf);
1417  return GNUNET_STRINGS_to_address_ipv4 (addr,
1418  addrlen,
1419  (struct sockaddr_in *) r_buf);
1420 }
int GNUNET_STRINGS_to_address_ipv4(const char *zt_addr, uint16_t addrlen, struct sockaddr_in *r_buf)
Tries to convert &#39;zt_addr&#39; string to an IPv4 address.
Definition: strings.c:1360
int GNUNET_STRINGS_to_address_ipv6(const char *zt_addr, uint16_t addrlen, struct sockaddr_in6 *r_buf)
Tries to convert zt_addr string to an IPv6 address.
Definition: strings.c:1285
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_STRINGS_get_utf8_args()

int GNUNET_STRINGS_get_utf8_args ( int  argc,
char *const *  argv,
int *  u8argc,
char *const **  u8argv 
)

Returns utf-8 encoded arguments.

Does nothing (returns a copy of argc and argv) on any platform other than W32. Returned argv has u8argv[u8argc] == NULL. Returned argv is a single memory block, and can be freed with a single GNUNET_free() call.

Parameters
argcargc (as given by main())
argvargv (as given by main())
u8argca location to store new argc in (though it's th same as argc)
u8argva location to store new argv in
Returns
GNUNET_OK on success, GNUNET_SYSERR on failure

Does nothing (returns a copy of argc and argv) on any platform other than W32. Returned argv has u8argv[u8argc] == NULL. Returned argv is a single memory block, and can be freed with a single GNUNET_free() call.

Parameters
argcargc (as given by main())
argvargv (as given by main())
u8argca location to store new argc in (though it's th same as argc)
u8argva location to store new argv in
Returns
GNUNET_OK on success, GNUNET_SYSERR on failure

Definition at line 1521 of file strings.c.

References _make_continuous_arg_copy(), GNUNET_free, GNUNET_malloc, GNUNET_OK, and GNUNET_SYSERR.

Referenced by main().

1525 {
1526 #if WINDOWS
1527  wchar_t *wcmd;
1528  wchar_t **wargv;
1529  int wargc;
1530  int i;
1531  char **split_u8argv;
1532 
1533  wcmd = GetCommandLineW ();
1534  if (NULL == wcmd)
1535  return GNUNET_SYSERR;
1536  wargv = CommandLineToArgvW (wcmd, &wargc);
1537  if (NULL == wargv)
1538  return GNUNET_SYSERR;
1539 
1540  split_u8argv = GNUNET_malloc (argc * sizeof (char *));
1541 
1542  for (i = 0; i < wargc; i++)
1543  {
1544  size_t strl;
1545  /* Hopefully it will allocate us NUL-terminated strings... */
1546  split_u8argv[i] = (char *) u16_to_u8 (wargv[i], wcslen (wargv[i]) + 1, NULL, &strl);
1547  if (NULL == split_u8argv[i])
1548  {
1549  int j;
1550  for (j = 0; j < i; j++)
1551  free (split_u8argv[j]);
1552  GNUNET_free (split_u8argv);
1553  LocalFree (wargv);
1554  return GNUNET_SYSERR;
1555  }
1556  }
1557 
1558  *u8argv = _make_continuous_arg_copy (wargc, split_u8argv);
1559  *u8argc = wargc;
1560 
1561  for (i = 0; i < wargc; i++)
1562  free (split_u8argv[i]);
1563  free (split_u8argv);
1564  return GNUNET_OK;
1565 #else
1566  char *const *new_argv = (char *const *) _make_continuous_arg_copy (argc, argv);
1567  *u8argv = new_argv;
1568  *u8argc = argc;
1569  return GNUNET_OK;
1570 #endif
1571 }
static char *const * _make_continuous_arg_copy(int argc, char *const *argv)
Makes a copy of argv that consists of a single memory chunk that can be freed with a single call to G...
Definition: strings.c:1484
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_strlcpy()

size_t GNUNET_strlcpy ( char *  dst,
const char *  src,
size_t  n 
)

Like strlcpy but portable.

The given string src is copied in full length (until its null byte). The destination buffer is guaranteed to be null-terminated.

to a destination buffer and ensures that the destination string is null-terminated.

Parameters
dstdestination of the copy
srcsource of the copy, must be null-terminated
nthe length of the string to copy, including its terminating null byte
Returns
the length of the string that was copied, excluding the terminating null byte

The given string src is copied until its null byte or until n - 1 bytes have been read. The destination buffer is guaranteed to be null-terminated.

Parameters
dstdestination of the copy (must be n bytes long)
srcsource of the copy (at most n - 1 bytes will be read)
nthe length of the string to copy, including its terminating null byte
Returns
the length of the string that was copied, excluding the terminating null byte

Definition at line 267 of file gnunet-helper-exit-windows.c.

References GNUNET_assert, ret, and strnlen().

Referenced by add_unixpath(), create_keys(), GCP_2s(), GNUNET_CONNECTION_create_from_connect_to_unixpath(), GNUNET_i2s(), GNUNET_i2s2(), GNUNET_STRINGS_absolute_time_to_string(), GNUNET_TESTBED_hosts_load_from_file(), handle_add_host(), handle_remote_overlay_connect(), main(), mylog(), regex_split(), resolve_interface_name(), setup_interface(), tokenizer_cb(), and try_unixpath().

268 {
269  size_t ret;
270  size_t slen;
271 
272  GNUNET_assert (0 != n);
273  slen = strnlen (src, n - 1);
274  memcpy (dst, src, slen);
275  dst[slen] = '\0';
276  return slen;
277 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static int ret
Final status code.
Definition: gnunet-arm.c:89
static size_t strnlen(const char *s, size_t n)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_STRINGS_parse_ipv4_policy()

struct GNUNET_STRINGS_IPv4NetworkPolicy* GNUNET_STRINGS_parse_ipv4_policy ( const char *  routeListX)

Parse an IPv4 network policy.

The argument specifies a list of subnets. The format is (network[/netmask][:[!]SPORT-DPORT];)* (no whitespace, must be terminated with a semicolon). The network must be given in dotted-decimal notation. The netmask can be given in CIDR notation (/16) or in dotted-decimal (/255.255.0.0).

Parameters
routeListXa string specifying the IPv4 subnets
Returns
the converted list, terminated with all zeros; NULL if the synatx is flawed

The argument specifies a list of subnets. The format is (network[/netmask][:SPORT[-DPORT]];)* (no whitespace, must be terminated with a semicolon). The network must be given in dotted-decimal notation. The netmask can be given in CIDR notation (/16) or in dotted-decimal (/255.255.0.0).

Parameters
routeListXa string specifying the IPv4 subnets
Returns
the converted list, terminated with all zeros; NULL if the synatx is flawed

Definition at line 1654 of file strings.c.

References _, dummy, end, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_malloc, GNUNET_OK, GNUNET_strdup, len, LOG, GNUNET_STRINGS_IPv4NetworkPolicy::netmask, GNUNET_STRINGS_IPv4NetworkPolicy::network, parse_port_policy(), GNUNET_STRINGS_IPv4NetworkPolicy::pp, result, and SSCANF.

Referenced by GNUNET_TUN_ipv4policy2regex(), and process_acl4().

1655 {
1656  unsigned int count;
1657  unsigned int i;
1658  unsigned int j;
1659  unsigned int len;
1660  int cnt;
1661  unsigned int pos;
1662  unsigned int temps[8];
1663  int slash;
1665  int colon;
1666  int end;
1667  char *routeList;
1668  char dummy[2];
1669 
1670  if (NULL == routeListX)
1671  return NULL;
1672  len = strlen (routeListX);
1673  if (0 == len)
1674  return NULL;
1675  routeList = GNUNET_strdup (routeListX);
1676  count = 0;
1677  for (i = 0; i < len; i++)
1678  if (routeList[i] == ';')
1679  count++;
1680  result = GNUNET_malloc (sizeof (struct GNUNET_STRINGS_IPv4NetworkPolicy) * (count + 1));
1681  i = 0;
1682  pos = 0;
1683  while (i < count)
1684  {
1685  for (colon = pos; ':' != routeList[colon]; colon++)
1686  if ( (';' == routeList[colon]) ||
1687  ('\0' == routeList[colon]) )
1688  break;
1689  for (end = colon; ';' != routeList[end]; end++)
1690  if ('\0' == routeList[end])
1691  break;
1692  if ('\0' == routeList[end])
1693  break;
1694  routeList[end] = '\0';
1695  if (':' == routeList[colon])
1696  {
1697  routeList[colon] = '\0';
1698  if (GNUNET_OK != parse_port_policy (&routeList[colon + 1],
1699  &result[i].pp))
1700  break;
1701  }
1702  cnt =
1703  SSCANF (&routeList[pos],
1704  "%u.%u.%u.%u/%u.%u.%u.%u%1s",
1705  &temps[0],
1706  &temps[1],
1707  &temps[2],
1708  &temps[3],
1709  &temps[4],
1710  &temps[5],
1711  &temps[6],
1712  &temps[7],
1713  dummy);
1714  if (8 == cnt)
1715  {
1716  for (j = 0; j < 8; j++)
1717  if (temps[j] > 0xFF)
1718  {
1720  _("Invalid format for IP: `%s'\n"),
1721  &routeList[pos]);
1722  GNUNET_free (result);
1723  GNUNET_free (routeList);
1724  return NULL;
1725  }
1726  result[i].network.s_addr =
1727  htonl ((temps[0] << 24) + (temps[1] << 16) + (temps[2] << 8) +
1728  temps[3]);
1729  result[i].netmask.s_addr =
1730  htonl ((temps[4] << 24) + (temps[5] << 16) + (temps[6] << 8) +
1731  temps[7]);
1732  pos = end + 1;
1733  i++;
1734  continue;
1735  }
1736  /* try second notation */
1737  cnt =
1738  SSCANF (&routeList[pos],
1739  "%u.%u.%u.%u/%u%1s",
1740  &temps[0],
1741  &temps[1],
1742  &temps[2],
1743  &temps[3],
1744  &slash,
1745  dummy);
1746  if (5 == cnt)
1747  {
1748  for (j = 0; j < 4; j++)
1749  if (temps[j] > 0xFF)
1750  {
1752  _("Invalid format for IP: `%s'\n"),
1753  &routeList[pos]);
1754  GNUNET_free (result);
1755  GNUNET_free (routeList);
1756  return NULL;
1757  }
1758  result[i].network.s_addr =
1759  htonl ((temps[0] << 24) + (temps[1] << 16) + (temps[2] << 8) +
1760  temps[3]);
1761  if ((slash <= 32) && (slash >= 0))
1762  {
1763  result[i].netmask.s_addr = 0;
1764  while (slash > 0)
1765  {
1766  result[i].netmask.s_addr =
1767  (result[i].netmask.s_addr >> 1) + 0x80000000;
1768  slash--;
1769  }
1770  result[i].netmask.s_addr = htonl (result[i].netmask.s_addr);
1771  pos = end + 1;
1772  i++;
1773  continue;
1774  }
1775  else
1776  {
1778  _("Invalid network notation ('/%d' is not legal in IPv4 CIDR)."),
1779  slash);
1780  GNUNET_free (result);
1781  GNUNET_free (routeList);
1782  return NULL; /* error */
1783  }
1784  }
1785  /* try third notation */
1786  slash = 32;
1787  cnt =
1788  SSCANF (&routeList[pos],
1789  "%u.%u.%u.%u%1s",
1790  &temps[0],
1791  &temps[1],
1792  &temps[2],
1793  &temps[3],
1794  dummy);
1795  if (4 == cnt)
1796  {
1797  for (j = 0; j < 4; j++)
1798  if (temps[j] > 0xFF)
1799  {
1801  _("Invalid format for IP: `%s'\n"),
1802  &routeList[pos]);
1803  GNUNET_free (result);
1804  GNUNET_free (routeList);
1805  return NULL;
1806  }
1807  result[i].network.s_addr =
1808  htonl ((temps[0] << 24) + (temps[1] << 16) + (temps[2] << 8) +
1809  temps[3]);
1810  result[i].netmask.s_addr = 0;
1811  while (slash > 0)
1812  {
1813  result[i].netmask.s_addr = (result[i].netmask.s_addr >> 1) + 0x80000000;
1814  slash--;
1815  }
1816  result[i].netmask.s_addr = htonl (result[i].netmask.s_addr);
1817  pos = end + 1;
1818  i++;
1819  continue;
1820  }
1822  _("Invalid format for IP: `%s'\n"),
1823  &routeList[pos]);
1824  GNUNET_free (result);
1825  GNUNET_free (routeList);
1826  return NULL; /* error */
1827  }
1828  if (pos < strlen (routeList))
1829  {
1831  _("Invalid format: `%s'\n"),
1832  &routeListX[pos]);
1833  GNUNET_free (result);
1834  GNUNET_free (routeList);
1835  return NULL; /* oops */
1836  }
1837  GNUNET_free (routeList);
1838  return result; /* ok */
1839 }
static int parse_port_policy(const char *port_policy, struct GNUNET_STRINGS_PortPolicy *pp)
Parse the given port policy.
Definition: strings.c:1584
static int end
Set if we are to shutdown all services (including ARM).
Definition: gnunet-arm.c:34
static struct in_addr dummy
Target "dummy" address.
struct in_addr netmask
IPv4 netmask.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
struct in_addr network
IPv4 address.
IPV4 network in CIDR notation.
static int result
Global testing status.
#define LOG(kind,...)
Definition: strings.c:37
#define SSCANF
Definition: plibc.h:691
struct GNUNET_STRINGS_PortPolicy pp
Policy for port access.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_STRINGS_parse_ipv6_policy()

struct GNUNET_STRINGS_IPv6NetworkPolicy* GNUNET_STRINGS_parse_ipv6_policy ( const char *  routeListX)

Parse an IPv6 network policy.

The argument specifies a list of subnets. The format is (network[/netmask[:[!]SPORT[-DPORT]]];)* (no whitespace, must be terminated with a semicolon). The network must be given in colon-hex notation. The netmask must be given in CIDR notation (/16) or can be omitted to specify a single host. Note that the netmask is mandatory if ports are specified.

Parameters
routeListXa string specifying the policy
Returns
the converted list, 0-terminated, NULL if the synatx is flawed

The argument specifies a list of subnets. The format is (network[/netmask[:SPORT[-DPORT]]];)* (no whitespace, must be terminated with a semicolon). The network must be given in colon-hex notation. The netmask must be given in CIDR notation (/16) or can be omitted to specify a single host. Note that the netmask is mandatory if ports are specified.

Parameters
routeListXa string specifying the policy
Returns
the converted list, 0-terminated, NULL if the synatx is flawed

Definition at line 1854 of file strings.c.

References _, dummy, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_malloc, GNUNET_OK, GNUNET_strdup, inet_pton(), len, LOG, LOG_STRERROR, GNUNET_STRINGS_IPv6NetworkPolicy::netmask, GNUNET_STRINGS_IPv6NetworkPolicy::network, parse_port_policy(), GNUNET_STRINGS_IPv6NetworkPolicy::pp, result, ret, save(), SSCANF, and start.

Referenced by GNUNET_TUN_ipv6policy2regex(), and process_acl6().

1855 {
1856  unsigned int count;
1857  unsigned int i;
1858  unsigned int len;
1859  unsigned int pos;
1860  int start;
1861  int slash;
1862  int ret;
1863  char *routeList;
1865  unsigned int bits;
1866  unsigned int off;
1867  int save;
1868  int colon;
1869  char dummy[2];
1870 
1871  if (NULL == routeListX)
1872  return NULL;
1873  len = strlen (routeListX);
1874  if (0 == len)
1875  return NULL;
1876  routeList = GNUNET_strdup (routeListX);
1877  count = 0;
1878  for (i = 0; i < len; i++)
1879  if (';' == routeList[i])
1880  count++;
1881  if (';' != routeList[len - 1])
1882  {
1884  _("Invalid network notation (does not end with ';': `%s')\n"),
1885  routeList);
1886  GNUNET_free (routeList);
1887  return NULL;
1888  }
1889 
1890  result = GNUNET_malloc (sizeof (struct GNUNET_STRINGS_IPv6NetworkPolicy) * (count + 1));
1891  i = 0;
1892  pos = 0;
1893  while (i < count)
1894  {
1895  start = pos;
1896  while (';' != routeList[pos])
1897  pos++;
1898  slash = pos;
1899  while ((slash >= start) && (routeList[slash] != '/'))
1900  slash--;
1901 
1902  if (slash < start)
1903  {
1904  memset (&result[i].netmask,
1905  0xFF,
1906  sizeof (struct in6_addr));
1907  slash = pos;
1908  }
1909  else
1910  {
1911  routeList[pos] = '\0';
1912  for (colon = pos; ':' != routeList[colon]; colon--)
1913  if ('/' == routeList[colon])
1914  break;
1915  if (':' == routeList[colon])
1916  {
1917  routeList[colon] = '\0';
1918  if (GNUNET_OK != parse_port_policy (&routeList[colon + 1],
1919  &result[i].pp))
1920  {
1921  GNUNET_free (result);
1922  GNUNET_free (routeList);
1923  return NULL;
1924  }
1925  }
1926  ret = inet_pton (AF_INET6, &routeList[slash + 1], &result[i].netmask);
1927  if (ret <= 0)
1928  {
1929  save = errno;
1930  if ( (1 != SSCANF (&routeList[slash + 1],
1931  "%u%1s",
1932  &bits,
1933  dummy)) ||
1934  (bits > 128) )
1935  {
1936  if (0 == ret)
1938  _("Wrong format `%s' for netmask\n"),
1939  &routeList[slash + 1]);
1940  else
1941  {
1942  errno = save;
1943  LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "inet_pton");
1944  }
1945  GNUNET_free (result);
1946  GNUNET_free (routeList);
1947  return NULL;
1948  }
1949  off = 0;
1950  while (bits > 8)
1951  {
1952  result[i].netmask.s6_addr[off++] = 0xFF;
1953  bits -= 8;
1954  }
1955  while (bits > 0)
1956  {
1957  result[i].netmask.s6_addr[off] =
1958  (result[i].netmask.s6_addr[off] >> 1) + 0x80;
1959  bits--;
1960  }
1961  }
1962  }
1963  routeList[slash] = '\0';
1964  ret = inet_pton (AF_INET6, &routeList[start], &result[i].network);
1965  if (ret <= 0)
1966  {
1967  if (0 == ret)
1969  _("Wrong format `%s' for network\n"),
1970  &routeList[slash + 1]);
1971  else
1973  "inet_pton");
1974  GNUNET_free (result);
1975  GNUNET_free (routeList);
1976  return NULL;
1977  }
1978  pos++;
1979  i++;
1980  }
1981  GNUNET_free (routeList);
1982  return result;
1983 }
static int parse_port_policy(const char *port_policy, struct GNUNET_STRINGS_PortPolicy *pp)
Parse the given port policy.
Definition: strings.c:1584
static struct in_addr dummy
Target "dummy" address.
struct GNUNET_STRINGS_PortPolicy pp
Policy for port access.
static int start
Set if we are to start default services (including ARM).
Definition: gnunet-arm.c:39
network in CIDR notation for IPV6.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
static int ret
Final status code.
Definition: gnunet-arm.c:89
static void save()
Write persistent statistics to disk.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
struct in6_addr netmask
IPv6 netmask.
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
static int result
Global testing status.
#define LOG(kind,...)
Definition: strings.c:37
#define LOG_STRERROR(kind, syscall)
Definition: strings.c:39
#define SSCANF
Definition: plibc.h:691
static int inet_pton(int af, const char *cp, struct in_addr *buf)
Convert IPv4 address from text to binary form.
struct in6_addr network
IPv6 address.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
Here is the call graph for this function:
Here is the caller graph for this function: