Mon Mar 20 08:20:07 2006

Asterisk developer's documentation


Main Page | Modules | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

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  * \brief App to transmit a URL
00021  * 
00022  * \ingroup applications
00023  */
00024  
00025 #include <stdlib.h>
00026 #include <stdio.h>
00027 #include <string.h>
00028 
00029 #include "asterisk.h"
00030 
00031 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 7221 $")
00032 
00033 #include "asterisk/lock.h"
00034 #include "asterisk/file.h"
00035 #include "asterisk/logger.h"
00036 #include "asterisk/channel.h"
00037 #include "asterisk/pbx.h"
00038 #include "asterisk/module.h"
00039 #include "asterisk/translate.h"
00040 #include "asterisk/image.h"
00041 #include "asterisk/options.h"
00042 
00043 static char *tdesc = "Send URL Applications";
00044 
00045 static char *app = "SendURL";
00046 
00047 static char *synopsis = "Send a URL";
00048 
00049 static char *descrip = 
00050 "  SendURL(URL[|option]): Requests client go to URL (IAX2) or sends the \n"
00051 "URL to the client (other channels).\n"
00052 "Result is returned in the SENDURLSTATUS channel variable:\n"
00053 "    SUCCESS       URL successfully sent to client\n"
00054 "    FAILURE       Failed to send URL\n"
00055 "    NOLOAD        Clien failed to load URL (wait enabled)\n"
00056 "    UNSUPPORTED   Channel does not support URL transport\n"
00057 "\n"
00058 "If the option 'wait' is specified, execution will wait for an\n"
00059 "acknowledgement that the URL has been loaded before continuing\n"
00060 "and will return -1 if the peer is unable to load the URL\n"
00061 "\n"
00062 "Old behaviour (deprecated): \n"
00063 " If the client does not support Asterisk \"html\" transport, \n"
00064 " and there exists a step with priority n + 101, then execution will\n"
00065 " continue at that step.\n"
00066 " Otherwise, execution will continue at the next priority level.\n"
00067 " SendURL only returns 0 if the URL was sent correctly  or if\n"
00068 " the channel does not support HTML transport, and -1 otherwise.\n";
00069 
00070 STANDARD_LOCAL_USER;
00071 
00072 LOCAL_USER_DECL;
00073 
00074 static int sendurl_exec(struct ast_channel *chan, void *data)
00075 {
00076    int res = 0;
00077    struct localuser *u;
00078    char *tmp;
00079    char *options;
00080    int local_option_wait=0;
00081    int local_option_jump = 0;
00082    struct ast_frame *f;
00083    char *stringp=NULL;
00084    char *status = "FAILURE";
00085    
00086    if (ast_strlen_zero(data)) {
00087       ast_log(LOG_WARNING, "SendURL requires an argument (URL)\n");
00088       pbx_builtin_setvar_helper(chan, "SENDURLSTATUS", status);
00089       return -1;
00090    }
00091 
00092    LOCAL_USER_ADD(u);
00093 
00094    tmp = ast_strdupa(data);
00095    if (!tmp) {
00096       ast_log(LOG_ERROR, "Out of memory\n");
00097       LOCAL_USER_REMOVE(u);
00098       return -1;
00099    }
00100 
00101    stringp=tmp;
00102    strsep(&stringp, "|");
00103    options = strsep(&stringp, "|");
00104    if (options && !strcasecmp(options, "wait"))
00105       local_option_wait = 1;
00106    if (options && !strcasecmp(options, "j"))
00107       local_option_jump = 1;
00108    
00109    if (!ast_channel_supports_html(chan)) {
00110       /* Does not support transport */
00111       if (local_option_jump || option_priority_jumping)
00112           ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101);
00113       pbx_builtin_setvar_helper(chan, "SENDURLSTATUS", "UNSUPPORTED");
00114       LOCAL_USER_REMOVE(u);
00115       return 0;
00116    }
00117    res = ast_channel_sendurl(chan, tmp);
00118    if (res == -1) {
00119       pbx_builtin_setvar_helper(chan, "SENDURLSTATUS", "FAILURE");
00120       LOCAL_USER_REMOVE(u);
00121       return res;
00122    }
00123    status = "SUCCESS";
00124    if (local_option_wait) {
00125       for(;;) {
00126          /* Wait for an event */
00127          res = ast_waitfor(chan, -1);
00128          if (res < 0) 
00129             break;
00130          f = ast_read(chan);
00131          if (!f) {
00132             res = -1;
00133             status = "FAILURE";
00134             break;
00135          }
00136          if (f->frametype == AST_FRAME_HTML) {
00137             switch(f->subclass) {
00138             case AST_HTML_LDCOMPLETE:
00139                res = 0;
00140                ast_frfree(f);
00141                status = "NOLOAD";
00142                goto out;
00143                break;
00144             case AST_HTML_NOSUPPORT:
00145                /* Does not support transport */
00146                status ="UNSUPPORTED";
00147                if (local_option_jump || option_priority_jumping)
00148                   ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101);
00149                res = 0;
00150                goto out;
00151                break;
00152             default:
00153                ast_log(LOG_WARNING, "Don't know what to do with HTML subclass %d\n", f->subclass);
00154             };
00155          }
00156          ast_frfree(f);
00157       }
00158    } 
00159 out:  
00160    pbx_builtin_setvar_helper(chan, "SENDURLSTATUS", status);
00161    LOCAL_USER_REMOVE(u);
00162    return res;
00163 }
00164 
00165 int unload_module(void)
00166 {
00167    int res;
00168 
00169    res = ast_unregister_application(app);
00170    
00171    STANDARD_HANGUP_LOCALUSERS;
00172 
00173    return res; 
00174 }
00175 
00176 int load_module(void)
00177 {
00178    return ast_register_application(app, sendurl_exec, synopsis, descrip);
00179 }
00180 
00181 char *description(void)
00182 {
00183    return tdesc;
00184 }
00185 
00186 int usecount(void)
00187 {
00188    int res;
00189    STANDARD_USECOUNT(res);
00190    return res;
00191 }
00192 
00193 char *key()
00194 {
00195    return ASTERISK_GPL_KEY;
00196 }

Generated on Mon Mar 20 08:20:07 2006 for Asterisk - the Open Source PBX by  doxygen 1.3.9.1