# endif
# endif
+# if UDPC_PLATFORM == UDPC_PLATFORM_WINDOWS
+# define UDPC_EXPORT __declspec(dllexport)
+# else
+# define UDPC_EXPORT
+# endif
+
#endif // DOXYGEN_SHOULD_SKIP_THIS
#ifdef __cplusplus
struct UDPC_Context;
typedef struct UDPC_Context *UDPC_HContext;
-typedef enum {
+typedef enum UDPC_EXPORT UDPC_LoggingType {
/// Does not log anything
UDPC_SILENT,
/// Only log errors
/// Note auth policy will only take effect if public key verification of packets
/// is enabled (if libsodium is enabled).
-typedef enum {
+typedef enum UDPC_EXPORT UDPC_AuthPolicy {
/// All peers will not be denied regardless of use of public key verification
UDPC_AUTH_POLICY_FALLBACK=0,
/// Only peers with public key verification will be allowed
* create one. This struct does not hold dynamic data, so there is no need to
* free it.
*/
-typedef struct {
+typedef struct UDPC_EXPORT UDPC_ConnectionId {
UDPC_IPV6_ADDR_TYPE addr;
uint32_t scope_id;
uint16_t port;
* \warning This struct must be free'd with a call to UDPC_free_PacketInfo to
* avoid a memory leak.
*/
-typedef struct {
+typedef struct UDPC_EXPORT UDPC_PacketInfo {
/*!
* A char array of size \ref dataSize. Will be NULL if this UDPC_PacketInfo
* is invalid.
* \p conId in the UDPC_Event which refers to the peer with which the event
* ocurred.
*/
-typedef enum {
+typedef enum UDPC_EXPORT UDPC_EventType {
UDPC_ET_NONE,
UDPC_ET_REQUEST_CONNECT,
UDPC_ET_REQUEST_DISCONNECT,
* valid UDPC_ConnectionId \p conId that identifies the peer that the event is
* referring to.
*/
-typedef struct {
+typedef struct UDPC_EXPORT UDPC_Event {
UDPC_EventType type;
UDPC_ConnectionId conId;
union Value {
*
* \return An initialized UDPC_ConnectionId
*/
-UDPC_ConnectionId UDPC_create_id(UDPC_IPV6_ADDR_TYPE addr, uint16_t port);
+UDPC_EXPORT UDPC_ConnectionId UDPC_create_id(UDPC_IPV6_ADDR_TYPE addr, uint16_t port);
/*!
* \brief Creates an UDPC_ConnectionId with the given addr, scope_id, and port
*
* \return An initialized UDPC_ConnectionId
*/
-UDPC_ConnectionId UDPC_create_id_full(UDPC_IPV6_ADDR_TYPE addr, uint32_t scope_id, uint16_t port);
+UDPC_EXPORT UDPC_ConnectionId UDPC_create_id_full(UDPC_IPV6_ADDR_TYPE addr, uint32_t scope_id, uint16_t port);
/*!
* \brief Creates an UDPC_ConnectionId with the given port
*
* \return An initialized UDPC_ConnectionId
*/
-UDPC_ConnectionId UDPC_create_id_anyaddr(uint16_t port);
+UDPC_EXPORT UDPC_ConnectionId UDPC_create_id_anyaddr(uint16_t port);
/*!
* \brief Creates an UDPC_ConnectionId with the given addr string and port
*
* \return An initialized UDPC_ConnectionId
*/
-UDPC_ConnectionId UDPC_create_id_easy(const char *addrString, uint16_t port);
+UDPC_EXPORT UDPC_ConnectionId UDPC_create_id_easy(const char *addrString, uint16_t port);
-UDPC_ConnectionId UDPC_create_id_hostname(const char *hostname, uint16_t port);
+UDPC_EXPORT UDPC_ConnectionId UDPC_create_id_hostname(const char *hostname, uint16_t port);
/*!
* \brief Creates an UDPC_HContext that holds state for connections
*
* \return A UDPC context
*/
-UDPC_HContext UDPC_init(UDPC_ConnectionId listenId, int isClient, int isUsingLibsodium);
+UDPC_EXPORT UDPC_HContext UDPC_init(UDPC_ConnectionId listenId, int isClient, int isUsingLibsodium);
/*!
* \brief Creates an UDPC_HContext that holds state for connections that
* auto-updates via a thread.
*
* \return A UDPC context
*/
-UDPC_HContext UDPC_init_threaded_update(
+UDPC_EXPORT UDPC_HContext UDPC_init_threaded_update(
UDPC_ConnectionId listenId,
int isClient,
int isUsingLibsodium);
*
* \return A UDPC context
*/
-UDPC_HContext UDPC_init_threaded_update_ms(
+UDPC_EXPORT UDPC_HContext UDPC_init_threaded_update_ms(
UDPC_ConnectionId listenId,
int isClient,
int updateMS,
* \return non-zero if auto updating is enabled. If the context already had auto
* updating enabled, this function will return zero.
*/
-int UDPC_enable_threaded_update(UDPC_HContext ctx);
+UDPC_EXPORT int UDPC_enable_threaded_update(UDPC_HContext ctx);
/*!
* \brief Enables auto updating on a separate thread for the given UDPC_HContext
* with the specified update interval
* \return non-zero if auto updating is enabled. If the context already had auto
* updating enabled, this function will return zero.
*/
-int UDPC_enable_threaded_update_ms(UDPC_HContext ctx, int updateMS);
+UDPC_EXPORT int UDPC_enable_threaded_update_ms(UDPC_HContext ctx, int updateMS);
/*!
* \brief Disables auto updating on a separate thread for the given
* UDPC_HContext
* \return non-zero if auto updating is disabled. If the context already had
* auto updating disabled, this function will return zero.
*/
-int UDPC_disable_threaded_update(UDPC_HContext ctx);
+UDPC_EXPORT int UDPC_disable_threaded_update(UDPC_HContext ctx);
/*!
* \brief Checks if the given UDPC_HContext is valid (successfully initialized)
*
* \return non-zero if the given context is valid
*/
-int UDPC_is_valid_context(UDPC_HContext ctx);
+UDPC_EXPORT int UDPC_is_valid_context(UDPC_HContext ctx);
/*!
* \brief Cleans up the UDPC_HContext
* \warning This function must be called after a UDPC_HContext is no longer used
* to avoid memory leaks.
*/
-void UDPC_destroy(UDPC_HContext ctx);
+UDPC_EXPORT void UDPC_destroy(UDPC_HContext ctx);
/*!
* \brief Updates the context
* enabled via UDPC_init_threaded_update(), UDPC_init_threaded_update_ms(),
* UDPC_enable_threaded_update(), or UDPC_enable_threaded_update_ms().
*/
-void UDPC_update(UDPC_HContext ctx);
+UDPC_EXPORT void UDPC_update(UDPC_HContext ctx);
/*!
* \brief Initiate a connection to a server peer
* \param enableLibSodium If packet headers should be verified with the server
* peer (Fails if UDPC was not compiled with libsodium support)
*/
-void UDPC_client_initiate_connection(
+UDPC_EXPORT void UDPC_client_initiate_connection(
UDPC_HContext ctx,
UDPC_ConnectionId connectionId,
int enableLibSodium);
* \param data A pointer to data to be sent in a packet
* \param size The size in bytes of the data to be sent
*/
-void UDPC_queue_send(UDPC_HContext ctx, UDPC_ConnectionId destinationId,
+UDPC_EXPORT void UDPC_queue_send(UDPC_HContext ctx, UDPC_ConnectionId destinationId,
int isChecked, const void *data, uint32_t size);
/*!
*
* \return The size of the queue
*/
-unsigned long UDPC_get_queue_send_current_size(UDPC_HContext ctx);
+UDPC_EXPORT unsigned long UDPC_get_queue_send_current_size(UDPC_HContext ctx);
/*!
* \brief Gets the size of a connection's queue of queued packets
*
* \return The size of a connection's queue
*/
-unsigned long UDPC_get_queued_size(UDPC_HContext ctx, UDPC_ConnectionId id, int *exists);
+UDPC_EXPORT unsigned long UDPC_get_queued_size(UDPC_HContext ctx, UDPC_ConnectionId id, int *exists);
/*!
* \brief Gets the size limit of a connection's queue of queued packets
*
* \return The size limit of a connection's queue
*/
-unsigned long UDPC_get_max_queued_size();
+UDPC_EXPORT unsigned long UDPC_get_max_queued_size();
/*!
* \brief Set whether or not the UDPC context will accept new connections
* \param isAccepting Set to non-zero to accept connections
* \return The previous setting (1 if accepting, 0 if not)
*/
-int UDPC_set_accept_new_connections(UDPC_HContext ctx, int isAccepting);
+UDPC_EXPORT int UDPC_set_accept_new_connections(UDPC_HContext ctx, int isAccepting);
/*!
* \brief Drops an existing connection to a peer
* \param dropAllWithAddr Set to non-zero to drop all peers with the ip address
* specified in \p connectionId
*/
-void UDPC_drop_connection(UDPC_HContext ctx, UDPC_ConnectionId connectionId, int dropAllWithAddr);
+UDPC_EXPORT void UDPC_drop_connection(UDPC_HContext ctx, UDPC_ConnectionId connectionId, int dropAllWithAddr);
/*!
* \brief Checks if a connection exists to the peer identified by the given
*
* \return non-zero if a connection to the peer exists
*/
-int UDPC_has_connection(UDPC_HContext ctx, UDPC_ConnectionId connectionId);
+UDPC_EXPORT int UDPC_has_connection(UDPC_HContext ctx, UDPC_ConnectionId connectionId);
/*!
* \brief Gets a dynamically allocated array of connected peers' identifiers
* (set to NULL to not get a size)
* \return A dynamically allocated array of identifiers
*/
-UDPC_ConnectionId* UDPC_get_list_connected(UDPC_HContext ctx, unsigned int *size);
+UDPC_EXPORT UDPC_ConnectionId* UDPC_get_list_connected(UDPC_HContext ctx, unsigned int *size);
/*!
* \brief Cleans up a dynamically allocated array of connected peers' identifiers
* \param list The array to clean up
*/
-void UDPC_free_list_connected(UDPC_ConnectionId *list);
+UDPC_EXPORT void UDPC_free_list_connected(UDPC_ConnectionId *list);
/*!
* \brief Gets the protocol id of the UDPC context
* \param ctx The UDPC context
* \return The protocol id of the given UDPC context
*/
-uint32_t UDPC_get_protocol_id(UDPC_HContext ctx);
+UDPC_EXPORT uint32_t UDPC_get_protocol_id(UDPC_HContext ctx);
/*!
* \brief Sets the protocol id of the UDPC context
* \param id The new id to use as the protocol id
* \return The previous protocol id of the UDPC context
*/
-uint32_t UDPC_set_protocol_id(UDPC_HContext ctx, uint32_t id);
+UDPC_EXPORT uint32_t UDPC_set_protocol_id(UDPC_HContext ctx, uint32_t id);
/*!
* \brief Gets the logging type of the UDPC context
* \param ctx The UDPC context
* \return The logging type of the UDPC context
*/
-UDPC_LoggingType UDPC_get_logging_type(UDPC_HContext ctx);
+UDPC_EXPORT UDPC_LoggingType UDPC_get_logging_type(UDPC_HContext ctx);
/*!
* \brief Sets the logging type of the UDPC context
* \param loggingType The logging type to set to
* \return The previously set logging type
*/
-UDPC_LoggingType UDPC_set_logging_type(UDPC_HContext ctx, UDPC_LoggingType loggingType);
+UDPC_EXPORT UDPC_LoggingType UDPC_set_logging_type(UDPC_HContext ctx, UDPC_LoggingType loggingType);
/*!
* \brief Returns non-zero if the UDPC context will record events
* \param ctx The UDPC context
* \return non-zero if receiving events
*/
-int UDPC_get_receiving_events(UDPC_HContext ctx);
+UDPC_EXPORT int UDPC_get_receiving_events(UDPC_HContext ctx);
/*!
* \brief Sets whether or not UDPC will record events
* \param isReceivingEvents Set to non-zero to receive events
* \return non-zero if UDPC was previously receiving events
*/
-int UDPC_set_receiving_events(UDPC_HContext ctx, int isReceivingEvents);
+UDPC_EXPORT int UDPC_set_receiving_events(UDPC_HContext ctx, int isReceivingEvents);
/*!
* \brief Gets a recorded event
* \return An UDPC_Event (will be of type UDPC_ET_NONE if there are no more
* events)
*/
-UDPC_Event UDPC_get_event(UDPC_HContext ctx, unsigned long *remaining);
+UDPC_EXPORT UDPC_Event UDPC_get_event(UDPC_HContext ctx, unsigned long *remaining);
/*!
* \brief Get a received packet from a given UDPC context.
* \warning The received packet (if valid) must be free'd with a call to
* \ref UDPC_free_PacketInfo() to avoid a memory leak.
*/
-UDPC_PacketInfo UDPC_get_received(UDPC_HContext ctx, unsigned long *remaining);
+UDPC_EXPORT UDPC_PacketInfo UDPC_get_received(UDPC_HContext ctx, unsigned long *remaining);
/*!
* \brief Frees a UDPC_PacketInfo.
* set to NULL and \ref UDPC_PacketInfo::dataSize will be set to 0 if the given
* packet is valid.
*/
-void UDPC_free_PacketInfo(UDPC_PacketInfo pInfo);
+UDPC_EXPORT void UDPC_free_PacketInfo(UDPC_PacketInfo pInfo);
/*!
* \brief Sets public/private keys used for packet verification
* \return Non-zero if keys were successfully set, zero if context is invalid or
* libsodium is not enabled
*/
-int UDPC_set_libsodium_keys(UDPC_HContext ctx, const unsigned char *sk, const unsigned char *pk);
+UDPC_EXPORT int UDPC_set_libsodium_keys(UDPC_HContext ctx, const unsigned char *sk, const unsigned char *pk);
/*!
* \brief Sets the public/private keys used for packet verification
* \return Non-zero if keys were successfully set, zero if context is invalid or
* libsodium is not enabled
*/
-int UDPC_set_libsodium_key_easy(UDPC_HContext ctx, const unsigned char *sk);
+UDPC_EXPORT int UDPC_set_libsodium_key_easy(UDPC_HContext ctx, const unsigned char *sk);
/*!
* \brief Removes set keys if any used for packet verification
*
* \return Zero if context is invalid or libsodium is not enabled
*/
-int UDPC_unset_libsodium_keys(UDPC_HContext ctx);
+UDPC_EXPORT int UDPC_unset_libsodium_keys(UDPC_HContext ctx);
/*!
* \brief Adds a public key to the whitelist
*
* \return The size of the whitelist on success, zero otherwise
*/
-int UDPC_add_whitelist_pk(UDPC_HContext ctx, const unsigned char *pk);
+UDPC_EXPORT int UDPC_add_whitelist_pk(UDPC_HContext ctx, const unsigned char *pk);
/*!
* \brief Checks if a public key is in the whitelist
*
* \return Non-zero if the given public key is in the whitelist
*/
-int UDPC_has_whitelist_pk(UDPC_HContext ctx, const unsigned char *pk);
+UDPC_EXPORT int UDPC_has_whitelist_pk(UDPC_HContext ctx, const unsigned char *pk);
/*!
* \brief Removes a public key from the whitelist
*
* \return Non-zero if a public key was removed
*/
-int UDPC_remove_whitelist_pk(UDPC_HContext ctx, const unsigned char *pk);
+UDPC_EXPORT int UDPC_remove_whitelist_pk(UDPC_HContext ctx, const unsigned char *pk);
/*!
* \brief Clears the public key whitelist
* \return Zero if the context is invalid or libsodium is not enabled, non-zero
* if the whitelist was successfully cleared
*/
-int UDPC_clear_whitelist(UDPC_HContext ctx);
+UDPC_EXPORT int UDPC_clear_whitelist(UDPC_HContext ctx);
/*!
* \brief Gets how peers are handled regarding public key verification
*
* \return The current auth policy (see \ref UDPC_AuthPolicy) , or zero on fail
*/
-int UDPC_get_auth_policy(UDPC_HContext ctx);
+UDPC_EXPORT int UDPC_get_auth_policy(UDPC_HContext ctx);
/*!
* \brief Sets how peers are handled regarding public key verification
*
* \return The previous auth policy (see \ref UDPC_AuthPolicy), or zero on fail
*/
-int UDPC_set_auth_policy(UDPC_HContext ctx, int value);
+UDPC_EXPORT int UDPC_set_auth_policy(UDPC_HContext ctx, int value);
-const char *UDPC_atostr_cid(UDPC_HContext ctx, UDPC_ConnectionId connectionId);
+UDPC_EXPORT const char *UDPC_atostr_cid(UDPC_HContext ctx, UDPC_ConnectionId connectionId);
-const char *UDPC_atostr(UDPC_HContext ctx, UDPC_IPV6_ADDR_TYPE addr);
+UDPC_EXPORT const char *UDPC_atostr(UDPC_HContext ctx, UDPC_IPV6_ADDR_TYPE addr);
// =============================================================================
// Helpers
/// addrStr must be a valid ipv6 address or a valid ipv4 address
-UDPC_IPV6_ADDR_TYPE UDPC_strtoa(const char *addrStr);
+UDPC_EXPORT UDPC_IPV6_ADDR_TYPE UDPC_strtoa(const char *addrStr);
-UDPC_IPV6_ADDR_TYPE UDPC_strtoa_link(const char *addrStr, uint32_t *linkId_out);
+UDPC_EXPORT UDPC_IPV6_ADDR_TYPE UDPC_strtoa_link(const char *addrStr, uint32_t *linkId_out);
-UDPC_IPV6_ADDR_TYPE UDPC_a4toa6(uint32_t a4_be);
+UDPC_EXPORT UDPC_IPV6_ADDR_TYPE UDPC_a4toa6(uint32_t a4_be);
-int UDPC_is_big_endian();
-uint16_t UDPC_no16i(uint16_t i);
-uint32_t UDPC_no32i(uint32_t i);
-uint64_t UDPC_no64i(uint64_t i);
-float UDPC_no32f(float f);
-double UDPC_no64f(double f);
+UDPC_EXPORT int UDPC_is_big_endian();
+UDPC_EXPORT uint16_t UDPC_no16i(uint16_t i);
+UDPC_EXPORT uint32_t UDPC_no32i(uint32_t i);
+UDPC_EXPORT uint64_t UDPC_no64i(uint64_t i);
+UDPC_EXPORT float UDPC_no32f(float f);
+UDPC_EXPORT double UDPC_no64f(double f);
#ifdef __cplusplus
}