/soc/2015/jgeboski/facebook: 9cd963f45997: facebook: removed bin...

James Geboski <[email protected]>
Newsgroups gmane.comp.gnome.gaim.cvs
Message-ID <[email protected]>
Changeset: 9cd963f45997b368332db5766e65db781336ab49
Author:	 James Geboski <[email protected]>
Date:	 2015-08-09 19:43 -0400
Branch:	 facebook
URL: https://hg.pidgin.im/soc/2015/jgeboski/facebook/rev/9cd963f45997

Description:

facebook: removed binary thrift support

Facebook only uses compact thrift, rather than the binary thrift.

diffstat:

 libpurple/protocols/facebook/api.c    |   20 +-
 libpurple/protocols/facebook/thrift.c |  455 ++++++---------------------------
 libpurple/protocols/facebook/thrift.h |   49 +--
 3 files changed, 119 insertions(+), 405 deletions(-)

diffs (truncated from 1027 to 300 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
@@ -588,7 +588,7 @@ fb_api_cb_mqtt_open(FbMqtt *mqtt, gpoint
 	                      FB_MQTT_CONNECT_FLAG_PASS |
 	                      FB_MQTT_CONNECT_FLAG_CLR;
 
-	thft = fb_thrift_new(NULL, 0, TRUE);
+	thft = fb_thrift_new(NULL, 0);
 
 	/* Write the client identifier */
 	fb_thrift_write_field(thft, FB_THRIFT_TYPE_STRING, 1);
@@ -819,7 +819,7 @@ fb_api_cb_mqtt_connect(FbMqtt *mqtt, gpo
 }
 
 static void
-fb_api_cb_publish_mark(FbApi *api, const GByteArray *pload)
+fb_api_cb_publish_mark(FbApi *api, GByteArray *pload)
 {
 	FbJsonValues *values;
 	GError *err = NULL;
@@ -849,7 +849,7 @@ fb_api_cb_publish_mark(FbApi *api, const
 }
 
 static void
-fb_api_cb_publish_typing(FbApi *api, const GByteArray *pload)
+fb_api_cb_publish_typing(FbApi *api, GByteArray *pload)
 {
 	const gchar *str;
 	FbApiPrivate *priv = api->priv;
@@ -1007,7 +1007,7 @@ fb_api_message_parse_attach(FbApi *api, 
 }
 
 static void
-fb_api_cb_publish_ms(FbApi *api, const GByteArray *pload)
+fb_api_cb_publish_ms(FbApi *api, GByteArray *pload)
 {
 	const gchar *body;
 	const gchar *data;
@@ -1029,7 +1029,7 @@ fb_api_cb_publish_ms(FbApi *api, const G
 	JsonNode *root;
 	JsonNode *node;
 
-	thft = fb_thrift_new((GByteArray*) pload, 0, TRUE);
+	thft = fb_thrift_new(pload, 0);
 	fb_thrift_read_str(thft, NULL);
 	size = fb_thrift_get_pos(thft);
 	g_object_unref(thft);
@@ -1157,7 +1157,7 @@ fb_api_cb_publish_ms(FbApi *api, const G
 }
 
 static void
-fb_api_cb_publish_p(FbApi *api, const GByteArray *pload)
+fb_api_cb_publish_p(FbApi *api, GByteArray *pload)
 {
 	FbApiPresence pres;
 	FbThrift *thft;
@@ -1170,7 +1170,7 @@ fb_api_cb_publish_p(FbApi *api, const GB
 	guint size;
 
 	/* Start at 1 to skip the NULL byte */
-	thft  = fb_thrift_new((GByteArray*) pload, 1, TRUE);
+	thft  = fb_thrift_new(pload, 1);
 	press = NULL;
 
 	/* Skip the full list boolean field */
@@ -1243,8 +1243,8 @@ fb_api_cb_publish_p(FbApi *api, const GB
 }
 
 static void
-fb_api_cb_mqtt_publish(FbMqtt *mqtt, const gchar *topic,
-                       const GByteArray *pload, gpointer data)
+fb_api_cb_mqtt_publish(FbMqtt *mqtt, const gchar *topic, GByteArray *pload,
+                       gpointer data)
 {
 	FbApi *api = data;
 	gboolean comp;
@@ -1253,7 +1253,7 @@ fb_api_cb_mqtt_publish(FbMqtt *mqtt, con
 
 	static const struct {
 		const gchar *topic;
-		void (*func) (FbApi *api, const GByteArray *pload);
+		void (*func) (FbApi *api, GByteArray *pload);
 	} parsers[] = {
 		{"/mark_thread_response", fb_api_cb_publish_mark},
 		{"/orca_typing_notifications", fb_api_cb_publish_typing},
diff --git a/libpurple/protocols/facebook/thrift.c b/libpurple/protocols/facebook/thrift.c
--- a/libpurple/protocols/facebook/thrift.c
+++ b/libpurple/protocols/facebook/thrift.c
@@ -25,8 +25,8 @@
 
 struct _FbThriftPrivate
 {
-	FbThriftFlags flags;
 	GByteArray *bytes;
+	gboolean internal;
 	guint offset;
 	guint pos;
 	guint lastbool;
@@ -40,7 +40,7 @@ fb_thrift_dispose(GObject *obj)
 {
 	FbThriftPrivate *priv = FB_THRIFT(obj)->priv;
 
-	if (priv->flags & FB_THRIFT_FLAG_INTERNAL) {
+	if (priv->internal) {
 		g_byte_array_free(priv->bytes, TRUE);
 	}
 }
@@ -65,7 +65,7 @@ fb_thrift_init(FbThrift *thft)
 }
 
 FbThrift *
-fb_thrift_new(GByteArray *bytes, guint offset, gboolean compact)
+fb_thrift_new(GByteArray *bytes, guint offset)
 {
 	FbThrift *thft;
 	FbThriftPrivate *priv;
@@ -74,18 +74,14 @@ fb_thrift_new(GByteArray *bytes, guint o
 	priv = thft->priv;
 
 	if (bytes != NULL) {
-		priv->bytes  = bytes;
+		priv->bytes = bytes;
 		priv->offset = offset;
+		priv->pos = offset;
 	} else {
-		priv->bytes  = g_byte_array_new();
-		priv->flags |= FB_THRIFT_FLAG_INTERNAL;
+		priv->bytes = g_byte_array_new();
+		priv->internal = TRUE;
 	}
 
-	if (compact) {
-		priv->flags |= FB_THRIFT_FLAG_COMPACT;
-	}
-
-	priv->pos = priv->offset;
 	return thft;
 }
 
@@ -150,7 +146,7 @@ fb_thrift_read(FbThrift *thft, gpointer 
 }
 
 gboolean
-fb_thrift_read_bool(FbThrift *thft, gboolean *bln)
+fb_thrift_read_bool(FbThrift *thft, gboolean *value)
 {
 	FbThriftPrivate *priv;
 	guint8 byte;
@@ -158,36 +154,21 @@ fb_thrift_read_bool(FbThrift *thft, gboo
 	g_return_val_if_fail(FB_IS_THRIFT(thft), FALSE);
 	priv = thft->priv;
 
-	if (bln != NULL) {
-		*bln = FALSE;
-	}
-
-	if (!(priv->flags & FB_THRIFT_FLAG_COMPACT)) {
-		if (!fb_thrift_read_byte(thft, &byte)) {
-			return FALSE;
-		}
-
-		if (bln != NULL) {
-			*bln = byte != 0;
-		}
-
-		return TRUE;
-	}
-
 	if ((priv->lastbool & 0x03) != 0x01) {
 		if (!fb_thrift_read_byte(thft, &byte)) {
 			return FALSE;
 		}
 
-		if (bln != NULL) {
-			*bln = (byte & 0x0F) == 0x01;
+		if (value != NULL) {
+			*value = (byte & 0x0F) == 0x01;
 		}
 
+		priv->lastbool = 0;
 		return TRUE;
 	}
 
-	if (bln != NULL) {
-		*bln = ((priv->lastbool & 0x04) >> 2) != 0;
+	if (value != NULL) {
+		*value = ((priv->lastbool & 0x04) >> 2) != 0;
 	}
 
 	priv->lastbool = 0;
@@ -195,250 +176,145 @@ fb_thrift_read_bool(FbThrift *thft, gboo
 }
 
 gboolean
-fb_thrift_read_byte(FbThrift *thft, guint8 *byte)
+fb_thrift_read_byte(FbThrift *thft, guint8 *value)
 {
-	if (byte != NULL) {
-		*byte = 0;
-	}
-
-	return fb_thrift_read(thft, byte, sizeof *byte);
+	return fb_thrift_read(thft, value, sizeof *value);
 }
 
 gboolean
-fb_thrift_read_dbl(FbThrift *thft, gdouble *dbl)
+fb_thrift_read_dbl(FbThrift *thft, gdouble *value)
 {
 	gint64 i64;
 
 	/* Almost always 8, but check anyways */
-	static const gsize size = MIN(sizeof dbl, sizeof i64);
-
-	if (dbl != NULL) {
-		*dbl = 0;
-	}
+	static const gsize size = MIN(sizeof value, sizeof i64);
 
 	if (!fb_thrift_read_i64(thft, &i64)) {
 		return FALSE;
 	}
 
-	if (dbl != NULL) {
-		memcpy(&dbl, &i64, size);
+	if (value != NULL) {
+		memcpy(value, &i64, size);
 	}
 
 	return TRUE;
 }
 
 gboolean
-fb_thrift_read_i16(FbThrift *thft, gint16 *i16)
+fb_thrift_read_i16(FbThrift *thft, gint16 *value)
 {
-	FbThriftPrivate *priv;
 	gint64 i64;
 
-	g_return_val_if_fail(FB_IS_THRIFT(thft), FALSE);
-	priv = thft->priv;
-
-	if (i16 != NULL) {
-		*i16 = 0;
-	}
-
-	if (!(priv->flags & FB_THRIFT_FLAG_COMPACT)) {
-		if (!fb_thrift_read(thft, i16, sizeof *i16)) {
-			return FALSE;
-		}
-
-		if (i16 != NULL) {
-			*i16 = GINT16_FROM_BE(*i16);
-		}
-
-		return TRUE;
-	}
-
 	if (!fb_thrift_read_i64(thft, &i64)) {
 		return FALSE;
 	}
 
-	if (i16 != NULL) {
-		*i16 = i64;
+	if (value != NULL) {
+		*value = i64;
 	}
 
 	return TRUE;
 }
 
 gboolean
-fb_thrift_read_vi16(FbThrift *thft, guint16 *u16)
+fb_thrift_read_vi16(FbThrift *thft, guint16 *value)
 {
 	guint64 u64;
 
-	if (u16 != NULL) {
-		*u16 = 0;
-	}
-
 	if (!fb_thrift_read_vi64(thft, &u64)) {
 		return FALSE;
 	}
 
-	if (u16 != NULL) {
-		*u16 = u64;
+	if (value != NULL) {
+		*value = u64;
 	}
 
 	return TRUE;
 }
 
 gboolean
-fb_thrift_read_i32(FbThrift *thft, gint32 *i32)
+fb_thrift_read_i32(FbThrift *thft, gint32 *value)
 {
-	FbThriftPrivate *priv;

_______________________________________________
Commits mailing list
[email protected]
https://pidgin.im/cgi-bin/mailman/listinfo/commits
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.