1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
|
{
$Id: header,v 1.1 2000/07/13 06:33:45 michael Exp $
This file is part of the Free Component Library (FCL)
Copyright (c) 1999-2000 by the Free Pascal development team
See the file COPYING.FPC, included in this distribution,
for details about the copyright.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
**********************************************************************}
{$mode objfpc}
{$H+}
unit fpapache;
interface
uses
SysUtils,Classes,CustWeb,httpDefs,fpHTTP,httpd, apr, SyncObjs;
Type
TApacheHandler = Class;
{ TApacheRequest }
TApacheRequest = Class(TRequest)
Private
FApache : TApacheHandler;
FRequest : PRequest_rec;
Protected
Function GetFieldValue(Index : Integer) : String; override;
Procedure InitFromRequest;
procedure ReadContent; override;
Public
Constructor CreateReq(App : TApacheHandler; ARequest : PRequest_rec);
Property ApacheRequest : Prequest_rec Read FRequest;
Property ApacheApp : TApacheHandler Read FApache;
end;
{ TApacheResponse }
TApacheResponse = Class(TResponse)
private
FApache : TApacheHandler;
FRequest : PRequest_rec;
procedure SendStream(S: TStream);
Protected
Procedure DoSendHeaders(Headers : TStrings); override;
Procedure DoSendContent; override;
Public
Constructor CreateApache(Req : TApacheRequest);
Property ApacheRequest : Prequest_rec Read FRequest;
Property ApacheApp : TApacheHandler Read FApache;
end;
{ TCustomApacheApplication }
THandlerPriority = (hpFirst,hpMiddle,hpLast);
TBeforeRequestEvent = Procedure(Sender : TObject; Const AHandler : String;
Var AllowRequest : Boolean) of object;
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
FIdleWebModules: TList; //List of idle web modules available
FCriticalSection: TCriticalSection;
FBaseLocation: String;
FBeforeRequest: TBeforeRequestEvent;
FHandlerName: String;
FModuleName: String;
FModules : Array[0..1] of TStrings;
FPriority: THandlerPriority;
FModuleRecord : PModule;
function GetModules(Index: integer): TStrings;
procedure SetModules(Index: integer; const AValue: TStrings);
function GetIdleModuleCount : Integer;
function GetWorkingModuleCount : Integer;
Protected
Function ProcessRequest(P : PRequest_Rec) : Integer; virtual;
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;
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;
Property BeforeModules : TStrings Index 0 Read GetModules Write SetModules;
Property AfterModules : TStrings Index 1 Read GetModules Write SetModules;
Property BaseLocation : String Read FBaseLocation Write FBaseLocation;
Property ModuleName : String Read FModuleName Write FModuleName;
Property HandlerName : String Read FHandlerName Write FHandlerName;
Property BeforeRequest : TBeforeRequestEvent Read FBeforeRequest Write FBeforeRequest;
Property MaxRequests: Integer read FMaxRequests write FMaxRequests;
Property IdleWebModuleCount: Integer read GetIdleModuleCount;
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 Initialize;override;
procedure ShowException(E: Exception); override;
Function ProcessRequest(P : PRequest_Rec) : Integer; virtual;
Function AllowRequest(P : PRequest_Rec) : Boolean; virtual;
Procedure SetModuleRecord(Var ModuleRecord : Module);
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;
Property BeforeModules;
Property AfterModules;
Property AllowDefaultModule;
Property OnGetModule;
Property BaseLocation;
Property ModuleName;
Property MaxRequests;
Property IdleWebModuleCount;
Property WorkingWebModuleCount;
end;
EFPApacheError = Class(Exception);
Var
Application : TCustomApacheApplication = Nil;
ShowCleanUpErrors : Boolean = False;
AlternateHandler : ap_hook_handler_t = Nil;
Implementation
uses CustApp;
resourcestring
SErrNoModuleNameForRequest = 'Could not determine HTTP module name for request';
SErrNoModuleForRequest = 'Could not determine HTTP module for request "%s"';
SErrNoModuleRecord = 'No module record location set.';
SErrNoModuleName = 'No module name set';
SErrTooManyRequests = 'Too many simultaneous requests.';
const
HPRIO : Array[THandlerPriority] of Integer
= (APR_HOOK_FIRST,APR_HOOK_MIDDLE,APR_HOOK_LAST);
Procedure InitApache;
begin
Application:=TCustomApacheApplication.Create(Nil);
if not assigned(CustomApplication) then
CustomApplication := Application;
end;
Procedure DoneApache;
begin
Try
if CustomApplication=Application then
CustomApplication := nil;
FreeAndNil(Application);
except
if ShowCleanUpErrors then
Raise;
end;
end;
Function DefaultApacheHandler(P : PRequest_Rec) : integer;cdecl;
begin
If (AlternateHandler<>Nil) then
Result:=AlternateHandler(P)
else
If Application.AllowRequest(P) then
Result:=Application.ProcessRequest(P)
else
Result:=DECLINED;
end;
Procedure RegisterApacheHooks(P: PApr_pool_t);cdecl;
Var
H : ap_hook_handler_t;
PP1,PP2 : PPChar;
begin
H:=AlternateHandler;
If (H=Nil) then
H:=@DefaultApacheHandler;
PP1:=Nil;
PP2:=Nil;
ap_hook_handler(H,PP1,PP2,HPRIO[Application.HandlerPriority]);
end;
{ TApacheHandler }
function TApacheHandler.GetModules(Index: integer): TStrings;
begin
If (FModules[Index]=Nil) then
FModules[Index]:=TStringList.Create;
Result:=FModules[Index];
end;
procedure TApacheHandler.SetModules(Index: integer;
const AValue: TStrings);
begin
If (FModules[Index]=Nil) then
FModules[Index]:=TStringList.Create;
FModules[Index].Assign(AValue);
end;
Function TApacheHandler.ProcessRequest(P: PRequest_Rec) : Integer;
Var
Req : TApacheRequest;
Resp : TApacheResponse;
begin
Req:=TApacheRequest.CreateReq(Self,P);
Try
InitRequest(Req);
Req.InitRequestVars;
Resp:=TApacheResponse.CreateApache(Req);
Try
InitResponse(Resp);
HandleRequest(Req,Resp);
If Not Resp.ContentSent then
Resp.SendContent;
Finally
Result:=OK;
Resp.Free;
end;
Finally
Req.Free;
end;
end;
procedure TApacheHandler.Run;
begin
// Do nothing. This is a library
Initialize;
end;
function TApacheHandler.WaitForRequest(out ARequest: TRequest; out AResponse: TResponse): boolean;
begin
Result:=False;
ARequest:=Nil;
AResponse:=Nil;
end;
function TApacheHandler.AllowRequest(P: PRequest_Rec): Boolean;
Var
Hn : String;
begin
HN:=StrPas(p^.Handler);
Result:=CompareText(HN,FHandlerName)=0;
If Assigned(FBeforeRequest) then
FBeforeRequest(Self,HN,Result);
end;
function TApacheHandler.GetApplicationURL(ARequest: TRequest): String;
begin
Result:=inherited GetApplicationURL(ARequest);
If (Result='') then
Result:=BaseLocation;
end;
constructor TApacheHandler.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FPriority:=hpMiddle;
FMaxRequests:=64;
FWorkingWebModules:=TList.Create;
FIdleWebModules:=TList.Create;
FCriticalSection:=TCriticalSection.Create;
end;
destructor TApacheHandler.Destroy;
var I:Integer;
begin
FCriticalSection.Free;
for I := FIdleWebModules.Count - 1 downto 0 do
TComponent(FIdleWebModules[I]).Free;
FIdleWebModules.Free;
for I := FWorkingWebModules.Count - 1 downto 0 do
TComponent(FWorkingWebModules[I]).Free;
FWorkingWebModules.Free;
inherited Destroy;
end;
procedure TApacheHandler.SetModuleRecord(var ModuleRecord: Module);
begin
FModuleRecord:=@ModuleRecord;
FillChar(ModuleRecord,SizeOf(ModuleRecord),0);
end;
procedure TApacheHandler.Initialize;
begin
If (FModuleRecord=nil) then
Raise EFPApacheError.Create(SErrNoModuleRecord);
if (FModuleName='') and (FModuleRecord^.Name=Nil) then
Raise EFPApacheError.Create(SErrNoModuleName);
STANDARD20_MODULE_STUFF(FModuleRecord^);
If (StrPas(FModuleRecord^.name)<>FModuleName) then
FModuleRecord^.Name:=PChar(FModuleName);
FModuleRecord^.register_hooks:=@RegisterApacheHooks;
end;
procedure TApacheHandler.LogErrorMessage(Msg: String; LogLevel: integer);
begin
ap_log_error(pchar(FModuleName),0,LogLevel,0,Nil,'module: %s',[pchar(Msg)]);
end;
function TApacheHandler.GetIdleModuleCount : Integer;
begin
FCriticalSection.Enter;
try
Result := FIdleWebModules.Count;
finally
FCriticalSection.Leave;
end;
end;
function TApacheHandler.GetWorkingModuleCount : Integer;
begin
FCriticalSection.Enter;
try
Result := FWorkingWebModules.Count;
finally
FCriticalSection.Leave;
end;
end;
procedure TApacheHandler.HandleRequest(ARequest: TRequest; AResponse: TResponse);
Var
MC : TCustomHTTPModuleClass;
M : TCustomHTTPModule;
MN : String;
MI : TModuleItem;
Procedure GetAWebModule;
Var II:Integer;
begin
FCriticalSection.Enter;
try
if (FMaxRequests>0) and (FWorkingWebModules.Count>=FMaxRequests) then
Raise EFPApacheError.Create(SErrTooManyRequests);
if (FIdleWebModules.Count>0) then
begin
II := FIdleWebModules.Count - 1;
while (II>=0) and not (TComponent(FIdleWebModules[II]) is MC) do
Dec(II);
if (II>=0) then
begin
M:=TCustomHTTPModule(FIdleWebModules[II]);
FIdleWebModules.Delete(II);
end;
end;
if (M=nil) then
begin
M:=MC.Create(Self);
M.Name := '';
end;
FWorkingWebModules.Add(M);
finally
FCriticalSection.Leave;
end;
end;
begin
try
MC:=Nil;
M := Nil;
If (OnGetModule<>Nil) then
OnGetModule(Self,ARequest,MC);
If (MC=Nil) then
begin
MN:=GetModuleName(ARequest);
If (MN='') and Not AllowDefaultModule then
Raise EFPApacheError.Create(SErrNoModuleNameForRequest);
MI:=ModuleFactory.FindModule(MN);
If (MI=Nil) and (ModuleFactory.Count=1) then
MI:=ModuleFactory[0];
if (MI=Nil) then
Raise EFPApacheError.CreateFmt(SErrNoModuleForRequest,[MN]);
MC:=MI.ModuleClass;
end;
GetAWebModule;
M.HandleRequest(ARequest,AResponse);
FCriticalSection.Enter;
try
FWorkingWebModules.Remove(M);
FIdleWebModules.Add(M);
finally
FCriticalSection.Leave;
end;
except
On E : Exception do
begin
LogErrorMessage(E.Message,APLOG_ERR);
ShowRequestException(AResponse,E);
end;
end;
end;
{ TApacheRequest }
function TApacheRequest.GetFieldValue(Index: Integer): String;
Function MaybeP(P : Pchar) : String;
begin
If (P<>Nil) then
Result:=StrPas(P);
end;
var
FN : String;
I : Integer;
begin
Result:='';
If (Index in [1..NoHTTPFields]) then
begin
FN:=HTTPFieldNames[Index];
Result:=MaybeP(apr_table_get(FRequest^.headers_in,pchar(FN)));
end;
if (Result='') and Assigned(FRequest) then
case Index of
0 : Result:=MaybeP(FRequest^.protocol); // ProtocolVersion
7 : Result:=MaybeP(FRequest^.content_encoding); //ContentEncoding
25 : Result:=MaybeP(FRequest^.path_info); // PathInfo
26 : Result:=MaybeP(FRequest^.filename); // PathTranslated
27 : // RemoteAddr
If (FRequest^.Connection<>Nil) then
Result:=MaybeP(FRequest^.Connection^.remote_ip);
28 : // RemoteHost
If (FRequest^.Connection<>Nil) then
begin
Result:=MaybeP(ap_get_remote_host(FRequest^.Connection,
FRequest^.per_dir_config,
// nil,
REMOTE_NAME,@i));
end;
29 : begin // ScriptName
Result:=MaybeP(FRequest^.unparsed_uri);
I:=Pos('?',Result)-1;
If (I=-1) then
I:=Length(Result);
Result:=Copy(Result,1,I-Length(PathInfo));
end;
30 : Result:=IntToStr(ap_get_server_port(FRequest)); // ServerPort
31 : Result:=MaybeP(FRequest^.method); // Method
32 : Result:=MaybeP(FRequest^.unparsed_uri); // URL
33 : Result:=MaybeP(FRequest^.args); // Query
34 : Result:=MaybeP(FRequest^.HostName); // Host
else
Result:=inherited GetFieldValue(Index);
end;
end;
procedure TApacheRequest.ReadContent;
Function MinS(A,B : Integer) : Integer;
begin
If A<B then
Result:=A
else
Result:=B;
end;
Var
Left,Len,Count,Bytes : Integer;
P : Pchar;
begin
ap_setup_client_block(FRequest,REQUEST_CHUNKED_DECHUNK);
If (ap_should_client_block(FRequest)=1) then
begin
Len:=ContentLength;
If (Len>0) then
begin
SetLength(FContent,Len);
P:=PChar(FContent);
Left:=Len;
Count:=0;
Repeat
Bytes:=ap_get_client_block(FRequest,P,MinS(10*1024,Left));
Dec(Left,Bytes);
Inc(P,Bytes);
Inc(Count,Bytes);
Until (Count>=Len) or (Bytes=0);
SetLength(FContent,Count);
end;
end;
FContentRead:=True;
end;
procedure TApacheRequest.InitFromRequest;
begin
ParseCookies;
end;
Constructor TApacheRequest.CreateReq(App : TApacheHandler; ARequest : PRequest_rec);
begin
FApache:=App;
FRequest:=Arequest;
ReturnedPathInfo:=App.BaseLocation;
Inherited Create;
InitFromRequest;
end;
{ TApacheResponse }
procedure TApacheResponse.DoSendHeaders(Headers: TStrings);
Var
I,P : Integer;
N,V : String;
begin
For I:=0 to Headers.Count-1 do
begin
V:=Headers[i];
P:=Pos(':',V);
If (P<>0) and (P<Length(V)) then
begin
N:=Copy(V,1,P-1);
System.Delete(V,1,P);
V := Trim(V);//no need space before the value, apache puts it there
apr_table_set(FRequest^.headers_out,Pchar(N),Pchar(V));
end;
end;
end;
procedure TApacheResponse.DoSendContent;
Var
S : String;
I : Integer;
begin
S:=ContentType;
If (S<>'') then
FRequest^.content_type:=apr_pstrdup(FRequest^.pool,Pchar(S));
S:=ContentEncoding;
If (S<>'') then
FRequest^.content_encoding:=apr_pstrdup(FRequest^.pool,Pchar(S));
If Code <> 200 then
FRequest^.status := Code;
If assigned(ContentStream) then
SendStream(Contentstream)
else
for I:=0 to Contents.Count-1 do
begin
S:=Contents[i]+LineEnding;
// If there is a null, it's written also with ap_rwrite
ap_rwrite(PChar(S),Length(S),FRequest);
end;
end;
Procedure TApacheResponse.SendStream(S : TStream);
Var
Buf : Array[0..(10*1024)-1] of Byte;
Count : Integer;
begin
S.Seek(0,soBeginning);
Repeat
Count:=S.Read(Buf,SizeOf(Buf));
If Count>0 then
ap_rwrite(@Buf,Count,FRequest);
Until (Count=0);
end;
Constructor TApacheResponse.CreateApache(Req : TApacheRequest);
begin
FApache:=Req.ApacheApp;
Frequest:=Req.ApacheRequest;
Inherited Create(Req);
end;
function __dummythread(p: pointer): ptrint;
begin
sleep(1000);
Result:=0;
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.Initialize;
begin
Inherited;
TApacheHandler(WebHandler).Initialize;
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;
procedure TCustomApacheApplication.SetModuleRecord(var ModuleRecord: Module);
begin
TApacheHandler(WebHandler).SetModuleRecord(ModuleRecord);
end;
Initialization
BeginThread(@__dummythread);//crash prevention for simultaneous requests
InitApache;
Finalization
DoneApache;
end.
|