PrevNextUpHome SophiaFramework UNIVERSE 5.3
SFXSSLSocket
Class for the SSL socket communication.
#include <SFXSSLSocket.h.hpp>
class SFXSSLSocket : public SFXStorage;
typedef SFXSSLSocket&   SFXSSLSocketRef;
typedef SFXSSLSocket*   SFXSSLSocketPtr;
typedef SFXSSLSocket*&  SFXSSLSocketPtrRef;
typedef SFXSSLSocket**  SFXSSLSocketHandle;
typedef const SFXSSLSocket     ConstSFXSSLSocket;
typedef const SFXSSLSocket&    ConstSFXSSLSocketRef;
typedef const SFXSSLSocket*    ConstSFXSSLSocketPtr;
typedef const SFXSSLSocket*&   ConstSFXSSLSocketPtrRef;
typedef const SFXSSLSocket**   ConstSFXSSLSocketHandle;

Inheritance diagram

 Inheritance diagram of SFXSSLSocketClass

Collaboration diagram

 Collaboration diagram of SFXSSLSocketClass

Description

The SFXSSLSocket class provides the functions to implement the SSL client only.

In this class, data can be sent and received using the stream.

When the stream is not used, data can be sent and received with the SFXSSLSocket::Write / SFXSSLSocket::Read function.

[Note] Note

The SFXSSLSocket class encapsulates BREW API ISocket/ BREW API ISSL interface to provide high level functions for the SSL socket communication.

How to implement the SSL client

The SSL client can be implemented by taking the following procedures with the SFXSSLSocket class.

  1. Create the SFXSSLSocket instance, that is, the SSL socket.
  2. Open the SSL socket using the SFXSSLSocket::Open function.
  3. Bind the local IP address and port number to the TCP socket with the SFXTCPSocket::Bind function, if necessary. If binding is omitted, default port number will be bound to the TCP socket.
  4. Set the trust mode(default: SSL_TRUST_MODE_FAIL) using the SFXSSLSocket::SetTrustMode function.
  5. Connect(or send connection request) to the SSL server using the SFXSSLSocket::Connect funtion, and also regiter the callback function.
  6. The connection result will be notified to the callback function registered with the SFXSSLSocket::Connect function.
  7. Negotiate with the SSL server using the SFXSSLSocket::Negotiate function, and also regiter the callback function.
  8. The negotiation result will be notified to the callback function registered with the SFXSSLSocket::Negotiate function.
  9. To receive data, get the input stream. When the stream is not used, data can be received with the SFXSSLSocket::Read function.
  10. To send data, get the output stream. When the stream is not used, data can be sent with the SFXSSLSocket::Write function.
  11. Step 9. and 10. are repeated until no other data needs to be sent or received.
  12. Close the SSL socket using the SFXSSLSocket::Close function.

Example 842. Implementation of the SSL Client

// *** segments different from TCP are in bold
// The _socket variable is defined as class member variable since used in the callback function
class MyClass {
private:
    SFXSSLSocket _socket;
    SFXAnsiStringStreamWriter _writer; // output stream
    SFXAnsiStringStreamReader _reader; // input stream

public:
    Void Start(Void);

    // callback functions
    XALLBACK_DECLARE_SFXSSLSOCKET(OnConnect)
    XALLBACK_DECLARE_SFXSSLSOCKET(OnNegotiate)
    XALLBACK_DECLARE_SFXANSISTRINGSTREAMWRITER(OnFlush)
    XALLBACK_DECLARE_SFXANSISTRINGSTREAMREADER(OnFetch)
};

Void MyClass::Start(Void)
{
    SFCError error;
    SFXSocketAddress host("www.example.com:995");

    // open SSL socket
    if ((error = _socket.Open()) == SFERR_NO_ERROR) {
 
        // connect to www.example.com:443
        // *1 the connection result will be notified to the OnConnect function
        // *2 host name is automatically resolved
        error = _socket.Connect(host, XALLBACK_INTERNAL(OnConnect));
    }
    if (error != SFERR_NO_ERROR) { 
        // if an error occurs
        _socket.Close();
    }
    return;
}

// callback function notified of the connection result
XALLBACK_IMPLEMENT_SFXSSLSOCKET(MyClass, OnConnect, error)
{
    if (error == SFERR_NO_ERROR) { 

        // perform SSL Negotiation with server
        // * result of SSL negotiation will be notified to the OnNegotiate function
        error = _socket.Negotiate(XALLBACK_INTERNAL(OnNegotiate));
    }
    if (error != SFERR_NO_ERROR) { 

        // if an error occurs
        _socket.Close();
    }
    return;
}

// callback function notified of result of SSL negotiation
XALLBACK_IMPLEMENT_SFXSSLSOCKET(MyClass, OnNegotiate, error)
{
    static AChar message[] = "GET / HTTP/1.0\r\n\r\n";

    if (error == SFERR_NO_ERROR) {

        // get output stream for sending data to SSL socket (buffer size: 1024)
        if ((error = _socket.GetStreamWriter(1024, &_writer))
            == SFERR_NO_ERROR) {

            // write data from the message variable into output stream buffer
            if ((error = _writer.Write(message, lengthof(message))) == SFERR_NO_ERROR) {

                // perform flush: send data from output stream buffer to SSL socket actually
                // * the flush result will be notified to the OnFlush function
                error = _writer.Flush(XALLBACK_INTERNAL(OnFlush));
            }
            if (error != SFERR_NO_ERROR) { 
                // if an error occurs
                 _writer.Release();
            }
        }
    }
    if (error != SFERR_NO_ERROR) { 
       // if an error occurs
       _socket.Close();
    }
    return;
}

// callback function notified of the flush result
XALLBACK_IMPLEMENT_SFXANSISTRINGSTREAMWRITER(MyClass, OnFlush, error)
{
    // release output stream since all data is sent
    _writer.Release();

    if (error == SFERR_NO_ERROR) {

        // get input stream for receive data from SSL socket (buffer size: 1024)
        if ((error = _socket.GetStreamReader(1024, &_reader)) == SFERR_NO_ERROR) {

            // perform fetch: receive data from SSL socket to input stream  buffer actually 
            // * the fetch result will be notified to the OnFetch function
            if ((error = _reader.Fetch(XALLBACK_INTERNAL(OnFetch))) != SFERR_NO_ERROR) { 

                // if an error occurs
               _reader.Release(); 
            }
        }
    }

    if (error != SFERR_NO_ERROR) { 
        // if an error occurs
        _socket.Close();
    }

    return;
}

// callback function notified of the fetch result
XALLBACK_IMPLEMENT_SFXANSISTRINGSTREAMREADER(MyClass, OnFetch, error)
{
    SFXAnsiString string;

    if (error == SFERR_NO_ERROR) {

        // read data from input stream buffer into the string variable
        _reader >> string;

        // display the received data on BREW Output Window
        TRACE("%s", string.GetCString());
    }

    // release input stream since all data is received
    _reader.Release();

    // close SSL socket
    _socket.Close();
    return;
}

Reference

SFXTCPSocket | SFXUDPSocket | SFXSocketAddress | SSL Socket Communication | BREW API ISocket | BREW API ISSL

Member

Constructor/Destructor
SFXSSLSocket( Void )
Constructor of the SFXSSLSocket class.
~SFXSSLSocket( Void )
Destructor of the SFXSSLSocket class.
Public Functions
SFCError AsSFBAStream( SFBAStreamSmpPtr result )
Convert the SFBSocket instance internally managed by this SFXSSLSocket storage into the SFBAStream instance.
SFCError AsSFBSource( SFBSourceSmpPtr result )
Convert the SFBSocket instance internally managed by this SFXSSLSocket storage into the SFBSource instance.
SFCError Bind( SFXSocketAddressConstRef address )
Bind(Or bind the specified local IP address and port number to this socket).
Void Cancel( Void )
Cancel this SSL socket communication.
Void Close( Void )
Close this SSL socket.
SFCError Connect( SFXSocketAddressConstRef address , CallbackSPP spp , VoidPtr reference )
Send the connection request to the specified server in order to establish the connection.
SFCError GetLocalAddress( SFXSocketAddressPtr result )
Get the local IP address and port number of this SSL socket.
SFCError GetRemoteAddress( SFXSocketAddressPtr result )
Get the remote IP address and port number of the peer of this SSL socket.
SFBNetMgrSmpConstRef GetSFBNetMgr( Void )
Get the SFBNetMgr instance managed internally by this socket.
SFBSSLSmpConstRef GetSFBSSL( Void )
Get the SFBSSL instance managed internally by this socket.
SFBSocketSmpConstRef GetSFBSocket( Void )
Get the SFBSocket instance managed internally by this socket.
SFCError GetStreamReader( UInt32 size , SFXStreamReaderPtr result )
Get the input stream for reading data from this SSL socket.
SFCError GetStreamReader( SFXStreamReaderPtr result )
Get the input stream for reading data from this SSL socket.
SFCError GetStreamWriter( UInt32 size , SFXStreamWriterPtr result )
Get the output stream for writing data onto this SSL socket.
SFCError GetStreamWriter( SFXStreamWriterPtr result )
Get the output stream for writing data onto this SSL socket.
UInt32 GetTrustMode( Void )
Get the SSL trust mode of this SSL socket.
SFCError Negotiate( CallbackSPP spp , VoidPtr reference )
Perform the Negotiation for the SSL socket communication.
SFCError Open( SInt32 linger = -1 )
Open this SSL socket.
SFCError Permit( Void )
Set the non-SSL communication to this SSL socket.
SFCError Read( VoidPtr buffer , UInt32Ptr size )
Read data from this SSL socket without input stream.
SFCError ScheduleBind( CallbackSPP spp , VoidPtr reference )
Schedule to bind the local IP address and port number to this SSL socket.
SFCError ScheduleRead( CallbackSPP spp , VoidPtr reference )
Schedule to read data from this SSL socket without input stream.
SFCError ScheduleWrite( CallbackSPP spp , VoidPtr reference )
Schedule to write data onto this SSL socket without output stream.
SFCError SetTrustMode( UInt32 param )
Set the SSL trust mode of this SSL socket.
SFCError Write( VoidConstPtr buffer , UInt32Ptr size )
Write data into this SSL socket without output stream.
Types
CallbackSPP (inherits from SFXStorage)
Type of the callback function for the Storage class.

SFXSSLSocket::SFXSSLSocket
Constructor of the SFXSSLSocket class.
[ public, explicit ]
SFXSSLSocket(Void);

Description

This constructor does nothing.


SFXSSLSocket::~SFXSSLSocket
Destructor of the SFXSSLSocket class.
[ public, virtual ]
virtual ~SFXSSLSocket(Void);

Description

This destructor calls the SFXSSLSocket::Close function.

[Note] Note

Registered callback functions will be canceled.

Reference

SFXSSLSocket::Close


SFXSSLSocket::AsSFBAStream
Convert the SFBSocket instance internally managed by this SFXSSLSocket storage into the SFBAStream instance.
[ public, virtual, const ]
SFCError AsSFBAStream(
    SFBAStreamSmpPtr result   // pointer to the SFBAStream instance
);

Return value

  • If succeeds: SFERR_NO_ERROR
  • If this SFXSSLSocket storage has been closed: SFERR_INVALID_STATE
  • If the result argument is null: SFERR_INVALID_PARAM

Description

This function converts the SFBSocket instance internally managed by this SFXSSLSocket storage into the SFBAStream instance.

As a result, a pointer to the SFBAStream instance will be returned into the result argument.

[Note] Note
The contents of the SFXSSLSocket storage can be handled through the SFBAStream instance.

Reference

SFBSocket | SFBAStream


SFXSSLSocket::AsSFBSource
Convert the SFBSocket instance internally managed by this SFXSSLSocket storage into the SFBSource instance.
[ public, virtual, const ]
SFCError AsSFBSource(
    SFBSourceSmpPtr result   // pointer to the SFBSource instance
);

Return value

  • If succeeds: SFERR_NO_ERROR
  • If this SFXSSLSocket storage has been closed: SFERR_INVALID_STATE
  • If the result argument is null: SFERR_INVALID_PARAM

Description

This function converts the SFBSocket instance internally managed by this SFXSSLSocket storage into the SFBSource instance.

As a result, a pointer to the SFBSource instance will be returned into the result argument.

[Note] Note

This function internally calls the BREW API ISOURCEUTIL_SourceFromSocket function.

[Note] Note
The contents of the SFXSSLSocket storage can be handled as the SFBSource instance.

Reference

SFBSocket | SFBSource | BREW API ISOURCEUTIL_SourceFromSocket


SFXSSLSocket::Bind
Bind(Or bind the specified local IP address and port number to this socket).
[ public ]
SFCError Bind(
    SFXSocketAddressConstRef address   // local IP address and port number: Either SFXInetAddress::LoopbackInetAddress() or SFXInetAddress.AnyInetAddress() can be specified as local IP address
);

Return value

  • If succeeds: SFERR_NO_ERROR
  • If this socket has not been opened: SFERR_INVALID_STATE
  • If binding is blocked: AEE_NET_WOULDBLOCK
  • If other network error occurs: error value obtained by calling the BREW API ISOCKET_GetLastError function or AEE_NET_ERROR

Description

This function binds(or binds the specified local IP address and port number to this SSL socket).

In case of loopback communication within the device only, specify SFXInetAddress::LoopbackInetAddress() as the local IP address. Otherwise, i.e., when communicating with an external server, specify SFXInetAddress::AnyInetAddress(). For the limitation on BREW SDK, values other than these two are not supported.

* If this function returns AEE_NET_WOULDBLOCK, it will be necessary to register a callback function with the SFXSSLSocket::ScheduleBind function where binding will be performed with this function.

[Note] Note

In the client side, you don't necessarily have to bind. If binding is omitted, default port number will be bound to this SSL socket.

[Note] Note

This function internally calls the SFBSocket::Bind function.

[Note] Prerequisite

This socket needs to be opened with the SFXSSLSocket::Open function before this function is called.

Reference

SFXSSLSocket::Open | SFXSSLSocket::ScheduleBind | SFXInetAddress::LoopbackInetAddress | SFXInetAddress::AnyInetAddress | SFXSocketAddress | SFBSocket::Bind | BREW API ISOCKET_Bind | BREW API ISOCKET_GetLastError | BREW API AEE_BREW_LOOPBACK | BREW API AEE_INADDR_LOOPBACK | BREW API AEE_INADDR_ANY


SFXSSLSocket::Cancel
Cancel this SSL socket communication.
[ public, virtual ]
Void Cancel(Void);

Description

This function cancels various operations on this SSL socket.

Concretely, the registered callback function for each operation will be canceled and the status will be returned to before that operation is performed.

The operations to be canceled and its details are in the following table:

Table 194. Operations to be canceled and its details

Operations to be canceled Details
Connecting to the server with the SFXSSLSocket::Connect function. Cancel the callback function and restore the status to just after the SFXSSLSocket::Open function is executed.
Scheduling with the SFXSSLSocket::ScheduleBind function. Cancel the callback function and restore the status to just after the SFXSSLSocket::Open function is executed.
Scheduling with the SFXSSLSocket::ScheduleRead function. Cancel the callback function and restore the status to just after the SFXSSLSocket::Connect function is executed.
Scheduling with the SFXSSLSocket::ScheduleWrite function. Cancel the callback function and restore the status to just after the SFXSSLSocket::Connect function is executed.
[Note] Note

This function is called in the SFXSSLSocket::Close function.

Reference

SFXSSLSocket::Open | SFXSSLSocket::Connect | SFXSSLSocket::ScheduleBind | SFXSSLSocket::ScheduleRead | SFXSSLSocket::ScheduleWrite | SFXSSLSocket::Negotiate | SFXSSLSocket::Close


SFXSSLSocket::Close
Close this SSL socket.
[ public ]
Void Close(Void);

Description

This function closes this SSL socket.

Concretely, this function calls the SFXSSLSocket::Cancel function and releases the SFBNetMgr, SFBSocket and SFBSSL instances that this SSL socket internally manages.

[Note] Note

The registered callback functions will be canceled.

[Note] Note

This function is called in the SFXSSLSocket::~SFXSSLSocket destructor.

[Tip] Tip

When suspending, resources should be released by calling this function.

Reference

SFXSSLSocket::Open | SFXSSLSocket::Cancel | SFXSSLSocket::~SFXSSLSocket | SFBNetMgr | SFBSocket | SFBSSL | BREW API INetMgr | BREW API ISocket | BREW API ISSL


SFXSSLSocket::Connect
Send the connection request to the specified server in order to establish the connection.
[ public ]
SFCError Connect(
    SFXSocketAddressConstRef address   // domain (or IP address) and port number of the server
    CallbackSPP spp                    // callback function
    VoidPtr reference                  // data passed to callback function
);

Argument

address

Specify the domain (or IP address) and port number of the server. The domain will be automatically resolved, if necessary.

spp

Specify the callback function notified of the connection result.

reference

Specify the data passed to the callback function.

Return value

  • If succeeds: SFERR_NO_ERROR
  • If this socket is not opened or it has already been connected (including "Under connecting"): SFERR_INVALID_STATE
  • If domain name is not found: SFERR_INVALID_STATE
  • If failed to create the SFBNetMgr instance: SFERR_FAILED
  • If insufficient memory: SFERR_NO_MEMORY
  • If other network error occurs: error value obtained by calling the BREW API ISOCKET_GetLastError function or AEE_NET_ERROR

Description

This function sends the connection request to the specified server in order to establish the connection. After the connection is established, communication with the server will be performed using this SSL socket.

This function can not gets the result (error code) of the connection establishment as the return value. The the connection result will be notified to the callback function specified in the first argument as follows:

  • AEE_NET_EADDRINUSE: Local address requested via a prior call to ISOCKET_Bind() was not available.
  • AEE_NET_EBADF: Invalid socket descriptor is specfied.
  • AEE_NET_ECONNREFUSED: Connection attempt refused.
  • AEE_NET_EIPADDRCHANGED: IP address changed due to PPP resync.
  • AEE_NET_EINVAL: Invalid IP address and/or port specified.
  • AEE_NET_EISCONN: The socket is already connected (result was already received by a previous call to Connect()).
  • AEE_NET_EMFILE: Not enough network resources to complete this operations (too many sockets in use).
  • AEE_NET_ENETDOWN: Network is not available (e.g. handset outside of coverage area).
  • AEE_NET_EOPNOTSUPP: Socket type is not STREAM.
  • AEE_NET_ETIMEDOUT: Connection attempt timed out.
  • AEE_NET_SUCCESS(SFERR_NO_ERROR): Connect completed successfully; socket is prepared for reading and/or writing.

Until the callback function is called, the state of this SSL socket is "Under connecting". When the callback function is called, it will be "Connected" if the connection is established. Otherwise, it will be restored to "Opened" just before this function is called.

And, if the SFXSSLSocket::Cancel function is called before the result of the connection establishment is notified to the callback function, the connection establishment will be canceled and the state of this SSL socket will be restored to "Opened" just before this function is called.

* If this function returns the value other than SFERR_NO_ERROR, the specified callback function will not be called.

[Note] Note

This function internally calls the SFBSocket::Connect function.

[Note] Prerequisite

This socket needs to be opend by calling the SFXSSLSocket::Open function.

Reference

SFXSSLSocket::Open | SFXSSLSocket::Cancel | SFBSocket::Connect | SFXSocketAddress | SFBNetMgr | SFXStorage::CallbackSPP | BREW API INetMgr | BREW API ISOCKET_Connect | BREW API ISOCKET_GetLastError | BREW API Network AEE error codes


SFXSSLSocket::GetLocalAddress
Get the local IP address and port number of this SSL socket.
[ public, const ]
SFCError GetLocalAddress(
    SFXSocketAddressPtr result   // pointer to the local IP address and port number of this SSL socket
);

Return value

  • If succeeds: SFERR_NO_ERROR
  • If this socket is not bound nor connected: SFERR_INVALID_STATE
  • If the result argument is null: SFERR_INVALID_PARAM
  • If other network error occurs: error value obtained by calling the BREW API ISOCKET_GetLastError function or AEE_NET_ERROR

Description

This function gets the local IP address and port number of this SSL socket.

The actual physical IP address will be obtained from the socket for sending and receiving data after the connection is established. Until then, the value set with the SFXSSLSocket::Bind function will be return.

[Tip] Tip

The actual physical IP address can be also obtained by calling the SFXInetAddress::LocalInetAddress function.

[Note] Prerequisite

To get the local IP address and port number, this socket needs to be bound with the SFXSSLSocket::Bind function or connected with the SFXSSLSocket::Connect function.

Reference

SFXSSLSocket::Bind | SFXSSLSocket::Connect | SFXInetAddress::LocalInetAddress | SFXSocketAddress | BREW API ISOCKET_GetLastError


SFXSSLSocket::GetRemoteAddress
Get the remote IP address and port number of the peer of this SSL socket.
[ public, const ]
SFCError GetRemoteAddress(
    SFXSocketAddressPtr result   // pointer to the remote IP address and port number of the peer of this SSL socket
);

Return value

  • If succeeds: SFERR_NO_ERROR
  • If this socket is not connected(or connection is not established): SFERR_INVALID_STATE
  • If the result argument is null: SFERR_INVALID_PARAM
  • If other network error occurs: error value obtained by calling the BREW API ISOCKET_GetLastError function or AEE_NET_ERROR

Description

This function gets the remote IP address and port number of the peer of this SSL socket.

[Note] Note

This function internally calls the SFBSocket::GetPeerName function.

[Note] Prerequisite

To get the remote IP address and port number, this socket needs to be connected with the SFXSSLSocket::Connect function.

Reference

SFBSocket::GetPeerName | SFXSSLSocket::Connect | SFXSocketAddress | BREW API ISOCKET_GetPeerName | BREW API ISOCKET_GetLastError


SFXSSLSocket::GetSFBNetMgr
Get the SFBNetMgr instance managed internally by this socket.
[ public, const ]
SFBNetMgrSmpConstRef GetSFBNetMgr(Void);

Return value

SFBNetMgr instance managed internally by this socket.

Description

This function gets the SFBNetMgr instance managed internally by this socket.

Reference

SFBNetMgr | BREW API INetMgr


SFXSSLSocket::GetSFBSSL
Get the SFBSSL instance managed internally by this socket.
[ public, const ]
SFBSSLSmpConstRef GetSFBSSL(Void);

Return value

SFBSSL instance managed internally by this socket.

Description

This function gets the SFBSSL instance managed internally by this socket.

Reference

SFBSSL | BREW API ISSL


SFXSSLSocket::GetSFBSocket
Get the SFBSocket instance managed internally by this socket.
[ public, const ]
SFBSocketSmpConstRef GetSFBSocket(Void);

Return value

SFBSocket instance managed internally by this socket.

Description

This function gets the SFBSocket instance managed internally by this socket.

Reference

SFBSocket | BREW API ISocket


SFXSSLSocket::GetStreamReader
Get the input stream for reading data from this SSL socket.
[ public, virtual ]
SFCError GetStreamReader(
    UInt32 size                 // buffer size
    SFXStreamReaderPtr result   // pointer to the input stream
);
[ public, virtual ]
SFCError GetStreamReader(
    SFXStreamReaderPtr result   // pointer to the input stream
);

Return value

  • If succeeds: SFERR_NO_ERROR
  • If the result argument is null: SFERR_INVALID_PARAM
  • If the connection has not been established: SFERR_INVALID_STATE
  • If insufficient memory: SFERR_NO_MEMORY

Description

This function gets the input stream for reading data from this SSL socket.

If the size argument is specified, the buffer size of the input stream will be fixed with the specified value. Otherwise, the buffer size will be variable and the SFXElasticStreamReader class will be used internally.

[Tip] Tip
You have to use the SFXBinaryStreamReader, SFXAnsiStringStreamReader, or SFXWideStringStreamReader class for the input stream properly depending on the type of data to be read.
[Note] Prerequisite

To get the input stream, this socket needs to be connected with the SFXSSLSocket::Connect function.

Reference

SFXSSLSocket::GetStreamWriter | SFXBinaryStreamReader | SFXAnsiStringStreamReader | SFXWideStringStreamReader SFXSSLSocket::Connect | Stream Buffer


SFXSSLSocket::GetStreamWriter
Get the output stream for writing data onto this SSL socket.
[ public, virtual ]
SFCError GetStreamWriter(
    UInt32 size                 // buffer size
    SFXStreamWriterPtr result   // pointer to the output stream
);
[ public, virtual ]
SFCError GetStreamWriter(
    SFXStreamWriterPtr result   // pointer to the output stream
);

Return value

  • If succeeds: SFERR_NO_ERROR
  • If the result argument is null: SFERR_INVALID_PARAM
  • If the connection has not been established: SFERR_INVALID_STATE
  • If insufficient memory: SFERR_NO_MEMORY

Description

This function gets the output stream for writing data onto this SSL socket.

If the size argument is specified, the buffer size of the output stream will be fixed with the specified value. Otherwise, the buffer size will be variable and the SFXElasticStreamWriter class will be used internally.

[Tip] Tip
You have to use the SFXBinaryStreamWriter, SFXAnsiStringStreamWriter, or SFXWideStringStreamWriter class for the output stream properly depending on the type of data to write.
[Note] Prerequisite

To get the output stream, this socket needs to be connected with the SFXSSLSocket::Connect function.

Reference

SFXSSLSocket::GetStreamReader | SFXBinaryStreamWriter | SFXAnsiStringStreamWriter | SFXWideStringStreamWriter SFXSSLSocket::Connect | Stream Buffer


SFXSSLSocket::GetTrustMode
Get the SSL trust mode of this SSL socket.
[ public, const ]
UInt32 GetTrustMode(Void);

Return value

SSL trust mode of this SSL socket

Description

This function gets the SSL trust mode of this SSL socket.

The SSL trust mode is one of the following values.

  • SSL_TRUST_MODE_FAIL: Default, fail on trust errors.
  • SSL_TRUST_MODE_CHECK: Suspend on trust error so they can be checked and ignored.
  • SSL_TRUST_MODE_IGNORE: Ignore all trust errors.
  • SSL_TRUST_MODE_ALWAYS: Always suspend so trust can always be checked.
[Note] Note

For more details, see BREW API ISSL_NegotiateV in the BREW API Reference

Reference

SFXSSLSocket::SetTrustMode | BREW API ISSL_NegotiateV


SFXSSLSocket::Negotiate
Perform the Negotiation for the SSL socket communication.
[ public ]
SFCError Negotiate(
    CallbackSPP spp     // callback function
    VoidPtr reference   // data passed to callback function
);

Return value

  • If succeeds: SFERR_NO_ERROR
  • If this socket is not connected(or connection is not established): SFERR_INVALID_STATE
  • If failed to create the SFBSSLRootCerts instance: SFERR_FAILED
  • If insufficient memory: SFERR_NO_MEMORY

Description

This function performs the Negotiation for the SSL socket communication. Negotiation needs to be done after the connection is established with the SFXSSLSocket::Connect function.

[Note] Note

This function internally calls the SFBSocket::Writeable / SFBSSL::SetSocket / SFBSSL::NegotiateV function.

And it creates the SFBSSLRootCerts instance to set the BREW API WebOpt structure that will be passed to the BREW API ISSL_NegotiateV function.

Reference

SFXSSLSocket::Connect | SFBSSL::NegotiateV | SFBSocket::Writeable | SFBSSL::SetSocket | SFBSSLRootCerts | SFXStorage::CallbackSPP | BREW API ISSL_SetSocket | BREW API ISSL_NegotiateV | BREW API ISOCKET_Writeable | BREW API ISSLRootCerts | BREW API IWebOpts | BREW API WebOpt


SFXSSLSocket::Open
Open this SSL socket.
[ public ]
SFCError Open(
    SInt32 linger = -1   // linger time ( linger time is not set up when linger = -1  )
);

Return value

  • If succeeds: SFERR_NO_ERROR
  • If this socket has already been opened: SFERR_INVALID_STATE
  • If failed to create the SFBNetMgr or SFBSSL instance: SFERR_FAILED
  • If failed to create the SFBSocket instance: return value of INETMGR_GetLastError()
  • If a value greater than UINT16_MAXIMUM is set as the linger time: SFERR_INVALID_PARAM

Description

This function opens (or initializes) this this SSL socket.

Concretely, this function creates the SFBNetMgr instance and calls the BREW API INETMGR_OpenSocket function to create the SFBSocket instance of the AEE_SOCK_STREAM type. These instances are internally managed by this SSL socket. And the SSL trust mode set with the SFXSSLSocket::SetTrustMode function will be set to SSL_TRUST_MODE_FAIL automatically.

The SFBNetMgr / SFBSocket instance can be obtained with the SFXSSLSocket::GetSFBNetMgr / SFXSSLSocket::GetSFBSocket function. More detailed setting can be realized by using these instances.

[Note] Linger time(waiting time for connecting a network)

The linger time(waiting time for connecting a network) set up by the BREW API INETMGR_SetLinger function, can be specified by the linger argument of this function. Default value of this argument is -1. At this time the linger time is not set up. For more details on the linger time settings, refer to BREW API INETMGR_SetLinger.

[Tip] Tip

If the SFXSSLSocket::Close function is called, this SSL socket will be closed.

Reference

SFXSSLSocket::Close | SFXSSLSocket::GetSFBNetMgr | SFXSSLSocket::GetSFBSocket | SFXSSLSocket::SetTrustMode | SFBNetMgr | SFBSocket | BREW API INetMgr | BREW API ISocket | BREW API ISSL | BREW API INETMGR_SetLinger | BREW API INETMGR_OpenSocket


SFXSSLSocket::Permit
Set the non-SSL communication to this SSL socket.
[ public ]
SFCError Permit(Void);

Return value

  • If succeeds: SFERR_NO_ERROR
  • If connection has not been established, or after Negotiation is established: SFERR_INVALID_STATE

Description

This function sets the non-SSL communication(i.e. TCP communication) to this SSL socket.

After connection is established, the non-SSL communication(i.e. TCP communication) is available if calling this function before Negotiation is performed or after Negotiation fails.

[Note] Raison d'entre of the SFXSSLSocket::Permit function

The raison d'entre of the SFXSSLSocket::Permit function lies in that the SFXSSLSocket class can be used like the SFXTCPSocket class.

In some applet, the TCP or SSL communication is performed depending on the settings.

At this time, if the SFXSSLSocket::Permit function is called, the SFXSSLSocket class will become the TCP mode to peform not SSL but TCP communication, that is, the SFXTCPSocket needs not to be used.

Reference

SFXSSLSocket::Negotiate


SFXSSLSocket::Read
Read data from this SSL socket without input stream.
[ public, virtual ]
SFCError Read(
    VoidPtr buffer   // buffer to read data into
    UInt32Ptr size   
// before this function is called: size of the buffer to read data into; 
just after this function is returned: size of the data to be read actually

);

Argument

buffer

Specify the buffer to read data into.

size

Before calling this function, specify the size of the buffer to read data into. Just after this function is returned, the size of data to be read actually will be stored into this argument.

Return value

  • If succeeds: SFERR_NO_ERROR
  • If connection of this socket has not been established: SFERR_INVALID_STATE
  • If the size argument is null: SFERR_INVALID_PARAM
  • If retry is necessary: AEE_NET_WOULDBLOCK
  • If other network error occurs: error value obtained by calling the BREW API ISOCKET_GetLastError function or AEE_NET_ERROR

Description

This function reads data from this SSL socket without input stream.

When the peer closes the connection, this function will return SFERR_NO_ERROR and 0 will be returned into the area that the size argument points to.

* If this function returns AEE_NET_WOULDBLOCK, it will be necessary to register a callback function with the SFXSSLSocket::ScheduleRead function where data will be read with this function.

[Note] Note

This function internally calls the SFBAStream::Read function.

[Note] Prerequisite

The connection of this socket needs to be established with the SFXSSLSocket::Connect function before this function is called.

Reference

SFXSSLSocket::ScheduleRead | SFBAStream::Read | BREW API ISOCKET_Read


SFXSSLSocket::ScheduleBind
Schedule to bind the local IP address and port number to this SSL socket.
[ public ]
SFCError ScheduleBind(
    CallbackSPP spp     // callback function
    VoidPtr reference   // data passed to callback function
);

Return value

  • If succeeds: SFERR_NO_ERROR
  • If this socket has been closed, connected or under being connected, or binding has already been scheduled: SFERR_INVALID_STATE

Description

This function schedules to bind the local IP address and port number to this SSL socket.

Concretely, this function registers the callback function that will bind the local IP address and port number to this SSL socket with the SFXSSLSocket::Bind function. The registered callback function will be called by BREW AEE when it is possible to bind.

The status of this socket is "under scheduling to bind" until the callback function is called. And after the callback function is called, it will become the status before calling this function, i.e., "this socket is opened".

If you call the SFXSSLSocket::Cancel function before the callback function is called, binding will be canceled and the status will be returned to the status before calling this function, i.e., "this socket is opened".

*1. If the SFXSSLSocket::Bind function returns AEE_NET_WOULDBLOCK, it will be necessary to register a callback function with this function where binding will be performed with the SFXSSLSocket::Bind function.

*2. If this function returns the value other than SFERR_NO_ERROR, the specified callback function will not be called.

[Note] Note

This function internally calls the SFBSocket::Writeable function.

[Note] Prerequisite

Before this function is called, this socket needs to be opened with the SFXSSLSocket::Open function. However, if it is connected or under being connected, the SFERR_INVALID_STATE error will be returned.

In addition, if binding has already been scheduled, the SFERR_INVALID_STATE error will be returned too.

Reference

SFXSSLSocket::Bind | SFXSSLSocket::Cancel | SFXSSLSocket::Open | SFBSocket::Writeable | SFXStorage::CallbackSPP | BREW API ISOCKET_Writeable


SFXSSLSocket::ScheduleRead
Schedule to read data from this SSL socket without input stream.
[ public, virtual ]
SFCError ScheduleRead(
    CallbackSPP spp     // callback function
    VoidPtr reference   // data passed to callback function
);

Return value

  • If succeeds: SFERR_NO_ERROR
  • If the connection of this socket has not been established, or reading data has already been scheduled: SFERR_INVALID_STATE

Description

This function schedules to read data from this SSL socket without input stream.

Concretely, this function registers the callback function that will read data with the SFXSSLSocket::Read function. The registered callback function will be called by BREW AEE when it is possible to read data.

The status of this socket is "under scheduling to read data" until the callback function is called. And after the callback function is called, it will become the status before calling this function, i.e., "the connection of this socket is established".

If you call the SFXSSLSocket::Cancel function before the callback function is called, reading data will be canceled and the status will be returned to the status before calling this function, i.e., "the connection of this socket is established".

*1. If the SFXSSLSocket::Read function returns AEE_NET_WOULDBLOCK, it will be necessary to register a callback function with this function where data will be read with the SFXSSLSocket::Read function.

*2. If this function returns the value other than SFERR_NO_ERROR, the specified callback function will not be called.

[Note] Note

This function internally calls the SFBAStream::Readable function.

[Note] Prerequisite

The connection of this socket needs to be established with the SFXSSLSocket::Connect function before this function is called.

And if this socket has been already scheduled to read data, the SFERR_INVALID_STATE error will be returned.

Reference

SFXSSLSocket::Read | SFBAStream::Readable | SFXStorage::CallbackSPP | BREW API ISOCKET_Readable


SFXSSLSocket::ScheduleWrite
Schedule to write data onto this SSL socket without output stream.
[ public, virtual ]
SFCError ScheduleWrite(
    CallbackSPP spp     // callback function
    VoidPtr reference   // data passed to callback function
);

Return value

  • If succeeds: SFERR_NO_ERROR
  • If the connection of this socket has not been established, or writing data has already been scheduled: SFERR_INVALID_STATE

Description

This function schedules to write data onto this SSL socket without output stream.

Concretely, this function registers the callback function that will write data with the SFXSSLSocket::Read function. The registered callback function will be called by BREW AEE when it is possible to write data.

The status of this socket is "under scheduling to write data" until the callback function is called. And after the callback function is called, it will become the status before calling this function, i.e., "the connection of this socket is established".

If you call the SFXSSLSocket::Cancel function before the callback function is called, writing data will be canceled and the status will be returned to the status before calling this function, i.e., "the connection of this socket is established".

*1. If the SFXSSLSocket::Write function returns AEE_NET_WOULDBLOCK, it will be necessary to register a callback function with this function where data will be written with the SFXSSLSocket::Write function.

*2. If this function returns the value other than SFERR_NO_ERROR, the specified callback function will not be called.

[Note] Note

This function internally calls the SFBSocket::Writeable function.

[Note] Prerequisite

The connection of this socket needs to be established with the SFXSSLSocket::Connect function before this function is called.

And if this socket has been already scheduled to write data, the SFERR_INVALID_STATE error will be returned.

Reference

SFXSSLSocket::Write | SFBSocket::Writeable | SFXStorage::CallbackSPP | BREW API ISOCKET_Writeable


SFXSSLSocket::SetTrustMode
Set the SSL trust mode of this SSL socket.
[ public ]
SFCError SetTrustMode(
    UInt32 param   // SSL trust mode
);

Return value

  • If succeeds: SFERR_NO_ERROR
  • If this socket has been closed: SFERR_INVALID_STATE

Description

This function sets the SSL trust mode of this SSL socket.

The SSL trust mode will be until the SFXSSLSocket::Close function is called.

The SSL_RESULT_SERV_VERS error might occur depending on the handset device when calling the SFXSSLSocket::Connect function immediately after this value is changed.

If the SSL_RESULT_SERV_VERS error occurs, it is necessary to close this SSL socket with the SFXSSLSocket::Close function, set the SSL trust mode with this function, and then connect to the server with the SFXSSLSocket::Connect function.

One of the following values are available for the SSL trust mode:

  • SSL_TRUST_MODE_FAIL: Default, fail on trust errors.
  • SSL_TRUST_MODE_CHECK: Suspend on trust errors so they can be checked and ignored.
  • SSL_TRUST_MODE_IGNORE: Ignore all trust errors.
  • SSL_TRUST_MODE_ALWAYS: Always suspend so trust can always be checked.
[Note] Note

For more details, see BREW API ISSL_NegotiateV in the BREW API Reference

Reference

SFXSSLSocket::GetTrustMode | SFXSSLSocket::Open | SFXStorage::CallbackSPP | BREW API ISSL_NegotiateV


SFXSSLSocket::Write
Write data into this SSL socket without output stream.
[ public, virtual ]
SFCError Write(
    VoidConstPtr buffer   // buffer to write data into
    UInt32Ptr size        
// before this function is called: size of the buffer to write data into; 
just after this function is returned: size of the data to be written actually

);

Argument

buffer

Specify the buffer to write data into.

size

Before calling this function, specify the size of the buffer to write data into. Just after this function is returned, the size of data to be written into the buffer actually will be stored into this argument.

Return value

  • If succeeds: SFERR_NO_ERROR
  • If connection of this socket has not been established: SFERR_INVALID_STATE
  • If the size argument is null: SFERR_INVALID_PARAM
  • If retry is necessary: AEE_NET_WOULDBLOCK
  • If other network error occurs: error value obtained by calling the BREW API ISOCKET_GetLastError function or AEE_NET_ERROR

Description

This function writes data into this SSL socket without output stream.

* If this function returns AEE_NET_WOULDBLOCK, it will be necessary to register a callback function with the SFXSSLSocket::ScheduleWrite function where data will be written with this function.

[Note] Note

This function internally calls the SFBSocket::Write function.

[Note] Prerequisite

The connection of this socket needs to be established with the SFXSSLSocket::Connect function before this function is called.

Reference

SFXSSLSocket::ScheduleWrite | SFBSocket::Write | BREW API ISOCKET_Write