Fri Jun 19 12:09:29 2009

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: 89522 $")
00031 
00032 #include "asterisk/pbx.h"
00033 #include "asterisk/module.h"
00034 #include "asterisk/app.h"
00035 #include "asterisk/channel.h"
00036 
00037 static char *app = "SendURL";
00038 
00039 static char *synopsis = "Send a URL";
00040 
00041 static char *descrip = 
00042 "  SendURL(URL[,option]): Requests client go to URL (IAX2) or sends the \n"
00043 "URL to the client (other channels).\n"
00044 "Result is returned in the SENDURLSTATUS channel variable:\n"
00045 "    SUCCESS       URL successfully sent to client\n"
00046 "    FAILURE       Failed to send URL\n"
00047 "    NOLOAD        Client failed to load URL (wait enabled)\n"
00048 "    UNSUPPORTED   Channel does not support URL transport\n"
00049 "\n"
00050 "If the option 'w' is specified, execution will wait for an\n"
00051 "acknowledgement that the URL has been loaded before continuing\n"
00052 "\n"
00053 "SendURL continues normally if the URL was sent correctly or if the channel\n"
00054 "does not support HTML transport.  Otherwise, the channel is hung up.\n";
00055 
00056 enum {
00057    OPTION_WAIT = (1 << 0),
00058 } option_flags;
00059 
00060 AST_APP_OPTIONS(app_opts,{
00061    AST_APP_OPTION('w', OPTION_WAIT),
00062 });
00063 
00064 static int sendurl_exec(struct ast_channel *chan, void *data)
00065 {
00066    int res = 0;
00067    char *tmp;
00068    struct ast_frame *f;
00069    char *status = "FAILURE";
00070    char *opts[0];
00071    struct ast_flags flags;
00072    AST_DECLARE_APP_ARGS(args,
00073       AST_APP_ARG(url);
00074       AST_APP_ARG(options);
00075    );
00076    
00077    if (ast_strlen_zero(data)) {
00078       ast_log(LOG_WARNING, "SendURL requires an argument (URL)\n");
00079       pbx_builtin_setvar_helper(chan, "SENDURLSTATUS", status);
00080       return -1;
00081    }
00082 
00083    tmp = ast_strdupa(data);
00084 
00085    AST_STANDARD_APP_ARGS(args, tmp);
00086    if (args.argc == 2)
00087       ast_app_parse_options(app_opts, &flags, opts, args.options);
00088    
00089    if (!ast_channel_supports_html(chan)) {
00090       /* Does not support transport */
00091       pbx_builtin_setvar_helper(chan, "SENDURLSTATUS", "UNSUPPORTED");
00092       return 0;
00093    }
00094    res = ast_channel_sendurl(chan, args.url);
00095    if (res == -1) {
00096       pbx_builtin_setvar_helper(chan, "SENDURLSTATUS", "FAILURE");
00097       return res;
00098    }
00099    status = "SUCCESS";
00100    if (ast_test_flag(&flags, OPTION_WAIT)) {
00101       for(;;) {
00102          /* Wait for an event */
00103          res = ast_waitfor(chan, -1);
00104          if (res < 0) 
00105             break;
00106          f = ast_read(chan);
00107          if (!f) {
00108             res = -1;
00109             status = "FAILURE";
00110             break;
00111          }
00112          if (f->frametype == AST_FRAME_HTML) {
00113             switch(f->subclass) {
00114             case AST_HTML_LDCOMPLETE:
00115                res = 0;
00116                ast_frfree(f);
00117                status = "NOLOAD";
00118                goto out;
00119                break;
00120             case AST_HTML_NOSUPPORT:
00121                /* Does not support transport */
00122                status = "UNSUPPORTED";
00123                res = 0;
00124                ast_frfree(f);
00125                goto out;
00126                break;
00127             default:
00128                ast_log(LOG_WARNING, "Don't know what to do with HTML subclass %d\n", f->subclass);
00129             };
00130          }
00131          ast_frfree(f);
00132       }
00133    } 
00134 out:  
00135    pbx_builtin_setvar_helper(chan, "SENDURLSTATUS", status);
00136    return res;
00137 }
00138 
00139 static int unload_module(void)
00140 {
00141    return ast_unregister_application(app);
00142 }
00143 
00144 static int load_module(void)
00145 {
00146    return ast_register_application(app, sendurl_exec, synopsis, descrip);
00147 }
00148 
00149 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Send URL Applications");

Generated on Fri Jun 19 12:09:29 2009 for Asterisk - the Open Source PBX by  doxygen 1.4.7