Fri Jun 19 12:09:28 2009

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: 187365 $")
00033 
00034 #include "asterisk/file.h"
00035 #include "asterisk/channel.h"
00036 #include "asterisk/pbx.h"
00037 #include "asterisk/module.h"
00038 #include "asterisk/app.h"
00039 
00040 static const char *app = "SendText";
00041 
00042 static const char *synopsis = "Send a Text Message";
00043 
00044 static const char *descrip = 
00045 "  SendText(text): Sends text to current channel (callee).\n"
00046 "Result of transmission will be stored in the SENDTEXTSTATUS\n"
00047 "channel variable:\n"
00048 "      SUCCESS      Transmission succeeded\n"
00049 "      FAILURE      Transmission failed\n"
00050 "      UNSUPPORTED  Text transmission not supported by channel\n"
00051 "\n"
00052 "At this moment, text is supposed to be 7 bit ASCII in most channels.\n";
00053 
00054 static int sendtext_exec(struct ast_channel *chan, void *data)
00055 {
00056    int res = 0;
00057    char *status = "UNSUPPORTED";
00058    char *parse = NULL;
00059    AST_DECLARE_APP_ARGS(args,
00060       AST_APP_ARG(text);
00061    );
00062 
00063    /* NOT ast_strlen_zero, because some protocols (e.g. SIP) MUST be able to
00064     * send a zero-length message. */
00065    if (!data) {
00066       ast_log(LOG_WARNING, "SendText requires an argument (text)\n");
00067       return -1;
00068    } else
00069       parse = ast_strdupa(data);
00070    
00071    AST_STANDARD_APP_ARGS(args, parse);
00072 
00073    ast_channel_lock(chan);
00074    if (!chan->tech->send_text) {
00075       ast_channel_unlock(chan);
00076       /* Does not support transport */
00077       pbx_builtin_setvar_helper(chan, "SENDTEXTSTATUS", status);
00078       return 0;
00079    }
00080    status = "FAILURE";
00081    ast_channel_unlock(chan);
00082    res = ast_sendtext(chan, args.text);
00083    if (!res)
00084       status = "SUCCESS";
00085    pbx_builtin_setvar_helper(chan, "SENDTEXTSTATUS", status);
00086    return 0;
00087 }
00088 
00089 static int unload_module(void)
00090 {
00091    return ast_unregister_application(app);
00092 }
00093 
00094 static int load_module(void)
00095 {
00096    return ast_register_application(app, sendtext_exec, synopsis, descrip);
00097 }
00098 
00099 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Send Text Applications");

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