From 3864cf8a8ce675a95f0ae35d33d7eed87453ad11 Mon Sep 17 00:00:00 2001 From: Nicolas Dufresne Date: Fri, 4 Dec 2009 16:43:18 -0500 Subject: Added placeholder for google Mail Notification Added feature detection for "google:mail:notify" and pace holder for mail notification interface implementation. Signed-off-by: Nicolas Dufresne --- src/Makefile.am | 2 ++ src/conn-mail-notif.c | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/conn-mail-notif.h | 37 ++++++++++++++++++++++++ src/connection.c | 7 ++++- src/connection.h | 1 + src/namespaces.h | 1 + 6 files changed, 127 insertions(+), 1 deletion(-) create mode 100644 src/conn-mail-notif.c create mode 100644 src/conn-mail-notif.h (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am index e0d656a74..02ef616c9 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -53,6 +53,8 @@ libgabble_convenience_la_SOURCES = \ conn-presence.c \ conn-sidecars.h \ conn-sidecars.c \ + conn-mail-notif.h \ + conn-mail-notif.c \ connection.h \ connection.c \ connection-manager.h \ diff --git a/src/conn-mail-notif.c b/src/conn-mail-notif.c new file mode 100644 index 000000000..5a7b39d6f --- /dev/null +++ b/src/conn-mail-notif.c @@ -0,0 +1,80 @@ +/* + * conn-mail-notif - Gabble mail notification interface + * Copyright (C) 2009 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 "config.h" +#include "conn-mail-notif.h" + +#include + +#include "extensions/extensions.h" +#include +#include +#include + +#define DEBUG_FLAG GABBLE_DEBUG_MAIL_NOTIF + +#include "connection.h" +#include "debug.h" + +static void +gabble_mail_notification_subscribe (GabbleSvcConnectionInterfaceMailNotification *self, + DBusGMethodInvocation *context) +{ + /* TODO */ +} + +static void +gabble_mail_notification_unsubscribe (GabbleSvcConnectionInterfaceMailNotification *self, + DBusGMethodInvocation *context) +{ + /* TODO */ +} + +void +conn_mail_notif_class_init (GabbleConnectionClass *klass) +{ + /* TODO */ +} + + +void +conn_mail_notif_init (GabbleConnection *conn) +{ + /* TODO */ +} + + +void +conn_mail_notif_finalize (GabbleConnection *conn) +{ + /* TODO */ +} + + +void +conn_mail_notif_iface_init (gpointer g_iface, gpointer iface_data) +{ + GabbleSvcConnectionInterfaceMailNotificationClass *klass = g_iface; + +#define IMPLEMENT(x) gabble_svc_connection_interface_mail_notification_implement_##x (\ + klass, gabble_mail_notification_##x) + IMPLEMENT(subscribe); + IMPLEMENT(unsubscribe); +#undef IMPLEMENT +} diff --git a/src/conn-mail-notif.h b/src/conn-mail-notif.h new file mode 100644 index 000000000..10a642fd7 --- /dev/null +++ b/src/conn-mail-notif.h @@ -0,0 +1,37 @@ +/* + * conn-mail-notif.h - Header for Gabble connection mail notification interface + * Copyright (C) 2009 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 __CONN_EMAIL_NOTIF_H__ +#define __CONN_EMAIL_NOTIF_H__ + +#include + +#include "connection.h" + +G_BEGIN_DECLS + +void conn_mail_notif_class_init (GabbleConnectionClass *klass); +void conn_mail_notif_init (GabbleConnection *conn); +void conn_mail_notif_finalize (GabbleConnection *conn); +void conn_mail_notif_iface_init (gpointer g_iface, gpointer iface_data); + +G_END_DECLS + +#endif /* __CONN_EMAIL_NOTIF_H__ */ + diff --git a/src/connection.c b/src/connection.c index d0643e2e1..5b3993bcb 100644 --- a/src/connection.c +++ b/src/connection.c @@ -55,6 +55,7 @@ #include "conn-location.h" #include "conn-presence.h" #include "conn-sidecars.h" +#include "conn-mail-notif.h" #include "conn-olpc.h" #include "debug.h" #include "disco.h" @@ -95,7 +96,7 @@ G_DEFINE_TYPE_WITH_CODE(GabbleConnection, conn_avatars_iface_init); G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_CONNECTION_INTERFACE_CAPABILITIES, capabilities_service_iface_init); - G_IMPLEMENT_INTERFACE(TP_TYPE_SVC_DBUS_PROPERTIES, + G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_DBUS_PROPERTIES, tp_dbus_properties_mixin_iface_init); G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_CONNECTION_INTERFACE_CONTACTS, tp_contacts_mixin_iface_init); @@ -118,6 +119,8 @@ G_DEFINE_TYPE_WITH_CODE(GabbleConnection, olpc_gadget_iface_init); G_IMPLEMENT_INTERFACE (GABBLE_TYPE_SVC_CONNECTION_FUTURE, conn_future_iface_init); + G_IMPLEMENT_INTERFACE (GABBLE_TYPE_SVC_CONNECTION_INTERFACE_MAIL_NOTIFICATION, + conn_mail_notif_iface_init); ) /* properties */ @@ -2544,6 +2547,8 @@ connection_disco_cb (GabbleDisco *disco, conn->features |= GABBLE_CONNECTION_FEATURES_PRESENCE_INVISIBLE; else if (0 == strcmp (var, NS_PRIVACY)) conn->features |= GABBLE_CONNECTION_FEATURES_PRIVACY; + else if (0 == strcmp (var, NS_GOOGLE_MAIL_NOTIFY)) + conn->features |= GABBLE_CONNECTION_FEATURES_GOOGLE_MAIL_NOTIFY; } } diff --git a/src/connection.h b/src/connection.h index 6bce3053c..8758d91af 100644 --- a/src/connection.h +++ b/src/connection.h @@ -74,6 +74,7 @@ typedef enum GABBLE_CONNECTION_FEATURES_PRESENCE_INVISIBLE = 1 << 2, GABBLE_CONNECTION_FEATURES_PRIVACY = 1 << 3, GABBLE_CONNECTION_FEATURES_PEP = 1 << 4, + GABBLE_CONNECTION_FEATURES_GOOGLE_MAIL_NOTIFY = 1 << 5, } GabbleConnectionFeatures; typedef struct _GabbleConnectionPrivate GabbleConnectionPrivate; diff --git a/src/namespaces.h b/src/namespaces.h index 50c6e322b..18b3feb5c 100644 --- a/src/namespaces.h +++ b/src/namespaces.h @@ -105,6 +105,7 @@ #define NS_X_CONFERENCE "jabber:x:conference" #define NS_XMPP_STANZAS "urn:ietf:params:xml:ns:xmpp-stanzas" #define NS_GEOLOC "http://jabber.org/protocol/geoloc" +#define NS_GOOGLE_MAIL_NOTIFY "google:mail:notify" #define NS_TEMPPRES "urn:xmpp:temppres:0" -- cgit v1.2.1 From 45f52585e5bb68caad719929a9f81e95a417a74b Mon Sep 17 00:00:00 2001 From: Nicolas Dufresne Date: Tue, 22 Dec 2009 15:21:59 -0500 Subject: Adding mail notification debug section Signed-off-by: Nicolas Dufresne --- src/debug.c | 1 + src/debug.h | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/debug.c b/src/debug.c index ad180b556..53c884674 100644 --- a/src/debug.c +++ b/src/debug.c @@ -39,6 +39,7 @@ static GDebugKey keys[] = { { "search", GABBLE_DEBUG_SEARCH }, { "base-channel", GABBLE_DEBUG_BASE_CHANNEL }, { "plugins", GABBLE_DEBUG_PLUGINS }, + { "mail-notif", GABBLE_DEBUG_MAIL_NOTIF }, { 0, }, }; diff --git a/src/debug.h b/src/debug.h index 5eacff62c..dcd2cb85a 100644 --- a/src/debug.h +++ b/src/debug.h @@ -32,7 +32,8 @@ typedef enum GABBLE_DEBUG_FT = 1 << 18, GABBLE_DEBUG_SEARCH = 1 << 19, GABBLE_DEBUG_BASE_CHANNEL = 1 << 20, - GABBLE_DEBUG_PLUGINS = 1 << 21 + GABBLE_DEBUG_PLUGINS = 1 << 21, + GABBLE_DEBUG_MAIL_NOTIF = 1 << 22 } GabbleDebugFlags; void gabble_debug_set_flags_from_env (void); -- cgit v1.2.1 From 707cfcb9316547ccf2a033ef12ab10b8701582c7 Mon Sep 17 00:00:00 2001 From: Nicolas Dufresne Date: Tue, 22 Dec 2009 16:01:52 -0500 Subject: Adding Mail Notification properties stubs Also removed unneeded class_init() and rename finalize into dispose() since it's most used name. Signed-off-by: Nicolas Dufresne --- src/conn-mail-notif.c | 61 ++++++++++++++++++++++++++++++++++++++++++++------- src/conn-mail-notif.h | 5 +++-- src/connection.c | 25 +++++++++++++++++++++ 3 files changed, 81 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/conn-mail-notif.c b/src/conn-mail-notif.c index 5a7b39d6f..e561cefee 100644 --- a/src/conn-mail-notif.c +++ b/src/conn-mail-notif.c @@ -32,6 +32,19 @@ #include "connection.h" #include "debug.h" +enum +{ + PROP_CAPABILITIES, + PROP_UNREAD_MAIL_COUNT, + PROP_INBOX_URL, + PROP_METHOD, + PROP_POST_DATA, + PROP_UNREAD_MAILS, + NUM_OF_PROP, +}; + +static GPtrArray empty_array = { 0 }; + static void gabble_mail_notification_subscribe (GabbleSvcConnectionInterfaceMailNotification *self, DBusGMethodInvocation *context) @@ -46,13 +59,6 @@ gabble_mail_notification_unsubscribe (GabbleSvcConnectionInterfaceMailNotificati /* TODO */ } -void -conn_mail_notif_class_init (GabbleConnectionClass *klass) -{ - /* TODO */ -} - - void conn_mail_notif_init (GabbleConnection *conn) { @@ -61,7 +67,7 @@ conn_mail_notif_init (GabbleConnection *conn) void -conn_mail_notif_finalize (GabbleConnection *conn) +conn_mail_notif_dispose (GabbleConnection *conn) { /* TODO */ } @@ -78,3 +84,42 @@ conn_mail_notif_iface_init (gpointer g_iface, gpointer iface_data) IMPLEMENT(unsubscribe); #undef IMPLEMENT } + +void +conn_mail_notif_properties_getter (GObject *object, + GQuark interface, + GQuark name, + GValue *value, + gpointer getter_data) +{ + static GQuark prop_quarks[NUM_OF_PROP] = {0}; + + if (G_UNLIKELY (prop_quarks[0] == 0)) + { + prop_quarks[PROP_CAPABILITIES] = g_quark_from_static_string ("Capabilities"); + prop_quarks[PROP_UNREAD_MAIL_COUNT] = g_quark_from_static_string ("UnreadMailCount"); + prop_quarks[PROP_INBOX_URL] = g_quark_from_static_string ("InboxURL"); + prop_quarks[PROP_METHOD] = g_quark_from_static_string ("Method"); + prop_quarks[PROP_POST_DATA] = g_quark_from_static_string ("PostData"); + prop_quarks[PROP_UNREAD_MAILS] = g_quark_from_static_string ("UnreadMails"); + } + + DEBUG ("MailNotification get property %s", g_quark_to_string (name)); + + if (name == prop_quarks[PROP_CAPABILITIES]) + g_value_set_uint (value, + GABBLE_MAIL_NOTIFICATION_HAS_PROP_UNREADMAILCOUNT + | GABBLE_MAIL_NOTIFICATION_HAS_PROP_UNREADMAILS); + else if (name == prop_quarks[PROP_UNREAD_MAIL_COUNT]) + g_value_set_uint (value, 0); + else if (name == prop_quarks[PROP_INBOX_URL]) + g_value_set_string (value, ""); + else if (name == prop_quarks[PROP_METHOD]) + g_value_set_uint (value, GABBLE_HTTP_METHOD_GET); + else if (name == prop_quarks[PROP_POST_DATA]) + g_value_set_static_boxed (value, &empty_array); + else if (name == prop_quarks[PROP_UNREAD_MAILS]) + g_value_set_boxed (value, &empty_array); + else + g_assert (!"Unkown mail notification property, please file a bug."); +} diff --git a/src/conn-mail-notif.h b/src/conn-mail-notif.h index 10a642fd7..cfe9f3d3a 100644 --- a/src/conn-mail-notif.h +++ b/src/conn-mail-notif.h @@ -26,10 +26,11 @@ G_BEGIN_DECLS -void conn_mail_notif_class_init (GabbleConnectionClass *klass); void conn_mail_notif_init (GabbleConnection *conn); -void conn_mail_notif_finalize (GabbleConnection *conn); +void conn_mail_notif_dispose (GabbleConnection *conn); void conn_mail_notif_iface_init (gpointer g_iface, gpointer iface_data); +void conn_mail_notif_properties_getter (GObject *object, GQuark interface, + GQuark name, GValue *value, gpointer getter_data); G_END_DECLS diff --git a/src/connection.c b/src/connection.c index 5b3993bcb..bd2b6a540 100644 --- a/src/connection.c +++ b/src/connection.c @@ -336,6 +336,7 @@ gabble_connection_constructor (GType type, conn_olpc_activity_properties_init (self); conn_location_init (self); conn_sidecars_init (self); + conn_mail_notif_init (self); tp_contacts_mixin_add_contact_attributes_iface (G_OBJECT (self), TP_IFACE_CONNECTION_INTERFACE_CAPABILITIES, @@ -727,6 +728,15 @@ gabble_connection_class_init (GabbleConnectionClass *gabble_connection_class) { "DecloakAutomatically", TWICE ("decloak-automatically") }, { NULL } }; + static TpDBusPropertiesMixinPropImpl mail_notif_props[] = { + { "Capabilities", NULL, NULL }, + { "UnreadMailCount", NULL, NULL }, + { "InboxURL", NULL, NULL }, + { "Method", NULL, NULL }, + { "PostData", NULL, NULL }, + { "UnreadMails", NULL, NULL }, + { NULL } + }; static TpDBusPropertiesMixinIfaceImpl prop_interfaces[] = { { GABBLE_IFACE_OLPC_GADGET, conn_olpc_gadget_properties_getter, @@ -748,6 +758,11 @@ gabble_connection_class_init (GabbleConnectionClass *gabble_connection_class) tp_dbus_properties_mixin_setter_gobject_properties, decloak_props, }, + { GABBLE_IFACE_CONNECTION_INTERFACE_MAIL_NOTIFICATION, + conn_mail_notif_properties_getter, + NULL, + mail_notif_props, + }, { NULL } }; @@ -1009,6 +1024,8 @@ gabble_connection_dispose (GObject *object) g_hash_table_destroy (self->avatar_requests); + conn_mail_notif_dispose (self); + g_assert (priv->iq_disco_cb == NULL); g_assert (priv->iq_unknown_cb == NULL); g_assert (priv->olpc_msg_cb == NULL); @@ -2564,6 +2581,14 @@ connection_disco_cb (GabbleDisco *disco, tp_base_connection_add_interfaces ((TpBaseConnection *) conn, ifaces); } + if (conn->features & GABBLE_CONNECTION_FEATURES_GOOGLE_MAIL_NOTIFY) + { + const gchar *ifaces[] = + { GABBLE_IFACE_CONNECTION_INTERFACE_MAIL_NOTIFICATION, NULL }; + + tp_base_connection_add_interfaces ((TpBaseConnection *) conn, ifaces); + } + /* send presence to the server to indicate availability */ /* TODO: some way for the user to set this */ if (!_gabble_connection_signal_own_presence (conn, NULL, &error)) -- cgit v1.2.1 From 6c5703d040347acffb524c98d776b9915eb54853 Mon Sep 17 00:00:00 2001 From: Nicolas Dufresne Date: Tue, 22 Dec 2009 16:15:30 -0500 Subject: Implemented MailNotification.Subscribe/Unsubscribe Signed-off-by: Nicolas Dufresne --- src/conn-mail-notif.c | 124 +++++++++++++++++++++++++++++++++++++++++++++++--- src/connection.h | 6 +++ 2 files changed, 124 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/conn-mail-notif.c b/src/conn-mail-notif.c index e561cefee..43171e689 100644 --- a/src/conn-mail-notif.c +++ b/src/conn-mail-notif.c @@ -26,6 +26,8 @@ #include #include #include +#include +#include #define DEBUG_FLAG GABBLE_DEBUG_MAIL_NOTIF @@ -45,31 +47,141 @@ enum static GPtrArray empty_array = { 0 }; +static void unsubscribe (GabbleConnection *conn, const gchar *name); + +static void +sender_name_owner_changed (TpDBusDaemon *dbus_daemon, + const gchar *name, + const gchar *new_owner, + gpointer user_data) +{ + GabbleConnection *conn = user_data; + + if (new_owner == NULL || new_owner[0] == '\0') + { + DEBUG ("Sender removed: %s", name); + unsubscribe (conn, name); + } +} + static void -gabble_mail_notification_subscribe (GabbleSvcConnectionInterfaceMailNotification *self, +unsubscribe (GabbleConnection *conn, const gchar *name) +{ + tp_dbus_daemon_cancel_name_owner_watch (conn->daemon, name, + sender_name_owner_changed, conn); + + g_return_if_fail (conn->mail_subscribers_count > 0); + + conn->mail_subscribers_count -= 1; + g_datalist_remove_data (&conn->mail_subscribers, name); + + if (conn->mail_subscribers_count == 0) + { + DEBUG ("Last sender unsubscribed, cleaning up!"); + /* TODO Clean Mails data */ + } +} + +static void +gabble_mail_notification_subscribe (GabbleSvcConnectionInterfaceMailNotification *iface, DBusGMethodInvocation *context) { - /* TODO */ + GabbleConnection *conn = GABBLE_CONNECTION (iface); + const gchar *sender = dbus_g_method_get_sender (context); + + DEBUG ("Subscribe called by: %s", sender); + + if (!(conn->features & GABBLE_CONNECTION_FEATURES_GOOGLE_MAIL_NOTIFY) + || !conn->daemon) + { + tp_dbus_g_method_return_not_implemented (context); + return; + } + + if (g_datalist_get_data (&conn->mail_subscribers, sender)) + { + DEBUG ("Sender '%s' is already subscribed!", sender); + goto done; + } + + conn->mail_subscribers_count += 1; + g_datalist_set_data (&conn->mail_subscribers, sender, conn); + + /* TODO Get Mails Data */ + + tp_dbus_daemon_watch_name_owner (conn->daemon, + dbus_g_method_get_sender (context), + sender_name_owner_changed, conn, NULL); + +done: + gabble_svc_connection_interface_mail_notification_return_from_subscribe (context); } static void -gabble_mail_notification_unsubscribe (GabbleSvcConnectionInterfaceMailNotification *self, +gabble_mail_notification_unsubscribe (GabbleSvcConnectionInterfaceMailNotification *iface, DBusGMethodInvocation *context) { - /* TODO */ + GabbleConnection *conn = GABBLE_CONNECTION (iface); + const gchar *sender = dbus_g_method_get_sender (context); + + DEBUG ("Unsubscribe called by: %s", sender); + + if (!(conn->features & GABBLE_CONNECTION_FEATURES_GOOGLE_MAIL_NOTIFY) + || !conn->daemon) + { + tp_dbus_g_method_return_not_implemented (context); + return; + } + + if (!g_datalist_get_data (&conn->mail_subscribers, sender)) + { + DEBUG ("Sender '%s' is not subscribed!", sender); + goto done; + } + + unsubscribe (conn, sender); + +done: + gabble_svc_connection_interface_mail_notification_return_from_unsubscribe (context); } void conn_mail_notif_init (GabbleConnection *conn) { - /* TODO */ + GError *error = NULL; + conn->daemon = tp_dbus_daemon_dup (&error); + if (!conn->daemon) + { + DEBUG ("Failed to connect to dbus daemon: %s", error->message); + g_error_free (error); + } + + conn->mail_subscribers_count = 0; + conn->mail_subscribers = NULL; } +static void +foreach_cancel_watch (GQuark key_id, + gpointer handle_set, + gpointer user_data) +{ + GabbleConnection *conn = user_data; + + tp_dbus_daemon_cancel_name_owner_watch (conn->daemon, + g_quark_to_string (key_id), sender_name_owner_changed, conn); +} void conn_mail_notif_dispose (GabbleConnection *conn) { - /* TODO */ + if (conn->daemon) + { + conn->mail_subscribers_count = 0; + g_datalist_clear (&conn->mail_subscribers); + g_datalist_foreach (&conn->mail_subscribers, foreach_cancel_watch, conn); + g_object_unref (conn->daemon); + conn->daemon = NULL; + } } diff --git a/src/connection.h b/src/connection.h index 8758d91af..04b180d4d 100644 --- a/src/connection.h +++ b/src/connection.h @@ -28,6 +28,7 @@ #include #include #include +#include #include #include @@ -188,6 +189,11 @@ struct _GabbleConnection { /* gchar *interface → GList */ GHashTable *pending_sidecars; + /* Mail Notification */ + TpDBusDaemon *daemon; + gint mail_subscribers_count; + GData *mail_subscribers; + GabbleConnectionPrivate *priv; }; -- cgit v1.2.1 From 68a5e1a8fd20e10784cc01aa47ba3d4bdd7a10dd Mon Sep 17 00:00:00 2001 From: Nicolas Dufresne Date: Tue, 22 Dec 2009 17:11:45 -0500 Subject: Added data structurs to store emails data Signed-off-by: Nicolas Dufresne --- src/conn-mail-notif.c | 26 +++++++++++++++++++++----- src/connection.h | 2 ++ 2 files changed, 23 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/conn-mail-notif.c b/src/conn-mail-notif.c index 43171e689..5680d9b74 100644 --- a/src/conn-mail-notif.c +++ b/src/conn-mail-notif.c @@ -78,7 +78,13 @@ unsubscribe (GabbleConnection *conn, const gchar *name) if (conn->mail_subscribers_count == 0) { DEBUG ("Last sender unsubscribed, cleaning up!"); - /* TODO Clean Mails data */ + g_free (conn->inbox_url); + conn->inbox_url = NULL; + if (conn->unread_mails) + { + g_hash_table_unref (conn->unread_mails); + conn->unread_mails = NULL; + } } } @@ -158,6 +164,8 @@ conn_mail_notif_init (GabbleConnection *conn) conn->mail_subscribers_count = 0; conn->mail_subscribers = NULL; + conn->inbox_url = NULL; + conn->unread_mails = NULL; } static void @@ -182,6 +190,12 @@ conn_mail_notif_dispose (GabbleConnection *conn) g_object_unref (conn->daemon); conn->daemon = NULL; } + + g_free (conn->inbox_url); + conn->inbox_url = NULL; + if (conn->unread_mails) + g_hash_table_unref (conn->unread_mails); + conn->unread_mails = NULL; } @@ -205,6 +219,7 @@ conn_mail_notif_properties_getter (GObject *object, gpointer getter_data) { static GQuark prop_quarks[NUM_OF_PROP] = {0}; + GabbleConnection *conn = GABBLE_CONNECTION (object); if (G_UNLIKELY (prop_quarks[0] == 0)) { @@ -223,15 +238,16 @@ conn_mail_notif_properties_getter (GObject *object, GABBLE_MAIL_NOTIFICATION_HAS_PROP_UNREADMAILCOUNT | GABBLE_MAIL_NOTIFICATION_HAS_PROP_UNREADMAILS); else if (name == prop_quarks[PROP_UNREAD_MAIL_COUNT]) - g_value_set_uint (value, 0); + g_value_set_uint (value, + conn->unread_mails ? g_hash_table_size (conn->unread_mails) : 0); else if (name == prop_quarks[PROP_INBOX_URL]) - g_value_set_string (value, ""); + g_value_set_string (value, conn->inbox_url ?: ""); else if (name == prop_quarks[PROP_METHOD]) g_value_set_uint (value, GABBLE_HTTP_METHOD_GET); else if (name == prop_quarks[PROP_POST_DATA]) - g_value_set_static_boxed (value, &empty_array); + g_value_set_static_boxed (value, &empty_array); /* TODO */ else if (name == prop_quarks[PROP_UNREAD_MAILS]) - g_value_set_boxed (value, &empty_array); + g_value_set_boxed (value, &empty_array); /* TODO */ else g_assert (!"Unkown mail notification property, please file a bug."); } diff --git a/src/connection.h b/src/connection.h index 04b180d4d..b040db37c 100644 --- a/src/connection.h +++ b/src/connection.h @@ -193,6 +193,8 @@ struct _GabbleConnection { TpDBusDaemon *daemon; gint mail_subscribers_count; GData *mail_subscribers; + gchar *inbox_url; + GHashTable *unread_mails; GabbleConnectionPrivate *priv; }; -- cgit v1.2.1 From 8f52902aa9c0b8143fd033866517ff87ba9f6325 Mon Sep 17 00:00:00 2001 From: Nicolas Dufresne Date: Tue, 22 Dec 2009 17:55:44 -0500 Subject: Added google new-mail notification and mail request Hook signal to the new-mail message sent with google mail notification namespace and added mails data request. Signed-off-by: Nicolas Dufresne --- src/conn-mail-notif.c | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++- src/connection.h | 1 + 2 files changed, 95 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/conn-mail-notif.c b/src/conn-mail-notif.c index 5680d9b74..2f8f29975 100644 --- a/src/conn-mail-notif.c +++ b/src/conn-mail-notif.c @@ -19,6 +19,7 @@ #include "config.h" #include "conn-mail-notif.h" +#include "namespaces.h" #include @@ -48,6 +49,7 @@ enum static GPtrArray empty_array = { 0 }; static void unsubscribe (GabbleConnection *conn, const gchar *name); +static void update_unread_mails (GabbleConnection *conn); static void sender_name_owner_changed (TpDBusDaemon *dbus_daemon, @@ -114,7 +116,7 @@ gabble_mail_notification_subscribe (GabbleSvcConnectionInterfaceMailNotification g_datalist_set_data (&conn->mail_subscribers, sender, conn); /* TODO Get Mails Data */ - + tp_dbus_daemon_watch_name_owner (conn->daemon, dbus_g_method_get_sender (context), sender_name_owner_changed, conn, NULL); @@ -151,6 +153,87 @@ done: gabble_svc_connection_interface_mail_notification_return_from_unsubscribe (context); } +static void +get_unread_mails (GObject *source_object, GAsyncResult *res, gpointer user_data) +{ + GError *error = NULL; + gchar *result_str; + WockyXmppNode *node; + WockyPorter *porter = WOCKY_PORTER (source_object); + WockyXmppStanza *reply = wocky_porter_send_iq_finish (porter, res, &error); + + if (error) + { + DEBUG ("Failed retreive unread emails information: %s", error->message); + g_error_free (error); + goto end; + } + + DEBUG ("Got unread mail details"); + + result_str = wocky_xmpp_node_to_string (reply->node); + DEBUG("%s", result_str); + g_free (result_str); + + node = wocky_xmpp_node_get_child (reply->node, "mailbox"); + /* TODO Store unread mails */ + +end: + if (reply) + g_object_unref (reply); +} + +static void +update_unread_mails (GabbleConnection *conn) +{ + WockyXmppStanza *query; + WockyPorter *porter = wocky_session_get_porter (conn->session); + + DEBUG ("Updating unread mails information"); + + query = wocky_xmpp_stanza_build ( WOCKY_STANZA_TYPE_IQ, + WOCKY_STANZA_SUB_TYPE_GET, NULL, NULL, + WOCKY_NODE, "query", + WOCKY_NODE_XMLNS, NS_GOOGLE_MAIL_NOTIFY, + WOCKY_NODE_END, + WOCKY_STANZA_END); + wocky_porter_send_iq_async (porter, query, NULL, get_unread_mails, conn); + g_object_unref (query); +} + +static gboolean +new_mail_handler (WockyPorter *porter, WockyXmppStanza *stanza, + gpointer user_data) +{ + GabbleConnection *conn = user_data; + if (conn->mail_subscribers_count > 0) + { + DEBUG ("Got Google notification"); + update_unread_mails (conn); + } + return TRUE; +} + +static void +connection_status_changed (GabbleConnection *conn, TpConnectionStatus status, + TpConnectionStatusReason reason, gpointer user_data) +{ + if (status == TP_CONNECTION_STATUS_CONNECTED + && conn->features & GABBLE_CONNECTION_FEATURES_GOOGLE_MAIL_NOTIFY) + { + DEBUG ("Connected, registering Google 'new-mail' notification"); + conn->new_mail_handler_id = + wocky_porter_register_handler (wocky_session_get_porter (conn->session), + WOCKY_STANZA_TYPE_IQ, WOCKY_STANZA_SUB_TYPE_SET, + NULL, WOCKY_PORTER_HANDLER_PRIORITY_NORMAL, + new_mail_handler, conn, + WOCKY_NODE, "new-mail", + WOCKY_NODE_XMLNS, NS_GOOGLE_MAIL_NOTIFY, + WOCKY_NODE_END, + WOCKY_STANZA_END); + } +} + void conn_mail_notif_init (GabbleConnection *conn) { @@ -166,6 +249,9 @@ conn_mail_notif_init (GabbleConnection *conn) conn->mail_subscribers = NULL; conn->inbox_url = NULL; conn->unread_mails = NULL; + + g_signal_connect (conn, "status-changed", + G_CALLBACK (connection_status_changed), conn); } static void @@ -196,6 +282,13 @@ conn_mail_notif_dispose (GabbleConnection *conn) if (conn->unread_mails) g_hash_table_unref (conn->unread_mails); conn->unread_mails = NULL; + + if (conn->new_mail_handler_id) + { + WockyPorter *porter = wocky_session_get_porter (conn->session); + wocky_porter_unregister_handler (porter, conn->new_mail_handler_id); + conn->new_mail_handler_id = 0; + } } diff --git a/src/connection.h b/src/connection.h index b040db37c..cba6d98ff 100644 --- a/src/connection.h +++ b/src/connection.h @@ -195,6 +195,7 @@ struct _GabbleConnection { GData *mail_subscribers; gchar *inbox_url; GHashTable *unread_mails; + guint new_mail_handler_id; GabbleConnectionPrivate *priv; }; -- cgit v1.2.1 From c90cf44f0231d96bf1d7837aa6e7cfd98db9c7d4 Mon Sep 17 00:00:00 2001 From: Nicolas Dufresne Date: Tue, 22 Dec 2009 18:10:44 -0500 Subject: Store unread mails information Signed-off-by: Nicolas Dufresne --- src/conn-mail-notif.c | 130 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 128 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/conn-mail-notif.c b/src/conn-mail-notif.c index 2f8f29975..5831c25b7 100644 --- a/src/conn-mail-notif.c +++ b/src/conn-mail-notif.c @@ -46,6 +46,14 @@ enum NUM_OF_PROP, }; +struct MailsHelperData +{ + GabbleConnection *conn; + GHashTable *unread_mails; + GHashTable *old_mails; + GPtrArray *mails_added; +}; + static GPtrArray empty_array = { 0 }; static void unsubscribe (GabbleConnection *conn, const gchar *name); @@ -115,7 +123,8 @@ gabble_mail_notification_subscribe (GabbleSvcConnectionInterfaceMailNotification conn->mail_subscribers_count += 1; g_datalist_set_data (&conn->mail_subscribers, sender, conn); - /* TODO Get Mails Data */ + if (conn->mail_subscribers_count == 1) + update_unread_mails(conn); tp_dbus_daemon_watch_name_owner (conn->daemon, dbus_g_method_get_sender (context), @@ -153,6 +162,119 @@ done: gabble_svc_connection_interface_mail_notification_return_from_unsubscribe (context); } +static gboolean +mail_thread_info_each (WockyXmppNode *node, gpointer user_data) +{ + struct MailsHelperData *data = user_data; + + if (!tp_strdiff (node->name, "mail-thread-info")) + { + GHashTable *mail = NULL; + const gchar *val_str; + guint64 *tid; + gboolean dirty = FALSE; + + val_str = wocky_xmpp_node_get_attribute (node, "tid"); + + /* We absolutly need an ID */ + if (!val_str) + return TRUE; + + tid = g_new (guint64, 1); + *tid = g_ascii_strtoull (val_str, NULL, 0); + + if (data->old_mails) + mail = g_hash_table_lookup (data->old_mails, tid); + + if (mail) + { + g_hash_table_ref (mail); + g_hash_table_remove (data->old_mails, tid); + } + else + { + mail = tp_asv_new ("id", G_TYPE_UINT64, *tid, + "type", G_TYPE_UINT, GABBLE_MAIL_TYPE_THREAD, + NULL); + dirty = TRUE; + } + + val_str = wocky_xmpp_node_get_attribute (node, "date"); + if (val_str) + { + guint date; + date = (guint)(g_ascii_strtoull (val_str, NULL, 0) / 1000l); + if (date != tp_asv_get_uint32 (mail, "received-timestamp", NULL)) + dirty = TRUE; + tp_asv_set_uint32 (mail, "received-timestamp", date); + } + + /* TODO Handle URL, senders, subject and snippet */ + + g_hash_table_insert (data->unread_mails, tid, mail); + if (dirty) + g_ptr_array_add (data->mails_added, mail); + } + + return TRUE; +} + +static void +store_unread_mails (GabbleConnection *conn, WockyXmppNode *mailbox) +{ + GHashTableIter iter; + GArray *mails_removed; + struct MailsHelperData data; + const gchar *url; + + data.unread_mails = g_hash_table_new_full (g_int64_hash, + g_int64_equal, + g_free, + (GDestroyNotify)g_hash_table_unref); + data.conn = conn; + data.old_mails = conn->unread_mails; + conn->unread_mails = data.unread_mails; + data.mails_added = g_ptr_array_new (); + + url = wocky_xmpp_node_get_attribute (mailbox, "url"); + if (url && tp_strdiff (url, conn->inbox_url)) + { + /* FIXME figure-out how to use POST data to garantee authentication */ + g_free (conn->inbox_url); + conn->inbox_url = g_strdup (url); + gabble_svc_connection_interface_mail_notification_emit_inbox_url_changed ( + conn, conn->inbox_url, GABBLE_HTTP_METHOD_GET, &empty_array); + } + + /* Store new mails */ + wocky_xmpp_node_each_child (mailbox, mail_thread_info_each, &data); + + /* Generate the list of removed thread IDs */ + if (data.old_mails) + { + gpointer key; + mails_removed = g_array_sized_new (TRUE, TRUE, + sizeof (guint64), g_hash_table_size (data.old_mails)); + + g_hash_table_iter_init (&iter, data.old_mails); + while (g_hash_table_iter_next (&iter, &key, NULL)) + { + guint64 tid = *((guint64*)key); + g_array_append_val (mails_removed, tid); + } + g_hash_table_unref (data.old_mails); + } + else + mails_removed = g_array_new (TRUE, TRUE, sizeof (guint64)); + + if (data.mails_added->len || mails_removed->len) + gabble_svc_connection_interface_mail_notification_emit_unread_mails_changed (conn, + g_hash_table_size (conn->unread_mails), data.mails_added, mails_removed); + + g_ptr_array_free (data.mails_added, TRUE); + g_array_free (mails_removed, TRUE); +} + static void get_unread_mails (GObject *source_object, GAsyncResult *res, gpointer user_data) { @@ -176,7 +298,11 @@ get_unread_mails (GObject *source_object, GAsyncResult *res, gpointer user_data) g_free (result_str); node = wocky_xmpp_node_get_child (reply->node, "mailbox"); - /* TODO Store unread mails */ + if (node) + { + GabbleConnection *conn = user_data; + store_unread_mails (conn, node); + } end: if (reply) -- cgit v1.2.1 From 776b4707861cfd54d8b506638c30bfeadd63d4cd Mon Sep 17 00:00:00 2001 From: Nicolas Dufresne Date: Tue, 22 Dec 2009 18:27:00 -0500 Subject: Added mail attributes url, senders, subject and snippet Signed-off-by: Nicolas Dufresne --- src/conn-mail-notif.c | 101 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 100 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/conn-mail-notif.c b/src/conn-mail-notif.c index 5831c25b7..4f278a19d 100644 --- a/src/conn-mail-notif.c +++ b/src/conn-mail-notif.c @@ -162,6 +162,102 @@ done: gabble_svc_connection_interface_mail_notification_return_from_unsubscribe (context); } +static void +handle_url (GHashTable *mail, guint64 tid, const gchar *base_url) +{ + /* The URL in result is broken. The th= parameter should be in hexadecimal + * but it's set in decimal. We could try and fix the string, but the URL does + * not point exactly where we expect it to point. Let's craft a different + * URL that do a better job.*/ + + /* TODO Make sure we don't have to authenticate again */ + + GString *url = g_string_new (base_url); + g_string_append_printf (url, "/#inbox/%" G_GINT64_MODIFIER "x", tid); + + tp_asv_set_string (mail, "url", url->str); + tp_asv_set_uint32 (mail, "method", GABBLE_HTTP_METHOD_GET); + + g_string_free (url, TRUE); +} + +static gboolean +sender_each (WockyXmppNode *node, gpointer user_data) +{ + GPtrArray *senders = user_data; + + if (!tp_strdiff ("1", wocky_xmpp_node_get_attribute (node, "unread"))) + { + GType addr_type = GABBLE_STRUCT_TYPE_MAIL_ADDRESS; + GValue sender = {0}; + + g_value_init (&sender, addr_type); + g_value_set_static_boxed (&sender, + dbus_g_type_specialized_construct (addr_type)); + + dbus_g_type_struct_set (&sender, + 0, wocky_xmpp_node_get_attribute (node, "name") ?: "", + 1, wocky_xmpp_node_get_attribute (node, "address") ?: "", + G_MAXUINT); + + g_ptr_array_add (senders, g_value_get_boxed(&sender)); + g_value_unset (&sender); + } + return TRUE; +} + +static void +handle_senders (WockyXmppNode *parent_node, GHashTable *mail, gboolean *dirty) +{ + WockyXmppNode *node; + + node = wocky_xmpp_node_get_child (parent_node, "senders"); + if (node) + { + GType addr_list_type = GABBLE_ARRAY_TYPE_MAIL_ADDRESS_LIST; + GPtrArray *senders, *old_senders; + + senders = g_ptr_array_new (); + wocky_xmpp_node_each_child (node, sender_each, senders); + + old_senders = tp_asv_get_boxed (mail, "senders", addr_list_type); + if (!old_senders || senders->len != old_senders->len) + *dirty = TRUE; + + tp_asv_take_boxed (mail, "senders", addr_list_type, senders); + } +} + +static void +handle_subject (WockyXmppNode *parent_node, GHashTable *mail, gboolean *dirty) +{ + WockyXmppNode *node; + node = wocky_xmpp_node_get_child (parent_node, "subject"); + if (node) + { + if (tp_strdiff (node->content, tp_asv_get_string (mail, "subject"))) + { + *dirty = TRUE; + tp_asv_set_string (mail, "subject", node->content); + } + } +} + +static void +handle_snippet (WockyXmppNode *parent_node, GHashTable *mail, gboolean *dirty) +{ + WockyXmppNode *node; + node = wocky_xmpp_node_get_child (parent_node, "snippet"); + if (node) + { + if (tp_strdiff (node->content, tp_asv_get_string (mail, "snippet"))) + { + *dirty = TRUE; + tp_asv_set_string (mail, "snippet", node->content); + } + } +} + static gboolean mail_thread_info_each (WockyXmppNode *node, gpointer user_data) { @@ -209,7 +305,10 @@ mail_thread_info_each (WockyXmppNode *node, gpointer user_data) tp_asv_set_uint32 (mail, "received-timestamp", date); } - /* TODO Handle URL, senders, subject and snippet */ + handle_url (mail, *tid, data->conn->inbox_url); + handle_senders (node, mail, &dirty); + handle_subject (node, mail, &dirty); + handle_snippet (node, mail, &dirty); g_hash_table_insert (data->unread_mails, tid, mail); if (dirty) -- cgit v1.2.1 From 530502c43f4b9aceae07d6c98b1e6173fad64475 Mon Sep 17 00:00:00 2001 From: Nicolas Dufresne Date: Tue, 22 Dec 2009 18:57:18 -0500 Subject: Implemented getter for UnreadMails Signed-off-by: Nicolas Dufresne --- src/conn-mail-notif.c | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/conn-mail-notif.c b/src/conn-mail-notif.c index 4f278a19d..03b2b2d8c 100644 --- a/src/conn-mail-notif.c +++ b/src/conn-mail-notif.c @@ -375,7 +375,7 @@ store_unread_mails (GabbleConnection *conn, WockyXmppNode *mailbox) } static void -get_unread_mails (GObject *source_object, GAsyncResult *res, gpointer user_data) +query_unread_mails_cb (GObject *source_object, GAsyncResult *res, gpointer user_data) { GError *error = NULL; gchar *result_str; @@ -422,7 +422,7 @@ update_unread_mails (GabbleConnection *conn) WOCKY_NODE_XMLNS, NS_GOOGLE_MAIL_NOTIFY, WOCKY_NODE_END, WOCKY_STANZA_END); - wocky_porter_send_iq_async (porter, query, NULL, get_unread_mails, conn); + wocky_porter_send_iq_async (porter, query, NULL, query_unread_mails_cb, conn); g_object_unref (query); } @@ -529,6 +529,22 @@ conn_mail_notif_iface_init (gpointer g_iface, gpointer iface_data) #undef IMPLEMENT } +static GPtrArray* +get_unread_mails (GabbleConnection *conn) +{ + GPtrArray *mails = g_ptr_array_new (); + GHashTableIter iter; + gpointer value; + g_hash_table_iter_init (&iter, conn->unread_mails); + while (g_hash_table_iter_next (&iter, NULL, &value)) + { + GHashTable *mail = value; + g_ptr_array_add (mails, mail); + } + + return mails; +} + void conn_mail_notif_properties_getter (GObject *object, GQuark interface, @@ -563,9 +579,13 @@ conn_mail_notif_properties_getter (GObject *object, else if (name == prop_quarks[PROP_METHOD]) g_value_set_uint (value, GABBLE_HTTP_METHOD_GET); else if (name == prop_quarks[PROP_POST_DATA]) - g_value_set_static_boxed (value, &empty_array); /* TODO */ + g_value_set_static_boxed (value, &empty_array); else if (name == prop_quarks[PROP_UNREAD_MAILS]) - g_value_set_boxed (value, &empty_array); /* TODO */ + { + GPtrArray *mails = get_unread_mails(conn); + g_value_set_boxed (value, mails); + g_ptr_array_free (mails, TRUE); + } else g_assert (!"Unkown mail notification property, please file a bug."); } -- cgit v1.2.1 From 0696b230303994342d1b3566d44b6fb805b29d98 Mon Sep 17 00:00:00 2001 From: Nicolas Dufresne Date: Wed, 23 Dec 2009 21:32:57 -0500 Subject: Changed mails_subscribers into HashTable The mail subscribers where listed in GData with quarks for senders bus name. These name are different for every client, wich make usage of quarks inapropriate since the quark hash table tends to grow. Also fixed a leak with confusing dbus_g_method_get_sender() that do a strdup(). Signed-off-by: Nicolas Dufresne --- src/conn-mail-notif.c | 51 ++++++++++++++++++++++++++++----------------------- src/connection.h | 3 +-- 2 files changed, 29 insertions(+), 25 deletions(-) (limited to 'src') diff --git a/src/conn-mail-notif.c b/src/conn-mail-notif.c index 03b2b2d8c..134af5d34 100644 --- a/src/conn-mail-notif.c +++ b/src/conn-mail-notif.c @@ -80,12 +80,11 @@ unsubscribe (GabbleConnection *conn, const gchar *name) tp_dbus_daemon_cancel_name_owner_watch (conn->daemon, name, sender_name_owner_changed, conn); - g_return_if_fail (conn->mail_subscribers_count > 0); + g_return_if_fail (g_hash_table_size (conn->mail_subscribers) > 0); - conn->mail_subscribers_count -= 1; - g_datalist_remove_data (&conn->mail_subscribers, name); + g_hash_table_remove (conn->mail_subscribers, name); - if (conn->mail_subscribers_count == 0) + if (g_hash_table_size (conn->mail_subscribers) == 0) { DEBUG ("Last sender unsubscribed, cleaning up!"); g_free (conn->inbox_url); @@ -103,7 +102,7 @@ gabble_mail_notification_subscribe (GabbleSvcConnectionInterfaceMailNotification DBusGMethodInvocation *context) { GabbleConnection *conn = GABBLE_CONNECTION (iface); - const gchar *sender = dbus_g_method_get_sender (context); + gchar *sender = dbus_g_method_get_sender (context); DEBUG ("Subscribe called by: %s", sender); @@ -111,23 +110,22 @@ gabble_mail_notification_subscribe (GabbleSvcConnectionInterfaceMailNotification || !conn->daemon) { tp_dbus_g_method_return_not_implemented (context); + g_free (sender); return; } - if (g_datalist_get_data (&conn->mail_subscribers, sender)) + if (g_hash_table_lookup_extended (conn->mail_subscribers, sender, NULL, NULL)) { DEBUG ("Sender '%s' is already subscribed!", sender); goto done; } - conn->mail_subscribers_count += 1; - g_datalist_set_data (&conn->mail_subscribers, sender, conn); + g_hash_table_insert (conn->mail_subscribers, sender, NULL); - if (conn->mail_subscribers_count == 1) + if (g_hash_table_size (conn->mail_subscribers) == 1) update_unread_mails(conn); - tp_dbus_daemon_watch_name_owner (conn->daemon, - dbus_g_method_get_sender (context), + tp_dbus_daemon_watch_name_owner (conn->daemon, sender, sender_name_owner_changed, conn, NULL); done: @@ -139,7 +137,7 @@ gabble_mail_notification_unsubscribe (GabbleSvcConnectionInterfaceMailNotificati DBusGMethodInvocation *context) { GabbleConnection *conn = GABBLE_CONNECTION (iface); - const gchar *sender = dbus_g_method_get_sender (context); + gchar *sender = dbus_g_method_get_sender (context); DEBUG ("Unsubscribe called by: %s", sender); @@ -147,10 +145,12 @@ gabble_mail_notification_unsubscribe (GabbleSvcConnectionInterfaceMailNotificati || !conn->daemon) { tp_dbus_g_method_return_not_implemented (context); + g_free (sender); return; } - if (!g_datalist_get_data (&conn->mail_subscribers, sender)) + if (!g_hash_table_lookup_extended (conn->mail_subscribers, sender, + NULL, NULL)) { DEBUG ("Sender '%s' is not subscribed!", sender); goto done; @@ -159,6 +159,7 @@ gabble_mail_notification_unsubscribe (GabbleSvcConnectionInterfaceMailNotificati unsubscribe (conn, sender); done: + g_free (sender); gabble_svc_connection_interface_mail_notification_return_from_unsubscribe (context); } @@ -431,7 +432,7 @@ new_mail_handler (WockyPorter *porter, WockyXmppStanza *stanza, gpointer user_data) { GabbleConnection *conn = user_data; - if (conn->mail_subscribers_count > 0) + if (g_hash_table_size(conn->mail_subscribers) > 0) { DEBUG ("Got Google notification"); update_unread_mails (conn); @@ -470,8 +471,8 @@ conn_mail_notif_init (GabbleConnection *conn) g_error_free (error); } - conn->mail_subscribers_count = 0; - conn->mail_subscribers = NULL; + conn->mail_subscribers = g_hash_table_new_full (g_str_hash, g_str_equal, + g_free, NULL); conn->inbox_url = NULL; conn->unread_mails = NULL; @@ -479,15 +480,18 @@ conn_mail_notif_init (GabbleConnection *conn) G_CALLBACK (connection_status_changed), conn); } -static void -foreach_cancel_watch (GQuark key_id, - gpointer handle_set, +static gboolean +foreach_cancel_watch (gpointer key, + gpointer value, gpointer user_data) { GabbleConnection *conn = user_data; + const gchar *sender_name = user_data; tp_dbus_daemon_cancel_name_owner_watch (conn->daemon, - g_quark_to_string (key_id), sender_name_owner_changed, conn); + sender_name, sender_name_owner_changed, conn); + + return TRUE; } void @@ -495,9 +499,10 @@ conn_mail_notif_dispose (GabbleConnection *conn) { if (conn->daemon) { - conn->mail_subscribers_count = 0; - g_datalist_clear (&conn->mail_subscribers); - g_datalist_foreach (&conn->mail_subscribers, foreach_cancel_watch, conn); + g_hash_table_foreach_remove (conn->mail_subscribers, + foreach_cancel_watch, conn); + g_hash_table_unref (conn->mail_subscribers); + conn->mail_subscribers = NULL; g_object_unref (conn->daemon); conn->daemon = NULL; } diff --git a/src/connection.h b/src/connection.h index cba6d98ff..4832588fd 100644 --- a/src/connection.h +++ b/src/connection.h @@ -191,8 +191,7 @@ struct _GabbleConnection { /* Mail Notification */ TpDBusDaemon *daemon; - gint mail_subscribers_count; - GData *mail_subscribers; + GHashTable *mail_subscribers; gchar *inbox_url; GHashTable *unread_mails; guint new_mail_handler_id; -- cgit v1.2.1 From d8efecefc3ab316055ff7ec3ea31acc233cb0995 Mon Sep 17 00:00:00 2001 From: Nicolas Dufresne Date: Wed, 23 Dec 2009 21:48:44 -0500 Subject: Moved macro CHECK_STR_EMPTY to util and use it where possible Signed-off-by: Nicolas Dufresne --- src/conn-mail-notif.c | 3 ++- src/connection.c | 2 +- src/ft-channel.c | 2 -- src/jingle-session.c | 2 +- src/util.h | 2 ++ src/vcard-manager.c | 2 +- 6 files changed, 7 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/conn-mail-notif.c b/src/conn-mail-notif.c index 134af5d34..d27a31280 100644 --- a/src/conn-mail-notif.c +++ b/src/conn-mail-notif.c @@ -34,6 +34,7 @@ #include "connection.h" #include "debug.h" +#include "util.h" enum { @@ -67,7 +68,7 @@ sender_name_owner_changed (TpDBusDaemon *dbus_daemon, { GabbleConnection *conn = user_data; - if (new_owner == NULL || new_owner[0] == '\0') + if (CHECK_STR_EMPTY (new_owner)) { DEBUG ("Sender removed: %s", name); unsubscribe (conn, name); diff --git a/src/connection.c b/src/connection.c index bd2b6a540..5859e6f9e 100644 --- a/src/connection.c +++ b/src/connection.c @@ -3317,7 +3317,7 @@ gabble_connection_send_presence (GabbleConnection *conn, if (LM_MESSAGE_SUB_TYPE_SUBSCRIBE == sub_type) lm_message_node_add_own_nick (message->node, conn); - if (status != NULL && status[0] != '\0') + if (!CHECK_STR_EMPTY(status)) lm_message_node_add_child (message->node, "status", status); result = _gabble_connection_send (conn, message, error); diff --git a/src/ft-channel.c b/src/ft-channel.c index eff2a885a..7ae1d5bc3 100644 --- a/src/ft-channel.c +++ b/src/ft-channel.c @@ -67,8 +67,6 @@ G_DEFINE_TYPE_WITH_CODE (GabbleFileTransferChannel, gabble_file_transfer_channel file_transfer_iface_init); ); -#define CHECK_STR_EMPTY(x) ((x) == NULL || (x)[0] == '\0') - #define GABBLE_UNDEFINED_FILE_SIZE G_MAXUINT64 static const char *gabble_file_transfer_channel_interfaces[] = { NULL }; diff --git a/src/jingle-session.c b/src/jingle-session.c index d67ca6780..73f75b468 100644 --- a/src/jingle-session.c +++ b/src/jingle-session.c @@ -2038,7 +2038,7 @@ gabble_jingle_session_terminate (GabbleJingleSession *sess, lm_message_node_add_child (r, reason_elt, NULL); - if (text != NULL && *text != '\0') + if (!CHECK_STR_EMPTY(text)) lm_message_node_add_child (r, "text", text); } diff --git a/src/util.h b/src/util.h index aa6dbe67b..cd4de7b48 100644 --- a/src/util.h +++ b/src/util.h @@ -35,6 +35,8 @@ #include "types.h" +#define CHECK_STR_EMPTY(x) ((x) == NULL || (x)[0] == '\0') + typedef GSList * NodeIter; #define node_iter(node) (node->children) #define node_iter_next(i) (g_slist_next (i)) diff --git a/src/vcard-manager.c b/src/vcard-manager.c index 4353609f2..02877e040 100644 --- a/src/vcard-manager.c +++ b/src/vcard-manager.c @@ -810,7 +810,7 @@ observe_vcard (GabbleConnection *conn, { const gchar *fn = lm_message_node_get_value (fn_node); - if (fn != NULL && *fn != '\0') + if (!CHECK_STR_EMPTY(fn)) { field = ""; alias = g_strdup (fn); -- cgit v1.2.1 From 1b82ef746f09fa80c3203c4d08424deb4a19d0a5 Mon Sep 17 00:00:00 2001 From: Nicolas Dufresne Date: Wed, 23 Dec 2009 21:53:48 -0500 Subject: Mail Notification: Replace g_string_append_printf by g_strdup_printf() Signed-off-by: Nicolas Dufresne --- src/conn-mail-notif.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/conn-mail-notif.c b/src/conn-mail-notif.c index d27a31280..b29a9a79b 100644 --- a/src/conn-mail-notif.c +++ b/src/conn-mail-notif.c @@ -167,6 +167,7 @@ done: static void handle_url (GHashTable *mail, guint64 tid, const gchar *base_url) { + gchar *url; /* The URL in result is broken. The th= parameter should be in hexadecimal * but it's set in decimal. We could try and fix the string, but the URL does * not point exactly where we expect it to point. Let's craft a different @@ -174,13 +175,10 @@ handle_url (GHashTable *mail, guint64 tid, const gchar *base_url) /* TODO Make sure we don't have to authenticate again */ - GString *url = g_string_new (base_url); - g_string_append_printf (url, "/#inbox/%" G_GINT64_MODIFIER "x", tid); + url = g_strdup_printf ("%s/#inbox/%" G_GINT64_MODIFIER "x", base_url, tid); - tp_asv_set_string (mail, "url", url->str); + tp_asv_take_string (mail, "url", url); tp_asv_set_uint32 (mail, "method", GABBLE_HTTP_METHOD_GET); - - g_string_free (url, TRUE); } static gboolean -- cgit v1.2.1 From b0011cfbe615adc6e3db123ff3813493d0f24bc0 Mon Sep 17 00:00:00 2001 From: Nicolas Dufresne Date: Wed, 23 Dec 2009 22:25:54 -0500 Subject: Mail Notification: Fix coding style Removed trailing spaces. Put every function arguments of function definition on it's own line. Added white line after local declaration. Added a second white line between type definition block, static declaration block, forward declaration block and function definition. Signed-off-by: Nicolas Dufresne --- src/conn-mail-notif.c | 104 +++++++++++++++++++++++++++++++++++++------------- 1 file changed, 78 insertions(+), 26 deletions(-) (limited to 'src') diff --git a/src/conn-mail-notif.c b/src/conn-mail-notif.c index b29a9a79b..0441228a0 100644 --- a/src/conn-mail-notif.c +++ b/src/conn-mail-notif.c @@ -36,6 +36,7 @@ #include "debug.h" #include "util.h" + enum { PROP_CAPABILITIES, @@ -55,11 +56,14 @@ struct MailsHelperData GPtrArray *mails_added; }; + static GPtrArray empty_array = { 0 }; + static void unsubscribe (GabbleConnection *conn, const gchar *name); static void update_unread_mails (GabbleConnection *conn); + static void sender_name_owner_changed (TpDBusDaemon *dbus_daemon, const gchar *name, @@ -75,8 +79,10 @@ sender_name_owner_changed (TpDBusDaemon *dbus_daemon, } } + static void -unsubscribe (GabbleConnection *conn, const gchar *name) +unsubscribe (GabbleConnection *conn, + const gchar *name) { tp_dbus_daemon_cancel_name_owner_watch (conn->daemon, name, sender_name_owner_changed, conn); @@ -98,6 +104,7 @@ unsubscribe (GabbleConnection *conn, const gchar *name) } } + static void gabble_mail_notification_subscribe (GabbleSvcConnectionInterfaceMailNotification *iface, DBusGMethodInvocation *context) @@ -133,6 +140,7 @@ done: gabble_svc_connection_interface_mail_notification_return_from_subscribe (context); } + static void gabble_mail_notification_unsubscribe (GabbleSvcConnectionInterfaceMailNotification *iface, DBusGMethodInvocation *context) @@ -150,7 +158,7 @@ gabble_mail_notification_unsubscribe (GabbleSvcConnectionInterfaceMailNotificati return; } - if (!g_hash_table_lookup_extended (conn->mail_subscribers, sender, + if (!g_hash_table_lookup_extended (conn->mail_subscribers, sender, NULL, NULL)) { DEBUG ("Sender '%s' is not subscribed!", sender); @@ -164,11 +172,15 @@ done: gabble_svc_connection_interface_mail_notification_return_from_unsubscribe (context); } + static void -handle_url (GHashTable *mail, guint64 tid, const gchar *base_url) +handle_url (GHashTable *mail, + guint64 tid, + const gchar *base_url) { gchar *url; - /* The URL in result is broken. The th= parameter should be in hexadecimal + + /* The URL in result is broken. The th= parameter should be in hexadecimal * but it's set in decimal. We could try and fix the string, but the URL does * not point exactly where we expect it to point. Let's craft a different * URL that do a better job.*/ @@ -176,13 +188,15 @@ handle_url (GHashTable *mail, guint64 tid, const gchar *base_url) /* TODO Make sure we don't have to authenticate again */ url = g_strdup_printf ("%s/#inbox/%" G_GINT64_MODIFIER "x", base_url, tid); - + tp_asv_take_string (mail, "url", url); tp_asv_set_uint32 (mail, "method", GABBLE_HTTP_METHOD_GET); } + static gboolean -sender_each (WockyXmppNode *node, gpointer user_data) +sender_each (WockyXmppNode *node, + gpointer user_data) { GPtrArray *senders = user_data; @@ -192,7 +206,7 @@ sender_each (WockyXmppNode *node, gpointer user_data) GValue sender = {0}; g_value_init (&sender, addr_type); - g_value_set_static_boxed (&sender, + g_value_set_static_boxed (&sender, dbus_g_type_specialized_construct (addr_type)); dbus_g_type_struct_set (&sender, @@ -206,8 +220,11 @@ sender_each (WockyXmppNode *node, gpointer user_data) return TRUE; } + static void -handle_senders (WockyXmppNode *parent_node, GHashTable *mail, gboolean *dirty) +handle_senders (WockyXmppNode *parent_node, + GHashTable *mail, + gboolean *dirty) { WockyXmppNode *node; @@ -228,10 +245,14 @@ handle_senders (WockyXmppNode *parent_node, GHashTable *mail, gboolean *dirty) } } + static void -handle_subject (WockyXmppNode *parent_node, GHashTable *mail, gboolean *dirty) +handle_subject (WockyXmppNode *parent_node, + GHashTable *mail, + gboolean *dirty) { WockyXmppNode *node; + node = wocky_xmpp_node_get_child (parent_node, "subject"); if (node) { @@ -243,10 +264,14 @@ handle_subject (WockyXmppNode *parent_node, GHashTable *mail, gboolean *dirty) } } + static void -handle_snippet (WockyXmppNode *parent_node, GHashTable *mail, gboolean *dirty) +handle_snippet (WockyXmppNode *parent_node, + GHashTable *mail, + gboolean *dirty) { WockyXmppNode *node; + node = wocky_xmpp_node_get_child (parent_node, "snippet"); if (node) { @@ -258,8 +283,10 @@ handle_snippet (WockyXmppNode *parent_node, GHashTable *mail, gboolean *dirty) } } + static gboolean -mail_thread_info_each (WockyXmppNode *node, gpointer user_data) +mail_thread_info_each (WockyXmppNode *node, + gpointer user_data) { struct MailsHelperData *data = user_data; @@ -299,9 +326,11 @@ mail_thread_info_each (WockyXmppNode *node, gpointer user_data) if (val_str) { guint date; + date = (guint)(g_ascii_strtoull (val_str, NULL, 0) / 1000l); if (date != tp_asv_get_uint32 (mail, "received-timestamp", NULL)) dirty = TRUE; + tp_asv_set_uint32 (mail, "received-timestamp", date); } @@ -318,14 +347,16 @@ mail_thread_info_each (WockyXmppNode *node, gpointer user_data) return TRUE; } + static void -store_unread_mails (GabbleConnection *conn, WockyXmppNode *mailbox) +store_unread_mails (GabbleConnection *conn, + WockyXmppNode *mailbox) { GHashTableIter iter; GArray *mails_removed; struct MailsHelperData data; const gchar *url; - + data.unread_mails = g_hash_table_new_full (g_int64_hash, g_int64_equal, g_free, @@ -347,20 +378,22 @@ store_unread_mails (GabbleConnection *conn, WockyXmppNode *mailbox) /* Store new mails */ wocky_xmpp_node_each_child (mailbox, mail_thread_info_each, &data); - + /* Generate the list of removed thread IDs */ if (data.old_mails) { gpointer key; + mails_removed = g_array_sized_new (TRUE, TRUE, sizeof (guint64), g_hash_table_size (data.old_mails)); g_hash_table_iter_init (&iter, data.old_mails); - while (g_hash_table_iter_next (&iter, &key, NULL)) + while (g_hash_table_iter_next (&iter, &key, NULL)) { guint64 tid = *((guint64*)key); g_array_append_val (mails_removed, tid); } + g_hash_table_unref (data.old_mails); } else @@ -374,8 +407,11 @@ store_unread_mails (GabbleConnection *conn, WockyXmppNode *mailbox) g_array_free (mails_removed, TRUE); } + static void -query_unread_mails_cb (GObject *source_object, GAsyncResult *res, gpointer user_data) +query_unread_mails_cb (GObject *source_object, + GAsyncResult *res, + gpointer user_data) { GError *error = NULL; gchar *result_str; @@ -389,13 +425,13 @@ query_unread_mails_cb (GObject *source_object, GAsyncResult *res, gpointer user_ g_error_free (error); goto end; } - + DEBUG ("Got unread mail details"); result_str = wocky_xmpp_node_to_string (reply->node); - DEBUG("%s", result_str); + DEBUG ("%s", result_str); g_free (result_str); - + node = wocky_xmpp_node_get_child (reply->node, "mailbox"); if (node) { @@ -408,6 +444,7 @@ end: g_object_unref (reply); } + static void update_unread_mails (GabbleConnection *conn) { @@ -416,7 +453,7 @@ update_unread_mails (GabbleConnection *conn) DEBUG ("Updating unread mails information"); - query = wocky_xmpp_stanza_build ( WOCKY_STANZA_TYPE_IQ, + query = wocky_xmpp_stanza_build (WOCKY_STANZA_TYPE_IQ, WOCKY_STANZA_SUB_TYPE_GET, NULL, NULL, WOCKY_NODE, "query", WOCKY_NODE_XMLNS, NS_GOOGLE_MAIL_NOTIFY, @@ -426,11 +463,14 @@ update_unread_mails (GabbleConnection *conn) g_object_unref (query); } + static gboolean -new_mail_handler (WockyPorter *porter, WockyXmppStanza *stanza, +new_mail_handler (WockyPorter *porter, + WockyXmppStanza *stanza, gpointer user_data) { GabbleConnection *conn = user_data; + if (g_hash_table_size(conn->mail_subscribers) > 0) { DEBUG ("Got Google notification"); @@ -439,14 +479,18 @@ new_mail_handler (WockyPorter *porter, WockyXmppStanza *stanza, return TRUE; } + static void -connection_status_changed (GabbleConnection *conn, TpConnectionStatus status, - TpConnectionStatusReason reason, gpointer user_data) +connection_status_changed (GabbleConnection *conn, + TpConnectionStatus status, + TpConnectionStatusReason reason, + gpointer user_data) { if (status == TP_CONNECTION_STATUS_CONNECTED && conn->features & GABBLE_CONNECTION_FEATURES_GOOGLE_MAIL_NOTIFY) { DEBUG ("Connected, registering Google 'new-mail' notification"); + conn->new_mail_handler_id = wocky_porter_register_handler (wocky_session_get_porter (conn->session), WOCKY_STANZA_TYPE_IQ, WOCKY_STANZA_SUB_TYPE_SET, @@ -459,11 +503,13 @@ connection_status_changed (GabbleConnection *conn, TpConnectionStatus status, } } + void conn_mail_notif_init (GabbleConnection *conn) { GError *error = NULL; conn->daemon = tp_dbus_daemon_dup (&error); + if (!conn->daemon) { DEBUG ("Failed to connect to dbus daemon: %s", error->message); @@ -479,6 +525,7 @@ conn_mail_notif_init (GabbleConnection *conn) G_CALLBACK (connection_status_changed), conn); } + static gboolean foreach_cancel_watch (gpointer key, gpointer value, @@ -493,12 +540,13 @@ foreach_cancel_watch (gpointer key, return TRUE; } + void conn_mail_notif_dispose (GabbleConnection *conn) { if (conn->daemon) { - g_hash_table_foreach_remove (conn->mail_subscribers, + g_hash_table_foreach_remove (conn->mail_subscribers, foreach_cancel_watch, conn); g_hash_table_unref (conn->mail_subscribers); conn->mail_subscribers = NULL; @@ -522,7 +570,8 @@ conn_mail_notif_dispose (GabbleConnection *conn) void -conn_mail_notif_iface_init (gpointer g_iface, gpointer iface_data) +conn_mail_notif_iface_init (gpointer g_iface, + gpointer iface_data) { GabbleSvcConnectionInterfaceMailNotificationClass *klass = g_iface; @@ -533,12 +582,14 @@ conn_mail_notif_iface_init (gpointer g_iface, gpointer iface_data) #undef IMPLEMENT } -static GPtrArray* + +static GPtrArray * get_unread_mails (GabbleConnection *conn) { GPtrArray *mails = g_ptr_array_new (); GHashTableIter iter; gpointer value; + g_hash_table_iter_init (&iter, conn->unread_mails); while (g_hash_table_iter_next (&iter, NULL, &value)) { @@ -549,6 +600,7 @@ get_unread_mails (GabbleConnection *conn) return mails; } + void conn_mail_notif_properties_getter (GObject *object, GQuark interface, -- cgit v1.2.1 From 085cf5e6907bf150a3d68d036a1d58889f963272 Mon Sep 17 00:00:00 2001 From: Nicolas Dufresne Date: Thu, 24 Dec 2009 11:21:51 -0500 Subject: Mail Notification: Fix wrong cast and added object cast macro Signed-off-by: Nicolas Dufresne --- src/conn-mail-notif.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/conn-mail-notif.c b/src/conn-mail-notif.c index 0441228a0..e6245c789 100644 --- a/src/conn-mail-notif.c +++ b/src/conn-mail-notif.c @@ -70,7 +70,7 @@ sender_name_owner_changed (TpDBusDaemon *dbus_daemon, const gchar *new_owner, gpointer user_data) { - GabbleConnection *conn = user_data; + GabbleConnection *conn = GABBLE_CONNECTION (user_data); if (CHECK_STR_EMPTY (new_owner)) { @@ -435,7 +435,7 @@ query_unread_mails_cb (GObject *source_object, node = wocky_xmpp_node_get_child (reply->node, "mailbox"); if (node) { - GabbleConnection *conn = user_data; + GabbleConnection *conn = GABBLE_CONNECTION (user_data); store_unread_mails (conn, node); } @@ -469,7 +469,7 @@ new_mail_handler (WockyPorter *porter, WockyXmppStanza *stanza, gpointer user_data) { - GabbleConnection *conn = user_data; + GabbleConnection *conn = GABBLE_CONNECTION (user_data); if (g_hash_table_size(conn->mail_subscribers) > 0) { @@ -531,8 +531,8 @@ foreach_cancel_watch (gpointer key, gpointer value, gpointer user_data) { - GabbleConnection *conn = user_data; - const gchar *sender_name = user_data; + const gchar *sender_name = key; + GabbleConnection *conn = GABBLE_CONNECTION (user_data); tp_dbus_daemon_cancel_name_owner_watch (conn->daemon, sender_name, sender_name_owner_changed, conn); -- cgit v1.2.1 From a9a6f53a6b73f44ed1ca769e2a1005df08f48dea Mon Sep 17 00:00:00 2001 From: Nicolas Dufresne Date: Thu, 24 Dec 2009 11:28:14 -0500 Subject: Mail Notification: Fix memory leak on subcribe while already subscribed Signed-off-by: Nicolas Dufresne --- src/conn-mail-notif.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/conn-mail-notif.c b/src/conn-mail-notif.c index e6245c789..fa06941f3 100644 --- a/src/conn-mail-notif.c +++ b/src/conn-mail-notif.c @@ -125,6 +125,7 @@ gabble_mail_notification_subscribe (GabbleSvcConnectionInterfaceMailNotification if (g_hash_table_lookup_extended (conn->mail_subscribers, sender, NULL, NULL)) { DEBUG ("Sender '%s' is already subscribed!", sender); + g_free (sender); goto done; } -- cgit v1.2.1 From 63ceaaa6ce74910e7d9c1e5454fb9b6e562ea9e6 Mon Sep 17 00:00:00 2001 From: Nicolas Dufresne Date: Thu, 24 Dec 2009 11:38:28 -0500 Subject: Mail Notification: Highlight ownership passing with comments Signed-off-by: Nicolas Dufresne --- src/conn-mail-notif.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src') diff --git a/src/conn-mail-notif.c b/src/conn-mail-notif.c index fa06941f3..884819b27 100644 --- a/src/conn-mail-notif.c +++ b/src/conn-mail-notif.c @@ -129,6 +129,7 @@ gabble_mail_notification_subscribe (GabbleSvcConnectionInterfaceMailNotification goto done; } + /* Gives sender ownership to mail_subscribers hash table */ g_hash_table_insert (conn->mail_subscribers, sender, NULL); if (g_hash_table_size (conn->mail_subscribers) == 1) @@ -340,6 +341,7 @@ mail_thread_info_each (WockyXmppNode *node, handle_subject (node, mail, &dirty); handle_snippet (node, mail, &dirty); + /* gives tid ownership to unread_mails hash table */ g_hash_table_insert (data->unread_mails, tid, mail); if (dirty) g_ptr_array_add (data->mails_added, mail); -- cgit v1.2.1 From 7735cf7073d05bbebbdf99c942380ebcf8d959b4 Mon Sep 17 00:00:00 2001 From: Nicolas Dufresne Date: Thu, 24 Dec 2009 11:53:19 -0500 Subject: Mail Notification: More style fix and introduction comment on top Signed-off-by: Nicolas Dufresne --- src/conn-mail-notif.c | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/conn-mail-notif.c b/src/conn-mail-notif.c index 884819b27..4215b30d1 100644 --- a/src/conn-mail-notif.c +++ b/src/conn-mail-notif.c @@ -17,6 +17,15 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +/* This is implementation of Gmail Notification protocol as documented at + * http://code.google.com/intl/fr/apis/talk/jep_extensions/gmail.html + * This is the only protocol supported at the moment. To add new protocol, + * one would have to split the google specific parts wich are the + * update_unread_mails() function and the new-mail signal on google xml + * namespace. The data structure and suscription mechanism shall remain across + * protocols. + */ + #include "config.h" #include "conn-mail-notif.h" #include "namespaces.h" @@ -139,7 +148,8 @@ gabble_mail_notification_subscribe (GabbleSvcConnectionInterfaceMailNotification sender_name_owner_changed, conn, NULL); done: - gabble_svc_connection_interface_mail_notification_return_from_subscribe (context); + gabble_svc_connection_interface_mail_notification_return_from_subscribe ( + context); } @@ -182,10 +192,10 @@ handle_url (GHashTable *mail, { gchar *url; - /* The URL in result is broken. The th= parameter should be in hexadecimal - * but it's set in decimal. We could try and fix the string, but the URL does - * not point exactly where we expect it to point. Let's craft a different - * URL that do a better job.*/ + /* The URL in result is broken. The th= parameter should be in + * hexadecimal but it's set in decimal. We could try and fix the string, + * but the URL does not point exactly where we expect it to point. Let's + * craft a different URL that do a better job.*/ /* TODO Make sure we don't have to authenticate again */ @@ -360,10 +370,8 @@ store_unread_mails (GabbleConnection *conn, struct MailsHelperData data; const gchar *url; - data.unread_mails = g_hash_table_new_full (g_int64_hash, - g_int64_equal, - g_free, - (GDestroyNotify)g_hash_table_unref); + data.unread_mails = g_hash_table_new_full (g_int64_hash, g_int64_equal, + g_free, (GDestroyNotify) g_hash_table_unref); data.conn = conn; data.old_mails = conn->unread_mails; conn->unread_mails = data.unread_mails; @@ -372,7 +380,7 @@ store_unread_mails (GabbleConnection *conn, url = wocky_xmpp_node_get_attribute (mailbox, "url"); if (url && tp_strdiff (url, conn->inbox_url)) { - /* FIXME figure-out how to use POST data to garantee authentication */ + /* FIXME figure-out how to use POST data to guarantee authentication */ g_free (conn->inbox_url); conn->inbox_url = g_strdup (url); gabble_svc_connection_interface_mail_notification_emit_inbox_url_changed ( @@ -511,8 +519,8 @@ void conn_mail_notif_init (GabbleConnection *conn) { GError *error = NULL; - conn->daemon = tp_dbus_daemon_dup (&error); + conn->daemon = tp_dbus_daemon_dup (&error); if (!conn->daemon) { DEBUG ("Failed to connect to dbus daemon: %s", error->message); @@ -606,10 +614,10 @@ get_unread_mails (GabbleConnection *conn) void conn_mail_notif_properties_getter (GObject *object, - GQuark interface, - GQuark name, - GValue *value, - gpointer getter_data) + GQuark interface, + GQuark name, + GValue *value, + gpointer getter_data) { static GQuark prop_quarks[NUM_OF_PROP] = {0}; GabbleConnection *conn = GABBLE_CONNECTION (object); @@ -646,5 +654,5 @@ conn_mail_notif_properties_getter (GObject *object, g_ptr_array_free (mails, TRUE); } else - g_assert (!"Unkown mail notification property, please file a bug."); + g_assert (!"Unknown mail notification property, please file a bug."); } -- cgit v1.2.1 From 4818929192d43d8ae430e7948cd2c0dd05a66dbb Mon Sep 17 00:00:00 2001 From: Nicolas Dufresne Date: Tue, 5 Jan 2010 18:17:57 -0500 Subject: Disable all caps if server does not support mail notification Signed-off-by: Nicolas Dufresne --- src/conn-mail-notif.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/conn-mail-notif.c b/src/conn-mail-notif.c index 4215b30d1..c25a182bf 100644 --- a/src/conn-mail-notif.c +++ b/src/conn-mail-notif.c @@ -635,9 +635,14 @@ conn_mail_notif_properties_getter (GObject *object, DEBUG ("MailNotification get property %s", g_quark_to_string (name)); if (name == prop_quarks[PROP_CAPABILITIES]) - g_value_set_uint (value, - GABBLE_MAIL_NOTIFICATION_HAS_PROP_UNREADMAILCOUNT - | GABBLE_MAIL_NOTIFICATION_HAS_PROP_UNREADMAILS); + { + if (conn->features & GABBLE_CONNECTION_FEATURES_GOOGLE_MAIL_NOTIFY) + g_value_set_uint (value, + GABBLE_MAIL_NOTIFICATION_HAS_PROP_UNREADMAILCOUNT + | GABBLE_MAIL_NOTIFICATION_HAS_PROP_UNREADMAILS); + else + g_value_set_uint (value, 0); + } else if (name == prop_quarks[PROP_UNREAD_MAIL_COUNT]) g_value_set_uint (value, conn->unread_mails ? g_hash_table_size (conn->unread_mails) : 0); -- cgit v1.2.1 From eef551694132681ac23f83777ce43e607842ef3e Mon Sep 17 00:00:00 2001 From: Nicolas Dufresne Date: Tue, 5 Jan 2010 18:23:58 -0500 Subject: Don't crash when attribute unread_mails HashTable is NULL Signed-off-by: Nicolas Dufresne --- src/conn-mail-notif.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/conn-mail-notif.c b/src/conn-mail-notif.c index c25a182bf..138478ee2 100644 --- a/src/conn-mail-notif.c +++ b/src/conn-mail-notif.c @@ -601,11 +601,14 @@ get_unread_mails (GabbleConnection *conn) GHashTableIter iter; gpointer value; - g_hash_table_iter_init (&iter, conn->unread_mails); - while (g_hash_table_iter_next (&iter, NULL, &value)) + if (conn->unread_mails) { - GHashTable *mail = value; - g_ptr_array_add (mails, mail); + g_hash_table_iter_init (&iter, conn->unread_mails); + while (g_hash_table_iter_next (&iter, NULL, &value)) + { + GHashTable *mail = value; + g_ptr_array_add (mails, mail); + } } return mails; -- cgit v1.2.1 From c8fa090fc69c804bb88be54398e9541ee8f91027 Mon Sep 17 00:00:00 2001 From: Nicolas Dufresne Date: Fri, 8 Jan 2010 16:41:05 -0500 Subject: Ported Gabble Google Mail notification to new spec A modification was made to the Mail Notification spec to better support URL with authentication token. Also, mail id has been retyped to string for flexibility. Signed-off-by: Nicolas Dufresne --- src/conn-mail-notif.c | 161 ++++++++++++++++++++++++++++++-------------------- src/connection.c | 3 - 2 files changed, 98 insertions(+), 66 deletions(-) (limited to 'src') diff --git a/src/conn-mail-notif.c b/src/conn-mail-notif.c index 138478ee2..6400b4783 100644 --- a/src/conn-mail-notif.c +++ b/src/conn-mail-notif.c @@ -114,22 +114,32 @@ unsubscribe (GabbleConnection *conn, } +static inline gboolean +check_supported_or_dbus_return (GabbleConnection *conn, + DBusGMethodInvocation *context) +{ + if (!(conn->features & GABBLE_CONNECTION_FEATURES_GOOGLE_MAIL_NOTIFY)) + { + tp_dbus_g_method_return_not_implemented (context); + return TRUE; + } + return FALSE; +} + + static void gabble_mail_notification_subscribe (GabbleSvcConnectionInterfaceMailNotification *iface, DBusGMethodInvocation *context) { GabbleConnection *conn = GABBLE_CONNECTION (iface); - gchar *sender = dbus_g_method_get_sender (context); - - DEBUG ("Subscribe called by: %s", sender); + gchar *sender; - if (!(conn->features & GABBLE_CONNECTION_FEATURES_GOOGLE_MAIL_NOTIFY) - || !conn->daemon) - { - tp_dbus_g_method_return_not_implemented (context); - g_free (sender); + if (check_supported_or_dbus_return(conn, context)) return; - } + + sender = dbus_g_method_get_sender (context); + + DEBUG ("Subscribe called by: %s", sender); if (g_hash_table_lookup_extended (conn->mail_subscribers, sender, NULL, NULL)) { @@ -158,17 +168,14 @@ gabble_mail_notification_unsubscribe (GabbleSvcConnectionInterfaceMailNotificati DBusGMethodInvocation *context) { GabbleConnection *conn = GABBLE_CONNECTION (iface); - gchar *sender = dbus_g_method_get_sender (context); + gchar *sender; - DEBUG ("Unsubscribe called by: %s", sender); - - if (!(conn->features & GABBLE_CONNECTION_FEATURES_GOOGLE_MAIL_NOTIFY) - || !conn->daemon) - { - tp_dbus_g_method_return_not_implemented (context); - g_free (sender); + if (check_supported_or_dbus_return(conn, context)) return; - } + + sender = dbus_g_method_get_sender (context); + + DEBUG ("Unsubscribe called by: %s", sender); if (!g_hash_table_lookup_extended (conn->mail_subscribers, sender, NULL, NULL)) @@ -186,23 +193,65 @@ done: static void -handle_url (GHashTable *mail, - guint64 tid, - const gchar *base_url) +gabble_mail_notification_request_inbox_url ( + GabbleSvcConnectionInterfaceMailNotification *iface, + DBusGMethodInvocation *context) +{ + GabbleConnection *conn = GABBLE_CONNECTION (iface); + GValueArray *result; + + if (check_supported_or_dbus_return(conn, context)) + return; + + /* TODO Make sure we don't have to authenticate again */ + + result = tp_value_array_build (3, + G_TYPE_STRING, conn->inbox_url ?: "", + G_TYPE_UINT, GABBLE_HTTP_METHOD_GET, + GABBLE_ARRAY_TYPE_HTTP_POST_DATA_LIST, &empty_array, + G_TYPE_INVALID); + + gabble_svc_connection_interface_mail_notification_return_from_request_inbox_url ( + context, result); + + g_value_array_free (result); +} + + +static void +gabble_mail_notification_request_mail_url ( + GabbleSvcConnectionInterfaceMailNotification *iface, + const gchar *in_id, + const gchar *in_url_data, + DBusGMethodInvocation *context) { - gchar *url; + GabbleConnection *conn = GABBLE_CONNECTION (iface); + GValueArray *result; + gchar *url = NULL; - /* The URL in result is broken. The th= parameter should be in - * hexadecimal but it's set in decimal. We could try and fix the string, - * but the URL does not point exactly where we expect it to point. Let's - * craft a different URL that do a better job.*/ + if (check_supported_or_dbus_return(conn, context)) + return; /* TODO Make sure we don't have to authenticate again */ - url = g_strdup_printf ("%s/#inbox/%" G_GINT64_MODIFIER "x", base_url, tid); + if (conn->inbox_url) + { + guint64 tid = g_ascii_strtoull (in_id, NULL, 0); + url = g_strdup_printf ("%s/#inbox/%" G_GINT64_MODIFIER "x", + conn->inbox_url, tid); + } + + result = tp_value_array_build (3, + G_TYPE_STRING, url ?: "", + G_TYPE_UINT, GABBLE_HTTP_METHOD_GET, + GABBLE_ARRAY_TYPE_HTTP_POST_DATA_LIST, &empty_array, + G_TYPE_INVALID); + + gabble_svc_connection_interface_mail_notification_return_from_request_mail_url ( + context, result); + + g_value_array_free (result); - tp_asv_take_string (mail, "url", url); - tp_asv_set_uint32 (mail, "method", GABBLE_HTTP_METHOD_GET); } @@ -306,7 +355,7 @@ mail_thread_info_each (WockyXmppNode *node, { GHashTable *mail = NULL; const gchar *val_str; - guint64 *tid; + gchar *tid; gboolean dirty = FALSE; val_str = wocky_xmpp_node_get_attribute (node, "tid"); @@ -315,8 +364,7 @@ mail_thread_info_each (WockyXmppNode *node, if (!val_str) return TRUE; - tid = g_new (guint64, 1); - *tid = g_ascii_strtoull (val_str, NULL, 0); + tid = g_strdup (val_str); if (data->old_mails) mail = g_hash_table_lookup (data->old_mails, tid); @@ -328,8 +376,9 @@ mail_thread_info_each (WockyXmppNode *node, } else { - mail = tp_asv_new ("id", G_TYPE_UINT64, *tid, + mail = tp_asv_new ("id", G_TYPE_STRING, tid, "type", G_TYPE_UINT, GABBLE_MAIL_TYPE_THREAD, + "url_data", G_TYPE_STRING, "", NULL); dirty = TRUE; } @@ -346,7 +395,6 @@ mail_thread_info_each (WockyXmppNode *node, tp_asv_set_uint32 (mail, "received-timestamp", date); } - handle_url (mail, *tid, data->conn->inbox_url); handle_senders (node, mail, &dirty); handle_subject (node, mail, &dirty); handle_snippet (node, mail, &dirty); @@ -366,11 +414,11 @@ store_unread_mails (GabbleConnection *conn, WockyXmppNode *mailbox) { GHashTableIter iter; - GArray *mails_removed; + GPtrArray *mails_removed; struct MailsHelperData data; const gchar *url; - data.unread_mails = g_hash_table_new_full (g_int64_hash, g_int64_equal, + data.unread_mails = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) g_hash_table_unref); data.conn = conn; data.old_mails = conn->unread_mails; @@ -378,44 +426,38 @@ store_unread_mails (GabbleConnection *conn, data.mails_added = g_ptr_array_new (); url = wocky_xmpp_node_get_attribute (mailbox, "url"); - if (url && tp_strdiff (url, conn->inbox_url)) - { - /* FIXME figure-out how to use POST data to guarantee authentication */ - g_free (conn->inbox_url); - conn->inbox_url = g_strdup (url); - gabble_svc_connection_interface_mail_notification_emit_inbox_url_changed ( - conn, conn->inbox_url, GABBLE_HTTP_METHOD_GET, &empty_array); - } + g_free (conn->inbox_url); + conn->inbox_url = g_strdup (url); /* Store new mails */ wocky_xmpp_node_each_child (mailbox, mail_thread_info_each, &data); /* Generate the list of removed thread IDs */ + mails_removed = g_ptr_array_new_with_free_func (g_free); if (data.old_mails) { gpointer key; - mails_removed = g_array_sized_new (TRUE, TRUE, - sizeof (guint64), g_hash_table_size (data.old_mails)); - g_hash_table_iter_init (&iter, data.old_mails); while (g_hash_table_iter_next (&iter, &key, NULL)) { - guint64 tid = *((guint64*)key); - g_array_append_val (mails_removed, tid); + gchar *tid = key; + g_ptr_array_add (mails_removed, g_strdup (tid)); } g_hash_table_unref (data.old_mails); } - else - mails_removed = g_array_new (TRUE, TRUE, sizeof (guint64)); + g_ptr_array_add (mails_removed, NULL); if (data.mails_added->len || mails_removed->len) - gabble_svc_connection_interface_mail_notification_emit_unread_mails_changed (conn, - g_hash_table_size (conn->unread_mails), data.mails_added, mails_removed); + gabble_svc_connection_interface_mail_notification_emit_unread_mails_changed ( + conn, g_hash_table_size (conn->unread_mails), data.mails_added, + (const char **)mails_removed->pdata); + + DEBUG ("reached"); g_ptr_array_free (data.mails_added, TRUE); - g_array_free (mails_removed, TRUE); + g_ptr_array_free (mails_removed, TRUE); } @@ -590,6 +632,8 @@ conn_mail_notif_iface_init (gpointer g_iface, klass, gabble_mail_notification_##x) IMPLEMENT(subscribe); IMPLEMENT(unsubscribe); + IMPLEMENT(request_inbox_url); + IMPLEMENT(request_mail_url); #undef IMPLEMENT } @@ -629,9 +673,6 @@ conn_mail_notif_properties_getter (GObject *object, { prop_quarks[PROP_CAPABILITIES] = g_quark_from_static_string ("Capabilities"); prop_quarks[PROP_UNREAD_MAIL_COUNT] = g_quark_from_static_string ("UnreadMailCount"); - prop_quarks[PROP_INBOX_URL] = g_quark_from_static_string ("InboxURL"); - prop_quarks[PROP_METHOD] = g_quark_from_static_string ("Method"); - prop_quarks[PROP_POST_DATA] = g_quark_from_static_string ("PostData"); prop_quarks[PROP_UNREAD_MAILS] = g_quark_from_static_string ("UnreadMails"); } @@ -649,12 +690,6 @@ conn_mail_notif_properties_getter (GObject *object, else if (name == prop_quarks[PROP_UNREAD_MAIL_COUNT]) g_value_set_uint (value, conn->unread_mails ? g_hash_table_size (conn->unread_mails) : 0); - else if (name == prop_quarks[PROP_INBOX_URL]) - g_value_set_string (value, conn->inbox_url ?: ""); - else if (name == prop_quarks[PROP_METHOD]) - g_value_set_uint (value, GABBLE_HTTP_METHOD_GET); - else if (name == prop_quarks[PROP_POST_DATA]) - g_value_set_static_boxed (value, &empty_array); else if (name == prop_quarks[PROP_UNREAD_MAILS]) { GPtrArray *mails = get_unread_mails(conn); diff --git a/src/connection.c b/src/connection.c index 5859e6f9e..e4be148bf 100644 --- a/src/connection.c +++ b/src/connection.c @@ -731,9 +731,6 @@ gabble_connection_class_init (GabbleConnectionClass *gabble_connection_class) static TpDBusPropertiesMixinPropImpl mail_notif_props[] = { { "Capabilities", NULL, NULL }, { "UnreadMailCount", NULL, NULL }, - { "InboxURL", NULL, NULL }, - { "Method", NULL, NULL }, - { "PostData", NULL, NULL }, { "UnreadMails", NULL, NULL }, { NULL } }; -- cgit v1.2.1 From a20b89868b3ff53f02969e6b181475f53a57eeb3 Mon Sep 17 00:00:00 2001 From: Nicolas Dufresne Date: Wed, 27 Jan 2010 17:20:52 -0500 Subject: Bumped to latest MailNotification.DRAFT - Subscribe/Unsubscribe is now refcounted - Name or flags has been changed and flags exist for URL request - Mail "snippet" is now stored in "content" with "truncated set to TRUE - Mail "url_data" is now "url-data" - Timestamps are now 64 bit signed integer Signed-off-by: Nicolas Dufresne --- src/conn-mail-notif.c | 91 +++++++++++++++++++++++++++++---------------------- 1 file changed, 52 insertions(+), 39 deletions(-) (limited to 'src') diff --git a/src/conn-mail-notif.c b/src/conn-mail-notif.c index 6400b4783..f09f72121 100644 --- a/src/conn-mail-notif.c +++ b/src/conn-mail-notif.c @@ -50,9 +50,6 @@ enum { PROP_CAPABILITIES, PROP_UNREAD_MAIL_COUNT, - PROP_INBOX_URL, - PROP_METHOD, - PROP_POST_DATA, PROP_UNREAD_MAILS, NUM_OF_PROP, }; @@ -69,7 +66,8 @@ struct MailsHelperData static GPtrArray empty_array = { 0 }; -static void unsubscribe (GabbleConnection *conn, const gchar *name); +static void unsubscribe (GabbleConnection *conn, const gchar *name, + gboolean remove_all); static void update_unread_mails (GabbleConnection *conn); @@ -84,33 +82,44 @@ sender_name_owner_changed (TpDBusDaemon *dbus_daemon, if (CHECK_STR_EMPTY (new_owner)) { DEBUG ("Sender removed: %s", name); - unsubscribe (conn, name); + unsubscribe (conn, name, TRUE); } } static void unsubscribe (GabbleConnection *conn, - const gchar *name) + const gchar *name, gboolean remove_all) { - tp_dbus_daemon_cancel_name_owner_watch (conn->daemon, name, - sender_name_owner_changed, conn); + guint count; g_return_if_fail (g_hash_table_size (conn->mail_subscribers) > 0); - g_hash_table_remove (conn->mail_subscribers, name); + count = GPOINTER_TO_UINT ( + g_hash_table_lookup (conn->mail_subscribers, name)); - if (g_hash_table_size (conn->mail_subscribers) == 0) + if (count == 1 || remove_all) { - DEBUG ("Last sender unsubscribed, cleaning up!"); - g_free (conn->inbox_url); - conn->inbox_url = NULL; - if (conn->unread_mails) + tp_dbus_daemon_cancel_name_owner_watch (conn->daemon, name, + sender_name_owner_changed, conn); + + g_hash_table_remove (conn->mail_subscribers, name); + + if (g_hash_table_size (conn->mail_subscribers) == 0) { - g_hash_table_unref (conn->unread_mails); - conn->unread_mails = NULL; + DEBUG ("Last sender unsubscribed, cleaning up!"); + g_free (conn->inbox_url); + conn->inbox_url = NULL; + if (conn->unread_mails) + { + g_hash_table_unref (conn->unread_mails); + conn->unread_mails = NULL; + } } } + else + g_hash_table_insert (conn->mail_subscribers, g_strdup(name), + GUINT_TO_POINTER(--count)); } @@ -133,6 +142,7 @@ gabble_mail_notification_subscribe (GabbleSvcConnectionInterfaceMailNotification { GabbleConnection *conn = GABBLE_CONNECTION (iface); gchar *sender; + guint count; if (check_supported_or_dbus_return(conn, context)) return; @@ -141,23 +151,22 @@ gabble_mail_notification_subscribe (GabbleSvcConnectionInterfaceMailNotification DEBUG ("Subscribe called by: %s", sender); - if (g_hash_table_lookup_extended (conn->mail_subscribers, sender, NULL, NULL)) - { - DEBUG ("Sender '%s' is already subscribed!", sender); - g_free (sender); - goto done; - } + count = GPOINTER_TO_UINT ( + g_hash_table_lookup (conn->mail_subscribers, sender)); /* Gives sender ownership to mail_subscribers hash table */ - g_hash_table_insert (conn->mail_subscribers, sender, NULL); - - if (g_hash_table_size (conn->mail_subscribers) == 1) - update_unread_mails(conn); + g_hash_table_insert (conn->mail_subscribers, sender, + GUINT_TO_POINTER (++count)); - tp_dbus_daemon_watch_name_owner (conn->daemon, sender, - sender_name_owner_changed, conn, NULL); + if (count == 1) + { + if (g_hash_table_size (conn->mail_subscribers) == 1) + update_unread_mails(conn); + + tp_dbus_daemon_watch_name_owner (conn->daemon, sender, + sender_name_owner_changed, conn, NULL); + } -done: gabble_svc_connection_interface_mail_notification_return_from_subscribe ( context); } @@ -184,7 +193,7 @@ gabble_mail_notification_unsubscribe (GabbleSvcConnectionInterfaceMailNotificati goto done; } - unsubscribe (conn, sender); + unsubscribe (conn, sender, FALSE); done: g_free (sender); @@ -336,10 +345,11 @@ handle_snippet (WockyXmppNode *parent_node, node = wocky_xmpp_node_get_child (parent_node, "snippet"); if (node) { - if (tp_strdiff (node->content, tp_asv_get_string (mail, "snippet"))) + if (tp_strdiff (node->content, tp_asv_get_string (mail, "content"))) { *dirty = TRUE; - tp_asv_set_string (mail, "snippet", node->content); + tp_asv_set_boolean (mail, "truncated", TRUE); + tp_asv_set_string (mail, "content", node->content); } } } @@ -378,7 +388,7 @@ mail_thread_info_each (WockyXmppNode *node, { mail = tp_asv_new ("id", G_TYPE_STRING, tid, "type", G_TYPE_UINT, GABBLE_MAIL_TYPE_THREAD, - "url_data", G_TYPE_STRING, "", + "url-data", G_TYPE_STRING, "", NULL); dirty = TRUE; } @@ -386,13 +396,13 @@ mail_thread_info_each (WockyXmppNode *node, val_str = wocky_xmpp_node_get_attribute (node, "date"); if (val_str) { - guint date; + gint64 date; - date = (guint)(g_ascii_strtoull (val_str, NULL, 0) / 1000l); - if (date != tp_asv_get_uint32 (mail, "received-timestamp", NULL)) + date = (g_ascii_strtoll (val_str, NULL, 0) / 1000l); + if (date != tp_asv_get_int64 (mail, "received-timestamp", NULL)) dirty = TRUE; - tp_asv_set_uint32 (mail, "received-timestamp", date); + tp_asv_set_int64 (mail, "received-timestamp", date); } handle_senders (node, mail, &dirty); @@ -682,8 +692,11 @@ conn_mail_notif_properties_getter (GObject *object, { if (conn->features & GABBLE_CONNECTION_FEATURES_GOOGLE_MAIL_NOTIFY) g_value_set_uint (value, - GABBLE_MAIL_NOTIFICATION_HAS_PROP_UNREADMAILCOUNT - | GABBLE_MAIL_NOTIFICATION_HAS_PROP_UNREADMAILS); + GABBLE_MAIL_NOTIFICATION_SUPPORTS_UNREAD_MAIL_COUNT + | GABBLE_MAIL_NOTIFICATION_SUPPORTS_UNREAD_MAILS + | GABBLE_MAIL_NOTIFICATION_SUPPORTS_REQUEST_INBOX_URL + | GABBLE_MAIL_NOTIFICATION_SUPPORTS_REQUEST_MAIL_URL + ); else g_value_set_uint (value, 0); } -- cgit v1.2.1 From 61d654a21cdd76b3032dce4bf38dbcfff8ccb1ec Mon Sep 17 00:00:00 2001 From: Nicolas Dufresne Date: Mon, 22 Feb 2010 16:16:46 -0500 Subject: MailNotification.Subscribe/Unsubscribe can now return Disconnected error Signed-off-by: Nicolas Dufresne --- src/conn-mail-notif.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src') diff --git a/src/conn-mail-notif.c b/src/conn-mail-notif.c index f09f72121..0d57e128c 100644 --- a/src/conn-mail-notif.c +++ b/src/conn-mail-notif.c @@ -127,11 +127,19 @@ static inline gboolean check_supported_or_dbus_return (GabbleConnection *conn, DBusGMethodInvocation *context) { + if (TP_BASE_CONNECTION (conn)->status != TP_CONNECTION_STATUS_CONNECTED) + { + GError e = { TP_ERRORS, TP_ERROR_DISCONNECTED, "Not connected" }; + dbus_g_method_return_error (context, &e); + return TRUE; + } + if (!(conn->features & GABBLE_CONNECTION_FEATURES_GOOGLE_MAIL_NOTIFY)) { tp_dbus_g_method_return_not_implemented (context); return TRUE; } + return FALSE; } -- cgit v1.2.1 From 4ee285565ef75a1b75859eab53c2fa82c986bc92 Mon Sep 17 00:00:00 2001 From: Nicolas Dufresne Date: Mon, 22 Feb 2010 16:25:55 -0500 Subject: MailNotification.Unsubscribe now returns NotAvailable error Signed-off-by: Nicolas Dufresne --- src/conn-mail-notif.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/conn-mail-notif.c b/src/conn-mail-notif.c index 0d57e128c..3316f2b49 100644 --- a/src/conn-mail-notif.c +++ b/src/conn-mail-notif.c @@ -197,13 +197,17 @@ gabble_mail_notification_unsubscribe (GabbleSvcConnectionInterfaceMailNotificati if (!g_hash_table_lookup_extended (conn->mail_subscribers, sender, NULL, NULL)) { + GError e = { TP_ERRORS, TP_ERROR_NOT_AVAILABLE, "Not subscribed" }; + DEBUG ("Sender '%s' is not subscribed!", sender); - goto done; + + dbus_g_method_return_error (context, &e); + g_free (sender); + return; } unsubscribe (conn, sender, FALSE); -done: g_free (sender); gabble_svc_connection_interface_mail_notification_return_from_unsubscribe (context); } -- cgit v1.2.1 From 0d21034c6656a1d899eac4fbc1c3adf90c0c4e0e Mon Sep 17 00:00:00 2001 From: Nicolas Dufresne Date: Mon, 22 Feb 2010 16:50:59 -0500 Subject: Ported to latest version MailNotification Spec Major change is the property Capabilities renamed to MailNotificationFlags and the prefix for MailNotificationFlags now being MAIL_NOTIFICATION_FLAG. Other change are editorial changes. Signed-off-by: Nicolas Dufresne --- src/conn-mail-notif.c | 14 +++++++------- src/connection.c | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/conn-mail-notif.c b/src/conn-mail-notif.c index 3316f2b49..d277ba25a 100644 --- a/src/conn-mail-notif.c +++ b/src/conn-mail-notif.c @@ -48,7 +48,7 @@ enum { - PROP_CAPABILITIES, + PROP_MAIL_NOTIFICATION_FLAGS, PROP_UNREAD_MAIL_COUNT, PROP_UNREAD_MAILS, NUM_OF_PROP, @@ -693,21 +693,21 @@ conn_mail_notif_properties_getter (GObject *object, if (G_UNLIKELY (prop_quarks[0] == 0)) { - prop_quarks[PROP_CAPABILITIES] = g_quark_from_static_string ("Capabilities"); + prop_quarks[PROP_MAIL_NOTIFICATION_FLAGS] = g_quark_from_static_string ("MailNotificationFlags"); prop_quarks[PROP_UNREAD_MAIL_COUNT] = g_quark_from_static_string ("UnreadMailCount"); prop_quarks[PROP_UNREAD_MAILS] = g_quark_from_static_string ("UnreadMails"); } DEBUG ("MailNotification get property %s", g_quark_to_string (name)); - if (name == prop_quarks[PROP_CAPABILITIES]) + if (name == prop_quarks[PROP_MAIL_NOTIFICATION_FLAGS]) { if (conn->features & GABBLE_CONNECTION_FEATURES_GOOGLE_MAIL_NOTIFY) g_value_set_uint (value, - GABBLE_MAIL_NOTIFICATION_SUPPORTS_UNREAD_MAIL_COUNT - | GABBLE_MAIL_NOTIFICATION_SUPPORTS_UNREAD_MAILS - | GABBLE_MAIL_NOTIFICATION_SUPPORTS_REQUEST_INBOX_URL - | GABBLE_MAIL_NOTIFICATION_SUPPORTS_REQUEST_MAIL_URL + GABBLE_MAIL_NOTIFICATION_FLAG_SUPPORTS_UNREAD_MAIL_COUNT + | GABBLE_MAIL_NOTIFICATION_FLAG_SUPPORTS_UNREAD_MAILS + | GABBLE_MAIL_NOTIFICATION_FLAG_SUPPORTS_REQUEST_INBOX_URL + | GABBLE_MAIL_NOTIFICATION_FLAG_SUPPORTS_REQUEST_MAIL_URL ); else g_value_set_uint (value, 0); diff --git a/src/connection.c b/src/connection.c index e4be148bf..e3fd2b430 100644 --- a/src/connection.c +++ b/src/connection.c @@ -729,7 +729,7 @@ gabble_connection_class_init (GabbleConnectionClass *gabble_connection_class) { NULL } }; static TpDBusPropertiesMixinPropImpl mail_notif_props[] = { - { "Capabilities", NULL, NULL }, + { "MailNotificationFlags", NULL, NULL }, { "UnreadMailCount", NULL, NULL }, { "UnreadMails", NULL, NULL }, { NULL } -- cgit v1.2.1 From 4b8741b6898cddb85db4bc9aa4ddb2c3262df58b Mon Sep 17 00:00:00 2001 From: Nicolas Dufresne Date: Mon, 22 Feb 2010 18:25:39 -0500 Subject: Added MailAddress to MailNotification interface Signed-off-by: Nicolas Dufresne --- src/conn-mail-notif.c | 25 ++++++++++++++++++++++--- src/connection.c | 1 + 2 files changed, 23 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/conn-mail-notif.c b/src/conn-mail-notif.c index d277ba25a..6a2c70cc4 100644 --- a/src/conn-mail-notif.c +++ b/src/conn-mail-notif.c @@ -51,6 +51,7 @@ enum PROP_MAIL_NOTIFICATION_FLAGS, PROP_UNREAD_MAIL_COUNT, PROP_UNREAD_MAILS, + PROP_MAIL_ADDRESS, NUM_OF_PROP, }; @@ -693,9 +694,14 @@ conn_mail_notif_properties_getter (GObject *object, if (G_UNLIKELY (prop_quarks[0] == 0)) { - prop_quarks[PROP_MAIL_NOTIFICATION_FLAGS] = g_quark_from_static_string ("MailNotificationFlags"); - prop_quarks[PROP_UNREAD_MAIL_COUNT] = g_quark_from_static_string ("UnreadMailCount"); - prop_quarks[PROP_UNREAD_MAILS] = g_quark_from_static_string ("UnreadMails"); + prop_quarks[PROP_MAIL_NOTIFICATION_FLAGS] = + g_quark_from_static_string ("MailNotificationFlags"); + prop_quarks[PROP_UNREAD_MAIL_COUNT] = + g_quark_from_static_string ("UnreadMailCount"); + prop_quarks[PROP_UNREAD_MAILS] = + g_quark_from_static_string ("UnreadMails"); + prop_quarks[PROP_MAIL_ADDRESS] = + g_quark_from_static_string ("MailAddress"); } DEBUG ("MailNotification get property %s", g_quark_to_string (name)); @@ -721,6 +727,19 @@ conn_mail_notif_properties_getter (GObject *object, g_value_set_boxed (value, mails); g_ptr_array_free (mails, TRUE); } + else if (name == prop_quarks[PROP_MAIL_ADDRESS]) + { + gchar *address, *username, *stream_server; + + g_object_get (object, "username", &username, NULL); + g_object_get (object, "stream-server", &stream_server, NULL); + + address = gabble_encode_jid (username, stream_server, NULL); + + g_free (username); + g_free (stream_server); + g_value_take_string (value, address); + } else g_assert (!"Unknown mail notification property, please file a bug."); } diff --git a/src/connection.c b/src/connection.c index e3fd2b430..80c93d5a5 100644 --- a/src/connection.c +++ b/src/connection.c @@ -732,6 +732,7 @@ gabble_connection_class_init (GabbleConnectionClass *gabble_connection_class) { "MailNotificationFlags", NULL, NULL }, { "UnreadMailCount", NULL, NULL }, { "UnreadMails", NULL, NULL }, + { "MailAddress", NULL, NULL }, { NULL } }; static TpDBusPropertiesMixinIfaceImpl prop_interfaces[] = { -- cgit v1.2.1 From 4e675724217ece947e168bd9120f51100f3f67b6 Mon Sep 17 00:00:00 2001 From: Nicolas Dufresne Date: Thu, 25 Feb 2010 15:24:25 -0500 Subject: Update MailNotification Spec 0.19.1 The TP-Spec has been updated and uploaded upstream. The 'type' key of a Mail along with Mail_Type enumeration was replaced by a global MailNotificationFlag. Also, _request_mail_url() now receive a GValue instead of a string for url_data. Signed-off-by: Nicolas Dufresne --- src/conn-mail-notif.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/conn-mail-notif.c b/src/conn-mail-notif.c index 6a2c70cc4..128c6efdf 100644 --- a/src/conn-mail-notif.c +++ b/src/conn-mail-notif.c @@ -244,7 +244,7 @@ static void gabble_mail_notification_request_mail_url ( GabbleSvcConnectionInterfaceMailNotification *iface, const gchar *in_id, - const gchar *in_url_data, + const GValue *in_url_data, DBusGMethodInvocation *context) { GabbleConnection *conn = GABBLE_CONNECTION (iface); @@ -400,7 +400,6 @@ mail_thread_info_each (WockyXmppNode *node, else { mail = tp_asv_new ("id", G_TYPE_STRING, tid, - "type", G_TYPE_UINT, GABBLE_MAIL_TYPE_THREAD, "url-data", G_TYPE_STRING, "", NULL); dirty = TRUE; @@ -714,6 +713,7 @@ conn_mail_notif_properties_getter (GObject *object, | GABBLE_MAIL_NOTIFICATION_FLAG_SUPPORTS_UNREAD_MAILS | GABBLE_MAIL_NOTIFICATION_FLAG_SUPPORTS_REQUEST_INBOX_URL | GABBLE_MAIL_NOTIFICATION_FLAG_SUPPORTS_REQUEST_MAIL_URL + | GABBLE_MAIL_NOTIFICATION_FLAG_THREAD_BASED ); else g_value_set_uint (value, 0); -- cgit v1.2.1 From a6559438a3128e4a2c5d69880bca13bada15e481 Mon Sep 17 00:00:00 2001 From: Nicolas Dufresne Date: Wed, 24 Feb 2010 10:50:57 -0500 Subject: Removed trailing white space introduce by mail notification Signed-off-by: Nicolas Dufresne --- src/conn-mail-notif.c | 12 ++++++------ src/connection.c | 2 +- src/connection.h | 2 +- src/debug.c | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/conn-mail-notif.c b/src/conn-mail-notif.c index 128c6efdf..655fc9202 100644 --- a/src/conn-mail-notif.c +++ b/src/conn-mail-notif.c @@ -134,7 +134,7 @@ check_supported_or_dbus_return (GabbleConnection *conn, dbus_g_method_return_error (context, &e); return TRUE; } - + if (!(conn->features & GABBLE_CONNECTION_FEATURES_GOOGLE_MAIL_NOTIFY)) { tp_dbus_g_method_return_not_implemented (context); @@ -164,14 +164,14 @@ gabble_mail_notification_subscribe (GabbleSvcConnectionInterfaceMailNotification g_hash_table_lookup (conn->mail_subscribers, sender)); /* Gives sender ownership to mail_subscribers hash table */ - g_hash_table_insert (conn->mail_subscribers, sender, + g_hash_table_insert (conn->mail_subscribers, sender, GUINT_TO_POINTER (++count)); if (count == 1) { if (g_hash_table_size (conn->mail_subscribers) == 1) update_unread_mails(conn); - + tp_dbus_daemon_watch_name_owner (conn->daemon, sender, sender_name_owner_changed, conn, NULL); } @@ -232,7 +232,7 @@ gabble_mail_notification_request_inbox_url ( G_TYPE_UINT, GABBLE_HTTP_METHOD_GET, GABBLE_ARRAY_TYPE_HTTP_POST_DATA_LIST, &empty_array, G_TYPE_INVALID); - + gabble_svc_connection_interface_mail_notification_return_from_request_inbox_url ( context, result); @@ -473,7 +473,7 @@ store_unread_mails (GabbleConnection *conn, if (data.mails_added->len || mails_removed->len) gabble_svc_connection_interface_mail_notification_emit_unread_mails_changed ( - conn, g_hash_table_size (conn->unread_mails), data.mails_added, + conn, g_hash_table_size (conn->unread_mails), data.mails_added, (const char **)mails_removed->pdata); DEBUG ("reached"); @@ -733,7 +733,7 @@ conn_mail_notif_properties_getter (GObject *object, g_object_get (object, "username", &username, NULL); g_object_get (object, "stream-server", &stream_server, NULL); - + address = gabble_encode_jid (username, stream_server, NULL); g_free (username); diff --git a/src/connection.c b/src/connection.c index 80c93d5a5..562a84e1a 100644 --- a/src/connection.c +++ b/src/connection.c @@ -2581,7 +2581,7 @@ connection_disco_cb (GabbleDisco *disco, if (conn->features & GABBLE_CONNECTION_FEATURES_GOOGLE_MAIL_NOTIFY) { - const gchar *ifaces[] = + const gchar *ifaces[] = { GABBLE_IFACE_CONNECTION_INTERFACE_MAIL_NOTIFICATION, NULL }; tp_base_connection_add_interfaces ((TpBaseConnection *) conn, ifaces); diff --git a/src/connection.h b/src/connection.h index 4832588fd..ac25b9ac7 100644 --- a/src/connection.h +++ b/src/connection.h @@ -195,7 +195,7 @@ struct _GabbleConnection { gchar *inbox_url; GHashTable *unread_mails; guint new_mail_handler_id; - + GabbleConnectionPrivate *priv; }; diff --git a/src/debug.c b/src/debug.c index 53c884674..3091ee329 100644 --- a/src/debug.c +++ b/src/debug.c @@ -39,7 +39,7 @@ static GDebugKey keys[] = { { "search", GABBLE_DEBUG_SEARCH }, { "base-channel", GABBLE_DEBUG_BASE_CHANNEL }, { "plugins", GABBLE_DEBUG_PLUGINS }, - { "mail-notif", GABBLE_DEBUG_MAIL_NOTIF }, + { "mail-notif", GABBLE_DEBUG_MAIL_NOTIF }, { 0, }, }; -- cgit v1.2.1 From 2c0244173331ac271f7ae33e89f7b9f27dad0d85 Mon Sep 17 00:00:00 2001 From: Nicolas Dufresne Date: Wed, 24 Feb 2010 12:08:48 -0500 Subject: Renamed "mail-notif" debug section into "mail" Signed-off-by: Nicolas Dufresne --- src/debug.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/debug.c b/src/debug.c index 3091ee329..55d0f88dd 100644 --- a/src/debug.c +++ b/src/debug.c @@ -39,7 +39,7 @@ static GDebugKey keys[] = { { "search", GABBLE_DEBUG_SEARCH }, { "base-channel", GABBLE_DEBUG_BASE_CHANNEL }, { "plugins", GABBLE_DEBUG_PLUGINS }, - { "mail-notif", GABBLE_DEBUG_MAIL_NOTIF }, + { "mail", GABBLE_DEBUG_MAIL_NOTIF }, { 0, }, }; -- cgit v1.2.1 From 17689c956b8a75f260ec1265608c3a1e6b88befc Mon Sep 17 00:00:00 2001 From: Nicolas Dufresne Date: Wed, 24 Feb 2010 15:06:37 -0500 Subject: Replaced glib.h with glib-object.h in conn-mail-notif.h Signed-off-by: Nicolas Dufresne --- src/conn-mail-notif.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/conn-mail-notif.h b/src/conn-mail-notif.h index cfe9f3d3a..b1212e2bf 100644 --- a/src/conn-mail-notif.h +++ b/src/conn-mail-notif.h @@ -20,7 +20,7 @@ #ifndef __CONN_EMAIL_NOTIF_H__ #define __CONN_EMAIL_NOTIF_H__ -#include +#include #include "connection.h" -- cgit v1.2.1 From 73b70d450fc7decad161266c2a57c47cad8f355b Mon Sep 17 00:00:00 2001 From: Nicolas Dufresne Date: Wed, 24 Feb 2010 15:31:37 -0500 Subject: Fix conn-mail-notif.c headers ordering Signed-off-by: Nicolas Dufresne --- src/conn-mail-notif.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/conn-mail-notif.c b/src/conn-mail-notif.c index 655fc9202..ed3ef0cd0 100644 --- a/src/conn-mail-notif.c +++ b/src/conn-mail-notif.c @@ -27,22 +27,22 @@ */ #include "config.h" + #include "conn-mail-notif.h" -#include "namespaces.h" #include -#include "extensions/extensions.h" +#include +#include +#include #include #include -#include -#include -#include #define DEBUG_FLAG GABBLE_DEBUG_MAIL_NOTIF - #include "connection.h" #include "debug.h" +#include "extensions/extensions.h" +#include "namespaces.h" #include "util.h" -- cgit v1.2.1 From 8f2149dd2dd1d09b8154467a8573fdd8d97b824d Mon Sep 17 00:00:00 2001 From: Nicolas Dufresne Date: Wed, 24 Feb 2010 16:18:48 -0500 Subject: Fixed missing space before parenthesis in conn-mail-notif.c Signed-off-by: Nicolas Dufresne --- src/conn-mail-notif.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/conn-mail-notif.c b/src/conn-mail-notif.c index ed3ef0cd0..6fa10f5b6 100644 --- a/src/conn-mail-notif.c +++ b/src/conn-mail-notif.c @@ -119,8 +119,8 @@ unsubscribe (GabbleConnection *conn, } } else - g_hash_table_insert (conn->mail_subscribers, g_strdup(name), - GUINT_TO_POINTER(--count)); + g_hash_table_insert (conn->mail_subscribers, g_strdup (name), + GUINT_TO_POINTER (--count)); } @@ -153,7 +153,7 @@ gabble_mail_notification_subscribe (GabbleSvcConnectionInterfaceMailNotification gchar *sender; guint count; - if (check_supported_or_dbus_return(conn, context)) + if (check_supported_or_dbus_return (conn, context)) return; sender = dbus_g_method_get_sender (context); @@ -170,7 +170,7 @@ gabble_mail_notification_subscribe (GabbleSvcConnectionInterfaceMailNotification if (count == 1) { if (g_hash_table_size (conn->mail_subscribers) == 1) - update_unread_mails(conn); + update_unread_mails (conn); tp_dbus_daemon_watch_name_owner (conn->daemon, sender, sender_name_owner_changed, conn, NULL); @@ -188,7 +188,7 @@ gabble_mail_notification_unsubscribe (GabbleSvcConnectionInterfaceMailNotificati GabbleConnection *conn = GABBLE_CONNECTION (iface); gchar *sender; - if (check_supported_or_dbus_return(conn, context)) + if (check_supported_or_dbus_return (conn, context)) return; sender = dbus_g_method_get_sender (context); @@ -222,7 +222,7 @@ gabble_mail_notification_request_inbox_url ( GabbleConnection *conn = GABBLE_CONNECTION (iface); GValueArray *result; - if (check_supported_or_dbus_return(conn, context)) + if (check_supported_or_dbus_return (conn, context)) return; /* TODO Make sure we don't have to authenticate again */ @@ -251,7 +251,7 @@ gabble_mail_notification_request_mail_url ( GValueArray *result; gchar *url = NULL; - if (check_supported_or_dbus_return(conn, context)) + if (check_supported_or_dbus_return (conn, context)) return; /* TODO Make sure we don't have to authenticate again */ @@ -297,7 +297,7 @@ sender_each (WockyXmppNode *node, 1, wocky_xmpp_node_get_attribute (node, "address") ?: "", G_MAXUINT); - g_ptr_array_add (senders, g_value_get_boxed(&sender)); + g_ptr_array_add (senders, g_value_get_boxed (&sender)); g_value_unset (&sender); } return TRUE; @@ -546,7 +546,7 @@ new_mail_handler (WockyPorter *porter, { GabbleConnection *conn = GABBLE_CONNECTION (user_data); - if (g_hash_table_size(conn->mail_subscribers) > 0) + if (g_hash_table_size (conn->mail_subscribers) > 0) { DEBUG ("Got Google notification"); update_unread_mails (conn); @@ -652,10 +652,10 @@ conn_mail_notif_iface_init (gpointer g_iface, #define IMPLEMENT(x) gabble_svc_connection_interface_mail_notification_implement_##x (\ klass, gabble_mail_notification_##x) - IMPLEMENT(subscribe); - IMPLEMENT(unsubscribe); - IMPLEMENT(request_inbox_url); - IMPLEMENT(request_mail_url); + IMPLEMENT (subscribe); + IMPLEMENT (unsubscribe); + IMPLEMENT (request_inbox_url); + IMPLEMENT (request_mail_url); #undef IMPLEMENT } @@ -723,7 +723,7 @@ conn_mail_notif_properties_getter (GObject *object, conn->unread_mails ? g_hash_table_size (conn->unread_mails) : 0); else if (name == prop_quarks[PROP_UNREAD_MAILS]) { - GPtrArray *mails = get_unread_mails(conn); + GPtrArray *mails = get_unread_mails (conn); g_value_set_boxed (value, mails); g_ptr_array_free (mails, TRUE); } -- cgit v1.2.1 From f559057c3595d889c718c5b5d865586736fd6e41 Mon Sep 17 00:00:00 2001 From: Nicolas Dufresne Date: Wed, 24 Feb 2010 16:40:54 -0500 Subject: Add explicit comparison in conn-mail-notif.c Signed-off-by: Nicolas Dufresne --- src/conn-mail-notif.c | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/conn-mail-notif.c b/src/conn-mail-notif.c index 6fa10f5b6..eacb53a71 100644 --- a/src/conn-mail-notif.c +++ b/src/conn-mail-notif.c @@ -111,7 +111,7 @@ unsubscribe (GabbleConnection *conn, DEBUG ("Last sender unsubscribed, cleaning up!"); g_free (conn->inbox_url); conn->inbox_url = NULL; - if (conn->unread_mails) + if (conn->unread_mails != NULL) { g_hash_table_unref (conn->unread_mails); conn->unread_mails = NULL; @@ -256,7 +256,7 @@ gabble_mail_notification_request_mail_url ( /* TODO Make sure we don't have to authenticate again */ - if (conn->inbox_url) + if (conn->inbox_url != NULL) { guint64 tid = g_ascii_strtoull (in_id, NULL, 0); url = g_strdup_printf ("%s/#inbox/%" G_GINT64_MODIFIER "x", @@ -312,7 +312,7 @@ handle_senders (WockyXmppNode *parent_node, WockyXmppNode *node; node = wocky_xmpp_node_get_child (parent_node, "senders"); - if (node) + if (node != NULL) { GType addr_list_type = GABBLE_ARRAY_TYPE_MAIL_ADDRESS_LIST; GPtrArray *senders, *old_senders; @@ -321,7 +321,7 @@ handle_senders (WockyXmppNode *parent_node, wocky_xmpp_node_each_child (node, sender_each, senders); old_senders = tp_asv_get_boxed (mail, "senders", addr_list_type); - if (!old_senders || senders->len != old_senders->len) + if (old_senders == NULL || senders->len != old_senders->len) *dirty = TRUE; tp_asv_take_boxed (mail, "senders", addr_list_type, senders); @@ -337,7 +337,7 @@ handle_subject (WockyXmppNode *parent_node, WockyXmppNode *node; node = wocky_xmpp_node_get_child (parent_node, "subject"); - if (node) + if (node != NULL) { if (tp_strdiff (node->content, tp_asv_get_string (mail, "subject"))) { @@ -356,7 +356,7 @@ handle_snippet (WockyXmppNode *parent_node, WockyXmppNode *node; node = wocky_xmpp_node_get_child (parent_node, "snippet"); - if (node) + if (node != NULL) { if (tp_strdiff (node->content, tp_asv_get_string (mail, "content"))) { @@ -384,15 +384,15 @@ mail_thread_info_each (WockyXmppNode *node, val_str = wocky_xmpp_node_get_attribute (node, "tid"); /* We absolutly need an ID */ - if (!val_str) + if (val_str == NULL) return TRUE; tid = g_strdup (val_str); - if (data->old_mails) + if (data->old_mails != NULL) mail = g_hash_table_lookup (data->old_mails, tid); - if (mail) + if (mail != NULL) { g_hash_table_ref (mail); g_hash_table_remove (data->old_mails, tid); @@ -406,7 +406,7 @@ mail_thread_info_each (WockyXmppNode *node, } val_str = wocky_xmpp_node_get_attribute (node, "date"); - if (val_str) + if (val_str != NULL) { gint64 date; @@ -456,7 +456,7 @@ store_unread_mails (GabbleConnection *conn, /* Generate the list of removed thread IDs */ mails_removed = g_ptr_array_new_with_free_func (g_free); - if (data.old_mails) + if (data.old_mails != NULL) { gpointer key; @@ -471,7 +471,7 @@ store_unread_mails (GabbleConnection *conn, } g_ptr_array_add (mails_removed, NULL); - if (data.mails_added->len || mails_removed->len) + if (data.mails_added->len > 0 || mails_removed->len > 0) gabble_svc_connection_interface_mail_notification_emit_unread_mails_changed ( conn, g_hash_table_size (conn->unread_mails), data.mails_added, (const char **)mails_removed->pdata); @@ -494,7 +494,7 @@ query_unread_mails_cb (GObject *source_object, WockyPorter *porter = WOCKY_PORTER (source_object); WockyXmppStanza *reply = wocky_porter_send_iq_finish (porter, res, &error); - if (error) + if (error != NULL) { DEBUG ("Failed retreive unread emails information: %s", error->message); g_error_free (error); @@ -508,14 +508,14 @@ query_unread_mails_cb (GObject *source_object, g_free (result_str); node = wocky_xmpp_node_get_child (reply->node, "mailbox"); - if (node) + if (node != NULL) { GabbleConnection *conn = GABBLE_CONNECTION (user_data); store_unread_mails (conn, node); } end: - if (reply) + if (reply != NULL) g_object_unref (reply); } @@ -585,7 +585,7 @@ conn_mail_notif_init (GabbleConnection *conn) GError *error = NULL; conn->daemon = tp_dbus_daemon_dup (&error); - if (!conn->daemon) + if (conn->daemon == NULL) { DEBUG ("Failed to connect to dbus daemon: %s", error->message); g_error_free (error); @@ -619,7 +619,7 @@ foreach_cancel_watch (gpointer key, void conn_mail_notif_dispose (GabbleConnection *conn) { - if (conn->daemon) + if (conn->daemon != NULL) { g_hash_table_foreach_remove (conn->mail_subscribers, foreach_cancel_watch, conn); @@ -631,11 +631,11 @@ conn_mail_notif_dispose (GabbleConnection *conn) g_free (conn->inbox_url); conn->inbox_url = NULL; - if (conn->unread_mails) + if (conn->unread_mails != NULL) g_hash_table_unref (conn->unread_mails); conn->unread_mails = NULL; - if (conn->new_mail_handler_id) + if (conn->new_mail_handler_id != 0) { WockyPorter *porter = wocky_session_get_porter (conn->session); wocky_porter_unregister_handler (porter, conn->new_mail_handler_id); @@ -667,7 +667,7 @@ get_unread_mails (GabbleConnection *conn) GHashTableIter iter; gpointer value; - if (conn->unread_mails) + if (conn->unread_mails != NULL) { g_hash_table_iter_init (&iter, conn->unread_mails); while (g_hash_table_iter_next (&iter, NULL, &value)) -- cgit v1.2.1 From 6c5206aaf5eec550b20377e7da69295184a16d56 Mon Sep 17 00:00:00 2001 From: Nicolas Dufresne Date: Wed, 24 Feb 2010 16:48:07 -0500 Subject: conn-mail-notif.c: Add curly braces to "else", following coding style Signed-off-by: Nicolas Dufresne --- src/conn-mail-notif.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/conn-mail-notif.c b/src/conn-mail-notif.c index eacb53a71..9705ae7e9 100644 --- a/src/conn-mail-notif.c +++ b/src/conn-mail-notif.c @@ -119,8 +119,10 @@ unsubscribe (GabbleConnection *conn, } } else - g_hash_table_insert (conn->mail_subscribers, g_strdup (name), - GUINT_TO_POINTER (--count)); + { + g_hash_table_insert (conn->mail_subscribers, g_strdup (name), + GUINT_TO_POINTER (--count)); + } } @@ -719,8 +721,10 @@ conn_mail_notif_properties_getter (GObject *object, g_value_set_uint (value, 0); } else if (name == prop_quarks[PROP_UNREAD_MAIL_COUNT]) - g_value_set_uint (value, - conn->unread_mails ? g_hash_table_size (conn->unread_mails) : 0); + { + g_value_set_uint (value, + conn->unread_mails ? g_hash_table_size (conn->unread_mails) : 0); + } else if (name == prop_quarks[PROP_UNREAD_MAILS]) { GPtrArray *mails = get_unread_mails (conn); @@ -741,5 +745,7 @@ conn_mail_notif_properties_getter (GObject *object, g_value_take_string (value, address); } else - g_assert (!"Unknown mail notification property, please file a bug."); + { + g_assert (!"Unknown mail notification property, please file a bug."); + } } -- cgit v1.2.1 From ecd6ad3a3549249f0b7fa32a6920d54f2b599748 Mon Sep 17 00:00:00 2001 From: Nicolas Dufresne Date: Wed, 24 Feb 2010 16:57:15 -0500 Subject: Add blank lines around each if/while in conn-mail-notif.c Signed-off-by: Nicolas Dufresne --- src/conn-mail-notif.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src') diff --git a/src/conn-mail-notif.c b/src/conn-mail-notif.c index 9705ae7e9..054bdbe2c 100644 --- a/src/conn-mail-notif.c +++ b/src/conn-mail-notif.c @@ -111,6 +111,7 @@ unsubscribe (GabbleConnection *conn, DEBUG ("Last sender unsubscribed, cleaning up!"); g_free (conn->inbox_url); conn->inbox_url = NULL; + if (conn->unread_mails != NULL) { g_hash_table_unref (conn->unread_mails); @@ -323,6 +324,7 @@ handle_senders (WockyXmppNode *parent_node, wocky_xmpp_node_each_child (node, sender_each, senders); old_senders = tp_asv_get_boxed (mail, "senders", addr_list_type); + if (old_senders == NULL || senders->len != old_senders->len) *dirty = TRUE; @@ -408,6 +410,7 @@ mail_thread_info_each (WockyXmppNode *node, } val_str = wocky_xmpp_node_get_attribute (node, "date"); + if (val_str != NULL) { gint64 date; @@ -425,6 +428,7 @@ mail_thread_info_each (WockyXmppNode *node, /* gives tid ownership to unread_mails hash table */ g_hash_table_insert (data->unread_mails, tid, mail); + if (dirty) g_ptr_array_add (data->mails_added, mail); } @@ -458,11 +462,13 @@ store_unread_mails (GabbleConnection *conn, /* Generate the list of removed thread IDs */ mails_removed = g_ptr_array_new_with_free_func (g_free); + if (data.old_mails != NULL) { gpointer key; g_hash_table_iter_init (&iter, data.old_mails); + while (g_hash_table_iter_next (&iter, &key, NULL)) { gchar *tid = key; @@ -510,6 +516,7 @@ query_unread_mails_cb (GObject *source_object, g_free (result_str); node = wocky_xmpp_node_get_child (reply->node, "mailbox"); + if (node != NULL) { GabbleConnection *conn = GABBLE_CONNECTION (user_data); @@ -553,6 +560,7 @@ new_mail_handler (WockyPorter *porter, DEBUG ("Got Google notification"); update_unread_mails (conn); } + return TRUE; } @@ -587,6 +595,7 @@ conn_mail_notif_init (GabbleConnection *conn) GError *error = NULL; conn->daemon = tp_dbus_daemon_dup (&error); + if (conn->daemon == NULL) { DEBUG ("Failed to connect to dbus daemon: %s", error->message); @@ -633,8 +642,10 @@ conn_mail_notif_dispose (GabbleConnection *conn) g_free (conn->inbox_url); conn->inbox_url = NULL; + if (conn->unread_mails != NULL) g_hash_table_unref (conn->unread_mails); + conn->unread_mails = NULL; if (conn->new_mail_handler_id != 0) @@ -672,6 +683,7 @@ get_unread_mails (GabbleConnection *conn) if (conn->unread_mails != NULL) { g_hash_table_iter_init (&iter, conn->unread_mails); + while (g_hash_table_iter_next (&iter, NULL, &value)) { GHashTable *mail = value; -- cgit v1.2.1 From 8efbc0cc9970a6bf471398ae6013d3ea3080aea7 Mon Sep 17 00:00:00 2001 From: Nicolas Dufresne Date: Wed, 24 Feb 2010 16:58:44 -0500 Subject: Removed intl/fr from link to Google Mail extension doc Signed-off-by: Nicolas Dufresne --- src/conn-mail-notif.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/conn-mail-notif.c b/src/conn-mail-notif.c index 054bdbe2c..4429e341a 100644 --- a/src/conn-mail-notif.c +++ b/src/conn-mail-notif.c @@ -18,7 +18,7 @@ */ /* This is implementation of Gmail Notification protocol as documented at - * http://code.google.com/intl/fr/apis/talk/jep_extensions/gmail.html + * http://code.google.com/apis/talk/jep_extensions/gmail.html * This is the only protocol supported at the moment. To add new protocol, * one would have to split the google specific parts wich are the * update_unread_mails() function and the new-mail signal on google xml -- cgit v1.2.1 From 7d2eaf1f9007b95b53c753804bf5d2b769288ea1 Mon Sep 17 00:00:00 2001 From: Nicolas Dufresne Date: Wed, 24 Feb 2010 17:11:06 -0500 Subject: Remove static empty_array in conn-mail-notif.c Signed-off-by: Nicolas Dufresne --- src/conn-mail-notif.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/conn-mail-notif.c b/src/conn-mail-notif.c index 4429e341a..7a765d5dd 100644 --- a/src/conn-mail-notif.c +++ b/src/conn-mail-notif.c @@ -64,9 +64,6 @@ struct MailsHelperData }; -static GPtrArray empty_array = { 0 }; - - static void unsubscribe (GabbleConnection *conn, const gchar *name, gboolean remove_all); static void update_unread_mails (GabbleConnection *conn); @@ -224,22 +221,26 @@ gabble_mail_notification_request_inbox_url ( { GabbleConnection *conn = GABBLE_CONNECTION (iface); GValueArray *result; + GPtrArray *empty_array; if (check_supported_or_dbus_return (conn, context)) return; /* TODO Make sure we don't have to authenticate again */ + empty_array = g_ptr_array_new (); + result = tp_value_array_build (3, G_TYPE_STRING, conn->inbox_url ?: "", G_TYPE_UINT, GABBLE_HTTP_METHOD_GET, - GABBLE_ARRAY_TYPE_HTTP_POST_DATA_LIST, &empty_array, + GABBLE_ARRAY_TYPE_HTTP_POST_DATA_LIST, empty_array, G_TYPE_INVALID); gabble_svc_connection_interface_mail_notification_return_from_request_inbox_url ( context, result); g_value_array_free (result); + g_ptr_array_free (empty_array, TRUE); } @@ -253,6 +254,7 @@ gabble_mail_notification_request_mail_url ( GabbleConnection *conn = GABBLE_CONNECTION (iface); GValueArray *result; gchar *url = NULL; + GPtrArray *empty_array; if (check_supported_or_dbus_return (conn, context)) return; @@ -266,17 +268,19 @@ gabble_mail_notification_request_mail_url ( conn->inbox_url, tid); } + empty_array = g_ptr_array_new (); + result = tp_value_array_build (3, G_TYPE_STRING, url ?: "", G_TYPE_UINT, GABBLE_HTTP_METHOD_GET, - GABBLE_ARRAY_TYPE_HTTP_POST_DATA_LIST, &empty_array, + GABBLE_ARRAY_TYPE_HTTP_POST_DATA_LIST, empty_array, G_TYPE_INVALID); gabble_svc_connection_interface_mail_notification_return_from_request_mail_url ( context, result); g_value_array_free (result); - + g_ptr_array_free (empty_array, TRUE); } -- cgit v1.2.1 From 8486e8b712facf6188386b39e401c07da587a15c Mon Sep 17 00:00:00 2001 From: Nicolas Dufresne Date: Wed, 24 Feb 2010 17:39:42 -0500 Subject: Removed unneeded debug output in conn-mail-notif.c Signed-off-by: Nicolas Dufresne --- src/conn-mail-notif.c | 7 ------- 1 file changed, 7 deletions(-) (limited to 'src') diff --git a/src/conn-mail-notif.c b/src/conn-mail-notif.c index 7a765d5dd..8218666f4 100644 --- a/src/conn-mail-notif.c +++ b/src/conn-mail-notif.c @@ -488,8 +488,6 @@ store_unread_mails (GabbleConnection *conn, conn, g_hash_table_size (conn->unread_mails), data.mails_added, (const char **)mails_removed->pdata); - DEBUG ("reached"); - g_ptr_array_free (data.mails_added, TRUE); g_ptr_array_free (mails_removed, TRUE); } @@ -501,7 +499,6 @@ query_unread_mails_cb (GObject *source_object, gpointer user_data) { GError *error = NULL; - gchar *result_str; WockyXmppNode *node; WockyPorter *porter = WOCKY_PORTER (source_object); WockyXmppStanza *reply = wocky_porter_send_iq_finish (porter, res, &error); @@ -515,10 +512,6 @@ query_unread_mails_cb (GObject *source_object, DEBUG ("Got unread mail details"); - result_str = wocky_xmpp_node_to_string (reply->node); - DEBUG ("%s", result_str); - g_free (result_str); - node = wocky_xmpp_node_get_child (reply->node, "mailbox"); if (node != NULL) -- cgit v1.2.1 From 90f889a2a7091df1cc22e8653957e255cf69021f Mon Sep 17 00:00:00 2001 From: Nicolas Dufresne Date: Wed, 24 Feb 2010 17:47:44 -0500 Subject: Use g_hash_table_steal () in conn-mail-notif.c Signed-off-by: Nicolas Dufresne --- src/conn-mail-notif.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/conn-mail-notif.c b/src/conn-mail-notif.c index 8218666f4..7235a6041 100644 --- a/src/conn-mail-notif.c +++ b/src/conn-mail-notif.c @@ -398,14 +398,12 @@ mail_thread_info_each (WockyXmppNode *node, tid = g_strdup (val_str); if (data->old_mails != NULL) - mail = g_hash_table_lookup (data->old_mails, tid); - - if (mail != NULL) { - g_hash_table_ref (mail); - g_hash_table_remove (data->old_mails, tid); + mail = g_hash_table_lookup (data->old_mails, tid); + g_hash_table_steal (data->old_mails, tid); } - else + + if (mail == NULL) { mail = tp_asv_new ("id", G_TYPE_STRING, tid, "url-data", G_TYPE_STRING, "", -- cgit v1.2.1 From eb7322589438fec6cc8faa375e3c347266075a2b Mon Sep 17 00:00:00 2001 From: Nicolas Dufresne Date: Wed, 24 Feb 2010 17:55:34 -0500 Subject: Use return value instead of in/out param in conn-mail-notif.c Signed-off-by: Nicolas Dufresne --- src/conn-mail-notif.c | 41 ++++++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/conn-mail-notif.c b/src/conn-mail-notif.c index 7235a6041..2705a6cf5 100644 --- a/src/conn-mail-notif.c +++ b/src/conn-mail-notif.c @@ -311,11 +311,11 @@ sender_each (WockyXmppNode *node, } -static void +static gboolean handle_senders (WockyXmppNode *parent_node, - GHashTable *mail, - gboolean *dirty) + GHashTable *mail) { + gboolean dirty = FALSE; WockyXmppNode *node; node = wocky_xmpp_node_get_child (parent_node, "senders"); @@ -330,18 +330,20 @@ handle_senders (WockyXmppNode *parent_node, old_senders = tp_asv_get_boxed (mail, "senders", addr_list_type); if (old_senders == NULL || senders->len != old_senders->len) - *dirty = TRUE; + dirty = TRUE; tp_asv_take_boxed (mail, "senders", addr_list_type, senders); } + + return dirty; } -static void +static gboolean handle_subject (WockyXmppNode *parent_node, - GHashTable *mail, - gboolean *dirty) + GHashTable *mail) { + gboolean dirty = FALSE; WockyXmppNode *node; node = wocky_xmpp_node_get_child (parent_node, "subject"); @@ -349,18 +351,20 @@ handle_subject (WockyXmppNode *parent_node, { if (tp_strdiff (node->content, tp_asv_get_string (mail, "subject"))) { - *dirty = TRUE; + dirty = TRUE; tp_asv_set_string (mail, "subject", node->content); } } + + return dirty; } -static void +static gboolean handle_snippet (WockyXmppNode *parent_node, - GHashTable *mail, - gboolean *dirty) + GHashTable *mail) { + gboolean dirty = FALSE; WockyXmppNode *node; node = wocky_xmpp_node_get_child (parent_node, "snippet"); @@ -368,11 +372,13 @@ handle_snippet (WockyXmppNode *parent_node, { if (tp_strdiff (node->content, tp_asv_get_string (mail, "content"))) { - *dirty = TRUE; + dirty = TRUE; tp_asv_set_boolean (mail, "truncated", TRUE); tp_asv_set_string (mail, "content", node->content); } } + + return dirty; } @@ -424,9 +430,14 @@ mail_thread_info_each (WockyXmppNode *node, tp_asv_set_int64 (mail, "received-timestamp", date); } - handle_senders (node, mail, &dirty); - handle_subject (node, mail, &dirty); - handle_snippet (node, mail, &dirty); + if (handle_senders (node, mail)) + dirty = TRUE; + + if (handle_subject (node, mail)) + dirty = TRUE; + + if (handle_snippet (node, mail)) + dirty = TRUE; /* gives tid ownership to unread_mails hash table */ g_hash_table_insert (data->unread_mails, tid, mail); -- cgit v1.2.1 From 567e11173b056021474920fe06d54ff3391a5687 Mon Sep 17 00:00:00 2001 From: Nicolas Dufresne Date: Wed, 24 Feb 2010 18:02:03 -0500 Subject: Just use g_assert_not_reached() in conn-mail-notif.c property getter Signed-off-by: Nicolas Dufresne --- src/conn-mail-notif.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/conn-mail-notif.c b/src/conn-mail-notif.c index 2705a6cf5..b67a4a0af 100644 --- a/src/conn-mail-notif.c +++ b/src/conn-mail-notif.c @@ -764,6 +764,6 @@ conn_mail_notif_properties_getter (GObject *object, } else { - g_assert (!"Unknown mail notification property, please file a bug."); + g_assert_not_reached (); } } -- cgit v1.2.1 From 7cb1dfee34c2d4d291e25716bcf6d46a8a2104d9 Mon Sep 17 00:00:00 2001 From: Nicolas Dufresne Date: Wed, 24 Feb 2010 18:21:59 -0500 Subject: Explain why we convert Mail id from decimal to hexadecimal Signed-off-by: Nicolas Dufresne --- src/conn-mail-notif.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/conn-mail-notif.c b/src/conn-mail-notif.c index b67a4a0af..8186d79cd 100644 --- a/src/conn-mail-notif.c +++ b/src/conn-mail-notif.c @@ -263,6 +263,7 @@ gabble_mail_notification_request_mail_url ( if (conn->inbox_url != NULL) { + /* IDs are decimal on the XMPP side and hexadecimal on the wemail side. */ guint64 tid = g_ascii_strtoull (in_id, NULL, 0); url = g_strdup_printf ("%s/#inbox/%" G_GINT64_MODIFIER "x", conn->inbox_url, tid); -- cgit v1.2.1 From c57c0ba99d025b9bcca2ff7815650373f4722135 Mon Sep 17 00:00:00 2001 From: Nicolas Dufresne Date: Wed, 24 Feb 2010 18:46:55 -0500 Subject: Use g_error if we cannot allocate TpDBusDaemon Signed-off-by: Nicolas Dufresne --- src/conn-mail-notif.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src') diff --git a/src/conn-mail-notif.c b/src/conn-mail-notif.c index 8186d79cd..76d3251ac 100644 --- a/src/conn-mail-notif.c +++ b/src/conn-mail-notif.c @@ -605,8 +605,7 @@ conn_mail_notif_init (GabbleConnection *conn) if (conn->daemon == NULL) { - DEBUG ("Failed to connect to dbus daemon: %s", error->message); - g_error_free (error); + g_error ("Failed to connect to dbus daemon: %s", error->message); } conn->mail_subscribers = g_hash_table_new_full (g_str_hash, g_str_equal, -- cgit v1.2.1 From 8cb822743f7cdf225750591f476908e0b1277cac Mon Sep 17 00:00:00 2001 From: Nicolas Dufresne Date: Wed, 24 Feb 2010 19:06:50 -0500 Subject: Don't use GNU extension operator ?: in conn-mail-notif.c Signed-off-by: Nicolas Dufresne --- src/conn-mail-notif.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/conn-mail-notif.c b/src/conn-mail-notif.c index 76d3251ac..4d7bc6d37 100644 --- a/src/conn-mail-notif.c +++ b/src/conn-mail-notif.c @@ -231,7 +231,7 @@ gabble_mail_notification_request_inbox_url ( empty_array = g_ptr_array_new (); result = tp_value_array_build (3, - G_TYPE_STRING, conn->inbox_url ?: "", + G_TYPE_STRING, conn->inbox_url ? conn->inbox_url : "", G_TYPE_UINT, GABBLE_HTTP_METHOD_GET, GABBLE_ARRAY_TYPE_HTTP_POST_DATA_LIST, empty_array, G_TYPE_INVALID); @@ -272,7 +272,7 @@ gabble_mail_notification_request_mail_url ( empty_array = g_ptr_array_new (); result = tp_value_array_build (3, - G_TYPE_STRING, url ?: "", + G_TYPE_STRING, url ? url : "", G_TYPE_UINT, GABBLE_HTTP_METHOD_GET, GABBLE_ARRAY_TYPE_HTTP_POST_DATA_LIST, empty_array, G_TYPE_INVALID); @@ -295,14 +295,26 @@ sender_each (WockyXmppNode *node, { GType addr_type = GABBLE_STRUCT_TYPE_MAIL_ADDRESS; GValue sender = {0}; + const gchar *name; + const gchar *address; g_value_init (&sender, addr_type); g_value_set_static_boxed (&sender, dbus_g_type_specialized_construct (addr_type)); + name = wocky_xmpp_node_get_attribute (node, "name"); + + if (name == NULL) + name = ""; + + address = wocky_xmpp_node_get_attribute (node, "address"); + + if (address == NULL) + address = ""; + dbus_g_type_struct_set (&sender, - 0, wocky_xmpp_node_get_attribute (node, "name") ?: "", - 1, wocky_xmpp_node_get_attribute (node, "address") ?: "", + 0, name, + 1, address, G_MAXUINT); g_ptr_array_add (senders, g_value_get_boxed (&sender)); -- cgit v1.2.1 From 96f95e65e15ac4982846a6ef584588fbb3a4e005 Mon Sep 17 00:00:00 2001 From: Nicolas Dufresne Date: Wed, 24 Feb 2010 19:15:44 -0500 Subject: User subscriber instead of sender for var name in conn-mail-notif.c sender was confusing variable name since it is used has one of the mail attributes in mail hash table. Signed-off-by: Nicolas Dufresne --- src/conn-mail-notif.c | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) (limited to 'src') diff --git a/src/conn-mail-notif.c b/src/conn-mail-notif.c index 4d7bc6d37..fb2a74a53 100644 --- a/src/conn-mail-notif.c +++ b/src/conn-mail-notif.c @@ -70,7 +70,7 @@ static void update_unread_mails (GabbleConnection *conn); static void -sender_name_owner_changed (TpDBusDaemon *dbus_daemon, +subscriber_name_owner_changed (TpDBusDaemon *dbus_daemon, const gchar *name, const gchar *new_owner, gpointer user_data) @@ -99,13 +99,13 @@ unsubscribe (GabbleConnection *conn, if (count == 1 || remove_all) { tp_dbus_daemon_cancel_name_owner_watch (conn->daemon, name, - sender_name_owner_changed, conn); + subscriber_name_owner_changed, conn); g_hash_table_remove (conn->mail_subscribers, name); if (g_hash_table_size (conn->mail_subscribers) == 0) { - DEBUG ("Last sender unsubscribed, cleaning up!"); + DEBUG ("Last subscriber unsubscribed, cleaning up!"); g_free (conn->inbox_url); conn->inbox_url = NULL; @@ -150,21 +150,21 @@ gabble_mail_notification_subscribe (GabbleSvcConnectionInterfaceMailNotification DBusGMethodInvocation *context) { GabbleConnection *conn = GABBLE_CONNECTION (iface); - gchar *sender; + gchar *subscriber; guint count; if (check_supported_or_dbus_return (conn, context)) return; - sender = dbus_g_method_get_sender (context); + subscriber = dbus_g_method_get_sender (context); - DEBUG ("Subscribe called by: %s", sender); + DEBUG ("Subscribe called by: %s", subscriber); count = GPOINTER_TO_UINT ( - g_hash_table_lookup (conn->mail_subscribers, sender)); + g_hash_table_lookup (conn->mail_subscribers, subscriber)); - /* Gives sender ownership to mail_subscribers hash table */ - g_hash_table_insert (conn->mail_subscribers, sender, + /* Gives subscriber ownership to mail_subscribers hash table */ + g_hash_table_insert (conn->mail_subscribers, subscriber, GUINT_TO_POINTER (++count)); if (count == 1) @@ -172,8 +172,8 @@ gabble_mail_notification_subscribe (GabbleSvcConnectionInterfaceMailNotification if (g_hash_table_size (conn->mail_subscribers) == 1) update_unread_mails (conn); - tp_dbus_daemon_watch_name_owner (conn->daemon, sender, - sender_name_owner_changed, conn, NULL); + tp_dbus_daemon_watch_name_owner (conn->daemon, subscriber, + subscriber_name_owner_changed, conn, NULL); } gabble_svc_connection_interface_mail_notification_return_from_subscribe ( @@ -186,30 +186,30 @@ gabble_mail_notification_unsubscribe (GabbleSvcConnectionInterfaceMailNotificati DBusGMethodInvocation *context) { GabbleConnection *conn = GABBLE_CONNECTION (iface); - gchar *sender; + gchar *subscriber; if (check_supported_or_dbus_return (conn, context)) return; - sender = dbus_g_method_get_sender (context); + subscriber = dbus_g_method_get_sender (context); - DEBUG ("Unsubscribe called by: %s", sender); + DEBUG ("Unsubscribe called by: %s", subscriber); - if (!g_hash_table_lookup_extended (conn->mail_subscribers, sender, + if (!g_hash_table_lookup_extended (conn->mail_subscribers, subscriber, NULL, NULL)) { GError e = { TP_ERRORS, TP_ERROR_NOT_AVAILABLE, "Not subscribed" }; - DEBUG ("Sender '%s' is not subscribed!", sender); + DEBUG ("Subscriber '%s' is not subscribed!", subscriber); dbus_g_method_return_error (context, &e); - g_free (sender); + g_free (subscriber); return; } - unsubscribe (conn, sender, FALSE); + unsubscribe (conn, subscriber, FALSE); - g_free (sender); + g_free (subscriber); gabble_svc_connection_interface_mail_notification_return_from_unsubscribe (context); } @@ -635,11 +635,11 @@ foreach_cancel_watch (gpointer key, gpointer value, gpointer user_data) { - const gchar *sender_name = key; + const gchar *subscriber = key; GabbleConnection *conn = GABBLE_CONNECTION (user_data); tp_dbus_daemon_cancel_name_owner_watch (conn->daemon, - sender_name, sender_name_owner_changed, conn); + subscriber, subscriber_name_owner_changed, conn); return TRUE; } -- cgit v1.2.1 From c7f2abcb7512560d6e5f1830c8caad28c90ecc14 Mon Sep 17 00:00:00 2001 From: Nicolas Dufresne Date: Thu, 25 Feb 2010 14:31:24 -0500 Subject: Use SelfHandle instead of username@stream_server MailAddress Signed-off-by: Nicolas Dufresne --- src/conn-mail-notif.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/conn-mail-notif.c b/src/conn-mail-notif.c index fb2a74a53..3a44f69e4 100644 --- a/src/conn-mail-notif.c +++ b/src/conn-mail-notif.c @@ -763,16 +763,15 @@ conn_mail_notif_properties_getter (GObject *object, } else if (name == prop_quarks[PROP_MAIL_ADDRESS]) { - gchar *address, *username, *stream_server; - - g_object_get (object, "username", &username, NULL); - g_object_get (object, "stream-server", &stream_server, NULL); - - address = gabble_encode_jid (username, stream_server, NULL); - - g_free (username); - g_free (stream_server); - g_value_take_string (value, address); + TpBaseConnection *base = TP_BASE_CONNECTION (object); + TpHandleRepoIface *contact_handles = + tp_base_connection_get_handles (base, TP_HANDLE_TYPE_CONTACT); + TpHandle self = tp_base_connection_get_self_handle (base); + const gchar *bare_jid = tp_handle_inspect (contact_handles, self); + + /* After some testing I found that the bare jid (username@stream_server) + * always represent the e-mail address on Google account. */ + g_value_set_string (value, bare_jid); } else { -- cgit v1.2.1 From 35909d9d4fbef4ac60752481efd6722eb6819326 Mon Sep 17 00:00:00 2001 From: Nicolas Dufresne Date: Thu, 25 Feb 2010 15:32:24 -0500 Subject: Fixed copyright year to include 2010 Signed-off-by: Nicolas Dufresne --- src/conn-mail-notif.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/conn-mail-notif.c b/src/conn-mail-notif.c index 3a44f69e4..e1c41db2b 100644 --- a/src/conn-mail-notif.c +++ b/src/conn-mail-notif.c @@ -1,6 +1,6 @@ /* * conn-mail-notif - Gabble mail notification interface - * Copyright (C) 2009 Collabora Ltd. + * Copyright (C) 2009-2010 Collabora Ltd. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public -- cgit v1.2.1 From a77a14a07d31adc4307ea4e45de789d5c1170e58 Mon Sep 17 00:00:00 2001 From: Nicolas Dufresne Date: Thu, 25 Feb 2010 15:48:33 -0500 Subject: Renamed structure MailsHelperData into MailThreadCollector Also removed useless member unread_mails witch can already be accessed inside conn member. Signed-off-by: Nicolas Dufresne --- src/conn-mail-notif.c | 55 ++++++++++++++++++++++++++------------------------- 1 file changed, 28 insertions(+), 27 deletions(-) (limited to 'src') diff --git a/src/conn-mail-notif.c b/src/conn-mail-notif.c index e1c41db2b..2df6d710f 100644 --- a/src/conn-mail-notif.c +++ b/src/conn-mail-notif.c @@ -55,14 +55,6 @@ enum NUM_OF_PROP, }; -struct MailsHelperData -{ - GabbleConnection *conn; - GHashTable *unread_mails; - GHashTable *old_mails; - GPtrArray *mails_added; -}; - static void unsubscribe (GabbleConnection *conn, const gchar *name, gboolean remove_all); @@ -395,11 +387,21 @@ handle_snippet (WockyXmppNode *parent_node, } +/* Structure used has user_data mail_thread_info_each callback */ +typedef struct +{ + GabbleConnection *conn; + /* stolen from conn -> unread_mails, the left items in this is + * represent the removed emails */ + GHashTable *old_mails; + GPtrArray *mails_added; +} MailThreadCollector; + static gboolean mail_thread_info_each (WockyXmppNode *node, gpointer user_data) { - struct MailsHelperData *data = user_data; + MailThreadCollector *collector = user_data; if (!tp_strdiff (node->name, "mail-thread-info")) { @@ -416,10 +418,10 @@ mail_thread_info_each (WockyXmppNode *node, tid = g_strdup (val_str); - if (data->old_mails != NULL) + if (collector->old_mails != NULL) { - mail = g_hash_table_lookup (data->old_mails, tid); - g_hash_table_steal (data->old_mails, tid); + mail = g_hash_table_lookup (collector->old_mails, tid); + g_hash_table_steal (collector->old_mails, tid); } if (mail == NULL) @@ -453,10 +455,10 @@ mail_thread_info_each (WockyXmppNode *node, dirty = TRUE; /* gives tid ownership to unread_mails hash table */ - g_hash_table_insert (data->unread_mails, tid, mail); + g_hash_table_insert (collector->conn->unread_mails, tid, mail); if (dirty) - g_ptr_array_add (data->mails_added, mail); + g_ptr_array_add (collector->mails_added, mail); } return TRUE; @@ -469,31 +471,30 @@ store_unread_mails (GabbleConnection *conn, { GHashTableIter iter; GPtrArray *mails_removed; - struct MailsHelperData data; + MailThreadCollector collector; const gchar *url; - data.unread_mails = g_hash_table_new_full (g_str_hash, g_str_equal, + collector.conn = conn; + collector.old_mails = conn->unread_mails; + conn->unread_mails = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) g_hash_table_unref); - data.conn = conn; - data.old_mails = conn->unread_mails; - conn->unread_mails = data.unread_mails; - data.mails_added = g_ptr_array_new (); + collector.mails_added = g_ptr_array_new (); url = wocky_xmpp_node_get_attribute (mailbox, "url"); g_free (conn->inbox_url); conn->inbox_url = g_strdup (url); /* Store new mails */ - wocky_xmpp_node_each_child (mailbox, mail_thread_info_each, &data); + wocky_xmpp_node_each_child (mailbox, mail_thread_info_each, &collector); /* Generate the list of removed thread IDs */ mails_removed = g_ptr_array_new_with_free_func (g_free); - if (data.old_mails != NULL) + if (collector.old_mails != NULL) { gpointer key; - g_hash_table_iter_init (&iter, data.old_mails); + g_hash_table_iter_init (&iter, collector.old_mails); while (g_hash_table_iter_next (&iter, &key, NULL)) { @@ -501,16 +502,16 @@ store_unread_mails (GabbleConnection *conn, g_ptr_array_add (mails_removed, g_strdup (tid)); } - g_hash_table_unref (data.old_mails); + g_hash_table_unref (collector.old_mails); } g_ptr_array_add (mails_removed, NULL); - if (data.mails_added->len > 0 || mails_removed->len > 0) + if (collector.mails_added->len > 0 || mails_removed->len > 0) gabble_svc_connection_interface_mail_notification_emit_unread_mails_changed ( - conn, g_hash_table_size (conn->unread_mails), data.mails_added, + conn, g_hash_table_size (conn->unread_mails), collector.mails_added, (const char **)mails_removed->pdata); - g_ptr_array_free (data.mails_added, TRUE); + g_ptr_array_free (collector.mails_added, TRUE); g_ptr_array_free (mails_removed, TRUE); } -- cgit v1.2.1 From 8917c1bf051e98ba31ac9ddc0d4e0e4f0f754299 Mon Sep 17 00:00:00 2001 From: Nicolas Dufresne Date: Thu, 25 Feb 2010 15:53:21 -0500 Subject: conn-mail-notif.c: Use tp_value_array_build to simplify the code Signed-off-by: Nicolas Dufresne --- src/conn-mail-notif.c | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/conn-mail-notif.c b/src/conn-mail-notif.c index 2df6d710f..1c1484da8 100644 --- a/src/conn-mail-notif.c +++ b/src/conn-mail-notif.c @@ -285,32 +285,19 @@ sender_each (WockyXmppNode *node, if (!tp_strdiff ("1", wocky_xmpp_node_get_attribute (node, "unread"))) { - GType addr_type = GABBLE_STRUCT_TYPE_MAIL_ADDRESS; - GValue sender = {0}; + GValueArray *sender; const gchar *name; const gchar *address; - g_value_init (&sender, addr_type); - g_value_set_static_boxed (&sender, - dbus_g_type_specialized_construct (addr_type)); - name = wocky_xmpp_node_get_attribute (node, "name"); - - if (name == NULL) - name = ""; - address = wocky_xmpp_node_get_attribute (node, "address"); - if (address == NULL) - address = ""; - - dbus_g_type_struct_set (&sender, - 0, name, - 1, address, - G_MAXUINT); + sender = tp_value_array_build (2, + G_TYPE_STRING, name ? name : "", + G_TYPE_STRING, address ? address : "", + G_TYPE_INVALID); - g_ptr_array_add (senders, g_value_get_boxed (&sender)); - g_value_unset (&sender); + g_ptr_array_add (senders, sender); } return TRUE; } -- cgit v1.2.1 From a88baea0dd8f3144678175cb871c84576a511c77 Mon Sep 17 00:00:00 2001 From: Nicolas Dufresne Date: Thu, 25 Feb 2010 16:07:19 -0500 Subject: Made TpDBusDaemon globally accessible by all Connection extension Signed-off-by: Nicolas Dufresne --- src/conn-mail-notif.c | 19 ++++--------------- src/connection.c | 14 ++++++++++++++ src/connection.h | 4 +++- 3 files changed, 21 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/conn-mail-notif.c b/src/conn-mail-notif.c index 1c1484da8..072c693de 100644 --- a/src/conn-mail-notif.c +++ b/src/conn-mail-notif.c @@ -378,7 +378,7 @@ handle_snippet (WockyXmppNode *parent_node, typedef struct { GabbleConnection *conn; - /* stolen from conn -> unread_mails, the left items in this is + /* stolen from conn -> unread_mails, the left items in this is * represent the removed emails */ GHashTable *old_mails; GPtrArray *mails_added; @@ -599,15 +599,6 @@ connection_status_changed (GabbleConnection *conn, void conn_mail_notif_init (GabbleConnection *conn) { - GError *error = NULL; - - conn->daemon = tp_dbus_daemon_dup (&error); - - if (conn->daemon == NULL) - { - g_error ("Failed to connect to dbus daemon: %s", error->message); - } - conn->mail_subscribers = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); conn->inbox_url = NULL; @@ -636,14 +627,12 @@ foreach_cancel_watch (gpointer key, void conn_mail_notif_dispose (GabbleConnection *conn) { - if (conn->daemon != NULL) + if (conn->mail_subscribers) { g_hash_table_foreach_remove (conn->mail_subscribers, foreach_cancel_watch, conn); g_hash_table_unref (conn->mail_subscribers); conn->mail_subscribers = NULL; - g_object_unref (conn->daemon); - conn->daemon = NULL; } g_free (conn->inbox_url); @@ -752,11 +741,11 @@ conn_mail_notif_properties_getter (GObject *object, else if (name == prop_quarks[PROP_MAIL_ADDRESS]) { TpBaseConnection *base = TP_BASE_CONNECTION (object); - TpHandleRepoIface *contact_handles = + TpHandleRepoIface *contact_handles = tp_base_connection_get_handles (base, TP_HANDLE_TYPE_CONTACT); TpHandle self = tp_base_connection_get_self_handle (base); const gchar *bare_jid = tp_handle_inspect (contact_handles, self); - + /* After some testing I found that the bare jid (username@stream_server) * always represent the e-mail address on Google account. */ g_value_set_string (value, bare_jid); diff --git a/src/connection.c b/src/connection.c index 562a84e1a..250475d79 100644 --- a/src/connection.c +++ b/src/connection.c @@ -425,11 +425,19 @@ gabble_connection_constructed (GObject *object) static void gabble_connection_init (GabbleConnection *self) { + GError *error = NULL; GabbleConnectionPrivate *priv = G_TYPE_INSTANCE_GET_PRIVATE (self, GABBLE_TYPE_CONNECTION, GabbleConnectionPrivate); DEBUG("Initializing (GabbleConnection *)%p", self); + self->daemon = tp_dbus_daemon_dup (&error); + + if (self->daemon == NULL) + { + g_error ("Failed to connect to dbus daemon: %s", error->message); + } + self->priv = priv; self->lmconn = lm_connection_new (); @@ -1097,6 +1105,12 @@ gabble_connection_dispose (GObject *object) conn_sidecars_dispose (self); + if (self->daemon != NULL) + { + g_object_unref (self->daemon); + self->daemon = NULL; + } + if (G_OBJECT_CLASS (gabble_connection_parent_class)->dispose) G_OBJECT_CLASS (gabble_connection_parent_class)->dispose (object); } diff --git a/src/connection.h b/src/connection.h index ac25b9ac7..f198741ec 100644 --- a/src/connection.h +++ b/src/connection.h @@ -122,6 +122,9 @@ struct _GabbleConnection { TpPresenceMixin presence; TpContactsMixin contacts; + /* DBus daemon instance */ + TpDBusDaemon *daemon; + /* loudmouth connection */ LmConnection *lmconn; WockySession *session; @@ -190,7 +193,6 @@ struct _GabbleConnection { GHashTable *pending_sidecars; /* Mail Notification */ - TpDBusDaemon *daemon; GHashTable *mail_subscribers; gchar *inbox_url; GHashTable *unread_mails; -- cgit v1.2.1