Thu Apr 28 2011 17:13:28

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: 305889 $")
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 /*** DOCUMENTATION
00041    <application name="SendText" language="en_US">
00042       <synopsis>
00043          Send a Text Message.
00044       </synopsis>
00045       <syntax>
00046          <parameter name="text" required="true" />
00047       </syntax>
00048       <description>
00049          <para>Sends <replaceable>text</replaceable> to current channel (callee).</para>
00050          <para>Result of transmission will be stored in the <variable>SENDTEXTSTATUS</variable></para>
00051          <variablelist>
00052             <variable name="SENDTEXTSTATUS">
00053                <value name="SUCCESS">
00054                   Transmission succeeded.
00055                </value>
00056                <value name="FAILURE">
00057                   Transmission failed.
00058                </value>
00059                <value name="UNSUPPORTED">
00060                   Text transmission not supported by channel.
00061                </value>
00062             </variable>
00063          </variablelist>
00064          <note><para>At this moment, text is supposed to be 7 bit ASCII in most channels.</para></note>
00065       </description>
00066       <see-also>
00067          <ref type="application">SendImage</ref>
00068          <ref type="application">SendURL</ref>
00069       </see-also>
00070    </application>
00071  ***/
00072 
00073 static const char *app = "SendText";
00074 
00075 static int sendtext_exec(struct ast_channel *chan, void *data)
00076 {
00077    int res = 0;
00078    char *status = "UNSUPPORTED";
00079    char *parse = NULL;
00080    AST_DECLARE_APP_ARGS(args,
00081       AST_APP_ARG(text);
00082    );
00083 
00084    /* NOT ast_strlen_zero, because some protocols (e.g. SIP) MUST be able to
00085     * send a zero-length message. */
00086    if (!data) {
00087       ast_log(LOG_WARNING, "SendText requires an argument (text)\n");
00088       return -1;
00089    } else
00090       parse = ast_strdupa(data);
00091    
00092    AST_STANDARD_APP_ARGS(args, parse);
00093 
00094    ast_channel_lock(chan);
00095    if (!chan->tech->send_text) {
00096       ast_channel_unlock(chan);
00097       /* Does not support transport */
00098       pbx_builtin_setvar_helper(chan, "SENDTEXTSTATUS", status);
00099       return 0;
00100    }
00101    status = "FAILURE";
00102    res = ast_sendtext(chan, args.text);
00103    if (!res)
00104       status = "SUCCESS";
00105    ast_channel_unlock(chan);
00106    pbx_builtin_setvar_helper(chan, "SENDTEXTSTATUS", status);
00107    return 0;
00108 }
00109 
00110 static int unload_module(void)
00111 {
00112    return ast_unregister_application(app);
00113 }
00114 
00115 static int load_module(void)
00116 {
00117    return ast_register_application_xml(app, sendtext_exec);
00118 }
00119 
00120 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Send Text Applications");