浏览代码

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.
Peter Dunkley 12 年之前
父节点
当前提交
0a919692b2
共有 3 个文件被更改,包括 55 次插入8 次删除
  1. 25 1
      modules/registrar/reg_mod.c
  2. 29 6
      modules/registrar/save.c
  3. 1 1
      modules/registrar/save.h

+ 25 - 1
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;
 }

+ 29 - 6
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;
 }
 

+ 1 - 1
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 */