#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include "asterisk.h"
#include "asterisk/lock.h"
#include "asterisk/file.h"
#include "asterisk/logger.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/module.h"
#include "asterisk/translate.h"
#include "asterisk/utils.h"
#include "asterisk/options.h"
#include "asterisk/app.h"
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. | |
int | playback_exec (struct ast_channel *chan, void *data) |
int | unload_module (void) |
Cleanup all module structures, sockets, etc. | |
int | usecount (void) |
Provides a usecount. | |
Variables | |
char * | app = "Playback" |
char * | descrip |
LOCAL_USER_DECL | |
STANDARD_LOCAL_USER | |
char * | synopsis = "Play a file" |
char * | tdesc = "Sound File Playback Application" |
Definition in file app_playback.c.
|
Provides a description of the module.
Definition at line 165 of file app_playback.c. 00166 {
00167 return tdesc;
00168 }
|
|
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 177 of file app_playback.c. 00178 {
00179 return ASTERISK_GPL_KEY;
00180 }
|
|
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 160 of file app_playback.c. References app, ast_register_application(), descrip, playback_exec(), and synopsis. 00161 { 00162 return ast_register_application(app, playback_exec, synopsis, descrip); 00163 }
|
|
Definition at line 71 of file app_playback.c. References ast_channel::_state, ast_answer(), AST_APP_ARG, AST_DECLARE_APP_ARGS, ast_goto_if_exists(), ast_log(), AST_STANDARD_APP_ARGS, ast_stopstream(), ast_strdupa, ast_streamfile(), ast_strlen_zero(), ast_waitstream(), ast_channel::context, ast_channel::exten, ast_channel::language, LOCAL_USER_ADD, LOCAL_USER_REMOVE, LOG_ERROR, LOG_WARNING, ast_channel::name, pbx_builtin_setvar_helper(), ast_channel::priority, and strcasestr(). Referenced by load_module(). 00072 { 00073 int res = 0, mres = 0; 00074 struct localuser *u; 00075 char *tmp = NULL; 00076 int option_skip=0; 00077 int option_noanswer = 0; 00078 char *front = NULL, *back = NULL; 00079 int priority_jump = 0; 00080 AST_DECLARE_APP_ARGS(args, 00081 AST_APP_ARG(filenames); 00082 AST_APP_ARG(options); 00083 ); 00084 00085 if (ast_strlen_zero(data)) { 00086 ast_log(LOG_WARNING, "Playback requires an argument (filename)\n"); 00087 return -1; 00088 } 00089 00090 LOCAL_USER_ADD(u); 00091 00092 tmp = ast_strdupa(data); 00093 if (!tmp) { 00094 ast_log(LOG_ERROR, "Out of memory!\n"); 00095 LOCAL_USER_REMOVE(u); 00096 return -1; 00097 } 00098 00099 AST_STANDARD_APP_ARGS(args, tmp); 00100 00101 if (args.options) { 00102 if (strcasestr(args.options, "skip")) 00103 option_skip = 1; 00104 if (strcasestr(args.options, "noanswer")) 00105 option_noanswer = 1; 00106 if (strchr(args.options, 'j')) 00107 priority_jump = 1; 00108 } 00109 00110 if (chan->_state != AST_STATE_UP) { 00111 if (option_skip) { 00112 /* At the user's option, skip if the line is not up */ 00113 LOCAL_USER_REMOVE(u); 00114 return 0; 00115 } else if (!option_noanswer) 00116 /* Otherwise answer unless we're supposed to send this while on-hook */ 00117 res = ast_answer(chan); 00118 } 00119 if (!res) { 00120 ast_stopstream(chan); 00121 front = tmp; 00122 while (!res && front) { 00123 if ((back = strchr(front, '&'))) { 00124 *back = '\0'; 00125 back++; 00126 } 00127 res = ast_streamfile(chan, front, chan->language); 00128 if (!res) { 00129 res = ast_waitstream(chan, ""); 00130 ast_stopstream(chan); 00131 } else { 00132 ast_log(LOG_WARNING, "ast_streamfile failed on %s for %s\n", chan->name, (char *)data); 00133 if (priority_jump || option_priority_jumping) 00134 ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101); 00135 res = 0; 00136 mres = 1; 00137 } 00138 front = back; 00139 } 00140 if (mres) 00141 pbx_builtin_setvar_helper(chan, "PLAYBACKSTATUS", "FAILED"); 00142 else 00143 pbx_builtin_setvar_helper(chan, "PLAYBACKSTATUS", "SUCCESS"); 00144 } 00145 LOCAL_USER_REMOVE(u); 00146 return res; 00147 }
|
|
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 149 of file app_playback.c. References app, and ast_unregister_application(). 00150 { 00151 int res; 00152 00153 res = ast_unregister_application(app); 00154 00155 STANDARD_HANGUP_LOCALUSERS; 00156 00157 return res; 00158 }
|
|
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 170 of file app_playback.c. References STANDARD_USECOUNT. 00171 { 00172 int res; 00173 STANDARD_USECOUNT(res); 00174 return res; 00175 }
|
|
Definition at line 47 of file app_playback.c. Referenced by load_module(), and unload_module(). |
|
Definition at line 51 of file app_playback.c. Referenced by load_module(). |
|
Definition at line 69 of file app_playback.c. |
|
Definition at line 67 of file app_playback.c. |
|
Definition at line 49 of file app_playback.c. Referenced by load_module(). |
|
Definition at line 45 of file app_playback.c. |