From 56d3468df81f89947360e953b151e4532d7a74d5 Mon Sep 17 00:00:00 2001 From: Maximilien LEDOUX Date: Tue, 22 Feb 2022 09:30:33 +0100 Subject: [PATCH 1/8] Regex : Client to FileFrontEnd --- .../lightcontainer/protocol/Protocol.java | 70 ++++++++----------- .../lightcontainer/protocol/SbeHello.java | 16 +++++ app/src/main/resources/rules.txt | 18 ++++- 3 files changed, 63 insertions(+), 41 deletions(-) create mode 100644 app/src/main/java/lightcontainer/protocol/SbeHello.java diff --git a/app/src/main/java/lightcontainer/protocol/Protocol.java b/app/src/main/java/lightcontainer/protocol/Protocol.java index e7449f3..07bb621 100644 --- a/app/src/main/java/lightcontainer/protocol/Protocol.java +++ b/app/src/main/java/lightcontainer/protocol/Protocol.java @@ -7,15 +7,14 @@ import java.util.regex.Pattern; /** * Protocol - * + *

* Class allowing to define new rules for the LightContainer protocol, * also provides utility functions to work with regexes and the command to compare. * - * @version 1.0 - * @since 1.0 - * - * @see Pattern - * @author Jérémi NIHART + * @author Jérémi NIHART + * @version 1.0 + * @see Pattern + * @since 1.0 */ public abstract class Protocol { // Variables @@ -25,9 +24,10 @@ public abstract class Protocol { /** * Protocol constructor - * @param rule Command (e.g: LOGIN). - * @param regex Regex to compile and use for this command (e.g: LOGIN ([A-Z0-9a-z]{1,20})). - * Do not forget to define the groups in the regex. + * + * @param rule Command (e.g: LOGIN). + * @param regex Regex to compile and use for this command (e.g: LOGIN ([A-Z0-9a-z]{1,20})). + * Do not forget to define the groups in the regex. */ protected Protocol(String rule, String regex) { this.rule = rule; @@ -37,9 +37,8 @@ public abstract class Protocol { /** * Retrieve, the name of the Rule. * - * @return Name of this rule. - * - * @since 1.0 + * @return Name of this rule. + * @since 1.0 */ public String getRule() { return this.rule; @@ -48,17 +47,16 @@ public abstract class Protocol { /** * Check if a command matches the rule with the rule matcher. * - * @return True : if the command match with the rule. - * False though. - * @param cmd Command to verify with the rule matcher. - * - * @since 1.0 + * @param cmd Command to verify with the rule matcher. + * @return True : if the command match with the rule. + * False though. + * @since 1.0 */ protected boolean matcherCheck(String cmd) { Matcher ruleMatcher = this.rulePattern.matcher(cmd); if (ruleMatcher.matches()) { this.groups = new ArrayList<>(); - for (int i=1; i <= ruleMatcher.groupCount(); i++) this.groups.add(ruleMatcher.group(i)); + for (int i = 1; i <= ruleMatcher.groupCount(); i++) this.groups.add(ruleMatcher.group(i)); return true; } return false; @@ -66,14 +64,12 @@ public abstract class Protocol { /** * Get a list of all the groups extracted from the previously matched command with {@link #matcherCheck(String)}. - * + * * Requires to have run {@link #matcherCheck(String)} * - * @return String list containing all the groups extrapolated from the command. - * - * @since 1.0 - * - * @see Protocol#matcherCheck(String) + * @return String list containing all the groups extrapolated from the command. + * @see Protocol#matcherCheck(String) + * @since 1.0 */ protected List matcherGetGroups() { return this.groups; @@ -81,26 +77,23 @@ public abstract class Protocol { /** * Execute the rule on a command. - * + *

* This function allows you to check a command and process those groups (parameters) * use the utility functions of {@link Protocol} to facilitate processing, see @see. * - * @param cmd Command on which to execute the rule. - * - * @since 1.0 - * - * @see Protocol#execute(String) - * @see #matcherCheck(String) - * @see #matcherGetGroups() + * @param cmd Command on which to execute the rule. + * @see Protocol#execute(String) + * @see #matcherCheck(String) + * @see #matcherGetGroups() + * @since 1.0 */ public abstract void execute(String cmd); /** * Retrieve, the hashcode of the rule. * - * @return Rule hashcode. - * - * @since 1.0 + * @return Rule hashcode. + * @since 1.0 */ @Override public int hashCode() { @@ -110,10 +103,9 @@ public abstract class Protocol { /** * Compare the equality of two rules. * - * @return True : if the rules are equals - * False if not. - * - * @since 1.0 + * @return True : if the rules are equals + * False if not. + * @since 1.0 */ @Override public boolean equals(final Object obj) { diff --git a/app/src/main/java/lightcontainer/protocol/SbeHello.java b/app/src/main/java/lightcontainer/protocol/SbeHello.java new file mode 100644 index 0000000..af30e5b --- /dev/null +++ b/app/src/main/java/lightcontainer/protocol/SbeHello.java @@ -0,0 +1,16 @@ +package lightcontainer.protocol; + +public class SbeHello extends Protocol { + + + protected SbeHello() { + super("HELLO", "^(HELLO)\\s([A-Za-z0-9.]{5,20})\\s((6553[0-5])|(655[0-2][0-9])|(65[0-4][0-9]{2})|(6[0-4][0-9]{3})|([0-5][0-9]{4})|([0-9]{1,4}))\\r\\n$"); + } + + @Override + public void execute(String cmd) { + if (matcherCheck(cmd)) { + + } + } +} diff --git a/app/src/main/resources/rules.txt b/app/src/main/resources/rules.txt index 2cfa297..511bc2b 100644 --- a/app/src/main/resources/rules.txt +++ b/app/src/main/resources/rules.txt @@ -21,9 +21,23 @@ login = [A-Za-z0-9]{2,20} sbe_hello = ^(HELLO)\s([A-Za-z0-9.]{5,20})\s((6553[0-5])|(655[0-2][0-9])|(65[0-4][0-9]{2})|(6[0-4][0-9]{3})|([0-5][0-9]{4})|([0-9]{1,4}))\r\n$ //TODO \r\n -> à tester pour voir si déjà dans le flux ou doit être construit //FileFrontEnd to StorBackEnd -ffe_sendfile = ^(SENDFILE)\s([A-Za-z0-9.]{50,200}\s[0-9]{1,10}\s[A-Za-z0-9.]{50,200})\r\n(.*)$ +ffe_sendfile = ^(SENDFILE)\s([A-Za-z0-9.]{50,200}\s[0-9]{1,10}\s[A-Za-z0-9.]{50,200})\r\n$ sbe_sendresult = ^(SEND_OK|SEND_ERROR)\r\n$ ffe_erasefile = ^(ERASEFILE)\s([A-Za-z0-9.]{50,200})\r\n$ sbe_eraseresult = ^(ERASE_OK|ERASE_ERROR)\r\n$ ffe_retrievefile = ^(RETRIEVEFILE)\s([A-Za-z0-9.]{50,200})\r\n$ -sbe_retrieveresult = ^(RETRIEVE_OK)\s([A-Za-z0-9.]{50,200}\s[0-9]{1,10}\s[A-Za-z0-9.]{50,200})\r\n(.*)|(RETRIEVE_ERROR)$ \ No newline at end of file +sbe_retrieveresult = ^((RETRIEVE_OK)\s([A-Za-z0-9.]{50,200}\s[0-9]{1,10}\s[A-Za-z0-9.]{50,200})\r\n)|((RETRIEVE_ERROR)\r\n)$ + +//Client to FileFrontEnd +client_signin = ^(SIGNIN)\s([A-Za-z0-9]{2,20})\s([^\s!]{5,50})\r\n$ +client_signup = ^(SIGNUP)\s([A-Za-z0-9]{2,20})\s([^\s!]{5,50})\r\n$ +ffe_signresult = ^(SIGN_OK|SIGN_ERROR)\r\n$ +client_filelist = ^(FILELIST)\r\n$ +ffe_filelistresult = ^(FILES)\s(([^\s!]{1,20}![0-9]{1,10}){0,50})\r\n$ +client_savefile = ^(SAVE_FILE)\s([^\s!]{1,20})\s([0-9]{1,10})\r\n$ +ffe_savefileresult = ^(SAVEFILE_OK|SAVEFILE_ERROR)\r\n$ +client_getfile = ^(GETFILE)\s([^\s!]{1,20})\r\n$ +ffe_getfileresult = ^((GETFILE_OK)\s(^\s!]{1,20})\s([0-9]{1,10})\r\n)|((GETFILE_ERROR)\r\n)$ +client_removefile = ^(REMOVEFILE)\s([^\s!]{1,20})\r\n$ +ffe_removefileresult = ^(REMOVEFILE_OK|REMOVEFILE_ERROR)\r\n$ +client_signout = ^(SIGNOUT)\r\n$ \ No newline at end of file From ec8a58044d02abb39ab3aac6d77547c18f9fba72 Mon Sep 17 00:00:00 2001 From: Maximilien LEDOUX Date: Tue, 22 Feb 2022 11:13:46 +0100 Subject: [PATCH 2/8] =?UTF-8?q?Regex=20:=20Client=20to=20FileFrontEnd=20im?= =?UTF-8?q?pl=C3=A9mentation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../protocol/ClientFileList.java | 12 ++++++ .../protocol/ClientGetFile.java | 12 ++++++ .../protocol/ClientRemoveFile.java | 13 +++++++ .../protocol/ClientSaveFile.java | 12 ++++++ .../lightcontainer/protocol/ClientSignIn.java | 13 +++++++ .../protocol/ClientSignOut.java | 12 ++++++ .../lightcontainer/protocol/ClientSignUp.java | 12 ++++++ .../protocol/SbeEraseResult.java | 12 ++++++ .../lightcontainer/protocol/SbeHello.java | 2 +- .../protocol/SbeRetrieveResult.java | 12 ++++++ .../protocol/SbeSendResult.java | 13 +++++++ app/src/main/resources/rules.txt | 38 +++++++++---------- 12 files changed, 143 insertions(+), 20 deletions(-) create mode 100644 app/src/main/java/lightcontainer/protocol/ClientFileList.java create mode 100644 app/src/main/java/lightcontainer/protocol/ClientGetFile.java create mode 100644 app/src/main/java/lightcontainer/protocol/ClientRemoveFile.java create mode 100644 app/src/main/java/lightcontainer/protocol/ClientSaveFile.java create mode 100644 app/src/main/java/lightcontainer/protocol/ClientSignIn.java create mode 100644 app/src/main/java/lightcontainer/protocol/ClientSignOut.java create mode 100644 app/src/main/java/lightcontainer/protocol/ClientSignUp.java create mode 100644 app/src/main/java/lightcontainer/protocol/SbeEraseResult.java create mode 100644 app/src/main/java/lightcontainer/protocol/SbeRetrieveResult.java create mode 100644 app/src/main/java/lightcontainer/protocol/SbeSendResult.java diff --git a/app/src/main/java/lightcontainer/protocol/ClientFileList.java b/app/src/main/java/lightcontainer/protocol/ClientFileList.java new file mode 100644 index 0000000..c88f72f --- /dev/null +++ b/app/src/main/java/lightcontainer/protocol/ClientFileList.java @@ -0,0 +1,12 @@ +package lightcontainer.protocol; + +public class ClientFileList extends Protocol{ + protected ClientFileList() { + super("FILELIST", "^FILELIST\r\n$"); + } + + @Override + public void execute(String cmd) { + + } +} diff --git a/app/src/main/java/lightcontainer/protocol/ClientGetFile.java b/app/src/main/java/lightcontainer/protocol/ClientGetFile.java new file mode 100644 index 0000000..4b0fa24 --- /dev/null +++ b/app/src/main/java/lightcontainer/protocol/ClientGetFile.java @@ -0,0 +1,12 @@ +package lightcontainer.protocol; + +public class ClientGetFile extends Protocol{ + protected ClientGetFile() { + super("GETFILE","^GETFILE ([^ !]{1,20})\r\n$"); + } + + @Override + public void execute(String cmd) { + + } +} diff --git a/app/src/main/java/lightcontainer/protocol/ClientRemoveFile.java b/app/src/main/java/lightcontainer/protocol/ClientRemoveFile.java new file mode 100644 index 0000000..dd5375b --- /dev/null +++ b/app/src/main/java/lightcontainer/protocol/ClientRemoveFile.java @@ -0,0 +1,13 @@ +package lightcontainer.protocol; + +public class ClientRemoveFile extends Protocol{ + + protected ClientRemoveFile() { + super("REMOVEFILE", "^REMOVEFILE ([^ !]{1,20})\r\n$"); + } + + @Override + public void execute(String cmd) { + + } +} diff --git a/app/src/main/java/lightcontainer/protocol/ClientSaveFile.java b/app/src/main/java/lightcontainer/protocol/ClientSaveFile.java new file mode 100644 index 0000000..a3b7b11 --- /dev/null +++ b/app/src/main/java/lightcontainer/protocol/ClientSaveFile.java @@ -0,0 +1,12 @@ +package lightcontainer.protocol; + +public class ClientSaveFile extends Protocol { + protected ClientSaveFile() { + super("SAVEFILE", "^SAVE_FILE ([^ !]{1,20}) ([0-9]{1,10})\r\n$"); + } + + @Override + public void execute(String cmd) { + + } +} diff --git a/app/src/main/java/lightcontainer/protocol/ClientSignIn.java b/app/src/main/java/lightcontainer/protocol/ClientSignIn.java new file mode 100644 index 0000000..43edf56 --- /dev/null +++ b/app/src/main/java/lightcontainer/protocol/ClientSignIn.java @@ -0,0 +1,13 @@ +package lightcontainer.protocol; + +public class ClientSignIn extends Protocol { + + protected ClientSignIn() { + super("SIGNIN", "^(SIGNIN) ([A-Za-z0-9]{2,20}) ([^ !]{5,50})\r\n$"); + } + + @Override + public void execute(String cmd) { + + } +} diff --git a/app/src/main/java/lightcontainer/protocol/ClientSignOut.java b/app/src/main/java/lightcontainer/protocol/ClientSignOut.java new file mode 100644 index 0000000..909b047 --- /dev/null +++ b/app/src/main/java/lightcontainer/protocol/ClientSignOut.java @@ -0,0 +1,12 @@ +package lightcontainer.protocol; + +public class ClientSignOut extends Protocol { + protected ClientSignOut() { + super("SIGNOUT", "^SIGNOUT\r\n$"); + } + + @Override + public void execute(String cmd) { + + } +} diff --git a/app/src/main/java/lightcontainer/protocol/ClientSignUp.java b/app/src/main/java/lightcontainer/protocol/ClientSignUp.java new file mode 100644 index 0000000..91c67d3 --- /dev/null +++ b/app/src/main/java/lightcontainer/protocol/ClientSignUp.java @@ -0,0 +1,12 @@ +package lightcontainer.protocol; + +public class ClientSignUp extends Protocol{ + protected ClientSignUp() { + super("SIGNUP","^(SIGNUP) ([A-Za-z0-9]{2,20}) ([^ !]{5,50})\r\n$"); + } + + @Override + public void execute(String cmd) { + + } +} diff --git a/app/src/main/java/lightcontainer/protocol/SbeEraseResult.java b/app/src/main/java/lightcontainer/protocol/SbeEraseResult.java new file mode 100644 index 0000000..301edd8 --- /dev/null +++ b/app/src/main/java/lightcontainer/protocol/SbeEraseResult.java @@ -0,0 +1,12 @@ +package lightcontainer.protocol; + +public class SbeEraseResult extends Protocol { + protected SbeEraseResult() { + super("ERASERESULT", "^(ERASE_OK|ERASE_ERROR)\r\n$"); + } + + @Override + public void execute(String cmd) { + + } +} diff --git a/app/src/main/java/lightcontainer/protocol/SbeHello.java b/app/src/main/java/lightcontainer/protocol/SbeHello.java index af30e5b..6cd750a 100644 --- a/app/src/main/java/lightcontainer/protocol/SbeHello.java +++ b/app/src/main/java/lightcontainer/protocol/SbeHello.java @@ -4,7 +4,7 @@ public class SbeHello extends Protocol { protected SbeHello() { - super("HELLO", "^(HELLO)\\s([A-Za-z0-9.]{5,20})\\s((6553[0-5])|(655[0-2][0-9])|(65[0-4][0-9]{2})|(6[0-4][0-9]{3})|([0-5][0-9]{4})|([0-9]{1,4}))\\r\\n$"); + super("HELLO", "^(HELLO) ([A-Za-z0-9.]{5,20}) ([\\d]{0,5})\r\n$"); } @Override diff --git a/app/src/main/java/lightcontainer/protocol/SbeRetrieveResult.java b/app/src/main/java/lightcontainer/protocol/SbeRetrieveResult.java new file mode 100644 index 0000000..091cca2 --- /dev/null +++ b/app/src/main/java/lightcontainer/protocol/SbeRetrieveResult.java @@ -0,0 +1,12 @@ +package lightcontainer.protocol; + +public class SbeRetrieveResult extends Protocol { + protected SbeRetrieveResult() { + super("RETTRIEVERESULT", "^((RETRIEVE_OK) ([A-Za-z0-9.]{50,200} [0-9]{1,10} [A-Za-z0-9.]{50,200})\r\n)|((RETRIEVE_ERROR)\r\n)$"); + } + + @Override + public void execute(String cmd) { + + } +} diff --git a/app/src/main/java/lightcontainer/protocol/SbeSendResult.java b/app/src/main/java/lightcontainer/protocol/SbeSendResult.java new file mode 100644 index 0000000..48279e1 --- /dev/null +++ b/app/src/main/java/lightcontainer/protocol/SbeSendResult.java @@ -0,0 +1,13 @@ +package lightcontainer.protocol; + +public class SbeSendResult extends Protocol { + + protected SbeSendResult() { + super("SENDRESULT", "^(SEND_OK|SEND_ERROR)\r\n$"); + } + + @Override + public void execute(String cmd) { + + } +} diff --git a/app/src/main/resources/rules.txt b/app/src/main/resources/rules.txt index 511bc2b..e5d69af 100644 --- a/app/src/main/resources/rules.txt +++ b/app/src/main/resources/rules.txt @@ -4,40 +4,40 @@ port = (6553[0-5])|(655[0-2][0-9])|(65[0-4][0-9]{2})|(6[0-4][0-9]{3})|([1-5][0-9 size = [0-9]{1,10} line = \r\n visiblechar = \p{Print} -passchar = [^\s!] +passchar = [^ !] binary = . -password = [^\s!]{5,50} -bl = \s +password = [^ !]{5,50} +bl = //espace letter = [A-Za-z] digit_letter = [A-Za-z0-9] -filename = [^\s!]{1,20} +filename = [^ !]{1,20} domain = [A-Za-z0-9.]{5,20} hash_filename = [A-Za-z0-9.]{50,200} hash_filecontent = [A-Za-z0-9.]{50,200} -file_info = [A-Za-z0-9.]{50,200}\s[0-9]{1,10}\s[A-Za-z0-9.]{50,200} +file_info = [A-Za-z0-9.]{50,200} [0-9]{1,10} [A-Za-z0-9.]{50,200} login = [A-Za-z0-9]{2,20} //StorBackEnd to FileFrontEnd -sbe_hello = ^(HELLO)\s([A-Za-z0-9.]{5,20})\s((6553[0-5])|(655[0-2][0-9])|(65[0-4][0-9]{2})|(6[0-4][0-9]{3})|([0-5][0-9]{4})|([0-9]{1,4}))\r\n$ //TODO \r\n -> à tester pour voir si déjà dans le flux ou doit être construit +sbe_hello = ^HELLO ([A-Za-z0-9.]{5,20}) ([\d]{0,5})\r\n$ //TODO \r\n -> à tester pour voir si déjà dans le flux ou doit être construit //FileFrontEnd to StorBackEnd -ffe_sendfile = ^(SENDFILE)\s([A-Za-z0-9.]{50,200}\s[0-9]{1,10}\s[A-Za-z0-9.]{50,200})\r\n$ +ffe_sendfile = ^SENDFILE ([A-Za-z0-9.]{50,200} [0-9]{1,10} [A-Za-z0-9.]{50,200})\r\n$ sbe_sendresult = ^(SEND_OK|SEND_ERROR)\r\n$ -ffe_erasefile = ^(ERASEFILE)\s([A-Za-z0-9.]{50,200})\r\n$ +ffe_erasefile = ^ERASEFILE ([A-Za-z0-9.]{50,200})\r\n$ sbe_eraseresult = ^(ERASE_OK|ERASE_ERROR)\r\n$ -ffe_retrievefile = ^(RETRIEVEFILE)\s([A-Za-z0-9.]{50,200})\r\n$ -sbe_retrieveresult = ^((RETRIEVE_OK)\s([A-Za-z0-9.]{50,200}\s[0-9]{1,10}\s[A-Za-z0-9.]{50,200})\r\n)|((RETRIEVE_ERROR)\r\n)$ +ffe_retrievefile = ^RETRIEVEFILE ([A-Za-z0-9.]{50,200})\r\n$ +sbe_retrieveresult = ^(RETRIEVE_OK ([A-Za-z0-9.]{50,200} [0-9]{1,10} [A-Za-z0-9.]{50,200})\r\n)|(RETRIEVE_ERROR\r\n)$ //Client to FileFrontEnd -client_signin = ^(SIGNIN)\s([A-Za-z0-9]{2,20})\s([^\s!]{5,50})\r\n$ -client_signup = ^(SIGNUP)\s([A-Za-z0-9]{2,20})\s([^\s!]{5,50})\r\n$ +client_signin = ^SIGNIN ([A-Za-z0-9]{2,20}) ([^ !]{5,50})\r\n$ +client_signup = ^SIGNUP ([A-Za-z0-9]{2,20}) ([^ !]{5,50})\r\n$ ffe_signresult = ^(SIGN_OK|SIGN_ERROR)\r\n$ -client_filelist = ^(FILELIST)\r\n$ -ffe_filelistresult = ^(FILES)\s(([^\s!]{1,20}![0-9]{1,10}){0,50})\r\n$ -client_savefile = ^(SAVE_FILE)\s([^\s!]{1,20})\s([0-9]{1,10})\r\n$ +client_filelist = ^FILELIST\r\n$ +ffe_filelistresult = ^FILES(( [^ !]{1,20})!([0-9]{1,10})){0,50}$ +client_savefile = ^SAVE_FILE ([^ !]{1,20}) ([0-9]{1,10})\r\n$ ffe_savefileresult = ^(SAVEFILE_OK|SAVEFILE_ERROR)\r\n$ -client_getfile = ^(GETFILE)\s([^\s!]{1,20})\r\n$ -ffe_getfileresult = ^((GETFILE_OK)\s(^\s!]{1,20})\s([0-9]{1,10})\r\n)|((GETFILE_ERROR)\r\n)$ -client_removefile = ^(REMOVEFILE)\s([^\s!]{1,20})\r\n$ +client_getfile = ^GETFILE ([^ !]{1,20})\r\n$ +ffe_getfileresult = ^(GETFILE_OK (^ !]{1,20}) ([0-9]{1,10})\r\n)|(GETFILE_ERROR\r\n)$ +client_removefile = ^REMOVEFILE ([^ !]{1,20})\r\n$ ffe_removefileresult = ^(REMOVEFILE_OK|REMOVEFILE_ERROR)\r\n$ -client_signout = ^(SIGNOUT)\r\n$ \ No newline at end of file +client_signout = ^SIGNOUT\r\n$ \ No newline at end of file From a883918363cdacf95d21926b853c1631832a9202 Mon Sep 17 00:00:00 2001 From: Maximilien LEDOUX Date: Sat, 26 Feb 2022 14:32:59 +0100 Subject: [PATCH 3/8] Suppression protocols inutiles --- .../lightcontainer/protocol/ClientFileList.java | 12 ------------ .../lightcontainer/protocol/ClientGetFile.java | 12 ------------ .../protocol/ClientRemoveFile.java | 13 ------------- .../lightcontainer/protocol/ClientSaveFile.java | 12 ------------ .../lightcontainer/protocol/ClientSignIn.java | 13 ------------- .../lightcontainer/protocol/ClientSignOut.java | 12 ------------ .../lightcontainer/protocol/ClientSignUp.java | 12 ------------ .../lightcontainer/protocol/SbeEraseResult.java | 12 ------------ .../java/lightcontainer/protocol/SbeHello.java | 16 ---------------- .../protocol/SbeRetrieveResult.java | 12 ------------ .../lightcontainer/protocol/SbeSendResult.java | 13 ------------- 11 files changed, 139 deletions(-) delete mode 100644 app/src/main/java/lightcontainer/protocol/ClientFileList.java delete mode 100644 app/src/main/java/lightcontainer/protocol/ClientGetFile.java delete mode 100644 app/src/main/java/lightcontainer/protocol/ClientRemoveFile.java delete mode 100644 app/src/main/java/lightcontainer/protocol/ClientSaveFile.java delete mode 100644 app/src/main/java/lightcontainer/protocol/ClientSignIn.java delete mode 100644 app/src/main/java/lightcontainer/protocol/ClientSignOut.java delete mode 100644 app/src/main/java/lightcontainer/protocol/ClientSignUp.java delete mode 100644 app/src/main/java/lightcontainer/protocol/SbeEraseResult.java delete mode 100644 app/src/main/java/lightcontainer/protocol/SbeHello.java delete mode 100644 app/src/main/java/lightcontainer/protocol/SbeRetrieveResult.java delete mode 100644 app/src/main/java/lightcontainer/protocol/SbeSendResult.java diff --git a/app/src/main/java/lightcontainer/protocol/ClientFileList.java b/app/src/main/java/lightcontainer/protocol/ClientFileList.java deleted file mode 100644 index c88f72f..0000000 --- a/app/src/main/java/lightcontainer/protocol/ClientFileList.java +++ /dev/null @@ -1,12 +0,0 @@ -package lightcontainer.protocol; - -public class ClientFileList extends Protocol{ - protected ClientFileList() { - super("FILELIST", "^FILELIST\r\n$"); - } - - @Override - public void execute(String cmd) { - - } -} diff --git a/app/src/main/java/lightcontainer/protocol/ClientGetFile.java b/app/src/main/java/lightcontainer/protocol/ClientGetFile.java deleted file mode 100644 index 4b0fa24..0000000 --- a/app/src/main/java/lightcontainer/protocol/ClientGetFile.java +++ /dev/null @@ -1,12 +0,0 @@ -package lightcontainer.protocol; - -public class ClientGetFile extends Protocol{ - protected ClientGetFile() { - super("GETFILE","^GETFILE ([^ !]{1,20})\r\n$"); - } - - @Override - public void execute(String cmd) { - - } -} diff --git a/app/src/main/java/lightcontainer/protocol/ClientRemoveFile.java b/app/src/main/java/lightcontainer/protocol/ClientRemoveFile.java deleted file mode 100644 index dd5375b..0000000 --- a/app/src/main/java/lightcontainer/protocol/ClientRemoveFile.java +++ /dev/null @@ -1,13 +0,0 @@ -package lightcontainer.protocol; - -public class ClientRemoveFile extends Protocol{ - - protected ClientRemoveFile() { - super("REMOVEFILE", "^REMOVEFILE ([^ !]{1,20})\r\n$"); - } - - @Override - public void execute(String cmd) { - - } -} diff --git a/app/src/main/java/lightcontainer/protocol/ClientSaveFile.java b/app/src/main/java/lightcontainer/protocol/ClientSaveFile.java deleted file mode 100644 index a3b7b11..0000000 --- a/app/src/main/java/lightcontainer/protocol/ClientSaveFile.java +++ /dev/null @@ -1,12 +0,0 @@ -package lightcontainer.protocol; - -public class ClientSaveFile extends Protocol { - protected ClientSaveFile() { - super("SAVEFILE", "^SAVE_FILE ([^ !]{1,20}) ([0-9]{1,10})\r\n$"); - } - - @Override - public void execute(String cmd) { - - } -} diff --git a/app/src/main/java/lightcontainer/protocol/ClientSignIn.java b/app/src/main/java/lightcontainer/protocol/ClientSignIn.java deleted file mode 100644 index 43edf56..0000000 --- a/app/src/main/java/lightcontainer/protocol/ClientSignIn.java +++ /dev/null @@ -1,13 +0,0 @@ -package lightcontainer.protocol; - -public class ClientSignIn extends Protocol { - - protected ClientSignIn() { - super("SIGNIN", "^(SIGNIN) ([A-Za-z0-9]{2,20}) ([^ !]{5,50})\r\n$"); - } - - @Override - public void execute(String cmd) { - - } -} diff --git a/app/src/main/java/lightcontainer/protocol/ClientSignOut.java b/app/src/main/java/lightcontainer/protocol/ClientSignOut.java deleted file mode 100644 index 909b047..0000000 --- a/app/src/main/java/lightcontainer/protocol/ClientSignOut.java +++ /dev/null @@ -1,12 +0,0 @@ -package lightcontainer.protocol; - -public class ClientSignOut extends Protocol { - protected ClientSignOut() { - super("SIGNOUT", "^SIGNOUT\r\n$"); - } - - @Override - public void execute(String cmd) { - - } -} diff --git a/app/src/main/java/lightcontainer/protocol/ClientSignUp.java b/app/src/main/java/lightcontainer/protocol/ClientSignUp.java deleted file mode 100644 index 91c67d3..0000000 --- a/app/src/main/java/lightcontainer/protocol/ClientSignUp.java +++ /dev/null @@ -1,12 +0,0 @@ -package lightcontainer.protocol; - -public class ClientSignUp extends Protocol{ - protected ClientSignUp() { - super("SIGNUP","^(SIGNUP) ([A-Za-z0-9]{2,20}) ([^ !]{5,50})\r\n$"); - } - - @Override - public void execute(String cmd) { - - } -} diff --git a/app/src/main/java/lightcontainer/protocol/SbeEraseResult.java b/app/src/main/java/lightcontainer/protocol/SbeEraseResult.java deleted file mode 100644 index 301edd8..0000000 --- a/app/src/main/java/lightcontainer/protocol/SbeEraseResult.java +++ /dev/null @@ -1,12 +0,0 @@ -package lightcontainer.protocol; - -public class SbeEraseResult extends Protocol { - protected SbeEraseResult() { - super("ERASERESULT", "^(ERASE_OK|ERASE_ERROR)\r\n$"); - } - - @Override - public void execute(String cmd) { - - } -} diff --git a/app/src/main/java/lightcontainer/protocol/SbeHello.java b/app/src/main/java/lightcontainer/protocol/SbeHello.java deleted file mode 100644 index 6cd750a..0000000 --- a/app/src/main/java/lightcontainer/protocol/SbeHello.java +++ /dev/null @@ -1,16 +0,0 @@ -package lightcontainer.protocol; - -public class SbeHello extends Protocol { - - - protected SbeHello() { - super("HELLO", "^(HELLO) ([A-Za-z0-9.]{5,20}) ([\\d]{0,5})\r\n$"); - } - - @Override - public void execute(String cmd) { - if (matcherCheck(cmd)) { - - } - } -} diff --git a/app/src/main/java/lightcontainer/protocol/SbeRetrieveResult.java b/app/src/main/java/lightcontainer/protocol/SbeRetrieveResult.java deleted file mode 100644 index 091cca2..0000000 --- a/app/src/main/java/lightcontainer/protocol/SbeRetrieveResult.java +++ /dev/null @@ -1,12 +0,0 @@ -package lightcontainer.protocol; - -public class SbeRetrieveResult extends Protocol { - protected SbeRetrieveResult() { - super("RETTRIEVERESULT", "^((RETRIEVE_OK) ([A-Za-z0-9.]{50,200} [0-9]{1,10} [A-Za-z0-9.]{50,200})\r\n)|((RETRIEVE_ERROR)\r\n)$"); - } - - @Override - public void execute(String cmd) { - - } -} diff --git a/app/src/main/java/lightcontainer/protocol/SbeSendResult.java b/app/src/main/java/lightcontainer/protocol/SbeSendResult.java deleted file mode 100644 index 48279e1..0000000 --- a/app/src/main/java/lightcontainer/protocol/SbeSendResult.java +++ /dev/null @@ -1,13 +0,0 @@ -package lightcontainer.protocol; - -public class SbeSendResult extends Protocol { - - protected SbeSendResult() { - super("SENDRESULT", "^(SEND_OK|SEND_ERROR)\r\n$"); - } - - @Override - public void execute(String cmd) { - - } -} From 8201d3db9120a5b5ef3e11a9d361ba41b30acc18 Mon Sep 17 00:00:00 2001 From: Maximilien LEDOUX Date: Sat, 26 Feb 2022 14:41:35 +0100 Subject: [PATCH 4/8] =?UTF-8?q?ProtocolWriter=20:=20mod=C3=A8le=20pour=20r?= =?UTF-8?q?=C3=A8gles=20protocoles=20d'=C3=A9criture?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../protocol/ProtocolWriter.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 app/src/main/java/lightcontainer/protocol/ProtocolWriter.java diff --git a/app/src/main/java/lightcontainer/protocol/ProtocolWriter.java b/app/src/main/java/lightcontainer/protocol/ProtocolWriter.java new file mode 100644 index 0000000..c05e428 --- /dev/null +++ b/app/src/main/java/lightcontainer/protocol/ProtocolWriter.java @@ -0,0 +1,23 @@ +package lightcontainer.protocol; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public abstract class ProtocolWriter { + + private final Pattern rulePattern; + + protected ProtocolWriter(String pattern) { + this.rulePattern = Pattern.compile(pattern); + } + + public String execute(String data) { + Matcher ruleMatcher = this.rulePattern.matcher(data); + + if (ruleMatcher.matches()) { + + } + + return null; + } +} From 0ae48806796a253197f8ed2bf1e2176f13a12305 Mon Sep 17 00:00:00 2001 From: Maximilien LEDOUX Date: Sat, 26 Feb 2022 15:00:37 +0100 Subject: [PATCH 5/8] =?UTF-8?q?ProtocolWriter=20:=20mod=C3=A8le=20pour=20r?= =?UTF-8?q?=C3=A8gles=20protocoles=20d'=C3=A9criture=20termin=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../protocol/ProtocolWriter.java | 34 +++++++++++++++---- 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/lightcontainer/protocol/ProtocolWriter.java b/app/src/main/java/lightcontainer/protocol/ProtocolWriter.java index c05e428..051794a 100644 --- a/app/src/main/java/lightcontainer/protocol/ProtocolWriter.java +++ b/app/src/main/java/lightcontainer/protocol/ProtocolWriter.java @@ -1,23 +1,45 @@ package lightcontainer.protocol; +import java.util.StringJoiner; import java.util.regex.Matcher; import java.util.regex.Pattern; public abstract class ProtocolWriter { private final Pattern rulePattern; + private final String cmdName; - protected ProtocolWriter(String pattern) { + + protected ProtocolWriter(String cmdName, String pattern) { this.rulePattern = Pattern.compile(pattern); + this.cmdName = cmdName; } - public String execute(String data) { - Matcher ruleMatcher = this.rulePattern.matcher(data); + /** + * Permet de récupérer le nom du protocol + * @return + */ + public String getCmdName() { + return cmdName; + } - if (ruleMatcher.matches()) { + /** + * Permet de contruire une commande selon une règle établie. + * @param datas Les données à ajouter dans la commande; L'ordre défini leur position dans la commande + * @return La commande construite + */ + public String execute(String... datas) { + // Concatatène le nom de la commande avec les données (trim), avec un espace entre chaque + String command = null; + StringJoiner builder = new StringJoiner(" ", this.cmdName, ""); - } + for (String data : datas) + builder.add(data); - return null; + command = builder.toString(); + + // Vérifie que tout match (cf. Matcher). Si match alors on retourne la commande build, sinon on retourne NULL + Matcher ruleMatcher = this.rulePattern.matcher(command); + return ruleMatcher.matches() ? command : null; } } From ee867c9b1d3e8f9efd96fab3d44e2a30ebaa79fc Mon Sep 17 00:00:00 2001 From: Maximilien LEDOUX Date: Sat, 26 Feb 2022 15:07:46 +0100 Subject: [PATCH 6/8] =?UTF-8?q?SignoutRule=20cr=C3=A9=C3=A9e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../protocol/rules/{ => reader}/HelloRule.java | 2 +- .../protocol/rules/writer/SignoutRule.java | 14 ++++++++++++++ .../protocol/rules/HelloRuleTest.java | 1 + 3 files changed, 16 insertions(+), 1 deletion(-) rename app/src/main/java/lightcontainer/protocol/rules/{ => reader}/HelloRule.java (93%) create mode 100644 app/src/main/java/lightcontainer/protocol/rules/writer/SignoutRule.java diff --git a/app/src/main/java/lightcontainer/protocol/rules/HelloRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/HelloRule.java similarity index 93% rename from app/src/main/java/lightcontainer/protocol/rules/HelloRule.java rename to app/src/main/java/lightcontainer/protocol/rules/reader/HelloRule.java index 30acdb9..a39019b 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/HelloRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/HelloRule.java @@ -1,4 +1,4 @@ -package lightcontainer.protocol.rules; +package lightcontainer.protocol.rules.reader; import lightcontainer.protocol.ProtocolReader; diff --git a/app/src/main/java/lightcontainer/protocol/rules/writer/SignoutRule.java b/app/src/main/java/lightcontainer/protocol/rules/writer/SignoutRule.java new file mode 100644 index 0000000..ff42d2c --- /dev/null +++ b/app/src/main/java/lightcontainer/protocol/rules/writer/SignoutRule.java @@ -0,0 +1,14 @@ +package lightcontainer.protocol.rules.writer; + +import lightcontainer.protocol.ProtocolWriter; + +public class SignoutRule extends ProtocolWriter { + + private static final String PATTERN = "^SIGNOUT\r\n$"; + + public static final String NAME = "SIGNOUT"; + + public SignoutRule() { + super(NAME, PATTERN); + } +} diff --git a/app/src/test/java/lightcontainer/protocol/rules/HelloRuleTest.java b/app/src/test/java/lightcontainer/protocol/rules/HelloRuleTest.java index 8305c90..55517f4 100644 --- a/app/src/test/java/lightcontainer/protocol/rules/HelloRuleTest.java +++ b/app/src/test/java/lightcontainer/protocol/rules/HelloRuleTest.java @@ -1,6 +1,7 @@ package lightcontainer.protocol.rules; import lightcontainer.protocol.ProtocolReader; +import lightcontainer.protocol.rules.reader.HelloRule; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; From 2c0d56b30488599ff772d4798b376a9c7bbf9a73 Mon Sep 17 00:00:00 2001 From: Maximilien LEDOUX Date: Sat, 26 Feb 2022 15:12:56 +0100 Subject: [PATCH 7/8] Classe test pour SignoutRule --- .../protocol/rules/{ => reader}/HelloRuleTest.java | 2 +- .../protocol/rules/writer/SignoutRuleTest.java | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) rename app/src/test/java/lightcontainer/protocol/rules/{ => reader}/HelloRuleTest.java (91%) create mode 100644 app/src/test/java/lightcontainer/protocol/rules/writer/SignoutRuleTest.java diff --git a/app/src/test/java/lightcontainer/protocol/rules/HelloRuleTest.java b/app/src/test/java/lightcontainer/protocol/rules/reader/HelloRuleTest.java similarity index 91% rename from app/src/test/java/lightcontainer/protocol/rules/HelloRuleTest.java rename to app/src/test/java/lightcontainer/protocol/rules/reader/HelloRuleTest.java index 55517f4..c2a1b04 100644 --- a/app/src/test/java/lightcontainer/protocol/rules/HelloRuleTest.java +++ b/app/src/test/java/lightcontainer/protocol/rules/reader/HelloRuleTest.java @@ -1,4 +1,4 @@ -package lightcontainer.protocol.rules; +package lightcontainer.protocol.rules.reader; import lightcontainer.protocol.ProtocolReader; import lightcontainer.protocol.rules.reader.HelloRule; diff --git a/app/src/test/java/lightcontainer/protocol/rules/writer/SignoutRuleTest.java b/app/src/test/java/lightcontainer/protocol/rules/writer/SignoutRuleTest.java new file mode 100644 index 0000000..ab427ff --- /dev/null +++ b/app/src/test/java/lightcontainer/protocol/rules/writer/SignoutRuleTest.java @@ -0,0 +1,7 @@ +package lightcontainer.protocol.rules.writer; + +import static org.junit.jupiter.api.Assertions.*; + +class SignoutRuleTest { + +} \ No newline at end of file From d3361a76794a3dc0df3a7db1df54359beb51fc9a Mon Sep 17 00:00:00 2001 From: Maximilien LEDOUX Date: Sat, 26 Feb 2022 15:20:05 +0100 Subject: [PATCH 8/8] =?UTF-8?q?SignoutRule=20test=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lightcontainer/protocol/ProtocolWriter.java | 2 +- .../protocol/rules/writer/SignoutRuleTest.java | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/lightcontainer/protocol/ProtocolWriter.java b/app/src/main/java/lightcontainer/protocol/ProtocolWriter.java index 051794a..4605a30 100644 --- a/app/src/main/java/lightcontainer/protocol/ProtocolWriter.java +++ b/app/src/main/java/lightcontainer/protocol/ProtocolWriter.java @@ -31,7 +31,7 @@ public abstract class ProtocolWriter { public String execute(String... datas) { // Concatatène le nom de la commande avec les données (trim), avec un espace entre chaque String command = null; - StringJoiner builder = new StringJoiner(" ", this.cmdName, ""); + StringJoiner builder = new StringJoiner(" ", this.cmdName, "\r\n"); for (String data : datas) builder.add(data); diff --git a/app/src/test/java/lightcontainer/protocol/rules/writer/SignoutRuleTest.java b/app/src/test/java/lightcontainer/protocol/rules/writer/SignoutRuleTest.java index ab427ff..31bf799 100644 --- a/app/src/test/java/lightcontainer/protocol/rules/writer/SignoutRuleTest.java +++ b/app/src/test/java/lightcontainer/protocol/rules/writer/SignoutRuleTest.java @@ -1,7 +1,21 @@ package lightcontainer.protocol.rules.writer; +import lightcontainer.protocol.ProtocolWriter; +import org.junit.jupiter.api.Test; + import static org.junit.jupiter.api.Assertions.*; class SignoutRuleTest { + @Test + public void whenRuleIsRightThenReturnCommand() { + //GIVEN + ProtocolWriter protocolWriter = new SignoutRule(); + String[] datas = {}; + + //EXPECT + assertNotNull(protocolWriter.execute(datas)); + assertEquals("SIGNOUT\r\n", protocolWriter.execute(datas)); + } + } \ No newline at end of file