ZOO-Project
Macros | Functions | Variables
zoo_service_loader.c File Reference
#include <libxml/tree.h>
#include <libxml/xmlmemory.h>
#include <libxml/parser.h>
#include <libxml/xpath.h>
#include <libxml/xpathInternals.h>
#include "ulinet.h"
#include <libintl.h>
#include <locale.h>
#include <string.h>
#include "service_internal.h"
#include "server_internal.h"
#include "response_print.h"
#include "request_parser.h"
#include "service.h"
#include "sqlapi.h"
#include <dirent.h>
#include <signal.h>
#include <execinfo.h>
#include <unistd.h>
#include <dlfcn.h>
#include <libgen.h>
#include <fcntl.h>
#include <time.h>
#include <stdarg.h>
#include <libxslt/xslt.h>
#include <libxslt/xsltInternals.h>
#include <libxslt/transform.h>
#include <libxslt/xsltutils.h>
#include "cgic.h"

Macros

#define _(String)   dgettext ("zoo-kernel",String)
 Translation function for zoo-kernel. More...
 
#define __(String)   dgettext ("zoo-service",String)
 Translation function for zoo-service. More...
 
#define localPrintExceptionJ   localPrintException
 

Functions

int yylex ()
 
int crlex ()
 
void cleanUpSql (maps *pmsConf)
 Close any sql backend connexion and call end_sql. More...
 
void translateChar (char *pcOrigin, char cToReplace, char cToReplaceBy)
 Replace a char by another one in a string. More...
 
int createXidFile (maps *pmsConf, char *pcPath, char *pcUsid, const char *pcExtension, char *pcValue)
 Create PID (SID) file referencing the OS process identifier (service id) More...
 
int createSPidFile (maps *pmsConf, char *pcPath)
 Create the PID and SID files referencing the OS process identifier and the service id, respectively. More...
 
int createLenvFile (maps *pmsConf, char *pcPath, char *pcUsid)
 Create a _lenv.cfg file containing the lenv map. More...
 
int dumpBackFinalFile (maps *pmsConf, char *pcFileName, char *pcFileName1)
 Dump back the final file fbkp1 to fbkp. More...
 
int addServicesNamespaceToMap (maps **pmsConf)
 
void setRootUrlMap (maps *pmConf)
 
int _recursReaddirF (maps **ppmsConf, registry *prRegistry, void *pvDoc, void *pvNode, char *conf_dir, char *prefix, int saved_stdout, int level, void(func)(registry *, maps *, void *, void *, service *))
 Recursivelly parse zcfg starting from the ZOO-Kernel cwd. More...
 
int recursReaddirF (maps **ppmsConf, registry *prRegistry, void *pvDoc, void *pvNode, char *conf_dir_, char *prefix, int saved_stdout, int level, void(func)(registry *, maps *, void *, void *, service *))
 Recursivelly parse zcfg from search path (services namespace and cwd). More...
 
void exitAndCleanUp (registry *zooRegistry, maps **ppmsConf, const char *zcfg, const char *code, const char *locator, char *orig, char *corig, void(funcError)(maps **, map *))
 When th zcfg file is not found, print error message and cleanup memory Note this function does free the *ppmsConf memory. More...
 
int _fetchService (registry *zooRegistry, maps **pmsConf, service **spService, map *request_inputs, char *pcDir, char *cIdentifier, void(funcError)(maps **, map *))
 Parse the ZOO-Service ZCFG to fill the service datastructure. More...
 
int fetchService (registry *zooRegistry, maps **pmsConf, service **spService, map *request_inputs, char *pcDir, char *cIdentifier, void(funcError)(maps **, map *))
 Parse the ZOO-Service ZCFG to fill the service datastructure. More...
 
int _fetchServicesForDescription (registry *zooRegistry, maps **ppmsConf, char *r_inputs, void(func)(registry *, maps *, void *, void *, service *), void *doc, void *n, char *conf_dir, map *request_inputs, void(funcError)(maps **, map *))
 Search services from various possible sources. More...
 
int fetchServicesForDescription (registry *zooRegistry, maps **pmsConf, char *r_inputs, void(func)(registry *, maps *, void *, void *, service *), void *doc, void *n, char *pcDir, map *request_inputs, void(funcError)(maps **, map *))
 Search services from various possible sources. More...
 
void initAllEnvironment (maps *conf, map *request_inputs, const char *cPath, const char *request)
 Initialize environment sections, load env, and populate lenv and renv. More...
 
void donothing (int sig)
 Signal handling function which simply call exit(0). More...
 
void sig_handler (int sig)
 Signal handling function which create an ExceptionReport node containing the information message corresponding to the signal number. More...
 
void register_signals (void(func)(int))
 Register signals. More...
 
void loadServiceAndRun (maps **myMap, service *s1, map *request_inputs, maps **inputs, maps **ioutputs, int *eres)
 Load a service provider and run the service function. More...
 
void setSecurityFlags (maps *pmsConf, char *pcCgiQueryString)
 Set the security flag for the current request. More...
 
int ensureFiltered (maps **ppmsConf, const char *pcType)
 Invoke the execution of the security module in case security is activated. More...
 
int runRequest (map **inputs)
 Process the request. More...
 

Variables

char ** environ
 

Macro Definition Documentation

◆ _

#define _ (   String)    dgettext ("zoo-kernel",String)

Translation function for zoo-kernel.

◆ __

#define __ (   String)    dgettext ("zoo-service",String)

Translation function for zoo-service.

◆ localPrintExceptionJ

#define localPrintExceptionJ   localPrintException

Function Documentation

◆ _fetchService()

int _fetchService ( registry zooRegistry,
maps **  pmsConf,
service **  spService,
map request_inputs,
char *  pcDir,
char *  cIdentifier,
void(funcError)(maps **, map *)   
)

Parse the ZOO-Service ZCFG to fill the service datastructure.

Parameters
zooRegistrythe populated registry
pmsConfthe maps pointer to the content of main.cfg file
spServicethe pointer to the service pointer to be filled
request_inputsthe map pointer for http request inputs
pcDirthe path where the ZCFG files are stored
cIdentifierthe service identifier
funcErrorthe error function to be used in case of error

◆ _fetchServicesForDescription()

int _fetchServicesForDescription ( registry zooRegistry,
maps **  ppmsConf,
char *  r_inputs,
void(func)(registry *, maps *, void *, void *, service *)  ,
void *  doc,
void *  n,
char *  conf_dir,
map request_inputs,
void(funcError)(maps **, map *)   
)

Search services from various possible sources.

Parameters
zopRegistrythe populated registry
ppmsConfthe maps pointer to the content of main.cfg file
r_inputsthe service(s) name(s)
functhe function used to print the result back
docthe xml document or NULL (for json)
nthe xmlNode of JSON object pointer to the current element
conf_dirthe directory where the main.cfg has been found
request_inputsthe map pointer to the request KVP if any
funcErrorthe function used to print the error back
Returns
0 in case of success, 1 otherwise
See also
exitAndCleanUp

No support for dot in service name stored in metadb!? #ifdef META_DB service* s2=extractServiceFromDb(m,tmpMapI->value,0); if(s2==NULL){ #endif

◆ _recursReaddirF()

int _recursReaddirF ( maps **  ppmsConf,
registry prRegistry,
void *  pvDoc,
void *  pvNode,
char *  conf_dir,
char *  prefix,
int  saved_stdout,
int  level,
void(func)(registry *, maps *, void *, void *, service *)   
)

Recursivelly parse zcfg starting from the ZOO-Kernel cwd.

Call the func function given in arguments after parsing the ZCFG file.

Parameters
pmsConfthe conf maps containing the main.cfg settings
prRegistrythe registry containing profiles hierarchy
pvDocthe root XML Node to add the sub-elements
pvNodethe root XML Node to add the sub-elements
conf_dirthe location of the main.cfg file (basically cwd)
prefixthe current prefix if any, or NULL
saved_stdoutthe saved stdout identifier
levelthe current level (number of sub-directories to reach the current path)
funca pointer to a function having 5 parameters (registry*, maps*, xmlDocPtr, xmlNodePtr, and service*).
See also
inheritance, readServiceFile

◆ addServicesNamespaceToMap()

int addServicesNamespaceToMap ( maps **  pmsConf)

◆ cleanUpSql()

void cleanUpSql ( maps pmsConf)

Close any sql backend connexion and call end_sql.

Parameters
pmsConfthe maps pointer to the main configuration file
See also
close_sql,end_sql

◆ createLenvFile()

int createLenvFile ( maps pmsConf,
char *  pcPath,
char *  pcUsid 
)

Create a _lenv.cfg file containing the lenv map.

Parameters
pmsConfthe conf maps containing the main.cfg settings
pcPaththe path to store the sid file
pcUsidthe usid value
pcValuethe value to be stored

◆ createSPidFile()

int createSPidFile ( maps pmsConf,
char *  pcPath 
)

Create the PID and SID files referencing the OS process identifier and the service id, respectively.

Parameters
pmsConfthe conf maps containing the main.cfg settings
pcPaththe path to store the files

◆ createXidFile()

int createXidFile ( maps pmsConf,
char *  pcPath,
char *  pcUsid,
const char *  pcExtension,
char *  pcValue 
)

Create PID (SID) file referencing the OS process identifier (service id)

Parameters
pmsConfthe conf maps containing the main.cfg settings
pcPaththe path to store the sid file
pcUsidthe usid value
pcExtensionthe file extension (sid or pid)
pcValuethe value to be stored

◆ crlex()

int crlex ( )

◆ donothing()

void donothing ( int  sig)

Signal handling function which simply call exit(0).

Parameters
sigthe signal number

◆ dumpBackFinalFile()

int dumpBackFinalFile ( maps pmsConf,
char *  pcFileName,
char *  pcFileName1 
)

Dump back the final file fbkp1 to fbkp.

Parameters
pmsConfthe conf maps containing the main.cfg settings
pcFileNamethe string corresponding to the name of the file
pcFileName1the string corresponding to the name of the file

◆ ensureFiltered()

int ensureFiltered ( maps **  ppmsConf,
const char *  pcType 
)

Invoke the execution of the security module in case security is activated.

Parameters
ppmsConfthe maps pointing to the main.cfg file content
pcTypethe string defining the process to execute ('in' or 'out')
Returns
0 in case of success, 1 in case or error

◆ exitAndCleanUp()

void exitAndCleanUp ( registry zooRegistry,
maps **  ppmsConf,
const char *  zcfg,
const char *  code,
const char *  locator,
char *  orig,
char *  corig,
void(funcError)(maps **, map *)   
)

When th zcfg file is not found, print error message and cleanup memory Note this function does free the *ppmsConf memory.

Parameters
zooRegistrythe populated registry
ppmsConfthe maps pointer address to the content of main.cfg file
zcfgthe zcfg file name
codethe string determining the nature of the error
locatorthe string determining which parameter the error refer to
origthe service name
corigthe current service name (in case multiple services was parsed)
funcErrorthe function used to print the error back

◆ fetchService()

int fetchService ( registry zooRegistry,
maps **  pmsConf,
service **  spService,
map request_inputs,
char *  pcDir,
char *  cIdentifier,
void(funcError)(maps **, map *)   
)

Parse the ZOO-Service ZCFG to fill the service datastructure.

Parameters
zooRegistrythe populated registry
pmsConfthe maps pointer to the content of main.cfg file
spServicethe pointer to the service pointer to be filled
request_inputsthe map pointer for http request inputs
pcDirthe path where the ZCFG files are stored
cIdentifierthe service identifier
funcErrorthe error function to be used in case of error

◆ fetchServicesForDescription()

int fetchServicesForDescription ( registry zooRegistry,
maps **  pmsConf,
char *  r_inputs,
void(func)(registry *, maps *, void *, void *, service *)  ,
void *  doc,
void *  n,
char *  pcDir,
map request_inputs,
void(funcError)(maps **, map *)   
)

Search services from various possible sources.

Parameters
zopRegistrythe populated registry
mthe maps pointer to the content of main.cfg file
r_inputsthe service(s) name(s)
functhe function used to print the result back
docthe xml document or NULL (for json)
nthe xmlNode of JSON object pointer to the current element
conf_dirthe directory where the main.cfg has been found
request_inputsthe map pointer to the request KVP if any
funcErrorthe function used to print the error back
Returns
0 in case of success, 1 otherwise

◆ initAllEnvironment()

void initAllEnvironment ( maps conf,
map request_inputs,
const char *  cPath,
const char *  request 
)

Initialize environment sections, load env, and populate lenv and renv.

Parameters
confthe maps pointing to the main.cfg file content
request_inputsthe map pointing to the request KVP
cPatha string pointing to the cwd
requesta string pointing to the request key (xrequest or jrequest)

Initialize the specific [lenv] section which contains runtime variables:

  • usid : it is an universally unique identifier
  • osid : it is an idenfitication number
  • sid : it is the process idenfitication number (OS)
  • uusid : it is an universally unique identifier
  • status : value between 0 and 100 to express the completude of the operations of the running service
  • message : is a string where you can store error messages, in case service is failing, or o provide details on the ongoing operation.
  • cwd : the current working directory or servicePath if defined
  • soap : is a boolean value, true if the request was contained in a SOAP Envelop
  • sessid : string storing the session identifier (only when cookie is used)
  • cgiSid : only defined on Window platforms (for being able to identify the created process)

◆ loadServiceAndRun()

void loadServiceAndRun ( maps **  myMap,
service s1,
map request_inputs,
maps **  inputs,
maps **  ioutputs,
int *  eres 
)

Load a service provider and run the service function.

Parameters
myMapthe conf maps containing the main.cfg settings
s1the service structure
request_inputsmap storing all the request parameters
inputsthe inputs maps
ioutputsthe outputs maps
eresthe result returned by the service execution

Extract serviceType to know what kind of service should be loaded

Unable to load the specified shared library

◆ recursReaddirF()

int recursReaddirF ( maps **  ppmsConf,
registry prRegistry,
void *  pvDoc,
void *  pvNode,
char *  conf_dir_,
char *  prefix,
int  saved_stdout,
int  level,
void(func)(registry *, maps *, void *, void *, service *)   
)

Recursivelly parse zcfg from search path (services namespace and cwd).

If the main cofiguration maps (pmsConf) get, in the openapi section, a search_path key taking the value true, then the ZOO-Kernel default search_path used for searching zcfg files (cwd) is used in addition to the authenticated user namespace.

Parameters
ppmsConfthe conf maps containing the main.cfg settings
prRegistrythe registry containing profiles hierarchy
nthe root XML Node to add the sub-elements
conf_dirthe location of the main.cfg file (basically cwd)
prefixthe current prefix if any, or NULL
saved_stdoutthe saved stdout identifier
levelthe current level (number of sub-directories to reach the current path)
funca pointer to a function having 4 parameters (registry*, maps*, xmlNodePtr and service*).
See also
recursReaddirF

◆ register_signals()

void register_signals ( void(func)(int)  )

Register signals.

Parameters
afunction for handling signals
See also
donothing

◆ runRequest()

int runRequest ( map **  inputs)

Process the request.

Specific includes.

Parameters
inputsthe request parameters map
Returns
0 on sucess, other value on failure
See also
conf_read,recursReaddirF

Here we need to close stdout to ensure that unsupported chars has been found in the zcfg and then printed on stdout

Loop over Identifier list

Create the input and output maps data structure

05-007r7 WPS 1.0.0 page 57 : 'If status="true" and storeExecuteResponse is "false" then the service shall raise an exception.'

error server don't accept the process need to output a valid error response here !!!

Ensure that if error occurs when freeing memory, no signal will return an ExceptionReport document as the result was already returned to the client.

◆ setRootUrlMap()

void setRootUrlMap ( maps pmConf)

◆ setSecurityFlags()

void setSecurityFlags ( maps pmsConf,
char *  pcCgiQueryString 
)

Set the security flag for the current request.

Set [lenv] secured_url to true in case the access should be secured, false in other cases.

Parameters
pmsConfthe maps pointing to the main.cfg file content
pcCgiQueryStringthe string containing the request

◆ sig_handler()

void sig_handler ( int  sig)

Signal handling function which create an ExceptionReport node containing the information message corresponding to the signal number.

Parameters
sigthe signal number

◆ translateChar()

void translateChar ( char *  pcOrigin,
char  cToReplace,
char  cToReplaceBy 
)

Replace a char by another one in a string.

Parameters
pcOriginthe string to update
cToReplacethe char to replace
cToReplaceBythe char that will be used

◆ yylex()

int yylex ( )

Variable Documentation

◆ environ

char** environ