ZOO-Project
Functions
response_print.c File Reference
#include "cpl_vsi.h"
#include "service.h"
#include "service_internal.h"
#include "server_internal.h"
#include "response_print.h"
#include <dlfcn.h>
#include "mimetypes.h"
#include "service_json.h"

Functions

void addPrefix (maps *pmsConf, map *pmLevel, service *psService)
 Add prefix to the service name. More...
 
void printHeaders (maps *pmsConf)
 Print the HTTP headers based on a map. More...
 
void printSessionHeaders (maps *pmsConf)
 Print the Set-Cookie header if necessary (conf["lenv"]["cookie"]) and save the session file. More...
 
void addLangAttr (xmlNodePtr n, maps *m)
 Add a land attribute to a XML node. More...
 
char * zCapitalize1 (char *tmp)
 Replace the first letter by its upper case version in a new char array. More...
 
char * zCapitalize (char *tmp)
 Replace all letters by their upper case version in a new char array. More...
 
int zooXmlSearchForNs (const char *name)
 Search for an existing XML namespace in usedNS. More...
 
int zooXmlAddNs (xmlNodePtr nr, const char *url, const char *name)
 Add an XML namespace to the usedNS if it was not already used. More...
 
void zooXmlCleanupNs ()
 Free allocated memory to store used XML namespace. More...
 
int zooXmlAddDoc (const char *value)
 Add a XML document to the iDocs. More...
 
void zooXmlCleanupDocs ()
 Free allocated memort to store XML documents. More...
 
xmlNodePtr soapEnvelope (maps *conf, xmlNodePtr n)
 Generate a SOAP Envelope node when required (if the isSoap key of the [main] section is set to true). More...
 
xmlNodePtr printWPSHeader (xmlDocPtr doc, maps *m, const char *req, const char *rname, const char *version, int reqId)
 Generate a WPS header. More...
 
void addLanguageNodes (maps *conf, xmlNodePtr n, xmlNsPtr ns, xmlNsPtr ns_ows)
 
xmlNodePtr printGetCapabilitiesHeader (xmlDocPtr doc, maps *m, const char *version="1.0.0")
 Generate a Capabilities header. More...
 
void printGetCapabilitiesForProcess (registry *reg, maps *m, void *doc0, void *nc0, service *serv)
 Generate a wps:Process node for a servie and add it to a given node. More...
 
void attachAttributes (xmlNodePtr n, xmlNsPtr ns, map *content, int vid, map *serviceType)
 Attach attributes to a ProcessDescription or a ProcessOffering node. More...
 
void addMetadata (map *meta, xmlDocPtr doc, xmlNodePtr nc, xmlNsPtr ns_ows, xmlNsPtr ns_xlink, int vid)
 Add a Metadata node to any existing node. More...
 
void addAdditionalParameters (map *meta, xmlDocPtr doc, xmlNodePtr nc, xmlNsPtr ns_ows, xmlNsPtr ns_xlink, int fromDb)
 Add AdditionalParameters nodes to any existing node. More...
 
void addInheritedMetadata (xmlNodePtr n, xmlNsPtr ns_ows, xmlNsPtr ns_xlink, registry *reg, maps *main_conf, service *serv)
 Add the ows:Metadata nodes relative to the profile registry. More...
 
void printDescribeProcessForProcess (registry *reg, maps *m, void *doc0, void *nc0, service *serv)
 Generate a ProcessDescription node for a servie and add it to a given node. More...
 
void printFullDescription (xmlDocPtr doc, int in, elements *elem, const char *type, xmlNsPtr ns, xmlNsPtr ns_ows, xmlNodePtr nc1, int vid, int fromDb, const map *serviceType)
 Generate the required XML tree for the detailled metadata information of inputs or outputs. More...
 
void printProcessResponse (maps *m, map *request, int pid, service *serv, const char *service, int status, maps *inputs, maps *outputs)
 Generate a wps:Execute XML document. More...
 
void printDocument (maps *m, xmlDocPtr doc, int pid)
 Print a XML document. More...
 
void printOutputDefinitions (xmlDocPtr doc, xmlNodePtr nc, xmlNsPtr ns_wps, xmlNsPtr ns_ows, elements *e, maps *m, const char *type)
 Print a XML document. More...
 
void printIOType (xmlDocPtr doc, xmlNodePtr nc, xmlNsPtr ns_wps, xmlNsPtr ns_ows, xmlNsPtr ns_xlink, elements *e, maps *m, const char *type, int vid)
 Generate XML nodes describing inputs or outputs metadata. More...
 
void printDescription (xmlNodePtr root, xmlNsPtr ns_ows, const char *identifier, map *amap, int vid=0)
 Create XML node with basic ows metadata information (Identifier,Title,Abstract) More...
 
const char * produceStatusString (maps *pmConf, map *pmCode)
 Produce the status string used in HTTP headers. More...
 
void _printExceptionReportResponse (maps *m, map *s)
 Print an OWS ExceptionReport Document and HTTP headers (when required) depending on the code. More...
 
void printExceptionReportResponse (maps *pmsConf, map *psService)
 Print an OWS ExceptionReport or exception.yaml Document and HTTP headers (when required) depending on the code. More...
 
xmlNodePtr createExceptionReportNode (maps *m, map *s, int use_ns)
 Create an OWS ExceptionReport Node. More...
 
int errorException (maps *m, const char *message, const char *errorcode, const char *locator)
 Print an OWS ExceptionReport. More...
 
char * produceFileUrl (service *psService, maps *pmsConf, maps *pmsOutputs, const char *pccFormat, int itn)
 Produce a copy file and the corresponding url in case it is required Please, free the returned ressource while used. More...
 
void outputResponse (service *s, maps *request_inputs, maps *request_outputs, map *request_inputs1, int cpid, maps *m, int res)
 Generate the output response (RawDataOutput or ResponseDocument) More...
 
void * printRawdataOutput (maps *conf, maps *outputs)
 Print one outputs as raw. More...
 
void printBoundingBox (xmlNsPtr ns_ows, xmlNodePtr n, map *boundingbox)
 Create required XML nodes for boundingbox and update the current XML node. More...
 
mapparseBoundingBox (const char *value)
 Parse a BoundingBox string. More...
 
void printBoundingBoxDocument (maps *m, maps *boundingbox, FILE *file)
 Print an ows:BoundingBox XML document. More...
 
void printStatusInfo (maps *conf, map *statusInfo, char *req)
 Print a StatusInfo XML document. More...
 

Function Documentation

void _printExceptionReportResponse ( maps m,
map s 
)

Print an OWS ExceptionReport Document and HTTP headers (when required) depending on the code.

Set hasPrinted value to true in the [lenv] section.

Parameters
mthe maps containing the settings of the main.cfg file
sthe map containing the text,code,locator keys (or a map array of the same keys)
void addAdditionalParameters ( map meta,
xmlDocPtr  doc,
xmlNodePtr  nc,
xmlNsPtr  ns_ows,
xmlNsPtr  ns_xlink,
int  fromDb 
)

Add AdditionalParameters nodes to any existing node.

Parameters
metathe map defining the additional parameters
docthe XML document used
nbthe node to add the additional parameters
ns_owsthe OWS namespace
ns_xlinkthe xlink namespace
fromDb1 if the metadata has been extracted from the metadb, 0 otherwise
void addInheritedMetadata ( xmlNodePtr  n,
xmlNsPtr  ns_ows,
xmlNsPtr  ns_xlink,
registry reg,
maps main_conf,
service serv 
)

Add the ows:Metadata nodes relative to the profile registry.

Parameters
nthe XML node to add the ows:Metadata
ns_owsthe ows XML namespace
ns_xlinkthe ows xlink namespace
regthe profile registry
main_confthe map containing the main configuration content
servthe service
void addLangAttr ( xmlNodePtr  n,
maps m 
)

Add a land attribute to a XML node.

Parameters
nthe XML node to add the attribute
mthe map containing the language key to add as xml:lang
void addLanguageNodes ( maps conf,
xmlNodePtr  n,
xmlNsPtr  ns,
xmlNsPtr  ns_ows 
)
void addMetadata ( map meta,
xmlDocPtr  doc,
xmlNodePtr  nc,
xmlNsPtr  ns_ows,
xmlNsPtr  ns_xlink,
int  vid 
)

Add a Metadata node to any existing node.

Parameters
metathe map defining the additional parameters
docthe XML document used
nbthe node to add the additional parameters
ns_owsthe OWS namespace
ns_xlinkthe xlink namespace
vidthe version of WPS to use (0 for 1.0.0 and 1 for 2.0)
void addPrefix ( maps pmsConf,
map pmLevel,
service psService 
)

Add prefix to the service name.

Parameters
pmsConfthe conf maps containing the main.cfg settings
pmLevelthe map containing the level information
psServicethe service structure created from the zcfg file
void attachAttributes ( xmlNodePtr  n,
xmlNsPtr  ns,
map content,
int  vid,
map serviceType 
)

Attach attributes to a ProcessDescription or a ProcessOffering node.

Parameters
nthe XML node to attach the attributes to
nsthe XML namespace to create the attributes
contentthe servive main content created from the zcfg file
vidthe version identifier (0 for 1.0.0 and 1 for 2.0.0)
serviceTypestring containing the current service type
xmlNodePtr createExceptionReportNode ( maps m,
map s,
int  use_ns 
)

Create an OWS ExceptionReport Node.

Parameters
mthe conf maps
sthe map containing the text,code,locator keys
use_ns(0/1) choose if you want to generate an ExceptionReport or ows:ExceptionReport node respectively
Returns
the ExceptionReport/ows:ExceptionReport node
int errorException ( maps m,
const char *  message,
const char *  errorcode,
const char *  locator 
)

Print an OWS ExceptionReport.

Parameters
mthe conf maps
messagethe error message
errorcodethe error code
locatorthe potential locator
void outputResponse ( service s,
maps request_inputs,
maps request_outputs,
map request_inputs1,
int  cpid,
maps m,
int  res 
)

Generate the output response (RawDataOutput or ResponseDocument)

Parameters
sthe service structure containing the metadata information
request_inputsthe inputs provided to the service for execution
request_outputsthe outputs updated by the service execution
request_inputs1the map containing the HTTP request
cpidthe process identifier attached to a service execution
mthe conf maps containing the main.cfg settings
resthe value returned by the service execution

We get the requested output or fallback to the first one if the requested one is not present in the resulting outputs maps.

map* parseBoundingBox ( const char *  value)

Parse a BoundingBox string.

OGC 06-121r3: 10.2 Bounding box

Value is provided as : lowerCorner,upperCorner,crs,dimension Exemple : 189000,834000,285000,962000,urn:ogc:def:crs:OGC:1.3:CRS84

A map to store boundingbox information should 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

Note : support only 2D bounding box.

Parameters
valuethe char* containing the KVP bouding box
Returns
a map containing all the bounding box keys
void printBoundingBox ( xmlNsPtr  ns_ows,
xmlNodePtr  n,
map boundingbox 
)

Create required XML nodes for boundingbox and update the current XML node.

Parameters
ns_owsthe ows XML namespace
nthe XML node to update
boundingboxthe map containing the boundingbox definition
void printBoundingBoxDocument ( maps m,
maps boundingbox,
FILE *  file 
)

Print an ows:BoundingBox XML document.

Parameters
mthe maps containing the settings of the main.cfg file
boundingboxthe maps containing the boundingbox definition
filethe file to print the BoundingBox (if NULL then print on stdout)
See also
parseBoundingBox, printBoundingBox
void printDescribeProcessForProcess ( registry reg,
maps m,
void *  doc0,
void *  nc0,
service serv 
)

Generate a ProcessDescription node for a servie and add it to a given node.

Parameters
regthe profile registry
mthe conf maps containing the main.cfg settings
ncthe XML node to add the Process node
servthe servive structure created from the zcfg file
Returns
the generated wps:ProcessOfferings xmlNodePtr
void printDescription ( xmlNodePtr  root,
xmlNsPtr  ns_ows,
const char *  identifier,
map amap,
int  vid = 0 
)

Create XML node with basic ows metadata information (Identifier,Title,Abstract)

Parameters
rootthe root XML node to add the description
ns_owsthe ows XML namespace
identifierthe identifier to use
amapthe map containing the ows metadata information
void printDocument ( maps m,
xmlDocPtr  doc,
int  pid 
)

Print a XML document.

Parameters
mthe conf maps containing the main.cfg settings
docthe XML document
pidthe process identifier linked to a service
void printExceptionReportResponse ( maps pmsConf,
map psService 
)

Print an OWS ExceptionReport or exception.yaml Document and HTTP headers (when required) depending on the code.

Parameters
pmsConfthe maps containing the settings of the main.cfg file
psServicethe service
void printFullDescription ( xmlDocPtr  doc,
int  in,
elements elem,
const char *  type,
xmlNsPtr  ns,
xmlNsPtr  ns_ows,
xmlNodePtr  nc1,
int  vid,
int  fromDb,
const map serviceType 
)

Generate the required XML tree for the detailled metadata information of inputs or outputs.

Parameters
in1 in case of inputs, 0 for outputs
elemthe elements structure containing the metadata information
typethe name ("Input" or "Output") of the XML node to create
ns_owsthe ows XML namespace
ns_owsthe ows XML namespace
nc1the XML node to use to add the created tree
vidthe WPS version id (0 for 1.0.0, 1 for 2.0.0)
fromDb1 in case the metadata comes from the DB, -1 in other cases
serviceTypethe serviceType found in the ZCFG file or the DB

Range: Table 46 OGC Web Services Common Standard

RangeClosure: Table 47 OGC Web Services Common Standard

void printGetCapabilitiesForProcess ( registry reg,
maps m,
void *  doc0,
void *  nc0,
service serv 
)

Generate a wps:Process node for a servie and add it to a given node.

Parameters
regthe profiles registry
mthe conf maps containing the main.cfg settings
registrythe profile registry if any
ncthe XML node to add the Process node
servthe service structure created from the zcfg file
Returns
the generated wps:ProcessOfferings xmlNodePtr
xmlNodePtr printGetCapabilitiesHeader ( xmlDocPtr  doc,
maps m,
const char *  version = "1.0.0" 
)

Generate a Capabilities header.

Parameters
docthe document to add the header
mthe conf maps containing the main.cfg settings
Returns
the generated wps:ProcessOfferings xmlNodePtr
void printHeaders ( maps pmsConf)

Print the HTTP headers based on a map.

Parameters
pmsConfthe map containing the headers information
void printIOType ( xmlDocPtr  doc,
xmlNodePtr  nc,
xmlNsPtr  ns_wps,
xmlNsPtr  ns_ows,
xmlNsPtr  ns_xlink,
elements e,
maps m,
const char *  type,
int  vid 
)

Generate XML nodes describing inputs or outputs metadata.

Parameters
docthe XML document
ncthe XML node to add the definition
ns_wpsthe wps namespace
ns_owsthe ows namespace
ns_xlinkthe xlink namespace
ethe output elements
mthe conf maps containing the main.cfg settings
typethe type
void printOutputDefinitions ( xmlDocPtr  doc,
xmlNodePtr  nc,
xmlNsPtr  ns_wps,
xmlNsPtr  ns_ows,
elements e,
maps m,
const char *  type 
)

Print a XML document.

Parameters
docthe XML document (unused)
ncthe XML node to add the output definition
ns_wpsthe wps XML namespace
ns_owsthe ows XML namespace
ethe output elements
mthe conf maps containing the main.cfg settings
typethe type (unused)
void printProcessResponse ( maps m,
map request,
int  pid,
service serv,
const char *  service,
int  status,
maps inputs,
maps outputs 
)

Generate a wps:Execute XML document.

Parameters
mthe conf maps containing the main.cfg settings
requestthe map representing the HTTP request
pidthe process identifier linked to a service
servthe serv structure created from the zcfg file
servicethe service name
statusthe status returned by the service
inputsthe inputs provided
outputsthe outputs generated by the service

Check if the ZOO Service GetStatus is available in the local directory. If yes, then it uses a reference to an URL which the client can access to get information on the status of a running Service (using the percentCompleted attribute). Else fallback to the initial method using the xml file to write in ...

Display the process output only when requested !

In case there was no definition found in the ZCFG file but present in the service code

void* printRawdataOutput ( maps conf,
maps outputs 
)

Print one outputs as raw.

Parameters
confthe main configuration maps
outputsthe output to be print as raw
void printSessionHeaders ( maps pmsConf)

Print the Set-Cookie header if necessary (conf["lenv"]["cookie"]) and save the session file.

The session file (sess_<SESSID>_.cfg where <SESSID> is the cookie value) is stored in the conf["main"]["tmpPath"] directory.

Parameters
pmsConfthe main configuration map
void printStatusInfo ( maps conf,
map statusInfo,
char *  req 
)

Print a StatusInfo XML document.

a statusInfo map should contain the following keys:

  • JobID corresponding to usid key from the lenv section
  • Status the current state (Succeeded,Failed,Accepted,Running)
  • PercentCompleted (optional) the percent completed
  • Message (optional) any messages the service may wish to share
Parameters
confthe maps containing the settings of the main.cfg file
statusInfothe map containing the statusInfo definition
reqthe WPS requests (GetResult, GetStatus or Dismiss)
xmlNodePtr printWPSHeader ( xmlDocPtr  doc,
maps m,
const char *  req,
const char *  rname,
const char *  version,
int  reqId 
)

Generate a WPS header.

Parameters
docthe document to add the header
mthe conf maps containing the main.cfg settings
reqthe request type (GetCapabilities,DescribeProcess,Execute)
rnamethe root node name
Returns
the generated wps:rname xmlNodePtr (can be wps: Capabilities, wps:ProcessDescriptions,wps:ExecuteResponse)
char* produceFileUrl ( service psService,
maps pmsConf,
maps pmsOutputs,
const char *  pccFormat,
int  itn 
)

Produce a copy file and the corresponding url in case it is required Please, free the returned ressource while used.

Parameters
pmConfmaps* pointing to the main configuration file
const char* produceStatusString ( maps pmConf,
map pmCode 
)

Produce the status string used in HTTP headers.

Parameters
pmConfthe maps containing the settings of the main.cfg file
pmCodethe map containing the error code (or a map array of the same keys)
xmlNodePtr soapEnvelope ( maps conf,
xmlNodePtr  n 
)

Generate a SOAP Envelope node when required (if the isSoap key of the [main] section is set to true).

Parameters
confthe conf maps containing the main.cfg settings
nthe node used as children of the generated soap:Envelope
Returns
the generated soap:Envelope (if isSoap=true) or the input node n (when isSoap=false)
char* zCapitalize ( char *  tmp)

Replace all letters by their upper case version in a new char array.

Parameters
tmpthe char*
Returns
a new char* with first letter in upper case
Warning
be sure to free() the returned string after use
char* zCapitalize1 ( char *  tmp)

Replace the first letter by its upper case version in a new char array.

Parameters
tmpthe char*
Returns
a new char* with first letter in upper case
Warning
be sure to free() the returned string after use
int zooXmlAddDoc ( const char *  value)

Add a XML document to the iDocs.

Parameters
valuethe string containing the XML document
Returns
the index of the XML document added.
int zooXmlAddNs ( xmlNodePtr  nr,
const char *  url,
const char *  name 
)

Add an XML namespace to the usedNS if it was not already used.

Parameters
nrthe xmlNodePtr to attach the XML namspace (can be NULL)
urlthe url of the XML namespace to add
namethe name of the XML namespace to add
Returns
the index of the XML namespace added.
void zooXmlCleanupDocs ( )

Free allocated memort to store XML documents.

void zooXmlCleanupNs ( )

Free allocated memory to store used XML namespace.

int zooXmlSearchForNs ( const char *  name)

Search for an existing XML namespace in usedNS.

Parameters
namethe name of the XML namespace to search
Returns
the index of the XML namespace found or -1 if not found.