summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Jordan <mjordan@digium.com>2014-07-16 14:03:51 +0000
committerMatthew Jordan <mjordan@digium.com>2014-07-16 14:03:51 +0000
commitfd94fea5996a0f8074de1c470337a8d5c25fff38 (patch)
treecd8d0f4bc6036c44f6dd69a0feccfa7550ec83da
parent03e9c598e5fe2274e0e171519c5ac52738c65b14 (diff)
res_pjsip: Support setting a default accountcode on endpoints
Most channel drivers let you specify a default accountcode to be set on channels associated with a particular peer/endpoint/object. Prior to this patch, chan_pjsip/res_pjsip did not support such a setting. This patch adds a new setting to the res_pjsip endpoint object, 'accountcode'. When a channel is created that is associated with an endpoint with this value set, the channel will automatically have its accountcode property set to the value configured for the endpoint. Review: https://reviewboard.asterisk.org/r/3724/ ASTERISK-24000 #close Reported by: Matt Jordan ........ Merged revisions 418756 from http://svn.asterisk.org/svn/asterisk/branches/12 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@418757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
-rw-r--r--CHANGES11
-rw-r--r--channels/chan_pjsip.c8
-rw-r--r--configs/pjsip.conf.sample2
-rw-r--r--contrib/ast-db-manage/config/versions/1d50859ed02e_create_accountcode.py20
-rw-r--r--include/asterisk/res_pjsip.h2
-rw-r--r--res/res_pjsip.c7
-rw-r--r--res/res_pjsip/pjsip_configuration.c1
7 files changed, 49 insertions, 2 deletions
diff --git a/CHANGES b/CHANGES
index ef2ff2200..7fcd913de 100644
--- a/CHANGES
+++ b/CHANGES
@@ -179,6 +179,17 @@ res_config_pgsql
res_pgsql.conf.
------------------------------------------------------------------------------
+--- Functionality changes from Asterisk 12.4.0 to Asterisk 12.5.0 ------------
+------------------------------------------------------------------------------
+
+res_pjsip
+------------------
+ * The endpoint configuration object now supports 'accountcode'. Any channel
+ created for an endpoint with this setting will have its accountcode set
+ to the specified value.
+
+
+------------------------------------------------------------------------------
--- Functionality changes from Asterisk 12.3.0 to Asterisk 12.4.0 ------------
------------------------------------------------------------------------------
diff --git a/channels/chan_pjsip.c b/channels/chan_pjsip.c
index e55c48835..695211480 100644
--- a/channels/chan_pjsip.c
+++ b/channels/chan_pjsip.c
@@ -364,8 +364,12 @@ static struct ast_channel *chan_pjsip_new(struct ast_sip_session *session, int s
return NULL;
}
- if (!(chan = ast_channel_alloc(1, state, S_OR(session->id.number.str, ""), S_OR(session->id.name.str, ""), "", "", "", assignedids, requestor, 0, "PJSIP/%s-%08x", ast_sorcery_object_get_id(session->endpoint),
- (unsigned)ast_atomic_fetchadd_int((int *)&chan_idx, +1)))) {
+
+ chan = ast_channel_alloc(1, state, S_OR(session->id.number.str, ""), S_OR(session->id.name.str, ""),
+ session->endpoint->accountcode, "", "", assignedids,
+ requestor, 0, "PJSIP/%s-%08x", ast_sorcery_object_get_id(session->endpoint),
+ (unsigned)ast_atomic_fetchadd_int((int *)&chan_idx, +1));
+ if (!chan) {
return NULL;
}
diff --git a/configs/pjsip.conf.sample b/configs/pjsip.conf.sample
index 3aa05a96b..58774dc7c 100644
--- a/configs/pjsip.conf.sample
+++ b/configs/pjsip.conf.sample
@@ -435,6 +435,8 @@
; SYNOPSIS: Endpoint
;100rel=yes ; Allow support for RFC3262 provisional ACK tags (default:
; "yes")
+;accountcode=foo ; Set a default account code for channels created for
+ ; this endpoint
;aggregate_mwi=yes ; (default: "yes")
;allow= ; Media Codec s to allow (default: "")
;aors= ; AoR s to be used with the endpoint (default: "")
diff --git a/contrib/ast-db-manage/config/versions/1d50859ed02e_create_accountcode.py b/contrib/ast-db-manage/config/versions/1d50859ed02e_create_accountcode.py
new file mode 100644
index 000000000..eb2000137
--- /dev/null
+++ b/contrib/ast-db-manage/config/versions/1d50859ed02e_create_accountcode.py
@@ -0,0 +1,20 @@
+"""create accountcode
+
+Revision ID: 1d50859ed02e
+Revises: 51f8cb66540e
+Create Date: 2014-07-07 21:07:01.661783
+
+"""
+
+# revision identifiers, used by Alembic.
+revision = '1d50859ed02e'
+down_revision = '51f8cb66540e'
+
+from alembic import op
+import sqlalchemy as sa
+
+def upgrade():
+ op.add_column('ps_endpoints', sa.Column('accountcode', sa.String(20)))
+
+def downgrade():
+ op.drop_column('ps_endpoints', 'accountcode')
diff --git a/include/asterisk/res_pjsip.h b/include/asterisk/res_pjsip.h
index f5518c0e6..d569710e0 100644
--- a/include/asterisk/res_pjsip.h
+++ b/include/asterisk/res_pjsip.h
@@ -570,6 +570,8 @@ struct ast_sip_endpoint {
AST_STRING_FIELD(fromdomain);
/*! Context to route incoming MESSAGE requests to */
AST_STRING_FIELD(message_context);
+ /*! Accountcode to auto-set on channels */
+ AST_STRING_FIELD(accountcode);
);
/*! Configuration for extensions */
struct ast_sip_endpoint_extensions extensions;
diff --git a/res/res_pjsip.c b/res/res_pjsip.c
index b123a3706..2c15a798d 100644
--- a/res/res_pjsip.c
+++ b/res/res_pjsip.c
@@ -715,6 +715,13 @@
specified, then the <replaceable>context</replaceable> setting is used.
</para></description>
</configOption>
+ <configOption name="accountcode">
+ <synopsis>An accountcode to set automatically on any channels created for this endpoint.</synopsis>
+ <description><para>
+ If specified, any channel created for this endpoint will automatically
+ have this accountcode set on it.
+ </para></description>
+ </configOption>
</configObject>
<configObject name="auth">
<synopsis>Authentication type</synopsis>
diff --git a/res/res_pjsip/pjsip_configuration.c b/res/res_pjsip/pjsip_configuration.c
index ccd494932..59db4eb1e 100644
--- a/res/res_pjsip/pjsip_configuration.c
+++ b/res/res_pjsip/pjsip_configuration.c
@@ -1730,6 +1730,7 @@ int ast_res_pjsip_initialize_configuration(const struct ast_module_info *ast_mod
ast_sorcery_object_field_register_custom(sip_sorcery, "endpoint", "redirect_method", "user", redirect_handler, NULL, NULL, 0, 0);
ast_sorcery_object_field_register_custom(sip_sorcery, "endpoint", "set_var", "", set_var_handler, set_var_to_str, set_var_to_vl, 0, 0);
ast_sorcery_object_field_register(sip_sorcery, "endpoint", "message_context", "", OPT_STRINGFIELD_T, 1, STRFLDSET(struct ast_sip_endpoint, message_context));
+ ast_sorcery_object_field_register(sip_sorcery, "endpoint", "accountcode", "", OPT_STRINGFIELD_T, 1, STRFLDSET(struct ast_sip_endpoint, accountcode));
if (ast_sip_initialize_sorcery_transport()) {
ast_log(LOG_ERROR, "Failed to register SIP transport support with sorcery\n");