--- ../asterisk_1.2/apps/app_mixmonitor.c 2006-01-12 19:50:05.000000000 -0300 +++ apps/app_mixmonitor.c 2006-01-12 20:17:29.000000000 -0300 @@ -72,6 +72,15 @@ "The variable MIXMONITOR_FILENAME will contain the filename used to record.\n" ""; +static const char *stop_app = "StopMixMonitor"; +static const char *stop_synopsis = "Stop recording a call through MixMonitor"; +static const char *stop_desc = "" +" StopMixMonitor()\n\n" +"Stops the audio recording that was started with a call to MixMonitor()\n" +"on the current channel.\n" +""; + + STANDARD_LOCAL_USER; LOCAL_USER_DECL; @@ -393,6 +402,18 @@ return 0; } +static int stop_mixmonitor_exec(struct ast_channel *chan, void *data) +{ + if (ast_mutex_lock(&chan->lock) == 0) { + ast_channel_spy_stop_by_type(chan, mixmonitor_spy_type); + ast_mutex_unlock(&chan->lock); + } else { + ast_log(LOG_WARNING, "Could not lock %s to stop MixMonitor on it\n", + chan->name); + } + return 0; +} + static int mixmonitor_cli(int fd, int argc, char **argv) { struct ast_channel *chan; @@ -415,20 +436,53 @@ return RESULT_SUCCESS; } +static char *complete_mixmonitor_cli(char *line, char *word, int pos, int state) +{ + char *ret = NULL; -static struct ast_cli_entry cli_mixmonitor = { - { "mixmonitor", NULL, NULL }, + /* Channel name completion */ + if (pos == 2) { + struct ast_channel *c = NULL; + int which = 0; + int word_len = strlen(word); + + while ((c = ast_channel_walk_locked(c)) != NULL) { + if (!strncasecmp(word, c->name, word_len)) { + if (++which > state) { + ret = strdup(c->name); + ast_mutex_unlock(&c->lock); + break; + } + } + ast_mutex_unlock(&c->lock); + } + } + return ret; +} + +static struct ast_cli_entry cli_start_mixmonitor = { + { "mixmonitor", "start", NULL }, mixmonitor_cli, - "Execute a MixMonitor command", - "mixmonitor []\n" + "Start MixMonitor on a channel", + "mixmonitor start []\n", + complete_mixmonitor_cli }; +static struct ast_cli_entry cli_stop_mixmonitor = { + { "mixmonitor", "stop", NULL }, + mixmonitor_cli, + "Stop MixMonitor on a channel", + "mixmonitor stop []\n", + complete_mixmonitor_cli +}; int unload_module(void) { int res; - res = ast_cli_unregister(&cli_mixmonitor); + res = ast_cli_unregister(&cli_stop_mixmonitor); + res |= ast_cli_unregister(&cli_start_mixmonitor); + res |= ast_unregister_application(stop_app); res |= ast_unregister_application(app); STANDARD_HANGUP_LOCALUSERS; @@ -440,8 +494,10 @@ { int res; - res = ast_cli_register(&cli_mixmonitor); + res = ast_cli_register(&cli_start_mixmonitor); + res |= ast_cli_register(&cli_stop_mixmonitor); res |= ast_register_application(app, mixmonitor_exec, synopsis, desc); + res |= ast_register_application(stop_app, stop_mixmonitor_exec, stop_synopsis, stop_desc); return res; }