[sr-dev] git:pd/outbound: modules/registrar: added additional unregister() exported function to allow the removal of a specific contact
Peter Dunkley
peter.dunkley at crocodile-rcs.com
Fri Mar 1 12:21:12 CET 2013
Module: sip-router
Branch: pd/outbound
Commit: 0a919692b299e2eb819f7c97fa218189849d4566
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=0a919692b299e2eb819f7c97fa218189849d4566
Author: Peter Dunkley <peter.dunkley at crocodile-rcs.com>
Committer: Peter Dunkley <peter.dunkley at crocodile-rcs.com>
Date: Fri Mar 1 11:19:42 2013 +0000
modules/registrar: added additional unregister() exported function to allow the removal of a specific contact
- Contact is removed by using the ruid (unique ID for the location record)
- Getting the ruid to use here is a problem still to be solved.
---
modules/registrar/reg_mod.c | 26 +++++++++++++++++++++++++-
modules/registrar/save.c | 35 +++++++++++++++++++++++++++++------
modules/registrar/save.h | 2 +-
3 files changed, 55 insertions(+), 8 deletions(-)
diff --git a/modules/registrar/reg_mod.c b/modules/registrar/reg_mod.c
index d3fd4f2..586e3cc 100644
--- a/modules/registrar/reg_mod.c
+++ b/modules/registrar/reg_mod.c
@@ -94,6 +94,7 @@ static int w_lookup(struct sip_msg* _m, char* _d, char* _p2);
static int w_lookup_branches(struct sip_msg* _m, char* _d, char* _p2);
static int w_registered(struct sip_msg* _m, char* _d, char* _uri);
static int w_unregister(struct sip_msg* _m, char* _d, char* _uri);
+static int w_unregister2(struct sip_msg* _m, char* _d, char* _uri, char *_ruid);
/*! \brief Fixup functions */
static int domain_fixup(void** param, int param_no);
@@ -186,6 +187,8 @@ static cmd_export_t cmds[] = {
REQUEST_ROUTE },
{"unregister", (cmd_function)w_unregister, 2, unreg_fixup, 0,
REQUEST_ROUTE| FAILURE_ROUTE },
+ {"unregister", (cmd_function)w_unregister2, 3, unreg_fixup, 0,
+ REQUEST_ROUTE| FAILURE_ROUTE },
{"reg_fetch_contacts", (cmd_function)pv_fetch_contacts, 3,
fetchc_fixup, 0,
REQUEST_ROUTE| FAILURE_ROUTE },
@@ -501,7 +504,26 @@ static int w_unregister(struct sip_msg* _m, char* _d, char* _uri)
return -1;
}
- return unregister(_m, (udomain_t*)_d, &uri);
+ return unregister(_m, (udomain_t*)_d, &uri, NULL);
+}
+
+static int w_unregister2(struct sip_msg* _m, char* _d, char* _uri, char *_ruid)
+{
+ str uri = {0};
+ str ruid = {0};
+ if(fixup_get_svalue(_m, (gparam_p)_uri, &uri)!=0 || uri.len<=0)
+ {
+ LM_ERR("invalid uri parameter\n");
+ return -1;
+ }
+ if(fixup_get_svalue(_m, (gparam_p)_ruid, &ruid)!=0 || ruid.len<=0)
+ {
+ LM_ERR("invalid ruid parameter\n");
+ return -1;
+ }
+
+
+ return unregister(_m, (udomain_t*)_d, &uri, &ruid);
}
/*! \brief
@@ -546,6 +568,8 @@ static int unreg_fixup(void** param, int param_no)
return domain_fixup(param, 1);
} else if (param_no == 2) {
return fixup_spve_null(param, 1);
+ } else if (param_no == 3) {
+ return fixup_spve_null(param, 1);
}
return 0;
}
diff --git a/modules/registrar/save.c b/modules/registrar/save.c
index d568334..f55c933 100644
--- a/modules/registrar/save.c
+++ b/modules/registrar/save.c
@@ -953,26 +953,49 @@ error:
return 0;
}
-int unregister(struct sip_msg* _m, udomain_t* _d, str* _uri)
+int unregister(struct sip_msg* _m, udomain_t* _d, str* _uri, str *_ruid)
{
str aor = {0, 0};
sip_uri_t *u;
+ urecord_t *r;
+ ucontact_t *c;
u = parse_to_uri(_m);
if(u==NULL)
return -2;
-
if (extract_aor(_uri, &aor, NULL) < 0) {
LM_ERR("failed to extract Address Of Record\n");
return -1;
}
- if (star(_m, _d, &aor, &u->host) < 0)
- {
- LM_ERR("error unregistering user [%.*s]\n", aor.len, aor.s);
- return -1;
+ if (_ruid == NULL) {
+ /* No ruid provided - remove all contacts for aor */
+
+ if (star(_m, _d, &aor, &u->host) < 0)
+ {
+ LM_ERR("error unregistering user [%.*s]\n", aor.len, aor.s);
+ return -1;
+ }
+ } else {
+ /* ruid provided - remove a specific contact */
+
+ ul.lock_udomain(_d, &aor);
+ if (ul.get_urecord_by_ruid(_d, ul.get_aorhash(&aor),
+ _ruid, r, c) != 0) {
+ ul.unlock_udomain(_d, &aor);
+ LM_WARN("AOR/Contact not found\n");
+ return -1;
+ }
+ if (ul.delete_ucontact(r, c) != 0) {
+ ul.unlock_udomain(_d, &aor);
+ LM_WARN("could not delete contact\n");
+ return -1;
+ }
+ ul.release_urecord(r);
+ ul.unlock_udomain(_d, &aor);
}
+
return 1;
}
diff --git a/modules/registrar/save.h b/modules/registrar/save.h
index 69e1352..c6aa928 100644
--- a/modules/registrar/save.h
+++ b/modules/registrar/save.h
@@ -47,7 +47,7 @@
* Process REGISTER request and save it's contacts
*/
int save(struct sip_msg* _m, udomain_t* _d, int _cflags, str* _uri);
-int unregister(struct sip_msg* _m, udomain_t* _d, str* _uri);
+int unregister(struct sip_msg* _m, udomain_t* _d, str* _uri, str *_ruid);
#endif /* SAVE_H */
More information about the sr-dev
mailing list