/pidgin/main: 77536a48b4be: facebook: refactored util naming and...
James Geboski
jgeboski at gmail.com
Wed Dec 16 15:13:52 EST 2015
Changeset: 77536a48b4befe63e73cd92e6eedadd0a4422c27
Author: James Geboski <jgeboski at gmail.com>
Date: 2015-12-16 15:13 -0500
Branch: default
URL: https://hg.pidgin.im/pidgin/main/rev/77536a48b4be
Description:
facebook: refactored util naming and GTK-Doc
diffstat:
libpurple/protocols/facebook/api.c | 12 ++++----
libpurple/protocols/facebook/id.h | 2 +-
libpurple/protocols/facebook/util.c | 31 +++++++++-----------
libpurple/protocols/facebook/util.h | 54 +++++++++++++++++++-----------------
4 files changed, 50 insertions(+), 49 deletions(-)
diffs (280 lines):
diff --git a/libpurple/protocols/facebook/api.c b/libpurple/protocols/facebook/api.c
--- a/libpurple/protocols/facebook/api.c
+++ b/libpurple/protocols/facebook/api.c
@@ -717,7 +717,7 @@ fb_api_http_req(FbApi *api, const gchar
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_api_cb_mqtt_open(FbMqtt *mqtt, gpoint
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 @@ fb_api_cb_mqtt_publish(FbMqtt *mqtt, con
{"/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 @@ fb_api_rehash(FbApi *api)
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 @@ fb_api_publish(FbApi *api, const gchar *
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);
diff --git a/libpurple/protocols/facebook/id.h b/libpurple/protocols/facebook/id.h
--- a/libpurple/protocols/facebook/id.h
+++ b/libpurple/protocols/facebook/id.h
@@ -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:
diff --git a/libpurple/protocols/facebook/util.c b/libpurple/protocols/facebook/util.c
--- a/libpurple/protocols/facebook/util.c
+++ b/libpurple/protocols/facebook/util.c
@@ -244,7 +244,7 @@ fb_util_debug_hexdump(PurpleDebugLevel l
}
gchar *
-fb_util_locale_str(void)
+fb_util_get_locale(void)
{
const gchar * const *langs;
const gchar *lang;
@@ -272,7 +272,7 @@ fb_util_locale_str(void)
}
gchar *
-fb_util_randstr(gsize size)
+fb_util_rand_alnum(guint len)
{
gchar *ret;
GRand *rand;
@@ -285,19 +285,16 @@ 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, 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 @@ fb_util_serv_got_chat_in(PurpleConnectio
}
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 @@ fb_util_str_is(const gchar *str, GAsciiT
}
gboolean
-fb_util_zcompressed(const GByteArray *bytes)
+fb_util_zlib_test(const GByteArray *bytes)
{
guint8 b0;
guint8 b1;
@@ -503,7 +500,7 @@ fb_util_zcompressed(const GByteArray *by
}
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 @@ fb_util_zconv(GConverter *conv, const GB
}
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;
}
diff --git a/libpurple/protocols/facebook/util.h b/libpurple/protocols/facebook/util.h
--- a/libpurple/protocols/facebook/util.h
+++ b/libpurple/protocols/facebook/util.h
@@ -216,7 +216,7 @@ fb_util_debug_hexdump(PurpleDebugLevel l
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 @@ fb_util_debug_hexdump(PurpleDebugLevel l
* 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 @@ fb_util_serv_got_chat_in(PurpleConnectio
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_ */
More information about the Commits
mailing list