Annotation of libaitmqtt/src/conn.c, revision 1.3.12.2
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.3.12.2! misho 6: * $Id: conn.c,v 1.3.12.1 2022/09/13 20:37:21 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.3.12.2! misho 15: Copyright 2004 - 2022
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: #include "global.h"
47:
48:
49: /*
50: * mqtt_msgCONNECT() Create CONNECT message
51: *
52: * @csConnID = ConnectID
1.3.12.2! misho 53: * @Version = MQTT version
! 54: * @KASec = Keep alive timeout, if =0 default timeout for MQTT
1.1 misho 55: * @csUser = Username if !=NULL
56: * @csPass = Password for Username, only if csUser is set
57: * @csWillTopic = Will Topic if !=NULL Will Flags set into message
58: * @csWillMessage = Will Message, may be NULL
59: * @ClrSess = Clear Session subscriptions after disconnect
60: * @WillQOS = Will QOS if csWillTopic is set
61: * @WillRetain = Will Retain Will Message if csWillTopic is set
1.3.12.2! misho 62: * return: NULL error or allocated connect message
1.1 misho 63: */
1.3.12.2! misho 64: mqtt_msg_t *
! 65: mqtt_msgCONNECT(const char *csConnID, u_char Version, u_short KASec,
! 66: const char *csUser, const char *csPass,
1.1 misho 67: const char *csWillTopic, const char *csWillMessage,
68: u_char ClrSess, u_char WillQOS, u_char WillRetain)
69: {
1.2 misho 70: int len, siz = 0;
1.3 misho 71: u_int n, *l;
1.3.12.2! misho 72: mqtt_msg_t *msg = NULL;
1.1 misho 73: struct mqtthdr *hdr;
74: mqtthdr_var_t *var, *cid, *topic, *wmsg, *user, *pass;
75: mqtthdr_connflgs_t *flags;
76: mqtt_len_t *ka;
1.2 misho 77: void *data;
1.1 misho 78:
1.3.12.2! misho 79: if (!csConnID)
! 80: return NULL;
1.3.12.1 misho 81: if (strlen(csConnID) >= MQTT_CONNID_MAX) {
82: mqtt_SetErr(EINVAL, "Invalid argument ConnID is too long (max %d bytes)",
83: MQTT_CONNID_MAX - 1);
1.3.12.2! misho 84: return NULL;
! 85: }
! 86: if (Version < MQTT_PROTO_VER_3 || Version > MQTT_PROTO_VER_5) {
! 87: mqtt_SetErr(EINVAL, "Unsupported version");
! 88: return NULL;
1.1 misho 89: }
1.3.12.1 misho 90: if (csUser && strlen(csUser) >= MQTT_CRED_MAX) {
91: mqtt_SetErr(EINVAL, "Invalid argument Username is too long (max %d bytes)",
92: MQTT_CRED_MAX - 1);
1.3.12.2! misho 93: return NULL;
1.1 misho 94: }
1.3.12.1 misho 95: if (csPass && strlen(csPass) >= MQTT_CRED_MAX) {
96: mqtt_SetErr(EINVAL, "Invalid argument Password is too long (max %d bytes)",
97: MQTT_CRED_MAX - 1);
1.3.12.2! misho 98: return NULL;
1.1 misho 99: }
100: if (WillQOS > MQTT_QOS_EXACTLY) {
1.2 misho 101: mqtt_SetErr(EINVAL, "Invalid argument WillQOS - unknown QOS value");
1.3.12.2! misho 102: return NULL;
1.1 misho 103: }
104:
1.2 misho 105: /* calculate message size */
1.3.12.2! misho 106: len = 10; /* connect arguments: MQTT(6)+Version(1)+ConnFlags(1)+KeepAlive(2) */
1.2 misho 107: len += sizeof(mqtt_len_t) + strlen(csConnID); /* connect id */
108: if (csUser && *csUser) { /* user/pass */
109: len += sizeof(mqtt_len_t) + strlen(csUser);
110: if (csPass)
111: len += sizeof(mqtt_len_t) + strlen(csPass);
112: }
113: if (csWillTopic && *csWillTopic) { /* will messages */
114: len += sizeof(mqtt_len_t) + strlen(csWillTopic);
115: len += sizeof(mqtt_len_t) + (csWillMessage ? strlen(csWillMessage) : 0);
116: }
117:
118: /* calculate header size */
119: siz = sizeof(struct mqtthdr); /* mqtt fixed header */
120: n = mqtt_encodeLen(len); /* message size */
121: siz += mqtt_sizeLen(n) - 1; /* length size */
122:
1.3.12.2! misho 123: if (!(msg = mqtt_msgAlloc(siz + len)))
! 124: return NULL;
1.1 misho 125: else {
1.3.12.2! misho 126: data = msg->msg_base;
1.2 misho 127: hdr = (struct mqtthdr *) data;
1.1 misho 128: }
129:
130: /* fixed header */
131: hdr->mqtt_msg.type = MQTT_TYPE_CONNECT;
1.3 misho 132: l = (u_int*) hdr->mqtt_len;
133: *l = n;
1.2 misho 134: data += siz;
1.1 misho 135:
136: /* variable header */
1.2 misho 137: var = (mqtthdr_var_t*) data;
1.3.12.2! misho 138: var->var_sb.val = htons(strlen(MQTT_PROTO_STR));
! 139: memcpy(var->var_data, MQTT_PROTO_STR, ntohs(var->var_sb.val));
1.2 misho 140: data += MQTTHDR_VAR_SIZEOF(var);
1.1 misho 141:
1.2 misho 142: /* protocol version */
1.3.12.2! misho 143: *(u_char*) data++ = Version;
1.1 misho 144:
145: /* CONNECT header */
1.2 misho 146: flags = (mqtthdr_connflgs_t*) data++;
1.1 misho 147: flags->clean_sess = ClrSess ? 1 : 0;
148: if (csUser && *csUser) {
149: flags->username = 1;
150: flags->password = csPass ? 1 : 0;
151: } else {
152: flags->username = 0;
153: flags->password = 0;
154: }
155: if (csWillTopic && *csWillTopic) {
156: flags->will_flg = 1;
157: flags->will_qos = WillQOS;
158: flags->will_retain = WillRetain ? 1 : 0;
159: } else {
160: flags->will_flg = 0;
161: flags->will_qos = 0;
162: flags->will_retain = 0;
163: }
164:
1.2 misho 165: /* keep alive */
166: ka = (mqtt_len_t*) data;
1.3.12.2! misho 167: ka->val = KASec ? htons(KASec) : htons(MQTT_KEEPALIVE);
1.2 misho 168: data += sizeof(mqtt_len_t);
1.1 misho 169:
170: /* ConnID */
1.2 misho 171: cid = (mqtthdr_var_t*) data;
1.1 misho 172: cid->var_sb.val = htons(strlen(csConnID));
173: memcpy(cid->var_data, csConnID, ntohs(cid->var_sb.val));
1.2 misho 174: data += MQTTHDR_VAR_SIZEOF(cid);
1.1 misho 175:
176: /* If Will Flags setup */
177: if (csWillTopic && *csWillTopic) {
1.2 misho 178: topic = (mqtthdr_var_t*) data;
1.1 misho 179: topic->var_sb.val = htons(strlen(csWillTopic));
180: memcpy(topic->var_data, csWillTopic, ntohs(topic->var_sb.val));
1.2 misho 181: data += MQTTHDR_VAR_SIZEOF(topic);
1.1 misho 182:
1.2 misho 183: wmsg = (mqtthdr_var_t*) data;
1.1 misho 184: if (csWillMessage && *csWillMessage) {
185: wmsg->var_sb.val = htons(strlen(csWillMessage));
186: memcpy(wmsg->var_data, csWillMessage, ntohs(wmsg->var_sb.val));
187: } else
188: wmsg->var_sb.val = 0;
1.2 misho 189: data += MQTTHDR_VAR_SIZEOF(wmsg);
1.1 misho 190: }
191:
192: /* If defined Username & Password */
193: if (csUser && *csUser) {
1.2 misho 194: user = (mqtthdr_var_t*) data;
1.1 misho 195: user->var_sb.val = htons(strlen(csUser));
196: memcpy(user->var_data, csUser, ntohs(user->var_sb.val));
1.2 misho 197: data += MQTTHDR_VAR_SIZEOF(user);
1.1 misho 198:
199: if (csPass && *csPass) {
1.2 misho 200: pass = (mqtthdr_var_t*) data;
1.1 misho 201: pass->var_sb.val = htons(strlen(csPass));
202: memcpy(pass->var_data, csPass, ntohs(pass->var_sb.val));
1.2 misho 203: data += MQTTHDR_VAR_SIZEOF(pass);
1.1 misho 204: }
205: }
206:
1.3.12.2! misho 207: return msg;
1.1 misho 208: }
1.3.12.2! misho 209: #if 0
1.1 misho 210: /*
211: * mqtt_msgCONNACK() Create CONNACK message
212: *
213: * @buf = Message buffer
214: * @retcode = Return code
215: * return: -1 error or >-1 message size for send
216: */
1.3.12.2! misho 217: mqtt_msg_t *
! 218: mqtt_msgCONNACK(u_char retcode)
1.1 misho 219: {
220: int siz = 0;
221: struct mqtthdr *hdr;
222: mqtthdr_connack_t *ack;
1.3.12.2! misho 223: mqtt_msg_t *msg = NULL;
1.1 misho 224:
225: if (retcode > MQTT_RETCODE_DENIED) {
1.2 misho 226: mqtt_SetErr(EINVAL, "Invalid retcode");
1.3.12.2! misho 227: return NULL;
1.1 misho 228: }
229:
1.3.12.2! misho 230: if (!(msg = mqtt_msgAlloc(sizeof(struct mqtthdr) + sizeof(mqtthdr_connack_t))))
! 231: return NULL;
1.1 misho 232: else {
233: hdr = (struct mqtthdr *) (buf->msg_base + siz);
234: siz += sizeof(struct mqtthdr);
235: ack = (mqtthdr_connack_t*) (buf->msg_base + siz);
236: siz += sizeof(mqtthdr_connack_t);
237: }
238:
239: /* fixed header */
240: MQTTHDR_MSGINIT(hdr);
241: hdr->mqtt_msg.type = MQTT_TYPE_CONNACK;
242: *hdr->mqtt_len = sizeof(mqtthdr_connack_t);
243:
244: /* CONNACK header */
245: ack->reserved = 0;
246: ack->retcode = retcode;
247:
248: return siz;
249: }
250:
251: static int
252: _mqtt_msgSIMPLE_(mqtt_msg_t * __restrict buf, u_char cmd)
253: {
254: int siz = 0;
255: struct mqtthdr *hdr;
256:
257: if (!buf)
258: return -1;
259:
260: if (mqtt_msgRealloc(buf, sizeof(struct mqtthdr)) == -1)
261: return -1;
262: else {
263: hdr = (struct mqtthdr *) (buf->msg_base + siz);
264: siz += sizeof(struct mqtthdr);
265: }
266:
267: /* fixed header */
268: MQTTHDR_MSGINIT(hdr);
269: hdr->mqtt_msg.type = cmd;
270: *hdr->mqtt_len = 0;
271:
272: return siz;
273: }
274:
275: /*
276: * mqtt_msgPINGREQ() Create PINGREQ message
277: *
278: * @buf = Message buffer
279: * return: -1 error or >-1 message size for send
280: */
281: int
282: mqtt_msgPINGREQ(mqtt_msg_t * __restrict buf)
283: {
284: return _mqtt_msgSIMPLE_(buf, MQTT_TYPE_PINGREQ);
285: }
286:
287: /*
288: * mqtt_msgPINGRESP() Create PINGRESP message
289: *
290: * @buf = Message buffer
291: * return: -1 error or >-1 message size for send
292: */
293: int
294: mqtt_msgPINGRESP(mqtt_msg_t * __restrict buf)
295: {
296: return _mqtt_msgSIMPLE_(buf, MQTT_TYPE_PINGRESP);
297: }
298:
299: /*
300: * mqtt_msgDISCONNECT() Create DISCONNECT message
301: *
302: * @buf = Message buffer
303: * return: -1 error or >-1 message size for send
304: */
305: int
306: mqtt_msgDISCONNECT(mqtt_msg_t * __restrict buf)
307: {
308: return _mqtt_msgSIMPLE_(buf, MQTT_TYPE_DISCONNECT);
309: }
310:
311: /* ============= decode ============ */
312:
313: /*
314: * mqtt_readCONNECT() Read elements from CONNECT message
315: *
316: * @buf = Message buffer
317: * @kasec = Keep Alive in seconds for current connection
318: * @psConnID = ConnectID
319: * @connLen = ConnectID length
320: * @psUser = Username if !=NULL
321: * @userLen = Username length
322: * @psPass = Password for Username, only if csUser is set
323: * @passLen = Password length
324: * @psWillTopic = Will Topic if !=NULL Will Flags set into message and must be free()
325: * @psWillMessage = Will Message, may be NULL if !NULL must be free() after use!
326: * return: .reserved == 1 is error or == 0 connection flags & msg ok
327: */
328: mqtthdr_connack_t
329: mqtt_readCONNECT(mqtt_msg_t * __restrict buf, u_short *kasec, char * __restrict psConnID, int connLen,
330: char * __restrict psUser, int userLen, char * __restrict psPass, int passLen,
331: char ** __restrict psWillTopic, char ** __restrict psWillMessage)
332: {
333: mqtthdr_connflgs_t flg = { MQTT_CONNFLGS_INIT };
334: mqtthdr_connack_t cack = { 1, MQTT_RETCODE_DENIED };
335: struct mqtthdr *hdr;
336: mqtthdr_var_t *var;
337: mqtt_len_t *ka;
338: int len, ret;
339: caddr_t pos;
340:
341: if (!buf || !buf->msg_base || !buf->msg_len || !psConnID || !connLen)
342: return cack;
343:
344: hdr = _mqtt_readHEADER(buf, MQTT_TYPE_CONNECT, &ret, &len);
345: if (!hdr)
346: return cack;
347: if (len < 12) {
1.2 misho 348: mqtt_SetErr(EINVAL, "Short message length %d", len);
1.1 misho 349: return cack;
350: } else {
351: pos = buf->msg_base + ret + 1;
352: var = (mqtthdr_var_t*) pos;
353: }
354: /* check init string & protocol */
355: if (var->var_sb.sb.l != 6 || strncmp((char*) var->var_data, MQTT_CONN_STR, 6)) {
1.2 misho 356: mqtt_SetErr(EINVAL, "Invalid init string %.6s(%d)",
1.1 misho 357: var->var_data, var->var_sb.sb.l);
358: cack.retcode = MQTT_RETCODE_REFUSE_UNAVAIL;
359: return cack;
360: } else {
361: pos += var->var_sb.sb.l + sizeof(mqtt_len_t);
362: proto = (mqtthdr_protover_t*) pos;
363: }
364: if (*proto != MQTT_PROTO_VER) {
1.2 misho 365: mqtt_SetErr(EINVAL, "Invalid protocol version %d", *pos);
1.1 misho 366: cack.retcode = MQTT_RETCODE_REFUSE_VER;
367: return cack;
368: } else
369: pos++;
370: flg = *(mqtthdr_connflgs_t*) pos;
371: pos++;
372: ka = (mqtt_len_t*) pos;
373: *kasec = ntohs(ka->val);
374: pos += sizeof(mqtt_len_t);
375:
376: len -= pos - (caddr_t) var;
377:
378: /* get ConnID */
379: var = (mqtthdr_var_t*) pos;
380: len -= MQTTHDR_VAR_SIZEOF(var);
381: if (len < 0 || var->var_sb.sb.l > 23) {
1.2 misho 382: mqtt_SetErr(EINVAL, "Unexpected EOM at Connection ID %d", len);
1.1 misho 383: cack.retcode = MQTT_RETCODE_REFUSE_ID;
384: return cack;
385: } else {
386: memset(psConnID, 0, connLen--);
387: memcpy(psConnID, var->var_data, ntohs(var->var_sb.val) > connLen ? connLen : ntohs(var->var_sb.val));
388: pos += MQTTHDR_VAR_SIZEOF(var);
389: }
390:
391: /* get Willz */
392: if (flg.will_flg) {
393: var = (mqtthdr_var_t*) pos;
394: len -= MQTTHDR_VAR_SIZEOF(var);
395: if (len < 0) {
1.2 misho 396: mqtt_SetErr(EINVAL, "Unexpected EOM at Will Topic %d", len);
1.1 misho 397: cack.retcode = MQTT_RETCODE_REFUSE_ID;
398: return cack;
399: } else {
400: if (psWillTopic) {
401: *psWillTopic = malloc(ntohs(var->var_sb.val) + 1);
402: if (!*psWillTopic) {
403: LOGERR;
404: cack.retcode = MQTT_RETCODE_REFUSE_UNAVAIL;
405: return cack;
406: } else
407: memset(*psWillTopic, 0, ntohs(var->var_sb.val) + 1);
408: memcpy(*psWillTopic, var->var_data, ntohs(var->var_sb.val));
409: }
410: pos += MQTTHDR_VAR_SIZEOF(var);
411: }
412:
413: var = (mqtthdr_var_t*) pos;
414: len -= MQTTHDR_VAR_SIZEOF(var);
415: if (len < 0) {
1.2 misho 416: mqtt_SetErr(EINVAL, "Unexpected EOM at Will Message %d", len);
1.1 misho 417: cack.retcode = MQTT_RETCODE_REFUSE_ID;
418: return cack;
419: } else {
420: if (psWillMessage) {
421: *psWillMessage = malloc(ntohs(var->var_sb.val) + 1);
422: if (!*psWillMessage) {
423: LOGERR;
424: cack.retcode = MQTT_RETCODE_REFUSE_UNAVAIL;
425: return cack;
426: } else
427: memset(*psWillMessage, 0, ntohs(var->var_sb.val) + 1);
428: memcpy(*psWillMessage, var->var_data, ntohs(var->var_sb.val));
429: }
430: pos += MQTTHDR_VAR_SIZEOF(var);
431: }
432: }
433:
434: /* get User/Pass */
435: if (flg.username) {
436: var = (mqtthdr_var_t*) pos;
437: len -= MQTTHDR_VAR_SIZEOF(var);
438: if (len < 0 || var->var_sb.sb.l > 12) {
1.2 misho 439: mqtt_SetErr(EINVAL, "Unexpected EOM at Username %d", len);
1.1 misho 440: cack.retcode = MQTT_RETCODE_REFUSE_USERPASS;
441: return cack;
442: } else {
443: if (psUser && userLen) {
444: memset(psUser, 0, userLen--);
445: memcpy(psUser, var->var_data,
446: ntohs(var->var_sb.val) > userLen ? userLen : ntohs(var->var_sb.val));
447: }
448: pos += MQTTHDR_VAR_SIZEOF(var);
449: }
450: }
451: if (flg.password) {
452: var = (mqtthdr_var_t*) pos;
453: len -= MQTTHDR_VAR_SIZEOF(var);
454: if (len < 0 || var->var_sb.sb.l > 12) {
1.2 misho 455: mqtt_SetErr(EINVAL, "Unexpected EOM at Password %d", len);
1.1 misho 456: cack.retcode = MQTT_RETCODE_REFUSE_USERPASS;
457: return cack;
458: } else {
459: if (psPass && passLen) {
460: memset(psPass, 0, passLen--);
461: memcpy(psPass, var->var_data,
462: ntohs(var->var_sb.val) > passLen ? passLen : ntohs(var->var_sb.val));
463: }
464: pos += MQTTHDR_VAR_SIZEOF(var);
465: }
466: }
467:
468: flg.reserved = 0;
469: cack.reserved = flg.flags;
470: cack.retcode = MQTT_RETCODE_ACCEPTED;
471: return cack;
472: }
473:
474: /*
475: * mqtt_readCONNACK() Read CONNACK message
476: *
477: * @buf = Message buffer
478: * return: -1 error or >-1 CONNECT message return code
479: */
480: u_char
481: mqtt_readCONNACK(mqtt_msg_t * __restrict buf)
482: {
483: int len, ret;
484: struct mqtthdr *hdr;
485: mqtthdr_connack_t *ack;
486: caddr_t pos;
487:
488: if (!buf || !buf->msg_base || !buf->msg_len)
489: return (u_char) -1;
490:
491: hdr = _mqtt_readHEADER(buf, MQTT_TYPE_CONNACK, &ret, &len);
492: if (!hdr)
493: return (u_char) -1;
494: if (len < sizeof(mqtthdr_connack_t)) {
1.2 misho 495: mqtt_SetErr(EINVAL, "Short message length %d", len);
1.1 misho 496: return (u_char) -1;
497: } else {
498: pos = buf->msg_base + ret + 1;
499: ack = (mqtthdr_connack_t*) pos;
500: }
501:
502: if (ack->retcode > MQTT_RETCODE_DENIED) {
1.2 misho 503: mqtt_SetErr(EINVAL, "Invalid retcode %u", ack->retcode);
1.1 misho 504: return (u_char) -1;
505: }
506:
507: return ack->retcode;
508: }
509:
510: /*
511: * mqtt_readDISCONNECT() Read DISCONNECT message
512: *
513: * @buf = Message buffer
514: * return: -1 error, 0 ok, >0 undefined result
515: */
516: int
517: mqtt_readDISCONNECT(mqtt_msg_t * __restrict buf)
518: {
519: int len, ret;
520: struct mqtthdr *hdr;
521:
522: hdr = _mqtt_readHEADER(buf, MQTT_TYPE_DISCONNECT, &ret, &len);
523: if (!hdr || ret != 1)
524: return -1;
525:
526: return len;
527: }
528:
529: /*
530: * mqtt_readPINGREQ() Read PINGREQ message
531: *
532: * @buf = Message buffer
533: * return: -1 error, 0 ok, >0 undefined result
534: */
535: int
536: mqtt_readPINGREQ(mqtt_msg_t * __restrict buf)
537: {
538: int len, ret;
539: struct mqtthdr *hdr;
540:
541: hdr = _mqtt_readHEADER(buf, MQTT_TYPE_PINGREQ, &ret, &len);
542: if (!hdr || ret != 1)
543: return -1;
544:
545: return len;
546: }
547:
548: /*
549: * mqtt_readPINGRESP() Read PINGRESP message
550: *
551: * @buf = Message buffer
552: * return: -1 error, 0 ok, >0 undefined result
553: */
554: int
555: mqtt_readPINGRESP(mqtt_msg_t * __restrict buf)
556: {
557: int len, ret;
558: struct mqtthdr *hdr;
559:
560: hdr = _mqtt_readHEADER(buf, MQTT_TYPE_PINGRESP, &ret, &len);
561: if (!hdr || ret != 1)
562: return -1;
563:
564: return len;
565: }
1.3.12.2! misho 566: #endif
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>