Changeset 68 for trunk/Components/CoolWeb
- Timestamp:
- Dec 26, 2011, 12:07:37 PM (13 years ago)
- Location:
- trunk/Components/CoolWeb
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Components/CoolWeb/Common/UHtmlClasses.pas
r67 r68 9 9 10 10 type 11 12 { TDomainAddress } 13 11 14 TDomainAddress = class(TPersistent) 12 15 private … … 14 17 procedure SetAsString(const Value: string); 15 18 public 16 Levels: array of string; 19 Levels: TListString; 20 constructor Create; 21 destructor Destroy; override; 17 22 property AsString: string read GetAsString write SetAsString; 18 23 end; 19 24 20 25 TAddrClass = (acA, acB, acC, acD, acE); 26 27 { TIpAddress } 21 28 22 29 TIpAddress = class(TPersistent) … … 32 39 Octets: array[0..3] of Byte; 33 40 procedure Assign(Source: TPersistent); override; 41 function IsAddressString(Value: string): Boolean; 34 42 property AsCardinal: Cardinal read GetAsCardinal write SetAsCardinal; 35 43 property AsString: string read GetAsString write SetAsString; … … 589 597 end; 590 598 599 function TIpAddress.IsAddressString(Value: string): Boolean; 600 var 601 Parts: TListString; 602 begin 603 Result := True; 604 try 605 Parts := TListString.Create; 606 Parts.Explode(Value, '.', StrToStr); 607 if Parts.Count = 4 then begin 608 if (StrToInt(Parts[3]) < 0) or (StrToInt(Parts[3]) > 255) then Result := False; 609 if (StrToInt(Parts[2]) < 0) or (StrToInt(Parts[2]) > 255) then Result := False; 610 if (StrToInt(Parts[1]) < 0) or (StrToInt(Parts[1]) > 255) then Result := False; 611 if (StrToInt(Parts[0]) < 0) or (StrToInt(Parts[0]) > 255) then Result := False; 612 end else Result := False; 613 finally 614 Parts.Free; 615 end; 616 end; 617 591 618 function TIpAddress.GetAddrClass: TAddrClass; 592 619 begin … … 704 731 705 732 function TDomainAddress.GetAsString: string; 706 var 707 I: Integer; 708 begin 709 Result := ''; 710 for I := High(Levels) downto 0 do Result := Result + '.' + Levels[I]; 711 Delete(Result, 1, 1); 733 begin 734 try 735 Levels.Reverse; 736 Result := Levels.Implode('.', StrToStr); 737 finally 738 Levels.Reverse; 739 end; 712 740 end; 713 741 714 742 procedure TDomainAddress.SetAsString(const Value: string); 715 var 716 StrArray: TListString; 717 I: Integer; 718 begin 719 try 720 StrArray := TListString.Create; 721 StrArray.Explode(Value, '.', StrToStr); 722 SetLength(Levels, StrArray.Count); 723 for I := 0 to StrArray.Count - 1 do 724 Levels[StrArray.Count - 1 - I] := StrArray[I]; 725 finally 726 StrArray.Free; 727 end; 743 begin 744 Levels.Explode(Value, '.', StrToStr); 745 Levels.Reverse; 746 end; 747 748 constructor TDomainAddress.Create; 749 begin 750 Levels := TListString.Create; 751 end; 752 753 destructor TDomainAddress.Destroy; 754 begin 755 Levels.Free; 756 inherited Destroy; 728 757 end; 729 758 … … 792 821 procedure THostAddress.SetAsString(const Value: string); 793 822 begin 794 State := asIpAddress;795 try823 if IpAddress.IsAddressString(Value) then begin 824 State := asIpAddress; 796 825 IpAddress.AsString := Value; 797 e xcept798 on EConvertError doState := asDomainName;799 end;800 if State = asDomainName then DomainName.AsString := Value;826 end else begin 827 State := asDomainName; 828 DomainName.AsString := Value; 829 end; 801 830 end; 802 831 -
trunk/Components/CoolWeb/Network/UTCPServer.pas
r61 r68 31 31 32 32 TClientThreadedPool = class(TThreadPool) 33 protected 34 function NewItemObject: TObject; override; 33 35 private 34 36 FActive: Boolean; … … 164 166 { TClientThreadedPool } 165 167 168 function TClientThreadedPool.NewItemObject: TObject; 169 begin 170 Result := TTCPClientThread.Create; 171 TResetableThread(Result).OnException := ThreadException; 172 end; 173 166 174 procedure TClientThreadedPool.SetActive(const AValue: Boolean); 167 175 begin -
trunk/Components/CoolWeb/WebServer/UHTTPServer.pas
r67 r68 37 37 Cookies: TCookieList; 38 38 Post: TQueryParameterList; 39 procedure Clear; 39 40 constructor Create; 40 41 destructor Destroy; override; … … 48 49 Headers: TStringList; 49 50 Cookies: TCookieList; 51 procedure Clear; 50 52 constructor Create; 51 53 destructor Destroy; override; … … 232 234 { THTTPResponse } 233 235 236 procedure THTTPResponse.Clear; 237 begin 238 Content.Clear; 239 Cookies.Clear; 240 Headers.Clear; 241 end; 242 234 243 constructor THTTPResponse.Create; 235 244 begin … … 267 276 268 277 { THTTPRequest } 278 279 procedure THTTPRequest.Clear; 280 begin 281 Post.Clear; 282 Content.Clear; 283 QueryParts.Clear; 284 Cookies.Clear; 285 Headers.Clear; 286 Query.Clear; 287 end; 269 288 270 289 constructor THTTPRequest.Create; -
trunk/Components/CoolWeb/WebServer/UHTTPServerCGI.pas
r67 r68 66 66 repeat 67 67 Count := InputStream.Read(Buffer[1], Length(Buffer)); 68 Request.Content.Write(Buffer[1], Count);68 if Count > 0 then Request.Content.Write(Buffer[1], Count); 69 69 until Count = 0; 70 70 finally … … 77 77 78 78 // Load data 79 if Request.Headers.IndexOfName('Content-length') <> -1 then79 (*if Request.Headers.IndexOfName('Content-length') <> -1 then 80 80 try 81 81 InputStream := TIOStream.Create(iosInput); … … 83 83 finally 84 84 InputStream.Free; 85 end; 85 end; *) 86 86 87 87 // Load environment variables -
trunk/Components/CoolWeb/WebServer/UHTTPServerTCP.pas
r67 r68 21 21 constructor Create(AOwner: TComponent); override; 22 22 destructor Destroy; override; 23 procedure Run; override; 23 24 published 24 25 property MaxConnection: Integer read FMaxConnection write FMaxConnection; … … 143 144 end; 144 145 146 procedure THTTPServerTCP.Run; 147 begin 148 inherited Run; 149 WriteLn('HTTP Server started in TCP mode.'); 150 WriteLn('Listen on ' + Socket.Address + ':' + IntToStr(Socket.Port)); 151 WriteLn('Press any key to terminate...'); 152 Socket.ThreadPool.TotalCount := MaxConnection; 153 Socket.Active := True; 154 ReadLn; 155 WriteLn('Exiting'); 156 end; 157 145 158 end. 146 159 -
trunk/Components/CoolWeb/WebServer/UWebApp.pas
r67 r68 7 7 uses 8 8 Classes, SysUtils, CustApp, SpecializedList, UWebPage, UHTTPSessionFile, 9 UHTTPServer , UHTTPServerCGI;9 UHTTPServer; 10 10 11 11 type 12 THTTPServerType = (stCGI, stTCP); 13 12 14 TRegistredPage = class 13 15 Name: string; … … 26 28 private 27 29 FOnInitialize: TNotifyEvent; 30 FServerType: THTTPServerType; 28 31 procedure DoRun; override; 29 32 function DumpExceptionCallStack(E: Exception): string; 30 33 procedure HTTPServerRequest(HandlerData: THTTPHandlerData); 34 procedure SetServerType(AValue: THTTPServerType); 31 35 public 32 36 Pages: TRegistredPageList; … … 39 43 destructor Destroy; override; 40 44 property OnInitialize: TNotifyEvent read FOnInitialize write FOnInitialize; 45 property ServerType: THTTPServerType read FServerType write SetServerType; 41 46 end; 42 47 … … 49 54 50 55 implementation 56 57 uses 58 UHTTPServerCGI, UHTTPServerTCP; 51 59 52 60 resourcestring … … 133 141 end else Response.Content.WriteString(SPageNotFound); 134 142 end; 143 end; 144 145 procedure TWebApp.SetServerType(AValue: THTTPServerType); 146 begin 147 if FServerType = AValue then Exit; 148 FServerType := AValue; 149 HTTPServer.Free; 150 case FServerType of 151 stCGI: HTTPServer := THTTPServerCGI.Create(nil); 152 stTCP: HTTPServer := THTTPServerTCP.Create(nil); 153 end; 154 HTTPServer.OnRequest := HTTPServerRequest; 135 155 end; 136 156
Note:
See TracChangeset
for help on using the changeset viewer.