ZOO-Project
request_parser.h
Go to the documentation of this file.
1 /*
2  * Author : GĂ©rald FENOY
3  *
4  * Copyright (c) 2015 GeoLabs SARL
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22  * THE SOFTWARE.
23  */
24 
25 #ifndef ZOO_REQUEST_PARSER_H
26 #define ZOO_REQUEST_PARSER_H 1
27 
28 #pragma once
29 
30 #include "service.h"
31 #include "ulinet.h"
32 
33 #include <libxml/parser.h>
34 #include <libxml/xpath.h>
35 
36 
37 #define CWL_MAX_PARTS 64
38 
39 /* Defensive limits (override at compile time if needed). They do not replace
40  * the request size limit that should already be enforced upstream. */
41 #ifndef CWL_MAX_BODY_SIZE
42 #define CWL_MAX_BODY_SIZE (16UL * 1024UL * 1024UL)
43 #endif
44 #ifndef CWL_MAX_HEADER_BLOCK
45 #define CWL_MAX_HEADER_BLOCK 16384
46 #endif
47 #define CWL_MAX_BOUNDARY_LEN 70 /* RFC 2046 */
48 
49 #ifndef O_NOFOLLOW
50 #define O_NOFOLLOW 0
51 #endif
52 
53 #ifdef __cplusplus
54 extern "C" {
55 #endif
56 
61  typedef enum {
62  CWL_OK = 0,
63  CWL_ERR_INVALID = 1, // malformed or unsafe input
64  CWL_ERR_NOMEM = 2 // allocation failure
65  } cwlStatus;
66 
75  typedef struct {
76  char *contentId; // Content-ID of the part (without < and >)
77  char *contentLocation; // relative path proposed by the client
78  char *contentType; // MIME type of the part
79  const char *data; // pointer INTO the body buffer (no copy, never freed)
80  size_t len; // length of the part's data
81  } cwlPart;
82 
83  xmlXPathObjectPtr extractFromDoc (xmlDocPtr, const char *);
84  int appendMapsToMaps (maps**, maps*, maps*, elements*);
85  void ensureDecodedBase64(maps**);
87  int xmlParseBoundingBox(maps**,map**,xmlDocPtr);
88  int kvpParseOutputs(maps**,map *,maps**);
89  int xmlParseInputs(maps**,service*,maps**,xmlDocPtr,xmlNodeSet*,HINTERNET*);
90  int xmlParseBoundingBox(maps** main_conf,map** current_input,xmlDocPtr doc);
91  int xmlParseOutputs(maps**,map**,maps**,xmlDocPtr,xmlNodePtr,bool);
92  int xmlParseRequest(maps**,const char*,map**,service*,maps**,maps**,HINTERNET*);
94  void checkValidValue(map*,map**,const char*,const char**,int);
96  void parseCookie(maps**,const char*);
98  char *extractMimeParam(const char *contentType, const char *paramName);
99  int handleCwlMultipartDeploy(maps*, const char*, size_t, const char*, const char*);
100 
101 #ifdef __cplusplus
102 }
103 #endif
104 
105 #endif
appendMapsToMaps
int appendMapsToMaps(maps **, maps *, maps *, elements *)
Create (or append to) an array valued maps value = "["",""]".
Definition: request_parser.c:64
cwlPart::data
const char * data
Definition: request_parser.h:79
cwlPart
Structure representing a single part of a multipart request.
Definition: request_parser.h:75
validateRequest
int validateRequest(maps **, service *, map *, maps **, maps **, HINTERNET *)
Ensure that each requested arguments are present in the request DataInputs and ResponseDocument / Raw...
Definition: request_parser.c:1612
service.h
CWL_OK
@ CWL_OK
Definition: request_parser.h:62
cwlPart::contentLocation
char * contentLocation
Definition: request_parser.h:77
service
Metadata information about a full Service.
Definition: service.h:775
elements
Metadata information about input or output.
Definition: service.h:760
extractFromDoc
xmlXPathObjectPtr extractFromDoc(xmlDocPtr, const char *)
Apply XPath Expression on XML document.
Definition: request_parser.c:45
xmlParseBoundingBox
int xmlParseBoundingBox(maps **, map **, xmlDocPtr)
Parse a BoundingBoxData node.
Definition: request_parser.c:1161
cwlPart::contentType
char * contentType
Definition: request_parser.h:78
parseInputHttpRequests
int parseInputHttpRequests(maps *, maps *, HINTERNET *)
Parse all the http requests possibily attached to inputs and, add them to the request queue.
Definition: request_parser.c:1997
xmlParseRequest
int xmlParseRequest(maps **, const char *, map **, service *, maps **, maps **, HINTERNET *)
Parse XML request and store information in maps.
Definition: request_parser.c:1468
cwlPart::len
size_t len
Definition: request_parser.h:80
cwlPart::contentId
char * contentId
Definition: request_parser.h:76
maps
linked list of map pointer
Definition: service.h:738
CWL_ERR_NOMEM
@ CWL_ERR_NOMEM
Definition: request_parser.h:64
checkValidValue
void checkValidValue(map *, map **, const char *, const char **, int)
Verify if a parameter value is valid.
Definition: request_parser.c:1838
map
KVP linked list.
Definition: service.h:717
xmlParseOutputs
int xmlParseOutputs(maps **, map **, maps **, xmlDocPtr, xmlNodePtr, bool)
Parse outputs from XML nodes and store them in a maps.
Definition: request_parser.c:1265
parseCookie
void parseCookie(maps **, const char *)
Parse cookie contained in request headers.
Definition: request_parser.c:1950
CWL_ERR_INVALID
@ CWL_ERR_INVALID
Definition: request_parser.h:63
kvpParseOutputs
int kvpParseOutputs(maps **, map *, maps **)
Parse outputs provided as KVP and store them in a maps.
Definition: request_parser.c:387
ensureDecodedBase64
void ensureDecodedBase64(maps **)
Make sure that each value encoded in base64 in a maps is decoded.
Definition: request_parser.c:142
cwlStatus
cwlStatus
Result of the parsing helpers.
Definition: request_parser.h:61
extractMimeParam
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="<ma...
Definition: request_parser.c:2704
xmlParseInputs
int xmlParseInputs(maps **, service *, maps **, xmlDocPtr, xmlNodeSet *, HINTERNET *)
Parse inputs from XML nodes and store them in a maps.
Definition: request_parser.c:513
handleCwlMultipartDeploy
int handleCwlMultipartDeploy(maps *, const char *, size_t, const char *, const char *)
Handle the deployment of a CWL multipart request.
Definition: request_parser.c:2856
ulinet.h
parseRequest
int parseRequest(maps **, map **, service *, maps **, maps **, HINTERNET *)
Parse request and store information in maps.
Definition: request_parser.c:1577
kvpParseInputs
int kvpParseInputs(maps **, service *, map *, maps **, HINTERNET *)
Parse inputs provided as KVP and store them in a maps.
Definition: request_parser.c:198
HINTERNET
Multiple CURL handlers.
Definition: ulinet.h:96