| 1654 | } |
| 1655 | |
| 1656 | static int w_sip_validate(struct sip_msg *msg, void *_flags, pv_spec_t* err_txt) |
| 1657 | { |
| 1658 | unsigned int hdrs_len, status_code; |
| 1659 | unsigned long flags = (unsigned long)_flags; |
| 1660 | int method; |
| 1661 | str body; |
| 1662 | struct sip_uri *p_uri; |
| 1663 | struct cseq_body * cbody; |
| 1664 | pv_value_t pv_val; |
| 1665 | char reason[MAX_REASON]; |
| 1666 | int ret = -SV_GENERIC_FAILURE; |
| 1667 | |
| 1668 | if (!msg) { |
| 1669 | strcpy(reason, "no message object"); |
| 1670 | ret = SV_NO_MSG; |
| 1671 | goto failed; |
| 1672 | } |
| 1673 | |
| 1674 | /* try to check the whole SIP msg */ |
| 1675 | if (parse_headers(msg, HDR_EOH_F, 0) < 0) { |
| 1676 | strcpy(reason, "message parsing failed"); |
| 1677 | ret = SV_HDR_PARSE_ERROR; |
| 1678 | goto failed; |
| 1679 | } |
| 1680 | |
| 1681 | /* any message has to have a call-id */ |
| 1682 | if (!msg->callid) { |
| 1683 | strcpy(reason, "message doesn't have callid"); |
| 1684 | ret = SV_NO_CALLID; |
| 1685 | goto failed; |
| 1686 | } |
| 1687 | |
| 1688 | /* content length should be present if protocol is not UDP */ |
| 1689 | if (msg->rcv.proto != PROTO_UDP && !msg->content_length) { |
| 1690 | snprintf(reason, MAX_REASON-1, |
| 1691 | "message doesn't have Content Length header for proto %d", |
| 1692 | msg->rcv.proto); |
| 1693 | ret = SV_NO_CONTENT_LENGTH; |
| 1694 | goto failed; |
| 1695 | } |
| 1696 | |
| 1697 | body.s = NULL; |
| 1698 | body.len = 0; |
| 1699 | |
| 1700 | /* if not CANCEL, check if it has body */ |
| 1701 | if (msg->first_line.type!=SIP_REQUEST || msg->REQ_METHOD!=METHOD_CANCEL) { |
| 1702 | |
| 1703 | if (get_body( msg, &body)!=0) { |
| 1704 | strcpy(reason, "invalid parsing"); |
| 1705 | ret = SV_HDR_PARSE_ERROR; |
| 1706 | goto failed; |
| 1707 | } |
| 1708 | |
| 1709 | if (get_content_length(msg) != body.len) { |
| 1710 | snprintf(reason, MAX_REASON-1, "invalid body - content " |
| 1711 | "length %ld different than actual body %d", |
| 1712 | get_content_length(msg), body.len); |
| 1713 | ret = SV_INVALID_CONTENT_LENGTH; |
nothing calls this directly
no test coverage detected