blob: 732c33dcdabab62cde75d205c5ab0725cb742b8d [file] [log] [blame]
Brian Waters13d96012017-12-08 16:53:31 -06001/*********************************************************************************************************
2* Software License Agreement (BSD License) *
3* Author: Sebastien Decugis <sdecugis@freediameter.net> *
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/* Header file for the app_redirect extension.
37 *
38 * See the app_redirect.conf.sample file for the format of the configuration file.
39 */
40
41/* FreeDiameter's common include file */
42#include <freeDiameter/extension.h>
43
44/* Host configuration for this specific extension */
45#include <ard-host.h>
46#include <regex.h>
47
48/* Extension's configuration */
49struct ard_config {
50 uint32_t default_rct; /* redirect-cache-time to use unless overwritten by a rule */
51 struct fd_list rules; /* the list of rules in the order they appear in the conf file. */
52};
53extern struct ard_config * ard_conf; /* initialized in ard_conf.y */
54
55/* The types of redirects (from Redirect-Host-Usage AVP value) */
56enum redir_h_u {
57 DONT_CACHE = 0,
58 ALL_SESSION,
59 ALL_REALM,
60 REALM_AND_APPLICATION,
61 ALL_APPLICATION,
62 ALL_HOST,
63 ALL_USER
64};
65#define H_U_MAX ALL_USER
66
67/* A rule */
68struct ard_rule {
69 struct fd_list chain; /* link in configuration */
70
71 enum redir_h_u type; /* What kind of rule is this? */
72 uint32_t rct; /* overwrite default_rct is not 0 */
73
74 struct fd_list criteria; /* list of criteria to match. The rule is applied if all criteria match */
75
76 struct fd_list targets; /* list of Redirect-Host values to send. */
77};
78
79/* What kind of criteria exist */
80enum rule_criteria { /* note: the order of the values reflects the complexity of matching -- it should be kept this way */
81 APP_ID,
82 FROM_ID,
83 FROM_REALM,
84 AVP_INT,
85 AVP_STR
86};
87
88/* A criteria in the list */
89struct ard_criteria {
90 struct fd_list chain; /* link in ard_rule->criteria */
91 enum rule_criteria type; /* What is this rule */
92
93 /* the data that must be matched -- everything is not used by all criteria types */
94 char * s;
95 size_t sl;
96 int is_regex;
97 regex_t preg;
98 uint32_t i;
99 struct dict_avp_data avp_info;
100};
101
102/* A target entry in the ard_rule->targets list */
103struct ard_target {
104 struct fd_list chain;
105 os0_t s; /* must be freed afterwards */
106 size_t l;
107};
108
109/* The AVPs we use */
110extern struct dict_object * avp_Redirect_Host;
111extern struct dict_object * avp_Redirect_Host_Usage;
112extern struct dict_object * avp_Redirect_Max_Cache_Time;
113
114/* Parse the configuration file */
115int ard_conf_handle(char * conffile);
116
117/* Dump a rule (debug) */
118void ard_rule_dump(struct ard_rule * r);
119
120/* Check if a rule applies, and if found, create the reply */
121int ard_rule_apply(void * cbdata, struct msg ** msg);