Asterisk - The Open Source Telephony Project GIT-master-8f1982c
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Modules Pages
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 334 of file app_sendtext.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 334 of file app_sendtext.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module * AST_MODULE_SELF_SYM ( void  )

Definition at line 334 of file app_sendtext.c.

◆ load_module()

static int load_module ( void  )
static

Definition at line 324 of file app_sendtext.c.

325{
326 int res;
327
330
331 return res;
332}
static int sendtext_exec(struct ast_channel *chan, const char *data)
Definition: app_sendtext.c:192
static const char *const app
Definition: app_sendtext.c:189
static int recvtext_exec(struct ast_channel *chan, const char *data)
Definition: app_sendtext.c:283
static const char *const app2
Definition: app_sendtext.c:190
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
Definition: module.h:640

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 283 of file app_sendtext.c.

284{
285 double timeout = 0, timeout_ms = 0;
286 char *parse, *buf;
287
289 AST_APP_ARG(timeout);
290 );
291
292 parse = ast_strdupa(data);
293
295
296 if (!ast_strlen_zero(args.timeout)) {
297 if (sscanf(args.timeout, "%30lg", &timeout) != 1) {
298 ast_log(LOG_WARNING, "Invalid timeout provided: %s. No timeout set.\n", args.timeout);
299 return -1;
300 }
301 timeout_ms = timeout * 1000.0;
302 }
303
304 buf = ast_recvtext(chan, timeout_ms);
305 pbx_builtin_setvar_helper(chan, "RECEIVETEXTSTATUS", buf ? "SUCCESS" : "FAILURE");
306 if (buf) {
307 pbx_builtin_setvar_helper(chan, "RECEIVETEXTMESSAGE", buf);
308 ast_free(buf);
309 }
310
311 return 0;
312}
#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:4676
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 192 of file app_sendtext.c.

193{
194 char *status;
195 char *msg_type;
196 struct ast_str *str;
197 const char *from;
198 const char *to;
199 const char *content_type;
200 const char *body;
201 int rc = 0;
202
203 ast_channel_lock(chan);
204 from = pbx_builtin_getvar_helper(chan, "SENDTEXT_FROM_DISPLAYNAME");
205 to = pbx_builtin_getvar_helper(chan, "SENDTEXT_TO_DISPLAYNAME");
206 content_type = pbx_builtin_getvar_helper(chan, "SENDTEXT_CONTENT_TYPE");
207 body = S_OR(pbx_builtin_getvar_helper(chan, "SENDTEXT_BODY"), data);
208 body = S_OR(body, "");
209
210 if (!(str = ast_str_alloca(strlen(body) + 1))) {
211 rc = -1;
212 goto cleanup;
213 }
214 ast_str_get_encoded_str(&str, -1, body);
215 body = ast_str_buffer(str);
216
217 msg_type = "NONE";
218 status = "UNSUPPORTED";
219 if (ast_channel_tech(chan)->send_text_data) {
220 struct ast_msg_data *msg;
221 struct ast_msg_data_attribute attrs[] =
222 {
223 {
225 .value = (char *)S_OR(from, ""),
226 },
227 {
228 .type = AST_MSG_DATA_ATTR_TO,
229 .value = (char *)S_OR(to, ""),
230 },
231 {
233 .value = (char *)S_OR(content_type, ""),
234 },
235 {
237 .value = (char *)S_OR(body, ""),
238 },
239 };
240
241 msg_type = "ENHANCED";
243 if (msg) {
244 if (ast_sendtext_data(chan, msg) == 0) {
245 status = "SUCCESS";
246 } else {
247 status = "FAILURE";
248 }
249
250 ast_free(msg);
251 } else {
252 rc = -1;
253 goto cleanup;
254 }
255
256 } else if (ast_channel_tech(chan)->send_text) {
257 if (!ast_strlen_zero(content_type) && !ast_begins_with(content_type, "text/")) {
258 rc = -1;
259 goto cleanup;
260 }
261
262 msg_type = "BASIC";
263 if (ast_sendtext(chan, body) == 0) {
264 status = "SUCCESS";
265 } else {
266 status = "FAILURE";
267 }
268 }
269
270 pbx_builtin_setvar_helper(chan, "SENDTEXTTYPE", msg_type);
271 pbx_builtin_setvar_helper(chan, "SENDTEXTSTATUS", status);
272
273cleanup:
274 pbx_builtin_setvar_helper(chan, "SENDTEXT_FROM_DISPLAYNAME", NULL);
275 pbx_builtin_setvar_helper(chan, "SENDTEXT_TO_DISPLAYNAME", NULL);
276 pbx_builtin_setvar_helper(chan, "SENDTEXT_CONTENT_TYPE", NULL);
277 pbx_builtin_setvar_helper(chan, "SENDTEXT_BODY", NULL);
278 ast_channel_unlock(chan);
279
280 return rc;
281}
jack_status_t status
Definition: app_jack.c:149
const char * str
Definition: app_jack.c:150
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:4710
#define ast_channel_lock(chan)
Definition: channel.h:2972
int ast_sendtext(struct ast_channel *chan, const char *text)
Sends text to a channel.
Definition: channel.c:4768
const struct ast_channel_tech * ast_channel_tech(const struct ast_channel *chan)
#define ast_channel_unlock(chan)
Definition: channel.h:2973
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:3175
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 314 of file app_sendtext.c.

315{
316 int res;
317
320
321 return res;
322}
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 334 of file app_sendtext.c.

◆ app

const char* const app = "SendText"
static

Definition at line 189 of file app_sendtext.c.

Referenced by load_module(), and unload_module().

◆ app2

const char* const app2 = "ReceiveText"
static

Definition at line 190 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 334 of file app_sendtext.c.