CMSDK 2.0.1
Cross-platform C++ base library and SDK for the Psyclone AIOS platform
Loading...
Searching...
No Matches
cmlabs::RESTParser Class Reference

Parses and validates incoming requests against an XML REST API definition. More...

#include <RESTAPI.h>

Collaboration diagram for cmlabs::RESTParser:
[legend]

Public Member Functions

 RESTParser ()
 Create an uninitialised parser; call init() before use.
virtual ~RESTParser ()
 Destructor; deletes the owned RESTHTTPCall objects.
bool init (const char *restDefinition)
 Load and validate the XML REST API definition.
RESTRequestparseRequest (HTTPRequest *req)
 Parse an incoming HTTP request against the API definition.
RESTRequestparseRequest (DataMessage *msg)
 Parse a request carried in a DataMessage against the API definition.
const char * getLastErrorString ()

Static Public Member Functions

static bool UnitTest ()
 Run the RESTParser unit tests.

Protected Member Functions

XMLNode findTopNodeForRequest (const char *requestString)
std::map< std::string, RESTParamparseParamSet (XMLNode objectNode)
XMLNode parseRequest (const char *requestString, std::map< std::string, RESTParam > &paramSet, RESTRequest *restReq, std::string &signature)
bool extractParameters (HTTPRequest *req, std::map< std::string, RESTParam > &paramSet, RESTRequest *restReq)
bool extractParameters (DataMessage *msg, std::map< std::string, RESTParam > &paramSet, RESTRequest *restReq)
bool extractArrayParameters (HTTPRequest *req, std::map< std::string, RESTParam > &paramSet, RESTRequest *restReq, int entryNum, const char *content, uint32 contentSize, const char *contentType)
bool extractArrayParameters (DataMessage *msg, std::map< std::string, RESTParam > &paramSet, RESTRequest *restReq, int entryNum, const char *content, uint32 contentSize, const char *contentType)
bool setParameterValue (HTTPRequest *req, RESTParam &param, std::string value, RESTRequest *restReq, uint32 entryNum=0)
bool setParameterValue (DataMessage *msg, RESTParam &param, std::string value, RESTRequest *restReq, uint32 entryNum=0)

Protected Attributes

XMLNode mainNode
std::string lastErrorString
std::map< std::string, std::map< std::string, RESTParam > > paramSets
std::map< std::string, RESTHTTPCall * > httpCalls

Detailed Description

Parses and validates incoming requests against an XML REST API definition.

Initialise once with init() (the <restapi> XML), then call parseRequest() per incoming HTTPRequest or DataMessage. Returns a new RESTRequest per call (caller takes ownership); check RESTRequest::getStatus(). Owns the RESTHTTPCall objects defined in the API. init()/parseRequest() are not synchronised — initialise before serving and treat the parser as read-only afterwards.

Definition at line 153 of file RESTAPI.h.

Constructor & Destructor Documentation

◆ RESTParser()

cmlabs::RESTParser::RESTParser ( )

Create an uninitialised parser; call init() before use.

Definition at line 13 of file RESTAPI.cpp.

References mainNode.

Referenced by UnitTest().

◆ ~RESTParser()

cmlabs::RESTParser::~RESTParser ( )
virtual

Destructor; deletes the owned RESTHTTPCall objects.

Definition at line 16 of file RESTAPI.cpp.

References httpCalls.

Member Function Documentation

◆ extractArrayParameters() [1/2]

◆ extractArrayParameters() [2/2]

◆ extractParameters() [1/2]

◆ extractParameters() [2/2]

◆ findTopNodeForRequest()

XMLNode cmlabs::RESTParser::findTopNodeForRequest ( const char * requestString)
protected

Definition at line 1339 of file RESTAPI.cpp.

References cmlabs::XMLNode::getAttribute(), and mainNode.

Referenced by parseRequest().

◆ getLastErrorString()

const char * cmlabs::RESTParser::getLastErrorString ( )
inline
Returns
Description of the most recent init()/parse error.

Definition at line 181 of file RESTAPI.h.

References lastErrorString.

Referenced by UnitTest().

◆ init()

bool cmlabs::RESTParser::init ( const char * restDefinition)

Load and validate the XML REST API definition.

Parameters
restDefinitionXML text with <restapi> as the main tag.
Returns
true on success; on failure see getLastErrorString().

Definition at line 26 of file RESTAPI.cpp.

References cmlabs::XMLResults::error, cmlabs::eXMLErrorFirstTagNotFound, cmlabs::eXMLErrorNone, cmlabs::XMLNode::getAttribute(), httpCalls, cmlabs::RESTHTTPCall::init(), lastErrorString, mainNode, cmlabs::XMLResults::nColumn, cmlabs::XMLResults::nLine, paramSets, parseParamSet(), and cmlabs::utils::StringFormat().

Referenced by UnitTest().

◆ parseParamSet()

◆ parseRequest() [1/3]

◆ parseRequest() [2/3]

◆ parseRequest() [3/3]

◆ setParameterValue() [1/2]

◆ setParameterValue() [2/2]

◆ UnitTest()

Member Data Documentation

◆ httpCalls

std::map<std::string, RESTHTTPCall*> cmlabs::RESTParser::httpCalls
protected

Definition at line 187 of file RESTAPI.h.

Referenced by init(), parseRequest(), parseRequest(), and ~RESTParser().

◆ lastErrorString

std::string cmlabs::RESTParser::lastErrorString
protected

Definition at line 185 of file RESTAPI.h.

Referenced by getLastErrorString(), init(), and parseParamSet().

◆ mainNode

XMLNode cmlabs::RESTParser::mainNode
protected

Definition at line 184 of file RESTAPI.h.

Referenced by findTopNodeForRequest(), init(), parseRequest(), and RESTParser().

◆ paramSets

std::map<std::string, std::map<std::string, RESTParam> > cmlabs::RESTParser::paramSets
protected

Definition at line 186 of file RESTAPI.h.

Referenced by extractParameters(), extractParameters(), init(), and parseRequest().


The documentation for this class was generated from the following files:
  • /home/ubuntu/c/partner/psyclone2/CMSDK/include/RESTAPI.h
  • /home/ubuntu/c/partner/psyclone2/CMSDK/src/RESTAPI.cpp