liblog-bdm/lib/libtool.pc
2000-07-31 13:15:35 +00:00

1370 lines
43 KiB
PkgConfig

/*
Utilisation des API de la LIBDATASTR en mode optimisé :
- pas de vérif systématique des arguments
- pas de verrouillage systématique des data structures
*/
#define DS_MODE 2
/* Utilisation des API de la LIBLOG en mode optimisé */
#define LOG_MODE 1
#include <libtool.h>
VER_INFO_EXPORT (libtool, "$Revision: 1.1 $", "$Name: $", __FILE__, "$Author: smas $")
EXEC SQL INCLUDE SQLCA;
EXEC SQL INCLUDE ORACA;
EXEC ORACLE OPTION (ORACA=YES);
/*------------------------------------------------------------------------------*/
/* Définition de la sortie standard des messages d'erreur de la librairie */
/*------------------------------------------------------------------------------*/
/* (I) Out : flux de sortie des messages d'erreur */
/*------------------------------------------------------------------------------*/
TLT_Status TL_Library_Stderr_Set ( FILE * Out )
{
TL_stderr = Out;
return TLS_OK;
}
/*------------------------------------------------------------------------------*/
/* Chargement des caches de la librairie LIBLOG */
/*------------------------------------------------------------------------------*/
/* (I) ToLoad : liste des caches de données à charger */
/* (combinaison de TLD_KMOD, TLD_KFORMAT et TLD_GDRT) */
/*------------------------------------------------------------------------------*/
TLT_Status TL_LIBLOG_Load ( TLT_Cache ToLoad )
{
int Locked;
if (!LOG_Base)
{
sprintf (TL_Error_Msg, "Error TL_LIBLOG_Load : the LIBLOG library is not open");
TL_Error_Print ();
return TLS_KO;
}
if (TL_Param_Get () != TLS_OK)
{
sprintf (TL_Error_Msg, "Error TL_LIBLOG_Load : unable to retrieve parameters from KUNF");
TL_Error_Print ();
return TLS_KO;
}
/* Connexion à la base de données du suivi */
if (TL_Database_Connect () != LOGS_OK)
{
sprintf (TL_Error_Msg, "Error TL_LIBLOG_Load : unable to connect to database");
TL_Error_Print ();
return TLS_KO;
}
if (ToLoad & TLD_KMOD)
{
/* Verrouillage du cache des modules */
if (DS_DataStruct_Lock (LOG_Base->KMOD, DSD_WRITE, &Locked) != DSS_OK)
{
sprintf (TL_Error_Msg, "Error TL_LIBLOG_Load : unable to lock the KMOD data structure for writing");
TL_Error_Print ();
return TLS_KO;
}
/* Conversion du cache des modules en liste FIFO pour faciliter les insertions */
if (DS_DataStruct_Convert (LOG_Base->KMOD, NDD_DS_LIST|NDD_MN_FIFO) != DSS_OK)
{
sprintf (TL_Error_Msg, "Error TL_LIBLOG_Load : unable to convert the KMOD data structure to a FIFO list");
TL_Error_Print ();
return TLS_KO;
}
/* Chargement du cache des modules */
if (TL_KMOD_Load () != LOGS_OK)
{
sprintf (TL_Error_Msg, "Error TL_LIBLOG_Load : unable to load KMOD data structure from database");
TL_Error_Print ();
return TLS_KO;
}
/* Conversion du cache des modules en arbre auto-équilibré pour faciliter les recherches */
if (DS_DataStruct_Convert (LOG_Base->KMOD, NDD_DS_TREE|NDD_MN_AUTO_EQU) != DSS_OK)
{
sprintf (TL_Error_Msg, "Error TL_LIBLOG_Load : unable to convert the KMOD data structure to a tree");
TL_Error_Print ();
return TLS_KO;
}
/* Déverrouillage du cache des modules */
if (DS_DataStruct_Unlock (LOG_Base->KMOD) != DSS_OK)
{
sprintf (TL_Error_Msg, "Error TL_LIBLOG_Load : unable to unlock the KMODdata structure");
TL_Error_Print ();
return TLS_KO;
}
}
if (ToLoad & TLD_KFORMAT)
{
/* Verrouillage du cache des formats d'événement */
if (DS_DataStruct_Lock (LOG_Base->KFORMAT, DSD_WRITE, &Locked) != DSS_OK)
{
sprintf (TL_Error_Msg, "Error TL_LIBLOG_Load : unable to lock the KFORMAT data structure for writing");
TL_Error_Print ();
return TLS_KO;
}
/* Conversion du cache des formats d'événement en liste FIFO pour faciliter les insertions */
if (DS_DataStruct_Convert (LOG_Base->KFORMAT, NDD_DS_LIST|NDD_MN_FIFO) != DSS_OK)
{
sprintf (TL_Error_Msg, "Error TL_LIBLOG_Load : unable to convert the KFORMAT data structure to a FIFO list");
TL_Error_Print ();
return TLS_KO;
}
/* Chargement du cache des formats d'événement */
if (TL_KFORMAT_Load () != LOGS_OK)
{
sprintf (TL_Error_Msg, "Error TL_LIBLOG_Load : unable to load KFORMAT data structure from database");
TL_Error_Print ();
return TLS_KO;
}
/* Conversion du cache des formats d'événement en arbre auto-équilibré pour faciliter les recherches */
if (DS_DataStruct_Convert (LOG_Base->KFORMAT, NDD_DS_TREE|NDD_MN_AUTO_EQU) != DSS_OK)
{
sprintf (TL_Error_Msg, "Error TL_LIBLOG_Load : unable to convert the KFORMAT data structure to a tree");
TL_Error_Print ();
return TLS_KO;
}
/* Déverrouillage du cache des formats d'événement */
if (DS_DataStruct_Unlock (LOG_Base->KFORMAT) != DSS_OK)
{
sprintf (TL_Error_Msg, "Error TL_LIBLOG_Load : unable to unlock the KFORMAT data structure");
TL_Error_Print ();
return TLS_KO;
}
}
if (ToLoad & TLD_GDRT)
{
/* Verrouillage de la table de routage GDRT en écriture */
if (DS_DataStruct_Lock (LOG_Base->GDRT->Root, DSD_WRITE, &Locked) != DSS_OK)
{
sprintf (TL_Error_Msg, "Error TL_LIBLOG_Load : unable to lock the GDRT data structure for writing");
TL_Error_Print ();
return TLS_KO;
}
/* Conversion de la table de routage GDRT en liste FIFO pour faciliter les insertions */
if (DS_DataStruct_Convert (LOG_Base->GDRT->Root, NDD_DS_LIST|NDD_MN_FIFO) != DSS_OK)
{
sprintf (TL_Error_Msg, "Error TL_LIBLOG_Load : unable to convert the GDRT data structure to a FIFO list");
TL_Error_Print ();
return TLS_KO;
}
/* Chargement de la table de routage GDRT */
if (TL_GDRT_Load () != LOGS_OK)
{
sprintf (TL_Error_Msg, "Error TL_LIBLOG_Load : unable to load the GDRT data structure from database");
TL_Error_Print ();
return TLS_KO;
}
/* Conversion de la table de routage GDRT en arbre auto-équilibré pour faciliter les recherches */
if (DS_DataStruct_Convert (LOG_Base->GDRT->Root, NDD_DS_TREE|NDD_MN_AUTO_EQU) != DSS_OK)
{
sprintf (TL_Error_Msg, "Error TL_LIBLOG_Load : unable to convert the GDRT data structure to a tree");
TL_Error_Print ();
return TLS_KO;
}
/* Déverrouillage de la table de routage GDRT */
if (DS_DataStruct_Unlock (LOG_Base->GDRT->Root) != DSS_OK)
{
sprintf (TL_Error_Msg, "Error TL_LIBLOG_Load : unable to unlock the GDRT data structure");
TL_Error_Print ();
return TLS_KO;
}
}
return TLS_OK;
}
/*------------------------------------------------------------------------------*/
/* Déchargement des caches de la librairie LIBLOG */
/*------------------------------------------------------------------------------*/
/* (I) ToUnload : liste des caches de données à décharger */
/* (combinaison de TLD_KMOD, TLD_KFORMAT et TLD_GDRT) */
/*------------------------------------------------------------------------------*/
TLT_Status TL_LIBLOG_Unload (TLT_Cache ToUnload)
{
SMT_Heap * Heap;
size_t Size;
int Locked;
if (!LOG_Base)
{
sprintf (TL_Error_Msg, "Error TL_LIBLOG_Unload : the LIBLOG library is not open");
TL_Error_Print ();
return TLS_KO;
}
if (ToUnload & TLD_KMOD)
{
/* Verrouillage du cache des modules */
if (DS_DataStruct_Lock (LOG_Base->KMOD, DSD_WRITE, &Locked) != DSS_OK)
{
sprintf (TL_Error_Msg, "Error TL_LIBLOG_Unload : unable to lock the KMOD data structure for writing");
TL_Error_Print ();
return TLS_KO;
}
/* Déchargement du cache des modules */
if (TL_KMOD_Unload () != LOGS_OK)
{
sprintf (TL_Error_Msg, "Error TL_LIBLOG_Unload : unable to unload KMOD data structure");
TL_Error_Print ();
return TLS_KO;
}
/* Compression du heap sous-jacent */
if (SM_Heap_IsOpen (( (DST_RootDesc *)(LOG_Base->KMOD->User))->Heap_Name, &Heap) == SMS_OK)
SM_Heap_Compress (Heap, &Size);
/* Déverrouillage du cache des modules */
if (DS_DataStruct_Unlock (LOG_Base->KMOD) != DSS_OK)
{
sprintf (TL_Error_Msg, "Error TL_LIBLOG_Unload : unable to unlock the KMOD data structure");
TL_Error_Print ();
return TLS_KO;
}
}
if (ToUnload & TLD_KFORMAT)
{
/* Verrouillage du cache des formats d'événement en écriture */
if (DS_DataStruct_Lock (LOG_Base->KFORMAT, DSD_WRITE, &Locked) != DSS_OK)
{
sprintf (TL_Error_Msg, "Error TL_LIBLOG_Unload : unable to lock the KFORMAT data structure for writing");
TL_Error_Print ();
return TLS_KO;
}
/* Déchargement du cache des formats d'événement */
if (TL_KFORMAT_Unload () != LOGS_OK)
{
sprintf (TL_Error_Msg, "Error TL_LIBLOG_Unload : unable to unload KFORMAT data structure");
TL_Error_Print ();
return TLS_KO;
}
/* Compression du heap sous-jacent */
if (SM_Heap_IsOpen (( (DST_RootDesc *)(LOG_Base->KFORMAT->User))->Heap_Name, &Heap) == SMS_OK)
SM_Heap_Compress (Heap, &Size);
/* Déverrouillage du cache des formats d'événement */
if (DS_DataStruct_Unlock (LOG_Base->KFORMAT) != DSS_OK)
{
sprintf (TL_Error_Msg, "Error TL_LIBLOG_Unload : unable to unlock the KFORMAT data structure");
TL_Error_Print ();
return TLS_KO;
}
}
if (ToUnload & TLD_GDRT)
{
/* Verrouillage de la table de routage GDRT en écriture */
if (DS_DataStruct_Lock (LOG_Base->GDRT->Root, DSD_WRITE, &Locked) != DSS_OK)
{
sprintf (TL_Error_Msg, "Error TL_LIBLOG_Unload : unable to lock the GDRT data structure for writing");
TL_Error_Print ();
return TLS_KO;
}
/* Déchargement de la table GDRT */
if (TL_GDRT_Unload () != LOGS_OK)
{
sprintf (TL_Error_Msg, "Error TL_LIBLOG_Unload : unable to unload GDRT data structure");
TL_Error_Print ();
return TLS_KO;
}
/* Compression du heap sous-jacent */
if (SM_Heap_IsOpen (( (DST_RootDesc *)(LOG_Base->GDRT->Root->User))->Heap_Name, &Heap) == SMS_OK)
SM_Heap_Compress (Heap, &Size);
/* Déverrouillage de la table de routage GDRT */
if (DS_DataStruct_Unlock (LOG_Base->GDRT->Root) != DSS_OK)
{
sprintf (TL_Error_Msg, "Error TL_LIBLOG_Unload : unable to unlock the GDRT data structure");
TL_Error_Print ();
return TLS_KO;
}
}
return TLS_OK;
}
/*------------------------------------------------------------------------------*/
/* Affectation de toutes les tables de routage d'une section KUNF à un channel */
/*------------------------------------------------------------------------------*/
/* (I) Channel : pointeur sur le channel */
/* (I) Kunf_Name : nom de la section KUNF */
/*------------------------------------------------------------------------------*/
TLT_Status TL_Channel_RTab_Add (LOGT_Channel * My_Channel, const char * Kunf_Name)
{
KITEM * Item;
if (!My_Channel)
{
sprintf (TL_Error_Msg, "Error TL_Channel_RTab_Add : the channel is null");
TL_Error_Print ();
return TLS_KO;
}
kunfig_open (NULL, KUNFIG_OPEN_SIMPLEACCESS|KUNFIG_OPEN_OVERRIDINGENV);
/* Recherche de la section KUNF passée en paramètre */
Item = kunfig_directfindentry (Kunf_Name);
if (!Item)
{
sprintf (TL_Error_Msg, "Error TL_Channel_RTab_Add : unable to find section \"%s\"", Kunf_Name);
TL_Error_Print ();
kunfig_close ();
return TLS_KO;
}
/* On descend dans l'arborescence de la section pour récupérer la liste des tables de routage */
Item = kunfig_down (Item, KUNFIG_LOCAL);
while (Item)
{
char * Table_Name = kunfig_getname (Item);
char Name [256];
sprintf (Name, "%s:%s", Kunf_Name, Table_Name);
if (TL_RTab_Add (My_Channel, Name) != TLS_OK)
{
sprintf (TL_Error_Msg, "Error TL_Channel_RTab_Add : unable to add rooting table %s to the channel", Table_Name);
TL_Error_Print ();
kunfig_close ();
return TLS_KO;
}
Item = kunfig_next (Item, KUNFIG_LOCAL);
}
kunfig_close ();
return TLS_OK;
}
/*------------------------------------------------------------------------------*/
/* Affectation de tous les triggers d'une section KUNF à un channel */
/*------------------------------------------------------------------------------*/
/* (I) Channel : pointeur sur le channel */
/* (I) Kunf_Name : nom de la section KUNF */
/*------------------------------------------------------------------------------*/
TLT_Status TL_Channel_Trigger_Add (LOGT_Channel * My_Channel, const char * Kunf_Name)
{
KITEM * Item;
if (!My_Channel)
{
sprintf (TL_Error_Msg, "Error TL_Channel_Trigger_Add : the channel is null");
TL_Error_Print ();
return TLS_KO;
}
kunfig_open (NULL, KUNFIG_OPEN_SIMPLEACCESS|KUNFIG_OPEN_OVERRIDINGENV);
/* Recherche de la section KUNF passée en paramètre */
Item = kunfig_directfindentry (Kunf_Name);
if (!Item)
{
sprintf (TL_Error_Msg, "Error TL_Channel_Trigger_Add : unable to find section \"%s\"", Kunf_Name);
TL_Error_Print ();
kunfig_close ();
return TLS_KO;
}
/* On descend dans l'arborescence de la section pour récupérer la liste des triggers */
Item = kunfig_down (Item, KUNFIG_LOCAL);
while (Item)
{
char * Trigger_Name = kunfig_getname (Item);
char Name [256];
sprintf (Name, "%s:%s", Kunf_Name, Trigger_Name);
if (TL_Trigger_Add (My_Channel, Name) != TLS_OK)
{
sprintf (TL_Error_Msg, "Error TL_Channel_Trigger_Add : unable to add trigger %s to the channel", Trigger_Name);
TL_Error_Print ();
kunfig_close ();
return TLS_KO;
}
Item = kunfig_next (Item, KUNFIG_LOCAL);
}
kunfig_close ();
return TLS_OK;
}
/*------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------*/
/* Fonctions privées */
/*------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------*/
/* Chargement du cache des modules */
/*------------------------------------------------------------------------------*/
TLT_Status TL_KMOD_Load ( void )
{
int Id_Module;
char Cd_Module [81];
int Nb_Modules = 0;
/* Récupération des modules */
EXEC SQL DECLARE cursor_module CURSOR FOR SELECT ID_MODULE, CD_MODULE FROM TB_MODULE WHERE DAT_FIN_EFFET IS NOT NULL;
EXEC SQL OPEN cursor_module;
if (sqlca.sqlcode != SQL_OK)
{
sprintf (TL_Error_Msg, "Error TL_KMOD_Load : unable to open cursor to retrieve modules from the database (%s)", Oracle_Message_Get ());
TL_Error_Print ();
EXEC SQL CLOSE cursor_module;
return TLS_KO;
}
EXEC SQL FETCH cursor_module INTO :Id_Module, :Cd_Module;
while (sqlca.sqlcode == SQL_OK || sqlca.sqlcode == SQL_FETCHED_COLUMN_NULL)
{
void * Value;
if (DS_Value_Alloc (LOG_Base->KMOD, &Value, trim (Cd_Module), Id_Module) != NDS_OK)
{
sprintf (TL_Error_Msg, "Error TL_KMOD_Load : unable to create a module for the KMOD data structure");
TL_Error_Print ();
return TLS_KO;
}
if (DS_Value_Add (LOG_Base->KMOD, Value) != LOGS_OK)
{
sprintf (TL_Error_Msg, "Error TL_KMOD_Load : unable to add a module to the KMOD data structure");
TL_Error_Print ();
EXEC SQL CLOSE cursor_module;
return TLS_KO;
}
Nb_Modules++;
EXEC SQL FETCH cursor_module INTO :Id_Module, :Cd_Module;
}
if (sqlca.sqlcode != SQL_NO_DATA_FOUND)
{
sprintf (TL_Error_Msg, "Error TL_KMOD_Load : unable to fetch cursor to retrieve modules from the database (%s)", Oracle_Message_Get ());
TL_Error_Print ();
EXEC SQL CLOSE cursor_module;
return TLS_KO;
}
EXEC SQL CLOSE cursor_module;
sprintf (TL_Info_Msg, "TL_KMOD_Load : %d module(s) loaded in the KMOD data structure", Nb_Modules);
TL_Info_Print ();
return TLS_OK;
}
/*------------------------------------------------------------------------------*/
/* Déchargement du cache des modules */
/*------------------------------------------------------------------------------*/
TLT_Status TL_KMOD_Unload ( void )
{
if (DS_DataStruct_Traverse (LOG_Base->KMOD, NDD_CMD_DELETE_VALUE, NULL) != DSS_OK)
{
sprintf (TL_Error_Msg, "Error TL_KMOD_Unload : unable to delete all values from the KMOD data structure");
TL_Error_Print ();
return TLS_KO;
}
sprintf (TL_Info_Msg, "The KMOD data structure has been successfully unloaded");
TL_Info_Print ();
return TLS_OK;
}
/*------------------------------------------------------------------------------*/
/* Chargement du cache des formats d'événement */
/*------------------------------------------------------------------------------*/
TLT_Status TL_KFORMAT_Load ( void )
{
char Data [81];
unsigned int Event_Type;
LOGT_Event_Format * Format;
NDT_Node * Node;
char * Format_Data;
int Nb_Event_Format = 0;
int Nb_Event_Data = 0;
/* Récupération des formats d'événement */
EXEC SQL DECLARE cursor_format CURSOR FOR
SELECT TB_TYPE_EVEN.CD_TYPE_EVEN, TB_DONNEE.CD_DONNEE
FROM TB_TYPE_EVEN, TA_DONNEE_FORMAT, TB_DONNEE
WHERE TB_TYPE_EVEN.ID_FORMAT = TA_DONNEE_FORMAT.ID_FORMAT
AND TA_DONNEE_FORMAT.DAT_EFFET_FORMAT <= SYSDATE
AND TA_DONNEE_FORMAT.DAT_EFFET <= SYSDATE
AND TB_DONNEE.CD_DONNEE = TA_DONNEE_FORMAT.CD_DONNEE
AND TB_DONNEE.DAT_EFFET = TA_DONNEE_FORMAT.DAT_EFFET_DONNEE;
EXEC SQL OPEN cursor_format;
if (sqlca.sqlcode != SQL_OK)
{
sprintf (TL_Error_Msg, "Error TL_KFORMAT_Load : unable to open cursor to retrieve event formats from the database (%s)", Oracle_Message_Get ());
TL_Error_Print ();
EXEC SQL CLOSE cursor_format;
return TLS_KO;
}
EXEC SQL FETCH cursor_format INTO :Event_Type, :Data;
while (sqlca.sqlcode == SQL_OK || sqlca.sqlcode == SQL_FETCHED_COLUMN_NULL)
{
LOGT_Event_Format Tmp_Event_Format;
Tmp_Event_Format.Event_Type = Event_Type;
if (ND_Node_Find (LOG_Base->KFORMAT, &Node, (void *)(&Tmp_Event_Format), NULL) != NDS_OK)
{
/* Création du format de l'événement */
if (DS_Value_Alloc (LOG_Base->KFORMAT, (void **)&Format, Event_Type) != NDS_OK)
{
sprintf (TL_Error_Msg, "Error TL_KFORMAT_Load : unable to create a value for the KFORMAT data structure");
TL_Error_Print ();
EXEC SQL CLOSE cursor_format;
return TLS_KO;
}
if (DS_Value_Add (LOG_Base->KFORMAT, (void *)Format) != LOGS_OK)
{
sprintf (TL_Error_Msg, "Error TL_KFORMAT_Load : unable to add an event format to the KFORMAT data structure");
TL_Error_Print ();
EXEC SQL CLOSE cursor_format;
return TLS_KO;
}
Nb_Event_Format++;
}
else
Format = (LOGT_Event_Format *)(Node->Value);
/* Création de la donnée du format */
if (DS_Value_Alloc (Format->Data_List, (void **)&Format_Data, trim (Data)) != NDS_OK)
{
sprintf (TL_Error_Msg, "Error TL_KFORMAT_Load : unable to create a data for the event format data list");
TL_Error_Print ();
EXEC SQL CLOSE cursor_format;
return TLS_KO;
}
if (DS_Value_Add (Format->Data_List, (void *)Format_Data) != LOGS_OK)
{
sprintf (TL_Error_Msg, "Error TL_KFORMAT_Load : unable to add a data to the event format data list");
TL_Error_Print ();
EXEC SQL CLOSE cursor_format;
return TLS_KO;
}
Nb_Event_Data++;
EXEC SQL FETCH cursor_format INTO :Event_Type, :Data;
}
if (sqlca.sqlcode != SQL_NO_DATA_FOUND)
{
sprintf (TL_Error_Msg, "Error TL_KFORMAT_Load : unable to fetch cursor to retrieve formats from the database (%s)", Oracle_Message_Get ());
TL_Error_Print ();
EXEC SQL CLOSE cursor_format;
return TLS_KO;
}
EXEC SQL CLOSE cursor_format;
sprintf (TL_Info_Msg, "TL_KFORMAT_Load : %d format(s) and %d data(s) loaded in the KFORMAT data structure", Nb_Event_Format, Nb_Event_Data);
TL_Info_Print ();
return TLS_OK;
}
/*------------------------------------------------------------------------------*/
/* Déchargement du cache des formats d'événement */
/*------------------------------------------------------------------------------*/
TLT_Status TL_KFORMAT_Unload ( void )
{
if (DS_DataStruct_Traverse (LOG_Base->KFORMAT, NDD_CMD_DELETE_VALUE, NULL) != DSS_OK)
{
sprintf (TL_Error_Msg, "Error TL_KFORMAT_Unload : unable to delete all values from the KFORMAT data structure");
TL_Error_Print ();
return TLS_KO;
}
sprintf (TL_Info_Msg, "The KFORMAT data structure has been successfully unloaded");
TL_Info_Print ();
return TLS_OK;
}
/*------------------------------------------------------------------------------*/
/* Chargement de la table de routage par défaut (GDRT) */
/*------------------------------------------------------------------------------*/
TLT_Status TL_GDRT_Load ( void )
{
int cd_type_even;
int cd_retour;
char cd_gravite [2];
int rooting;
char nom_type_even [81];
int Nb_Event = 0;
int Nb_Tree = 0;
/* Sélection des types d'événement correspondant à la règle */
EXEC SQL DECLARE cursor_evt CURSOR FOR
SELECT CD_TYPE_EVEN, NOM_TYPE_EVEN, TB_TYPE_EVEN.CD_GRAVITE, CD_RETOUR, NIV_SORTIE FROM TB_TYPE_EVEN, TB_GRAVITE WHERE TB_TYPE_EVEN.CD_GRAVITE = TB_GRAVITE.CD_GRAVITE;
EXEC SQL OPEN cursor_evt;
if (sqlca.sqlcode != SQL_OK)
{
sprintf (TL_Error_Msg, "Error TL_GDRT_Load : unable to open cursor to retrieve event types from the database (%s)", Oracle_Message_Get ());
TL_Error_Print ();
EXEC SQL CLOSE cursor_evt;
return TLS_KO;
}
EXEC SQL FETCH cursor_evt INTO :cd_type_even, :nom_type_even, :cd_gravite, :cd_retour, :rooting;
while (sqlca.sqlcode == SQL_OK || sqlca.sqlcode == SQL_FETCHED_COLUMN_NULL)
{
if (ND_Manager_Exec (LOG_Base->GDRT->Root->Manager, NDD_CMD_MAKE_VALUE, trim (nom_type_even), cd_type_even, (LOGT_Gravite)cd_gravite [0], (LOGT_RC)cd_retour, (LOGT_Rooting)rooting, &Nb_Tree) != LOGS_OK)
{
sprintf (TL_Error_Msg, "Error TL_GDRT_Load : unable to add event \"%s\" to the GDRT data structure", trim (nom_type_even));
TL_Error_Print ();
EXEC SQL CLOSE cursor_evt;
return TLS_KO;
}
Nb_Event++;
EXEC SQL FETCH cursor_evt INTO :cd_type_even, :nom_type_even, :cd_gravite, :cd_retour, :rooting;
}
if (sqlca.sqlcode != SQL_NO_DATA_FOUND)
{
sprintf (TL_Error_Msg, "Error TL_GDRT_Load : unable to fetch cursor to retrieve event types from the database (%s)", Oracle_Message_Get ());
TL_Error_Print ();
EXEC SQL CLOSE cursor_evt;
return TLS_KO;
}
EXEC SQL CLOSE cursor_evt;
sprintf (TL_Info_Msg, "TL_GDRT_Load : %d event(s) loaded (%d tree(s) created) in the GDRT data structure", Nb_Event, Nb_Tree);
TL_Info_Print ();
return TLS_OK;
}
/*------------------------------------------------------------------------------*/
/* Déchargement de la table de routage GDRT */
/*------------------------------------------------------------------------------*/
TLT_Status TL_GDRT_Unload ( void )
{
if (DS_DataStruct_Traverse (LOG_Base->GDRT->Root, NDD_CMD_DELETE_VALUE, NULL) != DSS_OK)
{
sprintf (TL_Error_Msg, "Error TL_GDRT_Unload : unable to delete all values from the GDRT data structure");
TL_Error_Print ();
return TLS_KO;
}
sprintf (TL_Info_Msg, "The GDRT data structure has been successfully unloaded");
TL_Info_Print ();
return TLS_OK;
}
/*------------------------------------------------------------------------------*/
/* Connexion à la base de suivi */
/*------------------------------------------------------------------------------*/
TLT_Status TL_Database_Connect ( void )
{
EXEC SQL CONNECT :oracx;
if (sqlca.sqlcode != SQL_OK)
{
sprintf (TL_Error_Msg, "Error TL_Database_Connect %s", Oracle_Message_Get ());
TL_Error_Print ();
return TLS_KO;
}
return TLS_OK;
}
/*------------------------------------------------------------------------------*/
/* Ajout d'une table de routage utilisateur à un channel */
/*------------------------------------------------------------------------------*/
/* (I) Channel : pointeur sur le channel */
/* (I) Kunf_Name : nom de la section kunf de la table de routage */
/*------------------------------------------------------------------------------*/
TLT_Status TL_RTab_Add (LOGT_Channel * My_Channel, char * Kunf_Name)
{
KITEM * Item;
LOGT_RuleClass RuleClass;
LOGT_Rule * Rule;
LOGT_Rooting Rooting;
LOGT_RTab * RTab;
char * ptr;
char RTab_Name [100];
char sRule [256];
/* Recherche de la section relative à la table de routage */
Item = kunfig_directfindentry (Kunf_Name);
if (!Item)
{
sprintf (TL_Error_Msg, "Error TL_RTab_Add : unable to find section \"%s\"", Kunf_Name);
TL_Error_Print ();
return TLS_KO;
}
/* Création de la table de routage utilisateur */
if ((ptr = strrchr (Kunf_Name, ':')) ) ptr ++;
else ptr = Kunf_Name;
sprintf (RTab_Name, "%s_%d_%ld_%d", ptr, My_Channel->ModuleId, My_Channel->Pid, My_Channel->Id);
if (LOG_RTab_Alloc (&RTab, RTab_Name) != LOGS_OK)
{
sprintf (TL_Error_Msg, "Error TL_RTab_Add : unable to allocate memory for rooting table %s", RTab_Name);
TL_Error_Print ();
return TLS_KO;
}
/* On descend dans l'arborescence de la table de routage pour récupérer les règles associées */
Item = kunfig_down (Item, KUNFIG_LOCAL);
while (Item)
{
char Name [256];
char * Value;
char * Rule_Name = kunfig_getname (Item);
/* Récupération de la classe de la règle */
sprintf (Name, "%s:%s:class", Kunf_Name, Rule_Name);
Value = kunfig_directfindvalue (KUNFIG_LOCAL, Name);
if (!Value)
{
sprintf (TL_Error_Msg, "Error TL_RTab_Add : class is missing in section \"%s\"", Name);
TL_Error_Print ();
LOG_RTab_Free (RTab);
return TLS_KO;
}
if (!strcmp (Value, "ALL"))
RuleClass = LOGD_SELECT_ALL;
else if (!strcmp (Value, "GRV"))
RuleClass = LOGD_SELECT_GRV;
else if (!strcmp (Value, "RC"))
RuleClass = LOGD_SELECT_RC;
else if (!strcmp (Value, "TYPE"))
RuleClass = LOGD_SELECT_TYPE;
else
{
sprintf (TL_Error_Msg, "Error TL_RTab_Add : unknown class \"%s\" in section \"%s\"", Value, Name);
TL_Error_Print ();
LOG_RTab_Free (RTab);
return TLS_KO;
}
/* Récupération de la règle */
if (RuleClass != LOGD_SELECT_ALL)
{
sprintf (Name, "%s:%s:rule", Kunf_Name, Rule_Name);
Value = kunfig_directfindvalue (KUNFIG_LOCAL, Name);
if (!Value)
{
sprintf (TL_Error_Msg, "Error TL_RTab_Add : rule is missing in section \"%s\"", Name);
TL_Error_Print ();
LOG_RTab_Free (RTab);
return TLS_KO;
}
}
/* Vérifications d'usage sur la règle */
if (RuleClass == LOGD_SELECT_GRV)
{
LOGT_Gravite Gravite;
if (!strcmp (Value, "INFO"))
{
Gravite = LOGD_GRV_INFO;
Rule = (LOGT_Rule *)(&Gravite);
}
else if (!strcmp (Value, "TRACE"))
{
Gravite = LOGD_GRV_TRACE;
Rule = (LOGT_Rule *)(&Gravite);
}
else if (!strcmp (Value, "FONCT"))
{
Gravite = LOGD_GRV_FONCT;
Rule = (LOGT_Rule *)(&Gravite);
}
else if (!strcmp (Value, "DETAIL"))
{
Gravite = LOGD_GRV_DETAIL;
Rule = (LOGT_Rule *)(&Gravite);
}
else if (!strcmp (Value, "STAT"))
{
Gravite = LOGD_GRV_STAT;
Rule = (LOGT_Rule *)(&Gravite);
}
else if (!strcmp (Value, "ERR"))
{
Gravite = LOGD_GRV_ERR;
Rule = (LOGT_Rule *)(&Gravite);
}
else if (!strcmp (Value, "REJDON"))
{
Gravite = LOGD_GRV_REJDON;
Rule = (LOGT_Rule *)(&Gravite);
}
else if (!strcmp (Value, "REJENR"))
{
Gravite = LOGD_GRV_REJENR;
Rule = (LOGT_Rule *)(&Gravite);
}
else if (!strcmp (Value, "WARNING"))
{
Gravite = LOGD_GRV_WARNING;
Rule = (LOGT_Rule *)(&Gravite);
}
else if (!strcmp (Value, "RECYCLE"))
{
Gravite = LOGD_GRV_RECYCLE;
Rule = (LOGT_Rule *)(&Gravite);
}
else if (!strcmp (Value, "EXIT"))
{
Gravite = LOGD_GRV_EXIT;
Rule = (LOGT_Rule *)(&Gravite);
}
else if (!strcmp (Value, "ABEND"))
{
Gravite = LOGD_GRV_ABEND;
Rule = (LOGT_Rule *)(&Gravite);
}
else
{
sprintf (TL_Error_Msg, "Error TL_RTab_Add : bad rule \"%s\" in section \"%s\"", Value, Name);
TL_Error_Print ();
LOG_RTab_Free (RTab);
return TLS_KO;
}
}
else if (RuleClass == LOGD_SELECT_RC)
{
LOGT_RC RC;
if (!strcmp (Value, "OK"))
{
RC = LOGD_RC_OK;
Rule = (LOGT_Rule *)(&RC);
}
else if (!strcmp (Value, "ANOERR"))
{
RC = LOGD_RC_ANOERR;
Rule = (LOGT_Rule *)(&RC);
}
else if (!strcmp (Value, "REJDON"))
{
RC = LOGD_RC_REJDON;
Rule = (LOGT_Rule *)(&RC);
}
else if (!strcmp (Value, "REJENR"))
{
RC = LOGD_RC_REJENR;
Rule = (LOGT_Rule *)(&RC);
}
else if (!strcmp (Value, "WARNING"))
{
RC = LOGD_RC_WARNING;
Rule = (LOGT_Rule *)(&RC);
}
else if (!strcmp (Value, "RECYCLE"))
{
RC = LOGD_RC_RECYCLE;
Rule = (LOGT_Rule *)(&RC);
}
else if (!strcmp (Value, "EXIT"))
{
RC = LOGD_RC_EXIT;
Rule = (LOGT_Rule *)(&RC);
}
else if (!strcmp (Value, "ABEND"))
{
RC = LOGD_RC_ABEND;
Rule = (LOGT_Rule *)(&RC);
}
else
{
sprintf (TL_Error_Msg, "Error TL_RTab_Add : bad rule \"%s\" in section \"%s\"", Value, Name);
TL_Error_Print ();
LOG_RTab_Free (RTab);
return TLS_KO;
}
}
else if (RuleClass == LOGD_SELECT_TYPE)
{
/* La section kunf ne peut pas comporter le caractère ':' qui a donc été remplacé par "{2pts}" */
strcpy (sRule, Value);
while ((ptr = strstr (sRule, "{2pts}")) )
{
char Tmp [256];
strcpy (Tmp, ptr + 6);
*ptr = ':';
ptr++;
*ptr = (char)0;
strcat (sRule, Tmp);
}
Rule = (LOGT_Rule *)sRule;
}
/* Récupération du routage de la règle */
sprintf (Name, "%s:%s:rooting", Kunf_Name, Rule_Name);
Value = kunfig_directfindvalue (KUNFIG_LOCAL, Name);
if (!Value)
{
sprintf (TL_Error_Msg, "Error TL_RTab_Add : rooting is missing in section \"%s\"", Name);
TL_Error_Print ();
LOG_RTab_Free (RTab);
return TLS_KO;
}
Rooting = 0;
if (strstr (Value, "DATABASE")) Rooting += LOGD_ROOTING_DATABASE;
if (strstr (Value, "NULL")) Rooting += LOGD_ROOTING_NULL;
if (strstr (Value, "STDERR")) Rooting += LOGD_ROOTING_STDERR;
if (strstr (Value, "PREVIOUS")) Rooting += LOGD_ROOTING_PREVIOUS;
if (strstr (Value, "DEFAULT")) Rooting += LOGD_ROOTING_DEFAULT;
if (Rooting == 0)
{
sprintf (TL_Error_Msg, "Error TL_RTab_Add : bad rooting \"%s\" in section \"%s\"", Value, Name);
TL_Error_Print ();
LOG_RTab_Free (RTab);
return TLS_KO;
}
/* Mise à jour de la table de routage */
if (LOG_RTab_Setup (RTab, RuleClass, Rule, Rooting) != LOGS_OK)
{
sprintf (TL_Error_Msg, "Error TL_RTab_Add : unable to apply rule %s to the rooting table", Rule_Name);
TL_Error_Print ();
LOG_RTab_Free (RTab);
return TLS_KO;
}
Item = kunfig_next (Item, KUNFIG_LOCAL);
}
/* Ajout de la table de routage au channel */
if (LOG_RTab_Add (My_Channel, RTab) != LOGS_OK)
{
sprintf (TL_Error_Msg, "Error TL_RTab_Add : unable to add rooting table %s to the channel", RTab_Name);
TL_Error_Print ();
LOG_RTab_Free (RTab);
return TLS_KO;
}
return TLS_OK;
}
/*------------------------------------------------------------------------------*/
/* Ajout d'un trigger à un channel */
/*------------------------------------------------------------------------------*/
/* (I) Channel : pointeur sur le channel */
/* (I) Kunf_Name : nom de la section kunf du trigger */
/*------------------------------------------------------------------------------*/
TLT_Status TL_Trigger_Add (LOGT_Channel * My_Channel, char * Kunf_Name)
{
LOGT_Trigger * Trigger;
LOGT_RTab * RTab;
char Type_Evt [256];
LOGT_Flags Mode;
LOGT_Flags Type;
LOGT_RTab Tmp_RTab;
NDT_Node * Node;
char Name [256];
char * Value;
/* Récupération du type d'événement déclencheur du trigger (expression régulière) */
sprintf (Name, "%s:event", Kunf_Name);
Value = kunfig_directfindvalue (KUNFIG_LOCAL, Name);
if (!Value)
{
sprintf (TL_Error_Msg, "Error TL_Trigger_Add : missing trigger event type in section \"%s\"", Kunf_Name);
TL_Error_Print ();
return TLS_KO;
}
else
{
char * ptr;
/* La section kunf ne peut pas comporter le caractère ':' qui a donc été remplacé par "{2pts}" */
strcpy (Type_Evt, Value);
while ((ptr = strstr (Type_Evt, "{2pts}")) )
{
char Tmp [256];
strcpy (Tmp, ptr + 6);
*ptr = ':';
ptr++;
*ptr = (char)0;
strcat (Type_Evt, Tmp);
}
}
/* Récupération du type du trigger */
sprintf (Name, "%s:type", Kunf_Name);
Value = kunfig_directfindvalue (KUNFIG_LOCAL, Name);
if (!Value)
{
sprintf (TL_Error_Msg, "Error TL_Trigger_Add : missing trigger type in section \"%s\"", Kunf_Name);
TL_Error_Print ();
return TLS_KO;
}
/* Vérifications d'usage sur le type */
if (!strcmp (Value, "ADD"))
Type = LOGD_ADD;
else if (!strcmp (Value, "REMOVE"))
Type = LOGD_REMOVE;
else
{
sprintf (TL_Error_Msg, "Error TL_Trigger_Add : bad trigger type \"%s\" in section \"%s\"", Value, Kunf_Name);
TL_Error_Print ();
return TLS_KO;
}
/* Récupération du mode de fonctionnement du trigger */
sprintf (Name, "%s:mode", Kunf_Name);
Value = kunfig_directfindvalue (KUNFIG_LOCAL, Name);
if (!Value)
{
sprintf (TL_Error_Msg, "Error TL_Trigger_Add : missing trigger mode in section \"%s\"", Kunf_Name);
TL_Error_Print ();
return TLS_KO;
}
/* Vérifications d'usage sur le mode */
if (!strcmp (Value, "ONE_SHOT"))
Mode = LOGD_ONE_SHOT;
else if (!strcmp (Value, "PERMANENT"))
Mode = LOGD_PERMANENT;
else
{
sprintf (TL_Error_Msg, "Error TL_Trigger_Add : bad trigger mode \"%s\" in section \"%s\"", Value, Kunf_Name);
TL_Error_Print ();
return TLS_KO;
}
/* Récupération de la table de routage concernée */
sprintf (Name, "%s:rooting_table", Kunf_Name);
Value = kunfig_directfindvalue (KUNFIG_LOCAL, Name);
if (!Value)
{
sprintf (TL_Error_Msg, "Error TL_Trigger_Add : missing trigger rooting table in section \"%s\"", Kunf_Name);
TL_Error_Print ();
}
sprintf (Name, "%s_%d_%ld_%d", Value, My_Channel->ModuleId, My_Channel->Pid, My_Channel->Id);
Tmp_RTab.Name = Name;
/* Recherche de la table de routage dans la liste de la base */
if (DS_Node_Find (LOG_Base->URT_List, &Node, (void *)(&Tmp_RTab), NULL) != DSS_OK)
{
sprintf (TL_Error_Msg, "Error TL_Trigger_Add : rooting table \"%s\" is undefined", Value);
TL_Error_Print ();
return TLS_KO;
}
RTab = (LOGT_RTab *)(Node->Value);
/* Création du trigger */
if (LOG_Trigger_Add (&Trigger, My_Channel, RTab, Type_Evt, Type | Mode) != LOGS_OK)
{
sprintf (TL_Error_Msg, "Error TL_Trigger_Add : unable to create trigger %s", Kunf_Name);
TL_Error_Print ();
return TLS_KO;
}
return TLS_OK;
}
/*------------------------------------------------------------------------------*/
/* Routine d'affichage d'un message d'erreur */
/*------------------------------------------------------------------------------*/
void TL_Error_Print ( void )
{
if (TL_stderr) fprintf (TL_stderr, "%s\n", TL_Error_Msg);
}
/*------------------------------------------------------------------------------*/
/* Routine d'affichage d'un message d'information */
/*------------------------------------------------------------------------------*/
void TL_Info_Print ( void )
{
fprintf (stdout, "%s\n", TL_Info_Msg);
}
/*------------------------------------------------------------------------------*/
/* Récupération des paramétres */
/*------------------------------------------------------------------------------*/
TLT_Status TL_Param_Get ( void )
{
char * Login, * Pwd, * Sid, * Kunf_Name, * Env;
char Name [256];
if (kunfig_open (NULL, KUNFIG_OPEN_SIMPLEACCESS|KUNFIG_OPEN_OVERRIDINGENV) != KUNFIG_ERROR_NONE)
{
sprintf (TL_Error_Msg, "Error TL_Param_Get : unable to open kunfig file");
TL_Error_Print ();
return TLS_KO;
}
if ((Env = getenv ("BDM_PROFILE")) )
{
Kunf_Name = (char * )malloc ( strlen ("ADMIN:INSTALL_SUIVI") + strlen (Env) + 2);
sprintf (Kunf_Name, "ADMIN:INSTALL_SUIVI:%s", Env);
}
else
Kunf_Name = strdup ("ADMIN:INSTALL_SUIVI");
/* Récupération des paramètres de connexion à la base de suivi */
sprintf (Name, "%s:login", Kunf_Name);
if ((Login = kunfig_directfindvalue (KUNFIG_INHERIT, Name)) == NULL)
{
sprintf (TL_Error_Msg, "Error TL_Param_Get : unable to find %s in KUNF", Name);
TL_Error_Print ();
free (Kunf_Name);
return TLS_KO;
}
sprintf (Name, "%s:password", Kunf_Name);
if ((Pwd = kunfig_directfindvalue (KUNFIG_INHERIT, Name)) == NULL)
{
sprintf (TL_Error_Msg, "Error TL_Param_Get : unable to find %s in KUNF", Name);
TL_Error_Print ();
free (Kunf_Name);
return TLS_KO;
}
if (oracx) free (oracx);
sprintf (Name, "%s:instance", Kunf_Name);
if ((Sid = kunfig_directfindvalue (KUNFIG_INHERIT, Name)) )
{
oracx = (char * )malloc (strlen (Login) + strlen (Pwd) + strlen (Sid) + 3);
sprintf (oracx, "%s/%s@%s", Login, Pwd, Sid);
}
else
{
oracx = (char * )malloc (strlen (Login) + strlen (Pwd) + 2);
sprintf (oracx, "%s/%s", Login, Pwd);
}
free (Kunf_Name);
kunfig_close ();
return TLS_OK;
}
/*------------------------------------------------------------------------------*/
/* Suppression des espaces en début et fin de chaîne des caractères */
/*------------------------------------------------------------------------------*/
char * trim (char * str)
{
char * ptr1, * ptr2;
ptr1 = ptr2 = str;
while (*ptr1 == ' ') ptr1++;
if (ptr1 != str)
{
while (*ptr1 != '\0')
{
*ptr2 = *ptr1;
ptr2++;
ptr1++;
}
*ptr2 = *ptr1;
}
else
{
while (*ptr1 != '\0') ptr1++;
ptr2 = ptr1;
}
if (ptr2 > str)
{
ptr2--;
while (*ptr2 == ' ') ptr2--;
ptr2++;
*ptr2 = '\0';
}
return (str);
}
/*------------------------------------------------------------------------------*/
/* Récupération du message Oracle */
/*------------------------------------------------------------------------------*/
char * Oracle_Message_Get ( void )
{
size_t buf_len, oracle_text_len;
static char oracle_text [200];
buf_len = sizeof (oracle_text);
sqlglm (oracle_text, &buf_len, &oracle_text_len);
trim (oracle_text);
return oracle_text;
}