ZOO-Project
Macros | Functions | Variables
zoo_service_loader.c File Reference
#include "cgic.h"
#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>

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...
 

Functions

int yylex ()
 
int crlex ()
 
void translateChar (char *str, char toReplace, char toReplaceBy)
 Replace a char by another one in a string. More...
 
int dumpBackFinalFile (maps *m, char *fbkp, char *fbkp1)
 Dump back the final file fbkp1 to fbkp. More...
 
int recursReaddirF (maps *m, registry *r, void *doc1, void *n1, 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...
 
void exitAndCleanUp (registry *zooRegistry, maps *m, 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. More...
 
int fetchService (registry *zooRegistry, maps *m, service **spService, map *request_inputs, char *ntmp, char *cIdentifier, void(funcError)(maps *, map *))
 Parse the ZOO-Service ZCFG to fill the service datastructure. More...
 
int fetchServicesForDescription (registry *zooRegistry, maps *m, 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...
 
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 loadServiceAndRun (maps **myMap, service *s1, map *request_inputs, maps **inputs, maps **ioutputs, int *eres)
 Load a service provider and run the service function. 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.

Function Documentation

int crlex ( )
void donothing ( int  sig)

Signal handling function which simply call exit(0).

Parameters
sigthe signal number
int dumpBackFinalFile ( maps m,
char *  fbkp,
char *  fbkp1 
)

Dump back the final file fbkp1 to fbkp.

Parameters
mthe conf maps containing the main.cfg settings
fbkpthe string corresponding to the name of the file
fbkp1the string corresponding to the name of the file
void exitAndCleanUp ( registry zooRegistry,
maps m,
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.

Parameters
zooRegistrythe populated registry
mthe maps pointer 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
int fetchService ( registry zooRegistry,
maps m,
service **  spService,
map request_inputs,
char *  ntmp,
char *  cIdentifier,
void(funcError)(maps *, map *)   
)

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

Parameters
zooRegistrythe populated registry
mthe 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
ntmpthe path where the ZCFG files are stored
cIdentifierthe service identifier
funcErrorthe error function to be used in case of error
int fetchServicesForDescription ( registry zooRegistry,
maps m,
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
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

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

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)
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

int recursReaddirF ( maps m,
registry r,
void *  doc1,
void *  n1,
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
mthe conf maps containing the main.cfg settings
rthe 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
inheritance, readServiceFile
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

Parsing service specfic configuration file

Manage our own error log file (usefull to separate standard apache debug messages from the ZOO-Kernel ones but also for IIS users to avoid wrong headers messages returned by the CGI due to wrong redirection of stderr)

Language gesture

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.

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
void translateChar ( char *  str,
char  toReplace,
char  toReplaceBy 
)

Replace a char by another one in a string.

Parameters
strthe string to update
toReplacethe char to replace
toReplaceBythe char that will be used
int yylex ( )

Variable Documentation

char** environ