diff options
author | markster <markster@f38db490-d61c-443f-a65b-d21fe96a405b> | 2000-01-02 20:59:00 +0000 |
---|---|---|
committer | markster <markster@f38db490-d61c-443f-a65b-d21fe96a405b> | 2000-01-02 20:59:00 +0000 |
commit | 999d3524e27900ec85d461f644d0e2fde138fca4 (patch) | |
tree | 53bb1d4c35295fea70d6179bfa71cd1e10d402df /apps | |
parent | 2137f5008cf14c94312348e272f9b38df43233e1 (diff) |
Version 0.1.2 from FTP
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@152 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'apps')
-rwxr-xr-x | apps/Makefile | 2 | ||||
-rwxr-xr-x | apps/app_echo.c | 80 | ||||
-rwxr-xr-x | apps/app_skel.c | 50 | ||||
-rwxr-xr-x | apps/app_system.c | 82 | ||||
-rwxr-xr-x | apps/app_voicemail.c | 33 |
5 files changed, 198 insertions, 49 deletions
diff --git a/apps/Makefile b/apps/Makefile index 773eb535f..fd5eaac36 100755 --- a/apps/Makefile +++ b/apps/Makefile @@ -11,7 +11,7 @@ # the GNU General Public License # -APPS=app_dial.so app_playback.so app_voicemail.so app_directory.so app_intercom.so app_mp3.so +APPS=app_dial.so app_playback.so app_voicemail.so app_directory.so app_intercom.so app_mp3.so app_system.so app_echo.so CFLAGS+= diff --git a/apps/app_echo.c b/apps/app_echo.c new file mode 100755 index 000000000..370dc6863 --- /dev/null +++ b/apps/app_echo.c @@ -0,0 +1,80 @@ +/* + * Asterisk -- A telephony toolkit for Linux. + * + * Echo application -- play back what you hear to evaluate latency + * + * Copyright (C) 1999, Mark Spencer + * + * Mark Spencer <markster@linux-support.net> + * + * This program is free software, distributed under the terms of + * the GNU General Public License + */ + +#include <asterisk/file.h> +#include <asterisk/logger.h> +#include <asterisk/channel.h> +#include <asterisk/pbx.h> +#include <asterisk/module.h> +#include <stdlib.h> +#include <unistd.h> +#include <string.h> +#include <stdlib.h> + +#include <pthread.h> + + +static char *tdesc = "Simple Echo Application"; + +static char *app = "Echo"; + +STANDARD_LOCAL_USER; + +LOCAL_USER_DECL; + +static int skel_exec(struct ast_channel *chan, void *data) +{ + int res=-1; + struct localuser *u; + struct ast_frame *f; + LOCAL_USER_ADD(u); + /* Do our thing here */ + while((f = ast_read(chan))) { + if (f->frametype == AST_FRAME_VOICE) { + if (ast_write(chan, f)) + break; + } else if (f->frametype == AST_FRAME_DTMF) { + if (f->subclass == '#') { + res = 0; + break; + } else + if (ast_write(chan, f)) + break; + } + } + LOCAL_USER_REMOVE(u); + return res; +} + +int unload_module(void) +{ + STANDARD_HANGUP_LOCALUSERS; + return ast_unregister_application(app); +} + +int load_module(void) +{ + return ast_register_application(app, skel_exec); +} + +char *description(void) +{ + return tdesc; +} + +int usecount(void) +{ + int res; + STANDARD_USECOUNT(res); + return res; +} diff --git a/apps/app_skel.c b/apps/app_skel.c index e766d1142..419b8f40a 100755 --- a/apps/app_skel.c +++ b/apps/app_skel.c @@ -15,6 +15,7 @@ #include <asterisk/logger.h> #include <asterisk/channel.h> #include <asterisk/pbx.h> +#include <asterisk/module.h> #include <stdlib.h> #include <unistd.h> #include <string.h> @@ -22,63 +23,32 @@ #include <pthread.h> -static pthread_mutex_t skellock = PTHREAD_MUTEX_INITIALIZER; - -static int usecnt=0; static char *tdesc = "Trivial skeleton Application"; static char *app = "skel"; -struct skeluser { - struct ast_channel *chan; - struct skeluser *next; -} *users = NULL; +STANDARD_LOCAL_USER; + +LOCAL_USER_DECL; static int skel_exec(struct ast_channel *chan, void *data) { int res=0; - struct skeluser *u, *ul=NULL; + struct localuser *u; if (!data) { ast_log(LOG_WARNING, "skel requires an argument (filename)\n"); return -1; } - if (!(u=malloc(sizeof(struct skeluser)))) { - ast_log(LOG_WARNING, "Out of memory\n"); - return -1; - } - pthread_mutex_lock(&skellock); - u->chan = chan; - u->next = users; - users = u; - usecnt++; - pthread_mutex_unlock(&skellock); + LOCAL_USER_ADD(u); /* Do our thing here */ - pthread_mutex_lock(&skellock); - u = users; - while(u) { - if (ul) - ul->next = u->next; - else - users = u->next; - u = u->next; - } - usecnt--; - pthread_mutex_unlock(&skellock); + LOCAL_USER_REMOVE(u); return res; } int unload_module(void) { - struct skeluser *u; - pthread_mutex_lock(&skellock); - u = users; - while(u) { - /* Hang up anybody who is using us */ - ast_softhangup(u->chan); - u = u->next; - } - pthread_mutex_unlock(&skellock); + STANDARD_HANGUP_LOCALUSERS; return ast_unregister_application(app); } @@ -95,8 +65,6 @@ char *description(void) int usecount(void) { int res; - pthread_mutex_lock(&skellock); - res = usecnt; - pthread_mutex_unlock(&skellock); + STANDARD_USECOUNT(res); return res; } diff --git a/apps/app_system.c b/apps/app_system.c new file mode 100755 index 000000000..7e140a427 --- /dev/null +++ b/apps/app_system.c @@ -0,0 +1,82 @@ +/* + * Asterisk -- A telephony toolkit for Linux. + * + * Execute arbitrary system commands + * + * Copyright (C) 1999, Mark Spencer + * + * Mark Spencer <markster@linux-support.net> + * + * This program is free software, distributed under the terms of + * the GNU General Public License + */ + +#include <asterisk/file.h> +#include <asterisk/logger.h> +#include <asterisk/channel.h> +#include <asterisk/pbx.h> +#include <asterisk/module.h> +#include <stdlib.h> +#include <unistd.h> +#include <string.h> +#include <stdlib.h> + +#include <pthread.h> + + +static char *tdesc = "Generic System() application"; + +static char *app = "System"; + +STANDARD_LOCAL_USER; + +LOCAL_USER_DECL; + +static int skel_exec(struct ast_channel *chan, void *data) +{ + int res=0; + struct localuser *u; + if (!data) { + ast_log(LOG_WARNING, "System requires an argument(command)\n"); + return -1; + } + LOCAL_USER_ADD(u); + /* Do our thing here */ + res = system((char *)data); + if (res < 0) { + ast_log(LOG_WARNING, "Unable to execute '%s'\n", data); + res = -1; + } else if (res == 127) { + ast_log(LOG_WARNING, "Unable to execute '%s'\n", data); + res = -1; + } else { + if (res && ast_exists_extension(chan, chan->context, chan->exten, chan->priority + 101)) + chan->priority+=100; + res = 0; + } + LOCAL_USER_REMOVE(u); + return res; +} + +int unload_module(void) +{ + STANDARD_HANGUP_LOCALUSERS; + return ast_unregister_application(app); +} + +int load_module(void) +{ + return ast_register_application(app, skel_exec); +} + +char *description(void) +{ + return tdesc; +} + +int usecount(void) +{ + int res; + STANDARD_USECOUNT(res); + return res; +} diff --git a/apps/app_voicemail.c b/apps/app_voicemail.c index f2893b3f6..8fc6f500f 100755 --- a/apps/app_voicemail.c +++ b/apps/app_voicemail.c @@ -141,7 +141,7 @@ static int leave_voicemail(struct ast_channel *chan, char *ext, int silent) struct ast_config *cfg; char *copy, *name, *passwd, *email, *dir, *fmt, *fmts, *fn=NULL; char comment[256]; - struct ast_filestream *writer, *others[MAX_OTHER_FORMATS]; + struct ast_filestream *writer=NULL, *others[MAX_OTHER_FORMATS]; char *sfmt[MAX_OTHER_FORMATS]; int res = -1, fmtcnt=0, x; int msgnum; @@ -182,8 +182,12 @@ static int leave_voicemail(struct ast_channel *chan, char *ext, int silent) snprintf(comment, sizeof(comment), "Voicemail from %s to %s (%s) on %s\n", (chan->callerid ? chan->callerid : "Unknown"), name, ext, chan->name); + if (ast_fileexists(fn, NULL) > 0) { + msgnum++; + continue; + } writer = ast_writefile(fn, fmt, comment, O_EXCL, 1 /* check for other formats */, 0700); - if (!writer && (errno != EEXIST)) + if (!writer) break; msgnum++; } while(!writer && (msgnum < MAXMSG)); @@ -221,9 +225,14 @@ static int leave_voicemail(struct ast_channel *chan, char *ext, int silent) if (f->frametype == AST_FRAME_VOICE) { /* Write the primary format */ res = ast_writestream(writer, f); + if (res) { + ast_log(LOG_WARNING, "Error writing primary frame\n"); + break; + } /* And each of the others */ - for (x=0;x<fmtcnt;x++) + for (x=0;x<fmtcnt;x++) { res |= ast_writestream(others[x], f); + } ast_frfree(f); /* Exit on any error */ if (res) { @@ -314,20 +323,30 @@ static int vm_execmain(struct ast_channel *chan, void *data) ast_log(LOG_WARNING, "No voicemail configuration\n"); goto out; } - if (ast_streamfile(chan, "vm-login")) + if (ast_streamfile(chan, "vm-login")) { + ast_log(LOG_WARNING, "Couldn't stream login file\n"); goto out; + } do { /* Prompt for, and read in the username */ - if (ast_readstring(chan, username, sizeof(username), 2000, 5000, "#")) + if (ast_readstring(chan, username, sizeof(username), 2000, 5000, "#")) { + ast_log(LOG_WARNING, "Couldn't read username\n"); goto out; + } if (!strlen(username)) { + if (option_verbose > 2) + ast_verbose(VERBOSE_PREFIX_3 "Username not entered\n"); res = 0; goto out; } - if (ast_streamfile(chan, "vm-password")) + if (ast_streamfile(chan, "vm-password")) { + ast_log(LOG_WARNING, "Unable to stream password file\n"); goto out; - if (ast_readstring(chan, password, sizeof(password), 2000, 5000, "#")) + } + if (ast_readstring(chan, password, sizeof(password), 2000, 5000, "#")) { + ast_log(LOG_WARNING, "Unable to read password\n"); goto out; + } copy = ast_variable_retrieve(cfg, NULL, username); if (copy) { copy = strdup(copy); |