#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include "asterisk.h"
#include "asterisk/file.h"
#include "asterisk/logger.h"
#include "asterisk/options.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/module.h"
#include "asterisk/say.h"
Include dependency graph for app_sayunixtime.c:
Go to the source code of this file.
Functions | |
char * | description (void) |
Provides a description of the module. | |
char * | key () |
Returns the ASTERISK_GPL_KEY. | |
int | load_module (void) |
Initialize the module. | |
static int | sayunixtime_exec (struct ast_channel *chan, void *data) |
int | unload_module (void) |
Cleanup all module structures, sockets, etc. | |
int | usecount (void) |
Provides a usecount. | |
Variables | |
static char * | app_datetime = "DateTime" |
static char * | app_sayunixtime = "SayUnixTime" |
static char * | datetime_descrip |
LOCAL_USER_DECL | |
static char * | sayunixtime_descrip |
static char * | sayunixtime_synopsis = "Says a specified time in a custom format" |
STANDARD_LOCAL_USER | |
static char * | tdesc = "Say time" |
Definition in file app_sayunixtime.c.
|
Provides a description of the module.
Definition at line 150 of file app_sayunixtime.c. References tdesc. 00151 { 00152 return tdesc; 00153 }
|
|
Returns the ASTERISK_GPL_KEY. This returns the ASTERISK_GPL_KEY, signifiying that you agree to the terms of the GPL stated in the ASTERISK_GPL_KEY. Your module will not load if it does not return the EXACT message:
char *key(void) { return ASTERISK_GPL_KEY; }
Definition at line 162 of file app_sayunixtime.c. References ASTERISK_GPL_KEY. 00163 { 00164 return ASTERISK_GPL_KEY; 00165 }
|
|
Initialize the module. Initialize the Agents module. This function is being called by Asterisk when loading the module. Among other thing it registers applications, cli commands and reads the cofiguration file.
Definition at line 140 of file app_sayunixtime.c. References app_datetime, app_sayunixtime, ast_register_application(), datetime_descrip, sayunixtime_descrip, sayunixtime_exec(), and sayunixtime_synopsis. 00141 { 00142 int res; 00143 00144 res = ast_register_application(app_sayunixtime, sayunixtime_exec, sayunixtime_synopsis, sayunixtime_descrip); 00145 res |= ast_register_application(app_datetime, sayunixtime_exec, sayunixtime_synopsis, datetime_descrip); 00146 00147 return res; 00148 }
|
|
Definition at line 71 of file app_sayunixtime.c. References ast_channel::_state, ast_answer(), AST_DIGIT_ANY, ast_log(), ast_say_date_with_format(), AST_STATE_UP, ast_strdupa, format, ast_channel::language, LOCAL_USER_ADD, LOCAL_USER_REMOVE, LOG_ERROR, s, and strsep(). Referenced by load_module(). 00072 { 00073 int res=0; 00074 struct localuser *u; 00075 char *s,*zone=NULL,*timec,*format; 00076 time_t unixtime; 00077 struct timeval tv; 00078 00079 LOCAL_USER_ADD(u); 00080 00081 tv = ast_tvnow(); 00082 unixtime = (time_t)tv.tv_sec; 00083 00084 if( !strcasecmp(chan->language, "da" ) ) { 00085 format = "A dBY HMS"; 00086 } else if ( !strcasecmp(chan->language, "de" ) ) { 00087 format = "A dBY HMS"; 00088 } else if ( !strcasecmp(chan->language, "pt_BR" ) ) { 00089 format = "Ad 'digits/pt-de' B 'digits/pt-de' Y 'digits/pt-as' HMS"; 00090 } else { 00091 format = "ABdY 'digits/at' IMp"; 00092 } 00093 00094 if (data) { 00095 s = data; 00096 s = ast_strdupa(s); 00097 if (s) { 00098 timec = strsep(&s,"|"); 00099 if ((timec) && (*timec != '\0')) { 00100 long timein; 00101 if (sscanf(timec,"%ld",&timein) == 1) { 00102 unixtime = (time_t)timein; 00103 } 00104 } 00105 if (s) { 00106 zone = strsep(&s,"|"); 00107 if (zone && (*zone == '\0')) 00108 zone = NULL; 00109 if (s) { 00110 format = s; 00111 } 00112 } 00113 } else { 00114 ast_log(LOG_ERROR, "Out of memory error\n"); 00115 } 00116 } 00117 00118 if (chan->_state != AST_STATE_UP) { 00119 res = ast_answer(chan); 00120 } 00121 if (!res) 00122 res = ast_say_date_with_format(chan, unixtime, AST_DIGIT_ANY, chan->language, format, zone); 00123 00124 LOCAL_USER_REMOVE(u); 00125 return res; 00126 }
|
|
Cleanup all module structures, sockets, etc. This is called at exit. Any registrations and memory allocations need to be unregistered and free'd here. Nothing else will do these for you (until exit).
Definition at line 128 of file app_sayunixtime.c. References app_datetime, app_sayunixtime, ast_unregister_application(), and STANDARD_HANGUP_LOCALUSERS. 00129 { 00130 int res; 00131 00132 res = ast_unregister_application(app_sayunixtime); 00133 res |= ast_unregister_application(app_datetime); 00134 00135 STANDARD_HANGUP_LOCALUSERS; 00136 00137 return res; 00138 }
|
|
Provides a usecount. This function will be called by various parts of asterisk. Basically, all it has to do is to return a usecount when called. You will need to maintain your usecount within the module somewhere. The usecount should be how many channels provided by this module are in use.
Definition at line 155 of file app_sayunixtime.c. References STANDARD_USECOUNT. 00156 { 00157 int res; 00158 STANDARD_USECOUNT(res); 00159 return res; 00160 }
|
|
Definition at line 46 of file app_sayunixtime.c. Referenced by load_module(), and unload_module(). |
|
Definition at line 45 of file app_sayunixtime.c. Referenced by load_module(), and unload_module(). |
|
Definition at line 58 of file app_sayunixtime.c. Referenced by load_module(). |
|
Definition at line 69 of file app_sayunixtime.c. |
|
Definition at line 50 of file app_sayunixtime.c. Referenced by load_module(). |
|
Definition at line 48 of file app_sayunixtime.c. Referenced by load_module(). |
|
Definition at line 67 of file app_sayunixtime.c. |
|
Definition at line 43 of file app_sayunixtime.c. |