[asterisk-commits] kharwell: branch certified-13.1 r432658 - in /certified/branches/13.1: ./ con...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Mon Mar 9 11:44:36 CDT 2015
Author: kharwell
Date: Mon Mar 9 11:44:31 2015
New Revision: 432658
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=432658
Log:
res_pjsip: Allow configuration of endpoint identifier query order
It's possible to have a scenario that will create a conflict between endpoint
identifiers. For instance an incoming call could be identified by two different
endpoint identifiers and the one chosen depended upon which identifier module
loaded first. This of course causes problems when, for example, the incoming
call is expected to be identified by username, but instead is identified by ip.
This patch adds a new 'global' option to res_pjsip called
'endpoint_identifier_order'. It is a comma separated list of endpoint
identifier names that specifies the order by which identifiers are processed
and checked.
ASTERISK-24840 #close
Reported by: Mark Michelson
Review: https://reviewboard.asterisk.org/r/4455/
........
Merged revisions 432638 from http://svn.asterisk.org/svn/asterisk/branches/13
Added:
certified/branches/13.1/contrib/ast-db-manage/config/versions/45e3f47c6c44_add_pjsip_endpoint_identifier_order.py
- copied unchanged from r432638, branches/13/contrib/ast-db-manage/config/versions/45e3f47c6c44_add_pjsip_endpoint_identifier_order.py
Modified:
certified/branches/13.1/ (props changed)
certified/branches/13.1/CHANGES
certified/branches/13.1/configs/samples/pjsip.conf.sample
certified/branches/13.1/include/asterisk/res_pjsip.h
certified/branches/13.1/res/res_pjsip.c
certified/branches/13.1/res/res_pjsip/config_global.c
certified/branches/13.1/res/res_pjsip_endpoint_identifier_anonymous.c
certified/branches/13.1/res/res_pjsip_endpoint_identifier_ip.c
certified/branches/13.1/res/res_pjsip_endpoint_identifier_user.c
Propchange: certified/branches/13.1/
------------------------------------------------------------------------------
Binary property 'branch-13-merged' - no diff available.
Modified: certified/branches/13.1/CHANGES
URL: http://svnview.digium.com/svn/asterisk/certified/branches/13.1/CHANGES?view=diff&rev=432658&r1=432657&r2=432658
==============================================================================
--- certified/branches/13.1/CHANGES (original)
+++ certified/branches/13.1/CHANGES Mon Mar 9 11:44:31 2015
@@ -8,6 +8,16 @@
===
==============================================================================
------------------------------------------------------------------------------
+--- Functionality changes from Asterisk 13.1-cert1 to Asterisk 13.1-cert2 ----
+------------------------------------------------------------------------------
+
+res_pjsip
+------------------
+ * A new 'endpoint_identifier_order' option has been added that allows one to
+ set the order by which endpoint identifiers are processed and checked. This
+ option is specified under the 'global' type configuration section.
+
+------------------------------------------------------------------------------
--- Functionality changes from Asterisk 13.1.0 to Asterisk 13.1-cert1 --------
------------------------------------------------------------------------------
@@ -77,7 +87,7 @@
------------------
* New CLI commands have been added: "pjsip show identif(y|ies)", which lists
all configured PJSIP identify objects
-
+
------------------------------------------------------------------------------
--- Functionality changes from Asterisk 12 to Asterisk 13 --------------------
------------------------------------------------------------------------------
Modified: certified/branches/13.1/configs/samples/pjsip.conf.sample
URL: http://svnview.digium.com/svn/asterisk/certified/branches/13.1/configs/samples/pjsip.conf.sample?view=diff&rev=432658&r1=432657&r2=432658
==============================================================================
--- certified/branches/13.1/configs/samples/pjsip.conf.sample (original)
+++ certified/branches/13.1/configs/samples/pjsip.conf.sample Mon Mar 9 11:44:31 2015
@@ -861,6 +861,10 @@
;keep_alive_interval=20 ; The interval (in seconds) at which to send keepalive
; messages on all active connection-oriented transports
; (default: "0")
+;endpoint_identifier_order=ip,username,anonymous
+ ; The order by which endpoint identifiers are given priority.
+ ; Identifier names are derived from res_pjsip_endpoint_identifier_*
+ ; modules. (default: ip,username,anonymous)
; MODULE PROVIDING BELOW SECTION(S): res_pjsip_acl
Modified: certified/branches/13.1/include/asterisk/res_pjsip.h
URL: http://svnview.digium.com/svn/asterisk/certified/branches/13.1/include/asterisk/res_pjsip.h?view=diff&rev=432658&r1=432657&r2=432658
==============================================================================
--- certified/branches/13.1/include/asterisk/res_pjsip.h (original)
+++ certified/branches/13.1/include/asterisk/res_pjsip.h Mon Mar 9 11:44:31 2015
@@ -695,6 +695,8 @@
* \brief An entity responsible for identifying the source of a SIP message
*/
struct ast_sip_endpoint_identifier {
+ /*! Name of the endpoint identifier */
+ const char *name;
/*!
* \brief Callback used to identify the source of a message.
* See ast_sip_identify_endpoint for more details
@@ -1958,6 +1960,15 @@
*/
char *ast_sip_get_debug(void);
+/*!
+ * \brief Retrieve the global endpoint_identifier_order setting.
+ *
+ * Specifies the order by which endpoint identifiers should be regarded.
+ *
+ * \retval the global endpoint_identifier_order value
+ */
+char *ast_sip_get_endpoint_identifier_order(void);
+
/*! \brief Determines whether the res_pjsip module is loaded */
#define CHECK_PJSIP_MODULE_LOADED() \
do { \
Modified: certified/branches/13.1/res/res_pjsip.c
URL: http://svnview.digium.com/svn/asterisk/certified/branches/13.1/res/res_pjsip.c?view=diff&rev=432658&r1=432657&r2=432658
==============================================================================
--- certified/branches/13.1/res/res_pjsip.c (original)
+++ certified/branches/13.1/res/res_pjsip.c Mon Mar 9 11:44:31 2015
@@ -36,6 +36,7 @@
#include "asterisk/uuid.h"
#include "asterisk/sorcery.h"
#include "asterisk/file.h"
+#include "asterisk/cli.h"
/*** MODULEINFO
<depend>pjproject</depend>
@@ -1183,6 +1184,11 @@
<configOption name="debug" default="no">
<synopsis>Enable/Disable SIP debug logging. Valid options include yes|no or
a host address</synopsis>
+ </configOption>
+ <configOption name="endpoint_identifier_order" default="ip,username,anonymous">
+ <synopsis>The order by which endpoint identifiers are processed and checked.
+ Identifier names are usually derived from and can be found in the endpoint
+ identifier module itself (res_pjsip_endpoint_identifier_*)</synopsis>
</configOption>
</configObject>
</configFile>
@@ -1916,6 +1922,7 @@
}
struct endpoint_identifier_list {
+ unsigned int priority;
struct ast_sip_endpoint_identifier *identifier;
AST_RWLIST_ENTRY(endpoint_identifier_list) list;
};
@@ -1924,7 +1931,8 @@
int ast_sip_register_endpoint_identifier(struct ast_sip_endpoint_identifier *identifier)
{
- struct endpoint_identifier_list *id_list_item;
+ char *prev, *current, *identifier_order;
+ struct endpoint_identifier_list *iter, *id_list_item;
SCOPED_LOCK(lock, &endpoint_identifiers, AST_RWLIST_WRLOCK, AST_RWLIST_UNLOCK);
id_list_item = ast_calloc(1, sizeof(*id_list_item));
@@ -1934,10 +1942,67 @@
}
id_list_item->identifier = identifier;
- AST_RWLIST_INSERT_TAIL(&endpoint_identifiers, id_list_item, list);
- ast_debug(1, "Registered endpoint identifier %p\n", identifier);
+ ast_debug(1, "Register endpoint identifier %s (%p)\n", identifier->name, identifier);
+
+ if (ast_strlen_zero(identifier->name)) {
+ /* if an identifier has no name then place in front */
+ AST_RWLIST_INSERT_HEAD(&endpoint_identifiers, id_list_item, list);
+ ast_module_ref(ast_module_info->self);
+ return 0;
+ }
+
+ /* see if the name of the identifier is in the global endpoint_identifier_order list */
+ identifier_order = prev = current = ast_sip_get_endpoint_identifier_order();
+
+ if (ast_strlen_zero(identifier_order)) {
+ AST_RWLIST_INSERT_TAIL(&endpoint_identifiers, id_list_item, list);
+ ast_module_ref(ast_module_info->self);
+ ast_free(identifier_order);
+ return 0;
+ }
+
+ id_list_item->priority = 0;
+ while ((current = strchr(current, ','))) {
+ ++id_list_item->priority;
+ if (!strncmp(prev, identifier->name, current - prev)) {
+ break;
+ }
+ prev = ++current;
+ }
+
+ if (!current) {
+ /* check to see if it the only or last item */
+ if (!strcmp(prev, identifier->name)) {
+ ++id_list_item->priority;
+ } else {
+ id_list_item->priority = UINT_MAX;
+ }
+ }
+
+ if (id_list_item->priority == UINT_MAX || AST_RWLIST_EMPTY(&endpoint_identifiers)) {
+ /* if not in the endpoint_identifier_order list then consider it less in
+ priority and add it to the end */
+ AST_RWLIST_INSERT_TAIL(&endpoint_identifiers, id_list_item, list);
+ ast_module_ref(ast_module_info->self);
+ ast_free(identifier_order);
+ return 0;
+ }
+
+ AST_RWLIST_TRAVERSE_SAFE_BEGIN(&endpoint_identifiers, iter, list) {
+ if (id_list_item->priority < iter->priority) {
+ AST_RWLIST_INSERT_BEFORE_CURRENT(id_list_item, list);
+ break;
+ }
+
+ if (!AST_RWLIST_NEXT(iter, list)) {
+ AST_RWLIST_INSERT_AFTER(&endpoint_identifiers, iter, id_list_item, list);
+ break;
+ }
+ }
+ AST_RWLIST_TRAVERSE_SAFE_END;
ast_module_ref(ast_module_info->self);
+ ast_free(identifier_order);
return 0;
}
@@ -1971,6 +2036,41 @@
}
return endpoint;
}
+
+static char *cli_show_endpoint_identifiers(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+#define ENDPOINT_IDENTIFIER_FORMAT "%-20.20s\n"
+ struct endpoint_identifier_list *iter;
+
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "pjsip show identifiers";
+ e->usage = "Usage: pjsip show identifiers\n"
+ " List all registered endpoint identifiers\n";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
+
+ if (a->argc != 3) {
+ return CLI_SHOWUSAGE;
+ }
+
+ ast_cli(a->fd, ENDPOINT_IDENTIFIER_FORMAT, "Identifier Names:");
+ {
+ SCOPED_LOCK(lock, &endpoint_identifiers, AST_RWLIST_RDLOCK, AST_RWLIST_UNLOCK);
+ AST_RWLIST_TRAVERSE(&endpoint_identifiers, iter, list) {
+ ast_cli(a->fd, ENDPOINT_IDENTIFIER_FORMAT,
+ iter->identifier->name ? iter->identifier->name : "name not specified");
+ }
+ }
+ return CLI_SUCCESS;
+#undef ENDPOINT_IDENTIFIER_FORMAT
+}
+
+static struct ast_cli_entry cli_commands[] = {
+ AST_CLI_DEFINE(cli_show_endpoint_identifiers, "List registered endpoint identifiers")
+};
AST_RWLIST_HEAD_STATIC(endpoint_formatters, ast_sip_endpoint_formatter);
@@ -3234,6 +3334,7 @@
}
ast_res_pjsip_init_options_handling(0);
+ ast_cli_register_multiple(cli_commands, ARRAY_LEN(cli_commands));
ast_module_ref(ast_module_info->self);
@@ -3256,6 +3357,7 @@
static int unload_module(void)
{
+ ast_cli_unregister_multiple(cli_commands, ARRAY_LEN(cli_commands));
/* This will never get called as this module can't be unloaded */
return 0;
}
Modified: certified/branches/13.1/res/res_pjsip/config_global.c
URL: http://svnview.digium.com/svn/asterisk/certified/branches/13.1/res/res_pjsip/config_global.c?view=diff&rev=432658&r1=432657&r2=432658
==============================================================================
--- certified/branches/13.1/res/res_pjsip/config_global.c (original)
+++ certified/branches/13.1/res/res_pjsip/config_global.c Mon Mar 9 11:44:31 2015
@@ -39,6 +39,8 @@
AST_STRING_FIELD(default_outbound_endpoint);
/*! Debug logging yes|no|host */
AST_STRING_FIELD(debug);
+ /*! Order by which endpoint identifiers are checked (comma separated list) */
+ AST_STRING_FIELD(endpoint_identifier_order);
);
/* Value to put in Max-Forwards header */
unsigned int max_forwards;
@@ -57,7 +59,7 @@
{
struct global_config *cfg = ast_sorcery_generic_alloc(sizeof(*cfg), global_destructor);
- if (!cfg || ast_string_field_init(cfg, 80)) {
+ if (!cfg || ast_string_field_init(cfg, 100)) {
return NULL;
}
@@ -116,6 +118,21 @@
return res;
}
+char *ast_sip_get_endpoint_identifier_order(void)
+{
+ char *res;
+ struct global_config *cfg = get_global_cfg();
+
+ if (!cfg) {
+ return ast_strdup("ip,username,anonymous");
+ }
+
+ res = ast_strdup(cfg->endpoint_identifier_order);
+ ao2_ref(cfg, -1);
+
+ return res;
+}
+
unsigned int ast_sip_get_keep_alive_interval(void)
{
unsigned int interval;
@@ -152,6 +169,8 @@
OPT_STRINGFIELD_T, 0, STRFLDSET(struct global_config, default_outbound_endpoint));
ast_sorcery_object_field_register(sorcery, "global", "debug", "no",
OPT_STRINGFIELD_T, 0, STRFLDSET(struct global_config, debug));
+ ast_sorcery_object_field_register(sorcery, "global", "endpoint_identifier_order", "ip,username,anonymous",
+ OPT_STRINGFIELD_T, 0, STRFLDSET(struct global_config, endpoint_identifier_order));
ast_sorcery_object_field_register(sorcery, "global", "keep_alive_interval", "",
OPT_UINT_T, 0, FLDSET(struct global_config, keep_alive_interval));
Modified: certified/branches/13.1/res/res_pjsip_endpoint_identifier_anonymous.c
URL: http://svnview.digium.com/svn/asterisk/certified/branches/13.1/res/res_pjsip_endpoint_identifier_anonymous.c?view=diff&rev=432658&r1=432657&r2=432658
==============================================================================
--- certified/branches/13.1/res/res_pjsip_endpoint_identifier_anonymous.c (original)
+++ certified/branches/13.1/res/res_pjsip_endpoint_identifier_anonymous.c Mon Mar 9 11:44:31 2015
@@ -103,6 +103,7 @@
}
static struct ast_sip_endpoint_identifier anonymous_identifier = {
+ .name = "anonymous",
.identify_endpoint = anonymous_identify,
};
Modified: certified/branches/13.1/res/res_pjsip_endpoint_identifier_ip.c
URL: http://svnview.digium.com/svn/asterisk/certified/branches/13.1/res/res_pjsip_endpoint_identifier_ip.c?view=diff&rev=432658&r1=432657&r2=432658
==============================================================================
--- certified/branches/13.1/res/res_pjsip_endpoint_identifier_ip.c (original)
+++ certified/branches/13.1/res/res_pjsip_endpoint_identifier_ip.c Mon Mar 9 11:44:31 2015
@@ -150,6 +150,7 @@
}
static struct ast_sip_endpoint_identifier ip_identifier = {
+ .name = "ip",
.identify_endpoint = ip_identify,
};
Modified: certified/branches/13.1/res/res_pjsip_endpoint_identifier_user.c
URL: http://svnview.digium.com/svn/asterisk/certified/branches/13.1/res/res_pjsip_endpoint_identifier_user.c?view=diff&rev=432658&r1=432657&r2=432658
==============================================================================
--- certified/branches/13.1/res/res_pjsip_endpoint_identifier_user.c (original)
+++ certified/branches/13.1/res/res_pjsip_endpoint_identifier_user.c Mon Mar 9 11:44:31 2015
@@ -109,6 +109,7 @@
}
static struct ast_sip_endpoint_identifier username_identifier = {
+ .name = "username",
.identify_endpoint = username_identify,
};
More information about the asterisk-commits
mailing list