stun_config.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*
  2. * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
  3. * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. */
  19. #ifndef __PJNATH_STUN_CONFIG_H__
  20. #define __PJNATH_STUN_CONFIG_H__
  21. /**
  22. * @file stun_config.h
  23. * @brief STUN endpoint.
  24. */
  25. #include <pjnath/stun_msg.h>
  26. #include <pj/assert.h>
  27. #include <pj/errno.h>
  28. #include <pj/string.h>
  29. PJ_BEGIN_DECL
  30. /* **************************************************************************/
  31. /**
  32. * @defgroup PJNATH_STUN_CONFIG STUN Config
  33. * @brief STUN config
  34. * @ingroup PJNATH_STUN_BASE
  35. * @{
  36. */
  37. /**
  38. * STUN configuration.
  39. */
  40. typedef struct pj_stun_config
  41. {
  42. /**
  43. * Pool factory to be used.
  44. */
  45. pj_pool_factory *pf;
  46. /**
  47. * Ioqueue.
  48. */
  49. pj_ioqueue_t *ioqueue;
  50. /**
  51. * Timer heap instance.
  52. */
  53. pj_timer_heap_t *timer_heap;
  54. /**
  55. * Options.
  56. */
  57. unsigned options;
  58. /**
  59. * The default initial STUN round-trip time estimation in msecs.
  60. * The value normally is PJ_STUN_RTO_VALUE.
  61. */
  62. unsigned rto_msec;
  63. /**
  64. * The interval to cache outgoing STUN response in the STUN session,
  65. * in miliseconds.
  66. *
  67. * Default 10000 (10 seconds).
  68. */
  69. unsigned res_cache_msec;
  70. /**
  71. * Software name to be included in all STUN requests and responses.
  72. *
  73. * Default: PJNATH_STUN_SOFTWARE_NAME.
  74. */
  75. pj_str_t software_name;
  76. } pj_stun_config;
  77. /**
  78. * Initialize STUN config.
  79. */
  80. PJ_INLINE(void) pj_stun_config_init(pj_stun_config *cfg,
  81. pj_pool_factory *factory,
  82. unsigned options,
  83. pj_ioqueue_t *ioqueue,
  84. pj_timer_heap_t *timer_heap)
  85. {
  86. pj_bzero(cfg, sizeof(*cfg));
  87. cfg->pf = factory;
  88. cfg->options = options;
  89. cfg->ioqueue = ioqueue;
  90. cfg->timer_heap = timer_heap;
  91. cfg->rto_msec = PJ_STUN_RTO_VALUE;
  92. cfg->res_cache_msec = PJ_STUN_RES_CACHE_DURATION;
  93. cfg->software_name = pj_str((char*)PJNATH_STUN_SOFTWARE_NAME);
  94. }
  95. /**
  96. * Check that STUN config is valid.
  97. */
  98. PJ_INLINE(pj_status_t) pj_stun_config_check_valid(const pj_stun_config *cfg)
  99. {
  100. PJ_ASSERT_RETURN(cfg->ioqueue && cfg->pf && cfg->timer_heap &&
  101. cfg->rto_msec && cfg->res_cache_msec, PJ_EINVAL);
  102. return PJ_SUCCESS;
  103. }
  104. /**
  105. * @}
  106. */
  107. PJ_END_DECL
  108. #endif /* __PJNATH_STUN_CONFIG_H__ */