summaryrefslogtreecommitdiff
path: root/pjsip
diff options
context:
space:
mode:
authorBenny Prijono <bennylp@teluu.com>2008-06-11 11:18:04 +0000
committerBenny Prijono <bennylp@teluu.com>2008-06-11 11:18:04 +0000
commitf0897261d693c1111e6500fee4bdfb8570dbc568 (patch)
tree33305c682aae1c1fa77fd521b425211e5fd8b6b8 /pjsip
parentebbdbaed47300ebf9742a3a06438dd11ac1a5bae (diff)
Fixed error representing the qvalue in Contact header (parser error), and optimize the printing to remove ending zero digits (thanks Philippe Leuba)
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@2005 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjsip')
-rw-r--r--pjsip/src/pjsip/sip_msg.c13
-rw-r--r--pjsip/src/pjsip/sip_parser.c9
-rw-r--r--pjsip/src/test-pjsip/msg_test.c147
3 files changed, 164 insertions, 5 deletions
diff --git a/pjsip/src/pjsip/sip_msg.c b/pjsip/src/pjsip/sip_msg.c
index 20cece07..d51cedb4 100644
--- a/pjsip/src/pjsip/sip_msg.c
+++ b/pjsip/src/pjsip/sip_msg.c
@@ -1131,6 +1131,8 @@ static int pjsip_contact_hdr_print( pjsip_contact_hdr *hdr, char *buf,
buf += printed;
if (hdr->q1000) {
+ unsigned frac;
+
if (buf+19 >= endbuf)
return -1;
@@ -1141,9 +1143,14 @@ static int pjsip_contact_hdr_print( pjsip_contact_hdr *hdr, char *buf,
pj_memcpy(buf, ";q=", 3);
printed = pj_utoa(hdr->q1000/1000, buf+3);
buf += printed + 3;
- *buf++ = '.';
- printed = pj_utoa(hdr->q1000 % 1000, buf);
- buf += printed;
+ frac = hdr->q1000 % 1000;
+ if (frac != 0) {
+ *buf++ = '.';
+ if ((frac % 100)==0) frac /= 100;
+ if ((frac % 10)==0) frac /= 10;
+ printed = pj_utoa(frac, buf);
+ buf += printed;
+ }
}
if (hdr->expires >= 0) {
diff --git a/pjsip/src/pjsip/sip_parser.c b/pjsip/src/pjsip/sip_parser.c
index 273d9993..3e92c7ce 100644
--- a/pjsip/src/pjsip/sip_parser.c
+++ b/pjsip/src/pjsip/sip_parser.c
@@ -1640,11 +1640,16 @@ static void int_parse_contact_param( pjsip_contact_hdr *hdr,
if (!parser_stricmp(pname, pconst.pjsip_Q_STR) && pvalue.slen) {
char *dot_pos = (char*) pj_memchr(pvalue.ptr, '.', pvalue.slen);
if (!dot_pos) {
- hdr->q1000 = pj_strtoul(&pvalue);
+ hdr->q1000 = pj_strtoul(&pvalue) * 1000;
} else {
+ pj_str_t tmp = pvalue;
+
+ tmp.slen = dot_pos - pvalue.ptr;
+ hdr->q1000 = pj_strtoul(&tmp) * 1000;
+
pvalue.slen = (pvalue.ptr+pvalue.slen) - (dot_pos+1);
pvalue.ptr = dot_pos + 1;
- hdr->q1000 = pj_strtoul_mindigit(&pvalue, 3);
+ hdr->q1000 += pj_strtoul_mindigit(&pvalue, 3);
}
} else if (!parser_stricmp(pname, pconst.pjsip_EXPIRES_STR) && pvalue.slen) {
hdr->expires = pj_strtoul(&pvalue);
diff --git a/pjsip/src/test-pjsip/msg_test.c b/pjsip/src/test-pjsip/msg_test.c
index a1bee18f..cc603103 100644
--- a/pjsip/src/test-pjsip/msg_test.c
+++ b/pjsip/src/test-pjsip/msg_test.c
@@ -789,6 +789,11 @@ static int hdr_test_authorization(pjsip_hdr *h);
static int hdr_test_cid(pjsip_hdr *h);
static int hdr_test_contact0(pjsip_hdr *h);
static int hdr_test_contact1(pjsip_hdr *h);
+static int hdr_test_contact_q0(pjsip_hdr *h);
+static int hdr_test_contact_q1(pjsip_hdr *h);
+static int hdr_test_contact_q2(pjsip_hdr *h);
+static int hdr_test_contact_q3(pjsip_hdr *h);
+static int hdr_test_contact_q4(pjsip_hdr *h);
static int hdr_test_content_length(pjsip_hdr *h);
static int hdr_test_content_type(pjsip_hdr *h);
static int hdr_test_from(pjsip_hdr *h);
@@ -897,6 +902,43 @@ struct hdr_test_t
},
{
+ /* q=0 parameter in Contact header */
+ "Contact", "m",
+ NAME_ADDR ";q=0",
+ &hdr_test_contact_q0,
+ HDR_FLAG_DONT_PRINT
+ },
+
+ {
+ /* q=0.5 parameter in Contact header */
+ "Contact", "m",
+ NAME_ADDR ";q=0.5",
+ &hdr_test_contact_q1
+ },
+
+ {
+ /* q=1 parameter in Contact header */
+ "Contact", "m",
+ NAME_ADDR ";q=1",
+ &hdr_test_contact_q2
+ },
+
+ {
+ /* q=1.0 parameter in Contact header */
+ "Contact", "m",
+ NAME_ADDR ";q=1.0",
+ &hdr_test_contact_q3,
+ HDR_FLAG_DONT_PRINT
+ },
+
+ {
+ /* q=1.1 parameter in Contact header */
+ "Contact", "m",
+ NAME_ADDR ";q=1.15",
+ &hdr_test_contact_q4
+ },
+
+ {
/* Content-Length */
"Content-Length", "l",
"10",
@@ -1275,6 +1317,111 @@ static int hdr_test_contact1(pjsip_hdr *h)
}
/*
+ NAME_ADDR ";q=0"
+ */
+static int hdr_test_contact_q0(pjsip_hdr *h)
+{
+ pjsip_contact_hdr *hdr = (pjsip_contact_hdr*)h;
+ int rc;
+
+ if (h->type != PJSIP_H_CONTACT)
+ return -1710;
+
+ rc = nameaddr_test(hdr->uri);
+ if (rc != 0)
+ return rc;
+
+ if (hdr->q1000 != 0)
+ return -1711;
+
+ return 0;
+}
+
+/*
+ NAME_ADDR ";q=0.5"
+ */
+static int hdr_test_contact_q1(pjsip_hdr *h)
+{
+ pjsip_contact_hdr *hdr = (pjsip_contact_hdr*)h;
+ int rc;
+
+ if (h->type != PJSIP_H_CONTACT)
+ return -1710;
+
+ rc = nameaddr_test(hdr->uri);
+ if (rc != 0)
+ return rc;
+
+ if (hdr->q1000 != 500)
+ return -1712;
+
+ return 0;
+}
+
+/*
+ NAME_ADDR ";q=1"
+ */
+static int hdr_test_contact_q2(pjsip_hdr *h)
+{
+ pjsip_contact_hdr *hdr = (pjsip_contact_hdr*)h;
+ int rc;
+
+ if (h->type != PJSIP_H_CONTACT)
+ return -1710;
+
+ rc = nameaddr_test(hdr->uri);
+ if (rc != 0)
+ return rc;
+
+ if (hdr->q1000 != 1000)
+ return -1713;
+
+ return 0;
+}
+
+/*
+ NAME_ADDR ";q=1.0"
+ */
+static int hdr_test_contact_q3(pjsip_hdr *h)
+{
+ pjsip_contact_hdr *hdr = (pjsip_contact_hdr*)h;
+ int rc;
+
+ if (h->type != PJSIP_H_CONTACT)
+ return -1710;
+
+ rc = nameaddr_test(hdr->uri);
+ if (rc != 0)
+ return rc;
+
+ if (hdr->q1000 != 1000)
+ return -1714;
+
+ return 0;
+}
+
+/*
+ NAME_ADDR ";q=1.15"
+ */
+static int hdr_test_contact_q4(pjsip_hdr *h)
+{
+ pjsip_contact_hdr *hdr = (pjsip_contact_hdr*)h;
+ int rc;
+
+ if (h->type != PJSIP_H_CONTACT)
+ return -1710;
+
+ rc = nameaddr_test(hdr->uri);
+ if (rc != 0)
+ return rc;
+
+ if (hdr->q1000 != 1150)
+ return -1715;
+
+ return 0;
+}
+
+/*
"10"
*/
static int hdr_test_content_length(pjsip_hdr *h)