MQTT C Client Libraries Internals
Loading...
Searching...
No Matches
MQTTProtocolClient.c File Reference

Functions dealing with the MQTT protocol exchanges. More...

#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include "MQTTProtocolClient.h"
#include "MQTTPersistence.h"
#include "Socket.h"
#include "SocketBuffer.h"
#include "StackTrace.h"
#include "Heap.h"
Include dependency graph for MQTTProtocolClient.c:

Data Structures

struct  AckRequest
 

Macros

#define min(A, B)
 

Functions

static void MQTTProtocol_storeQoS0 (Clients *pubclient, Publish *publish)
 
static int MQTTProtocol_startPublishCommon (Clients *pubclient, Publish *publish, int qos, int retained)
 Utility function to start a new publish exchange.
 
static void MQTTProtocol_retries (START_TIME_TYPE now, Clients *client, int regardless)
 MQTT retry processing per client.
 
static int MQTTProtocol_queueAck (Clients *client, int ackType, int msgId)
 Queue an ack message.
 
int messageIDCompare (void *a, void *b)
 List callback function for comparing Message structures by message id.
 
int MQTTProtocol_assignMsgId (Clients *client)
 Assign a new message id for a client.
 
int MQTTProtocol_startPublish (Clients *pubclient, Publish *publish, int qos, int retained, Messages **mm)
 Start a new publish exchange.
 
MessagesMQTTProtocol_createMessage (Publish *publish, Messages **mm, int qos, int retained, int allocatePayload)
 Copy and store message data for retries.
 
PublicationsMQTTProtocol_storePublication (Publish *publish, int *len)
 Store message data for possible retry.
 
void MQTTProtocol_removePublication (Publications *p)
 Remove stored message data.
 
int MQTTProtocol_handlePublishes (void *pack, SOCKET sock)
 Process an incoming publish packet for a socket The payload field of the packet has not been transferred to another buffer at this point.
 
int MQTTProtocol_handlePubacks (void *pack, SOCKET sock, Publications **pubToRemove)
 Process an incoming puback packet for a socket.
 
int MQTTProtocol_handlePubrecs (void *pack, SOCKET sock, Publications **pubToRemove)
 Process an incoming pubrec packet for a socket.
 
int MQTTProtocol_handlePubrels (void *pack, SOCKET sock)
 Process an incoming pubrel packet for a socket.
 
int MQTTProtocol_handlePubcomps (void *pack, SOCKET sock, Publications **pubToRemove)
 Process an incoming pubcomp packet for a socket.
 
void MQTTProtocol_keepalive (START_TIME_TYPE now)
 MQTT protocol keepAlive processing.
 
void MQTTProtocol_retry (START_TIME_TYPE now, int doRetry, int regardless)
 MQTT retry protocol and socket pending writes processing.
 
void MQTTProtocol_freeClient (Clients *client)
 Free a client structure.
 
void MQTTProtocol_emptyMessageList (List *msgList)
 Empty a message list, leaving it able to accept new messages.
 
void MQTTProtocol_freeMessageList (List *msgList)
 Empty and free up all storage used by a message list.
 
void MQTTProtocol_writeAvailable (SOCKET socket)
 Callback that is invoked when the socket is available for writing.
 
char * MQTTStrncpy (char *dest, const char *src, size_t dest_size)
 Copy no more than dest_size -1 characters from the string pointed to by src to the array pointed to by dest.
 
char * MQTTStrdup (const char *src)
 Duplicate a string, safely, allocating space on the heap.
 

Variables

MQTTProtocol state
 
ClientStatesbstate
 

Detailed Description

Functions dealing with the MQTT protocol exchanges.

Some other related functions are in the MQTTProtocolOut module

Macro Definition Documentation

◆ min

#define min ( A,
B )
Value:
( (A) < (B) ? (A):(B))

Function Documentation

◆ messageIDCompare()

int messageIDCompare ( void * a,
void * b )

List callback function for comparing Message structures by message id.

Parameters
afirst integer value
bsecond integer value
Returns
boolean indicating whether a and b are equal

◆ MQTTProtocol_assignMsgId()

int MQTTProtocol_assignMsgId ( Clients * client)

Assign a new message id for a client.

Make sure it isn't already being used and does not exceed the maximum.

Parameters
clienta client structure
Returns
the next message id to use, or 0 if none available
Here is the call graph for this function:

◆ MQTTProtocol_createMessage()

Messages * MQTTProtocol_createMessage ( Publish * publish,
Messages ** mm,
int qos,
int retained,
int allocatePayload )

Copy and store message data for retries.

Parameters
publishthe publication data
mm- pointer to the message data to store
qosthe MQTT QoS to use
retainedboolean - whether to set the MQTT retained flag
allocatePayloadboolean - whether or not to malloc payload
Returns
pointer to the message data stored
Here is the call graph for this function:

◆ MQTTProtocol_emptyMessageList()

void MQTTProtocol_emptyMessageList ( List * msgList)

Empty a message list, leaving it able to accept new messages.

Parameters
msgListthe message list to empty
Here is the call graph for this function:

◆ MQTTProtocol_freeClient()

void MQTTProtocol_freeClient ( Clients * client)

Free a client structure.

Parameters
clientthe client data to free
Here is the call graph for this function:

◆ MQTTProtocol_freeMessageList()

void MQTTProtocol_freeMessageList ( List * msgList)

Empty and free up all storage used by a message list.

Parameters
msgListthe message list to empty and free
Here is the call graph for this function:

◆ MQTTProtocol_handlePubacks()

int MQTTProtocol_handlePubacks ( void * pack,
SOCKET sock,
Publications ** pubToRemove )

Process an incoming puback packet for a socket.

Parameters
packpointer to the publish packet
sockthe socket on which the packet was received
Returns
completion code
Here is the call graph for this function:

◆ MQTTProtocol_handlePubcomps()

int MQTTProtocol_handlePubcomps ( void * pack,
SOCKET sock,
Publications ** pubToRemove )

Process an incoming pubcomp packet for a socket.

Parameters
packpointer to the publish packet
sockthe socket on which the packet was received
Returns
completion code
Here is the call graph for this function:

◆ MQTTProtocol_handlePublishes()

int MQTTProtocol_handlePublishes ( void * pack,
SOCKET sock )

Process an incoming publish packet for a socket The payload field of the packet has not been transferred to another buffer at this point.

If it's needed beyond the scope of this function, it has to be copied.

Parameters
packpointer to the publish packet
sockthe socket on which the packet was received
Returns
completion code
Here is the call graph for this function:

◆ MQTTProtocol_handlePubrecs()

int MQTTProtocol_handlePubrecs ( void * pack,
SOCKET sock,
Publications ** pubToRemove )

Process an incoming pubrec packet for a socket.

Parameters
packpointer to the publish packet
sockthe socket on which the packet was received
Returns
completion code
Here is the call graph for this function:

◆ MQTTProtocol_handlePubrels()

int MQTTProtocol_handlePubrels ( void * pack,
SOCKET sock )

Process an incoming pubrel packet for a socket.

Parameters
packpointer to the publish packet
sockthe socket on which the packet was received
Returns
completion code
Here is the call graph for this function:

◆ MQTTProtocol_keepalive()

void MQTTProtocol_keepalive ( START_TIME_TYPE now)

MQTT protocol keepAlive processing.

Sends PINGREQ packets as required.

Parameters
nowcurrent time
Here is the call graph for this function:

◆ MQTTProtocol_queueAck()

int MQTTProtocol_queueAck ( Clients * client,
int ackType,
int msgId )
static

Queue an ack message.

This is used when the socket is full (e.g. SSL_ERROR_WANT_WRITE). To be completed/cleared when the socket is no longer full

Parameters
clientthe client that received the published message
ackTypethe type of ack to send
msgIdthe msg id of the message we are acknowledging
Returns
the completion code
Here is the call graph for this function:

◆ MQTTProtocol_removePublication()

void MQTTProtocol_removePublication ( Publications * p)

Remove stored message data.

Opposite of storePublication

Parameters
pstored publication to remove
Here is the call graph for this function:

◆ MQTTProtocol_retries()

static void MQTTProtocol_retries ( START_TIME_TYPE now,
Clients * client,
int regardless )
static

MQTT retry processing per client.

Parameters
nowcurrent time
client- the client to which to apply the retry processing
regardlessboolean - retry packets regardless of retry interval (used on reconnect)
Here is the call graph for this function:

◆ MQTTProtocol_retry()

void MQTTProtocol_retry ( START_TIME_TYPE now,
int doRetry,
int regardless )

MQTT retry protocol and socket pending writes processing.

Parameters
nowcurrent time
doRetryboolean - retries as well as pending writes?
regardlessboolean - retry packets regardless of retry interval (used on reconnect)
Here is the call graph for this function:

◆ MQTTProtocol_startPublish()

int MQTTProtocol_startPublish ( Clients * pubclient,
Publish * publish,
int qos,
int retained,
Messages ** mm )

Start a new publish exchange.

Store any state necessary and try to send the packet

Parameters
pubclientthe client to send the publication to
publishthe publication data
qosthe MQTT QoS to use
retainedboolean - whether to set the MQTT retained flag
mm- pointer to the message to send
Returns
the completion code
Here is the call graph for this function:

◆ MQTTProtocol_startPublishCommon()

static int MQTTProtocol_startPublishCommon ( Clients * pubclient,
Publish * publish,
int qos,
int retained )
static

Utility function to start a new publish exchange.

Parameters
pubclientthe client to send the publication to
publishthe publication data
qosthe MQTT QoS to use
retainedboolean - whether to set the MQTT retained flag
Returns
the completion code
Here is the call graph for this function:

◆ MQTTProtocol_storePublication()

Publications * MQTTProtocol_storePublication ( Publish * publish,
int * len )

Store message data for possible retry.

Parameters
publishthe publication data
lenreturned length of the data stored
Returns
the publication stored
Here is the call graph for this function:

◆ MQTTProtocol_writeAvailable()

void MQTTProtocol_writeAvailable ( SOCKET socket)

Callback that is invoked when the socket is available for writing.

This is the last attempt made to acknowledge a message. Failures that occur here are ignored.

Parameters
socketthe socket that is available for writing
Here is the call graph for this function:

◆ MQTTStrdup()

char * MQTTStrdup ( const char * src)

Duplicate a string, safely, allocating space on the heap.

Parameters
srcthe source string which characters copy from
Returns
the duplicated, allocated string
Here is the call graph for this function:

◆ MQTTStrncpy()

char * MQTTStrncpy ( char * dest,
const char * src,
size_t dest_size )

Copy no more than dest_size -1 characters from the string pointed to by src to the array pointed to by dest.

The destination string will always be null-terminated.

Parameters
destthe array which characters copy to
srcthe source string which characters copy from
dest_sizethe size of the memory pointed to by dest: copy no more than this -1 (allow for null). Must be >= 1
Returns
the destination string pointer
Here is the call graph for this function: