mbed OS5に対応したMilkcocoaライブラリのテストバージョンです。
Fork of mbed-os-example-mbed5-blinky by
Milkcocoa/MQTT/MQTTPacket/MQTTUnsubscribeServer.c@24:6ba1245bf049, 2017-01-24 (annotated)
- Committer:
- jksoft
- Date:
- Tue Jan 24 13:41:36 2017 +0000
- Revision:
- 24:6ba1245bf049
??????????
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jksoft | 24:6ba1245bf049 | 1 | /******************************************************************************* |
jksoft | 24:6ba1245bf049 | 2 | * Copyright (c) 2014 IBM Corp. |
jksoft | 24:6ba1245bf049 | 3 | * |
jksoft | 24:6ba1245bf049 | 4 | * All rights reserved. This program and the accompanying materials |
jksoft | 24:6ba1245bf049 | 5 | * are made available under the terms of the Eclipse Public License v1.0 |
jksoft | 24:6ba1245bf049 | 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. |
jksoft | 24:6ba1245bf049 | 7 | * |
jksoft | 24:6ba1245bf049 | 8 | * The Eclipse Public License is available at |
jksoft | 24:6ba1245bf049 | 9 | * http://www.eclipse.org/legal/epl-v10.html |
jksoft | 24:6ba1245bf049 | 10 | * and the Eclipse Distribution License is available at |
jksoft | 24:6ba1245bf049 | 11 | * http://www.eclipse.org/org/documents/edl-v10.php. |
jksoft | 24:6ba1245bf049 | 12 | * |
jksoft | 24:6ba1245bf049 | 13 | * Contributors: |
jksoft | 24:6ba1245bf049 | 14 | * Ian Craggs - initial API and implementation and/or initial documentation |
jksoft | 24:6ba1245bf049 | 15 | *******************************************************************************/ |
jksoft | 24:6ba1245bf049 | 16 | |
jksoft | 24:6ba1245bf049 | 17 | #include "MQTTPacket.h" |
jksoft | 24:6ba1245bf049 | 18 | #include "StackTrace.h" |
jksoft | 24:6ba1245bf049 | 19 | |
jksoft | 24:6ba1245bf049 | 20 | #include <string.h> |
jksoft | 24:6ba1245bf049 | 21 | |
jksoft | 24:6ba1245bf049 | 22 | |
jksoft | 24:6ba1245bf049 | 23 | /** |
jksoft | 24:6ba1245bf049 | 24 | * Deserializes the supplied (wire) buffer into unsubscribe data |
jksoft | 24:6ba1245bf049 | 25 | * @param dup integer returned - the MQTT dup flag |
jksoft | 24:6ba1245bf049 | 26 | * @param packetid integer returned - the MQTT packet identifier |
jksoft | 24:6ba1245bf049 | 27 | * @param maxcount - the maximum number of members allowed in the topicFilters and requestedQoSs arrays |
jksoft | 24:6ba1245bf049 | 28 | * @param count - number of members in the topicFilters and requestedQoSs arrays |
jksoft | 24:6ba1245bf049 | 29 | * @param topicFilters - array of topic filter names |
jksoft | 24:6ba1245bf049 | 30 | * @param buf the raw buffer data, of the correct length determined by the remaining length field |
jksoft | 24:6ba1245bf049 | 31 | * @param buflen the length in bytes of the data in the supplied buffer |
jksoft | 24:6ba1245bf049 | 32 | * @return the length of the serialized data. <= 0 indicates error |
jksoft | 24:6ba1245bf049 | 33 | */ |
jksoft | 24:6ba1245bf049 | 34 | int MQTTDeserialize_unsubscribe(unsigned char* dup, unsigned short* packetid, int maxcount, int* count, MQTTString topicFilters[], |
jksoft | 24:6ba1245bf049 | 35 | unsigned char* buf, int len) |
jksoft | 24:6ba1245bf049 | 36 | { |
jksoft | 24:6ba1245bf049 | 37 | MQTTHeader header = {0}; |
jksoft | 24:6ba1245bf049 | 38 | unsigned char* curdata = buf; |
jksoft | 24:6ba1245bf049 | 39 | unsigned char* enddata = NULL; |
jksoft | 24:6ba1245bf049 | 40 | int rc = 0; |
jksoft | 24:6ba1245bf049 | 41 | int mylen = 0; |
jksoft | 24:6ba1245bf049 | 42 | |
jksoft | 24:6ba1245bf049 | 43 | FUNC_ENTRY; |
jksoft | 24:6ba1245bf049 | 44 | header.byte = readChar(&curdata); |
jksoft | 24:6ba1245bf049 | 45 | if (header.bits.type != UNSUBSCRIBE) |
jksoft | 24:6ba1245bf049 | 46 | goto exit; |
jksoft | 24:6ba1245bf049 | 47 | *dup = header.bits.dup; |
jksoft | 24:6ba1245bf049 | 48 | |
jksoft | 24:6ba1245bf049 | 49 | curdata += (rc = MQTTPacket_decodeBuf(curdata, &mylen)); /* read remaining length */ |
jksoft | 24:6ba1245bf049 | 50 | enddata = curdata + mylen; |
jksoft | 24:6ba1245bf049 | 51 | |
jksoft | 24:6ba1245bf049 | 52 | *packetid = readInt(&curdata); |
jksoft | 24:6ba1245bf049 | 53 | |
jksoft | 24:6ba1245bf049 | 54 | *count = 0; |
jksoft | 24:6ba1245bf049 | 55 | while (curdata < enddata) |
jksoft | 24:6ba1245bf049 | 56 | { |
jksoft | 24:6ba1245bf049 | 57 | if (!readMQTTLenString(&topicFilters[*count], &curdata, enddata)) |
jksoft | 24:6ba1245bf049 | 58 | goto exit; |
jksoft | 24:6ba1245bf049 | 59 | (*count)++; |
jksoft | 24:6ba1245bf049 | 60 | } |
jksoft | 24:6ba1245bf049 | 61 | |
jksoft | 24:6ba1245bf049 | 62 | rc = 1; |
jksoft | 24:6ba1245bf049 | 63 | exit: |
jksoft | 24:6ba1245bf049 | 64 | FUNC_EXIT_RC(rc); |
jksoft | 24:6ba1245bf049 | 65 | return rc; |
jksoft | 24:6ba1245bf049 | 66 | } |
jksoft | 24:6ba1245bf049 | 67 | |
jksoft | 24:6ba1245bf049 | 68 | |
jksoft | 24:6ba1245bf049 | 69 | /** |
jksoft | 24:6ba1245bf049 | 70 | * Serializes the supplied unsuback data into the supplied buffer, ready for sending |
jksoft | 24:6ba1245bf049 | 71 | * @param buf the buffer into which the packet will be serialized |
jksoft | 24:6ba1245bf049 | 72 | * @param buflen the length in bytes of the supplied buffer |
jksoft | 24:6ba1245bf049 | 73 | * @param packetid integer - the MQTT packet identifier |
jksoft | 24:6ba1245bf049 | 74 | * @return the length of the serialized data. <= 0 indicates error |
jksoft | 24:6ba1245bf049 | 75 | */ |
jksoft | 24:6ba1245bf049 | 76 | int MQTTSerialize_unsuback(unsigned char* buf, int buflen, unsigned short packetid) |
jksoft | 24:6ba1245bf049 | 77 | { |
jksoft | 24:6ba1245bf049 | 78 | MQTTHeader header = {0}; |
jksoft | 24:6ba1245bf049 | 79 | int rc = 0; |
jksoft | 24:6ba1245bf049 | 80 | unsigned char *ptr = buf; |
jksoft | 24:6ba1245bf049 | 81 | |
jksoft | 24:6ba1245bf049 | 82 | FUNC_ENTRY; |
jksoft | 24:6ba1245bf049 | 83 | if (buflen < 2) |
jksoft | 24:6ba1245bf049 | 84 | { |
jksoft | 24:6ba1245bf049 | 85 | rc = MQTTPACKET_BUFFER_TOO_SHORT; |
jksoft | 24:6ba1245bf049 | 86 | goto exit; |
jksoft | 24:6ba1245bf049 | 87 | } |
jksoft | 24:6ba1245bf049 | 88 | header.byte = 0; |
jksoft | 24:6ba1245bf049 | 89 | header.bits.type = UNSUBACK; |
jksoft | 24:6ba1245bf049 | 90 | writeChar(&ptr, header.byte); /* write header */ |
jksoft | 24:6ba1245bf049 | 91 | |
jksoft | 24:6ba1245bf049 | 92 | ptr += MQTTPacket_encode(ptr, 2); /* write remaining length */ |
jksoft | 24:6ba1245bf049 | 93 | |
jksoft | 24:6ba1245bf049 | 94 | writeInt(&ptr, packetid); |
jksoft | 24:6ba1245bf049 | 95 | |
jksoft | 24:6ba1245bf049 | 96 | rc = ptr - buf; |
jksoft | 24:6ba1245bf049 | 97 | exit: |
jksoft | 24:6ba1245bf049 | 98 | FUNC_EXIT_RC(rc); |
jksoft | 24:6ba1245bf049 | 99 | return rc; |
jksoft | 24:6ba1245bf049 | 100 | } |
jksoft | 24:6ba1245bf049 | 101 | |
jksoft | 24:6ba1245bf049 | 102 |