[telepathy-gabble/master] Simplify _gabble_connection_get_cached_alias
Will Thompson
will.thompson at collabora.co.uk
Sat Apr 25 03:39:08 PDT 2009
---
src/conn-aliasing.c | 83 +++++++++++++++++++--------------------------------
1 files changed, 31 insertions(+), 52 deletions(-)
diff --git a/src/conn-aliasing.c b/src/conn-aliasing.c
index 297e4e1..1cf3cc9 100644
--- a/src/conn-aliasing.c
+++ b/src/conn-aliasing.c
@@ -773,6 +773,23 @@ OUT:
g_free (alias);
}
+static void
+set_or_clear (gchar **target,
+ gchar *source)
+{
+ if (target != NULL)
+ *target = source;
+ else
+ g_free (source);
+}
+
+static void
+maybe_set (gchar **target,
+ const gchar *source)
+{
+ if (target != NULL)
+ *target = g_strdup (source);
+}
GabbleConnectionAliasSource
_gabble_connection_get_cached_alias (GabbleConnection *conn,
@@ -782,7 +799,6 @@ _gabble_connection_get_cached_alias (GabbleConnection *conn,
TpBaseConnection *base = (TpBaseConnection *) conn;
TpHandleRepoIface *contact_handles = tp_base_connection_get_handles (base,
TP_HANDLE_TYPE_CONTACT);
- GabbleConnectionAliasSource ret = GABBLE_CONNECTION_ALIAS_NONE;
GabblePresence *pres;
const gchar *tmp, *jid;
gchar *resource = NULL;
@@ -795,35 +811,23 @@ _gabble_connection_get_cached_alias (GabbleConnection *conn,
tmp = gabble_roster_handle_get_name (conn->roster, handle);
if (NULL != tmp)
{
- ret = GABBLE_CONNECTION_ALIAS_FROM_ROSTER;
-
- if (NULL != alias)
- *alias = g_strdup (tmp);
-
- goto OUT;
+ maybe_set (alias, tmp);
+ return GABBLE_CONNECTION_ALIAS_FROM_ROSTER;
}
tmp = tp_handle_get_qdata (contact_handles, handle,
gabble_conn_aliasing_pep_alias_quark ());
if (tmp != NULL && tmp != NO_ALIAS)
{
- ret = GABBLE_CONNECTION_ALIAS_FROM_PRESENCE;
-
- if (NULL != alias)
- *alias = g_strdup (tmp);
-
- goto OUT;
+ maybe_set (alias, tmp);
+ return GABBLE_CONNECTION_ALIAS_FROM_PRESENCE;
}
pres = gabble_presence_cache_get (conn->presence_cache, handle);
if (NULL != pres && NULL != pres->nickname)
{
- ret = GABBLE_CONNECTION_ALIAS_FROM_PRESENCE;
-
- if (NULL != alias)
- *alias = g_strdup (pres->nickname);
-
- goto OUT;
+ maybe_set (alias, pres->nickname);
+ return GABBLE_CONNECTION_ALIAS_FROM_PRESENCE;
}
/* XXX: should this be more important than the ones from presence? */
@@ -838,14 +842,8 @@ _gabble_connection_get_cached_alias (GabbleConnection *conn,
if (cm_alias != NULL)
{
- ret = GABBLE_CONNECTION_ALIAS_FROM_CONNMGR;
-
- if (NULL != alias)
- *alias = cm_alias;
- else
- g_free (cm_alias);
-
- goto OUT;
+ set_or_clear (alias, cm_alias);
+ return GABBLE_CONNECTION_ALIAS_FROM_CONNMGR;
}
}
@@ -857,40 +855,21 @@ _gabble_connection_get_cached_alias (GabbleConnection *conn,
/* MUC handles have the nickname in the resource */
if (NULL != resource)
{
- ret = GABBLE_CONNECTION_ALIAS_FROM_MUC_RESOURCE;
-
- if (NULL != alias)
- {
- *alias = resource;
- resource = NULL;
- }
-
- goto OUT;
+ set_or_clear (alias, resource);
+ return GABBLE_CONNECTION_ALIAS_FROM_MUC_RESOURCE;
}
/* if we've seen a nickname in their vCard, use that */
tmp = gabble_vcard_manager_get_cached_alias (conn->vcard_manager, handle);
if (NULL != tmp)
{
- ret = GABBLE_CONNECTION_ALIAS_FROM_VCARD;
-
- if (NULL != alias)
- *alias = g_strdup (tmp);
-
- goto OUT;
+ maybe_set (alias, tmp);
+ return GABBLE_CONNECTION_ALIAS_FROM_VCARD;
}
/* otherwise just take their jid */
- ret = GABBLE_CONNECTION_ALIAS_FROM_JID;
-
- if (NULL != alias)
- *alias = g_strdup (jid);
-
- goto OUT;
-
-OUT:
- g_free (resource);
- return ret;
+ maybe_set (alias, jid);
+ return GABBLE_CONNECTION_ALIAS_FROM_JID;
}
static void
--
1.5.6.5
More information about the telepathy-commits
mailing list