GNUnet  0.19.3
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 
21 #if !defined (__GNUNET_UTIL_LIB_H_INSIDE__)
22 #error "Only <gnunet_util_lib.h> can be included directly."
23 #endif
24 
44 #if !defined (__GNUNET_UTIL_LIB_H_INSIDE__)
45 #error "Only <gnunet_util_lib.h> can be included directly."
46 #endif
47 
48 #ifndef GNUNET_STRINGS_LIB_H
49 #define GNUNET_STRINGS_LIB_H
50 
51 /* we need size_t, and since it can be both unsigned int
52  or unsigned long long, this IS platform dependent;
53  but "stdlib.h" should be portable 'enough' to be
54  unconditionally available... */
55 
56 #include <stdlib.h>
57 #include <sys/socket.h>
58 #include <netinet/in.h>
59 #include <netinet/ip.h>
60 
61 #ifdef __cplusplus
62 extern "C"
63 {
64 #if 0 /* keep Emacsens' auto-indent happy */
65 }
66 #endif
67 #endif
68 
69 #include "gnunet_time_lib.h"
70 
71 
80 GNUNET_STRINGS_fancy_size_to_bytes (const char *fancy_size,
81  unsigned long long *size);
82 
83 
93 GNUNET_STRINGS_fancy_time_to_relative (const char *fancy_time,
94  struct GNUNET_TIME_Relative *rtime);
95 
96 
108 GNUNET_STRINGS_fancy_time_to_absolute (const char *fancy_time,
109  struct GNUNET_TIME_Absolute *atime);
110 
111 
123 GNUNET_STRINGS_fancy_time_to_timestamp (const char *fancy_time,
124  struct GNUNET_TIME_Timestamp *atime);
125 
126 
133 char *
134 GNUNET_STRINGS_byte_size_fancy (unsigned long long size);
135 
136 
150 char *
151 GNUNET_STRINGS_conv (const char *input,
152  size_t len,
153  const char *input_charset,
154  const char *output_charset);
155 
156 
167 char *
168 GNUNET_STRINGS_to_utf8 (const char *input,
169  size_t len,
170  const char *charset);
171 
172 
179 char*
180 GNUNET_STRINGS_utf8_normalize (const char *input);
181 
182 
194 char *
195 GNUNET_STRINGS_from_utf8 (const char *input,
196  size_t len,
197  const char *charset);
198 
199 
209 GNUNET_STRINGS_utf8_tolower (const char *input,
210  char *output);
211 
212 
222 GNUNET_STRINGS_utf8_toupper (const char *input,
223  char *output);
224 
225 
234 char *
235 GNUNET_STRINGS_filename_expand (const char *fil);
236 
237 
257 size_t
258 GNUNET_STRINGS_buffer_fill (char *buffer,
259  size_t size,
260  unsigned int count,
261  ...);
262 
263 
276 unsigned int
277 GNUNET_STRINGS_buffer_tokenize (const char *buffer,
278  size_t size,
279  unsigned int count, ...);
280 
281 
292 const char *
294 
295 
306 const char *
308  int do_round);
309 
310 
322 const char *
324 
325 
338 char *
340  size_t size,
341  char *out,
342  size_t out_size);
343 
344 
355 char *
357  size_t size);
358 
359 
372  size_t enclen,
373  void *out,
374  size_t out_size);
375 
376 
390  size_t enclen,
391  void **out,
392  size_t *out_size);
393 
394 
404 size_t
405 GNUNET_STRINGS_base64_encode (const void *in,
406  size_t len,
407  char **output);
408 
409 
419 size_t
420 GNUNET_STRINGS_urlencode (const char *data,
421  size_t len,
422  char **out);
423 
424 
434 size_t
435 GNUNET_STRINGS_base64url_encode (const void *in,
436  size_t len,
437  char **output);
438 
439 
449 size_t
451  size_t len,
452  void **output);
453 
454 
464 size_t
466  size_t len,
467  void **out);
468 
478 size_t
479 GNUNET_STRINGS_urldecode (const char *data,
480  size_t len,
481  char **out);
482 
483 
501 GNUNET_STRINGS_parse_uri (const char *path,
502  char **scheme_part,
503  const char **path_part);
504 
505 
522  int can_be_uri,
523  int *r_is_uri,
524  char **r_uri_scheme);
525 
526 
531 {
536 
541 
546 
551 };
552 
553 
565  enum GNUNET_STRINGS_FilenameCheck checks);
566 
567 
580 GNUNET_STRINGS_to_address_ipv6 (const char *zt_addr,
581  uint16_t addrlen,
582  struct sockaddr_in6 *r_buf);
583 
584 
596 GNUNET_STRINGS_to_address_ipv4 (const char *zt_addr,
597  uint16_t addrlen,
598  struct sockaddr_in *r_buf);
599 
600 
610 size_t
611 GNUNET_STRINGS_parse_socket_addr (const char *addr,
612  uint8_t *af,
613  struct sockaddr **sa);
614 
615 
628 GNUNET_STRINGS_to_address_ip (const char *addr,
629  uint16_t addrlen,
630  struct sockaddr_storage *r_buf);
631 
632 
647  char *const *argv,
648  int *u8argc,
649  char *const **u8argv);
650 
651 
667 size_t
668 GNUNET_strlcpy (char *dst,
669  const char *src,
670  size_t n);
671 
672 
673 /* ***************** IPv4/IPv6 parsing ****************** */
674 
676 {
680  uint16_t start_port;
681 
685  uint16_t end_port;
686 
692 };
693 
694 
699 {
703  struct in_addr network;
704 
708  struct in_addr netmask;
709 
714 };
715 
716 
721 {
725  struct in6_addr network;
726 
730  struct in6_addr netmask;
731 
736 };
737 
738 
751 GNUNET_STRINGS_parse_ipv4_policy (const char *routeListX);
752 
753 
766 GNUNET_STRINGS_parse_ipv6_policy (const char *routeListX);
767 
768 
769 #if 0 /* keep Emacsens' auto-indent happy */
770 {
771 #endif
772 #ifdef __cplusplus
773 }
774 #endif
775 
776 /* ifndef GNUNET_UTIL_STRING_H */
777 #endif
778  /* end of group */
780  /* end of group addition */
782 
783 /* 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.
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:854
size_t GNUNET_STRINGS_base64url_decode(const char *data, size_t len, void **out)
Decode from Base64url.
Definition: strings.c:1760
struct GNUNET_STRINGS_IPv6NetworkPolicy * GNUNET_STRINGS_parse_ipv6_policy(const char *routeListX)
Parse an IPv6 network policy.
Definition: strings.c:1471
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:1149
char * GNUNET_STRINGS_filename_expand(const char *fil)
Complete filename (a la shell) from abbrevition.
Definition: strings.c:494
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:708
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:343
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:1134
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:1096
enum GNUNET_GenericReturnValue GNUNET_STRINGS_utf8_toupper(const char *input, char *output)
Convert the utf-8 input string to upper case.
Definition: strings.c:471
char * GNUNET_STRINGS_utf8_normalize(const char *input)
Normalize the utf-8 input string to NFC.
Definition: strings.c:429
size_t GNUNET_STRINGS_urldecode(const char *data, size_t len, char **out)
url/percent encode (RFC3986).
Definition: strings.c:1806
char * GNUNET_STRINGS_data_to_string_alloc(const void *buf, size_t size)
Return the base32crockford encoding of the given buffer.
Definition: strings.c:763
size_t GNUNET_STRINGS_urlencode(const char *data, size_t len, char **out)
url/percent encode (RFC3986).
Definition: strings.c:1850
enum GNUNET_GenericReturnValue GNUNET_STRINGS_string_to_data(const char *enc, size_t enclen, void *out, size_t out_size)
Convert CrockfordBase32 encoding back to data.
Definition: strings.c:788
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:72
char * GNUNET_STRINGS_byte_size_fancy(unsigned long long size)
Convert a given filesize into a fancy human-readable format.
Definition: strings.c:106
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:958
size_t GNUNET_STRINGS_base64url_encode(const void *in, size_t len, char **output)
Encode into Base64url.
Definition: strings.c:1656
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:896
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:44
enum GNUNET_GenericReturnValue GNUNET_STRINGS_fancy_time_to_relative(const char *fancy_time, struct GNUNET_TIME_Relative *rtime)
Convert a given fancy human-readable time to our internal representation.
Definition: strings.c:260
size_t GNUNET_STRINGS_base64_decode(const char *data, size_t len, void **output)
Decode from Base64.
Definition: strings.c:1695
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:1222
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:1033
size_t GNUNET_STRINGS_base64_encode(const void *in, size_t len, char **output)
Encode into Base64.
Definition: strings.c:1607
enum GNUNET_GenericReturnValue GNUNET_STRINGS_utf8_tolower(const char *input, char *output)
Convert the utf-8 input string to lower case.
Definition: strings.c:449
enum GNUNET_GenericReturnValue GNUNET_STRINGS_check_filename(const char *filename, enum GNUNET_STRINGS_FilenameCheck checks)
Perform checks on filename.
Definition: strings.c:1000
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:639
struct GNUNET_STRINGS_IPv4NetworkPolicy * GNUNET_STRINGS_parse_ipv4_policy(const char *routeListX)
Parse an IPv4 network policy.
Definition: strings.c:1290
size_t GNUNET_strlcpy(char *dst, const char *src, size_t n)
Like strlcpy but portable.
Definition: strings.c:138
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:405
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:417
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:236
@ 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:334
const char * GNUNET_STRINGS_absolute_time_to_string(struct GNUNET_TIME_Absolute t)
Like asctime, except for GNUnet time.
Definition: strings.c:616
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:569
enum GNUNET_GenericReturnValue GNUNET_STRINGS_fancy_time_to_absolute(const char *fancy_time, struct GNUNET_TIME_Absolute *atime)
Convert a given fancy human-readable time to our internal representation.
Definition: strings.c:302
static unsigned int size
Size of the "table".
Definition: peer.c:68
static struct GNUNET_TIME_Relative delta
Definition: speedup.c:36
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.