--- lib/Apache/AuthCAS.pm	2004-10-13 02:40:15.000000000 +0200
+++ lib/Apache/AuthCAS.pm.new	2006-12-13 17:51:12.000000000 +0100
@@ -6,26 +6,29 @@
 # Authentication service
 package Apache::AuthCAS;
 
+use Apache2::ServerRec ();
+
 $^W = 1;
 use diagnostics;
 use warnings;
 use strict;
-use mod_perl qw(StackedHandlers MethodHandlers Authen Authz);
+use mod_perl2;
 use constant MP2 => $mod_perl::VERSION >= 1.99;
 use vars qw($INITIALIZED $SESSION_CLEANUP_COUNTER);
 
 BEGIN {
 	if (MP2) {
-		require Apache::Const;
+		#require Apache2::Const;
 		require APR::URI;
-		Apache::Const->import(-compile => qw(FORBIDDEN HTTP_MOVED_TEMPORARILY OK DECLINED HTTP_OK));
+		#Apache::Const->import(-compile => qw(FORBIDDEN HTTP_MOVED_TEMPORARILY OK DECLINED HTTP_OK));
+		use Apache2::Const -compile => qw(FORBIDDEN HTTP_MOVED_TEMPORARILY OK DECLINED HTTP_OK);
 	} else {
 		require Apache::Constants;
 		Apache::Constants->import(qw(FORBIDDEN HTTP_MOVED_TEMPORARILY OK DECLINED HTTP_OK));
 	}
 }
 
-use Apache::URI;
+use Apache2::URI;
 use Net::SSLeay;
 use MIME::Base64;
 use DBI;
@@ -151,6 +154,50 @@
 	$SESSION_CLEANUP_COUNTER = 0;
 }
 
+sub compat_table_get_set {
+    my ($r, $table) = (shift, shift);
+    my ($key, $value) = @_;
+
+    if (1 == @_) {
+        return wantarray() 
+            ?       ($table->get($key))
+            : scalar($table->get($key));
+    }
+    elsif (2 == @_) {
+        if (defined $value) {
+            return wantarray() 
+                ?        ($table->set($key, $value))
+                :  scalar($table->set($key, $value));
+        }
+        else {
+            return wantarray() 
+                ?       ($table->unset($key))
+                : scalar($table->unset($key));
+        }
+    }
+    elsif (0 == @_) {
+        return $table;
+    }
+    else {
+        my $name = (caller(1))[3];
+        $r->warn("Usage: \$r->$name([key [,val]])");
+    }
+}
+
+sub header_out {
+    my $r = shift;
+    return wantarray() 
+        ?       (compat_table_get_set($r, scalar($r->headers_out), @_))
+        : scalar(compat_table_get_set($r, scalar($r->headers_out), @_));
+}
+
+sub err_header_out {
+    my $r = shift;
+    return wantarray() 
+        ?       (compat_table_get_set($r, scalar($r->err_headers_out), @_))
+        : scalar(compat_table_get_set($r, scalar($r->err_headers_out), @_));
+}
+
 my $tmp;
 
 sub initialize($$) {
@@ -167,7 +214,7 @@
 		$LOG_LEVEL = $DEFAULT_LOG_LEVEL;
 	}
 	
-	Apache->warn("$$: CAS: initialize()") unless ($LOG_LEVEL < $LOG_INFO);
+	Apache2::ServerRec::warn("$$: CAS: initialize()") unless ($LOG_LEVEL < $LOG_INFO);
 
 	# determine if we are running in production
 	if ($tmp = $r->dir_config("CASProduction")) {
@@ -176,16 +223,29 @@
 		{
 			$PRODUCTION = 1;
 		}
-		Apache->warn("$$: CAS: initialize(): setting CASProduction to $PRODUCTION") unless ($LOG_LEVEL < $LOG_INFO);
+		Apache2::ServerRec::warn("$$: CAS: initialize(): setting CASProduction to $PRODUCTION") unless ($LOG_LEVEL < $LOG_INFO);
 	} else {
 		# default
 		$PRODUCTION = 0;
 	}
 
+	# pretend that basic auth was performed
+	if ($tmp = $r->dir_config("XCASPretendBasicAuth")) {
+		if (defined($tmp) and ($tmp ne "") and 
+			(($tmp eq "1") or ($tmp =~ /true/i))) 
+		{
+			$PRETEND_BASIC_AUTH = 1;
+		}
+		Apache2::ServerRec::warn("$$: CAS: initialize(): setting XCASPretendBasicAuth to $PRETEND_BASIC_AUTH") unless ($LOG_LEVEL < $LOG_INFO);
+	} else {
+		# default
+		$PRETEND_BASIC_AUTH = 0;
+	}
+
 	# error pages
 	if ($tmp = $r->dir_config("CASErrorURL")) {
 		$ERROR_URL = $tmp;
-		Apache->warn("$$: CAS: initialize(): setting CASErrorURL to $ERROR_URL") unless ($LOG_LEVEL < $LOG_INFO);
+		Apache2::ServerRec::warn("$$: CAS: initialize(): setting CASErrorURL to $ERROR_URL") unless ($LOG_LEVEL < $LOG_INFO);
 	} else {
 		# default
 		$ERROR_URL = $DEFAULT_ERROR_URL;
@@ -194,14 +254,14 @@
 	# service settings
 	if ($tmp = $r->dir_config("CASService")) {
 		$SERVICE = $tmp;
-		Apache->warn("$$: CAS: initialize(): setting CASService to $SERVICE") unless ($LOG_LEVEL < $LOG_INFO);
+		Apache2::ServerRec::warn("$$: CAS: initialize(): setting CASService to $SERVICE") unless ($LOG_LEVEL < $LOG_INFO);
 	} else {
 		# default
 		$SERVICE = "";
 	}
 	if ($tmp = $r->dir_config("CASProxyService")) {
 		$PROXY_SERVICE = $tmp;
-		Apache->warn("$$: CAS: initialize(): setting CASProxyService to $PROXY_SERVICE") unless ($LOG_LEVEL < $LOG_INFO);
+		Apache2::ServerRec::warn("$$: CAS: initialize(): setting CASProxyService to $PROXY_SERVICE") unless ($LOG_LEVEL < $LOG_INFO);
 	} else {
 		# default
 		$PROXY_SERVICE = "";
@@ -210,60 +270,60 @@
 	# CAS server settings
 	if ($tmp = $r->dir_config("CASHost")) {
 		$CAS_HOST = $tmp;
-		Apache->warn("$$: CAS: initialize(): setting cas host to $CAS_HOST") unless ($LOG_LEVEL < $LOG_INFO);
+		Apache2::ServerRec::warn("$$: CAS: initialize(): setting cas host to $CAS_HOST") unless ($LOG_LEVEL < $LOG_INFO);
 	} elsif ($PRODUCTION) {
 		$CAS_HOST = $PROD_CAS_HOST;
-		Apache->warn("$$: CAS: initialize(): setting cas host to $CAS_HOST") unless ($LOG_LEVEL < $LOG_INFO);
+		Apache2::ServerRec::warn("$$: CAS: initialize(): setting cas host to $CAS_HOST") unless ($LOG_LEVEL < $LOG_INFO);
 	} else {
 		# default
 		$CAS_HOST = $DEVEL_CAS_HOST;
-		Apache->warn("$$: CAS: initialize(): setting cas host to $CAS_HOST") unless ($LOG_LEVEL < $LOG_INFO);
+		Apache2::ServerRec::warn("$$: CAS: initialize(): setting cas host to $CAS_HOST") unless ($LOG_LEVEL < $LOG_INFO);
 	}
 
 	if ($tmp = $r->dir_config("CASPort")) {
 		$CAS_PORT = $tmp;
-		Apache->warn("$$: CAS: initialize(): setting cas port to $CAS_PORT") unless ($LOG_LEVEL < $LOG_INFO);
+		Apache2::ServerRec::warn("$$: CAS: initialize(): setting cas port to $CAS_PORT") unless ($LOG_LEVEL < $LOG_INFO);
 	} elsif ($PRODUCTION) {
 		$CAS_PORT = $PROD_CAS_PORT;
-		Apache->warn("$$: CAS: initialize(): setting cas port to $CAS_PORT") unless ($LOG_LEVEL < $LOG_INFO);
+		Apache2::ServerRec::warn("$$: CAS: initialize(): setting cas port to $CAS_PORT") unless ($LOG_LEVEL < $LOG_INFO);
 	} else {
 		# default
 		$CAS_PORT = $DEVEL_CAS_PORT;
-		Apache->warn("$$: CAS: initialize(): setting cas port to $CAS_PORT") unless ($LOG_LEVEL < $LOG_INFO);
+		Apache2::ServerRec::warn("$$: CAS: initialize(): setting cas port to $CAS_PORT") unless ($LOG_LEVEL < $LOG_INFO);
 	}
 
 	# CAS URIs
 	if ($tmp = $r->dir_config("CASLoginURI")) {
 		$CAS_LOGIN_URI = $tmp;
-		Apache->warn("$$: CAS: initialize(): setting CASLoginURI to $CAS_LOGIN_URI") unless ($LOG_LEVEL < $LOG_INFO);
+		Apache2::ServerRec::warn("$$: CAS: initialize(): setting CASLoginURI to $CAS_LOGIN_URI") unless ($LOG_LEVEL < $LOG_INFO);
 	} else {
 		# default
 		$CAS_LOGIN_URI = $DEFAULT_CAS_LOGIN_URI;
 	}
 	if ($tmp = $r->dir_config("CASLogoutURI")) {
 		$CAS_LOGOUT_URI = $tmp;
-		Apache->warn("$$: CAS: initialize(): setting CASLogoutURI to $CAS_LOGOUT_URI") unless ($LOG_LEVEL < $LOG_INFO);
+		Apache2::ServerRec::warn("$$: CAS: initialize(): setting CASLogoutURI to $CAS_LOGOUT_URI") unless ($LOG_LEVEL < $LOG_INFO);
 	} else {
 		# default
 		$CAS_LOGOUT_URI = $DEFAULT_CAS_LOGOUT_URI;
 	}
 	if ($tmp = $r->dir_config("CASProxyURI")) {
 		$CAS_PROXY_URI = $tmp;
-		Apache->warn("$$: CAS: initialize(): setting CASProxyURI to $CAS_PROXY_URI") unless ($LOG_LEVEL < $LOG_INFO);
+		Apache2::ServerRec::warn("$$: CAS: initialize(): setting CASProxyURI to $CAS_PROXY_URI") unless ($LOG_LEVEL < $LOG_INFO);
 	} else {
 		# default
 		$CAS_PROXY_URI = $DEFAULT_CAS_PROXY_URI;
 	}
 	if ($tmp = $r->dir_config("CASProxyValidateURI")) {
 		$CAS_PROXY_VALIDATE_URI = $tmp;
-		Apache->warn("$$: CAS: initialize(): setting CASProxyValidateURI to $CAS_PROXY_VALIDATE_URI") unless ($LOG_LEVEL < $LOG_INFO);
+		Apache2::ServerRec::warn("$$: CAS: initialize(): setting CASProxyValidateURI to $CAS_PROXY_VALIDATE_URI") unless ($LOG_LEVEL < $LOG_INFO);
 	} else {
 		# default
 		$CAS_PROXY_VALIDATE_URI = $DEFAULT_CAS_PROXY_VALIDATE_URI;
 	}
 	if ($tmp = $r->dir_config("CASServiceValidateURI")) {
 		$CAS_SERVICE_VALIDATE_URI = $tmp;
-		Apache->warn("$$: CAS: initialize(): setting CASServiceValidateURI to $CAS_SERVICE_VALIDATE_URI") unless ($LOG_LEVEL < $LOG_INFO);
+		Apache2::ServerRec::warn("$$: CAS: initialize(): setting CASServiceValidateURI to $CAS_SERVICE_VALIDATE_URI") unless ($LOG_LEVEL < $LOG_INFO);
 	} else {
 		# default
 		$CAS_SERVICE_VALIDATE_URI = $DEFAULT_CAS_SERVICE_VALIDATE_URI;
@@ -272,7 +332,7 @@
 	# number of proxy tickets to add to the request
 	if ($tmp = $r->dir_config("CASNumProxyTickets")) {
 		$NUM_PROXY_TICKETS = $tmp;
-		Apache->warn("$$: CAS: initialize(): setting CASNumProxyTickets to $NUM_PROXY_TICKETS") unless ($LOG_LEVEL < $LOG_INFO);
+		Apache2::ServerRec::warn("$$: CAS: initialize(): setting CASNumProxyTickets to $NUM_PROXY_TICKETS") unless ($LOG_LEVEL < $LOG_INFO);
 	} else {
 		# default
 		$NUM_PROXY_TICKETS = $DEFAULT_NUM_PROXY_TICKETS;
@@ -281,21 +341,21 @@
 	# session settings
 	if ($tmp = $r->dir_config("CASSessionCookieName")) {
 		$SESSION_COOKIE_NAME = $tmp;
-		Apache->warn("$$: CAS: initialize(): setting CASSessionCookieName to $SESSION_COOKIE_NAME") unless ($LOG_LEVEL < $LOG_INFO);
+		Apache2::ServerRec::warn("$$: CAS: initialize(): setting CASSessionCookieName to $SESSION_COOKIE_NAME") unless ($LOG_LEVEL < $LOG_INFO);
 	} else {
 		# default
 		$SESSION_COOKIE_NAME = $DEFAULT_SESSION_COOKIE_NAME;
 	}
 	if ($tmp = $r->dir_config("CASSessionCookieDomain")) {
 		$SESSION_COOKIE_DOMAIN = $tmp;
-		Apache->warn("$$: CAS: initialize(): setting CASSessionCookieDomain to $SESSION_COOKIE_DOMAIN") unless ($LOG_LEVEL < $LOG_INFO);
+		Apache2::ServerRec::warn("$$: CAS: initialize(): setting CASSessionCookieDomain to $SESSION_COOKIE_DOMAIN") unless ($LOG_LEVEL < $LOG_INFO);
 	} else {
 		# default
 		$SESSION_COOKIE_DOMAIN = $DEFAULT_SESSION_COOKIE_DOMAIN;
 	}
 	if ($tmp = $r->dir_config("CASSessionTimeout")) {
 		$SESSION_TIMEOUT= $tmp;
-		Apache->warn("$$: CAS: initialize(): setting CASSessionTimeout to $SESSION_TIMEOUT") unless ($LOG_LEVEL < $LOG_INFO);
+		Apache2::ServerRec::warn("$$: CAS: initialize(): setting CASSessionTimeout to $SESSION_TIMEOUT") unless ($LOG_LEVEL < $LOG_INFO);
 	} else {
 		# default
 		$SESSION_TIMEOUT= $DEFAULT_SESSION_TIMEOUT;
@@ -304,101 +364,101 @@
 	# database settings
 	if ($tmp = $r->dir_config("CASDatabaseDriver")) {
 		$DB_DRIVER = $tmp;
-		Apache->warn("$$: CAS: initialize(): setting database driver to $DB_DRIVER") unless ($LOG_LEVEL < $LOG_INFO);
+		Apache2::ServerRec::warn("$$: CAS: initialize(): setting database driver to $DB_DRIVER") unless ($LOG_LEVEL < $LOG_INFO);
 	} elsif ($PRODUCTION) {
 		$DB_DRIVER = $PROD_DB_DRIVER;
-		Apache->warn("$$: CAS: initialize(): setting database driver to $DB_DRIVER") unless ($LOG_LEVEL < $LOG_INFO);
+		Apache2::ServerRec::warn("$$: CAS: initialize(): setting database driver to $DB_DRIVER") unless ($LOG_LEVEL < $LOG_INFO);
 	} else {
 		# default
 		$DB_DRIVER = $DEVEL_DB_DRIVER;
-		Apache->warn("$$: CAS: initialize(): setting database driver to $DB_DRIVER") unless ($LOG_LEVEL < $LOG_INFO);
+		Apache2::ServerRec::warn("$$: CAS: initialize(): setting database driver to $DB_DRIVER") unless ($LOG_LEVEL < $LOG_INFO);
 	}
 	if ($tmp = $r->dir_config("CASDatabaseHost")) {
 		$DB_HOST = $tmp;
-		Apache->warn("$$: CAS: initialize(): setting database host to $DB_HOST") unless ($LOG_LEVEL < $LOG_INFO);
+		Apache2::ServerRec::warn("$$: CAS: initialize(): setting database host to $DB_HOST") unless ($LOG_LEVEL < $LOG_INFO);
 	} elsif ($PRODUCTION) {
 		$DB_HOST = $PROD_DB_HOST;
-		Apache->warn("$$: CAS: initialize(): setting database host to $DB_HOST") unless ($LOG_LEVEL < $LOG_INFO);
+		Apache2::ServerRec::warn("$$: CAS: initialize(): setting database host to $DB_HOST") unless ($LOG_LEVEL < $LOG_INFO);
 	} else {
 		# default
 		$DB_HOST = $DEVEL_DB_HOST;
-		Apache->warn("$$: CAS: initialize(): setting database host to $DB_HOST") unless ($LOG_LEVEL < $LOG_INFO);
+		Apache2::ServerRec::warn("$$: CAS: initialize(): setting database host to $DB_HOST") unless ($LOG_LEVEL < $LOG_INFO);
 	
 	}
 	if ($tmp = $r->dir_config("CASDatabasePort")) {
 		$DB_PORT = $tmp;
-		Apache->warn("$$: CAS: initialize(): setting database port to $DB_PORT") unless ($LOG_LEVEL < $LOG_INFO);
+		Apache2::ServerRec::warn("$$: CAS: initialize(): setting database port to $DB_PORT") unless ($LOG_LEVEL < $LOG_INFO);
 	} elsif ($PRODUCTION) {
 		$DB_PORT = $PROD_DB_PORT;
-		Apache->warn("$$: CAS: initialize(): setting database port to $DB_PORT") unless ($LOG_LEVEL < $LOG_INFO);
+		Apache2::ServerRec::warn("$$: CAS: initialize(): setting database port to $DB_PORT") unless ($LOG_LEVEL < $LOG_INFO);
 	} else {
 		# default
 		$DB_PORT = $DEVEL_DB_PORT;
-		Apache->warn("$$: CAS: initialize(): setting database port to $DB_PORT") unless ($LOG_LEVEL < $LOG_INFO);
+		Apache2::ServerRec::warn("$$: CAS: initialize(): setting database port to $DB_PORT") unless ($LOG_LEVEL < $LOG_INFO);
 	}
 	if ($tmp = $r->dir_config("CASDatabaseName")) {
 		$DB_NAME = $tmp;
-		Apache->warn("$$: CAS: initialize(): setting database name to $DB_NAME") unless ($LOG_LEVEL < $LOG_INFO);
+		Apache2::ServerRec::warn("$$: CAS: initialize(): setting database name to $DB_NAME") unless ($LOG_LEVEL < $LOG_INFO);
 	} elsif ($PRODUCTION) {
 		$DB_NAME = $PROD_DB_NAME;
-		Apache->warn("$$: CAS: initialize(): setting database name to $DB_NAME") unless ($LOG_LEVEL < $LOG_INFO);
+		Apache2::ServerRec::warn("$$: CAS: initialize(): setting database name to $DB_NAME") unless ($LOG_LEVEL < $LOG_INFO);
 	} else {
 		# default
 		$DB_NAME = $DEVEL_DB_NAME;
-		Apache->warn("$$: CAS: initialize(): setting database name to $DB_NAME") unless ($LOG_LEVEL < $LOG_INFO);
+		Apache2::ServerRec::warn("$$: CAS: initialize(): setting database name to $DB_NAME") unless ($LOG_LEVEL < $LOG_INFO);
 	}
 	if ($tmp = $r->dir_config("CASDatabaseSessionTable")) {
 		$DB_SESSION_TABLE = $tmp;
-		Apache->warn("$$: CAS: initialize(): setting session table to $DB_SESSION_TABLE") unless ($LOG_LEVEL < $LOG_INFO);
+		Apache2::ServerRec::warn("$$: CAS: initialize(): setting session table to $DB_SESSION_TABLE") unless ($LOG_LEVEL < $LOG_INFO);
 	} elsif ($PRODUCTION) {
 		$DB_SESSION_TABLE = $PROD_DB_SESSION_TABLE;
-		Apache->warn("$$: CAS: initialize(): setting session table to $DB_SESSION_TABLE") unless ($LOG_LEVEL < $LOG_INFO);
+		Apache2::ServerRec::warn("$$: CAS: initialize(): setting session table to $DB_SESSION_TABLE") unless ($LOG_LEVEL < $LOG_INFO);
 	} else {
 		# default
 		$DB_SESSION_TABLE = $DEVEL_DB_SESSION_TABLE;
-		Apache->warn("$$: CAS: initialize(): setting session table to $DB_SESSION_TABLE") unless ($LOG_LEVEL < $LOG_INFO);
+		Apache2::ServerRec::warn("$$: CAS: initialize(): setting session table to $DB_SESSION_TABLE") unless ($LOG_LEVEL < $LOG_INFO);
 	}
 	if ($tmp = $r->dir_config("CASDatabasePGTIOUTable")) {
 		$DB_PGTIOU_TABLE = $tmp;
-		Apache->warn("$$: CAS: initialize(): setting pgtiou table to $DB_PGTIOU_TABLE") unless ($LOG_LEVEL < $LOG_INFO);
+		Apache2::ServerRec::warn("$$: CAS: initialize(): setting pgtiou table to $DB_PGTIOU_TABLE") unless ($LOG_LEVEL < $LOG_INFO);
 	} elsif ($PRODUCTION) {
 		$DB_PGTIOU_TABLE = $PROD_DB_PGTIOU_TABLE;
-		Apache->warn("$$: CAS: initialize(): setting pgtiou table to $DB_PGTIOU_TABLE") unless ($LOG_LEVEL < $LOG_INFO);
+		Apache2::ServerRec::warn("$$: CAS: initialize(): setting pgtiou table to $DB_PGTIOU_TABLE") unless ($LOG_LEVEL < $LOG_INFO);
 	} else {
 		# default
 		$DB_PGTIOU_TABLE = $DEVEL_DB_PGTIOU_TABLE;
-		Apache->warn("$$: CAS: initialize(): setting pgtiou table to $DB_PGTIOU_TABLE") unless ($LOG_LEVEL < $LOG_INFO);
+		Apache2::ServerRec::warn("$$: CAS: initialize(): setting pgtiou table to $DB_PGTIOU_TABLE") unless ($LOG_LEVEL < $LOG_INFO);
 	}
 	if ($tmp = $r->dir_config("CASDatabaseUser")) {
 		$DB_USER = $tmp;
-		Apache->warn("$$: CAS: initialize(): setting database user to $DB_USER") unless ($LOG_LEVEL < $LOG_INFO);
+		Apache2::ServerRec::warn("$$: CAS: initialize(): setting database user to $DB_USER") unless ($LOG_LEVEL < $LOG_INFO);
 	} elsif ($PRODUCTION) {
 		$DB_USER = $PROD_DB_USER;
-		Apache->warn("$$: CAS: initialize(): setting database user to $DB_USER") unless ($LOG_LEVEL < $LOG_INFO);
+		Apache2::ServerRec::warn("$$: CAS: initialize(): setting database user to $DB_USER") unless ($LOG_LEVEL < $LOG_INFO);
 	} else {
 		# default
 		$DB_USER = $DEVEL_DB_USER;
-		Apache->warn("$$: CAS: initialize(): setting database user to $DB_USER") unless ($LOG_LEVEL < $LOG_INFO);
+		Apache2::ServerRec::warn("$$: CAS: initialize(): setting database user to $DB_USER") unless ($LOG_LEVEL < $LOG_INFO);
 	}
 	if ($tmp = $r->dir_config("CASDatabasePass")) {
 		$DB_PASS = $tmp;
-		Apache->warn("$$: CAS: initialize(): setting database password to $DB_PASS") unless ($LOG_LEVEL < $LOG_INFO);
+		Apache2::ServerRec::warn("$$: CAS: initialize(): setting database password to $DB_PASS") unless ($LOG_LEVEL < $LOG_INFO);
 	} elsif ($PRODUCTION) {
 		$DB_PASS = $PROD_DB_PASS;
-		Apache->warn("$$: CAS: initialize(): setting database password to $DB_PASS") unless ($LOG_LEVEL < $LOG_INFO);
+		Apache2::ServerRec::warn("$$: CAS: initialize(): setting database password to $DB_PASS") unless ($LOG_LEVEL < $LOG_INFO);
 	} else {
 		# default
 		$DB_PASS = $DEVEL_DB_PASS;
-		Apache->warn("$$: CAS: initialize(): setting database password to $DB_PASS") unless ($LOG_LEVEL < $LOG_INFO);
+		Apache2::ServerRec::warn("$$: CAS: initialize(): setting database password to $DB_PASS") unless ($LOG_LEVEL < $LOG_INFO);
 	}
 
 	if (!$DB_HOST or !$DB_PORT or !$DB_NAME or !$DB_USER or !$DB_PASS) {
-		Apache->warn("$$: CAS: initialize(): database not properly configured.  Please specify: 'CASDatabaseHost', 'CASDatabasePort', 'CASDatabaseName', 'CASDatabaseUser', 'CASDatabasePassword'");
+		Apache2::ServerRec::warn("$$: CAS: initialize(): database not properly configured.  Please specify: 'CASDatabaseHost', 'CASDatabasePort', 'CASDatabaseName', 'CASDatabaseUser', 'CASDatabasePassword'");
 	}
 
 	if ($tmp = $r->dir_config("CASRemoveTicket")) {
 		$REMOVE_TICKET = $tmp;
-		Apache->warn("$$: CAS: initialize(): setting CASRemoveTicket to $REMOVE_TICKET") unless ($LOG_LEVEL < $LOG_INFO);
+		Apache2::ServerRec::warn("$$: CAS: initialize(): setting CASRemoveTicket to $REMOVE_TICKET") unless ($LOG_LEVEL < $LOG_INFO);
 	} else {
 		# default
 		$REMOVE_TICKET = $DEFAULT_REMOVE_TICKET;
@@ -415,7 +475,7 @@
 	my $tmp;
 
 	# Only authenticate the first internal request
-	return (MP2 ? Apache::OK : Apache::Constants::OK) unless $r->is_initial_req;
+	return Apache2::Const::OK unless $r->is_initial_req;
 
 	# get our configuration, unless we already have and we are running static
 	unless ($STATIC_INITIALIZATION and $INITIALIZED) {
@@ -425,15 +485,15 @@
 	# perform any cleanup that is needed
 	$self->cleanup($r);
 	
-	Apache->warn("$$: CAS: authenticate()") unless ($LOG_LEVEL < $LOG_DEBUG);
+	Apache2::ServerRec::warn("$$: CAS: authenticate()") unless ($LOG_LEVEL < $LOG_DEBUG);
 
 	# see if any of our other handlers have specified that they have already
 	# sufficiently checked the authenticating user
 	my $authenticated = $r->subprocess_env->{'AUTHENTICATED'} || "";
-	Apache->warn("$$: CAS: authenticated='$authenticated'") unless ($LOG_LEVEL < $LOG_DEBUG);
+	Apache2::ServerRec::warn("$$: CAS: authenticated='$authenticated'") unless ($LOG_LEVEL < $LOG_DEBUG);
 
 	if ($authenticated eq "true") {
-		return (MP2 ? Apache::OK : Apache::Constants::OK);
+		return Apache2::Const::OK;
 	}
 
 	# Parse the query string to get the ticket, plus any GET variables
@@ -459,17 +519,17 @@
 		my @params = split(/&/, $query);
 		foreach (@params) {
 			my ($key, $value) = split(/=/, $_);
-			Apache->warn("$$: CAS: authenticate(): PARAMS: '$key' => '$value'") unless ($LOG_LEVEL < $LOG_DEBUG);
+			Apache2::ServerRec::warn("$$: CAS: authenticate(): PARAMS: '$key' => '$value'") unless ($LOG_LEVEL < $LOG_DEBUG);
 			if ($key eq "ticket") {
-				Apache->warn("$$: CAS: authenticate(): ticket found: '$value'") unless ($LOG_LEVEL < $LOG_DEBUG);
+				Apache2::ServerRec::warn("$$: CAS: authenticate(): ticket found: '$value'") unless ($LOG_LEVEL < $LOG_DEBUG);
 				$ticket = $value || "";
 			}
 			if ($key eq $PGT_ID_PARAM) {
-				Apache->warn("$$: CAS: authenticate(): PGTID found: '$value'") unless ($LOG_LEVEL < $LOG_DEBUG);
+				Apache2::ServerRec::warn("$$: CAS: authenticate(): PGTID found: '$value'") unless ($LOG_LEVEL < $LOG_DEBUG);
 				$pgt = $value;
 			}
 			if ($key eq $PGT_IOU_PARAM) {
-				Apache->warn("$$: CAS: authenticate(): PGTIOU found: '$value'") unless ($LOG_LEVEL < $LOG_DEBUG);
+				Apache2::ServerRec::warn("$$: CAS: authenticate(): PGTIOU found: '$value'") unless ($LOG_LEVEL < $LOG_DEBUG);
 				$pgtiou = $value;
 			}
 		}
@@ -478,15 +538,15 @@
 	# this is the proxy receptor, should only enter here when CAS sends us the
 	# PGTIOU and the PGT
 	if (($pgtiou ne "") and ($pgt ne "")) {
-		Apache->warn("$$: CAS: authenticate(): proxy receptor invoked with '$pgtiou' => '$pgt'") unless ($LOG_LEVEL < $LOG_DEBUG);
+		Apache2::ServerRec::warn("$$: CAS: authenticate(): proxy receptor invoked with '$pgtiou' => '$pgt'") unless ($LOG_LEVEL < $LOG_DEBUG);
 
 		# save the pgtiou/pgt mapping
 		if (!$self->set_pgt($pgtiou, $pgt)) {
-			Apache->warn("$$: CAS: authenticate(): couldn't save '$pgtiou' => '$pgt', redirecting to error page") unless ($LOG_LEVEL < $LOG_ERROR);
+			Apache2::ServerRec::warn("$$: CAS: authenticate(): couldn't save '$pgtiou' => '$pgt', redirecting to error page") unless ($LOG_LEVEL < $LOG_ERROR);
 			return $self->redirect($r, $ERROR_URL, $DB_ERROR_CODE);
 		}
 
-		Apache->warn("$$: CAS: authenticate(): saved '$pgtiou' => '$pgt'") unless ($LOG_LEVEL < $LOG_DEBUG);
+		Apache2::ServerRec::warn("$$: CAS: authenticate(): saved '$pgtiou' => '$pgt'") unless ($LOG_LEVEL < $LOG_DEBUG);
 
 		# return a successful response to CAS
 		# have to not let request fall through to real content here
@@ -495,9 +555,9 @@
 
 	# determine any session cookies/session id we may have recieved
 	my ($cookie, $sid) = ("", "");
-	if (!defined($cookie = $r->header_in('Cookie'))) {
+	if (!defined($cookie = compat_table_get_set($r, scalar($r->headers_in), 'Cookie'))) {
 		# if we don't have a session cookie, the user can't be valid
-		Apache->warn("$$: CAS: authenticate(): no session cookie found") unless ($LOG_LEVEL < $LOG_DEBUG);
+		Apache2::ServerRec::warn("$$: CAS: authenticate(): no session cookie found") unless ($LOG_LEVEL < $LOG_DEBUG);
 
 		my $service;
 		if ($SERVICE eq "") {
@@ -507,26 +567,26 @@
 			# use the static entry point into this service
 			$service = $self->urlEncode($SERVICE);
 		}
-		Apache->warn("$$: CAS: authenticate(): no session cookie for service: '$service'") unless ($LOG_LEVEL < $LOG_DEBUG);
+		Apache2::ServerRec::warn("$$: CAS: authenticate(): no session cookie for service: '$service'") unless ($LOG_LEVEL < $LOG_DEBUG);
 	} else {
 		# we have a session cookie, so we need to get the session id
-		Apache->warn("$$: CAS: authenticate(): cookie found: '$cookie'") unless ($LOG_LEVEL < $LOG_DEBUG);
+		Apache2::ServerRec::warn("$$: CAS: authenticate(): cookie found: '$cookie'") unless ($LOG_LEVEL < $LOG_DEBUG);
 
 		# get session id from the cookie
 		$cookie =~ /.*$SESSION_COOKIE_NAME=([^;]+)(\s*;.*|\s*$)/;
 		$sid = $1 || "";
 		if (!$sid) {
 			# no sessions id in cookie?
-			Apache->warn("$$: CAS: authenticate(): no session id found in cookie: '$cookie'") unless ($LOG_LEVEL < $LOG_DEBUG);
+			Apache2::ServerRec::warn("$$: CAS: authenticate(): no session id found in cookie: '$cookie'") unless ($LOG_LEVEL < $LOG_DEBUG);
 		} else {
-			Apache->warn("$$: CAS: authenticate(): session id '$sid' found in cookie: '$cookie'") unless ($LOG_LEVEL < $LOG_DEBUG);
+			Apache2::ServerRec::warn("$$: CAS: authenticate(): session id '$sid' found in cookie: '$cookie'") unless ($LOG_LEVEL < $LOG_DEBUG);
 		}
 	}
 
 	# if we don't have a session id and there is no service ticket, redirect
 	# the user to CAS (they have never been authenticated)
 	if (!$ticket and !$sid) {
-		Apache->warn("$$: CAS: authenticate(): no ticket and no cookie, redirecting to login") unless ($LOG_LEVEL < $LOG_DEBUG);
+		Apache2::ServerRec::warn("$$: CAS: authenticate(): no ticket and no cookie, redirecting to login") unless ($LOG_LEVEL < $LOG_DEBUG);
 		return $self->redirect_login($r);
 	} 
 	
@@ -542,27 +602,27 @@
 		# try to get a session record for the session id we recieved
 		my @session_data; # session id, last accessed, netid, pgtiou
 		if (@session_data = $self->get_session_data($sid)) {
-			Apache->warn("$$: CAS: authenticate(): session data: ".join(",",@session_data)) unless ($LOG_LEVEL < $LOG_DEBUG);
+			Apache2::ServerRec::warn("$$: CAS: authenticate(): session data: ".join(",",@session_data)) unless ($LOG_LEVEL < $LOG_DEBUG);
 
 			# we found the session id in out session hash
 			my $last_accessed = $session_data[1];
 
 			# make sure the session is still valid
-			Apache->warn("$$: CAS: authenticate(): session last_accessed=$last_accessed") unless ($LOG_LEVEL < $LOG_DEBUG);
+			Apache2::ServerRec::warn("$$: CAS: authenticate(): session last_accessed=$last_accessed") unless ($LOG_LEVEL < $LOG_DEBUG);
 			if ($last_accessed + $SESSION_TIMEOUT >= time()) {
 				# session is still valid
-				Apache->warn("$$: CAS: authenticate(): session '$sid' is still valid") unless ($LOG_LEVEL < $LOG_DEBUG);
+				Apache2::ServerRec::warn("$$: CAS: authenticate(): session '$sid' is still valid") unless ($LOG_LEVEL < $LOG_DEBUG);
 
 				# record the last time the session was accessed
 				$session_data[1] = time();
-				Apache->warn("$$: CAS: authenticate(): setting last accessed time to '".time()."'") unless ($LOG_LEVEL < $LOG_DEBUG);
+				Apache2::ServerRec::warn("$$: CAS: authenticate(): setting last accessed time to '".time()."'") unless ($LOG_LEVEL < $LOG_DEBUG);
 
 				# if something bad happened, like database unavailability
 				if (!$self->set_session_data(@session_data)) {
-					Apache->warn("$$: CAS: authenticate(): problem saving session data, redirecting to the error page") unless ($LOG_LEVEL < $LOG_ERROR);
+					Apache2::ServerRec::warn("$$: CAS: authenticate(): problem saving session data, redirecting to the error page") unless ($LOG_LEVEL < $LOG_ERROR);
 					return $self->redirect($r, $ERROR_URL, $DB_ERROR_CODE);
 				} else {
-					Apache->warn("$$: CAS: authenticate(): saved session data: ".join(",",@session_data)) unless ($LOG_LEVEL < $LOG_DEBUG);
+					Apache2::ServerRec::warn("$$: CAS: authenticate(): saved session data: ".join(",",@session_data)) unless ($LOG_LEVEL < $LOG_DEBUG);
 				}
 				
 				# set the pgtiou
@@ -573,32 +633,31 @@
 					return $self->do_proxy($r, $sid, $pgtiou, $user, 0);
 				} else {
 					# no proxy stuff, so we are done
-					Apache->warn("$$: CAS: authenticate(): no proxy stuff, we are done") unless ($LOG_LEVEL < $LOG_DEBUG);
+					Apache2::ServerRec::warn("$$: CAS: authenticate(): no proxy stuff, we are done") unless ($LOG_LEVEL < $LOG_DEBUG);
 
-					Apache->warn("$$: CAS: authenticate(): setting header CAS_FILTER_USER=$user") unless ($LOG_LEVEL < $LOG_DEBUG);
-					$r->header_in('CAS_FILTER_USER', $user);
+					Apache2::ServerRec::warn("$$: CAS: authenticate(): setting header CAS_FILTER_USER=$user") unless ($LOG_LEVEL < $LOG_DEBUG);
+					compat_table_get_set($r, scalar($r->headers_in), 'CAS_FILTER_USER', $user);
 
 					if ($PRETEND_BASIC_AUTH) {
 						# setup this up for underlying authz modules that rely on Basic auth having been performed
-						$r->header_in('Authorization', "Basic " . encode_base64($user . ":DUMMYPASS"));
+						compat_table_get_set($r, scalar($r->headers_in), 'Authorization', "Basic " . encode_base64($user . ":DUMMYPASS"));
 						$r->user($user);
-						$r->connection->user($user);
-						$r->connection->auth_type("Basic");
+						$r->ap_auth_type("Basic");
 					}
 
-					return (MP2 ? Apache::OK : Apache::Constants::OK);
+					return (MP2 ? Apache2::Const::OK : Apache::Constants::OK);
 				}
 			} else {
-				Apache->warn("$$: CAS: authenticate(): session '$sid' has expired") unless ($LOG_LEVEL < $LOG_DEBUG);
+				Apache2::ServerRec::warn("$$: CAS: authenticate(): session '$sid' has expired") unless ($LOG_LEVEL < $LOG_DEBUG);
 				if (!$self->delete_session_data($sid)) {
-					Apache->warn("$$: CAS: authenticate(): couldn't delete expired session id='$sid'") unless ($LOG_LEVEL < $LOG_WARN);
+					Apache2::ServerRec::warn("$$: CAS: authenticate(): couldn't delete expired session id='$sid'") unless ($LOG_LEVEL < $LOG_WARN);
 				}
-				Apache->warn("$$: CAS: authenticate(): deleted expired session '$sid'") unless ($LOG_LEVEL < $LOG_DEBUG);
+				Apache2::ServerRec::warn("$$: CAS: authenticate(): deleted expired session '$sid'") unless ($LOG_LEVEL < $LOG_DEBUG);
 				
 				$sid = "";
 			}
 		} else {
-			Apache->warn("$$: CAS: authenticate(): session '$sid' is invalid") unless ($LOG_LEVEL < $LOG_DEBUG);
+			Apache2::ServerRec::warn("$$: CAS: authenticate(): session '$sid' is invalid") unless ($LOG_LEVEL < $LOG_DEBUG);
 			$sid = "";
 		}
 	}
@@ -613,7 +672,7 @@
 			# error occurred validating service ticket
 			return $self->redirect($r, $ERROR_URL, $properties{'error'});
 		} else {
-			Apache->warn("$$: CAS: authenticate(): valid service ticket '$ticket'") unless ($LOG_LEVEL < $LOG_DEBUG);
+			Apache2::ServerRec::warn("$$: CAS: authenticate(): valid service ticket '$ticket'") unless ($LOG_LEVEL < $LOG_DEBUG);
 		}
 
 		$pgtiou = $properties{'pgtiou'} || "";
@@ -626,78 +685,76 @@
 
 		$sid = &create_session_id();
 
-		Apache->warn("$$: CAS: authenticate(): setting sid='$sid' for netid='$user'") unless ($LOG_LEVEL < $LOG_DEBUG);
+		Apache2::ServerRec::warn("$$: CAS: authenticate(): setting sid='$sid' for netid='$user'") unless ($LOG_LEVEL < $LOG_DEBUG);
 
 		# map a new session id to this pgtiou and give the client a cookie
 		my $time = time();
-		Apache->warn("$$: CAS: authenticate(): trying to save session data: ".join(",",$sid, $time, $user, $pgtiou)) unless ($LOG_LEVEL < $LOG_DEBUG);
+		Apache2::ServerRec::warn("$$: CAS: authenticate(): trying to save session data: ".join(",",$sid, $time, $user, $pgtiou)) unless ($LOG_LEVEL < $LOG_DEBUG);
 		if (!$self->set_session_data($sid, $time, $user, $pgtiou)) {
 			# if something bad happened, like database unavailability
-			Apache->warn("$$: CAS: authenticate(): problem saving session data, redirecting to the error page") unless ($LOG_LEVEL < $LOG_ERROR);
+			Apache2::ServerRec::warn("$$: CAS: authenticate(): problem saving session data, redirecting to the error page") unless ($LOG_LEVEL < $LOG_ERROR);
 			return $self->redirect($r, $ERROR_URL, $DB_ERROR_CODE);
 		} else {
-			Apache->warn("$$: CAS: authenticate(): saved session data: ".join(",",$sid, $time, $user, $pgtiou)) unless ($LOG_LEVEL < $LOG_DEBUG);
+			Apache2::ServerRec::warn("$$: CAS: authenticate(): saved session data: ".join(",",$sid, $time, $user, $pgtiou)) unless ($LOG_LEVEL < $LOG_DEBUG);
 		}
 
-		Apache->warn("$$: CAS: authenticate(): sending session cookie") unless ($LOG_LEVEL < $LOG_DEBUG);
+		Apache2::ServerRec::warn("$$: CAS: authenticate(): sending session cookie") unless ($LOG_LEVEL < $LOG_DEBUG);
 		my $cookie = "$SESSION_COOKIE_NAME=$sid;path=/";
 		if ($SESSION_COOKIE_DOMAIN ne "") {
 			$cookie .= ";domain=.$SESSION_COOKIE_DOMAIN";
 		}
 
 		# send the cookie to the browser
-		$r->header_out("Set-Cookie" => $cookie);
+		header_out($r, ("Set-Cookie" => $cookie));
 
 		# in case we redirect (considered an "error")
-		$r->err_header_out("Set-Cookie" => $cookie);
+		err_header_out($r, ("Set-Cookie" => $cookie));
 	} else {
-		Apache->warn("$$: CAS: authenticate(): no valid session id or ticket") unless ($LOG_LEVEL < $LOG_DEBUG);
+		Apache2::ServerRec::warn("$$: CAS: authenticate(): no valid session id or ticket") unless ($LOG_LEVEL < $LOG_DEBUG);
 		return $self->redirect_login($r);
 	}
 
-	Apache->warn("$$: CAS: authenticate(): got user: '$user'") unless ($LOG_LEVEL < $LOG_DEBUG);
-	Apache->warn("$$: CAS: authenticate(): got PGTIOU: '$pgtiou'") unless ($LOG_LEVEL < $LOG_DEBUG);
+	Apache2::ServerRec::warn("$$: CAS: authenticate(): got user: '$user'") unless ($LOG_LEVEL < $LOG_DEBUG);
+	Apache2::ServerRec::warn("$$: CAS: authenticate(): got PGTIOU: '$pgtiou'") unless ($LOG_LEVEL < $LOG_DEBUG);
 
 	if ($PROXY_SERVICE) {
 		return $self->do_proxy($r, $sid, $pgtiou, $user, 1);
 	} else {
 		# no proxy stuff, so we are done
-		Apache->warn("$$: CAS: authenticate(): no proxy stuff, so we are done") unless ($LOG_LEVEL < $LOG_DEBUG);
+		Apache2::ServerRec::warn("$$: CAS: authenticate(): no proxy stuff, so we are done") unless ($LOG_LEVEL < $LOG_DEBUG);
 
 		# redirect to this same page minus the ticket
 		if (($REMOVE_TICKET eq "true") || ($REMOVE_TICKET eq "1")) {
-			Apache->warn("$$: CAS: authenticate(): setting header CAS_FILTER_USER=$user") unless ($LOG_LEVEL < $LOG_DEBUG);
-			$r->header_in('CAS_FILTER_USER', $user);
+			Apache2::ServerRec::warn("$$: CAS: authenticate(): setting header CAS_FILTER_USER=$user") unless ($LOG_LEVEL < $LOG_DEBUG);
+			compat_table_get_set($r, scalar($r->headers_in), 'CAS_FILTER_USER', $user);
 
 			if ($PRETEND_BASIC_AUTH) {
 				# setup this up for underlying authz modules that rely on Basic auth having been performed
-				$r->header_in('Authorization', "Basic " . encode_base64($user . ":DUMMYPASS"));
+				compat_table_get_set($r, scalar($r->headers_in), 'Authorization', "Basic " . encode_base64($user . ":DUMMYPASS"));
 				$r->user($user);
-				$r->connection->user($user);
-				$r->connection->auth_type("Basic");
+				$r->ap_auth_type("Basic");
 			}
 
-			Apache->warn("$$: CAS: authenticate(): trying to remove service ticket from URI") unless ($LOG_LEVEL < $LOG_DEBUG);
+			Apache2::ServerRec::warn("$$: CAS: authenticate(): trying to remove service ticket from URI") unless ($LOG_LEVEL < $LOG_DEBUG);
 			return $self->redirect_without_ticket($r);
 		} else {
-			Apache->warn("$$: CAS: authenticate(): setting header CAS_FILTER_USER=$user") unless ($LOG_LEVEL < $LOG_DEBUG);
-			$r->header_in('CAS_FILTER_USER', $user);
+			Apache2::ServerRec::warn("$$: CAS: authenticate(): setting header CAS_FILTER_USER=$user") unless ($LOG_LEVEL < $LOG_DEBUG);
+			compat_table_get_set($r, scalar($r->headers_in), 'CAS_FILTER_USER', $user);
 
 			if ($PRETEND_BASIC_AUTH) {
 				# setup this up for underlying authz modules that rely on Basic auth having been performed
-				$r->header_in('Authorization', "Basic " . encode_base64($user . ":DUMMYPASS"));
+				compat_table_get_set($r, scalar($r->headers_in), 'Authorization', "Basic " . encode_base64($user . ":DUMMYPASS"));
 				$r->user($user);
-				$r->connection->user($user);
-				$r->connection->auth_type("Basic");
+				$r->ap_auth_type("Basic");
 			}
 
-			Apache->warn("$$: CAS: authenticate(): not trying to remove service ticket from URI") unless ($LOG_LEVEL < $LOG_DEBUG);
-			return (MP2 ? Apache::OK : Apache::Constants::OK);
+			Apache2::ServerRec::warn("$$: CAS: authenticate(): not trying to remove service ticket from URI") unless ($LOG_LEVEL < $LOG_DEBUG);
+			return (MP2 ? Apache2::Const::OK : Apache::Constants::OK);
 		}
 	}
 
 	# failed if we got this far, but shouldn't
-	return (MP2 ? Apache::FORBIDDEN : Apache::Constants::FORBIDDEN);
+	return (MP2 ? Apache2::Const::FORBIDDEN : Apache::Constants::FORBIDDEN);
 }
 
 sub cleanup($$) {
@@ -705,13 +762,13 @@
 	my $r = shift;
 
 	$SESSION_CLEANUP_COUNTER++;
-	Apache->warn("$$: CAS: cleanup(): counter=$SESSION_CLEANUP_COUNTER") unless ($LOG_LEVEL < $LOG_DEBUG);
+	Apache2::ServerRec::warn("$$: CAS: cleanup(): counter=$SESSION_CLEANUP_COUNTER") unless ($LOG_LEVEL < $LOG_DEBUG);
 
 	# perform session cleanup
 	if ($SESSION_CLEANUP_COUNTER == 1) {
-		Apache->warn("$$: CAS: initialize(): performing session cleanup");
+		Apache2::ServerRec::warn("$$: CAS: initialize(): performing session cleanup");
 		$self->delete_expired_sessions();
-		Apache->warn("$$: CAS: initialize(): performing pgt/pgtiou cleanup");
+		Apache2::ServerRec::warn("$$: CAS: initialize(): performing pgt/pgtiou cleanup");
 		$self->delete_expired_pgts();
 	} 
 
@@ -726,19 +783,19 @@
 	my $self = shift;
 	my $r = shift;
 
-	Apache->warn("$$: CAS: redirect_without_ticket(): redirecting to remove service ticket from service string") unless ($LOG_LEVEL < $LOG_INFO);
+	Apache2::ServerRec::warn("$$: CAS: redirect_without_ticket(): redirecting to remove service ticket from service string") unless ($LOG_LEVEL < $LOG_INFO);
 
 	# this_url() strips the service ticket
 	my $url = $self->this_url($r);
-	$r->header_out("Location" => $url);
-	return (MP2 ? Apache::HTTP_MOVED_TEMPORARILY : Apache::Constants::HTTP_MOVED_TEMPORARILY);
+	header_out($r, ("Location" => $url));
+	return (MP2 ? Apache2::Const::HTTP_MOVED_TEMPORARILY : Apache::Constants::HTTP_MOVED_TEMPORARILY);
 }
 
 sub redirect_login($$) {
 	my $self = shift;
 	my $r = shift;
 
-	Apache->warn("$$: CAS: redirect_login()") unless ($LOG_LEVEL < $LOG_DEBUG);
+	Apache2::ServerRec::warn("$$: CAS: redirect_login()") unless ($LOG_LEVEL < $LOG_DEBUG);
 
 	my $service;
 	if ($SERVICE eq "") {
@@ -748,10 +805,10 @@
 		# use the static entry point into this service
 		$service = $self->urlEncode($SERVICE);
 	}
-	Apache->warn("$$: CAS: redirect_login(): redirecting to CAS for service: '$service'") unless ($LOG_LEVEL < $LOG_INFO);
+	Apache2::ServerRec::warn("$$: CAS: redirect_login(): redirecting to CAS for service: '$service'") unless ($LOG_LEVEL < $LOG_INFO);
 	my $redirect_url = "https://$CAS_HOST:$CAS_PORT$CAS_LOGIN_URI?service=$service";
-	$r->header_out("Location" => $redirect_url);
-	return (MP2 ? Apache::HTTP_MOVED_TEMPORARILY : Apache::Constants::HTTP_MOVED_TEMPORARILY);
+	header_out($r, ("Location" => $redirect_url));
+	return (MP2 ? Apache2::Const::HTTP_MOVED_TEMPORARILY : Apache::Constants::HTTP_MOVED_TEMPORARILY);
 }
 
 sub redirect($$) {
@@ -760,32 +817,32 @@
 	my $url = shift || "";
 	my $errcode = shift || "";
 
-	Apache->warn("$$: CAS: redirect()") unless ($LOG_LEVEL < $LOG_DEBUG);
+	Apache2::ServerRec::warn("$$: CAS: redirect()") unless ($LOG_LEVEL < $LOG_DEBUG);
 
 	if ($url) {
 		my $service;
 		if ($SERVICE eq "") {
 			# use the current URL as the service
 			$service = $self->this_url_encoded($r);
-			Apache->warn("$$: CAS: redirect(): using self as service") unless ($LOG_LEVEL < $LOG_DEBUG);
+			Apache2::ServerRec::warn("$$: CAS: redirect(): using self as service") unless ($LOG_LEVEL < $LOG_DEBUG);
 		} else {
 			# use the static entry point into this service
 			$service = $self->urlEncode($SERVICE);
-			Apache->warn("$$: CAS: redirect(): using configured service") unless ($LOG_LEVEL < $LOG_DEBUG);
+			Apache2::ServerRec::warn("$$: CAS: redirect(): using configured service") unless ($LOG_LEVEL < $LOG_DEBUG);
 		}
-		$r->header_out("CAS_FILTER_CAS_HOST", $CAS_HOST);
-		$r->header_out("CAS_FILTER_CAS_PORT", $CAS_PORT);
-		$r->header_out("CAS_FILTER_CAS_LOGIN_URI", $CAS_LOGIN_URI);
-		$r->header_out("CAS_FILTER_SERVICE", $service);
-		Apache->warn("$$: CAS: redirect(): redirecting to url: '$url' service: '$service'") unless ($LOG_LEVEL < $LOG_INFO);
-		$r->header_out("Location" => "$url?login_url=https://$CAS_HOST:$CAS_PORT$CAS_LOGIN_URI&service=$service&errcode=$errcode");
-		return (MP2 ? Apache::HTTP_MOVED_TEMPORARILY : Apache::Constants::HTTP_MOVED_TEMPORARILY);
+		header_out($r, ("CAS_FILTER_CAS_HOST", $CAS_HOST));
+		header_out($r, ("CAS_FILTER_CAS_PORT", $CAS_PORT));
+		header_out($r, ("CAS_FILTER_CAS_LOGIN_URI", $CAS_LOGIN_URI));
+		header_out($r, ("CAS_FILTER_SERVICE", $service));
+		Apache2::ServerRec::warn("$$: CAS: redirect(): redirecting to url: '$url' service: '$service'") unless ($LOG_LEVEL < $LOG_INFO);
+		header_out($r, ("Location" => "$url?login_url=https://$CAS_HOST:$CAS_PORT$CAS_LOGIN_URI&service=$service&errcode=$errcode"));
+		return (MP2 ? Apache2::Const::HTTP_MOVED_TEMPORARILY : Apache::Constants::HTTP_MOVED_TEMPORARILY);
 	} else {
-		Apache->warn("$$: CAS: redirect(): no redirect URL, displaying message") unless ($LOG_LEVEL < $LOG_INFO);
+		Apache2::ServerRec::warn("$$: CAS: redirect(): no redirect URL, displaying message") unless ($LOG_LEVEL < $LOG_INFO);
 		$r->content_type ('text/html');
 		$r->print("<html><body>service misconfigured</body></html>");
 		$r->rflush;
-		return (MP2 ? Apache::HTTP_OK : Apache::Constants::HTTP_OK);
+		return (MP2 ? Apache2::Const::HTTP_OK : Apache::Constants::HTTP_OK);
 	}
 }
 
@@ -802,7 +859,7 @@
 	my $ticket = shift;
 	my $proxy = shift;
 
-	Apache->warn("$$: CAS: validate_service_ticket(): validating service ticket '$ticket' through CAS") unless ($LOG_LEVEL < $LOG_DEBUG);
+	Apache2::ServerRec::warn("$$: CAS: validate_service_ticket(): validating service ticket '$ticket' through CAS") unless ($LOG_LEVEL < $LOG_DEBUG);
 	my %properties;
 
 	my $service;
@@ -814,7 +871,7 @@
 		$service = $self->urlEncode($SERVICE);
 	}
 
-	Apache->warn("$$: CAS: validate_service_ticket(): requesting validation for service: '$service'") unless ($LOG_LEVEL < $LOG_DEBUG);
+	Apache2::ServerRec::warn("$$: CAS: validate_service_ticket(): requesting validation for service: '$service'") unless ($LOG_LEVEL < $LOG_DEBUG);
 	my $tmp;
 	# FIXME - diff urls for proxy vs. none?
 	if ($proxy) {
@@ -823,7 +880,7 @@
 		$tmp = $CAS_SERVICE_VALIDATE_URI . "?service=$service&ticket=$ticket";
 	}
 
-	Apache->warn("$$: CAS: validate_service_ticket(): request URL: '$tmp'") unless ($LOG_LEVEL < $LOG_DEBUG);
+	Apache2::ServerRec::warn("$$: CAS: validate_service_ticket(): request URL: '$tmp'") unless ($LOG_LEVEL < $LOG_DEBUG);
 
 	if ($LOG_LEVEL >= $LOG_INSANE) {
 		$Net::SSLeay::trace = 3;  # 0=no debugging, 1=ciphers, 2=trace, 3=dump data
@@ -836,38 +893,38 @@
 
 	# if we had some type of connection problem
 	if (!defined($page)) {
-		Apache->warn("$$: CAS: validate_service_ticket(): error validating service");
+		Apache2::ServerRec::warn("$$: CAS: validate_service_ticket(): error validating service");
 		$properties{'error'} = $CAS_CONNECT_ERROR_CODE;
 		return %properties;
 	}
 
-	Apache->warn("$$: CAS: validate_service_ticket(): page: $page") unless ($LOG_LEVEL < $LOG_INSANE);
-	Apache->warn("$$: CAS: validate_service_ticket(): response: $response") unless ($LOG_LEVEL < $LOG_INSANE);
+	Apache2::ServerRec::warn("$$: CAS: validate_service_ticket(): page: $page") unless ($LOG_LEVEL < $LOG_INSANE);
+	Apache2::ServerRec::warn("$$: CAS: validate_service_ticket(): response: $response") unless ($LOG_LEVEL < $LOG_INSANE);
 
 	# FIXME - add a check for a 404 error/other errors
 	if ($page =~ /<cas:user>([^<]+)<\/cas:user>/) {
 		my $user = $1;
 		chomp $user;
-		Apache->warn("$$: CAS: validate_service_ticket(): valid service ticket, user '$user' authenticated") unless ($LOG_LEVEL < $LOG_DEBUG);
+		Apache2::ServerRec::warn("$$: CAS: validate_service_ticket(): valid service ticket, user '$user' authenticated") unless ($LOG_LEVEL < $LOG_DEBUG);
 		$properties{'user'} = $user;
 	
 		# only try to get PGTIOU if we are doing proxy stuff
 		if ($proxy) {
 			if ($page =~ /<cas:proxyGrantingTicket>([^<]+)<\/cas:proxyGrantingTicket>/) {
-				Apache->warn("$$: CAS: validate_service_ticket(): got pgt='$1' for user='$user'") unless ($LOG_LEVEL < $LOG_DEBUG);
+				Apache2::ServerRec::warn("$$: CAS: validate_service_ticket(): got pgt='$1' for user='$user'") unless ($LOG_LEVEL < $LOG_DEBUG);
 				if ($1 ne "") {
 					$properties{'pgtiou'} = $1;
 				} else {
-					Apache->warn("$$: CAS: validate_service_ticket(): empty PGT in response from CAS") unless ($LOG_LEVEL < $LOG_ERROR);
+					Apache2::ServerRec::warn("$$: CAS: validate_service_ticket(): empty PGT in response from CAS") unless ($LOG_LEVEL < $LOG_ERROR);
 				}
 			} else {
-				Apache->warn("$$: CAS: validate_service_ticket(): no PGT in response from CAS") unless ($LOG_LEVEL < $LOG_ERROR);
+				Apache2::ServerRec::warn("$$: CAS: validate_service_ticket(): no PGT in response from CAS") unless ($LOG_LEVEL < $LOG_ERROR);
 				$properties{'error'} = $PGT_ERROR_CODE;
 				return %properties;
 			}
 		}
 	} else {
-		Apache->warn("$$: CAS: validate_service_ticket(): invalid service ticket, user denied access") unless ($LOG_LEVEL < $LOG_DEBUG);
+		Apache2::ServerRec::warn("$$: CAS: validate_service_ticket(): invalid service ticket, user denied access") unless ($LOG_LEVEL < $LOG_DEBUG);
 		$properties{'error'} = $INVALID_ST_ERROR_CODE;
 		return %properties;
 	}
@@ -879,12 +936,12 @@
 	my $self = shift;
 	my $r = shift;
 
-	Apache->warn("$$: CAS: send_proxysuccess(): sending proxy success for CAS callback") unless ($LOG_LEVEL < $LOG_DEBUG);
+	Apache2::ServerRec::warn("$$: CAS: send_proxysuccess(): sending proxy success for CAS callback") unless ($LOG_LEVEL < $LOG_DEBUG);
 
 	$r->content_type("text/html");
 	$r->print("<casClient:proxySuccess xmlns:casClient=\"http://www.yale.edu/tp/casClient\"/>\n");
 	$r->rflush();
-	return (MP2 ? Apache::OK : Apache::Constants::OK);
+	return (MP2 ? Apache2::Const::OK : Apache::Constants::OK);
 }
 
 sub get_proxy_tickets($$) {
@@ -893,13 +950,13 @@
 	my $target = shift;
 	my $num_tickets = shift;
 
-	Apache->warn("$$: CAS: get_proxy_tickets()") unless ($LOG_LEVEL < $LOG_DEBUG);
+	Apache2::ServerRec::warn("$$: CAS: get_proxy_tickets()") unless ($LOG_LEVEL < $LOG_DEBUG);
 
 	my @tickets;
 	
 	for (my $i=0; $i < $num_tickets; $i++) {
 		my $uri = "$CAS_PROXY_URI?pgt=$pgt&targetService=$target";
-		Apache->warn("$$: CAS: get_proxy_tickets(): using PGT to obtain PT: calling URL '$uri'") unless ($LOG_LEVEL < $LOG_DEBUG);
+		Apache2::ServerRec::warn("$$: CAS: get_proxy_tickets(): using PGT to obtain PT: calling URL '$uri'") unless ($LOG_LEVEL < $LOG_DEBUG);
 
 		if ($LOG_LEVEL >= $LOG_INSANE) {
 			$Net::SSLeay::trace = 3;  # 0=no debugging, 1=ciphers, 2=trace, 3=dump data
@@ -910,16 +967,16 @@
 		my ($page, $response, %reply_headers) = Net::SSLeay::get_https($CAS_HOST, $CAS_PORT, $uri);
 
 		if ($page =~ /<cas:proxySuccess>/) {
-			Apache->warn("$$: CAS: get_proxy_tickets(): successful proxy request") unless ($LOG_LEVEL < $LOG_DEBUG);
+			Apache2::ServerRec::warn("$$: CAS: get_proxy_tickets(): successful proxy request") unless ($LOG_LEVEL < $LOG_DEBUG);
 			if ($page =~ /<cas:proxyTicket>([^<]+)<\/cas:proxyTicket>/) {
-				Apache->warn("$$: CAS: get_proxy_tickets(): successfully retrieved proxy ticket") unless ($LOG_LEVEL < $LOG_DEBUG);
+				Apache2::ServerRec::warn("$$: CAS: get_proxy_tickets(): successfully retrieved proxy ticket") unless ($LOG_LEVEL < $LOG_DEBUG);
 				push(@tickets, $1);
 			} else {
-				Apache->warn("$$: CAS: get_proxy_tickets(): no proxy ticket in response") unless ($LOG_LEVEL < $LOG_DEBUG);
+				Apache2::ServerRec::warn("$$: CAS: get_proxy_tickets(): no proxy ticket in response") unless ($LOG_LEVEL < $LOG_DEBUG);
 				return qw();
 			}
 		} else {
-			Apache->warn("$$: CAS: get_proxy_tickets(): unsuccessful proxy request") unless ($LOG_LEVEL < $LOG_DEBUG);
+			Apache2::ServerRec::warn("$$: CAS: get_proxy_tickets(): unsuccessful proxy request") unless ($LOG_LEVEL < $LOG_DEBUG);
 			return qw();
 		}
 	}
@@ -939,11 +996,11 @@
 	my $uid = shift;
 	my $pgtiou = shift || "";
 
-	Apache->warn("$$: CAS: set_session_data()") unless ($LOG_LEVEL < $LOG_DEBUG);
+	Apache2::ServerRec::warn("$$: CAS: set_session_data()") unless ($LOG_LEVEL < $LOG_DEBUG);
 
-	my $dbh = DBI->connect("dbi:Pg:dbname=$DB_NAME;host=$DB_HOST;port=$DB_PORT", $DB_USER, $DB_PASS, { AutoCommit => 1 });
+	my $dbh = DBI->connect("dbi:mysql:dbname=$DB_NAME", $DB_USER, $DB_PASS, { AutoCommit => 1 });
 	if (!defined($dbh)) {
-		Apache->warn("$$: CAS: set_session_data(): db connect error: $DBI::errstr") unless ($LOG_LEVEL < $LOG_ERROR);
+		Apache2::ServerRec::warn("$$: CAS: set_session_data(): db connect error: $DBI::errstr") unless ($LOG_LEVEL < $LOG_ERROR);
 		return "";
 	}
 
@@ -951,24 +1008,24 @@
 	my $sth = $dbh->prepare("SELECT id FROM $DB_SESSION_TABLE WHERE id='$sid';");
 	$sth->execute();
 	if ($sth->fetch()) {
-		Apache->warn("$$: CAS: set_session_data(): found session sid='$sid' to update") unless ($LOG_LEVEL < $LOG_DEBUG);
+		Apache2::ServerRec::warn("$$: CAS: set_session_data(): found session sid='$sid' to update") unless ($LOG_LEVEL < $LOG_DEBUG);
 
 		#print "DEBUG: '$id', '$last_accessed', '$uid', '$pgtiou'\n";
-		Apache->warn("$$: CAS: set_session_data(): SQL: UPDATE $DB_SESSION_TABLE SET last_accessed='$last_accessed', uid='$uid', pgtiou='$pgtiou' WHERE id='$sid';") unless ($LOG_LEVEL < $LOG_DEBUG);
+		Apache2::ServerRec::warn("$$: CAS: set_session_data(): SQL: UPDATE $DB_SESSION_TABLE SET last_accessed='$last_accessed', uid='$uid', pgtiou='$pgtiou' WHERE id='$sid';") unless ($LOG_LEVEL < $LOG_DEBUG);
 		my $sth = $dbh->prepare("UPDATE $DB_SESSION_TABLE SET last_accessed='$last_accessed', uid='$uid', pgtiou='$pgtiou' WHERE id='$sid';");
 		$sth->execute();
 		my $rc = $sth->err;
 
 		# if we have an error when updating the session
 		if ($rc) {
-			Apache->warn("$$: CAS: set_session_data(): error updating session sid='$sid'") unless ($LOG_LEVEL < $LOG_DEBUG);
+			Apache2::ServerRec::warn("$$: CAS: set_session_data(): error updating session sid='$sid'") unless ($LOG_LEVEL < $LOG_DEBUG);
 			$sth->finish();
 			$dbh->disconnect();
 			return "";
 		}
-		Apache->warn("$$: CAS: set_session_data(): updated session sid='$sid': last_accessed='$last_accessed', uid='$uid', pgtiou='$pgtiou'") unless ($LOG_LEVEL < $LOG_DEBUG);
+		Apache2::ServerRec::warn("$$: CAS: set_session_data(): updated session sid='$sid': last_accessed='$last_accessed', uid='$uid', pgtiou='$pgtiou'") unless ($LOG_LEVEL < $LOG_DEBUG);
 	} else {
-		Apache->warn("$$: CAS: set_session_data(): creating new session sid='$sid' to update") unless ($LOG_LEVEL < $LOG_DEBUG);
+		Apache2::ServerRec::warn("$$: CAS: set_session_data(): creating new session sid='$sid' to update") unless ($LOG_LEVEL < $LOG_DEBUG);
 
 		#print "DEBUG2: '$id', '$last_accessed', '$uid', '$pgtiou'\n";
 		my $sth = $dbh->prepare("INSERT INTO $DB_SESSION_TABLE(id,last_accessed,uid,pgtiou) VALUES('$sid', '$last_accessed', '$uid', '$pgtiou');");
@@ -994,12 +1051,12 @@
 	my $self = shift;
 	my $sid = shift;
 
-	Apache->warn("$$: CAS: get_session_data()") unless ($LOG_LEVEL < $LOG_DEBUG);
+	Apache2::ServerRec::warn("$$: CAS: get_session_data()") unless ($LOG_LEVEL < $LOG_DEBUG);
 
 	# retrieve a session object for this session id
-	my $dbh = DBI->connect("dbi:Pg:dbname=$DB_NAME;host=$DB_HOST;port=$DB_PORT", $DB_USER, $DB_PASS, { AutoCommit => 1 });
+	my $dbh = DBI->connect("dbi:mysql:dbname=$DB_NAME", $DB_USER, $DB_PASS, { AutoCommit => 1 });
 	if (!defined($dbh)) {
-		Apache->warn("$$: CAS: get_session_data(): db connect error: $DBI::errstr") unless ($LOG_LEVEL < $LOG_ERROR);
+		Apache2::ServerRec::warn("$$: CAS: get_session_data(): db connect error: $DBI::errstr") unless ($LOG_LEVEL < $LOG_ERROR);
 		return ();
 	}
 	my $sth = $dbh->prepare("SELECT last_accessed, uid, pgtiou FROM $DB_SESSION_TABLE WHERE id='$sid';");
@@ -1011,10 +1068,10 @@
 	$dbh->disconnect();
 
 	if ($result) {
-		Apache->warn("$$: CAS: get_session_data(): got session data for sid='$sid': last_accessed='$last_accessed' uid='$uid' pgtiou='$pgtiou'") unless ($LOG_LEVEL < $LOG_DEBUG);
+		Apache2::ServerRec::warn("$$: CAS: get_session_data(): got session data for sid='$sid': last_accessed='$last_accessed' uid='$uid' pgtiou='$pgtiou'") unless ($LOG_LEVEL < $LOG_DEBUG);
 		return ($sid, $last_accessed, $uid, $pgtiou);
 	}
-	Apache->warn("$$: CAS: get_session_data(): couldn't get session data for sid='$sid'") unless ($LOG_LEVEL < $LOG_DEBUG);
+	Apache2::ServerRec::warn("$$: CAS: get_session_data(): couldn't get session data for sid='$sid'") unless ($LOG_LEVEL < $LOG_DEBUG);
 	return ();
 }
 
@@ -1023,12 +1080,12 @@
 	my $self = shift;
 	my $sid = shift;
 
-	Apache->warn("$$: CAS: delete_session_data()") unless ($LOG_LEVEL < $LOG_DEBUG);
+	Apache2::ServerRec::warn("$$: CAS: delete_session_data()") unless ($LOG_LEVEL < $LOG_DEBUG);
 
 	# retrieve a session object for this session id
-	my $dbh = DBI->connect("dbi:Pg:dbname=$DB_NAME;host=$DB_HOST;port=$DB_PORT", $DB_USER, $DB_PASS, { AutoCommit => 1 });
+	my $dbh = DBI->connect("dbi:mysql:dbname=$DB_NAME", $DB_USER, $DB_PASS, { AutoCommit => 1 });
 	if (!defined($dbh)) {
-		Apache->warn("$$: CAS: delete_session_data(): db connect error: $DBI::errstr") unless ($LOG_LEVEL < $LOG_ERROR);
+		Apache2::ServerRec::warn("$$: CAS: delete_session_data(): db connect error: $DBI::errstr") unless ($LOG_LEVEL < $LOG_ERROR);
 		return "";
 	}
 	my $sth = $dbh->prepare("DELETE FROM $DB_SESSION_TABLE WHERE id='$sid';");
@@ -1038,12 +1095,12 @@
 	my $rc = $sth->err;
 	my $count = $sth->rows;
 	if ($rc) {
-		Apache->warn("$$: CAS: delete_session_data(): error deleting session mapping for sid='$sid'") unless ($LOG_LEVEL < $LOG_DEBUG);
+		Apache2::ServerRec::warn("$$: CAS: delete_session_data(): error deleting session mapping for sid='$sid'") unless ($LOG_LEVEL < $LOG_DEBUG);
 		$sth->finish();
 		$dbh->disconnect();
 		return "";
 	}
-	Apache->warn("$$: CAS: delete_session_data(): deleted '$count' session mappings for sid='$sid'") unless ($LOG_LEVEL < $LOG_DEBUG);
+	Apache2::ServerRec::warn("$$: CAS: delete_session_data(): deleted '$count' session mappings for sid='$sid'") unless ($LOG_LEVEL < $LOG_DEBUG);
 
 	$sth->finish();
 	$dbh->disconnect();
@@ -1055,18 +1112,18 @@
 sub delete_expired_sessions($$) {
 	my $self = shift;
 
-	Apache->warn("$$: CAS: delete_expired_sessions()") unless ($LOG_LEVEL < $LOG_DEBUG);
+	Apache2::ServerRec::warn("$$: CAS: delete_expired_sessions()") unless ($LOG_LEVEL < $LOG_DEBUG);
 
 	my $oldest_valid_time = time() - $SESSION_TIMEOUT;
-	Apache->warn("$$: CAS: delete_expired_sessions(): deleting sessions older than '$oldest_valid_time'") unless ($LOG_LEVEL < $LOG_DEBUG);
+	Apache2::ServerRec::warn("$$: CAS: delete_expired_sessions(): deleting sessions older than '$oldest_valid_time'") unless ($LOG_LEVEL < $LOG_DEBUG);
 
 	# retrieve a session object for this session id
-	my $dbh = DBI->connect("dbi:Pg:dbname=$DB_NAME;host=$DB_HOST;port=$DB_PORT", $DB_USER, $DB_PASS, { AutoCommit => 1 });
+	my $dbh = DBI->connect("dbi:mysql:dbname=$DB_NAME", $DB_USER, $DB_PASS, { AutoCommit => 1 });
 	if (!defined($dbh)) {
-		Apache->warn("$$: CAS: delete_expired_sessions(): db connect error: $DBI::errstr") unless ($LOG_LEVEL < $LOG_ERROR);
+		Apache2::ServerRec::warn("$$: CAS: delete_expired_sessions(): db connect error: $DBI::errstr") unless ($LOG_LEVEL < $LOG_ERROR);
 		return "";
 	}
-	Apache->warn("$$: CAS: delete_expired_sessions(): SQL: DELETE FROM $DB_SESSION_TABLE WHERE last_accessed<$oldest_valid_time;");
+	Apache2::ServerRec::warn("$$: CAS: delete_expired_sessions(): SQL: DELETE FROM $DB_SESSION_TABLE WHERE last_accessed<$oldest_valid_time;");
 	my $sth = $dbh->prepare("DELETE FROM $DB_SESSION_TABLE WHERE last_accessed<$oldest_valid_time;");
 	$sth->execute();
 
@@ -1074,12 +1131,12 @@
 	my $rc = $sth->err;
 	my $count = $sth->rows;
 	if ($rc) {
-		Apache->warn("$$: CAS: delete_expired_sessions(): error deleting expired sessions") unless ($LOG_LEVEL < $LOG_ERROR);
+		Apache2::ServerRec::warn("$$: CAS: delete_expired_sessions(): error deleting expired sessions") unless ($LOG_LEVEL < $LOG_ERROR);
 		$sth->finish();
 		$dbh->disconnect();
 		return "";
 	}
-	Apache->warn("$$: CAS: delete_expired_sessions(): deleted '$count' session mappings") unless ($LOG_LEVEL < $LOG_DEBUG);
+	Apache2::ServerRec::warn("$$: CAS: delete_expired_sessions(): deleted '$count' session mappings") unless ($LOG_LEVEL < $LOG_DEBUG);
 
 	$sth->finish();
 	$dbh->disconnect();
@@ -1093,11 +1150,11 @@
 	my $pgtiou = shift;
 	my $pgt = shift;
 
-	Apache->warn("$$: CAS: set_pgt()") unless ($LOG_LEVEL < $LOG_DEBUG);
+	Apache2::ServerRec::warn("$$: CAS: set_pgt()") unless ($LOG_LEVEL < $LOG_DEBUG);
 
-	my $dbh = DBI->connect("dbi:Pg:dbname=$DB_NAME;host=$DB_HOST;port=$DB_PORT", $DB_USER, $DB_PASS, { AutoCommit => 1 });
+	my $dbh = DBI->connect("dbi:mysql:dbname=$DB_NAME", $DB_USER, $DB_PASS, { AutoCommit => 1 });
 	if (!defined($dbh)) {
-		Apache->warn("$$: CAS: set_pgt(): db connect error: $DBI::errstr") unless ($LOG_LEVEL < $LOG_ERROR);
+		Apache2::ServerRec::warn("$$: CAS: set_pgt(): db connect error: $DBI::errstr") unless ($LOG_LEVEL < $LOG_ERROR);
 		return "";
 	}
 
@@ -1112,7 +1169,7 @@
 		$dbh->disconnect();
 		return "";
 	} else {
-		Apache->warn("$$: CAS: set_pgt(): adding pgtiou/pgt map for pgtiou='$pgtiou' pgt='$pgt'") unless ($LOG_LEVEL < $LOG_DEBUG);
+		Apache2::ServerRec::warn("$$: CAS: set_pgt(): adding pgtiou/pgt map for pgtiou='$pgtiou' pgt='$pgt'") unless ($LOG_LEVEL < $LOG_DEBUG);
 
 		#print "DEBUG2: '$pgtiou', '$pgt'\n";
 		my $created = time();
@@ -1128,7 +1185,7 @@
 		}
 	}
 	
-	Apache->warn("$$: CAS: set_pgt(): updated '$count' pgtiou/pgt map") unless ($LOG_LEVEL < $LOG_DEBUG);
+	Apache2::ServerRec::warn("$$: CAS: set_pgt(): updated '$count' pgtiou/pgt map") unless ($LOG_LEVEL < $LOG_DEBUG);
 
 	$sth->finish();
 	$dbh->disconnect();
@@ -1142,12 +1199,12 @@
 	my $pgtiou = shift;
 	my $sid = shift || "";
 
-	Apache->warn("$$: CAS: get_pgt(): getting pgtiou/pgt map for pgtiou='$pgtiou'") unless ($LOG_LEVEL < $LOG_DEBUG);
+	Apache2::ServerRec::warn("$$: CAS: get_pgt(): getting pgtiou/pgt map for pgtiou='$pgtiou'") unless ($LOG_LEVEL < $LOG_DEBUG);
 
 	# retrieve a pgt for this pgtiou
-	my $dbh = DBI->connect("dbi:Pg:dbname=$DB_NAME;host=$DB_HOST;port=$DB_PORT", $DB_USER, $DB_PASS, { AutoCommit => 1 });
+	my $dbh = DBI->connect("dbi:mysql:dbname=$DB_NAME", $DB_USER, $DB_PASS, { AutoCommit => 1 });
 	if (!defined($dbh)) {
-		Apache->warn("$$: CAS: get_pgt(): db connect error: $DBI::errstr") unless ($LOG_LEVEL < $LOG_ERROR);
+		Apache2::ServerRec::warn("$$: CAS: get_pgt(): db connect error: $DBI::errstr") unless ($LOG_LEVEL < $LOG_ERROR);
 		return "";
 	}
 	my $sth = $dbh->prepare("SELECT pgt FROM $DB_PGTIOU_TABLE WHERE pgtiou='$pgtiou';");
@@ -1159,10 +1216,10 @@
 	$dbh->disconnect();
 
 	if ($result) {
-		Apache->warn("$$: CAS: get_pgt(): got pgtiou/pgt map pgtiou='$pgtiou' pgt='$pgt'") unless ($LOG_LEVEL < $LOG_DEBUG);
+		Apache2::ServerRec::warn("$$: CAS: get_pgt(): got pgtiou/pgt map pgtiou='$pgtiou' pgt='$pgt'") unless ($LOG_LEVEL < $LOG_DEBUG);
 		return $pgt;
 	}
-	Apache->warn("$$: CAS: get_pgt(): coudln't get pgtiou/pgt map pgtiou='$pgtiou'") unless ($LOG_LEVEL < $LOG_DEBUG);
+	Apache2::ServerRec::warn("$$: CAS: get_pgt(): coudln't get pgtiou/pgt map pgtiou='$pgtiou'") unless ($LOG_LEVEL < $LOG_DEBUG);
 	return "";
 }
 
@@ -1171,12 +1228,12 @@
 	my $self = shift;
 	my $pgtiou = shift;
 
-	Apache->warn("$$: CAS: delete_pgt()") unless ($LOG_LEVEL < $LOG_DEBUG);
+	Apache2::ServerRec::warn("$$: CAS: delete_pgt()") unless ($LOG_LEVEL < $LOG_DEBUG);
 
 	# retrieve a session object for this session id
-	my $dbh = DBI->connect("dbi:Pg:dbname=$DB_NAME;host=$DB_HOST;port=$DB_PORT", $DB_USER, $DB_PASS, { AutoCommit => 1 });
+	my $dbh = DBI->connect("dbi:mysql:dbname=$DB_NAME", $DB_USER, $DB_PASS, { AutoCommit => 1 });
 	if (!defined($dbh)) {
-		Apache->warn("$$: CAS: delete_pgt(): db connect error: $DBI::errstr") unless ($LOG_LEVEL < $LOG_ERROR);
+		Apache2::ServerRec::warn("$$: CAS: delete_pgt(): db connect error: $DBI::errstr") unless ($LOG_LEVEL < $LOG_ERROR);
 		return "";
 	}
 	my $sth = $dbh->prepare("DELETE FROM $DB_PGTIOU_TABLE WHERE pgtiou='$pgtiou';");
@@ -1186,12 +1243,12 @@
 	my $rc = $sth->err;
 	my $count = $sth->rows;
 	if ($rc) {
-		Apache->warn("$$: CAS: delete_pgt(): error deleting pgtiou/pgt mapping for pgtiou='$pgtiou'") unless ($LOG_LEVEL < $LOG_DEBUG);
+		Apache2::ServerRec::warn("$$: CAS: delete_pgt(): error deleting pgtiou/pgt mapping for pgtiou='$pgtiou'") unless ($LOG_LEVEL < $LOG_DEBUG);
 		$sth->finish();
 		$dbh->disconnect();
 		return "";
 	}
-	Apache->warn("$$: CAS: delete_pgt(): deleted '$count' pgtiou/pgt mappings for pgtiou='$pgtiou'") unless ($LOG_LEVEL < $LOG_DEBUG);
+	Apache2::ServerRec::warn("$$: CAS: delete_pgt(): deleted '$count' pgtiou/pgt mappings for pgtiou='$pgtiou'") unless ($LOG_LEVEL < $LOG_DEBUG);
 
 	$sth->finish();
 	$dbh->disconnect();
@@ -1203,12 +1260,12 @@
 sub delete_expired_pgts($$) {
 	my $self = shift;
 
-	Apache->warn("$$: CAS: delete_expired_pgts()") unless ($LOG_LEVEL < $LOG_DEBUG);
+	Apache2::ServerRec::warn("$$: CAS: delete_expired_pgts()") unless ($LOG_LEVEL < $LOG_DEBUG);
 
 	# retrieve a session object for this session id
-	my $dbh = DBI->connect("dbi:Pg:dbname=$DB_NAME;host=$DB_HOST;port=$DB_PORT", $DB_USER, $DB_PASS, { AutoCommit => 1 });
+	my $dbh = DBI->connect("dbi:mysql:dbname=$DB_NAME", $DB_USER, $DB_PASS, { AutoCommit => 1 });
 	if (!defined($dbh)) {
-		Apache->warn("$$: CAS: delete_expired_pgts(): db connect error: $DBI::errstr") unless ($LOG_LEVEL < $LOG_ERROR);
+		Apache2::ServerRec::warn("$$: CAS: delete_expired_pgts(): db connect error: $DBI::errstr") unless ($LOG_LEVEL < $LOG_ERROR);
 		return "";
 	}
 
@@ -1220,12 +1277,12 @@
 	my $rc = $sth->err;
 	my $count = $sth->rows;
 	if ($rc) {
-		Apache->warn("$$: CAS: delete_expired_pgts(): error deleting pgtiou/pgt mappings") unless ($LOG_LEVEL < $LOG_DEBUG);
+		Apache2::ServerRec::warn("$$: CAS: delete_expired_pgts(): error deleting pgtiou/pgt mappings") unless ($LOG_LEVEL < $LOG_DEBUG);
 		$sth->finish();
 		$dbh->disconnect();
 		return "";
 	}
-	Apache->warn("$$: CAS: delete_expired_pgts(): deleted '$count' pgtiou/pgt mappings") unless ($LOG_LEVEL < $LOG_DEBUG);
+	Apache2::ServerRec::warn("$$: CAS: delete_expired_pgts(): deleted '$count' pgtiou/pgt mappings") unless ($LOG_LEVEL < $LOG_DEBUG);
 
 	$sth->finish();
 	$dbh->disconnect();
@@ -1243,15 +1300,15 @@
 	
 	my $pgt;
 
-	Apache->warn("$$: CAS: do_proxy(): looking up PGTIOU='$pgtiou' in cache") unless ($LOG_LEVEL < $LOG_DEBUG);
+	Apache2::ServerRec::warn("$$: CAS: do_proxy(): looking up PGTIOU='$pgtiou' in cache") unless ($LOG_LEVEL < $LOG_DEBUG);
 	if (!($pgt = $self->get_pgt($pgtiou, $sid))) {
-		Apache->warn("$$: CAS: do_proxy(): PGTIOU='$pgtiou' not found in cache!, deleting mapping and session, then redirecting to error page") unless ($LOG_LEVEL < $LOG_WARN);
+		Apache2::ServerRec::warn("$$: CAS: do_proxy(): PGTIOU='$pgtiou' not found in cache!, deleting mapping and session, then redirecting to error page") unless ($LOG_LEVEL < $LOG_WARN);
 
 		# deleting this PGTIOU mapping
 		if (!$self->delete_pgt($pgtiou)) {
-			Apache->warn("$$: CAS: do_proxy(): couldn't delete pgt '$pgtiou'") unless ($LOG_LEVEL < $LOG_WARN);
+			Apache2::ServerRec::warn("$$: CAS: do_proxy(): couldn't delete pgt '$pgtiou'") unless ($LOG_LEVEL < $LOG_WARN);
 		} else {
-			Apache->warn("$$: CAS: do_proxy(): deleted pgt '$pgtiou'") unless ($LOG_LEVEL < $LOG_DEBUG);
+			Apache2::ServerRec::warn("$$: CAS: do_proxy(): deleted pgt '$pgtiou'") unless ($LOG_LEVEL < $LOG_DEBUG);
 		}
 
 		# deleting session, since a new PGTIOU can't be retrieved until the
@@ -1260,11 +1317,11 @@
 
 		return $self->redirect($r, $ERROR_URL, $INVALID_PGT_ERROR_CODE);
 	}
-	Apache->warn("$$: CAS: do_proxy(): PGTIOU='$pgtiou' found in cache, PGT='$pgt'") unless ($LOG_LEVEL < $LOG_DEBUG);
+	Apache2::ServerRec::warn("$$: CAS: do_proxy(): PGTIOU='$pgtiou' found in cache, PGT='$pgt'") unless ($LOG_LEVEL < $LOG_DEBUG);
 
 	my @tickets = $self->get_proxy_tickets($pgt, $PROXY_SERVICE, $NUM_PROXY_TICKETS);
 	if (@tickets) {
-		Apache->warn("$$: CAS: do_proxy(): got PT='".join(',', @tickets)."'") unless ($LOG_LEVEL < $LOG_DEBUG);
+		Apache2::ServerRec::warn("$$: CAS: do_proxy(): got PT='".join(',', @tickets)."'") unless ($LOG_LEVEL < $LOG_DEBUG);
 
 		# place headers in request for underlying service
 		my $service;
@@ -1276,41 +1333,40 @@
 			$service = $self->urlEncode($SERVICE);
 		}
 
-		Apache->warn("$$: CAS: do_proxy(): setting header CAS_FILTER_HOST=$CAS_HOST") unless ($LOG_LEVEL < $LOG_DEBUG);
-		Apache->warn("$$: CAS: do_proxy(): setting header CAS_FILTER_PORT=$CAS_PORT") unless ($LOG_LEVEL < $LOG_DEBUG);
-		Apache->warn("$$: CAS: do_proxy(): setting header CAS_FILTER_LOGIN_URI=$CAS_LOGIN_URI") unless ($LOG_LEVEL < $LOG_DEBUG);
-		Apache->warn("$$: CAS: do_proxy(): setting header CAS_FILTER_SERVICE=$service") unless ($LOG_LEVEL < $LOG_DEBUG);
-		Apache->warn("$$: CAS: do_proxy(): setting header CAS_FILTER_USER=$user") unless ($LOG_LEVEL < $LOG_DEBUG);
+		Apache2::ServerRec::warn("$$: CAS: do_proxy(): setting header CAS_FILTER_HOST=$CAS_HOST") unless ($LOG_LEVEL < $LOG_DEBUG);
+		Apache2::ServerRec::warn("$$: CAS: do_proxy(): setting header CAS_FILTER_PORT=$CAS_PORT") unless ($LOG_LEVEL < $LOG_DEBUG);
+		Apache2::ServerRec::warn("$$: CAS: do_proxy(): setting header CAS_FILTER_LOGIN_URI=$CAS_LOGIN_URI") unless ($LOG_LEVEL < $LOG_DEBUG);
+		Apache2::ServerRec::warn("$$: CAS: do_proxy(): setting header CAS_FILTER_SERVICE=$service") unless ($LOG_LEVEL < $LOG_DEBUG);
+		Apache2::ServerRec::warn("$$: CAS: do_proxy(): setting header CAS_FILTER_USER=$user") unless ($LOG_LEVEL < $LOG_DEBUG);
 		if ($LOG_LEVEL >= $LOG_DEBUG) {
 			for (my $i=1; $i <= scalar(@tickets); $i++) {
 				if ($i == 1) {
-					Apache->warn("$$: CAS: do_proxy(): setting header CAS_FILTER_PT=".$tickets[0]);
-					Apache->warn("$$: CAS: do_proxy(): setting header CAS_FILTER_PT1=".$tickets[0]);
+					Apache2::ServerRec::warn("$$: CAS: do_proxy(): setting header CAS_FILTER_PT=".$tickets[0]);
+					Apache2::ServerRec::warn("$$: CAS: do_proxy(): setting header CAS_FILTER_PT1=".$tickets[0]);
 				} else {
-					Apache->warn("$$: CAS: do_proxy(): setting header CAS_FILTER_PT$i=".$tickets[$i-1]);
+					Apache2::ServerRec::warn("$$: CAS: do_proxy(): setting header CAS_FILTER_PT$i=".$tickets[$i-1]);
 				}
 			}
 		}
-		$r->header_in("CAS_FILTER_CAS_HOST", $CAS_HOST);
-		$r->header_in("CAS_FILTER_CAS_PORT", $CAS_PORT);
-		$r->header_in("CAS_FILTER_CAS_LOGIN_URI", $CAS_LOGIN_URI);
-		$r->header_in("CAS_FILTER_SERVICE", $service);
-		$r->header_in('CAS_FILTER_USER', $user);
+		compat_table_get_set($r, scalar($r->headers_in), "CAS_FILTER_CAS_HOST", $CAS_HOST);
+		compat_table_get_set($r, scalar($r->headers_in), "CAS_FILTER_CAS_PORT", $CAS_PORT);
+		compat_table_get_set($r, scalar($r->headers_in), "CAS_FILTER_CAS_LOGIN_URI", $CAS_LOGIN_URI);
+		compat_table_get_set($r, scalar($r->headers_in), "CAS_FILTER_SERVICE", $service);
+		compat_table_get_set($r, scalar($r->headers_in), 'CAS_FILTER_USER', $user);
 
 		if ($PRETEND_BASIC_AUTH) {
 			# setup this up for underlying authz modules that rely on Basic auth having been performed
-			$r->header_in('Authorization', "Basic " . encode_base64($user . ":DUMMYPASS"));
+			compat_table_get_set($r, scalar($r->headers_in), 'Authorization', "Basic " . encode_base64($user . ":DUMMYPASS"));
 			$r->user($user);
-			$r->connection->user($user);
-			$r->connection->auth_type("Basic");
+			$r->ap_auth_type("Basic");
 		}
 
 		for (my $i=1; $i <= scalar(@tickets); $i++) {
 			if ($i == 1) {
-				$r->header_in('CAS_FILTER_PT', $tickets[0]);
-				$r->header_in('CAS_FILTER_PT1', $tickets[0]);
+				compat_table_get_set($r, scalar($r->headers_in), 'CAS_FILTER_PT', $tickets[0]);
+				compat_table_get_set($r, scalar($r->headers_in), 'CAS_FILTER_PT1', $tickets[0]);
 			} else {
-				$r->header_in("CAS_FILTER_PT$i", $tickets[$i-1]);
+				compat_table_get_set($r, scalar($r->headers_in), "CAS_FILTER_PT$i", $tickets[$i-1]);
 			}
 		}
 
@@ -1318,29 +1374,29 @@
 		if ($ticket_redirect) {
 			# redirect to this same page minus the ticket
 			if (($REMOVE_TICKET eq "true") || ($REMOVE_TICKET eq "1")) {
-				Apache->warn("$$: CAS: authenticate(): trying to remove service ticket from URI") unless ($LOG_LEVEL < $LOG_DEBUG);
+				Apache2::ServerRec::warn("$$: CAS: authenticate(): trying to remove service ticket from URI") unless ($LOG_LEVEL < $LOG_DEBUG);
 				return $self->redirect_without_ticket($r);
 			} else {
-				Apache->warn("$$: CAS: authenticate(): not trying to remove service ticket from URI") unless ($LOG_LEVEL < $LOG_DEBUG);
-				return (MP2 ? Apache::OK : Apache::Constants::OK);
+				Apache2::ServerRec::warn("$$: CAS: authenticate(): not trying to remove service ticket from URI") unless ($LOG_LEVEL < $LOG_DEBUG);
+				return (MP2 ? Apache2::Const::OK : Apache::Constants::OK);
 			}
 		}
-		return (MP2 ? Apache::OK : Apache::Constants::OK);
+		return (MP2 ? Apache2::Const::OK : Apache::Constants::OK);
 	} else {
-		Apache->warn("$$: CAS: do_proxy(): failed to get PT") unless ($LOG_LEVEL < $LOG_WARN);
+		Apache2::ServerRec::warn("$$: CAS: do_proxy(): failed to get PT") unless ($LOG_LEVEL < $LOG_WARN);
 
 		# deleting this PGTIOU mapping
 		if (!$self->delete_pgt($pgtiou)) {
-			Apache->warn("$$: CAS: do_proxy(): couldn't delete pgt '$pgtiou'") unless ($LOG_LEVEL < $LOG_WARN);
+			Apache2::ServerRec::warn("$$: CAS: do_proxy(): couldn't delete pgt '$pgtiou'") unless ($LOG_LEVEL < $LOG_WARN);
 		} else {
-			Apache->warn("$$: CAS: do_proxy(): deleted pgt '$pgtiou'") unless ($LOG_LEVEL < $LOG_DEBUG);
+			Apache2::ServerRec::warn("$$: CAS: do_proxy(): deleted pgt '$pgtiou'") unless ($LOG_LEVEL < $LOG_DEBUG);
 		}
 
 		# deleting this session for this user
-		Apache->warn("$$: CAS: do_proxy(): deleting session data for sid='$sid'") unless ($LOG_LEVEL < $LOG_DEBUG);
+		Apache2::ServerRec::warn("$$: CAS: do_proxy(): deleting session data for sid='$sid'") unless ($LOG_LEVEL < $LOG_DEBUG);
 		$self->delete_session_data($sid);
 
-		Apache->warn("$$: CAS: do_proxy(): redirecting to CAS error page") unless ($LOG_LEVEL < $LOG_DEBUG);
+		Apache2::ServerRec::warn("$$: CAS: do_proxy(): redirecting to CAS error page") unless ($LOG_LEVEL < $LOG_DEBUG);
 		return $self->redirect($r, $ERROR_URL, $INVALID_PGT_ERROR_CODE);
 	}
 }
@@ -1377,14 +1433,14 @@
 	# get our request and log object
 	my ($self, $r) = @_;
 
-	Apache->warn("$$: CAS: this_url()") unless ($LOG_LEVEL < $LOG_DEBUG);
+	Apache2::ServerRec::warn("$$: CAS: this_url()") unless ($LOG_LEVEL < $LOG_DEBUG);
 
 	# get the local server name
 	my $s = $r->server;
 	my $local_hostname = $r->hostname;
 
 	# grab the uri that was requested (mod_perl 1.0 compatible)
-	my $uri = Apache::URI->parse($r);
+	my $uri = APR::URI->parse($r->pool, $r->construct_url);
 	my $uri2 = $r->parsed_uri;
 	my $uri3;
 	if (MP2) {
@@ -1401,16 +1457,16 @@
 	}
 
 	if ($query) {
-		Apache->warn("$$: CAS: this_url(): have query string '$query'") unless ($LOG_LEVEL < $LOG_DEBUG);
+		Apache2::ServerRec::warn("$$: CAS: this_url(): have query string '$query'") unless ($LOG_LEVEL < $LOG_DEBUG);
 		$query =~ s/\??&?ticket=[^&]+//;
 		if ($query ne "") {
 			$path .= "?$query";
 		}
 	} elsif ($unparsed =~ /\?$/) {
-		Apache->warn("$$: CAS: this_url(): adding '?' to query string") unless ($LOG_LEVEL < $LOG_DEBUG);
+		Apache2::ServerRec::warn("$$: CAS: this_url(): adding '?' to query string") unless ($LOG_LEVEL < $LOG_DEBUG);
 		$path .= "?";
 	} else {
-		Apache->warn("$$: CAS: this_url(): no query string") unless ($LOG_LEVEL < $LOG_DEBUG);
+		Apache2::ServerRec::warn("$$: CAS: this_url(): no query string") unless ($LOG_LEVEL < $LOG_DEBUG);
 	}
 
 	my $local_port = $r->get_server_port ? ($r->get_server_port) : '';
@@ -1418,13 +1474,13 @@
 	my $local_port3 = $s->port ? ($s->port) : '';
 	my $port = "";
 	if ($local_port ne "") {
-		Apache->warn("$$: CAS: this_url(): 1: setting port to '$local_port'") unless ($LOG_LEVEL < $LOG_DEBUG);
+		Apache2::ServerRec::warn("$$: CAS: this_url(): 1: setting port to '$local_port'") unless ($LOG_LEVEL < $LOG_DEBUG);
 		$port = $local_port;
 	} elsif ($local_port2 ne "") {
-		Apache->warn("$$: CAS: this_url(): 2: setting port to '$local_port2'") unless ($LOG_LEVEL < $LOG_DEBUG);
+		Apache2::ServerRec::warn("$$: CAS: this_url(): 2: setting port to '$local_port2'") unless ($LOG_LEVEL < $LOG_DEBUG);
 		$port = $local_port2;
 	} elsif ($local_port3 ne "") {
-		Apache->warn("$$: CAS: this_url(): 3: setting port to '$local_port3'") unless ($LOG_LEVEL < $LOG_DEBUG);
+		Apache2::ServerRec::warn("$$: CAS: this_url(): 3: setting port to '$local_port3'") unless ($LOG_LEVEL < $LOG_DEBUG);
 		$port = $local_port3;
 	}
 
@@ -1441,7 +1497,7 @@
 	# get our request and log object
 	my ($self, $r) = @_;
 
-	Apache->warn("$$: CAS: this_url_encoded()") unless ($LOG_LEVEL < $LOG_DEBUG);
+	Apache2::ServerRec::warn("$$: CAS: this_url_encoded()") unless ($LOG_LEVEL < $LOG_DEBUG);
 
 	my $url = $self->this_url($r);
 
