/soc/2015/jgeboski/facebook: 3f5570a17b15: facebook: initial imp...
James Geboski
jgeboski at gmail.com
Wed Jun 3 19:16:09 EDT 2015
Changeset: 3f5570a17b155ce22b6484cff017c90c81ecf366
Author: James Geboski <jgeboski at gmail.com>
Date: 2015-06-03 19:15 -0400
Branch: facebook
URL: https://hg.pidgin.im/soc/2015/jgeboski/facebook/rev/3f5570a17b15
Description:
facebook: initial import of bitlbee-facebook
This simply migrates the core functionality from bitlbee-facebook into
the libpurple plugin. This ports everything but group chats, which will
be ported in a subsequent patch.
diffstat:
.hgignore | 1 +
libpurple/protocols/facebook/Makefile.am | 33 +-
libpurple/protocols/facebook/Makefile.mingw | 25 +-
libpurple/protocols/facebook/api.c | 1457 ++++++++++++++++++++++++++
libpurple/protocols/facebook/api.h | 198 +++
libpurple/protocols/facebook/facebook.c | 390 ++++++-
libpurple/protocols/facebook/facebook.h | 2 +
libpurple/protocols/facebook/http.c | 151 ++
libpurple/protocols/facebook/http.h | 63 +
libpurple/protocols/facebook/id.h | 44 +
libpurple/protocols/facebook/json.c | 419 +++++++
libpurple/protocols/facebook/json.h | 119 ++
libpurple/protocols/facebook/marshaller.list | 5 +
libpurple/protocols/facebook/mqtt.c | 962 +++++++++++++++++
libpurple/protocols/facebook/mqtt.h | 234 ++++
libpurple/protocols/facebook/thrift.c | 931 ++++++++++++++++
libpurple/protocols/facebook/thrift.h | 197 +++
libpurple/protocols/facebook/util.c | 171 +++
libpurple/protocols/facebook/util.h | 39 +
19 files changed, 5425 insertions(+), 16 deletions(-)
diffs (truncated from 5655 to 300 lines):
diff --git a/.hgignore b/.hgignore
--- a/.hgignore
+++ b/.hgignore
@@ -83,6 +83,7 @@ libpurple/plugins/perl/common/Makefile.o
libpurple/plugins/perl/common/const-c.inc
libpurple/plugins/perl/common/const-xs.inc
libpurple/plugins/perl/common/lib
+libpurple/protocols/facebook/marshal.[ch]
libpurple/purple-client-bindings.[ch]
libpurple/purple-client-example
libpurple/purple.h$
diff --git a/libpurple/protocols/facebook/Makefile.am b/libpurple/protocols/facebook/Makefile.am
--- a/libpurple/protocols/facebook/Makefile.am
+++ b/libpurple/protocols/facebook/Makefile.am
@@ -1,11 +1,38 @@
EXTRA_DIST = \
- Makefile.mingw
+ Makefile.mingw \
+ marshaller.list
pkgdir = @PURPLE_PLUGINDIR@
FACEBOOKSOURCES = \
+ marshal.c \
+ marshal.h \
+ api.c \
+ api.h \
facebook.h \
- facebook.c
+ facebook.c \
+ http.c \
+ http.h \
+ id.h \
+ json.c \
+ json.h \
+ mqtt.c \
+ mqtt.h \
+ thrift.c \
+ thrift.h \
+ util.c \
+ util.h
+
+CLEANFILES = \
+ marshal.c \
+ marshal.h
+
+marshal.c: $(srcdir)/marshaller.list marshal.h
+ $(AM_V_GEN)echo "#include \"marshal.h\"" > $@
+ $(AM_V_at)$(GLIB_GENMARSHAL) --prefix=fb_marshal --body $(srcdir)/marshaller.list >> $@
+
+marshal.h: $(srcdir)/marshaller.list
+ $(AM_V_GEN)$(GLIB_GENMARSHAL) --prefix=fb_marshal --header $(srcdir)/marshaller.list > $@
AM_CFLAGS = $(st)
@@ -31,5 +58,7 @@ AM_CPPFLAGS = \
-I$(top_srcdir)/libpurple \
-I$(top_builddir)/libpurple \
$(GLIB_CFLAGS) \
+ $(JSON_CFLAGS) \
+ $(ZLIB_CFLAGS) \
$(GPLUGIN_CFLAGS) \
$(DEBUG_CFLAGS)
diff --git a/libpurple/protocols/facebook/Makefile.mingw b/libpurple/protocols/facebook/Makefile.mingw
--- a/libpurple/protocols/facebook/Makefile.mingw
+++ b/libpurple/protocols/facebook/Makefile.mingw
@@ -7,7 +7,7 @@
PIDGIN_TREE_TOP := ../../..
include $(PIDGIN_TREE_TOP)/libpurple/win32/global.mak
-TARGET = libnovell
+TARGET = libfacebook
TYPE = PLUGIN
# Static or Plugin...
@@ -27,18 +27,29 @@ INCLUDE_PATHS += -I. \
-I$(GTK_TOP)/include \
-I$(GTK_TOP)/include/glib-2.0 \
-I$(GTK_TOP)/lib/glib-2.0/include \
+ -I$(JSON_GLIB_TOP)/include/json-glib-1.0 \
-I$(PURPLE_TOP) \
-I$(PURPLE_TOP)/win32 \
+ -I$(GPLUGIN_TOP) \
-I$(PIDGIN_TREE_TOP)
LIB_PATHS += -L$(GTK_TOP)/lib \
+ -L$(JSON_GLIB_TOP)/lib \
+ -L$(GPLUGIN_TOP) \
-L$(PURPLE_TOP)
##
## SOURCES, OBJECTS
##
C_SRC = \
- facebook.c
+ api.c \
+ facebook.c \
+ http.c \
+ json.c \
+ marshal.c \
+ mqtt.c \
+ thrift.c \
+ util.c
OBJECTS = $(C_SRC:%.c=%.o)
@@ -50,6 +61,9 @@ LIBS = \
-lgobject-2.0 \
-lws2_32 \
-lintl \
+ -lgplugin \
+ -ljson-glib-1.0 \
+ -lz \
-lpurple
include $(PIDGIN_COMMON_RULES)
@@ -69,6 +83,13 @@ install: all $(DLL_INSTALL_DIR)
$(TARGET).dll: $(PURPLE_DLL).a $(OBJECTS)
$(CC) -shared $(OBJECTS) $(LIB_PATHS) $(LIBS) $(DLL_LD_FLAGS) -o $(TARGET).dll
+marshal.c: marshaller.list marshal.h
+ @echo "#include \"marshal.h\"" > $@
+ @$(GLIB_GENMARSHAL) --prefix=fb_marshal --body marshaller.list >> $@
+
+marshal.h: marshaller.list
+ @$(GLIB_GENMARSHAL) --prefix=fb_marshal --header marshaller.list > $@
+
##
## CLEAN RULES
##
diff --git a/libpurple/protocols/facebook/api.c b/libpurple/protocols/facebook/api.c
new file mode 100644
--- /dev/null
+++ b/libpurple/protocols/facebook/api.c
@@ -0,0 +1,1457 @@
+/* purple
+ *
+ * Purple is the legal property of its developers, whose names are too numerous
+ * to list here. Please refer to the COPYRIGHT file distributed with this
+ * source distribution.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
+ */
+
+#include <json-glib/json-glib.h>
+#include <stdarg.h>
+#include <string.h>
+
+#include "api.h"
+#include "http.h"
+#include "json.h"
+#include "marshal.h"
+#include "thrift.h"
+#include "util.h"
+
+enum
+{
+ PROP_0,
+
+ PROP_CID,
+ PROP_CUID,
+ PROP_MID,
+ PROP_STOKEN,
+ PROP_TOKEN,
+ PROP_UID,
+
+ PROP_N
+};
+
+struct _FbApiPrivate
+{
+ PurpleConnection *gc;
+ FbMqtt *mqtt;
+
+ FbId uid;
+ guint64 mid;
+ gchar *cid;
+ gchar *cuid;
+ gchar *stoken;
+ gchar *token;
+
+};
+
+G_DEFINE_TYPE(FbApi, fb_api, G_TYPE_OBJECT);
+
+static void
+fb_api_set_property(GObject *obj, guint prop, const GValue *val,
+ GParamSpec *pspec)
+{
+ FbApiPrivate *priv = FB_API(obj)->priv;
+
+ switch (prop) {
+ case PROP_CID:
+ g_free(priv->cid);
+ priv->cid = g_value_dup_string(val);
+ break;
+ case PROP_CUID:
+ g_free(priv->cuid);
+ priv->cuid = g_value_dup_string(val);
+ break;
+ case PROP_MID:
+ priv->mid = g_value_get_uint64(val);
+ break;
+ case PROP_STOKEN:
+ g_free(priv->stoken);
+ priv->stoken = g_value_dup_string(val);
+ break;
+ case PROP_TOKEN:
+ g_free(priv->token);
+ priv->token = g_value_dup_string(val);
+ break;
+ case PROP_UID:
+ priv->uid = g_value_get_int64(val);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop, pspec);
+ break;
+ }
+}
+
+static void
+fb_api_get_property(GObject *obj, guint prop, GValue *val, GParamSpec *pspec)
+{
+ FbApiPrivate *priv = FB_API(obj)->priv;
+
+ switch (prop) {
+ case PROP_CID:
+ g_value_set_string(val, priv->cid);
+ break;
+ case PROP_CUID:
+ g_value_set_string(val, priv->cuid);
+ break;
+ case PROP_MID:
+ g_value_set_uint64(val, priv->mid);
+ break;
+ case PROP_STOKEN:
+ g_value_set_string(val, priv->stoken);
+ break;
+ case PROP_TOKEN:
+ g_value_set_string(val, priv->token);
+ break;
+ case PROP_UID:
+ g_value_set_int64(val, priv->uid);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop, pspec);
+ break;
+ }
+}
+
+
+static void
+fb_api_dispose(GObject *obj)
+{
+ FbApiPrivate *priv = FB_API(obj)->priv;
+
+ if (G_LIKELY(priv->gc != NULL)) {
+ purple_http_conn_cancel_all(priv->gc);
+ }
+
+ if (G_UNLIKELY(priv->mqtt != NULL)) {
+ g_object_unref(priv->mqtt);
+ }
+
+ g_free(priv->cid);
+ g_free(priv->cuid);
+ g_free(priv->stoken);
+ g_free(priv->token);
+}
+
+static void
+fb_api_class_init(FbApiClass *klass)
+{
+ GObjectClass *gklass = G_OBJECT_CLASS(klass);
+ GParamSpec *props[PROP_N] = {NULL};
+
+ gklass->set_property = fb_api_set_property;
+ gklass->get_property = fb_api_get_property;
+ gklass->dispose = fb_api_dispose;
+ g_type_class_add_private(klass, sizeof (FbApiPrivate));
+
+ props[PROP_CID] = g_param_spec_string(
+ "cid",
+ "Client ID",
+ "Client identifier for MQTT",
+ NULL,
More information about the Commits
mailing list