build: Update config.guess and config.sub
[asterisk/asterisk.git] / res / res_pjsip_config_wizard.c
index cf09a54..3a761a7 100644 (file)
@@ -39,8 +39,6 @@
 
 #include "asterisk.h"
 
-ASTERISK_REGISTER_FILE()
-
 #include <regex.h>
 #include <pjsip.h>
 
@@ -141,6 +139,12 @@ ASTERISK_REGISTER_FILE()
                                        entry in the list.  If send_registrations is also set, a registration will
                                        also be created for each.</para></description>
                                </configOption>
+                               <configOption name="outbound_proxy">
+                                       <synopsis>Shortcut for specifying proxy on individual objects.</synopsis>
+                                       <description><para>Shortcut for specifying endpoint/outbound_proxy,
+                                       aor/outbound_proxy, and registration/outbound_proxy individually.
+                                       </para></description>
+                               </configOption>
                                <configOption name="sends_auth" default="no">
                                        <synopsis>Send outbound authentication to remote hosts.</synopsis>
                                        <description><para>At least outbound_auth/username is required.</para></description>
@@ -155,6 +159,13 @@ ASTERISK_REGISTER_FILE()
                                        be created for each host in the remote _hosts string.  If authentication is required,
                                        sends_auth and an outbound_auth/username must also be supplied.</para></description>
                                </configOption>
+                               <configOption name="sends_line_with_registrations" default="no">
+                                       <synopsis>Sets "line" and "endpoint parameters on registrations.</synopsis>
+                                       <description><para>Setting this to true will cause the wizard to skip the
+                                       creation of an identify object to match incoming requests to the endpoint and
+                                       instead add the line and endpoint parameters to the outbound registration object.
+                                       </para></description>
+                               </configOption>
                                <configOption name="accepts_registrations" default="no">
                                        <synopsis>Accept inbound registration from remote hosts.</synopsis>
                                        <description><para>An AOR with dynamic contacts will be created.  If
@@ -463,7 +474,7 @@ static int add_extension(struct ast_context *context, const char *exten,
        }
 
        if (ast_add_extension2_nolock(context, 0, exten, priority, NULL, NULL,
-                       app, data, free_ptr, BASE_REGISTRAR)) {
+                       app, data, free_ptr, BASE_REGISTRAR, NULL, 0)) {
                ast_free(data);
                return -1;
        }
@@ -597,11 +608,16 @@ static int handle_aor(const struct ast_sorcery *sorcery, struct object_type_wiza
        struct ast_sorcery_object *obj = NULL;
        const char *id = ast_category_get_name(wiz);
        const char *contact_pattern;
+       const char *outbound_proxy = ast_variable_find_last_in_list(wizvars, "outbound_proxy");
        int host_count = AST_VECTOR_SIZE(remote_hosts_vector);
        RAII_VAR(struct ast_variable *, vars, get_object_variables(wizvars, "aor/"), ast_variables_destroy);
 
        variable_list_append(&vars, "@pjsip_wizard", id);
 
+       if (!ast_strlen_zero(outbound_proxy)) {
+               variable_list_append_return(&vars, "outbound_proxy", outbound_proxy);
+       }
+
        /* If the user explicitly specified an aor/contact, don't use remote hosts. */
        if (!ast_variable_find_last_in_list(vars, "contact")) {
                if (!(contact_pattern = ast_variable_find_last_in_list(wizvars, "contact_pattern"))) {
@@ -649,6 +665,7 @@ static int handle_endpoint(const struct ast_sorcery *sorcery, struct object_type
        struct ast_variable *wizvars = ast_category_first(wiz);
        struct ast_sorcery_object *obj = NULL;
        const char *id = ast_category_get_name(wiz);
+       const char *outbound_proxy = ast_variable_find_last_in_list(wizvars, "outbound_proxy");
        const char *transport = ast_variable_find_last_in_list(wizvars, "transport");
        const char *hint_context = hint_context = ast_variable_find_last_in_list(wizvars, "hint_context");
        const char *hint_exten = ast_variable_find_last_in_list(wizvars, "hint_exten");
@@ -659,6 +676,10 @@ static int handle_endpoint(const struct ast_sorcery *sorcery, struct object_type
        variable_list_append_return(&vars, "@pjsip_wizard", id);
        variable_list_append_return(&vars, "aors", id);
 
+       if (!ast_strlen_zero(outbound_proxy)) {
+               variable_list_append_return(&vars, "outbound_proxy", outbound_proxy);
+       }
+
        if (ast_strlen_zero(hint_context)) {
                hint_context = ast_variable_find_last_in_list(vars, "context");
        }
@@ -721,8 +742,9 @@ static int handle_identify(const struct ast_sorcery *sorcery, struct object_type
 
        snprintf(new_id, sizeof(new_id), "%s-identify", id);
 
-       /* If accepting registrations, we don't need an identify. */
-       if (is_variable_true(wizvars, "accepts_registrations")) {
+       /* If accepting registrations or we're sending line, we don't need an identify. */
+       if (is_variable_true(wizvars, "accepts_registrations")
+               || is_variable_true(wizvars, "sends_line_with_registrations")) {
                /* If one exists, delete it. */
                obj = otw->wizard->retrieve_id(sorcery, otw->wizard_data, "identify", new_id);
                if (obj) {
@@ -838,6 +860,7 @@ static int handle_registrations(const struct ast_sorcery *sorcery, struct object
        const char *id = ast_category_get_name(wiz);
        const char *server_uri_pattern;
        const char *client_uri_pattern;
+       const char *outbound_proxy = ast_variable_find_last_in_list(wizvars, "outbound_proxy");
        const char *transport = ast_variable_find_last_in_list(wizvars, "transport");
        const char *username;
        char new_id[strlen(id) + MAX_ID_SUFFIX];
@@ -857,6 +880,10 @@ static int handle_registrations(const struct ast_sorcery *sorcery, struct object
                return -1;
        }
 
+       if (!ast_strlen_zero(outbound_proxy)) {
+               variable_list_append_return(&vars, "outbound_proxy", outbound_proxy);
+       }
+
        otw->wizard->retrieve_multiple(sorcery, otw->wizard_data, "registration", existing, search);
        ast_variables_destroy(search);
 
@@ -927,6 +954,11 @@ static int handle_registrations(const struct ast_sorcery *sorcery, struct object
                        variable_list_append_return(&registration_vars, "transport", transport);
                }
 
+               if (is_variable_true(wizvars, "sends_line_with_registrations")) {
+                       variable_list_append_return(&registration_vars, "line", "yes");
+                       variable_list_append_return(&registration_vars, "endpoint", id);
+               }
+
                snprintf(new_id, sizeof(new_id), "%s-reg-%d", id, host_counter);
 
                obj = create_object(sorcery, new_id, "registration", registration_vars);
@@ -969,7 +1001,10 @@ static int wizard_apply_handler(const struct ast_sorcery *sorcery, struct object
                char *hosts = ast_strdupa(remote_hosts);
 
                while ((host = ast_strsep(&hosts, ',', AST_STRSEP_TRIM))) {
-                       AST_VECTOR_APPEND(&remote_hosts_vector, ast_strdup(host));
+                       host = ast_strdup(host);
+                       if (host && AST_VECTOR_APPEND(&remote_hosts_vector, host)) {
+                               ast_free(host);
+                       }
                }
        }
 
@@ -989,7 +1024,7 @@ static int wizard_apply_handler(const struct ast_sorcery *sorcery, struct object
                rc = handle_registrations(sorcery, otw, wiz, &remote_hosts_vector);
        }
 
-       AST_VECTOR_REMOVE_CMP_UNORDERED(&remote_hosts_vector, NULL, NOT_EQUALS, ast_free);
+       AST_VECTOR_REMOVE_ALL_CMP_UNORDERED(&remote_hosts_vector, NULL, NOT_EQUALS, ast_free);
        AST_VECTOR_FREE(&remote_hosts_vector);
 
        ast_debug(4, "%s handler complete.  rc: %d\n", otw->object_type, rc);
@@ -1136,15 +1171,22 @@ static void wizard_mapped_observer(const char *name, struct ast_sorcery *sorcery
        /* We're only interested in memory wizards with the pjsip_wizard tag. */
        if (wizard_args && !strcmp(wizard_args, "pjsip_wizard")) {
                otw = ast_malloc(sizeof(*otw) + strlen(object_type) + 1);
+               if (!otw) {
+                       return;
+               }
+
                otw->sorcery = sorcery;
                otw->wizard = wizard;
                otw->wizard_data = wizard_data;
                otw->last_config = NULL;
                strcpy(otw->object_type, object_type); /* Safe */
                AST_VECTOR_RW_WRLOCK(&object_type_wizards);
-               AST_VECTOR_APPEND(&object_type_wizards, otw);
+               if (AST_VECTOR_APPEND(&object_type_wizards, otw)) {
+                       ast_free(otw);
+               } else {
+                       ast_debug(1, "Wizard mapped for object_type '%s'\n", object_type);
+               }
                AST_VECTOR_RW_UNLOCK(&object_type_wizards);
-               ast_debug(1, "Wizard mapped for object_type '%s'\n", object_type);
        }
 }
 
@@ -1293,7 +1335,7 @@ static int unload_module(void)
 {
        ast_cli_unregister_multiple(config_wizard_cli, ARRAY_LEN(config_wizard_cli));
        ast_sorcery_global_observer_remove(&global_observer);
-       AST_VECTOR_REMOVE_CMP_UNORDERED(&object_type_wizards, NULL, NOT_EQUALS, OTW_DELETE_CB);
+       AST_VECTOR_REMOVE_ALL_CMP_UNORDERED(&object_type_wizards, NULL, NOT_EQUALS, OTW_DELETE_CB);
        AST_VECTOR_RW_FREE(&object_type_wizards);
 
        return 0;