diff options
author | Jonny Lamb <jonny.lamb@collabora.co.uk> | 2011-03-02 15:34:16 +0000 |
---|---|---|
committer | Jonny Lamb <jonny.lamb@collabora.co.uk> | 2011-03-02 15:34:16 +0000 |
commit | e4bd1f21c86cbd949f70a911f6dc8dfd795e1baa (patch) | |
tree | 16635a3357f723f17d7fa939d46c1e866dc45901 /lib/gibber | |
parent | dbd43829b8370a7fb2b5120594b3e30752452a55 (diff) | |
download | telepathy-salut-e4bd1f21c86cbd949f70a911f6dc8dfd795e1baa.tar.gz |
gibber-iq-helper: removed
Signed-off-by: Jonny Lamb <jonny.lamb@collabora.co.uk>
Diffstat (limited to 'lib/gibber')
-rw-r--r-- | lib/gibber/Makefile.am | 2 | ||||
-rw-r--r-- | lib/gibber/gibber-bytestream-oob.c | 1 | ||||
-rw-r--r-- | lib/gibber/gibber-iq-helper.c | 403 | ||||
-rw-r--r-- | lib/gibber/gibber-iq-helper.h | 87 | ||||
-rw-r--r-- | lib/gibber/tests/Makefile.am | 1 | ||||
-rw-r--r-- | lib/gibber/tests/check-gibber-iq-helper.c | 439 |
6 files changed, 0 insertions, 933 deletions
diff --git a/lib/gibber/Makefile.am b/lib/gibber/Makefile.am index 75c27dd0..2b93f407 100644 --- a/lib/gibber/Makefile.am +++ b/lib/gibber/Makefile.am @@ -52,8 +52,6 @@ HANDWRITTEN_SOURCES = \ gibber-linklocal-transport.c \ gibber-linklocal-transport.h \ gibber-namespaces.h \ - gibber-iq-helper.c \ - gibber-iq-helper.h \ gibber-file-transfer.c \ gibber-file-transfer.h \ gibber-oob-file-transfer.c \ diff --git a/lib/gibber/gibber-bytestream-oob.c b/lib/gibber/gibber-bytestream-oob.c index 64a0fa5e..f01c0a59 100644 --- a/lib/gibber/gibber-bytestream-oob.c +++ b/lib/gibber/gibber-bytestream-oob.c @@ -38,7 +38,6 @@ #include "gibber-namespaces.h" #include "gibber-linklocal-transport.h" #include "gibber-xmpp-error.h" -#include "gibber-iq-helper.h" #include "gibber-util.h" #include "gibber-transport.h" #include "gibber-fd-transport.h" diff --git a/lib/gibber/gibber-iq-helper.c b/lib/gibber/gibber-iq-helper.c deleted file mode 100644 index 24532255..00000000 --- a/lib/gibber/gibber-iq-helper.c +++ /dev/null @@ -1,403 +0,0 @@ -/* - * gibber-iq-helper.c - Source for GibberIqHelper - * Copyright (C) 2007 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 <stdio.h> -#include <unistd.h> -#include <stdlib.h> -#include <string.h> - -#include "gibber-iq-helper.h" - -#include "gibber-xmpp-reader.h" -#include "gibber-xmpp-writer.h" -#include "gibber-transport.h" -#include <wocky/wocky-stanza.h> - -G_DEFINE_TYPE (GibberIqHelper, gibber_iq_helper, G_TYPE_OBJECT); - -enum -{ - PROP_XMPP_CONNECTION = 1, -}; - -typedef struct _GibberIqHelperPrivate GibberIqHelperPrivate; - -struct _GibberIqHelperPrivate -{ - GibberXmppConnection *xmpp_connection; - GHashTable *id_handlers; - - gboolean dispose_has_run; -}; - -#define GIBBER_IQ_HELPER_GET_PRIVATE(obj) \ - ((GibberIqHelperPrivate *) ((GibberIqHelper *) obj)->priv) - -static void -reply_handler_object_destroy_notify_cb (gpointer _data, GObject *object); - -typedef struct -{ - GibberIqHelper *self; - gchar *id; - GibberIqHelperStanzaReplyFunc reply_func; - WockyStanza *sent_stanza; - GObject *object; - gpointer user_data; -} ReplyHandlerData; - -static void -free_reply_handler_data (ReplyHandlerData *data) -{ - g_object_unref (data->sent_stanza); - g_free (data->id); - - if (data->object != NULL) - { - g_object_weak_unref (data->object, - reply_handler_object_destroy_notify_cb, data); - } - - g_slice_free (ReplyHandlerData, data); -} - -static void -gibber_iq_helper_init (GibberIqHelper *self) -{ - GibberIqHelperPrivate *priv = G_TYPE_INSTANCE_GET_PRIVATE (self, - GIBBER_TYPE_IQ_HELPER, GibberIqHelperPrivate); - - self->priv = priv; - - priv->id_handlers = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, - (GDestroyNotify) free_reply_handler_data); - - priv->dispose_has_run = FALSE; -} - -static void -xmpp_connection_received_stanza_cb (GibberXmppConnection *conn, - WockyStanza *stanza, - gpointer user_data) -{ - WockyNode *node = wocky_stanza_get_top_node (stanza); - GibberIqHelper *self = GIBBER_IQ_HELPER (user_data); - GibberIqHelperPrivate *priv = GIBBER_IQ_HELPER_GET_PRIVATE (self); - const gchar *id; - ReplyHandlerData *data; - - id = wocky_node_get_attribute (node, "id"); - if (id == NULL) - return; - - data = g_hash_table_lookup (priv->id_handlers, id); - if (data == NULL) - return; - - /* Reply have to be an iq stanza */ - if (strcmp (node->name, "iq")) - return; - - /* Its subtype have to be "result" or "error" */ - if (strcmp (wocky_node_get_attribute (node, "type"), "result") - != 0 && - strcmp (wocky_node_get_attribute (node, "type"), "error") - != 0) - return; - - /* the user callback may want to free the GibberIqHelper object. Delay this. - */ - g_object_ref (self); - - data->reply_func (self, data->sent_stanza, - stanza, data->object, data->user_data); - - g_hash_table_remove (priv->id_handlers, id); - - g_object_unref (self); -} - -static GObject * -gibber_iq_helper_constructor (GType type, - guint n_props, - GObjectConstructParam *props) -{ - GObject *obj; - GibberIqHelper *self; - GibberIqHelperPrivate *priv; - - obj = G_OBJECT_CLASS(gibber_iq_helper_parent_class)-> - constructor (type, n_props, props); - - self = GIBBER_IQ_HELPER (obj); - priv = GIBBER_IQ_HELPER_GET_PRIVATE (self); - - g_assert (priv->xmpp_connection != NULL); - - g_signal_connect (priv->xmpp_connection, "received-stanza", - G_CALLBACK (xmpp_connection_received_stanza_cb), obj); - - return obj; -} - -static void -gibber_iq_helper_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec) -{ - GibberIqHelper *self = GIBBER_IQ_HELPER (object); - GibberIqHelperPrivate *priv = GIBBER_IQ_HELPER_GET_PRIVATE (self); - - switch (property_id) - { - case PROP_XMPP_CONNECTION: - g_value_set_object (value, priv->xmpp_connection); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -static void -gibber_iq_helper_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec) -{ - GibberIqHelper *self = GIBBER_IQ_HELPER (object); - GibberIqHelperPrivate *priv = GIBBER_IQ_HELPER_GET_PRIVATE (self); - - switch (property_id) - { - case PROP_XMPP_CONNECTION: - priv->xmpp_connection = g_value_get_object (value); - g_object_ref (priv->xmpp_connection); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -static void gibber_iq_helper_dispose (GObject *object); -static void gibber_iq_helper_finalize (GObject *object); - -static void -gibber_iq_helper_class_init (GibberIqHelperClass *gibber_iq_helper_class) -{ - GObjectClass *object_class = G_OBJECT_CLASS (gibber_iq_helper_class); - GParamSpec *param_spec; - - g_type_class_add_private (gibber_iq_helper_class, - sizeof (GibberIqHelperPrivate)); - - object_class->constructor = gibber_iq_helper_constructor; - - object_class->dispose = gibber_iq_helper_dispose; - object_class->finalize = gibber_iq_helper_finalize; - - object_class->get_property = gibber_iq_helper_get_property; - object_class->set_property = gibber_iq_helper_set_property; - - param_spec = g_param_spec_object ( - "xmpp-connection", - "GibberXmppConnection object", - "Gibber XMPP Connection associated with this GibberIqHelper object", - GIBBER_TYPE_XMPP_CONNECTION, - G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_XMPP_CONNECTION, - param_spec); -} - -void -gibber_iq_helper_dispose (GObject *object) -{ - GibberIqHelper *self = GIBBER_IQ_HELPER (object); - GibberIqHelperPrivate *priv = GIBBER_IQ_HELPER_GET_PRIVATE (self); - - if (priv->dispose_has_run) - return; - - priv->dispose_has_run = TRUE; - - g_assert (priv->xmpp_connection != NULL); - g_signal_handlers_disconnect_by_func (priv->xmpp_connection, - xmpp_connection_received_stanza_cb, self); - g_object_unref (priv->xmpp_connection); - priv->xmpp_connection = NULL; - - if (G_OBJECT_CLASS (gibber_iq_helper_parent_class)->dispose) - G_OBJECT_CLASS (gibber_iq_helper_parent_class)->dispose (object); -} - -void -gibber_iq_helper_finalize (GObject *object) -{ - GibberIqHelper *self = GIBBER_IQ_HELPER (object); - GibberIqHelperPrivate *priv = GIBBER_IQ_HELPER_GET_PRIVATE (self); - - g_hash_table_destroy (priv->id_handlers); - priv->id_handlers = NULL; - - G_OBJECT_CLASS (gibber_iq_helper_parent_class)->finalize (object); -} - -GibberIqHelper * -gibber_iq_helper_new (GibberXmppConnection *xmpp_connection) -{ - g_return_val_if_fail (xmpp_connection != NULL, NULL); - - return g_object_new (GIBBER_TYPE_IQ_HELPER, - "xmpp-connection", xmpp_connection, - NULL); -} - -static void -reply_handler_object_destroy_notify_cb (gpointer _data, - GObject *object) -{ - /* The object was destroyed so we don't care about the - * reply anymore */ - ReplyHandlerData *data = _data; - GibberIqHelperPrivate *priv = GIBBER_IQ_HELPER_GET_PRIVATE (data->self); - - data->object = NULL; - g_hash_table_remove (priv->id_handlers, data->id); -} - -/* - * gibber_iq_send_with_reply - * - * Send a WockyStanza and call reply_func when we receive - * its reply. - * - * If object is non-NULL the handler will follow the lifetime of that object, - * which means that if the object is destroyed the callback will not be invoked - */ -gboolean -gibber_iq_helper_send_with_reply (GibberIqHelper *self, - WockyStanza *iq, - GibberIqHelperStanzaReplyFunc reply_func, - GObject *object, - gpointer user_data, - GError **error) -{ - WockyNode *node = wocky_stanza_get_top_node (iq); - GibberIqHelperPrivate *priv; - const gchar *tmp; - gchar *id; - ReplyHandlerData *data; - - g_return_val_if_fail (self != NULL, FALSE); - g_return_val_if_fail (iq != NULL, FALSE); - g_return_val_if_fail (reply_func != NULL, FALSE); - g_return_val_if_fail (strcmp (node->name, "iq") == 0, FALSE); - - priv = GIBBER_IQ_HELPER_GET_PRIVATE (self); - - tmp = wocky_node_get_attribute (node, "id"); - if (tmp == NULL) - { - id = gibber_xmpp_connection_new_id (priv->xmpp_connection); - wocky_node_set_attribute (node, "id", id); - } - else - { - id = g_strdup (tmp); - } - - if (!gibber_xmpp_connection_send (priv->xmpp_connection, iq, error)) - { - g_free (id); - return FALSE; - } - - data = g_slice_new (ReplyHandlerData); - data->reply_func = reply_func; - data->sent_stanza = g_object_ref (iq); - data->user_data = user_data; - data->object = object; - data->id = id; - data->self = self; - - if (object != NULL) - { - g_object_weak_ref (object, reply_handler_object_destroy_notify_cb, - data); - } - - /* XXX set a timout if we don't receive the reply ? */ - g_hash_table_insert (priv->id_handlers, id, data); - - return TRUE; -} - -static WockyStanza * -new_reply (WockyStanza *iq, - WockyStanzaSubType sub_type) -{ - WockyStanza *reply; - WockyNode *node = wocky_stanza_get_top_node (iq); - const gchar *id; - const gchar *iq_from, *iq_to; - - g_return_val_if_fail (sub_type == WOCKY_STANZA_SUB_TYPE_RESULT || - sub_type == WOCKY_STANZA_SUB_TYPE_ERROR, NULL); - g_return_val_if_fail (strcmp (node->name, "iq") == 0, NULL); - - id = wocky_node_get_attribute (node, "id"); - g_return_val_if_fail (id != NULL, NULL); - - iq_from = wocky_node_get_attribute (node, "from"); - iq_to = wocky_node_get_attribute (node, "to"); - - reply = wocky_stanza_build (WOCKY_STANZA_TYPE_IQ, - sub_type, - iq_to, iq_from, - WOCKY_NODE_ATTRIBUTE, "id", id, - NULL); - - return reply; -} - -WockyStanza * -gibber_iq_helper_new_result_reply (WockyStanza *iq) -{ - return new_reply (iq, WOCKY_STANZA_SUB_TYPE_RESULT); -} - -WockyStanza * -gibber_iq_helper_new_error_reply (WockyStanza *iq, - GibberXmppError error, - const gchar *errmsg) -{ - WockyStanza *stanza; - WockyNode *node; - - stanza = new_reply (iq, WOCKY_STANZA_SUB_TYPE_ERROR); - node = wocky_stanza_get_top_node (stanza); - gibber_xmpp_error_to_node (error, node, errmsg); - - /* TODO: Would be cool to copy <iq> children as in Gabble */ - - return stanza; -} diff --git a/lib/gibber/gibber-iq-helper.h b/lib/gibber/gibber-iq-helper.h deleted file mode 100644 index 3336d976..00000000 --- a/lib/gibber/gibber-iq-helper.h +++ /dev/null @@ -1,87 +0,0 @@ -/* - * gibber-iq-helper.h - Header for GibberIqHelper - * Copyright (C) 2007 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 __GIBBER_IQ_HELPER_H__ -#define __GIBBER_IQ_HELPER_H__ - -#include <glib-object.h> - -#include <wocky/wocky-stanza.h> -#include "gibber-xmpp-connection.h" -#include "gibber-xmpp-error.h" - -G_BEGIN_DECLS - -typedef struct _GibberIqHelper GibberIqHelper; -typedef struct _GibberIqHelperClass GibberIqHelperClass; - -struct _GibberIqHelperClass -{ - GObjectClass parent_class; -}; - -struct _GibberIqHelper -{ - GObject parent; - - gpointer priv; -}; - -GType gibber_iq_helper_get_type (void); - -/* TYPE MACROS */ -#define GIBBER_TYPE_IQ_HELPER \ - (gibber_iq_helper_get_type ()) -#define GIBBER_IQ_HELPER(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST((obj), GIBBER_TYPE_IQ_HELPER, GibberIqHelper)) -#define GIBBER_IQ_HELPER_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST((klass), GIBBER_TYPE_IQ_HELPER, \ - GibberIqHelperClass)) -#define GIBBER_IS_IQ_HELPER(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE((obj), GIBBER_TYPE_IQ_HELPER)) -#define GIBBER_IS_IQ_HELPER_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE((klass), GIBBER_TYPE_IQ_HELPER)) -#define GIBBER_IQ_HELPER_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS ((obj), GIBBER_TYPE_IQ_HELPER, \ - GibberIqHelperClass)) - -typedef void (*GibberIqHelperStanzaReplyFunc) (GibberIqHelper *helper, - WockyStanza *sent_stanza, - WockyStanza *reply_stanza, - GObject *object, - gpointer user_data); - -GibberIqHelper * -gibber_iq_helper_new (GibberXmppConnection *xmpp_connection); - -gboolean -gibber_iq_helper_send_with_reply (GibberIqHelper *helper, - WockyStanza *iq, GibberIqHelperStanzaReplyFunc reply_func, - GObject *object, gpointer user_data, GError **error); - -WockyStanza * -gibber_iq_helper_new_result_reply (WockyStanza *iq); - -WockyStanza * -gibber_iq_helper_new_error_reply (WockyStanza *iq, GibberXmppError error, - const gchar *errmsg); - -G_END_DECLS - -#endif /* #ifndef __GIBBER_IQ_HELPER_H__*/ diff --git a/lib/gibber/tests/Makefile.am b/lib/gibber/tests/Makefile.am index cf40c475..b7e460fc 100644 --- a/lib/gibber/tests/Makefile.am +++ b/lib/gibber/tests/Makefile.am @@ -79,7 +79,6 @@ check_PROGRAMS = \ check-gibber-xmpp-connection \ check-gibber-r-multicast-packet \ check-gibber-r-multicast-sender \ - check-gibber-iq-helper \ check-gibber-listener \ check-gibber-xmpp-error \ check-gibber-unix-transport diff --git a/lib/gibber/tests/check-gibber-iq-helper.c b/lib/gibber/tests/check-gibber-iq-helper.c deleted file mode 100644 index 20bbdc8d..00000000 --- a/lib/gibber/tests/check-gibber-iq-helper.c +++ /dev/null @@ -1,439 +0,0 @@ -/* - * check-gibber-iq-helper.c - Test for GibberIqHelper - * Copyright (C) 2007 Collabora Ltd. - * @author Guillaume Desmottes <guillaume.desmottes@collabora.co.uk> - * - * 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 <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <dbus/dbus-glib.h> - -#include <wocky/wocky-stanza.h> -#include <gibber/gibber-iq-helper.h> -#include <gibber/gibber-xmpp-error.h> -#include <gibber/gibber-namespaces.h> - -#include "test-transport.h" - -static gboolean received_reply = FALSE; - -static gboolean -send_hook (GibberTransport *transport, - const guint8 *data, - gsize length, - GError **error, - gpointer user_data) -{ - test_transport_write (TEST_TRANSPORT (transport), data, length); - return TRUE; -} - -static GibberXmppConnection * -create_xmpp_connection (void) -{ - GibberXmppConnection *xmpp_connection; - TestTransport *transport; - - transport = test_transport_new (send_hook, NULL); - xmpp_connection = gibber_xmpp_connection_new (GIBBER_TRANSPORT (transport)); - gibber_xmpp_connection_open (xmpp_connection, "to", "from", "1.0"); - - g_object_unref (transport); - - return xmpp_connection; -} - -static void -test_iq_helper_new (void) -{ - GibberXmppConnection *xmpp_connection = create_xmpp_connection (); - GibberIqHelper *iq_helper = gibber_iq_helper_new (xmpp_connection); - g_assert (iq_helper != NULL); - g_object_unref (xmpp_connection); - g_object_unref (iq_helper); -} - -static void -reply_func (GibberIqHelper *helper, - WockyStanza *sent_stanza, - WockyStanza *reply_stanza, - GObject *object, - gpointer user_data) -{ - received_reply = TRUE; -} - -static void -send_stanza_and_reply (GibberXmppConnection *xmpp_connection, - GibberIqHelper *iq_helper, - WockyStanza *stanza, - WockyStanza *reply) -{ - gboolean result; - - if (stanza != NULL) - { - result = gibber_iq_helper_send_with_reply (iq_helper, stanza, reply_func, - NULL, NULL, NULL); - g_assert (result); - } - - if (reply != NULL) - { - result = gibber_xmpp_connection_send (xmpp_connection, reply, NULL); - g_assert (result); - } - - while (g_main_context_iteration (NULL, FALSE)) - ; - -} - -static void -test_send_with_reply (void) -{ - GibberXmppConnection *xmpp_connection = create_xmpp_connection (); - GibberIqHelper *iq_helper = gibber_iq_helper_new (xmpp_connection); - WockyStanza *stanza, *reply; - - received_reply = FALSE; - - stanza = wocky_stanza_build (WOCKY_STANZA_TYPE_IQ, - WOCKY_STANZA_SUB_TYPE_SET, - "from", "to", - WOCKY_NODE_ATTRIBUTE, "id", "69", - NULL); - - /* Reply of the stanza */ - reply = wocky_stanza_build (WOCKY_STANZA_TYPE_IQ, - WOCKY_STANZA_SUB_TYPE_RESULT, - "to", "from", - WOCKY_NODE_ATTRIBUTE, "id", "69", - NULL); - - send_stanza_and_reply (xmpp_connection, iq_helper, stanza, reply); - g_assert (received_reply); - - g_object_unref (stanza); - g_object_unref (reply); - g_object_unref (xmpp_connection); - g_object_unref (iq_helper); -} - -static void -test_send_without_reply (void) -{ - GibberXmppConnection *xmpp_connection = create_xmpp_connection (); - GibberIqHelper *iq_helper = gibber_iq_helper_new (xmpp_connection); - WockyStanza *stanza; - - received_reply = FALSE; - - stanza = wocky_stanza_build (WOCKY_STANZA_TYPE_IQ, - WOCKY_STANZA_SUB_TYPE_SET, - "from", "to", - WOCKY_NODE_ATTRIBUTE, "id", "69", - NULL); - - send_stanza_and_reply (xmpp_connection, iq_helper, stanza, NULL); - g_assert (!received_reply); - - g_object_unref (stanza); - g_object_unref (xmpp_connection); - g_object_unref (iq_helper); -} - -static void -test_send_with_bad_reply_type (void) -{ - GibberXmppConnection *xmpp_connection = create_xmpp_connection (); - GibberIqHelper *iq_helper = gibber_iq_helper_new (xmpp_connection); - WockyStanza *stanza, *reply; - - received_reply = FALSE; - - stanza = wocky_stanza_build (WOCKY_STANZA_TYPE_IQ, - WOCKY_STANZA_SUB_TYPE_SET, - "from", "to", - WOCKY_NODE_ATTRIBUTE, "id", "69", - NULL); - - /* Reply can't be of sub type "get" */ - reply = wocky_stanza_build (WOCKY_STANZA_TYPE_IQ, - WOCKY_STANZA_SUB_TYPE_GET, - "to", "from", - WOCKY_NODE_ATTRIBUTE, "id", "69", - NULL); - - send_stanza_and_reply (xmpp_connection, iq_helper, stanza, reply); - g_assert (!received_reply); - - g_object_unref (stanza); - g_object_unref (reply); - g_object_unref (xmpp_connection); - g_object_unref (iq_helper); -} - -static void -test_send_without_id (void) -{ - GibberXmppConnection *xmpp_connection = create_xmpp_connection (); - GibberIqHelper *iq_helper = gibber_iq_helper_new (xmpp_connection); - WockyStanza *stanza, *reply; - gboolean result; - const gchar *id; - - received_reply = FALSE; - - stanza = wocky_stanza_build (WOCKY_STANZA_TYPE_IQ, - WOCKY_STANZA_SUB_TYPE_SET, - "from", "to", - NULL); - - result = gibber_iq_helper_send_with_reply (iq_helper, stanza, reply_func, - NULL, NULL, NULL); - g_assert (result); - - /* gibber_iq_helper_send_with_reply generated an id */ - id = wocky_node_get_attribute (wocky_stanza_get_top_node (stanza), - "id"); - - reply = wocky_stanza_build (WOCKY_STANZA_TYPE_IQ, - WOCKY_STANZA_SUB_TYPE_RESULT, - "to", "from", - WOCKY_NODE_ATTRIBUTE, "id", id, - NULL); - - result = gibber_xmpp_connection_send (xmpp_connection, reply, NULL); - g_assert (result); - - while (g_main_context_iteration (NULL, FALSE)) - ; - - g_assert (received_reply); - - g_object_unref (stanza); - g_object_unref (reply); - g_object_unref (xmpp_connection); - g_object_unref (iq_helper); -} - -static void -test_new_result_reply (void) -{ - GibberXmppConnection *xmpp_connection = create_xmpp_connection (); - GibberIqHelper *iq_helper = gibber_iq_helper_new (xmpp_connection); - WockyStanza *stanza, *reply; - gboolean result; - - received_reply = FALSE; - - stanza = wocky_stanza_build (WOCKY_STANZA_TYPE_IQ, - WOCKY_STANZA_SUB_TYPE_SET, - "from", "to", - NULL); - - result = gibber_iq_helper_send_with_reply (iq_helper, stanza, reply_func, - NULL, NULL, NULL); - g_assert (result); - - reply = gibber_iq_helper_new_result_reply (stanza); - g_assert (reply != NULL); - g_assert_cmpstr (wocky_stanza_get_top_node (reply)->name, ==, "iq"); - g_assert_cmpstr ( - wocky_node_get_attribute (wocky_stanza_get_top_node (reply), "type"), - ==, "result"); - result = gibber_xmpp_connection_send (xmpp_connection, reply, NULL); - g_assert (result); - - while (g_main_context_iteration (NULL, FALSE)) - ; - - g_assert (received_reply); - - g_object_unref (stanza); - g_object_unref (reply); - g_object_unref (xmpp_connection); - g_object_unref (iq_helper); -} - -static void -test_new_error_reply (void) -{ - GibberXmppConnection *xmpp_connection = create_xmpp_connection (); - GibberIqHelper *iq_helper = gibber_iq_helper_new (xmpp_connection); - WockyStanza *stanza, *reply; - WockyNode *error_node, *node; - gboolean result; - - received_reply = FALSE; - - stanza = wocky_stanza_build (WOCKY_STANZA_TYPE_IQ, - WOCKY_STANZA_SUB_TYPE_SET, - "from", "to", - NULL); - - result = gibber_iq_helper_send_with_reply (iq_helper, stanza, reply_func, - NULL, NULL, NULL); - g_assert (result); - - reply = gibber_iq_helper_new_error_reply (stanza, - XMPP_ERROR_BAD_REQUEST, "test"); - g_assert (reply != NULL); - g_assert_cmpstr (wocky_stanza_get_top_node (reply)->name, ==, "iq"); - g_assert_cmpstr ( - wocky_node_get_attribute (wocky_stanza_get_top_node (reply), "type"), - ==, "error"); - - error_node = wocky_node_get_child (wocky_stanza_get_top_node (reply), - "error"); - g_assert (error_node != NULL); - g_assert_cmpstr (wocky_node_get_attribute (error_node, "code"), ==, "400"); - g_assert_cmpstr (wocky_node_get_attribute (error_node, "type"), ==, "modify"); - - node = wocky_node_get_child_ns (error_node, "bad-request", - GIBBER_XMPP_NS_STANZAS); - g_assert (node != NULL); - - node = wocky_node_get_child (error_node, "text"); - g_assert (node != NULL); - g_assert_cmpstr (node->content, ==, "test"); - - result = gibber_xmpp_connection_send (xmpp_connection, reply, NULL); - g_assert (result); - - while (g_main_context_iteration (NULL, FALSE)) - ; - - g_assert (received_reply); - - g_object_unref (stanza); - g_object_unref (reply); - g_object_unref (xmpp_connection); - g_object_unref (iq_helper); -} - -static void -test_send_with_object_living (void) -{ - GibberXmppConnection *xmpp_connection = create_xmpp_connection (); - GibberIqHelper *iq_helper = gibber_iq_helper_new (xmpp_connection); - WockyStanza *stanza, *reply; - gboolean result; - GObject *object; - - received_reply = FALSE; - - /* We don't care about the TestTransport, we just need a GObject */ - object = g_object_new (TEST_TYPE_TRANSPORT, NULL); - - stanza = wocky_stanza_build (WOCKY_STANZA_TYPE_IQ, - WOCKY_STANZA_SUB_TYPE_SET, - "from", "to", - NULL); - - result = gibber_iq_helper_send_with_reply (iq_helper, stanza, reply_func, - object, NULL, NULL); - g_assert (result); - - reply = gibber_iq_helper_new_result_reply (stanza); - g_assert (reply != NULL); - result = gibber_xmpp_connection_send (xmpp_connection, reply, NULL); - g_assert (result); - - while (g_main_context_iteration (NULL, FALSE)) - ; - - g_assert (received_reply); - - g_object_unref (stanza); - g_object_unref (reply); - g_object_unref (object); - g_object_unref (xmpp_connection); - g_object_unref (iq_helper); -} - -static void -test_send_with_object_destroyed (void) -{ - GibberXmppConnection *xmpp_connection = create_xmpp_connection (); - GibberIqHelper *iq_helper = gibber_iq_helper_new (xmpp_connection); - WockyStanza *stanza, *reply; - gboolean result; - GObject *object; - - received_reply = FALSE; - - /* We don't care about the TestTransport, we just need a GObject */ - object = g_object_new (TEST_TYPE_TRANSPORT, NULL); - - stanza = wocky_stanza_build (WOCKY_STANZA_TYPE_IQ, - WOCKY_STANZA_SUB_TYPE_SET, - "from", "to", - NULL); - - result = gibber_iq_helper_send_with_reply (iq_helper, stanza, reply_func, - object, NULL, NULL); - g_assert (result); - - g_object_unref (object); - - reply = gibber_iq_helper_new_result_reply (stanza); - g_assert (reply != NULL); - result = gibber_xmpp_connection_send (xmpp_connection, reply, NULL); - g_assert (result); - - while (g_main_context_iteration (NULL, FALSE)) - ; - - /* Object was destroyed before we send the reply so we don't receive - * the reply */ - g_assert (!received_reply); - - g_object_unref (stanza); - g_object_unref (reply); - g_object_unref (xmpp_connection); - g_object_unref (iq_helper); -} - -int -main (int argc, - char **argv) -{ - g_test_init (&argc, &argv, NULL); - g_type_init (); - - g_test_add_func ("/gibber/iq-helper/new", test_iq_helper_new); - g_test_add_func ("/gibber/iq-helper/send-with-reply", test_send_with_reply); - g_test_add_func ("/gibber/iq-helper/send-without-reply", - test_send_without_reply); - g_test_add_func ("/gibber/iq-helper/send-with-bad-reply-type", - test_send_with_bad_reply_type); - g_test_add_func ("/gibber/iq-helper/send-without-id", test_send_without_id); - g_test_add_func ("/gibber/iq-helper/new-result-reply", test_new_result_reply); - g_test_add_func ("/gibber/iq-helper/new-error-reply", test_new_error_reply); - g_test_add_func ("/gibber/iq-helper/send-with-object-living", - test_send_with_object_living); - g_test_add_func ("/gibber/iq-helper/send-with-object-destroyed", - test_send_with_object_destroyed); - - return g_test_run (); -} - -#include "test-transport.c" |