XMLification (wave 4)

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@1412 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale 2006-05-10 15:47:54 +00:00
parent 7c0fce5a01
commit f09491a69b
26 changed files with 275 additions and 156 deletions

View File

@ -53,6 +53,10 @@ SWITCH_DECLARE(void) switch_console_loop(void);
*/ */
SWITCH_DECLARE(void) switch_console_printf(switch_text_channel_t channel, char *file, const char *func, int line, char *fmt, ...); SWITCH_DECLARE(void) switch_console_printf(switch_text_channel_t channel, char *file, const char *func, int line, char *fmt, ...);
/*!
\brief A method akin to printf for dealing with api streams
*/
SWITCH_DECLARE(switch_status_t) switch_console_stream_write(switch_stream_handle_t *handle, char *fmt, ...);
END_EXTERN_C END_EXTERN_C
#endif #endif

View File

@ -193,11 +193,11 @@ SWITCH_DECLARE(int) switch_loadable_module_get_codecs_sorted(switch_codec_interf
\brief Execute a registered API command \brief Execute a registered API command
\param cmd the name of the API command to execute \param cmd the name of the API command to execute
\param arg the optional arguement to the command \param arg the optional arguement to the command
\param retbuf a buffer to write output to \param stream stream for output
\param len the length in bytes of retbuf
\return the status returned by the API call \return the status returned by the API call
*/ */
SWITCH_DECLARE(switch_status_t) switch_api_execute(char *cmd, char *arg, char *retbuf, switch_size_t len); SWITCH_DECLARE(switch_status_t) switch_api_execute(char *cmd, char *arg, switch_stream_handle_t *stream);
/*! /*!

View File

@ -62,6 +62,14 @@ struct switch_state_handler_table {
switch_state_handler_t on_hold; switch_state_handler_t on_hold;
}; };
struct switch_stream_handle {
switch_stream_handle_write_function_t write_function;
void *data;
void *end;
switch_size_t data_size;
switch_size_t data_len;
};
/*! \brief Node in which to store custom outgoing channel callback hooks */ /*! \brief Node in which to store custom outgoing channel callback hooks */
struct switch_io_event_hook_outgoing_channel { struct switch_io_event_hook_outgoing_channel {
/*! the outgoing channel callback hook*/ /*! the outgoing channel callback hook*/

View File

@ -671,7 +671,9 @@ typedef switch_status_t (*switch_kill_channel_hook_t)(switch_core_session_t *, i
typedef switch_status_t (*switch_waitfor_read_hook_t)(switch_core_session_t *, int, int); typedef switch_status_t (*switch_waitfor_read_hook_t)(switch_core_session_t *, int, int);
typedef switch_status_t (*switch_waitfor_write_hook_t)(switch_core_session_t *, int, int); typedef switch_status_t (*switch_waitfor_write_hook_t)(switch_core_session_t *, int, int);
typedef switch_status_t (*switch_send_dtmf_hook_t)(switch_core_session_t *, char *); typedef switch_status_t (*switch_send_dtmf_hook_t)(switch_core_session_t *, char *);
typedef switch_status_t (*switch_api_function_t)(char *in, char *out, switch_size_t outlen); typedef struct switch_stream_handle switch_stream_handle_t;
typedef switch_status_t (*switch_stream_handle_write_function_t)(switch_stream_handle_t *handle, char *fmt, ...);
typedef switch_status_t (*switch_api_function_t)(char *in, switch_stream_handle_t *stream);
typedef switch_status_t (*switch_dtmf_callback_function_t)(switch_core_session_t *session, char *dtmf, void *buf, unsigned int buflen); typedef switch_status_t (*switch_dtmf_callback_function_t)(switch_core_session_t *session, char *dtmf, void *buf, unsigned int buflen);
typedef int (*switch_core_db_callback_func_t)(void *pArg, int argc, char **argv, char **columnNames); typedef int (*switch_core_db_callback_func_t)(void *pArg, int argc, char **argv, char **columnNames);
typedef switch_status_t (*switch_module_load_t) (switch_loadable_module_interface_t **, char *); typedef switch_status_t (*switch_module_load_t) (switch_loadable_module_interface_t **, char *);
@ -686,10 +688,11 @@ typedef struct switch_core_time_duration switch_core_time_duration_t;
typedef switch_xml_t (*switch_xml_search_function_t)(char *section, typedef switch_xml_t (*switch_xml_search_function_t)(char *section,
char *tag_name, char *tag_name,
char *key_name, char *key_name,
char *key_value); char *key_value,
char *params);
/* things we don't deserve to know about */ /* things we don't deserve to know about */
/*! \brief A channel */ /*! \brief A channel */
struct switch_channel; struct switch_channel;
/*! \brief A core session representing a call and all of it's resources */ /*! \brief A core session representing a call and all of it's resources */

View File

@ -184,7 +184,8 @@ SWITCH_DECLARE(char *) switch_string_replace(const char *string, const char *sea
SWITCH_DECLARE(switch_status_t) switch_string_match(const char *string, size_t string_len, const char *search, size_t search_len); SWITCH_DECLARE(switch_status_t) switch_string_match(const char *string, size_t string_len, const char *search, size_t search_len);
#define SWITCH_READ_ACCEPTABLE(status) status == SWITCH_STATUS_SUCCESS || status == SWITCH_STATUS_BREAK #define SWITCH_READ_ACCEPTABLE(status) status == SWITCH_STATUS_SUCCESS || status == SWITCH_STATUS_BREAK
SWITCH_DECLARE(int) switch_url_encode(char *url, char *buf, size_t len);
SWITCH_DECLARE(char *) switch_url_decode(char *s);
END_EXTERN_C END_EXTERN_C
#endif #endif

View File

@ -196,9 +196,10 @@ SWITCH_DECLARE(switch_status_t) switch_xml_locate(char *section,
char *key_name, char *key_name,
char *key_value, char *key_value,
switch_xml_t *root, switch_xml_t *root,
switch_xml_t *node); switch_xml_t *node,
char *params);
SWITCH_DECLARE(switch_xml_t) switch_xml_open_cfg(char *file_path, switch_xml_t *node); SWITCH_DECLARE(switch_xml_t) switch_xml_open_cfg(char *file_path, switch_xml_t *node, char *params);
SWITCH_DECLARE(switch_status_t) switch_xml_bind_search_function(switch_xml_search_function_t function); SWITCH_DECLARE(switch_status_t) switch_xml_bind_search_function(switch_xml_search_function_t function);
END_EXTERN_C END_EXTERN_C

View File

@ -33,15 +33,31 @@
static const char modname[] = "mod_commands"; static const char modname[] = "mod_commands";
static switch_status_t status_function(char *cmd, switch_stream_handle_t *stream)
static switch_status_t load_function(char *mod, char *out, size_t outlen)
{ {
switch_loadable_module_load_module((char *) SWITCH_GLOBAL_dirs.mod_dir, (char *) mod); switch_core_time_duration_t duration;
snprintf(out, outlen, "OK\n"); switch_core_measure_time(switch_core_uptime(), &duration);
stream->write_function(stream, "<b>UP %u year(s), %u day(s), %u hour(s), %u minute(s), %u second(s), %u millisecond(s), %u microsecond(s)</b>\n",
duration.yr,
duration.day,
duration.hr,
duration.min,
duration.sec,
duration.ms,
duration.mms
);
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
static switch_status_t kill_function(char *dest, char *out, size_t outlen) static switch_status_t load_function(char *mod, switch_stream_handle_t *stream)
{
switch_loadable_module_load_module((char *) SWITCH_GLOBAL_dirs.mod_dir, (char *) mod);
stream->write_function(stream, "OK\n");
return SWITCH_STATUS_SUCCESS;
}
static switch_status_t kill_function(char *dest, switch_stream_handle_t *stream)
{ {
switch_core_session_t *session = NULL; switch_core_session_t *session = NULL;
@ -50,16 +66,16 @@ static switch_status_t kill_function(char *dest, char *out, size_t outlen)
switch_core_session_kill_channel(session, SWITCH_SIG_KILL); switch_core_session_kill_channel(session, SWITCH_SIG_KILL);
switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING); switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
switch_core_session_rwunlock(session); switch_core_session_rwunlock(session);
snprintf(out, outlen, "OK\n"); stream->write_function(stream, "OK\n");
} else { } else {
snprintf(out, outlen, "No Such Channel!\n"); stream->write_function(stream, "No Such Channel!\n");
} }
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
static switch_status_t transfer_function(char *cmd, char *out, size_t outlen) static switch_status_t transfer_function(char *cmd, switch_stream_handle_t *stream)
{ {
switch_core_session_t *session = NULL; switch_core_session_t *session = NULL;
char *argv[4] = {0}; char *argv[4] = {0};
@ -68,7 +84,7 @@ static switch_status_t transfer_function(char *cmd, char *out, size_t outlen)
argc = switch_separate_string(cmd, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); argc = switch_separate_string(cmd, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
if (argc < 2 || argc > 4) { if (argc < 2 || argc > 4) {
snprintf(out, outlen, "Invalid Parameters\n"); stream->write_function(stream, "Invalid Parameters\n");
} else { } else {
char *uuid = argv[0]; char *uuid = argv[0];
char *dest = argv[1]; char *dest = argv[1];
@ -78,15 +94,15 @@ static switch_status_t transfer_function(char *cmd, char *out, size_t outlen)
if ((session = switch_core_session_locate(uuid))) { if ((session = switch_core_session_locate(uuid))) {
if (switch_ivr_session_transfer(session, dest, dp, context) == SWITCH_STATUS_SUCCESS) { if (switch_ivr_session_transfer(session, dest, dp, context) == SWITCH_STATUS_SUCCESS) {
snprintf(out, outlen, "OK\n"); stream->write_function(stream, "OK\n");
} else { } else {
snprintf(out, outlen, "ERROR\n"); stream->write_function(stream, "ERROR\n");
} }
switch_core_session_rwunlock(session); switch_core_session_rwunlock(session);
} else { } else {
snprintf(out, outlen, "No Such Channel!\n"); stream->write_function(stream, "No Such Channel!\n");
} }
} }
@ -96,7 +112,7 @@ static switch_status_t transfer_function(char *cmd, char *out, size_t outlen)
static switch_status_t pause_function(char *cmd, char *out, size_t outlen) static switch_status_t pause_function(char *cmd, switch_stream_handle_t *stream)
{ {
switch_core_session_t *session = NULL; switch_core_session_t *session = NULL;
char *argv[4] = {0}; char *argv[4] = {0};
@ -105,7 +121,7 @@ static switch_status_t pause_function(char *cmd, char *out, size_t outlen)
argc = switch_separate_string(cmd, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); argc = switch_separate_string(cmd, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
if (argc < 2) { if (argc < 2) {
snprintf(out, outlen, "Invalid Parameters\n"); stream->write_function(stream, "Invalid Parameters\n");
} else { } else {
char *uuid = argv[0]; char *uuid = argv[0];
char *dest = argv[1]; char *dest = argv[1];
@ -122,66 +138,32 @@ static switch_status_t pause_function(char *cmd, char *out, size_t outlen)
switch_core_session_rwunlock(session); switch_core_session_rwunlock(session);
} else { } else {
snprintf(out, outlen, "No Such Channel!\n"); stream->write_function(stream, "No Such Channel!\n");
} }
} }
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
struct show_return {
char *out;
size_t remaining;
};
static int show_callback(void *pArg, int argc, char **argv, char **columnNames){ static int show_callback(void *pArg, int argc, char **argv, char **columnNames){
struct show_return *returnval = (struct show_return *) pArg; switch_stream_handle_t *stream = (switch_stream_handle_t *) pArg;
char temp[1024];
size_t len;
sprintf(temp, "%s\n", argv[1]); stream->write_function(stream, "%s\n", argv[1]);
len = strlen(temp);
if (len < returnval->remaining) {
strcpy(returnval->out, temp);
returnval->remaining -= len;
returnval->out += len;
}
return 0; return 0;
} }
static switch_status_t status_function(char *cmd, char *out, size_t outlen)
{
switch_core_time_duration_t duration;
switch_core_measure_time(switch_core_uptime(), &duration);
snprintf(out, outlen, "<b>UP %u year(s), %u day(s), %u hour(s), %u minute(s), %u second(s), %u millisecond(s), %u microsecond(s)</b>\n", static switch_status_t show_function(char *cmd, switch_stream_handle_t *stream)
duration.yr,
duration.day,
duration.hr,
duration.min,
duration.sec,
duration.ms,
duration.mms
);
return SWITCH_STATUS_SUCCESS;
}
static switch_status_t show_function(char *cmd, char *out, size_t outlen)
{ {
char sql[1024]; char sql[1024];
char *errmsg; char *errmsg;
struct show_return returnval;
switch_core_db_t *db = switch_core_db_handle(); switch_core_db_t *db = switch_core_db_handle();
sprintf (sql, "select * from interfaces"); sprintf (sql, "select * from interfaces");
returnval.out = out; switch_core_db_exec(db, sql, show_callback, stream, &errmsg);
returnval.remaining = outlen;
switch_core_db_exec(db, sql, show_callback, &returnval, &errmsg);
if (errmsg) { if (errmsg) {
snprintf(out, outlen, "SQL ERR [%s]\n",errmsg); stream->write_function(stream, "SQL ERR [%s]\n",errmsg);
switch_core_db_free(errmsg); switch_core_db_free(errmsg);
errmsg = NULL; errmsg = NULL;
} }
@ -234,7 +216,6 @@ static switch_api_interface_t commands_api_interface = {
/*.next */ &load_api_interface /*.next */ &load_api_interface
}; };
static const switch_loadable_module_interface_t mod_commands_module_interface = { static const switch_loadable_module_interface_t mod_commands_module_interface = {
/*.module_name */ modname, /*.module_name */ modname,
/*.endpoint_interface */ NULL, /*.endpoint_interface */ NULL,

View File

@ -57,7 +57,7 @@ static void load_config(void)
switch_xml_t cfg, xml, settings, param; switch_xml_t cfg, xml, settings, param;
if (!(xml = switch_xml_open_cfg(cf, &cfg))) { if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf);
return; return;
} }

View File

@ -131,7 +131,7 @@ static switch_caller_extension_t *dialplan_hunt(switch_core_session_t *session)
char *exten_name = NULL; char *exten_name = NULL;
switch_xml_t cfg, xml, xcontext, xexten, xaction, xcond; switch_xml_t cfg, xml, xcontext, xexten, xaction, xcond;
char *context = NULL; char *context = NULL;
char params[1024];
channel = switch_core_session_get_channel(session); channel = switch_core_session_get_channel(session);
if ((caller_profile = switch_channel_get_caller_profile(channel))) { if ((caller_profile = switch_channel_get_caller_profile(channel))) {
@ -142,10 +142,10 @@ static switch_caller_extension_t *dialplan_hunt(switch_core_session_t *session)
} }
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Processing %s->%s!\n", caller_profile->caller_id_name, switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Processing %s->%s!\n", caller_profile->caller_id_name,
caller_profile->destination_number); caller_profile->destination_number);
if (!(xml = switch_xml_open_cfg(cf, &cfg))) { snprintf(params, sizeof(params), "dest=%s", caller_profile->destination_number);
if (!(xml = switch_xml_open_cfg(cf, &cfg, params))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf);
switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER); switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
return NULL; return NULL;

View File

@ -148,8 +148,8 @@ SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_dialplan, globals.dialplan);
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_codec_string, globals.codec_string); SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_codec_string, globals.codec_string);
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_codec_rates_string, globals.codec_rates_string); SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_codec_rates_string, globals.codec_rates_string);
static switch_status_t dl_login(char *arg, char *out, size_t outlen); static switch_status_t dl_login(char *arg, switch_stream_handle_t *stream);
static switch_status_t dl_logout(char *profile_name, char *out, size_t outlen); static switch_status_t dl_logout(char *profile_name, switch_stream_handle_t *stream);
static switch_status_t channel_on_init(switch_core_session_t *session); static switch_status_t channel_on_init(switch_core_session_t *session);
static switch_status_t channel_on_hangup(switch_core_session_t *session); static switch_status_t channel_on_hangup(switch_core_session_t *session);
static switch_status_t channel_on_ring(switch_core_session_t *session); static switch_status_t channel_on_ring(switch_core_session_t *session);
@ -1222,20 +1222,20 @@ static void set_profile_val(struct mdl_profile *profile, char *var, char *val)
} }
} }
static switch_status_t dl_logout(char *profile_name, char *out, size_t outlen) static switch_status_t dl_logout(char *profile_name, switch_stream_handle_t *stream)
{ {
struct mdl_profile *profile; struct mdl_profile *profile;
if ((profile = switch_core_hash_find(globals.profile_hash, profile_name))) { if ((profile = switch_core_hash_find(globals.profile_hash, profile_name))) {
ldl_handle_stop(profile->handle); ldl_handle_stop(profile->handle);
snprintf(out, outlen, "OK\n"); stream->write_function(stream, "OK\n");
} else { } else {
snprintf(out, outlen, "NO SUCH PROFILE %s\n", profile_name); stream->write_function(stream, "NO SUCH PROFILE %s\n", profile_name);
} }
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
static switch_status_t dl_login(char *arg, char *out, size_t outlen) static switch_status_t dl_login(char *arg, switch_stream_handle_t *stream)
{ {
char *argv[10] = {0}; char *argv[10] = {0};
int argc = 0; int argc = 0;
@ -1244,7 +1244,7 @@ static switch_status_t dl_login(char *arg, char *out, size_t outlen)
int x; int x;
if (switch_strlen_zero(arg)) { if (switch_strlen_zero(arg)) {
snprintf(out, outlen, "FAIL\n"); stream->write_function(stream, "FAIL\n");
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
@ -1259,7 +1259,7 @@ static switch_status_t dl_login(char *arg, char *out, size_t outlen)
if (profile) { if (profile) {
if (switch_test_flag(profile, TFLAG_IO)) { if (switch_test_flag(profile, TFLAG_IO)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Profile already exists."); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Profile already exists.");
snprintf(out, outlen, "Profile already exists\n"); stream->write_function(stream, "Profile already exists\n");
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
@ -1277,9 +1277,9 @@ static switch_status_t dl_login(char *arg, char *out, size_t outlen)
} }
if (profile && init_profile(profile, 1) == SWITCH_STATUS_SUCCESS) { if (profile && init_profile(profile, 1) == SWITCH_STATUS_SUCCESS) {
snprintf(out, outlen, "OK\n"); stream->write_function(stream, "OK\n");
} else { } else {
snprintf(out, outlen, "FAIL\n"); stream->write_function(stream, "FAIL\n");
} }
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
@ -1298,7 +1298,7 @@ static switch_status_t load_config(void)
switch_core_hash_init(&globals.profile_hash, module_pool); switch_core_hash_init(&globals.profile_hash, module_pool);
if (!(xml = switch_xml_open_cfg(cf, &cfg))) { if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf);
return SWITCH_STATUS_TERM; return SWITCH_STATUS_TERM;
} }

View File

@ -1609,7 +1609,7 @@ static int config_exosip(int reload)
globals.bytes_per_frame = DEFAULT_BYTES_PER_FRAME; globals.bytes_per_frame = DEFAULT_BYTES_PER_FRAME;
if (!(xml = switch_xml_open_cfg(cf, &cfg))) { if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf);
return SWITCH_STATUS_TERM; return SWITCH_STATUS_TERM;
} }

View File

@ -822,7 +822,7 @@ static switch_status_t load_config(void)
memset(&globals, 0, sizeof(globals)); memset(&globals, 0, sizeof(globals));
if (!(xml = switch_xml_open_cfg(cf, &cfg))) { if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf);
return SWITCH_STATUS_TERM; return SWITCH_STATUS_TERM;
} }

View File

@ -352,7 +352,7 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_mod
memset(&globals, 0, sizeof(globals)); memset(&globals, 0, sizeof(globals));
if (!(xml = switch_xml_open_cfg(cf, &cfg))) { if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf);
return SWITCH_STATUS_TERM; return SWITCH_STATUS_TERM;
} }

View File

@ -115,11 +115,11 @@ SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_dialplan, globals.dialplan)
static int dump_info(void); static int dump_info(void);
static switch_status_t load_config(void); static switch_status_t load_config(void);
static int get_dev_by_name(char *name, int in); static int get_dev_by_name(char *name, int in);
static switch_status_t place_call(char *dest, char *out, size_t outlen); static switch_status_t place_call(char *dest, switch_stream_handle_t *stream);
static switch_status_t hup_call(char *callid, char *out, size_t outlen); static switch_status_t hup_call(char *callid, switch_stream_handle_t *stream);
static switch_status_t call_info(char *callid, char *out, size_t outlen); static switch_status_t call_info(char *callid, switch_stream_handle_t *stream);
static switch_status_t send_dtmf(char *callid, char *out, size_t outlen); static switch_status_t send_dtmf(char *callid, switch_stream_handle_t *stream);
static switch_status_t answer_call(char *callid, char *out, size_t outlen); static switch_status_t answer_call(char *callid, switch_stream_handle_t *stream);
/* /*
State methods they get called when the state changes to the specific state State methods they get called when the state changes to the specific state
@ -571,7 +571,7 @@ static switch_status_t load_config(void)
memset(&globals, 0, sizeof(globals)); memset(&globals, 0, sizeof(globals));
if (!(xml = switch_xml_open_cfg(cf, &cfg))) { if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf);
return SWITCH_STATUS_TERM; return SWITCH_STATUS_TERM;
} }
@ -794,7 +794,7 @@ static switch_status_t engage_device(struct private_object *tech_pvt)
return SWITCH_STATUS_FALSE; return SWITCH_STATUS_FALSE;
} }
static switch_status_t place_call(char *dest, char *out, size_t outlen) static switch_status_t place_call(char *dest, switch_stream_handle_t *stream)
{ {
switch_core_session_t *session; switch_core_session_t *session;
switch_status_t status = SWITCH_STATUS_FALSE; switch_status_t status = SWITCH_STATUS_FALSE;
@ -804,8 +804,8 @@ static switch_status_t place_call(char *dest, char *out, size_t outlen)
return SWITCH_STATUS_FALSE; return SWITCH_STATUS_FALSE;
} }
strncpy(out, "FAIL", outlen - 1); stream->write_function(stream, "FAIL");
if ((session = switch_core_session_request(&channel_endpoint_interface, NULL)) != 0) { if ((session = switch_core_session_request(&channel_endpoint_interface, NULL)) != 0) {
struct private_object *tech_pvt; struct private_object *tech_pvt;
switch_channel_t *channel; switch_channel_t *channel;
@ -838,14 +838,14 @@ static switch_status_t place_call(char *dest, char *out, size_t outlen)
if ((status = engage_device(tech_pvt)) == SWITCH_STATUS_SUCCESS) { if ((status = engage_device(tech_pvt)) == SWITCH_STATUS_SUCCESS) {
switch_channel_set_state(channel, CS_INIT); switch_channel_set_state(channel, CS_INIT);
switch_core_session_thread_launch(tech_pvt->session); switch_core_session_thread_launch(tech_pvt->session);
snprintf(out, outlen, "SUCCESS:%s:%s", tech_pvt->call_id, switch_core_session_get_uuid(tech_pvt->session)); stream->write_function(stream, "SUCCESS:%s:%s", tech_pvt->call_id, switch_core_session_get_uuid(tech_pvt->session));
} }
} }
return status; return status;
} }
static switch_status_t hup_call(char *callid, char *out, size_t outlen) static switch_status_t hup_call(char *callid, switch_stream_handle_t *stream)
{ {
struct private_object *tech_pvt; struct private_object *tech_pvt;
switch_channel_t *channel = NULL; switch_channel_t *channel = NULL;
@ -869,7 +869,7 @@ static switch_status_t hup_call(char *callid, char *out, size_t outlen)
i++; i++;
} }
snprintf(out, outlen, "HUNGUP: %d", i); stream->write_function(stream, "HUNGUP: %d", i);
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
@ -880,16 +880,16 @@ static switch_status_t hup_call(char *callid, char *out, size_t outlen)
assert(channel != NULL); assert(channel != NULL);
switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING); switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
strncpy(out, "OK", outlen - 1); stream->write_function(stream, "OK");
} else { } else {
strncpy(out, "NO SUCH CALL", outlen - 1); stream->write_function(stream, "NO SUCH CALL");
} }
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
static switch_status_t send_dtmf(char *callid, char *out, size_t outlen) static switch_status_t send_dtmf(char *callid, switch_stream_handle_t *stream)
{ {
struct private_object *tech_pvt = NULL; struct private_object *tech_pvt = NULL;
switch_channel_t *channel = NULL; switch_channel_t *channel = NULL;
@ -905,15 +905,15 @@ static switch_status_t send_dtmf(char *callid, char *out, size_t outlen)
channel = switch_core_session_get_channel(tech_pvt->session); channel = switch_core_session_get_channel(tech_pvt->session);
assert(channel != NULL); assert(channel != NULL);
switch_channel_queue_dtmf(channel, dtmf); switch_channel_queue_dtmf(channel, dtmf);
strncpy(out, "OK", outlen - 1); stream->write_function(stream, "OK");
} else { } else {
strncpy(out, "NO SUCH CALL", outlen - 1); stream->write_function(stream, "NO SUCH CALL");
} }
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
static switch_status_t answer_call(char *callid, char *out, size_t outlen) static switch_status_t answer_call(char *callid, switch_stream_handle_t *stream)
{ {
struct private_object *tech_pvt = NULL; struct private_object *tech_pvt = NULL;
switch_channel_t *channel = NULL; switch_channel_t *channel = NULL;
@ -924,20 +924,20 @@ static switch_status_t answer_call(char *callid, char *out, size_t outlen)
switch_set_flag(tech_pvt, TFLAG_ANSWER); switch_set_flag(tech_pvt, TFLAG_ANSWER);
switch_channel_answer(channel); switch_channel_answer(channel);
} else { } else {
strncpy(out, "NO SUCH CALL", outlen - 1); stream->write_function(stream, "NO SUCH CALL");
} }
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
static void print_info(struct private_object *tech_pvt, char *out, size_t outlen) static void print_info(struct private_object *tech_pvt, switch_stream_handle_t *stream)
{ {
switch_channel_t *channel = NULL; switch_channel_t *channel = NULL;
channel = switch_core_session_get_channel(tech_pvt->session); channel = switch_core_session_get_channel(tech_pvt->session);
assert(channel != NULL); assert(channel != NULL);
snprintf(out, outlen, "CALL %s\t%s\t%s\t%s\t%s\n", stream->write_function(stream, "CALL %s\t%s\t%s\t%s\t%s\n",
tech_pvt->call_id, tech_pvt->call_id,
tech_pvt->caller_profile->caller_id_name ? tech_pvt->caller_profile->caller_id_name : "n/a", tech_pvt->caller_profile->caller_id_name ? tech_pvt->caller_profile->caller_id_name : "n/a",
tech_pvt->caller_profile->caller_id_number ? tech_pvt->caller_profile->caller_id_number : "n/a", tech_pvt->caller_profile->caller_id_number ? tech_pvt->caller_profile->caller_id_number : "n/a",
tech_pvt->caller_profile->destination_number ? tech_pvt->caller_profile->destination_number : "n/a", tech_pvt->caller_profile->destination_number ? tech_pvt->caller_profile->destination_number : "n/a",
@ -945,7 +945,7 @@ static void print_info(struct private_object *tech_pvt, char *out, size_t outlen
} }
static switch_status_t call_info(char *callid, char *out, size_t outlen) static switch_status_t call_info(char *callid, switch_stream_handle_t *stream)
{ {
struct private_object *tech_pvt; struct private_object *tech_pvt;
switch_hash_index_t *hi; switch_hash_index_t *hi;
@ -954,12 +954,12 @@ static switch_status_t call_info(char *callid, char *out, size_t outlen)
for (hi = apr_hash_first(module_pool, globals.call_hash); hi; hi = switch_hash_next(hi)) { for (hi = apr_hash_first(module_pool, globals.call_hash); hi; hi = switch_hash_next(hi)) {
switch_hash_this(hi, NULL, NULL, &val); switch_hash_this(hi, NULL, NULL, &val);
tech_pvt = val; tech_pvt = val;
print_info(tech_pvt, out + strlen(out), outlen - strlen(out)); print_info(tech_pvt, stream);
} }
} else if (callid && (tech_pvt = switch_core_hash_find(globals.call_hash, callid)) != 0) { } else if (callid && (tech_pvt = switch_core_hash_find(globals.call_hash, callid)) != 0) {
print_info(tech_pvt, out, outlen); print_info(tech_pvt, out, outlen);
} else { } else {
strncpy(out, "NO SUCH CALL", outlen - 1); stream->write_function(stream, "NO SUCH CALL");
} }
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;

View File

@ -1293,7 +1293,7 @@ static switch_status_t config_wanpipe(int reload)
globals.dtmf_off = 50; globals.dtmf_off = 50;
if (!(xml = switch_xml_open_cfg(cf, &cfg))) { if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf);
return SWITCH_STATUS_TERM; return SWITCH_STATUS_TERM;
} }

View File

@ -1308,7 +1308,7 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_mod
memset(&globals, 0, sizeof(globals)); memset(&globals, 0, sizeof(globals));
globals.next_woomera_port = WOOMERA_MIN_PORT; globals.next_woomera_port = WOOMERA_MIN_PORT;
if (!(xml = switch_xml_open_cfg(cf, &cfg))) { if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf);
return SWITCH_STATUS_TERM; return SWITCH_STATUS_TERM;
} }

View File

@ -54,7 +54,7 @@ static switch_status_t load_config(void)
char *cf = "event_multicast.conf"; char *cf = "event_multicast.conf";
switch_xml_t cfg, xml, settings, param; switch_xml_t cfg, xml, settings, param;
if (!(xml = switch_xml_open_cfg(cf, &cfg))) { if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf);
return SWITCH_STATUS_TERM; return SWITCH_STATUS_TERM;
} }

View File

@ -104,7 +104,7 @@ SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_jid, globals.jid)
memset(&globals, 0, sizeof(globals)); memset(&globals, 0, sizeof(globals));
if (!(xml = switch_xml_open_cfg(cf, &cfg))) { if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf);
return SWITCH_STATUS_TERM; return SWITCH_STATUS_TERM;
} }

View File

@ -199,7 +199,7 @@ static switch_status_t load_config(void)
sw_discovery_oid *oid; sw_discovery_oid *oid;
switch_xml_t cfg, xml, settings, param; switch_xml_t cfg, xml, settings, param;
if (!(xml = switch_xml_open_cfg(cf, &cfg))) { if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf);
return SWITCH_STATUS_TERM; return SWITCH_STATUS_TERM;
} }

View File

@ -1791,8 +1791,13 @@ static JSBool js_api_execute(JSContext *cx, JSObject *obj, uintN argc, jsval *ar
if (argc > 1) { if (argc > 1) {
char *cmd = JS_GetStringBytes(JS_ValueToString(cx, argv[0])); char *cmd = JS_GetStringBytes(JS_ValueToString(cx, argv[0]));
char *arg = JS_GetStringBytes(JS_ValueToString(cx, argv[1])); char *arg = JS_GetStringBytes(JS_ValueToString(cx, argv[1]));
switch_stream_handle_t stream = {0};
char retbuf[2048] = ""; char retbuf[2048] = "";
switch_api_execute(cmd, arg, retbuf, sizeof(retbuf));
stream.data = retbuf;
stream.end = stream.data;
stream.data_size = sizeof(retbuf);
switch_api_execute(cmd, arg, &stream);
*rval = STRING_TO_JSVAL (JS_NewStringCopyZ(cx, retbuf)); *rval = STRING_TO_JSVAL (JS_NewStringCopyZ(cx, retbuf));
} else { } else {
*rval = STRING_TO_JSVAL (JS_NewStringCopyZ(cx, "")); *rval = STRING_TO_JSVAL (JS_NewStringCopyZ(cx, ""));
@ -2149,16 +2154,16 @@ static void js_thread_launch(char *text)
} }
static switch_status_t launch_async(char *text, char *out, size_t outlen) static switch_status_t launch_async(char *text, switch_stream_handle_t *stream)
{ {
if (switch_strlen_zero(text)) { if (switch_strlen_zero(text)) {
switch_copy_string(out, "INVALID", outlen); stream->write_function(stream, "INVALID");
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
js_thread_launch(text); js_thread_launch(text);
switch_copy_string(out, "OK", outlen); stream->write_function(stream, "OK");
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }

View File

@ -83,7 +83,7 @@ static switch_status_t config_logger(void)
char *cf = "console.conf"; char *cf = "console.conf";
switch_xml_t cfg, xml, settings, param; switch_xml_t cfg, xml, settings, param;
if (!(xml = switch_xml_open_cfg(cf, &cfg))) { if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf);
return SWITCH_STATUS_TERM; return SWITCH_STATUS_TERM;
} }

View File

@ -41,6 +41,7 @@
static const char modname[] = "mod_xml_rpc"; static const char modname[] = "mod_xml_rpc";
static struct { static struct {
int port; int port;
uint8_t running; uint8_t running;
@ -65,16 +66,18 @@ static size_t file_callback(void *ptr, size_t size, size_t nmemb, void *data)
static switch_xml_t xml_url_fetch(char *section, static switch_xml_t xml_url_fetch(char *section,
char *tag_name, char *tag_name,
char *key_name, char *key_name,
char *key_value) char *key_value,
char *params)
{ {
char url[1024] = "", filename[1024] = ""; char url[1024] = "", filename[1024] = "";
CURL *curl_handle = NULL; CURL *curl_handle = NULL;
struct config_data config_data; struct config_data config_data;
switch_xml_t xml; switch_xml_t xml;
snprintf(url, sizeof(url), "%s?section=%s&tag_name=%s&key_name=%s&key_value=%s\n", globals.url, section, tag_name, key_name, key_value); snprintf(url, sizeof(url), "%s?section=%s&tag_name=%s&key_name=%s&key_value=%s%s%s\n",
globals.url, section, tag_name, key_name, key_value, params ? "&" : "", params ? params : "");
srand(time(NULL) + strlen(url)); srand(time(NULL) + strlen(url));
snprintf(filename, sizeof(filename), "%s%04x.tmp", SWITCH_GLOBAL_dirs.temp_dir, (rand() & 0xffff)); snprintf(filename, sizeof(filename), "%s%04x.tmp", SWITCH_GLOBAL_dirs.temp_dir, (rand() & 0xffff));
curl_global_init(CURL_GLOBAL_ALL); curl_global_init(CURL_GLOBAL_ALL);
@ -126,7 +129,7 @@ static switch_status_t do_config(void)
char *cf = "xml_rpc.conf"; char *cf = "xml_rpc.conf";
switch_xml_t cfg, xml, settings, param; switch_xml_t cfg, xml, settings, param;
if (!(xml = switch_xml_open_cfg(cf, &cfg))) { if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf);
return SWITCH_STATUS_TERM; return SWITCH_STATUS_TERM;
} }
@ -171,13 +174,37 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_mod
} }
#define CMDLEN 10240 static switch_status_t http_stream_write(switch_stream_handle_t *handle, char *fmt, ...)
{
va_list ap;
TSession *r = handle->data;
int ret = 0;
char *data;
va_start(ap, fmt);
#ifdef HAVE_VASPRINTF
ret = vasprintf(&data, fmt, ap);
#else
if ((data = (char *) malloc(2048))) {
vsnprintf(data, 2048, fmt, ap);
}
#endif
va_end(ap);
if (data) {
ret = 0;
HTTPWrite(r, data, strlen(data));
free(data);
}
return ret ? SWITCH_STATUS_FALSE : SWITCH_STATUS_SUCCESS;
}
abyss_bool HandleHook(TSession *r) abyss_bool HandleHook(TSession *r)
{ {
char *m = "text/html"; char *m = "text/html";
char *retbuf = malloc(CMDLEN);
char *command, *arg; char *command, *arg;
char *ret = NULL; switch_stream_handle_t stream = {0};
if(strncmp(r->uri, "/api/", 5)) { if(strncmp(r->uri, "/api/", 5)) {
return FALSE; return FALSE;
@ -191,33 +218,22 @@ abyss_bool HandleHook(TSession *r)
} }
ResponseChunked(r); ResponseChunked(r);
ResponseStatus(r,200); ResponseStatus(r,200);
memset(retbuf, 0, CMDLEN);
switch_api_execute(command, arg, retbuf, CMDLEN);
if (!strncasecmp(retbuf, "content-type: ", 14)) {
m = retbuf + 14;
if ((ret = strchr(m, '\n'))) {
*ret++ = '\0';
}
}
if (!ret) {
ret = retbuf;
}
ResponseContentType(r, m); ResponseContentType(r, m);
ResponseWrite(r); ResponseWrite(r);
HTTPWrite(r, ret , strlen(ret)); stream.data = r;
stream.write_function = http_stream_write;
switch_api_execute(command, arg, &stream);
HTTPWriteEnd(r); HTTPWriteEnd(r);
free(command); free(command);
free(retbuf);
return TRUE; return TRUE;
} }
#define CMDLEN 1024 * 256
static xmlrpc_value *freeswitch_api(xmlrpc_env *const envP, xmlrpc_value *const paramArrayP, void *const userData) static xmlrpc_value *freeswitch_api(xmlrpc_env *const envP, xmlrpc_value *const paramArrayP, void *const userData)
{ {
char *command, *arg; char *command, *arg;
char *retbuf = malloc(CMDLEN); char *retbuf = malloc(CMDLEN);
switch_stream_handle_t stream = {0};
xmlrpc_value *val; xmlrpc_value *val;
/* Parse our argument array. */ /* Parse our argument array. */
@ -227,7 +243,11 @@ static xmlrpc_value *freeswitch_api(xmlrpc_env *const envP, xmlrpc_value *const
} }
memset(retbuf, 0, CMDLEN); memset(retbuf, 0, CMDLEN);
switch_api_execute(command, arg, retbuf, CMDLEN); stream.data = retbuf;
stream.end = stream.data;
stream.data_size = CMDLEN;
stream.write_function = switch_console_stream_write;
switch_api_execute(command, arg, &stream);
/* Return our result. */ /* Return our result. */
val = xmlrpc_build_value(envP, "s", retbuf); val = xmlrpc_build_value(envP, "s", retbuf);

View File

@ -33,10 +33,51 @@
#include <switch_console.h> #include <switch_console.h>
#define CMD_BUFLEN 1024 * 1000 #define CMD_BUFLEN 1024 * 1000
SWITCH_DECLARE(switch_status_t) switch_console_stream_write(switch_stream_handle_t *handle, char *fmt, ...)
{
va_list ap;
char *buf = handle->data;
char *end = handle->end;
int ret = 0;
char *data;
if (handle->data_len >= handle->data_size) {
return SWITCH_STATUS_FALSE;
}
va_start(ap, fmt);
#ifdef HAVE_VASPRINTF
ret = vasprintf(&data, fmt, ap);
#else
if ((data = (char *) malloc(2048))) {
vsnprintf(data, 2048, fmt, ap);
}
#endif
va_end(ap);
if (data) {
uint32_t len = handle->data_size - handle->data_len;
if (len <= strlen(data)) {
ret = -1;
} else {
ret = 0;
snprintf(end, len, data);
handle->data_len = strlen(buf);
handle->end = handle->data + handle->data_len;
}
free(data);
}
return ret ? SWITCH_STATUS_FALSE : SWITCH_STATUS_SUCCESS;
}
static int switch_console_process(char *cmd, char *retbuf, int retlen) static int switch_console_process(char *cmd, char *retbuf, int retlen)
{ {
char *arg = NULL; char *arg = NULL;
switch_stream_handle_t stream = {0};
if (!strcmp(cmd, "shutdown") || !strcmp(cmd, "...")) { if (!strcmp(cmd, "shutdown") || !strcmp(cmd, "...")) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Bye!\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Bye!\n");
@ -62,7 +103,11 @@ static int switch_console_process(char *cmd, char *retbuf, int retlen)
*arg++ = '\0'; *arg++ = '\0';
} }
if (switch_api_execute(cmd, arg, retbuf, retlen) == SWITCH_STATUS_SUCCESS) { stream.data = retbuf;
stream.end = stream.data;
stream.data_size = retlen;
stream.write_function = switch_console_stream_write;
if (switch_api_execute(cmd, arg, &stream) == SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_CONSOLE, "API CALL [%s(%s)] output:\n%s\n", cmd, arg ? arg : "", retbuf); switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_CONSOLE, "API CALL [%s(%s)] output:\n%s\n", cmd, arg ? arg : "", retbuf);
} else { } else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Unknown Command: %s\n", cmd); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Unknown Command: %s\n", cmd);

View File

@ -471,7 +471,7 @@ SWITCH_DECLARE(switch_status_t) switch_loadable_module_init()
switch_core_hash_init(&loadable_modules.directory_hash, loadable_modules.pool); switch_core_hash_init(&loadable_modules.directory_hash, loadable_modules.pool);
switch_core_hash_init(&loadable_modules.dialplan_hash, loadable_modules.pool); switch_core_hash_init(&loadable_modules.dialplan_hash, loadable_modules.pool);
if ((xml = switch_xml_open_cfg(cf, &cfg))) { if ((xml = switch_xml_open_cfg(cf, &cfg, NULL))) {
switch_xml_t mods, ld; switch_xml_t mods, ld;
if ((mods = switch_xml_child(cfg, "modules"))) { if ((mods = switch_xml_child(cfg, "modules"))) {
@ -491,7 +491,7 @@ SWITCH_DECLARE(switch_status_t) switch_loadable_module_init()
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "open of %s failed\n", cf); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "open of %s failed\n", cf);
} }
if ((xml = switch_xml_open_cfg(pcf, &cfg))) { if ((xml = switch_xml_open_cfg(pcf, &cfg, NULL))) {
switch_xml_t mods, ld; switch_xml_t mods, ld;
if ((mods = switch_xml_child(cfg, "modules"))) { if ((mods = switch_xml_child(cfg, "modules"))) {
@ -667,17 +667,22 @@ SWITCH_DECLARE(int) switch_loadable_module_get_codecs_sorted(switch_codec_interf
return i; return i;
} }
SWITCH_DECLARE(switch_status_t) switch_api_execute(char *cmd, char *arg, char *retbuf, switch_size_t len) SWITCH_DECLARE(switch_status_t) switch_api_execute(char *cmd, char *arg, switch_stream_handle_t *stream)
{ {
switch_api_interface_t *api; switch_api_interface_t *api;
switch_status_t status; switch_status_t status;
switch_event_t *event; switch_event_t *event;
assert(stream != NULL);
assert(stream->data != NULL);
assert(stream->write_function != NULL);
if ((api = switch_loadable_module_get_api_interface(cmd)) != 0) { if ((api = switch_loadable_module_get_api_interface(cmd)) != 0) {
status = api->function(arg, retbuf, len); status = api->function(arg, stream);
} else { } else {
status = SWITCH_STATUS_FALSE; status = SWITCH_STATUS_FALSE;
snprintf(retbuf, len, "INVALID COMMAND [%s]", cmd); stream->write_function(stream, "INVALID COMMAND [%s]", cmd);
//snprintf(retbuf, len, "INVALID COMMAND [%s]", cmd);
} }
if (switch_event_create(&event, SWITCH_EVENT_API) == SWITCH_STATUS_SUCCESS) { if (switch_event_create(&event, SWITCH_EVENT_API) == SWITCH_STATUS_SUCCESS) {
@ -687,7 +692,7 @@ SWITCH_DECLARE(switch_status_t) switch_api_execute(char *cmd, char *arg, char *r
if (arg) { if (arg) {
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "API-Command-Arguement", arg); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "API-Command-Arguement", arg);
} }
switch_event_add_body(event, retbuf); //switch_event_add_body(event, retbuf);
switch_event_fire(&event); switch_event_fire(&event);
} }

View File

@ -212,6 +212,51 @@ SWITCH_DECLARE(int) switch_socket_waitfor(switch_pollfd_t *poll, int ms)
return nsds; return nsds;
} }
SWITCH_DECLARE(int) switch_url_encode(char *url, char *buf, size_t len)
{
char *p;
int x = 0;
const char urlunsafe[] = " \"#%&+:;<=>?@[\\]^`{|}";
const char hex[] = "0123456789ABCDEF";
memset(buf, 0, len);
for( p = url ; *p ; p++) {
if (*p < ' ' || *p > '~' || strchr(urlunsafe, *p)) {
if ((x + 3) > len) {
break;
}
buf[x++] = '%';
buf[x++] = hex[*p >> 4];
buf[x++] = hex[*p & 0x0f];
} else {
buf[x++] = *p;
}
if (x == len) {
break;
}
}
return x;
}
SWITCH_DECLARE(char *) switch_url_decode(char *s)
{
char *o;
unsigned int tmp;
for (o = s; *s; s++, o++) {
if (*s == '%' && strlen(s) > 2 && sscanf(s + 1, "%2x", &tmp) == 1) {
*o = tmp;
s += 2;
} else {
*o = *s;
}
}
*o = '\0';
return s;
}
#ifdef WIN32 #ifdef WIN32
//this forces certain symbols to not be optimized out of the dll //this forces certain symbols to not be optimized out of the dll
void include_me(void) void include_me(void)

View File

@ -745,7 +745,8 @@ SWITCH_DECLARE(switch_status_t) switch_xml_locate(char *section,
char *key_name, char *key_name,
char *key_value, char *key_value,
switch_xml_t *root, switch_xml_t *root,
switch_xml_t *node) switch_xml_t *node,
char *params)
{ {
switch_xml_t conf = NULL; switch_xml_t conf = NULL;
switch_xml_t tag = NULL; switch_xml_t tag = NULL;
@ -756,7 +757,7 @@ SWITCH_DECLARE(switch_status_t) switch_xml_locate(char *section,
switch_mutex_lock(XML_LOCK); switch_mutex_lock(XML_LOCK);
for(binding = BINDINGS; binding; binding = binding->next) { for(binding = BINDINGS; binding; binding = binding->next) {
if ((xml = binding->function(section, tag_name, key_name, key_value))) { if ((xml = binding->function(section, tag_name, key_name, key_value, params))) {
const char *err = NULL; const char *err = NULL;
err = switch_xml_error(xml); err = switch_xml_error(xml);
@ -883,7 +884,7 @@ SWITCH_DECLARE(switch_status_t) switch_xml_destroy(void)
return SWITCH_STATUS_FALSE; return SWITCH_STATUS_FALSE;
} }
SWITCH_DECLARE(switch_xml_t) switch_xml_open_cfg(char *file_path, switch_xml_t *node) SWITCH_DECLARE(switch_xml_t) switch_xml_open_cfg(char *file_path, switch_xml_t *node, char *params)
{ {
switch_xml_t xml = NULL, cfg = NULL; switch_xml_t xml = NULL, cfg = NULL;
@ -891,7 +892,7 @@ SWITCH_DECLARE(switch_xml_t) switch_xml_open_cfg(char *file_path, switch_xml_t *
assert(MAIN_XML_ROOT != NULL); assert(MAIN_XML_ROOT != NULL);
if (switch_xml_locate("configuration", "configuration", "name", file_path, &xml, &cfg) == SWITCH_STATUS_SUCCESS) { if (switch_xml_locate("configuration", "configuration", "name", file_path, &xml, &cfg, params) == SWITCH_STATUS_SUCCESS) {
*node = cfg; *node = cfg;
} }