Commit 30e14b1b authored by Marc Ariberti's avatar Marc Ariberti

* support for color logging when logging to stdout

* added command line support :
    * it is possible to precise a different config file

* upgrade version number to 0.2.0 for the release

* put my ideas in a plain mini TODO file
parent 0012c897
......@@ -11,8 +11,16 @@ C: marcari
D: Remove network part
D: Configuration system
D: Logging system
S: France
N: Christophe Massiot
E: massiot@via.ecp.fr
C: massiot
D: Initial program
D: Initial program
S: France
N: Alexis Guillard
E: alexis.guillard@bt.com
D: IPv6
S: United Kingdom
......@@ -2,10 +2,13 @@
# ChangeLog for miniVLCS #
#========================#
HEAD
0.2.0
Sat, 12 Oct 2002 21:08:53 +0200
* logger, config and network are now C++ objects
* added command line options facility
* color logging
* IPv6 support
* logger, config and network are now C++ objects
* vlcs.c file splited into vlcs.c logger.c and config.c
* More elaborated logging system
* Now takes only the first field (space separated) in the config file
......
......@@ -2,7 +2,7 @@
# vlcs (VideoLAN Channel Server) main Makefile - (c)2001 VideoLAN
###############################################################################
VERSION=0.1.2
VERSION=0.2.0
CC=c++
CFLAGS=-O3 -g -I. -Wall
......
......@@ -3,10 +3,10 @@
* Authors : Marc ARIBERTI <marcari@videolan.org> (current maintainer)
* Christophe MASSIOT <massiot@via.ecp.fr>
*
* Version : 0.1.2
* Version : 0.2.0
*
WARNING: difference with version 0.1.0
WARNING: difference since version 0.1.0
The former vlcs supported the older and the newer vlc syntax for network
streaming (ts:// and udp://). Now you should only use the newer one and upgrade
......@@ -45,6 +45,7 @@ How to install it :
* Decompress the archive
* change into the directory
* edit the vlcs.h and Makefile files, so that it fits your needs
* run 'make'
* edit the vlcs.conf configuration file : (a sample vlcs.conf is given)
- one line per channel
......
* make it a daemon (+write an administration interface, vlcs_ctl ?)
* add arguments to the command line
* port to other OSes
* add an HTML logging output ?
......@@ -2,7 +2,7 @@
* config.c: mini-VideoLAN Channel Server, configuration system
*****************************************************************************
* Copyright (C) 2001 VideoLAN
* $Id: config.c,v 1.5 2002/06/08 22:14:28 marcari Exp $
* $Id: config.c,v 1.6 2002/10/12 19:45:31 marcari Exp $
*
* Authors: Christophe Massiot <massiot@via.ecp.fr>
* Marc Ariberti <marcari@via.ecp.fr>
......@@ -43,8 +43,16 @@
#include "logger.h"
#include "config.h"
C_Config::C_Config(C_Logger &logger) : logger(logger)
C_Config::C_Config(C_Logger &logger)
: logger(logger)
{
m_pszConfigFile = strdup(CHANNEL_CONF);
}
C_Config::~C_Config()
{
DestroyList();
free(m_pszConfigFile);
}
/*
......@@ -63,7 +71,7 @@ void C_Config::DestroyList( void )
}
p_channels = NULL;
logger << INFO << "List of channels initialized" << END;
logger << C_Logger::INFO << "List of channels cleared" << C_Logger::END;
}
char * C_Config::RemoveLF( char * str )
......@@ -107,15 +115,15 @@ void C_Config::AddList( char * psz_item )
i_channel_max++;
logger << INFO << "Adding channel " << i_channel_max << " : "
<< p_new->psz_vlc_config << END;
logger << C_Logger::INFO << "Adding channel " << i_channel_max << " : "
<< p_new->psz_vlc_config << C_Logger::END;
}
time_t C_Config::GetModificationTime( void )
{
struct stat buf;
stat( CHANNEL_CONF, &buf);
stat( m_pszConfigFile, &buf);
return buf.st_mtime;
}
......@@ -130,10 +138,11 @@ void C_Config::ReadFile( void )
st_mtime = GetModificationTime();
p_config = fopen( CHANNEL_CONF, "r" );
p_config = fopen( m_pszConfigFile, "r" );
if( p_config == NULL )
{
logger << ALERT << "Cannot fopen " CHANNEL_CONF " : "<< strerror(errno);
logger << C_Logger::ALERT << "Cannot fopen " << m_pszConfigFile
<< " : "<< strerror(errno) << C_Logger::END;
exit( -1 );
}
......@@ -178,3 +187,9 @@ int C_Config::GetChannelNumber( void )
{
return i_channel_max + 1;
}
void C_Config::SetConfigFile(char * psz_config_file)
{
free(m_pszConfigFile);
m_pszConfigFile = strdup(psz_config_file);
}
......@@ -2,7 +2,7 @@
* config.c: mini-VideoLAN Channel Server, configuration system
*****************************************************************************
* Copyright (C) 2001 VideoLAN
* $Id: config.h,v 1.4 2002/06/08 22:14:28 marcari Exp $
* $Id: config.h,v 1.5 2002/10/12 19:45:31 marcari Exp $
*
* Authors: Christophe Massiot <massiot@via.ecp.fr>
* Marc Ariberti <marcari@via.ecp.fr>
......@@ -33,6 +33,7 @@ class C_Config
{
public:
C_Config(C_Logger &logger);
~C_Config();
void DestroyList( void );
void AddList( char * psz_item );
time_t GetModificationTime( void );
......@@ -41,11 +42,14 @@ public:
void CheckUpdate( void );
int GetChannelNumber( void );
void SetConfigFile(char * psz_config_file);
static char * RemoveLF( char * str );
protected:
int i_channel_max;
C_Logger &logger;
char * m_pszConfigFile;
time_t st_mtime; /* last modification time of the config file */
channel_t * p_channels;
C_Logger &logger;
};
......@@ -2,7 +2,7 @@
* logger.c: VideoLAN Channel Server logging facility
*****************************************************************************
* Copyright (C) 2001 VideoLAN
* $Id: logger.c,v 1.4 2002/06/09 12:34:29 marcari Exp $
* $Id: logger.c,v 1.5 2002/10/12 19:45:31 marcari Exp $
*
* Authors: Marc Ariberti <marcari@via.ecp.fr>
*
......@@ -94,11 +94,13 @@ C_Logger &C_ChainedLogger::operator<<(log_command value)
/* file logger */
C_FileLogger::C_FileLogger(int fd) : log_file(fd)
C_FileLogger::C_FileLogger(int fd, logging_color color)
: log_file(fd), m_color(color)
{
}
C_FileLogger::C_FileLogger(const char * filename) : log_file(filename, ios::app)
C_FileLogger::C_FileLogger(const char * filename, logging_color color)
: log_file(filename, ios::app), m_color(color)
{
}
......@@ -124,21 +126,45 @@ C_Logger &C_FileLogger::operator<<(log_command value)
switch(value)
{
case DEBUG:
if (m_color == LINUX)
{
log_file << "\033[37m";
}
log_file << "DEBUG : ";
break;
case INFO:
if (m_color == LINUX)
{
log_file << "\033[37;1m";
}
log_file << "INFO : ";
break;
case WARNING:
if (m_color == LINUX)
{
log_file << "\033[33;1m";
}
log_file << "WARNING : ";
break;
case ERROR:
if (m_color == LINUX)
{
log_file << "\033[31m";
}
log_file << "ERROR : ";
break;
case ALERT:
if (m_color == LINUX)
{
log_file << "\033[31;1m";
}
log_file << "ALERT : ";
break;
case END:
if (m_color == LINUX)
{
log_file << "\033[0m";
}
log_file << endl;
}
......@@ -146,7 +172,8 @@ C_Logger &C_FileLogger::operator<<(log_command value)
}
/* Standard logger */
C_StdLogger::C_StdLogger() : C_FileLogger(STDERR_FILENO)
C_StdLogger::C_StdLogger(logging_color color)
: C_FileLogger(STDERR_FILENO, color)
{
}
......
......@@ -2,7 +2,7 @@
* logger.h: VideoLAN Channel Server logging facility
*****************************************************************************
* Copyright (C) 2001 VideoLAN
* $Id: logger.h,v 1.4 2002/06/09 12:34:29 marcari Exp $
* $Id: logger.h,v 1.5 2002/10/12 19:45:31 marcari Exp $
*
* Authors: Marc Ariberti <marcari@via.ecp.fr>
*
......@@ -26,11 +26,11 @@
#include <fstream>
#include <string>
typedef enum { DEBUG, INFO, WARNING, ERROR, ALERT, END } log_command;
class C_Logger
{
public:
typedef enum { DEBUG, INFO, WARNING, ERROR, ALERT, END } log_command;
virtual ~C_Logger( void ) = 0;
virtual C_Logger &operator<<(const char * msg) = 0;
virtual C_Logger &operator<<(int value) = 0;
......@@ -70,8 +70,10 @@ protected:
class C_FileLogger : public C_Logger
{
public:
C_FileLogger(int fd);
C_FileLogger(const char * filename);
typedef enum { NO_COLOR, LINUX } logging_color;
C_FileLogger(int fd, logging_color color = NO_COLOR);
C_FileLogger(const char * filename, logging_color color = NO_COLOR);
virtual ~C_FileLogger( void );
virtual C_Logger &operator<<(const char * msg);
......@@ -80,12 +82,13 @@ public:
protected:
ofstream log_file;
logging_color m_color;
};
class C_StdLogger : public C_FileLogger
{
public:
C_StdLogger( void );
C_StdLogger( logging_color color = NO_COLOR );
virtual ~C_StdLogger( void );
};
......@@ -2,7 +2,7 @@
* socket.c: VideoLAN Channel Server network facilities
*****************************************************************************
* Copyright (C) 2001 VideoLAN
* $Id: socket.c,v 1.5 2002/06/09 17:56:17 marcari Exp $
* $Id: socket.c,v 1.6 2002/10/12 19:45:31 marcari Exp $
*
* Authors: Marc Ariberti <marcari@via.ecp.fr>
*
......@@ -62,16 +62,16 @@ C_IPv4Socket::C_IPv4Socket(C_Logger &logger, int port, char * bind_addr = NULL)
if( i_handle < 0 )
{
logger << ALERT << "Cannot open socket (" << strerror(errno)
<< "), exiting" << END;
logger << C_Logger::ALERT << "Cannot open socket (" << strerror(errno)
<< "), exiting" << C_Logger::END;
throw( -1 );
}
if( setsockopt( i_handle, SOL_SOCKET, SO_REUSEADDR, &i_opt, sizeof(i_opt) )
< 0 )
{
logger << ALERT << "Cannot setsockopt (" << strerror(errno)
<< "), exiting" << END;
logger << C_Logger::ALERT << "Cannot setsockopt (" << strerror(errno)
<< "), exiting" << C_Logger::END;
throw( -1 );
}
......@@ -90,8 +90,8 @@ C_IPv4Socket::C_IPv4Socket(C_Logger &logger, int port, char * bind_addr = NULL)
sa_server.sin_port = ntohs( VLCS_PORT );
if( bind( i_handle, (struct sockaddr *)&sa_server, sizeof(sa_server) ) < 0 )
{
logger << ALERT << "Cannot bind (" << strerror(errno) << "), exiting"
<< END;
logger << C_Logger::ALERT << "Cannot bind (" << strerror(errno) << "), exiting"
<< C_Logger::END;
throw( -1 );
}
}
......@@ -110,8 +110,8 @@ void C_IPv4Socket::Reply( char * psz_message )
time(&tm);
/* TODO: remove this ugly kludge */
logger << INFO << C_Config::RemoveLF( asctime( localtime( &tm ))) << " : "
<< Ntop( ) << " => " << psz_message << END;
logger << C_Logger::INFO << C_Config::RemoveLF( asctime( localtime( &tm ))) << " : "
<< Ntop( ) << " => " << psz_message << C_Logger::END;
for( ; ; )
{
if( sendto( i_handle, psz_message, strlen( psz_message ) + 1, 0,
......@@ -122,7 +122,7 @@ void C_IPv4Socket::Reply( char * psz_message )
{
continue;
}
logger << ALERT << "Cannot sendto : " << strerror(errno) << END;
logger << C_Logger::ALERT << "Cannot sendto : " << strerror(errno) << C_Logger::END;
}
break;
}
......@@ -149,16 +149,16 @@ C_IPv6Socket::C_IPv6Socket(C_Logger &logger, int port, char * bind_addr = NULL)
if( i_handle < 0 )
{
logger << ALERT << "Cannot open socket (" << strerror(errno)
<< "), exiting" << END;
logger << C_Logger::ALERT << "Cannot open socket (" << strerror(errno)
<< "), exiting" << C_Logger::END;
throw( -1 );
}
if( setsockopt( i_handle, SOL_SOCKET, SO_REUSEADDR, &i_opt, sizeof(i_opt) )
< 0 )
{
logger << ALERT << "Cannot setsockopt (" << strerror(errno)
<< "), exiting" << END;
logger << C_Logger::ALERT << "Cannot setsockopt (" << strerror(errno)
<< "), exiting" << C_Logger::END;
throw( -1 );
}
......@@ -177,8 +177,8 @@ C_IPv6Socket::C_IPv6Socket(C_Logger &logger, int port, char * bind_addr = NULL)
sa_server.sin6_port = ntohs( VLCS_PORT );
if( bind( i_handle, (struct sockaddr *)&sa_server, sizeof(sa_server) ) < 0 )
{
logger << ALERT << "Cannot bind (" << strerror(errno) << "), exiting"
<< END;
logger << C_Logger::ALERT << "Cannot bind (" << strerror(errno) << "), exiting"
<< C_Logger::END;
throw( -1 );
}
}
......@@ -197,8 +197,8 @@ void C_IPv6Socket::Reply( char * psz_message )
time(&tm);
/* TODO: remove this ugly kludge */
logger << INFO << C_Config::RemoveLF( asctime( localtime( &tm ))) << " : "
<< Ntop( ) << " => " << psz_message << END;
logger << C_Logger::INFO << C_Config::RemoveLF( asctime( localtime( &tm ))) << " : "
<< Ntop( ) << " => " << psz_message << C_Logger::END;
for( ; ; )
{
......
......@@ -2,7 +2,7 @@
* vlcs.c: mini-VideoLAN Channel Server
*****************************************************************************
* Copyright (C) 2001 VideoLAN
* $Id: vlcs.c,v 1.15 2002/06/10 23:20:24 marcari Exp $
* $Id: vlcs.c,v 1.16 2002/10/12 19:45:31 marcari Exp $
*
* Authors: Christophe Massiot <massiot@via.ecp.fr>
* Marc Ariberti <marcari@via.ecp.fr>
......@@ -39,6 +39,7 @@
#include <arpa/inet.h>
#include <signal.h>
#include <time.h>
#include <getopt.h>
#include "vlcs.h"
#include "logger.h"
......@@ -50,6 +51,32 @@
#define VLCS_PROTECTED 2
#define VLCS_FAILED 3
#define COPYRIGHT \
"VideoLAN Mini Channel Server - version 0.2.0 - (c) 2001-2002 VideoLAN\n"
#define HELP \
"Usage : %s [OPTION] [FILE]...\n" \
COPYRIGHT \
"\n" \
"Options :\n" \
" -c, --config-file <filename> changes the configuration file\n"\
" -h, --help display this help and exit\n"\
" -v, --version output version information and exit\n"\
""
/* Long options*/
static const struct option longopts[] =
{
/* name, has_arg, flag, val */
{ "version", 0, 0, 'v' },
{ "help", 0, 0, 'h' },
{ "config-file", 1, 0, 'c' },
{ 0, 0, 0, 0 }
};
/* Short options */
static const char *shortopts = "vhc:";
C_Socket * ip_socket = NULL;
C_Config * config = NULL;
C_ChainedLogger * logger;
......@@ -58,7 +85,7 @@ void Loop( C_Logger &logger ) throw (int)
{
fd_set sockets;
struct timeval timeout;
FD_ZERO( &sockets );
FD_SET( ip_socket->i_handle, &sockets );
FD_SET( 0, &sockets );
......@@ -72,8 +99,8 @@ void Loop( C_Logger &logger ) throw (int)
{
return;
}
logger << ALERT << "Cannot select (" << strerror(errno) << "), exiting"
<< END;
logger << C_Logger::ALERT << "Cannot select (" << strerror(errno) << "), exiting"
<< C_Logger::END;
throw( -1 );
}
......@@ -89,13 +116,12 @@ void Loop( C_Logger &logger ) throw (int)
{
return;
}
logger << ALERT << "Duh my controlling terminal has gone fishing"
<< END;
logger << C_Logger::ALERT << "Duh my controlling terminal has gone fishing" << C_Logger::END;
}
else if( p_buffer[0] == 'q' )
{
/* Quit */
logger << ALERT << "Exiting now on admin's request" << END;
logger << C_Logger::ALERT << "Exiting now on admin's request" << C_Logger::END;
throw( 0 );
}
}
......@@ -117,7 +143,7 @@ void Loop( C_Logger &logger ) throw (int)
{
return;
}
logger << ERROR << "Cannot recvfrom :" << strerror(errno) << END;
logger << C_Logger::ERROR << "Cannot recvfrom :" << strerror(errno) << C_Logger::END;
return;
}
p_buffer[i_len] = '\0';
......@@ -126,14 +152,14 @@ void Loop( C_Logger &logger ) throw (int)
&i_time, psz_macad ) != 4 )
{
ip_socket->Reply( "E: Bad request" );
logger << ERROR << "sscanf failed : " << p_buffer;
logger << C_Logger::ERROR << "sscanf failed : " << p_buffer;
return;
}
if ( i_version < 13 )
{
ip_socket->Reply( "E: Version mismatch, please upgrade your software" );
logger << ALERT << "Break-in attempt ! " << ip_socket->Ntop();
logger << C_Logger::ALERT << "Break-in attempt ! " << ip_socket->Ntop();
return;
}
......@@ -142,14 +168,14 @@ void Loop( C_Logger &logger ) throw (int)
i_channel >= config->GetChannelNumber() )
{
ip_socket->Reply( "E: Channel doesn't exist" );
logger << ERROR << "Bad channel : " << psz_channel;
logger << C_Logger::ERROR << "Bad channel : " << psz_channel;
return;
}
p_channel = config->GetChannel( i_channel );
if( p_channel == NULL )
{
logger << ERROR << "Bad channel : " << psz_channel;
logger << C_Logger::ERROR << "Bad channel : " << psz_channel;
ip_socket->Reply( "E: Channel doesn't exist" );
return;
}
......@@ -184,21 +210,22 @@ int main( int argc, char ** argv )
try
{
logger = new C_ChainedLogger();
config = new C_Config(*logger);
#ifdef LOG_FILE
logger->Add(new C_FileLogger(LOG_FILE));
#endif
#ifdef LOG_STDOUT
logger->Add(new C_StdLogger());
#if LOG_STDOUT == LINUX_COLORS
logger->Add(new C_StdLogger(C_FileLogger::LINUX));
#else
logger->Add(new C_StdLogger(C_FileLogger::NO_COLOR));
#endif
#ifdef SYSLOG_NAME
logger->Add(new C_SysLogger(SYSLOG_NAME, SYSLOG_FACILITY));
#endif
config = new C_Config(*logger);
config->ReadFile();
#ifdef IPV6
# ifdef BIND_ADDRESS
......@@ -213,7 +240,36 @@ int main( int argc, char ** argv )
ip_socket = new C_IPv4Socket(*logger, VLCS_PORT);
# endif
#endif
int opt;
opterr = 0;
while((opt = getopt_long( argc, argv, shortopts, longopts, 0)) != EOF)
{
switch(opt)
{
case 'c':
config->SetConfigFile(optarg);
break;
case 'h':
fprintf(stderr, HELP, *argv);
throw( 0 );
break;
case 'v':
fprintf(stderr, COPYRIGHT);
throw( 0 );
break;
case '?':
fprintf(stderr,"%s: invalid option or missing parameter -- %c\n"
"Try `%s --help' for more information.\n",
*argv, optopt, *argv);
throw( 1 );
break;
}
}
config->ReadFile();
for( ; ; )
{
Loop(*logger);
......
......@@ -2,7 +2,7 @@
* vlcs.h: VideoLAN Channel Server configuration
*****************************************************************************
* Copyright (C) 2001 VideoLAN
* $Id: vlcs.h,v 1.6 2002/06/08 18:09:18 marcari Exp $
* $Id: vlcs.h,v 1.7 2002/10/12 19:45:31 marcari Exp $
*
* Authors: Christophe Massiot <massiot@via.ecp.fr>
* Marc Ariberti <marcari@via.ecp.fr>
......@@ -33,7 +33,11 @@
#define VLCS_PORT 6010
#define CHANNEL_CONF "vlcs.conf"
#define LOG_STDOUT
#define NO_COLORS 0
#define LINUX_COLORS 1
/* undefine this symbol to remove STDOUT logging */
#define LOG_STDOUT LINUX_COLORS
/* undefine this symbol if you do not want to log to a file */
#define LOG_FILE "vlcs.log"
......
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