public class Domain implements IdCachable, Verifyable {
- private User owner;
+ private CertificateOwner owner;
private String suffix;
throw new IllegalArgumentException("Invalid domain id " + id);
}
this.id = id;
- owner = User.getById(rs.getInt(1));
+ owner = CertificateOwner.getById(rs.getInt(1));
suffix = rs.getString(2);
rs.close();
}
- public Domain(User owner, String suffix) throws GigiApiException {
- checkCertifyableDomain(suffix, owner.isInGroup(Group.CODESIGNING));
- this.owner = owner;
- this.suffix = suffix;
-
+ public Domain(User actor, CertificateOwner owner, String suffix) throws GigiApiException {
+ synchronized (Domain.class) {
+ checkCertifyableDomain(suffix, actor.isInGroup(Group.CODESIGNING));
+ this.owner = owner;
+ this.suffix = suffix;
+ insert();
+ }
}
public static void checkCertifyableDomain(String s, boolean hasPunycodeRight) throws GigiApiException {
}
}
- public void insert() throws GigiApiException {
- synchronized (Domain.class) {
- if (id != 0) {
- throw new GigiApiException("already inserted.");
- }
- checkInsert(suffix);
- GigiPreparedStatement ps = DatabaseConnection.getInstance().prepare("INSERT INTO `domains` SET memid=?, domain=?");
- ps.setInt(1, owner.getId());
- ps.setString(2, suffix);
- ps.execute();
- id = ps.lastInsertId();
- myCache.put(this);
+ private void insert() throws GigiApiException {
+ if (id != 0) {
+ throw new GigiApiException("already inserted.");
}
+ checkInsert(suffix);
+ GigiPreparedStatement ps = DatabaseConnection.getInstance().prepare("INSERT INTO `domains` SET memid=?, domain=?");
+ ps.setInt(1, owner.getId());
+ ps.setString(2, suffix);
+ ps.execute();
+ id = ps.lastInsertId();
+ myCache.put(this);
}
public void delete() throws GigiApiException {
ps.execute();
}
- public User getOwner() {
+ public CertificateOwner getOwner() {
return owner;
}
}
public synchronized void verify(String hash) throws GigiApiException {
- GigiPreparedStatement ps = DatabaseConnection.getInstance().prepare("UPDATE `domainPinglog` SET `state`='success' WHERE `challenge`=? AND `configId` IN (SELECT `id` FROM `pingconfig` WHERE `domainid`=?)");
+ GigiPreparedStatement ps = DatabaseConnection.getInstance().prepare("UPDATE `domainPinglog` SET `state`='success' WHERE `challenge`=? AND `state`='open' AND `configId` IN (SELECT `id` FROM `pingconfig` WHERE `domainid`=? AND `type`='email')");
ps.setString(1, hash);
ps.setInt(2, id);
ps.executeUpdate();
}
public DomainPingExecution[] getPings() throws GigiApiException {
- GigiPreparedStatement ps = DatabaseConnection.getInstance().prepareScrollable("SELECT `state`, `type`, `info`, `result`, `configId` FROM `domainPinglog` INNER JOIN `pingconfig` ON `pingconfig`.`id`=`domainPinglog`.`configId` WHERE `pingconfig`.`domainid`=? ORDER BY `when` DESC;");
+ GigiPreparedStatement ps = DatabaseConnection.getInstance().prepareScrollable("SELECT `state`, `type`, `info`, `result`, `configId`, `when` FROM `domainPinglog` INNER JOIN `pingconfig` ON `pingconfig`.`id`=`domainPinglog`.`configId` WHERE `pingconfig`.`domainid`=? ORDER BY `when` DESC;");
ps.setInt(1, id);
GigiResultSet rs = ps.executeQuery();
rs.last();