[Telepathy-commits] [telepathy-salut/master] Clean up extract_tube_information: do not use 2 variables with the same name in the same function, and return early when possible to avoid complex code
Alban Crequy
alban.crequy at collabora.co.uk
Tue Nov 25 03:59:23 PST 2008
---
src/salut-tubes-manager.c | 71 ++++++++++++++++++++++++---------------------
1 files changed, 38 insertions(+), 33 deletions(-)
diff --git a/src/salut-tubes-manager.c b/src/salut-tubes-manager.c
index ea0fef7..8cf8420 100644
--- a/src/salut-tubes-manager.c
+++ b/src/salut-tubes-manager.c
@@ -184,13 +184,39 @@ extract_tube_information (TpHandleRepoIface *contact_repo,
node = close_node;
}
- _close = close_node != NULL;
+ _close = (close_node != NULL);
if (close != NULL)
{
*close = _close;
}
- if (!_close && type != NULL)
+ if (tube_id != NULL)
+ {
+ const gchar *str;
+ gchar *endptr;
+ long int tmp;
+
+ str = gibber_xmpp_node_get_attribute (node, "id");
+ if (str == NULL)
+ {
+ DEBUG ("no tube id in tube request");
+ return FALSE;
+ }
+
+ tmp = strtol (str, &endptr, 10);
+ if (!endptr || *endptr)
+ {
+ DEBUG ("tube id is not numeric: %s", str);
+ return FALSE;
+ }
+ *tube_id = (int) tmp;
+ }
+
+ /* next fields are not in the close stanza */
+ if (_close)
+ return TRUE;
+
+ if (type != NULL)
{
const gchar *tube_type;
@@ -206,35 +232,35 @@ extract_tube_information (TpHandleRepoIface *contact_repo,
}
}
- if (!_close && service != NULL)
+ if (service != NULL)
{
*service = gibber_xmpp_node_get_attribute (tube_node, "service");
}
- if (!_close && parameters != NULL)
+ if (parameters != NULL)
{
- GibberXmppNode *node;
+ GibberXmppNode *parameters_node;
- node = gibber_xmpp_node_get_child (tube_node, "parameters");
- *parameters = salut_gibber_xmpp_node_extract_properties (node,
+ parameters_node = gibber_xmpp_node_get_child (tube_node, "parameters");
+ *parameters = salut_gibber_xmpp_node_extract_properties (parameters_node,
"parameter");
}
- if (!_close && portnum != NULL)
+ if (portnum != NULL)
{
- GibberXmppNode *node;
+ GibberXmppNode *transport_node;
const gchar *str;
gchar *endptr;
long int tmp;
- node = gibber_xmpp_node_get_child (tube_node, "transport");
- if (node == NULL)
+ transport_node = gibber_xmpp_node_get_child (tube_node, "transport");
+ if (transport_node == NULL)
{
DEBUG ("no transport to connect to in the tube request");
return FALSE;
}
- str = gibber_xmpp_node_get_attribute (node, "port");
+ str = gibber_xmpp_node_get_attribute (transport_node, "port");
if (str == NULL)
{
DEBUG ("no port to connect to in the tube request");
@@ -250,27 +276,6 @@ extract_tube_information (TpHandleRepoIface *contact_repo,
*portnum = (int) tmp;
}
- if (tube_id != NULL)
- {
- const gchar *str;
- gchar *endptr;
- long int tmp;
-
- str = gibber_xmpp_node_get_attribute (node, "id");
- if (str == NULL)
- {
- DEBUG ("no tube id in tube request");
- return FALSE;
- }
-
- tmp = strtol (str, &endptr, 10);
- if (!endptr || *endptr)
- {
- DEBUG ("tube id is not numeric: %s", str);
- return FALSE;
- }
- *tube_id = (int) tmp;
- }
return TRUE;
}
--
1.5.6.5
More information about the Telepathy-commits
mailing list