diff --git a/src/include/switch_scheduler.h b/src/include/switch_scheduler.h index beff65f9f9..2241247ea7 100644 --- a/src/include/switch_scheduler.h +++ b/src/include/switch_scheduler.h @@ -67,16 +67,16 @@ SWITCH_DECLARE(uint32_t) switch_scheduler_add_task(time_t task_runtime, /*! \brief Delete a scheduled task \param task_id the id of the task - \return SWITCH_STATUS_SUCCESS if the task was deleted. + \return the number of jobs deleted */ -SWITCH_DECLARE(switch_status_t) switch_scheduler_del_task_id(uint32_t task_id); +SWITCH_DECLARE(uint32_t) switch_scheduler_del_task_id(uint32_t task_id); /*! \brief Delete a scheduled task based on the group name \param group the group name - \return SWITCH_STATUS_SUCCESS if any tasks were deleted + \return the number of jobs deleted */ -SWITCH_DECLARE(switch_status_t) switch_scheduler_del_task_group(char *group); +SWITCH_DECLARE(uint32_t) switch_scheduler_del_task_group(char *group); /*! diff --git a/src/include/switch_types.h b/src/include/switch_types.h index 4bf208053f..3465d60eb7 100644 --- a/src/include/switch_types.h +++ b/src/include/switch_types.h @@ -158,7 +158,8 @@ typedef enum { typedef enum { SSHF_NONE = 0, SSHF_OWN_THREAD = (1 << 0), - SSHF_FREE_ARG = (1 << 1) + SSHF_FREE_ARG = (1 << 1), + SSHF_NO_DEL = (1 << 2) } switch_scheduler_flag_t; typedef enum { diff --git a/src/include/switch_utils.h b/src/include/switch_utils.h index e88b15fb67..ce664352d4 100644 --- a/src/include/switch_utils.h +++ b/src/include/switch_utils.h @@ -54,6 +54,19 @@ SWITCH_BEGIN_EXTERN_C #else #define switch_is_file_path(file) ((*file == '/') || strstr(file, SWITCH_URL_SEPARATOR)) #endif + +static inline switch_bool_t switch_is_digit_string(char *s) { + + while(s && *s) { + if (*s < 48 || *s > 57) { + return SWITCH_FALSE; + } + s++; + } + + return SWITCH_TRUE; +} + /*! \brief Evaluate the truthfullness of a string expression \param expr a string expression diff --git a/src/mod/applications/mod_commands/mod_commands.c b/src/mod/applications/mod_commands/mod_commands.c index bd416f5eb6..8223e38911 100644 --- a/src/mod/applications/mod_commands/mod_commands.c +++ b/src/mod/applications/mod_commands/mod_commands.c @@ -705,6 +705,25 @@ static void sch_api_callback(switch_scheduler_task_t *task) switch_safe_free(stream.data); } +static switch_status_t sched_del_function(char *cmd, switch_core_session_t *isession, switch_stream_handle_t *stream) +{ + uint32_t cnt = 0; + + if (switch_is_digit_string(cmd)) { + int64_t tmp; + tmp = (uint32_t) atoi(cmd); + if (tmp > 0) { + cnt = switch_scheduler_del_task_id((uint32_t)tmp); + } + } else { + cnt = switch_scheduler_del_task_group(cmd); + } + + stream->write_function(stream, "DELETED: %u\n", cnt); + + return SWITCH_STATUS_SUCCESS; +} + static switch_status_t sched_api_function(char *cmd, switch_core_session_t *isession, switch_stream_handle_t *stream) { char *tm = NULL, *dcmd, *group; @@ -729,7 +748,7 @@ static switch_status_t sched_api_function(char *cmd, switch_core_session_t *ises } id = switch_scheduler_add_task(when, sch_api_callback, (char *) __SWITCH_FUNC__, group, 0, strdup(dcmd), SSHF_FREE_ARG); - stream->write_function(stream, "Added task %u for command [%s] group [%s]\n", id, dcmd, group); + stream->write_function(stream, "ADDED: %u\n", id); goto good; } } @@ -895,12 +914,20 @@ static switch_status_t help_function(char *cmd, switch_core_session_t *session, return SWITCH_STATUS_SUCCESS; } +static switch_api_interface_t sched_del_api_interface = { + /*.interface_name */ "sched_del", + /*.desc */ "Delete a Scheduled task", + /*.function */ sched_del_function, + /*.syntax */ "|", + /*.next */ NULL +}; + static switch_api_interface_t sched_api_api_interface = { /*.interface_name */ "sched_api", /*.desc */ "Schedule an api command", /*.function */ sched_api_function, /*.syntax */ "[+]