aboutsummaryrefslogtreecommitdiffstats
path: root/facebook/facebook-util.c
diff options
context:
space:
mode:
Diffstat (limited to 'facebook/facebook-util.c')
-rw-r--r--facebook/facebook-util.c53
1 files changed, 25 insertions, 28 deletions
diff --git a/facebook/facebook-util.c b/facebook/facebook-util.c
index a436a46..0fadc6e 100644
--- a/facebook/facebook-util.c
+++ b/facebook/facebook-util.c
@@ -204,7 +204,7 @@ fb_util_debug_hexdump(FbDebugLevel level, const GByteArray *bytes,
}
gchar *
-fb_util_locale_str(void)
+fb_util_get_locale(void)
{
const gchar * const *langs;
const gchar *lang;
@@ -232,7 +232,7 @@ fb_util_locale_str(void)
}
gchar *
-fb_util_randstr(gsize size)
+fb_util_rand_alnum(guint len)
{
gchar *ret;
GRand *rand;
@@ -245,25 +245,34 @@ fb_util_randstr(gsize size)
"0123456789";
static const gsize charc = G_N_ELEMENTS(chars) - 1;
- if (G_UNLIKELY(size < 1)) {
- return NULL;
- }
-
+ g_return_val_if_fail(len > 0, NULL);
rand = g_rand_new();
- ret = g_new(gchar, size + 1);
+ ret = g_new(gchar, len + 1);
- for (i = 0; i < size; i++) {
+ for (i = 0; i < len; i++) {
j = g_rand_int_range(rand, 0, charc);
ret[i] = chars[j];
}
- ret[size] = 0;
+ ret[len] = 0;
g_rand_free(rand);
return ret;
}
+gchar *
+fb_util_rand_uuid(void)
+{
+ guint8 buf[50];
+ sha1_state_t sha;
+
+ sha1_init(&sha);
+ random_bytes(buf, sizeof buf);
+ sha1_append(&sha, buf, sizeof buf);
+ return sha1_random_uuid(&sha);
+}
+
gboolean
-fb_util_str_is(const gchar *str, GAsciiType type)
+fb_util_strtest(const gchar *str, GAsciiType type)
{
gsize i;
gsize size;
@@ -283,20 +292,8 @@ fb_util_str_is(const gchar *str, GAsciiType type)
return TRUE;
}
-gchar *
-fb_util_uuid(void)
-{
- guint8 buf[50];
- sha1_state_t sha;
-
- sha1_init(&sha);
- random_bytes(buf, sizeof buf);
- sha1_append(&sha, buf, sizeof buf);
- return sha1_random_uuid(&sha);
-}
-
gboolean
-fb_util_zcompressed(const GByteArray *bytes)
+fb_util_zlib_test(const GByteArray *bytes)
{
guint8 b0;
guint8 b1;
@@ -315,7 +312,7 @@ fb_util_zcompressed(const GByteArray *bytes)
}
static GByteArray *
-fb_util_zconv(GConverter *conv, const GByteArray *bytes, GError **error)
+fb_util_zlib_conv(GConverter *conv, const GByteArray *bytes, GError **error)
{
GByteArray *ret;
GConverterResult res;
@@ -358,25 +355,25 @@ fb_util_zconv(GConverter *conv, const GByteArray *bytes, GError **error)
}
GByteArray *
-fb_util_zcompress(const GByteArray *bytes, GError **error)
+fb_util_zlib_deflate(const GByteArray *bytes, GError **error)
{
GByteArray *ret;
GZlibCompressor *conv;
conv = g_zlib_compressor_new(G_ZLIB_COMPRESSOR_FORMAT_ZLIB, -1);
- ret = fb_util_zconv(G_CONVERTER(conv), bytes, error);
+ ret = fb_util_zlib_conv(G_CONVERTER(conv), bytes, error);
g_object_unref(conv);
return ret;
}
GByteArray *
-fb_util_zuncompress(const GByteArray *bytes, GError **error)
+fb_util_zlib_inflate(const GByteArray *bytes, GError **error)
{
GByteArray *ret;
GZlibDecompressor *conv;
conv = g_zlib_decompressor_new(G_ZLIB_COMPRESSOR_FORMAT_ZLIB);
- ret = fb_util_zconv(G_CONVERTER(conv), bytes, error);
+ ret = fb_util_zlib_conv(G_CONVERTER(conv), bytes, error);
g_object_unref(conv);
return ret;
}