GNUnet  0.11.x
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 
36 #ifndef GNUNET_STRINGS_LIB_H
37 #define GNUNET_STRINGS_LIB_H
38 
39 /* we need size_t, and since it can be both unsigned int
40  or unsigned long long, this IS platform dependent;
41  but "stdlib.h" should be portable 'enough' to be
42  unconditionally available... */
43 #include <stdlib.h>
44 #include <sys/socket.h>
45 #include <netinet/in.h>
46 #include <netinet/ip.h>
47 
48 #ifdef __cplusplus
49 extern "C"
50 {
51 #if 0 /* keep Emacsens' auto-indent happy */
52 }
53 #endif
54 #endif
55 
56 #include "gnunet_time_lib.h"
57 
58 
66 int
67 GNUNET_STRINGS_fancy_size_to_bytes (const char *fancy_size,
68  unsigned long long *size);
69 
70 
79 int
80 GNUNET_STRINGS_fancy_time_to_relative (const char *fancy_time,
81  struct GNUNET_TIME_Relative *rtime);
82 
83 
94 int
95 GNUNET_STRINGS_fancy_time_to_absolute (const char *fancy_time,
96  struct GNUNET_TIME_Absolute *atime);
97 
98 
105 char *
106 GNUNET_STRINGS_byte_size_fancy (unsigned long long size);
107 
108 
122 char *
123 GNUNET_STRINGS_conv (const char *input,
124  size_t len,
125  const char *input_charset,
126  const char *output_charset);
127 
128 
139 char *
140 GNUNET_STRINGS_to_utf8 (const char *input,
141  size_t len,
142  const char *charset);
143 
144 
156 char *
157 GNUNET_STRINGS_from_utf8 (const char *input,
158  size_t len,
159  const char *charset);
160 
161 
169 void
170 GNUNET_STRINGS_utf8_tolower (const char *input,
171  char *output);
172 
173 
181 void
182 GNUNET_STRINGS_utf8_toupper (const char *input,
183  char *output);
184 
185 
194 char *
195 GNUNET_STRINGS_filename_expand (const char *fil);
196 
197 
217 size_t
218 GNUNET_STRINGS_buffer_fill (char *buffer,
219  size_t size,
220  unsigned int count,
221  ...);
222 
223 
236 unsigned int
237 GNUNET_STRINGS_buffer_tokenize (const char *buffer,
238  size_t size,
239  unsigned int count, ...);
240 
241 
252 const char *
254 
255 
266 const char *
268  int do_round);
269 
270 
282 const char *
284 
285 
298 char *
300  size_t size,
301  char *out,
302  size_t out_size);
303 
304 
315 char *
317  size_t size);
318 
319 
332  size_t enclen,
333  void *out,
334  size_t out_size);
335 
336 
350  size_t enclen,
351  void **out,
352  size_t *out_size);
353 
354 
364 size_t
365 GNUNET_STRINGS_base64_encode (const void *in,
366  size_t len,
367  char **output);
368 
369 
379 size_t
380 GNUNET_STRINGS_urlencode (const char *data,
381  size_t len,
382  char **out);
383 
384 
394 size_t
395 GNUNET_STRINGS_base64url_encode (const void *in,
396  size_t len,
397  char **output);
398 
399 
409 size_t
411  size_t len,
412  void **output);
413 
414 
424 size_t
426  size_t len,
427  void **out);
428 
438 size_t
439 GNUNET_STRINGS_urldecode (const char *data,
440  size_t len,
441  char **out);
442 
443 
451 char *
452 GNUNET_STRINGS_pp2s (const struct GNUNET_PeerIdentity *pids,
453  unsigned int num_pids);
454 
455 
473 GNUNET_STRINGS_parse_uri (const char *path,
474  char **scheme_part,
475  const char **path_part);
476 
477 
494  int can_be_uri,
495  int *r_is_uri,
496  char **r_uri_scheme);
497 
498 
503 {
508 
513 
518 
523 };
524 
525 
537  enum GNUNET_STRINGS_FilenameCheck checks);
538 
539 
552 GNUNET_STRINGS_to_address_ipv6 (const char *zt_addr,
553  uint16_t addrlen,
554  struct sockaddr_in6 *r_buf);
555 
556 
568 GNUNET_STRINGS_to_address_ipv4 (const char *zt_addr,
569  uint16_t addrlen,
570  struct sockaddr_in *r_buf);
571 
572 
582 size_t
583 GNUNET_STRINGS_parse_socket_addr (const char *addr,
584  uint8_t *af,
585  struct sockaddr **sa);
586 
587 
600 GNUNET_STRINGS_to_address_ip (const char *addr,
601  uint16_t addrlen,
602  struct sockaddr_storage *r_buf);
603 
604 
619  char *const *argv,
620  int *u8argc,
621  char *const **u8argv);
622 
623 
639 size_t
640 GNUNET_strlcpy (char *dst,
641  const char *src,
642  size_t n);
643 
644 
645 /* ***************** IPv4/IPv6 parsing ****************** */
646 
648 {
652  uint16_t start_port;
653 
657  uint16_t end_port;
658 
664 };
665 
666 
671 {
675  struct in_addr network;
676 
680  struct in_addr netmask;
681 
686 };
687 
688 
693 {
697  struct in6_addr network;
698 
702  struct in6_addr netmask;
703 
708 };
709 
710 
723 GNUNET_STRINGS_parse_ipv4_policy (const char *routeListX);
724 
725 
738 GNUNET_STRINGS_parse_ipv6_policy (const char *routeListX);
739 
740 
741 #if 0 /* keep Emacsens' auto-indent happy */
742 {
743 #endif
744 #ifdef __cplusplus
745 }
746 #endif
747 
748 /* ifndef GNUNET_UTIL_STRING_H */
749 #endif
750  /* end of group */
752 
753 /* 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.
GNUNET_GenericReturnValue
Named constants for return values.
Definition: gnunet_common.h:92
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:841
size_t GNUNET_STRINGS_base64url_decode(const char *data, size_t len, void **out)
Decode from Base64url.
Definition: strings.c:1747
struct GNUNET_STRINGS_IPv6NetworkPolicy * GNUNET_STRINGS_parse_ipv6_policy(const char *routeListX)
Parse an IPv6 network policy.
Definition: strings.c:1458
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:1136
char * GNUNET_STRINGS_filename_expand(const char *fil)
Complete filename (a la shell) from abbrevition.
Definition: strings.c:482
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:695
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:358
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:1121
char * GNUNET_STRINGS_pp2s(const struct GNUNET_PeerIdentity *pids, unsigned int num_pids)
Convert a peer path to a human-readable string.
Definition: strings.c:73
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:1083
size_t GNUNET_STRINGS_urldecode(const char *data, size_t len, char **out)
url/percent encode (RFC3986).
Definition: strings.c:1793
char * GNUNET_STRINGS_data_to_string_alloc(const void *buf, size_t size)
Return the base32crockford encoding of the given buffer.
Definition: strings.c:750
size_t GNUNET_STRINGS_urlencode(const char *data, size_t len, char **out)
url/percent encode (RFC3986).
Definition: strings.c:1830
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:775
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:96
char * GNUNET_STRINGS_byte_size_fancy(unsigned long long size)
Convert a given filesize into a fancy human-readable format.
Definition: strings.c:130
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:945
size_t GNUNET_STRINGS_base64url_encode(const void *in, size_t len, char **output)
Encode into Base64url.
Definition: strings.c:1643
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:883
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
void GNUNET_STRINGS_utf8_tolower(const char *input, char *output)
Convert the utf-8 input string to lower case.
Definition: strings.c:444
size_t GNUNET_STRINGS_base64_decode(const char *data, size_t len, void **output)
Decode from Base64.
Definition: strings.c:1682
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:1209
int 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:260
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:1020
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.
Definition: strings.c:284
size_t GNUNET_STRINGS_base64_encode(const void *in, size_t len, char **output)
Encode into Base64.
Definition: strings.c:1594
enum GNUNET_GenericReturnValue GNUNET_STRINGS_check_filename(const char *filename, enum GNUNET_STRINGS_FilenameCheck checks)
Perform checks on filename.
Definition: strings.c:987
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:626
struct GNUNET_STRINGS_IPv4NetworkPolicy * GNUNET_STRINGS_parse_ipv4_policy(const char *routeListX)
Parse an IPv4 network policy.
Definition: strings.c:1277
size_t GNUNET_strlcpy(char *dst, const char *src, size_t n)
Like strlcpy but portable.
Definition: strings.c:162
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:420
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:432
void GNUNET_STRINGS_utf8_toupper(const char *input, char *output)
Convert the utf-8 input string to upper case.
Definition: strings.c:463
@ 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.
int 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:326
const char * GNUNET_STRINGS_absolute_time_to_string(struct GNUNET_TIME_Absolute t)
Like asctime, except for GNUnet time.
Definition: strings.c:604
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:557
static unsigned int size
Size of the "table".
Definition: peer.c:67
static struct GNUNET_TIME_Relative delta
Definition: speedup.c:35
The identity of the host (wraps the signing key of the peer).
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.