parser_f.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. * $Id$
  3. *
  4. * Copyright (C) 2001-2003 FhG Fokus
  5. *
  6. * This file is part of ser, a free SIP server.
  7. *
  8. * ser is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version
  12. *
  13. * For a license to use the ser software under conditions
  14. * other than those described here, or to purchase support for this
  15. * software, please contact iptel.org by e-mail at the following addresses:
  16. * [email protected]
  17. *
  18. * ser is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * along with this program; if not, write to the Free Software
  25. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  26. *
  27. * History
  28. * --------
  29. * 2003-02-28 scratchpad compatibility abandoned (jiri)
  30. * 2003-03-24 find_not_quoted function added (janakj)
  31. */
  32. /*! \file
  33. * \brief Parser :: Parser helper functions
  34. *
  35. * turn the most frequently called functions into inline functions
  36. *
  37. * \ingroup parser
  38. */
  39. #ifndef parser_f_h
  40. #define parser_f_h
  41. #include "../comp_defs.h"
  42. #include "../str.h"
  43. char* eat_line(char* buffer, unsigned int len);
  44. /* turn the most frequently called functions into inline functions */
  45. inline static char* eat_space_end(const char* p, const char* pend)
  46. {
  47. for(;(p<pend)&&(*p==' ' || *p=='\t') ;p++);
  48. return (char *)p;
  49. }
  50. #define SP(_c) ((_c)=='\t' || (_c)==' ')
  51. inline static char* eat_lws_end(const char* p, const char* pend)
  52. {
  53. while(p<pend) {
  54. if (SP(*p)) p++;
  55. /* BTW--I really dislike line folding; -jiri */
  56. else if (*p=='\n' && p+1<pend && SP(*(p+1))) p+=2;
  57. else if (*p=='\r' && p+2<pend && *(p+1)=='\n'
  58. && SP(*(p+2))) p+=3;
  59. else break; /* no whitespace encountered */
  60. }
  61. return (char *)p;
  62. }
  63. inline static char* eat_token_end(const char* p, const char* pend)
  64. {
  65. for (;(p<pend)&&(*p!=' ')&&(*p!='\t')&&(*p!='\n')&&(*p!='\r'); p++);
  66. return (char *)p;
  67. }
  68. inline static char* eat_token2_end(const char* p, const char* pend, char delim)
  69. {
  70. for (;(p<pend)&&(*p!=(delim))&&(*p!='\n')&&(*p!='\r'); p++);
  71. return (char *)p;
  72. }
  73. inline static int is_empty_end(const char* p, const char* pend )
  74. {
  75. p=eat_space_end(p, pend );
  76. return ((p<(pend )) && (*p=='\r' || *p=='\n'));
  77. }
  78. /*
  79. * Find a character occurrence that is not quoted
  80. */
  81. inline static char* find_not_quoted(str* _s, char _c)
  82. {
  83. int quoted = 0, i;
  84. for(i = 0; i < _s->len; i++) {
  85. if (!quoted) {
  86. if (_s->s[i] == '\"') quoted = 1;
  87. else if (_s->s[i] == _c) return _s->s + i;
  88. } else {
  89. if ((_s->s[i] == '\"') && (_s->s[i - 1] != '\\')) quoted = 0;
  90. }
  91. }
  92. return 0;
  93. }
  94. #endif /* parser_f_h */