-removing 2nd argument from GNUNET_CLIENT_disconnect as it was virtually always GNUNE...
[oweals/gnunet.git] / src / util / strings.c
index d796d889461cdff192a359f5e3d7f4208387408f..f9e2d8da67ecd2522d820700cda4d96d67cd42c1 100644 (file)
@@ -31,6 +31,7 @@
 #endif
 #include "gnunet_common.h"
 #include "gnunet_strings_lib.h"
+#include <unicase.h>
 
 #define LOG(kind,...) GNUNET_log_from (kind, "util", __VA_ARGS__)
 
@@ -401,6 +402,45 @@ GNUNET_STRINGS_from_utf8 (const char *input, size_t len, const char *charset)
   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);
+}
 
 
 /**
@@ -977,7 +1017,7 @@ GNUNET_STRINGS_to_address_ipv6 (const char *zt_addr,
   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;
 }
@@ -1013,8 +1053,10 @@ GNUNET_STRINGS_to_address_ipv4 (const char *zt_addr, uint16_t addrlen,
   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;