aboutsummaryrefslogtreecommitdiff
path: root/src/util/strings.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/strings.c')
-rw-r--r--src/util/strings.c467
1 files changed, 76 insertions, 391 deletions
diff --git a/src/util/strings.c b/src/util/strings.c
index b62d5f547..24335e444 100644
--- a/src/util/strings.c
+++ b/src/util/strings.c
@@ -41,27 +41,6 @@
41 GNUNET_log_from_strerror (kind, "util-strings", syscall) 41 GNUNET_log_from_strerror (kind, "util-strings", syscall)
42 42
43 43
44/**
45 * Fill a buffer of the given size with
46 * count 0-terminated strings (given as varargs).
47 * If "buffer" is NULL, only compute the amount of
48 * space required (sum of "strlen(arg)+1").
49 *
50 * Unlike using "snprintf" with "%s", this function
51 * will add 0-terminators after each string. The
52 * #GNUNET_string_buffer_tokenize() function can be
53 * used to parse the buffer back into individual
54 * strings.
55 *
56 * @param buffer the buffer to fill with strings, can
57 * be NULL in which case only the necessary
58 * amount of space will be calculated
59 * @param size number of bytes available in buffer
60 * @param count number of strings that follow
61 * @param ... count 0-terminated strings to copy to buffer
62 * @return number of bytes written to the buffer
63 * (or number of bytes that would have been written)
64 */
65size_t 44size_t
66GNUNET_STRINGS_buffer_fill (char *buffer, 45GNUNET_STRINGS_buffer_fill (char *buffer,
67 size_t size, 46 size_t size,
@@ -90,13 +69,6 @@ GNUNET_STRINGS_buffer_fill (char *buffer,
90} 69}
91 70
92 71
93/**
94 * Convert a peer path to a human-readable string.
95 *
96 * @param pids array of PIDs to convert to a string
97 * @param num_pids length of the @a pids array
98 * @return string representing the array of @a pids
99 */
100char * 72char *
101GNUNET_STRINGS_pp2s (const struct GNUNET_PeerIdentity *pids, 73GNUNET_STRINGS_pp2s (const struct GNUNET_PeerIdentity *pids,
102 unsigned int num_pids) 74 unsigned int num_pids)
@@ -120,19 +92,6 @@ GNUNET_STRINGS_pp2s (const struct GNUNET_PeerIdentity *pids,
120} 92}
121 93
122 94
123/**
124 * Given a buffer of a given size, find "count"
125 * 0-terminated strings in the buffer and assign
126 * the count (varargs) of type "const char**" to the
127 * locations of the respective strings in the
128 * buffer.
129 *
130 * @param buffer the buffer to parse
131 * @param size size of the buffer
132 * @param count number of strings to locate
133 * @return offset of the character after the last 0-termination
134 * in the buffer, or 0 on error.
135 */
136unsigned int 95unsigned int
137GNUNET_STRINGS_buffer_tokenize (const char *buffer, 96GNUNET_STRINGS_buffer_tokenize (const char *buffer,
138 size_t size, 97 size_t size,
@@ -167,12 +126,6 @@ GNUNET_STRINGS_buffer_tokenize (const char *buffer,
167} 126}
168 127
169 128
170/**
171 * Convert a given filesize into a fancy human-readable format.
172 *
173 * @param size number of bytes
174 * @return fancy representation of the size (possibly rounded) for humans
175 */
176char * 129char *
177GNUNET_STRINGS_byte_size_fancy (unsigned long long size) 130GNUNET_STRINGS_byte_size_fancy (unsigned long long size)
178{ 131{
@@ -205,20 +158,10 @@ GNUNET_STRINGS_byte_size_fancy (unsigned long long size)
205} 158}
206 159
207 160
208/**
209 * Like strlcpy but portable. The given string @a src is copied until its null
210 * byte or until @a n - 1 bytes have been read. The destination buffer is
211 * guaranteed to be null-terminated.
212 *
213 * @param dst destination of the copy (must be @a n bytes long)
214 * @param src source of the copy (at most @a n - 1 bytes will be read)
215 * @param n the length of the string to copy, including its terminating null
216 * byte
217 * @return the length of the string that was copied, excluding the terminating
218 * null byte
219 */
220size_t 161size_t
221GNUNET_strlcpy (char *dst, const char *src, size_t n) 162GNUNET_strlcpy (char *dst,
163 const char *src,
164 size_t n)
222{ 165{
223 size_t slen; 166 size_t slen;
224 167
@@ -313,13 +256,6 @@ convert_with_table (const char *input,
313} 256}
314 257
315 258
316/**
317 * Convert a given fancy human-readable size to bytes.
318 *
319 * @param fancy_size human readable string (e.g. 1 MB)
320 * @param size set to the size in bytes
321 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
322 */
323int 259int
324GNUNET_STRINGS_fancy_size_to_bytes (const char *fancy_size, 260GNUNET_STRINGS_fancy_size_to_bytes (const char *fancy_size,
325 unsigned long long *size) 261 unsigned long long *size)
@@ -344,14 +280,6 @@ GNUNET_STRINGS_fancy_size_to_bytes (const char *fancy_size,
344} 280}
345 281
346 282
347/**
348 * Convert a given fancy human-readable time to our internal
349 * representation.
350 *
351 * @param fancy_time human readable string (e.g. 1 minute)
352 * @param rtime set to the relative time
353 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
354 */
355int 283int
356GNUNET_STRINGS_fancy_time_to_relative (const char *fancy_time, 284GNUNET_STRINGS_fancy_time_to_relative (const char *fancy_time,
357 struct GNUNET_TIME_Relative *rtime) 285 struct GNUNET_TIME_Relative *rtime)
@@ -394,15 +322,6 @@ GNUNET_STRINGS_fancy_time_to_relative (const char *fancy_time,
394} 322}
395 323
396 324
397/**
398 * Convert a given fancy human-readable time to our internal
399 * representation. The human-readable time is expected to be
400 * in local time, whereas the returned value will be in UTC.
401 *
402 * @param fancy_time human readable string (e.g. %Y-%m-%d %H:%M:%S)
403 * @param atime set to the absolute time
404 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
405 */
406int 325int
407GNUNET_STRINGS_fancy_time_to_absolute (const char *fancy_time, 326GNUNET_STRINGS_fancy_time_to_absolute (const char *fancy_time,
408 struct GNUNET_TIME_Absolute *atime) 327 struct GNUNET_TIME_Absolute *atime)
@@ -435,19 +354,6 @@ GNUNET_STRINGS_fancy_time_to_absolute (const char *fancy_time,
435} 354}
436 355
437 356
438/**
439 * Convert the len characters long character sequence
440 * given in input that is in the given input charset
441 * to a string in given output charset.
442 *
443 * @param input input string
444 * @param len number of bytes in @a input
445 * @param input_charset character set used for @a input
446 * @param output_charset desired character set for the return value
447 * @return the converted string (0-terminated),
448 * if conversion fails, a copy of the original
449 * string is returned.
450 */
451char * 357char *
452GNUNET_STRINGS_conv (const char *input, 358GNUNET_STRINGS_conv (const char *input,
453 size_t len, 359 size_t len,
@@ -510,18 +416,6 @@ fail:
510} 416}
511 417
512 418
513/**
514 * Convert the len characters long character sequence
515 * given in input that is in the given charset
516 * to UTF-8.
517 *
518 * @param input the input string (not necessarily 0-terminated)
519 * @param len the number of bytes in the @a input
520 * @param charset character set to convert from
521 * @return the converted string (0-terminated),
522 * if conversion fails, a copy of the original
523 * string is returned.
524 */
525char * 419char *
526GNUNET_STRINGS_to_utf8 (const char *input, 420GNUNET_STRINGS_to_utf8 (const char *input,
527 size_t len, 421 size_t len,
@@ -534,17 +428,6 @@ GNUNET_STRINGS_to_utf8 (const char *input,
534} 428}
535 429
536 430
537/**
538 * Convert the len bytes-long UTF-8 string
539 * given in input to the given charset.
540 *
541 * @param input the input string (not necessarily 0-terminated)
542 * @param len the number of bytes in the @a input
543 * @param charset character set to convert to
544 * @return the converted string (0-terminated),
545 * if conversion fails, a copy of the original
546 * string is returned.
547 */
548char * 431char *
549GNUNET_STRINGS_from_utf8 (const char *input, 432GNUNET_STRINGS_from_utf8 (const char *input,
550 size_t len, 433 size_t len,
@@ -557,15 +440,9 @@ GNUNET_STRINGS_from_utf8 (const char *input,
557} 440}
558 441
559 442
560/**
561 * Convert the utf-8 input string to lowercase.
562 * Output needs to be allocated appropriately.
563 *
564 * @param input input string
565 * @param output output buffer
566 */
567void 443void
568GNUNET_STRINGS_utf8_tolower (const char *input, char *output) 444GNUNET_STRINGS_utf8_tolower (const char *input,
445 char *output)
569{ 446{
570 uint8_t *tmp_in; 447 uint8_t *tmp_in;
571 size_t len; 448 size_t len;
@@ -582,15 +459,9 @@ GNUNET_STRINGS_utf8_tolower (const char *input, char *output)
582} 459}
583 460
584 461
585/**
586 * Convert the utf-8 input string to uppercase.
587 * Output needs to be allocated appropriately.
588 *
589 * @param input input string
590 * @param output output buffer
591 */
592void 462void
593GNUNET_STRINGS_utf8_toupper (const char *input, char *output) 463GNUNET_STRINGS_utf8_toupper (const char *input,
464 char *output)
594{ 465{
595 uint8_t *tmp_in; 466 uint8_t *tmp_in;
596 size_t len; 467 size_t len;
@@ -607,13 +478,6 @@ GNUNET_STRINGS_utf8_toupper (const char *input, char *output)
607} 478}
608 479
609 480
610/**
611 * Complete filename (a la shell) from abbrevition.
612 * @param fil the name of the file, may contain ~/ or
613 * be relative to the current directory
614 * @returns the full file name,
615 * NULL is returned on error
616 */
617char * 481char *
618GNUNET_STRINGS_filename_expand (const char *fil) 482GNUNET_STRINGS_filename_expand (const char *fil)
619{ 483{
@@ -689,15 +553,6 @@ GNUNET_STRINGS_filename_expand (const char *fil)
689} 553}
690 554
691 555
692/**
693 * Give relative time in human-readable fancy format.
694 * This is one of the very few calls in the entire API that is
695 * NOT reentrant!
696 *
697 * @param delta time in milli seconds
698 * @param do_round are we allowed to round a bit?
699 * @return time as human-readable string
700 */
701const char * 556const char *
702GNUNET_STRINGS_relative_time_to_string (struct GNUNET_TIME_Relative delta, 557GNUNET_STRINGS_relative_time_to_string (struct GNUNET_TIME_Relative delta,
703 int do_round) 558 int do_round)
@@ -745,15 +600,6 @@ GNUNET_STRINGS_relative_time_to_string (struct GNUNET_TIME_Relative delta,
745} 600}
746 601
747 602
748/**
749 * "asctime", except for GNUnet time. Converts a GNUnet internal
750 * absolute time (which is in UTC) to a string in local time.
751 * Note that the returned value will be overwritten if this function
752 * is called again.
753 *
754 * @param t the absolute time to convert
755 * @return timestamp in human-readable form in local time
756 */
757const char * 603const char *
758GNUNET_STRINGS_absolute_time_to_string (struct GNUNET_TIME_Absolute t) 604GNUNET_STRINGS_absolute_time_to_string (struct GNUNET_TIME_Absolute t)
759{ 605{
@@ -776,17 +622,6 @@ GNUNET_STRINGS_absolute_time_to_string (struct GNUNET_TIME_Absolute t)
776} 622}
777 623
778 624
779/**
780 * "man basename"
781 * Returns a pointer to a part of filename (allocates nothing)!
782 *
783 * @param filename filename to extract basename from
784 * @return short (base) name of the file (that is, everything following the
785 * last directory separator in filename. If filename ends with a
786 * directory separator, the result will be a zero-length string.
787 * If filename has no directory separators, the result is filename
788 * itself.
789 */
790const char * 625const char *
791GNUNET_STRINGS_get_short_name (const char *filename) 626GNUNET_STRINGS_get_short_name (const char *filename)
792{ 627{
@@ -856,18 +691,6 @@ getValue__ (unsigned char a)
856} 691}
857 692
858 693
859/**
860 * Convert binary data to ASCII encoding using Crockford Base32 encoding.
861 * Returns a pointer to the byte after the last byte in the string, that
862 * is where the 0-terminator was placed if there was room.
863 *
864 * @param data data to encode
865 * @param size size of data (in bytes)
866 * @param out buffer to fill
867 * @param out_size size of the buffer. Must be large enough to hold
868 * (size * 8 + 4) / 5 bytes
869 * @return pointer to the next byte in @a out or NULL on error.
870 */
871char * 694char *
872GNUNET_STRINGS_data_to_string (const void *data, 695GNUNET_STRINGS_data_to_string (const void *data,
873 size_t size, 696 size_t size,
@@ -923,16 +746,6 @@ GNUNET_STRINGS_data_to_string (const void *data,
923} 746}
924 747
925 748
926/**
927 * Return the base32crockford encoding of the given buffer.
928 *
929 * The returned string will be freshly allocated, and must be free'd
930 * with GNUNET_free().
931 *
932 * @param buffer with data
933 * @param size size of the buffer
934 * @return freshly allocated, null-terminated string
935 */
936char * 749char *
937GNUNET_STRINGS_data_to_string_alloc (const void *buf, size_t size) 750GNUNET_STRINGS_data_to_string_alloc (const void *buf, size_t size)
938{ 751{
@@ -958,17 +771,7 @@ GNUNET_STRINGS_data_to_string_alloc (const void *buf, size_t size)
958} 771}
959 772
960 773
961/** 774enum GNUNET_GenericReturnValue
962 * Convert Crockford Base32hex encoding back to data.
963 * @a out_size must match exactly the size of the data before it was encoded.
964 *
965 * @param enc the encoding
966 * @param enclen number of characters in @a enc (without 0-terminator, which can be missing)
967 * @param out location where to store the decoded data
968 * @param out_size size of the output buffer @a out
969 * @return #GNUNET_OK on success, #GNUNET_SYSERR if result has the wrong encoding
970 */
971int
972GNUNET_STRINGS_string_to_data (const char *enc, 775GNUNET_STRINGS_string_to_data (const char *enc,
973 size_t enclen, 776 size_t enclen,
974 void *out, 777 void *out,
@@ -1034,23 +837,49 @@ GNUNET_STRINGS_string_to_data (const char *enc,
1034} 837}
1035 838
1036 839
1037/** 840enum GNUNET_GenericReturnValue
1038 * Parse a path that might be an URI. 841GNUNET_STRINGS_string_to_data_alloc (const char *enc,
1039 * 842 size_t enclen,
1040 * @param path path to parse. Must be NULL-terminated. 843 void **out,
1041 * @param scheme_part a pointer to 'char *' where a pointer to a string that 844 size_t *out_size)
1042 * represents the URI scheme will be stored. Can be NULL. The string is 845{
1043 * allocated by the function, and should be freed by GNUNET_free() when 846 size_t size;
1044 * it is no longer needed. 847 void *data;
1045 * @param path_part a pointer to 'const char *' where a pointer to the path 848 int res;
1046 * part of the URI will be stored. Can be NULL. Points to the same block 849
1047 * of memory as 'path', and thus must not be freed. Might point to '\0', 850 size = (enclen * 5) / 8;
1048 * if path part is zero-length. 851 if (size >= GNUNET_MAX_MALLOC_CHECKED)
1049 * @return GNUNET_YES if it's an URI, GNUNET_NO otherwise. If 'path' is not 852 {
1050 * an URI, '* scheme_part' and '*path_part' will remain unchanged 853 GNUNET_break_op (0);
1051 * (if they weren't NULL). 854 return GNUNET_SYSERR;
1052 */ 855 }
1053int 856 data = GNUNET_malloc (size);
857 res = GNUNET_STRINGS_string_to_data (enc,
858 enclen,
859 data,
860 size);
861 if ( (0 < size) &&
862 (GNUNET_OK != res) )
863 {
864 size--;
865 res = GNUNET_STRINGS_string_to_data (enc,
866 enclen,
867 data,
868 size);
869 }
870 if (GNUNET_OK != res)
871 {
872 GNUNET_break_op (0);
873 GNUNET_free (data);
874 return GNUNET_SYSERR;
875 }
876 *out = data;
877 *out_size = size;
878 return GNUNET_OK;
879}
880
881
882enum GNUNET_GenericReturnValue
1054GNUNET_STRINGS_parse_uri (const char *path, 883GNUNET_STRINGS_parse_uri (const char *path,
1055 char **scheme_part, 884 char **scheme_part,
1056 const char **path_part) 885 const char **path_part)
@@ -1112,21 +941,7 @@ GNUNET_STRINGS_parse_uri (const char *path,
1112} 941}
1113 942
1114 943
1115/** 944enum GNUNET_GenericReturnValue
1116 * Check whether @a filename is absolute or not, and if it's an URI
1117 *
1118 * @param filename filename to check
1119 * @param can_be_uri #GNUNET_YES to check for being URI, #GNUNET_NO - to
1120 * assume it's not URI
1121 * @param r_is_uri a pointer to an int that is set to #GNUNET_YES if @a filename
1122 * is URI and to #GNUNET_NO otherwise. Can be NULL. If @a can_be_uri is
1123 * not #GNUNET_YES, `* r_is_uri` is set to #GNUNET_NO.
1124 * @param r_uri_scheme a pointer to a char * that is set to a pointer to URI scheme.
1125 * The string is allocated by the function, and should be freed with
1126 * GNUNET_free(). Can be NULL.
1127 * @return #GNUNET_YES if @a filename is absolute, #GNUNET_NO otherwise.
1128 */
1129int
1130GNUNET_STRINGS_path_is_absolute (const char *filename, 945GNUNET_STRINGS_path_is_absolute (const char *filename,
1131 int can_be_uri, 946 int can_be_uri,
1132 int *r_is_uri, 947 int *r_is_uri,
@@ -1168,15 +983,7 @@ GNUNET_STRINGS_path_is_absolute (const char *filename,
1168} 983}
1169 984
1170 985
1171/** 986enum GNUNET_GenericReturnValue
1172 * Perform @a checks on @a filename.
1173 *
1174 * @param filename file to check
1175 * @param checks checks to perform
1176 * @return #GNUNET_YES if all checks pass, #GNUNET_NO if at least one of them
1177 * fails, #GNUNET_SYSERR when a check can't be performed
1178 */
1179int
1180GNUNET_STRINGS_check_filename (const char *filename, 987GNUNET_STRINGS_check_filename (const char *filename,
1181 enum GNUNET_STRINGS_FilenameCheck checks) 988 enum GNUNET_STRINGS_FilenameCheck checks)
1182{ 989{
@@ -1209,19 +1016,7 @@ GNUNET_STRINGS_check_filename (const char *filename,
1209} 1016}
1210 1017
1211 1018
1212/** 1019enum GNUNET_GenericReturnValue
1213 * Tries to convert @a zt_addr string to an IPv6 address.
1214 * The string is expected to have the format "[ABCD::01]:80".
1215 *
1216 * @param zt_addr 0-terminated string. May be mangled by the function.
1217 * @param addrlen length of @a zt_addr (not counting 0-terminator).
1218 * @param r_buf a buffer to fill. Initially gets filled with zeroes,
1219 * then its sin6_port, sin6_family and sin6_addr are set appropriately.
1220 * @return #GNUNET_OK if conversion succeeded.
1221 * #GNUNET_SYSERR otherwise, in which
1222 * case the contents of @a r_buf are undefined.
1223 */
1224int
1225GNUNET_STRINGS_to_address_ipv6 (const char *zt_addr, 1020GNUNET_STRINGS_to_address_ipv6 (const char *zt_addr,
1226 uint16_t addrlen, 1021 uint16_t addrlen,
1227 struct sockaddr_in6 *r_buf) 1022 struct sockaddr_in6 *r_buf)
@@ -1284,18 +1079,7 @@ GNUNET_STRINGS_to_address_ipv6 (const char *zt_addr,
1284} 1079}
1285 1080
1286 1081
1287/** 1082enum GNUNET_GenericReturnValue
1288 * Tries to convert 'zt_addr' string to an IPv4 address.
1289 * The string is expected to have the format "1.2.3.4:80".
1290 *
1291 * @param zt_addr 0-terminated string. May be mangled by the function.
1292 * @param addrlen length of @a zt_addr (not counting 0-terminator).
1293 * @param r_buf a buffer to fill.
1294 * @return #GNUNET_OK if conversion succeeded.
1295 * #GNUNET_SYSERR otherwise, in which case
1296 * the contents of @a r_buf are undefined.
1297 */
1298int
1299GNUNET_STRINGS_to_address_ipv4 (const char *zt_addr, 1083GNUNET_STRINGS_to_address_ipv4 (const char *zt_addr,
1300 uint16_t addrlen, 1084 uint16_t addrlen,
1301 struct sockaddr_in *r_buf) 1085 struct sockaddr_in *r_buf)
@@ -1333,18 +1117,7 @@ GNUNET_STRINGS_to_address_ipv4 (const char *zt_addr,
1333} 1117}
1334 1118
1335 1119
1336/** 1120enum GNUNET_GenericReturnValue
1337 * Tries to convert @a addr string to an IP (v4 or v6) address.
1338 * Will automatically decide whether to treat 'addr' as v4 or v6 address.
1339 *
1340 * @param addr a string, may not be 0-terminated.
1341 * @param addrlen number of bytes in @a addr (if addr is 0-terminated,
1342 * 0-terminator should not be counted towards addrlen).
1343 * @param r_buf a buffer to fill.
1344 * @return #GNUNET_OK if conversion succeeded. #GNUNET_SYSERR otherwise, in which
1345 * case the contents of @a r_buf are undefined.
1346 */
1347int
1348GNUNET_STRINGS_to_address_ip (const char *addr, 1121GNUNET_STRINGS_to_address_ip (const char *addr,
1349 uint16_t addrlen, 1122 uint16_t addrlen,
1350 struct sockaddr_storage *r_buf) 1123 struct sockaddr_storage *r_buf)
@@ -1359,15 +1132,6 @@ GNUNET_STRINGS_to_address_ip (const char *addr,
1359} 1132}
1360 1133
1361 1134
1362/**
1363 * Parse an address given as a string into a
1364 * `struct sockaddr`.
1365 *
1366 * @param addr the address
1367 * @param[out] af set to the parsed address family (e.g. AF_INET)
1368 * @param[out] sa set to the parsed address
1369 * @return 0 on error, otherwise number of bytes in @a sa
1370 */
1371size_t 1135size_t
1372GNUNET_STRINGS_parse_socket_addr (const char *addr, 1136GNUNET_STRINGS_parse_socket_addr (const char *addr,
1373 uint8_t *af, 1137 uint8_t *af,
@@ -1441,21 +1205,7 @@ _make_continuous_arg_copy (int argc, char *const *argv)
1441} 1205}
1442 1206
1443 1207
1444/** 1208enum GNUNET_GenericReturnValue
1445 * Returns utf-8 encoded arguments.
1446 * Does nothing (returns a copy of argc and argv) on any platform
1447 * other than W32.
1448 * Returned argv has u8argv[u8argc] == NULL.
1449 * Returned argv is a single memory block, and can be freed with a single
1450 * GNUNET_free() call.
1451 *
1452 * @param argc argc (as given by main())
1453 * @param argv argv (as given by main())
1454 * @param u8argc a location to store new argc in (though it's th same as argc)
1455 * @param u8argv a location to store new argv in
1456 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
1457 */
1458int
1459GNUNET_STRINGS_get_utf8_args (int argc, 1209GNUNET_STRINGS_get_utf8_args (int argc,
1460 char *const *argv, 1210 char *const *argv,
1461 int *u8argc, 1211 int *u8argc,
@@ -1478,7 +1228,7 @@ GNUNET_STRINGS_get_utf8_args (int argc,
1478 * @return #GNUNET_OK on success, #GNUNET_SYSERR if the 1228 * @return #GNUNET_OK on success, #GNUNET_SYSERR if the
1479 * @a port_policy is malformed 1229 * @a port_policy is malformed
1480 */ 1230 */
1481static int 1231static enum GNUNET_GenericReturnValue
1482parse_port_policy (const char *port_policy, 1232parse_port_policy (const char *port_policy,
1483 struct GNUNET_STRINGS_PortPolicy *pp) 1233 struct GNUNET_STRINGS_PortPolicy *pp)
1484{ 1234{
@@ -1523,18 +1273,6 @@ parse_port_policy (const char *port_policy,
1523} 1273}
1524 1274
1525 1275
1526/**
1527 * Parse an IPv4 network policy. The argument specifies a list of
1528 * subnets. The format is
1529 * <tt>(network[/netmask][:SPORT[-DPORT]];)*</tt> (no whitespace, must
1530 * be terminated with a semicolon). The network must be given in
1531 * dotted-decimal notation. The netmask can be given in CIDR notation
1532 * (/16) or in dotted-decimal (/255.255.0.0).
1533 *
1534 * @param routeListX a string specifying the IPv4 subnets
1535 * @return the converted list, terminated with all zeros;
1536 * NULL if the synatx is flawed
1537 */
1538struct GNUNET_STRINGS_IPv4NetworkPolicy * 1276struct GNUNET_STRINGS_IPv4NetworkPolicy *
1539GNUNET_STRINGS_parse_ipv4_policy (const char *routeListX) 1277GNUNET_STRINGS_parse_ipv4_policy (const char *routeListX)
1540{ 1278{
@@ -1716,17 +1454,6 @@ GNUNET_STRINGS_parse_ipv4_policy (const char *routeListX)
1716} 1454}
1717 1455
1718 1456
1719/**
1720 * Parse an IPv6 network policy. The argument specifies a list of
1721 * subnets. The format is <tt>(network[/netmask[:SPORT[-DPORT]]];)*</tt>
1722 * (no whitespace, must be terminated with a semicolon). The network
1723 * must be given in colon-hex notation. The netmask must be given in
1724 * CIDR notation (/16) or can be omitted to specify a single host.
1725 * Note that the netmask is mandatory if ports are specified.
1726 *
1727 * @param routeListX a string specifying the policy
1728 * @return the converted list, 0-terminated, NULL if the synatx is flawed
1729 */
1730struct GNUNET_STRINGS_IPv6NetworkPolicy * 1457struct GNUNET_STRINGS_IPv6NetworkPolicy *
1731GNUNET_STRINGS_parse_ipv6_policy (const char *routeListX) 1458GNUNET_STRINGS_parse_ipv6_policy (const char *routeListX)
1732{ 1459{
@@ -1863,17 +1590,10 @@ static char *cvt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
1863 "0123456789+/"; 1590 "0123456789+/";
1864 1591
1865 1592
1866/**
1867 * Encode into Base64.
1868 *
1869 * @param in the data to encode
1870 * @param len the length of the input
1871 * @param output where to write the output (*output should be NULL,
1872 * is allocated)
1873 * @return the size of the output
1874 */
1875size_t 1593size_t
1876GNUNET_STRINGS_base64_encode (const void *in, size_t len, char **output) 1594GNUNET_STRINGS_base64_encode (const void *in,
1595 size_t len,
1596 char **output)
1877{ 1597{
1878 const char *data = in; 1598 const char *data = in;
1879 size_t ret; 1599 size_t ret;
@@ -1919,17 +1639,10 @@ GNUNET_STRINGS_base64_encode (const void *in, size_t len, char **output)
1919} 1639}
1920 1640
1921 1641
1922/**
1923 * Encode into Base64url. RFC7515
1924 *
1925 * @param in the data to encode
1926 * @param len the length of the input
1927 * @param output where to write the output (*output should be NULL,
1928 * is allocated)
1929 * @return the size of the output
1930 */
1931size_t 1642size_t
1932GNUNET_STRINGS_base64url_encode (const void *in, size_t len, char **output) 1643GNUNET_STRINGS_base64url_encode (const void *in,
1644 size_t len,
1645 char **output)
1933{ 1646{
1934 char *enc; 1647 char *enc;
1935 size_t pos; 1648 size_t pos;
@@ -1965,17 +1678,10 @@ GNUNET_STRINGS_base64url_encode (const void *in, size_t len, char **output)
1965 : ((a) == '+') ? 62 : ((a) == '/') ? 63 : -1) 1678 : ((a) == '+') ? 62 : ((a) == '/') ? 63 : -1)
1966 1679
1967 1680
1968/**
1969 * Decode from Base64.
1970 *
1971 * @param data the data to encode
1972 * @param len the length of the input
1973 * @param output where to write the output (*output should be NULL,
1974 * is allocated)
1975 * @return the size of the output
1976 */
1977size_t 1681size_t
1978GNUNET_STRINGS_base64_decode (const char *data, size_t len, void **out) 1682GNUNET_STRINGS_base64_decode (const char *data,
1683 size_t len,
1684 void **out)
1979{ 1685{
1980 char *output; 1686 char *output;
1981 size_t ret = 0; 1687 size_t ret = 0;
@@ -2037,17 +1743,10 @@ END:
2037} 1743}
2038 1744
2039 1745
2040/**
2041 * Decode from Base64url. RFC7515
2042 *
2043 * @param data the data to decode
2044 * @param len the length of the input
2045 * @param output where to write the output (*output should be NULL,
2046 * is allocated)
2047 * @return the size of the output
2048 */
2049size_t 1746size_t
2050GNUNET_STRINGS_base64url_decode (const char *data, size_t len, void **out) 1747GNUNET_STRINGS_base64url_decode (const char *data,
1748 size_t len,
1749 void **out)
2051{ 1750{
2052 char *s; 1751 char *s;
2053 int padding; 1752 int padding;
@@ -2090,17 +1789,10 @@ GNUNET_STRINGS_base64url_decode (const char *data, size_t len, void **out)
2090} 1789}
2091 1790
2092 1791
2093/**
2094 * url/percent encode (RFC3986).
2095 *
2096 * @param data the data to encode
2097 * @param len the length of the input
2098 * @param output where to write the output (*output should be NULL,
2099 * is allocated)
2100 * @return the size of the output
2101 */
2102size_t 1792size_t
2103GNUNET_STRINGS_urldecode (const char *data, size_t len, char **out) 1793GNUNET_STRINGS_urldecode (const char *data,
1794 size_t len,
1795 char **out)
2104{ 1796{
2105 const char *rpos = data; 1797 const char *rpos = data;
2106 *out = GNUNET_malloc (len + 1); /* output should always fit into input */ 1798 *out = GNUNET_malloc (len + 1); /* output should always fit into input */
@@ -2134,17 +1826,10 @@ GNUNET_STRINGS_urldecode (const char *data, size_t len, char **out)
2134} 1826}
2135 1827
2136 1828
2137/**
2138 * url/percent encode (RFC3986).
2139 *
2140 * @param data the data to decode
2141 * @param len the length of the input
2142 * @param output where to write the output (*output should be NULL,
2143 * is allocated)
2144 * @return the size of the output
2145 */
2146size_t 1829size_t
2147GNUNET_STRINGS_urlencode (const char *data, size_t len, char **out) 1830GNUNET_STRINGS_urlencode (const char *data,
1831 size_t len,
1832 char **out)
2148{ 1833{
2149 struct GNUNET_Buffer buf = { 0 }; 1834 struct GNUNET_Buffer buf = { 0 };
2150 const uint8_t *i8 = (uint8_t *) data; 1835 const uint8_t *i8 = (uint8_t *) data;