Commit d548f398 authored by Marc Ariberti's avatar Marc Ariberti

Logs are now available on the telnet interface.

parent 88a473e9
......@@ -5,6 +5,7 @@
HEAD
* Changed the logger system : now there's a list of logging output
referenced by their FILE* associated with a format type (screen/file)
* Logs are now visible on the telnet interface
*
0.0.1
......
......@@ -32,8 +32,8 @@ Task: 0x0c
Difficulty: Medium
Urgency: Normal
Description: LOG: log via telnet
Find a way to have th elogs inside interface.
Status: Todo
Find a way to have the logs inside interface.
Status: Done, Marcari
Task: 0x0b
Difficulty: Easy
......
......@@ -3,7 +3,7 @@
* Provide a telnet interface
*****************************************************************************
* Copyright (C) 1998, 1999, 2000, 2001 VideoLAN
* $Id: telnet.c,v 1.16 2001/04/30 23:32:10 nitrox Exp $
* $Id: telnet.c,v 1.17 2001/05/28 00:49:41 marcari Exp $
*
* Authors: Damien Lucas <nitrox@via.ecp.fr>
*
......@@ -63,6 +63,7 @@ static void Menu_send(int iSocket, struct IF_Menu mMenu);
static ERR_CODE TELNET_stop(int iSocket);
static ERR_CODE TELNET_reload(int iSocket);
static ERR_CODE TELNET_info(int iSocket);
static ERR_CODE TELNET_log(int iSocket);
static char* Catch_Word(int iSocket);
static char* Catch_Passwd(int iSocket);
......@@ -287,7 +288,16 @@ static void Menu_init (struct IF_Menu* mMenu)
mMenu_current->function=TELNET_info;
sprintf(mMenu_current->sName,"info");
sprintf(mMenu_current->sDescr,"Informations for a MAC address");
mMenu_current->next = malloc(sizeof(struct IFT_Command));
mMenu_current = mMenu_current->next;
mMenu_current->iIndex='3';
mMenu_current->function=TELNET_log;
sprintf(mMenu_current->sName,"log");
sprintf(mMenu_current->sDescr,"Draws the logs on the telnet intf");
mMenu_current->next=NULL;
}
......@@ -333,6 +343,58 @@ static ERR_CODE TELNET_info(int iSocket)
return 0;
}
/*****************************************************************************
* TELNET_log()
*****************************************************************************
* Display logs on the telnet ouput until a key is pressed
* TODO : test some err_codes
*****************************************************************************/
static ERR_CODE TELNET_log(int iSocket)
{
FILE * streamOut;
unsigned char bBuff;
char * msg = "<< Press any key to stop logging >>\r\n\r\n";
int end;
Message_send(iSocket, msg, strlen(msg));
/* convertit la socket en flux de donnes */
streamOut=fdopen(iSocket, "w");
/* inscrit le flux correspondant dans la liste du logger*/
LOG_create(streamOut, LOGTYPE_TELNET);
VS_log(LOGINFO, TELNET, "Log stream succesfully opened on telnet intf");
/* attend qu'on appuie sur une touche */
end=0;
while(end==0)
{
read(iSocket, &bBuff, 1);
switch(bBuff)
{
case IAC:
read(iSocket, &bBuff,1);
read(iSocket, &bBuff,1);
break; //TODO Terminal negociation
case '\r':
read(iSocket, &bBuff,1); //Need to read next byte: should be \n
default: // simple key -> end
end=1;
break;
}
}
/* retire le flux de la liste des sorties de log */
LOG_delete(streamOut);
return 0;
}
/*****************************************************************************
* Menu_send()
*****************************************************************************
......
......@@ -3,7 +3,7 @@
* Print a log to a file or to screen
*****************************************************************************
* Copyright (C) 1998, 1999, 2000, 2001 VideoLAN
* $Id: logger.c,v 1.19 2001/05/20 23:12:05 marcari Exp $
* $Id: logger.c,v 1.20 2001/05/28 00:49:41 marcari Exp $
*
* Authors: Damien Lucas <nitrox@via.ecp.fr>
* Marc Ariberti <marcari@via.ecp.fr>
......@@ -43,9 +43,8 @@ static struct LOG_stream * ls_none;
static pthread_mutex_t ptm_log_available;
static int is_log_available=FALSE;
/*****************************************************************************
* VS_log_File : Write a log inside fdLogfile
* VS_log_File : Write a log inside a file
*****************************************************************************/
static void VS_log_File(LOG_LEVELS level,
LOG_MODULES module,
......@@ -162,10 +161,129 @@ static void VS_log_File(LOG_LEVELS level,
#endif
}
/*****************************************************************************
* VS_log_Telnet : formats the ouput to be printed on a telnet intf
*****************************************************************************/
static void VS_log_Telnet(LOG_LEVELS level,
LOG_MODULES module,
struct LOG_stream * output_stream,
char* format,
va_list ap)
{
char MsgBuff[LOGBUFF_MAXSIZE]; /* buffer which will contain
the message wanted to be displayed */
char LineBuff[LOGBUFF_LINESIZE]; /* line currently displayed */
char HeaderBuff[34+20]; /* header of the message + color */
char FooterBuff[20]; /* footer of the message + end color */
int MessagePosition;
int MessageLength;
time_t MsgTime;
struct tm * ptmTime;
#ifndef DEBUG
if(level!=LOGDEBUG)
{
#endif
/* Record the time */
time(&MsgTime);
ptmTime=localtime(&MsgTime);
sprintf(HeaderBuff, "%02i/%02i %02i:%02i:%02i ", ptmTime->tm_mday,
ptmTime->tm_mon+1, ptmTime->tm_hour,
ptmTime->tm_min, ptmTime->tm_sec);
/* Determinate in which module it happened */
switch (module)
{
case SNMP:
sprintf(HeaderBuff+strlen(HeaderBuff), "[SNMP : ");
break;
case SERVER:
sprintf(HeaderBuff+strlen(HeaderBuff), "[SERVER: ");
break;
case DB:
sprintf(HeaderBuff+strlen(HeaderBuff), "[DB : ");
break;
case CFG:
sprintf(HeaderBuff+strlen(HeaderBuff), "[CFG : ");
break;
case IF:
sprintf(HeaderBuff+strlen(HeaderBuff), "[IF : ");
break;
case TELNET:
sprintf(HeaderBuff+strlen(HeaderBuff), "[TELNET: ");
break;
case LOGGER:
sprintf(HeaderBuff+strlen(HeaderBuff), "[LOGGER: ");
break;
}
/* Determinate the error level */
switch (level)
{
case LOGDEBUG:
sprintf(HeaderBuff+strlen(HeaderBuff), "debug ] ");
break;
case LOGINFO:
sprintf(HeaderBuff+strlen(HeaderBuff), "info ] ");
break;
case LOGWARNING:
sprintf(HeaderBuff+strlen(HeaderBuff), "Warning ] ");
break;
case LOGFATAL:
{
sprintf(HeaderBuff+strlen(HeaderBuff), "FATAL ] ");
break;
}
case LOGERROR:
{
sprintf(HeaderBuff+strlen(HeaderBuff), "ERROR ] ");
break;
}
}
/* XXX No error checking ! What length is the message ? */
vsnprintf(MsgBuff, LOGBUFF_MAXSIZE, format, ap);
sprintf(FooterBuff,"\r\n");
pthread_mutex_lock(&output_stream->ptm_log);
fputs(HeaderBuff, output_stream->fd_output);
MessageLength = strlen(MsgBuff);
MessagePosition = 0;
while ( (MessageLength-MessagePosition) > LOGBUFF_LINESIZE )
{
snprintf( LineBuff, LOGBUFF_LINESIZE+1, MsgBuff + MessagePosition );
fputs( LineBuff, output_stream->fd_output );
fputs( "\r\n ", output_stream->fd_output );
MessagePosition += LOGBUFF_LINESIZE;
}
fputs( MsgBuff + MessagePosition, output_stream->fd_output);
fputs(FooterBuff, output_stream->fd_output);
fflush(output_stream->fd_output);
pthread_mutex_unlock(&output_stream->ptm_log);
#ifndef DEBUG
}
#endif
}
/*****************************************************************************
* Write a log on stderr
* Write a log to a screen(-like) output
*****************************************************************************/
static void VS_log_Screen(LOG_LEVELS level,
LOG_MODULES module,
......@@ -321,6 +439,9 @@ void VS_log(LOG_LEVELS level, LOG_MODULES module, char* format, ...)
case LOGTYPE_SCREEN:
VS_log_Screen(level, module, ls_current, format, ap);
break;
case LOGTYPE_TELNET:
VS_log_Telnet(level, module, ls_current, format, ap);
break;
default:
}
ls_current=ls_current->next_stream;
......
......@@ -3,7 +3,7 @@
* Header file for logger.c
*****************************************************************************
* Copyright (C) 1998, 1999, 2000, 2001 VideoLAN
* $Id: logger.h,v 1.12 2001/05/20 23:12:05 marcari Exp $
* $Id: logger.h,v 1.13 2001/05/28 00:49:41 marcari Exp $
*
* Authors: Damien Lucas <nitrox@via.ecp.fr>
* Marc Ariberti <marcari@via.ecp.fr>
......@@ -33,6 +33,7 @@
#define LOGTYPE_NONE 0
#define LOGTYPE_FILE 1
#define LOGTYPE_SCREEN 2
#define LOGTYPE_TELNET 3
/* Structure that represents a log stream :
* there is one structure for each log output
......@@ -40,7 +41,7 @@
* the root element is ls_none
* the last element has next_stream=NULL
* no log is caracterized by : ls_none.next_stream==NULL
* */
*/
struct LOG_stream
{
FILE * fd_output;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment