Merge changes from team/group/appdocsxml
[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 #include "asterisk.h"
31
32 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
33
34 #include "asterisk/file.h"
35 #include "asterisk/channel.h"
36 #include "asterisk/pbx.h"
37 #include "asterisk/module.h"
38 #include "asterisk/app.h"
39
40 /*** DOCUMENTATION
41         <application name="SendText" language="en_US">
42                 <synopsis>
43                         Send a Text Message.
44                 </synopsis>
45                 <syntax>
46                         <parameter name="text" required="true" />
47                 </syntax>
48                 <description>
49                         <para>Sends <replaceable>text</replaceable> to current channel (callee).</para>
50                         <para>Result of transmission will be stored in the <variable>SENDTEXTSTATUS</variable></para>
51                         <variablelist>
52                                 <variable name="SENDTEXTSTATUS">
53                                         <value name="SUCCESS">
54                                                 Transmission succeeded.
55                                         </value>
56                                         <value name="FAILURE">
57                                                 Transmission failed.
58                                         </value>
59                                         <value name="UNSUPPORTED">
60                                                 Text transmission not supported by channel.
61                                         </value>
62                                 </variable>
63                         </variablelist>
64                         <note><para>At this moment, text is supposed to be 7 bit ASCII in most channels.</para></note>
65                 </description>
66         </application>
67  ***/
68
69 static const char *app = "SendText";
70
71 static int sendtext_exec(struct ast_channel *chan, void *data)
72 {
73         int res = 0;
74         char *status = "UNSUPPORTED";
75         char *parse = NULL;
76         AST_DECLARE_APP_ARGS(args,
77                 AST_APP_ARG(text);
78         );
79
80         if (ast_strlen_zero(data)) {
81                 ast_log(LOG_WARNING, "SendText requires an argument (text)\n");
82                 return -1;
83         } else
84                 parse = ast_strdupa(data);
85         
86         AST_STANDARD_APP_ARGS(args, parse);
87
88         ast_channel_lock(chan);
89         if (!chan->tech->send_text) {
90                 ast_channel_unlock(chan);
91                 /* Does not support transport */
92                 pbx_builtin_setvar_helper(chan, "SENDTEXTSTATUS", status);
93                 return 0;
94         }
95         status = "FAILURE";
96         ast_channel_unlock(chan);
97         res = ast_sendtext(chan, args.text);
98         if (!res)
99                 status = "SUCCESS";
100         pbx_builtin_setvar_helper(chan, "SENDTEXTSTATUS", status);
101         return 0;
102 }
103
104 static int unload_module(void)
105 {
106         return ast_unregister_application(app);
107 }
108
109 static int load_module(void)
110 {
111         return ast_register_application_xml(app, sendtext_exec);
112 }
113
114 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Send Text Applications");