Sat Mar 24 23:26:37 2007

Asterisk developer's documentation


app_sayunixtime.c File Reference

SayUnixTime application. More...

#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"


Detailed Description

SayUnixTime application.

Definition in file app_sayunixtime.c.


Function Documentation

char* description void   ) 
 

Provides a description of the module.

Returns:
a short description of your module

Definition at line 148 of file app_sayunixtime.c.

00149 {
00150    return tdesc;
00151 }

char* key void   ) 
 

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;
 }

Returns:
ASTERISK_GPL_KEY

Definition at line 160 of file app_sayunixtime.c.

References ASTERISK_GPL_KEY.

00161 {
00162    return ASTERISK_GPL_KEY;
00163 }

int load_module void   ) 
 

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.

Returns:
int Always 0.

Definition at line 138 of file app_sayunixtime.c.

References ast_register_application(), and sayunixtime_exec().

static int sayunixtime_exec struct ast_channel chan,
void *  data
[static]
 

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 {
00089       format = "ABdY 'digits/at' IMp";
00090    } 
00091 
00092    if (data) {
00093       s = data;
00094       s = ast_strdupa(s);
00095       if (s) {
00096          timec = strsep(&s,"|");
00097          if ((timec) && (*timec != '\0')) {
00098             long timein;
00099             if (sscanf(timec,"%ld",&timein) == 1) {
00100                unixtime = (time_t)timein;
00101             }
00102          }
00103          if (s) {
00104             zone = strsep(&s,"|");
00105             if (zone && (*zone == '\0'))
00106                zone = NULL;
00107             if (s) {
00108                format = s;
00109             }
00110          }
00111       } else {
00112          ast_log(LOG_ERROR, "Out of memory error\n");
00113       }
00114    }
00115 
00116    if (chan->_state != AST_STATE_UP) {
00117       res = ast_answer(chan);
00118    }
00119    if (!res)
00120       res = ast_say_date_with_format(chan, unixtime, AST_DIGIT_ANY, chan->language, format, zone);
00121 
00122    LOCAL_USER_REMOVE(u);
00123    return res;
00124 }

int unload_module void   ) 
 

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).

Returns:
Zero on success, or non-zero on error.

Definition at line 126 of file app_sayunixtime.c.

References ast_unregister_application(), and STANDARD_HANGUP_LOCALUSERS.

00127 {
00128    int res;
00129    
00130    res = ast_unregister_application(app_sayunixtime);
00131    res |= ast_unregister_application(app_datetime);
00132 
00133    STANDARD_HANGUP_LOCALUSERS;
00134    
00135    return res;
00136 }

int usecount void   ) 
 

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.

Returns:
The module's usecount.

Definition at line 153 of file app_sayunixtime.c.

References STANDARD_USECOUNT.

00154 {
00155    int res;
00156    STANDARD_USECOUNT(res);
00157    return res;
00158 }


Variable Documentation

char* app_datetime = "DateTime" [static]
 

Definition at line 46 of file app_sayunixtime.c.

char* app_sayunixtime = "SayUnixTime" [static]
 

Definition at line 45 of file app_sayunixtime.c.

char* datetime_descrip [static]
 

Definition at line 58 of file app_sayunixtime.c.

LOCAL_USER_DECL
 

Definition at line 69 of file app_sayunixtime.c.

char* sayunixtime_descrip [static]
 

Definition at line 50 of file app_sayunixtime.c.

char* sayunixtime_synopsis = "Says a specified time in a custom format" [static]
 

Definition at line 48 of file app_sayunixtime.c.

STANDARD_LOCAL_USER
 

Definition at line 67 of file app_sayunixtime.c.

char* tdesc = "Say time" [static]
 

Definition at line 43 of file app_sayunixtime.c.


Generated on Sat Mar 24 23:26:38 2007 for Asterisk - the Open Source PBX by  doxygen 1.4.6