Ignore:
Timestamp:
Sep 13, 2010, 11:20:24 AM (14 years ago)
Author:
george
Message:
  • Přidáno: Druhá varianta projektu pro sestavení TCP serveru.
  • Přidáno: Vlastní obsluha vyjímek a zobrazení ve HTTP tvaru.
  • Opraveno: Zpracování session třídy THTTPSessionStorageMySQL.
Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

    • Property svn:ignore
      •  

        old new  
        22UConfig.pas
        33bin
         4lib
  • trunk/WebServer/UHTTPSessionMySQL.pas

    r32 r33  
    1212  { TFileHTTPSessionStorage }
    1313
    14   TMySQLHTTPSessionStorage = class(THTTPSessionStorage)
     14  THTTPSessionStorageMySQL = class(THTTPSessionStorage)
    1515  private
    1616    Lock: TCriticalSection;
     
    3232{ THTTPSession }
    3333
    34 function TMySQLHTTPSessionStorage.GetNewSessionId: string;
     34function THTTPSessionStorageMySQL.GetNewSessionId: string;
    3535var
    3636  DbRows: TDbRows;
     37  Found: Boolean;
    3738begin
    38   DbRows := nil;
    39   Result := BinToHexString(SHA1(FloatToStr(Now)));
    4039  repeat
    41     if Assigned(DbRows) then DbRows.Destroy;
    42     DbRows := SqlDatabase.Query('SELECT * FROM Session WHERE Identification="' +
    43       Result + '"');
    44     if DbRows.Count > 0 then Result := BinToHexString(SHA1(FloatToStr(Now)));
    45   until DbRows.Count > 0;
    46   DbRows.Destroy;
     40    Result := BinToHexString(SHA1(FloatToStr(Now)));
     41    try
     42      DbRows := SqlDatabase.Query('SELECT * FROM `HTTPSession` WHERE `Identification`="' +
     43        Result + '"');
     44      Found := DbRows.Count > 0;
     45    finally
     46      DbRows.Free;
     47    end;
     48  until not Found;
    4749end;
    4850
    49 procedure TMySQLHTTPSessionStorage.GetSessionId(HandlerData: THTTPHandlerData);
     51procedure THTTPSessionStorageMySQL.GetSessionId(HandlerData: THTTPHandlerData);
    5052begin
    5153  with HandlerData do begin
     
    5456    end else begin
    5557      SessionId := GetNewSessionId;
    56       Response.Cookies.Values[SessionIdCookieName] := SessionId;
    5758    end;
    5859  end;
    5960end;
    6061
    61 procedure TMySQLHTTPSessionStorage.Load(HandlerData: THTTPHandlerData);
     62procedure THTTPSessionStorageMySQL.Load(HandlerData: THTTPHandlerData);
    6263var
    6364  DbRows: TDbRows;
     
    6667  try
    6768    Lock.Acquire;
    68     DbRows := SqlDatabase.Query('SELECT * FROM Session WHERE Identification="' +
     69    DbRows := SqlDatabase.Query('SELECT * FROM `HTTPSession` WHERE `Identification`="' +
    6970      HandlerData.SessionId + '"');
    7071    if DbRows.Count > 0 then begin
     
    7374      HandlerData.SessionId := GetNewSessionId;
    7475    end;
    75     DbRows.Destroy;
    7676  finally
     77    DbRows.Free;
    7778    Lock.Release;
    7879  end;
     
    8081end;
    8182
    82 procedure TMySQLHTTPSessionStorage.Save(HandlerData: THTTPHandlerData);
     83procedure THTTPSessionStorageMySQL.Save(HandlerData: THTTPHandlerData);
    8384var
    8485  DbRows: TDbRows;
     
    8788  try
    8889    Lock.Acquire;
    89     DbRows := SqlDatabase.Query('SELECT * FROM Session WHERE Identification="' +
     90    DbRows := SqlDatabase.Query('SELECT * FROM `HTTPSession` WHERE `Identification`="' +
    9091      HandlerData.SessionId + '"');
    9192    if DbRows.Count > 0 then
    92       DbRows2 := SqlDatabase.Query('UPDATE Session SET Variables="' + HandlerData.Session.Text
    93         + '" WHERE Identification="' + HandlerData.SessionId + '"')
    94     else DbRows2 := SqlDatabase.Query('REPLACE Session SET Variables="' + HandlerData.Session.Text
    95         + '" WHERE Identification="' + HandlerData.SessionId + '"');
    96     DbRows2.Destroy;
    97     DbRows.Destroy;
     93      DbRows2 := SqlDatabase.Query('UPDATE `HTTPSession` SET `Variables`="' + HandlerData.Session.Text
     94        + '" WHERE `Identification`="' + HandlerData.SessionId + '", `Time` = NOW()')
     95    else DbRows2 := SqlDatabase.Query('INSERT INTO `HTTPSession` (`Time`,  `Variables`, `Identification`) VALUES (' +
     96    'NOW(), "' + HandlerData.Session.Text + '", "' + HandlerData.SessionId + '")');
    9897    HandlerData.Response.Cookies.Values[SessionIdCookieName] := HandlerData.SessionId;
    9998  finally
     99    DbRows2.Free;
     100    DbRows.Free;
    100101    Lock.Release;
    101102  end;
     
    103104end;
    104105
    105 constructor TMySQLHTTPSessionStorage.Create;
     106constructor THTTPSessionStorageMySQL.Create;
    106107begin
    107108  inherited Create;
     
    109110  Sessions := TStringList.Create;
    110111  SessionIdCookieName := 'SessionId';
    111   SqlDatabase := TSqlDatabase.Create;
    112112  Timeout := 3600;
    113113end;
    114114
    115 destructor TMySQLHTTPSessionStorage.Destroy;
     115destructor THTTPSessionStorageMySQL.Destroy;
    116116begin
    117   SqlDatabase.Destroy;
    118   Sessions.Destroy;
    119   Lock.Destroy;
     117  Sessions.Free;
     118  Lock.Free;
    120119  inherited Destroy;
    121120end;
Note: See TracChangeset for help on using the changeset viewer.