[sr-dev] git:alexh/master: modules_k/uac_redirect: Parse Contact's "flags" header parameter into branch flags.

Alex Hermann alex at speakup.nl
Mon Aug 8 11:11:05 CEST 2011


Module: sip-router
Branch: alexh/master
Commit: e430827e3501181992596dd950ea0e36b41c084b
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=e430827e3501181992596dd950ea0e36b41c084b

Author: Alex Hermann <alex at speakup.nl>
Committer: Alex Hermann <alex at speakup.nl>
Date:   Tue Jul 26 11:14:25 2011 +0200

modules_k/uac_redirect: Parse Contact's "flags" header parameter into branch flags.

---

 modules_k/uac_redirect/rd_funcs.c |    6 ++++--
 parser/contact/contact.c          |    2 ++
 parser/contact/contact.h          |    1 +
 parser/parse_param.c              |   12 +++++++++++-
 parser/parse_param.h              |    2 ++
 5 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/modules_k/uac_redirect/rd_funcs.c b/modules_k/uac_redirect/rd_funcs.c
index 2f85ed1..173f398 100644
--- a/modules_k/uac_redirect/rd_funcs.c
+++ b/modules_k/uac_redirect/rd_funcs.c
@@ -32,7 +32,6 @@
 #include "../../dprint.h"
 #include "../../qvalue.h"
 #include "../../parser/contact/parse_contact.h"
-#include "../../qvalue.h"
 #include "rd_filter.h"
 #include "rd_funcs.h"
 
@@ -189,6 +188,7 @@ static int shmcontact2dset(struct sip_msg *req, struct sip_msg *sh_rpl,
 	int added;
 	int dup;
 	int ret;
+	unsigned int flags;
 
 	/* dup can be:
 	 *    0 - sh reply but nothing duplicated 
@@ -274,8 +274,10 @@ static int shmcontact2dset(struct sip_msg *req, struct sip_msg *sh_rpl,
 	for ( i=0 ; i<n ; i++ ) {
 		LM_DBG("adding contact <%.*s>\n", scontacts[i]->uri.len,
 				scontacts[i]->uri.s);
+		if (!scontacts[i]->flags || str2int(&(scontacts[i]->flags->body), &flags) < 0)
+			flags = bflags;
 		if (km_append_branch( 0, &scontacts[i]->uri, 0, 0, sqvalues[i],
-					bflags, 0)<0) {
+					flags, 0)<0) {
 			LM_ERR("failed to add contact to dset\n");
 		} else {
 			added++;
diff --git a/parser/contact/contact.c b/parser/contact/contact.c
index 4b953f3..f14aabb 100644
--- a/parser/contact/contact.c
+++ b/parser/contact/contact.c
@@ -248,6 +248,7 @@ int parse_contacts(str* _s, contact_t** _c)
 			c->received = hooks.contact.received;
 			c->methods = hooks.contact.methods;
 			c->instance = hooks.contact.instance;
+			c->flags = hooks.contact.flags;
 
 			if (_s->len == 0) goto ok;
 		}
@@ -317,6 +318,7 @@ void print_contacts(FILE* _o, contact_t* _c)
 		fprintf(_o, "received: %p\n", ptr->received);
 		fprintf(_o, "methods  : %p\n", ptr->methods);
 		fprintf(_o, "instance: %p\n", ptr->instance);
+		fprintf(_o, "flags   : %p\n", ptr->flags);
 		fprintf(_o, "len     : %d\n", ptr->len);
 		if (ptr->params) {
 			print_params(_o, ptr->params);
diff --git a/parser/contact/contact.h b/parser/contact/contact.h
index 1865bd4..48bba22 100644
--- a/parser/contact/contact.h
+++ b/parser/contact/contact.h
@@ -51,6 +51,7 @@ typedef struct contact {
 	param_t* methods;       /* methods parameter hook */
 	param_t* received;      /* received parameter hook */
 	param_t* instance;      /* sip.instance parameter hook */
+	param_t* flags;         /* flags parameter hook */
 	param_t* params;        /* List of all parameters */
 	int len;                /* Total length of the element */
         struct contact* next; /* Next contact in the list */
diff --git a/parser/parse_param.c b/parser/parse_param.c
index 6e8f653..f6a5413 100644
--- a/parser/parse_param.c
+++ b/parser/parse_param.c
@@ -113,7 +113,7 @@ static inline void parse_event_dialog_class(param_hooks_t* h, param_t* p)
 
 /*! \brief
  * Try to find out parameter name, recognized parameters
- * are q, expires and methods
+ * are q, expires, methods, +sip.instance and flags
  */
 static inline void parse_contact_class(param_hooks_t* _h, param_t* _p)
 {
@@ -168,6 +168,15 @@ static inline void parse_contact_class(param_hooks_t* _h, param_t* _p)
 			_h->contact.instance = _p;
 		}
 		break;
+
+	case 'f':
+	case 'F':
+		if ((_p->name.len == 5) &&
+		    (!strncasecmp(_p->name.s + 1, "lags", 4))) {
+			_p->type = P_FLAGS;
+			_h->contact.flags = _p;
+		}
+		break;
 	}
 }
 
@@ -602,6 +611,7 @@ static inline void print_param(FILE* _o, param_t* _p)
 	case P_Q:         type = "P_Q";         break;
 	case P_EXPIRES:   type = "P_EXPIRES";   break;
 	case P_METHODS:   type = "P_METHODS";   break;
+	case P_FLAGS:     type = "P_FLAGS";     break;
 	case P_TRANSPORT: type = "P_TRANSPORT"; break;
 	case P_LR:        type = "P_LR";        break;
 	case P_R2:        type = "P_R2";        break;
diff --git a/parser/parse_param.h b/parser/parse_param.h
index 1b92de6..1429f23 100644
--- a/parser/parse_param.h
+++ b/parser/parse_param.h
@@ -53,6 +53,7 @@ typedef enum ptype {
 	P_EXPIRES,   /*!< Contact: expires parameter */
 	P_METHODS,   /*!< Contact: methods parameter */
 	P_RECEIVED,  /*!< Contact: received parameter */
+	P_FLAGS,     /*!< Contact: flags parameter */
 	P_TRANSPORT, /*!< URI: transport parameter */
 	P_LR,        /*!< URI: lr parameter */
 	P_R2,        /*!< URI: r2 parameter (ser specific) */
@@ -103,6 +104,7 @@ struct contact_hooks {
 	struct param* methods;  /*!< methods parameter */
 	struct param* received; /*!< received parameter */
 	struct param* instance; /*!< sip.instance parameter */
+	struct param* flags;    /*!< flags parameter */
 };
 
 




More information about the sr-dev mailing list