[Asterisk-code-review] Fix Alembic upgrades. (asterisk[13])

Mark Michelson asteriskteam at digium.com
Wed Jun 22 10:42:28 CDT 2016


Mark Michelson has uploaded a new change for review.

  https://gerrit.asterisk.org/3070

Change subject: Fix Alembic upgrades.
......................................................................

Fix Alembic upgrades.

A non-existent constraint was being referenced in the upgrade script.
This patch corrects the problem by removing the reference.

This patch fixes another realtime problem as well. Our Alembic scripts
store booleans as yes or no values. However, Sorcery tries to insert
"true" or "false" instead. This patch updates Sorcery to use "yes" and
"no"

ASTERISK-26128 #close

Change-Id: I366dbbf91418a9cb160b3ca74b0e59b5ac284bec

asljkdf;jas

Change-Id: I2e6cf770bbe5d56d609e3108a0a876f22b49e971
---
M contrib/ast-db-manage/config/versions/81b01a191a46_pjsip_add_contact_reg_server.py
M include/asterisk/config_options.h
M main/config_options.c
M main/sorcery.c
M res/res_pjsip/location.c
5 files changed, 32 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/70/3070/1

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
index 0318b9a..0919370 100644
--- 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
@@ -16,10 +16,8 @@
 
 def upgrade():
     op.add_column('ps_contacts', sa.Column('reg_server', sa.String(20)))
-    op.drop_constraint('id', 'ps_contacts', type_='unique')
     op.create_unique_constraint('ps_contacts_uq', 'ps_contacts', ['id','reg_server'])
 
 def downgrade():
     op.drop_constraint('ps_contacts_uq', 'ps_contacts', type_='unique')
     op.drop_column('ps_contacts', 'reg_server')
-    op.create_unique_constraint(None, 'ps_contacts', 'id')
diff --git a/include/asterisk/config_options.h b/include/asterisk/config_options.h
index 30c0421..1ebebc6 100644
--- a/include/asterisk/config_options.h
+++ b/include/asterisk/config_options.h
@@ -281,6 +281,28 @@
 	 */
 	OPT_BOOL_T,
 
+	/*! \brief Type for default option handler for bools (ast_true/ast_false)
+	 * \note aco_option_register flags:
+	 *   non-zero : process via ast_true
+	 *   0        : process via ast_false
+	 * aco_option_register varargs:
+	 *   FLDSET macro with the field of type int. It is important to note that the field
+	 *   cannot be a bitfield. If bitfields are required, they must be set via a custom handler.
+	 *
+	 * This is nearly exactly the same as OPT_BOOL_T. The only difference is that when
+	 * translated to a string, OPT_BOOL_T becomes "true" or "false"; OPT_YESNO_T becomes
+	 * "yes" or "no".
+	 *
+	 * Example:
+	 * {code}
+	 * struct test_item {
+	 *     int enabled;
+	 * };
+	 * aco_option_register(&cfg_info, "enabled", ACO_EXACT, my_types, "no", OPT_YESNO_T, 1, FLDSET(struct test_item, enabled));
+	 * {endcode}
+	 */
+	OPT_YESNO_T,
+
 	/*! \brief Type for default option handler for bools (ast_true/ast_false) that are stored in a flag
 	 * \note aco_option_register flags:
 	 *   non-zero : process via ast_true
diff --git a/main/config_options.c b/main/config_options.c
index c8988c9..34eace6 100644
--- a/main/config_options.c
+++ b/main/config_options.c
@@ -87,6 +87,7 @@
 static char *aco_option_type_string[] = {
 	"ACL",				/* OPT_ACL_T, */
 	"Boolean",			/* OPT_BOOL_T, */
+	"Boolean",			/* OPT_YESNO_T, */
 	"Boolean",			/* OPT_BOOLFLAG_T, */
 	"String",			/* OPT_CHAR_ARRAY_T, */
 	"Codec",			/* OPT_CODEC_T, */
@@ -139,6 +140,7 @@
 	switch(type) {
 	case OPT_ACL_T: return acl_handler_fn;
 	case OPT_BOOL_T: return bool_handler_fn;
+	case OPT_YESNO_T: return bool_handler_fn;
 	case OPT_BOOLFLAG_T: return boolflag_handler_fn;
 	case OPT_CHAR_ARRAY_T: return chararray_handler_fn;
 	case OPT_CODEC_T: return codec_handler_fn;
diff --git a/main/sorcery.c b/main/sorcery.c
index 4dedc4d..bfc7688 100644
--- a/main/sorcery.c
+++ b/main/sorcery.c
@@ -290,6 +290,12 @@
 	return !(*buf = ast_strdup(*field ? "true" : "false")) ? -1 : 0;
 }
 
+static int yesno_handler_fn(const void *obj, const intptr_t *args, char **buf)
+{
+	unsigned int *field = (unsigned int *)(obj + args[0]);
+	return !(*buf = ast_strdup(*field ? "yes" : "no")) ? -1 : 0;
+}
+
 static int sockaddr_handler_fn(const void *obj, const intptr_t *args, char **buf)
 {
 	struct ast_sockaddr *field = (struct ast_sockaddr *)(obj + args[0]);
@@ -313,6 +319,7 @@
 {
 	switch(type) {
 	case OPT_BOOL_T: return bool_handler_fn;
+	case OPT_YESNO_T: return yesno_handler_fn;
 	case OPT_CHAR_ARRAY_T: return chararray_handler_fn;
 	case OPT_CODEC_T: return codec_handler_fn;
 	case OPT_DOUBLE_T: return double_handler_fn;
diff --git a/res/res_pjsip/location.c b/res/res_pjsip/location.c
index bf08d8e..f02a72c 100644
--- a/res/res_pjsip/location.c
+++ b/res/res_pjsip/location.c
@@ -1138,7 +1138,7 @@
 	ast_sorcery_object_field_register(sorcery, "contact", "qualify_frequency", 0, OPT_UINT_T,
 		PARSE_IN_RANGE, FLDSET(struct ast_sip_contact, qualify_frequency), 0, 86400);
 	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", "authenticate_qualify", "no", OPT_BOOL_T, 1, FLDSET(struct ast_sip_contact, authenticate_qualify));
+	ast_sorcery_object_field_register(sorcery, "contact", "authenticate_qualify", "no", OPT_YESNO_T, 1, FLDSET(struct ast_sip_contact, authenticate_qualify));
 	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));

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I2e6cf770bbe5d56d609e3108a0a876f22b49e971
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-Owner: Mark Michelson <mmichelson at digium.com>



More information about the asterisk-code-review mailing list