#endif
#include "gnunet_common.h"
#include "gnunet_strings_lib.h"
+#include <unicase.h>
#define LOG(kind,...) GNUNET_log_from (kind, "util", __VA_ARGS__)
{ "'", 60 * 1000},
{ "h", 60 * 60 * 1000},
{ "d", 24 * 60 * 60 * 1000},
- { "a", 31557600 /* year */ },
+ { "a", 31536000000LL /* year */ },
{ NULL, 0}
};
int ret;
return GNUNET_STRINGS_conv (input, len, "UTF-8", charset);
}
+/**
+ * Convert the utf-8 input string to lowercase
+ * Output needs to be allocated appropriately
+ *
+ * @param input input string
+ * @param output output buffer
+ */
+void
+GNUNET_STRINGS_utf8_tolower(const char* input, char** output)
+{
+ uint8_t *tmp_in;
+ size_t len;
+
+ tmp_in = u8_tolower ((uint8_t*)input, strlen ((char *) input),
+ NULL, UNINORM_NFD, NULL, &len);
+ memcpy(*output, tmp_in, len);
+ (*output)[len] = '\0';
+ free(tmp_in);
+}
+
+/**
+ * Convert the utf-8 input string to uppercase
+ * Output needs to be allocated appropriately
+ *
+ * @param input input string
+ * @param output output buffer
+ */
+void
+GNUNET_STRINGS_utf8_toupper(const char* input, char** output)
+{
+ uint8_t *tmp_in;
+ size_t len;
+
+ tmp_in = u8_toupper ((uint8_t*)input, strlen ((char *) input),
+ NULL, UNINORM_NFD, NULL, &len);
+ memcpy(*output, tmp_in, len);
+ (*output)[len] = '\0';
+ free(tmp_in);
+}
/**
* @return pointer to the next byte in 'out' or NULL on error.
*/
char *
-GNUNET_STRINGS_data_to_string (unsigned char *data, size_t size, char *out, size_t out_size)
+GNUNET_STRINGS_data_to_string (const unsigned char *data, size_t size, char *out, size_t out_size)
{
/**
- * 32 characters for encoding (GNUNET_CRYPTO_hash => 32 characters)
+ * 32 characters for encoding
*/
static char *encTable__ = "0123456789ABCDEFGHIJKLMNOPQRSTUV";
unsigned int wpos;
GNUNET_assert (data != NULL);
GNUNET_assert (out != NULL);
- GNUNET_assert (out_size >= (((size*8) + ((size*8) % 5)) % 5));
+ if (out_size < (((size*8) + ((size*8) % 5)) % 5))
+ {
+ GNUNET_break (0);
+ return NULL;
+ }
vbit = 0;
wpos = 0;
rpos = 0;
vbit = 5;
}
if (wpos >= out_size)
+ {
+ GNUNET_break (0);
return NULL;
+ }
out[wpos++] = encTable__[(bits >> (vbit - 5)) & 31];
vbit -= 5;
}
if (wpos != out_size)
+ {
+ GNUNET_break (0);
return NULL;
+ }
GNUNET_assert (vbit == 0);
return &out[wpos];
}
ret = inet_pton (AF_INET6, zt_addr, &r_buf->sin6_addr);
if (ret <= 0)
return GNUNET_SYSERR;
- r_buf->sin6_port = htonl (port);
+ r_buf->sin6_port = htons (port);
r_buf->sin6_family = AF_INET6;
return GNUNET_OK;
}
if (port > 65535)
return GNUNET_SYSERR;
+
+
r_buf->sin_family = AF_INET;
- r_buf->sin_port = htonl (port);
+ r_buf->sin_port = htons (port);
r_buf->sin_addr.s_addr = htonl ((temps[0] << 24) + (temps[1] << 16) +
(temps[2] << 8) + temps[3]);
return GNUNET_OK;