From ca481842569116305d1aad2fcb29ec2ebedbfac2 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 2 Sep 2010 16:41:09 -0500 Subject: [PATCH] strip trailing and leading whitespace in api execute args and commands --- src/switch_loadable_module.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/switch_loadable_module.c b/src/switch_loadable_module.c index ada05e7fed..0ef3624326 100644 --- a/src/switch_loadable_module.c +++ b/src/switch_loadable_module.c @@ -1683,27 +1683,34 @@ SWITCH_DECLARE(switch_status_t) switch_api_execute(const char *cmd, const char * { switch_api_interface_t *api; switch_status_t status; + char *arg_no_spaces; + char *cmd_no_spaces; switch_assert(stream != NULL); switch_assert(stream->data != NULL); switch_assert(stream->write_function != NULL); + + cmd_no_spaces = switch_strip_whitespace(cmd); + arg_no_spaces = switch_strip_whitespace(arg); + + if (!stream->param_event) { switch_event_create(&stream->param_event, SWITCH_EVENT_API); } if (stream->param_event) { - if (cmd) { - switch_event_add_header_string(stream->param_event, SWITCH_STACK_BOTTOM, "API-Command", cmd); + if (cmd_no_spaces) { + switch_event_add_header_string(stream->param_event, SWITCH_STACK_BOTTOM, "API-Command", cmd_no_spaces); } - if (arg) { - switch_event_add_header_string(stream->param_event, SWITCH_STACK_BOTTOM, "API-Command-Argument", arg); + if (arg_no_spaces) { + switch_event_add_header_string(stream->param_event, SWITCH_STACK_BOTTOM, "API-Command-Argument", arg_no_spaces); } } - if (cmd && (api = switch_loadable_module_get_api_interface(cmd)) != 0) { - if ((status = api->function(arg, session, stream)) != SWITCH_STATUS_SUCCESS) { + if (cmd_no_spaces && (api = switch_loadable_module_get_api_interface(cmd_no_spaces)) != 0) { + if ((status = api->function(arg_no_spaces, session, stream)) != SWITCH_STATUS_SUCCESS) { stream->write_function(stream, "COMMAND RETURNED ERROR!\n"); } UNPROTECT_INTERFACE(api); @@ -1716,6 +1723,8 @@ SWITCH_DECLARE(switch_status_t) switch_api_execute(const char *cmd, const char * switch_event_fire(&stream->param_event); } + switch_safe_free(cmd_no_spaces); + switch_safe_free(arg_no_spaces); return status; }