parse_from.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. /*! \file
  28. * \brief Parser :: SIP From header parsing
  29. *
  30. * \ingroup parser
  31. */
  32. #include "parse_from.h"
  33. #include "parse_to.h"
  34. #include <stdlib.h>
  35. #include <string.h>
  36. #include "../dprint.h"
  37. #include "msg_parser.h"
  38. #include "../ut.h"
  39. #include "../mem/mem.h"
  40. /*! \brief
  41. * This method is used to parse the from header.
  42. *
  43. * \note It was decided not to parse
  44. * anything in core that is not *needed* so this method gets called by
  45. * rad_acc module and any other modules that needs the FROM header.
  46. *
  47. * params: msg : sip msg
  48. * returns 0 on success,
  49. * -1 on failure.
  50. */
  51. int parse_from_header( struct sip_msg *msg)
  52. {
  53. struct to_body* from_b;
  54. if ( !msg->from && ( parse_headers(msg,HDR_FROM_F,0)==-1 || !msg->from)) {
  55. LOG(L_ERR,"ERROR:parse_from_header: bad msg or missing FROM header\n");
  56. goto error;
  57. }
  58. /* maybe the header is already parsed! */
  59. if (msg->from->parsed)
  60. return 0;
  61. /* bad luck! :-( - we have to parse it */
  62. /* first, get some memory */
  63. from_b = pkg_malloc(sizeof(struct to_body));
  64. if (from_b == 0) {
  65. LOG(L_ERR, "ERROR:parse_from_header: out of pkg_memory\n");
  66. goto error;
  67. }
  68. /* now parse it!! */
  69. memset(from_b, 0, sizeof(struct to_body));
  70. parse_to(msg->from->body.s,msg->from->body.s+msg->from->body.len+1,from_b);
  71. if (from_b->error == PARSE_ERROR) {
  72. LOG(L_ERR, "ERROR:parse_from_header: bad from header\n");
  73. pkg_free(from_b);
  74. goto error;
  75. }
  76. msg->from->parsed = from_b;
  77. return 0;
  78. error:
  79. return -1;
  80. }