pidgin/pidgin

77536a48b4be
Parents a06ade737f26
Children b29ee022017f
facebook: refactored util naming and GTK-Doc
--- a/libpurple/protocols/facebook/api.c Wed Dec 16 14:04:26 2015 -0500
+++ b/libpurple/protocols/facebook/api.c Wed Dec 16 15:13:36 2015 -0500
@@ -717,7 +717,7 @@
fb_http_params_set_str(params, "format", "json");
fb_http_params_set_str(params, "method", method);
- val = fb_util_locale_str();
+ val = fb_util_get_locale();
fb_http_params_set_str(params, "locale", val);
g_free(val);
@@ -919,7 +919,7 @@
fb_thrift_write_stop(thft);
bytes = fb_thrift_get_bytes(thft);
- cytes = fb_util_zcompress(bytes, &err);
+ cytes = fb_util_zlib_deflate(bytes, &err);
FB_API_ERROR_EMIT(api, err,
g_object_unref(thft);
@@ -1619,10 +1619,10 @@
{"/t_p", fb_api_cb_publish_p}
};
- comp = fb_util_zcompressed(pload);
+ comp = fb_util_zlib_test(pload);
if (G_LIKELY(comp)) {
- bytes = fb_util_zuncompress(pload, &err);
+ bytes = fb_util_zlib_inflate(pload, &err);
FB_API_ERROR_EMIT(api, err, return);
} else {
bytes = (GByteArray*) pload;
@@ -1685,7 +1685,7 @@
priv = api->priv;
if (priv->cid == NULL) {
- priv->cid = fb_util_randstr(32);
+ priv->cid = fb_util_rand_alnum(32);
}
if (priv->did == NULL) {
@@ -2127,7 +2127,7 @@
va_end(ap);
bytes = g_byte_array_new_take((guint8*) msg, strlen(msg));
- cytes = fb_util_zcompress(bytes, &err);
+ cytes = fb_util_zlib_deflate(bytes, &err);
FB_API_ERROR_EMIT(api, err,
g_byte_array_free(bytes, TRUE);
--- a/libpurple/protocols/facebook/id.h Wed Dec 16 14:04:26 2015 -0500
+++ b/libpurple/protocols/facebook/id.h Wed Dec 16 15:13:36 2015 -0500
@@ -93,7 +93,7 @@
*
* Return: #TRUE if the string is an #FbId, otherwise #FALSE.
*/
-#define FB_ID_IS_STR(s) fb_util_str_is(s, G_ASCII_DIGIT)
+#define FB_ID_IS_STR(s) fb_util_strtest(s, G_ASCII_DIGIT)
/**
* FB_ID_TO_STR:
--- a/libpurple/protocols/facebook/util.c Wed Dec 16 14:04:26 2015 -0500
+++ b/libpurple/protocols/facebook/util.c Wed Dec 16 15:13:36 2015 -0500
@@ -244,7 +244,7 @@
}
gchar *
-fb_util_locale_str(void)
+fb_util_get_locale(void)
{
const gchar * const *langs;
const gchar *lang;
@@ -272,7 +272,7 @@
}
gchar *
-fb_util_randstr(gsize size)
+fb_util_rand_alnum(guint len)
{
gchar *ret;
GRand *rand;
@@ -285,19 +285,16 @@
"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, len + 1);
- rand = g_rand_new();
- ret = g_new(gchar, size + 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;
}
@@ -463,7 +460,7 @@
}
gboolean
-fb_util_str_is(const gchar *str, GAsciiType type)
+fb_util_strtest(const gchar *str, GAsciiType type)
{
gsize i;
gsize size;
@@ -484,7 +481,7 @@
}
gboolean
-fb_util_zcompressed(const GByteArray *bytes)
+fb_util_zlib_test(const GByteArray *bytes)
{
guint8 b0;
guint8 b1;
@@ -503,7 +500,7 @@
}
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;
@@ -546,25 +543,25 @@
}
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;
}
--- a/libpurple/protocols/facebook/util.h Wed Dec 16 14:04:26 2015 -0500
+++ b/libpurple/protocols/facebook/util.h Wed Dec 16 15:13:36 2015 -0500
@@ -216,7 +216,7 @@
G_GNUC_PRINTF(3, 4);
/**
- * fb_util_locale_str:
+ * fb_util_get_locale:
*
* Gets the locale string (ex: en_US) from the system. The returned
* string should be freed with #g_free() when no longer needed.
@@ -224,19 +224,20 @@
* Returns: The locale string.
*/
gchar *
-fb_util_locale_str(void);
+fb_util_get_locale(void);
/**
- * fb_util_randstr:
- * @size: The size of the string.
+ * fb_util_rand_alnum:
+ * @len: The length of the string.
*
- * Gets a random alphanumeric string. The returned string should be
- * freed with #g_free() when no longer needed.
+ * Gets a random alphanumeric (A-Za-z0-9) string. This function should
+ * *not* be relied on for cryptographic operations. The returned string
+ * should be freed with #g_free() when no longer needed.
*
- * Returns: The random string.
+ * Returns: The alphanumeric string.
*/
gchar *
-fb_util_randstr(gsize size);
+fb_util_rand_alnum(guint len);
/**
* fb_util_request_buddy:
@@ -295,52 +296,55 @@
guint64 timestamp);
/**
- * fb_util_str_is:
+ * fb_util_strtest:
* @str: The string.
* @type: The #GAsciiType.
*
- * Determines if @str abides to the #GAsciiType.
+ * Tests if the string only contains characters allowed by the
+ * #GAsciiType. More than one type can be specified by ORing the types
+ * together.
*
- * Returns: #TRUE if the string abides to @type, otherwise #FALSE.
+ * Returns: #TRUE if the string only contains characters allowed by the
+ * #GAsciiType, otherwise #FALSE.
*/
gboolean
-fb_util_str_is(const gchar *str, GAsciiType type);
+fb_util_strtest(const gchar *str, GAsciiType type);
/**
- * fb_util_zcompressed:
+ * fb_util_zlib_test:
* @bytes: The #GByteArray.
*
- * Determines if the #GByteArray is zlib compressed.
+ * Tests if the #GByteArray is zlib compressed.
*
* Returns: #TRUE if the #GByteArray is compressed, otherwise #FALSE.
*/
gboolean
-fb_util_zcompressed(const GByteArray *bytes);
+fb_util_zlib_test(const GByteArray *bytes);
/**
- * fb_util_zcompress:
+ * fb_util_zlib_deflate:
* @bytes: The #GByteArray.
* @error: The return location for the #GError or #NULL.
*
- * Compresses a #GByteArray with zlib. The returned #GByteArray should
- * be freed with #g_byte_array_free() when no longer needed.
+ * Deflates a #GByteArray with zlib. The returned #GByteArray should be
+ * freed with #g_byte_array_free() when no longer needed.
*
- * Returns: The compressed #GByteArray.
+ * Returns: The deflated #GByteArray or #NULL on error.
*/
GByteArray *
-fb_util_zcompress(const GByteArray *bytes, GError **error);
+fb_util_zlib_deflate(const GByteArray *bytes, GError **error);
/**
- * fb_util_zuncompress:
+ * fb_util_zlib_inflate:
* @bytes: The #GByteArray.
* @error: The return location for the #GError or #NULL.
*
- * Uncompresses a #GByteArray with zlib. The returned #GByteArray
- * should be freed with #g_byte_array_free() when no longer needed.
+ * Inflates a #GByteArray with zlib. The returned #GByteArray should be
+ * freed with #g_byte_array_free() when no longer needed.
*
- * Returns: The uncompressed #GByteArray or #NULL on error.
+ * Returns: The inflated #GByteArray or #NULL on error.
*/
GByteArray *
-fb_util_zuncompress(const GByteArray *bytes, GError **error);
+fb_util_zlib_inflate(const GByteArray *bytes, GError **error);
#endif /* _FACEBOOK_UTIL_H_ */