Skip to content

Commit

Permalink
Merge pull request #3 from AndreyRybkin/master
Browse files Browse the repository at this point in the history
usrloc_dmq: add module for usrloc sync via dmq
  • Loading branch information
miconda committed Jan 3, 2015
2 parents 03dfde0 + 68ca030 commit 2f1c30a
Show file tree
Hide file tree
Showing 7 changed files with 795 additions and 0 deletions.
9 changes: 9 additions & 0 deletions modules/usrloc_dmq/Makefile
@@ -0,0 +1,9 @@
include ../../Makefile.defs
auto_gen=
NAME=usrloc_dmq.so

DEFS+=-DKAMAILIO_MOD_INTERFACE

SERLIBPATH=../../lib
SER_LIBS+=$(SERLIBPATH)/srutils/srutils
include ../../Makefile.modules
4 changes: 4 additions & 0 deletions modules/usrloc_dmq/doc/Makefile
@@ -0,0 +1,4 @@
docs = usrloc_dmq.xml

docbook_dir = ../../../docbook
include $(docbook_dir)/Makefile.module
48 changes: 48 additions & 0 deletions modules/usrloc_dmq/doc/usrloc_dmq.xml
@@ -0,0 +1,48 @@
<?xml version="1.0" encoding='ISO-8859-1'?>
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
"http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd" [

<!-- Include general documentation entities -->
<!ENTITY % docentities SYSTEM "../../../docbook/entities.xml">
%docentities;

]>

<book xmlns:xi="http://www.w3.org/2001/XInclude">
<bookinfo>
<title>usrloc_dmq Module</title>
<productname class="trade">&kamailioname;</productname>
<authorgroup>
<author>
<firstname>Andrey</firstname>
<surname>Rybkin</surname>
<affiliation><orgname>bks.tv</orgname></affiliation>
<email>rybkin.a@bks.tv</email>
<address>
<otheraddr>
<ulink></ulink>
</otheraddr>
</address>
</author>
<editor>
<firstname>Andrey</firstname>
<surname>Rybkin</surname>
<affiliation><orgname>bks.tv</orgname></affiliation>
<email>rybkin.a@bks.tv</email>
<address>
<otheraddr>
<ulink></ulink>
</otheraddr>
</address>
</editor>
</authorgroup>
<copyright>
<year>2014</year>
</copyright>
</bookinfo>
<toc></toc>

<xi:include href="usrloc_dmq_admin.xml"/>


</book>
74 changes: 74 additions & 0 deletions modules/usrloc_dmq/doc/usrloc_dmq_admin.xml
@@ -0,0 +1,74 @@
<?xml version="1.0" encoding='ISO-8859-1'?>
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
"http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd" [

<!-- Include general documentation entities -->
<!ENTITY % docentities SYSTEM "../../../docbook/entities.xml">
%docentities;

]>
<!-- Module User's Guide -->

<chapter>

<title>&adminguide;</title>

<section>
<title>Overview</title>
<para>
The module add usrloc contacts replication between multiple servers via DMQ module.
</para>
</section>
<section>
<title>Dependencies</title>
<section>
<title>&kamailio; Modules</title>
<para>
The following modules must be loaded before this module:
<itemizedlist>
<listitem>
<para>
<emphasis>DMQ module must be loaded first.</emphasis>.
<emphasis>USRLOC module must be loaded first.</emphasis>.
</para>
</listitem>
</itemizedlist>
</para>
</section>
<section>
<title>Parameters</title>
<section id="usrloc_dmq.p.enable">
<title><varname>enable</varname> (int)</title>
<para>
USRLOC replication
0 - disabled
1 - enabled
</para>
<emphasis>
Default value is 0.
</emphasis>
</para>
</section>
<section id="usrloc_dmq.p.flag">
<title><varname>flag</varname> (int)</title>
<para>
Flag to be used for marking if a contact should be constructed for the DMQ
</para>
<para>
<emphasis>
Default value is 2.
</emphasis>
</para>
<example>
<title>Set <varname>flag</varname> parameter</title>
<programlisting format="linespecific">
...
modparam("usrloc_dmq", "flag", 2)
...
</programlisting>
</example>
</section>
</section>

</chapter>

87 changes: 87 additions & 0 deletions modules/usrloc_dmq/usrloc_dmq.c
@@ -0,0 +1,87 @@
#include <stdio.h>
#include "../../sr_module.h"
#include "../../dprint.h"
#include "../../error.h"
#include "../../modules/usrloc/usrloc.h"
#include "../usrloc/ul_callback.h"
#include "../../modules/sl/sl.h"
#include "../../mod_fix.h"

#include "usrloc_sync.h"

static int mod_init(void);
static int child_init(int);

int enable_usrloc = 0;
int usrloc_syncflag = 2;

MODULE_VERSION

static param_export_t params[] = {
{"enable", INT_PARAM, &enable_usrloc},
{"flag", INT_PARAM, &usrloc_syncflag},
{0, 0, 0}
};

struct module_exports exports = {
"usrloc_dmq", /* module name */
DEFAULT_DLFLAGS, /* dlopen flags */
0, /* exported functions */
params, /* exported parameters */
0, /* exported statistics */
0, /* exported MI functions */
0, /* exported pseudo-variables */
0, /* extra processes */
mod_init, /* module initialization function */
0, /* response handling function */
0, /* destroy function */
child_init /* per-child init function */
};


static int mod_init(void)
{
LM_ERR("dmq_sync loaded: usrloc=%d\n", enable_usrloc);

if (enable_usrloc) {
usrloc_dmq_flag = 1 << usrloc_syncflag;
bind_usrloc_t bind_usrloc;

bind_usrloc = (bind_usrloc_t)find_export("ul_bind_usrloc", 1, 0);
if (!bind_usrloc) {
LM_ERR("can't bind usrloc\n");
return -1;
}
if (bind_usrloc(&ul) < 0) {
LM_ERR("Can't bind ul\n");
return -1;
}
if(ul.register_ulcb != NULL) {
if(ul.register_ulcb(ULCB_MAX, ul_cb_contact, 0)< 0)
{
LM_ERR("can not register callback for expired contacts\n");
return -1;
}
}
if (!usrloc_dmq_initialize()){
LM_DBG("usrloc_dmq initialized\n");
} else {
LM_ERR("Error in usrloc_dmq_initialize()\n");
}
}
return 0;
}

static int child_init(int rank)
{

if (rank == PROC_MAIN) {
LM_ERR("child_init PROC_MAIN\n");
return 0;
}
if(rank == PROC_INIT || rank == PROC_TCP_MAIN) {
LM_ERR("child_init PROC_INIT\n");
return 0;
}
return 0;
}

0 comments on commit 2f1c30a

Please sign in to comment.