gnunet_strings_lib.h (24424B)
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 25 /** 26 * @addtogroup libgnunetutil 27 * Multi-function utilities library for GNUnet programs 28 * @{ 29 * 30 * @author Christian Grothoff 31 * @author Krista Bennett 32 * @author Gerd Knorr <kraxel@bytesex.org> 33 * @author Ioana Patrascu 34 * @author Tzvetan Horozov 35 * 36 * @file 37 * Strings and string handling functions 38 * 39 * @defgroup strings Strings library 40 * Strings and string handling functions, including malloc and string tokenizing. 41 * @{ 42 */ 43 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 72 /** 73 * Convert a given fancy human-readable size to bytes. 74 * 75 * @param fancy_size human readable string (e.g. 1 MB) 76 * @param size set to the size in bytes 77 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 78 */ 79 enum GNUNET_GenericReturnValue 80 GNUNET_STRINGS_fancy_size_to_bytes (const char *fancy_size, 81 unsigned long long *size); 82 83 84 /** 85 * Convert a given fancy human-readable time to our internal 86 * representation. 87 * 88 * @param fancy_time human readable string (e.g. 1 minute) 89 * @param rtime set to the relative time 90 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 91 */ 92 enum GNUNET_GenericReturnValue 93 GNUNET_STRINGS_fancy_time_to_relative (const char *fancy_time, 94 struct GNUNET_TIME_Relative *rtime); 95 96 97 /** 98 * @ingroup time 99 * Convert a given fancy human-readable time to our internal 100 * representation. The human-readable time is expected to be 101 * in local time, whereas the returned value will be in UTC. 102 * 103 * @param fancy_time human readable string (e.g. %Y-%m-%d %H:%M:%S) 104 * @param atime set to the absolute time 105 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 106 */ 107 enum GNUNET_GenericReturnValue 108 GNUNET_STRINGS_fancy_time_to_absolute (const char *fancy_time, 109 struct GNUNET_TIME_Absolute *atime); 110 111 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 /** 128 * Convert a given filesize into a fancy human-readable format. 129 * 130 * @param size number of bytes 131 * @return fancy representation of the size (possibly rounded) for humans 132 */ 133 char * 134 GNUNET_STRINGS_byte_size_fancy (unsigned long long size); 135 136 137 /** 138 * Convert the len characters long character sequence 139 * given in input that is in the given input charset 140 * to a string in given output charset. 141 * 142 * @param input input string 143 * @param len number of bytes in @a input 144 * @param input_charset character set used for @a input 145 * @param output_charset desired character set for the return value 146 * @return the converted string (0-terminated), 147 * if conversion fails, a copy of the original 148 * string is returned. 149 */ 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 157 /** 158 * Convert the len characters long character sequence 159 * given in input that is in the given charset 160 * to UTF-8. 161 * 162 * @param input the input string (not necessarily 0-terminated) 163 * @param len the number of bytes in the @a input 164 * @param charset character set to convert from 165 * @return the converted string (0-terminated) 166 */ 167 char * 168 GNUNET_STRINGS_to_utf8 (const char *input, 169 size_t len, 170 const char *charset); 171 172 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 /** 184 * Convert the len bytes-long UTF-8 string 185 * given in input to the given charset. 186 * 187 * @param input the input string (not necessarily 0-terminated) 188 * @param len the number of bytes in the @a input 189 * @param charset character set to convert to 190 * @return the converted string (0-terminated), 191 * if conversion fails, a copy of the original 192 * string is returned. 193 */ 194 char * 195 GNUNET_STRINGS_from_utf8 (const char *input, 196 size_t len, 197 const char *charset); 198 199 200 /** 201 * Convert the utf-8 input string to lower case. 202 * Output needs to be allocated appropriately. 203 * 204 * @param input input string 205 * @param output output buffer 206 * @return GNUNET_OK on success 207 */ 208 enum GNUNET_GenericReturnValue 209 GNUNET_STRINGS_utf8_tolower (const char *input, 210 char *output); 211 212 213 /** 214 * Convert the utf-8 input string to upper case. 215 * Output needs to be allocated appropriately. 216 * 217 * @param input input string 218 * @param output output buffer 219 * @return #GNUNET_OK on success 220 */ 221 enum GNUNET_GenericReturnValue 222 GNUNET_STRINGS_utf8_toupper (const char *input, 223 char *output); 224 225 226 /** 227 * Complete filename (a la shell) from abbrevition. 228 * 229 * @param fil the name of the file, may contain ~/ or 230 * be relative to the current directory 231 * @return the full file name, 232 * NULL is returned on error 233 */ 234 char * 235 GNUNET_STRINGS_filename_expand (const char *fil); 236 237 238 /** 239 * Fill a buffer of the given size with count 0-terminated strings 240 * (given as varargs). If "buffer" is NULL, only compute the amount 241 * of space required (sum of "strlen(arg)+1"). 242 * 243 * Unlike using "snprintf" with "%s", this function will add 244 * 0-terminators after each string. The 245 * "GNUNET_string_buffer_tokenize" function can be used to parse the 246 * buffer back into individual strings. 247 * 248 * @param buffer the buffer to fill with strings, can 249 * be NULL in which case only the necessary 250 * amount of space will be calculated 251 * @param size number of bytes available in buffer 252 * @param count number of strings that follow 253 * @param ... count 0-terminated strings to copy to buffer 254 * @return number of bytes written to the buffer 255 * (or number of bytes that would have been written) 256 */ 257 size_t 258 GNUNET_STRINGS_buffer_fill (char *buffer, 259 size_t size, 260 unsigned int count, 261 ...); 262 263 264 /** 265 * Given a buffer of a given size, find "count" 0-terminated strings 266 * in the buffer and assign the count (varargs) of type "const char**" 267 * to the locations of the respective strings in the buffer. 268 * 269 * @param buffer the buffer to parse 270 * @param size size of the @a buffer 271 * @param count number of strings to locate 272 * @param ... pointers to where to store the strings 273 * @return offset of the character after the last 0-termination 274 * in the buffer, or 0 on error. 275 */ 276 unsigned int 277 GNUNET_STRINGS_buffer_tokenize (const char *buffer, 278 size_t size, 279 unsigned int count, ...); 280 281 282 /** 283 * @ingroup time 284 * Like `asctime`, except for GNUnet time. Converts a GNUnet internal 285 * absolute time (which is in UTC) to a string in local time. 286 * Note that the returned value will be overwritten if this function 287 * is called again. 288 * 289 * @param t the timestamp to convert 290 * @return timestamp in human-readable form in local time 291 */ 292 const char * 293 GNUNET_STRINGS_timestamp_to_string (struct GNUNET_TIME_Timestamp t); 294 295 /** 296 * @ingroup time 297 * Like `asctime`, except for GNUnet time. Converts a GNUnet internal 298 * absolute time (which is in UTC) to a string in local time. 299 * Note that the returned value will be overwritten if this function 300 * is called again. 301 * 302 * @param t the absolute time to convert 303 * @return timestamp in human-readable form in local time 304 */ 305 const char * 306 GNUNET_STRINGS_absolute_time_to_string (struct GNUNET_TIME_Absolute t); 307 308 309 /** 310 * @ingroup time 311 * Give relative time in human-readable fancy format. 312 * This is one of the very few calls in the entire API that is 313 * NOT reentrant! 314 * 315 * @param delta time in milli seconds 316 * @param do_round are we allowed to round a bit? 317 * @return string in human-readable form 318 */ 319 const char * 320 GNUNET_STRINGS_relative_time_to_string (struct GNUNET_TIME_Relative delta, 321 int do_round); 322 323 324 /** 325 * "man basename" 326 * Returns a pointer to a part of filename (allocates nothing)! 327 * 328 * @param filename filename to extract basename from 329 * @return short (base) name of the file (that is, everything following the 330 * last directory separator in filename. If filename ends with a 331 * directory separator, the result will be a zero-length string. 332 * If filename has no directory separators, the result is filename 333 * itself. 334 */ 335 const char * 336 GNUNET_STRINGS_get_short_name (const char *filename); 337 338 339 /** 340 * Convert binary data to ASCII encoding using CrockfordBase32. 341 * Does not append 0-terminator, but returns a pointer to the place where 342 * it should be placed, if needed. 343 * 344 * @param data data to encode 345 * @param size size of data (in bytes) 346 * @param out buffer to fill 347 * @param out_size size of the buffer. Must be large enough to hold 348 * ((size*8) + (((size*8) % 5) > 0 ? 5 - ((size*8) % 5) : 0)) / 5 349 * @return pointer to the next byte in 'out' or NULL on error. 350 */ 351 char * 352 GNUNET_STRINGS_data_to_string (const void *data, 353 size_t size, 354 char *out, 355 size_t out_size); 356 357 358 /** 359 * Return the base32crockford encoding of the given buffer. 360 * 361 * The returned string will be freshly allocated, and must be free'd 362 * with #GNUNET_free(). 363 * 364 * @param buf buffer with data 365 * @param size size of the buffer @a buf 366 * @return freshly allocated, null-terminated string 367 */ 368 char * 369 GNUNET_STRINGS_data_to_string_alloc (const void *buf, 370 size_t size); 371 372 373 /** 374 * Convert CrockfordBase32 encoding back to data. 375 * @a out_size must match exactly the size of the data before it was encoded. 376 * 377 * @param enc the encoding 378 * @param enclen number of characters in @a enc (without 0-terminator, which can be missing) 379 * @param out location where to store the decoded data 380 * @param out_size size of the output buffer @a out 381 * @return #GNUNET_OK on success, #GNUNET_SYSERR if result has the wrong encoding 382 */ 383 enum GNUNET_GenericReturnValue 384 GNUNET_STRINGS_string_to_data (const char *enc, 385 size_t enclen, 386 void *out, 387 size_t out_size); 388 389 390 /** 391 * Convert CrockfordBase32 encoding back to data. 392 * @a out_size will be determined from @a enc and 393 * @a out will be allocated to be large enough. 394 * 395 * @param enc the encoding 396 * @param enclen number of characters in @a enc (without 0-terminator, which can be missing) 397 * @param[out] out location where to allocate and store the decoded data 398 * @param[out] out_size set to the size of the output buffer @a out 399 * @return #GNUNET_OK on success, #GNUNET_SYSERR if result has the wrong encoding 400 */ 401 enum GNUNET_GenericReturnValue 402 GNUNET_STRINGS_string_to_data_alloc (const char *enc, 403 size_t enclen, 404 void **out, 405 size_t *out_size); 406 407 408 /** 409 * Encode into Base64. 410 * 411 * @param data the data to encode 412 * @param len the length of the input 413 * @param output where to write the output (*output should be NULL, 414 * is allocated) 415 * @return the size of the output 416 */ 417 size_t 418 GNUNET_STRINGS_base64_encode (const void *in, 419 size_t len, 420 char **output); 421 422 423 /** 424 * url/percent encode (RFC3986). 425 * 426 * FIXME: awkward API, @a len is not actually used 427 * @a out is 0-terminated, should probably be changed 428 * to only input @a data and directly return @out or NULL. 429 * 430 * @param data the data to decode 431 * @param len the length of the input 432 * @param out where to write the output (*out should be NULL, 433 * is allocated) 434 * @return the size of the output 435 */ 436 size_t 437 GNUNET_STRINGS_urlencode (size_t len, 438 const char data[static len], 439 char **out); 440 441 442 /** 443 * Encode into Base64url. RFC7515 444 * 445 * @param in the data to encode 446 * @param len the length of the input 447 * @param output where to write the output (*output should be NULL, 448 * is allocated) 449 * @return the size of the output 450 */ 451 size_t 452 GNUNET_STRINGS_base64url_encode (const void *in, 453 size_t len, 454 char **output); 455 456 457 /** 458 * Decode from Base64. 459 * 460 * @param data the data to encode 461 * @param len the length of the input 462 * @param[out] output where to write the output (*output should be NULL, 463 * is allocated) 464 * @return the size of the output 465 */ 466 size_t 467 GNUNET_STRINGS_base64_decode (const char *data, 468 size_t len, 469 void **output); 470 471 472 /** 473 * Decode from Base64url. RFC7515 474 * 475 * @param data the data to decode 476 * @param len the length of the input 477 * @param out where to write the output (*out should be NULL, 478 * is allocated) 479 * @return the size of the output 480 */ 481 size_t 482 GNUNET_STRINGS_base64url_decode (const char *data, 483 size_t len, 484 void **out); 485 486 /** 487 * url/percent encode (RFC3986). 488 * 489 * @param data the data to encode 490 * @param len the length of the input 491 * @param[out] out where to write the output (*output should be NULL, 492 * is allocated) 493 * @return the size of the output 494 */ 495 size_t 496 GNUNET_STRINGS_urldecode (const char *data, 497 size_t len, 498 char **out); 499 500 501 /** 502 * Parse a path that might be an URI. 503 * 504 * @param path path to parse. Must be NULL-terminated. 505 * @param[out] scheme_part pointer to a string that 506 * represents the URI scheme will be stored. Can be NULL. The string is 507 * allocated by the function, and should be freed by GNUNET_free() when 508 * it is no longer needed. 509 * @param path_part a pointer to 'const char *' where a pointer to the path 510 * part of the URI will be stored. Can be NULL. Points to the same block 511 * of memory as @a path, and thus must not be freed. Might point to '\0', 512 * if path part is zero-length. 513 * @return #GNUNET_YES if it's an URI, #GNUNET_NO otherwise. If 'path' is not 514 * an URI, '* scheme_part' and '*path_part' will remain unchanged 515 * (if they weren't NULL). 516 */ 517 enum GNUNET_GenericReturnValue 518 GNUNET_STRINGS_parse_uri (const char *path, 519 char **scheme_part, 520 const char **path_part); 521 522 523 /** 524 * Check whether filename is absolute or not, and if it's an URI 525 * 526 * @param filename filename to check 527 * @param can_be_uri #GNUNET_YES to check for being URI, #GNUNET_NO - to 528 * assume it's not URI 529 * @param r_is_uri a pointer to an int that is set to #GNUNET_YES if 'filename' 530 * is URI and to GNUNET_NO otherwise. Can be NULL. If 'can_be_uri' is 531 * not #GNUNET_YES, *r_is_uri is set to #GNUNET_NO. 532 * @param r_uri_scheme a pointer to a char * that is set to a pointer to URI scheme. 533 * The string is allocated by the function, and should be freed with 534 * GNUNET_free (). Can be NULL. 535 * @return #GNUNET_YES if 'filename' is absolute, #GNUNET_NO otherwise. 536 */ 537 enum GNUNET_GenericReturnValue 538 GNUNET_STRINGS_path_is_absolute (const char *filename, 539 int can_be_uri, 540 int *r_is_uri, 541 char **r_uri_scheme); 542 543 544 /** 545 * Flags for what we should check a file for. 546 */ 547 enum GNUNET_STRINGS_FilenameCheck 548 { 549 /** 550 * Check that it exists. 551 */ 552 GNUNET_STRINGS_CHECK_EXISTS = 0x00000001, 553 554 /** 555 * Check that it is a directory. 556 */ 557 GNUNET_STRINGS_CHECK_IS_DIRECTORY = 0x00000002, 558 559 /** 560 * Check that it is a link. 561 */ 562 GNUNET_STRINGS_CHECK_IS_LINK = 0x00000004, 563 564 /** 565 * Check that the path is an absolute path. 566 */ 567 GNUNET_STRINGS_CHECK_IS_ABSOLUTE = 0x00000008 568 }; 569 570 571 /** 572 * Perform checks on @a filename. FIXME: some duplication with 573 * "GNUNET_DISK_"-APIs. We should unify those. 574 * 575 * @param filename file to check 576 * @param checks checks to perform 577 * @return #GNUNET_YES if all checks pass, #GNUNET_NO if at least one of them 578 * fails, #GNUNET_SYSERR when a check can't be performed 579 */ 580 enum GNUNET_GenericReturnValue 581 GNUNET_STRINGS_check_filename (const char *filename, 582 enum GNUNET_STRINGS_FilenameCheck checks); 583 584 585 /** 586 * Tries to convert @a zt_addr string to an IPv6 address. 587 * The string is expected to have the format "[ABCD::01]:80". 588 * 589 * @param zt_addr 0-terminated string. May be mangled by the function. 590 * @param addrlen length of zt_addr (not counting 0-terminator). 591 * @param r_buf a buffer to fill. Initially gets filled with zeroes, 592 * then its sin6_port, sin6_family and sin6_addr are set appropriately. 593 * @return #GNUNET_OK if conversion succeeded. #GNUNET_SYSERR otherwise, in which 594 * case the contents of r_buf are undefined. 595 */ 596 enum GNUNET_GenericReturnValue 597 GNUNET_STRINGS_to_address_ipv6 (const char *zt_addr, 598 size_t addrlen, 599 struct sockaddr_in6 *r_buf); 600 601 602 /** 603 * Tries to convert @a zt_addr string to an IPv4 address. 604 * The string is expected to have the format "1.2.3.4:80". 605 * 606 * @param zt_addr 0-terminated string. May be mangled by the function. 607 * @param addrlen length of zt_addr (not counting 0-terminator). 608 * @param r_buf a buffer to fill. 609 * @return #GNUNET_OK if conversion succeeded. #GNUNET_SYSERR otherwise, in which case 610 * the contents of r_buf are undefined. 611 */ 612 enum GNUNET_GenericReturnValue 613 GNUNET_STRINGS_to_address_ipv4 (const char *zt_addr, 614 size_t addrlen, 615 struct sockaddr_in *r_buf); 616 617 618 /** 619 * Parse an address given as a string into a 620 * `struct sockaddr`. 621 * 622 * @param addr the address 623 * @param[out] af set to the parsed address family (e.g. AF_INET) 624 * @param[out] sa set to the parsed address 625 * @return 0 on error, otherwise number of bytes in @a sa 626 */ 627 size_t 628 GNUNET_STRINGS_parse_socket_addr (const char *addr, 629 uint8_t *af, 630 struct sockaddr **sa); 631 632 633 /** 634 * Tries to convert @a addr string to an IP (v4 or v6) address. 635 * Will automatically decide whether to treat 'addr' as v4 or v6 address. 636 * 637 * @param addr a string, may not be 0-terminated. 638 * @param addrlen number of bytes in @a addr (if addr is 0-terminated, 639 * 0-terminator should not be counted towards addrlen). 640 * @param r_buf a buffer to fill. 641 * @return #GNUNET_OK if conversion succeeded. #GNUNET_SYSERR otherwise, in which 642 * case the contents of r_buf are undefined. 643 */ 644 enum GNUNET_GenericReturnValue 645 GNUNET_STRINGS_to_address_ip (const char *addr, 646 uint16_t addrlen, 647 struct sockaddr_storage *r_buf); 648 649 650 /** 651 * Like strlcpy but portable. The given string @a src is copied in full length 652 * (until its null byte). The destination buffer is guaranteed to be 653 * null-terminated. 654 * 655 * to a destination buffer 656 * and ensures that the destination string is null-terminated. 657 * 658 * @param dst destination of the copy 659 * @param src source of the copy, must be null-terminated 660 * @param n the length of the string to copy, including its terminating null 661 * byte 662 * @return the length of the string that was copied, excluding the terminating 663 * null byte 664 */ 665 size_t 666 GNUNET_strlcpy (char *dst, 667 const char *src, 668 size_t n); 669 670 671 /** 672 * Sometimes we use the binary name to determine which specific 673 * test to run. In those cases, the string after the last "_" 674 * in 'argv[0]' specifies a string that determines the configuration 675 * file or plugin to use. 676 * 677 * This function returns the respective substring, taking care 678 * of issues such as binaries ending in '.exe' on W32. 679 * 680 * @param argv0 the name of the binary 681 * @return string between the last '_' and the '.exe' (or the end of the string), 682 * NULL if argv0 has no '_' 683 */ 684 char * 685 GNUNET_STRINGS_get_suffix_from_binary_name (const char *argv0); 686 687 688 /* ***************** IPv4/IPv6 parsing ****************** */ 689 690 struct GNUNET_STRINGS_PortPolicy 691 { 692 /** 693 * Starting port range (0 if none given). 694 */ 695 uint16_t start_port; 696 697 /** 698 * End of port range (0 if none given). 699 */ 700 uint16_t end_port; 701 702 /** 703 * #GNUNET_YES if the port range should be negated 704 * ("!" in policy). 705 */ 706 int negate_portrange; 707 }; 708 709 710 /** 711 * @brief IPV4 network in CIDR notation. 712 */ 713 struct GNUNET_STRINGS_IPv4NetworkPolicy 714 { 715 /** 716 * IPv4 address. 717 */ 718 struct in_addr network; 719 720 /** 721 * IPv4 netmask. 722 */ 723 struct in_addr netmask; 724 725 /** 726 * Policy for port access. 727 */ 728 struct GNUNET_STRINGS_PortPolicy pp; 729 }; 730 731 732 /** 733 * @brief network in CIDR notation for IPV6. 734 */ 735 struct GNUNET_STRINGS_IPv6NetworkPolicy 736 { 737 /** 738 * IPv6 address. 739 */ 740 struct in6_addr network; 741 742 /** 743 * IPv6 netmask. 744 */ 745 struct in6_addr netmask; 746 747 /** 748 * Policy for port access. 749 */ 750 struct GNUNET_STRINGS_PortPolicy pp; 751 }; 752 753 754 /** 755 * Parse an IPv4 network policy. The argument specifies a list of 756 * subnets. The format is <tt>(network[/netmask][:[!]SPORT-DPORT];)*</tt> 757 * (no whitespace, must be terminated with a semicolon). The network 758 * must be given in dotted-decimal notation. The netmask can be given 759 * in CIDR notation (/16) or in dotted-decimal (/255.255.0.0). 760 * 761 * @param routeListX a string specifying the IPv4 subnets 762 * @return the converted list, terminated with all zeros; 763 * NULL if the syntax is flawed 764 */ 765 struct GNUNET_STRINGS_IPv4NetworkPolicy * 766 GNUNET_STRINGS_parse_ipv4_policy (const char *routeListX); 767 768 769 /** 770 * Parse an IPv6 network policy. The argument specifies a list of 771 * subnets. The format is <tt>(network[/netmask[:[!]SPORT[-DPORT]]];)*</tt> 772 * (no whitespace, must be terminated with a semicolon). The network 773 * must be given in colon-hex notation. The netmask must be given in 774 * CIDR notation (/16) or can be omitted to specify a single host. 775 * Note that the netmask is mandatory if ports are specified. 776 * 777 * @param routeListX a string specifying the policy 778 * @return the converted list, 0-terminated, NULL if the syntax is flawed 779 */ 780 struct GNUNET_STRINGS_IPv6NetworkPolicy * 781 GNUNET_STRINGS_parse_ipv6_policy (const char *routeListX); 782 783 784 #if 0 /* keep Emacsens' auto-indent happy */ 785 { 786 #endif 787 #ifdef __cplusplus 788 } 789 #endif 790 791 /* ifndef GNUNET_UTIL_STRING_H */ 792 #endif 793 794 /** @} */ /* end of group */ 795 796 /** @} */ /* end of group addition */ 797 798 /* end of gnunet_util_string.h */