MCPcopy Create free account
hub / github.com/OpenSIPS/opensips / parse_msg_opt

Function parse_msg_opt

parser/msg_parser.c:828–947  ·  view source on GitHub ↗

returns 0 if ok, -1 for errors */

Source from the content-addressed store, hash-verified

826
827/* returns 0 if ok, -1 for errors */
828int parse_msg_opt(char* buf, unsigned int len, struct sip_msg* msg,
829 int free_on_err)
830{
831
832 char *tmp;
833 char* rest;
834 struct msg_start *fl;
835 int offset;
836 hdr_flags_t flags;
837
838 /* eat crlf from the beginning */
839 for (tmp=buf; (unsigned int)(tmp-buf) < len
840 && (*tmp=='\n' || *tmp=='\r'); tmp++);
841 offset=tmp-buf;
842 fl=&(msg->first_line);
843 rest=parse_first_line(tmp, len-offset, fl);
844
845 offset+=rest-tmp;
846 tmp=rest;
847 switch(fl->type){
848 case SIP_INVALID:
849 LM_DBG("invalid message\n");
850 /* if failed to parse the first line, we simply consider that the whole
851 buffer was parsed, so that nothing is left to be parsed :) - this will
852 do the trick and make "msg" struct acceptable for following parsing
853 attempts */
854 msg->unparsed = msg->buf + msg->len;
855 goto error;
856 break;
857 case SIP_REQUEST:
858 LM_DBG("SIP Request:\n");
859 LM_DBG(" method: <%.*s>\n",fl->u.request.method.len,
860 ZSW(fl->u.request.method.s));
861 LM_DBG(" uri: <%.*s>\n",fl->u.request.uri.len,
862 ZSW(fl->u.request.uri.s));
863 LM_DBG(" version: <%.*s>\n",fl->u.request.version.len,
864 ZSW(fl->u.request.version.s));
865 flags=HDR_EOH_F;
866 break;
867 case SIP_REPLY:
868 LM_DBG("SIP Reply (status):\n");
869 LM_DBG(" version: <%.*s>\n",fl->u.reply.version.len,
870 ZSW(fl->u.reply.version.s));
871 LM_DBG(" status: <%.*s>\n", fl->u.reply.status.len,
872 ZSW(fl->u.reply.status.s));
873 LM_DBG(" reason: <%.*s>\n", fl->u.reply.reason.len,
874 ZSW(fl->u.reply.reason.s));
875 flags=HDR_EOH_F;
876 break;
877 default:
878 LM_DBG("unknown type %d\n",fl->type);
879 goto error;
880 }
881 msg->unparsed=tmp;
882 /*find first Via: */
883 if (parse_headers(msg, flags, 0)==-1) goto parse_error;
884
885#ifdef EXTRA_DEBUG

Callers 1

receive_msgFunction · 0.85

Calls 2

parse_first_lineFunction · 0.85
free_sip_msgFunction · 0.85

Tested by

no test coverage detected