|
@@ -22,29 +22,29 @@ uses
|
|
|
|
|
|
Type
|
|
|
|
|
|
- TCustomApacheApplication = Class;
|
|
|
+ TApacheHandler = Class;
|
|
|
|
|
|
{ TApacheRequest }
|
|
|
|
|
|
TApacheRequest = Class(TRequest)
|
|
|
Private
|
|
|
- FApache : TCustomApacheApplication;
|
|
|
+ FApache : TApacheHandler;
|
|
|
FRequest : PRequest_rec;
|
|
|
Protected
|
|
|
Function GetFieldValue(Index : Integer) : String; override;
|
|
|
Procedure InitFromRequest;
|
|
|
procedure ReadContent; override;
|
|
|
Public
|
|
|
- Constructor CreateReq(App : TCustomApacheApplication; ARequest : PRequest_rec);
|
|
|
+ Constructor CreateReq(App : TApacheHandler; ARequest : PRequest_rec);
|
|
|
Property ApacheRequest : Prequest_rec Read FRequest;
|
|
|
- Property ApacheApp : TCustomApacheApplication Read FApache;
|
|
|
+ Property ApacheApp : TApacheHandler Read FApache;
|
|
|
end;
|
|
|
|
|
|
{ TApacheResponse }
|
|
|
|
|
|
TApacheResponse = Class(TResponse)
|
|
|
private
|
|
|
- FApache : TCustomApacheApplication;
|
|
|
+ FApache : TApacheHandler;
|
|
|
FRequest : PRequest_rec;
|
|
|
procedure SendStream(S: TStream);
|
|
|
Protected
|
|
@@ -53,7 +53,7 @@ Type
|
|
|
Public
|
|
|
Constructor CreateApache(Req : TApacheRequest);
|
|
|
Property ApacheRequest : Prequest_rec Read FRequest;
|
|
|
- Property ApacheApp : TCustomApacheApplication Read FApache;
|
|
|
+ Property ApacheApp : TApacheHandler Read FApache;
|
|
|
end;
|
|
|
|
|
|
{ TCustomApacheApplication }
|
|
@@ -61,7 +61,7 @@ Type
|
|
|
TBeforeRequestEvent = Procedure(Sender : TObject; Const AHandler : String;
|
|
|
Var AllowRequest : Boolean) of object;
|
|
|
|
|
|
- TCustomApacheApplication = Class(TCustomWebApplication)
|
|
|
+ TApacheHandler = Class(TWebHandler)
|
|
|
private
|
|
|
FMaxRequests: Integer; //Maximum number of simultaneous web module requests (default=64, if set to zero no limit)
|
|
|
FWorkingWebModules: TList; //List of currently running web modules handling requests
|
|
@@ -80,16 +80,15 @@ Type
|
|
|
function GetWorkingModuleCount : Integer;
|
|
|
Protected
|
|
|
Function ProcessRequest(P : PRequest_Rec) : Integer; virtual;
|
|
|
- Procedure DoRun; override;
|
|
|
function WaitForRequest(out ARequest : TRequest; out AResponse : TResponse) : boolean; override;
|
|
|
Function AllowRequest(P : PRequest_Rec) : Boolean; virtual;
|
|
|
function GetApplicationURL(ARequest : TRequest): String; override;
|
|
|
Public
|
|
|
Constructor Create(AOwner : TComponent); override;
|
|
|
Destructor Destroy; override;
|
|
|
+ Procedure Run; override;
|
|
|
Procedure SetModuleRecord(Var ModuleRecord : Module);
|
|
|
- Procedure Initialize; override;
|
|
|
- Procedure ShowException(E : Exception); override;
|
|
|
+ Procedure Initialize;
|
|
|
Procedure LogErrorMessage(Msg : String; LogLevel : integer = APLOG_INFO); virtual;
|
|
|
Procedure handleRequest(ARequest : TRequest; AResponse : TResponse); override;
|
|
|
Property HandlerPriority : THandlerPriority Read FPriority Write FPriority default hpMiddle;
|
|
@@ -104,6 +103,43 @@ Type
|
|
|
Property WorkingWebModuleCount: Integer read GetWorkingModuleCount;
|
|
|
end;
|
|
|
|
|
|
+ TCustomApacheApplication = Class(TCustomWebApplication)
|
|
|
+ private
|
|
|
+ function GetAfterModules: TStrings;
|
|
|
+ function GetBaseLocation: String;
|
|
|
+ function GetBeforeModules: TStrings;
|
|
|
+ function GetBeforeRequest: TBeforeRequestEvent;
|
|
|
+ function GetHandlerName: String;
|
|
|
+ function GetIdleModuleCount: Integer;
|
|
|
+ function GetMaxRequests: Integer;
|
|
|
+ function GetModuleName: String;
|
|
|
+ function GetPriority: THandlerPriority;
|
|
|
+ function GetWorkingModuleCount: Integer;
|
|
|
+ procedure SetAfterModules(const AValue: TStrings);
|
|
|
+ procedure SetBaseLocation(const AValue: String);
|
|
|
+ procedure SetBeforeModules(const AValue: TStrings);
|
|
|
+ procedure SetBeforeRequest(const AValue: TBeforeRequestEvent);
|
|
|
+ procedure SetHandlerName(const AValue: String);
|
|
|
+ procedure SetMaxRequests(const AValue: Integer);
|
|
|
+ procedure SetModuleName(const AValue: String);
|
|
|
+ procedure SetPriority(const AValue: THandlerPriority);
|
|
|
+ public
|
|
|
+ function InitializeWebHandler: TWebHandler; override;
|
|
|
+ procedure ShowException(E: Exception); override;
|
|
|
+ Function ProcessRequest(P : PRequest_Rec) : Integer; virtual;
|
|
|
+ Function AllowRequest(P : PRequest_Rec) : Boolean; virtual;
|
|
|
+ Property HandlerPriority : THandlerPriority Read GetPriority Write SetPriority default hpMiddle;
|
|
|
+ Property BeforeModules : TStrings Read GetBeforeModules Write SetBeforeModules;
|
|
|
+ Property AfterModules : TStrings Read GetAfterModules Write SetAfterModules;
|
|
|
+ Property BaseLocation : String Read GetBaseLocation Write SetBaseLocation;
|
|
|
+ Property ModuleName : String Read GetModuleName Write SetModuleName;
|
|
|
+ Property HandlerName : String Read GetHandlerName Write SetHandlerName;
|
|
|
+ Property BeforeRequest : TBeforeRequestEvent Read GetBeforeRequest Write SetBeforeRequest;
|
|
|
+ Property MaxRequests: Integer read GetMaxRequests write SetMaxRequests;
|
|
|
+ Property IdleWebModuleCount: Integer read GetIdleModuleCount;
|
|
|
+ Property WorkingWebModuleCount: Integer read GetWorkingModuleCount;
|
|
|
+ end;
|
|
|
+
|
|
|
TApacheApplication = Class(TCustomApacheApplication)
|
|
|
Public
|
|
|
Property HandlerPriority;
|
|
@@ -184,16 +220,16 @@ begin
|
|
|
ap_hook_handler(H,PP1,PP2,HPRIO[Application.HandlerPriority]);
|
|
|
end;
|
|
|
|
|
|
-{ TCustomApacheApplication }
|
|
|
+{ TApacheHandler }
|
|
|
|
|
|
-function TCustomApacheApplication.GetModules(Index: integer): TStrings;
|
|
|
+function TApacheHandler.GetModules(Index: integer): TStrings;
|
|
|
begin
|
|
|
If (FModules[Index]=Nil) then
|
|
|
FModules[Index]:=TStringList.Create;
|
|
|
Result:=FModules[Index];
|
|
|
end;
|
|
|
|
|
|
-procedure TCustomApacheApplication.SetModules(Index: integer;
|
|
|
+procedure TApacheHandler.SetModules(Index: integer;
|
|
|
const AValue: TStrings);
|
|
|
begin
|
|
|
If (FModules[Index]=Nil) then
|
|
@@ -201,7 +237,7 @@ begin
|
|
|
FModules[Index].Assign(AValue);
|
|
|
end;
|
|
|
|
|
|
-Function TCustomApacheApplication.ProcessRequest(P: PRequest_Rec) : Integer;
|
|
|
+Function TApacheHandler.ProcessRequest(P: PRequest_Rec) : Integer;
|
|
|
|
|
|
Var
|
|
|
Req : TApacheRequest;
|
|
@@ -225,18 +261,18 @@ begin
|
|
|
end;
|
|
|
end;
|
|
|
|
|
|
-procedure TCustomApacheApplication.DoRun;
|
|
|
+procedure TApacheHandler.Run;
|
|
|
begin
|
|
|
// Do nothing. This is a library
|
|
|
+ Initialize;
|
|
|
end;
|
|
|
|
|
|
-function TCustomApacheApplication.WaitForRequest(out ARequest: TRequest;
|
|
|
- out AResponse: TResponse): boolean;
|
|
|
+function TApacheHandler.WaitForRequest(out ARequest: TRequest; out AResponse: TResponse): boolean;
|
|
|
begin
|
|
|
// Do nothing. Requests are triggered by Apache
|
|
|
end;
|
|
|
|
|
|
-function TCustomApacheApplication.AllowRequest(P: PRequest_Rec): Boolean;
|
|
|
+function TApacheHandler.AllowRequest(P: PRequest_Rec): Boolean;
|
|
|
|
|
|
Var
|
|
|
Hn : String;
|
|
@@ -248,15 +284,14 @@ begin
|
|
|
FBeforeRequest(Self,HN,Result);
|
|
|
end;
|
|
|
|
|
|
-function TCustomApacheApplication.GetApplicationURL(ARequest: TRequest
|
|
|
- ): String;
|
|
|
+function TApacheHandler.GetApplicationURL(ARequest: TRequest): String;
|
|
|
begin
|
|
|
Result:=inherited GetApplicationURL(ARequest);
|
|
|
If (Result='') then
|
|
|
Result:=BaseLocation;
|
|
|
end;
|
|
|
|
|
|
-constructor TCustomApacheApplication.Create(AOwner: TComponent);
|
|
|
+constructor TApacheHandler.Create(AOwner: TComponent);
|
|
|
begin
|
|
|
inherited Create(AOwner);
|
|
|
FPriority:=hpMiddle;
|
|
@@ -266,7 +301,7 @@ begin
|
|
|
FCriticalSection:=TCriticalSection.Create;
|
|
|
end;
|
|
|
|
|
|
-destructor TCustomApacheApplication.Destroy;
|
|
|
+destructor TApacheHandler.Destroy;
|
|
|
var I:Integer;
|
|
|
begin
|
|
|
FCriticalSection.Free;
|
|
@@ -280,13 +315,13 @@ begin
|
|
|
end;
|
|
|
|
|
|
|
|
|
-procedure TCustomApacheApplication.SetModuleRecord(var ModuleRecord: Module);
|
|
|
+procedure TApacheHandler.SetModuleRecord(var ModuleRecord: Module);
|
|
|
begin
|
|
|
FModuleRecord:=@ModuleRecord;
|
|
|
FillChar(ModuleRecord,SizeOf(ModuleRecord),0);
|
|
|
end;
|
|
|
|
|
|
-procedure TCustomApacheApplication.Initialize;
|
|
|
+procedure TApacheHandler.Initialize;
|
|
|
|
|
|
begin
|
|
|
If (FModuleRecord=nil) then
|
|
@@ -299,18 +334,12 @@ begin
|
|
|
FModuleRecord^.register_hooks:=@RegisterApacheHooks;
|
|
|
end;
|
|
|
|
|
|
-procedure TCustomApacheApplication.ShowException(E: Exception);
|
|
|
-begin
|
|
|
- ap_log_error(pchar(FModuleName),0,APLOG_ERR,0,Nil,'module: %s',[Pchar(E.Message)]);
|
|
|
-end;
|
|
|
-
|
|
|
-procedure TCustomApacheApplication.LogErrorMessage(Msg: String;
|
|
|
- LogLevel: integer);
|
|
|
+procedure TApacheHandler.LogErrorMessage(Msg: String; LogLevel: integer);
|
|
|
begin
|
|
|
ap_log_error(pchar(FModuleName),0,LogLevel,0,Nil,'module: %s',[pchar(Msg)]);
|
|
|
end;
|
|
|
|
|
|
-function TCustomApacheApplication.GetIdleModuleCount : Integer;
|
|
|
+function TApacheHandler.GetIdleModuleCount : Integer;
|
|
|
begin
|
|
|
FCriticalSection.Enter;
|
|
|
try
|
|
@@ -320,7 +349,7 @@ begin
|
|
|
end;
|
|
|
end;
|
|
|
|
|
|
-function TCustomApacheApplication.GetWorkingModuleCount : Integer;
|
|
|
+function TApacheHandler.GetWorkingModuleCount : Integer;
|
|
|
begin
|
|
|
FCriticalSection.Enter;
|
|
|
try
|
|
@@ -330,7 +359,7 @@ begin
|
|
|
end;
|
|
|
end;
|
|
|
|
|
|
-procedure TCustomApacheApplication.HandleRequest(ARequest: TRequest; AResponse: TResponse);
|
|
|
+procedure TApacheHandler.HandleRequest(ARequest: TRequest; AResponse: TResponse);
|
|
|
|
|
|
Var
|
|
|
MC : TCustomHTTPModuleClass;
|
|
@@ -399,7 +428,7 @@ begin
|
|
|
except
|
|
|
On E : Exception do
|
|
|
begin
|
|
|
- ShowException(E);
|
|
|
+ LogErrorMessage(E.Message,APLOG_ERR);
|
|
|
ShowRequestException(AResponse,E);
|
|
|
end;
|
|
|
end;
|
|
@@ -497,7 +526,7 @@ begin
|
|
|
ParseCookies;
|
|
|
end;
|
|
|
|
|
|
-Constructor TApacheRequest.CreateReq(App : TCustomApacheApplication; ARequest : PRequest_rec);
|
|
|
+Constructor TApacheRequest.CreateReq(App : TApacheHandler; ARequest : PRequest_rec);
|
|
|
|
|
|
begin
|
|
|
FApache:=App;
|
|
@@ -584,6 +613,118 @@ begin
|
|
|
//empty
|
|
|
end;
|
|
|
|
|
|
+{ TCustomApacheApplication }
|
|
|
+
|
|
|
+function TCustomApacheApplication.GetAfterModules: TStrings;
|
|
|
+begin
|
|
|
+ result := TApacheHandler(WebHandler).AfterModules;
|
|
|
+end;
|
|
|
+
|
|
|
+function TCustomApacheApplication.GetBaseLocation: String;
|
|
|
+begin
|
|
|
+ result := TApacheHandler(WebHandler).BaseLocation;
|
|
|
+end;
|
|
|
+
|
|
|
+function TCustomApacheApplication.GetBeforeModules: TStrings;
|
|
|
+begin
|
|
|
+ result := TApacheHandler(WebHandler).BeforeModules;
|
|
|
+end;
|
|
|
+
|
|
|
+function TCustomApacheApplication.GetBeforeRequest: TBeforeRequestEvent;
|
|
|
+begin
|
|
|
+ result := TApacheHandler(WebHandler).BeforeRequest;
|
|
|
+end;
|
|
|
+
|
|
|
+function TCustomApacheApplication.GetHandlerName: String;
|
|
|
+begin
|
|
|
+ result := TApacheHandler(WebHandler).HandlerName;
|
|
|
+end;
|
|
|
+
|
|
|
+function TCustomApacheApplication.GetIdleModuleCount: Integer;
|
|
|
+begin
|
|
|
+ result := TApacheHandler(WebHandler).IdleWebModuleCount;
|
|
|
+end;
|
|
|
+
|
|
|
+function TCustomApacheApplication.GetMaxRequests: Integer;
|
|
|
+begin
|
|
|
+ result := TApacheHandler(WebHandler).MaxRequests;
|
|
|
+end;
|
|
|
+
|
|
|
+function TCustomApacheApplication.GetModuleName: String;
|
|
|
+begin
|
|
|
+ result := TApacheHandler(WebHandler).ModuleName;
|
|
|
+end;
|
|
|
+
|
|
|
+function TCustomApacheApplication.GetPriority: THandlerPriority;
|
|
|
+begin
|
|
|
+ result := TApacheHandler(WebHandler).HandlerPriority;
|
|
|
+end;
|
|
|
+
|
|
|
+function TCustomApacheApplication.GetWorkingModuleCount: Integer;
|
|
|
+begin
|
|
|
+ result := TApacheHandler(WebHandler).WorkingWebModuleCount;
|
|
|
+end;
|
|
|
+
|
|
|
+procedure TCustomApacheApplication.SetAfterModules(const AValue: TStrings);
|
|
|
+begin
|
|
|
+ TApacheHandler(WebHandler).AfterModules := AValue;
|
|
|
+end;
|
|
|
+
|
|
|
+procedure TCustomApacheApplication.SetBaseLocation(const AValue: String);
|
|
|
+begin
|
|
|
+ TApacheHandler(WebHandler).BaseLocation := AValue;
|
|
|
+end;
|
|
|
+
|
|
|
+procedure TCustomApacheApplication.SetBeforeModules(const AValue: TStrings);
|
|
|
+begin
|
|
|
+ TApacheHandler(WebHandler).BeforeModules := AValue;
|
|
|
+end;
|
|
|
+
|
|
|
+procedure TCustomApacheApplication.SetBeforeRequest(const AValue: TBeforeRequestEvent);
|
|
|
+begin
|
|
|
+ TApacheHandler(WebHandler).BeforeRequest := AValue;
|
|
|
+end;
|
|
|
+
|
|
|
+procedure TCustomApacheApplication.SetHandlerName(const AValue: String);
|
|
|
+begin
|
|
|
+ TApacheHandler(WebHandler).HandlerName := AValue;
|
|
|
+end;
|
|
|
+
|
|
|
+procedure TCustomApacheApplication.SetMaxRequests(const AValue: Integer);
|
|
|
+begin
|
|
|
+ TApacheHandler(WebHandler).MaxRequests := AValue;
|
|
|
+end;
|
|
|
+
|
|
|
+procedure TCustomApacheApplication.SetModuleName(const AValue: String);
|
|
|
+begin
|
|
|
+ TApacheHandler(WebHandler).ModuleName := AValue;
|
|
|
+end;
|
|
|
+
|
|
|
+procedure TCustomApacheApplication.SetPriority(const AValue: THandlerPriority);
|
|
|
+begin
|
|
|
+ TApacheHandler(WebHandler).HandlerPriority := AValue;
|
|
|
+end;
|
|
|
+
|
|
|
+function TCustomApacheApplication.InitializeWebHandler: TWebHandler;
|
|
|
+begin
|
|
|
+ Result:=TApacheHandler.Create(self);
|
|
|
+end;
|
|
|
+
|
|
|
+procedure TCustomApacheApplication.ShowException(E: Exception);
|
|
|
+begin
|
|
|
+ ap_log_error(pchar(TApacheHandler(WebHandler).ModuleName),0,APLOG_ERR,0,Nil,'module: %s',[Pchar(E.Message)]);
|
|
|
+end;
|
|
|
+
|
|
|
+function TCustomApacheApplication.ProcessRequest(P: PRequest_Rec): Integer;
|
|
|
+begin
|
|
|
+ result := TApacheHandler(WebHandler).ProcessRequest(p);
|
|
|
+end;
|
|
|
+
|
|
|
+function TCustomApacheApplication.AllowRequest(P: PRequest_Rec): Boolean;
|
|
|
+begin
|
|
|
+ result := TApacheHandler(WebHandler).AllowRequest(p);
|
|
|
+end;
|
|
|
+
|
|
|
Initialization
|
|
|
BeginThread(@__dummythread);//crash prevention for simultaneous requests
|
|
|
sleep(300);
|