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 #include <stdlib.h>
00026 #include <stdio.h>
00027 #include <string.h>
00028
00029 #include "asterisk.h"
00030
00031 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 33480 $")
00032
00033 #include "asterisk/lock.h"
00034 #include "asterisk/file.h"
00035 #include "asterisk/logger.h"
00036 #include "asterisk/channel.h"
00037 #include "asterisk/pbx.h"
00038 #include "asterisk/module.h"
00039 #include "asterisk/translate.h"
00040 #include "asterisk/image.h"
00041 #include "asterisk/options.h"
00042
00043 static char *tdesc = "Send URL Applications";
00044
00045 static char *app = "SendURL";
00046
00047 static char *synopsis = "Send a URL";
00048
00049 static char *descrip =
00050 " SendURL(URL[|option]): Requests client go to URL (IAX2) or sends the \n"
00051 "URL to the client (other channels).\n"
00052 "Result is returned in the SENDURLSTATUS channel variable:\n"
00053 " SUCCESS URL successfully sent to client\n"
00054 " FAILURE Failed to send URL\n"
00055 " NOLOAD Clien failed to load URL (wait enabled)\n"
00056 " UNSUPPORTED Channel does not support URL transport\n"
00057 "\n"
00058 "If the option 'wait' is specified, execution will wait for an\n"
00059 "acknowledgement that the URL has been loaded before continuing\n"
00060 "and will return -1 if the peer is unable to load the URL\n"
00061 "\n"
00062 "Old behaviour (deprecated): \n"
00063 " If the client does not support Asterisk \"html\" transport, \n"
00064 " and there exists a step with priority n + 101, then execution will\n"
00065 " continue at that step.\n"
00066 " Otherwise, execution will continue at the next priority level.\n"
00067 " SendURL only returns 0 if the URL was sent correctly or if\n"
00068 " the channel does not support HTML transport, and -1 otherwise.\n";
00069
00070 STANDARD_LOCAL_USER;
00071
00072 LOCAL_USER_DECL;
00073
00074 static int sendurl_exec(struct ast_channel *chan, void *data)
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
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
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
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 }
00165
00166 int unload_module(void)
00167 {
00168 int res;
00169
00170 res = ast_unregister_application(app);
00171
00172 STANDARD_HANGUP_LOCALUSERS;
00173
00174 return res;
00175 }
00176
00177 int load_module(void)
00178 {
00179 return ast_register_application(app, sendurl_exec, synopsis, descrip);
00180 }
00181
00182 char *description(void)
00183 {
00184 return tdesc;
00185 }
00186
00187 int usecount(void)
00188 {
00189 int res;
00190 STANDARD_USECOUNT(res);
00191 return res;
00192 }
00193
00194 char *key()
00195 {
00196 return ASTERISK_GPL_KEY;
00197 }