|
Lines 12-19
Link Here
|
| 12 |
|
12 |
|
| 13 |
import java.io.*; |
13 |
import java.io.*; |
| 14 |
import java.lang.reflect.Method; |
14 |
import java.lang.reflect.Method; |
| 15 |
import java.net.ServerSocket; |
15 |
import java.net.*; |
| 16 |
import java.net.Socket; |
|
|
| 17 |
import java.util.Dictionary; |
16 |
import java.util.Dictionary; |
| 18 |
import java.util.Hashtable; |
17 |
import java.util.Hashtable; |
| 19 |
import org.eclipse.osgi.framework.console.CommandProvider; |
18 |
import org.eclipse.osgi.framework.console.CommandProvider; |
|
Lines 92-114
Link Here
|
| 92 |
private final ServiceTracker<CommandProvider, CommandProvider> cpTracker; |
91 |
private final ServiceTracker<CommandProvider, CommandProvider> cpTracker; |
| 93 |
private final ServiceTracker<ConsoleSession, FrameworkConsole> sessions; |
92 |
private final ServiceTracker<ConsoleSession, FrameworkConsole> sessions; |
| 94 |
private final String consolePort; |
93 |
private final String consolePort; |
|
|
94 |
// Allow for specifying the particular local host address on which the framework to listen for connections. Currently it listens on |
| 95 |
// all network interfaces of the host and restricting this is desirable from security point of view. See bug 322917. |
| 96 |
private final String consoleHost; |
| 95 |
private FrameworkCommandProvider fwkCommands; |
97 |
private FrameworkCommandProvider fwkCommands; |
| 96 |
private ServiceRegistration<?> builtinSession; |
98 |
private ServiceRegistration<?> builtinSession; |
| 97 |
private ConsoleSocketGetter scsg; |
99 |
private ConsoleSocketGetter socketGetter; |
| 98 |
private final boolean isEnabled; |
100 |
private final boolean isEnabled; |
| 99 |
|
101 |
|
| 100 |
public ConsoleManager(Framework framework, String consolePort) { |
102 |
public ConsoleManager(Framework framework, String consolePropValue) { |
| 101 |
if ("false".equals(FrameworkProperties.getProperty(PROP_CONSOLE_ENABLED)) || "none".equals(consolePort)) { //$NON-NLS-1$ //$NON-NLS-2$ |
103 |
String port = null; |
|
|
104 |
String host = null; |
| 105 |
if (consolePropValue != null) { |
| 106 |
int index = consolePropValue.lastIndexOf(":"); //$NON-NLS-1$ |
| 107 |
if (index > -1) { |
| 108 |
host = consolePropValue.substring(0, index); |
| 109 |
} |
| 110 |
port = consolePropValue.substring(index + 1); |
| 111 |
} |
| 112 |
|
| 113 |
if ("false".equals(FrameworkProperties.getProperty(PROP_CONSOLE_ENABLED)) || "none".equals(port)) { //$NON-NLS-1$ //$NON-NLS-2$ |
| 102 |
isEnabled = false; |
114 |
isEnabled = false; |
| 103 |
this.framework = null; |
115 |
this.framework = null; |
| 104 |
this.cpTracker = null; |
116 |
this.cpTracker = null; |
| 105 |
this.sessions = null; |
117 |
this.sessions = null; |
|
|
118 |
this.consoleHost = null; |
| 106 |
this.consolePort = null; |
119 |
this.consolePort = null; |
| 107 |
return; |
120 |
return; |
| 108 |
} |
121 |
} |
| 109 |
this.isEnabled = true; |
122 |
this.isEnabled = true; |
| 110 |
this.framework = framework; |
123 |
this.framework = framework; |
| 111 |
this.consolePort = consolePort != null ? consolePort.trim() : consolePort; |
124 |
this.consoleHost = host != null ? host.trim() : host; |
|
|
125 |
this.consolePort = port != null ? port.trim() : port; |
| 112 |
this.cpTracker = new ServiceTracker<CommandProvider, CommandProvider>(framework.getSystemBundleContext(), CommandProvider.class.getName(), null); |
126 |
this.cpTracker = new ServiceTracker<CommandProvider, CommandProvider>(framework.getSystemBundleContext(), CommandProvider.class.getName(), null); |
| 113 |
this.sessions = new ServiceTracker<ConsoleSession, FrameworkConsole>(framework.getSystemBundleContext(), ConsoleSession.class.getName(), this); |
127 |
this.sessions = new ServiceTracker<ConsoleSession, FrameworkConsole>(framework.getSystemBundleContext(), ConsoleSession.class.getName(), this); |
| 114 |
} |
128 |
} |
|
Lines 166-172
Link Here
|
| 166 |
builtinSession = framework.getSystemBundleContext().registerService(ConsoleSession.class.getName(), session, props); |
180 |
builtinSession = framework.getSystemBundleContext().registerService(ConsoleSession.class.getName(), session, props); |
| 167 |
} else { |
181 |
} else { |
| 168 |
try { |
182 |
try { |
| 169 |
scsg = new ConsoleManager.ConsoleSocketGetter(new ServerSocket(port)); |
183 |
if (consoleHost != null) { |
|
|
184 |
socketGetter = new ConsoleSocketGetter(new ServerSocket(port, 0, InetAddress.getByName(consoleHost))); |
| 185 |
} else { |
| 186 |
socketGetter = new ConsoleManager.ConsoleSocketGetter(new ServerSocket(port)); |
| 187 |
} |
| 170 |
} catch (IOException e) { |
188 |
} catch (IOException e) { |
| 171 |
e.printStackTrace(); |
189 |
e.printStackTrace(); |
| 172 |
} |
190 |
} |
|
Lines 189-196
Link Here
|
| 189 |
} |
207 |
} |
| 190 |
sessions.close(); |
208 |
sessions.close(); |
| 191 |
cpTracker.close(); |
209 |
cpTracker.close(); |
| 192 |
if (scsg != null) |
210 |
if (socketGetter != null) |
| 193 |
scsg.shutdown(); |
211 |
socketGetter.shutdown(); |
| 194 |
if (fwkCommands != null) |
212 |
if (fwkCommands != null) |
| 195 |
fwkCommands.stop(); |
213 |
fwkCommands.stop(); |
| 196 |
} |
214 |
} |