mirror of
https://github.com/moparisthebest/Simba
synced 2024-12-24 08:18:52 -05:00
Made the "Forgot to free" message universal. Delete the newinternets.pas.
git-svn-id: http://www.villavu.com/repositories/merlijn/mufasa@539 3f818213-9676-44b0-a9b4-5e4c4e03d09d
This commit is contained in:
parent
87c496ca85
commit
db241061dd
@ -81,6 +81,7 @@ begin
|
|||||||
if HTTPClients[index] = nil then
|
if HTTPClients[index] = nil then
|
||||||
raise exception.CreateFmt('FreeHTTPClient: Trying to free an index(%d) that is already freed',[index]);
|
raise exception.CreateFmt('FreeHTTPClient: Trying to free an index(%d) that is already freed',[index]);
|
||||||
THTTPClient(HTTPClients[index]).Free;
|
THTTPClient(HTTPClients[index]).Free;
|
||||||
|
HTTPClients[index] := nil;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
constructor TMInternet.Create(Owner: TObject);
|
constructor TMInternet.Create(Owner: TObject);
|
||||||
@ -97,10 +98,16 @@ var
|
|||||||
begin
|
begin
|
||||||
for i := Connections.Count -1 downto 0 do
|
for i := Connections.Count -1 downto 0 do
|
||||||
if Connections[i] <> nil then
|
if Connections[i] <> nil then
|
||||||
|
begin
|
||||||
TObject(Connections[i]).Free;
|
TObject(Connections[i]).Free;
|
||||||
|
Writeln(Format('Connection[%d] has not been freed in the script, freeing it now.',[i]));
|
||||||
|
end;
|
||||||
for i := HTTPClients.Count -1 downto 0 do
|
for i := HTTPClients.Count -1 downto 0 do
|
||||||
if HTTPClients[i] <> nil then
|
if HTTPClients[i] <> nil then
|
||||||
|
begin
|
||||||
THTTPClient(HTTPClients[i]).Free;
|
THTTPClient(HTTPClients[i]).Free;
|
||||||
|
Writeln(Format('HTTPClient[%d] has not been freed in the script, freeing it now.',[i]));
|
||||||
|
end;
|
||||||
Connections.Free;
|
Connections.Free;
|
||||||
HTTPClients.Free;
|
HTTPClients.Free;
|
||||||
inherited Destroy;
|
inherited Destroy;
|
||||||
|
@ -1,305 +0,0 @@
|
|||||||
unit newinternets;
|
|
||||||
|
|
||||||
{$mode objfpc}{$H+}
|
|
||||||
|
|
||||||
interface
|
|
||||||
|
|
||||||
uses
|
|
||||||
Classes, SysUtils;
|
|
||||||
|
|
||||||
type
|
|
||||||
{
|
|
||||||
Record to hold the information of a $_POST variable and value.
|
|
||||||
}
|
|
||||||
TPostVariable = record
|
|
||||||
variable, value: String;
|
|
||||||
end;
|
|
||||||
|
|
||||||
{
|
|
||||||
Store the internet connection information
|
|
||||||
}
|
|
||||||
TInternetConnection = class(TObject)
|
|
||||||
protected
|
|
||||||
//url of the connection
|
|
||||||
ConnURL: String;
|
|
||||||
//contains post paramaters and vars
|
|
||||||
PostVars: TList;
|
|
||||||
private
|
|
||||||
function createPostVariable(variable, value: String): TPostVariable;
|
|
||||||
public
|
|
||||||
constructor Create(URL: String);
|
|
||||||
destructor Destroy; override;
|
|
||||||
|
|
||||||
//$_POST variable functions for PHP transmission
|
|
||||||
procedure AddPostVariable(theVar, theValue: String);
|
|
||||||
procedure DelPostVariable(theVar: String);
|
|
||||||
procedure ReplacePostVariable(searchVar, replaceVar, value: String);
|
|
||||||
function PostHTTP(out dataStream: TStream): Boolean;
|
|
||||||
end;
|
|
||||||
|
|
||||||
TMufasaInternet = class(TObject)
|
|
||||||
protected
|
|
||||||
// TList storing all of the connection infos
|
|
||||||
ConnList : TList;
|
|
||||||
|
|
||||||
public
|
|
||||||
function ConnectionOpen(URL: String): Integer;
|
|
||||||
function ConnectionClose(ConnInd: Integer): Boolean;
|
|
||||||
destructor Destroy; override;
|
|
||||||
|
|
||||||
//$_POST variable functions for PHP
|
|
||||||
procedure AddPostVariable(connInd: Integer; theVar, theValue: String);
|
|
||||||
procedure DelPostVariable(connInd: Integer; theVar: String);
|
|
||||||
procedure ReplacePostVariable(connInd: Integer; searchVar, replaceVar, value: String);
|
|
||||||
function PostHTTP(connInd: Integer; out dataStream: TStream): Boolean;
|
|
||||||
end;
|
|
||||||
|
|
||||||
function GetPage(URL: String): String;
|
|
||||||
|
|
||||||
implementation
|
|
||||||
uses
|
|
||||||
httpsend, synacode;
|
|
||||||
|
|
||||||
|
|
||||||
function replace(sStr, rStr, iStr: String): String;
|
|
||||||
var
|
|
||||||
ind: Integer;
|
|
||||||
begin
|
|
||||||
ind := Pos(sStr, iStr);
|
|
||||||
while (ind <> 0) do
|
|
||||||
begin
|
|
||||||
Delete(iStr, ind, Length(sStr));
|
|
||||||
Insert(rStr, iStr, ind);
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
{ TInternetConnection }
|
|
||||||
|
|
||||||
procedure TInternetConnection.Create(URL: String);
|
|
||||||
begin
|
|
||||||
inherited;
|
|
||||||
Self.ConnURL := EncodeURL(URL);
|
|
||||||
Self.PostVars.Create;
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TInternetConnection.Destroy; overload;
|
|
||||||
begin
|
|
||||||
inherited;
|
|
||||||
// ADD CLOSING OF CONNECTION
|
|
||||||
|
|
||||||
// Clear it up
|
|
||||||
PostVars.Clear;
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TInternetConnect.AddPostVariable(theVar, theValue: String);
|
|
||||||
var
|
|
||||||
currentIndex: Integer;
|
|
||||||
begin
|
|
||||||
theVar := EncodeURLElement(theVar);
|
|
||||||
theValue := EncodeURLElement(theValue);
|
|
||||||
Self.PostVars.Add(createPostVariable(theVar, theValue));
|
|
||||||
{ with Self do
|
|
||||||
begin
|
|
||||||
|
|
||||||
|
|
||||||
if (FreeSpotsHigh = -1) then
|
|
||||||
begin
|
|
||||||
setLength(PostVars, PostVarsHigh + 2);
|
|
||||||
inc(PostVarsHigh);
|
|
||||||
currentIndex := PostVarsHigh;
|
|
||||||
end else
|
|
||||||
begin
|
|
||||||
currentIndex := PostFreeSpots[FreeSpotsHigh];
|
|
||||||
dec(FreeSpotsHigh);
|
|
||||||
end;
|
|
||||||
PostVars[currentIndex].variable := theVar;
|
|
||||||
PostVars[currentIndex].value := theValue;
|
|
||||||
|
|
||||||
end; }
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TInternetConnection.DelPostVariable(theVar: String);
|
|
||||||
var
|
|
||||||
i: Integer;
|
|
||||||
tempPostVar: TPostVariable;
|
|
||||||
begin
|
|
||||||
for i := (Self.PostVars.Count - 1) downto 0 do
|
|
||||||
begin
|
|
||||||
if (theVar = Self.PostVars.Items[i].variable) then
|
|
||||||
begin
|
|
||||||
tempPostVar := PostVars.Items[i];
|
|
||||||
Self.PostVars.Remove(tempPostVar);
|
|
||||||
break;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TInternetConnection.ReplacePostVariable(searchVar, replaceVar, theValue: String);
|
|
||||||
var
|
|
||||||
i: Integer;
|
|
||||||
tempPostVar: TPostVariable;
|
|
||||||
begin
|
|
||||||
with Self do
|
|
||||||
begin
|
|
||||||
for i := (PostVars.Count - 1) downto 0 do
|
|
||||||
begin
|
|
||||||
tempPostVar := PostVars.Items[i];
|
|
||||||
if (searchVar = tempPostVar.variable) then
|
|
||||||
begin
|
|
||||||
tempPostVar.variable := replaceVar;
|
|
||||||
tempPostVar.value := theValue;
|
|
||||||
break;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
function TInternetConnection.PostHTTP(out dataStream: TStream): Boolean;
|
|
||||||
var
|
|
||||||
// holds the vars when they are placed together
|
|
||||||
URLData: String;
|
|
||||||
tempPostVar: TPostVariable;
|
|
||||||
begin
|
|
||||||
try
|
|
||||||
with Self do
|
|
||||||
begin
|
|
||||||
//ADD Connection stuffs
|
|
||||||
|
|
||||||
for i := (PostVars.Count - 1) downto 0 do
|
|
||||||
begin
|
|
||||||
tempPostVar := PostVars.Items[i];
|
|
||||||
if (tempPostVar.variable <> '') then
|
|
||||||
begin
|
|
||||||
URLData := URLData + format('%d=%d+', [tempPostVar.variable,
|
|
||||||
tempPostVar.value]);
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
Delete(URLData, Length(URLData) - 1, 1);
|
|
||||||
|
|
||||||
{I DONT KNOW (TStream), this should work since we don't reuse it after.}
|
|
||||||
dataStream := TStream.Create;
|
|
||||||
HttpPostURL(ConnURL, URLData, dataStream);
|
|
||||||
|
|
||||||
// Lets remove all Post Variable data so fresh start next time.
|
|
||||||
PostVars.Clear;
|
|
||||||
end;
|
|
||||||
except
|
|
||||||
raise Exception.createFMT('TInternetConnection.PostHTTP: Something went wrong, could not complete. URL: %d', URLData);
|
|
||||||
exit(false);
|
|
||||||
end;
|
|
||||||
result := true;
|
|
||||||
end;
|
|
||||||
|
|
||||||
{ TMufasaInternet }
|
|
||||||
|
|
||||||
{
|
|
||||||
Allocate space in the ConnArray, then open the connection.
|
|
||||||
}
|
|
||||||
function TMufasaInternet.ConnectionOpen(URL: String): Integer;
|
|
||||||
var
|
|
||||||
currentIndex: Integer;
|
|
||||||
begin
|
|
||||||
try
|
|
||||||
Result := Self.ConnList.Add(TInternetConnection.Create(URL));
|
|
||||||
except
|
|
||||||
raise Exception.createFMT('TInternetArray.ConnectionClose: Could not close connection %d URL: %d',
|
|
||||||
[theInd, ConnURL]);
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
{
|
|
||||||
Close the connection, add the index to the FreeSpots.
|
|
||||||
}
|
|
||||||
function TMufasaInternet.ConnectionClose(theInd: Integer): Boolean;
|
|
||||||
var
|
|
||||||
tempConn: TInternetConnection;
|
|
||||||
begin
|
|
||||||
try
|
|
||||||
tempConn := Self.ConnList.Items[theInd];
|
|
||||||
Self.ConnList.Remove(tempConn);
|
|
||||||
tempConn.Destroy;
|
|
||||||
{
|
|
||||||
with Self do
|
|
||||||
begin
|
|
||||||
ConnArray[theInd].Destroy;
|
|
||||||
if (FreeSpotsHigh = FreeSpotsLen) then
|
|
||||||
begin
|
|
||||||
FreeSpotsLen := FreeSpotsLen + 1;
|
|
||||||
setLength(FreeSpots, FreeSpotsLen);
|
|
||||||
end;
|
|
||||||
FreeSpots[FreeSpotsHigh] := theInd;
|
|
||||||
end; }
|
|
||||||
except
|
|
||||||
raise Exception.createFMT('TInternetArray.ConnectionClose: Could not close connection %d URL: %d',
|
|
||||||
[theInd, ConnList.Items[theInd].ConnURL]);
|
|
||||||
exit(false);
|
|
||||||
end;
|
|
||||||
result := True;
|
|
||||||
end;
|
|
||||||
|
|
||||||
{
|
|
||||||
Wrapper for the TInternetConnection.PostVariableAdd procedure which accepts
|
|
||||||
a connection index.
|
|
||||||
}
|
|
||||||
procedure TMufasaInternet.PostVariableAdd(connInd: Integer; theVar, theValue: String);
|
|
||||||
begin
|
|
||||||
try
|
|
||||||
ConnList.Items[commInd].PostVariableAdd(theVar, theValue);
|
|
||||||
except
|
|
||||||
raise Exception.createFMT('TInternetArray.PostVariableAdd: %d is not in the ConnArray',
|
|
||||||
[connInd]);
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
{
|
|
||||||
Wrapper for the TInternetConnection.PostVariableDel procedure which accepts
|
|
||||||
a connection index.
|
|
||||||
}
|
|
||||||
procedure TMufasaInternet.PostVariableDel(connInd: Integer; theVar: String);
|
|
||||||
begin
|
|
||||||
try
|
|
||||||
ConnList.Items[commInd].PostVariableAdd(theVar);
|
|
||||||
except
|
|
||||||
raise Exception.createFMT('TInternetArray.PostVariableDel: %d is not in the ConnArray',
|
|
||||||
[connInd]);
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
{
|
|
||||||
Wrapper for the TInternetConnection.PostVariableReplace procedure which accepts
|
|
||||||
a connection index.
|
|
||||||
}
|
|
||||||
procedure TMufasaInternet.PostVariableReplace(connInd: Integer; searchVar, replaceVar, value: String);
|
|
||||||
begin
|
|
||||||
try
|
|
||||||
ConnList.Items[commInd].PostVariableAdd(searchVar, replaceVar, value);
|
|
||||||
except
|
|
||||||
raise Exception.createFMT('TInternetArray.PostVariableReplace: %d is not in the ConnArray',
|
|
||||||
[connInd]);
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
function TMufasaInternet.PostHTTP(connInd: Integer; out dataStream: TStream): Boolean;
|
|
||||||
begin
|
|
||||||
try
|
|
||||||
result := ConnList.Items[commInd].PostHTTP(dataStream);
|
|
||||||
except
|
|
||||||
raise Exception.createFMT('TInternetArray.PostHTTP: %d is not in the ConnArray',
|
|
||||||
[connInd]);
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
{ OTHER }
|
|
||||||
function GetPage(URL: String): String;
|
|
||||||
var
|
|
||||||
s: TStringList;
|
|
||||||
begin
|
|
||||||
s:=TStringList.Create;
|
|
||||||
HttpGetText(URL, s);
|
|
||||||
result := String(s.GetText);
|
|
||||||
s.Free;
|
|
||||||
end;
|
|
||||||
|
|
||||||
end.
|
|
||||||
|
|
||||||
|
|
@ -122,7 +122,7 @@ begin;
|
|||||||
For I := 0 To High(MFiles) Do
|
For I := 0 To High(MFiles) Do
|
||||||
If MFiles[i].FS <> nil Then
|
If MFiles[i].FS <> nil Then
|
||||||
Begin
|
Begin
|
||||||
WriteLn('You forgot to free a file... (Path = ' + MFiles[i].Path + ')');
|
Writeln(Format('File[%s] has not been freed in the script, freeing it now.',[MFiles[i].Path]));
|
||||||
Try
|
Try
|
||||||
MFiles[I].FS.Free;
|
MFiles[I].FS.Free;
|
||||||
Except
|
Except
|
||||||
|
Loading…
Reference in New Issue
Block a user