diff options
Diffstat (limited to 'src/include/gnunet_strings_lib.h')
-rw-r--r-- | src/include/gnunet_strings_lib.h | 99 |
1 files changed, 75 insertions, 24 deletions
diff --git a/src/include/gnunet_strings_lib.h b/src/include/gnunet_strings_lib.h index 977c2ead7..df70c5e8f 100644 --- a/src/include/gnunet_strings_lib.h +++ b/src/include/gnunet_strings_lib.h | |||
@@ -18,7 +18,15 @@ | |||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | #if ! defined (__GNUNET_UTIL_LIB_H_INSIDE__) | ||
22 | #error "Only <gnunet_util_lib.h> can be included directly." | ||
23 | #endif | ||
24 | |||
21 | /** | 25 | /** |
26 | * @addtogroup libgnunetutil | ||
27 | * Multi-function utilities library for GNUnet programs | ||
28 | * @{ | ||
29 | * | ||
22 | * @author Christian Grothoff | 30 | * @author Christian Grothoff |
23 | * @author Krista Bennett | 31 | * @author Krista Bennett |
24 | * @author Gerd Knorr <kraxel@bytesex.org> | 32 | * @author Gerd Knorr <kraxel@bytesex.org> |
@@ -33,6 +41,10 @@ | |||
33 | * @{ | 41 | * @{ |
34 | */ | 42 | */ |
35 | 43 | ||
44 | #if ! defined (__GNUNET_UTIL_LIB_H_INSIDE__) | ||
45 | #error "Only <gnunet_util_lib.h> can be included directly." | ||
46 | #endif | ||
47 | |||
36 | #ifndef GNUNET_STRINGS_LIB_H | 48 | #ifndef GNUNET_STRINGS_LIB_H |
37 | #define GNUNET_STRINGS_LIB_H | 49 | #define GNUNET_STRINGS_LIB_H |
38 | 50 | ||
@@ -40,6 +52,7 @@ | |||
40 | or unsigned long long, this IS platform dependent; | 52 | or unsigned long long, this IS platform dependent; |
41 | but "stdlib.h" should be portable 'enough' to be | 53 | but "stdlib.h" should be portable 'enough' to be |
42 | unconditionally available... */ | 54 | unconditionally available... */ |
55 | |||
43 | #include <stdlib.h> | 56 | #include <stdlib.h> |
44 | #include <sys/socket.h> | 57 | #include <sys/socket.h> |
45 | #include <netinet/in.h> | 58 | #include <netinet/in.h> |
@@ -63,7 +76,7 @@ extern "C" | |||
63 | * @param size set to the size in bytes | 76 | * @param size set to the size in bytes |
64 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 77 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
65 | */ | 78 | */ |
66 | int | 79 | enum GNUNET_GenericReturnValue |
67 | GNUNET_STRINGS_fancy_size_to_bytes (const char *fancy_size, | 80 | GNUNET_STRINGS_fancy_size_to_bytes (const char *fancy_size, |
68 | unsigned long long *size); | 81 | unsigned long long *size); |
69 | 82 | ||
@@ -76,7 +89,7 @@ GNUNET_STRINGS_fancy_size_to_bytes (const char *fancy_size, | |||
76 | * @param rtime set to the relative time | 89 | * @param rtime set to the relative time |
77 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 90 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
78 | */ | 91 | */ |
79 | int | 92 | enum GNUNET_GenericReturnValue |
80 | GNUNET_STRINGS_fancy_time_to_relative (const char *fancy_time, | 93 | GNUNET_STRINGS_fancy_time_to_relative (const char *fancy_time, |
81 | struct GNUNET_TIME_Relative *rtime); | 94 | struct GNUNET_TIME_Relative *rtime); |
82 | 95 | ||
@@ -91,12 +104,27 @@ GNUNET_STRINGS_fancy_time_to_relative (const char *fancy_time, | |||
91 | * @param atime set to the absolute time | 104 | * @param atime set to the absolute time |
92 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 105 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
93 | */ | 106 | */ |
94 | int | 107 | enum GNUNET_GenericReturnValue |
95 | GNUNET_STRINGS_fancy_time_to_absolute (const char *fancy_time, | 108 | GNUNET_STRINGS_fancy_time_to_absolute (const char *fancy_time, |
96 | struct GNUNET_TIME_Absolute *atime); | 109 | struct GNUNET_TIME_Absolute *atime); |
97 | 110 | ||
98 | 111 | ||
99 | /** | 112 | /** |
113 | * @ingroup time | ||
114 | * Convert a given fancy human-readable time to our internal | ||
115 | * representation. The human-readable time is expected to be | ||
116 | * in local time, whereas the returned value will be in UTC. | ||
117 | * | ||
118 | * @param fancy_time human readable string (e.g. %Y-%m-%d %H:%M:%S) | ||
119 | * @param atime set to the absolute time | ||
120 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | ||
121 | */ | ||
122 | enum GNUNET_GenericReturnValue | ||
123 | GNUNET_STRINGS_fancy_time_to_timestamp (const char *fancy_time, | ||
124 | struct GNUNET_TIME_Timestamp *atime); | ||
125 | |||
126 | |||
127 | /** | ||
100 | * Convert a given filesize into a fancy human-readable format. | 128 | * Convert a given filesize into a fancy human-readable format. |
101 | * | 129 | * |
102 | * @param size number of bytes | 130 | * @param size number of bytes |
@@ -143,6 +171,16 @@ GNUNET_STRINGS_to_utf8 (const char *input, | |||
143 | 171 | ||
144 | 172 | ||
145 | /** | 173 | /** |
174 | * Normalize the utf-8 input string to NFC. | ||
175 | * | ||
176 | * @param input input string | ||
177 | * @return result (freshly allocated) or NULL on error. | ||
178 | */ | ||
179 | char* | ||
180 | GNUNET_STRINGS_utf8_normalize (const char *input); | ||
181 | |||
182 | |||
183 | /** | ||
146 | * Convert the len bytes-long UTF-8 string | 184 | * Convert the len bytes-long UTF-8 string |
147 | * given in input to the given charset. | 185 | * given in input to the given charset. |
148 | * | 186 | * |
@@ -165,8 +203,9 @@ GNUNET_STRINGS_from_utf8 (const char *input, | |||
165 | * | 203 | * |
166 | * @param input input string | 204 | * @param input input string |
167 | * @param output output buffer | 205 | * @param output output buffer |
206 | * @return GNUNET_OK on success | ||
168 | */ | 207 | */ |
169 | void | 208 | enum GNUNET_GenericReturnValue |
170 | GNUNET_STRINGS_utf8_tolower (const char *input, | 209 | GNUNET_STRINGS_utf8_tolower (const char *input, |
171 | char *output); | 210 | char *output); |
172 | 211 | ||
@@ -177,8 +216,9 @@ GNUNET_STRINGS_utf8_tolower (const char *input, | |||
177 | * | 216 | * |
178 | * @param input input string | 217 | * @param input input string |
179 | * @param output output buffer | 218 | * @param output output buffer |
219 | * @return #GNUNET_OK on success | ||
180 | */ | 220 | */ |
181 | void | 221 | enum GNUNET_GenericReturnValue |
182 | GNUNET_STRINGS_utf8_toupper (const char *input, | 222 | GNUNET_STRINGS_utf8_toupper (const char *input, |
183 | char *output); | 223 | char *output); |
184 | 224 | ||
@@ -370,15 +410,19 @@ GNUNET_STRINGS_base64_encode (const void *in, | |||
370 | /** | 410 | /** |
371 | * url/percent encode (RFC3986). | 411 | * url/percent encode (RFC3986). |
372 | * | 412 | * |
413 | * FIXME: awkward API, @a len is not actually used | ||
414 | * @a out is 0-terminated, should probably be changed | ||
415 | * to only input @a data and directly return @out or NULL. | ||
416 | * | ||
373 | * @param data the data to decode | 417 | * @param data the data to decode |
374 | * @param len the length of the input | 418 | * @param len the length of the input |
375 | * @param output where to write the output (*output should be NULL, | 419 | * @param out where to write the output (*out should be NULL, |
376 | * is allocated) | 420 | * is allocated) |
377 | * @return the size of the output | 421 | * @return the size of the output |
378 | */ | 422 | */ |
379 | size_t | 423 | size_t |
380 | GNUNET_STRINGS_urlencode (const char *data, | 424 | GNUNET_STRINGS_urlencode (size_t len, |
381 | size_t len, | 425 | const char data[static len], |
382 | char **out); | 426 | char **out); |
383 | 427 | ||
384 | 428 | ||
@@ -417,7 +461,7 @@ GNUNET_STRINGS_base64_decode (const char *data, | |||
417 | * | 461 | * |
418 | * @param data the data to decode | 462 | * @param data the data to decode |
419 | * @param len the length of the input | 463 | * @param len the length of the input |
420 | * @param output where to write the output (*output should be NULL, | 464 | * @param out where to write the output (*out should be NULL, |
421 | * is allocated) | 465 | * is allocated) |
422 | * @return the size of the output | 466 | * @return the size of the output |
423 | */ | 467 | */ |
@@ -431,7 +475,7 @@ GNUNET_STRINGS_base64url_decode (const char *data, | |||
431 | * | 475 | * |
432 | * @param data the data to encode | 476 | * @param data the data to encode |
433 | * @param len the length of the input | 477 | * @param len the length of the input |
434 | * @param output where to write the output (*output should be NULL, | 478 | * @param[out] out where to write the output (*output should be NULL, |
435 | * is allocated) | 479 | * is allocated) |
436 | * @return the size of the output | 480 | * @return the size of the output |
437 | */ | 481 | */ |
@@ -442,18 +486,6 @@ GNUNET_STRINGS_urldecode (const char *data, | |||
442 | 486 | ||
443 | 487 | ||
444 | /** | 488 | /** |
445 | * Convert a peer path to a human-readable string. | ||
446 | * | ||
447 | * @param pids array of PIDs to convert to a string | ||
448 | * @param num_pids length of the @a pids array | ||
449 | * @return string representing the array of @a pids | ||
450 | */ | ||
451 | char * | ||
452 | GNUNET_STRINGS_pp2s (const struct GNUNET_PeerIdentity *pids, | ||
453 | unsigned int num_pids); | ||
454 | |||
455 | |||
456 | /** | ||
457 | * Parse a path that might be an URI. | 489 | * Parse a path that might be an URI. |
458 | * | 490 | * |
459 | * @param path path to parse. Must be NULL-terminated. | 491 | * @param path path to parse. Must be NULL-terminated. |
@@ -550,7 +582,7 @@ GNUNET_STRINGS_check_filename (const char *filename, | |||
550 | */ | 582 | */ |
551 | enum GNUNET_GenericReturnValue | 583 | enum GNUNET_GenericReturnValue |
552 | GNUNET_STRINGS_to_address_ipv6 (const char *zt_addr, | 584 | GNUNET_STRINGS_to_address_ipv6 (const char *zt_addr, |
553 | uint16_t addrlen, | 585 | size_t addrlen, |
554 | struct sockaddr_in6 *r_buf); | 586 | struct sockaddr_in6 *r_buf); |
555 | 587 | ||
556 | 588 | ||
@@ -566,7 +598,7 @@ GNUNET_STRINGS_to_address_ipv6 (const char *zt_addr, | |||
566 | */ | 598 | */ |
567 | enum GNUNET_GenericReturnValue | 599 | enum GNUNET_GenericReturnValue |
568 | GNUNET_STRINGS_to_address_ipv4 (const char *zt_addr, | 600 | GNUNET_STRINGS_to_address_ipv4 (const char *zt_addr, |
569 | uint16_t addrlen, | 601 | size_t addrlen, |
570 | struct sockaddr_in *r_buf); | 602 | struct sockaddr_in *r_buf); |
571 | 603 | ||
572 | 604 | ||
@@ -642,6 +674,23 @@ GNUNET_strlcpy (char *dst, | |||
642 | size_t n); | 674 | size_t n); |
643 | 675 | ||
644 | 676 | ||
677 | /** | ||
678 | * Sometimes we use the binary name to determine which specific | ||
679 | * test to run. In those cases, the string after the last "_" | ||
680 | * in 'argv[0]' specifies a string that determines the configuration | ||
681 | * file or plugin to use. | ||
682 | * | ||
683 | * This function returns the respective substring, taking care | ||
684 | * of issues such as binaries ending in '.exe' on W32. | ||
685 | * | ||
686 | * @param argv0 the name of the binary | ||
687 | * @return string between the last '_' and the '.exe' (or the end of the string), | ||
688 | * NULL if argv0 has no '_' | ||
689 | */ | ||
690 | char * | ||
691 | GNUNET_STRINGS_get_suffix_from_binary_name (const char *argv0); | ||
692 | |||
693 | |||
645 | /* ***************** IPv4/IPv6 parsing ****************** */ | 694 | /* ***************** IPv4/IPv6 parsing ****************** */ |
646 | 695 | ||
647 | struct GNUNET_STRINGS_PortPolicy | 696 | struct GNUNET_STRINGS_PortPolicy |
@@ -750,4 +799,6 @@ GNUNET_STRINGS_parse_ipv6_policy (const char *routeListX); | |||
750 | 799 | ||
751 | /** @} */ /* end of group */ | 800 | /** @} */ /* end of group */ |
752 | 801 | ||
802 | /** @} */ /* end of group addition */ | ||
803 | |||
753 | /* end of gnunet_util_string.h */ | 804 | /* end of gnunet_util_string.h */ |