parse_rpid.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * Copyright (C) 2001-2003 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 :: Remote-party-id: 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 RPID header.
  35. *
  36. * params: msg : sip msg
  37. * returns 0 on success,
  38. * -1 on failure.
  39. */
  40. int parse_rpid_header( struct sip_msg *msg )
  41. {
  42. struct to_body* rpid_b;
  43. if ( !msg->rpid && (parse_headers(msg, HDR_RPID_F, 0)==-1 || !msg->rpid)) {
  44. goto error;
  45. }
  46. /* maybe the header is already parsed! */
  47. if (msg->rpid->parsed)
  48. return 0;
  49. /* bad luck! :-( - we have to parse it */
  50. /* first, get some memory */
  51. rpid_b = pkg_malloc(sizeof(struct to_body));
  52. if (rpid_b == 0) {
  53. LOG(L_ERR, "ERROR:parse_rpid_header: out of pkg_memory\n");
  54. goto error;
  55. }
  56. /* now parse it!! */
  57. memset(rpid_b, 0, sizeof(struct to_body));
  58. parse_to(msg->rpid->body.s,msg->rpid->body.s+msg->rpid->body.len+1,rpid_b);
  59. if (rpid_b->error == PARSE_ERROR) {
  60. LOG(L_ERR, "ERROR:parse_rpid_header: bad rpid header\n");
  61. free_to(rpid_b);
  62. goto error;
  63. }
  64. msg->rpid->parsed = rpid_b;
  65. return 0;
  66. error:
  67. return -1;
  68. }