Wed Jan 8 2020 09:49:40

Asterisk developer's documentation


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 <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>extended</support_level>
30  ***/
31 
32 #include "asterisk.h"
33 
34 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 339776 $")
35 
36 #include "asterisk/pbx.h"
37 #include "asterisk/module.h"
38 #include "asterisk/app.h"
39 #include "asterisk/channel.h"
40 
41 /*** DOCUMENTATION
42  <application name="SendURL" language="en_US">
43  <synopsis>
44  Send a URL.
45  </synopsis>
46  <syntax>
47  <parameter name="URL" required="true" />
48  <parameter name="option">
49  <optionlist>
50  <option name="w">
51  <para>Execution will wait for an acknowledgement that the
52  URL has been loaded before continuing.</para>
53  </option>
54  </optionlist>
55  </parameter>
56  </syntax>
57  <description>
58  <para>Requests client go to <replaceable>URL</replaceable> (IAX2) or sends the
59  URL to the client (other channels).</para>
60  <para>Result is returned in the <variable>SENDURLSTATUS</variable> channel variable:</para>
61  <variablelist>
62  <variable name="SENDURLSTATUS">
63  <value name="SUCCESS">
64  URL successfully sent to client.
65  </value>
66  <value name="FAILURE">
67  Failed to send URL.
68  </value>
69  <value name="NOLOAD">
70  Client failed to load URL (wait enabled).
71  </value>
72  <value name="UNSUPPORTED">
73  Channel does not support URL transport.
74  </value>
75  </variable>
76  </variablelist>
77  <para>SendURL continues normally if the URL was sent correctly or if the channel
78  does not support HTML transport. Otherwise, the channel is hung up.</para>
79  </description>
80  <see-also>
81  <ref type="application">SendImage</ref>
82  <ref type="application">SendText</ref>
83  </see-also>
84  </application>
85  ***/
86 
87 static char *app = "SendURL";
88 
90  OPTION_WAIT = (1 << 0),
91 };
92 
95 });
96 
97 static int sendurl_exec(struct ast_channel *chan, const char *data)
98 {
99  int res = 0;
100  char *tmp;
101  struct ast_frame *f;
102  char *status = "FAILURE";
103  char *opts[0];
104  struct ast_flags flags = { 0 };
106  AST_APP_ARG(url);
107  AST_APP_ARG(options);
108  );
109 
110  if (ast_strlen_zero(data)) {
111  ast_log(LOG_WARNING, "SendURL requires an argument (URL)\n");
112  pbx_builtin_setvar_helper(chan, "SENDURLSTATUS", status);
113  return -1;
114  }
115 
116  tmp = ast_strdupa(data);
117 
119  if (args.argc == 2)
120  ast_app_parse_options(app_opts, &flags, opts, args.options);
121 
122  if (!ast_channel_supports_html(chan)) {
123  /* Does not support transport */
124  pbx_builtin_setvar_helper(chan, "SENDURLSTATUS", "UNSUPPORTED");
125  return 0;
126  }
127  res = ast_channel_sendurl(chan, args.url);
128  if (res == -1) {
129  pbx_builtin_setvar_helper(chan, "SENDURLSTATUS", "FAILURE");
130  return res;
131  }
132  status = "SUCCESS";
133  if (ast_test_flag(&flags, OPTION_WAIT)) {
134  for(;;) {
135  /* Wait for an event */
136  res = ast_waitfor(chan, -1);
137  if (res < 0)
138  break;
139  f = ast_read(chan);
140  if (!f) {
141  res = -1;
142  status = "FAILURE";
143  break;
144  }
145  if (f->frametype == AST_FRAME_HTML) {
146  switch (f->subclass.integer) {
147  case AST_HTML_LDCOMPLETE:
148  res = 0;
149  ast_frfree(f);
150  status = "NOLOAD";
151  goto out;
152  break;
153  case AST_HTML_NOSUPPORT:
154  /* Does not support transport */
155  status = "UNSUPPORTED";
156  res = 0;
157  ast_frfree(f);
158  goto out;
159  break;
160  default:
161  ast_log(LOG_WARNING, "Don't know what to do with HTML subclass %d\n", f->subclass.integer);
162  };
163  }
164  ast_frfree(f);
165  }
166  }
167 out:
168  pbx_builtin_setvar_helper(chan, "SENDURLSTATUS", status);
169  return res;
170 }
171 
172 static int unload_module(void)
173 {
174  return ast_unregister_application(app);
175 }
176 
177 static int load_module(void)
178 {
180 }
181 
182 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Send URL Applications");
union ast_frame_subclass subclass
Definition: frame.h:146
Main Channel structure associated with a channel.
Definition: channel.h:742
#define AST_MODULE_INFO_STANDARD(keystr, desc)
Definition: module.h:396
Asterisk main include file. File version handling, generic pbx functions.
#define AST_APP_OPTIONS(holder, options...)
Declares an array of options for an application.
Definition: app.h:712
#define ast_test_flag(p, flag)
Definition: utils.h:63
int ast_channel_supports_html(struct ast_channel *channel)
Checks for HTML support on a channel.
Definition: channel.c:5902
#define LOG_WARNING
Definition: logger.h:144
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: app.c:2101
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application&#39;s arguments.
Definition: app.h:572
struct ast_frame * ast_read(struct ast_channel *chan)
Reads a frame.
Definition: channel.c:4383
static char * app
Definition: app_url.c:87
int ast_unregister_application(const char *app)
Unregister an application.
Definition: pbx.c:7705
static int load_module(void)
Definition: app_url.c:177
static struct ast_app_option app_opts[128]
Definition: app_url.c:95
General Asterisk PBX channel definitions.
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: utils.h:663
#define AST_HTML_LDCOMPLETE
Definition: frame.h:230
static struct @350 args
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
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:5914
#define AST_HTML_NOSUPPORT
Definition: frame.h:232
static int sendurl_exec(struct ast_channel *chan, const char *data)
Definition: app_url.c:97
static struct ast_format f[]
Definition: format_g726.c:181
Structure used to handle boolean flags.
Definition: utils.h:200
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...
Definition: pbx.c:10546
int ast_waitfor(struct ast_channel *chan, int ms)
Wait for input on a channel.
Definition: channel.c:3539
option_flags
Definition: app_skel.c:78
static int unload_module(void)
Definition: app_url.c:172
Application convenience functions, designed to give consistent look and feel to Asterisk apps...
Data structure associated with a single frame of data.
Definition: frame.h:142
#define AST_APP_ARG(name)
Define an application argument.
Definition: app.h:555
enum ast_frame_type frametype
Definition: frame.h:144
#define ast_frfree(fr)
Definition: frame.h:583
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the &#39;standard&#39; argument separation process for an application.
Definition: app.h:604
static char url[512]
#define ASTERISK_GPL_KEY
The text the key() function should return.
Definition: module.h:38
Asterisk module definitions.
union ast_frame::@172 data
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
Definition: module.h:437
jack_status_t status
Definition: app_jack.c:143
#define ASTERISK_FILE_VERSION(file, version)
Register/unregister a source code file with the core.
Definition: asterisk.h:180
#define AST_APP_OPTION(option, flagno)
Declares an application option that does not accept an argument.
Definition: app.h:721