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

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.15! misho       6: * $Id: aitmqtt.h,v 1.1.1.1.2.14 2012/04/27 16:02:16 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: 
1.1.1.1.2.7  misho      15: Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
1.1       misho      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: 
1.1.1.1.2.9  misho     107: #define MQTT_QOS_DENY          0       /* Not granted QoS for SUBACK */
                    108: #define MQTT_QOS_PASS          2       /* Granted QoS for SUBACK */
                    109: 
1.1       misho     110: #define MQTT_FLAG_RETAIN       1       /* This flag is only used on PUBLISH messages.
                    111: 
                    112:                                           When a client sends a PUBLISH to a server, 
                    113:                                           if the Retain flag is set (1), 
                    114:                                           the server should hold on to the message after it has been 
                    115:                                           delivered to the current subscribers.
                    116:                                           When a new subscription is established on a topic, 
                    117:                                           the last retained message on that topic should be sent to 
                    118:                                           the subscriber with the Retain flag set.
                    119:                                           If there is no retained message, nothing is sent
                    120:                                           This is useful where publishers send messages on a 
                    121:                                           "report by exception" basis, where it might be some time between messages. 
                    122:                                           This allows new subscribers to instantly receive data with the retained, 
                    123:                                           or Last Known Good, value.
                    124: 
                    125:                                           When a server sends a PUBLISH to a client as a result of 
                    126:                                           a subscription that already existed when the original PUBLISH arrived, 
                    127:                                           the Retain flag should not be set, regardless of the Retain flag 
                    128:                                           of the original PUBLISH. This allows a client to distinguish messages 
                    129:                                           that are being received because they were retained and those 
                    130:                                           that are being received "live".
                    131: 
                    132:                                           Retained messages should be kept over restarts of the server.
                    133:                                           A server may delete a retained message if it receives a message 
                    134:                                           with a zero-length payload and the Retain flag set on the same topic. */
                    135: 
                    136: /* VARIABLE HEADERS */
                    137: 
                    138: #define MQTT_RETCODE_ACCEPTED          0
                    139: #define MQTT_RETCODE_REFUSE_VER                1
                    140: #define MQTT_RETCODE_REFUSE_ID         2
                    141: #define MQTT_RETCODE_REFUSE_UNAVAIL    3
                    142: #define MQTT_RETCODE_REFUSE_USERPASS   4
                    143: #define MQTT_RETCODE_DENIED            5
                    144: 
                    145: 
                    146: /* MQTT Message buffer */
                    147: 
                    148: typedef struct {
                    149:        void            *msg_base;
                    150:        unsigned short  msg_len;
                    151: } mqtt_msg_t;
                    152: 
                    153: /* MQTT structures */
                    154: 
                    155: typedef union {
                    156:        struct {
                    157:                unsigned short  m:8,
                    158:                                l:8;
                    159:        } sb;
                    160:        unsigned short  val;
                    161: } mqtt_len_t;
                    162: 
                    163: typedef struct {
                    164:        unsigned char   sub_ret;
                    165:        mqtt_msg_t      sub_topic;
                    166:        mqtt_msg_t      sub_value;
                    167: } mqtt_subscr_t;
                    168: 
                    169: typedef struct {
                    170:        mqtt_len_t      var_sb;
                    171:        unsigned char   var_data[0];
                    172: } __packed mqtthdr_var_t;
                    173: #define MQTTHDR_VAR_SIZEOF(x)          (assert((x)), sizeof(mqtt_len_t) + ntohs((x)->var_sb.val))
                    174: 
                    175: typedef unsigned char mqtthdr_protover_t;
                    176: 
                    177: typedef union {
                    178:        struct {
                    179:                unsigned char   reserved:1,
                    180:                                clean_sess:1,
                    181:                                will_flg:1,
                    182:                                will_qos:2,
                    183:                                will_retain:1,
                    184:                                password:1,
                    185:                                username:1;
                    186:        };
                    187:        unsigned char           flags;
                    188: } __packed mqtthdr_connflgs_t;
                    189: 
                    190: typedef struct {
                    191:        unsigned char   reserved;
                    192:        unsigned char   retcode;
                    193: } __packed mqtthdr_connack_t;
                    194: 
                    195: 
                    196: // -------------------------------------------------------
                    197: // mqtt_GetErrno() Get error code of last operation
                    198: inline int mqtt_GetErrno();
                    199: // mqtt_GetError() Get error text of last operation
                    200: inline const char *mqtt_GetError();
                    201: // -------------------------------------------------------
                    202: 
                    203: 
                    204: /*
                    205:  * mqtt_msgAlloc() Allocate memory for MQTT Message
                    206:  *
                    207:  * @len = >0 Allocate buffer with length
                    208:  * return: NULL error or Message, after use must call mqtt_msgFree() with all!=0
                    209:  */
                    210: inline mqtt_msg_t *mqtt_msgAlloc(unsigned short len);
                    211: /*
                    212:  * mqtt_msgFree() Free MQTT message
                    213:  *
                    214:  * @msg = Message buffer
                    215:  * @all = !=0 Destroy entire message, if MQTT Message allocated with mqtt_msgAlloc()
                    216:  * return: none
                    217:  */
                    218: inline void mqtt_msgFree(mqtt_msg_t ** __restrict msg, int all);
                    219: /*
                    220:  * mqtt_msgRealloc() Reallocate MQTT message buffer
                    221:  *
                    222:  * @msg = MQTT message
                    223:  * @len = new length
                    224:  * return: -1 error or >-1 old buffer length
                    225:  */
                    226: inline int mqtt_msgRealloc(mqtt_msg_t * __restrict msg, unsigned short len);
1.1.1.1.2.15! misho     227: /*
        !           228:  * mqtt_msgDup() - Duplicate message buffer
        !           229:  *
        !           230:  * @msg = Message
        !           231:  * return: NULL error or !=NULL duplicated message, after use must call mqtt_msgFree() with all!=0
        !           232:  */
        !           233: inline mqtt_msg_t *mqtt_msgDup(mqtt_msg_t * __restrict msg);
1.1       misho     234: 
                    235: /*
1.1.1.1.2.1  misho     236:  * mqtt_expandTopic() - Expanding topic to regular expression
                    237:  *
                    238:  * @csInput = Input topic
                    239:  * @psRegEx = Output to regular expression
                    240:  * @regexLen = Length of psRegEx
                    241:  * @BOL = Begin of Line, if =0 not added
                    242:  * @EOL = End of Line, if =0 not appended
                    243:  * return: -1 error, 0 nothing expanded or >0 expanded bytes
                    244:  */
                    245: int mqtt_expandTopic(const char *csInput, char * __restrict psRegEx, int regexLen, 
                    246:                unsigned char BOL, unsigned char EOL);
1.1.1.1.2.6  misho     247: /*
                    248:  * mqtt_sqlTopic() - Expanding topic to SQL search string
                    249:  *
                    250:  * @csInput = Input topic
                    251:  * @psSQL = Output to SQL search string
                    252:  * @sqlLen = Length of psSQL
                    253:  * return: -1 error, 0 changed bytes
                    254:  */
                    255: int mqtt_sqlTopic(const char *csInput, char * __restrict psSQL, int sqlLen);
1.1.1.1.2.1  misho     256: 
                    257: /*
1.1       misho     258:  * mqtt_encodeLen() Encode number to MQTT length field
                    259:  *
                    260:  * @num = number for encode
                    261:  * return: -1 error or >-1 length
                    262:  */
                    263: inline unsigned int mqtt_encodeLen(unsigned int num);
                    264: /*
                    265:  * mqtt_decodeLen() Decode length from MQTT packet
                    266:  *
                    267:  * @len = length from MQTT header
                    268:  * @n = sizeof bytes, if !=NULL
                    269:  * return: -1 error, >-1 length of message
                    270:  */
                    271: inline unsigned int mqtt_decodeLen(void * __restrict len, int * __restrict n);
                    272: /*
                    273:  * mqtt_sizeLen Return sizeof len field
                    274:  *
                    275:  * @len = length
                    276:  * return: -1 error, >-1 sizeof len in bytes
                    277:  */
                    278: inline char mqtt_sizeLen(unsigned int len);
                    279: /*
1.1.1.1.2.10  misho     280:  * mqtt_str2subs Create MQTT subscribe variable from string(s)
1.1       misho     281:  *
1.1.1.1.2.10  misho     282:  * @csStr = null terminated string array
                    283:  * @strnum = copy at most number of strings elements
1.1       misho     284:  * @qoses = QoS elements applied to subscribe variable, 
                    285:  *             count of elements must be equal with csStr elements
                    286:  * return: NULL error or != subscribe variables array, must be free after use with mqtt_freeSub()
                    287:  */
1.1.1.1.2.10  misho     288: inline mqtt_subscr_t *mqtt_str2subs(const char **csStr, unsigned short strnum, 
                    289:                unsigned char *qoses);
1.1       misho     290: /*
                    291:  * mqtt_subFree() Free array from subscribe variables
                    292:  *
                    293:  * @subs = Subscribe variables
                    294:  * return: none
                    295:  */
                    296: inline void mqtt_subFree(mqtt_subscr_t ** __restrict subs);
                    297: /*
                    298:  * mqtt_subAlloc() Create array from subscribe variables
                    299:  *
                    300:  * @num = Number of elements
                    301:  * return: NULL error or subscribe array, after use must call mqtt_subFree()
                    302:  */
                    303: inline mqtt_subscr_t *mqtt_subAlloc(unsigned short num);
                    304: /*
                    305:  * mqtt_subRealloc() Reallocate array from subscribe variables
                    306:  *
                    307:  * @subs = Subscribe array
                    308:  * @num = Number of elements
                    309:  * return: NULL error or subscribe array, after use must call mqtt_subFree()
                    310:  */
1.1.1.1.2.11  misho     311: inline mqtt_subscr_t *mqtt_subRealloc(mqtt_subscr_t ** __restrict subs, unsigned short num);
1.1.1.1.2.14  misho     312: /*
                    313:  * mqtt_subCopy() - Copy subscription structure to another one
                    314:  *
                    315:  * @dst = destination subscription
                    316:  * @src = source subscription
                    317:  * return: =NULL error or !=NULL successful copied a structure
                    318:  */
                    319: inline mqtt_subscr_t *mqtt_subCopy(mqtt_subscr_t * __restrict dst, mqtt_subscr_t * __restrict src);
1.1       misho     320: 
                    321: 
                    322: /*** SENDER FUNCTIONS ***/
                    323: 
                    324: /*
                    325:  * mqtt_msgCONNECT() Create CONNECT message
                    326:  *
                    327:  * @buf = Message buffer
                    328:  * @csConnID = ConnectID
                    329:  * @kasec = Keep alive timeout
                    330:  * @csUser = Username if !=NULL
                    331:  * @csPass = Password for Username, only if csUser is set
                    332:  * @csWillTopic = Will Topic if !=NULL Will Flags set into message
                    333:  * @csWillMessage = Will Message, may be NULL
                    334:  * @ClrSess = Clear Session subscriptions after disconnect
                    335:  * @WillQOS = Will QOS if csWillTopic is set
                    336:  * @WillRetain = Will Retain Will Message if csWillTopic is set
                    337:  * return: -1 error or >-1 message size for send
                    338:  */
                    339: int mqtt_msgCONNECT(mqtt_msg_t * __restrict buf, const char *csConnID, 
                    340:                unsigned short kasec, const char *csUser, const char *csPass, 
                    341:                const char *csWillTopic, const char *csWillMessage, 
                    342:                unsigned char ClrSess, unsigned char WillQOS, unsigned char WillRetain);
                    343: /*
                    344:  * mqtt_msgCONNACK() Create CONNACK message
                    345:  *
                    346:  * @buf = Message buffer
                    347:  * @retcode = Return code
                    348:  * return: -1 error or >-1 message size for send
                    349:  */
                    350: int mqtt_msgCONNACK(mqtt_msg_t * __restrict buf, unsigned char retcode);
                    351: /*
                    352:  * mqtt_msgDISCONNECT() Create DISCONNECT message
                    353:  *
                    354:  * @buf = Message buffer
                    355:  * return: -1 error or >-1 message size for send
                    356:  */
                    357: int mqtt_msgDISCONNECT(mqtt_msg_t * __restrict buf);
                    358: /*
                    359:  * mqtt_msgPINGREQ() Create PINGREQ message
                    360:  *
                    361:  * @buf = Message buffer
                    362:  * return: -1 error or >-1 message size for send
                    363:  */
                    364: int mqtt_msgPINGREQ(mqtt_msg_t * __restrict buf);
                    365: /*
                    366:  * mqtt_msgPINGRESP() Create PINGRESP message
                    367:  *
                    368:  * @buf = Message buffer
                    369:  * return: -1 error or >-1 message size for send
                    370:  */
                    371: int mqtt_msgPINGRESP(mqtt_msg_t * __restrict buf);
                    372: 
                    373: /*
                    374:  * mqtt_msgPUBLISH() Create PUBLISH message
                    375:  *
                    376:  * @buf = Message buffer
                    377:  * @csTopic = Publish topic
                    378:  * @msgID = MessageID >0, if QOS != MQTT_QOS_ONCE
                    379:  * @Dup = Duplicate message
                    380:  * @QOS = QoS
                    381:  * @Retain = Retain message
                    382:  * @pData = Publish data into topic
                    383:  * @datlen = Publish data length
                    384:  * return: -1 error or >-1 message size for send
                    385:  */
                    386: int mqtt_msgPUBLISH(mqtt_msg_t * __restrict buf, const char *csTopic, 
                    387:                unsigned short msgID, unsigned char Dup, unsigned char QOS, 
                    388:                unsigned char Retain, const void *pData, int datlen);
                    389: /*
                    390:  * mqtt_msgPUBACK() Create PUBACK message
                    391:  *
                    392:  * @buf = Message buffer
                    393:  * @msgID = MessageID
                    394:  * return: -1 error or >-1 message size for send
                    395:  */
                    396: inline int mqtt_msgPUBACK(mqtt_msg_t * __restrict buf, unsigned short msgID);
                    397: /*
                    398:  * mqtt_msgPUBREC() Create PUBREC message
                    399:  *
                    400:  * @buf = Message buffer
                    401:  * @msgID = MessageID
                    402:  * return: -1 error or >-1 message size for send
                    403:  */
                    404: inline int mqtt_msgPUBREC(mqtt_msg_t * __restrict buf, unsigned short msgID);
                    405: /*
                    406:  * mqtt_msgPUBREL() Create PUBREL message
                    407:  *
                    408:  * @buf = Message buffer
                    409:  * @msgID = MessageID
                    410:  * return: -1 error or >-1 message size for send
                    411:  */
                    412: inline int mqtt_msgPUBREL(mqtt_msg_t * __restrict buf, unsigned short msgID);
                    413: /*
                    414:  * mqtt_msgPUBCOMP() Create PUBCOMP message
                    415:  *
                    416:  * @buf = Message buffer
                    417:  * @msgID = MessageID
                    418:  * return: -1 error or >-1 message size for send
                    419:  */
                    420: inline int mqtt_msgPUBCOMP(mqtt_msg_t * __restrict buf, unsigned short msgID);
                    421: 
                    422: /*
                    423:  * mqtt_msgSUBSCRIBE() Create SUBSCRIBE message
                    424:  *
                    425:  * @buf = Message buffer
                    426:  * @Topics = MQTT subscription topics
                    427:  * @msgID = MessageID
                    428:  * @Dup = Duplicate message
                    429:  * @QOS = QoS
                    430:  * return: -1 error or >-1 message size for send
                    431:  */
                    432: int
                    433: mqtt_msgSUBSCRIBE(mqtt_msg_t * __restrict buf, mqtt_subscr_t * __restrict Topics, 
                    434:                unsigned short msgID, unsigned char Dup, unsigned char QOS);
                    435: /*
                    436:  * mqtt_msgSUBACK() Create SUBACK message
                    437:  *
                    438:  * @buf = Message buffer
                    439:  * @Topics = MQTT subscription topics
                    440:  * @msgID = MessageID
                    441:  * return: -1 error or >-1 message size for send
                    442:  */
                    443: int mqtt_msgSUBACK(mqtt_msg_t * __restrict buf, mqtt_subscr_t * __restrict Topics, 
                    444:                unsigned short msgID);
                    445: /*
                    446:  * mqtt_msgUNSUBSCRIBE() Create UNSUBSCRIBE message
                    447:  *
                    448:  * @buf = Message buffer
                    449:  * @Topics = MQTT subscription topics
                    450:  * @msgID = MessageID
                    451:  * @Dup = Duplicate message
                    452:  * @QOS = QoS
                    453:  * return: -1 error or >-1 message size for send
                    454:  */
                    455: int
                    456: mqtt_msgUNSUBSCRIBE(mqtt_msg_t * __restrict buf, mqtt_subscr_t * __restrict Topics, 
                    457:                unsigned short msgID, unsigned char Dup, unsigned char QOS);
                    458: /*
                    459:  * mqtt_msgUNSUBACK() Create UNSUBACK message
                    460:  *
                    461:  * @buf = Message buffer
                    462:  * @msgID = MessageID
                    463:  * return: -1 error or >-1 message size for send
                    464:  */
                    465: int mqtt_msgUNSUBACK(mqtt_msg_t * __restrict buf, unsigned short msgID);
                    466: 
                    467: 
                    468: /*** RECEIVER FUNCTIONS ***/
                    469: 
                    470: /*
                    471:  * mqtt_readCONNECT() Read elements from CONNECT message
                    472:  *
                    473:  * @buf = Message buffer
                    474:  * @kasec = Keep Alive in seconds for current connection
                    475:  * @psConnID = ConnectID
                    476:  * @connLen = ConnectID length
                    477:  * @psUser = Username if !=NULL
                    478:  * @userLen = Username length
                    479:  * @psPass = Password for Username, only if csUser is set
                    480:  * @passLen = Password length
                    481:  * @psWillTopic = Will Topic if !=NULL Will Flags set into message and must be free()
                    482:  * @psWillMessage = Will Message, may be NULL if !NULL must be free() after use!
                    483:  * return: .reserved == 1 is error or == 0 connection flags & msg ok
                    484:  */
                    485: mqtthdr_connack_t mqtt_readCONNECT(mqtt_msg_t * __restrict buf, unsigned short *kasec, 
                    486:                char * __restrict psConnID, int connLen, 
                    487:                char * __restrict psUser, int userLen, char * __restrict psPass, int passLen,  
                    488:                char ** __restrict psWillTopic, char ** __restrict psWillMessage);
                    489: /*
                    490:  * mqtt_readCONNACK() Read CONNACK message
                    491:  *
                    492:  * @buf = Message buffer
                    493:  * return: -1 error or >-1 CONNECT message return code
                    494:  */
                    495: unsigned char mqtt_readCONNACK(mqtt_msg_t * __restrict buf);
                    496: /*
                    497:  * mqtt_readDISCONNECT() Read DISCONNECT message
                    498:  *
                    499:  * @buf = Message buffer
                    500:  * return: -1 error, 0 ok, >0 undefined result
                    501:  */
                    502: int mqtt_readDISCONNECT(mqtt_msg_t * __restrict buf);
                    503: /*
                    504:  * mqtt_readPINGREQ() Read PINGREQ message
                    505:  *
                    506:  * @buf = Message buffer
                    507:  * return: -1 error, 0 ok, >0 undefined result
                    508:  */
                    509: int mqtt_readPINGREQ(mqtt_msg_t * __restrict buf);
                    510: /*
                    511:  * mqtt_readPINGRESP() Read PINGRESP message
                    512:  *
                    513:  * @buf = Message buffer
                    514:  * return: -1 error, 0 ok, >0 undefined result
                    515:  */
                    516: int mqtt_readPINGRESP(mqtt_msg_t * __restrict buf);
                    517: 
                    518: /*
                    519:  * mqtt_readPUBLISH() Read PUBLISH message
                    520:  *
                    521:  * @buf = Message buffer
                    522:  * @psTopic = Topic
                    523:  * @topicLen = Topic length
                    524:  * @msgID = MessageID
1.1.1.1.2.15! misho     525:  * @pData = Data buffer, may be NULL
1.1.1.1.2.13  misho     526:  * return: -1 error or !=-1 allocated data buffer length
1.1       misho     527:  */
1.1.1.1.2.13  misho     528: int mqtt_readPUBLISH(mqtt_msg_t * __restrict buf, char * __restrict psTopic, 
                    529:                int topicLen, unsigned short *msgID, void ** __restrict pData);
1.1       misho     530: /*
                    531:  * mqtt_readPUBACK() Read PUBACK message
                    532:  *
                    533:  * @buf = Message buffer
                    534:  * return: -1 error or MessageID
                    535:  */
1.1.1.1.2.2  misho     536: unsigned short mqtt_readPUBACK(mqtt_msg_t * __restrict buf);
1.1       misho     537: /*
                    538:  * mqtt_readPUBREC() Read PUBREC message
                    539:  *
                    540:  * @buf = Message buffer
                    541:  * return: -1 error or MessageID
                    542:  */
1.1.1.1.2.2  misho     543: unsigned short mqtt_readPUBREC(mqtt_msg_t * __restrict buf);
1.1       misho     544: /*
                    545:  * mqtt_readPUBREL() Read PUBREL message
                    546:  *
                    547:  * @buf = Message buffer
                    548:  * return: -1 error or MessageID
                    549:  */
1.1.1.1.2.2  misho     550: unsigned short mqtt_readPUBREL(mqtt_msg_t * __restrict buf);
1.1       misho     551: /*
                    552:  * mqtt_readPUBCOMP() Read PUBCOMP message
                    553:  *
                    554:  * @buf = Message buffer
                    555:  * return: -1 error or MessageID
                    556:  */
1.1.1.1.2.2  misho     557: unsigned short mqtt_readPUBCOMP(mqtt_msg_t * __restrict buf);
1.1       misho     558: 
                    559: /*
                    560:  * mqtt_readSUBSCRIBE() Read SUBSCRIBE message
                    561:  *
                    562:  * @buf = Message buffer
                    563:  * @msgID = MessageID
                    564:  * @subscr = Subscriptions, must be free after use with mqtt_subFree()
1.1.1.1.2.8  misho     565:  * return: -1 error or >-1 elements into subscr
1.1       misho     566:  */
1.1.1.1.2.8  misho     567: int mqtt_readSUBSCRIBE(mqtt_msg_t * __restrict buf, unsigned short *msgID, 
1.1       misho     568:                mqtt_subscr_t **subscr);
                    569: /*
                    570:  * mqtt_readSUBACK() Read SUBACK message
                    571:  *
                    572:  * @buf = Message buffer
                    573:  * @msgID = MessageID
                    574:  * @subqos = Subscribes QoS, must be free after use with free()
                    575:  * return: -1 error or >-1 readed subscribes QoS elements
                    576:  */
1.1.1.1.2.2  misho     577: int mqtt_readSUBACK(mqtt_msg_t * __restrict buf, unsigned short *msgID, unsigned char **subqos);
1.1       misho     578: /*
                    579:  * mqtt_readUNSUBSCRIBE() Read UNSUBSCRIBE message
                    580:  *
                    581:  * @buf = Message buffer
                    582:  * @msgID = MessageID
                    583:  * @subscr = Subscriptions, must be free after use with mqtt_subFree()
1.1.1.1.2.8  misho     584:  * return: -1 error or >-1 elements into subscr
1.1       misho     585:  */
1.1.1.1.2.8  misho     586: int mqtt_readUNSUBSCRIBE(mqtt_msg_t * __restrict buf, unsigned short *msgID, 
1.1       misho     587:                mqtt_subscr_t **subscr);
                    588: /*
                    589:  * mqtt_readUNSUBACK() Read UNSUBACK message
                    590:  *
                    591:  * @buf = Message buffer
                    592:  * return: -1 error or MessageID
                    593:  */
1.1.1.1.2.2  misho     594: unsigned short mqtt_readUNSUBACK(mqtt_msg_t * __restrict buf);
1.1       misho     595: 
                    596: 
                    597: #endif

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