MeterLogger
Data Structures | Typedefs | Enumerations | Functions
mqtt_msg.h File Reference
#include "user_config.h"
#include "c_types.h"
Include dependency graph for mqtt_msg.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  mqtt_message
 
struct  mqtt_connection
 
struct  mqtt_connect_info
 

Typedefs

typedef struct mqtt_message mqtt_message_t
 
typedef struct mqtt_connection mqtt_connection_t
 
typedef struct mqtt_connect_info mqtt_connect_info_t
 

Enumerations

enum  mqtt_message_type {
  MQTT_MSG_TYPE_CONNECT = 1, MQTT_MSG_TYPE_CONNACK = 2, MQTT_MSG_TYPE_PUBLISH = 3, MQTT_MSG_TYPE_PUBACK = 4,
  MQTT_MSG_TYPE_PUBREC = 5, MQTT_MSG_TYPE_PUBREL = 6, MQTT_MSG_TYPE_PUBCOMP = 7, MQTT_MSG_TYPE_SUBSCRIBE = 8,
  MQTT_MSG_TYPE_SUBACK = 9, MQTT_MSG_TYPE_UNSUBSCRIBE = 10, MQTT_MSG_TYPE_UNSUBACK = 11, MQTT_MSG_TYPE_PINGREQ = 12,
  MQTT_MSG_TYPE_PINGRESP = 13, MQTT_MSG_TYPE_DISCONNECT = 14
}
 
enum  mqtt_connect_return_code {
  CONNECTION_ACCEPTED = 0, CONNECTION_REFUSE_PROTOCOL, CONNECTION_REFUSE_ID_REJECTED, CONNECTION_REFUSE_SERVER_UNAVAILABLE,
  CONNECTION_REFUSE_BAD_USERNAME, CONNECTION_REFUSE_NOT_AUTHORIZED
}
 

Functions

static int ICACHE_FLASH_ATTR mqtt_get_type (uint8_t *buffer)
 
static int ICACHE_FLASH_ATTR mqtt_get_connect_return_code (uint8_t *buffer)
 
static int ICACHE_FLASH_ATTR mqtt_get_dup (uint8_t *buffer)
 
static int ICACHE_FLASH_ATTR mqtt_get_qos (uint8_t *buffer)
 
static int ICACHE_FLASH_ATTR mqtt_get_retain (uint8_t *buffer)
 
void ICACHE_FLASH_ATTR mqtt_msg_init (mqtt_connection_t *connection, uint8_t *buffer, uint16_t buffer_length)
 
int ICACHE_FLASH_ATTR mqtt_get_total_length (uint8_t *buffer, uint16_t length)
 
const char *ICACHE_FLASH_ATTR mqtt_get_publish_topic (uint8_t *buffer, uint16_t *length)
 
const char *ICACHE_FLASH_ATTR mqtt_get_publish_data (uint8_t *buffer, uint16_t *length)
 
uint16_t ICACHE_FLASH_ATTR mqtt_get_id (uint8_t *buffer, uint16_t length)
 
mqtt_message_t *ICACHE_FLASH_ATTR mqtt_msg_connect (mqtt_connection_t *connection, mqtt_connect_info_t *info)
 
mqtt_message_t *ICACHE_FLASH_ATTR mqtt_msg_publish (mqtt_connection_t *connection, const char *topic, const char *data, int data_length, int qos, int retain, uint16_t *message_id)
 
mqtt_message_t *ICACHE_FLASH_ATTR mqtt_msg_puback (mqtt_connection_t *connection, uint16_t message_id)
 
mqtt_message_t *ICACHE_FLASH_ATTR mqtt_msg_pubrec (mqtt_connection_t *connection, uint16_t message_id)
 
mqtt_message_t *ICACHE_FLASH_ATTR mqtt_msg_pubrel (mqtt_connection_t *connection, uint16_t message_id)
 
mqtt_message_t *ICACHE_FLASH_ATTR mqtt_msg_pubcomp (mqtt_connection_t *connection, uint16_t message_id)
 
mqtt_message_t *ICACHE_FLASH_ATTR mqtt_msg_subscribe (mqtt_connection_t *connection, const char *topic, int qos, uint16_t *message_id)
 
mqtt_message_t *ICACHE_FLASH_ATTR mqtt_msg_unsubscribe (mqtt_connection_t *connection, const char *topic, uint16_t *message_id)
 
mqtt_message_t *ICACHE_FLASH_ATTR mqtt_msg_pingreq (mqtt_connection_t *connection)
 
mqtt_message_t *ICACHE_FLASH_ATTR mqtt_msg_pingresp (mqtt_connection_t *connection)
 
mqtt_message_t *ICACHE_FLASH_ATTR mqtt_msg_disconnect (mqtt_connection_t *connection)
 

Typedef Documentation

◆ mqtt_connect_info_t

◆ mqtt_connection_t

◆ mqtt_message_t

typedef struct mqtt_message mqtt_message_t

Enumeration Type Documentation

◆ mqtt_connect_return_code

Enumerator
CONNECTION_ACCEPTED 
CONNECTION_REFUSE_PROTOCOL 
CONNECTION_REFUSE_ID_REJECTED 
CONNECTION_REFUSE_SERVER_UNAVAILABLE 
CONNECTION_REFUSE_BAD_USERNAME 
CONNECTION_REFUSE_NOT_AUTHORIZED 

Definition at line 69 of file mqtt_msg.h.

◆ mqtt_message_type

Enumerator
MQTT_MSG_TYPE_CONNECT 
MQTT_MSG_TYPE_CONNACK 
MQTT_MSG_TYPE_PUBLISH 
MQTT_MSG_TYPE_PUBACK 
MQTT_MSG_TYPE_PUBREC 
MQTT_MSG_TYPE_PUBREL 
MQTT_MSG_TYPE_PUBCOMP 
MQTT_MSG_TYPE_SUBSCRIBE 
MQTT_MSG_TYPE_SUBACK 
MQTT_MSG_TYPE_UNSUBSCRIBE 
MQTT_MSG_TYPE_UNSUBACK 
MQTT_MSG_TYPE_PINGREQ 
MQTT_MSG_TYPE_PINGRESP 
MQTT_MSG_TYPE_DISCONNECT 

Definition at line 51 of file mqtt_msg.h.

Function Documentation

◆ mqtt_get_connect_return_code()

static int ICACHE_FLASH_ATTR mqtt_get_connect_return_code ( uint8_t *  buffer)
inlinestatic

Definition at line 112 of file mqtt_msg.h.

Referenced by mqtt_tcpclient_recv().

112 { return buffer[3]; }
Here is the caller graph for this function:

◆ mqtt_get_dup()

static int ICACHE_FLASH_ATTR mqtt_get_dup ( uint8_t *  buffer)
inlinestatic

Definition at line 113 of file mqtt_msg.h.

113 { return (buffer[0] & 0x08) >> 3; }

◆ mqtt_get_id()

uint16_t ICACHE_FLASH_ATTR mqtt_get_id ( uint8_t *  buffer,
uint16_t  length 
)

Definition at line 229 of file mqtt_msg.c.

References mqtt_get_qos(), mqtt_get_type(), MQTT_MSG_TYPE_PUBACK, MQTT_MSG_TYPE_PUBCOMP, MQTT_MSG_TYPE_PUBLISH, MQTT_MSG_TYPE_PUBREC, MQTT_MSG_TYPE_PUBREL, MQTT_MSG_TYPE_SUBACK, MQTT_MSG_TYPE_SUBSCRIBE, and MQTT_MSG_TYPE_UNSUBACK.

Referenced by mqtt_get_retain(), mqtt_send_keepalive(), MQTT_Task(), mqtt_tcpclient_connect_cb(), and mqtt_tcpclient_recv().

230 {
231  if (length < 1)
232  return 0;
233 
234  switch (mqtt_get_type(buffer))
235  {
237  {
238  int i;
239  int topiclen;
240 
241  for (i = 1; i < length; ++i)
242  {
243  if ((buffer[i] & 0x80) == 0)
244  {
245  ++i;
246  break;
247  }
248  }
249 
250  if (i + 2 >= length)
251  return 0;
252  topiclen = buffer[i++] << 8;
253  topiclen |= buffer[i++];
254 
255  if (i + topiclen >= length)
256  return 0;
257  i += topiclen;
258 
259  if (mqtt_get_qos(buffer) > 0)
260  {
261  if (i + 2 >= length)
262  return 0;
263  //i += 2;
264  } else {
265  return 0;
266  }
267 
268  return (buffer[i] << 8) | buffer[i + 1];
269  }
277  {
278  // This requires the remaining length to be encoded in 1 byte,
279  // which it should be.
280  if (length >= 4 && (buffer[1] & 0x80) == 0)
281  return (buffer[2] << 8) | buffer[3];
282  else
283  return 0;
284  }
285 
286  default:
287  return 0;
288  }
289 }
static int ICACHE_FLASH_ATTR mqtt_get_type(uint8_t *buffer)
Definition: mqtt_msg.h:111
static int ICACHE_FLASH_ATTR mqtt_get_qos(uint8_t *buffer)
Definition: mqtt_msg.h:114
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mqtt_get_publish_data()

const char* ICACHE_FLASH_ATTR mqtt_get_publish_data ( uint8_t *  buffer,
uint16_t *  length 
)

Definition at line 183 of file mqtt_msg.c.

References mqtt_get_qos(), and NULL.

Referenced by deliver_publish(), and mqtt_get_retain().

184 {
185  int i;
186  int totlen = 0;
187  int topiclen;
188  int blength = *length;
189  *length = 0;
190 
191  for (i = 1; i < blength; ++i)
192  {
193  totlen += (buffer[i] & 0x7f) << (7 * (i - 1));
194  if ((buffer[i] & 0x80) == 0)
195  {
196  ++i;
197  break;
198  }
199  }
200  totlen += i;
201 
202  if (i + 2 >= blength)
203  return NULL;
204  topiclen = buffer[i++] << 8;
205  topiclen |= buffer[i++];
206 
207  if (i + topiclen >= blength)
208  return NULL;
209 
210  i += topiclen;
211 
212  if (mqtt_get_qos(buffer) > 0)
213  {
214  if (i + 2 >= blength)
215  return NULL;
216  i += 2;
217  }
218 
219  if (totlen < i)
220  return NULL;
221 
222  if (totlen <= blength)
223  *length = totlen - i;
224  else
225  *length = blength - i;
226  return (const char*)(buffer + i);
227 }
#define NULL
Definition: def.h:47
static int ICACHE_FLASH_ATTR mqtt_get_qos(uint8_t *buffer)
Definition: mqtt_msg.h:114
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mqtt_get_publish_topic()

const char* ICACHE_FLASH_ATTR mqtt_get_publish_topic ( uint8_t *  buffer,
uint16_t *  length 
)

Definition at line 154 of file mqtt_msg.c.

References NULL.

Referenced by deliver_publish(), and mqtt_get_retain().

155 {
156  int i;
157  int totlen = 0;
158  int topiclen;
159 
160  for (i = 1; i < *length; ++i)
161  {
162  totlen += (buffer[i] & 0x7f) << (7 * (i - 1));
163  if ((buffer[i] & 0x80) == 0)
164  {
165  ++i;
166  break;
167  }
168  }
169  totlen += i;
170 
171  if (i + 2 >= *length)
172  return NULL;
173  topiclen = buffer[i++] << 8;
174  topiclen |= buffer[i++];
175 
176  if (i + topiclen > *length)
177  return NULL;
178 
179  *length = topiclen;
180  return (const char*)(buffer + i);
181 }
#define NULL
Definition: def.h:47
Here is the caller graph for this function:

◆ mqtt_get_qos()

static int ICACHE_FLASH_ATTR mqtt_get_qos ( uint8_t *  buffer)
inlinestatic

Definition at line 114 of file mqtt_msg.h.

Referenced by mqtt_get_id(), mqtt_get_publish_data(), and mqtt_tcpclient_recv().

114 { return (buffer[0] & 0x06) >> 1; }
Here is the caller graph for this function:

◆ mqtt_get_retain()

static int ICACHE_FLASH_ATTR mqtt_get_retain ( uint8_t *  buffer)
inlinestatic

Definition at line 115 of file mqtt_msg.h.

References mqtt_message::data, ICACHE_FLASH_ATTR, mqtt_message::length, mqtt_get_id(), mqtt_get_publish_data(), mqtt_get_publish_topic(), mqtt_get_total_length(), mqtt_msg_connect(), mqtt_msg_disconnect(), mqtt_msg_init(), mqtt_msg_pingreq(), mqtt_msg_pingresp(), mqtt_msg_puback(), mqtt_msg_pubcomp(), mqtt_msg_publish(), mqtt_msg_pubrec(), mqtt_msg_pubrel(), mqtt_msg_subscribe(), and mqtt_msg_unsubscribe().

115 { return (buffer[0] & 0x01); }
Here is the call graph for this function:

◆ mqtt_get_total_length()

int ICACHE_FLASH_ATTR mqtt_get_total_length ( uint8_t *  buffer,
uint16_t  length 
)

Definition at line 135 of file mqtt_msg.c.

Referenced by mqtt_get_retain(), and mqtt_tcpclient_recv().

136 {
137  int i;
138  int totlen = 0;
139 
140  for (i = 1; i < length; ++i)
141  {
142  totlen += (buffer[i] & 0x7f) << (7 * (i - 1));
143  if ((buffer[i] & 0x80) == 0)
144  {
145  ++i;
146  break;
147  }
148  }
149  totlen += i;
150 
151  return totlen;
152 }
Here is the caller graph for this function:

◆ mqtt_get_type()

static int ICACHE_FLASH_ATTR mqtt_get_type ( uint8_t *  buffer)
inlinestatic

Definition at line 111 of file mqtt_msg.h.

Referenced by mqtt_get_id(), mqtt_send_keepalive(), MQTT_Task(), mqtt_tcpclient_connect_cb(), and mqtt_tcpclient_recv().

111 { return (buffer[0] & 0xf0) >> 4; }
Here is the caller graph for this function:

◆ mqtt_msg_connect()

mqtt_message_t* ICACHE_FLASH_ATTR mqtt_msg_connect ( mqtt_connection_t connection,
mqtt_connect_info_t info 
)

Definition at line 291 of file mqtt_msg.c.

References append_string(), mqtt_connection::buffer, mqtt_connection::buffer_length, mqtt_connect_info::clean_session, mqtt_connect_info::client_id, fail_message(), fini_message(), init_message(), mqtt_connect_info::keepalive, mqtt_message::length, memcpy, mqtt_connection::message, MQTT_CONNECT_FLAG_CLEAN_SESSION, MQTT_CONNECT_FLAG_PASSWORD, MQTT_CONNECT_FLAG_USERNAME, MQTT_CONNECT_FLAG_WILL, MQTT_CONNECT_FLAG_WILL_RETAIN, MQTT_MSG_TYPE_CONNECT, NULL, mqtt_connect_info::password, strlen, mqtt_connect_info::username, mqtt_connect_info::will_message, mqtt_connect_info::will_qos, mqtt_connect_info::will_retain, and mqtt_connect_info::will_topic.

Referenced by mqtt_get_retain(), and mqtt_tcpclient_connect_cb().

292 {
293  struct mqtt_connect_variable_header* variable_header;
294 
295  init_message(connection);
296 
297  if (connection->message.length + sizeof(*variable_header) > connection->buffer_length)
298  return fail_message(connection);
299  variable_header = (void*)(connection->buffer + connection->message.length);
300  connection->message.length += sizeof(*variable_header);
301 
302  variable_header->lengthMsb = 0;
303 #if defined(PROTOCOL_NAMEv31)
304  variable_header->lengthLsb = 6;
305  memcpy(variable_header->magic, "MQIsdp", 6);
306  variable_header->version = 3;
307 #elif defined(PROTOCOL_NAMEv311)
308  variable_header->lengthLsb = 4;
309  memcpy(variable_header->magic, "MQTT", 4);
310  variable_header->version = 4;
311 #else
312 #error "Please define protocol name"
313 #endif
314 
315  variable_header->flags = 0;
316  variable_header->keepaliveMsb = info->keepalive >> 8;
317  variable_header->keepaliveLsb = info->keepalive & 0xff;
318 
319  if (info->clean_session)
320  variable_header->flags |= MQTT_CONNECT_FLAG_CLEAN_SESSION;
321 
322  if (info->client_id == NULL)
323  {
324  /* Never allowed */
325  return fail_message(connection);
326  }
327  else if (info->client_id[0] == '\0')
328  {
329 #ifdef PROTOCOL_NAMEv311
330  /* Allowed. Format 0 Length ID */
331  append_string(connection, info->client_id, 2) ;
332 #else
333  /* 0 Length not allowed */
334  return fail_message(connection);
335 #endif
336  }
337  else
338  {
339  /* No 0 data and at least 1 long. Good to go. */
340  if(append_string(connection, info->client_id, strlen(info->client_id)) < 0)
341  return fail_message(connection);
342  }
343 
344  if (info->will_topic != NULL && info->will_topic[0] != '\0')
345  {
346  if (append_string(connection, info->will_topic, strlen(info->will_topic)) < 0)
347  return fail_message(connection);
348 
349  if (append_string(connection, info->will_message, strlen(info->will_message)) < 0)
350  return fail_message(connection);
351 
352  variable_header->flags |= MQTT_CONNECT_FLAG_WILL;
353  if (info->will_retain)
354  variable_header->flags |= MQTT_CONNECT_FLAG_WILL_RETAIN;
355  variable_header->flags |= (info->will_qos & 3) << 3;
356  }
357 
358  if (info->username != NULL && info->username[0] != '\0')
359  {
360  if (append_string(connection, info->username, strlen(info->username)) < 0)
361  return fail_message(connection);
362 
363  variable_header->flags |= MQTT_CONNECT_FLAG_USERNAME;
364  }
365 
366  if (info->password != NULL && info->password[0] != '\0')
367  {
368  if (append_string(connection, info->password, strlen(info->password)) < 0)
369  return fail_message(connection);
370 
371  variable_header->flags |= MQTT_CONNECT_FLAG_PASSWORD;
372  }
373 
374  return fini_message(connection, MQTT_MSG_TYPE_CONNECT, 0, 0, 0);
375 }
static mqtt_message_t *ICACHE_FLASH_ATTR fini_message(mqtt_connection_t *connection, int type, int dup, int qos, int retain)
Definition: mqtt_msg.c:105
static mqtt_message_t *ICACHE_FLASH_ATTR fail_message(mqtt_connection_t *connection)
Definition: mqtt_msg.c:98
char * will_message
Definition: mqtt_msg.h:102
char * will_topic
Definition: mqtt_msg.h:101
#define NULL
Definition: def.h:47
char * username
Definition: mqtt_msg.h:99
mqtt_message_t message
Definition: mqtt_msg.h:88
static int ICACHE_FLASH_ATTR append_string(mqtt_connection_t *connection, const char *string, int len)
Definition: mqtt_msg.c:63
char * client_id
Definition: mqtt_msg.h:98
static int ICACHE_FLASH_ATTR init_message(mqtt_connection_t *connection)
Definition: mqtt_msg.c:92
uint16_t length
Definition: mqtt_msg.h:82
uint32_t keepalive
Definition: mqtt_msg.h:103
#define memcpy(x, a, b)
Definition: platform.h:22
uint8_t * buffer
Definition: mqtt_msg.h:91
#define strlen(a)
Definition: platform.h:25
uint16_t buffer_length
Definition: mqtt_msg.h:92
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mqtt_msg_disconnect()

mqtt_message_t* ICACHE_FLASH_ATTR mqtt_msg_disconnect ( mqtt_connection_t connection)

Definition at line 483 of file mqtt_msg.c.

References fini_message(), init_message(), and MQTT_MSG_TYPE_DISCONNECT.

Referenced by mqtt_get_retain().

484 {
485  init_message(connection);
486  return fini_message(connection, MQTT_MSG_TYPE_DISCONNECT, 0, 0, 0);
487 }
static mqtt_message_t *ICACHE_FLASH_ATTR fini_message(mqtt_connection_t *connection, int type, int dup, int qos, int retain)
Definition: mqtt_msg.c:105
static int ICACHE_FLASH_ATTR init_message(mqtt_connection_t *connection)
Definition: mqtt_msg.c:92
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mqtt_msg_init()

void ICACHE_FLASH_ATTR mqtt_msg_init ( mqtt_connection_t connection,
uint8_t *  buffer,
uint16_t  buffer_length 
)

Definition at line 128 of file mqtt_msg.c.

References mqtt_connection::buffer, mqtt_connection::buffer_length, and memset.

Referenced by mqtt_get_retain(), MQTT_InitClient(), and mqtt_tcpclient_connect_cb().

129 {
130  memset(connection, 0, sizeof(mqtt_connection_t));
131  connection->buffer = buffer;
132  connection->buffer_length = buffer_length;
133 }
#define memset(x, a, b)
Definition: platform.h:21
uint8_t * buffer
Definition: mqtt_msg.h:91
uint16_t buffer_length
Definition: mqtt_msg.h:92
Here is the caller graph for this function:

◆ mqtt_msg_pingreq()

mqtt_message_t* ICACHE_FLASH_ATTR mqtt_msg_pingreq ( mqtt_connection_t connection)

Definition at line 471 of file mqtt_msg.c.

References fini_message(), init_message(), and MQTT_MSG_TYPE_PINGREQ.

Referenced by mqtt_get_retain(), MQTT_Ping(), and mqtt_send_keepalive().

472 {
473  init_message(connection);
474  return fini_message(connection, MQTT_MSG_TYPE_PINGREQ, 0, 0, 0);
475 }
static mqtt_message_t *ICACHE_FLASH_ATTR fini_message(mqtt_connection_t *connection, int type, int dup, int qos, int retain)
Definition: mqtt_msg.c:105
static int ICACHE_FLASH_ATTR init_message(mqtt_connection_t *connection)
Definition: mqtt_msg.c:92
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mqtt_msg_pingresp()

mqtt_message_t* ICACHE_FLASH_ATTR mqtt_msg_pingresp ( mqtt_connection_t connection)

Definition at line 477 of file mqtt_msg.c.

References fini_message(), init_message(), and MQTT_MSG_TYPE_PINGRESP.

Referenced by mqtt_get_retain(), and mqtt_tcpclient_recv().

478 {
479  init_message(connection);
480  return fini_message(connection, MQTT_MSG_TYPE_PINGRESP, 0, 0, 0);
481 }
static mqtt_message_t *ICACHE_FLASH_ATTR fini_message(mqtt_connection_t *connection, int type, int dup, int qos, int retain)
Definition: mqtt_msg.c:105
static int ICACHE_FLASH_ATTR init_message(mqtt_connection_t *connection)
Definition: mqtt_msg.c:92
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mqtt_msg_puback()

mqtt_message_t* ICACHE_FLASH_ATTR mqtt_msg_puback ( mqtt_connection_t connection,
uint16_t  message_id 
)

Definition at line 403 of file mqtt_msg.c.

References append_message_id(), fail_message(), fini_message(), init_message(), and MQTT_MSG_TYPE_PUBACK.

Referenced by mqtt_get_retain(), and mqtt_tcpclient_recv().

404 {
405  init_message(connection);
406  if (append_message_id(connection, message_id) == 0)
407  return fail_message(connection);
408  return fini_message(connection, MQTT_MSG_TYPE_PUBACK, 0, 0, 0);
409 }
static mqtt_message_t *ICACHE_FLASH_ATTR fini_message(mqtt_connection_t *connection, int type, int dup, int qos, int retain)
Definition: mqtt_msg.c:105
static mqtt_message_t *ICACHE_FLASH_ATTR fail_message(mqtt_connection_t *connection)
Definition: mqtt_msg.c:98
static uint16_t ICACHE_FLASH_ATTR append_message_id(mqtt_connection_t *connection, uint16_t message_id)
Definition: mqtt_msg.c:76
static int ICACHE_FLASH_ATTR init_message(mqtt_connection_t *connection)
Definition: mqtt_msg.c:92
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mqtt_msg_pubcomp()

mqtt_message_t* ICACHE_FLASH_ATTR mqtt_msg_pubcomp ( mqtt_connection_t connection,
uint16_t  message_id 
)

Definition at line 427 of file mqtt_msg.c.

References append_message_id(), fail_message(), fini_message(), init_message(), and MQTT_MSG_TYPE_PUBCOMP.

Referenced by mqtt_get_retain(), and mqtt_tcpclient_recv().

428 {
429  init_message(connection);
430  if (append_message_id(connection, message_id) == 0)
431  return fail_message(connection);
432  return fini_message(connection, MQTT_MSG_TYPE_PUBCOMP, 0, 0, 0);
433 }
static mqtt_message_t *ICACHE_FLASH_ATTR fini_message(mqtt_connection_t *connection, int type, int dup, int qos, int retain)
Definition: mqtt_msg.c:105
static mqtt_message_t *ICACHE_FLASH_ATTR fail_message(mqtt_connection_t *connection)
Definition: mqtt_msg.c:98
static uint16_t ICACHE_FLASH_ATTR append_message_id(mqtt_connection_t *connection, uint16_t message_id)
Definition: mqtt_msg.c:76
static int ICACHE_FLASH_ATTR init_message(mqtt_connection_t *connection)
Definition: mqtt_msg.c:92
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mqtt_msg_publish()

mqtt_message_t* ICACHE_FLASH_ATTR mqtt_msg_publish ( mqtt_connection_t connection,
const char *  topic,
const char *  data,
int  data_length,
int  qos,
int  retain,
uint16_t *  message_id 
)

Definition at line 377 of file mqtt_msg.c.

References append_message_id(), append_string(), mqtt_connection::buffer, mqtt_connection::buffer_length, fail_message(), fini_message(), init_message(), mqtt_message::length, memcpy, mqtt_connection::message, MQTT_MSG_TYPE_PUBLISH, NULL, and strlen.

Referenced by mqtt_get_retain(), and MQTT_Publish().

378 {
379  init_message(connection);
380 
381  if (topic == NULL || topic[0] == '\0')
382  return fail_message(connection);
383 
384  if (append_string(connection, topic, strlen(topic)) < 0)
385  return fail_message(connection);
386 
387  if (qos > 0)
388  {
389  if ((*message_id = append_message_id(connection, 0)) == 0)
390  return fail_message(connection);
391  }
392  else
393  *message_id = 0;
394 
395  if (connection->message.length + data_length > connection->buffer_length)
396  return fail_message(connection);
397  memcpy(connection->buffer + connection->message.length, data, data_length);
398  connection->message.length += data_length;
399 
400  return fini_message(connection, MQTT_MSG_TYPE_PUBLISH, 0, qos, retain);
401 }
static mqtt_message_t *ICACHE_FLASH_ATTR fini_message(mqtt_connection_t *connection, int type, int dup, int qos, int retain)
Definition: mqtt_msg.c:105
static mqtt_message_t *ICACHE_FLASH_ATTR fail_message(mqtt_connection_t *connection)
Definition: mqtt_msg.c:98
#define NULL
Definition: def.h:47
static uint16_t ICACHE_FLASH_ATTR append_message_id(mqtt_connection_t *connection, uint16_t message_id)
Definition: mqtt_msg.c:76
mqtt_message_t message
Definition: mqtt_msg.h:88
static int ICACHE_FLASH_ATTR append_string(mqtt_connection_t *connection, const char *string, int len)
Definition: mqtt_msg.c:63
static int ICACHE_FLASH_ATTR init_message(mqtt_connection_t *connection)
Definition: mqtt_msg.c:92
uint16_t length
Definition: mqtt_msg.h:82
#define memcpy(x, a, b)
Definition: platform.h:22
uint8_t * buffer
Definition: mqtt_msg.h:91
#define strlen(a)
Definition: platform.h:25
uint16_t buffer_length
Definition: mqtt_msg.h:92
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mqtt_msg_pubrec()

mqtt_message_t* ICACHE_FLASH_ATTR mqtt_msg_pubrec ( mqtt_connection_t connection,
uint16_t  message_id 
)

Definition at line 411 of file mqtt_msg.c.

References append_message_id(), fail_message(), fini_message(), init_message(), and MQTT_MSG_TYPE_PUBREC.

Referenced by mqtt_get_retain(), and mqtt_tcpclient_recv().

412 {
413  init_message(connection);
414  if (append_message_id(connection, message_id) == 0)
415  return fail_message(connection);
416  return fini_message(connection, MQTT_MSG_TYPE_PUBREC, 0, 0, 0);
417 }
static mqtt_message_t *ICACHE_FLASH_ATTR fini_message(mqtt_connection_t *connection, int type, int dup, int qos, int retain)
Definition: mqtt_msg.c:105
static mqtt_message_t *ICACHE_FLASH_ATTR fail_message(mqtt_connection_t *connection)
Definition: mqtt_msg.c:98
static uint16_t ICACHE_FLASH_ATTR append_message_id(mqtt_connection_t *connection, uint16_t message_id)
Definition: mqtt_msg.c:76
static int ICACHE_FLASH_ATTR init_message(mqtt_connection_t *connection)
Definition: mqtt_msg.c:92
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mqtt_msg_pubrel()

mqtt_message_t* ICACHE_FLASH_ATTR mqtt_msg_pubrel ( mqtt_connection_t connection,
uint16_t  message_id 
)

Definition at line 419 of file mqtt_msg.c.

References append_message_id(), fail_message(), fini_message(), init_message(), and MQTT_MSG_TYPE_PUBREL.

Referenced by mqtt_get_retain(), and mqtt_tcpclient_recv().

420 {
421  init_message(connection);
422  if (append_message_id(connection, message_id) == 0)
423  return fail_message(connection);
424  return fini_message(connection, MQTT_MSG_TYPE_PUBREL, 0, 1, 0);
425 }
static mqtt_message_t *ICACHE_FLASH_ATTR fini_message(mqtt_connection_t *connection, int type, int dup, int qos, int retain)
Definition: mqtt_msg.c:105
static mqtt_message_t *ICACHE_FLASH_ATTR fail_message(mqtt_connection_t *connection)
Definition: mqtt_msg.c:98
static uint16_t ICACHE_FLASH_ATTR append_message_id(mqtt_connection_t *connection, uint16_t message_id)
Definition: mqtt_msg.c:76
static int ICACHE_FLASH_ATTR init_message(mqtt_connection_t *connection)
Definition: mqtt_msg.c:92
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mqtt_msg_subscribe()

mqtt_message_t* ICACHE_FLASH_ATTR mqtt_msg_subscribe ( mqtt_connection_t connection,
const char *  topic,
int  qos,
uint16_t *  message_id 
)

Definition at line 435 of file mqtt_msg.c.

References append_message_id(), append_string(), mqtt_connection::buffer, mqtt_connection::buffer_length, fail_message(), fini_message(), init_message(), mqtt_message::length, mqtt_connection::message, MQTT_MSG_TYPE_SUBSCRIBE, NULL, and strlen.

Referenced by mqtt_get_retain(), and MQTT_Subscribe().

436 {
437  init_message(connection);
438 
439  if (topic == NULL || topic[0] == '\0')
440  return fail_message(connection);
441 
442  if ((*message_id = append_message_id(connection, 0)) == 0)
443  return fail_message(connection);
444 
445  if (append_string(connection, topic, strlen(topic)) < 0)
446  return fail_message(connection);
447 
448  if (connection->message.length + 1 > connection->buffer_length)
449  return fail_message(connection);
450  connection->buffer[connection->message.length++] = qos;
451 
452  return fini_message(connection, MQTT_MSG_TYPE_SUBSCRIBE, 0, 1, 0);
453 }
static mqtt_message_t *ICACHE_FLASH_ATTR fini_message(mqtt_connection_t *connection, int type, int dup, int qos, int retain)
Definition: mqtt_msg.c:105
static mqtt_message_t *ICACHE_FLASH_ATTR fail_message(mqtt_connection_t *connection)
Definition: mqtt_msg.c:98
#define NULL
Definition: def.h:47
static uint16_t ICACHE_FLASH_ATTR append_message_id(mqtt_connection_t *connection, uint16_t message_id)
Definition: mqtt_msg.c:76
mqtt_message_t message
Definition: mqtt_msg.h:88
static int ICACHE_FLASH_ATTR append_string(mqtt_connection_t *connection, const char *string, int len)
Definition: mqtt_msg.c:63
static int ICACHE_FLASH_ATTR init_message(mqtt_connection_t *connection)
Definition: mqtt_msg.c:92
uint16_t length
Definition: mqtt_msg.h:82
uint8_t * buffer
Definition: mqtt_msg.h:91
#define strlen(a)
Definition: platform.h:25
uint16_t buffer_length
Definition: mqtt_msg.h:92
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mqtt_msg_unsubscribe()

mqtt_message_t* ICACHE_FLASH_ATTR mqtt_msg_unsubscribe ( mqtt_connection_t connection,
const char *  topic,
uint16_t *  message_id 
)

Definition at line 455 of file mqtt_msg.c.

References append_message_id(), append_string(), fail_message(), fini_message(), init_message(), MQTT_MSG_TYPE_UNSUBSCRIBE, NULL, and strlen.

Referenced by mqtt_get_retain(), and MQTT_UnSubscribe().

456 {
457  init_message(connection);
458 
459  if (topic == NULL || topic[0] == '\0')
460  return fail_message(connection);
461 
462  if ((*message_id = append_message_id(connection, 0)) == 0)
463  return fail_message(connection);
464 
465  if (append_string(connection, topic, strlen(topic)) < 0)
466  return fail_message(connection);
467 
468  return fini_message(connection, MQTT_MSG_TYPE_UNSUBSCRIBE, 0, 1, 0);
469 }
static mqtt_message_t *ICACHE_FLASH_ATTR fini_message(mqtt_connection_t *connection, int type, int dup, int qos, int retain)
Definition: mqtt_msg.c:105
static mqtt_message_t *ICACHE_FLASH_ATTR fail_message(mqtt_connection_t *connection)
Definition: mqtt_msg.c:98
#define NULL
Definition: def.h:47
static uint16_t ICACHE_FLASH_ATTR append_message_id(mqtt_connection_t *connection, uint16_t message_id)
Definition: mqtt_msg.c:76
static int ICACHE_FLASH_ATTR append_string(mqtt_connection_t *connection, const char *string, int len)
Definition: mqtt_msg.c:63
static int ICACHE_FLASH_ATTR init_message(mqtt_connection_t *connection)
Definition: mqtt_msg.c:92
#define strlen(a)
Definition: platform.h:25
Here is the call graph for this function:
Here is the caller graph for this function: