parse_cseq.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. * ser 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. * History:
  21. * --------
  22. * 2003-02-28 scratchpad compatibility abandoned (jiri)
  23. * 2003-01-22 zero-termination in CSeq eliminated (jiri)
  24. */
  25. /*! \file
  26. * \brief Parser :: Cseq header field handling
  27. *
  28. * \ingroup parser
  29. */
  30. #include "../comp_defs.h"
  31. #include "parse_cseq.h"
  32. #include "parser_f.h" /* eat_space_end and so on */
  33. #include "../dprint.h"
  34. #include "parse_def.h"
  35. #include "parse_methods.h"
  36. #include "../mem/mem.h"
  37. /*BUGGY*/
  38. char* parse_cseq(char* const buf, const char* const end, struct cseq_body* const cb)
  39. {
  40. char *t, *m, *m_end;
  41. cb->error=PARSE_ERROR;
  42. t=buf;
  43. cb->number.s=t;
  44. t=eat_token_end(t, end);
  45. if (t>=end) goto error;
  46. cb->number.len=t-cb->number.s;
  47. m=eat_space_end(t, end);
  48. m_end=eat_token_end(m, end);
  49. if (m_end>=end) {
  50. LOG(L_ERR, "ERROR: parse_cseq: "
  51. "method terminated unexpectedly\n");
  52. goto error;
  53. }
  54. if (m_end==m){
  55. /* null method*/
  56. LOG(L_ERR, "ERROR:parse_cseq: no method found\n");
  57. goto error;
  58. }
  59. cb->method.s=m;
  60. t=m_end;
  61. cb->method.len=t-cb->method.s;
  62. /* Cache method id */
  63. if (parse_method_name(&cb->method, &cb->method_id)!=0){
  64. LOG(L_ERR, "Cannot parse method string\n");
  65. goto error;
  66. }
  67. /* there may be trailing LWS
  68. * (it was not my idea to put it in SIP; -jiri )
  69. */
  70. t=eat_lws_end(t, end);
  71. /*check if the header ends here*/
  72. if (t>=end) {
  73. LOG(L_ERR, "ERROR: parse_cseq: strange EoHF\n");
  74. goto error;
  75. }
  76. if (*t=='\r' && t+1<end && *(t+1)=='\n') {
  77. cb->error=PARSE_OK;
  78. return t+2;
  79. }
  80. if (*t=='\n') {
  81. cb->error=PARSE_OK;
  82. return t+1;
  83. }
  84. LOG(L_ERR, "ERROR: CSeq EoL expected\n");
  85. error:
  86. LOG(L_ERR, "ERROR: parse_cseq: bad cseq\n");
  87. return t;
  88. }
  89. void free_cseq(struct cseq_body* const cb)
  90. {
  91. pkg_free(cb);
  92. }