Asterisk - The Open Source Telephony Project GIT-master-754dea3
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Modules Pages
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 444 of file main/message.c.

445{
446 struct ast_msg *msg;
447
448 if (!(msg = ao2_alloc(sizeof(*msg), msg_destructor))) {
449 return NULL;
450 }
451
452 if (ast_string_field_init(msg, 128)) {
453 ao2_ref(msg, -1);
454 return NULL;
455 }
456
459 if (!msg->vars) {
460 ao2_ref(msg, -1);
461 return NULL;
462 }
463 ast_string_field_set(msg, context, "default");
464
465 return msg;
466}
@ AO2_ALLOC_OPT_LOCK_MUTEX
Definition: astobj2.h:363
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
#define ao2_container_alloc_list(ao2_options, container_options, sort_fn, cmp_fn)
Allocate and initialize a list container.
Definition: astobj2.h:1327
#define ao2_alloc(data_size, destructor_fn)
Definition: astobj2.h:409
static void msg_destructor(void *obj)
Definition: main/message.c:436
static int msg_data_cmp_fn(void *obj, void *arg, int flags)
Definition: main/message.c:424
#define NULL
Definition: resample.c:96
#define ast_string_field_set(x, field, data)
Set a field to a simple string value.
Definition: stringfields.h:521
#define ast_string_field_init(x, size)
Initialize a field pool and fields.
Definition: stringfields.h:359
A message.
Definition: main/message.c:259
struct ao2_container * vars
Definition: main/message.c:277

References ao2_alloc, AO2_ALLOC_OPT_LOCK_MUTEX, ao2_container_alloc_list, ao2_ref, ast_string_field_init, ast_string_field_set, voicemailpwcheck::context, 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(), send_message(), and xmpp_pak_message().

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

Return values
NULLalways.

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

475{
476 ao2_ref(msg, -1);
477 return NULL;
478}

References ao2_ref, and NULL.

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

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

558{
559 return msg->body;
560}
const ast_string_field body
Definition: main/message.c:275

References ast_msg::body.

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

◆ 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
Returns
The endpoint associated with the message
Return values
NULLor empty string if the message has no associated endpoint

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

578{
579 return msg->endpoint;
580}
const ast_string_field endpoint
Definition: main/message.c:275

References ast_msg::endpoint.

Referenced by AST_TEST_DEFINE(), and msg_to_endpoint().

◆ 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
Returns
The source of the message
Return values
NULLor empty string if the message has no source

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

563{
564 return msg->from;
565}
const ast_string_field from
Definition: main/message.c:275

References ast_msg::from.

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

◆ 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
Returns
The technology of the message
Return values
NULLor empty string if the message has no associated technology

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

573{
574 return msg->tech;
575}
const ast_string_field tech
Definition: main/message.c:275

References ast_msg::tech.

Referenced by AST_TEST_DEFINE(), and msg_to_endpoint().

◆ 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
Returns
The destination of the message
Return values
NULLor empty string if the message has no destination

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

568{
569 return msg->to;
570}
const ast_string_field to
Definition: main/message.c:275

References ast_msg::to.

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

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

647{
648 struct msg_data *data;
649 const char *val = NULL;
650
651 if (!(data = msg_data_find(msg->vars, name))) {
652 return NULL;
653 }
654
655 /* Yep, this definitely looks like val would be a dangling pointer
656 * after the ref count is decremented. As long as the message structure
657 * is used in a thread safe manner, this will not be the case though.
658 * The ast_msg holds a reference to this object in the msg->vars container. */
659 val = data->value;
660 ao2_ref(data, -1);
661
662 return val;
663}
static const char name[]
Definition: format_mp3.c:68
static struct msg_data * msg_data_find(struct ao2_container *vars, const char *name)
Definition: main/message.c:598
struct ast_msg * msg
const ast_string_field value
Definition: main/message.c:250
Definition: ast_expr2.c:325

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

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

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

1670{
1671 const struct ast_msg_handler *match;
1672
1674
1676 if (match) {
1677 ast_log(LOG_ERROR, "Message handler already registered for '%s'\n",
1678 handler->name);
1680 return -1;
1681 }
1682
1684 ast_log(LOG_ERROR, "Failed to register message handler for '%s'\n",
1685 handler->name);
1687 return -1;
1688 }
1689 ast_verb(5, "Message handler '%s' registered.\n", handler->name);
1690
1692
1693 return 0;
1694
1695}
#define ast_log
Definition: astobj2.c:42
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:2387
#define LOG_ERROR
#define ast_verb(level,...)
#define ast_rwlock_wrlock(a)
Definition: lock.h:240
#define ast_rwlock_unlock(a)
Definition: lock.h:238
struct @377 msg_handlers
Vector of received message handlers.
static const struct ast_msg_handler * msg_handler_find_by_tech_name(const char *tech_name)
static ast_rwlock_t msg_handlers_lock
Lock for msg_handlers vector.
Definition: main/message.c:287
An external processor of received messages.
Definition: message.h:98
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
#define AST_VECTOR_APPEND(vec, elem)
Append an element to a vector, growing the vector if needed.
Definition: vector.h:256

References ast_log, ast_rwlock_unlock, ast_rwlock_wrlock, AST_VECTOR_APPEND, ast_verb, handler(), LOG_ERROR, match(), msg_handler_find_by_tech_name(), msg_handlers, and msg_handlers_lock.

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

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

1712{
1713 int match;
1714
1719
1720 if (match) {
1721 ast_log(LOG_ERROR, "No '%s' message handler found.\n", handler->name);
1722 return -1;
1723 }
1724
1725 ast_verb(5, "Message handler '%s' unregistered.\n", handler->name);
1726 return 0;
1727}
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
#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

References ast_log, ast_rwlock_unlock, ast_rwlock_wrlock, AST_VECTOR_ELEM_CLEANUP_NOOP, AST_VECTOR_REMOVE_CMP_UNORDERED, ast_verb, handler(), LOG_ERROR, match(), msg_handler_cmp(), msg_handlers, and msg_handlers_lock.

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

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

964{
965 int i;
966 int result = 0;
967
969 for (i = 0; i < AST_VECTOR_SIZE(&msg_handlers); i++) {
971
972 ast_debug(5, "Seeing if %s can handle message\n", handler->name);
973 if (handler->has_destination(msg)) {
974 ast_debug(5, "%s can handle message\n", handler->name);
975 result = 1;
976 break;
977 }
978 }
980
981 return result;
982}
static PGresult * result
Definition: cel_pgsql.c:84
#define ast_debug(level,...)
Log a DEBUG message.
#define ast_rwlock_rdlock(a)
Definition: lock.h:239
#define AST_VECTOR_SIZE(vec)
Get the number of elements in a vector.
Definition: vector.h:609
#define AST_VECTOR_GET(vec, idx)
Get an element from a vector.
Definition: vector.h:680

References ast_debug, ast_rwlock_rdlock, ast_rwlock_unlock, AST_VECTOR_GET, AST_VECTOR_SIZE, handler(), msg_handlers, msg_handlers_lock, and result.

Referenced by AST_TEST_DEFINE(), and module_on_rx_request().

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

985{
986 int res;
988 if (res == -1) {
989 ao2_ref(msg, -1);
990 }
991
992 return res;
993}
static int msg_q_cb(void *data)
Definition: main/message.c:933
static struct ast_taskprocessor * msg_q_tp
Definition: main/message.c:292
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.

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

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

◆ ast_msg_ref()

struct ast_msg * ast_msg_ref ( struct ast_msg msg)

Bump a msg's ref count.

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

469{
470 ao2_ref(msg, 1);
471 return msg;
472}

References ao2_ref.

Referenced by msg_data_create().

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

1410{
1411 char *tech_name = NULL;
1412 const struct ast_msg_tech *msg_tech;
1413 int res = -1;
1414
1415 if (ast_strlen_zero(to)) {
1416 ao2_ref(msg, -1);
1417 return -1;
1418 }
1419
1420 tech_name = ast_strdupa(to);
1421 tech_name = strsep(&tech_name, ":");
1422
1424 msg_tech = msg_find_by_tech_name(tech_name);
1425
1426 if (!msg_tech) {
1427 ast_log(LOG_ERROR, "Unknown message tech: %s\n", tech_name);
1429 return -1;
1430 }
1431
1432 res = msg_tech->msg_send(msg, S_OR(to, ""), S_OR(from, ""));
1433
1435
1436 ao2_ref(msg, -1);
1437
1438 return res;
1439}
char * strsep(char **str, const char *delims)
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:298
static ast_rwlock_t msg_techs_lock
Lock for msg_techs vector.
Definition: main/message.c:281
static const struct ast_msg_tech * msg_find_by_tech_name(const char *tech_name)
static const struct ast_msg_tech msg_tech
#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
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
A message technology.
Definition: message.h:52
int(*const msg_send)(const struct ast_msg *msg, const char *to, const char *from)
Send a message.
Definition: message.h:75

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, msg_techs_lock, NULL, S_OR, and strsep().

Referenced by AST_TEST_DEFINE(), and send_message().

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

503{
504 va_list ap;
505
506 va_start(ap, fmt);
507 ast_string_field_build_va(msg, body, fmt, ap);
508 va_end(ap);
509
510 return 0;
511}
#define ast_string_field_build_va(x, field, fmt, args)
Set a field to a complex (built) value.
Definition: stringfields.h:591

References ast_string_field_build_va, and ast_msg::body.

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

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

514{
515 va_list ap;
516
517 va_start(ap, fmt);
518 ast_string_field_build_va(msg, context, fmt, ap);
519 va_end(ap);
520
521 return 0;
522}

References ast_string_field_build_va, and voicemailpwcheck::context.

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

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

547{
548 va_list ap;
549
550 va_start(ap, fmt);
551 ast_string_field_build_va(msg, endpoint, fmt, ap);
552 va_end(ap);
553
554 return 0;
555}

References ast_string_field_build_va, and ast_msg::endpoint.

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

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

525{
526 va_list ap;
527
528 va_start(ap, fmt);
529 ast_string_field_build_va(msg, exten, fmt, ap);
530 va_end(ap);
531
532 return 0;
533}

References ast_string_field_build_va, and ast_msg::exten.

Referenced by AST_TEST_DEFINE(), and rx_data_to_ast_msg().

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

492{
493 va_list ap;
494
495 va_start(ap, fmt);
496 ast_string_field_build_va(msg, from, fmt, ap);
497 va_end(ap);
498
499 return 0;
500}

References ast_string_field_build_va, and ast_msg::from.

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

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

536{
537 va_list ap;
538
539 va_start(ap, fmt);
540 ast_string_field_build_va(msg, tech, fmt, ap);
541 va_end(ap);
542
543 return 0;
544}

References ast_string_field_build_va, and ast_msg::tech.

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

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

481{
482 va_list ap;
483
484 va_start(ap, fmt);
485 ast_string_field_build_va(msg, to, fmt, ap);
486 va_end(ap);
487
488 return 0;
489}

References ast_string_field_build_va, and ast_msg::to.

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

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

642{
643 return msg_set_var_full(msg, name, value, 0);
644}
static int msg_set_var_full(struct ast_msg *msg, const char *name, const char *value, unsigned int outbound)
Definition: main/message.c:606
int value
Definition: syslog.c:37

References msg_data::msg, msg_set_var_full(), name, and value.

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

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

637{
638 return msg_set_var_full(msg, name, value, 1);
639}

References msg_data::msg, msg_set_var_full(), name, and value.

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

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

1610{
1611 const struct ast_msg_tech *match;
1612
1614
1616 if (match) {
1617 ast_log(LOG_ERROR, "Message technology already registered for '%s'\n",
1618 tech->name);
1620 return -1;
1621 }
1622
1623 if (AST_VECTOR_APPEND(&msg_techs, tech)) {
1624 ast_log(LOG_ERROR, "Failed to register message technology for '%s'\n",
1625 tech->name);
1627 return -1;
1628 }
1629 ast_verb(5, "Message technology '%s' registered.\n", tech->name);
1630
1632
1633 return 0;
1634}
struct @376 msg_techs
Vector of message technologies.
const char *const name
Name of this message technology.
Definition: message.h:61

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

Referenced by AST_TEST_DEFINE(), and load_module().

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

1651{
1652 int match;
1653
1658
1659 if (match) {
1660 ast_log(LOG_ERROR, "No '%s' message technology found.\n", tech->name);
1661 return -1;
1662 }
1663
1664 ast_verb(5, "Message technology '%s' unregistered.\n", tech->name);
1665
1666 return 0;
1667}
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.

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(), msg_techs, msg_techs_lock, and ast_msg_tech::name.

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

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

733{
734 if (iter) {
737 ast_free(iter);
738 }
739}
#define ast_free(a)
Definition: astmm.h:180
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: main/message.c:726
struct ao2_iterator iter
Definition: main/message.c:666

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(), and vars_to_headers().

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

671{
673
674 iter = ast_calloc(1, sizeof(*iter));
675 if (!iter) {
676 return NULL;
677 }
678
679 iter->iter = ao2_iterator_init(msg->vars, 0);
680
681 return iter;
682}
#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.

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

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

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

716{
717 return ast_msg_var_iterator_get_next(msg, iter, name, value, 1);
718}
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: main/message.c:684

References ast_msg_var_iterator_get_next(), msg_data::msg, name, and value.

Referenced by AST_TEST_DEFINE(), and vars_to_headers().

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

722{
723 return ast_msg_var_iterator_get_next(msg, iter, name, value, 0);
724}

References ast_msg_var_iterator_get_next(), msg_data::msg, name, and value.

Referenced by msg_to_json().

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

727{
729 iter->current_used = NULL;
730}
#define ao2_cleanup(obj)
Definition: astobj2.h:1934
struct msg_data * current_used
Definition: main/message.c:667

References ao2_cleanup, ast_msg_var_iterator::current_used, and NULL.

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