blob: 21b5a93dfd3ba48ae10c07282bbc3f1d3ce34136 [file] [log] [blame]
Brian Waters13d96012017-12-08 16:53:31 -06001/*********************************************************************************************************
2* Software License Agreement (BSD License) *
3* Authors: Sebastien Decugis <sdecugis@freediameter.net> *
4* and Thomas Klausner <tk@giga.or.at> *
5* *
6* Copyright (c) 2011, 2014, WIDE Project and NICT *
7* All rights reserved. *
8* *
9* Redistribution and use of this software in source and binary forms, with or without modification, are *
10* permitted provided that the following conditions are met: *
11* *
12* * Redistributions of source code must retain the above *
13* copyright notice, this list of conditions and the *
14* following disclaimer. *
15* *
16* * Redistributions in binary form must reproduce the above *
17* copyright notice, this list of conditions and the *
18* following disclaimer in the documentation and/or other *
19* materials provided with the distribution. *
20* *
21* * Neither the name of the WIDE Project or NICT nor the *
22* names of its contributors may be used to endorse or *
23* promote products derived from this software without *
24* specific prior written permission of WIDE Project and *
25* NICT. *
26* *
27* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED *
28* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
29* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR *
30* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *
31* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS *
32* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR *
33* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF *
34* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
35*********************************************************************************************************/
36
37#include "rt_redir.h"
38
39struct dict_object * redir_dict_dr = NULL;
40struct dict_object * redir_dict_un = NULL;
41
42static struct fd_rt_fwd_hdl * fwd_hdl = NULL;
43static struct fd_rt_out_hdl * out_hdl = NULL;
44static pthread_t exp_thr = (pthread_t)NULL;
45
46/* Initialize the module */
47static int redir_entry(char * conffile)
48{
49 TRACE_ENTRY("");
50
51 /* Dictionary objects */
52 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Destination-Realm", &redir_dict_dr, ENOENT) );
53 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "User-Name", &redir_dict_un, ENOENT) );
54
55 /* Initialize the entries array */
56 CHECK_FCT( redir_entry_init() );
57
58 /* Start the expire thread */
59 CHECK_POSIX( pthread_create( &exp_thr, NULL, redir_exp_thr_fct, NULL ) );
60
61 /* Register the callback that receives the answers and processes when it contains a Redirect indication. */
62 CHECK_FCT( fd_rt_fwd_register ( redir_fwd_cb, NULL, RT_FWD_ANS, &fwd_hdl ) );
63
64 /* Register the callback that applies the saved Redirect rules to outgoing messages. */
65 CHECK_FCT( fd_rt_out_register ( redir_out_cb, NULL, 10, &out_hdl ) );
66
67 return 0;
68}
69
70EXTENSION_ENTRY("rt_redirect", redir_entry);
71
72/* And terminate it */
73void fd_ext_fini(void)
74{
75 /* Unregister the callbacks */
76 if (fwd_hdl) {
77 CHECK_FCT_DO( fd_rt_fwd_unregister(fwd_hdl, NULL), );
78 }
79 if (out_hdl) {
80 CHECK_FCT_DO( fd_rt_out_unregister(out_hdl, NULL), );
81 }
82
83 /* Stop the expiry thread */
84 CHECK_FCT_DO( fd_thr_term(&exp_thr), );
85
86 /* Empty all entries */
87 redir_entry_fini();
88
89 return;
90}