Module: sip-router
Branch: master
Commit: 5cbedc6b515b50f9ade7457abedba18747d98f75
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=5cbedc6…
Author: Victor Seva <linuxmaniac(a)torreviejawireless.org>
Committer: Victor Seva <linuxmaniac(a)torreviejawireless.org>
Date: Tue Aug 13 10:14:42 2013 +0200
modules/debugger: Added module parameter reset_msgid. Added RPC command dbg.reset_msgid
The message id ($mi) will be reset but internally there is no change. This can be
useful for unit tests cases.
---
modules/debugger/debugger_api.c | 100 +++++++++++++++++++++++++++++++
modules/debugger/debugger_api.h | 10 +++
modules/debugger/debugger_mod.c | 12 ++++
modules/debugger/doc/debugger_admin.xml | 44 ++++++++++++++
4 files changed, 166 insertions(+), 0 deletions(-)
diff --git a/modules/debugger/debugger_api.c b/modules/debugger/debugger_api.c
index d3f64e4..7a11631 100644
--- a/modules/debugger/debugger_api.c
+++ b/modules/debugger/debugger_api.c
@@ -180,6 +180,11 @@ int _dbg_step_usleep = 100000;
int _dbg_step_loops = 200;
/**
+ * disabled by default
+ */
+int _dbg_reset_msgid = 0;
+
+/**
*
*/
typedef struct _dbg_cmd
@@ -199,6 +204,9 @@ typedef struct _dbg_pid
unsigned int state;
dbg_cmd_t in;
dbg_cmd_t out;
+ gen_lock_t *lock;
+ unsigned int reset_msgid; /* flag to reset the id */
+ unsigned int msgid_base; /* real id since the reset */
} dbg_pid_t;
/**
@@ -227,6 +235,48 @@ typedef struct _dbg_bp
*/
static dbg_bp_t *_dbg_bp_list = NULL;
+/* defined later */
+int dbg_get_pid_index(unsigned int pid);
+
+/*!
+ * \brief Callback function that checks if reset_msgid is set
+ * and modifies msg->id if necessary.
+ * \param msg SIP message
+ * \param flags unused
+ * \param bar unused
+ * \return 1 on success, -1 on failure
+ */
+int dbg_msgid_filter(struct sip_msg *msg, unsigned int flags, void *bar)
+{
+ unsigned int process_no = my_pid();
+ int indx = dbg_get_pid_index(process_no);
+ unsigned int msgid_base = 0;
+ unsigned int msgid_new = 0;
+ if(indx<0) return -1;
+ LM_DBG("process_no:%d indx:%d\n", process_no, indx);
+ lock_get(_dbg_pid_list[indx].lock);
+ if(_dbg_pid_list[indx].reset_msgid==1)
+ {
+ LM_DBG("reset_msgid! msgid_base:%d\n", msg->id);
+ _dbg_pid_list[indx].reset_msgid = 0;
+ _dbg_pid_list[indx].msgid_base = msg->id - 1;
+ }
+ msgid_base = _dbg_pid_list[indx].msgid_base;
+ lock_release(_dbg_pid_list[indx].lock);
+ msgid_new = msg->id - msgid_base;
+ LM_DBG("msg->id:%d msgid_base:%d -> %d\n", msg->id, msgid_base,
msgid_new);
+ if(msgid_new>0)
+ {
+ msg->id = msgid_new;
+ return 1;
+ }
+ else
+ {
+ LM_WARN("msgid_new<=0??\n");
+ return -1;
+ }
+}
+
/**
* callback executed for each cfg action
*/
@@ -497,6 +547,22 @@ int dbg_init_mypid(void)
_dbg_pid_list[process_no].set |= DBG_ABKPOINT_ON;
if(_dbg_cfgtrace==1)
_dbg_pid_list[process_no].set |= DBG_CFGTRACE_ON;
+ if(_dbg_reset_msgid==1)
+ {
+ LM_DBG("[%d] create locks\n", process_no);
+ _dbg_pid_list[process_no].lock = lock_alloc();
+ if(_dbg_pid_list[process_no].lock==NULL)
+ {
+ LM_ERR("cannot allocate the lock\n");
+ return -1;
+ }
+ if(lock_init(_dbg_pid_list[process_no].lock)==NULL)
+ {
+ LM_ERR("cannot init the lock\n");
+ lock_dealloc(_dbg_pid_list[process_no].lock);
+ return -1;
+ }
+ }
return 0;
}
@@ -879,11 +945,45 @@ static void dbg_rpc_mod_level(rpc_t* rpc, void* ctx){
/**
*
*/
+static const char* dbg_rpc_reset_msgid_doc[2] = {
+ "Reset msgid on all process",
+ 0
+};
+
+static void dbg_rpc_reset_msgid(rpc_t* rpc, void* ctx){
+ int i;
+ if (_dbg_reset_msgid==0)
+ {
+ rpc->fault(ctx, 500, "reset_msgid is 0. Set it to 1 to enable.");
+ return;
+ }
+ if(_dbg_pid_list==NULL)
+ {
+ rpc->fault(ctx, 500, "_dbg_pid_list is NULL");
+ return;
+ }
+ LM_DBG("set reset_msgid\n");
+ for(i=0; i<_dbg_pid_no; i++)
+ {
+ if (_dbg_pid_list[i].lock!=NULL)
+ {
+ lock_get(_dbg_pid_list[i].lock);
+ _dbg_pid_list[i].reset_msgid = 1;
+ lock_release(_dbg_pid_list[i].lock);
+ }
+ }
+ rpc->add(ctx, "s", "200 ok");
+}
+
+/**
+ *
+ */
rpc_export_t dbg_rpc[] = {
{"dbg.bp", dbg_rpc_bp, dbg_rpc_bp_doc, 0},
{"dbg.ls", dbg_rpc_list, dbg_rpc_list_doc, 0},
{"dbg.trace", dbg_rpc_trace, dbg_rpc_trace_doc, 0},
{"dbg.mod_level", dbg_rpc_mod_level, dbg_rpc_mod_level_doc, 0},
+ {"dbg.reset_msgid", dbg_rpc_reset_msgid, dbg_rpc_reset_msgid_doc, 0},
{0, 0, 0, 0}
};
diff --git a/modules/debugger/debugger_api.h b/modules/debugger/debugger_api.h
index be20098..011013a 100644
--- a/modules/debugger/debugger_api.h
+++ b/modules/debugger/debugger_api.h
@@ -40,6 +40,16 @@ void dbg_enable_mod_levels(void);
int dbg_init_pvcache(void);
void dbg_enable_log_assign(void);
+/*!
+ * \brief Callback function that checks if reset_msgid is set
+ * and modifies msg->id if necessary.
+ * \param msg SIP message
+ * \param flags unused
+ * \param bar unused
+ * \return 1 on success, -1 on failure
+ */
+int dbg_msgid_filter(struct sip_msg *msg, unsigned int flags, void *bar);
+
#define DBG_DP_NULL 1
#define DBG_DP_AVP 2
#define DBG_DP_SCRIPTVAR 4
diff --git a/modules/debugger/debugger_mod.c b/modules/debugger/debugger_mod.c
index cef4617..87724ce 100644
--- a/modules/debugger/debugger_mod.c
+++ b/modules/debugger/debugger_mod.c
@@ -33,6 +33,7 @@
#include "../../mod_fix.h"
#include "../../parser/parse_param.h"
#include "../../shm_init.h"
+#include "../../script_cb.h"
#include "debugger_api.h"
#include "debugger_config.h"
@@ -58,6 +59,7 @@ extern int _dbg_cfgtrace_facility;
extern char *_dbg_cfgtrace_prefix;
extern int _dbg_step_usleep;
extern int _dbg_step_loops;
+extern int _dbg_reset_msgid;
static char * _dbg_cfgtrace_facility_str = 0;
static int _dbg_log_assign = 0;
@@ -86,6 +88,7 @@ static param_export_t params[]={
{"mod_hash_size", INT_PARAM, &default_dbg_cfg.mod_hash_size},
{"mod_level_mode", INT_PARAM, &default_dbg_cfg.mod_level_mode},
{"mod_level", STR_PARAM|USE_FUNC_PARAM, (void*)dbg_mod_level_param},
+ {"reset_msgid", INT_PARAM, &_dbg_reset_msgid},
{0, 0, 0}
};
@@ -152,6 +155,15 @@ static int mod_init(void)
return -1;
}
}
+ if(_dbg_reset_msgid==1)
+ {
+ unsigned int ALL = REQUEST_CB+FAILURE_CB+ONREPLY_CB
+ +BRANCH_CB+ONSEND_CB+ERROR_CB+LOCAL_CB+EVENT_CB+BRANCH_FAILURE_CB;
+ if (register_script_cb(dbg_msgid_filter, PRE_SCRIPT_CB|ALL, 0) != 0) {
+ LM_ERR("could not insert callback");
+ return -1;
+ }
+ }
return dbg_init_bp_list();
}
diff --git a/modules/debugger/doc/debugger_admin.xml
b/modules/debugger/doc/debugger_admin.xml
index 7fb8cc7..4a41ade 100644
--- a/modules/debugger/doc/debugger_admin.xml
+++ b/modules/debugger/doc/debugger_admin.xml
@@ -415,6 +415,27 @@ dbg_pv_dump(30, "L_DBG");
</example>
</section>
+ <section>
+ <title><varname>reset_msgid</varname> (int)</title>
+ <para>
+ Used to enable or disable the ability to reset the msgid ($mi)
+ through the dbg.reset_msgid RPC command. (0 - disabled, 1 - enabled).
+ </para>
+ <para>
+ <emphasis>
+ Default value is <quote>0</quote> - feature disabled.
+ </emphasis>
+ </para>
+ <example>
+ <title>Set <varname>reset_msgid</varname> parameter</title>
+ <programlisting format="linespecific">
+...
+modparam("debugger", "reset_msgid", 1)
+...
+</programlisting>
+ </example>
+ </section>
+
</section>
<section>
@@ -575,6 +596,29 @@ dbg_pv_dump(30, "L_DBG");
</programlisting>
</section>
+ <section>
+ <title>
+ <function moreinfo="none">dbg.reset_msgid</function>
+ </title>
+ <para>
+ Resets the message sequence ($mi). Internally there is no real change.
+ This can be useful for unit test cases in order to be able to replicate
+ exactly the same kamailio output.
+
+ You need to set the debugger parameter reset_msgid to 1 to activate this
+ functionallity.
+ </para>
+ <para>
+ Name: <emphasis>dbg.reset_msgid</emphasis>
+ </para>
+ <para>
+ Examples of use with &sercmd;:
+ </para>
+ <programlisting format="linespecific">
+ dbg.reset_msgid
+ </programlisting>
+ </section>
+
</section>
<section>
<title>Usage</title>