cgilaz: added demo from Michael Van Canneyt

git-svn-id: trunk@13933 -
This commit is contained in:
mattias 2008-01-31 12:39:37 +00:00
parent cd21cbb318
commit 32b926d3f9
9 changed files with 246 additions and 18 deletions

5
.gitattributes vendored
View File

@ -8,6 +8,11 @@ components/cgi/README.txt svneol=native#text/plain
components/cgi/cgilaz.lpk svneol=native#text/pascal components/cgi/cgilaz.lpk svneol=native#text/pascal
components/cgi/cgilaz.pas svneol=native#text/plain components/cgi/cgilaz.pas svneol=native#text/plain
components/cgi/cgimodules.pas svneol=native#text/pascal components/cgi/cgimodules.pas svneol=native#text/pascal
components/cgi/demo/samplecgi.lpi svneol=native#text/plain
components/cgi/demo/samplecgi.lpr svneol=native#text/plain
components/cgi/demo/wmdump.lfm svneol=native#text/plain
components/cgi/demo/wmdump.lrs svneol=native#text/plain
components/cgi/demo/wmdump.pp svneol=native#text/plain
components/cgi/ide/Makefile svneol=native#text/plain components/cgi/ide/Makefile svneol=native#text/plain
components/cgi/ide/Makefile.fpc svneol=native#text/plain components/cgi/ide/Makefile.fpc svneol=native#text/plain
components/cgi/ide/README.txt svneol=native#text/plain components/cgi/ide/README.txt svneol=native#text/plain

View File

@ -4,8 +4,10 @@ With the cgimodules.pas unit you can easily create cgi applications with
datamodules. datamodules.
In the IDE sub directory you can find a design time package, which will install In the IDE sub directory you can find a design time package, which will install
some helpful IDE features like 'CGI Application' and 'CGI Module'. some helpful IDE features like 'Simple CGI Application' and 'Simple CGI Module'.
Note that this package is deprecated in favour of the more advanced lazweb
package: that package supports Apache modules and CGI applications with a
unified structure, using a similar but more elaborate approach.
For very simple CGI programs, cgimodules is still suitable, though.

View File

@ -0,0 +1,56 @@
<?xml version="1.0"?>
<CONFIG>
<ProjectOptions>
<PathDelim Value="/"/>
<Version Value="6"/>
<General>
<SessionStorage Value="InIDEConfig"/>
<MainUnit Value="0"/>
<IconPath Value="./"/>
<TargetFileExt Value=""/>
</General>
<VersionInfo>
<ProjectVersion Value=""/>
</VersionInfo>
<PublishOptions>
<Version Value="2"/>
<IgnoreBinaries Value="False"/>
<IncludeFileFilter Value="*.(pas|pp|inc|lfm|lpr|lrs|lpi|lpk|sh|xml)"/>
<ExcludeFileFilter Value="*.(bak|ppu|ppw|o|so);*~;backup"/>
</PublishOptions>
<RunParams>
<local>
<FormatVersion Value="1"/>
<LaunchingApplication PathPlusParams="/usr/X11R6/bin/xterm -T 'Lazarus Run Output' -e $(LazarusDir)/tools/runwait.sh $(TargetCmdLine)"/>
</local>
</RunParams>
<RequiredPackages Count="1">
<Item1>
<PackageName Value="CGILaz"/>
</Item1>
</RequiredPackages>
<Units Count="2">
<Unit0>
<Filename Value="samplecgi.lpr"/>
<IsPartOfProject Value="True"/>
<UnitName Value="samplecgi"/>
</Unit0>
<Unit1>
<Filename Value="wmdump.pp"/>
<ComponentName Value="DemoModule"/>
<IsPartOfProject Value="True"/>
<ResourceFilename Value="wmdump.lrs"/>
<UnitName Value="wmdump"/>
</Unit1>
</Units>
</ProjectOptions>
<CompilerOptions>
<Version Value="5"/>
<CodeGeneration>
<Generate Value="Faster"/>
</CodeGeneration>
<Other>
<CompilerPath Value="$(CompPath)"/>
</Other>
</CompilerOptions>
</CONFIG>

View File

@ -0,0 +1,15 @@
program samplecgi;
{$mode objfpc}{$H+}
uses
cgiModules, wmdump;
begin
Application:=TModuledCGIApplication.Create(nil);
Application.Initialize;
Application.CreateForm(TDemoModule, DemoModule);
Application.Run;
Application.Free;
end.

View File

@ -0,0 +1,10 @@
object DemoModule: TDemoModule
OnCGIRequest = DemoModuleCGIRequest
ContentType = 'text/html'
left = 433
top = 309
Height = 0
HorizontalOffset = 0
VerticalOffset = 0
Width = 0
end

View File

@ -0,0 +1,8 @@
{ This is an automatically generated lazarus resource file }
LazarusResources.Add('TDemoModule','FORMDATA',[
'TPF0'#11'TDemoModule'#10'DemoModule'#12'OnCGIRequest'#7#20'DemoModuleCGIRequ'
+'est'#11'ContentType'#6#9'text/html'#4'left'#3#177#1#3'top'#3'5'#1#6'Height'
+#2#0#16'HorizontalOffset'#2#0#14'VerticalOffset'#2#0#5'Width'#2#0#0#0
]);

View File

@ -0,0 +1,127 @@
unit wmdump;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, LResources, cgiModules;
type
{ TDemoModule }
TDemoModule = class(TCGIDatamodule)
procedure DemoModuleCGIRequest(Sender: TObject);
private
procedure EmitRequestVariables;
procedure EmitServerVariables;
{ private declarations }
public
{ public declarations }
procedure EmitVariable(Const VarName,VarValue : String);
end;
var
DemoModule: TDemoModule;
implementation
uses cgiapp;
{ TDemoModule }
{
The OnCGIRequest handler is called to handle the request
}
procedure TDemoModule.DemoModuleCGIRequest(Sender: TObject);
begin
// Emit content type (See ContentType property of the module)
EmitContentType;
// AddResponseLn sends one line of text to the web client.
AddResponseLn('<HTML>');
AddResponseLn('<TITLE>CGI Server environment</TITLE>');
AddResponseLn('<BODY>');
EmitServerVariables;
AddResponseLn('<HR/>');
EmitRequestVariables;
end;
procedure TDemoModule.EmitServerVariables;
begin
AddResponseLn('<H1>CGI Server environment:</H1>');
AddResponseLn('<TABLE>');
AddResponseLn('<TR><TH>Variable</TH><TH>Value</TH></TR>');
// Server environment is accessible as properties of the Application class.
// The same list can be retrieved as a name=value stringlist with the
// GetCGIVarList call.
EmitVariable('AuthType',Application.AuthType);
EmitVariable('ContentLength',IntToStr(Application.ContentLength));
EmitVariable('ContentType',Application.ContentType);
EmitVariable('GatewayInterface',Application.GatewayInterface);
EmitVariable('PathInfo',Application.PathInfo);
EmitVariable('PathTranslated',Application.PathTranslated);
EmitVariable('QueryString',Application.QueryString);
EmitVariable('RemoteAddress',Application.RemoteAddress);
EmitVariable('RemoteHost',Application.RemoteHost);
EmitVariable('RemoteIdent',Application.RemoteIdent);
EmitVariable('RemoteUser',Application.RemoteUser);
EmitVariable('RequestMethod',Application.RequestMethod);
EmitVariable('ScriptName',Application.ScriptName);
EmitVariable('ServerName',Application.ServerName);
EmitVariable('ServerPort',IntToStr(Application.ServerPort));
EmitVariable('ServerProtocol',Application.ServerProtocol);
EmitVariable('ServerSoftware',Application.ServerSoftware);
EmitVariable('HTTPAccept',Application.HTTPAccept);
EmitVariable('HTTPAcceptCharset',Application.HTTPAcceptCharset);
EmitVariable('HTTPAcceptEncoding',Application.HTTPAcceptEncoding);
EmitVariable('HTTPIfModifiedSince',Application.HTTPIfModifiedSince);
EmitVariable('HTTPReferer',Application.HTTPReferer);
EmitVariable('HTTPUserAgent',Application.HTTPUserAgent);
EmitVariable('Email',Application.Email);
EmitVariable('Administrator',Application.Administrator);
// EmitVariable('',Application.);
end;
procedure TDemoModule.EmitRequestVariables;
Var
L : TStringList;
I : Integer;
N,V : String;
begin
AddResponseLn('</TABLE>');
AddResponseLn('<H1>Query variables:</H1>');
AddResponseLn('<TR><TH>Variable</TH><TH>Value</TH></TR>');
L:=TStringList.Create;
try
// Retrieve parsed list of variables as name=value pairs
Application.GetRequestVarList(L,False);
For I:=0 to L.Count-1 do
begin
L.GetNameValue(I,N,V);
EmitVariable(N,V);
end;
// Alternatively,
// Application.RequestVariables[Varname : string] gives named acces to the variables
// Application.RequestvariableCount returns the number of variables.
finally
L.Free;
end;
AddResponseLn('</TABLE>');
end;
procedure TDemoModule.EmitVariable(const VarName, VarValue: String);
begin
AddResponseLn(Format('<TR><TD>%s</TD><TD>%s</TD></TR>',[VarName,VarValue]));
end;
initialization
{$I wmdump.lrs}
end.

View File

@ -34,8 +34,8 @@ unit CGILazIDEIntf;
interface interface
uses uses
Classes, SysUtils, cgiApp, cgiModules, LazIDEIntf, ProjectIntf, Classes, SysUtils, cgiApp, Controls, Forms, cgiModules,
Controls, Forms; LazIDEIntf, ProjectIntf, FormEditingIntf;
type type
{ TCGIApplicationDescriptor } { TCGIApplicationDescriptor }
@ -73,6 +73,7 @@ begin
RegisterProjectFileDescriptor(FileDescriptorCGIModule); RegisterProjectFileDescriptor(FileDescriptorCGIModule);
ProjectDescriptorCGIApplication:=TCGIApplicationDescriptor.Create; ProjectDescriptorCGIApplication:=TCGIApplicationDescriptor.Create;
RegisterProjectDescriptor(ProjectDescriptorCGIApplication); RegisterProjectDescriptor(ProjectDescriptorCGIApplication);
FormEditingHook.RegisterDesignerBaseClass(TCGIDataModule);
end; end;
{ TCGIApplicationDescriptor } { TCGIApplicationDescriptor }
@ -80,19 +81,21 @@ end;
constructor TCGIApplicationDescriptor.Create; constructor TCGIApplicationDescriptor.Create;
begin begin
inherited Create; inherited Create;
Name:='CGIApplication'; Name:='Simple CGIApplication';
end; end;
function TCGIApplicationDescriptor.GetLocalizedName: string; function TCGIApplicationDescriptor.GetLocalizedName: string;
begin begin
Result:='CGi Application'; Result:='Simple CGI Application';
end; end;
function TCGIApplicationDescriptor.GetLocalizedDescription: string; function TCGIApplicationDescriptor.GetLocalizedDescription: string;
begin begin
Result:='CGi Application'#13#13'A CGI (Common Gateway Interface) program ' Result:='Simple CGI Application'#13#10
+'in Free Pascal. The program file is ' +'A CGI (Common Gateway Interface) program in Free Pascal.'#13#10
+'automatically maintained by Lazarus.'; +'The program file is automatically maintained by Lazarus.'#13#10
+'This kind of application is deprecated, for CGI programs or Apache modules, '
+'please use the LazWeb package instead';
end; end;
function TCGIApplicationDescriptor.InitProject(AProject: TLazProject): TModalResult; function TCGIApplicationDescriptor.InitProject(AProject: TLazProject): TModalResult;
@ -148,7 +151,7 @@ end;
constructor TFileDescPascalUnitWithCGIDataModule.Create; constructor TFileDescPascalUnitWithCGIDataModule.Create;
begin begin
inherited Create; inherited Create;
Name:='CGIModule'; Name:='SimpleCGIModule';
ResourceClass:=TCGIDataModule; ResourceClass:=TCGIDataModule;
UseCreateFormStatements:=true; UseCreateFormStatements:=true;
end; end;
@ -161,13 +164,15 @@ end;
function TFileDescPascalUnitWithCGIDataModule.GetLocalizedName: string; function TFileDescPascalUnitWithCGIDataModule.GetLocalizedName: string;
begin begin
Result:='CGI Module'; Result:='Simple CGI Module';
end; end;
function TFileDescPascalUnitWithCGIDataModule.GetLocalizedDescription: string; function TFileDescPascalUnitWithCGIDataModule.GetLocalizedDescription: string;
begin begin
Result:='CGi Module'#13 Result:='Simple CGI Module'#13#10
+'A datamodule for CGI applications.'; +'A datamodule for CGI applications.'
+'This module is deprecated, please use the CGI module support '
+'of the lazweb package instead';
end; end;
end. end.

View File

@ -4,11 +4,11 @@ msgstr ""
"Content-Type: text/plain; charset=UTF-8\n" "Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n" "Content-Transfer-Encoding: 8bit\n"
#: cgimodules:serrnomainmodule
msgid "No CGI datamodule to handle CGI request."
msgstr ""
#: cgimodules:serrnorequesthandler #: cgimodules:serrnorequesthandler
msgid "%s: No CGI request handler set." msgid "%s: No CGI request handler set."
msgstr "" msgstr ""
#: cgimodules:serrnomainmodule
msgid "No CGI datamodule to handle CGI request."
msgstr ""