There were discussions in the list about getting rid of the MI interface
and sticking with the RPC one. We should stop adding new MI commands. I see
that the RPC commands are already implemented.
Regards,
Ovidiu Sas
On Nov 12, 2014 5:59 AM, "Federico Cabiddu" <federico.cabiddu(a)gmail.com>
wrote:
Module: sip-router
Branch: master
Commit: a255911902788bf74a7f4279fce4758b2f2a4613
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=a255911…
Author: Federico Cabiddu <federico.cabiddu(a)gmail.com>
Committer: Federico Cabiddu <federico.cabiddu(a)gmail.com>
Date: Wed Nov 12 11:52:29 2014 +0100
modules/tsilo: added MI commands
---
modules/tsilo/Makefile | 5 +++-
modules/tsilo/README | 51
+++++++++++++++++++++++++++++--------
modules/tsilo/doc/tsilo_admin.xml | 44 ++++++++++++++++++++++++++------
modules/tsilo/ts_hash.c | 2 +-
modules/tsilo/ts_hash.h | 16 ++++++------
modules/tsilo/tsilo.c | 30 ++++++++++++++++-----
6 files changed, 112 insertions(+), 36 deletions(-)
diff --git a/modules/tsilo/Makefile b/modules/tsilo/Makefile
index 40b04cb..c179aec 100644
--- a/modules/tsilo/Makefile
+++ b/modules/tsilo/Makefile
@@ -9,10 +9,13 @@ include ../../Makefile.defs
auto_gen=
NAME=tsilo.so
LIBS=
-DEFS+= -DSER_MOD_INTERFACE
+DEFS+=-DKAMAILIO_MOD_INTERFACE
ifeq ($(INSTALL_FLAVOUR),kamailio)
DEFS+= -DWITH_EVENT_LOCAL_REQUEST
endif # INSTALL_FLAVOUR
+SERLIBPATH=../../lib
+SER_LIBS+=$(SERLIBPATH)/kmi/kmi
+
include ../../Makefile.modules
diff --git a/modules/tsilo/README b/modules/tsilo/README
index 4790ad1..297c435 100644
--- a/modules/tsilo/README
+++ b/modules/tsilo/README
@@ -10,7 +10,7 @@ Federico Cabiddu
<federico.cabiddu(a)gmail.com>
- Copyright © 2014 Federico Cabiddu
+ Copyright © 2014 Federico Cabiddu
__________________________________________________________________
Table of Contents
@@ -33,7 +33,10 @@ Federico Cabiddu
4.2. ts_append(domain, ruri)
4.3. ts_append_to(tindex, tlabel, domain)
- 5. Statistics
+ 5. MI Commands
+
+ 5.1. ts_dump
+ 5.2. ts_lookup
List of Examples
@@ -62,19 +65,26 @@ Chapter 1. Admin Guide
4.2. ts_append(domain, ruri)
4.3. ts_append_to(tindex, tlabel, domain)
- 5. Statistics
+ 5. MI Commands
+
+ 5.1. ts_dump
+ 5.2. ts_lookup
1. Overview
This modules provides transaction storage for the Kamailio SIP Server
- Platform. It stores in an internal table transactions for an user and
- add branches to them if new contacts are added.
+ Platform. It stores in an internal table transactions for a Request-URI
+ (R-URI) and add branches to them later if new contacts for the AOR are
+ added.
- For each message, the modules stores "Request-URI" ("R-URI"), URI
and
- the internal transaction index and label.
+ When the ts_store function is called, the modules stores the current
+ transaction R-URI URI, index and label. Two functions (ts_append and
+ ts_append_to) provide the ability to add new branches either to a
+ specific transaction or to all of the transactions stored for a given
+ R-URI.
- When the transaction is destroyed (by the TM module, the transaction is
- removed from the module table.
+ When a transaction is destroyed by the TM module, it is removed from
+ the module's table too.
2. Dependencies
@@ -105,7 +115,7 @@ Chapter 1. Admin Guide
must be a power of two, otherwise it will be rounded down to the
nearest power of two.
- Default value is "2048".
+ Default value is “2048”.
Example 1.1. Set hash_size parameter
...
@@ -182,4 +192,23 @@ if (is_method("REGISTER")) {
}
...
-5. Statistics
+5. MI Commands
+
+ 5.1. ts_dump
+ 5.2. ts_lookup
+
+5.1. ts_dump
+
+ Dumps the entire content of the TSILO table
+
+ Parameters:
+ * brief - (optional, may not be present); if equals to string
+ “brief”, a brief dump will be done (only RURI, without the
+ transaction(s) details)
+
+5.2. ts_lookup
+
+ Dumps the transactions stored for the given RURI
+
+ Parameters:
+ * ruri - RURI for which we want to show the transactions.
diff --git a/modules/tsilo/doc/tsilo_admin.xml
b/modules/tsilo/doc/tsilo_admin.xml
index 4c35e69..36180d1 100644
--- a/modules/tsilo/doc/tsilo_admin.xml
+++ b/modules/tsilo/doc/tsilo_admin.xml
@@ -17,17 +17,15 @@
<title>Overview</title>
<para>
This modules provides transaction storage for the
&kamailioname;. It
- stores in an internal table transactions for an user and
add branches
- to them if new contacts are added.
+ stores in an internal table transactions for a Request-URI
(R-URI) and add branches
+ to them later if new contacts for the AOR are added.
</para>
<para>
- For each message, the modules stores
<quote>Request-URI</quote>
- (<quote>R-URI</quote>), &uri; and the internal
transaction
index
- and label.
+ When the <emphasis>ts_store</emphasis> function is called,
the modules stores the current transaction R-URI &uri;, index and label.
Two functions (<emphasis>ts_append</emphasis> and
<emphasis>ts_append_to</emphasis>) provide the ability to add new branches
either to a specific transaction or to all of the transactions stored for a
given R-URI.
</para>
<para>
- When the transaction is destroyed (by the
<emphasis>TM</emphasis> module,
- the transaction is removed from the module table.
+ When a transaction is destroyed by the
<emphasis>TM</emphasis> module,
+ it is removed from the module's table too.
</para>
</section>
<section>
@@ -201,6 +199,36 @@ if (is_method("REGISTER")) {
</section>
<section>
- <title>Statistics</title>
+ <title>MI Commands</title>
+ <section id="tsilo.mi.ts_dump">
+ <title>
+ <function
moreinfo="none">ts_dump</function>
+ </title>
+ <para>
+ Dumps the entire content of the TSILO table
+ </para>
+ <para>Parameters: </para>
+ <itemizedlist>
+ <listitem><para>
+ <emphasis>brief</emphasis> -
(optional, may not be present); if
+ equals to string
<quote>brief</quote>, a brief dump will be
+ done (only RURI, without the
transaction(s) details)
+ </para></listitem>
+ </itemizedlist>
+ </section>
+ <section id="tsilo.mi.ts_lookup">
+ <title>
+ <function
moreinfo="none">ts_lookup</function>
+ </title>
+ <para>
+ Dumps the transactions stored for the given RURI
+ </para>
+ <para>Parameters: </para>
+ <itemizedlist>
+ <listitem><para>
+ <emphasis>ruri</emphasis> - RURI
for which we want to show the transactions.
+ </para></listitem>
+ </itemizedlist>
+ </section>
</section>
</chapter>
diff --git a/modules/tsilo/ts_hash.c b/modules/tsilo/ts_hash.c
index 089f425..6225db6 100644
--- a/modules/tsilo/ts_hash.c
+++ b/modules/tsilo/ts_hash.c
@@ -162,7 +162,7 @@ void unlock_entry(ts_entry_t *entry) {
void lock_entry_by_ruri(str* ruri)
{
- unsigned int sl;
+ unsigned int sl;
sl = core_hash(ruri, 0, 0) & (t_table->size-1);
ts_lock(t_table, &t_table->entries[sl]);
diff --git a/modules/tsilo/ts_hash.h b/modules/tsilo/ts_hash.h
index b895c26..bc7adf1 100644
--- a/modules/tsilo/ts_hash.h
+++ b/modules/tsilo/ts_hash.h
@@ -26,8 +26,8 @@
* Module: \ref tsilo
*/
-#ifndef _DIALOG_TS_HASH_H_
-#define _DIALOG_TS_HASH_H_
+#ifndef _TS_HASH_H_
+#define _TS_HASH_H_
#include "../../locking.h"
#include "../../lib/kmi/mi.h"
@@ -64,10 +64,10 @@ typedef struct ts_urecord
/*! entries in the main transaction table */
typedef struct ts_entry
{
- int n; /*!< Number of elements in the
collision slot */
+ int n; /*!< Number of elements in the
collision slot */
struct ts_urecord *first; /*!< urecord list */
- struct ts_urecord *last; /*!< optimisation, end of the
urecord list */
- unsigned int next_id; /*!< next id */
+ struct ts_urecord *last; /*!< optimisation, end of the
urecord list */
+ unsigned int next_id; /*!< next id */
unsigned int lock_idx; /*!< lock index */
} ts_entry_t;
@@ -75,13 +75,13 @@ typedef struct ts_entry
/*! main transaction table */
typedef struct ts_table
{
- unsigned int size; /*!< size of the dialog table */
+ unsigned int size; /*!< size of the tsilo table */
struct ts_entry *entries; /*!< urecord hash table */
unsigned int locks_no; /*!< number of locks */
- gen_lock_set_t *locks; /*!< lock table */
+ gen_lock_set_t *locks; /*!< lock table */
} ts_table_t;
-/*! global dialog table */
+/*! global transactions table */
extern ts_table_t *t_table;
/*!
diff --git a/modules/tsilo/tsilo.c b/modules/tsilo/tsilo.c
index 90eb292..9c404dd 100644
--- a/modules/tsilo/tsilo.c
+++ b/modules/tsilo/tsilo.c
@@ -32,11 +32,13 @@
#include "../../modules/tm/tm_load.h"
#include "../../modules/registrar/api.h"
#include "../../dset.h"
+#include "../../lib/kmi/mi.h"
#include "ts_hash.h"
#include "ts_handlers.h"
#include "ts_append.h"
#include "ts_store.h"
+#include "ts_mi.h"
MODULE_VERSION
@@ -57,20 +59,24 @@ static int w_ts_append_to(struct sip_msg* msg, char
*idx, char *lbl, char *d);
static int fixup_ts_append_to(void** param, int param_no);
static int w_ts_append(struct sip_msg* _msg, char *_table, char *_ruri);
static int fixup_ts_append(void** param, int param_no);
-
static int w_ts_store(struct sip_msg* msg);
-
static cmd_export_t cmds[]={
{"ts_append_to", (cmd_function)w_ts_append_to, 3,
- fixup_ts_append_to, REQUEST_ROUTE | FAILURE_ROUTE },
+ fixup_ts_append_to, 0, REQUEST_ROUTE | FAILURE_ROUTE },
{"ts_append", (cmd_function)w_ts_append, 2,
- fixup_ts_append, REQUEST_ROUTE | FAILURE_ROUTE },
+ fixup_ts_append, 0, REQUEST_ROUTE | FAILURE_ROUTE },
{"ts_store", (cmd_function)w_ts_store, 0,
- 0 , REQUEST_ROUTE | FAILURE_ROUTE },
+ 0 , 0, REQUEST_ROUTE | FAILURE_ROUTE },
{0,0,0,0,0}
};
+static mi_export_t mi_cmds[] = {
+ { "ts_dump", mi_tsilo_dump, 0, 0, 0
},
+ { "ts_lookup", mi_tsilo_lookup, 0, 0, 0
},
+ { 0, 0, 0, 0, 0}
+};
+
static param_export_t params[]={
{"hash_size", INT_PARAM, &hash_size},
{0,0,0}
@@ -80,13 +86,16 @@ static param_export_t params[]={
/** module exports */
struct module_exports exports= {
"tsilo",
+ DEFAULT_DLFLAGS,
cmds,
- 0, /* RPC methods */
params,
+ 0, /* exported statistics */
+ mi_cmds, /* exported MI functions */
+ 0,
+ 0,
mod_init, /* module initialization function */
0,
(destroy_function) destroy, /* destroy function */
- 0,
0
};
@@ -97,6 +106,13 @@ static int mod_init(void)
{
unsigned int n;
+ /* register the MI commands */
+ if(register_mi_mod(exports.name, mi_cmds)!=0)
+ {
+ LM_ERR("failed to register MI commands\n");
+ return -1;
+ }
+
/* load the TM API */
if (load_tm_api(&_tmb)!=0) {
LM_ERR("can't load TM API\n");
_______________________________________________
sr-dev mailing list
sr-dev(a)lists.sip-router.org
http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev