Thu Apr 28 2011 17:13:29

Asterisk developer's documentation


app_url.c

Go to the documentation of this file.
00001 /*
00002  * Asterisk -- An open source telephony toolkit.
00003  *
00004  * Copyright (C) 1999 - 2005, Digium, Inc.
00005  *
00006  * Mark Spencer <markster@digium.com>
00007  *
00008  * See http://www.asterisk.org for more information about
00009  * the Asterisk project. Please do not directly contact
00010  * any of the maintainers of this project for assistance;
00011  * the project provides a web site, mailing lists and IRC
00012  * channels for your use.
00013  *
00014  * This program is free software, distributed under the terms of
00015  * the GNU General Public License Version 2. See the LICENSE file
00016  * at the top of the source tree.
00017  */
00018 
00019 /*! \file
00020  *
00021  * \brief App to transmit a URL
00022  *
00023  * \author Mark Spencer <markster@digium.com>
00024  * 
00025  * \ingroup applications
00026  */
00027  
00028 #include "asterisk.h"
00029 
00030 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 154542 $")
00031 
00032 #include "asterisk/pbx.h"
00033 #include "asterisk/module.h"
00034 #include "asterisk/app.h"
00035 #include "asterisk/channel.h"
00036 
00037 /*** DOCUMENTATION
00038    <application name="SendURL" language="en_US">
00039       <synopsis>
00040          Send a URL.
00041       </synopsis>
00042       <syntax>
00043          <parameter name="URL" required="true" />
00044          <parameter name="option">
00045             <optionlist>
00046                <option name="w">
00047                   <para>Execution will wait for an acknowledgement that the
00048                   URL has been loaded before continuing.</para>
00049                </option>
00050             </optionlist>
00051          </parameter>
00052       </syntax>
00053       <description>
00054          <para>Requests client go to <replaceable>URL</replaceable> (IAX2) or sends the
00055          URL to the client (other channels).</para>
00056          <para>Result is returned in the <variable>SENDURLSTATUS</variable> channel variable:</para>
00057          <variablelist>
00058             <variable name="SENDURLSTATUS">
00059                <value name="SUCCESS">
00060                   URL successfully sent to client.
00061                </value>
00062                <value name="FAILURE">
00063                   Failed to send URL.
00064                </value>
00065                <value name="NOLOAD">
00066                   Client failed to load URL (wait enabled).
00067                </value>
00068                <value name="UNSUPPORTED">
00069                   Channel does not support URL transport.
00070                </value>
00071             </variable>
00072          </variablelist>
00073          <para>SendURL continues normally if the URL was sent correctly or if the channel
00074          does not support HTML transport.  Otherwise, the channel is hung up.</para>
00075       </description>
00076       <see-also>
00077          <ref type="application">SendImage</ref>
00078          <ref type="application">SendText</ref>
00079       </see-also>
00080    </application>
00081  ***/
00082 
00083 static char *app = "SendURL";
00084 
00085 enum {
00086    OPTION_WAIT = (1 << 0),
00087 } option_flags;
00088 
00089 AST_APP_OPTIONS(app_opts,{
00090    AST_APP_OPTION('w', OPTION_WAIT),
00091 });
00092 
00093 static int sendurl_exec(struct ast_channel *chan, void *data)
00094 {
00095    int res = 0;
00096    char *tmp;
00097    struct ast_frame *f;
00098    char *status = "FAILURE";
00099    char *opts[0];
00100    struct ast_flags flags;
00101    AST_DECLARE_APP_ARGS(args,
00102       AST_APP_ARG(url);
00103       AST_APP_ARG(options);
00104    );
00105    
00106    if (ast_strlen_zero(data)) {
00107       ast_log(LOG_WARNING, "SendURL requires an argument (URL)\n");
00108       pbx_builtin_setvar_helper(chan, "SENDURLSTATUS", status);
00109       return -1;
00110    }
00111 
00112    tmp = ast_strdupa(data);
00113 
00114    AST_STANDARD_APP_ARGS(args, tmp);
00115    if (args.argc == 2)
00116       ast_app_parse_options(app_opts, &flags, opts, args.options);
00117    
00118    if (!ast_channel_supports_html(chan)) {
00119       /* Does not support transport */
00120       pbx_builtin_setvar_helper(chan, "SENDURLSTATUS", "UNSUPPORTED");
00121       return 0;
00122    }
00123    res = ast_channel_sendurl(chan, args.url);
00124    if (res == -1) {
00125       pbx_builtin_setvar_helper(chan, "SENDURLSTATUS", "FAILURE");
00126       return res;
00127    }
00128    status = "SUCCESS";
00129    if (ast_test_flag(&flags, OPTION_WAIT)) {
00130       for(;;) {
00131          /* Wait for an event */
00132          res = ast_waitfor(chan, -1);
00133          if (res < 0) 
00134             break;
00135          f = ast_read(chan);
00136          if (!f) {
00137             res = -1;
00138             status = "FAILURE";
00139             break;
00140          }
00141          if (f->frametype == AST_FRAME_HTML) {
00142             switch(f->subclass) {
00143             case AST_HTML_LDCOMPLETE:
00144                res = 0;
00145                ast_frfree(f);
00146                status = "NOLOAD";
00147                goto out;
00148                break;
00149             case AST_HTML_NOSUPPORT:
00150                /* Does not support transport */
00151                status = "UNSUPPORTED";
00152                res = 0;
00153                ast_frfree(f);
00154                goto out;
00155                break;
00156             default:
00157                ast_log(LOG_WARNING, "Don't know what to do with HTML subclass %d\n", f->subclass);
00158             };
00159          }
00160          ast_frfree(f);
00161       }
00162    } 
00163 out:  
00164    pbx_builtin_setvar_helper(chan, "SENDURLSTATUS", status);
00165    return res;
00166 }
00167 
00168 static int unload_module(void)
00169 {
00170    return ast_unregister_application(app);
00171 }
00172 
00173 static int load_module(void)
00174 {
00175    return ast_register_application_xml(app, sendurl_exec);
00176 }
00177 
00178 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Send URL Applications");