Annotation of libaitmqtt/inc/aitmqtt.h, revision 1.1.1.1.2.5

1.1       misho       1: /*************************************************************************
                      2: * (C) 2011 AITNET ltd - Sofia/Bulgaria - <misho@aitbg.com>
                      3: *  by Michael Pounov <misho@openbsd-bg.org>
                      4: *
                      5: * $Author: misho $
1.1.1.1.2.5! misho       6: * $Id: aitmqtt.h,v 1.1.1.1.2.4 2012/01/27 15:15:32 misho Exp $
1.1       misho       7: *
                      8: **************************************************************************
                      9: The ELWIX and AITNET software is distributed under the following
                     10: terms:
                     11: 
                     12: All of the documentation and software included in the ELWIX and AITNET
                     13: Releases is copyrighted by ELWIX - Sofia/Bulgaria <info@elwix.org>
                     14: 
                     15: Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
                     16:        by Michael Pounov <misho@elwix.org>.  All rights reserved.
                     17: 
                     18: Redistribution and use in source and binary forms, with or without
                     19: modification, are permitted provided that the following conditions
                     20: are met:
                     21: 1. Redistributions of source code must retain the above copyright
                     22:    notice, this list of conditions and the following disclaimer.
                     23: 2. Redistributions in binary form must reproduce the above copyright
                     24:    notice, this list of conditions and the following disclaimer in the
                     25:    documentation and/or other materials provided with the distribution.
                     26: 3. All advertising materials mentioning features or use of this software
                     27:    must display the following acknowledgement:
                     28: This product includes software developed by Michael Pounov <misho@elwix.org>
                     29: ELWIX - Embedded LightWeight unIX and its contributors.
                     30: 4. Neither the name of AITNET nor the names of its contributors
                     31:    may be used to endorse or promote products derived from this software
                     32:    without specific prior written permission.
                     33: 
                     34: THIS SOFTWARE IS PROVIDED BY AITNET AND CONTRIBUTORS ``AS IS'' AND
                     35: ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     36: IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     37: ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     38: FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     39: DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     40: OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     41: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     42: LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     43: OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     44: SUCH DAMAGE.
                     45: */
                     46: #ifndef __AITMQTT_H
                     47: #define __AITMQTT_H
                     48: 
                     49: 
1.1.1.1.2.3  misho      50: #define MAX_CONNID             24
                     51: #define MAX_CRED               13
                     52: #define MQTTMSG_MAX            65529
1.1.1.1.2.5! misho      53: #define MQTT_DATA_MAX          268435455
1.1.1.1.2.3  misho      54: 
1.1.1.1.2.4  misho      55: #define MQTT_PROTO_VER         3
                     56: #define MQTT_KEEPALIVE         10
1.1.1.1.2.5! misho      57: #define MQTT_DEFAULT_MSGID     0xDEBA
1.1.1.1.2.4  misho      58: 
1.1       misho      59: /* FIXED HEADER */
                     60: 
                     61: struct mqtthdr {
                     62:        union {
                     63:                struct {
                     64:                        unsigned char   retain:1, 
                     65:                                        qos:2,
                     66:                                        dup:1,
                     67:                                        type:4;
                     68:                };
                     69:                unsigned char           val;
                     70:        } mqtt_msg;
                     71:        unsigned char                   mqtt_len[1];    /* may be grow to 4 bytes */
                     72: } __packed;
                     73: #define MQTTHDR_MSGINIT(x)     (assert((x)), (x)->mqtt_msg.val ^= (x)->mqtt_msg.val)
                     74: 
                     75: #define MQTT_TYPE_UNKNOWN      0       /* reserved */
                     76: #define MQTT_TYPE_CONNECT      1       /* client request to connect to server */
                     77: #define MQTT_TYPE_CONNACK      2       /* connect acknowledgment */
                     78: #define MQTT_TYPE_PUBLISH      3       /* publish message */
                     79: #define MQTT_TYPE_PUBACK       4       /* publish acknowledgment */
                     80: #define MQTT_TYPE_PUBREC       5       /* publish received (assured delivery part 1) */
                     81: #define MQTT_TYPE_PUBREL       6       /* publish release (assured delivery part 2) */
                     82: #define MQTT_TYPE_PUBCOMP      7       /* publish complete (assured delivery part 3) */
                     83: #define MQTT_TYPE_SUBSCRIBE    8       /* client subscribe request */
                     84: #define MQTT_TYPE_SUBACK       9       /* subscribe acknowledgment */
                     85: #define MQTT_TYPE_UNSUBSCRIBE  10      /* client unsubscribe request */
                     86: #define MQTT_TYPE_UNSUBACK     11      /* unsubscribe acknowledgment */
                     87: #define MQTT_TYPE_PINGREQ      12      /* PING request */
                     88: #define MQTT_TYPE_PINGRESP     13      /* PING response */
                     89: #define MQTT_TYPE_DISCONNECT   14      /* client is disconnecting */
                     90: #define MQTT_TYPE_MAX          15      /* reserved */
                     91: 
                     92: #define MQTT_FLAG_DUP          1       /* This flag is set when the client or server attempts to re-deliver 
                     93:                                           a PUBLISH, PUBREL, SUBSCRIBE or UNSUBSCRIBE message. 
                     94:                                           This applies to messages where the value of QoS is greater than 
                     95:                                           zero (0), and an acknowledgment is required. 
                     96:                                           When the DUP bit is set, the variable header includes a Message ID.
                     97: 
                     98:                                           The recipient should treat this flag as a hint as to whether 
                     99:                                           the message may have been previously received. 
                    100:                                           It should not be relied on to detect duplicates. */
                    101: 
                    102: #define MQTT_QOS_ONCE          0       /* At most once, Fire and Forget, <=1 */
                    103: #define MQTT_QOS_ACK           1       /* At least once, Acknowledged delivery, >=1 */
                    104: #define MQTT_QOS_EXACTLY       2       /* Exactly once, Assured delivery, =1 */
                    105: #define MQTT_QOS_RESERVED      3       /* reserved */
                    106: 
                    107: #define MQTT_FLAG_RETAIN       1       /* This flag is only used on PUBLISH messages.
                    108: 
                    109:                                           When a client sends a PUBLISH to a server, 
                    110:                                           if the Retain flag is set (1), 
                    111:                                           the server should hold on to the message after it has been 
                    112:                                           delivered to the current subscribers.
                    113:                                           When a new subscription is established on a topic, 
                    114:                                           the last retained message on that topic should be sent to 
                    115:                                           the subscriber with the Retain flag set.
                    116:                                           If there is no retained message, nothing is sent
                    117:                                           This is useful where publishers send messages on a 
                    118:                                           "report by exception" basis, where it might be some time between messages. 
                    119:                                           This allows new subscribers to instantly receive data with the retained, 
                    120:                                           or Last Known Good, value.
                    121: 
                    122:                                           When a server sends a PUBLISH to a client as a result of 
                    123:                                           a subscription that already existed when the original PUBLISH arrived, 
                    124:                                           the Retain flag should not be set, regardless of the Retain flag 
                    125:                                           of the original PUBLISH. This allows a client to distinguish messages 
                    126:                                           that are being received because they were retained and those 
                    127:                                           that are being received "live".
                    128: 
                    129:                                           Retained messages should be kept over restarts of the server.
                    130:                                           A server may delete a retained message if it receives a message 
                    131:                                           with a zero-length payload and the Retain flag set on the same topic. */
                    132: 
                    133: /* VARIABLE HEADERS */
                    134: 
                    135: #define MQTT_RETCODE_ACCEPTED          0
                    136: #define MQTT_RETCODE_REFUSE_VER                1
                    137: #define MQTT_RETCODE_REFUSE_ID         2
                    138: #define MQTT_RETCODE_REFUSE_UNAVAIL    3
                    139: #define MQTT_RETCODE_REFUSE_USERPASS   4
                    140: #define MQTT_RETCODE_DENIED            5
                    141: 
                    142: 
                    143: /* MQTT Message buffer */
                    144: 
                    145: typedef struct {
                    146:        void            *msg_base;
                    147:        unsigned short  msg_len;
                    148: } mqtt_msg_t;
                    149: 
                    150: /* MQTT structures */
                    151: 
                    152: typedef union {
                    153:        struct {
                    154:                unsigned short  m:8,
                    155:                                l:8;
                    156:        } sb;
                    157:        unsigned short  val;
                    158: } mqtt_len_t;
                    159: 
                    160: typedef struct {
                    161:        unsigned char   sub_ret;
                    162:        mqtt_msg_t      sub_topic;
                    163:        mqtt_msg_t      sub_value;
                    164: } mqtt_subscr_t;
                    165: 
                    166: typedef struct {
                    167:        mqtt_len_t      var_sb;
                    168:        unsigned char   var_data[0];
                    169: } __packed mqtthdr_var_t;
                    170: #define MQTTHDR_VAR_SIZEOF(x)          (assert((x)), sizeof(mqtt_len_t) + ntohs((x)->var_sb.val))
                    171: 
                    172: typedef unsigned char mqtthdr_protover_t;
                    173: 
                    174: typedef union {
                    175:        struct {
                    176:                unsigned char   reserved:1,
                    177:                                clean_sess:1,
                    178:                                will_flg:1,
                    179:                                will_qos:2,
                    180:                                will_retain:1,
                    181:                                password:1,
                    182:                                username:1;
                    183:        };
                    184:        unsigned char           flags;
                    185: } __packed mqtthdr_connflgs_t;
                    186: 
                    187: typedef struct {
                    188:        unsigned char   reserved;
                    189:        unsigned char   retcode;
                    190: } __packed mqtthdr_connack_t;
                    191: 
                    192: 
                    193: // -------------------------------------------------------
                    194: // mqtt_GetErrno() Get error code of last operation
                    195: inline int mqtt_GetErrno();
                    196: // mqtt_GetError() Get error text of last operation
                    197: inline const char *mqtt_GetError();
                    198: // -------------------------------------------------------
                    199: 
                    200: 
                    201: /*
                    202:  * mqtt_msgAlloc() Allocate memory for MQTT Message
                    203:  *
                    204:  * @len = >0 Allocate buffer with length
                    205:  * return: NULL error or Message, after use must call mqtt_msgFree() with all!=0
                    206:  */
                    207: inline mqtt_msg_t *mqtt_msgAlloc(unsigned short len);
                    208: /*
                    209:  * mqtt_msgFree() Free MQTT message
                    210:  *
                    211:  * @msg = Message buffer
                    212:  * @all = !=0 Destroy entire message, if MQTT Message allocated with mqtt_msgAlloc()
                    213:  * return: none
                    214:  */
                    215: inline void mqtt_msgFree(mqtt_msg_t ** __restrict msg, int all);
                    216: /*
                    217:  * mqtt_msgRealloc() Reallocate MQTT message buffer
                    218:  *
                    219:  * @msg = MQTT message
                    220:  * @len = new length
                    221:  * return: -1 error or >-1 old buffer length
                    222:  */
                    223: inline int mqtt_msgRealloc(mqtt_msg_t * __restrict msg, unsigned short len);
                    224: 
                    225: /*
1.1.1.1.2.1  misho     226:  * mqtt_expandTopic() - Expanding topic to regular expression
                    227:  *
                    228:  * @csInput = Input topic
                    229:  * @psRegEx = Output to regular expression
                    230:  * @regexLen = Length of psRegEx
                    231:  * @BOL = Begin of Line, if =0 not added
                    232:  * @EOL = End of Line, if =0 not appended
                    233:  * return: -1 error, 0 nothing expanded or >0 expanded bytes
                    234:  */
                    235: int mqtt_expandTopic(const char *csInput, char * __restrict psRegEx, int regexLen, 
                    236:                unsigned char BOL, unsigned char EOL);
                    237: 
                    238: /*
1.1       misho     239:  * mqtt_encodeLen() Encode number to MQTT length field
                    240:  *
                    241:  * @num = number for encode
                    242:  * return: -1 error or >-1 length
                    243:  */
                    244: inline unsigned int mqtt_encodeLen(unsigned int num);
                    245: /*
                    246:  * mqtt_decodeLen() Decode length from MQTT packet
                    247:  *
                    248:  * @len = length from MQTT header
                    249:  * @n = sizeof bytes, if !=NULL
                    250:  * return: -1 error, >-1 length of message
                    251:  */
                    252: inline unsigned int mqtt_decodeLen(void * __restrict len, int * __restrict n);
                    253: /*
                    254:  * mqtt_sizeLen Return sizeof len field
                    255:  *
                    256:  * @len = length
                    257:  * return: -1 error, >-1 sizeof len in bytes
                    258:  */
                    259: inline char mqtt_sizeLen(unsigned int len);
                    260: /*
                    261:  * mqtt_str2sub Create MQTT subscribe variable from string(s)
                    262:  *
                    263:  * @csStr = strings
                    264:  * @strnum = number of strings elements
                    265:  * @qoses = QoS elements applied to subscribe variable, 
                    266:  *             count of elements must be equal with csStr elements
                    267:  * return: NULL error or != subscribe variables array, must be free after use with mqtt_freeSub()
                    268:  */
                    269: inline mqtt_subscr_t *mqtt_str2sub(const char **csStr, unsigned short strnum, unsigned char *qoses);
                    270: /*
                    271:  * mqtt_subFree() Free array from subscribe variables
                    272:  *
                    273:  * @subs = Subscribe variables
                    274:  * return: none
                    275:  */
                    276: inline void mqtt_subFree(mqtt_subscr_t ** __restrict subs);
                    277: /*
                    278:  * mqtt_subAlloc() Create array from subscribe variables
                    279:  *
                    280:  * @num = Number of elements
                    281:  * return: NULL error or subscribe array, after use must call mqtt_subFree()
                    282:  */
                    283: inline mqtt_subscr_t *mqtt_subAlloc(unsigned short num);
                    284: /*
                    285:  * mqtt_subRealloc() Reallocate array from subscribe variables
                    286:  *
                    287:  * @subs = Subscribe array
                    288:  * @num = Number of elements
                    289:  * return: NULL error or subscribe array, after use must call mqtt_subFree()
                    290:  */
                    291: inline mqtt_subscr_t *mqtt_subRealloc(mqtt_subscr_t * __restrict subs, unsigned short num);
                    292: 
                    293: 
                    294: /*** SENDER FUNCTIONS ***/
                    295: 
                    296: /*
                    297:  * mqtt_msgCONNECT() Create CONNECT message
                    298:  *
                    299:  * @buf = Message buffer
                    300:  * @csConnID = ConnectID
                    301:  * @kasec = Keep alive timeout
                    302:  * @csUser = Username if !=NULL
                    303:  * @csPass = Password for Username, only if csUser is set
                    304:  * @csWillTopic = Will Topic if !=NULL Will Flags set into message
                    305:  * @csWillMessage = Will Message, may be NULL
                    306:  * @ClrSess = Clear Session subscriptions after disconnect
                    307:  * @WillQOS = Will QOS if csWillTopic is set
                    308:  * @WillRetain = Will Retain Will Message if csWillTopic is set
                    309:  * return: -1 error or >-1 message size for send
                    310:  */
                    311: int mqtt_msgCONNECT(mqtt_msg_t * __restrict buf, const char *csConnID, 
                    312:                unsigned short kasec, const char *csUser, const char *csPass, 
                    313:                const char *csWillTopic, const char *csWillMessage, 
                    314:                unsigned char ClrSess, unsigned char WillQOS, unsigned char WillRetain);
                    315: /*
                    316:  * mqtt_msgCONNACK() Create CONNACK message
                    317:  *
                    318:  * @buf = Message buffer
                    319:  * @retcode = Return code
                    320:  * return: -1 error or >-1 message size for send
                    321:  */
                    322: int mqtt_msgCONNACK(mqtt_msg_t * __restrict buf, unsigned char retcode);
                    323: /*
                    324:  * mqtt_msgDISCONNECT() Create DISCONNECT message
                    325:  *
                    326:  * @buf = Message buffer
                    327:  * return: -1 error or >-1 message size for send
                    328:  */
                    329: int mqtt_msgDISCONNECT(mqtt_msg_t * __restrict buf);
                    330: /*
                    331:  * mqtt_msgPINGREQ() Create PINGREQ message
                    332:  *
                    333:  * @buf = Message buffer
                    334:  * return: -1 error or >-1 message size for send
                    335:  */
                    336: int mqtt_msgPINGREQ(mqtt_msg_t * __restrict buf);
                    337: /*
                    338:  * mqtt_msgPINGRESP() Create PINGRESP message
                    339:  *
                    340:  * @buf = Message buffer
                    341:  * return: -1 error or >-1 message size for send
                    342:  */
                    343: int mqtt_msgPINGRESP(mqtt_msg_t * __restrict buf);
                    344: 
                    345: /*
                    346:  * mqtt_msgPUBLISH() Create PUBLISH message
                    347:  *
                    348:  * @buf = Message buffer
                    349:  * @csTopic = Publish topic
                    350:  * @msgID = MessageID >0, if QOS != MQTT_QOS_ONCE
                    351:  * @Dup = Duplicate message
                    352:  * @QOS = QoS
                    353:  * @Retain = Retain message
                    354:  * @pData = Publish data into topic
                    355:  * @datlen = Publish data length
                    356:  * return: -1 error or >-1 message size for send
                    357:  */
                    358: int mqtt_msgPUBLISH(mqtt_msg_t * __restrict buf, const char *csTopic, 
                    359:                unsigned short msgID, unsigned char Dup, unsigned char QOS, 
                    360:                unsigned char Retain, const void *pData, int datlen);
                    361: /*
                    362:  * mqtt_msgPUBACK() Create PUBACK message
                    363:  *
                    364:  * @buf = Message buffer
                    365:  * @msgID = MessageID
                    366:  * return: -1 error or >-1 message size for send
                    367:  */
                    368: inline int mqtt_msgPUBACK(mqtt_msg_t * __restrict buf, unsigned short msgID);
                    369: /*
                    370:  * mqtt_msgPUBREC() Create PUBREC message
                    371:  *
                    372:  * @buf = Message buffer
                    373:  * @msgID = MessageID
                    374:  * return: -1 error or >-1 message size for send
                    375:  */
                    376: inline int mqtt_msgPUBREC(mqtt_msg_t * __restrict buf, unsigned short msgID);
                    377: /*
                    378:  * mqtt_msgPUBREL() Create PUBREL message
                    379:  *
                    380:  * @buf = Message buffer
                    381:  * @msgID = MessageID
                    382:  * return: -1 error or >-1 message size for send
                    383:  */
                    384: inline int mqtt_msgPUBREL(mqtt_msg_t * __restrict buf, unsigned short msgID);
                    385: /*
                    386:  * mqtt_msgPUBCOMP() Create PUBCOMP message
                    387:  *
                    388:  * @buf = Message buffer
                    389:  * @msgID = MessageID
                    390:  * return: -1 error or >-1 message size for send
                    391:  */
                    392: inline int mqtt_msgPUBCOMP(mqtt_msg_t * __restrict buf, unsigned short msgID);
                    393: 
                    394: /*
                    395:  * mqtt_msgSUBSCRIBE() Create SUBSCRIBE message
                    396:  *
                    397:  * @buf = Message buffer
                    398:  * @Topics = MQTT subscription topics
                    399:  * @msgID = MessageID
                    400:  * @Dup = Duplicate message
                    401:  * @QOS = QoS
                    402:  * return: -1 error or >-1 message size for send
                    403:  */
                    404: int
                    405: mqtt_msgSUBSCRIBE(mqtt_msg_t * __restrict buf, mqtt_subscr_t * __restrict Topics, 
                    406:                unsigned short msgID, unsigned char Dup, unsigned char QOS);
                    407: /*
                    408:  * mqtt_msgSUBACK() Create SUBACK message
                    409:  *
                    410:  * @buf = Message buffer
                    411:  * @Topics = MQTT subscription topics
                    412:  * @msgID = MessageID
                    413:  * return: -1 error or >-1 message size for send
                    414:  */
                    415: int mqtt_msgSUBACK(mqtt_msg_t * __restrict buf, mqtt_subscr_t * __restrict Topics, 
                    416:                unsigned short msgID);
                    417: /*
                    418:  * mqtt_msgUNSUBSCRIBE() Create UNSUBSCRIBE message
                    419:  *
                    420:  * @buf = Message buffer
                    421:  * @Topics = MQTT subscription topics
                    422:  * @msgID = MessageID
                    423:  * @Dup = Duplicate message
                    424:  * @QOS = QoS
                    425:  * return: -1 error or >-1 message size for send
                    426:  */
                    427: int
                    428: mqtt_msgUNSUBSCRIBE(mqtt_msg_t * __restrict buf, mqtt_subscr_t * __restrict Topics, 
                    429:                unsigned short msgID, unsigned char Dup, unsigned char QOS);
                    430: /*
                    431:  * mqtt_msgUNSUBACK() Create UNSUBACK message
                    432:  *
                    433:  * @buf = Message buffer
                    434:  * @msgID = MessageID
                    435:  * return: -1 error or >-1 message size for send
                    436:  */
                    437: int mqtt_msgUNSUBACK(mqtt_msg_t * __restrict buf, unsigned short msgID);
                    438: 
                    439: 
                    440: /*** RECEIVER FUNCTIONS ***/
                    441: 
                    442: /*
                    443:  * mqtt_readCONNECT() Read elements from CONNECT message
                    444:  *
                    445:  * @buf = Message buffer
                    446:  * @kasec = Keep Alive in seconds for current connection
                    447:  * @psConnID = ConnectID
                    448:  * @connLen = ConnectID length
                    449:  * @psUser = Username if !=NULL
                    450:  * @userLen = Username length
                    451:  * @psPass = Password for Username, only if csUser is set
                    452:  * @passLen = Password length
                    453:  * @psWillTopic = Will Topic if !=NULL Will Flags set into message and must be free()
                    454:  * @psWillMessage = Will Message, may be NULL if !NULL must be free() after use!
                    455:  * return: .reserved == 1 is error or == 0 connection flags & msg ok
                    456:  */
                    457: mqtthdr_connack_t mqtt_readCONNECT(mqtt_msg_t * __restrict buf, unsigned short *kasec, 
                    458:                char * __restrict psConnID, int connLen, 
                    459:                char * __restrict psUser, int userLen, char * __restrict psPass, int passLen,  
                    460:                char ** __restrict psWillTopic, char ** __restrict psWillMessage);
                    461: /*
                    462:  * mqtt_readCONNACK() Read CONNACK message
                    463:  *
                    464:  * @buf = Message buffer
                    465:  * return: -1 error or >-1 CONNECT message return code
                    466:  */
                    467: unsigned char mqtt_readCONNACK(mqtt_msg_t * __restrict buf);
                    468: /*
                    469:  * mqtt_readDISCONNECT() Read DISCONNECT message
                    470:  *
                    471:  * @buf = Message buffer
                    472:  * return: -1 error, 0 ok, >0 undefined result
                    473:  */
                    474: int mqtt_readDISCONNECT(mqtt_msg_t * __restrict buf);
                    475: /*
                    476:  * mqtt_readPINGREQ() Read PINGREQ message
                    477:  *
                    478:  * @buf = Message buffer
                    479:  * return: -1 error, 0 ok, >0 undefined result
                    480:  */
                    481: int mqtt_readPINGREQ(mqtt_msg_t * __restrict buf);
                    482: /*
                    483:  * mqtt_readPINGRESP() Read PINGRESP message
                    484:  *
                    485:  * @buf = Message buffer
                    486:  * return: -1 error, 0 ok, >0 undefined result
                    487:  */
                    488: int mqtt_readPINGRESP(mqtt_msg_t * __restrict buf);
                    489: 
                    490: /*
                    491:  * mqtt_readPUBLISH() Read PUBLISH message
                    492:  *
                    493:  * @buf = Message buffer
                    494:  * @psTopic = Topic
                    495:  * @topicLen = Topic length
                    496:  * @msgID = MessageID
                    497:  * @pData = Data buffer
                    498:  * @datLen = Data buffer length, if *datLen == 0 allocate memory for pData
                    499:  * return: NULL error or !=NULL MQTT fixed header
                    500:  */
                    501: struct mqtthdr *mqtt_readPUBLISH(mqtt_msg_t * __restrict buf, char * __restrict psTopic, 
                    502:                int topicLen, unsigned short *msgID, void * __restrict pData, int *datLen);
                    503: /*
                    504:  * mqtt_readPUBACK() Read PUBACK message
                    505:  *
                    506:  * @buf = Message buffer
                    507:  * return: -1 error or MessageID
                    508:  */
1.1.1.1.2.2  misho     509: unsigned short mqtt_readPUBACK(mqtt_msg_t * __restrict buf);
1.1       misho     510: /*
                    511:  * mqtt_readPUBREC() Read PUBREC message
                    512:  *
                    513:  * @buf = Message buffer
                    514:  * return: -1 error or MessageID
                    515:  */
1.1.1.1.2.2  misho     516: unsigned short mqtt_readPUBREC(mqtt_msg_t * __restrict buf);
1.1       misho     517: /*
                    518:  * mqtt_readPUBREL() Read PUBREL message
                    519:  *
                    520:  * @buf = Message buffer
                    521:  * return: -1 error or MessageID
                    522:  */
1.1.1.1.2.2  misho     523: unsigned short mqtt_readPUBREL(mqtt_msg_t * __restrict buf);
1.1       misho     524: /*
                    525:  * mqtt_readPUBCOMP() Read PUBCOMP message
                    526:  *
                    527:  * @buf = Message buffer
                    528:  * return: -1 error or MessageID
                    529:  */
1.1.1.1.2.2  misho     530: unsigned short mqtt_readPUBCOMP(mqtt_msg_t * __restrict buf);
1.1       misho     531: 
                    532: /*
                    533:  * mqtt_readSUBSCRIBE() Read SUBSCRIBE message
                    534:  *
                    535:  * @buf = Message buffer
                    536:  * @msgID = MessageID
                    537:  * @subscr = Subscriptions, must be free after use with mqtt_subFree()
                    538:  * return: NULL error or !=NULL MQTT fixed header
                    539:  */
                    540: struct mqtthdr *mqtt_readSUBSCRIBE(mqtt_msg_t * __restrict buf, unsigned short *msgID, 
                    541:                mqtt_subscr_t **subscr);
                    542: /*
                    543:  * mqtt_readSUBACK() Read SUBACK message
                    544:  *
                    545:  * @buf = Message buffer
                    546:  * @msgID = MessageID
                    547:  * @subqos = Subscribes QoS, must be free after use with free()
                    548:  * return: -1 error or >-1 readed subscribes QoS elements
                    549:  */
1.1.1.1.2.2  misho     550: int mqtt_readSUBACK(mqtt_msg_t * __restrict buf, unsigned short *msgID, unsigned char **subqos);
1.1       misho     551: /*
                    552:  * mqtt_readUNSUBSCRIBE() Read UNSUBSCRIBE message
                    553:  *
                    554:  * @buf = Message buffer
                    555:  * @msgID = MessageID
                    556:  * @subscr = Subscriptions, must be free after use with mqtt_subFree()
                    557:  * return: NULL error or !=NULL MQTT fixed header
                    558:  */
                    559: struct mqtthdr *mqtt_readUNSUBSCRIBE(mqtt_msg_t * __restrict buf, unsigned short *msgID, 
                    560:                mqtt_subscr_t **subscr);
                    561: /*
                    562:  * mqtt_readUNSUBACK() Read UNSUBACK message
                    563:  *
                    564:  * @buf = Message buffer
                    565:  * return: -1 error or MessageID
                    566:  */
1.1.1.1.2.2  misho     567: unsigned short mqtt_readUNSUBACK(mqtt_msg_t * __restrict buf);
1.1       misho     568: 
                    569: 
                    570: #endif

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