ZOO-Project
response_print.h
Go to the documentation of this file.
1 /*
2  * Author : GĂ©rald FENOY
3  *
4  * Copyright (c) 2009-2013 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 #include "ulinet.h"
86 
87 #include "service.h"
88 #include <openssl/sha.h>
89 #include <openssl/md5.h>
90 #include <openssl/hmac.h>
91 #include <openssl/evp.h>
92 #include <openssl/bio.h>
93 #include <openssl/buffer.h>
94 
95 #include <libxml/parser.h>
96 #include <libxml/xpath.h>
97 
98 #include "cgic.h"
99 
100 #ifdef __cplusplus
101 extern "C" {
102 #endif
103 
106 #define ZOO_NS_MAX 10
107 
110 #define ZOO_DOC_MAX 20
111 
115  static char* SERVICE_URL;
116 
120  static xmlNsPtr usedNs[ZOO_NS_MAX];
124  static char* nsName[ZOO_NS_MAX];
128  static int nbNs=0;
132  static xmlDocPtr iDocs[ZOO_DOC_MAX];
136  static int nbDocs=0;
137 
141  static char wpsStatus[3][11]={
142  "Succeeded",
143  "Failed",
144  "Running"
145  };
149  static const char* schemas[2][8]={
150  {"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"},
151  {"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/"},
152  };
156  static int nbSupportedRequests=7;
160  static const char* requests[2][7]={
161  {"GetCapabilities","DescribeProcess","Execute",NULL},
162  {"GetCapabilities","DescribeProcess","Execute","GetStatus","GetResult","Dismiss",NULL},
163  };
167  static int nbReqIdentifier=2;
171  static int nbReqJob=3;
175  static const char root_nodes[2][4][20]={
176  {"ProcessOfferings","ProcessDescriptions","ExecuteResponse",NULL},
177  {"Contents","ProcessOfferings","Result",NULL}
178  };
179 
183  static const char* capabilities[2][7]={
184  {
185  "Process",
186  "processVersion","1",
187  "storeSupported","true",
188  "statusSupported","true"
189  },
190  {
191  "ProcessSummary",
192  "processVersion","1.0.0",
193  "jobControlOptions","sync-execute async-execute dismiss",
194  "outputTransmission","value reference"
195  }
196  };
197 
198  void addLangAttr(xmlNodePtr,maps*);
199 
200  void printHeaders(maps*);
201 
202  int zooXmlSearchForNs(const char*);
203  int zooXmlAddNs(xmlNodePtr,const char*,const char*);
204  void zooXmlCleanupNs();
205 
206  int zooXmlAddDoc(xmlNodePtr,const char*,const char*);
207  void zooXmlCleanupDocs();
208 
210  xmlNodePtr createExceptionReportNode(maps*,map*,int);
211  void printProcessResponse(maps*,map*,int,service*,const char*,int,maps*,maps*);
212  xmlNodePtr printWPSHeader(xmlDocPtr,maps*,const char*,const char*,const char*,int);
213  xmlNodePtr printGetCapabilitiesHeader(xmlDocPtr,maps*,const char*);
214  void printGetCapabilitiesForProcess(registry*,maps*,xmlDocPtr,xmlNodePtr,service*);
215  void printDescribeProcessForProcess(registry*,maps*,xmlDocPtr,xmlNodePtr,service*);
216  void printFullDescription(xmlDocPtr,int,elements*,const char*,xmlNsPtr,xmlNsPtr,xmlNodePtr,int,int,const map*);
217  void printDocument(maps*,xmlDocPtr,int);
218  void printDescription(xmlNodePtr,xmlNsPtr,const char*,map*,int);
219  void printIOType(xmlDocPtr,xmlNodePtr,xmlNsPtr,xmlNsPtr,xmlNsPtr,elements*,maps*,const char*,int);
220  map* parseBoundingBox(const char*);
221  void printBoundingBox(xmlNsPtr,xmlNodePtr,map*);
222  void printBoundingBoxDocument(maps*,maps*,FILE*);
223  void printOutputDefinitions(xmlDocPtr,xmlNodePtr,xmlNsPtr,xmlNsPtr,elements*,maps*,const char*);
224  void printStatusInfo(maps*,map*,char*);
225  void addAdditionalParameters(map*,xmlDocPtr,xmlNodePtr,xmlNsPtr,xmlNsPtr,int);
226  void addMetadata(map*,xmlDocPtr,xmlNodePtr,xmlNsPtr,xmlNsPtr,int);
227 
228  void outputResponse(service*,maps*,maps*,map*,int,maps*,int);
229 
230  int errorException(maps *, const char *, const char *, const char*);
231 
232  xmlNodePtr soapEnvelope(maps*,xmlNodePtr);
233  int checkForSoapEnvelope(xmlDocPtr);
234 
235 #ifdef __cplusplus
236 }
237 #endif
238 
239 #endif
#define ZOO_NS_MAX
Maximum number of XML namespaces.
Definition: response_print.h:106
xmlNodePtr printWPSHeader(xmlDocPtr, maps *, const char *, const char *, const char *, int)
Generate a WPS header.
Definition: response_print.c:287
void zooXmlCleanupDocs()
Free allocated memort to store XML documents.
Definition: response_print.c:236
static const char * schemas[2][8]
Definitions of schemas depending on the WPS version.
Definition: response_print.h:149
int zooXmlSearchForNs(const char *)
Search for an existing XML namespace in usedNS.
Definition: response_print.c:158
static const char root_nodes[2][4][20]
Definitions of root node for response depending on the request and the WPS version.
Definition: response_print.h:175
static xmlDocPtr iDocs[ZOO_DOC_MAX]
Array of xmlDocPtr storing XML docs.
Definition: response_print.h:132
void printIOType(xmlDocPtr, xmlNodePtr, xmlNsPtr, xmlNsPtr, xmlNsPtr, elements *, maps *, const char *, int)
Generate XML nodes describing inputs or outputs metadata.
Definition: response_print.c:2185
map * parseBoundingBox(const char *)
Parse a BoundingBox string.
Definition: response_print.c:3046
void outputResponse(service *, maps *, maps *, map *, int, maps *, int)
Generate the output response (RawDataOutput or ResponseDocument)
Definition: response_print.c:2642
int errorException(maps *, const char *, const char *, const char *)
Print an OWS ExceptionReport.
Definition: response_print.c:2617
static int nbNs
Number of XML namespaces.
Definition: response_print.h:128
static xmlNsPtr usedNs[ZOO_NS_MAX]
Array of xmlNsPtr storing all used XML namespace.
Definition: response_print.h:120
void zooXmlCleanupNs()
Free allocated memory to store used XML namespace.
Definition: response_print.c:202
static int nbSupportedRequests
Definitions of support requests (depending on the WPS version)
Definition: response_print.h:156
void addLangAttr(xmlNodePtr, maps *)
Add a land attribute to a XML node.
Definition: response_print.c:114
static int nbDocs
Number of XML docs.
Definition: response_print.h:136
void addAdditionalParameters(map *, xmlDocPtr, xmlNodePtr, xmlNsPtr, xmlNsPtr, int)
Add AdditionalParameters nodes to any existing node.
Definition: response_print.c:853
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:1129
int checkForSoapEnvelope(xmlDocPtr)
int zooXmlAddNs(xmlNodePtr, const char *, const char *)
Add an XML namespace to the usedNS if it was not already used.
Definition: response_print.c:177
static const char * requests[2][7]
Definitions of requests depending on the WPS version.
Definition: response_print.h:160
void printBoundingBoxDocument(maps *, maps *, FILE *)
Print an ows:BoundingBox XML document.
Definition: response_print.c:3099
linked list of map pointer
Definition: main_conf_read.y:285
static const char * capabilities[2][7]
Name and corresponding attributes depending on the WPS version.
Definition: response_print.h:183
void printOutputDefinitions(xmlDocPtr, xmlNodePtr, xmlNsPtr, xmlNsPtr, elements *, maps *, const char *)
Print a XML document.
Definition: response_print.c:2141
void printHeaders(maps *)
Print the HTTP headers based on a map.
Definition: response_print.c:97
void addMetadata(map *, xmlDocPtr, xmlNodePtr, xmlNsPtr, xmlNsPtr, int)
Add a Metadata node to any existing node.
Definition: response_print.c:766
static int nbReqJob
Definitions requests requiring jobid (only for WPS version 2.0.0)
Definition: response_print.h:171
KVP linked list.
Definition: service.h:237
static char wpsStatus[3][11]
Definitions of acceptable final status.
Definition: response_print.h:141
void printBoundingBox(xmlNsPtr, xmlNodePtr, map *)
Create required XML nodes for boundingbox and update the current XML node.
Definition: response_print.c:2994
void printDescription(xmlNodePtr, xmlNsPtr, const char *, map *, int)
Create XML node with basic ows metadata information (Identifier,Title,Abstract)
Definition: response_print.c:2432
static char * SERVICE_URL
Global char* to store the serverAddress value of the [main] section.
Definition: response_print.h:115
Metadata information about a full Service.
Definition: main_conf_read.y:322
void printProcessResponse(maps *, map *, int, service *, const char *, int, maps *, maps *)
Generate a wps:Execute XML document.
Definition: response_print.c:1787
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:253
Profile registry.
Definition: main_conf_read.y:342
void printDocument(maps *, xmlDocPtr, int)
Print a XML document.
Definition: response_print.c:2105
#define ZOO_DOC_MAX
Maximum number of XML docs.
Definition: response_print.h:110
void printExceptionReportResponse(maps *, map *)
Print an OWS ExceptionReport Document and HTTP headers (when required) depending on the code...
Definition: response_print.c:2467
void printGetCapabilitiesForProcess(registry *, maps *, xmlDocPtr, xmlNodePtr, service *)
Generate a wps:Process node for a servie and add it to a given node.
Definition: response_print.c:650
xmlNodePtr printGetCapabilitiesHeader(xmlDocPtr, maps *, const char *)
Generate a Capabilities header.
Definition: response_print.c:385
Metadata information about input or output.
Definition: main_conf_read.y:307
xmlNodePtr createExceptionReportNode(maps *, map *, int)
Create an OWS ExceptionReport Node.
Definition: response_print.c:2538
static int nbReqIdentifier
Definitions requests requiring identifier (depending on the WPS version)
Definition: response_print.h:167
static char * nsName[ZOO_NS_MAX]
Array storing names of the used XML namespace.
Definition: response_print.h:124
void printStatusInfo(maps *, map *, char *)
Print a StatusInfo XML document.
Definition: response_print.c:3163
int zooXmlAddDoc(xmlNodePtr, const char *, const char *)
void printDescribeProcessForProcess(registry *, maps *, xmlDocPtr, xmlNodePtr, service *)
Generate a ProcessDescription node for a servie and add it to a given node.
Definition: response_print.c:1011