parser_f.h

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  * For a license to use the ser software under conditions
00014  * other than those described here, or to purchase support for this
00015  * software, please contact iptel.org by e-mail at the following addresses:
00016  *    info@iptel.org
00017  *
00018  * ser is distributed in the hope that it will be useful,
00019  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00020  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00021  * GNU General Public License for more details.
00022  *
00023  * You should have received a copy of the GNU General Public License 
00024  * along with this program; if not, write to the Free Software 
00025  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00026  *
00027  * History
00028  * --------
00029  * 2003-02-28 scratchpad compatibility abandoned (jiri)
00030  * 2003-03-24 find_not_quoted function added (janakj)
00031  */
00032 
00043 #ifndef parser_f_h
00044 #define parser_f_h
00045 
00046 #include "../comp_defs.h"
00047 #include "../str.h"
00048 
00049 char* eat_line(char* buffer, unsigned int len);
00050 
00051 /* turn the most frequently called functions into inline functions */
00052 
00053 inline static char* eat_space_end(const char* p, const char* pend)
00054 {
00055         for(;(p<pend)&&(*p==' ' || *p=='\t') ;p++);
00056         return (char *)p;
00057 }
00058 #define SP(_c) ((_c)=='\t' || (_c)==' ')
00059 inline static char* eat_lws_end(const char* p, const char* pend)
00060 {
00061         while(p<pend) {
00062                 if (SP(*p)) p++;
00063                 /* BTW--I really dislike line folding; -jiri */
00064                 else if (*p=='\n' && p+1<pend && SP(*(p+1))) p+=2;
00065                 else if (*p=='\r' && p+2<pend && *(p+1)=='\n'
00066                                         && SP(*(p+2))) p+=3;
00067                 else break; /* no whitespace encountered */
00068         }
00069         return (char *)p;
00070 }
00071 
00072 
00073 
00074 inline static char* eat_token_end(const char* p, const char* pend)
00075 {
00076         for (;(p<pend)&&(*p!=' ')&&(*p!='\t')&&(*p!='\n')&&(*p!='\r'); p++);
00077         return (char *)p;
00078 }
00079 
00080 
00081 
00082 inline static char* eat_token2_end(const char* p, const char* pend, char delim)
00083 {
00084         for (;(p<pend)&&(*p!=(delim))&&(*p!='\n')&&(*p!='\r'); p++);
00085         return (char *)p;
00086 }
00087 
00088 
00089 
00090 inline static int is_empty_end(const char* p, const char* pend )
00091 {
00092         p=eat_space_end(p, pend );
00093         return ((p<(pend )) && (*p=='\r' || *p=='\n'));
00094 }
00095 
00096 
00097 /*
00098  * Find a character occurrence that is not quoted
00099  */
00100 inline static char* find_not_quoted(str* _s, char _c)
00101 {
00102         int quoted = 0, i;
00103         
00104         for(i = 0; i < _s->len; i++) {
00105                 if (!quoted) {
00106                         if (_s->s[i] == '\"') quoted = 1;
00107                         else if (_s->s[i] == _c) return _s->s + i;
00108                 } else {
00109                         if ((_s->s[i] == '\"') && (_s->s[i - 1] != '\\')) quoted = 0;
00110                 }
00111         }
00112         return 0;
00113 }
00114 
00115 
00116 #endif /* parser_f_h */