Asterisk - The Open Source Telephony Project  18.5.0
app_url.c
Go to the documentation of this file.
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 1999 - 2005, Digium, Inc.
5  *
6  * Mark Spencer <[email protected]>
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 <[email protected]>
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 
88  OPTION_WAIT = (1 << 0),
89 };
90 
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 };
104  AST_APP_ARG(url);
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 
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 {
173 }
174 
175 static int load_module(void)
176 {
178 }
179 
180 AST_MODULE_INFO_STANDARD_DEPRECATED(ASTERISK_GPL_KEY, "Send URL Applications");
Main Channel structure associated with a channel.
Asterisk main include file. File version handling, generic pbx functions.
#define AST_HTML_NOSUPPORT
#define ast_test_flag(p, flag)
Definition: utils.h:63
#define AST_HTML_LDCOMPLETE
int ast_channel_supports_html(struct ast_channel *channel)
Checks for HTML support on a channel.
Definition: channel.c:6720
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the &#39;standard&#39; argument separation process for an application.
#define LOG_WARNING
Definition: logger.h:274
static int tmp()
Definition: bt_open.c:389
struct ast_frame * ast_read(struct ast_channel *chan)
Reads a frame.
Definition: channel.c:4302
static char * app
Definition: app_url.c:85
const char * args
int ast_unregister_application(const char *app)
Unregister an application.
Definition: pbx_app.c:392
struct ast_frame_subclass subclass
static int load_module(void)
Definition: app_url.c:175
#define ast_strlen_zero(foo)
Definition: strings.h:52
static const struct ast_app_option app_opts[128]
Definition: app_url.c:93
#define AST_APP_OPTIONS(holder, options...)
Declares an array of options for an application.
AST_MODULE_INFO_STANDARD_DEPRECATED(ASTERISK_GPL_KEY, "Send URL Applications")
#define ast_log
Definition: astobj2.c:42
General Asterisk PBX channel definitions.
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:300
int ast_app_parse_options(const struct ast_app_option *options, struct ast_flags *flags, char **args, char *optstr)
Parses a string containing application options and sets flags/arguments.
Definition: main/app.c:2906
Core PBX routines and definitions.
int ast_channel_sendurl(struct ast_channel *channel, const char *url)
Sends a URL on a given link Send URL on link.
Definition: channel.c:6732
static int sendurl_exec(struct ast_channel *chan, const char *data)
Definition: app_url.c:95
Structure used to handle boolean flags.
Definition: utils.h:199
int pbx_builtin_setvar_helper(struct ast_channel *chan, const char *name, const char *value)
Add a variable to the channel variable stack, removing the most recently set value for the same name...
FILE * out
Definition: utils/frame.c:33
int ast_waitfor(struct ast_channel *chan, int ms)
Wait for input on a channel.
Definition: channel.c:3171
option_flags
Definition: app_skel.c:136
static int unload_module(void)
Definition: app_url.c:170
#define ast_frfree(fr)
Data structure associated with a single frame of data.
enum ast_frame_type frametype
static struct test_options options
#define AST_APP_OPTION(option, flagno)
Declares an application option that does not accept an argument.
static char url[512]
#define ASTERISK_GPL_KEY
The text the key() function should return.
Definition: module.h:46
Asterisk module definitions.
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application&#39;s arguments.
Application convenience functions, designed to give consistent look and feel to Asterisk apps...
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
Definition: module.h:626
jack_status_t status
Definition: app_jack.c:146
#define AST_APP_ARG(name)
Define an application argument.