diff --git a/app/src/main/java/lightcontainer/protocol/StandardizedDefinitions.java b/app/src/main/java/lightcontainer/protocol/StandardizedDefinitions.java index 5848f78..3e0d120 100644 --- a/app/src/main/java/lightcontainer/protocol/StandardizedDefinitions.java +++ b/app/src/main/java/lightcontainer/protocol/StandardizedDefinitions.java @@ -18,7 +18,7 @@ public class StandardizedDefinitions { private final static String DOMAIN = "[a-z-A-Z0-9\\.]{5,20}"; private final static String HASH_FILENAME = DIGIT_LETTER + "{50,200}"; private final static String HASH_FILECONTENT = DIGIT_LETTER + "{50,200}"; - private final static String FILE_INFO = HASH_FILENAME + BL + SIZE + BL + HASH_FILECONTENT; + private final static String FILE_INFO = "(" + HASH_FILENAME + ")" + BL + "(" + SIZE + ")" + BL + "(" + HASH_FILECONTENT + ")"; private final static String LOGIN = DIGIT_LETTER + "{5,20}"; //Regex à utiliser dans les différents protocoles. @@ -33,7 +33,7 @@ public class StandardizedDefinitions { public final static String SBE_ERASE_RESULT_OK = "^ERASE_OK" + LINE + "$"; public final static String SBE_ERASE_RESULT_ERROR = "^ERASE_ERROR" + LINE + "$"; public final static String FFE_RETRIEVE_FILE = "^RETRIEVEFILE" + BL + HASH_FILENAME + LINE + "$"; - public final static String SBE_RETRIEVE_RESULT_OK = "^RETRIEVE_OK" + BL + "(" + FILE_INFO + ")" + LINE + "$"; + public final static String SBE_RETRIEVE_RESULT_OK = "^RETRIEVE_OK" + BL + FILE_INFO + LINE + "$"; public final static String SBE_RETRIEVE_RESULT_ERROR = "^RETRIEVE_ERROR" + LINE + "$"; //Client demande à FFE une tâche. FFE répond à client. diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/EraseErrorRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/EraseErrorRule.java index 1ce0b0b..e9dd3b2 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/reader/EraseErrorRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/EraseErrorRule.java @@ -5,9 +5,11 @@ import lightcontainer.interfaces.ProtocolRepository; import lightcontainer.protocol.ProtocolReader; import lightcontainer.protocol.rules.writer.RemoveFileErrorRule; +import static lightcontainer.protocol.StandardizedDefinitions.SBE_ERASE_RESULT_ERROR; + public class EraseErrorRule extends ProtocolReader { - private static final String PATTERN = "^ERASE_ERROR\r\n$"; + private static final String PATTERN = SBE_ERASE_RESULT_ERROR; private static final String NAME = "ERASE_ERROR"; diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/EraseOkRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/EraseOkRule.java index 9125c7a..04c9ab7 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/reader/EraseOkRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/EraseOkRule.java @@ -5,9 +5,11 @@ import lightcontainer.interfaces.ProtocolRepository; import lightcontainer.protocol.ProtocolReader; import lightcontainer.protocol.rules.writer.RemoveFileOkRule; +import static lightcontainer.protocol.StandardizedDefinitions.SBE_ERASE_RESULT_OK; + public class EraseOkRule extends ProtocolReader { - private static final String PATTERN = "^ERASE_OK\r\n$"; + private static final String PATTERN = SBE_ERASE_RESULT_OK; private static final String NAME = "ERASE_OK"; 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 18bfeea..2974746 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/reader/FilelistRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/FilelistRule.java @@ -7,12 +7,14 @@ import lightcontainer.protocol.rules.writer.FilesRule; import java.util.List; +import static lightcontainer.protocol.StandardizedDefinitions.CLIENT_FILE_LIST; + /** * Règle permettant de récupérer la liste des fichiers d'un utilisateur */ public class FilelistRule extends ProtocolReader { // Constants - private static final String PATTERN = "^FILELIST\r\n$"; + private static final String PATTERN = CLIENT_FILE_LIST; private static final String NAME = "FILELIST"; diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/GetFileRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/GetFileRule.java index a667672..1f75281 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/reader/GetFileRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/GetFileRule.java @@ -4,15 +4,16 @@ import lightcontainer.domains.client.Context; import lightcontainer.interfaces.ProtocolRepository; import lightcontainer.protocol.ProtocolReader; import lightcontainer.protocol.rules.writer.GetFileErrorRule; -import lightcontainer.protocol.rules.writer.RemoveFileErrorRule; import lightcontainer.protocol.rules.writer.RetrieveFileRule; import lightcontainer.storage.ReadOnlyFile; import java.util.Iterator; +import static lightcontainer.protocol.StandardizedDefinitions.CLIENT_GET_FILE; + public class GetFileRule extends ProtocolReader { // Constants - private static final String PATTERN = "^GETFILE ([^ !]{1,20})\r\n$"; + private static final String PATTERN = CLIENT_GET_FILE; private static final String NAME = "GETFILE"; // -- arguments private static final int FILE_NAME = 0; // Index file name. @@ -80,9 +81,11 @@ public class GetFileRule extends ProtocolReader { return result; } - /** TMP + /** + * TMP * TODO : But futur est de pouvoir en avoir plusieurs (sbe) * Cette méthode permet de choisir le domaine voulu. + * * @param storageIterator Les domaines * @return Le domain choisi */ diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/HelloRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/HelloRule.java index b2b797d..9fa53a1 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/reader/HelloRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/HelloRule.java @@ -3,14 +3,16 @@ package lightcontainer.protocol.rules.reader; import lightcontainer.domains.client.Context; import lightcontainer.protocol.ProtocolReader; +import static lightcontainer.protocol.StandardizedDefinitions.SBE_HELLO; + /** * Règle permettant d'être alerter de l'annoncement d'un SBE */ public class HelloRule extends ProtocolReader { - private static final String PATTERN = "^HELLO ([A-Za-z0-9]{5,20}) ([0-9]{1,5})\r\n$"; + private static final String PATTERN = SBE_HELLO; - private static final String NAME = "HELLO"; + private static final String NAME = "HELLO"; // Index du domain dans le tableau de donnée private static final int DOMAIN = 0; diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/RemoveFileRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/RemoveFileRule.java index 7024478..efe5768 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/reader/RemoveFileRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/RemoveFileRule.java @@ -9,9 +9,11 @@ import lightcontainer.storage.ReadOnlyFile; import java.util.Iterator; +import static lightcontainer.protocol.StandardizedDefinitions.CLIENT_REMOVE_FILE; + public class RemoveFileRule extends ProtocolReader { - private static final String PATTERN = "^REMOVEFILE ([^ !]{1,20})\r\n$"; + private static final String PATTERN = CLIENT_REMOVE_FILE; private static final String NAME = "REMOVEFILE"; diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/RetrieveErrorRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/RetrieveErrorRule.java index 9bb8339..6b3a425 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/reader/RetrieveErrorRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/RetrieveErrorRule.java @@ -5,9 +5,11 @@ import lightcontainer.interfaces.ProtocolRepository; import lightcontainer.protocol.ProtocolReader; import lightcontainer.protocol.rules.writer.GetFileErrorRule; +import static lightcontainer.protocol.StandardizedDefinitions.SBE_RETRIEVE_RESULT_ERROR; + public class RetrieveErrorRule extends ProtocolReader { // Constants - private static final String PATTERN = "^RETRIEVE_ERROR\r\n$"; + private static final String PATTERN = SBE_RETRIEVE_RESULT_ERROR; private static final String NAME = "RETRIEVE_ERROR"; // Variables diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/RetrieveOkRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/RetrieveOkRule.java index 412681e..af326ab 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/reader/RetrieveOkRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/RetrieveOkRule.java @@ -6,13 +6,14 @@ import lightcontainer.protocol.ProtocolReader; import lightcontainer.protocol.rules.writer.GetFileOkRule; import lightcontainer.protocol.rules.writer.SaveFileErrorRule; import lightcontainer.utils.FileReceiver; -import lightcontainer.utils.FileSender; import java.io.InputStream; +import static lightcontainer.protocol.StandardizedDefinitions.SBE_RETRIEVE_RESULT_OK; + public class RetrieveOkRule extends ProtocolReader { // Constants - private static final String PATTERN = "^RETRIEVE_OK ([A-Za-z0-9.]{50,200}) ([0-9]{1,10}) ([A-Za-z0-9.]{50,200})\r\n$"; + private static final String PATTERN = SBE_RETRIEVE_RESULT_OK; private static final String NAME = "RETRIEVE_OK"; // -- arguments private static final int HASHED_FILE_NAME = 0; // Index hashed filename @@ -45,6 +46,7 @@ public class RetrieveOkRule extends ProtocolReader { /** * Bitch has bettern than my money + * * @param reader Buffer rempli du fichier */ @Override diff --git a/app/src/main/resources/appdata.json b/app/src/main/resources/appdata.json index 2baebe3..f473592 100644 --- a/app/src/main/resources/appdata.json +++ b/app/src/main/resources/appdata.json @@ -1 +1 @@ -{"unicast_port":8000,"multicast_ip":"224.66.66.1","multicast_port":15502,"network_interface":"","tls":true,"storagePath":"/home/benjamin/ffe","users":[{"name":"aaaaa","password":"$2a$10$nDCEDVwbNO/YDQ4qdRcxfuES4.aboluLzWouXXsk6vDoaWocv516W","aes_key":"kYtwHy9qJBg30WS6axWTFGVE0Ge5kpYiJJlC+COIEI4=","files":[]}]} \ No newline at end of file +{"unicast_port":8000,"multicast_ip":"224.66.66.1","multicast_port":15502,"network_interface":"Wi-Fi","tls":true,"storagePath":"C:\\Users\\ledou\\Documents\\ffe","users":[{"name":"aaaaa","password":"$2a$10$pUtcOXsQvLWYq1TJHTT8peb7ev/0YJFhrGUpj39InIstnSq1QcFGy","aes_key":"msCPN6nRJ9brhfLAZqmVuBkddtLH2ub1oEnlh73sEw8=","files":[{"name":"Reoutage.txt","fileNameSalt":"HX9Rd6VQgAzACtDHJ7S1aQ==","size":168,"iv":"unBbaL17c4pSaVi315RKaw==","storage":["orglightcont01"]}]}]} \ No newline at end of file