Asterisk - The Open Source Telephony Project GIT-master-a358458
Functions | Variables
app_sendtext.c File Reference

App to transmit a text message. More...

#include "asterisk.h"
#include "asterisk/file.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/module.h"
#include "asterisk/app.h"
#include "asterisk/message.h"
Include dependency graph for app_sendtext.c:

Go to the source code of this file.

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
static int load_module (void)
 
static int recvtext_exec (struct ast_channel *chan, const char *data)
 
static int sendtext_exec (struct ast_channel *chan, const char *data)
 
static int unload_module (void)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Send and Receive Text Applications" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, }
 
static const char *const app = "SendText"
 
static const char *const app2 = "ReceiveText"
 
static const struct ast_module_infoast_module_info = &__mod_info
 

Detailed Description

App to transmit a text message.

Author
Mark Spencer marks.nosp@m.ter@.nosp@m.digiu.nosp@m.m.co.nosp@m.m
Naveen Albert aster.nosp@m.isk@.nosp@m.phrea.nosp@m.knet.nosp@m..org
Note
Requires support of sending text messages from channel driver

Definition in file app_sendtext.c.

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 331 of file app_sendtext.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 331 of file app_sendtext.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module * AST_MODULE_SELF_SYM ( void  )

Definition at line 331 of file app_sendtext.c.

◆ load_module()

static int load_module ( void  )
static

Definition at line 321 of file app_sendtext.c.

322{
323 int res;
324
327
328 return res;
329}
static int sendtext_exec(struct ast_channel *chan, const char *data)
Definition: app_sendtext.c:189
static const char *const app
Definition: app_sendtext.c:186
static int recvtext_exec(struct ast_channel *chan, const char *data)
Definition: app_sendtext.c:280
static const char *const app2
Definition: app_sendtext.c:187
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
Definition: module.h:626

References app, app2, ast_register_application_xml, recvtext_exec(), and sendtext_exec().

◆ recvtext_exec()

static int recvtext_exec ( struct ast_channel chan,
const char *  data 
)
static

Definition at line 280 of file app_sendtext.c.

281{
282 double timeout = 0, timeout_ms = 0;
283 char *parse, *buf;
284
286 AST_APP_ARG(timeout);
287 );
288
289 parse = ast_strdupa(data);
290
292
293 if (!ast_strlen_zero(args.timeout)) {
294 if (sscanf(args.timeout, "%30lg", &timeout) != 1) {
295 ast_log(LOG_WARNING, "Invalid timeout provided: %s. No timeout set.\n", args.timeout);
296 return -1;
297 }
298 timeout_ms = timeout * 1000.0;
299 }
300
301 buf = ast_recvtext(chan, timeout_ms);
302 pbx_builtin_setvar_helper(chan, "RECEIVETEXTSTATUS", buf ? "SUCCESS" : "FAILURE");
303 if (buf) {
304 pbx_builtin_setvar_helper(chan, "RECEIVETEXTMESSAGE", buf);
305 ast_free(buf);
306 }
307
308 return 0;
309}
#define ast_free(a)
Definition: astmm.h:180
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:298
#define ast_log
Definition: astobj2.c:42
char * ast_recvtext(struct ast_channel *chan, int timeout)
Receives a text string from a channel Read a string of text from a channel.
Definition: channel.c:4717
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
#define AST_APP_ARG(name)
Define an application argument.
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application's arguments.
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the 'standard' argument separation process for an application.
#define LOG_WARNING
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.
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
const char * args

References args, AST_APP_ARG, AST_DECLARE_APP_ARGS, ast_free, ast_log, ast_recvtext(), AST_STANDARD_APP_ARGS, ast_strdupa, ast_strlen_zero(), buf, LOG_WARNING, and pbx_builtin_setvar_helper().

Referenced by load_module().

◆ sendtext_exec()

static int sendtext_exec ( struct ast_channel chan,
const char *  data 
)
static

Definition at line 189 of file app_sendtext.c.

190{
191 char *status;
192 char *msg_type;
193 struct ast_str *str;
194 const char *from;
195 const char *to;
196 const char *content_type;
197 const char *body;
198 int rc = 0;
199
200 ast_channel_lock(chan);
201 from = pbx_builtin_getvar_helper(chan, "SENDTEXT_FROM_DISPLAYNAME");
202 to = pbx_builtin_getvar_helper(chan, "SENDTEXT_TO_DISPLAYNAME");
203 content_type = pbx_builtin_getvar_helper(chan, "SENDTEXT_CONTENT_TYPE");
204 body = S_OR(pbx_builtin_getvar_helper(chan, "SENDTEXT_BODY"), data);
205 body = S_OR(body, "");
206
207 if (!(str = ast_str_alloca(strlen(body) + 1))) {
208 rc = -1;
209 goto cleanup;
210 }
211 ast_str_get_encoded_str(&str, -1, body);
212 body = ast_str_buffer(str);
213
214 msg_type = "NONE";
215 status = "UNSUPPORTED";
216 if (ast_channel_tech(chan)->send_text_data) {
217 struct ast_msg_data *msg;
218 struct ast_msg_data_attribute attrs[] =
219 {
220 {
222 .value = (char *)S_OR(from, ""),
223 },
224 {
225 .type = AST_MSG_DATA_ATTR_TO,
226 .value = (char *)S_OR(to, ""),
227 },
228 {
230 .value = (char *)S_OR(content_type, ""),
231 },
232 {
234 .value = (char *)S_OR(body, ""),
235 },
236 };
237
238 msg_type = "ENHANCED";
240 if (msg) {
241 if (ast_sendtext_data(chan, msg) == 0) {
242 status = "SUCCESS";
243 } else {
244 status = "FAILURE";
245 }
246
247 ast_free(msg);
248 } else {
249 rc = -1;
250 goto cleanup;
251 }
252
253 } else if (ast_channel_tech(chan)->send_text) {
254 if (!ast_strlen_zero(content_type) && !ast_begins_with(content_type, "text/")) {
255 rc = -1;
256 goto cleanup;
257 }
258
259 msg_type = "BASIC";
260 if (ast_sendtext(chan, body) == 0) {
261 status = "SUCCESS";
262 } else {
263 status = "FAILURE";
264 }
265 }
266
267 pbx_builtin_setvar_helper(chan, "SENDTEXTTYPE", msg_type);
268 pbx_builtin_setvar_helper(chan, "SENDTEXTSTATUS", status);
269
270cleanup:
271 pbx_builtin_setvar_helper(chan, "SENDTEXT_FROM_DISPLAYNAME", NULL);
272 pbx_builtin_setvar_helper(chan, "SENDTEXT_TO_DISPLAYNAME", NULL);
273 pbx_builtin_setvar_helper(chan, "SENDTEXT_CONTENT_TYPE", NULL);
274 pbx_builtin_setvar_helper(chan, "SENDTEXT_BODY", NULL);
275 ast_channel_unlock(chan);
276
277 return rc;
278}
jack_status_t status
Definition: app_jack.c:146
const char * str
Definition: app_jack.c:147
static void send_text(unsigned char pos, unsigned char inverse, struct unistimsession *pte, const char *text)
int ast_sendtext_data(struct ast_channel *chan, struct ast_msg_data *msg)
Sends text to a channel in an ast_msg_data structure wrapper with ast_sendtext as fallback.
Definition: channel.c:4751
#define ast_channel_lock(chan)
Definition: channel.h:2922
int ast_sendtext(struct ast_channel *chan, const char *text)
Sends text to a channel.
Definition: channel.c:4809
const struct ast_channel_tech * ast_channel_tech(const struct ast_channel *chan)
#define ast_channel_unlock(chan)
Definition: channel.h:2923
struct ast_msg_data * ast_msg_data_alloc(enum ast_msg_data_source_type source, struct ast_msg_data_attribute attributes[], size_t count)
Allocates an ast_msg_data structure.
@ AST_MSG_DATA_ATTR_BODY
Definition: message.h:458
@ AST_MSG_DATA_ATTR_TO
Definition: message.h:455
@ AST_MSG_DATA_ATTR_FROM
Definition: message.h:456
@ AST_MSG_DATA_ATTR_CONTENT_TYPE
Definition: message.h:457
@ AST_MSG_DATA_SOURCE_TYPE_IN_DIALOG
Definition: message.h:449
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: main/app.c:3165
const char * pbx_builtin_getvar_helper(struct ast_channel *chan, const char *name)
Return a pointer to the value of the corresponding channel variable.
static void * cleanup(void *unused)
Definition: pbx_realtime.c:124
#define NULL
Definition: resample.c:96
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:761
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one.
Definition: strings.h:80
#define ast_str_alloca(init_len)
Definition: strings.h:848
static int force_inline attribute_pure ast_begins_with(const char *str, const char *prefix)
Checks whether a string begins with another.
Definition: strings.h:97
enum ast_msg_data_attribute_type type
Definition: message.h:463
Structure used to transport a message through the frame core.
Support for dynamic strings.
Definition: strings.h:623
#define ARRAY_LEN(a)
Definition: utils.h:666

References ARRAY_LEN, ast_begins_with(), ast_channel_lock, ast_channel_tech(), ast_channel_unlock, ast_free, ast_msg_data_alloc(), AST_MSG_DATA_ATTR_BODY, AST_MSG_DATA_ATTR_CONTENT_TYPE, AST_MSG_DATA_ATTR_FROM, AST_MSG_DATA_ATTR_TO, AST_MSG_DATA_SOURCE_TYPE_IN_DIALOG, ast_sendtext(), ast_sendtext_data(), ast_str_alloca, ast_str_buffer(), ast_str_get_encoded_str(), ast_strlen_zero(), cleanup(), NULL, pbx_builtin_getvar_helper(), pbx_builtin_setvar_helper(), S_OR, send_text(), status, str, and ast_msg_data_attribute::type.

Referenced by load_module().

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 311 of file app_sendtext.c.

312{
313 int res;
314
317
318 return res;
319}
int ast_unregister_application(const char *app)
Unregister an application.
Definition: pbx_app.c:392

References app, app2, and ast_unregister_application().

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Send and Receive Text Applications" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, }
static

Definition at line 331 of file app_sendtext.c.

◆ app

const char* const app = "SendText"
static

Definition at line 186 of file app_sendtext.c.

Referenced by load_module(), and unload_module().

◆ app2

const char* const app2 = "ReceiveText"
static

Definition at line 187 of file app_sendtext.c.

Referenced by load_module(), and unload_module().

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 331 of file app_sendtext.c.