Sat Mar 24 22:55:38 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 150 of file app_sayunixtime.c.

00151 {
00152    return tdesc;
00153 }

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 162 of file app_sayunixtime.c.

References ASTERISK_GPL_KEY.

00163 {
00164    return ASTERISK_GPL_KEY;
00165 }

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

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 128 of file app_sayunixtime.c.

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

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 155 of file app_sayunixtime.c.

References STANDARD_USECOUNT.

00156 {
00157    int res;
00158    STANDARD_USECOUNT(res);
00159    return res;
00160 }


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 22:55:39 2007 for Asterisk - the Open Source PBX by  doxygen 1.4.7