Forráskód Böngészése

Added new function t_lookup_cancel. The function returns true if
tm knows about the transaction and the request is canceable.
Note: the functions accepts only CANCEL requests.

Nils Ohlmeier 19 éve
szülő
commit
25faad89e2
1 módosított fájl, 25 hozzáadás és 0 törlés
  1. 25 0
      modules/tm/tm.c

+ 25 - 0
modules/tm/tm.c

@@ -130,6 +130,7 @@ static int child_init(int rank);
 
 
 /* exported functions */
 /* exported functions */
 inline static int w_t_check(struct sip_msg* msg, char* str, char* str2);
 inline static int w_t_check(struct sip_msg* msg, char* str, char* str2);
+inline static int w_t_lookup_cancel(struct sip_msg* msg, char* str, char* str2);
 inline static int w_t_reply(struct sip_msg* msg, char* str, char* str2);
 inline static int w_t_reply(struct sip_msg* msg, char* str, char* str2);
 inline static int w_t_release(struct sip_msg* msg, char* str, char* str2);
 inline static int w_t_release(struct sip_msg* msg, char* str, char* str2);
 inline static int w_t_retransmit_reply(struct sip_msg* p_msg, char* foo,
 inline static int w_t_retransmit_reply(struct sip_msg* p_msg, char* foo,
@@ -192,6 +193,8 @@ static cmd_export_t cmds[]={
 			REQUEST_ROUTE},
 			REQUEST_ROUTE},
 	{"t_lookup_request",   w_t_check,               0, 0,
 	{"t_lookup_request",   w_t_check,               0, 0,
 			REQUEST_ROUTE},
 			REQUEST_ROUTE},
+	{"t_lookup_cancel",    w_t_lookup_cancel,     0, 0,
+			REQUEST_ROUTE},
 	{T_REPLY,              w_t_reply,               2, fixup_t_reply,
 	{T_REPLY,              w_t_reply,               2, fixup_t_reply,
 			REQUEST_ROUTE | FAILURE_ROUTE },
 			REQUEST_ROUTE | FAILURE_ROUTE },
 	{"t_retransmit_reply", w_t_retransmit_reply,    0, 0,
 	{"t_retransmit_reply", w_t_retransmit_reply,    0, 0,
@@ -629,6 +632,28 @@ inline static int w_t_check(struct sip_msg* msg, char* str, char* str2)
 	return t_check( msg , 0  ) ? 1 : -1;
 	return t_check( msg , 0  ) ? 1 : -1;
 }
 }
 
 
+inline static int w_t_lookup_cancel(struct sip_msg* msg, char* str, char* str2)
+{
+	struct cell *ret;
+	if (msg->REQ_METHOD==METHOD_CANCEL) {
+		if (t_check( msg , 0 )==-1) {
+			LOG(L_WARN, "WARNING: t_lookup_cancel() failed to find transaction\n");
+			return -1;
+		}
+		ret = t_lookupOriginalT( msg );
+		DBG("lookup_original: t_lookupOriginalT returned: %p\n", ret);
+		if (ret != T_NULL_CELL) {
+			/* The cell is reffed by t_lookupOriginalT, but T is not set.
+			So we must unref it before returning. */
+			UNREF(ret);
+			return 1;
+		}
+	} else {
+		LOG(L_WARN, "WARNING: script error t_lookup_cancel() called for non-CANCEL request\n");
+	}
+	return -1;
+}
+
 inline static int str2proto(char *s, int len) {
 inline static int str2proto(char *s, int len) {
 	if (len == 3 && !strncasecmp(s, "udp", 3))
 	if (len == 3 && !strncasecmp(s, "udp", 3))
 		return PROTO_UDP;
 		return PROTO_UDP;