diff --git a/configs/samples/geolocation.conf.sample b/configs/samples/geolocation.conf.sample index c5c1306efb..305f087fb2 100644 --- a/configs/samples/geolocation.conf.sample +++ b/configs/samples/geolocation.conf.sample @@ -170,8 +170,9 @@ location_source = sip1.myserver.net Defines the object type. type = profile --- profile_precedence (optional) ------------------------------------------ +-- profile_precedence (optional) -------------------------------------- Sets how to reconcile incoming and configured profiles. + profile_precedence = < prefer_incoming | prefer_config | discard_incoming | discard_config > @@ -202,7 +203,9 @@ profile_precedence = prefer_config -- pidf_element (optional) -------------------------------------------- PIDF-LO element in which to place the location description. + pidf_element = < tuple | device | person > +Default: device If the format is civicAddress or GML, this sets the PIDF element into which the location information will be placed. @@ -217,10 +220,12 @@ Per [RFC5491], "device" is preferred and therefore the default. Example: pidf_element = tuple --- allow_routing_use (optional) ------------------------------------- +-- allow_routing_use (optional) --------------------------------------- Sets whether the "Geolocation-Routing" header is added to outgoing requests. + allow_routing_use = < yes | no > +Default: no Set to "yes" to indicate that servers later in the path can use the location information for routing purposes. Set to "no" @@ -253,7 +258,7 @@ floor and room just for this profile Example: location_info_refinement = floor=20, room=20a2 --- location_variables ------------------------------------------------- +-- location_variables (optional) -------------------------------------- If the referenced Location object uses any replacement variables, they can be assigned here. There is no need to define variables that come @@ -261,6 +266,26 @@ from the channel using this profile. They get assigned automatically. location_variables = myfloor=20, myroom=222 +-- suppress_empty_ca_elements (optional) ------------------------------ +Sets whether empty values for Civic Address elements should be +suppressed from the outgoing PIDF-LO document. + +suppress_empty_ca_elements = < yes | no > +Default: no + +Setting to "yes" allows you to define a location info template +with channel variables that may or may not exist. + +For example, with: +location_info_refinement = FLR=${MyFlr} +suppress_empty_ca_elements = no ; the default + +If the MyFlr channel variable weren't set, the outgoing PIDF-LO document +would have an empty element in it. If suppress_empty_ca_elements +were set to "yes", the FLR element would be dropped from the PIDF-LO +document altogether. + + -- Profile Example ---------------------------------------------------- [myprofile] diff --git a/doc/CHANGES-staging/res_geolocation.txt b/doc/CHANGES-staging/res_geolocation.txt index 641ce5b41d..ddf855b22a 100644 --- a/doc/CHANGES-staging/res_geolocation.txt +++ b/doc/CHANGES-staging/res_geolocation.txt @@ -30,3 +30,6 @@ Added 4 built-in profiles: The profiles are empty except for having their precedence set. +Added profile parameter "suppress_empty_ca_elements" that +will cause Civic Address elements that are empty to be +suppressed from the outgoing PIDF-LO document. diff --git a/include/asterisk/res_geolocation.h b/include/asterisk/res_geolocation.h index 31426c0cfb..87f89a2cdd 100644 --- a/include/asterisk/res_geolocation.h +++ b/include/asterisk/res_geolocation.h @@ -82,6 +82,7 @@ struct ast_geoloc_profile { struct ast_variable *location_refinement; struct ast_variable *location_variables; struct ast_variable *usage_rules; + int suppress_empty_ca_elements; }; struct ast_geoloc_eprofile { @@ -102,6 +103,7 @@ struct ast_geoloc_eprofile { struct ast_variable *effective_location; struct ast_variable *usage_rules; struct ast_variable *confidence; + int suppress_empty_ca_elements; }; /*! diff --git a/res/res_geolocation/eprofile_to_pidf.xslt b/res/res_geolocation/eprofile_to_pidf.xslt index dec73edd9e..797fa66cdf 100644 --- a/res/res_geolocation/eprofile_to_pidf.xslt +++ b/res/res_geolocation/eprofile_to_pidf.xslt @@ -13,6 +13,7 @@ + @@ -80,9 +81,11 @@ each element, adding the "ca" namespace --> - - - + + + + + diff --git a/res/res_geolocation/geoloc_config.c b/res/res_geolocation/geoloc_config.c index 5916697215..ee542f046b 100644 --- a/res/res_geolocation/geoloc_config.c +++ b/res/res_geolocation/geoloc_config.c @@ -445,7 +445,6 @@ static char *geoloc_config_show_profiles(struct ast_cli_entry *e, int cmd, struc iter = ao2_iterator_init(sorted_container, AO2_ITERATOR_UNLINK); for (; (profile = ao2_iterator_next(&iter)); ) { - char *action = NULL; struct ast_str *loc_str = NULL; struct ast_str *refinement_str = NULL; struct ast_str *variables_str = NULL; @@ -463,24 +462,23 @@ static char *geoloc_config_show_profiles(struct ast_cli_entry *e, int cmd, struc variables_str = ast_variable_list_join(eprofile->location_variables, ",", "=", "\"", NULL); usage_rules_str = ast_variable_list_join(eprofile->usage_rules, ",", "=", "\"", NULL); - precedence_to_str(eprofile, NULL, &action); - ast_cli(a->fd, - "id: %-s\n" - "profile_disposition: %-s\n" - "pidf_element: %-s\n" - "location_reference: %-s\n" - "Location_format: %-s\n" - "location_details: %-s\n" - "location_method: %-s\n" - "location_refinement: %-s\n" - "location_variables: %-s\n" - "allow_routing_use: %-s\n" - "effective_location: %-s\n" - "usage_rules: %-s\n" - "notes: %-s\n", + "id: %-s\n" + "profile_precedence: %-s\n" + "pidf_element: %-s\n" + "location_reference: %-s\n" + "Location_format: %-s\n" + "location_details: %-s\n" + "location_method: %-s\n" + "location_refinement: %-s\n" + "location_variables: %-s\n" + "allow_routing_use: %-s\n" + "suppress_empty_elements: %-s\n" + "effective_location: %-s\n" + "usage_rules: %-s\n" + "notes: %-s\n", eprofile->id, - action, + precedence_names[eprofile->precedence], pidf_element_names[eprofile->pidf_element], S_OR(eprofile->location_reference, ""), format_names[eprofile->format], @@ -488,14 +486,14 @@ static char *geoloc_config_show_profiles(struct ast_cli_entry *e, int cmd, struc S_OR(eprofile->method, ""), S_COR(refinement_str, ast_str_buffer(refinement_str), ""), S_COR(variables_str, ast_str_buffer(variables_str), ""), - S_COR(eprofile->precedence, "yes", "no"), + S_COR(eprofile->allow_routing_use, "yes", "no"), + S_COR(eprofile->suppress_empty_ca_elements, "yes", "no"), S_COR(resolved_str, ast_str_buffer(resolved_str), ""), S_COR(usage_rules_str, ast_str_buffer(usage_rules_str), ""), S_OR(eprofile->notes, "") ); ao2_ref(eprofile, -1); - ast_free(action); ast_free(loc_str); ast_free(refinement_str); ast_free(variables_str); @@ -695,6 +693,8 @@ int geoloc_config_load(void) 0, STRFLDSET(struct ast_geoloc_profile, notes)); ast_sorcery_object_field_register(geoloc_sorcery, "profile", "allow_routing_use", "no", OPT_BOOL_T, 1, FLDSET(struct ast_geoloc_profile, allow_routing_use)); + ast_sorcery_object_field_register(geoloc_sorcery, "profile", "suppress_empty_ca_elements", + "no", OPT_BOOL_T, 1, FLDSET(struct ast_geoloc_profile, suppress_empty_ca_elements)); ast_sorcery_load(geoloc_sorcery); diff --git a/res/res_geolocation/geoloc_dialplan.c b/res/res_geolocation/geoloc_dialplan.c index c75189fa17..710daa65a2 100644 --- a/res/res_geolocation/geoloc_dialplan.c +++ b/res/res_geolocation/geoloc_dialplan.c @@ -88,6 +88,8 @@ static int geoloc_profile_read(struct ast_channel *chan, ast_str_append(buf, len, "%s", eprofile->method); } else if (ast_strings_equal(args.field, "allow_routing_use")) { ast_str_append(buf, len, "%s", eprofile->allow_routing_use ? "yes" : "no"); + } else if (ast_strings_equal(args.field, "suppress_empty_ca_elements")) { + ast_str_append(buf, len, "%s", eprofile->suppress_empty_ca_elements ? "yes" : "no"); } else if (ast_strings_equal(args.field, "profile_precedence")) { ast_str_append(buf, len, "%s", ast_geoloc_precedence_to_name(eprofile->precedence)); } else if (ast_strings_equal(args.field, "format")) { @@ -212,19 +214,16 @@ static int geoloc_profile_write(struct ast_channel *chan, const char *cmd, char ast_string_field_set(eprofile, location_reference, value); } else if (ast_strings_equal(args.field, "method")) { ast_string_field_set(eprofile, method, value); - } else if (ast_strings_equal(args.field, "allow_routing_use")) { eprofile->allow_routing_use = ast_true(value); - + } else if (ast_strings_equal(args.field, "suppress_empty_ca_elements")) { + eprofile->suppress_empty_ca_elements = ast_true(value); } else if (ast_strings_equal(args.field, "profile_precedence")) { TEST_ENUM_VALUE(chan_name, eprofile, precedence, value); - } else if (ast_strings_equal(args.field, "format")) { TEST_ENUM_VALUE(chan_name, eprofile, format, value); - } else if (ast_strings_equal(args.field, "pidf_element")) { TEST_ENUM_VALUE(chan_name, eprofile, pidf_element, value); - } else if (ast_strings_equal(args.field, "location_info")) { TEST_VARLIST(chan_name, eprofile, location_info, value); } else if (ast_strings_equal(args.field, "location_source")) { diff --git a/res/res_geolocation/geoloc_doc.xml b/res/res_geolocation/geoloc_doc.xml index 2e28f7e144..0e1b31dbfc 100644 --- a/res/res_geolocation/geoloc_doc.xml +++ b/res/res_geolocation/geoloc_doc.xml @@ -175,6 +175,10 @@ Sets the value of the Geolocation-Routing header. + + Sets if empty Civic Address elements should be suppressed + from the PIDF-LO document. + Determine which profile on a channel should be used diff --git a/res/res_geolocation/geoloc_eprofile.c b/res/res_geolocation/geoloc_eprofile.c index bfba2d2168..5f20612cde 100644 --- a/res/res_geolocation/geoloc_eprofile.c +++ b/res/res_geolocation/geoloc_eprofile.c @@ -176,6 +176,7 @@ struct ast_geoloc_eprofile *ast_geoloc_eprofile_create_from_profile(struct ast_g ao2_lock(profile); eprofile->allow_routing_use = profile->allow_routing_use; eprofile->pidf_element = profile->pidf_element; + eprofile->suppress_empty_ca_elements = profile->suppress_empty_ca_elements; rc = ast_string_field_set(eprofile, location_reference, profile->location_reference); if (rc == 0) { @@ -988,6 +989,7 @@ const char *ast_geoloc_eprofile_to_pidf(struct ast_geoloc_eprofile *eprofile, struct ast_xml_node *temp_node = NULL; const char *entity = NULL; int has_no_entity = 0; + const char *params[] = { "suppress_empty_ca_elements", "false()", NULL }; SCOPE_ENTER(3, "%s\n", ref_string); @@ -1038,7 +1040,10 @@ const char *ast_geoloc_eprofile_to_pidf(struct ast_geoloc_eprofile *eprofile, doc_len = 0; } - pidf_doc = ast_xslt_apply(eprofile_to_pidf_xslt, intermediate, NULL); + if (eprofile->suppress_empty_ca_elements) { + params[1] = "true()"; + } + pidf_doc = ast_xslt_apply(eprofile_to_pidf_xslt, intermediate, params); if (!pidf_doc) { SCOPE_EXIT_LOG_RTN_VALUE(NULL, LOG_ERROR, "%s: Unable to create final PIDF-LO doc from intermediate doc\n", ref_string); diff --git a/res/res_geolocation/geoloc_private.h b/res/res_geolocation/geoloc_private.h index 6b9a63e338..ff5e2af99f 100644 --- a/res/res_geolocation/geoloc_private.h +++ b/res/res_geolocation/geoloc_private.h @@ -90,7 +90,7 @@ static int _stem ## _handler(const struct aco_option *opt, struct ast_variable * while ((item = ast_strsep(&item_string, ',', AST_STRSEP_ALL))) { \ item_name = ast_strsep(&item, '=', AST_STRSEP_ALL); \ item_value = ast_strsep(&item, '=', AST_STRSEP_ALL); \ - new_var = ast_variable_new(item_name, item_value, ""); \ + new_var = ast_variable_new(item_name, S_OR(item_value, ""), ""); \ if (!new_var) { \ rc = -1; \ break; \