parser_f.h

Go to the documentation of this file.
00001 /* 
00002  * $Id: parser_f.h 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 Parser helper functions
00026  * \ingroup parser
00027  */
00028 
00029 #ifndef parser_f_h
00030 #define parser_f_h
00031 
00032 #include "../str.h"
00033 
00034 char* eat_line(char* buffer, unsigned int len);
00035 
00036 /* turn the most frequently called functions into inline functions */
00037 
00038 inline static char* eat_space_end(const char* p, const char* pend)
00039 {
00040    for(;(p<pend)&&(*p==' ' || *p=='\t') ;p++);
00041    return (char *)p;
00042 }
00043 #define SP(_c) ((_c)=='\t' || (_c)==' ')
00044 inline static char* eat_lws_end(const char* p, const char* pend)
00045 {
00046    while(p<pend) {
00047       if (SP(*p)) p++;
00048       else if (*p=='\n' && p+1<pend && SP(*(p+1))) p+=2;
00049       else if (*p=='\r' && p+2<pend && *(p+1)=='\n'
00050                && SP(*(p+2))) p+=3;
00051       else break; /* no whitespace encountered */
00052    }
00053    return (char *)p;
00054 }
00055 
00056 
00057 
00058 inline static char* eat_token_end(const char* p, const char* pend)
00059 {
00060    for (;(p<pend)&&(*p!=' ')&&(*p!='\t')&&(*p!='\n')&&(*p!='\r'); p++);
00061    return (char *)p;
00062 }
00063 
00064 
00065 
00066 inline static char* eat_token2_end(const char* p, const char* pend, char delim)
00067 {
00068    for (;(p<pend)&&(*p!=(delim))&&(*p!='\n')&&(*p!='\r'); p++);
00069    return (char *)p;
00070 }
00071 
00072 
00073 
00074 inline static int is_empty_end(const char* p, const char* pend )
00075 {
00076    p=eat_space_end(p, pend );
00077    return ((p<(pend )) && (*p=='\r' || *p=='\n'));
00078 }
00079 
00080 
00081 /*
00082  * Find a character occurrence that is not quoted
00083  */
00084 inline static char* find_not_quoted(str* _s, char _c)
00085 {
00086    int quoted = 0, i;
00087    
00088    for(i = 0; i < _s->len; i++) {
00089       if (!quoted) {
00090          if (_s->s[i] == '\"') quoted = 1;
00091          else if (_s->s[i] == _c) return _s->s + i;
00092       } else {
00093          if ((_s->s[i] == '\"') && (_s->s[i - 1] != '\\')) quoted = 0;
00094       }
00095    }
00096    return 0;
00097 }
00098 
00099 
00100 #endif /* parser_f_h */

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