[svn-commits] mmichelson: branch mmichelson/rls-config r416659 - /team/mmichelson/rls-confi...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Wed Jun 18 17:44:13 CDT 2014


Author: mmichelson
Date: Wed Jun 18 17:44:10 2014
New Revision: 416659

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=416659
Log:
Implement list configuration logic.


Modified:
    team/mmichelson/rls-config/res/res_pjsip_pubsub.c

Modified: team/mmichelson/rls-config/res/res_pjsip_pubsub.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/rls-config/res/res_pjsip_pubsub.c?view=diff&rev=416659&r1=416658&r2=416659
==============================================================================
--- team/mmichelson/rls-config/res/res_pjsip_pubsub.c (original)
+++ team/mmichelson/rls-config/res/res_pjsip_pubsub.c Wed Jun 18 17:44:10 2014
@@ -257,6 +257,20 @@
 };
 
 /*!
+ * \brief Resource list configuration item
+ */
+struct resource_list {
+	/*! SIP event package the list uses. */
+	char event[32];
+	/*! Strings representing resources in the list. */
+	AST_VECTOR(, const char *) items;
+	/*! Indicates if Asterisk sends full or partial state on notifications. */
+	unsigned int full_state;
+	/*! Time, in milliseconds Asterisk waits before sending a batched notification.*/
+	unsigned int notification_batch_interval;
+};
+
+/*!
  * Used to create new entity IDs by ESCs.
  */
 static int esc_etag_counter;
@@ -1914,6 +1928,79 @@
 	return (ast_asprintf(buf, "%ld", persistence->expires.tv_sec) < 0) ? -1 : 0;
 }
 
+#define RESOURCE_LIST_INIT_SIZE 4
+
+static void resource_list_destructor(void *obj)
+{
+	struct resource_list *list = obj;
+
+	AST_VECTOR_FREE(&list->items);
+}
+
+static void *resource_list_alloc(const char *name)
+{
+	struct resource_list *list;
+	
+	list = ast_sorcery_generic_alloc(sizeof(*list), resource_list_destructor);
+	if (!list) {
+		return NULL;
+	}
+
+	if (AST_VECTOR_INIT(&list->items, RESOURCE_LIST_INIT_SIZE)) {
+		ao2_cleanup(list);
+		return NULL;
+	}
+
+	return list;
+}
+
+static int list_item_handler(const struct aco_option *opt,
+		struct ast_variable *var, void *obj)
+{
+	struct resource_list *list = obj;
+
+	return AST_VECTOR_APPEND(&list->items, var->value);
+}
+
+static int list_item_to_str(const void *obj, const intptr_t *args, char **buf)
+{
+	const struct resource_list *list = obj;
+	int i;
+	struct ast_str *str = ast_str_create(32);
+
+	for (i = 0; i < AST_VECTOR_SIZE(&list->items); ++i) {
+		ast_str_append(&str, 0, "%s,", AST_VECTOR_GET(&list->items, i));
+	}
+
+	/* Chop off trailing comma */
+	ast_str_truncate(str, -1);
+	*buf = ast_strdup(ast_str_buffer(str));
+	return 0;
+}
+
+static int apply_list_configuration(struct ast_sorcery *sorcery)
+{
+	ast_sorcery_apply_default(sorcery, "resource_list", "config",
+			"pjsip.conf,criteria=type=resource_list");
+	if (ast_sorcery_object_register(sorcery, "resource_list", resource_list_alloc,
+				NULL, NULL)) {
+		return -1;
+	}
+
+	ast_sorcery_object_field_register(sorcery, "resource_list", "type", "",
+			OPT_NOOP_T, 0, 0);
+	ast_sorcery_object_field_register(sorcery, "resource_list", "event", "",
+			OPT_CHAR_ARRAY_T, 0, CHARFLDSET(struct resource_list, event));
+	ast_sorcery_object_field_register(sorcery, "resource_list", "full_state", "0",
+			OPT_UINT_T, 0, FLDSET(struct resource_list, full_state));
+	ast_sorcery_object_field_register(sorcery, "resource_list", "notification_batch_interval",
+			"0", OPT_UINT_T, 0, FLDSET(struct resource_list, notification_batch_interval));
+	ast_sorcery_object_field_register_custom(sorcery, "resource_list", "list_item",
+			"", list_item_handler, list_item_to_str, NULL, 0, 0);
+
+	return 0;
+}
+
 static int load_module(void)
 {
 	static const pj_str_t str_PUBLISH = { "PUBLISH", 7 };
@@ -1970,6 +2057,11 @@
 	ast_sorcery_object_field_register_custom(sorcery, "subscription_persistence", "expires", "",
 		persistence_expires_str2struct, persistence_expires_struct2str, NULL, 0, 0);
 
+	if (apply_list_configuration(sorcery)) {
+		ast_sip_unregister_service(&pubsub_module);
+		ast_sched_context_destroy(sched);
+	}
+
 	if (ast_test_flag(&ast_options, AST_OPT_FLAG_FULLY_BOOTED)) {
 		ast_sip_push_task(NULL, subscription_persistence_load, NULL);
 	} else {




More information about the svn-commits mailing list