ZOO-Project
Macros | Functions
server_internal.c File Reference
#include "server_internal.h"
#include "service_internal.h"
#include "response_print.h"
#include "mimetypes.h"
#include <dlfcn.h>
#include <uuid/uuid.h>
#include <signal.h>
#include <dirent.h>

Macros

#define PATHBUFSIZE   4096
 

Functions

int zoo_path_compare (char *path1, char *path2)
 
int getVersionId (const char *version)
 Detect WPS version used (1.0.0 or 2.0.0). More...
 
char * get_uuid ()
 Generate a UUID. More...
 
void parseIdentifier (maps *conf, char *conf_dir, char *identifier, char *buffer)
 Extract the service identifier from the full service identifier ie: More...
 
char from_hex (char ch)
 Converts a hex character to its integer value. More...
 
char to_hex (char code)
 Converts an integer value to its hec character. More...
 
char * url_encode (char *str)
 URLEncode an url. More...
 
char * url_decode (char *str)
 Decode an URLEncoded url. More...
 
int isValidLang (maps *conf, const char *str)
 Verify if a given language is listed in the lang list defined in the [main] section of the main.cfg file. More...
 
char * getEncoding (maps *m)
 Access the value of the encoding key in a maps. More...
 
char * getVersion (maps *m)
 Access the value of the version key in a maps. More...
 
void readGeneratedFile (maps *m, map *content, char *filename)
 Read a file generated by a service. More...
 
int writeFile (char *fname, char *val, int length)
 Write a file from value and length. More...
 
void dumpMapsValuesToFiles (maps **main_conf, maps **in)
 Dump all values in a maps as files. More...
 
char * base64 (const char *input, int length)
 Base64 encoding of a char*. More...
 
char * base64d (const char *input, int length, int *red)
 Base64 decoding of a char*. More...
 
void readBase64 (map **in)
 Read Base64 value and split it value by lines of 64 char. More...
 
char * addDefaultValues (maps **out, elements *in, maps *m, int type, map **err)
 Add the default values defined in the zcfg to a maps. More...
 
char * getLastErrorMessage ()
 Access the last error message returned by the OS when trying to dynamically load a shared library. More...
 
void readFinalRes (maps *conf, char *pid, map *statusInfo)
 Read the Result file (.res). More...
 
int isRunning (maps *conf, char *pid)
 Check if a service is running. More...
 
void runGetStatus (maps **ppmsConf, char *pid, char *req)
 Run GetStatus requests. More...
 
void removeSubdirectory (maps *pmsConf, char *acDirectoryName)
 Remove a directory and its content. More...
 
void runDismiss (maps *pmsConf, char *pid)
 Run Dismiss requests. More...
 
int getServiceFromFile (maps *, const char *, service **)
 Parse a ZCFG file and fill the service structure. More...
 
int readServiceFile (maps *pmsConf, char *file, service **service, char *name)
 Parse the service file using getServiceFromFile or use getServiceFromYAML if YAML support was activated. More...
 
int createRegistry (maps *m, registry **r, char *reg_dir)
 Create the profile registry. More...
 
char * produceErrorMessage (maps *pmsConf)
 Create a string containing the basic error message. More...
 
int getServicesNamespacePath (maps *pmsConf, char *oldPath, char *newPath, int maxSize)
 Checks if the zooServicesNamespace map is present in the main map; if it is, the path to the directory where the ZOO-kernel should search for service providers will be updated. More...
 

Macro Definition Documentation

◆ PATHBUFSIZE

#define PATHBUFSIZE   4096

Function Documentation

◆ addDefaultValues()

char* addDefaultValues ( maps **  out,
elements in,
maps m,
int  type,
map **  err 
)

Add the default values defined in the zcfg to a maps.

Parameters
outthe maps containing the inputs or outputs given in the initial HTTP request
inthe description of all inputs or outputs available for a service
mthe maps containing the settings of the main.cfg file
type0 for inputs and 1 for outputs
errthe map to store potential missing mandatory input parameters or wrong output names depending on the type.
Returns
"" if no error was detected, the name of last input or output causing an error.

In case of an Input maps, then add the minOccurs and maxOccurs to the content map.

Parsing BoundingBoxData, fill the following map and then add it to the content map of the Input maps: lowerCorner, upperCorner, srs and dimensions cf. parseBoundingBox

◆ base64()

char* base64 ( const char *  input,
int  length 
)

Base64 encoding of a char*.

Parameters
inputthe value to encode
lengththe value length
Returns
the buffer containing the base64 value
Warning
make sure to free the returned value

◆ base64d()

char* base64d ( const char *  input,
int  length,
int *  red 
)

Base64 decoding of a char*.

Parameters
inputthe value to decode
lengththe value length
redthe value length
Returns
the buffer containing the base64 value
Warning
make sure to free the returned value

◆ createRegistry()

int createRegistry ( maps m,
registry **  r,
char *  reg_dir 
)

Create the profile registry.

The profile registry is optional (created only if the registry key is available in the [main] section of the main.cfg file) and can be used to store the profiles hierarchy. The registry is a directory which should contain the following sub-directories:

  • concept: direcotry containing .html files describing concept
  • generic: directory containing .zcfg files for wps:GenericProcess
  • implementation: directory containing .zcfg files for wps:Process
Parameters
mthe conf maps containing the main.cfg settings
rthe registry to update
reg_dirthe resgitry
Returns
0 if the resgitry is null or was correctly updated, -1 on failure

◆ dumpMapsValuesToFiles()

void dumpMapsValuesToFiles ( maps **  main_conf,
maps **  in 
)

Dump all values in a maps as files.

Parameters
main_confthe maps containing the settings of the main.cfg file
inthe maps containing values to dump as files

◆ from_hex()

char from_hex ( char  ch)

Converts a hex character to its integer value.

Parameters
chthe char to convert
Returns
the converted char

◆ get_uuid()

char* get_uuid ( )

Generate a UUID.

ref: https://www.ietf.org/rfc/rfc4122.txt / 4.2

Returns
a new char* containing the UUID, make sure to free the returned resource once used.

◆ getEncoding()

char* getEncoding ( maps m)

Access the value of the encoding key in a maps.

Parameters
mthe maps to search for the encoding key
Returns
the value of the encoding key in a maps if encoding key exists, "UTF-8" in other case.

◆ getLastErrorMessage()

char* getLastErrorMessage ( )

Access the last error message returned by the OS when trying to dynamically load a shared library.

Returns
the last error message
Warning
The character string returned from getLastErrorMessage resides in a static buffer. The application should not write to this buffer or attempt to free() it.

◆ getServiceFromFile()

int getServiceFromFile ( maps conf,
const char *  file,
service **  service 
)

Parse a ZCFG file and fill the service structure.

Parameters
confthe conf maps containing the main.cfg settings
filethe fullpath to the ZCFG file
servicethe service structure to fill
Returns
0 on success, -1 on failure

◆ getServicesNamespacePath()

int getServicesNamespacePath ( maps pmsConf,
char *  oldPath,
char *  newPath,
int  maxSize 
)

Checks if the zooServicesNamespace map is present in the main map; if it is, the path to the directory where the ZOO-kernel should search for service providers will be updated.

Parameters
pmsConfthe conf maps containing the main.cfg settings
oldPathdefault location where the ZOO-kernel should search for service providers
newPathlocation where the ZOO-kernel should search for service providers considering the namespace
maxSizemaximum number of bytes to be used in the newPath buffer.

◆ getVersion()

char* getVersion ( maps m)

Access the value of the version key in a maps.

Parameters
mthe maps to search for the version key
Returns
the value of the version key in a maps if encoding key exists, "1.0.0" in other case.

◆ getVersionId()

int getVersionId ( const char *  version)

Detect WPS version used (1.0.0 or 2.0.0).

Parameters
versionnumber as char* (1.0.0 or 2.0.0)
Returns
0 in case of version 1.0.0, 1 for 2.0.0, -1 in other case

◆ isRunning()

int isRunning ( maps conf,
char *  pid 
)

Check if a service is running.

Parameters
confthe maps containing the setting of the main.cfg file
pidthe unique service identifier (usid from the lenv section)
Returns
1 in case the service is still running, 0 otherwise

◆ isValidLang()

int isValidLang ( maps conf,
const char *  str 
)

Verify if a given language is listed in the lang list defined in the [main] section of the main.cfg file.

Parameters
confthe map containing the settings from the main.cfg file
strthe specific language
Returns
1 if the specific language is listed, -1 in other case.

◆ parseIdentifier()

void parseIdentifier ( maps conf,
char *  conf_dir,
char *  identifier,
char *  buffer 
)

Extract the service identifier from the full service identifier ie:

  • Full service name: OTB.BandMath
  • Service name: BandMath
Parameters
confthe maps containing the settings of the main.cfg file
conf_dirthe full path to the ZOO-Kernel directory
identifierthe full service name (potentialy including a prefix, ie: Prefix.MyService)
bufferthe resulting service identifier (without any prefix)

◆ produceErrorMessage()

char* produceErrorMessage ( maps pmsConf)

Create a string containing the basic error message.

Parameters
pmsConfthe main configuration maps pointer
Returns
a new char* containing the error message (ressource should be freed)

◆ readBase64()

void readBase64 ( map **  in)

Read Base64 value and split it value by lines of 64 char.

Parameters
inthe map containing the value to split

◆ readFinalRes()

void readFinalRes ( maps conf,
char *  pid,
map statusInfo 
)

Read the Result file (.res).

Parameters
confthe maps containing the setting of the main.cfg file
pidthe service identifier (usid key from the [lenv] section)

◆ readGeneratedFile()

void readGeneratedFile ( maps m,
map content,
char *  filename 
)

Read a file generated by a service.

Parameters
mthe conf maps
contentthe output item
filenamethe file to read

◆ readServiceFile()

int readServiceFile ( maps pmsConf,
char *  file,
service **  service,
char *  name 
)

Parse the service file using getServiceFromFile or use getServiceFromYAML if YAML support was activated.

Parameters
pmsConfthe conf maps containing the main.cfg settings
filethe file name to parse
servicethe service to update witht the file content
namethe service name
Returns
true if the file can be parsed or false
See also
getServiceFromFile, getServiceFromYAML

◆ removeSubdirectory()

void removeSubdirectory ( maps pmsConf,
char *  acDirectoryName 
)

Remove a directory and its content.

@pmsConf the maps containing the setting of the main.cfg file @acDirectory the directory to remove

◆ runDismiss()

void runDismiss ( maps pmsConf,
char *  pid 
)

Run Dismiss requests.

Parameters
pmsConfthe maps containing the setting of the main.cfg file
pidthe service identifier (usid key from the [lenv] section)

◆ runGetStatus()

void runGetStatus ( maps **  ppmsConf,
char *  pid,
char *  req 
)

Run GetStatus requests.

Specifically for the OGC API - Processes - Part 1 - Core support, in case something wrong happens, the conf maps will get in the lenv section the following fields:

  • error: "true", indicating that something went wrong
  • code: the OGC error code (such as NoSuchJob)
  • message: the error message o be reported
Parameters
confthe maps containing the setting of the main.cfg file
pidthe service identifier (usid key from the [lenv] section)
reqthe request (GetStatus / GetResult)

◆ to_hex()

char to_hex ( char  code)

Converts an integer value to its hec character.

Parameters
codethe char to convert
Returns
the converted char

◆ url_decode()

char* url_decode ( char *  str)

Decode an URLEncoded url.

Parameters
strthe URLEncoded url to decode
Returns
a url-decoded version of str
Warning
be sure to free() the returned string after use

◆ url_encode()

char* url_encode ( char *  str)

URLEncode an url.

Parameters
strthe url to encode
Returns
a url-encoded version of str
Warning
be sure to free() the returned string after use

◆ writeFile()

int writeFile ( char *  fname,
char *  val,
int  length 
)

Write a file from value and length.

Parameters
fnamethe file name
valthe value
lengththe value length

◆ zoo_path_compare()

int zoo_path_compare ( char *  path1,
char *  path2 
)