1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.james.jspf.terms;
22
23 import org.apache.james.jspf.core.LogEnabled;
24 import org.apache.james.jspf.core.Logger;
25 import org.apache.james.jspf.core.MacroExpand;
26 import org.apache.james.jspf.core.MacroExpandEnabled;
27 import org.apache.james.jspf.core.SPFSession;
28 import org.apache.james.jspf.core.exceptions.PermErrorException;
29
30
31
32
33
34 public abstract class GenericMechanism implements Mechanism, ConfigurationEnabled, LogEnabled, MacroExpandEnabled {
35
36
37
38
39 protected static final String IP4_CIDR_LENGTH_REGEX = "/(\\d+)";
40
41
42
43
44 protected static final String IP6_CIDR_LENGTH_REGEX = "/(\\d+)";
45
46
47
48
49 protected static final String DUAL_CIDR_LENGTH_REGEX = "(?:"
50 + IP4_CIDR_LENGTH_REGEX + ")?" + "(?:/" + IP6_CIDR_LENGTH_REGEX
51 + ")?";
52
53 private String domain;
54
55 protected Logger log;
56
57 protected MacroExpand macroExpand;
58
59
60
61
62
63
64
65 protected String expandHost(SPFSession spfData) throws PermErrorException {
66 String host = getDomain();
67 if (host == null) {
68 host = spfData.getCurrentDomain();
69 } else {
70
71 host = macroExpand.expand(host, spfData, MacroExpand.DOMAIN);
72 }
73 return host;
74 }
75
76
77
78
79 public synchronized void config(Configuration params) throws PermErrorException {
80 if (params.groupCount() >= 1 && params.group(1) != null) {
81 domain = params.group(1);
82 } else {
83 domain = null;
84 }
85 }
86
87
88
89
90 protected synchronized String getDomain() {
91 return domain;
92 }
93
94
95
96
97 public void enableLogging(Logger logger) {
98 this.log = logger;
99 }
100
101
102
103
104 public void enableMacroExpand(MacroExpand macroExpand) {
105 this.macroExpand = macroExpand;
106 }
107 }