[asterisk-commits] eliel: branch eliel/data_retrieval r191624 - /team/eliel/data_retrieval/main/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri May 1 17:54:29 CDT 2009


Author: eliel
Date: Fri May  1 17:54:26 2009
New Revision: 191624

URL: http://svn.digium.com/svn-view/asterisk?view=rev&rev=191624
Log:
Allow unregistering every node registered by a registrar passing
a NULL path.

Modified:
    team/eliel/data_retrieval/main/data.c

Modified: team/eliel/data_retrieval/main/data.c
URL: http://svn.digium.com/svn-view/asterisk/team/eliel/data_retrieval/main/data.c?view=diff&rev=191624&r1=191623&r2=191624
==============================================================================
--- team/eliel/data_retrieval/main/data.c (original)
+++ team/eliel/data_retrieval/main/data.c Fri May  1 17:54:26 2009
@@ -215,6 +215,8 @@
 	if (found && found->registrar && registrar) {
 		if (strcmp(found->registrar, registrar)) {
 			/* if the name doesn't match, do not return this node. */
+			ast_log(LOG_DEBUG, "Registrar doesn't match, node was registered by '%s' "
+				"and we are searching for '%s'\n", found->registrar, registrar);
 			ao2_ref(found, -1);
 			return NULL;
 		}
@@ -271,6 +273,38 @@
 
 /*!
  * \internal
+ * \brief Release every node registered by 'registrar'.
+ * \param[in] parent The parent node.
+ * \param[in] registrar
+ * \see __ast_data_unregister
+ */
+static void data_node_provider_release_all(struct ao2_container *parent, const char *registrar)
+{
+	struct ao2_iterator i;
+	struct data_node_provider *node;
+
+	i = ao2_iterator_init(parent, 0);
+	while ((node = ao2_iterator_next(&i))) {
+		if (!node->handler) {
+			/* this is a non-terminal node, go inside it. */
+			data_node_provider_release_all(node->children, registrar);
+			if (!ao2_container_count(node->children)) {
+				/* if this node was left empty, unlink it. */
+				ao2_unlink(parent, node);
+			}
+		} else {
+			if (!strcmp(node->registrar, registrar)) {
+				/* if the registrars match, release it! */
+				ao2_unlink(parent, node);
+			}
+		}
+		ao2_ref(node, -1);
+	}
+
+}
+
+/*!
+ * \internal
  * \brief Create the middle nodes for the specified path (asterisk/testnode1/childnode)
  * \param[in] parent Where to add the middle nodes structure.
  * \param[in] path The path of nodes to add.
@@ -350,15 +384,17 @@
 
 int __ast_data_unregister(const char *path, const char *registrar)
 {
-	int ret;
-
-	/* XXX: if path is NULL, unregister every node that was registered by 'registrar' */
+	int ret = 0;
 
 	data_write_lock();
-	ret = data_node_provider_release(root_data, path, registrar);
+	if (path) {
+		ret = data_node_provider_release(root_data, path, registrar);
+	} else {
+		data_node_provider_release_all(root_data, registrar);
+	}
 	data_unlock();
 
-	if (ret) {
+	if (path && ret) {
 		ast_log(LOG_ERROR, "Unable to unregister '%s' for '%s'\n", path, registrar);
 	}
 
@@ -387,7 +423,7 @@
 
 	/* some tests */
 	ast_data_register("asterisk/node1/node11/node111", &test_provider);
-	ast_data_unregister("asterisk/node1/node11/node111");
+	ast_data_unregister(NULL);
 
 	return 0;
 }




More information about the asterisk-commits mailing list