summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenny Prijono <bennylp@teluu.com>2006-03-02 21:16:00 +0000
committerBenny Prijono <bennylp@teluu.com>2006-03-02 21:16:00 +0000
commitd4f5064c25f3000771921ffc18ceab3810c3d9d2 (patch)
treefbf6cbfe2d4f2b40cba2893c818e9652b2a119a7
parent9c6c63de6a5564b32ee1239bb77ef605c8a69837 (diff)
Changed pjsip_msg_body_clone(), added pjsip_msg_body_create()
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@266 74dad513-b988-da41-8d7b-12977e46ad98
-rw-r--r--pjsip/include/pjsip/sip_msg.h34
-rw-r--r--pjsip/src/pjsip/sip_msg.c48
-rw-r--r--pjsip/src/pjsip/sip_util.c12
3 files changed, 83 insertions, 11 deletions
diff --git a/pjsip/include/pjsip/sip_msg.h b/pjsip/include/pjsip/sip_msg.h
index f4649d9e..df764152 100644
--- a/pjsip/include/pjsip/sip_msg.h
+++ b/pjsip/include/pjsip/sip_msg.h
@@ -610,12 +610,44 @@ PJ_DECL(void*) pjsip_clone_text_data( pj_pool_t *pool, const void *data,
*
* @return PJ_SUCCESS on success.
*/
-PJ_DECL(pj_status_t) pjsip_msg_body_clone(pj_pool_t *pool,
+PJ_DECL(pj_status_t) pjsip_msg_body_copy( pj_pool_t *pool,
pjsip_msg_body *dst_body,
const pjsip_msg_body *src_body );
/**
+ * Create cloned message body. This will duplicate the contents of the message
+ * body using the \a clone_data member of the source message body.
+ *
+ * @param pool Pool to use to duplicate the message body.
+ * @param body Source message body to duplicate.
+ *
+ * @return The cloned message body on successfull.
+ */
+PJ_DECL(pjsip_msg_body*) pjsip_msg_body_clone( pj_pool_t *pool,
+ const pjsip_msg_body *body );
+
+
+/**
+ * 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.
+ *
+ * @param pool Pool to allocate message body and its contents.
+ * @param type MIME type (e.g. "text").
+ * @param subtype MIME subtype (e.g. "plain").
+ * @param text The text content to be put in the message body.
+ *
+ * @return A new message body with the specified Content-Type and
+ * text.
+ */
+PJ_DECL(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 );
+
+/**
* @}
*/
diff --git a/pjsip/src/pjsip/sip_msg.c b/pjsip/src/pjsip/sip_msg.c
index e1ce1fb6..0a6b2f41 100644
--- a/pjsip/src/pjsip/sip_msg.c
+++ b/pjsip/src/pjsip/sip_msg.c
@@ -1758,9 +1758,9 @@ PJ_DEF(void*) pjsip_clone_text_data( pj_pool_t *pool, const void *data,
return newdata;
}
-PJ_DEF(pj_status_t) pjsip_msg_body_clone( pj_pool_t *pool,
- pjsip_msg_body *dst_body,
- const pjsip_msg_body *src_body )
+PJ_DEF(pj_status_t) pjsip_msg_body_copy( pj_pool_t *pool,
+ pjsip_msg_body *dst_body,
+ const pjsip_msg_body *src_body )
{
/* First check if clone_data field is initialized. */
PJ_ASSERT_RETURN( src_body->clone_data!=NULL, PJ_EINVAL );
@@ -1787,3 +1787,45 @@ PJ_DEF(pj_status_t) pjsip_msg_body_clone( pj_pool_t *pool,
return PJ_SUCCESS;
}
+
+PJ_DEF(pjsip_msg_body*) pjsip_msg_body_clone( pj_pool_t *pool,
+ const pjsip_msg_body *body )
+{
+ pjsip_msg_body *new_body;
+ pj_status_t status;
+
+ new_body = pj_pool_alloc(pool, sizeof(pjsip_msg_body));
+ PJ_ASSERT_RETURN(new_body, NULL);
+
+ status = pjsip_msg_body_copy(pool, new_body, body);
+
+ return (status==PJ_SUCCESS) ? new_body : NULL;
+}
+
+
+PJ_DEF(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 )
+{
+ pjsip_msg_body *body;
+
+ PJ_ASSERT_RETURN(pool && type && subtype && text, NULL);
+
+ body = pj_pool_zalloc(pool, sizeof(pjsip_msg_body));
+ PJ_ASSERT_RETURN(body != NULL, NULL);
+
+ pj_strdup(pool, &body->content_type.type, type);
+ pj_strdup(pool, &body->content_type.subtype, subtype);
+ body->content_type.param.slen = 0;
+
+ body->data = pj_pool_alloc(pool, text->slen);
+ pj_memcpy(body->data, text->ptr, text->slen);
+ body->len = text->slen;
+
+ body->clone_data = &pjsip_clone_text_data;
+ body->print_body = &pjsip_print_text_body;
+
+ return body;
+}
+
diff --git a/pjsip/src/pjsip/sip_util.c b/pjsip/src/pjsip/sip_util.c
index bb928b73..60f48681 100644
--- a/pjsip/src/pjsip/sip_util.c
+++ b/pjsip/src/pjsip/sip_util.c
@@ -1235,9 +1235,8 @@ PJ_DEF(pj_status_t) pjsip_endpt_respond_stateless( pjsip_endpoint *endpt,
/* Add the message body, if any. */
if (body) {
- tdata->msg->body = pj_pool_alloc(tdata->pool, sizeof(pjsip_msg_body));
- status = pjsip_msg_body_clone( tdata->pool, tdata->msg->body, body );
- if (status != PJ_SUCCESS) {
+ tdata->msg->body = pjsip_msg_body_clone( tdata->pool, body );
+ if (tdata->msg->body == NULL) {
pjsip_tx_data_dec_ref(tdata);
return status;
}
@@ -1295,9 +1294,8 @@ PJ_DEF(pj_status_t) pjsip_endpt_respond( pjsip_endpoint *endpt,
/* Add the message body, if any. */
if (body) {
- tdata->msg->body = pj_pool_alloc(tdata->pool, sizeof(pjsip_msg_body));
- status = pjsip_msg_body_clone( tdata->pool, tdata->msg->body, body );
- if (status != PJ_SUCCESS) {
+ tdata->msg->body = pjsip_msg_body_clone( tdata->pool, body );
+ if (tdata->msg->body == NULL) {
pjsip_tx_data_dec_ref(tdata);
return status;
}
@@ -1317,7 +1315,7 @@ PJ_DEF(pj_status_t) pjsip_endpt_respond( pjsip_endpoint *endpt,
status = pjsip_tsx_send_msg(tsx, tdata);
if (status != PJ_SUCCESS) {
pjsip_tx_data_dec_ref(tdata);
- } else {
+ } else if (p_tsx) {
*p_tsx = tsx;
}