📄 snoopdb.pl
字号:
sub BEGIN
{ push @INC, qw ( ../Pi3Perl/lib ); }
use strict;
use Pi3;
sub execute {
my($obj) = shift;
my($pihttp) = shift;
my($iobuf) = shift;
my($written);
my($response_db);
my($request_db);
my($connection_db);
my($host_db);
my($iterator);
my($result);
my($key);
my($response) = "";
$request_db = Pi3::PIHTTP_getDB($pihttp, Pi3::GETDB_REQUEST);
$response_db = Pi3::PIHTTP_getDB($pihttp, &Pi3::GETDB_RESPONSE);
$connection_db = Pi3::PIHTTP_getDB($pihttp, &Pi3::GETDB_CONNECTION);
$host_db = Pi3::PIHTTP_getDB($pihttp, &Pi3::GETDB_HOST);
$response .= "<html><body background=\"/icons/Pi3Tile.gif\" bgcolor=\"#FFFFFF\">\n";
$response .= "<table width=\"100%\"><TR>";
$response .= "<td align=LEFT valign=CENTER><h1>Explore the Pi3Web database with Pi3Perl</h1></td>\n";
$response .= "<td align=CENTER valign=CENTER><img src=\"/icons/Pi3Web_earth2.gif\" alt=\"Pi3Web\"></td>\n";
$response .= "</tr></table>\n";
$response .= "Press the following <a href=\"/pi3perl/snoopdb.pl/text.txt?variable1=value1&variable2=value2\">link</a>";
$response .= " to create some <i>PathInfo</i> and <i>QueryString</i> related variables.";
$response .= "<HR>\n";
$response .= &explore_db($request_db, "<H2>Request Database</H2>");
$response .= &explore_db($response_db, "<H2>Response Database</H2>");
$response .= &explore_db($connection_db, "<H2>Connection Database</H2>");
$response .= &explore_db($host_db, "<H2>Host Database</H2>");
# Set content-type and start response (send HTTP status line and response headers)
Pi3::HTTPCore_sendGeneralHeaders($pihttp);
Pi3::PIDB_replace($response_db,&Pi3::PIDBTYPE_RFC822,"Content-Type","text/html",&Pi3::PIDBFLAG_NONE);
# Either disable connection keep-alive or send a correct content-length.
Pi3::PIDB_replace($response_db,&Pi3::PIDBTYPE_RFC822,"Content-Length",length($response),&Pi3::PIDBFLAG_NONE);
Pi3::HTTPCore_sendEntityHeaders($pihttp, $response_db);
# get output buffer structure and write out response
$written = Pi3::PIIOBuffer_write($iobuf,$response,length($response),&Pi3::PIIOBUF_NONE);
return &Pi3::PIAPI_COMPLETED;
};
sub explore_db {
my ($database) = shift;
my ($text) = shift;
$text .= &explore_type($database, &Pi3::PIDBTYPE_STRING, "<H5>DBTYPE_STRING</H5>");
$text .= &explore_type($database, &Pi3::PIDBTYPE_RFC822, "<H5>DBTYPE_RFC822</H5>");
$text .= &explore_type($database, &Pi3::PIDBTYPE_OPAQUE, "<H5>DBTYPE_OPAQUE</H5>");
return $text;
};
sub explore_type {
my ($database) = shift;
my ($type) = shift;
my ($text) = shift;
my ($iterator);
my ($key);
my ($result);
$iterator = Pi3::PIDB_getIterator($database,$type,"",&Pi3::PIDBFLAG_NONE);
if ($iterator) {
$text = "" unless (Pi3::PIDBIterator_atValidElement($iterator));
while (Pi3::PIDBIterator_atValidElement($iterator)) {
$result = Pi3::PIDBIterator_current($iterator,$type,$key);
$text .= sprintf("%s: %s\n<BR>", $key, $result) if ($key);
Pi3::PIDBIterator_next($iterator);
};
Pi3::PIDBIterator_delete($iterator);
};
return $text;
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -