Creating tag for the release of asterisk-1.6.1-beta1
[asterisk-bristuff.git] / apps / app_url.c
blobf71b32fd050d5736329f0f88af6bddead898a05b
1 /*
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.
19 /*! \file
21 * \brief App to transmit a URL
23 * \author Mark Spencer <markster@digium.com>
25 * \ingroup applications
28 #include "asterisk.h"
30 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
32 #include "asterisk/pbx.h"
33 #include "asterisk/module.h"
34 #include "asterisk/app.h"
35 #include "asterisk/channel.h"
37 static char *app = "SendURL";
39 static char *synopsis = "Send a URL";
41 static char *descrip =
42 " SendURL(URL[,option]): Requests client go to URL (IAX2) or sends the \n"
43 "URL to the client (other channels).\n"
44 "Result is returned in the SENDURLSTATUS channel variable:\n"
45 " SUCCESS URL successfully sent to client\n"
46 " FAILURE Failed to send URL\n"
47 " NOLOAD Client failed to load URL (wait enabled)\n"
48 " UNSUPPORTED Channel does not support URL transport\n"
49 "\n"
50 "If the option 'w' is specified, execution will wait for an\n"
51 "acknowledgement that the URL has been loaded before continuing\n"
52 "\n"
53 "SendURL continues normally if the URL was sent correctly or if the channel\n"
54 "does not support HTML transport. Otherwise, the channel is hung up.\n";
56 enum {
57 OPTION_WAIT = (1 << 0),
58 } option_flags;
60 AST_APP_OPTIONS(app_opts,{
61 AST_APP_OPTION('w', OPTION_WAIT),
62 });
64 static int sendurl_exec(struct ast_channel *chan, void *data)
66 int res = 0;
67 char *tmp;
68 struct ast_frame *f;
69 char *status = "FAILURE";
70 char *opts[0];
71 struct ast_flags flags;
72 AST_DECLARE_APP_ARGS(args,
73 AST_APP_ARG(url);
74 AST_APP_ARG(options);
77 if (ast_strlen_zero(data)) {
78 ast_log(LOG_WARNING, "SendURL requires an argument (URL)\n");
79 pbx_builtin_setvar_helper(chan, "SENDURLSTATUS", status);
80 return -1;
83 tmp = ast_strdupa(data);
85 AST_STANDARD_APP_ARGS(args, tmp);
86 if (args.argc == 2)
87 ast_app_parse_options(app_opts, &flags, opts, args.options);
89 if (!ast_channel_supports_html(chan)) {
90 /* Does not support transport */
91 pbx_builtin_setvar_helper(chan, "SENDURLSTATUS", "UNSUPPORTED");
92 return 0;
94 res = ast_channel_sendurl(chan, args.url);
95 if (res == -1) {
96 pbx_builtin_setvar_helper(chan, "SENDURLSTATUS", "FAILURE");
97 return res;
99 status = "SUCCESS";
100 if (ast_test_flag(&flags, OPTION_WAIT)) {
101 for(;;) {
102 /* Wait for an event */
103 res = ast_waitfor(chan, -1);
104 if (res < 0)
105 break;
106 f = ast_read(chan);
107 if (!f) {
108 res = -1;
109 status = "FAILURE";
110 break;
112 if (f->frametype == AST_FRAME_HTML) {
113 switch(f->subclass) {
114 case AST_HTML_LDCOMPLETE:
115 res = 0;
116 ast_frfree(f);
117 status = "NOLOAD";
118 goto out;
119 break;
120 case AST_HTML_NOSUPPORT:
121 /* Does not support transport */
122 status = "UNSUPPORTED";
123 res = 0;
124 ast_frfree(f);
125 goto out;
126 break;
127 default:
128 ast_log(LOG_WARNING, "Don't know what to do with HTML subclass %d\n", f->subclass);
131 ast_frfree(f);
134 out:
135 pbx_builtin_setvar_helper(chan, "SENDURLSTATUS", status);
136 return res;
139 static int unload_module(void)
141 return ast_unregister_application(app);
144 static int load_module(void)
146 return ast_register_application(app, sendurl_exec, synopsis, descrip);
149 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Send URL Applications");