- Timestamp:
- Jul 20, 2011, 11:42:23 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Network/CoolWeb/WebServer/UWebApp.pas
r255 r256 1 1 unit UWebApp; 2 2 3 {$mode objfpc}{$H+}3 {$mode Delphi}{$H+} 4 4 5 5 interface 6 6 7 7 uses 8 Classes, SysUtils, CustApp, SpecializedList, UWebPage; 8 Classes, SysUtils, CustApp, SpecializedList, UWebPage, UHTTPSessionFile, 9 UHTTPServer, UHTTPServerCGI; 9 10 10 11 type 11 12 TRegistredPage = class 12 Path: string;13 Name: string; 13 14 Page: TWebPage; 15 end; 16 17 { TRegistredPageList } 18 19 TRegistredPageList = class(TListObject) 20 function FindByName(Name: string): TRegistredPage; 14 21 end; 15 22 … … 18 25 TWebApp = class(TCustomApplication) 19 26 private 27 FOnInitialize: TNotifyEvent; 20 28 procedure DoRun; override; 29 procedure HTTPServerRequest(HandlerData: THTTPHandlerData); 21 30 public 22 Pages: TListObject; 31 Pages: TRegistredPageList; 32 HTTPServer: THTTPServer; 33 HTTPSessionStorageFile: THTTPSessionStorageFile; 23 34 procedure RegisterPage(PageClass: TWebPageClass; out Reference; Path: string); 24 35 constructor Create(AOwner: TComponent); override; 25 36 destructor Destroy; override; 37 property OnInitialize: TNotifyEvent read FOnInitialize write FOnInitialize; 26 38 end; 27 39 … … 29 41 procedure Register; 30 42 43 var 44 Application: TWebApp; 45 31 46 32 47 implementation 48 49 resourcestring 50 SPageNotFound = 'Page not found'; 51 33 52 34 53 procedure Register; … … 37 56 end; 38 57 58 { TRegistredPageList } 59 60 function TRegistredPageList.FindByName(Name: string): TRegistredPage; 61 var 62 I: Integer; 63 begin 64 I := 0; 65 while (I < Count) and (TRegistredPage(Items[I]).Name <> Name) do Inc(I); 66 if I < Count then Result := TRegistredPage(Items[I]) 67 else Result := nil; 68 end; 69 39 70 { TWebApp } 40 71 41 72 procedure TWebApp.DoRun; 42 73 begin 74 if Assigned(FOnInitialize) then FOnInitialize(Self); 75 HTTPServer.Run; 43 76 Terminate; 44 77 end; … … 53 86 // NewPage.Page := PageClass.Create(Self); 54 87 NewPage.Page := PageClass.Create(nil); 55 NewPage. Path:= Path;88 NewPage.Name := Path; 56 89 TWebPage(Reference) := NewPage.Page; 90 end; 91 92 procedure TWebApp.HTTPServerRequest(HandlerData: THTTPHandlerData); 93 var 94 Page: TRegistredPage; 95 PageName: string; 96 begin 97 with HandlerData do begin 98 //Request.QueryParts.Count := 2; 99 //Request.QueryParts[0] := 'uzivatel'; 100 //Request.QueryParts[1] := 'prihlaseni'; 101 102 if Request.QueryParts.Count > 0 then PageName := Request.QueryParts[0] 103 else PageName := ''; 104 Page := Pages.FindByName(PageName); 105 if Assigned(Page) then begin 106 Page.Page.OnProduce(HandlerData); 107 end else Response.Stream.WriteString(SPageNotFound); 108 end; 57 109 end; 58 110 … … 60 112 begin 61 113 inherited Create(AOwner); 62 Pages := TListObject.Create; 114 Pages := TRegistredPageList.Create; 115 HTTPServer := THTTPServerCGI.Create(nil); 116 HTTPServer.OnRequest := HTTPServerRequest; 63 117 end; 64 118 … … 66 120 begin 67 121 Pages.Free; 122 HTTPServer.Free; 68 123 inherited Destroy; 69 124 end; 70 125 126 127 initialization 128 129 Application := TWebApp.Create(nil); 130 131 132 finalization 133 134 Application.Free; 135 71 136 end. 72 137
Note:
See TracChangeset
for help on using the changeset viewer.