diff options
-rw-r--r-- | src/include/gnunet_strings_lib.h | 13 | ||||
-rw-r--r-- | src/util/strings.c | 41 |
2 files changed, 51 insertions, 3 deletions
diff --git a/src/include/gnunet_strings_lib.h b/src/include/gnunet_strings_lib.h index d68ca5c78..a0d261d49 100644 --- a/src/include/gnunet_strings_lib.h +++ b/src/include/gnunet_strings_lib.h | |||
@@ -76,6 +76,19 @@ GNUNET_STRINGS_fancy_time_to_relative (const char *fancy_time, | |||
76 | 76 | ||
77 | 77 | ||
78 | /** | 78 | /** |
79 | * Convert a given fancy human-readable time to our internal | ||
80 | * representation. | ||
81 | * | ||
82 | * @param fancy_time human readable string (i.e. %Y-%m-%d %H:%M:%S) | ||
83 | * @param atime set to the absolute time | ||
84 | * @return GNUNET_OK on success, GNUNET_SYSERR on error | ||
85 | */ | ||
86 | int | ||
87 | GNUNET_STRINGS_fancy_time_to_absolute (const char *fancy_time, | ||
88 | struct GNUNET_TIME_Absolute *atime); | ||
89 | |||
90 | |||
91 | /** | ||
79 | * Convert a given filesize into a fancy human-readable format. | 92 | * Convert a given filesize into a fancy human-readable format. |
80 | * | 93 | * |
81 | * @param size number of bytes | 94 | * @param size number of bytes |
diff --git a/src/util/strings.c b/src/util/strings.c index cc44767d6..9c7f95e7c 100644 --- a/src/util/strings.c +++ b/src/util/strings.c | |||
@@ -308,6 +308,38 @@ GNUNET_STRINGS_fancy_time_to_relative (const char *fancy_time, | |||
308 | return ret; | 308 | return ret; |
309 | } | 309 | } |
310 | 310 | ||
311 | |||
312 | /** | ||
313 | * Convert a given fancy human-readable time to our internal | ||
314 | * representation. | ||
315 | * | ||
316 | * @param fancy_time human readable string (i.e. %Y-%m-%d %H:%M:%S) | ||
317 | * @param atime set to the absolute time | ||
318 | * @return GNUNET_OK on success, GNUNET_SYSERR on error | ||
319 | */ | ||
320 | int | ||
321 | GNUNET_STRINGS_fancy_time_to_absolute (const char *fancy_time, | ||
322 | struct GNUNET_TIME_Absolute *atime) | ||
323 | { | ||
324 | struct tm tv; | ||
325 | time_t t; | ||
326 | |||
327 | if ( (NULL == strptime (fancy_time, "%c", &tv)) && | ||
328 | (NULL == strptime (fancy_time, "%Ec", &tv)) && | ||
329 | (NULL == strptime (fancy_time, "%Y-%m-%d %H:%M:%S", &tv)) && | ||
330 | (NULL == strptime (fancy_time, "%Y-%m-%d %H:%M", &tv)) && | ||
331 | (NULL == strptime (fancy_time, "%x", &tv)) && | ||
332 | (NULL == strptime (fancy_time, "%Ex", &tv)) && | ||
333 | (NULL == strptime (fancy_time, "%Y-%m-%d", &tv)) && | ||
334 | (NULL == strptime (fancy_time, "%Y-%m", &tv)) && | ||
335 | (NULL == strptime (fancy_time, "%Y", &tv)) ) | ||
336 | return GNUNET_SYSERR; | ||
337 | t = mktime (&tv); | ||
338 | atime->abs_value = (uint64_t) ((uint64_t) t * 1000LL); | ||
339 | return GNUNET_OK; | ||
340 | } | ||
341 | |||
342 | |||
311 | /** | 343 | /** |
312 | * Convert the len characters long character sequence | 344 | * Convert the len characters long character sequence |
313 | * given in input that is in the given input charset | 345 | * given in input that is in the given input charset |
@@ -389,10 +421,11 @@ GNUNET_STRINGS_to_utf8 (const char *input, size_t len, const char *charset) | |||
389 | return GNUNET_STRINGS_conv (input, len, charset, "UTF-8"); | 421 | return GNUNET_STRINGS_conv (input, len, charset, "UTF-8"); |
390 | } | 422 | } |
391 | 423 | ||
424 | |||
392 | /** | 425 | /** |
393 | * Convert the len bytes-long UTF-8 string | 426 | * Convert the len bytes-long UTF-8 string |
394 | * given in input to the given charset. | 427 | * given in input to the given charset. |
395 | 428 | * | |
396 | * @return the converted string (0-terminated), | 429 | * @return the converted string (0-terminated), |
397 | * if conversion fails, a copy of the orignal | 430 | * if conversion fails, a copy of the orignal |
398 | * string is returned. | 431 | * string is returned. |
@@ -403,6 +436,7 @@ GNUNET_STRINGS_from_utf8 (const char *input, size_t len, const char *charset) | |||
403 | return GNUNET_STRINGS_conv (input, len, "UTF-8", charset); | 436 | return GNUNET_STRINGS_conv (input, len, "UTF-8", charset); |
404 | } | 437 | } |
405 | 438 | ||
439 | |||
406 | /** | 440 | /** |
407 | * Convert the utf-8 input string to lowercase | 441 | * Convert the utf-8 input string to lowercase |
408 | * Output needs to be allocated appropriately | 442 | * Output needs to be allocated appropriately |
@@ -423,6 +457,7 @@ GNUNET_STRINGS_utf8_tolower(const char* input, char** output) | |||
423 | free(tmp_in); | 457 | free(tmp_in); |
424 | } | 458 | } |
425 | 459 | ||
460 | |||
426 | /** | 461 | /** |
427 | * Convert the utf-8 input string to uppercase | 462 | * Convert the utf-8 input string to uppercase |
428 | * Output needs to be allocated appropriately | 463 | * Output needs to be allocated appropriately |
@@ -455,7 +490,6 @@ char * | |||
455 | GNUNET_STRINGS_filename_expand (const char *fil) | 490 | GNUNET_STRINGS_filename_expand (const char *fil) |
456 | { | 491 | { |
457 | char *buffer; | 492 | char *buffer; |
458 | |||
459 | #ifndef MINGW | 493 | #ifndef MINGW |
460 | size_t len; | 494 | size_t len; |
461 | size_t n; | 495 | size_t n; |
@@ -982,7 +1016,6 @@ GNUNET_STRINGS_check_filename (const char *filename, | |||
982 | } | 1016 | } |
983 | 1017 | ||
984 | 1018 | ||
985 | |||
986 | /** | 1019 | /** |
987 | * Tries to convert 'zt_addr' string to an IPv6 address. | 1020 | * Tries to convert 'zt_addr' string to an IPv6 address. |
988 | * The string is expected to have the format "[ABCD::01]:80". | 1021 | * The string is expected to have the format "[ABCD::01]:80". |
@@ -1114,6 +1147,7 @@ GNUNET_STRINGS_to_address_ip (const char *addr, | |||
1114 | return GNUNET_STRINGS_to_address_ipv4 (addr, addrlen, (struct sockaddr_in *) r_buf); | 1147 | return GNUNET_STRINGS_to_address_ipv4 (addr, addrlen, (struct sockaddr_in *) r_buf); |
1115 | } | 1148 | } |
1116 | 1149 | ||
1150 | |||
1117 | /** | 1151 | /** |
1118 | * Makes a copy of argv that consists of a single memory chunk that can be | 1152 | * Makes a copy of argv that consists of a single memory chunk that can be |
1119 | * freed with a single call to GNUNET_free (); | 1153 | * freed with a single call to GNUNET_free (); |
@@ -1139,6 +1173,7 @@ _make_continuous_arg_copy (int argc, char *const *argv) | |||
1139 | return (char *const *) new_argv; | 1173 | return (char *const *) new_argv; |
1140 | } | 1174 | } |
1141 | 1175 | ||
1176 | |||
1142 | /** | 1177 | /** |
1143 | * Returns utf-8 encoded arguments. | 1178 | * Returns utf-8 encoded arguments. |
1144 | * Does nothing (returns a copy of argc and argv) on any platform | 1179 | * Does nothing (returns a copy of argc and argv) on any platform |