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

Author: Juha Heinanen <[email protected]>
Committer: Juha Heinanen <[email protected]>
Date:   Wed Dec  7 07:53:28 2011 +0200

modules_k/msilo: added storage of extra SIP headers from AVP

---

 modules_k/msilo/README              |   32 +++++++++++++++++++++-----
 modules_k/msilo/doc/msilo_admin.xml |   29 ++++++++++++++++++++++++
 modules_k/msilo/msilo.c             |   42 +++++++++++++++++++++++++++++++++++
 3 files changed, 97 insertions(+), 6 deletions(-)

diff --git a/modules_k/msilo/README b/modules_k/msilo/README
index f9c44b0..e1fe9a3 100644
--- a/modules_k/msilo/README
+++ b/modules_k/msilo/README
@@ -65,6 +65,7 @@ Juha Heinanen
               3.26. add_date (int)
               3.27. max_messages (int)
               3.28. add_contact (int)
+              3.29. extra_hdrs_avp (str)
 
         4. Functions
 
@@ -113,9 +114,10 @@ Juha Heinanen
    1.26. Set the “add_date” parameter
    1.27. Set the “max_messages” parameter
    1.28. Set the “add_contact” parameter
-   1.29. m_store usage
-   1.30. m_dump usage
-   1.31. Kamailio config script - sample msilo usage
+   1.29. Set the “extra_hdrs_avp” parameter
+   1.30. m_store usage
+   1.31. m_dump usage
+   1.32. Kamailio config script - sample msilo usage
 
 Chapter 1. Admin Guide
 
@@ -157,6 +159,7 @@ Chapter 1. Admin Guide
         3.26. add_date (int)
         3.27. max_messages (int)
         3.28. add_contact (int)
+        3.29. extra_hdrs_avp (str)
 
    4. Functions
 
@@ -254,6 +257,7 @@ Chapter 1. Admin Guide
    3.26. add_date (int)
    3.27. max_messages (int)
    3.28. add_contact (int)
+   3.29. extra_hdrs_avp (str)
 
 3.1. db_url (string)
 
@@ -596,6 +600,22 @@ modparam("msilo", "max_messages", 0)
 modparam("msilo", "add_contact", 1)
 ...
 
+3.29. extra_hdrs_avp (str)
+
+   Name of an AVP which may contain extra headers that are stored with the
+   message when m_store() is called. These extra headers (if any) are then
+   included in MESSAGE request generated by m_dump().
+
+   If the parameter is not set, m_store() does not look for extra headers
+   from any AVP.
+
+   Default value is “null”.
+
+   Example 1.29. Set the “extra_hdrs_avp” parameter
+...
+modparam("msilo", "extra_hdrs_avp", "$avp(msilo_extra_hdrs)")
+...
+
 4. Functions
 
    4.1. m_store([owner])
@@ -617,7 +637,7 @@ modparam("msilo", "add_contact", 1)
 
    This function can be used from REQUEST_ROUTE, FAILURE_ROUTE.
 
-   Example 1.29. m_store usage
+   Example 1.30. m_store usage
 ...
 m_store();
 m_store("$tu");
@@ -637,7 +657,7 @@ m_store("$tu");
 
    This function can be used from REQUEST_ROUTE.
 
-   Example 1.30. m_dump usage
+   Example 1.31. m_dump usage
 ...
 m_dump();
 m_dump("$fu");
@@ -679,7 +699,7 @@ m_dump("$fu");
 
    Next picture displays a sample usage of msilo.
 
-   Example 1.31. Kamailio config script - sample msilo usage
+   Example 1.32. Kamailio config script - sample msilo usage
 ...
 # $Id$
 #
diff --git a/modules_k/msilo/doc/msilo_admin.xml 
b/modules_k/msilo/doc/msilo_admin.xml
index ee975f8..3d02670 100644
--- a/modules_k/msilo/doc/msilo_admin.xml
+++ b/modules_k/msilo/doc/msilo_admin.xml
@@ -566,6 +566,7 @@ modparam("msilo", "snd_time_avp", "$avp(i:123)")
 </programlisting>
                </example>
        </section>
+
        <section>
                <title><varname>add_date</varname> (int)</title>
                <para>
@@ -626,6 +627,34 @@ modparam("msilo", "add_contact", 1)
 </programlisting>
                </example>
        </section>
+
+       <section>
+               <title><varname>extra_hdrs_avp</varname> (str)</title>
+               <para>
+               Name of an AVP which may contain extra headers that are
+               stored with the message when m_store() is called.  These extra
+               headers (if any) are then included in MESSAGE request
+               generated by m_dump().
+               </para>
+               <para>
+               If the parameter is not set, m_store() does not look
+               for extra headers from any AVP.
+               </para>
+               <para>
+               <emphasis>
+                       Default value is <quote>null</quote>.
+               </emphasis>
+               </para>
+               <example>
+               <title>Set the <quote>extra_hdrs_avp</quote> parameter</title>
+<programlisting format="linespecific">
+...
+modparam("msilo", "extra_hdrs_avp", "$avp(msilo_extra_hdrs)")
+...
+</programlisting>
+               </example>
+       </section>
+
        </section>
 
        <section>
diff --git a/modules_k/msilo/msilo.c b/modules_k/msilo/msilo.c
index cb23b2b..689b81a 100644
--- a/modules_k/msilo/msilo.c
+++ b/modules_k/msilo/msilo.c
@@ -39,6 +39,7 @@
  * 2006-09-10 m_dump now checks if registering UA supports MESSAGE method (jh)
  * 2006-10-05 added max_messages module variable (jh)
  * 2011-10-19 added storage of extra SIP headers (hpw)
+ * 2011-12-07 added storage of extra SIP headers from AVP (jh)
  */
 
 #include <stdio.h>
@@ -154,6 +155,10 @@ static str ms_snd_time_avp_param = {NULL, 0};
 int_str ms_snd_time_avp_name;
 unsigned short ms_snd_time_avp_type;
 
+static str ms_extra_hdrs_avp_param = {NULL, 0};
+int_str ms_extra_hdrs_avp_name;
+unsigned short ms_extra_hdrs_avp_type;
+
 str msg_type = str_init("MESSAGE");
 
 /** module functions */
@@ -220,6 +225,7 @@ static param_export_t params[]={
        { "sc_snd_time",      STR_PARAM, &sc_snd_time.s           },
        { "sc_stored_hdrs",   STR_PARAM, &sc_stored_hdrs.s        },
        { "snd_time_avp",     STR_PARAM, &ms_snd_time_avp_param.s },
+       { "extra_hdrs_avp",   STR_PARAM, &ms_extra_hdrs_avp_param.s },
        { "add_date",         INT_PARAM, &ms_add_date             },
        { "max_messages",     INT_PARAM, &ms_max_messages         },
        { "add_contact",      INT_PARAM, &ms_add_contact          },
@@ -303,6 +309,8 @@ static int mod_init(void)
        sc_snd_time.len = strlen(sc_snd_time.s);
        if (ms_snd_time_avp_param.s)
                ms_snd_time_avp_param.len = strlen(ms_snd_time_avp_param.s);
+       if (ms_extra_hdrs_avp_param.s)
+               ms_extra_hdrs_avp_param.len = strlen(ms_extra_hdrs_avp_param.s);
 
        /* binding to mysql module  */
        if (db_bind_mod(&ms_db_url, &msilo_dbf))
@@ -334,6 +342,22 @@ static int mod_init(void)
                }
        }
 
+       if (ms_extra_hdrs_avp_param.s && ms_extra_hdrs_avp_param.len > 0) {
+           if (pv_parse_spec(&ms_extra_hdrs_avp_param, &avp_spec)==0
+               || avp_spec.type!=PVT_AVP) {
+               LM_ERR("malformed or non AVP %.*s AVP definition\n",
+                      ms_extra_hdrs_avp_param.len, ms_extra_hdrs_avp_param.s);
+               return -1;
+           }
+
+           if (pv_get_avp_name(0, &(avp_spec.pvp), &ms_extra_hdrs_avp_name,
+                              &ms_extra_hdrs_avp_type) != 0) {
+               LM_ERR("[%.*s]- invalid AVP definition\n",
+                      ms_extra_hdrs_avp_param.len, ms_extra_hdrs_avp_param.s);
+               return -1;
+           }
+       }
+
        db_con = msilo_dbf.init(&ms_db_url);
        if (!db_con)
        {
@@ -502,6 +526,24 @@ static int get_non_mandatory_headers(struct sip_msg *msg, 
char *buf, int buf_len
 {
        struct hdr_field *hdrs;
        int len = 0;
+       int_str avp_value;
+       struct usr_avp *avp;
+
+       if (ms_extra_hdrs_avp_name.n != 0) {
+           avp = NULL;
+           avp = search_first_avp(ms_extra_hdrs_avp_type,
+                                  ms_extra_hdrs_avp_name, &avp_value, 0);
+           if ((avp != NULL) && is_avp_str_val(avp)) {
+               if (buf_len <= avp_value.s.len) {
+                   LM_ERR("insufficient space to store headers in silo\n");
+                   return -1;
+               }
+               memcpy(buf, avp_value.s.s, avp_value.s.len);
+               LM_INFO("copied '%.*s' to buf\n", avp_value.s.len,
+                       avp_value.s.s);
+               return avp_value.s.len;
+           }
+       }
 
        for (hdrs = msg->headers; hdrs != NULL; hdrs = hdrs->next)
        {


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

Reply via email to