Wed Jan 8 2020 09:49:40

Asterisk developer's documentation


app_sendtext.c
Go to the documentation of this file.
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 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 328209 $")
37 
38 #include "asterisk/file.h"
39 #include "asterisk/channel.h"
40 #include "asterisk/pbx.h"
41 #include "asterisk/module.h"
42 #include "asterisk/app.h"
43 
44 /*** DOCUMENTATION
45  <application name="SendText" language="en_US">
46  <synopsis>
47  Send a Text Message.
48  </synopsis>
49  <syntax>
50  <parameter name="text" required="true" />
51  </syntax>
52  <description>
53  <para>Sends <replaceable>text</replaceable> to current channel (callee).</para>
54  <para>Result of transmission will be stored in the <variable>SENDTEXTSTATUS</variable></para>
55  <variablelist>
56  <variable name="SENDTEXTSTATUS">
57  <value name="SUCCESS">
58  Transmission succeeded.
59  </value>
60  <value name="FAILURE">
61  Transmission failed.
62  </value>
63  <value name="UNSUPPORTED">
64  Text transmission not supported by channel.
65  </value>
66  </variable>
67  </variablelist>
68  <note><para>At this moment, text is supposed to be 7 bit ASCII in most channels.</para></note>
69  </description>
70  <see-also>
71  <ref type="application">SendImage</ref>
72  <ref type="application">SendURL</ref>
73  </see-also>
74  </application>
75  ***/
76 
77 static const char * const app = "SendText";
78 
79 static int sendtext_exec(struct ast_channel *chan, const char *data)
80 {
81  char *status = "UNSUPPORTED";
82  struct ast_str *str;
83 
84  /* NOT ast_strlen_zero, because some protocols (e.g. SIP) MUST be able to
85  * send a zero-length message. */
86  if (!data) {
87  ast_log(LOG_WARNING, "SendText requires an argument (text)\n");
88  return -1;
89  }
90 
91  if (!(str = ast_str_alloca(strlen(data) + 1))) {
92  return -1;
93  }
94 
95  ast_str_get_encoded_str(&str, -1, data);
96 
97  ast_channel_lock(chan);
98  if (!chan->tech->send_text) {
99  ast_channel_unlock(chan);
100  /* Does not support transport */
101  pbx_builtin_setvar_helper(chan, "SENDTEXTSTATUS", status);
102  return 0;
103  }
104  status = "FAILURE";
105  if (!ast_sendtext(chan, ast_str_buffer(str))) {
106  status = "SUCCESS";
107  }
108  ast_channel_unlock(chan);
109  pbx_builtin_setvar_helper(chan, "SENDTEXTSTATUS", status);
110  return 0;
111 }
112 
113 static int unload_module(void)
114 {
115  return ast_unregister_application(app);
116 }
117 
118 static int load_module(void)
119 {
121 }
122 
123 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Send Text Applications");
#define ast_channel_lock(chan)
Definition: channel.h:2466
Main Channel structure associated with a channel.
Definition: channel.h:742
#define AST_MODULE_INFO_STANDARD(keystr, desc)
Definition: module.h:396
Asterisk main include file. File version handling, generic pbx functions.
static int sendtext_exec(struct ast_channel *chan, const char *data)
Definition: app_sendtext.c:79
#define LOG_WARNING
Definition: logger.h:144
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:497
int ast_str_get_encoded_str(struct ast_str **str, int maxlen, const char *stream)
Decode a stream of encoded control or extended ASCII characters.
Definition: app.c:2210
#define ast_str_alloca(init_len)
Definition: strings.h:608
const char * str
Definition: app_jack.c:144
const char * data
Definition: channel.h:755
int ast_unregister_application(const char *app)
Unregister an application.
Definition: pbx.c:7705
General Asterisk PBX channel definitions.
static int load_module(void)
Definition: app_sendtext.c:118
Core PBX routines and definitions.
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:364
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
#define ast_channel_unlock(chan)
Definition: channel.h:2467
int(*const send_text)(struct ast_channel *chan, const char *text)
Display or transmit text.
Definition: channel.h:557
int pbx_builtin_setvar_helper(struct ast_channel *chan, const char *name, const char *value)
Add a variable to the channel variable stack, removing the most recently set value for the same name...
Definition: pbx.c:10546
Application convenience functions, designed to give consistent look and feel to Asterisk apps...
static const char *const app
Definition: app_sendtext.c:77
static int unload_module(void)
Definition: app_sendtext.c:113
#define ASTERISK_GPL_KEY
The text the key() function should return.
Definition: module.h:38
Asterisk module definitions.
struct ast_channel_tech * tech
Definition: channel.h:743
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
Definition: module.h:437
jack_status_t status
Definition: app_jack.c:143
#define ASTERISK_FILE_VERSION(file, version)
Register/unregister a source code file with the core.
Definition: asterisk.h:180
int ast_sendtext(struct ast_channel *chan, const char *text)
Sends text to a channel.
Definition: channel.c:4687