gnunet_strings_lib.h (24426B)
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 /** 297 * @ingroup time 298 * Like `asctime`, except for GNUnet time. Converts a GNUnet internal 299 * absolute time (which is in UTC) to a string in local time. 300 * Note that the returned value will be overwritten if this function 301 * is called again. 302 * 303 * @param t the absolute time to convert 304 * @return timestamp in human-readable form in local time 305 */ 306 const char * 307 GNUNET_STRINGS_absolute_time_to_string (struct GNUNET_TIME_Absolute t); 308 309 310 /** 311 * @ingroup time 312 * Give relative time in human-readable fancy format. 313 * This is one of the very few calls in the entire API that is 314 * NOT reentrant! 315 * 316 * @param delta time in milli seconds 317 * @param do_round are we allowed to round a bit? 318 * @return string in human-readable form 319 */ 320 const char * 321 GNUNET_STRINGS_relative_time_to_string (struct GNUNET_TIME_Relative delta, 322 int do_round); 323 324 325 /** 326 * "man basename" 327 * Returns a pointer to a part of filename (allocates nothing)! 328 * 329 * @param filename filename to extract basename from 330 * @return short (base) name of the file (that is, everything following the 331 * last directory separator in filename. If filename ends with a 332 * directory separator, the result will be a zero-length string. 333 * If filename has no directory separators, the result is filename 334 * itself. 335 */ 336 const char * 337 GNUNET_STRINGS_get_short_name (const char *filename); 338 339 340 /** 341 * Convert binary data to ASCII encoding using CrockfordBase32. 342 * Does not append 0-terminator, but returns a pointer to the place where 343 * it should be placed, if needed. 344 * 345 * @param data data to encode 346 * @param size size of data (in bytes) 347 * @param out buffer to fill 348 * @param out_size size of the buffer. Must be large enough to hold 349 * ((size*8) + (((size*8) % 5) > 0 ? 5 - ((size*8) % 5) : 0)) / 5 350 * @return pointer to the next byte in 'out' or NULL on error. 351 */ 352 char * 353 GNUNET_STRINGS_data_to_string (const void *data, 354 size_t size, 355 char *out, 356 size_t out_size); 357 358 359 /** 360 * Return the base32crockford encoding of the given buffer. 361 * 362 * The returned string will be freshly allocated, and must be free'd 363 * with #GNUNET_free(). 364 * 365 * @param buf buffer with data 366 * @param size size of the buffer @a buf 367 * @return freshly allocated, null-terminated string 368 */ 369 char * 370 GNUNET_STRINGS_data_to_string_alloc (const void *buf, 371 size_t size); 372 373 374 /** 375 * Convert CrockfordBase32 encoding back to data. 376 * @a out_size must match exactly the size of the data before it was encoded. 377 * 378 * @param enc the encoding 379 * @param enclen number of characters in @a enc (without 0-terminator, which can be missing) 380 * @param out location where to store the decoded data 381 * @param out_size size of the output buffer @a out 382 * @return #GNUNET_OK on success, #GNUNET_SYSERR if result has the wrong encoding 383 */ 384 enum GNUNET_GenericReturnValue 385 GNUNET_STRINGS_string_to_data (const char *enc, 386 size_t enclen, 387 void *out, 388 size_t out_size); 389 390 391 /** 392 * Convert CrockfordBase32 encoding back to data. 393 * @a out_size will be determined from @a enc and 394 * @a out will be allocated to be large enough. 395 * 396 * @param enc the encoding 397 * @param enclen number of characters in @a enc (without 0-terminator, which can be missing) 398 * @param[out] out location where to allocate and store the decoded data 399 * @param[out] out_size set to the size of the output buffer @a out 400 * @return #GNUNET_OK on success, #GNUNET_SYSERR if result has the wrong encoding 401 */ 402 enum GNUNET_GenericReturnValue 403 GNUNET_STRINGS_string_to_data_alloc (const char *enc, 404 size_t enclen, 405 void **out, 406 size_t *out_size); 407 408 409 /** 410 * Encode into Base64. 411 * 412 * @param data the data to encode 413 * @param len the length of the input 414 * @param output where to write the output (*output should be NULL, 415 * is allocated) 416 * @return the size of the output 417 */ 418 size_t 419 GNUNET_STRINGS_base64_encode (const void *in, 420 size_t len, 421 char **output); 422 423 424 /** 425 * url/percent encode (RFC3986). 426 * 427 * FIXME: awkward API, @a len is not actually used 428 * @a out is 0-terminated, should probably be changed 429 * to only input @a data and directly return @out or NULL. 430 * 431 * @param data the data to decode 432 * @param len the length of the input 433 * @param out where to write the output (*out should be NULL, 434 * is allocated) 435 * @return the size of the output 436 */ 437 size_t 438 GNUNET_STRINGS_urlencode (size_t len, 439 const char data[static len], 440 char **out); 441 442 443 /** 444 * Encode into Base64url. RFC7515 445 * 446 * @param in the data to encode 447 * @param len the length of the input 448 * @param output where to write the output (*output should be NULL, 449 * is allocated) 450 * @return the size of the output 451 */ 452 size_t 453 GNUNET_STRINGS_base64url_encode (const void *in, 454 size_t len, 455 char **output); 456 457 458 /** 459 * Decode from Base64. 460 * 461 * @param data the data to encode 462 * @param len the length of the input 463 * @param[out] output where to write the output (*output should be NULL, 464 * is allocated) 465 * @return the size of the output 466 */ 467 size_t 468 GNUNET_STRINGS_base64_decode (const char *data, 469 size_t len, 470 void **output); 471 472 473 /** 474 * Decode from Base64url. RFC7515 475 * 476 * @param data the data to decode 477 * @param len the length of the input 478 * @param out where to write the output (*out should be NULL, 479 * is allocated) 480 * @return the size of the output 481 */ 482 size_t 483 GNUNET_STRINGS_base64url_decode (const char *data, 484 size_t len, 485 void **out); 486 487 /** 488 * url/percent encode (RFC3986). 489 * 490 * @param data the data to encode 491 * @param len the length of the input 492 * @param[out] out where to write the output (*output should be NULL, 493 * is allocated) 494 * @return the size of the output 495 */ 496 size_t 497 GNUNET_STRINGS_urldecode (const char *data, 498 size_t len, 499 char **out); 500 501 502 /** 503 * Parse a path that might be an URI. 504 * 505 * @param path path to parse. Must be NULL-terminated. 506 * @param[out] scheme_part pointer to a string that 507 * represents the URI scheme will be stored. Can be NULL. The string is 508 * allocated by the function, and should be freed by GNUNET_free() when 509 * it is no longer needed. 510 * @param path_part a pointer to 'const char *' where a pointer to the path 511 * part of the URI will be stored. Can be NULL. Points to the same block 512 * of memory as @a path, and thus must not be freed. Might point to '\0', 513 * if path part is zero-length. 514 * @return #GNUNET_YES if it's an URI, #GNUNET_NO otherwise. If 'path' is not 515 * an URI, '* scheme_part' and '*path_part' will remain unchanged 516 * (if they weren't NULL). 517 */ 518 enum GNUNET_GenericReturnValue 519 GNUNET_STRINGS_parse_uri (const char *path, 520 char **scheme_part, 521 const char **path_part); 522 523 524 /** 525 * Check whether filename is absolute or not, and if it's an URI 526 * 527 * @param filename filename to check 528 * @param can_be_uri #GNUNET_YES to check for being URI, #GNUNET_NO - to 529 * assume it's not URI 530 * @param r_is_uri a pointer to an int that is set to #GNUNET_YES if 'filename' 531 * is URI and to GNUNET_NO otherwise. Can be NULL. If 'can_be_uri' is 532 * not #GNUNET_YES, *r_is_uri is set to #GNUNET_NO. 533 * @param r_uri_scheme a pointer to a char * that is set to a pointer to URI scheme. 534 * The string is allocated by the function, and should be freed with 535 * GNUNET_free (). Can be NULL. 536 * @return #GNUNET_YES if 'filename' is absolute, #GNUNET_NO otherwise. 537 */ 538 enum GNUNET_GenericReturnValue 539 GNUNET_STRINGS_path_is_absolute (const char *filename, 540 int can_be_uri, 541 int *r_is_uri, 542 char **r_uri_scheme); 543 544 545 /** 546 * Flags for what we should check a file for. 547 */ 548 enum GNUNET_STRINGS_FilenameCheck 549 { 550 /** 551 * Check that it exists. 552 */ 553 GNUNET_STRINGS_CHECK_EXISTS = 0x00000001, 554 555 /** 556 * Check that it is a directory. 557 */ 558 GNUNET_STRINGS_CHECK_IS_DIRECTORY = 0x00000002, 559 560 /** 561 * Check that it is a link. 562 */ 563 GNUNET_STRINGS_CHECK_IS_LINK = 0x00000004, 564 565 /** 566 * Check that the path is an absolute path. 567 */ 568 GNUNET_STRINGS_CHECK_IS_ABSOLUTE = 0x00000008 569 }; 570 571 572 /** 573 * Perform checks on @a filename. FIXME: some duplication with 574 * "GNUNET_DISK_"-APIs. We should unify those. 575 * 576 * @param filename file to check 577 * @param checks checks to perform 578 * @return #GNUNET_YES if all checks pass, #GNUNET_NO if at least one of them 579 * fails, #GNUNET_SYSERR when a check can't be performed 580 */ 581 enum GNUNET_GenericReturnValue 582 GNUNET_STRINGS_check_filename (const char *filename, 583 enum GNUNET_STRINGS_FilenameCheck checks); 584 585 586 /** 587 * Tries to convert @a zt_addr string to an IPv6 address. 588 * The string is expected to have the format "[ABCD::01]:80". 589 * 590 * @param zt_addr 0-terminated string. May be mangled by the function. 591 * @param addrlen length of zt_addr (not counting 0-terminator). 592 * @param r_buf a buffer to fill. Initially gets filled with zeroes, 593 * then its sin6_port, sin6_family and sin6_addr are set appropriately. 594 * @return #GNUNET_OK if conversion succeeded. #GNUNET_SYSERR otherwise, in which 595 * case the contents of r_buf are undefined. 596 */ 597 enum GNUNET_GenericReturnValue 598 GNUNET_STRINGS_to_address_ipv6 (const char *zt_addr, 599 size_t addrlen, 600 struct sockaddr_in6 *r_buf); 601 602 603 /** 604 * Tries to convert @a zt_addr string to an IPv4 address. 605 * The string is expected to have the format "1.2.3.4:80". 606 * 607 * @param zt_addr 0-terminated string. May be mangled by the function. 608 * @param addrlen length of zt_addr (not counting 0-terminator). 609 * @param r_buf a buffer to fill. 610 * @return #GNUNET_OK if conversion succeeded. #GNUNET_SYSERR otherwise, in which case 611 * the contents of r_buf are undefined. 612 */ 613 enum GNUNET_GenericReturnValue 614 GNUNET_STRINGS_to_address_ipv4 (const char *zt_addr, 615 size_t addrlen, 616 struct sockaddr_in *r_buf); 617 618 619 /** 620 * Parse an address given as a string into a 621 * `struct sockaddr`. 622 * 623 * @param addr the address 624 * @param[out] af set to the parsed address family (e.g. AF_INET) 625 * @param[out] sa set to the parsed address 626 * @return 0 on error, otherwise number of bytes in @a sa 627 */ 628 size_t 629 GNUNET_STRINGS_parse_socket_addr (const char *addr, 630 uint8_t *af, 631 struct sockaddr **sa); 632 633 634 /** 635 * Tries to convert @a addr string to an IP (v4 or v6) address. 636 * Will automatically decide whether to treat 'addr' as v4 or v6 address. 637 * 638 * @param addr a string, may not be 0-terminated. 639 * @param addrlen number of bytes in @a addr (if addr is 0-terminated, 640 * 0-terminator should not be counted towards addrlen). 641 * @param r_buf a buffer to fill. 642 * @return #GNUNET_OK if conversion succeeded. #GNUNET_SYSERR otherwise, in which 643 * case the contents of r_buf are undefined. 644 */ 645 enum GNUNET_GenericReturnValue 646 GNUNET_STRINGS_to_address_ip (const char *addr, 647 uint16_t addrlen, 648 struct sockaddr_storage *r_buf); 649 650 651 /** 652 * Like strlcpy but portable. The given string @a src is copied in full length 653 * (until its null byte). The destination buffer is guaranteed to be 654 * null-terminated. 655 * 656 * to a destination buffer 657 * and ensures that the destination string is null-terminated. 658 * 659 * @param dst destination of the copy 660 * @param src source of the copy, must be null-terminated 661 * @param n the length of the string to copy, including its terminating null 662 * byte 663 * @return the length of the string that was copied, excluding the terminating 664 * null byte 665 */ 666 size_t 667 GNUNET_strlcpy (char *dst, 668 const char *src, 669 size_t n); 670 671 672 /** 673 * Sometimes we use the binary name to determine which specific 674 * test to run. In those cases, the string after the last "_" 675 * in 'argv[0]' specifies a string that determines the configuration 676 * file or plugin to use. 677 * 678 * This function returns the respective substring, taking care 679 * of issues such as binaries ending in '.exe' on W32. 680 * 681 * @param argv0 the name of the binary 682 * @return string between the last '_' and the '.exe' (or the end of the string), 683 * NULL if argv0 has no '_' 684 */ 685 char * 686 GNUNET_STRINGS_get_suffix_from_binary_name (const char *argv0); 687 688 689 /* ***************** IPv4/IPv6 parsing ****************** */ 690 691 struct GNUNET_STRINGS_PortPolicy 692 { 693 /** 694 * Starting port range (0 if none given). 695 */ 696 uint16_t start_port; 697 698 /** 699 * End of port range (0 if none given). 700 */ 701 uint16_t end_port; 702 703 /** 704 * #GNUNET_YES if the port range should be negated 705 * ("!" in policy). 706 */ 707 int negate_portrange; 708 }; 709 710 711 /** 712 * @brief IPV4 network in CIDR notation. 713 */ 714 struct GNUNET_STRINGS_IPv4NetworkPolicy 715 { 716 /** 717 * IPv4 address. 718 */ 719 struct in_addr network; 720 721 /** 722 * IPv4 netmask. 723 */ 724 struct in_addr netmask; 725 726 /** 727 * Policy for port access. 728 */ 729 struct GNUNET_STRINGS_PortPolicy pp; 730 }; 731 732 733 /** 734 * @brief network in CIDR notation for IPV6. 735 */ 736 struct GNUNET_STRINGS_IPv6NetworkPolicy 737 { 738 /** 739 * IPv6 address. 740 */ 741 struct in6_addr network; 742 743 /** 744 * IPv6 netmask. 745 */ 746 struct in6_addr netmask; 747 748 /** 749 * Policy for port access. 750 */ 751 struct GNUNET_STRINGS_PortPolicy pp; 752 }; 753 754 755 /** 756 * Parse an IPv4 network policy. The argument specifies a list of 757 * subnets. The format is <tt>(network[/netmask][:[!]SPORT-DPORT];)*</tt> 758 * (no whitespace, must be terminated with a semicolon). The network 759 * must be given in dotted-decimal notation. The netmask can be given 760 * in CIDR notation (/16) or in dotted-decimal (/255.255.0.0). 761 * 762 * @param routeListX a string specifying the IPv4 subnets 763 * @return the converted list, terminated with all zeros; 764 * NULL if the syntax is flawed 765 */ 766 struct GNUNET_STRINGS_IPv4NetworkPolicy * 767 GNUNET_STRINGS_parse_ipv4_policy (const char *routeListX); 768 769 770 /** 771 * Parse an IPv6 network policy. The argument specifies a list of 772 * subnets. The format is <tt>(network[/netmask[:[!]SPORT[-DPORT]]];)*</tt> 773 * (no whitespace, must be terminated with a semicolon). The network 774 * must be given in colon-hex notation. The netmask must be given in 775 * CIDR notation (/16) or can be omitted to specify a single host. 776 * Note that the netmask is mandatory if ports are specified. 777 * 778 * @param routeListX a string specifying the policy 779 * @return the converted list, 0-terminated, NULL if the syntax is flawed 780 */ 781 struct GNUNET_STRINGS_IPv6NetworkPolicy * 782 GNUNET_STRINGS_parse_ipv6_policy (const char *routeListX); 783 784 785 #if 0 /* keep Emacsens' auto-indent happy */ 786 { 787 #endif 788 #ifdef __cplusplus 789 } 790 #endif 791 792 /* ifndef GNUNET_UTIL_STRING_H */ 793 #endif 794 795 /** @} */ /* end of group */ 796 797 /** @} */ /* end of group addition */ 798 799 /* end of gnunet_util_string.h */