Author: jflesch
Date: 2007-07-30 02:32:15 +0000 (Mon, 30 Jul 2007)
New Revision: 14434
Added:
trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/SSKBoard.java
trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/SSKBoardFactory.java
Modified:
trunk/apps/Thaw/src/thaw/core/Main.java
trunk/apps/Thaw/src/thaw/fcp/FCPClientGet.java
trunk/apps/Thaw/src/thaw/fcp/FCPClientPut.java
trunk/apps/Thaw/src/thaw/i18n/source.thaw_fr.properties
trunk/apps/Thaw/src/thaw/i18n/thaw.properties
trunk/apps/Thaw/src/thaw/i18n/thaw_fr.properties
trunk/apps/Thaw/src/thaw/plugins/MiniFrost.java
trunk/apps/Thaw/src/thaw/plugins/index/Comment.java
trunk/apps/Thaw/src/thaw/plugins/index/Index.java
trunk/apps/Thaw/src/thaw/plugins/miniFrost/BoardTree.java
trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKBoard.java
trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKBoardAttachment.java
trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKBoardFactory.java
trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKDraft.java
trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKFileAttachment.java
trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKMessage.java
trunk/apps/Thaw/src/thaw/plugins/miniFrost/interfaces/Board.java
trunk/apps/Thaw/src/thaw/plugins/signatures/Identity.java
Log:
Add support for the keyed/signed boards
Modified: trunk/apps/Thaw/src/thaw/core/Main.java
===================================================================
--- trunk/apps/Thaw/src/thaw/core/Main.java 2007-07-29 22:28:50 UTC (rev
14433)
+++ trunk/apps/Thaw/src/thaw/core/Main.java 2007-07-30 02:32:15 UTC (rev
14434)
@@ -128,9 +128,5 @@
}
-
-
-
-
}
Modified: trunk/apps/Thaw/src/thaw/fcp/FCPClientGet.java
===================================================================
--- trunk/apps/Thaw/src/thaw/fcp/FCPClientGet.java 2007-07-29 22:28:50 UTC
(rev 14433)
+++ trunk/apps/Thaw/src/thaw/fcp/FCPClientGet.java 2007-07-30 02:32:15 UTC
(rev 14434)
@@ -88,7 +88,9 @@
/**
* Used to resume query from persistent queue of the node.
* Think of adding this FCPClientGet as a queryManager observer.
- * @param destinationDir if null, then a temporary file will be create
(path determined only when the file is availabed ; this file will be deleted on
jvm exit)
+ * @param destinationDir if null, then a temporary file will be create
+ * (path determined only when the file is
availabed ;
+ * this file will be deleted on jvm exit)
*/
public FCPClientGet(final String id, final String key, final int
priority,
final int persistence, final boolean globalQueue,
Modified: trunk/apps/Thaw/src/thaw/fcp/FCPClientPut.java
===================================================================
--- trunk/apps/Thaw/src/thaw/fcp/FCPClientPut.java 2007-07-29 22:28:50 UTC
(rev 14433)
+++ trunk/apps/Thaw/src/thaw/fcp/FCPClientPut.java 2007-07-30 02:32:15 UTC
(rev 14434)
@@ -76,7 +76,7 @@
* @param keyType : KEY_TYPE_CHK ; KEY_TYPE_KSK ; KEY_TYPE_SSK
* @param rev : ignored if key == CHK || rev == -1
* @param name : ignored if key == CHK
- * @param privateKey : ignored if key == CHK/KSK ; can be null if it
has to be generated ; USK@[...]/
+ * @param privateKey : ignored if key == CHK/KSK ; can be null if it
has to be generated ; USK@[...]/ (must ends with a '/'
* @param persistence PERSISTENCE_FOREVER ;
PERSISTENCE_UNTIL_NODE_REBOOT ; PERSISTENCE_UNTIL_DISCONNEC
*/
public FCPClientPut(final File file, final int keyType,
@@ -910,13 +910,19 @@
else
key = "KSK@" + name;
}
+ else if (keyType == KEY_TYPE_SSK &&
privateKey.startsWith("SSK")) {
+ if (rev >= 0)
+ key = privateKey + name+"-"+rev;
+ else
+ key = privateKey + name;
+ }
+ else if (keyType == KEY_TYPE_SSK &&
privateKey.startsWith("USK")) {
+ if (rev >= 0)
+ key = privateKey + name + "/" + rev;
+ else
+ key = privateKey + name;
+ }
- else if (keyType == KEY_TYPE_SSK &&
privateKey.startsWith("SSK"))
- key = privateKey + name+"-"+rev;
-
- else if (keyType == KEY_TYPE_SSK &&
privateKey.startsWith("USK"))
- key = privateKey + name + "/" + rev;
-
if (key == null) {
Logger.warning(this, "Unknown key type ?! May result in
a strange behavior !");
return privateKey;
Modified: trunk/apps/Thaw/src/thaw/i18n/source.thaw_fr.properties
===================================================================
--- trunk/apps/Thaw/src/thaw/i18n/source.thaw_fr.properties 2007-07-29
22:28:50 UTC (rev 14433)
+++ trunk/apps/Thaw/src/thaw/i18n/source.thaw_fr.properties 2007-07-30
02:32:15 UTC (rev 14434)
@@ -166,7 +166,7 @@
thaw.plugin.insert.SSK=SSK / USK
thaw.plugin.insert.selectRev=Revision
thaw.plugin.insert.selectName=Nom
-thaw.plugin.insert.publicKey=Clef public
+thaw.plugin.insert.publicKey=Clef publique
thaw.plugin.insert.privateKey=Clef priv?e
thaw.plugin.insert.insertAction=Inserer
thaw.plugin.insert.specifyNameAndRev=Veuillez sp?cifier un nom et une r?vision
@@ -528,10 +528,17 @@
thaw.plugin.miniFrost=Forums
thaw.plugin.miniFrost.boards=Boards
thaw.plugin.miniFrost.board=Board
-thaw.plugin.miniFrost.FrostKSK=boards Frost non-sign?e
+
+thaw.plugin.miniFrost.FrostKSK=board Frost non-sign?e
+thaw.plugin.miniFrost.FrostSSK=board Frost sign?e
+
thaw.plugin.miniFrost.selectType=Veuillez selectionner le type de board voulu
thaw.plugin.miniFrost.boardName=Nom de la board ?
+thaw.plugin.miniFrost.board.name=Nom:
+thaw.plugin.miniFrost.board.publicKey=Clef publique:
+thaw.plugin.miniFrost.board.privateKey=Clef priv?e:
+
thaw.plugin.miniFrost.loadNewMessages=Charger les nouveaux messages
thaw.plugin.miniFrost.subject=Sujet
@@ -579,3 +586,4 @@
thaw.plugin.miniFrost.newMsgAnnounce=X nouveaux messages sur la board 'Y'
thaw.plugin.miniFrost.messageSent=Message sur la board 'X' envoy?
+thaw.plugin.miniFrost.generateKeys=Generer les clefs
Modified: trunk/apps/Thaw/src/thaw/i18n/thaw.properties
===================================================================
--- trunk/apps/Thaw/src/thaw/i18n/thaw.properties 2007-07-29 22:28:50 UTC
(rev 14433)
+++ trunk/apps/Thaw/src/thaw/i18n/thaw.properties 2007-07-30 02:32:15 UTC
(rev 14434)
@@ -542,10 +542,17 @@
thaw.plugin.miniFrost=Boards
thaw.plugin.miniFrost.boards=Boards
thaw.plugin.miniFrost.board=Board
-thaw.plugin.miniFrost.FrostKSK=unsigned Frost boards
+
+thaw.plugin.miniFrost.FrostKSK=unsigned Frost board
+thaw.plugin.miniFrost.FrostSSK=signed Frost board
+
thaw.plugin.miniFrost.selectType=Please select the board type wanted
thaw.plugin.miniFrost.boardName=Board name ?
+thaw.plugin.miniFrost.board.name=Name:
+thaw.plugin.miniFrost.board.publicKey=Public key:
+thaw.plugin.miniFrost.board.privateKey=Private key:
+
thaw.plugin.miniFrost.loadNewMessages=Load new messages
@@ -594,3 +601,5 @@
thaw.plugin.miniFrost.newMsgAnnounce=X new messages on the board 'Y'
thaw.plugin.miniFrost.messageSent=Message to the board 'X' sent
+
+thaw.plugin.miniFrost.generateKeys=Generate keys
Modified: trunk/apps/Thaw/src/thaw/i18n/thaw_fr.properties
===================================================================
--- trunk/apps/Thaw/src/thaw/i18n/thaw_fr.properties 2007-07-29 22:28:50 UTC
(rev 14433)
+++ trunk/apps/Thaw/src/thaw/i18n/thaw_fr.properties 2007-07-30 02:32:15 UTC
(rev 14434)
@@ -528,10 +528,17 @@
thaw.plugin.miniFrost=Forums
thaw.plugin.miniFrost.boards=Boards
thaw.plugin.miniFrost.board=Board
-thaw.plugin.miniFrost.FrostKSK=boards Frost non-sign\u00e9e
+
+thaw.plugin.miniFrost.FrostKSK=board Frost non-sign\u00e9e
+thaw.plugin.miniFrost.FrostSSK=board Frost sign\u00e9e
+
thaw.plugin.miniFrost.selectType=Veuillez selectionner le type de board voulu
thaw.plugin.miniFrost.boardName=Nom de la board ?
+thaw.plugin.miniFrost.board.name=Nom:
+thaw.plugin.miniFrost.board.publicKey=Clef publique:
+thaw.plugin.miniFrost.board.privateKey=Clef priv\u00e9e:
+
thaw.plugin.miniFrost.loadNewMessages=Charger les nouveaux messages
thaw.plugin.miniFrost.subject=Sujet
@@ -579,3 +586,4 @@
thaw.plugin.miniFrost.newMsgAnnounce=X nouveaux messages sur la board 'Y'
thaw.plugin.miniFrost.messageSent=Message sur la board 'X' envoy\u00e9
+thaw.plugin.miniFrost.generateKeys=Generer les clefs
Modified: trunk/apps/Thaw/src/thaw/plugins/MiniFrost.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/MiniFrost.java 2007-07-29 22:28:50 UTC
(rev 14433)
+++ trunk/apps/Thaw/src/thaw/plugins/MiniFrost.java 2007-07-30 02:32:15 UTC
(rev 14434)
@@ -25,6 +25,7 @@
public final static BoardFactory[] factories =
new BoardFactory[] {
new thaw.plugins.miniFrost.frostKSK.KSKBoardFactory(),
+ new thaw.plugins.miniFrost.frostKSK.SSKBoardFactory()
};
Modified: trunk/apps/Thaw/src/thaw/plugins/index/Comment.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/Comment.java 2007-07-29 22:28:50 UTC
(rev 14433)
+++ trunk/apps/Thaw/src/thaw/plugins/index/Comment.java 2007-07-30 02:32:15 UTC
(rev 14434)
@@ -772,7 +772,7 @@
FCPClientGet get = new FCPClientGet(publicKey, 2 /* priority */,
FCPClientGet.PERSISTENCE_UNTIL_DISCONNECT /* persistence */,
- false /* global queue */, 3
/* max retries */,
+ false /* global queue */, 0
/* maxretries */,
System.getProperty("java.io.tmpdir"),
MAX_SIZE, true /* no DDA
*/);
Modified: trunk/apps/Thaw/src/thaw/plugins/index/Index.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/Index.java 2007-07-29 22:28:50 UTC
(rev 14433)
+++ trunk/apps/Thaw/src/thaw/plugins/index/Index.java 2007-07-30 02:32:15 UTC
(rev 14434)
@@ -833,7 +833,7 @@
2, /* <= priority */
FCPClientGet.PERSISTENCE_UNTIL_DISCONNECT,
false, /* <= globalQueue */
- 5, /* maxRetries */
+ 3, /* maxRetries */
System.getProperty("java.io.tmpdir"), /* destination directory */
MAX_SIZE, /* max size */
true /* <= noDDA */);
Modified: trunk/apps/Thaw/src/thaw/plugins/miniFrost/BoardTree.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/miniFrost/BoardTree.java 2007-07-29
22:28:50 UTC (rev 14433)
+++ trunk/apps/Thaw/src/thaw/plugins/miniFrost/BoardTree.java 2007-07-30
02:32:15 UTC (rev 14434)
@@ -274,7 +274,7 @@
}
}
- /* TODO : Sort the vector */
+ java.util.Collections.sort(boards);
model.setBoardList(boards);
}
Modified: trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKBoard.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKBoard.java
2007-07-29 22:28:50 UTC (rev 14433)
+++ trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKBoard.java
2007-07-30 02:32:15 UTC (rev 14434)
@@ -70,6 +70,7 @@
}
+
public Vector getMessages(String[] keywords,
int orderBy,
boolean desc,
@@ -315,7 +316,50 @@
return lastDate;
}
+ /* for example KSK at frost|message|news|2007.7.21-boards-47.xml */
+ public final static String KEY_HEADER = /* "KSK@" +
*/"frost|message|news|";
+ /**
+ * called by KSKMessage.download();
+ */
+ protected String getDownloadKey(Date date, int rev) {
+ java.text.SimpleDateFormat formatter = new
java.text.SimpleDateFormat("yyyy.M.d");
+
+ StringBuffer keyBuf = new StringBuffer("KSK@"+KEY_HEADER);
+
+ keyBuf = formatter.format(date, keyBuf, new
java.text.FieldPosition(0));
+ keyBuf.append("-"+getName()+"-");
+ keyBuf.append(Integer.toString(rev));
+ keyBuf.append(".xml");
+
+ return keyBuf.toString();
+ }
+
+ /**
+ * called by KSKDraft
+ */
+ protected String getPrivateKey() {
+ return null;
+ }
+
+ /**
+ * called by KSKDraft
+ */
+ protected String getNameForInsertion(Date date, int rev) {
+ java.text.SimpleDateFormat formatter = new
java.text.SimpleDateFormat("yyyy.M.d");
+ //formatter.setTimeZone(java.util.TimeZone.getTimeZone("GMT"));
+
+ StringBuffer keyBuf = new StringBuffer(KEY_HEADER);
+
+ keyBuf = formatter.format(date, keyBuf, new
java.text.FieldPosition(0));
+ keyBuf.append("-"+getName()+"-");
+ keyBuf.append(Integer.toString(rev));
+ keyBuf.append(".xml");
+
+ return keyBuf.toString();
+ }
+
+
protected static Date getMidnight(Date date) {
Calendar cal = new java.util.GregorianCalendar();
cal.setTime(date);
@@ -636,9 +680,12 @@
}
- public void destroy() {
+ public boolean destroy() {
Hsqldb db = factory.getDb();
+ if (!KSKMessage.destroy(this, db))
+ return false;
+
try {
synchronized(db.dbLock) {
PreparedStatement st;
@@ -650,7 +697,10 @@
}
} catch(SQLException e) {
Logger.error(this, "Can't destroy the board because :
"+e.toString());
+ return false;
}
+
+ return true;
}
public int getId() {
@@ -678,4 +728,8 @@
public Draft getDraft(Message inReplyTo) {
return new KSKDraft(this, (KSKMessage)inReplyTo);
}
+
+ public int compareTo(Object o) {
+ return toString().compareToIgnoreCase(o.toString());
+ }
}
Modified:
trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKBoardAttachment.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKBoardAttachment.java
2007-07-29 22:28:50 UTC (rev 14433)
+++ trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKBoardAttachment.java
2007-07-30 02:32:15 UTC (rev 14434)
@@ -31,6 +31,13 @@
String privateKey,
String description) {
this.boardName = boardName;
+
+ if (publicKey.endsWith("/"))
+ publicKey.replaceAll("/", "");
+
+ if (privateKey != null && privateKey.endsWith("/"))
+ privateKey.replaceAll("/", "");
+
this.publicKey = publicKey;
this.privateKey = privateKey;
this.description = description;
@@ -158,8 +165,7 @@
public void apply(Hsqldb db, FCPQueueManager queueManager, String
action) {
if (action.equals(I18n.getMessage("thaw.common.add"))) {
if (publicKey != null) {
- /* TODO */
- Logger.error(this, "Signed board not supported
atm");
+ boardFactory.createBoard(boardName, publicKey,
privateKey);
return;
}
boardFactory.createBoard(boardName);
@@ -246,4 +252,31 @@
return buf;
}
+
+ public static boolean destroy(KSKBoard board, Hsqldb db) {
+ try {
+ synchronized(db.dbLock) {
+ PreparedStatement st;
+
+ st =
db.getConnection().prepareStatement("SELECT id FROM frostKSKMessages "+
+ "WHERE
boardId = ?");
+ st.setInt(1, board.getId());
+
+ ResultSet set = st.executeQuery();
+
+ while(set.next()) {
+ int id = set.getInt("id");
+ st =
db.getConnection().prepareStatement("DELETE FROM frostKSKAttachmentBoards "+
+
"WHERE messageId = ?");
+ st.setInt(1, id);
+ st.execute();
+ }
+ }
+ } catch(SQLException e) {
+ Logger.error(null, "Can't destroy the board attachments
of the board because : "+e.toString());
+ return false;
+ }
+
+ return true;
+ }
}
Modified:
trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKBoardFactory.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKBoardFactory.java
2007-07-29 22:28:50 UTC (rev 14433)
+++ trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKBoardFactory.java
2007-07-30 02:32:15 UTC (rev 14434)
@@ -7,6 +7,7 @@
import java.util.HashMap;
import java.util.Iterator;
+import java.util.Date;
import thaw.core.Core;
import thaw.core.Logger;
@@ -107,6 +108,13 @@
+ "name VARCHAR(128) NOT NULL, "
+ "lastUpdate DATE DEFAULT NULL NULL)");
+ sendQuery("CREATE CACHED TABLE frostSSKBoards ("
+ + "id INTEGER IDENTITY NOT NULL, "
+ + "publicKey VARCHAR(256) NOT NULL, "
+ + "privateKey VARCHAR(256) NULL, "
+ + "kskBoardId INTEGER NOT NULL, "
+ + "FOREIGN KEY (kskBoardId) REFERENCES frostKSKBoards
(id))");
+
sendQuery("CREATE CACHED TABLE frostKSKMessages ("
+ "id INTEGER IDENTITY NOT NULL, "
+ "subject VARCHAR(512) NULL, "
@@ -144,48 +152,60 @@
}
- private void addDefaultBoards() {
+ protected void addDefaultBoards() {
for (int i = 0 ; i < DEFAULT_BOARDS.length ; i++) {
createBoard(DEFAULT_BOARDS[i]);
}
}
+ protected int countNewMessages(int boardId) {
+ int count = 0;
+ try {
+ PreparedStatement subSt
+ = db.getConnection().prepareStatement("SELECT
count(id)"+
+ "FROM
frostKSKMessages "+
+ "WHERE
boardId = ? "+
+ "AND read
= FALSE AND archived = FALSE");
+ subSt.setInt(1, boardId);
+ ResultSet subRes = subSt.executeQuery();
+ if (subRes.next())
+ count = subRes.getInt(1);
+ } catch(SQLException e) {
+ Logger.error(this, "Can't count the number of new
message on the board because : "+e.toString());
+ }
+
+ return count;
+ }
+
+
+
public Vector getBoards() {
Vector v = new Vector();
try {
synchronized(db.dbLock) {
PreparedStatement st
- =
db.getConnection().prepareStatement("SELECT id, name, lastUpdate "+
-
"FROM frostKSKBoards "+
+ =
db.getConnection().prepareStatement("SELECT frostKSKBoards.id, "+
+ "
frostKSKBoards.name, "+
+ "
frostKSKBoards.lastUpdate "+
+
"FROM frostKSKBoards LEFT OUTER JOIN frostSSKBoards "+
+ "
ON frostKSKBoards.id = frostSSKBoards.kskBoardId "+
+
"WHERE frostSSKBoards.id IS NULL "+
"ORDER BY LOWER(name)");
ResultSet set = st.executeQuery();
while(set.next()) {
int id = set.getInt("id");
String name = set.getString("name");
+ Date lastUpdate =
set.getDate("lastUpdate");
if (boards.get(name) != null)
v.add(boards.get(name));
else {
+ int count =
countNewMessages(id);
- int count = 0;
- java.util.Date lastUpdate =
set.getDate("lastUpdate");
-
- PreparedStatement subSt
- =
st.getConnection().prepareStatement("SELECT count(id)"+
-
"FROM frostKSKMessages "+
-
"WHERE boardId = ? "+
-
"AND read = FALSE AND archived = FALSE");
- subSt.setInt(1, id);
-
- ResultSet subRes =
subSt.executeQuery();
-
- if (subRes.next())
- count =
subRes.getInt(1);
-
KSKBoard board = new
KSKBoard(this,
id, name, lastUpdate,
count);
@@ -203,11 +223,7 @@
}
- protected KSKBoard getBoard(String name) {
- return (KSKBoard)boards.get(name);
- }
-
protected KSKBoard getBoard(int id) {
for (Iterator it = boards.values().iterator();
it.hasNext();) {
@@ -221,6 +237,7 @@
}
+
public Vector getAllMessages(String[] keywords, int orderBy,
boolean desc, boolean archived,
boolean unsigned, int minTrustLevel) {
@@ -242,13 +259,18 @@
createBoard(name);
}
- public void createBoard(String name) {
+ protected void createBoard(String name) {
try {
synchronized(db.dbLock) {
PreparedStatement st;
- st =
db.getConnection().prepareStatement("SELECT id FROM frostKSKBoards "+
- "WHERE
LOWER(name) = ?");
+ st =
db.getConnection().prepareStatement("SELECT frostKSKBoards.id, "+
+ "FROM
frostKSKBoards LEFT OUTER JOIN frostSSKBoards "+
+ " ON
frostKSKBoards.id = frostSSKBoards.kskBoardId "+
+ "WHERE
frostSSKBoards.id IS NULL "+
+ "AND
LOWER(frostKSKBoards.name) = ? "+
+ "LIMIT
1");
+
st.setString(1, name.toLowerCase());
ResultSet set = st.executeQuery();
@@ -269,6 +291,77 @@
}
+
+ /**
+ * Put here to make my life simpler with the KSKBoardAttachment.
+ */
+ protected void createBoard(String name, String publicKey, String
privateKey) {
+ if (!thaw.fcp.FreenetURIHelper.isAKey(publicKey)) {
+ Logger.error(this, "Invalid publicKey");
+ return;
+ }
+
+ if (privateKey != null && "".equals(privateKey))
+ privateKey = null;
+
+
+ try {
+ synchronized(db.dbLock) {
+ PreparedStatement st;
+
+ st =
db.getConnection().prepareStatement("SELECT id "+
+ "FROM
frostSSKBoards "+
+ "WHERE
publicKey = ?");
+ st.setString(1, publicKey);
+ ResultSet set = st.executeQuery();
+
+ if (set.next()) {
+ Logger.warning(this, "Board already
added");
+ return;
+ }
+
+ /* we must get the id first, else we will mix
up things */
+
+ int id = 0;
+
+ st =
db.getConnection().prepareStatement("SELECT id FROM frostKSKBoards "+
+ "ORDER
by id DESC LIMIT 1");
+ set = st.executeQuery();
+
+ if (set.next())
+ id = set.getInt("id") + 1;
+
+
+ name = name.toLowerCase();
+
+ st =
db.getConnection().prepareStatement("INSERT INTO frostKSKBoards "+
+ "(id,
name) VALUES (?, ?)");
+
+ st.setInt(1, id);
+ st.setString(2, name);
+
+ st.execute();
+
+
+ st =
db.getConnection().prepareStatement("INSERT INTO frostSSKBoards "+
+
"(publicKey, privateKey, kskBoardId) "+
+
"VALUES (?, ?, ?)");
+ st.setString(1, publicKey);
+ if (privateKey != null)
+ st.setString(2, privateKey);
+ else
+ st.setNull(2, Types.VARCHAR);
+ st.setInt(3, id);
+
+ st.execute();
+
+ }
+ } catch(SQLException e) {
+ Logger.error(this, "Can't add the board because :
"+e.toString());
+ }
+ }
+
+
public String toString() {
return I18n.getMessage("thaw.plugin.miniFrost.FrostKSK");
}
Modified: trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKDraft.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKDraft.java
2007-07-29 22:28:50 UTC (rev 14433)
+++ trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKDraft.java
2007-07-30 02:32:15 UTC (rev 14434)
@@ -154,34 +154,24 @@
}
- private String getKey(Date date, int rev) {
- java.text.SimpleDateFormat formatter = new
java.text.SimpleDateFormat("yyyy.M.d");
- //formatter.setTimeZone(java.util.TimeZone.getTimeZone("GMT"));
-
- StringBuffer keyBuf = new StringBuffer(KSKMessage.KEY_HEADER);
-
- keyBuf = formatter.format(date, keyBuf, new
java.text.FieldPosition(0));
- keyBuf.append("-"+board.getName()+"-");
- keyBuf.append(Integer.toString(rev));
- keyBuf.append(".xml");
-
- return keyBuf.toString();
- }
-
private void startInsertion() {
waiting = false;
posting = true;
notifyPlugin();
- String key = getKey(date, revUsed);
+ String privateKey = board.getPrivateKey();
+ String name = board.getNameForInsertion(date, revUsed);
- Logger.info(this, "Inserting : KSK@"+key);
+ if (privateKey == null)
+ Logger.info(this, "Inserting : KSK@"+name);
+ else
+ Logger.info(this, "Insertion : SSK@[...]/"+name);
FCPClientPut clientPut = new FCPClientPut(fileToInsert,
FCPClientPut.KEY_TYPE_KSK,
-1, /* rev : we
specify it ouselves in the key name */
- key,
- null, /* privateKey */
+ name,
+ privateKey, /*
privateKey */
2, /* priority */
false,
FCPClientPut.PERSISTENCE_FOREVER);
Modified:
trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKFileAttachment.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKFileAttachment.java
2007-07-29 22:28:50 UTC (rev 14433)
+++ trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKFileAttachment.java
2007-07-30 02:32:15 UTC (rev 14434)
@@ -266,4 +266,31 @@
return buf;
}
+
+ public static boolean destroy(KSKBoard board, Hsqldb db) {
+ try {
+ synchronized(db.dbLock) {
+ PreparedStatement st;
+
+ st =
db.getConnection().prepareStatement("SELECT id FROM frostKSKMessages "+
+ "WHERE
boardId = ?");
+ st.setInt(1, board.getId());
+
+ ResultSet set = st.executeQuery();
+
+ while(set.next()) {
+ int id = set.getInt("id");
+ st =
db.getConnection().prepareStatement("DELETE FROM frostKSKAttachmentFiles "+
+
"WHERE messageId = ?");
+ st.setInt(1, id);
+ st.execute();
+ }
+ }
+ } catch(SQLException e) {
+ Logger.error(null, "Can't destroy the file attachments
of the board because : "+e.toString());
+ return false;
+ }
+
+ return true;
+ }
}
Modified: trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKMessage.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKMessage.java
2007-07-29 22:28:50 UTC (rev 14433)
+++ trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKMessage.java
2007-07-30 02:32:15 UTC (rev 14434)
@@ -35,10 +35,7 @@
*/
public final static int FCP_MAX_SIZE = 32*1024;
- /* for example KSK at frost|message|news|2007.7.21-boards-47.xml */
- public final static String KEY_HEADER = /* "KSK@" +
*/"frost|message|news|";
-
/* content is not kept in memory (at least not here) */
private int id;
private String subject;
@@ -73,15 +70,8 @@
java.text.SimpleDateFormat formatter = new
java.text.SimpleDateFormat("yyyy.M.d");
//formatter.setTimeZone(java.util.TimeZone.getTimeZone("GMT"));
- StringBuffer keyBuf = new StringBuffer("KSK@"+KEY_HEADER);
+ key = board.getDownloadKey(date, rev);
- keyBuf = formatter.format(date, keyBuf, new
java.text.FieldPosition(0));
- keyBuf.append("-"+board.getName()+"-");
- keyBuf.append(Integer.toString(rev));
- keyBuf.append(".xml");
-
- key = keyBuf.toString();
-
Logger.info(this, "Fetching : "+key.toString());
FCPClientGet get = new FCPClientGet(key, FCP_PRIORITY,
@@ -108,7 +98,8 @@
int code = get.getGetFailedCode();
if (code == 13 /* dnd */
- || code == 14 /* route not found */) {
+ || code == 14 /* route not found */
+ || code == 20 /* jflesch is stupid */) {
Logger.info(this, key+" not found");
successfullyDownloaded = false;
} else {
@@ -474,4 +465,27 @@
return (((KSKMessage)o).getId() == id);
}
+
+
+ public static boolean destroy(KSKBoard board, Hsqldb db) {
+ if (!KSKFileAttachment.destroy(board, db)
+ || !KSKBoardAttachment.destroy(board, db))
+ return false;
+
+ try {
+ synchronized(db.dbLock) {
+ PreparedStatement st;
+
+ st =
db.getConnection().prepareStatement("DELETE FROM frostKSKMessages "+
+ "WHERE
boardId = ?");
+ st.setInt(1, board.getId());
+ st.execute();
+ }
+ } catch(SQLException e) {
+ Logger.error(null, "Can't destroy the board messages
because : "+e.toString());
+ return false;
+ }
+
+ return true;
+ }
}
Added: trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/SSKBoard.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/SSKBoard.java
(rev 0)
+++ trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/SSKBoard.java
2007-07-30 02:32:15 UTC (rev 14434)
@@ -0,0 +1,134 @@
+package thaw.plugins.miniFrost.frostKSK;
+
+import java.sql.*;
+
+import java.util.Date;
+import thaw.core.Logger;
+import thaw.plugins.Hsqldb;
+
+
+public class SSKBoard extends KSKBoard {
+
+ private String publicKey;
+ private String privateKey;
+
+ public SSKBoard(SSKBoardFactory factory,
+ int id, String name, Date lastUpdate,
+ String publicKey, String privateKey,
+ int newMessages) {
+
+ super(factory, id, name, lastUpdate, newMessages);
+
+ if (!publicKey.endsWith("/"))
+ publicKey += "/";
+ if (privateKey != null && !privateKey.endsWith("/"))
+ privateKey += "/";
+
+ this.publicKey = publicKey;
+ this.privateKey = privateKey;
+ }
+
+
+ /**
+ * called by KSKMessage.download();
+ */
+ protected String getDownloadKey(Date date, int rev) {
+ java.text.SimpleDateFormat formatter = new
java.text.SimpleDateFormat("yyyy.M.d");
+
+ StringBuffer keyBuf = new StringBuffer(publicKey);
+
+ keyBuf.append(getName()+"|");
+ keyBuf = formatter.format(date, keyBuf, new
java.text.FieldPosition(0));
+ keyBuf.append("-");
+ keyBuf.append(Integer.toString(rev));
+ keyBuf.append(".xml");
+
+ return keyBuf.toString();
+ }
+
+ /**
+ * called by KSKDraft
+ */
+ protected String getPrivateKey() {
+ return privateKey;
+ }
+
+ /**
+ * called by KSKDraft
+ */
+ protected String getNameForInsertion(Date date, int rev) {
+ java.text.SimpleDateFormat formatter = new
java.text.SimpleDateFormat("yyyy.M.d");
+
+ StringBuffer keyBuf = new StringBuffer(getName()+"|");
+
+ keyBuf = formatter.format(date, keyBuf, new
java.text.FieldPosition(0));
+ keyBuf.append("-");
+ keyBuf.append(Integer.toString(rev));
+ keyBuf.append(".xml");
+
+ return keyBuf.toString();
+ }
+
+ public boolean destroy() {
+ try {
+ Hsqldb db = getFactory().getDb();
+
+ synchronized(db.dbLock) {
+ PreparedStatement st;
+
+ st =
db.getConnection().prepareStatement("DELETE FROM frostSSKBoards "+
+ "WHERE
kskBoardId = ?");
+ st.setInt(1, getId());
+ st.execute();
+ }
+ } catch(SQLException e) {
+ Logger.error(this, "Can't destroy the board because :
"+e.toString());
+ return false;
+ }
+
+ if (!super.destroy()) {
+ /* unable to destroy the board
+ * => we put back the public and private keys
+ * to avoid some desynchronisations
+ */
+
+ try {
+ Hsqldb db = getFactory().getDb();
+
+ synchronized(db.dbLock) {
+ PreparedStatement st;
+
+ st =
db.getConnection().prepareStatement("INSERT INTO frostSSKBoards "+
+
"(publicKey, privateKey, kskBoardId) "+
+
"VALUES (?, ?, ?)");
+ st.setString(1, publicKey);
+ if (privateKey != null)
+ st.setString(2, privateKey);
+ else
+ st.setNull(2, Types.VARCHAR);
+ st.setInt(3, getId());
+
+ st.execute();
+ }
+ } catch(SQLException e) {
+ Logger.error(this, "Oops ! Unable to delete the
board, and I think that I've broken something :(");
+ Logger.error(this, "Reason : "+e.toString());
+ }
+
+ return false;
+ }
+
+ return true;
+ }
+
+
+ public thaw.plugins.miniFrost.interfaces.Draft
getDraft(thaw.plugins.miniFrost.interfaces.Message inReplyTo) {
+ if (privateKey == null) {
+ Logger.warning(this, "Sorry, you need the private key
to post on this board");
+ return null;
+ }
+
+ return super.getDraft(inReplyTo);
+ }
+}
+
Added: trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/SSKBoardFactory.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/SSKBoardFactory.java
(rev 0)
+++ trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/SSKBoardFactory.java
2007-07-30 02:32:15 UTC (rev 14434)
@@ -0,0 +1,231 @@
+/* Yes, I know ... */
+package thaw.plugins.miniFrost.frostKSK;
+
+import java.awt.GridLayout;
+import java.awt.BorderLayout;
+
+import javax.swing.JDialog;
+import javax.swing.JTextField;
+import javax.swing.JLabel;
+import javax.swing.JButton;
+import javax.swing.JPanel;
+
+import java.awt.event.ActionListener;
+import java.awt.event.ActionEvent;
+
+import java.util.Vector;
+import java.util.Iterator;
+import java.util.Date;
+import java.util.HashMap;
+
+import java.util.Observer;
+import java.util.Observable;
+
+import java.sql.*;
+
+import thaw.fcp.FCPGenerateSSK;
+import thaw.core.Logger;
+import thaw.core.Core;
+import thaw.core.I18n;
+import thaw.plugins.Hsqldb;
+import thaw.plugins.MiniFrost;
+
+
+public class SSKBoardFactory extends KSKBoardFactory {
+
+ public final static String[] DEFAULT_BOARDS_NAME = new String[] {
+ "freenet-announce"
+ };
+
+ public final static String[] DEFAULT_BOARDS_PUBLICKEY = new String[] {
+ "SSK at
MGJOpsf32MDiti3I3ipzdLwKAXZFumiih-YE5ABZNQE,gcUpKZ17E18pyAtXzk4FVjLPo8IgpUqiCa~yBB0RSZo,AQACAAE"
+ };
+
+
+ public final static int BOARD_FACTORY_ID = 1;
+
+ private Hsqldb db;
+ private Core core;
+
+ private HashMap boards;
+
+
+ public SSKBoardFactory() {
+ super();
+ }
+
+ public boolean init(Hsqldb db, Core core, MiniFrost plugin) {
+ this.db = db;
+ this.core = core;
+ this.boards = new HashMap();
+ return super.init(db, core, plugin);
+ }
+
+ protected void addDefaultBoards() {
+ for (int i = 0 ; i < DEFAULT_BOARDS_NAME.length ; i++)
+ createBoard(DEFAULT_BOARDS_NAME[i],
+ DEFAULT_BOARDS_PUBLICKEY[i],
+ null);
+ }
+
+ public Vector getBoards() {
+ Vector v = new Vector();
+
+ try {
+ synchronized(db.dbLock) {
+ PreparedStatement st
+ =
db.getConnection().prepareStatement("SELECT frostKSKBoards.id, "+
+ "
frostKSKBoards.name, "+
+ "
frostKSKBoards.lastUpdate, "+
+ "
frostSSKBoards.publicKey, "+
+ "
frostSSKBoards.privateKey "+
+
"FROM frostKSKBoards INNER JOIN frostSSKBoards "+
+ "
ON frostKSKBoards.id = frostSSKBoards.kskBoardId "+
+
"ORDER BY LOWER(name)");
+ ResultSet set = st.executeQuery();
+
+ while(set.next()) {
+ int id = set.getInt("id");
+ String name = set.getString("name");
+ String publicKey =
set.getString("publicKey");
+ String privateKey =
set.getString("privateKey");
+ Date lastUpdate =
set.getDate("lastUpdate");
+
+ if (boards.get(name+publicKey) != null)
+
v.add(boards.get(name+publicKey));
+ else {
+
+ int count =
countNewMessages(id);
+
+ SSKBoard board = new
SSKBoard(this,
+
id, name, lastUpdate,
+
publicKey, privateKey,
+
count);
+
+ v.add(board);
+ boards.put(name+publicKey,
board);
+ }
+ }
+ }
+ } catch(SQLException e) {
+ Logger.error(this, "Can't get the board list because :
"+e.toString());
+ }
+
+ return v;
+ }
+
+
+ protected KSKBoard getBoard(int id) {
+ for (Iterator it = boards.values().iterator();
+ it.hasNext();) {
+ KSKBoard board = (KSKBoard)it.next();
+
+ if (board.getId() == id)
+ return board;
+ }
+
+ return null;
+ }
+
+
+ public Vector getAllMessages(String[] keywords, int orderBy,
+ boolean desc, boolean archived,
+ boolean unsigned, int minTrustLevel) {
+ /* KSKBoardFactory will do the job for us */
+ return new Vector();
+ }
+
+
+
+ private class NewBoardDialog implements Observer, ActionListener {
+ private JDialog dialog;
+
+ private JTextField name;
+ private JTextField publicKey;
+ private JTextField privateKey;
+
+ private JButton generate;
+ private JButton ok;
+ private JButton cancel;
+
+ public NewBoardDialog(thaw.core.MainWindow mainWindow) {
+ dialog = new JDialog(mainWindow.getMainFrame(),
+
I18n.getMessage("thaw.plugin.miniFrost.FrostSSK"));
+
+ dialog.getContentPane().setLayout(new BorderLayout(5,
5));
+
+ JPanel labelPanel = new JPanel(new GridLayout(4, 1));
+ labelPanel.add(new
JLabel(I18n.getMessage("thaw.plugin.miniFrost.board.name")));
+ labelPanel.add(new
JLabel(I18n.getMessage("thaw.plugin.miniFrost.board.publicKey")));
+ labelPanel.add(new
JLabel(I18n.getMessage("thaw.plugin.miniFrost.board.privateKey")));
+ labelPanel.add(generate = new
JButton(I18n.getMessage("thaw.plugin.miniFrost.generateKeys")));
+
+ JPanel fieldPanel = new JPanel(new GridLayout(4, 1));
+ fieldPanel.add(name = new JTextField(""));
+ fieldPanel.add(publicKey = new JTextField(""));
+ fieldPanel.add(privateKey = new JTextField(""));
+
+ JPanel buttonPanel = new JPanel(new GridLayout(1, 2));
+ buttonPanel.add(cancel = new
JButton(I18n.getMessage("thaw.common.cancel")));
+ buttonPanel.add( ok = new
JButton(I18n.getMessage("thaw.common.ok")));
+
+ dialog.getContentPane().add(labelPanel,
BorderLayout.WEST);
+ dialog.getContentPane().add(fieldPanel,
BorderLayout.CENTER);
+ dialog.getContentPane().add(buttonPanel,
BorderLayout.SOUTH);
+
+ generate.addActionListener(this);
+ ok.addActionListener(this);
+ cancel.addActionListener(this);
+
+ dialog.setSize(700, 150);
+ dialog.setVisible(true);
+ }
+
+ public void actionPerformed(ActionEvent e) {
+ if (e.getSource() == generate) {
+ FCPGenerateSSK generator = new FCPGenerateSSK();
+
+ generator.addObserver(this);
+ generator.start(core.getQueueManager());
+
+ return;
+ } else if (e.getSource() == ok) {
+ createBoard(name.getText(),
+ publicKey.getText(),
+ privateKey.getText());
+ }
+
+ synchronized(this) {
+ this.notifyAll();
+ }
+ dialog.setVisible(false);
+ }
+
+ public void update(Observable o, Object param) {
+ if (o instanceof FCPGenerateSSK) {
+ FCPGenerateSSK generator = (FCPGenerateSSK)o;
+ publicKey.setText(generator.getPublicKey());
+ privateKey.setText(generator.getPrivateKey());
+ generator.deleteObserver(this);
+ }
+ }
+ }
+
+
+ public void createBoard(thaw.core.MainWindow mainWindow) {
+ NewBoardDialog dialog = new NewBoardDialog(mainWindow);
+
+ synchronized(dialog) {
+ try {
+ dialog.wait();
+ } catch(InterruptedException e) {
+ /* \_o< */
+ }
+ }
+ }
+
+ public String toString() {
+ return I18n.getMessage("thaw.plugin.miniFrost.FrostSSK");
+ }
+}
+
Modified: trunk/apps/Thaw/src/thaw/plugins/miniFrost/interfaces/Board.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/miniFrost/interfaces/Board.java
2007-07-29 22:28:50 UTC (rev 14433)
+++ trunk/apps/Thaw/src/thaw/plugins/miniFrost/interfaces/Board.java
2007-07-30 02:32:15 UTC (rev 14434)
@@ -5,7 +5,7 @@
import javax.swing.tree.MutableTreeNode;
import java.util.Vector;
-public interface Board {
+public interface Board extends Comparable {
/**
* @return folder db id
@@ -69,7 +69,7 @@
public int getNewMessageNumber();
- public void destroy();
+ public boolean destroy();
/**
* Always return the board name,
Modified: trunk/apps/Thaw/src/thaw/plugins/signatures/Identity.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/signatures/Identity.java 2007-07-29
22:28:50 UTC (rev 14433)
+++ trunk/apps/Thaw/src/thaw/plugins/signatures/Identity.java 2007-07-30
02:32:15 UTC (rev 14434)
@@ -498,8 +498,13 @@
public boolean check(String text, String sig) {
- initFrostCrypt();
- return frostCrypt.detachedVerify(text, publicKey, sig);
+ try {
+ initFrostCrypt();
+ return frostCrypt.detachedVerify(text, publicKey, sig);
+ } catch(Exception e) {
+ Logger.notice(this, "signature check failed because:
"+e.toString());
+ return false;
+ }
}