diff options
author | Alvaro Soliverez <alvaro.soliverez@collabora.co.uk> | 2012-03-14 19:29:54 -0300 |
---|---|---|
committer | Olli Salli <olli.salli@collabora.co.uk> | 2012-03-15 22:03:10 +0200 |
commit | 19539e3418641cd379e80a69d3243db5537e0dc3 (patch) | |
tree | b204e7e8d1838173e38e89dc79e4cb88655b6607 | |
parent | 5754bc81e3f94589d91820fe34975dfb63730f28 (diff) | |
download | telepathy-salut-19539e3418641cd379e80a69d3243db5537e0dc3.tar.gz |
Move plugin library-specific code from util.c into its own file, to
prevent dependency problems
As part of this, a new SalutPluginContactInterface had to be created to
access contact capabilities that were needed for the plugin utils.
Accessing SalutContact directly would bring most of salut core in, so a
GInterface is used, similar to what is done with SalutPluginConnection
-rw-r--r-- | plugins/test.c | 3 | ||||
-rw-r--r-- | salut/Makefile.am | 1 | ||||
-rw-r--r-- | salut/plugin-contact.h | 59 | ||||
-rw-r--r-- | salut/util.h | 3 | ||||
-rw-r--r-- | src/Makefile.am | 5 | ||||
-rw-r--r-- | src/contact.c | 23 | ||||
-rw-r--r-- | src/contact.h | 5 | ||||
-rw-r--r-- | src/plugin-contact.c | 57 | ||||
-rw-r--r-- | src/plugin-util.c | 102 | ||||
-rw-r--r-- | src/util.c | 68 |
10 files changed, 254 insertions, 72 deletions
diff --git a/plugins/test.c b/plugins/test.c index accd0312..9df8a61a 100644 --- a/plugins/test.c +++ b/plugins/test.c @@ -38,7 +38,8 @@ test_plugin_class_init (TestPluginClass *klass) static void initialize (SalutPlugin *plugin, - TpBaseConnectionManager *connection_manager) + TpBaseConnectionManager *connection_manager, + SalutCreateProtocolImpl callback) { DEBUG ("%p on connection manager %p", plugin, connection_manager); diff --git a/salut/Makefile.am b/salut/Makefile.am index 14653c1f..f9befdbe 100644 --- a/salut/Makefile.am +++ b/salut/Makefile.am @@ -6,6 +6,7 @@ salutincludedir = $(includedir)/telepathy-salut-0/salut salutinclude_HEADERS = \ plugin.h \ plugin-connection.h \ + plugin-contact.h \ protocol.h \ caps-channel-manager.h \ capabilities.h \ diff --git a/salut/plugin-contact.h b/salut/plugin-contact.h new file mode 100644 index 00000000..b9815bef --- /dev/null +++ b/salut/plugin-contact.h @@ -0,0 +1,59 @@ +/* + * plugin-contact.h — Connection API available to telepathy-salut plugins + * Copyright © 2012 Collabora Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef SALUT_PLUGIN_CONTACT_H +#define SALUT_PLUGIN_CONTACT_H + +#include <glib-object.h> + +#include <wocky/wocky.h> +#include <salut/capability-set.h> + +G_BEGIN_DECLS + +typedef struct _SalutPluginContact SalutPluginContact; +typedef struct _SalutPluginContactInterface SalutPluginContactInterface; + +#define SALUT_TYPE_PLUGIN_CONTACT (salut_plugin_contact_get_type ()) +#define SALUT_PLUGIN_CONTACT(o) \ + (G_TYPE_CHECK_INSTANCE_CAST ((o), SALUT_TYPE_PLUGIN_CONTACT, \ + SalutPluginContact)) +#define SALUT_IS_PLUGIN_CONTACT(o) \ + (G_TYPE_CHECK_INSTANCE_TYPE ((o), SALUT_TYPE_PLUGIN_CONTACT)) +#define SALUT_PLUGIN_CONTACT_GET_IFACE(o) \ + (G_TYPE_INSTANCE_GET_INTERFACE ((o), SALUT_TYPE_PLUGIN_CONTACT, \ + SalutPluginContactInterface)) + +GType salut_plugin_contact_get_type (void) G_GNUC_CONST; + +typedef GabbleCapabilitySet * (*SalutPluginContactGetCapsFunc) ( + SalutPluginContact *plugin_contact); + +struct _SalutPluginContactInterface +{ + GTypeInterface parent; + SalutPluginContactGetCapsFunc get_caps; +}; + +GabbleCapabilitySet *salut_plugin_contact_get_caps ( + SalutPluginContact *plugin_contact); + +G_END_DECLS + +#endif diff --git a/salut/util.h b/salut/util.h index 977e0b49..379658b1 100644 --- a/salut/util.h +++ b/salut/util.h @@ -1,5 +1,5 @@ /* - * util.h - Headers for Salut utility functions + * plugin-util.h - Headers for Salut plugins utility functions * Copyright (C) 2011 Collabora Ltd. * * This library is free software; you can redistribute it and/or @@ -21,7 +21,6 @@ #define SALUT_UTIL_H #include <wocky/wocky.h> -#include <wocky/wocky.h> void salut_send_ll_pep_event (WockySession *session, WockyStanza *stanza); diff --git a/src/Makefile.am b/src/Makefile.am index 43dd959a..d4ebb458 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -79,7 +79,6 @@ CORE_SOURCES = \ tubes-channel.c \ util.h \ util.c \ - $(top_srcdir)/salut/util.h \ protocol.c \ $(top_srcdir)/salut/protocol.h \ plugin-loader.c \ @@ -148,9 +147,13 @@ libsalut_plugins_la_LIBADD = \ libsalut_plugins_la_SOURCES = \ $(top_srcdir)/salut/plugin.h \ + plugin-util.c \ + $(top_srcdir)/salut/util.h \ plugin.c \ $(top_srcdir)/salut/plugin-connection.h \ plugin-connection.c \ + $(top_srcdir)/salut/plugin-contact.h \ + plugin-contact.c \ $(top_srcdir)/salut/capability-set.h \ capability-set.c \ debug.h \ diff --git a/src/contact.c b/src/contact.c index 004543a6..49059b8a 100644 --- a/src/contact.c +++ b/src/contact.c @@ -38,9 +38,15 @@ static void xep_0115_capabilities_iface_init (gpointer, gpointer); +static void +salut_plugin_contact_iface_init (SalutPluginContactInterface *iface, + gpointer iface_data); + G_DEFINE_TYPE_WITH_CODE (SalutContact, salut_contact, WOCKY_TYPE_LL_CONTACT, G_IMPLEMENT_INTERFACE (WOCKY_TYPE_XEP_0115_CAPABILITIES, xep_0115_capabilities_iface_init); + G_IMPLEMENT_INTERFACE (SALUT_TYPE_PLUGIN_CONTACT, + salut_plugin_contact_iface_init); ) /* properties */ @@ -907,3 +913,20 @@ xep_0115_capabilities_iface_init (gpointer g_iface, iface->get_data_forms = salut_contact_get_data_forms; } + +GabbleCapabilitySet * +salut_contact_get_capabilities (SalutPluginContact *plugin_contact) +{ + SalutContact *contact = SALUT_CONTACT (plugin_contact); + + g_return_val_if_fail (SALUT_IS_CONTACT (contact), NULL); + + return contact->caps; +} + +static void +salut_plugin_contact_iface_init (SalutPluginContactInterface *iface, + gpointer iface_data) +{ + iface->get_caps = salut_contact_get_capabilities; +} diff --git a/src/contact.h b/src/contact.h index b2be40b1..da99773f 100644 --- a/src/contact.h +++ b/src/contact.h @@ -27,6 +27,9 @@ #include <salut/capability-set.h> #include "presence.h" #include "connection.h" + +#include "salut/plugin-contact.h" + #ifdef ENABLE_OLPC #include "olpc-activity.h" #endif @@ -152,6 +155,8 @@ void salut_contact_set_capabilities (SalutContact *contact, const GabbleCapabilitySet *caps, const GPtrArray *data_forms); +GabbleCapabilitySet *salut_contact_get_capabilities (SalutPluginContact *plugin_contact); + #ifdef ENABLE_OLPC typedef void (*SalutContactOLPCActivityFunc) (SalutOlpcActivity *activity, gpointer user_data); diff --git a/src/plugin-contact.c b/src/plugin-contact.c new file mode 100644 index 00000000..76b90983 --- /dev/null +++ b/src/plugin-contact.c @@ -0,0 +1,57 @@ +/* + * plugin-contact.c — API for telepathy-salut plugins + * Copyright © 2012 Collabora Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "salut/plugin-contact.h" + +#include <glib-object.h> +#include <telepathy-glib/errors.h> +#include <debug.h> + +/** + * SECTION: salut-plugin-contact + * @title: SalutPluginContact + * @short_description: Object representing salut contact, implemented by + * Salut internals. + * + * This Object represents Salut Contact. + * + * Virtual methods in SalutPluginContactInterface interface are implemented + * by SalutContact object. And only Salut should implement this interface. + */ +G_DEFINE_INTERFACE (SalutPluginContact, + salut_plugin_contact, + G_TYPE_OBJECT); + +static void +salut_plugin_contact_default_init (SalutPluginContactInterface *iface) +{ +} + +GabbleCapabilitySet * +salut_plugin_contact_get_caps ( + SalutPluginContact *plugin_contact) +{ + SalutPluginContactInterface *iface = + SALUT_PLUGIN_CONTACT_GET_IFACE (plugin_contact); + + g_return_val_if_fail (iface != NULL, NULL); + g_return_val_if_fail (iface->get_caps != NULL, NULL); + + return iface->get_caps (plugin_contact); +} diff --git a/src/plugin-util.c b/src/plugin-util.c new file mode 100644 index 00000000..c22f1aa7 --- /dev/null +++ b/src/plugin-util.c @@ -0,0 +1,102 @@ +/* + * util.c - Code for Salut utility functions + * Copyright (C) 2006-2007 Collabora Ltd. + * Copyright (C) 2006-2007 Nokia Corporation + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include <salut/util.h> + +#include <stdlib.h> +#include <string.h> +#include <glib.h> +#include <glib-object.h> +#include <dbus/dbus-glib.h> +#include <telepathy-glib/util.h> + +#include <salut/capability-set.h> +#include <salut/plugin-contact.h> + +#ifdef HAVE_UUID +# include <uuid.h> +#endif + +static void +send_stanza_to_contact (WockyPorter *porter, + WockyContact *contact, + WockyStanza *stanza) +{ + WockyStanza *to_send = wocky_stanza_copy (stanza); + + wocky_stanza_set_to_contact (to_send, contact); + wocky_porter_send (porter, to_send); + g_object_unref (to_send); +} + +void +salut_send_ll_pep_event (WockySession *session, + WockyStanza *stanza) +{ + WockyContactFactory *contact_factory; + WockyPorter *porter; + WockyLLContact *self_contact; + GList *contacts, *l; + WockyNode *message, *event, *items; + const gchar *pep_node; + gchar *node; + + g_return_if_fail (WOCKY_IS_SESSION (session)); + g_return_if_fail (WOCKY_IS_STANZA (stanza)); + + message = wocky_stanza_get_top_node (stanza); + event = wocky_node_get_first_child (message); + items = wocky_node_get_first_child (event); + + pep_node = wocky_node_get_attribute (items, "node"); + + if (pep_node == NULL) + return; + + node = g_strdup_printf ("%s+notify", pep_node); + + contact_factory = wocky_session_get_contact_factory (session); + porter = wocky_session_get_porter (session); + + contacts = wocky_contact_factory_get_ll_contacts (contact_factory); + + for (l = contacts; l != NULL; l = l->next) + { + SalutPluginContact *contact; + + if (!SALUT_IS_PLUGIN_CONTACT (l->data)) + continue; + + contact = l->data; + + if (gabble_capability_set_has (salut_plugin_contact_get_caps(contact), node)) + send_stanza_to_contact (porter, WOCKY_CONTACT (contact), stanza); + } + + /* now send to self */ + self_contact = wocky_contact_factory_ensure_ll_contact (contact_factory, + wocky_porter_get_full_jid (porter)); + + send_stanza_to_contact (porter, WOCKY_CONTACT (self_contact), stanza); + + g_object_unref (self_contact); + g_list_free (contacts); + g_free (node); +} @@ -19,7 +19,6 @@ */ #include "util.h" -#include <salut/util.h> #include <stdlib.h> #include <string.h> @@ -322,70 +321,3 @@ salut_generate_id (void) last++, g_random_int ()); #endif } - -static void -send_stanza_to_contact (WockyPorter *porter, - WockyContact *contact, - WockyStanza *stanza) -{ - WockyStanza *to_send = wocky_stanza_copy (stanza); - - wocky_stanza_set_to_contact (to_send, contact); - wocky_porter_send (porter, to_send); - g_object_unref (to_send); -} - -void -salut_send_ll_pep_event (WockySession *session, - WockyStanza *stanza) -{ - WockyContactFactory *contact_factory; - WockyPorter *porter; - WockyLLContact *self_contact; - GList *contacts, *l; - WockyNode *message, *event, *items; - const gchar *pep_node; - gchar *node; - - g_return_if_fail (WOCKY_IS_SESSION (session)); - g_return_if_fail (WOCKY_IS_STANZA (stanza)); - - message = wocky_stanza_get_top_node (stanza); - event = wocky_node_get_first_child (message); - items = wocky_node_get_first_child (event); - - pep_node = wocky_node_get_attribute (items, "node"); - - if (pep_node == NULL) - return; - - node = g_strdup_printf ("%s+notify", pep_node); - - contact_factory = wocky_session_get_contact_factory (session); - porter = wocky_session_get_porter (session); - - contacts = wocky_contact_factory_get_ll_contacts (contact_factory); - - for (l = contacts; l != NULL; l = l->next) - { - SalutContact *contact; - - if (!SALUT_IS_CONTACT (l->data)) - continue; - - contact = l->data; - - if (gabble_capability_set_has (contact->caps, node)) - send_stanza_to_contact (porter, WOCKY_CONTACT (contact), stanza); - } - - /* now send to self */ - self_contact = wocky_contact_factory_ensure_ll_contact (contact_factory, - wocky_porter_get_full_jid (porter)); - - send_stanza_to_contact (porter, WOCKY_CONTACT (self_contact), stanza); - - g_object_unref (self_contact); - g_list_free (contacts); - g_free (node); -} |