Changeset 2005


Ignore:
Timestamp:
Jun 11, 2008 11:18:04 AM (16 years ago)
Author:
bennylp
Message:

Fixed error representing the qvalue in Contact header (parser error), and optimize the printing to remove ending zero digits (thanks Philippe Leuba)

Location:
pjproject/trunk/pjsip/src
Files:
3 edited

Legend:

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

    r1954 r2005  
    11321132 
    11331133        if (hdr->q1000) { 
     1134            unsigned frac; 
     1135 
    11341136            if (buf+19 >= endbuf) 
    11351137                return -1; 
     
    11421144            printed = pj_utoa(hdr->q1000/1000, buf+3); 
    11431145            buf += printed + 3; 
    1144             *buf++ = '.'; 
    1145             printed = pj_utoa(hdr->q1000 % 1000, buf); 
    1146             buf += printed; 
     1146            frac = hdr->q1000 % 1000; 
     1147            if (frac != 0) { 
     1148                *buf++ = '.'; 
     1149                if ((frac % 100)==0) frac /= 100; 
     1150                if ((frac % 10)==0) frac /= 10; 
     1151                printed = pj_utoa(frac, buf); 
     1152                buf += printed; 
     1153            } 
    11471154        } 
    11481155 
  • pjproject/trunk/pjsip/src/pjsip/sip_parser.c

    r1957 r2005  
    16411641            char *dot_pos = (char*) pj_memchr(pvalue.ptr, '.', pvalue.slen); 
    16421642            if (!dot_pos) { 
    1643                 hdr->q1000 = pj_strtoul(&pvalue); 
     1643                hdr->q1000 = pj_strtoul(&pvalue) * 1000; 
    16441644            } else { 
     1645                pj_str_t tmp = pvalue; 
     1646 
     1647                tmp.slen = dot_pos - pvalue.ptr; 
     1648                hdr->q1000 = pj_strtoul(&tmp) * 1000; 
     1649 
    16451650                pvalue.slen = (pvalue.ptr+pvalue.slen) - (dot_pos+1); 
    16461651                pvalue.ptr = dot_pos + 1; 
    1647                 hdr->q1000 = pj_strtoul_mindigit(&pvalue, 3); 
     1652                hdr->q1000 += pj_strtoul_mindigit(&pvalue, 3); 
    16481653            }     
    16491654        } else if (!parser_stricmp(pname, pconst.pjsip_EXPIRES_STR) && pvalue.slen) { 
  • pjproject/trunk/pjsip/src/test-pjsip/msg_test.c

    r1957 r2005  
    790790static int hdr_test_contact0(pjsip_hdr *h); 
    791791static int hdr_test_contact1(pjsip_hdr *h); 
     792static int hdr_test_contact_q0(pjsip_hdr *h); 
     793static int hdr_test_contact_q1(pjsip_hdr *h); 
     794static int hdr_test_contact_q2(pjsip_hdr *h); 
     795static int hdr_test_contact_q3(pjsip_hdr *h); 
     796static int hdr_test_contact_q4(pjsip_hdr *h); 
    792797static int hdr_test_content_length(pjsip_hdr *h); 
    793798static int hdr_test_content_type(pjsip_hdr *h); 
     
    898903 
    899904    { 
     905        /* q=0 parameter in Contact header */ 
     906        "Contact", "m", 
     907        NAME_ADDR ";q=0", 
     908        &hdr_test_contact_q0, 
     909        HDR_FLAG_DONT_PRINT 
     910    }, 
     911 
     912    { 
     913        /* q=0.5 parameter in Contact header */ 
     914        "Contact", "m", 
     915        NAME_ADDR ";q=0.5", 
     916        &hdr_test_contact_q1 
     917    }, 
     918 
     919    { 
     920        /* q=1 parameter in Contact header */ 
     921        "Contact", "m", 
     922        NAME_ADDR ";q=1", 
     923        &hdr_test_contact_q2 
     924    }, 
     925 
     926    { 
     927        /* q=1.0 parameter in Contact header */ 
     928        "Contact", "m", 
     929        NAME_ADDR ";q=1.0", 
     930        &hdr_test_contact_q3, 
     931        HDR_FLAG_DONT_PRINT 
     932    }, 
     933 
     934    { 
     935        /* q=1.1 parameter in Contact header */ 
     936        "Contact", "m", 
     937        NAME_ADDR ";q=1.15", 
     938        &hdr_test_contact_q4 
     939    }, 
     940 
     941    { 
    900942        /* Content-Length */ 
    901943        "Content-Length", "l", 
     
    12711313    if (rc != 0) 
    12721314        return rc; 
     1315 
     1316    return 0; 
     1317} 
     1318 
     1319/* 
     1320    NAME_ADDR ";q=0" 
     1321 */ 
     1322static int hdr_test_contact_q0(pjsip_hdr *h) 
     1323{ 
     1324    pjsip_contact_hdr *hdr = (pjsip_contact_hdr*)h; 
     1325    int rc; 
     1326 
     1327    if (h->type != PJSIP_H_CONTACT) 
     1328        return -1710; 
     1329 
     1330    rc = nameaddr_test(hdr->uri); 
     1331    if (rc != 0) 
     1332        return rc; 
     1333 
     1334    if (hdr->q1000 != 0) 
     1335        return -1711; 
     1336 
     1337    return 0; 
     1338} 
     1339 
     1340/* 
     1341    NAME_ADDR ";q=0.5" 
     1342 */ 
     1343static int hdr_test_contact_q1(pjsip_hdr *h) 
     1344{ 
     1345    pjsip_contact_hdr *hdr = (pjsip_contact_hdr*)h; 
     1346    int rc; 
     1347 
     1348    if (h->type != PJSIP_H_CONTACT) 
     1349        return -1710; 
     1350 
     1351    rc = nameaddr_test(hdr->uri); 
     1352    if (rc != 0) 
     1353        return rc; 
     1354 
     1355    if (hdr->q1000 != 500) 
     1356        return -1712; 
     1357 
     1358    return 0; 
     1359} 
     1360 
     1361/* 
     1362    NAME_ADDR ";q=1" 
     1363 */ 
     1364static int hdr_test_contact_q2(pjsip_hdr *h) 
     1365{ 
     1366    pjsip_contact_hdr *hdr = (pjsip_contact_hdr*)h; 
     1367    int rc; 
     1368 
     1369    if (h->type != PJSIP_H_CONTACT) 
     1370        return -1710; 
     1371 
     1372    rc = nameaddr_test(hdr->uri); 
     1373    if (rc != 0) 
     1374        return rc; 
     1375 
     1376    if (hdr->q1000 != 1000) 
     1377        return -1713; 
     1378 
     1379    return 0; 
     1380} 
     1381 
     1382/* 
     1383    NAME_ADDR ";q=1.0" 
     1384 */ 
     1385static int hdr_test_contact_q3(pjsip_hdr *h) 
     1386{ 
     1387    pjsip_contact_hdr *hdr = (pjsip_contact_hdr*)h; 
     1388    int rc; 
     1389 
     1390    if (h->type != PJSIP_H_CONTACT) 
     1391        return -1710; 
     1392 
     1393    rc = nameaddr_test(hdr->uri); 
     1394    if (rc != 0) 
     1395        return rc; 
     1396 
     1397    if (hdr->q1000 != 1000) 
     1398        return -1714; 
     1399 
     1400    return 0; 
     1401} 
     1402 
     1403/* 
     1404    NAME_ADDR ";q=1.15" 
     1405 */ 
     1406static int hdr_test_contact_q4(pjsip_hdr *h) 
     1407{ 
     1408    pjsip_contact_hdr *hdr = (pjsip_contact_hdr*)h; 
     1409    int rc; 
     1410 
     1411    if (h->type != PJSIP_H_CONTACT) 
     1412        return -1710; 
     1413 
     1414    rc = nameaddr_test(hdr->uri); 
     1415    if (rc != 0) 
     1416        return rc; 
     1417 
     1418    if (hdr->q1000 != 1150) 
     1419        return -1715; 
    12731420 
    12741421    return 0; 
Note: See TracChangeset for help on using the changeset viewer.