Ignore:
Timestamp:
Jan 5, 2006 11:35:46 PM (18 years ago)
Author:
bennylp
Message:

Added loop transport to test transaction

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip/src/pjsip/sip_msg.c

    r106 r107  
    2020#include <pjsip/sip_parser.h> 
    2121#include <pjsip/print_util.h> 
     22#include <pjsip/sip_errno.h> 
    2223#include <pj/string.h> 
    2324#include <pj/pool.h> 
     
    366367    /* Process message body. */ 
    367368    if (msg->body) { 
    368         pj_str_t ctype_hdr = { "Content-Type: ", 14}; 
    369         int len; 
    370         const pjsip_media_type *media = &msg->body->content_type; 
    371         char *clen_pos; 
    372  
    373         /* Add Content-Type header. */ 
    374         if ( (end-p) < 24+media->type.slen+media->subtype.slen+media->param.slen) { 
    375             return -1; 
     369        char *clen_pos = NULL; 
     370 
     371        /* Automaticly adds Content-Type and Content-Length headers, only 
     372         * if content_type is set in the message body. 
     373         */ 
     374        if (msg->body->content_type.type.slen) { 
     375            pj_str_t ctype_hdr = { "Content-Type: ", 14}; 
     376            const pjsip_media_type *media = &msg->body->content_type; 
     377 
     378            /* Add Content-Type header. */ 
     379            if ( (end-p) < 24 + media->type.slen + media->subtype.slen +  
     380                           media->param.slen)  
     381            { 
     382                return -1; 
     383            } 
     384            pj_memcpy(p, ctype_hdr.ptr, ctype_hdr.slen); 
     385            p += ctype_hdr.slen; 
     386            p += print_media_type(p, media); 
     387            *p++ = '\r'; 
     388            *p++ = '\n'; 
     389 
     390            /* Add Content-Length header. */ 
     391            if ((end-p) < clen_hdr.slen + 12 + 2) { 
     392                return -1; 
     393            } 
     394            pj_memcpy(p, clen_hdr.ptr, clen_hdr.slen); 
     395            p += clen_hdr.slen; 
     396             
     397            /* Print blanks after "Content-Type:", this is where we'll put 
     398             * the content length value after we know the length of the 
     399             * body. 
     400             */ 
     401            pj_memset(p, ' ', 12); 
     402            clen_pos = p; 
     403            p += 12; 
     404            *p++ = '\r'; 
     405            *p++ = '\n'; 
    376406        } 
    377         pj_memcpy(p, ctype_hdr.ptr, ctype_hdr.slen); 
    378         p += ctype_hdr.slen; 
    379         p += print_media_type(p, media); 
    380         *p++ = '\r'; 
    381         *p++ = '\n'; 
    382  
    383         /* Add Content-Length header. */ 
    384         if ((end-p) < clen_hdr.slen+12+2) { 
    385             return -1; 
    386         } 
    387         pj_memcpy(p, clen_hdr.ptr, clen_hdr.slen); 
    388         p += clen_hdr.slen; 
    389          
    390         /* Print blanks after "Content-Type:", this is where we'll put 
    391          * the content length value after we know the length of the 
    392          * body. 
    393          */ 
    394         pj_memset(p, ' ', 12); 
    395         clen_pos = p; 
    396         p += 12; 
    397         *p++ = '\r'; 
    398         *p++ = '\n'; 
    399407         
    400408        /* Add blank newline. */ 
     
    412420         * Content-Length header. 
    413421         */ 
    414         len = pj_utoa(len, clen_pos); 
    415         clen_pos[len] = ' '; 
     422        if (clen_pos) { 
     423            len = pj_utoa(len, clen_pos); 
     424            clen_pos[len] = ' '; 
     425        } 
    416426 
    417427    } else { 
     
    14651475/////////////////////////////////////////////////////////////////////////////// 
    14661476/* 
    1467  * General purpose function to textual data in a SIP body.  
     1477 * Message body manipulations. 
    14681478 */ 
    14691479PJ_DEF(int) pjsip_print_text_body(pjsip_msg_body *msg_body, char *buf, pj_size_t size) 
     
    14741484    return msg_body->len; 
    14751485} 
     1486 
     1487PJ_DEF(pj_status_t) pjsip_msg_body_clone( pj_pool_t *pool, 
     1488                                          pjsip_msg_body *dst_body, 
     1489                                          const pjsip_msg_body *src_body ) 
     1490{ 
     1491    /* First check if clone_data field is initialized. */ 
     1492    PJ_ASSERT_RETURN( src_body->clone_data!=NULL, PJ_EINVAL ); 
     1493 
     1494    /* Duplicate content-type */ 
     1495    pj_strdup(pool, &dst_body->content_type.type,  
     1496                    &src_body->content_type.type); 
     1497    pj_strdup(pool, &dst_body->content_type.subtype,  
     1498                    &src_body->content_type.subtype); 
     1499    pj_strdup(pool, &dst_body->content_type.param, 
     1500                    &src_body->content_type.param); 
     1501 
     1502    /* Duplicate data. */ 
     1503    dst_body->data = (*src_body->clone_data)(pool, src_body->data,  
     1504                                             src_body->len ); 
     1505 
     1506    /* Length. */ 
     1507    dst_body->len = src_body->len; 
     1508 
     1509    /* Function pointers. */ 
     1510    dst_body->print_body = src_body->print_body; 
     1511    dst_body->clone_data = src_body->clone_data; 
     1512 
     1513    return PJ_SUCCESS; 
     1514} 
     1515 
Note: See TracChangeset for help on using the changeset viewer.