parse_supported.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * $Id$
  3. *
  4. * Copyright (C) 2006 Andreas Granig <[email protected]>
  5. *
  6. * This file is part of Kamailio, a free SIP server.
  7. *
  8. * Kamailio 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. * Kamailio is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. */
  22. /*!
  23. * \file
  24. * \brief Supported parser
  25. * \ingroup parser
  26. */
  27. #include "../mem/mem.h"
  28. #include "parse_supported.h"
  29. /*!
  30. * Parse all Supported headers
  31. */
  32. int parse_supported( struct sip_msg *msg)
  33. {
  34. unsigned int supported;
  35. struct hdr_field *hdr;
  36. struct option_tag_body *sb;
  37. /* maybe the header is already parsed! */
  38. if (msg->supported && msg->supported->parsed)
  39. return 0;
  40. /* parse to the end in order to get all SUPPORTED headers */
  41. if (parse_headers(msg,HDR_EOH_F,0)==-1 || !msg->supported)
  42. return -1;
  43. /* bad luck! :-( - we have to parse them */
  44. supported = 0;
  45. for( hdr=msg->supported ; hdr ; hdr=next_sibling_hdr(hdr)) {
  46. if (hdr->parsed) {
  47. supported |= ((struct option_tag_body*)hdr->parsed)->option_tags;
  48. continue;
  49. }
  50. sb = (struct option_tag_body*)pkg_malloc(sizeof(struct option_tag_body));
  51. if (sb == 0) {
  52. LM_ERR("out of pkg_memory\n");
  53. return -1;
  54. }
  55. parse_option_tag_body(&(hdr->body), &(sb->option_tags));
  56. sb->hfree = hf_free_option_tag;
  57. sb->option_tags_all = 0;
  58. hdr->parsed = (void*)sb;
  59. supported |= sb->option_tags;
  60. }
  61. ((struct option_tag_body*)msg->supported->parsed)->option_tags_all =
  62. supported;
  63. return 0;
  64. }