]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
strip trailing and leading whitespace in api execute args and commands
authorAnthony Minessale <anthm@freeswitch.org>
Thu, 2 Sep 2010 21:41:09 +0000 (16:41 -0500)
committerAnthony Minessale <anthm@freeswitch.org>
Thu, 2 Sep 2010 21:41:09 +0000 (16:41 -0500)
src/switch_loadable_module.c

index ada05e7fed0d459334aec0422bdc9d4eba193e27..0ef3624326ded0285d1013c346621884f0588bad 100644 (file)
@@ -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;
 }