pidgin/pidgin

Merged in default (pull request #675)

2020-04-24, Gary Kramlich
0dc2bdba54d2
Merged in default (pull request #675)

Pull PurpleProtocolFactory out to it's own file.

Approved-by: Elliott Sales de Andrade
Approved-by: John Bailey
--- a/doc/reference/libpurple/libpurple-docs.xml Fri Apr 10 02:39:50 2020 +0000
+++ b/doc/reference/libpurple/libpurple-docs.xml Fri Apr 24 01:58:16 2020 +0000
@@ -66,6 +66,7 @@
<xi:include href="xml/purple-gio.xml" />
<xi:include href="xml/purpleaccountoption.xml" />
<xi:include href="xml/purpleaccountusersplit.xml" />
+ <xi:include href="xml/purpleprotocolfactory.xml" />
<xi:include href="xml/purpleuiinfo.xml" />
<xi:include href="xml/queuedoutputstream.xml" />
<xi:include href="xml/signals.xml" />
--- a/libpurple/connection.c Fri Apr 10 02:39:50 2020 +0000
+++ b/libpurple/connection.c Fri Apr 24 01:58:16 2020 +0000
@@ -30,6 +30,7 @@
#include "notify.h"
#include "prefs.h"
#include "proxy.h"
+#include "purpleprotocolfactory.h"
#include "request.h"
#include "server.h"
#include "signals.h"
@@ -986,15 +987,16 @@
}
}
- if (PURPLE_PROTOCOL_IMPLEMENTS(protocol, FACTORY, connection_new))
- gc = purple_protocol_factory_iface_connection_new(protocol, account,
- password);
- else
+ if(PURPLE_IS_PROTOCOL_FACTORY(protocol)) {
+ gc = purple_protocol_factory_connection_new(
+ PURPLE_PROTOCOL_FACTORY(protocol), account, password);
+ } else {
gc = g_object_new(PURPLE_TYPE_CONNECTION,
"protocol", protocol,
"account", account,
"password", password,
NULL);
+ }
g_return_if_fail(gc != NULL);
@@ -1055,15 +1057,16 @@
return;
}
- if (PURPLE_PROTOCOL_IMPLEMENTS(protocol, FACTORY, connection_new))
- gc = purple_protocol_factory_iface_connection_new(protocol, account,
- password);
- else
+ if(PURPLE_IS_PROTOCOL_FACTORY(protocol)) {
+ gc = purple_protocol_factory_connection_new(
+ PURPLE_PROTOCOL_FACTORY(protocol), account, password);
+ } else {
gc = g_object_new(PURPLE_TYPE_CONNECTION,
"protocol", protocol,
"account", account,
"password", password,
NULL);
+ }
g_return_if_fail(gc != NULL);
--- a/libpurple/meson.build Fri Apr 10 02:39:50 2020 +0000
+++ b/libpurple/meson.build Fri Apr 24 01:58:16 2020 +0000
@@ -48,6 +48,7 @@
'purple-gio.c',
'purpleaccountoption.c',
'purpleaccountusersplit.c',
+ 'purpleprotocolfactory.c',
'purpleuiinfo.c',
'queuedoutputstream.c',
'request.c',
@@ -125,6 +126,7 @@
'purple-gio.h',
'purpleaccountoption.h',
'purpleaccountusersplit.h',
+ 'purpleprotocolfactory.h',
'purpleuiinfo.h',
'queuedoutputstream.h',
'request.h',
--- a/libpurple/protocol.c Fri Apr 10 02:39:50 2020 +0000
+++ b/libpurple/protocol.c Fri Apr 24 01:58:16 2020 +0000
@@ -817,62 +817,3 @@
#undef DEFINE_PROTOCOL_FUNC_WITH_RETURN
#undef DEFINE_PROTOCOL_FUNC
-
-/**************************************************************************
- * Protocol Factory Interface API
- **************************************************************************/
-#define DEFINE_PROTOCOL_FUNC(protocol,funcname,...) \
- PurpleProtocolFactoryInterface *factory_iface = \
- PURPLE_PROTOCOL_FACTORY_GET_IFACE(protocol); \
- if (factory_iface && factory_iface->funcname) \
- factory_iface->funcname(__VA_ARGS__);
-
-#define DEFINE_PROTOCOL_FUNC_WITH_RETURN(protocol,defaultreturn,funcname,...) \
- PurpleProtocolFactoryInterface *factory_iface = \
- PURPLE_PROTOCOL_FACTORY_GET_IFACE(protocol); \
- if (factory_iface && factory_iface->funcname) \
- return factory_iface->funcname(__VA_ARGS__); \
- else \
- return defaultreturn;
-
-GType
-purple_protocol_factory_iface_get_type(void)
-{
- static GType type = 0;
-
- if (G_UNLIKELY(type == 0)) {
- static const GTypeInfo info = {
- .class_size = sizeof(PurpleProtocolFactoryInterface),
- };
-
- type = g_type_register_static(G_TYPE_INTERFACE,
- "PurpleProtocolFactoryInterface", &info, 0);
- }
- return type;
-}
-
-PurpleConnection *
-purple_protocol_factory_iface_connection_new(PurpleProtocol *protocol,
- PurpleAccount *account, const char *password)
-{
- DEFINE_PROTOCOL_FUNC_WITH_RETURN(protocol, NULL, connection_new, protocol,
- account, password);
-}
-
-PurpleRoomlist *
-purple_protocol_factory_iface_roomlist_new(PurpleProtocol *protocol,
- PurpleAccount *account)
-{
- DEFINE_PROTOCOL_FUNC_WITH_RETURN(protocol, NULL, roomlist_new, account);
-}
-
-PurpleWhiteboard *
-purple_protocol_factory_iface_whiteboard_new(PurpleProtocol *protocol,
- PurpleAccount *account, const char *who, int state)
-{
- DEFINE_PROTOCOL_FUNC_WITH_RETURN(protocol, NULL, whiteboard_new, account,
- who, state);
-}
-
-#undef DEFINE_PROTOCOL_FUNC_WITH_RETURN
-#undef DEFINE_PROTOCOL_FUNC
--- a/libpurple/protocol.h Fri Apr 10 02:39:50 2020 +0000
+++ b/libpurple/protocol.h Fri Apr 24 01:58:16 2020 +0000
@@ -594,44 +594,6 @@
#define PURPLE_PROTOCOL_MEDIA_GET_IFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE((obj), PURPLE_TYPE_PROTOCOL_MEDIA, \
PurpleProtocolMediaInterface))
-#define PURPLE_TYPE_PROTOCOL_FACTORY (purple_protocol_factory_iface_get_type())
-
-typedef struct _PurpleProtocolFactoryInterface PurpleProtocolFactoryInterface;
-
-/**
- * PurpleProtocolFactoryInterface:
- * @connection_new: Creates a new protocol-specific connection object that
- * inherits #PurpleConnection.
- * @roomlist_new: Creates a new protocol-specific room list object that
- * inherits #PurpleRoomlist.
- * @whiteboard_new: Creates a new protocol-specific whiteboard object that
- * inherits #PurpleWhiteboard.
- *
- * The protocol factory interface.
- *
- * This interface provides callbacks for construction of protocol-specific
- * subclasses of some purple objects.
- */
-struct _PurpleProtocolFactoryInterface
-{
- /*< private >*/
- GTypeInterface parent_iface;
-
- /*< public >*/
- PurpleConnection *(*connection_new)(PurpleProtocol *protocol,
- PurpleAccount *account,
- const char *password);
-
- PurpleRoomlist *(*roomlist_new)(PurpleAccount *account);
-
- PurpleWhiteboard *(*whiteboard_new)(PurpleAccount *account,
- const char *who, int state);
-};
-
-#define PURPLE_IS_PROTOCOL_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), PURPLE_TYPE_PROTOCOL_FACTORY))
-#define PURPLE_PROTOCOL_FACTORY_GET_IFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE((obj), PURPLE_TYPE_PROTOCOL_FACTORY, \
- PurpleProtocolFactoryInterface))
-
/**
* PURPLE_PROTOCOL_IMPLEMENTS:
* @protocol: The protocol in which to check
@@ -1259,35 +1221,6 @@
gboolean purple_protocol_media_iface_send_dtmf(PurpleProtocol *protocol,
PurpleMedia *media, gchar dtmf, guint8 volume, guint8 duration);
-/**************************************************************************/
-/* Protocol Factory Interface API */
-/**************************************************************************/
-
-/**
- * purple_protocol_factory_iface_get_type:
- *
- * Returns: The #GType for the protocol factory interface.
- */
-GType purple_protocol_factory_iface_get_type(void);
-
-/**
- * purple_protocol_factory_iface_connection_new: (skip)
- */
-PurpleConnection *purple_protocol_factory_iface_connection_new(PurpleProtocol *protocol,
- PurpleAccount *account, const char *password);
-
-/**
- * purple_protocol_factory_iface_roomlist_new: (skip)
- */
-PurpleRoomlist *purple_protocol_factory_iface_roomlist_new(PurpleProtocol *protocol,
- PurpleAccount *account);
-
-/**
- * purple_protocol_factory_iface_whiteboard_new: (skip)
- */
-PurpleWhiteboard *purple_protocol_factory_iface_whiteboard_new(PurpleProtocol *protocol,
- PurpleAccount *account, const char *who, int state);
-
G_END_DECLS
#endif /* PURPLE_PROTOCOL_H */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/libpurple/purpleprotocolfactory.c Fri Apr 24 01:58:16 2020 +0000
@@ -0,0 +1,90 @@
+/*
+ * 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 "purpleprotocolfactory.h"
+
+G_DEFINE_INTERFACE(PurpleProtocolFactory, purple_protocol_factory, G_TYPE_INVALID);
+
+/******************************************************************************
+ * GInterface Implementation
+ *****************************************************************************/
+static void
+purple_protocol_factory_default_init(PurpleProtocolFactoryInterface *iface) {
+}
+
+/******************************************************************************
+ * Public API
+ *****************************************************************************/
+PurpleConnection *
+purple_protocol_factory_connection_new(PurpleProtocolFactory *factory,
+ PurpleAccount *account,
+ const gchar *password)
+{
+ PurpleProtocolFactoryInterface *iface = NULL;
+
+ g_return_val_if_fail(PURPLE_IS_PROTOCOL_FACTORY(factory), NULL);
+ g_return_val_if_fail(PURPLE_IS_ACCOUNT(account), NULL);
+
+ iface = PURPLE_PROTOCOL_FACTORY_GET_IFACE(factory);
+ if(iface && iface->connection_new) {
+ return iface->connection_new(factory, account, password);
+ }
+
+ return NULL;
+}
+
+PurpleRoomlist *
+purple_protocol_factory_roomlist_new(PurpleProtocolFactory *factory,
+ PurpleAccount *account)
+{
+ PurpleProtocolFactoryInterface *iface = NULL;
+
+ g_return_val_if_fail(PURPLE_IS_PROTOCOL_FACTORY(factory), NULL);
+ g_return_val_if_fail(PURPLE_IS_ACCOUNT(account), NULL);
+
+ iface = PURPLE_PROTOCOL_FACTORY_GET_IFACE(factory);
+ if(iface && iface->roomlist_new) {
+ return iface->roomlist_new(factory, account);
+ }
+
+ return NULL;
+}
+
+PurpleWhiteboard *
+purple_protocol_factory_whiteboard_new(PurpleProtocolFactory *factory,
+ PurpleAccount *account,
+ const gchar *who,
+ gint state)
+{
+ PurpleProtocolFactoryInterface *iface = NULL;
+
+ g_return_val_if_fail(PURPLE_IS_PROTOCOL_FACTORY(factory), NULL);
+ g_return_val_if_fail(PURPLE_IS_ACCOUNT(account), NULL);
+ g_return_val_if_fail(who, NULL);
+
+ iface = PURPLE_PROTOCOL_FACTORY_GET_IFACE(factory);
+ if(iface && iface->whiteboard_new) {
+ return iface->whiteboard_new(factory, account, who, state);
+ }
+
+ return NULL;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/libpurple/purpleprotocolfactory.h Fri Apr 24 01:58:16 2020 +0000
@@ -0,0 +1,145 @@
+/*
+ * 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
+ */
+
+#ifndef PURPLE_PROTOCOL_FACTORY_H
+#define PURPLE_PROTOCOL_FACTORY_H
+
+/**
+ * SECTION:protocol-factory
+ * @section_id: purple-protocol-factory
+ * @title: ProtocolFactoryInterface
+ * @short_description: <filename>purpleprotocolfactory.h</filename>
+ *
+ * A interface where protocols can expose subclasses of libpurple objects.
+ */
+
+#include <glib.h>
+#include <glib-object.h>
+
+#include <libpurple/account.h>
+#include <libpurple/connection.h>
+#include <libpurple/protocol.h>
+
+G_BEGIN_DECLS
+
+#define PURPLE_TYPE_PROTOCOL_FACTORY (purple_protocol_factory_iface_get_type())
+G_DECLARE_INTERFACE(PurpleProtocolFactory, purple_protocol_factory, PURPLE,
+ PROTOCOL_FACTORY, GObject)
+
+/**
+ * PurpleProtocolFactory:
+ *
+ * #PurpleProtocolFactory is an opaque representation of an object that
+ * implements #PurpleProtocolFactoryInterface.
+ */
+
+/**
+ * PurpleProtocolFactoryInterface:
+ * @connection_new: Creates a new protocol-specific connection object that
+ * subclasses #PurpleConnection.
+ * @roomlist_new: Creates a new protocol-specific room list object that
+ * subclasses #PurpleRoomlist.
+ * @whiteboard_new: Creates a new protocol-specific whiteboard object that
+ * subclasses #PurpleWhiteboard.
+ *
+ * The protocol factory interface.
+ *
+ * This interface provides callbacks for construction of protocol-specific
+ * subclasses of some purple objects.
+ */
+struct _PurpleProtocolFactoryInterface {
+ /*< private >*/
+ GTypeInterface parent_iface;
+
+ /*< public >*/
+ PurpleConnection *(*connection_new)(PurpleProtocolFactory *factory,
+ PurpleAccount *account,
+ const gchar *password);
+
+ PurpleRoomlist *(*roomlist_new)(PurpleProtocolFactory *factory,
+ PurpleAccount *account);
+
+ PurpleWhiteboard *(*whiteboard_new)(PurpleProtocolFactory *factory,
+ PurpleAccount *account,
+ const gchar *who,
+ gint state);
+};
+
+/**
+ * purple_protocol_factory_get_type:
+ *
+ * The standard `_get_type` function for #PurpleProtocolFactory.
+ *
+ * Returns: The #GType for the protocol factory interface.
+ *
+ * Since: 3.0.0
+ */
+
+/**
+ * purple_protocol_factory_connection_new:
+ * @factory: The #PurpleProtocolFactory instance.
+ * @account: The #PurpleAccount to create the connection for.
+ * @password: The password for @account.
+ *
+ * Creates a new protocol-specific #PurpleConnection subclass.
+ *
+ * Returns: (transfer full): The new #PurpleConnection subclass.
+ *
+ * Since: 3.0.0
+ */
+PurpleConnection *purple_protocol_factory_connection_new(PurpleProtocolFactory *factory,
+ PurpleAccount *account, const gchar *password);
+
+/**
+ * purple_protocol_factory_roomlist_new:
+ * @factory: The #PurpleProtocolFactory instance.
+ * @account: The #PurpleAccount to create a roomlist for.
+ *
+ * Creates a new protocol-specific #PurpleRoomlist subclass.
+ *
+ * Returns: (transfer full): The new #PurpleRoomlist subclass for @account.
+ *
+ * Since: 3.0.0
+ */
+PurpleRoomlist *purple_protocol_factory_roomlist_new(PurpleProtocolFactory *factory,
+ PurpleAccount *account);
+
+/**
+ * purple_protocol_factory_whiteboard_new:
+ * @factory: The #PurpleProtocolFactory instance.
+ * @account: The #PurpleAccount instance to create a whiteboard for.
+ * @who: The name of the contact to create a whiteboard with.
+ * @state: NFI.
+ *
+ * Creates a new protocol-specific #PurpleWhiteboard subclass.
+ *
+ * Returns: (transfer full): The new #PurpleWhiteboard subclass for @account
+ * and @who.
+ *
+ * Since: 3.0.0
+ */
+PurpleWhiteboard *purple_protocol_factory_whiteboard_new(PurpleProtocolFactory *factory,
+ PurpleAccount *account, const gchar *who, gint state);
+
+G_END_DECLS
+
+#endif /* PURPLE_PROTOCOL_FACTORY_H */
--- a/libpurple/roomlist.c Fri Apr 10 02:39:50 2020 +0000
+++ b/libpurple/roomlist.c Fri Apr 24 01:58:16 2020 +0000
@@ -24,6 +24,7 @@
#include "account.h"
#include "connection.h"
#include "debug.h"
+#include "purpleprotocolfactory.h"
#include "roomlist.h"
#include "server.h"
@@ -393,13 +394,16 @@
g_return_val_if_fail(PURPLE_IS_PROTOCOL(protocol), NULL);
- if (PURPLE_PROTOCOL_IMPLEMENTS(protocol, FACTORY, roomlist_new))
- list = purple_protocol_factory_iface_roomlist_new(protocol, account);
- else
+ if(PURPLE_IS_PROTOCOL_FACTORY(protocol)) {
+ list = purple_protocol_factory_roomlist_new(
+ PURPLE_PROTOCOL_FACTORY(protocol), account);
+ }
+ else {
list = g_object_new(PURPLE_TYPE_ROOMLIST,
"account", account,
NULL
);
+ }
g_return_val_if_fail(list != NULL, NULL);
--- a/libpurple/whiteboard.c Fri Apr 10 02:39:50 2020 +0000
+++ b/libpurple/whiteboard.c Fri Apr 24 01:58:16 2020 +0000
@@ -23,6 +23,7 @@
#include "internal.h"
#include "whiteboard.h"
+#include "purpleprotocolfactory.h"
#include "protocol.h"
typedef struct _PurpleWhiteboardPrivate PurpleWhiteboardPrivate;
@@ -518,16 +519,17 @@
g_return_val_if_fail(PURPLE_IS_PROTOCOL(protocol), NULL);
- if (PURPLE_PROTOCOL_IMPLEMENTS(protocol, FACTORY, whiteboard_new))
- wb = purple_protocol_factory_iface_whiteboard_new(protocol, account,
- who, state);
- else
+ if(PURPLE_IS_PROTOCOL_FACTORY(protocol)) {
+ wb = purple_protocol_factory_whiteboard_new(
+ PURPLE_PROTOCOL_FACTORY(protocol), account, who, state);
+ } else {
wb = g_object_new(PURPLE_TYPE_WHITEBOARD,
"account", account,
"who", who,
"state", state,
NULL
);
+ }
g_return_val_if_fail(wb != NULL, NULL);