(file) Return to hashfiles.pm CVS log (file) (dir) Up to [RizwankCVS] / geekymedia_web / awstats-6.3 / wwwroot / cgi-bin / plugins

  1 rizwank 1.1 #!/usr/bin/perl
  2             #-----------------------------------------------------------------------------
  3             # HashFiles AWStats plugin
  4             # Allows AWStats to read/save its data file as native hash files.
  5             # This increase read andwrite files operations.
  6             #-----------------------------------------------------------------------------
  7             # Perl Required Modules: Storable
  8             #-----------------------------------------------------------------------------
  9             # $Revision: 1.11 $ - $Author: eldy $ - $Date: 2004/05/21 21:16:54 $
 10             
 11             
 12             # <-----
 13             # ENTER HERE THE USE COMMAND FOR ALL REQUIRED PERL MODULES
 14             if (!eval ('require "Storable.pm";')) { return $@?"Error: $@":"Error: Need Perl module Storable"; }
 15             # ----->
 16             use strict;no strict "refs";
 17             
 18             
 19             
 20             #-----------------------------------------------------------------------------
 21             # PLUGIN VARIABLES
 22 rizwank 1.1 #-----------------------------------------------------------------------------
 23             # <-----
 24             # ENTER HERE THE MINIMUM AWSTATS VERSION REQUIRED BY YOUR PLUGIN
 25             # AND THE NAME OF ALL FUNCTIONS THE PLUGIN MANAGE.
 26             my $PluginNeedAWStatsVersion="5.1";
 27             my $PluginHooksFunctions="SearchFile LoadCache SaveHash";
 28             # ----->
 29             
 30             # <-----
 31             # IF YOUR PLUGIN NEED GLOBAL VARIABLES, THEY MUST BE DECLARED HERE.
 32             use vars qw/
 33             $PluginHashfilesUpToDate
 34             /;
 35             # ----->
 36             
 37             
 38             
 39             #-----------------------------------------------------------------------------
 40             # PLUGIN FUNCTION: Init_pluginname
 41             #-----------------------------------------------------------------------------
 42             sub Init_hashfiles {
 43 rizwank 1.1 	my $InitParams=shift;
 44             
 45             	# <-----
 46             	# ENTER HERE CODE TO DO INIT PLUGIN ACTIONS
 47             	$PluginHashfilesUpToDate=1;
 48             	# ----->
 49             
 50             	my $checkversion=&Check_Plugin_Version($PluginNeedAWStatsVersion);
 51             	return ($checkversion?$checkversion:"$PluginHooksFunctions");
 52             }
 53             
 54             
 55             
 56             #-----------------------------------------------------------------------------
 57             # PLUGIN FUNTION: SearchFile_pluginname
 58             # UNIQUE: YES (Only one plugin using this function can be loaded)
 59             #-----------------------------------------------------------------------------
 60             sub SearchFile_hashfiles {
 61             	my ($searchdir,$dnscachefile,$filesuffix,$dnscacheext,$filetoload)=@_;	# Get params sent by ref
 62             	if (-f "${searchdir}$dnscachefile$filesuffix.hash") {
 63             		my ($tmp1a,$tmp2a,$tmp3a,$tmp4a,$tmp5a,$tmp6a,$tmp7a,$tmp8a,$tmp9a,$datesource,$tmp10a,$tmp11a,$tmp12a) = stat("${searchdir}$dnscachefile$filesuffix$dnscacheext");
 64 rizwank 1.1 		my ($tmp1b,$tmp2b,$tmp3b,$tmp4b,$tmp5b,$tmp6b,$tmp7b,$tmp8b,$tmp9b,$datehash,$tmp10b,$tmp11b,$tmp12b) = stat("${searchdir}$dnscachefile$filesuffix.hash");
 65             		if ($datesource && $datehash < $datesource) {
 66             			$PluginHashfilesUpToDate=0;
 67             			debug(" Plugin hashfiles: Hash file not up to date. Will use source file $filetoload instead.");
 68             		}
 69             		else {
 70             			# There is no source file or there is and hash file is up to date. We can just load hash file
 71             			$filetoload="${searchdir}$dnscachefile$filesuffix.hash";
 72             		}
 73             	}
 74             	elsif ($filetoload) {
 75             		$PluginHashfilesUpToDate=0;
 76             		debug(" Plugin hashfiles: Hash file not found. Will use source file $filetoload instead.");
 77             	}
 78             	# Change calling params
 79             	$_[4]=$filetoload;
 80             }
 81             
 82             
 83             #-----------------------------------------------------------------------------
 84             # PLUGIN FUNCTION: LoadCache_pluginname
 85 rizwank 1.1 # UNIQUE: YES (Only one plugin using this function can be loaded)
 86             #-----------------------------------------------------------------------------
 87             sub LoadCache_hashfiles {
 88             	my ($filetoload,$hashtoload)=@_;
 89             	if ($filetoload =~ /\.hash$/) {
 90             		# There is no source file or there is and hash file is up to date. We can just load hash file
 91             		eval('%$hashtoload = %{ retrieve("$filetoload") };');
 92             	}
 93             }
 94             
 95             
 96             #-----------------------------------------------------------------------------
 97             # PLUGIN FUNCTION: SaveHash_pluginname
 98             # UNIQUE: YES (Only one plugin using this function can be loaded)
 99             #-----------------------------------------------------------------------------
100             sub SaveHash_hashfiles {
101             	my ($filetosave,$hashtosave,$testifuptodate,$nbmaxofelemtosave,$nbofelemsaved)=@_;
102             	if (! $testifuptodate || ! $PluginHashfilesUpToDate) {
103             		$filetosave =~ s/(\.\w+)$//; $filetosave.=".hash";
104             		debug(" Plugin hashfiles: Save data ".($nbmaxofelemtosave?"($nbmaxofelemtosave records max)":"(all records)")." into hash file $filetosave");
105             		if (! $nbmaxofelemtosave || (scalar keys %$hashtosave <= $nbmaxofelemtosave)) {
106 rizwank 1.1 			# Save all hash array
107             			eval('store(\%$hashtosave, "$filetosave");');
108             			$_[4]=scalar keys %$hashtosave;
109             		}
110             		else {
111             			debug(" Plugin hashfiles: We need to resize hash to save from ".(scalar keys %$hashtosave)." to $nbmaxofelemtosave");
112             			# Save part of hash array
113             			my $counter=0;
114             			my %newhashtosave=();
115             			foreach my $key (keys %$hashtosave) {
116             				$newhashtosave{$key}=$hashtosave->{$key};
117             				if (++$counter >= $nbmaxofelemtosave) { last; }
118             			}
119             			eval('store(\%newhashtosave, "$filetosave");');
120             			$_[4]=scalar keys %newhashtosave;
121             		}
122             		$_[0]=$filetosave;
123             	}
124             	else {
125             		$_[4]=0;
126             	}
127 rizwank 1.1 }
128             
129             
130             1;	# Do not remove this line

Rizwan Kassim
Powered by
ViewCVS 0.9.2