summaryrefslogtreecommitdiff
path: root/channels
diff options
context:
space:
mode:
authorWalter Doekes <walter+asterisk@wjd.nu>2016-02-19 11:30:15 +0100
committerWalter Doekes <walter+asterisk@wjd.nu>2016-02-19 11:30:15 +0100
commitc00082329ef405ce2af6aaa8e40ada37de2aeb7b (patch)
treed80cfbb6818414b7d3abeee39b673f836affd6d0 /channels
parent6fc57b3e1f401fd18e3e4d4462f973094dd0908c (diff)
chan_sip: Optionally supply fromuser/fromdomain in SIP dial string.
Previously you could add [!dnid] to the SIP dial string to alter the To: header. This change allows you to alter the From header as well. SIP dial string extra options now look like this: [![touser[@todomain]][![fromuser][@fromdomain]]] INCOMPATIBLE CHANGE: If you were using an exclamation mark in your To: header, that is no longer possible. ASTERISK-25803 #close Change-Id: I2457e9ba7a89eb1da22084bab5a4d4328e189db7
Diffstat (limited to 'channels')
-rw-r--r--channels/chan_sip.c45
1 files changed, 42 insertions, 3 deletions
diff --git a/channels/chan_sip.c b/channels/chan_sip.c
index aaf0b6d51..2e9a6d195 100644
--- a/channels/chan_sip.c
+++ b/channels/chan_sip.c
@@ -29680,7 +29680,8 @@ static int sip_devicestate(const char *data)
* or SIP/devicename/extension/IPorHost
* or SIP/username@domain//IPorHost
* and there is an optional [!dnid] argument you can append to alter the
- * To: header.
+ * To: header. And after that, a [![fromuser][@fromdomain]] argument.
+ * Leave those blank to use the defaults.
* \endverbatim
*/
static struct ast_channel *sip_request_call(const char *type, struct ast_format_cap *cap, const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, const char *dest, int *cause)
@@ -29752,11 +29753,49 @@ static struct ast_channel *sip_request_call(const char *type, struct ast_format_
/* Save the destination, the SIP dial string */
ast_copy_string(tmp, dest, sizeof(tmp));
- /* Find DNID and take it away */
+ /* Find optional DNID (SIP to-uri) and From-CLI (SIP from-uri)
+ * and strip it from the dial string:
+ * [!touser[@todomain][![fromuser][@fromdomain]]]
+ * For historical reasons, the touser@todomain is passed as dnid
+ * while fromuser@fromdomain are split immediately. Passing a
+ * todomain without touser will create an invalid SIP message. */
dnid = strchr(tmp, '!');
if (dnid != NULL) {
+ char *fromuser_and_domain;
+
*dnid++ = '\0';
- ast_string_field_set(p, todnid, dnid);
+ if ((fromuser_and_domain = strchr(dnid, '!'))) {
+ char *forward_compat;
+ char *fromdomain;
+
+ *fromuser_and_domain++ = '\0';
+
+ /* Cut it at a trailing NUL or trailing '!' for
+ * forward compatibility with extra arguments
+ * in the future. */
+ if ((forward_compat = strchr(fromuser_and_domain, '!'))) {
+ /* Ignore the rest.. */
+ *forward_compat = '\0';
+ }
+
+ if ((fromdomain = strchr(fromuser_and_domain, '@'))) {
+ *fromdomain++ = '\0';
+ /* Set fromdomain. */
+ if (!ast_strlen_zero(fromdomain)) {
+ ast_string_field_set(p, fromdomain, fromdomain);
+ }
+ }
+
+ /* Set fromuser. */
+ if (!ast_strlen_zero(fromuser_and_domain)) {
+ ast_string_field_set(p, fromuser, fromuser_and_domain);
+ }
+ }
+
+ /* Set DNID (touser/todomain). */
+ if (!ast_strlen_zero(dnid)) {
+ ast_string_field_set(p, todnid, dnid);
+ }
}
/* Divvy up the items separated by slashes */