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 272
 	if ((nested>0) && (s->f[nested-1] == f)) {
272 273
 		BUG("Topmost nested function equals to final function, won't call it twice\n");
273 274
 	} else {
274
-		s->f[nested] = f;
275
+		s->f[nested++] = f;
275 276
 	}
277
+	s->param_offset[nested] = s->n;
276 278
 
277 279
 	return 0;
278 280
 
... ...
@@ -282,7 +284,7 @@ not_found:
282 284
 
283 285
 int run_select(str* res, select_t* s, struct sip_msg* msg)
284 286
 {
285
-	int ret, i;
287
+	int ret;
286 288
 
287 289
 	if (res == NULL) {
288 290
 		BUG("Select unprepared result space\n");
... ...
@@ -299,8 +301,8 @@ int run_select(str* res, select_t* s, struct sip_msg* msg)
299 301
 	DBG("Calling SELECT %p \n", s->f);
300 302
 
301 303
 	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);
304
+	for (s->lvl=0; (ret == 0) && (s->f[s->lvl] !=0 ) && (s->lvl<MAX_NESTED_CALLS); (s->lvl)++)	{
305
+		ret = s->f[s->lvl](res, s, msg);
304 306
 	}
305 307
 	return ret;
306 308
 }
... ...
@@ -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 605
 	RETURN0_res(uri.port);
605 606
 }
606 607
 
608
+int select_uri_hostport(str* res, select_t* s, struct sip_msg* msg)
609
+{
610
+	char* p;
611
+	int size;
612
+	
613
+	if (parse_uri(res->s,res->len, &uri)<0)
614
+		return -1;
615
+
616
+	if (!uri.host.len)
617
+		return -1;
618
+	
619
+	if (uri.port.len) {
620
+		res->s=uri.host.s;
621
+		res->len=uri.host.len+uri.port.len+1;
622
+		return 0;
623
+	}
624
+	
625
+	size=uri.host.len+5;
626
+	if (!(p = get_static_buffer(size)))
627
+		return -1;
628
+			
629
+	strncpy(p, uri.host.s, uri.host.len);
630
+	switch (uri.type) {
631
+		case SIPS_URI_T:
632
+		case TELS_URI_T:
633
+			strncpy(p+uri.host.len, ":5061", 5); 
634
+			break;
635
+		case SIP_URI_T:
636
+		case TEL_URI_T:
637
+			strncpy(p+uri.host.len, ":5060", 5);
638
+			break;
639
+		case ERROR_URI_T:
640
+			return -1;
641
+	}
642
+	res->s = p;
643
+	res->len = size;
644
+	return 0;
645
+}
646
+
607 647
 int select_uri_params(str* res, select_t* s, struct sip_msg* msg)
608 648
 {
609 649
 	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 143
 	{ select_any_uri, SEL_PARAM_STR, STR_STATIC_INIT("host"), select_uri_host, 0},
143 144
 	{ select_any_uri, SEL_PARAM_STR, STR_STATIC_INIT("port"), select_uri_port, 0},
144 145
 	{ select_any_uri, SEL_PARAM_STR, STR_STATIC_INIT("params"), select_uri_params, 0},
146
+	{ select_any_uri, SEL_PARAM_STR, STR_STATIC_INIT("hostport"), select_uri_hostport, 0},
145 147
 	{ NULL, SEL_PARAM_STR, STR_STATIC_INIT("event"), select_event, 0},
146 148
 
147 149
 	{ NULL, SEL_PARAM_STR, STR_STATIC_INIT("record_route"), select_rr, 0},