route.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 2013, Digium, Inc.
  5. *
  6. * See http://www.asterisk.org for more information about
  7. * the Asterisk project. Please do not directly contact
  8. * any of the maintainers of this project for assistance;
  9. * the project provides a web site, mailing lists and IRC
  10. * channels for your use.
  11. *
  12. * This program is free software, distributed under the terms of
  13. * the GNU General Public License Version 2. See the LICENSE file
  14. * at the top of the source tree.
  15. */
  16. /*!
  17. * \file
  18. * \brief sip_route header file
  19. */
  20. #ifndef _SIP_ROUTE_H
  21. #define _SIP_ROUTE_H
  22. #include "asterisk/linkedlists.h"
  23. #include "asterisk/strings.h"
  24. /*!
  25. * \brief Opaque storage of a sip route hop
  26. */
  27. struct sip_route_hop;
  28. /*!
  29. * \internal \brief Internal enum to remember last calculated
  30. */
  31. enum sip_route_type {
  32. route_loose = 0, /*!< The first hop contains ;lr or does not exist */
  33. route_strict, /*!< The first hop exists and does not contain ;lr */
  34. route_invalidated, /*!< strict/loose routing needs to be rechecked */
  35. };
  36. /*!
  37. * \brief Structure to store route information
  38. *
  39. * \note This must be zero-filled on allocation
  40. */
  41. struct sip_route {
  42. AST_LIST_HEAD_NOLOCK(, sip_route_hop) list;
  43. enum sip_route_type type;
  44. };
  45. /*!
  46. * \brief Add a new hop to the route
  47. *
  48. * \param route Route
  49. * \param uri Address of this hop
  50. * \param len Length of hop not including null terminator
  51. * \param inserthead If true then inserted the new route to the top of the list
  52. *
  53. * \retval Pointer to null terminated copy of URI on success
  54. * \retval NULL on error
  55. */
  56. const char *sip_route_add(struct sip_route *route, const char *uri, size_t len, int inserthead);
  57. /*!
  58. * \brief Add routes from header
  59. *
  60. * \note This procedure is for headers that require use of <brackets>.
  61. */
  62. void sip_route_process_header(struct sip_route *route, const char *header, int inserthead);
  63. /*!
  64. * \brief copy route-set
  65. *
  66. * \retval non-zero on failure
  67. * \retval 0 on success
  68. */
  69. void sip_route_copy(struct sip_route *dst, const struct sip_route *src);
  70. /*!
  71. * \brief Free all routes in the list
  72. */
  73. void sip_route_clear(struct sip_route *route);
  74. /*!
  75. * \brief Verbose dump of all hops for debugging
  76. */
  77. void sip_route_dump(const struct sip_route *route);
  78. /*!
  79. * \brief Make the comma separated list of route hops
  80. *
  81. * \param route Source of route list
  82. * \param formatcli Add's space after comma's, print's N/A if list is empty.
  83. * \param skip Number of hops to skip
  84. *
  85. * \retval an allocated struct ast_str on success
  86. * \retval NULL on failure
  87. */
  88. struct ast_str *sip_route_list(const struct sip_route *route, int formatcli, int skip)
  89. __attribute__((__malloc__)) __attribute__((__warn_unused_result__));
  90. /*!
  91. * \brief Check if the route is strict
  92. *
  93. * \note The result is cached in route->type
  94. */
  95. int sip_route_is_strict(struct sip_route *route);
  96. /*!
  97. * \brief Get the URI of the route's first hop
  98. */
  99. const char *sip_route_first_uri(const struct sip_route *route);
  100. /*!
  101. * \brief Check if route has no URI's
  102. */
  103. #define sip_route_empty(route) AST_LIST_EMPTY(&(route)->list)
  104. #endif