Applications no longer need to call ast_module_user_add and ast_module_user_remove...
[asterisk/asterisk.git] / apps / app_dictate.c
index b77a389..566ff0f 100644 (file)
@@ -51,7 +51,6 @@ static char *synopsis = "Virtual Dictation Machine";
 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),
@@ -90,7 +89,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,
@@ -102,8 +100,6 @@ 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)) {
@@ -123,7 +119,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;
        }
 
@@ -140,7 +135,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);
@@ -151,7 +146,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);
@@ -268,7 +263,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;
                                                }
@@ -308,7 +304,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);
@@ -330,31 +326,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;
 }
 
-static int unload_module(void *mod)
+static int unload_module(void)
 {
        int res;
        res = ast_unregister_application(app);
        return res;
 }
 
-static int load_module(void *mod)
+static int load_module(void)
 {
-       __mod_desc = mod;
        return ast_register_application(app, dictate_exec, synopsis, desc);
 }
 
-static const char *description(void)
-{
-       return "Virtual Dictation Machine";
-}
-
-static const char *key(void)
-{
-       return ASTERISK_GPL_KEY;
-}
-
-STD_MOD(MOD_1, NULL, NULL, NULL);
+AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Virtual Dictation Machine");