2006-01-03 22:13:59 +00:00
|
|
|
/*
|
|
|
|
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
|
2009-02-13 23:37:37 +00:00
|
|
|
* Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
|
2006-01-03 22:13:59 +00:00
|
|
|
*
|
|
|
|
* Version: MPL 1.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
2009-02-04 21:20:54 +00:00
|
|
|
* Anthony Minessale II <anthm@freeswitch.org>
|
2006-01-03 22:13:59 +00:00
|
|
|
* Portions created by the Initial Developer are Copyright (C)
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
*
|
2009-02-04 21:20:54 +00:00
|
|
|
* Anthony Minessale II <anthm@freeswitch.org>
|
2006-10-21 23:02:36 +00:00
|
|
|
* Neal Horman <neal at wanlink dot com>
|
2006-01-03 22:13:59 +00:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* mod_skel.c -- Framework Demo Module
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#include <switch.h>
|
|
|
|
|
2009-01-27 21:32:15 +00:00
|
|
|
/* Prototypes */
|
2009-03-05 15:03:29 +00:00
|
|
|
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_skel_shutdown);
|
|
|
|
SWITCH_MODULE_RUNTIME_FUNCTION(mod_skel_runtime);
|
2007-06-13 17:48:49 +00:00
|
|
|
SWITCH_MODULE_LOAD_FUNCTION(mod_skel_load);
|
2009-01-27 21:32:15 +00:00
|
|
|
|
|
|
|
/* SWITCH_MODULE_DEFINITION(name, load, shutdown, runtime)
|
|
|
|
* Defines a switch_loadable_module_function_table_t and a static const char[] modname
|
|
|
|
*/
|
2009-03-05 15:03:29 +00:00
|
|
|
SWITCH_MODULE_DEFINITION(mod_skel, mod_skel_load, mod_skel_shutdown, NULL);
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
CODEC_NEGOTIATION_GREEDY = 1,
|
|
|
|
CODEC_NEGOTIATION_GENEROUS = 2,
|
|
|
|
CODEC_NEGOTIATION_EVIL = 3
|
|
|
|
} codec_negotiation_t;
|
|
|
|
|
|
|
|
static struct {
|
|
|
|
char *codec_negotiation_str;
|
|
|
|
codec_negotiation_t codec_negotiation;
|
|
|
|
switch_bool_t sip_trace;
|
|
|
|
int integer;
|
|
|
|
} globals;
|
|
|
|
|
|
|
|
static switch_status_t config_callback_siptrace(switch_xml_config_item_t *data, switch_bool_t changed)
|
|
|
|
{
|
|
|
|
switch_bool_t value = *(switch_bool_t*)data->ptr;
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "In siptrace callback: value %s changed %s\n",
|
|
|
|
value ? "true" : "false", changed ? "true" : "false");
|
|
|
|
|
|
|
|
/*
|
|
|
|
if (changed) {
|
|
|
|
nua_set_params(((sofia_profile_t*)data->functiondata)->nua, TPTAG_LOG(value), TAG_END());
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
return SWITCH_STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static switch_status_t do_config(switch_bool_t reload)
|
|
|
|
{
|
|
|
|
switch_xml_t cfg, xml, settings;
|
|
|
|
switch_xml_config_string_options_t config_opt_codec_negotiation = { NULL, 0, "greedy|generous|evil" };
|
|
|
|
/* enforce_min, min, enforce_max, max */
|
|
|
|
switch_xml_config_int_options_t config_opt_integer = { SWITCH_TRUE, 0, SWITCH_TRUE, 10 };
|
|
|
|
switch_xml_config_enum_item_t config_opt_codec_negotiation_enum[] = {
|
|
|
|
{ "greedy", CODEC_NEGOTIATION_GREEDY },
|
|
|
|
{ "generous", CODEC_NEGOTIATION_GENEROUS },
|
|
|
|
{ "evil", CODEC_NEGOTIATION_EVIL },
|
|
|
|
{ NULL, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
switch_xml_config_item_t instructions[] = {
|
|
|
|
/* parameter name type reloadable pointer default value options structure */
|
|
|
|
SWITCH_CONFIG_ITEM("codec-negotiation-str", SWITCH_CONFIG_STRING, SWITCH_TRUE, &globals.codec_negotiation_str, "greedy", &config_opt_codec_negotiation),
|
|
|
|
SWITCH_CONFIG_ITEM("codec-negotiation", SWITCH_CONFIG_ENUM, SWITCH_TRUE, &globals.codec_negotiation, (void*)CODEC_NEGOTIATION_GREEDY, &config_opt_codec_negotiation_enum),
|
|
|
|
SWITCH_CONFIG_ITEM_CALLBACK("sip-trace", SWITCH_CONFIG_BOOL, SWITCH_TRUE, &globals.sip_trace, (void*)SWITCH_FALSE, config_callback_siptrace, NULL ),
|
|
|
|
SWITCH_CONFIG_ITEM("integer", SWITCH_CONFIG_INT, SWITCH_FALSE, &globals.integer, (void*)100, &config_opt_integer),
|
|
|
|
SWITCH_CONFIG_ITEM_END()
|
|
|
|
};
|
|
|
|
|
|
|
|
memset(&globals, 0, sizeof(globals));
|
|
|
|
|
|
|
|
if (!(xml = switch_xml_open_cfg("skel.conf", &cfg, NULL))) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Could not open skel.conf\n");
|
|
|
|
return SWITCH_STATUS_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((settings = switch_xml_child(cfg, "settings"))) {
|
|
|
|
if (switch_xml_config_parse(switch_xml_child(settings, "param"), 0, instructions) == SWITCH_STATUS_SUCCESS) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE,"Config parsed ok!\n");
|
|
|
|
return SWITCH_STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cfg) {
|
|
|
|
switch_xml_free(cfg);
|
|
|
|
}
|
|
|
|
|
|
|
|
return SWITCH_STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
SWITCH_STANDARD_API(skel_function)
|
|
|
|
{
|
|
|
|
stream->write_function(stream, "+OK Reloading\n");
|
|
|
|
do_config(SWITCH_TRUE);
|
|
|
|
return SWITCH_STATUS_SUCCESS;
|
|
|
|
}
|
2006-01-03 22:13:59 +00:00
|
|
|
|
2009-01-27 21:32:15 +00:00
|
|
|
/* Macro expands to: switch_status_t mod_skel_load(switch_loadable_module_interface_t **module_interface, switch_memory_pool_t *pool) */
|
2007-06-13 17:48:49 +00:00
|
|
|
SWITCH_MODULE_LOAD_FUNCTION(mod_skel_load)
|
2006-01-20 15:05:05 +00:00
|
|
|
{
|
2009-03-05 15:03:29 +00:00
|
|
|
switch_api_interface_t *api_interface;
|
2006-01-03 22:13:59 +00:00
|
|
|
/* connect my internal structure to the blank pointer passed to me */
|
2008-05-27 04:54:52 +00:00
|
|
|
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
|
2006-01-03 22:13:59 +00:00
|
|
|
|
2006-04-16 06:05:53 +00:00
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Hello World!\n");
|
2009-03-05 15:03:29 +00:00
|
|
|
|
|
|
|
do_config(SWITCH_FALSE);
|
|
|
|
|
|
|
|
SWITCH_ADD_API(api_interface, "skel", "Skel API", skel_function, "syntax");
|
2006-01-03 22:13:59 +00:00
|
|
|
|
|
|
|
/* indicate that the module should continue to be loaded */
|
|
|
|
return SWITCH_STATUS_SUCCESS;
|
|
|
|
}
|
2006-03-03 16:57:21 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
Called when the system shuts down
|
2009-03-05 15:03:29 +00:00
|
|
|
Macro expands to: switch_status_t mod_skel_shutdown() */
|
2008-10-16 20:06:13 +00:00
|
|
|
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_skel_shutdown)
|
2006-10-21 23:02:36 +00:00
|
|
|
{
|
|
|
|
return SWITCH_STATUS_SUCCESS;
|
|
|
|
}
|
2009-03-05 15:03:29 +00:00
|
|
|
|
2006-03-03 16:57:21 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
If it exists, this is called in it's own thread when the module-load completes
|
2008-10-06 23:05:55 +00:00
|
|
|
If it returns anything but SWITCH_STATUS_TERM it will be called again automatically
|
2009-01-27 21:32:15 +00:00
|
|
|
Macro expands to: switch_status_t mod_skel_runtime()
|
2008-10-16 20:06:13 +00:00
|
|
|
SWITCH_MODULE_RUNTIME_FUNCTION(mod_skel_runtime)
|
2006-10-21 23:02:36 +00:00
|
|
|
{
|
|
|
|
while(looping)
|
|
|
|
{
|
2008-11-14 23:31:21 +00:00
|
|
|
switch_cond_next();
|
2006-10-21 23:02:36 +00:00
|
|
|
}
|
|
|
|
return SWITCH_STATUS_TERM;
|
|
|
|
}
|
2006-03-03 16:57:21 +00:00
|
|
|
*/
|
2006-11-27 22:30:48 +00:00
|
|
|
|
|
|
|
/* For Emacs:
|
|
|
|
* Local Variables:
|
|
|
|
* mode:c
|
2008-02-03 22:14:57 +00:00
|
|
|
* indent-tabs-mode:t
|
2006-11-27 22:30:48 +00:00
|
|
|
* tab-width:4
|
|
|
|
* c-basic-offset:4
|
|
|
|
* End:
|
|
|
|
* For VIM:
|
2009-03-05 15:03:29 +00:00
|
|
|
* vim:set softtabstop=4 shiftwidth=4 tabstop=4
|
2006-11-27 22:30:48 +00:00
|
|
|
*/
|