parse_from.c 2.3 KB

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