diff --git a/src/net/azib/ipscan/Main.java b/src/net/azib/ipscan/Main.java index edb555b1..a78cfb1e 100755 --- a/src/net/azib/ipscan/Main.java +++ b/src/net/azib/ipscan/Main.java @@ -10,6 +10,7 @@ import java.util.Locale; import java.util.logging.Level; import java.util.logging.Logger; +import net.azib.ipscan.config.CommandLineProcessor; import net.azib.ipscan.config.ComponentRegistry; import net.azib.ipscan.config.Config; import net.azib.ipscan.config.Labels; @@ -54,8 +55,6 @@ public class Main { initSystemProperties(); - processCommandLine(args); - Display display = Display.getDefault(); LOG.finer("SWT initialized after " + (System.currentTimeMillis() - startTime)); @@ -68,8 +67,10 @@ public class Main { ComponentRegistry componentRegistry = new ComponentRegistry(); LOG.finer("ComponentRegistry initialized after " + (System.currentTimeMillis() - startTime)); + processCommandLine(args, componentRegistry); + // create the main window using dependency injection - MainWindow mainWindow = componentRegistry.createMainWindow(); + MainWindow mainWindow = componentRegistry.getMainWindow(); LOG.fine("Startup time: " + (System.currentTimeMillis() - startTime)); while (!mainWindow.isDisposed()) { @@ -109,12 +110,11 @@ public class Main { Security.setProperty("networkaddress.cache.negative.ttl", "0"); } - private static void processCommandLine(String[] args) { + private static void processCommandLine(String[] args, ComponentRegistry componentRegistry) { if (args.length != 0) { // TODO: implement command-line - String usageText = "Command-line usage is not implemented yet, sorry"; - - showMessageToConsole(usageText); + CommandLineProcessor cli = componentRegistry.getCommandLineProcessor(); + showMessageToConsole(cli.toString()); } } @@ -131,7 +131,6 @@ public class Main { } catch (Exception e) { // Java 5 will reach here - e.printStackTrace(); } if (haveConsole) { diff --git a/src/net/azib/ipscan/config/CommandLineProcessor.java b/src/net/azib/ipscan/config/CommandLineProcessor.java new file mode 100644 index 00000000..9b430986 --- /dev/null +++ b/src/net/azib/ipscan/config/CommandLineProcessor.java @@ -0,0 +1,38 @@ +/** + * This file is a part of Angry IP Scanner source code, + * see http://www.azib.net/ for more information. + * Licensed under GPLv2. + */ + +package net.azib.ipscan.config; + +import net.azib.ipscan.exporters.ExporterRegistry; +import net.azib.ipscan.feeders.Feeder; +import net.azib.ipscan.gui.feeders.AbstractFeederGUI; + +/** + * CommandLineProcessor + * + * @author Anton Keks + */ +public class CommandLineProcessor { + + private AbstractFeederGUI[] feeders; + private ExporterRegistry exporters; + + public CommandLineProcessor(AbstractFeederGUI[] feeders, ExporterRegistry exporters) { + this.feeders = feeders; + this.exporters = exporters; + } + + @Override + public String toString() { + StringBuilder usage = new StringBuilder(); + usage.append("Command-line support is not yet implemented...\n\nAvailable feeders:\n"); + for (AbstractFeederGUI feeder : feeders) { + usage.append(feeder.getFeederName()).append('\n'); + } + return usage.toString(); + } + +} diff --git a/src/net/azib/ipscan/config/ComponentRegistry.java b/src/net/azib/ipscan/config/ComponentRegistry.java index a5aaf9eb..1e146480 100755 --- a/src/net/azib/ipscan/config/ComponentRegistry.java +++ b/src/net/azib/ipscan/config/ComponentRegistry.java @@ -72,6 +72,7 @@ import org.picocontainer.defaults.DefaultPicoContainer; public class ComponentRegistry { private PicoContainer container; + private boolean containerStarted; public ComponentRegistry() { MutablePicoContainer container = new DefaultPicoContainer(); @@ -113,6 +114,7 @@ public class ComponentRegistry { container.registerComponentImplementation(Scanner.class); container.registerComponentImplementation(StateMachine.class); container.registerComponentImplementation(ScannerDispatcherThreadFactory.class); + container.registerComponentImplementation(CommandLineProcessor.class); // GUI follows (TODO: move GUI to a separate place) @@ -211,11 +213,23 @@ public class ComponentRegistry { } } - public MainWindow createMainWindow() { + private void start() { + if (!containerStarted) { + containerStarted = true; + container.start(); + } + } + + public MainWindow getMainWindow() { // initialize all startable components - container.start(); + start(); // initialize and return the main window return (MainWindow) container.getComponentInstance(MainWindow.class); } + public CommandLineProcessor getCommandLineProcessor() { + start(); + return (CommandLineProcessor) container.getComponentInstance(CommandLineProcessor.class); + } + } diff --git a/src/net/azib/ipscan/exporters/SQLExporter.java b/src/net/azib/ipscan/exporters/SQLExporter.java new file mode 100644 index 00000000..ec59d550 --- /dev/null +++ b/src/net/azib/ipscan/exporters/SQLExporter.java @@ -0,0 +1,41 @@ +/** + * + */ +package net.azib.ipscan.exporters; + +import java.io.IOException; + +import net.azib.ipscan.config.Labels; +import net.azib.ipscan.core.PortIterator; +import net.azib.ipscan.core.values.NumericRangeList; +import net.azib.ipscan.fetchers.IPFetcher; +import net.azib.ipscan.fetchers.PortsFetcher; + +/** + * SQL Exporter + *

+ * Exports results as an SQL inserts, suitable for sqlite, mysql, etc, + * optionally preceding by a 'create table'. + * TODO: implement SQLExporter + * + * @author Anton Keks + */ +public class SQLExporter extends AbstractExporter { + + static final char DELIMETER = ':'; + + public String getId() { + return "exporter.sql"; + } + + public String getFilenameExtension() { + return "sql"; + } + + public void setFetchers(String[] fetcherNames) throws IOException { + } + + public void nextAdressResults(Object[] results) throws IOException { + + } +}