Classes | Typedefs | Enumerations | Functions
MQTTPacket.h File Reference
#include "Socket.h"
#include "LinkedList.h"
#include "Clients.h"
#include "MQTTProperties.h"
#include "MQTTReasonCodes.h"
#include "MQTTPacketOut.h"
Include dependency graph for MQTTPacket.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  Ack
 
struct  Connack
 
struct  Connect
 
union  Header
 
struct  MQTTPacket
 
struct  Publish
 
struct  Suback
 
struct  Unsuback
 

Typedefs

typedef unsigned int bool
 
typedef void *(* pf) (int, unsigned char, char *, size_t)
 
typedef Ack Puback
 
typedef Ack Pubcomp
 
typedef Ack Pubrec
 
typedef Ack Pubrel
 

Enumerations

enum  errors { MQTTPACKET_BAD = -4, MQTTPACKET_BUFFER_TOO_SHORT = -2, MQTTPACKET_READ_ERROR = -1, MQTTPACKET_READ_COMPLETE }
 
enum  msgTypes {
  CONNECT = 1, CONNACK, PUBLISH, PUBACK,
  PUBREC, PUBREL, PUBCOMP, SUBSCRIBE,
  SUBACK, UNSUBSCRIBE, UNSUBACK, PINGREQ,
  PINGRESP, DISCONNECT, AUTH, CONNECT,
  PUBLISH, SUBSCRIBE, SUBSCRIBE_MANY, UNSUBSCRIBE,
  CONNECT = 1, CONNACK, PUBLISH, PUBACK,
  PUBREC, PUBREL, PUBCOMP, SUBSCRIBE,
  SUBACK, UNSUBSCRIBE, UNSUBACK, PINGREQ,
  PINGRESP, DISCONNECT, AUTH
}
 

Functions

int MQTTLenStringRead (MQTTLenString *lenstring, char **pptr, char *enddata)
 
void * MQTTPacket_ack (int MQTTVersion, unsigned char aHeader, char *data, size_t datalen)
 
int MQTTPacket_decode (networkHandles *net, size_t *value)
 
int MQTTPacket_decodeBuf (char *buf, unsigned int *value)
 
int MQTTPacket_encode (char *buf, size_t length)
 
void * MQTTPacket_Factory (int MQTTVersion, networkHandles *net, int *error)
 
void MQTTPacket_free_packet (MQTTPacket *pack)
 
void MQTTPacket_freeAck (Ack *pack)
 
void MQTTPacket_freePublish (Publish *pack)
 
void MQTTPacket_freeSuback (Suback *pack)
 
void MQTTPacket_freeUnsuback (Unsuback *pack)
 
void * MQTTPacket_header_only (int MQTTVersion, unsigned char aHeader, char *data, size_t datalen)
 
const char * MQTTPacket_name (int ptype)
 
void * MQTTPacket_publish (int MQTTVersion, unsigned char aHeader, char *data, size_t datalen)
 
int MQTTPacket_send (networkHandles *net, Header header, char *buffer, size_t buflen, int free, int MQTTVersion)
 
int MQTTPacket_send_disconnect (Clients *client, enum MQTTReasonCodes reason, MQTTProperties *props)
 
int MQTTPacket_send_puback (int MQTTVersion, int msgid, networkHandles *net, const char *clientID)
 
int MQTTPacket_send_pubcomp (int MQTTVersion, int msgid, networkHandles *net, const char *clientID)
 
int MQTTPacket_send_publish (Publish *pack, int dup, int qos, int retained, networkHandles *net, const char *clientID)
 
int MQTTPacket_send_pubrec (int MQTTVersion, int msgid, networkHandles *net, const char *clientID)
 
int MQTTPacket_send_pubrel (int MQTTVersion, int msgid, int dup, networkHandles *net, const char *clientID)
 
int MQTTPacket_sends (networkHandles *net, Header header, PacketBuffers *buffers, int MQTTVersion)
 
int MQTTPacket_VBIlen (int rem_len)
 
unsigned char readChar (char **pptr)
 
int readInt (char **pptr)
 
int readInt4 (char **pptr)
 
char * readUTF (char **pptr, char *enddata)
 
void writeChar (char **pptr, char c)
 
void writeData (char **pptr, const void *data, int datalen)
 
void writeInt (char **pptr, int anInt)
 
void writeInt4 (char **pptr, int anInt)
 
void writeMQTTLenString (char **pptr, MQTTLenString lenstring)
 
void writeUTF (char **pptr, const char *string)
 

Typedef Documentation

typedef unsigned int bool

Definition at line 31 of file MQTTPacket.h.

typedef void*(* pf) (int, unsigned char, char *, size_t)

Definition at line 32 of file MQTTPacket.h.

typedef Ack Puback

Definition at line 223 of file MQTTPacket.h.

typedef Ack Pubcomp

Definition at line 226 of file MQTTPacket.h.

typedef Ack Pubrec

Definition at line 224 of file MQTTPacket.h.

typedef Ack Pubrel

Definition at line 225 of file MQTTPacket.h.

Enumeration Type Documentation

enum errors
Enumerator
MQTTPACKET_BAD 
MQTTPACKET_BUFFER_TOO_SHORT 
MQTTPACKET_READ_ERROR 
MQTTPACKET_READ_COMPLETE 

Definition at line 37 of file MQTTPacket.h.

enum msgTypes
Enumerator
CONNECT 
CONNACK 
PUBLISH 
PUBACK 
PUBREC 
PUBREL 
PUBCOMP 
SUBSCRIBE 
SUBACK 
UNSUBSCRIBE 
UNSUBACK 
PINGREQ 
PINGRESP 
DISCONNECT 
AUTH 
CONNECT 
PUBLISH 
SUBSCRIBE 
SUBSCRIBE_MANY 
UNSUBSCRIBE 
CONNECT 
CONNACK 
PUBLISH 
PUBACK 
PUBREC 
PUBREL 
PUBCOMP 
SUBSCRIBE 
SUBACK 
UNSUBSCRIBE 
UNSUBACK 
PINGREQ 
PINGRESP 
DISCONNECT 
AUTH 

Definition at line 46 of file MQTTPacket.h.

Function Documentation

int MQTTLenStringRead ( MQTTLenString lenstring,
char **  pptr,
char *  enddata 
)

Definition at line 962 of file MQTTPacket.c.

void* MQTTPacket_ack ( int  MQTTVersion,
unsigned char  aHeader,
char *  data,
size_t  datalen 
)

Function used in the new packets table to create acknowledgement packets.

Parameters
MQTTVersionthe version of MQTT being used
aHeaderthe MQTT header byte
datathe rest of the packet
datalenthe length of the rest of the packet
Returns
pointer to the packet structure

Definition at line 783 of file MQTTPacket.c.

int MQTTPacket_decode ( networkHandles net,
size_t *  value 
)

Decodes the message length according to the MQTT algorithm

Parameters
socketthe socket from which to read the bytes
valuethe decoded length returned
Returns
the number of bytes read from the socket

Definition at line 325 of file MQTTPacket.c.

int MQTTPacket_decodeBuf ( char *  buf,
unsigned int *  value 
)

Definition at line 1052 of file MQTTPacket.c.

int MQTTPacket_encode ( char *  buf,
size_t  length 
)

Encodes the message length according to the MQTT algorithm

Parameters
bufthe buffer into which the encoded data is written
lengththe length to be encoded
Returns
the number of bytes written to buffer

Definition at line 297 of file MQTTPacket.c.

void* MQTTPacket_Factory ( int  MQTTVersion,
networkHandles net,
int *  error 
)

Reads one MQTT packet from a socket.

Parameters
socketa socket from which to read an MQTT packet
errorpointer to the error code which is completed if no packet is returned
Returns
the packet structure or NULL if there was an error

Definition at line 103 of file MQTTPacket.c.

void MQTTPacket_free_packet ( MQTTPacket pack)

Free allocated storage for a various packet tyoes

Parameters
packpointer to the suback packet structure

Definition at line 905 of file MQTTPacket.c.

void MQTTPacket_freeAck ( Ack pack)

Free allocated storage for an ack packet.

Parameters
packpointer to the publish packet structure

Definition at line 617 of file MQTTPacket.c.

void MQTTPacket_freePublish ( Publish pack)

Free allocated storage for a publish packet.

Parameters
packpointer to the publish packet structure

Definition at line 601 of file MQTTPacket.c.

void MQTTPacket_freeSuback ( Suback pack)

Free allocated storage for a suback packet.

Parameters
packpointer to the suback packet structure

Definition at line 684 of file MQTTPacket.c.

void MQTTPacket_freeUnsuback ( Unsuback pack)

Free allocated storage for a suback packet.

Parameters
packpointer to the suback packet structure

Definition at line 700 of file MQTTPacket.c.

void* MQTTPacket_header_only ( int  MQTTVersion,
unsigned char  aHeader,
char *  data,
size_t  datalen 
)

Function used in the new packets table to create packets which have only a header.

Parameters
MQTTVersionthe version of MQTT
aHeaderthe MQTT header byte
datathe rest of the packet
datalenthe length of the rest of the packet
Returns
pointer to the packet structure

Definition at line 495 of file MQTTPacket.c.

const char* MQTTPacket_name ( int  ptype)

Converts an MQTT packet code into its name

Parameters
ptypepacket code
Returns
the corresponding string, or "UNKNOWN"

Definition at line 65 of file MQTTPacket.c.

void* MQTTPacket_publish ( int  MQTTVersion,
unsigned char  aHeader,
char *  data,
size_t  datalen 
)

Function used in the new packets table to create publish packets.

Parameters
MQTTVersion
aHeaderthe MQTT header byte
datathe rest of the packet
datalenthe length of the rest of the packet
Returns
pointer to the packet structure

Definition at line 553 of file MQTTPacket.c.

int MQTTPacket_send ( networkHandles net,
Header  header,
char *  buffer,
size_t  buflen,
int  freeData,
int  MQTTVersion 
)

Sends an MQTT packet in one system call write

Parameters
socketthe socket to which to write the data
headerthe one-byte MQTT header
bufferthe rest of the buffer to write (not including remaining length)
buflenthe length of the data in buffer to be written
MQTTVersionthe version of MQTT being used
Returns
the completion code (TCPSOCKET_COMPLETE etc)

Definition at line 190 of file MQTTPacket.c.

int MQTTPacket_send_disconnect ( Clients client,
enum MQTTReasonCodes  reason,
MQTTProperties props 
)

Send an MQTT disconnect packet down a socket.

Parameters
socketthe open socket to send the data to
Returns
the completion code (e.g. TCPSOCKET_COMPLETE)

Definition at line 508 of file MQTTPacket.c.

int MQTTPacket_send_puback ( int  MQTTVersion,
int  msgid,
networkHandles net,
const char *  clientID 
)

Send an MQTT PUBACK packet down a socket.

Parameters
MQTTVersionthe version of MQTT being used
msgidthe MQTT message id to use
socketthe open socket to send the data to
clientIDthe string client identifier, only used for tracing
Returns
the completion code (e.g. TCPSOCKET_COMPLETE)

Definition at line 668 of file MQTTPacket.c.

int MQTTPacket_send_pubcomp ( int  MQTTVersion,
int  msgid,
networkHandles net,
const char *  clientID 
)

Send an MQTT PUBCOMP packet down a socket.

Parameters
MQTTVersionthe version of MQTT being used
msgidthe MQTT message id to use
socketthe open socket to send the data to
clientIDthe string client identifier, only used for tracing
Returns
the completion code (e.g. TCPSOCKET_COMPLETE)

Definition at line 763 of file MQTTPacket.c.

int MQTTPacket_send_publish ( Publish pack,
int  dup,
int  qos,
int  retained,
networkHandles net,
const char *  clientID 
)

Send an MQTT PUBLISH packet down a socket.

Parameters
packa structure from which to get some values to use, e.g topic, payload
dupboolean - whether to set the MQTT DUP flag
qosthe value to use for the MQTT QoS setting
retainedboolean - whether to set the MQTT retained flag
socketthe open socket to send the data to
clientIDthe string client identifier, only used for tracing
Returns
the completion code (e.g. TCPSOCKET_COMPLETE)

Definition at line 835 of file MQTTPacket.c.

int MQTTPacket_send_pubrec ( int  MQTTVersion,
int  msgid,
networkHandles net,
const char *  clientID 
)

Send an MQTT PUBREC packet down a socket.

Parameters
MQTTVersionthe version of MQTT being used
msgidthe MQTT message id to use
socketthe open socket to send the data to
clientIDthe string client identifier, only used for tracing
Returns
the completion code (e.g. TCPSOCKET_COMPLETE)

Definition at line 722 of file MQTTPacket.c.

int MQTTPacket_send_pubrel ( int  MQTTVersion,
int  msgid,
int  dup,
networkHandles net,
const char *  clientID 
)

Send an MQTT PUBREL packet down a socket.

Parameters
MQTTVersionthe version of MQTT being used
msgidthe MQTT message id to use
dupboolean - whether to set the MQTT DUP flag
socketthe open socket to send the data to
clientIDthe string client identifier, only used for tracing
Returns
the completion code (e.g. TCPSOCKET_COMPLETE)

Definition at line 743 of file MQTTPacket.c.

int MQTTPacket_sends ( networkHandles net,
Header  header,
PacketBuffers bufs,
int  MQTTVersion 
)

Sends an MQTT packet from multiple buffers in one system call write

Parameters
socketthe socket to which to write the data
headerthe one-byte MQTT header
countthe number of buffers
buffersthe rest of the buffers to write (not including remaining length)
buflensthe lengths of the data in the array of buffers to be written
theMQTT version being used
Returns
the completion code (TCPSOCKET_COMPLETE etc)

Definition at line 250 of file MQTTPacket.c.

int MQTTPacket_VBIlen ( int  rem_len)

Definition at line 990 of file MQTTPacket.c.

unsigned char readChar ( char **  pptr)

Reads one character from the input buffer.

Parameters
pptrpointer to the input buffer - incremented by the number of bytes used & returned
Returns
the character read

Definition at line 425 of file MQTTPacket.c.

int readInt ( char **  pptr)

Calculates an integer from two bytes read from the input buffer

Parameters
pptrpointer to the input buffer - incremented by the number of bytes used & returned
Returns
the integer value calculated

Definition at line 359 of file MQTTPacket.c.

int readInt4 ( char **  pptr)

Calculates an integer from two bytes read from the input buffer

Parameters
pptrpointer to the input buffer - incremented by the number of bytes used & returned
Returns
the integer value calculated

Definition at line 945 of file MQTTPacket.c.

char* readUTF ( char **  pptr,
char *  enddata 
)

Reads a "UTF" string from the input buffer. UTF as in the MQTT v3 spec which really means a length delimited string. So it reads the two byte length then the data according to that length. The end of the buffer is provided too, so we can prevent buffer overruns caused by an incorrect length.

Parameters
pptrpointer to the input buffer - incremented by the number of bytes used & returned
enddatapointer to the end of the buffer not to be read beyond
Returns
an allocated C string holding the characters read, or NULL if the length read would have caused an overrun.

Definition at line 413 of file MQTTPacket.c.

void writeChar ( char **  pptr,
char  c 
)

Writes one character to an output buffer.

Parameters
pptrpointer to the output buffer - incremented by the number of bytes used & returned
cthe character to write

Definition at line 438 of file MQTTPacket.c.

void writeData ( char **  pptr,
const void *  data,
int  datalen 
)

Writes length delimited data to an output buffer

Parameters
pptrpointer to the output buffer - incremented by the number of bytes used & returned
datathe data to write
datalenthe length of the data to write

Definition at line 479 of file MQTTPacket.c.

void writeInt ( char **  pptr,
int  anInt 
)

Writes an integer as 2 bytes to an output buffer.

Parameters
pptrpointer to the output buffer - incremented by the number of bytes used & returned
anIntthe integer to write

Definition at line 450 of file MQTTPacket.c.

void writeInt4 ( char **  pptr,
int  anInt 
)

Writes an integer as 4 bytes to an output buffer.

Parameters
pptrpointer to the output buffer - incremented by the number of bytes used & returned
anIntthe integer to write

Definition at line 925 of file MQTTPacket.c.

void writeMQTTLenString ( char **  pptr,
MQTTLenString  lenstring 
)

Definition at line 954 of file MQTTPacket.c.

void writeUTF ( char **  pptr,
const char *  string 
)

Writes a "UTF" string to an output buffer. Converts C string to length-delimited.

Parameters
pptrpointer to the output buffer - incremented by the number of bytes used & returned
stringthe C string to write

Definition at line 464 of file MQTTPacket.c.



plotjuggler
Author(s): Davide Faconti
autogenerated on Sun Dec 6 2020 04:02:49