Skip to content

Commit

Permalink
>Release date: 2015-08-16
Browse files Browse the repository at this point in the history
Relaxed check for incoming Publishes (mosca 0.31.1 incompability)

[NEW] zero message id is accepted on incoming publish closes #42
  • Loading branch information
Christoph Krey committed Aug 16, 2015
1 parent 948fb2e commit 3f212fa
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 99 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
MQTT-Client-Framework iOS Release Notes
=======================================

## MQTT-Client-Framework 0.2.4
>Release date: 2015-08-16
Relaxed check for incoming Publishes (mosca 0.31.1 incompability)

[NEW] zero message id is accepted on incoming publish closes #42

## MQTT-Client-Framework 0.2.3
>Release date: 2015-07-23
Expand Down
4 changes: 2 additions & 2 deletions MQTTClient.podspec
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
Pod::Spec.new do |s|
s.name = "MQTTClient"
s.version = "0.2.3"
s.version = "0.2.4"
s.summary = "IOS native ObjectiveC MQTT Framework"
s.homepage = "https://github.com/ckrey/MQTT-Client-Framework"
s.license = { :type => "MIT", :file => "LICENSE" }
s.author = { "Christoph Krey" => "[email protected]" }
s.source = { :git => "https://github.com/ckrey/MQTT-Client-Framework.git", :tag => "0.2.3" }
s.source = { :git => "https://github.com/ckrey/MQTT-Client-Framework.git", :tag => "0.2.4" }

s.source_files = "MQTTClient/MQTTClient", "MQTTClient/MQTTClient/**/*.{h,m}"
s.requires_arc = true
Expand Down
178 changes: 81 additions & 97 deletions MQTTClient/MQTTClient/MQTTSession.m
Original file line number Diff line number Diff line change
Expand Up @@ -878,11 +878,8 @@ - (void)closeInternal

[self tell];
self.synchronPub = FALSE;
self.synchronPubMid = 0;
self.synchronSub = FALSE;
self.synchronSubMid = 0;
self.synchronUnsub = FALSE;
self.synchronUnsubMid = 0;
self.synchronConnect = FALSE;
self.synchronDisconnect = FALSE;
self.selfReference = nil;
Expand Down Expand Up @@ -1208,31 +1205,29 @@ - (void)handlePublish:(MQTTMessage*)msg
if ([data length] >= 2) {
bytes = [data bytes];
UInt16 msgId = 256 * bytes[0] + bytes[1];
if (msgId != 0) {
msg.mid = msgId;
data = [data subdataWithRange:NSMakeRange(2, [data length] - 2)];
if ([msg qos] == 1) {
if ([self.delegate respondsToSelector:@selector(newMessage:data:onTopic:qos:retained:mid:)]) {
[self.delegate newMessage:self data:data onTopic:topic qos:msg.qos retained:msg.retainFlag mid:msgId];
}
if(self.messageHandler){
self.messageHandler(data, topic);
}
[self send:[MQTTMessage pubackMessageWithMessageId:msgId]];
return;
msg.mid = msgId;
data = [data subdataWithRange:NSMakeRange(2, [data length] - 2)];
if ([msg qos] == 1) {
if ([self.delegate respondsToSelector:@selector(newMessage:data:onTopic:qos:retained:mid:)]) {
[self.delegate newMessage:self data:data onTopic:topic qos:msg.qos retained:msg.retainFlag mid:msgId];
}
if(self.messageHandler){
self.messageHandler(data, topic);
}
[self send:[MQTTMessage pubackMessageWithMessageId:msgId]];
return;
} else {
if (![self.persistence storeMessageForClientId:self.clientId
topic:topic
data:data
retainFlag:msg.retainFlag
qos:msg.qos
msgId:msgId
incomingFlag:YES]) {
if (DEBUGSESS) NSLog(@"%@ dropping incoming messages", self);
} else {
if (![self.persistence storeMessageForClientId:self.clientId
topic:topic
data:data
retainFlag:msg.retainFlag
qos:msg.qos
msgId:msgId
incomingFlag:YES]) {
if (DEBUGSESS) NSLog(@"%@ dropping incoming messages", self);
} else {
[self tell];
[self send:[MQTTMessage pubrecMessageWithMessageId:msgId]];
}
[self tell];
[self send:[MQTTMessage pubrecMessageWithMessageId:msgId]];
}
}
}
Expand All @@ -1244,22 +1239,20 @@ - (void)handlePuback:(MQTTMessage*)msg
if ([[msg data] length] == 2) {
UInt8 const *bytes = [[msg data] bytes];
UInt16 messageId = (256 * bytes[0] + bytes[1]);
if (messageId != 0) {
msg.mid = messageId;
MQTTFlow *flow = [self.persistence flowforClientId:self.clientId
incomingFlag:NO
messageId:messageId];
if (flow) {
if ([flow.commandType intValue] == MQTTPublish && [flow.qosLevel intValue] == MQTTQosLevelAtLeastOnce) {
[self.persistence deleteFlow:flow];
[self.persistence sync];
[self tell];
if ([self.delegate respondsToSelector:@selector(messageDelivered:msgID:)]) {
[self.delegate messageDelivered:self msgID:messageId];
}
if (self.synchronPub && self.synchronPubMid == messageId) {
self.synchronPub = FALSE;
}
msg.mid = messageId;
MQTTFlow *flow = [self.persistence flowforClientId:self.clientId
incomingFlag:NO
messageId:messageId];
if (flow) {
if ([flow.commandType intValue] == MQTTPublish && [flow.qosLevel intValue] == MQTTQosLevelAtLeastOnce) {
[self.persistence deleteFlow:flow];
[self.persistence sync];
[self tell];
if ([self.delegate respondsToSelector:@selector(messageDelivered:msgID:)]) {
[self.delegate messageDelivered:self msgID:messageId];
}
if (self.synchronPub && self.synchronPubMid == messageId) {
self.synchronPub = FALSE;
}
}
}
Expand Down Expand Up @@ -1305,23 +1298,21 @@ - (void)handlePubrec:(MQTTMessage*)msg
if ([[msg data] length] == 2) {
UInt8 const *bytes = [[msg data] bytes];
UInt16 messageId = (256 * bytes[0] + bytes[1]);
if (messageId != 0) {
msg.mid = messageId;
MQTTMessage *pubrelmsg = [MQTTMessage pubrelMessageWithMessageId:messageId];
MQTTFlow *flow = [self.persistence flowforClientId:self.clientId
incomingFlag:NO
messageId:messageId];
if (flow) {
if ([flow.commandType intValue] == MQTTPublish && [flow.qosLevel intValue] == MQTTQosLevelExactlyOnce) {
flow.commandType = @(MQTTPubrel);
flow.topic = nil;
flow.data = nil;
flow.deadline = [NSDate dateWithTimeIntervalSinceNow:DUPTIMEOUT];
[self.persistence sync];
}
msg.mid = messageId;
MQTTMessage *pubrelmsg = [MQTTMessage pubrelMessageWithMessageId:messageId];
MQTTFlow *flow = [self.persistence flowforClientId:self.clientId
incomingFlag:NO
messageId:messageId];
if (flow) {
if ([flow.commandType intValue] == MQTTPublish && [flow.qosLevel intValue] == MQTTQosLevelExactlyOnce) {
flow.commandType = @(MQTTPubrel);
flow.topic = nil;
flow.data = nil;
flow.deadline = [NSDate dateWithTimeIntervalSinceNow:DUPTIMEOUT];
[self.persistence sync];
}
[self send:pubrelmsg];
}
[self send:pubrelmsg];
}
}

Expand All @@ -1330,51 +1321,47 @@ - (void)handlePubrel:(MQTTMessage*)msg
if ([[msg data] length] == 2) {
UInt8 const *bytes = [[msg data] bytes];
UInt16 messageId = (256 * bytes[0] + bytes[1]);
if (messageId != 0) {
MQTTFlow *flow = [self.persistence flowforClientId:self.clientId
incomingFlag:YES
messageId:messageId];
if (flow) {
if ([self.delegate respondsToSelector:@selector(newMessage:data:onTopic:qos:retained:mid:)]) {
[self.delegate newMessage:self
data:flow.data
onTopic:flow.topic
qos:[flow.qosLevel intValue]
retained:[flow.retainedFlag boolValue]
mid:[flow.messageId intValue]
];
}
if(self.messageHandler){
self.messageHandler(flow.data, flow.topic);
}

[self.persistence deleteFlow:flow];
[self.persistence sync];
[self tell];
MQTTFlow *flow = [self.persistence flowforClientId:self.clientId
incomingFlag:YES
messageId:messageId];
if (flow) {
if ([self.delegate respondsToSelector:@selector(newMessage:data:onTopic:qos:retained:mid:)]) {
[self.delegate newMessage:self
data:flow.data
onTopic:flow.topic
qos:[flow.qosLevel intValue]
retained:[flow.retainedFlag boolValue]
mid:[flow.messageId intValue]
];
}
[self send:[MQTTMessage pubcompMessageWithMessageId:messageId]];
if(self.messageHandler){
self.messageHandler(flow.data, flow.topic);
}

[self.persistence deleteFlow:flow];
[self.persistence sync];
[self tell];
}
[self send:[MQTTMessage pubcompMessageWithMessageId:messageId]];
}
}

- (void)handlePubcomp:(MQTTMessage*)msg {
if ([[msg data] length] == 2) {
UInt8 const *bytes = [[msg data] bytes];
UInt16 messageId = (256 * bytes[0] + bytes[1]);
if (messageId != 0) {
MQTTFlow *flow = [self.persistence flowforClientId:self.clientId
incomingFlag:NO
messageId:messageId];
if (flow && [flow.commandType intValue] == MQTTPubrel) {
[self.persistence deleteFlow:flow];
[self.persistence sync];
[self tell];
if ([self.delegate respondsToSelector:@selector(messageDelivered:msgID:)]) {
[self.delegate messageDelivered:self msgID:messageId];
}
if (self.synchronPub && self.synchronPubMid == messageId) {
self.synchronPub = FALSE;
}
MQTTFlow *flow = [self.persistence flowforClientId:self.clientId
incomingFlag:NO
messageId:messageId];
if (flow && [flow.commandType intValue] == MQTTPubrel) {
[self.persistence deleteFlow:flow];
[self.persistence sync];
[self tell];
if ([self.delegate respondsToSelector:@selector(messageDelivered:msgID:)]) {
[self.delegate messageDelivered:self msgID:messageId];
}
if (self.synchronPub && self.synchronPubMid == messageId) {
self.synchronPub = FALSE;
}
}
}
Expand Down Expand Up @@ -1407,11 +1394,8 @@ - (void)error:(MQTTSessionEvent)eventCode error:(NSError *)error {
}

self.synchronPub = FALSE;
self.synchronPubMid = 0;
self.synchronSub = FALSE;
self.synchronSubMid = 0;
self.synchronUnsub = FALSE;
self.synchronUnsubMid = 0;
self.synchronConnect = FALSE;
self.synchronDisconnect = FALSE;
}
Expand Down

0 comments on commit 3f212fa

Please sign in to comment.