30 #if !defined(NO_PERSISTENCE) 44 #define min(A,B) ( (A) < (B) ? (A):(B)) 52 "RESERVED",
"CONNECT",
"CONNACK",
"PUBLISH",
"PUBACK",
"PUBREC",
"PUBREL",
53 "PUBCOMP",
"SUBSCRIBE",
"SUBACK",
"UNSUBSCRIBE",
"UNSUBACK",
54 "PINGREQ",
"PINGRESP",
"DISCONNECT",
"AUTH" 94 static char*
readUTFlen(
char** pptr,
char* enddata,
int*
len);
107 size_t remaining_length;
110 size_t actual_len = 0;
128 if (remaining_length && data == NULL)
134 if (actual_len < remaining_length)
145 if ((pack = (*
new_packets[ptype])(MQTTVersion, header.
byte, data, remaining_length)) == NULL)
150 #if !defined(NO_PERSISTENCE) 161 buf[0] = header.
byte;
164 &data, &remaining_length, header.
bits.
type, ((
Publish *)pack)->msgId, 1, MQTTVersion);
206 buf[0] = header.
byte;
209 #if !defined(NO_PERSISTENCE) 212 char* ptraux = buffer;
216 header.
bits.
type, msgId, 0, MQTTVersion);
219 packetbufs.
count = 1;
222 packetbufs.
frees = &freeData;
223 memset(packetbufs.
mask,
'\0',
sizeof(packetbufs.
mask));
253 size_t buf0len, total = 0;
257 for (i = 0; i < bufs->
count; i++)
266 buf[0] = header.
byte;
269 #if !defined(NO_PERSISTENCE) 272 char *ptraux = bufs->
buffers[2];
275 header.
bits.
type, msgId, 0, MQTTVersion);
304 char d = length % 128;
313 }
while (length > 0);
331 #define MAX_NO_OF_REMAINING_LENGTH_BYTES 4 345 *value += (c & 127) * multiplier;
347 }
while ((c & 128) != 0);
362 int len = 256*((
unsigned char)(*ptr)) + (
unsigned char)(*(ptr+1));
385 if (enddata - (*pptr) > 1)
388 if (&(*pptr)[*len] <= enddata)
390 if ((
string =
malloc(*len+1)) == NULL)
392 memcpy(
string, *pptr, *len);
427 unsigned char c = **pptr;
452 **pptr = (char)(anInt / 256);
454 **pptr = (char)(anInt % 256);
466 size_t len = strlen(
string);
468 memcpy(*pptr,
string, len);
482 memcpy(*pptr, data, datalen);
497 static unsigned char header = 0;
523 if ((buf =
malloc(buflen)) == NULL)
556 char* curdata =
data;
557 char* enddata = &data[datalen];
562 memset(pack,
'\0',
sizeof(
Publish));
590 pack->
payloadlen = (int)(datalen-(curdata-data));
604 if (pack->
topic != NULL)
644 if ((ptr = buf =
malloc(2)) == NULL)
689 if (pack->
qoss != NULL)
786 char* curdata =
data;
787 char* enddata = &data[datalen];
790 if ((pack =
malloc(
sizeof(
Ack))) == NULL)
843 if (topiclen == NULL)
854 char* bufs[4] = {topiclen, pack->
topic, NULL, pack->
payload};
856 int frees[4] = {1, 0, 1, 0};
859 bufs[2] = ptr =
malloc(buflen);
872 memcpy(pack->
mask, packetbufs.
mask,
sizeof(pack->
mask));
876 char*
ptr = topiclen;
879 int frees[3] = {1, 0, 0};
884 memcpy(pack->
mask, packetbufs.
mask,
sizeof(pack->
mask));
890 Log(
LOG_PROTOCOL, 10, NULL, net->
socket, clientID, pack->
msgId, qos, retained, rc, pack->
payloadlen,
927 **pptr = (char)(anInt / 16777216);
930 **pptr = (char)(anInt / 65536);
933 **pptr = (char)(anInt / 256);
935 **pptr = (char)(anInt % 256);
947 unsigned char*
ptr = (
unsigned char*)*pptr;
948 int value = 16777216*(*ptr) + 65536*(*(ptr+1)) + 256*(*(ptr+2)) + (*(ptr+3));
957 memcpy(*pptr, lenstring.
data, lenstring.
len);
958 *pptr += lenstring.
len;
967 if (enddata - (*pptr) > 1)
970 if (&(*pptr)[lenstring->
len] <= enddata)
972 lenstring->
data = (
char*)*pptr;
973 *pptr += lenstring->
len;
974 len = 2 + lenstring->
len;
996 else if (rem_len < 16384)
998 else if (rem_len < 2097152)
1017 #define MAX_NO_OF_REMAINING_LENGTH_BYTES 4 1029 rc = (*getcharfn)(&
c, 1);
1032 *value += (c & 127) * multiplier;
1034 }
while ((c & 128) != 0);
1046 for (i = 0; i <
count; ++i)
static int MQTTPacket_send_ack(int MQTTVersion, int type, int msgid, int dup, networkHandles *net)
void MQTTPacket_freeSuback(Suback *pack)
MQTTProperties properties
void WebSocket_framePosSeekTo(size_t pos)
void MQTTPacket_freeAck(Ack *pack)
int MQTTProperties_read(MQTTProperties *properties, char **pptr, char *enddata)
enum MQTTPropertyCodes value
void * MQTTPacket_suback(int MQTTVersion, unsigned char aHeader, char *data, size_t datalen)
int MQTTProperties_len(MQTTProperties *props)
int MQTTPacket_VBIlen(int rem_len)
int MQTTProperties_write(char **pptr, const MQTTProperties *properties)
void * MQTTPacket_publish(int MQTTVersion, unsigned char aHeader, char *data, size_t datalen)
void MQTTProperties_free(MQTTProperties *props)
unsigned char readChar(char **pptr)
void *(* pf)(int, unsigned char, char *, size_t)
int MQTTPacket_send_puback(int MQTTVersion, int msgid, networkHandles *net, const char *clientID)
#define MAX_NO_OF_REMAINING_LENGTH_BYTES
void MQTTPacket_free_packet(MQTTPacket *pack)
size_t WebSocket_framePos()
int MQTTPacket_send_disconnect(Clients *client, enum MQTTReasonCodes reason, MQTTProperties *props)
char * WebSocket_getdata(networkHandles *net, size_t bytes, size_t *actual_len)
receives data from a socket. It should receive all data from the socket that is immediately available...
void MQTTPacket_freePublish(Publish *pack)
char * readUTF(char **pptr, char *enddata)
void writeInt(char **pptr, int anInt)
static l_noret error(LoadState *S, const char *why)
void writeMQTTLenString(char **pptr, MQTTLenString lenstring)
MQTTProperties properties
void writeChar(char **pptr, char c)
int MQTTPacket_send_pubcomp(int MQTTVersion, int msgid, networkHandles *net, const char *clientID)
const char ** MQTTClient_packet_names
int MQTTPacket_decode(networkHandles *net, size_t *value)
void * MQTTPacket_connack(int MQTTVersion, unsigned char aHeader, char *data, size_t datalen)
int bufchar(char *c, int count)
int MQTTPacket_decodeBuf(char *buf, unsigned int *value)
int MQTTPacket_encode(char *buf, size_t length)
int readInt4(char **pptr)
static char * readUTFlen(char **pptr, char *enddata, int *len)
START_TIME_TYPE lastReceived
int MQTTLenStringRead(MQTTLenString *lenstring, char **pptr, char *enddata)
const char * MQTTPacket_name(int ptype)
void writeData(char **pptr, const void *data, int datalen)
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)
void MQTTPacket_freeUnsuback(Unsuback *pack)
void Log(enum LOG_LEVELS log_level, int msgno, const char *format,...)
void * MQTTPacket_Factory(int MQTTVersion, networkHandles *net, int *error)
MQTTProperties properties
int WebSocket_getch(networkHandles *net, char *c)
receives 1 byte from a socket
void writeUTF(char **pptr, const char *string)
void * MQTTPacket_unsuback(int MQTTVersion, unsigned char aHeader, char *data, size_t datalen)
void writeInt4(char **pptr, int anInt)
int MQTTPacket_VBIdecode(int(*getcharfn)(char *, int), unsigned int *value)
int WebSocket_putdatas(networkHandles *net, char **buf0, size_t *buf0len, PacketBuffers *bufs)
int MQTTPersistence_putPacket(int socket, char *buf0, size_t buf0len, int count, char **buffers, size_t *buflens, int htype, int msgId, int scr, int MQTTVersion)
START_TIME_TYPE MQTTTime_now(void)
void * MQTTPacket_ack(int MQTTVersion, unsigned char aHeader, char *data, size_t datalen)
int MQTTPacket_send(networkHandles *net, Header header, char *buffer, size_t buflen, int freeData, int MQTTVersion)
#define TCPSOCKET_COMPLETE
int MQTTPacket_sends(networkHandles *net, Header header, PacketBuffers *bufs, int MQTTVersion)
static const char * packet_names[]
MQTTProperties properties
void ListFree(List *aList)
int MQTTPacket_send_publish(Publish *pack, int dup, int qos, int retained, networkHandles *net, const char *clientID)
#define TCPSOCKET_INTERRUPTED
void * MQTTPacket_header_only(int MQTTVersion, unsigned char aHeader, char *data, size_t datalen)
#define MQTTProperties_initializer