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 /*** MODULEINFO
00031    <support_level>core</support_level>
00032  ***/
00033  
00034 #include "asterisk.h"
00035 
00036 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 356042 $")
00037 
00038 #include "asterisk/file.h"
00039 #include "asterisk/channel.h"
00040 #include "asterisk/pbx.h"
00041 #include "asterisk/module.h"
00042 #include "asterisk/app.h"
00043 
00044 /*** DOCUMENTATION
00045    <application name="SendText" language="en_US">
00046       <synopsis>
00047          Send a Text Message.
00048       </synopsis>
00049       <syntax>
00050          <parameter name="text" required="true" />
00051       </syntax>
00052       <description>
00053          <para>Sends <replaceable>text</replaceable> to current channel (callee).</para>
00054          <para>Result of transmission will be stored in the <variable>SENDTEXTSTATUS</variable></para>
00055          <variablelist>
00056             <variable name="SENDTEXTSTATUS">
00057                <value name="SUCCESS">
00058                   Transmission succeeded.
00059                </value>
00060                <value name="FAILURE">
00061                   Transmission failed.
00062                </value>
00063                <value name="UNSUPPORTED">
00064                   Text transmission not supported by channel.
00065                </value>
00066             </variable>
00067          </variablelist>
00068          <note><para>At this moment, text is supposed to be 7 bit ASCII in most channels.</para></note>
00069       </description>
00070       <see-also>
00071          <ref type="application">SendImage</ref>
00072          <ref type="application">SendURL</ref>
00073       </see-also>
00074    </application>
00075  ***/
00076 
00077 static const char * const app = "SendText";
00078 
00079 static int sendtext_exec(struct ast_channel *chan, const char *data)
00080 {
00081    char *status = "UNSUPPORTED";
00082    struct ast_str *str;
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    }
00090 
00091    if (!(str = ast_str_alloca(strlen(data) + 1))) {
00092       return -1;
00093    }
00094 
00095    ast_str_get_encoded_str(&str, -1, data);
00096 
00097    ast_channel_lock(chan);
00098    if (!ast_channel_tech(chan)->send_text) {
00099       ast_channel_unlock(chan);
00100       /* Does not support transport */
00101       pbx_builtin_setvar_helper(chan, "SENDTEXTSTATUS", status);
00102       return 0;
00103    }
00104    status = "FAILURE";
00105    if (!ast_sendtext(chan, ast_str_buffer(str))) {
00106       status = "SUCCESS";
00107    }
00108    ast_channel_unlock(chan);
00109    pbx_builtin_setvar_helper(chan, "SENDTEXTSTATUS", status);
00110    return 0;
00111 }
00112 
00113 static int unload_module(void)
00114 {
00115    return ast_unregister_application(app);
00116 }
00117 
00118 static int load_module(void)
00119 {
00120    return ast_register_application_xml(app, sendtext_exec);
00121 }
00122 
00123 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Send Text Applications");

Generated on Thu Apr 16 06:27:12 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6