[asterisk-commits] mmichelson: branch group/CCSS r213044 - /team/group/CCSS/main/ccss.c
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Wed Aug 19 09:14:33 CDT 2009
Author: mmichelson
Date: Wed Aug 19 09:14:29 2009
New Revision: 213044
URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=213044
Log:
Adding main/ccss.c to version control. Must have slipped my mind yesterday.
Added:
team/group/CCSS/main/ccss.c (with props)
Added: team/group/CCSS/main/ccss.c
URL: http://svn.asterisk.org/svn-view/asterisk/team/group/CCSS/main/ccss.c?view=auto&rev=213044
==============================================================================
--- team/group/CCSS/main/ccss.c (added)
+++ team/group/CCSS/main/ccss.c Wed Aug 19 09:14:29 2009
@@ -1,0 +1,284 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 1999 - 2009, 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.
+ */
+
+/*! \file
+ * \brief Call Completion Supplementary Services implementation
+ * \author Mark Michelson <mmichelson at digium.com>
+ */
+
+/*!
+ * \since 1.6.4
+ * \brief A structure for holding the configuration parameters
+ * relating to CCSS
+ */
+
+#include "asterisk.h"
+#include "asterisk/strings.h"
+#include "asterisk/ccss.h"
+#include "asterisk/channel.h"
+
+struct ast_cc_config_params {
+ enum ast_cc_agent_policies cc_agent_policy;
+ enum ast_cc_monitor_policies cc_monitor_policy;
+ unsigned int cc_offer_timer;
+ unsigned int ccnr_available_timer;
+ unsigned int ccbs_available_timer;
+ unsigned int cc_max_agents;
+ unsigned int cc_max_monitors;
+ /*XXX callback_macro only applies to generic agents. Should this
+ * be part of the generic agent's private_data field? My initial
+ * thinking is no, since it makes sense that someone might wish
+ * to modify this the same way that they would modify any other
+ * CCSS configuration value. If someone sets a callback_macro and
+ * we use a native CCSS agent, then we'll just ignore the param...
+ */
+ char cc_callback_macro[AST_MAX_EXTENSION];
+};
+
+/* XXX I'm making these defaults up right now with no real regard for
+ * what they *should* be. This can be revisited.
+ */
+static const unsigned int CC_OFFER_TIMER_DEFAULT = 20u;
+static const unsigned int CCNR_AVAILABLE_TIMER_DEFAULT = 7200u;
+static const unsigned int CCBS_AVAILABLE_TIMER_DEFAULT = 4800u;
+static const unsigned int CC_MAX_AGENTS_DEFAULT = 5u;
+static const unsigned int CC_MAX_MONITORS_DEFAULT = 5u;
+
+struct ast_cc_config_params *ast_cc_config_params_init(void)
+{
+ struct ast_cc_config_params *params = ast_calloc(1, sizeof(*params));
+
+ if (!params) {
+ return NULL;
+ }
+
+ /* Yeah, I could use the get/set functions, but what's the point since
+ * I have direct access to the structure fields in this file.
+ */
+ params->cc_agent_policy = AST_CC_AGENT_NEVER;
+ params->cc_monitor_policy = AST_CC_MONITOR_NEVER;
+ params->cc_offer_timer = CC_OFFER_TIMER_DEFAULT;
+ params->ccnr_available_timer = CCNR_AVAILABLE_TIMER_DEFAULT;
+ params->ccbs_available_timer = CCBS_AVAILABLE_TIMER_DEFAULT;
+ params->cc_max_agents = CC_MAX_AGENTS_DEFAULT;
+ params->cc_max_monitors = CC_MAX_MONITORS_DEFAULT;
+ /* No need to set cc_callback_macro since calloc will 0 it out anyway */
+ return params;
+}
+
+void ast_cc_config_params_destroy(struct ast_cc_config_params *params)
+{
+ ast_free(params);
+}
+
+static enum ast_cc_agent_policies str_to_agent_policy(const char * const value)
+{
+ if (!strcasecmp(value, "never")) {
+ return AST_CC_AGENT_NEVER;
+ } else if (!strcasecmp(value, "native")) {
+ return AST_CC_AGENT_NATIVE;
+ } else if (!strcasecmp(value, "generic")) {
+ return AST_CC_AGENT_GENERIC;
+ } else {
+ ast_log(LOG_WARNING, "%s is an invalid value for cc_agent_policy. Switching to 'never'\n", value);
+ return AST_CC_AGENT_NEVER;
+ }
+}
+
+static enum ast_cc_monitor_policies str_to_monitor_policy(const char * const value)
+{
+ if (!strcasecmp(value, "never")) {
+ return AST_CC_MONITOR_NEVER;
+ } else if (!strcasecmp(value, "native")) {
+ return AST_CC_MONITOR_NATIVE;
+ } else if (!strcasecmp(value, "generic")) {
+ return AST_CC_MONITOR_GENERIC;
+ } else if (!strcasecmp(value, "always")) {
+ return AST_CC_MONITOR_ALWAYS;
+ } else {
+ ast_log(LOG_WARNING, "%s is an invalid value for cc_monitor_policy. Switching to 'never'\n", value);
+ return AST_CC_MONITOR_NEVER;
+ }
+}
+
+int ast_cc_set_param(struct ast_cc_config_params *params, const char * const name, const char * const value)
+{
+ unsigned int value_as_uint;
+ if (!strcasecmp(name, "cc_agent_policy")) {
+ return ast_set_cc_agent_policy(params, str_to_agent_policy(value));
+ } else if (!strcasecmp(name, "cc_monitor_policy")) {
+ return ast_set_cc_monitor_policy(params, str_to_monitor_policy(value));
+ } else if (!strcasecmp(name, "cc_callback_macro")) {
+ ast_set_cc_callback_macro(params, value);
+ return 0;
+ }
+
+ if (!sscanf(value, "%30d", &value_as_uint) == 1) {
+ return -1;
+ }
+
+ if (!strcasecmp(name, "cc_offer_timer")) {
+ ast_set_cc_offer_timer(params, value_as_uint);
+ } else if (!strcasecmp(name, "ccnr_available_timer")) {
+ ast_set_ccnr_available_timer(params, value_as_uint);
+ } else if (!strcasecmp(name, "ccbs_available_timer")) {
+ ast_set_ccbs_available_timer(params, value_as_uint);
+ } else if (!strcasecmp(name, "cc_max_agents")) {
+ ast_set_cc_max_agents(params, value_as_uint);
+ } else if (!strcasecmp(name, "cc_max_monitors")) {
+ ast_set_cc_max_monitors(params, value_as_uint);
+ } else {
+ ast_log(LOG_WARNING, "%s is not a valid CC parameter. Ignoring.\n", name);
+ }
+
+ return 0;
+}
+
+/* Heh, I suppose that we could just check if the first two characters
+ * of an option name are 'cc' and this could be a lot more efficient.
+ * That seems HIGHLY error prone, though, so I'll just do this the long way
+ */
+int ast_cc_is_config_param(const char * const name)
+{
+ return (!strcasecmp(name, "cc_agent_policy") ||
+ !strcasecmp(name, "cc_monitor_policy") ||
+ !strcasecmp(name, "cc_offer_timer") ||
+ !strcasecmp(name, "ccnr_available_timer") ||
+ !strcasecmp(name, "ccbs_available_timer") ||
+ !strcasecmp(name, "cc_max_agents") ||
+ !strcasecmp(name, "cc_max_monitors") ||
+ !strcasecmp(name, "cc_callback_macro"));
+}
+
+void ast_cc_copy_config_params(struct ast_cc_config_params *dest, const struct ast_cc_config_params *src)
+{
+ memcpy(dest, src, sizeof(*dest));
+}
+
+enum ast_cc_agent_policies ast_get_cc_agent_policy(struct ast_cc_config_params *config)
+{
+ return config->cc_agent_policy;
+}
+
+int ast_set_cc_agent_policy(struct ast_cc_config_params *config, enum ast_cc_agent_policies value)
+{
+ /* Screw C and its weak type checking for making me have to do this
+ * validation at runtime.
+ */
+ if (value < AST_CC_AGENT_NEVER || value > AST_CC_AGENT_GENERIC) {
+ return -1;
+ }
+ config->cc_agent_policy = value;
+ return 0;
+}
+
+enum ast_cc_monitor_policies ast_get_cc_monitor_policy(struct ast_cc_config_params *config)
+{
+ return config->cc_monitor_policy;
+}
+
+int ast_set_cc_monitor_policy(struct ast_cc_config_params *config, enum ast_cc_monitor_policies value)
+{
+ /* Screw C and its weak type checking for making me have to do this
+ * validation at runtime.
+ */
+ if (value < AST_CC_MONITOR_NEVER || value > AST_CC_MONITOR_ALWAYS) {
+ return -1;
+ }
+ config->cc_monitor_policy = value;
+ return 0;
+}
+
+unsigned int ast_get_cc_offer_timer(struct ast_cc_config_params *config)
+{
+ return config->cc_offer_timer;
+}
+
+void ast_set_cc_offer_timer(struct ast_cc_config_params *config, unsigned int value)
+{
+ /* 0 is an unreasonable value for any timer. Stick with the default */
+ if (value == 0) {
+ ast_log(LOG_WARNING, "0 is an invalid value for cc_offer_timer. Retaining value as %u\n", config->cc_offer_timer);
+ return;
+ }
+ config->cc_offer_timer = value;
+}
+
+unsigned int ast_get_ccnr_available_timer(struct ast_cc_config_params *config)
+{
+ return config->ccnr_available_timer;
+}
+
+void ast_set_ccnr_available_timer(struct ast_cc_config_params *config, unsigned int value)
+{
+ /* 0 is an unreasonable value for any timer. Stick with the default */
+ if (value == 0) {
+ ast_log(LOG_WARNING, "0 is an invalid value for ccnr_available_timer. Retaining value as %u\n", config->ccnr_available_timer);
+ return;
+ }
+ config->ccnr_available_timer = value;
+}
+
+unsigned int ast_get_ccbs_available_timer(struct ast_cc_config_params *config)
+{
+ return config->ccbs_available_timer;
+}
+
+void ast_set_ccbs_available_timer(struct ast_cc_config_params *config, unsigned int value)
+{
+ /* 0 is an unreasonable value for any timer. Stick with the default */
+ if (value == 0) {
+ ast_log(LOG_WARNING, "0 is an invalid value for ccbs_available_timer. Retaining value as %u\n", config->ccbs_available_timer);
+ return;
+ }
+ config->ccbs_available_timer = value;
+}
+
+unsigned int ast_get_cc_max_agents(struct ast_cc_config_params *config)
+{
+ return config->cc_max_agents;
+}
+
+void ast_set_cc_max_agents(struct ast_cc_config_params *config, unsigned int value)
+{
+ config->cc_max_agents = value;
+}
+
+unsigned int ast_get_cc_max_monitors(struct ast_cc_config_params *config)
+{
+ return config->cc_max_monitors;
+}
+
+void ast_set_cc_max_monitors(struct ast_cc_config_params *config, unsigned int value)
+{
+ config->cc_max_monitors = value;
+}
+
+const char *ast_get_cc_callback_macro(struct ast_cc_config_params *config)
+{
+ return config->cc_callback_macro;
+}
+
+void ast_set_cc_callback_macro(struct ast_cc_config_params *config, const char * const value)
+{
+ if (ast_strlen_zero(value)) {
+ config->cc_callback_macro[0] = '\0';
+ } else {
+ ast_copy_string(config->cc_callback_macro, value, sizeof(config->cc_callback_macro));
+ }
+}
Propchange: team/group/CCSS/main/ccss.c
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: team/group/CCSS/main/ccss.c
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange: team/group/CCSS/main/ccss.c
------------------------------------------------------------------------------
svn:mime-type = text/plain
More information about the asterisk-commits
mailing list