Skip to content

Commit

Permalink
dmq_usrloc: use usrloc internal flag for replication
Browse files Browse the repository at this point in the history
- flags field in location record is for internal usage and must not be
  defined outside the module, because it can end up in conflicts in the
  future
- removed the parameter that was used to set the flag
- added dmq_ul prefix for global vars to avoid shared objects conflicts
- removed unused extern declarations
  • Loading branch information
miconda committed Jan 23, 2015
1 parent e7e5fd6 commit 836e693
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 122 deletions.
29 changes: 11 additions & 18 deletions modules/dmq_usrloc/README
Expand Up @@ -27,11 +27,10 @@ Andrey Rybkin
3. Parameters

3.1. enable (int)
3.2. flag (int)

List of Examples

1.1. Set flag parameter
1.1. Set enable parameter

Chapter 1. Admin Guide

Expand All @@ -45,12 +44,11 @@ Chapter 1. Admin Guide
3. Parameters

3.1. enable (int)
3.2. flag (int)

1. Overview

The module add usrloc contacts replication between multiple servers via
DMQ module.
The module adds user location (usrloc) records replication between
multiple servers via DMQ module.

2. Dependencies

Expand All @@ -59,28 +57,23 @@ Chapter 1. Admin Guide
2.1. Kamailio Modules

The following modules must be loaded before this module:
* DMQ module must be loaded first.. USRLOC module must be loaded
first..
* DMQ module..
* USRLOC module..

3. Parameters

3.1. enable (int)
3.2. flag (int)

3.1. enable (int)

USRLOC replication 0 - disabled 1 - enabled
The parameter controls whetner the replication is active or not. The
value can be:
* 0 - replication is disabled
* 1 - replication is enabled

Default value is 0.

3.2. flag (int)

Flag to be used for marking if a contact should be constructed for the
DMQ

Default value is 2.

Example 1.1. Set flag parameter
Example 1.1. Set enable parameter
...
modparam("dmq_usrloc", "flag", 2)
modparam("dmq_usrloc", "enable", 1)
...
99 changes: 49 additions & 50 deletions modules/dmq_usrloc/dmq_usrloc.c
@@ -1,24 +1,24 @@
/*
* Copyright (C) 2014 Andrey Rybkin <rybkin.a@bks.tv>
*
* This file is part of Kamailio, a free SIP server.
*
* This file is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version
*
*
* This file is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
* Copyright (C) 2014 Andrey Rybkin <rybkin.a@bks.tv>
*
* This file is part of Kamailio, a free SIP server.
*
* This file is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version
*
*
* This file is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/

#include <stdio.h>
#include "../../sr_module.h"
Expand All @@ -34,14 +34,14 @@
static int mod_init(void);
static int child_init(int);

int enable_usrloc = 0;
int usrloc_syncflag = 2;
int dmq_usrloc_enable = 0;

usrloc_api_t dmq_ul;

MODULE_VERSION

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

Expand All @@ -63,35 +63,34 @@ struct module_exports exports = {

static int mod_init(void)
{
LM_ERR("dmq_usrloc 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");
bind_usrloc_t bind_usrloc;
LM_INFO("dmq usrloc replication mode = %d\n", dmq_usrloc_enable);

if (dmq_usrloc_enable) {

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(&dmq_ul) < 0) {
LM_ERR("Can't bind ul\n");
return -1;
}
if(dmq_ul.register_ulcb != NULL) {
if(dmq_ul.register_ulcb(ULCB_MAX, dmq_ul_cb_contact, 0)< 0)
{
LM_ERR("can not register callback for expired contacts\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("dmq_usrloc initialized\n");
} else {
LM_ERR("Error in dmq_usrloc_initialize()\n");
}
}
return 0;
if (!usrloc_dmq_initialize()){
LM_DBG("dmq_usrloc initialized\n");
} else {
LM_ERR("Error in dmq_usrloc_initialize()\n");
}
}
return 0;
}

static int child_init(int rank)
Expand Down
45 changes: 25 additions & 20 deletions modules/dmq_usrloc/doc/dmq_usrloc_admin.xml
Expand Up @@ -16,7 +16,8 @@
<section>
<title>Overview</title>
<para>
The module add usrloc contacts replication between multiple servers via DMQ module.
The module adds user location (usrloc) records replication
between multiple servers via DMQ module.
</para>
</section>
<section>
Expand All @@ -28,8 +29,12 @@
<itemizedlist>
<listitem>
<para>
<emphasis>DMQ module must be loaded first.</emphasis>.
<emphasis>USRLOC module must be loaded first.</emphasis>.
<emphasis>DMQ module.</emphasis>.
</para>
</listitem>
<listitem>
<para>
<emphasis>USRLOC module.</emphasis>.
</para>
</listitem>
</itemizedlist>
Expand All @@ -41,34 +46,34 @@
<section id="usrloc_dmq.p.enable">
<title><varname>enable</varname> (int)</title>
<para>
USRLOC replication
0 - disabled
1 - enabled
The parameter controls whetner the replication is active or not.
The value can be:
<itemizedlist>
<listitem>
<para>
0 - replication is disabled
</para>
</listitem>
<listitem>
<para>
1 - replication is enabled
</para>
</listitem>
</itemizedlist>
</para>
<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>
<title>Set <varname>enable</varname> parameter</title>
<programlisting format="linespecific">
...
modparam("dmq_usrloc", "flag", 2)
modparam("dmq_usrloc", "enable", 1)
...
</programlisting>
</example>
</example>
</section>
</section>

Expand Down

0 comments on commit 836e693

Please sign in to comment.