Skip to content

Commit 6270763

Browse files
Merge pull request #126 from purecloudlabs/GCVCALLP-2375
Updated docs and added explicit return code for * Contact when it fails
2 parents 61f60b8 + 64f5856 commit 6270763

File tree

2 files changed

+36
-10
lines changed

2 files changed

+36
-10
lines changed

modules/sipmsgops/doc/sipmsgops_admin.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -998,6 +998,8 @@ add_body_part("Hello World!", "text/plain");
998998
</para></listitem>
999999
<listitem><para><emphasis>-29</emphasis> - Bad To URI username
10001000
</para></listitem>
1001+
<listitem><para><emphasis>-30</emphasis> - Contact header contains * for non-Register request
1002+
</para></listitem>
10011003
<listitem><para><emphasis>-255</emphasis> - undefined errors.
10021004
</para></listitem>
10031005
</itemizedlist>
@@ -1025,6 +1027,15 @@ if(!sipmsg_validate("sh", $var(err_reason)))
10251027
exit;
10261028
}
10271029
...
1030+
1031+
...
1032+
# checks Contact header for a 200 Ok reply and logs when it's *
1033+
if(!sipmsg_validate("c"))
1034+
{
1035+
if ($rc == -30)
1036+
xlog("Invalid * Contact header found\n");
1037+
}
1038+
...
10281039
</programlisting>
10291040
</example>
10301041
</section>

modules/sipmsgops/sipmsgops.c

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1576,7 +1576,7 @@ enum sip_validation_failures {
15761576
SV_BAD_USERNAME=-27,
15771577
SV_FROM_USERNAME_ERROR=-28,
15781578
SV_TO_USERNAME_ERROR=-29,
1579-
SV_BAD_EXPIRES=-30,
1579+
SV_BAD_STAR_CONTACT=-30,
15801580
SV_GENERIC_FAILURE=-255
15811581
};
15821582

@@ -1621,24 +1621,39 @@ static enum sip_validation_failures validate_contact_header(struct sip_msg *msg,
16211621
/* empty contacts header - this can be a * Contact header, valid only for REGISTER requests */
16221622
contact_body = (contact_body_t *) msg->contact->parsed;
16231623

1624-
if (method != METHOD_REGISTER || msg->first_line.type == SIP_REPLY) {
1625-
strcpy(reason, "empty body for 'Contact' header");
1626-
ret = SV_CONTACT_PARSE_ERROR;
1627-
goto failed;
1628-
} else {
1624+
if (method == METHOD_REGISTER) {
1625+
if (contact_body->star != 1) {
1626+
strcpy(reason, "empty body for 'Contact' header");
1627+
ret = SV_CONTACT_PARSE_ERROR;
1628+
goto failed;
1629+
} else if (msg->first_line.type == SIP_REPLY) {
1630+
strcpy(reason, "Contact header for REGISTER reply contains '*' only valid for REGISTER request");
1631+
ret = SV_BAD_STAR_CONTACT;
1632+
goto failed;
1633+
}
1634+
16291635
if (!msg->expires || (parse_expires(msg->expires) < 0 || !msg->expires->parsed)) {
16301636
strcpy(reason, "failed to parse 'Expires' header");
1631-
ret = SV_BAD_EXPIRES;
1637+
ret = SV_BAD_STAR_CONTACT;
16321638
goto failed;
16331639
}
16341640

16351641
expires_body = (exp_body_t*) msg->expires->parsed;
16361642

1637-
if (!expires_body || !(expires_body->val == 0 && contact_body->star == 1)) {
1643+
if (!expires_body || expires_body->val != 0) {
16381644
strcpy(reason, "Expires header greater than 0 for REGISTER 'Contact' header with '*' value");
1639-
ret = SV_CONTACT_PARSE_ERROR;
1645+
ret = SV_BAD_STAR_CONTACT;
16401646
goto failed;
16411647
}
1648+
} else {
1649+
if (contact_body->star != 1) {
1650+
strcpy(reason, "empty body for 'Contact' header");
1651+
ret = SV_CONTACT_PARSE_ERROR;
1652+
} else {
1653+
strcpy(reason, "Contact header for SIP message contains '*' only valid for REGISTER request");
1654+
ret = SV_BAD_STAR_CONTACT;
1655+
}
1656+
goto failed;
16421657
}
16431658
}
16441659
}
@@ -1894,7 +1909,7 @@ static int w_sip_validate(struct sip_msg *msg, void *_flags, pv_spec_t* err_txt)
18941909
}
18951910
}
18961911

1897-
if (flags & SIP_PARSE_CONTACT && (status_code > 199 || status_code < 400)) {
1912+
if (flags & SIP_PARSE_CONTACT && (status_code > 199 && status_code < 400)) {
18981913
ret = validate_contact_header(msg, method, reason);
18991914

19001915
if (ret != 0) {

0 commit comments

Comments
 (0)