diff --git a/modules/dmq_usrloc/README b/modules/dmq_usrloc/README index b259c3ac367..c22b9fa286e 100644 --- a/modules/dmq_usrloc/README +++ b/modules/dmq_usrloc/README @@ -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 @@ -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 @@ -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) ... diff --git a/modules/dmq_usrloc/dmq_usrloc.c b/modules/dmq_usrloc/dmq_usrloc.c index 4505a7031a9..cd5fedd40ce 100644 --- a/modules/dmq_usrloc/dmq_usrloc.c +++ b/modules/dmq_usrloc/dmq_usrloc.c @@ -1,24 +1,24 @@ /* -* Copyright (C) 2014 Andrey Rybkin -* -* 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 + * + * 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 #include "../../sr_module.h" @@ -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} }; @@ -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) diff --git a/modules/dmq_usrloc/doc/dmq_usrloc_admin.xml b/modules/dmq_usrloc/doc/dmq_usrloc_admin.xml index 59c58e855ec..abd529dab7a 100644 --- a/modules/dmq_usrloc/doc/dmq_usrloc_admin.xml +++ b/modules/dmq_usrloc/doc/dmq_usrloc_admin.xml @@ -16,7 +16,8 @@
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.
@@ -28,8 +29,12 @@ - DMQ module must be loaded first.. - USRLOC module must be loaded first.. + DMQ module.. + + + + + USRLOC module.. @@ -41,34 +46,34 @@
<varname>enable</varname> (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. -
-
- <varname>flag</varname> (int) - - Flag to be used for marking if a contact should be constructed for the DMQ - - - - Default value is 2. - - - Set <varname>flag</varname> parameter + Set <varname>enable</varname> parameter ... -modparam("dmq_usrloc", "flag", 2) +modparam("dmq_usrloc", "enable", 1) ... - +
diff --git a/modules/dmq_usrloc/usrloc_sync.c b/modules/dmq_usrloc/usrloc_sync.c index 7ef38946128..e68949c56be 100644 --- a/modules/dmq_usrloc/usrloc_sync.c +++ b/modules/dmq_usrloc/usrloc_sync.c @@ -40,11 +40,10 @@ dmq_resp_cback_t usrloc_dmq_resp_callback = {&usrloc_dmq_resp_callback_f, 0}; int usrloc_dmq_send_all(); int usrloc_dmq_request_sync(); int usrloc_dmq_send_contact(ucontact_t* ptr, str aor, int action, dmq_node_t* node); -usrloc_api_t ul; #define MAX_AOR_LEN 256 -int add_contact(str aor, ucontact_info_t* ci) +static int add_contact(str aor, ucontact_info_t* ci) { urecord_t* r; udomain_t* _d; @@ -52,14 +51,14 @@ int add_contact(str aor, ucontact_info_t* ci) str contact; int res; - ul.get_udomain("location", &_d); - res = ul.get_urecord(_d, &aor, &r); + dmq_ul.get_udomain("location", &_d); + res = dmq_ul.get_urecord(_d, &aor, &r); if (res < 0) { LM_ERR("failed to retrieve record from usrloc\n"); goto error; } else if ( res == 0) { LM_DBG("'%.*s' found in usrloc\n", aor.len, ZSW(aor.s)); - res = ul.get_ucontact(r, ci->c, ci->callid, ci->path, ci->cseq, &c); + res = dmq_ul.get_ucontact(r, ci->c, ci->callid, ci->path, ci->cseq, &c); LM_DBG("get_ucontact = %d\n", res); if (res==-1) { LM_ERR("Invalid cseq\n"); @@ -68,28 +67,28 @@ int add_contact(str aor, ucontact_info_t* ci) LM_DBG("Not found contact\n"); contact.s = ci->c->s; contact.len = ci->c->len; - ul.insert_ucontact(r, &contact, ci, &c); + dmq_ul.insert_ucontact(r, &contact, ci, &c); } else if (res == 0) { LM_DBG("Found contact\n"); - ul.update_ucontact(r, c, ci); + dmq_ul.update_ucontact(r, c, ci); } } else { LM_DBG("'%.*s' Not found in usrloc\n", aor.len, ZSW(aor.s)); - ul.insert_urecord(_d, &aor, &r); + dmq_ul.insert_urecord(_d, &aor, &r); LM_DBG("Insert record\n"); contact.s = ci->c->s; contact.len = ci->c->len; - ul.insert_ucontact(r, &contact, ci, &c); + dmq_ul.insert_ucontact(r, &contact, ci, &c); LM_DBG("Insert ucontact\n"); } LM_DBG("Release record\n"); - ul.release_urecord(r); + dmq_ul.release_urecord(r); LM_DBG("Unlock udomain\n"); - ul.unlock_udomain(_d, &aor); + dmq_ul.unlock_udomain(_d, &aor); return 0; error: - ul.unlock_udomain(_d, &aor); + dmq_ul.unlock_udomain(_d, &aor); return -1; } @@ -113,11 +112,11 @@ void usrloc_get_all_ucontact(dmq_node_t* node) ucontact_t* ptr = 0; int res; - if (ul.get_all_ucontacts == NULL){ - LM_ERR("ul.get_all_ucontacts is NULL\n"); + if (dmq_ul.get_all_ucontacts == NULL){ + LM_ERR("dmq_ul.get_all_ucontacts is NULL\n"); goto done; } - rval = ul.get_all_ucontacts(buf, len, 0, 0, 1); + rval = dmq_ul.get_all_ucontacts(buf, len, 0, 0, 1); if (rval<0) { LM_ERR("failed to fetch contacts\n"); goto done; @@ -131,7 +130,7 @@ void usrloc_get_all_ucontact(dmq_node_t* node) LM_ERR("out of pkg memory\n"); goto done; } - rval = ul.get_all_ucontacts(buf, len, 0, 0, 1); + rval = dmq_ul.get_all_ucontacts(buf, len, 0, 0, 1); if (rval != 0) { pkg_free(buf); goto done; @@ -159,14 +158,14 @@ void usrloc_get_all_ucontact(dmq_node_t* node) memcpy( &aorhash, cp, sizeof(aorhash)); cp = (char*)cp + sizeof(aorhash); - ul.get_udomain("location", &_d); + dmq_ul.get_udomain("location", &_d); - res = ul.get_urecord_by_ruid(_d, aorhash, &ruid, &r, &ptr); + res = dmq_ul.get_urecord_by_ruid(_d, aorhash, &ruid, &r, &ptr); aor = r->aor; if (res > 0) { LM_DBG("'%.*s' Not found in usrloc\n", aor.len, ZSW(aor.s)); - ul.release_urecord(r); - ul.unlock_udomain(_d, &aor); + dmq_ul.release_urecord(r); + dmq_ul.unlock_udomain(_d, &aor); continue; } LM_DBG("- AoR: %.*s AoRhash=%d Flags=%d\n", aor.len, aor.s, aorhash, flags); @@ -175,8 +174,8 @@ void usrloc_get_all_ucontact(dmq_node_t* node) usrloc_dmq_send_contact(ptr, aor, DMQ_UPDATE, node); ptr = ptr->next; } - ul.release_urecord(r); - ul.unlock_udomain(_d, &aor); + dmq_ul.release_urecord(r); + dmq_ul.unlock_udomain(_d, &aor); } pkg_free(buf); @@ -340,7 +339,7 @@ int usrloc_dmq_handle_msg(struct sip_msg* msg, peer_reponse_t* resp, dmq_node_t* ci.callid = &callid; ci.cseq = cseq; ci.flags = flags; - ci.flags |= usrloc_dmq_flag; + ci.flags |= FL_RPL; ci.cflags = cflags; ci.user_agent = &user_agent; ci.methods = methods; @@ -434,7 +433,7 @@ int usrloc_dmq_send_contact(ucontact_t* ptr, str aor, int action, dmq_node_t* no } flags = ptr->flags; - flags &= ~usrloc_dmq_flag; + flags &= ~FL_RPL; srjson_AddNumberToObject(&jdoc, jdoc.root, "action", action); @@ -488,7 +487,7 @@ int usrloc_dmq_resp_callback_f(struct sip_msg* msg, int code, return 0; } -void ul_cb_contact(ucontact_t* ptr, int type, void* param) +void dmq_ul_cb_contact(ucontact_t* ptr, int type, void* param) { str aor; @@ -496,7 +495,7 @@ void ul_cb_contact(ucontact_t* ptr, int type, void* param) aor.s = ptr->aor->s; aor.len = ptr->aor->len; - if (!(ptr->flags & usrloc_dmq_flag)) { + if (!(ptr->flags & FL_RPL)) { switch(type){ case UL_CONTACT_INSERT: diff --git a/modules/dmq_usrloc/usrloc_sync.h b/modules/dmq_usrloc/usrloc_sync.h index d5678a22ac2..c00e19904f2 100644 --- a/modules/dmq_usrloc/usrloc_sync.h +++ b/modules/dmq_usrloc/usrloc_sync.h @@ -29,14 +29,8 @@ #include "../../parser/parse_content.h" #include "../usrloc/usrloc.h" -int usrloc_dmq_flag; -extern dmq_api_t usrloc_dmqb; -extern dmq_peer_t* usrloc_dmq_peer; -extern dmq_resp_cback_t usrloc_dmq_resp_callback; -extern rpc_export_t ul_rpc[]; - -usrloc_api_t ul; +extern usrloc_api_t dmq_ul; typedef enum { DMQ_NONE, @@ -49,6 +43,6 @@ int usrloc_dmq_resp_callback_f(struct sip_msg* msg, int code, dmq_node_t* node, int usrloc_dmq_initialize(); int usrloc_dmq_handle_msg(struct sip_msg* msg, peer_reponse_t* resp, dmq_node_t* node); int usrloc_dmq_request_sync(); -void ul_cb_contact(ucontact_t* c, int type, void* param); +void dmq_ul_cb_contact(ucontact_t* c, int type, void* param); #endif