blob: d23096eeb76efafd87e4bacb8e7c905aad8cb7a8 [file] [log] [blame]
Tristan Matthews0a329cc2013-07-17 13:20:14 -04001/* $Id$ */
2/*
3 * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
4 * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
5 *
6 * This program 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 * This program 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20#ifndef __PJNATH_STUN_CONFIG_H__
21#define __PJNATH_STUN_CONFIG_H__
22
23/**
24 * @file stun_config.h
25 * @brief STUN endpoint.
26 */
27
28#include <pjnath/stun_msg.h>
29#include <pj/assert.h>
30#include <pj/errno.h>
31#include <pj/string.h>
32
33
34PJ_BEGIN_DECL
35
36
37/* **************************************************************************/
38/**
39 * @defgroup PJNATH_STUN_CONFIG STUN Config
40 * @brief STUN config
41 * @ingroup PJNATH_STUN_BASE
42 * @{
43 */
44
45/**
46 * STUN configuration.
47 */
48typedef struct pj_stun_config
49{
50 /**
51 * Pool factory to be used.
52 */
53 pj_pool_factory *pf;
54
55 /**
56 * Ioqueue.
57 */
58 pj_ioqueue_t *ioqueue;
59
60 /**
61 * Timer heap instance.
62 */
63 pj_timer_heap_t *timer_heap;
64
65 /**
66 * Options.
67 */
68 unsigned options;
69
70 /**
71 * The default initial STUN round-trip time estimation in msecs.
72 * The value normally is PJ_STUN_RTO_VALUE.
73 */
74 unsigned rto_msec;
75
76 /**
77 * The interval to cache outgoing STUN response in the STUN session,
78 * in miliseconds.
79 *
80 * Default 10000 (10 seconds).
81 */
82 unsigned res_cache_msec;
83
84 /**
85 * Software name to be included in all STUN requests and responses.
86 *
87 * Default: PJNATH_STUN_SOFTWARE_NAME.
88 */
89 pj_str_t software_name;
90
91} pj_stun_config;
92
93
94
95/**
96 * Initialize STUN config.
97 */
98PJ_INLINE(void) pj_stun_config_init(pj_stun_config *cfg,
99 pj_pool_factory *factory,
100 unsigned options,
101 pj_ioqueue_t *ioqueue,
102 pj_timer_heap_t *timer_heap)
103{
104 pj_bzero(cfg, sizeof(*cfg));
105
106 cfg->pf = factory;
107 cfg->options = options;
108 cfg->ioqueue = ioqueue;
109 cfg->timer_heap = timer_heap;
110 cfg->rto_msec = PJ_STUN_RTO_VALUE;
111 cfg->res_cache_msec = PJ_STUN_RES_CACHE_DURATION;
112 cfg->software_name = pj_str((char*)PJNATH_STUN_SOFTWARE_NAME);
113}
114
115
116/**
117 * Check that STUN config is valid.
118 */
119PJ_INLINE(pj_status_t) pj_stun_config_check_valid(const pj_stun_config *cfg)
120{
121 PJ_ASSERT_RETURN(cfg->ioqueue && cfg->pf && cfg->timer_heap &&
122 cfg->rto_msec && cfg->res_cache_msec, PJ_EINVAL);
123 return PJ_SUCCESS;
124}
125
126
127/**
128 * @}
129 */
130
131
132PJ_END_DECL
133
134
135#endif /* __PJNATH_STUN_CONFIG_H__ */
136