Annotation of mqtt/inc/aitmqtt.h, revision 1.1.1.1.2.4

1.1       misho       1: #ifndef __AITMQTT_H
                      2: #define __AITMQTT_H
                      3: 
                      4: 
1.1.1.1.2.3  misho       5: #define MQTT_DATA_MAX          268435455
1.1.1.1.2.4! misho       6: #define MQTT_CONN_STR          "MQIsdp"
        !             7: #define MQTT_PROTO_VER         3
        !             8: #define MQTT_KEEPALIVE         10
        !             9: 
        !            10: /* FIXED HEADER */
1.1.1.1.2.3  misho      11: 
1.1.1.1.2.1  misho      12: struct mqtthdr {
1.1.1.1.2.4! misho      13:        struct {
        !            14:                unsigned char   retain:1, 
        !            15:                                qos:2,
        !            16:                                dup:1,
        !            17:                                type:4;
        !            18:        } mqtt_msg;
        !            19:        unsigned char           mqtt_len[1];    /* may be grow to 4 bytes */
        !            20: } __packed;
1.1.1.1.2.1  misho      21: 
                     22: #define MQTT_TYPE_UNKNOWN      0       /* reserved */
                     23: #define MQTT_TYPE_CONNECT      1       /* client request to connect to server */
                     24: #define MQTT_TYPE_CONNACK      2       /* connect acknowledgment */
                     25: #define MQTT_TYPE_PUBLISH      3       /* publish message */
                     26: #define MQTT_TYPE_PUBACK       4       /* publish acknowledgment */
                     27: #define MQTT_TYPE_PUBREC       5       /* publish received (assured delivery part 1) */
                     28: #define MQTT_TYPE_PUBREL       6       /* publish release (assured delivery part 2) */
                     29: #define MQTT_TYPE_PUBCOMP      7       /* publish complete (assured delivery part 3) */
                     30: #define MQTT_TYPE_SUBSCRIBE    8       /* client subscribe request */
                     31: #define MQTT_TYPE_SUBACK       9       /* subscribe acknowledgment */
                     32: #define MQTT_TYPE_UNSUBSCRIBE  10      /* client unsubscribe request */
                     33: #define MQTT_TYPE_UNSUBACK     11      /* unsubscribe acknowledgment */
                     34: #define MQTT_TYPE_PINGREQ      12      /* PING request */
                     35: #define MQTT_TYPE_PINGRESP     13      /* PING response */
                     36: #define MQTT_TYPE_DISCONNECT   14      /* client is disconnecting */
                     37: #define MQTT_TYPE_RESERVED     15      /* reserved */
                     38: 
                     39: #define MQTT_FLAG_DUP          1       /* This flag is set when the client or server attempts to re-deliver 
                     40:                                           a PUBLISH, PUBREL, SUBSCRIBE or UNSUBSCRIBE message. 
                     41:                                           This applies to messages where the value of QoS is greater than 
                     42:                                           zero (0), and an acknowledgment is required. 
                     43:                                           When the DUP bit is set, the variable header includes a Message ID.
                     44: 
                     45:                                           The recipient should treat this flag as a hint as to whether 
                     46:                                           the message may have been previously received. 
                     47:                                           It should not be relied on to detect duplicates. */
                     48: 
                     49: #define MQTT_QOS_ONCE          0       /* At most once, Fire and Forget, <=1 */
                     50: #define MQTT_QOS_ACK           1       /* At least once, Acknowledged delivery, >=1 */
                     51: #define MQTT_QOS_EXACTLY       2       /* Exactly once, Assured delivery, =1 */
                     52: #define MQTT_QOS_RESERVED      3       /* reserved */
                     53: 
                     54: #define MQTT_FLAG_RETAIN       1       /* This flag is only used on PUBLISH messages.
                     55: 
                     56:                                           When a client sends a PUBLISH to a server, 
                     57:                                           if the Retain flag is set (1), 
                     58:                                           the server should hold on to the message after it has been 
                     59:                                           delivered to the current subscribers.
                     60:                                           When a new subscription is established on a topic, 
                     61:                                           the last retained message on that topic should be sent to 
                     62:                                           the subscriber with the Retain flag set.
                     63:                                           If there is no retained message, nothing is sent
                     64:                                           This is useful where publishers send messages on a 
                     65:                                           "report by exception" basis, where it might be some time between messages. 
                     66:                                           This allows new subscribers to instantly receive data with the retained, 
                     67:                                           or Last Known Good, value.
                     68: 
                     69:                                           When a server sends a PUBLISH to a client as a result of 
                     70:                                           a subscription that already existed when the original PUBLISH arrived, 
                     71:                                           the Retain flag should not be set, regardless of the Retain flag 
                     72:                                           of the original PUBLISH. This allows a client to distinguish messages 
                     73:                                           that are being received because they were retained and those 
                     74:                                           that are being received "live".
                     75: 
                     76:                                           Retained messages should be kept over restarts of the server.
                     77:                                           A server may delete a retained message if it receives a message 
                     78:                                           with a zero-length payload and the Retain flag set on the same topic. */
                     79: 
1.1.1.1.2.4! misho      80: /* VARIABLE HEADERS */
        !            81: 
        !            82: #define MQTT_RETCODE_ACCEPTED          0
        !            83: #define MQTT_RETCODE_REFUSE_VER                1
        !            84: #define MQTT_RETCODE_REFUSE_ID         2
        !            85: #define MQTT_RETCODE_REFUSE_UNAVAIL    3
        !            86: #define MQTT_RETCODE_REFUSE_USERPASS   4
        !            87: #define MQTT_RETCODE_DENIED            5
        !            88: 
        !            89: 
        !            90: typedef union {
        !            91:        struct {
        !            92:                unsigned short  m:8,
        !            93:                                l:8;
        !            94:        } sb;
        !            95:        unsigned short  val;
        !            96: } mqtthdr_val_t;
        !            97: 
        !            98: typedef struct {
        !            99:        mqtthdr_val_t   var_sb;
        !           100:        unsigned char   var_data[0];
        !           101: } __packed mqtthdr_var_t;
        !           102: 
        !           103: typedef unsigned char mqtthdr_protover_t;
        !           104: typedef unsigned char mqtthdr_retcode_t;
        !           105: 
        !           106: typedef struct {
        !           107:        unsigned char   reserved:1,
        !           108:                        clean_sess:1,
        !           109:                        will_flg:1,
        !           110:                        will_qos:2,
        !           111:                        will_retain:1,
        !           112:                        password:1,
        !           113:                        username:1;
        !           114: } __packed mqtthdr_connflgs_t;
        !           115: 
1.1.1.1.2.1  misho     116: 
1.1       misho     117: // -------------------------------------------------------
                    118: // mqtt_GetErrno() Get error code of last operation
                    119: inline int mqtt_GetErrno();
                    120: // mqtt_GetError() Get error text of last operation
                    121: inline const char *mqtt_GetError();
                    122: // -------------------------------------------------------
                    123: 
                    124: 
1.1.1.1.2.1  misho     125: /*
                    126:  * mqtt_encodeLen() Encode number to MQTT length field
                    127:  * @num = number for encode
                    128:  * return: -1 error or >-1 length
                    129:  */
                    130: inline unsigned int mqtt_encodeLen(unsigned int num);
                    131: /*
                    132:  * mqtt_decodeLen() Decode length from MQTT packet
                    133:  * @len = length
1.1.1.1.2.2  misho     134:  * @n = sizeof bytes, if !=NULL
1.1.1.1.2.1  misho     135:  * return: -1 error, >-1 length of message
                    136:  */
1.1.1.1.2.2  misho     137: inline unsigned int mqtt_decodeLen(unsigned int len, char *n);
                    138: /*
                    139:  * mqtt_sizeLen Return sizeof len field
                    140:  * @len = length
                    141:  * return: -1 error, >-1 sizeof len in bytes
                    142:  */
                    143: inline char mqtt_sizeLen(unsigned int len);
1.1.1.1.2.4! misho     144: /*
        !           145:  * mqtt_str2var Create MQTT variable from string
        !           146:  * @csStr = string
        !           147:  * @strLen = string length
        !           148:  * return: NULL error or != ok variable, must be free after use!
        !           149:  */
        !           150: inline mqtthdr_var_t *mqtt_str2var(const unsigned char *csStr, unsigned short strLen);
1.1.1.1.2.1  misho     151: 
                    152: 
1.1       misho     153: #endif

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