Browse code

topos: reset the flags of dlg storage record on bye

Daniel-Constantin Mierla authored on 30/03/2016 11:41:40
Showing 3 changed files
... ...
@@ -908,6 +908,10 @@ int tps_request_sent(sip_msg_t *msg, int dialog, int local)
908 908
 		tps_reinsert_contact(msg, ptsd, &ptsd->bs_contact);
909 909
 	}
910 910
 
911
+	if(dialog!=0) {
912
+		tps_storage_end_dialog(msg, &mtsd, ptsd);
913
+	}
914
+
911 915
 done:
912 916
 	tps_storage_lock_release(&lkey);
913 917
 	return 0;
... ...
@@ -978,7 +978,6 @@ int tps_storage_update_dialog(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd)
978 978
 	db1_res_t* db_res = NULL;
979 979
 	int nr_keys;
980 980
 	int nr_ucols;
981
-	int n;
982 981
 	int ret;
983 982
 
984 983
 	if(msg==NULL || md==NULL || sd==NULL || _tps_db_handle==NULL)
... ...
@@ -1055,6 +1054,72 @@ int tps_storage_update_dialog(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd)
1055 1054
 	return 0;
1056 1055
 }
1057 1056
 
1057
+/**
1058
+ *
1059
+ */
1060
+int tps_storage_end_dialog(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd)
1061
+{
1062
+	db_key_t db_keys[4];
1063
+	db_op_t  db_ops[4];
1064
+	db_val_t db_vals[4];
1065
+	db_key_t db_ucols[TPS_NR_KEYS];
1066
+	db_val_t db_uvals[TPS_NR_KEYS];
1067
+	db1_res_t* db_res = NULL;
1068
+	int nr_keys;
1069
+	int nr_ucols;
1070
+
1071
+	if(msg==NULL || md==NULL || sd==NULL || _tps_db_handle==NULL)
1072
+		return -1;
1073
+
1074
+	if(md->s_method_id != METHOD_BYE) {
1075
+		return 0;
1076
+	}
1077
+
1078
+	memset(db_ucols, 0, TPS_NR_KEYS*sizeof(db_key_t));
1079
+	memset(db_uvals, 0, TPS_NR_KEYS*sizeof(db_val_t));
1080
+
1081
+	nr_keys = 0;
1082
+	nr_ucols = 0;
1083
+
1084
+	db_keys[nr_keys]=&td_col_a_uuid;
1085
+	db_ops[nr_keys]=OP_EQ;
1086
+	db_vals[nr_keys].type = DB1_STR;
1087
+	db_vals[nr_keys].nul = 0;
1088
+	if(sd->a_uuid.len>0 && sd->a_uuid.s[0]=='a') {
1089
+		db_vals[nr_keys].val.str_val = TPS_STRZ(sd->a_uuid);
1090
+	} else {
1091
+		if(sd->b_uuid.len<=0) {
1092
+			LM_ERR("no valid dlg uuid\n");
1093
+			return -1;
1094
+		}
1095
+		db_vals[nr_keys].val.str_val = TPS_STRZ(sd->b_uuid);
1096
+	}
1097
+	nr_keys++;
1098
+
1099
+	db_ucols[nr_ucols] = &td_col_rectime;
1100
+	db_uvals[nr_ucols].type = DB1_DATETIME;
1101
+	db_uvals[nr_ucols].val.time_val = time(NULL);
1102
+	nr_ucols++;
1103
+
1104
+	db_ucols[nr_ucols] = &td_col_iflags;
1105
+	db_uvals[nr_ucols].type = DB1_INT;
1106
+	db_uvals[nr_ucols].val.int_val = 0;
1107
+	nr_ucols++;
1108
+
1109
+	if (_tpsdbf.use_table(_tps_db_handle, &td_table_name) < 0) {
1110
+		LM_ERR("failed to perform use table\n");
1111
+		return -1;
1112
+	}
1113
+
1114
+	if(_tpsdbf.update(_tps_db_handle, db_keys, db_ops, db_vals,
1115
+				db_ucols, db_uvals, nr_keys, nr_ucols)!=0) {
1116
+		LM_ERR("failed to do db update for [%.*s]!\n",
1117
+				md->a_uuid.len, md->a_uuid.s);
1118
+		return -1;
1119
+	}
1120
+	return 0;
1121
+}
1122
+
1058 1123
 /**
1059 1124
  *
1060 1125
  */
... ...
@@ -85,6 +85,7 @@ int tps_storage_load_branch(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd);
85 85
 int tps_storage_update_branch(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd);
86 86
 int tps_storage_load_dialog(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd);
87 87
 int tps_storage_update_dialog(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd);
88
+int tps_storage_end_dialog(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd);
88 89
 
89 90
 int tps_storage_lock_set_init(void);
90 91
 int tps_storage_lock_get(str *lkey);