ZOO-Project
Data Structures | Macros | Enumerations | Functions
request_parser.h File Reference
#include "service.h"
#include "ulinet.h"
#include <libxml/parser.h>
#include <libxml/xpath.h>

Go to the source code of this file.

Data Structures

struct  cwlPart
 Structure representing a single part of a multipart request. More...
 

Macros

#define CWL_MAX_PARTS   64
 
#define CWL_MAX_BODY_SIZE   (16UL * 1024UL * 1024UL)
 
#define CWL_MAX_HEADER_BLOCK   16384
 
#define CWL_MAX_BOUNDARY_LEN   70 /* RFC 2046 */
 
#define O_NOFOLLOW   0
 

Enumerations

enum  cwlStatus { CWL_OK = 0, CWL_ERR_INVALID = 1, CWL_ERR_NOMEM = 2 }
 Result of the parsing helpers. More...
 

Functions

xmlXPathObjectPtr extractFromDoc (xmlDocPtr, const char *)
 Apply XPath Expression on XML document. More...
 
int appendMapsToMaps (maps **, maps *, maps *, elements *)
 Create (or append to) an array valued maps value = "["",""]". More...
 
void ensureDecodedBase64 (maps **)
 Make sure that each value encoded in base64 in a maps is decoded. More...
 
int kvpParseInputs (maps **, service *, map *, maps **, HINTERNET *)
 Parse inputs provided as KVP and store them in a maps. More...
 
int xmlParseBoundingBox (maps **, map **, xmlDocPtr)
 Parse a BoundingBoxData node. More...
 
int kvpParseOutputs (maps **, map *, maps **)
 Parse outputs provided as KVP and store them in a maps. More...
 
int xmlParseInputs (maps **, service *, maps **, xmlDocPtr, xmlNodeSet *, HINTERNET *)
 Parse inputs from XML nodes and store them in a maps. More...
 
int xmlParseOutputs (maps **, map **, maps **, xmlDocPtr, xmlNodePtr, bool)
 Parse outputs from XML nodes and store them in a maps. More...
 
int xmlParseRequest (maps **, const char *, map **, service *, maps **, maps **, HINTERNET *)
 Parse XML request and store information in maps. More...
 
int parseRequest (maps **, map **, service *, maps **, maps **, HINTERNET *)
 Parse request and store information in maps. More...
 
void checkValidValue (map *, map **, const char *, const char **, int)
 Verify if a parameter value is valid. More...
 
int validateRequest (maps **, service *, map *, maps **, maps **, HINTERNET *)
 Ensure that each requested arguments are present in the request DataInputs and ResponseDocument / RawDataOutput. More...
 
void parseCookie (maps **, const char *)
 Parse cookie contained in request headers. More...
 
int parseInputHttpRequests (maps *, maps *, HINTERNET *)
 Parse all the http requests possibily attached to inputs and, add them to the request queue. More...
 
char * extractMimeParam (const char *contentType, const char *paramName)
 Extract the value of a parameter from a header such as 'multipart/related; boundary="a;b"; start="<main@cwl>"'. More...
 
int handleCwlMultipartDeploy (maps *, const char *, size_t, const char *, const char *)
 Handle the deployment of a CWL multipart request. More...
 

Data Structure Documentation

◆ cwlPart

struct cwlPart

Structure representing a single part of a multipart request.

This structure holds metadata and content for each part of a multipart request. It is used when handling multipart requests, such as CWL multipart deploys. Each part contains its Content-ID, proposed relative path, MIME type, and the actual data. The data pointer points into the original body buffer and should not be freed separately. The length field indicates the size of the data buffer.

Data Fields
char * contentId
char * contentLocation
char * contentType
const char * data
size_t len

Macro Definition Documentation

◆ CWL_MAX_BODY_SIZE

#define CWL_MAX_BODY_SIZE   (16UL * 1024UL * 1024UL)

◆ CWL_MAX_BOUNDARY_LEN

#define CWL_MAX_BOUNDARY_LEN   70 /* RFC 2046 */

◆ CWL_MAX_HEADER_BLOCK

#define CWL_MAX_HEADER_BLOCK   16384

◆ CWL_MAX_PARTS

#define CWL_MAX_PARTS   64

◆ O_NOFOLLOW

#define O_NOFOLLOW   0

Enumeration Type Documentation

◆ cwlStatus

enum cwlStatus

Result of the parsing helpers.

NOMEM is kept distinct from INVALID so that an allocation failure is reported as a server error, not as a bad request.

Enumerator
CWL_OK 
CWL_ERR_INVALID 
CWL_ERR_NOMEM 

Function Documentation

◆ appendMapsToMaps()

int appendMapsToMaps ( maps **  ppmsConf,
maps *  pmsOutput,
maps *  pmsInput,
elements *  peElem 
)

Create (or append to) an array valued maps value = "["",""]".

Parameters
ppmsConfthe conf maps containing the main.cfg settings
pmsOutputthe map to update
pmsInputthe map to append
peElemthe elements containing default definitions
Returns
0 on success, -1 on failure

◆ checkValidValue()

void checkValidValue ( map *  request,
map **  res,
const char *  toCheck,
const char **  avalues,
int  mandatory 
)

Verify if a parameter value is valid.

Parameters
requestthe request map
resthe error map potentially generated
toCheckthe parameter to use
avaluesthe acceptable values (or null if testing only for presence)
mandatoryverify the presence of the parameter if mandatory > 0

◆ ensureDecodedBase64()

void ensureDecodedBase64 ( maps **  ppmsInput)

Make sure that each value encoded in base64 in a maps is decoded.

Parameters
ppmsInputthe maps containing the values
See also
readBase64

◆ extractFromDoc()

xmlXPathObjectPtr extractFromDoc ( xmlDocPtr  doc,
const char *  pccSearch 
)

Apply XPath Expression on XML document.

Parameters
docthe XML Document
pccSearchthe XPath expression
Returns
xmlXPathObjectPtr containing the resulting nodes set

◆ extractMimeParam()

char* extractMimeParam ( const char *  pccContentType,
const char *  pccParamName 
)

Extract the value of a parameter from a header such as 'multipart/related; boundary="a;b"; start="<main@cwl>"'.

Handles unquoted values, quoted values containing ';' and backslash-escaped characters inside quoted values. The parameter name is matched exactly (case-insensitively). Angle brackets are NOT removed here.

Parameters
pccContentTypeThe content type header string.
pccParamNameThe name of the parameter to extract.
Returns
A malloc'ed string with the unquoted value, or NULL if the parameter is absent, empty, malformed or if the allocation fails.

◆ handleCwlMultipartDeploy()

int handleCwlMultipartDeploy ( maps *  pmsConf,
const char *  pccBody,
size_t  stBodyLen,
const char *  pccBoundary,
const char *  pccStartId 
)

Handle the deployment of a CWL multipart request.

Writes every part under an exclusively created work directory and publishes the "cwl-parts" map and "main"/"workDir" in the configuration only once everything has been written successfully. Every error path goes through a single cleanup block.

Root document contract (RFC 2387):

  • if start= is given, it is compared, after removing the optional angle brackets, with the Content-ID of each part (exact match, no "cid:" handling): start="<main@cwl>" selects the part whose header is "Content-ID: <main@cwl>". It must match exactly one part, otherwise the request is rejected;
  • if start= is absent, the root is the FIRST part.

Published in "cwl-parts": name (raw start value, "" if absent), path[i] and file[i] for each part, main (relative name of the root) and mainPath (absolute path of the root). Two parts resolving to the same path, or sharing the same Content-ID, are rejected.

Parameters
pmsConfThe configuration maps.
pccBodyThe body of the multipart request.
stBodyLenThe length of the body.
pccBoundaryThe boundary string for the multipart request.
pccStartIdThe start parameter value (may be NULL).
Returns
0 on success, -1 on failure (an OGC exception has been raised).

◆ kvpParseInputs()

int kvpParseInputs ( maps **  pmsConf,
service *  s,
map *  request_inputs,
maps **  request_output,
HINTERNET *  hInternet 
)

Parse inputs provided as KVP and store them in a maps.

Parameters
pmsConfthe conf maps containing the main.cfg settings
sthe service
request_inputsthe map storing KVP raw value
request_outputthe maps to store the KVP pairs
hInternetthe HINTERNET queue to add potential requests
Returns
0 on success, -1 on failure

◆ kvpParseOutputs()

int kvpParseOutputs ( maps **  pmsConf,
map *  request_inputs,
maps **  request_output 
)

Parse outputs provided as KVP and store them in a maps.

Parameters
pmsConfthe conf maps containing the main.cfg settings
request_inputsthe map storing KVP raw value
request_outputthe maps to store the KVP pairs
Returns
0 on success, -1 on failure

Parsing outputs provided as KVP

Put each Output into the outputs_as_text array

◆ parseCookie()

void parseCookie ( maps **  conf,
const char *  cookie 
)

Parse cookie contained in request headers.

Parameters
confthe conf maps containinfg the main.cfg
cookiethe

◆ parseInputHttpRequests()

int parseInputHttpRequests ( maps *  conf,
maps *  inputs,
HINTERNET *  hInternet 
)

Parse all the http requests possibily attached to inputs and, add them to the request queue.

Add Reference and Order fields to the input's metadata map.

Parameters
confmaps containing the main configuration file
inputsmaps containing all the inputs
hInternetan HTINTERNET connection
Returns
0 in case of success
See also
readCurrentInput

◆ parseRequest()

int parseRequest ( maps **  pmsConf,
map **  request_inputs,
service *  s,
maps **  inputs,
maps **  outputs,
HINTERNET *  hInternet 
)

Parse request and store information in maps.

Parameters
pmsConfthe conf maps containing the main.cfg settings
postthe string containing the XML request
request_inputsthe map storing KVP raw value
sthe service
inputsthe maps to store the KVP pairs
outputsthe maps to store the KVP pairs
hInternetthe HINTERNET queue to add potential requests
Returns
0 on success, -1 on failure
See also
kvpParseOutputs,kvpParseInputs,xmlParseRequest

◆ validateRequest()

int validateRequest ( maps **  pmsConf,
service *  s,
map *  original_request,
maps **  request_inputs,
maps **  request_outputs,
HINTERNET *  hInternet 
)

Ensure that each requested arguments are present in the request DataInputs and ResponseDocument / RawDataOutput.

Potentially run http requests from the queue in parallel. For optional inputs add default values defined in the ZCFG file.

Parameters
pmsConf
s
original_request
request_inputs
request_outputs
hInternet
See also
runHttpRequests

◆ xmlParseBoundingBox()

int xmlParseBoundingBox ( maps **  ,
map **  ,
xmlDocPtr   
)

Parse a BoundingBoxData node.

http://schemas.opengis.net/ows/1.1.0/owsCommon.xsd: BoundingBoxType

A map to store boundingbox information will contain:

  • LowerCorner : double double (minimum within this bounding box)
  • UpperCorner : double double (maximum within this bounding box)
  • crs : URI (Reference to definition of the CRS)
  • dimensions : int
Parameters
pmsConfthe conf maps containing the main.cfg settings
request_inputsthe map storing KVP raw value
docthe xmlDocPtr containing the BoudingoxData node
Returns
a map containing all the bounding box keys

◆ xmlParseInputs()

int xmlParseInputs ( maps **  pmsConf,
service *  s,
maps **  request_output,
xmlDocPtr  doc,
xmlNodeSet *  nodes,
HINTERNET *  hInternet 
)

Parse inputs from XML nodes and store them in a maps.

Parameters
pmsConfthe conf maps containing the main.cfg settings
sthe service
request_outputthe maps to store the KVP pairs
docthe xmlDocPtr containing the original request
nodesthe input nodes array
hInternetthe HINTERNET queue to add potential requests
Returns
0 on success, -1 on failure

◆ xmlParseOutputs()

int xmlParseOutputs ( maps **  pmsConf,
map **  request_inputs,
maps **  request_output,
xmlDocPtr  doc,
xmlNodePtr  cur,
bool  raw 
)

Parse outputs from XML nodes and store them in a maps.

Parameters
pmsConfthe conf maps containing the main.cfg settings
request_inputsthe map storing KVP raw value
request_outputthe maps to store the KVP pairs
docthe xmlDocPtr containing the original request
curthe xmlNodePtr corresponding to the ResponseDocument or RawDataOutput XML node
rawtrue if the node is RawDataOutput, false in case of ResponseDocument
Returns
0 on success, -1 on failure

◆ xmlParseRequest()

int xmlParseRequest ( maps **  pmsConf,
const char *  post,
map **  request_inputs,
service *  s,
maps **  inputs,
maps **  outputs,
HINTERNET *  hInternet 
)

Parse XML request and store information in maps.

Parameters
pmsConfthe conf maps containing the main.cfg settings
postthe string containing the XML request
request_inputsthe map storing KVP raw value
sthe service
inputsthe maps to store the KVP pairs
outputsthe maps to store the KVP pairs
hInternetthe HINTERNET queue to add potential requests
Returns
0 on success, -1 on failure

Extract Input nodes from the XML Request.