Asterisk - The Open Source Telephony Project  GIT-master-a24979a
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 336 of file app_sendtext.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 336 of file app_sendtext.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module* AST_MODULE_SELF_SYM ( void  )

Definition at line 336 of file app_sendtext.c.

◆ load_module()

static int load_module ( void  )
static

Definition at line 326 of file app_sendtext.c.

327 {
328  int res;
329 
332 
333  return res;
334 }
static int sendtext_exec(struct ast_channel *chan, const char *data)
Definition: app_sendtext.c:194
static const char *const app
Definition: app_sendtext.c:191
static int recvtext_exec(struct ast_channel *chan, const char *data)
Definition: app_sendtext.c:285
static const char *const app2
Definition: app_sendtext.c:192
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
Definition: module.h:626

◆ recvtext_exec()

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

Definition at line 285 of file app_sendtext.c.

286 {
287  double timeout = 0, timeout_ms = 0;
288  char *parse, *buf;
289 
291  AST_APP_ARG(timeout);
292  );
293 
294  parse = ast_strdupa(data);
295 
297 
298  if (!ast_strlen_zero(args.timeout)) {
299  if (sscanf(args.timeout, "%30lg", &timeout) != 1) {
300  ast_log(LOG_WARNING, "Invalid timeout provided: %s. No timeout set.\n", args.timeout);
301  return -1;
302  }
303  timeout_ms = timeout * 1000.0;
304  }
305 
306  buf = ast_recvtext(chan, timeout_ms);
307  pbx_builtin_setvar_helper(chan, "RECEIVETEXTSTATUS", buf ? "SUCCESS" : "FAILURE");
308  if (buf) {
309  pbx_builtin_setvar_helper(chan, "RECEIVETEXTMESSAGE", buf);
310  ast_free(buf);
311  }
312 
313  return 0;
314 }
#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
static void parse(struct mgcp_request *req)
Definition: chan_mgcp.c:1844
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:4752
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, parse(), and pbx_builtin_setvar_helper().

◆ sendtext_exec()

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

Definition at line 194 of file app_sendtext.c.

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

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.

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 316 of file app_sendtext.c.

317 {
318  int res;
319 
322 
323  return res;
324 }
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 326 of file app_sendtext.c.

◆ app

const char* const app = "SendText"
static

Definition at line 191 of file app_sendtext.c.

Referenced by unload_module().

◆ app2

const char* const app2 = "ReceiveText"
static

Definition at line 192 of file app_sendtext.c.

Referenced by unload_module().

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 336 of file app_sendtext.c.