Browse code

select_buf: - get_static_buffer (meant for select calls which need extra space

- internal reset_static_buffer called before any request is processed

select_core:
select_uri_hostport returns host:port notation (default port value based on uri type)

select:
select structure contains new array param_offset and lvl - the nested level
number of params or particular nested level could be obtained by
param_offset[lvl+1]-param_offset[lvl]

Michal Matyska authored on 21/06/2006 19:11:58
Showing 5 changed files
... ...
@@ -57,7 +57,7 @@
57 57
 #include "script_cb.h"
58 58
 #include "dset.h"
59 59
 #include "usr_avp.h"
60
-
60
+#include "select_buf.h"
61 61
 
62 62
 #include "tcp_server.h" /* for tcpconn_add_alias */
63 63
 
... ...
@@ -119,6 +119,7 @@ int receive_msg(char* buf, unsigned int len, struct receive_info* rcv_info)
119 119
 
120 120
 	/* ... clear branches from previous message */
121 121
 	clear_branches();
122
+	reset_static_buffer();
122 123
 
123 124
 	if (msg->first_line.type==SIP_REQUEST){
124 125
 		/* sanity checks */
... ...
@@ -250,6 +250,7 @@ int resolve_select(select_t* s)
250 250
 		if (t->table[table_idx].flags & NESTED) {
251 251
 			if (nested < MAX_NESTED_CALLS-1) { /* need space for final function */
252 252
 				s->f[nested++] = f;
253
+				s->param_offset[nested] = param_idx+1;
253 254
 			} else {
254 255
 				BUG("MAX_NESTED_CALLS too small to resolve select\n");
255 256
 				goto not_found;
... ...
@@ -271,8 +272,9 @@ int resolve_select(select_t* s)
271 271
 	if ((nested>0) && (s->f[nested-1] == f)) {
272 272
 		BUG("Topmost nested function equals to final function, won't call it twice\n");
273 273
 	} else {
274
-		s->f[nested] = f;
274
+		s->f[nested++] = f;
275 275
 	}
276
+	s->param_offset[nested] = s->n;
276 277
 
277 278
 	return 0;
278 279
 
... ...
@@ -282,7 +284,7 @@ not_found:
282 282
 
283 283
 int run_select(str* res, select_t* s, struct sip_msg* msg)
284 284
 {
285
-	int ret, i;
285
+	int ret;
286 286
 
287 287
 	if (res == NULL) {
288 288
 		BUG("Select unprepared result space\n");
... ...
@@ -299,8 +301,8 @@ int run_select(str* res, select_t* s, struct sip_msg* msg)
299 299
 	DBG("Calling SELECT %p \n", s->f);
300 300
 
301 301
 	ret = 0;
302
-	for (i=0; (ret == 0) && (s->f[i] !=0 ) && (i<MAX_NESTED_CALLS); i++)	{
303
-		ret = s->f[i](res, s, msg);
302
+	for (s->lvl=0; (ret == 0) && (s->f[s->lvl] !=0 ) && (s->lvl<MAX_NESTED_CALLS); (s->lvl)++)	{
303
+		ret = s->f[s->lvl](res, s, msg);
304 304
 	}
305 305
 	return ret;
306 306
 }
... ...
@@ -119,8 +119,10 @@ typedef int (*select_f)(str* res, struct select* s, struct sip_msg* msg);
119 119
 
120 120
 typedef struct select {
121 121
 	select_f f[MAX_NESTED_CALLS];
122
+	int param_offset[MAX_NESTED_CALLS+1];
122 123
 	select_param_t params[MAX_SELECT_PARAMS];
123 124
 	int n;
125
+	int lvl;
124 126
 } select_t;
125 127
 
126 128
 typedef struct {
... ...
@@ -34,6 +34,7 @@
34 34
  
35 35
 #include "select.h"
36 36
 #include "select_core.h"
37
+#include "select_buf.h"
37 38
 #include "dprint.h"
38 39
 #include "trim.h"
39 40
 #include "parser/hf.h"
... ...
@@ -604,6 +605,45 @@ int select_uri_port(str* res, select_t* s, struct sip_msg* msg)
604 604
 	RETURN0_res(uri.port);
605 605
 }
606 606
 
607
+int select_uri_hostport(str* res, select_t* s, struct sip_msg* msg)
608
+{
609
+	char* p;
610
+	int size;
611
+	
612
+	if (parse_uri(res->s,res->len, &uri)<0)
613
+		return -1;
614
+
615
+	if (!uri.host.len)
616
+		return -1;
617
+	
618
+	if (uri.port.len) {
619
+		res->s=uri.host.s;
620
+		res->len=uri.host.len+uri.port.len+1;
621
+		return 0;
622
+	}
623
+	
624
+	size=uri.host.len+5;
625
+	if (!(p = get_static_buffer(size)))
626
+		return -1;
627
+			
628
+	strncpy(p, uri.host.s, uri.host.len);
629
+	switch (uri.type) {
630
+		case SIPS_URI_T:
631
+		case TELS_URI_T:
632
+			strncpy(p+uri.host.len, ":5061", 5); 
633
+			break;
634
+		case SIP_URI_T:
635
+		case TEL_URI_T:
636
+			strncpy(p+uri.host.len, ":5060", 5);
637
+			break;
638
+		case ERROR_URI_T:
639
+			return -1;
640
+	}
641
+	res->s = p;
642
+	res->len = size;
643
+	return 0;
644
+}
645
+
607 646
 int select_uri_params(str* res, select_t* s, struct sip_msg* msg)
608 647
 {
609 648
 	if (parse_uri(res->s, res->len, &uri)<0)
... ...
@@ -79,6 +79,7 @@ SELECT_F(select_uri_user)
79 79
 SELECT_F(select_uri_pwd)
80 80
 SELECT_F(select_uri_host)
81 81
 SELECT_F(select_uri_port)
82
+SELECT_F(select_uri_hostport)
82 83
 SELECT_F(select_uri_params)
83 84
 
84 85
 SELECT_F(select_event)
... ...
@@ -142,6 +143,7 @@ static select_row_t select_core[] = {
142 142
 	{ select_any_uri, SEL_PARAM_STR, STR_STATIC_INIT("host"), select_uri_host, 0},
143 143
 	{ select_any_uri, SEL_PARAM_STR, STR_STATIC_INIT("port"), select_uri_port, 0},
144 144
 	{ select_any_uri, SEL_PARAM_STR, STR_STATIC_INIT("params"), select_uri_params, 0},
145
+	{ select_any_uri, SEL_PARAM_STR, STR_STATIC_INIT("hostport"), select_uri_hostport, 0},
145 146
 	{ NULL, SEL_PARAM_STR, STR_STATIC_INIT("event"), select_event, 0},
146 147
 
147 148
 	{ NULL, SEL_PARAM_STR, STR_STATIC_INIT("record_route"), select_rr, 0},