[asterisk-commits] mmichelson: branch group/pimp_my_sip r382270 - in /team/group/pimp_my_sip: in...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Feb 28 12:49:27 CST 2013


Author: mmichelson
Date: Thu Feb 28 12:49:24 2013
New Revision: 382270

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=382270
Log:
Add options to determine how endpoints are identified.

Prior to this commit, the method by which endpoints were identified was
dependent on what endpoint identification modules were loaded. While this
works, it's not likely to be useful for most deployments. Instead, having
control within the configuration of how identification should occur per
endpoint is more useful.

There is now an "identify_by" option that accepts a comma-delimited list of
methods by which the endpoint can be identified. By default, this is set to
"username,location" which allows for the endpoint to be identified by both
by username and by its IP address. The option can be changed to only allow
one method or the other.

Using this allows for easy expansion in case new methods of endpoint identification
are devised.


Modified:
    team/group/pimp_my_sip/include/asterisk/res_sip.h
    team/group/pimp_my_sip/res/res_sip/sip_configuration.c
    team/group/pimp_my_sip/res/res_sip_endpoint_identifier_ip.c
    team/group/pimp_my_sip/res/res_sip_endpoint_identifier_user.c

Modified: team/group/pimp_my_sip/include/asterisk/res_sip.h
URL: http://svnview.digium.com/svn/asterisk/team/group/pimp_my_sip/include/asterisk/res_sip.h?view=diff&rev=382270&r1=382269&r2=382270
==============================================================================
--- team/group/pimp_my_sip/include/asterisk/res_sip.h (original)
+++ team/group/pimp_my_sip/include/asterisk/res_sip.h Thu Feb 28 12:49:24 2013
@@ -201,6 +201,16 @@
 	unsigned int nonce_lifetime;
 	/* Used to determine what to use when authenticating */
 	enum ast_sip_auth_type type;
+};
+
+/*!
+ * \brief Different methods by which incoming requests can be matched to endpoints
+ */
+enum ast_sip_endpoint_identifier_type {
+	/*! Identify based on user name in From header */
+	AST_SIP_ENDPOINT_IDENTIFY_BY_USERNAME = (1 << 0),
+	/*! Identify based on source location of the SIP message */
+	AST_SIP_ENDPOINT_IDENTIFY_BY_LOCATION = (1 << 1),
 };
 
 /*!
@@ -248,6 +258,8 @@
 	AST_LIST_HEAD_NOLOCK(, ast_sip_registration) registrations;
 	/*! Frequency to send OPTIONS requests to endpoint. 0 is disabled. */
 	unsigned int qualify_frequency;
+	/*! Method(s) by which the endpoint should be identified. */
+	enum ast_sip_endpoint_identifier_type ident_method;
 };
 
 /*!

Modified: team/group/pimp_my_sip/res/res_sip/sip_configuration.c
URL: http://svnview.digium.com/svn/asterisk/team/group/pimp_my_sip/res/res_sip/sip_configuration.c?view=diff&rev=382270&r1=382269&r2=382270
==============================================================================
--- team/group/pimp_my_sip/res/res_sip/sip_configuration.c (original)
+++ team/group/pimp_my_sip/res/res_sip/sip_configuration.c Thu Feb 28 12:49:24 2013
@@ -232,6 +232,26 @@
 failure:
 	destroy_endpoint_auths(endpoint);
 	return -1;
+}
+
+static int ident_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
+{
+	struct ast_sip_endpoint *endpoint = obj;
+	char *idents = ast_strdupa(var->value);
+	char *val;
+
+	while ((val = strsep(&idents, ","))) {
+		if (!strcasecmp(val, "username")) {
+			endpoint->ident_method |= AST_SIP_ENDPOINT_IDENTIFY_BY_USERNAME;
+		} else if (!strcasecmp(val, "location")) {
+			endpoint->ident_method |= AST_SIP_ENDPOINT_IDENTIFY_BY_LOCATION;
+		} else {
+			ast_log(LOG_ERROR, "Unrecognized identification method %s specified for endpoint %s\n",
+					val, ast_sorcery_object_get_id(endpoint));
+			return -1;
+		}
+	}
+	return 0;
 }
 
 int ast_res_sip_initialize_configuration(void)
@@ -286,6 +306,7 @@
 	ast_sorcery_object_field_register(sip_sorcery, "endpoint", "timers_min_se", "90", OPT_UINT_T, 0, FLDSET(struct ast_sip_endpoint, min_se));
 	ast_sorcery_object_field_register(sip_sorcery, "endpoint", "timers_sess_expires", "1800", OPT_UINT_T, 0, FLDSET(struct ast_sip_endpoint, sess_expires));
 	ast_sorcery_object_field_register_custom(sip_sorcery, "endpoint", "auth", "", auth_handler, NULL, 0, 0);
+	ast_sorcery_object_field_register_custom(sip_sorcery, "endpoint", "identify_by", "username,location", ident_handler, NULL, 0, 0);
 
 	if (ast_sip_initialize_sorcery_transport(sip_sorcery)) {
 		ast_log(LOG_ERROR, "Failed to register SIP transport support with sorcery\n");

Modified: team/group/pimp_my_sip/res/res_sip_endpoint_identifier_ip.c
URL: http://svnview.digium.com/svn/asterisk/team/group/pimp_my_sip/res/res_sip_endpoint_identifier_ip.c?view=diff&rev=382270&r1=382269&r2=382270
==============================================================================
--- team/group/pimp_my_sip/res/res_sip_endpoint_identifier_ip.c (original)
+++ team/group/pimp_my_sip/res/res_sip_endpoint_identifier_ip.c Thu Feb 28 12:49:24 2013
@@ -42,6 +42,10 @@
 
 	endpoint = ast_sip_get_endpoint_from_location(host);
 	if (endpoint) {
+		if (!(endpoint->ident_method & AST_SIP_ENDPOINT_IDENTIFY_BY_LOCATION)) {
+			ao2_ref(endpoint, -1);
+			return NULL;
+		}
 		ast_debug(3, "Retrieved endpoint %s for IP address %s\n", ast_sorcery_object_get_id(endpoint), host);
 	} else {
 		ast_debug(3, "Could not find endpoint based on IP address %s\n", host);

Modified: team/group/pimp_my_sip/res/res_sip_endpoint_identifier_user.c
URL: http://svnview.digium.com/svn/asterisk/team/group/pimp_my_sip/res/res_sip_endpoint_identifier_user.c?view=diff&rev=382270&r1=382269&r2=382270
==============================================================================
--- team/group/pimp_my_sip/res/res_sip_endpoint_identifier_user.c (original)
+++ team/group/pimp_my_sip/res/res_sip_endpoint_identifier_user.c Thu Feb 28 12:49:24 2013
@@ -50,6 +50,10 @@
 	}
 	endpoint = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "endpoint", endpoint_name);
 	if (endpoint) {
+		if (!(endpoint->ident_method & AST_SIP_ENDPOINT_IDENTIFY_BY_USERNAME)) {
+			ao2_ref(endpoint, -1);
+			return NULL;
+		}
 		ast_debug(3, "Retrieved endpoint %s\n", ast_sorcery_object_get_id(endpoint));
 	}
 	return endpoint;




More information about the asterisk-commits mailing list