Asterisk - The Open Source Telephony Project  21.4.1
Data Structures | Macros | Functions | Variables
main/message.c File Reference

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

#include "asterisk.h"
#include "asterisk/_private.h"
#include "asterisk/module.h"
#include "asterisk/datastore.h"
#include "asterisk/pbx.h"
#include "asterisk/manager.h"
#include "asterisk/strings.h"
#include "asterisk/astobj2.h"
#include "asterisk/vector.h"
#include "asterisk/app.h"
#include "asterisk/taskprocessor.h"
#include "asterisk/message.h"

Go to the source code of this file.

Data Structures

struct  ast_msg
 A message. More...
 
struct  ast_msg_data
 Structure used to transport a message through the frame core. More...
 
struct  ast_msg_var_iterator
 
struct  msg_data
 
struct  outhead
 

Macros

#define ATTRIBUTE_UNSET   -1
 

Functions

static void __init_msg_q_chan (void)
 
static int action_messagesend (struct mansession *s, const struct message *m)
 
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_init (void)
 
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.
 
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...
 
void ast_msg_shutdown (void)
 
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...
 
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)
 
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.
 
static void chan_cleanup (struct ast_channel *chan)
 
static int chan_msg_indicate (struct ast_channel *chan, int condition, const void *data, size_t datalen)
 
static struct ast_framechan_msg_read (struct ast_channel *chan)
 
static int chan_msg_send_digit_begin (struct ast_channel *chan, char digit)
 
static int chan_msg_send_digit_end (struct ast_channel *chan, char digit, unsigned int duration)
 
static int chan_msg_write (struct ast_channel *chan, struct ast_frame *fr)
 
static struct ast_channelcreate_msg_q_chan (void)
 
static void destroy_msg_q_chan (void *data)
 
static int dialplan_handle_msg_cb (struct ast_msg *msg)
 
static int dialplan_has_destination_cb (const struct ast_msg *msg)
 
static void message_shutdown (void)
 
static struct msg_datamsg_data_alloc (void)
 
static int msg_data_cmp_fn (void *obj, void *arg, int flags)
 
static void msg_data_destructor (void *obj)
 
static struct msg_datamsg_data_find (struct ao2_container *vars, const char *name)
 
static int msg_data_func_read (struct ast_channel *chan, const char *function, char *data, char *buf, size_t len)
 
static int msg_data_func_write (struct ast_channel *chan, const char *function, char *data, const char *value)
 
static struct ast_datastoremsg_datastore_find_or_create (struct ast_channel *chan)
 
static void msg_destructor (void *obj)
 
static void msg_ds_destroy (void *data)
 
static const struct ast_msg_techmsg_find_by_tech_name (const char *tech_name)
 
static int msg_func_read (struct ast_channel *chan, const char *function, char *data, char *buf, size_t len)
 
static int msg_func_write (struct ast_channel *chan, const char *function, char *data, const char *value)
 
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. More...
 
static const struct ast_msg_handlermsg_handler_find_by_tech_name (const char *tech_name)
 
static int msg_q_cb (void *data)
 
static void msg_route (struct ast_channel *chan, struct ast_msg *msg)
 
static int msg_send_exec (struct ast_channel *chan, const char *data)
 
static int msg_set_var_full (struct ast_msg *msg, const char *name, const char *value, unsigned int outbound)
 
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. More...
 

Variables

static const char app_msg_send [] = "MessageSend"
 
static struct ast_msg_handler dialplan_msg_handler
 
static struct ast_channel_tech msg_chan_tech_hack
 
static struct ast_custom_function msg_data_function
 
static const struct ast_datastore_info msg_datastore
 
static struct ast_custom_function msg_function
 
struct {
   size_t   current
 
   const struct ast_msg_handler **   elems
 
   size_t   max
 
msg_handlers
 Vector of received message handlers.
 
static ast_rwlock_t msg_handlers_lock
 Lock for msg_handlers vector.
 
static struct ast_threadstorage msg_q_chan = { .once = PTHREAD_ONCE_INIT , .key_init = __init_msg_q_chan , .custom_init = NULL , }
 
static struct ast_taskprocessormsg_q_tp
 
struct {
   size_t   current
 
   const struct ast_msg_tech **   elems
 
   size_t   max
 
msg_techs
 Vector of message technologies.
 
static ast_rwlock_t msg_techs_lock
 Lock for msg_techs vector.
 

Detailed Description

Out-of-call text message support.

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

Definition in file main/message.c.

Function Documentation

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 432 of file main/message.c.

References AO2_ALLOC_OPT_LOCK_MUTEX, ao2_container_alloc_list, ao2_ref, ast_string_field_init, ast_string_field_set, ast_msg::context, and ast_msg::vars.

Referenced by xmpp_pak_message().

433 {
434  struct ast_msg *msg;
435 
436  if (!(msg = ao2_alloc(sizeof(*msg), msg_destructor))) {
437  return NULL;
438  }
439 
440  if (ast_string_field_init(msg, 128)) {
441  ao2_ref(msg, -1);
442  return NULL;
443  }
444 
446  NULL, msg_data_cmp_fn);
447  if (!msg->vars) {
448  ao2_ref(msg, -1);
449  return NULL;
450  }
451  ast_string_field_set(msg, context, "default");
452 
453  return msg;
454 }
#define ao2_container_alloc_list(ao2_options, container_options, sort_fn, cmp_fn)
Allocate and initialize a list container.
Definition: astobj2.h:1327
struct ao2_container * vars
Definition: main/message.c:265
#define ast_string_field_init(x, size)
Initialize a field pool and fields.
Definition: stringfields.h:359
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
const ast_string_field context
Definition: main/message.c:263
A message.
Definition: main/message.c:247
#define ast_string_field_set(x, field, data)
Set a field to a simple string value.
Definition: stringfields.h:521
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().

Return values
NULLalways.

Definition at line 462 of file main/message.c.

References ao2_ref.

Referenced by xmpp_pak_message().

463 {
464  ao2_ref(msg, -1);
465  return NULL;
466 }
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
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 545 of file main/message.c.

References ast_msg::body.

546 {
547  return msg->body;
548 }
const ast_string_field body
Definition: main/message.c:263
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
Returns
The endpoint associated with the message
Return values
NULLor empty string if the message has no associated endpoint

Definition at line 565 of file main/message.c.

References ast_msg::endpoint.

566 {
567  return msg->endpoint;
568 }
const ast_string_field endpoint
Definition: main/message.c:263
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
Returns
The source of the message
Return values
NULLor empty string if the message has no source

Definition at line 550 of file main/message.c.

References ast_msg::from.

551 {
552  return msg->from;
553 }
const ast_string_field from
Definition: main/message.c:263
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
Returns
The technology of the message
Return values
NULLor empty string if the message has no associated technology

Definition at line 560 of file main/message.c.

References ast_msg::tech.

561 {
562  return msg->tech;
563 }
const ast_string_field tech
Definition: main/message.c:263
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
Returns
The destination of the message
Return values
NULLor empty string if the message has no destination

Definition at line 555 of file main/message.c.

References ast_msg::to.

556 {
557  return msg->to;
558 }
const ast_string_field to
Definition: main/message.c:263
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 634 of file main/message.c.

References ao2_ref, and ast_msg::vars.

635 {
636  struct msg_data *data;
637  const char *val = NULL;
638 
639  if (!(data = msg_data_find(msg->vars, name))) {
640  return NULL;
641  }
642 
643  /* Yep, this definitely looks like val would be a dangling pointer
644  * after the ref count is decremented. As long as the message structure
645  * is used in a thread safe manner, this will not be the case though.
646  * The ast_msg holds a reference to this object in the msg->vars container. */
647  val = data->value;
648  ao2_ref(data, -1);
649 
650  return val;
651 }
struct ao2_container * vars
Definition: main/message.c:265
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
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 1657 of file main/message.c.

References AST_VECTOR_APPEND, msg_handlers, msg_handlers_lock, and ast_msg_handler::name.

Referenced by ast_msg_init(), and messaging_init().

1658 {
1659  const struct ast_msg_handler *match;
1660 
1661  ast_rwlock_wrlock(&msg_handlers_lock);
1662 
1663  match = msg_handler_find_by_tech_name(handler->name);
1664  if (match) {
1665  ast_log(LOG_ERROR, "Message handler already registered for '%s'\n",
1666  handler->name);
1667  ast_rwlock_unlock(&msg_handlers_lock);
1668  return -1;
1669  }
1670 
1671  if (AST_VECTOR_APPEND(&msg_handlers, handler)) {
1672  ast_log(LOG_ERROR, "Failed to register message handler for '%s'\n",
1673  handler->name);
1674  ast_rwlock_unlock(&msg_handlers_lock);
1675  return -1;
1676  }
1677  ast_verb(5, "Message handler '%s' registered.\n", handler->name);
1678 
1679  ast_rwlock_unlock(&msg_handlers_lock);
1680 
1681  return 0;
1682 
1683 }
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
struct @378 msg_handlers
Vector of received message handlers.
const char * name
Name of the message handler.
Definition: message.h:102
static ast_rwlock_t msg_handlers_lock
Lock for msg_handlers vector.
Definition: main/message.c:275
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 1699 of file main/message.c.

References AST_VECTOR_ELEM_CLEANUP_NOOP, AST_VECTOR_REMOVE_CMP_UNORDERED, msg_handler_cmp(), msg_handlers, msg_handlers_lock, and ast_msg_handler::name.

Referenced by messaging_cleanup().

1700 {
1701  int match;
1702 
1703  ast_rwlock_wrlock(&msg_handlers_lock);
1706  ast_rwlock_unlock(&msg_handlers_lock);
1707 
1708  if (match) {
1709  ast_log(LOG_ERROR, "No '%s' message handler found.\n", handler->name);
1710  return -1;
1711  }
1712 
1713  ast_verb(5, "Message handler '%s' unregistered.\n", handler->name);
1714  return 0;
1715 }
#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
struct @378 msg_handlers
Vector of received message handlers.
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.
#define AST_VECTOR_ELEM_CLEANUP_NOOP(elem)
Vector element cleanup that does nothing.
Definition: vector.h:571
const char * name
Name of the message handler.
Definition: message.h:102
static ast_rwlock_t msg_handlers_lock
Lock for msg_handlers vector.
Definition: main/message.c:275
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 951 of file main/message.c.

References ast_debug, AST_VECTOR_GET, AST_VECTOR_SIZE, ast_msg_handler::has_destination, msg_handlers, msg_handlers_lock, and ast_msg_handler::name.

952 {
953  int i;
954  int result = 0;
955 
956  ast_rwlock_rdlock(&msg_handlers_lock);
957  for (i = 0; i < AST_VECTOR_SIZE(&msg_handlers); i++) {
958  const struct ast_msg_handler *handler = AST_VECTOR_GET(&msg_handlers, i);
959 
960  ast_debug(5, "Seeing if %s can handle message\n", handler->name);
961  if (handler->has_destination(msg)) {
962  ast_debug(5, "%s can handle message\n", handler->name);
963  result = 1;
964  break;
965  }
966  }
967  ast_rwlock_unlock(&msg_handlers_lock);
968 
969  return result;
970 }
An external processor of received messages.
Definition: message.h:98
struct @378 msg_handlers
Vector of received message handlers.
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_debug(level,...)
Log a DEBUG message.
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:680
static ast_rwlock_t msg_handlers_lock
Lock for msg_handlers vector.
Definition: main/message.c:275
#define AST_VECTOR_SIZE(vec)
Get the number of elements in a vector.
Definition: vector.h:609
int ast_msg_init ( void  )

Provided by message.c

Definition at line 1758 of file main/message.c.

References __ast_custom_function_register(), ast_manager_register_xml_core, ast_msg_handler_register(), ast_register_application2(), ast_register_cleanup(), ast_rwlock_init, ast_taskprocessor_get(), AST_VECTOR_INIT, msg_handlers, msg_handlers_lock, msg_techs, and TPS_REF_DEFAULT.

1759 {
1760  int res;
1761 
1762  msg_q_tp = ast_taskprocessor_get("ast_msg_queue", TPS_REF_DEFAULT);
1763  if (!msg_q_tp) {
1764  return -1;
1765  }
1766 
1768  if (AST_VECTOR_INIT(&msg_techs, 8)) {
1769  return -1;
1770  }
1771 
1773  if (AST_VECTOR_INIT(&msg_handlers, 4)) {
1774  return -1;
1775  }
1776 
1777  res = ast_msg_handler_register(&dialplan_msg_handler);
1778 
1779  res |= __ast_custom_function_register(&msg_function, NULL);
1780  res |= __ast_custom_function_register(&msg_data_function, NULL);
1781  res |= ast_register_application2(app_msg_send, msg_send_exec, NULL, NULL, NULL);
1782  res |= ast_manager_register_xml_core("MessageSend", EVENT_FLAG_MESSAGE, action_messagesend);
1783 
1784  ast_register_cleanup(message_shutdown);
1785 
1786  return res;
1787 }
#define ast_rwlock_init(rwlock)
wrapper for rwlock with tracking enabled
Definition: lock.h:224
struct ast_taskprocessor * ast_taskprocessor_get(const char *name, enum ast_tps_options create)
Get a reference to a taskprocessor with the specified name and create the taskprocessor if necessary...
return a reference to a taskprocessor, create one if it does not exist
Definition: taskprocessor.h:76
struct @378 msg_handlers
Vector of received message handlers.
static ast_rwlock_t msg_techs_lock
Lock for msg_techs vector.
Definition: main/message.c:269
#define ast_manager_register_xml_core(action, authority, func)
Register a manager callback using XML documentation to describe the manager.
Definition: manager.h:202
int ast_msg_handler_register(const struct ast_msg_handler *handler)
Register a ast_msg_handler.
#define AST_VECTOR_INIT(vec, size)
Initialize a vector.
Definition: vector.h:113
int ast_register_cleanup(void(*func)(void))
Register a function to be executed before Asterisk gracefully exits.
Definition: clicompat.c:19
struct @377 msg_techs
Vector of message technologies.
static ast_rwlock_t msg_handlers_lock
Lock for msg_handlers vector.
Definition: main/message.c:275
int __ast_custom_function_register(struct ast_custom_function *acf, struct ast_module *mod)
Register a custom function.
int ast_register_application2(const char *app, int(*execute)(struct ast_channel *, const char *), const char *synopsis, const char *description, void *mod)
Register an application.
Definition: pbx_app.c:103
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 972 of file main/message.c.

References ao2_ref, and ast_taskprocessor_push().

Referenced by xmpp_pak_message().

973 {
974  int res;
975  res = ast_taskprocessor_push(msg_q_tp, msg_q_cb, msg);
976  if (res == -1) {
977  ao2_ref(msg, -1);
978  }
979 
980  return res;
981 }
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
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.
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 1397 of file main/message.c.

References ao2_ref, ast_strdupa, ast_msg_tech::msg_send, and S_OR.

1398 {
1399  char *tech_name = NULL;
1400  const struct ast_msg_tech *msg_tech;
1401  int res = -1;
1402 
1403  if (ast_strlen_zero(to)) {
1404  ao2_ref(msg, -1);
1405  return -1;
1406  }
1407 
1408  tech_name = ast_strdupa(to);
1409  tech_name = strsep(&tech_name, ":");
1410 
1411  ast_rwlock_rdlock(&msg_techs_lock);
1412  msg_tech = msg_find_by_tech_name(tech_name);
1413 
1414  if (!msg_tech) {
1415  ast_log(LOG_ERROR, "Unknown message tech: %s\n", tech_name);
1416  ast_rwlock_unlock(&msg_techs_lock);
1417  return -1;
1418  }
1419 
1420  res = msg_tech->msg_send(msg, S_OR(to, ""), S_OR(from, ""));
1421 
1422  ast_rwlock_unlock(&msg_techs_lock);
1423 
1424  ao2_ref(msg, -1);
1425 
1426  return res;
1427 }
static ast_rwlock_t msg_techs_lock
Lock for msg_techs vector.
Definition: main/message.c:269
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:298
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
A message technology.
Definition: message.h:52
#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
int(*const msg_send)(const struct ast_msg *msg, const char *to, const char *from)
Send a message.
Definition: message.h:75
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 490 of file main/message.c.

References ast_string_field_build_va, and ast_msg::body.

Referenced by xmpp_pak_message().

491 {
492  va_list ap;
493 
494  va_start(ap, fmt);
495  ast_string_field_build_va(msg, body, fmt, ap);
496  va_end(ap);
497 
498  return 0;
499 }
#define ast_string_field_build_va(x, field, fmt, args)
Set a field to a complex (built) value.
Definition: stringfields.h:591
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 501 of file main/message.c.

References ast_string_field_build_va, and ast_msg::context.

Referenced by xmpp_pak_message().

502 {
503  va_list ap;
504 
505  va_start(ap, fmt);
506  ast_string_field_build_va(msg, context, fmt, ap);
507  va_end(ap);
508 
509  return 0;
510 }
#define ast_string_field_build_va(x, field, fmt, args)
Set a field to a complex (built) value.
Definition: stringfields.h:591
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 534 of file main/message.c.

References ast_string_field_build_va, and ast_msg::endpoint.

Referenced by xmpp_pak_message().

535 {
536  va_list ap;
537 
538  va_start(ap, fmt);
539  ast_string_field_build_va(msg, endpoint, fmt, ap);
540  va_end(ap);
541 
542  return 0;
543 }
#define ast_string_field_build_va(x, field, fmt, args)
Set a field to a complex (built) value.
Definition: stringfields.h:591
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 512 of file main/message.c.

References ast_string_field_build_va, and ast_msg::exten.

513 {
514  va_list ap;
515 
516  va_start(ap, fmt);
517  ast_string_field_build_va(msg, exten, fmt, ap);
518  va_end(ap);
519 
520  return 0;
521 }
#define ast_string_field_build_va(x, field, fmt, args)
Set a field to a complex (built) value.
Definition: stringfields.h:591
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 479 of file main/message.c.

References ast_string_field_build_va, and ast_msg::from.

Referenced by xmpp_pak_message().

480 {
481  va_list ap;
482 
483  va_start(ap, fmt);
484  ast_string_field_build_va(msg, from, fmt, ap);
485  va_end(ap);
486 
487  return 0;
488 }
#define ast_string_field_build_va(x, field, fmt, args)
Set a field to a complex (built) value.
Definition: stringfields.h:591
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 523 of file main/message.c.

References ast_string_field_build_va, and ast_msg::tech.

Referenced by xmpp_pak_message().

524 {
525  va_list ap;
526 
527  va_start(ap, fmt);
528  ast_string_field_build_va(msg, tech, fmt, ap);
529  va_end(ap);
530 
531  return 0;
532 }
#define ast_string_field_build_va(x, field, fmt, args)
Set a field to a complex (built) value.
Definition: stringfields.h:591
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 468 of file main/message.c.

References ast_string_field_build_va, and ast_msg::to.

Referenced by xmpp_pak_message().

469 {
470  va_list ap;
471 
472  va_start(ap, fmt);
473  ast_string_field_build_va(msg, to, fmt, ap);
474  va_end(ap);
475 
476  return 0;
477 }
#define ast_string_field_build_va(x, field, fmt, args)
Set a field to a complex (built) value.
Definition: stringfields.h:591
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 629 of file main/message.c.

Referenced by xmpp_pak_message().

630 {
631  return msg_set_var_full(msg, name, value, 0);
632 }
const char *const name
Name of this message technology.
Definition: message.h:61
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 624 of file main/message.c.

625 {
626  return msg_set_var_full(msg, name, value, 1);
627 }
const char *const name
Name of this message technology.
Definition: message.h:61
void ast_msg_shutdown ( void  )

Provided by message.c

Definition at line 1717 of file main/message.c.

References ast_taskprocessor_unreference().

1718 {
1719  if (msg_q_tp) {
1720  msg_q_tp = ast_taskprocessor_unreference(msg_q_tp);
1721  }
1722 }
void * ast_taskprocessor_unreference(struct ast_taskprocessor *tps)
Unreference the specified taskprocessor and its reference count will decrement.
int ast_msg_tech_register ( const struct ast_msg_tech tech)

Register a message technology.

Return values
0success
non-zerofailure

Definition at line 1597 of file main/message.c.

References AST_VECTOR_APPEND, msg_techs, and ast_msg_tech::name.

Referenced by load_module().

1598 {
1599  const struct ast_msg_tech *match;
1600 
1601  ast_rwlock_wrlock(&msg_techs_lock);
1602 
1603  match = msg_find_by_tech_name(tech->name);
1604  if (match) {
1605  ast_log(LOG_ERROR, "Message technology already registered for '%s'\n",
1606  tech->name);
1607  ast_rwlock_unlock(&msg_techs_lock);
1608  return -1;
1609  }
1610 
1611  if (AST_VECTOR_APPEND(&msg_techs, tech)) {
1612  ast_log(LOG_ERROR, "Failed to register message technology for '%s'\n",
1613  tech->name);
1614  ast_rwlock_unlock(&msg_techs_lock);
1615  return -1;
1616  }
1617  ast_verb(5, "Message technology '%s' registered.\n", tech->name);
1618 
1619  ast_rwlock_unlock(&msg_techs_lock);
1620 
1621  return 0;
1622 }
#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 ast_rwlock_t msg_techs_lock
Lock for msg_techs vector.
Definition: main/message.c:269
struct @377 msg_techs
Vector of message technologies.
A message technology.
Definition: message.h:52
int ast_msg_tech_unregister ( const struct ast_msg_tech tech)

Unregister a message technology.

Return values
0success
non-zerofailure

Definition at line 1638 of file main/message.c.

References AST_VECTOR_ELEM_CLEANUP_NOOP, AST_VECTOR_REMOVE_CMP_UNORDERED, msg_tech_cmp(), msg_techs, and ast_msg_tech::name.

1639 {
1640  int match;
1641 
1642  ast_rwlock_wrlock(&msg_techs_lock);
1645  ast_rwlock_unlock(&msg_techs_lock);
1646 
1647  if (match) {
1648  ast_log(LOG_ERROR, "No '%s' message technology found.\n", tech->name);
1649  return -1;
1650  }
1651 
1652  ast_verb(5, "Message technology '%s' unregistered.\n", tech->name);
1653 
1654  return 0;
1655 }
#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 ast_rwlock_t msg_techs_lock
Lock for msg_techs vector.
Definition: main/message.c:269
#define AST_VECTOR_ELEM_CLEANUP_NOOP(elem)
Vector element cleanup that does nothing.
Definition: vector.h:571
struct @377 msg_techs
Vector of message technologies.
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.
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 720 of file main/message.c.

References ao2_iterator_destroy(), and ast_msg_var_unref_current().

721 {
722  if (iter) {
723  ao2_iterator_destroy(&iter->iter);
725  ast_free(iter);
726  }
727 }
void ast_msg_var_unref_current(struct ast_msg_var_iterator *iter)
Unref a message var from inside an iterator loop.
Definition: main/message.c:714
void ao2_iterator_destroy(struct ao2_iterator *iter)
Destroy a container iterator.
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 658 of file main/message.c.

References ao2_iterator_init(), ast_calloc, and ast_msg::vars.

659 {
660  struct ast_msg_var_iterator *iter;
661 
662  iter = ast_calloc(1, sizeof(*iter));
663  if (!iter) {
664  return NULL;
665  }
666 
667  iter->iter = ao2_iterator_init(msg->vars, 0);
668 
669  return iter;
670 }
struct ao2_container * vars
Definition: main/message.c:265
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:202
struct ao2_iterator ao2_iterator_init(struct ao2_container *c, int flags) attribute_warn_unused_result
Create an iterator for a container.
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 703 of file main/message.c.

704 {
705  return ast_msg_var_iterator_get_next(msg, iter, name, value, 1);
706 }
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 708 of file main/message.c.

710 {
711  return ast_msg_var_iterator_get_next(msg, iter, name, value, 0);
712 }
static int msg_handler_cmp ( const struct ast_msg_handler vec_elem,
const struct ast_msg_handler srch 
)
static

Comparison callback for ast_msg_handler vector removal.

Parameters
vec_elemThe element in the vector being compared
srchThe element being looked up
Return values
non-zeroThe items are equal
0The items are not equal

Definition at line 1694 of file main/message.c.

References ast_msg_handler::name.

Referenced by ast_msg_handler_unregister().

1695 {
1696  return !strcmp(vec_elem->name, srch->name);
1697 }
const char * name
Name of the message handler.
Definition: message.h:102
static int msg_tech_cmp ( const struct ast_msg_tech vec_elem,
const struct ast_msg_tech srch 
)
static

Comparison callback for ast_msg_tech vector removal.

Parameters
vec_elemThe element in the vector being compared
srchThe element being looked up
Return values
non-zeroThe items are equal
0The items are not equal

Definition at line 1633 of file main/message.c.

References ast_msg_tech::name.

Referenced by ast_msg_tech_unregister().

1634 {
1635  return !strcmp(vec_elem->name, srch->name);
1636 }
const char *const name
Name of this message technology.
Definition: message.h:61

Variable Documentation

struct ast_msg_handler dialplan_msg_handler
static
Initial value:
= {
.name = "dialplan",
.handle_msg = dialplan_handle_msg_cb,
.has_destination = dialplan_has_destination_cb,
}

Definition at line 906 of file main/message.c.

struct ast_custom_function msg_data_function
static
Initial value:
= {
.name = "MESSAGE_DATA",
.read = msg_data_func_read,
.write = msg_data_func_write,
}

Definition at line 307 of file main/message.c.

const struct ast_datastore_info msg_datastore
static
Initial value:
= {
.type = "message",
.destroy = msg_ds_destroy,
}

Definition at line 286 of file main/message.c.

struct ast_custom_function msg_function
static
Initial value:
= {
.name = "MESSAGE",
.read = msg_func_read,
.write = msg_func_write,
}

Definition at line 296 of file main/message.c.