Diff for /libaitmqtt/inc/aitmqtt.h between versions 1.3.4.6 and 1.3.4.12

version 1.3.4.6, 2022/09/13 20:12:15 version 1.3.4.12, 2022/09/15 13:50:14
Line 47  SUCH DAMAGE. Line 47  SUCH DAMAGE.
 #define __AITMQTT_H  #define __AITMQTT_H
   
   
#define MAX_CONNID         24#define MQTT_CONNID_MAX                24
#define MAX_CRED           13#define MQTT_CRED_MAX                13
 #define MQTTMSG_MAX             65535  #define MQTTMSG_MAX             65535
 #define MQTTMSG_BIN_MAX         65535  #define MQTTMSG_BIN_MAX         65535
 #define MQTT_DATA_MAX           268435455  #define MQTT_DATA_MAX           268435455
   
#define MQTT_PROTO_VER          3#define MQTT_PROTO_VER_3        3
#define MQTT_PROTO_DEFVER        5#define MQTT_PROTO_VER_311 4
#define MQTT_KEEPALIVE          10#define MQTT_PROTO_VER_5        5
#define MQTT_DEFAULT_MSGID      0xDEBA#define MQTT_KEEPALIVE          60
   
 /* FIXED HEADER */  /* FIXED HEADER */
   
Line 75  struct mqtthdr { Line 75  struct mqtthdr {
 #define MQTTHDR_MSGINIT(x)      (assert((x)), (x)->mqtt_msg.val ^= (x)->mqtt_msg.val, *(x)->mqtt_len = 0)  #define MQTTHDR_MSGINIT(x)      (assert((x)), (x)->mqtt_msg.val ^= (x)->mqtt_msg.val, *(x)->mqtt_len = 0)
 #define MQTTHDR_DATA_SIZEOF(x)  (assert((x)), mqtt_decodeLen((x)->mqtt_len, NULL))  #define MQTTHDR_DATA_SIZEOF(x)  (assert((x)), mqtt_decodeLen((x)->mqtt_len, NULL))
   
   typedef union {
           struct {
                   unsigned short  m:8,
                                   l:8;
           } sb;
           unsigned short  val;
   } __attribute__((packed)) mqtt_len_t;
   
   typedef struct {
           mqtt_len_t      var_sb;
           unsigned char   var_data[0];
   } __attribute__((packed)) mqtthdr_var_t;
   #define MQTTHDR_VAR_SIZEOF(x)           (assert((x)), sizeof(mqtt_len_t) + ntohs((x)->var_sb.val))
   
   typedef union {
           struct {
                   unsigned char   reserved:1,
                                   clean_sess:1,
                                   will_flg:1,
                                   will_qos:2,
                                   will_retain:1,
                                   password:1,
                                   username:1;
           };
           unsigned char           flags;
   } __attribute__((packed)) mqtthdr_connflgs_t;
   
   typedef struct {
           unsigned char   reserved;
           unsigned char   retcode;
   } __attribute__((packed)) mqtthdr_connack_t;
   
 #define MQTT_TYPE_UNKNOWN       0       /* reserved */  #define MQTT_TYPE_UNKNOWN       0       /* reserved */
 #define MQTT_TYPE_CONNECT       1       /* client request to connect to server (CLI) */  #define MQTT_TYPE_CONNECT       1       /* client request to connect to server (CLI) */
 #define MQTT_TYPE_CONNACK       2       /* connect acknowledgment (SRV) [ret_no_data] */  #define MQTT_TYPE_CONNACK       2       /* connect acknowledgment (SRV) [ret_no_data] */
Line 205  typedef struct { Line 237  typedef struct {
   
 /* MQTT structures */  /* MQTT structures */
   
 typedef union {  
         struct {  
                 unsigned short  m:8,  
                                 l:8;  
         } sb;  
         unsigned short  val;  
 } mqtt_len_t;  
   
 typedef struct {  typedef struct {
        unsigned char   sub_ret;        unsigned char   sub_qos;
         mqtt_msg_t      sub_topic;          mqtt_msg_t      sub_topic;
         mqtt_msg_t      sub_value;          mqtt_msg_t      sub_value;
 } mqtt_subscr_t;  } mqtt_subscr_t;
   
 typedef struct {  
         mqtt_len_t      var_sb;  
         unsigned char   var_data[0];  
 } __attribute__((packed)) mqtthdr_var_t;  
 #define MQTTHDR_VAR_SIZEOF(x)           (assert((x)), sizeof(mqtt_len_t) + ntohs((x)->var_sb.val))  
   
 typedef unsigned char mqtthdr_protover_t;  
   
 typedef union {  
         struct {  
                 unsigned char   reserved:1,  
                                 clean_sess:1,  
                                 will_flg:1,  
                                 will_qos:2,  
                                 will_retain:1,  
                                 password:1,  
                                 username:1;  
         };  
         unsigned char           flags;  
 } __attribute__((packed)) mqtthdr_connflgs_t;  
   
 typedef struct {  
         unsigned char   reserved;  
         unsigned char   retcode;  
 } __attribute__((packed)) mqtthdr_connack_t;  
   
   
 // -------------------------------------------------------  // -------------------------------------------------------
 // mqtt_GetErrno() Get error code of last operation  // mqtt_GetErrno() Get error code of last operation
 int mqtt_GetErrno();  int mqtt_GetErrno();
Line 265  mqtt_msg_t *mqtt_msgAlloc(unsigned int len); Line 263  mqtt_msg_t *mqtt_msgAlloc(unsigned int len);
  * mqtt_msgFree() Free MQTT message   * mqtt_msgFree() Free MQTT message
  *   *
  * @msg = Message buffer   * @msg = Message buffer
 * @all = !=0 Destroy entire message, if MQTT Message allocated with mqtt_msgAlloc() * @keepmsg = !=0 just free message content
  * return: none   * return: none
  */   */
void mqtt_msgFree(mqtt_msg_t ** __restrict msg, int all);void mqtt_msgFree(mqtt_msg_t ** __restrict msg, int keepmsg);
 /*  /*
  * mqtt_msgRealloc() Reallocate MQTT message buffer   * mqtt_msgRealloc() Reallocate MQTT message buffer
  *   *
Line 383  mqtt_subscr_t *mqtt_subCopy(mqtt_subscr_t * __restrict Line 381  mqtt_subscr_t *mqtt_subCopy(mqtt_subscr_t * __restrict
 /*  /*
  * mqtt_msgCONNECT() Create CONNECT message   * mqtt_msgCONNECT() Create CONNECT message
  *   *
  * @buf = Message buffer  
  * @csConnID = ConnectID   * @csConnID = ConnectID
 * @kasec = Keep alive timeout, if =0 default timeout for MQTT * @Version = MQTT version, if =0 default version is 3.1.1
  * @KASec = Keep alive timeout, if =0 default timeout for MQTT
  * @csUser = Username if !=NULL   * @csUser = Username if !=NULL
  * @csPass = Password for Username, only if csUser is set   * @csPass = Password for Username, only if csUser is set
  * @csWillTopic = Will Topic if !=NULL Will Flags set into message   * @csWillTopic = Will Topic if !=NULL Will Flags set into message
Line 393  mqtt_subscr_t *mqtt_subCopy(mqtt_subscr_t * __restrict Line 391  mqtt_subscr_t *mqtt_subCopy(mqtt_subscr_t * __restrict
  * @ClrSess = Clear Session subscriptions after disconnect   * @ClrSess = Clear Session subscriptions after disconnect
  * @WillQOS = Will QOS if csWillTopic is set   * @WillQOS = Will QOS if csWillTopic is set
  * @WillRetain = Will Retain Will Message if csWillTopic is set   * @WillRetain = Will Retain Will Message if csWillTopic is set
 * return: -1 error or >-1 message size for send * return: NULL error or allocated CONNECT message
  */   */
int mqtt_msgCONNECT(mqtt_msg_t * __restrict buf, const char *csConnID, mqtt_msg_t *mqtt_msgCONNECT(const char *csConnID, unsigned char Version, 
                unsigned short kasec, const char *csUser, const char *csPass,                 unsigned short KASec, const char *csUser, const char *csPass, 
                 const char *csWillTopic, const char *csWillMessage,                   const char *csWillTopic, const char *csWillMessage, 
                 unsigned char ClrSess, unsigned char WillQOS, unsigned char WillRetain);                  unsigned char ClrSess, unsigned char WillQOS, unsigned char WillRetain);
 /*  /*
  * mqtt_msgCONNACK() Create CONNACK message   * mqtt_msgCONNACK() Create CONNACK message
  *   *
  * @buf = Message buffer  
  * @retcode = Return code   * @retcode = Return code
 * return: -1 error or >-1 message size for send * return: NULL error or allocated CONNACK message
  */   */
int mqtt_msgCONNACK(mqtt_msg_t * __restrict buf, unsigned char retcode);mqtt_msg_t *mqtt_msgCONNACK(unsigned char retcode);
 /*  /*
  * mqtt_msgDISCONNECT() Create DISCONNECT message   * mqtt_msgDISCONNECT() Create DISCONNECT message
  *   *
 * @buf = Message buffer * return: NULL error or allocated message
 * return: -1 error or >-1 message size for send 
  */   */
int mqtt_msgDISCONNECT(mqtt_msg_t * __restrict buf);mqtt_msg_t *mqtt_msgDISCONNECT();
 /*  /*
  * mqtt_msgPINGREQ() Create PINGREQ message   * mqtt_msgPINGREQ() Create PINGREQ message
  *   *
 * @buf = Message buffer * return: NULL error or allocated message
 * return: -1 error or >-1 message size for send 
  */   */
int mqtt_msgPINGREQ(mqtt_msg_t * __restrict buf);mqtt_msg_t *mqtt_msgPINGREQ();
 /*  /*
  * mqtt_msgPINGRESP() Create PINGRESP message   * mqtt_msgPINGRESP() Create PINGRESP message
  *   *
 * @buf = Message buffer * return: NULL error or allocated message
 * return: -1 error or >-1 message size for send 
  */   */
int mqtt_msgPINGRESP(mqtt_msg_t * __restrict buf);mqtt_msg_t *mqtt_msgPINGRESP();
   
 /*  /*
  * mqtt_msgPUBLISH() Create PUBLISH message   * mqtt_msgPUBLISH() Create PUBLISH message
  *   *
  * @buf = Message buffer  
  * @csTopic = Publish topic   * @csTopic = Publish topic
  * @msgID = MessageID >0, if QOS != MQTT_QOS_ONCE   * @msgID = MessageID >0, if QOS != MQTT_QOS_ONCE
  * @Dup = Duplicate message   * @Dup = Duplicate message
Line 440  int mqtt_msgPINGRESP(mqtt_msg_t * __restrict buf); Line 433  int mqtt_msgPINGRESP(mqtt_msg_t * __restrict buf);
  * @Retain = Retain message   * @Retain = Retain message
  * @pData = Publish data into topic   * @pData = Publish data into topic
  * @datlen = Publish data length   * @datlen = Publish data length
 * return: -1 error or >-1 message size for send * return: NULL error or allocated PUBLISH message
  */   */
int mqtt_msgPUBLISH(mqtt_msg_t * __restrict buf, const char *csTopic, mqtt_msg_t *mqtt_msgPUBLISH(const char *csTopic, unsigned short msgID, 
                unsigned short msgID, unsigned char Dup, unsigned char QOS,                 unsigned char Dup, unsigned char QOS, 
                 unsigned char Retain, const void *pData, int datlen);                  unsigned char Retain, const void *pData, int datlen);
 /*  /*
  * mqtt_msgPUBACK() Create PUBACK message   * mqtt_msgPUBACK() Create PUBACK message
  *   *
  * @buf = Message buffer  
  * @msgID = MessageID   * @msgID = MessageID
 * return: -1 error or >-1 message size for send * return: NULL error or allocated PUBACK message
  */   */
int mqtt_msgPUBACK(mqtt_msg_t * __restrict buf, unsigned short msgID);mqtt_msg_t *mqtt_msgPUBACK(unsigned short msgID);
 /*  /*
  * mqtt_msgPUBREC() Create PUBREC message   * mqtt_msgPUBREC() Create PUBREC message
  *   *
  * @buf = Message buffer  
  * @msgID = MessageID   * @msgID = MessageID
 * return: -1 error or >-1 message size for send * return: NULL error or allocated PUBREC message
  */   */
int mqtt_msgPUBREC(mqtt_msg_t * __restrict buf, unsigned short msgID);mqtt_msg_t *mqtt_msgPUBREC(unsigned short msgID);
 /*  /*
  * mqtt_msgPUBREL() Create PUBREL message   * mqtt_msgPUBREL() Create PUBREL message
  *   *
  * @buf = Message buffer  
  * @msgID = MessageID   * @msgID = MessageID
 * return: -1 error or >-1 message size for send * return: NULL error or allocated PUBREL message
  */   */
int mqtt_msgPUBREL(mqtt_msg_t * __restrict buf, unsigned short msgID);mqtt_msg_t *mqtt_msgPUBREL(unsigned short msgID);
 /*  /*
  * mqtt_msgPUBCOMP() Create PUBCOMP message   * mqtt_msgPUBCOMP() Create PUBCOMP message
  *   *
  * @buf = Message buffer  
  * @msgID = MessageID   * @msgID = MessageID
 * return: -1 error or >-1 message size for send * return: NULL error or allocated PUBCOMP message
  */   */
int mqtt_msgPUBCOMP(mqtt_msg_t * __restrict buf, unsigned short msgID);mqtt_msg_t *mqtt_msgPUBCOMP(unsigned short msgID);
   
 /*  /*
  * mqtt_msgSUBSCRIBE() Create SUBSCRIBE message   * mqtt_msgSUBSCRIBE() Create SUBSCRIBE message
  *   *
  * @buf = Message buffer  
  * @Topics = MQTT subscription topics   * @Topics = MQTT subscription topics
  * @msgID = MessageID   * @msgID = MessageID
  * @Dup = Duplicate message   * @Dup = Duplicate message
  * @QOS = QoS   * @QOS = QoS
 * return: -1 error or >-1 message size for send * return: NULL error or allocated SUBSCRIBE message
  */   */
intmqtt_msg_t *mqtt_msgSUBSCRIBE(mqtt_subscr_t ** __restrict Topics, 
mqtt_msgSUBSCRIBE(mqtt_msg_t * __restrict buf, mqtt_subscr_t * __restrict Topics,  
                 unsigned short msgID, unsigned char Dup, unsigned char QOS);                  unsigned short msgID, unsigned char Dup, unsigned char QOS);
 /*  /*
  * mqtt_msgSUBACK() Create SUBACK message   * mqtt_msgSUBACK() Create SUBACK message
  *   *
  * @buf = Message buffer  
  * @Topics = MQTT subscription topics   * @Topics = MQTT subscription topics
  * @msgID = MessageID   * @msgID = MessageID
 * return: -1 error or >-1 message size for send * return: NULL error or allocated SUBACK message
  */   */
int mqtt_msgSUBACK(mqtt_msg_t * __restrict buf, mqtt_subscr_t * __restrict Topics, mqtt_msg_t *mqtt_msgSUBACK(mqtt_subscr_t ** __restrict Topics, unsigned short msgID);
                unsigned short msgID); 
 /*  /*
  * mqtt_msgUNSUBSCRIBE() Create UNSUBSCRIBE message   * mqtt_msgUNSUBSCRIBE() Create UNSUBSCRIBE message
  *   *
  * @buf = Message buffer  
  * @Topics = MQTT subscription topics   * @Topics = MQTT subscription topics
  * @msgID = MessageID   * @msgID = MessageID
  * @Dup = Duplicate message   * @Dup = Duplicate message
  * @QOS = QoS   * @QOS = QoS
 * return: -1 error or >-1 message size for send * return: NULL error or allocated UNSUBSCRIBE message
  */   */
intmqtt_msg_t *mqtt_msgUNSUBSCRIBE(mqtt_subscr_t ** __restrict Topics, 
mqtt_msgUNSUBSCRIBE(mqtt_msg_t * __restrict buf, mqtt_subscr_t * __restrict Topics,  
                 unsigned short msgID, unsigned char Dup, unsigned char QOS);                  unsigned short msgID, unsigned char Dup, unsigned char QOS);
 /*  /*
  * mqtt_msgUNSUBACK() Create UNSUBACK message   * mqtt_msgUNSUBACK() Create UNSUBACK message
  *   *
  * @buf = Message buffer  
  * @msgID = MessageID   * @msgID = MessageID
 * return: -1 error or >-1 message size for send * return: NULL error or allocated UNSUBACK message
  */   */
int mqtt_msgUNSUBACK(mqtt_msg_t * __restrict buf, unsigned short msgID);mqtt_msg_t *mqtt_msgUNSUBACK(unsigned short msgID);
   
   
 /*** RECEIVER FUNCTIONS ***/  /*** RECEIVER FUNCTIONS ***/
Line 530  int mqtt_msgUNSUBACK(mqtt_msg_t * __restrict buf, unsi Line 512  int mqtt_msgUNSUBACK(mqtt_msg_t * __restrict buf, unsi
  * mqtt_readCONNECT() Read elements from CONNECT message   * mqtt_readCONNECT() Read elements from CONNECT message
  *   *
  * @buf = Message buffer   * @buf = Message buffer
 * @kasec = Keep Alive in seconds for current connection * @KASec = Keep Alive in seconds for current connection
  * @psConnID = ConnectID   * @psConnID = ConnectID
  * @connLen = ConnectID length   * @connLen = ConnectID length
  * @psUser = Username if !=NULL   * @psUser = Username if !=NULL
  * @userLen = Username length   * @userLen = Username length
  * @psPass = Password for Username, only if csUser is set   * @psPass = Password for Username, only if csUser is set
  * @passLen = Password length   * @passLen = Password length
 * @psWillTopic = Will Topic if !=NULL Will Flags set into message and must be free() * @psWillTopic = Will Topic if !=NULL Will Flags set into message and must be e_free()
 * @psWillMessage = Will Message, may be NULL if !NULL must be free() after use! * @psWillMessage = Will Message, may be NULL if !NULL must be e_free() after use!
  * return: .reserved == 1 is error or == 0 connection flags & msg ok   * return: .reserved == 1 is error or == 0 connection flags & msg ok
  */   */
mqtthdr_connack_t mqtt_readCONNECT(mqtt_msg_t * __restrict buf, unsigned short *kasec, mqtthdr_connack_t mqtt_readCONNECT(mqtt_msg_t * __restrict buf, unsigned short *KASec, 
                 char * __restrict psConnID, int connLen,                   char * __restrict psConnID, int connLen, 
                 char * __restrict psUser, int userLen, char * __restrict psPass, int passLen,                    char * __restrict psUser, int userLen, char * __restrict psPass, int passLen,  
                 char ** __restrict psWillTopic, char ** __restrict psWillMessage);                  char ** __restrict psWillTopic, char ** __restrict psWillMessage);
Line 630  int mqtt_readSUBSCRIBE(mqtt_msg_t * __restrict buf, un Line 612  int mqtt_readSUBSCRIBE(mqtt_msg_t * __restrict buf, un
  *   *
  * @buf = Message buffer   * @buf = Message buffer
  * @msgID = MessageID   * @msgID = MessageID
 * @subqos = Subscribes QoS, must be free after use with free() * @subqos = Subscribes QoS, must be free after use with e_free()
  * return: -1 error or >-1 readed subscribes QoS elements   * return: -1 error or >-1 readed subscribes QoS elements
  */   */
 int mqtt_readSUBACK(mqtt_msg_t * __restrict buf, unsigned short *msgID, unsigned char **subqos);  int mqtt_readSUBACK(mqtt_msg_t * __restrict buf, unsigned short *msgID, unsigned char **subqos);

Removed from v.1.3.4.6  
changed lines
  Added in v.1.3.4.12


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>