parse_sipifmatch.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. * Copyright (C) 2004 Jamey Hicks, jamey dot hicks at hp dot com
  3. *
  4. * This file is part of SIP-router, a free SIP server.
  5. *
  6. * SIP-router 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. * SIP-router is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. /*! \file
  21. * \brief Parser :: Parse if-match header
  22. *
  23. * \ingroup parser
  24. */
  25. #include <string.h>
  26. #include "parse_sipifmatch.h"
  27. #include "../dprint.h"
  28. #include "parse_def.h"
  29. #include "../mem/mem.h"
  30. #include "../trim.h"
  31. static inline char* skip_token(char* _b, int _l)
  32. {
  33. int i = 0;
  34. for(i = 0; i < _l; i++) {
  35. switch(_b[i]) {
  36. case ' ':
  37. case '\r':
  38. case '\n':
  39. case '\t':
  40. case ';':
  41. return _b + i;
  42. }
  43. }
  44. return _b + _l;
  45. }
  46. int etag_parser(char *_s, int _l, str *_e)
  47. {
  48. char* end;
  49. _e->s = _s;
  50. _e->len = _l;
  51. trim_leading(_e);
  52. if (_e->len == 0) {
  53. LOG(L_ERR, "etag_parser(): Empty body\n");
  54. return -1;
  55. }
  56. end = skip_token(_e->s, _e->len);
  57. _e->len = end - _e->s;
  58. return 0;
  59. }
  60. int parse_sipifmatch(struct hdr_field* _h)
  61. {
  62. str *e;
  63. DBG("parse_sipifmatch() called\n");
  64. if (_h->parsed != 0) {
  65. return 0;
  66. }
  67. e = (str*)pkg_malloc(sizeof(str));
  68. if (e == 0) {
  69. LOG(L_ERR, "parse_ifsipmatch(): No memory left\n");
  70. return -1;
  71. }
  72. memset(e, 0, sizeof(str));
  73. if (etag_parser(_h->body.s, _h->body.len, e) < 0) {
  74. LOG(L_ERR, "parse_sipifmatch(): Error in tag_parser\n");
  75. pkg_free(e);
  76. return -2;
  77. }
  78. _h->parsed = (void*)e;
  79. return 0;
  80. }
  81. void free_sipifmatch(str** _e)
  82. {
  83. if (*_e)
  84. pkg_free(*_e);
  85. *_e = 0;
  86. }