parse_cseq.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. * ser is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. *
  22. * History:
  23. * --------
  24. * 2003-02-28 scratchpad compatibility abandoned (jiri)
  25. * 2003-01-22 zero-termination in CSeq eliminated (jiri)
  26. */
  27. /*! \file
  28. * \brief Parser :: Cseq header field handling
  29. *
  30. * \ingroup parser
  31. */
  32. #include "../comp_defs.h"
  33. #include "parse_cseq.h"
  34. #include "parser_f.h" /* eat_space_end and so on */
  35. #include "../dprint.h"
  36. #include "parse_def.h"
  37. #include "parse_methods.h"
  38. #include "../mem/mem.h"
  39. /*BUGGY*/
  40. char* parse_cseq(char *buf, char* end, struct cseq_body* cb)
  41. {
  42. char *t, *m, *m_end;
  43. cb->error=PARSE_ERROR;
  44. t=buf;
  45. cb->number.s=t;
  46. t=eat_token_end(t, end);
  47. if (t>=end) goto error;
  48. cb->number.len=t-cb->number.s;
  49. m=eat_space_end(t, end);
  50. m_end=eat_token_end(m, end);
  51. if (m_end>=end) {
  52. LOG(L_ERR, "ERROR: parse_cseq: "
  53. "method terminated unexpectedly\n");
  54. goto error;
  55. }
  56. if (m_end==m){
  57. /* null method*/
  58. LOG(L_ERR, "ERROR:parse_cseq: no method found\n");
  59. goto error;
  60. }
  61. cb->method.s=m;
  62. t=m_end;
  63. cb->method.len=t-cb->method.s;
  64. /* Cache method id */
  65. if (parse_method_name(&cb->method, &cb->method_id)!=0){
  66. LOG(L_ERR, "Cannot parse method string\n");
  67. goto error;
  68. }
  69. /* there may be trailing LWS
  70. * (it was not my idea to put it in SIP; -jiri )
  71. */
  72. t=eat_lws_end(t, end);
  73. /*check if the header ends here*/
  74. if (t>=end) {
  75. LOG(L_ERR, "ERROR: parse_cseq: strange EoHF\n");
  76. goto error;
  77. }
  78. if (*t=='\r' && t+1<end && *(t+1)=='\n') {
  79. cb->error=PARSE_OK;
  80. return t+2;
  81. }
  82. if (*t=='\n') {
  83. cb->error=PARSE_OK;
  84. return t+1;
  85. }
  86. LOG(L_ERR, "ERROR: CSeq EoL expected\n");
  87. error:
  88. LOG(L_ERR, "ERROR: parse_cseq: bad cseq\n");
  89. return t;
  90. }
  91. void free_cseq(struct cseq_body* cb)
  92. {
  93. pkg_free(cb);
  94. }