parse_cseq.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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-01-22 zero-termination in CSeq eliminated (jiri)
  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 "../mem/mem.h"
  38. /*
  39. * Parse CSeq header field
  40. */
  41. /*BUGGY*/
  42. char* parse_cseq(char *buf, char* end, struct cseq_body* cb)
  43. {
  44. char *t, *m, *m_end;
  45. cb->error=PARSE_ERROR;
  46. t=buf;
  47. cb->number.s=t;
  48. t=eat_token_end(t, end);
  49. if (t>=end) goto error;
  50. cb->number.len=t-cb->number.s;
  51. m=eat_space_end(t, end);
  52. m_end=eat_token_end(m, end);
  53. if (m_end>=end) {
  54. LOG(L_ERR, "ERROR: parse_cseq: "
  55. "method terminated unexpectedly\n");
  56. goto error;
  57. }
  58. if (m_end==m){
  59. /* null method*/
  60. LOG(L_ERR, "ERROR:parse_cseq: no method found\n");
  61. goto error;
  62. }
  63. cb->method.s=m;
  64. t=m_end;
  65. cb->method.len=t-cb->method.s;
  66. /* there may be trailing LWS
  67. * (it was not my idea to put it in SIP; -jiri )
  68. */
  69. t=eat_lws_end(t, end);
  70. /*check if the header ends here*/
  71. if (t>=end) {
  72. LOG(L_ERR, "ERROR: parse_cseq: strange EoHF\n");
  73. goto error;
  74. }
  75. if (*t=='\r' && t+1<end && *(t+1)=='\n') {
  76. cb->error=PARSE_OK;
  77. return t+2;
  78. }
  79. if (*t=='\n') {
  80. cb->error=PARSE_OK;
  81. return t+1;
  82. }
  83. LOG(L_ERR, "ERROR: CSeq EoL expected\n");
  84. error:
  85. LOG(L_ERR, "ERROR: parse_cseq: bad cseq\n");
  86. return t;
  87. }
  88. void free_cseq(struct cseq_body* cb)
  89. {
  90. pkg_free(cb);
  91. }