remove more unnecessary casts for NULL.
[asterisk/asterisk.git] / apps / app_dictate.c
index 871fc5a..58d6111 100644 (file)
  * \ingroup applications
  */
 
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-#include <sys/stat.h>  /* for mkdir */
-
 #include "asterisk.h"
 
 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 
+#include <sys/stat.h>
+
+#include "asterisk/paths.h"    /* use ast_config_AST_SPOOL_DIR */
 #include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/channel.h"
 #include "asterisk/pbx.h"
 #include "asterisk/module.h"
 #include "asterisk/say.h"
-#include "asterisk/lock.h"
 #include "asterisk/app.h"
 
-static char *tdesc = "Virtual Dictation Machine";
 static char *app = "Dictate";
 static char *synopsis = "Virtual Dictation Machine";
-static char *desc = "  Dictate([<base_dir>[|<filename>]])\n"
+static char *desc = "  Dictate([<base_dir>[,<filename>]])\n"
 "Start dictation machine using optional base dir for files.\n";
 
-LOCAL_USER_DECL;
 
 typedef enum {
        DFLAG_RECORD = (1 << 0),
@@ -91,7 +83,6 @@ static int dictate_exec(struct ast_channel *chan, void *data)
        struct ast_flags flags = {0};
        struct ast_filestream *fs;
        struct ast_frame *f = NULL;
-       struct localuser *u;
        int ffactor = 320 * 80,
                res = 0,
                done = 0,
@@ -103,13 +94,10 @@ static int dictate_exec(struct ast_channel *chan, void *data)
                len = 0,
                maxlen = 0,
                mode = 0;
-               
-       LOCAL_USER_ADD(u);
        
        snprintf(dftbase, sizeof(dftbase), "%s/dictate", ast_config_AST_SPOOL_DIR);
        if (!ast_strlen_zero(data)) {
-               if (!(parse = ast_strdupa(data)))
-                       return -1;
+               parse = ast_strdupa(data);
                AST_STANDARD_APP_ARGS(args, parse);
        } else
                args.argc = 0;
@@ -125,7 +113,6 @@ static int dictate_exec(struct ast_channel *chan, void *data)
        oldr = chan->readformat;
        if ((res = ast_set_read_format(chan, AST_FORMAT_SLINEAR)) < 0) {
                ast_log(LOG_WARNING, "Unable to set to linear mode.\n");
-               LOCAL_USER_REMOVE(u);
                return -1;
        }
 
@@ -142,7 +129,7 @@ static int dictate_exec(struct ast_channel *chan, void *data)
                        ast_copy_string(filein, filename, sizeof(filein));
                        filename = "";
                }
-               mkdir(base, 0755);
+               ast_mkdir(base, 0755);
                len = strlen(base) + strlen(filein) + 2;
                if (!path || len > maxlen) {
                        path = alloca(len);
@@ -153,7 +140,7 @@ static int dictate_exec(struct ast_channel *chan, void *data)
                }
 
                snprintf(path, len, "%s/%s", base, filein);
-               fs = ast_writefile(path, "raw", NULL, O_CREAT|O_APPEND, 0, 0700);
+               fs = ast_writefile(path, "raw", NULL, O_CREAT|O_APPEND, 0, AST_FILE_MODE);
                mode = DMODE_PLAY;
                memset(&flags, 0, sizeof(flags));
                ast_set_flag(&flags, DFLAG_PAUSE);
@@ -183,7 +170,7 @@ static int dictate_exec(struct ast_channel *chan, void *data)
                                                if (speed > 4) {
                                                        speed = 1;
                                                }
-                                               res = ast_say_number(chan, speed, AST_DIGIT_ANY, chan->language, (char *) NULL);
+                                               res = ast_say_number(chan, speed, AST_DIGIT_ANY, chan->language, NULL);
                                                break;
                                        case '7':
                                                samples -= ffactor;
@@ -270,7 +257,8 @@ static int dictate_exec(struct ast_channel *chan, void *data)
                                                if (lastop != DFLAG_PLAY) {
                                                        lastop = DFLAG_PLAY;
                                                        ast_closestream(fs);
-                                                       fs = ast_openstream(chan, path, chan->language);
+                                                       if (!(fs = ast_openstream(chan, path, chan->language)))
+                                                               break;
                                                        ast_seekstream(fs, samples, SEEK_SET);
                                                        chan->stream = NULL;
                                                }
@@ -310,7 +298,7 @@ static int dictate_exec(struct ast_channel *chan, void *data)
                                                } else {
                                                        oflags |= O_APPEND;
                                                }
-                                               fs = ast_writefile(path, "raw", NULL, oflags, 0, 0700);
+                                               fs = ast_writefile(path, "raw", NULL, oflags, 0, AST_FILE_MODE);
                                                if (ast_test_flag(&flags, DFLAG_TRUNC)) {
                                                        ast_seekstream(fs, 0, SEEK_SET);
                                                        ast_clear_flag(&flags, DFLAG_TRUNC);
@@ -332,40 +320,19 @@ static int dictate_exec(struct ast_channel *chan, void *data)
        if (oldr) {
                ast_set_read_format(chan, oldr);
        }
-       LOCAL_USER_REMOVE(u);
-       return res;
+       return 0;
 }
 
-int unload_module(void)
+static int unload_module(void)
 {
        int res;
-
        res = ast_unregister_application(app);
-       
-       STANDARD_HANGUP_LOCALUSERS;
-       
        return res;
 }
 
-int load_module(void)
+static int load_module(void)
 {
        return ast_register_application(app, dictate_exec, synopsis, desc);
 }
 
-const char *description(void)
-{
-       return tdesc;
-}
-
-int usecount(void)
-{
-       int res;
-       STANDARD_USECOUNT(res);
-       return res;
-}
-
-const char *key()
-{
-       return ASTERISK_GPL_KEY;
-}
-
+AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Virtual Dictation Machine");