Changeset 237 for Network


Ignore:
Timestamp:
Apr 30, 2011, 10:54:24 PM (14 years ago)
Author:
george
Message:
  • Main web server classes reworked as components for easier visual design.
Location:
Network/CoolWeb
Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • Network/CoolWeb/CoolWeb.lpk

    r222 r237  
    2020    <License Value="GNU/GPL"/>
    2121    <Version Minor="1"/>
    22     <Files Count="16">
     22    <Files Count="17">
    2323      <Item1>
    2424        <Filename Value="WebServer/UHTTPServer.pas"/>
     
    2727      <Item2>
    2828        <Filename Value="WebServer/UHTTPServerCGI.pas"/>
     29        <HasRegisterProc Value="True"/>
    2930        <UnitName Value="UHTTPServerCGI"/>
    3031      </Item2>
    3132      <Item3>
    3233        <Filename Value="WebServer/UHTTPServerTCP.pas"/>
     34        <HasRegisterProc Value="True"/>
    3335        <UnitName Value="UHTTPServerTCP"/>
    3436      </Item3>
    3537      <Item4>
    3638        <Filename Value="WebServer/UHTTPSessionFile.pas"/>
     39        <HasRegisterProc Value="True"/>
    3740        <UnitName Value="UHTTPSessionFile"/>
    3841      </Item4>
    3942      <Item5>
    4043        <Filename Value="WebServer/UHTTPSessionMySQL.pas"/>
     44        <HasRegisterProc Value="True"/>
    4145        <UnitName Value="UHTTPSessionMySQL"/>
    4246      </Item5>
     
    8589        <UnitName Value="UXmlClasses"/>
    8690      </Item16>
     91      <Item17>
     92        <Filename Value="WebServer/UWebPage.pas"/>
     93        <UnitName Value="UWebPage"/>
     94      </Item17>
    8795    </Files>
    8896    <Type Value="RunAndDesignTime"/>
  • Network/CoolWeb/CoolWeb.pas

    r95 r237  
    88
    99uses
    10   UHTTPServer, UHTTPServerCGI, UHTTPServerTCP, UHTTPSessionFile,
     10  UHTTPServer, UHTTPServerCGI, UHTTPServerTCP, UHTTPSessionFile, 
    1111  UHTTPSessionMySQL, USqlDatabase, UTCPServer, UPageList, UUser, UCommon,
    1212  UHtmlClasses, UMemoryStreamEx, UMIMEType, UPool, UResetableThread,
    13   UXmlClasses, LazarusPackageIntf;
     13  UXmlClasses, UWebPage, LazarusPackageIntf;
    1414
    1515implementation
     
    1717procedure Register;
    1818begin
     19  RegisterUnit('UHTTPServerCGI', @UHTTPServerCGI.Register);
     20  RegisterUnit('UHTTPServerTCP', @UHTTPServerTCP.Register);
     21  RegisterUnit('UHTTPSessionFile', @UHTTPSessionFile.Register);
     22  RegisterUnit('UHTTPSessionMySQL', @UHTTPSessionMySQL.Register);
    1923end;
    2024
  • Network/CoolWeb/WebServer/UHTTPServer.pas

    r104 r237  
    7777  { THTTPSessionStorage }
    7878
    79   THTTPSessionStorage = class
     79  THTTPSessionStorage = class(TComponent)
    8080    procedure Load(HandlerData: THTTPHandlerData); virtual;
    8181    procedure Save(HandlerData: THTTPHandlerData); virtual;
    82     constructor Create; virtual;
     82    constructor Create(AOwner: TComponent); override;
    8383    destructor Destroy; override;
    8484  end;
     
    8686  { THTTPServer }
    8787
    88   THTTPServer = class
     88  THTTPServer = class(TComponent)
    8989  private
     90    FDocumentRoot: string;
    9091    FOnRequest: TRequestEvent;
     92    FSessionStorage: THTTPSessionStorage;
    9193    FShowExceptions: Boolean;
    9294    procedure SetShowExceptions(const AValue: Boolean);
    9395  public
    94     Name: string;
    95     DocumentRoot: string;
    96     SessionStorage: THTTPSessionStorage;
    97     ShowExceptions: Boolean;
    9896    procedure Run; virtual;
    9997    procedure ErrorResponse(HandlerData: THTTPHandlerData);
    10098    procedure FileResponse(HandlerData: THTTPHandlerData);
    10199    procedure ServerInfo(HandlerData: THTTPHandlerData); virtual;
    102     constructor Create;
     100    constructor Create(AOwner: TComponent); override;
    103101    destructor Destroy; override;
     102  published
     103    property ShowExceptions: Boolean read FShowExceptions write SetShowExceptions;
     104    property DocumentRoot: string read FDocumentRoot write FDocumentRoot;
     105    property SessionStorage: THTTPSessionStorage read FSessionStorage
     106      write FSessionStorage;
    104107    property OnRequest: TRequestEvent read FOnRequest write FOnRequest;
    105     property ShowExceptions: Boolean read FShowExceptions write SetShowExceptions;
    106108  end;
    107109
     
    200202end;
    201203
    202 constructor THTTPServer.Create;
    203 begin
     204constructor THTTPServer.Create(AOwner: TComponent);
     205begin
     206  inherited;
    204207  ShowExceptions := False;
    205208  DocumentRoot := './';
    206   Name := 'THTTPServer';
    207209end;
    208210
    209211destructor THTTPServer.Destroy;
    210212begin
    211   SessionStorage.Free;
    212213  inherited Destroy;
    213214end;
     
    351352constructor THTTPSessionStorage.Create;
    352353begin
    353 
     354  inherited;
    354355end;
    355356
  • Network/CoolWeb/WebServer/UHTTPServerCGI.pas

    r104 r237  
    1616    EnvVars: TStringList;
    1717    procedure Run; override;
    18     constructor Create;
     18    constructor Create(AOwner: TComponent); override;
    1919    destructor Destroy; override;
    2020    procedure ServerInfo(HandlerData: THTTPHandlerData); override;
    2121  end;
     22
     23
     24procedure Register;
    2225
    2326implementation
     
    2629  SEnvironmentVariables = 'Environment variables:';
    2730
     31procedure Register;
     32begin
     33  RegisterComponents('CoolWeb', [THTTPServerCGI]);
     34end;
     35
     36
    2837{ THTTPServerCGI }
    2938
    30 constructor THTTPServerCGI.Create;
     39constructor THTTPServerCGI.Create(AOwner: TComponent);
    3140begin
    3241  inherited;
  • Network/CoolWeb/WebServer/UHTTPServerTCP.pas

    r94 r237  
    1414  THTTPServerTCP = class(THTTPServer)
    1515  private
     16    FMaxConnection: Integer;
    1617    procedure HandleClient(Sender: TObject);
    1718  public
    1819    Socket: TTCPServer;
    19     MaxConnection: Integer;
    2020    RequestHandlerList: TRequestHandlerList;
    21     constructor Create;
     21    constructor Create(AOwner: TComponent); override;
    2222    destructor Destroy; override;
     23  published
     24    property MaxConnection: Integer read FMaxConnection write FMaxConnection;
    2325  end;
     26
     27procedure Register;
    2428
    2529implementation
    2630
     31procedure Register;
     32begin
     33  RegisterComponents('CoolWeb', [THTTPServerTCP]);
     34end;
     35
    2736procedure THTTPServerTCP.HandleClient(Sender: TObject);
    2837var
    29   RequestHandler: TRequestHandler;
    3038  Line: string;
    3139  LineIndex: Integer;
     
    119127{ THTTPServerTCP }
    120128
    121 constructor THTTPServerTCP.Create;
     129constructor THTTPServerTCP.Create(AOwner: TComponent);
    122130begin
    123131  inherited;
  • Network/CoolWeb/WebServer/UHTTPSessionFile.pas

    r94 r237  
    1414  THTTPSessionStorageFile = class(THTTPSessionStorage)
    1515  private
     16    FDirectory: string;
     17    FSessionIdCookieName: string;
     18    FTimeout: Integer;
    1619    Lock: TCriticalSection;
    1720    function GetNewSessionId: string;
    1821    procedure GetSessionId(HandlerData: THTTPHandlerData);
    1922  public
    20     Timeout: Integer; // in seconds
    21     Directory: string;
    22     SessionIdCookieName: string;
    2323    Sessions: TStringList;
    2424    procedure Load(HandlerData: THTTPHandlerData); override;
    2525    procedure Save(HandlerData: THTTPHandlerData); override;
    26     constructor Create; override;
     26    constructor Create(AOwner: TComponent); override;
    2727    destructor Destroy; override;
     28  published
     29    property Timeout: Integer read FTimeout write FTimeout; // in seconds
     30    property Directory: string read FDirectory write FDirectory;
     31    property SessionIdCookieName: string read FSessionIdCookieName
     32      write FSessionIdCookieName;
    2833  end;
    2934
     35procedure Register;
     36
    3037implementation
     38
     39procedure Register;
     40begin
     41  RegisterComponents('CoolWeb', [THTTPSessionStorageFile]);
     42end;
     43
    3144
    3245{ THTTPSession }
     
    88101end;
    89102
    90 constructor THTTPSessionStorageFile.Create;
     103constructor THTTPSessionStorageFile.Create(AOwner: TComponent);
    91104begin
    92   inherited Create;
     105  inherited;
    93106  Lock := TCriticalSection.Create;
    94107  Sessions := TStringList.Create;
  • Network/CoolWeb/WebServer/UHTTPSessionMySQL.pas

    r94 r237  
    1212  { TFileHTTPSessionStorage }
    1313
     14  { THTTPSessionStorageMySQL }
     15
    1416  THTTPSessionStorageMySQL = class(THTTPSessionStorage)
    1517  private
     18    FSessionIdCookieName: string;
     19    FTimeout: Integer;
    1620    Lock: TCriticalSection;
    1721    function GetNewSessionId: string;
    1822    procedure GetSessionId(HandlerData: THTTPHandlerData);
    1923  public
    20     Timeout: Integer; // in seconds
    2124    SqlDatabase: TSqlDatabase;
    22     SessionIdCookieName: string;
    2325    Sessions: TStringList;
    2426    procedure Load(HandlerData: THTTPHandlerData); override;
    2527    procedure Save(HandlerData: THTTPHandlerData); override;
    26     constructor Create; override;
     28    constructor Create(AOwner: TComponent); override;
    2729    destructor Destroy; override;
     30  published
     31    property Timeout: Integer read FTimeout write FTimeout; // in seconds
     32    property SessionIdCookieName: string read FSessionIdCookieName
     33      write FSessionIdCookieName;
    2834  end;
    2935
     36procedure Register;
     37
    3038implementation
     39
     40procedure Register;
     41begin
     42  RegisterComponents('CoolWeb', [THTTPSessionStorageMySQL]);
     43end;
     44
    3145
    3246{ THTTPSession }
     
    110124end;
    111125
    112 constructor THTTPSessionStorageMySQL.Create;
     126constructor THTTPSessionStorageMySQL.Create(AOwner: TComponent);
    113127begin
    114   inherited Create;
     128  inherited;
    115129  Lock := TCriticalSection.Create;
    116130  Sessions := TStringList.Create;
Note: See TracChangeset for help on using the changeset viewer.