Debian Codegraph @

lib/freeDiameter-1.2.1/extensions/app_redirect/app_redir.c

raw symbols SCIP
1 /*********************************************************************************************************
2 * Software License Agreement (BSD License) *
3 * Author: Sebastien Decugis <[email protected]> *
4 * *
5 * Copyright (c) 2011, WIDE Project and NICT *
6 * All rights reserved. *
7 * *
8 * Redistribution and use of this software in source and binary forms, with or without modification, are *
9 * permitted provided that the following conditions are met: *
10 * *
11 * * Redistributions of source code must retain the above *
12 * copyright notice, this list of conditions and the *
13 * following disclaimer. *
14 * *
15 * * Redistributions in binary form must reproduce the above *
16 * copyright notice, this list of conditions and the *
17 * following disclaimer in the documentation and/or other *
18 * materials provided with the distribution. *
19 * *
20 * * Neither the name of the WIDE Project or NICT nor the *
21 * names of its contributors may be used to endorse or *
22 * promote products derived from this software without *
23 * specific prior written permission of WIDE Project and *
24 * NICT. *
25 * *
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED *
27 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
28 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR *
29 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *
30 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS *
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR *
32 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF *
33 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
34 *********************************************************************************************************/
35
36 /*
37 * Configurable routing of messages for freeDiameter.
38 */
39
40 #include "app_redir.h"
41
42 static struct fd_rt_fwd_hdl * ard_fwd_cb = NULL;
43
44 /* entry point */
45 static int ard_entry(char * conffile)
46 {
47 TRACE_ENTRY("%p", conffile);
48
49 /* Parse the configuration file */
50 CHECK_FCT( ard_conf_handle(conffile) );
51
52 /* Resolve the dictionary objects we use */
53 CHECK_FCT( fd_dict_search ( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Redirect-Host", &avp_Redirect_Host, ENOENT ));
54 CHECK_FCT( fd_dict_search ( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Redirect-Host-Usage", &avp_Redirect_Host_Usage, ENOENT ));
55 CHECK_FCT( fd_dict_search ( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Redirect-Max-Cache-Time", &avp_Redirect_Max_Cache_Time, ENOENT ));
56
57 /* Register the proxy callback */
58 CHECK_FCT( fd_rt_fwd_register(ard_rule_apply, NULL, RT_FWD_REQ, &ard_fwd_cb) );
59
60 /* We're done */
61 return 0;
62 }
63
64 /* Unload */
65 void fd_ext_fini(void)
66 {
67 TRACE_ENTRY();
68
69 /* Unregister the proxy callback */
70 if (ard_fwd_cb) {
71 CHECK_FCT_DO( fd_rt_fwd_unregister(ard_fwd_cb, NULL), );
72 }
73
74 /* Destroy all rules */
75 while (!FD_IS_LIST_EMPTY(&ard_conf->rules)) {
76 struct ard_rule * r = ard_conf->rules.next->o;
77 fd_list_unlink(&r->chain);
78 while (!FD_IS_LIST_EMPTY(&r->criteria)) {
79 struct ard_criteria * c = r->criteria.next->o;
80 fd_list_unlink(&c->chain);
81 if (c->is_regex) {
82 regfree(&c->preg);
83 }
84 free(c->s);
85 free(c);
86 }
87 while (!FD_IS_LIST_EMPTY(&r->targets)) {
88 struct ard_target * t = r->targets.next->o;
89 fd_list_unlink(&t->chain);
90 free(t->s);
91 free(t);
92 }
93 free(r);
94 }
95
96 /* Done */
97 return ;
98 }
99
100 EXTENSION_ENTRY("app_redirect", ard_entry);