<p>Sean Bright has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/16433">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">config_options: Handle ACO arrays correctly in generated XML docs.<br><br>There are 3 separate changes here but they are all closely related:<br><br>* Only try to set matchfield attributes on 'field' nodes<br><br>* We need to adjust how we treat the category pointer based on the<br> value of the category_match, to avoid memory corruption. We now<br> generate a regex-like string when match types other than<br> ACO_WHITELIST and ACO_BLACKLIST are used.<br><br>* Switch app_agent_pool from ACO_BLACKLIST_ARRAY to<br> ACO_BLACKLIST_EXACT since we only have one category we need to<br> ignore, not two.<br><br>ASTERISK-29614 #close<br><br>Change-Id: I7be7bdb1bb9814f942bc6bb4fdd0a55a7b7efe1e<br>---<br>M apps/app_agent_pool.c<br>M main/config_options.c<br>2 files changed, 55 insertions(+), 15 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/33/16433/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/apps/app_agent_pool.c b/apps/app_agent_pool.c</span><br><span>index e78953f..bb28899 100644</span><br><span>--- a/apps/app_agent_pool.c</span><br><span>+++ b/apps/app_agent_pool.c</span><br><span>@@ -456,17 +456,11 @@</span><br><span> struct ao2_container *agents;</span><br><span> };</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-static const char *agent_type_blacklist[] = {</span><br><span style="color: hsl(0, 100%, 40%);">- "general",</span><br><span style="color: hsl(0, 100%, 40%);">- "agents",</span><br><span style="color: hsl(0, 100%, 40%);">- NULL,</span><br><span style="color: hsl(0, 100%, 40%);">-};</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span> static struct aco_type agent_type = {</span><br><span> .type = ACO_ITEM,</span><br><span> .name = "agent-id",</span><br><span style="color: hsl(0, 100%, 40%);">- .category_match = ACO_BLACKLIST_ARRAY,</span><br><span style="color: hsl(0, 100%, 40%);">- .category = (const char *)agent_type_blacklist,</span><br><span style="color: hsl(120, 100%, 40%);">+ .category_match = ACO_BLACKLIST_EXACT,</span><br><span style="color: hsl(120, 100%, 40%);">+ .category = "general",</span><br><span> .item_alloc = agent_cfg_alloc,</span><br><span> .item_find = agent_cfg_find,</span><br><span> .item_offset = offsetof(struct agents_cfg, agents),</span><br><span>diff --git a/main/config_options.c b/main/config_options.c</span><br><span>index cbd7622..c59a8b5 100644</span><br><span>--- a/main/config_options.c</span><br><span>+++ b/main/config_options.c</span><br><span>@@ -1037,6 +1037,45 @@</span><br><span> return NULL;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+/*! \internal</span><br><span style="color: hsl(120, 100%, 40%);">+ * \brief Generate a category match string suitable for display in 'config show help'</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+static struct ast_str *derive_category_text(enum aco_category_op category_match, const char *category)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_str *s = ast_str_create(128);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!s) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ switch (category_match) {</span><br><span style="color: hsl(120, 100%, 40%);">+ case ACO_WHITELIST_ARRAY:</span><br><span style="color: hsl(120, 100%, 40%);">+ case ACO_BLACKLIST_ARRAY: {</span><br><span style="color: hsl(120, 100%, 40%);">+ size_t i;</span><br><span style="color: hsl(120, 100%, 40%);">+ const char **matches = (const char **) category;</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_str_append(&s, 0, "^(");</span><br><span style="color: hsl(120, 100%, 40%);">+ for (i = 0; matches[i]; i++) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_str_append(&s, 0, "%s%s",</span><br><span style="color: hsl(120, 100%, 40%);">+ i ? "|" : "",</span><br><span style="color: hsl(120, 100%, 40%);">+ matches[i]);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_str_append(&s, 0, ")$");</span><br><span style="color: hsl(120, 100%, 40%);">+ break;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ case ACO_WHITELIST_EXACT:</span><br><span style="color: hsl(120, 100%, 40%);">+ case ACO_BLACKLIST_EXACT:</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_str_set(&s, 0, "^%s$", category);</span><br><span style="color: hsl(120, 100%, 40%);">+ break;</span><br><span style="color: hsl(120, 100%, 40%);">+ case ACO_WHITELIST:</span><br><span style="color: hsl(120, 100%, 40%);">+ case ACO_BLACKLIST:</span><br><span style="color: hsl(120, 100%, 40%);">+ default:</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_str_set(&s, 0, "%s", category);</span><br><span style="color: hsl(120, 100%, 40%);">+ break;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ return s;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> /* Define as 0 if we want to allow configurations to be registered without</span><br><span> * documentation</span><br><span> */</span><br><span>@@ -1051,6 +1090,7 @@</span><br><span> RAII_VAR(struct ast_xml_doc_item *, config_info, ao2_find(xmldocs, module, OBJ_KEY), ao2_cleanup);</span><br><span> struct ast_xml_doc_item *config_type;</span><br><span> struct ast_xml_node *type, *syntax, *matchinfo, *tmp;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_str *derived_category = NULL;</span><br><span> </span><br><span> /* If we already have a syntax element, bail. This isn't an error, since we may unload a module which</span><br><span> * has updated the docs and then load it again. */</span><br><span>@@ -1083,7 +1123,12 @@</span><br><span> return XMLDOC_STRICT ? -1 : 0;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- ast_xml_set_text(tmp, category);</span><br><span style="color: hsl(120, 100%, 40%);">+ derived_category = derive_category_text(category_match, category);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (derived_category) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_xml_set_text(tmp, ast_str_buffer(derived_category));</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_free(derived_category);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> switch (category_match) {</span><br><span> case ACO_WHITELIST:</span><br><span> case ACO_WHITELIST_EXACT:</span><br><span>@@ -1097,14 +1142,15 @@</span><br><span> break;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- if (!ast_strlen_zero(matchfield) && !(tmp = ast_xml_new_child(matchinfo, "field"))) {</span><br><span style="color: hsl(0, 100%, 40%);">- ast_log(LOG_WARNING, "Could not add %s attribute for type '%s' in module '%s'\n", matchfield, name, module);</span><br><span style="color: hsl(0, 100%, 40%);">- return XMLDOC_STRICT ? -1 : 0;</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!ast_strlen_zero(matchfield)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!(tmp = ast_xml_new_child(matchinfo, "field"))) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(LOG_WARNING, "Could not add %s attribute for type '%s' in module '%s'\n", matchfield, name, module);</span><br><span style="color: hsl(120, 100%, 40%);">+ return XMLDOC_STRICT ? -1 : 0;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_xml_set_attribute(tmp, "name", matchfield);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_xml_set_text(tmp, matchvalue);</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- ast_xml_set_attribute(tmp, "name", matchfield);</span><br><span style="color: hsl(0, 100%, 40%);">- ast_xml_set_text(tmp, matchvalue);</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span> if (!config_info || !(config_type = find_xmldoc_type(config_info, name))) {</span><br><span> ast_log(LOG_WARNING, "Could not obtain XML documentation item for config type %s\n", name);</span><br><span> return XMLDOC_STRICT ? -1 : 0;</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/16433">change 16433</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/c/asterisk/+/16433"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 16 </div>
<div style="display:none"> Gerrit-Change-Id: I7be7bdb1bb9814f942bc6bb4fdd0a55a7b7efe1e </div>
<div style="display:none"> Gerrit-Change-Number: 16433 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Sean Bright <sean@seanbright.com> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>