提交 ed04a08d authored 作者: Thomas Mueller's avatar Thomas Mueller

Server.createTcpServer, createPgServer, createWebServer: invalid arguments are now detected.

上级 6cf432c7
......@@ -77,7 +77,7 @@ public class Backup extends Tool {
showUsage();
return;
} else {
throwUnsupportedOption(arg);
showUsageAndThrowUnsupportedOption(arg);
}
}
try {
......
......@@ -80,7 +80,7 @@ public class ChangeFileEncryption extends Tool {
showUsage();
return;
} else {
throwUnsupportedOption(arg);
showUsageAndThrowUnsupportedOption(arg);
}
}
if ((encryptPassword == null && decryptPassword == null) || cipher == null) {
......
......@@ -146,7 +146,7 @@ ShutdownHandler {
} else if ("-webPort".equals(arg)) {
i++;
} else {
throwUnsupportedOption(arg);
showUsageAndThrowUnsupportedOption(arg);
}
} else if ("-tool".equals(arg)) {
startDefaultServers = false;
......@@ -177,7 +177,7 @@ ShutdownHandler {
} else if ("-tcpShutdownForce".equals(arg)) {
tcpShutdownForce = true;
} else {
throwUnsupportedOption(arg);
showUsageAndThrowUnsupportedOption(arg);
}
} else if (arg.startsWith("-pg")) {
if ("-pg".equals(arg)) {
......@@ -190,7 +190,7 @@ ShutdownHandler {
} else if ("-pgPort".equals(arg)) {
i++;
} else {
throwUnsupportedOption(arg);
showUsageAndThrowUnsupportedOption(arg);
}
} else if ("-properties".equals(arg)) {
i++;
......@@ -201,7 +201,7 @@ ShutdownHandler {
} else if ("-baseDir".equals(arg)) {
i++;
} else {
throwUnsupportedOption(arg);
showUsageAndThrowUnsupportedOption(arg);
}
}
if (startDefaultServers) {
......
......@@ -93,7 +93,7 @@ public class ConvertTraceFile extends Tool {
showUsage();
return;
} else {
throwUnsupportedOption(arg);
showUsageAndThrowUnsupportedOption(arg);
}
}
try {
......
......@@ -72,7 +72,7 @@ public class CreateCluster extends Tool {
showUsage();
return;
} else {
throwUnsupportedOption(arg);
showUsageAndThrowUnsupportedOption(arg);
}
}
if (urlSource == null || urlTarget == null || serverList == null) {
......
......@@ -58,7 +58,7 @@ public class DeleteDbFiles extends Tool {
showUsage();
return;
} else {
throwUnsupportedOption(arg);
showUsageAndThrowUnsupportedOption(arg);
}
}
process(dir, db, quiet);
......
......@@ -167,7 +167,7 @@ public class Recover extends Tool implements DataHandler {
showUsage();
return;
} else {
throwUnsupportedOption(arg);
showUsageAndThrowUnsupportedOption(arg);
}
}
process(dir, db);
......
......@@ -66,7 +66,7 @@ public class Restore extends Tool {
showUsage();
return;
} else {
throwUnsupportedOption(arg);
showUsageAndThrowUnsupportedOption(arg);
}
}
execute(zipFileName, dir, db, false);
......
......@@ -126,7 +126,7 @@ public class RunScript extends Tool {
showUsage();
return;
} else {
throwUnsupportedOption(arg);
showUsageAndThrowUnsupportedOption(arg);
}
}
if (url == null) {
......
......@@ -88,7 +88,7 @@ public class Script extends Tool {
showUsage();
return;
} else {
throwUnsupportedOption(arg);
showUsageAndThrowUnsupportedOption(arg);
}
}
if (url == null) {
......
......@@ -44,6 +44,7 @@ public class Server extends Tool implements Runnable, ShutdownHandler {
* @param args the command line arguments
*/
public Server(Service service, String... args) throws SQLException {
verifyArgs(args);
this.service = service;
try {
service.init(args);
......@@ -115,6 +116,75 @@ public class Server extends Tool implements Runnable, ShutdownHandler {
new Server().runTool(args);
}
private void verifyArgs(String... args) throws SQLException {
for (int i = 0; args != null && i < args.length; i++) {
String arg = args[i];
if (arg == null) {
continue;
} else if ("-?".equals(arg) || "-help".equals(arg)) {
// ok
} else if (arg.startsWith("-web")) {
if ("-web".equals(arg)) {
// ok
} else if ("-webAllowOthers".equals(arg)) {
// no parameters
} else if ("-webDaemon".equals(arg)) {
// no parameters
} else if ("-webSSL".equals(arg)) {
// no parameters
} else if ("-webPort".equals(arg)) {
i++;
} else {
throwUnsupportedOption(arg);
}
} else if ("-browser".equals(arg)) {
// ok
} else if (arg.startsWith("-tcp")) {
if ("-tcp".equals(arg)) {
// ok
} else if ("-tcpAllowOthers".equals(arg)) {
// no parameters
} else if ("-tcpDaemon".equals(arg)) {
// no parameters
} else if ("-tcpSSL".equals(arg)) {
// no parameters
} else if ("-tcpPort".equals(arg)) {
i++;
} else if ("-tcpPassword".equals(arg)) {
i++;
} else if ("-tcpShutdown".equals(arg)) {
i++;
} else if ("-tcpShutdownForce".equals(arg)) {
// ok
} else {
throwUnsupportedOption(arg);
}
} else if (arg.startsWith("-pg")) {
if ("-pg".equals(arg)) {
// ok
} else if ("-pgAllowOthers".equals(arg)) {
// no parameters
} else if ("-pgDaemon".equals(arg)) {
// no parameters
} else if ("-pgPort".equals(arg)) {
i++;
} else {
throwUnsupportedOption(arg);
}
} else if ("-properties".equals(arg)) {
i++;
} else if ("-trace".equals(arg)) {
// no parameters
} else if ("-ifExists".equals(arg)) {
// no parameters
} else if ("-baseDir".equals(arg)) {
i++;
} else {
throwUnsupportedOption(arg);
}
}
}
public void runTool(String... args) throws SQLException {
boolean tcpStart = false, pgStart = false, webStart = false;
boolean browserStart = false;
......@@ -142,7 +212,7 @@ public class Server extends Tool implements Runnable, ShutdownHandler {
} else if ("-webPort".equals(arg)) {
i++;
} else {
throwUnsupportedOption(arg);
showUsageAndThrowUnsupportedOption(arg);
}
} else if ("-browser".equals(arg)) {
startDefaultServers = false;
......@@ -168,7 +238,7 @@ public class Server extends Tool implements Runnable, ShutdownHandler {
} else if ("-tcpShutdownForce".equals(arg)) {
tcpShutdownForce = true;
} else {
throwUnsupportedOption(arg);
showUsageAndThrowUnsupportedOption(arg);
}
} else if (arg.startsWith("-pg")) {
if ("-pg".equals(arg)) {
......@@ -181,7 +251,7 @@ public class Server extends Tool implements Runnable, ShutdownHandler {
} else if ("-pgPort".equals(arg)) {
i++;
} else {
throwUnsupportedOption(arg);
showUsageAndThrowUnsupportedOption(arg);
}
} else if ("-properties".equals(arg)) {
i++;
......@@ -192,9 +262,10 @@ public class Server extends Tool implements Runnable, ShutdownHandler {
} else if ("-baseDir".equals(arg)) {
i++;
} else {
throwUnsupportedOption(arg);
showUsageAndThrowUnsupportedOption(arg);
}
}
verifyArgs(args);
if (startDefaultServers) {
tcpStart = true;
pgStart = true;
......
......@@ -136,7 +136,7 @@ public class Shell extends Tool implements Runnable {
showUsage();
return;
} else {
throwUnsupportedOption(arg);
showUsageAndThrowUnsupportedOption(arg);
}
}
if (url != null) {
......
......@@ -50,8 +50,18 @@ public abstract class Tool {
* @param option the unsupported option
* @return this method never returns normally
*/
protected SQLException throwUnsupportedOption(String option) throws SQLException {
protected SQLException showUsageAndThrowUnsupportedOption(String option) throws SQLException {
showUsage();
throw throwUnsupportedOption(option);
}
/**
* Throw a SQLException saying this command line option is not supported.
*
* @param option the unsupported option
* @return this method never returns normally
*/
protected SQLException throwUnsupportedOption(String option) throws SQLException {
throw new SQLException("Unsupported option: " + option);
}
......
......@@ -113,7 +113,7 @@ public class FileShell extends Tool {
showUsage();
return;
} else {
throwUnsupportedOption(arg);
showUsageAndThrowUnsupportedOption(arg);
}
}
promptLoop();
......
......@@ -170,12 +170,12 @@ public class FtpServer extends Tool implements Service {
} else if ("-ftpTask".equals(arg)) {
// no parameters
} else {
throwUnsupportedOption(arg);
showUsageAndThrowUnsupportedOption(arg);
}
} else if ("-trace".equals(arg)) {
// no parameters
} else {
throwUnsupportedOption(arg);
showUsageAndThrowUnsupportedOption(arg);
}
}
Server server = new Server(this, args);
......
......@@ -69,7 +69,7 @@ public class FileViewer extends Tool {
showUsage();
return;
} else {
throwUnsupportedOption(arg);
showUsageAndThrowUnsupportedOption(arg);
}
}
if (file == null) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论