parse_to.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * Copyright (C) 2001-2003 Fhg Fokus
  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. * History:
  21. * ---------
  22. * 2003-04-26 ZSW (jiri)
  23. * 2010-03-03 fix multi-token no-quotes display name (andrei)
  24. */
  25. /** Parser :: Parse To: header.
  26. * @file
  27. * @ingroup parser
  28. */
  29. #include "parse_to.h"
  30. #include "parse_addr_spec.h"
  31. #include <stdlib.h>
  32. #include <string.h>
  33. #include "../dprint.h"
  34. #include "msg_parser.h"
  35. #include "parse_uri.h"
  36. #include "../ut.h"
  37. #include "../mem/mem.h"
  38. char* parse_to(char* const buffer, const char* const end, struct to_body* const to_b)
  39. {
  40. return parse_addr_spec(buffer, end, to_b, 0);
  41. }
  42. int parse_to_header(struct sip_msg* const msg)
  43. {
  44. if ( !msg->to && ( parse_headers(msg,HDR_TO_F,0)==-1 || !msg->to)) {
  45. ERR("bad msg or missing TO header\n");
  46. return -1;
  47. }
  48. // HDR_TO_T is automatically parsed (get_hdr_field in parser/msg_parser.c)
  49. // so check only ptr validity
  50. if (msg->to->parsed)
  51. return 0;
  52. else
  53. return -1;
  54. }
  55. sip_uri_t *parse_to_uri(sip_msg_t* const msg)
  56. {
  57. to_body_t *tb = NULL;
  58. if(msg==NULL)
  59. return NULL;
  60. if(parse_to_header(msg)<0)
  61. {
  62. LM_ERR("cannot parse TO header\n");
  63. return NULL;
  64. }
  65. if(msg->to==NULL || get_to(msg)==NULL)
  66. return NULL;
  67. tb = get_to(msg);
  68. if(tb->parsed_uri.user.s!=NULL || tb->parsed_uri.host.s!=NULL)
  69. return &tb->parsed_uri;
  70. if (parse_uri(tb->uri.s, tb->uri.len , &tb->parsed_uri)<0)
  71. {
  72. LM_ERR("failed to parse To uri\n");
  73. memset(&tb->parsed_uri, 0, sizeof(struct sip_uri));
  74. return NULL;
  75. }
  76. return &tb->parsed_uri;
  77. }