package net.sourceforge.pain.tinylib.data; import net.sourceforge.pain.db.*; import java.util.*; /** * User: fmike Date: May 9, 2004 Time: 2:42:26 AM */ public final class BanRegistry extends DbObject { private static final int SITE_BANS = 0; private static final int NFIELDS = 1; public static final int SITE_BAN_NEWBIES = 1; public static final int SITE_BAN_ALL = 2; public BanRegistry() { } BanRegistry(final PainDB db) throws RuntimeException { super(db); } protected DbClassSchema provideSchema() { byte types[] = new byte[NFIELDS]; String names[] = new String[NFIELDS]; types[SITE_BANS] = DbType.STRING_KEY_MAP; names[SITE_BANS] = "site_bans"; return new DbClassSchema(types, names); } /* keys of map are ""+site_ip+ban_type */ public Map getSiteBans() { return getStringKeyMap(SITE_BANS); } /** * * @param ip * @param host - site DNS host name, or IP copy if no domain name found * @param type * @param adminName * @param reason * @return */ public SiteBan banSite(String ip, String host, int type, String adminName, String reason) { String banKey = getSiteBanKey(ip, type); Map bans = getSiteBans(); SiteBan ban = (SiteBan) bans.get(banKey); if (ban != null) { throw new IllegalStateException("Site was already banned by : " + ban.getAdminName()); } ban = new SiteBan(getDB(), ip, host, type, adminName, reason); bans.put(banKey, ban); return ban; } private String getSiteBanKey(String ip, int type) { return ip + "_" + type; } public SiteBan getSiteBan(String ip, int banType) { return (SiteBan) getSiteBans().get(getSiteBanKey(ip, banType)); } }