Changeset 3241 for pjproject/trunk
- Timestamp:
- Aug 1, 2010 9:24:58 AM (14 years ago)
- Location:
- pjproject/trunk/pjsip
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip/include/pjsip/sip_msg.h
r3233 r3241 516 516 pj_str_t type; /**< Media type. */ 517 517 pj_str_t subtype; /**< Media subtype. */ 518 pj _str_t param; /**< Media type parameters (concatenated).*/518 pjsip_param param; /**< Media type parameters */ 519 519 } pjsip_media_type; 520 520 521 522 /** 523 * Initialize the media type with the specified type and subtype string. 524 * 525 * @param mt The media type. 526 * @param type Optionally specify the media type. 527 * @param subtype Optionally specify the media subtype. 528 */ 529 PJ_DECL(void) pjsip_media_type_init(pjsip_media_type *mt, 530 pj_str_t *type, 531 pj_str_t *subtype); 532 533 /** 534 * Initialize the media type with the specified type and subtype string. 535 * 536 * @param mt The media type. 537 * @param type Optionally specify the media type. 538 * @param subtype Optionally specify the media subtype. 539 */ 540 PJ_DECL(void) pjsip_media_type_init2(pjsip_media_type *mt, 541 char *type, 542 char *subtype); 543 544 /** 545 * Compare two media types. 546 * 547 * @param mt1 The first media type. 548 * @param mt2 The second media type. 549 * 550 * @return Zero if both media types are equal, -1 if mt1 < mt2, 551 * 1 if mt1 > mt2. 552 */ 553 PJ_DECL(int) pjsip_media_type_cmp(const pjsip_media_type *mt1, 554 const pjsip_media_type *mt2); 521 555 522 556 /** … … 530 564 pjsip_media_type *dst, 531 565 const pjsip_media_type *src); 566 567 /** 568 * Print media type to the specified buffer. 569 * 570 * @param buf Destination buffer. 571 * @param len Length of the buffer. 572 * @param mt The media type to be printed. 573 * 574 * @return The number of characters printed to the buffer, or -1 575 * if there's not enough space in the buffer. 576 */ 577 PJ_DECL(int) pjsip_media_type_print(char *buf, unsigned len, 578 const pjsip_media_type *mt); 532 579 533 580 /** -
pjproject/trunk/pjsip/src/pjsip-ua/sip_xfer.c
r2750 r3241 375 375 pjsip_tx_data *tdata; 376 376 pjsip_xfer *xfer; 377 pjsip_param *param; 377 378 const pj_str_t reason = { "noresource", 10 }; 378 379 char *body; … … 423 424 /* Create SIP message body. */ 424 425 msg_body = PJ_POOL_ZALLOC_T(tdata->pool, pjsip_msg_body); 425 msg_body->content_type.type = STR_MESSAGE; 426 msg_body->content_type.subtype = STR_SIPFRAG; 427 msg_body->content_type.param = STR_SIPFRAG_VERSION; 426 pjsip_media_type_init(&msg_body->content_type, (pj_str_t*)&STR_MESSAGE, 427 (pj_str_t*)&STR_SIPFRAG); 428 428 msg_body->data = body; 429 429 msg_body->len = bodylen; 430 430 msg_body->print_body = &pjsip_print_text_body; 431 431 msg_body->clone_data = &pjsip_clone_text_data; 432 433 param = PJ_POOL_ALLOC_T(tdata->pool, pjsip_param); 434 param->name = pj_str("version"); 435 param->value = pj_str("2.0"); 436 pj_list_push_back(&msg_body->content_type.param, param); 432 437 433 438 /* Attach sipfrag body. */ -
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); -
pjproject/trunk/pjsip/src/test/msg_test.c
r2724 r3241 482 482 pjsip_via_hdr *via; 483 483 pjsip_generic_string_hdr *generic; 484 pjsip_param *prm; 484 485 pj_str_t str; 485 486 … … 570 571 pj_strdup2(pool, &ctype->media.type, "text"); 571 572 pj_strdup2(pool, &ctype->media.subtype, "html"); 572 pj_strdup2(pool, &ctype->media.param, ";charset=ISO-8859-4"); 573 prm = PJ_POOL_ALLOC_T(pool, pjsip_param); 574 prm->name = pj_str("charset"); 575 prm->value = pj_str("ISO-8859-4"); 576 pj_list_push_back(&ctype->media.param, prm); 573 577 574 578 /* "Route: <sip:bigbox3.site3.atlanta.com;lr>,\r\n" */ … … 1591 1595 { 1592 1596 pjsip_ctype_hdr *hdr = (pjsip_ctype_hdr*)h; 1597 const pjsip_param *prm; 1593 1598 1594 1599 if (h->type != PJSIP_H_CONTENT_TYPE) … … 1604 1609 * pjsip will print the parameter unescaped. 1605 1610 */ 1606 PJ_TODO(FIX_PARAMETER_IN_MEDIA_TYPE); 1607 1608 if (pj_strcmp2(&hdr->media.param, ";" GENERIC_PARAM_PARSED)) 1609 return -1940; 1611 prm = hdr->media.param.next; 1612 if (prm == &hdr->media.param) return -1940; 1613 if (pj_strcmp2(&prm->name, "p0")) return -1941; 1614 if (pj_strcmp2(&prm->value, "a")) return -1942; 1615 1616 prm = prm->next; 1617 if (prm == &hdr->media.param) return -1950; 1618 if (pj_strcmp2(&prm->name, "p1")) { PJ_LOG(3,("", "%.*s", (int)prm->name.slen, prm->name.ptr)); return -1951; } 1619 if (pj_strcmp2(&prm->value, "\"ab:;cd\"")) { PJ_LOG(3,("", "%.*s", (int)prm->value.slen, prm->value.ptr)); return -1952; } 1620 1621 prm = prm->next; 1622 if (prm == &hdr->media.param) return -1960; 1623 if (pj_strcmp2(&prm->name, "p2")) return -1961; 1624 if (pj_strcmp2(&prm->value, "ab:cd")) return -1962; 1625 1626 prm = prm->next; 1627 if (prm == &hdr->media.param) return -1970; 1628 if (pj_strcmp2(&prm->name, "p3")) return -1971; 1629 if (pj_strcmp2(&prm->value, "")) return -1972; 1610 1630 1611 1631 return 0;
Note: See TracChangeset
for help on using the changeset viewer.