GNUnet  0.17.5
gnunet_strings_lib.h
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet.
3  Copyright (C) 2001-2013 GNUnet e.V.
4 
5  GNUnet is free software: you can redistribute it and/or modify it
6  under the terms of the GNU Affero General Public License as published
7  by the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  GNUnet is distributed in the hope that it will be useful, but
11  WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Affero General Public License for more details.
14 
15  You should have received a copy of the GNU Affero General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18  SPDX-License-Identifier: AGPL3.0-or-later
19  */
20 
40 #ifndef GNUNET_STRINGS_LIB_H
41 #define GNUNET_STRINGS_LIB_H
42 
43 /* we need size_t, and since it can be both unsigned int
44  or unsigned long long, this IS platform dependent;
45  but "stdlib.h" should be portable 'enough' to be
46  unconditionally available... */
47 #include <stdlib.h>
48 #include <sys/socket.h>
49 #include <netinet/in.h>
50 #include <netinet/ip.h>
51 
52 #ifdef __cplusplus
53 extern "C"
54 {
55 #if 0 /* keep Emacsens' auto-indent happy */
56 }
57 #endif
58 #endif
59 
60 #include "gnunet_time_lib.h"
61 
62 
71 GNUNET_STRINGS_fancy_size_to_bytes (const char *fancy_size,
72  unsigned long long *size);
73 
74 
84 GNUNET_STRINGS_fancy_time_to_relative (const char *fancy_time,
85  struct GNUNET_TIME_Relative *rtime);
86 
87 
99 GNUNET_STRINGS_fancy_time_to_absolute (const char *fancy_time,
100  struct GNUNET_TIME_Absolute *atime);
101 
102 
114 GNUNET_STRINGS_fancy_time_to_timestamp (const char *fancy_time,
115  struct GNUNET_TIME_Timestamp *atime);
116 
117 
124 char *
125 GNUNET_STRINGS_byte_size_fancy (unsigned long long size);
126 
127 
141 char *
142 GNUNET_STRINGS_conv (const char *input,
143  size_t len,
144  const char *input_charset,
145  const char *output_charset);
146 
147 
158 char *
159 GNUNET_STRINGS_to_utf8 (const char *input,
160  size_t len,
161  const char *charset);
162 
163 
170 char*
171 GNUNET_STRINGS_utf8_normalize (const char *input);
172 
173 
185 char *
186 GNUNET_STRINGS_from_utf8 (const char *input,
187  size_t len,
188  const char *charset);
189 
190 
200 GNUNET_STRINGS_utf8_tolower (const char *input,
201  char *output);
202 
203 
213 GNUNET_STRINGS_utf8_toupper (const char *input,
214  char *output);
215 
216 
225 char *
226 GNUNET_STRINGS_filename_expand (const char *fil);
227 
228 
248 size_t
249 GNUNET_STRINGS_buffer_fill (char *buffer,
250  size_t size,
251  unsigned int count,
252  ...);
253 
254 
267 unsigned int
268 GNUNET_STRINGS_buffer_tokenize (const char *buffer,
269  size_t size,
270  unsigned int count, ...);
271 
272 
283 const char *
285 
286 
297 const char *
299  int do_round);
300 
301 
313 const char *
315 
316 
329 char *
331  size_t size,
332  char *out,
333  size_t out_size);
334 
335 
346 char *
348  size_t size);
349 
350 
363  size_t enclen,
364  void *out,
365  size_t out_size);
366 
367 
381  size_t enclen,
382  void **out,
383  size_t *out_size);
384 
385 
395 size_t
396 GNUNET_STRINGS_base64_encode (const void *in,
397  size_t len,
398  char **output);
399 
400 
410 size_t
411 GNUNET_STRINGS_urlencode (const char *data,
412  size_t len,
413  char **out);
414 
415 
425 size_t
426 GNUNET_STRINGS_base64url_encode (const void *in,
427  size_t len,
428  char **output);
429 
430 
440 size_t
442  size_t len,
443  void **output);
444 
445 
455 size_t
457  size_t len,
458  void **out);
459 
469 size_t
470 GNUNET_STRINGS_urldecode (const char *data,
471  size_t len,
472  char **out);
473 
474 
492 GNUNET_STRINGS_parse_uri (const char *path,
493  char **scheme_part,
494  const char **path_part);
495 
496 
513  int can_be_uri,
514  int *r_is_uri,
515  char **r_uri_scheme);
516 
517 
522 {
527 
532 
537 
542 };
543 
544 
556  enum GNUNET_STRINGS_FilenameCheck checks);
557 
558 
571 GNUNET_STRINGS_to_address_ipv6 (const char *zt_addr,
572  uint16_t addrlen,
573  struct sockaddr_in6 *r_buf);
574 
575 
587 GNUNET_STRINGS_to_address_ipv4 (const char *zt_addr,
588  uint16_t addrlen,
589  struct sockaddr_in *r_buf);
590 
591 
601 size_t
602 GNUNET_STRINGS_parse_socket_addr (const char *addr,
603  uint8_t *af,
604  struct sockaddr **sa);
605 
606 
619 GNUNET_STRINGS_to_address_ip (const char *addr,
620  uint16_t addrlen,
621  struct sockaddr_storage *r_buf);
622 
623 
638  char *const *argv,
639  int *u8argc,
640  char *const **u8argv);
641 
642 
658 size_t
659 GNUNET_strlcpy (char *dst,
660  const char *src,
661  size_t n);
662 
663 
664 /* ***************** IPv4/IPv6 parsing ****************** */
665 
667 {
671  uint16_t start_port;
672 
676  uint16_t end_port;
677 
683 };
684 
685 
690 {
694  struct in_addr network;
695 
699  struct in_addr netmask;
700 
705 };
706 
707 
712 {
716  struct in6_addr network;
717 
721  struct in6_addr netmask;
722 
727 };
728 
729 
742 GNUNET_STRINGS_parse_ipv4_policy (const char *routeListX);
743 
744 
757 GNUNET_STRINGS_parse_ipv6_policy (const char *routeListX);
758 
759 
760 #if 0 /* keep Emacsens' auto-indent happy */
761 {
762 #endif
763 #ifdef __cplusplus
764 }
765 #endif
766 
767 /* ifndef GNUNET_UTIL_STRING_H */
768 #endif
769  /* end of group */
771  /* end of group addition */
773 
774 /* end of gnunet_util_string.h */
static char * filename
static OpusEncoder * enc
OPUS encoder.
uint32_t data
The data value.
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
static void do_round(void *cls)
Send out PUSHes and PULLs, possibly update #view, samplers.
static char buf[2048]
static struct GNUNET_SCHEDULER_Task * t
Main task.
Functions related to time.
GNUNET_GenericReturnValue
Named constants for return values.
Definition: gnunet_common.h:96
enum GNUNET_GenericReturnValue GNUNET_STRINGS_string_to_data_alloc(const char *enc, size_t enclen, void **out, size_t *out_size)
Convert CrockfordBase32 encoding back to data.
Definition: strings.c:855
size_t GNUNET_STRINGS_base64url_decode(const char *data, size_t len, void **out)
Decode from Base64url.
Definition: strings.c:1761
struct GNUNET_STRINGS_IPv6NetworkPolicy * GNUNET_STRINGS_parse_ipv6_policy(const char *routeListX)
Parse an IPv6 network policy.
Definition: strings.c:1472
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.
Definition: strings.c:1150
char * GNUNET_STRINGS_filename_expand(const char *fil)
Complete filename (a la shell) from abbrevition.
Definition: strings.c:495
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.
Definition: strings.c:709
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:344
enum GNUNET_GenericReturnValue 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.
Definition: strings.c:1135
GNUNET_STRINGS_FilenameCheck
Flags for what we should check a file for.
enum GNUNET_GenericReturnValue 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.
Definition: strings.c:1097
enum GNUNET_GenericReturnValue GNUNET_STRINGS_utf8_toupper(const char *input, char *output)
Convert the utf-8 input string to upper case.
Definition: strings.c:472
char * GNUNET_STRINGS_utf8_normalize(const char *input)
Normalize the utf-8 input string to NFC.
Definition: strings.c:430
size_t GNUNET_STRINGS_urldecode(const char *data, size_t len, char **out)
url/percent encode (RFC3986).
Definition: strings.c:1807
char * GNUNET_STRINGS_data_to_string_alloc(const void *buf, size_t size)
Return the base32crockford encoding of the given buffer.
Definition: strings.c:764
size_t GNUNET_STRINGS_urlencode(const char *data, size_t len, char **out)
url/percent encode (RFC3986).
Definition: strings.c:1851
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:789
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 ...
Definition: strings.c:73
char * GNUNET_STRINGS_byte_size_fancy(unsigned long long size)
Convert a given filesize into a fancy human-readable format.
Definition: strings.c:107
enum GNUNET_GenericReturnValue 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.
Definition: strings.c:959
size_t GNUNET_STRINGS_base64url_encode(const void *in, size_t len, char **output)
Encode into Base64url.
Definition: strings.c:1657
enum GNUNET_GenericReturnValue 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:897
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).
Definition: strings.c:45
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:261
size_t GNUNET_STRINGS_base64_decode(const char *data, size_t len, void **output)
Decode from Base64.
Definition: strings.c:1696
enum GNUNET_GenericReturnValue GNUNET_STRINGS_get_utf8_args(int argc, char *const *argv, int *u8argc, char *const **u8argv)
Returns utf-8 encoded arguments.
Definition: strings.c:1223
enum GNUNET_GenericReturnValue 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:1034
size_t GNUNET_STRINGS_base64_encode(const void *in, size_t len, char **output)
Encode into Base64.
Definition: strings.c:1608
enum GNUNET_GenericReturnValue GNUNET_STRINGS_utf8_tolower(const char *input, char *output)
Convert the utf-8 input string to lower case.
Definition: strings.c:450
enum GNUNET_GenericReturnValue GNUNET_STRINGS_check_filename(const char *filename, enum GNUNET_STRINGS_FilenameCheck checks)
Perform checks on filename.
Definition: strings.c:1001
const char * GNUNET_STRINGS_get_short_name(const char *filename)
"man basename" Returns a pointer to a part of filename (allocates nothing)!
Definition: strings.c:640
struct GNUNET_STRINGS_IPv4NetworkPolicy * GNUNET_STRINGS_parse_ipv4_policy(const char *routeListX)
Parse an IPv4 network policy.
Definition: strings.c:1291
size_t GNUNET_strlcpy(char *dst, const char *src, size_t n)
Like strlcpy but portable.
Definition: strings.c:139
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...
Definition: strings.c:406
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.
Definition: strings.c:418
enum GNUNET_GenericReturnValue GNUNET_STRINGS_fancy_size_to_bytes(const char *fancy_size, unsigned long long *size)
Convert a given fancy human-readable size to bytes.
Definition: strings.c:237
@ GNUNET_STRINGS_CHECK_IS_ABSOLUTE
Check that the path is an absolute path.
@ GNUNET_STRINGS_CHECK_IS_DIRECTORY
Check that it is a directory.
@ GNUNET_STRINGS_CHECK_EXISTS
Check that it exists.
@ GNUNET_STRINGS_CHECK_IS_LINK
Check that it is a link.
enum GNUNET_GenericReturnValue GNUNET_STRINGS_fancy_time_to_timestamp(const char *fancy_time, struct GNUNET_TIME_Timestamp *atime)
Convert a given fancy human-readable time to our internal representation.
Definition: strings.c:335
const char * GNUNET_STRINGS_absolute_time_to_string(struct GNUNET_TIME_Absolute t)
Like asctime, except for GNUnet time.
Definition: strings.c:617
const char * GNUNET_STRINGS_relative_time_to_string(struct GNUNET_TIME_Relative delta, int do_round)
Give relative time in human-readable fancy format.
Definition: strings.c:570
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:303
static unsigned int size
Size of the "table".
Definition: peer.c:67
static struct GNUNET_TIME_Relative delta
Definition: speedup.c:35
IPV4 network in CIDR notation.
struct in_addr network
IPv4 address.
struct GNUNET_STRINGS_PortPolicy pp
Policy for port access.
struct in_addr netmask
IPv4 netmask.
network in CIDR notation for IPV6.
struct GNUNET_STRINGS_PortPolicy pp
Policy for port access.
struct in6_addr network
IPv6 address.
struct in6_addr netmask
IPv6 netmask.
uint16_t start_port
Starting port range (0 if none given).
int negate_portrange
GNUNET_YES if the port range should be negated ("!" in policy).
uint16_t end_port
End of port range (0 if none given).
Time for absolute times used by GNUnet, in microseconds.
Time for relative time used by GNUnet, in microseconds.
Rounded time for timestamps used by GNUnet, in seconds.