[Asterisk-code-review] res pjsip pubsub: Treat "prune on boot" as a boolean. (asterisk[13])

Joshua Colp asteriskteam at digium.com
Fri Jul 27 09:51:18 CDT 2018


Joshua Colp has uploaded this change for review. ( https://gerrit.asterisk.org/9744


Change subject: res_pjsip_pubsub: Treat "prune_on_boot" as a boolean.
......................................................................

res_pjsip_pubsub: Treat "prune_on_boot" as a boolean.

The alembic for the PJSIP subscription persistence table has the
"prune_on_boot" field as a boolean. While in Asterisk we are
tolerant of many different definitions of true and false in the
database we only accept "yes" and "no". This change makes the
field treated as a boolean instead of an integer, thus storing
"yes" and "no" instead of "1" and "0".

The OPT_BOOL_T field type can't be used as it stores in string
format as "true" and "false" which is not supported by the Alembic.

Change-Id: Ic8b9211b36babefe78f70def6828a135a6ae7ab6
---
M res/res_pjsip_pubsub.c
1 file changed, 16 insertions(+), 2 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/44/9744/1

diff --git a/res/res_pjsip_pubsub.c b/res/res_pjsip_pubsub.c
index 2f32ebc..c04f4e2 100644
--- a/res/res_pjsip_pubsub.c
+++ b/res/res_pjsip_pubsub.c
@@ -4729,6 +4729,20 @@
 	return (ast_asprintf(buf, "%ld", persistence->expires.tv_sec) < 0) ? -1 : 0;
 }
 
+static int persistence_prune_on_boot_str2int(const struct aco_option *opt, struct ast_variable *var, void *obj)
+{
+	struct subscription_persistence *persistence = obj;
+	persistence->prune_on_boot = ast_true(var->value);
+	return 0;
+}
+
+static int persistence_prune_on_boot_int2str(const void *obj, const intptr_t *args, char **buf)
+{
+	const struct subscription_persistence *persistence = obj;
+	*buf = ast_strdup(persistence->prune_on_boot ? "yes" : "no");
+	return 0;
+}
+
 #define RESOURCE_LIST_INIT_SIZE 4
 
 static void resource_list_destructor(void *obj)
@@ -5589,8 +5603,8 @@
 		persistence_expires_str2struct, persistence_expires_struct2str, NULL, 0, 0);
 	ast_sorcery_object_field_register(sorcery, "subscription_persistence", "contact_uri", "", OPT_CHAR_ARRAY_T, 0,
 		CHARFLDSET(struct subscription_persistence, contact_uri));
-	ast_sorcery_object_field_register(sorcery, "subscription_persistence", "prune_on_boot", "0", OPT_UINT_T, 0,
-		FLDSET(struct subscription_persistence, prune_on_boot));
+	ast_sorcery_object_field_register_custom(sorcery, "subscription_persistence", "prune_on_boot", "no",
+		persistence_prune_on_boot_str2int, persistence_prune_on_boot_int2str, NULL, 0, 0);
 
 	if (apply_list_configuration(sorcery)) {
 		ast_sched_context_destroy(sched);

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

Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic8b9211b36babefe78f70def6828a135a6ae7ab6
Gerrit-Change-Number: 9744
Gerrit-PatchSet: 1
Gerrit-Owner: Joshua Colp <jcolp at digium.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20180727/b7a6a580/attachment.html>


More information about the asterisk-code-review mailing list