Changeset 3241 for pjproject/trunk/pjsip/src/pjsip/sip_msg.c
- Timestamp:
- Aug 1, 2010 9:24:58 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip/src/pjsip/sip_msg.c
r2968 r3241 23 23 #include <pjsip/sip_errno.h> 24 24 #include <pj/ctype.h> 25 #include <pj/guid.h> 25 26 #include <pj/string.h> 26 27 #include <pj/pool.h> … … 146 147 147 148 static pj_str_t status_phrase[710]; 148 static int print_media_type(char *buf, const pjsip_media_type *media); 149 static int print_media_type(char *buf, unsigned len, 150 const pjsip_media_type *media); 149 151 150 152 static int init_status_phrase() … … 490 492 491 493 /* 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) { 495 495 return -1; 496 496 } 497 497 pj_memcpy(p, ctype_hdr.ptr, ctype_hdr.slen); 498 498 p += ctype_hdr.slen; 499 p += print_media_type(p, media);499 p += print_media_type(p, end-p, media); 500 500 *p++ = '\r'; 501 501 *p++ = '\n'; … … 603 603 * Media type 604 604 */ 605 /* 606 * Init media type. 607 */ 608 PJ_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 620 PJ_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 */ 646 PJ_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 605 664 PJ_DEF(void) pjsip_media_type_cp( pj_pool_t *pool, 606 665 pjsip_media_type *dst, … … 610 669 pj_strdup(pool, &dst->type, &src->type); 611 670 pj_strdup(pool, &dst->subtype, &src->subtype); 612 pj _strdup(pool, &dst->param,&src->param);671 pjsip_param_clone(pool, &dst->param, &src->param); 613 672 } 614 673 … … 1264 1323 pj_bzero(mem, sizeof(pjsip_ctype_hdr)); 1265 1324 init_hdr(hdr, PJSIP_H_CONTENT_TYPE, &ctype_hdr_vptr); 1325 pj_list_init(&hdr->media.param); 1266 1326 return hdr; 1267 1327 … … 1274 1334 } 1275 1335 1276 static int print_media_type(char *buf, const pjsip_media_type *media) 1336 static int print_media_type(char *buf, unsigned len, 1337 const pjsip_media_type *media) 1277 1338 { 1278 1339 char *p = buf; 1340 pj_ssize_t printed; 1341 const pjsip_parser_const_t *pc; 1279 1342 1280 1343 pj_memcpy(p, media->type.ptr, media->type.slen); … … 1284 1347 p += media->subtype.slen; 1285 1348 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; 1290 1357 1291 1358 return p-buf; 1359 } 1360 1361 1362 PJ_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); 1292 1366 } 1293 1367 … … 1300 1374 1301 1375 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) 1304 1377 { 1305 1378 return -1; … … 1311 1384 *p++ = ' '; 1312 1385 1313 len = print_media_type(p, &hdr->media);1386 len = print_media_type(p, buf+size-p, &hdr->media); 1314 1387 p += len; 1315 1388 … … 1324 1397 pj_strdup(pool, &hdr->media.type, &rhs->media.type); 1325 1398 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); 1327 1400 return hdr; 1328 1401 } … … 2079 2152 2080 2153 /* 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); 2087 2156 2088 2157 /* Duplicate data. */ … … 2130 2199 pj_strdup(pool, &body->content_type.type, type); 2131 2200 pj_strdup(pool, &body->content_type.subtype, subtype); 2132 body->content_type.param.slen = 0;2201 pj_list_init(&body->content_type.param); 2133 2202 2134 2203 body->data = pj_pool_alloc(pool, text->slen);
Note: See TracChangeset
for help on using the changeset viewer.