Asterisk - The Open Source Telephony Project  18.5.0
Data Structures | Enumerations | Functions
message.h File Reference

Out-of-call text message support. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ast_msg_data_attribute
 
struct  ast_msg_handler
 An external processor of received messages. More...
 
struct  ast_msg_tech
 A message technology. More...
 

Enumerations

enum  ast_msg_data_attribute_type {
  AST_MSG_DATA_ATTR_TO = 0, AST_MSG_DATA_ATTR_FROM, AST_MSG_DATA_ATTR_CONTENT_TYPE, AST_MSG_DATA_ATTR_BODY,
  __AST_MSG_DATA_ATTR_LAST
}
 
enum  ast_msg_data_source_type {
  AST_MSG_DATA_SOURCE_TYPE_UNKNOWN = 0, AST_MSG_DATA_SOURCE_TYPE_T140, AST_MSG_DATA_SOURCE_TYPE_IN_DIALOG, AST_MSG_DATA_SOURCE_TYPE_OUT_OF_DIALOG,
  __AST_MSG_DATA_SOURCE_TYPE_LAST
}
 

Functions

struct ast_msgast_msg_alloc (void)
 Allocate a message. More...
 
struct ast_msg_dataast_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. More...
 
struct ast_msg_dataast_msg_data_alloc2 (enum ast_msg_data_source_type source_type, const char *to, const char *from, const char *content_type, const char *body)
 Allocates an ast_msg_data structure. More...
 
struct ast_msg_dataast_msg_data_dup (struct ast_msg_data *msg)
 Clone an ast_msg_data structure. More...
 
const char * ast_msg_data_get_attribute (struct ast_msg_data *msg, enum ast_msg_data_attribute_type attribute_type)
 Get attribute from ast_msg_data. More...
 
size_t ast_msg_data_get_length (struct ast_msg_data *msg)
 Get length of the structure. More...
 
enum ast_msg_data_source_type ast_msg_data_get_source_type (struct ast_msg_data *msg)
 Get "source type" from ast_msg_data. More...
 
int ast_msg_data_queue_frame (struct ast_channel *channel, struct ast_msg_data *msg)
 Queue an AST_FRAME_TEXT_DATA frame containing an ast_msg_data structure. More...
 
struct ast_msgast_msg_destroy (struct ast_msg *msg)
 Destroy an ast_msg. More...
 
const char * ast_msg_get_body (const struct ast_msg *msg)
 Get the body of a message. More...
 
const char * ast_msg_get_endpoint (const struct ast_msg *msg)
 Retrieve the endpoint associated with this message. More...
 
const char * ast_msg_get_from (const struct ast_msg *msg)
 Retrieve the source of this message. More...
 
const char * ast_msg_get_tech (const struct ast_msg *msg)
 Retrieve the technology associated with this message. More...
 
const char * ast_msg_get_to (const struct ast_msg *msg)
 Retrieve the destination of this message. More...
 
const char * ast_msg_get_var (struct ast_msg *msg, const char *name)
 Get the specified variable on the message. More...
 
int ast_msg_handler_register (const struct ast_msg_handler *handler)
 Register a ast_msg_handler. More...
 
int ast_msg_handler_unregister (const struct ast_msg_handler *handler)
 Unregister a ast_msg_handler. More...
 
int ast_msg_has_destination (const struct ast_msg *msg)
 Determine if a particular message has a destination via some handler. More...
 
int ast_msg_queue (struct ast_msg *msg)
 Queue a message for routing through the dialplan. More...
 
struct ast_msgast_msg_ref (struct ast_msg *msg)
 Bump a msg's ref count. More...
 
int ast_msg_send (struct ast_msg *msg, const char *to, const char *from)
 Send a msg directly to an endpoint. More...
 
int ast_msg_set_body (struct ast_msg *msg, const char *fmt,...)
 Set the 'body' text of a message (in UTF-8) More...
 
int ast_msg_set_context (struct ast_msg *msg, const char *fmt,...)
 Set the dialplan context for this message. More...
 
int ast_msg_set_endpoint (struct ast_msg *msg, const char *fmt,...)
 Set the technology's endpoint associated with this message. More...
 
int ast_msg_set_exten (struct ast_msg *msg, const char *fmt,...)
 Set the dialplan extension for this message. More...
 
int ast_msg_set_from (struct ast_msg *msg, const char *fmt,...)
 Set the 'from' URI of a message. More...
 
int ast_msg_set_tech (struct ast_msg *msg, const char *fmt,...)
 Set the technology associated with this message. More...
 
int ast_msg_set_to (struct ast_msg *msg, const char *fmt,...)
 Set the 'to' URI of a message. More...
 
int ast_msg_set_var (struct ast_msg *msg, const char *name, const char *value)
 Set a variable on the message going to the dialplan. More...
 
int ast_msg_set_var_outbound (struct ast_msg *msg, const char *name, const char *value)
 Set a variable on the message being sent to a message tech directly. More...
 
int ast_msg_tech_register (const struct ast_msg_tech *tech)
 Register a message technology. More...
 
int ast_msg_tech_unregister (const struct ast_msg_tech *tech)
 Unregister a message technology. More...
 
void ast_msg_var_iterator_destroy (struct ast_msg_var_iterator *iter)
 Destroy a message variable iterator. More...
 
struct ast_msg_var_iteratorast_msg_var_iterator_init (const struct ast_msg *msg)
 Create a new message variable iterator. More...
 
int ast_msg_var_iterator_next (const struct ast_msg *msg, struct ast_msg_var_iterator *iter, const char **name, const char **value)
 Get the next variable name and value that is set for sending outbound. More...
 
int ast_msg_var_iterator_next_received (const struct ast_msg *msg, struct ast_msg_var_iterator *iter, const char **name, const char **value)
 Get the next variable name and value that was set on a received message. More...
 
void ast_msg_var_unref_current (struct ast_msg_var_iterator *iter)
 Unref a message var from inside an iterator loop. More...
 

Detailed Description

Out-of-call text message support.

Author
Russell Bryant russe.nosp@m.ll@d.nosp@m.igium.nosp@m..com

The purpose of this API is to provide support for text messages that are not session based. The messages are passed into the Asterisk core to be routed through the dialplan or another interface and potentially sent back out through a message technology that has been registered through this API.

Definition in file message.h.

Function Documentation

◆ ast_msg_alloc()

struct ast_msg* ast_msg_alloc ( void  )

Allocate a message.

Allocate a message for the purposes of passing it into the Asterisk core to be routed through the dialplan. If ast_msg_queue() is not called, this message must be destroyed using ast_msg_destroy(). Otherwise, the message core code will take care of it.

Returns
A message object. This function will return NULL if an allocation error occurs.

Definition at line 418 of file message.c.

References ao2_alloc, AO2_ALLOC_OPT_LOCK_MUTEX, ao2_container_alloc_list, ao2_ref, ast_string_field_init, ast_string_field_set, context, msg_data::msg, msg_data_cmp_fn(), msg_destructor(), NULL, and ast_msg::vars.

Referenced by action_messagesend(), AST_TEST_DEFINE(), module_on_rx_request(), msg_datastore_find_or_create(), receive_message(), send_message(), and xmpp_pak_message().

419 {
420  struct ast_msg *msg;
421 
422  if (!(msg = ao2_alloc(sizeof(*msg), msg_destructor))) {
423  return NULL;
424  }
425 
426  if (ast_string_field_init(msg, 128)) {
427  ao2_ref(msg, -1);
428  return NULL;
429  }
430 
433  if (!msg->vars) {
434  ao2_ref(msg, -1);
435  return NULL;
436  }
437  ast_string_field_set(msg, context, "default");
438 
439  return msg;
440 }
static int msg_data_cmp_fn(void *obj, void *arg, int flags)
Definition: message.c:398
#define ao2_container_alloc_list(ao2_options, container_options, sort_fn, cmp_fn)
Definition: astobj2.h:1335
#define NULL
Definition: resample.c:96
static void msg_destructor(void *obj)
Definition: message.c:410
struct ao2_container * vars
Definition: message.c:251
#define ast_string_field_init(x, size)
Initialize a field pool and fields.
Definition: stringfields.h:353
#define ao2_ref(o, delta)
Definition: astobj2.h:464
#define ao2_alloc(data_size, destructor_fn)
Definition: astobj2.h:411
A message.
Definition: message.c:233
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:116
#define ast_string_field_set(x, field, data)
Set a field to a simple string value.
Definition: stringfields.h:514

◆ ast_msg_destroy()

struct ast_msg* ast_msg_destroy ( struct ast_msg msg)

Destroy an ast_msg.

This should only be called on a message if it was not passed on to ast_msg_queue().

Returns
NULL, always.

Definition at line 448 of file message.c.

References ao2_ref, and NULL.

Referenced by ast_msg_safe_destroy(), module_on_rx_request(), msg_data_destroy(), receive_message(), send_message(), and xmpp_pak_message().

449 {
450  ao2_ref(msg, -1);
451  return NULL;
452 }
#define NULL
Definition: resample.c:96
#define ao2_ref(o, delta)
Definition: astobj2.h:464

◆ ast_msg_get_body()

const char* ast_msg_get_body ( const struct ast_msg msg)

Get the body of a message.

Note
The return value is valid only as long as the ast_message is valid. Hold a reference to the message if you plan on storing the return value.
Returns
The body of the messsage, encoded in UTF-8.

Definition at line 531 of file message.c.

References ast_msg::body.

Referenced by AST_TEST_DEFINE(), msg_send(), msg_to_json(), sip_msg_send(), and xmpp_send_cb().

532 {
533  return msg->body;
534 }
const ast_string_field body
Definition: message.c:249

◆ ast_msg_get_endpoint()

const char* ast_msg_get_endpoint ( const struct ast_msg msg)

Retrieve the endpoint associated with this message.

Since
12.5.0
Parameters
msgThe message to get the endpoint from
Return values
Theendpoint associated with the message
NULLor empty string if the message has no associated endpoint

Definition at line 551 of file message.c.

References ast_msg::endpoint.

Referenced by AST_TEST_DEFINE(), and msg_to_endpoint().

552 {
553  return msg->endpoint;
554 }
const ast_string_field endpoint
Definition: message.c:249

◆ ast_msg_get_from()

const char* ast_msg_get_from ( const struct ast_msg msg)

Retrieve the source of this message.

Since
12.5.0
Parameters
msgThe message to get the soure from
Return values
Thesource of the message
NULLor empty string if the message has no source

Definition at line 536 of file message.c.

References ast_msg::from.

Referenced by AST_TEST_DEFINE(), msg_send(), and msg_to_json().

537 {
538  return msg->from;
539 }
const ast_string_field from
Definition: message.c:249

◆ ast_msg_get_tech()

const char* ast_msg_get_tech ( const struct ast_msg msg)

Retrieve the technology associated with this message.

Since
12.5.0
Parameters
msgThe message to get the technology from
Return values
Thetechnology of the message
NULLor empty string if the message has no associated technology

Definition at line 546 of file message.c.

References ast_msg::tech.

Referenced by AST_TEST_DEFINE(), and msg_to_endpoint().

547 {
548  return msg->tech;
549 }
const ast_string_field tech
Definition: message.c:249

◆ ast_msg_get_to()

const char* ast_msg_get_to ( const struct ast_msg msg)

Retrieve the destination of this message.

Since
12.5.0
Parameters
msgThe message to get the destination from
Return values
Thedestination of the message
NULLor empty string if the message has no destination

Definition at line 541 of file message.c.

References ast_msg::to.

Referenced by AST_TEST_DEFINE(), msg_send(), msg_to_json(), and test_msg_has_destination_cb().

542 {
543  return msg->to;
544 }
const ast_string_field to
Definition: message.c:249

◆ ast_msg_get_var()

const char* ast_msg_get_var ( struct ast_msg msg,
const char *  name 
)

Get the specified variable on the message.

Note
The return value is valid only as long as the ast_message is valid. Hold a reference to the message if you plan on storing the return value. Do re-set the same message var name while holding a pointer to the result of this function.
Returns
The value associated with variable "name". NULL if variable not found.

Definition at line 620 of file message.c.

References ao2_ref, msg_data_find(), NULL, msg_data::value, and ast_msg::vars.

Referenced by AST_TEST_DEFINE(), msg_data_func_read(), and update_content_type().

621 {
622  struct msg_data *data;
623  const char *val = NULL;
624 
625  if (!(data = msg_data_find(msg->vars, name))) {
626  return NULL;
627  }
628 
629  /* Yep, this definitely looks like val would be a dangling pointer
630  * after the ref count is decremented. As long as the message structure
631  * is used in a thread safe manner, this will not be the case though.
632  * The ast_msg holds a reference to this object in the msg->vars container. */
633  val = data->value;
634  ao2_ref(data, -1);
635 
636  return val;
637 }
Definition: ast_expr2.c:325
#define NULL
Definition: resample.c:96
struct ao2_container * vars
Definition: message.c:251
static struct msg_data * msg_data_find(struct ao2_container *vars, const char *name)
Definition: message.c:572
#define ao2_ref(o, delta)
Definition: astobj2.h:464
static const char name[]
Definition: cdr_mysql.c:74
const ast_string_field value
Definition: message.c:224

◆ ast_msg_handler_register()

int ast_msg_handler_register ( const struct ast_msg_handler handler)

Register a ast_msg_handler.

Since
12.5.0
Parameters
handlerThe handler to register
Return values
0Success
non-zeroError

Definition at line 1629 of file message.c.

References ast_log, ast_rwlock_unlock, ast_rwlock_wrlock, AST_VECTOR_APPEND, ast_verb, LOG_ERROR, match(), msg_handler_find_by_tech_name(), and ast_msg_handler::name.

Referenced by ast_msg_init(), AST_TEST_DEFINE(), and messaging_init().

1630 {
1631  const struct ast_msg_handler *match;
1632 
1633  ast_rwlock_wrlock(&msg_handlers_lock);
1634 
1635  match = msg_handler_find_by_tech_name(handler->name);
1636  if (match) {
1637  ast_log(LOG_ERROR, "Message handler already registered for '%s'\n",
1638  handler->name);
1639  ast_rwlock_unlock(&msg_handlers_lock);
1640  return -1;
1641  }
1642 
1643  if (AST_VECTOR_APPEND(&msg_handlers, handler)) {
1644  ast_log(LOG_ERROR, "Failed to register message handler for '%s'\n",
1645  handler->name);
1646  ast_rwlock_unlock(&msg_handlers_lock);
1647  return -1;
1648  }
1649  ast_verb(2, "Message handler '%s' registered.\n", handler->name);
1650 
1651  ast_rwlock_unlock(&msg_handlers_lock);
1652 
1653  return 0;
1654 
1655 }
An external processor of received messages.
Definition: message.h:98
#define AST_VECTOR_APPEND(vec, elem)
Append an element to a vector, growing the vector if needed.
Definition: vector.h:256
static int match(struct ast_sockaddr *addr, unsigned short callno, unsigned short dcallno, const struct chan_iax2_pvt *cur, int check_dcallno)
Definition: chan_iax2.c:2315
#define ast_rwlock_unlock(a)
Definition: lock.h:232
#define ast_verb(level,...)
Definition: logger.h:463
#define ast_log
Definition: astobj2.c:42
#define LOG_ERROR
Definition: logger.h:285
const char * name
Name of the message handler.
Definition: message.h:102
#define ast_rwlock_wrlock(a)
Definition: lock.h:234
static const struct ast_msg_handler * msg_handler_find_by_tech_name(const char *tech_name)
Definition: message.c:1207

◆ ast_msg_handler_unregister()

int ast_msg_handler_unregister ( const struct ast_msg_handler handler)

Unregister a ast_msg_handler.

Since
12.5.0
Parameters
handlerThe handler to unregister
Return values
0Success
non-zeroError

Definition at line 1671 of file message.c.

References ast_log, ast_rwlock_unlock, ast_rwlock_wrlock, AST_VECTOR_ELEM_CLEANUP_NOOP, AST_VECTOR_REMOVE_CMP_UNORDERED, ast_verb, LOG_ERROR, match(), msg_handler_cmp(), and ast_msg_handler::name.

Referenced by AST_TEST_DEFINE(), message_shutdown(), and messaging_cleanup().

1672 {
1673  int match;
1674 
1675  ast_rwlock_wrlock(&msg_handlers_lock);
1676  match = AST_VECTOR_REMOVE_CMP_UNORDERED(&msg_handlers, handler, msg_handler_cmp,
1678  ast_rwlock_unlock(&msg_handlers_lock);
1679 
1680  if (match) {
1681  ast_log(LOG_ERROR, "No '%s' message handler found.\n", handler->name);
1682  return -1;
1683  }
1684 
1685  ast_verb(3, "Message handler '%s' unregistered.\n", handler->name);
1686  return 0;
1687 }
#define AST_VECTOR_REMOVE_CMP_UNORDERED(vec, value, cmp, cleanup)
Remove an element from a vector that matches the given comparison.
Definition: vector.h:488
static int match(struct ast_sockaddr *addr, unsigned short callno, unsigned short dcallno, const struct chan_iax2_pvt *cur, int check_dcallno)
Definition: chan_iax2.c:2315
#define ast_rwlock_unlock(a)
Definition: lock.h:232
#define ast_verb(level,...)
Definition: logger.h:463
#define ast_log
Definition: astobj2.c:42
#define AST_VECTOR_ELEM_CLEANUP_NOOP(elem)
Vector element cleanup that does nothing.
Definition: vector.h:573
#define LOG_ERROR
Definition: logger.h:285
static int msg_handler_cmp(const struct ast_msg_handler *vec_elem, const struct ast_msg_handler *srch)
Comparison callback for ast_msg_handler vector removal.
Definition: message.c:1666
const char * name
Name of the message handler.
Definition: message.h:102
#define ast_rwlock_wrlock(a)
Definition: lock.h:234

◆ ast_msg_has_destination()

int ast_msg_has_destination ( const struct ast_msg msg)

Determine if a particular message has a destination via some handler.

Since
12.5.0
Parameters
msgThe message to check
Return values
0if the message has no handler that can find a destination
1if the message has a handler that can find a destination

Definition at line 937 of file message.c.

References ast_debug, ast_rwlock_rdlock, ast_rwlock_unlock, AST_VECTOR_GET, AST_VECTOR_SIZE, handler(), ast_msg_handler::has_destination, ast_msg_handler::name, and result.

Referenced by AST_TEST_DEFINE(), module_on_rx_request(), and receive_message().

938 {
939  int i;
940  int result = 0;
941 
942  ast_rwlock_rdlock(&msg_handlers_lock);
943  for (i = 0; i < AST_VECTOR_SIZE(&msg_handlers); i++) {
944  const struct ast_msg_handler *handler = AST_VECTOR_GET(&msg_handlers, i);
945 
946  ast_debug(5, "Seeing if %s can handle message\n", handler->name);
947  if (handler->has_destination(msg)) {
948  ast_debug(5, "%s can handle message\n", handler->name);
949  result = 1;
950  break;
951  }
952  }
953  ast_rwlock_unlock(&msg_handlers_lock);
954 
955  return result;
956 }
#define ast_rwlock_rdlock(a)
Definition: lock.h:233
An external processor of received messages.
Definition: message.h:98
int(*const has_destination)(const struct ast_msg *msg)
Return whether or not the message has a valid destination.
Definition: message.h:127
#define ast_rwlock_unlock(a)
Definition: lock.h:232
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:452
const char * name
Name of the message handler.
Definition: message.h:102
#define AST_VECTOR_GET(vec, idx)
Get an element from a vector.
Definition: vector.h:682
static void handler(const char *name, int response_code, struct ast_variable *get_params, struct ast_variable *path_vars, struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
Definition: test_ari.c:59
static PGresult * result
Definition: cel_pgsql.c:88
#define AST_VECTOR_SIZE(vec)
Get the number of elements in a vector.
Definition: vector.h:611

◆ ast_msg_queue()

int ast_msg_queue ( struct ast_msg msg)

Queue a message for routing through the dialplan.

Regardless of the return value of this function, this funciton will take care of ensuring that the message object is properly destroyed when needed.

Return values
0message successfully queued
non-zerofailure, message not sent to dialplan

Definition at line 958 of file message.c.

References ao2_ref, ast_taskprocessor_push(), and msg_q_cb().

Referenced by AST_TEST_DEFINE(), module_on_rx_request(), receive_message(), and xmpp_pak_message().

959 {
960  int res;
961  res = ast_taskprocessor_push(msg_q_tp, msg_q_cb, msg);
962  if (res == -1) {
963  ao2_ref(msg, -1);
964  }
965 
966  return res;
967 }
static int msg_q_cb(void *data)
Definition: message.c:907
#define ao2_ref(o, delta)
Definition: astobj2.h:464
int ast_taskprocessor_push(struct ast_taskprocessor *tps, int(*task_exe)(void *datap), void *datap) attribute_warn_unused_result
Push a task into the specified taskprocessor queue and signal the taskprocessor thread.

◆ ast_msg_ref()

struct ast_msg* ast_msg_ref ( struct ast_msg msg)

Bump a msg's ref count.

Definition at line 442 of file message.c.

References ao2_ref, and msg_data::msg.

Referenced by msg_data_create().

443 {
444  ao2_ref(msg, 1);
445  return msg;
446 }
#define ao2_ref(o, delta)
Definition: astobj2.h:464

◆ ast_msg_send()

int ast_msg_send ( struct ast_msg msg,
const char *  to,
const char *  from 
)

Send a msg directly to an endpoint.

Regardless of the return value of this function, this funciton will take care of ensuring that the message object is properly destroyed when needed.

Return values
0message successfully queued to be sent out
non-zerofailure, message not get sent out.

Definition at line 1369 of file message.c.

References ao2_ref, ast_log, ast_rwlock_rdlock, ast_rwlock_unlock, ast_strdupa, ast_strlen_zero, LOG_ERROR, msg_find_by_tech_name(), ast_msg_tech::msg_send, msg_tech, NULL, S_OR, and strsep().

Referenced by AST_TEST_DEFINE(), and send_message().

1370 {
1371  char *tech_name = NULL;
1372  const struct ast_msg_tech *msg_tech;
1373  int res = -1;
1374 
1375  if (ast_strlen_zero(to)) {
1376  ao2_ref(msg, -1);
1377  return -1;
1378  }
1379 
1380  tech_name = ast_strdupa(to);
1381  tech_name = strsep(&tech_name, ":");
1382 
1384  msg_tech = msg_find_by_tech_name(tech_name);
1385 
1386  if (!msg_tech) {
1387  ast_log(LOG_ERROR, "Unknown message tech: %s\n", tech_name);
1389  return -1;
1390  }
1391 
1392  res = msg_tech->msg_send(msg, S_OR(to, ""), S_OR(from, ""));
1393 
1395 
1396  ao2_ref(msg, -1);
1397 
1398  return res;
1399 }
#define ast_rwlock_rdlock(a)
Definition: lock.h:233
static const struct ast_msg_tech * msg_find_by_tech_name(const char *tech_name)
Definition: message.c:1181
static const struct ast_msg_tech msg_tech
#define NULL
Definition: resample.c:96
#define ast_rwlock_unlock(a)
Definition: lock.h:232
#define ast_strlen_zero(foo)
Definition: strings.h:52
#define ast_log
Definition: astobj2.c:42
#define ao2_ref(o, delta)
Definition: astobj2.h:464
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:300
#define LOG_ERROR
Definition: logger.h:285
A message technology.
Definition: message.h:52
static ast_rwlock_t msg_techs_lock
Lock for msg_techs vector.
Definition: message.c:255
char * strsep(char **str, const char *delims)
#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
int(*const msg_send)(const struct ast_msg *msg, const char *to, const char *from)
Send a message.
Definition: message.h:75

◆ ast_msg_set_body()

int ast_msg_set_body ( struct ast_msg msg,
const char *  fmt,
  ... 
)

Set the 'body' text of a message (in UTF-8)

Return values
0success
-1failure

Definition at line 476 of file message.c.

References ast_string_field_build_va, and ast_msg::body.

Referenced by action_messagesend(), AST_TEST_DEFINE(), msg_func_write(), receive_message(), rx_data_to_ast_msg(), send_message(), and xmpp_pak_message().

477 {
478  va_list ap;
479 
480  va_start(ap, fmt);
481  ast_string_field_build_va(msg, body, fmt, ap);
482  va_end(ap);
483 
484  return 0;
485 }
#define ast_string_field_build_va(x, field, fmt, args)
Set a field to a complex (built) value.
Definition: stringfields.h:588

◆ ast_msg_set_context()

int ast_msg_set_context ( struct ast_msg msg,
const char *  fmt,
  ... 
)

Set the dialplan context for this message.

Return values
0success
-1failure

Definition at line 487 of file message.c.

References ast_string_field_build_va, and context.

Referenced by AST_TEST_DEFINE(), receive_message(), rx_data_to_ast_msg(), and xmpp_pak_message().

488 {
489  va_list ap;
490 
491  va_start(ap, fmt);
492  ast_string_field_build_va(msg, context, fmt, ap);
493  va_end(ap);
494 
495  return 0;
496 }
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:116
#define ast_string_field_build_va(x, field, fmt, args)
Set a field to a complex (built) value.
Definition: stringfields.h:588

◆ ast_msg_set_endpoint()

int ast_msg_set_endpoint ( struct ast_msg msg,
const char *  fmt,
  ... 
)

Set the technology's endpoint associated with this message.

Since
12.5.0
Return values
0success
-1failure

Definition at line 520 of file message.c.

References ast_string_field_build_va, and ast_msg::endpoint.

Referenced by AST_TEST_DEFINE(), receive_message(), rx_data_to_ast_msg(), and xmpp_pak_message().

521 {
522  va_list ap;
523 
524  va_start(ap, fmt);
525  ast_string_field_build_va(msg, endpoint, fmt, ap);
526  va_end(ap);
527 
528  return 0;
529 }
#define ast_string_field_build_va(x, field, fmt, args)
Set a field to a complex (built) value.
Definition: stringfields.h:588

◆ ast_msg_set_exten()

int ast_msg_set_exten ( struct ast_msg msg,
const char *  fmt,
  ... 
)

Set the dialplan extension for this message.

Return values
0success
-1failure

Definition at line 498 of file message.c.

References ast_string_field_build_va, and exten.

Referenced by AST_TEST_DEFINE(), receive_message(), and rx_data_to_ast_msg().

499 {
500  va_list ap;
501 
502  va_start(ap, fmt);
503  ast_string_field_build_va(msg, exten, fmt, ap);
504  va_end(ap);
505 
506  return 0;
507 }
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:118
#define ast_string_field_build_va(x, field, fmt, args)
Set a field to a complex (built) value.
Definition: stringfields.h:588

◆ ast_msg_set_from()

int ast_msg_set_from ( struct ast_msg msg,
const char *  fmt,
  ... 
)

Set the 'from' URI of a message.

Return values
0success
-1failure

Definition at line 465 of file message.c.

References ast_string_field_build_va, and msg_data::from.

Referenced by AST_TEST_DEFINE(), msg_func_write(), receive_message(), rx_data_to_ast_msg(), send_message(), and xmpp_pak_message().

466 {
467  va_list ap;
468 
469  va_start(ap, fmt);
470  ast_string_field_build_va(msg, from, fmt, ap);
471  va_end(ap);
472 
473  return 0;
474 }
#define ast_string_field_build_va(x, field, fmt, args)
Set a field to a complex (built) value.
Definition: stringfields.h:588

◆ ast_msg_set_tech()

int ast_msg_set_tech ( struct ast_msg msg,
const char *  fmt,
  ... 
)

Set the technology associated with this message.

Since
12.5.0
Return values
0success
-1failure

Definition at line 509 of file message.c.

References ast_string_field_build_va, and ast_msg::tech.

Referenced by AST_TEST_DEFINE(), receive_message(), rx_data_to_ast_msg(), and xmpp_pak_message().

510 {
511  va_list ap;
512 
513  va_start(ap, fmt);
514  ast_string_field_build_va(msg, tech, fmt, ap);
515  va_end(ap);
516 
517  return 0;
518 }
#define ast_string_field_build_va(x, field, fmt, args)
Set a field to a complex (built) value.
Definition: stringfields.h:588

◆ ast_msg_set_to()

int ast_msg_set_to ( struct ast_msg msg,
const char *  fmt,
  ... 
)

Set the 'to' URI of a message.

Return values
0success
-1failure

Definition at line 454 of file message.c.

References ast_string_field_build_va, and ast_msg::to.

Referenced by AST_TEST_DEFINE(), msg_func_write(), receive_message(), rx_data_to_ast_msg(), send_message(), and xmpp_pak_message().

455 {
456  va_list ap;
457 
458  va_start(ap, fmt);
459  ast_string_field_build_va(msg, to, fmt, ap);
460  va_end(ap);
461 
462  return 0;
463 }
#define ast_string_field_build_va(x, field, fmt, args)
Set a field to a complex (built) value.
Definition: stringfields.h:588

◆ ast_msg_set_var()

int ast_msg_set_var ( struct ast_msg msg,
const char *  name,
const char *  value 
)

Set a variable on the message going to the dialplan.

Note
Setting a variable that already exists overwrites the existing variable value
Parameters
msg
nameName of variable to set
valueValue of variable to set
Return values
0success
-1failure

Definition at line 615 of file message.c.

References msg_set_var_full().

Referenced by AST_TEST_DEFINE(), headers_to_vars(), receive_message(), rx_data_to_ast_msg(), set_message_vars_from_req(), and xmpp_pak_message().

616 {
617  return msg_set_var_full(msg, name, value, 0);
618 }
int value
Definition: syslog.c:37
static int msg_set_var_full(struct ast_msg *msg, const char *name, const char *value, unsigned int outbound)
Definition: message.c:580
static const char name[]
Definition: cdr_mysql.c:74

◆ ast_msg_set_var_outbound()

int ast_msg_set_var_outbound ( struct ast_msg msg,
const char *  name,
const char *  value 
)

Set a variable on the message being sent to a message tech directly.

Note
Setting a variable that already exists overwrites the existing variable value
Parameters
msg
nameName of variable to set
valueValue of variable to set
Return values
0success
-1failure

Definition at line 610 of file message.c.

References msg_set_var_full().

Referenced by action_messagesend(), AST_TEST_DEFINE(), msg_data_func_write(), and send_message().

611 {
612  return msg_set_var_full(msg, name, value, 1);
613 }
int value
Definition: syslog.c:37
static int msg_set_var_full(struct ast_msg *msg, const char *name, const char *value, unsigned int outbound)
Definition: message.c:580
static const char name[]
Definition: cdr_mysql.c:74

◆ ast_msg_tech_register()

int ast_msg_tech_register ( const struct ast_msg_tech tech)

Register a message technology.

Return values
0success
non-zerofailure

Definition at line 1569 of file message.c.

References ast_log, ast_rwlock_unlock, ast_rwlock_wrlock, AST_VECTOR_APPEND, ast_verb, LOG_ERROR, match(), msg_find_by_tech_name(), and ast_msg_tech::name.

Referenced by AST_TEST_DEFINE(), and load_module().

1570 {
1571  const struct ast_msg_tech *match;
1572 
1574 
1575  match = msg_find_by_tech_name(tech->name);
1576  if (match) {
1577  ast_log(LOG_ERROR, "Message technology already registered for '%s'\n",
1578  tech->name);
1580  return -1;
1581  }
1582 
1583  if (AST_VECTOR_APPEND(&msg_techs, tech)) {
1584  ast_log(LOG_ERROR, "Failed to register message technology for '%s'\n",
1585  tech->name);
1587  return -1;
1588  }
1589  ast_verb(3, "Message technology '%s' registered.\n", tech->name);
1590 
1592 
1593  return 0;
1594 }
#define AST_VECTOR_APPEND(vec, elem)
Append an element to a vector, growing the vector if needed.
Definition: vector.h:256
const char *const name
Name of this message technology.
Definition: message.h:61
static const struct ast_msg_tech * msg_find_by_tech_name(const char *tech_name)
Definition: message.c:1181
static int match(struct ast_sockaddr *addr, unsigned short callno, unsigned short dcallno, const struct chan_iax2_pvt *cur, int check_dcallno)
Definition: chan_iax2.c:2315
#define ast_rwlock_unlock(a)
Definition: lock.h:232
#define ast_verb(level,...)
Definition: logger.h:463
#define ast_log
Definition: astobj2.c:42
#define LOG_ERROR
Definition: logger.h:285
A message technology.
Definition: message.h:52
static ast_rwlock_t msg_techs_lock
Lock for msg_techs vector.
Definition: message.c:255
#define ast_rwlock_wrlock(a)
Definition: lock.h:234

◆ ast_msg_tech_unregister()

int ast_msg_tech_unregister ( const struct ast_msg_tech tech)

Unregister a message technology.

Return values
0success
non-zerofailure

Definition at line 1610 of file message.c.

References ast_log, ast_rwlock_unlock, ast_rwlock_wrlock, AST_VECTOR_ELEM_CLEANUP_NOOP, AST_VECTOR_REMOVE_CMP_UNORDERED, ast_verb, LOG_ERROR, match(), msg_tech_cmp(), and ast_msg_tech::name.

Referenced by AST_TEST_DEFINE(), load_module(), and unload_module().

1611 {
1612  int match;
1613 
1615  match = AST_VECTOR_REMOVE_CMP_UNORDERED(&msg_techs, tech, msg_tech_cmp,
1618 
1619  if (match) {
1620  ast_log(LOG_ERROR, "No '%s' message technology found.\n", tech->name);
1621  return -1;
1622  }
1623 
1624  ast_verb(2, "Message technology '%s' unregistered.\n", tech->name);
1625 
1626  return 0;
1627 }
#define AST_VECTOR_REMOVE_CMP_UNORDERED(vec, value, cmp, cleanup)
Remove an element from a vector that matches the given comparison.
Definition: vector.h:488
const char *const name
Name of this message technology.
Definition: message.h:61
static int match(struct ast_sockaddr *addr, unsigned short callno, unsigned short dcallno, const struct chan_iax2_pvt *cur, int check_dcallno)
Definition: chan_iax2.c:2315
#define ast_rwlock_unlock(a)
Definition: lock.h:232
#define ast_verb(level,...)
Definition: logger.h:463
#define ast_log
Definition: astobj2.c:42
#define AST_VECTOR_ELEM_CLEANUP_NOOP(elem)
Vector element cleanup that does nothing.
Definition: vector.h:573
#define LOG_ERROR
Definition: logger.h:285
static ast_rwlock_t msg_techs_lock
Lock for msg_techs vector.
Definition: message.c:255
#define ast_rwlock_wrlock(a)
Definition: lock.h:234
static int msg_tech_cmp(const struct ast_msg_tech *vec_elem, const struct ast_msg_tech *srch)
Comparison callback for ast_msg_tech vector removal.
Definition: message.c:1605

◆ ast_msg_var_iterator_destroy()

void ast_msg_var_iterator_destroy ( struct ast_msg_var_iterator iter)

Destroy a message variable iterator.

Parameters
iterIterator to be destroyed

Definition at line 706 of file message.c.

References ao2_iterator_destroy(), ast_free, ast_msg_var_unref_current(), and ast_msg_var_iterator::iter.

Referenced by AST_TEST_DEFINE(), msg_to_json(), sip_msg_send(), and vars_to_headers().

707 {
708  if (iter) {
709  ao2_iterator_destroy(&iter->iter);
711  ast_free(iter);
712  }
713 }
struct ao2_iterator iter
Definition: message.c:640
void ao2_iterator_destroy(struct ao2_iterator *iter)
Destroy a container iterator.
void ast_msg_var_unref_current(struct ast_msg_var_iterator *iter)
Unref a message var from inside an iterator loop.
Definition: message.c:700
#define ast_free(a)
Definition: astmm.h:182

◆ ast_msg_var_iterator_init()

struct ast_msg_var_iterator* ast_msg_var_iterator_init ( const struct ast_msg msg)

Create a new message variable iterator.

Parameters
msgA message whose variables are to be iterated over
Returns
An opaque pointer to the new iterator

Definition at line 644 of file message.c.

References ao2_iterator_init(), ast_calloc, ast_msg_var_iterator::iter, NULL, and ast_msg::vars.

Referenced by AST_TEST_DEFINE(), msg_to_json(), sip_msg_send(), and vars_to_headers().

645 {
646  struct ast_msg_var_iterator *iter;
647 
648  iter = ast_calloc(1, sizeof(*iter));
649  if (!iter) {
650  return NULL;
651  }
652 
653  iter->iter = ao2_iterator_init(msg->vars, 0);
654 
655  return iter;
656 }
struct ao2_iterator iter
Definition: message.c:640
#define NULL
Definition: resample.c:96
struct ao2_container * vars
Definition: message.c:251
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:204
struct ao2_iterator ao2_iterator_init(struct ao2_container *c, int flags) attribute_warn_unused_result
Create an iterator for a container.

◆ ast_msg_var_iterator_next()

int ast_msg_var_iterator_next ( const struct ast_msg msg,
struct ast_msg_var_iterator iter,
const char **  name,
const char **  value 
)

Get the next variable name and value that is set for sending outbound.

Parameters
msgThe message with the variables
iterAn iterator created with ast_msg_var_iterator_init
nameA pointer to the name result pointer
valueA pointer to the value result pointer
Return values
0No more entries
1Valid entry

Definition at line 689 of file message.c.

References ast_msg_var_iterator_get_next().

Referenced by AST_TEST_DEFINE(), sip_msg_send(), and vars_to_headers().

690 {
691  return ast_msg_var_iterator_get_next(msg, iter, name, value, 1);
692 }
int value
Definition: syslog.c:37
static const char name[]
Definition: cdr_mysql.c:74
static int ast_msg_var_iterator_get_next(const struct ast_msg *msg, struct ast_msg_var_iterator *iter, const char **name, const char **value, unsigned int send)
Definition: message.c:658

◆ ast_msg_var_iterator_next_received()

int ast_msg_var_iterator_next_received ( const struct ast_msg msg,
struct ast_msg_var_iterator iter,
const char **  name,
const char **  value 
)

Get the next variable name and value that was set on a received message.

Parameters
msgThe message with the variables
iterAn iterator created with ast_msg_var_iterator_init
nameA pointer to the name result pointer
valueA pointer to the value result pointer
Return values
0No more entries
1Valid entry

Definition at line 694 of file message.c.

References ast_msg_var_iterator_get_next().

Referenced by msg_to_json().

696 {
697  return ast_msg_var_iterator_get_next(msg, iter, name, value, 0);
698 }
int value
Definition: syslog.c:37
static const char name[]
Definition: cdr_mysql.c:74
static int ast_msg_var_iterator_get_next(const struct ast_msg *msg, struct ast_msg_var_iterator *iter, const char **name, const char **value, unsigned int send)
Definition: message.c:658

◆ ast_msg_var_unref_current()

void ast_msg_var_unref_current ( struct ast_msg_var_iterator iter)

Unref a message var from inside an iterator loop.

Definition at line 700 of file message.c.

References ao2_cleanup, ast_msg_var_iterator::current_used, and NULL.

Referenced by ast_msg_var_iterator_destroy(), AST_TEST_DEFINE(), msg_to_json(), sip_msg_send(), and vars_to_headers().

701 {
702  ao2_cleanup(iter->current_used);
703  iter->current_used = NULL;
704 }
#define NULL
Definition: resample.c:96
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
struct msg_data * current_used
Definition: message.c:641