Ignore:
Timestamp:
Aug 1, 2010 9:24:58 AM (14 years ago)
Author:
bennylp
Message:

Re #1070 (support for multipart bodies): modified the param field of pjsip_media_type from a simple string to pjsip_param, to support a more complex use of this field

File:
1 edited

Legend:

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

    r2968 r3241  
    2323#include <pjsip/sip_errno.h> 
    2424#include <pj/ctype.h> 
     25#include <pj/guid.h> 
    2526#include <pj/string.h> 
    2627#include <pj/pool.h> 
     
    146147 
    147148static pj_str_t status_phrase[710]; 
    148 static int print_media_type(char *buf, const pjsip_media_type *media); 
     149static int print_media_type(char *buf, unsigned len, 
     150                            const pjsip_media_type *media); 
    149151 
    150152static int init_status_phrase() 
     
    490492 
    491493            /* Add Content-Type header. */ 
    492             if ( (end-p) < 24 + media->type.slen + media->subtype.slen +  
    493                            media->param.slen)  
    494             { 
     494            if ( (end-p) < 24 + media->type.slen + media->subtype.slen) { 
    495495                return -1; 
    496496            } 
    497497            pj_memcpy(p, ctype_hdr.ptr, ctype_hdr.slen); 
    498498            p += ctype_hdr.slen; 
    499             p += print_media_type(p, media); 
     499            p += print_media_type(p, end-p, media); 
    500500            *p++ = '\r'; 
    501501            *p++ = '\n'; 
     
    603603 * Media type 
    604604 */ 
     605/* 
     606 * Init media type. 
     607 */ 
     608PJ_DEF(void) pjsip_media_type_init( pjsip_media_type *mt, 
     609                                    pj_str_t *type, 
     610                                    pj_str_t *subtype) 
     611{ 
     612    pj_bzero(mt, sizeof(*mt)); 
     613    pj_list_init(&mt->param); 
     614    if (type) 
     615        mt->type = *type; 
     616    if (subtype) 
     617        mt->subtype = *subtype; 
     618} 
     619 
     620PJ_DEF(void) pjsip_media_type_init2( pjsip_media_type *mt, 
     621                                     char *type, 
     622                                     char *subtype) 
     623{ 
     624    pj_str_t s_type, s_subtype; 
     625 
     626    if (type) { 
     627        s_type = pj_str(type); 
     628    } else { 
     629        s_type.ptr = NULL; 
     630        s_type.slen = 0; 
     631    } 
     632 
     633    if (subtype) { 
     634        s_subtype = pj_str(subtype); 
     635    } else { 
     636        s_subtype.ptr = NULL; 
     637        s_subtype.slen = 0; 
     638    } 
     639 
     640    pjsip_media_type_init(mt, &s_type, &s_subtype); 
     641} 
     642 
     643/* 
     644 * Compare two media types. 
     645 */ 
     646PJ_DEF(int) pjsip_media_type_cmp( const pjsip_media_type *mt1, 
     647                                  const pjsip_media_type *mt2) 
     648{ 
     649    int rc; 
     650 
     651    PJ_ASSERT_RETURN(mt1 && mt2, 1); 
     652 
     653    rc = pj_stricmp(&mt1->type, &mt2->type); 
     654    if (rc) return rc; 
     655 
     656    rc = pj_stricmp(&mt1->subtype, &mt2->subtype); 
     657    if (rc) return rc; 
     658 
     659    rc = pjsip_param_cmp(&mt1->param, &mt2->param, 0); 
     660 
     661    return rc; 
     662} 
     663 
    605664PJ_DEF(void) pjsip_media_type_cp( pj_pool_t *pool, 
    606665                                  pjsip_media_type *dst, 
     
    610669    pj_strdup(pool, &dst->type,    &src->type); 
    611670    pj_strdup(pool, &dst->subtype, &src->subtype); 
    612     pj_strdup(pool, &dst->param,  &src->param); 
     671    pjsip_param_clone(pool, &dst->param, &src->param); 
    613672} 
    614673 
     
    12641323    pj_bzero(mem, sizeof(pjsip_ctype_hdr)); 
    12651324    init_hdr(hdr, PJSIP_H_CONTENT_TYPE, &ctype_hdr_vptr); 
     1325    pj_list_init(&hdr->media.param); 
    12661326    return hdr; 
    12671327 
     
    12741334} 
    12751335 
    1276 static int print_media_type(char *buf, const pjsip_media_type *media) 
     1336static int print_media_type(char *buf, unsigned len, 
     1337                            const pjsip_media_type *media) 
    12771338{ 
    12781339    char *p = buf; 
     1340    pj_ssize_t printed; 
     1341    const pjsip_parser_const_t *pc; 
    12791342 
    12801343    pj_memcpy(p, media->type.ptr, media->type.slen); 
     
    12841347    p += media->subtype.slen; 
    12851348 
    1286     if (media->param.slen) { 
    1287         pj_memcpy(p, media->param.ptr, media->param.slen); 
    1288         p += media->param.slen; 
    1289     } 
     1349    pc = pjsip_parser_const(); 
     1350    printed = pjsip_param_print_on(&media->param, p, buf+len-p, 
     1351                                   &pc->pjsip_TOKEN_SPEC, 
     1352                                   &pc->pjsip_TOKEN_SPEC, ';'); 
     1353    if (printed < 0) 
     1354        return -1; 
     1355 
     1356    p += printed; 
    12901357 
    12911358    return p-buf; 
     1359} 
     1360 
     1361 
     1362PJ_DEF(int) pjsip_media_type_print(char *buf, unsigned len, 
     1363                                   const pjsip_media_type *media) 
     1364{ 
     1365    return print_media_type(buf, len, media); 
    12921366} 
    12931367 
     
    13001374 
    13011375    if ((pj_ssize_t)size < hname->slen +  
    1302                            hdr->media.type.slen + hdr->media.subtype.slen +  
    1303                            hdr->media.param.slen + 8) 
     1376                           hdr->media.type.slen + hdr->media.subtype.slen + 8) 
    13041377    { 
    13051378        return -1; 
     
    13111384    *p++ = ' '; 
    13121385 
    1313     len = print_media_type(p, &hdr->media); 
     1386    len = print_media_type(p, buf+size-p, &hdr->media); 
    13141387    p += len; 
    13151388 
     
    13241397    pj_strdup(pool, &hdr->media.type, &rhs->media.type); 
    13251398    pj_strdup(pool, &hdr->media.subtype, &rhs->media.subtype); 
    1326     pj_strdup(pool, &hdr->media.param, &rhs->media.param); 
     1399    pjsip_param_clone(pool, &hdr->media.param, &rhs->media.param); 
    13271400    return hdr; 
    13281401} 
     
    20792152 
    20802153    /* Duplicate content-type */ 
    2081     pj_strdup(pool, &dst_body->content_type.type,  
    2082                     &src_body->content_type.type); 
    2083     pj_strdup(pool, &dst_body->content_type.subtype,  
    2084                     &src_body->content_type.subtype); 
    2085     pj_strdup(pool, &dst_body->content_type.param, 
    2086                     &src_body->content_type.param); 
     2154    pjsip_media_type_cp(pool, &dst_body->content_type, 
     2155                        &src_body->content_type); 
    20872156 
    20882157    /* Duplicate data. */ 
     
    21302199    pj_strdup(pool, &body->content_type.type, type); 
    21312200    pj_strdup(pool, &body->content_type.subtype, subtype); 
    2132     body->content_type.param.slen = 0; 
     2201    pj_list_init(&body->content_type.param); 
    21332202 
    21342203    body->data = pj_pool_alloc(pool, text->slen); 
Note: See TracChangeset for help on using the changeset viewer.