use double-quotes instead of angle-brackets for non-system include files (bug #4058)
[asterisk/asterisk.git] / apps / app_sayunixtime.c
1 /*
2  * Asterisk -- A telephony toolkit for Linux.
3  *
4  * SayUnixTime application
5  * 
6  * Copyright (c) 2003 Tilghman Lesher.  All rights reserved.
7  *
8  * Tilghman Lesher <app_sayunixtime__200309@the-tilghman.com>
9  *
10  * This code is released by the author with no restrictions on usage.
11  *
12  */
13
14 #include <stdio.h>
15 #include <stdlib.h>
16 #include <unistd.h>
17 #include <string.h>
18 #include "asterisk/file.h"
19 #include "asterisk/logger.h"
20 #include "asterisk/options.h"
21 #include "asterisk/channel.h"
22 #include "asterisk/pbx.h"
23 #include "asterisk/module.h"
24 #include "asterisk/say.h"
25
26
27 static char *tdesc = "Say time";
28
29 static char *app_sayunixtime = "SayUnixTime";
30 static char *app_datetime = "DateTime";
31
32 static char *sayunixtime_synopsis = "Says a specified time in a custom format";
33
34 static char *sayunixtime_descrip =
35 "SayUnixTime([unixtime][|[timezone][|format]])\n"
36 "  unixtime: time, in seconds since Jan 1, 1970.  May be negative.\n"
37 "              defaults to now.\n"
38 "  timezone: timezone, see /usr/share/zoneinfo for a list.\n"
39 "              defaults to machine default.\n"
40 "  format:   a format the time is to be said in.  See voicemail.conf.\n"
41 "              defaults to \"ABdY 'digits/at' IMp\"\n"
42 "  Returns 0 or -1 on hangup.\n";
43 static char *datetime_descrip =
44 "DateTime([unixtime][|[timezone][|format]])\n"
45 "  unixtime: time, in seconds since Jan 1, 1970.  May be negative.\n"
46 "              defaults to now.\n"
47 "  timezone: timezone, see /usr/share/zoneinfo for a list.\n"
48 "              defaults to machine default.\n"
49 "  format:   a format the time is to be said in.  See voicemail.conf.\n"
50 "              defaults to \"ABdY 'digits/at' IMp\"\n"
51 "  Returns 0 or -1 on hangup.\n";
52
53 STANDARD_LOCAL_USER;
54
55 LOCAL_USER_DECL;
56
57 static int sayunixtime_exec(struct ast_channel *chan, void *data)
58 {
59         int res=0;
60         struct localuser *u;
61         char *s,*zone=NULL,*timec,*format;
62         time_t unixtime;
63         struct timeval tv;
64         
65         LOCAL_USER_ADD(u);
66
67         gettimeofday(&tv,NULL);
68         unixtime = (time_t)tv.tv_sec;
69
70         if( !strcasecmp(chan->language, "de" ) ) {
71                 format = "A dBY HMS";
72         } else {
73                 format = "ABdY 'digits/at' IMp";
74         } 
75
76         if (data) {
77                 s = data;
78                 s = ast_strdupa(s);
79                 if (s) {
80                         timec = strsep(&s,"|");
81                         if ((timec) && (*timec != '\0')) {
82                                 long timein;
83                                 if (sscanf(timec,"%ld",&timein) == 1) {
84                                         unixtime = (time_t)timein;
85                                 }
86                         }
87                         if (s) {
88                                 zone = strsep(&s,"|");
89                                 if (zone && (*zone == '\0'))
90                                         zone = NULL;
91                                 if (s) {
92                                         format = s;
93                                 }
94                         }
95                 } else {
96                         ast_log(LOG_ERROR, "Out of memory error\n");
97                 }
98         }
99
100         if (chan->_state != AST_STATE_UP) {
101                 res = ast_answer(chan);
102         }
103         if (!res)
104                 res = ast_say_date_with_format(chan, unixtime, AST_DIGIT_ANY, chan->language, format, zone);
105
106         LOCAL_USER_REMOVE(u);
107         return res;
108 }
109
110 int unload_module(void)
111 {
112         int res;
113         STANDARD_HANGUP_LOCALUSERS;
114         res = ast_unregister_application(app_sayunixtime);
115         if (! res)
116                 return ast_unregister_application(app_datetime);
117         else
118                 return res;
119 }
120
121 int load_module(void)
122 {
123         int res;
124         res = ast_register_application(app_sayunixtime, sayunixtime_exec, sayunixtime_synopsis, sayunixtime_descrip);
125         if (! res)
126                 return ast_register_application(app_datetime, sayunixtime_exec, sayunixtime_synopsis, datetime_descrip);
127         else
128                 return res;
129 }
130
131 char *description(void)
132 {
133         return tdesc;
134 }
135
136 int usecount(void)
137 {
138         int res;
139         STANDARD_USECOUNT(res);
140         return res;
141 }
142
143 char *key()
144 {
145         return ASTERISK_GPL_KEY;
146 }