Commit 6beb6d22 authored by Thiago Camargo's avatar Thiago Camargo Committed by thiago

[JM-1032] - Fixes on STUN Server Start and Stop

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@8039 b35dd754-fafc-0310-a699-88a17e54d16e
parent efbf1c23
...@@ -105,12 +105,10 @@ public class STUNService extends BasicModule { ...@@ -105,12 +105,10 @@ public class STUNService extends BasicModule {
// //
if (enabled && !oldValue) { if (enabled && !oldValue) {
startSTUNService(); startSTUNService();
} } else if (!enabled && oldValue) {
else if (!enabled && oldValue) {
stop(); stop();
} }
} } else if (property.equals("stun.local.enabled")) {
else if (property.equals("stun.local.enabled")) {
localEnabled = JiveGlobals.getBooleanProperty("stun.local.enabled", false); localEnabled = JiveGlobals.getBooleanProperty("stun.local.enabled", false);
} }
} }
...@@ -118,8 +116,7 @@ public class STUNService extends BasicModule { ...@@ -118,8 +116,7 @@ public class STUNService extends BasicModule {
public void propertyDeleted(String property, Map<String, Object> params) { public void propertyDeleted(String property, Map<String, Object> params) {
if (property.equals("stun.enabled")) { if (property.equals("stun.enabled")) {
enabled = true; enabled = true;
} } else if (property.equals("stun.local.enabled")) {
else if (property.equals("stun.local.enabled")) {
localEnabled = false; localEnabled = false;
} }
} }
...@@ -151,8 +148,7 @@ public class STUNService extends BasicModule { ...@@ -151,8 +148,7 @@ public class STUNService extends BasicModule {
if (primary != null && secondary != null) { if (primary != null && secondary != null) {
stunServer = new StunServer(primaryPort, primary, secondaryPort, secondary); stunServer = new StunServer(primaryPort, primary, secondaryPort, secondary);
stunServer.start(); stunServer.start();
} } else {
else {
setLocalEnabled(false); setLocalEnabled(false);
} }
} }
...@@ -178,9 +174,11 @@ public class STUNService extends BasicModule { ...@@ -178,9 +174,11 @@ public class STUNService extends BasicModule {
private void stopSTUNService() { private void stopSTUNService() {
XMPPServer server = XMPPServer.getInstance(); XMPPServer server = XMPPServer.getInstance();
server.getIQDiscoInfoHandler().removeServerFeature(NAMESPACE); server.getIQDiscoInfoHandler().removeServerFeature(NAMESPACE);
if (stunIQHandler != null) {
server.getIQRouter().removeHandler(stunIQHandler); server.getIQRouter().removeHandler(stunIQHandler);
stunIQHandler = null; stunIQHandler = null;
} }
}
public void stop() { public void stop() {
super.stop(); super.stop();
...@@ -259,8 +257,7 @@ public class STUNService extends BasicModule { ...@@ -259,8 +257,7 @@ public class STUNService extends BasicModule {
if (isLocalEnabled()) { if (isLocalEnabled()) {
startLocalServer(); startLocalServer();
} }
} } else {
else {
stopSTUNService(); stopSTUNService();
} }
this.enabled = enabled; this.enabled = enabled;
...@@ -276,8 +273,7 @@ public class STUNService extends BasicModule { ...@@ -276,8 +273,7 @@ public class STUNService extends BasicModule {
this.localEnabled = enabled; this.localEnabled = enabled;
if (isLocalEnabled()) { if (isLocalEnabled()) {
startLocalServer(); startLocalServer();
} } else {
else {
stopLocal(); stopLocal();
} }
} }
...@@ -413,8 +409,7 @@ public class STUNService extends BasicModule { ...@@ -413,8 +409,7 @@ public class STUNService extends BasicModule {
} }
} }
} } else {
else {
// Answer an error since the server can't handle the requested namespace // Answer an error since the server can't handle the requested namespace
reply.setError(PacketError.Condition.service_unavailable); reply.setError(PacketError.Condition.service_unavailable);
} }
......
...@@ -52,7 +52,7 @@ ...@@ -52,7 +52,7 @@
boolean add = request.getParameter("add") != null; boolean add = request.getParameter("add") != null;
int remove = ParamUtils.getIntParameter(request, "remove", -1); int remove = ParamUtils.getIntParameter(request, "remove", -1);
boolean success = false; boolean success = false;
boolean enabled = false; boolean enabled = true;
boolean localEnabled = false; boolean localEnabled = false;
String primaryAddress; String primaryAddress;
...@@ -73,8 +73,7 @@ ...@@ -73,8 +73,7 @@
secondaryAddress = ParamUtils.getParameter(request, "secondaryAddress", true); secondaryAddress = ParamUtils.getParameter(request, "secondaryAddress", true);
JiveGlobals.setProperty("stun.address.secondary", secondaryAddress); JiveGlobals.setProperty("stun.address.secondary", secondaryAddress);
enabled = ParamUtils.getBooleanParameter(request, "enabled", enabled); enabled = JiveGlobals.getBooleanProperty("stun.enabled", enabled);
JiveGlobals.setProperty("stun.enabled", String.valueOf(enabled));
localEnabled = ParamUtils.getBooleanParameter(request, "localEnabled", localEnabled); localEnabled = ParamUtils.getBooleanParameter(request, "localEnabled", localEnabled);
JiveGlobals.setProperty("stun.local.enabled", String.valueOf(localEnabled)); JiveGlobals.setProperty("stun.local.enabled", String.valueOf(localEnabled));
...@@ -86,12 +85,10 @@ ...@@ -86,12 +85,10 @@
success = stunService.isEnabled() == enabled && stunService.isLocalEnabled() == localEnabled; success = stunService.isEnabled() == enabled && stunService.isLocalEnabled() == localEnabled;
} } else if (remove > -1) {
else if (remove > -1) {
stunService.removeExternalServer(remove); stunService.removeExternalServer(remove);
success = true; success = true;
} } else if (add) {
else if (add) {
String server = ParamUtils.getParameter(request, "externalServer", true); String server = ParamUtils.getParameter(request, "externalServer", true);
String port = ParamUtils.getParameter(request, "externalPort", true); String port = ParamUtils.getParameter(request, "externalPort", true);
...@@ -176,14 +173,14 @@ ...@@ -176,14 +173,14 @@
<form action="" method="post" name="settings"> <form action="" method="post" name="settings">
<div class="jive-contentBoxHeader"> <div class="jive-contentBoxHeader">
<fmt:message key="stun.settings.title"/> <fmt:message key="stun.settings.title"/>
</div> </div>
<div class="jive-contentBox"> <div class="jive-contentBox">
<table cellpadding="3" cellspacing="5" border="0"> <table cellpadding="3" cellspacing="5" border="0">
<tbody> <tbody>
<tr> <tr>
<td align="left" colspan="2"> <td align="left" colspan="2">
<fmt:message key="stun.settings.localenabled"/> <fmt:message key="stun.settings.localenabled"/>
:&nbsp<input type="checkbox" :&nbsp<input type="checkbox"
...@@ -191,28 +188,37 @@ ...@@ -191,28 +188,37 @@
<%=stunService.isLocalEnabled()?"checked":""%> <%=stunService.isLocalEnabled()?"checked":""%>
align="left"> align="left">
</td> </td>
</tr> </tr>
<tr> <tr>
<td align="left"> <td align="left">
<fmt:message key="stun.settings.primaryaddress"/>: <fmt:message key="stun.settings.primaryaddress"/>
</td><td> :
</td>
<td>
<select size="1" name="primaryAddress"> <select size="1" name="primaryAddress">
<option value="CHOOSE">-- Select Address --</option> <option value="CHOOSE">-- Select Address --</option>
<% <%
List<InetAddress> addresses = stunService.getAddresses(); List<InetAddress> addresses = stunService.getAddresses();
for (InetAddress iaddress : addresses) { for (InetAddress iaddress : addresses) {
String hostAddress = iaddress.getHostAddress(); String hostAddress = iaddress.getHostAddress();
boolean isPrimaryAddress = hostAddress.equals(stunService.getPrimaryAddress()); boolean isPrimaryAddress = hostAddress.equals(stunService.getPrimaryAddress());
%> %>
<option value="<%= hostAddress %>" <% if(isPrimaryAddress) { %>selected <% } %> ><%= hostAddress %> <option value="<%= hostAddress %>" <% if (isPrimaryAddress) { %>
selected <% } %> ><%= hostAddress %>
</option> </option>
<% } %> <% } %>
</td> </td>
</tr> </tr>
<tr> <tr>
<td align="left"> <td align="left">
<fmt:message key="stun.settings.secondaryaddress"/>: <fmt:message key="stun.settings.secondaryaddress"/>
</td><td> :
</td>
<td>
<select size="1" name="secondaryAddress"> <select size="1" name="secondaryAddress">
<option value="CHOOSE">-- Select Address --</option> <option value="CHOOSE">-- Select Address --</option>
<% <%
...@@ -220,44 +226,49 @@ ...@@ -220,44 +226,49 @@
String hostAddress = iaddress.getHostAddress(); String hostAddress = iaddress.getHostAddress();
boolean isSecondaryAddress = hostAddress.equals(stunService.getSecondaryAddress()); boolean isSecondaryAddress = hostAddress.equals(stunService.getSecondaryAddress());
%> %>
<option value="<%= hostAddress %>" <% if(isSecondaryAddress) { %>selected <% } %> ><%= hostAddress %> <option value="<%= hostAddress %>" <% if (isSecondaryAddress) { %>
selected <% } %> ><%= hostAddress %>
</option> </option>
<% } %> <% } %>
</select> </select>
</td> </td>
</tr> </tr>
<tr> <tr>
<td align="left"> <td align="left">
<fmt:message key="stun.settings.primaryport"/>: <fmt:message key="stun.settings.primaryport"/>
</td><td> :
</td>
<td>
<input type="text" size="6" <input type="text" size="6"
maxlength="10" maxlength="10"
name="primaryPort" name="primaryPort"
value="<%=stunService.getPrimaryPort()%>" value="<%=stunService.getPrimaryPort()%>"
align="left"> align="left">
</td> </td>
</tr> </tr>
<tr> <tr>
<td align="left"> <td align="left">
<fmt:message key="stun.settings.secondaryport"/>: <fmt:message key="stun.settings.secondaryport"/>
</td><td> :
</td>
<td>
<input type="text" size="6" <input type="text" size="6"
maxlength="10" maxlength="10"
name="secondaryPort" name="secondaryPort"
value="<%=stunService.getSecondaryPort()%>" value="<%=stunService.getSecondaryPort()%>"
align="left"> align="left">
</td> </td>
</tr> </tr>
<tr> <tr>
<td> <td>
<input type="hidden" name="save"> <input type="hidden" name="save">
<input type="button" name="set" value="<fmt:message key="global.save_settings" />" <input type="button" name="set" value="<fmt:message key="global.save_settings" />"
onclick="checkAndSubmit()"> onclick="checkAndSubmit()">
</td> </td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
</div> </div>
</form> </form>
<form action="" method="post" name="add"> <form action="" method="post" name="add">
<div class="jive-contentBoxHeader"> <div class="jive-contentBoxHeader">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment