parser_f.h 2.9 KB

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