00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include "asterisk.h"
00029
00030 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 89522 $")
00031
00032 #include "asterisk/pbx.h"
00033 #include "asterisk/module.h"
00034 #include "asterisk/app.h"
00035 #include "asterisk/channel.h"
00036
00037 static char *app = "SendURL";
00038
00039 static char *synopsis = "Send a URL";
00040
00041 static char *descrip =
00042 " SendURL(URL[,option]): Requests client go to URL (IAX2) or sends the \n"
00043 "URL to the client (other channels).\n"
00044 "Result is returned in the SENDURLSTATUS channel variable:\n"
00045 " SUCCESS URL successfully sent to client\n"
00046 " FAILURE Failed to send URL\n"
00047 " NOLOAD Client failed to load URL (wait enabled)\n"
00048 " UNSUPPORTED Channel does not support URL transport\n"
00049 "\n"
00050 "If the option 'w' is specified, execution will wait for an\n"
00051 "acknowledgement that the URL has been loaded before continuing\n"
00052 "\n"
00053 "SendURL continues normally if the URL was sent correctly or if the channel\n"
00054 "does not support HTML transport. Otherwise, the channel is hung up.\n";
00055
00056 enum {
00057 OPTION_WAIT = (1 << 0),
00058 } option_flags;
00059
00060 AST_APP_OPTIONS(app_opts,{
00061 AST_APP_OPTION('w', OPTION_WAIT),
00062 });
00063
00064 static int sendurl_exec(struct ast_channel *chan, void *data)
00065 {
00066 int res = 0;
00067 char *tmp;
00068 struct ast_frame *f;
00069 char *status = "FAILURE";
00070 char *opts[0];
00071 struct ast_flags flags;
00072 AST_DECLARE_APP_ARGS(args,
00073 AST_APP_ARG(url);
00074 AST_APP_ARG(options);
00075 );
00076
00077 if (ast_strlen_zero(data)) {
00078 ast_log(LOG_WARNING, "SendURL requires an argument (URL)\n");
00079 pbx_builtin_setvar_helper(chan, "SENDURLSTATUS", status);
00080 return -1;
00081 }
00082
00083 tmp = ast_strdupa(data);
00084
00085 AST_STANDARD_APP_ARGS(args, tmp);
00086 if (args.argc == 2)
00087 ast_app_parse_options(app_opts, &flags, opts, args.options);
00088
00089 if (!ast_channel_supports_html(chan)) {
00090
00091 pbx_builtin_setvar_helper(chan, "SENDURLSTATUS", "UNSUPPORTED");
00092 return 0;
00093 }
00094 res = ast_channel_sendurl(chan, args.url);
00095 if (res == -1) {
00096 pbx_builtin_setvar_helper(chan, "SENDURLSTATUS", "FAILURE");
00097 return res;
00098 }
00099 status = "SUCCESS";
00100 if (ast_test_flag(&flags, OPTION_WAIT)) {
00101 for(;;) {
00102
00103 res = ast_waitfor(chan, -1);
00104 if (res < 0)
00105 break;
00106 f = ast_read(chan);
00107 if (!f) {
00108 res = -1;
00109 status = "FAILURE";
00110 break;
00111 }
00112 if (f->frametype == AST_FRAME_HTML) {
00113 switch(f->subclass) {
00114 case AST_HTML_LDCOMPLETE:
00115 res = 0;
00116 ast_frfree(f);
00117 status = "NOLOAD";
00118 goto out;
00119 break;
00120 case AST_HTML_NOSUPPORT:
00121
00122 status = "UNSUPPORTED";
00123 res = 0;
00124 ast_frfree(f);
00125 goto out;
00126 break;
00127 default:
00128 ast_log(LOG_WARNING, "Don't know what to do with HTML subclass %d\n", f->subclass);
00129 };
00130 }
00131 ast_frfree(f);
00132 }
00133 }
00134 out:
00135 pbx_builtin_setvar_helper(chan, "SENDURLSTATUS", status);
00136 return res;
00137 }
00138
00139 static int unload_module(void)
00140 {
00141 return ast_unregister_application(app);
00142 }
00143
00144 static int load_module(void)
00145 {
00146 return ast_register_application(app, sendurl_exec, synopsis, descrip);
00147 }
00148
00149 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Send URL Applications");