SearchSECODatabaseAPI
DatabaseRequestHandler Class Reference

Handles requests towards database. More...

#include <DatabaseRequestHandler.h>

Public Member Functions

 DatabaseRequestHandler (DatabaseHandler *database, Statistics *stats, std::string ip=IP, int port=DBPORT)
 
std::string handleUploadRequest (std::string request, std::string client)
 Handles requests which want to add one project with their corresponding methods to the database. More...
 
std::string handleCheckRequest (std::string request)
 Handles requests wanting to obtain methods with certain hashes. More...
 
std::string handleCheckRequest (std::vector< Hash > hashes)
 Handles requests wanting to obtain methods with certain hashes. More...
 
std::string handleCheckUploadRequest (std::string request, std::string client)
 Handles requests wanting to first check for matches with existing methods in other projects, after which it adds the project itself to the database. More...
 
std::string handleExtractProjectsRequest (std::string request)
 Handles requests wanting to obtain project data from the database given their projectID and version. More...
 
std::string handlePrevProjectsRequest (std::string request)
 Handles requests wanting to obtain project data from a the database from a previous version given their projectID. More...
 
std::string handleGetAuthorRequest (std::string request)
 Handles a requests for retrieving the authors by the given IDs. More...
 
std::string handleGetMethodsByAuthorRequest (std::string request)
 Handles requests wanting to obtain methods with certain authors. More...
 
std::string getExtension (std::string file)
 Retrieves the extension from the passed file name. More...
 

Detailed Description

Handles requests towards database.

Member Function Documentation

◆ getExtension()

std::string DatabaseRequestHandler::getExtension ( std::string  file)

Retrieves the extension from the passed file name.

Parameters
fileThe file name to get the extension of.
Returns
The extension of the file.

◆ handleCheckRequest() [1/2]

std::string DatabaseRequestHandler::handleCheckRequest ( std::string  request)

Handles requests wanting to obtain methods with certain hashes.

Parameters
requestThe request made by the user, having the following format: "hash_1'\n'hash_2'\n'...'\n'hash_N".
Returns
The methods which contain hashes equal to one within the request. A method is presented as follows: "method_hash?projectID?startVersion?startVersionHash?endVersion?endVersionHash? method_name?file?lineNumber?parserVersion?vulnCode?authorTotal?authorID_1?...?authorID_N". Separated methods are separated by '
'.

◆ handleCheckRequest() [2/2]

std::string DatabaseRequestHandler::handleCheckRequest ( std::vector< Hash >  hashes)

Handles requests wanting to obtain methods with certain hashes.

Parameters
hashesThe list of hashes we want to check for.
Returns
The methods which contain hashes equal to one within the request. A method is presented as follows: "method_hash?projectID?startVersion?startVersionHash?endVersion?endVersionHash? method_name?file?lineNumber?parserVersion?vulnCode?authorTotal?authorID_1?...?authorID_N". Separated methods are separated by '
'.

◆ handleCheckUploadRequest()

std::string DatabaseRequestHandler::handleCheckUploadRequest ( std::string  request,
std::string  client 
)

Handles requests wanting to first check for matches with existing methods in other projects, after which it adds the project itself to the database.

Parameters
requestThe request made by the user, having the following format: "projectID?version?versionHash?license?project_name?url?owner_name?owner_mail?parserVersion'\n' method1_hash?method1_name?method1_fileLocation?method1_lineNumber?method1_numberOfAuthors? method1_author1_name?method1_author1_mail?...?method1_authorM_name?method1_authorM_mail?vulnCode'\n' <method2_data>'\n'...'\n'<methodN_data>".
Returns
The methods which contain hashes equal to one within the request. A method is presented as follows: "method_hash?projectID?startVersion?startVersionHash?endVersion?endVersionHash? method_name?file?lineNumber?parserVersion?vulnCode?authorTotal?authorID_1?...?authorID_N". Separated methods are separated by '
'.

◆ handleExtractProjectsRequest()

std::string DatabaseRequestHandler::handleExtractProjectsRequest ( std::string  request)

Handles requests wanting to obtain project data from the database given their projectID and version.

Parameters
requestThe request made by the user which has the following format: "projectID_1?version_1'\n'...'\n'projectID_M?version_M".
Returns
The projects found in the database in string format. A project is presented as follows: "projectID?version?versionHash?license?project_name?url?owner_id?parserVersion". Separated projects are separated by '
'.

◆ handleGetAuthorRequest()

std::string DatabaseRequestHandler::handleGetAuthorRequest ( std::string  request)

Handles a requests for retrieving the authors by the given IDs.

<param nam'="request"> The request that contains the author ids with the following format: id_1'
'...'
'id_N

Returns
A string with the authors retrieved from the database. An author is presented as follows: "name?mail?id". The authors are separated by '
'.

◆ handleGetMethodsByAuthorRequest()

std::string DatabaseRequestHandler::handleGetMethodsByAuthorRequest ( std::string  request)

Handles requests wanting to obtain methods with certain authors.

Parameters
requestThe request made by the user, having the following format: "authorID_1'\n'authorID_2'\n'...".
Returns
The method keys that the given authors have worked on. An entry is presented as follows: "authorID?hash?projectID?version". Separated entries are separated by '
'.

◆ handlePrevProjectsRequest()

std::string DatabaseRequestHandler::handlePrevProjectsRequest ( std::string  request)

Handles requests wanting to obtain project data from a the database from a previous version given their projectID.

Parameters
requestThe request made by the user which has the following format: "projectID_1'\n'...'\n'projectID_M".
Returns
The projects found in the database in string format. A project is presented as follows: "projectID?version?versionHash?license?project_name?url?owner_id?parserVersion". Separated projects are separated by '
'.

◆ handleUploadRequest()

std::string DatabaseRequestHandler::handleUploadRequest ( std::string  request,
std::string  client 
)

Handles requests which want to add one project with their corresponding methods to the database.

Parameters
requestThe request made by the user. It has the following format: "projectID?version?versionHash?license?project_name?url?owner_name?owner_mail?parserVersion'\n' prevVersion'\n' unchangedfile1?unchangedfile2?...?unchangedfileM'\n' method1_hash?method1_name?method1_fileLocation?method1_lineNumber?method1_numberOfAuthors? method1_author1_name?method1_author1_mail?<other authors>?vulnCode'\n'<method2_data>'\n'...'\n'<methodN_data>". If you want to upload a new project, the second and third row containing prevVersion and the unchanged files, can be left empty.
Returns
Response towards user after processing the request.

The documentation for this class was generated from the following files: