From 70a8652f3a6b11718ee1a21a0dad1503d3af1902 Mon Sep 17 00:00:00 2001 From: Richard Good Date: Fri, 22 Jul 2016 08:49:13 +0200 Subject: [PATCH] modules/ims_registrar_scscf: new RPC command regscscf.dereg_impu to initiate network de-register --- .../doc/ims_registrar_scscf_admin.xml | 5 +- modules/ims_registrar_scscf/reg_mod.c | 12 ++- modules/ims_registrar_scscf/reg_rpc.c | 82 +++++++++++++++++++ modules/ims_registrar_scscf/reg_rpc.h | 28 +++++++ 4 files changed, 122 insertions(+), 5 deletions(-) create mode 100644 modules/ims_registrar_scscf/reg_rpc.c create mode 100644 modules/ims_registrar_scscf/reg_rpc.h diff --git a/modules/ims_registrar_scscf/doc/ims_registrar_scscf_admin.xml b/modules/ims_registrar_scscf/doc/ims_registrar_scscf_admin.xml index 76a0f35e9b8..b8f3cc46afd 100644 --- a/modules/ims_registrar_scscf/doc/ims_registrar_scscf_admin.xml +++ b/modules/ims_registrar_scscf/doc/ims_registrar_scscf_admin.xml @@ -913,9 +913,8 @@ if (can_publish_reg("location")){ exported RPC commands.
- ulpcscf.status - - Status of pcscf_usrloc, AORs, max slots, etc. + regscscf.dereg_impu + Initiate network de-register of IMPU
diff --git a/modules/ims_registrar_scscf/reg_mod.c b/modules/ims_registrar_scscf/reg_mod.c index 13adaabfc42..76e4485b4cb 100644 --- a/modules/ims_registrar_scscf/reg_mod.c +++ b/modules/ims_registrar_scscf/reg_mod.c @@ -50,6 +50,7 @@ #include "../../sr_module.h" #include "../../timer.h" #include "../../dprint.h" +#include "../../rpc_lookup.h" #include "../../error.h" #include "../../socket_info.h" #include "../../pvar.h" @@ -74,6 +75,7 @@ #include "registrar_notify.h" #include "../cdp_avp/mod_export.h" #include "pvt_message.h" +#include "reg_rpc.h" MODULE_VERSION @@ -271,8 +273,9 @@ static param_export_t params[] = { {"subscription_expires_range", INT_PARAM, &subscription_expires_range}, {"user_data_always", INT_PARAM, &user_data_always}, {"notification_list_size_threshold", INT_PARAM, ¬ification_list_size_threshold}, - {"notification_processes", INT_PARAM, ¬ification_processes}, - {"send_vs_callid_avp", INT_PARAM, &send_vs_callid_avp}, + {"notification_processes", INT_PARAM, ¬ification_processes}, + {"send_vs_callid_avp", INT_PARAM, &send_vs_callid_avp}, + {0, 0, 0} }; @@ -318,6 +321,11 @@ static int mod_init(void) { str s; bind_usrloc_t bind_usrloc; qvalue_t dq; + + if (rpc_register_array(reg_rpc) != 0) { + LM_ERR("failed to register RPC commands\n"); + return -1; + } callback_singleton = shm_malloc(sizeof (int)); *callback_singleton = 0; diff --git a/modules/ims_registrar_scscf/reg_rpc.c b/modules/ims_registrar_scscf/reg_rpc.c new file mode 100644 index 00000000000..f24e15123fb --- /dev/null +++ b/modules/ims_registrar_scscf/reg_rpc.c @@ -0,0 +1,82 @@ +/* + * $Id$ + * + * usrloc module + * + * Copyright (C) 2009 Daniel-Constantin Mierla (asipto.com). + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include "../../ip_addr.h" +#include "../../dprint.h" + +#include "reg_rpc.h" +#include "../ims_usrloc_scscf/usrloc.h" +#include "registrar_notify.h" + + +static const char* reg_rpc_dereg_impu_doc[2] = {"De-register IMPU from S-CSCF", 0}; + +extern usrloc_api_t ul; + +static void reg_rpc_dereg_impu(rpc_t* rpc, void* ctx) +{ + int i; + str impu; + int res; + udomain_t* domain; + struct impurecord* impu_rec; + + if (rpc->scan(ctx, "S", &impu) < 1) { + rpc->fault(ctx, 400, "required IMPU argument"); + return; + } + + LM_DBG("Request to re-register impu <%.*s>\n", impu.len, impu.s); + + res = ul.get_udomain("location", &domain); + if (res != 0) { + LM_ERR("Failed to get domain\n"); + return; + } + + ul.lock_udomain(domain, &impu); + res = ul.get_impurecord(domain, &impu, &impu_rec); + if (res != 0) { + LM_ERR("Trying to de-register '%.*s' Not found in usrloc\n", impu.len, impu.s); + ul.unlock_udomain(domain, &impu); + return; + } + + for (i = 0; i < impu_rec->num_contacts; i++) { + LM_DBG("Deleting contact with AOR [%.*s]\n", impu_rec->newcontacts[i]->aor.len, impu_rec->newcontacts[i]->aor.s); + ul.lock_contact_slot_i(impu_rec->newcontacts[i]->sl); + impu_rec->newcontacts[i]->state = CONTACT_DELETE_PENDING; + if (impu_rec->shead) { + //send NOTIFY to all subscribers of this IMPU. + notify_subscribers(impu_rec, 0, 0); + } + impu_rec->newcontacts[i]->state = CONTACT_DELETED; + ul.unlock_contact_slot_i(impu_rec->newcontacts[i]->sl); + } + + ul.unlock_udomain(domain, &impu); +} + +rpc_export_t reg_rpc[] = { + {"regscscf.dereg_impu", reg_rpc_dereg_impu, reg_rpc_dereg_impu_doc, 0}, + {0, 0, 0, 0} +}; + + diff --git a/modules/ims_registrar_scscf/reg_rpc.h b/modules/ims_registrar_scscf/reg_rpc.h new file mode 100644 index 00000000000..218f27bb131 --- /dev/null +++ b/modules/ims_registrar_scscf/reg_rpc.h @@ -0,0 +1,28 @@ +/* + * $Id$ + * + * usrloc module + * + * Copyright (C) 2009 Daniel-Constantin Mierla (asipto.com). + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef _REG_RPC_H_ +#define _REG_RPC_H_ + +#include "../../rpc.h" + +extern rpc_export_t reg_rpc[]; + +#endif