|
ZOO-Project
|
#include "request_parser.h"#include "service_internal.h"#include "server_internal.h"#include "service_callback.h"#include "response_print.h"#include "caching.h"#include "cgic.h"#include <errno.h>#include <dirent.h>#include <string.h>Macros | |
| #define | CWL_FAIL(kind, msg) do { iErrKind = (kind); pccErrMsg = (msg); goto cleanup; } while (0) |
Functions | |
| xmlXPathObjectPtr | extractFromDoc (xmlDocPtr doc, const char *pccSearch) |
| Apply XPath Expression on XML document. More... | |
| int | appendMapsToMaps (maps **ppmsConf, maps *pmsOutput, maps *pmsInput, elements *peElem) |
| Create (or append to) an array valued maps value = "["",""]". More... | |
| void | ensureDecodedBase64 (maps **ppmsInput) |
| Make sure that each value encoded in base64 in a maps is decoded. More... | |
| 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. More... | |
| int | kvpParseOutputs (maps **pmsConf, map *request_inputs, maps **request_output) |
| Parse outputs provided as KVP and store them in a maps. More... | |
| int | defineMissingIdentifier (maps **pmsConf, maps **mymaps) |
| Create a "missingIdentifier" maps in case it is NULL. More... | |
| 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. More... | |
| int | xmlParseBoundingBox (maps **pmsConf, map **current_input, xmlDocPtr doc) |
| Parse a BoundingBoxData node. More... | |
| int | xmlParseOutputs2 (maps **pmsConf, map **request_inputs, maps **request_output, xmlDocPtr doc, xmlNodeSet *nodes) |
| Parse outputs from XML nodes and store them in a maps (WPS version 2.0.0). More... | |
| 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. More... | |
| 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. More... | |
| int | parseRequest (maps **pmsConf, map **request_inputs, service *s, maps **inputs, maps **outputs, HINTERNET *hInternet) |
| Parse request and store information in maps. More... | |
| 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. More... | |
| void | checkValidValue (map *request, map **res, const char *toCheck, const char **avalues, int mandatory) |
| Verify if a parameter value is valid. More... | |
| void | parseCookie (maps **conf, const char *cookie) |
| Parse cookie contained in request headers. More... | |
| int | parseInputHttpRequests (maps *conf, maps *inputs, HINTERNET *hInternet) |
| Parse all the http requests possibily attached to inputs and, add them to the request queue. More... | |
| char * | getDirName (const char *pccPath) |
| Returns the parent directory of the given path, allocated with malloc. More... | |
| static const char * | findBytes (const char *pccData, size_t stDataLen, const char *pccNeedle, size_t stNeedleLen) |
| Searches for a sequence of bytes (needle) within a larger block of data. More... | |
| static const char * | findHeaderEnd (const char *pccStart, const char *pccEnd, size_t *pstSepLen) |
| Finds the end of the headers in a CWL multipart message. More... | |
| static const char * | findBoundaryLine (const char *pccBody, const char *pccFrom, const char *pccEnd, const char *pccDelim, size_t stDelimLen, int *piIsFinal, const char **ppcAfterLine) |
| Finds the next boundary delimiter LINE in a multipart body. More... | |
| static cwlStatus | splitHeaderLine (const char *pccLine, size_t stLen, char **ppcField, char **ppcValue) |
| Splits a header line into its field and value components. More... | |
| static char * | stripAngleBrackets (const char *pccInput) |
| Strips angle brackets from a string if they exist. More... | |
| static void | freeCwlParts (cwlPart *pcpParts, int iNbParts) |
| Frees the strings owned by the parts. More... | |
| static cwlStatus | parsePartHeaders (const char *pccHeaderBlock, size_t stLen, cwlPart *pcpPart) |
| Parses the headers of a multipart part and fills the corresponding fields in the cwlPart structure. More... | |
| cwlStatus | splitMultipartRelated (const char *pccBody, size_t stBodyLen, const char *pccBoundary, cwlPart pcpParts[], int iMaxParts, int *piNbParts) |
| Splits a multipart/related body into its constituent parts. More... | |
| cwlStatus | sanitizeRelativePath (const char *pccRawName, char **ppcOut) |
| Sanitize a relative file path. More... | |
| int | pathStaysUnderWorkDir (const char *pccWorkDir, const char *pccFullPath) |
| Verify that the parent directory of fullPath resolves under workDir. More... | |
| static int | mkdirOne (const char *pccPath) |
| Creates one directory; an already existing path is accepted ONLY if it is a real directory (not a file, not a symlink). More... | |
| int | mkdirRecursive (const char *pccPath) |
| Recursively create the specified directory and all its missing parent directories. More... | |
| int | mkdirRecursiveForFile (const char *pccFilePath) |
| Recursively create the parent directory of the specified file path (without creating the file itself). More... | |
| static int | removeRecursive (const char *pccPath) |
| Recursively remove the specified file or directory. More... | |
| int | cleanupWorkDir (const char *pccWorkDir) |
| Clean up the specified work directory by recursively removing all its contents. More... | |
| char * | createExclusiveWorkDir (maps *pmsConf) |
| Create the work directory of a multipart deployment with mkdtemp(): the directory is guaranteed to be new and owned by this request (mode 0700), so it is always safe to remove it on error. More... | |
| 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>"'. More... | |
| int | handleInvalidParameterValue (maps *pmsConf, const char *pccMessage) |
| Raise an OGC "InvalidParameterValue" exception and return -1. More... | |
| int | handleInternalError (maps *pmsConf, const char *pccMessage) |
| Raise an OGC "NoApplicableCode" exception (server-side failure: disk full, out of memory, ...) and return -1. More... | |
| static int | writeAll (int iFd, const char *pccData, size_t stLen) |
| Write the whole buffer to a file descriptor, handling partial writes and EINTR. More... | |
| int | handleCwlMultipartDeploy (maps *pmsConf, const char *pccBody, size_t stBodyLen, const char *pccBoundary, const char *pccStartId) |
| Handle the deployment of a CWL multipart request. More... | |
| #define CWL_FAIL | ( | kind, | |
| msg | |||
| ) | do { iErrKind = (kind); pccErrMsg = (msg); goto cleanup; } while (0) |
Create (or append to) an array valued maps value = "["",""]".
| ppmsConf | the conf maps containing the main.cfg settings |
| pmsOutput | the map to update |
| pmsInput | the map to append |
| peElem | the elements containing default definitions |
| void checkValidValue | ( | map * | request, |
| map ** | res, | ||
| const char * | toCheck, | ||
| const char ** | avalues, | ||
| int | mandatory | ||
| ) |
Verify if a parameter value is valid.
| request | the request map |
| res | the error map potentially generated |
| toCheck | the parameter to use |
| avalues | the acceptable values (or null if testing only for presence) |
| mandatory | verify the presence of the parameter if mandatory > 0 |
| int cleanupWorkDir | ( | const char * | pccWorkDir | ) |
Clean up the specified work directory by recursively removing all its contents.
| pccWorkDir | The path to the work directory to clean up. |
| char* createExclusiveWorkDir | ( | maps * | pmsConf | ) |
Create the work directory of a multipart deployment with mkdtemp(): the directory is guaranteed to be new and owned by this request (mode 0700), so it is always safe to remove it on error.
| pmsConf | The configuration maps ("main"/"tmpPath", default "/tmp"). |
Create a "missingIdentifier" maps in case it is NULL.
| pmsConf | the conf maps containing the main.cfg settings |
| mymaps | the maps to update |
| void ensureDecodedBase64 | ( | maps ** | ppmsInput | ) |
Make sure that each value encoded in base64 in a maps is decoded.
| ppmsInput | the maps containing the values |
| xmlXPathObjectPtr extractFromDoc | ( | xmlDocPtr | doc, |
| const char * | pccSearch | ||
| ) |
Apply XPath Expression on XML document.
| doc | the XML Document |
| pccSearch | the XPath expression |
| 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.
| pccContentType | The content type header string. |
| pccParamName | The name of the parameter to extract. |
|
static |
Finds the next boundary delimiter LINE in a multipart body.
A delimiter is only accepted if it starts at the beginning of the body or right after a '
', and is followed by either "--" (closing delimiter) or optional blanks and a line break. An occurrence of "--boundary" inside the content of a part (or a longer boundary sharing the same prefix) is ignored.
| pccBody | Start of the whole body (used to detect "beginning of body"). |
| pccFrom | Where to start searching. |
| pccEnd | End of the body. |
| pccDelim | The delimiter string ("--" + boundary). |
| stDelimLen | Length of the delimiter string. |
| piIsFinal | Set to 1 if the delimiter is the closing one ("--boundary--"). |
| ppcAfterLine | Set to the first byte after the delimiter line. |
|
static |
Searches for a sequence of bytes (needle) within a larger block of data.
| pccData | Pointer to the start of the data block. |
| stDataLen | Length of the data block. |
| pccNeedle | Pointer to the sequence of bytes to search for. |
| stNeedleLen | Length of the sequence of bytes to search for. |
|
static |
Finds the end of the headers in a CWL multipart message.
| pccStart | Pointer to the start of the buffer containing headers. |
| pccEnd | Pointer to the end of the buffer. |
| pstSepLen | Pointer to a size_t variable where the length of the separator will be stored. |
|
static |
Frees the strings owned by the parts.
'data' is NOT freed: it points into the body buffer provided by the caller.
| pcpParts | Array of parts. |
| iNbParts | Number of valid entries in the array. |
| char* getDirName | ( | const char * | pccPath | ) |
Returns the parent directory of the given path, allocated with malloc.
The caller is responsible for freeing the returned string.
| pccPath | Full path to the file for which the parent directory is to be determined. |
| 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):
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.
| pmsConf | The configuration maps. |
| pccBody | The body of the multipart request. |
| stBodyLen | The length of the body. |
| pccBoundary | The boundary string for the multipart request. |
| pccStartId | The start parameter value (may be NULL). |
| int handleInternalError | ( | maps * | pmsConf, |
| const char * | pccMessage | ||
| ) |
Raise an OGC "NoApplicableCode" exception (server-side failure: disk full, out of memory, ...) and return -1.
| pmsConf | The configuration maps. |
| pccMessage | The error message. |
| int handleInvalidParameterValue | ( | maps * | pmsConf, |
| const char * | pccMessage | ||
| ) |
Raise an OGC "InvalidParameterValue" exception and return -1.
| pmsConf | The configuration maps. |
| pccMessage | The error message. |
| 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.
| pmsConf | the conf maps containing the main.cfg settings |
| s | the service |
| request_inputs | the map storing KVP raw value |
| request_output | the maps to store the KVP pairs |
| hInternet | the HINTERNET queue to add potential requests |
Parse outputs provided as KVP and store them in a maps.
| pmsConf | the conf maps containing the main.cfg settings |
| request_inputs | the map storing KVP raw value |
| request_output | the maps to store the KVP pairs |
Parsing outputs provided as KVP
Put each Output into the outputs_as_text array
|
static |
Creates one directory; an already existing path is accepted ONLY if it is a real directory (not a file, not a symlink).
| int mkdirRecursive | ( | const char * | pccPath | ) |
Recursively create the specified directory and all its missing parent directories.
Equivalent to "mkdir -p".
| pccPath | The path of the directory to create. |
| int mkdirRecursiveForFile | ( | const char * | pccFilePath | ) |
Recursively create the parent directory of the specified file path (without creating the file itself).
| pccFilePath | The path of the file whose parent directory is to be created. |
| void parseCookie | ( | maps ** | conf, |
| const char * | cookie | ||
| ) |
Parse cookie contained in request headers.
| conf | the conf maps containinfg the main.cfg |
| cookie | the |
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.
| conf | maps containing the main configuration file |
| inputs | maps containing all the inputs |
| hInternet | an HTINTERNET connection |
|
static |
Parses the headers of a multipart part and fills the corresponding fields in the cwlPart structure.
A repeated Content-ID, Content-Location or Content-Type header is rejected (ambiguous), and an allocation failure is reported instead of silently dropping the header.
| pccHeaderBlock | Pointer to the start of the header block. |
| stLen | Length of the header block. |
| pcpPart | Pointer to the cwlPart structure to be filled with the parsed headers. |
| int parseRequest | ( | maps ** | pmsConf, |
| map ** | request_inputs, | ||
| service * | s, | ||
| maps ** | inputs, | ||
| maps ** | outputs, | ||
| HINTERNET * | hInternet | ||
| ) |
Parse request and store information in maps.
| pmsConf | the conf maps containing the main.cfg settings |
| post | the string containing the XML request |
| request_inputs | the map storing KVP raw value |
| s | the service |
| inputs | the maps to store the KVP pairs |
| outputs | the maps to store the KVP pairs |
| hInternet | the HINTERNET queue to add potential requests |
| int pathStaysUnderWorkDir | ( | const char * | pccWorkDir, |
| const char * | pccFullPath | ||
| ) |
Verify that the parent directory of fullPath resolves under workDir.
The final file component is NOT checked here: it is created with O_CREAT | O_EXCL | O_NOFOLLOW by the caller, which refuses an existing file or a symlink.
| pccWorkDir | The base directory to check against. |
| pccFullPath | The full path to check. |
|
static |
Recursively remove the specified file or directory.
If the path is a directory, all its contents are removed as well.
| pccPath | The path to remove. |
| cwlStatus sanitizeRelativePath | ( | const char * | pccRawName, |
| char ** | ppcOut | ||
| ) |
Sanitize a relative file path.
| pccRawName | The raw relative file path to sanitize. |
| ppcOut | Receives a newly allocated "clean" relative path on CWL_OK, NULL otherwise. |
|
static |
Splits a header line into its field and value components.
On CWL_OK, both outputs are either malloc'ed (to be freed by the caller) or both NULL when the line is a folded continuation line, which is ignored.
| pccLine | Pointer to the start of the header line. |
| stLen | Length of the header line. |
| ppcField | Receives the field name. |
| ppcValue | Receives the field value. |
| cwlStatus splitMultipartRelated | ( | const char * | pccBody, |
| size_t | stBodyLen, | ||
| const char * | pccBoundary, | ||
| cwlPart | pcpParts[], | ||
| int | iMaxParts, | ||
| int * | piNbParts | ||
| ) |
Splits a multipart/related body into its constituent parts.
Delimiters are only recognized as full lines; the closing delimiter ("--boundary--") is required; more than iMaxParts parts is an error (no silent truncation). On failure, everything allocated here is released.
| pccBody | Pointer to the start of the body. |
| stBodyLen | Length of the body. |
| pccBoundary | Boundary string used to separate parts. |
| pcpParts | Array of cwlPart structures to be filled. |
| iMaxParts | Maximum number of parts that can be stored in the parts array. |
| piNbParts | Pointer to an integer where the number of parts found will be stored (0 on failure). |
|
static |
Strips angle brackets from a string if they exist.
| pccInput | The input string. |
| 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.
| pmsConf | |
| s | |
| original_request | |
| request_inputs | |
| request_outputs | |
| hInternet |
|
static |
Write the whole buffer to a file descriptor, handling partial writes and EINTR.
Uses write(2) directly, so FCGI's stdio wrappers are not involved.
Parse a BoundingBoxData node.
http://schemas.opengis.net/ows/1.1.0/owsCommon.xsd: BoundingBoxType
A map to store boundingbox information will contain:
| pmsConf | the conf maps containing the main.cfg settings |
| request_inputs | the map storing KVP raw value |
| doc | the xmlDocPtr containing the BoudingoxData node |
| 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.
| pmsConf | the conf maps containing the main.cfg settings |
| s | the service |
| request_output | the maps to store the KVP pairs |
| doc | the xmlDocPtr containing the original request |
| nodes | the input nodes array |
| hInternet | the HINTERNET queue to add potential requests |
| 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.
| pmsConf | the conf maps containing the main.cfg settings |
| request_inputs | the map storing KVP raw value |
| request_output | the maps to store the KVP pairs |
| doc | the xmlDocPtr containing the original request |
| cur | the xmlNodePtr corresponding to the ResponseDocument or RawDataOutput XML node |
| raw | true if the node is RawDataOutput, false in case of ResponseDocument |
| int xmlParseOutputs2 | ( | maps ** | pmsConf, |
| map ** | request_inputs, | ||
| maps ** | request_output, | ||
| xmlDocPtr | doc, | ||
| xmlNodeSet * | nodes | ||
| ) |
Parse outputs from XML nodes and store them in a maps (WPS version 2.0.0).
| pmsConf | the conf maps containing the main.cfg settings |
| request_inputs | the map storing KVP raw value |
| request_output | the maps to store the KVP pairs |
| doc | the xmlDocPtr containing the original request |
| cur | the xmlNodePtr corresponding to the ResponseDocument or RawDataOutput XML node |
| raw | true if the node is RawDataOutput, false in case of ResponseDocument |
| 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.
| pmsConf | the conf maps containing the main.cfg settings |
| post | the string containing the XML request |
| request_inputs | the map storing KVP raw value |
| s | the service |
| inputs | the maps to store the KVP pairs |
| outputs | the maps to store the KVP pairs |
| hInternet | the HINTERNET queue to add potential requests |
Extract Input nodes from the XML Request.
1.8.17