parser_f.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. #ifndef parser_f_h
  33. #define parser_f_h
  34. #include "../comp_defs.h"
  35. #include "../str.h"
  36. char* eat_line(char* buffer, unsigned int len);
  37. /* turn the most frequently called functions into inline functions */
  38. inline static char* eat_space_end(char* p, char* pend)
  39. {
  40. for(;(p<pend)&&(*p==' ' || *p=='\t') ;p++);
  41. return p;
  42. }
  43. #define SP(_c) ((_c)=='\t' || (_c)==' ')
  44. inline static char* eat_lws_end(char* p, char* pend)
  45. {
  46. while(p<pend) {
  47. if (SP(*p)) p++;
  48. /* btw--I really dislike line folding; -jiri */
  49. else if (*p=='\n' && p+1<pend && SP(*(p+1))) p+=2;
  50. else if (*p=='\r' && p+2<pend && *(p+1)=='\n'
  51. && SP(*(p+2))) p+=3;
  52. else break; /* no whitespace encountered */
  53. }
  54. return p;
  55. }
  56. inline static char* eat_token_end(char* p, char* pend)
  57. {
  58. for (;(p<pend)&&(*p!=' ')&&(*p!='\t')&&(*p!='\n')&&(*p!='\r'); p++);
  59. return p;
  60. }
  61. inline static char* eat_token2_end(char* p, char* pend, char delim)
  62. {
  63. for (;(p<pend)&&(*p!=(delim))&&(*p!='\n')&&(*p!='\r'); p++);
  64. return p;
  65. }
  66. inline static int is_empty_end(char* p, char* pend )
  67. {
  68. p=eat_space_end(p, pend );
  69. return ((p<(pend )) && (*p=='\r' || *p=='\n'));
  70. }
  71. /*
  72. * Find a character occurence that is not quoted
  73. */
  74. inline static char* find_not_quoted(str* _s, char _c)
  75. {
  76. int quoted = 0, i;
  77. for(i = 0; i < _s->len; i++) {
  78. if (!quoted) {
  79. if (_s->s[i] == '\"') quoted = 1;
  80. else if (_s->s[i] == _c) return _s->s + i;
  81. } else {
  82. if ((_s->s[i] == '\"') && (_s->s[i - 1] != '\\')) quoted = 0;
  83. }
  84. }
  85. return 0;
  86. }
  87. #endif /* parser_f_h */