parse_cseq.c

Go to the documentation of this file.
00001 /*
00002  * $Id: parse_cseq.c 4720 2008-08-23 10:56:15Z henningw $ 
00003  *
00004  * Copyright (C) 2001-2003 FhG Fokus
00005  *
00006  * This file is part of Kamailio, a free SIP server.
00007  *
00008  * Kamailio is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation; either version 2 of the License, or
00011  * (at your option) any later version
00012  *
00013  * Kamailio is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License 
00019  * along with this program; if not, write to the Free Software 
00020  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021  */
00022 
00023 /*!
00024  * \file
00025  * \brief Parse CSEQ header field
00026  * \ingroup parser
00027  */
00028 
00029 #include "parse_cseq.h"
00030 #include "parser_f.h"  /* eat_space_end and so on */
00031 #include "../dprint.h"
00032 #include "parse_def.h"
00033 #include "parse_methods.h"
00034 #include "../mem/mem.h"
00035 
00036 /*!
00037  * Parse CSeq header field
00038  */
00039 char* parse_cseq(char *buf, char* end, struct cseq_body* cb)
00040 {
00041    char *t, *m, *m_end;
00042    
00043    cb->error=PARSE_ERROR;
00044    t=buf;
00045    
00046    cb->number.s=t;
00047    t=eat_token_end(t, end);
00048    if (t>=end) goto error;
00049    cb->number.len=t-cb->number.s;
00050 
00051    m=eat_space_end(t, end);
00052    m_end=eat_token_end(m, end);
00053 
00054    if (m_end>=end) {
00055          LM_ERR("method terminated unexpectedly\n");
00056          goto error;
00057    }
00058    if (m_end==m){
00059       /* null method*/
00060       LM_ERR("no method found\n");
00061       goto error;
00062    }
00063    cb->method.s=m;
00064    t=m_end;
00065    cb->method.len=t-cb->method.s;
00066    
00067    /* cache the method id */
00068    if(parse_method(cb->method.s, t, (unsigned int*)&cb->method_id)==0)
00069    {
00070       LM_ERR("cannot parse the method\n");
00071       goto error;
00072    }
00073    
00074    /* there may be trailing LWS 
00075     * (it was not my idea to put it in SIP; -jiri )
00076     */
00077    t=eat_lws_end(t, end);
00078    /*check if the header ends here*/
00079    if (t>=end) {
00080       LM_ERR("strange EoHF\n");
00081       goto error;
00082    }
00083    if (*t=='\r' && t+1<end && *(t+1)=='\n') {
00084          cb->error=PARSE_OK;
00085          return t+2;
00086    }
00087    if (*t=='\n') {
00088          cb->error=PARSE_OK;
00089          return t+1;
00090    }
00091    LM_ERR("expecting CSeq EoL\n");
00092 
00093 error:
00094    LM_ERR("bad cseq\n");
00095    return t;
00096 }
00097 
00098 
00099 void free_cseq(struct cseq_body* cb)
00100 {
00101    pkg_free(cb);
00102 }

Generated on Thu May 24 00:00:28 2012 for Kamailio - The Open Source SIP Server by  doxygen 1.5.6