Check for a message in the socket and return the length of the first * message. If this is UDP, the only check is if we have buffers. If this is * TCP or TLS we need to parse out the content-length. */
| 671 | * message. If this is UDP, the only check is if we have buffers. If this is |
| 672 | * TCP or TLS we need to parse out the content-length. */ |
| 673 | int SIPpSocket::check_for_message() |
| 674 | { |
| 675 | struct socketbuf *socketbuf = ss_in; |
| 676 | int state = ss_control ? CFM_CONTROL : CFM_NORMAL; |
| 677 | const char *l; |
| 678 | |
| 679 | if (!socketbuf) |
| 680 | return 0; |
| 681 | |
| 682 | if (ss_transport == T_UDP || ss_transport == T_SCTP) { |
| 683 | return socketbuf->len; |
| 684 | } |
| 685 | |
| 686 | int len = 0; |
| 687 | |
| 688 | while (socketbuf->offset + len < socketbuf->len) { |
| 689 | char c = socketbuf->buf[socketbuf->offset + len]; |
| 690 | |
| 691 | switch(state) { |
| 692 | case CFM_CONTROL: |
| 693 | /* For CMD Message the escape char is the end of message */ |
| 694 | if (c == 27) { |
| 695 | return len + 1; /* The plus one includes the control character. */ |
| 696 | } |
| 697 | break; |
| 698 | case CFM_NORMAL: |
| 699 | if (c == '\r') { |
| 700 | state = CFM_CR; |
| 701 | } |
| 702 | break; |
| 703 | case CFM_CR: |
| 704 | if (c == '\n') { |
| 705 | state = CFM_CRLF; |
| 706 | } else { |
| 707 | state = CFM_NORMAL; |
| 708 | } |
| 709 | break; |
| 710 | case CFM_CRLF: |
| 711 | if (c == '\r') { |
| 712 | state = CFM_CRLFCR; |
| 713 | } else { |
| 714 | state = CFM_NORMAL; |
| 715 | } |
| 716 | break; |
| 717 | case CFM_CRLFCR: |
| 718 | if (c == '\n') { |
| 719 | state = CFM_CRLFCRLF; |
| 720 | } else { |
| 721 | state = CFM_NORMAL; |
| 722 | } |
| 723 | break; |
| 724 | } |
| 725 | |
| 726 | /* Head off failing because the buffer does not contain the whole header. */ |
| 727 | if (socketbuf->offset + len == socketbuf->len - 1) { |
| 728 | merge_socketbufs(socketbuf); |
| 729 | } |
| 730 |
nothing calls this directly
no test coverage detected