mirror of
https://github.com/SFML/CSFML.git
synced 2026-10-25 21:06:12 +01:00
Compare commits
15
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
904c98b058 | ||
|
|
fe8c6adb12 | ||
|
|
63dc503d20 | ||
|
|
8208e90599 | ||
|
|
af34a2890e | ||
|
|
d95f00f212 | ||
|
|
917e811888 | ||
|
|
523c48cf98 | ||
|
|
b4220b39ff | ||
|
|
e38e58c835 | ||
|
|
6d7cc360a1 | ||
|
|
a4c9ecec57 | ||
|
|
a08585812d | ||
|
|
0a4871cfbe | ||
|
|
13935af42b |
No files matched your search
@@ -9,7 +9,7 @@ concurrency:
|
||||
cancel-in-progress: true
|
||||
|
||||
env:
|
||||
SFML_VERSION: 3.0.2
|
||||
SFML_VERSION: 3.1.0
|
||||
|
||||
defaults:
|
||||
run:
|
||||
@@ -26,8 +26,7 @@ jobs:
|
||||
platform:
|
||||
- { name: Windows VS2026 x86, os: windows-2025-vs2026, flags: -AWin32 }
|
||||
- { name: Windows VS2026 x64, os: windows-2025-vs2026, flags: -Ax64 }
|
||||
# ClangCL is disabled until we build against SFML 3.1, the FLAC version bundled with SFML 3.0 fails to compile with VS2026's ClangCL
|
||||
# - { name: Windows ClangCL, os: windows-2025-vs2026, flags: -T ClangCL }
|
||||
- { name: Windows ClangCL, os: windows-2025-vs2026, flags: -T ClangCL }
|
||||
- { name: Windows Clang, os: windows-2025-vs2026, flags: -GNinja -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ }
|
||||
- { name: Linux GCC, os: ubuntu-24.04, flags: -GNinja }
|
||||
- { name: Linux Clang, os: ubuntu-24.04, flags: -GNinja -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ }
|
||||
@@ -43,12 +42,12 @@ jobs:
|
||||
- name: Get CMake and Ninja
|
||||
uses: lukka/get-cmake@latest
|
||||
with:
|
||||
cmakeVersion: ${{ runner.os == 'Windows' && '4.2' || '3.22' }} # Visual Studio 2026 generator requires CMake 4.2 or later
|
||||
cmakeVersion: ${{ runner.os == 'Windows' && '4.2' || '3.28' }} # Visual Studio 2026 generator requires CMake 4.2 or later
|
||||
ninjaVersion: latest
|
||||
|
||||
- name: Install Linux Dependencies
|
||||
if: runner.os == 'Linux'
|
||||
run: sudo apt-get update && sudo apt-get install libxrandr-dev libxcursor-dev libxi-dev libudev-dev libflac-dev libvorbis-dev libgl1-mesa-dev libegl1-mesa-dev libfreetype-dev
|
||||
run: sudo apt-get update && sudo apt-get install libxrandr-dev libxcursor-dev libxi-dev libudev-dev libflac-dev libvorbis-dev libgl1-mesa-dev libegl1-mesa-dev libfreetype-dev libharfbuzz-dev libmbedtls-dev libssh2-1-dev
|
||||
|
||||
- name: Checkout SFML
|
||||
uses: actions/checkout@v7
|
||||
@@ -63,9 +62,13 @@ jobs:
|
||||
BUILD_TYPE: ${{ matrix.type.name }}
|
||||
CMAKE_FLAGS: ${{ matrix.platform.flags }} ${{ matrix.config.flags }}
|
||||
run: |
|
||||
# Let the installed SFML libraries find each other, same as tools/nuget/build.linux.sh
|
||||
RPATH_FLAGS=()
|
||||
if [ "$RUNNER_OS" = "Linux" ]; then RPATH_FLAGS=('-DCMAKE_INSTALL_RPATH=$ORIGIN'); fi
|
||||
cmake -S SFML -B SFML/build \
|
||||
-DCMAKE_BUILD_TYPE="$BUILD_TYPE" \
|
||||
-DCMAKE_INSTALL_PREFIX=SFML/install \
|
||||
"${RPATH_FLAGS[@]}" \
|
||||
$CMAKE_FLAGS
|
||||
|
||||
- name: Build SFML
|
||||
@@ -128,7 +131,7 @@ jobs:
|
||||
- name: Get CMake and Ninja
|
||||
uses: lukka/get-cmake@latest
|
||||
with:
|
||||
cmakeVersion: ${{ runner.os == 'Windows' && '4.2' || '3.22' }} # Visual Studio 2026 generator requires CMake 4.2 or later
|
||||
cmakeVersion: ${{ runner.os == 'Windows' && '4.2' || '3.28' }} # Visual Studio 2026 generator requires CMake 4.2 or later
|
||||
ninjaVersion: latest
|
||||
|
||||
- name: Install Dependencies
|
||||
@@ -171,7 +174,7 @@ jobs:
|
||||
- name: Get CMake and Ninja
|
||||
uses: lukka/get-cmake@latest
|
||||
with:
|
||||
cmakeVersion: ${{ runner.os == 'Windows' && '4.2' || '3.22' }} # Visual Studio 2026 generator requires CMake 4.2 or later
|
||||
cmakeVersion: ${{ runner.os == 'Windows' && '4.2' || '3.28' }} # Visual Studio 2026 generator requires CMake 4.2 or later
|
||||
ninjaVersion: latest
|
||||
|
||||
- name: Install Doxygen
|
||||
|
||||
@@ -16,7 +16,7 @@ concurrency:
|
||||
cancel-in-progress: true
|
||||
|
||||
env:
|
||||
SFML_VERSION: 3.0.2
|
||||
SFML_VERSION: 3.1.0
|
||||
|
||||
defaults:
|
||||
run:
|
||||
|
||||
+3
-3
@@ -1,4 +1,4 @@
|
||||
cmake_minimum_required(VERSION 3.22)
|
||||
cmake_minimum_required(VERSION 3.28)
|
||||
|
||||
# define a macro that helps defining an option
|
||||
macro(csfml_set_option var default type docstring)
|
||||
@@ -13,7 +13,7 @@ endmacro()
|
||||
csfml_set_option(CMAKE_BUILD_TYPE Release STRING "Choose the type of build (Debug or Release)")
|
||||
|
||||
# project name
|
||||
project(CSFML VERSION 3.0.0)
|
||||
project(CSFML VERSION 3.1.0)
|
||||
|
||||
# we use the paths from the cmake GNUInstallDirs module as defaults
|
||||
# you can override these if you like
|
||||
@@ -66,7 +66,7 @@ endif()
|
||||
if(CSFML_BUILD_NETWORK)
|
||||
list(PREPEND SFML_MODULES "Network")
|
||||
endif()
|
||||
find_package(SFML 3.0 COMPONENTS ${SFML_MODULES} REQUIRED)
|
||||
find_package(SFML 3.1 COMPONENTS ${SFML_MODULES} REQUIRED)
|
||||
|
||||
# add the subdirectories
|
||||
add_subdirectory(src/CSFML)
|
||||
|
||||
+1
-2
@@ -42,9 +42,8 @@
|
||||
/// font = sfFont_createFromFile("arial.ttf");
|
||||
/// if (!font)
|
||||
/// return EXIT_FAILURE;
|
||||
/// text = sfText_create();
|
||||
/// text = sfText_create(font);
|
||||
/// sfText_setString(text, "Hello SFML");
|
||||
/// sfText_setFont(text, font);
|
||||
/// sfText_setCharacterSize(text, 50);
|
||||
///
|
||||
/// /* Load a music to play */
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
|
||||
#include <CSFML/Audio/Listener.h>
|
||||
#include <CSFML/Audio/Music.h>
|
||||
#include <CSFML/Audio/PlaybackDevice.h>
|
||||
#include <CSFML/Audio/Sound.h>
|
||||
#include <CSFML/Audio/SoundBuffer.h>
|
||||
#include <CSFML/Audio/SoundBufferRecorder.h>
|
||||
|
||||
@@ -0,0 +1,205 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2026 Laurent Gomila (laurent@sfml-dev.org)
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <CSFML/Audio/Export.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Enumeration of the playback device notifications
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
typedef enum
|
||||
{
|
||||
sfPlaybackDeviceStarted, ///< Playback device has been started
|
||||
sfPlaybackDeviceStopped, ///< Playback device has been stopped
|
||||
sfPlaybackDeviceRerouted, ///< Playback device has been rerouted (Generated on platforms that support automatic stream routing)
|
||||
sfPlaybackDeviceInterruptionBegan, ///< Playback device interruption has begun (Generated on Apple mobile platforms)
|
||||
sfPlaybackDeviceInterruptionEnded, ///< Playback device interruption has ended (Generated on Apple mobile platforms)
|
||||
sfPlaybackDeviceUnlocked ///< Playback device has been unlocked (Generated by Emscripten/WebAudio)
|
||||
} sfPlaybackDeviceNotification;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Callback that is called to notify of changes to the playback device state
|
||||
///
|
||||
/// \param notification The notification
|
||||
/// \param userData User data passed to sfPlaybackDevice_setNotificationCallback
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
typedef void (*sfPlaybackDeviceNotificationCallback)(sfPlaybackDeviceNotification notification, void* userData);
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get a list of the names of all available audio playback devices
|
||||
///
|
||||
/// If the operating system reports multiple devices with
|
||||
/// the same name, a number will be appended to the name
|
||||
/// of all subsequent devices to distinguish them from each
|
||||
/// other. This guarantees that every entry returned by this
|
||||
/// function will represent a unique device.
|
||||
///
|
||||
/// The default device, if one is marked as such, will be
|
||||
/// placed at the beginning of the list.
|
||||
///
|
||||
/// The returned array and strings stay valid until the next
|
||||
/// call to this function.
|
||||
///
|
||||
/// \param count Pointer to a variable that will be filled with the number of devices
|
||||
///
|
||||
/// \return An array of strings containing the device names or NULL if no devices are available
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_AUDIO_API const char* const* sfPlaybackDevice_getAvailableDevices(size_t* count);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the name of the default audio playback device
|
||||
///
|
||||
/// Note that depending on when this function is called, the
|
||||
/// default device reported by the operating system might
|
||||
/// change e.g. when a USB audio device is plugged into or
|
||||
/// unplugged from the system.
|
||||
///
|
||||
/// The returned string stays valid until the next call to
|
||||
/// this function.
|
||||
///
|
||||
/// \return The name of the default audio playback device or NULL if there is none
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_AUDIO_API const char* sfPlaybackDevice_getDefaultDevice(void);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Set the audio playback device
|
||||
///
|
||||
/// This function sets the audio playback device to the device
|
||||
/// with the given name. It can be called on the fly (i.e:
|
||||
/// while sounds are playing).
|
||||
///
|
||||
/// If there are sounds playing when the audio playback
|
||||
/// device is switched, the sounds will continue playing
|
||||
/// uninterrupted on the new audio playback device.
|
||||
///
|
||||
/// \param name The name of the audio playback device
|
||||
///
|
||||
/// \return True, if it was able to set the requested device
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_AUDIO_API bool sfPlaybackDevice_setDevice(const char* name);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Set the audio playback device to the default
|
||||
///
|
||||
/// This function sets the audio playback device to the
|
||||
/// default device. It can be called on the fly (i.e:
|
||||
/// while sounds are playing).
|
||||
///
|
||||
/// When certain backends are used, using the default device
|
||||
/// will enable automatic stream routing. When automatic
|
||||
/// stream routing is enabled, audio data is automatically
|
||||
/// sent to whichever physical audio device is currently
|
||||
/// marked as the default on the system.
|
||||
///
|
||||
/// Automatic stream routing is currently supported when using
|
||||
/// the WASAPI or DirectSound backend on Windows or the
|
||||
/// Core Audio backend on macOS and iOS.
|
||||
///
|
||||
/// \return True, if it was able to set the audio playback device to the default device
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_AUDIO_API bool sfPlaybackDevice_setDeviceToDefault(void);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Set the audio playback device to the null device
|
||||
///
|
||||
/// This function sets the audio playback device to the
|
||||
/// null device. It can be called on the fly (i.e:
|
||||
/// while sounds are playing).
|
||||
///
|
||||
/// Audio data routed to the null device will be discarded
|
||||
/// by the backend. This can be used to keep sounds playing
|
||||
/// without having them actually output on a physical
|
||||
/// audio playback device.
|
||||
///
|
||||
/// \return True, if it was able to set the audio playback device to the null device
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_AUDIO_API bool sfPlaybackDevice_setDeviceToNull(void);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the name of the current audio playback device
|
||||
///
|
||||
/// The returned string stays valid until the next call to
|
||||
/// this function.
|
||||
///
|
||||
/// \return The name of the current audio playback device or NULL if there is none
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_AUDIO_API const char* sfPlaybackDevice_getDevice(void);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the sample rate of the current audio playback device
|
||||
///
|
||||
/// \return The sample rate of the current audio playback device or 0 if there is none
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_AUDIO_API uint32_t sfPlaybackDevice_getDeviceSampleRate(void);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Check if the current playback device is the default device
|
||||
///
|
||||
/// This function will return false if there is no
|
||||
/// current playback device.
|
||||
///
|
||||
/// \return True, if the current playback device is the default device
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_AUDIO_API bool sfPlaybackDevice_isDefaultDevice(void);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Set a callback that should be called to notify of changes to the playback device state
|
||||
///
|
||||
/// Warning: Do not attempt to alter the device state from
|
||||
/// within this callback. This includes changing the device
|
||||
/// and even creating/destroying sound objects since that
|
||||
/// could indirectly cause the playback device to be
|
||||
/// created/destroyed. Also do not attempt to set the
|
||||
/// notification callback from within this callback. Doing
|
||||
/// so will result in a deadlock.
|
||||
///
|
||||
/// When receiving a notification via this callback, store
|
||||
/// the information somewhere and react on it from another
|
||||
/// thread e.g. the main thread within the application.
|
||||
///
|
||||
/// \param callback The callback to be called, pass NULL to remove the current callback
|
||||
/// \param userData User data that will be passed to the callback
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_AUDIO_API void sfPlaybackDevice_setNotificationCallback(sfPlaybackDeviceNotificationCallback callback, void* userData);
|
||||
@@ -36,7 +36,7 @@
|
||||
// Define the CSFML version
|
||||
////////////////////////////////////////////////////////////
|
||||
#define CSFML_VERSION_MAJOR 3
|
||||
#define CSFML_VERSION_MINOR 0
|
||||
#define CSFML_VERSION_MINOR 1
|
||||
#define CSFML_VERSION_PATCH 0
|
||||
|
||||
|
||||
|
||||
@@ -292,6 +292,36 @@ CSFML_GRAPHICS_API void sfCircleShape_setOutlineColor(sfCircleShape* shape, sfCo
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_GRAPHICS_API void sfCircleShape_setOutlineThickness(sfCircleShape* shape, float thickness);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Set the limit on the ratio between miter length and outline thickness of a circle shape
|
||||
///
|
||||
/// Outline segments around each corner are joined either
|
||||
/// with a miter or a bevel join.
|
||||
/// - A miter join is formed by extending outline segments until
|
||||
/// they intersect. The distance between the point of
|
||||
/// intersection and the shape's corner is the miter length.
|
||||
/// - A bevel join is formed by connecting outline segments with
|
||||
/// a straight line perpendicular to the corner's bisector.
|
||||
///
|
||||
/// The miter limit is used to determine whether outline segments
|
||||
/// around a corner are joined with a bevel or a miter.
|
||||
/// When the ratio between the miter length and outline thickness
|
||||
/// exceeds the miter limit, a bevel is used instead of a miter.
|
||||
///
|
||||
/// The miter limit is linked to the maximum inner angle of a
|
||||
/// corner below which a bevel is used by the following formula:
|
||||
///
|
||||
/// miterLimit = 1 / sin(angle / 2)
|
||||
///
|
||||
/// The miter limit must be greater than or equal to 1.
|
||||
/// By default, the miter limit is 10.
|
||||
///
|
||||
/// \param shape Shape object
|
||||
/// \param miterLimit New miter limit
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_GRAPHICS_API void sfCircleShape_setMiterLimit(sfCircleShape* shape, float miterLimit);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the source texture of a circle shape
|
||||
///
|
||||
@@ -346,6 +376,16 @@ CSFML_GRAPHICS_API sfColor sfCircleShape_getOutlineColor(const sfCircleShape* sh
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_GRAPHICS_API float sfCircleShape_getOutlineThickness(const sfCircleShape* shape);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the limit on the ratio between miter length and outline thickness of a circle shape
|
||||
///
|
||||
/// \param shape Shape object
|
||||
///
|
||||
/// \return Limit on the ratio between miter length and outline thickness
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_GRAPHICS_API float sfCircleShape_getMiterLimit(const sfCircleShape* shape);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the total number of points of a circle shape
|
||||
///
|
||||
|
||||
@@ -292,6 +292,36 @@ CSFML_GRAPHICS_API void sfConvexShape_setOutlineColor(sfConvexShape* shape, sfCo
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_GRAPHICS_API void sfConvexShape_setOutlineThickness(sfConvexShape* shape, float thickness);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Set the limit on the ratio between miter length and outline thickness of a convex shape
|
||||
///
|
||||
/// Outline segments around each corner are joined either
|
||||
/// with a miter or a bevel join.
|
||||
/// - A miter join is formed by extending outline segments until
|
||||
/// they intersect. The distance between the point of
|
||||
/// intersection and the shape's corner is the miter length.
|
||||
/// - A bevel join is formed by connecting outline segments with
|
||||
/// a straight line perpendicular to the corner's bisector.
|
||||
///
|
||||
/// The miter limit is used to determine whether outline segments
|
||||
/// around a corner are joined with a bevel or a miter.
|
||||
/// When the ratio between the miter length and outline thickness
|
||||
/// exceeds the miter limit, a bevel is used instead of a miter.
|
||||
///
|
||||
/// The miter limit is linked to the maximum inner angle of a
|
||||
/// corner below which a bevel is used by the following formula:
|
||||
///
|
||||
/// miterLimit = 1 / sin(angle / 2)
|
||||
///
|
||||
/// The miter limit must be greater than or equal to 1.
|
||||
/// By default, the miter limit is 10.
|
||||
///
|
||||
/// \param shape Shape object
|
||||
/// \param miterLimit New miter limit
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_GRAPHICS_API void sfConvexShape_setMiterLimit(sfConvexShape* shape, float miterLimit);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the source texture of a convex shape
|
||||
///
|
||||
@@ -346,6 +376,16 @@ CSFML_GRAPHICS_API sfColor sfConvexShape_getOutlineColor(const sfConvexShape* sh
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_GRAPHICS_API float sfConvexShape_getOutlineThickness(const sfConvexShape* shape);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the limit on the ratio between miter length and outline thickness of a convex shape
|
||||
///
|
||||
/// \param shape Shape object
|
||||
///
|
||||
/// \return Limit on the ratio between miter length and outline thickness
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_GRAPHICS_API float sfConvexShape_getMiterLimit(const sfConvexShape* shape);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the total number of points of a convex shape
|
||||
///
|
||||
|
||||
@@ -101,6 +101,31 @@ CSFML_GRAPHICS_API void sfFont_destroy(const sfFont* font);
|
||||
CSFML_GRAPHICS_API sfGlyph
|
||||
sfFont_getGlyph(const sfFont* font, uint32_t codePoint, unsigned int characterSize, bool bold, float outlineThickness);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get a glyph in a font by glyph ID
|
||||
///
|
||||
/// If the font is a bitmap font, not all character sizes
|
||||
/// might be available. If the glyph is not available at the
|
||||
/// requested size, an empty glyph is returned.
|
||||
///
|
||||
/// Glyph IDs are font specific and are for example
|
||||
/// provided by the shaped glyphs of a text.
|
||||
///
|
||||
/// Be aware that using a negative value for the outline
|
||||
/// thickness will cause distorted rendering.
|
||||
///
|
||||
/// \param font Source font
|
||||
/// \param id ID of the glyph to get
|
||||
/// \param characterSize Character size, in pixels
|
||||
/// \param bold Retrieve the bold version or the regular one?
|
||||
/// \param outlineThickness Thickness of outline (when != 0 the glyph will not be filled)
|
||||
///
|
||||
/// \return The corresponding glyph
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_GRAPHICS_API sfGlyph
|
||||
sfFont_getGlyphById(const sfFont* font, uint32_t id, unsigned int characterSize, bool bold, float outlineThickness);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Determine if this font has a glyph representing the requested code point
|
||||
///
|
||||
@@ -157,6 +182,44 @@ CSFML_GRAPHICS_API float sfFont_getBoldKerning(const sfFont* font, uint32_t firs
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_GRAPHICS_API float sfFont_getLineSpacing(const sfFont* font, unsigned int characterSize);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the ascent of a font
|
||||
///
|
||||
/// The ascent is the largest distance between the baseline and
|
||||
/// the top of all glyphs in the font.
|
||||
///
|
||||
/// Be aware that there is no uniform definition of how the
|
||||
/// ascent is calculated. It can vary from font to font.
|
||||
///
|
||||
/// \param font Source font
|
||||
/// \param characterSize Reference character size
|
||||
///
|
||||
/// \return Ascent, in pixels
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_GRAPHICS_API float sfFont_getAscent(const sfFont* font, unsigned int characterSize);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the descent of a font
|
||||
///
|
||||
/// The descent is the largest distance between the baseline and
|
||||
/// the bottom of all glyphs in the font.
|
||||
///
|
||||
/// Be aware that there is no uniform definition of how the
|
||||
/// descent is calculated. It can vary from font to font.
|
||||
///
|
||||
/// The descent shares the same coordinate system as the
|
||||
/// ascent. This means that it will be negative for distances
|
||||
/// below the baseline.
|
||||
///
|
||||
/// \param font Source font
|
||||
/// \param characterSize Reference character size
|
||||
///
|
||||
/// \return Descent, in pixels
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_GRAPHICS_API float sfFont_getDescent(const sfFont* font, unsigned int characterSize);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the position of the underline
|
||||
///
|
||||
|
||||
@@ -29,10 +29,16 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <CSFML/Graphics/Export.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// sfFontInfo holds various information about a font
|
||||
////////////////////////////////////////////////////////////
|
||||
typedef struct
|
||||
{
|
||||
const char* family;
|
||||
uint64_t id; ///< A unique ID that identifies the font
|
||||
const char* family; ///< The font family
|
||||
bool hasKerning; ///< Has kerning information
|
||||
bool hasVerticalMetrics; ///< Has native vertical metrics
|
||||
} sfFontInfo;
|
||||
@@ -82,8 +82,8 @@ CSFML_GRAPHICS_API sfImage* sfImage_createFromPixels(sfVector2u size, const uint
|
||||
/// \brief Create an image from a file on disk
|
||||
///
|
||||
/// The supported image formats are bmp, png, tga, jpg, gif,
|
||||
/// psd, hdr and pic. Some format options are not supported,
|
||||
/// like progressive jpeg.
|
||||
/// psd, hdr, pic, pnm and qoi. Some format options are not supported,
|
||||
/// like jpeg with arithmetic coding or ASCII pnm.
|
||||
/// If this function fails, the image is left unchanged.
|
||||
///
|
||||
/// \param filename Path of the image file to load
|
||||
@@ -97,8 +97,8 @@ CSFML_GRAPHICS_API sfImage* sfImage_createFromFile(const char* filename);
|
||||
/// \brief Create an image from a file in memory
|
||||
///
|
||||
/// The supported image formats are bmp, png, tga, jpg, gif,
|
||||
/// psd, hdr and pic. Some format options are not supported,
|
||||
/// like progressive jpeg.
|
||||
/// psd, hdr, pic, pnm and qoi. Some format options are not supported,
|
||||
/// like jpeg with arithmetic coding or ASCII pnm.
|
||||
/// If this function fails, the image is left unchanged.
|
||||
///
|
||||
/// \param data Pointer to the file data in memory
|
||||
@@ -113,8 +113,8 @@ CSFML_GRAPHICS_API sfImage* sfImage_createFromMemory(const void* data, size_t si
|
||||
/// \brief Create an image from a custom stream
|
||||
///
|
||||
/// The supported image formats are bmp, png, tga, jpg, gif,
|
||||
/// psd, hdr and pic. Some format options are not supported,
|
||||
/// like progressive jpeg.
|
||||
/// psd, hdr, pic, pnm and qoi. Some format options are not supported,
|
||||
/// like jpeg with arithmetic coding or ASCII pnm.
|
||||
/// If this function fails, the image is left unchanged.
|
||||
///
|
||||
/// \param stream Source stream to read from
|
||||
@@ -147,7 +147,7 @@ CSFML_GRAPHICS_API void sfImage_destroy(const sfImage* image);
|
||||
///
|
||||
/// The format of the image is automatically deduced from
|
||||
/// the extension. The supported image formats are bmp, png,
|
||||
/// tga and jpg. The destination file is overwritten
|
||||
/// tga, jpg and qoi. The destination file is overwritten
|
||||
/// if it already exists. This function fails if the image is empty.
|
||||
///
|
||||
/// \param image Image object
|
||||
@@ -164,7 +164,7 @@ CSFML_GRAPHICS_API bool sfImage_saveToFile(const sfImage* image, const char* fil
|
||||
/// \brief Save the image to a buffer in memory
|
||||
///
|
||||
/// The format of the image must be specified.
|
||||
/// The supported image formats are bmp, png, tga and jpg.
|
||||
/// The supported image formats are bmp, png, tga, jpg and qoi.
|
||||
/// This function fails if the image is empty, or if
|
||||
/// the format was invalid.
|
||||
///
|
||||
|
||||
@@ -292,6 +292,36 @@ CSFML_GRAPHICS_API void sfRectangleShape_setOutlineColor(sfRectangleShape* shape
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_GRAPHICS_API void sfRectangleShape_setOutlineThickness(sfRectangleShape* shape, float thickness);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Set the limit on the ratio between miter length and outline thickness of a rectangle shape
|
||||
///
|
||||
/// Outline segments around each corner are joined either
|
||||
/// with a miter or a bevel join.
|
||||
/// - A miter join is formed by extending outline segments until
|
||||
/// they intersect. The distance between the point of
|
||||
/// intersection and the shape's corner is the miter length.
|
||||
/// - A bevel join is formed by connecting outline segments with
|
||||
/// a straight line perpendicular to the corner's bisector.
|
||||
///
|
||||
/// The miter limit is used to determine whether outline segments
|
||||
/// around a corner are joined with a bevel or a miter.
|
||||
/// When the ratio between the miter length and outline thickness
|
||||
/// exceeds the miter limit, a bevel is used instead of a miter.
|
||||
///
|
||||
/// The miter limit is linked to the maximum inner angle of a
|
||||
/// corner below which a bevel is used by the following formula:
|
||||
///
|
||||
/// miterLimit = 1 / sin(angle / 2)
|
||||
///
|
||||
/// The miter limit must be greater than or equal to 1.
|
||||
/// By default, the miter limit is 10.
|
||||
///
|
||||
/// \param shape Shape object
|
||||
/// \param miterLimit New miter limit
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_GRAPHICS_API void sfRectangleShape_setMiterLimit(sfRectangleShape* shape, float miterLimit);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the source texture of a rectangle shape
|
||||
///
|
||||
@@ -346,6 +376,16 @@ CSFML_GRAPHICS_API sfColor sfRectangleShape_getOutlineColor(const sfRectangleSha
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_GRAPHICS_API float sfRectangleShape_getOutlineThickness(const sfRectangleShape* shape);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the limit on the ratio between miter length and outline thickness of a rectangle shape
|
||||
///
|
||||
/// \param shape Shape object
|
||||
///
|
||||
/// \return Limit on the ratio between miter length and outline thickness
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_GRAPHICS_API float sfRectangleShape_getMiterLimit(const sfRectangleShape* shape);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the total number of points of a rectangle shape
|
||||
///
|
||||
|
||||
@@ -708,8 +708,11 @@ CSFML_GRAPHICS_API void sfMouse_setPositionRenderWindow(sfVector2i position, con
|
||||
///
|
||||
/// \return Current position of \a finger, or undefined if it's not down
|
||||
///
|
||||
/// \deprecated Use the position of the touch events (sfEvtTouchBegan, sfEvtTouchMoved and sfEvtTouchEnded) instead
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_GRAPHICS_API sfVector2i sfTouch_getPositionRenderWindow(unsigned int finger, const sfRenderWindow* relativeTo);
|
||||
CSFML_GRAPHICS_API CSFML_DEPRECATED sfVector2i sfTouch_getPositionRenderWindow(unsigned int finger,
|
||||
const sfRenderWindow* relativeTo);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Create a Vulkan rendering surface
|
||||
|
||||
@@ -291,6 +291,36 @@ CSFML_GRAPHICS_API void sfShape_setOutlineColor(sfShape* shape, sfColor color);
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_GRAPHICS_API void sfShape_setOutlineThickness(sfShape* shape, float thickness);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Set the limit on the ratio between miter length and outline thickness of a shape
|
||||
///
|
||||
/// Outline segments around each corner are joined either
|
||||
/// with a miter or a bevel join.
|
||||
/// - A miter join is formed by extending outline segments until
|
||||
/// they intersect. The distance between the point of
|
||||
/// intersection and the shape's corner is the miter length.
|
||||
/// - A bevel join is formed by connecting outline segments with
|
||||
/// a straight line perpendicular to the corner's bisector.
|
||||
///
|
||||
/// The miter limit is used to determine whether outline segments
|
||||
/// around a corner are joined with a bevel or a miter.
|
||||
/// When the ratio between the miter length and outline thickness
|
||||
/// exceeds the miter limit, a bevel is used instead of a miter.
|
||||
///
|
||||
/// The miter limit is linked to the maximum inner angle of a
|
||||
/// corner below which a bevel is used by the following formula:
|
||||
///
|
||||
/// miterLimit = 1 / sin(angle / 2)
|
||||
///
|
||||
/// The miter limit must be greater than or equal to 1.
|
||||
/// By default, the miter limit is 10.
|
||||
///
|
||||
/// \param shape Shape object
|
||||
/// \param miterLimit New miter limit
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_GRAPHICS_API void sfShape_setMiterLimit(sfShape* shape, float miterLimit);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the source texture of a shape
|
||||
///
|
||||
@@ -345,6 +375,16 @@ CSFML_GRAPHICS_API sfColor sfShape_getOutlineColor(const sfShape* shape);
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_GRAPHICS_API float sfShape_getOutlineThickness(const sfShape* shape);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the limit on the ratio between miter length and outline thickness of a shape
|
||||
///
|
||||
/// \param shape Shape object
|
||||
///
|
||||
/// \return Limit on the ratio between miter length and outline thickness
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_GRAPHICS_API float sfShape_getMiterLimit(const sfShape* shape);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the total number of points of a shape
|
||||
///
|
||||
|
||||
@@ -30,12 +30,15 @@
|
||||
#include <CSFML/Graphics/Export.h>
|
||||
|
||||
#include <CSFML/Graphics/Color.h>
|
||||
#include <CSFML/Graphics/Glyph.h>
|
||||
#include <CSFML/Graphics/Rect.h>
|
||||
#include <CSFML/Graphics/Transform.h>
|
||||
#include <CSFML/Graphics/Types.h>
|
||||
#include <CSFML/Graphics/Vertex.h>
|
||||
#include <CSFML/System/Vector2.h>
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
@@ -50,6 +53,102 @@ typedef enum
|
||||
sfTextStrikeThrough = 1 << 3 ///< Strike through characters
|
||||
} sfTextStyle;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Line alignment of a multi-line text
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
typedef enum
|
||||
{
|
||||
sfTextLineAlignmentDefault, ///< Automatically align lines by script direction, left-align left-to-right text and right-align right-to-left text
|
||||
sfTextLineAlignmentLeft, ///< Force align all lines to the left, regardless of script direction
|
||||
sfTextLineAlignmentCenter, ///< Force align all lines centrally
|
||||
sfTextLineAlignmentRight ///< Force align lines to the right, regardless of script direction
|
||||
} sfTextLineAlignment;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Cluster grouping algorithm
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
typedef enum
|
||||
{
|
||||
sfTextClusterGroupingGrapheme, ///< Group clusters by grapheme
|
||||
sfTextClusterGroupingCharacter, ///< Group clusters by character
|
||||
sfTextClusterGroupingNone ///< Do not group clusters
|
||||
} sfTextClusterGrouping;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Direction of the text a glyph belongs to
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
typedef enum
|
||||
{
|
||||
sfTextDirectionUnspecified, ///< Unspecified
|
||||
sfTextDirectionLeftToRight, ///< Left-to-right
|
||||
sfTextDirectionRightToLeft, ///< Right-to-left
|
||||
sfTextDirectionTopToBottom, ///< Top-to-bottom
|
||||
sfTextDirectionBottomToTop ///< Bottom-to-top
|
||||
} sfTextDirection;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Text orientation
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
typedef enum
|
||||
{
|
||||
sfTextOrientationDefault, ///< Default (left-to-right or right-to-left depending on detected script)
|
||||
sfTextOrientationTopToBottom, ///< Top-to-bottom
|
||||
sfTextOrientationBottomToTop ///< Bottom-to-top
|
||||
} sfTextOrientation;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Glyph that has been positioned by the shaper
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
typedef struct
|
||||
{
|
||||
sfGlyph glyph; ///< The glyph
|
||||
sfVector2f position; ///< Position of the glyph within a text
|
||||
uint32_t cluster; ///< Cluster ID
|
||||
sfTextDirection textDirection; ///< Text direction
|
||||
float baseline; ///< The baseline position of the line this glyph is a part of
|
||||
size_t vertexOffset; ///< Starting offset of the vertex data belonging to this glyph
|
||||
size_t vertexCount; ///< Count of vertices belonging to this glyph
|
||||
} sfShapedGlyph;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Callback that is provided with glyph data for pre-processing
|
||||
///
|
||||
/// The callback is called once per glyph whenever the text
|
||||
/// geometry is regenerated, in the order in which the glyph
|
||||
/// geometry is generated. The style, fill color, outline color
|
||||
/// and outline thickness of the glyph can be modified through
|
||||
/// the given pointers.
|
||||
///
|
||||
/// To map glyphs back to the input string, use the cluster
|
||||
/// value of the shaped glyph. See sf::Text::GlyphPreProcessor
|
||||
/// in the SFML documentation for a detailed explanation.
|
||||
///
|
||||
/// Changing the style or outline thickness might lead to
|
||||
/// slight inconsistencies of the text bounds, changing the
|
||||
/// fill or outline color is always safe. It is not safe to
|
||||
/// query the text bounds from within the callback.
|
||||
///
|
||||
/// \param shapedGlyph The shaped glyph to pre-process
|
||||
/// \param style Style of the glyph (see sfTextStyle enum)
|
||||
/// \param fillColor Fill color of the glyph
|
||||
/// \param outlineColor Outline color of the glyph
|
||||
/// \param outlineThickness Outline thickness of the glyph
|
||||
/// \param userData User data passed to sfText_setGlyphPreProcessor
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
typedef void (*sfGlyphPreProcessor)(
|
||||
const sfShapedGlyph* shapedGlyph,
|
||||
uint32_t* style,
|
||||
sfColor* fillColor,
|
||||
sfColor* outlineColor,
|
||||
float* outlineThickness,
|
||||
void* userData);
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Create a new text
|
||||
@@ -367,6 +466,31 @@ CSFML_GRAPHICS_API void sfText_setOutlineColor(sfText* text, sfColor color);
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_GRAPHICS_API void sfText_setOutlineThickness(sfText* text, float thickness);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Set the line alignment for a multi-line text
|
||||
///
|
||||
/// By default, the line alignment is sfTextLineAlignmentDefault.
|
||||
///
|
||||
/// \param text Text object
|
||||
/// \param lineAlignment New line alignment
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_GRAPHICS_API void sfText_setLineAlignment(sfText* text, sfTextLineAlignment lineAlignment);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Set the text orientation
|
||||
///
|
||||
/// By default, the text orientation is sfTextOrientationDefault.
|
||||
///
|
||||
/// Vertical text orientations require the font to provide
|
||||
/// vertical metrics, see sfFontInfo.
|
||||
///
|
||||
/// \param text Text object
|
||||
/// \param textOrientation New text orientation
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_GRAPHICS_API void sfText_setTextOrientation(sfText* text, sfTextOrientation textOrientation);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the string of a text (returns an ANSI string)
|
||||
///
|
||||
@@ -475,6 +599,26 @@ CSFML_GRAPHICS_API sfColor sfText_getOutlineColor(const sfText* text);
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_GRAPHICS_API float sfText_getOutlineThickness(const sfText* text);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the line alignment for a multi-line text
|
||||
///
|
||||
/// \param text Text object
|
||||
///
|
||||
/// \return Line alignment
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_GRAPHICS_API sfTextLineAlignment sfText_getLineAlignment(const sfText* text);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the text orientation
|
||||
///
|
||||
/// \param text Text object
|
||||
///
|
||||
/// \return Text orientation
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_GRAPHICS_API sfTextOrientation sfText_getTextOrientation(const sfText* text);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Return the position of the \a index-th character in a text
|
||||
///
|
||||
@@ -490,8 +634,113 @@ CSFML_GRAPHICS_API float sfText_getOutlineThickness(const sfText* text);
|
||||
///
|
||||
/// \return Position of the character
|
||||
///
|
||||
/// \deprecated Use sfText_getShapedGlyphs instead
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_GRAPHICS_API sfVector2f sfText_findCharacterPos(const sfText* text, size_t index);
|
||||
CSFML_GRAPHICS_API CSFML_DEPRECATED sfVector2f sfText_findCharacterPos(const sfText* text, size_t index);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the shaped glyphs that make up a text
|
||||
///
|
||||
/// The result of shaping, i.e. positioning individual glyphs
|
||||
/// based on the properties of the font and the input text,
|
||||
/// is a sequence of shaped glyphs. In addition to the glyph
|
||||
/// information that is available by looking up a glyph from
|
||||
/// a font, the glyph position, glyph cluster ID and direction
|
||||
/// of the text represented by the glyph is provided.
|
||||
///
|
||||
/// When positioning e.g. a cursor within the text, grapheme
|
||||
/// clusters can be treated as the basic units of which the
|
||||
/// text is composed. See sfText_setClusterGrouping.
|
||||
///
|
||||
/// The returned glyph positions are in local coordinates
|
||||
/// (translation, rotation, scale and origin are not applied).
|
||||
///
|
||||
/// The returned array is owned by the text and stays valid
|
||||
/// until the next call to this function or until the text
|
||||
/// is destroyed.
|
||||
///
|
||||
/// \param text Text object
|
||||
/// \param count Pointer to a variable that will be filled with the number of shaped glyphs
|
||||
///
|
||||
/// \return Pointer to the array of shaped glyphs
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_GRAPHICS_API const sfShapedGlyph* sfText_getShapedGlyphs(const sfText* text, size_t* count);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the cluster grouping algorithm in use
|
||||
///
|
||||
/// \param text Text object
|
||||
///
|
||||
/// \return The cluster grouping algorithm in use
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_GRAPHICS_API sfTextClusterGrouping sfText_getClusterGrouping(const sfText* text);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Set the cluster grouping algorithm to use
|
||||
///
|
||||
/// By default, character cluster grouping is used.
|
||||
///
|
||||
/// Character cluster grouping is good enough to be able to
|
||||
/// position cursors in most scenarios. If more coarse-grained
|
||||
/// grouping is required, grapheme grouping can be selected.
|
||||
///
|
||||
/// Cluster grouping can also be disabled if necessary.
|
||||
///
|
||||
/// \param text Text object
|
||||
/// \param clusterGrouping The cluster grouping algorithm to use
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_GRAPHICS_API void sfText_setClusterGrouping(sfText* text, sfTextClusterGrouping clusterGrouping);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Set the glyph pre-processor to be called per glyph
|
||||
///
|
||||
/// The glyph pre-processor is called with glyph data to be
|
||||
/// pre-processed whenever the text geometry is regenerated.
|
||||
///
|
||||
/// \param text Text object
|
||||
/// \param glyphPreProcessor The glyph pre-processor to be called per glyph, pass NULL to disable pre-processing
|
||||
/// \param userData User data that will be passed to the glyph pre-processor
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_GRAPHICS_API void sfText_setGlyphPreProcessor(sfText* text, sfGlyphPreProcessor glyphPreProcessor, void* userData);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the vertex data of a text
|
||||
///
|
||||
/// The vertices form triangles (sfTriangles).
|
||||
///
|
||||
/// The vertex data is regenerated by the text whenever it is
|
||||
/// necessary. Any changes made to the vertex data will be
|
||||
/// discarded whenever this happens.
|
||||
///
|
||||
/// \param text Text object
|
||||
/// \param count Pointer to a variable that will be filled with the number of vertices
|
||||
///
|
||||
/// \return Pointer to the vertex data of the text
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_GRAPHICS_API sfVertex* sfText_getVertexData(const sfText* text, size_t* count);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the outline vertex data of a text
|
||||
///
|
||||
/// The vertices form triangles (sfTriangles).
|
||||
///
|
||||
/// The outline vertex data is regenerated by the text whenever
|
||||
/// it is necessary. Any changes made to the outline vertex data
|
||||
/// will be discarded whenever this happens.
|
||||
///
|
||||
/// \param text Text object
|
||||
/// \param count Pointer to a variable that will be filled with the number of vertices
|
||||
///
|
||||
/// \return Pointer to the outline vertex data of the text
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_GRAPHICS_API sfVertex* sfText_getOutlineVertexData(const sfText* text, size_t* count);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the local bounding rectangle of a text
|
||||
|
||||
@@ -28,10 +28,12 @@
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#include <CSFML/Network/Dns.h>
|
||||
#include <CSFML/Network/Ftp.h>
|
||||
#include <CSFML/Network/Http.h>
|
||||
#include <CSFML/Network/IpAddress.h>
|
||||
#include <CSFML/Network/Packet.h>
|
||||
#include <CSFML/Network/Sftp.h>
|
||||
#include <CSFML/Network/SocketSelector.h>
|
||||
#include <CSFML/Network/SocketStatus.h>
|
||||
#include <CSFML/Network/TcpListener.h>
|
||||
|
||||
@@ -0,0 +1,288 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2026 Laurent Gomila (laurent@sfml-dev.org)
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <CSFML/Network/Export.h>
|
||||
|
||||
#include <CSFML/Network/IpAddress.h>
|
||||
#include <CSFML/Network/Types.h>
|
||||
#include <CSFML/System/Time.h>
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief A DNS MX record
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
typedef struct
|
||||
{
|
||||
const char* exchange; ///< Host willing to act as mail exchange
|
||||
uint16_t preference; ///< Preference of this record among others, lower values are preferred
|
||||
} sfDnsMxRecord;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief A DNS SRV record
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
typedef struct
|
||||
{
|
||||
const char* target; ///< The domain name of the target host
|
||||
uint16_t port; ///< The port on the target host of the service
|
||||
uint16_t weight; ///< Server selection mechanism, larger weights should be given a proportionately higher probability of being selected
|
||||
uint16_t priority; ///< The priority of the target host, a client must attempt to contact the target host with the lowest-numbered priority it can reach
|
||||
} sfDnsSrvRecord;
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Resolve a hostname into a list of IP addresses
|
||||
///
|
||||
/// The returned array must be freed with sfFree.
|
||||
///
|
||||
/// \param hostname Hostname to resolve, encoded in UTF-8
|
||||
/// \param servers The list of servers to query, NULL to use the default servers
|
||||
/// \param serverCount Number of servers in \a servers
|
||||
/// \param timeout Query timeout if using a provided list of servers, use 0 to wait forever
|
||||
/// \param count Pointer to a variable that will be filled with the number of addresses
|
||||
///
|
||||
/// \return Array of IP addresses the given hostname resolves to, NULL if name resolution fails or no address was found
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API sfIpAddress* sfDns_resolve(
|
||||
const char* hostname,
|
||||
const sfIpAddress* servers,
|
||||
size_t serverCount,
|
||||
sfTime timeout,
|
||||
size_t* count);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Query NS records for a hostname
|
||||
///
|
||||
/// \param hostname Hostname to query NS records for, encoded in UTF-8
|
||||
/// \param servers The list of servers to query, NULL to use the default servers
|
||||
/// \param serverCount Number of servers in \a servers
|
||||
/// \param timeout Query timeout if using a provided list of servers, use 0 to wait forever
|
||||
///
|
||||
/// \return New list of NS records, which can be empty
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API sfDnsNsRecords* sfDns_queryNs(const char* hostname, const sfIpAddress* servers, size_t serverCount, sfTime timeout);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Query MX records for a hostname
|
||||
///
|
||||
/// \param hostname Hostname to query MX records for, encoded in UTF-8
|
||||
/// \param servers The list of servers to query, NULL to use the default servers
|
||||
/// \param serverCount Number of servers in \a servers
|
||||
/// \param timeout Query timeout if using a provided list of servers, use 0 to wait forever
|
||||
///
|
||||
/// \return New list of MX records, which can be empty
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API sfDnsMxRecords* sfDns_queryMx(const char* hostname, const sfIpAddress* servers, size_t serverCount, sfTime timeout);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Query SRV records for a hostname
|
||||
///
|
||||
/// \param hostname Hostname to query SRV records for, encoded in UTF-8
|
||||
/// \param servers The list of servers to query, NULL to use the default servers
|
||||
/// \param serverCount Number of servers in \a servers
|
||||
/// \param timeout Query timeout if using a provided list of servers, use 0 to wait forever
|
||||
///
|
||||
/// \return New list of SRV records, which can be empty
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API sfDnsSrvRecords* sfDns_querySrv(const char* hostname, const sfIpAddress* servers, size_t serverCount, sfTime timeout);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Query TXT records for a hostname
|
||||
///
|
||||
/// \param hostname Hostname to query TXT records for, encoded in UTF-8
|
||||
/// \param servers The list of servers to query, NULL to use the default servers
|
||||
/// \param serverCount Number of servers in \a servers
|
||||
/// \param timeout Query timeout if using a provided list of servers, use 0 to wait forever
|
||||
///
|
||||
/// \return New list of TXT records, which can be empty
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API sfDnsTxtRecords* sfDns_queryTxt(const char* hostname, const sfIpAddress* servers, size_t serverCount, sfTime timeout);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the computer's public address via DNS
|
||||
///
|
||||
/// The public address is the address of the computer from the
|
||||
/// point of view of the internet, i.e. something like 89.54.1.169
|
||||
/// or 2600:1901:0:13e0::1 as opposed to a private or local address
|
||||
/// like 192.168.1.56 or fe80::1234:5678:9abc.
|
||||
///
|
||||
/// This function depends on both your network connection and
|
||||
/// the server, and may be very slow. You should try to use it
|
||||
/// as little as possible.
|
||||
///
|
||||
/// \param timeout Maximum time to wait, use 0 to wait forever
|
||||
/// \param type The type of public address to get
|
||||
///
|
||||
/// \return Public IP address of the computer on success, sfIpAddress_None otherwise
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API sfIpAddress sfDns_getPublicAddress(sfTime timeout, sfIpAddressType type);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Destroy a list of NS records
|
||||
///
|
||||
/// \param records List of NS records to destroy
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API void sfDnsNsRecords_destroy(const sfDnsNsRecords* records);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the number of NS records in a list
|
||||
///
|
||||
/// \param records List of NS records
|
||||
///
|
||||
/// \return Number of NS records
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API size_t sfDnsNsRecords_getCount(const sfDnsNsRecords* records);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get a NS record of a list
|
||||
///
|
||||
/// \param records List of NS records
|
||||
/// \param index Index of the NS record to get
|
||||
///
|
||||
/// \return The NS record, encoded in UTF-8
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API const char* sfDnsNsRecords_getRecord(const sfDnsNsRecords* records, size_t index);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Destroy a list of MX records
|
||||
///
|
||||
/// \param records List of MX records to destroy
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API void sfDnsMxRecords_destroy(const sfDnsMxRecords* records);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the number of MX records in a list
|
||||
///
|
||||
/// \param records List of MX records
|
||||
///
|
||||
/// \return Number of MX records
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API size_t sfDnsMxRecords_getCount(const sfDnsMxRecords* records);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get a MX record of a list
|
||||
///
|
||||
/// The strings of the record stay valid until the list
|
||||
/// is destroyed.
|
||||
///
|
||||
/// \param records List of MX records
|
||||
/// \param index Index of the MX record to get
|
||||
///
|
||||
/// \return The MX record
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API sfDnsMxRecord sfDnsMxRecords_getRecord(const sfDnsMxRecords* records, size_t index);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Destroy a list of SRV records
|
||||
///
|
||||
/// \param records List of SRV records to destroy
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API void sfDnsSrvRecords_destroy(const sfDnsSrvRecords* records);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the number of SRV records in a list
|
||||
///
|
||||
/// \param records List of SRV records
|
||||
///
|
||||
/// \return Number of SRV records
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API size_t sfDnsSrvRecords_getCount(const sfDnsSrvRecords* records);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get a SRV record of a list
|
||||
///
|
||||
/// The strings of the record stay valid until the list
|
||||
/// is destroyed.
|
||||
///
|
||||
/// \param records List of SRV records
|
||||
/// \param index Index of the SRV record to get
|
||||
///
|
||||
/// \return The SRV record
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API sfDnsSrvRecord sfDnsSrvRecords_getRecord(const sfDnsSrvRecords* records, size_t index);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Destroy a list of TXT records
|
||||
///
|
||||
/// \param records List of TXT records to destroy
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API void sfDnsTxtRecords_destroy(const sfDnsTxtRecords* records);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the number of TXT records in a list
|
||||
///
|
||||
/// \param records List of TXT records
|
||||
///
|
||||
/// \return Number of TXT records
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API size_t sfDnsTxtRecords_getCount(const sfDnsTxtRecords* records);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the number of strings in a TXT record
|
||||
///
|
||||
/// \param records List of TXT records
|
||||
/// \param index Index of the TXT record
|
||||
///
|
||||
/// \return Number of strings in the TXT record
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API size_t sfDnsTxtRecords_getStringCount(const sfDnsTxtRecords* records, size_t index);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get a string of a TXT record
|
||||
///
|
||||
/// \param records List of TXT records
|
||||
/// \param index Index of the TXT record
|
||||
/// \param stringIndex Index of the string within the TXT record
|
||||
///
|
||||
/// \return The string, encoded in UTF-8
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API const char* sfDnsTxtRecords_getString(const sfDnsTxtRecords* records, size_t index, size_t stringIndex);
|
||||
+111
-34
@@ -119,8 +119,10 @@ typedef enum
|
||||
///
|
||||
/// \param ftpListingResponse Ftp listing response to destroy
|
||||
///
|
||||
/// \deprecated Use sfSftp if possible
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API void sfFtpListingResponse_destroy(const sfFtpListingResponse* ftpListingResponse);
|
||||
CSFML_NETWORK_API CSFML_DEPRECATED void sfFtpListingResponse_destroy(const sfFtpListingResponse* ftpListingResponse);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Check if a FTP listing response status code means a success
|
||||
@@ -132,8 +134,10 @@ CSFML_NETWORK_API void sfFtpListingResponse_destroy(const sfFtpListingResponse*
|
||||
///
|
||||
/// \return true if the status is a success, false if it is a failure
|
||||
///
|
||||
/// \deprecated Use sfSftp if possible
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API bool sfFtpListingResponse_isOk(const sfFtpListingResponse* ftpListingResponse);
|
||||
CSFML_NETWORK_API CSFML_DEPRECATED bool sfFtpListingResponse_isOk(const sfFtpListingResponse* ftpListingResponse);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the status code of a FTP listing response
|
||||
@@ -142,8 +146,10 @@ CSFML_NETWORK_API bool sfFtpListingResponse_isOk(const sfFtpListingResponse* ftp
|
||||
///
|
||||
/// \return Status code
|
||||
///
|
||||
/// \deprecated Use sfSftp if possible
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API sfFtpStatus sfFtpListingResponse_getStatus(const sfFtpListingResponse* ftpListingResponse);
|
||||
CSFML_NETWORK_API CSFML_DEPRECATED sfFtpStatus sfFtpListingResponse_getStatus(const sfFtpListingResponse* ftpListingResponse);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the full message contained in a FTP listing response
|
||||
@@ -152,8 +158,10 @@ CSFML_NETWORK_API sfFtpStatus sfFtpListingResponse_getStatus(const sfFtpListingR
|
||||
///
|
||||
/// \return The response message
|
||||
///
|
||||
/// \deprecated Use sfSftp if possible
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API const char* sfFtpListingResponse_getMessage(const sfFtpListingResponse* ftpListingResponse);
|
||||
CSFML_NETWORK_API CSFML_DEPRECATED const char* sfFtpListingResponse_getMessage(const sfFtpListingResponse* ftpListingResponse);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Return the number of directory/file names contained in a FTP listing response
|
||||
@@ -162,8 +170,10 @@ CSFML_NETWORK_API const char* sfFtpListingResponse_getMessage(const sfFtpListing
|
||||
///
|
||||
/// \return Total number of names available
|
||||
///
|
||||
/// \deprecated Use sfSftp if possible
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API size_t sfFtpListingResponse_getCount(const sfFtpListingResponse* ftpListingResponse);
|
||||
CSFML_NETWORK_API CSFML_DEPRECATED size_t sfFtpListingResponse_getCount(const sfFtpListingResponse* ftpListingResponse);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Return a directory/file name contained in a FTP listing response
|
||||
@@ -173,16 +183,21 @@ CSFML_NETWORK_API size_t sfFtpListingResponse_getCount(const sfFtpListingRespons
|
||||
///
|
||||
/// \return The requested name
|
||||
///
|
||||
/// \deprecated Use sfSftp if possible
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API const char* sfFtpListingResponse_getName(const sfFtpListingResponse* ftpListingResponse, size_t index);
|
||||
CSFML_NETWORK_API CSFML_DEPRECATED const char* sfFtpListingResponse_getName(const sfFtpListingResponse* ftpListingResponse,
|
||||
size_t index);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Destroy a FTP directory response
|
||||
///
|
||||
/// \param ftpDirectoryResponse Ftp directory response to destroy
|
||||
///
|
||||
/// \deprecated Use sfSftp if possible
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API void sfFtpDirectoryResponse_destroy(const sfFtpDirectoryResponse* ftpDirectoryResponse);
|
||||
CSFML_NETWORK_API CSFML_DEPRECATED void sfFtpDirectoryResponse_destroy(const sfFtpDirectoryResponse* ftpDirectoryResponse);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Check if a FTP directory response status code means a success
|
||||
@@ -194,8 +209,10 @@ CSFML_NETWORK_API void sfFtpDirectoryResponse_destroy(const sfFtpDirectoryRespon
|
||||
///
|
||||
/// \return true if the status is a success, false if it is a failure
|
||||
///
|
||||
/// \deprecated Use sfSftp if possible
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API bool sfFtpDirectoryResponse_isOk(const sfFtpDirectoryResponse* ftpDirectoryResponse);
|
||||
CSFML_NETWORK_API CSFML_DEPRECATED bool sfFtpDirectoryResponse_isOk(const sfFtpDirectoryResponse* ftpDirectoryResponse);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the status code of a FTP directory response
|
||||
@@ -204,8 +221,11 @@ CSFML_NETWORK_API bool sfFtpDirectoryResponse_isOk(const sfFtpDirectoryResponse*
|
||||
///
|
||||
/// \return Status code
|
||||
///
|
||||
/// \deprecated Use sfSftp if possible
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API sfFtpStatus sfFtpDirectoryResponse_getStatus(const sfFtpDirectoryResponse* ftpDirectoryResponse);
|
||||
CSFML_NETWORK_API CSFML_DEPRECATED sfFtpStatus
|
||||
sfFtpDirectoryResponse_getStatus(const sfFtpDirectoryResponse* ftpDirectoryResponse);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the full message contained in a FTP directory response
|
||||
@@ -214,8 +234,11 @@ CSFML_NETWORK_API sfFtpStatus sfFtpDirectoryResponse_getStatus(const sfFtpDirect
|
||||
///
|
||||
/// \return The response message
|
||||
///
|
||||
/// \deprecated Use sfSftp if possible
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API const char* sfFtpDirectoryResponse_getMessage(const sfFtpDirectoryResponse* ftpDirectoryResponse);
|
||||
CSFML_NETWORK_API CSFML_DEPRECATED const char* sfFtpDirectoryResponse_getMessage(
|
||||
const sfFtpDirectoryResponse* ftpDirectoryResponse);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the directory returned in a FTP directory response
|
||||
@@ -227,8 +250,11 @@ CSFML_NETWORK_API const char* sfFtpDirectoryResponse_getMessage(const sfFtpDirec
|
||||
///
|
||||
/// \return Directory name or NULL if it failed
|
||||
///
|
||||
/// \deprecated Use sfSftp if possible
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API const char* sfFtpDirectoryResponse_getDirectory(const sfFtpDirectoryResponse* ftpDirectoryResponse);
|
||||
CSFML_NETWORK_API CSFML_DEPRECATED const char* sfFtpDirectoryResponse_getDirectory(
|
||||
const sfFtpDirectoryResponse* ftpDirectoryResponse);
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
@@ -241,8 +267,11 @@ CSFML_NETWORK_API const char* sfFtpDirectoryResponse_getDirectory(const sfFtpDir
|
||||
///
|
||||
/// \return Directory name or NULL if it failed
|
||||
///
|
||||
/// \deprecated Use sfSftp if possible
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API const sfChar32* sfFtpDirectoryResponse_getDirectoryUnicode(const sfFtpDirectoryResponse* ftpDirectoryResponse);
|
||||
CSFML_NETWORK_API CSFML_DEPRECATED const sfChar32* sfFtpDirectoryResponse_getDirectoryUnicode(
|
||||
const sfFtpDirectoryResponse* ftpDirectoryResponse);
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
@@ -250,8 +279,10 @@ CSFML_NETWORK_API const sfChar32* sfFtpDirectoryResponse_getDirectoryUnicode(con
|
||||
///
|
||||
/// \param ftpResponse Ftp response to destroy
|
||||
///
|
||||
/// \deprecated Use sfSftp if possible
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API void sfFtpResponse_destroy(const sfFtpResponse* ftpResponse);
|
||||
CSFML_NETWORK_API CSFML_DEPRECATED void sfFtpResponse_destroy(const sfFtpResponse* ftpResponse);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Check if a FTP response status code means a success
|
||||
@@ -263,8 +294,10 @@ CSFML_NETWORK_API void sfFtpResponse_destroy(const sfFtpResponse* ftpResponse);
|
||||
///
|
||||
/// \return true if the status is a success, false if it is a failure
|
||||
///
|
||||
/// \deprecated Use sfSftp if possible
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API bool sfFtpResponse_isOk(const sfFtpResponse* ftpResponse);
|
||||
CSFML_NETWORK_API CSFML_DEPRECATED bool sfFtpResponse_isOk(const sfFtpResponse* ftpResponse);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the status code of a FTP response
|
||||
@@ -273,8 +306,10 @@ CSFML_NETWORK_API bool sfFtpResponse_isOk(const sfFtpResponse* ftpResponse);
|
||||
///
|
||||
/// \return Status code
|
||||
///
|
||||
/// \deprecated Use sfSftp if possible
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API sfFtpStatus sfFtpResponse_getStatus(const sfFtpResponse* ftpResponse);
|
||||
CSFML_NETWORK_API CSFML_DEPRECATED sfFtpStatus sfFtpResponse_getStatus(const sfFtpResponse* ftpResponse);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the full message contained in a FTP response
|
||||
@@ -283,24 +318,30 @@ CSFML_NETWORK_API sfFtpStatus sfFtpResponse_getStatus(const sfFtpResponse* ftpRe
|
||||
///
|
||||
/// \return The response message
|
||||
///
|
||||
/// \deprecated Use sfSftp if possible
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API const char* sfFtpResponse_getMessage(const sfFtpResponse* ftpResponse);
|
||||
CSFML_NETWORK_API CSFML_DEPRECATED const char* sfFtpResponse_getMessage(const sfFtpResponse* ftpResponse);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Create a new Ftp object
|
||||
///
|
||||
/// \return A new sfFtp object
|
||||
///
|
||||
/// \deprecated Use sfSftp if possible
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API sfFtp* sfFtp_create(void);
|
||||
CSFML_NETWORK_API CSFML_DEPRECATED sfFtp* sfFtp_create(void);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Destroy a Ftp object
|
||||
///
|
||||
/// \param ftp Ftp object to destroy
|
||||
///
|
||||
/// \deprecated Use sfSftp if possible
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API void sfFtp_destroy(const sfFtp* ftp);
|
||||
CSFML_NETWORK_API CSFML_DEPRECATED void sfFtp_destroy(const sfFtp* ftp);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Connect to the specified FTP server
|
||||
@@ -321,8 +362,10 @@ CSFML_NETWORK_API void sfFtp_destroy(const sfFtp* ftp);
|
||||
///
|
||||
/// \return Server response to the request
|
||||
///
|
||||
/// \deprecated Use sfSftp if possible
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API sfFtpResponse* sfFtp_connect(sfFtp* ftp, sfIpAddress server, unsigned short port, sfTime timeout);
|
||||
CSFML_NETWORK_API CSFML_DEPRECATED sfFtpResponse* sfFtp_connect(sfFtp* ftp, sfIpAddress server, unsigned short port, sfTime timeout);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Log in using an anonymous account
|
||||
@@ -334,8 +377,10 @@ CSFML_NETWORK_API sfFtpResponse* sfFtp_connect(sfFtp* ftp, sfIpAddress server, u
|
||||
///
|
||||
/// \return Server response to the request
|
||||
///
|
||||
/// \deprecated Use sfSftp if possible
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API sfFtpResponse* sfFtp_loginAnonymous(sfFtp* ftp);
|
||||
CSFML_NETWORK_API CSFML_DEPRECATED sfFtpResponse* sfFtp_loginAnonymous(sfFtp* ftp);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Log in using a username and a password
|
||||
@@ -349,8 +394,10 @@ CSFML_NETWORK_API sfFtpResponse* sfFtp_loginAnonymous(sfFtp* ftp);
|
||||
///
|
||||
/// \return Server response to the request
|
||||
///
|
||||
/// \deprecated Use sfSftp if possible
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API sfFtpResponse* sfFtp_login(sfFtp* ftp, const char* name, const char* password);
|
||||
CSFML_NETWORK_API CSFML_DEPRECATED sfFtpResponse* sfFtp_login(sfFtp* ftp, const char* name, const char* password);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Close the connection with the server
|
||||
@@ -359,8 +406,10 @@ CSFML_NETWORK_API sfFtpResponse* sfFtp_login(sfFtp* ftp, const char* name, const
|
||||
///
|
||||
/// \return Server response to the request
|
||||
///
|
||||
/// \deprecated Use sfSftp if possible
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API sfFtpResponse* sfFtp_disconnect(sfFtp* ftp);
|
||||
CSFML_NETWORK_API CSFML_DEPRECATED sfFtpResponse* sfFtp_disconnect(sfFtp* ftp);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Send a null command to keep the connection alive
|
||||
@@ -372,8 +421,10 @@ CSFML_NETWORK_API sfFtpResponse* sfFtp_disconnect(sfFtp* ftp);
|
||||
///
|
||||
/// \return Server response to the request
|
||||
///
|
||||
/// \deprecated Use sfSftp if possible
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API sfFtpResponse* sfFtp_keepAlive(sfFtp* ftp);
|
||||
CSFML_NETWORK_API CSFML_DEPRECATED sfFtpResponse* sfFtp_keepAlive(sfFtp* ftp);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the current working directory
|
||||
@@ -385,8 +436,10 @@ CSFML_NETWORK_API sfFtpResponse* sfFtp_keepAlive(sfFtp* ftp);
|
||||
///
|
||||
/// \return Server response to the request
|
||||
///
|
||||
/// \deprecated Use sfSftp if possible
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API sfFtpDirectoryResponse* sfFtp_getWorkingDirectory(sfFtp* ftp);
|
||||
CSFML_NETWORK_API CSFML_DEPRECATED sfFtpDirectoryResponse* sfFtp_getWorkingDirectory(sfFtp* ftp);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the contents of the given directory
|
||||
@@ -401,8 +454,10 @@ CSFML_NETWORK_API sfFtpDirectoryResponse* sfFtp_getWorkingDirectory(sfFtp* ftp);
|
||||
///
|
||||
/// \return Server response to the request
|
||||
///
|
||||
/// \deprecated Use sfSftp if possible
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API sfFtpListingResponse* sfFtp_getDirectoryListing(sfFtp* ftp, const char* directory);
|
||||
CSFML_NETWORK_API CSFML_DEPRECATED sfFtpListingResponse* sfFtp_getDirectoryListing(sfFtp* ftp, const char* directory);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Change the current working directory
|
||||
@@ -414,8 +469,10 @@ CSFML_NETWORK_API sfFtpListingResponse* sfFtp_getDirectoryListing(sfFtp* ftp, co
|
||||
///
|
||||
/// \return Server response to the request
|
||||
///
|
||||
/// \deprecated Use sfSftp if possible
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API sfFtpResponse* sfFtp_changeDirectory(sfFtp* ftp, const char* directory);
|
||||
CSFML_NETWORK_API CSFML_DEPRECATED sfFtpResponse* sfFtp_changeDirectory(sfFtp* ftp, const char* directory);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Go to the parent directory of the current one
|
||||
@@ -424,8 +481,10 @@ CSFML_NETWORK_API sfFtpResponse* sfFtp_changeDirectory(sfFtp* ftp, const char* d
|
||||
///
|
||||
/// \return Server response to the request
|
||||
///
|
||||
/// \deprecated Use sfSftp if possible
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API sfFtpResponse* sfFtp_parentDirectory(sfFtp* ftp);
|
||||
CSFML_NETWORK_API CSFML_DEPRECATED sfFtpResponse* sfFtp_parentDirectory(sfFtp* ftp);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Create a new directory
|
||||
@@ -438,8 +497,10 @@ CSFML_NETWORK_API sfFtpResponse* sfFtp_parentDirectory(sfFtp* ftp);
|
||||
///
|
||||
/// \return Server response to the request
|
||||
///
|
||||
/// \deprecated Use sfSftp if possible
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API sfFtpResponse* sfFtp_createDirectory(sfFtp* ftp, const char* name);
|
||||
CSFML_NETWORK_API CSFML_DEPRECATED sfFtpResponse* sfFtp_createDirectory(sfFtp* ftp, const char* name);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Remove an existing directory
|
||||
@@ -454,8 +515,10 @@ CSFML_NETWORK_API sfFtpResponse* sfFtp_createDirectory(sfFtp* ftp, const char* n
|
||||
///
|
||||
/// \return Server response to the request
|
||||
///
|
||||
/// \deprecated Use sfSftp if possible
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API sfFtpResponse* sfFtp_deleteDirectory(sfFtp* ftp, const char* name);
|
||||
CSFML_NETWORK_API CSFML_DEPRECATED sfFtpResponse* sfFtp_deleteDirectory(sfFtp* ftp, const char* name);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Rename an existing file
|
||||
@@ -469,8 +532,10 @@ CSFML_NETWORK_API sfFtpResponse* sfFtp_deleteDirectory(sfFtp* ftp, const char* n
|
||||
///
|
||||
/// \return Server response to the request
|
||||
///
|
||||
/// \deprecated Use sfSftp if possible
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API sfFtpResponse* sfFtp_renameFile(sfFtp* ftp, const char* file, const char* newName);
|
||||
CSFML_NETWORK_API CSFML_DEPRECATED sfFtpResponse* sfFtp_renameFile(sfFtp* ftp, const char* file, const char* newName);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Remove an existing file
|
||||
@@ -485,8 +550,10 @@ CSFML_NETWORK_API sfFtpResponse* sfFtp_renameFile(sfFtp* ftp, const char* file,
|
||||
///
|
||||
/// \return Server response to the request
|
||||
///
|
||||
/// \deprecated Use sfSftp if possible
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API sfFtpResponse* sfFtp_deleteFile(sfFtp* ftp, const char* name);
|
||||
CSFML_NETWORK_API CSFML_DEPRECATED sfFtpResponse* sfFtp_deleteFile(sfFtp* ftp, const char* name);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Download a file from a FTP server
|
||||
@@ -503,8 +570,14 @@ CSFML_NETWORK_API sfFtpResponse* sfFtp_deleteFile(sfFtp* ftp, const char* name);
|
||||
///
|
||||
/// \return Server response to the request
|
||||
///
|
||||
/// \deprecated Use sfSftp if possible
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API sfFtpResponse* sfFtp_download(sfFtp* ftp, const char* remoteFile, const char* localPath, sfFtpTransferMode mode);
|
||||
CSFML_NETWORK_API CSFML_DEPRECATED sfFtpResponse* sfFtp_download(
|
||||
sfFtp* ftp,
|
||||
const char* remoteFile,
|
||||
const char* localPath,
|
||||
sfFtpTransferMode mode);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Upload a file to a FTP server
|
||||
@@ -522,8 +595,10 @@ CSFML_NETWORK_API sfFtpResponse* sfFtp_download(sfFtp* ftp, const char* remoteFi
|
||||
///
|
||||
/// \return Server response to the request
|
||||
///
|
||||
/// \deprecated Use sfSftp if possible
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API sfFtpResponse* sfFtp_upload(
|
||||
CSFML_NETWORK_API CSFML_DEPRECATED sfFtpResponse* sfFtp_upload(
|
||||
sfFtp* ftp,
|
||||
const char* localFile,
|
||||
const char* remotePath,
|
||||
@@ -547,5 +622,7 @@ CSFML_NETWORK_API sfFtpResponse* sfFtp_upload(
|
||||
///
|
||||
/// \return Server response to the request
|
||||
///
|
||||
/// \deprecated Use sfSftp if possible
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API sfFtpResponse* sfFtp_sendCommand(sfFtp* ftp, const char* command, const char* parameter);
|
||||
CSFML_NETWORK_API CSFML_DEPRECATED sfFtpResponse* sfFtp_sendCommand(sfFtp* ftp, const char* command, const char* parameter);
|
||||
@@ -29,9 +29,12 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <CSFML/Network/Export.h>
|
||||
|
||||
#include <CSFML/Network/IpAddress.h>
|
||||
#include <CSFML/Network/Types.h>
|
||||
#include <CSFML/System/Time.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Enumerate the available HTTP methods for a request
|
||||
@@ -272,12 +275,35 @@ CSFML_NETWORK_API void sfHttp_destroy(const sfHttp* http);
|
||||
/// leave it like this unless you really need a port other
|
||||
/// than the standard one, or use an unknown protocol.
|
||||
///
|
||||
/// The host is resolved immediately. To use HTTPS, prefix
|
||||
/// the host with "https://".
|
||||
///
|
||||
/// \param http Http object
|
||||
/// \param host Web server to connect to
|
||||
/// \param port Port to use for connection
|
||||
///
|
||||
/// \return True if the host has been resolved and is valid, false otherwise
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API void sfHttp_setHost(sfHttp* http, const char* host, unsigned short port);
|
||||
CSFML_NETWORK_API bool sfHttp_setHost(sfHttp* http, const char* host, unsigned short port);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Set the target host of a HTTP object with a given address type
|
||||
///
|
||||
/// See sfHttp_setHost for details.
|
||||
///
|
||||
/// \param http Http object
|
||||
/// \param host Web server to connect to
|
||||
/// \param port Port to use for connection
|
||||
/// \param addressType Address type to use for the connection, NULL to specify no preference
|
||||
///
|
||||
/// \return True if the host has been resolved and is valid, false otherwise
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API bool sfHttp_setHostWithAddressType(sfHttp* http,
|
||||
const char* host,
|
||||
unsigned short port,
|
||||
const sfIpAddressType* addressType);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Send a HTTP request and return the server's response.
|
||||
@@ -299,3 +325,23 @@ CSFML_NETWORK_API void sfHttp_setHost(sfHttp* http, const char* host, unsigned s
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API sfHttpResponse* sfHttp_sendRequest(sfHttp* http, const sfHttpRequest* request, sfTime timeout);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Send a HTTP request and return the server's response, optionally without verifying the server
|
||||
///
|
||||
/// See sfHttp_sendRequest for details. sfHttp_sendRequest
|
||||
/// always verifies the server when using HTTPS.
|
||||
///
|
||||
/// \param http Http object
|
||||
/// \param request Request to send
|
||||
/// \param timeout Maximum time to wait
|
||||
/// \param verifyServer Verify the server if using HTTPS
|
||||
///
|
||||
/// \return Server's response
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API sfHttpResponse* sfHttp_sendRequestWithVerification(
|
||||
const sfHttp* http,
|
||||
const sfHttpRequest* request,
|
||||
sfTime timeout,
|
||||
bool verifyServer);
|
||||
@@ -31,17 +31,34 @@
|
||||
|
||||
#include <CSFML/System/Time.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Encapsulate an IPv4 network address
|
||||
/// \brief Encapsulate an IPv4 or IPv6 network address
|
||||
///
|
||||
/// The address is stored as its string representation,
|
||||
/// which is large enough to hold any IPv6 address.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
typedef struct
|
||||
{
|
||||
char address[16];
|
||||
char address[46];
|
||||
} sfIpAddress;
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Type of an IP address
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
typedef enum
|
||||
{
|
||||
sfIpAddressV4, ///< IPv4 address
|
||||
sfIpAddressV6 ///< IPv6 address
|
||||
} sfIpAddressType;
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Empty object that represents invalid addresses
|
||||
///
|
||||
@@ -49,36 +66,85 @@ typedef struct
|
||||
CSFML_NETWORK_API const sfIpAddress sfIpAddress_None;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Value representing any address (0.0.0.0)
|
||||
/// \brief The same as sfIpAddress_AnyV4
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API const sfIpAddress sfIpAddress_Any;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Local host IP address (127.0.0.1, or "localhost")
|
||||
/// \brief The same as sfIpAddress_LocalHostV4
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API const sfIpAddress sfIpAddress_LocalHost;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief UDP broadcast address (255.255.255.255)
|
||||
/// \brief The same as sfIpAddress_BroadcastV4
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API const sfIpAddress sfIpAddress_Broadcast;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Create an address from a string
|
||||
/// \brief Value representing any IPv4 address (0.0.0.0)
|
||||
///
|
||||
/// Here \a address can be either a decimal address
|
||||
/// (ex: "192.168.1.56") or a network name (ex: "localhost").
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API const sfIpAddress sfIpAddress_AnyV4;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Local host IPv4 address (127.0.0.1)
|
||||
///
|
||||
/// \param address IP address or network name
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API const sfIpAddress sfIpAddress_LocalHostV4;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief UDP broadcast IPv4 address (255.255.255.255)
|
||||
///
|
||||
/// \return Resulting address
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API const sfIpAddress sfIpAddress_BroadcastV4;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Value representing any IPv6 address (::)
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API const sfIpAddress sfIpAddress_AnyV6;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Local host IPv6 address (::1)
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API const sfIpAddress sfIpAddress_LocalHostV6;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Create an address from a string representation
|
||||
///
|
||||
/// Here \a address can be either an IPv4 address in
|
||||
/// dotted-decimal notation (ex: "192.168.1.56") or an IPv6
|
||||
/// address in standard notation (ex: "2606:4700:4700::1111").
|
||||
/// Network names are not resolved, use sfDns_resolve or
|
||||
/// sfIpAddress_resolve for that.
|
||||
///
|
||||
/// \param address IP address string
|
||||
///
|
||||
/// \return Resulting address or sfIpAddress_None if the string is not a valid address
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API sfIpAddress sfIpAddress_fromString(const char* address);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Create an IPv4 address from a string or by resolving a network name
|
||||
///
|
||||
/// Here \a address can be either a decimal address
|
||||
/// (ex: "192.168.1.56") or a network name (ex: "localhost").
|
||||
/// Only IPv4 addresses are returned.
|
||||
///
|
||||
/// \param address IP address or network name
|
||||
///
|
||||
/// \return Resulting address or sfIpAddress_None if the address could not be resolved
|
||||
///
|
||||
/// \deprecated Use sfDns_resolve instead
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API CSFML_DEPRECATED sfIpAddress sfIpAddress_resolve(const char* address);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Create an address from 4 bytes
|
||||
///
|
||||
@@ -112,12 +178,24 @@ CSFML_NETWORK_API sfIpAddress sfIpAddress_fromBytes(uint8_t byte0, uint8_t byte1
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API sfIpAddress sfIpAddress_fromInteger(uint32_t address);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Create an IPv6 address from 16 bytes
|
||||
///
|
||||
/// \param bytes Array of 16 bytes containing the address
|
||||
///
|
||||
/// \return Resulting address
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API sfIpAddress sfIpAddress_fromV6Bytes(const uint8_t bytes[16]);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get a string representation of an address
|
||||
///
|
||||
/// The returned string is the decimal representation of the
|
||||
/// IP address (like "192.168.1.56"), even if it was constructed
|
||||
/// from a host name.
|
||||
/// IPv4 address (like "192.168.1.56") or the standard
|
||||
/// representation of the IPv6 address (like "2606:4700:4700::1111"),
|
||||
/// even if it was constructed from a host name.
|
||||
/// The string must be able to hold at least 46 characters.
|
||||
///
|
||||
/// \param address Address object
|
||||
/// \param string String where the string representation will be stored
|
||||
@@ -134,6 +212,9 @@ CSFML_NETWORK_API void sfIpAddress_toString(sfIpAddress address, char* string);
|
||||
/// The integer produced by this function can then be converted
|
||||
/// back to a sfIpAddress with sfIpAddress_fromInteger.
|
||||
///
|
||||
/// Only IPv4 addresses can be converted to an integer, 0 is
|
||||
/// returned for IPv6 addresses.
|
||||
///
|
||||
/// \param address Address object
|
||||
///
|
||||
/// \return 32-bits unsigned integer representation of the address
|
||||
@@ -141,6 +222,50 @@ CSFML_NETWORK_API void sfIpAddress_toString(sfIpAddress address, char* string);
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API uint32_t sfIpAddress_toInteger(sfIpAddress address);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get a 16-byte representation of an IPv6 address
|
||||
///
|
||||
/// The bytes produced by this function can then be converted
|
||||
/// back to a sfIpAddress with sfIpAddress_fromV6Bytes.
|
||||
///
|
||||
/// \param address Address object
|
||||
/// \param bytes Array of 16 bytes that will be filled with the address
|
||||
///
|
||||
/// \return True if the address is a valid IPv6 address and the bytes have been written, false otherwise
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API bool sfIpAddress_toV6Bytes(sfIpAddress address, uint8_t bytes[16]);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the type of an address
|
||||
///
|
||||
/// \param address Address object
|
||||
///
|
||||
/// \return The type of the address, sfIpAddressV4 is returned for invalid addresses
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API sfIpAddressType sfIpAddress_getType(sfIpAddress address);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Check if an address is a valid IPv4 address
|
||||
///
|
||||
/// \param address Address object
|
||||
///
|
||||
/// \return True if the address is a valid IPv4 address
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API bool sfIpAddress_isV4(sfIpAddress address);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Check if an address is a valid IPv6 address
|
||||
///
|
||||
/// \param address Address object
|
||||
///
|
||||
/// \return True if the address is a valid IPv6 address
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API bool sfIpAddress_isV6(sfIpAddress address);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the computer's local address
|
||||
///
|
||||
@@ -150,11 +275,28 @@ CSFML_NETWORK_API uint32_t sfIpAddress_toInteger(sfIpAddress address);
|
||||
/// Unlike sfIpAddress_getPublicAddress, this function is fast
|
||||
/// and may be used safely anywhere.
|
||||
///
|
||||
/// This returns the local IPv4 address.
|
||||
///
|
||||
/// \return Local IP address of the computer
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API sfIpAddress sfIpAddress_getLocalAddress(void);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the computer's local address of a given type
|
||||
///
|
||||
/// The local address is the address of the computer from the
|
||||
/// LAN point of view, i.e. something like 192.168.1.56 or
|
||||
/// fe80::1234:5678:9abc. It is meaningful only for
|
||||
/// communications over the local network.
|
||||
///
|
||||
/// \param type The type of local address to get
|
||||
///
|
||||
/// \return Local IP address of the computer or sfIpAddress_None if there is none
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API sfIpAddress sfIpAddress_getLocalAddressOfType(sfIpAddressType type);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the computer's public address
|
||||
///
|
||||
@@ -170,9 +312,31 @@ CSFML_NETWORK_API sfIpAddress sfIpAddress_getLocalAddress(void);
|
||||
/// to be possibly stuck waiting in case there is a problem; use
|
||||
/// 0 to deactivate this limit.
|
||||
///
|
||||
/// This returns the public IPv4 address.
|
||||
///
|
||||
/// \param timeout Maximum time to wait
|
||||
///
|
||||
/// \return Public IP address of the computer
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API sfIpAddress sfIpAddress_getPublicAddress(sfTime timeout);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the computer's public address of a given type
|
||||
///
|
||||
/// The public address is the address of the computer from the
|
||||
/// internet point of view, i.e. something like 89.54.1.169 or
|
||||
/// 2600:1901:0:13e0::1. See sfIpAddress_getPublicAddress for
|
||||
/// details.
|
||||
///
|
||||
/// If tamper resistance is required, setting \a secure to true
|
||||
/// will make use of verified HTTPS connections to get the address.
|
||||
///
|
||||
/// \param timeout Maximum time to wait, use 0 to deactivate the limit
|
||||
/// \param type The type of public address to get, NULL to specify no preference
|
||||
/// \param secure True to retrieve the public address via a secure HTTPS connection, false to retrieve via DNS or an insecure connection
|
||||
///
|
||||
/// \return Public IP address of the computer or sfIpAddress_None on failure
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API sfIpAddress sfIpAddress_getPublicAddressOfType(sfTime timeout, const sfIpAddressType* type, bool secure);
|
||||
@@ -0,0 +1,778 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2026 Laurent Gomila (laurent@sfml-dev.org)
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <CSFML/Network/Export.h>
|
||||
|
||||
#include <CSFML/Network/IpAddress.h>
|
||||
#include <CSFML/Network/Types.h>
|
||||
#include <CSFML/System/TimeoutWithPredicate.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Values of a SFTP result
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
typedef enum
|
||||
{
|
||||
// General result values
|
||||
sfSftpSuccess, ///< Operation completed successfully
|
||||
sfSftpDisconnected, ///< The TCP socket has been disconnected
|
||||
sfSftpTimeout, ///< Operation timed out
|
||||
sfSftpRefused, ///< Connection refused
|
||||
sfSftpError, ///< Generic error
|
||||
|
||||
// SSH result values
|
||||
sfSftpBannerReceive, ///< Error during banner receive
|
||||
sfSftpBannerSend, ///< Error during banner send
|
||||
sfSftpInvalidMac, ///< Invalid message authentication code
|
||||
sfSftpAllocationFailure, ///< Allocation failure
|
||||
sfSftpSocketSend, ///< Error sending on socket
|
||||
sfSftpKeyExchangeFailure, ///< Key exchange failed
|
||||
sfSftpHostKeyInitialization, ///< Host key initialization failed
|
||||
sfSftpHostKeySign, ///< Host key signing failed
|
||||
sfSftpDecryptError, ///< Decryption failed
|
||||
sfSftpProtocolError, ///< SSH protocol error
|
||||
sfSftpPasswordExpired, ///< Password expired
|
||||
sfSftpFileError, ///< File error
|
||||
sfSftpMethodNone, ///< No method found
|
||||
sfSftpAuthenticationFailed, ///< Authentication failed
|
||||
sfSftpPublicKeyUnverified, ///< Public key unverified
|
||||
sfSftpChannelOutOfOrder, ///< Channel out of order
|
||||
sfSftpChannelFailure, ///< Channel failure
|
||||
sfSftpChannelRequestDenied, ///< Channel request denied
|
||||
sfSftpChannelUnknown, ///< Channel unknown
|
||||
sfSftpChannelWindowExceeded, ///< Channel window exceeded
|
||||
sfSftpChannelPacketExceeded, ///< Channel packet exceeded
|
||||
sfSftpChannelClosed, ///< Channel closed
|
||||
sfSftpChannelEofSent, ///< Channel EOF sent
|
||||
sfSftpScpProtocol, ///< SCP protocol error
|
||||
sfSftpZlibError, ///< Zlib error
|
||||
sfSftpRequestDenied, ///< Request denied
|
||||
sfSftpMethodNotSupported, ///< Method not supported
|
||||
sfSftpInvalidData, ///< Invalid data
|
||||
sfSftpPublicKeyProtocol, ///< Public key protocol error
|
||||
sfSftpBufferTooSmall, ///< Buffer too small
|
||||
sfSftpBadUse, ///< Bad usage
|
||||
sfSftpCompressError, ///< Compression error
|
||||
sfSftpOutOfBoundary, ///< Out of boundary
|
||||
sfSftpAgentProtocol, ///< Agent protocol error
|
||||
sfSftpSocketRecv, ///< Socket receive error
|
||||
sfSftpEncryptError, ///< Encryption failed
|
||||
sfSftpBadSocket, ///< Bad socket
|
||||
sfSftpKnownHosts, ///< Known hosts error
|
||||
sfSftpChannelWindowFull, ///< Channel window full
|
||||
sfSftpKeyFileAuthenticationFailed, ///< Key file authentication failed
|
||||
|
||||
// SFTP result values
|
||||
sfSftpEndOfFile, ///< End of file
|
||||
sfSftpNoSuchFile, ///< No such file
|
||||
sfSftpPermissionDenied, ///< Permission denied
|
||||
sfSftpFailure, ///< Failure
|
||||
sfSftpBadMessage, ///< Bad message
|
||||
sfSftpNoConnection, ///< No connection
|
||||
sfSftpConnectionLost, ///< Connection lost
|
||||
sfSftpOperationUnsupported, ///< Operation unsupported
|
||||
sfSftpInvalidHandle, ///< Invalid handle
|
||||
sfSftpNoSuchPath, ///< No such path
|
||||
sfSftpFileAlreadyExists, ///< File already exists
|
||||
sfSftpWriteProtect, ///< Write protect
|
||||
sfSftpNoMedia, ///< No media
|
||||
sfSftpNoSpaceOnFileSystem, ///< No space on filesystem
|
||||
sfSftpQuotaExceeded, ///< Quota exceeded
|
||||
sfSftpUnknownPrincipal, ///< Unknown principal
|
||||
sfSftpLockConflict, ///< Lock conflict
|
||||
sfSftpDirectoryNotEmpty, ///< Directory not empty
|
||||
sfSftpNotADirectory, ///< Not a directory
|
||||
sfSftpInvalidFilename, ///< Invalid filename
|
||||
sfSftpLinkLoop, ///< Link loop
|
||||
sfSftpSftpError ///< Generic SFTP error
|
||||
} sfSftpResultValue;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Type of a remote file system entry
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
typedef enum
|
||||
{
|
||||
sfSftpFileNone, ///< No type
|
||||
sfSftpFileNotFound, ///< The file does not exist
|
||||
sfSftpFileRegular, ///< Regular file
|
||||
sfSftpFileDirectory, ///< Directory
|
||||
sfSftpFileSymlink, ///< Symbolic link
|
||||
sfSftpFileBlock, ///< Block special file
|
||||
sfSftpFileCharacter, ///< Character special file
|
||||
sfSftpFileFifo, ///< FIFO or pipe
|
||||
sfSftpFileSocket, ///< Socket
|
||||
sfSftpFileUnknown ///< Unknown type
|
||||
} sfSftpFileType;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Attributes of a remote file system entry
|
||||
///
|
||||
/// Each attribute is only valid if the corresponding
|
||||
/// has-flag is set.
|
||||
///
|
||||
/// Permissions use the POSIX permission bits, e.g. 0755.
|
||||
/// Times are given in seconds since the Unix epoch.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
typedef struct
|
||||
{
|
||||
const char* path; ///< Path to the entry, encoded in UTF-8
|
||||
uint64_t size; ///< Size of the entry
|
||||
uint64_t userId; ///< Owner user ID
|
||||
uint64_t groupId; ///< Group ID
|
||||
int64_t accessTime; ///< Last access time
|
||||
int64_t modificationTime; ///< Last modification time
|
||||
sfSftpFileType type; ///< Type of the entry
|
||||
uint32_t permissions; ///< Permissions
|
||||
bool hasType; ///< Whether the type is available
|
||||
bool hasSize; ///< Whether the size is available
|
||||
bool hasPermissions; ///< Whether the permissions are available
|
||||
bool hasUserId; ///< Whether the owner user ID is available
|
||||
bool hasGroupId; ///< Whether the group ID is available
|
||||
bool hasAccessTime; ///< Whether the last access time is available
|
||||
bool hasModificationTime; ///< Whether the last modification time is available
|
||||
} sfSftpAttributes;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Type of a SSH host key
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
typedef enum
|
||||
{
|
||||
sfSftpHostKeyUnknown, ///< Unknown key type
|
||||
sfSftpHostKeyRsa, ///< RSA
|
||||
sfSftpHostKeyDsa, ///< DSA
|
||||
sfSftpHostKeyEcdsa256, ///< NIST P-256 ECDSA
|
||||
sfSftpHostKeyEcdsa384, ///< NIST P-384 ECDSA
|
||||
sfSftpHostKeyEcdsa521, ///< NIST P-521 ECDSA
|
||||
sfSftpHostKeyEd25519 ///< ED25519
|
||||
} sfSftpHostKeyType;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief SSH session information
|
||||
///
|
||||
/// The algorithm identifiers follow the RFC 4253 specification.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
typedef struct
|
||||
{
|
||||
sfSftpHostKeyType hostKeyType; ///< Host key type
|
||||
const uint8_t* hostKeyData; ///< Host key data
|
||||
size_t hostKeySize; ///< Size of the host key data
|
||||
uint8_t hostKeySha1[20]; ///< Host key SHA1 hash
|
||||
uint8_t hostKeySha256[32]; ///< Host key SHA256 hash
|
||||
const char* keyExchangeAlgorithm; ///< Key exchange algorithm used in the session
|
||||
const char* hostKeyAlgorithm; ///< Host key algorithm used in the session
|
||||
const char* clientToServerEncryptionAlgorithm; ///< Client to server encryption algorithm used in the session
|
||||
const char* serverToClientEncryptionAlgorithm; ///< Server to client encryption algorithm used in the session
|
||||
const char* clientToServerMacAlgorithm; ///< Client to server message authentication code algorithm used in the session
|
||||
const char* serverToClientMacAlgorithm; ///< Server to client message authentication code algorithm used in the session
|
||||
const char* clientToServerCompressionAlgorithm; ///< Client to server compression algorithm used in the session
|
||||
const char* serverToClientCompressionAlgorithm; ///< Server to client compression algorithm used in the session
|
||||
} sfSftpSessionInfo;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Callback receiving the data of a downloaded file
|
||||
///
|
||||
/// The data is transferred in sequential blocks. The size of
|
||||
/// the blocks can change over time.
|
||||
///
|
||||
/// \param data Pointer to the received data block
|
||||
/// \param size Size of the received data block
|
||||
/// \param userData User data passed to sfSftp_download
|
||||
///
|
||||
/// \return True to continue the transfer, false to abort it
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
typedef bool (*sfSftpDownloadCallback)(const void* data, size_t size, void* userData);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Callback providing the data of a file to upload
|
||||
///
|
||||
/// Data to be sent should be copied into the data block and
|
||||
/// \a size set to the actual number of bytes copied. When
|
||||
/// called, \a size contains the size of the data block, which
|
||||
/// can change over time.
|
||||
///
|
||||
/// \param data Pointer to the data block to fill
|
||||
/// \param size Size of the data block, to be set to the number of bytes copied
|
||||
/// \param userData User data passed to sfSftp_upload
|
||||
///
|
||||
/// \return True to continue the transfer, false to stop it e.g. because there is no more data to send
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
typedef bool (*sfSftpUploadCallback)(void* data, size_t* size, void* userData);
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Destroy a SFTP result
|
||||
///
|
||||
/// \param result SFTP result to destroy
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API void sfSftpResult_destroy(const sfSftpResult* result);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Check if a SFTP result is a success
|
||||
///
|
||||
/// \param result SFTP result
|
||||
///
|
||||
/// \return True if the result is sfSftpSuccess
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API bool sfSftpResult_isOk(const sfSftpResult* result);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the value of a SFTP result
|
||||
///
|
||||
/// \param result SFTP result
|
||||
///
|
||||
/// \return Result value
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API sfSftpResultValue sfSftpResult_getValue(const sfSftpResult* result);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the message of a SFTP result
|
||||
///
|
||||
/// \param result SFTP result
|
||||
///
|
||||
/// \return The result message
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API const char* sfSftpResult_getMessage(const sfSftpResult* result);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Destroy a SFTP path result
|
||||
///
|
||||
/// \param result SFTP path result to destroy
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API void sfSftpPathResult_destroy(const sfSftpPathResult* result);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Check if a SFTP path result is a success
|
||||
///
|
||||
/// \param result SFTP path result
|
||||
///
|
||||
/// \return True if the result is sfSftpSuccess
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API bool sfSftpPathResult_isOk(const sfSftpPathResult* result);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the value of a SFTP path result
|
||||
///
|
||||
/// \param result SFTP path result
|
||||
///
|
||||
/// \return Result value
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API sfSftpResultValue sfSftpPathResult_getValue(const sfSftpPathResult* result);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the message of a SFTP path result
|
||||
///
|
||||
/// \param result SFTP path result
|
||||
///
|
||||
/// \return The result message
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API const char* sfSftpPathResult_getMessage(const sfSftpPathResult* result);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the path of a SFTP path result
|
||||
///
|
||||
/// \param result SFTP path result
|
||||
///
|
||||
/// \return The path, encoded in UTF-8
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API const char* sfSftpPathResult_getPath(const sfSftpPathResult* result);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Destroy a SFTP attributes result
|
||||
///
|
||||
/// \param result SFTP attributes result to destroy
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API void sfSftpAttributesResult_destroy(const sfSftpAttributesResult* result);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Check if a SFTP attributes result is a success
|
||||
///
|
||||
/// \param result SFTP attributes result
|
||||
///
|
||||
/// \return True if the result is sfSftpSuccess
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API bool sfSftpAttributesResult_isOk(const sfSftpAttributesResult* result);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the value of a SFTP attributes result
|
||||
///
|
||||
/// \param result SFTP attributes result
|
||||
///
|
||||
/// \return Result value
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API sfSftpResultValue sfSftpAttributesResult_getValue(const sfSftpAttributesResult* result);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the message of a SFTP attributes result
|
||||
///
|
||||
/// \param result SFTP attributes result
|
||||
///
|
||||
/// \return The result message
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API const char* sfSftpAttributesResult_getMessage(const sfSftpAttributesResult* result);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the attributes of a SFTP attributes result
|
||||
///
|
||||
/// The strings of the attributes stay valid until the
|
||||
/// result is destroyed.
|
||||
///
|
||||
/// \param result SFTP attributes result
|
||||
///
|
||||
/// \return The attributes
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API sfSftpAttributes sfSftpAttributesResult_getAttributes(const sfSftpAttributesResult* result);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Destroy a SFTP listing result
|
||||
///
|
||||
/// \param result SFTP listing result to destroy
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API void sfSftpListingResult_destroy(const sfSftpListingResult* result);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Check if a SFTP listing result is a success
|
||||
///
|
||||
/// \param result SFTP listing result
|
||||
///
|
||||
/// \return True if the result is sfSftpSuccess
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API bool sfSftpListingResult_isOk(const sfSftpListingResult* result);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the value of a SFTP listing result
|
||||
///
|
||||
/// \param result SFTP listing result
|
||||
///
|
||||
/// \return Result value
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API sfSftpResultValue sfSftpListingResult_getValue(const sfSftpListingResult* result);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the message of a SFTP listing result
|
||||
///
|
||||
/// \param result SFTP listing result
|
||||
///
|
||||
/// \return The result message
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API const char* sfSftpListingResult_getMessage(const sfSftpListingResult* result);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the number of entries in a SFTP listing result
|
||||
///
|
||||
/// \param result SFTP listing result
|
||||
///
|
||||
/// \return Number of directory entries
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API size_t sfSftpListingResult_getCount(const sfSftpListingResult* result);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the attributes of an entry in a SFTP listing result
|
||||
///
|
||||
/// The strings of the attributes stay valid until the
|
||||
/// result is destroyed.
|
||||
///
|
||||
/// \param result SFTP listing result
|
||||
/// \param index Index of the entry to get
|
||||
///
|
||||
/// \return The attributes of the entry
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API sfSftpAttributes sfSftpListingResult_getAttributes(const sfSftpListingResult* result, size_t index);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Create a new SFTP object
|
||||
///
|
||||
/// \return A new sfSftp object
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API sfSftp* sfSftp_create(void);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Destroy an existing SFTP object
|
||||
///
|
||||
/// \param sftp SFTP object to destroy
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API void sfSftp_destroy(const sfSftp* sftp);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Connect to the specified SFTP server
|
||||
///
|
||||
/// \param sftp SFTP object
|
||||
/// \param server Address of the server to connect to
|
||||
/// \param port Port used for the connection, the default SFTP port is 22
|
||||
/// \param timeout Maximum time to wait, optionally a predicate can be provided for more fine-grained control
|
||||
///
|
||||
/// \return Result of the connection attempt
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API sfSftpResult* sfSftp_connect(sfSftp* sftp, sfIpAddress server, unsigned short port, sfTimeoutWithPredicate timeout);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Disconnect the connection with the server
|
||||
///
|
||||
/// \param sftp SFTP object
|
||||
/// \param timeout Maximum time to wait, optionally a predicate can be provided for more fine-grained control
|
||||
///
|
||||
/// \return Result of disconnecting the connection with the server
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API sfSftpResult* sfSftp_disconnect(sfSftp* sftp, sfTimeoutWithPredicate timeout);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get SSH session information
|
||||
///
|
||||
/// After connecting to the server and before actually
|
||||
/// logging in the SSH session information of the underlying
|
||||
/// connection will be available.
|
||||
///
|
||||
/// The session information contains among other things the
|
||||
/// public key identifying the remote host and the connection
|
||||
/// parameters such as encryption and compression used.
|
||||
///
|
||||
/// Relying on the user to check the authenticity of the host
|
||||
/// key is the typical method used to verify the connection
|
||||
/// to the legitimate host. If connection security is a high
|
||||
/// priority, examining the parameters and aborting the
|
||||
/// connection if any weak algorithms are used is also possible.
|
||||
///
|
||||
/// The pointers in the session information stay valid until
|
||||
/// the next call to this function or until the SFTP object
|
||||
/// is destroyed.
|
||||
///
|
||||
/// \param sftp SFTP object
|
||||
/// \param info Session information to fill
|
||||
///
|
||||
/// \return True if the session information is available, false otherwise
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API bool sfSftp_getSessionInfo(const sfSftp* sftp, sfSftpSessionInfo* info);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Log in using a username and a password
|
||||
///
|
||||
/// Logging in is mandatory after connecting to the server.
|
||||
/// Users that are not logged in cannot perform any operation.
|
||||
///
|
||||
/// \param sftp SFTP object
|
||||
/// \param name User name
|
||||
/// \param password Password
|
||||
/// \param timeout Maximum time to wait, optionally a predicate can be provided for more fine-grained control
|
||||
///
|
||||
/// \return Result of attempting to log in to the server
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API sfSftpResult* sfSftp_login(sfSftp* sftp, const char* name, const char* password, sfTimeoutWithPredicate timeout);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Log in using a public/private key pair
|
||||
///
|
||||
/// Logging in is mandatory after connecting to the server.
|
||||
/// Users that are not logged in cannot perform any operation.
|
||||
///
|
||||
/// The public and private key data should be provided in PEM
|
||||
/// format. Even though it is technically possible to derive
|
||||
/// the public key from the private key, due to backend
|
||||
/// limitations, providing a pre-generated public key as well
|
||||
/// is necessary for this function to be able to succeed.
|
||||
///
|
||||
/// If the private key is not protected by a passphrase the
|
||||
/// passphrase should be set to the empty string or NULL.
|
||||
///
|
||||
/// \param sftp SFTP object
|
||||
/// \param name User name
|
||||
/// \param publicKeyData Public key data
|
||||
/// \param publicKeyLength Public key data length
|
||||
/// \param privateKeyData Private key data
|
||||
/// \param privateKeyLength Private key data length
|
||||
/// \param privateKeyPassphrase Private key passphrase, NULL terminated
|
||||
/// \param timeout Maximum time to wait, optionally a predicate can be provided for more fine-grained control
|
||||
///
|
||||
/// \return Result of attempting to log in to the server
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API sfSftpResult* sfSftp_loginWithKey(
|
||||
sfSftp* sftp,
|
||||
const char* name,
|
||||
const char* publicKeyData,
|
||||
size_t publicKeyLength,
|
||||
const char* privateKeyData,
|
||||
size_t privateKeyLength,
|
||||
const char* privateKeyPassphrase,
|
||||
sfTimeoutWithPredicate timeout);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Resolve a remote path into an absolute remote path
|
||||
///
|
||||
/// Paths can contain links and other reserved path identifiers
|
||||
/// such as . and .. referring to the current directory and
|
||||
/// parent directory respectively. This function determines
|
||||
/// the absolute path, which does not contain links or . or ..
|
||||
///
|
||||
/// Resolving "." will return the absolute path to the current
|
||||
/// working directory of the user after logging in to the SFTP
|
||||
/// server.
|
||||
///
|
||||
/// \param sftp SFTP object
|
||||
/// \param path Path to convert into an absolute path, encoded in UTF-8
|
||||
/// \param timeout Maximum time to wait, optionally a predicate can be provided for more fine-grained control
|
||||
///
|
||||
/// \return Result of converting the path into an absolute path
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API sfSftpPathResult* sfSftp_resolvePath(sfSftp* sftp, const char* path, sfTimeoutWithPredicate timeout);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the current working directory on the server
|
||||
///
|
||||
/// This is an alias for calling sfSftp_resolvePath with ".".
|
||||
///
|
||||
/// \param sftp SFTP object
|
||||
/// \param timeout Maximum time to wait, optionally a predicate can be provided for more fine-grained control
|
||||
///
|
||||
/// \return Result of getting the current working directory
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API sfSftpPathResult* sfSftp_getWorkingDirectory(sfSftp* sftp, sfTimeoutWithPredicate timeout);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the attributes of a remote file or directory
|
||||
///
|
||||
/// Depending on whether \a path refers to a file or directory,
|
||||
/// the attributes can contain e.g. the type of file, the file
|
||||
/// owner, group, file size, modification and access times.
|
||||
///
|
||||
/// If links are not to be followed, \a followLinks can be set
|
||||
/// to false. In this case the attributes of the link itself
|
||||
/// will be returned.
|
||||
///
|
||||
/// \param sftp SFTP object
|
||||
/// \param path Path to the remote file or directory whose attributes to get, encoded in UTF-8
|
||||
/// \param followLinks True to follow links, false to return attributes of the link itself
|
||||
/// \param timeout Maximum time to wait, optionally a predicate can be provided for more fine-grained control
|
||||
///
|
||||
/// \return Result of getting the attributes
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API sfSftpAttributesResult* sfSftp_getAttributes(
|
||||
sfSftp* sftp,
|
||||
const char* path,
|
||||
bool followLinks,
|
||||
sfTimeoutWithPredicate timeout);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the contents of the given directory
|
||||
///
|
||||
/// This function retrieves the sub-directories and files
|
||||
/// contained in the given directory. It is not recursive.
|
||||
///
|
||||
/// \param sftp SFTP object
|
||||
/// \param path Path of the directory whose contents to list, encoded in UTF-8
|
||||
/// \param timeout Maximum time to wait, optionally a predicate can be provided for more fine-grained control
|
||||
///
|
||||
/// \return Result of getting the contents of the given directory
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API sfSftpListingResult* sfSftp_getDirectoryListing(sfSftp* sftp, const char* path, sfTimeoutWithPredicate timeout);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Create a new directory
|
||||
///
|
||||
/// The new directory is created as a child of the current
|
||||
/// working directory.
|
||||
///
|
||||
/// A common permissions value is 0755 (rwxr-xr-x).
|
||||
///
|
||||
/// \param sftp SFTP object
|
||||
/// \param path Path of the directory to create, encoded in UTF-8
|
||||
/// \param permissions POSIX permissions of the directory to create
|
||||
/// \param timeout Maximum time to wait, optionally a predicate can be provided for more fine-grained control
|
||||
///
|
||||
/// \return Result of creating the directory
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API sfSftpResult* sfSftp_createDirectory(sfSftp* sftp,
|
||||
const char* path,
|
||||
uint32_t permissions,
|
||||
sfTimeoutWithPredicate timeout);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Remove an existing directory
|
||||
///
|
||||
/// Use this function with caution, the directory will
|
||||
/// be removed permanently!
|
||||
///
|
||||
/// \param sftp SFTP object
|
||||
/// \param path Path of the directory to remove, encoded in UTF-8
|
||||
/// \param timeout Maximum time to wait, optionally a predicate can be provided for more fine-grained control
|
||||
///
|
||||
/// \return Result of removing the directory
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API sfSftpResult* sfSftp_deleteDirectory(sfSftp* sftp, const char* path, sfTimeoutWithPredicate timeout);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Rename an existing file or directory
|
||||
///
|
||||
/// In POSIX renaming and moving are synonymous. If you want
|
||||
/// to move a file or directory from one place to another
|
||||
/// you rename it from an old to a new path.
|
||||
///
|
||||
/// If a file exists at the specified new path, depending
|
||||
/// on whether \a overwrite is set to true, the rename operation
|
||||
/// will overwrite it or not. Non-empty directories cannot be
|
||||
/// overwritten by this operation.
|
||||
///
|
||||
/// \param sftp SFTP object
|
||||
/// \param oldPath Old path to the file or directory, encoded in UTF-8
|
||||
/// \param newPath New path to the file or directory, encoded in UTF-8
|
||||
/// \param overwrite True to allow overwriting a file that exists at \a newPath
|
||||
/// \param timeout Maximum time to wait, optionally a predicate can be provided for more fine-grained control
|
||||
///
|
||||
/// \return Result of the operation
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API sfSftpResult* sfSftp_rename(
|
||||
sfSftp* sftp,
|
||||
const char* oldPath,
|
||||
const char* newPath,
|
||||
bool overwrite,
|
||||
sfTimeoutWithPredicate timeout);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Remove an existing file
|
||||
///
|
||||
/// Use this function with caution, the file will be
|
||||
/// removed permanently!
|
||||
///
|
||||
/// \param sftp SFTP object
|
||||
/// \param path Path to the file to remove, encoded in UTF-8
|
||||
/// \param timeout Maximum time to wait, optionally a predicate can be provided for more fine-grained control
|
||||
///
|
||||
/// \return Result of removing the file
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API sfSftpResult* sfSftp_deleteFile(sfSftp* sftp, const char* path, sfTimeoutWithPredicate timeout);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Download a file from the server
|
||||
///
|
||||
/// The file data is transferred in sequential blocks. For
|
||||
/// every block of data transferred, the provided callback
|
||||
/// is called.
|
||||
///
|
||||
/// The function returns once all the data in the remote file
|
||||
/// has been transferred or an error occurs or the function
|
||||
/// times out.
|
||||
///
|
||||
/// \param sftp SFTP object
|
||||
/// \param remotePath Path of the remote file whose data to download, encoded in UTF-8
|
||||
/// \param callback Callback to be called for every available data block
|
||||
/// \param userData User data that will be passed to the callback
|
||||
/// \param offset Byte offset into the remote file at which reading should start
|
||||
/// \param timeout Maximum time to wait, optionally a predicate can be provided for more fine-grained control
|
||||
///
|
||||
/// \return Result of downloading the file
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API sfSftpResult* sfSftp_download(
|
||||
sfSftp* sftp,
|
||||
const char* remotePath,
|
||||
sfSftpDownloadCallback callback,
|
||||
void* userData,
|
||||
uint64_t offset,
|
||||
sfTimeoutWithPredicate timeout);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Upload a file to the server
|
||||
///
|
||||
/// The file data is transferred in sequential blocks. Every
|
||||
/// time the function wants to send a new block of data the
|
||||
/// provided callback is called.
|
||||
///
|
||||
/// The function returns once all the data has been sent or
|
||||
/// an error occurs or the function times out.
|
||||
///
|
||||
/// If a file does not exist at the remote path yet, it will
|
||||
/// be created with the provided permissions. A common
|
||||
/// permissions value is 0644 (rw-r--r--).
|
||||
///
|
||||
/// \param sftp SFTP object
|
||||
/// \param remotePath Path of the remote file in which to upload the data, encoded in UTF-8
|
||||
/// \param callback Callback to be called for every data block to send
|
||||
/// \param userData User data that will be passed to the callback
|
||||
/// \param permissions POSIX permissions of the remote file if it has to be created
|
||||
/// \param truncate True to truncate the remote file if it already exists
|
||||
/// \param append True to append to the remote file if it already exists
|
||||
/// \param offset Byte offset into the remote file at which writing should start
|
||||
/// \param timeout Maximum time to wait, optionally a predicate can be provided for more fine-grained control
|
||||
///
|
||||
/// \return Result of uploading the file
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API sfSftpResult* sfSftp_upload(
|
||||
sfSftp* sftp,
|
||||
const char* remotePath,
|
||||
sfSftpUploadCallback callback,
|
||||
void* userData,
|
||||
uint32_t permissions,
|
||||
bool truncate,
|
||||
bool append,
|
||||
uint64_t offset,
|
||||
sfTimeoutWithPredicate timeout);
|
||||
@@ -32,6 +32,31 @@
|
||||
#include <CSFML/Network/Types.h>
|
||||
#include <CSFML/System/Time.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Readiness types a socket selector can check for
|
||||
///
|
||||
/// The values can be combined with a bitwise OR.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
typedef enum
|
||||
{
|
||||
sfSocketSelectorReceive = 1 << 0, ///< Check if sockets are ready to be received from
|
||||
sfSocketSelectorSend = 1 << 1 ///< Check if sockets are ready to be sent to
|
||||
} sfSocketSelectorReadiness;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Callback that is called when a socket is ready
|
||||
///
|
||||
/// \param readiness Readiness of the socket, a combination of sfSocketSelectorReadiness values
|
||||
/// \param userData User data passed when adding the socket
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
typedef void (*sfSocketSelectorCallback)(uint32_t readiness, void* userData);
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Create a new selector
|
||||
@@ -66,13 +91,64 @@ CSFML_NETWORK_API void sfSocketSelector_destroy(const sfSocketSelector* selector
|
||||
/// so you have to make sure that the socket is not destroyed
|
||||
/// while it is stored in the selector.
|
||||
///
|
||||
/// The socket is checked for being ready to receive.
|
||||
///
|
||||
/// \param selector Socket selector object
|
||||
/// \param socket Pointer to the socket to add
|
||||
///
|
||||
/// \return True if the socket was successfully added
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API void sfSocketSelector_addTcpListener(sfSocketSelector* selector, sfTcpListener* socket);
|
||||
CSFML_NETWORK_API void sfSocketSelector_addTcpSocket(sfSocketSelector* selector, sfTcpSocket* socket);
|
||||
CSFML_NETWORK_API void sfSocketSelector_addUdpSocket(sfSocketSelector* selector, sfUdpSocket* socket);
|
||||
CSFML_NETWORK_API bool sfSocketSelector_addTcpListener(sfSocketSelector* selector, sfTcpListener* socket);
|
||||
CSFML_NETWORK_API bool sfSocketSelector_addTcpSocket(sfSocketSelector* selector, sfTcpSocket* socket);
|
||||
CSFML_NETWORK_API bool sfSocketSelector_addUdpSocket(sfSocketSelector* selector, sfUdpSocket* socket);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Add a new socket to a socket selector with the readiness to check for and an optional callback
|
||||
///
|
||||
/// This function keeps a weak pointer to the socket,
|
||||
/// so you have to make sure that the socket is not destroyed
|
||||
/// while it is stored in the selector.
|
||||
///
|
||||
/// The readiness to wait for can be specified as a combination
|
||||
/// of sfSocketSelectorReceive and sfSocketSelectorSend.
|
||||
///
|
||||
/// If a callback is provided, it will be called with the
|
||||
/// readiness of the socket when sfSocketSelector_dispatchReadyCallbacks
|
||||
/// is called after sfSocketSelector_wait returned true. Using
|
||||
/// callbacks scales better than checking every socket with
|
||||
/// sfSocketSelector_isXxxReadyFor.
|
||||
///
|
||||
/// Adding a socket that has already been added updates its
|
||||
/// readiness and callback.
|
||||
///
|
||||
/// \param selector Socket selector object
|
||||
/// \param socket Pointer to the socket to add
|
||||
/// \param readiness Readiness to wait for, combination of sfSocketSelectorReadiness values
|
||||
/// \param callback Callback to call when the socket is ready, can be NULL
|
||||
/// \param userData User data that will be passed to the callback
|
||||
///
|
||||
/// \return True if the socket was successfully added
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API bool sfSocketSelector_addTcpListenerWithReadiness(
|
||||
sfSocketSelector* selector,
|
||||
sfTcpListener* socket,
|
||||
uint32_t readiness,
|
||||
sfSocketSelectorCallback callback,
|
||||
void* userData);
|
||||
CSFML_NETWORK_API bool sfSocketSelector_addTcpSocketWithReadiness(
|
||||
sfSocketSelector* selector,
|
||||
sfTcpSocket* socket,
|
||||
uint32_t readiness,
|
||||
sfSocketSelectorCallback callback,
|
||||
void* userData);
|
||||
CSFML_NETWORK_API bool sfSocketSelector_addUdpSocketWithReadiness(
|
||||
sfSocketSelector* selector,
|
||||
sfUdpSocket* socket,
|
||||
uint32_t readiness,
|
||||
sfSocketSelectorCallback callback,
|
||||
void* userData);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Remove a socket from a socket selector
|
||||
@@ -83,10 +159,12 @@ CSFML_NETWORK_API void sfSocketSelector_addUdpSocket(sfSocketSelector* selector,
|
||||
/// \param selector Socket selector object
|
||||
/// \param socket Pointer to the socket to remove
|
||||
///
|
||||
/// \return True if the socket was successfully removed
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API void sfSocketSelector_removeTcpListener(sfSocketSelector* selector, sfTcpListener* socket);
|
||||
CSFML_NETWORK_API void sfSocketSelector_removeTcpSocket(sfSocketSelector* selector, sfTcpSocket* socket);
|
||||
CSFML_NETWORK_API void sfSocketSelector_removeUdpSocket(sfSocketSelector* selector, sfUdpSocket* socket);
|
||||
CSFML_NETWORK_API bool sfSocketSelector_removeTcpListener(sfSocketSelector* selector, sfTcpListener* socket);
|
||||
CSFML_NETWORK_API bool sfSocketSelector_removeTcpSocket(sfSocketSelector* selector, sfTcpSocket* socket);
|
||||
CSFML_NETWORK_API bool sfSocketSelector_removeUdpSocket(sfSocketSelector* selector, sfUdpSocket* socket);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Remove all the sockets stored in a selector
|
||||
@@ -101,11 +179,13 @@ CSFML_NETWORK_API void sfSocketSelector_removeUdpSocket(sfSocketSelector* select
|
||||
CSFML_NETWORK_API void sfSocketSelector_clear(sfSocketSelector* selector);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Wait until one or more sockets are ready to receive
|
||||
/// \brief Wait until one or more sockets are ready
|
||||
///
|
||||
/// This function returns as soon as at least one socket has
|
||||
/// some data available to be received. To know which sockets are
|
||||
/// ready, use the sfSocketSelector_isXxxReady functions.
|
||||
/// This function returns as soon as at least one socket is
|
||||
/// ready for the readiness it was added with (by default
|
||||
/// having some data available to be received). To know which
|
||||
/// sockets are ready, use the sfSocketSelector_isXxxReady
|
||||
/// functions or sfSocketSelector_dispatchReadyCallbacks.
|
||||
/// If you use a timeout and no socket is ready before the timeout
|
||||
/// is over, the function returns false.
|
||||
///
|
||||
@@ -136,3 +216,41 @@ CSFML_NETWORK_API bool sfSocketSelector_wait(sfSocketSelector* selector, sfTime
|
||||
CSFML_NETWORK_API bool sfSocketSelector_isTcpListenerReady(const sfSocketSelector* selector, sfTcpListener* socket);
|
||||
CSFML_NETWORK_API bool sfSocketSelector_isTcpSocketReady(const sfSocketSelector* selector, sfTcpSocket* socket);
|
||||
CSFML_NETWORK_API bool sfSocketSelector_isUdpSocketReady(const sfSocketSelector* selector, sfUdpSocket* socket);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Test a socket to know if it is ready for the given readiness
|
||||
///
|
||||
/// This function must be used after a call to
|
||||
/// sfSocketSelector_wait, to know which sockets are ready.
|
||||
///
|
||||
/// \param selector Socket selector object
|
||||
/// \param socket Socket to test
|
||||
/// \param readiness Readiness to check for, combination of sfSocketSelectorReadiness values
|
||||
///
|
||||
/// \return true if the socket is ready, false otherwise
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API bool sfSocketSelector_isTcpListenerReadyFor(const sfSocketSelector* selector,
|
||||
sfTcpListener* socket,
|
||||
uint32_t readiness);
|
||||
CSFML_NETWORK_API bool sfSocketSelector_isTcpSocketReadyFor(const sfSocketSelector* selector,
|
||||
sfTcpSocket* socket,
|
||||
uint32_t readiness);
|
||||
CSFML_NETWORK_API bool sfSocketSelector_isUdpSocketReadyFor(const sfSocketSelector* selector,
|
||||
sfUdpSocket* socket,
|
||||
uint32_t readiness);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Call the callbacks of all sockets that are ready
|
||||
///
|
||||
/// After sfSocketSelector_wait returned true, at least one
|
||||
/// socket is ready. Calling this function will call the
|
||||
/// callbacks of all the sockets that became ready during
|
||||
/// the wait. Calling this function multiple times after a
|
||||
/// single call to sfSocketSelector_wait will run the callbacks
|
||||
/// multiple times.
|
||||
///
|
||||
/// \param selector Socket selector object
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API void sfSocketSelector_dispatchReadyCallbacks(sfSocketSelector* selector);
|
||||
@@ -34,9 +34,23 @@
|
||||
#include <CSFML/Network/Types.h>
|
||||
#include <CSFML/System/Time.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Transport layer security status codes
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
typedef enum
|
||||
{
|
||||
sfTlsNotConnected, ///< TCP connection not yet connected
|
||||
sfTlsHandshakeStarted, ///< TLS handshake has been started
|
||||
sfTlsHandshakeComplete, ///< TLS handshake is complete, stream is encrypted
|
||||
sfTlsError ///< An unexpected error happened
|
||||
} sfTlsStatus;
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Create a new TCP socket
|
||||
///
|
||||
@@ -229,3 +243,121 @@ CSFML_NETWORK_API sfSocketStatus sfTcpSocket_sendPacket(sfTcpSocket* socket, sfP
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API sfSocketStatus sfTcpSocket_receivePacket(sfTcpSocket* socket, sfPacket* packet);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Set up transport layer security as a client
|
||||
///
|
||||
/// Once the TCP connection is connected, transport layer
|
||||
/// security can be set up.
|
||||
///
|
||||
/// If this function is called before the TCP connection is
|
||||
/// connected, it will return sfTlsNotConnected and must be
|
||||
/// called again once the TCP connection is connected.
|
||||
///
|
||||
/// If this function started TLS setup but could not finish
|
||||
/// it within this call e.g. because this socket was set to
|
||||
/// non-blocking, it will return sfTlsHandshakeStarted and
|
||||
/// this function will have to be called repeatedly until
|
||||
/// sfTlsHandshakeComplete is returned. If this socket is
|
||||
/// blocking, sfTlsHandshakeComplete should be returned
|
||||
/// within the same function call if TLS setup was successful.
|
||||
///
|
||||
/// If sfTlsError is returned, something went wrong with TLS
|
||||
/// setup and the connection must be reconnected and TLS setup
|
||||
/// reattempted after it is connected again.
|
||||
///
|
||||
/// If verification is enabled, this function verifies the peer
|
||||
/// using the system provided certificate store. If the peer
|
||||
/// does not have a certificate that was signed by a certificate
|
||||
/// authority i.e. a self-signed certificate, the entire certificate
|
||||
/// chain can be provided using sfTcpSocket_setupTlsClientWithCertificate.
|
||||
///
|
||||
/// The hostname is sent to the server via server name indication
|
||||
/// (SNI) and used to verify the certificate chain returned by the
|
||||
/// server.
|
||||
///
|
||||
/// \param socket TCP socket object
|
||||
/// \param hostname Hostname of the remote peer, encoded in UTF-8, used for verification
|
||||
/// \param verifyPeer True to enable peer verification, false to disable it
|
||||
///
|
||||
/// \return TLS status code
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API sfTlsStatus sfTcpSocket_setupTlsClient(sfTcpSocket* socket, const char* hostname, bool verifyPeer);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Set up transport layer security as a client with a given certificate chain
|
||||
///
|
||||
/// When calling this function, the certificate chain to verify
|
||||
/// the host with has to be provided. Verification is always
|
||||
/// enabled when calling this function.
|
||||
///
|
||||
/// The certificate data can be provided in PEM or DER format.
|
||||
///
|
||||
/// See sfTcpSocket_setupTlsClient for details on the returned
|
||||
/// status codes.
|
||||
///
|
||||
/// \param socket TCP socket object
|
||||
/// \param hostname Hostname of the remote peer, encoded in UTF-8, used for verification
|
||||
/// \param certificateChainData Certificate chain data in PEM or DER encoding
|
||||
/// \param certificateChainSize Size of the certificate chain data
|
||||
///
|
||||
/// \return TLS status code
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API sfTlsStatus sfTcpSocket_setupTlsClientWithCertificate(
|
||||
sfTcpSocket* socket,
|
||||
const char* hostname,
|
||||
const void* certificateChainData,
|
||||
size_t certificateChainSize);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Set up transport layer security as a server
|
||||
///
|
||||
/// Once the TCP connection is connected, transport layer
|
||||
/// security can be set up.
|
||||
///
|
||||
/// As a server, a certificate chain as well as a private key
|
||||
/// must be provided. The certificate and private key data can
|
||||
/// be provided in PEM or DER format. If the private key is
|
||||
/// secured by a password, the password must be provided.
|
||||
///
|
||||
/// If sfTlsError is returned, something went wrong with TLS
|
||||
/// setup and the connection must be disconnected. The client
|
||||
/// must reconnect and reattempt TLS setup again.
|
||||
///
|
||||
/// See sfTcpSocket_setupTlsClient for details on the other
|
||||
/// returned status codes.
|
||||
///
|
||||
/// \param socket TCP socket object
|
||||
/// \param certificateChainData Certificate chain data in PEM or DER encoding
|
||||
/// \param certificateChainSize Size of the certificate chain data
|
||||
/// \param privateKeyData Private key data in PEM or DER encoding
|
||||
/// \param privateKeySize Size of the private key data
|
||||
/// \param privateKeyPasswordData Private key password data, can be NULL if there is no password
|
||||
/// \param privateKeyPasswordSize Size of the private key password data
|
||||
///
|
||||
/// \return TLS status code
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API sfTlsStatus sfTcpSocket_setupTlsServer(
|
||||
sfTcpSocket* socket,
|
||||
const void* certificateChainData,
|
||||
size_t certificateChainSize,
|
||||
const void* privateKeyData,
|
||||
size_t privateKeySize,
|
||||
const void* privateKeyPasswordData,
|
||||
size_t privateKeyPasswordSize);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the name of the TLS ciphersuite currently in use
|
||||
///
|
||||
/// The returned string stays valid until the next call to
|
||||
/// this function or until the socket is destroyed.
|
||||
///
|
||||
/// \param socket TCP socket object
|
||||
///
|
||||
/// \return TLS ciphersuite currently in use or NULL if TLS is not set up
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_NETWORK_API const char* sfTcpSocket_getCurrentCiphersuiteName(const sfTcpSocket* socket);
|
||||
@@ -25,6 +25,10 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
typedef struct sfDnsMxRecords sfDnsMxRecords;
|
||||
typedef struct sfDnsNsRecords sfDnsNsRecords;
|
||||
typedef struct sfDnsSrvRecords sfDnsSrvRecords;
|
||||
typedef struct sfDnsTxtRecords sfDnsTxtRecords;
|
||||
typedef struct sfFtpDirectoryResponse sfFtpDirectoryResponse;
|
||||
typedef struct sfFtpListingResponse sfFtpListingResponse;
|
||||
typedef struct sfFtpResponse sfFtpResponse;
|
||||
@@ -33,6 +37,11 @@ typedef struct sfHttpRequest sfHttpRequest;
|
||||
typedef struct sfHttpResponse sfHttpResponse;
|
||||
typedef struct sfHttp sfHttp;
|
||||
typedef struct sfPacket sfPacket;
|
||||
typedef struct sfSftpAttributesResult sfSftpAttributesResult;
|
||||
typedef struct sfSftpListingResult sfSftpListingResult;
|
||||
typedef struct sfSftpPathResult sfSftpPathResult;
|
||||
typedef struct sfSftpResult sfSftpResult;
|
||||
typedef struct sfSftp sfSftp;
|
||||
typedef struct sfSocketSelector sfSocketSelector;
|
||||
typedef struct sfTcpListener sfTcpListener;
|
||||
typedef struct sfTcpSocket sfTcpSocket;
|
||||
|
||||
@@ -35,5 +35,7 @@
|
||||
#include <CSFML/System/InputStream.h>
|
||||
#include <CSFML/System/Sleep.h>
|
||||
#include <CSFML/System/Time.h>
|
||||
#include <CSFML/System/TimeoutWithPredicate.h>
|
||||
#include <CSFML/System/Vector2.h>
|
||||
#include <CSFML/System/Vector3.h>
|
||||
#include <CSFML/System/Version.h>
|
||||
@@ -0,0 +1,66 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2026 Laurent Gomila (laurent@sfml-dev.org)
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <CSFML/System/Time.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Predicate that returns true to continue or false to time out
|
||||
///
|
||||
/// \param userData User data stored in the sfTimeoutWithPredicate
|
||||
///
|
||||
/// \return True to continue, false to time out
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
typedef bool (*sfTimeoutPredicate)(void* userData);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Hybrid of a timeout and a continuation predicate
|
||||
///
|
||||
/// Functions taking a timeout parameter that is specified
|
||||
/// solely by a time cannot be easily interrupted. A predicate
|
||||
/// allows interrupting the operation at any time, e.g. when
|
||||
/// the user cancels it.
|
||||
///
|
||||
/// If \a predicate is NULL, the operation times out after
|
||||
/// \a timeout (0 meaning no timeout). If \a predicate is set,
|
||||
/// \a timeout is ignored and the operation times out once the
|
||||
/// predicate returns false. The predicate is checked every
|
||||
/// \a period, a period of 0 checks it every millisecond.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
typedef struct
|
||||
{
|
||||
sfTime timeout; ///< Time to time out after, if no predicate is set
|
||||
sfTimeoutPredicate predicate; ///< Predicate that returns true to continue or false to time out, can be NULL
|
||||
void* userData; ///< User data passed to the predicate
|
||||
sfTime period; ///< The period between checks of the predicate
|
||||
} sfTimeoutWithPredicate;
|
||||
@@ -0,0 +1,64 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2026 Laurent Gomila (laurent@sfml-dev.org)
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <CSFML/System/Export.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Version information of the SFML library
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
typedef struct
|
||||
{
|
||||
int8_t major; ///< SFML major version
|
||||
int8_t minor; ///< SFML minor version
|
||||
int8_t patch; ///< SFML patch version
|
||||
bool isRelease; ///< true if this is a release version, false if this is a development version
|
||||
const char* string; ///< String representation of the SFML version, e.g. 3.1.0 or 3.1.0-dev
|
||||
} sfVersion;
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the version of the SFML library loaded at runtime
|
||||
///
|
||||
/// This is the version of the SFML library CSFML is linked
|
||||
/// against at runtime, which can differ from the version
|
||||
/// CSFML was compiled with (see CSFML_VERSION_MAJOR,
|
||||
/// CSFML_VERSION_MINOR and CSFML_VERSION_PATCH).
|
||||
///
|
||||
/// The returned string is owned by SFML and stays valid
|
||||
/// for the whole lifetime of the program.
|
||||
///
|
||||
/// \return Version information of the SFML library
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_SYSTEM_API sfVersion sfGetVersion(void);
|
||||
@@ -40,8 +40,10 @@
|
||||
///
|
||||
/// \return true if \a finger is currently touching the screen, false otherwise
|
||||
///
|
||||
/// \deprecated Use the touch events (sfEvtTouchBegan, sfEvtTouchMoved and sfEvtTouchEnded) instead
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_WINDOW_API bool sfTouch_isDown(unsigned int finger);
|
||||
CSFML_WINDOW_API CSFML_DEPRECATED bool sfTouch_isDown(unsigned int finger);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the current position of a touch in window coordinates
|
||||
@@ -54,8 +56,10 @@ CSFML_WINDOW_API bool sfTouch_isDown(unsigned int finger);
|
||||
///
|
||||
/// \return Current position of \a finger, or undefined if it's not down
|
||||
///
|
||||
/// \deprecated Use the touch events (sfEvtTouchBegan, sfEvtTouchMoved and sfEvtTouchEnded) instead
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_WINDOW_API sfVector2i sfTouch_getPosition(unsigned int finger, const sfWindow* relativeTo);
|
||||
CSFML_WINDOW_API CSFML_DEPRECATED sfVector2i sfTouch_getPosition(unsigned int finger, const sfWindow* relativeTo);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the current position of a touch in window coordinates
|
||||
@@ -68,5 +72,7 @@ CSFML_WINDOW_API sfVector2i sfTouch_getPosition(unsigned int finger, const sfWin
|
||||
///
|
||||
/// \return Current position of \a finger, or undefined if it's not down
|
||||
///
|
||||
/// \deprecated Use the touch events (sfEvtTouchBegan, sfEvtTouchMoved and sfEvtTouchEnded) instead
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_WINDOW_API sfVector2i sfTouch_getPositionWindowBase(unsigned int finger, const sfWindowBase* relativeTo);
|
||||
CSFML_WINDOW_API CSFML_DEPRECATED sfVector2i sfTouch_getPositionWindowBase(unsigned int finger, const sfWindowBase* relativeTo);
|
||||
@@ -38,7 +38,7 @@ Here's how to get started.
|
||||
|
||||
1. Install SFML.
|
||||
This may be done in a variety of ways including using a system package manager or building and installing SFML from source.
|
||||
The major version of SFML must match the major version of CSFML.
|
||||
The major version of SFML must match the major version of CSFML and the minor version of SFML must be the same or newer than the one of CSFML.
|
||||
2. Configure CSFML.
|
||||
If you are building CSFML for the purpose of contributing, we recommend using the `dev` CMake preset.
|
||||
This will enable a number of useful settings related to developing the library.
|
||||
|
||||
@@ -11,6 +11,8 @@ set(SRC
|
||||
${SRCROOT}/Music.cpp
|
||||
${SRCROOT}/MusicStruct.hpp
|
||||
${INCROOT}/Music.h
|
||||
${SRCROOT}/PlaybackDevice.cpp
|
||||
${INCROOT}/PlaybackDevice.h
|
||||
${SRCROOT}/Sound.cpp
|
||||
${SRCROOT}/SoundStruct.hpp
|
||||
${INCROOT}/Sound.h
|
||||
|
||||
@@ -0,0 +1,135 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2026 Laurent Gomila (laurent@sfml-dev.org)
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <CSFML/Audio/PlaybackDevice.h>
|
||||
|
||||
#include <SFML/Audio/PlaybackDevice.hpp>
|
||||
|
||||
#include <cassert>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
// Helper function for returning optional strings
|
||||
[[nodiscard]] const char* toCString(std::string& storage, const std::optional<std::string>& string)
|
||||
{
|
||||
if (!string)
|
||||
return nullptr;
|
||||
|
||||
storage = *string;
|
||||
return storage.c_str();
|
||||
}
|
||||
} // namespace
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
const char* const* sfPlaybackDevice_getAvailableDevices(size_t* count)
|
||||
{
|
||||
static std::vector<std::string> stringDevices;
|
||||
static std::vector<const char*> devices;
|
||||
|
||||
stringDevices = sf::PlaybackDevice::getAvailableDevices();
|
||||
devices.clear();
|
||||
devices.reserve(stringDevices.size());
|
||||
for (const auto& stringDevice : stringDevices)
|
||||
devices.push_back(stringDevice.c_str());
|
||||
|
||||
if (count)
|
||||
*count = devices.size();
|
||||
|
||||
return !devices.empty() ? devices.data() : nullptr;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
const char* sfPlaybackDevice_getDefaultDevice()
|
||||
{
|
||||
static std::string defaultDevice;
|
||||
return toCString(defaultDevice, sf::PlaybackDevice::getDefaultDevice());
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool sfPlaybackDevice_setDevice(const char* name)
|
||||
{
|
||||
assert(name);
|
||||
return sf::PlaybackDevice::setDevice(name);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool sfPlaybackDevice_setDeviceToDefault()
|
||||
{
|
||||
return sf::PlaybackDevice::setDeviceToDefault();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool sfPlaybackDevice_setDeviceToNull()
|
||||
{
|
||||
return sf::PlaybackDevice::setDeviceToNull();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
const char* sfPlaybackDevice_getDevice()
|
||||
{
|
||||
static std::string device;
|
||||
return toCString(device, sf::PlaybackDevice::getDevice());
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
uint32_t sfPlaybackDevice_getDeviceSampleRate()
|
||||
{
|
||||
return sf::PlaybackDevice::getDeviceSampleRate().value_or(0);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool sfPlaybackDevice_isDefaultDevice()
|
||||
{
|
||||
return sf::PlaybackDevice::isDefaultDevice();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfPlaybackDevice_setNotificationCallback(sfPlaybackDeviceNotificationCallback callback, void* userData)
|
||||
{
|
||||
if (!callback)
|
||||
{
|
||||
sf::PlaybackDevice::setNotificationCallback({});
|
||||
return;
|
||||
}
|
||||
|
||||
sf::PlaybackDevice::setNotificationCallback(
|
||||
[callback, userData](sf::PlaybackDevice::Notification notification)
|
||||
{ callback(static_cast<sfPlaybackDeviceNotification>(notification), userData); });
|
||||
}
|
||||
@@ -12,6 +12,7 @@ set(SRC
|
||||
${SRCROOT}/Color.cpp
|
||||
${INCROOT}/Color.h
|
||||
${SRCROOT}/ConvertColor.hpp
|
||||
${SRCROOT}/ConvertGlyph.hpp
|
||||
${SRCROOT}/ConvertRect.hpp
|
||||
${SRCROOT}/ConvertRenderStates.hpp
|
||||
${SRCROOT}/ConvertStencil.hpp
|
||||
|
||||
@@ -207,6 +207,14 @@ void sfCircleShape_setOutlineThickness(sfCircleShape* shape, float thickness)
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfCircleShape_setMiterLimit(sfCircleShape* shape, float miterLimit)
|
||||
{
|
||||
assert(shape);
|
||||
shape->setMiterLimit(miterLimit);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
const sfTexture* sfCircleShape_getTexture(const sfCircleShape* shape)
|
||||
{
|
||||
@@ -247,6 +255,14 @@ float sfCircleShape_getOutlineThickness(const sfCircleShape* shape)
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
float sfCircleShape_getMiterLimit(const sfCircleShape* shape)
|
||||
{
|
||||
assert(shape);
|
||||
return shape->getMiterLimit();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
size_t sfCircleShape_getPointCount(const sfCircleShape* shape)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2026 Laurent Gomila (laurent@sfml-dev.org)
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <CSFML/Graphics/ConvertRect.hpp>
|
||||
#include <CSFML/Graphics/Glyph.h>
|
||||
|
||||
#include <SFML/Graphics/Glyph.hpp>
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Convert sf::Glyph to sfGlyph
|
||||
////////////////////////////////////////////////////////////
|
||||
[[nodiscard]] inline sfGlyph convertGlyph(const sf::Glyph& glyph)
|
||||
{
|
||||
return {glyph.advance, convertRect(glyph.bounds), convertRect(glyph.textureRect)};
|
||||
}
|
||||
@@ -204,6 +204,14 @@ void sfConvexShape_setOutlineThickness(sfConvexShape* shape, float thickness)
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfConvexShape_setMiterLimit(sfConvexShape* shape, float miterLimit)
|
||||
{
|
||||
assert(shape);
|
||||
shape->setMiterLimit(miterLimit);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
const sfTexture* sfConvexShape_getTexture(const sfConvexShape* shape)
|
||||
{
|
||||
@@ -244,6 +252,14 @@ float sfConvexShape_getOutlineThickness(const sfConvexShape* shape)
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
float sfConvexShape_getMiterLimit(const sfConvexShape* shape)
|
||||
{
|
||||
assert(shape);
|
||||
return shape->getMiterLimit();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
size_t sfConvexShape_getPointCount(const sfConvexShape* shape)
|
||||
{
|
||||
|
||||
+28
-10
@@ -26,7 +26,7 @@
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <CSFML/CallbackStream.hpp>
|
||||
#include <CSFML/Graphics/ConvertRect.hpp>
|
||||
#include <CSFML/Graphics/ConvertGlyph.hpp>
|
||||
#include <CSFML/Graphics/Font.h>
|
||||
#include <CSFML/Graphics/FontStruct.hpp>
|
||||
|
||||
@@ -88,14 +88,15 @@ sfGlyph sfFont_getGlyph(const sfFont* font, uint32_t codePoint, unsigned int cha
|
||||
{
|
||||
assert(font);
|
||||
|
||||
sf::Glyph sfmlGlyph = font->getGlyph(codePoint, characterSize, bold, outlineThickness);
|
||||
return convertGlyph(font->getGlyph(codePoint, characterSize, bold, outlineThickness));
|
||||
}
|
||||
|
||||
sfGlyph glyph{};
|
||||
glyph.advance = sfmlGlyph.advance;
|
||||
glyph.bounds = convertRect(sfmlGlyph.bounds);
|
||||
glyph.textureRect = convertRect(sfmlGlyph.textureRect);
|
||||
|
||||
return glyph;
|
||||
////////////////////////////////////////////////////////////
|
||||
sfGlyph sfFont_getGlyphById(const sfFont* font, uint32_t id, unsigned int characterSize, bool bold, float outlineThickness)
|
||||
{
|
||||
assert(font);
|
||||
return convertGlyph(font->getGlyphById(id, characterSize, bold, outlineThickness));
|
||||
}
|
||||
|
||||
|
||||
@@ -111,7 +112,7 @@ bool sfFont_hasGlyph(const sfFont* font, uint32_t codePoint)
|
||||
float sfFont_getKerning(const sfFont* font, uint32_t first, uint32_t second, unsigned int characterSize)
|
||||
{
|
||||
assert(font);
|
||||
return font->getKerning(first, second, characterSize);
|
||||
return font->getKerning(char32_t{first}, char32_t{second}, characterSize);
|
||||
}
|
||||
|
||||
|
||||
@@ -119,7 +120,7 @@ float sfFont_getKerning(const sfFont* font, uint32_t first, uint32_t second, uns
|
||||
float sfFont_getBoldKerning(const sfFont* font, uint32_t first, uint32_t second, unsigned int characterSize)
|
||||
{
|
||||
assert(font);
|
||||
return font->getKerning(first, second, characterSize, true);
|
||||
return font->getKerning(char32_t{first}, char32_t{second}, characterSize, true);
|
||||
}
|
||||
|
||||
|
||||
@@ -131,6 +132,22 @@ float sfFont_getLineSpacing(const sfFont* font, unsigned int characterSize)
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
float sfFont_getAscent(const sfFont* font, unsigned int characterSize)
|
||||
{
|
||||
assert(font);
|
||||
return font->getAscent(characterSize);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
float sfFont_getDescent(const sfFont* font, unsigned int characterSize)
|
||||
{
|
||||
assert(font);
|
||||
return font->getDescent(characterSize);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
float sfFont_getUnderlinePosition(const sfFont* font, unsigned int characterSize)
|
||||
{
|
||||
@@ -178,5 +195,6 @@ bool sfFont_isSmooth(const sfFont* font)
|
||||
sfFontInfo sfFont_getInfo(const sfFont* font)
|
||||
{
|
||||
assert(font);
|
||||
return {font->getInfo().family.c_str()};
|
||||
const sf::Font::Info& info = font->getInfo();
|
||||
return {info.id, info.family.c_str(), info.hasKerning, info.hasVerticalMetrics};
|
||||
}
|
||||
@@ -204,6 +204,14 @@ void sfRectangleShape_setOutlineThickness(sfRectangleShape* shape, float thickne
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfRectangleShape_setMiterLimit(sfRectangleShape* shape, float miterLimit)
|
||||
{
|
||||
assert(shape);
|
||||
shape->setMiterLimit(miterLimit);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
const sfTexture* sfRectangleShape_getTexture(const sfRectangleShape* shape)
|
||||
{
|
||||
@@ -244,6 +252,14 @@ float sfRectangleShape_getOutlineThickness(const sfRectangleShape* shape)
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
float sfRectangleShape_getMiterLimit(const sfRectangleShape* shape)
|
||||
{
|
||||
assert(shape);
|
||||
return shape->getMiterLimit();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
size_t sfRectangleShape_getPointCount(const sfRectangleShape* shape)
|
||||
{
|
||||
|
||||
@@ -196,6 +196,14 @@ void sfShape_setOutlineThickness(sfShape* shape, float thickness)
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfShape_setMiterLimit(sfShape* shape, float miterLimit)
|
||||
{
|
||||
assert(shape);
|
||||
shape->setMiterLimit(miterLimit);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
const sfTexture* sfShape_getTexture(const sfShape* shape)
|
||||
{
|
||||
@@ -236,6 +244,14 @@ float sfShape_getOutlineThickness(const sfShape* shape)
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
float sfShape_getMiterLimit(const sfShape* shape)
|
||||
{
|
||||
assert(shape);
|
||||
return shape->getMiterLimit();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
size_t sfShape_getPointCount(const sfShape* shape)
|
||||
{
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <CSFML/Graphics/ConvertColor.hpp>
|
||||
#include <CSFML/Graphics/ConvertGlyph.hpp>
|
||||
#include <CSFML/Graphics/ConvertRect.hpp>
|
||||
#include <CSFML/Graphics/ConvertTransform.hpp>
|
||||
#include <CSFML/Graphics/Font.h>
|
||||
@@ -33,6 +34,22 @@
|
||||
#include <CSFML/Graphics/TextStruct.hpp>
|
||||
#include <CSFML/System/ConvertVector2.hpp>
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
// Helper function for converting a SFML shaped glyph to a CSFML one
|
||||
[[nodiscard]] sfShapedGlyph convertShapedGlyph(const sf::Text::ShapedGlyph& shapedGlyph)
|
||||
{
|
||||
return {convertGlyph(shapedGlyph.glyph),
|
||||
convertVector2(shapedGlyph.position),
|
||||
shapedGlyph.cluster,
|
||||
static_cast<sfTextDirection>(shapedGlyph.textDirection),
|
||||
shapedGlyph.baseline,
|
||||
shapedGlyph.vertexOffset,
|
||||
shapedGlyph.vertexCount};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
#include <SFML/Graphics/Color.hpp>
|
||||
|
||||
|
||||
@@ -250,6 +267,22 @@ void sfText_setOutlineThickness(sfText* text, float thickness)
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfText_setLineAlignment(sfText* text, sfTextLineAlignment lineAlignment)
|
||||
{
|
||||
assert(text);
|
||||
text->setLineAlignment(static_cast<sf::Text::LineAlignment>(lineAlignment));
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfText_setTextOrientation(sfText* text, sfTextOrientation textOrientation)
|
||||
{
|
||||
assert(text);
|
||||
text->setTextOrientation(static_cast<sf::Text::TextOrientation>(textOrientation));
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
const char* sfText_getString(const sfText* text)
|
||||
{
|
||||
@@ -333,6 +366,22 @@ float sfText_getOutlineThickness(const sfText* text)
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
sfTextLineAlignment sfText_getLineAlignment(const sfText* text)
|
||||
{
|
||||
assert(text);
|
||||
return static_cast<sfTextLineAlignment>(text->getLineAlignment());
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
sfTextOrientation sfText_getTextOrientation(const sfText* text)
|
||||
{
|
||||
assert(text);
|
||||
return static_cast<sfTextOrientation>(text->getTextOrientation());
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
sfVector2f sfText_findCharacterPos(const sfText* text, size_t index)
|
||||
{
|
||||
@@ -341,6 +390,101 @@ sfVector2f sfText_findCharacterPos(const sfText* text, size_t index)
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
const sfShapedGlyph* sfText_getShapedGlyphs(const sfText* text, size_t* count)
|
||||
{
|
||||
assert(text);
|
||||
assert(count);
|
||||
|
||||
const auto& shapedGlyphs = text->getShapedGlyphs();
|
||||
text->ShapedGlyphs.clear();
|
||||
text->ShapedGlyphs.reserve(shapedGlyphs.size());
|
||||
for (const auto& shapedGlyph : shapedGlyphs)
|
||||
text->ShapedGlyphs.push_back(convertShapedGlyph(shapedGlyph));
|
||||
|
||||
*count = text->ShapedGlyphs.size();
|
||||
return text->ShapedGlyphs.data();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
sfTextClusterGrouping sfText_getClusterGrouping(const sfText* text)
|
||||
{
|
||||
assert(text);
|
||||
return static_cast<sfTextClusterGrouping>(text->getClusterGrouping());
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfText_setClusterGrouping(sfText* text, sfTextClusterGrouping clusterGrouping)
|
||||
{
|
||||
assert(text);
|
||||
text->setClusterGrouping(static_cast<sf::Text::ClusterGrouping>(clusterGrouping));
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfText_setGlyphPreProcessor(sfText* text, sfGlyphPreProcessor glyphPreProcessor, void* userData)
|
||||
{
|
||||
assert(text);
|
||||
|
||||
if (!glyphPreProcessor)
|
||||
{
|
||||
text->setGlyphPreProcessor({});
|
||||
return;
|
||||
}
|
||||
|
||||
text->setGlyphPreProcessor(
|
||||
[glyphPreProcessor, userData](const sf::Text::ShapedGlyph& shapedGlyph,
|
||||
std::uint32_t& style,
|
||||
sf::Color& fillColor,
|
||||
sf::Color& outlineColor,
|
||||
float& outlineThickness)
|
||||
{
|
||||
const sfShapedGlyph glyph = convertShapedGlyph(shapedGlyph);
|
||||
sfColor csfmlFillColor = convertColor(fillColor);
|
||||
sfColor csfmlOutlineColor = convertColor(outlineColor);
|
||||
glyphPreProcessor(&glyph, &style, &csfmlFillColor, &csfmlOutlineColor, &outlineThickness, userData);
|
||||
fillColor = convertColor(csfmlFillColor);
|
||||
outlineColor = convertColor(csfmlOutlineColor);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
sfVertex* sfText_getVertexData(const sfText* text, size_t* count)
|
||||
{
|
||||
assert(text);
|
||||
assert(count);
|
||||
|
||||
// Make sure the geometry is up to date, sf::Text only updates it when needed
|
||||
[[maybe_unused]] const auto bounds = text->getLocalBounds();
|
||||
|
||||
sf::VertexArray& vertices = text->getVertexData();
|
||||
*count = vertices.getVertexCount();
|
||||
|
||||
// the cast is safe, sfVertex has to be binary compatible with sf::Vertex
|
||||
return *count > 0 ? reinterpret_cast<sfVertex*>(&vertices[0]) : nullptr;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
sfVertex* sfText_getOutlineVertexData(const sfText* text, size_t* count)
|
||||
{
|
||||
assert(text);
|
||||
assert(count);
|
||||
|
||||
// Make sure the geometry is up to date, sf::Text only updates it when needed
|
||||
[[maybe_unused]] const auto bounds = text->getLocalBounds();
|
||||
|
||||
sf::VertexArray& vertices = text->getOutlineVertexData();
|
||||
*count = vertices.getVertexCount();
|
||||
|
||||
// the cast is safe, sfVertex has to be binary compatible with sf::Vertex
|
||||
return *count > 0 ? reinterpret_cast<sfVertex*>(&vertices[0]) : nullptr;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
sfFloatRect sfText_getLocalBounds(const sfText* text)
|
||||
{
|
||||
|
||||
@@ -29,11 +29,13 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <CSFML/Graphics/FontStruct.hpp>
|
||||
#include <CSFML/Graphics/Rect.h>
|
||||
#include <CSFML/Graphics/Text.h>
|
||||
#include <CSFML/Graphics/Transform.h>
|
||||
|
||||
#include <SFML/Graphics/Text.hpp>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
@@ -42,8 +44,9 @@
|
||||
struct sfText : sf::Text
|
||||
{
|
||||
using sf::Text::Text;
|
||||
const sfFont* Font{};
|
||||
mutable std::string String;
|
||||
mutable sfTransform Transform{};
|
||||
mutable sfTransform InverseTransform{};
|
||||
const sfFont* Font{};
|
||||
mutable std::string String;
|
||||
mutable sfTransform Transform{};
|
||||
mutable sfTransform InverseTransform{};
|
||||
mutable std::vector<sfShapedGlyph> ShapedGlyphs;
|
||||
};
|
||||
@@ -3,6 +3,10 @@ set(SRCROOT ${PROJECT_SOURCE_DIR}/src/CSFML/Network)
|
||||
|
||||
# all source files
|
||||
set(SRC
|
||||
${SRCROOT}/ConvertIpAddress.hpp
|
||||
${SRCROOT}/Dns.cpp
|
||||
${SRCROOT}/DnsStruct.hpp
|
||||
${INCROOT}/Dns.h
|
||||
${INCROOT}/Export.h
|
||||
${SRCROOT}/Ftp.cpp
|
||||
${SRCROOT}/FtpStruct.hpp
|
||||
@@ -15,6 +19,9 @@ set(SRC
|
||||
${SRCROOT}/Packet.cpp
|
||||
${SRCROOT}/PacketStruct.hpp
|
||||
${INCROOT}/Packet.h
|
||||
${SRCROOT}/Sftp.cpp
|
||||
${SRCROOT}/SftpStruct.hpp
|
||||
${INCROOT}/Sftp.h
|
||||
${SRCROOT}/SocketSelector.cpp
|
||||
${SRCROOT}/SocketSelectorStruct.hpp
|
||||
${INCROOT}/SocketSelector.h
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2026 Laurent Gomila (laurent@sfml-dev.org)
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <CSFML/Network/IpAddress.h>
|
||||
|
||||
#include <SFML/Network/IpAddress.hpp>
|
||||
|
||||
#include <cstring>
|
||||
#include <optional>
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Convert sf::IpAddress to sfIpAddress
|
||||
////////////////////////////////////////////////////////////
|
||||
[[nodiscard]] inline sfIpAddress convertIpAddress(const sf::IpAddress& address)
|
||||
{
|
||||
sfIpAddress result{};
|
||||
std::strncpy(result.address, address.toString().c_str(), sizeof(result.address) - 1);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Convert std::optional<sf::IpAddress> to sfIpAddress
|
||||
////////////////////////////////////////////////////////////
|
||||
[[nodiscard]] inline sfIpAddress convertIpAddress(const std::optional<sf::IpAddress>& address)
|
||||
{
|
||||
return address ? convertIpAddress(*address) : sfIpAddress_None;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Convert sfIpAddress to std::optional<sf::IpAddress>
|
||||
////////////////////////////////////////////////////////////
|
||||
[[nodiscard]] inline std::optional<sf::IpAddress> convertIpAddress(const sfIpAddress& address)
|
||||
{
|
||||
return sf::IpAddress::fromString(address.address);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Convert an optional sfIpAddressType to std::optional<sf::IpAddress::Type>
|
||||
////////////////////////////////////////////////////////////
|
||||
[[nodiscard]] inline std::optional<sf::IpAddress::Type> convertIpAddressType(const sfIpAddressType* type)
|
||||
{
|
||||
if (!type)
|
||||
return std::nullopt;
|
||||
|
||||
return static_cast<sf::IpAddress::Type>(*type);
|
||||
}
|
||||
@@ -0,0 +1,285 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2026 Laurent Gomila (laurent@sfml-dev.org)
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <CSFML/Network/ConvertIpAddress.hpp>
|
||||
#include <CSFML/Network/Dns.h>
|
||||
#include <CSFML/Network/DnsStruct.hpp>
|
||||
|
||||
#include <SFML/Network/Dns.hpp>
|
||||
#include <SFML/System/String.hpp>
|
||||
|
||||
#include <cassert>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
[[nodiscard]] sf::String fromUtf8(const char* string)
|
||||
{
|
||||
return sf::String::fromUtf8(string, string + std::strlen(string));
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
[[nodiscard]] std::string toUtf8(const sf::String& string)
|
||||
{
|
||||
const auto utf8 = string.toUtf8();
|
||||
return {utf8.begin(), utf8.end()};
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
[[nodiscard]] std::vector<sf::IpAddress> convertServers(const sfIpAddress* servers, size_t serverCount)
|
||||
{
|
||||
std::vector<sf::IpAddress> result;
|
||||
|
||||
if (!servers)
|
||||
return result;
|
||||
|
||||
result.reserve(serverCount);
|
||||
for (size_t i = 0; i < serverCount; ++i)
|
||||
{
|
||||
if (const auto address = convertIpAddress(servers[i]))
|
||||
result.push_back(*address);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
[[nodiscard]] std::optional<sf::Time> convertTimeout(sfTime timeout)
|
||||
{
|
||||
if (timeout.microseconds == 0)
|
||||
return std::nullopt;
|
||||
|
||||
return sf::microseconds(timeout.microseconds);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
sfIpAddress* sfDns_resolve(const char* hostname, const sfIpAddress* servers, size_t serverCount, sfTime timeout, size_t* count)
|
||||
{
|
||||
assert(hostname);
|
||||
assert(count);
|
||||
|
||||
*count = 0;
|
||||
|
||||
const auto addresses = sf::Dns::resolve(fromUtf8(hostname), convertServers(servers, serverCount), convertTimeout(timeout));
|
||||
if (!addresses || addresses->empty())
|
||||
return nullptr;
|
||||
|
||||
auto* result = static_cast<sfIpAddress*>(std::malloc(addresses->size() * sizeof(sfIpAddress)));
|
||||
if (!result)
|
||||
return nullptr;
|
||||
|
||||
for (std::size_t i = 0; i < addresses->size(); ++i)
|
||||
result[i] = convertIpAddress((*addresses)[i]);
|
||||
|
||||
*count = addresses->size();
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
sfDnsNsRecords* sfDns_queryNs(const char* hostname, const sfIpAddress* servers, size_t serverCount, sfTime timeout)
|
||||
{
|
||||
assert(hostname);
|
||||
|
||||
auto* records = new sfDnsNsRecords;
|
||||
for (const auto& record :
|
||||
sf::Dns::queryNs(fromUtf8(hostname), convertServers(servers, serverCount), convertTimeout(timeout)))
|
||||
records->Records.push_back(toUtf8(record));
|
||||
|
||||
return records;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
sfDnsMxRecords* sfDns_queryMx(const char* hostname, const sfIpAddress* servers, size_t serverCount, sfTime timeout)
|
||||
{
|
||||
assert(hostname);
|
||||
|
||||
auto* records = new sfDnsMxRecords;
|
||||
for (const auto& record :
|
||||
sf::Dns::queryMx(fromUtf8(hostname), convertServers(servers, serverCount), convertTimeout(timeout)))
|
||||
records->Records.push_back({toUtf8(record.exchange), record.preference});
|
||||
|
||||
return records;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
sfDnsSrvRecords* sfDns_querySrv(const char* hostname, const sfIpAddress* servers, size_t serverCount, sfTime timeout)
|
||||
{
|
||||
assert(hostname);
|
||||
|
||||
auto* records = new sfDnsSrvRecords;
|
||||
for (const auto& record :
|
||||
sf::Dns::querySrv(fromUtf8(hostname), convertServers(servers, serverCount), convertTimeout(timeout)))
|
||||
records->Records.push_back({toUtf8(record.target), record.port, record.weight, record.priority});
|
||||
|
||||
return records;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
sfDnsTxtRecords* sfDns_queryTxt(const char* hostname, const sfIpAddress* servers, size_t serverCount, sfTime timeout)
|
||||
{
|
||||
assert(hostname);
|
||||
|
||||
auto* records = new sfDnsTxtRecords;
|
||||
for (const auto& record :
|
||||
sf::Dns::queryTxt(fromUtf8(hostname), convertServers(servers, serverCount), convertTimeout(timeout)))
|
||||
{
|
||||
auto& strings = records->Records.emplace_back();
|
||||
for (const auto& string : record)
|
||||
strings.push_back(toUtf8(string));
|
||||
}
|
||||
|
||||
return records;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
sfIpAddress sfDns_getPublicAddress(sfTime timeout, sfIpAddressType type)
|
||||
{
|
||||
return convertIpAddress(sf::Dns::getPublicAddress(convertTimeout(timeout), static_cast<sf::IpAddress::Type>(type)));
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfDnsNsRecords_destroy(const sfDnsNsRecords* records)
|
||||
{
|
||||
delete records;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
size_t sfDnsNsRecords_getCount(const sfDnsNsRecords* records)
|
||||
{
|
||||
assert(records);
|
||||
return records->Records.size();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
const char* sfDnsNsRecords_getRecord(const sfDnsNsRecords* records, size_t index)
|
||||
{
|
||||
assert(records);
|
||||
assert(index < records->Records.size());
|
||||
return records->Records[index].c_str();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfDnsMxRecords_destroy(const sfDnsMxRecords* records)
|
||||
{
|
||||
delete records;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
size_t sfDnsMxRecords_getCount(const sfDnsMxRecords* records)
|
||||
{
|
||||
assert(records);
|
||||
return records->Records.size();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
sfDnsMxRecord sfDnsMxRecords_getRecord(const sfDnsMxRecords* records, size_t index)
|
||||
{
|
||||
assert(records);
|
||||
assert(index < records->Records.size());
|
||||
|
||||
const auto& record = records->Records[index];
|
||||
return {record.exchange.c_str(), record.preference};
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfDnsSrvRecords_destroy(const sfDnsSrvRecords* records)
|
||||
{
|
||||
delete records;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
size_t sfDnsSrvRecords_getCount(const sfDnsSrvRecords* records)
|
||||
{
|
||||
assert(records);
|
||||
return records->Records.size();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
sfDnsSrvRecord sfDnsSrvRecords_getRecord(const sfDnsSrvRecords* records, size_t index)
|
||||
{
|
||||
assert(records);
|
||||
assert(index < records->Records.size());
|
||||
|
||||
const auto& record = records->Records[index];
|
||||
return {record.target.c_str(), record.port, record.weight, record.priority};
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfDnsTxtRecords_destroy(const sfDnsTxtRecords* records)
|
||||
{
|
||||
delete records;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
size_t sfDnsTxtRecords_getCount(const sfDnsTxtRecords* records)
|
||||
{
|
||||
assert(records);
|
||||
return records->Records.size();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
size_t sfDnsTxtRecords_getStringCount(const sfDnsTxtRecords* records, size_t index)
|
||||
{
|
||||
assert(records);
|
||||
assert(index < records->Records.size());
|
||||
return records->Records[index].size();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
const char* sfDnsTxtRecords_getString(const sfDnsTxtRecords* records, size_t index, size_t stringIndex)
|
||||
{
|
||||
assert(records);
|
||||
assert(index < records->Records.size());
|
||||
assert(stringIndex < records->Records[index].size());
|
||||
return records->Records[index][stringIndex].c_str();
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2026 Laurent Gomila (laurent@sfml-dev.org)
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Internal structure of sfDnsNsRecords
|
||||
////////////////////////////////////////////////////////////
|
||||
struct sfDnsNsRecords
|
||||
{
|
||||
std::vector<std::string> Records;
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Internal structure of sfDnsMxRecords
|
||||
////////////////////////////////////////////////////////////
|
||||
struct sfDnsMxRecords
|
||||
{
|
||||
struct Record
|
||||
{
|
||||
std::string exchange;
|
||||
std::uint16_t preference{};
|
||||
};
|
||||
|
||||
std::vector<Record> Records;
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Internal structure of sfDnsSrvRecords
|
||||
////////////////////////////////////////////////////////////
|
||||
struct sfDnsSrvRecords
|
||||
{
|
||||
struct Record
|
||||
{
|
||||
std::string target;
|
||||
std::uint16_t port{};
|
||||
std::uint16_t weight{};
|
||||
std::uint16_t priority{};
|
||||
};
|
||||
|
||||
std::vector<Record> Records;
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Internal structure of sfDnsTxtRecords
|
||||
////////////////////////////////////////////////////////////
|
||||
struct sfDnsTxtRecords
|
||||
{
|
||||
std::vector<std::vector<std::string>> Records;
|
||||
};
|
||||
@@ -25,6 +25,7 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <CSFML/Network/ConvertIpAddress.hpp>
|
||||
#include <CSFML/Network/Ftp.h>
|
||||
#include <CSFML/Network/FtpStruct.hpp>
|
||||
|
||||
@@ -205,7 +206,7 @@ sfFtpResponse* sfFtp_connect(sfFtp* ftp, sfIpAddress server, unsigned short port
|
||||
{
|
||||
assert(ftp);
|
||||
|
||||
std::optional<sf::IpAddress> sfmlServer = sf::IpAddress::resolve(server.address);
|
||||
std::optional<sf::IpAddress> sfmlServer = convertIpAddress(server);
|
||||
|
||||
if (!sfmlServer)
|
||||
return nullptr;
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <CSFML/Network/ConvertIpAddress.hpp>
|
||||
#include <CSFML/Network/Http.h>
|
||||
#include <CSFML/Network/HttpStruct.hpp>
|
||||
|
||||
@@ -149,10 +150,18 @@ void sfHttp_destroy(const sfHttp* http)
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfHttp_setHost(sfHttp* http, const char* host, unsigned short port)
|
||||
bool sfHttp_setHost(sfHttp* http, const char* host, unsigned short port)
|
||||
{
|
||||
assert(http);
|
||||
http->setHost(host ? host : "", port);
|
||||
return http->setHost(host ? host : "", port);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool sfHttp_setHostWithAddressType(sfHttp* http, const char* host, unsigned short port, const sfIpAddressType* addressType)
|
||||
{
|
||||
assert(http);
|
||||
return http->setHost(host ? host : "", port, convertIpAddressType(addressType));
|
||||
}
|
||||
|
||||
|
||||
@@ -163,3 +172,12 @@ sfHttpResponse* sfHttp_sendRequest(sfHttp* http, const sfHttpRequest* request, s
|
||||
assert(request);
|
||||
return new sfHttpResponse{http->sendRequest(*request, sf::microseconds(timeout.microseconds))};
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
sfHttpResponse* sfHttp_sendRequestWithVerification(const sfHttp* http, const sfHttpRequest* request, sfTime timeout, bool verifyServer)
|
||||
{
|
||||
assert(http);
|
||||
assert(request);
|
||||
return new sfHttpResponse{http->sendRequest(*request, sf::microseconds(timeout.microseconds), verifyServer)};
|
||||
}
|
||||
+106
-25
@@ -25,63 +25,90 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <CSFML/Network/ConvertIpAddress.hpp>
|
||||
#include <CSFML/Network/IpAddress.h>
|
||||
|
||||
#include <SFML/Network/IpAddress.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <cstring>
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
// Helper function for converting a SFML address to a CSFML one
|
||||
[[nodiscard]] sfIpAddress fromSFMLAddress(std::optional<sf::IpAddress> address)
|
||||
{
|
||||
if (!address)
|
||||
return sfIpAddress_None;
|
||||
|
||||
sfIpAddress result{};
|
||||
std::strncpy(result.address, address->toString().c_str(), 15);
|
||||
return result;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
const sfIpAddress sfIpAddress_None = {{0}};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
const sfIpAddress sfIpAddress_Any = sfIpAddress_fromBytes(0, 0, 0, 0);
|
||||
const sfIpAddress sfIpAddress_Any = {"0.0.0.0"};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
const sfIpAddress sfIpAddress_LocalHost = sfIpAddress_fromBytes(127, 0, 0, 1);
|
||||
const sfIpAddress sfIpAddress_LocalHost = {"127.0.0.1"};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
const sfIpAddress sfIpAddress_Broadcast = sfIpAddress_fromBytes(255, 255, 255, 255);
|
||||
const sfIpAddress sfIpAddress_Broadcast = {"255.255.255.255"};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
const sfIpAddress sfIpAddress_AnyV4 = {"0.0.0.0"};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
const sfIpAddress sfIpAddress_LocalHostV4 = {"127.0.0.1"};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
const sfIpAddress sfIpAddress_BroadcastV4 = {"255.255.255.255"};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
const sfIpAddress sfIpAddress_AnyV6 = {"::"};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
const sfIpAddress sfIpAddress_LocalHostV6 = {"::1"};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
sfIpAddress sfIpAddress_fromString(const char* address)
|
||||
{
|
||||
assert(address);
|
||||
return fromSFMLAddress(sf::IpAddress::resolve(address));
|
||||
return convertIpAddress(sf::IpAddress::fromString(address));
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
sfIpAddress sfIpAddress_resolve(const char* address)
|
||||
{
|
||||
assert(address);
|
||||
return convertIpAddress(sf::IpAddress::resolve(address));
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
sfIpAddress sfIpAddress_fromBytes(uint8_t byte0, uint8_t byte1, uint8_t byte2, uint8_t byte3)
|
||||
{
|
||||
return fromSFMLAddress(sf::IpAddress(byte0, byte1, byte2, byte3));
|
||||
return convertIpAddress(sf::IpAddress(byte0, byte1, byte2, byte3));
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
sfIpAddress sfIpAddress_fromInteger(uint32_t address)
|
||||
{
|
||||
return fromSFMLAddress(sf::IpAddress(address));
|
||||
return convertIpAddress(sf::IpAddress(address));
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
sfIpAddress sfIpAddress_fromV6Bytes(const uint8_t bytes[16])
|
||||
{
|
||||
assert(bytes);
|
||||
|
||||
std::array<std::uint8_t, 16> array{};
|
||||
std::copy(bytes, bytes + array.size(), array.begin());
|
||||
return convertIpAddress(sf::IpAddress(array));
|
||||
}
|
||||
|
||||
|
||||
@@ -96,20 +123,74 @@ void sfIpAddress_toString(sfIpAddress address, char* string)
|
||||
////////////////////////////////////////////////////////////
|
||||
uint32_t sfIpAddress_toInteger(sfIpAddress address)
|
||||
{
|
||||
const auto sfmlAddress = sf::IpAddress::resolve(address.address);
|
||||
return sfmlAddress ? sfmlAddress->toInteger() : 0;
|
||||
const auto sfmlAddress = convertIpAddress(address);
|
||||
return sfmlAddress && sfmlAddress->isV4() ? sfmlAddress->toInteger() : 0;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool sfIpAddress_toV6Bytes(sfIpAddress address, uint8_t bytes[16])
|
||||
{
|
||||
assert(bytes);
|
||||
|
||||
const auto sfmlAddress = convertIpAddress(address);
|
||||
if (!sfmlAddress || !sfmlAddress->isV6())
|
||||
return false;
|
||||
|
||||
const auto array = sfmlAddress->toBytes();
|
||||
std::copy(array.begin(), array.end(), bytes);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
sfIpAddressType sfIpAddress_getType(sfIpAddress address)
|
||||
{
|
||||
const auto sfmlAddress = convertIpAddress(address);
|
||||
return sfmlAddress ? static_cast<sfIpAddressType>(sfmlAddress->getType()) : sfIpAddressV4;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool sfIpAddress_isV4(sfIpAddress address)
|
||||
{
|
||||
const auto sfmlAddress = convertIpAddress(address);
|
||||
return sfmlAddress && sfmlAddress->isV4();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool sfIpAddress_isV6(sfIpAddress address)
|
||||
{
|
||||
const auto sfmlAddress = convertIpAddress(address);
|
||||
return sfmlAddress && sfmlAddress->isV6();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
sfIpAddress sfIpAddress_getLocalAddress()
|
||||
{
|
||||
return fromSFMLAddress(sf::IpAddress::getLocalAddress());
|
||||
return convertIpAddress(sf::IpAddress::getLocalAddress());
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
sfIpAddress sfIpAddress_getLocalAddressOfType(sfIpAddressType type)
|
||||
{
|
||||
return convertIpAddress(sf::IpAddress::getLocalAddress(static_cast<sf::IpAddress::Type>(type)));
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
sfIpAddress sfIpAddress_getPublicAddress(sfTime timeout)
|
||||
{
|
||||
return fromSFMLAddress(sf::IpAddress::getPublicAddress(sf::microseconds(timeout.microseconds)));
|
||||
return convertIpAddress(sf::IpAddress::getPublicAddress(sf::microseconds(timeout.microseconds)));
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
sfIpAddress sfIpAddress_getPublicAddressOfType(sfTime timeout, const sfIpAddressType* type, bool secure)
|
||||
{
|
||||
return convertIpAddress(
|
||||
sf::IpAddress::getPublicAddress(sf::microseconds(timeout.microseconds), convertIpAddressType(type), secure));
|
||||
}
|
||||
@@ -0,0 +1,547 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2026 Laurent Gomila (laurent@sfml-dev.org)
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <CSFML/Network/ConvertIpAddress.hpp>
|
||||
#include <CSFML/Network/Sftp.h>
|
||||
#include <CSFML/Network/SftpStruct.hpp>
|
||||
#include <CSFML/System/ConvertTimeoutWithPredicate.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <chrono>
|
||||
#include <filesystem>
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
[[nodiscard]] std::filesystem::path toPath(const char* path)
|
||||
{
|
||||
return std::filesystem::u8path(path ? path : "");
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
[[nodiscard]] std::string fromPath(const std::filesystem::path& path)
|
||||
{
|
||||
const auto string = path.u8string();
|
||||
return {string.begin(), string.end()};
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
[[nodiscard]] sfSftpFileType convertFileType(std::filesystem::file_type type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case std::filesystem::file_type::none:
|
||||
return sfSftpFileNone;
|
||||
case std::filesystem::file_type::not_found:
|
||||
return sfSftpFileNotFound;
|
||||
case std::filesystem::file_type::regular:
|
||||
return sfSftpFileRegular;
|
||||
case std::filesystem::file_type::directory:
|
||||
return sfSftpFileDirectory;
|
||||
case std::filesystem::file_type::symlink:
|
||||
return sfSftpFileSymlink;
|
||||
case std::filesystem::file_type::block:
|
||||
return sfSftpFileBlock;
|
||||
case std::filesystem::file_type::character:
|
||||
return sfSftpFileCharacter;
|
||||
case std::filesystem::file_type::fifo:
|
||||
return sfSftpFileFifo;
|
||||
case std::filesystem::file_type::socket:
|
||||
return sfSftpFileSocket;
|
||||
default:
|
||||
return sfSftpFileUnknown;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// SFML stores the seconds since the Unix epoch in the file time
|
||||
[[nodiscard]] std::int64_t convertFileTime(std::filesystem::file_time_type time)
|
||||
{
|
||||
return std::chrono::duration_cast<std::chrono::seconds>(time.time_since_epoch()).count();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
[[nodiscard]] sfSftpAttributes convertAttributes(const sf::Sftp::Attributes& attributes, const std::string& path)
|
||||
{
|
||||
sfSftpAttributes result{};
|
||||
result.path = path.c_str();
|
||||
|
||||
if (attributes.type)
|
||||
{
|
||||
result.hasType = true;
|
||||
result.type = convertFileType(*attributes.type);
|
||||
}
|
||||
|
||||
if (attributes.size)
|
||||
{
|
||||
result.hasSize = true;
|
||||
result.size = *attributes.size;
|
||||
}
|
||||
|
||||
if (attributes.permissions)
|
||||
{
|
||||
result.hasPermissions = true;
|
||||
result.permissions = static_cast<std::uint32_t>(*attributes.permissions);
|
||||
}
|
||||
|
||||
if (attributes.userId)
|
||||
{
|
||||
result.hasUserId = true;
|
||||
result.userId = *attributes.userId;
|
||||
}
|
||||
|
||||
if (attributes.groupId)
|
||||
{
|
||||
result.hasGroupId = true;
|
||||
result.groupId = *attributes.groupId;
|
||||
}
|
||||
|
||||
if (attributes.accessTime)
|
||||
{
|
||||
result.hasAccessTime = true;
|
||||
result.accessTime = convertFileTime(*attributes.accessTime);
|
||||
}
|
||||
|
||||
if (attributes.modificationTime)
|
||||
{
|
||||
result.hasModificationTime = true;
|
||||
result.modificationTime = convertFileTime(*attributes.modificationTime);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
[[nodiscard]] sfSftpResult* createResult(const sf::Sftp::Result& result)
|
||||
{
|
||||
return new sfSftpResult{result};
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
[[nodiscard]] sfSftpPathResult* createResult(const sf::Sftp::PathResult& result)
|
||||
{
|
||||
return new sfSftpPathResult{result, fromPath(result.getPath())};
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
[[nodiscard]] sfSftpAttributesResult* createResult(const sf::Sftp::AttributesResult& result)
|
||||
{
|
||||
return new sfSftpAttributesResult{result, fromPath(result.getAttributes().path)};
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
[[nodiscard]] sfSftpListingResult* createResult(const sf::Sftp::ListingResult& result)
|
||||
{
|
||||
std::vector<std::string> paths;
|
||||
paths.reserve(result.getListing().size());
|
||||
for (const auto& attributes : result.getListing())
|
||||
paths.push_back(fromPath(attributes.path));
|
||||
|
||||
return new sfSftpListingResult{result, std::move(paths)};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfSftpResult_destroy(const sfSftpResult* result)
|
||||
{
|
||||
delete result;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool sfSftpResult_isOk(const sfSftpResult* result)
|
||||
{
|
||||
assert(result);
|
||||
return result->isOk();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
sfSftpResultValue sfSftpResult_getValue(const sfSftpResult* result)
|
||||
{
|
||||
assert(result);
|
||||
return static_cast<sfSftpResultValue>(result->getValue());
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
const char* sfSftpResult_getMessage(const sfSftpResult* result)
|
||||
{
|
||||
assert(result);
|
||||
return result->getMessage().c_str();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfSftpPathResult_destroy(const sfSftpPathResult* result)
|
||||
{
|
||||
delete result;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool sfSftpPathResult_isOk(const sfSftpPathResult* result)
|
||||
{
|
||||
assert(result);
|
||||
return result->isOk();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
sfSftpResultValue sfSftpPathResult_getValue(const sfSftpPathResult* result)
|
||||
{
|
||||
assert(result);
|
||||
return static_cast<sfSftpResultValue>(result->getValue());
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
const char* sfSftpPathResult_getMessage(const sfSftpPathResult* result)
|
||||
{
|
||||
assert(result);
|
||||
return result->getMessage().c_str();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
const char* sfSftpPathResult_getPath(const sfSftpPathResult* result)
|
||||
{
|
||||
assert(result);
|
||||
return result->Path.c_str();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfSftpAttributesResult_destroy(const sfSftpAttributesResult* result)
|
||||
{
|
||||
delete result;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool sfSftpAttributesResult_isOk(const sfSftpAttributesResult* result)
|
||||
{
|
||||
assert(result);
|
||||
return result->isOk();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
sfSftpResultValue sfSftpAttributesResult_getValue(const sfSftpAttributesResult* result)
|
||||
{
|
||||
assert(result);
|
||||
return static_cast<sfSftpResultValue>(result->getValue());
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
const char* sfSftpAttributesResult_getMessage(const sfSftpAttributesResult* result)
|
||||
{
|
||||
assert(result);
|
||||
return result->getMessage().c_str();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
sfSftpAttributes sfSftpAttributesResult_getAttributes(const sfSftpAttributesResult* result)
|
||||
{
|
||||
assert(result);
|
||||
return convertAttributes(result->getAttributes(), result->Path);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfSftpListingResult_destroy(const sfSftpListingResult* result)
|
||||
{
|
||||
delete result;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool sfSftpListingResult_isOk(const sfSftpListingResult* result)
|
||||
{
|
||||
assert(result);
|
||||
return result->isOk();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
sfSftpResultValue sfSftpListingResult_getValue(const sfSftpListingResult* result)
|
||||
{
|
||||
assert(result);
|
||||
return static_cast<sfSftpResultValue>(result->getValue());
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
const char* sfSftpListingResult_getMessage(const sfSftpListingResult* result)
|
||||
{
|
||||
assert(result);
|
||||
return result->getMessage().c_str();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
size_t sfSftpListingResult_getCount(const sfSftpListingResult* result)
|
||||
{
|
||||
assert(result);
|
||||
return result->getListing().size();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
sfSftpAttributes sfSftpListingResult_getAttributes(const sfSftpListingResult* result, size_t index)
|
||||
{
|
||||
assert(result);
|
||||
assert(index < result->getListing().size());
|
||||
return convertAttributes(result->getListing()[index], result->Paths[index]);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
sfSftp* sfSftp_create()
|
||||
{
|
||||
return new sfSftp;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfSftp_destroy(const sfSftp* sftp)
|
||||
{
|
||||
delete sftp;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
sfSftpResult* sfSftp_connect(sfSftp* sftp, sfIpAddress server, unsigned short port, sfTimeoutWithPredicate timeout)
|
||||
{
|
||||
assert(sftp);
|
||||
|
||||
const auto address = convertIpAddress(server);
|
||||
if (!address)
|
||||
return createResult(sf::Sftp::Result(sf::Sftp::Result::Value::Error, "Invalid server address"));
|
||||
|
||||
return createResult(sftp->connect(*address, port, convertTimeoutWithPredicate(timeout)));
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
sfSftpResult* sfSftp_disconnect(sfSftp* sftp, sfTimeoutWithPredicate timeout)
|
||||
{
|
||||
assert(sftp);
|
||||
return createResult(sftp->disconnect(convertTimeoutWithPredicate(timeout)));
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool sfSftp_getSessionInfo(const sfSftp* sftp, sfSftpSessionInfo* info)
|
||||
{
|
||||
assert(sftp);
|
||||
assert(info);
|
||||
|
||||
sftp->SessionInfo = sftp->getSessionInfo();
|
||||
if (!sftp->SessionInfo)
|
||||
return false;
|
||||
|
||||
const auto& sessionInfo = *sftp->SessionInfo;
|
||||
const auto& hostKey = sessionInfo.hostKey;
|
||||
|
||||
*info = {};
|
||||
info->hostKeyType = static_cast<sfSftpHostKeyType>(hostKey.type);
|
||||
info->hostKeyData = reinterpret_cast<const std::uint8_t*>(hostKey.data.data());
|
||||
info->hostKeySize = hostKey.data.size();
|
||||
std::transform(hostKey.sha1.begin(),
|
||||
hostKey.sha1.end(),
|
||||
info->hostKeySha1,
|
||||
[](std::byte b) { return std::to_integer<std::uint8_t>(b); });
|
||||
std::transform(hostKey.sha256.begin(),
|
||||
hostKey.sha256.end(),
|
||||
info->hostKeySha256,
|
||||
[](std::byte b) { return std::to_integer<std::uint8_t>(b); });
|
||||
info->keyExchangeAlgorithm = sessionInfo.keyExchangeAlgorithm.c_str();
|
||||
info->hostKeyAlgorithm = sessionInfo.hostKeyAlgorithm.c_str();
|
||||
info->clientToServerEncryptionAlgorithm = sessionInfo.clientToServerEncryptionAlgorithm.c_str();
|
||||
info->serverToClientEncryptionAlgorithm = sessionInfo.serverToClientEncryptionAlgorithm.c_str();
|
||||
info->clientToServerMacAlgorithm = sessionInfo.clientToServerMacAlgorithm.c_str();
|
||||
info->serverToClientMacAlgorithm = sessionInfo.serverToClientMacAlgorithm.c_str();
|
||||
info->clientToServerCompressionAlgorithm = sessionInfo.clientToServerCompressionAlgorithm.c_str();
|
||||
info->serverToClientCompressionAlgorithm = sessionInfo.serverToClientCompressionAlgorithm.c_str();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
sfSftpResult* sfSftp_login(sfSftp* sftp, const char* name, const char* password, sfTimeoutWithPredicate timeout)
|
||||
{
|
||||
assert(sftp);
|
||||
return createResult(sftp->login(name ? name : "", password ? password : "", convertTimeoutWithPredicate(timeout)));
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
sfSftpResult* sfSftp_loginWithKey(
|
||||
sfSftp* sftp,
|
||||
const char* name,
|
||||
const char* publicKeyData,
|
||||
size_t publicKeyLength,
|
||||
const char* privateKeyData,
|
||||
size_t privateKeyLength,
|
||||
const char* privateKeyPassphrase,
|
||||
sfTimeoutWithPredicate timeout)
|
||||
{
|
||||
assert(sftp);
|
||||
assert(publicKeyData);
|
||||
assert(privateKeyData);
|
||||
return createResult(
|
||||
sftp->login(name ? name : "",
|
||||
publicKeyData,
|
||||
publicKeyLength,
|
||||
privateKeyData,
|
||||
privateKeyLength,
|
||||
privateKeyPassphrase ? privateKeyPassphrase : "",
|
||||
convertTimeoutWithPredicate(timeout)));
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
sfSftpPathResult* sfSftp_resolvePath(sfSftp* sftp, const char* path, sfTimeoutWithPredicate timeout)
|
||||
{
|
||||
assert(sftp);
|
||||
return createResult(sftp->resolvePath(toPath(path), convertTimeoutWithPredicate(timeout)));
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
sfSftpPathResult* sfSftp_getWorkingDirectory(sfSftp* sftp, sfTimeoutWithPredicate timeout)
|
||||
{
|
||||
assert(sftp);
|
||||
return createResult(sftp->getWorkingDirectory(convertTimeoutWithPredicate(timeout)));
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
sfSftpAttributesResult* sfSftp_getAttributes(sfSftp* sftp, const char* path, bool followLinks, sfTimeoutWithPredicate timeout)
|
||||
{
|
||||
assert(sftp);
|
||||
return createResult(sftp->getAttributes(toPath(path), followLinks, convertTimeoutWithPredicate(timeout)));
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
sfSftpListingResult* sfSftp_getDirectoryListing(sfSftp* sftp, const char* path, sfTimeoutWithPredicate timeout)
|
||||
{
|
||||
assert(sftp);
|
||||
return createResult(sftp->getDirectoryListing(toPath(path), convertTimeoutWithPredicate(timeout)));
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
sfSftpResult* sfSftp_createDirectory(sfSftp* sftp, const char* path, uint32_t permissions, sfTimeoutWithPredicate timeout)
|
||||
{
|
||||
assert(sftp);
|
||||
return createResult(sftp->createDirectory(toPath(path),
|
||||
static_cast<std::filesystem::perms>(permissions),
|
||||
convertTimeoutWithPredicate(timeout)));
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
sfSftpResult* sfSftp_deleteDirectory(sfSftp* sftp, const char* path, sfTimeoutWithPredicate timeout)
|
||||
{
|
||||
assert(sftp);
|
||||
return createResult(sftp->deleteDirectory(toPath(path), convertTimeoutWithPredicate(timeout)));
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
sfSftpResult* sfSftp_rename(sfSftp* sftp, const char* oldPath, const char* newPath, bool overwrite, sfTimeoutWithPredicate timeout)
|
||||
{
|
||||
assert(sftp);
|
||||
return createResult(sftp->rename(toPath(oldPath), toPath(newPath), overwrite, convertTimeoutWithPredicate(timeout)));
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
sfSftpResult* sfSftp_deleteFile(sfSftp* sftp, const char* path, sfTimeoutWithPredicate timeout)
|
||||
{
|
||||
assert(sftp);
|
||||
return createResult(sftp->deleteFile(toPath(path), convertTimeoutWithPredicate(timeout)));
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
sfSftpResult* sfSftp_download(sfSftp* sftp,
|
||||
const char* remotePath,
|
||||
sfSftpDownloadCallback callback,
|
||||
void* userData,
|
||||
uint64_t offset,
|
||||
sfTimeoutWithPredicate timeout)
|
||||
{
|
||||
assert(sftp);
|
||||
assert(callback);
|
||||
return createResult(sftp->download(
|
||||
toPath(remotePath),
|
||||
[callback, userData](const void* data, std::size_t size) { return callback(data, size, userData); },
|
||||
offset,
|
||||
convertTimeoutWithPredicate(timeout)));
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
sfSftpResult* sfSftp_upload(
|
||||
sfSftp* sftp,
|
||||
const char* remotePath,
|
||||
sfSftpUploadCallback callback,
|
||||
void* userData,
|
||||
uint32_t permissions,
|
||||
bool truncate,
|
||||
bool append,
|
||||
uint64_t offset,
|
||||
sfTimeoutWithPredicate timeout)
|
||||
{
|
||||
assert(sftp);
|
||||
assert(callback);
|
||||
return createResult(sftp->upload(
|
||||
toPath(remotePath),
|
||||
[callback, userData](void* data, std::size_t& size) { return callback(data, &size, userData); },
|
||||
static_cast<std::filesystem::perms>(permissions),
|
||||
truncate,
|
||||
append,
|
||||
offset,
|
||||
convertTimeoutWithPredicate(timeout)));
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2026 Laurent Gomila (laurent@sfml-dev.org)
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Network/Sftp.hpp>
|
||||
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Internal structure of sfSftp
|
||||
////////////////////////////////////////////////////////////
|
||||
struct sfSftp : sf::Sftp
|
||||
{
|
||||
mutable std::optional<sf::Sftp::SessionInfo> SessionInfo;
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Internal structure of sfSftpResult
|
||||
////////////////////////////////////////////////////////////
|
||||
struct sfSftpResult : sf::Sftp::Result
|
||||
{
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Internal structure of sfSftpPathResult
|
||||
////////////////////////////////////////////////////////////
|
||||
struct sfSftpPathResult : sf::Sftp::PathResult
|
||||
{
|
||||
std::string Path;
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Internal structure of sfSftpAttributesResult
|
||||
////////////////////////////////////////////////////////////
|
||||
struct sfSftpAttributesResult : sf::Sftp::AttributesResult
|
||||
{
|
||||
std::string Path;
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Internal structure of sfSftpListingResult
|
||||
////////////////////////////////////////////////////////////
|
||||
struct sfSftpListingResult : sf::Sftp::ListingResult
|
||||
{
|
||||
std::vector<std::string> Paths;
|
||||
};
|
||||
@@ -31,6 +31,22 @@
|
||||
#include <CSFML/Network/TcpSocketStruct.hpp>
|
||||
#include <CSFML/Network/UdpSocketStruct.hpp>
|
||||
|
||||
#include <functional>
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
[[nodiscard]] std::function<void(sf::SocketSelector::ReadinessType)> convertCallback(sfSocketSelectorCallback callback,
|
||||
void* userData)
|
||||
{
|
||||
if (!callback)
|
||||
return {};
|
||||
|
||||
return [callback, userData](sf::SocketSelector::ReadinessType readiness) { callback(readiness, userData); };
|
||||
}
|
||||
} // namespace
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
sfSocketSelector* sfSocketSelector_create()
|
||||
@@ -55,44 +71,86 @@ void sfSocketSelector_destroy(const sfSocketSelector* selector)
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfSocketSelector_addTcpListener(sfSocketSelector* selector, sfTcpListener* socket)
|
||||
bool sfSocketSelector_addTcpListener(sfSocketSelector* selector, sfTcpListener* socket)
|
||||
{
|
||||
assert(selector);
|
||||
assert(socket);
|
||||
selector->add(*socket);
|
||||
return selector->add(*socket);
|
||||
}
|
||||
void sfSocketSelector_addTcpSocket(sfSocketSelector* selector, sfTcpSocket* socket)
|
||||
bool sfSocketSelector_addTcpSocket(sfSocketSelector* selector, sfTcpSocket* socket)
|
||||
{
|
||||
assert(selector);
|
||||
assert(socket);
|
||||
selector->add(*socket);
|
||||
return selector->add(*socket);
|
||||
}
|
||||
void sfSocketSelector_addUdpSocket(sfSocketSelector* selector, sfUdpSocket* socket)
|
||||
bool sfSocketSelector_addUdpSocket(sfSocketSelector* selector, sfUdpSocket* socket)
|
||||
{
|
||||
assert(selector);
|
||||
assert(socket);
|
||||
selector->add(*socket);
|
||||
return selector->add(*socket);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfSocketSelector_removeTcpListener(sfSocketSelector* selector, sfTcpListener* socket)
|
||||
bool sfSocketSelector_addTcpListenerWithReadiness(
|
||||
sfSocketSelector* selector,
|
||||
sfTcpListener* socket,
|
||||
uint32_t readiness,
|
||||
sfSocketSelectorCallback callback,
|
||||
void* userData)
|
||||
{
|
||||
assert(selector);
|
||||
assert(socket);
|
||||
selector->remove(*socket);
|
||||
return selector->add(*socket, readiness, convertCallback(callback, userData));
|
||||
}
|
||||
void sfSocketSelector_removeTcpSocket(sfSocketSelector* selector, sfTcpSocket* socket)
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool sfSocketSelector_addTcpSocketWithReadiness(
|
||||
sfSocketSelector* selector,
|
||||
sfTcpSocket* socket,
|
||||
uint32_t readiness,
|
||||
sfSocketSelectorCallback callback,
|
||||
void* userData)
|
||||
{
|
||||
assert(selector);
|
||||
assert(socket);
|
||||
selector->remove(*socket);
|
||||
return selector->add(*socket, readiness, convertCallback(callback, userData));
|
||||
}
|
||||
void sfSocketSelector_removeUdpSocket(sfSocketSelector* selector, sfUdpSocket* socket)
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool sfSocketSelector_addUdpSocketWithReadiness(
|
||||
sfSocketSelector* selector,
|
||||
sfUdpSocket* socket,
|
||||
uint32_t readiness,
|
||||
sfSocketSelectorCallback callback,
|
||||
void* userData)
|
||||
{
|
||||
assert(selector);
|
||||
assert(socket);
|
||||
selector->remove(*socket);
|
||||
return selector->add(*socket, readiness, convertCallback(callback, userData));
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool sfSocketSelector_removeTcpListener(sfSocketSelector* selector, sfTcpListener* socket)
|
||||
{
|
||||
assert(selector);
|
||||
assert(socket);
|
||||
return selector->remove(*socket);
|
||||
}
|
||||
bool sfSocketSelector_removeTcpSocket(sfSocketSelector* selector, sfTcpSocket* socket)
|
||||
{
|
||||
assert(selector);
|
||||
assert(socket);
|
||||
return selector->remove(*socket);
|
||||
}
|
||||
bool sfSocketSelector_removeUdpSocket(sfSocketSelector* selector, sfUdpSocket* socket)
|
||||
{
|
||||
assert(selector);
|
||||
assert(socket);
|
||||
return selector->remove(*socket);
|
||||
}
|
||||
|
||||
|
||||
@@ -131,3 +189,38 @@ bool sfSocketSelector_isUdpSocketReady(const sfSocketSelector* selector, sfUdpSo
|
||||
assert(socket);
|
||||
return selector->isReady(*socket);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool sfSocketSelector_isTcpListenerReadyFor(const sfSocketSelector* selector, sfTcpListener* socket, uint32_t readiness)
|
||||
{
|
||||
assert(selector);
|
||||
assert(socket);
|
||||
return selector->isReady(*socket, readiness);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool sfSocketSelector_isTcpSocketReadyFor(const sfSocketSelector* selector, sfTcpSocket* socket, uint32_t readiness)
|
||||
{
|
||||
assert(selector);
|
||||
assert(socket);
|
||||
return selector->isReady(*socket, readiness);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool sfSocketSelector_isUdpSocketReadyFor(const sfSocketSelector* selector, sfUdpSocket* socket, uint32_t readiness)
|
||||
{
|
||||
assert(selector);
|
||||
assert(socket);
|
||||
return selector->isReady(*socket, readiness);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfSocketSelector_dispatchReadyCallbacks(sfSocketSelector* selector)
|
||||
{
|
||||
assert(selector);
|
||||
selector->dispatchReadyCallbacks();
|
||||
}
|
||||
@@ -25,6 +25,7 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <CSFML/Network/ConvertIpAddress.hpp>
|
||||
#include <CSFML/Network/TcpListener.h>
|
||||
#include <CSFML/Network/TcpListenerStruct.hpp>
|
||||
#include <CSFML/Network/TcpSocketStruct.hpp>
|
||||
@@ -75,7 +76,7 @@ sfSocketStatus sfTcpListener_listen(sfTcpListener* listener, unsigned short port
|
||||
{
|
||||
assert(listener);
|
||||
|
||||
std::optional<sf::IpAddress> sfmlAddress = sf::IpAddress::resolve(address.address);
|
||||
std::optional<sf::IpAddress> sfmlAddress = convertIpAddress(address);
|
||||
|
||||
if (!sfmlAddress)
|
||||
{
|
||||
|
||||
@@ -25,12 +25,15 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <CSFML/Network/ConvertIpAddress.hpp>
|
||||
#include <CSFML/Network/PacketStruct.hpp>
|
||||
#include <CSFML/Network/TcpSocket.h>
|
||||
#include <CSFML/Network/TcpSocketStruct.hpp>
|
||||
|
||||
#include <SFML/Network/IpAddress.hpp>
|
||||
#include <SFML/System/String.hpp>
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstring>
|
||||
|
||||
|
||||
@@ -82,7 +85,7 @@ sfIpAddress sfTcpSocket_getRemoteAddress(const sfTcpSocket* socket)
|
||||
sfIpAddress result = sfIpAddress_None;
|
||||
if (address)
|
||||
{
|
||||
std::strncpy(result.address, address->toString().c_str(), 15);
|
||||
result = convertIpAddress(*address);
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -100,7 +103,7 @@ unsigned short sfTcpSocket_getRemotePort(const sfTcpSocket* socket)
|
||||
////////////////////////////////////////////////////////////
|
||||
sfSocketStatus sfTcpSocket_connect(sfTcpSocket* socket, sfIpAddress remoteAddress, unsigned short remotePort, sfTime timeout)
|
||||
{
|
||||
std::optional<sf::IpAddress> address = sf::IpAddress::resolve(remoteAddress.address);
|
||||
std::optional<sf::IpAddress> address = convertIpAddress(remoteAddress);
|
||||
|
||||
if (!address)
|
||||
{
|
||||
@@ -169,3 +172,73 @@ sfSocketStatus sfTcpSocket_receivePacket(sfTcpSocket* socket, sfPacket* packet)
|
||||
assert(packet);
|
||||
return static_cast<sfSocketStatus>(socket->receive(*packet));
|
||||
}
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
[[nodiscard]] sf::String fromUtf8(const char* string)
|
||||
{
|
||||
return sf::String::fromUtf8(string, string + std::strlen(string));
|
||||
}
|
||||
} // namespace
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
sfTlsStatus sfTcpSocket_setupTlsClient(sfTcpSocket* socket, const char* hostname, bool verifyPeer)
|
||||
{
|
||||
assert(socket);
|
||||
assert(hostname);
|
||||
return static_cast<sfTlsStatus>(socket->setupTlsClient(fromUtf8(hostname), verifyPeer));
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
sfTlsStatus sfTcpSocket_setupTlsClientWithCertificate(sfTcpSocket* socket,
|
||||
const char* hostname,
|
||||
const void* certificateChainData,
|
||||
size_t certificateChainSize)
|
||||
{
|
||||
assert(socket);
|
||||
assert(hostname);
|
||||
assert(certificateChainData);
|
||||
return static_cast<sfTlsStatus>(
|
||||
socket->setupTlsClient(fromUtf8(hostname), static_cast<const std::byte*>(certificateChainData), certificateChainSize));
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
sfTlsStatus sfTcpSocket_setupTlsServer(
|
||||
sfTcpSocket* socket,
|
||||
const void* certificateChainData,
|
||||
size_t certificateChainSize,
|
||||
const void* privateKeyData,
|
||||
size_t privateKeySize,
|
||||
const void* privateKeyPasswordData,
|
||||
size_t privateKeyPasswordSize)
|
||||
{
|
||||
assert(socket);
|
||||
assert(certificateChainData);
|
||||
assert(privateKeyData);
|
||||
return static_cast<sfTlsStatus>(
|
||||
socket->setupTlsServer(static_cast<const std::byte*>(certificateChainData),
|
||||
certificateChainSize,
|
||||
static_cast<const std::byte*>(privateKeyData),
|
||||
privateKeySize,
|
||||
static_cast<const std::byte*>(privateKeyPasswordData),
|
||||
privateKeyPasswordData ? privateKeyPasswordSize : 0));
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
const char* sfTcpSocket_getCurrentCiphersuiteName(const sfTcpSocket* socket)
|
||||
{
|
||||
assert(socket);
|
||||
|
||||
const auto name = socket->getCurrentCiphersuiteName();
|
||||
if (!name)
|
||||
return nullptr;
|
||||
|
||||
socket->CiphersuiteName = *name;
|
||||
return socket->CiphersuiteName.c_str();
|
||||
}
|
||||
@@ -29,10 +29,13 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Network/TcpSocket.hpp>
|
||||
|
||||
#include <string>
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Internal structure of sfTcpSocket
|
||||
////////////////////////////////////////////////////////////
|
||||
struct sfTcpSocket : sf::TcpSocket
|
||||
{
|
||||
mutable std::string CiphersuiteName;
|
||||
};
|
||||
@@ -25,6 +25,7 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <CSFML/Network/ConvertIpAddress.hpp>
|
||||
#include <CSFML/Network/PacketStruct.hpp>
|
||||
#include <CSFML/Network/UdpSocket.h>
|
||||
#include <CSFML/Network/UdpSocketStruct.hpp>
|
||||
@@ -76,7 +77,7 @@ sfSocketStatus sfUdpSocket_bind(sfUdpSocket* socket, unsigned short port, sfIpAd
|
||||
{
|
||||
assert(socket);
|
||||
|
||||
std::optional<sf::IpAddress> sfmlAddress = sf::IpAddress::resolve(address.address);
|
||||
std::optional<sf::IpAddress> sfmlAddress = convertIpAddress(address);
|
||||
|
||||
if (!sfmlAddress)
|
||||
{
|
||||
@@ -101,7 +102,7 @@ sfSocketStatus sfUdpSocket_send(sfUdpSocket* socket, const void* data, size_t si
|
||||
assert(socket);
|
||||
|
||||
// Convert the address
|
||||
std::optional<sf::IpAddress> address = sf::IpAddress::resolve(remoteAddress.address);
|
||||
std::optional<sf::IpAddress> address = convertIpAddress(remoteAddress);
|
||||
|
||||
if (!address)
|
||||
{
|
||||
@@ -139,7 +140,7 @@ sfSocketStatus sfUdpSocket_receive(sfUdpSocket* socket,
|
||||
|
||||
if (address)
|
||||
{
|
||||
std::strncpy(remoteAddress->address, address->toString().c_str(), 15);
|
||||
*remoteAddress = convertIpAddress(*address);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -157,7 +158,7 @@ sfSocketStatus sfUdpSocket_sendPacket(sfUdpSocket* socket, sfPacket* packet, sfI
|
||||
assert(packet);
|
||||
|
||||
// Convert the address
|
||||
std::optional<sf::IpAddress> address = sf::IpAddress::resolve(remoteAddress.address);
|
||||
std::optional<sf::IpAddress> address = convertIpAddress(remoteAddress);
|
||||
|
||||
if (!address)
|
||||
{
|
||||
@@ -187,7 +188,7 @@ sfSocketStatus sfUdpSocket_receivePacket(sfUdpSocket* socket, sfPacket* packet,
|
||||
|
||||
if (address)
|
||||
{
|
||||
std::strncpy(remoteAddress->address, address->toString().c_str(), 15);
|
||||
*remoteAddress = convertIpAddress(*address);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,9 +20,13 @@ set(SRC
|
||||
${INCROOT}/Sleep.h
|
||||
${SRCROOT}/Time.cpp
|
||||
${INCROOT}/Time.h
|
||||
${SRCROOT}/ConvertTimeoutWithPredicate.hpp
|
||||
${INCROOT}/TimeoutWithPredicate.h
|
||||
${INCROOT}/Types.h
|
||||
${INCROOT}/Vector2.h
|
||||
${INCROOT}/Vector3.h
|
||||
${SRCROOT}/Version.cpp
|
||||
${INCROOT}/Version.h
|
||||
)
|
||||
|
||||
# define the csfml-system target
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2026 Laurent Gomila (laurent@sfml-dev.org)
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <CSFML/System/TimeoutWithPredicate.h>
|
||||
|
||||
#include <SFML/System/TimeoutWithPredicate.hpp>
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Convert sfTimeoutWithPredicate to sf::TimeoutWithPredicate
|
||||
////////////////////////////////////////////////////////////
|
||||
[[nodiscard]] inline sf::TimeoutWithPredicate convertTimeoutWithPredicate(const sfTimeoutWithPredicate& timeout)
|
||||
{
|
||||
if (!timeout.predicate)
|
||||
return {sf::microseconds(timeout.timeout.microseconds)};
|
||||
|
||||
const auto period = timeout.period.microseconds > 0 ? sf::microseconds(timeout.period.microseconds)
|
||||
: sf::milliseconds(1);
|
||||
return {[predicate = timeout.predicate, userData = timeout.userData] { return predicate(userData); }, period};
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2026 Laurent Gomila (laurent@sfml-dev.org)
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <CSFML/System/Version.h>
|
||||
|
||||
#include <SFML/System/Version.hpp>
|
||||
|
||||
#include <string>
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
sfVersion sfGetVersion()
|
||||
{
|
||||
const auto& version = sf::version();
|
||||
static const std::string string(version.string);
|
||||
return {version.major, version.minor, version.patch, version.isRelease, string.c_str()};
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
#include <CSFML/Audio/PlaybackDevice.h>
|
||||
|
||||
#include <SFML/Audio/PlaybackDevice.hpp>
|
||||
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
TEST_CASE("[Audio] sfPlaybackDevice")
|
||||
{
|
||||
SECTION("sfPlaybackDeviceNotification")
|
||||
{
|
||||
STATIC_CHECK(sfPlaybackDeviceStarted == static_cast<int>(sf::PlaybackDevice::Notification::DeviceStarted));
|
||||
STATIC_CHECK(sfPlaybackDeviceStopped == static_cast<int>(sf::PlaybackDevice::Notification::DeviceStopped));
|
||||
STATIC_CHECK(sfPlaybackDeviceRerouted == static_cast<int>(sf::PlaybackDevice::Notification::DeviceRerouted));
|
||||
STATIC_CHECK(sfPlaybackDeviceInterruptionBegan ==
|
||||
static_cast<int>(sf::PlaybackDevice::Notification::DeviceInterruptionBegan));
|
||||
STATIC_CHECK(sfPlaybackDeviceInterruptionEnded ==
|
||||
static_cast<int>(sf::PlaybackDevice::Notification::DeviceInterruptionEnded));
|
||||
STATIC_CHECK(sfPlaybackDeviceUnlocked == static_cast<int>(sf::PlaybackDevice::Notification::DeviceUnlocked));
|
||||
}
|
||||
|
||||
SECTION("sfPlaybackDevice_setNotificationCallback")
|
||||
{
|
||||
sfPlaybackDevice_setNotificationCallback([](sfPlaybackDeviceNotification, void*) {}, nullptr);
|
||||
sfPlaybackDevice_setNotificationCallback(nullptr, nullptr);
|
||||
}
|
||||
}
|
||||
+9
-1
@@ -27,6 +27,7 @@ add_executable(test-csfml-system
|
||||
System/Time.test.cpp
|
||||
System/Vector2.test.cpp
|
||||
System/Vector3.test.cpp
|
||||
System/Version.test.cpp
|
||||
)
|
||||
target_link_libraries(test-csfml-system PRIVATE csfml-system Catch2::Catch2WithMain)
|
||||
set_target_warnings(test-csfml-system)
|
||||
@@ -48,12 +49,14 @@ add_executable(test-csfml-graphics
|
||||
Graphics/BlendMode.test.cpp
|
||||
Graphics/Color.test.cpp
|
||||
Graphics/CoordinateType.test.cpp
|
||||
Graphics/Font.test.cpp
|
||||
Graphics/Image.test.cpp
|
||||
Graphics/PrimitiveType.test.cpp
|
||||
Graphics/Rect.test.cpp
|
||||
Graphics/RenderStates.test.cpp
|
||||
Graphics/Shape.test.cpp
|
||||
Graphics/StencilMode.test.cpp
|
||||
Graphics/Text.test.cpp
|
||||
Graphics/Transform.test.cpp
|
||||
Graphics/VertexArray.test.cpp
|
||||
Graphics/View.test.cpp
|
||||
@@ -63,16 +66,21 @@ set_target_warnings(test-csfml-graphics)
|
||||
catch_discover_tests(test-csfml-graphics WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
||||
add_executable(test-csfml-network
|
||||
Network/Dns.test.cpp
|
||||
Network/Ftp.test.cpp
|
||||
Network/Http.test.cpp
|
||||
Network/IpAddress.test.cpp
|
||||
Network/Sftp.test.cpp
|
||||
Network/SocketSelector.test.cpp
|
||||
Network/SocketStatus.test.cpp
|
||||
Network/TcpSocket.test.cpp
|
||||
)
|
||||
target_link_libraries(test-csfml-network PRIVATE csfml-network Catch2::Catch2WithMain SFML::Network)
|
||||
target_link_libraries(test-csfml-network PRIVATE csfml-network csfml-system Catch2::Catch2WithMain SFML::Network)
|
||||
set_target_warnings(test-csfml-network)
|
||||
catch_discover_tests(test-csfml-network)
|
||||
|
||||
add_executable(test-csfml-audio
|
||||
Audio/PlaybackDevice.test.cpp
|
||||
Audio/SoundChannel.test.cpp
|
||||
)
|
||||
target_link_libraries(test-csfml-audio PRIVATE csfml-audio Catch2::Catch2WithMain SFML::Audio)
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
#include <CSFML/Graphics/Font.h>
|
||||
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include <string>
|
||||
|
||||
TEST_CASE("[Graphics] sfFont")
|
||||
{
|
||||
SECTION("sfFont_createFromFile")
|
||||
{
|
||||
CHECK(sfFont_createFromFile("does/not/exist.ttf") == nullptr);
|
||||
|
||||
sfFont* font = sfFont_createFromFile("Graphics/tuffy.ttf");
|
||||
REQUIRE(font != nullptr);
|
||||
|
||||
const sfFontInfo info = sfFont_getInfo(font);
|
||||
CHECK(info.id != 0);
|
||||
CHECK(std::string(info.family) == "Tuffy");
|
||||
CHECK(!info.hasVerticalMetrics);
|
||||
|
||||
CHECK(sfFont_getAscent(font, 10) > 0);
|
||||
CHECK(sfFont_getDescent(font, 10) < 0);
|
||||
CHECK(sfFont_getAscent(font, 20) > sfFont_getAscent(font, 10));
|
||||
|
||||
sfFont_destroy(font);
|
||||
}
|
||||
}
|
||||
@@ -47,6 +47,7 @@ TEST_CASE("[Graphics] sfShape")
|
||||
CHECK(outlineColor.b == sfWhite.b);
|
||||
CHECK(outlineColor.a == sfWhite.a);
|
||||
CHECK(sfShape_getOutlineThickness(shape) == 0);
|
||||
CHECK(sfShape_getMiterLimit(shape) == 10);
|
||||
CHECK(sfShape_getPointCount(shape) == 3);
|
||||
const sfVector2f point = sfShape_getPoint(shape, 0);
|
||||
CHECK(point.x == 0);
|
||||
@@ -104,4 +105,12 @@ TEST_CASE("[Graphics] sfShape")
|
||||
CHECK(origin.y == 90);
|
||||
sfShape_destroy(shape);
|
||||
}
|
||||
|
||||
SECTION("Set/get miter limit")
|
||||
{
|
||||
sfShape* shape = sfShape_create(getPointCount, getPoint, &points);
|
||||
sfShape_setMiterLimit(shape, 2);
|
||||
CHECK(sfShape_getMiterLimit(shape) == 2);
|
||||
sfShape_destroy(shape);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
#include <CSFML/Graphics/Font.h>
|
||||
#include <CSFML/Graphics/Text.h>
|
||||
|
||||
#include <SFML/Graphics/Text.hpp>
|
||||
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
TEST_CASE("[Graphics] sfText")
|
||||
{
|
||||
SECTION("sfTextLineAlignment")
|
||||
{
|
||||
STATIC_CHECK(sfTextLineAlignmentDefault == static_cast<int>(sf::Text::LineAlignment::Default));
|
||||
STATIC_CHECK(sfTextLineAlignmentLeft == static_cast<int>(sf::Text::LineAlignment::Left));
|
||||
STATIC_CHECK(sfTextLineAlignmentCenter == static_cast<int>(sf::Text::LineAlignment::Center));
|
||||
STATIC_CHECK(sfTextLineAlignmentRight == static_cast<int>(sf::Text::LineAlignment::Right));
|
||||
}
|
||||
|
||||
SECTION("sfTextClusterGrouping")
|
||||
{
|
||||
STATIC_CHECK(sfTextClusterGroupingGrapheme == static_cast<int>(sf::Text::ClusterGrouping::Grapheme));
|
||||
STATIC_CHECK(sfTextClusterGroupingCharacter == static_cast<int>(sf::Text::ClusterGrouping::Character));
|
||||
STATIC_CHECK(sfTextClusterGroupingNone == static_cast<int>(sf::Text::ClusterGrouping::None));
|
||||
}
|
||||
|
||||
SECTION("sfTextDirection")
|
||||
{
|
||||
STATIC_CHECK(sfTextDirectionUnspecified == static_cast<int>(sf::Text::TextDirection::Unspecified));
|
||||
STATIC_CHECK(sfTextDirectionLeftToRight == static_cast<int>(sf::Text::TextDirection::LeftToRight));
|
||||
STATIC_CHECK(sfTextDirectionRightToLeft == static_cast<int>(sf::Text::TextDirection::RightToLeft));
|
||||
STATIC_CHECK(sfTextDirectionTopToBottom == static_cast<int>(sf::Text::TextDirection::TopToBottom));
|
||||
STATIC_CHECK(sfTextDirectionBottomToTop == static_cast<int>(sf::Text::TextDirection::BottomToTop));
|
||||
}
|
||||
|
||||
SECTION("sfTextOrientation")
|
||||
{
|
||||
STATIC_CHECK(sfTextOrientationDefault == static_cast<int>(sf::Text::TextOrientation::Default));
|
||||
STATIC_CHECK(sfTextOrientationTopToBottom == static_cast<int>(sf::Text::TextOrientation::TopToBottom));
|
||||
STATIC_CHECK(sfTextOrientationBottomToTop == static_cast<int>(sf::Text::TextOrientation::BottomToTop));
|
||||
}
|
||||
|
||||
SECTION("Set/get layout properties")
|
||||
{
|
||||
sfFont* font = sfFont_createFromFile("Graphics/tuffy.ttf");
|
||||
REQUIRE(font != nullptr);
|
||||
sfText* text = sfText_create(font);
|
||||
|
||||
CHECK(sfText_getLineAlignment(text) == sfTextLineAlignmentDefault);
|
||||
CHECK(sfText_getTextOrientation(text) == sfTextOrientationDefault);
|
||||
CHECK(sfText_getClusterGrouping(text) == sfTextClusterGroupingCharacter);
|
||||
|
||||
sfText_setLineAlignment(text, sfTextLineAlignmentCenter);
|
||||
sfText_setTextOrientation(text, sfTextOrientationTopToBottom);
|
||||
sfText_setClusterGrouping(text, sfTextClusterGroupingGrapheme);
|
||||
|
||||
CHECK(sfText_getLineAlignment(text) == sfTextLineAlignmentCenter);
|
||||
CHECK(sfText_getTextOrientation(text) == sfTextOrientationTopToBottom);
|
||||
CHECK(sfText_getClusterGrouping(text) == sfTextClusterGroupingGrapheme);
|
||||
|
||||
sfText* copy = sfText_copy(text);
|
||||
CHECK(sfText_getLineAlignment(copy) == sfTextLineAlignmentCenter);
|
||||
sfText_destroy(copy);
|
||||
|
||||
sfText_destroy(text);
|
||||
sfFont_destroy(font);
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,25 @@
|
||||
#include <CSFML/Network/Dns.h>
|
||||
#include <CSFML/System/Alloc.h>
|
||||
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include <cstring>
|
||||
|
||||
TEST_CASE("[Network] sfDns")
|
||||
{
|
||||
SECTION("sfDns_resolve")
|
||||
{
|
||||
size_t count = 0;
|
||||
sfIpAddress* addresses = sfDns_resolve("127.0.0.1", nullptr, 0, sfSeconds(1), &count);
|
||||
REQUIRE(addresses != nullptr);
|
||||
REQUIRE(count == 1);
|
||||
CHECK(std::strcmp(addresses[0].address, "127.0.0.1") == 0);
|
||||
sfFree(addresses);
|
||||
|
||||
addresses = sfDns_resolve("::1", nullptr, 0, sfSeconds(1), &count);
|
||||
REQUIRE(addresses != nullptr);
|
||||
REQUIRE(count == 1);
|
||||
CHECK(std::strcmp(addresses[0].address, "::1") == 0);
|
||||
sfFree(addresses);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
#include <CSFML/Network/IpAddress.h>
|
||||
|
||||
#include <SFML/Network/IpAddress.hpp>
|
||||
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include <cstring>
|
||||
@@ -17,15 +19,62 @@ TEST_CASE("[Network] sfIpAddress")
|
||||
CHECK(std::strcmp(sfIpAddress_Any.address, "0.0.0.0") == 0);
|
||||
CHECK(std::strcmp(sfIpAddress_LocalHost.address, "127.0.0.1") == 0);
|
||||
CHECK(std::strcmp(sfIpAddress_Broadcast.address, "255.255.255.255") == 0);
|
||||
|
||||
CHECK(std::strcmp(sfIpAddress_AnyV4.address, "0.0.0.0") == 0);
|
||||
CHECK(std::strcmp(sfIpAddress_LocalHostV4.address, "127.0.0.1") == 0);
|
||||
CHECK(std::strcmp(sfIpAddress_BroadcastV4.address, "255.255.255.255") == 0);
|
||||
CHECK(std::strcmp(sfIpAddress_AnyV6.address, "::") == 0);
|
||||
CHECK(std::strcmp(sfIpAddress_LocalHostV6.address, "::1") == 0);
|
||||
}
|
||||
|
||||
SECTION("sfIpAddressType")
|
||||
{
|
||||
STATIC_CHECK(sfIpAddressV4 == static_cast<int>(sf::IpAddress::Type::IpV4));
|
||||
STATIC_CHECK(sfIpAddressV6 == static_cast<int>(sf::IpAddress::Type::IpV6));
|
||||
}
|
||||
|
||||
SECTION("sfIpAddress_fromString")
|
||||
{
|
||||
CHECK(sfIpAddress_toInteger(sfIpAddress_fromString("")) == 0);
|
||||
CHECK(sfIpAddress_toInteger(sfIpAddress_fromString("256.256.256.256")) == 0);
|
||||
CHECK(sfIpAddress_toInteger(sfIpAddress_fromString("localhost")) == 0x7F000001);
|
||||
CHECK(sfIpAddress_toInteger(sfIpAddress_fromString("localhost")) == 0);
|
||||
CHECK(sfIpAddress_toInteger(sfIpAddress_fromString("192.168.0.1")) == 0xC0A80001);
|
||||
CHECK(sfIpAddress_toInteger(sfIpAddress_fromString("8.8.8.8")) == 0x08080808);
|
||||
CHECK(std::strcmp(sfIpAddress_fromString("2606:4700:4700::1111").address, "2606:4700:4700::1111") == 0);
|
||||
CHECK(std::strcmp(sfIpAddress_fromString("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff").address,
|
||||
"ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff") == 0);
|
||||
}
|
||||
|
||||
SECTION("sfIpAddress_resolve")
|
||||
{
|
||||
CHECK(sfIpAddress_toInteger(sfIpAddress_resolve("")) == 0);
|
||||
CHECK(sfIpAddress_toInteger(sfIpAddress_resolve("localhost")) == 0x7F000001);
|
||||
CHECK(sfIpAddress_toInteger(sfIpAddress_resolve("192.168.0.1")) == 0xC0A80001);
|
||||
}
|
||||
|
||||
SECTION("Type")
|
||||
{
|
||||
CHECK(sfIpAddress_isV4(sfIpAddress_LocalHostV4));
|
||||
CHECK(!sfIpAddress_isV6(sfIpAddress_LocalHostV4));
|
||||
CHECK(sfIpAddress_getType(sfIpAddress_LocalHostV4) == sfIpAddressV4);
|
||||
CHECK(!sfIpAddress_isV4(sfIpAddress_LocalHostV6));
|
||||
CHECK(sfIpAddress_isV6(sfIpAddress_LocalHostV6));
|
||||
CHECK(sfIpAddress_getType(sfIpAddress_LocalHostV6) == sfIpAddressV6);
|
||||
CHECK(!sfIpAddress_isV4(sfIpAddress_None));
|
||||
CHECK(!sfIpAddress_isV6(sfIpAddress_None));
|
||||
}
|
||||
|
||||
SECTION("sfIpAddress_fromV6Bytes")
|
||||
{
|
||||
const uint8_t bytes[16] = {0x26, 0x06, 0x47, 0x00, 0x47, 0x00, 0, 0, 0, 0, 0, 0, 0, 0, 0x11, 0x11};
|
||||
const sfIpAddress address = sfIpAddress_fromV6Bytes(bytes);
|
||||
CHECK(std::strcmp(address.address, "2606:4700:4700::1111") == 0);
|
||||
CHECK(sfIpAddress_toInteger(address) == 0);
|
||||
|
||||
uint8_t result[16] = {};
|
||||
CHECK(sfIpAddress_toV6Bytes(address, result));
|
||||
CHECK(std::memcmp(bytes, result, sizeof(bytes)) == 0);
|
||||
CHECK(!sfIpAddress_toV6Bytes(sfIpAddress_LocalHostV4, result));
|
||||
}
|
||||
|
||||
SECTION("sfIpAddress_fromBytes")
|
||||
|
||||
@@ -0,0 +1,106 @@
|
||||
#include <CSFML/Network/Sftp.h>
|
||||
|
||||
#include <SFML/Network/Sftp.hpp>
|
||||
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
TEST_CASE("[Network] sfSftp")
|
||||
{
|
||||
SECTION("sfSftpResultValue")
|
||||
{
|
||||
STATIC_CHECK(sfSftpSuccess == static_cast<int>(sf::Sftp::Result::Value::Success));
|
||||
STATIC_CHECK(sfSftpDisconnected == static_cast<int>(sf::Sftp::Result::Value::Disconnected));
|
||||
STATIC_CHECK(sfSftpTimeout == static_cast<int>(sf::Sftp::Result::Value::Timeout));
|
||||
STATIC_CHECK(sfSftpRefused == static_cast<int>(sf::Sftp::Result::Value::Refused));
|
||||
STATIC_CHECK(sfSftpError == static_cast<int>(sf::Sftp::Result::Value::Error));
|
||||
STATIC_CHECK(sfSftpBannerReceive == static_cast<int>(sf::Sftp::Result::Value::BannerReceive));
|
||||
STATIC_CHECK(sfSftpBannerSend == static_cast<int>(sf::Sftp::Result::Value::BannerSend));
|
||||
STATIC_CHECK(sfSftpInvalidMac == static_cast<int>(sf::Sftp::Result::Value::InvalidMac));
|
||||
STATIC_CHECK(sfSftpAllocationFailure == static_cast<int>(sf::Sftp::Result::Value::AllocationFailure));
|
||||
STATIC_CHECK(sfSftpSocketSend == static_cast<int>(sf::Sftp::Result::Value::SocketSend));
|
||||
STATIC_CHECK(sfSftpKeyExchangeFailure == static_cast<int>(sf::Sftp::Result::Value::KeyExchangeFailure));
|
||||
STATIC_CHECK(sfSftpHostKeyInitialization == static_cast<int>(sf::Sftp::Result::Value::HostKeyInitialization));
|
||||
STATIC_CHECK(sfSftpHostKeySign == static_cast<int>(sf::Sftp::Result::Value::HostKeySign));
|
||||
STATIC_CHECK(sfSftpDecryptError == static_cast<int>(sf::Sftp::Result::Value::DecryptError));
|
||||
STATIC_CHECK(sfSftpProtocolError == static_cast<int>(sf::Sftp::Result::Value::ProtocolError));
|
||||
STATIC_CHECK(sfSftpPasswordExpired == static_cast<int>(sf::Sftp::Result::Value::PasswordExpired));
|
||||
STATIC_CHECK(sfSftpFileError == static_cast<int>(sf::Sftp::Result::Value::FileError));
|
||||
STATIC_CHECK(sfSftpMethodNone == static_cast<int>(sf::Sftp::Result::Value::MethodNone));
|
||||
STATIC_CHECK(sfSftpAuthenticationFailed == static_cast<int>(sf::Sftp::Result::Value::AuthenticationFailed));
|
||||
STATIC_CHECK(sfSftpPublicKeyUnverified == static_cast<int>(sf::Sftp::Result::Value::PublicKeyUnverified));
|
||||
STATIC_CHECK(sfSftpChannelOutOfOrder == static_cast<int>(sf::Sftp::Result::Value::ChannelOutOfOrder));
|
||||
STATIC_CHECK(sfSftpChannelFailure == static_cast<int>(sf::Sftp::Result::Value::ChannelFailure));
|
||||
STATIC_CHECK(sfSftpChannelRequestDenied == static_cast<int>(sf::Sftp::Result::Value::ChannelRequestDenied));
|
||||
STATIC_CHECK(sfSftpChannelUnknown == static_cast<int>(sf::Sftp::Result::Value::ChannelUnknown));
|
||||
STATIC_CHECK(sfSftpChannelWindowExceeded == static_cast<int>(sf::Sftp::Result::Value::ChannelWindowExceeded));
|
||||
STATIC_CHECK(sfSftpChannelPacketExceeded == static_cast<int>(sf::Sftp::Result::Value::ChannelPacketExceeded));
|
||||
STATIC_CHECK(sfSftpChannelClosed == static_cast<int>(sf::Sftp::Result::Value::ChannelClosed));
|
||||
STATIC_CHECK(sfSftpChannelEofSent == static_cast<int>(sf::Sftp::Result::Value::ChannelEofSent));
|
||||
STATIC_CHECK(sfSftpScpProtocol == static_cast<int>(sf::Sftp::Result::Value::ScpProtocol));
|
||||
STATIC_CHECK(sfSftpZlibError == static_cast<int>(sf::Sftp::Result::Value::ZlibError));
|
||||
STATIC_CHECK(sfSftpRequestDenied == static_cast<int>(sf::Sftp::Result::Value::RequestDenied));
|
||||
STATIC_CHECK(sfSftpMethodNotSupported == static_cast<int>(sf::Sftp::Result::Value::MethodNotSupported));
|
||||
STATIC_CHECK(sfSftpInvalidData == static_cast<int>(sf::Sftp::Result::Value::InvalidData));
|
||||
STATIC_CHECK(sfSftpPublicKeyProtocol == static_cast<int>(sf::Sftp::Result::Value::PublicKeyProtocol));
|
||||
STATIC_CHECK(sfSftpBufferTooSmall == static_cast<int>(sf::Sftp::Result::Value::BufferTooSmall));
|
||||
STATIC_CHECK(sfSftpBadUse == static_cast<int>(sf::Sftp::Result::Value::BadUse));
|
||||
STATIC_CHECK(sfSftpCompressError == static_cast<int>(sf::Sftp::Result::Value::CompressError));
|
||||
STATIC_CHECK(sfSftpOutOfBoundary == static_cast<int>(sf::Sftp::Result::Value::OutOfBoundary));
|
||||
STATIC_CHECK(sfSftpAgentProtocol == static_cast<int>(sf::Sftp::Result::Value::AgentProtocol));
|
||||
STATIC_CHECK(sfSftpSocketRecv == static_cast<int>(sf::Sftp::Result::Value::SocketRecv));
|
||||
STATIC_CHECK(sfSftpEncryptError == static_cast<int>(sf::Sftp::Result::Value::EncryptError));
|
||||
STATIC_CHECK(sfSftpBadSocket == static_cast<int>(sf::Sftp::Result::Value::BadSocket));
|
||||
STATIC_CHECK(sfSftpKnownHosts == static_cast<int>(sf::Sftp::Result::Value::KnownHosts));
|
||||
STATIC_CHECK(sfSftpChannelWindowFull == static_cast<int>(sf::Sftp::Result::Value::ChannelWindowFull));
|
||||
STATIC_CHECK(sfSftpKeyFileAuthenticationFailed ==
|
||||
static_cast<int>(sf::Sftp::Result::Value::KeyFileAuthenticationFailed));
|
||||
STATIC_CHECK(sfSftpEndOfFile == static_cast<int>(sf::Sftp::Result::Value::EndOfFile));
|
||||
STATIC_CHECK(sfSftpNoSuchFile == static_cast<int>(sf::Sftp::Result::Value::NoSuchFile));
|
||||
STATIC_CHECK(sfSftpPermissionDenied == static_cast<int>(sf::Sftp::Result::Value::PermissionDenied));
|
||||
STATIC_CHECK(sfSftpFailure == static_cast<int>(sf::Sftp::Result::Value::Failure));
|
||||
STATIC_CHECK(sfSftpBadMessage == static_cast<int>(sf::Sftp::Result::Value::BadMessage));
|
||||
STATIC_CHECK(sfSftpNoConnection == static_cast<int>(sf::Sftp::Result::Value::NoConnection));
|
||||
STATIC_CHECK(sfSftpConnectionLost == static_cast<int>(sf::Sftp::Result::Value::ConnectionLost));
|
||||
STATIC_CHECK(sfSftpOperationUnsupported == static_cast<int>(sf::Sftp::Result::Value::OperationUnsupported));
|
||||
STATIC_CHECK(sfSftpInvalidHandle == static_cast<int>(sf::Sftp::Result::Value::InvalidHandle));
|
||||
STATIC_CHECK(sfSftpNoSuchPath == static_cast<int>(sf::Sftp::Result::Value::NoSuchPath));
|
||||
STATIC_CHECK(sfSftpFileAlreadyExists == static_cast<int>(sf::Sftp::Result::Value::FileAlreadyExists));
|
||||
STATIC_CHECK(sfSftpWriteProtect == static_cast<int>(sf::Sftp::Result::Value::WriteProtect));
|
||||
STATIC_CHECK(sfSftpNoMedia == static_cast<int>(sf::Sftp::Result::Value::NoMedia));
|
||||
STATIC_CHECK(sfSftpNoSpaceOnFileSystem == static_cast<int>(sf::Sftp::Result::Value::NoSpaceOnFileSystem));
|
||||
STATIC_CHECK(sfSftpQuotaExceeded == static_cast<int>(sf::Sftp::Result::Value::QuotaExceeded));
|
||||
STATIC_CHECK(sfSftpUnknownPrincipal == static_cast<int>(sf::Sftp::Result::Value::UnknownPrincipal));
|
||||
STATIC_CHECK(sfSftpLockConflict == static_cast<int>(sf::Sftp::Result::Value::LockConflict));
|
||||
STATIC_CHECK(sfSftpDirectoryNotEmpty == static_cast<int>(sf::Sftp::Result::Value::DirectoryNotEmpty));
|
||||
STATIC_CHECK(sfSftpNotADirectory == static_cast<int>(sf::Sftp::Result::Value::NotADirectory));
|
||||
STATIC_CHECK(sfSftpInvalidFilename == static_cast<int>(sf::Sftp::Result::Value::InvalidFilename));
|
||||
STATIC_CHECK(sfSftpLinkLoop == static_cast<int>(sf::Sftp::Result::Value::LinkLoop));
|
||||
STATIC_CHECK(sfSftpSftpError == static_cast<int>(sf::Sftp::Result::Value::SftpError));
|
||||
}
|
||||
|
||||
SECTION("sfSftpHostKeyType")
|
||||
{
|
||||
using HostKeyType = sf::Sftp::SessionInfo::HostKey::Type;
|
||||
STATIC_CHECK(sfSftpHostKeyUnknown == static_cast<int>(HostKeyType::Unknown));
|
||||
STATIC_CHECK(sfSftpHostKeyRsa == static_cast<int>(HostKeyType::Rsa));
|
||||
STATIC_CHECK(sfSftpHostKeyDsa == static_cast<int>(HostKeyType::Dsa));
|
||||
STATIC_CHECK(sfSftpHostKeyEcdsa256 == static_cast<int>(HostKeyType::Ecdsa256));
|
||||
STATIC_CHECK(sfSftpHostKeyEcdsa384 == static_cast<int>(HostKeyType::Ecdsa384));
|
||||
STATIC_CHECK(sfSftpHostKeyEcdsa521 == static_cast<int>(HostKeyType::Ecdsa521));
|
||||
STATIC_CHECK(sfSftpHostKeyEd25519 == static_cast<int>(HostKeyType::Ed25519));
|
||||
}
|
||||
|
||||
SECTION("Unconnected")
|
||||
{
|
||||
sfSftp* sftp = sfSftp_create();
|
||||
sfSftpSessionInfo info{};
|
||||
CHECK(!sfSftp_getSessionInfo(sftp, &info));
|
||||
|
||||
sfSftpResult* result = sfSftp_connect(sftp, sfIpAddress_None, 22, {});
|
||||
CHECK(!sfSftpResult_isOk(result));
|
||||
CHECK(sfSftpResult_getValue(result) == sfSftpError);
|
||||
sfSftpResult_destroy(result);
|
||||
|
||||
sfSftp_destroy(sftp);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
#include <CSFML/Network/SocketSelector.h>
|
||||
#include <CSFML/Network/TcpListener.h>
|
||||
#include <CSFML/Network/TcpSocket.h>
|
||||
|
||||
#include <SFML/Network/SocketSelector.hpp>
|
||||
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
TEST_CASE("[Network] sfSocketSelector")
|
||||
{
|
||||
SECTION("sfSocketSelectorReadiness")
|
||||
{
|
||||
STATIC_CHECK(sfSocketSelectorReceive == static_cast<int>(sf::SocketSelector::Receive));
|
||||
STATIC_CHECK(sfSocketSelectorSend == static_cast<int>(sf::SocketSelector::Send));
|
||||
}
|
||||
|
||||
SECTION("Ready callbacks")
|
||||
{
|
||||
sfTcpListener* listener = sfTcpListener_create();
|
||||
REQUIRE(sfTcpListener_listen(listener, 0, sfIpAddress_LocalHost) == sfSocketDone);
|
||||
|
||||
sfTcpSocket* client = sfTcpSocket_create();
|
||||
REQUIRE(sfTcpSocket_connect(client, sfIpAddress_LocalHost, sfTcpListener_getLocalPort(listener), sfSeconds(1)) ==
|
||||
sfSocketDone);
|
||||
|
||||
sfSocketSelector* selector = sfSocketSelector_create();
|
||||
|
||||
uint32_t readiness = 0;
|
||||
const auto callback = [](uint32_t ready, void* userData) { *static_cast<uint32_t*>(userData) |= ready; };
|
||||
CHECK(sfSocketSelector_addTcpListenerWithReadiness(selector, listener, sfSocketSelectorReceive, callback, &readiness));
|
||||
|
||||
REQUIRE(sfSocketSelector_wait(selector, sfSeconds(1)));
|
||||
CHECK(sfSocketSelector_isTcpListenerReady(selector, listener));
|
||||
CHECK(sfSocketSelector_isTcpListenerReadyFor(selector, listener, sfSocketSelectorReceive));
|
||||
sfSocketSelector_dispatchReadyCallbacks(selector);
|
||||
CHECK(readiness == sfSocketSelectorReceive);
|
||||
|
||||
CHECK(sfSocketSelector_removeTcpListener(selector, listener));
|
||||
|
||||
sfSocketSelector_destroy(selector);
|
||||
sfTcpSocket_destroy(client);
|
||||
sfTcpListener_destroy(listener);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
#include <CSFML/Network/TcpSocket.h>
|
||||
|
||||
#include <SFML/Network/TcpSocket.hpp>
|
||||
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
TEST_CASE("[Network] sfTcpSocket")
|
||||
{
|
||||
SECTION("sfTlsStatus")
|
||||
{
|
||||
STATIC_CHECK(sfTlsNotConnected == static_cast<int>(sf::TcpSocket::TlsStatus::NotConnected));
|
||||
STATIC_CHECK(sfTlsHandshakeStarted == static_cast<int>(sf::TcpSocket::TlsStatus::HandshakeStarted));
|
||||
STATIC_CHECK(sfTlsHandshakeComplete == static_cast<int>(sf::TcpSocket::TlsStatus::HandshakeComplete));
|
||||
STATIC_CHECK(sfTlsError == static_cast<int>(sf::TcpSocket::TlsStatus::Error));
|
||||
}
|
||||
|
||||
SECTION("TLS on unconnected socket")
|
||||
{
|
||||
sfTcpSocket* socket = sfTcpSocket_create();
|
||||
CHECK(sfTcpSocket_setupTlsClient(socket, "localhost", true) == sfTlsNotConnected);
|
||||
CHECK(sfTcpSocket_getCurrentCiphersuiteName(socket) == nullptr);
|
||||
sfTcpSocket_destroy(socket);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
#include <CSFML/System/Version.h>
|
||||
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include <string>
|
||||
|
||||
TEST_CASE("[System] sfGetVersion")
|
||||
{
|
||||
const sfVersion version = sfGetVersion();
|
||||
CHECK(version.major == 3);
|
||||
CHECK(version.minor >= 1);
|
||||
CHECK(version.patch >= 0);
|
||||
REQUIRE(version.string != nullptr);
|
||||
CHECK(std::string(version.string).rfind(std::to_string(version.major) + "." + std::to_string(version.minor), 0) == 0);
|
||||
}
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
#!/bin/sh
|
||||
|
||||
VERSION="3.0.2"
|
||||
VERSION_C="3.0.0"
|
||||
VERSION="3.1.0"
|
||||
VERSION_C="3.1.0"
|
||||
# BUILD_CSFML=FALSE
|
||||
BUILD_CSFML=TRUE
|
||||
BUILD_SFML=FALSE
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||
|
||||
<Version>3.0.0</Version>
|
||||
<Version>3.1.0</Version>
|
||||
<Authors>Laurent Gomila</Authors>
|
||||
<PackageTags>sfml csfml</PackageTags>
|
||||
<Copyright>Copyright © Laurent Gomila</Copyright>
|
||||
|
||||
@@ -58,7 +58,7 @@ if [[ -n "$CXX_COMPILER" ]]; then
|
||||
echo "Using custom compilers: CXX=$CXX_COMPILER, CC=$C_COMPILER"
|
||||
fi
|
||||
|
||||
SFMLBranch="3.0.2" # The branch or tag of the SFML repository to be cloned
|
||||
SFMLBranch="3.1.0" # The branch or tag of the SFML repository to be cloned
|
||||
CSFMLDir="$(realpath ../../)" # The directory of the source code of CSFML
|
||||
|
||||
OutDir="./CSFML/runtimes/$RID/native" # The base directory of all CSFML modules, used to copy the final libraries
|
||||
@@ -145,8 +145,8 @@ cmake --build . --config Release
|
||||
# STEP 5: Copy result to the NuGet folders #
|
||||
# ======================================== #
|
||||
|
||||
SFMLMajorMinor="3.0"
|
||||
CSFMLMajorMinor="3.0"
|
||||
SFMLMajorMinor="3.1"
|
||||
CSFMLMajorMinor="3.1"
|
||||
|
||||
# Copies one SFML and CSFML module into the NuGet package
|
||||
# The module name must be passed to this function as an argument, in lowercase
|
||||
@@ -161,7 +161,7 @@ copymodule()
|
||||
# SFML.Net only searches for the name with common pre- and suffixes
|
||||
# As such we need to ship e.g. libcsfml-graphics.so
|
||||
# But the CSFML libs will look for the major.minor version
|
||||
# As such we also need to ship e.g. libcsfml-graphics.so.3.0
|
||||
# As such we also need to ship e.g. libcsfml-graphics.so.3.1
|
||||
# Unfortunately NuGet package don't support symlinks: https://github.com/NuGet/Home/issues/10734
|
||||
# For SFML, we can just ship one version that CSFML will be looking for
|
||||
cp "$SFMLLibDir/libsfml-$MODULE.so.$SFMLMajorMinor" "$OutDir"
|
||||
|
||||
@@ -46,7 +46,7 @@ echo "Please note that all SFML dependencies must be installed and available to
|
||||
|
||||
RID="$1"
|
||||
|
||||
SFMLBranch="3.0.2" # The branch or tag of the SFML repository to be cloned
|
||||
SFMLBranch="3.1.0" # The branch or tag of the SFML repository to be cloned
|
||||
CSFMLDir="$(grealpath "$(git rev-parse --show-toplevel)")" # The directory of the source code of CSFML
|
||||
|
||||
OutDir="./CSFML/runtimes/$RID/native" # The base directory of all CSFML modules, used to copy the final libraries
|
||||
@@ -150,9 +150,9 @@ cmake --build . --config Release --target install
|
||||
# STEP 5: Copy result to the NuGet folders #
|
||||
# ======================================== #
|
||||
|
||||
SFMLMajorMinor="3.0"
|
||||
SFMLMajorMinor="3.1"
|
||||
SFMLMajorMinorPatch="$SFMLMajorMinor.0"
|
||||
CSFMLMajorMinor="3.0"
|
||||
CSFMLMajorMinor="3.1"
|
||||
CSFMLMajorMinorPatch="$CSFMLMajorMinor.0"
|
||||
|
||||
# Copies one SFML and CSFML module into the NuGet package
|
||||
@@ -168,7 +168,7 @@ copymodule()
|
||||
# SFML.Net only searches for the name with common pre- and suffixes
|
||||
# As such we need to ship e.g. libcsfml-graphics.dylib
|
||||
# But the CSFML libs will look for the major.minor version
|
||||
# As such we also need to ship e.g. libcsfml-graphics.3.0.dylib
|
||||
# As such we also need to ship e.g. libcsfml-graphics.3.1.dylib
|
||||
# Unfortunately NuGet package don't support symlinks: https://github.com/NuGet/Home/issues/10734
|
||||
# For SFML, we can just ship one version that CSFML will be looking for
|
||||
cp "$SFMLLibDir/libsfml-$MODULE.$SFMLMajorMinor.dylib" "$OutDir"
|
||||
|
||||
@@ -43,7 +43,7 @@ Write-Output "Building $RID"
|
||||
Write-Output "Using $Generator as the cmake generator"
|
||||
Write-Output "Using architecture $ArchitectureCMake"
|
||||
|
||||
$SFMLBranch = "3.0.2" # The branch or tag of the SFML repository to be cloned
|
||||
$SFMLBranch = "3.1.0" # The branch or tag of the SFML repository to be cloned
|
||||
$CSFMLDir = (Get-Item (git rev-parse --show-toplevel)).FullName # The directory of the source code of CSFML
|
||||
|
||||
$OutDir = "./CSFML/runtimes/$RID/native" # The directory of all CSFML modules, used to copy the final dlls
|
||||
|
||||
Reference in new issue
Block a user