components: fpweb: add support for FastCGI from fpc 2.3.1 (issue #13421)

* Support for FastCGI applications
* Mentioned difference between custom and normal web-applications (handling webmodules)
* Register THtmlPageProducer
* Set executabletype to petLibrary for Apache-modules
* Removed runnable flag from Webapplications that can't be run from inside the Lazarus IDE
* Removed CreateFormStatements flag from webapplication which don't need those 
patch by Joost van der Sluis

git-svn-id: trunk@19548 -
This commit is contained in:
vincents 2009-04-21 10:57:58 +00:00
parent 0c01642a75
commit ae6e3689e1

View File

@ -19,6 +19,10 @@
{$H+}
unit WebLazIDEIntf;
{$IFNDEF VER2_0}{$IFNDEF VER2_2}
{$DEFINE HasFastCGISupport}
{$ENDIF VER2_0}{$ENDIF VER2_2}
interface
uses
@ -36,7 +40,7 @@ type
function InitProject(AProject: TLazProject): TModalResult; override;
function CreateStartFiles(AProject: TLazProject): TModalResult; override;
end;
{ TCGIApplicationDescriptor }
{ TApacheApplicationDescriptor }
TApacheApplicationDescriptor = class(TProjectDescriptor)
public
@ -47,6 +51,7 @@ type
function CreateStartFiles(AProject: TLazProject): TModalResult; override;
end;
{ TCustomCGIApplicationDescriptor }
TCustomCGIApplicationDescriptor = class(TProjectDescriptor)
public
constructor Create; override;
@ -56,6 +61,29 @@ type
function CreateStartFiles(AProject: TLazProject): TModalResult; override;
end;
{$IFDEF HasFastCGISupport}
{ TCustomFCGIApplicationDescriptor }
TCustomFCGIApplicationDescriptor = class(TProjectDescriptor)
public
constructor Create; override;
function GetLocalizedName: string; override;
function GetLocalizedDescription: string; override;
function InitProject(AProject: TLazProject): TModalResult; override;
function CreateStartFiles(AProject: TLazProject): TModalResult; override;
end;
{ TFCGIApplicationDescriptor }
TFCGIApplicationDescriptor = class(TProjectDescriptor)
public
constructor Create; override;
function GetLocalizedName: string; override;
function GetLocalizedDescription: string; override;
function InitProject(AProject: TLazProject): TModalResult; override;
function CreateStartFiles(AProject: TLazProject): TModalResult; override;
end;
{$ENDIF HasFastCGISupport}
{ TFileDescPascalUnitWithCGIDataModule }
TFileDescWebDataModule = class(TFileDescPascalUnitWithResource)
@ -80,6 +108,10 @@ var
ProjectDescriptorCustomCGIApplication: TCustomCGIApplicationDescriptor;
ProjectDescriptorCGIApplication: TCGIApplicationDescriptor;
ProjectDescriptorApacheApplication: TApacheApplicationDescriptor;
{$IFDEF HasFastCGISupport}
ProjectDescriptorCustomFCGIApplication: TCustomFCGIApplicationDescriptor;
ProjectDescriptorFCGIApplication: TFCGIApplicationDescriptor;
{$ENDIF HasFastCGISupport}
FileDescriptorHTMLModule: TFileDescHTMLModule;
FileDescriptorWebModule: TFileDescWebDataModule;
@ -96,8 +128,9 @@ Procedure RegisterHTMLComponents;
begin
RegisterComponents(fpWebTab,[THTMLDatasetContentProducer,
THTMLSelectProducer,
THTMLDatasetSelectProducer
{$IFNDEF VER2_0}{$IFNDEF VER2_2_0},THTMLEntityProducer{$ENDIF}{$ENDIF}
THTMLDatasetSelectProducer,
THTMLEntityProducer
{$IFNDEF VER2_0}{$IFNDEF VER2_2},THTMLPageProducer{$ENDIF}{$ENDIF}
])
end;
@ -131,6 +164,12 @@ begin
RegisterProjectDescriptor(ProjectDescriptorCustomCGIApplication);
ProjectDescriptorApacheApplication:=TApacheApplicationDescriptor.Create;
RegisterProjectDescriptor(ProjectDescriptorApacheApplication);
{$IFDEF HasFastCGISupport}
ProjectDescriptorFCGIApplication:=TFCGIApplicationDescriptor.Create;
RegisterProjectDescriptor(ProjectDescriptorFCGIApplication);
ProjectDescriptorCustomFCGIApplication:=TCustomFCGIApplicationDescriptor.Create;
RegisterProjectDescriptor(ProjectDescriptorCustomFCGIApplication);
{$ENDIF HasFastCGISupport}
FormEditingHook.RegisterDesignerBaseClass(TFPWebModule);
FormEditingHook.RegisterDesignerBaseClass(TFPHTMLModule);
end;
@ -151,7 +190,7 @@ end;
function TCGIApplicationDescriptor.GetLocalizedDescription: string;
begin
Result:='CGI Application'#13#13'A CGI (Common Gateway Interface) program '
+'in Free Pascal. The program file is '
+'in Free Pascal using webmodules. The program file is '
+'automatically maintained by Lazarus.';
end;
@ -186,10 +225,13 @@ begin
AProject.MainFile.SetSourceText(NewSource);
// add
AProject.AddPackageDependency('FCL');
AProject.AddPackageDependency('WebLaz');
// compiler options
AProject.LazCompilerOptions.Win32GraphicApp:=false;
AProject.Flags := AProject.Flags - [pfMainUnitHasCreateFormStatements];
AProject.Flags := AProject.Flags - [pfRunnable];
Result:= mrOK;
end;
@ -270,6 +312,8 @@ begin
AProject.AddPackageDependency('WebLaz');
// compiler options
AProject.LazCompilerOptions.Win32GraphicApp:=false;
AProject.Flags := AProject.Flags - [pfMainUnitHasCreateFormStatements];
AProject.Flags := AProject.Flags - [pfRunnable];
Result:= mrOK;
end;
@ -362,7 +406,7 @@ end;
function TApacheApplicationDescriptor.GetLocalizedDescription: string;
begin
Result:='Apache module'#13#13'An Apache loadable module '
+'in Free Pascal. The main library file is '
+'in Free Pascal using webmodules. The main library file is '
+'automatically maintained by Lazarus.';
end;
@ -424,6 +468,9 @@ begin
// compiler options
AProject.LazCompilerOptions.Win32GraphicApp:=false;
AProject.ExecutableType:=petLibrary;
AProject.Flags := AProject.Flags - [pfMainUnitHasCreateFormStatements];
AProject.Flags := AProject.Flags - [pfRunnable];
Result:= mrOK;
end;
@ -434,6 +481,160 @@ begin
Result:= mrOK;
end;
{$IFDEF HasFastCGISupport}
{ TCustomFCGIApplicationDescriptor }
constructor TCustomFCGIApplicationDescriptor.Create;
begin
inherited Create;
Name:='Custom FastCGI Application';
end;
function TCustomFCGIApplicationDescriptor.GetLocalizedName: string;
begin
Result:='Custom FastCGI Application';
end;
function TCustomFCGIApplicationDescriptor.GetLocalizedDescription: string;
begin
Result:='Custom FastCGI Application'#13#13'A FastCGI (Common Gateway Interface) program '
+'in Free Pascal. The program file is '
+'automatically maintained by Lazarus.';
end;
function TCustomFCGIApplicationDescriptor.InitProject(AProject: TLazProject
): TModalResult;
var
le: string;
NewSource: String;
MainFile: TLazProjectFile;
begin
inherited InitProject(AProject);
MainFile:=AProject.CreateProjectFile('fcgiproject1.lpr');
MainFile.IsPartOfProject:=true;
AProject.AddFile(MainFile,false);
AProject.MainFileID:=0;
// create program source
le:=LineEnding;
NewSource:='program fcgiproject1;'+le
+le
+'{$mode objfpc}{$H+}'+le
+le
+'uses'+le
+' Classes,SysUtils,httpDefs,custfcgi;'+le
+le
+'Type'+le
+' TFCGIApp = Class(TCustomFCGIApplication)'+le
+' Public'+le
+' Procedure HandleRequest(ARequest : Trequest; AResponse : TResponse); override;'+le
+' end;'+le
+le
+'Procedure TFCGIApp.HandleRequest(ARequest : Trequest; AResponse : TResponse);'+le
+le
+'begin'+le
+' // Your code here'+le
+'end;'+le
+le
+'begin'+le
+' With TFCGIApp.Create(Nil) do'+le
+' try'+le
+' Initialize;'+le
+' Run;'+le
+' finally'+le
+' Free;'+le
+' end;'+le
+'end.'+le;
AProject.MainFile.SetSourceText(NewSource);
// add
AProject.AddPackageDependency('FCL');
AProject.AddPackageDependency('WebLaz');
// compiler options
AProject.LazCompilerOptions.Win32GraphicApp:=false;
AProject.Flags := AProject.Flags - [pfMainUnitHasCreateFormStatements];
AProject.Flags := AProject.Flags - [pfRunnable];
Result:= mrOK;
end;
function TCustomFCGIApplicationDescriptor.CreateStartFiles(AProject: TLazProject
): TModalResult;
begin
Result:= mrOK;
end;
{ TFCGIApplicationDescriptor }
constructor TFCGIApplicationDescriptor.Create;
begin
inherited Create;
Name:='FastCGI Application';
end;
function TFCGIApplicationDescriptor.GetLocalizedName: string;
begin
Result:='FastCGI Application';
end;
function TFCGIApplicationDescriptor.GetLocalizedDescription: string;
begin
Result:='FastCGI Application'#13#13'A FastCGI (Common Gateway Interface) program '
+'in Free Pascal using webmodules. The program file is '
+'automatically maintained by Lazarus.';
end;
function TFCGIApplicationDescriptor.InitProject(AProject: TLazProject
): TModalResult;
var
le: string;
NewSource: String;
MainFile: TLazProjectFile;
begin
inherited InitProject(AProject);
MainFile:=AProject.CreateProjectFile('fcgiproject1.lpr');
MainFile.IsPartOfProject:=true;
AProject.AddFile(MainFile,false);
AProject.MainFileID:=0;
// create program source
le:=LineEnding;
NewSource:='program fcgiproject1;'+le
+le
+'{$mode objfpc}{$H+}'+le
+le
+'uses'+le
+' fpWeb,fpFCGI;'+le
+le
+'begin'+le
+' Application.Title:=''fcgiproject1'';'+le
+' Application.Initialize;'+le
+' Application.Run;'+le
+'end.'+le
+le;
AProject.MainFile.SetSourceText(NewSource);
// add
AProject.AddPackageDependency('FCL');
AProject.AddPackageDependency('WebLaz');
// compiler options
AProject.LazCompilerOptions.Win32GraphicApp:=false;
AProject.Flags := AProject.Flags - [pfMainUnitHasCreateFormStatements];
AProject.Flags := AProject.Flags - [pfRunnable];
Result:= mrOK;
end;
function TFCGIApplicationDescriptor.CreateStartFiles(AProject: TLazProject
): TModalResult;
begin
LazarusIDE.DoNewEditorFile(FileDescriptorWebModule,'','',
[nfIsPartOfProject,nfOpenInEditor,nfCreateDefaultSrc]);
Result:= mrOK;
end;
{$ENDIF HasFastCGISupport}
end.