srv.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 1999 - 2013, Digium, Inc.
  5. *
  6. * Mark Spencer <markster@digium.com>
  7. *
  8. * See http://www.asterisk.org for more information about
  9. * the Asterisk project. Please do not directly contact
  10. * any of the maintainers of this project for assistance;
  11. * the project provides a web site, mailing lists and IRC
  12. * channels for your use.
  13. *
  14. * This program is free software, distributed under the terms of
  15. * the GNU General Public License Version 2. See the LICENSE file
  16. * at the top of the source tree.
  17. */
  18. /*
  19. * DNS SRV record support
  20. */
  21. #ifndef _ASTERISK_SRV_H
  22. #define _ASTERISK_SRV_H
  23. /*! \file srv.h
  24. *
  25. * \brief Support for DNS SRV records, used in to locate SIP services.
  26. *
  27. * \note Note: This SRV record support will respect the priority and weight
  28. * elements of the records that are returned, but there are no provisions
  29. * for retrying or failover between records.
  30. */
  31. /*! \brief An opaque type, for lookup usage */
  32. struct srv_context;
  33. /*! \brief Retrieve set of SRV lookups, in order
  34. *
  35. * \param[in] context A pointer in which to hold the result
  36. * \param[in] service The service name to look up
  37. * \param[out] host Result host
  38. * \param[out] port Associated TCP portnum
  39. *
  40. * \retval -1 Query failed
  41. * \retval 0 Result exists in host and port
  42. * \retval 1 No more results
  43. */
  44. extern int ast_srv_lookup(struct srv_context **context, const char *service, const char **host, unsigned short *port);
  45. /*! \brief Cleanup resources associated with ast_srv_lookup
  46. *
  47. * \param context Pointer passed into ast_srv_lookup
  48. */
  49. void ast_srv_cleanup(struct srv_context **context);
  50. /*! \brief Lookup entry in SRV records Returns 1 if found, 0 if not found, -1 on hangup
  51. *
  52. * Only do SRV record lookup if you get a domain without a port. If you get a port #, it's a DNS host name.
  53. *
  54. * \param chan Ast channel
  55. * \param host host name (return value)
  56. * \param hostlen Length of string "host"
  57. * \param port Port number (return value)
  58. * \param service Service tag for SRV lookup (like "_sip._udp" or "_stun._udp"
  59. */
  60. extern int ast_get_srv(struct ast_channel *chan, char *host, int hostlen, int *port, const char *service);
  61. /*!
  62. * \brief Get the number of records for a given SRV context
  63. *
  64. * \details
  65. * This is meant to be used after calling ast_srv_lookup, so that
  66. * one may retrieve the number of records returned during a specific
  67. * SRV lookup.
  68. *
  69. * \param context The context returned by ast_srv_lookup
  70. *
  71. * \return Number of records in context
  72. */
  73. unsigned int ast_srv_get_record_count(struct srv_context *context);
  74. /*!
  75. * \brief Retrieve details from a specific SRV record
  76. *
  77. * \details
  78. * After calling ast_srv_lookup, the srv_context will contain
  79. * the data from several records. You can retrieve the data
  80. * of a specific one by asking for a specific record number. The
  81. * records are sorted based on priority and secondarily based on
  82. * weight. See RFC 2782 for the exact sorting rules.
  83. *
  84. * \param context The context returned by ast_srv_lookup
  85. * \param record_num The 1-indexed record number to retrieve
  86. * \param[out] host The host portion of the record
  87. * \param[out] port The port portion of the record
  88. * \param[out] priority The priority portion of the record
  89. * \param[out] weight The weight portion of the record
  90. *
  91. * \retval -1 Failed to retrieve information.
  92. * Likely due to an out of range record_num
  93. * \retval 0 Success
  94. */
  95. int ast_srv_get_nth_record(struct srv_context *context, int record_num, const char **host,
  96. unsigned short *port, unsigned short *priority, unsigned short *weight);
  97. #endif /* _ASTERISK_SRV_H */