File:  [ELWIX - Embedded LightWeight unIX -] / libaitmqtt / inc / aitmqtt.h
Revision 1.3: download - view: text, annotated - select for diffs - revision graph
Thu May 30 09:18:33 2013 UTC (11 years ago) by misho
Branches: MAIN
CVS tags: mqtt1_8, mqtt1_7, MQTT1_7, MQTT1_6, HEAD
version 1.6

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

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