Browse Source

nameaddr support in select framework

if you want to use nameaddr parsing in your select function define as foolows:
{ select_YOUR_FUNCTION_xxx, SEL_PARAM_STR, STR_STATIC_INIT("nameaddr"), select_any_nameaddr, NESTED | CONSUME_NEXT_STR }
Michal Matyska 19 years ago
parent
commit
84b87bd360
3 changed files with 53 additions and 1 deletions
  1. 1 1
      select.c
  2. 43 0
      select_core.c
  3. 9 0
      select_core.h

+ 1 - 1
select.c

@@ -248,7 +248,7 @@ int resolve_select(select_t* s)
 			if (nested < MAX_NESTED_CALLS-1) { /* need space for final function */
 			if (nested < MAX_NESTED_CALLS-1) { /* need space for final function */
 				s->lvl = nested;
 				s->lvl = nested;
 				s->f[nested++] = f;
 				s->f[nested++] = f;
-				s->param_offset[nested] = param_idx+1;
+				s->param_offset[nested] = param_idx;
 			} else {
 			} else {
 				BUG("MAX_NESTED_CALLS too small to resolve select\n");
 				BUG("MAX_NESTED_CALLS too small to resolve select\n");
 				goto not_found;
 				goto not_found;

+ 43 - 0
select_core.c

@@ -37,6 +37,7 @@
 #include "select_buf.h"
 #include "select_buf.h"
 #include "dprint.h"
 #include "dprint.h"
 #include "trim.h"
 #include "trim.h"
+#include "parser/parser_f.h"
 #include "parser/hf.h"
 #include "parser/hf.h"
 #include "parser/parse_from.h"
 #include "parser/parse_from.h"
 #include "parser/parse_to.h"
 #include "parser/parse_to.h"
@@ -792,3 +793,45 @@ int select_cseq_method(str* res, select_t* s, struct sip_msg* msg)
 	*res = cs->method;
 	*res = cs->method;
 	return 0;
 	return 0;
 }
 }
+
+ABSTRACT_F(select_any_nameaddr)
+
+int select_nameaddr_name(str* res, select_t* s, struct sip_msg* msg)
+{
+	char *p;
+	
+	p=find_not_quoted(res, '<');
+	if (!p) {
+		DBG("select_nameaddr_name: no < found, whole string is uri\n");
+		res->len=0;
+		return 1;
+	}
+
+	res->len=p-res->s;
+	while (res->len && SP(res->s[res->len-1])) res->len--;
+	return 0;
+}
+
+int select_nameaddr_uri(str* res, select_t* s, struct sip_msg* msg)
+{
+	char *p;
+	
+	p=find_not_quoted(res, '<');
+	if (!p) {
+		DBG("select_nameaddr_uri: no < found, whole string is uri\n");
+		return 0;
+	}
+
+	res->len=res->len - (p-res->s) -1;
+	res->s=p +1;
+	
+	p=find_not_quoted(res, '>');
+	if (!p) {
+		ERR("select_nameaddr_uri: no > found, invalid nameaddr value\n");
+		return -1;
+	}
+
+	res->len=p-res->s;
+	return 0;
+}
+

+ 9 - 0
select_core.h

@@ -73,6 +73,10 @@ SELECT_F(select_via_params_spec)
 SELECT_F(select_msgheader)
 SELECT_F(select_msgheader)
 SELECT_F(select_anyheader)
 SELECT_F(select_anyheader)
 
 
+SELECT_F(select_any_nameaddr)
+SELECT_F(select_nameaddr_name)
+SELECT_F(select_nameaddr_uri)
+	
 SELECT_F(select_any_uri)
 SELECT_F(select_any_uri)
 SELECT_F(select_uri_type)
 SELECT_F(select_uri_type)
 SELECT_F(select_uri_user)
 SELECT_F(select_uri_user)
@@ -156,8 +160,13 @@ static select_row_t select_core[] = {
 	{ select_cseq, SEL_PARAM_STR, STR_STATIC_INIT("num"), select_cseq_num, 0},
 	{ select_cseq, SEL_PARAM_STR, STR_STATIC_INIT("num"), select_cseq_num, 0},
 	{ select_cseq, SEL_PARAM_STR, STR_STATIC_INIT("method"), select_cseq_method, 0},
 	{ select_cseq, SEL_PARAM_STR, STR_STATIC_INIT("method"), select_cseq_method, 0},
 
 
+	{ select_any_nameaddr, SEL_PARAM_STR, STR_STATIC_INIT("name"), select_nameaddr_name, 0},
+	{ select_any_nameaddr, SEL_PARAM_STR, STR_STATIC_INIT("uri"), select_nameaddr_uri, 0},
+	{ select_nameaddr_uri, SEL_PARAM_INT, STR_NULL, select_any_uri, NESTED},
+
 	{ NULL, SEL_PARAM_STR, STR_STATIC_INIT("msg"), select_msgheader, SEL_PARAM_EXPECTED},
 	{ NULL, SEL_PARAM_STR, STR_STATIC_INIT("msg"), select_msgheader, SEL_PARAM_EXPECTED},
 	{ select_msgheader, SEL_PARAM_STR, STR_NULL, select_anyheader, OPTIONAL | CONSUME_NEXT_INT | FIXUP_CALL},
 	{ select_msgheader, SEL_PARAM_STR, STR_NULL, select_anyheader, OPTIONAL | CONSUME_NEXT_INT | FIXUP_CALL},
+	{ select_anyheader, SEL_PARAM_STR, STR_STATIC_INIT("nameaddr"), select_any_nameaddr, NESTED | CONSUME_NEXT_STR},
 	{ NULL, SEL_PARAM_INT, STR_NULL, NULL, 0}
 	{ NULL, SEL_PARAM_INT, STR_NULL, NULL, 0}
 };
 };