|
From: <jgr...@us...> - 2003-03-03 22:02:09
|
Update of /cvsroot/popfile/engine/POPFile
In directory sc8-pr-cvs1:/tmp/cvs-serv19388/POPFile
Modified Files:
Configuration.pm Logger.pm Module.pm
Log Message:
Fix up the constructors so that they call the parent classes, add new parameter method to POPFile::Configuration, fix up calls to child and flush_child_data for proxies; various other minor tweaks. With this commit POPFile OO is limping along... my guess is the next commit and you'll be able to try it out
Index: Configuration.pm
===================================================================
RCS file: /cvsroot/popfile/engine/POPFile/Configuration.pm,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** Configuration.pm 3 Mar 2003 15:21:44 -0000 1.8
--- Configuration.pm 3 Mar 2003 22:01:32 -0000 1.9
***************
*** 28,41 ****
{
my $type = shift;
! my $self;
!
# All the current configuration parameters are stored in this hash which
# is intended to be globally accessed by modules that make use of this module,
# to register a configuration default entries are made in this hash in the form
#
! # $self->{configuration}{parameter}
! $self->{configuration} = {};
!
! return bless $self, $type;
}
--- 28,45 ----
{
my $type = shift;
! my $self = POPFile::Module->new();
!
# All the current configuration parameters are stored in this hash which
# is intended to be globally accessed by modules that make use of this module,
# to register a configuration default entries are made in this hash in the form
#
! # $self->{configuration_parameters__}{parameter}
! $self->{configuration_parameters__} = {};
!
! bless $self, $type;
!
! $self->name( 'config' );
!
! return $self;
}
***************
*** 53,59 ****
# This is the location where we store the PID of POPFile in a file
# called popfile.pid
!
! $self->{configuration}{piddir} = './';
!
return 1;
}
--- 57,63 ----
# This is the location where we store the PID of POPFile in a file
# called popfile.pid
!
! $self->config_( 'piddir', './' );
!
return 1;
}
***************
*** 70,74 ****
my ( $self ) = @_;
! if ( open PID, ">$self->{configuration}{piddir}popfile.pid" ) {
print PID "$$\n";
close PID;
--- 74,78 ----
my ( $self ) = @_;
! if ( open PID, '>' . $self->config_( 'piddir' ) . 'popfile.pid' ) {
print PID "$$\n";
close PID;
***************
*** 88,144 ****
{
my ( $self ) = @_;
-
- unlink( "$self->{configuration}{piddir}popfile.pid" );
- }
! # ---------------------------------------------------------------------------------------------
! #
! # name
! #
! # Called to get the simple name for this module
! #
! # ---------------------------------------------------------------------------------------------
! sub name
! {
! my ( $self ) = @_;
!
! return 'config';
! }
!
! # ---------------------------------------------------------------------------------------------
! #
! # service
! #
! #
! # ---------------------------------------------------------------------------------------------
! sub service
! {
! my ( $self ) = @_;
!
! return 1;
! }
!
! # ---------------------------------------------------------------------------------------------
! #
! # forked
! #
! # Called when someone forks POPFile
! #
! # ---------------------------------------------------------------------------------------------
! sub forked
! {
! my ( $self ) = @_;
! }
!
! # ---------------------------------------------------------------------------------------------
! #
! # reaper
! #
! # Called to reap our dead children
! #
! # ---------------------------------------------------------------------------------------------
! sub reaper
! {
! my ( $self ) = @_;
}
--- 92,97 ----
{
my ( $self ) = @_;
! unlink( $self->config_( 'piddir' ) . 'popfile.pid' );
}
***************
*** 152,156 ****
#
# ---------------------------------------------------------------------------------------------
! sub parse_command_line
{
my ( $self ) = @_;
--- 105,109 ----
#
# ---------------------------------------------------------------------------------------------
! sub parse_command_line
{
my ( $self ) = @_;
***************
*** 159,173 ****
# the default values defined at the start of the code and those read from the configuration
# file
!
if ( $#ARGV >= 0 ) {
my $i = 0;
!
while ( $i < $#ARGV ) {
# A command line argument must start with a -
!
if ( $ARGV[$i] =~ /^-(.+)$/ ) {
! if ( defined($self->{configuration}{$1}) ) {
if ( $i < $#ARGV ) {
! $self->{configuration}{$1} = $ARGV[$i+1];
$i += 2;
} else {
--- 112,126 ----
# the default values defined at the start of the code and those read from the configuration
# file
!
if ( $#ARGV >= 0 ) {
my $i = 0;
!
while ( $i < $#ARGV ) {
# A command line argument must start with a -
!
if ( $ARGV[$i] =~ /^-(.+)$/ ) {
! if ( defined($self->{configuration_parameters__}{$1}) ) {
if ( $i < $#ARGV ) {
! $self->{configuration_parameters__}{$1} = $ARGV[$i+1];
$i += 2;
} else {
***************
*** 195,210 ****
#
# ---------------------------------------------------------------------------------------------
! sub load_configuration
{
my ( $self ) = @_;
!
if ( open CONFIG, "<popfile.cfg" ) {
while ( <CONFIG> ) {
s/(\015|\012)//g;
if ( /(\S+) (.+)/ ) {
! $self->{configuration}{$1} = $2;
}
}
!
close CONFIG;
}
--- 148,163 ----
#
# ---------------------------------------------------------------------------------------------
! sub load_configuration
{
my ( $self ) = @_;
!
if ( open CONFIG, "<popfile.cfg" ) {
while ( <CONFIG> ) {
s/(\015|\012)//g;
if ( /(\S+) (.+)/ ) {
! $self->{configuration_parameters__}{$1} = $2;
}
}
!
close CONFIG;
}
***************
*** 218,235 ****
#
# ---------------------------------------------------------------------------------------------
! sub save_configuration
{
my ( $self ) = @_;
if ( open CONFIG, ">popfile.cfg" ) {
! foreach my $key (keys %{$self->{configuration}}) {
! print CONFIG "$key $self->{configuration}{$key}\n";
}
!
close CONFIG;
}
! # TODO work out where this actually needs to be called
! # $classifier->write_parameters();
}
--- 171,208 ----
#
# ---------------------------------------------------------------------------------------------
! sub save_configuration
{
my ( $self ) = @_;
if ( open CONFIG, ">popfile.cfg" ) {
! foreach my $key (keys %{$self->{configuration_parameters__}}) {
! print CONFIG "$key $self->{configuration_parameters__}{$key}\n";
}
!
close CONFIG;
}
+ }
! # ---------------------------------------------------------------------------------------------
! #
! # parameter
! #
! # Gets or sets a parameter
! #
! # $name Name of the parameter to get or set
! # $value Optional value to set the parameter to
! #
! # Always returns the current value of the parameter
! #
! # ---------------------------------------------------------------------------------------------
! sub parameter
! {
! my ( $self, $name, $value ) = @_;
!
! if ( defined( $value ) ) {
! $self->{configuration_parameters__}{$name} = $value;
! }
!
! return $self->{configuration_parameters__}{$name};
}
Index: Logger.pm
===================================================================
RCS file: /cvsroot/popfile/engine/POPFile/Logger.pm,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** Logger.pm 3 Mar 2003 15:21:45 -0000 1.9
--- Logger.pm 3 Mar 2003 22:01:33 -0000 1.10
***************
*** 28,39 ****
sub new
{
! my $proto = shift;
my $class = ref($proto) || $proto;
! my $self = {};
# The name of the debug file
! $self->{debug_filename} = '';
!
bless($self, $class);
return $self;
}
--- 28,42 ----
sub new
{
! my $proto = shift;
my $class = ref($proto) || $proto;
! my $self = POPFile::Module->new();
# The name of the debug file
! $self->{debug_filename__} = '';
!
bless($self, $class);
+
+ $self->name( 'logger' );
+
return $self;
}
***************
*** 51,74 ****
# Start with debugging to file
! $self->{configuration}->{configuration}{debug} = 1;
# The default location for log files
! $self->{configuration}->{configuration}{logdir} = './';
remove_debug_files( $self );
-
- return 1;
- }
-
- # ---------------------------------------------------------------------------------------------
- #
- # start
- #
- # Called to start this module
- #
- # ---------------------------------------------------------------------------------------------
- sub start
- {
- my ( $self ) = @_;
return 1;
--- 54,63 ----
# Start with debugging to file
! $self->config_( 'debug', 1 );
# The default location for log files
! $self->config_( 'logdir', './' );
remove_debug_files( $self );
return 1;
***************
*** 77,106 ****
# ---------------------------------------------------------------------------------------------
#
- # stop
- #
- # Called to shutdown this module
- #
- # ---------------------------------------------------------------------------------------------
- sub stop
- {
- my ( $self ) = @_;
- }
-
- # ---------------------------------------------------------------------------------------------
- #
- # name
- #
- # Called to get the simple name for this module
- #
- # ---------------------------------------------------------------------------------------------
- sub name
- {
- my ( $self ) = @_;
-
- return 'logger';
- }
-
- # ---------------------------------------------------------------------------------------------
- #
# service
#
--- 66,69 ----
***************
*** 118,145 ****
# ---------------------------------------------------------------------------------------------
#
- # forked
- #
- # Called when someone forks POPFile
- #
- # ---------------------------------------------------------------------------------------------
- sub forked
- {
- my ( $self ) = @_;
- }
-
- # ---------------------------------------------------------------------------------------------
- #
- # reaper
- #
- # Called to reap our dead children
- #
- # ---------------------------------------------------------------------------------------------
- sub reaper
- {
- my ( $self ) = @_;
- }
-
- # ---------------------------------------------------------------------------------------------
- #
# remove_debug_files
#
--- 81,84 ----
***************
*** 150,159 ****
{
my ( $self ) = @_;
-
- my $yesterday = defined($self->{today})?$self->{today}:0;
- calculate_today( $self );
! if ( $self->{today} > $yesterday ) {
! my @debug_files = glob "$self->{configuration}->{configuration}{logdir}popfile*.log";
foreach my $debug_file (@debug_files) {
--- 89,98 ----
{
my ( $self ) = @_;
! my $yesterday = defined($self->{today__})?$self->{today__}:0;
! calculate_today__( $self );
!
! if ( $self->{today__} > $yesterday ) {
! my @debug_files = glob $self->config_( 'logdir' ) . 'popfile*.log';
foreach my $debug_file (@debug_files) {
***************
*** 172,182 ****
#
# ---------------------------------------------------------------------------------------------
! sub calculate_today
{
my ( $self ) = @_;
!
# Create the name of the debug file for the debug() function
! $self->{today} = int( time / $seconds_per_day ) * $seconds_per_day;
! $self->{debug_filename} = "$self->{configuration}->{configuration}{logdir}popfile$self->{today}.log";
}
--- 111,121 ----
#
# ---------------------------------------------------------------------------------------------
! sub calculate_today__
{
my ( $self ) = @_;
!
# Create the name of the debug file for the debug() function
! $self->{today__} = int( time / $seconds_per_day ) * $seconds_per_day;
! $self->{debug_filename__} = $self->config_( 'logdir' ) . "popfile$self->{today__}.log";
}
***************
*** 190,198 ****
#
# ---------------------------------------------------------------------------------------------
! sub debug
{
my ( $self, $message ) = @_;
!
! if ( $self->{configuration}->{configuration}{debug} > 0 ) {
# Check to see if we are handling the USER/PASS command and if we are then obscure the
# account information
--- 129,137 ----
#
# ---------------------------------------------------------------------------------------------
! sub debug
{
my ( $self, $message ) = @_;
!
! if ( $self->config_( 'debug' ) > 0 ) {
# Check to see if we are handling the USER/PASS command and if we are then obscure the
# account information
***************
*** 203,215 ****
my $now = localtime;
my $msg = "$now ($$): $message";
!
! if ( $self->{configuration}->{configuration}{debug} & 1 ) {
! open DEBUG, ">>$self->{debug_filename}";
binmode DEBUG;
print DEBUG $msg;
close DEBUG;
}
!
! print $msg if ( $self->{configuration}->{configuration}{debug} & 2 );
}
}
--- 142,154 ----
my $now = localtime;
my $msg = "$now ($$): $message";
!
! if ( $self->config_( 'debug' ) & 1 ) {
! open DEBUG, ">>$self->{debug_filename__}";
binmode DEBUG;
print DEBUG $msg;
close DEBUG;
}
!
! print $msg if ( $self->config_( 'debug' ) & 2 );
}
}
Index: Module.pm
===================================================================
RCS file: /cvsroot/popfile/engine/POPFile/Module.pm,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** Module.pm 3 Mar 2003 15:21:46 -0000 1.2
--- Module.pm 3 Mar 2003 22:01:35 -0000 1.3
***************
*** 224,228 ****
my ( $self, $message ) = @_;
! $self->{logger__}->debug( $self->{name__} . ':' . $message );
}
--- 224,228 ----
my ( $self, $message ) = @_;
! $self->{logger__}->debug( $self->{name__} . ': ' . $message );
}
***************
*** 235,272 ****
# $name The name of the parameter (e.g. 'port')
# $value (optional) The value to set
- # $short_name 1 if the $name should be registered in short form as well
#
# If called with just a $name then config_() will return the current value
! # of the configuration parameter.
! #
! # Short vs Long Names. All configuration parameters are identified by their
! # long name which consists of the individual parameter name preceded by the
! # module name (underscore is used as the separator). For compatbility with
! # older versions of POPFile the configuration module will also recognize some
! # short names (i.e. without the preceding name and underscore) and map automaticall
! # to the long name
! #
! # Example: POP3 registers a parameter for its listen port call port, this is stored
! # in the configuration as pop3_port. POP3 also registers for the short name version
! # which is simply port. When loading the configuration either will be accepted.
! #
! # Note NO NEW PARAMETERS should use short form
#
# ---------------------------------------------------------------------------------------------
sub config_
{
! my ( $self, $name, $value, $short_name ) = @_;
!
! my $long_name = $self->{name__} . '_' . $name;
!
! if ( defined( $value ) ) {
! $self->{configuration__}->{configuration}{$long_name} = $value;
!
! if ( defined( $short_name ) ) {
! $self->{configuration__}->{configuration}{$name} = $value;
! }
! }
! return $self->{configuration__}->{configuration}{$long_name};
}
--- 235,248 ----
# $name The name of the parameter (e.g. 'port')
# $value (optional) The value to set
#
# If called with just a $name then config_() will return the current value
! # of the configuration parameter.
#
# ---------------------------------------------------------------------------------------------
sub config_
{
! my ( $self, $name, $value ) = @_;
! return $self->{configuration__}->parameter( $self->{name__} . '_' . $name, $value );
}
|