File:  [ELWIX - Embedded LightWeight unIX -] / libaitmqtt / inc / aitmqtt.h
Revision 1.1.1.1.2.9: download - view: text, annotated - select for diffs - revision graph
Thu Apr 26 12:33:14 2012 UTC (12 years, 2 months ago) by misho
Branches: mqtt1_1
Diff to: branchpoint 1.1.1.1: preferred, unified
add new defines
remove some reallocs

    1: /*************************************************************************
    2: * (C) 2011 AITNET ltd - Sofia/Bulgaria - <misho@aitbg.com>
    3: *  by Michael Pounov <misho@openbsd-bg.org>
    4: *
    5: * $Author: misho $
    6: * $Id: aitmqtt.h,v 1.1.1.1.2.9 2012/04/26 12:33:14 misho Exp $
    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, 2012
   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: 
   50: #define MAX_CONNID		24
   51: #define MAX_CRED		13
   52: #define MQTTMSG_MAX		65529
   53: #define MQTT_DATA_MAX		268435455
   54: 
   55: #define MQTT_PROTO_VER		3
   56: #define MQTT_KEEPALIVE		10
   57: #define MQTT_DEFAULT_MSGID	0xDEBA
   58: 
   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_QOS_DENY		0	/* Not granted QoS for SUBACK */
  108: #define MQTT_QOS_PASS		2	/* Granted QoS for SUBACK */
  109: 
  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);
  227: 
  228: /*
  229:  * mqtt_expandTopic() - Expanding topic to regular expression
  230:  *
  231:  * @csInput = Input topic
  232:  * @psRegEx = Output to regular expression
  233:  * @regexLen = Length of psRegEx
  234:  * @BOL = Begin of Line, if =0 not added
  235:  * @EOL = End of Line, if =0 not appended
  236:  * return: -1 error, 0 nothing expanded or >0 expanded bytes
  237:  */
  238: int mqtt_expandTopic(const char *csInput, char * __restrict psRegEx, int regexLen, 
  239: 		unsigned char BOL, unsigned char EOL);
  240: /*
  241:  * mqtt_sqlTopic() - Expanding topic to SQL search string
  242:  *
  243:  * @csInput = Input topic
  244:  * @psSQL = Output to SQL search string
  245:  * @sqlLen = Length of psSQL
  246:  * return: -1 error, 0 changed bytes
  247:  */
  248: int mqtt_sqlTopic(const char *csInput, char * __restrict psSQL, int sqlLen);
  249: 
  250: /*
  251:  * mqtt_encodeLen() Encode number to MQTT length field
  252:  *
  253:  * @num = number for encode
  254:  * return: -1 error or >-1 length
  255:  */
  256: inline unsigned int mqtt_encodeLen(unsigned int num);
  257: /*
  258:  * mqtt_decodeLen() Decode length from MQTT packet
  259:  *
  260:  * @len = length from MQTT header
  261:  * @n = sizeof bytes, if !=NULL
  262:  * return: -1 error, >-1 length of message
  263:  */
  264: inline unsigned int mqtt_decodeLen(void * __restrict len, int * __restrict n);
  265: /*
  266:  * mqtt_sizeLen Return sizeof len field
  267:  *
  268:  * @len = length
  269:  * return: -1 error, >-1 sizeof len in bytes
  270:  */
  271: inline char mqtt_sizeLen(unsigned int len);
  272: /*
  273:  * mqtt_str2sub Create MQTT subscribe variable from string(s)
  274:  *
  275:  * @csStr = strings
  276:  * @strnum = number of strings elements
  277:  * @qoses = QoS elements applied to subscribe variable, 
  278:  * 		count of elements must be equal with csStr elements
  279:  * return: NULL error or != subscribe variables array, must be free after use with mqtt_freeSub()
  280:  */
  281: inline mqtt_subscr_t *mqtt_str2sub(const char **csStr, unsigned short strnum, unsigned char *qoses);
  282: /*
  283:  * mqtt_subFree() Free array from subscribe variables
  284:  *
  285:  * @subs = Subscribe variables
  286:  * return: none
  287:  */
  288: inline void mqtt_subFree(mqtt_subscr_t ** __restrict subs);
  289: /*
  290:  * mqtt_subAlloc() Create array from subscribe variables
  291:  *
  292:  * @num = Number of elements
  293:  * return: NULL error or subscribe array, after use must call mqtt_subFree()
  294:  */
  295: inline mqtt_subscr_t *mqtt_subAlloc(unsigned short num);
  296: /*
  297:  * mqtt_subRealloc() Reallocate array from subscribe variables
  298:  *
  299:  * @subs = Subscribe array
  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_subRealloc(mqtt_subscr_t * __restrict subs, unsigned short num);
  304: 
  305: 
  306: /*** SENDER FUNCTIONS ***/
  307: 
  308: /*
  309:  * mqtt_msgCONNECT() Create CONNECT message
  310:  *
  311:  * @buf = Message buffer
  312:  * @csConnID = ConnectID
  313:  * @kasec = Keep alive timeout
  314:  * @csUser = Username if !=NULL
  315:  * @csPass = Password for Username, only if csUser is set
  316:  * @csWillTopic = Will Topic if !=NULL Will Flags set into message
  317:  * @csWillMessage = Will Message, may be NULL
  318:  * @ClrSess = Clear Session subscriptions after disconnect
  319:  * @WillQOS = Will QOS if csWillTopic is set
  320:  * @WillRetain = Will Retain Will Message if csWillTopic is set
  321:  * return: -1 error or >-1 message size for send
  322:  */
  323: int mqtt_msgCONNECT(mqtt_msg_t * __restrict buf, const char *csConnID, 
  324: 		unsigned short kasec, const char *csUser, const char *csPass, 
  325: 		const char *csWillTopic, const char *csWillMessage, 
  326: 		unsigned char ClrSess, unsigned char WillQOS, unsigned char WillRetain);
  327: /*
  328:  * mqtt_msgCONNACK() Create CONNACK message
  329:  *
  330:  * @buf = Message buffer
  331:  * @retcode = Return code
  332:  * return: -1 error or >-1 message size for send
  333:  */
  334: int mqtt_msgCONNACK(mqtt_msg_t * __restrict buf, unsigned char retcode);
  335: /*
  336:  * mqtt_msgDISCONNECT() Create DISCONNECT message
  337:  *
  338:  * @buf = Message buffer
  339:  * return: -1 error or >-1 message size for send
  340:  */
  341: int mqtt_msgDISCONNECT(mqtt_msg_t * __restrict buf);
  342: /*
  343:  * mqtt_msgPINGREQ() Create PINGREQ message
  344:  *
  345:  * @buf = Message buffer
  346:  * return: -1 error or >-1 message size for send
  347:  */
  348: int mqtt_msgPINGREQ(mqtt_msg_t * __restrict buf);
  349: /*
  350:  * mqtt_msgPINGRESP() Create PINGRESP message
  351:  *
  352:  * @buf = Message buffer
  353:  * return: -1 error or >-1 message size for send
  354:  */
  355: int mqtt_msgPINGRESP(mqtt_msg_t * __restrict buf);
  356: 
  357: /*
  358:  * mqtt_msgPUBLISH() Create PUBLISH message
  359:  *
  360:  * @buf = Message buffer
  361:  * @csTopic = Publish topic
  362:  * @msgID = MessageID >0, if QOS != MQTT_QOS_ONCE
  363:  * @Dup = Duplicate message
  364:  * @QOS = QoS
  365:  * @Retain = Retain message
  366:  * @pData = Publish data into topic
  367:  * @datlen = Publish data length
  368:  * return: -1 error or >-1 message size for send
  369:  */
  370: int mqtt_msgPUBLISH(mqtt_msg_t * __restrict buf, const char *csTopic, 
  371: 		unsigned short msgID, unsigned char Dup, unsigned char QOS, 
  372: 		unsigned char Retain, const void *pData, int datlen);
  373: /*
  374:  * mqtt_msgPUBACK() Create PUBACK message
  375:  *
  376:  * @buf = Message buffer
  377:  * @msgID = MessageID
  378:  * return: -1 error or >-1 message size for send
  379:  */
  380: inline int mqtt_msgPUBACK(mqtt_msg_t * __restrict buf, unsigned short msgID);
  381: /*
  382:  * mqtt_msgPUBREC() Create PUBREC message
  383:  *
  384:  * @buf = Message buffer
  385:  * @msgID = MessageID
  386:  * return: -1 error or >-1 message size for send
  387:  */
  388: inline int mqtt_msgPUBREC(mqtt_msg_t * __restrict buf, unsigned short msgID);
  389: /*
  390:  * mqtt_msgPUBREL() Create PUBREL message
  391:  *
  392:  * @buf = Message buffer
  393:  * @msgID = MessageID
  394:  * return: -1 error or >-1 message size for send
  395:  */
  396: inline int mqtt_msgPUBREL(mqtt_msg_t * __restrict buf, unsigned short msgID);
  397: /*
  398:  * mqtt_msgPUBCOMP() Create PUBCOMP message
  399:  *
  400:  * @buf = Message buffer
  401:  * @msgID = MessageID
  402:  * return: -1 error or >-1 message size for send
  403:  */
  404: inline int mqtt_msgPUBCOMP(mqtt_msg_t * __restrict buf, unsigned short msgID);
  405: 
  406: /*
  407:  * mqtt_msgSUBSCRIBE() Create SUBSCRIBE message
  408:  *
  409:  * @buf = Message buffer
  410:  * @Topics = MQTT subscription topics
  411:  * @msgID = MessageID
  412:  * @Dup = Duplicate message
  413:  * @QOS = QoS
  414:  * return: -1 error or >-1 message size for send
  415:  */
  416: int
  417: mqtt_msgSUBSCRIBE(mqtt_msg_t * __restrict buf, mqtt_subscr_t * __restrict Topics, 
  418: 		unsigned short msgID, unsigned char Dup, unsigned char QOS);
  419: /*
  420:  * mqtt_msgSUBACK() Create SUBACK message
  421:  *
  422:  * @buf = Message buffer
  423:  * @Topics = MQTT subscription topics
  424:  * @msgID = MessageID
  425:  * return: -1 error or >-1 message size for send
  426:  */
  427: int mqtt_msgSUBACK(mqtt_msg_t * __restrict buf, mqtt_subscr_t * __restrict Topics, 
  428: 		unsigned short msgID);
  429: /*
  430:  * mqtt_msgUNSUBSCRIBE() Create UNSUBSCRIBE message
  431:  *
  432:  * @buf = Message buffer
  433:  * @Topics = MQTT subscription topics
  434:  * @msgID = MessageID
  435:  * @Dup = Duplicate message
  436:  * @QOS = QoS
  437:  * return: -1 error or >-1 message size for send
  438:  */
  439: int
  440: mqtt_msgUNSUBSCRIBE(mqtt_msg_t * __restrict buf, mqtt_subscr_t * __restrict Topics, 
  441: 		unsigned short msgID, unsigned char Dup, unsigned char QOS);
  442: /*
  443:  * mqtt_msgUNSUBACK() Create UNSUBACK message
  444:  *
  445:  * @buf = Message buffer
  446:  * @msgID = MessageID
  447:  * return: -1 error or >-1 message size for send
  448:  */
  449: int mqtt_msgUNSUBACK(mqtt_msg_t * __restrict buf, unsigned short msgID);
  450: 
  451: 
  452: /*** RECEIVER FUNCTIONS ***/
  453: 
  454: /*
  455:  * mqtt_readCONNECT() Read elements from CONNECT message
  456:  *
  457:  * @buf = Message buffer
  458:  * @kasec = Keep Alive in seconds for current connection
  459:  * @psConnID = ConnectID
  460:  * @connLen = ConnectID length
  461:  * @psUser = Username if !=NULL
  462:  * @userLen = Username length
  463:  * @psPass = Password for Username, only if csUser is set
  464:  * @passLen = Password length
  465:  * @psWillTopic = Will Topic if !=NULL Will Flags set into message and must be free()
  466:  * @psWillMessage = Will Message, may be NULL if !NULL must be free() after use!
  467:  * return: .reserved == 1 is error or == 0 connection flags & msg ok
  468:  */
  469: mqtthdr_connack_t mqtt_readCONNECT(mqtt_msg_t * __restrict buf, unsigned short *kasec, 
  470: 		char * __restrict psConnID, int connLen, 
  471: 		char * __restrict psUser, int userLen, char * __restrict psPass, int passLen,  
  472: 		char ** __restrict psWillTopic, char ** __restrict psWillMessage);
  473: /*
  474:  * mqtt_readCONNACK() Read CONNACK message
  475:  *
  476:  * @buf = Message buffer
  477:  * return: -1 error or >-1 CONNECT message return code
  478:  */
  479: unsigned char mqtt_readCONNACK(mqtt_msg_t * __restrict buf);
  480: /*
  481:  * mqtt_readDISCONNECT() Read DISCONNECT message
  482:  *
  483:  * @buf = Message buffer
  484:  * return: -1 error, 0 ok, >0 undefined result
  485:  */
  486: int mqtt_readDISCONNECT(mqtt_msg_t * __restrict buf);
  487: /*
  488:  * mqtt_readPINGREQ() Read PINGREQ message
  489:  *
  490:  * @buf = Message buffer
  491:  * return: -1 error, 0 ok, >0 undefined result
  492:  */
  493: int mqtt_readPINGREQ(mqtt_msg_t * __restrict buf);
  494: /*
  495:  * mqtt_readPINGRESP() Read PINGRESP message
  496:  *
  497:  * @buf = Message buffer
  498:  * return: -1 error, 0 ok, >0 undefined result
  499:  */
  500: int mqtt_readPINGRESP(mqtt_msg_t * __restrict buf);
  501: 
  502: /*
  503:  * mqtt_readPUBLISH() Read PUBLISH message
  504:  *
  505:  * @buf = Message buffer
  506:  * @psTopic = Topic
  507:  * @topicLen = Topic length
  508:  * @msgID = MessageID
  509:  * @pData = Data buffer
  510:  * @datLen = Data buffer length, if *datLen == 0 allocate memory for pData
  511:  * return: NULL error or !=NULL MQTT fixed header
  512:  */
  513: struct mqtthdr *mqtt_readPUBLISH(mqtt_msg_t * __restrict buf, char * __restrict psTopic, 
  514: 		int topicLen, unsigned short *msgID, void * __restrict pData, int *datLen);
  515: /*
  516:  * mqtt_readPUBACK() Read PUBACK message
  517:  *
  518:  * @buf = Message buffer
  519:  * return: -1 error or MessageID
  520:  */
  521: unsigned short mqtt_readPUBACK(mqtt_msg_t * __restrict buf);
  522: /*
  523:  * mqtt_readPUBREC() Read PUBREC message
  524:  *
  525:  * @buf = Message buffer
  526:  * return: -1 error or MessageID
  527:  */
  528: unsigned short mqtt_readPUBREC(mqtt_msg_t * __restrict buf);
  529: /*
  530:  * mqtt_readPUBREL() Read PUBREL message
  531:  *
  532:  * @buf = Message buffer
  533:  * return: -1 error or MessageID
  534:  */
  535: unsigned short mqtt_readPUBREL(mqtt_msg_t * __restrict buf);
  536: /*
  537:  * mqtt_readPUBCOMP() Read PUBCOMP message
  538:  *
  539:  * @buf = Message buffer
  540:  * return: -1 error or MessageID
  541:  */
  542: unsigned short mqtt_readPUBCOMP(mqtt_msg_t * __restrict buf);
  543: 
  544: /*
  545:  * mqtt_readSUBSCRIBE() Read SUBSCRIBE message
  546:  *
  547:  * @buf = Message buffer
  548:  * @msgID = MessageID
  549:  * @subscr = Subscriptions, must be free after use with mqtt_subFree()
  550:  * return: -1 error or >-1 elements into subscr
  551:  */
  552: int mqtt_readSUBSCRIBE(mqtt_msg_t * __restrict buf, unsigned short *msgID, 
  553: 		mqtt_subscr_t **subscr);
  554: /*
  555:  * mqtt_readSUBACK() Read SUBACK message
  556:  *
  557:  * @buf = Message buffer
  558:  * @msgID = MessageID
  559:  * @subqos = Subscribes QoS, must be free after use with free()
  560:  * return: -1 error or >-1 readed subscribes QoS elements
  561:  */
  562: int mqtt_readSUBACK(mqtt_msg_t * __restrict buf, unsigned short *msgID, unsigned char **subqos);
  563: /*
  564:  * mqtt_readUNSUBSCRIBE() Read UNSUBSCRIBE message
  565:  *
  566:  * @buf = Message buffer
  567:  * @msgID = MessageID
  568:  * @subscr = Subscriptions, must be free after use with mqtt_subFree()
  569:  * return: -1 error or >-1 elements into subscr
  570:  */
  571: int mqtt_readUNSUBSCRIBE(mqtt_msg_t * __restrict buf, unsigned short *msgID, 
  572: 		mqtt_subscr_t **subscr);
  573: /*
  574:  * mqtt_readUNSUBACK() Read UNSUBACK message
  575:  *
  576:  * @buf = Message buffer
  577:  * return: -1 error or MessageID
  578:  */
  579: unsigned short mqtt_readUNSUBACK(mqtt_msg_t * __restrict buf);
  580: 
  581: 
  582: #endif

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