Asterisk - The Open Source Telephony Project
21.4.1
|
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_msg * | ast_msg_alloc (void) |
Allocate a message. More... | |
struct ast_msg_data * | ast_msg_data_alloc (enum ast_msg_data_source_type source, struct ast_msg_data_attribute attributes[], size_t count) |
Allocates an ast_msg_data structure. More... | |
struct ast_msg_data * | ast_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_data * | ast_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_msg * | ast_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_msg * | ast_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_iterator * | ast_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_frame * | chan_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_channel * | create_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_data * | msg_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_data * | msg_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_datastore * | msg_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_tech * | msg_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_handler * | msg_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_taskprocessor * | msg_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. | |
Out-of-call text message support.
Definition in file main/message.c.
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.
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().
Destroy an ast_msg.
This should only be called on a message if it was not passed on to ast_msg_queue().
NULL | always. |
Definition at line 462 of file main/message.c.
References ao2_ref.
Referenced by xmpp_pak_message().
const char* ast_msg_get_body | ( | const struct ast_msg * | msg | ) |
Get the body of a message.
Definition at line 545 of file main/message.c.
References ast_msg::body.
const char* ast_msg_get_endpoint | ( | const struct ast_msg * | msg | ) |
Retrieve the endpoint associated with this message.
msg | The message to get the endpoint from |
NULL | or empty string if the message has no associated endpoint |
Definition at line 565 of file main/message.c.
References ast_msg::endpoint.
const char* ast_msg_get_from | ( | const struct ast_msg * | msg | ) |
Retrieve the source of this message.
msg | The message to get the soure from |
NULL | or empty string if the message has no source |
Definition at line 550 of file main/message.c.
References ast_msg::from.
const char* ast_msg_get_tech | ( | const struct ast_msg * | msg | ) |
Retrieve the technology associated with this message.
msg | The message to get the technology from |
NULL | or empty string if the message has no associated technology |
Definition at line 560 of file main/message.c.
References ast_msg::tech.
const char* ast_msg_get_to | ( | const struct ast_msg * | msg | ) |
Retrieve the destination of this message.
msg | The message to get the destination from |
NULL | or empty string if the message has no destination |
Definition at line 555 of file main/message.c.
References ast_msg::to.
const char* ast_msg_get_var | ( | struct ast_msg * | msg, |
const char * | name | ||
) |
Get the specified variable on the message.
Definition at line 634 of file main/message.c.
References ao2_ref, and ast_msg::vars.
int ast_msg_handler_register | ( | const struct ast_msg_handler * | handler | ) |
Register a ast_msg_handler
.
handler | The handler to register |
0 | Success |
non-zero | Error |
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().
int ast_msg_handler_unregister | ( | const struct ast_msg_handler * | handler | ) |
Unregister a ast_msg_handler
.
handler | The handler to unregister |
0 | Success |
non-zero | Error |
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().
int ast_msg_has_destination | ( | const struct ast_msg * | msg | ) |
Determine if a particular message has a destination via some handler.
msg | The message to check |
0 | if the message has no handler that can find a destination |
1 | if 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.
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.
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.
0 | message successfully queued |
non-zero | failure, 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().
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.
0 | message successfully queued to be sent out |
non-zero | failure, 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.
int ast_msg_set_body | ( | struct ast_msg * | msg, |
const char * | fmt, | ||
... | |||
) |
Set the 'body' text of a message (in UTF-8)
0 | success |
-1 | failure |
Definition at line 490 of file main/message.c.
References ast_string_field_build_va, and ast_msg::body.
Referenced by xmpp_pak_message().
int ast_msg_set_context | ( | struct ast_msg * | msg, |
const char * | fmt, | ||
... | |||
) |
Set the dialplan context for this message.
0 | success |
-1 | failure |
Definition at line 501 of file main/message.c.
References ast_string_field_build_va, and ast_msg::context.
Referenced by xmpp_pak_message().
int ast_msg_set_endpoint | ( | struct ast_msg * | msg, |
const char * | fmt, | ||
... | |||
) |
Set the technology's endpoint associated with this message.
0 | success |
-1 | failure |
Definition at line 534 of file main/message.c.
References ast_string_field_build_va, and ast_msg::endpoint.
Referenced by xmpp_pak_message().
int ast_msg_set_exten | ( | struct ast_msg * | msg, |
const char * | fmt, | ||
... | |||
) |
Set the dialplan extension for this message.
0 | success |
-1 | failure |
Definition at line 512 of file main/message.c.
References ast_string_field_build_va, and ast_msg::exten.
int ast_msg_set_from | ( | struct ast_msg * | msg, |
const char * | fmt, | ||
... | |||
) |
Set the 'from' URI of a message.
0 | success |
-1 | failure |
Definition at line 479 of file main/message.c.
References ast_string_field_build_va, and ast_msg::from.
Referenced by xmpp_pak_message().
int ast_msg_set_tech | ( | struct ast_msg * | msg, |
const char * | fmt, | ||
... | |||
) |
Set the technology associated with this message.
0 | success |
-1 | failure |
Definition at line 523 of file main/message.c.
References ast_string_field_build_va, and ast_msg::tech.
Referenced by xmpp_pak_message().
int ast_msg_set_to | ( | struct ast_msg * | msg, |
const char * | fmt, | ||
... | |||
) |
Set the 'to' URI of a message.
0 | success |
-1 | failure |
Definition at line 468 of file main/message.c.
References ast_string_field_build_va, and ast_msg::to.
Referenced by xmpp_pak_message().
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.
msg | |
name | Name of variable to set |
value | Value of variable to set |
0 | success |
-1 | failure |
Definition at line 629 of file main/message.c.
Referenced by xmpp_pak_message().
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.
msg | |
name | Name of variable to set |
value | Value of variable to set |
0 | success |
-1 | failure |
Definition at line 624 of file main/message.c.
void ast_msg_shutdown | ( | void | ) |
Provided by message.c
Definition at line 1717 of file main/message.c.
References ast_taskprocessor_unreference().
int ast_msg_tech_register | ( | const struct ast_msg_tech * | tech | ) |
Register a message technology.
0 | success |
non-zero | failure |
Definition at line 1597 of file main/message.c.
References AST_VECTOR_APPEND, msg_techs, and ast_msg_tech::name.
Referenced by load_module().
int ast_msg_tech_unregister | ( | const struct ast_msg_tech * | tech | ) |
Unregister a message technology.
0 | success |
non-zero | failure |
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.
void ast_msg_var_iterator_destroy | ( | struct ast_msg_var_iterator * | iter | ) |
Destroy a message variable iterator.
iter | Iterator to be destroyed |
Definition at line 720 of file main/message.c.
References ao2_iterator_destroy(), and ast_msg_var_unref_current().
struct ast_msg_var_iterator* ast_msg_var_iterator_init | ( | const struct ast_msg * | msg | ) |
Create a new message variable iterator.
msg | A message whose variables are to be iterated over |
Definition at line 658 of file main/message.c.
References ao2_iterator_init(), ast_calloc, and ast_msg::vars.
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.
msg | The message with the variables |
iter | An iterator created with ast_msg_var_iterator_init |
name | A pointer to the name result pointer |
value | A pointer to the value result pointer |
0 | No more entries |
1 | Valid entry |
Definition at line 703 of file main/message.c.
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.
msg | The message with the variables |
iter | An iterator created with ast_msg_var_iterator_init |
name | A pointer to the name result pointer |
value | A pointer to the value result pointer |
0 | No more entries |
1 | Valid entry |
Definition at line 708 of file main/message.c.
|
static |
Comparison callback for ast_msg_handler
vector removal.
vec_elem | The element in the vector being compared |
srch | The element being looked up |
non-zero | The items are equal |
0 | The items are not equal |
Definition at line 1694 of file main/message.c.
References ast_msg_handler::name.
Referenced by ast_msg_handler_unregister().
|
static |
Comparison callback for ast_msg_tech
vector removal.
vec_elem | The element in the vector being compared |
srch | The element being looked up |
non-zero | The items are equal |
0 | The items are not equal |
Definition at line 1633 of file main/message.c.
References ast_msg_tech::name.
Referenced by ast_msg_tech_unregister().
|
static |
Definition at line 906 of file main/message.c.
|
static |
Definition at line 307 of file main/message.c.
|
static |
Definition at line 286 of file main/message.c.
|
static |
Definition at line 296 of file main/message.c.