From 07dbe3697bcad18f5766fc0d71a7fc48ff8a26d0 Mon Sep 17 00:00:00 2001 From: Daniel-Constantin Mierla Date: Sun, 27 Mar 2016 11:38:17 +0200 Subject: [PATCH] presence: remove jumping to error from error in update_presentity() - coherent indentation --- modules/presence/presentity.c | 137 +++++++++++++++++----------------- 1 file changed, 67 insertions(+), 70 deletions(-) diff --git a/modules/presence/presentity.c b/modules/presence/presentity.c index 1c385b53e0a..71adc362ff6 100644 --- a/modules/presence/presentity.c +++ b/modules/presence/presentity.c @@ -13,8 +13,8 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * */ @@ -22,7 +22,7 @@ /*! * \file * \brief Kamailio presence module :: Presentity handling - * \ingroup presence + * \ingroup presence */ @@ -39,7 +39,7 @@ #include "../../str.h" #include "../../data_lump_rpl.h" #include "presentity.h" -#include "presence.h" +#include "presence.h" #include "notify.h" #include "publish.h" #include "hash.h" @@ -101,9 +101,9 @@ int publ_send200ok(struct sip_msg *msg, int lexpire, str etag) if (msg == NULL) return 0; - LM_DBG("send 200OK reply\n"); + LM_DBG("send 200OK reply\n"); LM_DBG("etag= %s - len= %d\n", etag.s, etag.len); - + hdr_append.s = buf; hdr_append.s[0]='\0'; hdr_append.len = snprintf(hdr_append.s, buf_len, "Expires: %d\r\n", @@ -119,7 +119,7 @@ int publ_send200ok(struct sip_msg *msg, int lexpire, str etag) goto error; } hdr_append.s[hdr_append.len]= '\0'; - + if (add_lump_rpl( msg, hdr_append.s, hdr_append.len, LUMP_RPL_HDR)==0 ) { LM_ERR("unable to add lump_rl\n"); @@ -192,17 +192,17 @@ unsigned int pres_get_priority(void) /** * create new presentity record */ -presentity_t* new_presentity( str* domain,str* user,int expires, +presentity_t* new_presentity( str* domain,str* user,int expires, pres_ev_t* event, str* etag, str* sender) { presentity_t *presentity= NULL; int size, init_len; - + /* allocating memory for presentity */ size = sizeof(presentity_t)+ domain->len+ user->len+ etag->len +1; if(sender) size+= sizeof(str)+ sender->len* sizeof(char); - + init_len= size; presentity = (presentity_t*)pkg_malloc(size); @@ -216,8 +216,8 @@ presentity_t* new_presentity( str* domain,str* user,int expires, presentity->domain.s = (char*)presentity+ size; strncpy(presentity->domain.s, domain->s, domain->len); presentity->domain.len = domain->len; - size+= domain->len; - + size+= domain->len; + presentity->user.s = (char*)presentity+size; strncpy(presentity->user.s, user->s, user->len); presentity->user.len = user->len; @@ -229,7 +229,7 @@ presentity_t* new_presentity( str* domain,str* user,int expires, presentity->etag.len = etag->len; size+= etag->len+1; - + if(sender) { presentity->sender= (str*)((char*)presentity+ size); @@ -250,7 +250,7 @@ presentity_t* new_presentity( str* domain,str* user,int expires, presentity->received_time= (int)time(NULL); presentity->priority = pres_get_priority(); return presentity; - + error: if(presentity) pkg_free(presentity); @@ -328,7 +328,7 @@ int update_presentity(struct sip_msg* msg, presentity_t* presentity, str* body, goto error; } } - + if(uandd_to_uri(presentity->user, presentity->domain, &pres_uri)< 0) { LM_ERR("constructing uri from user and domain\n"); @@ -342,7 +342,7 @@ int update_presentity(struct sip_msg* msg, presentity_t* presentity, str* body, query_vals[n_query_cols].nul = 0; query_vals[n_query_cols].val.str_val = presentity->domain; n_query_cols++; - + query_cols[n_query_cols] = &str_username_col; query_ops[n_query_cols] = OP_EQ; query_vals[n_query_cols].type = DB1_STR; @@ -367,7 +367,7 @@ int update_presentity(struct sip_msg* msg, presentity_t* presentity, str* body, result_cols[rez_body_col= n_result_cols++] = &str_body_col; result_cols[rez_sender_col= n_result_cols++] = &str_sender_col; - if(new_t) + if(new_t) { /* insert new record in hash_table */ @@ -377,8 +377,8 @@ int update_presentity(struct sip_msg* msg, presentity_t* presentity, str* body, LM_ERR("inserting record in hash table\n"); goto error; } - - /* insert new record into database */ + + /* insert new record into database */ query_cols[n_query_cols] = &str_sender_col; query_vals[n_query_cols].type = DB1_STR; query_vals[n_query_cols].nul = 0; @@ -397,7 +397,7 @@ int update_presentity(struct sip_msg* msg, presentity_t* presentity, str* body, query_vals[n_query_cols].nul = 0; query_vals[n_query_cols].val.str_val = *body; n_query_cols++; - + query_cols[n_query_cols] = &str_received_time_col; query_vals[n_query_cols].type = DB1_INT; query_vals[n_query_cols].nul = 0; @@ -409,7 +409,7 @@ int update_presentity(struct sip_msg* msg, presentity_t* presentity, str* body, query_vals[n_query_cols].nul = 0; query_vals[n_query_cols].val.int_val = presentity->priority; n_query_cols++; - + if (presentity->expires != -1) { /* A real PUBLISH */ @@ -419,8 +419,8 @@ int update_presentity(struct sip_msg* msg, presentity_t* presentity, str* body, query_vals[n_query_cols].val.int_val = presentity->expires+ (int)time(NULL); n_query_cols++; - - if (pa_dbf.use_table(pa_db, &presentity_table) < 0) + + if (pa_dbf.use_table(pa_db, &presentity_table) < 0) { LM_ERR("unsuccessful use_table\n"); goto error; @@ -436,8 +436,8 @@ int update_presentity(struct sip_msg* msg, presentity_t* presentity, str* body, } LM_DBG("inserting %d cols into table\n",n_query_cols); - - if (pa_dbf.insert(pa_db, query_cols, query_vals, n_query_cols) < 0) + + if (pa_dbf.insert(pa_db, query_cols, query_vals, n_query_cols) < 0) { LM_ERR("inserting new record in database\n"); goto error; @@ -451,8 +451,8 @@ int update_presentity(struct sip_msg* msg, presentity_t* presentity, str* body, query_vals[n_query_cols].nul = 0; query_vals[n_query_cols].val.int_val = -1; n_query_cols++; - - if (pa_dbf.use_table(pa_db, &presentity_table) < 0) + + if (pa_dbf.use_table(pa_db, &presentity_table) < 0) { LM_ERR("unsuccessful use_table\n"); goto error; @@ -474,7 +474,7 @@ int update_presentity(struct sip_msg* msg, presentity_t* presentity, str* body, } - if (pa_dbf.replace(pa_db, query_cols, query_vals, n_query_cols, 4, 0) < 0) + if (pa_dbf.replace(pa_db, query_cols, query_vals, n_query_cols, 4, 0) < 0) { LM_ERR("replacing record in database\n"); goto error; @@ -490,9 +490,9 @@ int update_presentity(struct sip_msg* msg, presentity_t* presentity, str* body, goto send_notify; } else - { + { - if (pa_dbf.use_table(pa_db, &presentity_table) < 0) + if (pa_dbf.use_table(pa_db, &presentity_table) < 0) { LM_ERR("unsuccessful sql use table\n"); goto error; @@ -511,7 +511,7 @@ int update_presentity(struct sip_msg* msg, presentity_t* presentity, str* body, { if (pa_dbf.query (pa_db, query_cols, query_ops, query_vals, - result_cols, n_query_cols, n_result_cols, 0, &result) < 0) + result_cols, n_query_cols, n_result_cols, 0, &result) < 0) { LM_ERR("unsuccessful sql query\n"); goto error; @@ -521,7 +521,7 @@ int update_presentity(struct sip_msg* msg, presentity_t* presentity, str* body, if (!(result->n > 0)) goto send_412; - + db_record_exists= 1; /* analize if previous body has a dialog */ row = &result->rows[0]; @@ -553,23 +553,23 @@ int update_presentity(struct sip_msg* msg, presentity_t* presentity, str* body, LM_DBG("old_sender = %.*s\n", sender.len, sender.s ); if(presentity->sender) { - if(!(presentity->sender->len == sender.len && - presence_sip_uri_match(presentity->sender, &sender)== 0)) - bla_update_publish= 0; + if(!(presentity->sender->len == sender.len && + presence_sip_uri_match(presentity->sender, &sender)== 0)) + bla_update_publish= 0; } after_dialog_check: pa_dbf.free_result(pa_db, result); result = NULL; - + } - if(presentity->expires <= 0) + if(presentity->expires <= 0) { if (!db_record_exists) { if (pa_dbf.query (pa_db, query_cols, query_ops, query_vals, - result_cols, n_query_cols, n_result_cols, 0, &result) < 0) + result_cols, n_query_cols, n_result_cols, 0, &result) < 0) { LM_ERR("unsuccessful sql query\n"); goto error; @@ -658,7 +658,7 @@ int update_presentity(struct sip_msg* msg, presentity_t* presentity, str* body, } if(presentity->event->etag_not_new== 0) - { + { /* generate another etag */ unsigned int publ_nr; str str_publ_nr= {0, 0}; @@ -673,7 +673,7 @@ int update_presentity(struct sip_msg* msg, presentity_t* presentity, str* body, { LM_ERR("wrong etag\n"); goto error; - } + } str_publ_nr.s= dot+1; str_publ_nr.len--; @@ -689,7 +689,7 @@ int update_presentity(struct sip_msg* msg, presentity_t* presentity, str* body, goto error; } etag.len=(strlen(etag.s)); - + cur_etag= etag; update_keys[n_update_cols] = &str_etag_col; @@ -701,7 +701,7 @@ int update_presentity(struct sip_msg* msg, presentity_t* presentity, str* body, } else cur_etag= presentity->etag; - + update_keys[n_update_cols] = &str_expires_col; update_vals[n_update_cols].type = DB1_INT; update_vals[n_update_cols].nul = 0; @@ -730,7 +730,7 @@ int update_presentity(struct sip_msg* msg, presentity_t* presentity, str* body, n_update_cols++; /* updated stored sphere */ - if(sphere_enable && + if(sphere_enable && presentity->event->evp->type== EVENT_PRESENCE) { if( publ_cache_enabled && @@ -741,8 +741,7 @@ int update_presentity(struct sip_msg* msg, presentity_t* presentity, str* body, } } } - - + if( presentity->sender) { update_keys[n_update_cols] = &str_sender_col; @@ -756,14 +755,14 @@ int update_presentity(struct sip_msg* msg, presentity_t* presentity, str* body, if (!pa_dbf.affected_rows && !db_record_exists) { if (pa_dbf.query (pa_db, query_cols, query_ops, query_vals, - result_cols, n_query_cols, n_result_cols, 0, &result) < 0) + result_cols, n_query_cols, n_result_cols, 0, &result) < 0) { LM_ERR("unsuccessful sql query\n"); goto error; } if(result== NULL) goto error; - + if (!(result->n > 0)) goto send_412; @@ -773,7 +772,7 @@ int update_presentity(struct sip_msg* msg, presentity_t* presentity, str* body, } if( pa_dbf.update( pa_db,query_cols, query_ops, query_vals, - update_keys, update_vals, n_query_cols, n_update_cols )<0) + update_keys, update_vals, n_query_cols, n_update_cols )<0) { LM_ERR("updating published info in database\n"); goto error; @@ -871,21 +870,19 @@ int update_presentity(struct sip_msg* msg, presentity_t* presentity, str* body, pa_dbf.free_result(pa_db, result); if(etag.s) pkg_free(etag.s); - if(rules_doc) - { + if(rules_doc) { if(rules_doc->s) pkg_free(rules_doc->s); pkg_free(rules_doc); } - if(pres_uri.s) + if(pres_uri.s) { pkg_free(pres_uri.s); + pres_uri.s = NULL; + } - if (pa_dbf.abort_transaction) - { - if (pa_dbf.abort_transaction(pa_db) < 0) - { + if (pa_dbf.abort_transaction) { + if (pa_dbf.abort_transaction(pa_db) < 0) { LM_ERR("in abort_transaction\n"); - goto error; } } @@ -894,7 +891,7 @@ int update_presentity(struct sip_msg* msg, presentity_t* presentity, str* body, int pres_htable_restore(void) { - /* query all records from presentity table and insert records + /* query all records from presentity table and insert records * in presentity table */ db_key_t result_cols[6]; db1_res_t *result= NULL; @@ -946,7 +943,7 @@ int pres_htable_restore(void) if(row_vals[expires_col].val.int_val< (int)time(NULL)) continue; - + sphere= NULL; user.s= (char*)row_vals[user_col].val.string_val; user.len= strlen(user.s); @@ -970,7 +967,7 @@ int pres_htable_restore(void) goto error; } /* insert in hash_table*/ - + if(sphere_enable && event== EVENT_PRESENCE ) { body.s= (char*)row_vals[body_col].val.string_val; @@ -1000,7 +997,7 @@ int pres_htable_restore(void) error: if(result) pa_dbf.free_result(pa_db, result); - return -1; + return -1; } char* extract_sphere(str body) @@ -1010,7 +1007,7 @@ char* extract_sphere(str body) xmlDocPtr doc= NULL; xmlNodePtr node; char* cont, *sphere= NULL; - + doc= xmlParseMemory(body.s, body.len); if(doc== NULL) @@ -1020,7 +1017,7 @@ char* extract_sphere(str body) } node= xmlNodeGetNodeByName(doc->children, "sphere", "rpid"); - + if(node== NULL) node= xmlNodeGetNodeByName(doc->children, "sphere", "r"); @@ -1144,8 +1141,8 @@ char* get_sphere(str* pres_uri) n_query_cols++; result_cols[n_result_cols++] = &str_body_col; - - if (pa_dbf.use_table(pa_db, &presentity_table) < 0) + + if (pa_dbf.use_table(pa_db, &presentity_table) < 0) { LM_ERR("in use_table\n"); return NULL; @@ -1157,14 +1154,14 @@ char* get_sphere(str* pres_uri) query_str = str_received_time_col; } if (pa_dbf.query (pa_db, query_cols, 0, query_vals, - result_cols, n_query_cols, n_result_cols, &query_str , &result) < 0) + result_cols, n_query_cols, n_result_cols, &query_str , &result) < 0) { LM_ERR("failed to query %.*s table\n", presentity_table.len, presentity_table.s); if(result) pa_dbf.free_result(pa_db, result); return NULL; } - + if(result== NULL) return NULL; @@ -1190,7 +1187,7 @@ char* get_sphere(str* pres_uri) LM_ERR("Empty notify body record\n"); goto error; } - + sphere= extract_sphere(body); pa_dbf.free_result(pa_db, result); @@ -1290,7 +1287,7 @@ int mark_presentity_for_delete(presentity_t *pres) if (RES_ROW_N(result) > 1) { /* More that one is prevented by DB constraint - but handle - it anyway */ + * it anyway */ LM_ERR("Found %d presentities - expected 1\n", RES_ROW_N(result)); if (delete_presentity(pres) < 0) @@ -1300,7 +1297,7 @@ int mark_presentity_for_delete(presentity_t *pres) } /* Want the calling function to continue properly so do not - return an error */ + * return an error */ goto done; } @@ -1341,7 +1338,7 @@ int mark_presentity_for_delete(presentity_t *pres) n_update_cols++; if (pa_dbf.update(pa_db, query_cols, 0, query_vals, update_cols, - update_vals, n_query_cols, n_update_cols) < 0) + update_vals, n_query_cols, n_update_cols) < 0) { LM_ERR("unsuccessful sql update operation"); goto error;