]> WPIA git - gigi.git/blobdiff - src/org/cacert/gigi/ping/PingerDaemon.java
Move the "dbObject"s to their own package.
[gigi.git] / src / org / cacert / gigi / ping / PingerDaemon.java
index 253780cbe19a041926b204d78b5c1f89b9ee7ad9..4ed4eb4bcdfef020a920ef09534d45f32303beeb 100644 (file)
@@ -1,16 +1,14 @@
 package org.cacert.gigi.ping;
 
-import java.io.FileReader;
-import java.io.IOException;
+import java.security.KeyStore;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.util.HashMap;
-import java.util.Properties;
 
-import org.cacert.gigi.Domain;
-import org.cacert.gigi.User;
 import org.cacert.gigi.database.DatabaseConnection;
+import org.cacert.gigi.dbObjects.Domain;
+import org.cacert.gigi.dbObjects.User;
 import org.cacert.gigi.util.RandomToken;
 
 public class PingerDaemon extends Thread {
@@ -21,13 +19,19 @@ public class PingerDaemon extends Thread {
 
     private PreparedStatement enterPingResult;
 
+    private KeyStore truststore;
+
+    public PingerDaemon(KeyStore truststore) {
+        this.truststore = truststore;
+    }
+
     @Override
     public void run() {
         try {
             searchNeededPings = DatabaseConnection.getInstance().prepare("SELECT pingconfig.*, domains.domain, domains.memid FROM pingconfig LEFT JOIN domainPinglog ON domainPinglog.configId=pingconfig.id INNER JOIN domains ON domains.id=pingconfig.domainid WHERE domainPinglog.configId IS NULL ");
             enterPingResult = DatabaseConnection.getInstance().prepare("INSERT INTO domainPinglog SET configId=?, state=?, result=?, challenge=?");
             pingers.put("email", new EmailPinger());
-            pingers.put("ssl", new SSLPinger());
+            pingers.put("ssl", new SSLPinger(truststore));
             pingers.put("http", new HTTPFetch());
             pingers.put("dns", new DNSPinger());
         } catch (SQLException e) {
@@ -42,7 +46,6 @@ public class PingerDaemon extends Thread {
             try {
                 Thread.sleep(5000);
             } catch (InterruptedException e) {
-                e.printStackTrace();
             }
         }
     }
@@ -62,19 +65,11 @@ public class PingerDaemon extends Thread {
                 }
                 enterPingResult.setInt(1, rs.getInt("id"));
                 String resp = dp.ping(Domain.getById(rs.getInt("domainid")), config, User.getById(rs.getInt("memid")));
-                enterPingResult.setString(2, resp == DomainPinger.PING_STILL_PENDING ? "open" : resp == DomainPinger.PING_SUCCEDED ? "success" : "failed");
+                enterPingResult.setString(2, DomainPinger.PING_STILL_PENDING == resp ? "open" : DomainPinger.PING_SUCCEDED.equals(resp) ? "success" : "failed");
                 enterPingResult.setString(3, resp);
                 enterPingResult.setString(4, token);
                 enterPingResult.execute();
             }
         }
     }
-
-    public static void main(String[] args) throws IOException {
-        Properties conf = new Properties();
-        conf.load(new FileReader("config/gigi.properties"));
-        DatabaseConnection.init(conf);
-        new PingerDaemon().run();
-
-    }
 }