Browse code

@method returns METHOD string within request select_method

t_relay does not return error when the transaction was already started by t_newtran
so from now you can use in the script:
if (!t_newtran) drop; # avoid retransmission processing
...some time consuming action
t_relay();

Michal Matyska authored on 29/06/2006 10:34:13
Showing 3 changed files
... ...
@@ -212,15 +212,20 @@ int t_relay_to( struct sip_msg  *p_msg , struct proxy_l *proxy, int proto,
212 212
 	/* parsing error, memory alloc, whatever ... if via is bad
213 213
 	   and we are forced to reply there, return with 0 (->break),
214 214
 	   pass error status otherwise
215
+
216
+       MMA: return value E_SCRIPT means that transaction was already started from the script
217
+	   so continue with that transaction
215 218
 	*/
216
-	if (new_tran<0) {
217
-		ret = (ser_error==E_BAD_VIA && reply_to_via) ? 0 : new_tran;
218
-		goto done;
219
-	}
220
-	/* if that was a retransmission, return we are happily done */
221
-	if (new_tran==0) {
222
-		ret = 1;
223
-		goto done;
219
+	if (new_tran!=E_SCRIPT) {
220
+		if (new_tran<0) {
221
+			ret = (ser_error==E_BAD_VIA && reply_to_via) ? 0 : new_tran;
222
+			goto done;
223
+		}
224
+		/* if that was a retransmission, return we are happily done */
225
+		if (new_tran==0) {
226
+			ret = 1;
227
+			goto done;
228
+		}
224 229
 	}
225 230
 
226 231
 	/* new transaction */
... ...
@@ -57,6 +57,13 @@
57 57
 #define TEST_RET_res_body(x) if (x){*res=x->body;return 0;}else return 1;
58 58
 #define TEST_RET_res_value(x) if (x){*res=x->value;return 0;}else return 1;
59 59
 
60
+int select_method(str* res, select_t* s, struct sip_msg* msg)
61
+{
62
+	if (msg->first_line.type==SIP_REQUEST) {
63
+		RETURN0_res(msg->first_line.u.request.method);
64
+	} else return -1;
65
+}
66
+
60 67
 int select_ruri(str* res, select_t* s, struct sip_msg* msg)
61 68
 {
62 69
 	if (msg->first_line.type==SIP_REQUEST) {
... ...
@@ -67,7 +74,7 @@ int select_ruri(str* res, select_t* s, struct sip_msg* msg)
67 74
 			RETURN0_res(msg->first_line.u.request.uri);
68 75
 		}
69 76
 	}
70
-	return 1;
77
+	return -1;
71 78
 }
72 79
 
73 80
 int select_from(str* res, select_t* s, struct sip_msg* msg)
... ...
@@ -117,15 +124,15 @@ int select_from_params(str* res, select_t* s, struct sip_msg* msg)
117 124
 
118 125
 int parse_to_header(struct sip_msg *msg)
119 126
 {
120
-        if ( !msg->to && ( parse_headers(msg,HDR_TO_F,0)==-1 || !msg->to)) {
121
-                ERR("bad msg or missing TO header\n");
122
-                return -1;
123
-        }
127
+	if ( !msg->to && ( parse_headers(msg,HDR_TO_F,0)==-1 || !msg->to)) {
128
+		ERR("bad msg or missing TO header\n");
129
+		return -1;
130
+	}
124 131
 
125
-        // HDR_TO_T is automatically parsed (get_hdr_field in parser/msg_parser.c)
126
-        // so check only ptr validity
127
-        if (msg->to->parsed)
128
-                return 0;
132
+	// HDR_TO_T is automatically parsed (get_hdr_field in parser/msg_parser.c)
133
+	// so check only ptr validity
134
+	if (msg->to->parsed)
135
+		return 0;
129 136
 	else
130 137
 		return -1;
131 138
 }
... ...
@@ -61,6 +61,7 @@ enum {
61 61
 	SEL_AUTH_QOP
62 62
 };
63 63
 
64
+SELECT_F(select_method)
64 65
 SELECT_F(select_ruri)
65 66
 SELECT_F(select_from)
66 67
 SELECT_F(select_from_uri)
... ...
@@ -120,6 +121,7 @@ SELECT_F(select_auth_username)
120 121
 SELECT_F(select_auth_username_comp)
121 122
 
122 123
 static select_row_t select_core[] = {
124
+	{ NULL, SEL_PARAM_STR, STR_STATIC_INIT("method"), select_method, 0},
123 125
 	{ NULL, SEL_PARAM_STR, STR_STATIC_INIT("ruri"), select_ruri, 0},
124 126
 	{ select_ruri, SEL_PARAM_STR, STR_NULL, select_any_uri, NESTED},
125 127
 	{ NULL, SEL_PARAM_STR, STR_STATIC_INIT("from"), select_from, 0},