Merged revisions 73316 via svnmerge from
[asterisk/asterisk.git] / apps / app_sayunixtime.c
old mode 100755 (executable)
new mode 100644 (file)
index 9c126a1..2e9c9b3
@@ -1,7 +1,8 @@
 /*
  * Asterisk -- An open source telephony toolkit.
  *
- * Copyright (c) 2003 Tilghman Lesher.  All rights reserved.
+ * Copyright (c) 2003, 2006 Tilghman Lesher.  All rights reserved.
+ * Copyright (c) 2006 Digium, Inc.
  *
  * Tilghman Lesher <app_sayunixtime__200309@the-tilghman.com>
  *
 /*! \file
  *
  * \brief SayUnixTime application
+ *
+ * \author Tilghman Lesher <app_sayunixtime__200309@the-tilghman.com>
  * 
+ * \ingroup applications
  */
 
+#include "asterisk.h"
+
+ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
 #include <string.h>
 
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
 #include "asterisk/file.h"
 #include "asterisk/logger.h"
 #include "asterisk/options.h"
@@ -37,9 +41,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 #include "asterisk/pbx.h"
 #include "asterisk/module.h"
 #include "asterisk/say.h"
-
-
-static char *tdesc = "Say time";
+#include "asterisk/app.h"
 
 static char *app_sayunixtime = "SayUnixTime";
 static char *app_datetime = "DateTime";
@@ -53,8 +55,7 @@ static char *sayunixtime_descrip =
 "  timezone: timezone, see /usr/share/zoneinfo for a list.\n"
 "              defaults to machine default.\n"
 "  format:   a format the time is to be said in.  See voicemail.conf.\n"
-"              defaults to \"ABdY 'digits/at' IMp\"\n"
-"  Returns 0 or -1 on hangup.\n";
+"              defaults to \"ABdY 'digits/at' IMp\"\n";
 static char *datetime_descrip =
 "DateTime([unixtime][|[timezone][|format]])\n"
 "  unixtime: time, in seconds since Jan 1, 1970.  May be negative.\n"
@@ -62,81 +63,57 @@ static char *datetime_descrip =
 "  timezone: timezone, see /usr/share/zoneinfo for a list.\n"
 "              defaults to machine default.\n"
 "  format:   a format the time is to be said in.  See voicemail.conf.\n"
-"              defaults to \"ABdY 'digits/at' IMp\"\n"
-"  Returns 0 or -1 on hangup.\n";
-
-STANDARD_LOCAL_USER;
+"              defaults to \"ABdY 'digits/at' IMp\"\n";
 
-LOCAL_USER_DECL;
 
 static int sayunixtime_exec(struct ast_channel *chan, void *data)
 {
-       int res=0;
-       struct localuser *u;
-       char *s,*zone=NULL,*timec,*format;
+       AST_DECLARE_APP_ARGS(args,
+                            AST_APP_ARG(timeval);
+                            AST_APP_ARG(timezone);
+                            AST_APP_ARG(format);
+       );
+       char *parse;
+       int res = 0;
+       struct ast_module_user *u;
        time_t unixtime;
-       struct timeval tv;
        
-       LOCAL_USER_ADD(u);
-
-       tv = ast_tvnow();
-       unixtime = (time_t)tv.tv_sec;
-
-       if( !strcasecmp(chan->language, "da" ) ) {
-               format = "A dBY HMS";
-       } else if ( !strcasecmp(chan->language, "de" ) ) {
-               format = "A dBY HMS";
-       } else {
-               format = "ABdY 'digits/at' IMp";
-       } 
-
-       if (data) {
-               s = data;
-               s = ast_strdupa(s);
-               if (s) {
-                       timec = strsep(&s,"|");
-                       if ((timec) && (*timec != '\0')) {
-                               long timein;
-                               if (sscanf(timec,"%ld",&timein) == 1) {
-                                       unixtime = (time_t)timein;
-                               }
-                       }
-                       if (s) {
-                               zone = strsep(&s,"|");
-                               if (zone && (*zone == '\0'))
-                                       zone = NULL;
-                               if (s) {
-                                       format = s;
-                               }
-                       }
-               } else {
-                       ast_log(LOG_ERROR, "Out of memory error\n");
-               }
-       }
-
-       if (chan->_state != AST_STATE_UP) {
+       if (!data)
+               return 0;
+
+       parse = ast_strdupa(data);
+
+       u = ast_module_user_add(chan);
+
+       AST_STANDARD_APP_ARGS(args, parse);
+
+       ast_get_time_t(args.timeval, &unixtime, time(NULL), NULL);
+
+       if (chan->_state != AST_STATE_UP)
                res = ast_answer(chan);
-       }
+
        if (!res)
-               res = ast_say_date_with_format(chan, unixtime, AST_DIGIT_ANY, chan->language, format, zone);
+               res = ast_say_date_with_format(chan, unixtime, AST_DIGIT_ANY,
+                                              chan->language, args.format, args.timezone);
+
+       ast_module_user_remove(u);
 
-       LOCAL_USER_REMOVE(u);
        return res;
 }
 
-int unload_module(void)
+static int unload_module(void)
 {
        int res;
        
        res = ast_unregister_application(app_sayunixtime);
        res |= ast_unregister_application(app_datetime);
 
-       STANDARD_HANGUP_LOCALUSERS;
+       ast_module_user_hangup_all();
        
        return res;
 }
 
-int load_module(void)
+static int load_module(void)
 {
        int res;
        
@@ -146,19 +123,4 @@ int load_module(void)
        return res;
 }
 
-char *description(void)
-{
-       return tdesc;
-}
-
-int usecount(void)
-{
-       int res;
-       STANDARD_USECOUNT(res);
-       return res;
-}
-
-char *key()
-{
-       return ASTERISK_GPL_KEY;
-}
+AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Say time");