<p>George Joseph has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/19159">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">res_geolocation: Add profile parameter suppress_empty_ca_elements<br><br>Added profile parameter "suppress_empty_ca_elements" that<br>will cause Civic Address elements that are empty to be<br>suppressed from the outgoing PIDF-LO document.<br><br>Fixed a possible SEGV if a sub-parameter value didn't have a<br>value.<br><br>ASTERISK-30177<br><br>Change-Id: I924ccc5aa2f45110a3155b22e53dfaf3ef2092dd<br>---<br>M configs/samples/geolocation.conf.sample<br>M doc/CHANGES-staging/res_geolocation.txt<br>M include/asterisk/res_geolocation.h<br>M res/res_geolocation/eprofile_to_pidf.xslt<br>M res/res_geolocation/geoloc_config.c<br>M res/res_geolocation/geoloc_dialplan.c<br>M res/res_geolocation/geoloc_doc.xml<br>M res/res_geolocation/geoloc_eprofile.c<br>M res/res_geolocation/geoloc_private.h<br>9 files changed, 92 insertions(+), 32 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/59/19159/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/configs/samples/geolocation.conf.sample b/configs/samples/geolocation.conf.sample</span><br><span>index c5c1306..305f087 100644</span><br><span>--- a/configs/samples/geolocation.conf.sample</span><br><span>+++ b/configs/samples/geolocation.conf.sample</span><br><span>@@ -170,8 +170,9 @@</span><br><span> Defines the object type.</span><br><span> type = profile</span><br><span> </span><br><span>--- profile_precedence (optional) ------------------------------------------</span><br><span style="color: hsl(120, 100%, 40%);">+-- profile_precedence (optional) --------------------------------------</span><br><span> Sets how to reconcile incoming and configured profiles.</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> profile_precedence = < prefer_incoming | prefer_config | discard_incoming</span><br><span> | discard_config ></span><br><span> </span><br><span>@@ -202,7 +203,9 @@</span><br><span> </span><br><span> -- pidf_element (optional) --------------------------------------------</span><br><span> PIDF-LO element in which to place the location description.</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> pidf_element = < tuple | device | person ></span><br><span style="color: hsl(120, 100%, 40%);">+Default: device</span><br><span> </span><br><span> If the format is civicAddress or GML, this sets the PIDF element into</span><br><span> which the location information will be placed.</span><br><span>@@ -217,10 +220,12 @@</span><br><span> Example:</span><br><span> pidf_element = tuple</span><br><span> </span><br><span>--- allow_routing_use (optional) -------------------------------------</span><br><span style="color: hsl(120, 100%, 40%);">+-- allow_routing_use (optional) ---------------------------------------</span><br><span> Sets whether the "Geolocation-Routing" header is added to outgoing</span><br><span> requests.</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> allow_routing_use = < yes | no ></span><br><span style="color: hsl(120, 100%, 40%);">+Default: no</span><br><span> </span><br><span> Set to "yes" to indicate that servers later in the path</span><br><span> can use the location information for routing purposes. Set to "no"</span><br><span>@@ -253,7 +258,7 @@</span><br><span> Example:</span><br><span> location_info_refinement = floor=20, room=20a2</span><br><span> </span><br><span>--- location_variables -------------------------------------------------</span><br><span style="color: hsl(120, 100%, 40%);">+-- location_variables (optional) --------------------------------------</span><br><span> </span><br><span> If the referenced Location object uses any replacement variables, they</span><br><span> can be assigned here. There is no need to define variables that come</span><br><span>@@ -261,6 +266,26 @@</span><br><span> </span><br><span> location_variables = myfloor=20, myroom=222</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+-- suppress_empty_ca_elements (optional) ------------------------------</span><br><span style="color: hsl(120, 100%, 40%);">+Sets whether empty values for Civic Address elements should be</span><br><span style="color: hsl(120, 100%, 40%);">+suppressed from the outgoing PIDF-LO document.</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+suppress_empty_ca_elements = < yes | no ></span><br><span style="color: hsl(120, 100%, 40%);">+Default: no</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+Setting to "yes" allows you to define a location info template</span><br><span style="color: hsl(120, 100%, 40%);">+with channel variables that may or may not exist.</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+For example, with:</span><br><span style="color: hsl(120, 100%, 40%);">+location_info_refinement = FLR=${MyFlr}</span><br><span style="color: hsl(120, 100%, 40%);">+suppress_empty_ca_elements = no ; the default</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+If the MyFlr channel variable weren't set, the outgoing PIDF-LO document</span><br><span style="color: hsl(120, 100%, 40%);">+would have an empty <FLR/> element in it. If suppress_empty_ca_elements</span><br><span style="color: hsl(120, 100%, 40%);">+were set to "yes", the FLR element would be dropped from the PIDF-LO</span><br><span style="color: hsl(120, 100%, 40%);">+document altogether.</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> -- Profile Example ----------------------------------------------------</span><br><span> </span><br><span> [myprofile]</span><br><span>diff --git a/doc/CHANGES-staging/res_geolocation.txt b/doc/CHANGES-staging/res_geolocation.txt</span><br><span>index 298e7f8..837b09a 100644</span><br><span>--- a/doc/CHANGES-staging/res_geolocation.txt</span><br><span>+++ b/doc/CHANGES-staging/res_geolocation.txt</span><br><span>@@ -7,3 +7,7 @@</span><br><span> "<discard_incoming>"</span><br><span> The profiles are empty except for having their precedence</span><br><span> set.</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+Added profile parameter "suppress_empty_ca_elements" that</span><br><span style="color: hsl(120, 100%, 40%);">+will cause Civic Address elements that are empty to be</span><br><span style="color: hsl(120, 100%, 40%);">+suppressed from the outgoing PIDF-LO document.</span><br><span>diff --git a/include/asterisk/res_geolocation.h b/include/asterisk/res_geolocation.h</span><br><span>index 31426c0c..87f89a2 100644</span><br><span>--- a/include/asterisk/res_geolocation.h</span><br><span>+++ b/include/asterisk/res_geolocation.h</span><br><span>@@ -82,6 +82,7 @@</span><br><span> struct ast_variable *location_refinement;</span><br><span> struct ast_variable *location_variables;</span><br><span> struct ast_variable *usage_rules;</span><br><span style="color: hsl(120, 100%, 40%);">+ int suppress_empty_ca_elements;</span><br><span> };</span><br><span> </span><br><span> struct ast_geoloc_eprofile {</span><br><span>@@ -102,6 +103,7 @@</span><br><span> struct ast_variable *effective_location;</span><br><span> struct ast_variable *usage_rules;</span><br><span> struct ast_variable *confidence;</span><br><span style="color: hsl(120, 100%, 40%);">+ int suppress_empty_ca_elements;</span><br><span> };</span><br><span> </span><br><span> /*!</span><br><span>diff --git a/res/res_geolocation/eprofile_to_pidf.xslt b/res/res_geolocation/eprofile_to_pidf.xslt</span><br><span>index dec73ed..797fa66 100644</span><br><span>--- a/res/res_geolocation/eprofile_to_pidf.xslt</span><br><span>+++ b/res/res_geolocation/eprofile_to_pidf.xslt</span><br><span>@@ -13,6 +13,7 @@</span><br><span> </span><br><span> <xsl:output method="xml" indent="yes"/></span><br><span> <xsl:strip-space elements="*"/></span><br><span style="color: hsl(120, 100%, 40%);">+ <xsl:param name="suppress_empty_ca_elements" select="false()"/></span><br><span> </span><br><span> <!-- REMINDER: The "match" and "select" xpaths refer to the input document,</span><br><span> not the output document --></span><br><span>@@ -80,9 +81,11 @@</span><br><span> each element, adding the "ca" namespace --></span><br><span> </span><br><span> <xsl:template match="civicAddress/*"></span><br><span style="color: hsl(0, 100%, 40%);">- <xsl:element name="ca:{name()}"></span><br><span style="color: hsl(0, 100%, 40%);">- <xsl:value-of select="."/></span><br><span style="color: hsl(0, 100%, 40%);">- </xsl:element></span><br><span style="color: hsl(120, 100%, 40%);">+ <xsl:if test="not($suppress_empty_ca_elements) or boolean(node())"></span><br><span style="color: hsl(120, 100%, 40%);">+ <xsl:element name="ca:{name()}"></span><br><span style="color: hsl(120, 100%, 40%);">+ <xsl:value-of select="."/></span><br><span style="color: hsl(120, 100%, 40%);">+ </xsl:element></span><br><span style="color: hsl(120, 100%, 40%);">+ </xsl:if></span><br><span> </xsl:template></span><br><span> </span><br><span> <xsl:template match="location-info/civicAddress"></span><br><span>diff --git a/res/res_geolocation/geoloc_config.c b/res/res_geolocation/geoloc_config.c</span><br><span>index 5916697..ee542f0 100644</span><br><span>--- a/res/res_geolocation/geoloc_config.c</span><br><span>+++ b/res/res_geolocation/geoloc_config.c</span><br><span>@@ -445,7 +445,6 @@</span><br><span> </span><br><span> iter = ao2_iterator_init(sorted_container, AO2_ITERATOR_UNLINK);</span><br><span> for (; (profile = ao2_iterator_next(&iter)); ) {</span><br><span style="color: hsl(0, 100%, 40%);">- char *action = NULL;</span><br><span> struct ast_str *loc_str = NULL;</span><br><span> struct ast_str *refinement_str = NULL;</span><br><span> struct ast_str *variables_str = NULL;</span><br><span>@@ -463,24 +462,23 @@</span><br><span> variables_str = ast_variable_list_join(eprofile->location_variables, ",", "=", "\"", NULL);</span><br><span> usage_rules_str = ast_variable_list_join(eprofile->usage_rules, ",", "=", "\"", NULL);</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- precedence_to_str(eprofile, NULL, &action);</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span> ast_cli(a->fd,</span><br><span style="color: hsl(0, 100%, 40%);">- "id: %-s\n"</span><br><span style="color: hsl(0, 100%, 40%);">- "profile_disposition: %-s\n"</span><br><span style="color: hsl(0, 100%, 40%);">- "pidf_element: %-s\n"</span><br><span style="color: hsl(0, 100%, 40%);">- "location_reference: %-s\n"</span><br><span style="color: hsl(0, 100%, 40%);">- "Location_format: %-s\n"</span><br><span style="color: hsl(0, 100%, 40%);">- "location_details: %-s\n"</span><br><span style="color: hsl(0, 100%, 40%);">- "location_method: %-s\n"</span><br><span style="color: hsl(0, 100%, 40%);">- "location_refinement: %-s\n"</span><br><span style="color: hsl(0, 100%, 40%);">- "location_variables: %-s\n"</span><br><span style="color: hsl(0, 100%, 40%);">- "allow_routing_use: %-s\n"</span><br><span style="color: hsl(0, 100%, 40%);">- "effective_location: %-s\n"</span><br><span style="color: hsl(0, 100%, 40%);">- "usage_rules: %-s\n"</span><br><span style="color: hsl(0, 100%, 40%);">- "notes: %-s\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ "id: %-s\n"</span><br><span style="color: hsl(120, 100%, 40%);">+ "profile_precedence: %-s\n"</span><br><span style="color: hsl(120, 100%, 40%);">+ "pidf_element: %-s\n"</span><br><span style="color: hsl(120, 100%, 40%);">+ "location_reference: %-s\n"</span><br><span style="color: hsl(120, 100%, 40%);">+ "Location_format: %-s\n"</span><br><span style="color: hsl(120, 100%, 40%);">+ "location_details: %-s\n"</span><br><span style="color: hsl(120, 100%, 40%);">+ "location_method: %-s\n"</span><br><span style="color: hsl(120, 100%, 40%);">+ "location_refinement: %-s\n"</span><br><span style="color: hsl(120, 100%, 40%);">+ "location_variables: %-s\n"</span><br><span style="color: hsl(120, 100%, 40%);">+ "allow_routing_use: %-s\n"</span><br><span style="color: hsl(120, 100%, 40%);">+ "suppress_empty_elements: %-s\n"</span><br><span style="color: hsl(120, 100%, 40%);">+ "effective_location: %-s\n"</span><br><span style="color: hsl(120, 100%, 40%);">+ "usage_rules: %-s\n"</span><br><span style="color: hsl(120, 100%, 40%);">+ "notes: %-s\n",</span><br><span> eprofile->id,</span><br><span style="color: hsl(0, 100%, 40%);">- action,</span><br><span style="color: hsl(120, 100%, 40%);">+ precedence_names[eprofile->precedence],</span><br><span> pidf_element_names[eprofile->pidf_element],</span><br><span> S_OR(eprofile->location_reference, "<none>"),</span><br><span> format_names[eprofile->format],</span><br><span>@@ -488,14 +486,14 @@</span><br><span> S_OR(eprofile->method, "<none>"),</span><br><span> S_COR(refinement_str, ast_str_buffer(refinement_str), "<none>"),</span><br><span> S_COR(variables_str, ast_str_buffer(variables_str), "<none>"),</span><br><span style="color: hsl(0, 100%, 40%);">- S_COR(eprofile->precedence, "yes", "no"),</span><br><span style="color: hsl(120, 100%, 40%);">+ S_COR(eprofile->allow_routing_use, "yes", "no"),</span><br><span style="color: hsl(120, 100%, 40%);">+ S_COR(eprofile->suppress_empty_ca_elements, "yes", "no"),</span><br><span> S_COR(resolved_str, ast_str_buffer(resolved_str), "<none>"),</span><br><span> S_COR(usage_rules_str, ast_str_buffer(usage_rules_str), "<none>"),</span><br><span> S_OR(eprofile->notes, "<none>")</span><br><span> );</span><br><span> ao2_ref(eprofile, -1);</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- ast_free(action);</span><br><span> ast_free(loc_str);</span><br><span> ast_free(refinement_str);</span><br><span> ast_free(variables_str);</span><br><span>@@ -695,6 +693,8 @@</span><br><span> 0, STRFLDSET(struct ast_geoloc_profile, notes));</span><br><span> ast_sorcery_object_field_register(geoloc_sorcery, "profile", "allow_routing_use",</span><br><span> "no", OPT_BOOL_T, 1, FLDSET(struct ast_geoloc_profile, allow_routing_use));</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_sorcery_object_field_register(geoloc_sorcery, "profile", "suppress_empty_ca_elements",</span><br><span style="color: hsl(120, 100%, 40%);">+ "no", OPT_BOOL_T, 1, FLDSET(struct ast_geoloc_profile, suppress_empty_ca_elements));</span><br><span> </span><br><span> </span><br><span> ast_sorcery_load(geoloc_sorcery);</span><br><span>diff --git a/res/res_geolocation/geoloc_dialplan.c b/res/res_geolocation/geoloc_dialplan.c</span><br><span>index c75189f..710daa6 100644</span><br><span>--- a/res/res_geolocation/geoloc_dialplan.c</span><br><span>+++ b/res/res_geolocation/geoloc_dialplan.c</span><br><span>@@ -88,6 +88,8 @@</span><br><span> ast_str_append(buf, len, "%s", eprofile->method);</span><br><span> } else if (ast_strings_equal(args.field, "allow_routing_use")) {</span><br><span> ast_str_append(buf, len, "%s", eprofile->allow_routing_use ? "yes" : "no");</span><br><span style="color: hsl(120, 100%, 40%);">+ } else if (ast_strings_equal(args.field, "suppress_empty_ca_elements")) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_str_append(buf, len, "%s", eprofile->suppress_empty_ca_elements ? "yes" : "no");</span><br><span> } else if (ast_strings_equal(args.field, "profile_precedence")) {</span><br><span> ast_str_append(buf, len, "%s", ast_geoloc_precedence_to_name(eprofile->precedence));</span><br><span> } else if (ast_strings_equal(args.field, "format")) {</span><br><span>@@ -212,19 +214,16 @@</span><br><span> ast_string_field_set(eprofile, location_reference, value);</span><br><span> } else if (ast_strings_equal(args.field, "method")) {</span><br><span> ast_string_field_set(eprofile, method, value);</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span> } else if (ast_strings_equal(args.field, "allow_routing_use")) {</span><br><span> eprofile->allow_routing_use = ast_true(value);</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(120, 100%, 40%);">+ } else if (ast_strings_equal(args.field, "suppress_empty_ca_elements")) {</span><br><span style="color: hsl(120, 100%, 40%);">+ eprofile->suppress_empty_ca_elements = ast_true(value);</span><br><span> } else if (ast_strings_equal(args.field, "profile_precedence")) {</span><br><span> TEST_ENUM_VALUE(chan_name, eprofile, precedence, value);</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span> } else if (ast_strings_equal(args.field, "format")) {</span><br><span> TEST_ENUM_VALUE(chan_name, eprofile, format, value);</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span> } else if (ast_strings_equal(args.field, "pidf_element")) {</span><br><span> TEST_ENUM_VALUE(chan_name, eprofile, pidf_element, value);</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span> } else if (ast_strings_equal(args.field, "location_info")) {</span><br><span> TEST_VARLIST(chan_name, eprofile, location_info, value);</span><br><span> } else if (ast_strings_equal(args.field, "location_source")) {</span><br><span>diff --git a/res/res_geolocation/geoloc_doc.xml b/res/res_geolocation/geoloc_doc.xml</span><br><span>index 2e28f7e..0e1b31d 100644</span><br><span>--- a/res/res_geolocation/geoloc_doc.xml</span><br><span>+++ b/res/res_geolocation/geoloc_doc.xml</span><br><span>@@ -175,6 +175,10 @@</span><br><span> <configOption name="allow_routing_use"></span><br><span> <synopsis>Sets the value of the Geolocation-Routing header.</synopsis></span><br><span> </configOption></span><br><span style="color: hsl(120, 100%, 40%);">+ <configOption name="suppress_empty_ca_elements"></span><br><span style="color: hsl(120, 100%, 40%);">+ <synopsis>Sets if empty Civic Address elements should be suppressed</span><br><span style="color: hsl(120, 100%, 40%);">+ from the PIDF-LO document.</synopsis></span><br><span style="color: hsl(120, 100%, 40%);">+ </configOption></span><br><span> </span><br><span> <configOption name="profile_precedence" default="discard_incoming"></span><br><span> <synopsis>Determine which profile on a channel should be used</synopsis></span><br><span>diff --git a/res/res_geolocation/geoloc_eprofile.c b/res/res_geolocation/geoloc_eprofile.c</span><br><span>index bfba2d2..5f20612 100644</span><br><span>--- a/res/res_geolocation/geoloc_eprofile.c</span><br><span>+++ b/res/res_geolocation/geoloc_eprofile.c</span><br><span>@@ -176,6 +176,7 @@</span><br><span> ao2_lock(profile);</span><br><span> eprofile->allow_routing_use = profile->allow_routing_use;</span><br><span> eprofile->pidf_element = profile->pidf_element;</span><br><span style="color: hsl(120, 100%, 40%);">+ eprofile->suppress_empty_ca_elements = profile->suppress_empty_ca_elements;</span><br><span> </span><br><span> rc = ast_string_field_set(eprofile, location_reference, profile->location_reference);</span><br><span> if (rc == 0) {</span><br><span>@@ -988,6 +989,7 @@</span><br><span> struct ast_xml_node *temp_node = NULL;</span><br><span> const char *entity = NULL;</span><br><span> int has_no_entity = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+ const char *params[] = { "suppress_empty_ca_elements", "false()", NULL };</span><br><span> </span><br><span> SCOPE_ENTER(3, "%s\n", ref_string);</span><br><span> </span><br><span>@@ -1038,7 +1040,10 @@</span><br><span> doc_len = 0;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- pidf_doc = ast_xslt_apply(eprofile_to_pidf_xslt, intermediate, NULL);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (eprofile->suppress_empty_ca_elements) {</span><br><span style="color: hsl(120, 100%, 40%);">+ params[1] = "true()";</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ pidf_doc = ast_xslt_apply(eprofile_to_pidf_xslt, intermediate, params);</span><br><span> if (!pidf_doc) {</span><br><span> SCOPE_EXIT_LOG_RTN_VALUE(NULL, LOG_ERROR, "%s: Unable to create final PIDF-LO doc from intermediate doc\n",</span><br><span> ref_string);</span><br><span>diff --git a/res/res_geolocation/geoloc_private.h b/res/res_geolocation/geoloc_private.h</span><br><span>index 6b9a63e..ff5e2af 100644</span><br><span>--- a/res/res_geolocation/geoloc_private.h</span><br><span>+++ b/res/res_geolocation/geoloc_private.h</span><br><span>@@ -90,7 +90,7 @@</span><br><span> while ((item = ast_strsep(&item_string, ',', AST_STRSEP_ALL))) { \</span><br><span> item_name = ast_strsep(&item, '=', AST_STRSEP_ALL); \</span><br><span> item_value = ast_strsep(&item, '=', AST_STRSEP_ALL); \</span><br><span style="color: hsl(0, 100%, 40%);">- new_var = ast_variable_new(item_name, item_value, ""); \</span><br><span style="color: hsl(120, 100%, 40%);">+ new_var = ast_variable_new(item_name, S_OR(item_value, ""), ""); \</span><br><span> if (!new_var) { \</span><br><span> rc = -1; \</span><br><span> break; \</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/19159">change 19159</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/+/19159"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 18 </div>
<div style="display:none"> Gerrit-Change-Id: I924ccc5aa2f45110a3155b22e53dfaf3ef2092dd </div>
<div style="display:none"> Gerrit-Change-Number: 19159 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>