# LogSQL.pm## Log to an SQL table## Author: Mike McCauley (mikem@open.com.au)# Copyright (C) 1997 Open System Consultants# $Id: LogSQL.pm,v 1.4 2000/11/07 21:18:05 mikem Exp $package Radius::LogSQL;use strict;use File::Path;use File::Basename;use Radius::LogGeneric;use Radius::SqlDb;use vars qw($VERSION @ISA);BEGIN {    @ISA = qw(Radius::LogGeneric Radius::SqlDb);}###################################################################### Contruct a new Session database handler# The most recently created one is remembered in $Session::dbsub new{    my ($class, $file) = @_;    my $self = $class->SUPER::new($file);    return $self;}###################################################################### Do per-instance default initialization# This is called by Configurable during Configurable::new before# the config file is parsed. Its a good place initialize instance # variables# that might get overridden when the config file is parsed.# Do per-instance default initialization. This is called after# construction is completesub initialize{    my ($self) = @_;    $self->Radius::LogGeneric::initialize;    $self->Radius::SqlDb::initialize;    $self->{Table} = 'RADLOG';    # $p and $s are interpolated in the context of sub log    $self->{LogQuery} = 'insert into $self->{Table} (TIME_STAMP, PRIORITY, MESSAGE) values (%t, $p, $s)';}###################################################################### Override the keyword function in Configurable# Return 0 if not understood, else 1sub keyword{    my ($self, $file, $keyword, $value) = @_;    if ($keyword eq 'Table')    {	$self->{Table} = $value;    }    elsif ($keyword eq 'LogQuery')    {	$self->{LogQuery} = $value;    }    else    {	# Multiple inheritance	return $self->Radius::LogGeneric::keyword	              ($file, $keyword, $value)		|| $self->Radius::SqlDb::keyword		      ($file, $keyword, $value);    }    return 1;}###################################################################### Log a message # $p is the message priority, $s is the messagesub log{    my ($self, $p, $s) = @_;    if ($p <= $self->{Trace})    {	# (Re)-connect to the database if necessary, 	return undef	    if !$self->reconnect;	my $time = time;	$s = $self->quote($s);	my $q = &Radius::Util::format_special($self->{LogQuery});	$q =~ s/@/\\@/g;	$q = eval qq/"$q"/; # Interpolate perl vars	$self->do($q);    }}1;