Browse Source

modules/ims_registrar_scscf: new RPC command regscscf.dereg_impu to initiate network de-register

Richard Good 9 years ago
parent
commit
70a8652f3a

+ 2 - 3
modules/ims_registrar_scscf/doc/ims_registrar_scscf_admin.xml

@@ -913,9 +913,8 @@ if (can_publish_reg("location")){
     <para>exported RPC commands.</para>
 
     <section>
-      <title>ulpcscf.status</title>
-
-      <para>Status of pcscf_usrloc, AORs, max slots, etc.</para>
+      <title>regscscf.dereg_impu</title>
+      <para>Initiate network de-register of IMPU</para>
     </section>
   </section>
 

+ 10 - 2
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, &notification_list_size_threshold},
-    {"notification_processes", INT_PARAM, &notification_processes},
-    {"send_vs_callid_avp", INT_PARAM, &send_vs_callid_avp},
+	{"notification_processes", INT_PARAM, &notification_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;

+ 82 - 0
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}
+};
+
+

+ 28 - 0
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