remove some useless includes
[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
36 static char *app = "SendURL";
37
38 static char *synopsis = "Send a URL";
39
40 static char *descrip = 
41 "  SendURL(URL[,option]): Requests client go to URL (IAX2) or sends the \n"
42 "URL to the client (other channels).\n"
43 "Result is returned in the SENDURLSTATUS channel variable:\n"
44 "    SUCCESS       URL successfully sent to client\n"
45 "    FAILURE       Failed to send URL\n"
46 "    NOLOAD        Client failed to load URL (wait enabled)\n"
47 "    UNSUPPORTED   Channel does not support URL transport\n"
48 "\n"
49 "If the option 'w' is specified, execution will wait for an\n"
50 "acknowledgement that the URL has been loaded before continuing\n"
51 "\n"
52 "SendURL continues normally if the URL was sent correctly or if the channel\n"
53 "does not support HTML transport.  Otherwise, the channel is hung up.\n";
54
55 enum {
56         OPTION_WAIT = (1 << 0),
57 } option_flags;
58
59 AST_APP_OPTIONS(app_opts,{
60         AST_APP_OPTION('w', OPTION_WAIT),
61 });
62
63 static int sendurl_exec(struct ast_channel *chan, void *data)
64 {
65         int res = 0;
66         char *tmp;
67         struct ast_frame *f;
68         char *status = "FAILURE";
69         char *opts[0];
70         struct ast_flags flags;
71         AST_DECLARE_APP_ARGS(args,
72                 AST_APP_ARG(url);
73                 AST_APP_ARG(options);
74         );
75         
76         if (ast_strlen_zero(data)) {
77                 ast_log(LOG_WARNING, "SendURL requires an argument (URL)\n");
78                 pbx_builtin_setvar_helper(chan, "SENDURLSTATUS", status);
79                 return -1;
80         }
81
82         tmp = ast_strdupa(data);
83
84         AST_STANDARD_APP_ARGS(args, tmp);
85         if (args.argc == 2)
86                 ast_app_parse_options(app_opts, &flags, opts, args.options);
87         
88         if (!ast_channel_supports_html(chan)) {
89                 /* Does not support transport */
90                 pbx_builtin_setvar_helper(chan, "SENDURLSTATUS", "UNSUPPORTED");
91                 return 0;
92         }
93         res = ast_channel_sendurl(chan, args.url);
94         if (res == -1) {
95                 pbx_builtin_setvar_helper(chan, "SENDURLSTATUS", "FAILURE");
96                 return res;
97         }
98         status = "SUCCESS";
99         if (ast_test_flag(&flags, OPTION_WAIT)) {
100                 for(;;) {
101                         /* Wait for an event */
102                         res = ast_waitfor(chan, -1);
103                         if (res < 0) 
104                                 break;
105                         f = ast_read(chan);
106                         if (!f) {
107                                 res = -1;
108                                 status = "FAILURE";
109                                 break;
110                         }
111                         if (f->frametype == AST_FRAME_HTML) {
112                                 switch(f->subclass) {
113                                 case AST_HTML_LDCOMPLETE:
114                                         res = 0;
115                                         ast_frfree(f);
116                                         status = "NOLOAD";
117                                         goto out;
118                                         break;
119                                 case AST_HTML_NOSUPPORT:
120                                         /* Does not support transport */
121                                         status = "UNSUPPORTED";
122                                         res = 0;
123                                         ast_frfree(f);
124                                         goto out;
125                                         break;
126                                 default:
127                                         ast_log(LOG_WARNING, "Don't know what to do with HTML subclass %d\n", f->subclass);
128                                 };
129                         }
130                         ast_frfree(f);
131                 }
132         } 
133 out:    
134         pbx_builtin_setvar_helper(chan, "SENDURLSTATUS", status);
135         return res;
136 }
137
138 static int unload_module(void)
139 {
140         return ast_unregister_application(app);
141 }
142
143 static int load_module(void)
144 {
145         return ast_register_application(app, sendurl_exec, synopsis, descrip);
146 }
147
148 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Send URL Applications");