Ver código fonte

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 19 anos atrás
pai
commit
8c5e4afe14
5 arquivos alterados com 52 adições e 5 exclusões
  1. 2 1
      receive.c
  2. 6 4
      select.c
  3. 2 0
      select.h
  4. 40 0
      select_core.c
  5. 2 0
      select_core.h

+ 2 - 1
receive.c

@@ -57,7 +57,7 @@
 #include "script_cb.h"
 #include "dset.h"
 #include "usr_avp.h"
-
+#include "select_buf.h"
 
 #include "tcp_server.h" /* for tcpconn_add_alias */
 
@@ -119,6 +119,7 @@ int receive_msg(char* buf, unsigned int len, struct receive_info* rcv_info)
 
 	/* ... clear branches from previous message */
 	clear_branches();
+	reset_static_buffer();
 
 	if (msg->first_line.type==SIP_REQUEST){
 		/* sanity checks */

+ 6 - 4
select.c

@@ -250,6 +250,7 @@ int resolve_select(select_t* s)
 		if (t->table[table_idx].flags & NESTED) {
 			if (nested < MAX_NESTED_CALLS-1) { /* need space for final function */
 				s->f[nested++] = f;
+				s->param_offset[nested] = param_idx+1;
 			} else {
 				BUG("MAX_NESTED_CALLS too small to resolve select\n");
 				goto not_found;
@@ -271,8 +272,9 @@ int resolve_select(select_t* s)
 	if ((nested>0) && (s->f[nested-1] == f)) {
 		BUG("Topmost nested function equals to final function, won't call it twice\n");
 	} else {
-		s->f[nested] = f;
+		s->f[nested++] = f;
 	}
+	s->param_offset[nested] = s->n;
 
 	return 0;
 
@@ -282,7 +284,7 @@ not_found:
 
 int run_select(str* res, select_t* s, struct sip_msg* msg)
 {
-	int ret, i;
+	int ret;
 
 	if (res == NULL) {
 		BUG("Select unprepared result space\n");
@@ -299,8 +301,8 @@ int run_select(str* res, select_t* s, struct sip_msg* msg)
 	DBG("Calling SELECT %p \n", s->f);
 
 	ret = 0;
-	for (i=0; (ret == 0) && (s->f[i] !=0 ) && (i<MAX_NESTED_CALLS); i++)	{
-		ret = s->f[i](res, s, msg);
+	for (s->lvl=0; (ret == 0) && (s->f[s->lvl] !=0 ) && (s->lvl<MAX_NESTED_CALLS); (s->lvl)++)	{
+		ret = s->f[s->lvl](res, s, msg);
 	}
 	return ret;
 }

+ 2 - 0
select.h

@@ -119,8 +119,10 @@ typedef int (*select_f)(str* res, struct select* s, struct sip_msg* msg);
 
 typedef struct select {
 	select_f f[MAX_NESTED_CALLS];
+	int param_offset[MAX_NESTED_CALLS+1];
 	select_param_t params[MAX_SELECT_PARAMS];
 	int n;
+	int lvl;
 } select_t;
 
 typedef struct {

+ 40 - 0
select_core.c

@@ -34,6 +34,7 @@
  
 #include "select.h"
 #include "select_core.h"
+#include "select_buf.h"
 #include "dprint.h"
 #include "trim.h"
 #include "parser/hf.h"
@@ -604,6 +605,45 @@ int select_uri_port(str* res, select_t* s, struct sip_msg* msg)
 	RETURN0_res(uri.port);
 }
 
+int select_uri_hostport(str* res, select_t* s, struct sip_msg* msg)
+{
+	char* p;
+	int size;
+	
+	if (parse_uri(res->s,res->len, &uri)<0)
+		return -1;
+
+	if (!uri.host.len)
+		return -1;
+	
+	if (uri.port.len) {
+		res->s=uri.host.s;
+		res->len=uri.host.len+uri.port.len+1;
+		return 0;
+	}
+	
+	size=uri.host.len+5;
+	if (!(p = get_static_buffer(size)))
+		return -1;
+			
+	strncpy(p, uri.host.s, uri.host.len);
+	switch (uri.type) {
+		case SIPS_URI_T:
+		case TELS_URI_T:
+			strncpy(p+uri.host.len, ":5061", 5); 
+			break;
+		case SIP_URI_T:
+		case TEL_URI_T:
+			strncpy(p+uri.host.len, ":5060", 5);
+			break;
+		case ERROR_URI_T:
+			return -1;
+	}
+	res->s = p;
+	res->len = size;
+	return 0;
+}
+
 int select_uri_params(str* res, select_t* s, struct sip_msg* msg)
 {
 	if (parse_uri(res->s, res->len, &uri)<0)

+ 2 - 0
select_core.h

@@ -79,6 +79,7 @@ SELECT_F(select_uri_user)
 SELECT_F(select_uri_pwd)
 SELECT_F(select_uri_host)
 SELECT_F(select_uri_port)
+SELECT_F(select_uri_hostport)
 SELECT_F(select_uri_params)
 
 SELECT_F(select_event)
@@ -142,6 +143,7 @@ static select_row_t select_core[] = {
 	{ select_any_uri, SEL_PARAM_STR, STR_STATIC_INIT("host"), select_uri_host, 0},
 	{ select_any_uri, SEL_PARAM_STR, STR_STATIC_INIT("port"), select_uri_port, 0},
 	{ select_any_uri, SEL_PARAM_STR, STR_STATIC_INIT("params"), select_uri_params, 0},
+	{ select_any_uri, SEL_PARAM_STR, STR_STATIC_INIT("hostport"), select_uri_hostport, 0},
 	{ NULL, SEL_PARAM_STR, STR_STATIC_INIT("event"), select_event, 0},
 
 	{ NULL, SEL_PARAM_STR, STR_STATIC_INIT("record_route"), select_rr, 0},