Chapter 5:Message Buffers
5.1 Receive Data Buffer
PJSIP收到的SIP消息将以pjsip_rx_data传递给PJSIP的软件组件,而不是普通消息。这个结构体包含了收到消息的所有信息描述。
收到和传输数据缓冲区的描述在头文件 <pjsip/sip_transport.h>。
5.1.1 Receive Data Buffer Structure
struct pjsip_rx_data
{
// This part contains static info about the buffer.
struct
{
pj_pool_t *pool; // Pool owned by this buffer
pjsip_transport *transport; // The transport that received the msg.
pjsip_rx_data_op_key op_key; // Ioqueue’s operation key
} tp_info;
// This part contains information about the packet
struct
{
pj_time_val timestamp; // Packet arrival time
char packet[PJSIP_MAX_PKT_LEN]; // The packet buffer
pj_uint32_t zero; // Zero padding.
int len; // Packet length
pj_sockaddr addr; // Source address
int addr_len; // Address length.
} pkt_info;
// This part describes the message and message elements after parsing.
struct
{
char *msg_buf; // Pointer to start of msg in the buf.
int len; // Message length.
pjsip_msg *msg; // The parsed message.
// Shortcut to important headers:
pj_str_t call_id; // Call-ID string.
pjsip_from_hdr *from; // From header.
pjsip_to_hdr *to; // To header.
pjsip_via_hdr *via; // First Via header.
pjsip_cseq_hdr *cseq; // CSeq header.
pjsip_max_forwards_hdr *max_fwd; // Max-Forwards header.
pjsip_route_hdr *route; // First Route header.
pjsip_rr_hdr *record_route; // First Record-Route header.
pjsip_ctype_hdr *ctype; // Content-Type header.
pjsip_clen_hdr *clen; // Content-Length header.
pjsip_require_hdr *require; // The first Require header.
pjsip_parser_err_report parse_err; // List of parser errors.
} msg_info;
// This part is updated after the rx_data reaches endpoint.
struct
{
pj_str_t key; // Transaction key.
void *mod_data[PJSIP_MAX_MODULE]; // Module specific data.
} endpt_info;
};
5.2 Transmit Data Buffer (pjsip_tx_data)
当PJSIP应用程序想要发送传出(outgoing)消息时,必须建立一个传输数据缓冲区,提供一个内存池,所有消息相关的字段都必须从这里面分配,传输层处理消息需要的引用计数器,锁保护和其他的消息。
struct pjsip_tx_data
{
/** This is for transmission queue; it's managed by transports. */
PJ_DECL_LIST_MEMBER(struct pjsip_tx_data);
/** Memory pool for this buffer. */
pj_pool_t *pool;
/** A name to identify this buffer. */
char obj_name[PJ_MAX_OBJ_NAME];
/** Time of the rx request; set by pjsip_endpt_create_response(). */
pj_time_val rx_timestamp;
/** The transport manager for this buffer. */
pjsip_tpmgr *mgr;
/** Ioqueue asynchronous operation key. */
pjsip_tx_data_op_key op_key;
/** Lock object. */
pj_lock_t *lock;
/** The message in this buffer. */
pjsip_msg *msg;
/** Contigous buffer containing the packet. */
pjsip_buffer buf;
/** Reference counter. */
pj_atomic_t *ref_cnt;
/** Being processed by transport? */
int is_pending;
/** Transport manager internal. */
void *token;
void (*cb)(void*, pjsip_tx_data*, pj_ssize_t);
/** Transport info, only valid during on_tx_request() and on_tx_response() */
struct {
pjsip_transport *transport; /**< Transport being used. */
pj_sockaddr dst_addr; /**< Destination address. */
int dst_addr_len; /**< Length of address. */
char dst_name[16]; /**< Destination address. */
int dst_port; /**< Destination port. */
} tp_info;
};