From c9d40b273390ee46a5c6441fd5fd81c48edce22a Mon Sep 17 00:00:00 2001 From: Benny Prijono Date: Wed, 13 Oct 2010 09:41:37 +0000 Subject: Fixed #1147: Bug in parsing multipart message bodies (thanks Johan Lantz for the report) git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@3340 74dad513-b988-da41-8d7b-12977e46ad98 --- pjsip/include/pjsip/sip_msg.h | 8 +++++++- pjsip/src/pjsip/sip_msg.c | 7 +++++-- pjsip/src/pjsip/sip_multipart.c | 5 ++++- pjsip/src/pjsip/sip_parser.c | 3 ++- pjsip/src/test/multipart_test.c | 4 ++-- 5 files changed, 20 insertions(+), 7 deletions(-) (limited to 'pjsip') diff --git a/pjsip/include/pjsip/sip_msg.h b/pjsip/include/pjsip/sip_msg.h index 4c112dc9..39cc6949 100644 --- a/pjsip/include/pjsip/sip_msg.h +++ b/pjsip/include/pjsip/sip_msg.h @@ -546,12 +546,18 @@ PJ_DECL(void) pjsip_media_type_init2(pjsip_media_type *mt, * * @param mt1 The first media type. * @param mt2 The second media type. + * @param cmp_param Specify how to compare the media type parameters: + * - 0: do not compare parameters + * - 1: compare parameters but ignore parameters that + * only appear in one of the media type. + * - 2: compare the parameters. * * @return Zero if both media types are equal, -1 if mt1 < mt2, * 1 if mt1 > mt2. */ PJ_DECL(int) pjsip_media_type_cmp(const pjsip_media_type *mt1, - const pjsip_media_type *mt2); + const pjsip_media_type *mt2, + int cmp_param); /** * Copy SIP media type to another. diff --git a/pjsip/src/pjsip/sip_msg.c b/pjsip/src/pjsip/sip_msg.c index 1b38c240..241062f5 100644 --- a/pjsip/src/pjsip/sip_msg.c +++ b/pjsip/src/pjsip/sip_msg.c @@ -645,7 +645,8 @@ PJ_DEF(void) pjsip_media_type_init2( pjsip_media_type *mt, * Compare two media types. */ PJ_DEF(int) pjsip_media_type_cmp( const pjsip_media_type *mt1, - const pjsip_media_type *mt2) + const pjsip_media_type *mt2, + pj_bool_t cmp_param) { int rc; @@ -657,7 +658,9 @@ PJ_DEF(int) pjsip_media_type_cmp( const pjsip_media_type *mt1, rc = pj_stricmp(&mt1->subtype, &mt2->subtype); if (rc) return rc; - rc = pjsip_param_cmp(&mt1->param, &mt2->param, 0); + if (cmp_param) { + rc = pjsip_param_cmp(&mt1->param, &mt2->param, (cmp_param==1)); + } return rc; } diff --git a/pjsip/src/pjsip/sip_multipart.c b/pjsip/src/pjsip/sip_multipart.c index e9aa76e2..a3311504 100644 --- a/pjsip/src/pjsip/sip_multipart.c +++ b/pjsip/src/pjsip/sip_multipart.c @@ -396,8 +396,11 @@ pjsip_multipart_find_part( const pjsip_msg_body *mp, part = m_data->part_head.next; while (part != &m_data->part_head) { - if (pjsip_media_type_cmp(&part->body->content_type, content_type)==0) + if (pjsip_media_type_cmp(&part->body->content_type, + content_type, 0)==0) + { return part; + } part = part->next; } diff --git a/pjsip/src/pjsip/sip_parser.c b/pjsip/src/pjsip/sip_parser.c index 61559601..de68dd8a 100644 --- a/pjsip/src/pjsip/sip_parser.c +++ b/pjsip/src/pjsip/sip_parser.c @@ -1856,7 +1856,8 @@ static pjsip_hdr* parse_hdr_content_type( pjsip_parse_ctx *ctx ) /* Parse media parameters */ while (*scanner->curptr == ';') { pjsip_param *param = PJ_POOL_ALLOC_T(ctx->pool, pjsip_param); - int_parse_param(scanner, ctx->pool, ¶m->name, ¶m->value, 0); + int_parse_param(scanner, ctx->pool, ¶m->name, ¶m->value, + PJSIP_PARSE_REMOVE_QUOTE); pj_list_push_back(&hdr->media.param, param); } diff --git a/pjsip/src/test/multipart_test.c b/pjsip/src/test/multipart_test.c index 37c81670..9f059545 100644 --- a/pjsip/src/test/multipart_test.c +++ b/pjsip/src/test/multipart_test.c @@ -116,7 +116,7 @@ static int verify_part(pjsip_multipart_part *part, init_media_type(&mt, h_content_type, h_content_subtype, boundary); - if (pjsip_media_type_cmp(&ctype_hdr->media, &mt) != 0) + if (pjsip_media_type_cmp(&ctype_hdr->media, &mt, 2) != 0) return -20; } else { @@ -153,7 +153,7 @@ static pj_status_t verify1(pj_pool_t *pool, pjsip_msg_body *body) /* Check content-type: "multipart/mixed;boundary=12345" */ init_media_type(&mt, "multipart", "mixed", "12345"); - if (pjsip_media_type_cmp(&body->content_type, &mt) != 0) + if (pjsip_media_type_cmp(&body->content_type, &mt, 2) != 0) return -200; /* First part: -- cgit v1.2.3