mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-14 19:59:05 +01:00
Found the bug, it was just a SQL syntax error.
This commit is contained in:
@@ -2,7 +2,6 @@ package net.sf.briar.db;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.security.PublicKey;
|
||||
import java.sql.Blob;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
@@ -40,9 +39,9 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
private static final String CREATE_LOCAL_SUBSCRIPTIONS =
|
||||
"CREATE TABLE localSubscriptions"
|
||||
+ " (groupId HASH NOT NULL,"
|
||||
+ " name VARCHAR NOT NULL,"
|
||||
+ " salt BINARY,"
|
||||
+ " publicKey BINARY,"
|
||||
+ " groupName VARCHAR NOT NULL,"
|
||||
+ " restricted BOOLEAN NOT NULL,"
|
||||
+ " groupKey BINARY NOT NULL,"
|
||||
+ " PRIMARY KEY (groupId))";
|
||||
|
||||
private static final String CREATE_MESSAGES =
|
||||
@@ -90,9 +89,9 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
"CREATE TABLE contactSubscriptions"
|
||||
+ " (contactId INT NOT NULL,"
|
||||
+ " groupId HASH NOT NULL,"
|
||||
+ " name VARCHAR NOT NULL,"
|
||||
+ " salt BINARY,"
|
||||
+ " publicKey BINARY,"
|
||||
+ " groupName VARCHAR NOT NULL,"
|
||||
+ " restricted BOOLEAN NOT NULL,"
|
||||
+ " groupKey BINARY NOT NULL,"
|
||||
+ " PRIMARY KEY (contactId, groupId),"
|
||||
+ " FOREIGN KEY (contactId) REFERENCES contacts (contactId)"
|
||||
+ " ON DELETE CASCADE)";
|
||||
@@ -531,14 +530,14 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
PreparedStatement ps = null;
|
||||
try {
|
||||
String sql = "INSERT INTO localSubscriptions"
|
||||
+ " (groupId, name, salt, publicKey)"
|
||||
+ " (groupId, groupName, restricted, groupKey)"
|
||||
+ " VALUES (?, ?, ?, ?)";
|
||||
ps = txn.prepareStatement(sql);
|
||||
ps.setBytes(1, g.getId().getBytes());
|
||||
ps.setString(2, g.getName());
|
||||
ps.setBytes(3, g.getSalt());
|
||||
PublicKey k = g.getPublicKey();
|
||||
ps.setBytes(4, k == null ? null : k.getEncoded());
|
||||
ps.setBoolean(3, g.isRestricted());
|
||||
if(g.isRestricted()) ps.setBytes(4, g.getPublicKey().getEncoded());
|
||||
else ps.setBytes(4, g.getSalt());
|
||||
int rowsAffected = ps.executeUpdate();
|
||||
assert rowsAffected == 1;
|
||||
ps.close();
|
||||
@@ -990,7 +989,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
PreparedStatement ps = null;
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
String sql = "SELECT (groupId, name, salt, publicKey)"
|
||||
String sql = "SELECT groupId, groupName, restricted, groupKey"
|
||||
+ " FROM localSubscriptions";
|
||||
ps = txn.prepareStatement(sql);
|
||||
rs = ps.executeQuery();
|
||||
@@ -998,9 +997,9 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
while(rs.next()) {
|
||||
GroupId id = new GroupId(rs.getBytes(1));
|
||||
String name = rs.getString(2);
|
||||
byte[] salt = rs.getBytes(3);
|
||||
byte[] publicKey = rs.getBytes(4);
|
||||
subs.add(groupFactory.createGroup(id, name, salt, publicKey));
|
||||
boolean restricted = rs.getBoolean(3);
|
||||
byte[] key = rs.getBytes(4);
|
||||
subs.add(groupFactory.createGroup(id, name, restricted, key));
|
||||
}
|
||||
rs.close();
|
||||
ps.close();
|
||||
@@ -1018,7 +1017,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
PreparedStatement ps = null;
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
String sql = "SELECT (groupId, name, salt, publicKey)"
|
||||
String sql = "SELECT groupId, groupName, restricted, groupKey"
|
||||
+ " FROM contactSubscriptions"
|
||||
+ " WHERE contactId = ?";
|
||||
ps = txn.prepareStatement(sql);
|
||||
@@ -1028,9 +1027,9 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
while(rs.next()) {
|
||||
GroupId id = new GroupId(rs.getBytes(1));
|
||||
String name = rs.getString(2);
|
||||
byte[] salt = rs.getBytes(3);
|
||||
byte[] publicKey = rs.getBytes(4);
|
||||
subs.add(groupFactory.createGroup(id, name, salt, publicKey));
|
||||
boolean restricted = rs.getBoolean(3);
|
||||
byte[] key = rs.getBytes(4);
|
||||
subs.add(groupFactory.createGroup(id, name, restricted, key));
|
||||
}
|
||||
rs.close();
|
||||
ps.close();
|
||||
@@ -1390,16 +1389,17 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
ps.close();
|
||||
// Store the new subscriptions
|
||||
sql = "INSERT INTO contactSubscriptions"
|
||||
+ "(contactId, groupId, name, salt, publicKey)"
|
||||
+ "(contactId, groupId, groupName, restricted, groupKey)"
|
||||
+ " VALUES (?, ?, ?, ?, ?)";
|
||||
ps = txn.prepareStatement(sql);
|
||||
ps.setInt(1, c.getInt());
|
||||
for(Group g : subs) {
|
||||
ps.setBytes(2, g.getId().getBytes());
|
||||
ps.setString(3, g.getName());
|
||||
ps.setBytes(4, g.getSalt());
|
||||
PublicKey k = g.getPublicKey();
|
||||
ps.setBytes(5, k == null ? null : k.getEncoded());
|
||||
ps.setBoolean(4, g.isRestricted());
|
||||
if(g.isRestricted())
|
||||
ps.setBytes(5, g.getPublicKey().getEncoded());
|
||||
else ps.setBytes(5, g.getSalt());
|
||||
ps.addBatch();
|
||||
}
|
||||
int[] rowsAffectedArray = ps.executeBatch();
|
||||
|
||||
@@ -19,20 +19,15 @@ class GroupFactoryImpl implements GroupFactory {
|
||||
this.keyParser = keyParser;
|
||||
}
|
||||
|
||||
public Group createGroup(GroupId id, String name, byte[] salt,
|
||||
byte[] publicKey) {
|
||||
if(salt == null && publicKey == null)
|
||||
throw new IllegalArgumentException();
|
||||
if(salt != null && publicKey != null)
|
||||
throw new IllegalArgumentException();
|
||||
PublicKey key = null;
|
||||
if(publicKey != null) {
|
||||
public Group createGroup(GroupId id, String name, boolean restricted,
|
||||
byte[] b) {
|
||||
if(restricted) {
|
||||
try {
|
||||
key = keyParser.parsePublicKey(publicKey);
|
||||
PublicKey key = keyParser.parsePublicKey(b);
|
||||
return new GroupImpl(id, name, null, key);
|
||||
} catch (InvalidKeySpecException e) {
|
||||
throw new IllegalArgumentException(e);
|
||||
}
|
||||
}
|
||||
return new GroupImpl(id, name, salt, key);
|
||||
} else return new GroupImpl(id, name, b, null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,4 +39,14 @@ public class GroupImpl implements Group {
|
||||
public PublicKey getPublicKey() {
|
||||
return publicKey;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return o instanceof Group && id.equals(((Group) o).getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return id.hashCode();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ class MessageImpl implements Message {
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return o instanceof Message && id.equals(((Message)o).getId());
|
||||
return o instanceof Message && id.equals(((Message) o).getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user