Bläddra i källkod

cnxcc: minor changes

* use [PKG|SHM]_MEM_ERROR
* use memset and avoid initialization per field
* init variables
* add cnxcc to lgtm build
* use localtime_r() for a safer multi-thread usage
* replaced deprecated STR_PARAM with PARAM_STR
* clean includes
* clang-format
Victor Seva 5 år sedan
förälder
incheckning
e98457faf2

+ 2 - 1
.lgtm.yml

@@ -8,6 +8,7 @@ extraction:
       - "libcurl4-openssl-dev"
       - "libjansson-dev"
       - "libhiredis-dev"
+      - "libevent-dev"
       - "liblua5.1-0-dev"
       - "libpcre3-dev"
       - "libncurses5-dev"
@@ -24,6 +25,6 @@ extraction:
     after_prepare:
     - "export PKG_CONFIG_PATH=$LGTM_WORKSPACE/usr/lib/pkgconfig:$PKG_CONFIG_PATH"
     configure:
-      command: "make include_modules='app_lua app_python3 db_mysql db_postgres db_redis dialplan http_client jansson lcr ndb_redis presence presence_xml presence_dialoginfo pua pua_dialoginfo topos_redis uuid websocket xmlops' cfg"
+      command: "make include_modules='app_lua app_python3 cnxcc db_mysql db_postgres db_redis dialplan http_client jansson lcr ndb_redis presence presence_xml presence_dialoginfo pua pua_dialoginfo topos_redis uuid websocket xmlops' cfg"
     index:
       build_command: "make all"

+ 1 - 3
src/modules/cnxcc/cnxcc.c

@@ -19,10 +19,8 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  *
  */
-#include <time.h>
-#include <string.h>
+
 #include <stdlib.h>
-#include <sys/time.h>
 
 #include "cnxcc.h"
 

+ 5 - 3
src/modules/cnxcc/cnxcc.h

@@ -23,6 +23,8 @@
 #ifndef _CNXCC_H
 #define _CNXCC_H
 
+#include <time.h>
+
 #include "../../core/str.h"
 
 #define DATETIME_SIZE sizeof("0001-01-01 00:00:00")
@@ -37,12 +39,12 @@ static inline unsigned int get_current_timestamp()
 static inline int timestamp2isodt(str *dest, unsigned int timestamp)
 {
 	time_t tim;
-	struct tm *tmPtr;
+	struct tm tmPtr;
 
 	tim = timestamp;
-	tmPtr = localtime(&tim);
+	localtime_r(&tim, &tmPtr);
 
-	strftime(dest->s, DATETIME_SIZE, "%Y-%m-%d %H:%M:%S", tmPtr);
+	strftime(dest->s, DATETIME_SIZE, "%Y-%m-%d %H:%M:%S", &tmPtr);
 	dest->len = DATETIME_LENGTH;
 
 	return 0;

+ 36 - 88
src/modules/cnxcc/cnxcc_mod.c

@@ -27,32 +27,28 @@
 #include <sys/ipc.h>
 #include <unistd.h>
 #include <fcntl.h>
-#include <time.h>
 #include <ctype.h>
 
 #include "../../core/sr_module.h"
+#include "../../core/mod_fix.h"
 #include "../../core/dprint.h"
 #include "../../core/error.h"
 #include "../../core/mem/mem.h"
-#include "../../core/shm_init.h"
 #include "../../core/mem/shm_mem.h"
-#include "../../core/pvar.h"
-#include "../../core/locking.h"
+
 #include "../../core/lock_ops.h"
-#include "../../core/str_hash.h"
 #include "../../core/timer_proc.h"
-#include "../../modules/tm/tm_load.h"
 #include "../../core/parser/parse_from.h"
 #include "../../core/parser/parse_to.h"
 #include "../../core/parser/parse_uri.h"
 #include "../../core/parser/parse_cseq.h"
 #include "../../core/parser/contact/parse_contact.h"
 #include "../../core/parser/contact/contact.h"
-#include "../../core/parser/parse_rr.h"
-#include "../../core/mod_fix.h"
+
+#include "../tm/tm_load.h"
 #include "../dialog/dlg_load.h"
 #include "../dialog/dlg_hash.h"
-#include "../../core/fmsg.h"
+
 #include "../../core/rpc.h"
 #include "../../core/rpc_lookup.h"
 #include "../../core/kemi.h"
@@ -170,7 +166,7 @@ static cmd_export_t cmds[] = {
 static param_export_t params[] = {
 	{"dlg_flag", INT_PARAM,	&_data.ctrl_flag },
 	{"credit_check_period", INT_PARAM,	&_data.check_period },
-	{"redis", STR_PARAM, &_data.redis_cnn_str.s },
+	{"redis", PARAM_STR, &_data.redis_cnn_str },
 	{ 0, 0, 0 }
 };
 /* clang-format on */
@@ -262,9 +258,6 @@ static int __mod_init(void)
 		return -1;
 	}
 
-	if(_data.redis_cnn_str.s)
-		_data.redis_cnn_str.len = strlen(_data.redis_cnn_str.s);
-
 	_data.time.credit_data_by_client =
 			shm_malloc(sizeof(struct str_hash_table));
 	_data.time.call_data_by_cid = shm_malloc(sizeof(struct str_hash_table));
@@ -284,15 +277,11 @@ static int __mod_init(void)
 	memset(_data.channel.call_data_by_cid, 0, sizeof(struct str_hash_table));
 
 	_data.stats = (stats_t *)shm_malloc(sizeof(stats_t));
-
 	if(!_data.stats) {
-		LM_ERR("Error allocating shared memory stats\n");
+		SHM_MEM_ERROR;
 		return -1;
 	}
-
-	_data.stats->active = 0;
-	_data.stats->dropped = 0;
-	_data.stats->total = 0;
+	memset(_data.stats, 0, sizeof(stats_t));
 
 	if(__init_hashtable(_data.time.credit_data_by_client) != 0)
 		return -1;
@@ -312,9 +301,7 @@ static int __mod_init(void)
 	if(__init_hashtable(_data.channel.call_data_by_cid) != 0)
 		return -1;
 
-
 	cnxcc_lock_init(_data.lock);
-
 	cnxcc_lock_init(_data.time.lock);
 	cnxcc_lock_init(_data.money.lock);
 	cnxcc_lock_init(_data.channel.lock);
@@ -433,21 +420,22 @@ static int __child_init(int rank)
 
 static int __init_hashtable(struct str_hash_table *ht)
 {
-	if(__shm_str_hash_alloc(ht, HT_SIZE) != 0) {
-		LM_ERR("Error allocating shared memory hashtable\n");
+	if(ht == NULL)
+		return -1;
+
+	if(__shm_str_hash_alloc(ht, HT_SIZE) != 0)
 		return -1;
-	}
 
 	str_hash_init(ht);
 	return 0;
 }
 
 static void __dialog_created_callback(
-		struct dlg_cell *cell, int type, struct dlg_cb_params *params)
+		struct dlg_cell *cell, int type, struct dlg_cb_params *_params)
 {
 	struct sip_msg *msg = NULL;
 
-	msg = params->direction == SIP_REPLY ? params->rpl : params->req;
+	msg = _params->direction == SIP_REPLY ? _params->rpl : _params->req;
 
 	if(msg == NULL) {
 		LM_ERR("Error getting direction of SIP msg\n");
@@ -471,7 +459,7 @@ static void __dialog_created_callback(
 }
 
 static void __dialog_confirmed_callback(
-		struct dlg_cell *cell, int type, struct dlg_cb_params *params)
+		struct dlg_cell *cell, int type, struct dlg_cb_params *_params)
 {
 	LM_DBG("Dialog confirmed for CID [%.*s]\n", cell->callid.len,
 			cell->callid.s);
@@ -480,7 +468,7 @@ static void __dialog_confirmed_callback(
 }
 
 static void __dialog_terminated_callback(
-		struct dlg_cell *cell, int type, struct dlg_cb_params *params)
+		struct dlg_cell *cell, int type, struct dlg_cb_params *_params)
 {
 	LM_DBG("Dialog terminated for CID [%.*s]\n", cell->callid.len,
 			cell->callid.s);
@@ -915,7 +903,7 @@ static void __start_billing(
 	 * Store from-tag value
 	 */
 	if(shm_str_dup(&call->sip_data.from_tag, &tags[0]) != 0) {
-		LM_ERR("No more pkg memory\n");
+		SHM_MEM_ERROR;
 		goto exit;
 	}
 
@@ -923,13 +911,13 @@ static void __start_billing(
 	 * Store to-tag value
 	 */
 	if(shm_str_dup(&call->sip_data.to_tag, &tags[1]) != 0) {
-		LM_ERR("No more pkg memory\n");
+		SHM_MEM_ERROR;
 		goto exit;
 	}
 
 	if(shm_str_dup(&call->sip_data.from_uri, from_uri) != 0
 			|| shm_str_dup(&call->sip_data.to_uri, to_uri) != 0) {
-		LM_ERR("No more pkg memory\n");
+		SHM_MEM_ERROR;
 		goto exit;
 	}
 
@@ -1089,9 +1077,10 @@ static int __shm_str_hash_alloc(struct str_hash_table *ht, int size)
 {
 	ht->table = shm_malloc(sizeof(struct str_hash_head) * size);
 
-	if(!ht->table)
+	if(!ht->table) {
+		SHM_MEM_ERROR;
 		return -1;
-
+	}
 	ht->size = size;
 	return 0;
 }
@@ -1110,7 +1099,7 @@ int terminate_call(call_t *call)
 			call->dlg_h_entry);
 
 	data = &call->sip_data;
-	if(faked_msg_init_with_dlg_info(&data->callid, &data->from_uri,
+	if(cnxcc_faked_msg_init_with_dlg_info(&data->callid, &data->from_uri,
 			   &data->from_tag, &data->to_uri, &data->to_tag, &dmsg)
 			!= 0) {
 		LM_ERR("[%.*s]: error generating faked sip message\n", data->callid.len,
@@ -1197,7 +1186,7 @@ static credit_data_t *__get_or_create_credit_data_entry(
 	return (credit_data_t *)e->u.p;
 
 no_memory:
-	LM_ERR("No shared memory left\n");
+	SHM_MEM_ERROR;
 	return NULL;
 }
 
@@ -1205,17 +1194,13 @@ static credit_data_t *__alloc_new_credit_data(
 		str *client_id, credit_type_t type)
 {
 	credit_data_t *credit_data = shm_malloc(sizeof(credit_data_t));
-	;
-
 	if(credit_data == NULL)
 		goto no_memory;
-
 	memset(credit_data, 0, sizeof(credit_data_t));
 
 	cnxcc_lock_init(credit_data->lock);
 
 	credit_data->call_list = shm_malloc(sizeof(call_t));
-
 	if(credit_data->call_list == NULL)
 		goto no_memory;
 
@@ -1231,7 +1216,6 @@ static credit_data_t *__alloc_new_credit_data(
 
 	if(_data.redis) {
 		credit_data->str_id = shm_malloc(client_id->len + 1);
-
 		if(!credit_data->str_id)
 			goto no_memory;
 
@@ -1239,14 +1223,7 @@ static credit_data_t *__alloc_new_credit_data(
 		snprintf(credit_data->str_id, client_id->len + 1, "%.*s",
 				client_id->len, client_id->s);
 	}
-
-	credit_data->max_amount = 0;
-	credit_data->concurrent_calls = 0;
-	credit_data->consumed_amount = 0;
-	credit_data->ended_calls_consumed_amount = 0;
-	credit_data->number_of_calls = 0;
 	credit_data->type = type;
-	credit_data->deallocating = 0;
 
 	if(!_data.redis)
 		return credit_data;
@@ -1257,7 +1234,7 @@ static credit_data_t *__alloc_new_credit_data(
 	return credit_data;
 
 no_memory:
-	LM_ERR("No shared memory left\n");
+	SHM_MEM_ERROR;
 error:
 	return NULL;
 }
@@ -1277,9 +1254,10 @@ static call_t *__alloc_new_call_by_money(credit_data_t *credit_data,
 
 	call = shm_malloc(sizeof(call_t));
 	if(call == NULL) {
-		LM_ERR("No shared memory left\n");
+		SHM_MEM_ERROR;
 		goto error;
 	}
+	memset(call, 0, sizeof(call_t));
 
 	if((!msg->callid && parse_headers(msg, HDR_CALLID_F, 0) != 0)
 			|| shm_str_dup(&call->sip_data.callid, &msg->callid->body) != 0) {
@@ -1287,16 +1265,6 @@ static call_t *__alloc_new_call_by_money(credit_data_t *credit_data,
 		goto error;
 	}
 
-	call->sip_data.to_uri.s = NULL;
-	call->sip_data.to_uri.len = 0;
-	call->sip_data.to_tag.s = NULL;
-	call->sip_data.to_tag.len = 0;
-
-	call->sip_data.from_uri.s = NULL;
-	call->sip_data.from_uri.len = 0;
-	call->sip_data.from_tag.s = NULL;
-	call->sip_data.from_tag.len = 0;
-
 	call->consumed_amount = initial_pulse * cost_per_second;
 	call->connect_amount = connect_cost;
 	call->confirmed = FALSE;
@@ -1356,6 +1324,7 @@ static call_t *__alloc_new_call_by_time(
 		LM_ERR("No shared memory left\n");
 		goto error;
 	}
+	memset(call, 0, sizeof(call_t));
 
 	if((!msg->callid && parse_headers(msg, HDR_CALLID_F, 0) != 0)
 			|| shm_str_dup(&call->sip_data.callid, &msg->callid->body) != 0) {
@@ -1363,16 +1332,6 @@ static call_t *__alloc_new_call_by_time(
 		goto error;
 	}
 
-	call->sip_data.to_uri.s = NULL;
-	call->sip_data.to_uri.len = 0;
-	call->sip_data.to_tag.s = NULL;
-	call->sip_data.to_tag.len = 0;
-
-	call->sip_data.from_uri.s = NULL;
-	call->sip_data.from_uri.len = 0;
-	call->sip_data.from_tag.s = NULL;
-	call->sip_data.from_tag.len = 0;
-
 	call->consumed_amount = 0;
 	call->confirmed = FALSE;
 	call->max_amount = max_secs;
@@ -1423,9 +1382,10 @@ static call_t *alloc_new_call_by_channel(
 
 	call = shm_malloc(sizeof(call_t));
 	if(call == NULL) {
-		LM_ERR("No shared memory left\n");
+		SHM_MEM_ERROR;
 		goto error;
 	}
+	memset(call, 0, sizeof(call_t));
 
 	if((!msg->callid && parse_headers(msg, HDR_CALLID_F, 0) != 0)
 			|| shm_str_dup(&call->sip_data.callid, &msg->callid->body) != 0) {
@@ -1433,16 +1393,6 @@ static call_t *alloc_new_call_by_channel(
 		goto error;
 	}
 
-	call->sip_data.to_uri.s = NULL;
-	call->sip_data.to_uri.len = 0;
-	call->sip_data.to_tag.s = NULL;
-	call->sip_data.to_tag.len = 0;
-
-	call->sip_data.from_uri.s = NULL;
-	call->sip_data.from_uri.len = 0;
-	call->sip_data.from_tag.s = NULL;
-	call->sip_data.from_tag.len = 0;
-
 	call->consumed_amount = 0;
 	call->confirmed = FALSE;
 	call->max_amount = max_chan;
@@ -1534,14 +1484,13 @@ static int __add_call_by_cid(str *cid, call_t *call, credit_type_t type)
 	}
 
 	e = shm_malloc(sizeof(struct str_hash_entry));
-
 	if(e == NULL) {
-		LM_ERR("No shared memory left\n");
+		SHM_MEM_ERROR;
 		return -1;
 	}
 
 	if(shm_str_dup(&e->key, cid) != 0) {
-		LM_ERR("No shared memory left\n");
+		SHM_MEM_ERROR;
 		return -1;
 	}
 
@@ -1961,6 +1910,10 @@ static int __set_max_time(sip_msg_t *msg, char *pclient, char *pmaxsecs)
 static int ki_update_max_time(sip_msg_t *msg, str *sclient, int secs)
 {
 	credit_data_t *credit_data = NULL;
+	struct str_hash_table *ht = NULL;
+	struct str_hash_entry *e = NULL;
+	double update_fraction = secs;
+	call_t *call = NULL, *tmp_call = NULL;
 
 	set_ctrl_flag(msg);
 
@@ -1985,12 +1938,7 @@ static int ki_update_max_time(sip_msg_t *msg, str *sclient, int secs)
 			sclient->len, sclient->s, secs, msg->callid->body.len,
 			msg->callid->body.s);
 
-
-	struct str_hash_table *ht = NULL;
-	struct str_hash_entry *e = NULL;
 	ht = _data.time.credit_data_by_client;
-	double update_fraction = secs;
-	call_t *call = NULL, *tmp_call = NULL;
 
 	cnxcc_lock(_data.time.lock);
 	e = str_hash_get(ht, sclient->s, sclient->len);

+ 7 - 5
src/modules/cnxcc/cnxcc_mod.h

@@ -25,7 +25,7 @@
 #include "../../core/locking.h"
 #include "../../core/atomic_ops.h"
 #include "../../core/str_hash.h"
-#include "../../core/parser/parse_rr.h"
+#include "../../core/flags.h"
 
 #define str_shm_free_if_not_null(_var_) \
 	if(_var_.s != NULL) {               \
@@ -35,7 +35,7 @@
 	}
 
 /*!
- * \brief Init a cnxcc_lock 
+ * \brief Init a cnxcc_lock
  * \param _entry locked entry
  */
 #define cnxcc_lock_init(_entry) \
@@ -89,13 +89,15 @@ typedef struct stats
 	unsigned int dropped;
 } stats_t;
 
-typedef enum cnxpvtypes {
+typedef enum cnxpvtypes
+{
 	CNX_PV_ACTIVE = 1,
 	CNX_PV_TOTAL,
 	CNX_PV_DROPPED
 } cnxpvtypes_t;
 
-typedef enum credit_type {
+typedef enum credit_type
+{
 	CREDIT_TIME,
 	CREDIT_MONEY,
 	CREDIT_CHANNEL
@@ -212,7 +214,7 @@ typedef struct credit_data
 
 	char *str_id;
 	// flag to mark this instance in the process of being eliminated
-	int deallocating : 1;
+	unsigned int deallocating : 1;
 } credit_data_t;
 
 

+ 21 - 8
src/modules/cnxcc/cnxcc_redis.c

@@ -144,9 +144,18 @@ error:
 static struct redis *__alloc_redis(char *ip, int port, int db)
 {
 	struct redis *redis = pkg_malloc(sizeof(struct redis));
+	if(!redis) {
+		PKG_MEM_ERROR;
+		return NULL;
+	}
 	int len = strlen(ip);
 
 	redis->ip = pkg_malloc(len + 1);
+	if(!redis->ip) {
+		PKG_MEM_ERROR;
+		pkg_free(redis);
+		return NULL;
+	}
 	strcpy(redis->ip, ip);
 
 	redis->port = port;
@@ -226,8 +235,7 @@ static struct redis *__redis_connect(struct redis *redis)
 
 static int __redis_select_db(redisContext *ctxt, int db)
 {
-	redisReply *rpl;
-	rpl = redisCommand(ctxt, "SELECT %d", db);
+	redisReply *rpl = redisCommand(ctxt, "SELECT %d", db);
 
 	if(!rpl || rpl->type == REDIS_REPLY_ERROR) {
 		if(!rpl)
@@ -245,7 +253,7 @@ static int __redis_select_db(redisContext *ctxt, int db)
 static int __redis_exec(
 		credit_data_t *credit_data, const char *cmd, redisReply **rpl)
 {
-	redisReply *rpl_aux;
+	redisReply *rpl_aux = NULL;
 	char cmd_buffer[1024];
 
 	*rpl = redisCommand(_data.redis->ctxt, cmd);
@@ -300,7 +308,7 @@ int redis_incr_by_double(
 int redis_get_double(credit_data_t *credit_data, const char *instruction,
 		const char *key, double *value)
 {
-	str str_double = {0, 0};
+	str str_double = STR_NULL;
 	char buffer[128];
 
 	if(redis_get_str(credit_data, instruction, key, &str_double) < 0)
@@ -389,6 +397,11 @@ int redis_get_str(credit_data_t *credit_data, const char *instruction,
 	}
 
 	value->s = pkg_malloc(rpl->len);
+	if(!value->s) {
+		PKG_MEM_ERROR;
+		freeReplyObject(rpl);
+		return -1;
+	}
 	value->len = rpl->len;
 	memcpy(value->s, rpl->str, rpl->len);
 
@@ -516,7 +529,7 @@ int redis_insert_double_value(
 
 int redis_kill_list_member_exists(credit_data_t *credit_data)
 {
-	redisReply *rpl;
+	redisReply *rpl = NULL;
 	int exists = 0;
 	char cmd_buffer[1024];
 
@@ -552,7 +565,7 @@ static void __redis_subscribe_to_kill_list(struct redis *redis)
 
 int redis_publish_to_kill_list(credit_data_t *credit_data)
 {
-	redisReply *rpl;
+	redisReply *rpl = NULL;
 	char cmd_buffer[1024];
 	snprintf(cmd_buffer, sizeof(cmd_buffer), "PUBLISH cnxcc:kill_list %s",
 			credit_data->str_id);
@@ -578,8 +591,8 @@ static void __async_disconnect_cb(const redisAsyncContext *c, int status)
 static void __subscription_cb(redisAsyncContext *c, void *r, void *privdata)
 {
 	redisReply *reply = r;
-	str key;
-	credit_data_t *credit_data;
+	str key = STR_NULL;
+	credit_data_t *credit_data = NULL;
 
 	if(reply == NULL) {
 		LM_ERR("reply is NULL\n");

+ 13 - 21
src/modules/cnxcc/cnxcc_rpc.c

@@ -22,18 +22,16 @@
 
 #include <stdio.h>
 
-#include "../../core/rpc.h"
-#include "../../core/rpc_lookup.h"
-
+#include "cnxcc_rpc.h"
 #include "cnxcc_mod.h"
 
 extern data_t _data;
 
 void rpc_kill_call(rpc_t *rpc, void *ctx)
 {
-	call_t *call;
-	hash_tables_t *hts;
-	str callid;
+	call_t *call = NULL;
+	hash_tables_t *hts = NULL;
+	str callid = STR_NULL;
 
 	if(!rpc->scan(ctx, "S", &callid)) {
 		LM_ERR("%s: error reading RPC param\n", __FUNCTION__);
@@ -65,11 +63,12 @@ void rpc_kill_call(rpc_t *rpc, void *ctx)
 
 void rpc_check_client_stats(rpc_t *rpc, void *ctx)
 {
-	call_t *call, *tmp;
+	call_t *call = NULL, *tmp = NULL;
 	int index = 0;
-	str client_id, rows;
+	str client_id = STR_NULL;
+	str rows = STR_NULL;
 	char row_buffer[512];
-	credit_data_t *credit_data;
+	credit_data_t *credit_data = NULL;
 
 	if(!rpc->scan(ctx, "S", &client_id)) {
 		LM_ERR("%s: error reading RPC param\n", __FUNCTION__);
@@ -98,9 +97,7 @@ void rpc_check_client_stats(rpc_t *rpc, void *ctx)
 		return;
 	}
 
-	rows.len = 0;
 	rows.s = pkg_malloc(10);
-
 	if(rows.s == NULL)
 		goto nomem;
 
@@ -137,7 +134,6 @@ void rpc_check_client_stats(rpc_t *rpc, void *ctx)
 
 		row_len = strlen(row_buffer);
 		rows.s = pkg_reallocxf(rows.s, rows.len + row_len);
-
 		if(rows.s == NULL) {
 			cnxcc_unlock(credit_data->lock);
 			goto nomem;
@@ -161,14 +157,14 @@ void rpc_check_client_stats(rpc_t *rpc, void *ctx)
 	return;
 
 nomem:
-	LM_ERR("No more pkg memory\n");
+	PKG_MEM_ERROR;
 	rpc->fault(ctx, 500, "No more memory\n");
 }
 
 static int iterate_over_table(
 		hash_tables_t *hts, str *result, credit_type_t type)
 {
-	struct str_hash_entry *h_entry, *tmp;
+	struct str_hash_entry *h_entry = NULL, *tmp = NULL;
 	char row_buffer[512];
 	int index = 0;
 
@@ -223,7 +219,6 @@ static int iterate_over_table(
 
 				row_len = strlen(row_buffer);
 				result->s = pkg_reallocxf(result->s, result->len + row_len);
-
 				if(result->s == NULL) {
 					cnxcc_unlock(hts->lock);
 					goto nomem;
@@ -238,21 +233,18 @@ static int iterate_over_table(
 	return 0;
 
 nomem:
-	LM_ERR("No more pkg memory\n");
+	PKG_MEM_ERROR;
 	return -1;
 }
 
 void rpc_active_clients(rpc_t *rpc, void *ctx)
 {
-	str rows;
+	str rows = STR_NULL;
 
 	rows.s = pkg_malloc(10);
-
 	if(rows.s == NULL)
 		goto nomem;
 
-	rows.len = 0;
-
 	iterate_over_table(&_data.time, &rows, CREDIT_TIME);
 	iterate_over_table(&_data.money, &rows, CREDIT_MONEY);
 
@@ -266,6 +258,6 @@ void rpc_active_clients(rpc_t *rpc, void *ctx)
 	return;
 
 nomem:
-	LM_ERR("No more pkg memory\n");
+	PKG_MEM_ERROR;
 	rpc->fault(ctx, 500, "No more memory\n");
 }

+ 2 - 0
src/modules/cnxcc/cnxcc_rpc.h

@@ -23,6 +23,8 @@
 #ifndef CNXCC_RPC_H_
 #define CNXCC_RPC_H_
 
+#include "../../core/rpc.h"
+
 void rpc_active_clients(rpc_t *rpc, void *ctx);
 void rpc_kill_call(rpc_t *rpc, void *ctx);
 void rpc_active_clients(rpc_t *rpc, void *ctx);

+ 2 - 2
src/modules/cnxcc/cnxcc_select.c

@@ -20,9 +20,9 @@
  *
  */
 
-#include "../../core/select.h"
-#include "../../core/select_buf.h"
+#include "../../core/ut.h"
 
+#include "cnxcc_select.h"
 #include "cnxcc_mod.h"
 
 extern data_t _data;

+ 3 - 0
src/modules/cnxcc/cnxcc_select.h

@@ -23,6 +23,9 @@
 #ifndef CNXCC_SELECT_H_
 #define CNXCC_SELECT_H_
 
+#include "../../core/str.h"
+#include "../../core/select.h"
+
 int sel_root(str *res, select_t *s, struct sip_msg *msg);
 int sel_channels(str *res, select_t *s, struct sip_msg *msg);
 int sel_channels_count(str *res, select_t *s, struct sip_msg *msg);

+ 9 - 8
src/modules/cnxcc/cnxcc_sip_msg_faker.c

@@ -20,29 +20,30 @@
  *
  */
 
+#include <sys/socket.h>
+
 #include "../../core/parser/msg_parser.h"
 #include "../../core/globals.h"
 
-#include <sys/socket.h>
-
 #define FAKED_SIP_MSG_FORMAT                                                 \
 	"OPTIONS sip:[email protected] SIP/2.0\r\nVia: SIP/2.0/UDP "              \
 	"127.0.0.1\r\nFrom: <%.*s>;tag=%.*s\r\nTo: <%.*s>;tag=%.*s\r\nCall-ID: " \
 	"%.*s\r\nCSeq: 1 OPTIONS\r\nContent-Length: 0\r\n\r\n"
 
 #define FAKED_SIP_MSG_BUF_LEN 1024
-char _faked_sip_msg_buf[FAKED_SIP_MSG_BUF_LEN];
+static char _faked_sip_msg_buf[FAKED_SIP_MSG_BUF_LEN];
 
 static struct sip_msg _faked_msg;
 
-int faked_msg_init_with_dlg_info(str *callid, str *from_uri, str *from_tag,
-		str *to_uri, str *to_tag, struct sip_msg **msg)
+int cnxcc_faked_msg_init_with_dlg_info(str *callid, str *from_uri,
+		str *from_tag, str *to_uri, str *to_tag, struct sip_msg **msg)
 {
 	memset(_faked_sip_msg_buf, 0, FAKED_SIP_MSG_BUF_LEN);
+	memset(&_faked_msg, 0, sizeof(struct sip_msg));
 
-	snprintf(_faked_sip_msg_buf, FAKED_SIP_MSG_BUF_LEN, FAKED_SIP_MSG_FORMAT, from_uri->len,
-			from_uri->s, from_tag->len, from_tag->s, to_uri->len, to_uri->s,
-			to_tag->len, to_tag->s, callid->len, callid->s);
+	snprintf(_faked_sip_msg_buf, FAKED_SIP_MSG_BUF_LEN, FAKED_SIP_MSG_FORMAT,
+			from_uri->len, from_uri->s, from_tag->len, from_tag->s, to_uri->len,
+			to_uri->s, to_tag->len, to_tag->s, callid->len, callid->s);
 
 	LM_DBG("fake msg:\n%s\n", _faked_sip_msg_buf);
 

+ 4 - 2
src/modules/cnxcc/cnxcc_sip_msg_faker.h

@@ -22,7 +22,9 @@
 #ifndef CNXCC_SIP_MSG_FAKER_H_
 #define CNXCC_SIP_MSG_FAKER_H_
 
-int faked_msg_init_with_dlg_info(str *callid, str *from_uri, str *from_tag,
-		str *to_uri, str *to_tag, struct sip_msg **msg);
+#include "../../core/str.h"
+
+int cnxcc_faked_msg_init_with_dlg_info(str *callid, str *from_uri,
+		str *from_tag, str *to_uri, str *to_tag, struct sip_msg **msg);
 
 #endif /* CNXCC_SIP_MSG_FAKER_H_ */