improvements to PageCompiler (new precondition page attribute)

This commit is contained in:
Guenter Obiltschnig 2008-06-10 15:21:44 +00:00
parent 9f751f5e9a
commit ecefa6121c
3 changed files with 730 additions and 677 deletions

View File

@ -2,7 +2,8 @@ POCO C++ Server Page Compiler User Guide
PageCompiler PageCompiler
!!!Introduction !!!Introduction
PageCompiler is a command line tool that translates HTML files (and other kinds of files), into PageCompiler is a command line tool that translates HTML files (and other kinds of files, such as
cascading style sheet files), into
C++ code, more precisely, subclasses of Poco::Net::HTTPRequestHandler. C++ code, more precisely, subclasses of Poco::Net::HTTPRequestHandler.
The source files can contain special directives that allow it to include C++ code into The source files can contain special directives that allow it to include C++ code into
the source file. The syntax of this directives is based on the syntax used for the source file. The syntax of this directives is based on the syntax used for
@ -179,6 +180,53 @@ Allows you to specify whether the response is sent using chunked transfer encodi
Defaults to <[true]>. Defaults to <[true]>.
Set the value to <[false]> to disable chunked transfer encoding. Set the value to <[false]> to disable chunked transfer encoding.
!precondition
Allows the specification of a precondition, which must be a C++ expression
valid in the context of the request handler. This can be used to implement
authentication.
Example:
<%@ page
class="AuthSamplePage"
precondition="checkCredentials(request, response)"
%>
<%!
bool checkCredentials(Poco::Net::HTTPServerRequest& request, Poco::Net::HTTPServerResponse& response)
{
bool isAuthenticated = false;
if (request.hasCredentials())
{
std::string scheme;
std::string authInfo;
request.getCredentials(scheme, authInfo);
if (scheme == Poco::Net::HTTPBasicCredentials::SCHEME)
{
Poco::Net::HTTPBasicCredentials cred(request);
isAuthenticated = (cred.getUsername() == "joeuser" && cred.getPassword() == "s3cr3t");
}
}
if (!isAuthenticated)
{
response.requireAuthentication("Restricted Area");
response.send();
}
return isAuthenticated;
}
%>
<html>
<head>
<title>Restricted Area</title>
</head>
<body>
<h1>Restricted Area</h1>
</body>
</html>
----
!session (OSP only) !session (OSP only)
For use with the POCO Open Service Platform only. For use with the POCO Open Service Platform only.

View File

@ -1,7 +1,7 @@
// //
// CodeWriter.cpp // CodeWriter.cpp
// //
// $Id: //poco/Main/PageCompiler/src/CodeWriter.cpp#1 $ // $Id: //poco/1.3/PageCompiler/src/CodeWriter.cpp#1 $
// //
// Copyright (c) 2008, Applied Informatics Software Engineering GmbH. // Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
@ -234,6 +234,10 @@ void CodeWriter::writeHandler(std::ostream& ostr)
{ {
ostr << "void " << _class << "::handleRequest(Poco::Net::HTTPServerRequest& request, Poco::Net::HTTPServerResponse& response)\n"; ostr << "void " << _class << "::handleRequest(Poco::Net::HTTPServerRequest& request, Poco::Net::HTTPServerResponse& response)\n";
ostr << "{\n"; ostr << "{\n";
if (_page.has("page.precondition"))
{
ostr << "\tif (!(" << _page.get("page.precondition") << ")) return;\n\n";
}
writeSession(ostr); writeSession(ostr);
writeForm(ostr); writeForm(ostr);
writeRequest(ostr); writeRequest(ostr);
@ -289,4 +293,5 @@ void CodeWriter::writeRequest(std::ostream& ostr)
ostr << "\tresponse.setContentType(\"" << contentType << "\");\n"; ostr << "\tresponse.setContentType(\"" << contentType << "\");\n";
ostr << "\n"; ostr << "\n";
ostr << "\tstd::ostream& ostr = response.send();\n"; ostr << "\tstd::ostream& ostr = response.send();\n";
ostr << "\tif (request.getMethod() == Poco::Net::HTTPRequest::HTTP_HEAD) return;\n";
} }

View File

@ -1,7 +1,7 @@
// //
// CodeWriter.h // CodeWriter.h
// //
// $Id: //poco/Main/PageCompiler/src/CodeWriter.h#1 $ // $Id: //poco/1.3/PageCompiler/src/CodeWriter.h#1 $
// //
// Copyright (c) 2008, Applied Informatics Software Engineering GmbH. // Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
@ -50,7 +50,7 @@ public:
CodeWriter(const Page& page, const std::string& clazz); CodeWriter(const Page& page, const std::string& clazz);
/// Creates the CodeWriter, using the given Page. /// Creates the CodeWriter, using the given Page.
~CodeWriter(); virtual ~CodeWriter();
/// Destroys the PageReader. /// Destroys the PageReader.
virtual void writeHeader(std::ostream& ostr, const std::string& headerFileName); virtual void writeHeader(std::ostream& ostr, const std::string& headerFileName);