Author: jflesch
Date: 2008-02-13 00:12:37 +0000 (Wed, 13 Feb 2008)
New Revision: 17852
Added:
trunk/apps/Thaw/src/thaw/plugins/webOfTrust/DatabaseManager.java
Modified:
trunk/apps/Thaw/src/thaw/fcp/FreenetURIHelper.java
trunk/apps/Thaw/src/thaw/plugins/WebOfTrust.java
trunk/apps/Thaw/src/thaw/plugins/index/DatabaseManager.java
trunk/apps/Thaw/src/thaw/plugins/index/Index.java
trunk/apps/Thaw/src/thaw/plugins/index/IndexContainer.java
trunk/apps/Thaw/src/thaw/plugins/index/IndexManagementHelper.java
trunk/apps/Thaw/src/thaw/plugins/index/IndexParser.java
trunk/apps/Thaw/src/thaw/plugins/index/Link.java
trunk/apps/Thaw/src/thaw/plugins/index/LinkContainer.java
trunk/apps/Thaw/src/thaw/plugins/index/LinkTable.java
trunk/apps/Thaw/src/thaw/plugins/index/SearchResult.java
trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKBoardFactory.java
trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKMessage.java
trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKMessageParser.java
Log:
Index browser : categories are now attached to links
Modified: trunk/apps/Thaw/src/thaw/fcp/FreenetURIHelper.java
===================================================================
--- trunk/apps/Thaw/src/thaw/fcp/FreenetURIHelper.java 2008-02-12 23:53:06 UTC
(rev 17851)
+++ trunk/apps/Thaw/src/thaw/fcp/FreenetURIHelper.java 2008-02-13 00:12:37 UTC
(rev 17852)
@@ -648,7 +648,7 @@
return null;
if (key.startsWith("KSK@")) {
- return key;
+ return key.toLowerCase();
}
if (key.length() <= 70)
Modified: trunk/apps/Thaw/src/thaw/plugins/WebOfTrust.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/WebOfTrust.java 2008-02-12 23:53:06 UTC
(rev 17851)
+++ trunk/apps/Thaw/src/thaw/plugins/WebOfTrust.java 2008-02-13 00:12:37 UTC
(rev 17852)
@@ -183,6 +183,10 @@
return getTrustListPublicKey();
return null;
}
+
+ public void addTrustList(Identity id, String publicKey) {
+ /* TODO */
+ }
public void stop() {
used--;
Modified: trunk/apps/Thaw/src/thaw/plugins/index/DatabaseManager.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/DatabaseManager.java 2008-02-12
23:53:06 UTC (rev 17851)
+++ trunk/apps/Thaw/src/thaw/plugins/index/DatabaseManager.java 2008-02-13
00:12:37 UTC (rev 17852)
@@ -41,6 +41,7 @@
import thaw.core.Logger;
import thaw.core.SplashScreen;
import thaw.fcp.FCPQueueManager;
+import thaw.fcp.FreenetURIHelper;
import thaw.plugins.Hsqldb;
/**
@@ -87,7 +88,7 @@
if (config.getValue("indexDatabaseVersion") == null) {
newDb = true;
- config.setValue("indexDatabaseVersion", "9");
+ config.setValue("indexDatabaseVersion", "10");
} else {
/* CONVERTIONS */
@@ -150,6 +151,13 @@
if (convertDatabase_8_to_9(db))
config.setValue("indexDatabaseVersion",
"9");
}
+
+ if
("9".equals(config.getValue("indexDatabaseVersion"))) {
+ if (splashScreen != null)
+ splashScreen.setStatus("Converting
database ...");
+ if (convertDatabase_9_to_10(db))
+ config.setValue("indexDatabaseVersion",
"10");
+ }
/* ... */
}
@@ -157,8 +165,18 @@
createTables(db);
+ if (splashScreen != null)
+ splashScreen.setStatus("Cleaning up categories ...");
cleanUpCategories(db);
+ if (splashScreen != null)
+ splashScreen.setStatus("Updating link categories ...");
+ updateLinkCategories(db);
+
+ if (splashScreen != null)
+ splashScreen.setStatus("Loading index browser ...");
+
+
return newDb;
}
@@ -196,8 +214,48 @@
Logger.error(new DatabaseManager(), "Can't cleanup the
unused categories because: "+e.toString());
}
}
+
+ public static void updateLinkCategories(Hsqldb db) {
+ try {
+ synchronized(db.dbLock) {
+ PreparedStatement selectLinks;
+ PreparedStatement selectIndex;
+ PreparedStatement updateLink;
+ selectLinks =
db.getConnection().prepareStatement("SELECT id, publicKey FROM links WHERE
category IS NULL");
+ selectIndex =
db.getConnection().prepareStatement("SELECT categoryId FROM indexes wHERE
LOWER(publicKey) LIKE ? LIMIT 1");
+ updateLink =
db.getConnection().prepareStatement("UPDATE links SET category = ? WHERE id =
?");
+
+ ResultSet linksWithoutCategory =
selectLinks.executeQuery();
+
+ while(linksWithoutCategory.next()) {
+ int linkId =
linksWithoutCategory.getInt("id");
+ String linkKey =
linksWithoutCategory.getString("publicKey");
+
+ selectIndex.setString(1,
FreenetURIHelper.getComparablePart(linkKey) +"%");
+
+ ResultSet possibleCorrespondingIndex =
selectIndex.executeQuery();
+
+ if (possibleCorrespondingIndex.next()) {
+ Object o =
possibleCorrespondingIndex.getObject("categoryId");
+
+ if (o != null) {
+ int catId =
possibleCorrespondingIndex.getInt("categoryId");
+
+ updateLink.setInt(1,
catId);
+ updateLink.setInt(2,
linkId);
+ updateLink.execute();
+ }
+ }
+ }
+ }
+ } catch(SQLException e) {
+ Logger.error(new DatabaseManager(), "Can't cleanup the
unused categories because: "+e.toString());
+ }
+ }
+
+
/**
* Can be safely called, even if the tables already exist.
*/
@@ -211,7 +269,8 @@
sendQuery(db,
"CREATE CACHED TABLE categories ("
+ "id INTEGER IDENTITY NOT NULL,"
- + "name VARCHAR(255) NOT NULL)");
+ + "name VARCHAR(255) NOT NULL,"
+ + "PRIMARY KEY(id))");
sendQuery(db,
"CREATE CACHED TABLE indexFolders ("
@@ -240,7 +299,8 @@
+ "newComment BOOLEAN DEFAULT FALSE NOT NULL, "
+ "parent INTEGER NULL, " /* direct parent */
+ "PRIMARY KEY (id), "
- + "FOREIGN KEY (parent) REFERENCES indexFolders
(id))");
+ + "FOREIGN KEY (parent) REFERENCES indexFolders (id),
"
+ + "FOREIGN KEY (categoryId) REFERENCES categories
(id))");
/* direct AND indirect parents */
sendQuery(db, /* this table avoid some horrible recursivities */
@@ -286,9 +346,11 @@
+ "toDelete BOOLEAN DEFAULT false NOT NULL,"
+ "dontDelete BOOLEAN DEFAULT false NOT NULL,"
+ "blackListed BOOLEAN DEFAULT false NOT NULL,"
+ + "category INTEGER DEFAULT NULL, "
+ "PRIMARY KEY (id),"
+ "FOREIGN KEY (indexParent) REFERENCES indexes (id),"
- + "FOREIGN KEY (indexTarget) REFERENCES indexes
(id))");
+ + "FOREIGN KEY (indexTarget) REFERENCES indexes (id),"
+ + "FOREIGN KEY (category) REFERENCES categories
(id))");
sendQuery(db,
"CREATE CACHED TABLE metadataNames ("
@@ -1082,4 +1144,16 @@
return true;
}
+
+ public static boolean convertDatabase_9_to_10(Hsqldb db) {
+ if (!sendQuery(db, "ALTER TABLE links ADD COLUMN category
INTEGER DEFAULT NULL NULL")
+ || !sendQuery(db, "ALTER TABLE links ADD
FOREIGN KEY (category) REFERENCES categories (id)")) {
+
+ Logger.error(new DatabaseManager(), "Error while
converting the database (8 to 9) !");
+ return false;
+ }
+
+ return true;
+
+ }
}
Modified: trunk/apps/Thaw/src/thaw/plugins/index/Index.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/Index.java 2008-02-12 23:53:06 UTC
(rev 17851)
+++ trunk/apps/Thaw/src/thaw/plugins/index/Index.java 2008-02-13 00:12:37 UTC
(rev 17852)
@@ -1255,8 +1255,14 @@
PreparedStatement st;
- st =
db.getConnection().prepareStatement("SELECT id, publicKey, blackListed "+
- "FROM
links WHERE indexParent = ?");
+ st =
db.getConnection().prepareStatement("SELECT links.id AS id, " +
+
" links.publicKey AS publicKey, "+
+
" links.blackListed AS blacklisted," +
+
" links.indexParent AS indexParent, "+
+
" categories.name AS categoryName "+
+
" FROM links LEFT OUTER JOIN categories "+
+
" ON links.category = categories.id "+
+
"WHERE links.indexParent = ?");
st.setInt(1, id);
@@ -1264,7 +1270,7 @@
while(res.next()) {
Link l = new Link(db, res.getInt("id"),
res.getString("publicKey"),
-
res.getBoolean("blackListed"),
+
res.getString("categoryName"), res.getBoolean("blackListed"),
this);
links.add(l);
}
@@ -1296,7 +1302,7 @@
}
- public boolean addLink(String key) {
+ public boolean addLink(String key, String category) {
try {
if (key == null) /* it was the beginning of the index */
return true;
@@ -1310,12 +1316,17 @@
st =
db.getConnection().prepareStatement("INSERT INTO links "+
"(publicKey, mark, comment, "+
-
"indexParent, indexTarget, blackListed) "+
-
"VALUES (?, 0, ?, ?, NULL, ?)");
+
"indexParent, indexTarget, blackListed, category) "+
+
"VALUES (?, 0, ?, ?, NULL, ?, ?)");
st.setString(1, key);
st.setString(2, "No comment"); /* comment not
used at the moment */
st.setInt(3, id);
st.setBoolean(4, blackListed);
+
+ if (category != null)
+ st.setInt(5, getCategoryId(category));
+ else
+ st.setNull(5, Types.INTEGER);
st.execute();
@@ -1897,7 +1908,39 @@
return ("Thaw "+Main.VERSION);
}
+ /**
+ * @return -1 if none
+ */
+ public int getCategoryId() {
+ try {
+ synchronized(db.dbLock) {
+ PreparedStatement st;
+ st =
db.getConnection().prepareStatement("SELECT categoryId "+
+ "FROM
indexes "+
+ "WHERE
id = ? LIMIT 1");
+ st.setInt(1, id);
+ ResultSet set = st.executeQuery();
+
+ if (!set.next())
+ return -1;
+
+ Object o = set.getObject("categoryId");
+
+ if (o == null)
+ return -1;
+
+ return set.getInt("categoryId");
+ }
+ } catch(SQLException e) {
+ Logger.error(this,
+ "Unable to get the category of the index
because : "+
+ e.toString());
+ }
+
+ return -1;
+ }
+
public String getCategory() {
try {
synchronized(db.dbLock) {
@@ -1924,19 +1967,13 @@
return null;
}
-
- /**
- * create it if it doesn't exist
- */
- public void setCategory(String category) {
+
+ public static String cleanUpCategoryName(String category) {
if (category == null)
- return;
+ return null;
category = category.trim();
- if ("".equals(category))
- return;
-
category = category.toLowerCase();
String oldCat;
@@ -1945,7 +1982,22 @@
oldCat = category;
category = category.replaceAll("//", "/");
} while(!oldCat.equals(category));
+
+ if ("".equals(category))
+ return null;
+
+ return category;
+ }
+ /**
+ * create it if it doesn't exist
+ */
+ protected int getCategoryId(String cat) {
+ cat = cleanUpCategoryName(cat);
+
+ if (cat == null)
+ return -1;
+
try {
synchronized(db.dbLock) {
PreparedStatement st;
@@ -1955,10 +2007,11 @@
st =
db.getConnection().prepareStatement("SELECT id FROM categories "+
"WHERE
name = ? LIMIT 1");
- st.setString(1, category);
+ st.setString(1, cat);
set = st.executeQuery();
+ /* if it doesn't exist, we create it */
if (!set.next()) {
st =
db.getConnection().prepareStatement("SELECT id FROM categories "+
@@ -1971,15 +2024,45 @@
st =
db.getConnection().prepareStatement("INSERT INTO categories "+
"(id, name) VALUES (?, ?)");
st.setInt(1, catId);
- st.setString(2, category);
+ st.setString(2, cat);
st.execute();
+
+ return catId;
} else {
- catId = set.getInt("id");
+
+ /* else we return the existing id */
+ return set.getInt("id");
}
+ }
+ } catch(SQLException e) {
+ Logger.error(this, "Can't create/find the category
'"+cat+"'");
+ }
+ return -1;
+ }
+
+
+ /**
+ * create it if it doesn't exist
+ */
+ public void setCategory(String category) {
+
+ cleanUpCategoryName(category);
+
+ if (category == null || "".equals(category))
+ return;
+
+ try {
+
+ synchronized(db.dbLock) {
+ int catId = getCategoryId(category);
+
+ if (catId < 0)
+ return;
+
/* set the categoryId of the index */
- st =
db.getConnection().prepareStatement("UPDATE indexes SET categoryId = ? "+
+ PreparedStatement st =
db.getConnection().prepareStatement("UPDATE indexes SET categoryId = ? "+
"WHERE
id = ?");
st.setInt(1, catId);
st.setInt(2, id);
Modified: trunk/apps/Thaw/src/thaw/plugins/index/IndexContainer.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/IndexContainer.java 2008-02-12
23:53:06 UTC (rev 17851)
+++ trunk/apps/Thaw/src/thaw/plugins/index/IndexContainer.java 2008-02-13
00:12:37 UTC (rev 17852)
@@ -68,7 +68,7 @@
* (because of db errors or anything else)
*/
public boolean addFile(String publicKey, long size, String mime);
- public boolean addLink(String publicKey);
+ public boolean addLink(String publicKey, String category);
public void setCommentKeys(String publicKey, String privateKey);
public void addBlackListedRev(int rev);
Modified: trunk/apps/Thaw/src/thaw/plugins/index/IndexManagementHelper.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/IndexManagementHelper.java
2008-02-12 23:53:06 UTC (rev 17851)
+++ trunk/apps/Thaw/src/thaw/plugins/index/IndexManagementHelper.java
2008-02-13 00:12:37 UTC (rev 17852)
@@ -1539,9 +1539,10 @@
PreparedStatement st;
int nextId = DatabaseManager.getNextId(db,
"links");
+ int catId = target.getCategoryId();
- st =
db.getConnection().prepareStatement("INSERT INTO links (id, publicKey, mark,
comment, indexParent, indexTarget, blackListed) "+
-
"VALUES (?, ?, ?, ?, ?, ?, FALSE)");
+ st =
db.getConnection().prepareStatement("INSERT INTO links (id, publicKey, mark,
comment, indexParent, indexTarget, blackListed, category) "+
+
"VALUES (?, ?, ?, ?, ?, ?, FALSE, ?)");
st.setInt(1, nextId);
st.setString(2, linkKey);
@@ -1549,6 +1550,11 @@
st.setString(4, "" /* comment : not used at the
moment */);
st.setInt(5, target.getId());
st.setNull(6, Types.INTEGER /* indexTarget :
not used at the moment */);
+
+ if (catId >= 0)
+ st.setInt(7, catId);
+ else
+ st.setNull(7, Types.INTEGER);
st.execute();
} catch(SQLException e) {
Modified: trunk/apps/Thaw/src/thaw/plugins/index/IndexParser.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/IndexParser.java 2008-02-12
23:53:06 UTC (rev 17851)
+++ trunk/apps/Thaw/src/thaw/plugins/index/IndexParser.java 2008-02-13
00:12:37 UTC (rev 17852)
@@ -191,10 +191,14 @@
LinkContainer link = links[i];
String key =
index.findTheLatestKey(link.getPublicKey());
+ String cat = link.getCategory();
final Element xmlLink = xmlDoc.createElement("link");
xmlLink.setAttribute("key", key);
+
+ if (cat != null)
+ xmlLink.setAttribute("category", cat);
linksEl.appendChild(xmlLink);
}
@@ -355,7 +359,7 @@
} else if ("link".equals(rawName)
|| "index".equals(rawName)) { /* links */
- if (!index.addLink(attrs.getValue("key"))) {
+ if (!index.addLink(attrs.getValue("key"),
attrs.getValue("category"))) {
throw new SAXException("Index parsing
interrupted because of a backend error");
}
Modified: trunk/apps/Thaw/src/thaw/plugins/index/Link.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/Link.java 2008-02-12 23:53:06 UTC
(rev 17851)
+++ trunk/apps/Thaw/src/thaw/plugins/index/Link.java 2008-02-13 00:12:37 UTC
(rev 17852)
@@ -16,6 +16,7 @@
private final Hsqldb db;
private String publicKey;
+ private String category;
private int parentId;
private Index parent = null;
@@ -31,17 +32,18 @@
}
- public Link(final Hsqldb hsqldb, final int id, String publicKey,
boolean blackListed,
+ public Link(final Hsqldb hsqldb, final int id, String publicKey, String
category, boolean blackListed,
int parentId) {
this.id = id;
this.db = hsqldb;
this.publicKey = publicKey;
this.blackListed = blackListed;
this.parentId = parentId;
+ this.category = category;
}
- public Link(final Hsqldb hsqldb, final int id, String publicKey,
boolean blackListed,
+ public Link(final Hsqldb hsqldb, final int id, String publicKey, String
category, boolean blackListed,
Index parent) {
this.id = id;
this.db = hsqldb;
@@ -49,6 +51,7 @@
this.blackListed = blackListed;
this.parentId = parent.getId();
this.parent = parent;
+ this.category = category;
}
@@ -58,8 +61,13 @@
try {
PreparedStatement st;
- st = db.getConnection().prepareStatement("SELECT
publicKey, blackListed, indexParent FROM links "+
- "WHERE id = ?
LIMIT 1");
+ st = db.getConnection().prepareStatement("SELECT
links.publicKey AS publicKey, "+
+
" links.blackListed AS blacklisted," +
+
" links.indexParent AS indexParent, "+
+
" categories.name AS categoryName "+
+
" FROM links LEFT OUTER JOIN categories "+
+
" ON links.category = categories.id "+
+
" WHERE links.id = ? LIMIT 1");
st.setInt(1, id);
@@ -69,6 +77,7 @@
publicKey = rs.getString("publicKey");
parentId = rs.getInt("indexParent");
blackListed = rs.getBoolean("blackListed");
+ category = rs.getString("categoryName");
} else {
Logger.error(this, "Link
'"+Integer.toString(id)+"' not found.");
}
@@ -87,6 +96,13 @@
return publicKey;
}
+
+ public String getCategory() {
+ if (publicKey == null)
+ reloadDataFromDb(id);
+
+ return category;
+ }
public boolean compare(final Link l) {
String key_a;
@@ -207,7 +223,12 @@
* return the index name
*/
public String toString() {
- return getIndexName();
+ String cat = getCategory();
+
+ if (cat == null)
+ return getIndexName();
+
+ return cat+"/"+getIndexName();
}
public void setPublicKey(final String key) {
Modified: trunk/apps/Thaw/src/thaw/plugins/index/LinkContainer.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/LinkContainer.java 2008-02-12
23:53:06 UTC (rev 17851)
+++ trunk/apps/Thaw/src/thaw/plugins/index/LinkContainer.java 2008-02-13
00:12:37 UTC (rev 17852)
@@ -3,5 +3,6 @@
public interface LinkContainer {
public String getPublicKey();
+ public String getCategory();
}
Modified: trunk/apps/Thaw/src/thaw/plugins/index/LinkTable.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/LinkTable.java 2008-02-12
23:53:06 UTC (rev 17851)
+++ trunk/apps/Thaw/src/thaw/plugins/index/LinkTable.java 2008-02-13
00:12:37 UTC (rev 17852)
@@ -49,6 +49,7 @@
private Link firstSelectedLink = null;
private int firstSelectedLinkCorrespondingIndexId = -1; /* hmm .. I
should make it shorter ... */
+ private final static String unknownStr =
I18n.getMessage("thaw.common.unknown");
public LinkTable (final FCPQueueManager queueManager, IndexBrowserPanel
indexBrowser,
Config config) {
@@ -268,6 +269,7 @@
columnNames = new Vector();
columnNames.add(I18n.getMessage("thaw.plugin.index.index"));
+
columnNames.add(I18n.getMessage("thaw.plugin.index.category"));
//columnNames.add(I18n.getMessage("thaw.common.key"));
}
@@ -304,7 +306,8 @@
switch(column) {
case(0): return link.getIndexName();
- //case(1): return link.getPublicKey();
+ case(1): return (link.getCategory() != null ?
link.getCategory() : unknownStr);
+ //case(2): return link.getPublicKey();
default: return null;
}
}
Modified: trunk/apps/Thaw/src/thaw/plugins/index/SearchResult.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/SearchResult.java 2008-02-12
23:53:06 UTC (rev 17851)
+++ trunk/apps/Thaw/src/thaw/plugins/index/SearchResult.java 2008-02-13
00:12:37 UTC (rev 17852)
@@ -108,9 +108,13 @@
try {
PreparedStatement st;
- st =
db.getConnection().prepareStatement("SELECT id, publicKey, indexParent,
blackListed "+
- "FROM
links "+
- "WHERE
"+getWhereClause(false));
+ st =
db.getConnection().prepareStatement("SELECT links.publicKey AS publicKey, "+
+
" links.blackListed AS blacklisted," +
+
" links.indexParent AS indexParent, "+
+
" categories.name AS categoryName "+
+
" FROM links OUTER JOIN categories "+
+
" ON links.category = categories.id "+
+
"WHERE "+getWhereClause(false));
fillInStatement(st);
ResultSet set = st.executeQuery();
@@ -119,6 +123,7 @@
v.add(new Link(db,
set.getInt("id"),
set.getString("publicKey"),
+
set.getString("categoryName"),
false,
set.getInt("indexParent") ));
}
Modified:
trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKBoardFactory.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKBoardFactory.java
2008-02-12 23:53:06 UTC (rev 17851)
+++ trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKBoardFactory.java
2008-02-13 00:12:37 UTC (rev 17852)
@@ -267,13 +267,15 @@
sendQuery("CREATE CACHED TABLE frostKSKBoards ("
+ "id INTEGER IDENTITY NOT NULL, "
+ "name VARCHAR(128) NOT NULL, "
- + "lastUpdate DATE DEFAULT NULL NULL)");
+ + "lastUpdate DATE DEFAULT NULL NULL, "
+ + "PRIMARY KEY(id))");
sendQuery("CREATE CACHED TABLE frostSSKBoards ("
+ "id INTEGER IDENTITY NOT NULL, "
+ "publicKey VARCHAR(256) NOT NULL, "
+ "privateKey VARCHAR(256) NULL, "
+ "kskBoardId INTEGER NOT NULL, "
+ + "PRIMARY KEY(id), "
+ "FOREIGN KEY (kskBoardId) REFERENCES frostKSKBoards
(id))");
sendQuery("CREATE CACHED TABLE frostKSKInvalidSlots ("
@@ -282,6 +284,7 @@
+ "date DATE NOT NULL, "
+ "minRev INTEGER NOT NULL, "
+ "maxRev INTEGER NOT NULL, "
+ + "PRIMARY KEY(id), "
+ "FOREIGN KEY (boardId) REFERENCES
frostKSKBoards (id))");
sendQuery("CREATE CACHED TABLE frostKSKMessages ("
@@ -300,6 +303,7 @@
+ "archived BOOLEAN DEFAULT FALSE NOT NULL, "
+ "encryptedFor INTEGER DEFAULT NULL NULL, "
+ "boardId INTEGER NOT NULL, "
+ + "PRIMARY KEY(id), "
+ "FOREIGN KEY (boardId) REFERENCES frostKSKBoards
(id), "
+ "FOREIGN KEY (inReplyTo) REFERENCES
frostKSKMessages (id), "
+ "FOREIGN KEY (sigId) REFERENCES signatures (id), "
@@ -311,6 +315,7 @@
+ "size BIGINT NOT NULL, "
+ "key VARCHAR(512) NOT NULL, "
+ "messageId INTEGER NOT NULL, "
+ + "PRIMARY KEY(id), "
+ "FOREIGN KEY (messageId) REFERENCES
frostKSKMessages (id))");
sendQuery("CREATE CACHED TABLE frostKSKAttachmentBoards ("
@@ -320,6 +325,7 @@
+ "privateKey VARCHAR(256) NULL, "
+ "description VARCHAR(512) NULL, "
+ "messageId INTEGER NOT NULL, "
+ + "PRIMARY KEY(id), "
+ "FOREIGN KEY (messageId) REFERENCES
frostKSKMessages (id))");
if (core.getConfig().getValue("frostKSKDatabaseVersion") ==
null)
Modified: trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKMessage.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKMessage.java
2008-02-12 23:53:06 UTC (rev 17851)
+++ trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKMessage.java
2008-02-13 00:12:37 UTC (rev 17852)
@@ -154,6 +154,10 @@
&&
parser.filter(board.getFactory().getPlugin().getRegexpBlacklist())
&& parser.insert(db, board.getId(),
date, rev, board.getName())) {
+
+ if (parser.getTrustListPublicKey() != null) {
+
board.getFactory().getWoT().addTrustList(parser.getIdentity(),
parser.getTrustListPublicKey());
+ }
new File(get.getPath()).delete();
Modified:
trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKMessageParser.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKMessageParser.java
2008-02-12 23:53:06 UTC (rev 17851)
+++ trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKMessageParser.java
2008-02-13 00:12:37 UTC (rev 17852)
@@ -134,12 +134,28 @@
if (identity == null || wotPublicKey == null)
return null;
- String toSign = wotPublicKey+"|"+date+"|"+time+"|"+messageId;
+ String toSign = wotPublicKey+"|"+date+"|"+time+"|"+messageId;
/* no 'GMT' at the end of the time string because I'm a lazy bastard */
return identity.sign(toSign);
}
+
+ private boolean checkWotPublicKeySignature(Identity identity, String
wotPublicKey, String signature) {
+ if (identity == null || wotPublicKey == null || signature ==
null)
+ return false;
+
+ String toSign = wotPublicKey+"|"+date+"|"+time+"|"+messageId;
/* no 'GMT' at the end of the time string because I'm a lazy bastard */
+ return identity.check(toSign, signature);
+ }
+
+ public Identity getIdentity() {
+ return identity;
+ }
+ public String getTrustListPublicKey() {
+ return wotPublicKey;
+ }
+
private boolean alreadyInTheDb(Hsqldb db, String msgId) {
try {
@@ -418,8 +434,17 @@
if (!ret) {
Logger.notice(this, "Invalid signature !");
+ wotPublicKeySignature = null;
+ wotPublicKey = null;
return invalidMessage("Invalid signature");
}
+
+ if (wotPublicKey != null) {
+ if (!checkWotPublicKeySignature(identity, wotPublicKey,
wotPublicKeySignature)) {
+ wotPublicKeySignature = null;
+ wotPublicKey = null;
+ }
+ }
return true;
}
@@ -444,6 +469,8 @@
publicKey = XMLTools.getChildElementsCDATAValue(root,
"pubKey");
idLinePos = XMLTools.getChildElementsTextValue(root,
"IdLinePos");
idLineLen = XMLTools.getChildElementsTextValue(root,
"IdLineLen");
+ wotPublicKey = XMLTools.getChildElementsTextValue(root,
"trustListPublicKey");
+ wotPublicKeySignature =
XMLTools.getChildElementsTextValue(root, "trustListPublicKeySignature");
List l = XMLTools.getChildElementsByTagName(root,
"AttachmentList");
if (l.size() == 1) {
Added: trunk/apps/Thaw/src/thaw/plugins/webOfTrust/DatabaseManager.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/webOfTrust/DatabaseManager.java
(rev 0)
+++ trunk/apps/Thaw/src/thaw/plugins/webOfTrust/DatabaseManager.java
2008-02-13 00:12:37 UTC (rev 17852)
@@ -0,0 +1,66 @@
+package thaw.plugins.webOfTrust;
+
+import thaw.core.Config;
+import thaw.core.SplashScreen;
+import thaw.core.Logger;
+import thaw.plugins.Hsqldb;
+
+import java.sql.*;
+
+public class DatabaseManager {
+ /**
+ * @splashScreen can be null
+ * @return true if database is a new one
+ */
+ public static boolean init(Hsqldb db, Config config, SplashScreen
splashScreen) {
+ boolean newDb;
+
+ newDb = false;
+
+ if (config.getValue("wotDatabaseVersion") == null) {
+ newDb = true;
+ config.setValue("wotDatabaseVersion", "0");
+ } else {
+ /* ... */
+ }
+
+ createTables(db);
+
+ return newDb;
+ }
+
+ public static void createTables(Hsqldb db) {
+ /*sendQuery(db,
+ "CREATE CACHED TABLE indexFolders ("
+ + "id INTEGER IDENTITY NOT NULL,"
+ + "name VARCHAR(255) NOT NULL,"
+ + "positionInTree INTEGER NOT NULL,"
+ + "modifiableIndexes BOOLEAN NOT NULL,"
+ + "parent INTEGER NULL,"
+ + "PRIMARY KEY (id),"
+ + "FOREIGN KEY (parent) REFERENCES
indexFolders (id))");
+ */
+
+ sendQuery(db, "CREATE CACHED TABLE wot ("
+ + "id INTEGER IDENTITY NOT NULL, "
+ + "publicKey VARCHAR(400) NOT NULL, "
+ + "score SMALLINT NOT NULL, "
+ + "sigId INTEGER NOT NULL, "
+ + "PRIMARY KEY(id), "
+ + "FOREIGN KEY(sigId) REFERENCES signatures
(id))");
+ }
+
+ /**
+ * Returns no error / Throws no exception.
+ * @return false if an exception happened
+ */
+ protected static boolean sendQuery(final Hsqldb db, final String query)
{
+ try {
+ db.executeQuery(query);
+ return true;
+ } catch(final SQLException e) {
+ Logger.notice(new DatabaseManager(), "While
(re)creating sql tables: "+e.toString());
+ return false;
+ }
+ }
+}