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