#include <stdlib.h>
#include <stdio.h>
#include <string.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/image.h"
#include "asterisk/options.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. | |
static int | sendurl_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 = "SendURL" |
static char * | descrip |
LOCAL_USER_DECL | |
STANDARD_LOCAL_USER | |
static char * | synopsis = "Send a URL" |
static char * | tdesc = "Send URL Applications" |
Definition in file app_url.c.
char* description | ( | void | ) |
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; }
Definition at line 194 of file app_url.c.
References ASTERISK_GPL_KEY.
00195 { 00196 return ASTERISK_GPL_KEY; 00197 }
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.
Definition at line 177 of file app_url.c.
References ast_register_application(), and sendurl_exec().
00178 { 00179 return ast_register_application(app, sendurl_exec, synopsis, descrip); 00180 }
static int sendurl_exec | ( | struct ast_channel * | chan, | |
void * | data | |||
) | [static] |
Definition at line 74 of file app_url.c.
References ast_channel_sendurl(), ast_channel_supports_html(), AST_FRAME_HTML, ast_frfree(), ast_goto_if_exists(), AST_HTML_LDCOMPLETE, AST_HTML_NOSUPPORT, ast_log(), ast_read(), ast_strdupa, ast_strlen_zero(), ast_waitfor(), ast_channel::context, ast_frame::frametype, LOCAL_USER_ADD, LOCAL_USER_REMOVE, LOG_ERROR, LOG_WARNING, option_priority_jumping, pbx_builtin_setvar_helper(), strsep(), and ast_frame::subclass.
Referenced by load_module().
00075 { 00076 int res = 0; 00077 struct localuser *u; 00078 char *tmp; 00079 char *options; 00080 int local_option_wait=0; 00081 int local_option_jump = 0; 00082 struct ast_frame *f; 00083 char *stringp=NULL; 00084 char *status = "FAILURE"; 00085 00086 if (ast_strlen_zero(data)) { 00087 ast_log(LOG_WARNING, "SendURL requires an argument (URL)\n"); 00088 pbx_builtin_setvar_helper(chan, "SENDURLSTATUS", status); 00089 return -1; 00090 } 00091 00092 LOCAL_USER_ADD(u); 00093 00094 tmp = ast_strdupa(data); 00095 if (!tmp) { 00096 ast_log(LOG_ERROR, "Out of memory\n"); 00097 LOCAL_USER_REMOVE(u); 00098 return -1; 00099 } 00100 00101 stringp=tmp; 00102 strsep(&stringp, "|"); 00103 options = strsep(&stringp, "|"); 00104 if (options && !strcasecmp(options, "wait")) 00105 local_option_wait = 1; 00106 if (options && !strcasecmp(options, "j")) 00107 local_option_jump = 1; 00108 00109 if (!ast_channel_supports_html(chan)) { 00110 /* Does not support transport */ 00111 if (local_option_jump || option_priority_jumping) 00112 ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101); 00113 pbx_builtin_setvar_helper(chan, "SENDURLSTATUS", "UNSUPPORTED"); 00114 LOCAL_USER_REMOVE(u); 00115 return 0; 00116 } 00117 res = ast_channel_sendurl(chan, tmp); 00118 if (res == -1) { 00119 pbx_builtin_setvar_helper(chan, "SENDURLSTATUS", "FAILURE"); 00120 LOCAL_USER_REMOVE(u); 00121 return res; 00122 } 00123 status = "SUCCESS"; 00124 if (local_option_wait) { 00125 for(;;) { 00126 /* Wait for an event */ 00127 res = ast_waitfor(chan, -1); 00128 if (res < 0) 00129 break; 00130 f = ast_read(chan); 00131 if (!f) { 00132 res = -1; 00133 status = "FAILURE"; 00134 break; 00135 } 00136 if (f->frametype == AST_FRAME_HTML) { 00137 switch(f->subclass) { 00138 case AST_HTML_LDCOMPLETE: 00139 res = 0; 00140 ast_frfree(f); 00141 status = "NOLOAD"; 00142 goto out; 00143 break; 00144 case AST_HTML_NOSUPPORT: 00145 /* Does not support transport */ 00146 status ="UNSUPPORTED"; 00147 if (local_option_jump || option_priority_jumping) 00148 ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101); 00149 res = 0; 00150 ast_frfree(f); 00151 goto out; 00152 break; 00153 default: 00154 ast_log(LOG_WARNING, "Don't know what to do with HTML subclass %d\n", f->subclass); 00155 }; 00156 } 00157 ast_frfree(f); 00158 } 00159 } 00160 out: 00161 pbx_builtin_setvar_helper(chan, "SENDURLSTATUS", status); 00162 LOCAL_USER_REMOVE(u); 00163 return res; 00164 }
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).
Definition at line 166 of file app_url.c.
References ast_unregister_application(), and STANDARD_HANGUP_LOCALUSERS.
00167 { 00168 int res; 00169 00170 res = ast_unregister_application(app); 00171 00172 STANDARD_HANGUP_LOCALUSERS; 00173 00174 return res; 00175 }
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.
Definition at line 187 of file app_url.c.
References STANDARD_USECOUNT.
00188 { 00189 int res; 00190 STANDARD_USECOUNT(res); 00191 return res; 00192 }