diff --git a/src/FFI/Tox/Tox.hs b/src/FFI/Tox/Tox.hs new file mode 100644 index 0000000..457d28c --- /dev/null +++ b/src/FFI/Tox/Tox.hs @@ -0,0 +1,886 @@ +-- bazel-out/k8-fastbuild/bin/c-toxcore/tox/tox.h +{-# LANGUAGE DeriveGeneric #-} +module FFI.Tox.Tox where + +import Data.MessagePack (MessagePack) +import Data.Word (Word16, Word32, Word64) +import Foreign.C.Enum (CEnum (..), CErr) +import Foreign.C.String (CString) +import Foreign.C.Types (CInt (..), CSize (..)) +import Foreign.Ptr (FunPtr, Ptr) +import GHC.Generics (Generic) +import Test.QuickCheck.Arbitrary (Arbitrary (..), + arbitraryBoundedEnum) + +data ToxStruct +type ToxPtr = Ptr ToxStruct +foreign import ccall tox_version_major :: Word32 +foreign import ccall tox_version_minor :: Word32 +foreign import ccall tox_version_patch :: Word32 +foreign import ccall tox_version_is_compatible :: Word32 -> Word32 -> Word32 -> IO Bool +foreign import ccall tox_public_key_size :: Word32 +foreign import ccall tox_secret_key_size :: Word32 +foreign import ccall tox_conference_uid_size :: Word32 +foreign import ccall tox_conference_id_size :: Word32 +foreign import ccall tox_nospam_size :: Word32 +foreign import ccall tox_address_size :: Word32 +foreign import ccall tox_max_name_length :: Word32 +foreign import ccall tox_max_status_message_length :: Word32 +foreign import ccall tox_max_friend_request_length :: Word32 +foreign import ccall tox_max_message_length :: Word32 +foreign import ccall tox_max_custom_packet_size :: Word32 +foreign import ccall tox_hash_length :: Word32 +foreign import ccall tox_file_id_length :: Word32 +foreign import ccall tox_max_filename_length :: Word32 +foreign import ccall tox_max_hostname_length :: Word32 +data UserStatus + = UserStatusNone + | UserStatusAway + | UserStatusBusy + deriving (Eq, Ord, Enum, Bounded, Read, Show, Generic) +instance MessagePack UserStatus +instance Arbitrary UserStatus where arbitrary = arbitraryBoundedEnum +data MessageType + = MessageTypeNormal + | MessageTypeAction + deriving (Eq, Ord, Enum, Bounded, Read, Show, Generic) +instance MessagePack MessageType +instance Arbitrary MessageType where arbitrary = arbitraryBoundedEnum +data ProxyType + = ProxyTypeNone + | ProxyTypeHttp + | ProxyTypeSocks5 + deriving (Eq, Ord, Enum, Bounded, Read, Show, Generic) +instance MessagePack ProxyType +instance Arbitrary ProxyType where arbitrary = arbitraryBoundedEnum +data SavedataType + = SavedataTypeNone + | SavedataTypeToxSave + | SavedataTypeSecretKey + deriving (Eq, Ord, Enum, Bounded, Read, Show, Generic) +instance MessagePack SavedataType +instance Arbitrary SavedataType where arbitrary = arbitraryBoundedEnum +data LogLevel + = LogLevelTrace + | LogLevelDebug + | LogLevelInfo + | LogLevelWarning + | LogLevelError + deriving (Eq, Ord, Enum, Bounded, Read, Show, Generic) +instance MessagePack LogLevel +instance Arbitrary LogLevel where arbitrary = arbitraryBoundedEnum +type LogCb = ToxPtr -> CEnum LogLevel -> CString -> Word32 -> CString -> CString -> Ptr () -> IO () +foreign import ccall "wrapper" wrapLogCb :: LogCb -> IO (FunPtr LogCb) +data SystemStruct +type SystemPtr = Ptr SystemStruct +data OptionsStruct +type OptionsPtr = Ptr OptionsStruct +foreign import ccall tox_options_get_ipv6_enabled :: OptionsPtr -> IO Bool +foreign import ccall tox_options_set_ipv6_enabled :: OptionsPtr -> Bool -> IO () +foreign import ccall tox_options_get_udp_enabled :: OptionsPtr -> IO Bool +foreign import ccall tox_options_set_udp_enabled :: OptionsPtr -> Bool -> IO () +foreign import ccall tox_options_get_local_discovery_enabled :: OptionsPtr -> IO Bool +foreign import ccall tox_options_set_local_discovery_enabled :: OptionsPtr -> Bool -> IO () +foreign import ccall tox_options_get_dht_announcements_enabled :: OptionsPtr -> IO Bool +foreign import ccall tox_options_set_dht_announcements_enabled :: OptionsPtr -> Bool -> IO () +foreign import ccall tox_options_get_proxy_type :: OptionsPtr -> IO (CEnum ProxyType) +foreign import ccall tox_options_set_proxy_type :: OptionsPtr -> CEnum ProxyType -> IO () +foreign import ccall tox_options_get_proxy_host :: OptionsPtr -> IO CString +foreign import ccall tox_options_set_proxy_host :: OptionsPtr -> CString -> IO () +foreign import ccall tox_options_get_proxy_port :: OptionsPtr -> IO Word16 +foreign import ccall tox_options_set_proxy_port :: OptionsPtr -> Word16 -> IO () +foreign import ccall tox_options_get_start_port :: OptionsPtr -> IO Word16 +foreign import ccall tox_options_set_start_port :: OptionsPtr -> Word16 -> IO () +foreign import ccall tox_options_get_end_port :: OptionsPtr -> IO Word16 +foreign import ccall tox_options_set_end_port :: OptionsPtr -> Word16 -> IO () +foreign import ccall tox_options_get_tcp_port :: OptionsPtr -> IO Word16 +foreign import ccall tox_options_set_tcp_port :: OptionsPtr -> Word16 -> IO () +foreign import ccall tox_options_get_hole_punching_enabled :: OptionsPtr -> IO Bool +foreign import ccall tox_options_set_hole_punching_enabled :: OptionsPtr -> Bool -> IO () +foreign import ccall tox_options_get_savedata_type :: OptionsPtr -> IO (CEnum SavedataType) +foreign import ccall tox_options_set_savedata_type :: OptionsPtr -> CEnum SavedataType -> IO () +foreign import ccall tox_options_get_savedata_data :: OptionsPtr -> IO CString +foreign import ccall tox_options_set_savedata_data :: OptionsPtr -> CString -> CSize -> IO () +foreign import ccall tox_options_get_savedata_length :: OptionsPtr -> IO CSize +foreign import ccall tox_options_set_savedata_length :: OptionsPtr -> CSize -> IO () +foreign import ccall tox_options_get_log_callback :: OptionsPtr -> IO (FunPtr LogCb) +foreign import ccall tox_options_set_log_callback :: OptionsPtr -> FunPtr LogCb -> IO () +foreign import ccall tox_options_get_log_user_data :: OptionsPtr -> IO (Ptr ()) +foreign import ccall tox_options_set_log_user_data :: OptionsPtr -> Ptr () -> IO () +foreign import ccall tox_options_get_experimental_thread_safety :: OptionsPtr -> IO Bool +foreign import ccall tox_options_set_experimental_thread_safety :: OptionsPtr -> Bool -> IO () +foreign import ccall tox_options_get_operating_system :: OptionsPtr -> IO SystemPtr +foreign import ccall tox_options_set_operating_system :: OptionsPtr -> SystemPtr -> IO () +foreign import ccall tox_options_default :: OptionsPtr -> IO () +data ErrOptionsNew + = ErrOptionsNewMalloc + deriving (Eq, Ord, Enum, Bounded, Read, Show, Generic) +instance MessagePack ErrOptionsNew +instance Arbitrary ErrOptionsNew where arbitrary = arbitraryBoundedEnum +foreign import ccall tox_options_new :: CErr ErrOptionsNew -> IO OptionsPtr +foreign import ccall tox_options_free :: OptionsPtr -> IO () +data ErrNew + = ErrNewNull + | ErrNewMalloc + | ErrNewPortAlloc + | ErrNewProxyBadType + | ErrNewProxyBadHost + | ErrNewProxyBadPort + | ErrNewProxyNotFound + | ErrNewLoadEncrypted + | ErrNewLoadBadFormat + deriving (Eq, Ord, Enum, Bounded, Read, Show, Generic) +instance MessagePack ErrNew +instance Arbitrary ErrNew where arbitrary = arbitraryBoundedEnum +foreign import ccall tox_new :: OptionsPtr -> CErr ErrNew -> IO ToxPtr +foreign import ccall tox_kill :: ToxPtr -> IO () +foreign import ccall tox_get_system :: ToxPtr -> IO SystemPtr +foreign import ccall tox_get_savedata_size :: ToxPtr -> IO CSize +foreign import ccall tox_get_savedata :: ToxPtr -> CString -> IO () +data ErrBootstrap + = ErrBootstrapNull + | ErrBootstrapBadHost + | ErrBootstrapBadPort + deriving (Eq, Ord, Enum, Bounded, Read, Show, Generic) +instance MessagePack ErrBootstrap +instance Arbitrary ErrBootstrap where arbitrary = arbitraryBoundedEnum +foreign import ccall tox_bootstrap :: ToxPtr -> CString -> Word16 -> CString -> CErr ErrBootstrap -> IO Bool +foreign import ccall tox_add_tcp_relay :: ToxPtr -> CString -> Word16 -> CString -> CErr ErrBootstrap -> IO Bool +data Connection + = ConnectionNone + | ConnectionTcp + | ConnectionUdp + deriving (Eq, Ord, Enum, Bounded, Read, Show, Generic) +instance MessagePack Connection +instance Arbitrary Connection where arbitrary = arbitraryBoundedEnum +foreign import ccall tox_self_get_connection_status :: ToxPtr -> IO (CEnum Connection) +type SelfConnectionStatusCb = ToxPtr -> CEnum Connection -> Ptr () -> IO () +foreign import ccall "wrapper" wrapSelfConnectionStatusCb :: SelfConnectionStatusCb -> IO (FunPtr SelfConnectionStatusCb) +foreign import ccall tox_callback_self_connection_status :: ToxPtr -> FunPtr SelfConnectionStatusCb -> IO () +foreign import ccall tox_iteration_interval :: ToxPtr -> IO Word32 +foreign import ccall tox_iterate :: ToxPtr -> Ptr () -> IO () +foreign import ccall tox_self_get_address :: ToxPtr -> CString -> IO () +foreign import ccall tox_self_set_nospam :: ToxPtr -> Word32 -> IO () +foreign import ccall tox_self_get_nospam :: ToxPtr -> IO Word32 +foreign import ccall tox_self_get_public_key :: ToxPtr -> CString -> IO () +foreign import ccall tox_self_get_secret_key :: ToxPtr -> CString -> IO () +data ErrSetInfo + = ErrSetInfoNull + | ErrSetInfoTooLong + deriving (Eq, Ord, Enum, Bounded, Read, Show, Generic) +instance MessagePack ErrSetInfo +instance Arbitrary ErrSetInfo where arbitrary = arbitraryBoundedEnum +foreign import ccall tox_self_set_name :: ToxPtr -> CString -> CSize -> CErr ErrSetInfo -> IO Bool +foreign import ccall tox_self_get_name_size :: ToxPtr -> IO CSize +foreign import ccall tox_self_get_name :: ToxPtr -> CString -> IO () +foreign import ccall tox_self_set_status_message :: ToxPtr -> CString -> CSize -> CErr ErrSetInfo -> IO Bool +foreign import ccall tox_self_get_status_message_size :: ToxPtr -> IO CSize +foreign import ccall tox_self_get_status_message :: ToxPtr -> CString -> IO () +foreign import ccall tox_self_set_status :: ToxPtr -> CEnum UserStatus -> IO () +foreign import ccall tox_self_get_status :: ToxPtr -> IO (CEnum UserStatus) +data ErrFriendAdd + = ErrFriendAddNull + | ErrFriendAddTooLong + | ErrFriendAddNoMessage + | ErrFriendAddOwnKey + | ErrFriendAddAlreadySent + | ErrFriendAddBadChecksum + | ErrFriendAddSetNewNospam + | ErrFriendAddMalloc + deriving (Eq, Ord, Enum, Bounded, Read, Show, Generic) +instance MessagePack ErrFriendAdd +instance Arbitrary ErrFriendAdd where arbitrary = arbitraryBoundedEnum +foreign import ccall tox_friend_add :: ToxPtr -> CString -> CString -> CSize -> CErr ErrFriendAdd -> IO Word32 +foreign import ccall tox_friend_add_norequest :: ToxPtr -> CString -> CErr ErrFriendAdd -> IO Word32 +data ErrFriendDelete + = ErrFriendDeleteFriendNotFound + deriving (Eq, Ord, Enum, Bounded, Read, Show, Generic) +instance MessagePack ErrFriendDelete +instance Arbitrary ErrFriendDelete where arbitrary = arbitraryBoundedEnum +foreign import ccall tox_friend_delete :: ToxPtr -> Word32 -> CErr ErrFriendDelete -> IO Bool +data ErrFriendByPublicKey + = ErrFriendByPublicKeyNull + | ErrFriendByPublicKeyNotFound + deriving (Eq, Ord, Enum, Bounded, Read, Show, Generic) +instance MessagePack ErrFriendByPublicKey +instance Arbitrary ErrFriendByPublicKey where arbitrary = arbitraryBoundedEnum +foreign import ccall tox_friend_by_public_key :: ToxPtr -> CString -> CErr ErrFriendByPublicKey -> IO Word32 +foreign import ccall tox_friend_exists :: ToxPtr -> Word32 -> IO Bool +foreign import ccall tox_self_get_friend_list_size :: ToxPtr -> IO CSize +foreign import ccall tox_self_get_friend_list :: ToxPtr -> Ptr Word32 -> IO () +data ErrFriendGetPublicKey + = ErrFriendGetPublicKeyFriendNotFound + deriving (Eq, Ord, Enum, Bounded, Read, Show, Generic) +instance MessagePack ErrFriendGetPublicKey +instance Arbitrary ErrFriendGetPublicKey where arbitrary = arbitraryBoundedEnum +foreign import ccall tox_friend_get_public_key :: ToxPtr -> Word32 -> CString -> CErr ErrFriendGetPublicKey -> IO Bool +data ErrFriendGetLastOnline + = ErrFriendGetLastOnlineFriendNotFound + deriving (Eq, Ord, Enum, Bounded, Read, Show, Generic) +instance MessagePack ErrFriendGetLastOnline +instance Arbitrary ErrFriendGetLastOnline where arbitrary = arbitraryBoundedEnum +foreign import ccall tox_friend_get_last_online :: ToxPtr -> Word32 -> CErr ErrFriendGetLastOnline -> IO Word64 +data ErrFriendQuery + = ErrFriendQueryNull + | ErrFriendQueryFriendNotFound + deriving (Eq, Ord, Enum, Bounded, Read, Show, Generic) +instance MessagePack ErrFriendQuery +instance Arbitrary ErrFriendQuery where arbitrary = arbitraryBoundedEnum +foreign import ccall tox_friend_get_name_size :: ToxPtr -> Word32 -> CErr ErrFriendQuery -> IO CSize +foreign import ccall tox_friend_get_name :: ToxPtr -> Word32 -> CString -> CErr ErrFriendQuery -> IO Bool +type FriendNameCb = ToxPtr -> Word32 -> CString -> CSize -> Ptr () -> IO () +foreign import ccall "wrapper" wrapFriendNameCb :: FriendNameCb -> IO (FunPtr FriendNameCb) +foreign import ccall tox_callback_friend_name :: ToxPtr -> FunPtr FriendNameCb -> IO () +foreign import ccall tox_friend_get_status_message_size :: ToxPtr -> Word32 -> CErr ErrFriendQuery -> IO CSize +foreign import ccall tox_friend_get_status_message :: ToxPtr -> Word32 -> CString -> CErr ErrFriendQuery -> IO Bool +type FriendStatusMessageCb = ToxPtr -> Word32 -> CString -> CSize -> Ptr () -> IO () +foreign import ccall "wrapper" wrapFriendStatusMessageCb :: FriendStatusMessageCb -> IO (FunPtr FriendStatusMessageCb) +foreign import ccall tox_callback_friend_status_message :: ToxPtr -> FunPtr FriendStatusMessageCb -> IO () +foreign import ccall tox_friend_get_status :: ToxPtr -> Word32 -> CErr ErrFriendQuery -> IO (CEnum UserStatus) +type FriendStatusCb = ToxPtr -> Word32 -> CEnum UserStatus -> Ptr () -> IO () +foreign import ccall "wrapper" wrapFriendStatusCb :: FriendStatusCb -> IO (FunPtr FriendStatusCb) +foreign import ccall tox_callback_friend_status :: ToxPtr -> FunPtr FriendStatusCb -> IO () +foreign import ccall tox_friend_get_connection_status :: ToxPtr -> Word32 -> CErr ErrFriendQuery -> IO (CEnum Connection) +type FriendConnectionStatusCb = ToxPtr -> Word32 -> CEnum Connection -> Ptr () -> IO () +foreign import ccall "wrapper" wrapFriendConnectionStatusCb :: FriendConnectionStatusCb -> IO (FunPtr FriendConnectionStatusCb) +foreign import ccall tox_callback_friend_connection_status :: ToxPtr -> FunPtr FriendConnectionStatusCb -> IO () +foreign import ccall tox_friend_get_typing :: ToxPtr -> Word32 -> CErr ErrFriendQuery -> IO Bool +type FriendTypingCb = ToxPtr -> Word32 -> Bool -> Ptr () -> IO () +foreign import ccall "wrapper" wrapFriendTypingCb :: FriendTypingCb -> IO (FunPtr FriendTypingCb) +foreign import ccall tox_callback_friend_typing :: ToxPtr -> FunPtr FriendTypingCb -> IO () +data ErrSetTyping + = ErrSetTypingFriendNotFound + deriving (Eq, Ord, Enum, Bounded, Read, Show, Generic) +instance MessagePack ErrSetTyping +instance Arbitrary ErrSetTyping where arbitrary = arbitraryBoundedEnum +foreign import ccall tox_self_set_typing :: ToxPtr -> Word32 -> Bool -> CErr ErrSetTyping -> IO Bool +data ErrFriendSendMessage + = ErrFriendSendMessageNull + | ErrFriendSendMessageFriendNotFound + | ErrFriendSendMessageFriendNotConnected + | ErrFriendSendMessageSendq + | ErrFriendSendMessageTooLong + | ErrFriendSendMessageEmpty + deriving (Eq, Ord, Enum, Bounded, Read, Show, Generic) +instance MessagePack ErrFriendSendMessage +instance Arbitrary ErrFriendSendMessage where arbitrary = arbitraryBoundedEnum +foreign import ccall tox_friend_send_message :: ToxPtr -> Word32 -> CEnum MessageType -> CString -> CSize -> CErr ErrFriendSendMessage -> IO Word32 +type FriendReadReceiptCb = ToxPtr -> Word32 -> Word32 -> Ptr () -> IO () +foreign import ccall "wrapper" wrapFriendReadReceiptCb :: FriendReadReceiptCb -> IO (FunPtr FriendReadReceiptCb) +foreign import ccall tox_callback_friend_read_receipt :: ToxPtr -> FunPtr FriendReadReceiptCb -> IO () +type FriendRequestCb = ToxPtr -> CString -> CString -> CSize -> Ptr () -> IO () +foreign import ccall "wrapper" wrapFriendRequestCb :: FriendRequestCb -> IO (FunPtr FriendRequestCb) +foreign import ccall tox_callback_friend_request :: ToxPtr -> FunPtr FriendRequestCb -> IO () +type FriendMessageCb = ToxPtr -> Word32 -> CEnum MessageType -> CString -> CSize -> Ptr () -> IO () +foreign import ccall "wrapper" wrapFriendMessageCb :: FriendMessageCb -> IO (FunPtr FriendMessageCb) +foreign import ccall tox_callback_friend_message :: ToxPtr -> FunPtr FriendMessageCb -> IO () +foreign import ccall tox_hash :: CString -> CString -> CSize -> IO Bool +data FileKind + = FileKindData + | FileKindAvatar + deriving (Eq, Ord, Enum, Bounded, Read, Show, Generic) +instance MessagePack FileKind +instance Arbitrary FileKind where arbitrary = arbitraryBoundedEnum +data FileControl + = FileControlResume + | FileControlPause + | FileControlCancel + deriving (Eq, Ord, Enum, Bounded, Read, Show, Generic) +instance MessagePack FileControl +instance Arbitrary FileControl where arbitrary = arbitraryBoundedEnum +data ErrFileControl + = ErrFileControlFriendNotFound + | ErrFileControlFriendNotConnected + | ErrFileControlNotFound + | ErrFileControlNotPaused + | ErrFileControlDenied + | ErrFileControlAlreadyPaused + | ErrFileControlSendq + deriving (Eq, Ord, Enum, Bounded, Read, Show, Generic) +instance MessagePack ErrFileControl +instance Arbitrary ErrFileControl where arbitrary = arbitraryBoundedEnum +foreign import ccall tox_file_control :: ToxPtr -> Word32 -> Word32 -> CEnum FileControl -> CErr ErrFileControl -> IO Bool +type FileRecvControlCb = ToxPtr -> Word32 -> Word32 -> CEnum FileControl -> Ptr () -> IO () +foreign import ccall "wrapper" wrapFileRecvControlCb :: FileRecvControlCb -> IO (FunPtr FileRecvControlCb) +foreign import ccall tox_callback_file_recv_control :: ToxPtr -> FunPtr FileRecvControlCb -> IO () +data ErrFileSeek + = ErrFileSeekFriendNotFound + | ErrFileSeekFriendNotConnected + | ErrFileSeekNotFound + | ErrFileSeekDenied + | ErrFileSeekInvalidPosition + | ErrFileSeekSendq + deriving (Eq, Ord, Enum, Bounded, Read, Show, Generic) +instance MessagePack ErrFileSeek +instance Arbitrary ErrFileSeek where arbitrary = arbitraryBoundedEnum +foreign import ccall tox_file_seek :: ToxPtr -> Word32 -> Word32 -> Word64 -> CErr ErrFileSeek -> IO Bool +data ErrFileGet + = ErrFileGetNull + | ErrFileGetFriendNotFound + | ErrFileGetNotFound + deriving (Eq, Ord, Enum, Bounded, Read, Show, Generic) +instance MessagePack ErrFileGet +instance Arbitrary ErrFileGet where arbitrary = arbitraryBoundedEnum +foreign import ccall tox_file_get_file_id :: ToxPtr -> Word32 -> Word32 -> CString -> CErr ErrFileGet -> IO Bool +data ErrFileSend + = ErrFileSendNull + | ErrFileSendFriendNotFound + | ErrFileSendFriendNotConnected + | ErrFileSendNameTooLong + | ErrFileSendTooMany + deriving (Eq, Ord, Enum, Bounded, Read, Show, Generic) +instance MessagePack ErrFileSend +instance Arbitrary ErrFileSend where arbitrary = arbitraryBoundedEnum +foreign import ccall tox_file_send :: ToxPtr -> Word32 -> Word32 -> Word64 -> CString -> CString -> CSize -> CErr ErrFileSend -> IO Word32 +data ErrFileSendChunk + = ErrFileSendChunkNull + | ErrFileSendChunkFriendNotFound + | ErrFileSendChunkFriendNotConnected + | ErrFileSendChunkNotFound + | ErrFileSendChunkNotTransferring + | ErrFileSendChunkInvalidLength + | ErrFileSendChunkSendq + | ErrFileSendChunkWrongPosition + deriving (Eq, Ord, Enum, Bounded, Read, Show, Generic) +instance MessagePack ErrFileSendChunk +instance Arbitrary ErrFileSendChunk where arbitrary = arbitraryBoundedEnum +foreign import ccall tox_file_send_chunk :: ToxPtr -> Word32 -> Word32 -> Word64 -> CString -> CSize -> CErr ErrFileSendChunk -> IO Bool +type FileChunkRequestCb = ToxPtr -> Word32 -> Word32 -> Word64 -> CSize -> Ptr () -> IO () +foreign import ccall "wrapper" wrapFileChunkRequestCb :: FileChunkRequestCb -> IO (FunPtr FileChunkRequestCb) +foreign import ccall tox_callback_file_chunk_request :: ToxPtr -> FunPtr FileChunkRequestCb -> IO () +type FileRecvCb = ToxPtr -> Word32 -> Word32 -> Word32 -> Word64 -> CString -> CSize -> Ptr () -> IO () +foreign import ccall "wrapper" wrapFileRecvCb :: FileRecvCb -> IO (FunPtr FileRecvCb) +foreign import ccall tox_callback_file_recv :: ToxPtr -> FunPtr FileRecvCb -> IO () +type FileRecvChunkCb = ToxPtr -> Word32 -> Word32 -> Word64 -> CString -> CSize -> Ptr () -> IO () +foreign import ccall "wrapper" wrapFileRecvChunkCb :: FileRecvChunkCb -> IO (FunPtr FileRecvChunkCb) +foreign import ccall tox_callback_file_recv_chunk :: ToxPtr -> FunPtr FileRecvChunkCb -> IO () +data ConferenceType + = ConferenceTypeText + | ConferenceTypeAv + deriving (Eq, Ord, Enum, Bounded, Read, Show, Generic) +instance MessagePack ConferenceType +instance Arbitrary ConferenceType where arbitrary = arbitraryBoundedEnum +type ConferenceInviteCb = ToxPtr -> Word32 -> CEnum ConferenceType -> CString -> CSize -> Ptr () -> IO () +foreign import ccall "wrapper" wrapConferenceInviteCb :: ConferenceInviteCb -> IO (FunPtr ConferenceInviteCb) +foreign import ccall tox_callback_conference_invite :: ToxPtr -> FunPtr ConferenceInviteCb -> IO () +type ConferenceConnectedCb = ToxPtr -> Word32 -> Ptr () -> IO () +foreign import ccall "wrapper" wrapConferenceConnectedCb :: ConferenceConnectedCb -> IO (FunPtr ConferenceConnectedCb) +foreign import ccall tox_callback_conference_connected :: ToxPtr -> FunPtr ConferenceConnectedCb -> IO () +type ConferenceMessageCb = ToxPtr -> Word32 -> Word32 -> CEnum MessageType -> CString -> CSize -> Ptr () -> IO () +foreign import ccall "wrapper" wrapConferenceMessageCb :: ConferenceMessageCb -> IO (FunPtr ConferenceMessageCb) +foreign import ccall tox_callback_conference_message :: ToxPtr -> FunPtr ConferenceMessageCb -> IO () +type ConferenceTitleCb = ToxPtr -> Word32 -> Word32 -> CString -> CSize -> Ptr () -> IO () +foreign import ccall "wrapper" wrapConferenceTitleCb :: ConferenceTitleCb -> IO (FunPtr ConferenceTitleCb) +foreign import ccall tox_callback_conference_title :: ToxPtr -> FunPtr ConferenceTitleCb -> IO () +type ConferencePeerNameCb = ToxPtr -> Word32 -> Word32 -> CString -> CSize -> Ptr () -> IO () +foreign import ccall "wrapper" wrapConferencePeerNameCb :: ConferencePeerNameCb -> IO (FunPtr ConferencePeerNameCb) +foreign import ccall tox_callback_conference_peer_name :: ToxPtr -> FunPtr ConferencePeerNameCb -> IO () +type ConferencePeerListChangedCb = ToxPtr -> Word32 -> Ptr () -> IO () +foreign import ccall "wrapper" wrapConferencePeerListChangedCb :: ConferencePeerListChangedCb -> IO (FunPtr ConferencePeerListChangedCb) +foreign import ccall tox_callback_conference_peer_list_changed :: ToxPtr -> FunPtr ConferencePeerListChangedCb -> IO () +data ErrConferenceNew + = ErrConferenceNewInit + deriving (Eq, Ord, Enum, Bounded, Read, Show, Generic) +instance MessagePack ErrConferenceNew +instance Arbitrary ErrConferenceNew where arbitrary = arbitraryBoundedEnum +foreign import ccall tox_conference_new :: ToxPtr -> CErr ErrConferenceNew -> IO Word32 +data ErrConferenceDelete + = ErrConferenceDeleteConferenceNotFound + deriving (Eq, Ord, Enum, Bounded, Read, Show, Generic) +instance MessagePack ErrConferenceDelete +instance Arbitrary ErrConferenceDelete where arbitrary = arbitraryBoundedEnum +foreign import ccall tox_conference_delete :: ToxPtr -> Word32 -> CErr ErrConferenceDelete -> IO Bool +data ErrConferencePeerQuery + = ErrConferencePeerQueryConferenceNotFound + | ErrConferencePeerQueryPeerNotFound + | ErrConferencePeerQueryNoConnection + deriving (Eq, Ord, Enum, Bounded, Read, Show, Generic) +instance MessagePack ErrConferencePeerQuery +instance Arbitrary ErrConferencePeerQuery where arbitrary = arbitraryBoundedEnum +foreign import ccall tox_conference_peer_count :: ToxPtr -> Word32 -> CErr ErrConferencePeerQuery -> IO Word32 +foreign import ccall tox_conference_peer_get_name_size :: ToxPtr -> Word32 -> Word32 -> CErr ErrConferencePeerQuery -> IO CSize +foreign import ccall tox_conference_peer_get_name :: ToxPtr -> Word32 -> Word32 -> CString -> CErr ErrConferencePeerQuery -> IO Bool +foreign import ccall tox_conference_peer_get_public_key :: ToxPtr -> Word32 -> Word32 -> CString -> CErr ErrConferencePeerQuery -> IO Bool +foreign import ccall tox_conference_peer_number_is_ours :: ToxPtr -> Word32 -> Word32 -> CErr ErrConferencePeerQuery -> IO Bool +foreign import ccall tox_conference_offline_peer_count :: ToxPtr -> Word32 -> CErr ErrConferencePeerQuery -> IO Word32 +foreign import ccall tox_conference_offline_peer_get_name_size :: ToxPtr -> Word32 -> Word32 -> CErr ErrConferencePeerQuery -> IO CSize +foreign import ccall tox_conference_offline_peer_get_name :: ToxPtr -> Word32 -> Word32 -> CString -> CErr ErrConferencePeerQuery -> IO Bool +foreign import ccall tox_conference_offline_peer_get_public_key :: ToxPtr -> Word32 -> Word32 -> CString -> CErr ErrConferencePeerQuery -> IO Bool +foreign import ccall tox_conference_offline_peer_get_last_active :: ToxPtr -> Word32 -> Word32 -> CErr ErrConferencePeerQuery -> IO Word64 +data ErrConferenceSetMaxOffline + = ErrConferenceSetMaxOfflineConferenceNotFound + deriving (Eq, Ord, Enum, Bounded, Read, Show, Generic) +instance MessagePack ErrConferenceSetMaxOffline +instance Arbitrary ErrConferenceSetMaxOffline where arbitrary = arbitraryBoundedEnum +foreign import ccall tox_conference_set_max_offline :: ToxPtr -> Word32 -> Word32 -> CErr ErrConferenceSetMaxOffline -> IO Bool +data ErrConferenceInvite + = ErrConferenceInviteConferenceNotFound + | ErrConferenceInviteFailSend + | ErrConferenceInviteNoConnection + deriving (Eq, Ord, Enum, Bounded, Read, Show, Generic) +instance MessagePack ErrConferenceInvite +instance Arbitrary ErrConferenceInvite where arbitrary = arbitraryBoundedEnum +foreign import ccall tox_conference_invite :: ToxPtr -> Word32 -> Word32 -> CErr ErrConferenceInvite -> IO Bool +data ErrConferenceJoin + = ErrConferenceJoinInvalidLength + | ErrConferenceJoinWrongType + | ErrConferenceJoinFriendNotFound + | ErrConferenceJoinDuplicate + | ErrConferenceJoinInitFail + | ErrConferenceJoinFailSend + deriving (Eq, Ord, Enum, Bounded, Read, Show, Generic) +instance MessagePack ErrConferenceJoin +instance Arbitrary ErrConferenceJoin where arbitrary = arbitraryBoundedEnum +foreign import ccall tox_conference_join :: ToxPtr -> Word32 -> CString -> CSize -> CErr ErrConferenceJoin -> IO Word32 +data ErrConferenceSendMessage + = ErrConferenceSendMessageConferenceNotFound + | ErrConferenceSendMessageTooLong + | ErrConferenceSendMessageNoConnection + | ErrConferenceSendMessageFailSend + deriving (Eq, Ord, Enum, Bounded, Read, Show, Generic) +instance MessagePack ErrConferenceSendMessage +instance Arbitrary ErrConferenceSendMessage where arbitrary = arbitraryBoundedEnum +foreign import ccall tox_conference_send_message :: ToxPtr -> Word32 -> CEnum MessageType -> CString -> CSize -> CErr ErrConferenceSendMessage -> IO Bool +data ErrConferenceTitle + = ErrConferenceTitleConferenceNotFound + | ErrConferenceTitleInvalidLength + | ErrConferenceTitleFailSend + deriving (Eq, Ord, Enum, Bounded, Read, Show, Generic) +instance MessagePack ErrConferenceTitle +instance Arbitrary ErrConferenceTitle where arbitrary = arbitraryBoundedEnum +foreign import ccall tox_conference_get_title_size :: ToxPtr -> Word32 -> CErr ErrConferenceTitle -> IO CSize +foreign import ccall tox_conference_get_title :: ToxPtr -> Word32 -> CString -> CErr ErrConferenceTitle -> IO Bool +foreign import ccall tox_conference_set_title :: ToxPtr -> Word32 -> CString -> CSize -> CErr ErrConferenceTitle -> IO Bool +foreign import ccall tox_conference_get_chatlist_size :: ToxPtr -> IO CSize +foreign import ccall tox_conference_get_chatlist :: ToxPtr -> Ptr Word32 -> IO () +data ErrConferenceGetType + = ErrConferenceGetTypeConferenceNotFound + deriving (Eq, Ord, Enum, Bounded, Read, Show, Generic) +instance MessagePack ErrConferenceGetType +instance Arbitrary ErrConferenceGetType where arbitrary = arbitraryBoundedEnum +foreign import ccall tox_conference_get_type :: ToxPtr -> Word32 -> CErr ErrConferenceGetType -> IO (CEnum ConferenceType) +foreign import ccall tox_conference_get_id :: ToxPtr -> Word32 -> CString -> IO Bool +data ErrConferenceById + = ErrConferenceByIdNull + | ErrConferenceByIdNotFound + deriving (Eq, Ord, Enum, Bounded, Read, Show, Generic) +instance MessagePack ErrConferenceById +instance Arbitrary ErrConferenceById where arbitrary = arbitraryBoundedEnum +foreign import ccall tox_conference_by_id :: ToxPtr -> CString -> CErr ErrConferenceById -> IO Word32 +foreign import ccall tox_conference_get_uid :: ToxPtr -> Word32 -> CString -> IO Bool +data ErrConferenceByUid + = ErrConferenceByUidNull + | ErrConferenceByUidNotFound + deriving (Eq, Ord, Enum, Bounded, Read, Show, Generic) +instance MessagePack ErrConferenceByUid +instance Arbitrary ErrConferenceByUid where arbitrary = arbitraryBoundedEnum +foreign import ccall tox_conference_by_uid :: ToxPtr -> CString -> CErr ErrConferenceByUid -> IO Word32 +data ErrFriendCustomPacket + = ErrFriendCustomPacketNull + | ErrFriendCustomPacketFriendNotFound + | ErrFriendCustomPacketFriendNotConnected + | ErrFriendCustomPacketInvalid + | ErrFriendCustomPacketEmpty + | ErrFriendCustomPacketTooLong + | ErrFriendCustomPacketSendq + deriving (Eq, Ord, Enum, Bounded, Read, Show, Generic) +instance MessagePack ErrFriendCustomPacket +instance Arbitrary ErrFriendCustomPacket where arbitrary = arbitraryBoundedEnum +foreign import ccall tox_friend_send_lossy_packet :: ToxPtr -> Word32 -> CString -> CSize -> CErr ErrFriendCustomPacket -> IO Bool +foreign import ccall tox_friend_send_lossless_packet :: ToxPtr -> Word32 -> CString -> CSize -> CErr ErrFriendCustomPacket -> IO Bool +type FriendLossyPacketCb = ToxPtr -> Word32 -> CString -> CSize -> Ptr () -> IO () +foreign import ccall "wrapper" wrapFriendLossyPacketCb :: FriendLossyPacketCb -> IO (FunPtr FriendLossyPacketCb) +foreign import ccall tox_callback_friend_lossy_packet :: ToxPtr -> FunPtr FriendLossyPacketCb -> IO () +type FriendLosslessPacketCb = ToxPtr -> Word32 -> CString -> CSize -> Ptr () -> IO () +foreign import ccall "wrapper" wrapFriendLosslessPacketCb :: FriendLosslessPacketCb -> IO (FunPtr FriendLosslessPacketCb) +foreign import ccall tox_callback_friend_lossless_packet :: ToxPtr -> FunPtr FriendLosslessPacketCb -> IO () +data ErrGetPort + = ErrGetPortNotBound + deriving (Eq, Ord, Enum, Bounded, Read, Show, Generic) +instance MessagePack ErrGetPort +instance Arbitrary ErrGetPort where arbitrary = arbitraryBoundedEnum +foreign import ccall tox_self_get_dht_id :: ToxPtr -> CString -> IO () +foreign import ccall tox_self_get_udp_port :: ToxPtr -> CErr ErrGetPort -> IO Word16 +foreign import ccall tox_self_get_tcp_port :: ToxPtr -> CErr ErrGetPort -> IO Word16 +foreign import ccall tox_group_max_topic_length :: Word32 +foreign import ccall tox_group_max_part_length :: Word32 +foreign import ccall tox_group_max_message_length :: Word32 +foreign import ccall tox_group_max_custom_lossy_packet_length :: Word32 +foreign import ccall tox_group_max_custom_lossless_packet_length :: Word32 +foreign import ccall tox_group_max_group_name_length :: Word32 +foreign import ccall tox_group_max_password_size :: Word32 +foreign import ccall tox_group_chat_id_size :: Word32 +foreign import ccall tox_group_peer_public_key_size :: Word32 +data GroupPrivacyState + = GroupPrivacyStatePublic + | GroupPrivacyStatePrivate + deriving (Eq, Ord, Enum, Bounded, Read, Show, Generic) +instance MessagePack GroupPrivacyState +instance Arbitrary GroupPrivacyState where arbitrary = arbitraryBoundedEnum +data GroupTopicLock + = GroupTopicLockEnabled + | GroupTopicLockDisabled + deriving (Eq, Ord, Enum, Bounded, Read, Show, Generic) +instance MessagePack GroupTopicLock +instance Arbitrary GroupTopicLock where arbitrary = arbitraryBoundedEnum +data GroupVoiceState + = GroupVoiceStateAll + | GroupVoiceStateModerator + | GroupVoiceStateFounder + deriving (Eq, Ord, Enum, Bounded, Read, Show, Generic) +instance MessagePack GroupVoiceState +instance Arbitrary GroupVoiceState where arbitrary = arbitraryBoundedEnum +data GroupRole + = GroupRoleFounder + | GroupRoleModerator + | GroupRoleUser + | GroupRoleObserver + deriving (Eq, Ord, Enum, Bounded, Read, Show, Generic) +instance MessagePack GroupRole +instance Arbitrary GroupRole where arbitrary = arbitraryBoundedEnum +data ErrGroupNew + = ErrGroupNewTooLong + | ErrGroupNewEmpty + | ErrGroupNewInit + | ErrGroupNewState + | ErrGroupNewAnnounce + deriving (Eq, Ord, Enum, Bounded, Read, Show, Generic) +instance MessagePack ErrGroupNew +instance Arbitrary ErrGroupNew where arbitrary = arbitraryBoundedEnum +foreign import ccall tox_group_new :: ToxPtr -> CEnum GroupPrivacyState -> CString -> CSize -> CString -> CSize -> CErr ErrGroupNew -> IO Word32 +data ErrGroupJoin + = ErrGroupJoinInit + | ErrGroupJoinBadChatId + | ErrGroupJoinEmpty + | ErrGroupJoinTooLong + | ErrGroupJoinPassword + | ErrGroupJoinCore + deriving (Eq, Ord, Enum, Bounded, Read, Show, Generic) +instance MessagePack ErrGroupJoin +instance Arbitrary ErrGroupJoin where arbitrary = arbitraryBoundedEnum +foreign import ccall tox_group_join :: ToxPtr -> CString -> CString -> CSize -> CString -> CSize -> CErr ErrGroupJoin -> IO Word32 +data ErrGroupIsConnected + = ErrGroupIsConnectedGroupNotFound + deriving (Eq, Ord, Enum, Bounded, Read, Show, Generic) +instance MessagePack ErrGroupIsConnected +instance Arbitrary ErrGroupIsConnected where arbitrary = arbitraryBoundedEnum +foreign import ccall tox_group_is_connected :: ToxPtr -> Word32 -> CErr ErrGroupIsConnected -> IO Bool +data ErrGroupDisconnect + = ErrGroupDisconnectGroupNotFound + | ErrGroupDisconnectAlreadyDisconnected + deriving (Eq, Ord, Enum, Bounded, Read, Show, Generic) +instance MessagePack ErrGroupDisconnect +instance Arbitrary ErrGroupDisconnect where arbitrary = arbitraryBoundedEnum +foreign import ccall tox_group_disconnect :: ToxPtr -> Word32 -> CErr ErrGroupDisconnect -> IO Bool +data ErrGroupReconnect + = ErrGroupReconnectGroupNotFound + | ErrGroupReconnectCore + deriving (Eq, Ord, Enum, Bounded, Read, Show, Generic) +instance MessagePack ErrGroupReconnect +instance Arbitrary ErrGroupReconnect where arbitrary = arbitraryBoundedEnum +foreign import ccall tox_group_reconnect :: ToxPtr -> Word32 -> CErr ErrGroupReconnect -> IO Bool +data ErrGroupLeave + = ErrGroupLeaveGroupNotFound + | ErrGroupLeaveTooLong + | ErrGroupLeaveFailSend + deriving (Eq, Ord, Enum, Bounded, Read, Show, Generic) +instance MessagePack ErrGroupLeave +instance Arbitrary ErrGroupLeave where arbitrary = arbitraryBoundedEnum +foreign import ccall tox_group_leave :: ToxPtr -> Word32 -> CString -> CSize -> CErr ErrGroupLeave -> IO Bool +data ErrGroupSelfQuery + = ErrGroupSelfQueryGroupNotFound + deriving (Eq, Ord, Enum, Bounded, Read, Show, Generic) +instance MessagePack ErrGroupSelfQuery +instance Arbitrary ErrGroupSelfQuery where arbitrary = arbitraryBoundedEnum +data ErrGroupSelfNameSet + = ErrGroupSelfNameSetGroupNotFound + | ErrGroupSelfNameSetTooLong + | ErrGroupSelfNameSetInvalid + | ErrGroupSelfNameSetFailSend + deriving (Eq, Ord, Enum, Bounded, Read, Show, Generic) +instance MessagePack ErrGroupSelfNameSet +instance Arbitrary ErrGroupSelfNameSet where arbitrary = arbitraryBoundedEnum +foreign import ccall tox_group_self_set_name :: ToxPtr -> Word32 -> CString -> CSize -> CErr ErrGroupSelfNameSet -> IO Bool +foreign import ccall tox_group_self_get_name_size :: ToxPtr -> Word32 -> CErr ErrGroupSelfQuery -> IO CSize +foreign import ccall tox_group_self_get_name :: ToxPtr -> Word32 -> CString -> CErr ErrGroupSelfQuery -> IO Bool +data ErrGroupSelfStatusSet + = ErrGroupSelfStatusSetGroupNotFound + | ErrGroupSelfStatusSetFailSend + deriving (Eq, Ord, Enum, Bounded, Read, Show, Generic) +instance MessagePack ErrGroupSelfStatusSet +instance Arbitrary ErrGroupSelfStatusSet where arbitrary = arbitraryBoundedEnum +foreign import ccall tox_group_self_set_status :: ToxPtr -> Word32 -> CEnum UserStatus -> CErr ErrGroupSelfStatusSet -> IO Bool +foreign import ccall tox_group_self_get_status :: ToxPtr -> Word32 -> CErr ErrGroupSelfQuery -> IO (CEnum UserStatus) +foreign import ccall tox_group_self_get_role :: ToxPtr -> Word32 -> CErr ErrGroupSelfQuery -> IO (CEnum GroupRole) +foreign import ccall tox_group_self_get_peer_id :: ToxPtr -> Word32 -> CErr ErrGroupSelfQuery -> IO Word32 +foreign import ccall tox_group_self_get_public_key :: ToxPtr -> Word32 -> CString -> CErr ErrGroupSelfQuery -> IO Bool +data ErrGroupPeerQuery + = ErrGroupPeerQueryGroupNotFound + | ErrGroupPeerQueryPeerNotFound + deriving (Eq, Ord, Enum, Bounded, Read, Show, Generic) +instance MessagePack ErrGroupPeerQuery +instance Arbitrary ErrGroupPeerQuery where arbitrary = arbitraryBoundedEnum +foreign import ccall tox_group_peer_get_name_size :: ToxPtr -> Word32 -> Word32 -> CErr ErrGroupPeerQuery -> IO CSize +foreign import ccall tox_group_peer_get_name :: ToxPtr -> Word32 -> Word32 -> CString -> CErr ErrGroupPeerQuery -> IO Bool +foreign import ccall tox_group_peer_get_status :: ToxPtr -> Word32 -> Word32 -> CErr ErrGroupPeerQuery -> IO (CEnum UserStatus) +foreign import ccall tox_group_peer_get_role :: ToxPtr -> Word32 -> Word32 -> CErr ErrGroupPeerQuery -> IO (CEnum GroupRole) +foreign import ccall tox_group_peer_get_connection_status :: ToxPtr -> Word32 -> Word32 -> CErr ErrGroupPeerQuery -> IO (CEnum Connection) +foreign import ccall tox_group_peer_get_public_key :: ToxPtr -> Word32 -> Word32 -> CString -> CErr ErrGroupPeerQuery -> IO Bool +type GroupPeerNameCb = ToxPtr -> Word32 -> Word32 -> CString -> CSize -> Ptr () -> IO () +foreign import ccall "wrapper" wrapGroupPeerNameCb :: GroupPeerNameCb -> IO (FunPtr GroupPeerNameCb) +foreign import ccall tox_callback_group_peer_name :: ToxPtr -> FunPtr GroupPeerNameCb -> IO () +type GroupPeerStatusCb = ToxPtr -> Word32 -> Word32 -> CEnum UserStatus -> Ptr () -> IO () +foreign import ccall "wrapper" wrapGroupPeerStatusCb :: GroupPeerStatusCb -> IO (FunPtr GroupPeerStatusCb) +foreign import ccall tox_callback_group_peer_status :: ToxPtr -> FunPtr GroupPeerStatusCb -> IO () +data ErrGroupStateQueries + = ErrGroupStateQueriesGroupNotFound + deriving (Eq, Ord, Enum, Bounded, Read, Show, Generic) +instance MessagePack ErrGroupStateQueries +instance Arbitrary ErrGroupStateQueries where arbitrary = arbitraryBoundedEnum +data ErrGroupTopicSet + = ErrGroupTopicSetGroupNotFound + | ErrGroupTopicSetTooLong + | ErrGroupTopicSetPermissions + | ErrGroupTopicSetFailCreate + | ErrGroupTopicSetFailSend + | ErrGroupTopicSetDisconnected + deriving (Eq, Ord, Enum, Bounded, Read, Show, Generic) +instance MessagePack ErrGroupTopicSet +instance Arbitrary ErrGroupTopicSet where arbitrary = arbitraryBoundedEnum +foreign import ccall tox_group_set_topic :: ToxPtr -> Word32 -> CString -> CSize -> CErr ErrGroupTopicSet -> IO Bool +foreign import ccall tox_group_get_topic_size :: ToxPtr -> Word32 -> CErr ErrGroupStateQueries -> IO CSize +foreign import ccall tox_group_get_topic :: ToxPtr -> Word32 -> CString -> CErr ErrGroupStateQueries -> IO Bool +type GroupTopicCb = ToxPtr -> Word32 -> Word32 -> CString -> CSize -> Ptr () -> IO () +foreign import ccall "wrapper" wrapGroupTopicCb :: GroupTopicCb -> IO (FunPtr GroupTopicCb) +foreign import ccall tox_callback_group_topic :: ToxPtr -> FunPtr GroupTopicCb -> IO () +foreign import ccall tox_group_get_name_size :: ToxPtr -> Word32 -> CErr ErrGroupStateQueries -> IO CSize +foreign import ccall tox_group_get_name :: ToxPtr -> Word32 -> CString -> CErr ErrGroupStateQueries -> IO Bool +foreign import ccall tox_group_get_chat_id :: ToxPtr -> Word32 -> CString -> CErr ErrGroupStateQueries -> IO Bool +foreign import ccall tox_group_get_number_groups :: ToxPtr -> IO Word32 +foreign import ccall tox_group_get_privacy_state :: ToxPtr -> Word32 -> CErr ErrGroupStateQueries -> IO (CEnum GroupPrivacyState) +type GroupPrivacyStateCb = ToxPtr -> Word32 -> CEnum GroupPrivacyState -> Ptr () -> IO () +foreign import ccall "wrapper" wrapGroupPrivacyStateCb :: GroupPrivacyStateCb -> IO (FunPtr GroupPrivacyStateCb) +foreign import ccall tox_callback_group_privacy_state :: ToxPtr -> FunPtr GroupPrivacyStateCb -> IO () +foreign import ccall tox_group_get_voice_state :: ToxPtr -> Word32 -> CErr ErrGroupStateQueries -> IO (CEnum GroupVoiceState) +type GroupVoiceStateCb = ToxPtr -> Word32 -> CEnum GroupVoiceState -> Ptr () -> IO () +foreign import ccall "wrapper" wrapGroupVoiceStateCb :: GroupVoiceStateCb -> IO (FunPtr GroupVoiceStateCb) +foreign import ccall tox_callback_group_voice_state :: ToxPtr -> FunPtr GroupVoiceStateCb -> IO () +foreign import ccall tox_group_get_topic_lock :: ToxPtr -> Word32 -> CErr ErrGroupStateQueries -> IO (CEnum GroupTopicLock) +type GroupTopicLockCb = ToxPtr -> Word32 -> CEnum GroupTopicLock -> Ptr () -> IO () +foreign import ccall "wrapper" wrapGroupTopicLockCb :: GroupTopicLockCb -> IO (FunPtr GroupTopicLockCb) +foreign import ccall tox_callback_group_topic_lock :: ToxPtr -> FunPtr GroupTopicLockCb -> IO () +foreign import ccall tox_group_get_peer_limit :: ToxPtr -> Word32 -> CErr ErrGroupStateQueries -> IO Word16 +type GroupPeerLimitCb = ToxPtr -> Word32 -> Word32 -> Ptr () -> IO () +foreign import ccall "wrapper" wrapGroupPeerLimitCb :: GroupPeerLimitCb -> IO (FunPtr GroupPeerLimitCb) +foreign import ccall tox_callback_group_peer_limit :: ToxPtr -> FunPtr GroupPeerLimitCb -> IO () +foreign import ccall tox_group_get_password_size :: ToxPtr -> Word32 -> CErr ErrGroupStateQueries -> IO CSize +foreign import ccall tox_group_get_password :: ToxPtr -> Word32 -> CString -> CErr ErrGroupStateQueries -> IO Bool +type GroupPasswordCb = ToxPtr -> Word32 -> CString -> CSize -> Ptr () -> IO () +foreign import ccall "wrapper" wrapGroupPasswordCb :: GroupPasswordCb -> IO (FunPtr GroupPasswordCb) +foreign import ccall tox_callback_group_password :: ToxPtr -> FunPtr GroupPasswordCb -> IO () +data ErrGroupSendMessage + = ErrGroupSendMessageGroupNotFound + | ErrGroupSendMessageTooLong + | ErrGroupSendMessageEmpty + | ErrGroupSendMessageBadType + | ErrGroupSendMessagePermissions + | ErrGroupSendMessageFailSend + | ErrGroupSendMessageDisconnected + deriving (Eq, Ord, Enum, Bounded, Read, Show, Generic) +instance MessagePack ErrGroupSendMessage +instance Arbitrary ErrGroupSendMessage where arbitrary = arbitraryBoundedEnum +foreign import ccall tox_group_send_message :: ToxPtr -> Word32 -> CEnum MessageType -> CString -> CSize -> Ptr Word32 -> CErr ErrGroupSendMessage -> IO Bool +data ErrGroupSendPrivateMessage + = ErrGroupSendPrivateMessageGroupNotFound + | ErrGroupSendPrivateMessagePeerNotFound + | ErrGroupSendPrivateMessageTooLong + | ErrGroupSendPrivateMessageEmpty + | ErrGroupSendPrivateMessagePermissions + | ErrGroupSendPrivateMessageFailSend + | ErrGroupSendPrivateMessageDisconnected + | ErrGroupSendPrivateMessageBadType + deriving (Eq, Ord, Enum, Bounded, Read, Show, Generic) +instance MessagePack ErrGroupSendPrivateMessage +instance Arbitrary ErrGroupSendPrivateMessage where arbitrary = arbitraryBoundedEnum +foreign import ccall tox_group_send_private_message :: ToxPtr -> Word32 -> Word32 -> CEnum MessageType -> CString -> CSize -> CErr ErrGroupSendPrivateMessage -> IO Bool +data ErrGroupSendCustomPacket + = ErrGroupSendCustomPacketGroupNotFound + | ErrGroupSendCustomPacketTooLong + | ErrGroupSendCustomPacketEmpty + | ErrGroupSendCustomPacketPermissions + | ErrGroupSendCustomPacketDisconnected + deriving (Eq, Ord, Enum, Bounded, Read, Show, Generic) +instance MessagePack ErrGroupSendCustomPacket +instance Arbitrary ErrGroupSendCustomPacket where arbitrary = arbitraryBoundedEnum +foreign import ccall tox_group_send_custom_packet :: ToxPtr -> Word32 -> Bool -> CString -> CSize -> CErr ErrGroupSendCustomPacket -> IO Bool +data ErrGroupSendCustomPrivatePacket + = ErrGroupSendCustomPrivatePacketGroupNotFound + | ErrGroupSendCustomPrivatePacketTooLong + | ErrGroupSendCustomPrivatePacketEmpty + | ErrGroupSendCustomPrivatePacketPeerNotFound + | ErrGroupSendCustomPrivatePacketPermissions + | ErrGroupSendCustomPrivatePacketFailSend + | ErrGroupSendCustomPrivatePacketDisconnected + deriving (Eq, Ord, Enum, Bounded, Read, Show, Generic) +instance MessagePack ErrGroupSendCustomPrivatePacket +instance Arbitrary ErrGroupSendCustomPrivatePacket where arbitrary = arbitraryBoundedEnum +foreign import ccall tox_group_send_custom_private_packet :: ToxPtr -> Word32 -> Word32 -> Bool -> CString -> CSize -> CErr ErrGroupSendCustomPrivatePacket -> IO Bool +type GroupMessageCb = ToxPtr -> Word32 -> Word32 -> CEnum MessageType -> CString -> CSize -> Word32 -> Ptr () -> IO () +foreign import ccall "wrapper" wrapGroupMessageCb :: GroupMessageCb -> IO (FunPtr GroupMessageCb) +foreign import ccall tox_callback_group_message :: ToxPtr -> FunPtr GroupMessageCb -> IO () +type GroupPrivateMessageCb = ToxPtr -> Word32 -> Word32 -> CEnum MessageType -> CString -> CSize -> Ptr () -> IO () +foreign import ccall "wrapper" wrapGroupPrivateMessageCb :: GroupPrivateMessageCb -> IO (FunPtr GroupPrivateMessageCb) +foreign import ccall tox_callback_group_private_message :: ToxPtr -> FunPtr GroupPrivateMessageCb -> IO () +type GroupCustomPacketCb = ToxPtr -> Word32 -> Word32 -> CString -> CSize -> Ptr () -> IO () +foreign import ccall "wrapper" wrapGroupCustomPacketCb :: GroupCustomPacketCb -> IO (FunPtr GroupCustomPacketCb) +foreign import ccall tox_callback_group_custom_packet :: ToxPtr -> FunPtr GroupCustomPacketCb -> IO () +type GroupCustomPrivatePacketCb = ToxPtr -> Word32 -> Word32 -> CString -> CSize -> Ptr () -> IO () +foreign import ccall "wrapper" wrapGroupCustomPrivatePacketCb :: GroupCustomPrivatePacketCb -> IO (FunPtr GroupCustomPrivatePacketCb) +foreign import ccall tox_callback_group_custom_private_packet :: ToxPtr -> FunPtr GroupCustomPrivatePacketCb -> IO () +data ErrGroupInviteFriend + = ErrGroupInviteFriendGroupNotFound + | ErrGroupInviteFriendFriendNotFound + | ErrGroupInviteFriendInviteFail + | ErrGroupInviteFriendFailSend + | ErrGroupInviteFriendDisconnected + deriving (Eq, Ord, Enum, Bounded, Read, Show, Generic) +instance MessagePack ErrGroupInviteFriend +instance Arbitrary ErrGroupInviteFriend where arbitrary = arbitraryBoundedEnum +foreign import ccall tox_group_invite_friend :: ToxPtr -> Word32 -> Word32 -> CErr ErrGroupInviteFriend -> IO Bool +data ErrGroupInviteAccept + = ErrGroupInviteAcceptBadInvite + | ErrGroupInviteAcceptInitFailed + | ErrGroupInviteAcceptTooLong + | ErrGroupInviteAcceptEmpty + | ErrGroupInviteAcceptPassword + | ErrGroupInviteAcceptCore + | ErrGroupInviteAcceptFailSend + deriving (Eq, Ord, Enum, Bounded, Read, Show, Generic) +instance MessagePack ErrGroupInviteAccept +instance Arbitrary ErrGroupInviteAccept where arbitrary = arbitraryBoundedEnum +foreign import ccall tox_group_invite_accept :: ToxPtr -> Word32 -> CString -> CSize -> CString -> CSize -> CString -> CSize -> CErr ErrGroupInviteAccept -> IO Word32 +type GroupInviteCb = ToxPtr -> Word32 -> CString -> CSize -> CString -> CSize -> Ptr () -> IO () +foreign import ccall "wrapper" wrapGroupInviteCb :: GroupInviteCb -> IO (FunPtr GroupInviteCb) +foreign import ccall tox_callback_group_invite :: ToxPtr -> FunPtr GroupInviteCb -> IO () +type GroupPeerJoinCb = ToxPtr -> Word32 -> Word32 -> Ptr () -> IO () +foreign import ccall "wrapper" wrapGroupPeerJoinCb :: GroupPeerJoinCb -> IO (FunPtr GroupPeerJoinCb) +foreign import ccall tox_callback_group_peer_join :: ToxPtr -> FunPtr GroupPeerJoinCb -> IO () +data GroupExitType + = GroupExitTypeQuit + | GroupExitTypeTimeout + | GroupExitTypeDisconnected + | GroupExitTypeSelfDisconnected + | GroupExitTypeKick + | GroupExitTypeSyncError + deriving (Eq, Ord, Enum, Bounded, Read, Show, Generic) +instance MessagePack GroupExitType +instance Arbitrary GroupExitType where arbitrary = arbitraryBoundedEnum +type GroupPeerExitCb = ToxPtr -> Word32 -> Word32 -> CEnum GroupExitType -> CString -> CSize -> CString -> CSize -> Ptr () -> IO () +foreign import ccall "wrapper" wrapGroupPeerExitCb :: GroupPeerExitCb -> IO (FunPtr GroupPeerExitCb) +foreign import ccall tox_callback_group_peer_exit :: ToxPtr -> FunPtr GroupPeerExitCb -> IO () +type GroupSelfJoinCb = ToxPtr -> Word32 -> Ptr () -> IO () +foreign import ccall "wrapper" wrapGroupSelfJoinCb :: GroupSelfJoinCb -> IO (FunPtr GroupSelfJoinCb) +foreign import ccall tox_callback_group_self_join :: ToxPtr -> FunPtr GroupSelfJoinCb -> IO () +data GroupJoinFail + = GroupJoinFailPeerLimit + | GroupJoinFailInvalidPassword + | GroupJoinFailUnknown + deriving (Eq, Ord, Enum, Bounded, Read, Show, Generic) +instance MessagePack GroupJoinFail +instance Arbitrary GroupJoinFail where arbitrary = arbitraryBoundedEnum +type GroupJoinFailCb = ToxPtr -> Word32 -> CEnum GroupJoinFail -> Ptr () -> IO () +foreign import ccall "wrapper" wrapGroupJoinFailCb :: GroupJoinFailCb -> IO (FunPtr GroupJoinFailCb) +foreign import ccall tox_callback_group_join_fail :: ToxPtr -> FunPtr GroupJoinFailCb -> IO () +data ErrGroupFounderSetPassword + = ErrGroupFounderSetPasswordGroupNotFound + | ErrGroupFounderSetPasswordPermissions + | ErrGroupFounderSetPasswordTooLong + | ErrGroupFounderSetPasswordFailSend + | ErrGroupFounderSetPasswordMalloc + | ErrGroupFounderSetPasswordDisconnected + deriving (Eq, Ord, Enum, Bounded, Read, Show, Generic) +instance MessagePack ErrGroupFounderSetPassword +instance Arbitrary ErrGroupFounderSetPassword where arbitrary = arbitraryBoundedEnum +foreign import ccall tox_group_founder_set_password :: ToxPtr -> Word32 -> CString -> CSize -> CErr ErrGroupFounderSetPassword -> IO Bool +data ErrGroupFounderSetTopicLock + = ErrGroupFounderSetTopicLockGroupNotFound + | ErrGroupFounderSetTopicLockInvalid + | ErrGroupFounderSetTopicLockPermissions + | ErrGroupFounderSetTopicLockFailSet + | ErrGroupFounderSetTopicLockFailSend + | ErrGroupFounderSetTopicLockDisconnected + deriving (Eq, Ord, Enum, Bounded, Read, Show, Generic) +instance MessagePack ErrGroupFounderSetTopicLock +instance Arbitrary ErrGroupFounderSetTopicLock where arbitrary = arbitraryBoundedEnum +foreign import ccall tox_group_founder_set_topic_lock :: ToxPtr -> Word32 -> CEnum GroupTopicLock -> CErr ErrGroupFounderSetTopicLock -> IO Bool +data ErrGroupFounderSetVoiceState + = ErrGroupFounderSetVoiceStateGroupNotFound + | ErrGroupFounderSetVoiceStatePermissions + | ErrGroupFounderSetVoiceStateFailSet + | ErrGroupFounderSetVoiceStateFailSend + | ErrGroupFounderSetVoiceStateDisconnected + deriving (Eq, Ord, Enum, Bounded, Read, Show, Generic) +instance MessagePack ErrGroupFounderSetVoiceState +instance Arbitrary ErrGroupFounderSetVoiceState where arbitrary = arbitraryBoundedEnum +foreign import ccall tox_group_founder_set_voice_state :: ToxPtr -> Word32 -> CEnum GroupVoiceState -> CErr ErrGroupFounderSetVoiceState -> IO Bool +data ErrGroupFounderSetPrivacyState + = ErrGroupFounderSetPrivacyStateGroupNotFound + | ErrGroupFounderSetPrivacyStatePermissions + | ErrGroupFounderSetPrivacyStateFailSet + | ErrGroupFounderSetPrivacyStateFailSend + | ErrGroupFounderSetPrivacyStateDisconnected + deriving (Eq, Ord, Enum, Bounded, Read, Show, Generic) +instance MessagePack ErrGroupFounderSetPrivacyState +instance Arbitrary ErrGroupFounderSetPrivacyState where arbitrary = arbitraryBoundedEnum +foreign import ccall tox_group_founder_set_privacy_state :: ToxPtr -> Word32 -> CEnum GroupPrivacyState -> CErr ErrGroupFounderSetPrivacyState -> IO Bool +data ErrGroupFounderSetPeerLimit + = ErrGroupFounderSetPeerLimitGroupNotFound + | ErrGroupFounderSetPeerLimitPermissions + | ErrGroupFounderSetPeerLimitFailSet + | ErrGroupFounderSetPeerLimitFailSend + | ErrGroupFounderSetPeerLimitDisconnected + deriving (Eq, Ord, Enum, Bounded, Read, Show, Generic) +instance MessagePack ErrGroupFounderSetPeerLimit +instance Arbitrary ErrGroupFounderSetPeerLimit where arbitrary = arbitraryBoundedEnum +foreign import ccall tox_group_founder_set_peer_limit :: ToxPtr -> Word32 -> Word16 -> CErr ErrGroupFounderSetPeerLimit -> IO Bool +data ErrGroupSetIgnore + = ErrGroupSetIgnoreGroupNotFound + | ErrGroupSetIgnorePeerNotFound + | ErrGroupSetIgnoreSelf + deriving (Eq, Ord, Enum, Bounded, Read, Show, Generic) +instance MessagePack ErrGroupSetIgnore +instance Arbitrary ErrGroupSetIgnore where arbitrary = arbitraryBoundedEnum +foreign import ccall tox_group_set_ignore :: ToxPtr -> Word32 -> Word32 -> Bool -> CErr ErrGroupSetIgnore -> IO Bool +data ErrGroupModSetRole + = ErrGroupModSetRoleGroupNotFound + | ErrGroupModSetRolePeerNotFound + | ErrGroupModSetRolePermissions + | ErrGroupModSetRoleAssignment + | ErrGroupModSetRoleFailAction + | ErrGroupModSetRoleSelf + deriving (Eq, Ord, Enum, Bounded, Read, Show, Generic) +instance MessagePack ErrGroupModSetRole +instance Arbitrary ErrGroupModSetRole where arbitrary = arbitraryBoundedEnum +foreign import ccall tox_group_mod_set_role :: ToxPtr -> Word32 -> Word32 -> CEnum GroupRole -> CErr ErrGroupModSetRole -> IO Bool +data ErrGroupModKickPeer + = ErrGroupModKickPeerGroupNotFound + | ErrGroupModKickPeerPeerNotFound + | ErrGroupModKickPeerPermissions + | ErrGroupModKickPeerFailAction + | ErrGroupModKickPeerFailSend + | ErrGroupModKickPeerSelf + deriving (Eq, Ord, Enum, Bounded, Read, Show, Generic) +instance MessagePack ErrGroupModKickPeer +instance Arbitrary ErrGroupModKickPeer where arbitrary = arbitraryBoundedEnum +foreign import ccall tox_group_mod_kick_peer :: ToxPtr -> Word32 -> Word32 -> CErr ErrGroupModKickPeer -> IO Bool +data GroupModEvent + = GroupModEventKick + | GroupModEventObserver + | GroupModEventUser + | GroupModEventModerator + deriving (Eq, Ord, Enum, Bounded, Read, Show, Generic) +instance MessagePack GroupModEvent +instance Arbitrary GroupModEvent where arbitrary = arbitraryBoundedEnum +type GroupModerationCb = ToxPtr -> Word32 -> Word32 -> Word32 -> CEnum GroupModEvent -> Ptr () -> IO () +foreign import ccall "wrapper" wrapGroupModerationCb :: GroupModerationCb -> IO (FunPtr GroupModerationCb) +foreign import ccall tox_callback_group_moderation :: ToxPtr -> FunPtr GroupModerationCb -> IO () diff --git a/src/Network/Tox/C/CEnum.hs b/src/Foreign/C/Enum.hs similarity index 96% rename from src/Network/Tox/C/CEnum.hs rename to src/Foreign/C/Enum.hs index 8cf6d92..bb8c125 100644 --- a/src/Network/Tox/C/CEnum.hs +++ b/src/Foreign/C/Enum.hs @@ -1,7 +1,7 @@ {-# LANGUAGE GeneralizedNewtypeDeriving #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE StrictData #-} -module Network.Tox.C.CEnum where +module Foreign.C.Enum where import Foreign.C.Types (CInt) import Foreign.Marshal.Alloc (alloca) diff --git a/src/Network/Tox/C.hs b/src/Network/Tox/C.hs index f1cd09d..2662f2b 100644 --- a/src/Network/Tox/C.hs +++ b/src/Network/Tox/C.hs @@ -2,6 +2,36 @@ module Network.Tox.C ( module M ) where +import FFI.Tox.Tox as M (Connection (..), + ErrBootstrap (..), + ErrConferenceDelete (..), + ErrConferenceGetType (..), + ErrConferenceInvite (..), + ErrConferenceJoin (..), + ErrConferenceNew (..), + ErrConferencePeerQuery (..), + ErrConferenceSendMessage (..), + ErrConferenceTitle (..), + ErrFileControl (..), + ErrFileGet (..), + ErrFileSeek (..), + ErrFileSend (..), + ErrFileSendChunk (..), + ErrFriendAdd (..), + ErrFriendByPublicKey (..), + ErrFriendCustomPacket (..), + ErrFriendDelete (..), + ErrFriendGetLastOnline (..), + ErrFriendGetPublicKey (..), + ErrFriendQuery (..), + ErrFriendSendMessage (..), + ErrGetPort (..), ErrNew (..), + ErrSetInfo (..), + ErrSetTyping (..), + FileKind (..), LogLevel (..), + MessageType (..), + ProxyType (..), + SavedataType (..), ToxPtr) import Network.Tox.C.Constants as M import Network.Tox.C.Options as M import Network.Tox.C.Tox as M diff --git a/src/Network/Tox/C/Options.hs b/src/Network/Tox/C/Options.hs index a9a00ec..1d0ee46 100644 --- a/src/Network/Tox/C/Options.hs +++ b/src/Network/Tox/C/Options.hs @@ -3,16 +3,40 @@ {-# LANGUAGE StrictData #-} module Network.Tox.C.Options where -import Control.Exception (bracket) -import Data.ByteString (ByteString) -import qualified Data.ByteString as BS -import Data.Word (Word16, Word32) -import Foreign.C.String (CString, peekCString, withCString) -import Foreign.C.Types (CInt (..), CSize (..)) -import Foreign.Ptr (FunPtr, Ptr, nullPtr) -import GHC.Generics (Generic) - -import Network.Tox.C.CEnum +import Control.Exception (bracket) +import Data.ByteString (ByteString) +import qualified Data.ByteString as BS +import Data.Word (Word16) +import Foreign.C.Enum +import Foreign.C.String (peekCString, withCString) +import Foreign.Ptr (nullPtr) +import GHC.Generics (Generic) + +import FFI.Tox.Tox (LogCb, LogLevel (..), OptionsPtr, + ProxyType (..), SavedataType (..), + tox_options_get_end_port, + tox_options_get_ipv6_enabled, + tox_options_get_proxy_host, + tox_options_get_proxy_port, + tox_options_get_proxy_type, + tox_options_get_savedata_data, + tox_options_get_savedata_length, + tox_options_get_savedata_type, + tox_options_get_start_port, + tox_options_get_tcp_port, + tox_options_get_udp_enabled, + tox_options_set_end_port, + tox_options_set_ipv6_enabled, + tox_options_set_log_callback, + tox_options_set_proxy_host, + tox_options_set_proxy_port, + tox_options_set_proxy_type, + tox_options_set_savedata_data, + tox_options_set_savedata_length, + tox_options_set_savedata_type, + tox_options_set_start_port, + tox_options_set_tcp_port, + tox_options_set_udp_enabled, wrapLogCb) -------------------------------------------------------------------------------- -- @@ -21,28 +45,6 @@ import Network.Tox.C.CEnum -------------------------------------------------------------------------------- --- | Type of proxy used to connect to TCP relays. -data ProxyType - = ProxyTypeNone - -- Don't use a proxy. - | ProxyTypeHttp - -- HTTP proxy using CONNECT. - | ProxyTypeSocks5 - -- SOCKS proxy for simple socket pipes. - deriving (Eq, Ord, Enum, Bounded, Read, Show, Generic) - - --- Type of savedata to create the Tox instance from. -data SavedataType - = SavedataTypeNone - -- No savedata. - | SavedataTypeToxSave - -- Savedata is one that was obtained from tox_get_savedata - | SavedataTypeSecretKey - -- Savedata is a secret key of length 'tox_secret_key_size' - deriving (Eq, Ord, Enum, Bounded, Read, Show, Generic) - - -- This struct contains all the startup options for Tox. You can either allocate -- this object yourself, and pass it to tox_options_default, or call -- tox_options_new to get a new default options object. @@ -132,43 +134,6 @@ defaultOptions = Options } -data OptionsStruct -type OptionsPtr = Ptr OptionsStruct - - -foreign import ccall tox_options_get_ipv6_enabled :: OptionsPtr -> IO Bool -foreign import ccall tox_options_get_udp_enabled :: OptionsPtr -> IO Bool -foreign import ccall tox_options_get_proxy_type :: OptionsPtr -> IO (CEnum ProxyType) -foreign import ccall tox_options_get_proxy_host :: OptionsPtr -> IO CString -foreign import ccall tox_options_get_proxy_port :: OptionsPtr -> IO Word16 -foreign import ccall tox_options_get_start_port :: OptionsPtr -> IO Word16 -foreign import ccall tox_options_get_end_port :: OptionsPtr -> IO Word16 -foreign import ccall tox_options_get_tcp_port :: OptionsPtr -> IO Word16 -foreign import ccall tox_options_get_savedata_type :: OptionsPtr -> IO (CEnum SavedataType) -foreign import ccall tox_options_get_savedata_data :: OptionsPtr -> IO CString -foreign import ccall tox_options_get_savedata_length :: OptionsPtr -> IO CSize - -foreign import ccall tox_options_set_ipv6_enabled :: OptionsPtr -> Bool -> IO () -foreign import ccall tox_options_set_udp_enabled :: OptionsPtr -> Bool -> IO () -foreign import ccall tox_options_set_proxy_type :: OptionsPtr -> CEnum ProxyType -> IO () -foreign import ccall tox_options_set_proxy_host :: OptionsPtr -> CString -> IO () -foreign import ccall tox_options_set_proxy_port :: OptionsPtr -> Word16 -> IO () -foreign import ccall tox_options_set_start_port :: OptionsPtr -> Word16 -> IO () -foreign import ccall tox_options_set_end_port :: OptionsPtr -> Word16 -> IO () -foreign import ccall tox_options_set_tcp_port :: OptionsPtr -> Word16 -> IO () -foreign import ccall tox_options_set_savedata_type :: OptionsPtr -> CEnum SavedataType -> IO () -foreign import ccall tox_options_set_savedata_data :: OptionsPtr -> CString -> CSize -> IO () -foreign import ccall tox_options_set_savedata_length :: OptionsPtr -> CSize -> IO () - - -data LogLevel - = LogLevelTrace - | LogLevelDebug - | LogLevelInfo - | LogLevelWarning - | LogLevelError - deriving (Eq, Ord, Enum, Bounded, Read, Show) - logLevelName :: LogLevel -> Char logLevelName LogLevelTrace = 'T' logLevelName LogLevelDebug = 'D' @@ -176,10 +141,6 @@ logLevelName LogLevelInfo = 'I' logLevelName LogLevelWarning = 'W' logLevelName LogLevelError = 'E' -type LogCb = Ptr () -> CEnum LogLevel -> CString -> Word32 -> CString -> CString -> Ptr () -> IO () -foreign import ccall tox_options_set_log_callback :: OptionsPtr -> FunPtr LogCb -> IO () -foreign import ccall "wrapper" wrapLogCb :: LogCb -> IO (FunPtr LogCb) - logHandler :: LogCb logHandler _ cLevel cFile line cFunc cMsg _ = do let level = fromCEnum cLevel diff --git a/src/Network/Tox/C/Tox.hs b/src/Network/Tox/C/Tox.hs index 0f9ec9a..3266a40 100644 --- a/src/Network/Tox/C/Tox.hs +++ b/src/Network/Tox/C/Tox.hs @@ -85,28 +85,99 @@ import qualified Data.ByteString as BS import qualified Data.ByteString.Lazy as LBS import qualified Data.MessagePack as MP import Data.Word (Word16, Word32, Word64) +import Foreign.C.Enum import Foreign.C.String (CString, withCString) -import Foreign.C.Types (CInt (..), CSize (..), CTime (..)) +import Foreign.C.Types (CTime (..)) import Foreign.Marshal.Array (allocaArray, peekArray) import Foreign.Ptr (Ptr, nullPtr) import System.Posix.Types (EpochTime) -import Network.Tox.C.CEnum +import FFI.Tox.Tox (ConferenceType, Connection, + ErrBootstrap (..), + ErrConferenceDelete (..), + ErrConferenceGetType (..), + ErrConferenceInvite (..), + ErrConferenceJoin (..), + ErrConferenceNew (..), + ErrConferencePeerQuery (..), + ErrConferenceSendMessage (..), + ErrConferenceTitle (..), + ErrFileControl (..), ErrFileGet (..), + ErrFileSeek (..), ErrFileSend (..), + ErrFileSendChunk (..), + ErrFriendAdd (..), + ErrFriendByPublicKey (..), + ErrFriendCustomPacket (..), + ErrFriendDelete (..), + ErrFriendGetLastOnline (..), + ErrFriendGetPublicKey (..), + ErrFriendQuery (..), + ErrFriendSendMessage (..), + ErrGetPort (..), ErrNew (..), + ErrSetInfo (..), ErrSetTyping (..), + FileControl, FileKind (..), + MessageType, ToxPtr, UserStatus, + tox_add_tcp_relay, tox_bootstrap, + tox_conference_delete, + tox_conference_get_chatlist, + tox_conference_get_chatlist_size, + tox_conference_get_title, + tox_conference_get_title_size, + tox_conference_get_type, + tox_conference_invite, + tox_conference_join, + tox_conference_new, + tox_conference_peer_count, + tox_conference_peer_get_name, + tox_conference_peer_get_name_size, + tox_conference_peer_get_public_key, + tox_conference_peer_number_is_ours, + tox_conference_send_message, + tox_conference_set_title, + tox_file_control, + tox_file_get_file_id, tox_file_seek, + tox_file_send, tox_file_send_chunk, + tox_friend_add, + tox_friend_add_norequest, + tox_friend_by_public_key, + tox_friend_delete, tox_friend_exists, + tox_friend_get_connection_status, + tox_friend_get_last_online, + tox_friend_get_name, + tox_friend_get_name_size, + tox_friend_get_public_key, + tox_friend_get_status_message, + tox_friend_get_status_message_size, + tox_friend_get_typing, + tox_friend_send_lossless_packet, + tox_friend_send_lossy_packet, + tox_friend_send_message, + tox_get_savedata, + tox_get_savedata_size, tox_hash, + tox_iteration_interval, tox_kill, + tox_new, tox_self_get_address, + tox_self_get_dht_id, + tox_self_get_friend_list, + tox_self_get_friend_list_size, + tox_self_get_name, + tox_self_get_name_size, + tox_self_get_nospam, + tox_self_get_public_key, + tox_self_get_secret_key, + tox_self_get_status_message, + tox_self_get_status_message_size, + tox_self_get_tcp_port, + tox_self_get_udp_port, + tox_self_set_name, + tox_self_set_nospam, + tox_self_set_status, + tox_self_set_status_message, + tox_self_set_typing) import Network.Tox.C.Constants import Network.Tox.C.Options -import Network.Tox.C.Type import Network.Tox.Types.Events (Event) --- | The Tox instance type. All the state associated with a connection is held --- within the instance. Multiple instances can exist and operate concurrently. --- The maximum number of Tox instances that can exist on a single network device --- is limited. Note that this is not just a per-process limit, since the --- limiting factor is the number of usable ports on a device. -data ToxStruct -type Tox = Ptr ToxStruct - - -------------------------------------------------------------------------------- -- -- :: Global types @@ -126,70 +197,7 @@ type Tox = Ptr ToxStruct -- -------------------------------------------------------------------------------- - -data ErrNew - = ErrNewNull - -- One of the arguments to the function was 'nullPtr' when it was not - -- expected. - - | ErrNewMalloc - -- The function was unable to allocate enough memory to store the internal - -- structures for the Tox object. - - | ErrNewPortAlloc - -- The function was unable to bind to a port. This may mean that all ports - -- have already been bound, e.g. by other Tox instances, or it may mean a - -- permission error. You may be able to gather more information from errno. - - | ErrNewProxyBadType - -- proxy_type was invalid. - - | ErrNewProxyBadHost - -- proxy_type was valid but the proxy_host passed had an invalid format or - -- was 'nullPtr'. - - | ErrNewProxyBadPort - -- proxy_type was valid, but the proxy_port was invalid. - - | ErrNewProxyNotFound - -- The proxy address passed could not be resolved. - - | ErrNewLoadEncrypted - -- The byte array to be loaded contained an encrypted save. - - | ErrNewLoadBadFormat - -- The data format was invalid. This can happen when loading data that was - -- saved by an older version of Tox, or when the data has been corrupted. - -- When loading from badly formatted data, some data may have been loaded, - -- and the rest is discarded. Passing an invalid length parameter also - -- causes this error. - deriving (Eq, Ord, Enum, Bounded, Read, Show) - - --- @brief Creates and initialises a new Tox instance with the options passed. --- --- This function will bring the instance into a valid state. Running the event --- loop with a new instance will operate correctly. --- --- If loading failed or succeeded only partially, the new or partially loaded --- instance is returned and an error code is set. --- --- @param options An options object as described above. If this parameter is --- 'nullPtr', the default options are used. --- --- @see tox_iterate for the event loop. --- --- @return A new Tox instance pointer on success or 'nullPtr' on failure. -foreign import ccall tox_new :: OptionsPtr -> CErr ErrNew -> IO Tox - --- | Releases all resources associated with the Tox instance and disconnects --- from the network. --- --- After calling this function, the Tox pointer becomes invalid. No other --- functions can be called, and the pointer value can no longer be read. -foreign import ccall tox_kill :: Tox -> IO () - -withTox :: Options -> (Tox -> IO a) -> IO (Either ErrNew a) +withTox :: Options -> (ToxPtr -> IO a) -> IO (Either ErrNew a) withTox opts f = fmap mapErr . withOptions opts $ \copts -> do result <- callErrFun . tox_new $ copts @@ -206,22 +214,7 @@ withTox opts f = mapErr (Left ErrOptionsNewMalloc) = Left ErrNewMalloc mapErr (Right ok) = ok - --- | Calculates the number of bytes required to store the tox instance with --- tox_get_savedata. This function cannot fail. The result is always greater --- than 0. --- --- @see threading for concurrency implications. -foreign import ccall tox_get_savedata_size :: Tox -> IO CSize - --- | Store all information associated with the tox instance to a byte array. --- --- @param data A memory region large enough to store the tox instance data. --- Call tox_get_savedata_size to find the number of bytes required. If this --- parameter is 'nullPtr', this function has no effect. -foreign import ccall tox_get_savedata :: Tox -> CString -> IO () - -toxGetSavedata :: Tox -> IO BS.ByteString +toxGetSavedata :: ToxPtr -> IO BS.ByteString toxGetSavedata tox = do savedataLen <- tox_get_savedata_size tox allocaArray (fromIntegral savedataLen) $ \savedataPtr -> do @@ -236,20 +229,6 @@ toxGetSavedata tox = do -------------------------------------------------------------------------------- -data ErrBootstrap - = ErrBootstrapNull - -- One of the arguments to the function was 'nullPtr' when it was not - -- expected. - - | ErrBootstrapBadHost - -- The address could not be resolved to an IP address, or the IP address - -- passed was invalid. - - | ErrBootstrapBadPort - -- The port passed was invalid. The valid port range is (1, 65535). - deriving (Eq, Ord, Enum, Bounded, Read, Show) - - -- | Sends a "get nodes" request to the given bootstrap node with IP, port, and -- public key to setup connections. -- @@ -262,8 +241,7 @@ data ErrBootstrap -- @param public_key The long term public key of the bootstrap node -- ('tox_public_key_size' bytes). -- @return true on success. -foreign import ccall tox_bootstrap :: Tox -> CString -> Word16 -> CString -> CErr ErrBootstrap -> IO () -toxBootstrap :: Tox -> String -> Word16 -> BS.ByteString -> IO (Either ErrBootstrap ()) +toxBootstrap :: ToxPtr -> String -> Word16 -> BS.ByteString -> IO (Either ErrBootstrap Bool) toxBootstrap tox address port pubKey = withCString address $ \address' -> BS.useAsCString pubKey $ \pubKey' -> @@ -281,8 +259,7 @@ toxBootstrap tox address port pubKey = -- @param public_key The long term public key of the TCP relay -- ('tox_public_key_size' bytes). -- @return true on success. -foreign import ccall tox_add_tcp_relay :: Tox -> CString -> Word16 -> CString -> CErr ErrBootstrap -> IO () -toxAddTcpRelay :: Tox -> String -> Word16 -> BS.ByteString -> IO (Either ErrBootstrap ()) +toxAddTcpRelay :: ToxPtr -> String -> Word16 -> BS.ByteString -> IO (Either ErrBootstrap Bool) toxAddTcpRelay tox address port pubKey = withCString address $ \address' -> BS.useAsCString pubKey $ \pubKey' -> @@ -302,14 +279,14 @@ data ErrEventsIterate -- Failed to encode or decode events in msgpack. deriving (Eq, Ord, Enum, Bounded, Read, Show) -foreign import ccall tox_events_init :: Tox -> IO () -foreign import ccall tox_events_iterate :: Tox -> Bool -> CErr ErrEventsIterate -> IO ToxEvents +foreign import ccall tox_events_init :: ToxPtr -> IO () +foreign import ccall tox_events_iterate :: ToxPtr -> Bool -> CErr ErrEventsIterate -> IO ToxEvents -foreign import ccall tox_events_bytes_size :: ToxEvents -> IO Word32 -foreign import ccall tox_events_get_bytes :: ToxEvents -> CString -> IO () +foreign import ccall tox_events_bytes_size :: ToxEvents -> IO Word32 +foreign import ccall tox_events_get_bytes :: ToxEvents -> CString -> IO () -foreign import ccall tox_events_load :: CString -> Word32 -> IO ToxEvents -foreign import ccall tox_events_free :: ToxEvents -> IO () +foreign import ccall tox_events_load :: CString -> Word32 -> IO ToxEvents +foreign import ccall tox_events_free :: ToxEvents -> IO () toxEventsToPtr :: [Event] -> IO ToxEvents toxEventsToPtr events = @@ -330,7 +307,7 @@ toxEventsFromPtr evPtr = do return $ Left $ show err Right ok -> return $ Right ok -toxEventsIterate :: Tox -> IO (Either String [Event]) +toxEventsIterate :: ToxPtr -> IO (Either String [Event]) toxEventsIterate tox = callErrFun (tox_events_iterate tox True) >>= \case Left err -> return $ Left $ show err @@ -339,8 +316,7 @@ toxEventsIterate tox = -- | Return the time in milliseconds before tox_iterate() should be called again -- for optimal performance. -foreign import ccall tox_iteration_interval :: Tox -> IO Word32 -toxIterationInterval :: Tox -> IO Word32 +toxIterationInterval :: ToxPtr -> IO Word32 toxIterationInterval = tox_iteration_interval -------------------------------------------------------------------------------- @@ -357,9 +333,7 @@ toxIterationInterval = tox_iteration_interval -- @param address A memory region of at least 'tox_address_size' bytes. If this -- parameter is 'nullPtr', this function has no effect. -- @see 'tox_address_size' for the address format. -foreign import ccall tox_self_get_address :: Tox -> CString -> IO () - -toxSelfGetAddress :: Tox -> IO BS.ByteString +toxSelfGetAddress :: ToxPtr -> IO BS.ByteString toxSelfGetAddress tox = let addrLen = fromIntegral tox_address_size in allocaArray addrLen $ \addrPtr -> do @@ -369,18 +343,18 @@ toxSelfGetAddress tox = -- | Set the 4-byte nospam part of the address. -- -- @param nospam Any 32 bit unsigned integer. -foreign import ccall "tox_self_set_nospam" toxSelfSetNospam :: Tox -> Word32 -> IO () +toxSelfSetNospam :: ToxPtr -> Word32 -> IO () +toxSelfSetNospam = tox_self_set_nospam -- | Get the 4-byte nospam part of the address. -foreign import ccall "tox_self_get_nospam" toxSelfGetNospam :: Tox -> IO Word32 +toxSelfGetNospam :: ToxPtr -> IO Word32 +toxSelfGetNospam = tox_self_get_nospam -- | Copy the Tox Public Key (long term) from the Tox object. -- -- @param public_key A memory region of at least 'tox_public_key_size' bytes. If -- this parameter is 'nullPtr', this function has no effect. -foreign import ccall tox_self_get_public_key :: Tox -> CString -> IO () - -toxSelfGetPublicKey :: Tox -> IO BS.ByteString +toxSelfGetPublicKey :: ToxPtr -> IO BS.ByteString toxSelfGetPublicKey tox = let pkLen = fromIntegral tox_public_key_size in allocaArray pkLen $ \pkPtr -> do @@ -391,9 +365,7 @@ toxSelfGetPublicKey tox = -- -- @param secret_key A memory region of at least 'tox_secret_key_size' bytes. If -- this parameter is 'nullPtr', this function has no effect. -foreign import ccall tox_self_get_secret_key :: Tox -> CString -> IO () - -toxSelfGetSecretKey :: Tox -> IO BS.ByteString +toxSelfGetSecretKey :: ToxPtr -> IO BS.ByteString toxSelfGetSecretKey tox = let skLen = fromIntegral tox_secret_key_size in allocaArray skLen $ \skPtr -> do @@ -408,18 +380,6 @@ toxSelfGetSecretKey tox = -------------------------------------------------------------------------------- --- | Common error codes for all functions that set a piece of user-visible --- client information. -data ErrSetInfo - = ErrSetInfoNull - -- One of the arguments to the function was 'nullPtr' when it was not - -- expected. - - | ErrSetInfoTooLong - -- Information length exceeded maximum permissible size. - deriving (Eq, Ord, Enum, Bounded, Read, Show) - - -- | Set the nickname for the Tox client. -- -- Nickname length cannot exceed 'tox_max_name_length'. If length is 0, the name @@ -430,21 +390,11 @@ data ErrSetInfo -- @param length The size of the name byte array. -- -- @return true on success. -foreign import ccall tox_self_set_name :: Tox -> CString -> CSize -> CErr ErrSetInfo -> IO () -toxSelfSetName :: Tox -> BS.ByteString -> IO (Either ErrSetInfo ()) +toxSelfSetName :: ToxPtr -> BS.ByteString -> IO (Either ErrSetInfo Bool) toxSelfSetName tox name = BS.useAsCStringLen name $ \(nameStr, nameLen) -> callErrFun $ tox_self_set_name tox nameStr (fromIntegral nameLen) - --- | Return the length of the current nickname as passed to tox_self_set_name. --- --- If no nickname was set before calling this function, the name is empty, --- and this function returns 0. --- --- @see threading for concurrency implications. -foreign import ccall tox_self_get_name_size :: Tox -> IO CSize - -- | Write the nickname set by tox_self_set_name to a byte array. -- -- If no nickname was set before calling this function, the name is empty, @@ -455,9 +405,7 @@ foreign import ccall tox_self_get_name_size :: Tox -> IO CSize -- -- @param name A valid memory location large enough to hold the nickname. -- If this parameter is NULL, the function has no effect. -foreign import ccall tox_self_get_name :: Tox -> CString -> IO () - -toxSelfGetName :: Tox -> IO BS.ByteString +toxSelfGetName :: ToxPtr -> IO BS.ByteString toxSelfGetName tox = do nameLen <- tox_self_get_name_size tox allocaArray (fromIntegral nameLen) $ \namePtr -> do @@ -470,22 +418,12 @@ toxSelfGetName tox = do -- Status message length cannot exceed 'tox_max_status_message_length'. If -- length is 0, the status parameter is ignored (it can be 'nullPtr'), and the -- user status is set back to empty. -foreign import ccall tox_self_set_status_message :: Tox -> CString -> CSize -> CErr ErrSetInfo -> IO () -toxSelfSetStatusMessage :: Tox -> BS.ByteString -> IO (Either ErrSetInfo ()) +toxSelfSetStatusMessage :: ToxPtr -> BS.ByteString -> IO (Either ErrSetInfo Bool) toxSelfSetStatusMessage tox statusMsg = BS.useAsCStringLen statusMsg $ \(statusMsgStr, statusMsgLen) -> callErrFun $ tox_self_set_status_message tox statusMsgStr (fromIntegral statusMsgLen) --- | Return the length of the current status message as passed to tox_self_set_status_message. --- --- If no status message was set before calling this function, the status --- is empty, and this function returns 0. --- --- @see threading for concurrency implications. -foreign import ccall tox_self_get_status_message_size :: Tox -> IO CSize - - -- | Write the status message set by tox_self_set_status_message to a byte array. -- -- If no status message was set before calling this function, the status is @@ -496,9 +434,7 @@ foreign import ccall tox_self_get_status_message_size :: Tox -> IO CSize -- -- @param status_message A valid memory location large enough to hold the -- status message. If this parameter is NULL, the function has no effect. -foreign import ccall tox_self_get_status_message :: Tox -> CString -> IO () - -toxSelfGetStatusMessage :: Tox -> IO BS.ByteString +toxSelfGetStatusMessage :: ToxPtr -> IO BS.ByteString toxSelfGetStatusMessage tox = do statusMessageLen <- tox_self_get_status_message_size tox allocaArray (fromIntegral statusMessageLen) $ \statusMessagePtr -> do @@ -509,8 +445,7 @@ toxSelfGetStatusMessage tox = do -- | Set the client's user status. -- -- @param user_status One of the user statuses listed in the enumeration above. -foreign import ccall tox_self_set_status :: Tox -> CEnum UserStatus -> IO () -toxSelfSetStatus :: Tox -> UserStatus -> IO () +toxSelfSetStatus :: ToxPtr -> UserStatus -> IO () toxSelfSetStatus tox userStatus = tox_self_set_status tox $ toCEnum userStatus @@ -522,37 +457,6 @@ toxSelfSetStatus tox userStatus = -------------------------------------------------------------------------------- -data ErrFriendAdd - = ErrFriendAddNull - -- One of the arguments to the function was 'nullPtr' when it was not - -- expected. - - | ErrFriendAddTooLong - -- The length of the friend request message exceeded - -- 'tox_max_friend_request_length'. - - | ErrFriendAddNoMessage - -- The friend request message was empty. This, and the TooLong code will - -- never be returned from tox_friend_add_norequest. - - | ErrFriendAddOwnKey - -- The friend address belongs to the sending client. - - | ErrFriendAddAlreadySent - -- A friend request has already been sent, or the address belongs to a - -- friend that is already on the friend list. - - | ErrFriendAddBadChecksum - -- The friend address checksum failed. - - | ErrFriendAddSetNewNospam - -- The friend was already there, but the nospam value was different. - - | ErrFriendAddMalloc - -- A memory allocation failed when trying to increase the friend list size. - deriving (Eq, Ord, Enum, Bounded, Read, Show) - - -- | Add a friend to the friend list and send a friend request. -- -- A friend request message must be at least 1 byte long and at most @@ -574,8 +478,7 @@ data ErrFriendAdd -- @param length The length of the data byte array. -- -- @return the friend number on success, UINT32_MAX on failure. -foreign import ccall tox_friend_add :: Tox -> CString -> CString -> CSize -> CErr ErrFriendAdd -> IO Word32 -toxFriendAdd :: Tox -> BS.ByteString -> BS.ByteString -> IO (Either ErrFriendAdd Word32) +toxFriendAdd :: ToxPtr -> BS.ByteString -> BS.ByteString -> IO (Either ErrFriendAdd Word32) toxFriendAdd tox address message = BS.useAsCStringLen message $ \(msgStr, msgLen) -> BS.useAsCString address $ \addr' -> @@ -597,20 +500,12 @@ toxFriendAdd tox address message = -- -- @return the friend number on success, UINT32_MAX on failure. -- @see tox_friend_add for a more detailed description of friend numbers. -foreign import ccall tox_friend_add_norequest :: Tox -> CString -> CErr ErrFriendAdd -> IO Word32 -toxFriendAddNorequest :: Tox -> BS.ByteString -> IO (Either ErrFriendAdd Word32) +toxFriendAddNorequest :: ToxPtr -> BS.ByteString -> IO (Either ErrFriendAdd Word32) toxFriendAddNorequest tox address = BS.useAsCString address $ \addr' -> callErrFun $ tox_friend_add_norequest tox addr' -data ErrFriendDelete - = ErrFriendDeleteFriendNotFound - -- There was no friend with the given friend number. No friends were - -- deleted. - deriving (Eq, Ord, Enum, Bounded, Read, Show) - - -- | Remove a friend from the friend list. -- -- This does not notify the friend of their deletion. After calling this @@ -620,9 +515,7 @@ data ErrFriendDelete -- @param friend_number Friend number for the friend to be deleted. -- -- @return true on success. -foreign import ccall tox_friend_delete :: Tox -> Word32 -> CErr ErrFriendDelete -> IO () - -toxFriendDelete :: Tox -> Word32 -> IO (Either ErrFriendDelete ()) +toxFriendDelete :: ToxPtr -> Word32 -> IO (Either ErrFriendDelete Bool) toxFriendDelete tox fn = callErrFun $ tox_friend_delete tox fn @@ -633,35 +526,19 @@ toxFriendDelete tox fn = callErrFun $ tox_friend_delete tox fn -------------------------------------------------------------------------------- -data ErrFriendByPublicKey - = ErrFriendByPublicKeyNull - -- One of the arguments to the function was 'nullPtr' when it was not - -- expected. - - | ErrFriendByPublicKeyNotFound - -- No friend with the given Public Key exists on the friend list. - deriving (Eq, Ord, Enum, Bounded, Read, Show) - - -- | Return the friend number associated with that Public Key. -- -- @return the friend number on success, UINT32_MAX on failure. -- @param public_key A byte array containing the Public Key. -foreign import ccall tox_friend_by_public_key :: Tox -> CString -> CErr ErrFriendByPublicKey -> IO Word32 -toxFriendByPublicKey :: Tox -> BS.ByteString -> IO (Either ErrFriendByPublicKey Word32) +toxFriendByPublicKey :: ToxPtr -> BS.ByteString -> IO (Either ErrFriendByPublicKey Word32) toxFriendByPublicKey tox address = BS.useAsCString address $ \addr' -> callErrFun $ tox_friend_by_public_key tox addr' -- | Checks if a friend with the given friend number exists and returns true if -- it does. -foreign import ccall "tox_friend_exists" toxFriendExists :: Tox -> Word32 -> IO Bool - --- | Return the number of friends on the friend list. --- --- This function can be used to determine how much memory to allocate for --- tox_self_get_friend_list. -foreign import ccall tox_self_get_friend_list_size :: Tox -> IO CSize +toxFriendExists :: ToxPtr -> Word32 -> IO Bool +toxFriendExists = tox_friend_exists -- | Copy a list of valid friend numbers into an array. -- @@ -670,20 +547,13 @@ foreign import ccall tox_self_get_friend_list_size :: Tox -> IO CSize -- -- @param list A memory region with enough space to hold the friend list. If -- this parameter is 'nullPtr', this function has no effect. -foreign import ccall tox_self_get_friend_list :: Tox -> Ptr Word32 -> IO () - -toxSelfGetFriendList :: Tox -> IO [Word32] +toxSelfGetFriendList :: ToxPtr -> IO [Word32] toxSelfGetFriendList tox = do friendListSize <- tox_self_get_friend_list_size tox allocaArray (fromIntegral friendListSize) $ \friendListPtr -> do tox_self_get_friend_list tox friendListPtr peekArray (fromIntegral friendListSize) friendListPtr -data ErrFriendGetPublicKey - = ErrFriendGetPublicKeyFriendNotFound - -- No friend with the given number exists on the friend list. - deriving (Eq, Ord, Enum, Bounded, Read, Show) - -- | Copies the Public Key associated with a given friend number to a byte -- array. @@ -693,8 +563,7 @@ data ErrFriendGetPublicKey -- this parameter is 'nullPtr', this function has no effect. -- -- @return true on success. -foreign import ccall tox_friend_get_public_key :: Tox -> Word32 -> CString -> CErr ErrFriendGetPublicKey -> IO Bool -toxFriendGetPublicKey :: Tox -> Word32 -> IO (Either ErrFriendGetPublicKey BS.ByteString) +toxFriendGetPublicKey :: ToxPtr -> Word32 -> IO (Either ErrFriendGetPublicKey BS.ByteString) toxFriendGetPublicKey tox fn = let pkLen = fromIntegral tox_public_key_size in allocaArray pkLen $ \pkPtr -> do @@ -704,18 +573,11 @@ toxFriendGetPublicKey tox fn = Right _ -> Right <$> BS.packCStringLen (pkPtr, pkLen) -data ErrFriendGetLastOnline - = ErrFriendGetLastOnlineFriendNotFound - -- No friend with the given number exists on the friend list. - deriving (Eq, Ord, Enum, Bounded, Read, Show) - - -- | Return a unix-time timestamp of the last time the friend associated with a given -- friend number was seen online. This function will return UINT64_MAX on error. -- -- @param friend_number The friend number you want to query. -foreign import ccall tox_friend_get_last_online :: Tox -> Word32 -> CErr ErrFriendGetLastOnline -> IO Word64 -toxFriendGetLastOnline :: Tox -> Word32 -> IO (Either ErrFriendGetLastOnline EpochTime) +toxFriendGetLastOnline :: ToxPtr -> Word32 -> IO (Either ErrFriendGetLastOnline EpochTime) toxFriendGetLastOnline tox fn = callErrFun (tox_friend_get_last_online tox fn >=> (return . CTime . fromIntegral)) @@ -727,25 +589,6 @@ toxFriendGetLastOnline tox fn = -------------------------------------------------------------------------------- --- | Common error codes for friend state query functions. -data ErrFriendQuery - = ErrFriendQueryNull - -- The pointer parameter for storing the query result (name, message) was - -- NULL. Unlike the `_self_` variants of these functions, which have no effect - -- when a parameter is NULL, these functions return an error in that case. - - | ErrFriendQueryFriendNotFound - -- The friend_number did not designate a valid friend. - deriving (Eq, Ord, Enum, Bounded, Read, Show) - - --- | Return the length of the friend's name. If the friend number is invalid, the --- return value is unspecified. --- --- The return value is equal to the `length` argument received by the last --- `friend_name` callback. -foreign import ccall tox_friend_get_name_size :: Tox -> Word32 -> CErr ErrFriendQuery -> IO CSize - -- | Write the name of the friend designated by the given friend number to a byte -- array. -- @@ -758,9 +601,7 @@ foreign import ccall tox_friend_get_name_size :: Tox -> Word32 -> CErr ErrFriend -- @param name A valid memory region large enough to store the friend's name. -- -- @return true on success. -foreign import ccall tox_friend_get_name :: Tox -> Word32 -> CString -> CErr ErrFriendQuery -> IO Bool - -toxFriendGetName :: Tox -> Word32 -> IO (Either ErrFriendQuery BS.ByteString) +toxFriendGetName :: ToxPtr -> Word32 -> IO (Either ErrFriendQuery BS.ByteString) toxFriendGetName tox fn = do nameLenRes <- callErrFun $ tox_friend_get_name_size tox fn case nameLenRes of @@ -772,10 +613,6 @@ toxFriendGetName tox fn = do Right _ -> Right <$> BS.packCStringLen (namePtr, fromIntegral nameLen) --- | Return the length of the friend's status message. If the friend number is --- invalid, the return value is SIZE_MAX. -foreign import ccall tox_friend_get_status_message_size :: Tox -> Word32 -> CErr ErrFriendQuery -> IO CSize - -- | Write the status message of the friend designated by the given friend number to a byte -- array. -- @@ -786,9 +623,7 @@ foreign import ccall tox_friend_get_status_message_size :: Tox -> Word32 -> CErr -- `friend_status_message` callback. -- -- @param status_message A valid memory region large enough to store the friend's status message. -foreign import ccall tox_friend_get_status_message :: Tox -> Word32 -> CString -> CErr ErrFriendQuery -> IO Bool - -toxFriendGetStatusMessage :: Tox -> Word32 -> IO (Either ErrFriendQuery BS.ByteString) +toxFriendGetStatusMessage :: ToxPtr -> Word32 -> IO (Either ErrFriendQuery BS.ByteString) toxFriendGetStatusMessage tox fn = do statusMessageLenRes <- callErrFun $ tox_friend_get_status_message_size tox fn case statusMessageLenRes of @@ -810,8 +645,7 @@ toxFriendGetStatusMessage tox fn = do -- -- @return the friend's connection status as it was received through the -- `friend_connection_status` event. -foreign import ccall tox_friend_get_connection_status :: Tox -> Word32 -> CErr ErrFriendQuery -> IO (CEnum Connection) -toxFriendGetConnectionStatus :: Tox -> Word32 -> IO (Either ErrFriendQuery Connection) +toxFriendGetConnectionStatus :: ToxPtr -> Word32 -> IO (Either ErrFriendQuery Connection) toxFriendGetConnectionStatus tox fn = callErrFun (tox_friend_get_connection_status tox fn >=> return . fromCEnum) @@ -823,8 +657,7 @@ toxFriendGetConnectionStatus tox fn = -- @return true if the friend is typing. -- @return false if the friend is not typing, or the friend number was -- invalid. Inspect the error code to determine which case it is. -foreign import ccall tox_friend_get_typing :: Tox -> Word32 -> CErr ErrFriendQuery -> IO Bool -toxFriendGetTyping :: Tox -> Word32 -> IO (Either ErrFriendQuery Bool) +toxFriendGetTyping :: ToxPtr -> Word32 -> IO (Either ErrFriendQuery Bool) toxFriendGetTyping tox fn = callErrFun $ tox_friend_get_typing tox fn @@ -835,12 +668,6 @@ toxFriendGetTyping tox fn = callErrFun $ tox_friend_get_typing tox fn -------------------------------------------------------------------------------- -data ErrSetTyping - = ErrSetTypingFriendNotFound - -- The friend number did not designate a valid friend. - deriving (Eq, Ord, Enum, Bounded, Read, Show) - - -- | Set the client's typing status for a friend. -- -- The client is responsible for turning it on or off. @@ -849,33 +676,10 @@ data ErrSetTyping -- @param typing The typing status. True means the client is typing. -- -- @return true on success. -foreign import ccall tox_self_set_typing :: Tox -> Word32 -> Bool -> CErr ErrSetTyping -> IO Bool -toxSelfSetTyping :: Tox -> Word32 -> Bool -> IO (Either ErrSetTyping Bool) +toxSelfSetTyping :: ToxPtr -> Word32 -> Bool -> IO (Either ErrSetTyping Bool) toxSelfSetTyping tox fn typing = callErrFun $ tox_self_set_typing tox fn typing -data ErrFriendSendMessage - = ErrFriendSendMessageNull - -- One of the arguments to the function was 'nullPtr' when it was not - -- expected. - - | ErrFriendSendMessageFriendNotFound - -- The friend number did not designate a valid friend. - - | ErrFriendSendMessageFriendNotConnected - -- This client is currently not connected to the friend. - - | ErrFriendSendMessageSendq - -- An allocation error occurred while increasing the send queue size. - - | ErrFriendSendMessageTooLong - -- Message length exceeded 'tox_max_message_length'. - - | ErrFriendSendMessageEmpty - -- Attempted to send a zero-length message. - deriving (Eq, Ord, Enum, Bounded, Read, Show) - - -- | Send a text chat message to an online friend. -- -- This function creates a chat message packet and pushes it into the send @@ -898,8 +702,7 @@ data ErrFriendSendMessage -- @param message A non-'nullPtr' pointer to the first element of a byte array -- containing the message text. -- @param length Length of the message to be sent. -foreign import ccall tox_friend_send_message :: Tox -> Word32 -> CEnum MessageType -> CString -> CSize -> CErr ErrFriendSendMessage -> IO Word32 -toxFriendSendMessage :: Tox -> Word32 -> MessageType -> BS.ByteString -> IO (Either ErrFriendSendMessage Word32) +toxFriendSendMessage :: ToxPtr -> Word32 -> MessageType -> BS.ByteString -> IO (Either ErrFriendSendMessage Word32) toxFriendSendMessage tox fn messageType message = BS.useAsCStringLen message $ \(msgStr, msgLen) -> callErrFun $ tox_friend_send_message tox fn (toCEnum messageType) msgStr (fromIntegral msgLen) @@ -929,8 +732,6 @@ toxFriendSendMessage tox fn messageType message = -- @param length Size of the data array or 0. -- -- @return true if hash was not 'nullPtr'. -foreign import ccall tox_hash :: CString -> CString -> CSize -> IO Bool - toxHash :: BS.ByteString -> IO BS.ByteString toxHash d = let hashLen = fromIntegral tox_hash_length in @@ -940,58 +741,6 @@ toxHash d = BS.packCStringLen (dataPtr, fromIntegral dataLen) -data FileKind - = FileKindData - -- Arbitrary file data. Clients can choose to handle it based on the file - -- name or magic or any other way they choose. - - | FileKindAvatar - -- Avatar file_id. This consists of tox_hash(image). Avatar data. This - -- consists of the image data. - -- - -- Avatars can be sent at any time the client wishes. Generally, a client - -- will send the avatar to a friend when that friend comes online, and to - -- all friends when the avatar changed. A client can save some traffic by - -- remembering which friend received the updated avatar already and only - -- send it if the friend has an out of date avatar. - -- - -- Clients who receive avatar send requests can reject it (by sending - -- FileControlCancel before any other controls), or accept it (by sending - -- FileControlResume). The file_id of length 'tox_hash_length' bytes (same - -- length as 'tox_file_id_length') will contain the hash. A client can - -- compare this hash with a saved hash and send FileControlCancel to - -- terminate the avatar transfer if it matches. - -- - -- When file_size is set to 0 in the transfer request it means that the - -- client has no avatar. - deriving (Eq, Ord, Enum, Bounded, Read, Show) - - -data ErrFileControl - = ErrFileControlFriendNotFound - -- The friend_number passed did not designate a valid friend. - - | ErrFileControlFriendNotConnected - -- This client is currently not connected to the friend. - - | ErrFileControlNotFound - -- No file transfer with the given file number was found for the given friend. - - | ErrFileControlNotPaused - -- A Resume control was sent, but the file transfer is running normally. - - | ErrFileControlDenied - -- A Resume control was sent, but the file transfer was paused by the other - -- party. Only the party that paused the transfer can resume it. - - | ErrFileControlAlreadyPaused - -- A Pause control was sent, but the file transfer was already paused. - - | ErrFileControlSendq - -- Packet queue is full. - deriving (Eq, Ord, Enum, Bounded, Read, Show) - - -- | Sends a file control command to a friend for a given file transfer. -- -- @param friend_number The friend number of the friend the file is being @@ -1000,32 +749,10 @@ data ErrFileControl -- @param control The control command to send. -- -- @return true on success. -foreign import ccall tox_file_control :: Tox -> Word32 -> Word32 -> CEnum FileControl -> CErr ErrFileControl -> IO Bool -toxFileControl :: Tox -> Word32 -> Word32 -> FileControl -> IO (Either ErrFileControl Bool) +toxFileControl :: ToxPtr -> Word32 -> Word32 -> FileControl -> IO (Either ErrFileControl Bool) toxFileControl tox fn fileNum control = callErrFun $ tox_file_control tox fn fileNum (toCEnum control) -data ErrFileSeek - = ErrFileSeekFriendNotFound - -- The friend_number passed did not designate a valid friend. - - | ErrFileSeekFriendNotConnected - -- This client is currently not connected to the friend. - - | ErrFileSeekNotFound - -- No file transfer with the given file number was found for the given friend. - - | ErrFileSeekDenied - -- File was not in a state where it could be seeked. - - | ErrFileSeekInvalidPosition - -- Seek position was invalid - - | ErrFileSeekSendq - -- Packet queue is full. - deriving (Eq, Ord, Enum, Bounded, Read, Show) - - -- | Sends a file seek control command to a friend for a given file transfer. -- -- This function can only be called to resume a file transfer right before @@ -1035,24 +762,10 @@ data ErrFileSeek -- received from. -- @param file_number The friend-specific identifier for the file transfer. -- @param position The position that the file should be seeked to. -foreign import ccall tox_file_seek :: Tox -> Word32 -> Word32 -> Word64 -> CErr ErrFileSeek -> IO Bool -toxFileSeek :: Tox -> Word32 -> Word32 -> Word64 -> IO (Either ErrFileSeek Bool) +toxFileSeek :: ToxPtr -> Word32 -> Word32 -> Word64 -> IO (Either ErrFileSeek Bool) toxFileSeek tox fn fileNum pos = callErrFun $ tox_file_seek tox fn fileNum pos -data ErrFileGet - = ErrFileGetNull - -- One of the arguments to the function was 'nullPtr' when it was not - -- expected. - - | ErrFileGetFriendNotFound - -- The friend_number passed did not designate a valid friend. - - | ErrFileGetNotFound - -- No file transfer with the given file number was found for the given friend. - deriving (Eq, Ord, Enum, Bounded, Read, Show) - - -- | Copy the file id associated to the file transfer to a byte array. -- -- @param friend_number The friend number of the friend the file is being @@ -1062,8 +775,7 @@ data ErrFileGet -- this parameter is 'nullPtr', this function has no effect. -- -- @return true on success. -foreign import ccall tox_file_get_file_id :: Tox -> Word32 -> Word32 -> CString -> CErr ErrFileGet -> IO Bool -toxFileGetFileId :: Tox -> Word32 -> Word32 -> IO (Either ErrFileGet BS.ByteString) +toxFileGetFileId :: ToxPtr -> Word32 -> Word32 -> IO (Either ErrFileGet BS.ByteString) toxFileGetFileId tox fn fileNum = let fileIdLen = fromIntegral tox_file_id_length in allocaArray fileIdLen $ \fileIdPtr -> do @@ -1080,26 +792,6 @@ toxFileGetFileId tox fn fileNum = -------------------------------------------------------------------------------- -data ErrFileSend - = ErrFileSendNull - -- One of the arguments to the function was 'nullPtr' when it was not - -- expected. - - | ErrFileSendFriendNotFound - -- The friend_number passed did not designate a valid friend. - - | ErrFileSendFriendNotConnected - -- This client is currently not connected to the friend. - - | ErrFileSendNameTooLong - -- Filename length exceeded 'tox_max_filename_length' bytes. - - | ErrFileSendTooMany - -- Too many ongoing transfers. The maximum number of concurrent file transfers - -- is 256 per friend per direction (sending and receiving). - deriving (Eq, Ord, Enum, Bounded, Read, Show) - - -- | Send a file transmission request. -- -- Maximum filename length is 'tox_max_filename_length' bytes. The filename @@ -1158,43 +850,10 @@ data ErrFileSend -- number is per friend. File numbers are reused after a transfer terminates. -- On failure, this function returns UINT32_MAX. Any pattern in file numbers -- should not be relied on. -foreign import ccall tox_file_send :: Tox -> Word32 -> CEnum FileKind -> Word64 -> CString -> CString -> CSize -> CErr ErrFileSend -> IO Word32 -toxFileSend :: Tox -> Word32 -> FileKind -> Word64 -> BS.ByteString -> IO (Either ErrFileSend Word32) +toxFileSend :: ToxPtr -> Word32 -> FileKind -> Word64 -> BS.ByteString -> IO (Either ErrFileSend Word32) toxFileSend tox fn fileKind fileSize fileName = BS.useAsCStringLen fileName $ \(fileNamePtr, fileNameLen) -> - callErrFun $ tox_file_send tox fn (toCEnum fileKind) fileSize nullPtr fileNamePtr (fromIntegral fileNameLen) - - -data ErrFileSendChunk - = ErrFileSendChunkNull - -- The length parameter was non-zero, but data was 'nullPtr'. - - | ErrFileSendChunkFriendNotFound - -- The friend_number passed did not designate a valid friend. - - | ErrFileSendChunkFriendNotConnected - -- This client is currently not connected to the friend. - - | ErrFileSendChunkNotFound - -- No file transfer with the given file number was found for the given friend. - - | ErrFileSendChunkNotTransferring - -- File transfer was found but isn't in a transferring state: (paused, done, - -- broken, etc...) (happens only when not called from the request chunk - -- callback). - - | ErrFileSendChunkInvalidLength - -- Attempted to send more or less data than requested. The requested data - -- size is adjusted according to maximum transmission unit and the expected - -- end of the file. Trying to send less or more than requested will return - -- this error. - - | ErrFileSendChunkSendq - -- Packet queue is full. - - | ErrFileSendChunkWrongPosition - -- Position parameter was wrong. - deriving (Eq, Ord, Enum, Bounded, Read, Show) + callErrFun $ tox_file_send tox fn (fromIntegral $ fromEnum fileKind) fileSize nullPtr fileNamePtr (fromIntegral fileNameLen) -- | Send a chunk of file data to a friend. @@ -1212,8 +871,7 @@ data ErrFileSendChunk -- @param file_number The file transfer identifier returned by tox_file_send. -- @param position The file or stream position from which to continue reading. -- @return true on success. -foreign import ccall tox_file_send_chunk :: Tox -> Word32 -> Word32 -> Word64 -> CString -> CSize -> CErr ErrFileSendChunk -> IO Bool -toxFileSendChunk :: Tox -> Word32 -> Word32 -> Word64 -> BS.ByteString -> IO (Either ErrFileSendChunk Bool) +toxFileSendChunk :: ToxPtr -> Word32 -> Word32 -> Word64 -> BS.ByteString -> IO (Either ErrFileSendChunk Bool) toxFileSendChunk tox fn fileNum pos d = BS.useAsCStringLen d $ \(dataPtr, dataLen) -> callErrFun $ tox_file_send_chunk tox fn fileNum pos dataPtr (fromIntegral dataLen) @@ -1226,69 +884,34 @@ toxFileSendChunk tox fn fileNum pos d = -------------------------------------------------------------------------------- -data ErrConferenceNew - = ErrConferenceNewInit - -- The conference instance failed to initialize. - deriving (Eq, Ord, Enum, Bounded, Read, Show) - - -- | Creates a new conference. -- -- This function creates a new text conference. -- -- @return conference number on success, or UINT32_MAX on failure. -foreign import ccall tox_conference_new :: Tox -> CErr ErrConferenceNew -> IO Word32 -toxConferenceNew :: Tox -> IO (Either ErrConferenceNew Word32) +toxConferenceNew :: ToxPtr -> IO (Either ErrConferenceNew Word32) toxConferenceNew tox = callErrFun $ tox_conference_new tox -data ErrConferenceDelete - = ErrConferenceDeleteConferenceNotFound - -- The conference number passed did not designate a valid conference. - deriving (Eq, Ord, Enum, Bounded, Read, Show) - - -- | This function deletes a conference. -- -- @param conference_number The conference number of the conference to be deleted. -- -- @return true on success. -foreign import ccall tox_conference_delete :: Tox -> Word32 -> CErr ErrConferenceDelete -> IO Bool -toxConferenceDelete :: Tox -> Word32 -> IO (Either ErrConferenceDelete Bool) +toxConferenceDelete :: ToxPtr -> Word32 -> IO (Either ErrConferenceDelete Bool) toxConferenceDelete tox gn = callErrFun $ tox_conference_delete tox gn --- | Error codes for peer info queries. -data ErrConferencePeerQuery - = ErrConferencePeerQueryConferenceNotFound - -- The conference number passed did not designate a valid conference. - - | ErrConferencePeerQueryPeerNotFound - -- The peer number passed did not designate a valid peer. - - | ErrConferencePeerQueryNoConnection - -- The client is not connected to the conference. - deriving (Eq, Ord, Enum, Bounded, Read, Show) - - - -- | Return the number of peers in the conference. Return value is unspecified on failure. -foreign import ccall tox_conference_peer_count :: Tox -> Word32 -> CErr ErrConferencePeerQuery -> IO Word32 -toxConferencePeerCount :: Tox -> Word32 -> IO (Either ErrConferencePeerQuery Word32) +toxConferencePeerCount :: ToxPtr -> Word32 -> IO (Either ErrConferencePeerQuery Word32) toxConferencePeerCount tox gn = callErrFun $ tox_conference_peer_count tox gn --- | Return the length of the peer's name. Return value is unspecified on failure. -foreign import ccall tox_conference_peer_get_name_size :: Tox -> Word32 -> Word32 -> CErr ErrConferencePeerQuery -> IO CSize - - -- | Copy the name of peer_number who is in conference_number to name. -- name must be at least TOX_MAX_NAME_LENGTH long. -- -- @return true on success. -foreign import ccall tox_conference_peer_get_name :: Tox -> Word32 -> Word32 -> CString -> CErr ErrConferencePeerQuery -> IO Bool - -toxConferencePeerGetName :: Tox -> Word32 -> Word32 -> IO (Either ErrConferencePeerQuery BS.ByteString) +toxConferencePeerGetName :: ToxPtr -> Word32 -> Word32 -> IO (Either ErrConferencePeerQuery BS.ByteString) toxConferencePeerGetName tox gn pn = do nameLenRes <- callErrFun $ tox_conference_peer_get_name_size tox gn pn case nameLenRes of @@ -1304,8 +927,7 @@ toxConferencePeerGetName tox gn pn = do -- public_key must be TOX_PUBLIC_KEY_SIZE long. -- -- @return true on success. -foreign import ccall tox_conference_peer_get_public_key :: Tox -> Word32 -> Word32 -> CString -> CErr ErrConferencePeerQuery -> IO Bool -toxConferencePeerGetPublicKey :: Tox -> Word32 -> Word32 -> IO (Either ErrConferencePeerQuery BS.ByteString) +toxConferencePeerGetPublicKey :: ToxPtr -> Word32 -> Word32 -> IO (Either ErrConferencePeerQuery BS.ByteString) toxConferencePeerGetPublicKey tox gn pn = let pkLen = fromIntegral tox_public_key_size in allocaArray pkLen $ \pkPtr -> do @@ -1316,54 +938,20 @@ toxConferencePeerGetPublicKey tox gn pn = -- | Return true if passed peer_number corresponds to our own. -foreign import ccall tox_conference_peer_number_is_ours :: Tox -> Word32 -> Word32 -> CErr ErrConferencePeerQuery -> IO Bool -toxConferencePeerNumberIsOurs :: Tox -> Word32 -> Word32 -> IO (Either ErrConferencePeerQuery Bool) +toxConferencePeerNumberIsOurs :: ToxPtr -> Word32 -> Word32 -> IO (Either ErrConferencePeerQuery Bool) toxConferencePeerNumberIsOurs tox gn pn = callErrFun $ tox_conference_peer_number_is_ours tox gn pn -data ErrConferenceInvite - = ErrConferenceInviteConferenceNotFound - -- The conference number passed did not designate a valid conference. - - | ErrConferenceInviteFailSend - -- The invite packet failed to send. - deriving (Eq, Ord, Enum, Bounded, Read, Show) - - - -- | Invites a friend to a conference. -- -- @param friend_number The friend number of the friend we want to invite. -- @param conference_number The conference number of the conference we want to invite the friend to. -- -- @return true on success. -foreign import ccall tox_conference_invite :: Tox -> Word32 -> Word32 -> CErr ErrConferenceInvite -> IO Bool -toxConferenceInvite :: Tox -> Word32 -> Word32 -> IO (Either ErrConferenceInvite Bool) +toxConferenceInvite :: ToxPtr -> Word32 -> Word32 -> IO (Either ErrConferenceInvite Bool) toxConferenceInvite tox fn gn = callErrFun $ tox_conference_invite tox fn gn -data ErrConferenceJoin - = ErrConferenceJoinInvalidLength - -- The cookie passed has an invalid length. - - | ErrConferenceJoinWrongType - -- The conference is not the expected type. This indicates an invalid cookie. - - | ErrConferenceJoinFriendNotFound - -- The friend number passed does not designate a valid friend. - - | ErrConferenceJoinDuplicate - -- Client is already in this conference. - - | ErrConferenceJoinInitFail - -- Conference instance failed to initialize. - - | ErrConferenceJoinFailSend - -- The join packet failed to send. - deriving (Eq, Ord, Enum, Bounded, Read, Show) - - - -- | Joins a conference that the client has been invited to. -- -- @param friend_number The friend number of the friend who sent the invite. @@ -1371,29 +959,12 @@ data ErrConferenceJoin -- @param length The size of cookie. -- -- @return conference number on success, UINT32_MAX on failure. -foreign import ccall tox_conference_join :: Tox -> Word32 -> CString -> CSize -> CErr ErrConferenceJoin -> IO Word32 -toxConferenceJoin :: Tox -> Word32 -> BS.ByteString -> IO (Either ErrConferenceJoin Word32) +toxConferenceJoin :: ToxPtr -> Word32 -> BS.ByteString -> IO (Either ErrConferenceJoin Word32) toxConferenceJoin tox fn cookie = BS.useAsCStringLen cookie $ \(cookiePtr, cookieLen) -> callErrFun $ tox_conference_join tox fn cookiePtr (fromIntegral cookieLen) -data ErrConferenceSendMessage - = ErrConferenceSendMessageConferenceNotFound - -- The conference number passed did not designate a valid conference. - - | ErrConferenceSendMessageTooLong - -- The message is too long. - - | ErrConferenceSendMessageNoConnection - -- The client is not connected to the conference. - - | ErrConferenceSendMessageFailSend - -- The message packet failed to send. - deriving (Eq, Ord, Enum, Bounded, Read, Show) - - - -- | Send a text chat message to the conference. -- -- This function creates a conference message packet and pushes it into the send @@ -1410,33 +981,12 @@ data ErrConferenceSendMessage -- @param length Length of the message to be sent. -- -- @return true on success. -foreign import ccall tox_conference_send_message :: Tox -> Word32 -> CEnum MessageType -> CString -> CSize -> CErr ErrConferenceSendMessage -> IO Bool -toxConferenceSendMessage :: Tox -> Word32 -> MessageType -> BS.ByteString -> IO (Either ErrConferenceSendMessage Bool) +toxConferenceSendMessage :: ToxPtr -> Word32 -> MessageType -> BS.ByteString -> IO (Either ErrConferenceSendMessage Bool) toxConferenceSendMessage tox gn messageType message = BS.useAsCStringLen message $ \(msgPtr, msgLen) -> callErrFun $ tox_conference_send_message tox gn (toCEnum messageType) msgPtr (fromIntegral msgLen) -data ErrConferenceTitle - = ErrConferenceTitleConferenceNotFound - -- The conference number passed did not designate a valid conference. - - | ErrConferenceTitleInvalidLength - -- The title is too long or empty. - - | ErrConferenceTitleFailSend - -- The title packet failed to send. - deriving (Eq, Ord, Enum, Bounded, Read, Show) - - - --- | Return the length of the conference title. Return value is unspecified on failure. --- --- The return value is equal to the `length` argument received by the last --- `conference_title` callback. -foreign import ccall tox_conference_get_title_size :: Tox -> Word32 -> CErr ErrConferenceTitle -> IO CSize - - -- | Write the title designated by the given conference number to a byte array. -- -- Call tox_conference_get_title_size to determine the allocation size for the `title` parameter. @@ -1448,9 +998,7 @@ foreign import ccall tox_conference_get_title_size :: Tox -> Word32 -> CErr ErrC -- If this parameter is NULL, this function has no effect. -- -- @return true on success. -foreign import ccall tox_conference_get_title :: Tox -> Word32 -> CString -> CErr ErrConferenceTitle -> IO Bool - -toxConferenceGetTitle :: Tox -> Word32 -> IO (Either ErrConferenceTitle BS.ByteString) +toxConferenceGetTitle :: ToxPtr -> Word32 -> IO (Either ErrConferenceTitle BS.ByteString) toxConferenceGetTitle tox gn = do titleLenRes <- callErrFun $ tox_conference_get_title_size tox gn case titleLenRes of @@ -1466,38 +1014,22 @@ toxConferenceGetTitle tox gn = do -- Title length cannot be longer than TOX_MAX_NAME_LENGTH. -- -- @return true on success. -foreign import ccall tox_conference_set_title :: Tox -> Word32 -> CString -> CSize -> CErr ErrConferenceTitle -> IO Bool -toxConferenceSetTitle :: Tox -> Word32 -> BS.ByteString -> IO (Either ErrConferenceTitle Bool) +toxConferenceSetTitle :: ToxPtr -> Word32 -> BS.ByteString -> IO (Either ErrConferenceTitle Bool) toxConferenceSetTitle tox gn title = BS.useAsCStringLen title $ \(titlePtr, titleLen) -> callErrFun $ tox_conference_set_title tox gn titlePtr (fromIntegral titleLen) --- | Return the number of conferences in the Tox instance. --- This should be used to determine how much memory to allocate for `tox_conference_get_chatlist`. -foreign import ccall tox_conference_get_chatlist_size :: Tox -> IO CSize - - -- | Copy a list of valid conference IDs into the array chatlist. Determine how much space -- to allocate for the array with the `tox_conference_get_chatlist_size` function. -foreign import ccall tox_conference_get_chatlist :: Tox -> Ptr Word32 -> IO () - -toxConferenceGetChatlist :: Tox -> IO [Word32] +toxConferenceGetChatlist :: ToxPtr -> IO [Word32] toxConferenceGetChatlist tox = do chatListSize <- tox_conference_get_chatlist_size tox allocaArray (fromIntegral chatListSize) $ \chatListPtr -> do tox_conference_get_chatlist tox chatListPtr peekArray (fromIntegral chatListSize) chatListPtr --- | Returns the type of conference (TOX_CONFERENCE_TYPE) that conference_number is. Return value is --- unspecified on failure. -data ErrConferenceGetType - = ErrConferenceGetTypeConferenceNotFound - -- The conference number passed did not designate a valid conference. - deriving (Eq, Ord, Enum, Bounded, Read, Show) - -foreign import ccall tox_conference_get_type :: Tox -> Word32 -> CErr ErrConferenceGetType -> IO (CEnum ConferenceType) -toxConferenceGetType :: Tox -> Word32 -> IO (Either ErrConferenceGetType ConferenceType) +toxConferenceGetType :: ToxPtr -> Word32 -> IO (Either ErrConferenceGetType ConferenceType) toxConferenceGetType tox gn = callErrFun (tox_conference_get_type tox gn >=> (return . fromCEnum)) @@ -1508,32 +1040,6 @@ toxConferenceGetType tox gn = callErrFun (tox_conference_get_type tox gn >=> (re -------------------------------------------------------------------------------- -data ErrFriendCustomPacket - = ErrFriendCustomPacketNull - -- One of the arguments to the function was 'nullPtr' when it was not - -- expected. - - | ErrFriendCustomPacketFriendNotFound - -- The friend number did not designate a valid friend. - - | ErrFriendCustomPacketFriendNotConnected - -- This client is currently not connected to the friend. - - | ErrFriendCustomPacketInvalid - -- The first byte of data was not in the specified range for the packet - -- type. This range is 200-254 for lossy, and 160-191 for lossless packets. - - | ErrFriendCustomPacketEmpty - -- Attempted to send an empty packet. - - | ErrFriendCustomPacketTooLong - -- Packet data length exceeded 'tox_max_custom_packet_size'. - - | ErrFriendCustomPacketSendq - -- Packet queue is full. - deriving (Eq, Ord, Enum, Bounded, Read, Show) - - -- | Send a custom lossy packet to a friend. -- -- The first byte of data must be in the range 200-254. Maximum length of a @@ -1552,8 +1058,7 @@ data ErrFriendCustomPacket -- @param length The length of the packet data byte array. -- -- @return true on success. -foreign import ccall tox_friend_send_lossy_packet :: Tox -> Word32 -> CString -> CSize -> CErr ErrFriendCustomPacket -> IO Bool -toxFriendLossyPacket :: Tox -> Word32 -> BS.ByteString -> IO (Either ErrFriendCustomPacket Bool) +toxFriendLossyPacket :: ToxPtr -> Word32 -> BS.ByteString -> IO (Either ErrFriendCustomPacket Bool) toxFriendLossyPacket tox fn d = BS.useAsCStringLen d $ \(dataPtr, dataLen) -> callErrFun $ tox_friend_send_lossy_packet tox fn dataPtr (fromIntegral dataLen) @@ -1572,8 +1077,7 @@ toxFriendLossyPacket tox fn d = -- @param length The length of the packet data byte array. -- -- @return true on success. -foreign import ccall tox_friend_send_lossless_packet :: Tox -> Word32 -> CString -> CSize -> CErr ErrFriendCustomPacket -> IO Bool -toxFriendLosslessPacket :: Tox -> Word32 -> BS.ByteString -> IO (Either ErrFriendCustomPacket Bool) +toxFriendLosslessPacket :: ToxPtr -> Word32 -> BS.ByteString -> IO (Either ErrFriendCustomPacket Bool) toxFriendLosslessPacket tox fn d = BS.useAsCStringLen d $ \(dataPtr, dataLen) -> callErrFun $ tox_friend_send_lossless_packet tox fn dataPtr (fromIntegral dataLen) @@ -1597,28 +1101,18 @@ toxFriendLosslessPacket tox fn d = -- -- @param dht_id A memory region of at least 'tox_public_key_size' bytes. If -- this parameter is 'nullPtr', this function has no effect. -foreign import ccall tox_self_get_dht_id :: Tox -> CString -> IO () - -toxSelfGetDhtId :: Tox -> IO BS.ByteString +toxSelfGetDhtId :: ToxPtr -> IO BS.ByteString toxSelfGetDhtId tox = let idLen = fromIntegral tox_public_key_size in allocaArray idLen $ \idPtr -> do tox_self_get_dht_id tox idPtr BS.packCStringLen (idPtr, idLen) -data ErrGetPort - = ErrGetPortNotBound - -- The instance was not bound to any port. - deriving (Eq, Ord, Enum, Bounded, Read, Show) - - -- | Return the UDP port this Tox instance is bound to. -foreign import ccall tox_self_get_udp_port :: Tox -> CErr ErrGetPort -> IO Word16 -toxSelfGetUdpPort :: Tox -> IO (Either ErrGetPort Word16) +toxSelfGetUdpPort :: ToxPtr -> IO (Either ErrGetPort Word16) toxSelfGetUdpPort tox = callErrFun $ tox_self_get_udp_port tox -- | Return the TCP port this Tox instance is bound to. This is only relevant if -- the instance is acting as a TCP relay. -foreign import ccall tox_self_get_tcp_port :: Tox -> CErr ErrGetPort -> IO Word16 -toxSelfGetTcpPort :: Tox -> IO (Either ErrGetPort Word16) -toxSelfGetTcpPort tox = callErrFun $ tox_self_get_udp_port tox +toxSelfGetTcpPort :: ToxPtr -> IO (Either ErrGetPort Word16) +toxSelfGetTcpPort tox = callErrFun $ tox_self_get_tcp_port tox diff --git a/src/Network/Tox/C/Type.hs b/src/Network/Tox/C/Type.hs index d370f1d..69781cd 100644 --- a/src/Network/Tox/C/Type.hs +++ b/src/Network/Tox/C/Type.hs @@ -9,8 +9,7 @@ import qualified Data.ByteString as BS import Data.MessagePack (MessagePack) import GHC.Generics (Generic) import GHC.TypeNats (Nat) -import Test.QuickCheck.Arbitrary (Arbitrary (..), - arbitraryBoundedEnum) +import Test.QuickCheck.Arbitrary (Arbitrary (..)) newtype FixedByteString (size :: Nat) = FixedByteString BS.ByteString @@ -23,93 +22,3 @@ instance Arbitrary (FixedByteString size) where type PublicKey = FixedByteString 32 - - --- | Protocols that can be used to connect to the network or friends. -data Connection - = ConnectionNone - -- There is no connection. This instance, or the friend the state change is - -- about, is now offline. - - | ConnectionTcp - -- A TCP connection has been established. For the own instance, this means - -- it is connected through a TCP relay, only. For a friend, this means that - -- the connection to that particular friend goes through a TCP relay. - - | ConnectionUdp - -- A UDP connection has been established. For the own instance, this means - -- it is able to send UDP packets to DHT nodes, but may still be connected - -- to a TCP relay. For a friend, this means that the connection to that - -- particular friend was built using direct UDP packets. - deriving (Eq, Ord, Enum, Bounded, Read, Show, Generic) - -instance MessagePack Connection -instance Arbitrary Connection where - arbitrary = arbitraryBoundedEnum - - --- | Represents the possible statuses a client can have. -data UserStatus - = UserStatusNone - -- ^ User is online and available. - | UserStatusAway - -- ^ User is away. Clients can set this e.g. after a user defined inactivity - -- time. - | UserStatusBusy - -- ^ User is busy. Signals to other clients that this client does not - -- currently wish to communicate. - deriving (Eq, Ord, Enum, Bounded, Read, Show, Generic) - -instance MessagePack UserStatus -instance Arbitrary UserStatus where - arbitrary = arbitraryBoundedEnum - - --- | Represents message types for tox_friend_send_message and group chat --- messages. -data MessageType - = MessageTypeNormal - -- ^ Normal text message. Similar to PRIVMSG on IRC. - | MessageTypeAction - -- ^ A message describing an user action. This is similar to /me (CTCP - -- ACTION) on IRC. - deriving (Eq, Ord, Enum, Bounded, Read, Show, Generic) - -instance MessagePack MessageType -instance Arbitrary MessageType where - arbitrary = arbitraryBoundedEnum - - -data FileControl - = FileControlResume - -- Sent by the receiving side to accept a file send request. Also sent after - -- a FileControlPause command to continue sending or receiving. - - | FileControlPause - -- Sent by clients to pause the file transfer. The initial state of a file - -- transfer is always paused on the receiving side and running on the - -- sending side. If both the sending and receiving side pause the transfer, - -- then both need to send FileControlResume for the transfer to resume. - - | FileControlCancel - -- Sent by the receiving side to reject a file send request before any other - -- commands are sent. Also sent by either side to terminate a file transfer. - deriving (Eq, Ord, Enum, Bounded, Read, Show, Generic) - -instance MessagePack FileControl -instance Arbitrary FileControl where - arbitrary = arbitraryBoundedEnum - - --- | Conference types for the conference_invite event. -data ConferenceType - = ConferenceTypeText - -- Text-only conferences that must be accepted with the tox_conference_join function. - - | ConferenceTypeAv - -- Video conference. The function to accept these is in toxav. - deriving (Eq, Ord, Enum, Bounded, Read, Show, Generic) - -instance MessagePack ConferenceType -instance Arbitrary ConferenceType where - arbitrary = arbitraryBoundedEnum diff --git a/src/Network/Tox/Types/Events.hs b/src/Network/Tox/Types/Events.hs index a19ff0a..f0df35b 100644 --- a/src/Network/Tox/Types/Events.hs +++ b/src/Network/Tox/Types/Events.hs @@ -6,11 +6,11 @@ module Network.Tox.Types.Events where import qualified Data.ByteString as BS import Data.MessagePack (MessagePack) import Data.Word (Word16, Word32, Word64) -import GHC.Generics (Generic) -import Network.Tox.C.Type (ConferenceType, +import FFI.Tox.Tox (ConferenceType, Connection, FileControl, - MessageType, PublicKey, - UserStatus) + MessageType, UserStatus) +import GHC.Generics (Generic) +import Network.Tox.C.Type (PublicKey) import Test.QuickCheck.Arbitrary (Arbitrary (..)) import Test.QuickCheck.Arbitrary.Generic (genericArbitrary, genericShrink) diff --git a/test/Network/Tox/C/ToxSpec.hs b/test/Network/Tox/C/ToxSpec.hs index 37cf5b0..d8e9315 100644 --- a/test/Network/Tox/C/ToxSpec.hs +++ b/test/Network/Tox/C/ToxSpec.hs @@ -16,14 +16,6 @@ boxPK, boxSK :: Int boxPK = 32 boxSK = 32 -instance Arbitrary C.ProxyType where - shrink = genericShrink - arbitrary = arbitraryBoundedEnum - -instance Arbitrary C.SavedataType where - shrink = genericShrink - arbitrary = arbitraryBoundedEnum - -- | Ensure that the hostname has a chance of being valid. filterHost :: C.Options -> C.Options filterHost o@C.Options{C.proxyHost = h} = o{C.proxyHost = filter (`elem` hostChars) h} diff --git a/test/Network/Tox/Types/EventsSpec.hs b/test/Network/Tox/Types/EventsSpec.hs index 2e64b20..84fd8d8 100644 --- a/test/Network/Tox/Types/EventsSpec.hs +++ b/test/Network/Tox/Types/EventsSpec.hs @@ -29,7 +29,7 @@ processEvent SelfConnectionStatus{} = return True processEvent _ = return False -toxIterate :: Int -> [C.Tox] -> IO () +toxIterate :: Int -> [C.ToxPtr] -> IO () toxIterate 0 _ = expectationFailure "could not bootstrap" toxIterate countdown toxes = do @@ -69,6 +69,6 @@ spec = do must $ C.withTox C.defaultOptions $ \tox2 -> do bootstrapPort <- must $ C.toxSelfGetUdpPort tox1 bootstrapKey <- C.toxSelfGetDhtId tox1 - must $ C.toxBootstrap tox2 "127.0.0.1" bootstrapPort bootstrapKey + _ <- must $ C.toxBootstrap tox2 "127.0.0.1" bootstrapPort bootstrapKey toxIterate 100 [tox1, tox2] diff --git a/tools/BUILD.bazel b/tools/BUILD.bazel index 9174b13..4e25318 100644 --- a/tools/BUILD.bazel +++ b/tools/BUILD.bazel @@ -1,18 +1,5 @@ load("@rules_haskell//haskell:defs.bzl", "haskell_binary") -haskell_binary( - name = "gen-struct", - srcs = ["gen-struct.hs"], - deps = [ - "//hs-schema", - "//hs-toxcore-c", - "//third_party/haskell:base", - "//third_party/haskell:bytestring", - "//third_party/haskell:data-fix", - "//third_party/haskell:groom", - ], -) - haskell_binary( name = "groupbot", srcs = ["groupbot.hs"], diff --git a/tools/gen-struct.hs b/tools/gen-struct.hs deleted file mode 100644 index 4eaefe5..0000000 --- a/tools/gen-struct.hs +++ /dev/null @@ -1,67 +0,0 @@ -{-# OPTIONS_GHC -Wno-orphans #-} -{-# LANGUAGE DataKinds #-} -{-# LANGUAGE KindSignatures #-} -{-# LANGUAGE OverloadedStrings #-} -{-# LANGUAGE ScopedTypeVariables #-} -module Main (main) where - -import Control.Monad (when) -import Data.ByteString (ByteString) -import qualified Data.ByteString as BS -import Data.Fix (Fix (..)) -import Data.Proxy (Proxy (..)) -import Data.Schema (Schema, SchemaF (..), Type (..)) -import Data.Schema.Builder (Builder (..), ToSchema (..), atom) -import Data.Schema.C (genC) -import Data.Schema.Deinline (deinline) -import Data.Schema.Pretty (ppSchema) -import Data.Word (Word16, Word32, Word64) -import GHC.TypeNats (KnownNat, Nat, natVal) -import Text.Groom (groom) - -import Network.Tox.C.Type -import Network.Tox.Types.Events - - -instance KnownNat size => ToSchema (FixedByteString (size :: Nat)) where - toSchema = atom (TyFixedBin (fromIntegral $ natVal (Proxy :: Proxy size))) (FixedByteString BS.empty) - -instance ToSchema ByteString where - toSchema = atom TyBin BS.empty -instance ToSchema Word16 where - toSchema = atom TyWord16 0 -instance ToSchema Word32 where - toSchema = atom TyWord32 0 -instance ToSchema Word64 where - toSchema = atom TyWord64 0 -instance ToSchema Bool where - toSchema = atom TyBool False - -instance ToSchema Connection -instance ToSchema MessageType -instance ToSchema ConferenceType -instance ToSchema FileControl -instance ToSchema UserStatus -instance ToSchema Event -instance ToSchema Events - - -schemas :: Schema -schemas = deinline $ Fix . Schema $ - [ getSchema (toSchema :: Builder ConferenceType) - , getSchema (toSchema :: Builder Connection) - , getSchema (toSchema :: Builder FileControl) - , getSchema (toSchema :: Builder MessageType) - , getSchema (toSchema :: Builder UserStatus) - , getSchema (toSchema :: Builder Events) - ] - -main :: IO () -main = do - when True $ - -- putStrLn . groom $ schemas - putStrLn . groom $ getSchema (toSchema :: Builder Connection) - when False $ - print . ppSchema $ schemas - when False $ - print . genC . getSchema $ (toSchema :: Builder Event) diff --git a/tools/groupbot.hs b/tools/groupbot.hs index a1d30d1..12ce768 100644 --- a/tools/groupbot.hs +++ b/tools/groupbot.hs @@ -68,7 +68,7 @@ must = (getRight =<<) newtype UserData = UserData { groupNumber :: Word32 } deriving (Read, Show) -handleEvent :: C.Tox -> UserData -> Event -> IO UserData +handleEvent :: C.ToxPtr -> UserData -> Event -> IO UserData handleEvent tox ud@(UserData gn) = \case SelfConnectionStatus{ connectionStatus } -> do putStrLn "SelfConnectionStatusCb" @@ -120,7 +120,7 @@ handleEvent tox ud@(UserData gn) = \case _ -> return ud -loop :: C.Tox -> UserData -> IO () +loop :: C.ToxPtr -> UserData -> IO () loop tox ud = do interval <- C.toxIterationInterval tox threadDelay $ fromIntegral $ interval * 10000 @@ -135,7 +135,7 @@ main = do exists <- doesFileExist savedataFilename loadedSavedata <- if exists then BS.readFile savedataFilename else return BS.empty must $ C.withTox (options loadedSavedata) $ \tox -> do - must $ C.toxBootstrap tox bootstrapHost 33445 bootstrapKey + _ <- must $ C.toxBootstrap tox bootstrapHost 33445 bootstrapKey adr <- C.toxSelfGetAddress tox putStrLn $ (BS.unpack . Base16.encode) adr diff --git a/toxcore-c.cabal b/toxcore-c.cabal index 9ddbb2f..ff0c4af 100644 --- a/toxcore-c.cabal +++ b/toxcore-c.cabal @@ -25,8 +25,9 @@ library ghc-options: -Wall extra-libraries: toxcore exposed-modules: + FFI.Tox.Tox + Foreign.C.Enum Network.Tox.C - Network.Tox.C.CEnum Network.Tox.C.Constants Network.Tox.C.Options Network.Tox.C.Tox @@ -56,20 +57,6 @@ executable groupbot , text , toxcore-c -executable gen-struct - default-language: Haskell2010 - hs-source-dirs: tools - ghc-options: -Wall -Wno-unused-imports - extra-libraries: toxcore - main-is: gen-struct.hs - build-depends: - base <5 - , bytestring - , data-fix - , groom - , schema >=0.0.3 - , toxcore-c - test-suite testsuite default-language: Haskell2010 type: exitcode-stdio-1.0