Skip to content

Commit

Permalink
Ftp
Browse files Browse the repository at this point in the history
  • Loading branch information
deadalnix committed Jan 23, 2012
1 parent 516b673 commit dc811a0
Show file tree
Hide file tree
Showing 5 changed files with 359 additions and 185 deletions.
3 changes: 2 additions & 1 deletion include/dsfml/network/CMakeLists.txt
Expand Up @@ -4,7 +4,8 @@ set(SRCROOT ${CMAKE_SOURCE_DIR}/src/dsfml/network)
# all source files
set(SRC
${SRCROOT}/all.d
${INCROOT}/ftp.d
${SRCROOT}/ftp.d
${SRCROOT}/Ftp.cpp
${INCROOT}/http.d
${SRCROOT}/ipaddress.d
${SRCROOT}/IpAddress.cpp
Expand Down
184 changes: 0 additions & 184 deletions include/dsfml/network/ftp.d

This file was deleted.

14 changes: 14 additions & 0 deletions patches/SFML/System/PointerProvider.hpp
@@ -0,0 +1,14 @@
namespace sf {

// Ensure that Enumeration have a known size.
template<class T> struct PointerProvider {
PointerProvider(T t)
: item(t)
{}

private:
T item;
};

}

73 changes: 73 additions & 0 deletions src/dsfml/network/Ftp.cpp
@@ -0,0 +1,73 @@
#include<SFML/Network/Ftp.hpp>
#include<SFML/Network/IpAddress.hpp>
#include<SFML/System/Enumeration.hpp>
#include<SFML/System/PointerProvider.hpp>
#include<new>

typedef sf::Ftp::Response sfFtpResponse;

sfFtpResponse* sfFtpResponse_Create(unsigned int code, const char* message, size_t length) {
return new sfFtpResponse(sf::Enumeration<sf::Ftp::Response::Status, unsigned int>(code), std::string(message, length));
}

void sfFtpResponse_Destroy(sfFtpResponse* response) {
delete response;
}

bool sfFtpResponse_IsOk(const sfFtpResponse* response) {
return response->IsOk();
}

unsigned int sfFtpResponse_GetStatus(const sfFtpResponse* response) {
return response->GetStatus();
}

const char* sfFtpResponse_GetMessage(const sfFtpResponse* response) {
return response->GetMessage().c_str();
}

typedef sf::Ftp::DirectoryResponse sfFtpDirectoryResponse;

void sfFtpDirectoryResponse_Destroy(sfFtpDirectoryResponse* directoryResponse) {
delete directoryResponse;
}

const char* sfFtpDirectoryResponse_GetDirectory(const sfFtpDirectoryResponse* directoryResponse) {
return directoryResponse->GetDirectory().c_str();
}

typedef sf::Ftp::ListingResponse sfFtpListingResponse;

void sfFtpListingResponse_Destroy(sfFtpListingResponse* listingResponse) {
delete listingResponse;
}

typedef sf::Ftp sfFtp;

void sfFtp_Create(sfFtp* ftp) {
new(ftp) sfFtp();
}

void sfFtp_Destroy(sfFtp* ftp) {
ftp->~sfFtp();
}

typedef sf::Time sfTime;
typedef sf::IpAddress sfIpAddress;

sfFtpResponse* sfFtp_Connect(sfFtp* ftp, sfIpAddress server, unsigned short port, sfTime timeout) {
return reinterpret_cast<sfFtpResponse*>(new sf::PointerProvider<sfFtpResponse>(ftp->Connect(server, port, timeout)));
}

sfFtpResponse* sfFtp_Disconnect(sfFtp* ftp) {
return reinterpret_cast<sfFtpResponse*>(new sf::PointerProvider<sfFtpResponse>(ftp->Disconnect()));
}

sfFtpResponse* sfFtp_Login(sfFtp* ftp) {
return reinterpret_cast<sfFtpResponse*>(new sf::PointerProvider<sfFtpResponse>(ftp->Login()));
}

sfFtpResponse* sfFtp_Login(sfFtp* ftp, const char* userName, size_t userNameLength, const char* password, size_t passwordLength) {
return reinterpret_cast<sfFtpResponse*>(new sf::PointerProvider<sfFtpResponse>(ftp->Login(std::string(userName, userNameLength), std::string(password, passwordLength))));
}

0 comments on commit dc811a0

Please sign in to comment.