Commit 3c921e5f authored by Ismail Moumni's avatar Ismail Moumni
Browse files

edit server_conn

parent 3d1c11a9
Pipeline #706 failed with stage
in 13 seconds
......@@ -21,3 +21,4 @@ tests/__pycache__/__init__.cpython-38.pyc
tests/__pycache__/test_query_valid.cpython-38-pytest-6.0.2.pyc
tests/__pycache__/test_mail.cpython-38-pytest-6.0.2.pyc
softwares/mailer/__init__.py
softwares/server/__init__.py
......@@ -25,22 +25,26 @@ class RdosServer:
serv.listen(5)
# accepting the connection from client and getting client IP
conn, addr = serv.accept()
with conn:
print('Connexion acceptee depuis l IP : ', addr)
# Receiving Data from Client
data = conn.recv(4096)
query = (json.loads(data.decode('utf-8')))
print(query)
if query_valid(query):
Tool = __RDOS_Tool__
dt_js = json.dumps(send_param_client(__RDOS_Dict__, Tool))
print(dt_js)
conn.send(bytes((dt_js), "utf-8"))
while True:
if conn:
print('Connexion acceptee depuis l IP : ', addr)
# Receiving Data from Client
data = conn.recv(4096)
query = (json.loads(data.decode('utf-8')))
print(query)
if query_valid(query):
match = verif_param(query)
if match == query:
print("ok")
conn.send(bytes(json.dumps(match), "utf-8"))
else:
print('Erreur query : ')
conn.send(bytes(json.dumps(match), "utf-8"))
# Function query_valwid matches the query send from client side
# with the the parameter dict
# Function input dictionnary from client
# Function input dictionary from client
# Function output boolean true if match else False
def query_valid(data: dict):
if 'parameters' in data:
......@@ -52,8 +56,8 @@ def query_valid(data: dict):
# Function send_param_client send a Dict containing parameters
# needed to add a query to db
# Function exmaple s = {"ARGUMENTS","Tools":"List of Tools" }
# Function input takes dictionnary and a list of tools
# Function output returns a new dictionnary containing arguments
# Function input takes dictionary and a list of tools
# Function output returns a new dictionary containing arguments
# # for db query and list of tools
def send_param_client(__RDOS_Dict__: dict, __RDOS_Tools__: list):
# req = db.getParameters()
......@@ -61,20 +65,23 @@ def send_param_client(__RDOS_Dict__: dict, __RDOS_Tools__: list):
# Function json_loads changes a json file into a Dict
# Function json_loads returns a Dictinnary
# Function json_loads returns a dictionary
def json_to_dict(js):
data = json.loads(js)
return data
# Function db_req sends a request to get parameters of tools from database
# Function takes a dictionnary for input
# Function takes a dictionary for input
# Function return a Dict containing tool parameters and default parameters
def db_req(tool: dict):
tool_dict = db.getParameters(tool)
return tool_dict
# Function match_query_dict matches two dictionaries
# Function input takes 2 dictionaries to match
# Function output return trur if dictionaries matches else raise a value error exception
def match_query_dict(biblio: dict, data: dict):
if biblio is not None and data is not None:
return biblio.keys() == data.keys()
......@@ -82,9 +89,9 @@ def match_query_dict(biblio: dict, data: dict):
raise ValueError("Error Dict Values ")
# Function match_generator_dict Matches Dictionnary with a list
# Function input 2 arguments Dictionnary and query from Server
# Function output true if dictionnary keys match list elements else false
# Function match_generator_dict Matches dictionary with a list
# Function input 2 arguments dictionary and query from Server
# Function output true if dictionary keys match list elements else false
def match_generator_dict(biblio: dict, Genereator: list):
for a in Genereator:
for b in biblio.keys():
......@@ -93,6 +100,9 @@ def match_generator_dict(biblio: dict, Genereator: list):
return True
# Function verif_param verifies json send from client to server by matching it with database query
# Function input takes a dictionary
# Function output returns query if it matches with database query keys if not it raises an error
def verif_param(data: dict):
tool = data.keys().strip('[]')
s = db.getParameters(data['tool'])
......
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