- Add some see-also references based on TFOT.
[asterisk/asterisk.git] / apps / app_url.c
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 1999 - 2005, Digium, Inc.
5  *
6  * Mark Spencer <markster@digium.com>
7  *
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.
13  *
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.
17  */
18
19 /*! \file
20  *
21  * \brief App to transmit a URL
22  *
23  * \author Mark Spencer <markster@digium.com>
24  * 
25  * \ingroup applications
26  */
27  
28 #include "asterisk.h"
29
30 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
31
32 #include "asterisk/pbx.h"
33 #include "asterisk/module.h"
34 #include "asterisk/app.h"
35 #include "asterisk/channel.h"
36
37 /*** DOCUMENTATION
38         <application name="SendURL" language="en_US">
39                 <synopsis>
40                         Send a URL.
41                 </synopsis>
42                 <syntax>
43                         <parameter name="URL" required="true" />
44                         <parameter name="option">
45                                 <optionlist>
46                                         <option name="w">
47                                                 <para>Execution will wait for an acknowledgement that the
48                                                 URL has been loaded before continuing.</para>
49                                         </option>
50                                 </optionlist>
51                         </parameter>
52                 </syntax>
53                 <description>
54                         <para>Requests client go to <replaceable>URL</replaceable> (IAX2) or sends the
55                         URL to the client (other channels).</para>
56                         <para>Result is returned in the <variable>SENDURLSTATUS</variable> channel variable:</para>
57                         <variablelist>
58                                 <variable name="SENDURLSTATUS">
59                                         <value name="SUCCESS">
60                                                 URL successfully sent to client.
61                                         </value>
62                                         <value name="FAILURE">
63                                                 Failed to send URL.
64                                         </value>
65                                         <value name="NOLOAD">
66                                                 Client failed to load URL (wait enabled).
67                                         </value>
68                                         <value name="UNSUPPORTED">
69                                                 Channel does not support URL transport.
70                                         </value>
71                                 </variable>
72                         </variablelist>
73                         <para>SendURL continues normally if the URL was sent correctly or if the channel
74                         does not support HTML transport.  Otherwise, the channel is hung up.</para>
75                 </description>
76                 <see-also>
77                         <ref type="application">SendImage</ref>
78                         <ref type="application">SendText</ref>
79                 </see-also>
80         </application>
81  ***/
82
83 static char *app = "SendURL";
84
85 enum {
86         OPTION_WAIT = (1 << 0),
87 } option_flags;
88
89 AST_APP_OPTIONS(app_opts,{
90         AST_APP_OPTION('w', OPTION_WAIT),
91 });
92
93 static int sendurl_exec(struct ast_channel *chan, void *data)
94 {
95         int res = 0;
96         char *tmp;
97         struct ast_frame *f;
98         char *status = "FAILURE";
99         char *opts[0];
100         struct ast_flags flags;
101         AST_DECLARE_APP_ARGS(args,
102                 AST_APP_ARG(url);
103                 AST_APP_ARG(options);
104         );
105         
106         if (ast_strlen_zero(data)) {
107                 ast_log(LOG_WARNING, "SendURL requires an argument (URL)\n");
108                 pbx_builtin_setvar_helper(chan, "SENDURLSTATUS", status);
109                 return -1;
110         }
111
112         tmp = ast_strdupa(data);
113
114         AST_STANDARD_APP_ARGS(args, tmp);
115         if (args.argc == 2)
116                 ast_app_parse_options(app_opts, &flags, opts, args.options);
117         
118         if (!ast_channel_supports_html(chan)) {
119                 /* Does not support transport */
120                 pbx_builtin_setvar_helper(chan, "SENDURLSTATUS", "UNSUPPORTED");
121                 return 0;
122         }
123         res = ast_channel_sendurl(chan, args.url);
124         if (res == -1) {
125                 pbx_builtin_setvar_helper(chan, "SENDURLSTATUS", "FAILURE");
126                 return res;
127         }
128         status = "SUCCESS";
129         if (ast_test_flag(&flags, OPTION_WAIT)) {
130                 for(;;) {
131                         /* Wait for an event */
132                         res = ast_waitfor(chan, -1);
133                         if (res < 0) 
134                                 break;
135                         f = ast_read(chan);
136                         if (!f) {
137                                 res = -1;
138                                 status = "FAILURE";
139                                 break;
140                         }
141                         if (f->frametype == AST_FRAME_HTML) {
142                                 switch(f->subclass) {
143                                 case AST_HTML_LDCOMPLETE:
144                                         res = 0;
145                                         ast_frfree(f);
146                                         status = "NOLOAD";
147                                         goto out;
148                                         break;
149                                 case AST_HTML_NOSUPPORT:
150                                         /* Does not support transport */
151                                         status = "UNSUPPORTED";
152                                         res = 0;
153                                         ast_frfree(f);
154                                         goto out;
155                                         break;
156                                 default:
157                                         ast_log(LOG_WARNING, "Don't know what to do with HTML subclass %d\n", f->subclass);
158                                 };
159                         }
160                         ast_frfree(f);
161                 }
162         } 
163 out:    
164         pbx_builtin_setvar_helper(chan, "SENDURLSTATUS", status);
165         return res;
166 }
167
168 static int unload_module(void)
169 {
170         return ast_unregister_application(app);
171 }
172
173 static int load_module(void)
174 {
175         return ast_register_application_xml(app, sendurl_exec);
176 }
177
178 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Send URL Applications");