Changeset 266


Ignore:
Timestamp:
Mar 2, 2006 9:16:00 PM (18 years ago)
Author:
bennylp
Message:

Changed pjsip_msg_body_clone(), added pjsip_msg_body_create()

Location:
pjproject/trunk/pjsip
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip/include/pjsip/sip_msg.h

    r212 r266  
    611611 * @return              PJ_SUCCESS on success. 
    612612 */ 
    613 PJ_DECL(pj_status_t) pjsip_msg_body_clone(pj_pool_t *pool, 
     613PJ_DECL(pj_status_t) pjsip_msg_body_copy( pj_pool_t *pool, 
    614614                                          pjsip_msg_body *dst_body, 
    615615                                          const pjsip_msg_body *src_body ); 
    616616                                            
     617 
     618/** 
     619 * Create cloned message body. This will duplicate the contents of the message 
     620 * body using the \a clone_data member of the source message body. 
     621 * 
     622 * @param pool          Pool to use to duplicate the message body. 
     623 * @param body          Source message body to duplicate. 
     624 * 
     625 * @return              The cloned message body on successfull. 
     626 */ 
     627PJ_DECL(pjsip_msg_body*) pjsip_msg_body_clone( pj_pool_t *pool, 
     628                                               const pjsip_msg_body *body ); 
     629                                            
     630 
     631/** 
     632 * Create a text message body. Use this function to create message body when 
     633 * the content is a simple text. For non-text message body (e.g.  
     634 * pjmedia_sdp_session or pj_xml_node), application must construct the message 
     635 * manually. 
     636 * 
     637 * @param pool          Pool to allocate message body and its contents. 
     638 * @param type          MIME type (e.g. "text"). 
     639 * @param subtype       MIME subtype (e.g. "plain"). 
     640 * @param text          The text content to be put in the message body. 
     641 * 
     642 * @return              A new message body with the specified Content-Type and 
     643 *                      text. 
     644 */ 
     645PJ_DECL(pjsip_msg_body*) pjsip_msg_body_create( pj_pool_t *pool, 
     646                                                const pj_str_t *type, 
     647                                                const pj_str_t *subtype, 
     648                                                const pj_str_t *text ); 
    617649 
    618650/** 
  • pjproject/trunk/pjsip/src/pjsip/sip_msg.c

    r212 r266  
    17591759} 
    17601760 
    1761 PJ_DEF(pj_status_t) pjsip_msg_body_clone( pj_pool_t *pool, 
    1762                                           pjsip_msg_body *dst_body, 
    1763                                           const pjsip_msg_body *src_body ) 
     1761PJ_DEF(pj_status_t) pjsip_msg_body_copy( pj_pool_t *pool, 
     1762                                         pjsip_msg_body *dst_body, 
     1763                                         const pjsip_msg_body *src_body ) 
    17641764{ 
    17651765    /* First check if clone_data field is initialized. */ 
     
    17881788} 
    17891789 
     1790 
     1791PJ_DEF(pjsip_msg_body*) pjsip_msg_body_clone( pj_pool_t *pool, 
     1792                                              const pjsip_msg_body *body ) 
     1793{ 
     1794    pjsip_msg_body *new_body; 
     1795    pj_status_t status; 
     1796 
     1797    new_body = pj_pool_alloc(pool, sizeof(pjsip_msg_body)); 
     1798    PJ_ASSERT_RETURN(new_body, NULL); 
     1799 
     1800    status = pjsip_msg_body_copy(pool, new_body, body); 
     1801 
     1802    return (status==PJ_SUCCESS) ? new_body : NULL; 
     1803} 
     1804 
     1805 
     1806PJ_DEF(pjsip_msg_body*) pjsip_msg_body_create( pj_pool_t *pool, 
     1807                                               const pj_str_t *type, 
     1808                                               const pj_str_t *subtype, 
     1809                                               const pj_str_t *text ) 
     1810{ 
     1811    pjsip_msg_body *body; 
     1812 
     1813    PJ_ASSERT_RETURN(pool && type && subtype && text, NULL); 
     1814 
     1815    body = pj_pool_zalloc(pool, sizeof(pjsip_msg_body)); 
     1816    PJ_ASSERT_RETURN(body != NULL, NULL); 
     1817 
     1818    pj_strdup(pool, &body->content_type.type, type); 
     1819    pj_strdup(pool, &body->content_type.subtype, subtype); 
     1820    body->content_type.param.slen = 0; 
     1821 
     1822    body->data = pj_pool_alloc(pool, text->slen); 
     1823    pj_memcpy(body->data, text->ptr, text->slen); 
     1824    body->len = text->slen; 
     1825 
     1826    body->clone_data = &pjsip_clone_text_data; 
     1827    body->print_body = &pjsip_print_text_body; 
     1828 
     1829    return body; 
     1830} 
     1831 
  • pjproject/trunk/pjsip/src/pjsip/sip_util.c

    r175 r266  
    12361236    /* Add the message body, if any. */ 
    12371237    if (body) { 
    1238         tdata->msg->body = pj_pool_alloc(tdata->pool, sizeof(pjsip_msg_body)); 
    1239         status = pjsip_msg_body_clone( tdata->pool, tdata->msg->body, body ); 
    1240         if (status != PJ_SUCCESS) { 
     1238        tdata->msg->body = pjsip_msg_body_clone( tdata->pool, body ); 
     1239        if (tdata->msg->body == NULL) { 
    12411240            pjsip_tx_data_dec_ref(tdata); 
    12421241            return status; 
     
    12961295    /* Add the message body, if any. */ 
    12971296    if (body) { 
    1298         tdata->msg->body = pj_pool_alloc(tdata->pool, sizeof(pjsip_msg_body)); 
    1299         status = pjsip_msg_body_clone( tdata->pool, tdata->msg->body, body ); 
    1300         if (status != PJ_SUCCESS) { 
     1297        tdata->msg->body = pjsip_msg_body_clone( tdata->pool, body ); 
     1298        if (tdata->msg->body == NULL) { 
    13011299            pjsip_tx_data_dec_ref(tdata); 
    13021300            return status; 
     
    13181316    if (status != PJ_SUCCESS) { 
    13191317        pjsip_tx_data_dec_ref(tdata); 
    1320     } else { 
     1318    } else if (p_tsx) { 
    13211319        *p_tsx = tsx; 
    13221320    } 
Note: See TracChangeset for help on using the changeset viewer.