Tue Sep 30 01:19:30 2008

Asterisk developer's documentation


app_sendtext.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 text message
00022  *
00023  * \author Mark Spencer <markster@digium.com>
00024  * 
00025  * \note Requires support of sending text messages from channel driver
00026  *
00027  * \ingroup applications
00028  */
00029  
00030 #include "asterisk.h"
00031 
00032 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 40722 $")
00033 
00034 #include <stdlib.h>
00035 #include <stdio.h>
00036 #include <string.h>
00037 
00038 #include "asterisk/lock.h"
00039 #include "asterisk/file.h"
00040 #include "asterisk/logger.h"
00041 #include "asterisk/channel.h"
00042 #include "asterisk/pbx.h"
00043 #include "asterisk/module.h"
00044 #include "asterisk/translate.h"
00045 #include "asterisk/image.h"
00046 #include "asterisk/options.h"
00047 #include "asterisk/app.h"
00048 
00049 static const char *app = "SendText";
00050 
00051 static const char *synopsis = "Send a Text Message";
00052 
00053 static const char *descrip = 
00054 "  SendText(text[|options]): Sends text to current channel (callee).\n"
00055 "Result of transmission will be stored in the SENDTEXTSTATUS\n"
00056 "channel variable:\n"
00057 "      SUCCESS      Transmission succeeded\n"
00058 "      FAILURE      Transmission failed\n"
00059 "      UNSUPPORTED  Text transmission not supported by channel\n"
00060 "\n"
00061 "At this moment, text is supposed to be 7 bit ASCII in most channels.\n"
00062 "The option string many contain the following character:\n"
00063 "'j' -- jump to n+101 priority if the channel doesn't support\n"
00064 "       text transport\n";
00065 
00066 
00067 static int sendtext_exec(struct ast_channel *chan, void *data)
00068 {
00069    int res = 0;
00070    struct ast_module_user *u;
00071    char *status = "UNSUPPORTED";
00072    char *parse = NULL;
00073    int priority_jump = 0;
00074    AST_DECLARE_APP_ARGS(args,
00075       AST_APP_ARG(text);
00076       AST_APP_ARG(options);
00077    );
00078       
00079    u = ast_module_user_add(chan);   
00080 
00081    if (ast_strlen_zero(data)) {
00082       ast_log(LOG_WARNING, "SendText requires an argument (text[|options])\n");
00083       ast_module_user_remove(u);
00084       return -1;
00085    } else
00086       parse = ast_strdupa(data);
00087    
00088    AST_STANDARD_APP_ARGS(args, parse);
00089 
00090    if (args.options) {
00091       if (strchr(args.options, 'j'))
00092          priority_jump = 1;
00093    }
00094 
00095    ast_channel_lock(chan);
00096    if (!chan->tech->send_text) {
00097       ast_channel_unlock(chan);
00098       /* Does not support transport */
00099       if (priority_jump || ast_opt_priority_jumping)
00100          ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101);
00101       ast_module_user_remove(u);
00102       return 0;
00103    }
00104    status = "FAILURE";
00105    ast_channel_unlock(chan);
00106    res = ast_sendtext(chan, args.text);
00107    if (!res)
00108       status = "SUCCESS";
00109    pbx_builtin_setvar_helper(chan, "SENDTEXTSTATUS", status);
00110    ast_module_user_remove(u);
00111    return 0;
00112 }
00113 
00114 static int unload_module(void)
00115 {
00116    int res;
00117    
00118    res = ast_unregister_application(app);
00119    
00120    ast_module_user_hangup_all();
00121 
00122    return res; 
00123 }
00124 
00125 static int load_module(void)
00126 {
00127    return ast_register_application(app, sendtext_exec, synopsis, descrip);
00128 }
00129 
00130 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Send Text Applications");

Generated on Tue Sep 30 01:19:30 2008 for Asterisk - the Open Source PBX by  doxygen 1.5.6