parse_cseq.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. #include "parse_cseq.h"
  28. #include "parser_f.h" /* eat_space_end and so on */
  29. #include "../dprint.h"
  30. #include "parse_def.h"
  31. #include "../mem/mem.h"
  32. /*
  33. * Parse CSeq header field
  34. */
  35. /*BUGGY*/
  36. char* parse_cseq(char *buf, char* end, struct cseq_body* cb)
  37. {
  38. char *t, *m, *m_end;
  39. char c;
  40. cb->error=PARSE_ERROR;
  41. t=eat_space_end(buf, end);
  42. if (t>=end) goto error;
  43. cb->number.s=t;
  44. t=eat_token_end(t, end);
  45. if (t>=end) goto error;
  46. m=eat_space_end(t, end);
  47. m_end=eat_token_end(m, end);
  48. *t=0; /*null terminate it*/
  49. cb->number.len=t-cb->number.s;
  50. if (m_end>=end) goto error;
  51. if (m_end==m){
  52. /* null method*/
  53. LOG(L_ERR, "ERROR:parse_cseq: no method found\n");
  54. goto error;
  55. }
  56. cb->method.s=m;
  57. t=m_end;
  58. c=*t;
  59. *t=0; /*null terminate it*/
  60. cb->method.len=t-cb->method.s;
  61. t++;
  62. /*check if the header ends here*/
  63. if (c=='\n') goto check_continue;
  64. do{
  65. for (;(t<end)&&((*t==' ')||(*t=='\t')||(*t=='\r'));t++);
  66. if (t>=end) goto error;
  67. if (*t!='\n'){
  68. LOG(L_ERR, "ERROR:parse_cseq: unexpected char <%c> at end of"
  69. " cseq\n", *t);
  70. goto error;
  71. }
  72. t++;
  73. check_continue:
  74. ;
  75. }while( (t<end) && ((*t==' ')||(*t=='\t')) );
  76. cb->error=PARSE_OK;
  77. return t;
  78. error:
  79. LOG(L_ERR, "ERROR: parse_cseq: bad cseq\n");
  80. return t;
  81. }
  82. void free_cseq(struct cseq_body* cb)
  83. {
  84. pkg_free(cb);
  85. }