#if HAVE_ICONV
#include <iconv.h>
#endif
-#include "gnunet_common.h"
-#include "gnunet_strings_lib.h"
+#include "gnunet_util_lib.h"
#include <unicase.h>
#include <unistr.h>
#include <uniconv.h>
*
* @param fancy_time human readable string (i.e. 1 minute)
* @param rtime set to the relative time
- * @return GNUNET_OK on success, GNUNET_SYSERR on error
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
*/
int
GNUNET_STRINGS_fancy_time_to_relative (const char *fancy_time,
/**
* Convert a given fancy human-readable time to our internal
- * representation.
+ * representation. The human-readable time is expected to be
+ * in local time, whereas the returned value will be in UTC.
*
* @param fancy_time human readable string (i.e. %Y-%m-%d %H:%M:%S)
* @param atime set to the absolute time
- * @return GNUNET_OK on success, GNUNET_SYSERR on error
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
*/
int
GNUNET_STRINGS_fancy_time_to_absolute (const char *fancy_time,
* Convert the len characters long character sequence
* given in input that is in the given input charset
* to a string in given output charset.
+ *
+ * @param input input string
+ * @param len number of bytes in @a input
+ * @param input_charset character set used for @a input
+ * @param ouptut_charset desired character set for the return value
* @return the converted string (0-terminated),
* if conversion fails, a copy of the orignal
* string is returned.
*/
char *
GNUNET_STRINGS_conv (const char *input,
- size_t len,
- const char *input_charset,
+ size_t len,
+ const char *input_charset,
const char *output_charset)
{
char *ret;
size_t u8_string_length;
size_t encoded_string_length;
- u8_string = u8_conv_from_encoding (input_charset,
- iconveh_error,
- input, len,
- NULL, NULL,
+ u8_string = u8_conv_from_encoding (input_charset,
+ iconveh_error,
+ input, len,
+ NULL, NULL,
&u8_string_length);
if (NULL == u8_string)
{
free (u8_string);
return ret;
}
- encoded_string = u8_conv_to_encoding (output_charset, iconveh_error,
- u8_string, u8_string_length,
- NULL, NULL,
+ encoded_string = u8_conv_to_encoding (output_charset, iconveh_error,
+ u8_string, u8_string_length,
+ NULL, NULL,
&encoded_string_length);
free (u8_string);
if (NULL == encoded_string)
* Convert the len characters long character sequence
* given in input that is in the given charset
* to UTF-8.
+ *
+ * @param input the input string (not necessarily 0-terminated)
+ * @param len the number of bytes in the @a input
+ * @param charset character set to convert from
* @return the converted string (0-terminated),
* if conversion fails, a copy of the orignal
* string is returned.
*/
char *
-GNUNET_STRINGS_to_utf8 (const char *input, size_t len, const char *charset)
+GNUNET_STRINGS_to_utf8 (const char *input,
+ size_t len,
+ const char *charset)
{
return GNUNET_STRINGS_conv (input, len, charset, "UTF-8");
}
* Convert the len bytes-long UTF-8 string
* given in input to the given charset.
*
+ * @param input the input string (not necessarily 0-terminated)
+ * @param len the number of bytes in the @a input
+ * @param charset character set to convert to
* @return the converted string (0-terminated),
* if conversion fails, a copy of the orignal
* string is returned.
*/
char *
-GNUNET_STRINGS_from_utf8 (const char *input, size_t len, const char *charset)
+GNUNET_STRINGS_from_utf8 (const char *input,
+ size_t len,
+ const char *charset)
{
return GNUNET_STRINGS_conv (input, len, "UTF-8", charset);
}
return _("forever");
if (0 == delta.rel_value_us)
return _("0 ms");
- if ( ( (GNUNET_YES == do_round) &&
- (dval > 5 * 1000) ) ||
+ if ( ( (GNUNET_YES == do_round) &&
+ (dval > 5 * 1000) ) ||
(0 == (dval % 1000) ))
{
dval = dval / 1000;
unit = _( /* time unit */ "ms");
- if ( ( (GNUNET_YES == do_round) &&
- (dval > 5 * 1000) ) ||
+ if ( ( (GNUNET_YES == do_round) &&
+ (dval > 5 * 1000) ) ||
(0 == (dval % 1000) ))
{
dval = dval / 1000;
dval = dval / 60;
unit = _( /* time unit */ "m");
if ( ( (GNUNET_YES == do_round) &&
- (dval > 5 * 60) ) ||
+ (dval > 5 * 60) ) ||
(0 == (dval % 60) ))
{
dval = dval / 60;
/**
- * "asctime", except for GNUnet time.
- * This is one of the very few calls in the entire API that is
- * NOT reentrant!
+ * "asctime", except for GNUnet time. Converts a GNUnet internal
+ * absolute time (which is in UTC) to a string in local time.
+ * Note that the returned value will be overwritten if this function
+ * is called again.
*
* @param t time to convert
* @return absolute time in human-readable format
* Convert binary data to ASCII encoding. The ASCII encoding is rather
* GNUnet specific. It was chosen such that it only uses characters
* in [0-9A-V], can be produced without complex arithmetics and uses a
- * small number of characters.
+ * small number of characters.
* Does not append 0-terminator, but returns a pointer to the place where
* it should be placed, if needed.
*
GNUNET_STRINGS_data_to_string (const void *data, size_t size, char *out, size_t out_size)
{
/**
- * 32 characters for encoding
+ * 32 characters for encoding
*/
static char *encTable__ = "0123456789ABCDEFGHIJKLMNOPQRSTUV";
unsigned int wpos;
/**
* Perform 'checks' on 'filename'
- *
+ *
* @param filename file to check
* @param checks checks to perform
* @return GNUNET_YES if all checks pass, GNUNET_NO if at least one of them
/**
* Tries to convert 'zt_addr' string to an IPv6 address.
* The string is expected to have the format "[ABCD::01]:80".
- *
+ *
* @param zt_addr 0-terminated string. May be mangled by the function.
* @param addrlen length of zt_addr (not counting 0-terminator).
* @param r_buf a buffer to fill. Initially gets filled with zeroes,
* case the contents of r_buf are undefined.
*/
int
-GNUNET_STRINGS_to_address_ipv6 (const char *zt_addr,
+GNUNET_STRINGS_to_address_ipv6 (const char *zt_addr,
uint16_t addrlen,
struct sockaddr_in6 *r_buf)
{
unsigned int port;
if (addrlen < 6)
- return GNUNET_SYSERR;
+ return GNUNET_SYSERR;
memcpy (zbuf, zt_addr, addrlen);
if ('[' != zbuf[0])
{
/**
* Tries to convert 'zt_addr' string to an IPv4 address.
* The string is expected to have the format "1.2.3.4:80".
- *
+ *
* @param zt_addr 0-terminated string. May be mangled by the function.
* @param addrlen length of zt_addr (not counting 0-terminator).
* @param r_buf a buffer to fill.
/**
* Tries to convert 'addr' string to an IP (v4 or v6) address.
* Will automatically decide whether to treat 'addr' as v4 or v6 address.
- *
+ *
* @param addr a string, may not be 0-terminated.
* @param addrlen number of bytes in addr (if addr is 0-terminated,
* 0-terminator should not be counted towards addrlen).
* case the contents of r_buf are undefined.
*/
int
-GNUNET_STRINGS_to_address_ip (const char *addr,
+GNUNET_STRINGS_to_address_ip (const char *addr,
uint16_t addrlen,
struct sockaddr_storage *r_buf)
{
size_t strl;
/* Hopefully it will allocate us NUL-terminated strings... */
split_u8argv[i] = (char *) u16_to_u8 (wargv[i], wcslen (wargv[i]) + 1, NULL, &strl);
- if (split_u8argv == NULL)
+ if (NULL == split_u8argv[i])
{
int j;
for (j = 0; j < i; j++)