-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix incorrect free calls in FTP/HTTP responses
The memory is inside the object and has to be freed using destroy instead. New FTP test/example (to be used in RosettaCode.org)
- Loading branch information
Showing
10 changed files
with
91 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
GNATdoc.Index = { | ||
"project": "ASFML", | ||
"timestamp": "2024-05-25 18:48:10" | ||
"timestamp": "2024-05-31 22:38:31" | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
.PHONY: all clean run | ||
|
||
all: | ||
gprbuild | ||
|
||
clean: | ||
gprclean | ||
|
||
run: | ||
./main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
with Ada.Text_IO; | ||
with Sf.Network.Ftp; | ||
with Sf.Network.IpAddress; | ||
with Sf.System.Time; | ||
|
||
procedure Main is | ||
use Sf; use Sf.Network; use Sf.Network.Ftp; | ||
FTP_Error : exception; | ||
|
||
FTP_Object : constant sfFtp_Ptr := create; | ||
|
||
procedure Check_Response (FTP_Response : sfFtpResponse_Ptr) is | ||
Message : constant String := Response.getMessage (FTP_Response); | ||
begin | ||
Response.destroy (FTP_Response); | ||
if not Response.isOk (FTP_Response) then | ||
raise FTP_Error with Message; | ||
else | ||
Ada.Text_IO.Put_Line ("OK: " & Message); | ||
end if; | ||
end Check_Response; | ||
|
||
procedure List_Directory (Path : String) is | ||
Response : sfFtpListingResponse_Ptr; | ||
begin | ||
Response := getDirectoryListing (FTP_Object, Path); | ||
if ListingResponse.isOk (Response) then | ||
for Index in 0 .. ListingResponse.getCount (Response) - 1 loop | ||
Ada.Text_IO.Put_Line (ListingResponse.getName (Response, Index)); | ||
end loop; | ||
else | ||
Ada.Text_IO.Put_Line (ListingResponse.getMessage (Response)); | ||
end if; | ||
ListingResponse.destroy (Response); | ||
end List_Directory; | ||
|
||
begin | ||
|
||
Check_Response | ||
(connect (FTP_Object, | ||
server => IpAddress.fromString ("speedtest.tele2.net"), | ||
port => 21, | ||
timeout => Sf.System.Time.sfSeconds (30.0))); | ||
|
||
Check_Response (loginAnonymous (FTP_Object)); | ||
|
||
Check_Response (changeDirectory (FTP_Object, "/upload")); | ||
Check_Response (changeDirectory (FTP_Object, "/")); | ||
|
||
List_Directory ("."); | ||
|
||
Check_Response (download (FTP_Object, | ||
remoteFile => "100KB.zip", | ||
localPath => ".", | ||
mode => sfFtpBinary)); | ||
destroy (FTP_Object); | ||
end Main; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
with "../../asfml.gpr"; | ||
|
||
project Main is | ||
|
||
for Create_Missing_Dirs use "True"; | ||
|
||
for Source_Dirs use ("."); | ||
for Object_Dir use "obj"; | ||
for Main use ("main.adb"); | ||
for Exec_Dir use "."; | ||
|
||
end Main; |