mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-18 07:19:22 +02:00
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:
parent
0c01642a75
commit
ae6e3689e1
@ -19,6 +19,10 @@
|
|||||||
{$H+}
|
{$H+}
|
||||||
unit WebLazIDEIntf;
|
unit WebLazIDEIntf;
|
||||||
|
|
||||||
|
{$IFNDEF VER2_0}{$IFNDEF VER2_2}
|
||||||
|
{$DEFINE HasFastCGISupport}
|
||||||
|
{$ENDIF VER2_0}{$ENDIF VER2_2}
|
||||||
|
|
||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
@ -36,7 +40,7 @@ type
|
|||||||
function InitProject(AProject: TLazProject): TModalResult; override;
|
function InitProject(AProject: TLazProject): TModalResult; override;
|
||||||
function CreateStartFiles(AProject: TLazProject): TModalResult; override;
|
function CreateStartFiles(AProject: TLazProject): TModalResult; override;
|
||||||
end;
|
end;
|
||||||
{ TCGIApplicationDescriptor }
|
{ TApacheApplicationDescriptor }
|
||||||
|
|
||||||
TApacheApplicationDescriptor = class(TProjectDescriptor)
|
TApacheApplicationDescriptor = class(TProjectDescriptor)
|
||||||
public
|
public
|
||||||
@ -47,6 +51,7 @@ type
|
|||||||
function CreateStartFiles(AProject: TLazProject): TModalResult; override;
|
function CreateStartFiles(AProject: TLazProject): TModalResult; override;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{ TCustomCGIApplicationDescriptor }
|
||||||
TCustomCGIApplicationDescriptor = class(TProjectDescriptor)
|
TCustomCGIApplicationDescriptor = class(TProjectDescriptor)
|
||||||
public
|
public
|
||||||
constructor Create; override;
|
constructor Create; override;
|
||||||
@ -56,6 +61,29 @@ type
|
|||||||
function CreateStartFiles(AProject: TLazProject): TModalResult; override;
|
function CreateStartFiles(AProject: TLazProject): TModalResult; override;
|
||||||
end;
|
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 }
|
{ TFileDescPascalUnitWithCGIDataModule }
|
||||||
|
|
||||||
TFileDescWebDataModule = class(TFileDescPascalUnitWithResource)
|
TFileDescWebDataModule = class(TFileDescPascalUnitWithResource)
|
||||||
@ -80,6 +108,10 @@ var
|
|||||||
ProjectDescriptorCustomCGIApplication: TCustomCGIApplicationDescriptor;
|
ProjectDescriptorCustomCGIApplication: TCustomCGIApplicationDescriptor;
|
||||||
ProjectDescriptorCGIApplication: TCGIApplicationDescriptor;
|
ProjectDescriptorCGIApplication: TCGIApplicationDescriptor;
|
||||||
ProjectDescriptorApacheApplication: TApacheApplicationDescriptor;
|
ProjectDescriptorApacheApplication: TApacheApplicationDescriptor;
|
||||||
|
{$IFDEF HasFastCGISupport}
|
||||||
|
ProjectDescriptorCustomFCGIApplication: TCustomFCGIApplicationDescriptor;
|
||||||
|
ProjectDescriptorFCGIApplication: TFCGIApplicationDescriptor;
|
||||||
|
{$ENDIF HasFastCGISupport}
|
||||||
FileDescriptorHTMLModule: TFileDescHTMLModule;
|
FileDescriptorHTMLModule: TFileDescHTMLModule;
|
||||||
FileDescriptorWebModule: TFileDescWebDataModule;
|
FileDescriptorWebModule: TFileDescWebDataModule;
|
||||||
|
|
||||||
@ -96,8 +128,9 @@ Procedure RegisterHTMLComponents;
|
|||||||
begin
|
begin
|
||||||
RegisterComponents(fpWebTab,[THTMLDatasetContentProducer,
|
RegisterComponents(fpWebTab,[THTMLDatasetContentProducer,
|
||||||
THTMLSelectProducer,
|
THTMLSelectProducer,
|
||||||
THTMLDatasetSelectProducer
|
THTMLDatasetSelectProducer,
|
||||||
{$IFNDEF VER2_0}{$IFNDEF VER2_2_0},THTMLEntityProducer{$ENDIF}{$ENDIF}
|
THTMLEntityProducer
|
||||||
|
{$IFNDEF VER2_0}{$IFNDEF VER2_2},THTMLPageProducer{$ENDIF}{$ENDIF}
|
||||||
])
|
])
|
||||||
|
|
||||||
end;
|
end;
|
||||||
@ -131,6 +164,12 @@ begin
|
|||||||
RegisterProjectDescriptor(ProjectDescriptorCustomCGIApplication);
|
RegisterProjectDescriptor(ProjectDescriptorCustomCGIApplication);
|
||||||
ProjectDescriptorApacheApplication:=TApacheApplicationDescriptor.Create;
|
ProjectDescriptorApacheApplication:=TApacheApplicationDescriptor.Create;
|
||||||
RegisterProjectDescriptor(ProjectDescriptorApacheApplication);
|
RegisterProjectDescriptor(ProjectDescriptorApacheApplication);
|
||||||
|
{$IFDEF HasFastCGISupport}
|
||||||
|
ProjectDescriptorFCGIApplication:=TFCGIApplicationDescriptor.Create;
|
||||||
|
RegisterProjectDescriptor(ProjectDescriptorFCGIApplication);
|
||||||
|
ProjectDescriptorCustomFCGIApplication:=TCustomFCGIApplicationDescriptor.Create;
|
||||||
|
RegisterProjectDescriptor(ProjectDescriptorCustomFCGIApplication);
|
||||||
|
{$ENDIF HasFastCGISupport}
|
||||||
FormEditingHook.RegisterDesignerBaseClass(TFPWebModule);
|
FormEditingHook.RegisterDesignerBaseClass(TFPWebModule);
|
||||||
FormEditingHook.RegisterDesignerBaseClass(TFPHTMLModule);
|
FormEditingHook.RegisterDesignerBaseClass(TFPHTMLModule);
|
||||||
end;
|
end;
|
||||||
@ -151,7 +190,7 @@ end;
|
|||||||
function TCGIApplicationDescriptor.GetLocalizedDescription: string;
|
function TCGIApplicationDescriptor.GetLocalizedDescription: string;
|
||||||
begin
|
begin
|
||||||
Result:='CGI Application'#13#13'A CGI (Common Gateway Interface) program '
|
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.';
|
+'automatically maintained by Lazarus.';
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -186,10 +225,13 @@ begin
|
|||||||
AProject.MainFile.SetSourceText(NewSource);
|
AProject.MainFile.SetSourceText(NewSource);
|
||||||
|
|
||||||
// add
|
// add
|
||||||
|
AProject.AddPackageDependency('FCL');
|
||||||
AProject.AddPackageDependency('WebLaz');
|
AProject.AddPackageDependency('WebLaz');
|
||||||
|
|
||||||
// compiler options
|
// compiler options
|
||||||
AProject.LazCompilerOptions.Win32GraphicApp:=false;
|
AProject.LazCompilerOptions.Win32GraphicApp:=false;
|
||||||
|
AProject.Flags := AProject.Flags - [pfMainUnitHasCreateFormStatements];
|
||||||
|
AProject.Flags := AProject.Flags - [pfRunnable];
|
||||||
Result:= mrOK;
|
Result:= mrOK;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -270,6 +312,8 @@ begin
|
|||||||
AProject.AddPackageDependency('WebLaz');
|
AProject.AddPackageDependency('WebLaz');
|
||||||
// compiler options
|
// compiler options
|
||||||
AProject.LazCompilerOptions.Win32GraphicApp:=false;
|
AProject.LazCompilerOptions.Win32GraphicApp:=false;
|
||||||
|
AProject.Flags := AProject.Flags - [pfMainUnitHasCreateFormStatements];
|
||||||
|
AProject.Flags := AProject.Flags - [pfRunnable];
|
||||||
Result:= mrOK;
|
Result:= mrOK;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -362,7 +406,7 @@ end;
|
|||||||
function TApacheApplicationDescriptor.GetLocalizedDescription: string;
|
function TApacheApplicationDescriptor.GetLocalizedDescription: string;
|
||||||
begin
|
begin
|
||||||
Result:='Apache module'#13#13'An Apache loadable module '
|
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.';
|
+'automatically maintained by Lazarus.';
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -424,6 +468,9 @@ begin
|
|||||||
|
|
||||||
// compiler options
|
// compiler options
|
||||||
AProject.LazCompilerOptions.Win32GraphicApp:=false;
|
AProject.LazCompilerOptions.Win32GraphicApp:=false;
|
||||||
|
AProject.ExecutableType:=petLibrary;
|
||||||
|
AProject.Flags := AProject.Flags - [pfMainUnitHasCreateFormStatements];
|
||||||
|
AProject.Flags := AProject.Flags - [pfRunnable];
|
||||||
Result:= mrOK;
|
Result:= mrOK;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -434,6 +481,160 @@ begin
|
|||||||
Result:= mrOK;
|
Result:= mrOK;
|
||||||
end;
|
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.
|
end.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user