Sat Aug 6 00:39:21 2011

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: 43445 $")
00031 
00032 #include <stdlib.h>
00033 #include <stdio.h>
00034 #include <string.h>
00035 
00036 #include "asterisk/lock.h"
00037 #include "asterisk/file.h"
00038 #include "asterisk/logger.h"
00039 #include "asterisk/channel.h"
00040 #include "asterisk/pbx.h"
00041 #include "asterisk/module.h"
00042 #include "asterisk/translate.h"
00043 #include "asterisk/image.h"
00044 #include "asterisk/options.h"
00045 
00046 static char *app = "SendURL";
00047 
00048 static char *synopsis = "Send a URL";
00049 
00050 static char *descrip = 
00051 "  SendURL(URL[|option]): Requests client go to URL (IAX2) or sends the \n"
00052 "URL to the client (other channels).\n"
00053 "Result is returned in the SENDURLSTATUS channel variable:\n"
00054 "    SUCCESS       URL successfully sent to client\n"
00055 "    FAILURE       Failed to send URL\n"
00056 "    NOLOAD        Client failed to load URL (wait enabled)\n"
00057 "    UNSUPPORTED   Channel does not support URL transport\n"
00058 "\n"
00059 "If the option 'wait' is specified, execution will wait for an\n"
00060 "acknowledgement that the URL has been loaded before continuing\n"
00061 "\n"
00062 "If jumping is specified as an option (the 'j' flag), the client does not\n"
00063 "support Asterisk \"html\" transport, and there exists a step with priority\n"
00064 "n + 101, then execution will continue at that step.\n"
00065 "\n"
00066 "SendURL continues normally if the URL was sent correctly or if the channel\n"
00067 "does not support HTML transport.  Otherwise, the channel is hung up.\n";
00068 
00069 
00070 static int sendurl_exec(struct ast_channel *chan, void *data)
00071 {
00072    int res = 0;
00073    struct ast_module_user *u;
00074    char *tmp;
00075    char *options;
00076    int local_option_wait=0;
00077    int local_option_jump = 0;
00078    struct ast_frame *f;
00079    char *stringp=NULL;
00080    char *status = "FAILURE";
00081    
00082    if (ast_strlen_zero(data)) {
00083       ast_log(LOG_WARNING, "SendURL requires an argument (URL)\n");
00084       pbx_builtin_setvar_helper(chan, "SENDURLSTATUS", status);
00085       return -1;
00086    }
00087 
00088    u = ast_module_user_add(chan);
00089 
00090    tmp = ast_strdupa(data);
00091 
00092    stringp=tmp;
00093    strsep(&stringp, "|");
00094    options = strsep(&stringp, "|");
00095    if (options && !strcasecmp(options, "wait"))
00096       local_option_wait = 1;
00097    if (options && !strcasecmp(options, "j"))
00098       local_option_jump = 1;
00099    
00100    if (!ast_channel_supports_html(chan)) {
00101       /* Does not support transport */
00102       if (local_option_jump || ast_opt_priority_jumping)
00103           ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101);
00104       pbx_builtin_setvar_helper(chan, "SENDURLSTATUS", "UNSUPPORTED");
00105       ast_module_user_remove(u);
00106       return 0;
00107    }
00108    res = ast_channel_sendurl(chan, tmp);
00109    if (res == -1) {
00110       pbx_builtin_setvar_helper(chan, "SENDURLSTATUS", "FAILURE");
00111       ast_module_user_remove(u);
00112       return res;
00113    }
00114    status = "SUCCESS";
00115    if (local_option_wait) {
00116       for(;;) {
00117          /* Wait for an event */
00118          res = ast_waitfor(chan, -1);
00119          if (res < 0) 
00120             break;
00121          f = ast_read(chan);
00122          if (!f) {
00123             res = -1;
00124             status = "FAILURE";
00125             break;
00126          }
00127          if (f->frametype == AST_FRAME_HTML) {
00128             switch(f->subclass) {
00129             case AST_HTML_LDCOMPLETE:
00130                res = 0;
00131                ast_frfree(f);
00132                status = "NOLOAD";
00133                goto out;
00134                break;
00135             case AST_HTML_NOSUPPORT:
00136                /* Does not support transport */
00137                status ="UNSUPPORTED";
00138                if (local_option_jump || ast_opt_priority_jumping)
00139                   ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101);
00140                res = 0;
00141                ast_frfree(f);
00142                goto out;
00143                break;
00144             default:
00145                ast_log(LOG_WARNING, "Don't know what to do with HTML subclass %d\n", f->subclass);
00146             };
00147          }
00148          ast_frfree(f);
00149       }
00150    } 
00151 out:  
00152    pbx_builtin_setvar_helper(chan, "SENDURLSTATUS", status);
00153    ast_module_user_remove(u);
00154    return res;
00155 }
00156 
00157 static int unload_module(void)
00158 {
00159    int res;
00160 
00161    res = ast_unregister_application(app);
00162    
00163    ast_module_user_hangup_all();
00164 
00165    return res; 
00166 }
00167 
00168 static int load_module(void)
00169 {
00170    return ast_register_application(app, sendurl_exec, synopsis, descrip);
00171 }
00172 
00173 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Send URL Applications");

Generated on Sat Aug 6 00:39:21 2011 for Asterisk - the Open Source PBX by  doxygen 1.4.7