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: 227580 $")
00031
00032 #include "asterisk/pbx.h"
00033 #include "asterisk/module.h"
00034 #include "asterisk/app.h"
00035 #include "asterisk/channel.h"
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083 static char *app = "SendURL";
00084
00085 enum option_flags {
00086 OPTION_WAIT = (1 << 0),
00087 };
00088
00089 AST_APP_OPTIONS(app_opts,{
00090 AST_APP_OPTION('w', OPTION_WAIT),
00091 });
00092
00093 static int sendurl_exec(struct ast_channel *chan, const char *data)
00094 {
00095 int res = 0;
00096 char *tmp;
00097 struct ast_frame *f;
00098 char *status = "FAILURE";
00099 char *opts[0];
00100 struct ast_flags flags;
00101 AST_DECLARE_APP_ARGS(args,
00102 AST_APP_ARG(url);
00103 AST_APP_ARG(options);
00104 );
00105
00106 if (ast_strlen_zero(data)) {
00107 ast_log(LOG_WARNING, "SendURL requires an argument (URL)\n");
00108 pbx_builtin_setvar_helper(chan, "SENDURLSTATUS", status);
00109 return -1;
00110 }
00111
00112 tmp = ast_strdupa(data);
00113
00114 AST_STANDARD_APP_ARGS(args, tmp);
00115 if (args.argc == 2)
00116 ast_app_parse_options(app_opts, &flags, opts, args.options);
00117
00118 if (!ast_channel_supports_html(chan)) {
00119
00120 pbx_builtin_setvar_helper(chan, "SENDURLSTATUS", "UNSUPPORTED");
00121 return 0;
00122 }
00123 res = ast_channel_sendurl(chan, args.url);
00124 if (res == -1) {
00125 pbx_builtin_setvar_helper(chan, "SENDURLSTATUS", "FAILURE");
00126 return res;
00127 }
00128 status = "SUCCESS";
00129 if (ast_test_flag(&flags, OPTION_WAIT)) {
00130 for(;;) {
00131
00132 res = ast_waitfor(chan, -1);
00133 if (res < 0)
00134 break;
00135 f = ast_read(chan);
00136 if (!f) {
00137 res = -1;
00138 status = "FAILURE";
00139 break;
00140 }
00141 if (f->frametype == AST_FRAME_HTML) {
00142 switch (f->subclass.integer) {
00143 case AST_HTML_LDCOMPLETE:
00144 res = 0;
00145 ast_frfree(f);
00146 status = "NOLOAD";
00147 goto out;
00148 break;
00149 case AST_HTML_NOSUPPORT:
00150
00151 status = "UNSUPPORTED";
00152 res = 0;
00153 ast_frfree(f);
00154 goto out;
00155 break;
00156 default:
00157 ast_log(LOG_WARNING, "Don't know what to do with HTML subclass %d\n", f->subclass.integer);
00158 };
00159 }
00160 ast_frfree(f);
00161 }
00162 }
00163 out:
00164 pbx_builtin_setvar_helper(chan, "SENDURLSTATUS", status);
00165 return res;
00166 }
00167
00168 static int unload_module(void)
00169 {
00170 return ast_unregister_application(app);
00171 }
00172
00173 static int load_module(void)
00174 {
00175 return ast_register_application_xml(app, sendurl_exec);
00176 }
00177
00178 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Send URL Applications");