Asterisk - The Open Source Telephony Project  18.5.0
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 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 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 = "30ef0c93b36035ec78c9cfd712d36d9b" , .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 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
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 250 of file app_sendtext.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 250 of file app_sendtext.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module* AST_MODULE_SELF_SYM ( void  )

Definition at line 250 of file app_sendtext.c.

◆ load_module()

static int load_module ( void  )
static

Definition at line 245 of file app_sendtext.c.

References app, ast_register_application_xml, and sendtext_exec().

246 {
248 }
static int sendtext_exec(struct ast_channel *chan, const char *data)
Definition: app_sendtext.c:149
static const char *const app
Definition: app_sendtext.c:147
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
Definition: module.h:626

◆ sendtext_exec()

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

Definition at line 149 of file app_sendtext.c.

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().

150 {
151  char *status;
152  char *msg_type;
153  struct ast_str *str;
154  const char *from;
155  const char *to;
156  const char *content_type;
157  const char *body;
158  int rc = 0;
159 
160  ast_channel_lock(chan);
161  from = pbx_builtin_getvar_helper(chan, "SENDTEXT_FROM_DISPLAYNAME");
162  to = pbx_builtin_getvar_helper(chan, "SENDTEXT_TO_DISPLAYNAME");
163  content_type = pbx_builtin_getvar_helper(chan, "SENDTEXT_CONTENT_TYPE");
164  body = S_OR(pbx_builtin_getvar_helper(chan, "SENDTEXT_BODY"), data);
165  body = S_OR(body, "");
166 
167  if (!(str = ast_str_alloca(strlen(body) + 1))) {
168  rc = -1;
169  goto cleanup;
170  }
171  ast_str_get_encoded_str(&str, -1, body);
172  body = ast_str_buffer(str);
173 
174  msg_type = "NONE";
175  status = "UNSUPPORTED";
176  if (ast_channel_tech(chan)->send_text_data) {
177  struct ast_msg_data *msg;
178  struct ast_msg_data_attribute attrs[] =
179  {
180  {
182  .value = (char *)S_OR(from, ""),
183  },
184  {
185  .type = AST_MSG_DATA_ATTR_TO,
186  .value = (char *)S_OR(to, ""),
187  },
188  {
190  .value = (char *)S_OR(content_type, ""),
191  },
192  {
193  .type = AST_MSG_DATA_ATTR_BODY,
194  .value = (char *)S_OR(body, ""),
195  },
196  };
197 
198  msg_type = "ENHANCED";
200  if (msg) {
201  if (ast_sendtext_data(chan, msg) == 0) {
202  status = "SUCCESS";
203  } else {
204  status = "FAILURE";
205  }
206 
207  ast_free(msg);
208  } else {
209  rc = -1;
210  goto cleanup;
211  }
212 
213  } else if (ast_channel_tech(chan)->send_text) {
214  if (!ast_strlen_zero(content_type) && !ast_begins_with(content_type, "text/")) {
215  rc = -1;
216  goto cleanup;
217  }
218 
219  msg_type = "BASIC";
220  if (ast_sendtext(chan, body) == 0) {
221  status = "SUCCESS";
222  } else {
223  status = "FAILURE";
224  }
225  }
226 
227  pbx_builtin_setvar_helper(chan, "SENDTEXTTYPE", msg_type);
228  pbx_builtin_setvar_helper(chan, "SENDTEXTSTATUS", status);
229 
230 cleanup:
231  pbx_builtin_setvar_helper(chan, "SENDTEXT_FROM_DISPLAYNAME", NULL);
232  pbx_builtin_setvar_helper(chan, "SENDTEXT_TO_DISPLAYNAME", NULL);
233  pbx_builtin_setvar_helper(chan, "SENDTEXT_CONTENT_TYPE", NULL);
234  pbx_builtin_setvar_helper(chan, "SENDTEXT_BODY", NULL);
235  ast_channel_unlock(chan);
236 
237  return rc;
238 }
#define ast_channel_lock(chan)
Definition: channel.h:2945
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
enum ast_msg_data_attribute_type type
Definition: message.h:463
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:714
Structure used to transport a message through the frame core.
Definition: message.c:1406
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.
Definition: message.c:1418
#define ast_str_alloca(init_len)
Definition: strings.h:800
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:4796
const char * str
Definition: app_jack.c:147
#define NULL
Definition: resample.c:96
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:3015
const char * pbx_builtin_getvar_helper(struct ast_channel *chan, const char *name)
Return a pointer to the value of the corresponding channel variable.
#define ast_strlen_zero(foo)
Definition: strings.h:52
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584
#define ast_channel_unlock(chan)
Definition: channel.h:2946
#define ast_free(a)
Definition: astmm.h:182
static void * cleanup(void *unused)
Definition: pbx_realtime.c:124
static void send_text(unsigned char pos, unsigned char inverse, struct unistimsession *pte, const char *text)
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...
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one...
Definition: strings.h:79
static int force_inline attribute_pure ast_begins_with(const char *str, const char *prefix)
Definition: strings.h:94
const struct ast_channel_tech * ast_channel_tech(const struct ast_channel *chan)
jack_status_t status
Definition: app_jack.c:146
int ast_sendtext(struct ast_channel *chan, const char *text)
Sends text to a channel.
Definition: channel.c:4854

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 240 of file app_sendtext.c.

References app, and ast_unregister_application().

241 {
243 }
int ast_unregister_application(const char *app)
Unregister an application.
Definition: pbx_app.c:392
static const char *const app
Definition: app_sendtext.c:147

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Send 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 = "30ef0c93b36035ec78c9cfd712d36d9b" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, }
static

Definition at line 250 of file app_sendtext.c.

◆ app

const char* const app = "SendText"
static

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