[svn-commits] file: branch file/pimp_sip_registration r382380 - in /team/file/pimp_sip_regi...
SVN commits to the Digium repositories
svn-commits at lists.digium.com
Mon Mar 4 11:16:49 CST 2013
Author: file
Date: Mon Mar 4 11:16:45 2013
New Revision: 382380
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=382380
Log:
Add domain alias support and make res_sip_endpoint_identifier_user aware of domains.
Added:
team/file/pimp_sip_registration/res/res_sip/config_domain_aliases.c (with props)
Modified:
team/file/pimp_sip_registration/include/asterisk/res_sip.h
team/file/pimp_sip_registration/res/res_sip/config_transport.c
team/file/pimp_sip_registration/res/res_sip/sip_configuration.c
team/file/pimp_sip_registration/res/res_sip_endpoint_identifier_user.c
Modified: team/file/pimp_sip_registration/include/asterisk/res_sip.h
URL: http://svnview.digium.com/svn/asterisk/team/file/pimp_sip_registration/include/asterisk/res_sip.h?view=diff&rev=382380&r1=382379&r2=382380
==============================================================================
--- team/file/pimp_sip_registration/include/asterisk/res_sip.h (original)
+++ team/file/pimp_sip_registration/include/asterisk/res_sip.h Mon Mar 4 11:16:45 2013
@@ -52,15 +52,17 @@
struct pjsip_tpfactory *factory;
};
-/*!
- * Details about a SIP domain
- */
-struct ast_sip_domain {
+#define SIP_SORCERY_DOMAIN_ALIAS_TYPE "domain_alias"
+
+/*!
+ * Details about a SIP domain alias
+ */
+struct ast_sip_domain_alias {
+ /*! Sorcery object details */
+ SORCERY_OBJECT(details);
AST_DECLARE_STRING_FIELDS(
- /*! The name of the domain */
- AST_STRING_FIELD(name);
- /*! Incoming context for authenticated calls from the domain */
- AST_STRING_FIELD(context);
+ /*! Domain to be aliased to */
+ AST_STRING_FIELD(domain);
);
};
@@ -92,6 +94,8 @@
AST_STRING_FIELD(privkey_file);
/*! Password to open the private key */
AST_STRING_FIELD(password);
+ /*! Optional domain to use for messages if provided could not be found */
+ AST_STRING_FIELD(domain);
);
/*! Type of transport */
enum ast_sip_transport_type type;
@@ -499,6 +503,16 @@
int ast_sip_location_delete_contact(struct ast_sip_contact *contact);
/*!
+ * \brief Initialize domain aliases support on a sorcery instance
+ *
+ * \param sorcery The sorcery instance
+ *
+ * \retval -1 failure
+ * \retval 0 success
+ */
+int ast_sip_initialize_sorcery_domain_alias(struct ast_sorcery *sorcery);
+
+/*!
* \brief Initialize authentication support on a sorcery instance
*
* \param sorcery The sorcery instance
Added: team/file/pimp_sip_registration/res/res_sip/config_domain_aliases.c
URL: http://svnview.digium.com/svn/asterisk/team/file/pimp_sip_registration/res/res_sip/config_domain_aliases.c?view=auto&rev=382380
==============================================================================
--- team/file/pimp_sip_registration/res/res_sip/config_domain_aliases.c (added)
+++ team/file/pimp_sip_registration/res/res_sip/config_domain_aliases.c Mon Mar 4 11:16:45 2013
@@ -1,0 +1,67 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2013, Digium, Inc.
+ *
+ * Joshua Colp <jcolp at digium.com>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+#include "asterisk.h"
+
+#undef bzero
+#define bzero bzero
+#include "pjsip.h"
+#include "pjlib.h"
+#include "asterisk/res_sip.h"
+#include "asterisk/logger.h"
+#include "asterisk/sorcery.h"
+
+static void domain_alias_destroy(void *obj)
+{
+ struct ast_sip_domain_alias *alias = obj;
+
+ ast_string_field_free_memory(alias);
+}
+
+static void *domain_alias_alloc(const char *name)
+{
+ struct ast_sip_domain_alias *alias = ao2_alloc(sizeof(*alias), domain_alias_destroy);
+
+ if (!alias) {
+ return NULL;
+ }
+
+ if (ast_string_field_init(alias, 256)) {
+ ao2_cleanup(alias);
+ return NULL;
+ }
+
+ return alias;
+}
+
+/*! \brief Initialize sorcery with domain alias support */
+int ast_sip_initialize_sorcery_domain_alias(struct ast_sorcery *sorcery)
+{
+ ast_sorcery_apply_default(sorcery, SIP_SORCERY_DOMAIN_ALIAS_TYPE, "config", "res_sip.conf,criteria=type=domain_alias");
+
+ if (ast_sorcery_object_register(sorcery, SIP_SORCERY_DOMAIN_ALIAS_TYPE, domain_alias_alloc, NULL, NULL)) {
+ return -1;
+ }
+
+ ast_sorcery_object_field_register(sorcery, SIP_SORCERY_DOMAIN_ALIAS_TYPE, "type", "",
+ OPT_NOOP_T, 0, 0);
+ ast_sorcery_object_field_register(sorcery, SIP_SORCERY_DOMAIN_ALIAS_TYPE, "domain",
+ "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_domain_alias, domain));
+
+ return 0;
+}
Propchange: team/file/pimp_sip_registration/res/res_sip/config_domain_aliases.c
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: team/file/pimp_sip_registration/res/res_sip/config_domain_aliases.c
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange: team/file/pimp_sip_registration/res/res_sip/config_domain_aliases.c
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: team/file/pimp_sip_registration/res/res_sip/config_transport.c
URL: http://svnview.digium.com/svn/asterisk/team/file/pimp_sip_registration/res/res_sip/config_transport.c?view=diff&rev=382380&r1=382379&r2=382380
==============================================================================
--- team/file/pimp_sip_registration/res/res_sip/config_transport.c (original)
+++ team/file/pimp_sip_registration/res/res_sip/config_transport.c Mon Mar 4 11:16:45 2013
@@ -247,6 +247,7 @@
ast_sorcery_object_field_register(sorcery, "transport", "cert_file", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_transport, cert_file));
ast_sorcery_object_field_register(sorcery, "transport", "privkey_file", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_transport, privkey_file));
ast_sorcery_object_field_register(sorcery, "transport", "password", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_transport, password));
+ ast_sorcery_object_field_register(sorcery, "transport", "domain", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_transport, domain));
ast_sorcery_object_field_register_custom(sorcery, "transport", "verify_server", "", transport_tls_bool_handler, NULL, 0, 0);
ast_sorcery_object_field_register_custom(sorcery, "transport", "verify_client", "", transport_tls_bool_handler, NULL, 0, 0);
ast_sorcery_object_field_register_custom(sorcery, "transport", "require_client_cert", "", transport_tls_bool_handler, NULL, 0, 0);
Modified: team/file/pimp_sip_registration/res/res_sip/sip_configuration.c
URL: http://svnview.digium.com/svn/asterisk/team/file/pimp_sip_registration/res/res_sip/sip_configuration.c?view=diff&rev=382380&r1=382379&r2=382380
==============================================================================
--- team/file/pimp_sip_registration/res/res_sip/sip_configuration.c (original)
+++ team/file/pimp_sip_registration/res/res_sip/sip_configuration.c Mon Mar 4 11:16:45 2013
@@ -220,6 +220,13 @@
return -1;
}
+ if (ast_sip_initialize_sorcery_domain_alias(sip_sorcery)) {
+ ast_log(LOG_ERROR, "Failed to register SIP domain aliases support with sorcery\n");
+ ast_sorcery_unref(sip_sorcery);
+ sip_sorcery = NULL;
+ return -1;
+ }
+
ast_sorcery_load(sip_sorcery);
return 0;
Modified: team/file/pimp_sip_registration/res/res_sip_endpoint_identifier_user.c
URL: http://svnview.digium.com/svn/asterisk/team/file/pimp_sip_registration/res/res_sip_endpoint_identifier_user.c?view=diff&rev=382380&r1=382379&r2=382380
==============================================================================
--- team/file/pimp_sip_registration/res/res_sip_endpoint_identifier_user.c (original)
+++ team/file/pimp_sip_registration/res/res_sip_endpoint_identifier_user.c Mon Mar 4 11:16:45 2013
@@ -29,7 +29,7 @@
#include "asterisk/res_sip.h"
#include "asterisk/module.h"
-static int get_endpoint_name(pjsip_rx_data *rdata, char *endpoint, size_t size)
+static int get_endpoint_details(pjsip_rx_data *rdata, char *endpoint, size_t endpoint_size, char *domain, size_t domain_size)
{
pjsip_uri *from = rdata->msg_info.from->uri;
pjsip_sip_uri *sip_from;
@@ -37,18 +37,65 @@
return -1;
}
sip_from = (pjsip_sip_uri *) pjsip_uri_get_uri(from);
- ast_copy_pj_str(endpoint, &sip_from->user, size);
+ ast_copy_pj_str(endpoint, &sip_from->user, endpoint_size);
+ ast_copy_pj_str(domain, &sip_from->host, domain_size);
+ return 0;
+}
+
+static int find_transport_in_use(void *obj, void *arg, int flags)
+{
+ struct ast_sip_transport *transport = obj;
+ pjsip_rx_data *rdata = arg;
+
+ if ((transport->state->transport == rdata->tp_info.transport) ||
+ (transport->state->factory && !pj_strcmp(&transport->state->factory->addr_name.host, &rdata->tp_info.transport->local_name.host) &&
+ transport->state->factory->addr_name.port == rdata->tp_info.transport->local_name.port)) {
+ return CMP_MATCH | CMP_STOP;
+ }
+
return 0;
}
static struct ast_sip_endpoint *username_identify(pjsip_rx_data *rdata)
{
- char endpoint_name[64];
+ char endpoint_name[64], domain_name[64], id[AST_UUID_STR_LEN];
struct ast_sip_endpoint *endpoint;
- if (get_endpoint_name(rdata, endpoint_name, sizeof(endpoint_name))) {
+ RAII_VAR(struct ast_sip_domain_alias *, alias, NULL, ao2_cleanup);
+ RAII_VAR(struct ao2_container *, transports, NULL, ao2_cleanup);
+ RAII_VAR(struct ast_sip_transport *, transport, NULL, ao2_cleanup);
+
+ if (get_endpoint_details(rdata, endpoint_name, sizeof(endpoint_name), domain_name, sizeof(domain_name))) {
return NULL;
}
+
+ /* Attempt to find the endpoint given the name and domain provided */
+ snprintf(id, sizeof(id), "%s@%s", endpoint_name, domain_name);
+ if ((endpoint = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "endpoint", id))) {
+ goto done;
+ }
+
+ /* See if an alias exists for the domain provided */
+ if ((alias = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "domain_alias", domain_name))) {
+ snprintf(id, sizeof(id), "%s@%s", endpoint_name, alias->domain);
+ if ((endpoint = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "endpoint", id))) {
+ goto done;
+ }
+ }
+
+ /* See if the transport this came in on has a provided domain */
+ if ((transports = ast_sorcery_retrieve_by_fields(ast_sip_get_sorcery(), "transport", AST_RETRIEVE_FLAG_MULTIPLE | AST_RETRIEVE_FLAG_ALL, NULL)) &&
+ (transport = ao2_callback(transports, 0, find_transport_in_use, rdata)) &&
+ !ast_strlen_zero(transport->domain)) {
+ snprintf(id, sizeof(id), "%s@%s", endpoint_name, transport->domain);
+ if ((endpoint = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "endpoint", id))) {
+ goto done;
+ }
+ }
+
+ /* Fall back to no domain */
endpoint = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "endpoint", endpoint_name);
+
+done:
if (endpoint) {
ast_debug(3, "Retrieved endpoint %s\n", ast_sorcery_object_get_id(endpoint));
}
More information about the svn-commits
mailing list