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
Enhanced Messaging

Data Structures

struct  ast_msg_data_attribute
 

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_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...
 

Detailed Description

Enhanced Messaging

The basic messaging framework has a basic drawback... It can only pass a text string through the core. This causes several issues:

The Enhanced Messaging framework allows attributes, such as "From", "To" and "Content-Type" to be attached to the message by the incoming channel tech which can then be used by the outgoing channel tech to construct the appropriate technology-specific outgoing message.

Enumeration Type Documentation

◆ ast_msg_data_attribute_type

Enumerator
AST_MSG_DATA_ATTR_TO 
AST_MSG_DATA_ATTR_FROM 
AST_MSG_DATA_ATTR_CONTENT_TYPE 
AST_MSG_DATA_ATTR_BODY 
__AST_MSG_DATA_ATTR_LAST 

Definition at line 454 of file message.h.

454 {
460};
@ AST_MSG_DATA_ATTR_BODY
Definition: message.h:458
@ AST_MSG_DATA_ATTR_TO
Definition: message.h:455
@ AST_MSG_DATA_ATTR_FROM
Definition: message.h:456
@ __AST_MSG_DATA_ATTR_LAST
Definition: message.h:459
@ AST_MSG_DATA_ATTR_CONTENT_TYPE
Definition: message.h:457

◆ ast_msg_data_source_type

Enumerator
AST_MSG_DATA_SOURCE_TYPE_UNKNOWN 
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 

Definition at line 446 of file message.h.

446 {
452};
@ __AST_MSG_DATA_SOURCE_TYPE_LAST
Definition: message.h:451
@ AST_MSG_DATA_SOURCE_TYPE_UNKNOWN
Definition: message.h:447
@ AST_MSG_DATA_SOURCE_TYPE_IN_DIALOG
Definition: message.h:449
@ AST_MSG_DATA_SOURCE_TYPE_T140
Definition: message.h:448
@ AST_MSG_DATA_SOURCE_TYPE_OUT_OF_DIALOG
Definition: message.h:450

Function Documentation

◆ ast_msg_data_alloc()

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.

Since
13.22.0
15.5.0
Parameters
sourceThe source type of the message
attributesA pointer to an array of ast_msg_data_attribute structures
countThe number of elements in the array
Returns
Pointer to msg structure or NULL on allocation failure. Caller must call ast_free when done.

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

1460{
1461 struct ast_msg_data *msg;
1462 size_t len = sizeof(*msg);
1463 size_t i;
1464 size_t current_offset = 0;
1465 enum ast_msg_data_attribute_type attr_type;
1466
1467 if (!attributes) {
1468 ast_assert(attributes != NULL);
1469 return NULL;
1470 }
1471
1472 if (!count) {
1473 ast_assert(count > 0);
1474 return NULL;
1475 }
1476
1477 /* Calculate the length required for the buffer */
1478 for (i=0; i < count; i++) {
1479 if (!attributes[i].value) {
1480 ast_assert(attributes[i].value != NULL);
1481 return NULL;
1482 }
1483 len += (strlen(attributes[i].value) + 1);
1484 }
1485
1486 msg = ast_calloc(1, len);
1487 if (!msg) {
1488 return NULL;
1489 }
1490 msg->source = source;
1491 msg->length = len;
1492
1493 /* Mark all of the attributes as unset */
1494 for (attr_type = 0; attr_type < __AST_MSG_DATA_ATTR_LAST; attr_type++) {
1495 msg->attribute_value_offsets[attr_type] = ATTRIBUTE_UNSET;
1496 }
1497
1498 /* Set the ones we have and increment the offset */
1499 for (i=0; i < count; i++) {
1500 len = (strlen(attributes[i].value) + 1);
1501 ast_copy_string(msg->buf + current_offset, attributes[i].value, len); /* Safe */
1502 msg->attribute_value_offsets[attributes[i].type] = current_offset;
1503 current_offset += len;
1504 }
1505
1506 return msg;
1507}
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:202
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
ast_msg_data_attribute_type
Definition: message.h:454
#define ATTRIBUTE_UNSET
#define NULL
Definition: resample.c:96
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:425
enum ast_msg_data_attribute_type type
Definition: message.h:463
Structure used to transport a message through the frame core.
enum ast_msg_data_source_type source
int attribute_value_offsets[__AST_MSG_DATA_ATTR_LAST]
int value
Definition: syslog.c:37
#define ast_assert(a)
Definition: utils.h:739

References __AST_MSG_DATA_ATTR_LAST, ast_assert, ast_calloc, ast_copy_string(), ATTRIBUTE_UNSET, attribute_value_offsets, buf, len(), length, NULL, source, ast_msg_data_attribute::type, ast_msg_data_attribute::value, and value.

Referenced by ast_msg_data_alloc2(), ast_sendtext(), chan_pjsip_sendtext(), incoming_in_dialog_request(), send_message(), and sendtext_exec().

◆ ast_msg_data_alloc2()

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.

Since
13.35.0
16.12.0
17.6.0
Parameters
source_typeThe source type of the message
toWhere the message is sent to
fromWhere the message is sent from
content_typeContent type of the body
bodyThe message body
Returns
Pointer to msg structure or NULL on allocation failure. Caller must call ast_free when done.

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

1511{
1512 struct ast_msg_data_attribute attrs[] =
1513 {
1514 {
1516 .value = (char *)S_OR(to, ""),
1517 },
1518 {
1519 .type = AST_MSG_DATA_ATTR_FROM,
1520 .value = (char *)S_OR(from, ""),
1521 },
1522 {
1524 .value = (char *)S_OR(content_type, ""),
1525 },
1526 {
1527 .type = AST_MSG_DATA_ATTR_BODY,
1528 .value = (char *)S_OR(body, ""),
1529 },
1530 };
1531
1532 return ast_msg_data_alloc(source_type, attrs, ARRAY_LEN(attrs));
1533}
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.
#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
#define ARRAY_LEN(a)
Definition: utils.h:666

References ARRAY_LEN, ast_msg_data_alloc(), AST_MSG_DATA_ATTR_BODY, AST_MSG_DATA_ATTR_CONTENT_TYPE, AST_MSG_DATA_ATTR_FROM, AST_MSG_DATA_ATTR_TO, S_OR, and ast_msg_data_attribute::type.

Referenced by queue_sendtext_data().

◆ ast_msg_data_dup()

struct ast_msg_data * ast_msg_data_dup ( struct ast_msg_data msg)

Clone an ast_msg_data structure.

Since
13.22.0
15.5.0
Parameters
msgThe message to clone
Returns
New message structure or NULL if there was an allocation failure. Caller must call ast_free when done.

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

1536{
1537 struct ast_msg_data *dest;
1538
1539 if (!msg) {
1540 ast_assert(msg != NULL);
1541 return NULL;
1542 }
1543
1544 dest = ast_malloc(msg->length);
1545 if (!dest) {
1546 return NULL;
1547 }
1548 memcpy(dest, msg, msg->length);
1549
1550 return dest;
1551}
#define ast_malloc(len)
A wrapper for malloc()
Definition: astmm.h:191

References ast_assert, ast_malloc, length, and NULL.

Referenced by sendtext_data_create().

◆ ast_msg_data_get_attribute()

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.

Since
13.22.0
15.5.0
Parameters
msgPointer to ast_msg_data structure
attribute_typeOne of ast_msg_data_attribute_type
Returns
The attribute or an empty string ("") if the attribute wasn't set.

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

1575{
1576 if (!msg) {
1577 ast_assert(msg != NULL);
1578 return "";
1579 }
1580
1581 if (msg->attribute_value_offsets[attribute_type] > ATTRIBUTE_UNSET) {
1582 return msg->buf + msg->attribute_value_offsets[attribute_type];
1583 }
1584
1585 return "";
1586}

References ast_assert, ATTRIBUTE_UNSET, attribute_value_offsets, buf, and NULL.

Referenced by ast_bridge_channel_queue_frame(), ast_sendtext_data(), bridge_channel_handle_write(), chan_pjsip_sendtext_data(), incoming_in_dialog_request(), sendtext(), and softmix_bridge_write_text().

◆ ast_msg_data_get_length()

size_t ast_msg_data_get_length ( struct ast_msg_data msg)

Get length of the structure.

Since
13.22.0
15.5.0
Parameters
msgPointer to ast_msg_data structure
Returns
The length of the structure itself plus the dynamically allocated attribute buffer.

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

1554{
1555 if (!msg) {
1556 ast_assert(msg != NULL);
1557 return 0;
1558 }
1559
1560 return msg->length;
1561}

References ast_assert, length, and NULL.

Referenced by queue_sendtext_data(), and send_message().

◆ ast_msg_data_get_source_type()

enum ast_msg_data_source_type ast_msg_data_get_source_type ( struct ast_msg_data msg)

Get "source type" from ast_msg_data.

Since
13.22.0
15.5.0
Parameters
msgPointer to ast_msg_data structure
Returns
The source type field.

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

1564{
1565 if (!msg) {
1566 ast_assert(msg != NULL);
1568 }
1569
1570 return msg->source;
1571}

References ast_assert, AST_MSG_DATA_SOURCE_TYPE_UNKNOWN, NULL, and source.

◆ ast_msg_data_queue_frame()

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.

Since
13.22.0
15.5.0
Parameters
channelThe channel on which to queue the frame
msgPointer to ast_msg_data structure
Return values
-1Error
0Success

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

1589{
1590 struct ast_frame f;
1591
1592 if (!channel) {
1593 ast_assert(channel != NULL);
1594 return -1;
1595 }
1596
1597 if (!msg) {
1598 ast_assert(msg != NULL);
1599 return -1;
1600 }
1601
1602 memset(&f, 0, sizeof(f));
1603 f.frametype = AST_FRAME_TEXT_DATA;
1604 f.data.ptr = msg;
1605 f.datalen = msg->length;
1606 return ast_queue_frame(channel, &f);
1607}
int ast_queue_frame(struct ast_channel *chan, struct ast_frame *f)
Queue one or more frames to a channel's frame queue.
Definition: channel.c:1158
@ AST_FRAME_TEXT_DATA
Data structure associated with a single frame of data.

References ast_assert, AST_FRAME_TEXT_DATA, ast_queue_frame(), ast_frame::data, ast_frame::datalen, ast_frame::frametype, length, NULL, and ast_frame::ptr.

Referenced by incoming_in_dialog_request().