[svn-commits] mmichelson: branch mmichelson/sip_options r394016 - in /team/mmichelson/sip_o...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Wed Jul 10 15:52:58 CDT 2013


Author: mmichelson
Date: Wed Jul 10 15:52:56 2013
New Revision: 394016

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=394016
Log:
Add timert1 and timerb options.

These options are a bit different from others so far in that they affect how
PJSIP operates rather than how Asterisk operates. These, plus other PJSIP options
need to be set early and then cannot be changed due to a reload. The only way these
could be changed is if res_sip.so is unloaded and the loaded again.

Since these options cannot be reloaded, they need to be handled by a separate sorcery
than the rest of the SIP configuration. I've started by calling the sorcery as well
as the type for this configuration "system". I could have gone with "pjsip" or something
similar, but I think "system" gives us a place to put other non-pjsip related options that
we may introduce that also cannot be affected by reloads.


Added:
    team/mmichelson/sip_options/res/res_sip/config_system.c   (with props)
Modified:
    team/mmichelson/sip_options/res/res_sip.c
    team/mmichelson/sip_options/res/res_sip/include/res_sip_private.h

Modified: team/mmichelson/sip_options/res/res_sip.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/sip_options/res/res_sip.c?view=diff&rev=394016&r1=394015&r2=394016
==============================================================================
--- team/mmichelson/sip_options/res/res_sip.c (original)
+++ team/mmichelson/sip_options/res/res_sip.c Wed Jul 10 15:52:56 2013
@@ -1561,6 +1561,11 @@
 		goto error;
 	}
 
+	if (ast_sip_initialize_system()) {
+		ast_log(LOG_ERROR, "Failed to initialize SIP system configuration. Aborting load\n");
+		goto error;
+	}
+
 	pjsip_tsx_layer_init_module(ast_pjsip_endpoint);
 	pjsip_ua_init_module(ast_pjsip_endpoint, NULL);
 

Added: team/mmichelson/sip_options/res/res_sip/config_system.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/sip_options/res/res_sip/config_system.c?view=auto&rev=394016
==============================================================================
--- team/mmichelson/sip_options/res/res_sip/config_system.c (added)
+++ team/mmichelson/sip_options/res/res_sip/config_system.c Wed Jul 10 15:52:56 2013
@@ -1,0 +1,100 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2013, Digium, Inc.
+ *
+ * Mark Michelson <mmichelson at digium.com>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+#include "asterisk.h"
+
+#include <pjsip.h>
+#include <pjlib.h>
+
+#include "asterisk/res_sip.h"
+#include "asterisk/sorcery.h"
+#include "include/res_sip_private.h"
+
+#define DEFAULT_TIMER_T1 500
+#define DEFAULT_TIMER_B 32000
+
+struct system_config {
+	SORCERY_OBJECT(details);
+	int timert1;
+	int timerb;
+};
+
+static struct ast_sorcery *system_sorcery;
+
+static void *system_alloc(const char *name)
+{
+	struct system_config *system = ast_sorcery_generic_alloc(sizeof(*system), NULL);
+
+	if (!system) {
+		return NULL;
+	}
+
+	return system;
+}
+
+static int system_apply(const struct ast_sorcery *system_sorcery, void *obj)
+{
+	struct system_config *system = obj;
+	int min_timerb;
+
+	if (system->timert1 < DEFAULT_TIMER_T1) {
+		ast_log(LOG_WARNING, "Timer T1 setting is too low. Setting to %d\n", DEFAULT_TIMER_T1);
+		system->timert1 = DEFAULT_TIMER_T1;
+	}
+
+	min_timerb = 64 * system->timert1;
+
+	if (system->timerb < min_timerb) {
+		ast_log(LOG_WARNING, "Timer B setting is too low. Setting to %d\n", min_timerb);
+		system->timerb = min_timerb;
+	}
+
+	pjsip_cfg()->tsx.t1 = system->timert1;
+	pjsip_cfg()->tsx.td = system->timerb;
+
+	return 0;
+}
+
+int ast_sip_initialize_system(void)
+{
+	system_sorcery = ast_sorcery_open();
+	if (!system_sorcery) {
+		ast_log(LOG_ERROR, "Failed to open SIP system sorcery\n");
+		return -1;
+	}
+
+	ast_sorcery_apply_config(system_sorcery, "res_sip");
+
+	ast_sorcery_apply_default(system_sorcery, "system", "config", "res_sip.conf,criteria=type=system");
+
+	if (ast_sorcery_object_register(system_sorcery, "system", system_alloc, NULL, system_apply)) {
+		ast_sorcery_unref(system_sorcery);
+		system_sorcery = NULL;
+		return -1;
+	}
+
+	ast_sorcery_object_field_register(system_sorcery, "system", "type", "", OPT_NOOP_T, 0, 0);
+	ast_sorcery_object_field_register(system_sorcery, "system", "timert1", __stringify(DEFAULT_TIMER_T1),
+			OPT_UINT_T, 0, FLDSET(struct system_config, timert1));
+	ast_sorcery_object_field_register(system_sorcery, "system", "timerb", __stringify(DEFAULT_TIMER_B),
+			OPT_UINT_T, 0, FLDSET(struct system_config, timerb));
+
+	ast_sorcery_load(system_sorcery);
+
+	return 0;
+}

Propchange: team/mmichelson/sip_options/res/res_sip/config_system.c
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: team/mmichelson/sip_options/res/res_sip/config_system.c
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: team/mmichelson/sip_options/res/res_sip/config_system.c
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: team/mmichelson/sip_options/res/res_sip/include/res_sip_private.h
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/sip_options/res/res_sip/include/res_sip_private.h?view=diff&rev=394016&r1=394015&r2=394016
==============================================================================
--- team/mmichelson/sip_options/res/res_sip/include/res_sip_private.h (original)
+++ team/mmichelson/sip_options/res/res_sip/include/res_sip_private.h Wed Jul 10 15:52:56 2013
@@ -55,4 +55,12 @@
  */
 int ast_sip_initialize_outbound_authentication(void);
 
+/*!
+ * \brief Initialize system configuration
+ *
+ * \retval 0 Success
+ * \retval non-zero Failure
+ */
+int ast_sip_initialize_system(void);
+
 #endif /* RES_SIP_PRIVATE_H_ */




More information about the svn-commits mailing list