mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-22 11:19:26 +02:00
cgilaz: added demo from Michael Van Canneyt
git-svn-id: trunk@13933 -
This commit is contained in:
parent
cd21cbb318
commit
32b926d3f9
5
.gitattributes
vendored
5
.gitattributes
vendored
@ -8,6 +8,11 @@ components/cgi/README.txt svneol=native#text/plain
|
||||
components/cgi/cgilaz.lpk svneol=native#text/pascal
|
||||
components/cgi/cgilaz.pas svneol=native#text/plain
|
||||
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.fpc svneol=native#text/plain
|
||||
components/cgi/ide/README.txt svneol=native#text/plain
|
||||
|
@ -4,8 +4,10 @@ With the cgimodules.pas unit you can easily create cgi applications with
|
||||
datamodules.
|
||||
|
||||
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.
|
||||
|
56
components/cgi/demo/samplecgi.lpi
Normal file
56
components/cgi/demo/samplecgi.lpi
Normal 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>
|
15
components/cgi/demo/samplecgi.lpr
Normal file
15
components/cgi/demo/samplecgi.lpr
Normal 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.
|
||||
|
10
components/cgi/demo/wmdump.lfm
Normal file
10
components/cgi/demo/wmdump.lfm
Normal 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
|
8
components/cgi/demo/wmdump.lrs
Normal file
8
components/cgi/demo/wmdump.lrs
Normal 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
|
||||
]);
|
127
components/cgi/demo/wmdump.pp
Normal file
127
components/cgi/demo/wmdump.pp
Normal 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.
|
||||
|
@ -34,8 +34,8 @@ unit CGILazIDEIntf;
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, cgiApp, cgiModules, LazIDEIntf, ProjectIntf,
|
||||
Controls, Forms;
|
||||
Classes, SysUtils, cgiApp, Controls, Forms, cgiModules,
|
||||
LazIDEIntf, ProjectIntf, FormEditingIntf;
|
||||
|
||||
type
|
||||
{ TCGIApplicationDescriptor }
|
||||
@ -73,6 +73,7 @@ begin
|
||||
RegisterProjectFileDescriptor(FileDescriptorCGIModule);
|
||||
ProjectDescriptorCGIApplication:=TCGIApplicationDescriptor.Create;
|
||||
RegisterProjectDescriptor(ProjectDescriptorCGIApplication);
|
||||
FormEditingHook.RegisterDesignerBaseClass(TCGIDataModule);
|
||||
end;
|
||||
|
||||
{ TCGIApplicationDescriptor }
|
||||
@ -80,19 +81,21 @@ end;
|
||||
constructor TCGIApplicationDescriptor.Create;
|
||||
begin
|
||||
inherited Create;
|
||||
Name:='CGIApplication';
|
||||
Name:='Simple CGIApplication';
|
||||
end;
|
||||
|
||||
function TCGIApplicationDescriptor.GetLocalizedName: string;
|
||||
begin
|
||||
Result:='CGi Application';
|
||||
Result:='Simple CGI Application';
|
||||
end;
|
||||
|
||||
function TCGIApplicationDescriptor.GetLocalizedDescription: string;
|
||||
begin
|
||||
Result:='CGi Application'#13#13'A CGI (Common Gateway Interface) program '
|
||||
+'in Free Pascal. The program file is '
|
||||
+'automatically maintained by Lazarus.';
|
||||
Result:='Simple CGI Application'#13#10
|
||||
+'A CGI (Common Gateway Interface) program in Free Pascal.'#13#10
|
||||
+'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;
|
||||
|
||||
function TCGIApplicationDescriptor.InitProject(AProject: TLazProject): TModalResult;
|
||||
@ -148,7 +151,7 @@ end;
|
||||
constructor TFileDescPascalUnitWithCGIDataModule.Create;
|
||||
begin
|
||||
inherited Create;
|
||||
Name:='CGIModule';
|
||||
Name:='SimpleCGIModule';
|
||||
ResourceClass:=TCGIDataModule;
|
||||
UseCreateFormStatements:=true;
|
||||
end;
|
||||
@ -161,13 +164,15 @@ end;
|
||||
|
||||
function TFileDescPascalUnitWithCGIDataModule.GetLocalizedName: string;
|
||||
begin
|
||||
Result:='CGI Module';
|
||||
Result:='Simple CGI Module';
|
||||
end;
|
||||
|
||||
function TFileDescPascalUnitWithCGIDataModule.GetLocalizedDescription: string;
|
||||
begin
|
||||
Result:='CGi Module'#13
|
||||
+'A datamodule for CGI applications.';
|
||||
Result:='Simple CGI Module'#13#10
|
||||
+'A datamodule for CGI applications.'
|
||||
+'This module is deprecated, please use the CGI module support '
|
||||
+'of the lazweb package instead';
|
||||
end;
|
||||
|
||||
end.
|
||||
|
@ -4,11 +4,11 @@ msgstr ""
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
|
||||
#: cgimodules:serrnomainmodule
|
||||
msgid "No CGI datamodule to handle CGI request."
|
||||
msgstr ""
|
||||
|
||||
#: cgimodules:serrnorequesthandler
|
||||
msgid "%s: No CGI request handler set."
|
||||
msgstr ""
|
||||
|
||||
#: cgimodules:serrnomainmodule
|
||||
msgid "No CGI datamodule to handle CGI request."
|
||||
msgstr ""
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user