[Asterisk-code-review] pjsip: Added "reg server" to contacts. (asterisk[13])

Alexei Gradinari asteriskteam at digium.com
Fri Apr 15 14:28:44 CDT 2016


Alexei Gradinari has uploaded a new change for review.

  https://gerrit.asterisk.org/2624

Change subject: pjsip: Added "reg_server" to contacts.
......................................................................

pjsip: Added "reg_server" to contacts.

If the Asterisk system name is set in asterisk.conf, it will be stored
into the "reg_server" field in the ps_contacts table to facilitate
multi-server setups.

ASTERISK-25931

Change-Id: Ia8f6bd2267809c78753b52bcf21835b9b59f4cb8
---
M CHANGES
A contrib/ast-db-manage/config/versions/81b01a191a46_pjsip_add_contact_reg_server.py
M include/asterisk/res_pjsip.h
M res/res_pjsip.c
M res/res_pjsip/location.c
M res/res_pjsip_registrar.c
6 files changed, 48 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/24/2624/1

diff --git a/CHANGES b/CHANGES
index 382c4a4..ca5b432 100644
--- a/CHANGES
+++ b/CHANGES
@@ -12,6 +12,13 @@
 --- Functionality changes from Asterisk 13.8.0 to Asterisk 13.9.0 ------------
 ------------------------------------------------------------------------------
 
+res_pjsip
+------------------
+ * Added "reg_server" to contacts.
+   If the Asterisk system name is set in asterisk.conf, it will be stored
+   into the "reg_server" field in the ps_contacts table to facilitate
+   multi-server setups.
+
 chan_pjsip
 ------------------
  * Added 'pjsip show channelstats' CLI command.
diff --git a/contrib/ast-db-manage/config/versions/81b01a191a46_pjsip_add_contact_reg_server.py b/contrib/ast-db-manage/config/versions/81b01a191a46_pjsip_add_contact_reg_server.py
new file mode 100644
index 0000000..0453bd2
--- /dev/null
+++ b/contrib/ast-db-manage/config/versions/81b01a191a46_pjsip_add_contact_reg_server.py
@@ -0,0 +1,23 @@
+"""pjsip: add contact reg_server
+
+Revision ID: 81b01a191a46
+Revises: 1c688d9a003c
+Create Date: 2016-04-15 15:00:35.024525
+
+"""
+
+# revision identifiers, used by Alembic.
+revision = '81b01a191a46'
+down_revision = '1c688d9a003c'
+
+from alembic import op
+import sqlalchemy as sa
+
+
+def upgrade():
+    op.add_column('ps_contacts', sa.Column('reg_server', sa.String(20)))
+
+
+def downgrade():
+    with op.batch_alter_table('ps_contacts') as batch_op:
+        batch_op.drop_column('reg_server')
diff --git a/include/asterisk/res_pjsip.h b/include/asterisk/res_pjsip.h
index 3a9d61e..538b268 100644
--- a/include/asterisk/res_pjsip.h
+++ b/include/asterisk/res_pjsip.h
@@ -228,6 +228,8 @@
 		AST_STRING_FIELD(path);
 		/*! Content of the User-Agent header in REGISTER request */
 		AST_STRING_FIELD(user_agent);
+		/*! Asterisk Server name */
+		AST_STRING_FIELD(reg_server);
 	);
 	/*! Absolute time that this contact is no longer valid after */
 	struct timeval expiration_time;
diff --git a/res/res_pjsip.c b/res/res_pjsip.c
index cc86f90..8bdcd63 100644
--- a/res/res_pjsip.c
+++ b/res/res_pjsip.c
@@ -1092,6 +1092,12 @@
 						REGISTER requests and is not intended to be configured manually.
 					</para></description>
 				</configOption>
+				<configOption name="reg_server">
+					<synopsis>Asterisk Server name</synopsis>
+					<description><para>
+						Asterisk Server name on which SIP endpoint registered.
+					</para></description>
+				</configOption>
 			</configObject>
 			<configObject name="aor">
 				<synopsis>The configuration for a location of an endpoint</synopsis>
diff --git a/res/res_pjsip/location.c b/res/res_pjsip/location.c
index 19fa803..cc7501c 100644
--- a/res/res_pjsip/location.c
+++ b/res/res_pjsip/location.c
@@ -23,6 +23,7 @@
 #include "asterisk/res_pjsip.h"
 #include "asterisk/logger.h"
 #include "asterisk/astobj2.h"
+#include "asterisk/paths.h"
 #include "asterisk/sorcery.h"
 #include "include/res_pjsip_private.h"
 #include "asterisk/res_pjsip_cli.h"
@@ -333,6 +334,10 @@
 
 	if (!ast_strlen_zero(user_agent)) {
 		ast_string_field_set(contact, user_agent, user_agent);
+	}
+
+	if (!ast_strlen_zero(ast_config_AST_SYSTEM_NAME)) {
+		ast_string_field_set(contact, reg_server, ast_config_AST_SYSTEM_NAME);
 	}
 
 	contact->endpoint = ao2_bump(endpoint);
@@ -1090,6 +1095,7 @@
 	ast_sorcery_object_field_register(sorcery, "contact", "qualify_timeout", "3.0", OPT_DOUBLE_T, 0, FLDSET(struct ast_sip_contact, qualify_timeout));
 	ast_sorcery_object_field_register(sorcery, "contact", "outbound_proxy", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_contact, outbound_proxy));
 	ast_sorcery_object_field_register(sorcery, "contact", "user_agent", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_contact, user_agent));
+	ast_sorcery_object_field_register(sorcery, "contact", "reg_server", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_contact, reg_server));
 
 	ast_sorcery_object_field_register(sorcery, "aor", "type", "", OPT_NOOP_T, 0, 0);
 	ast_sorcery_object_field_register(sorcery, "aor", "minimum_expiration", "60", OPT_UINT_T, 0, FLDSET(struct ast_sip_aor, minimum_expiration));
diff --git a/res/res_pjsip_registrar.c b/res/res_pjsip_registrar.c
index 7767004..734513b 100644
--- a/res/res_pjsip_registrar.c
+++ b/res/res_pjsip_registrar.c
@@ -30,6 +30,7 @@
 
 #include "asterisk/res_pjsip.h"
 #include "asterisk/module.h"
+#include "asterisk/paths.h"
 #include "asterisk/test.h"
 #include "asterisk/taskprocessor.h"
 #include "asterisk/manager.h"
@@ -555,6 +556,9 @@
 			if (user_agent) {
 				ast_string_field_set(contact_update, user_agent, user_agent);
 			}
+			if (!ast_strlen_zero(ast_config_AST_SYSTEM_NAME)) {
+				ast_string_field_set(contact_update, reg_server, ast_config_AST_SYSTEM_NAME);
+			}
 
 			if (ast_sip_location_update_contact(contact_update)) {
 				ast_log(LOG_ERROR, "Failed to update contact '%s' expiration time to %d seconds.\n",

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia8f6bd2267809c78753b52bcf21835b9b59f4cb8
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-Owner: Alexei Gradinari <alex2grad at gmail.com>



More information about the asterisk-code-review mailing list