Ver Fonte

tm: new function t_cell_append_branches(tindex, tlabel)

- append current branches to a specific transaction identified by index
  and label
Daniel-Constantin Mierla há 10 meses atrás
pai
commit
520be940f8

+ 48 - 0
src/modules/tm/t_append_branches.c

@@ -273,3 +273,51 @@ done:
 	}
 	return ret;
 }
+
+/**
+ *
+ */
+int t_cell_append_branches(int tindex, int tlabel)
+{
+	tm_cell_t *t = NULL;
+	/* a pointer to an existing transaction or 0 if lookup fails */
+	tm_cell_t *orig_t = NULL;
+	int ret;
+	int orig_branch;
+	str contact = STR_NULL;
+
+	orig_t = get_t();
+	orig_branch = get_t_branch();
+
+	/* lookup a transaction based on its identifier (hash_index:label) */
+	if(t_lookup_ident(&t, tindex, tlabel) < 0) {
+		LM_ERR("transaction [%u:%u] not found\n", tindex, tlabel);
+		ret = -1;
+		goto done;
+	}
+
+	/* check if the dialog is still in the early stage */
+	if(t->flags & T_CANCELED) {
+		LM_DBG("transaction [%u:%u] was cancelled\n", tindex, tlabel);
+		ret = -2;
+		goto done;
+	}
+
+	if(t->uas.status >= 200) {
+		LM_DBG("transaction [%u:%u] sent out a final response already - %d\n",
+				tindex, tlabel, t->uas.status);
+		ret = -3;
+		goto done;
+	}
+
+	ret = t_append_branches(&contact);
+
+done:
+	/* unref the transaction which had been referred by t_lookup_ident() call.
+	 * - restore the original transaction (if any) */
+	if(t)
+		unref_cell(t);
+	set_t(orig_t, orig_branch);
+
+	return ret;
+}

+ 2 - 0
src/modules/tm/t_append_branches.h

@@ -34,4 +34,6 @@
 int t_append_branches(str *contact);
 typedef int (*t_append_branches_f)(str *contact);
 
+int t_cell_append_branches(int tindex, int tlabel);
+
 #endif

+ 23 - 0
src/modules/tm/tm.c

@@ -212,6 +212,7 @@ static int w_t_get_status_code(sip_msg_t *msg, char *p1, char *p2);
 
 static int t_clean(struct sip_msg *msg, char *key, char *value);
 static int w_t_exists(struct sip_msg *msg, char *p1, char *p2);
+static int w_t_cell_append_branches(sip_msg_t *msg, char *pindex, char *plabel);
 
 /* by default the fr timers avps are not set, so that the avps won't be
  * searched for nothing each time a new transaction is created */
@@ -442,6 +443,8 @@ static cmd_export_t cmds[] = {
 	{"t_next_contact_flow", t_next_contact_flow, 0, 0, 0, REQUEST_ROUTE},
 	{"t_clean", t_clean, 0, 0, 0, ANY_ROUTE},
 	{"t_exists", w_t_exists, 0, 0, 0, ANY_ROUTE},
+	{"t_cell_append_branches", w_t_cell_append_branches, 2, fixup_igp_igp,
+			fixup_free_igp_igp, ANY_ROUTE},
 
 	/* not applicable from the script */
 	{"load_tm", (cmd_function)load_tm, NO_SCRIPT, 0, 0, 0},
@@ -3209,6 +3212,26 @@ static int w_t_exists(struct sip_msg *msg, char *p1, char *p2)
 	return ki_t_exists(msg);
 }
 
+static int w_t_cell_append_branches(sip_msg_t *msg, char *pindex, char *plabel)
+{
+	int tindex = 0;
+	int tlabel = 0;
+	int ret;
+
+	if(fixup_get_ivalue(msg, (gparam_t *)pindex, &tindex) != 0) {
+		LM_ERR("invalid index parameter\n");
+		return -1;
+	}
+	if(fixup_get_ivalue(msg, (gparam_t *)plabel, &tlabel) != 0) {
+		LM_ERR("invalid label parameter\n");
+		return -1;
+	}
+
+	ret = t_cell_append_branches(tindex, tlabel);
+
+	return (ret == 0) ? 1 : ret;
+}
+
 #ifdef USE_DNS_FAILOVER
 /* parse reply codes for failover given in module parameter */
 static int t_failover_parse_reply_codes()