Websocket Provider

Detailed Description

Classes

class  BinaryNinja::WebsocketClient
 
class  BinaryNinja::CoreWebsocketClient
 
class  BinaryNinja::WebsocketProvider
 

Class Documentation

◆ BinaryNinja::WebsocketClient

class BinaryNinja::WebsocketClient

Public Member Functions

bool Connect (const std::string &host, const std::unordered_map< std::string, std::string > &headers, BNWebsocketClientOutputCallbacks *callbacks)
 Connect to a given url, asynchronously. More...
 
virtual bool Write (const std::vector< uint8_t > &data)=0
 Write some data to the websocket. More...
 
virtual bool Disconnect ()=0
 Disconnect the websocket. More...
 
- Public Member Functions inherited from BinaryNinja::CoreRefCountObject< BNWebsocketClient, BNNewWebsocketClientReference, BNFreeWebsocketClient >
 CoreRefCountObject ()
 
virtual ~CoreRefCountObject ()
 
BNWebsocketClientGetObject () const
 
void AddRef ()
 
void Release ()
 
void AddRefForRegistration ()
 
void ReleaseForRegistration ()
 
void AddRefForCallback ()
 
void ReleaseForCallback ()
 

Protected Member Functions

 WebsocketClient (WebsocketProvider *provider)
 
 WebsocketClient (BNWebsocketClient *instance)
 
bool ReadData (uint8_t *data, uint64_t len)
 
virtual void DestroyClient ()
 Cleanup any resources created by the client. More...
 
virtual bool Connect (const std::string &host, const std::unordered_map< std::string, std::string > &headers)=0
 Virtual method for performing the connection, overridden by a subclass. More...
 

Static Protected Member Functions

static void DestroyClientCallback (void *ctxt)
 
static bool ConnectCallback (void *ctxt, const char *host, uint64_t headerCount, const char *const *headerKeys, const char *const *headerValues)
 
static bool WriteCallback (const uint8_t *data, uint64_t len, void *ctxt)
 
static bool DisconnectCallback (void *ctxt)
 
static void ErrorCallback (const char *msg, void *ctxt)
 

Additional Inherited Members

- Static Public Member Functions inherited from BinaryNinja::CoreRefCountObject< BNWebsocketClient, BNNewWebsocketClientReference, BNFreeWebsocketClient >
static BNWebsocketClientGetObject (CoreRefCountObject *obj)
 
static BNWebsocketClientGetObject (const CoreRefCountObject *obj)
 
- Public Attributes inherited from BinaryNinja::CoreRefCountObject< BNWebsocketClient, BNNewWebsocketClientReference, BNFreeWebsocketClient >
std::atomic< int > m_refs
 
bool m_registeredRef
 
BNWebsocketClientm_object
 

Constructor & Destructor Documentation

◆ WebsocketClient() [1/2]

WebsocketClient::WebsocketClient ( WebsocketProvider provider)
protected

◆ WebsocketClient() [2/2]

WebsocketClient::WebsocketClient ( BNWebsocketClient instance)
protected

Member Function Documentation

◆ DestroyClientCallback()

void WebsocketClient::DestroyClientCallback ( void *  ctxt)
staticprotected

◆ ConnectCallback()

bool WebsocketClient::ConnectCallback ( void *  ctxt,
const char *  host,
uint64_t  headerCount,
const char *const *  headerKeys,
const char *const *  headerValues 
)
staticprotected

◆ WriteCallback()

bool WebsocketClient::WriteCallback ( const uint8_t *  data,
uint64_t  len,
void *  ctxt 
)
staticprotected

◆ DisconnectCallback()

bool WebsocketClient::DisconnectCallback ( void *  ctxt)
staticprotected

◆ ErrorCallback()

void WebsocketClient::ErrorCallback ( const char *  msg,
void *  ctxt 
)
staticprotected

◆ ReadData()

bool WebsocketClient::ReadData ( uint8_t *  data,
uint64_t  len 
)
protected

◆ DestroyClient()

void WebsocketClient::DestroyClient ( )
protectedvirtual

Cleanup any resources created by the client.

◆ Connect() [1/2]

virtual bool BinaryNinja::WebsocketClient::Connect ( const std::string &  host,
const std::unordered_map< std::string, std::string > &  headers 
)
protectedpure virtual

Virtual method for performing the connection, overridden by a subclass.

Parameters
hostFull url with scheme, domain, optionally port, and path
headersHTTP header keys and values
Returns
True if the connection has started, but not necessarily if it succeeded

Implemented in BinaryNinja::CoreWebsocketClient.

◆ Connect() [2/2]

bool WebsocketClient::Connect ( const std::string &  host,
const std::unordered_map< std::string, std::string > &  headers,
BNWebsocketClientOutputCallbacks callbacks 
)

Connect to a given url, asynchronously.

The connection will be run in a separate thread managed by the websocket provider.

Callbacks will be called **on the thread of the connection**, so be sure to ExecuteOnMainThread any long-running or gui operations in the callbacks.

If the connection succeeds, connectedCallback will be called. On normal termination, disconnectedCallback will be called. If the connection succeeds, but later fails, disconnectedCallback will not be called, and errorCallback will be called instead. If the connection fails, neither connectedCallback nor disconnectedCallback will be called, and errorCallback will be called instead.

If connectedCallback or readCallback return false, the connection will be aborted.

Parameters
hostFull url with scheme, domain, optionally port, and path
headersHTTP header keys and values
callbacksStructure with callbacks for various websocket events
Returns
True if the connection has started, but not necessarily if it succeeded

◆ Write()

virtual bool BinaryNinja::WebsocketClient::Write ( const std::vector< uint8_t > &  data)
pure virtual

Write some data to the websocket.

Parameters
dataData to write
Returns
True if successful

Implemented in BinaryNinja::CoreWebsocketClient.

◆ Disconnect()

virtual bool BinaryNinja::WebsocketClient::Disconnect ( )
pure virtual

Disconnect the websocket.

Returns
True if successful

Implemented in BinaryNinja::CoreWebsocketClient.

◆ BinaryNinja::CoreWebsocketClient

class BinaryNinja::CoreWebsocketClient

Public Member Functions

 CoreWebsocketClient (BNWebsocketClient *instance)
 
virtual ~CoreWebsocketClient ()
 
virtual bool Connect (const std::string &host, const std::unordered_map< std::string, std::string > &headers) override
 Virtual method for performing the connection, overridden by a subclass. More...
 
virtual bool Write (const std::vector< uint8_t > &data) override
 Write some data to the websocket. More...
 
virtual bool Disconnect () override
 Disconnect the websocket. More...
 
- Public Member Functions inherited from BinaryNinja::WebsocketClient
bool Connect (const std::string &host, const std::unordered_map< std::string, std::string > &headers, BNWebsocketClientOutputCallbacks *callbacks)
 Connect to a given url, asynchronously. More...
 
virtual bool Write (const std::vector< uint8_t > &data)=0
 Write some data to the websocket. More...
 
virtual bool Disconnect ()=0
 Disconnect the websocket. More...
 
- Public Member Functions inherited from BinaryNinja::CoreRefCountObject< BNWebsocketClient, BNNewWebsocketClientReference, BNFreeWebsocketClient >
 CoreRefCountObject ()
 
virtual ~CoreRefCountObject ()
 
BNWebsocketClientGetObject () const
 
void AddRef ()
 
void Release ()
 
void AddRefForRegistration ()
 
void ReleaseForRegistration ()
 
void AddRefForCallback ()
 
void ReleaseForCallback ()
 

Additional Inherited Members

- Static Public Member Functions inherited from BinaryNinja::CoreRefCountObject< BNWebsocketClient, BNNewWebsocketClientReference, BNFreeWebsocketClient >
static BNWebsocketClientGetObject (CoreRefCountObject *obj)
 
static BNWebsocketClientGetObject (const CoreRefCountObject *obj)
 
- Public Attributes inherited from BinaryNinja::CoreRefCountObject< BNWebsocketClient, BNNewWebsocketClientReference, BNFreeWebsocketClient >
std::atomic< int > m_refs
 
bool m_registeredRef
 
BNWebsocketClientm_object
 
- Protected Member Functions inherited from BinaryNinja::WebsocketClient
 WebsocketClient (WebsocketProvider *provider)
 
 WebsocketClient (BNWebsocketClient *instance)
 
bool ReadData (uint8_t *data, uint64_t len)
 
virtual void DestroyClient ()
 Cleanup any resources created by the client. More...
 
virtual bool Connect (const std::string &host, const std::unordered_map< std::string, std::string > &headers)=0
 Virtual method for performing the connection, overridden by a subclass. More...
 
- Static Protected Member Functions inherited from BinaryNinja::WebsocketClient
static void DestroyClientCallback (void *ctxt)
 
static bool ConnectCallback (void *ctxt, const char *host, uint64_t headerCount, const char *const *headerKeys, const char *const *headerValues)
 
static bool WriteCallback (const uint8_t *data, uint64_t len, void *ctxt)
 
static bool DisconnectCallback (void *ctxt)
 
static void ErrorCallback (const char *msg, void *ctxt)
 

Constructor & Destructor Documentation

◆ CoreWebsocketClient()

CoreWebsocketClient::CoreWebsocketClient ( BNWebsocketClient instance)

◆ ~CoreWebsocketClient()

virtual BinaryNinja::CoreWebsocketClient::~CoreWebsocketClient ( )
inlinevirtual

Member Function Documentation

◆ Connect()

bool CoreWebsocketClient::Connect ( const std::string &  host,
const std::unordered_map< std::string, std::string > &  headers 
)
overridevirtual

Virtual method for performing the connection, overridden by a subclass.

Parameters
hostFull url with scheme, domain, optionally port, and path
headersHTTP header keys and values
Returns
True if the connection has started, but not necessarily if it succeeded

Implements BinaryNinja::WebsocketClient.

◆ Write()

bool CoreWebsocketClient::Write ( const std::vector< uint8_t > &  data)
overridevirtual

Write some data to the websocket.

Parameters
dataData to write
Returns
True if successful

Implements BinaryNinja::WebsocketClient.

◆ Disconnect()

bool CoreWebsocketClient::Disconnect ( )
overridevirtual

Disconnect the websocket.

Returns
True if successful

Implements BinaryNinja::WebsocketClient.

◆ BinaryNinja::WebsocketProvider

class BinaryNinja::WebsocketProvider

Public Member Functions

virtual Ref< WebsocketClientCreateNewClient ()=0
 
- Public Member Functions inherited from BinaryNinja::StaticCoreRefCountObject< BNWebsocketProvider >
 StaticCoreRefCountObject ()
 
virtual ~StaticCoreRefCountObject ()
 
BNWebsocketProviderGetObject () const
 
void AddRef ()
 
void Release ()
 
void AddRefForRegistration ()
 
void AddRefForCallback ()
 
void ReleaseForCallback ()
 

Static Public Member Functions

static std::vector< Ref< WebsocketProvider > > GetList ()
 
static Ref< WebsocketProviderGetByName (const std::string &name)
 
static void Register (WebsocketProvider *provider)
 
- Static Public Member Functions inherited from BinaryNinja::StaticCoreRefCountObject< BNWebsocketProvider >
static BNWebsocketProviderGetObject (StaticCoreRefCountObject *obj)
 

Protected Member Functions

 WebsocketProvider (const std::string &name)
 
 WebsocketProvider (BNWebsocketProvider *provider)
 

Static Protected Member Functions

static BNWebsocketClientCreateClientCallback (void *ctxt)
 

Additional Inherited Members

- Public Attributes inherited from BinaryNinja::StaticCoreRefCountObject< BNWebsocketProvider >
std::atomic< int > m_refs
 
BNWebsocketProviderm_object
 

Constructor & Destructor Documentation

◆ WebsocketProvider() [1/2]

BinaryNinja::WebsocketProvider::WebsocketProvider ( const std::string &  name)
protected

◆ WebsocketProvider() [2/2]

WebsocketProvider::WebsocketProvider ( BNWebsocketProvider provider)
protected

Member Function Documentation

◆ CreateClientCallback()

BNWebsocketClient * WebsocketProvider::CreateClientCallback ( void *  ctxt)
staticprotected

◆ CreateNewClient()

virtual Ref< WebsocketClient > BinaryNinja::WebsocketProvider::CreateNewClient ( )
pure virtual

◆ GetList()

vector< Ref< WebsocketProvider > > WebsocketProvider::GetList ( )
static

◆ GetByName()

Ref< WebsocketProvider > WebsocketProvider::GetByName ( const std::string &  name)
static

◆ Register()

void WebsocketProvider::Register ( WebsocketProvider provider)
static