paho_mqtt_c: refactor: rename symbols so they all have same prefix (#204)
* paho_mqtt_c: refactor: rename symbols so they all have same prefix * Update AWS IOT example after MQTT refactoring
This commit is contained in:
parent
12d0da0c58
commit
8368929a66
18 changed files with 488 additions and 470 deletions
|
|
@ -25,7 +25,7 @@
|
|||
* @param length the length to be encoded
|
||||
* @return the number of bytes written to buffer
|
||||
*/
|
||||
int MQTTPacket_encode(unsigned char* buf, int length)
|
||||
int mqtt_packet_encode(unsigned char* buf, int length)
|
||||
{
|
||||
int rc = 0;
|
||||
|
||||
|
|
@ -50,7 +50,7 @@ int MQTTPacket_encode(unsigned char* buf, int length)
|
|||
* @param value the decoded length returned
|
||||
* @return the number of bytes read from the socket
|
||||
*/
|
||||
int MQTTPacket_decode(int (*getcharfn)(unsigned char*, int), int* value)
|
||||
int mqtt_packet_decode(int (*getcharfn)(unsigned char*, int), int* value)
|
||||
{
|
||||
unsigned char c;
|
||||
int multiplier = 1;
|
||||
|
|
@ -80,7 +80,7 @@ exit:
|
|||
}
|
||||
|
||||
|
||||
int MQTTPacket_len(int rem_len)
|
||||
int mqtt_packet_len(int rem_len)
|
||||
{
|
||||
rem_len += 1; /* header byte */
|
||||
|
||||
|
|
@ -99,7 +99,7 @@ int MQTTPacket_len(int rem_len)
|
|||
|
||||
static unsigned char* bufptr;
|
||||
|
||||
int bufchar(unsigned char* c, int count)
|
||||
static int bufchar(unsigned char* c, int count)
|
||||
{
|
||||
int i;
|
||||
|
||||
|
|
@ -109,10 +109,10 @@ int bufchar(unsigned char* c, int count)
|
|||
}
|
||||
|
||||
|
||||
int MQTTPacket_decodeBuf(unsigned char* buf, int* value)
|
||||
int mqtt_packet_decode_buf(unsigned char* buf, int* value)
|
||||
{
|
||||
bufptr = buf;
|
||||
return MQTTPacket_decode(bufchar, value);
|
||||
return mqtt_packet_decode(bufchar, value);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -121,7 +121,7 @@ int MQTTPacket_decodeBuf(unsigned char* buf, int* value)
|
|||
* @param pptr pointer to the input buffer - incremented by the number of bytes used & returned
|
||||
* @return the integer value calculated
|
||||
*/
|
||||
int readInt(unsigned char** pptr)
|
||||
int mqtt_read_int(unsigned char** pptr)
|
||||
{
|
||||
unsigned char* ptr = *pptr;
|
||||
int len = 256*(*ptr) + (*(ptr+1));
|
||||
|
|
@ -135,7 +135,7 @@ int readInt(unsigned char** pptr)
|
|||
* @param pptr pointer to the input buffer - incremented by the number of bytes used & returned
|
||||
* @return the character read
|
||||
*/
|
||||
char readChar(unsigned char** pptr)
|
||||
char mqtt_read_char(unsigned char** pptr)
|
||||
{
|
||||
char c = **pptr;
|
||||
(*pptr)++;
|
||||
|
|
@ -148,7 +148,7 @@ char readChar(unsigned char** pptr)
|
|||
* @param pptr pointer to the output buffer - incremented by the number of bytes used & returned
|
||||
* @param c the character to write
|
||||
*/
|
||||
void writeChar(unsigned char** pptr, char c)
|
||||
void mqtt_write_char(unsigned char** pptr, char c)
|
||||
{
|
||||
**pptr = c;
|
||||
(*pptr)++;
|
||||
|
|
@ -160,7 +160,7 @@ void writeChar(unsigned char** pptr, char c)
|
|||
* @param pptr pointer to the output buffer - incremented by the number of bytes used & returned
|
||||
* @param anInt the integer to write
|
||||
*/
|
||||
void writeInt(unsigned char** pptr, int anInt)
|
||||
void mqtt_write_int(unsigned char** pptr, int anInt)
|
||||
{
|
||||
**pptr = (unsigned char)(anInt / 256);
|
||||
(*pptr)++;
|
||||
|
|
@ -174,34 +174,34 @@ void writeInt(unsigned char** pptr, int anInt)
|
|||
* @param pptr pointer to the output buffer - incremented by the number of bytes used & returned
|
||||
* @param string the C string to write
|
||||
*/
|
||||
void writeCString(unsigned char** pptr, const char* string)
|
||||
void mqtt_write_cstr(unsigned char** pptr, const char* string)
|
||||
{
|
||||
int len = strlen(string);
|
||||
writeInt(pptr, len);
|
||||
mqtt_write_int(pptr, len);
|
||||
memcpy(*pptr, string, len);
|
||||
*pptr += len;
|
||||
}
|
||||
|
||||
|
||||
int getLenStringLen(char* ptr)
|
||||
{
|
||||
int len = 256*((unsigned char)(*ptr)) + (unsigned char)(*(ptr+1));
|
||||
return len;
|
||||
}
|
||||
//int getLenStringLen(char* ptr)
|
||||
//{
|
||||
// int len = 256*((unsigned char)(*ptr)) + (unsigned char)(*(ptr+1));
|
||||
// return len;
|
||||
//}
|
||||
|
||||
|
||||
void writeMQTTString(unsigned char** pptr, MQTTString mqttstring)
|
||||
void mqtt_write_mqqt_str(unsigned char** pptr, mqtt_string_t mqttstring)
|
||||
{
|
||||
if (mqttstring.lenstring.len > 0)
|
||||
{
|
||||
writeInt(pptr, mqttstring.lenstring.len);
|
||||
mqtt_write_int(pptr, mqttstring.lenstring.len);
|
||||
memcpy(*pptr, mqttstring.lenstring.data, mqttstring.lenstring.len);
|
||||
*pptr += mqttstring.lenstring.len;
|
||||
}
|
||||
else if (mqttstring.cstring)
|
||||
writeCString(pptr, mqttstring.cstring);
|
||||
mqtt_write_cstr(pptr, mqttstring.cstring);
|
||||
else
|
||||
writeInt(pptr, 0);
|
||||
mqtt_write_int(pptr, 0);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -211,7 +211,7 @@ void writeMQTTString(unsigned char** pptr, MQTTString mqttstring)
|
|||
* @param enddata pointer to the end of the data: do not read beyond
|
||||
* @return 1 if successful, 0 if not
|
||||
*/
|
||||
int readMQTTLenString(MQTTString* mqttstring, unsigned char** pptr, unsigned char* enddata)
|
||||
int mqtt_read_str_len(mqtt_string_t* mqttstring, unsigned char** pptr, unsigned char* enddata)
|
||||
{
|
||||
int rc = 0;
|
||||
|
||||
|
|
@ -219,7 +219,7 @@ int readMQTTLenString(MQTTString* mqttstring, unsigned char** pptr, unsigned ch
|
|||
/* the first two bytes are the length of the string */
|
||||
if (enddata - (*pptr) > 1) /* enough length to read the integer? */
|
||||
{
|
||||
mqttstring->lenstring.len = readInt(pptr); /* increments pptr to point past length */
|
||||
mqttstring->lenstring.len = mqtt_read_int(pptr); /* increments pptr to point past length */
|
||||
if (&(*pptr)[mqttstring->lenstring.len] <= enddata)
|
||||
{
|
||||
mqttstring->lenstring.data = (char*)*pptr;
|
||||
|
|
@ -238,7 +238,7 @@ int readMQTTLenString(MQTTString* mqttstring, unsigned char** pptr, unsigned ch
|
|||
* @param mqttstring the string to return the length of
|
||||
* @return the length of the string
|
||||
*/
|
||||
int MQTTstrlen(MQTTString mqttstring)
|
||||
int mqtt_strlen(mqtt_string_t mqttstring)
|
||||
{
|
||||
int rc = 0;
|
||||
|
||||
|
|
@ -256,7 +256,7 @@ int MQTTstrlen(MQTTString mqttstring)
|
|||
* @param bptr the C string to compare
|
||||
* @return boolean - equal or not
|
||||
*/
|
||||
int MQTTPacket_equals(MQTTString* a, char* bptr)
|
||||
int mqtt_packet_equals(mqtt_string_t* a, char* bptr)
|
||||
{
|
||||
int alen = 0,
|
||||
blen = 0;
|
||||
|
|
@ -286,10 +286,10 @@ int MQTTPacket_equals(MQTTString* a, char* bptr)
|
|||
* @return integer MQTT packet type, or -1 on error
|
||||
* @note the whole message must fit into the caller's buffer
|
||||
*/
|
||||
int MQTTPacket_read(unsigned char* buf, int buflen, int (*getfn)(unsigned char*, int))
|
||||
int mqtt_packet_read(unsigned char* buf, int buflen, int (*getfn)(unsigned char*, int))
|
||||
{
|
||||
int rc = -1;
|
||||
MQTTHeader header = {0};
|
||||
mqtt_header_t header = {0};
|
||||
int len = 0;
|
||||
int rem_len = 0;
|
||||
|
||||
|
|
@ -299,8 +299,8 @@ int MQTTPacket_read(unsigned char* buf, int buflen, int (*getfn)(unsigned char*
|
|||
|
||||
len = 1;
|
||||
/* 2. read the remaining length. This is variable in itself */
|
||||
MQTTPacket_decode(getfn, &rem_len);
|
||||
len += MQTTPacket_encode(buf + 1, rem_len); /* put the original remaining length back into the buffer */
|
||||
mqtt_packet_decode(getfn, &rem_len);
|
||||
len += mqtt_packet_encode(buf + 1, rem_len); /* put the original remaining length back into the buffer */
|
||||
|
||||
/* 3. read the rest of the buffer using a callback to supply the rest of the data */
|
||||
if((rem_len + len) > buflen)
|
||||
|
|
@ -320,7 +320,7 @@ exit:
|
|||
* @param value the decoded length returned
|
||||
* @return integer the number of bytes read from the socket, 0 for call again, or -1 on error
|
||||
*/
|
||||
static int MQTTPacket_decodenb(MQTTTransport *trp)
|
||||
static int decodenb(mqtt_transport_t *trp)
|
||||
{
|
||||
unsigned char c;
|
||||
int rc = MQTTPACKET_READ_ERROR;
|
||||
|
|
@ -357,10 +357,10 @@ exit:
|
|||
* @return integer MQTT packet type, 0 for call again, or -1 on error
|
||||
* @note the whole message must fit into the caller's buffer
|
||||
*/
|
||||
int MQTTPacket_readnb(unsigned char* buf, int buflen, MQTTTransport *trp)
|
||||
int mqtt_packet_readnb(unsigned char* buf, int buflen, mqtt_transport_t *trp)
|
||||
{
|
||||
int rc = -1, frc;
|
||||
MQTTHeader header = {0};
|
||||
mqtt_header_t header = {0};
|
||||
|
||||
switch(trp->state){
|
||||
default:
|
||||
|
|
@ -377,11 +377,11 @@ int MQTTPacket_readnb(unsigned char* buf, int buflen, MQTTTransport *trp)
|
|||
/*FALLTHROUGH*/
|
||||
/* read the remaining length. This is variable in itself */
|
||||
case 1:
|
||||
if((frc=MQTTPacket_decodenb(trp)) == MQTTPACKET_READ_ERROR)
|
||||
if((frc=decodenb(trp)) == MQTTPACKET_READ_ERROR)
|
||||
goto exit;
|
||||
if(frc == 0)
|
||||
return 0;
|
||||
trp->len = 1 + MQTTPacket_encode(buf + 1, trp->rem_len); /* put the original remaining length back into the buffer */
|
||||
trp->len = 1 + mqtt_packet_encode(buf + 1, trp->rem_len); /* put the original remaining length back into the buffer */
|
||||
if((trp->rem_len + trp->len) > buflen)
|
||||
goto exit;
|
||||
++trp->state;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue