Commit 7c5cfc3b authored by Ismail Moumni's avatar Ismail Moumni
Browse files

Editing server_conn

parent 256f9993
Pipeline #1062 failed with stage
in 14 seconds
...@@ -6,7 +6,6 @@ import sys ...@@ -6,7 +6,6 @@ import sys
import database.database as db import database.database as db
sys.path.append(os.path.realpath('../softwares/')) sys.path.append(os.path.realpath('../softwares/'))
__RDOS_Dict__ = {} __RDOS_Dict__ = {}
# tools List # tools List
...@@ -34,18 +33,12 @@ class RdosServer: ...@@ -34,18 +33,12 @@ class RdosServer:
print("Requete reçu : ", query) print("Requete reçu : ", query)
if(query is not None): if(query is not None):
# Sending GENERATORS # Sending GENERATORS
if (query["request"] == "generators"): if (query_valid(query)):
response = db.db_generators() response = db.db_generators()
conn.send(bytes(json.dumps(response), "utf-8")) conn.send(bytes(json.dumps(response), "utf-8"))
# Inserting in DATABASE # Inserting in DATABASE
elif (query["Tool"] is not None):
match = verif_param(query)
if match != query:
ins = db_insert(conn, match)
print(ins)
else: else:
raise Exception("Query doesn't match!") db_insert(conn, check_and_complete_parameters(query))
conn.send(bytes(json.dumps(match), "utf-8"))
# Function query_valwid matches the query send from client side # Function query_valwid matches the query send from client side
...@@ -108,10 +101,10 @@ def match_query_dict(biblio: dict, data: dict): ...@@ -108,10 +101,10 @@ def match_query_dict(biblio: dict, data: dict):
raise ValueError("Error Dict Values ") raise ValueError("Error Dict Values ")
# Function verif_param verifies json send from client to server by matching it with database query # Function check_and_complete_parameters verifies json send from client to server by matching it with database query
# Function input takes a dictionary # Function input takes a dictionary
# Function output returns query if it matches with database query keys if not it raises an error # Function output returns query if it matches with database query keys if not it raises an error
def verif_param(data: dict): def check_and_complete_parameters(data: dict):
if data is not None: if data is not None:
tool = data.keys().strip('[]') tool = data.keys().strip('[]')
s = db.getParameters(data['tool']) s = db.getParameters(data['tool'])
...@@ -146,7 +139,7 @@ def db_generators(req: dict): ...@@ -146,7 +139,7 @@ def db_generators(req: dict):
s = db.get_generators() s = db.get_generators()
return s return s
else: else:
raise Exception("Error Database") raise Exception("Dictionnaire non Valid")
else: else:
raise Exception("Dictionnaire Vide!!") raise Exception("Dictionnaire Vide!!")
...@@ -156,12 +149,10 @@ def db_generators(req: dict): ...@@ -156,12 +149,10 @@ def db_generators(req: dict):
# Function db_insert returns a string if query send # Function db_insert returns a string if query send
def db_insert(s: socket, req: dict): def db_insert(s: socket, req: dict):
if(req is not None): if(req is not None):
if (verif_param(req) == req):
ins = db.insert_query(req) ins = db.insert_query(req)
s.send(bytes(json.dumps(ins), "utf-8")) s.send(bytes(json.dumps(ins), "utf-8"))
print("Query send") print("Query send")
else: else:
raise Exception("Query Doesn't match")
raise Exception("Invalid Query") raise Exception("Invalid Query")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment