Skip to content

Commit

Permalink
pdb: implemented rpc commands, removed mi leftovers
Browse files Browse the repository at this point in the history
  • Loading branch information
miconda committed Jan 4, 2017
1 parent e72d96e commit 5911e50
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 60 deletions.
40 changes: 18 additions & 22 deletions src/modules/pdb/doc/pdb_admin.xml
Expand Up @@ -9,7 +9,7 @@

<chapter>
<title>&adminguide;</title>

<section>
<title>Overview</title>
<para>
Expand Down Expand Up @@ -37,7 +37,7 @@
<section>
<title>&kamailio; Modules</title>
<para>
The module depends on the following modules (in the other words
The module depends on the following modules (in the other words
the listed modules must be loaded before this module):
</para>
<itemizedlist>
Expand All @@ -49,7 +49,7 @@
<section>
<title>External Libraries or Applications</title>
<para>
The following libraries or applications must be installed
The following libraries or applications must be installed
before running &kamailio; with this module loaded:
</para>
<itemizedlist>
Expand Down Expand Up @@ -108,9 +108,9 @@ modparam("pdb", "server", "localhost:10001,host.name:10001,192.168.1.7:10002")
<para>
Sends the query string to all configured servers and stores the answer in
dstavp. If it takes more than the configured timeout, false is returned.

Pseudo-variables or AVPs can be used for the query string.

The answer must consist of the null terminated query string followed by
a two byte integer value in network byte order. The integer value will
be stored in the given AVP.
Expand All @@ -130,54 +130,50 @@ cr_route("$avp(i:82)", "$rd", "$rU", "$rU", "call_id");
</section>
</section>
<section>
<title><acronym>MI</acronym> Commands</title>
<section>
<title>
<function moreinfo="none">pdb_status</function>
</title>
<title>RPC Commands</title>
<section id="pdb.r.status">
<title>pdb.status</title>
<para>
Prints the status of the module.
This can either be "active" or "deactivated".
</para>
<example>
<title><function>pdb_status</function> usage</title>
<title><function>pdb.status</function> usage</title>
<programlisting format="linespecific">
...
&ctltool; fifo pdb_status
&kamcmd; pdb.status
...
</programlisting>
</example>
</section>
<section>
<title>
<function moreinfo="none">pdb_activate</function>
</title>
<section id="pdb.r.activate">
<title>pdb.activate</title>
<para>
Activates the module. This is the default after loading the module.
</para>
<example>
<title><function>pdb_activate</function> usage</title>
<title><function>pdb.activate</function> usage</title>
<programlisting format="linespecific">
...
&ctltool; fifo pdb_activate
&kamcmd; pdb.activate
...
</programlisting>
</example>
</section>
<section>
<section id="pdb.r.deactivate">
<title>
<function moreinfo="none">pdb_deactivate</function>
<function moreinfo="none">pdb.deactivate</function>
</title>
<para>
Deactivates the module. No more queries are performed until it is
activated again. As long as the module is deactivated, the
pdb_query function will return -1.
</para>
<example>
<title><function>pdb_deactivate</function> usage</title>
<title><function>pdb.deactivate</function> usage</title>
<programlisting format="linespecific">
...
&ctltool; fifo pdb_deactivate
&kamcmd; pdb.deactivate
...
</programlisting>
</example>
Expand Down
98 changes: 60 additions & 38 deletions src/modules/pdb/pdb.c
Expand Up @@ -27,6 +27,7 @@
#include "../../core/sr_module.h"
#include "../../core/mem/mem.h"
#include "../../core/mem/shm_mem.h"
#include "../../core/rpc_lookup.h"
#include <sys/time.h>
#include <poll.h>
#include <stdlib.h>
Expand Down Expand Up @@ -72,7 +73,8 @@ struct multiparam_t {


/* ---- exported commands: */
static int pdb_query(struct sip_msg *_msg, struct multiparam_t *_number, struct multiparam_t *_dstavp);
static int pdb_query(struct sip_msg *_msg, struct multiparam_t *_number,
struct multiparam_t *_dstavp);

/* ---- fixup functions: */
static int pdb_query_fixup(void **arg, int arg_no);
Expand Down Expand Up @@ -105,16 +107,6 @@ static param_export_t params[] = {
};


#ifdef MI_REMOVED
/* Exported MI functions */
static mi_export_t mi_cmds[] = {
{ "pdb_status", mi_pdb_status, MI_NO_INPUT_FLAG, 0, mi_child_init },
{ "pdb_activate", mi_pdb_activate, MI_NO_INPUT_FLAG, 0, mi_child_init },
{ "pdb_deactivate", mi_pdb_deactivate, MI_NO_INPUT_FLAG, 0, mi_child_init },
{ 0, 0, 0, 0, 0}
};
#endif

struct module_exports exports = {
"pdb",
DEFAULT_DLFLAGS, /* dlopen flags */
Expand Down Expand Up @@ -716,48 +708,78 @@ static void destroy_server_socket(void)
}


#ifdef MI_REMOVED
struct mi_root * mi_pdb_status(struct mi_root* cmd, void* param)
static void pdb_rpc_status(rpc_t* rpc, void* ctx)
{
struct mi_root * root = NULL;
struct mi_node * node = NULL;

if (active == NULL) return init_mi_tree(500, "NULL pointer", 12);

root = init_mi_tree( 200, MI_OK_S, MI_OK_LEN);
if (root == NULL) return NULL;

if (*active) node = addf_mi_node_child(&root->node, 0, 0, 0, "pdb is active");
else node = addf_mi_node_child(&root->node, 0, 0, 0, "pdb is deactivated");
if (node == NULL) {
free_mi_tree(root);
return NULL;
void *vh;
if (active == NULL) {
rpc->fault(ctx, 500, "Active field not initialized");
return;
}

return root;
if (rpc->add(ctx, "{", &vh) < 0) {
rpc->fault(ctx, 500, "Server error");
return;
}
rpc->struct_add(vh, "ds",
"active", *active,
"status", (*active)?"active":"inactive");
}


struct mi_root * mi_pdb_deactivate(struct mi_root* cmd, void* param)
static void pdb_rpc_activate(rpc_t* rpc, void* ctx)
{
if (active == NULL) return init_mi_tree(500, "NULL pointer", 12);
if (active == NULL) {
rpc->fault(ctx, 500, "Active field not initialized");
return;
}
*active=1;
}

static void pdb_rpc_deactivate(rpc_t* rpc, void* ctx)
{
if (active == NULL) {
rpc->fault(ctx, 500, "Active field not initialized");
return;
}
*active=0;
return init_mi_tree(200, MI_OK_S, MI_OK_LEN);
}

static const char* pdb_rpc_status_doc[2] = {
"Get the pdb status.",
0
};

struct mi_root * mi_pdb_activate(struct mi_root* cmd, void* param)
{
if (active == NULL) return init_mi_tree(500, "NULL pointer", 12);
static const char* pdb_rpc_activate_doc[2] = {
"Activate pdb.",
0
};

*active=1;
return init_mi_tree( 200, MI_OK_S, MI_OK_LEN);
static const char* pdb_rpc_deactivate_doc[2] = {
"Deactivate pdb.",
0
};

rpc_export_t pdb_rpc[] = {
{"pdb.status", pdb_rpc_status, pdb_rpc_status_doc, 0},
{"pdb.activate", pdb_rpc_activate, pdb_rpc_activate_doc, 0},
{"pdb.deactivate", pdb_rpc_deactivate, pdb_rpc_deactivate_doc, 0},
{0, 0, 0, 0}
};

static int pdb_rpc_init(void)
{
if (rpc_register_array(pdb_rpc)!=0)
{
LM_ERR("failed to register RPC commands\n");
return -1;
}
return 0;
}
#endif

static int mod_init(void)
{
if(pdb_rpc_init()<0) {
LM_ERR("failed to register RPC commands\n");
return -1;
}
active = shm_malloc(sizeof(*active));
if (active == NULL) {
SHM_MEM_ERROR;
Expand Down

0 comments on commit 5911e50

Please sign in to comment.