<p>George Joseph has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/19158">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">res_geolocation: Add built-in profiles<br><br>The trigger to perform outgoing geolocation processing is the<br>presence of a geoloc_outgoing_call_profile on an endpoint. This<br>is intentional so as to not leak location information to<br>destinations that shouldn't receive it. In a totally dynamic<br>configuration scenario however, there may not be any profiles<br>defined in geolocation.conf. This makes it impossible to do<br>outgoing processing without defining a "dummy" profile in the<br>config file.<br><br>This commit adds 4 built-in profiles:<br> "<prefer_config>"<br> "<discard_config>"<br> "<prefer_incoming>"<br> "<discard_incoming>"<br>The profiles are empty except for having their precedence<br>set and can be set on an endpoint to allow processing without<br>entries in geolocation.conf. "<discard_config>" is actually the<br>best one to use in this situation.<br><br>ASTERISK-30182<br><br>Change-Id: I1819ccfa404ce59802a3a07ad1cabed60fb9480a<br>---<br>M configs/samples/geolocation.conf.sample<br>A doc/CHANGES-staging/res_geolocation.txt<br>M res/res_geolocation/geoloc_config.c<br>3 files changed, 126 insertions(+), 9 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/58/19158/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 8c44edb..c5c1306 100644</span><br><span>--- a/configs/samples/geolocation.conf.sample</span><br><span>+++ b/configs/samples/geolocation.conf.sample</span><br><span>@@ -272,3 +272,13 @@</span><br><span> </span><br><span> =======================================================================</span><br><span> --;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+-- NOTE ---------------------------------------------------------------</span><br><span style="color: hsl(120, 100%, 40%);">+There are 4 built-in profiles that can be assigned to endpoints:</span><br><span style="color: hsl(120, 100%, 40%);">+ "<prefer_config>"</span><br><span style="color: hsl(120, 100%, 40%);">+ "<discard_config>"</span><br><span style="color: hsl(120, 100%, 40%);">+ "<prefer_incoming>"</span><br><span style="color: hsl(120, 100%, 40%);">+ "<discard_incoming>"</span><br><span style="color: hsl(120, 100%, 40%);">+The profiles are empty except for having their precedence</span><br><span style="color: hsl(120, 100%, 40%);">+set.</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span>diff --git a/doc/CHANGES-staging/res_geolocation.txt b/doc/CHANGES-staging/res_geolocation.txt</span><br><span>new file mode 100644</span><br><span>index 0000000..298e7f8</span><br><span>--- /dev/null</span><br><span>+++ b/doc/CHANGES-staging/res_geolocation.txt</span><br><span>@@ -0,0 +1,9 @@</span><br><span style="color: hsl(120, 100%, 40%);">+Subject: res_geolocation</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+Added 4 built-in profiles:</span><br><span style="color: hsl(120, 100%, 40%);">+ "<prefer_config>"</span><br><span style="color: hsl(120, 100%, 40%);">+ "<discard_config>"</span><br><span style="color: hsl(120, 100%, 40%);">+ "<prefer_incoming>"</span><br><span style="color: hsl(120, 100%, 40%);">+ "<discard_incoming>"</span><br><span style="color: hsl(120, 100%, 40%);">+The profiles are empty except for having their precedence</span><br><span style="color: hsl(120, 100%, 40%);">+set.</span><br><span>diff --git a/res/res_geolocation/geoloc_config.c b/res/res_geolocation/geoloc_config.c</span><br><span>index 772bdc7..5916697 100644</span><br><span>--- a/res/res_geolocation/geoloc_config.c</span><br><span>+++ b/res/res_geolocation/geoloc_config.c</span><br><span>@@ -85,7 +85,8 @@</span><br><span> </span><br><span> static void *geoloc_profile_alloc(const char *name)</span><br><span> {</span><br><span style="color: hsl(0, 100%, 40%);">- struct ast_geoloc_profile *profile = ast_sorcery_generic_alloc(sizeof(*profile), geoloc_profile_destructor);</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_geoloc_profile *profile = ast_sorcery_generic_alloc(sizeof(*profile),</span><br><span style="color: hsl(120, 100%, 40%);">+ geoloc_profile_destructor);</span><br><span> if (profile) {</span><br><span> ast_string_field_init(profile, 128);</span><br><span> }</span><br><span>@@ -581,18 +582,64 @@</span><br><span> return 0;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+static int default_profile_create(const char *name)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ int rc = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_geoloc_profile *profile;</span><br><span style="color: hsl(120, 100%, 40%);">+ char *id = ast_alloca(strlen(name) + 3 /* <, >, NULL */);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ sprintf(id, "<%s>", name); /* Safe */</span><br><span style="color: hsl(120, 100%, 40%);">+ profile = ast_sorcery_alloc(geoloc_sorcery, "profile", id);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_assert_return(profile != NULL, 0);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ profile->precedence = ast_geoloc_precedence_str_to_enum(name);</span><br><span style="color: hsl(120, 100%, 40%);">+ profile->pidf_element = AST_PIDF_ELEMENT_DEVICE;</span><br><span style="color: hsl(120, 100%, 40%);">+ rc = ast_sorcery_create(geoloc_sorcery, profile);</span><br><span style="color: hsl(120, 100%, 40%);">+ /*</span><br><span style="color: hsl(120, 100%, 40%);">+ * We're either passing the ref to sorcery or there was an error.</span><br><span style="color: hsl(120, 100%, 40%);">+ * Either way we need to drop our reference.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_ref(profile, -1);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ /* ast_assert_return wants a true/false */</span><br><span style="color: hsl(120, 100%, 40%);">+ return rc == 0 ? 1 : 0;</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%);">+static int geoloc_load_default_profiles(void)</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%);">+ * If any of these fail, the module will fail to load</span><br><span style="color: hsl(120, 100%, 40%);">+ * and clean up the sorcery instance so no error cleanup</span><br><span style="color: hsl(120, 100%, 40%);">+ * is required here.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_assert_return(default_profile_create("prefer_config"), -1);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_assert_return(default_profile_create("discard_config"), -1);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_assert_return(default_profile_create("prefer_incoming"), -1);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_assert_return(default_profile_create("discard_incoming"), -1);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ return 0;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> int geoloc_config_load(void)</span><br><span> {</span><br><span style="color: hsl(120, 100%, 40%);">+ enum ast_sorcery_apply_result result;</span><br><span style="color: hsl(120, 100%, 40%);">+ int rc = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> if (!(geoloc_sorcery = ast_sorcery_open())) {</span><br><span> ast_log(LOG_ERROR, "Failed to open geolocation sorcery\n");</span><br><span> return AST_MODULE_LOAD_DECLINE;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- ast_sorcery_apply_default(geoloc_sorcery, "location", "config", "geolocation.conf,criteria=type=location");</span><br><span style="color: hsl(0, 100%, 40%);">- if (ast_sorcery_object_register(geoloc_sorcery, "location", geoloc_location_alloc, NULL, geoloc_location_apply_handler)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_sorcery_apply_config(geoloc_sorcery, "location");</span><br><span style="color: hsl(120, 100%, 40%);">+ result = ast_sorcery_apply_default(geoloc_sorcery, "location", "config", "geolocation.conf,criteria=type=location");</span><br><span style="color: hsl(120, 100%, 40%);">+ if (result != AST_SORCERY_APPLY_SUCCESS) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(LOG_ERROR, "Failed to apply defaults for geoloc location object with sorcery\n");</span><br><span style="color: hsl(120, 100%, 40%);">+ return AST_MODULE_LOAD_DECLINE;</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%);">+ rc = ast_sorcery_object_register(geoloc_sorcery, "location", geoloc_location_alloc, NULL, geoloc_location_apply_handler);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (rc != 0) {</span><br><span> ast_log(LOG_ERROR, "Failed to register geoloc location object with sorcery\n");</span><br><span style="color: hsl(0, 100%, 40%);">- ast_sorcery_unref(geoloc_sorcery);</span><br><span style="color: hsl(0, 100%, 40%);">- geoloc_sorcery = NULL;</span><br><span> return AST_MODULE_LOAD_DECLINE;</span><br><span> }</span><br><span> </span><br><span>@@ -609,11 +656,25 @@</span><br><span> 0, STRFLDSET(struct ast_geoloc_location, method));</span><br><span> </span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- ast_sorcery_apply_default(geoloc_sorcery, "profile", "config", "geolocation.conf,criteria=type=profile");</span><br><span style="color: hsl(0, 100%, 40%);">- if (ast_sorcery_object_register(geoloc_sorcery, "profile", geoloc_profile_alloc, NULL, geoloc_profile_apply_handler)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_sorcery_apply_config(geoloc_sorcery, "profile");</span><br><span style="color: hsl(120, 100%, 40%);">+ /*</span><br><span style="color: hsl(120, 100%, 40%);">+ * The memory backend is used to contain the built-in profiles.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+ result = ast_sorcery_apply_wizard_mapping(geoloc_sorcery, "profile", "memory", NULL, 0);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (result == AST_SORCERY_APPLY_FAIL) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(LOG_ERROR, "Failed to add memory wizard mapping to geoloc profile object\n");</span><br><span style="color: hsl(120, 100%, 40%);">+ return AST_MODULE_LOAD_DECLINE;</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%);">+ result = ast_sorcery_apply_wizard_mapping(geoloc_sorcery, "profile", "config",</span><br><span style="color: hsl(120, 100%, 40%);">+ "geolocation.conf,criteria=type=profile", 0);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (result == AST_SORCERY_APPLY_FAIL) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(LOG_ERROR, "Failed to add memory wizard mapping to geoloc profile object\n");</span><br><span style="color: hsl(120, 100%, 40%);">+ return AST_MODULE_LOAD_DECLINE;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ rc = ast_sorcery_object_register(geoloc_sorcery, "profile", geoloc_profile_alloc, NULL, geoloc_profile_apply_handler);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (rc != 0) {</span><br><span> ast_log(LOG_ERROR, "Failed to register geoloc profile object with sorcery\n");</span><br><span style="color: hsl(0, 100%, 40%);">- ast_sorcery_unref(geoloc_sorcery);</span><br><span style="color: hsl(0, 100%, 40%);">- geoloc_sorcery = NULL;</span><br><span> return AST_MODULE_LOAD_DECLINE;</span><br><span> }</span><br><span> </span><br><span>@@ -638,6 +699,13 @@</span><br><span> </span><br><span> ast_sorcery_load(geoloc_sorcery);</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ rc = geoloc_load_default_profiles();</span><br><span style="color: hsl(120, 100%, 40%);">+ if (rc != 0) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(LOG_ERROR, "Failed to load default geoloc profiles\n");</span><br><span style="color: hsl(120, 100%, 40%);">+ return AST_MODULE_LOAD_DECLINE;</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%);">+</span><br><span> ast_cli_register_multiple(geoloc_location_cli_commands, ARRAY_LEN(geoloc_location_cli_commands));</span><br><span> </span><br><span> return AST_MODULE_LOAD_SUCCESS;</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/19158">change 19158</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/+/19158"/><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: I1819ccfa404ce59802a3a07ad1cabed60fb9480a </div>
<div style="display:none"> Gerrit-Change-Number: 19158 </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>