#include #include #include #include #include #include #include VER_INFO_EXPORT (logadmin, "$Revision: 1.1 $", "$Name: $", __FILE__, "$Author: smas $") #define USAGE "Usage : %s [ --help | --version [-v] | --create | --destroy | --load [1|2|3] ] | --unload [1|2|3] ]\n" typedef struct { double sec; struct timeval start; struct timeval stop; } cpt; #define t_start(x){gettimeofday(&(x.start), NULL);} #define t_stop(x){gettimeofday(&(x.stop), NULL); x.sec = (double)(x.stop.tv_sec) - (double)(x.start.tv_sec) + ((double)(x.stop.tv_usec) - (double)(x.start.tv_usec)) / 1000000;} cpt t_exec; #define QUIT 0 #define BASE_INIT 1 #define BASE_OPEN 2 #define BASE_INFO 3 #define BASE_CLOSE 4 #define BASE_END 5 #define BASE_LOAD 6 #define BASE_UNLOAD 7 #define SHOW_CHANNEL_LIST 8 #define SHOW_RTAB_LIST 9 #define CHANNEL_DUMP 10 #define RTAB_DUMP 11 #define TEST_EVENT 12 char menu [1000]; char tmp [100]; void init_menu (void); int print_menu (void); char * Get_Rooting (LOGT_Rooting); char * Get_RC (LOGT_RC); int main (int argc, char ** argv) { int choice, i; char Name [100]; LOGT_Channel * My_Channel; char Answer[10]; NDT_Node * Node; NDT_Root * Root; LOGT_RTab RTab; int Mode; LOGT_Info * Info; TL_Library_Stderr_Set (stderr); /* Lancement de commande d'administration ? */ if (argc >= 2) { if (!strcmp (argv [1], "--help")) { fprintf (stderr, USAGE, argv [0]); return -1; } else if (!strcmp (argv [1], "--version")) { if (argc >= 3 && !strcmp (argv [2], "-v")) return VER_Object_Print (stdout, VERD_VERBOSE); else return VER_Object_Print (stdout, VERD_MINIMAL); } else if (!strcmp (argv [1], "--create")) { if (SM_Library_Open (0, NULL, SMD_OPEN | SMD_DEBUG_ALL) != SMS_OK) { fprintf (stderr, "=> Impossible d'ouvrir l'instance de la LIBSHMEM\n"); return -1; } if (LOG_Library_Open (0, NULL, LOGD_CREATE | SMD_DEBUG_ALL) != LOGS_OK) { fprintf (stderr, "=> Création de la LIBLOG impossible\n"); return -1; } return 0; } else if (!strcmp (argv [1], "--load")) { Mode = 0; if (argc > 2) { if (strchr (argv [2], '1')) Mode += TLD_KMOD; if (strchr (argv [2], '2')) Mode += TLD_KFORMAT; if (strchr (argv [2], '3')) Mode += TLD_GDRT; } if (LOG_Library_Open (0, NULL, LOGD_OPEN | SMD_DEBUG_ALL) != LOGS_OK) { fprintf (stderr, "=> Ouverture de la LIBLOG impossible\n"); return -1; } if (TL_LIBLOG_Load (Mode) != LOGS_OK) { fprintf (stderr, "=> Chargement de la LIBLOG impossible\n"); return -1; } return 0; } else if (!strcmp (argv [1], "--unload")) { Mode = 0; if (argc > 2) { if (strchr (argv [2], '1')) Mode += TLD_KMOD; if (strchr (argv [2], '2')) Mode += TLD_KFORMAT; if (strchr (argv [2], '3')) Mode += TLD_GDRT; } if (LOG_Library_Open (0, NULL, LOGD_OPEN | SMD_DEBUG_ALL) != LOGS_OK) { fprintf (stderr, "=> Ouverture de la LIBLOG impossible\n"); return -1; } if (TL_LIBLOG_Unload (Mode) != LOGS_OK) { fprintf (stderr, "=> Déchargement de la LIBLOG impossible\n"); return -1; } return 0; } else if (!strcmp (argv [1], "--destroy")) { if (LOG_Library_Open (0, NULL, LOGD_OPEN | SMD_DEBUG_ALL) != LOGS_OK) { fprintf (stderr, "=> Ouverture de la LIBLOG à détruire impossible\n"); return -1; } if (LOG_Library_Close (LOGD_DESTROY) != LOGS_OK) { fprintf (stderr, "=> Destruction de la LIBLOG impossible\n"); return -1; } return 0; } else { fprintf (stderr, USAGE, argv [0]); return -1; } } /* Lancement du menu intercatif */ init_menu (); choice = print_menu (); while (choice != QUIT) { strcpy (Answer, "yes"); switch (choice) { case BASE_INIT: fprintf (stdout, "\nReturn code = %s\n", \ LOG_Library_Open (0, NULL, LOGD_CREATE | SMD_DEBUG_ALL) == LOGS_OK ? "OK" : "NOK" ); break; case BASE_OPEN: fprintf (stdout, "\nReturn code = %s\n", \ LOG_Library_Open (0, NULL, LOGD_OPEN | SMD_DEBUG_ALL) == LOGS_OK ? "OK" : "NOK" ); break; case BASE_END: fprintf (stdout, "\nReturn code = %s\n", \ LOG_Library_Close (LOGD_DESTROY) == LOGS_OK ? "OK" : "NOK" ); break; case BASE_CLOSE: fprintf (stdout, "\nReturn code = %s\n", \ LOG_Library_Close (LOGD_CLOSE) == LOGS_OK ? "OK" : "NOK" ); break; case BASE_INFO: DS_DataStruct_Info_Print (LOG_Base->KMOD, stdout); DS_DataStruct_Info_Print (LOG_Base->KFORMAT, stdout); DS_DataStruct_Info_Print (LOG_Base->GDRT->Root, stdout); DS_DataStruct_Info_Print (LOG_Base->LMRT_List, stdout); DS_DataStruct_Info_Print (LOG_Base->LDRT_List, stdout); DS_DataStruct_Info_Print (LOG_Base->URT_List, stdout); DS_DataStruct_Info_Print (LOG_Base->Channel_List, stdout); break; case BASE_LOAD: fprintf (stdout, "\nCache to load ? (KMOD=1, KFORMAT=2, GDRT=3) "); gets (Name); Mode = 0; if (strchr (Name, '1')) Mode |= TLD_KMOD; if (strchr (Name, '2')) Mode += TLD_KFORMAT; if (strchr (Name, '3')) Mode += TLD_GDRT; fprintf (stdout, "\nReturn code = %s\n", TL_LIBLOG_Load (Mode) == LOGS_OK ? "OK" : "NOK" ); break; case BASE_UNLOAD: fprintf (stdout, "\nCache to unload ? (KMOD=1, KFORMAT=2, GDRT=3) "); gets (Name); Mode = 0; if (strchr (Name, '1')) Mode += TLD_KMOD; if (strchr (Name, '2')) Mode += TLD_KFORMAT; if (strchr (Name, '3')) Mode += TLD_GDRT; fprintf (stdout, "\nReturn code = %s\n", TL_LIBLOG_Unload (Mode) == LOGS_OK ? "OK" : "NOK" ); break; case SHOW_RTAB_LIST: DS_DataStruct_Print (LOG_Base->LMRT_List, stdout); DS_DataStruct_Print (LOG_Base->LDRT_List, stdout); DS_DataStruct_Print (LOG_Base->URT_List, stdout); break; case SHOW_CHANNEL_LIST: DS_DataStruct_Print (LOG_Base->Channel_List, stdout); break; case CHANNEL_DUMP: fprintf (stdout, "\nChannel address ? "); gets (Name); i = atoi (Name); if (DS_Node_Find (LOG_Base->Channel_List, &Node, (void *)i, NULL) != DSS_OK) fprintf (stdout, "Unable to find channel at address %d\n", i); else { My_Channel = (LOGT_Channel *)(Node->Value); ND_Manager_Exec (LOG_Base->Channel_List->Manager, NDD_CMD_PRINT_VALUE, &My_Channel, stdout); if (fprintf (stdout, "\n\nShow rooting tables ? (y/n) ") && gets (tmp) && *tmp == 'y') DS_DataStruct_Print (My_Channel->RTab_List, stdout); if (fprintf (stdout, "\nShow submodules ? (y/n) ") && gets (tmp) && *tmp == 'y') DS_DataStruct_Print (My_Channel->SubModule_List, stdout); if (fprintf (stdout, "\nShow triggers ? (y/n) ") && gets (tmp) && *tmp == 'y') DS_DataStruct_Print (My_Channel->Trigger_List, stdout); if (fprintf (stdout, "\nShow event counters ? (y/n) ") && gets (tmp) && *tmp == 'y') DS_DataStruct_Print (My_Channel->Event_Cpt_List, stdout); } break; case RTAB_DUMP: fprintf (stdout, "\nTable Name ? "); gets (Name); RTab.Name = Name; if ((DS_Node_Find (LOG_Base->LMRT_List, &Node, &RTab, NULL) == DSS_OK && (Root = LOG_Base->LMRT_List)) || (DS_Node_Find (LOG_Base->LDRT_List, &Node, &RTab, NULL) == DSS_OK && (Root = LOG_Base->LDRT_List)) || (DS_Node_Find (LOG_Base->URT_List, &Node, &RTab, NULL) == DSS_OK && (Root = LOG_Base->URT_List))) { ND_Manager_Exec (Root->Manager, NDD_CMD_PRINT_VALUE, (void **)&(Node->Value), stdout); if (fprintf (stdout, "\n\nShow events ? (y/n) ") && gets (tmp) && *tmp == 'y') DS_DataStruct_Print (((LOGT_RTab *)(Node->Value))->Root, stdout); } else fprintf (stdout, "\nUnable to find rooting table \"%s\"\n", Name); break; case TEST_EVENT: fprintf (stdout, "\nEvent name ? "); gets (Name); Info = (LOGT_Info *)malloc(sizeof(LOGT_Info)); t_start (t_exec); if (LOG_Event_Info_Get(NULL, &Info, Name) != LOGS_OK) { fprintf (stdout, "\nEvénement \"%s\" non résolu\n", Name); t_stop (t_exec); } else { t_stop (t_exec); fprintf (stdout, "\nEvénement \"%s\" résolu en %.4f sec :\n", Name, t_exec.sec); fprintf (stdout, "\t- Type : %s (%d)\n", Info->Event_Name, Info->Event_Type); fprintf (stdout, "\t- Routage : %s\n", Get_Rooting(Info->Rooting)); fprintf (stdout, "\t- Gravité : %c\n", (char)Info->Gravite); fprintf (stdout, "\t- Code retour : %s\n", Get_RC(Info->RC)); fprintf (stdout, "\t- Format :"); if (Info->Data_List) { ND_Node_First_Get(Info->Data_List, &Node); i = 0; while (Node) { if (i > 0) fprintf (stdout, ","); fprintf (stdout, " %s", (char *)(Node->Value)); ND_Node_Next_Get (Node, &Node); i++; } } fprintf (stdout, "\n\n"); } free(Info); break; case QUIT: fprintf (stdout, "\nExiting program ...\n"); break; default: fprintf (stdout, "\nUndefined choice %d\n", choice); } choice = print_menu (); } return 0; } void init_menu (void) { sprintf (menu, "Menu :\n"); sprintf (tmp, " - %2d) %-25s", QUIT, "Quit"); strcat (menu, tmp); sprintf (tmp, " - %2d) %-25s\n", BASE_INIT, "Init library"); strcat (menu, tmp); sprintf (tmp, " - %2d) %-25s", BASE_OPEN, "Open library"); strcat (menu, tmp); sprintf (tmp, " - %2d) %-25s\n", BASE_INFO, "Info library"); strcat (menu, tmp); sprintf (tmp, " - %2d) %-25s", BASE_CLOSE, "Close library"); strcat (menu, tmp); sprintf (tmp, " - %2d) %-25s\n", BASE_END, "End library"); strcat (menu, tmp); sprintf (tmp, " - %2d) %-25s", BASE_LOAD, "Load library cache"); strcat (menu, tmp); sprintf (tmp, " - %2d) %-25s\n", BASE_UNLOAD, "Unload library cache"); strcat (menu, tmp); sprintf (tmp, " - %2d) %-25s", SHOW_CHANNEL_LIST, "Show channels"); strcat (menu, tmp); sprintf (tmp, " - %2d) %-25s\n", SHOW_RTAB_LIST, "Show rooting tables"); strcat (menu, tmp); sprintf (tmp, " - %2d) %-25s", CHANNEL_DUMP, "Dump a channel"); strcat (menu, tmp); sprintf (tmp, " - %2d) %-25s\n", RTAB_DUMP, "Dump a rooting table"); strcat (menu, tmp); sprintf (tmp, " - %2d) %-25s\n", TEST_EVENT, "Test an event"); strcat (menu, tmp); } int print_menu (void) { fprintf (stdout, "---------------------------------------------------------------------------\n%s", menu); tmp[0] = '\0'; while (tmp[0] == '\0') { printf ("\nChoice ? "); gets (tmp); } return atoi (tmp); } char *Get_Rooting(LOGT_Rooting Rooting) { static char lib[20]; switch ((int)Rooting) { case LOGD_ROOTING_NULL: strcpy(lib, "NULL"); break; case LOGD_ROOTING_STDERR: strcpy(lib, "STDERR"); break; case LOGD_ROOTING_DATABASE: strcpy(lib, "BASE"); break; case LOGD_ROOTING_DEFAULT: strcpy(lib, "DEFAULT"); break; case LOGD_ROOTING_PREVIOUS: strcpy(lib, "PREVIOUS"); break; default: strcpy(lib, "unknown"); break; } return lib; } char *Get_RC(LOGT_RC RC) { static char lib[20]; switch ((int)RC) { case LOGD_RC_OK: strcpy(lib, "OK"); break; case LOGD_RC_ANOERR: strcpy(lib, "ANOERR"); break; case LOGD_RC_REJDON: strcpy(lib, "REJDON"); break; case LOGD_RC_REJENR: strcpy(lib, "REJENR"); break; case LOGD_RC_WARNING: strcpy(lib, "WARNING"); break; case LOGD_RC_RECYCLE: strcpy(lib, "RECYCLE"); break; case LOGD_RC_EXIT: strcpy(lib, "EXIT"); break; case LOGD_RC_ABEND: strcpy(lib, "ABEND"); break; default: strcpy(lib, "unknown"); break; } return lib; }