aboutsummaryrefslogtreecommitdiff
path: root/src/include/gnunet_strings_lib.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/include/gnunet_strings_lib.h')
-rw-r--r--src/include/gnunet_strings_lib.h174
1 files changed, 83 insertions, 91 deletions
diff --git a/src/include/gnunet_strings_lib.h b/src/include/gnunet_strings_lib.h
index db657f54e..25dfada42 100644
--- a/src/include/gnunet_strings_lib.h
+++ b/src/include/gnunet_strings_lib.h
@@ -16,7 +16,7 @@
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @author Christian Grothoff 22 * @author Christian Grothoff
@@ -61,8 +61,8 @@ extern "C"
61 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 61 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
62 */ 62 */
63int 63int
64GNUNET_STRINGS_fancy_size_to_bytes (const char *fancy_size, 64GNUNET_STRINGS_fancy_size_to_bytes(const char *fancy_size,
65 unsigned long long *size); 65 unsigned long long *size);
66 66
67 67
68/** 68/**
@@ -74,8 +74,8 @@ GNUNET_STRINGS_fancy_size_to_bytes (const char *fancy_size,
74 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 74 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
75 */ 75 */
76int 76int
77GNUNET_STRINGS_fancy_time_to_relative (const char *fancy_time, 77GNUNET_STRINGS_fancy_time_to_relative(const char *fancy_time,
78 struct GNUNET_TIME_Relative *rtime); 78 struct GNUNET_TIME_Relative *rtime);
79 79
80 80
81/** 81/**
@@ -89,8 +89,8 @@ GNUNET_STRINGS_fancy_time_to_relative (const char *fancy_time,
89 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 89 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
90 */ 90 */
91int 91int
92GNUNET_STRINGS_fancy_time_to_absolute (const char *fancy_time, 92GNUNET_STRINGS_fancy_time_to_absolute(const char *fancy_time,
93 struct GNUNET_TIME_Absolute *atime); 93 struct GNUNET_TIME_Absolute *atime);
94 94
95 95
96/** 96/**
@@ -100,7 +100,7 @@ GNUNET_STRINGS_fancy_time_to_absolute (const char *fancy_time,
100 * @return fancy representation of the size (possibly rounded) for humans 100 * @return fancy representation of the size (possibly rounded) for humans
101 */ 101 */
102char * 102char *
103GNUNET_STRINGS_byte_size_fancy (unsigned long long size); 103GNUNET_STRINGS_byte_size_fancy(unsigned long long size);
104 104
105 105
106/** 106/**
@@ -117,9 +117,9 @@ GNUNET_STRINGS_byte_size_fancy (unsigned long long size);
117 * string is returned. 117 * string is returned.
118 */ 118 */
119char * 119char *
120GNUNET_STRINGS_conv (const char *input, size_t len, 120GNUNET_STRINGS_conv(const char *input, size_t len,
121 const char *input_charset, 121 const char *input_charset,
122 const char *output_charset); 122 const char *output_charset);
123 123
124 124
125/** 125/**
@@ -133,9 +133,9 @@ GNUNET_STRINGS_conv (const char *input, size_t len,
133 * @return the converted string (0-terminated) 133 * @return the converted string (0-terminated)
134 */ 134 */
135char * 135char *
136GNUNET_STRINGS_to_utf8 (const char *input, 136GNUNET_STRINGS_to_utf8(const char *input,
137 size_t len, 137 size_t len,
138 const char *charset); 138 const char *charset);
139 139
140 140
141/** 141/**
@@ -150,9 +150,9 @@ GNUNET_STRINGS_to_utf8 (const char *input,
150 * string is returned. 150 * string is returned.
151 */ 151 */
152char * 152char *
153GNUNET_STRINGS_from_utf8 (const char *input, 153GNUNET_STRINGS_from_utf8(const char *input,
154 size_t len, 154 size_t len,
155 const char *charset); 155 const char *charset);
156 156
157 157
158/** 158/**
@@ -163,8 +163,8 @@ GNUNET_STRINGS_from_utf8 (const char *input,
163 * @param output output buffer 163 * @param output output buffer
164 */ 164 */
165void 165void
166GNUNET_STRINGS_utf8_tolower (const char *input, 166GNUNET_STRINGS_utf8_tolower(const char *input,
167 char *output); 167 char *output);
168 168
169 169
170/** 170/**
@@ -175,8 +175,8 @@ GNUNET_STRINGS_utf8_tolower (const char *input,
175 * @param output output buffer 175 * @param output output buffer
176 */ 176 */
177void 177void
178GNUNET_STRINGS_utf8_toupper (const char *input, 178GNUNET_STRINGS_utf8_toupper(const char *input,
179 char *output); 179 char *output);
180 180
181 181
182/** 182/**
@@ -188,7 +188,7 @@ GNUNET_STRINGS_utf8_toupper (const char *input,
188 * NULL is returned on error 188 * NULL is returned on error
189 */ 189 */
190char * 190char *
191GNUNET_STRINGS_filename_expand (const char *fil); 191GNUNET_STRINGS_filename_expand(const char *fil);
192 192
193 193
194/** 194/**
@@ -211,10 +211,10 @@ GNUNET_STRINGS_filename_expand (const char *fil);
211 * (or number of bytes that would have been written) 211 * (or number of bytes that would have been written)
212 */ 212 */
213size_t 213size_t
214GNUNET_STRINGS_buffer_fill (char *buffer, 214GNUNET_STRINGS_buffer_fill(char *buffer,
215 size_t size, 215 size_t size,
216 unsigned int count, 216 unsigned int count,
217 ...); 217 ...);
218 218
219 219
220/** 220/**
@@ -230,9 +230,9 @@ GNUNET_STRINGS_buffer_fill (char *buffer,
230 * in the buffer, or 0 on error. 230 * in the buffer, or 0 on error.
231 */ 231 */
232unsigned int 232unsigned int
233GNUNET_STRINGS_buffer_tokenize (const char *buffer, 233GNUNET_STRINGS_buffer_tokenize(const char *buffer,
234 size_t size, 234 size_t size,
235 unsigned int count, ...); 235 unsigned int count, ...);
236 236
237 237
238 238
@@ -247,7 +247,7 @@ GNUNET_STRINGS_buffer_tokenize (const char *buffer,
247 * @return timestamp in human-readable form in local time 247 * @return timestamp in human-readable form in local time
248 */ 248 */
249const char * 249const char *
250GNUNET_STRINGS_absolute_time_to_string (struct GNUNET_TIME_Absolute t); 250GNUNET_STRINGS_absolute_time_to_string(struct GNUNET_TIME_Absolute t);
251 251
252 252
253/** 253/**
@@ -261,8 +261,8 @@ GNUNET_STRINGS_absolute_time_to_string (struct GNUNET_TIME_Absolute t);
261 * @return string in human-readable form 261 * @return string in human-readable form
262 */ 262 */
263const char * 263const char *
264GNUNET_STRINGS_relative_time_to_string (struct GNUNET_TIME_Relative delta, 264GNUNET_STRINGS_relative_time_to_string(struct GNUNET_TIME_Relative delta,
265 int do_round); 265 int do_round);
266 266
267 267
268/** 268/**
@@ -277,7 +277,7 @@ GNUNET_STRINGS_relative_time_to_string (struct GNUNET_TIME_Relative delta,
277 * itself. 277 * itself.
278 */ 278 */
279const char * 279const char *
280GNUNET_STRINGS_get_short_name (const char *filename); 280GNUNET_STRINGS_get_short_name(const char *filename);
281 281
282 282
283/** 283/**
@@ -293,10 +293,10 @@ GNUNET_STRINGS_get_short_name (const char *filename);
293 * @return pointer to the next byte in 'out' or NULL on error. 293 * @return pointer to the next byte in 'out' or NULL on error.
294 */ 294 */
295char * 295char *
296GNUNET_STRINGS_data_to_string (const void *data, 296GNUNET_STRINGS_data_to_string(const void *data,
297 size_t size, 297 size_t size,
298 char *out, 298 char *out,
299 size_t out_size); 299 size_t out_size);
300 300
301 301
302/** 302/**
@@ -310,8 +310,8 @@ GNUNET_STRINGS_data_to_string (const void *data,
310 * @return freshly allocated, null-terminated string 310 * @return freshly allocated, null-terminated string
311 */ 311 */
312char * 312char *
313GNUNET_STRINGS_data_to_string_alloc (const void *buf, 313GNUNET_STRINGS_data_to_string_alloc(const void *buf,
314 size_t size); 314 size_t size);
315 315
316 316
317/** 317/**
@@ -325,10 +325,10 @@ GNUNET_STRINGS_data_to_string_alloc (const void *buf,
325 * @return #GNUNET_OK on success, #GNUNET_SYSERR if result has the wrong encoding 325 * @return #GNUNET_OK on success, #GNUNET_SYSERR if result has the wrong encoding
326 */ 326 */
327int 327int
328GNUNET_STRINGS_string_to_data (const char *enc, 328GNUNET_STRINGS_string_to_data(const char *enc,
329 size_t enclen, 329 size_t enclen,
330 void *out, 330 void *out,
331 size_t out_size); 331 size_t out_size);
332 332
333 333
334/** 334/**
@@ -341,9 +341,9 @@ GNUNET_STRINGS_string_to_data (const char *enc,
341 * @return the size of the output 341 * @return the size of the output
342 */ 342 */
343size_t 343size_t
344GNUNET_STRINGS_base64_encode (const void *in, 344GNUNET_STRINGS_base64_encode(const void *in,
345 size_t len, 345 size_t len,
346 char **output); 346 char **output);
347 347
348 348
349/** 349/**
@@ -356,9 +356,9 @@ GNUNET_STRINGS_base64_encode (const void *in,
356 * @return the size of the output 356 * @return the size of the output
357 */ 357 */
358size_t 358size_t
359GNUNET_STRINGS_base64_decode (const char *data, 359GNUNET_STRINGS_base64_decode(const char *data,
360 size_t len, 360 size_t len,
361 void **output); 361 void **output);
362 362
363 363
364/** 364/**
@@ -369,8 +369,8 @@ GNUNET_STRINGS_base64_decode (const char *data,
369 * @return string representing the array of @a pids 369 * @return string representing the array of @a pids
370 */ 370 */
371char * 371char *
372GNUNET_STRINGS_pp2s (const struct GNUNET_PeerIdentity *pids, 372GNUNET_STRINGS_pp2s(const struct GNUNET_PeerIdentity *pids,
373 unsigned int num_pids); 373 unsigned int num_pids);
374 374
375 375
376/** 376/**
@@ -390,9 +390,9 @@ GNUNET_STRINGS_pp2s (const struct GNUNET_PeerIdentity *pids,
390 * (if they weren't NULL). 390 * (if they weren't NULL).
391 */ 391 */
392int 392int
393GNUNET_STRINGS_parse_uri (const char *path, 393GNUNET_STRINGS_parse_uri(const char *path,
394 char **scheme_part, 394 char **scheme_part,
395 const char **path_part); 395 const char **path_part);
396 396
397 397
398/** 398/**
@@ -410,17 +410,16 @@ GNUNET_STRINGS_parse_uri (const char *path,
410 * @return #GNUNET_YES if 'filename' is absolute, #GNUNET_NO otherwise. 410 * @return #GNUNET_YES if 'filename' is absolute, #GNUNET_NO otherwise.
411 */ 411 */
412int 412int
413GNUNET_STRINGS_path_is_absolute (const char *filename, 413GNUNET_STRINGS_path_is_absolute(const char *filename,
414 int can_be_uri, 414 int can_be_uri,
415 int *r_is_uri, 415 int *r_is_uri,
416 char **r_uri_scheme); 416 char **r_uri_scheme);
417 417
418 418
419/** 419/**
420 * Flags for what we should check a file for. 420 * Flags for what we should check a file for.
421 */ 421 */
422enum GNUNET_STRINGS_FilenameCheck 422enum GNUNET_STRINGS_FilenameCheck {
423{
424 /** 423 /**
425 * Check that it exists. 424 * Check that it exists.
426 */ 425 */
@@ -453,8 +452,8 @@ enum GNUNET_STRINGS_FilenameCheck
453 * fails, #GNUNET_SYSERR when a check can't be performed 452 * fails, #GNUNET_SYSERR when a check can't be performed
454 */ 453 */
455int 454int
456GNUNET_STRINGS_check_filename (const char *filename, 455GNUNET_STRINGS_check_filename(const char *filename,
457 enum GNUNET_STRINGS_FilenameCheck checks); 456 enum GNUNET_STRINGS_FilenameCheck checks);
458 457
459 458
460/** 459/**
@@ -469,9 +468,9 @@ GNUNET_STRINGS_check_filename (const char *filename,
469 * case the contents of r_buf are undefined. 468 * case the contents of r_buf are undefined.
470 */ 469 */
471int 470int
472GNUNET_STRINGS_to_address_ipv6 (const char *zt_addr, 471GNUNET_STRINGS_to_address_ipv6(const char *zt_addr,
473 uint16_t addrlen, 472 uint16_t addrlen,
474 struct sockaddr_in6 *r_buf); 473 struct sockaddr_in6 *r_buf);
475 474
476 475
477/** 476/**
@@ -485,9 +484,9 @@ GNUNET_STRINGS_to_address_ipv6 (const char *zt_addr,
485 * the contents of r_buf are undefined. 484 * the contents of r_buf are undefined.
486 */ 485 */
487int 486int
488GNUNET_STRINGS_to_address_ipv4 (const char *zt_addr, 487GNUNET_STRINGS_to_address_ipv4(const char *zt_addr,
489 uint16_t addrlen, 488 uint16_t addrlen,
490 struct sockaddr_in *r_buf); 489 struct sockaddr_in *r_buf);
491 490
492 491
493/** 492/**
@@ -500,9 +499,9 @@ GNUNET_STRINGS_to_address_ipv4 (const char *zt_addr,
500 * @return 0 on error, otherwise number of bytes in @a sa 499 * @return 0 on error, otherwise number of bytes in @a sa
501 */ 500 */
502size_t 501size_t
503GNUNET_STRINGS_parse_socket_addr (const char *addr, 502GNUNET_STRINGS_parse_socket_addr(const char *addr,
504 uint8_t *af, 503 uint8_t *af,
505 struct sockaddr **sa); 504 struct sockaddr **sa);
506 505
507 506
508/** 507/**
@@ -517,9 +516,9 @@ GNUNET_STRINGS_parse_socket_addr (const char *addr,
517 * case the contents of r_buf are undefined. 516 * case the contents of r_buf are undefined.
518 */ 517 */
519int 518int
520GNUNET_STRINGS_to_address_ip (const char *addr, 519GNUNET_STRINGS_to_address_ip(const char *addr,
521 uint16_t addrlen, 520 uint16_t addrlen,
522 struct sockaddr_storage *r_buf); 521 struct sockaddr_storage *r_buf);
523 522
524 523
525/** 524/**
@@ -535,10 +534,10 @@ GNUNET_STRINGS_to_address_ip (const char *addr,
535 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure 534 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
536 */ 535 */
537int 536int
538GNUNET_STRINGS_get_utf8_args (int argc, 537GNUNET_STRINGS_get_utf8_args(int argc,
539 char *const *argv, 538 char *const *argv,
540 int *u8argc, 539 int *u8argc,
541 char *const **u8argv); 540 char *const **u8argv);
542 541
543 542
544/** 543/**
@@ -554,7 +553,7 @@ GNUNET_STRINGS_get_utf8_args (int argc,
554 * @param n the length of the string to copy, including its terminating null 553 * @param n the length of the string to copy, including its terminating null
555 * byte 554 * byte
556 * @return the length of the string that was copied, excluding the terminating 555 * @return the length of the string that was copied, excluding the terminating
557 * null byte 556 * null byte
558 */ 557 */
559size_t 558size_t
560GNUNET_strlcpy(char *dst, const char *src, size_t n); 559GNUNET_strlcpy(char *dst, const char *src, size_t n);
@@ -562,9 +561,7 @@ GNUNET_strlcpy(char *dst, const char *src, size_t n);
562 561
563/* ***************** IPv4/IPv6 parsing ****************** */ 562/* ***************** IPv4/IPv6 parsing ****************** */
564 563
565struct GNUNET_STRINGS_PortPolicy 564struct GNUNET_STRINGS_PortPolicy {
566{
567
568 /** 565 /**
569 * Starting port range (0 if none given). 566 * Starting port range (0 if none given).
570 */ 567 */
@@ -580,15 +577,13 @@ struct GNUNET_STRINGS_PortPolicy
580 * ("!" in policy). 577 * ("!" in policy).
581 */ 578 */
582 int negate_portrange; 579 int negate_portrange;
583
584}; 580};
585 581
586 582
587/** 583/**
588 * @brief IPV4 network in CIDR notation. 584 * @brief IPV4 network in CIDR notation.
589 */ 585 */
590struct GNUNET_STRINGS_IPv4NetworkPolicy 586struct GNUNET_STRINGS_IPv4NetworkPolicy {
591{
592 /** 587 /**
593 * IPv4 address. 588 * IPv4 address.
594 */ 589 */
@@ -603,15 +598,13 @@ struct GNUNET_STRINGS_IPv4NetworkPolicy
603 * Policy for port access. 598 * Policy for port access.
604 */ 599 */
605 struct GNUNET_STRINGS_PortPolicy pp; 600 struct GNUNET_STRINGS_PortPolicy pp;
606
607}; 601};
608 602
609 603
610/** 604/**
611 * @brief network in CIDR notation for IPV6. 605 * @brief network in CIDR notation for IPV6.
612 */ 606 */
613struct GNUNET_STRINGS_IPv6NetworkPolicy 607struct GNUNET_STRINGS_IPv6NetworkPolicy {
614{
615 /** 608 /**
616 * IPv6 address. 609 * IPv6 address.
617 */ 610 */
@@ -626,7 +619,6 @@ struct GNUNET_STRINGS_IPv6NetworkPolicy
626 * Policy for port access. 619 * Policy for port access.
627 */ 620 */
628 struct GNUNET_STRINGS_PortPolicy pp; 621 struct GNUNET_STRINGS_PortPolicy pp;
629
630}; 622};
631 623
632 624
@@ -642,7 +634,7 @@ struct GNUNET_STRINGS_IPv6NetworkPolicy
642 * NULL if the synatx is flawed 634 * NULL if the synatx is flawed
643 */ 635 */
644struct GNUNET_STRINGS_IPv4NetworkPolicy * 636struct GNUNET_STRINGS_IPv4NetworkPolicy *
645GNUNET_STRINGS_parse_ipv4_policy (const char *routeListX); 637GNUNET_STRINGS_parse_ipv4_policy(const char *routeListX);
646 638
647 639
648/** 640/**
@@ -657,7 +649,7 @@ GNUNET_STRINGS_parse_ipv4_policy (const char *routeListX);
657 * @return the converted list, 0-terminated, NULL if the synatx is flawed 649 * @return the converted list, 0-terminated, NULL if the synatx is flawed
658 */ 650 */
659struct GNUNET_STRINGS_IPv6NetworkPolicy * 651struct GNUNET_STRINGS_IPv6NetworkPolicy *
660GNUNET_STRINGS_parse_ipv6_policy (const char *routeListX); 652GNUNET_STRINGS_parse_ipv6_policy(const char *routeListX);
661 653
662 654
663#if 0 /* keep Emacsens' auto-indent happy */ 655#if 0 /* keep Emacsens' auto-indent happy */