2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 1999 - 2005, Digium, Inc.
6 * Mark Spencer <markster@digium.com>
8 * See http://www.asterisk.org for more information about
9 * the Asterisk project. Please do not directly contact
10 * any of the maintainers of this project for assistance;
11 * the project provides a web site, mailing lists and IRC
12 * channels for your use.
14 * This program is free software, distributed under the terms of
15 * the GNU General Public License Version 2. See the LICENSE file
16 * at the top of the source tree.
21 * \brief App to transmit a URL
23 * \author Mark Spencer <markster@digium.com>
25 * \ingroup applications
30 ASTERISK_FILE_VERSION(__FILE__
, "$Revision$")
36 #include "asterisk/lock.h"
37 #include "asterisk/file.h"
38 #include "asterisk/logger.h"
39 #include "asterisk/channel.h"
40 #include "asterisk/pbx.h"
41 #include "asterisk/module.h"
42 #include "asterisk/translate.h"
43 #include "asterisk/image.h"
44 #include "asterisk/options.h"
46 static char *app
= "SendURL";
48 static char *synopsis
= "Send a URL";
50 static char *descrip
=
51 " SendURL(URL[|option]): Requests client go to URL (IAX2) or sends the \n"
52 "URL to the client (other channels).\n"
53 "Result is returned in the SENDURLSTATUS channel variable:\n"
54 " SUCCESS URL successfully sent to client\n"
55 " FAILURE Failed to send URL\n"
56 " NOLOAD Client failed to load URL (wait enabled)\n"
57 " UNSUPPORTED Channel does not support URL transport\n"
59 "If the option 'wait' is specified, execution will wait for an\n"
60 "acknowledgement that the URL has been loaded before continuing\n"
62 "If jumping is specified as an option (the 'j' flag), the client does not\n"
63 "support Asterisk \"html\" transport, and there exists a step with priority\n"
64 "n + 101, then execution will continue at that step.\n"
66 "SendURL continues normally if the URL was sent correctly or if the channel\n"
67 "does not support HTML transport. Otherwise, the channel is hung up.\n";
70 static int sendurl_exec(struct ast_channel
*chan
, void *data
)
73 struct ast_module_user
*u
;
76 int local_option_wait
=0;
77 int local_option_jump
= 0;
80 char *status
= "FAILURE";
82 if (ast_strlen_zero(data
)) {
83 ast_log(LOG_WARNING
, "SendURL requires an argument (URL)\n");
84 pbx_builtin_setvar_helper(chan
, "SENDURLSTATUS", status
);
88 u
= ast_module_user_add(chan
);
90 tmp
= ast_strdupa(data
);
93 strsep(&stringp
, "|");
94 options
= strsep(&stringp
, "|");
95 if (options
&& !strcasecmp(options
, "wait"))
96 local_option_wait
= 1;
97 if (options
&& !strcasecmp(options
, "j"))
98 local_option_jump
= 1;
100 if (!ast_channel_supports_html(chan
)) {
101 /* Does not support transport */
102 if (local_option_jump
|| ast_opt_priority_jumping
)
103 ast_goto_if_exists(chan
, chan
->context
, chan
->exten
, chan
->priority
+ 101);
104 pbx_builtin_setvar_helper(chan
, "SENDURLSTATUS", "UNSUPPORTED");
105 ast_module_user_remove(u
);
108 res
= ast_channel_sendurl(chan
, tmp
);
110 pbx_builtin_setvar_helper(chan
, "SENDURLSTATUS", "FAILURE");
111 ast_module_user_remove(u
);
115 if (local_option_wait
) {
117 /* Wait for an event */
118 res
= ast_waitfor(chan
, -1);
127 if (f
->frametype
== AST_FRAME_HTML
) {
128 switch(f
->subclass
) {
129 case AST_HTML_LDCOMPLETE
:
135 case AST_HTML_NOSUPPORT
:
136 /* Does not support transport */
137 status
="UNSUPPORTED";
138 if (local_option_jump
|| ast_opt_priority_jumping
)
139 ast_goto_if_exists(chan
, chan
->context
, chan
->exten
, chan
->priority
+ 101);
145 ast_log(LOG_WARNING
, "Don't know what to do with HTML subclass %d\n", f
->subclass
);
152 pbx_builtin_setvar_helper(chan
, "SENDURLSTATUS", status
);
153 ast_module_user_remove(u
);
157 static int unload_module(void)
161 res
= ast_unregister_application(app
);
163 ast_module_user_hangup_all();
168 static int load_module(void)
170 return ast_register_application(app
, sendurl_exec
, synopsis
, descrip
);
173 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY
, "Send URL Applications");