You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by no...@apache.org on 2006/09/25 07:43:28 UTC

svn commit: r449578 - /james/jspf/trunk/src/main/java/org/apache/james/jspf/SPFQuery.java

Author: norman
Date: Sun Sep 24 22:43:27 2006
New Revision: 449578

URL: http://svn.apache.org/viewvc?view=rev&rev=449578
Log:
Allow the user to set a default explanation on cmdline usage. See JSPF-28

Modified:
    james/jspf/trunk/src/main/java/org/apache/james/jspf/SPFQuery.java

Modified: james/jspf/trunk/src/main/java/org/apache/james/jspf/SPFQuery.java
URL: http://svn.apache.org/viewvc/james/jspf/trunk/src/main/java/org/apache/james/jspf/SPFQuery.java?view=diff&rev=449578&r1=449577&r2=449578
==============================================================================
--- james/jspf/trunk/src/main/java/org/apache/james/jspf/SPFQuery.java (original)
+++ james/jspf/trunk/src/main/java/org/apache/james/jspf/SPFQuery.java Sun Sep 24 22:43:27 2006
@@ -45,8 +45,20 @@
     
     private final static int NONE_RCODE = 6;
     
-    private final static int UNKNOWN_RCODE = 255;
-
+    private final static int UNKNOWN_RCODE = 255;
+    
+    private final static String CMD_IP = "-ip";
+    
+    private final static String CMD_SENDER = "-sender";
+    
+    private final static String CMD_HELO = "-helo";
+    
+    private final static String CMD_DEBUG = "-debug";
+    
+    private final static String CMD_VERBOSE = "-verbose";
+
+    private final static String CMD_DEFAULT_EXP =  "-default-explanation";
+    
     private static Logger logger = Logger.getRootLogger();
 
     /**
@@ -57,7 +69,8 @@
 
         String ip = null;
         String sender = null;
-        String helo = null;
+        String helo = null;
+        String defaultExplanation = null;
 
         SimpleLayout layout = new SimpleLayout();
         ConsoleAppender consoleAppender = new ConsoleAppender(layout);
@@ -71,17 +84,21 @@
         } else {
             for (int i = 0; i < args.length; i++) {
                 String[] arguments = args[i].split("=");
-
-                if (arguments[0].equals("-ip")) {
+
+                if (arguments == null || arguments.length != 2) usage();
+                
+                if (arguments[0].equals(CMD_IP)) {
                     ip = arguments[1];
-                } else if (arguments[0].equals("-sender")) {
+                } else if (arguments[0].equals(CMD_SENDER)) {
                     sender = arguments[1];
-                } else if (arguments[0].equals("-helo")) {
+                } else if (arguments[0].equals(CMD_HELO)) {
                     helo = arguments[1];
-                } else if (arguments[0].equals("-debug")) {
+                } else if (arguments[0].equals(CMD_DEBUG)) {
                     logger.setLevel(Level.DEBUG);
-                } else if (arguments[0].equals("-verbose")) {
-                    logger.setLevel(Level.TRACE);
+                } else if (arguments[0].equals(CMD_VERBOSE)) {
+                    logger.setLevel(Level.TRACE);
+                } else if (arguments[0].equals(CMD_DEFAULT_EXP)) {
+                    defaultExplanation = arguments[1];
                 } else {
                     usage();
                 }
@@ -89,12 +106,20 @@
             }
 
             // check if all needed values was set
-            if (ip != null && sender != null && helo != null) {
-                SPF spf = new SPF(new Log4JLogger(logger));
+            if (ip != null && sender != null && helo != null) {
+                
+                SPF spf = new SPF(new Log4JLogger(logger));
+                
+                // Check if we should set a costum default explanation
+                if (defaultExplanation != null) {
+                    spf.setDefaultExplanation(defaultExplanation);
+                }
+                
                 SPFResult result = spf.checkSPF(ip, sender, helo);
                 System.out.println(result.getResult());
                 System.out.println(result.getHeader());
-                System.exit(getReturnCode(result.getResult()));
+                System.exit(getReturnCode(result.getResult()));
+                
             } else {
                 usage();
             }
@@ -105,8 +130,8 @@
      * Print out the usage
      */
     private static void usage() {
-        System.out
-                .println("Usage: java -jar jspf-x.jar -ip=192.168.100.1 -sender=postmaster@foo.bar -helo=foo.bar [-debug] [-verbose]");
+        System.out.println("Usage: java -jar jspf-x.jar " + CMD_IP + "=192.168.100.1 " + CMD_SENDER + "=postmaster@foo.bar "
+                        + CMD_HELO + "=foo.bar [" + CMD_DEBUG + "] [" + CMD_VERBOSE+ "]");
         System.exit(UNKNOWN_RCODE);
     }
     
@@ -117,7 +142,8 @@
      * @param result The result 
      * @return returnCode
      */
-    public static int getReturnCode(String result) {
+    public static int getReturnCode(String result) {
+        
         if (result.equals(SPF1Utils.PASS_CONV)) {
             return PASS_RCODE;
         } else if (result.equals(SPF1Utils.FAIL_CONV)) {
@@ -132,7 +158,8 @@
             return PERM_ERROR_RCODE;
         } else if (result.equals(SPF1Utils.NONE_CONV)) {
             return NONE_RCODE;
-        } 
+        } 
+        
         return UNKNOWN_RCODE;
     }
 



---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org