app_url.c
Go to the documentation of this file.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
00029
00030
00031
00032 #include "asterisk.h"
00033
00034 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 339776 $")
00035
00036 #include "asterisk/pbx.h"
00037 #include "asterisk/module.h"
00038 #include "asterisk/app.h"
00039 #include "asterisk/channel.h"
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
00084
00085
00086
00087 static char *app = "SendURL";
00088
00089 enum option_flags {
00090 OPTION_WAIT = (1 << 0),
00091 };
00092
00093 AST_APP_OPTIONS(app_opts,{
00094 AST_APP_OPTION('w', OPTION_WAIT),
00095 });
00096
00097 static int sendurl_exec(struct ast_channel *chan, const char *data)
00098 {
00099 int res = 0;
00100 char *tmp;
00101 struct ast_frame *f;
00102 char *status = "FAILURE";
00103 char *opts[0];
00104 struct ast_flags flags = { 0 };
00105 AST_DECLARE_APP_ARGS(args,
00106 AST_APP_ARG(url);
00107 AST_APP_ARG(options);
00108 );
00109
00110 if (ast_strlen_zero(data)) {
00111 ast_log(LOG_WARNING, "SendURL requires an argument (URL)\n");
00112 pbx_builtin_setvar_helper(chan, "SENDURLSTATUS", status);
00113 return -1;
00114 }
00115
00116 tmp = ast_strdupa(data);
00117
00118 AST_STANDARD_APP_ARGS(args, tmp);
00119 if (args.argc == 2)
00120 ast_app_parse_options(app_opts, &flags, opts, args.options);
00121
00122 if (!ast_channel_supports_html(chan)) {
00123
00124 pbx_builtin_setvar_helper(chan, "SENDURLSTATUS", "UNSUPPORTED");
00125 return 0;
00126 }
00127 res = ast_channel_sendurl(chan, args.url);
00128 if (res == -1) {
00129 pbx_builtin_setvar_helper(chan, "SENDURLSTATUS", "FAILURE");
00130 return res;
00131 }
00132 status = "SUCCESS";
00133 if (ast_test_flag(&flags, OPTION_WAIT)) {
00134 for(;;) {
00135
00136 res = ast_waitfor(chan, -1);
00137 if (res < 0)
00138 break;
00139 f = ast_read(chan);
00140 if (!f) {
00141 res = -1;
00142 status = "FAILURE";
00143 break;
00144 }
00145 if (f->frametype == AST_FRAME_HTML) {
00146 switch (f->subclass.integer) {
00147 case AST_HTML_LDCOMPLETE:
00148 res = 0;
00149 ast_frfree(f);
00150 status = "NOLOAD";
00151 goto out;
00152 break;
00153 case AST_HTML_NOSUPPORT:
00154
00155 status = "UNSUPPORTED";
00156 res = 0;
00157 ast_frfree(f);
00158 goto out;
00159 break;
00160 default:
00161 ast_log(LOG_WARNING, "Don't know what to do with HTML subclass %d\n", f->subclass.integer);
00162 };
00163 }
00164 ast_frfree(f);
00165 }
00166 }
00167 out:
00168 pbx_builtin_setvar_helper(chan, "SENDURLSTATUS", status);
00169 return res;
00170 }
00171
00172 static int unload_module(void)
00173 {
00174 return ast_unregister_application(app);
00175 }
00176
00177 static int load_module(void)
00178 {
00179 return ast_register_application_xml(app, sendurl_exec);
00180 }
00181
00182 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Send URL Applications");