parse_refer_to.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * Copyright (C) 2005 Juha Heinanen
  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. /*! \file
  21. * \brief Parser :: Refert-To: header parser
  22. *
  23. * \ingroup parser
  24. */
  25. #include "parse_from.h"
  26. #include "parse_to.h"
  27. #include <stdlib.h>
  28. #include <string.h>
  29. #include "../dprint.h"
  30. #include "msg_parser.h"
  31. #include "../ut.h"
  32. #include "../mem/mem.h"
  33. /*! \brief
  34. * This method is used to parse Refer-To header.
  35. *
  36. * params: msg : sip msg
  37. * returns 0 on success,
  38. * -1 on failure.
  39. */
  40. int parse_refer_to_header( struct sip_msg *msg )
  41. {
  42. struct to_body* refer_to_b;
  43. if ( !msg->refer_to &&
  44. (parse_headers(msg, HDR_REFER_TO_F,0)==-1 || !msg->refer_to)) {
  45. goto error;
  46. }
  47. /* maybe the header is already parsed! */
  48. if (msg->refer_to->parsed)
  49. return 0;
  50. /* bad luck! :-( - we have to parse it */
  51. /* first, get some memory */
  52. refer_to_b = pkg_malloc(sizeof(struct to_body));
  53. if (refer_to_b == 0) {
  54. LOG(L_ERR, "ERROR:parse_refer_to_header: out of pkg_memory\n");
  55. goto error;
  56. }
  57. /* now parse it!! */
  58. memset(refer_to_b, 0, sizeof(struct to_body));
  59. parse_to(msg->refer_to->body.s,
  60. msg->refer_to->body.s + msg->refer_to->body.len+1,
  61. refer_to_b);
  62. if (refer_to_b->error == PARSE_ERROR) {
  63. LOG(L_ERR, "ERROR:parse_refer_to_header: bad Refer-To header\n");
  64. free_to(refer_to_b);
  65. goto error;
  66. }
  67. msg->refer_to->parsed = refer_to_b;
  68. return 0;
  69. error:
  70. return -1;
  71. }