[Asterisk-code-review] res pjsip: Fix mwi subscribe replaces unsolicited type mismatch (asterisk[15])

George Joseph asteriskteam at digium.com
Wed Sep 5 09:55:32 CDT 2018


George Joseph has submitted this change and it was merged. ( https://gerrit.asterisk.org/9840 )

Change subject: res_pjsip: Fix mwi_subscribe_replaces_unsolicited type mismatch
......................................................................

res_pjsip: Fix mwi_subscribe_replaces_unsolicited type mismatch

ASTERISK-27988

Change-Id: Iccafdd0552ea8aaed647620fb14499f1bf341843
---
A contrib/ast-db-manage/config/versions/fe6592859b85_fix_mwi_subscribe_replaces_.py
M res/res_pjsip/pjsip_configuration.c
2 files changed, 62 insertions(+), 1 deletion(-)

Approvals:
  Kevin Harwell: Looks good to me, but someone else must approve
  Joshua Colp: Looks good to me, approved
  George Joseph: Approved for Submit



diff --git a/contrib/ast-db-manage/config/versions/fe6592859b85_fix_mwi_subscribe_replaces_.py b/contrib/ast-db-manage/config/versions/fe6592859b85_fix_mwi_subscribe_replaces_.py
new file mode 100644
index 0000000..4ecaaf7
--- /dev/null
+++ b/contrib/ast-db-manage/config/versions/fe6592859b85_fix_mwi_subscribe_replaces_.py
@@ -0,0 +1,61 @@
+"""Fix mwi_subscribe_replaces_unsolicited
+
+Revision ID: fe6592859b85
+Revises: 19b00bc19b7b
+Create Date: 2018-08-06 15:50:44.405534
+
+"""
+
+# revision identifiers, used by Alembic.
+revision = 'fe6592859b85'
+down_revision = '1d3ed26d9978'
+
+from alembic import op
+import sqlalchemy as sa
+from sqlalchemy.dialects.postgresql import ENUM
+
+AST_BOOL_NAME = 'ast_bool_values'
+# We'll just ignore the n/y and f/t abbreviations as Asterisk does not write
+# those aliases.
+AST_BOOL_VALUES = [ '0', '1',
+                    'off', 'on',
+                    'false', 'true',
+                    'no', 'yes' ]
+
+
+def upgrade():
+    # Create the new enum
+    ast_bool_values = ENUM(*AST_BOOL_VALUES, name=AST_BOOL_NAME, create_type=False)
+    if op.get_context().bind.dialect.name == 'postgresql':
+        ast_bool_values.create(op.get_bind(), checkfirst=False)
+
+    # There is no direct way to convert from Integer to ENUM that is
+    # not database specific so we transition through a string type.
+    op.alter_column('ps_endpoints', 'mwi_subscribe_replaces_unsolicited',
+                    type_=sa.String(5))
+    op.alter_column('ps_endpoints', 'mwi_subscribe_replaces_unsolicited',
+                    type_=ast_bool_values)
+
+
+def downgrade():
+    # First we need to ensure the column is using only the 'numeric' bool enum values.
+    op.execute("UPDATE ps_endpoints SET mwi_subscribe_replaces_unsolicited='0'"
+               " WHERE mwi_subscribe_replaces_unsolicited='off'"
+               "  OR mwi_subscribe_replaces_unsolicited='false'"
+               "  OR mwi_subscribe_replaces_unsolicited='no'")
+    op.execute("UPDATE ps_endpoints SET mwi_subscribe_replaces_unsolicited='1'"
+               " WHERE mwi_subscribe_replaces_unsolicited='on'"
+               "  OR mwi_subscribe_replaces_unsolicited='true'"
+               "  OR mwi_subscribe_replaces_unsolicited='yes'")
+
+    # There is no direct way to convert from ENUM to Integer that is
+    # not database specific so we transition through a string type.
+    if op.get_context().bind.dialect.name == 'mssql':
+        op.drop_constraint('ck_ps_endpoints_mwi_subscribe_replaces_unsolicited_ast_bool_values', 'ps_endpoints')
+    op.alter_column('ps_endpoints', 'mwi_subscribe_replaces_unsolicited',
+                    type_=sa.String(5))
+    op.alter_column('ps_endpoints', 'mwi_subscribe_replaces_unsolicited',
+                    type_=sa.Integer)
+
+    if op.get_context().bind.dialect.name == 'postgresql':
+        ENUM(name=AST_BOOL_NAME).drop(op.get_bind(), checkfirst=False)
diff --git a/res/res_pjsip/pjsip_configuration.c b/res/res_pjsip/pjsip_configuration.c
index aad4cfc..02d186e 100644
--- a/res/res_pjsip/pjsip_configuration.c
+++ b/res/res_pjsip/pjsip_configuration.c
@@ -1825,7 +1825,7 @@
 	ast_sorcery_object_field_register(sip_sorcery, "endpoint", "mailboxes", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_endpoint, subscription.mwi.mailboxes));
 	ast_sorcery_object_field_register_custom(sip_sorcery, "endpoint", "voicemail_extension", "", voicemail_extension_handler, voicemail_extension_to_str, NULL, 0, 0);
 	ast_sorcery_object_field_register(sip_sorcery, "endpoint", "aggregate_mwi", "yes", OPT_BOOL_T, 1, FLDSET(struct ast_sip_endpoint, subscription.mwi.aggregate));
-	ast_sorcery_object_field_register(sip_sorcery, "endpoint", "mwi_subscribe_replaces_unsolicited", "no", OPT_BOOL_T, 1, FLDSET(struct ast_sip_endpoint, subscription.mwi.subscribe_replaces_unsolicited));
+	ast_sorcery_object_field_register(sip_sorcery, "endpoint", "mwi_subscribe_replaces_unsolicited", "no", OPT_YESNO_T, 1, FLDSET(struct ast_sip_endpoint, subscription.mwi.subscribe_replaces_unsolicited));
 	ast_sorcery_object_field_register_custom(sip_sorcery, "endpoint", "media_encryption", "no", media_encryption_handler, media_encryption_to_str, NULL, 0, 0);
 	ast_sorcery_object_field_register(sip_sorcery, "endpoint", "use_avpf", "no", OPT_BOOL_T, 1, FLDSET(struct ast_sip_endpoint, media.rtp.use_avpf));
 	ast_sorcery_object_field_register(sip_sorcery, "endpoint", "force_avp", "no", OPT_BOOL_T, 1, FLDSET(struct ast_sip_endpoint, media.rtp.force_avp));

-- 
To view, visit https://gerrit.asterisk.org/9840
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 15
Gerrit-MessageType: merged
Gerrit-Change-Id: Iccafdd0552ea8aaed647620fb14499f1bf341843
Gerrit-Change-Number: 9840
Gerrit-PatchSet: 3
Gerrit-Owner: Richard Mudgett <rmudgett at digium.com>
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Jenkins2
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>
Gerrit-Reviewer: Richard Mudgett <rmudgett at digium.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20180905/7be39361/attachment-0001.html>


More information about the asterisk-code-review mailing list