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 /*** MODULEINFO
00029    <support_level>extended</support_level>
00030  ***/
00031  
00032 #include "asterisk.h"
00033 
00034 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 419592 $")
00035 
00036 #include "asterisk/pbx.h"
00037 #include "asterisk/module.h"
00038 #include "asterisk/app.h"
00039 #include "asterisk/channel.h"
00040 
00041 /*** DOCUMENTATION
00042    <application name="SendURL" language="en_US">
00043       <synopsis>
00044          Send a URL.
00045       </synopsis>
00046       <syntax>
00047          <parameter name="URL" required="true" />
00048          <parameter name="option">
00049             <optionlist>
00050                <option name="w">
00051                   <para>Execution will wait for an acknowledgement that the
00052                   URL has been loaded before continuing.</para>
00053                </option>
00054             </optionlist>
00055          </parameter>
00056       </syntax>
00057       <description>
00058          <para>Requests client go to <replaceable>URL</replaceable> (IAX2) or sends the
00059          URL to the client (other channels).</para>
00060          <para>Result is returned in the <variable>SENDURLSTATUS</variable> channel variable:</para>
00061          <variablelist>
00062             <variable name="SENDURLSTATUS">
00063                <value name="SUCCESS">
00064                   URL successfully sent to client.
00065                </value>
00066                <value name="FAILURE">
00067                   Failed to send URL.
00068                </value>
00069                <value name="NOLOAD">
00070                   Client failed to load URL (wait enabled).
00071                </value>
00072                <value name="UNSUPPORTED">
00073                   Channel does not support URL transport.
00074                </value>
00075             </variable>
00076          </variablelist>
00077          <para>SendURL continues normally if the URL was sent correctly or if the channel
00078          does not support HTML transport.  Otherwise, the channel is hung up.</para>
00079       </description>
00080       <see-also>
00081          <ref type="application">SendImage</ref>
00082          <ref type="application">SendText</ref>
00083       </see-also>
00084    </application>
00085  ***/
00086 
00087 static char *app = "SendURL";
00088 
00089 enum option_flags {
00090    OPTION_WAIT = (1 << 0),
00091 };
00092 
00093 AST_APP_OPTIONS(app_opts,{
00094    AST_APP_OPTION('w', OPTION_WAIT),
00095 });
00096 
00097 static int sendurl_exec(struct ast_channel *chan, const char *data)
00098 {
00099    int res = 0;
00100    char *tmp;
00101    struct ast_frame *f;
00102    char *status = "FAILURE";
00103    char *opts[0];
00104    struct ast_flags flags = { 0 };
00105    AST_DECLARE_APP_ARGS(args,
00106       AST_APP_ARG(url);
00107       AST_APP_ARG(options);
00108    );
00109    
00110    if (ast_strlen_zero(data)) {
00111       ast_log(LOG_WARNING, "SendURL requires an argument (URL)\n");
00112       pbx_builtin_setvar_helper(chan, "SENDURLSTATUS", status);
00113       return -1;
00114    }
00115 
00116    tmp = ast_strdupa(data);
00117 
00118    AST_STANDARD_APP_ARGS(args, tmp);
00119    if (args.argc == 2)
00120       ast_app_parse_options(app_opts, &flags, opts, args.options);
00121    
00122    if (!ast_channel_supports_html(chan)) {
00123       /* Does not support transport */
00124       pbx_builtin_setvar_helper(chan, "SENDURLSTATUS", "UNSUPPORTED");
00125       return 0;
00126    }
00127    res = ast_channel_sendurl(chan, args.url);
00128    if (res == -1) {
00129       pbx_builtin_setvar_helper(chan, "SENDURLSTATUS", "FAILURE");
00130       return res;
00131    }
00132    status = "SUCCESS";
00133    if (ast_test_flag(&flags, OPTION_WAIT)) {
00134       for(;;) {
00135          /* Wait for an event */
00136          res = ast_waitfor(chan, -1);
00137          if (res < 0) 
00138             break;
00139          f = ast_read(chan);
00140          if (!f) {
00141             res = -1;
00142             status = "FAILURE";
00143             break;
00144          }
00145          if (f->frametype == AST_FRAME_HTML) {
00146             switch (f->subclass.integer) {
00147             case AST_HTML_LDCOMPLETE:
00148                res = 0;
00149                ast_frfree(f);
00150                status = "NOLOAD";
00151                goto out;
00152                break;
00153             case AST_HTML_NOSUPPORT:
00154                /* Does not support transport */
00155                status = "UNSUPPORTED";
00156                res = 0;
00157                ast_frfree(f);
00158                goto out;
00159                break;
00160             default:
00161                ast_log(LOG_WARNING, "Don't know what to do with HTML subclass %d\n", f->subclass.integer);
00162             };
00163          }
00164          ast_frfree(f);
00165       }
00166    } 
00167 out:  
00168    pbx_builtin_setvar_helper(chan, "SENDURLSTATUS", status);
00169    return res;
00170 }
00171 
00172 static int unload_module(void)
00173 {
00174    return ast_unregister_application(app);
00175 }
00176 
00177 static int load_module(void)
00178 {
00179    return ast_register_application_xml(app, sendurl_exec);
00180 }
00181 
00182 AST_MODULE_INFO_STANDARD_EXTENDED(ASTERISK_GPL_KEY, "Send URL Applications");
00183 

Generated on Thu Apr 16 06:27:12 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6