Eliminate -Wextra warnings
This commit is contained in:
parent
e5ca2d8578
commit
24b9d6c3c6
12 changed files with 65 additions and 56 deletions
|
@ -11,6 +11,7 @@
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "debug.h"
|
||||||
#include "mqtt_internal.h"
|
#include "mqtt_internal.h"
|
||||||
#include "platform.h"
|
#include "platform.h"
|
||||||
|
|
||||||
|
@ -24,7 +25,7 @@ struct _PlatformData {
|
||||||
};
|
};
|
||||||
|
|
||||||
PlatformStatusCode platform_init(MQTTHandle *handle) {
|
PlatformStatusCode platform_init(MQTTHandle *handle) {
|
||||||
handle->platform = calloc(1, sizeof(struct _PlatformData));
|
handle->platform = (PlatformData *)calloc(1, sizeof(struct _PlatformData));
|
||||||
handle->platform->sock = -1;
|
handle->platform->sock = -1;
|
||||||
if (handle->platform) {
|
if (handle->platform) {
|
||||||
return PlatformStatusOk;
|
return PlatformStatusOk;
|
||||||
|
@ -64,6 +65,7 @@ PlatformStatusCode platform_run_task(MQTTHandle *handle, int *task_handle, Platf
|
||||||
return PlatformStatusError;
|
return PlatformStatusError;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*task_handle = free_task;
|
||||||
return PlatformStatusOk;
|
return PlatformStatusOk;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
#include "mqtt_internal.h"
|
#include "mqtt_internal.h"
|
||||||
|
|
||||||
typedef void (*PlatformTask)(MQTTHandle *handle);
|
typedef void *(*PlatformTask)(MQTTHandle *handle);
|
||||||
|
|
||||||
/** maximum receiver buffer size, defined by platform */
|
/** maximum receiver buffer size, defined by platform */
|
||||||
extern const size_t max_receive_buffer_size;
|
extern const size_t max_receive_buffer_size;
|
||||||
|
|
|
@ -198,7 +198,7 @@ static inline size_t buffer_append_buffer(Buffer *dest, Buffer *src) {
|
||||||
return buffer_append_data(dest, src->data, src->len);
|
return buffer_append_data(dest, src->data, src->len);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if DEBUG
|
#if DEBUG_HEXDUMP
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
|
||||||
static inline void buffer_hexdump(Buffer *buffer, int indent) {
|
static inline void buffer_hexdump(Buffer *buffer, int indent) {
|
||||||
|
|
10
src/mqtt.c
10
src/mqtt.c
|
@ -35,7 +35,7 @@ static inline void parse_packet(MQTTHandle *handle, MQTTPacket *packet) {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PacketTypePublish:
|
case PacketTypePublish:
|
||||||
dispatch_subscription(handle, packet->payload);
|
dispatch_subscription(handle, (PublishPayload *)packet->payload);
|
||||||
// TODO: Handle QoS
|
// TODO: Handle QoS
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ static inline void parse_packet(MQTTHandle *handle, MQTTPacket *packet) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _reader(MQTTHandle *handle) {
|
static void *_reader(MQTTHandle *handle) {
|
||||||
Buffer *buffer = buffer_allocate(max_receive_buffer_size);
|
Buffer *buffer = buffer_allocate(max_receive_buffer_size);
|
||||||
|
|
||||||
handle->reader_alive = true;
|
handle->reader_alive = true;
|
||||||
|
@ -64,7 +64,7 @@ static void _reader(MQTTHandle *handle) {
|
||||||
PlatformStatusCode ret = platform_read(handle, buffer);
|
PlatformStatusCode ret = platform_read(handle, buffer);
|
||||||
if (ret == PlatformStatusError) {
|
if (ret == PlatformStatusError) {
|
||||||
handle->reader_alive = false;
|
handle->reader_alive = false;
|
||||||
return;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
|
@ -85,7 +85,7 @@ static void _reader(MQTTHandle *handle) {
|
||||||
platform_disconnect(handle);
|
platform_disconnect(handle);
|
||||||
handle->reader_alive = false;
|
handle->reader_alive = false;
|
||||||
buffer_release(buffer);
|
buffer_release(buffer);
|
||||||
return;
|
return NULL;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
hexdump(buffer->data, num_bytes, 2);
|
hexdump(buffer->data, num_bytes, 2);
|
||||||
|
@ -147,7 +147,7 @@ MQTTHandle *mqtt_connect(MQTTConfig *config, MQTTEventHandler callback, void *co
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
MQTTHandle *handle = calloc(sizeof(struct _MQTTHandle), 1);
|
MQTTHandle *handle = (MQTTHandle *)calloc(sizeof(struct _MQTTHandle), 1);
|
||||||
PlatformStatusCode ret = platform_init(handle);
|
PlatformStatusCode ret = platform_init(handle);
|
||||||
if (ret == PlatformStatusError) {
|
if (ret == PlatformStatusError) {
|
||||||
free(handle);
|
free(handle);
|
||||||
|
|
|
@ -13,11 +13,14 @@
|
||||||
|
|
||||||
#define LIBMQTT_VERSION_MAJOR @LIBMQTT_VERSION_MAJOR@
|
#define LIBMQTT_VERSION_MAJOR @LIBMQTT_VERSION_MAJOR@
|
||||||
#define LIBMQTT_VERSION_MINOR @LIBMQTT_VERSION_MINOR@
|
#define LIBMQTT_VERSION_MINOR @LIBMQTT_VERSION_MINOR@
|
||||||
#define LIBMQTT_BUILD_DATE @LIBMQTT_BUILD_DATE@
|
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
#ifndef _unused
|
||||||
|
#define _unused __attribute__((unused))
|
||||||
|
#endif
|
||||||
|
|
||||||
typedef struct _MQTTHandle MQTTHandle;
|
typedef struct _MQTTHandle MQTTHandle;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|
40
src/packet.c
40
src/packet.c
|
@ -7,7 +7,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
MQTTPacket *allocate_MQTTPacket(MQTTControlPacketType type) {
|
MQTTPacket *allocate_MQTTPacket(MQTTControlPacketType type) {
|
||||||
MQTTPacket *packet = calloc(1, sizeof(MQTTPacket));
|
MQTTPacket *packet = (MQTTPacket *)calloc(1, sizeof(MQTTPacket));
|
||||||
packet->packet_type = type;
|
packet->packet_type = type;
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
|
@ -75,12 +75,12 @@ char *utf8_string_decode(Buffer *buffer) {
|
||||||
return NULL; // buffer too small
|
return NULL; // buffer too small
|
||||||
}
|
}
|
||||||
uint16_t sz = (buffer->data[buffer->position] << 8) + buffer->data[buffer->position + 1];
|
uint16_t sz = (buffer->data[buffer->position] << 8) + buffer->data[buffer->position + 1];
|
||||||
if (buffer_free_space(buffer) < sz + 2) {
|
if (buffer_free_space(buffer) < (size_t)(sz + 2)) {
|
||||||
return NULL; // incomplete buffer
|
return NULL; // incomplete buffer
|
||||||
}
|
}
|
||||||
buffer->position += 2;
|
buffer->position += 2;
|
||||||
|
|
||||||
result = malloc(sz + 1);
|
result = (char *)malloc(sz + 1);
|
||||||
buffer_copy_out(buffer, result, sz);
|
buffer_copy_out(buffer, result, sz);
|
||||||
result[sz] = '\0';
|
result[sz] = '\0';
|
||||||
return result;
|
return result;
|
||||||
|
@ -152,11 +152,11 @@ size_t utf8_string_encode(char *string, Buffer *buffer) {
|
||||||
#if MQTT_SERVER
|
#if MQTT_SERVER
|
||||||
bool decode_connect(Buffer *buffer, ConnectPayload *payload) {
|
bool decode_connect(Buffer *buffer, ConnectPayload *payload) {
|
||||||
// Validate this is actually a connect packet
|
// Validate this is actually a connect packet
|
||||||
char template[] = { 0x00, 0x04, 'M', 'Q', 'T', 'T' };
|
char check[] = { 0x00, 0x04, 'M', 'Q', 'T', 'T' };
|
||||||
if (memcmp(buffer->data + buffer->position, template, sizeof(template)) != 0) {
|
if (memcmp(buffer->data + buffer->position, check, sizeof(check)) != 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
buffer->position += sizeof(template);
|
buffer->position += sizeof(check);
|
||||||
|
|
||||||
payload->protocol_level = buffer->data[buffer->position++];
|
payload->protocol_level = buffer->data[buffer->position++];
|
||||||
uint8_t flags = buffer->data[buffer->position++];
|
uint8_t flags = buffer->data[buffer->position++];
|
||||||
|
@ -172,7 +172,7 @@ bool decode_connect(Buffer *buffer, ConnectPayload *payload) {
|
||||||
payload->will_topic = utf8_string_decode(buffer);
|
payload->will_topic = utf8_string_decode(buffer);
|
||||||
payload->will_message = utf8_string_decode(buffer);
|
payload->will_message = utf8_string_decode(buffer);
|
||||||
}
|
}
|
||||||
payload->will_qos = (flags & 0x18) >> 3;
|
payload->will_qos = (MQTTQosLevel)((flags & 0x18) >> 3);
|
||||||
payload->retain_will = (flags & 0x20) > 0;
|
payload->retain_will = (flags & 0x20) > 0;
|
||||||
|
|
||||||
// username
|
// username
|
||||||
|
@ -191,7 +191,7 @@ bool decode_connect(Buffer *buffer, ConnectPayload *payload) {
|
||||||
|
|
||||||
bool decode_connack(Buffer *buffer, ConnAckPayload *payload) {
|
bool decode_connack(Buffer *buffer, ConnAckPayload *payload) {
|
||||||
payload->session_present = buffer->data[buffer->position++] & 0x01;
|
payload->session_present = buffer->data[buffer->position++] & 0x01;
|
||||||
payload->status = buffer->data[buffer->position++];
|
payload->status = (ConnAckStatus)buffer->data[buffer->position++];
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -200,7 +200,7 @@ bool decode_publish(Buffer *buffer, PublishPayload *payload, size_t sz) {
|
||||||
uint8_t flags = buffer->data[buffer->position - 2] & 0x0f;
|
uint8_t flags = buffer->data[buffer->position - 2] & 0x0f;
|
||||||
uint16_t start_pos = buffer->position;
|
uint16_t start_pos = buffer->position;
|
||||||
|
|
||||||
payload->qos = (flags & 0x06) >> 1;
|
payload->qos = (MQTTQosLevel)((flags & 0x06) >> 1);
|
||||||
payload->retain = ((flags & 0x01) > 0);
|
payload->retain = ((flags & 0x01) > 0);
|
||||||
payload->duplicate = ((flags & 0x08) > 0);
|
payload->duplicate = ((flags & 0x08) > 0);
|
||||||
|
|
||||||
|
@ -214,7 +214,7 @@ bool decode_publish(Buffer *buffer, PublishPayload *payload, size_t sz) {
|
||||||
|
|
||||||
size_t len = sz - (buffer->position - start_pos) + 1;
|
size_t len = sz - (buffer->position - start_pos) + 1;
|
||||||
if (len > 1) {
|
if (len > 1) {
|
||||||
payload->message = calloc(1, len);
|
payload->message = (char *)calloc(1, len);
|
||||||
memcpy(payload->message, buffer->data + buffer->position, len - 1);
|
memcpy(payload->message, buffer->data + buffer->position, len - 1);
|
||||||
buffer->position += len - 1;
|
buffer->position += len - 1;
|
||||||
}
|
}
|
||||||
|
@ -238,7 +238,7 @@ bool decode_subscribe(Buffer *buffer, SubscribePayload *payload) {
|
||||||
buffer->position += 2;
|
buffer->position += 2;
|
||||||
|
|
||||||
payload->topic = utf8_string_decode(buffer);
|
payload->topic = utf8_string_decode(buffer);
|
||||||
payload->qos = buffer->data[buffer->position++] & 0x03;
|
payload->qos = (MQTTQosLevel)(buffer->data[buffer->position++] & 0x03);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -250,7 +250,7 @@ bool decode_suback(Buffer *buffer, SubAckPayload *payload) {
|
||||||
+ buffer->data[buffer->position + 1];
|
+ buffer->data[buffer->position + 1];
|
||||||
buffer->position += 2;
|
buffer->position += 2;
|
||||||
|
|
||||||
payload->status = buffer->data[buffer->position++];
|
payload->status = (SubAckStatus)(buffer->data[buffer->position++]);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -271,7 +271,7 @@ bool decode_unsubscribe(Buffer *buffer, UnsubscribePayload *payload) {
|
||||||
|
|
||||||
MQTTPacket *mqtt_packet_decode(Buffer *buffer) {
|
MQTTPacket *mqtt_packet_decode(Buffer *buffer) {
|
||||||
// validate that the buffer is big enough
|
// validate that the buffer is big enough
|
||||||
MQTTControlPacketType type = (buffer->data[buffer->position] & 0xf0) >> 4;
|
MQTTControlPacketType type = (MQTTControlPacketType)((buffer->data[buffer->position] & 0xf0) >> 4);
|
||||||
buffer->position++;
|
buffer->position++;
|
||||||
size_t packet_size = variable_length_int_decode(buffer);
|
size_t packet_size = variable_length_int_decode(buffer);
|
||||||
|
|
||||||
|
@ -283,20 +283,20 @@ MQTTPacket *mqtt_packet_decode(Buffer *buffer) {
|
||||||
bool valid = false;
|
bool valid = false;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case PacketTypeConnAck:
|
case PacketTypeConnAck:
|
||||||
valid = decode_connack(buffer, result->payload);
|
valid = decode_connack(buffer, (ConnAckPayload *)result->payload);
|
||||||
break;
|
break;
|
||||||
case PacketTypePublish:
|
case PacketTypePublish:
|
||||||
valid = decode_publish(buffer, result->payload, packet_size);
|
valid = decode_publish(buffer, (PublishPayload *)result->payload, packet_size);
|
||||||
break;
|
break;
|
||||||
case PacketTypeSubAck:
|
case PacketTypeSubAck:
|
||||||
valid = decode_suback(buffer, result->payload);
|
valid = decode_suback(buffer, (SubAckPayload *)result->payload);
|
||||||
break;
|
break;
|
||||||
case PacketTypePubAck:
|
case PacketTypePubAck:
|
||||||
case PacketTypePubRec:
|
case PacketTypePubRec:
|
||||||
case PacketTypePubRel:
|
case PacketTypePubRel:
|
||||||
case PacketTypePubComp:
|
case PacketTypePubComp:
|
||||||
case PacketTypeUnsubAck:
|
case PacketTypeUnsubAck:
|
||||||
valid = decode_packet_id(buffer, result->payload);
|
valid = decode_packet_id(buffer, (PacketIDPayload *)result->payload);
|
||||||
break;
|
break;
|
||||||
case PacketTypePingResp:
|
case PacketTypePingResp:
|
||||||
case PacketTypeDisconnect:
|
case PacketTypeDisconnect:
|
||||||
|
@ -308,13 +308,13 @@ MQTTPacket *mqtt_packet_decode(Buffer *buffer) {
|
||||||
valid = true; // there is no payload
|
valid = true; // there is no payload
|
||||||
break;
|
break;
|
||||||
case PacketTypeConnect:
|
case PacketTypeConnect:
|
||||||
valid = decode_connect(buffer, result->payload);
|
valid = decode_connect(buffer, (ConnectPayload *)result->payload);
|
||||||
break;
|
break;
|
||||||
case PacketTypeSubscribe:
|
case PacketTypeSubscribe:
|
||||||
valid = decode_subscribe(buffer, result->payload);
|
valid = decode_subscribe(buffer, (SubscribePayload *)result->payload);
|
||||||
break;
|
break;
|
||||||
case PacketTypeUnsubscribe:
|
case PacketTypeUnsubscribe:
|
||||||
valid = decode_unsubscribe(buffer, result->payload);
|
valid = decode_unsubscribe(buffer, (UnsubscribePayload *)result->payload);
|
||||||
break;
|
break;
|
||||||
#endif /* MQTT_SERVER */
|
#endif /* MQTT_SERVER */
|
||||||
|
|
||||||
|
|
|
@ -58,7 +58,7 @@ void handle_pubrec(MQTTHandle *handle, void *context) {
|
||||||
|
|
||||||
#if MQTT_CLIENT
|
#if MQTT_CLIENT
|
||||||
bool send_connect_packet(MQTTHandle *handle) {
|
bool send_connect_packet(MQTTHandle *handle) {
|
||||||
ConnectPayload *payload = calloc(1, sizeof(ConnectPayload));
|
ConnectPayload *payload = (ConnectPayload *)calloc(1, sizeof(ConnectPayload));
|
||||||
|
|
||||||
payload->client_id = handle->config->client_id;
|
payload->client_id = handle->config->client_id;
|
||||||
payload->protocol_level = 4;
|
payload->protocol_level = 4;
|
||||||
|
@ -94,7 +94,7 @@ void remove_pending(MQTTHandle *handle, void *context) {
|
||||||
|
|
||||||
#if MQTT_CLIENT
|
#if MQTT_CLIENT
|
||||||
bool send_subscribe_packet(MQTTHandle *handle, char *topic, MQTTQosLevel qos) {
|
bool send_subscribe_packet(MQTTHandle *handle, char *topic, MQTTQosLevel qos) {
|
||||||
SubscribePayload *payload = calloc(1, sizeof(SubscribePayload));
|
SubscribePayload *payload = (SubscribePayload *)calloc(1, sizeof(SubscribePayload));
|
||||||
|
|
||||||
payload->packet_id = (++handle->packet_id_counter > 0) ? handle->packet_id_counter : ++handle->packet_id_counter;
|
payload->packet_id = (++handle->packet_id_counter > 0) ? handle->packet_id_counter : ++handle->packet_id_counter;
|
||||||
payload->topic = strdup(topic);
|
payload->topic = strdup(topic);
|
||||||
|
@ -112,7 +112,7 @@ bool send_subscribe_packet(MQTTHandle *handle, char *topic, MQTTQosLevel qos) {
|
||||||
|
|
||||||
#if MQTT_CLIENT
|
#if MQTT_CLIENT
|
||||||
bool send_unsubscribe_packet(MQTTHandle *handle, char *topic) {
|
bool send_unsubscribe_packet(MQTTHandle *handle, char *topic) {
|
||||||
UnsubscribePayload *payload = calloc(1, sizeof(UnsubscribePayload));
|
UnsubscribePayload *payload = (UnsubscribePayload *)calloc(1, sizeof(UnsubscribePayload));
|
||||||
|
|
||||||
payload->packet_id = (++handle->packet_id_counter > 0) ? handle->packet_id_counter : ++handle->packet_id_counter;
|
payload->packet_id = (++handle->packet_id_counter > 0) ? handle->packet_id_counter : ++handle->packet_id_counter;
|
||||||
payload->topic = topic;
|
payload->topic = topic;
|
||||||
|
@ -129,7 +129,7 @@ bool send_unsubscribe_packet(MQTTHandle *handle, char *topic) {
|
||||||
#endif /* MQTT_CLIENT */
|
#endif /* MQTT_CLIENT */
|
||||||
|
|
||||||
bool send_publish_packet(MQTTHandle *handle, char *topic, char *message, MQTTQosLevel qos, MQTTPublishEventHandler callback) {
|
bool send_publish_packet(MQTTHandle *handle, char *topic, char *message, MQTTQosLevel qos, MQTTPublishEventHandler callback) {
|
||||||
PublishPayload *payload = calloc(1, sizeof(PublishPayload));
|
PublishPayload *payload = (PublishPayload *)calloc(1, sizeof(PublishPayload));
|
||||||
|
|
||||||
payload->qos = qos;
|
payload->qos = qos;
|
||||||
payload->retain = true;
|
payload->retain = true;
|
||||||
|
@ -155,14 +155,14 @@ bool send_publish_packet(MQTTHandle *handle, char *topic, char *message, MQTTQos
|
||||||
free(payload);
|
free(payload);
|
||||||
break;
|
break;
|
||||||
case MQTT_QOS_1: {
|
case MQTT_QOS_1: {
|
||||||
PublishCallback *ctx = malloc(sizeof(PublishCallback));
|
PublishCallback *ctx = (PublishCallback *)malloc(sizeof(PublishCallback));
|
||||||
ctx->payload = payload;
|
ctx->payload = payload;
|
||||||
ctx->callback = callback;
|
ctx->callback = callback;
|
||||||
expect_packet(handle, PacketTypePubAck, payload->packet_id, handle_puback_pubcomp, ctx);
|
expect_packet(handle, PacketTypePubAck, payload->packet_id, handle_puback_pubcomp, ctx);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case MQTT_QOS_2: {
|
case MQTT_QOS_2: {
|
||||||
PublishCallback *ctx = malloc(sizeof(PublishCallback));
|
PublishCallback *ctx = (PublishCallback *)malloc(sizeof(PublishCallback));
|
||||||
ctx->payload = payload;
|
ctx->payload = payload;
|
||||||
ctx->callback = callback;
|
ctx->callback = callback;
|
||||||
expect_packet(handle, PacketTypePubRec, payload->packet_id, handle_pubrec, ctx);
|
expect_packet(handle, PacketTypePubRec, payload->packet_id, handle_pubrec, ctx);
|
||||||
|
|
|
@ -17,7 +17,7 @@ static inline void dump_expected(MQTTHandle *handle) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void expect_packet(MQTTHandle *handle, MQTTControlPacketType type, uint16_t packet_id, MQTTEventHandler callback, void *context) {
|
void expect_packet(MQTTHandle *handle, MQTTControlPacketType type, uint16_t packet_id, MQTTEventHandler callback, void *context) {
|
||||||
MQTTCallbackQueueItem *item = calloc(1, sizeof(MQTTCallbackQueueItem));
|
MQTTCallbackQueueItem *item = (MQTTCallbackQueueItem *)calloc(1, sizeof(MQTTCallbackQueueItem));
|
||||||
|
|
||||||
item->type = type;
|
item->type = type;
|
||||||
item->packet_id = packet_id;
|
item->packet_id = packet_id;
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
#include "subscriptions.h"
|
#include "subscriptions.h"
|
||||||
|
|
||||||
void add_subscription(MQTTHandle *handle, char *topic, MQTTQosLevel qos, MQTTPublishEventHandler callback) {
|
void add_subscription(MQTTHandle *handle, char *topic, MQTTQosLevel qos, MQTTPublishEventHandler callback) {
|
||||||
SubscriptionItem *item = calloc(1, sizeof(SubscriptionItem));
|
SubscriptionItem *item = (SubscriptionItem *)calloc(1, sizeof(SubscriptionItem));
|
||||||
|
|
||||||
item->topic = topic;
|
item->topic = topic;
|
||||||
item->qos = qos;
|
item->qos = qos;
|
||||||
|
|
|
@ -8,20 +8,20 @@ int leave = 0;
|
||||||
|
|
||||||
#define LOG(fmt, ...) fprintf(stdout, fmt "\n", ## __VA_ARGS__)
|
#define LOG(fmt, ...) fprintf(stdout, fmt "\n", ## __VA_ARGS__)
|
||||||
|
|
||||||
bool err_handler(MQTTHandle *handle, MQTTConfig *config, MQTTErrorCode error) {
|
bool err_handler(_unused MQTTHandle *handle, _unused MQTTConfig *config, MQTTErrorCode error) {
|
||||||
LOG("Error received: %d", error);
|
LOG("Error received: %d", error);
|
||||||
exit(1);
|
exit(1);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void publish_handler(MQTTHandle *handle, char *topic, char *message) {
|
void publish_handler(_unused MQTTHandle *handle, char *topic, char *message) {
|
||||||
LOG("Published %s -> %s", topic, message);
|
LOG("Published %s -> %s", topic, message);
|
||||||
|
|
||||||
leave++;
|
leave++;
|
||||||
}
|
}
|
||||||
|
|
||||||
void mqtt_connected(MQTTHandle *handle, void *context) {
|
void mqtt_connected(MQTTHandle *handle, _unused void *context) {
|
||||||
LOG("Connected!");
|
LOG("Connected!");
|
||||||
MQTTStatus result;
|
MQTTStatus result;
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ void mqtt_connected(MQTTHandle *handle, void *context) {
|
||||||
leave = true;
|
leave = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(_unused int argc, _unused char **argv) {
|
||||||
MQTTConfig config = { 0 };
|
MQTTConfig config = { 0 };
|
||||||
|
|
||||||
config.client_id = "libmqtt_testsuite_this_is_too_long";
|
config.client_id = "libmqtt_testsuite_this_is_too_long";
|
||||||
|
|
|
@ -8,7 +8,7 @@ bool leave = false;
|
||||||
|
|
||||||
#define LOG(fmt, ...) fprintf(stdout, fmt "\n", ## __VA_ARGS__)
|
#define LOG(fmt, ...) fprintf(stdout, fmt "\n", ## __VA_ARGS__)
|
||||||
|
|
||||||
bool err_handler(MQTTHandle *handle, MQTTConfig *config, MQTTErrorCode error) {
|
bool err_handler(_unused MQTTHandle *handle, _unused MQTTConfig *config, MQTTErrorCode error) {
|
||||||
LOG("Error received: %d", error);
|
LOG("Error received: %d", error);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -33,7 +33,7 @@ void callback(MQTTHandle *handle, char *topic, char *payload) {
|
||||||
leave = true;
|
leave = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void mqtt_connected(MQTTHandle *handle, void *context) {
|
void mqtt_connected(MQTTHandle *handle, _unused void *context) {
|
||||||
LOG("Connected!");
|
LOG("Connected!");
|
||||||
|
|
||||||
LOG("Trying subscribe on testsuite/mqtt/test...");
|
LOG("Trying subscribe on testsuite/mqtt/test...");
|
||||||
|
@ -50,7 +50,7 @@ void mqtt_connected(MQTTHandle *handle, void *context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(_unused int argc, _unused char **argv) {
|
||||||
MQTTConfig config = { 0 };
|
MQTTConfig config = { 0 };
|
||||||
|
|
||||||
config.client_id = "libmqtt_testsuite";
|
config.client_id = "libmqtt_testsuite";
|
||||||
|
|
28
tests/test.h
28
tests/test.h
|
@ -19,7 +19,7 @@ typedef struct {
|
||||||
TestStatus status;
|
TestStatus status;
|
||||||
char *message;
|
char *message;
|
||||||
Buffer *buffer;
|
Buffer *buffer;
|
||||||
Buffer *template;
|
Buffer *valid;
|
||||||
} TestResult;
|
} TestResult;
|
||||||
|
|
||||||
typedef TestResult (*TestPointer)(void);
|
typedef TestResult (*TestPointer)(void);
|
||||||
|
@ -43,18 +43,18 @@ extern DefinedTest defined_tests[];
|
||||||
|
|
||||||
#define TEST_OK() return (TestResult){ TestStatusOk, NULL, NULL, NULL }
|
#define TEST_OK() return (TestResult){ TestStatusOk, NULL, NULL, NULL }
|
||||||
#define TESTRESULT(_status, _message) return (TestResult){ _status, _message, NULL, NULL }
|
#define TESTRESULT(_status, _message) return (TestResult){ _status, _message, NULL, NULL }
|
||||||
#define TESTRESULT_BUFFER(_status, _message, _buffer, _template) return (TestResult){ _status, _message, _buffer, _template }
|
#define TESTRESULT_BUFFER(_status, _message, _buffer, _valid) return (TestResult){ _status, _message, _buffer, _valid }
|
||||||
#define TESTASSERT(_assertion, _message) if (!(_assertion)) { return (TestResult){ TestStatusFailure, _message, NULL, NULL }; }
|
#define TESTASSERT(_assertion, _message) if (!(_assertion)) { return (TestResult){ TestStatusFailure, _message, NULL, NULL }; }
|
||||||
|
|
||||||
|
|
||||||
static inline TestResult TESTMEMCMP(Buffer *template, Buffer *check) {
|
static inline TestResult TESTMEMCMP(Buffer *valid, Buffer *check) {
|
||||||
if (template->len != check->len) {
|
if (valid->len != check->len) {
|
||||||
TESTRESULT_BUFFER(TestStatusFailureHexdump, "Buffer size differs from template", check, template);
|
TESTRESULT_BUFFER(TestStatusFailureHexdump, "Buffer size differs from valid", check, valid);
|
||||||
}
|
}
|
||||||
if (memcmp(template->data, check->data, template->len) == 0) {
|
if (memcmp(valid->data, check->data, valid->len) == 0) {
|
||||||
TESTRESULT(TestStatusOk, "Buffer matches template");
|
TESTRESULT(TestStatusOk, "Buffer matches valid");
|
||||||
} else {
|
} else {
|
||||||
TESTRESULT_BUFFER(TestStatusFailureHexdump, "Buffer and template differ", check, template);
|
TESTRESULT_BUFFER(TestStatusFailureHexdump, "Buffer and valid differ", check, valid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,7 +66,11 @@ static TestResult not_implemented(void) {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
#ifndef _unused
|
||||||
|
#define _unused __attribute__((unused))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int main(_unused int argc, _unused char **argv) {
|
||||||
uint16_t successes = 0;
|
uint16_t successes = 0;
|
||||||
uint16_t skips = 0;
|
uint16_t skips = 0;
|
||||||
uint16_t failures = 0;
|
uint16_t failures = 0;
|
||||||
|
@ -101,9 +105,9 @@ int main(int argc, char **argv) {
|
||||||
if (result.message) {
|
if (result.message) {
|
||||||
fprintf(stderr, " -> %s\n", result.message);
|
fprintf(stderr, " -> %s\n", result.message);
|
||||||
}
|
}
|
||||||
if (result.template) {
|
if (result.valid) {
|
||||||
fprintf(stderr, " -> Template (%zu bytes)\n", result.template->len);
|
fprintf(stderr, " -> Template (%zu bytes)\n", result.valid->len);
|
||||||
buffer_hexdump(result.template, 5);
|
buffer_hexdump(result.valid, 5);
|
||||||
}
|
}
|
||||||
if (result.buffer) {
|
if (result.buffer) {
|
||||||
fprintf(stderr, " -> Buffer (%zu bytes)\n", result.buffer->len);
|
fprintf(stderr, " -> Buffer (%zu bytes)\n", result.buffer->len);
|
||||||
|
|
Loading…
Reference in a new issue