Przeglądaj źródła

tsilo: added ts_append_branches(uri)

- add current internal branches to the transaction stored for the uri
Daniel-Constantin Mierla 10 miesięcy temu
rodzic
commit
e9574d0833

+ 88 - 0
src/modules/tsilo/ts_append.c

@@ -168,3 +168,91 @@ done:
 
 	return ret;
 }
+
+
+/**
+ *
+ */
+int ts_append_branches(sip_msg_t *msg, str *ruri)
+{
+	ts_transaction_t *ptr = NULL;
+	ts_urecord_t *_r;
+	tm_cell_t *t = NULL;
+	tm_cell_t *orig_t = NULL;
+	sip_uri_t p_uri;
+	str *t_uri = NULL;
+	str contact = STR_NULL;
+	int orig_branch;
+	int res;
+
+	/* parse R-URI */
+	if(use_domain) {
+		t_uri = ruri;
+	} else {
+		if(parse_uri(ruri->s, ruri->len, &p_uri) < 0) {
+			LM_ERR("failed to parse uri %.*s\n", ruri->len, ruri->s);
+			return -1;
+		}
+		t_uri = &p_uri.user;
+	}
+
+	/* find urecord in TSILO cache */
+	lock_entry_by_ruri(t_uri);
+
+	res = get_ts_urecord(t_uri, &_r);
+
+	if(res != 0) {
+		LM_DBG("no record for %.*s\n", t_uri->len, t_uri->s);
+		unlock_entry_by_ruri(t_uri);
+		return -2;
+	}
+
+	/* cycle through existing transactions */
+	ptr = _r->transactions;
+
+	for(ptr = _r->transactions; ptr != NULL; ptr = ptr->next) {
+		LM_DBG("transaction %u:%u found for %.*s, going to append branches\n",
+				ptr->tindex, ptr->tlabel, t_uri->len, t_uri->s);
+
+		orig_t = _tmb.t_gett();
+		orig_branch = _tmb.t_gett_branch();
+
+		/* lookup a transaction based on its identifier (hash_index:label) */
+		if(_tmb.t_lookup_ident(&t, ptr->tindex, ptr->tlabel) < 0 || t == NULL) {
+			LM_ERR("transaction [%u:%u] not found\n", ptr->tindex, ptr->tlabel);
+			continue;
+		}
+
+		/* check if the dialog is still in the early stage */
+		if(t->flags & T_CANCELED) {
+			LM_DBG("transaction [%u:%u] was cancelled\n", ptr->tindex,
+					ptr->tlabel);
+			goto done;
+		}
+
+		if(t->uas.status >= 200) {
+			LM_DBG("transaction [%u:%u] sent out a final response already - "
+				   "%d\n",
+					ptr->tindex, ptr->tlabel, t->uas.status);
+			goto done;
+		}
+
+		/* if the contact has been given previously
+			then do a new append only for the desired location */
+		res = _tmb.t_append_branches(&contact);
+
+		if(res > 0) {
+			update_stat(added_branches, res);
+		}
+
+	done:
+		/* unref the transaction which had been referred by t_lookup_ident() call.
+		 * Restore the original transaction (if any) */
+		_tmb.unref_cell(t);
+		_tmb.t_sett(orig_t, orig_branch);
+	}
+
+	unlock_entry_by_ruri(t_uri);
+
+	return 1;
+}

+ 1 - 0
src/modules/tsilo/ts_append.h

@@ -25,5 +25,6 @@
 int ts_append(struct sip_msg *msg, str *ruri, str *contact, char *table);
 int ts_append_to(struct sip_msg *msg, int tindex, int tlabel, char *table,
 		str *uri, str *contact);
+int ts_append_branches(sip_msg_t *msg, str *ruri);
 
 #endif

+ 32 - 0
src/modules/tsilo/tsilo.c

@@ -68,6 +68,7 @@ static int w_ts_append_by_contact2(
 		struct sip_msg *_msg, char *_table, char *_ruri);
 static int w_ts_append_by_contact3(
 		struct sip_msg *_msg, char *_table, char *_ruri, char *_contact);
+static int w_ts_append_branches(struct sip_msg *_msg, char *_ruri, char *_p2);
 static int fixup_ts_append_by_contact(void **param, int param_no);
 static int w_ts_store(struct sip_msg *msg, char *p1, char *p2);
 static int w_ts_store1(struct sip_msg *msg, char *_ruri, char *p2);
@@ -91,6 +92,9 @@ static cmd_export_t cmds[] = {
 		{"ts_append_by_contact", (cmd_function)w_ts_append_by_contact3,
 				3, /* for three parameters */
 				fixup_ts_append_by_contact, 0, REQUEST_ROUTE | FAILURE_ROUTE},
+		{"ts_append_branches", (cmd_function)w_ts_append_branches, 1,
+				fixup_spve_null, fixup_free_spve_null,
+				REQUEST_ROUTE | FAILURE_ROUTE},
 		{"ts_store", (cmd_function)w_ts_store, 0, 0, 0,
 				REQUEST_ROUTE | FAILURE_ROUTE},
 		{"ts_store", (cmd_function)w_ts_store1, 1, fixup_spve_null, 0,
@@ -666,6 +670,34 @@ static int ki_ts_append_by_contact_uri(
 	return rc;
 }
 
+/**
+ *
+ */
+static int w_ts_append_branches(struct sip_msg *_msg, char *_ruri, char *_p2)
+{
+	str turi = STR_NULL;
+	str ruri = STR_NULL;
+	int rc;
+
+	if(_ruri == NULL
+			|| (fixup_get_svalue(_msg, (gparam_p)_ruri, &turi) != 0
+					|| turi.len <= 0)) {
+		LM_ERR("invalid ruri parameter\n");
+		return -1;
+	}
+	if(ts_check_uri(&turi) < 0)
+		return -1;
+
+	if(pkg_str_dup(&ruri, &turi) < 0)
+		return -1;
+
+	rc = ts_append_branches(_msg, &ruri);
+
+	pkg_free(ruri.s);
+
+	return rc;
+}
+
 /**
  *
  */