Merge "BuildSystem: Resolve resolv.h not via Generic but Particular Header-Check."
[asterisk/asterisk.git] / apps / app_sendtext.c
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 1999 - 2005, Digium, Inc.
5  *
6  * Mark Spencer <markster@digium.com>
7  *
8  * See http://www.asterisk.org for more information about
9  * the Asterisk project. Please do not directly contact
10  * any of the maintainers of this project for assistance;
11  * the project provides a web site, mailing lists and IRC
12  * channels for your use.
13  *
14  * This program is free software, distributed under the terms of
15  * the GNU General Public License Version 2. See the LICENSE file
16  * at the top of the source tree.
17  */
18
19 /*! \file
20  *
21  * \brief App to transmit a text message
22  *
23  * \author Mark Spencer <markster@digium.com>
24  *
25  * \note Requires support of sending text messages from channel driver
26  *
27  * \ingroup applications
28  */
29
30 /*** MODULEINFO
31         <support_level>core</support_level>
32  ***/
33
34 #include "asterisk.h"
35
36 #include "asterisk/file.h"
37 #include "asterisk/channel.h"
38 #include "asterisk/pbx.h"
39 #include "asterisk/module.h"
40 #include "asterisk/app.h"
41
42 /*** DOCUMENTATION
43         <application name="SendText" language="en_US">
44                 <synopsis>
45                         Send a Text Message.
46                 </synopsis>
47                 <syntax>
48                         <parameter name="text" required="true" />
49                 </syntax>
50                 <description>
51                         <para>Sends <replaceable>text</replaceable> to current channel (callee).</para>
52                         <para>Result of transmission will be stored in the <variable>SENDTEXTSTATUS</variable></para>
53                         <variablelist>
54                                 <variable name="SENDTEXTSTATUS">
55                                         <value name="SUCCESS">
56                                                 Transmission succeeded.
57                                         </value>
58                                         <value name="FAILURE">
59                                                 Transmission failed.
60                                         </value>
61                                         <value name="UNSUPPORTED">
62                                                 Text transmission not supported by channel.
63                                         </value>
64                                 </variable>
65                         </variablelist>
66                         <note><para>At this moment, text is supposed to be 7 bit ASCII in most channels.</para></note>
67                 </description>
68                 <see-also>
69                         <ref type="application">SendImage</ref>
70                         <ref type="application">SendURL</ref>
71                 </see-also>
72         </application>
73  ***/
74
75 static const char * const app = "SendText";
76
77 static int sendtext_exec(struct ast_channel *chan, const char *data)
78 {
79         char *status = "UNSUPPORTED";
80         struct ast_str *str;
81
82         /* NOT ast_strlen_zero, because some protocols (e.g. SIP) MUST be able to
83          * send a zero-length message. */
84         if (!data) {
85                 ast_log(LOG_WARNING, "SendText requires an argument (text)\n");
86                 return -1;
87         }
88
89         if (!(str = ast_str_alloca(strlen(data) + 1))) {
90                 return -1;
91         }
92
93         ast_str_get_encoded_str(&str, -1, data);
94
95         ast_channel_lock(chan);
96         if (!ast_channel_tech(chan)->send_text) {
97                 ast_channel_unlock(chan);
98                 /* Does not support transport */
99                 pbx_builtin_setvar_helper(chan, "SENDTEXTSTATUS", status);
100                 return 0;
101         }
102         status = "FAILURE";
103         if (!ast_sendtext(chan, ast_str_buffer(str))) {
104                 status = "SUCCESS";
105         }
106         ast_channel_unlock(chan);
107         pbx_builtin_setvar_helper(chan, "SENDTEXTSTATUS", status);
108         return 0;
109 }
110
111 static int unload_module(void)
112 {
113         return ast_unregister_application(app);
114 }
115
116 static int load_module(void)
117 {
118         return ast_register_application_xml(app, sendtext_exec);
119 }
120
121 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Send Text Applications");