Pi3Perl
PspHandler


Name:
Pi3Perl

Description:
Load and execute an Pi3Perl script extension.

Options:
Option Default Values Short Description Example(s)
Init - Any subroutine name in Pi3Perl file Define a perl sub to be called for initialisation Init="init"
Excute + Any subroutine name in Pi3Perl file Define a perl sub to be called for execution Execute="exec"
File + Any valid (.pl) file name Define a Pi3Perl script to be loaded and executed File="../Pi3Perl/snoopdb.pl"
- in the default indicates no default
+ in the default indicates the field is mandatory

Description of Options

Init
After successful run of the perl parser during startup, the Init subroutine is called. This is only done, if the optional Init parameter is set. The Init sub will get the Pi3 object as a parameter from the perl stack. One scalar return value is expected to get back by Pi3Web, either to contain PIAPI_COMPLETED or PIAPI_ERROR.
Execute
During request, the perl subroutine, given as the value of this configuration key is executed. The Execute sub will get the Pi3 object, the PIHTTP object and the PIIOBuffer object as parameters from the perl stack. One scalar return value is expected to get back by Pi3Web, either to contain PIAPI_COMPLETED or PIAPI_ERROR.
File
The given file will be loaded during Pi3Web startup. The file is parsed by perl and the server won't start, if the parser fails.

Phase:
HANDLE

Returns:
PIAPI_COMPLETED or PIAPI_ERROR according to the status returned by the extension.

Note:
For the PSP language specification refer to the respective Pi3-HOWTO page.

Example:

	<Object>
		Name P3P
		Class FlexibleHandlerClass
		Condition "&cmp(&dblookup(response,string,ObjectMap),PSP)"
		CheckPath ReturnCode ReturnCode=COMPLETED
		CheckType ReturnCode ReturnCode=COMPLETED
		CheckAccess AccessByFile RequirePermissions="X"
		Handle Pi3Perl File="../Pi3Perl/snoopdb.pl" Pi3Perl Execute="execute"
	</Object>
	

A Pi3Perl file to perform Http redirects:

	use strict;
	use Pi3;

	sub execute {
		my($obj) = shift;
		my($pihttp) = shift;
		my($iobuf) = shift;
		my($r) = Pi3::PIHTTP_getDB($pihttp, &Pi3::GETDB_RESPONSE);

		# Set the location header and the appropriate StatusCode (302 Found)
		my($l) = "http://localhost".Pi3::PIDB_lookup($r,&Pi3::PIDBTYPE_STRING,"PathInfo",&Pi3::PIDBFLAG_NONE);
		Pi3::PIDB_replace($r,&Pi3::PIDBTYPE_RFC822,"Location",$l,&Pi3::PIDBFLAG_NONE);
		Pi3::HTTPUtil_doHTTPError($pihttp,&Pi3::ST_FOUND);

		# Send HTTP status line and response headers
		Pi3::HTTPCore_sendGeneralHeaders($pihttp);
		Pi3::HTTPCore_sendEntityHeaders($pihttp, $r);
		return &Pi3::PIAPI_COMPLETED;
	}

:


Name:
PspHandler

Description:
Load and execute an PSP (Perl Server Pages) extension.

Options:
Option Default Values Short Description Example(s)
DestructLevel - 0, 1 define destruction level for perl interpreters DestructLevel 1
- in the default indicates no default
+ in the default indicates the field is mandatory

Description of Options

DestructLevel
A value of 1 will force the explicite destruction of used perl interpreter instances during server shutdown. This may currently cause server crashes. A value of 0 (default, recommended) does nothing on shutdown.

Phase:
HANDLE

Returns:
PIAPI_COMPLETED or PIAPI_ERROR according to the status returned by the extension.

Note:
For the PSP language specification refer to the respective Pi3-HOWTO page.

Example:

	<Object>
		Name PSP
		Class FlexibleHandlerClass
		Condition "&cmp(&dblookup(response,string,ObjectMap),PSP)"
		CheckPath ReturnCode ReturnCode=COMPLETED
		CheckType ReturnCode ReturnCode=COMPLETED
		CheckAccess AccessByFile RequirePermissions="X"
		Handle PerlSrvPages
	</Object>
	

A PSP script to perform Http redirects:

	<%
	sub pspSetResponse {
		$pspResponse{"Location"} = "http://localhost".$pspRequest{"PathInfo"};
		$pspResponseStatus = 302;
		return 0;
	}
	%>