GNUnet  0.10.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 
45 #ifdef __cplusplus
46 extern "C"
47 {
48 #if 0 /* keep Emacsens' auto-indent happy */
49 }
50 #endif
51 #endif
52 
53 #include "gnunet_time_lib.h"
54 
55 
63 int
64 GNUNET_STRINGS_fancy_size_to_bytes(const char *fancy_size,
65  unsigned long long *size);
66 
67 
76 int
77 GNUNET_STRINGS_fancy_time_to_relative(const char *fancy_time,
78  struct GNUNET_TIME_Relative *rtime);
79 
80 
91 int
92 GNUNET_STRINGS_fancy_time_to_absolute(const char *fancy_time,
93  struct GNUNET_TIME_Absolute *atime);
94 
95 
102 char *
103 GNUNET_STRINGS_byte_size_fancy(unsigned long long size);
104 
105 
119 char *
120 GNUNET_STRINGS_conv(const char *input, size_t len,
121  const char *input_charset,
122  const char *output_charset);
123 
124 
135 char *
136 GNUNET_STRINGS_to_utf8(const char *input,
137  size_t len,
138  const char *charset);
139 
140 
152 char *
153 GNUNET_STRINGS_from_utf8(const char *input,
154  size_t len,
155  const char *charset);
156 
157 
165 void
166 GNUNET_STRINGS_utf8_tolower(const char *input,
167  char *output);
168 
169 
177 void
178 GNUNET_STRINGS_utf8_toupper(const char *input,
179  char *output);
180 
181 
190 char *
191 GNUNET_STRINGS_filename_expand(const char *fil);
192 
193 
213 size_t
214 GNUNET_STRINGS_buffer_fill(char *buffer,
215  size_t size,
216  unsigned int count,
217  ...);
218 
219 
232 unsigned int
233 GNUNET_STRINGS_buffer_tokenize(const char *buffer,
234  size_t size,
235  unsigned int count, ...);
236 
237 
238 
249 const char *
251 
252 
263 const char *
265  int do_round);
266 
267 
279 const char *
281 
282 
295 char *
297  size_t size,
298  char *out,
299  size_t out_size);
300 
301 
312 char *
314  size_t size);
315 
316 
327 int
329  size_t enclen,
330  void *out,
331  size_t out_size);
332 
333 
343 size_t
344 GNUNET_STRINGS_base64_encode(const void *in,
345  size_t len,
346  char **output);
347 
348 
358 size_t
360  size_t len,
361  void **output);
362 
363 
371 char *
372 GNUNET_STRINGS_pp2s(const struct GNUNET_PeerIdentity *pids,
373  unsigned int num_pids);
374 
375 
392 int
393 GNUNET_STRINGS_parse_uri(const char *path,
394  char **scheme_part,
395  const char **path_part);
396 
397 
412 int
414  int can_be_uri,
415  int *r_is_uri,
416  char **r_uri_scheme);
417 
418 
427 
432 
437 
442 };
443 
444 
454 int
456  enum GNUNET_STRINGS_FilenameCheck checks);
457 
458 
470 int
471 GNUNET_STRINGS_to_address_ipv6(const char *zt_addr,
472  uint16_t addrlen,
473  struct sockaddr_in6 *r_buf);
474 
475 
486 int
487 GNUNET_STRINGS_to_address_ipv4(const char *zt_addr,
488  uint16_t addrlen,
489  struct sockaddr_in *r_buf);
490 
491 
501 size_t
502 GNUNET_STRINGS_parse_socket_addr(const char *addr,
503  uint8_t *af,
504  struct sockaddr **sa);
505 
506 
518 int
519 GNUNET_STRINGS_to_address_ip(const char *addr,
520  uint16_t addrlen,
521  struct sockaddr_storage *r_buf);
522 
523 
536 int
538  char *const *argv,
539  int *u8argc,
540  char *const **u8argv);
541 
542 
558 size_t
559 GNUNET_strlcpy(char *dst, const char *src, size_t n);
560 
561 
562 /* ***************** IPv4/IPv6 parsing ****************** */
563 
568  uint16_t start_port;
569 
573  uint16_t end_port;
574 
580 };
581 
582 
590  struct in_addr network;
591 
595  struct in_addr netmask;
596 
601 };
602 
603 
611  struct in6_addr network;
612 
616  struct in6_addr netmask;
617 
622 };
623 
624 
637 GNUNET_STRINGS_parse_ipv4_policy(const char *routeListX);
638 
639 
652 GNUNET_STRINGS_parse_ipv6_policy(const char *routeListX);
653 
654 
655 #if 0 /* keep Emacsens' auto-indent happy */
656 {
657 #endif
658 #ifdef __cplusplus
659 }
660 #endif
661 
662 /* ifndef GNUNET_UTIL_STRING_H */
663 #endif
664  /* end of group */
666 
667 /* end of gnunet_util_string.h */
static void do_round(void *cls)
Send out PUSHes and PULLs, possibly update #view, samplers.
struct GNUNET_STRINGS_IPv4NetworkPolicy * GNUNET_STRINGS_parse_ipv4_policy(const char *routeListX)
Parse an IPv4 network policy.
Definition: strings.c:1519
static struct GNUNET_TIME_Relative delta
Definition: speedup.c:35
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:446
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:1033
char * GNUNET_STRINGS_byte_size_fancy(unsigned long long size)
Convert a given filesize into a fancy human-readable format.
Definition: strings.c:175
uint16_t start_port
Starting port range (0 if none given).
struct GNUNET_STRINGS_IPv6NetworkPolicy * GNUNET_STRINGS_parse_ipv6_policy(const char *routeListX)
Parse an IPv6 network policy.
Definition: strings.c:1711
int GNUNET_STRINGS_get_utf8_args(int argc, char *const *argv, int *u8argc, char *const **u8argv)
Returns utf-8 encoded arguments.
Definition: strings.c:1439
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:1109
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:350
Check that the path is an absolute path.
network in CIDR notation for IPV6.
int negate_portrange
GNUNET_YES if the port range should be negated ("!" in policy).
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:401
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:318
static struct GNUNET_SCHEDULER_Task * t
Main task.
Check that it exists.
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.
Definition: strings.c:1278
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:135
void GNUNET_STRINGS_utf8_toupper(const char *input, char *output)
Convert the utf-8 input string to upper case.
Definition: strings.c:577
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:100
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:686
IPV4 network in CIDR notation.
static char buf[2048]
static char * filename
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:538
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:65
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:1351
size_t GNUNET_STRINGS_base64_decode(const char *data, size_t len, void **output)
Decode from Base64.
Definition: strings.c:1920
size_t GNUNET_STRINGS_base64_encode(const void *in, size_t len, char **output)
Encode into Base64.
Definition: strings.c:1856
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:776
static unsigned int size
Size of the "table".
Definition: peer.c:66
int GNUNET_STRINGS_check_filename(const char *filename, enum GNUNET_STRINGS_FilenameCheck checks)
Perform checks on filename.
Definition: strings.c:1159
char * GNUNET_STRINGS_filename_expand(const char *fil)
Complete filename (a la shell) from abbrevition.
Definition: strings.c:602
The identity of the host (wraps the signing key of the peer).
uint16_t end_port
End of port range (0 if none given).
static OpusEncoder * enc
OPUS encoder.
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:1204
GNUNET_STRINGS_FilenameCheck
Flags for what we should check a file for.
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:520
Time for absolute times used by GNUnet, in microseconds.
Check that it is a link.
char * GNUNET_STRINGS_data_to_string_alloc(const void *buf, size_t size)
Return the base32crockford encoding of the given buffer.
Definition: strings.c:921
const char * GNUNET_STRINGS_absolute_time_to_string(struct GNUNET_TIME_Absolute t)
Like asctime, except for GNUnet time.
Definition: strings.c:741
uint32_t data
The data value.
size_t GNUNET_strlcpy(char *dst, const char *src, size_t n)
Like strlcpy but portable.
Definition: strings.c:219
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.
Definition: strings.c:1327
int 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:953
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:857
Check that it is a directory.
Time for relative time used by GNUnet, in microseconds.
void GNUNET_STRINGS_utf8_tolower(const char *input, char *output)
Convert the utf-8 input string to lower case.
Definition: strings.c:552
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...