|
|
@@ -152,7 +152,11 @@ int luat_mqtt_set_connopts(luat_mqtt_ctrl_t *mqtt_ctrl, luat_mqtt_connopts_t *op
|
|
|
static const char proto_hdr[] = "Sec-WebSocket-Protocol: mqtt\r\n";
|
|
|
char *hdr = (char*)luat_heap_malloc(sizeof(proto_hdr));
|
|
|
if (hdr) {
|
|
|
+ LLOGD("WebSocket header allocation successful, size: %d", sizeof(proto_hdr));
|
|
|
memcpy(hdr, proto_hdr, sizeof(proto_hdr));
|
|
|
+ } else {
|
|
|
+ LLOGW("WebSocket header allocation failed, size: %d", sizeof(proto_hdr));
|
|
|
+ return -1;
|
|
|
}
|
|
|
luat_websocket_set_headers(&mqtt_ctrl->ws_ctrl, hdr);
|
|
|
/* 绑定回调,切换发送函数 */
|
|
|
@@ -392,11 +396,11 @@ static int luat_mqtt_msg_cb(luat_mqtt_ctrl_t *mqtt_ctrl) {
|
|
|
uint16_t topic_len = mqtt_parse_pub_topic_ptr(mqtt_ctrl->mqtt_packet_buffer, &ptr);
|
|
|
uint32_t payload_len = mqtt_parse_pub_msg_ptr(mqtt_ctrl->mqtt_packet_buffer, &ptr);
|
|
|
luat_mqtt_msg_t *mqtt_msg = (luat_mqtt_msg_t *)luat_heap_malloc(sizeof(luat_mqtt_msg_t)+topic_len+payload_len);
|
|
|
- mqtt_msg->topic_len = mqtt_parse_pub_topic(mqtt_ctrl->mqtt_packet_buffer, mqtt_msg->data);
|
|
|
- mqtt_msg->payload_len = mqtt_parse_publish_msg(mqtt_ctrl->mqtt_packet_buffer, mqtt_msg->data+topic_len);
|
|
|
- mqtt_msg->message_id = mqtt_parse_msg_id(mqtt_ctrl->mqtt_packet_buffer);
|
|
|
- mqtt_msg->flags = mqtt_ctrl->mqtt_packet_buffer[0];
|
|
|
- l_luat_mqtt_msg_cb(mqtt_ctrl, MQTT_MSG_PUBLISH, (int)mqtt_msg);
|
|
|
+ mqtt_msg->topic_len = mqtt_parse_pub_topic(mqtt_ctrl->mqtt_packet_buffer, mqtt_msg->data);
|
|
|
+ mqtt_msg->payload_len = mqtt_parse_publish_msg(mqtt_ctrl->mqtt_packet_buffer, mqtt_msg->data+topic_len);
|
|
|
+ mqtt_msg->message_id = mqtt_parse_msg_id(mqtt_ctrl->mqtt_packet_buffer);
|
|
|
+ mqtt_msg->flags = mqtt_ctrl->mqtt_packet_buffer[0];
|
|
|
+ l_luat_mqtt_msg_cb(mqtt_ctrl, MQTT_MSG_PUBLISH, (int)mqtt_msg);
|
|
|
#else
|
|
|
l_luat_mqtt_msg_cb(mqtt_ctrl, MQTT_MSG_PUBLISH, 0);
|
|
|
#endif
|