Remove unnecessary if statements before calling iks_delete (redundant check is
authorPhilippe Sultan <philippe.sultan@gmail.com>
Fri, 29 Feb 2008 14:15:03 +0000 (14:15 +0000)
committerPhilippe Sultan <philippe.sultan@gmail.com>
Fri, 29 Feb 2008 14:15:03 +0000 (14:15 +0000)
done inside iks_delete), thus making the code conform with coding guidelines.

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@105263 65c4cc65-6c06-0410-ace0-fbb531ad65f3

channels/chan_gtalk.c
channels/chan_jingle.c
res/res_jabber.c

index 05e7de7..b21201c 100644 (file)
@@ -281,10 +281,8 @@ static int add_codec_to_answer(const struct gtalk_pvt *p, int codec, iks *dcodec
                payload_eg711u = iks_new("payload-type");
        
                if(!payload_eg711u || !payload_pcmu) {
-                       if(payload_pcmu)
-                               iks_delete(payload_pcmu);
-                       if(payload_eg711u)
-                               iks_delete(payload_eg711u);
+                       iks_delete(payload_pcmu);
+                       iks_delete(payload_eg711u);
                        ast_log(LOG_WARNING,"Failed to allocate iks node");
                        return -1;
                }
@@ -304,10 +302,8 @@ static int add_codec_to_answer(const struct gtalk_pvt *p, int codec, iks *dcodec
                payload_pcma = iks_new("payload-type");
                payload_eg711a = iks_new("payload-type");
                if(!payload_eg711a || !payload_pcma) {
-                       if(payload_eg711a)
-                               iks_delete(payload_eg711a);
-                       if(payload_pcma)
-                               iks_delete(payload_pcma);
+                       iks_delete(payload_eg711a);
+                       iks_delete(payload_pcma);
                        ast_log(LOG_WARNING,"Failed to allocate iks node");
                        return -1;
                }
@@ -378,17 +374,12 @@ static int gtalk_invite(struct gtalk_pvt *p, char *to, char *from, char *sid, in
        transport = iks_new("transport");
        payload_telephone = iks_new("payload-type");
        if (!(iq && gtalk && dcodecs && transport && payload_telephone)){
-               if(iq)
-                       iks_delete(iq);
-               if(gtalk)
-                       iks_delete(gtalk);
-               if(dcodecs)
-                       iks_delete(dcodecs);
-               if(transport)
-                       iks_delete(transport);
-               if(payload_telephone)
-                       iks_delete(payload_telephone);
-
+               iks_delete(iq);
+               iks_delete(gtalk);
+               iks_delete(dcodecs);
+               iks_delete(transport);
+               iks_delete(payload_telephone);
+               
                ast_log(LOG_ERROR, "Could not allocate iksemel nodes\n");
                return 0;
        }
@@ -428,6 +419,7 @@ static int gtalk_invite(struct gtalk_pvt *p, char *to, char *from, char *sid, in
        iks_insert_node(dcodecs, payload_telephone);
 
        ast_aji_send(client->connection, iq);
+
        iks_delete(payload_telephone);
        iks_delete(transport);
        iks_delete(dcodecs);
@@ -443,12 +435,9 @@ static int gtalk_invite_response(struct gtalk_pvt *p, char *to , char *from, cha
        session = iks_new("session");
        transport = iks_new("transport");
        if(!(iq && session && transport)) {
-               if(iq)
-                       iks_delete(iq);
-               if(session)
-                       iks_delete(session);
-               if(transport)
-                       iks_delete(transport);
+               iks_delete(iq);
+               iks_delete(session);
+               iks_delete(transport);
                ast_log(LOG_ERROR, " Unable to allocate IKS node\n");
                return -1;
        }
@@ -465,6 +454,7 @@ static int gtalk_invite_response(struct gtalk_pvt *p, char *to , char *from, cha
        iks_insert_node(iq,session);
        iks_insert_node(session,transport);
        ast_aji_send(p->parent->connection, iq);
+
        iks_delete(transport);
        iks_delete(session);
        iks_delete(iq);
@@ -564,13 +554,13 @@ static int gtalk_response(struct gtalk *client, char *from, ikspak *pak, const c
                        }
                }
                ast_aji_send(client->connection, response);
-               if (reason)
-                       iks_delete(reason);
-               if (error)
-                       iks_delete(error);
-               iks_delete(response);
                res = 0;
        }
+
+       iks_delete(reason);
+       iks_delete(error);
+       iks_delete(response);
+
        return res;
 }
 
@@ -832,14 +822,11 @@ safeout:
                ast_free(ours1);
        if (ours2)
                ast_free(ours2);
-       if (iq)
-               iks_delete(iq);
-       if (gtalk)
-               iks_delete(gtalk);
-       if (candidate)
-               iks_delete(candidate);
-       if(transport)
-               iks_delete(transport);
+       iks_delete(iq);
+       iks_delete(gtalk);
+       iks_delete(candidate);
+       iks_delete(transport);
+
        return 1;
 }
 
@@ -1022,11 +1009,13 @@ static int gtalk_action(struct gtalk *client, struct gtalk_pvt *p, const char *a
                        iks_insert_attrib(session, "xmlns", "http://www.google.com/session");
                        iks_insert_node(request, session);
                        ast_aji_send(client->connection, request);
-                       iks_delete(session);
                        res = 0;
                }
-               iks_delete(request);
        }
+
+       iks_delete(session);
+       iks_delete(request);
+
        return res;
 }
 
@@ -1260,6 +1249,7 @@ static int gtalk_add_candidate(struct gtalk *client, ikspak *pak)
        iks_insert_attrib(receipt, "to", iks_find_attrib(pak->x, "from"));
        iks_insert_attrib(receipt, "id", iks_find_attrib(pak->x, "id"));
        ast_aji_send(c, receipt);
+
        iks_delete(receipt);
 
        return 1;
@@ -1402,12 +1392,9 @@ static int gtalk_digit(struct ast_channel *ast, char digit, unsigned int duratio
        gtalk = iks_new("gtalk");
        dtmf = iks_new("dtmf");
        if(!iq || !gtalk || !dtmf) {
-               if(iq)
-                       iks_delete(iq);
-               if(gtalk)
-                       iks_delete(gtalk);
-               if(dtmf)
-                       iks_delete(dtmf);
+               iks_delete(iq);
+               iks_delete(gtalk);
+               iks_delete(dtmf);
                ast_log(LOG_ERROR, "Did not send dtmf do to memory issue\n");
                return -1;
        }
@@ -1433,6 +1420,7 @@ static int gtalk_digit(struct ast_channel *ast, char digit, unsigned int duratio
                iks_insert_attrib(dtmf, "action", "button-up");
        }
        ast_aji_send(client->connection, iq);
+
        iks_delete(iq);
        iks_delete(gtalk);
        iks_delete(dtmf);
index 8763397..8c2361c 100644 (file)
@@ -362,6 +362,7 @@ static int jingle_accept_call(struct jingle *client, struct jingle_pvt *p)
                iks_insert_node(dcodecs, payload_cn);
 
                ast_aji_send(c, iq);
+
                iks_delete(payload_red);
                iks_delete(payload_audio);
                iks_delete(payload_cn);
@@ -463,13 +464,13 @@ static int jingle_response(struct jingle *client, ikspak *pak, const char *reaso
                        }
                }
                ast_aji_send(client->connection, response);
-               if (reason)
-                       iks_delete(reason);
-               if (error)
-                       iks_delete(error);
-               iks_delete(response);
                res = 0;
        }
+       
+       iks_delete(reason);
+       iks_delete(error);
+       iks_delete(response);
+
        return res;
 }
 
@@ -727,16 +728,12 @@ safeout:
                ast_free(ours1);
        if (ours2)
                ast_free(ours2);
-       if (iq)
-               iks_delete(iq);
-       if (jingle)
-               iks_delete(jingle);
-       if (content)
-               iks_delete(content);
-       if (transport)
-               iks_delete(transport);
-       if (candidate)
-               iks_delete(candidate);
+       iks_delete(iq);
+       iks_delete(jingle);
+       iks_delete(content);
+       iks_delete(transport);
+       iks_delete(candidate);
+
        return 1;
 }
 
@@ -905,11 +902,13 @@ static int jingle_action(struct jingle *client, struct jingle_pvt *p, const char
                        iks_insert_node(iq, jingle);
 
                        ast_aji_send(client->connection, iq);
-                       iks_delete(jingle);
                        res = 0;
                }
-               iks_delete(iq);
        }
+       
+       iks_delete(jingle);
+       iks_delete(iq);
+       
        return res;
 }
 
@@ -1114,6 +1113,7 @@ static int jingle_add_candidate(struct jingle *client, ikspak *pak)
        iks_insert_attrib(receipt, "to", iks_find_attrib(pak->x, "from"));
        iks_insert_attrib(receipt, "id", iks_find_attrib(pak->x, "id"));
        ast_aji_send(c, receipt);
+
        iks_delete(receipt);
 
        return 1;
@@ -1246,12 +1246,9 @@ static int jingle_digit(struct ast_channel *ast, char digit, unsigned int durati
        jingle = iks_new("jingle");
        dtmf = iks_new("dtmf");
        if(!iq || !jingle || !dtmf) {
-               if(iq)
-                       iks_delete(iq);
-               if(jingle)
-                       iks_delete(jingle);
-               if(dtmf)
-                       iks_delete(dtmf);
+               iks_delete(iq);
+               iks_delete(jingle);
+               iks_delete(dtmf);
                ast_log(LOG_ERROR, "Did not send dtmf do to memory issue\n");
                return -1;
        }
@@ -1277,6 +1274,7 @@ static int jingle_digit(struct ast_channel *ast, char digit, unsigned int durati
                iks_insert_attrib(dtmf, "action", "button-up");
        }
        ast_aji_send(client->connection, iq);
+
        iks_delete(iq);
        iks_delete(jingle);
        iks_delete(dtmf);
index f5cabb1..9dab2da 100644 (file)
@@ -1040,12 +1040,11 @@ static int aji_register_approve_handler(void *data, ikspak *pak)
                ast_log(LOG_ERROR, "Out of memory.\n");
        }
 
-       if (iq)
-               iks_delete(iq);
-       if(presence)
-               iks_delete(presence);
-       if (x)
-               iks_delete(x);
+
+       iks_delete(iq);
+       iks_delete(presence);
+       iks_delete(x);
+       
        ASTOBJ_UNREF(client, aji_client_destroy);
        return IKS_FILTER_EAT;
 }
@@ -1088,14 +1087,11 @@ static int aji_register_query_handler(void *data, ikspak *pak)
                } else {
                        ast_log(LOG_ERROR, "Out of memory.\n");
                }
-               if (iq)
-                       iks_delete(iq);
-               if (query)
-                       iks_delete(query);
-               if (error)
-                       iks_delete(error);
-               if (notacceptable)
-                       iks_delete(notacceptable);
+
+               iks_delete(iq);
+               iks_delete(query);
+               iks_delete(error);
+               iks_delete(notacceptable);
        } else  if (!(node = iks_find_attrib(pak->query, "node"))) {
                iks *iq = NULL, *query = NULL, *instructions = NULL;
                char *explain = "Welcome to Asterisk - the Open Source PBX.\n";
@@ -1115,12 +1111,10 @@ static int aji_register_query_handler(void *data, ikspak *pak)
                } else {
                        ast_log(LOG_ERROR, "Out of memory.\n");
                }
-               if (iq)
-                       iks_delete(iq);
-               if (query)
-                       iks_delete(query);
-               if (instructions)
-                       iks_delete(instructions);
+
+               iks_delete(iq);
+               iks_delete(query);
+               iks_delete(instructions);
        }
        ASTOBJ_UNREF(client, aji_client_destroy);
        return IKS_FILTER_EAT;
@@ -1159,12 +1153,10 @@ static int aji_ditems_handler(void *data, ikspak *pak)
                } else {
                        ast_log(LOG_ERROR, "Out of memory.\n");
                }
-               if (iq)
-                       iks_delete(iq);
-               if (query)
-                       iks_delete(query);
-               if (item)
-                       iks_delete(item);
+
+               iks_delete(iq);
+               iks_delete(query);
+               iks_delete(item);
 
        } else if (!strcasecmp(node, "http://jabber.org/protocol/commands")) {
                iks *iq, *query, *confirm;
@@ -1188,12 +1180,10 @@ static int aji_ditems_handler(void *data, ikspak *pak)
                } else {
                        ast_log(LOG_ERROR, "Out of memory.\n");
                }
-               if (iq)
-                       iks_delete(iq);
-               if (query)
-                       iks_delete(query);
-               if (confirm)
-                       iks_delete(confirm);
+
+               iks_delete(iq);
+               iks_delete(query);
+               iks_delete(confirm);
 
        } else if (!strcasecmp(node, "confirmaccount")) {
                iks *iq = NULL, *query = NULL, *feature = NULL;
@@ -1215,12 +1205,10 @@ static int aji_ditems_handler(void *data, ikspak *pak)
                } else {
                        ast_log(LOG_ERROR, "Out of memory.\n");
                }
-               if (iq)
-                       iks_delete(iq);
-               if (query)
-                       iks_delete(query);
-               if (feature)
-                       iks_delete(feature);
+
+               iks_delete(iq);
+               iks_delete(query);
+               iks_delete(feature);
        }
 
        ASTOBJ_UNREF(client, aji_client_destroy);
@@ -1275,16 +1263,12 @@ static int aji_client_info_handler(void *data, ikspak *pak)
                        ast_aji_send(client, iq);
                } else
                        ast_log(LOG_ERROR, "Out of Memory.\n");
-               if (iq)
-                       iks_delete(iq);
-               if (query)
-                       iks_delete(query);
-               if (ident)
-                       iks_delete(ident);
-               if (google)
-                       iks_delete(google);
-               if (disco)
-                       iks_delete(disco);
+
+               iks_delete(iq);
+               iks_delete(query);
+               iks_delete(ident);
+               iks_delete(google);
+               iks_delete(disco);
        } else if (pak->subtype == IKS_TYPE_ERROR) {
                ast_log(LOG_NOTICE, "User %s does not support discovery.\n", pak->from->full);
        }
@@ -1364,26 +1348,16 @@ static int aji_dinfo_handler(void *data, ikspak *pak)
                        ast_log(LOG_ERROR, "Out of memory.\n");
                }
 
-               if (iq)
-                       iks_delete(iq);
-               if (query)
-                       iks_delete(query);
-               if (identity)
-                       iks_delete(identity);
-               if (disco)
-                       iks_delete(disco);
-               if (reg)
-                       iks_delete(reg);
-               if (commands)
-                       iks_delete(commands);
-               if (gateway)
-                       iks_delete(gateway);
-               if (version)
-                       iks_delete(version);
-               if (vcard)
-                       iks_delete(vcard);
-               if (search)
-                       iks_delete(search);
+               iks_delete(iq);
+               iks_delete(query);
+               iks_delete(identity);
+               iks_delete(disco);
+               iks_delete(reg);
+               iks_delete(commands);
+               iks_delete(gateway);
+               iks_delete(version);
+               iks_delete(vcard);
+               iks_delete(search);
 
        } else if (pak->subtype == IKS_TYPE_GET && !strcasecmp(node, "http://jabber.org/protocol/commands")) {
                iks *iq, *query, *confirm;
@@ -1407,12 +1381,10 @@ static int aji_dinfo_handler(void *data, ikspak *pak)
                } else {
                        ast_log(LOG_ERROR, "Out of memory.\n");
                }
-               if (iq)
-                       iks_delete(iq);
-               if (query)
-                       iks_delete(query);
-               if (confirm)
-                       iks_delete(confirm);
+
+               iks_delete(iq);
+               iks_delete(query);
+               iks_delete(confirm);
 
        } else if (pak->subtype == IKS_TYPE_GET && !strcasecmp(node, "confirmaccount")) {
                iks *iq, *query, *feature;
@@ -1434,12 +1406,10 @@ static int aji_dinfo_handler(void *data, ikspak *pak)
                } else {
                        ast_log(LOG_ERROR, "Out of memory.\n");
                }
-               if (iq)
-                       iks_delete(iq);
-               if (query)
-                       iks_delete(query);
-               if (feature)
-                       iks_delete(feature);
+
+               iks_delete(iq);
+               iks_delete(query);
+               iks_delete(feature);
        }
 
        ASTOBJ_UNREF(client, aji_client_destroy);
@@ -1675,10 +1645,9 @@ static void aji_handle_presence(struct aji_client *client, ikspak *pak)
                                
                        } else
                                ast_log(LOG_ERROR, "Out of memory.\n");
-                       if(query)
-                               iks_delete(query);
-                       if(iq)
-                               iks_delete(iq);
+                       
+                       iks_delete(query);
+                       iks_delete(iq);
                }
        }
        switch (pak->subtype) {
@@ -1741,10 +1710,10 @@ static void aji_handle_subscribe(struct aji_client *client, ikspak *pak)
                        ast_aji_send(client, presence);
                } else
                        ast_log(LOG_ERROR, "Unable to allocate nodes\n");
-               if (presence)
-                       iks_delete(presence);
-               if (status)
-                       iks_delete(status);
+
+               iks_delete(presence);
+               iks_delete(status);
+
                if (client->component)
                        aji_set_presence(client, pak->from->full, iks_find_attrib(pak->x, "to"), client->status, client->statusmessage);
        case IKS_TYPE_SUBSCRIBED:
@@ -1778,8 +1747,8 @@ int ast_aji_send_chat(struct aji_client *client, const char *address, const char
                } else {
                        ast_log(LOG_ERROR, "Out of memory.\n");
                }
-               if (message_packet)
-                       iks_delete(message_packet);
+
+               iks_delete(message_packet);
        } else
                ast_log(LOG_WARNING, "JABBER: Not connected can't send\n");
        return 1;
@@ -1831,10 +1800,10 @@ int ast_aji_join_chat(struct aji_client *client, char *room)
                res = ast_aji_send(client, presence);
        } else 
                ast_log(LOG_ERROR, "Out of memory.\n");
-       if (presence)
-               iks_delete(presence);
-       if (priority)
-               iks_delete(priority);
+       
+       iks_delete(presence);
+       iks_delete(priority);
+       
        return res;
 }
 
@@ -1866,12 +1835,11 @@ int ast_aji_invite_chat(struct aji_client *client, char *user, char *room, char
                res = ast_aji_send(client, invite);
        } else 
                ast_log(LOG_ERROR, "Out of memory.\n");
-       if (body)
-               iks_delete(body);
-       if (namespace)
-               iks_delete(namespace);
-       if (invite)
-               iks_delete(invite);
+
+       iks_delete(body);
+       iks_delete(namespace);
+       iks_delete(invite);
+       
        return res;
 }
 
@@ -2078,14 +2046,12 @@ static void aji_pruneregister(struct aji_client *client)
                });
        } else
                ast_log(LOG_ERROR, "Out of memory.\n");
-       if (removeiq)
-               iks_delete(removeiq);
-       if (removequery)
-               iks_delete(removequery);
-       if (removeitem)
-               iks_delete(removeitem);
-       if (send)
-               iks_delete(send);
+
+       iks_delete(removeiq);
+       iks_delete(removequery);
+       iks_delete(removeitem);
+       iks_delete(send);
+       
        ASTOBJ_CONTAINER_PRUNE_MARKED(&client->buddies, aji_buddy_destroy);
 }
 
@@ -2118,8 +2084,8 @@ static int aji_filter_roster(void *data, ikspak *pak)
                }
                if (!flag)
                        ast_copy_flags(&iterator->flags, &client->flags, AJI_AUTOREGISTER);
-               if (x)
-                       iks_delete(x);
+               iks_delete(x);
+               
                ASTOBJ_UNLOCK(iterator);
        });
 
@@ -2158,8 +2124,8 @@ static int aji_filter_roster(void *data, ikspak *pak)
                }
                x = iks_next(x);
        }
-       if (x)
-               iks_delete(x);
+
+       iks_delete(x);
        aji_pruneregister(client);
 
        ASTOBJ_UNREF(client, aji_client_destroy);
@@ -2195,13 +2161,15 @@ static int aji_get_roster(struct aji_client *client)
 {
        iks *roster = NULL;
        roster = iks_make_iq(IKS_TYPE_GET, IKS_NS_ROSTER);
+
        if(roster) {
                iks_insert_attrib(roster, "id", "roster");
                aji_set_presence(client, NULL, client->jid->full, client->status, client->statusmessage);
                ast_aji_send(client, roster);
        }
-       if (roster)
-               iks_delete(roster);
+
+       iks_delete(roster);
+       
        return 1;
 }
 
@@ -2315,12 +2283,10 @@ static void aji_set_presence(struct aji_client *client, char *to, char *from, in
                res = ast_aji_send(client, presence);
        } else
                ast_log(LOG_ERROR, "Out of memory.\n");
-       if (cnode)
-               iks_delete(cnode);
-       if (presence)
-               iks_delete(presence);
-       if (priority)
-               iks_delete(priority);
+
+       iks_delete(cnode);
+       iks_delete(presence);
+       iks_delete(priority);
 }
 
 /*!