Changeset 33
- Timestamp:
- Sep 13, 2010, 11:20:24 AM (14 years ago)
- Location:
- trunk
- Files:
-
- 8 added
- 3 deleted
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:ignore
-
old new 2 2 UConfig.pas 3 3 bin 4 lib
-
- Property svn:ignore
-
trunk/Application/UUser.pas
r32 r33 1 1 unit UUser; 2 2 3 {$mode delphi}3 {$mode Delphi}{$H+} 4 4 5 5 interface 6 6 7 7 uses 8 Classes, SysUtils, USqlDatabase, UCGIApplication;8 Classes, SysUtils, synacode, USqlDatabase, UCommon, UHTTPServer; 9 9 10 10 type 11 TSQLUserList = class 11 EDuplicateItem = class(Exception); 12 ENotFound = class(Exception); 13 14 { TWebUser } 15 16 TWebUser = class 12 17 Database: TSqlDatabase; 18 HandlerData: THTTPHandlerData; 19 procedure Delete(Id: Integer); 20 procedure Add(Name, Password, Email: string); 21 function GetIdByName(Name: string): Integer; 22 function GetIdByNamePassword(Name: string; PassWord: string): Integer; 13 23 end; 14 24 15 TUser = class25 { TWebOnlineUser } 16 26 17 end; 18 19 { TSQLOnlineUser } 20 21 TSQLOnlineUser = class 27 TWebOnlineUser = class 22 28 Database: TSqlDatabase; 29 HandlerData: THTTPHandlerData; 23 30 Id: Integer; 24 31 User: Integer; 25 CGI: TCGIApplication;26 procedure Login(Name, Password: string);27 function Logout: string;28 32 procedure Update; 33 procedure Login(User: Integer); 34 procedure Logout; 29 35 end; 30 36 31 37 implementation 32 38 33 { TSQLOnlineUser } 39 resourcestring 40 SDuplicateUserItem = 'User name already used.'; 34 41 35 procedure TSQLOnlineUser.Login(Name, Password: string); 42 { TOnlineUser } 43 44 procedure TWebOnlineUser.Update; 45 var 46 DbRows: TDbRows; 47 Id: Integer; 48 begin 49 DbRows := Database.Query('SELECT * FROM `UserOnline` WHERE `SessionId`="' + 50 HandlerData.Request.Cookies.Values['SessionId'] + '"'); 51 if DbRows.Count > 0 then begin 52 // Update exited 53 Id := StrToInt(DbRows[0].Values['Id']); 54 DbRows.Free; 55 DbRows := Database.Query('UPDATE `UserOnline` SET `ActivityTime` = NOW() WHERE `Id`=' + IntToStr(Id)); 56 end else begin 57 // Create new record 58 DbRows.Free; 59 DbRows := Database.Query('INSERT INTO `UserOnline` (`User`, `ActivityTime`, `SessionId`) ' + 60 'VALUES (1, NOW(), "' + HandlerData.Request.Cookies.Values['SessionId'] + '")'); 61 Id := Database.LastInsertId; 62 end; 63 DbRows.Destroy; 64 end; 65 66 procedure TWebOnlineUser.Login(User: Integer); 36 67 var 37 68 DbRows: TDbRows; 38 69 begin 39 70 Logout; 40 try 41 DbRows := Database.Query('UPDATE `UserOnline` SET `User` = ' + IntToStr(User) + ', `LoginTime` = NOW() WHERE `SessionId`="' + 42 CGI.Cookies.Values['SessionId'] + '"'); 43 finally 44 DbRows.Free; 45 end; 71 DbRows := Database.Query('UPDATE `UserOnline` SET `User` = ' + IntToStr(User) + ', `LoginTime` = NOW() WHERE `SessionId`="' + 72 HandlerData.Request.Cookies.Values['SessionId'] + '"'); 73 DbRows.Destroy; 46 74 Self.User := User; 47 75 end; 48 76 49 function TSQLOnlineUser.Logout: string;77 procedure TWebOnlineUser.Logout; 50 78 var 51 79 DbRows: TDbRows; … … 53 81 if Id = 1 then Update; 54 82 if User <> 1 then begin 55 try 56 DbRows := Database.Query('UPDATE `UserOnline` SET `User` = 1 WHERE `SessionId`="' + 57 CGI.Cookies.Values['SessionId'] + '"'); 58 finally 59 DbRows.Free; 60 end; 83 DbRows := Database.Query('UPDATE `UserOnline` SET `User` = 1 WHERE `SessionId`="' + 84 HandlerData.Request.Cookies.Values['SessionId'] + '"'); 85 DbRows.Destroy; 61 86 User := 1; 62 87 end; 63 88 end; 64 89 65 procedure TSQLOnlineUser.Update; 90 { TUser } 91 92 procedure TWebUser.Delete(Id: Integer); 66 93 begin 94 Database.Query('DELETE FROM `User` WHERE `Id`=' + IntToStr(Id)); 95 end; 67 96 97 procedure TWebUser.Add(Name, Password, Email: string); 98 var 99 Salt: string; 100 DbRows: TDbRows; 101 begin 102 DbRows := Database.Query('SELECT `Id` FROM `User` WHERE `Name`="' + Name + '"'); 103 try 104 if DbRows.Count = 0 then begin 105 Salt := EncodeBase64(Copy(BinToHexString(SHA1(FloatToStr(Now))), 1, 8)); 106 Database.Query('INSERT INTO `User` (`Name`, `Password`, `Salt`, `Email`, `RegistrationTime`) VALUES ("' + 107 Name + '", SHA1(CONCAT("' + Password + '", "' + Salt + '")), "' + Salt + 108 '", "' + Email + '", NOW())'); 109 end else raise EDuplicateItem.Create(SDuplicateUserItem); 110 finally 111 DbRows.Destroy; 112 end; 113 end; 114 115 function TWebUser.GetIdByName(Name: string): Integer; 116 var 117 DbRows: TDbRows; 118 begin 119 DbRows := Database.Query('SELECT `Id` FROM `User` WHERE `Name`="' + Name + '"'); 120 try 121 if DbRows.Count = 1 then Result := StrToInt(DbRows[0].ValuesAtIndex[0]) 122 else raise ENotFound.Create('User "' + Name + '" not found'); 123 finally 124 DBRows.Destroy; 125 end; 126 end; 127 128 function TWebUser.GetIdByNamePassword(Name: string; PassWord: string): Integer; 129 var 130 DbRows: TDbRows; 131 begin 132 DbRows := Database.Query('SELECT `Id` FROM `User` WHERE `Name`="' + Name + '" AND ' + 133 '`Password` = SHA1(CONCAT("' + Password + '", Salt))'); 134 try 135 if DbRows.Count = 1 then Result := StrToInt(DbRows[0].ValuesAtIndex[0]) 136 else raise ENotFound.Create('User "' + Name + '" not found'); 137 finally 138 DBRows.Destroy; 139 end; 68 140 end; 69 141 -
trunk/Common/USqlDatabase.pas
r25 r33 52 52 function GetLastErrorMessage: string; 53 53 function GetLastErrorNumber: Integer; 54 function CheckError: Boolean;55 54 function GetCharset: string; 56 55 procedure SetDatabase(const Value: string); … … 91 90 implementation 92 91 93 uses DateUtils, Math; 92 uses 93 DateUtils, Math; 94 95 resourcestring 96 SDatabaseQueryError = 'Database query error: "%s"'; 94 97 95 98 const … … 172 175 FSession := NewSession; 173 176 end else FConnected := False; 174 CheckError; 175 Rows := Query('SET NAMES ' + Encoding); 176 Rows.Free; 177 178 if LastErrorNumber <> 0 then 179 raise EQueryError.Create(Format(SDatabaseQueryError, [LastErrorMessage])); 180 181 try 182 Rows := Query('SET NAMES ' + Encoding); 183 finally 184 Rows.Free; 185 end; 177 186 end; 178 187 … … 197 206 System.Delete(DbNames, 1, 1); 198 207 System.Delete(DbValues, 1, 1); 199 DbResult := Query('INSERT INTO `' + Table + '` (' + DbNames + ') VALUES (' + DbValues + ')'); 200 DbResult.Free; 208 try 209 DbResult := Query('INSERT INTO `' + Table + '` (' + DbNames + ') VALUES (' + DbValues + ')'); 210 finally 211 DbResult.Free; 212 end; 201 213 end; 202 214 … … 210 222 RepeatLastAction := False; 211 223 LastQuery := Data; 212 //if not Connected then NastaveniPripojeni.ShowModal;213 224 Result := TDbRows.Create; 214 //repeat215 225 mysql_query(FSession, PChar(Data)); 216 //until not217 CheckError;218 //if not CheckError then219 begin 220 221 222 223 224 225 226 227 228 229 226 if LastErrorNumber <> 0 then begin 227 raise EQueryError.Create(Format(SDatabaseQueryError, [Data])); 228 end; 229 230 DbResult := mysql_store_result(FSession); 231 if Assigned(DbResult) then begin 232 Result.Count := mysql_num_rows(DbResult); 233 for I := 0 to Result.Count - 1 do begin 234 DbRow := mysql_fetch_row(DbResult); 235 Result[I] := TAssociativeArray.Create; 236 with Result[I] do begin 237 for II := 0 to mysql_num_fields(DbResult) - 1 do begin 238 Add(mysql_fetch_field_direct(DbResult, II)^.Name + 239 NameValueSeparator + PChar((DbRow + II)^)); 230 240 end; 231 241 end; 232 242 end; 233 end;234 243 end; 235 244 mysql_free_result(DbResult); 236 (*237 if Assigned(DatabaseIntegrity) then238 with DatabaseIntegrity do if not Checking then begin239 Check;240 DebugLog('Database integrity: Unreferenced='+IntToStr(Unreferenced)+' BadReferences='+IntToStr(BadReferences));241 end;242 *)243 245 end; 244 246 … … 263 265 System.Delete(DbNames, 1, 1); 264 266 System.Delete(DbValues, 1, 1); 265 DbResult := Query('REPLACE INTO `' + Table + '` (' + DbNames + ') VALUES (' + DbValues + ')'); 266 DbResult.Free; 267 try 268 DbResult := Query('REPLACE INTO `' + Table + '` (' + DbNames + ') VALUES (' + DbValues + ')'); 269 finally 270 DbResult.Free; 271 end; 267 272 end; 268 273 … … 270 275 begin 271 276 Table := ATable; 272 Result := Query('SELECT ' + Filter + ' FROM `' + Table + '` WHERE ' +Condition);277 Result := Query('SELECT ' + Filter + ' FROM `' + Table + '` WHERE ' + Condition); 273 278 end; 274 279 … … 289 294 end; 290 295 System.Delete(DbValues, 1, 1); 291 DbResult := Query('UPDATE `' + Table + '` SET (' + DbValues + ') WHERE ' + Condition); 292 DbResult.Free; 296 try 297 DbResult := Query('UPDATE `' + Table + '` SET (' + DbValues + ') WHERE ' + Condition); 298 finally 299 DbResult.Free; 300 end; 293 301 end; 294 302 … … 303 311 begin 304 312 Table := ATable; 305 DbResult := Query('DELETE FROM `' + Table + '` WHERE ' + Condition); 306 DbResult.Free; 313 try 314 DbResult := Query('DELETE FROM `' + Table + '` WHERE ' + Condition); 315 finally 316 DbResult.Free; 317 end; 307 318 end; 308 319 … … 338 349 begin 339 350 Result := mysql_errno(FSession); 340 end;341 342 function TSqlDatabase.CheckError: Boolean;343 begin344 Result := LastErrorNumber <> 0;345 if Result then346 raise EQueryError.Create('Database query error: "' + LastErrorMessage + '"');347 351 end; 348 352 -
trunk/Pages/UMainPage.pas
r27 r33 6 6 7 7 uses 8 Classes, SysUtils, USqlDatabase, UCore, UCustomCGIApplication, UHtmlClasses; 9 10 procedure Links(App: TCustomCGIApplication); 11 procedure History(App: TCustomCGIApplication); 12 procedure Internet(App: TCustomCGIApplication); 13 procedure VoIP(App: TCustomCGIApplication); 14 procedure Hosting(App: TCustomCGIApplication); 15 procedure About(App: TCustomCGIApplication); 16 procedure Documents(App: TCustomCGIApplication); 17 procedure Contact(App: TCustomCGIApplication); 8 Classes, SysUtils, USqlDatabase, UCore, UCustomApplication, UHtmlClasses, 9 UHTTPServer; 10 11 procedure Links(App: TCustomApplication; HandlerData: THTTPHandlerData); 12 procedure History(App: TCustomApplication; HandlerData: THTTPHandlerData); 13 procedure Internet(App: TCustomApplication; HandlerData: THTTPHandlerData); 14 procedure VoIP(App: TCustomApplication; HandlerData: THTTPHandlerData); 15 procedure Hosting(App: TCustomApplication; HandlerData: THTTPHandlerData); 16 procedure About(App: TCustomApplication; HandlerData: THTTPHandlerData); 17 procedure Documents(App: TCustomApplication; HandlerData: THTTPHandlerData); 18 procedure Contact(App: TCustomApplication; HandlerData: THTTPHandlerData); 19 procedure ServerInfo(App: TCustomApplication; HandlerData: THTTPHandlerData); 18 20 19 21 implementation 20 22 21 procedure Links(App: TCustom CGIApplication);23 procedure Links(App: TCustomApplication; HandlerData: THTTPHandlerData); 22 24 begin 23 25 App.HtmlDocument.Title := 'Odkazy'; … … 65 67 end; 66 68 67 procedure History(App: TCustom CGIApplication);69 procedure History(App: TCustomApplication; HandlerData: THTTPHandlerData); 68 70 var 69 71 DbRows: TDbRows; … … 90 92 end; 91 93 92 procedure Internet(App: TCustom CGIApplication);94 procedure Internet(App: TCustomApplication; HandlerData: THTTPHandlerData); 93 95 begin 94 96 with App do begin … … 116 118 end; 117 119 118 procedure VoIP(App: TCustom CGIApplication);120 procedure VoIP(App: TCustomApplication; HandlerData: THTTPHandlerData); 119 121 begin 120 122 with App do begin … … 150 152 end; 151 153 152 procedure Hosting(App: TCustom CGIApplication);154 procedure Hosting(App: TCustomApplication; HandlerData: THTTPHandlerData); 153 155 var 154 156 I: Integer; … … 183 185 end; 184 186 185 procedure About(App: TCustom CGIApplication);187 procedure About(App: TCustomApplication; HandlerData: THTTPHandlerData); 186 188 var 187 189 TextBlock: THtmlString; … … 235 237 end; 236 238 237 procedure Documents(App: TCustom CGIApplication);239 procedure Documents(App: TCustomApplication; HandlerData: THTTPHandlerData); 238 240 begin 239 241 with App do begin … … 259 261 end; 260 262 261 procedure Contact(App: TCustom CGIApplication);263 procedure Contact(App: TCustomApplication; HandlerData: THTTPHandlerData); 262 264 begin 263 265 App.HtmlDocument.Title := 'Kontakt'; … … 275 277 end; 276 278 279 procedure ServerInfo(App: TCustomApplication; HandlerData: THTTPHandlerData); 280 begin 281 HandlerData.Session.Values['Test'] := 'Tst'; 282 App.HTTPServer.ServerInfo(HandlerData); 283 end; 284 277 285 end. 278 286 -
trunk/WebServer/UHTTPServer.pas
r32 r33 89 89 private 90 90 FOnRequest: TRequestEvent; 91 FShowExceptions: Boolean; 92 procedure SetShowExceptions(const AValue: Boolean); 91 93 public 92 94 Name: string; 93 95 DocumentRoot: string; 94 96 SessionStorage: THTTPSessionStorage; 97 ShowExceptions: Boolean; 98 procedure Run; virtual; 95 99 procedure ErrorResponse(HandlerData: THTTPHandlerData); 96 procedure Run; virtual;97 100 procedure FileResponse(HandlerData: THTTPHandlerData); 101 procedure ServerInfo(HandlerData: THTTPHandlerData); virtual; 98 102 constructor Create; 99 103 destructor Destroy; override; 100 104 property OnRequest: TRequestEvent read FOnRequest write FOnRequest; 101 end; 105 property ShowExceptions: Boolean read FShowExceptions write SetShowExceptions; 106 end; 107 108 procedure HTTPExceptionShow(Obj: TObject; Addr: Pointer; FrameCount: Longint; Frames: PPointer); 109 procedure HTTPExceptionHide(Obj: TObject; Addr: Pointer; FrameCount: Longint; Frames: PPointer); 110 102 111 103 112 resourcestring … … 109 118 { THTTPServer } 110 119 120 procedure THTTPServer.ServerInfo(HandlerData: THTTPHandlerData); 121 var 122 I: Integer; 123 begin 124 with HandlerData, Response.Stream do begin 125 //Response.Cookies.Values['Test'] := 'Halo'; 126 //Response.Cookies.Values['Test2'] := 'Halo2'; 127 128 //HTTPServer.SessionHandler.Variables.Values['Session1'] := 'Value1'; 129 //HTTPServer.SessionHandler.Variables.Values['Session2'] := 'Value2'; 130 131 WriteString('<a href="?ServerInfo">Refresh</a>'); 132 133 WriteString('<h5>Request HTTP headers</h5>'); 134 for I := 0 to Request.Headers.Count - 1 do begin; 135 WriteString(Request.Headers.Strings[I] + '<br/>'); 136 end; 137 138 WriteString('<h5>Request HTTP cookies</h5>'); 139 for I := 0 to Request.Cookies.Count - 1 do begin; 140 WriteString(Request.Cookies.Strings[I] + '<br/>'); 141 end; 142 143 WriteString('Session id: ' + SessionId); 144 WriteString('<h5>Session variables</h5>'); 145 for I := 0 to Session.Count - 1 do begin; 146 WriteString(Session.Strings[I] + '<br/>'); 147 end; 148 149 WriteString('<h5>Response HTTP headers</h5>'); 150 with Response.Stream do 151 for I := 0 to Response.Headers.Count - 1 do begin; 152 WriteString(Response.Headers.Strings[I] + '<br/>'); 153 end; 154 155 WriteString('<h5>Response HTTP cookies</h5>'); 156 for I := 0 to Response.Cookies.Count - 1 do begin; 157 WriteString(Response.Cookies.Strings[I] + '<br/>'); 158 end; 159 end; 160 end; 161 111 162 procedure THTTPServer.ErrorResponse(HandlerData: THTTPHandlerData); 112 163 begin … … 114 165 WriteString('<html><body>Page ' + Request.Path + ' not found.</body></html>'); 115 166 end; 167 end; 168 169 procedure THTTPServer.SetShowExceptions(const AValue: Boolean); 170 begin 171 FShowExceptions := AValue; 172 if AValue then ExceptProc := HTTPExceptionShow 173 else ExceptProc := HTTPExceptionHide; 116 174 end; 117 175 … … 314 372 end; 315 373 374 procedure HTTPExceptionShow(Obj: TObject; Addr: Pointer; FrameCount: Longint; Frames: PPointer); 375 type 376 TArrayOfPointer = array of Pointer; 377 var 378 Message: string; 379 i: LongInt; 380 hstdout: ^Text; 381 begin 382 hstdout := @stdout; 383 WriteLn(hstdout^, 'Content-type: text/html'); 384 WriteLn(hstdout^); 385 Writeln(hstdout^, 'An unhandled exception occurred at $', HexStr(PtrUInt(Addr), SizeOf(PtrUInt) * 2), ' :'); 386 if Obj is exception then 387 begin 388 Message := Exception(Obj).ClassName + ' : ' + Exception(Obj).Message; 389 Writeln(hstdout^, Message); 390 end 391 else 392 Writeln(hstdout^, 'Exception object ', Obj.ClassName, ' is not of class Exception.'); 393 Writeln(hstdout^, BackTraceStrFunc(Addr)); 394 if (FrameCount > 0) then 395 begin 396 for i := 0 to FrameCount - 1 do 397 Writeln(hstdout^, BackTraceStrFunc(TArrayOfPointer(Frames)[i])); 398 end; 399 Writeln(hstdout^,''); 400 end; 401 402 procedure HTTPExceptionHide(Obj: TObject; Addr: Pointer; FrameCount: Longint; Frames: PPointer); 403 type 404 TArrayOfPointer = array of Pointer; 405 var 406 Message: string; 407 i: LongInt; 408 hstdout: ^Text; 409 hstderr: ^Text; 410 begin 411 hstdout := @stdout; 412 hstderr := @stderr; 413 WriteLn(hstdout^, 'Content-type: text/html'); 414 WriteLn(hstdout^); 415 WriteLn(hstdout^, 'Error occured during page generation.'); 416 Writeln(hstderr^, 'An unhandled exception occurred at $', HexStr(PtrUInt(Addr), SizeOf(PtrUInt) * 2), ' :'); 417 if Obj is exception then 418 begin 419 Message := Exception(Obj).ClassName + ' : ' + Exception(Obj).Message; 420 Writeln(hstderr^, Message); 421 end 422 else 423 Writeln(hstderr^, 'Exception object ', Obj.ClassName, ' is not of class Exception.'); 424 Writeln(hstderr^, BackTraceStrFunc(Addr)); 425 if (FrameCount > 0) then 426 begin 427 for i := 0 to FrameCount - 1 do 428 Writeln(hstderr^, BackTraceStrFunc(TArrayOfPointer(Frames)[i])); 429 end; 430 Writeln(hstderr^,''); 431 end; 432 316 433 end. 317 434 -
trunk/WebServer/UHTTPServerCGI.pas
r32 r33 18 18 constructor Create; 19 19 destructor Destroy; override; 20 procedure S ysInfo;20 procedure ServerInfo(HandlerData: THTTPHandlerData); override; 21 21 end; 22 22 … … 50 50 51 51 // Process cookies 52 if Request.Headers.IndexOfName('Cookie') <> -1 then53 Request.Cookies.Parse( Request.Headers.Values['Cookie']);52 if EnvVars.IndexOfName('HTTP_COOKIE') <> -1 then 53 Request.Cookies.Parse(EnvVars.Values['HTTP_COOKIE']); 54 54 55 55 // Parse query string … … 64 64 Length(EnvVars.Values['REQUEST_URI']))); 65 65 66 // Load session variables 67 if Assigned(SessionStorage) then 68 SessionStorage.Load(HandlerData); 69 66 70 Response.Stream.Clear; 67 71 Response.Headers.Values['Content-type'] := 'text/html'; 68 72 73 // Execute content handler 69 74 if Assigned(OnRequest) then OnRequest(HandlerData) 70 75 else raise EEmptyHTTPHandler.Create(SEmptyHTTPHandler); 71 76 77 // Store session variables 78 if Assigned(SessionStorage) then 79 SessionStorage.Save(HandlerData); 80 72 81 with Response do begin 82 // Generate cookies 83 for I := 0 to Cookies.Count - 1 do 84 Headers.Add('Set-Cookie' + Headers.NameValueSeparator + Cookies.Names[I] + '=' + Cookies.ValueFromIndex[I]); 85 // + ';path=/;expires=' + RFC822DateTime(Now); 86 73 87 // Generate headers 74 88 for I := 0 to Headers.Count - 1 do begin 75 89 WriteLn(Headers.Names[I] + ': ' + Headers.ValueFromIndex[I]); 76 90 end; 77 78 // Generate cookies79 for I := 0 to Cookies.Count - 1 do80 Headers.Add('Set-Cookie' + Headers.NameValueSeparator + Cookies.Names[I] + '=' + Cookies.ValueFromIndex[I]);81 // + ';path=/;expires=' + RFC822DateTime(Now);82 91 83 92 WriteLn; // Empty line header separator … … 92 101 end; 93 102 94 procedure THTTPServerCGI.S ysInfo;103 procedure THTTPServerCGI.ServerInfo(HandlerData: THTTPHandlerData); 95 104 var 96 105 I: Integer; 97 106 begin 98 (* Output.Add('<h4>Environment variables:</h4>'); 99 Output.Add('<table border="1">'); 100 for I := 0 to EnvVars.Count - 1 do begin 101 Output.Add('<tr><td>' + EnvVars.Names[I] + '</td><td>' + 102 EnvVars.ValueFromIndex[I] + '</td></tr>'); 107 inherited; 108 with HandlerData, Response.Stream do begin 109 WriteString('<h5>Environment variables:</h5>'); 110 WriteString('<table border="1">'); 111 for I := 0 to EnvVars.Count - 1 do begin 112 WriteString('<tr><td>' + EnvVars.Names[I] + '</td><td>' + 113 EnvVars.ValueFromIndex[I] + '</td></tr>'); 114 end; 115 WriteString('</table>'); 103 116 end; 104 Output.Add('</table>');*)105 117 end; 106 118 -
trunk/WebServer/UHTTPSessionFile.pas
r32 r33 10 10 type 11 11 12 { T FileHTTPSessionStorage }12 { THTTPSessionStorageFile } 13 13 14 T FileHTTPSessionStorage = class(THTTPSessionStorage)14 THTTPSessionStorageFile = class(THTTPSessionStorage) 15 15 private 16 16 Lock: TCriticalSection; … … 32 32 { THTTPSession } 33 33 34 function T FileHTTPSessionStorage.GetNewSessionId: string;34 function THTTPSessionStorageFile.GetNewSessionId: string; 35 35 begin 36 36 Result := BinToHexString(SHA1(FloatToStr(Now))); … … 39 39 end; 40 40 41 procedure T FileHTTPSessionStorage.GetSessionId(HandlerData: THTTPHandlerData);41 procedure THTTPSessionStorageFile.GetSessionId(HandlerData: THTTPHandlerData); 42 42 begin 43 43 with HandlerData do begin … … 51 51 end; 52 52 53 procedure T FileHTTPSessionStorage.Load(HandlerData: THTTPHandlerData);53 procedure THTTPSessionStorageFile.Load(HandlerData: THTTPHandlerData); 54 54 var 55 55 SessionFile: string; … … 68 68 end; 69 69 70 procedure T FileHTTPSessionStorage.Save(HandlerData: THTTPHandlerData);70 procedure THTTPSessionStorageFile.Save(HandlerData: THTTPHandlerData); 71 71 var 72 72 SessionFile: string; … … 88 88 end; 89 89 90 constructor T FileHTTPSessionStorage.Create;90 constructor THTTPSessionStorageFile.Create; 91 91 begin 92 92 inherited Create; … … 98 98 end; 99 99 100 destructor T FileHTTPSessionStorage.Destroy;100 destructor THTTPSessionStorageFile.Destroy; 101 101 begin 102 102 Sessions.Destroy; -
trunk/WebServer/UHTTPSessionMySQL.pas
r32 r33 12 12 { TFileHTTPSessionStorage } 13 13 14 T MySQLHTTPSessionStorage= class(THTTPSessionStorage)14 THTTPSessionStorageMySQL = class(THTTPSessionStorage) 15 15 private 16 16 Lock: TCriticalSection; … … 32 32 { THTTPSession } 33 33 34 function T MySQLHTTPSessionStorage.GetNewSessionId: string;34 function THTTPSessionStorageMySQL.GetNewSessionId: string; 35 35 var 36 36 DbRows: TDbRows; 37 Found: Boolean; 37 38 begin 38 DbRows := nil;39 Result := BinToHexString(SHA1(FloatToStr(Now)));40 39 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; 47 49 end; 48 50 49 procedure T MySQLHTTPSessionStorage.GetSessionId(HandlerData: THTTPHandlerData);51 procedure THTTPSessionStorageMySQL.GetSessionId(HandlerData: THTTPHandlerData); 50 52 begin 51 53 with HandlerData do begin … … 54 56 end else begin 55 57 SessionId := GetNewSessionId; 56 Response.Cookies.Values[SessionIdCookieName] := SessionId;57 58 end; 58 59 end; 59 60 end; 60 61 61 procedure T MySQLHTTPSessionStorage.Load(HandlerData: THTTPHandlerData);62 procedure THTTPSessionStorageMySQL.Load(HandlerData: THTTPHandlerData); 62 63 var 63 64 DbRows: TDbRows; … … 66 67 try 67 68 Lock.Acquire; 68 DbRows := SqlDatabase.Query('SELECT * FROM Session WHERE Identification="' +69 DbRows := SqlDatabase.Query('SELECT * FROM `HTTPSession` WHERE `Identification`="' + 69 70 HandlerData.SessionId + '"'); 70 71 if DbRows.Count > 0 then begin … … 73 74 HandlerData.SessionId := GetNewSessionId; 74 75 end; 75 DbRows.Destroy;76 76 finally 77 DbRows.Free; 77 78 Lock.Release; 78 79 end; … … 80 81 end; 81 82 82 procedure T MySQLHTTPSessionStorage.Save(HandlerData: THTTPHandlerData);83 procedure THTTPSessionStorageMySQL.Save(HandlerData: THTTPHandlerData); 83 84 var 84 85 DbRows: TDbRows; … … 87 88 try 88 89 Lock.Acquire; 89 DbRows := SqlDatabase.Query('SELECT * FROM Session WHERE Identification="' +90 DbRows := SqlDatabase.Query('SELECT * FROM `HTTPSession` WHERE `Identification`="' + 90 91 HandlerData.SessionId + '"'); 91 92 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 + '")'); 98 97 HandlerData.Response.Cookies.Values[SessionIdCookieName] := HandlerData.SessionId; 99 98 finally 99 DbRows2.Free; 100 DbRows.Free; 100 101 Lock.Release; 101 102 end; … … 103 104 end; 104 105 105 constructor T MySQLHTTPSessionStorage.Create;106 constructor THTTPSessionStorageMySQL.Create; 106 107 begin 107 108 inherited Create; … … 109 110 Sessions := TStringList.Create; 110 111 SessionIdCookieName := 'SessionId'; 111 SqlDatabase := TSqlDatabase.Create;112 112 Timeout := 3600; 113 113 end; 114 114 115 destructor T MySQLHTTPSessionStorage.Destroy;115 destructor THTTPSessionStorageMySQL.Destroy; 116 116 begin 117 SqlDatabase.Destroy; 118 Sessions.Destroy; 119 Lock.Destroy; 117 Sessions.Free; 118 Lock.Free; 120 119 inherited Destroy; 121 120 end; -
trunk/languages/index.cs.po
r32 r33 10 10 "Content-Transfer-Encoding: 8bit\n" 11 11 12 #: ucustomapplication.spagenotfound 13 msgctxt "ucustomapplication.spagenotfound" 14 msgid "Page not found" 15 msgstr "Stránka nenalezena" 16 12 17 #: ucustomcgiapplication.spagenotfound 18 msgctxt "ucustomcgiapplication.spagenotfound" 13 19 msgid "Page not found" 14 20 msgstr "Stránka nenalezena" … … 32 38 msgstr "" 33 39 40 #: usqldatabase.sdatabasequeryerror 41 msgid "Database query error: \"%s\"" 42 msgstr "" 43 44 #: uuser.sduplicateuseritem 45 msgid "User name already used." 46 msgstr "" 47 -
trunk/languages/index.po
r32 r33 2 2 msgstr "Content-Type: text/plain; charset=UTF-8" 3 3 4 #: ucustomapplication.spagenotfound 5 msgctxt "ucustomapplication.spagenotfound" 6 msgid "Page not found" 7 msgstr "" 8 4 9 #: ucustomcgiapplication.spagenotfound 10 msgctxt "ucustomcgiapplication.spagenotfound" 5 11 msgid "Page not found" 6 12 msgstr "" … … 24 30 msgstr "" 25 31 32 #: usqldatabase.sdatabasequeryerror 33 msgid "Database query error: \"%s\"" 34 msgstr "" 35 36 #: uuser.sduplicateuseritem 37 msgid "User name already used." 38 msgstr "" 39
Note:
See TracChangeset
for help on using the changeset viewer.