Skip to content

Commit

Permalink
WIP: Separating v3 and v5
Browse files Browse the repository at this point in the history
  • Loading branch information
CIPop committed Aug 11, 2023
1 parent 1383551 commit 8d25790
Show file tree
Hide file tree
Showing 32 changed files with 584 additions and 118 deletions.
15 changes: 13 additions & 2 deletions MQTTClient/src/MQTTClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -421,10 +421,16 @@ int MQTT::Client<Network, Timer, a, b>::sendPacket(int32_t length, Timer& timer)
rc = FAILURE;

#if defined(MQTT_DEBUG)

char printbuf[150];
DEBUG("Rc %d from sending packet %s\r\n", rc,
#if defined(MQTTV5)
MQTTV5Format_toServerString(printbuf, sizeof(printbuf), sendbuf, length));
#else
MQTTFormat_toServerString(printbuf, sizeof(printbuf), sendbuf, length));
#endif
#endif // MQTTV5

#endif // MQTT_DEBUG
return rc;
}

Expand Down Expand Up @@ -503,7 +509,12 @@ int MQTT::Client<Network, Timer, MAX_MQTT_PACKET_SIZE, b>::readPacket(Timer& tim
{
char printbuf[50];
DEBUG("Rc %d receiving packet %s\r\n", rc,
MQTTFormat_toClientString(printbuf, sizeof(printbuf), readbuf, len));
#if defined(MQTTV5)
MQTTV5Format_toClientString(printbuf, sizeof(printbuf), readbuf, len));
#else
MQTTFormat_toClientString(printbuf, sizeof(printbuf), readbuf, len));
#endif // MQTTV5

}
#endif
return rc;
Expand Down
3 changes: 2 additions & 1 deletion MQTTPacket/samples/v5log.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
*
*******************************************************************************/

#include "V5/MQTTV5Packet.h"
#include <stdio.h>
#include "MQTTV5Packet.h"

static const char* v5property_identifier_to_string(int identifier)
{
Expand Down
2 changes: 1 addition & 1 deletion MQTTPacket/samples/v5log.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*
*******************************************************************************/

#include "V5/MQTTV5Packet.h"
#include "MQTTV5Packet.h"

void v5property_print(MQTTProperty property);
const char* v5reasoncode_to_string(int reasoncode);
2 changes: 1 addition & 1 deletion MQTTPacket/samples/v5ping.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include <string.h>
#include <stdlib.h>

#include "V5/MQTTV5Packet.h"
#include "MQTTV5Packet.h"
#include "transport.h"
#include "v5log.h"

Expand Down
2 changes: 1 addition & 1 deletion MQTTPacket/samples/v5ping_nb.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include <string.h>
#include <stdlib.h>

#include "V5/MQTTV5Packet.h"
#include "MQTTV5Packet.h"
#include "transport.h"
#include "v5log.h"

Expand Down
4 changes: 2 additions & 2 deletions MQTTPacket/samples/v5pub0sub1.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include <string.h>
#include <stdlib.h>

#include "V5/MQTTV5Packet.h"
#include "MQTTV5Packet.h"
#include "transport.h"
#include "v5log.h"

Expand Down Expand Up @@ -258,7 +258,7 @@ int main(int argc, char *argv[])
}

printf("disconnecting\n");
len = MQTTSerialize_disconnect(buf, buflen);
len = MQTTV5Serialize_disconnect(buf, buflen, MQTTREASONCODE_NORMAL_DISCONNECTION, NULL);
rc = transport_sendPacketBuffer(mysock, buf, len);

exit:
Expand Down
2 changes: 1 addition & 1 deletion MQTTPacket/samples/v5pub0sub1_nb.c
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ int main(int argc, char *argv[])
}

printf("disconnecting\n");
len = MQTTSerialize_disconnect(buf, buflen);
len = MQTTV5Serialize_disconnect(buf, buflen, MQTTREASONCODE_NORMAL_DISCONNECTION, NULL);
rc = transport_sendPacketBuffer(mysock, buf, len);

exit:
Expand Down
2 changes: 1 addition & 1 deletion MQTTPacket/samples/v5qos0pub.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include <string.h>
#include <stdlib.h>

#include "V5/MQTTV5Packet.h"
#include "MQTTV5Packet.h"
#include "transport.h"
#include "v5log.h"

Expand Down
14 changes: 7 additions & 7 deletions MQTTPacket/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#*******************************************************************************
# Copyright (c) 2017 IBM Corp.
# Copyright (c) 2017, 2023 IBM Corp.
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
Expand All @@ -15,33 +15,33 @@
#*******************************************************************************/

# MQTTPacket Library
file(GLOB SOURCES "*.c")
file(GLOB SOURCES "*.c" "V3/*.c")
add_library(paho-embed-mqtt3c SHARED ${SOURCES})
install(TARGETS paho-embed-mqtt3c DESTINATION /usr/lib)
target_compile_definitions(paho-embed-mqtt3c PRIVATE MQTT_SERVER MQTT_CLIENT)

add_library(MQTTPacketClient SHARED MQTTFormat MQTTPacket
add_library(MQTTPacketClient SHARED V3/MQTTFormat MQTTPacket
MQTTSerializePublish MQTTDeserializePublish
MQTTConnectClient MQTTSubscribeClient MQTTUnsubscribeClient)
target_compile_definitions(MQTTPacketClient PRIVATE MQTT_CLIENT)

add_library(MQTTPacketServer SHARED MQTTFormat MQTTPacket
add_library(MQTTPacketServer SHARED V3/MQTTFormat MQTTPacket
MQTTSerializePublish MQTTDeserializePublish
MQTTConnectServer MQTTSubscribeServer MQTTUnsubscribeServer)
target_compile_definitions(MQTTPacketServer PRIVATE MQTT_SERVER)

file(GLOB SOURCES5 "*.c" "V5/*.c" ../samples/transport.c)
file(GLOB SOURCES5 "*.c" "V5/*.c")

add_library(paho-embed-mqtt5c SHARED ${SOURCES5})
install(TARGETS paho-embed-mqtt5c DESTINATION /usr/lib)
target_compile_definitions(paho-embed-mqtt5c PRIVATE MQTT_SERVER MQTT_CLIENT MQTTV5)

add_library(MQTTPacketClient5 SHARED MQTTFormat MQTTPacket
add_library(MQTTPacketClient5 SHARED V5/MQTTV5Format MQTTPacket
MQTTSerializePublish MQTTDeserializePublish V5/MQTTProperties V5/MQTTV5Packet
MQTTConnectClient MQTTSubscribeClient MQTTUnsubscribeClient)
target_compile_definitions(MQTTPacketClient5 PRIVATE MQTT_CLIENT MQTTV5)

add_library(MQTTPacketServer5 SHARED MQTTFormat MQTTPacket
add_library(MQTTPacketServer5 SHARED V5/MQTTV5Format MQTTPacket
MQTTSerializePublish MQTTDeserializePublish V5/MQTTProperties V5/MQTTV5Packet
MQTTConnectServer MQTTSubscribeServer MQTTUnsubscribeServer)
target_compile_definitions(MQTTPacketServer5 PRIVATE MQTT_SERVER MQTTV5)
26 changes: 5 additions & 21 deletions MQTTPacket/src/MQTTConnectClient.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*******************************************************************************/

#if defined(MQTTV5)
#include "V5/MQTTV5Packet.h"
#include "MQTTV5Packet.h"
#else
#include "MQTTPacket.h"
#endif
Expand Down Expand Up @@ -72,11 +72,6 @@ int MQTTSerialize_connectLength(MQTTPacket_connectData* options)
* @return serialized length, or error if 0
*/
#if defined(MQTTV5)
int MQTTSerialize_connect(unsigned char* buf, int32_t buflen, MQTTPacket_connectData* options)
{
return MQTTV5Serialize_connect(buf, buflen, options, NULL);
}

int MQTTV5Serialize_connect(unsigned char* buf, int32_t buflen, MQTTPacket_connectData* options,
MQTTProperties* connectProperties)
#else
Expand Down Expand Up @@ -166,11 +161,6 @@ int MQTTSerialize_connect(unsigned char* buf, int32_t buflen, MQTTPacket_connect
* @return error code. 1 is success, 0 is failure
*/
#if defined(MQTTV5)
int MQTTDeserialize_connack(unsigned char* sessionPresent, unsigned char* connack_rc, unsigned char* buf, int32_t buflen)
{
return MQTTV5Deserialize_connack(NULL, sessionPresent, connack_rc, buf, buflen);
}

int MQTTV5Deserialize_connack(MQTTProperties* connackProperties, unsigned char* sessionPresent, unsigned char* connack_rc,
unsigned char* buf, int32_t buflen)
#else
Expand Down Expand Up @@ -221,11 +211,6 @@ int MQTTDeserialize_connack(unsigned char* sessionPresent, unsigned char* connac
int MQTTV5Serialize_zero(unsigned char* buf, int32_t buflen, unsigned char packettype,
unsigned char reasonCode, MQTTProperties* properties);

int MQTTSerialize_zero(unsigned char* buf, int32_t buflen, unsigned char packettype)
{
return MQTTV5Serialize_zero(buf, buflen, packettype, -1, NULL);
}

int MQTTV5Serialize_zero(unsigned char* buf, int32_t buflen, unsigned char packettype,
unsigned char reasonCode, MQTTProperties* properties)
#else
Expand Down Expand Up @@ -278,11 +263,6 @@ int MQTTSerialize_zero(unsigned char* buf, int32_t buflen, unsigned char packett
* @return serialized length, or error if 0
*/
#if defined(MQTTV5)
int MQTTSerialize_disconnect(unsigned char* buf, int32_t buflen)
{
return MQTTV5Serialize_disconnect(buf, buflen, -1, NULL);
}

int MQTTV5Serialize_disconnect(unsigned char* buf, int32_t buflen,
unsigned char reasonCode, MQTTProperties* properties)
#else
Expand Down Expand Up @@ -314,5 +294,9 @@ int MQTTV5Serialize_auth(unsigned char* buf, int32_t buflen,
*/
int MQTTSerialize_pingreq(unsigned char* buf, int32_t buflen)
{
#if defined(MQTTV5)
return MQTTV5Serialize_zero(buf, buflen, PINGREQ, -1, NULL);
#else
return MQTTSerialize_zero(buf, buflen, PINGREQ);
#endif
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2014, 2023 IBM Corp. and others
* Copyright (c) 2023 Microsoft Corporation. All rights reserved.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
Expand All @@ -10,21 +10,15 @@
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* Contributors:
* Ian Craggs - initial API and implementation and/or initial documentation
* Ian Craggs - add connack return code definitions
* Xiang Rong - 442039 Add makefile to Embedded C client
* Ian Craggs - fix for issue #64, bit order in connack response
*******************************************************************************/

#ifndef MQTTCONNECT_H_
#define MQTTCONNECT_H_
#ifndef MQTTCONNECT_COMMON_H_
#define MQTTCONNECT_COMMON_H_

#include <stdint.h>
#if defined(MQTTV5)
#include "V5/MQTTProperties.h"
#endif

#else
enum MQTTConnackReturnCodes
{
MQTTCONNACK_CONNECTION_ACCEPTED = 0,
Expand All @@ -34,6 +28,8 @@ enum MQTTConnackReturnCodes
MQTTCONNACK_BAD_USERNAME_OR_PASSWORD = 4,
MQTTCONNACK_NOT_AUTHORIZED = 5,
};
#endif


#if !defined(DLLImport)
#define DLLImport
Expand Down Expand Up @@ -145,14 +141,4 @@ typedef union
#define MQTTPacket_connectData_initializer { {'M', 'Q', 'T', 'C'}, 4, {NULL, {0, NULL}}, 60, 1, 0, \
MQTTPacket_willOptions_initializer, {NULL, {0, NULL}}, {NULL, {0, NULL}} }

DLLExport int MQTTSerialize_connect(unsigned char* buf, int32_t buflen, MQTTPacket_connectData* options);
DLLExport int MQTTDeserialize_connect(MQTTPacket_connectData* data, unsigned char* buf, int32_t len);

DLLExport int MQTTSerialize_connack(unsigned char* buf, int32_t buflen, unsigned char connack_rc, unsigned char sessionPresent);
DLLExport int MQTTDeserialize_connack(unsigned char* sessionPresent, unsigned char* connack_rc, unsigned char* buf, int32_t buflen);

DLLExport int MQTTSerialize_disconnect(unsigned char* buf, int32_t buflen);
DLLExport int MQTTDeserialize_disconnect(unsigned char* buf, int32_t buflen);
DLLExport int MQTTSerialize_pingreq(unsigned char* buf, int32_t buflen);

#endif /* MQTTCONNECT_H_ */
#endif /* MQTTCONNECT_COMMON_H_ */
2 changes: 1 addition & 1 deletion MQTTPacket/src/MQTTConnectServer.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

#include "StackTrace.h"
#if defined(MQTTV5)
#include "V5/MQTTV5Packet.h"
#include "MQTTV5Packet.h"
#else
#include "MQTTPacket.h"
#endif
Expand Down
2 changes: 1 addition & 1 deletion MQTTPacket/src/MQTTDeserializePublish.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*******************************************************************************/

#if defined(MQTTV5)
#include "V5/MQTTV5Packet.h"
#include "MQTTV5Packet.h"
#else
#include "MQTTPacket.h"
#endif
Expand Down
10 changes: 5 additions & 5 deletions MQTTPacket/src/MQTTPacket.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@ typedef struct

int MQTTstrlen(MQTTString mqttstring);

#include "MQTTConnect.h"
#include "MQTTPublish.h"
#include "MQTTSubscribe.h"
#include "MQTTUnsubscribe.h"
#include "MQTTFormat.h"
#include "V3/MQTTConnect.h"
#include "V3/MQTTPublish.h"
#include "V3/MQTTSubscribe.h"
#include "V3/MQTTUnsubscribe.h"
#include "V3/MQTTFormat.h"

DLLExport int32_t MQTTSerialize_ack(unsigned char* buf, int32_t buflen, unsigned char type, unsigned char dup, unsigned short packetid);
DLLExport int32_t MQTTDeserialize_ack(unsigned char* packettype, unsigned char* dup, unsigned short* packetid, unsigned char* buf, int32_t buflen);
Expand Down
Loading

0 comments on commit 8d25790

Please sign in to comment.