浏览代码

topos: proper storage of dlg data for persistence

Daniel-Constantin Mierla 9 年之前
父节点
当前提交
5654079944
共有 4 个文件被更改,包括 170 次插入11 次删除
  1. 5 5
      modules/topos/topos_mod.c
  2. 5 5
      modules/topos/tps_msg.c
  3. 152 1
      modules/topos/tps_storage.c
  4. 8 0
      modules/topos/tps_storage.h

+ 5 - 5
modules/topos/topos_mod.c

@@ -64,7 +64,7 @@ MODULE_VERSION
 /* Database connection handle */
 db1_con_t* _tps_db_handle = NULL;
 /* DB functions */
-db_func_t tpsdbf;
+db_func_t _tpsdbf;
 /* sruid to get internal uid */
 sruid_t _tps_sruid;
 
@@ -116,11 +116,11 @@ struct module_exports exports= {
 static int mod_init(void)
 {
 	/* Find a database module */
-	if (db_bind_mod(&_tps_db_url, &tpsdbf)) {
+	if (db_bind_mod(&_tps_db_url, &_tpsdbf)) {
 		LM_ERR("unable to bind database module\n");
 		return -1;
 	}
-	if (!DB_CAPABILITY(tpsdbf, DB_CAP_ALL)) {
+	if (!DB_CAPABILITY(_tpsdbf, DB_CAP_ALL)) {
 		LM_CRIT("database modules does not "
 			"provide all functions needed\n");
 		return -1;
@@ -163,7 +163,7 @@ static int child_init(int rank)
 	if (rank==PROC_INIT || rank==PROC_MAIN || rank==PROC_TCP_MAIN)
 		return 0; /* do nothing for the main process */
 
-	_tps_db_handle = tpsdbf.init(&_tps_db_url);
+	_tps_db_handle = _tpsdbf.init(&_tps_db_url);
 	if (!_tps_db_handle) {
 		LM_ERR("unable to connect database\n");
 		return -1;
@@ -178,7 +178,7 @@ static int child_init(int rank)
 static void destroy(void)
 {
 	if (_tps_db_handle) {
-		tpsdbf.close(_tps_db_handle);
+		_tpsdbf.close(_tps_db_handle);
 		_tps_db_handle = 0;
 	}
 	tps_storage_lock_set_destroy();

+ 5 - 5
modules/topos/tps_msg.c

@@ -97,7 +97,7 @@ int tps_get_param_value(str *in, str *name, str *value)
 			return 0;
 		}
 	}
-	
+
 	if(params) free_params(params);
 	return 1;
 
@@ -254,7 +254,7 @@ int tps_route_direction(sip_msg_t *msg)
 		LM_DBG("no route header - downstream\n");
 		return 0;
 	}
-	if (parse_rr(msg->route) < 0) 
+	if (parse_rr(msg->route) < 0)
 	{
 		LM_ERR("failed to parse route header\n");
 		return -1;
@@ -434,7 +434,7 @@ int tps_pack_request(sip_msg_t *msg, tps_data_t *ptsd)
 int tps_reinsert_via(sip_msg_t *msg, tps_data_t *ptsd, str *hbody)
 {
 	str hname = str_init("Via");
-	
+
 	if(tps_add_headers(msg, &hname, hbody, 1)<0) {
 		return -1;
 	}
@@ -448,7 +448,7 @@ int tps_reinsert_via(sip_msg_t *msg, tps_data_t *ptsd, str *hbody)
 int tps_reinsert_contact(sip_msg_t *msg, tps_data_t *ptsd, str *hbody)
 {
 	str hname = str_init("Contact");
-	
+
 	if(tps_add_headers(msg, &hname, hbody, 0)<0) {
 		return -1;
 	}
@@ -494,7 +494,7 @@ int tps_request_sent(sip_msg_t *msg, int dialog, int direction, int local)
 		if(get_cseq(msg)->method_id==METHOD_ACK
 				|| get_cseq(msg)->method_id==METHOD_CANCEL
 				|| local==2) {
-			// th_mask_callid(&msg);
+			// ts_mask_callid(&msg);
 			goto done;
 		} else {
 			/* should be for upstream */

+ 152 - 1
modules/topos/tps_storage.c

@@ -45,7 +45,10 @@
 
 extern sruid_t _tps_sruid;
 
-#define TPS_STORAGE_LOCK_SIZE	1<<8
+extern db1_con_t* _tps_db_handle;
+extern db_func_t _tpsdbf;
+
+#define TPS_STORAGE_LOCK_SIZE	1<<9
 static gen_lock_set_t *_tps_storage_lock_set = NULL;
 
 /**
@@ -238,3 +241,151 @@ int tps_storage_record(sip_msg_t *msg, tps_data_t *td)
 	if(ret<0) return ret;
 	return tps_storage_fill_contact(msg, td, TPS_DIR_UPSTREAM);
 }
+
+
+/**
+ * database storage
+ */
+str td_col_rectime = str_init("rectime");
+str td_col_a_callid = str_init("a_callid");
+str td_col_a_uuid = str_init("a_uuid");
+str td_col_b_uuid = str_init("b_uuid");
+str td_col_a_contact = str_init("a_contact");
+str td_col_b_contact = str_init("b_contact");
+str td_col_as_contact = str_init("as_contact");
+str td_col_bs_contact = str_init("bs_contact");
+str td_col_a_tag = str_init("a_tag");
+str td_col_b_tag = str_init("b_tag");
+str td_col_a_rr = str_init("a_rr");
+str td_col_b_rr = str_init("b_rr");
+str td_col_iflags = str_init("iflags");
+str td_col_a_uri = str_init("a_uri");
+str td_col_b_uri = str_init("b_uri");
+str td_col_r_uri = str_init("r_uri");
+str td_col_a_srcip = str_init("a_srcip");
+str td_col_b_srcip = str_init("b_srcip");
+
+str tt_col_rectime = str_init("rectime");
+str tt_col_a_callid = str_init("a_callid");
+str tt_col_a_uuid = str_init("a_uuid");
+str tt_col_b_uuid = str_init("b_uuid");
+str tt_col_direction = str_init("direction");
+str tt_col_x_via = str_init("x_via");
+str tt_col_x_tag = str_init("x_tag");
+
+#define TPS_NR_KEYS	32
+
+/**
+ *
+ */
+int tps_db_insert_dialog(tps_data_t *td)
+{
+	db_key_t db_keys[TPS_NR_KEYS];
+	db_val_t db_vals[TPS_NR_KEYS];
+	int nr_keys;
+
+	memset(db_keys, 0, TPS_NR_KEYS*sizeof(db_key_t));
+	memset(db_vals, 0, TPS_NR_KEYS*sizeof(db_val_t));
+	nr_keys = 0;
+
+	db_keys[nr_keys] = &td_col_rectime;
+	db_vals[nr_keys].type = DB1_INT;
+	db_vals[nr_keys].val.int_val = (int)time(NULL);
+	nr_keys++;
+
+	db_keys[nr_keys] = &td_col_a_callid;
+	db_vals[nr_keys].type = DB1_STR;
+	db_vals[nr_keys].val.str_val = td->a_callid;
+	nr_keys++;
+
+	db_keys[nr_keys] = &td_col_a_uuid;
+	db_vals[nr_keys].type = DB1_STR;
+	db_vals[nr_keys].val.str_val = td->a_uuid;
+	nr_keys++;
+
+	db_keys[nr_keys] = &td_col_b_uuid;
+	db_vals[nr_keys].type = DB1_STR;
+	db_vals[nr_keys].val.str_val = td->b_uuid;
+	nr_keys++;
+
+	db_keys[nr_keys] = &td_col_a_contact;
+	db_vals[nr_keys].type = DB1_STR;
+	db_vals[nr_keys].val.str_val = td->a_contact;
+	nr_keys++;
+
+	db_keys[nr_keys] = &td_col_b_contact;
+	db_vals[nr_keys].type = DB1_STR;
+	db_vals[nr_keys].val.str_val = td->b_contact;
+	nr_keys++;
+
+	db_keys[nr_keys] = &td_col_as_contact;
+	db_vals[nr_keys].type = DB1_STR;
+	db_vals[nr_keys].val.str_val = td->as_contact;
+	nr_keys++;
+
+	db_keys[nr_keys] = &td_col_bs_contact;
+	db_vals[nr_keys].type = DB1_STR;
+	db_vals[nr_keys].val.str_val = td->bs_contact;
+	nr_keys++;
+
+	db_keys[nr_keys] = &td_col_a_tag;
+	db_vals[nr_keys].type = DB1_STR;
+	db_vals[nr_keys].val.str_val = td->a_tag;
+	nr_keys++;
+
+	db_keys[nr_keys] = &td_col_b_tag;
+	db_vals[nr_keys].type = DB1_STR;
+	db_vals[nr_keys].val.str_val = td->b_tag;
+	nr_keys++;
+
+	db_keys[nr_keys] = &td_col_a_rr;
+	db_vals[nr_keys].type = DB1_STR;
+	db_vals[nr_keys].val.str_val = td->a_rr;
+	nr_keys++;
+
+	db_keys[nr_keys] = &td_col_b_rr;
+	db_vals[nr_keys].type = DB1_STR;
+	db_vals[nr_keys].val.str_val = td->b_rr;
+	nr_keys++;
+
+	db_keys[nr_keys] = &td_col_iflags;
+	db_vals[nr_keys].type = DB1_INT;
+	db_vals[nr_keys].val.int_val = td->iflags;
+	nr_keys++;
+
+	db_keys[nr_keys] = &td_col_a_uri;
+	db_vals[nr_keys].type = DB1_STR;
+	db_vals[nr_keys].val.str_val = td->a_uri;
+	nr_keys++;
+
+	db_keys[nr_keys] = &td_col_b_uri;
+	db_vals[nr_keys].type = DB1_STR;
+	db_vals[nr_keys].val.str_val = td->b_uri;
+	nr_keys++;
+
+	db_keys[nr_keys] = &td_col_r_uri;
+	db_vals[nr_keys].type = DB1_STR;
+	db_vals[nr_keys].val.str_val = td->r_uri;
+	nr_keys++;
+
+	db_keys[nr_keys] = &td_col_a_srcip;
+	db_vals[nr_keys].type = DB1_STR;
+	db_vals[nr_keys].val.str_val = td->a_srcip;
+	nr_keys++;
+
+	db_keys[nr_keys] = &td_col_b_srcip;
+	db_vals[nr_keys].type = DB1_STR;
+	db_vals[nr_keys].val.str_val = td->b_srcip;
+	nr_keys++;
+
+	if(_tpsdbf.insert(_tps_db_handle, db_keys, db_vals, nr_keys) < 0)
+	{
+		LM_ERR("failed to store message\n");
+		goto error;
+	}
+
+	return 0;
+
+error:
+	return -1;
+}

+ 8 - 0
modules/topos/tps_storage.h

@@ -47,9 +47,17 @@ typedef struct tps_data {
 	str b_contact;
 	str as_contact;
 	str bs_contact;
+	str a_tag;
+	str b_tag;
+	str a_uri;
+	str b_uri;
+	str r_uri;
+	str a_srcip;
+	str b_srcip;
 	str x_via1;
 	str x_via2;
 	str x_vbranch1;
+	int32_t iflags;
 } tps_data_t;
 
 int tps_storage_dialog_find(sip_msg_t *msg, tps_data_t *td);