Group PJSIP_MSG_BODY

group PJSIP_MSG_BODY

SIP message body structures and manipulation.

Functions

int pjsip_print_text_body(pjsip_msg_body *msg_body, char *buf, pj_size_t size)

General purpose function to textual data in a SIP body. Attach this function in a SIP message body only if the data in pjsip_msg_body is a textual message ready to be embedded in a SIP message. If the data in the message body is not a textual body, then application must supply a custom function to print that body.

Parameters
  • msg_body – The message body.

  • buf – Buffer to copy the message body to.

  • size – The size of the buffer.

Returns

The length copied to the buffer, or -1.

void *pjsip_clone_text_data(pj_pool_t *pool, const void *data, unsigned len)

General purpose function to clone textual data in a SIP body. Attach this function as “clone_data” member of the SIP body only if the data type is a text (i.e. C string, not pj_str_t), and the length indicates the length of the text.

Parameters
  • pool – Pool used to clone the data.

  • data – Textual data.

  • len – The length of the string.

Returns

New text duplicated from the original text.

pj_status_t pjsip_msg_body_copy(pj_pool_t *pool, pjsip_msg_body *dst_body, const pjsip_msg_body *src_body)

Clone the message body in src_body to the dst_body. This will duplicate the contents of the message body using the clone_data member of the source message body.

Parameters
  • pool – Pool to use to duplicate the message body.

  • dst_body – Destination message body.

  • src_body – Source message body to duplicate.

Returns

PJ_SUCCESS on success.

pjsip_msg_body *pjsip_msg_body_clone(pj_pool_t *pool, const pjsip_msg_body *body)

Create cloned message body. This will duplicate the contents of the message body using the clone_data member of the source message body.

Parameters
  • pool – Pool to use to duplicate the message body.

  • body – Source message body to duplicate.

Returns

The cloned message body on successfull.

pjsip_msg_body *pjsip_msg_body_create(pj_pool_t *pool, const pj_str_t *type, const pj_str_t *subtype, const pj_str_t *text)

Create a text message body. Use this function to create message body when the content is a simple text. For non-text message body (e.g. pjmedia_sdp_session or pj_xml_node), application must construct the message manually.

Parameters
  • pool – Pool to allocate message body and its contents.

  • type – MIME type (e.g. “text”).

  • subtype – MIME subtype (e.g. “plain”).

  • text – The text content to be put in the message body.

Returns

A new message body with the specified Content-Type and text.

struct pjsip_msg_body
#include <sip_msg.h>

Generic abstraction to message body. When an incoming message is parsed (pjsip_parse_msg()), the parser fills in all members with the appropriate value. The ‘data’ and ‘len’ member will describe portion of incoming packet which denotes the message body. When application needs to attach message body to outgoing SIP message, it must fill in all members of this structure.

Forward declaration for message body (sip_msg.h).