SharkSSL™ Embedded SSL/TLS Stack
|
Macros | |
#define | SharkMQ_setCtx(o, ctx) SOCKET_constructor(&(o)->sock, ctx) |
Bare metal configuration. More... | |
#define | SharkMQ_getSendBufPtr(o) (SharkSslCon_getEncBufPtr((o)->scon) + 15) |
Zero copy API: Get start of send buffer. More... | |
#define | SharkMQ_getSendBufSize(o) (SharkSslCon_getEncBufSize((o)->scon) - 15) |
Zero copy API: Get max buffer length. More... | |
#define | SharkMQ_getMsgSize(o) ((o)->frameLen-15) |
Returns the message size, which is SharkMQ::frameLen - 15. More... | |
Functions | |
void | SharkMQ_constructor (SharkMQ *o, U8 *buf, U16 bufLen) |
Create a secure SMQ client instance. More... | |
int | SharkMQ_init (SharkMQ *o, SharkSslCon *scon, const char *url, U32 *rnd) |
Initiate the SharkMQ server connection. More... | |
int | SharkMQ_connect (SharkMQ *o, const char *uid, int uidLen, const char *credentials, U8 credLen, const char *info, int infoLen, U16 maxTlsFrameSize) |
Connect/establish a persistent SMQ connection. More... | |
void | SharkMQ_disconnect (SharkMQ *o) |
Gracefully close the connection. More... | |
void | SharkMQ_destructor (SharkMQ *o) |
Terminate an SMQ instance. More... | |
int | SharkMQ_create (SharkMQ *o, const char *topic) |
Create a topic an fetch the topic ID (tid). More... | |
int | SharkMQ_createsub (SharkMQ *o, const char *subtopic) |
Create a sub-topic and fetch the subtopic ID. More... | |
int | SharkMQ_subscribe (SharkMQ *o, const char *topic) |
Subscribe to topic. More... | |
int | SharkMQ_unsubscribe (SharkMQ *o, U32 tid) |
Requests the broker to unsubscribe the client from a topic. More... | |
int | SharkMQ_publish (SharkMQ *o, const void *data, int len, U32 tid, U32 subtid) |
Publish messages to a topic and optionally to a sub-topic. More... | |
int | SharkMQ_wrtstr (SharkMQ *o, const char *str) |
Publish a message in chunks and request the broker to assemble the message before publishing to the subscriber(s). More... | |
int | SharkMQ_write (SharkMQ *o, const void *data, int len) |
Publish a message in chunks and request the broker to assemble the message before publishing to the subscriber(s). More... | |
int | SharkMQ_pubflush (SharkMQ *o, U32 tid, U32 subtid) |
Flush the internal buffer and request the broker to assemble all stored fragments as one message. More... | |
int | SharkMQ_observe (SharkMQ *o, U32 tid) |
Request the broker to provide change notification events when the number of subscribers to a specific topic changes. More... | |
int | SharkMQ_unobserve (SharkMQ *o, U32 tid) |
Stop receiving change notifications for a topic ID or ephemeral topic ID. More... | |
int | SharkMQ_getMessage (SharkMQ *o, U8 **msg) |
Wait for messages sent from the broker. More... | |
#define SharkMQ_getMsgSize | ( | o | ) | ((o)->frameLen-15) |
Returns the message size, which is SharkMQ::frameLen - 15.
o | the SharkMQ instance. |
#define SharkMQ_getSendBufPtr | ( | o | ) | (SharkSslCon_getEncBufPtr((o)->scon) + 15) |
Zero copy API: Get start of send buffer.
Returns SharkSslCon_getEncBufPtr() + 15. Use with SharkMQ_publish and set "data argument"=NULL.
o | the SharkMQ instance. |
#define SharkMQ_getSendBufSize | ( | o | ) | (SharkSslCon_getEncBufSize((o)->scon) - 15) |
Zero copy API: Get max buffer length.
Returns SharkSslCon_getEncBufSize - 15. Use with SharkMQ_getSendBufPtr.
o | the SharkMQ instance. |
#define SharkMQ_setCtx | ( | o, | |
ctx | |||
) | SOCKET_constructor(&(o)->sock, ctx) |
int SharkMQ_connect | ( | SharkMQ * | o, |
const char * | uid, | ||
int | uidLen, | ||
const char * | credentials, | ||
U8 | credLen, | ||
const char * | info, | ||
int | infoLen, | ||
U16 | maxTlsFrameSize | ||
) |
Connect/establish a persistent SMQ connection.
The connection phase is divided into two steps: (1) initiating via SharkMQ_init and (2) connecting.
o | the SharkMQ instance. |
uid | a universally unique client identifier (uid) must be unique across all clients connecting to the same broker instance. The uid is preferably a stringified version of the client's Ethernet MAC address. |
uidLen | the uid length. |
credentials | provide credentials if required by the broker instance. |
credLen | credentials length. |
info | a string that provides information to optional server code interacting with the broker. This string is also passed into the optional broker's authentication callback function. |
infoLen | length of info. |
maxTlsFrameSize | - Request server limits TLS frame size to this size. SMQ messages sent by server larger than this size is split up into smaller chunks. The value zero means don't care. |
The broker may optionally send a human readable string in addition to the above broker produced error codes. This string is avaiable via SharkMQ::buf.
void SharkMQ_constructor | ( | SharkMQ * | o, |
U8 * | buf, | ||
U16 | bufLen | ||
) |
Create a secure SMQ client instance.
o | Uninitialized data of size sizeof(SharkMQ). |
buf | is used for internal management and must not be less than 127 bytes and not smaller than the largest control frame. Function SharkMQ_getMessage will return SMQE_BUF_OVERFLOW if the buffer is not sufficiently large. |
bufLen | buffer length. |
int SharkMQ_create | ( | SharkMQ * | o, |
const char * | topic | ||
) |
Create a topic an fetch the topic ID (tid).
The SharkMQ protocol is optimized and does not directly use a string when publishing, but a number. The server randomly a creates 32 bit number and persistently stores the topic name and number.
The response to SharkMQ_create is asynchronous and returned as status SMQ_CREATEACK via SharkMQ_getMessage.
o | the SharkMQ instance. |
topic | the topic name where you plan on publishing messages. |
int SharkMQ_createsub | ( | SharkMQ * | o, |
const char * | subtopic | ||
) |
Create a sub-topic and fetch the subtopic ID.
The response to SharkMQ_subscribe is asynchronous and returned as status SMQ_CREATESUBACK via SharkMQ_getMessage.
o | the SharkMQ instance. |
subtopic | the sub-topic name you want registered. |
void SharkMQ_disconnect | ( | SharkMQ * | o | ) |
Gracefully close the connection.
You cannot publish any messages after calling this method.
o | the SharkMQ instance. |
int SharkMQ_getMessage | ( | SharkMQ * | o, |
U8 ** | msg | ||
) |
Wait for messages sent from the broker.
o | the SharkMQ instance. |
msg | a pointer to the response data (out param) |
Note: the default timeout value is set to one minute. You can set the timeout value by setting SharkMQ::timeout to the number of milliseconds you want to wait for incoming messages before the timeout triggers. Note: Setting a long timeout may interfere with the built in PING timer.
int SharkMQ_init | ( | SharkMQ * | o, |
SharkSslCon * | scon, | ||
const char * | url, | ||
U32 * | rnd | ||
) |
Initiate the SharkMQ server connection.
The connection phase is divided into two steps: (1) initiating and (2) connecting via SharkMQ_connect.
o | the SharkMQ instance. |
scon | SharkSslCon instance created by calling SharkSsl_createCon. |
url | is a URL that starts with http:// and this URL must be to a server resource that initiates an SMQ connection. |
rnd | (out param) a random number created by the server. This number can be used for securing hash based password encryption. |
A negative return value is one of: an error code from se_connect, or a SMQ error code.
A return value greater than zero means that a connection is established, but the connection is not trusted unless the return value is SharkSslConTrust_CertCn.
On success, SharkMQ::buf is set to the IP address of the client as seen by the broker.
int SharkMQ_observe | ( | SharkMQ * | o, |
U32 | tid | ||
) |
Request the broker to provide change notification events when the number of subscribers to a specific topic changes.
Ephemeral topic IDs can also be observed. The number of connected subscribers for an ephemeral ID can only be one, which means the client is connected. Receiving a change notification for an ephemeral ID means the client has disconnected and that you no longer will get any change notifications for the observed topic ID.
Change notification events are received as SMQ_SUBCHANGE via SharkMQ_getMessage.
o | the SharkMQ instance. |
tid | the Topic ID you which to observe. |
int SharkMQ_pubflush | ( | SharkMQ * | o, |
U32 | tid, | ||
U32 | subtid | ||
) |
Flush the internal buffer and request the broker to assemble all stored fragments as one message.
This message is then published to topic 'tid', and sub-topic 'subtid'.
o | the SharkMQ instance. |
tid | the topic ID (created with SharkMQ_create). |
subtid | optional sub-topic ID preferably created with SharkMQ_createsub. |
Example:
int SharkMQ_publish | ( | SharkMQ * | o, |
const void * | data, | ||
int | len, | ||
U32 | tid, | ||
U32 | subtid | ||
) |
Publish messages to a topic and optionally to a sub-topic.
Topic name must have previosly been been resolved by SharkMQ_create and sub-topic should preferably have been created by SharkMQ_createsub.
o | the SharkMQ instance. |
data | message payload. |
len | payload length. |
tid | the topic ID (created with SharkMQ_create). |
subtid | optional sub-topic ID preferably created with SharkMQ_createsub. |
int SharkMQ_subscribe | ( | SharkMQ * | o, |
const char * | topic | ||
) |
Subscribe to topic.
The response to SharkMQ_subscribe is asynchronous and returned as status SMQ_SUBACK via SharkMQ_getMessage.
o | the SharkMQ instance. |
topic | the topic name to subscribe to. |
int SharkMQ_unobserve | ( | SharkMQ * | o, |
U32 | tid | ||
) |
Stop receiving change notifications for a topic ID or ephemeral topic ID.
o | the SharkMQ instance. |
tid | the Topic ID you no longer want to observe. |
int SharkMQ_unsubscribe | ( | SharkMQ * | o, |
U32 | tid | ||
) |
Requests the broker to unsubscribe the client from a topic.
o | the SharkMQ instance. |
tid | the topic name's Topic ID. |
int SharkMQ_write | ( | SharkMQ * | o, |
const void * | data, | ||
int | len | ||
) |
Publish a message in chunks and request the broker to assemble the message before publishing to the subscriber(s).
This method uses the internal SharkSSL send buffer and sends the message as a chunk when the internal buffer is full, thus sending the message as an incomplete message to the broker. The message is assembled by the broker when you flush the remaining bytes in the buffer by calling SharkMQ_pubflush.
o | the SharkMQ instance. |
data | message payload. |
len | payload length. |
int SharkMQ_wrtstr | ( | SharkMQ * | o, |
const char * | str | ||
) |
Publish a message in chunks and request the broker to assemble the message before publishing to the subscriber(s).
This method uses the internal SharkSSL send buffer and sends the message as a chunk when the internal buffer is full, thus sending the message as an incomplete message to the broker. The message is assembled by the broker when you flush the remaining bytes in the buffer by calling SharkMQ_pubflush.
o | the SharkMQ instance. |
str | a string. |