ZOO-Project
response_print.h
Go to the documentation of this file.
1 /*
2  * Author : GĂ©rald FENOY
3  *
4  * Copyright (c) 2009-2023 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_RESPONSE_PRINT_H
26 #define ZOO_RESPONSE_PRINT_H 1
27 
28 #pragma once
29 
33 #define DEFAULT_SERVICE_URL "http://www.zoo-project.org/"
34 
37 #define TIME_SIZE 40
38 
39 #include <libintl.h>
40 #include <locale.h>
41 
45 #define _(String) dgettext ("zoo-kernel",String)
46 
49 #define _ss(String) dgettext ("zoo-services",String)
50 
54 #define ZOO_LOCK_CREATE_FAILED -4
55 
58 #define ZOO_LOCK_ACQUIRE_FAILED -5
59 
62 #define ZOO_LOCK_RELEASE_FAILED -6
63 
64 #include <sys/stat.h>
65 #include <sys/types.h>
66 #ifndef WIN32
67 #include <sys/ipc.h>
68 #include <sys/shm.h>
69 #include <sys/sem.h>
70 #else
71 #include <direct.h>
72 #endif
73 #include <stdio.h>
74 #include <time.h>
75 #include <ctype.h>
76 #ifdef WIN32
77 #ifndef USE_RUBY
78 #include <unistd.h>
79 #endif
80 #endif
81 #ifndef WIN32
82 //#include <locale.h>
83 #include <locale.h> // knut: this appears to be a non-standard header file that has been removed in newer versions of glibc; it may be sufficient to include <locale.h> (see above)
84 #endif
85 
86 #include "service.h"
87 #include <openssl/sha.h>
88 #include <openssl/md5.h>
89 #include <openssl/hmac.h>
90 #include <openssl/evp.h>
91 #include <openssl/bio.h>
92 #include <openssl/buffer.h>
93 
94 #include <libxml/parser.h>
95 #include <libxml/xpath.h>
96 
97 #ifdef __cplusplus
98 extern "C" {
99 #endif
100 
103 #define ZOO_NS_MAX 10
104 
107 #define ZOO_DOC_MAX 20
108 
112  static char* SERVICE_URL;
113 
117  static xmlNsPtr usedNs[ZOO_NS_MAX];
121  static char* nsName[ZOO_NS_MAX];
125  static int nbNs=0;
129  static xmlDocPtr iDocs[ZOO_DOC_MAX];
133  static int nbDocs=0;
134 
138  static char wpsStatus[3][11]={
139  "Succeeded",
140  "Failed",
141  "Running"
142  };
146  static const char* schemas[2][8]={
147  {"1.0.0","http://www.opengis.net/ows/1.1","http://www.opengis.net/wps/1.0.0","http://schemas.opengis.net/wps/1.0.0","%s %s/wps%s_response.xsd","http://schemas.opengis.net/ows/1.1.0/owsExceptionReport.xsd","1.1.0"},
148  {"2.0.0","http://www.opengis.net/ows/2.0","http://www.opengis.net/wps/2.0","http://schemas.opengis.net/wps/2.0","http://www.opengis.net/wps/2.0 http://schemas.opengis.net/wps/2.0/wps.xsd","http://schemas.opengis.net/ows/2.0/owsExceptionReport.xsd","2.0.2","http://www.opengis.net/spec/wps/2.0/def/process-profile/"},
149  };
153  static int nbSupportedRequests=7;
157  static const char* requests[2][7]={
158  {"GetCapabilities","DescribeProcess","Execute",NULL},
159  {"GetCapabilities","DescribeProcess","Execute","GetStatus","GetResult","Dismiss",NULL},
160  };
164  static int nbReqIdentifier=2;
168  static int nbReqJob=3;
172  static const char* root_nodes[2][4]={
173  {"ProcessOfferings","ProcessDescriptions","ExecuteResponse",NULL},
174  {"Contents","ProcessOfferings","Result",NULL}
175  };
176 
180  static const char* capabilities[2][7]={
181  {
182  "Process",
183  "processVersion","1",
184  "storeSupported","true",
185  "statusSupported","true"
186  },
187  {
188  "ProcessSummary",
189  "processVersion","1.0.0",
190  "jobControlOptions","sync-execute async-execute dismiss",
191  "outputTransmission","value reference"
192  }
193  };
194 
198  static const char* const aapccStatusCodes[][10] = {
199  {
200  "500 Not Implemented",
201  "OperationNotSupported",
202  "NoApplicableCode",
203  "InvalidQueryParameterValue",
204  NULL
205  },
206  {
207  "400 Bad request",
208  "MissingParameterValue",
209  "InvalidParameterValue",
210  "InvalidUpdateSequence",
211  "OptionNotSupported",
212  "VersionNegotiationFailed",
213  "NoSuchMode",
214  "BadRequest",
215  "WorkflowNotFound",
216  // ref. https://github.com/opengeospatial/ogcapi-processes/issues/250
217  //"InvalidQueryParameterValue",
218  NULL
219  },
220  {
221  "404 Not Found",
222  "NotFound",
223  "NoSuchProcess",
224  "NoSuchJob",
225  "ResultNotReady",
226  NULL
227  },
228  {
229  "500 Not Implemented",
230  NULL
231  }
232  };
233 
234  void addLangAttr(xmlNodePtr,maps*);
235 
236  void printHeaders(maps**);
237  void printSessionHeaders(maps**);
238  int printAFile(maps**,char*,zStatStruct,void (funcError) (maps**, map*));
239 
240  int zooXmlSearchForNs(const char*);
241  int zooXmlAddNs(xmlNodePtr,const char*,const char*);
242  void zooXmlCleanupNs();
243 
244  int zooXmlAddDoc(xmlNodePtr,const char*,const char*);
245  void zooXmlCleanupDocs();
246 
247  const char* produceStatusString(maps*,map*);
249  xmlNodePtr createExceptionReportNode(maps*,map*,int);
250  void printProcessResponse(maps**,map*,int,service*,const char*,int,maps*,maps*);
251  xmlNodePtr printWPSHeader(xmlDocPtr,maps*,const char*,const char*,const char*,int);
252  xmlNodePtr printGetCapabilitiesHeader(xmlDocPtr,maps*,const char*);
255  void printFullDescription(xmlDocPtr,int,elements*,const char*,xmlNsPtr,xmlNsPtr,xmlNodePtr,int,int,const map*);
256  void printDocument(maps**,xmlDocPtr,int);
257  void printDescription(xmlNodePtr,xmlNsPtr,const char*,map*,int);
258  void printIOType(xmlDocPtr,xmlNodePtr,xmlNsPtr,xmlNsPtr,xmlNsPtr,elements*,maps*,const char*,int);
259  void printRawdataOutput(maps**,maps*);
261  map* parseBoundingBox(const char*);
262  void printBoundingBox(xmlNsPtr,xmlNodePtr,map*);
263  void printBoundingBoxDocument(maps*,maps*,FILE*);
264  void printOutputDefinitions(xmlDocPtr,xmlNodePtr,xmlNsPtr,xmlNsPtr,elements*,maps*,const char*);
265  void printStatusInfo(maps*,map*,char*);
266  void addAdditionalParameters(map*,xmlDocPtr,xmlNodePtr,xmlNsPtr,xmlNsPtr,int);
267  void addMetadata(map*,xmlDocPtr,xmlNodePtr,xmlNsPtr,xmlNsPtr,int);
268 
269  char* produceFileUrl(service*,maps*,maps*,const char*, int);
270  void outputResponse(service*,maps*,maps*,map*,int,maps**,int);
271 
272  void localPrintException(maps**,map*);
273  int errorException(maps**, const char *, const char *, const char*);
274 
275  xmlNodePtr soapEnvelope(maps*,xmlNodePtr);
276  int checkForSoapEnvelope(xmlDocPtr);
277 
278 #ifdef __cplusplus
279 }
280 #endif
281 
282 #endif
zooXmlAddNs
int zooXmlAddNs(xmlNodePtr, const char *, const char *)
Add an XML namespace to the usedNS if it was not already used.
Definition: response_print.c:273
printRawdataOutput
void printRawdataOutput(maps **, maps *)
Print one outputs as raw.
Definition: response_print.c:3218
printSessionHeaders
void printSessionHeaders(maps **)
Print the Set-Cookie header if necessary (conf["lenv"]["cookie"]) and save the session file.
Definition: response_print.c:148
printDescription
void printDescription(xmlNodePtr, xmlNsPtr, const char *, map *, int)
Create XML node with basic ows metadata information (Identifier,Title,Abstract)
Definition: response_print.c:2561
wpsStatus
static char wpsStatus[3][11]
Definitions of acceptable final status.
Definition: response_print.h:138
SERVICE_URL
static char * SERVICE_URL
Global char* to store the serverAddress value of the [main] section.
Definition: response_print.h:112
service.h
printBoundingBoxDocument
void printBoundingBoxDocument(maps *, maps *, FILE *)
Print an ows:BoundingBox XML document.
Definition: response_print.c:3408
printExceptionReportResponse
void printExceptionReportResponse(maps **, map *)
Print an OWS ExceptionReport or exception.yaml Document and HTTP headers (when required) depending on...
Definition: response_print.c:2678
printOutputDefinitions
void printOutputDefinitions(xmlDocPtr, xmlNodePtr, xmlNsPtr, xmlNsPtr, elements *, maps *, const char *)
Print a XML document.
Definition: response_print.c:2264
soapEnvelope
xmlNodePtr soapEnvelope(maps *, xmlNodePtr)
Generate a SOAP Envelope node when required (if the isSoap key of the [main] section is set to true).
Definition: response_print.c:349
outputResponse
void outputResponse(service *, maps *, maps *, map *, int, maps **, int)
Generate the output response (RawDataOutput or ResponseDocument)
Definition: response_print.c:2929
ZOO_DOC_MAX
#define ZOO_DOC_MAX
Maximum number of XML docs.
Definition: response_print.h:107
aapccStatusCodes
static const char *const aapccStatusCodes[][10]
Correspondance between HTTP status code and exception code.
Definition: response_print.h:198
nbReqJob
static int nbReqJob
Definitions requests requiring jobid (only for WPS version 2.0.0)
Definition: response_print.h:168
service
Metadata information about a full Service.
Definition: service.h:715
elements
Metadata information about input or output.
Definition: service.h:700
printProcessResponse
void printProcessResponse(maps **, map *, int, service *, const char *, int, maps *, maps *)
Generate a wps:Execute XML document.
Definition: response_print.c:1908
produceFileUrl
char * produceFileUrl(service *, maps *, maps *, const char *, int)
Produce a copy file and the corresponding url in case it is required Please, free the returned ressou...
Definition: response_print.c:2825
ZOO_NS_MAX
#define ZOO_NS_MAX
Maximum number of XML namespaces.
Definition: response_print.h:103
printWPSHeader
xmlNodePtr printWPSHeader(xmlDocPtr, maps *, const char *, const char *, const char *, int)
Generate a WPS header.
Definition: response_print.c:383
createExceptionReportNode
xmlNodePtr createExceptionReportNode(maps *, map *, int)
Create an OWS ExceptionReport Node.
Definition: response_print.c:2698
printStatusInfo
void printStatusInfo(maps *, map *, char *)
Print a StatusInfo XML document.
Definition: response_print.c:3472
root_nodes
static const char * root_nodes[2][4]
Definitions of root node for response depending on the request and the WPS version.
Definition: response_print.h:172
printGetCapabilitiesHeader
xmlNodePtr printGetCapabilitiesHeader(xmlDocPtr, maps *, const char *)
Generate a Capabilities header.
Definition: response_print.c:481
printHeaders
void printHeaders(maps **)
Print the HTTP headers based on a map.
Definition: response_print.c:117
printAFile
int printAFile(maps **, char *, zStatStruct, void(funcError)(maps **, map *))
Print a file red as binary.
Definition: response_print.c:53
printDocument
void printDocument(maps **, xmlDocPtr, int)
Print a XML document.
Definition: response_print.c:2228
usedNs
static xmlNsPtr usedNs[ZOO_NS_MAX]
Array of xmlNsPtr storing all used XML namespace.
Definition: response_print.h:117
maps
linked list of map pointer
Definition: service.h:678
nbReqIdentifier
static int nbReqIdentifier
Definitions requests requiring identifier (depending on the WPS version)
Definition: response_print.h:164
nsName
static char * nsName[ZOO_NS_MAX]
Array storing names of the used XML namespace.
Definition: response_print.h:121
zooXmlSearchForNs
int zooXmlSearchForNs(const char *)
Search for an existing XML namespace in usedNS.
Definition: response_print.c:254
nbDocs
static int nbDocs
Number of XML docs.
Definition: response_print.h:133
zooXmlAddDoc
int zooXmlAddDoc(xmlNodePtr, const char *, const char *)
checkForSoapEnvelope
int checkForSoapEnvelope(xmlDocPtr)
printRawdataOutputs
void printRawdataOutputs(maps **, service *, maps *)
Print all outputs as raw.
Definition: response_print.c:3123
map
KVP linked list.
Definition: service.h:657
printIOType
void printIOType(xmlDocPtr, xmlNodePtr, xmlNsPtr, xmlNsPtr, xmlNsPtr, elements *, maps *, const char *, int)
Generate XML nodes describing inputs or outputs metadata.
Definition: response_print.c:2308
parseBoundingBox
map * parseBoundingBox(const char *)
Parse a BoundingBox string.
Definition: response_print.c:3355
errorException
int errorException(maps **, const char *, const char *, const char *)
Print an OWS ExceptionReport.
Definition: response_print.c:2796
nbNs
static int nbNs
Number of XML namespaces.
Definition: response_print.h:125
printDescribeProcessForProcess
void printDescribeProcessForProcess(registry *, maps *, void *, void *, service *)
Generate a ProcessDescription node for a servie and add it to a given node.
Definition: response_print.c:1112
produceStatusString
const char * produceStatusString(maps *, map *)
Produce the status string used in HTTP headers.
Definition: response_print.c:2594
zooXmlCleanupDocs
void zooXmlCleanupDocs()
Free allocated memort to store XML documents.
Definition: response_print.c:332
zooXmlCleanupNs
void zooXmlCleanupNs()
Free allocated memory to store used XML namespace.
Definition: response_print.c:298
schemas
static const char * schemas[2][8]
Definitions of schemas depending on the WPS version.
Definition: response_print.h:146
printGetCapabilitiesForProcess
void printGetCapabilitiesForProcess(registry *, maps *, void *, void *, service *)
Generate a wps:Process node for a servie and add it to a given node.
Definition: response_print.c:746
addLangAttr
void addLangAttr(xmlNodePtr, maps *)
Add a land attribute to a XML node.
Definition: response_print.c:210
registry
Profile registry.
Definition: service.h:735
iDocs
static xmlDocPtr iDocs[ZOO_DOC_MAX]
Array of xmlDocPtr storing XML docs.
Definition: response_print.h:129
addAdditionalParameters
void addAdditionalParameters(map *, xmlDocPtr, xmlNodePtr, xmlNsPtr, xmlNsPtr, int)
Add AdditionalParameters nodes to any existing node.
Definition: response_print.c:953
addMetadata
void addMetadata(map *, xmlDocPtr, xmlNodePtr, xmlNsPtr, xmlNsPtr, int)
Add a Metadata node to any existing node.
Definition: response_print.c:864
printBoundingBox
void printBoundingBox(xmlNsPtr, xmlNodePtr, map *)
Create required XML nodes for boundingbox and update the current XML node.
Definition: response_print.c:3303
requests
static const char * requests[2][7]
Definitions of requests depending on the WPS version.
Definition: response_print.h:157
nbSupportedRequests
static int nbSupportedRequests
Definitions of support requests (depending on the WPS version)
Definition: response_print.h:153
capabilities
static const char * capabilities[2][7]
Name and corresponding attributes depending on the WPS version.
Definition: response_print.h:180
localPrintException
void localPrintException(maps **, map *)
Invoke the ensureFiltered then printExceptionReportResponseJ functions.
Definition: response_print.c:2777
zStatStruct
#define zStatStruct
Definition: service.h:155
printFullDescription
void printFullDescription(xmlDocPtr, int, elements *, const char *, xmlNsPtr, xmlNsPtr, xmlNodePtr, int, int, const map *)
Generate the required XML tree for the detailled metadata information of inputs or outputs.
Definition: response_print.c:1231