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

Author: Peter Dunkley <[email protected]>
Committer: Peter Dunkley <[email protected]>
Date:   Tue Jan  8 00:24:13 2013 +0000

modules_k/registrar: Added modparam to allow Flow-Timer: to be set in 200 OK 
response to REGISTER requests

---

 modules_k/registrar/reg_mod.c |    8 ++++++++
 modules_k/registrar/reg_mod.h |    6 ++++++
 modules_k/registrar/reply.c   |   28 ++++++++++++++++++++++++++++
 3 files changed, 42 insertions(+), 0 deletions(-)

diff --git a/modules_k/registrar/reg_mod.c b/modules_k/registrar/reg_mod.c
index 4f83696..bbc6e11 100644
--- a/modules_k/registrar/reg_mod.c
+++ b/modules_k/registrar/reg_mod.c
@@ -120,6 +120,7 @@ sruid_t _reg_sruid;
 
 int reg_gruu_enabled = 1;
 int reg_outbound_mode = 0;
+int reg_flow_timer = 0;
 
 /* Populate this AVP if testing for specific registration instance. */
 char *reg_callid_avp_param = 0;
@@ -224,6 +225,7 @@ static param_export_t params[] = {
        {"xavp_rcd",           STR_PARAM, &reg_xavp_rcd.s                       
                },
        {"gruu_enabled",       INT_PARAM, &reg_gruu_enabled                     
                },
        {"outbound_mode",      INT_PARAM, &reg_outbound_mode                    
                },
+       {"flow_timer",         INT_PARAM, &reg_flow_timer                       
                },
        {0, 0, 0}
 };
 
@@ -380,6 +382,12 @@ static int mod_init(void)
                return -1;
        }
 
+       if (reg_flow_timer < 0 || reg_flow_timer > REG_FLOW_TIMER_MAX
+                       || (reg_flow_timer > 0 && reg_outbound_mode != 
REG_OUTBOUND_REQUIRE)) {
+               LM_ERR("bad value for flow_timer\n");
+               return -1;
+       }
+
        /* fix the flags */
        sock_flag = (sock_flag!=-1)?(1<<sock_flag):0;
        tcp_persistent_flag = 
(tcp_persistent_flag!=-1)?(1<<tcp_persistent_flag):0;
diff --git a/modules_k/registrar/reg_mod.h b/modules_k/registrar/reg_mod.h
index 04d31fa..7074590 100644
--- a/modules_k/registrar/reg_mod.h
+++ b/modules_k/registrar/reg_mod.h
@@ -71,6 +71,11 @@
 #define REG_OUTBOUND_SUPPORTED 1
 #define REG_OUTBOUND_REQUIRE   2
 
+/* Maximum of 999 to keep flow-timer to 3 digits
+   - make sure to update reply.c:add_flow_timer() if the number of digits
+     increases! */
+#define REG_FLOW_TIMER_MAX     999
+
 extern int nat_flag;
 extern int tcp_persistent_flag;
 extern int received_avp;
@@ -89,6 +94,7 @@ extern int path_mode;
 extern int path_use_params;
 extern int reg_gruu_enabled;
 extern int reg_outbound_mode;
+extern int reg_flow_timer;
 
 extern str sock_hdr_name;
 extern int sock_flag;
diff --git a/modules_k/registrar/reply.c b/modules_k/registrar/reply.c
index 5ce444e..b7b387a 100644
--- a/modules_k/registrar/reply.c
+++ b/modules_k/registrar/reply.c
@@ -581,6 +581,29 @@ static int add_supported(struct sip_msg* _m, str* _p)
                     LUMP_RPL_HDR | LUMP_RPL_NODUP);
        return 0;
 }
+
+#define FLOW_TIMER "Flow-Timer: "
+#define FLOW_TIMER_LEN (sizeof(FLOW_TIMER) - 1)
+
+static int add_flow_timer(struct sip_msg* _m)
+{
+       char* buf;
+       int lump_len;
+
+       /* Add three as REG_FLOW_TIMER_MAX is 999 - three digits */
+       buf = (char*)pkg_malloc(FLOW_TIMER_LEN + 3 + CRLF_LEN);
+       if (!buf) {
+               LM_ERR("no pkg memory left\n");
+               return -1;
+       }
+       lump_len = snprintf(buf, FLOW_TIMER_LEN + 3 + CRLF_LEN,
+                               "%.*s%d%.*s",
+                               FLOW_TIMER_LEN, FLOW_TIMER,
+                               reg_flow_timer,
+                               CRLF_LEN, CRLF);
+       add_lump_rpl(_m, buf, lump_len, LUMP_RPL_HDR | LUMP_RPL_NODUP);
+       return 0;
+}
  
 /*! \brief
  * Send a reply
@@ -630,6 +653,11 @@ int reg_send_reply(struct sip_msg* _m)
                case REG_OUTBOUND_REQUIRE:
                        if (add_require(_m, &outbound_str) < 0)
                                return -1;
+
+                       if (reg_flow_timer > 0) {
+                               if (add_flow_timer(_m) < 0)
+                                       return -1;
+                       }
                        /* Fall-thru */
                case REG_OUTBOUND_SUPPORTED:
                        if (add_supported(_m, &outbound_str) < 0)


_______________________________________________
sr-dev mailing list
[email protected]
http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev

Reply via email to