Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of MQTTPacket by
MQTTUnsubscribeServer.c@14:c2052aee81de, 2014-08-01 (annotated)
- Committer:
- Ian Craggs
- Date:
- Fri Aug 01 15:34:04 2014 +0100
- Revision:
- 14:c2052aee81de
- Parent:
- 0:7734401cc1b4
- Child:
- 16:d0b3886ada32
Change C types to better fit MQTT types, and match MQTT-SN library
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| icraggs | 0:7734401cc1b4 | 1 | /******************************************************************************* |
| icraggs | 0:7734401cc1b4 | 2 | * Copyright (c) 2014 IBM Corp. |
| icraggs | 0:7734401cc1b4 | 3 | * |
| icraggs | 0:7734401cc1b4 | 4 | * All rights reserved. This program and the accompanying materials |
| icraggs | 0:7734401cc1b4 | 5 | * are made available under the terms of the Eclipse Public License v1.0 |
| icraggs | 0:7734401cc1b4 | 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. |
| icraggs | 0:7734401cc1b4 | 7 | * |
| icraggs | 0:7734401cc1b4 | 8 | * The Eclipse Public License is available at |
| icraggs | 0:7734401cc1b4 | 9 | * http://www.eclipse.org/legal/epl-v10.html |
| icraggs | 0:7734401cc1b4 | 10 | * and the Eclipse Distribution License is available at |
| icraggs | 0:7734401cc1b4 | 11 | * http://www.eclipse.org/org/documents/edl-v10.php. |
| icraggs | 0:7734401cc1b4 | 12 | * |
| icraggs | 0:7734401cc1b4 | 13 | * Contributors: |
| icraggs | 0:7734401cc1b4 | 14 | * Ian Craggs - initial API and implementation and/or initial documentation |
| icraggs | 0:7734401cc1b4 | 15 | *******************************************************************************/ |
| icraggs | 0:7734401cc1b4 | 16 | |
| icraggs | 0:7734401cc1b4 | 17 | #include "MQTTPacket.h" |
| icraggs | 0:7734401cc1b4 | 18 | #include "StackTrace.h" |
| icraggs | 0:7734401cc1b4 | 19 | |
| icraggs | 0:7734401cc1b4 | 20 | #include <string.h> |
| icraggs | 0:7734401cc1b4 | 21 | |
| icraggs | 0:7734401cc1b4 | 22 | |
| icraggs | 0:7734401cc1b4 | 23 | /** |
| icraggs | 0:7734401cc1b4 | 24 | * Deserializes the supplied (wire) buffer into unsubscribe data |
| icraggs | 0:7734401cc1b4 | 25 | * @param dup integer returned - the MQTT dup flag |
| icraggs | 0:7734401cc1b4 | 26 | * @param packetid integer returned - the MQTT packet identifier |
| icraggs | 0:7734401cc1b4 | 27 | * @param maxcount - the maximum number of members allowed in the topicFilters and requestedQoSs arrays |
| icraggs | 0:7734401cc1b4 | 28 | * @param count - number of members in the topicFilters and requestedQoSs arrays |
| icraggs | 0:7734401cc1b4 | 29 | * @param topicFilters - array of topic filter names |
| icraggs | 0:7734401cc1b4 | 30 | * @param buf the raw buffer data, of the correct length determined by the remaining length field |
| icraggs | 0:7734401cc1b4 | 31 | * @param buflen the length in bytes of the data in the supplied buffer |
| icraggs | 0:7734401cc1b4 | 32 | * @return the length of the serialized data. <= 0 indicates error |
| icraggs | 0:7734401cc1b4 | 33 | */ |
| Ian Craggs |
14:c2052aee81de | 34 | int MQTTDeserialize_unsubscribe(unsigned char* dup, unsigned short* packetid, int maxcount, int* count, MQTTString topicFilters[], |
| Ian Craggs |
14:c2052aee81de | 35 | unsigned char* buf, int len) |
| icraggs | 0:7734401cc1b4 | 36 | { |
| icraggs | 0:7734401cc1b4 | 37 | MQTTHeader header; |
| Ian Craggs |
14:c2052aee81de | 38 | unsigned char* curdata = buf; |
| Ian Craggs |
14:c2052aee81de | 39 | unsigned char* enddata = NULL; |
| icraggs | 0:7734401cc1b4 | 40 | int rc = 0; |
| icraggs | 0:7734401cc1b4 | 41 | int mylen = 0; |
| icraggs | 0:7734401cc1b4 | 42 | |
| icraggs | 0:7734401cc1b4 | 43 | FUNC_ENTRY; |
| icraggs | 0:7734401cc1b4 | 44 | header.byte = readChar(&curdata); |
| icraggs | 0:7734401cc1b4 | 45 | *dup = header.bits.dup; |
| icraggs | 0:7734401cc1b4 | 46 | |
| icraggs | 0:7734401cc1b4 | 47 | curdata += (rc = MQTTPacket_decodeBuf(curdata, &mylen)); /* read remaining length */ |
| icraggs | 0:7734401cc1b4 | 48 | enddata = curdata + mylen; |
| icraggs | 0:7734401cc1b4 | 49 | |
| icraggs | 0:7734401cc1b4 | 50 | *packetid = readInt(&curdata); |
| icraggs | 0:7734401cc1b4 | 51 | |
| icraggs | 0:7734401cc1b4 | 52 | *count = 0; |
| icraggs | 0:7734401cc1b4 | 53 | while (curdata < enddata) |
| icraggs | 0:7734401cc1b4 | 54 | { |
| icraggs | 0:7734401cc1b4 | 55 | if (!readMQTTLenString(&topicFilters[*count], &curdata, enddata)) |
| icraggs | 0:7734401cc1b4 | 56 | goto exit; |
| icraggs | 0:7734401cc1b4 | 57 | (*count)++; |
| icraggs | 0:7734401cc1b4 | 58 | } |
| icraggs | 0:7734401cc1b4 | 59 | |
| icraggs | 0:7734401cc1b4 | 60 | rc = 1; |
| icraggs | 0:7734401cc1b4 | 61 | exit: |
| icraggs | 0:7734401cc1b4 | 62 | FUNC_EXIT_RC(rc); |
| icraggs | 0:7734401cc1b4 | 63 | return rc; |
| icraggs | 0:7734401cc1b4 | 64 | } |
| icraggs | 0:7734401cc1b4 | 65 | |
| icraggs | 0:7734401cc1b4 | 66 | |
| icraggs | 0:7734401cc1b4 | 67 | /** |
| icraggs | 0:7734401cc1b4 | 68 | * Serializes the supplied unsuback data into the supplied buffer, ready for sending |
| icraggs | 0:7734401cc1b4 | 69 | * @param buf the buffer into which the packet will be serialized |
| icraggs | 0:7734401cc1b4 | 70 | * @param buflen the length in bytes of the supplied buffer |
| icraggs | 0:7734401cc1b4 | 71 | * @param packetid integer - the MQTT packet identifier |
| icraggs | 0:7734401cc1b4 | 72 | * @return the length of the serialized data. <= 0 indicates error |
| icraggs | 0:7734401cc1b4 | 73 | */ |
| Ian Craggs |
14:c2052aee81de | 74 | int MQTTSerialize_unsuback(unsigned char* buf, int buflen, unsigned short packetid) |
| icraggs | 0:7734401cc1b4 | 75 | { |
| icraggs | 0:7734401cc1b4 | 76 | MQTTHeader header; |
| icraggs | 0:7734401cc1b4 | 77 | int rc = 0; |
| Ian Craggs |
14:c2052aee81de | 78 | unsigned char *ptr = buf; |
| icraggs | 0:7734401cc1b4 | 79 | |
| icraggs | 0:7734401cc1b4 | 80 | FUNC_ENTRY; |
| icraggs | 0:7734401cc1b4 | 81 | if (buflen < 2) |
| icraggs | 0:7734401cc1b4 | 82 | { |
| icraggs | 0:7734401cc1b4 | 83 | rc = MQTTPACKET_BUFFER_TOO_SHORT; |
| icraggs | 0:7734401cc1b4 | 84 | goto exit; |
| icraggs | 0:7734401cc1b4 | 85 | } |
| icraggs | 0:7734401cc1b4 | 86 | header.byte = 0; |
| icraggs | 0:7734401cc1b4 | 87 | header.bits.type = UNSUBACK; |
| icraggs | 0:7734401cc1b4 | 88 | writeChar(&ptr, header.byte); /* write header */ |
| icraggs | 0:7734401cc1b4 | 89 | |
| icraggs | 0:7734401cc1b4 | 90 | ptr += MQTTPacket_encode(ptr, 2); /* write remaining length */ |
| icraggs | 0:7734401cc1b4 | 91 | |
| icraggs | 0:7734401cc1b4 | 92 | writeInt(&ptr, packetid); |
| icraggs | 0:7734401cc1b4 | 93 | |
| icraggs | 0:7734401cc1b4 | 94 | rc = ptr - buf; |
| icraggs | 0:7734401cc1b4 | 95 | exit: |
| icraggs | 0:7734401cc1b4 | 96 | FUNC_EXIT_RC(rc); |
| icraggs | 0:7734401cc1b4 | 97 | return rc; |
| icraggs | 0:7734401cc1b4 | 98 | } |
| icraggs | 0:7734401cc1b4 | 99 | |
| icraggs | 0:7734401cc1b4 | 100 |
