Added the trunk/branches/tags directories at repository root, and moved previous root into trunk/

git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/trunk@1002 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
laurentgom 2009-01-28 16:18:34 +00:00
commit 2f524481c1
974 changed files with 295448 additions and 0 deletions

View file

@ -0,0 +1,486 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2008 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_FTP_H
#define SFML_FTP_H
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Config.h>
#include <SFML/Network/IPAddress.h>
////////////////////////////////////////////////////////////
/// Enumerate all the FTP file transfer modes
////////////////////////////////////////////////////////////
enum sfFtpTransferMode
{
sfFtpBinary, ///< Binary mode (file is transfered as a sequence of bytes)
sfFtpAscii, ///< Text mode using ASCII encoding
sfFtpEbcdic ///< Text mode using EBCDIC encoding
};
////////////////////////////////////////////////////////////
/// Enumerate all the valid status codes returned in
/// a FTP response
////////////////////////////////////////////////////////////
enum sfFtpStatus
{
// 1xx: the requested action is being initiated,
// expect another reply before proceeding with a new command
sfFtpRestartMarkerReply = 110, ///< Restart marker reply
sfFtpServiceReadySoon = 120, ///< Service ready in N minutes
sfFtpDataConnectionAlreadyOpened = 125, ///< Data connection already opened, transfer starting
sfFtpOpeningDataConnection = 150, ///< File status ok, about to open data connection
// 2xx: the requested action has been successfully completed
sfFtpOk = 200, ///< Command ok
sfFtpPointlessCommand = 202, ///< Command not implemented
sfFtpSystemStatus = 211, ///< System status, or system help reply
sfFtpDirectoryStatus = 212, ///< Directory status
sfFtpFileStatus = 213, ///< File status
sfFtpHelpMessage = 214, ///< Help message
sfFtpSystemType = 215, ///< NAME system type, where NAME is an official system name from the list in the Assigned Numbers document
sfFtpServiceReady = 220, ///< Service ready for new user
sfFtpClosingConnection = 221, ///< Service closing control connection
sfFtpDataConnectionOpened = 225, ///< Data connection open, no transfer in progress
sfFtpClosingDataConnection = 226, ///< Closing data connection, requested file action successful
sfFtpEnteringPassiveMode = 227, ///< Entering passive mode
sfFtpLoggedIn = 230, ///< User logged in, proceed. Logged out if appropriate
sfFtpFileActionOk = 250, ///< Requested file action ok
sfFtpDirectoryOk = 257, ///< PATHNAME created
// 3xx: the command has been accepted, but the requested action
// is dormant, pending receipt of further information
sfFtpNeedPassword = 331, ///< User name ok, need password
sfFtpNeedAccountToLogIn = 332, ///< Need account for login
sfFtpNeedInformation = 350, ///< Requested file action pending further information
// 4xx: the command was not accepted and the requested action did not take place,
// but the error condition is temporary and the action may be requested again
sfFtpServiceUnavailable = 421, ///< Service not available, closing control connection
sfFtpDataConnectionUnavailable = 425, ///< Can't open data connection
sfFtpTransferAborted = 426, ///< Connection closed, transfer aborted
sfFtpFileActionAborted = 450, ///< Requested file action not taken
sfFtpLocalError = 451, ///< Requested action aborted, local error in processing
sfFtpInsufficientStorageSpace = 452, ///< Requested action not taken; insufficient storage space in system, file unavailable
// 5xx: the command was not accepted and
// the requested action did not take place
sfFtpCommandUnknown = 500, ///< Syntax error, command unrecognized
sfFtpParametersUnknown = 501, ///< Syntax error in parameters or arguments
sfFtpCommandNotImplemented = 502, ///< Command not implemented
sfFtpBadCommandSequence = 503, ///< Bad sequence of commands
sfFtpParameterNotImplemented = 504, ///< Command not implemented for that parameter
sfFtpNotLoggedIn = 530, ///< Not logged in
sfFtpNeedAccountToStore = 532, ///< Need account for storing files
sfFtpFileUnavailable = 550, ///< Requested action not taken, file unavailable
sfFtpPageTypeUnknown = 551, ///< Requested action aborted, page type unknown
sfFtpNotEnoughMemory = 552, ///< Requested file action aborted, exceeded storage allocation
sfFtpFilenameNotAllowed = 553, ///< Requested action not taken, file name not allowed
// 10xx: SFML custom codes
sfFtpInvalidResponse = 1000, ///< Response is not a valid FTP one
sfFtpConnectionFailed = 1001, ///< Connection with server failed
sfFtpConnectionClosed = 1002, ///< Connection with server closed
sfFtpInvalidFile = 1003 ///< Invalid file to upload / download
};
////////////////////////////////////////////////////////////
/// sfFtpListingResponse wraps a FTP directory listing response,
/// which is basically :
/// - a status code
/// - a message
/// - a list of directory and files
////////////////////////////////////////////////////////////
typedef struct sfFtpListingResponse sfFtpListingResponse;
////////////////////////////////////////////////////////////
/// Destroy an existing Ftp listing response
///
/// \param FtpResponse : Ftp listing response to destroy
///
////////////////////////////////////////////////////////////
CSFML_API void sfFtpListingResponse_Destroy(sfFtpListingResponse* FtpListingResponse);
////////////////////////////////////////////////////////////
/// Convenience function to check if the response status code
/// means a success
///
/// \param FtpListingResponse : Ftp listing response
///
/// \return sfTrue if status is success (code < 400)
///
////////////////////////////////////////////////////////////
CSFML_API sfBool sfFtpListingResponse_IsOk(sfFtpListingResponse* FtpListingResponse);
////////////////////////////////////////////////////////////
/// Get the response status code
///
/// \param FtpListingResponse : Ftp listing response
///
/// \return Status code
///
////////////////////////////////////////////////////////////
CSFML_API sfFtpStatus sfFtpListingResponse_GetStatus(sfFtpListingResponse* FtpListingResponse);
////////////////////////////////////////////////////////////
/// Get the full message contained in the response
///
/// \param FtpListingResponse : Ftp listing response
///
/// \return The response message
///
////////////////////////////////////////////////////////////
CSFML_API const char* sfFtpListingResponse_GetMessage(sfFtpListingResponse* FtpListingResponse);
////////////////////////////////////////////////////////////
/// Get the number of filenames in the listing
///
/// \param FtpListingResponse : Ftp listing response
///
/// \return Total number of filenames
///
////////////////////////////////////////////////////////////
CSFML_API size_t sfFtpListingResponse_GetCount(sfFtpListingResponse* FtpListingResponse);
////////////////////////////////////////////////////////////
/// Get the Index-th filename in the directory
///
/// \param FtpListingResponse : Ftp listing response
/// \param Index : Index of the filename to get
///
/// \return Index-th filename
///
////////////////////////////////////////////////////////////
CSFML_API const char* sfFtpListingResponse_GetFilename(sfFtpListingResponse* FtpListingResponse, size_t Index);
////////////////////////////////////////////////////////////
/// sfFtpDirectoryResponse wraps a FTP directory response, which is basically :
/// - a status code
/// - a message
/// - a directory name
////////////////////////////////////////////////////////////
typedef struct sfFtpDirectoryResponse sfFtpDirectoryResponse;
////////////////////////////////////////////////////////////
/// Destroy an existing Ftp directory response
///
/// \param FtpDirectoryResponse : Ftp directory response to destroy
///
////////////////////////////////////////////////////////////
CSFML_API void sfFtpDirectoryResponse_Destroy(sfFtpDirectoryResponse* FtpDirectoryResponse);
////////////////////////////////////////////////////////////
/// Convenience function to check if the response status code
/// means a success
///
/// \param FtpDirectoryResponse : Ftp directory response
///
/// \return sfTrue if status is success (code < 400)
///
////////////////////////////////////////////////////////////
CSFML_API sfBool sfFtpDirectoryResponse_IsOk(sfFtpDirectoryResponse* FtpDirectoryResponse);
////////////////////////////////////////////////////////////
/// Get the response status code
///
/// \param FtpDirectoryResponse : Ftp directory response
///
/// \return Status code
///
////////////////////////////////////////////////////////////
CSFML_API sfFtpStatus sfFtpDirectoryResponse_GetStatus(sfFtpDirectoryResponse* FtpDirectoryResponse);
////////////////////////////////////////////////////////////
/// Get the full message contained in the response
///
/// \param FtpDirectoryResponse : Ftp directory response
///
/// \return The response message
///
////////////////////////////////////////////////////////////
CSFML_API const char* sfFtpDirectoryResponse_GetMessage(sfFtpDirectoryResponse* FtpDirectoryResponse);
////////////////////////////////////////////////////////////
/// Get the directory returned in the response
///
/// \param FtpDirectoryResponse : Ftp directory response
///
/// \return Directory name
///
////////////////////////////////////////////////////////////
CSFML_API const char* sfFtpDirectoryResponse_GetDirectory(sfFtpDirectoryResponse* FtpDirectoryResponse);
////////////////////////////////////////////////////////////
/// sfFtpResponse wraps a FTP response, which is basically :
/// - a status code
/// - a message
////////////////////////////////////////////////////////////
typedef struct sfFtpResponse sfFtpResponse;
////////////////////////////////////////////////////////////
/// Destroy an existing Ftp response
///
/// \param FtpResponse : Ftp response to destroy
///
////////////////////////////////////////////////////////////
CSFML_API void sfFtpResponse_Destroy(sfFtpResponse* FtpResponse);
////////////////////////////////////////////////////////////
/// Convenience function to check if the response status code
/// means a success
///
/// \param FtpResponse : Ftp response
///
/// \return sfTrue if status is success (code < 400)
///
////////////////////////////////////////////////////////////
CSFML_API sfBool sfFtpResponse_IsOk(sfFtpResponse* FtpResponse);
////////////////////////////////////////////////////////////
/// Get the response status code
///
/// \param FtpResponse : Ftp response
///
/// \return Status code
///
////////////////////////////////////////////////////////////
CSFML_API sfFtpStatus sfFtpResponse_GetStatus(sfFtpResponse* FtpResponse);
////////////////////////////////////////////////////////////
/// Get the full message contained in the response
///
/// \param FtpResponse : Ftp response
///
/// \return The response message
///
////////////////////////////////////////////////////////////
CSFML_API const char* sfFtpResponse_GetMessage(sfFtpResponse* FtpResponse);
////////////////////////////////////////////////////////////
/// sfFtp provides methods for manipulating the FTP
/// protocol (described in RFC 959).
/// It provides easy access and transfers to remote
/// directories and files on a FTP server
////////////////////////////////////////////////////////////
typedef struct sfFtp sfFtp;
////////////////////////////////////////////////////////////
/// Construct a new Ftp
///
/// \return Pointer to the new Ftp
///
////////////////////////////////////////////////////////////
CSFML_API sfFtp* sfFtp_Create();
////////////////////////////////////////////////////////////
/// Destroy an existing Ftp
///
/// \param Ftp : Ftp to destroy
///
////////////////////////////////////////////////////////////
CSFML_API void sfFtp_Destroy(sfFtp* Ftp);
////////////////////////////////////////////////////////////
/// Connect to the specified FTP server
///
/// \param Ftp : Ftp instance
/// \param Server : FTP server to connect to
/// \param Port : Port used for connection (21 by default, standard FTP port)
/// \param Timeout : Maximum time to wait (0 to use no timeout)
///
/// \return Server response to the request
///
////////////////////////////////////////////////////////////
CSFML_API sfFtpResponse* sfFtp_Connect(sfFtp* Ftp, sfIPAddress Server, unsigned short Port, float Timeout);
////////////////////////////////////////////////////////////
/// Log in using anonymous account
///
/// \param Ftp : Ftp instance
///
/// \return Server response to the request
///
////////////////////////////////////////////////////////////
CSFML_API sfFtpResponse* sfFtp_LoginAnonymous(sfFtp* Ftp);
////////////////////////////////////////////////////////////
/// Log in using a username and a password
///
/// \param Ftp : Ftp instance
/// \param UserName : User name
/// \param Password : Password
///
/// \return Server response to the request
///
////////////////////////////////////////////////////////////
CSFML_API sfFtpResponse* sfFtp_Login(sfFtp* Ftp, const char* UserName, const char* Password);
////////////////////////////////////////////////////////////
/// Close the connection with FTP server
///
/// \param Ftp : Ftp instance
///
/// \return Server response to the request
///
////////////////////////////////////////////////////////////
CSFML_API sfFtpResponse* sfFtp_Disconnect(sfFtp* Ftp);
////////////////////////////////////////////////////////////
/// Send a null command just to prevent from being disconnected
///
/// \param Ftp : Ftp instance
///
/// \return Server response to the request
///
////////////////////////////////////////////////////////////
CSFML_API sfFtpResponse* sfFtp_KeepAlive(sfFtp* Ftp);
////////////////////////////////////////////////////////////
/// Get the current working directory
///
/// \param Ftp : Ftp instance
///
/// \return Server response to the request
///
////////////////////////////////////////////////////////////
CSFML_API sfFtpDirectoryResponse* sfFtp_GetWorkingDirectory(sfFtp* Ftp);
////////////////////////////////////////////////////////////
/// Get the contents of the given directory
/// (subdirectories and files)
///
/// \param Ftp : Ftp instance
/// \param Directory : Directory to list ("" by default, the current one)
///
/// \return Server response to the request
///
////////////////////////////////////////////////////////////
CSFML_API sfFtpListingResponse* sfFtp_GetDirectoryListing(sfFtp* Ftp, const char* Directory);
////////////////////////////////////////////////////////////
/// Change the current working directory
///
/// \param Ftp : Ftp instance
/// \param Directory : New directory, relative to the current one
///
/// \return Server response to the request
///
////////////////////////////////////////////////////////////
CSFML_API sfFtpResponse* sfFtp_ChangeDirectory(sfFtp* Ftp, const char* Directory);
////////////////////////////////////////////////////////////
/// Go to the parent directory of the current one
///
/// \param Ftp : Ftp instance
///
/// \return Server response to the request
///
////////////////////////////////////////////////////////////
CSFML_API sfFtpResponse* sfFtp_ParentDirectory(sfFtp* Ftp);
////////////////////////////////////////////////////////////
/// Create a new directory
///
/// \param Ftp : Ftp instance
/// \param Name : Name of the directory to create
///
/// \return Server response to the request
///
////////////////////////////////////////////////////////////
CSFML_API sfFtpResponse* sfFtp_MakeDirectory(sfFtp* Ftp, const char* Name);
////////////////////////////////////////////////////////////
/// Remove an existing directory
///
/// \param Ftp : Ftp instance
/// \param Name : Name of the directory to remove
///
/// \return Server response to the request
///
////////////////////////////////////////////////////////////
CSFML_API sfFtpResponse* sfFtp_DeleteDirectory(sfFtp* Ftp, const char* Name);
////////////////////////////////////////////////////////////
/// Rename a file
///
/// \param Ftp : Ftp instance
/// \param File : File to rename
/// \param NewName : New name
///
/// \return Server response to the request
///
////////////////////////////////////////////////////////////
CSFML_API sfFtpResponse* sfFtp_RenameFile(sfFtp* Ftp, const char* File, const char* NewName);
////////////////////////////////////////////////////////////
/// Remove an existing file
///
/// \param Ftp : Ftp instance
/// \param Name : File to remove
///
/// \return Server response to the request
///
////////////////////////////////////////////////////////////
CSFML_API sfFtpResponse* sfFtp_DeleteFile(sfFtp* Ftp, const char* Name);
////////////////////////////////////////////////////////////
/// Download a file from the server
///
/// \param Ftp : Ftp instance
/// \param DistantFile : Path of the distant file to download
/// \param DestPath : Where to put to file on the local computer
/// \param Mode : Transfer mode (binary by default)
///
/// \return Server response to the request
///
////////////////////////////////////////////////////////////
CSFML_API sfFtpResponse* sfFtp_Download(sfFtp* Ftp, const char* DistantFile, const char* DestPath, sfFtpTransferMode Mode);
////////////////////////////////////////////////////////////
/// Upload a file to the server
///
/// \param Ftp : Ftp instance
/// \param LocalFile : Path of the local file to upload
/// \param DestPath : Where to put to file on the server
/// \param Mode : Transfer mode (binary by default)
///
/// \return Server response to the request
///
////////////////////////////////////////////////////////////
CSFML_API sfFtpResponse* sfFtp_Upload(sfFtp* Ftp, const char* LocalFile, const char* DestPath, sfFtpTransferMode Mode);
#endif // SFML_FTP_H

View file

@ -0,0 +1,282 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2008 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_HTTP_H
#define SFML_HTTP_H
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Config.h>
////////////////////////////////////////////////////////////
/// Enumerate the available HTTP methods for a request
////////////////////////////////////////////////////////////
enum sfHttpMethod
{
sfHttpGet, ///< Request in get mode, standard method to retrieve a page
sfHttpPost, ///< Request in post mode, usually to send data to a page
sfHttpHead ///< Request a page's header only
};
////////////////////////////////////////////////////////////
/// Enumerate all the valid status codes returned in
/// a HTTP response
////////////////////////////////////////////////////////////
enum sfHttpStatus
{
// 2xx: success
sfHttpOk = 200, ///< Most common code returned when operation was successful
sfHttpCreated = 201, ///< The resource has successfully been created
sfHttpAccepted = 202, ///< The request has been accepted, but will be processed later by the server
sfHttpNoContent = 204, ///< Sent when the server didn't send any data in return
// 3xx: redirection
sfHttpMultipleChoices = 300, ///< The requested page can be accessed from several locations
sfHttpMovedPermanently = 301, ///< The requested page has permanently moved to a new location
sfHttpMovedTemporarily = 302, ///< The requested page has temporarily moved to a new location
sfHttpNotModified = 304, ///< For conditionnal requests, means the requested page hasn't changed and doesn't need to be refreshed
// 4xx: client error
sfHttpBadRequest = 400, ///< The server couldn't understand the request (syntax error)
sfHttpUnauthorized = 401, ///< The requested page needs an authentification to be accessed
sfHttpForbidden = 403, ///< The requested page cannot be accessed at all, even with authentification
sfHttpNotFound = 404, ///< The requested page doesn't exist
// 5xx: server error
sfHttpInternalServerError = 500, ///< The server encountered an unexpected error
sfHttpNotImplemented = 501, ///< The server doesn't implement a requested feature
sfHttpBadGateway = 502, ///< The gateway server has received an error from the source server
sfHttpServiceNotAvailable = 503, ///< The server is temporarily unavailable (overloaded, in maintenance, ...)
// 10xx: SFML custom codes
sfHttpInvalidResponse = 1000, ///< Response is not a valid HTTP one
sfHttpConnectionFailed = 1001 ///< Connection with server failed
};
////////////////////////////////////////////////////////////
/// sfHttpRequest wraps an HTTP request, which is basically :
/// - a header with a method, a target URI, and a set of field/value pairs
/// - an optional body (for POST requests)
////////////////////////////////////////////////////////////
typedef struct sfHttpRequest sfHttpRequest;
////////////////////////////////////////////////////////////
/// Construct a new Http request
///
/// \return Pointer to the new Http request
///
////////////////////////////////////////////////////////////
CSFML_API sfHttpRequest* sfHttpRequest_Create();
////////////////////////////////////////////////////////////
/// Destroy an existing Http request
///
/// \param HttpRequest : Http request to destroy
///
////////////////////////////////////////////////////////////
CSFML_API void sfHttpRequest_Destroy(sfHttpRequest* HttpRequest);
////////////////////////////////////////////////////////////
/// Set the value of a field; the field is added if it doesn't exist
///
/// \param HttpRequest : Http request to modify
/// \param Field : Name of the field to set (case-insensitive)
/// \param Value : Value of the field
///
////////////////////////////////////////////////////////////
CSFML_API void sfHttpRequest_SetField(sfHttpRequest* HttpRequest, const char* Field, const char* Value);
////////////////////////////////////////////////////////////
/// Set the request method.
/// This parameter is sfHttpGet by default
///
/// \param HttpRequest : Http request to modify
/// \param RequestMethod : Method to use for the request
///
////////////////////////////////////////////////////////////
CSFML_API void sfHttpRequest_SetMethod(sfHttpRequest* HttpRequest, sfHttpMethod Method);
////////////////////////////////////////////////////////////
/// Set the target URI of the request.
/// This parameter is "/" by default
///
/// \param HttpRequest : Http request to modify
/// \param URI : URI to request, local to the host
///
////////////////////////////////////////////////////////////
CSFML_API void sfHttpRequest_SetURI(sfHttpRequest* HttpRequest, const char* URI);
////////////////////////////////////////////////////////////
/// Set the HTTP version of the request.
/// This parameter is 1.0 by default
///
/// \param HttpRequest : Http request to modify
/// \param Major : Major version number
/// \param Minor : Minor version number
///
////////////////////////////////////////////////////////////
CSFML_API void sfHttpRequest_SetHttpVersion(sfHttpRequest* HttpRequest, unsigned int Major, unsigned int Minor);
////////////////////////////////////////////////////////////
/// Set the body of the request. This parameter is optional and
/// makes sense only for POST requests.
/// This parameter is empty by default
///
/// \param HttpRequest : Http request to modify
/// \param Body : Content of the request body
///
////////////////////////////////////////////////////////////
CSFML_API void sfHttpRequest_SetBody(sfHttpRequest* HttpRequest, const char* Body);
////////////////////////////////////////////////////////////
/// sfHttpResponse wraps an HTTP response, which is basically :
/// - a header with a status code and a set of field/value pairs
/// - a body (the content of the requested resource)
////////////////////////////////////////////////////////////
typedef struct sfHttpResponse sfHttpResponse;
////////////////////////////////////////////////////////////
/// Destroy an existing Http response
///
/// \param HttpResponse : Http response to destroy
///
////////////////////////////////////////////////////////////
CSFML_API void sfHttpResponse_Destroy(sfHttpResponse* HttpResponse);
////////////////////////////////////////////////////////////
/// Get the value of a field; returns NULL if the field doesn't exist
///
/// \param HttpResponse : Http response
/// \param Field : Field to get
///
/// \return Value of the field (NULL if it doesn't exist)
///
////////////////////////////////////////////////////////////
CSFML_API const char* sfHttpResponse_GetField(sfHttpResponse* HttpResponse, const char* Field);
////////////////////////////////////////////////////////////
/// Get the status of a response
///
/// \param HttpResponse : Http response
///
/// \return Status of the response
///
////////////////////////////////////////////////////////////
CSFML_API sfHttpStatus sfHttpResponse_GetStatus(sfHttpResponse* HttpResponse);
////////////////////////////////////////////////////////////
/// Get the major HTTP version of a response
///
/// \param HttpResponse : Http response
///
/// \return HTTP major version of the response
///
////////////////////////////////////////////////////////////
CSFML_API unsigned int sfHttpResponse_GetMajorVersion(sfHttpResponse* HttpResponse);
////////////////////////////////////////////////////////////
/// Get the minor HTTP version of a response
///
/// \param HttpResponse : Http response
///
/// \return HTTP minor version of the response
///
////////////////////////////////////////////////////////////
CSFML_API unsigned int sfHttpResponse_GetMinorVersion(sfHttpResponse* HttpResponse);
////////////////////////////////////////////////////////////
/// Get the body of the response. The body can contain :
/// - the requested page (for GET requests)
/// - a response from the server (for POST requests)
/// - nothing (for HEAD requests)
/// - an error message (in case of an error)
///
/// \param HttpResponse : Http response
///
/// \return Body of the response (empty string if no body)
///
////////////////////////////////////////////////////////////
CSFML_API const char* sfHttpResponse_GetBody(sfHttpResponse* HttpResponse);
////////////////////////////////////////////////////////////
/// sfHttp provides methods for manipulating the HTTP
/// protocol (described in RFC 1945).
/// It can connect to a website, get its files, send requests, etc.
////////////////////////////////////////////////////////////
typedef struct sfHttp sfHttp;
////////////////////////////////////////////////////////////
/// Construct a new Http object
///
/// \return Pointer to the new Http
///
////////////////////////////////////////////////////////////
CSFML_API sfHttp* sfHttp_Create();
////////////////////////////////////////////////////////////
/// Destroy an existing Http object
///
/// \param Http : Http to destroy
///
////////////////////////////////////////////////////////////
CSFML_API void sfHttp_Destroy(sfHttp* Http);
////////////////////////////////////////////////////////////
/// Set the target host of a Http server
///
/// \param Http : Http object
/// \param Host : Web server to connect to
/// \param Port : Port to use for connection (0 to use the standard port of the protocol used)
///
////////////////////////////////////////////////////////////
CSFML_API void sfHttp_SetHost(sfHttp* Http, const char* Host, unsigned short Port);
////////////////////////////////////////////////////////////
/// Send a HTTP request and return the server's response.
/// You must be connected to a host before sending requests.
/// Any missing mandatory header field will be added with an appropriate value.
/// Warning : this function waits for the server's response and may
/// not return instantly; use a thread if you don't want to block your
/// application.
///
/// \param Http : Http object
/// \param Request : Request to send
/// \param Timeout : Maximum time to wait (0 to use no timeout)
///
/// \return Server's response, or NULL if request is invalid
///
////////////////////////////////////////////////////////////
CSFML_API sfHttpResponse* sfHttp_SendRequest(sfHttp* Http, sfHttpRequest* Request, float Timeout);
#endif // SFML_HTTP_H

View file

@ -0,0 +1,133 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2008 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_IPADDRESS_H
#define SFML_IPADDRESS_H
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Config.h>
////////////////////////////////////////////////////////////
/// sfIPAddress provides easy manipulation of IP v4 addresses
////////////////////////////////////////////////////////////
typedef struct
{
char Address[16];
} sfIPAddress;
////////////////////////////////////////////////////////////
/// Construct an address from a string
///
/// \param String : IP address ("xxx.xxx.xxx.xxx") or network name
///
/// \return Resulting address
///
////////////////////////////////////////////////////////////
CSFML_API sfIPAddress sfIPAddress_FromString(const char* String);
////////////////////////////////////////////////////////////
/// Construct an address from 4 bytes
///
/// \param Byte0 : First byte of the address
/// \param Byte1 : Second byte of the address
/// \param Byte2 : Third byte of the address
/// \param Byte3 : Fourth byte of the address
///
/// \return Resulting address
///
////////////////////////////////////////////////////////////
CSFML_API sfIPAddress sfIPAddress_FromBytes(sfUint8 Byte0, sfUint8 Byte1, sfUint8 Byte2, sfUint8 Byte3);
////////////////////////////////////////////////////////////
/// Construct the address from a 32-bits integer
///
/// \param Address : 4 bytes of the address packed into a 32-bits integer
///
////////////////////////////////////////////////////////////
CSFML_API sfIPAddress sfIPAddress_FromInteger(sfUint32 Address);
////////////////////////////////////////////////////////////
/// Tell if an address is a valid one
///
/// \param Address : Address to check
///
/// \return sfTrue if address has a valid syntax
///
////////////////////////////////////////////////////////////
CSFML_API sfBool sfIPAddress_IsValid(sfIPAddress Address);
////////////////////////////////////////////////////////////
/// Get a string representation of an address
///
/// \param Address : Address to convert
/// \param String : Char array to fill (size must be >= 16)
///
////////////////////////////////////////////////////////////
CSFML_API void sfIPAddress_ToString(sfIPAddress Address, char* String);
////////////////////////////////////////////////////////////
/// Get an integer representation of the address
///
/// \param Address : Address to convert
///
/// \return 32-bits integer containing the 4 bytes of the address, in system endianness
///
////////////////////////////////////////////////////////////
CSFML_API sfUint32 sfIPAddress_ToInteger(sfIPAddress Address);
////////////////////////////////////////////////////////////
/// Get the computer's local IP address (from the LAN point of view)
///
/// \return Local IP address
///
////////////////////////////////////////////////////////////
CSFML_API sfIPAddress sfIPAddress_GetLocalAddress();
////////////////////////////////////////////////////////////
/// Get the computer's public IP address (from the web point of view).
/// The only way to get a public address is to ask it to a
/// distant website ; as a consequence, this function may be
/// very slow -- use it as few as possible !
///
/// \param Timeout : Maximum time to wait, in seconds (use 0 for no timeout)
///
/// \return Public IP address
///
////////////////////////////////////////////////////////////
CSFML_API sfIPAddress sfIPAddress_GetPublicAddress(float Timeout);
////////////////////////////////////////////////////////////
/// Get the computer's loopback address
///
/// \return Local host IP address (127.0.0.1, or "localhost")
///
////////////////////////////////////////////////////////////
CSFML_API sfIPAddress sfIPAddress_LocalHost();
#endif // SFML_IPADDRESS_H

View file

@ -0,0 +1,153 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2008 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_PACKET_H
#define SFML_PACKET_H
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Config.h>
////////////////////////////////////////////////////////////
/// sfPacket wraps data to send / to receive through the network
////////////////////////////////////////////////////////////
typedef struct sfPacket sfPacket;
////////////////////////////////////////////////////////////
/// Create a new empty packet
///
/// \return A new sfPacket object
///
////////////////////////////////////////////////////////////
CSFML_API sfPacket* sfPacket_Create();
////////////////////////////////////////////////////////////
/// Destroy an existing packet
///
/// \param Packet : Packet to delete
///
////////////////////////////////////////////////////////////
CSFML_API void sfPacket_Destroy(sfPacket* Packet);
////////////////////////////////////////////////////////////
/// Append data to the end of a packet
///
/// \param Packet : Packet to fill
/// \param Data : Pointer to the bytes to append
/// \param SizeInBytes : Number of bytes to append
///
////////////////////////////////////////////////////////////
CSFML_API void sfPacket_Append(sfPacket* Packet, void* Data, size_t SizeInBytes);
////////////////////////////////////////////////////////////
/// Clear all the data of a packet
///
/// \param Packet : Packet to clear
///
///////////////////////////////////////////////////////////
CSFML_API void sfPacket_Clear(sfPacket* Packet);
////////////////////////////////////////////////////////////
/// Get a pointer to the data contained in a packet
/// Warning : the returned pointer may be invalid after you
/// append data to the packet
///
/// \param Packet : Packet to get data from
///
/// \return Pointer to the data
///
////////////////////////////////////////////////////////////
CSFML_API const char* sfPacket_GetData(sfPacket* Packet);
////////////////////////////////////////////////////////////
/// Get the size of the data contained in a packet
///
/// \param Packet : Packet to get data size from
///
/// \return Data size, in bytes
///
////////////////////////////////////////////////////////////
CSFML_API size_t sfPacket_GetDataSize(sfPacket* Packet);
////////////////////////////////////////////////////////////
/// Tell if the reading position has reached the end of the packet
///
/// \param Packet : Packet to check
///
/// \return sfTrue if all data have been read into the packet
///
////////////////////////////////////////////////////////////
CSFML_API sfBool sfPacket_EndOfPacket(sfPacket* Packet);
////////////////////////////////////////////////////////////
/// Return the validity of packet
///
/// \param Packet : Packet to check
///
/// \return sfTrue if last data extraction from packet was successful
///
////////////////////////////////////////////////////////////
CSFML_API sfBool sfPacket_CanRead(sfPacket* Packet);
////////////////////////////////////////////////////////////
/// Functions to extract data from a packet
///
/// \param Packet : Packet to read
///
////////////////////////////////////////////////////////////
CSFML_API sfBool sfPacket_ReadBool(sfPacket* Packet);
CSFML_API sfInt8 sfPacket_ReadInt8(sfPacket* Packet);
CSFML_API sfUint8 sfPacket_ReadUint8(sfPacket* Packet);
CSFML_API sfInt16 sfPacket_ReadInt16(sfPacket* Packet);
CSFML_API sfUint16 sfPacket_ReadUint16(sfPacket* Packet);
CSFML_API sfInt32 sfPacket_ReadInt32(sfPacket* Packet);
CSFML_API sfUint32 sfPacket_ReadUint32(sfPacket* Packet);
CSFML_API float sfPacket_ReadFloat(sfPacket* Packet);
CSFML_API double sfPacket_ReadDouble(sfPacket* Packet);
CSFML_API void sfPacket_ReadString(sfPacket* Packet, char* String);
CSFML_API void sfPacket_ReadWideString(sfPacket* Packet, wchar_t* String);
////////////////////////////////////////////////////////////
/// Functions to insert data into a packet
///
/// \param Packet : Packet to write
///
////////////////////////////////////////////////////////////
CSFML_API void sfPacket_WriteBool(sfPacket* Packet, sfBool);
CSFML_API void sfPacket_WriteInt8(sfPacket* Packet, sfInt8);
CSFML_API void sfPacket_WriteUint8(sfPacket* Packet, sfUint8);
CSFML_API void sfPacket_WriteInt16(sfPacket* Packet, sfInt16);
CSFML_API void sfPacket_WriteUint16(sfPacket* Packet, sfUint16);
CSFML_API void sfPacket_WriteInt32(sfPacket* Packet, sfInt32);
CSFML_API void sfPacket_WriteUint32(sfPacket* Packet, sfUint32);
CSFML_API void sfPacket_WriteFloat(sfPacket* Packet, float);
CSFML_API void sfPacket_WriteDouble(sfPacket* Packet, double);
CSFML_API void sfPacket_WriteString(sfPacket* Packet, const char* String);
CSFML_API void sfPacket_WriteWideString(sfPacket* Packet, const wchar_t* String);
#endif // SFML_PACKET_H

View file

@ -0,0 +1,120 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2008 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_SELECTOR_H
#define SFML_SELECTOR_H
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Config.h>
#include <SFML/Network/SocketTCP.h>
#include <SFML/Network/SocketUDP.h>
////////////////////////////////////////////////////////////
/// sfSelectorTCP and sfSelectorUDP allow reading from multiple sockets
/// without blocking. It's a kind of multiplexer
////////////////////////////////////////////////////////////
typedef struct sfSelectorTCP sfSelectorTCP;
typedef struct sfSelectorUDP sfSelectorUDP;
////////////////////////////////////////////////////////////
/// Create a new selector
///
/// \return A new sfSelector object
///
////////////////////////////////////////////////////////////
CSFML_API sfSelectorTCP* sfSelectorTCP_Create();
CSFML_API sfSelectorUDP* sfSelectorUDP_Create();
////////////////////////////////////////////////////////////
/// Destroy an existing selector
///
/// \param Selector : Selector to delete
///
////////////////////////////////////////////////////////////
CSFML_API void sfSelectorTCP_Destroy(sfSelectorTCP* Selector);
CSFML_API void sfSelectorUDP_Destroy(sfSelectorUDP* Selector);
////////////////////////////////////////////////////////////
/// Add a socket to watch to a selector
///
/// \param Selector : Selector to add the socket to
/// \param Socket : Socket to add
///
////////////////////////////////////////////////////////////
CSFML_API void sfSelectorTCP_Add(sfSelectorTCP* Selector, sfSocketTCP* Socket);
CSFML_API void sfSelectorUDP_Add(sfSelectorUDP* Selector, sfSocketUDP* Socket);
////////////////////////////////////////////////////////////
/// Remove a socket from a selector
///
/// \param Selector : Selector to remove the socket from
/// \param Socket : Socket to remove
///
////////////////////////////////////////////////////////////
CSFML_API void sfSelectorTCP_Remove(sfSelectorTCP* Selector, sfSocketTCP* Socket);
CSFML_API void sfSelectorUDP_Remove(sfSelectorUDP* Selector, sfSocketUDP* Socket);
////////////////////////////////////////////////////////////
/// Remove all sockets from a selector
///
/// \param Selector : Selector to remove the socket from
///
////////////////////////////////////////////////////////////
CSFML_API void sfSelectorTCP_Clear(sfSelectorTCP* Selector);
CSFML_API void sfSelectorUDP_Clear(sfSelectorUDP* Selector);
////////////////////////////////////////////////////////////
/// Wait and collect sockets which are ready for reading.
/// This functions will return either when at least one socket
/// is ready, or when the given time is out
///
/// \param Selector : Selector to check
/// \param Timeout : Maximum time to wait, in seconds (0 to disable timeout)
///
/// \return Number of sockets ready
///
////////////////////////////////////////////////////////////
CSFML_API unsigned int sfSelectorTCP_Wait(sfSelectorTCP* Selector, float Timeout);
CSFML_API unsigned int sfSelectorUDP_Wait(sfSelectorUDP* Selector, float Timeout);
////////////////////////////////////////////////////////////
/// After a call to Wait(), get the Index-th socket which is
/// ready for reading. The total number of sockets ready
/// is the integer returned by the previous call to Wait()
///
/// \param Selector : Selector to check
/// \param Index : Index of the socket to get
///
/// \return The Index-th socket
///
////////////////////////////////////////////////////////////
CSFML_API sfSocketTCP* sfSelectorTCP_GetSocketReady(sfSelectorTCP* Selector, unsigned int Index);
CSFML_API sfSocketUDP* sfSelectorUDP_GetSocketReady(sfSelectorUDP* Selector, unsigned int Index);
#endif // SFML_SELECTOR_H

View file

@ -0,0 +1,43 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2008 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_SOCKETSTATUS_H
#define SFML_SOCKETSTATUS_H
////////////////////////////////////////////////////////////
/// Define the status that can be returned by the socket
/// functions
////////////////////////////////////////////////////////////
typedef enum
{
sfSocketDone,
sfSocketNotReady,
sfSocketDisconnected,
sfSocketError
} sfSocketStatus;
#endif // SFML_SOCKETSTATUS_H

View file

@ -0,0 +1,167 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2008 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_SOCKETTCP_H
#define SFML_SOCKETTCP_H
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Config.h>
#include <SFML/Network/IPAddress.h>
#include <SFML/Network/Packet.h>
#include <SFML/Network/SocketStatus.h>
////////////////////////////////////////////////////////////
/// SocketTCP wraps a socket using TCP protocol to
/// send data safely (but a bit slower)
////////////////////////////////////////////////////////////
typedef struct sfSocketTCP sfSocketTCP;
////////////////////////////////////////////////////////////
/// Construct a new TCP socket
///
/// \return Pointer to the new socket
///
////////////////////////////////////////////////////////////
CSFML_API sfSocketTCP* sfSocketTCP_Create();
////////////////////////////////////////////////////////////
/// Destroy an existing TCP socket
///
/// \param Socket : Socket to destroy
///
////////////////////////////////////////////////////////////
CSFML_API void sfSocketTCP_Destroy(sfSocketTCP* Socket);
////////////////////////////////////////////////////////////
/// Change the blocking state of a TCP socket.
/// The default behaviour of a socket is blocking
///
/// \param Socket : Socket to modify
/// \param Blocking : Pass sfTrue to set the socket as blocking, or false for non-blocking
///
////////////////////////////////////////////////////////////
CSFML_API void sfSocketTCP_SetBlocking(sfSocketTCP* Socket, sfBool Blocking);
////////////////////////////////////////////////////////////
/// Connect a TCP socket to another computer on a specified port
///
/// \param Socket : Socket to use for connecting
/// \param Port : Port to use for transfers (warning : ports < 1024 are reserved)
/// \param HostAddress : IP Address of the host to connect to
/// \param Timeout : Maximum time to wait (0 to use no timeout)
///
/// \return sfTrue if operation has been successful
///
////////////////////////////////////////////////////////////
CSFML_API sfSocketStatus sfSocketTCP_Connect(sfSocketTCP* Socket, unsigned short Port, sfIPAddress HostAddress, float Timeout);
////////////////////////////////////////////////////////////
/// Listen to a specified port for incoming data or connections
///
/// \param Socket : Socket to use for listening
/// \param Port : Port to listen to
///
/// \return sfTrue if operation has been successful
///
////////////////////////////////////////////////////////////
CSFML_API sfBool sfSocketTCP_Listen(sfSocketTCP* Socket, unsigned short Port);
////////////////////////////////////////////////////////////
/// Wait for a connection (must be listening to a port).
/// This function is blocking, ie. it won't return before
/// a connection has been accepted
///
/// \param Socket : Socket to use for accepting
/// \param Connected : Pointer to a socket pointer that will be filled with the connected client
/// \param Address : Pointer to an address to fill with client infos
///
/// \return Socket status
///
////////////////////////////////////////////////////////////
CSFML_API sfSocketStatus sfSocketTCP_Accept(sfSocketTCP* Socket, sfSocketTCP** Connected, sfIPAddress* Address);
////////////////////////////////////////////////////////////
/// Send an array of bytes to the host (must be connected first)
///
/// \param Socket : Socket to use for sending
/// \param Data : Pointer to the bytes to send
/// \param Size : Number of bytes to send
///
/// \return Socket status
///
////////////////////////////////////////////////////////////
CSFML_API sfSocketStatus sfSocketTCP_Send(sfSocketTCP* Socket, const char* Data, size_t Size);
////////////////////////////////////////////////////////////
/// Receive an array of bytes from the host (must be connected first)
///
/// \param Socket : Socket to use for receiving
/// \param Data : Pointer to a byte array to fill (make sure it is big enough)
/// \param MaxSize : Maximum number of bytes to read
/// \param SizeReceived : Number of bytes received
///
/// \return Socket status
///
////////////////////////////////////////////////////////////
CSFML_API sfSocketStatus sfSocketTCP_Receive(sfSocketTCP* Socket, char* Data, size_t MaxSize, size_t* SizeReceived);
////////////////////////////////////////////////////////////
/// Send a packet of data to the host (must be connected first)
///
/// \param Socket : Socket to use for sending
/// \param Packet : Packet to send
///
/// \return Socket status
///
////////////////////////////////////////////////////////////
CSFML_API sfSocketStatus sfSocketTCP_SendPacket(sfSocketTCP* Socket, sfPacket* Packet);
////////////////////////////////////////////////////////////
/// Receive a packet from the host (must be connected first)
///
/// \param Socket : Socket to use for receiving
/// \param Packet : Packet to fill with received data
///
/// \return Socket status
///
////////////////////////////////////////////////////////////
CSFML_API sfSocketStatus sfSocketTCP_ReceivePacket(sfSocketTCP* Socket, sfPacket* Packet);
////////////////////////////////////////////////////////////
/// Check if a socket is in a valid state ; this function
/// can be called any time to check if the socket is OK
///
/// \param Socket : Socket to check
///
/// \return True if the socket is valid
///
////////////////////////////////////////////////////////////
CSFML_API sfBool sfSocketTCP_IsValid(sfSocketTCP* Socket);
#endif // SFML_SOCKETTCP_H

View file

@ -0,0 +1,162 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2008 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_SOCKETUDP_H
#define SFML_SOCKETUDP_H
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Config.h>
#include <SFML/Network/IPAddress.h>
#include <SFML/Network/Packet.h>
#include <SFML/Network/SocketStatus.h>
////////////////////////////////////////////////////////////
/// sfSocketUDP wraps a socket using UDP protocol to
/// send data fastly (but with less safety)
////////////////////////////////////////////////////////////
typedef struct sfSocketUDP sfSocketUDP;
////////////////////////////////////////////////////////////
/// Construct a new UDP socket
///
/// \return Pointer to the new socket
///
////////////////////////////////////////////////////////////
CSFML_API sfSocketUDP* sfSocketUDP_Create();
////////////////////////////////////////////////////////////
/// Destroy an existing UDP socket
///
/// \param Socket : Socket to destroy
///
////////////////////////////////////////////////////////////
CSFML_API void sfSocketUDP_Destroy(sfSocketUDP* Socket);
////////////////////////////////////////////////////////////
/// Change the blocking state of a UDP socket.
/// The default behaviour of a socket is blocking
///
/// \param Socket : Socket to modify
/// \param Blocking : Pass sfTrue to set the socket as blocking, or false for non-blocking
///
////////////////////////////////////////////////////////////
CSFML_API void sfSocketUDP_SetBlocking(sfSocketUDP* Socket, sfBool Blocking);
////////////////////////////////////////////////////////////
/// Bind a socket to a specific port
///
/// \param Socket : Socket to bind
/// \param Port : Port to bind the socket to
///
/// \return True if operation has been successful
///
////////////////////////////////////////////////////////////
CSFML_API sfBool sfSocketUDP_Bind(sfSocketUDP* Socket, unsigned short Port);
////////////////////////////////////////////////////////////
/// Unbind a socket from its previous port, if any
///
/// \param Socket : Socket to unbind
///
/// \return sfTrue if operation has been successful
///
////////////////////////////////////////////////////////////
CSFML_API sfBool sfSocketUDP_Unbind(sfSocketUDP* Socket);
////////////////////////////////////////////////////////////
/// Send an array of bytes
///
/// \param Socket : Socket to use for sending
/// \param Data : Pointer to the bytes to send
/// \param Size : Number of bytes to send
/// \param Address : Address of the computer to send the packet to
/// \param Port : Port to use for communication
///
/// \return Socket status
///
////////////////////////////////////////////////////////////
CSFML_API sfSocketStatus sfSocketUDP_Send(sfSocketUDP* Socket, const char* Data, size_t Size, sfIPAddress Address, unsigned short Port);
////////////////////////////////////////////////////////////
/// Receive an array of bytes.
/// This function is blocking, ie. it won't return before some
/// bytes have been received
///
/// \param Socket : Socket to use for receiving
/// \param Data : Pointer to a byte array to fill (make sure it is big enough)
/// \param MaxSize : Maximum number of bytes to read
/// \param SizeReceived : Number of bytes received
/// \param Address : Address of the computer which sent the data
/// \param Port : Port on which the remote computer sent the data
///
/// \return Socket status
///
////////////////////////////////////////////////////////////
CSFML_API sfSocketStatus sfSocketUDP_Receive(sfSocketUDP* Socket, char* Data, size_t MaxSize, size_t* SizeReceived, sfIPAddress* Address, unsigned short* Port);
////////////////////////////////////////////////////////////
/// Send a packet of data
///
/// \param Socket : Socket to use for sending
/// \param Packet : Packet to send
/// \param Address : Address of the computer to send the packet to
/// \param Port : Port to use for communication
///
/// \return Socket status
///
////////////////////////////////////////////////////////////
CSFML_API sfSocketStatus sfSocketUDP_SendPacket(sfSocketUDP* Socket, sfPacket* Packet, sfIPAddress Address, unsigned short Port);
////////////////////////////////////////////////////////////
/// Receive a packet.
/// This function is blocking, ie. it won't return before a
/// packet is received
///
/// \param Socket : Socket to use for receiving
/// \param Packet : Packet to fill with received data
/// \param Address : Address of the computer which sent the packet
/// \param Port : Port on which the remote computer sent the data
///
/// \return Socket status
///
////////////////////////////////////////////////////////////
CSFML_API sfSocketStatus sfSocketUDP_ReceivePacket(sfSocketUDP* Socket, sfPacket* Packet, sfIPAddress* Address, unsigned short* Port);
////////////////////////////////////////////////////////////
/// Check if a socket is in a valid state ; this function
/// can be called any time to check if the socket is OK
///
/// \param Socket : Socket to check
///
/// \return sfTrue if the socket is valid
///
////////////////////////////////////////////////////////////
CSFML_API sfBool sfSocketUDP_IsValid(sfSocketUDP* Socket);
#endif // SFML_SOCKETUDP_H