[asterisk-commits] res pjsip: Change default from user value. (asterisk[13])

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Sat Sep 5 15:57:07 CDT 2015


Joshua Colp has submitted this change and it was merged.

Change subject: res_pjsip: Change default from user value.
......................................................................


res_pjsip: Change default from user value.

When Asterisk sends an outbound SIP request, if there is no direct
reason to place a specific value for the username in the From header,
Asterisk would generate a UUID. For example, this would happen when
sending outbound OPTIONS requests when qualifying or when sending
outbound INVITE requests when originating (if no explicit caller ID were
provided). The issue is that some SIP providers reject these sorts of
requests with a "Name too long" error response.

This patch aims to fix this by changing the default outbound username in
>From headers to "asterisk". This value can be overridden by changing the
default_from_user option in the global options if desired.

ASTERISK-25377 #close
Reported by Mark Michelson

Change-Id: I6a4d34a56ff73ff4f661b0075aeba5461b7f3190
---
A contrib/ast-db-manage/config/versions/154177371065_add_default_from_user.py
M include/asterisk/res_pjsip.h
M res/res_pjsip.c
M res/res_pjsip/config_global.c
4 files changed, 60 insertions(+), 2 deletions(-)

Approvals:
  Anonymous Coward #1000019: Verified
  Matt Jordan: Looks good to me, but someone else must approve
  Joshua Colp: Looks good to me, approved



diff --git a/contrib/ast-db-manage/config/versions/154177371065_add_default_from_user.py b/contrib/ast-db-manage/config/versions/154177371065_add_default_from_user.py
new file mode 100644
index 0000000..7e6cf99
--- /dev/null
+++ b/contrib/ast-db-manage/config/versions/154177371065_add_default_from_user.py
@@ -0,0 +1,22 @@
+"""add default_from_user
+
+Revision ID: 154177371065
+Revises: 26f10cadc157
+Create Date: 2015-09-04 14:13:59.195013
+
+"""
+
+# revision identifiers, used by Alembic.
+revision = '154177371065'
+down_revision = '26f10cadc157'
+
+from alembic import op
+import sqlalchemy as sa
+
+
+def upgrade():
+    op.add_column('ps_globals', sa.Column('default_from_user', sa.String(80)))
+
+
+def downgrade():
+    op.drop_column('ps_globals', 'default_from_user')
diff --git a/include/asterisk/res_pjsip.h b/include/asterisk/res_pjsip.h
index d1bf388..4f3fadc 100644
--- a/include/asterisk/res_pjsip.h
+++ b/include/asterisk/res_pjsip.h
@@ -2039,6 +2039,17 @@
  */
 char *ast_sip_get_endpoint_identifier_order(void);
 
+/*!
+ * \brief Retrieve the global default from user.
+ *
+ * This is the value placed in outbound requests' From header if there
+ * is no better option (such as an endpoint-configured from_user or
+ * caller ID number).
+ *
+ * \retval The global default_from_user value.
+ */
+const char *ast_sip_get_default_from_user(void);
+
 /*! \brief Determines whether the res_pjsip module is loaded */
 #define CHECK_PJSIP_MODULE_LOADED()				\
 	do {							\
diff --git a/res/res_pjsip.c b/res/res_pjsip.c
index 19f8b59..7afcb70 100644
--- a/res/res_pjsip.c
+++ b/res/res_pjsip.c
@@ -1283,6 +1283,11 @@
                                         Identifier names are usually derived from and can be found in the endpoint
                                         identifier module itself (res_pjsip_endpoint_identifier_*)</synopsis>
 				</configOption>
+				<configOption name="default_from_user" default="asterisk">
+					<synopsis>When Asterisk generates an outgoing SIP request, the From header username will be
+                                        set to this value if there is no better option (such as CallerID) to be
+                                        used.</synopsis>
+				</configOption>
 			</configObject>
 		</configFile>
 	</configInfo>
@@ -2337,10 +2342,9 @@
 	pjsip_sip_uri *sip_uri;
 	pjsip_transport_type_e type = PJSIP_TRANSPORT_UNSPECIFIED;
 	int local_port;
-	char uuid_str[AST_UUID_STR_LEN];
 
 	if (ast_strlen_zero(user)) {
-		user = ast_uuid_generate_str(uuid_str, sizeof(uuid_str));
+		user = ast_sip_get_default_from_user();
 	}
 
 	/* Parse the provided target URI so we can determine what transport it will end up using */
diff --git a/res/res_pjsip/config_global.c b/res/res_pjsip/config_global.c
index 42ba234..b348896 100644
--- a/res/res_pjsip/config_global.c
+++ b/res/res_pjsip/config_global.c
@@ -34,6 +34,7 @@
 #define DEFAULT_DEBUG "no"
 #define DEFAULT_ENDPOINT_IDENTIFIER_ORDER "ip,username,anonymous"
 #define DEFAULT_MAX_INITIAL_QUALIFY_TIME 0
+#define DEFAULT_FROM_USER "asterisk"
 
 static char default_useragent[256];
 
@@ -46,6 +47,8 @@
 		AST_STRING_FIELD(debug);
 		/*! Order by which endpoint identifiers are checked (comma separated list) */
 		AST_STRING_FIELD(endpoint_identifier_order);
+		/*! User name to place in From header if there is no better option */
+		AST_STRING_FIELD(default_from_user);
 	);
 	/* Value to put in Max-Forwards header */
 	unsigned int max_forwards;
@@ -179,6 +182,22 @@
 	return time;
 }
 
+const char *ast_sip_get_default_from_user(void)
+{
+	const char *from_user;
+	struct global_config *cfg;
+
+	cfg = get_global_cfg();
+	if (!cfg) {
+		return DEFAULT_FROM_USER;
+	}
+
+	from_user = cfg->default_from_user;
+	ao2_ref(cfg, -1);
+
+	return from_user;
+}
+
 /*!
  * \internal
  * \brief Observer to set default global object if none exist.
@@ -292,6 +311,8 @@
 	ast_sorcery_object_field_register(sorcery, "global", "max_initial_qualify_time",
 		__stringify(DEFAULT_MAX_INITIAL_QUALIFY_TIME),
 		OPT_UINT_T, 0, FLDSET(struct global_config, max_initial_qualify_time));
+	ast_sorcery_object_field_register(sorcery, "global", "default_from_user", DEFAULT_FROM_USER,
+		OPT_STRINGFIELD_T, 0, STRFLDSET(struct global_config, default_from_user));
 
 	if (ast_sorcery_instance_observer_add(sorcery, &observer_callbacks_global)) {
 		return -1;

-- 
To view, visit https://gerrit.asterisk.org/1198
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I6a4d34a56ff73ff4f661b0075aeba5461b7f3190
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-Owner: Mark Michelson <mmichelson at digium.com>
Gerrit-Reviewer: Anonymous Coward #1000019
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Matt Jordan <mjordan at digium.com>



More information about the asterisk-commits mailing list