În data de 31.05.2014 11:36, "Juha Heinanen" <jh@tutpro.com> a scris:
Module: sip-router
Branch: master
Commit: 7f136429e5b676077c4f71c5cc178dd0c125951b
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=7f136429e5b676077c4f71c5cc178dd0c125951b

Author: Juha Heinanen <jh@tutpro.com>
Committer: Juha Heinanen <jh@tutpro.com>
Date:   Sat May 31 10:34:19 2014 +0300

modules/acc: added reason_from_reason_hf module paramater

- in schema, increased size of sip_reason field to 128 chars

---

 lib/srdb1/schema/acc.xml          |    2 +-
 lib/srdb1/schema/entities.xml     |    2 +-
 lib/srdb1/schema/missed_calls.xml |    2 +-
 modules/acc/README                |   33 +++++++++++++++++++++++++--------
 modules/acc/acc_logic.c           |   21 ++++++++++++++++++++-
 modules/acc/acc_mod.c             |    2 ++
 modules/acc/acc_mod.h             |    1 +
 modules/acc/doc/acc_admin.xml     |   20 ++++++++++++++++++++
 8 files changed, 71 insertions(+), 12 deletions(-)

diff --git a/lib/srdb1/schema/acc.xml b/lib/srdb1/schema/acc.xml
index 719298e..2d8d66b 100644
--- a/lib/srdb1/schema/acc.xml
+++ b/lib/srdb1/schema/acc.xml
@@ -9,7 +9,7 @@

 <table id="acc" xmlns:db="http://docbook.org/ns/docbook">
     <name>acc</name>
-    <version>4</version>
+    <version>5</version>
     <type db="mysql">&MYSQL_TABLE_TYPE;</type>
     <description>
         <db:para>This table is used by the ACC module to report on transactions - accounted calls. More information is available at: &KAMAILIO_MOD_DOC;acc.html
diff --git a/lib/srdb1/schema/entities.xml b/lib/srdb1/schema/entities.xml
index 526ac55..bb3ddf3 100644
--- a/lib/srdb1/schema/entities.xml
+++ b/lib/srdb1/schema/entities.xml
@@ -13,7 +13,7 @@
 <!ENTITY avp_val_len "128">
 <!ENTITY ip_add_len "50">
 <!ENTITY sip_code_len "3">
-<!ENTITY sip_reason_len "32">
+<!ENTITY sip_reason_len "128">
 <!ENTITY cseq_len "11">
 <!ENTITY callid_len "255">
 <!ENTITY expires_len "11">
diff --git a/lib/srdb1/schema/missed_calls.xml b/lib/srdb1/schema/missed_calls.xml
index 7a66440..8c824ab 100644
--- a/lib/srdb1/schema/missed_calls.xml
+++ b/lib/srdb1/schema/missed_calls.xml
@@ -9,7 +9,7 @@

 <table id="missed_calls" xmlns:db="http://docbook.org/ns/docbook">
     <name>missed_calls</name>
-    <version>3</version>
+    <version>4</version>
     <type db="mysql">&MYSQL_TABLE_TYPE;</type>
     <description>
         <db:para>This table is used by the ACC module for keeping track of missed calls. This table is similar to the 'acc' table. More information is available at: &KAMAILIO_MOD_DOC;acc.html</db:para>
diff --git a/modules/acc/README b/modules/acc/README
index ea72fd6..8316b52 100644
--- a/modules/acc/README
+++ b/modules/acc/README
@@ -131,6 +131,7 @@ Sven Knoblich
               6.48. time_attr (str)
               6.49. time_exten (str)
               6.50. time_format (str)
+              6.51. reason_from_reason_hf (int)

         7. Functions

@@ -193,10 +194,11 @@ Sven Knoblich
    1.48. time_attr example
    1.49. time_exten example
    1.50. time_format example
-   1.51. acc_log_request usage
-   1.52. acc_db_request usage
-   1.53. acc_rad_request usage
-   1.54. acc_diam_request usage
+   1.51. reason_from_reason_hf
+   1.52. acc_log_request usage
+   1.53. acc_db_request usage
+   1.54. acc_rad_request usage
+   1.55. acc_diam_request usage

 Chapter 1. Admin Guide

@@ -291,6 +293,7 @@ Chapter 1. Admin Guide
         6.48. time_attr (str)
         6.49. time_exten (str)
         6.50. time_format (str)
+        6.51. reason_from_reason_hf (int)

    7. Functions

@@ -705,6 +708,7 @@ $dlg_var(callee) = $avp(callee); #callee='C'
    6.48. time_attr (str)
    6.49. time_exten (str)
    6.50. time_format (str)
+   6.51. reason_from_reason_hf (int)

 6.1. early_media (integer)

@@ -1350,6 +1354,19 @@ modparam("acc", "time_exten", "micorsecs")
 modparam("acc", "time_format", "%Y/%m/%d %H:%M:%S")
 ...

+6.51. reason_from_reason_hf (int)
+
+   Tells where to take sip_reason from. If value is 0, sip_reason is taken
+   from status line. Otherwise, sip_reason is taken from Reason header
+   field(s) if present. Currently only the first Reason header is used.
+
+   Default value is 0.
+
+   Example 1.51. reason_from_reason_hf
+...
+modparam("acc", "reason_from_reason_hf", 1)
+...
+
 7. Functions

    7.1. acc_log_request(comment)
@@ -1370,7 +1387,7 @@ modparam("acc", "time_format", "%Y/%m/%d %H:%M:%S")

    This function can be used from ANY_ROUTE.

-   Example 1.51. acc_log_request usage
+   Example 1.52. acc_log_request usage
 ...
 acc_log_request("Some comment");
 $var(code) = 404;
@@ -1392,7 +1409,7 @@ acc_log_request("$var(code) Error: $avp(reason)");

    This function can be used from ANY_ROUTE.

-   Example 1.52. acc_db_request usage
+   Example 1.53. acc_db_request usage
 ...
 acc_db_request("Some comment", "SomeTable");
 acc_db_request("Some comment", "acc_$time(year)_$time(mon)");
@@ -1410,7 +1427,7 @@ acc_db_request("$var(code) Error: $avp(reason)", "SomeTable");

    This function can be used from ANY_ROUTE.

-   Example 1.53. acc_rad_request usage
+   Example 1.54. acc_rad_request usage
 ...
 acc_rad_request("Some comment");
 acc_rad_request("$var(code) Error: $avp(reason)");
@@ -1427,7 +1444,7 @@ acc_rad_request("$var(code) Error: $avp(reason)");

    This function can be used from ANY_ROUTE.

-   Example 1.54. acc_diam_request usage
+   Example 1.55. acc_diam_request usage
 ...
 acc_diam_request("Some comment");
 acc_diam_request("$var(code) Error: $avp(reason)");
diff --git a/modules/acc/acc_logic.c b/modules/acc/acc_logic.c
index 0641388..452e171 100644
--- a/modules/acc/acc_logic.c
+++ b/modules/acc/acc_logic.c
@@ -42,6 +42,7 @@
 #include "../../sr_module.h"
 #include "../../parser/parse_from.h"
 #include "../../parser/parse_content.h"
+#include "../../lib/kcore/cmpapi.h"
 #include "../../modules/tm/tm_load.h"
 #include "../rr/api.h"
 #include "../../flags.h"
@@ -132,6 +133,8 @@ static inline void env_set_text(char *p, int len)
 static inline void env_set_code_status( int code, struct sip_msg *reply)
 {
        static char code_buf[INT2STR_MAX_LEN];
+       str reason = {"Reason", 6};
+       struct hdr_field *hf;

        acc_env.code = code;
        if (reply==FAKED_REPLY || reply==NULL) {
@@ -143,7 +146,23 @@ static inline void env_set_code_status( int code, struct sip_msg *reply)
                acc_env.reason.len = strlen(acc_env.reason.s);
        } else {
                acc_env.code_s = reply->first_line.u.reply.status;
-               acc_env.reason = reply->first_line.u.reply.reason;
+               hf = NULL;
+               if (reason_from_reason_hf) {
+                       /* TODO: take reason from all Reason headers */
+                       if(parse_headers(reply, HDR_EOH_F, 0) < 0) {
+                               LM_ERR("error parsing headers\n");
+                       } else {
+                               for (hf=reply->headers; hf; hf=hf->next) {
+                                       if (cmp_hdrname_str(&hf->name, &reason)==0)
+                                               break;
+                               }
+                       }
+               }
+               if (hf == NULL) {
+                       acc_env.reason = reply->first_line.u.reply.reason;
+               } else {
+                       acc_env.reason = hf->body;
+               }
        }
 }

diff --git a/modules/acc/acc_mod.c b/modules/acc/acc_mod.c
index ff94baa..347e054 100644
--- a/modules/acc/acc_mod.c
+++ b/modules/acc/acc_mod.c
@@ -110,6 +110,7 @@ static char* leg_info_str = 0;      /*!< multi call-leg support */
 struct acc_extra *leg_info = 0;
 int acc_prepare_flag = -1; /*!< should the request be prepared for later acc */
 char *acc_time_format = "%Y-%m-%d %H:%M:%S";
+int reason_from_reason_hf = 0; /*!< assign reason from reason hf if present */

 /* ----- time mode variables ------- */
 /*! \name AccTimeModeVariables  Time Mode Variables */
@@ -258,6 +259,7 @@ static param_export_t params[] = {
        {"multi_leg_info",          STR_PARAM, &leg_info_str            },
        {"detect_direction",        INT_PARAM, &detect_direction        },
        {"acc_prepare_flag",        INT_PARAM, &acc_prepare_flag        },
+       {"reason_from_reason_hf",   INT_PARAM, &reason_from_reason_hf   },
        /* syslog specific */
        {"log_flag",             INT_PARAM, &log_flag             },
        {"log_missed_flag",      INT_PARAM, &log_missed_flag      },
diff --git a/modules/acc/acc_mod.h b/modules/acc/acc_mod.h
index 98cef33..68911dc 100644
--- a/modules/acc/acc_mod.h
+++ b/modules/acc/acc_mod.h
@@ -50,6 +50,7 @@ extern int failed_transaction_flag;
 extern unsigned short failed_filter[];
 extern int detect_direction;
 extern int acc_prepare_flag;
+extern int reason_from_reason_hf;

 extern int log_facility;
 extern int log_level;
diff --git a/modules/acc/doc/acc_admin.xml b/modules/acc/doc/acc_admin.xml
index 54b9517..b0a1217 100644
--- a/modules/acc/doc/acc_admin.xml
+++ b/modules/acc/doc/acc_admin.xml
@@ -1479,6 +1479,26 @@ modparam("acc", "time_format", "%Y/%m/%d %H:%M:%S")
 </programlisting>
                </example>
        </section>
+       <section id="acc.p.reason_from_reason_hf">
+               <title><varname>reason_from_reason_hf</varname> (int)</title>
+               <para>
+               Tells where to take sip_reason from.  If value is 0,
+               sip_reason is taken from status line.  Otherwise, sip_reason
+               is taken from Reason header field(s) if present.
+               Currently only the first Reason header is used.
+               </para>
+               <para>
+               Default value is 0.
+               </para>
+               <example>
+               <title>reason_from_reason_hf</title>
+               <programlisting format="linespecific">
+...
+modparam("acc", "reason_from_reason_hf", 1)
+...
+</programlisting>
+               </example>
+       </section>
        </section>

        <section>


_______________________________________________
sr-dev mailing list
sr-dev@lists.sip-router.org
http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev