diff --git a/app/src/main/java/lightcontainer/domains/client/Context.java b/app/src/main/java/lightcontainer/domains/client/Context.java index 089474e..31fee1a 100644 --- a/app/src/main/java/lightcontainer/domains/client/Context.java +++ b/app/src/main/java/lightcontainer/domains/client/Context.java @@ -173,7 +173,7 @@ public class Context { } public List getStringifiedFilesOf() { - return repository.load().getStringifiedFilesOf(login); + return repository.getStringifiedFilesOf(login); } public boolean canAddFile() { diff --git a/app/src/main/java/lightcontainer/protocol/ProtocolWriter.java b/app/src/main/java/lightcontainer/protocol/ProtocolWriter.java index 1d40f80..481cdd8 100644 --- a/app/src/main/java/lightcontainer/protocol/ProtocolWriter.java +++ b/app/src/main/java/lightcontainer/protocol/ProtocolWriter.java @@ -76,7 +76,7 @@ public abstract class ProtocolWriter { String command = builder + "\r\n"; Matcher ruleMatcher = this.rulePattern.matcher(command); // Vérifie que tout match (cf. Matcher). Si match alors on retourne la commande build, sinon on retourne NULL - + System.out.println("Essaye : " + command); if (ruleMatcher.matches()) { ProtocolResult result = onExecuted(context, data); result.setCommand(command); diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/FilelistRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/FilelistRule.java index a1c1da9..18bfeea 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/reader/FilelistRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/FilelistRule.java @@ -46,4 +46,9 @@ public class FilelistRule extends ProtocolReader { } return result; } + + @Override + protected T onError(Context context) { + return super.onError(context); + } } diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/SavefileRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/SavefileRule.java index 069e27f..907b1ff 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/reader/SavefileRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/SavefileRule.java @@ -59,6 +59,7 @@ public class SavefileRule extends ProtocolReader { if (getContext().canAddFile()) { try { FileReceiver fileReceiver = new FileReceiver(storagePath); + getContext().putDataString("fileName", this.filename); // Ajout login devant le nom du fichier this.filename = getContext().getLogin() + "_" + this.filename; @@ -78,7 +79,6 @@ public class SavefileRule extends ProtocolReader { String fileHash = SHA.hashFile(storagePath, this.filename); // On met les données de la requête actuelle - getContext().putDataString("fileName", filename); getContext().putDataInt("size", size); getContext().putDataString("iv", iv); getContext().putDataString("fileNameSalt", fileNameSalt); diff --git a/app/src/main/java/lightcontainer/repository/ProtocolRepositoryImpl.java b/app/src/main/java/lightcontainer/repository/ProtocolRepositoryImpl.java index 277636b..aed6995 100644 --- a/app/src/main/java/lightcontainer/repository/ProtocolRepositoryImpl.java +++ b/app/src/main/java/lightcontainer/repository/ProtocolRepositoryImpl.java @@ -31,6 +31,7 @@ public class ProtocolRepositoryImpl implements ProtocolRepository { return command; } } + System.out.println("COMMANDE NULL"); return null; } diff --git a/app/src/main/java/lightcontainer/storage/AppData.java b/app/src/main/java/lightcontainer/storage/AppData.java index 1a712b6..d0d188b 100644 --- a/app/src/main/java/lightcontainer/storage/AppData.java +++ b/app/src/main/java/lightcontainer/storage/AppData.java @@ -92,6 +92,20 @@ public class AppData { } } + /** + * Use this method when a user signs up. + * + * @return True if the user was added. False if a user with the same name already exists. + */ + public boolean addUser(User user) { + if (this.users.containsKey(user.getName())) { + return false; + } else { + this.users.put(user.getName(), user); + return true; + } + } + public boolean canAddFile(String login) { if (this.users.containsKey(login)) { return this.users.get(login).canAddFile(); @@ -178,4 +192,5 @@ public class AppData { User user = getUser(login); return user == null ? null : user.getAesKey(); } + } diff --git a/app/src/main/java/lightcontainer/storage/JsonAdapter.java b/app/src/main/java/lightcontainer/storage/JsonAdapter.java index c3a0175..026dc37 100644 --- a/app/src/main/java/lightcontainer/storage/JsonAdapter.java +++ b/app/src/main/java/lightcontainer/storage/JsonAdapter.java @@ -94,7 +94,7 @@ public class JsonAdapter implements Adapter { AppData appData = AppData.getInstance(); appData.setAppConfig(appConfig); for (User user : users) { - appData.addUser(user.getName(), user.getPassword(), user.getAesKey(), user.getPasswordSalt()); + appData.addUser(user); } return appData; } catch (JsonParseException parseException) { diff --git a/app/src/main/java/lightcontainer/storage/Repository.java b/app/src/main/java/lightcontainer/storage/Repository.java index ecbec85..81720c5 100644 --- a/app/src/main/java/lightcontainer/storage/Repository.java +++ b/app/src/main/java/lightcontainer/storage/Repository.java @@ -7,6 +7,7 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Paths; import java.nio.file.StandardOpenOption; +import java.util.List; public class Repository { @@ -139,4 +140,7 @@ public class Repository { } + public List getStringifiedFilesOf(String login) { + return this.appData.getStringifiedFilesOf(login); + } } diff --git a/app/src/main/java/lightcontainer/storage/User.java b/app/src/main/java/lightcontainer/storage/User.java index 0db77b0..13ccbb2 100644 --- a/app/src/main/java/lightcontainer/storage/User.java +++ b/app/src/main/java/lightcontainer/storage/User.java @@ -26,6 +26,7 @@ public class User { this.aesKey = aesKey; this.passwordSalt = passwordSalt; this.files = files; + System.out.println(files.size() + " fichiers trouvéssss pour " + name); } public String getName() { @@ -53,7 +54,7 @@ public class User { List result = new ArrayList<>(); while (fileIterator.hasNext()) { File file = fileIterator.next(); - String stringify = " " + file.getName() + "!" + file.getSize(); + String stringify = file.getName() + "!" + file.getSize(); result.add(stringify); } return result; diff --git a/app/src/main/resources/appdata.json b/app/src/main/resources/appdata.json index 372a838..8a76dfd 100644 --- a/app/src/main/resources/appdata.json +++ b/app/src/main/resources/appdata.json @@ -1,24 +1 @@ -{ - "unicast_port": 8000, - "multicast_ip": "226.66.66.1", - "multicast_port": 15502, - "network_interface": "My network interface", - "tls": true, - "storagePath": "D:\\ffe", - "users": [ - { - "name": "endmove", - "password": "1f82407cace28cd7d97d23f82e8235d9da97575d033a12334fc71d3517f6a90fa04af829df3c722c38d3b68842e4ca2b", - "aes_key": "p0G+iViPp656O6aMKgcXSDT/e9/00wQH/ztUWf4tyr4=", - "passwordSalt": "ItYiXkwPa84Gwb6dGHQvXQ==", - "files": [] - }, - { - "name": "aaaaa", - "password": "5d628c274ebb008324f1e199d3bfff0a3fe839730a7f2355e82850d7acca5e5ca64db9071abf3d91034295695f84a617", - "aes_key": "qlTH6TijnfMRnrS0Qf+k6IPKGp5LoRMXGxCq16e+mF4=", - "passwordSalt": "Ns8Al6DpqPsIDlCSRBVTEg==", - "files": [] - } - ] -} \ No newline at end of file +{"unicast_port":8000,"multicast_ip":"226.66.66.1","multicast_port":15502,"network_interface":"My network interface","tls":true,"storagePath":"/home/benjamin/ffe","users":[{"name":"endmove","password":"1f82407cace28cd7d97d23f82e8235d9da97575d033a12334fc71d3517f6a90fa04af829df3c722c38d3b68842e4ca2b","aes_key":"p0G+iViPp656O6aMKgcXSDT/e9/00wQH/ztUWf4tyr4=","passwordSalt":"ItYiXkwPa84Gwb6dGHQvXQ==","files":[]},{"name":"aaaaa","password":"5d628c274ebb008324f1e199d3bfff0a3fe839730a7f2355e82850d7acca5e5ca64db9071abf3d91034295695f84a617","aes_key":"qlTH6TijnfMRnrS0Qf+k6IPKGp5LoRMXGxCq16e+mF4=","passwordSalt":"Ns8Al6DpqPsIDlCSRBVTEg==","files":[{"name":"ca.crt","fileNameSalt":"Mjo7iQeEl2PYX1RDUZbSlQ==","size":4207,"iv":"uALI+Feo1lIg1lBxbCMwIQ==","storage":["lightcontainerSB01"]},{"name":"main.py","fileNameSalt":"YRwnBiXINCJ+zyxwADgNRQ==","size":854,"iv":"9LXrJFtcgU4DeUBghc4Dgw==","storage":["lightcontainerSB01"]}]}]} \ No newline at end of file