2022-02-20 11:33:47 +01:00
|
|
|
package readers
|
2022-02-19 18:10:52 +01:00
|
|
|
|
2022-03-08 12:01:51 +01:00
|
|
|
import (
|
|
|
|
"StoreBackEnd/pkg/protocol"
|
2022-03-08 17:44:10 +01:00
|
|
|
"net"
|
2022-03-08 12:01:51 +01:00
|
|
|
)
|
2022-02-19 18:10:52 +01:00
|
|
|
|
2022-03-08 10:25:00 +01:00
|
|
|
// EraseFileRulePrefix Identifiant de cette règle
|
|
|
|
const EraseFileRulePrefix = "ERASEFILE"
|
2022-02-22 08:34:45 +01:00
|
|
|
|
2022-02-19 18:10:52 +01:00
|
|
|
// EraseFileRule Demande de suppression d'un fichier
|
|
|
|
type EraseFileRule struct {
|
|
|
|
// Cmd Nom de la règle
|
|
|
|
Cmd string
|
|
|
|
|
|
|
|
// matcher Permet de vérifier le matching
|
|
|
|
matcher *protocol.RegexMatcher
|
|
|
|
}
|
|
|
|
|
|
|
|
// CreateEraseFileRule Création d'une instance de EraseFileRule
|
2022-02-22 10:52:07 +01:00
|
|
|
func CreateEraseFileRule(pattern string) protocol.IProtocolReader {
|
2022-02-19 18:10:52 +01:00
|
|
|
return &EraseFileRule{
|
2022-03-08 10:25:00 +01:00
|
|
|
Cmd: EraseFileRulePrefix,
|
2022-02-19 18:10:52 +01:00
|
|
|
matcher: protocol.CreateRegexMatcher(pattern),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-22 08:47:03 +01:00
|
|
|
func (rule EraseFileRule) GetCmd() string {
|
|
|
|
return rule.Cmd
|
|
|
|
}
|
|
|
|
|
2022-03-08 17:44:10 +01:00
|
|
|
func (rule EraseFileRule) Execute(data string) (string, bool, func(r net.Conn) (string, bool)) {
|
2022-02-20 12:35:05 +01:00
|
|
|
if rule.Match(data) {
|
2022-02-22 10:52:07 +01:00
|
|
|
values := rule.matcher.Parse(data)
|
|
|
|
println(values[1], " est le hash du fichier à supprimer")
|
2022-03-08 12:01:51 +01:00
|
|
|
return "Parsing : Fichier avec le hash " + values[1] + " supprimé", true, nil
|
2022-02-19 18:10:52 +01:00
|
|
|
} else {
|
2022-03-08 12:01:51 +01:00
|
|
|
return "Parsing : EraseFileRule command incorrecte", false, nil
|
2022-02-19 18:10:52 +01:00
|
|
|
}
|
|
|
|
}
|
2022-02-20 12:35:05 +01:00
|
|
|
|
|
|
|
func (rule EraseFileRule) Match(data string) bool {
|
|
|
|
return rule.matcher.Match(data)
|
|
|
|
}
|