Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Adrxx committed Jul 26, 2018
2 parents dc89fd5 + ea17a8f commit 03cf44e
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 72 deletions.
10 changes: 5 additions & 5 deletions MQTTClient.podspec
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
Pod::Spec.new do |mqttc|
mqttc.name = "MQTTClient"
mqttc.version = "0.13.1"
mqttc.version = "0.15.0"
mqttc.summary = "iOS, macOS and tvOS native ObjectiveC MQTT Client Framework"
mqttc.homepage = "https://github.com/novastone-media/MQTT-Client-Framework"
mqttc.license = { :type => "EPLv1", :file => "LICENSE" }
mqttc.author = { "novastonemedia" => "ios@novastonemedia.com" }
mqttc.source = {
:git => "https://github.com/novastone-media/MQTT-Client-Framework.git",
:tag => "0.13.1",
:tag => "0.15.0",
:submodules => true
}

Expand Down Expand Up @@ -75,15 +75,15 @@ Pod::Spec.new do |mqttc|
end

mqttc.subspec 'Manager' do |manager|
manager.source_files = "MQTTClient/MQTTClient/MQTTSessionManager.{h,m}",
manager.source_files = "MQTTClient/MQTTClient/MQTTSessionManager.{h,m}",
"MQTTClient/MQTTClient/ReconnectTimer.{h,m}",
"MQTTClient/MQTTClient/ForegroundReconnection.{h,m}"
manager.dependency 'MQTTClient/Min'
end

mqttc.subspec 'ManagerL' do |managerl|
managerl.source_files = "MQTTClient/MQTTClient/MQTTSessionManager.{h,m}",
"MQTTClient/MQTTClient/ReconnectTimer.{h,m}",
managerl.source_files = "MQTTClient/MQTTClient/MQTTSessionManager.{h,m}",
"MQTTClient/MQTTClient/ReconnectTimer.{h,m}",
"MQTTClient/MQTTClient/ForegroundReconnection.{h,m}"
managerl.dependency 'MQTTClient/MinL'
managerl.xcconfig = { 'GCC_PREPROCESSOR_DEFINITIONS' => 'LUMBERJACK=1' }
Expand Down
2 changes: 1 addition & 1 deletion MQTTClient/MQTTClient/MQTTDecoder.m
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ - (void)stream:(NSStream *)sender handleEvent:(NSStreamEvent)eventCode {
self.dataBuffer = nil;
self.state = MQTTDecoderStateDecodingHeader;
} else {
DDLogError(@"[MQTTDecoder] oops received (%lu)=%@...", (unsigned long)self.dataBuffer.length,
DDLogWarn(@"[MQTTDecoder] oops received (%lu)=%@...", (unsigned long)self.dataBuffer.length,
[self.dataBuffer subdataWithRange:NSMakeRange(0, MIN(256, self.dataBuffer.length))]);
}
}
Expand Down
66 changes: 2 additions & 64 deletions MQTTClient/MQTTClient/MQTTSession.m
Original file line number Diff line number Diff line change
Expand Up @@ -1268,7 +1268,7 @@ - (void)error:(MQTTSessionEvent)eventCode error:(NSError *)error {
self.connectionHandler(eventCode);
}

if(eventCode == MQTTSessionEventConnectionClosedByBroker && self.connectHandler) {
if (eventCode == MQTTSessionEventConnectionClosedByBroker && self.connectHandler) {
error = [NSError errorWithDomain:MQTTSessionErrorDomain
code:MQTTSessionErrorConnectionRefused
userInfo:@{NSLocalizedDescriptionKey : @"Server has closed connection without connack."}];
Expand Down Expand Up @@ -1321,85 +1321,23 @@ - (void)tell {
}
}

/*
* Threaded block callbacks
*/
- (void)onConnect:(MQTTConnectHandler)connectHandler error:(NSError *)error {
NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithObject:connectHandler forKey:@"Block"];
if (error) {
dict[@"Error"] = error;
}
NSThread *thread = [[NSThread alloc] initWithTarget:self selector:@selector(onConnectExecute:) object:dict];
[thread start];
}

- (void)onConnectExecute:(NSDictionary *)dict {
MQTTConnectHandler connectHandler = dict[@"Block"];
NSError *error = dict[@"Error"];
connectHandler(error);
}

- (void)onDisconnect:(MQTTDisconnectHandler)disconnectHandler error:(NSError *)error {
NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithObject:disconnectHandler forKey:@"Block"];
if (error) {
dict[@"Error"] = error;
}
NSThread *thread = [[NSThread alloc] initWithTarget:self selector:@selector(onDisconnectExecute:) object:dict];
[thread start];
}

- (void)onDisconnectExecute:(NSDictionary *)dict {
MQTTDisconnectHandler disconnectHandler = dict[@"Block"];
NSError *error = dict[@"Error"];
disconnectHandler(error);
}

- (void)onSubscribe:(MQTTSubscribeHandler)subscribeHandler error:(NSError *)error gQoss:(NSArray *)gqoss{
NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithObject:subscribeHandler forKey:@"Block"];
if (error) {
dict[@"Error"] = error;
}
if (gqoss) {
dict[@"GQoss"] = gqoss;
}
NSThread *thread = [[NSThread alloc] initWithTarget:self selector:@selector(onSubscribeExecute:) object:dict];
[thread start];
}

- (void)onSubscribeExecute:(NSDictionary *)dict {
MQTTSubscribeHandler subscribeHandler = dict[@"Block"];
NSError *error = dict[@"Error"];
NSArray *gqoss = dict[@"GQoss"];
- (void)onSubscribe:(MQTTSubscribeHandler)subscribeHandler error:(NSError *)error gQoss:(NSArray *)gqoss {
subscribeHandler(error, gqoss);
}

- (void)onUnsubscribe:(MQTTUnsubscribeHandler)unsubscribeHandler error:(NSError *)error {
NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithObject:unsubscribeHandler forKey:@"Block"];
if (error) {
dict[@"Error"] = error;
}
NSThread *thread = [[NSThread alloc] initWithTarget:self selector:@selector(onUnsubscribeExecute:) object:dict];
[thread start];
}

- (void)onUnsubscribeExecute:(NSDictionary *)dict {
MQTTUnsubscribeHandler unsubscribeHandler = dict[@"Block"];
NSError *error = dict[@"Error"];
unsubscribeHandler(error);
}

- (void)onPublish:(MQTTPublishHandler)publishHandler error:(NSError *)error {
NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithObject:publishHandler forKey:@"Block"];
if (error) {
dict[@"Error"] = error;
}
NSThread *thread = [[NSThread alloc] initWithTarget:self selector:@selector(onPublishExecute:) object:dict];
[thread start];
}

- (void)onPublishExecute:(NSDictionary *)dict {
MQTTPublishHandler publishHandler = dict[@"Block"];
NSError *error = dict[@"Error"];
publishHandler(error);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
*/
@property (strong, nonatomic) NSString *host;

/** url an NSURL containing the presigned URL
* defaults to nil
*/
@property (strong, nonatomic) NSURL *url;

/** port an unsigned 32 bit integer containing the IP port number to connect to
* defaults to 80
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ @implementation MQTTWebsocketTransport
@synthesize delegate;
@dynamic host;
@dynamic port;
@dynamic url;

- (instancetype)init {
self = [super init];
self.host = @"localhost";
self.port = 80;
self.url = nil;
self.path = @"/mqtt";
self.tls = false;
self.allowUntrustedCertificates = false;
Expand Down Expand Up @@ -54,6 +56,9 @@ - (void)open {
}

- (NSURL*) endpointURL {
if(self.url != nil) {
return self.url;
}
NSString *protocol = (self.tls) ? @"wss" : @"ws";
NSString *portString = (self.port == 0) ? @"" : [NSString stringWithFormat:@":%d",(unsigned int)self.port];
NSString *path = self.path;
Expand Down
6 changes: 6 additions & 0 deletions MQTTClient/MQTTClientTests/MQTTSessionTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#import "MQTTSession.h"
#import "MQTTSSLSecurityPolicyTransport.h"
#import "MQTTTestHelpers.h"
#import "MQTTLog.h"

@interface MQTTSessionTests : XCTestCase

Expand Down Expand Up @@ -54,15 +55,20 @@ - (void)testConnectDisconnectMultipleTimes {
dispatch_queue_t background = dispatch_queue_create("background", NULL);

__block MQTTSession *session = [MQTTTestHelpers session:parameters];
session.cleanSessionFlag = YES;
session.queue = background;
NSLog(@"[XY] connect");
[session connectWithConnectHandler:^(NSError *error) {
NSLog(@"[XY] connected");
XCTAssertNil(error);
XCTAssertEqual(session.status, MQTTSessionStatusConnected);
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
NSLog(@"[XY] destory session");
session = nil;
[expectation fulfill];
}];
}];
NSLog(@"[XY] wait for expecation");
[self waitForExpectationsWithTimeout:40 handler:nil];
}
}
Expand Down
4 changes: 2 additions & 2 deletions MQTTClient/MQTTClientTests/MQTTTestHelpers.plist
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
<key>host</key>
<string>0.0.0.0</string>
<key>timeout</key>
<integer>60</integer>
<integer>20</integer>
<key>port</key>
<integer>1883</integer>
<real>1883</real>
<key>tls</key>
<false/>
<key>protocollevel</key>
Expand Down
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,18 @@ Publish a message to a topic:
}];
```
If you already have a self signed URL from broker like AWS IoT endpoint, use the `url` property of `MQTTWebsocketTransport`:
```objective-c
MQTTWebsocketTransport *transport = [[MQTTWebsocketTransport alloc] init];
transport.url = @"wss://aws.iot-amazonaws.com/mqtt?expiry='2018-05-01T23:12:32.950Z'"
MQTTSession *session = [[MQTTSession alloc] init];
session.transport = transport;
[session connectWithConnectHandler:^(NSError *error) {
// Do some work
}];
```

## Installation

### CocoaPods
Expand Down Expand Up @@ -129,6 +141,10 @@ github "novastone-media/MQTT-Client-Framework"
3. Right click on it and select "Show in Finder" option.
4. Just drag and drop MQTTClient.framework to your project

## Security Disclosure

If you believe you have identified a security vulnerability with MQTT-Client-Framework, please report it to ios@novastonemedia.com and do not post it to a public issue tracker.

## Thanks

This project was originally written by [Christoph Krey](https://github.com/ckrey).

0 comments on commit 03cf44e

Please sign in to comment.