1 /*******************************************************************************
2 * Copyright (c) 2007, 2014 Massimiliano Ziccardi
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *******************************************************************************/
16 package it.jnrpe.server;
17
18 import java.util.ArrayList;
19 import java.util.List;
20
21 /**
22 * Represent the JNRPE configuration server section.
23 *
24 * @author Massimiliano Ziccardi
25 */
26 public class ServerSection {
27
28 /**
29 * The default backlog size.
30 */
31 public final static int DEFAULT_BACKLOG = 128;
32
33 /**
34 * <code>true</code> if dynamic parameters ($ARGx$ macros) must be
35 * interpolated.
36 */
37 private boolean acceptParams;
38
39 /**
40 * The plugins directory path.
41 */
42 private String pluginPath;
43
44 /**
45 * The list of all the binding where JNRPE must listen on.
46 */
47 private final List<BindAddress> bindingsList = new ArrayList<BindAddress>();
48
49 /**
50 * The list of all the addresses (IP/URL) JNRPE must accept requests from.
51 */
52 private final List<String> allowedAddressesList = new ArrayList<String>();
53
54 /**
55 * The maximum number connections.
56 */
57 private int backlogSize = DEFAULT_BACKLOG;
58
59 /**
60 * Read timeout in seconds.
61 */
62 private Integer readTimeout = null;
63
64 /**
65 * Write timeout in seconds.
66 */
67 private Integer writeTimeout = null;
68
69 /**
70 * @return all the configured binding addresses.
71 */
72 public final List<BindAddress> getBindAddresses() {
73 return bindingsList;
74 }
75
76 /**
77 * Adds a binding address to the list. The format of a binding address is
78 * [SSL/]address[:port]:
79 * <ul>
80 * <li>SSL/ : if present means than JNRPE must create an SSL socket
81 * <li>:port : is the port where JNRPE must listen to
82 * </ul>
83 *
84 * @param bindAddress
85 * The address to add
86 */
87 final void addBindAddress(final String bindAddress) {
88
89 boolean ssl = bindAddress.toUpperCase().startsWith("SSL/");
90
91 String sAddress;
92
93 if (ssl) {
94 sAddress = bindAddress.substring("SSL/".length());
95 } else {
96 sAddress = bindAddress;
97 }
98
99 addBindAddress(sAddress, ssl);
100 }
101
102 /**
103 * Adds a binding address to the list of binding address.
104 *
105 * @param bindAddress
106 * The IP/URL
107 * @param useSSL
108 * <code>true</code> if SSL must be used
109 */
110 final void addBindAddress(final String bindAddress, final boolean useSSL) {
111 bindingsList.add(new BindAddress(bindAddress, useSSL));
112 }
113
114 /**
115 * @return the list of allowed IP address client
116 */
117 public final List<String> getAllowedAddresses() {
118 return allowedAddressesList;
119 }
120
121 /**
122 * Adds an address to the list of allowed clients.
123 *
124 * @param address
125 * The IP/URL that must be accepted
126 */
127 final void addAllowedAddress(final String address) {
128 allowedAddressesList.add(address);
129 }
130
131 /**
132 * Returns whether this server must resolve $ARGx$ macros or not.
133 *
134 * @return <code>true</code> if macros must be resolved
135 */
136 public final boolean acceptParams() {
137 return acceptParams;
138 }
139
140 public final int getBacklogSize() {
141 return this.backlogSize;
142 }
143
144 public final int getReadTimeout() {
145 return readTimeout;
146 }
147
148 public final int getWriteTimeout() {
149 return writeTimeout;
150 }
151
152 /**
153 * Sets whether this server must resolve $ARGx$ macros or not.
154 *
155 * @param acceptParms
156 * pass <code>true</code> if macros must be resolved.
157 */
158 final void setAcceptParams(final boolean acceptParms) {
159 this.acceptParams = acceptParms;
160 }
161
162 /**
163 * @return the path to the directory where all plugins are istalled.
164 */
165 public final String getPluginPath() {
166 return pluginPath;
167 }
168
169 /**
170 * Sets the path to the directory where all plugins are istalled.
171 *
172 * @param pluginDirectoryPath
173 * The path to the plugins installation directory
174 */
175 final void setPluginPath(final String pluginDirectoryPath) {
176 this.pluginPath = pluginDirectoryPath;
177 }
178
179 /**
180 * Sets the maximum number of accepted connections. Default is
181 * {@value #DEFAULT_BACKLOG}.
182 *
183 * @param backLogSize
184 */
185 final void setBackLogSize(final int backLogSize) {
186 this.backlogSize = backLogSize;
187 }
188
189 final void setReadTimeout(final int readTimeout) {
190 this.readTimeout = readTimeout;
191 }
192
193 final void setWriteTimeout(final int writeTimeout) {
194 this.writeTimeout = writeTimeout;
195 }
196 }