parse_cseq.c

Go to the documentation of this file.
00001 /* 
00002  * $Id$ 
00003  *
00004  * Copyright (C) 2001-2003 FhG Fokus
00005  *
00006  * This file is part of ser, a free SIP server.
00007  *
00008  * ser 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  * ser 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  * History:
00023  * --------
00024  * 2003-02-28 scratchpad compatibility abandoned (jiri)
00025  * 2003-01-22 zero-termination in CSeq eliminated (jiri)
00026  */
00027 
00036 #include "../comp_defs.h"
00037 #include "parse_cseq.h"
00038 #include "parser_f.h"  /* eat_space_end and so on */
00039 #include "../dprint.h"
00040 #include "parse_def.h"
00041 #include "parse_methods.h"
00042 #include "../mem/mem.h"
00043 
00044 /*BUGGY*/
00045 char* parse_cseq(char *buf, char* end, struct cseq_body* cb)
00046 {
00047         char *t, *m, *m_end;
00048         
00049         cb->error=PARSE_ERROR;
00050         t=buf;
00051         
00052         cb->number.s=t;
00053         t=eat_token_end(t, end);
00054         if (t>=end) goto error;
00055         cb->number.len=t-cb->number.s;
00056 
00057         m=eat_space_end(t, end);
00058         m_end=eat_token_end(m, end);
00059 
00060         if (m_end>=end) {
00061                         LOG(L_ERR, "ERROR: parse_cseq: "
00062                                                 "method terminated unexpectedly\n");
00063                         goto error;
00064         }
00065         if (m_end==m){
00066                 /* null method*/
00067                 LOG(L_ERR,  "ERROR:parse_cseq: no method found\n");
00068                 goto error;
00069         }
00070         cb->method.s=m;
00071         t=m_end;
00072         cb->method.len=t-cb->method.s;
00073 
00074         /* Cache method id */
00075         if (parse_method_name(&cb->method, &cb->method_id)!=0){
00076                 LOG(L_ERR, "Cannot parse method string\n");
00077                 goto error;
00078         }
00079 
00080         /* there may be trailing LWS 
00081          * (it was not my idea to put it in SIP; -jiri )
00082          */
00083         t=eat_lws_end(t, end);
00084         /*check if the header ends here*/
00085         if (t>=end) {
00086                 LOG(L_ERR, "ERROR: parse_cseq: strange EoHF\n");
00087                 goto error;
00088         }
00089         if (*t=='\r' && t+1<end && *(t+1)=='\n') {
00090                         cb->error=PARSE_OK;
00091                         return t+2;
00092         }
00093         if (*t=='\n') {
00094                         cb->error=PARSE_OK;
00095                         return t+1;
00096         }
00097         LOG(L_ERR, "ERROR: CSeq EoL expected\n");
00098 
00099 error:
00100         LOG(L_ERR, "ERROR: parse_cseq: bad cseq\n");
00101         return t;
00102 }
00103 
00104 
00105 void free_cseq(struct cseq_body* cb)
00106 {
00107         pkg_free(cb);
00108 }