فهرست منبع

htable: coherent indentation and whitespacing

Daniel-Constantin Mierla 9 سال پیش
والد
کامیت
79ad0e2d8a
6فایلهای تغییر یافته به همراه66 افزوده شده و 65 حذف شده
  1. 1 1
      modules/htable/api.c
  2. 20 20
      modules/htable/ht_api.c
  3. 5 5
      modules/htable/ht_db.c
  4. 26 25
      modules/htable/ht_dmq.c
  5. 7 7
      modules/htable/ht_var.c
  6. 7 7
      modules/htable/htable.c

+ 1 - 1
modules/htable/api.c

@@ -18,7 +18,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
-		       
+
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>

+ 20 - 20
modules/htable/ht_api.c

@@ -240,7 +240,7 @@ ht_t* ht_get_table(str *name)
 	ht = _ht_root;
 	while(ht!=NULL)
 	{
-		if(htid == ht->htid && name->len==ht->name.len 
+		if(htid == ht->htid && name->len==ht->name.len
 				&& strncmp(name->s, ht->name.s, name->len)==0)
 		{
 			LM_DBG("htable found [%.*s]\n", name->len, name->s);
@@ -266,7 +266,7 @@ int ht_add_table(str *name, int autoexp, str *dbtable, str *dbcols, int size,
 	ht = _ht_root;
 	while(ht!=NULL)
 	{
-		if(htid == ht->htid && name->len==ht->name.len 
+		if(htid == ht->htid && name->len==ht->name.len
 				&& strncmp(name->s, ht->name.s, name->len)==0)
 		{
 			LM_ERR("htable already configured [%.*s]\n", name->len, name->s);
@@ -461,7 +461,7 @@ int ht_set_cell(ht_t *ht, str *name, int type, int_str *val, int mode)
 		return -1;
 
 	hid = ht_compute_hash(name);
-	
+
 	idx = ht_get_entry(hid, ht->htsize);
 
 	now = 0;
@@ -477,7 +477,7 @@ int ht_set_cell(ht_t *ht, str *name, int type, int_str *val, int mode)
 	}
 	while(it!=NULL && it->cellid == hid)
 	{
-		if(name->len==it->name.len 
+		if(name->len==it->name.len
 				&& strncmp(name->s, it->name.s, name->len)==0)
 		{
 			/* update value */
@@ -491,7 +491,7 @@ int ht_set_cell(ht_t *ht, str *name, int type, int_str *val, int mode)
 						it->value.s.len = val->s.len;
 						memcpy(it->value.s.s, val->s.s, val->s.len);
 						it->value.s.s[it->value.s.len] = '\0';
-						
+
 						if(ht->updateexpire)
 							it->expire = now + ht->htexpire;
 					} else {
@@ -602,20 +602,20 @@ int ht_del_cell(ht_t *ht, str *name)
 		return -1;
 
 	hid = ht_compute_hash(name);
-	
+
 	idx = ht_get_entry(hid, ht->htsize);
 
 	/* head test and return */
 	if(ht->entries[idx].first==NULL)
 		return 0;
-	
+
 	ht_slot_lock(ht, idx);
 	it = ht->entries[idx].first;
 	while(it!=NULL && it->cellid < hid)
 		it = it->next;
 	while(it!=NULL && it->cellid == hid)
 	{
-		if(name->len==it->name.len 
+		if(name->len==it->name.len
 				&& strncmp(name->s, it->name.s, name->len)==0)
 		{
 			/* found */
@@ -781,20 +781,20 @@ ht_cell_t* ht_cell_pkg_copy(ht_t *ht, str *name, ht_cell_t *old)
 		return NULL;
 
 	hid = ht_compute_hash(name);
-	
+
 	idx = ht_get_entry(hid, ht->htsize);
 
 	/* head test and return */
 	if(ht->entries[idx].first==NULL)
 		return NULL;
-	
+
 	ht_slot_lock(ht, idx);
 	it = ht->entries[idx].first;
 	while(it!=NULL && it->cellid < hid)
 		it = it->next;
 	while(it!=NULL && it->cellid == hid)
 	{
-		if(name->len==it->name.len 
+		if(name->len==it->name.len
 				&& strncmp(name->s, it->name.s, name->len)==0)
 		{
 			/* found */
@@ -938,12 +938,12 @@ int ht_table_spec(char *spec)
 			if(str2int(&tok, &updateexpire) != 0)
 				goto error;
 
-			LM_DBG("htable [%.*s] - updateexpire [%u]\n", name.len, name.s, updateexpire); 
+			LM_DBG("htable [%.*s] - updateexpire [%u]\n", name.len, name.s, updateexpire);
 		} else if(pit->name.len == 12 && strncmp(pit->name.s, "dmqreplicate", 12) == 0) {
 			if(str2int(&tok, &dmqreplicate) != 0)
 				goto error;
 
-			LM_DBG("htable [%.*s] - dmqreplicate [%u]\n", name.len, name.s, dmqreplicate); 
+			LM_DBG("htable [%.*s] - dmqreplicate [%u]\n", name.len, name.s, dmqreplicate);
 		} else { goto error; }
 	}
 
@@ -1129,7 +1129,7 @@ int ht_set_cell_expire(ht_t *ht, str *name, int type, int_str *val)
 		return 0;
 
 	hid = ht_compute_hash(name);
-	
+
 	idx = ht_get_entry(hid, ht->htsize);
 
 	now = 0;
@@ -1144,7 +1144,7 @@ int ht_set_cell_expire(ht_t *ht, str *name, int type, int_str *val)
 		it = it->next;
 	while(it!=NULL && it->cellid == hid)
 	{
-		if(name->len==it->name.len 
+		if(name->len==it->name.len
 				&& strncmp(name->s, it->name.s, name->len)==0)
 		{
 			/* update value */
@@ -1174,7 +1174,7 @@ int ht_get_cell_expire(ht_t *ht, str *name, unsigned int *val)
 		return 0;
 
 	hid = ht_compute_hash(name);
-	
+
 	idx = ht_get_entry(hid, ht->htsize);
 
 	now = time(NULL);
@@ -1184,7 +1184,7 @@ int ht_get_cell_expire(ht_t *ht, str *name, unsigned int *val)
 		it = it->next;
 	while(it!=NULL && it->cellid == hid)
 	{
-		if(name->len==it->name.len 
+		if(name->len==it->name.len
 				&& strncmp(name->s, it->name.s, name->len)==0)
 		{
 			/* update value */
@@ -1410,18 +1410,18 @@ int ht_count_cells_re(str *sre, ht_t *ht, int mode)
 								cnt++;
 						break;
 						case 2: /* rlike */
-							if(sval.len<=tval.len 
+							if(sval.len<=tval.len
 									&& strncmp(sval.s,
 										tval.s+tval.len-sval.len, sval.len)==0)
 								cnt++;
 						break;
 						case 3: /* llike */
-							if(sval.len<=tval.len 
+							if(sval.len<=tval.len
 									&& strncmp(sval.s, tval.s, sval.len)==0)
 								cnt++;
 						break;
 						case 4: /* str eq */
-							if(sval.len==tval.len 
+							if(sval.len==tval.len
 									&& strncmp(sval.s, tval.s, sval.len)==0)
 								cnt++;
 						break;

+ 5 - 5
modules/htable/ht_db.c

@@ -74,7 +74,7 @@ int ht_db_init_con(void)
 	if (!DB_CAPABILITY(ht_dbf, DB_CAP_ALL))
 	{
 		LM_ERR("database module does not "
-		    "implement all functions needed by the module\n");
+				"implement all functions needed by the module\n");
 		return -1;
 	}
 	return 0;
@@ -89,10 +89,10 @@ int ht_db_open_con(void)
 	ht_db_con = ht_dbf.init(&ht_db_url);
 	if(ht_db_con==NULL)
 	{
-		LM_ERR("failed to connect to the database\n");        
+		LM_ERR("failed to connect to the database\n");
 		return -1;
 	}
-	
+
 	LM_DBG("database connection opened successfully\n");
 	return 0;
 }
@@ -435,7 +435,7 @@ int ht_db_load_table(ht_t *ht, str *dbtable, int mode)
 							goto error;
 					}
 				}
-				
+
 				if(ht_set_cell(ht, &hname, (vtype)?0:AVP_VAL_STR, &val, mode))
 				{
 					LM_ERR("error adding to hash table\n");
@@ -451,7 +451,7 @@ int ht_db_load_table(ht_t *ht, str *dbtable, int mode)
 					}
 				}
 			}
-	 	}
+		}
 		if (DB_CAPABILITY(ht_dbf, DB_CAP_FETCH)) {
 			if(ht_dbf.fetch_result(ht_db_con, &db_res, ht_fetch_rows)<0) {
 				LM_ERR("Error while fetching!\n");

+ 26 - 25
modules/htable/ht_dmq.c

@@ -1,5 +1,5 @@
 /**
- * 
+ *
  * Copyright (C) 2013 Charles Chance (Sipcentric Ltd)
  *
  * This file is part of Kamailio, a free SIP server.
@@ -14,8 +14,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
  *
  */
@@ -50,13 +50,13 @@ int ht_dmq_initialize()
 {
 	dmq_peer_t not_peer;
 
-        /* load the DMQ API */
-        if (dmq_load_api(&ht_dmqb)!=0) {
-                LM_ERR("cannot load dmq api\n");
-                return -1;
-        } else {
-                LM_DBG("loaded dmq api\n");
-        }
+	/* load the DMQ API */
+	if (dmq_load_api(&ht_dmqb)!=0) {
+		LM_ERR("cannot load dmq api\n");
+		return -1;
+	} else {
+		LM_DBG("loaded dmq api\n");
+	}
 
 	not_peer.callback = ht_dmq_handle_msg;
 	not_peer.init_callback = NULL;
@@ -76,14 +76,15 @@ error:
 	return -1;
 }
 
-int ht_dmq_broadcast(str* body) {
-        if (!ht_dmq_peer) {
-                LM_ERR("ht_dmq_peer is null!\n");
-                return -1;
-        }
-        LM_DBG("sending broadcast...\n");
-        ht_dmqb.bcast_message(ht_dmq_peer, body, 0, &ht_dmq_resp_callback, 1, &ht_dmq_content_type);
-        return 0;
+int ht_dmq_broadcast(str* body)
+{
+	if (!ht_dmq_peer) {
+		LM_ERR("ht_dmq_peer is null!\n");
+		return -1;
+	}
+	LM_DBG("sending broadcast...\n");
+	ht_dmqb.bcast_message(ht_dmq_peer, body, 0, &ht_dmq_resp_callback, 1, &ht_dmq_content_type);
+	return 0;
 }
 
 /**
@@ -102,7 +103,7 @@ int ht_dmq_handle_msg(struct sip_msg* msg, peer_reponse_t* resp, dmq_node_t* dmq
 
 	/* received dmq message */
 	LM_DBG("dmq message received\n");
-	
+
 	if(!msg->content_length) {
 		LM_ERR("no content length header found\n");
 		goto invalid;
@@ -122,7 +123,7 @@ int ht_dmq_handle_msg(struct sip_msg* msg, peer_reponse_t* resp, dmq_node_t* dmq
 	}
 
 	/* parse body */
-	LM_DBG("body: %.*s\n", body.len, body.s);	
+	LM_DBG("body: %.*s\n", body.len, body.s);
 
 	srjson_InitDoc(&jdoc, NULL);
 	jdoc.buf = body;
@@ -160,7 +161,7 @@ int ht_dmq_handle_msg(struct sip_msg* msg, peer_reponse_t* resp, dmq_node_t* dmq
 			LM_ERR("unrecognized field in json object\n");
 			goto invalid;
 		}
-	}	
+	}
 
 	if (ht_dmq_replay_action(action, &htname, &cname, type, &val, mode)!=0) {
 		LM_ERR("failed to replay action\n");
@@ -181,7 +182,7 @@ invalid:
 error:
 	srjson_DestroyDoc(&jdoc);
 	resp->reason = dmq_500_rpl;
-	resp->resp_code = 500;	
+	resp->resp_code = 500;
 	return 0;
 }
 
@@ -189,7 +190,7 @@ int ht_dmq_replicate_action(ht_dmq_action_t action, str* htname, str* cname, int
 
 	srjson_doc_t jdoc;
 
-        LM_DBG("replicating action to dmq peers...\n");
+	LM_DBG("replicating action to dmq peers...\n");
 
 	srjson_InitDoc(&jdoc, NULL);
 
@@ -214,7 +215,7 @@ int ht_dmq_replicate_action(ht_dmq_action_t action, str* htname, str* cname, int
 		}
 	}
 
-	srjson_AddNumberToObject(&jdoc, jdoc.root, "mode", mode);	
+	srjson_AddNumberToObject(&jdoc, jdoc.root, "mode", mode);
 
 	jdoc.buf.s = srjson_PrintUnformatted(&jdoc, jdoc.root);
 	if(jdoc.buf.s!=NULL) {
@@ -251,7 +252,7 @@ int ht_dmq_replay_action(ht_dmq_action_t action, str* htname, str* cname, int ty
 		return -1;
 	}
 
-        LM_DBG("replaying action %d on %.*s=>%.*s...\n", action, htname->len, htname->s, cname->len, cname->s);
+	LM_DBG("replaying action %d on %.*s=>%.*s...\n", action, htname->len, htname->s, cname->len, cname->s);
 
 	if (action==HT_DMQ_SET_CELL) {
 		return ht_set_cell(ht, cname, type, val, mode);

+ 7 - 7
modules/htable/ht_var.c

@@ -18,7 +18,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
-		       
+
 #include "ht_api.h"
 #include "ht_var.h"
 #include "ht_dmq.h"
@@ -62,7 +62,7 @@ int pv_get_ht_cell(struct sip_msg *msg,  pv_param_t *param,
 
 	if(htc->flags&AVP_VAL_STR)
 		return pv_get_strval(msg, param, res, &htc->value.s);
-	
+
 	/* integer */
 	return pv_get_sintval(msg, param, res, htc->value.n);
 }
@@ -241,7 +241,7 @@ int pv_set_ht_cell_expire(struct sip_msg* msg, pv_param_t *param,
 	}
 	if (hpv->ht->dmqreplicate>0 && ht_dmq_replicate_action(HT_DMQ_SET_CELL_EXPIRE, &hpv->htname, &htname, 0, &isval, 0)!=0) {
 		LM_ERR("dmq relication failed\n");
-	}	
+	}
 	if(ht_set_cell_expire(hpv->ht, &htname, 0, &isval)!=0)
 	{
 		LM_ERR("cannot set $sht(%.*s)\n", htname.len, htname.s);
@@ -271,7 +271,7 @@ int pv_get_ht_cn(struct sip_msg *msg,  pv_param_t *param,
 		LM_ERR("cannot get $sht name\n");
 		return -1;
 	}
-	
+
 	cnt = ht_count_cells_re(&htname, hpv->ht, 0);
 
 	/* integer */
@@ -298,7 +298,7 @@ int pv_get_ht_cv(struct sip_msg *msg,  pv_param_t *param,
 		LM_ERR("cannot get $sht name\n");
 		return -1;
 	}
-	
+
 	cnt = ht_count_cells_re(&htname, hpv->ht, 1);
 
 	/* integer */
@@ -344,7 +344,7 @@ int pv_get_ht_add(struct sip_msg *msg,  pv_param_t *param,
 		if (ht_dmq_replicate_action(HT_DMQ_SET_CELL, &hpv->htname, &htname, 0, &htc->value, 1)!=0) {
 			LM_ERR("dmq relication failed\n");
 		}
-	}	
+	}
 	return pv_get_sintval(msg, param, res, htc->value.n);
 }
 
@@ -363,7 +363,7 @@ int pv_get_ht_dec(struct sip_msg *msg,  pv_param_t *param,
 int pv_parse_ht_expired_cell(pv_spec_t *sp, str *in)
 {
 	if ((in->len != 3 || strncmp(in->s, "key", in->len) != 0) &&
-	    (in->len != 5 || strncmp(in->s, "value", in->len) != 0))
+			(in->len != 5 || strncmp(in->s, "value", in->len) != 0))
 	{
 		return -1;
 	}

+ 7 - 7
modules/htable/htable.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
  */
 
@@ -250,7 +250,7 @@ static int child_init(int rank)
 
 	if (rank!=PROC_INIT)
 		return 0;
-	
+
 	rt = route_get(&event_rt, "htable:mod-init");
 	if(rt>=0 && event_rt.rlist[rt]!=NULL) {
 		LM_DBG("executing event_route[htable:mod-init] (%d)\n", rt);
@@ -573,7 +573,7 @@ static struct mi_root* ht_mi_reload(struct mi_root* cmd_tree, void* param)
 
 	if(ht_db_url.len<=0)
 		return init_mi_tree(500, MI_ERR_RELOAD, MI_ERR_RELOAD_LEN);
-	
+
 	if(ht_db_init_con()!=0)
 		return init_mi_tree(500, MI_ERR_RELOAD, MI_ERR_RELOAD_LEN);
 	if(ht_db_open_con()!=0)
@@ -884,7 +884,7 @@ static void htable_rpc_get(rpc_t* rpc, void* c) {
 			goto error;
 		}
 	}
-	
+
 error:
 	/* Release the allocated memory */
 	ht_cell_pkg_free(htc);
@@ -910,7 +910,7 @@ static void htable_rpc_sets(rpc_t* rpc, void* c) {
 		rpc->fault(c, 500, "No such htable");
 		return;
 	}
-	
+
 	if (ht->dmqreplicate>0 && ht_dmq_replicate_action(HT_DMQ_SET_CELL, &ht->name, &keyname, AVP_VAL_STR, &keyvalue, 1)!=0) {
 		LM_ERR("dmq relication failed\n");
 	}
@@ -948,7 +948,7 @@ static void htable_rpc_seti(rpc_t* rpc, void* c) {
 	if (ht->dmqreplicate>0 && ht_dmq_replicate_action(HT_DMQ_SET_CELL, &ht->name, &keyname, 0, &keyvalue, 1)!=0) {
 		LM_ERR("dmq relication failed\n");
 	}
-	
+
 	if(ht_set_cell(ht, &keyname, 0, &keyvalue, 1)!=0)
 	{
 		LM_ERR("cannot set $sht(%.*s=>%.*s)\n", htname.len, htname.s,