[asterisk-commits] russell: branch russell/data_retrieval r111995 - in /team/russell/data_retrie...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Mar 31 11:32:30 CDT 2008


Author: russell
Date: Mon Mar 31 11:32:29 2008
New Revision: 111995

URL: http://svn.digium.com/view/asterisk?view=rev&rev=111995
Log:
Add a friendly name attribute to data nodes to help improve CLI presentation.
I'm not especially thrilled about this ... but I think it's probably worth it ...

Modified:
    team/russell/data_retrieval/channels/chan_sip.c
    team/russell/data_retrieval/include/asterisk/data.h
    team/russell/data_retrieval/main/data.c

Modified: team/russell/data_retrieval/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/russell/data_retrieval/channels/chan_sip.c?view=diff&rev=111995&r1=111994&r2=111995
==============================================================================
--- team/russell/data_retrieval/channels/chan_sip.c (original)
+++ team/russell/data_retrieval/channels/chan_sip.c Mon Mar 31 11:32:29 2008
@@ -8314,9 +8314,9 @@
 
 	if (!dst->data && !(dst->data = ast_str_create(src->data->used + 1)))
 		return;
-	else if (dst->data->len < src->data->used)
+	else if (dst->data->len < src->data->used + 1)
 		ast_str_make_space(&dst->data, src->data->used + 1);
-		
+
 	memcpy(dst->data->str, src->data->str, src->data->used + 1);
 	dst->data->used = src->data->used;
 	offset = ((void *)dst->data->str) - ((void *)src->data->str);
@@ -21446,29 +21446,35 @@
 	struct ast_data_node *settings_node;
 	int res = 0;
 
-	if (!(settings_node = ast_data_node_new("sip_settings"))) {
+	if (!(settings_node = ast_data_node_new("sip_settings", "SIP Channel Driver Settings"))) {
 		return NULL;
 	}
 
-	res |= ast_data_node_add_child_str(settings_node, "bindaddr", ast_inet_ntoa(bindaddr.sin_addr));
-	res |= ast_data_node_add_child_uint(settings_node, "bindport", (uint32_t) ntohs(bindaddr.sin_port));
-	res |= ast_data_node_add_child_bool(settings_node, "videosupport",
+	res |= ast_data_node_add_child_str(settings_node, "bindaddr", "Bind Address",
+		ast_inet_ntoa(bindaddr.sin_addr));
+	res |= ast_data_node_add_child_uint(settings_node, "bindport", "Bind Port",
+		(uint32_t) ntohs(bindaddr.sin_port));
+	res |= ast_data_node_add_child_bool(settings_node, "videosupport", "Video Support",
 		ast_test_flag(&global_flags[1], SIP_PAGE2_VIDEOSUPPORT));
-	res |= ast_data_node_add_child_bool(settings_node, "textsupport",
+	res |= ast_data_node_add_child_bool(settings_node, "textsupport", "Text Support",
 		ast_test_flag(&global_flags[1], SIP_PAGE2_TEXTSUPPORT));
-	res |= ast_data_node_add_child_bool(settings_node, "autocreatepeer", autocreatepeer);
-	res |= ast_data_node_add_child_bool(settings_node, "match_auth_username", global_match_auth_username);
-	res |= ast_data_node_add_child_bool(settings_node, "allowguest", global_allowguest);
-	res |= ast_data_node_add_child_bool(settings_node, "allowsubscribe", 
+	res |= ast_data_node_add_child_bool(settings_node, "autocreatepeer", "Auto Create Peers",
+		autocreatepeer);
+	res |= ast_data_node_add_child_bool(settings_node, "match_auth_username", "Match Auth Username",
+		global_match_auth_username);
+	res |= ast_data_node_add_child_bool(settings_node, "allowguest", "Allow Unauthenticated Calls",
+		global_allowguest);
+	res |= ast_data_node_add_child_bool(settings_node, "allowsubscribe", "Allow Subscribe",
 		ast_test_flag(&global_flags[1], SIP_PAGE2_ALLOWSUBSCRIBE));
-	res |= ast_data_node_add_child_bool(settings_node, "callcounter", global_callcounter);
-	res |= ast_data_node_add_child_bool(settings_node, "allowoverlap", 
+	res |= ast_data_node_add_child_bool(settings_node, "callcounter", "Enable Call Counters",
+		global_callcounter);
+	res |= ast_data_node_add_child_bool(settings_node, "allowoverlap", "Allow Overlap Dialing",
 		ast_test_flag(&global_flags[1], SIP_PAGE2_ALLOWOVERLAP));
-	res |= ast_data_node_add_child_bool(settings_node, "promiscredir", 
+	res |= ast_data_node_add_child_bool(settings_node, "promiscredir", "Promiscuous Redirect",
 		ast_test_flag(&global_flags[0], SIP_PROMISCREDIR));
-	res |= ast_data_node_add_child_bool(settings_node, "sip_domain_support", 
+	res |= ast_data_node_add_child_bool(settings_node, "sip_domain_support", "SIP Domain Support",
 		!AST_LIST_EMPTY(&domain_list));
-	res |= ast_data_node_add_child_bool(settings_node, "allowexternaldomains", 
+	res |= ast_data_node_add_child_bool(settings_node, "allowexternaldomains", "Allow External Domains",
 		allow_external_domains);
 
 	if (res) {

Modified: team/russell/data_retrieval/include/asterisk/data.h
URL: http://svn.digium.com/view/asterisk/team/russell/data_retrieval/include/asterisk/data.h?view=diff&rev=111995&r1=111994&r2=111995
==============================================================================
--- team/russell/data_retrieval/include/asterisk/data.h (original)
+++ team/russell/data_retrieval/include/asterisk/data.h Mon Mar 31 11:32:29 2008
@@ -61,6 +61,8 @@
 
 const char *ast_data_node_get_name(const struct ast_data_node *node);
 
+const char *ast_data_node_get_friendly_name(const struct ast_data_node *node);
+
 unsigned int ast_data_node_get_bool(const struct ast_data_node *node);
 
 uint32_t ast_data_node_get_uint(const struct ast_data_node *node);
@@ -77,7 +79,7 @@
 /*! @{ Data Node Generation and Destruction */
 /*********************************************************************************************/
 
-struct ast_data_node *ast_data_node_new(const char *name);
+struct ast_data_node *ast_data_node_new(const char *name, const char *friendly_name);
 
 /*!
  * \brief Destroy a node and all of its children
@@ -97,16 +99,16 @@
 int ast_data_node_add_child(struct ast_data_node *parent, struct ast_data_node *child);
 
 struct ast_data_node *ast_data_node_add_child_grouping(struct ast_data_node *parent, 
-	const char *name);
+	const char *name, const char *friendly_name);
 
 int ast_data_node_add_child_bool(struct ast_data_node *parent, 
-	const char *name, unsigned int val);
+	const char *name, const char *friendly_name, unsigned int val);
 
 int ast_data_node_add_child_uint(struct ast_data_node *parent, 
-	const char *name, uint32_t uint);
+	const char *name, const char *friendly_name, uint32_t uint);
 
 int ast_data_node_add_child_str(struct ast_data_node *parent, 
-	const char *name, const char *str);
+	const char *name, const char *friendly_name, const char *str);
 
 /*! @} */
 

Modified: team/russell/data_retrieval/main/data.c
URL: http://svn.digium.com/view/asterisk/team/russell/data_retrieval/main/data.c?view=diff&rev=111995&r1=111994&r2=111995
==============================================================================
--- team/russell/data_retrieval/main/data.c (original)
+++ team/russell/data_retrieval/main/data.c Mon Mar 31 11:32:29 2008
@@ -49,7 +49,8 @@
 	} payload;
 	AST_LIST_HEAD_NOLOCK(, ast_data_node) children;
 	AST_LIST_ENTRY(ast_data_node) entry;
-	char name[1];
+	char *friendly_name;
+	char name[0];
 };
 
 #define NUM_DATA_PROV_BUCKETS 53
@@ -65,6 +66,11 @@
 	return node->name;
 }
 
+const char *ast_data_node_get_friendly_name(const struct ast_data_node *node)
+{
+	return S_OR(node->friendly_name, node->name);
+}
+
 enum ast_data_node_type ast_data_node_get_type(const struct ast_data_node *node)
 {
 	return node->node_type;
@@ -95,17 +101,25 @@
 	return AST_LIST_NEXT(node, entry);
 }
 
-struct ast_data_node *ast_data_node_new(const char *name)
+struct ast_data_node *ast_data_node_new(const char *name, const char *friendly_name)
 {
 	struct ast_data_node *node;
 	size_t len;
 
-	len = sizeof(*node) + strlen(name);
+	len = sizeof(*node) + strlen(name) + 1;
+	if (friendly_name) {
+		len += strlen(friendly_name) + 1;
+	}
 
 	if (!(node = ast_calloc(1, len)))
 		return NULL;
 	
 	strcpy(node->name, name);
+
+	if (friendly_name) {
+		node->friendly_name = ((char *) node) + sizeof(*node) + strlen(name) + 1;
+		strcpy(node->friendly_name, friendly_name);
+	}
 
 	return node;
 }
@@ -170,11 +184,11 @@
 }
 
 struct ast_data_node *ast_data_node_add_child_grouping(struct ast_data_node *parent, 
-	const char *name)
+	const char *name, const char *friendly_name)
 {
 	struct ast_data_node *node;
 
-	if (!(node = ast_data_node_new(name))) {
+	if (!(node = ast_data_node_new(name, friendly_name))) {
 		return NULL;
 	}
 
@@ -186,11 +200,11 @@
 }
 
 int ast_data_node_add_child_bool(struct ast_data_node *parent, 
-	const char *name, unsigned int val)
+	const char *name, const char *friendly_name, unsigned int val)
 {
 	struct ast_data_node *node;
 
-	if (!(node = ast_data_node_new(name))) {
+	if (!(node = ast_data_node_new(name, friendly_name))) {
 		return -1;
 	}
 
@@ -208,11 +222,11 @@
 }
 
 int ast_data_node_add_child_uint(struct ast_data_node *parent, 
-	const char *name, uint32_t uint)
+	const char *name, const char *friendly_name, uint32_t uint)
 {
 	struct ast_data_node *node;
 
-	if (!(node = ast_data_node_new(name))) {
+	if (!(node = ast_data_node_new(name, friendly_name))) {
 		return -1;
 	}
 
@@ -230,11 +244,11 @@
 }
 
 int ast_data_node_add_child_str(struct ast_data_node *parent, 
-	const char *name, const char *str)
+	const char *name, const char *friendly_name, const char *str)
 {
 	struct ast_data_node *node;
 
-	if (!(node = ast_data_node_new(name))) {
+	if (!(node = ast_data_node_new(name, friendly_name))) {
 		return -1;
 	}
 
@@ -364,31 +378,31 @@
 	struct ast_data_node *results, *fruit, *orange, *veggies;
 	int res = 0;
 
-	if (!(results = ast_data_node_new("test_provider"))) {
-		return NULL;
-	}
-
-	fruit = ast_data_node_add_child_grouping(results, "fruits");
-
-	res |= ast_data_node_add_child_str(fruit, "fruit", "apple");
-
-	if (!(orange = ast_data_node_add_child_grouping(fruit, "oranges"))) {
+	if (!(results = ast_data_node_new("test_provider", "Test Data Provider"))) {
+		return NULL;
+	}
+
+	fruit = ast_data_node_add_child_grouping(results, "fruits", "Fruits");
+
+	res |= ast_data_node_add_child_str(fruit, "fruit", "Fruit", "apple");
+
+	if (!(orange = ast_data_node_add_child_grouping(fruit, "oranges", "Oranges"))) {
 		results = ast_data_node_destroy(results);
 		return NULL;
 	}
 
-	res |= ast_data_node_add_child_str(orange, "orange", "mandarin");
-	res |= ast_data_node_add_child_str(orange, "orange", "navel");
-	res |= ast_data_node_add_child_str(fruit, "fruit", "banana");
-
-	if (!(veggies = ast_data_node_add_child_grouping(results, "veggies"))) {
+	res |= ast_data_node_add_child_str(orange, "orange", "Orange", "mandarin");
+	res |= ast_data_node_add_child_str(orange, "orange", "Orange", "navel");
+	res |= ast_data_node_add_child_str(fruit, "fruit", "Fruit", "banana");
+
+	if (!(veggies = ast_data_node_add_child_grouping(results, "veggies", "Vegetables"))) {
 		results = ast_data_node_destroy(results);
 		return NULL;
 	}
 
-	res |= ast_data_node_add_child_str(veggies, "veggie", "broccoli");
-	res |= ast_data_node_add_child_str(veggies, "veggie", "squash");
-	res |= ast_data_node_add_child_str(veggies, "veggie", "spinach");
+	res |= ast_data_node_add_child_str(veggies, "veggie", "Vegetable", "broccoli");
+	res |= ast_data_node_add_child_str(veggies, "veggie", "Vegetable", "squash");
+	res |= ast_data_node_add_child_str(veggies, "veggie", "Vegetable", "spinach");
 
 	if (res) {
 		results = ast_data_node_destroy(results);
@@ -417,7 +431,7 @@
 		ast_str_append(buf, 0, "> ");
 	}
 
-	ast_str_append(buf, 0, "%s: ", ast_data_node_get_name(node));
+	ast_str_append(buf, 0, "%s: ", ast_data_node_get_friendly_name(node));
 
 	node_type = ast_data_node_get_type(node);
 
@@ -503,7 +517,7 @@
 
 	provider_name = a->argv[e->args];
 
-	if (!(query = ast_data_node_new(provider_name))) {
+	if (!(query = ast_data_node_new(provider_name, NULL))) {
 		return CLI_FAILURE;
 	}
 




More information about the asterisk-commits mailing list