├── XcodeCoverage ├── .gitignore ├── cleancov ├── llvm-cov-wrapper.sh ├── exportenv.sh ├── run_code_coverage_post.sh ├── envcov.sh ├── LICENSE.txt ├── getcov └── README.md ├── .travis.yml ├── MDWampTests ├── en.lproj │ └── InfoPlist.strings ├── MDWampTests-Info.plist ├── MDWampSerializationMock.h ├── MDWampClientConfigTests.m ├── MDWampTransportdelegateMock.h ├── MDWampTransportMock.h ├── MDWampClientDelegateMock.h ├── MDWampSerializationMock.m ├── MDWampTransportdelegateMock.m ├── MDWampClientDelegateMock.m ├── MDWampSerializations.m ├── MDWampTestIncludes.h ├── MDStackTest.m ├── MDWampTransportMock.m ├── MDWampTransportRawSocketTests.m ├── MDWampProtocolVersion2Tests.m ├── MDWampTransportWebSocketTests.m └── XCTAsyncTestCase.m ├── MDWampDemo ├── resources │ ├── en.lproj │ │ └── InfoPlist.strings │ ├── link-32.png │ ├── save_as.png │ ├── online-32.png │ ├── save_as@2x.png │ ├── online-32@2x.png │ ├── run_command.png │ ├── broken_link-32.png │ ├── collaboration.png │ ├── run_command@2x.png │ ├── collaboration@2x.png │ └── Images.xcassets │ │ ├── first.imageset │ │ ├── first.png │ │ ├── first@2x.png │ │ └── Contents.json │ │ ├── second.imageset │ │ ├── second.png │ │ ├── second@2x.png │ │ └── Contents.json │ │ ├── AppIcon.appiconset │ │ └── Contents.json │ │ └── LaunchImage.launchimage │ │ └── Contents.json ├── src │ ├── main.m │ ├── AppDelegate.h │ ├── ChatStartViewController.h │ ├── CallRPCViewController.h │ ├── RegisterRPCViewController.h │ ├── ConnectViewController.h │ ├── ChatViewController.h │ ├── AppDelegate.m │ ├── ChatStartViewController.m │ ├── ConnectViewController.m │ ├── CallRPCViewController.m │ ├── RegisterRPCViewController.m │ └── ChatViewController.m ├── MDWampDemo-Prefix.pch └── MDWampDemo-Info.plist ├── MDWamp.xcodeproj ├── project.xcworkspace │ └── contents.xcworkspacedata └── xcshareddata │ └── xcschemes │ ├── libMDWamp.xcscheme │ ├── MDWampDemo.xcscheme │ └── MDWamp.xcscheme ├── MDWamp ├── MDWamp-Prefix.pch ├── src │ ├── MDWampMessages │ │ ├── MDWampCancel.h │ │ ├── MDWampChallenge.h │ │ ├── MDWampInterrupt.h │ │ ├── MDWampCancel.m │ │ ├── MDWampChallenge.m │ │ ├── MDWampInterrupt.m │ │ ├── MDWampUnsubscribed.h │ │ ├── MDWampUnregistered.h │ │ ├── MDWampAbort.h │ │ ├── MDWampGoodbye.h │ │ ├── MDWampMessage.h │ │ ├── MDWampPublished.h │ │ ├── MDWampRegistered.h │ │ ├── MDWampUnregister.h │ │ ├── MDWampAuthenticate.h │ │ ├── MDWampSubscribed.h │ │ ├── MDWampHello.h │ │ ├── MDWampRegister.h │ │ ├── MDWampUnsubscribe.h │ │ ├── MDWampSubscribe.h │ │ ├── MDWampYield.h │ │ ├── MDWampWelcome.h │ │ ├── MDWampInvocation.h │ │ ├── MDWampCall.h │ │ ├── MDWampPublish.h │ │ ├── MDWampResult.h │ │ ├── MDWampUnregistered.m │ │ ├── MDWampEvent.h │ │ ├── MDWampUnsubscribed.m │ │ ├── MDWampAbort.m │ │ ├── MDWampRegistered.m │ │ ├── MDWampUnregister.m │ │ ├── MDWampUnsubscribe.m │ │ ├── MDWampPublished.m │ │ ├── MDWampSubscribed.m │ │ ├── MDWampSubscribe.m │ │ ├── MDWampAuthenticate.m │ │ ├── MDWampGoodbye.m │ │ ├── MDWampError.h │ │ ├── MDWampHello.m │ │ ├── MDWampRegister.m │ │ ├── MDWampWelcome.m │ │ ├── MDWampMessages.h │ │ ├── MDWampYield.m │ │ ├── MDWampCall.m │ │ ├── MDWampInvocation.m │ │ ├── MDWampResult.m │ │ ├── MDWampPublish.m │ │ ├── MDWampEvent.m │ │ ├── MDWampError.m │ │ ├── MDWampMessageFactory.h │ │ └── MDWampMessageFactory.m │ ├── MDWampTransports │ │ ├── MDWampTransportRawSocket.h │ │ ├── MDWampTransports.h │ │ ├── MDWampTransportDelegate.h │ │ ├── MDWampTransport.h │ │ ├── MDWampTransportWebSocket.h │ │ ├── MDWampTransportRawSocket.m │ │ └── MDWampTransportWebSocket.m │ ├── MDWampConstants.m │ ├── Categories │ │ ├── NSString+MDString.h │ │ ├── NSMutableArray+MDStack.h │ │ ├── NSMutableArray+MDStack.m │ │ └── NSString+MDString.m │ ├── MDWampSerializations │ │ ├── MDWampSerializationJSON.h │ │ ├── MDWampSerializationMsgpack.h │ │ ├── MDWampSerialization.h │ │ ├── MDWampSerializations.h │ │ ├── MDWampSerializationMsgpack.m │ │ └── MDWampSerializationJSON.m │ ├── MDWampConstants.h │ ├── MDWampClientDelegate.h │ ├── MDWampClientConfig.m │ └── MDWampClientConfig.h └── MDWamp-Info.plist ├── .gitignore ├── .gitmodules ├── .crossbar └── config.json ├── MDWamp.podspec.json └── bump.py /XcodeCoverage/.gitignore: -------------------------------------------------------------------------------- 1 | env.sh 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: objective-c 2 | xcode_project: MDWamp.xcodeproj 3 | xcode_scheme: MDWamp -------------------------------------------------------------------------------- /MDWampTests/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /MDWampDemo/resources/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /MDWampDemo/resources/link-32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mogui/MDWamp/HEAD/MDWampDemo/resources/link-32.png -------------------------------------------------------------------------------- /MDWampDemo/resources/save_as.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mogui/MDWamp/HEAD/MDWampDemo/resources/save_as.png -------------------------------------------------------------------------------- /MDWampDemo/resources/online-32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mogui/MDWamp/HEAD/MDWampDemo/resources/online-32.png -------------------------------------------------------------------------------- /MDWampDemo/resources/save_as@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mogui/MDWamp/HEAD/MDWampDemo/resources/save_as@2x.png -------------------------------------------------------------------------------- /MDWampDemo/resources/online-32@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mogui/MDWamp/HEAD/MDWampDemo/resources/online-32@2x.png -------------------------------------------------------------------------------- /MDWampDemo/resources/run_command.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mogui/MDWamp/HEAD/MDWampDemo/resources/run_command.png -------------------------------------------------------------------------------- /MDWampDemo/resources/broken_link-32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mogui/MDWamp/HEAD/MDWampDemo/resources/broken_link-32.png -------------------------------------------------------------------------------- /MDWampDemo/resources/collaboration.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mogui/MDWamp/HEAD/MDWampDemo/resources/collaboration.png -------------------------------------------------------------------------------- /MDWampDemo/resources/run_command@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mogui/MDWamp/HEAD/MDWampDemo/resources/run_command@2x.png -------------------------------------------------------------------------------- /MDWampDemo/resources/collaboration@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mogui/MDWamp/HEAD/MDWampDemo/resources/collaboration@2x.png -------------------------------------------------------------------------------- /MDWampDemo/resources/Images.xcassets/first.imageset/first.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mogui/MDWamp/HEAD/MDWampDemo/resources/Images.xcassets/first.imageset/first.png -------------------------------------------------------------------------------- /MDWampDemo/resources/Images.xcassets/first.imageset/first@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mogui/MDWamp/HEAD/MDWampDemo/resources/Images.xcassets/first.imageset/first@2x.png -------------------------------------------------------------------------------- /MDWampDemo/resources/Images.xcassets/second.imageset/second.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mogui/MDWamp/HEAD/MDWampDemo/resources/Images.xcassets/second.imageset/second.png -------------------------------------------------------------------------------- /MDWampDemo/resources/Images.xcassets/second.imageset/second@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mogui/MDWamp/HEAD/MDWampDemo/resources/Images.xcassets/second.imageset/second@2x.png -------------------------------------------------------------------------------- /MDWamp.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /MDWamp/MDWamp-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header 3 | // 4 | // The contents of this file are implicitly included at the beginning of every source file. 5 | // 6 | 7 | #ifdef __OBJC__ 8 | #import 9 | #endif 10 | -------------------------------------------------------------------------------- /XcodeCoverage/cleancov: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Copyright 2014 Jonathan M. Reid. See LICENSE.txt 4 | # Created by: Jon Reid, http://qualitycoding.org/ 5 | # Source: https://github.com/jonreid/XcodeCoverage 6 | # 7 | 8 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 9 | source ${DIR}/envcov.sh 10 | 11 | LCOV --zerocounters -d "${OBJ_DIR}" 12 | -------------------------------------------------------------------------------- /XcodeCoverage/llvm-cov-wrapper.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Copyright 2014 Jonathan M. Reid. See LICENSE.txt 4 | # Created by: Jon Reid, http://qualitycoding.org/ 5 | # Source: https://github.com/jonreid/XcodeCoverage 6 | # 7 | 8 | if [ "$1" = "-v" ]; then 9 | echo "llvm-cov-wrapper 4.2.1" 10 | exit 0 11 | else 12 | /usr/bin/gcov $* 13 | fi 14 | -------------------------------------------------------------------------------- /XcodeCoverage/exportenv.sh: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2014 Jonathan M. Reid. See LICENSE.txt 3 | # Created by: Jon Reid, http://qualitycoding.org/ 4 | # Source: https://github.com/jonreid/XcodeCoverage 5 | # 6 | 7 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 8 | export | egrep '( BUILT_PRODUCTS_DIR)|(CURRENT_ARCH)|(OBJECT_FILE_DIR_normal)|(SRCROOT)|(OBJROOT)' > ${DIR}/env.sh 9 | -------------------------------------------------------------------------------- /MDWampDemo/resources/Images.xcassets/first.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x", 6 | "filename" : "first.png" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x", 11 | "filename" : "first@2x.png" 12 | } 13 | ], 14 | "info" : { 15 | "version" : 1, 16 | "author" : "xcode" 17 | } 18 | } -------------------------------------------------------------------------------- /MDWampDemo/resources/Images.xcassets/second.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x", 6 | "filename" : "second.png" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x", 11 | "filename" : "second@2x.png" 12 | } 13 | ], 14 | "info" : { 15 | "version" : 1, 16 | "author" : "xcode" 17 | } 18 | } -------------------------------------------------------------------------------- /MDWampDemo/src/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // MDWampDemo 4 | // 5 | // Created by Niko Usai on 27/06/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "AppDelegate.h" 12 | 13 | int main(int argc, char * argv[]) 14 | { 15 | @autoreleasepool { 16 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | MDWamp/build 3 | MDWampTest/build 4 | MDWamp/MDWamp.xcodeproj/project.xcworkspace/xcuserdata/* 5 | MDWamp/MDWamp.xcodeproj/xcuserdata/* 6 | MDWampTest/MDWampTest.xcodeproj/project.xcworkspace/xcuserdata/* 7 | MDWampTest/MDWampTest.xcodeproj/xcuserdata/* 8 | MDWamp.xcodeproj/project.xcworkspace/xcuserdata/* 9 | MDWamp.xcodeproj/xcuserdata/* 10 | MDWamp.xcodeproj/project.xcworkspace/xcshareddata 11 | Carthage 12 | -------------------------------------------------------------------------------- /MDWamp/src/MDWampMessages/MDWampCancel.h: -------------------------------------------------------------------------------- 1 | // 2 | // MDWampCancel.h 3 | // MDWamp 4 | // 5 | // Created by Niko Usai on 26/08/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "MDWampMessage.h" 11 | @interface MDWampCancel : NSObject 12 | @property (nonatomic, strong) NSNumber *request; 13 | @property (nonatomic, strong) NSDictionary *options; 14 | @end 15 | -------------------------------------------------------------------------------- /MDWamp/src/MDWampMessages/MDWampChallenge.h: -------------------------------------------------------------------------------- 1 | // 2 | // MDWampChallenge.h 3 | // MDWamp 4 | // 5 | // Created by Niko Usai on 26/08/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "MDWampMessage.h" 11 | @interface MDWampChallenge : NSObject 12 | @property (nonatomic, strong) NSString *authMethod; 13 | @property (nonatomic, strong) NSDictionary *extra; 14 | @end 15 | -------------------------------------------------------------------------------- /MDWamp/src/MDWampMessages/MDWampInterrupt.h: -------------------------------------------------------------------------------- 1 | // 2 | // MDWampInterrupt.h 3 | // MDWamp 4 | // 5 | // Created by Niko Usai on 26/08/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "MDWampMessage.h" 11 | @interface MDWampInterrupt : NSObject 12 | @property (nonatomic, strong) NSNumber *request; 13 | @property (nonatomic, strong) NSDictionary *options; 14 | @end 15 | -------------------------------------------------------------------------------- /MDWampDemo/src/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // MDWampDemo 4 | // 5 | // Created by Niko Usai on 27/06/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "MDWamp.h" 11 | 12 | 13 | 14 | @interface AppDelegate : UIResponder 15 | 16 | @property (strong, nonatomic) UIWindow *window; 17 | @property (strong, nonatomic) MDWamp *wampConnection; 18 | @end 19 | -------------------------------------------------------------------------------- /MDWampDemo/src/ChatStartViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ChatStartViewController.h 3 | // MDWamp 4 | // 5 | // Created by Niko Usai on 27/06/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ChatStartViewController : UIViewController 12 | @property (weak, nonatomic) IBOutlet UITextField *roomField; 13 | @property (weak, nonatomic) IBOutlet UITextField *nickField; 14 | 15 | - (IBAction)join:(id)sender; 16 | @end 17 | -------------------------------------------------------------------------------- /MDWampDemo/src/CallRPCViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // CallRPCViewController.h 3 | // MDWamp 4 | // 5 | // Created by Niko Usai on 04/07/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface CallRPCViewController : UIViewController 12 | 13 | @property (weak, nonatomic) IBOutlet UITextField *procedureName; 14 | @property (weak, nonatomic) IBOutlet UITextView *resultText; 15 | - (IBAction)callProcedure:(id)sender; 16 | @end 17 | -------------------------------------------------------------------------------- /MDWampDemo/resources/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "40x40", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "60x60", 16 | "scale" : "2x" 17 | } 18 | ], 19 | "info" : { 20 | "version" : 1, 21 | "author" : "xcode" 22 | } 23 | } -------------------------------------------------------------------------------- /MDWamp/src/MDWampTransports/MDWampTransportRawSocket.h: -------------------------------------------------------------------------------- 1 | // 2 | // RawSocketTransport.h 3 | // MDWamp 4 | // 5 | // Created by Niko Usai on 05/07/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "MDWampTransport.h" 11 | @interface MDWampTransportRawSocket : NSObject 12 | - (id)initWithHost:(NSString*)host port:(NSInteger)port; 13 | @property iddelegate; 14 | @property (nonatomic, strong) NSString *serialization; 15 | @end 16 | -------------------------------------------------------------------------------- /XcodeCoverage/run_code_coverage_post.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | button=`/usr/bin/osascript < 8 | #import "AppDelegate.h" 9 | 10 | #ifndef __IPHONE_5_0 11 | #warning "This project uses features only available in iOS SDK 5.0 and later." 12 | #endif 13 | 14 | #ifdef __OBJC__ 15 | #import 16 | #import 17 | 18 | 19 | #define AppDel (AppDelegate *)[[UIApplication sharedApplication] delegate] 20 | #endif 21 | -------------------------------------------------------------------------------- /MDWampDemo/resources/Images.xcassets/LaunchImage.launchimage/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "orientation" : "portrait", 5 | "idiom" : "iphone", 6 | "extent" : "full-screen", 7 | "minimum-system-version" : "7.0", 8 | "scale" : "2x" 9 | }, 10 | { 11 | "orientation" : "portrait", 12 | "idiom" : "iphone", 13 | "subtype" : "retina4", 14 | "extent" : "full-screen", 15 | "minimum-system-version" : "7.0", 16 | "scale" : "2x" 17 | } 18 | ], 19 | "info" : { 20 | "version" : 1, 21 | "author" : "xcode" 22 | } 23 | } -------------------------------------------------------------------------------- /MDWampDemo/src/RegisterRPCViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // RegisterRPCViewController.h 3 | // MDWamp 4 | // 5 | // Created by Niko Usai on 03/07/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface RegisterRPCViewController : UIViewController 12 | @property (weak, nonatomic) IBOutlet UITextField *procedureName; 13 | 14 | @property (weak, nonatomic) IBOutlet UISegmentedControl *procedureAction; 15 | @property (weak, nonatomic) IBOutlet UITextView *textArea; 16 | @property (weak, nonatomic) IBOutlet UIButton *registerButton; 17 | - (IBAction)register:(id)sender; 18 | @end 19 | -------------------------------------------------------------------------------- /MDWampDemo/src/ConnectViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // FirstViewController.h 3 | // MDWampDemo 4 | // 5 | // Created by Niko Usai on 27/06/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ConnectViewController : UIViewController 12 | @property (weak, nonatomic) IBOutlet UITextField *hostField; 13 | @property (weak, nonatomic) IBOutlet UITextField *realmField; 14 | @property (weak, nonatomic) IBOutlet UIButton *connectButton; 15 | @property (weak, nonatomic) IBOutlet UITextView *serverDetails; 16 | @property (weak, nonatomic) IBOutlet UIButton *connectIcon; 17 | 18 | 19 | - (IBAction)connect:(id)sender; 20 | @end 21 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "External/SocketRocket"] 2 | path = External/SocketRocket 3 | url = git://github.com/square/SocketRocket.git 4 | [submodule "External/msgpack-objectivec"] 5 | path = External/msgpack-objectivec 6 | url = git://github.com/msgpack/msgpack-objectivec.git 7 | [submodule "External/CocoaAsyncSocket"] 8 | path = External/CocoaAsyncSocket 9 | url = git://github.com/robbiehanson/CocoaAsyncSocket.git 10 | [submodule "External/xctest-additions"] 11 | path = External/xctest-additions 12 | url = git://github.com/iheartradio/xctest-additions.git 13 | [submodule "External/MPMessagePack"] 14 | path = External/MPMessagePack 15 | url = git://github.com/gabriel/MPMessagePack.git 16 | -------------------------------------------------------------------------------- /XcodeCoverage/envcov.sh: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2014 Jonathan M. Reid. See LICENSE.txt 3 | # Created by: Jon Reid, http://qualitycoding.org/ 4 | # Source: https://github.com/jonreid/XcodeCoverage 5 | # 6 | 7 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 8 | source ${DIR}/env.sh 9 | 10 | # Change the report name if you like: 11 | LCOV_INFO=Coverage.info 12 | 13 | XCODECOVERAGE_PATH="${SRCROOT}/XcodeCoverage" 14 | LCOV_PATH="${XCODECOVERAGE_PATH}/lcov-1.10/bin" 15 | OBJ_DIR=${OBJECT_FILE_DIR_normal}/${CURRENT_ARCH} 16 | 17 | # Fix for the new LLVM-COV that requires gcov to have a -v paramter 18 | LCOV() { 19 | ${LCOV_PATH}/lcov $* --gcov-tool ${XCODECOVERAGE_PATH}/llvm-cov-wrapper.sh 20 | } 21 | -------------------------------------------------------------------------------- /MDWampDemo/src/ChatViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // SecondViewController.h 3 | // MDWampDemo 4 | // 5 | // Created by Niko Usai on 27/06/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ChatViewController : UIViewController 12 | @property (weak, nonatomic) IBOutlet UILabel *roomNameField; 13 | @property (weak, nonatomic) IBOutlet UITableView *tableView; 14 | @property (weak, nonatomic) IBOutlet UITextField *inputText; 15 | @property (strong, nonatomic) NSString *nickname; 16 | @property (strong, nonatomic) NSString *room; 17 | @property (weak, nonatomic) IBOutlet UIView *inputControls; 18 | - (IBAction)part:(id)sender; 19 | - (IBAction)send:(id)sender; 20 | 21 | @end 22 | -------------------------------------------------------------------------------- /MDWampTests/MDWampTests-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundlePackageType 14 | BNDL 15 | CFBundleShortVersionString 16 | 1.0 17 | CFBundleSignature 18 | ???? 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /MDWamp/src/MDWampMessages/MDWampCancel.m: -------------------------------------------------------------------------------- 1 | // 2 | // MDWampCancel.m 3 | // MDWamp 4 | // 5 | // Created by Niko Usai on 26/08/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | 9 | #import "MDWampCancel.h" 10 | 11 | @implementation MDWampCancel 12 | - (id)initWithPayload:(NSArray *)payload 13 | { 14 | self = [super init]; 15 | if (self) { 16 | NSMutableArray *tmp = [payload mutableCopy]; 17 | // [CANCEL, CALL.Request|id, Options|dict] 18 | self.request = [tmp shift]; 19 | self.options = [tmp shift]; 20 | } 21 | return self; 22 | } 23 | 24 | - (NSArray *)marshall 25 | { 26 | NSNumber *code = [[MDWampMessageFactory sharedFactory] codeFromObject:self]; 27 | return @[code, self.request, self.options]; 28 | } 29 | 30 | @end 31 | -------------------------------------------------------------------------------- /MDWamp/src/MDWampMessages/MDWampChallenge.m: -------------------------------------------------------------------------------- 1 | // 2 | // MDWampChallenge.m 3 | // MDWamp 4 | // 5 | // Created by Niko Usai on 26/08/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | 9 | #import "MDWampChallenge.h" 10 | 11 | @implementation MDWampChallenge 12 | - (id)initWithPayload:(NSArray *)payload 13 | { 14 | self = [super init]; 15 | if (self) { 16 | NSMutableArray *tmp = [payload mutableCopy]; 17 | // [CHALLENGE, AuthMethod|string, Extra|dict] 18 | self.authMethod = [tmp shift]; 19 | self.extra = [tmp shift]; 20 | } 21 | return self; 22 | } 23 | 24 | - (NSArray *)marshall 25 | { 26 | NSNumber *code = [[MDWampMessageFactory sharedFactory] codeFromObject:self]; 27 | return @[code, self.authMethod, self.extra ]; 28 | } 29 | @end 30 | -------------------------------------------------------------------------------- /MDWamp/src/MDWampMessages/MDWampInterrupt.m: -------------------------------------------------------------------------------- 1 | // 2 | // MDWampInterrupt.m 3 | // MDWamp 4 | // 5 | // Created by Niko Usai on 26/08/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | 9 | #import "MDWampInterrupt.h" 10 | 11 | @implementation MDWampInterrupt 12 | - (id)initWithPayload:(NSArray *)payload 13 | { 14 | self = [super init]; 15 | if (self) { 16 | NSMutableArray *tmp = [payload mutableCopy]; 17 | // [INTERRUPT, INVOCATION.Request|id, Options|dict] 18 | self.request = [tmp shift]; 19 | self.options = [tmp shift]; 20 | } 21 | return self; 22 | } 23 | 24 | - (NSArray *)marshall 25 | { 26 | NSNumber *code = [[MDWampMessageFactory sharedFactory] codeFromObject:self]; 27 | return @[code, self.request, self.options]; 28 | } 29 | 30 | @end 31 | -------------------------------------------------------------------------------- /MDWamp/src/MDWampTransports/MDWampTransports.h: -------------------------------------------------------------------------------- 1 | // 2 | // Header.h 3 | // MDWamp 4 | // 5 | // Created by Niko Usai on 11/03/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | // 20 | 21 | #ifndef MDWampTransport_h 22 | #define MDWampTransport_h 23 | 24 | #import "MDWampTransportWebSocket.h" 25 | #import "MDWampTransportRawSocket.h" 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /MDWampTests/MDWampSerializationMock.h: -------------------------------------------------------------------------------- 1 | // 2 | // MDWampSerializationMock.h 3 | // MDWamp 4 | // 5 | // Created by Niko Usai on 12/03/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | // 20 | 21 | #import 22 | #import "MDWampSerialization.h" 23 | 24 | @interface MDWampSerializationMock : NSObject 25 | 26 | @end 27 | -------------------------------------------------------------------------------- /MDWamp/src/MDWampConstants.m: -------------------------------------------------------------------------------- 1 | // 2 | // MDWampConstants.m 3 | // MDWamp 4 | // 5 | // Created by Niko Usai on 08/07/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | 9 | #import "MDWampConstants.h" 10 | NSString *const kMDWampSerializationMsgpack = @"MDWampSerializationMsgpack"; 11 | NSString *const kMDWampSerializationJSON = @"MDWampSerializationJSON"; 12 | NSString *const kMDWampErrorDomain = @"it.mogui.MDWamp"; 13 | 14 | NSString *const MDWampOption_exclude_me = @"exclude_me"; 15 | NSString *const MDWampOption_disclose_me = @"disclose_me"; 16 | NSString *const MDWampOption_acknowledge = @"acknowledge"; 17 | NSString *const MDWampOption_receive_progress = @"receive_progress"; 18 | NSString *const MDWampOption_progress = @"progress"; 19 | NSString *const MDWampOption_exclude = @"exclude"; 20 | NSString *const MDWampOption_eligible = @"eligible"; 21 | NSString *const MDWampOption_match = @"match"; 22 | -------------------------------------------------------------------------------- /MDWamp/src/Categories/NSString+MDString.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSString+MDString.h 3 | // MDWamp 4 | // 5 | // Created by Niko Usai on 09/03/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | // 20 | 21 | #import 22 | 23 | @interface NSString (MDString) 24 | + (NSString*) stringWithRandomId; 25 | - (NSString *) hmacSHA256DataWithKey:(NSString *)key; 26 | @end 27 | -------------------------------------------------------------------------------- /MDWamp/src/MDWampSerializations/MDWampSerializationJSON.h: -------------------------------------------------------------------------------- 1 | // 2 | // MDWampSerializationJSON.h 3 | // MDWamp 4 | // 5 | // Created by Niko Usai on 09/03/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | // 20 | 21 | #import 22 | #import "MDWampSerialization.h" 23 | 24 | @interface MDWampSerializationJSON : NSObject 25 | 26 | @end 27 | -------------------------------------------------------------------------------- /MDWamp/src/MDWampMessages/MDWampUnsubscribed.h: -------------------------------------------------------------------------------- 1 | // 2 | // MDWampUnsubscribed.h 3 | // MDWamp 4 | // 5 | // Created by Niko Usai on 11/04/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | // 20 | 21 | #import 22 | #import "MDWampMessage.h" 23 | @interface MDWampUnsubscribed : NSObject 24 | @property (nonatomic, strong) NSNumber *request; 25 | @end 26 | -------------------------------------------------------------------------------- /MDWamp/src/MDWampSerializations/MDWampSerializationMsgpack.h: -------------------------------------------------------------------------------- 1 | // 2 | // MDWampSerializationMsgpack.h 3 | // MDWamp 4 | // 5 | // Created by Niko Usai on 24/06/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | // 20 | 21 | #import 22 | #import "MDWampSerialization.h" 23 | 24 | @interface MDWampSerializationMsgpack : NSObject 25 | 26 | @end 27 | -------------------------------------------------------------------------------- /MDWamp/src/MDWampSerializations/MDWampSerialization.h: -------------------------------------------------------------------------------- 1 | // 2 | // MDWampSerialization.h 3 | // MDWamp 4 | // 5 | // Created by Niko Usai on 09/03/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | // 20 | 21 | #import 22 | 23 | @protocol MDWampSerialization 24 | 25 | - (id) pack:(NSArray*)arguments; 26 | - (NSArray*) unpack:(NSData *)data; 27 | 28 | @end 29 | -------------------------------------------------------------------------------- /MDWamp/src/MDWampMessages/MDWampUnregistered.h: -------------------------------------------------------------------------------- 1 | // 2 | // MDWampUnregistered.h 3 | // MDWamp 4 | // 5 | // Created by Niko Usai on 22/04/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | // 20 | 21 | #import 22 | #import "MDWampMessage.h" 23 | 24 | @interface MDWampUnregistered : NSObject 25 | @property (nonatomic, strong) NSNumber *request; 26 | @end 27 | -------------------------------------------------------------------------------- /MDWamp/src/MDWampSerializations/MDWampSerializations.h: -------------------------------------------------------------------------------- 1 | // 2 | // MDWampSerialization.h 3 | // MDWamp 4 | // 5 | // Created by Niko Usai on 09/03/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | // 20 | 21 | #ifndef MDWamp_MDWampSerialization_h 22 | #define MDWamp_MDWampSerialization_h 23 | 24 | #import "MDWampSerializationJSON.h" 25 | #import "MDWampSerializationMsgpack.h" 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /.crossbar/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "workers": [ 3 | { 4 | "type": "router", 5 | "realms": [ 6 | { 7 | "name": "realm1", 8 | "roles": [ 9 | { 10 | "name": "anonymous", 11 | "permissions": [ 12 | { 13 | "uri": "*", 14 | "publish": true, 15 | "subscribe": true, 16 | "call": true, 17 | "register": true 18 | } 19 | ] 20 | } 21 | ] 22 | } 23 | ], 24 | "transports": [ 25 | { 26 | "type": "rawsocket", 27 | "serializer": "json", 28 | "endpoint": { 29 | "type": "tcp", 30 | "port": 9000 31 | }, 32 | "debug": true 33 | }, 34 | { 35 | "type": "websocket", 36 | "endpoint": { 37 | "type": "tcp", 38 | "port": 8080 39 | } 40 | } 41 | ] 42 | } 43 | ] 44 | } -------------------------------------------------------------------------------- /MDWamp/src/MDWampMessages/MDWampAbort.h: -------------------------------------------------------------------------------- 1 | // 2 | // MDWampAbort.h 3 | // MDWamp 4 | // 5 | // Created by Niko Usai on 08/03/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | // 20 | 21 | #import 22 | #import "MDWampMessage.h" 23 | 24 | @interface MDWampAbort : NSObject 25 | @property (nonatomic, strong) NSDictionary *details; 26 | @property (nonatomic, strong) NSString *reason; 27 | @end 28 | -------------------------------------------------------------------------------- /MDWamp/src/MDWampMessages/MDWampGoodbye.h: -------------------------------------------------------------------------------- 1 | // 2 | // MDWampGoodbye.h 3 | // MDWamp 4 | // 5 | // Created by Niko Usai on 08/03/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | // 20 | 21 | #import 22 | #import "MDWampMessage.h" 23 | 24 | @interface MDWampGoodbye : NSObject 25 | @property (nonatomic, strong) NSDictionary *details; 26 | @property (nonatomic, strong) NSString *reason; 27 | @end 28 | -------------------------------------------------------------------------------- /MDWamp/src/MDWampMessages/MDWampMessage.h: -------------------------------------------------------------------------------- 1 | // 2 | // MDWampMessage.h 3 | // MDWamp 4 | // 5 | // Created by Niko Usai on 08/03/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | // 20 | 21 | #import 22 | #import "MDWampConstants.h" 23 | #import "MDWampMessageFactory.h" 24 | 25 | @protocol MDWampMessage 26 | 27 | - (id) initWithPayload:(NSArray *)payload; 28 | - (NSArray *) marshall; 29 | @end 30 | 31 | -------------------------------------------------------------------------------- /MDWamp/src/MDWampMessages/MDWampPublished.h: -------------------------------------------------------------------------------- 1 | // 2 | // MDWampPublished.h 3 | // MDWamp 4 | // 5 | // Created by Niko Usai on 22/04/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | // 20 | 21 | #import 22 | #import "MDWampMessage.h" 23 | @interface MDWampPublished : NSObject 24 | @property (nonatomic, strong) NSNumber *request; 25 | @property (nonatomic, strong) NSNumber *publication; 26 | @end 27 | -------------------------------------------------------------------------------- /MDWamp/src/MDWampMessages/MDWampRegistered.h: -------------------------------------------------------------------------------- 1 | // 2 | // MDWampRegistered.h 3 | // MDWamp 4 | // 5 | // Created by Niko Usai on 22/04/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | // 20 | 21 | #import 22 | #import "MDWampMessage.h" 23 | @interface MDWampRegistered : NSObject 24 | @property (nonatomic, strong) NSNumber *request; 25 | @property (nonatomic, strong) NSNumber *registration; 26 | @end 27 | -------------------------------------------------------------------------------- /MDWamp/src/MDWampMessages/MDWampUnregister.h: -------------------------------------------------------------------------------- 1 | // 2 | // MDWampUnregister.h 3 | // MDWamp 4 | // 5 | // Created by Niko Usai on 22/04/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | // 20 | 21 | #import 22 | #import "MDWampMessage.h" 23 | @interface MDWampUnregister : NSObject 24 | @property (nonatomic, strong) NSNumber *request; 25 | @property (nonatomic, strong) NSNumber *registration; 26 | @end 27 | -------------------------------------------------------------------------------- /MDWamp/src/MDWampMessages/MDWampAuthenticate.h: -------------------------------------------------------------------------------- 1 | // 2 | // MDWampAuthenticate.h 3 | // MDWamp 4 | // 5 | // Created by Niko Usai on 26/08/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | // 20 | 21 | #import 22 | #import "MDWampMessage.h" 23 | @interface MDWampAuthenticate : NSObject 24 | @property (nonatomic, strong) NSString *signature; 25 | @property (nonatomic, strong) NSDictionary *extra; 26 | @end 27 | -------------------------------------------------------------------------------- /MDWamp/src/MDWampMessages/MDWampSubscribed.h: -------------------------------------------------------------------------------- 1 | // 2 | // MDWampSubscribed.h 3 | // MDWamp 4 | // 5 | // Created by Niko Usai on 10/04/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | // 20 | 21 | #import 22 | #import "MDWampMessage.h" 23 | 24 | @interface MDWampSubscribed : NSObject 25 | @property (nonatomic, strong) NSNumber *request; 26 | @property (nonatomic, strong) NSNumber *subscription; 27 | @end 28 | -------------------------------------------------------------------------------- /MDWamp.podspec.json: -------------------------------------------------------------------------------- 1 | { 2 | "osx": { 3 | "frameworks": [ 4 | "CFNetwork", 5 | "Security" 6 | ] 7 | }, 8 | "name": "MDWamp", 9 | "license": "Apache 2.0", 10 | "requires_arc": true, 11 | "authors": { 12 | "Niko Usai": "mogui83@gmail.com" 13 | }, 14 | "ios": { 15 | "frameworks": [ 16 | "MobileCoreServices", 17 | "CFNetwork", 18 | "Security" 19 | ] 20 | }, 21 | "summary": "A client side objective-C implementation of the WebSocket subprotocol WAMP", 22 | "libraries": "icucore", 23 | "platforms": { 24 | "osx": "10.8", 25 | "ios": "7.1" 26 | }, 27 | "version": "2.2.4", 28 | "source": { 29 | "git": "https://github.com/mogui/MDWamp.git", 30 | "tag": "2.2.4" 31 | }, 32 | "dependencies": { 33 | "CocoaAsyncSocket": [], 34 | "MPMessagePack": [], 35 | "SocketRocket": [] 36 | }, 37 | "source_files": "MDWamp/**/*.{h,m,c}", 38 | "homepage": "http://github.com/mogui/MDWamp" 39 | } -------------------------------------------------------------------------------- /MDWamp/MDWamp-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIconFile 10 | 11 | CFBundleIdentifier 12 | $(PRODUCT_BUNDLE_IDENTIFIER) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | ${PRODUCT_NAME} 17 | CFBundlePackageType 18 | FMWK 19 | CFBundleShortVersionString 20 | 2.2.4 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 2.2.0 25 | NSHumanReadableCopyright 26 | Copyright © 2013 mogui.it. All rights reserved. 27 | NSPrincipalClass 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /MDWamp/src/MDWampMessages/MDWampHello.h: -------------------------------------------------------------------------------- 1 | // 2 | // MDWampHello.h 3 | // MDWamp 4 | // 5 | // Created by Niko Usai on 08/03/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | // 20 | 21 | #import 22 | #import "MDWampMessage.h" 23 | 24 | @interface MDWampHello : NSObject 25 | @property (nonatomic, strong) NSString *realm; 26 | @property (nonatomic, strong) NSDictionary *details; 27 | @property (nonatomic, readonly) NSDictionary *roles; 28 | @end 29 | -------------------------------------------------------------------------------- /MDWamp/src/MDWampMessages/MDWampRegister.h: -------------------------------------------------------------------------------- 1 | // 2 | // MDWampRegister.h 3 | // MDWamp 4 | // 5 | // Created by Niko Usai on 22/04/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | // 20 | 21 | #import 22 | #import "MDWampMessage.h" 23 | @interface MDWampRegister : NSObject 24 | @property (nonatomic, strong) NSNumber *request; 25 | @property (nonatomic, strong) NSDictionary *options; 26 | @property (nonatomic, strong) NSString *procedure; 27 | @end 28 | -------------------------------------------------------------------------------- /MDWamp/src/MDWampMessages/MDWampUnsubscribe.h: -------------------------------------------------------------------------------- 1 | // 2 | // MDwampUnsubscribe.h 3 | // MDWamp 4 | // 5 | // Created by Niko Usai on 11/04/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | // 20 | 21 | #import 22 | #import "MDWampMessage.h" 23 | 24 | @interface MDWampUnsubscribe : NSObject 25 | @property (nonatomic, strong) NSString *topic; 26 | @property (nonatomic, strong) NSNumber *request; 27 | @property (nonatomic, strong) NSNumber *subscription; 28 | @end 29 | -------------------------------------------------------------------------------- /MDWamp/src/Categories/NSMutableArray+MDStack.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSMutableArray+MDStack.h 3 | // MDWamp 4 | // 5 | // Adds simple stack behavior to nsarry 6 | // 7 | // Created by Niko Usai on 08/03/14. 8 | // Copyright (c) 2014 mogui.it. All rights reserved. 9 | // 10 | // Licensed under the Apache License, Version 2.0 (the "License"); 11 | // you may not use this file except in compliance with the License. 12 | // You may obtain a copy of the License at 13 | // 14 | // http://www.apache.org/licenses/LICENSE-2.0 15 | // 16 | // Unless required by applicable law or agreed to in writing, software 17 | // distributed under the License is distributed on an "AS IS" BASIS, 18 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | // See the License for the specific language governing permissions and 20 | // limitations under the License. 21 | // 22 | 23 | #import 24 | 25 | @interface NSMutableArray (MDStack) 26 | - (id) shift __attribute((ns_returns_retained)); 27 | - (void) unshift:(id)object; 28 | - (id) pop __attribute((ns_returns_retained)); 29 | - (void) push:(id)object; 30 | @end 31 | -------------------------------------------------------------------------------- /MDWampTests/MDWampClientConfigTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // MDWampClientConfigTests.m 3 | // MDWamp 4 | // 5 | // Created by Niko Usai on 09/10/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "MDWampClientConfig.h" 11 | 12 | #define ROLES @{@"some role" : @"other"} 13 | #define AGENT @"MDWamp v2.2.0" 14 | 15 | @interface MDWampClientConfigTests : XCTestCase { 16 | MDWampClientConfig *conf; 17 | } 18 | @end 19 | 20 | @implementation MDWampClientConfigTests 21 | 22 | - (void)setUp { 23 | [super setUp]; 24 | conf = [[MDWampClientConfig alloc] init]; 25 | conf.roles = ROLES; 26 | conf.agent = AGENT; 27 | conf.authmethods = @[]; 28 | // Put setup code here. This method is called before the invocation of each test method in the class. 29 | } 30 | 31 | - (void)testGetHelloDetails { 32 | // This is an example of a functional test case. 33 | NSDictionary *d = @{@"roles" : ROLES, @"agent" : AGENT, @"authmethods":@[]}; 34 | NSDictionary *hello = [conf getHelloDetails]; 35 | XCTAssertEqualObjects(d, hello, @"Not proper details dictionary returned"); 36 | } 37 | 38 | @end 39 | -------------------------------------------------------------------------------- /MDWamp/src/MDWampMessages/MDWampSubscribe.h: -------------------------------------------------------------------------------- 1 | // 2 | // MDWampSubscribe.h 3 | // MDWamp 4 | // 5 | // Created by Niko Usai on 10/04/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | // 20 | 21 | #import 22 | #import "MDWampMessage.h" 23 | // [SUBSCRIBE, Request|id, Options|dict, Topic|uri] 24 | @interface MDWampSubscribe : NSObject 25 | @property (nonatomic, strong) NSNumber *request; 26 | @property (nonatomic, strong) NSDictionary *options; 27 | @property (nonatomic, strong) NSString *topic; 28 | @end 29 | -------------------------------------------------------------------------------- /MDWampTests/MDWampTransportdelegateMock.h: -------------------------------------------------------------------------------- 1 | // 2 | // MDWampTransportdelegateMock.h 3 | // MDWamp 4 | // 5 | // Created by Niko Usai on 17/06/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | // 20 | 21 | #import 22 | #import "MDWampTransportDelegate.h" 23 | @interface MDWampTransportDelegateMock : NSObject 24 | @property (assign) BOOL didReceiveCalled; 25 | @property (assign) BOOL didOpenCalled; 26 | @property (assign) BOOL didFailCalled; 27 | @property (assign) BOOL didCloseCalled; 28 | @end 29 | -------------------------------------------------------------------------------- /MDWamp/src/MDWampMessages/MDWampYield.h: -------------------------------------------------------------------------------- 1 | // 2 | // MDWampYield.h 3 | // MDWamp 4 | // 5 | // Created by Niko Usai on 22/04/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | // 20 | 21 | #import 22 | #import "MDWampMessage.h" 23 | 24 | @interface MDWampYield : NSObject 25 | 26 | @property (nonatomic, strong) NSNumber *request; 27 | @property (nonatomic, strong) NSDictionary *options; 28 | @property (nonatomic, strong) NSArray *arguments; 29 | @property (nonatomic, strong) NSDictionary *argumentsKw; 30 | 31 | @end 32 | -------------------------------------------------------------------------------- /XcodeCoverage/LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright 2014 Jonathan M. Reid 2 | All rights reserved. 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | this software and associated documentation files (the "Software"), to deal in 6 | the Software without restriction, including without limitation the rights to 7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 8 | the Software, and to permit persons to whom the Software is furnished to do so, 9 | subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 17 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 18 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | 21 | (MIT License) 22 | -------------------------------------------------------------------------------- /XcodeCoverage/getcov: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Copyright 2014 Jonathan M. Reid. See LICENSE.txt 4 | # Created by: Jon Reid, http://qualitycoding.org/ 5 | # Source: https://github.com/jonreid/XcodeCoverage 6 | # 7 | 8 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 9 | source ${DIR}/envcov.sh 10 | 11 | remove_old_report() 12 | { 13 | pushd ${BUILT_PRODUCTS_DIR} 14 | if [ -e lcov ]; then 15 | rm -r lcov 16 | fi 17 | popd 18 | } 19 | 20 | enter_lcov_dir() 21 | { 22 | cd ${BUILT_PRODUCTS_DIR} 23 | mkdir lcov 24 | cd lcov 25 | } 26 | 27 | gather_coverage() 28 | { 29 | LCOV --capture --derive-func-data -b "${SRCROOT}" -d "${OBJ_DIR}" -o ${LCOV_INFO} 30 | } 31 | 32 | exclude_data() 33 | { 34 | LCOV --remove ${LCOV_INFO} "Applications/Xcode.app/*" -d "${OBJ_DIR}" -o ${LCOV_INFO} 35 | LCOV --remove ${LCOV_INFO} "main.m" -d "${OBJ_DIR}" -o ${LCOV_INFO} 36 | # Remove other patterns here... 37 | } 38 | 39 | generate_report() 40 | { 41 | "${LCOV_PATH}/genhtml" --output-directory . ${LCOV_INFO} 42 | open index.html 43 | } 44 | 45 | remove_old_report 46 | enter_lcov_dir 47 | gather_coverage 48 | exclude_data 49 | generate_report 50 | -------------------------------------------------------------------------------- /MDWamp/src/MDWampMessages/MDWampWelcome.h: -------------------------------------------------------------------------------- 1 | // 2 | // MDWampWelcome.h 3 | // MDWamp 4 | // 5 | // Created by Niko Usai on 08/03/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | // 20 | 21 | #import 22 | #import "MDWampMessage.h" 23 | 24 | @interface MDWampWelcome : NSObject 25 | @property (nonatomic, strong) NSNumber *session; 26 | @property (nonatomic, strong) NSDictionary *details; 27 | @property (nonatomic, readonly) NSDictionary *roles; 28 | @property (nonatomic, strong) NSNumber *protocolVersion; 29 | @property (nonatomic, strong) NSString *serverIdent; 30 | @end 31 | -------------------------------------------------------------------------------- /MDWamp/src/MDWampMessages/MDWampInvocation.h: -------------------------------------------------------------------------------- 1 | // 2 | // MDWampInvocation.h 3 | // MDWamp 4 | // 5 | // Created by Niko Usai on 22/04/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | // 20 | 21 | #import 22 | #import "MDWampMessage.h" 23 | 24 | @interface MDWampInvocation : NSObject 25 | 26 | @property (nonatomic, strong) NSNumber *request; 27 | @property (nonatomic, strong) NSNumber *registration; 28 | @property (nonatomic, strong) NSDictionary *options; 29 | @property (nonatomic, strong) NSArray *arguments; 30 | @property (nonatomic, strong) NSDictionary *argumentsKw; 31 | 32 | @end 33 | -------------------------------------------------------------------------------- /MDWamp/src/MDWampConstants.h: -------------------------------------------------------------------------------- 1 | // 2 | // MDWampConstants.h 3 | // MDWamp 4 | // 5 | // Created by Niko Usai on 08/07/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "NSMutableArray+MDStack.h" 11 | #import "NSString+MDString.h" 12 | 13 | // Debug Boilerplate 14 | #ifdef DEBUG 15 | #define MDWampDebugLog(fmt, ...) NSLog((@"%s " fmt), __PRETTY_FUNCTION__, ##__VA_ARGS__); 16 | #else 17 | #define MDWampDebugLog(fmt, ...) 18 | #endif 19 | 20 | // Serialization Classes 21 | FOUNDATION_EXPORT NSString *const kMDWampSerializationMsgpack; 22 | FOUNDATION_EXPORT NSString *const kMDWampSerializationJSON; 23 | 24 | // NSError domain 25 | FOUNDATION_EXPORT NSString *const kMDWampErrorDomain; 26 | 27 | // OPTIONS 28 | FOUNDATION_EXPORT NSString *const MDWampOption_exclude_me; 29 | FOUNDATION_EXPORT NSString *const MDWampOption_disclose_me; 30 | FOUNDATION_EXPORT NSString *const MDWampOption_acknowledge; 31 | FOUNDATION_EXPORT NSString *const MDWampOption_receive_progress; 32 | FOUNDATION_EXPORT NSString *const MDWampOption_progress; 33 | FOUNDATION_EXPORT NSString *const MDWampOption_exclude; 34 | FOUNDATION_EXPORT NSString *const MDWampOption_eligible; 35 | FOUNDATION_EXPORT NSString *const MDWampOption_match; 36 | -------------------------------------------------------------------------------- /MDWamp/src/MDWampMessages/MDWampCall.h: -------------------------------------------------------------------------------- 1 | // 2 | // MDWampCall.h 3 | // MDWamp 4 | // 5 | // Created by Niko Usai on 22/04/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | // 20 | 21 | #import 22 | #import "MDWampMessage.h" 23 | 24 | @interface MDWampCall : NSObject 25 | @property (nonatomic, strong) NSNumber *request; 26 | @property (nonatomic, strong) NSString *callID; 27 | @property (nonatomic, strong) NSDictionary *options; 28 | @property (nonatomic, strong) NSString *procedure; 29 | @property (nonatomic, strong) NSArray *arguments; 30 | @property (nonatomic, strong) NSDictionary *argumentsKw; 31 | @end 32 | -------------------------------------------------------------------------------- /MDWamp/src/MDWampMessages/MDWampPublish.h: -------------------------------------------------------------------------------- 1 | // 2 | // MDWampPublish.h 3 | // MDWamp 4 | // 5 | // Created by Niko Usai on 10/04/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | // 20 | 21 | #import 22 | #import "MDWampMessage.h" 23 | 24 | @interface MDWampPublish : NSObject 25 | @property (nonatomic, strong) NSNumber *request; 26 | @property (nonatomic, strong) NSDictionary *options; 27 | @property (nonatomic, strong) NSString *topic; 28 | @property (nonatomic, strong) NSArray *arguments; 29 | @property (nonatomic, strong) NSDictionary *argumentsKw; 30 | @property (nonatomic, assign) NSDictionary *event; 31 | @end 32 | -------------------------------------------------------------------------------- /MDWamp/src/MDWampMessages/MDWampResult.h: -------------------------------------------------------------------------------- 1 | // 2 | // MDWampResult.h 3 | // MDWamp 4 | // 5 | // Created by Niko Usai on 22/04/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | // 20 | 21 | #import 22 | #import "MDWampMessage.h" 23 | 24 | @interface MDWampResult : NSObject 25 | @property (nonatomic, strong) NSNumber *request; 26 | @property (nonatomic, strong) NSString *callID; 27 | @property (nonatomic, strong) NSDictionary *options; 28 | @property (nonatomic, strong) NSArray *arguments; 29 | @property (nonatomic, strong) NSDictionary *argumentsKw; 30 | @property (nonatomic, strong) id result; 31 | @property (nonatomic, readonly) BOOL progress; 32 | @end 33 | -------------------------------------------------------------------------------- /MDWamp/src/MDWampMessages/MDWampUnregistered.m: -------------------------------------------------------------------------------- 1 | // 2 | // MDWampUnregistered.m 3 | // MDWamp 4 | // 5 | // Created by Niko Usai on 22/04/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | // 20 | 21 | #import "MDWampUnregistered.h" 22 | 23 | @implementation MDWampUnregistered 24 | - (id)initWithPayload:(NSArray *)payload 25 | { 26 | self = [super init]; 27 | if (self) { 28 | NSMutableArray *tmp = [payload mutableCopy]; 29 | self.request = [tmp shift]; 30 | } 31 | return self; 32 | } 33 | 34 | - (NSArray *)marshall 35 | { 36 | NSNumber *code = [[MDWampMessageFactory sharedFactory] codeFromObject:self]; 37 | return @[code, self.request]; 38 | } 39 | 40 | @end 41 | -------------------------------------------------------------------------------- /MDWamp/src/MDWampSerializations/MDWampSerializationMsgpack.m: -------------------------------------------------------------------------------- 1 | // 2 | // MDWampSerializationMsgpack.m 3 | // MDWamp 4 | // 5 | // Created by Niko Usai on 24/06/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | // 20 | 21 | #import "MDWampSerializationMsgpack.h" 22 | #import "MPMessagePack.h" 23 | 24 | 25 | @implementation MDWampSerializationMsgpack 26 | - (id) pack:(NSArray*)arguments 27 | { 28 | return [arguments mp_messagePack]; 29 | } 30 | 31 | - (NSArray*) unpack:(NSData *)data 32 | { 33 | NSError *error = nil; 34 | NSArray *unpacked = [MPMessagePackReader readData:data error:&error]; 35 | if (error) { 36 | return nil; 37 | } 38 | return unpacked; 39 | } 40 | @end 41 | -------------------------------------------------------------------------------- /MDWamp/src/MDWampMessages/MDWampEvent.h: -------------------------------------------------------------------------------- 1 | // 2 | // MDWampEvent.h 3 | // MDWamp 4 | // 5 | // Created by Niko Usai on 22/04/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | // 20 | 21 | #import 22 | #import "MDWampMessage.h" 23 | @interface MDWampEvent : NSObject 24 | @property (nonatomic, strong) NSNumber *subscription; 25 | @property (nonatomic, strong) NSNumber *publication; 26 | @property (nonatomic, strong) NSString *topic; 27 | @property (nonatomic, strong) NSDictionary *details; 28 | @property (nonatomic, strong) NSArray *arguments; 29 | @property (nonatomic, strong) NSDictionary *argumentsKw; 30 | @property (nonatomic, assign) NSDictionary *event; 31 | @end 32 | -------------------------------------------------------------------------------- /MDWamp/src/MDWampMessages/MDWampUnsubscribed.m: -------------------------------------------------------------------------------- 1 | // 2 | // MDWampUnsubscribed.m 3 | // MDWamp 4 | // 5 | // Created by Niko Usai on 11/04/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | // 20 | 21 | #import "MDWampUnsubscribed.h" 22 | 23 | @implementation MDWampUnsubscribed 24 | 25 | - (id)initWithPayload:(NSArray *)payload 26 | { 27 | self = [super init]; 28 | if (self) { 29 | NSMutableArray *tmp = [payload mutableCopy]; 30 | self.request = [tmp shift]; 31 | } 32 | return self; 33 | } 34 | 35 | 36 | - (NSArray *)marshall 37 | { 38 | NSNumber *code = [[MDWampMessageFactory sharedFactory] codeFromObject:self]; 39 | return @[code, self.request]; 40 | } 41 | @end 42 | -------------------------------------------------------------------------------- /MDWampTests/MDWampTransportMock.h: -------------------------------------------------------------------------------- 1 | // 2 | // MDWampTransportMock.h 3 | // MDWamp 4 | // 5 | // Created by Niko Usai on 12/03/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | // 20 | 21 | #import 22 | #import "MDWampTransport.h" 23 | 24 | @interface MDWampTransportMock : NSObject 25 | @property iddelegate; 26 | 27 | // test utility 28 | @property (assign) BOOL openWillFail; 29 | @property (nonatomic, strong) NSString *serializationClass; 30 | @property (nonatomic, strong) NSMutableArray *sendBuffer; 31 | - (void) triggerDidReceiveMessage:(id)msg; 32 | - (id)initWithServer:(NSURL *)request protocolVersions:(NSArray *)protocols; 33 | @end 34 | -------------------------------------------------------------------------------- /MDWamp/src/MDWampMessages/MDWampAbort.m: -------------------------------------------------------------------------------- 1 | // 2 | // MDWampAbort.m 3 | // MDWamp 4 | // 5 | // Created by Niko Usai on 08/03/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | // 20 | 21 | #import "MDWampAbort.h" 22 | 23 | @implementation MDWampAbort 24 | 25 | - (id)initWithPayload:(NSArray *)payload 26 | { 27 | self = [super init]; 28 | if (self) { 29 | NSMutableArray *tmp = [payload mutableCopy]; 30 | self.details = [tmp shift]; 31 | self.reason = [tmp shift]; 32 | } 33 | return self; 34 | } 35 | 36 | 37 | - (NSArray *)marshall 38 | { 39 | NSNumber *code = [[MDWampMessageFactory sharedFactory] codeFromObject:self]; 40 | return @[code, self.details, self.reason]; 41 | } 42 | 43 | @end 44 | -------------------------------------------------------------------------------- /MDWampTests/MDWampClientDelegateMock.h: -------------------------------------------------------------------------------- 1 | // 2 | // MDWampClientDelegateMock.h 3 | // MDWamp 4 | // 5 | // Created by Niko Usai on 13/12/13. 6 | // Copyright (c) 2013 mogui.it. All rights reserved. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | // 20 | 21 | #import 22 | #import "MDWampClientDelegate.h" 23 | 24 | @interface MDWampClientDelegateMock : NSObject 25 | 26 | @property (assign) BOOL onOpenCalled; 27 | @property (assign) BOOL onCloseCalled; 28 | @property (assign) BOOL onAuthReqWithAnswerCalled; 29 | @property (assign) BOOL onAuthSignWithSignatureCalled; 30 | @property (assign) BOOL onAuthWithAnswerCalled; 31 | @property (assign) BOOL onAuthFailForCallCalled; 32 | @property (nonatomic, copy) void (^onOpenCallback)(void); 33 | 34 | @end 35 | -------------------------------------------------------------------------------- /MDWamp/src/Categories/NSMutableArray+MDStack.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSMutableArray+MDStack.m 3 | // MDWamp 4 | // 5 | // Created by Niko Usai on 08/03/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | // 20 | 21 | #import "NSMutableArray+MDStack.h" 22 | 23 | @implementation NSMutableArray (MDStack) 24 | 25 | - (id) shift 26 | { 27 | id obj = [self objectAtIndex:0]; 28 | [self removeObjectAtIndex:0]; 29 | return obj; 30 | } 31 | 32 | - (void) unshift:(id)object 33 | { 34 | [self insertObject:object atIndex:0]; 35 | } 36 | 37 | - (id) pop 38 | { 39 | id obj = [self lastObject]; 40 | [self removeLastObject]; 41 | return obj; 42 | } 43 | 44 | - (void) push:(id)object 45 | { 46 | [self addObject:object]; 47 | } 48 | 49 | @end 50 | -------------------------------------------------------------------------------- /MDWamp/src/MDWampMessages/MDWampRegistered.m: -------------------------------------------------------------------------------- 1 | // 2 | // MDWampRegistered.m 3 | // MDWamp 4 | // 5 | // Created by Niko Usai on 22/04/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | // 20 | 21 | #import "MDWampRegistered.h" 22 | 23 | @implementation MDWampRegistered 24 | 25 | - (id)initWithPayload:(NSArray *)payload 26 | { 27 | self = [super init]; 28 | if (self) { 29 | NSMutableArray *tmp = [payload mutableCopy]; 30 | self.request = [tmp shift]; 31 | self.registration = [tmp shift]; 32 | } 33 | return self; 34 | } 35 | 36 | - (NSArray *)marshall 37 | { 38 | NSNumber *code = [[MDWampMessageFactory sharedFactory] codeFromObject:self]; 39 | return @[code, self.request, self.registration]; 40 | } 41 | 42 | @end 43 | -------------------------------------------------------------------------------- /MDWamp/src/MDWampMessages/MDWampUnregister.m: -------------------------------------------------------------------------------- 1 | // 2 | // MDWampUnregister.m 3 | // MDWamp 4 | // 5 | // Created by Niko Usai on 22/04/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | // 20 | 21 | #import "MDWampUnregister.h" 22 | 23 | @implementation MDWampUnregister 24 | 25 | - (id)initWithPayload:(NSArray *)payload 26 | { 27 | self = [super init]; 28 | if (self) { 29 | NSMutableArray *tmp = [payload mutableCopy]; 30 | self.request = [tmp shift]; 31 | self.registration = [tmp shift]; 32 | } 33 | return self; 34 | } 35 | 36 | - (NSArray *)marshall 37 | { 38 | NSNumber *code = [[MDWampMessageFactory sharedFactory] codeFromObject:self]; 39 | return @[code, self.request, self.registration]; 40 | } 41 | 42 | @end 43 | -------------------------------------------------------------------------------- /MDWamp/src/MDWampMessages/MDWampUnsubscribe.m: -------------------------------------------------------------------------------- 1 | // 2 | // MDwampUnsubscribe.m 3 | // MDWamp 4 | // 5 | // Created by Niko Usai on 11/04/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | // 20 | 21 | #import "MDWampUnsubscribe.h" 22 | 23 | @implementation MDWampUnsubscribe 24 | - (id)initWithPayload:(NSArray *)payload 25 | { 26 | self = [super init]; 27 | if (self) { 28 | NSMutableArray *tmp = [payload mutableCopy]; 29 | self.request = [tmp shift]; 30 | self.subscription = [tmp shift]; 31 | } 32 | return self; 33 | } 34 | 35 | 36 | - (NSArray *)marshall 37 | { 38 | NSNumber *code = [[MDWampMessageFactory sharedFactory] codeFromObject:self]; 39 | return @[code, self.request, self.subscription]; 40 | } 41 | @end 42 | -------------------------------------------------------------------------------- /MDWamp/src/MDWampMessages/MDWampPublished.m: -------------------------------------------------------------------------------- 1 | // 2 | // MDWampPublished.m 3 | // MDWamp 4 | // 5 | // Created by Niko Usai on 22/04/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | // 20 | 21 | #import "MDWampPublished.h" 22 | 23 | @implementation MDWampPublished 24 | 25 | 26 | - (id)initWithPayload:(NSArray *)payload 27 | { 28 | self = [super init]; 29 | if (self) { 30 | NSMutableArray *tmp = [payload mutableCopy]; 31 | self.request = [tmp shift]; 32 | self.publication = [tmp shift]; 33 | } 34 | return self; 35 | } 36 | 37 | 38 | - (NSArray *)marshall 39 | { 40 | NSNumber *code = [[MDWampMessageFactory sharedFactory] codeFromObject:self]; 41 | return @[code, self.request, self.publication]; 42 | } 43 | 44 | @end 45 | -------------------------------------------------------------------------------- /MDWamp/src/MDWampMessages/MDWampSubscribed.m: -------------------------------------------------------------------------------- 1 | // 2 | // MDWampSubscribed.m 3 | // MDWamp 4 | // 5 | // Created by Niko Usai on 10/04/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | // 20 | 21 | #import "MDWampSubscribed.h" 22 | 23 | @implementation MDWampSubscribed 24 | 25 | - (id)initWithPayload:(NSArray *)payload 26 | { 27 | self = [super init]; 28 | if (self) { 29 | NSMutableArray *tmp = [payload mutableCopy]; 30 | self.request = [tmp shift]; 31 | self.subscription = [tmp shift]; 32 | } 33 | return self; 34 | } 35 | 36 | 37 | - (NSArray *)marshall 38 | { 39 | NSNumber *code = [[MDWampMessageFactory sharedFactory] codeFromObject:self]; 40 | return @[code, self.request, self.subscription]; 41 | } 42 | 43 | 44 | @end 45 | -------------------------------------------------------------------------------- /MDWamp/src/MDWampMessages/MDWampSubscribe.m: -------------------------------------------------------------------------------- 1 | // 2 | // MDWampSubscribe.m 3 | // MDWamp 4 | // 5 | // Created by Niko Usai on 10/04/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | // 20 | 21 | #import "MDWampSubscribe.h" 22 | 23 | @implementation MDWampSubscribe 24 | 25 | - (id)initWithPayload:(NSArray *)payload 26 | { 27 | self = [super init]; 28 | if (self) { 29 | NSMutableArray *tmp = [payload mutableCopy]; 30 | self.request = [tmp shift]; 31 | self.options = [tmp shift]; 32 | self.topic = [tmp shift]; 33 | } 34 | return self; 35 | } 36 | 37 | - (NSArray *)marshall 38 | { 39 | NSNumber *code = [[MDWampMessageFactory sharedFactory] codeFromObject:self]; 40 | return @[code, self.request, self.options, self.topic]; 41 | } 42 | 43 | @end 44 | -------------------------------------------------------------------------------- /MDWamp/src/MDWampMessages/MDWampAuthenticate.m: -------------------------------------------------------------------------------- 1 | // 2 | // MDWampAuthenticate.m 3 | // MDWamp 4 | // 5 | // Created by Niko Usai on 26/08/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | // 20 | #import "MDWampAuthenticate.h" 21 | 22 | @implementation MDWampAuthenticate 23 | 24 | - (id)initWithPayload:(NSArray *)payload 25 | { 26 | self = [super init]; 27 | if (self) { 28 | NSMutableArray *tmp = [payload mutableCopy]; 29 | // [AUTHENTICATE, Signature|string, Extra|dict] 30 | self.signature = [tmp shift]; 31 | self.extra = [tmp shift]; 32 | } 33 | return self; 34 | } 35 | 36 | - (NSArray *)marshall 37 | { 38 | NSNumber *code = [[MDWampMessageFactory sharedFactory] codeFromObject:self]; 39 | return @[code, self.signature, self.extra]; 40 | } 41 | 42 | @end 43 | -------------------------------------------------------------------------------- /MDWamp/src/MDWampMessages/MDWampGoodbye.m: -------------------------------------------------------------------------------- 1 | // 2 | // MDWampGoodbye.m 3 | // MDWamp 4 | // 5 | // Created by Niko Usai on 08/03/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | // 20 | 21 | #import "MDWampGoodbye.h" 22 | 23 | @implementation MDWampGoodbye 24 | 25 | - (id)initWithPayload:(NSArray *)payload 26 | { 27 | self = [super init]; 28 | if (self) { 29 | NSMutableArray *tmp = [payload mutableCopy]; 30 | self.details = [tmp shift]; 31 | self.reason = [tmp shift]; 32 | } 33 | return self; 34 | } 35 | 36 | 37 | - (NSArray *)marshall 38 | { 39 | NSNumber *code = [[MDWampMessageFactory sharedFactory] codeFromObject:self]; 40 | return @[ 41 | code, 42 | self.details, 43 | self.reason 44 | ]; 45 | } 46 | 47 | 48 | @end 49 | -------------------------------------------------------------------------------- /MDWamp/src/MDWampMessages/MDWampError.h: -------------------------------------------------------------------------------- 1 | // 2 | // MDWampError.h 3 | // MDWamp 4 | // 5 | // Created by Niko Usai on 08/03/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | // 20 | 21 | #import 22 | #import "MDWampMessage.h" 23 | 24 | @interface MDWampError : NSObject 25 | @property (nonatomic, strong) NSNumber *type; 26 | @property (nonatomic, strong) NSNumber *request; 27 | @property (nonatomic, strong) NSString *callID; // Used in version 1 28 | @property (nonatomic, strong) NSDictionary *details; 29 | @property (nonatomic, strong) NSString *error; 30 | @property (nonatomic, strong) NSString *errorDesc; // Used in vesion 1 31 | @property (nonatomic, strong) NSArray *arguments; 32 | @property (nonatomic, strong) NSDictionary *argumentsKw; 33 | - (NSError *) makeError; 34 | @end 35 | -------------------------------------------------------------------------------- /MDWamp/src/MDWampMessages/MDWampHello.m: -------------------------------------------------------------------------------- 1 | // 2 | // MDWampHello.m 3 | // MDWamp 4 | // 5 | // Created by Niko Usai on 08/03/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | // 20 | 21 | #import "MDWampHello.h" 22 | 23 | @implementation MDWampHello 24 | 25 | - (id)initWithPayload:(NSArray *)payload 26 | { 27 | self = [super init]; 28 | if (self) { 29 | NSMutableArray *tmp = [payload mutableCopy]; 30 | self.realm = [tmp shift]; 31 | self.details = [tmp shift]; 32 | 33 | } 34 | return self; 35 | } 36 | 37 | - (NSArray *) marshall 38 | { 39 | NSNumber *code = [[MDWampMessageFactory sharedFactory] codeFromObject:self]; 40 | return @[code, self.realm, self.details ]; 41 | 42 | } 43 | 44 | - (NSDictionary*)roles 45 | { 46 | return self.details[@"roles"]; 47 | } 48 | 49 | @end 50 | -------------------------------------------------------------------------------- /MDWampTests/MDWampSerializationMock.m: -------------------------------------------------------------------------------- 1 | // 2 | // MDWampSerializationMock.m 3 | // MDWamp 4 | // 5 | // Created by Niko Usai on 12/03/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | // 20 | 21 | #import "MDWampSerializationMock.h" 22 | 23 | @implementation MDWampSerializationMock 24 | 25 | - (id) pack:(NSArray*)arguments; 26 | { 27 | return arguments; 28 | } 29 | 30 | - (NSArray*) unpack:(id)data 31 | { 32 | return data; 33 | } 34 | 35 | - (NSData*) packArguments:(id)firstObj, ... NS_REQUIRES_NIL_TERMINATION 36 | { 37 | NSMutableArray *argArray = [[NSMutableArray alloc] init]; 38 | va_list args; 39 | va_start(args, firstObj); 40 | 41 | for (id arg = firstObj; arg != nil; arg = va_arg(args, id)) { 42 | [argArray addObject:arg]; 43 | } 44 | 45 | va_end(args); 46 | 47 | return [self pack:argArray]; 48 | } 49 | 50 | @end 51 | -------------------------------------------------------------------------------- /MDWampTests/MDWampTransportdelegateMock.m: -------------------------------------------------------------------------------- 1 | // 2 | // MDWampTransportdelegateMock.m 3 | // MDWamp 4 | // 5 | // Created by Niko Usai on 17/06/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | // 20 | 21 | #import "MDWampTransportDelegateMock.h" 22 | @interface MDWampTransportDelegateMock () 23 | 24 | 25 | @end 26 | @implementation MDWampTransportDelegateMock 27 | 28 | // message will either be an NSString or NSData 29 | - (void)transportDidReceiveMessage:(NSData *)message { 30 | self.didReceiveCalled = YES; 31 | } 32 | 33 | - (void)transportDidOpenWithSerialization:(NSString*)serialization { 34 | self.didOpenCalled = YES; 35 | } 36 | 37 | - (void)transportDidFailWithError:(NSError *)error { 38 | self.didFailCalled = YES; 39 | } 40 | 41 | - (void)transportDidCloseWithError:(NSError *)error { 42 | self.didCloseCalled = YES; 43 | } 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /MDWamp/src/MDWampMessages/MDWampRegister.m: -------------------------------------------------------------------------------- 1 | // 2 | // MDWampRegister.m 3 | // MDWamp 4 | // 5 | // Created by Niko Usai on 22/04/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | // 20 | 21 | #import "MDWampRegister.h" 22 | 23 | @implementation MDWampRegister 24 | 25 | // [REGISTER, Request|id, Options|dict, Procedure|uri] 26 | 27 | - (id)initWithPayload:(NSArray *)payload 28 | { 29 | self = [super init]; 30 | if (self) { 31 | NSMutableArray *tmp = [payload mutableCopy]; 32 | self.request = [tmp shift]; 33 | self.options = [tmp shift]; 34 | self.procedure = [tmp shift]; 35 | } 36 | return self; 37 | } 38 | 39 | - (NSArray *)marshall 40 | { 41 | NSNumber *code = [[MDWampMessageFactory sharedFactory] codeFromObject:self]; 42 | return @[code, self.request, self.options, self.procedure]; 43 | } 44 | 45 | 46 | @end 47 | -------------------------------------------------------------------------------- /MDWamp/src/MDWampMessages/MDWampWelcome.m: -------------------------------------------------------------------------------- 1 | // 2 | // MDWampWelcome.m 3 | // MDWamp 4 | // 5 | // Created by Niko Usai on 08/03/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | // 20 | 21 | #import "MDWampWelcome.h" 22 | 23 | @implementation MDWampWelcome 24 | 25 | - (id)initWithPayload:(NSArray *)payload 26 | { 27 | self = [super init]; 28 | if (self) { 29 | NSMutableArray *tmp = [payload mutableCopy]; 30 | self.session = [tmp shift]; 31 | self.details = [tmp shift]; 32 | } 33 | return self; 34 | } 35 | 36 | 37 | - (NSArray *)marshall 38 | { 39 | NSNumber *code = [[MDWampMessageFactory sharedFactory] codeFromObject:self]; 40 | return @[ 41 | code, 42 | self.session, 43 | self.details 44 | ]; 45 | } 46 | 47 | - (NSDictionary *)roles 48 | { 49 | return self.details[@"roles"]; 50 | } 51 | @end 52 | -------------------------------------------------------------------------------- /MDWamp/src/MDWampTransports/MDWampTransportDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // MDWampTransportDelegate.h 3 | // MDWamp 4 | // 5 | // Created by Niko Usai on 11/03/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | // 20 | 21 | #import 22 | #import "MDWampConstants.h" 23 | 24 | @protocol MDWampTransportDelegate 25 | 26 | 27 | // message will either be an NSString or NSData 28 | - (void)transportDidReceiveMessage:(NSData *)message; 29 | 30 | @optional 31 | /** 32 | * Transport has correctly opened a connection 33 | */ 34 | - (void)transportDidOpenWithSerialization:(NSString *)serialization; 35 | 36 | /** 37 | * Transport Failed connection 38 | * 39 | * @param error 40 | */ 41 | - (void)transportDidFailWithError:(NSError *)error; 42 | 43 | /** 44 | * Transport Closed connection 45 | * 46 | * @param error 47 | */ 48 | - (void)transportDidCloseWithError:(NSError *)error; 49 | 50 | 51 | @end 52 | -------------------------------------------------------------------------------- /MDWamp/src/MDWampTransports/MDWampTransport.h: -------------------------------------------------------------------------------- 1 | // 2 | // MDWampTransportProtocol.h 3 | // MDWamp 4 | // 5 | // Created by Niko Usai on 11/03/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | // 20 | 21 | #import 22 | #import "MDWampTransportDelegate.h" 23 | #import "MDWampConstants.h" 24 | 25 | @class MDWampMessage; 26 | @protocol MDWampTransport 27 | 28 | /** 29 | * The transport delegate 30 | */ 31 | @property iddelegate; 32 | 33 | 34 | 35 | /** 36 | * Method used to open a connection to the transport 37 | */ 38 | - (void) open; 39 | 40 | /** 41 | * Method used to close a connection with the transport 42 | */ 43 | - (void) close; 44 | /** 45 | * Test the connection with the transport 46 | * 47 | * @return connection status 48 | */ 49 | - (BOOL) isConnected; 50 | 51 | /** 52 | * Method to send data on the transport 53 | */ 54 | - (void)send:(NSData *)data; 55 | 56 | @end 57 | -------------------------------------------------------------------------------- /MDWampDemo/MDWampDemo-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleDisplayName 8 | ${PRODUCT_NAME} 9 | CFBundleExecutable 10 | ${EXECUTABLE_NAME} 11 | CFBundleIdentifier 12 | $(PRODUCT_BUNDLE_IDENTIFIER) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | ${PRODUCT_NAME} 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1.0 25 | LSRequiresIPhoneOS 26 | 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UIStatusBarTintParameters 34 | 35 | UINavigationBar 36 | 37 | Style 38 | UIBarStyleDefault 39 | Translucent 40 | 41 | 42 | 43 | UISupportedInterfaceOrientations 44 | 45 | UIInterfaceOrientationPortrait 46 | UIInterfaceOrientationPortraitUpsideDown 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /MDWamp/src/MDWampSerializations/MDWampSerializationJSON.m: -------------------------------------------------------------------------------- 1 | // 2 | // MDWampSerializationJSON.m 3 | // MDWamp 4 | // 5 | // Created by Niko Usai on 09/03/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | // 20 | 21 | #import "MDWampSerializationJSON.h" 22 | 23 | @implementation MDWampSerializationJSON 24 | 25 | - (id) pack:(NSArray*)arguments 26 | { 27 | NSError *error = nil; 28 | NSData *jsonData = [NSJSONSerialization dataWithJSONObject:arguments options:0 error:&error]; 29 | if (error) { 30 | return nil; 31 | } 32 | 33 | return [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];; 34 | } 35 | 36 | - (NSArray*) unpack:(NSData *)data 37 | { 38 | NSData *d = data; 39 | if (![data isKindOfClass:[NSData class]]) { 40 | d = [(NSString*)data dataUsingEncoding:NSUTF8StringEncoding]; 41 | } 42 | return [NSJSONSerialization JSONObjectWithData:d options:NSJSONReadingAllowFragments error:nil]; 43 | } 44 | 45 | 46 | @end 47 | -------------------------------------------------------------------------------- /MDWamp/src/MDWampMessages/MDWampMessages.h: -------------------------------------------------------------------------------- 1 | // 2 | // MDWampMessages.h 3 | // MDWamp 4 | // 5 | // Created by Niko Usai on 09/03/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | // 20 | 21 | #ifndef MDWamp_MDWampMessages_h 22 | #define MDWamp_MDWampMessages_h 23 | 24 | #import "MDWampMessageFactory.h" 25 | #import "MDWampMessage.h" 26 | 27 | #import "MDWampHello.h" 28 | #import "MDWampWelcome.h" 29 | #import "MDWampGoodbye.h" 30 | #import "MDWampAbort.h" 31 | #import "MDWampError.h" 32 | 33 | #import "MDWampPublish.h" 34 | #import "MDWampPublished.h" 35 | #import "MDWampEvent.h" 36 | 37 | #import "MDWampSubscribe.h" 38 | #import "MDWampSubscribed.h" 39 | #import "MDWampUnsubscribe.h" 40 | #import "MDWampUnsubscribed.h" 41 | 42 | #import "MDWampRegister.h" 43 | #import "MDWampRegistered.h" 44 | #import "MDWampUnregister.h" 45 | #import "MDWampUnregistered.h" 46 | 47 | #import "MDWampCall.h" 48 | #import "MDWampResult.h" 49 | #import "MDWampInvocation.h" 50 | #import "MDWampYield.h" 51 | 52 | #import "MDWampChallenge.h" 53 | #import "MDWampAuthenticate.h" 54 | #import "MDWampCancel.h" 55 | #import "MDWampInterrupt.h" 56 | #endif 57 | -------------------------------------------------------------------------------- /MDWampTests/MDWampClientDelegateMock.m: -------------------------------------------------------------------------------- 1 | // 2 | // MDWampClientDelegateMock.m 3 | // MDWamp 4 | // 5 | // Created by Niko Usai on 13/12/13. 6 | // Copyright (c) 2013 mogui.it. All rights reserved. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | // 20 | 21 | #import "MDWampClientDelegateMock.h" 22 | 23 | @implementation MDWampClientDelegateMock 24 | 25 | - (void) mdwamp:(MDWamp *)wamp sessionEstablished:(NSDictionary *)info 26 | { 27 | self.onOpenCalled = YES; 28 | if(self.onOpenCallback){ 29 | self.onOpenCallback(); 30 | } 31 | } 32 | 33 | - (void) mdwamp:(MDWamp *)wamp closedSession:(NSInteger)code reason:(NSString*)reason details:(NSDictionary *)details 34 | { 35 | self.onCloseCalled = YES; 36 | } 37 | 38 | - (void) onAuthReqWithAnswer:(NSString *)answer 39 | { 40 | self.onAuthReqWithAnswerCalled = YES; 41 | } 42 | 43 | - (void) onAuthSignWithSignature:(NSString *)signature 44 | { 45 | self.onAuthSignWithSignatureCalled = YES; 46 | } 47 | 48 | - (void) onAuthWithAnswer:(NSString *)answer 49 | { 50 | self.onAuthWithAnswerCalled = YES; 51 | } 52 | 53 | - (void) onAuthFailForCall:(NSString *)procCall withError:(NSString *)errorDetails 54 | { 55 | self.onAuthFailForCallCalled = YES; 56 | } 57 | @end 58 | -------------------------------------------------------------------------------- /MDWamp/src/MDWampTransports/MDWampTransportWebSocket.h: -------------------------------------------------------------------------------- 1 | // 2 | // MDWampTransportWebSocket.h 3 | // MDWamp 4 | // 5 | // Created by Niko Usai on 11/03/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | // 20 | 21 | #import 22 | #import "MDWampTransport.h" 23 | 24 | FOUNDATION_EXPORT NSString *const kMDWampProtocolWamp2json; 25 | FOUNDATION_EXPORT NSString *const kMDWampProtocolWamp2msgpack; 26 | 27 | @interface MDWampTransportWebSocket : NSObject 28 | @property iddelegate; 29 | 30 | /** 31 | * Default initializer 32 | * By restricting the array of protocol versions we force to use a given protocol 33 | * they are in the form of wamp, wamp.2.json, wamp.2.msgpack 34 | * 35 | * @param request request representing a server 36 | * 37 | * @return intsance of the transport 38 | */ 39 | - (id)initWithServer:(NSURL *)request protocolVersions:(NSArray *)protocols; 40 | 41 | /** 42 | * Request Cookies 43 | * Sets the request cookies 44 | * 45 | * @param cookies cookies to be sent with the request (Array of NSHTTPCookie objects) 46 | */ 47 | - (void)setRequestCookies:(NSArray *)requestCookies; 48 | 49 | @end 50 | -------------------------------------------------------------------------------- /MDWampTests/MDWampSerializations.m: -------------------------------------------------------------------------------- 1 | // 2 | // MDWampSerializationJSONTests.m 3 | // MDWamp 4 | // 5 | // Created by Niko Usai on 18/06/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | // 20 | 21 | #import 22 | #import "MDWampSerializations.h" 23 | 24 | @interface MDWampSerializations : XCTestCase 25 | { 26 | id ser; 27 | } 28 | @end 29 | 30 | @implementation MDWampSerializations 31 | 32 | - (void)setUp 33 | { 34 | [super setUp]; 35 | 36 | } 37 | 38 | - (void)testPackJson 39 | { 40 | ser = [[MDWampSerializationJSON alloc] init]; 41 | NSArray *a = @[@1, @2]; 42 | NSString *json = [ser pack:a]; 43 | XCTAssertEqualObjects(json , @"[1,2]" , @"Must return correct json"); 44 | } 45 | 46 | - (void)testUnpackJson 47 | { 48 | ser = [[MDWampSerializationJSON alloc] init]; 49 | NSString *json = @"[1,2]"; 50 | NSArray *a = [ser unpack:json]; 51 | NSArray *arr = @[@1,@2]; 52 | XCTAssertEqualObjects(a, arr, @"Must return correct object"); 53 | } 54 | 55 | - (void)testMsgpack { 56 | ser = [[MDWampSerializationMsgpack alloc] init]; 57 | NSArray *a = @[@1, @2]; 58 | NSData *s = [ser pack:a]; 59 | XCTAssertEqualObjects(a, [ser unpack:s], @"Must be the same as start"); 60 | } 61 | 62 | 63 | 64 | @end 65 | -------------------------------------------------------------------------------- /MDWamp/src/Categories/NSString+MDString.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSString+MDString.m 3 | // MDWamp 4 | // 5 | // Created by Niko Usai on 09/03/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | // 20 | 21 | #import "NSString+MDString.h" 22 | #include 23 | #include 24 | 25 | @implementation NSString (MDString) 26 | 27 | + (NSString*) stringWithRandomId 28 | { 29 | NSInteger ii; 30 | NSString *allletters = @"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuwxyz0123456789"; 31 | NSString *outstring = @""; 32 | for (ii=0; ii<20; ii++) { 33 | outstring = [outstring stringByAppendingString:[allletters substringWithRange:[allletters rangeOfComposedCharacterSequenceAtIndex:random()%[allletters length]]]]; 34 | } 35 | 36 | return outstring; 37 | } 38 | 39 | - (NSString *) hmacSHA256DataWithKey:(NSString *)key 40 | { 41 | const char *cKey = [key cStringUsingEncoding:NSASCIIStringEncoding]; 42 | const char *cData = [self cStringUsingEncoding:NSASCIIStringEncoding]; 43 | 44 | unsigned char cHMAC[CC_SHA256_DIGEST_LENGTH]; 45 | 46 | CCHmac(kCCHmacAlgSHA256, cKey, strlen(cKey), cData, strlen(cData), cHMAC); 47 | return [[NSData dataWithBytes:cHMAC length:CC_SHA1_DIGEST_LENGTH] base64EncodedStringWithOptions:0]; 48 | } 49 | 50 | 51 | @end 52 | -------------------------------------------------------------------------------- /MDWamp/src/MDWampMessages/MDWampYield.m: -------------------------------------------------------------------------------- 1 | // 2 | // MDWampYield.m 3 | // MDWamp 4 | // 5 | // Created by Niko Usai on 22/04/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | // 20 | 21 | #import "MDWampYield.h" 22 | 23 | @implementation MDWampYield 24 | 25 | - (id)initWithPayload:(NSArray *)payload 26 | { 27 | self = [super init]; 28 | if (self) { 29 | NSMutableArray *tmp = [payload mutableCopy]; 30 | // [YIELD, INVOCATION.Request|id, Options|dict, Arguments|list, ArgumentsKw|dict] 31 | 32 | self.request = [tmp shift]; 33 | self.options = [tmp shift]; 34 | if ([tmp count] > 0) self.arguments = [tmp shift]; 35 | if ([tmp count] > 0) self.argumentsKw = [tmp shift]; 36 | } 37 | return self; 38 | } 39 | 40 | - (NSArray *)marshall 41 | { 42 | NSNumber *code = [[MDWampMessageFactory sharedFactory] codeFromObject:self]; 43 | if (self.arguments && self.argumentsKw) { 44 | return @[code, self.request, self.options, self.arguments, self.argumentsKw ]; 45 | } else if(self.arguments) { 46 | return @[code, self.request, self.options, self.arguments ]; 47 | } else if(self.argumentsKw) { 48 | return @[code, self.request, self.options, @[], self.argumentsKw ]; 49 | } else { 50 | return @[code, self.request, self.options]; 51 | } 52 | } 53 | 54 | 55 | @end 56 | -------------------------------------------------------------------------------- /MDWampTests/MDWampTestIncludes.h: -------------------------------------------------------------------------------- 1 | // 2 | // MDWampTest.h 3 | // MDWamp 4 | // 5 | // Created by Niko Usai on 13/12/13. 6 | // Copyright (c) 2013 mogui.it. All rights reserved. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | // 20 | 21 | #ifndef MDWamp_MDWampTest_h 22 | #define MDWamp_MDWampTest_h 23 | 24 | /* 25 | * Wamp autobahn testsute server url, 26 | * launched by a simple wstest -d -m wampserver -w URL 27 | */ 28 | #define kMDWampTestsServerV1URL @"ws://localhost:9000" 29 | /** 30 | * Wamp Crossbar server url 31 | * launched with all defaults crossbar start 32 | */ 33 | #define kMDWampTestsServerV2URL @"ws://localhost:8080/ws" 34 | 35 | /* 36 | * Define the time a single tests wait for a network call to end 37 | * Increase if test server response are slow 38 | */ 39 | #define kMDWampTestsNetworkWait 1 40 | 41 | /** 42 | * Handler method to dispatch after some seconds 43 | * in order to wait for a network reply 44 | * 45 | * @param blockToRun - the block of code to run 46 | */ 47 | static inline void wait_for_network(void (^blockToRun)(void) ){ 48 | dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(kMDWampTestsNetworkWait * NSEC_PER_SEC)); 49 | dispatch_after(popTime, dispatch_get_main_queue(), blockToRun); 50 | } 51 | 52 | #define kMDWampSerializationMock @"MDWampSerializationMock" 53 | 54 | #import "MDWampClientDelegateMock.h" 55 | #import "MDWampTransportMock.h" 56 | #import "MDWampSerializationMock.h" 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /MDWamp/src/MDWampMessages/MDWampCall.m: -------------------------------------------------------------------------------- 1 | // 2 | // MDWampCall.m 3 | // MDWamp 4 | // 5 | // Created by Niko Usai on 22/04/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | // 20 | 21 | #import "MDWampCall.h" 22 | 23 | @implementation MDWampCall 24 | 25 | - (id)initWithPayload:(NSArray *)payload 26 | { 27 | self = [super init]; 28 | if (self) { 29 | NSMutableArray *tmp = [payload mutableCopy]; 30 | // [CALL, Request|id, Options|dict, Procedure|uri, Arguments|list, ArgumentsKw|dict] 31 | self.request = [tmp shift]; 32 | self.options = [tmp shift]; 33 | self.procedure = [tmp shift]; 34 | if ([tmp count] > 0) self.arguments = [tmp shift]; 35 | if ([tmp count] > 0) self.argumentsKw = [tmp shift]; 36 | } 37 | return self; 38 | } 39 | 40 | - (NSArray *)marshall 41 | { 42 | NSNumber *code = [[MDWampMessageFactory sharedFactory] codeFromObject:self]; 43 | if (self.arguments && self.argumentsKw) { 44 | return @[code, self.request, self.options, self.procedure, self.arguments, self.argumentsKw ]; 45 | } else if(self.arguments) { 46 | return @[code, self.request, self.options, self.procedure, self.arguments ]; 47 | } else if(self.argumentsKw) { 48 | return @[code, self.request, self.options, self.procedure, @[], self.argumentsKw ]; 49 | } else { 50 | return @[code,self.request, self.options, self.procedure]; 51 | } 52 | } 53 | 54 | @end 55 | -------------------------------------------------------------------------------- /MDWamp/src/MDWampMessages/MDWampInvocation.m: -------------------------------------------------------------------------------- 1 | // 2 | // MDWampInvocation.m 3 | // MDWamp 4 | // 5 | // Created by Niko Usai on 22/04/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | // 20 | 21 | #import "MDWampInvocation.h" 22 | 23 | @implementation MDWampInvocation 24 | 25 | - (id)initWithPayload:(NSArray *)payload 26 | { 27 | self = [super init]; 28 | if (self) { 29 | NSMutableArray *tmp = [payload mutableCopy]; 30 | // [INVOCATION, Request|id, REGISTERED.Registration|id, options|dict, CALL.Arguments|list, CALL.ArgumentsKw|dict] 31 | 32 | self.request = [tmp shift]; 33 | self.registration = [tmp shift]; 34 | self.options = [tmp shift]; 35 | if ([tmp count] > 0) self.arguments = [tmp shift]; 36 | if ([tmp count] > 0) self.argumentsKw = [tmp shift]; 37 | } 38 | return self; 39 | } 40 | 41 | - (NSArray *)marshall 42 | { 43 | NSNumber *code = [[MDWampMessageFactory sharedFactory] codeFromObject:self]; 44 | if (self.arguments && self.argumentsKw) { 45 | return @[code, self.request, self.registration, self.options, self.arguments, self.argumentsKw ]; 46 | } else if(self.arguments) { 47 | return @[code, self.request, self.registration, self.options, self.arguments ]; 48 | } else if(self.argumentsKw) { 49 | return @[code, self.request, self.registration, self.options, @[], self.argumentsKw ]; 50 | } else { 51 | return @[code, self.request, self.registration, self.options]; 52 | } 53 | } 54 | 55 | @end 56 | -------------------------------------------------------------------------------- /MDWampDemo/src/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // MDWampDemo 4 | // 5 | // Created by Niko Usai on 27/06/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | 11 | @implementation AppDelegate 12 | 13 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 14 | { 15 | // Override point for customization after application launch. 16 | 17 | return YES; 18 | } 19 | 20 | - (void)applicationWillResignActive:(UIApplication *)application 21 | { 22 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 23 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 24 | } 25 | 26 | - (void)applicationDidEnterBackground:(UIApplication *)application 27 | { 28 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 29 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 30 | } 31 | 32 | - (void)applicationWillEnterForeground:(UIApplication *)application 33 | { 34 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 35 | } 36 | 37 | - (void)applicationDidBecomeActive:(UIApplication *)application 38 | { 39 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 40 | } 41 | 42 | - (void)applicationWillTerminate:(UIApplication *)application 43 | { 44 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 45 | } 46 | 47 | @end 48 | -------------------------------------------------------------------------------- /MDWampDemo/src/ChatStartViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ChatStartViewController.m 3 | // MDWamp 4 | // 5 | // Created by Niko Usai on 27/06/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | 9 | #import "ChatStartViewController.h" 10 | #import "ChatViewController.h" 11 | @interface ChatStartViewController () 12 | 13 | @end 14 | 15 | @implementation ChatStartViewController 16 | 17 | - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 18 | { 19 | self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 20 | if (self) { 21 | // Custom initialization 22 | } 23 | return self; 24 | } 25 | 26 | - (void)viewDidLoad 27 | { 28 | [super viewDidLoad]; 29 | // Do any additional setup after loading the view. 30 | } 31 | - (void) viewDidAppear:(BOOL)animated 32 | { 33 | dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ 34 | if (![[AppDel wampConnection] isConnected]) { 35 | 36 | self.tabBarController.selectedViewController = self.tabBarController.viewControllers[0]; 37 | 38 | UIAlertView *av = [[UIAlertView alloc] initWithTitle:@"!!" message:@"You must first connect!" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil]; 39 | [av show]; 40 | } 41 | 42 | }); 43 | } 44 | - (void)didReceiveMemoryWarning 45 | { 46 | [super didReceiveMemoryWarning]; 47 | // Dispose of any resources that can be recreated. 48 | } 49 | 50 | /* 51 | #pragma mark - Navigation 52 | 53 | // In a storyboard-based application, you will often want to do a little preparation before navigation 54 | - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 55 | { 56 | // Get the new view controller using [segue destinationViewController]. 57 | // Pass the selected object to the new view controller. 58 | } 59 | */ 60 | - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { 61 | ChatViewController *vc = segue.destinationViewController; 62 | vc.room = self.roomField.text; 63 | vc.nickname = self.nickField.text; 64 | } 65 | 66 | - (IBAction)join:(id)sender { 67 | } 68 | @end 69 | -------------------------------------------------------------------------------- /MDWamp/src/MDWampMessages/MDWampResult.m: -------------------------------------------------------------------------------- 1 | // 2 | // MDWampResult.m 3 | // MDWamp 4 | // 5 | // Created by Niko Usai on 22/04/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | // 20 | 21 | #import "MDWampResult.h" 22 | 23 | @implementation MDWampResult 24 | 25 | - (id)initWithPayload:(NSArray *)payload 26 | { 27 | self = [super init]; 28 | if (self) { 29 | NSMutableArray *tmp = [payload mutableCopy]; 30 | // [RESULT, CALL.Request|id, options|dict, YIELD.Arguments|list, YIELD.ArgumentsKw|dict] 31 | self.request = [tmp shift]; 32 | self.options = [tmp shift]; 33 | if ([tmp count] > 0) self.arguments = [tmp shift]; 34 | if ([tmp count] > 0) self.argumentsKw = [tmp shift]; 35 | } 36 | return self; 37 | } 38 | 39 | - (NSArray *)marshall 40 | { 41 | NSNumber *code = [[MDWampMessageFactory sharedFactory] codeFromObject:self]; 42 | if (self.arguments && self.argumentsKw) { 43 | return @[code, self.request, self.options, self.arguments, self.argumentsKw ]; 44 | } else if(self.arguments) { 45 | return @[code, self.request, self.options, self.arguments ]; 46 | } else if(self.argumentsKw) { 47 | return @[code, self.request, self.options, @[], self.argumentsKw ]; 48 | } else { 49 | return @[code, self.request, self.options]; 50 | } 51 | } 52 | 53 | - (void)setResult:(id)result 54 | { 55 | self.arguments = @[result]; 56 | } 57 | 58 | - (id)result 59 | { 60 | return self.arguments[0]; 61 | } 62 | 63 | - (BOOL)progress { 64 | return [self.options[@"progress"] boolValue]; 65 | } 66 | @end 67 | -------------------------------------------------------------------------------- /XcodeCoverage/README.md: -------------------------------------------------------------------------------- 1 | ![XcodeCoverage](http://qualitycoding.org/jrwp/wp-content/uploads/2014/03/XcodeCoverage.png) 2 | 3 | These scripts provide a simple way to generate HTML reports of the code coverage 4 | of your Xcode project. 5 | 6 | 7 | Installation 8 | ============ 9 | 10 | 1. Fork this repository; you're probably going to want to make your own 11 | modifications. 12 | 2. Place the XcodeCoverage folder in the same folder as your Xcode project. 13 | 3. Depending on your version of Xcode, you may need to get Xcode's coverage 14 | instrumentation by going to Xcode Preferences, into Downloads, and installing 15 | Command Line Tools. 16 | 4. In your Xcode project, enable these two build settings at the project level 17 | for your Debug configuration only: 18 | * Instrument Program Flow 19 | * Generate Test Coverage Files 20 | 5. In your main target, add a Run Script build phase to execute 21 | ``XcodeCoverage/exportenv.sh`` 22 | 23 | A few people have been tripped up by the last step: Make sure you add the 24 | script to your main target (your app or library), not your test target. 25 | 26 | 27 | Execution 28 | ========= 29 | 30 | 1. Run your unit tests 31 | 2. In Terminal, execute `getcov` in your project's XcodeCoverage folder. 32 | 33 | If you make changes to your test code without changing the production code and 34 | want a clean slate, use the ``cleancov`` script. 35 | 36 | If you make changes to your production code, you should clear out all build 37 | artifacts before measuring code coverage again. "Clean Build Folder" by holding 38 | down the Option key in Xcode's "Product" menu. 39 | 40 | **Optional:** XcodeCoverage can prompt to run code coverage after running unit tests: 41 | 42 | * Edit Xcode scheme -> Test -> Post-actions 43 | * Set "Shell" to: ``/bin/bash`` 44 | * Set "Provide build settings from" to your main target 45 | * Set script to: 46 | ``source ${SRCROOT}/XcodeCoverage/run_code_coverage_post.sh`` 47 | 48 | 49 | Modification 50 | ============ 51 | 52 | There are two places you may want to modify: 53 | 54 | 1. In envcov.sh, ``LCOV_INFO`` determines the name shown in the report. 55 | 2. In getcov, edit ``exclude_data()`` to specify which files to exclude, for 56 | example, third-party libraries. 57 | -------------------------------------------------------------------------------- /MDWamp/src/MDWampMessages/MDWampPublish.m: -------------------------------------------------------------------------------- 1 | // 2 | // MDWampPublish.m 3 | // MDWamp 4 | // 5 | // Created by Niko Usai on 10/04/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | // 20 | 21 | #import "MDWampPublish.h" 22 | 23 | @implementation MDWampPublish 24 | 25 | - (id)initWithPayload:(NSArray *)payload 26 | { 27 | self = [super init]; 28 | if (self) { 29 | NSMutableArray *tmp = [payload mutableCopy]; 30 | // [PUBLISH, Request|id, Options|dict, Topic|uri, Arguments|list, ArgumentsKw|dict] 31 | self.request = [tmp shift]; 32 | self.options = [tmp shift]; 33 | self.topic = [tmp shift]; 34 | if ([tmp count] > 0) self.arguments = [tmp shift]; 35 | if ([tmp count] > 0) self.argumentsKw = [tmp shift]; 36 | } 37 | return self; 38 | } 39 | 40 | - (NSArray *)marshall 41 | { 42 | NSNumber *code = [[MDWampMessageFactory sharedFactory] codeFromObject:self]; 43 | 44 | if (self.arguments && self.argumentsKw) { 45 | return @[code, self.request, self.options, self.topic, self.arguments, self.argumentsKw ]; 46 | } else if(self.arguments) { 47 | return @[code, self.request, self.options, self.topic, self.arguments ]; 48 | } else if(self.argumentsKw) { 49 | return @[code, self.request, self.options, self.topic, @[], self.argumentsKw ]; 50 | } else { 51 | return @[code, self.request, self.options, self.topic]; 52 | } 53 | } 54 | 55 | - (NSDictionary *)event { 56 | return self.argumentsKw; 57 | } 58 | 59 | - (void)setEvent:(NSDictionary *)event { 60 | self.argumentsKw = event; 61 | } 62 | 63 | @end 64 | -------------------------------------------------------------------------------- /MDWampTests/MDStackTest.m: -------------------------------------------------------------------------------- 1 | // 2 | // MDStackTest.m 3 | // MDWamp 4 | // 5 | // Created by Niko Usai on 15/06/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | // 20 | 21 | #import 22 | #import "NSMutableArray+MDStack.h" 23 | @interface MDStackTest : XCTestCase { 24 | NSMutableArray *arr; 25 | } 26 | 27 | @end 28 | 29 | @implementation MDStackTest 30 | 31 | - (void)setUp 32 | { 33 | [super setUp]; 34 | arr = [@[@1, @2, @3] mutableCopy]; 35 | // Put setup code here. This method is called before the invocation of each test method in the class. 36 | } 37 | 38 | - (void)tearDown 39 | { 40 | // Put teardown code here. This method is called after the invocation of each test method in the class. 41 | [super tearDown]; 42 | } 43 | 44 | - (void)testPush 45 | { 46 | [arr push:@4]; 47 | XCTAssertEqual([arr count], 4, @"element must be added"); 48 | XCTAssertEqualObjects(arr[3], @4, @"last element should be the one we added"); 49 | } 50 | 51 | - (void)testPop { 52 | NSNumber *a = [arr pop]; 53 | XCTAssertEqual([arr count], 2, @"element must be removede when popped"); 54 | XCTAssertEqualObjects(a, @3, @"last element should be the last of the array"); 55 | 56 | } 57 | 58 | - (void)testShift { 59 | NSNumber *a = [arr shift]; 60 | XCTAssertEqual([arr count], 2, @"element must be removede when shifted"); 61 | XCTAssertEqualObjects(a, @1, @"last element should be the first of the array"); 62 | } 63 | 64 | - (void)testUnshift { 65 | [arr unshift:@0]; 66 | XCTAssertEqual([arr count], 4, @"element must be added"); 67 | XCTAssertEqualObjects(arr[0], @0, @"first element should be the one we added"); 68 | } 69 | 70 | @end 71 | -------------------------------------------------------------------------------- /MDWamp/src/MDWampClientDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // MDWampClientDelegate.h 3 | // MDWamp 4 | // 5 | // Created by Niko Usai on 13/12/13. 6 | // Copyright (c) 2013 mogui.it. All rights reserved. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | // 20 | 21 | @class MDWamp; 22 | 23 | @protocol MDWampClientDelegate 24 | 25 | @optional 26 | 27 | /** 28 | * Called when client connect to the server 29 | * 30 | * @param wamp wamp client 31 | * @param info dictionary with additional info 32 | */ 33 | - (void) mdwamp:(MDWamp*)wamp sessionEstablished:(NSDictionary*)info; 34 | 35 | /** 36 | * Called when client disconnect from the server 37 | * it gives code of the error / reason of disconnect and a description of the reason 38 | * 39 | * @param wamp wamp client 40 | * @param code 41 | * @param reason 42 | * @param details 43 | */ 44 | - (void) mdwamp:(MDWamp *)wamp closedSession:(NSInteger)code reason:(NSString*)reason details:(NSDictionary *)details; 45 | ///* 46 | // * Auth req finished 47 | // * 48 | // * @param answer authreq answer 49 | // */ 50 | //- (void) onAuthReqWithAnswer:(NSString *)answer; 51 | // 52 | ///* 53 | // * Signed authentification challenge 54 | // * 55 | // * @param signature HmacSHA256(challenge, secret) 56 | // */ 57 | //- (void) onAuthSignWithSignature:(NSString *)signature; 58 | // 59 | ///* 60 | // * Handshake finished 61 | // * 62 | // * @param answer auth call answer 63 | // */ 64 | //- (void) onAuthWithAnswer:(NSString *)answer; 65 | // 66 | ///* 67 | // * Auth failed 68 | // * 69 | // * @param procCall auth procedure that failed: authreq or auth 70 | // * @param error the error returned by the failed call 71 | // */ 72 | //- (void) onAuthFailForCall:(NSString *)procCall withError:(NSString *)errorDetails; 73 | // 74 | @end 75 | -------------------------------------------------------------------------------- /MDWamp/src/MDWampMessages/MDWampEvent.m: -------------------------------------------------------------------------------- 1 | // 2 | // MDWampEvent.m 3 | // MDWamp 4 | // 5 | // Created by Niko Usai on 22/04/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | // 20 | 21 | #import "MDWampEvent.h" 22 | 23 | @implementation MDWampEvent 24 | 25 | - (id)initWithPayload:(NSArray *)payload 26 | { 27 | self = [super init]; 28 | if (self) { 29 | NSMutableArray *tmp = [payload mutableCopy]; 30 | // [EVENT, SUBSCRIBED.Subscription|id, PUBLISHED.Publication|id, Details|dict, PUBLISH.Arguments|list, PUBLISH.ArgumentsKw|dict] 31 | 32 | self.subscription = [tmp shift]; 33 | self.publication = [tmp shift]; 34 | self.details = [tmp shift]; 35 | if ([tmp count] > 0) self.arguments = [tmp shift]; 36 | if ([tmp count] > 0) self.argumentsKw = [tmp shift]; 37 | } 38 | return self; 39 | } 40 | 41 | - (NSArray *)marshall 42 | { 43 | NSNumber *code = [[MDWampMessageFactory sharedFactory] codeFromObject:self]; 44 | 45 | if (self.arguments && self.argumentsKw) { 46 | return @[code, self.subscription, self.publication, self.details, self.arguments, self.argumentsKw ]; 47 | } else if(self.arguments) { 48 | return @[code, self.subscription, self.publication, self.details, self.arguments ]; 49 | } else if(self.argumentsKw) { 50 | return @[code, self.subscription, self.publication, self.details, @[], self.argumentsKw ]; 51 | } else { 52 | return @[code,self.subscription, self.publication, self.details]; 53 | } 54 | } 55 | 56 | - (NSDictionary *)event { 57 | return self.argumentsKw; 58 | } 59 | 60 | - (void)setEvent:(NSDictionary *)event { 61 | self.argumentsKw = event; 62 | } 63 | 64 | @end 65 | -------------------------------------------------------------------------------- /MDWampTests/MDWampTransportMock.m: -------------------------------------------------------------------------------- 1 | // 2 | // MDWampTransportMock.m 3 | // MDWamp 4 | // 5 | // Created by Niko Usai on 12/03/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | // 20 | 21 | #import "MDWampTransportMock.h" 22 | #import "MDWamp.h" 23 | #import "MDWampMessages.h" 24 | #import "NSMutableArray+MDStack.h" 25 | #import "MDWampConstants.h" 26 | 27 | 28 | @interface MDWampTransportMock () 29 | @property (strong) NSArray *proto; 30 | @property (assign) BOOL connected; 31 | @end 32 | 33 | 34 | @implementation MDWampTransportMock 35 | 36 | - (id)initWithServer:(NSURL *)request protocolVersions:(NSArray *)protocols 37 | { 38 | self = [super init]; 39 | if (self) { 40 | self.openWillFail = NO; 41 | self.connected = NO; 42 | self.sendBuffer = [[NSMutableArray alloc] init]; 43 | self.serializationClass = 0; 44 | } 45 | return self; 46 | } 47 | 48 | - (void) open 49 | { 50 | NSLog(@"Opening transport"); 51 | if (self.openWillFail) { 52 | NSError *error = [NSError errorWithDomain:kMDWampErrorDomain code:-10 userInfo:@{NSLocalizedDescriptionKey: @"Opening the transport failed miserably"}]; 53 | [self.delegate transportDidFailWithError:error]; 54 | } else { 55 | [self.delegate transportDidOpenWithSerialization:self.serializationClass]; 56 | self.connected = YES; 57 | } 58 | } 59 | 60 | - (void) close 61 | { 62 | NSLog(@"Closing the transport"); 63 | self.connected = NO; 64 | [self.delegate transportDidCloseWithError:nil]; 65 | } 66 | 67 | - (BOOL) isConnected 68 | { 69 | return self.connected; 70 | } 71 | 72 | - (void)send:(id)data 73 | { 74 | [self.sendBuffer push:data]; 75 | } 76 | 77 | 78 | // Test methods 79 | - (void) triggerDidReceiveMessage:(id)msg 80 | { 81 | [self.delegate transportDidReceiveMessage:msg]; 82 | } 83 | 84 | 85 | 86 | @end 87 | -------------------------------------------------------------------------------- /MDWamp/src/MDWampMessages/MDWampError.m: -------------------------------------------------------------------------------- 1 | // 2 | // MDWampError.m 3 | // MDWamp 4 | // 5 | // Created by Niko Usai on 08/03/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | // 20 | 21 | #import "MDWampError.h" 22 | 23 | @implementation MDWampError 24 | - (id)initWithPayload:(NSArray *)payload 25 | { 26 | self = [super init]; 27 | if (self) { 28 | NSMutableArray *tmp = [payload mutableCopy]; 29 | self.type = [tmp shift]; 30 | self.request = [tmp shift]; 31 | self.details = [tmp shift]; 32 | self.error = [tmp shift]; 33 | if ([tmp count] > 0) self.arguments = [tmp shift]; 34 | if ([tmp count] > 0) self.argumentsKw = [tmp shift]; 35 | } 36 | return self; 37 | } 38 | 39 | 40 | - (NSArray *)marshall 41 | { 42 | NSNumber *code = [[MDWampMessageFactory sharedFactory] codeFromObject:self]; 43 | 44 | if (self.arguments && self.argumentsKw) { 45 | return @[code, self.type, self.request, self.details, self.error, 46 | self.arguments, self.argumentsKw ]; 47 | } else if(self.arguments) { 48 | return @[code, self.type, self.request, self.details, self.error, 49 | self.arguments ]; 50 | } else if(self.argumentsKw) { 51 | return @[code, self.type, self.request, self.details, self.error, @[], self.argumentsKw ]; 52 | } else { 53 | return @[code, self.type, self.request, self.details, self.error ]; 54 | } 55 | } 56 | 57 | - (NSError *) makeError 58 | { 59 | NSDictionary *info; 60 | if (self.details && [self.details isKindOfClass:[NSDictionary class]]) { 61 | info = [self.details mutableCopy]; 62 | [(NSMutableDictionary*)info setObject:self.error forKey:NSLocalizedDescriptionKey]; 63 | if (self.arguments) { 64 | [(NSMutableDictionary*)info setObject:self.arguments forKey:@"args"]; 65 | } 66 | if (self.argumentsKw) { 67 | [(NSMutableDictionary*)info setObject:self.argumentsKw forKey:@"kwargs"]; 68 | } 69 | } else { 70 | info = @{NSLocalizedDescriptionKey: self.error}; 71 | } 72 | return [NSError errorWithDomain:kMDWampErrorDomain code:[self.type integerValue] userInfo:info]; 73 | } 74 | 75 | @end 76 | -------------------------------------------------------------------------------- /MDWampDemo/src/ConnectViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // FirstViewController.m 3 | // MDWampDemo 4 | // 5 | // Created by Niko Usai on 27/06/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | 9 | #import "ConnectViewController.h" 10 | 11 | 12 | @interface ConnectViewController () 13 | @property (assign) BOOL connected; 14 | @end 15 | 16 | @implementation ConnectViewController 17 | 18 | - (void)viewDidLoad 19 | { 20 | [super viewDidLoad]; 21 | MDWampTransportWebSocket *transport = [[MDWampTransportWebSocket alloc] initWithServer:[NSURL URLWithString:self.hostField.text] protocolVersions:@[kMDWampProtocolWamp2json]]; 22 | 23 | // Test Raw socket 24 | // MDWampTransportRawSocket *transport = [[MDWampTransportRawSocket alloc] initWithHost:@"127.0.0.1" port:9000]; 25 | // [transport setSerialization:kMDWampSerializationJSON]; 26 | // 27 | (AppDel).wampConnection = [[MDWamp alloc] initWithTransport:transport realm:self.realmField.text delegate:self]; 28 | 29 | // Do any additional setup after loading the view, typically from a nib. 30 | } 31 | - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField 32 | { 33 | if (self.connected) { 34 | return NO; 35 | } 36 | return YES; 37 | } 38 | 39 | - (BOOL)textFieldShouldReturn:(UITextField *)textField { 40 | [textField resignFirstResponder]; 41 | return YES; 42 | } 43 | 44 | - (void)didReceiveMemoryWarning 45 | { 46 | [super didReceiveMemoryWarning]; 47 | // Dispose of any resources that can be recreated. 48 | } 49 | 50 | - (IBAction)connect:(id)sender { 51 | // CHECK empty fields 52 | if (!self.connected) { 53 | 54 | [(AppDel).wampConnection connect]; 55 | } else { 56 | [(AppDel).wampConnection disconnect]; 57 | } 58 | } 59 | 60 | - (void) mdwamp:(MDWamp*)wamp sessionEstablished:(NSDictionary*)info { 61 | 62 | self.connected = YES; 63 | [self.connectButton setTitle:@"DISCONNECT" forState:UIControlStateNormal]; 64 | NSLog(@"serverd details: %@", info); 65 | [self.connectIcon setHighlighted:YES]; 66 | self.serverDetails.text = [NSString stringWithFormat:@"\n"\ 67 | @"authid:\t %@\n"\ 68 | @"authmethod:\t %@\n"\ 69 | @"authrole:\t %@\n"\ 70 | @"roles:\t %@\n", info[@"authid"], info[@"authmethod"], info[@"authrole"], [[info[@"roles"] allKeys] componentsJoinedByString:@", "]]; 71 | } 72 | 73 | - (void) mdwamp:(MDWamp *)wamp closedSession:(NSInteger)code reason:(NSString*)reason details:(NSDictionary *)details { 74 | [self.connectIcon setHighlighted:NO]; 75 | self.connected = NO; 76 | self.serverDetails.text = reason; 77 | [self.connectButton setTitle:@"CONNECT" forState:UIControlStateNormal]; 78 | } 79 | 80 | @end 81 | -------------------------------------------------------------------------------- /MDWamp.xcodeproj/xcshareddata/xcschemes/libMDWamp.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 34 | 35 | 45 | 46 | 52 | 53 | 54 | 55 | 56 | 57 | 63 | 64 | 70 | 71 | 72 | 73 | 75 | 76 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /MDWampDemo/src/CallRPCViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // CallRPCViewController.m 3 | // MDWamp 4 | // 5 | // Created by Niko Usai on 04/07/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | 9 | #import "CallRPCViewController.h" 10 | 11 | @interface CallRPCViewController () { 12 | UIImageView *tmpIv; 13 | } 14 | 15 | @end 16 | 17 | @implementation CallRPCViewController 18 | 19 | - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 20 | { 21 | self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 22 | if (self) { 23 | // Custom initialization 24 | } 25 | return self; 26 | } 27 | 28 | - (void)viewDidLoad 29 | { 30 | [super viewDidLoad]; 31 | // Do any additional setup after loading the view. 32 | } 33 | 34 | - (void) viewDidAppear:(BOOL)animated 35 | { 36 | dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ 37 | if (![[AppDel wampConnection] isConnected]) { 38 | 39 | self.tabBarController.selectedViewController = self.tabBarController.viewControllers[0]; 40 | 41 | UIAlertView *av = [[UIAlertView alloc] initWithTitle:@"!!" message:@"You must first connect!" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil]; 42 | [av show]; 43 | } 44 | 45 | }); 46 | } 47 | 48 | 49 | -(BOOL)textFieldShouldReturn:(UITextField *)textField { 50 | //Keyboard becomes visible 51 | [textField resignFirstResponder]; 52 | return YES; 53 | } 54 | 55 | - (IBAction)callProcedure:(id)sender { 56 | if (tmpIv) { 57 | [tmpIv removeFromSuperview]; 58 | } 59 | 60 | [[AppDel wampConnection] call:self.procedureName.text args:nil kwArgs:nil options:nil complete:^(MDWampResult *result, NSError *error) { 61 | self.resultText.text = @""; 62 | if (error) { 63 | self.resultText.text = error.localizedDescription; 64 | return; 65 | } 66 | 67 | if (result.argumentsKw) { // is the device info 68 | NSString *res = [NSString stringWithFormat:@"name: %@\nos: %@ %@", result.argumentsKw[@"name"], result.argumentsKw[@"systemName"], result.argumentsKw[@"systemVersion"]]; 69 | self.resultText.text = res; 70 | } else { // else is the screenshot 71 | // NOTICE: in a real world application you will make 72 | // a sort of application protocol with this messages to differ the response or you just know what procedures returns :P 73 | NSString *arr = result.result; 74 | NSData *decoded = [[NSData alloc] initWithBase64EncodedString:arr options:NSDataBase64DecodingIgnoreUnknownCharacters]; 75 | UIImage *img = [UIImage imageWithData:decoded]; 76 | tmpIv = [[UIImageView alloc] initWithFrame:self.resultText.frame]; 77 | tmpIv.contentMode = UIViewContentModeScaleAspectFit; 78 | tmpIv.image = img; 79 | [UIView transitionWithView:self.view duration:0.5 80 | options:UIViewAnimationOptionTransitionCrossDissolve 81 | animations:^ { 82 | [self.view addSubview:tmpIv]; 83 | } completion:nil]; 84 | 85 | } 86 | }]; 87 | 88 | } 89 | @end 90 | -------------------------------------------------------------------------------- /bump.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import argparse 3 | import plistlib 4 | import json 5 | import os 6 | import sys 7 | 8 | valid_bumps = ['major', 'minor', 'bugfix'] 9 | 10 | # 11 | # Argparse 12 | # 13 | parser = argparse.ArgumentParser(description='Bump version in xcode project and podspec') 14 | parser.add_argument('bump', type=str, nargs='?', default=valid_bumps[2], choices=valid_bumps, help='Which part of semantic verison to bump default: bugfix') 15 | parser.add_argument('--version', dest='version', help='explicitly set a version, ignores semver specified') 16 | parser.add_argument('--tag', action='store_true', help='tag the git repository with new version') 17 | # parser.add_argument('--no-build', action='store_true', help='doesn\'t increment the build number') 18 | parser.add_argument('-p', metavar='plist', help='plist file to operate on') 19 | parser.add_argument('-s', metavar='podspec', help='podspec file to operate on') 20 | args = parser.parse_args() 21 | 22 | 23 | def error(msg): 24 | print("=== Error ===\n%s\n=============\n" % msg) 25 | parser.print_help() 26 | sys.exit(-1) 27 | 28 | project_name = None 29 | 30 | podspec = args.s 31 | plist = args.p 32 | 33 | if (plist is None) or (podspec is None): 34 | for element in os.listdir('.'): 35 | if 'xcodeproj' in element: 36 | project_name = element.split('.')[0] 37 | break 38 | 39 | if project_name is None: 40 | error('Your not in a Xcode project directory, cannot find xcodeproj\nPlease specify Info.plist and podspec.json to operate on') 41 | 42 | if plist is None: 43 | plist = "%s/%s-Info.plist" % (project_name, project_name) 44 | 45 | if podspec is None: 46 | podspec = "%s.podspec.json" % project_name 47 | 48 | # check files 49 | if not os.path.isfile(plist): 50 | error('plist: %s file not found' % plist) 51 | 52 | if not os.path.isfile(podspec): 53 | error('podspec: %s file not found' % podspec) 54 | 55 | # read plist 56 | plist_d = plistlib.readPlist(plist) 57 | 58 | 59 | # read podspec 60 | f = open(podspec, 'r') 61 | podspec_d = json.load(f) 62 | f.close() 63 | 64 | current_version = plist_d['CFBundleShortVersionString'] 65 | new_version = current_version 66 | 67 | print('Current Version is %s' % current_version) 68 | 69 | if args.version is None: 70 | version_split = current_version.split('.') 71 | 72 | if args.bump == 'bugfix': 73 | version_split[2] = str(int(version_split[2]) + 1) 74 | elif args.bump == 'minor': 75 | version_split[1] = str(int(version_split[1]) + 1) 76 | version_split[2] = '0' 77 | elif args.bump == 'major': 78 | version_split[0] = str(int(version_split[0]) + 1) 79 | version_split[1] = '0' 80 | version_split[2] = '0' 81 | 82 | print(version_split) 83 | new_version = '.'.join(version_split) 84 | else: 85 | new_version = args.version 86 | 87 | print('New Version will be %s' % new_version) 88 | 89 | # edit objects 90 | podspec_d['version'] = new_version 91 | podspec_d['source']['tag'] = new_version 92 | 93 | plist_d['CFBundleShortVersionString'] = new_version 94 | 95 | # Saving files 96 | print("Saving files...") 97 | 98 | try: 99 | with open(podspec, 'w') as fp: 100 | json.dump(podspec_d, fp, sort_keys=False, indent=4, separators=(',', ': ')) 101 | plistlib.writePlist(plist_d, plist) 102 | except Exception, e: 103 | error(e.message) 104 | 105 | print('OK') 106 | -------------------------------------------------------------------------------- /MDWamp/src/MDWampMessages/MDWampMessageFactory.h: -------------------------------------------------------------------------------- 1 | // 2 | // MDWampMessageFactory.h 3 | // MDWamp 4 | // 5 | // Created by Niko Usai on 01/04/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | // 20 | 21 | #import 22 | #import "MDWampConstants.h" 23 | @protocol MDWampMessage; 24 | 25 | FOUNDATION_EXPORT NSString *const kMDWampHello ; 26 | FOUNDATION_EXPORT NSString *const kMDWampWelcome ; 27 | FOUNDATION_EXPORT NSString *const kMDWampAbort ; 28 | FOUNDATION_EXPORT NSString *const kMDWampChallenge ; 29 | FOUNDATION_EXPORT NSString *const kMDWampAuthenticate ; 30 | FOUNDATION_EXPORT NSString *const kMDWampGoodbye ; 31 | FOUNDATION_EXPORT NSString *const kMDWampError ; 32 | FOUNDATION_EXPORT NSString *const kMDWampPublish ; 33 | FOUNDATION_EXPORT NSString *const kMDWampPublished ; 34 | FOUNDATION_EXPORT NSString *const kMDWampSubscribe ; 35 | FOUNDATION_EXPORT NSString *const kMDWampSubscribed ; 36 | FOUNDATION_EXPORT NSString *const kMDWampUnsubscribe ; 37 | FOUNDATION_EXPORT NSString *const kMDWampUnsubscribed ; 38 | FOUNDATION_EXPORT NSString *const kMDWampEvent ; 39 | FOUNDATION_EXPORT NSString *const kMDWampCall ; 40 | FOUNDATION_EXPORT NSString *const kMDWampCancel ; 41 | FOUNDATION_EXPORT NSString *const kMDWampResult ; 42 | FOUNDATION_EXPORT NSString *const kMDWampRegister ; 43 | FOUNDATION_EXPORT NSString *const kMDWampRegistered ; 44 | FOUNDATION_EXPORT NSString *const kMDWampUnregister ; 45 | FOUNDATION_EXPORT NSString *const kMDWampUnregistered ; 46 | FOUNDATION_EXPORT NSString *const kMDWampInvocation ; 47 | FOUNDATION_EXPORT NSString *const kMDWampInterrupt ; 48 | FOUNDATION_EXPORT NSString *const kMDWampYield ; 49 | 50 | @interface MDWampMessageFactory : NSObject 51 | 52 | /** 53 | * Singleton 54 | * 55 | */ 56 | + (instancetype) sharedFactory; 57 | 58 | /** 59 | * return an MDWampMessage instance, given the code 60 | * and inited with the payload 61 | * 62 | * @param code protocol code 63 | * @param payload array of parameters to init the message with 64 | * 65 | * @return an instance of the right message 66 | */ 67 | - (id)objectFromCode:(NSNumber*)code withPayload:(NSArray*)payload; 68 | 69 | /** 70 | * Gives the class name as a string given the right code 71 | * 72 | * @param code protocol code 73 | * 74 | * @return Class string name 75 | */ 76 | - (NSString *)nameFromCode:(NSNumber*)code; 77 | 78 | /** 79 | * Gives the protocol code for a class Name 80 | * 81 | * @param NSString class name 82 | * 83 | * @return code 84 | */ 85 | - (NSNumber *)codeFromClassName:(NSString*)className; 86 | 87 | /** 88 | * Gives the protocol code for a given object 89 | * 90 | * @param object an MDWampMessage ninstance 91 | * 92 | * @return protocol code 93 | */ 94 | - (NSNumber *)codeFromObject:(id)object; 95 | 96 | @end 97 | -------------------------------------------------------------------------------- /MDWamp/src/MDWampClientConfig.m: -------------------------------------------------------------------------------- 1 | // 2 | // MDWampClientConfig.m 3 | // MDWamp 4 | // 5 | // Created by Niko Usai on 09/10/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | 9 | #import "MDWampClientConfig.h" 10 | #import "MDWampConstants.h" 11 | 12 | #pragma Constants 13 | 14 | NSString * const kMDWampRolePublisher = @"publisher"; 15 | NSString * const kMDWampRoleSubscriber = @"subscriber"; 16 | NSString * const kMDWampRoleCaller = @"caller"; 17 | NSString * const kMDWampRoleCallee = @"callee"; 18 | NSString * const kMDWampAuthMethodCRA = @"wampcra"; 19 | NSString * const kMDWampAuthMethodTicket = @"ticket"; 20 | 21 | @interface MDWampClientConfig() 22 | 23 | @end 24 | 25 | @implementation MDWampClientConfig 26 | 27 | - (instancetype)init { 28 | self = [super init]; 29 | if (self) { 30 | self.authmethods = @[]; 31 | self.roles = @{ 32 | kMDWampRolePublisher : @{ 33 | @"subscriber_blackwhite_listing": @YES, 34 | @"publisher_exclusion": @YES, 35 | @"publisher_identification": @YES 36 | }, 37 | kMDWampRoleSubscriber : @{ 38 | @"publication_trustlevels": @YES, 39 | @"pattern_based_subscription": @YES 40 | }, 41 | kMDWampRoleCaller : @{ 42 | @"callee_blackwhite_listing": @YES, 43 | @"caller_exclusion": @YES, 44 | @"caller_identification": @YES, 45 | @"call_canceling":@YES, 46 | @"progressive_call_results":@YES 47 | }, 48 | kMDWampRoleCallee : @{ 49 | @"call_canceling":@YES, 50 | @"progressive_call_results":@YES 51 | } 52 | }; 53 | self.publisher_acknowledge = NO; 54 | self.publisher_exclude_me = YES; 55 | self.publisher_identification = NO; 56 | 57 | self.caller_exclude_me = YES; 58 | self.caller_identification = NO; 59 | self.caller_progressive_result = NO; 60 | } 61 | return self; 62 | } 63 | 64 | - (NSDictionary *)getHelloDetails { 65 | NSMutableDictionary* d = [NSMutableDictionary dictionaryWithDictionary:@{ @"roles" : self.roles, @"authmethods" : self.authmethods }]; 66 | 67 | if (self.agent) { 68 | d[@"agent"] = self.agent; 69 | } 70 | 71 | if (self.authid) { 72 | d[@"authid"] = self.authid; 73 | } 74 | 75 | // Integrity checks 76 | if ([self.authmethods containsObject:kMDWampAuthMethodCRA] && (!self.authid || !self.sharedSecret) ) { 77 | // if wampcra MUST be provided authid 78 | #ifdef DEBUG 79 | [NSException raise:@"it.mogui.mdwamp" format:@"Inconsistent MDWampClientConfig with wampcra an authid and sharedSecred must be provided"]; 80 | #else 81 | MDWampDebugLog(@"Inconsistent MDWampClientConfig with wampcra an authid must be provided"); 82 | #endif 83 | } 84 | 85 | if ([self.authmethods containsObject:kMDWampAuthMethodTicket] && (!self.authid || !self.ticket) ) { 86 | // if wampcra MUST be provided authid 87 | #ifdef DEBUG 88 | [NSException raise:@"it.mogui.mdwamp" format:@"Inconsistent MDWampClientConfig with ticket based auth an authid and ticket must be provided"]; 89 | #else 90 | MDWampDebugLog(@"Inconsistent MDWampClientConfig with ticket based auth an authid and ticket must be provided"); 91 | #endif 92 | } 93 | 94 | return [NSDictionary dictionaryWithDictionary:d]; 95 | } 96 | 97 | @end 98 | -------------------------------------------------------------------------------- /MDWamp/src/MDWampTransports/MDWampTransportRawSocket.m: -------------------------------------------------------------------------------- 1 | // 2 | // RawSocketTransport.m 3 | // MDWamp 4 | // 5 | // Created by Niko Usai on 05/07/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | 9 | #import "MDWampTransportRawSocket.h" 10 | #import "GCDAsyncSocket.h" 11 | @interface MDWampTransportRawSocket () 12 | 13 | @property (nonatomic, strong) GCDAsyncSocket *socket; 14 | @property (nonatomic, strong) NSString *host; 15 | @property (nonatomic, assign) NSInteger port; 16 | 17 | @end 18 | @implementation MDWampTransportRawSocket 19 | 20 | - (id)initWithHost:(NSString*)host port:(NSInteger)port 21 | { 22 | self = [super init]; 23 | if (self) { 24 | dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); 25 | self.socket = [[GCDAsyncSocket alloc] initWithDelegate:self delegateQueue:queue]; 26 | self.host = host; 27 | self.port = port; 28 | self.serialization = kMDWampSerializationJSON; 29 | 30 | } 31 | return self; 32 | } 33 | 34 | - (void)socket:(GCDAsyncSocket *)sender didConnectToHost:(NSString *)host port:(UInt16)port 35 | { 36 | if (_delegate && [_delegate respondsToSelector:@selector(transportDidOpenWithSerialization:)]) { 37 | dispatch_async(dispatch_get_main_queue(), ^{ 38 | [_delegate transportDidOpenWithSerialization:self.serialization]; 39 | }); 40 | } 41 | } 42 | 43 | - (void)socketDidDisconnect:(GCDAsyncSocket *)sock withError:(NSError *)err { 44 | if (err) { 45 | if (_delegate && [_delegate respondsToSelector:@selector(transportDidFailWithError:)]) { 46 | dispatch_async(dispatch_get_main_queue(), ^{ 47 | [_delegate transportDidFailWithError:err]; 48 | }); 49 | } 50 | } else { 51 | if (_delegate && [_delegate respondsToSelector:@selector(transportDidCloseWithError:)]) { 52 | dispatch_async(dispatch_get_main_queue(), ^{ 53 | [_delegate transportDidCloseWithError:nil]; 54 | }); 55 | } 56 | } 57 | } 58 | 59 | - (void)socket:(GCDAsyncSocket *)sock didReadData:(NSData *)data withTag:(long)tag { 60 | NSRange lRange = NSMakeRange(0, 4); 61 | NSData *l = [data subdataWithRange:lRange]; 62 | uint32_t *bigEndianLength = (uint32_t *)[l bytes]; 63 | uint32_t length = CFSwapInt32BigToHost(*bigEndianLength); 64 | 65 | NSRange contentRange = NSMakeRange(4, length); 66 | NSData *content = [data subdataWithRange:contentRange]; 67 | if (_delegate && [_delegate respondsToSelector:@selector(transportDidReceiveMessage:)]) { 68 | dispatch_async(dispatch_get_main_queue(), ^{ 69 | [_delegate transportDidReceiveMessage:content]; 70 | }); 71 | } 72 | } 73 | 74 | - (void) open 75 | { 76 | NSError *err = nil; 77 | if (![_socket connectToHost:self.host onPort:self.port error:&err]) 78 | { 79 | NSLog(@"I goofed: %@", err); 80 | return; 81 | } 82 | } 83 | 84 | - (void) close 85 | { 86 | [_socket disconnect]; 87 | } 88 | 89 | - (BOOL) isConnected 90 | { 91 | return [_socket isConnected]; 92 | } 93 | 94 | - (void)send:(NSData *)data 95 | { 96 | unsigned int len = (unsigned int)[data length]; 97 | int32_t swapped = CFSwapInt32HostToBig(len); 98 | NSMutableData *dd = [NSMutableData dataWithBytes:&swapped length:sizeof(unsigned int)]; 99 | [dd appendData:data]; 100 | [_socket writeData:dd withTimeout:0.5 tag:1]; 101 | [_socket readDataWithTimeout:0.5 tag:2]; 102 | } 103 | 104 | @end 105 | -------------------------------------------------------------------------------- /MDWampTests/MDWampTransportRawSocketTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // MDWampTransportRawSocketTests.m 3 | // MDWamp 4 | // 5 | // Created by Niko Usai on 06/07/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "XCTAsyncTestCase.h" 11 | #import "MDWampTransportRawSocket.h" 12 | 13 | typedef enum : NSUInteger { 14 | TestOpen, 15 | TestClose, 16 | TestMessage, 17 | TestFail 18 | } MDWampRawSocketTestsOperation; 19 | 20 | @interface MDWampTransportRawSocketTests : XCTAsyncTestCase 21 | { 22 | MDWampTransportRawSocket *transport; 23 | } 24 | @property (assign) MDWampRawSocketTestsOperation operation; 25 | @end 26 | 27 | @implementation MDWampTransportRawSocketTests 28 | 29 | - (void)setUp 30 | { 31 | [super setUp]; 32 | transport = [[MDWampTransportRawSocket alloc] initWithHost:@"127.0.0.1" port:9000]; 33 | [transport setSerialization:kMDWampSerializationJSON]; 34 | [transport setDelegate:self]; 35 | [self prepare]; 36 | 37 | // Put setup code here. This method is called before the invocation of each test method in the class. 38 | } 39 | 40 | - (void) transportDidOpenWithSerialization:(NSString*)serialization { 41 | XCTAssert([transport isConnected], @"Must be connected"); 42 | 43 | if (self.operation == TestOpen) { 44 | [self notify:kXCTUnitWaitStatusSuccess]; 45 | } else if (self.operation == TestClose) { 46 | [transport close]; 47 | } else if (self.operation == TestMessage) { 48 | NSString *helloMsg = @"[1,\"realm1\",{\"roles\":{\"publisher\":{},\"subscriber\":{}}}]"; 49 | NSData *d = [helloMsg dataUsingEncoding:NSUTF8StringEncoding]; 50 | [transport send:d]; 51 | } else if (self.operation == TestFail) { 52 | NSData *d = [@"[Wrong format at all]" dataUsingEncoding:NSUTF8StringEncoding]; 53 | [transport send:d]; 54 | } 55 | } 56 | 57 | - (void) transportDidReceiveMessage:(NSData *)message { 58 | if (self.operation == TestMessage) { 59 | XCTAssertNotNil(message, @"Must receive something"); 60 | 61 | NSString *welcome = [[NSString alloc] initWithData:message encoding:NSUTF8StringEncoding]; 62 | NSLog(@"received %@", welcome); 63 | // Test if the received string is a JSON representing a Welcome message 64 | XCTAssert([welcome hasPrefix:@"[2,"], @"Check received Welcome"); 65 | 66 | [self notify:kXCTUnitWaitStatusSuccess]; 67 | } 68 | } 69 | 70 | - (void) transportDidFailWithError:(NSError *)error { 71 | XCTAssertFalse([transport isConnected], @"Must be not connected"); 72 | [self notify:kXCTUnitWaitStatusSuccess]; 73 | } 74 | 75 | - (void) transportDidCloseWithError:(NSError *)error { 76 | XCTAssertFalse([transport isConnected], @"Must be not connected"); 77 | [self notify:kXCTUnitWaitStatusSuccess]; 78 | } 79 | 80 | - (void)testOpen 81 | { 82 | self.operation = TestOpen; 83 | [transport open]; 84 | [self waitForStatus:kXCTUnitWaitStatusSuccess timeout:1]; 85 | } 86 | 87 | - (void)testClose 88 | { 89 | self.operation = TestClose; 90 | [transport open]; 91 | [self waitForStatus:kXCTUnitWaitStatusSuccess timeout:1]; 92 | } 93 | 94 | - (void)testSendAndReceiveMessage { 95 | self.operation = TestMessage; 96 | [transport open]; 97 | [self waitForStatus:kXCTUnitWaitStatusSuccess timeout:1]; 98 | } 99 | 100 | - (void)testFail { 101 | self.operation = TestFail; 102 | [transport open]; 103 | [self waitForStatus:kXCTUnitWaitStatusSuccess timeout:1]; 104 | } 105 | @end 106 | -------------------------------------------------------------------------------- /MDWamp.xcodeproj/xcshareddata/xcschemes/MDWampDemo.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 | 54 | 56 | 62 | 63 | 64 | 65 | 66 | 67 | 73 | 75 | 81 | 82 | 83 | 84 | 86 | 87 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /MDWamp/src/MDWampClientConfig.h: -------------------------------------------------------------------------------- 1 | // 2 | // MDWampClientConfig.h 3 | // MDWamp 4 | // 5 | // Created by Niko Usai on 09/10/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "MDWampChallenge.h" 11 | 12 | // ROles 13 | extern NSString* const kMDWampRolePublisher; 14 | extern NSString* const kMDWampRoleSubscriber; 15 | extern NSString* const kMDWampRoleCaller; 16 | extern NSString* const kMDWampRoleCallee; 17 | 18 | // Auth methods 19 | extern NSString* const kMDWampAuthMethodCRA; 20 | extern NSString* const kMDWampAuthMethodTicket; 21 | 22 | @interface MDWampClientConfig : NSObject 23 | 24 | #pragma mark Generics 25 | /** 26 | * An array of MDWampRoles the client will assume on connection 27 | * default is all roles along with all advanced feature 28 | */ 29 | @property (nonatomic, strong) NSDictionary *roles; 30 | 31 | /** 32 | * Similar to what browsers do with the User-Agent HTTP header, 33 | * HELLO message MAY disclose the WAMP implementation in use to its peer 34 | */ 35 | @property (nonatomic, strong) NSString *agent; 36 | 37 | #pragma mark Authentication 38 | /** 39 | * Shared secret to use in wampCRA 40 | */ 41 | @property (nonatomic, strong) NSString *sharedSecret; 42 | 43 | /** 44 | * Ticket used with ticket-based Auth 45 | */ 46 | @property (nonatomic, strong) NSString *ticket; 47 | 48 | /** 49 | * list of authentication method that client is willing to use, currently implemented are: 50 | * wampcra - WAMP Challenge-Response Authentication 51 | */ 52 | @property (nonatomic, strong) NSArray *authmethods; 53 | 54 | /** 55 | * the authentication ID (e.g. username) the client wishes to authenticate as 56 | */ 57 | @property (nonatomic, strong) NSString *authid; 58 | 59 | /** 60 | * Block used to defer the signing of a Wamp CRA challange 61 | * in the block you do your processing to sign the challange (async if you need) 62 | * once getted the signature call 63 | */ 64 | @property (nonatomic, strong) void (^deferredWampCRASigningBlock)( MDWampChallenge *challange, void(^finishBLock)(NSString *signature) ); 65 | 66 | #pragma mark Pub/Sub 67 | 68 | /** 69 | * Default config when Sending a Publish request (can be overrided using options dictionary for every PUBLISH mesg) 70 | * If YES Publisher receives a PUBLISHED acknowledge message from router 71 | * default: NO 72 | */ 73 | @property (nonatomic, assign) BOOL publisher_acknowledge; 74 | 75 | /** 76 | * Default config when Sending a Publish request (can be overrided using options dictionary for every PUBLISH mesg) 77 | * If YES the Publisher will NOT receive the messages he sends to the topic he is subscribed to 78 | * default: YES 79 | */ 80 | @property (nonatomic, assign) BOOL publisher_exclude_me; 81 | 82 | /** 83 | * Default config when Sending a Publish request (can be overrided using options dictionary for every PUBLISH mesg) 84 | * If YES the Publisher request the disclosure of its identity (its WAMP session ID) to receivers of a published event 85 | * default: NO 86 | */ 87 | @property (nonatomic, assign) BOOL publisher_identification; 88 | 89 | /** 90 | * Default config when Sending a Call request (can be overrided using options dictionary for every mesg) 91 | * If YES the Caller will NOT receive the call of a procedure if he has registered to that procedure 92 | * default: YES 93 | */ 94 | @property (nonatomic, assign) BOOL caller_exclude_me; 95 | 96 | /** 97 | * Default config when Sending a CALL request (can be overrided using options dictionary for every mesg) 98 | * If YES the Caller request the disclosure of its identity (its WAMP session ID) to callee 99 | * default: NO 100 | */ 101 | @property (nonatomic, assign) BOOL caller_identification; 102 | 103 | /** 104 | * Default config when Sending a CALL request (can be overrided using options dictionary for every mesg) 105 | * If YES the Caller indicates it's willingness to receive progressive results 106 | * default: NO 107 | 108 | */ 109 | @property (nonatomic, assign) BOOL caller_progressive_result; 110 | 111 | #pragma mark Helpers 112 | /** 113 | * returns a suitable Dictionary to be used as details settings for an HELLO message 114 | * 115 | * @return NSDictionary hello details dictionary 116 | */ 117 | - (NSDictionary *) getHelloDetails; 118 | 119 | 120 | 121 | @end -------------------------------------------------------------------------------- /MDWamp/src/MDWampTransports/MDWampTransportWebSocket.m: -------------------------------------------------------------------------------- 1 | // 2 | // MDWampTransportWebSocket.m 3 | // MDWamp 4 | // 5 | // Created by Niko Usai on 11/03/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | // 20 | 21 | #import "MDWampTransportWebSocket.h" 22 | #import "SRWebSocket.h" 23 | #import "NSMutableArray+MDStack.h" 24 | 25 | NSString *const kMDWampProtocolWamp2json = @"wamp.2.json"; 26 | NSString *const kMDWampProtocolWamp2msgpack = @"wamp.2.msgpack"; 27 | 28 | 29 | @interface MDWampTransportWebSocket () 30 | 31 | @property (nonatomic, strong) SRWebSocket *socket; 32 | @property (nonatomic, strong) NSArray *protocols; 33 | @property (nonatomic, strong) NSURL *request; 34 | @end 35 | 36 | @implementation MDWampTransportWebSocket 37 | 38 | - (id)initWithServer:(NSURL *)request protocolVersions:(NSArray *)protocols 39 | { 40 | self = [super init]; 41 | if (self) { 42 | NSAssert([protocols count] > 0, @"Specify a valid WAMP protocol"); 43 | 44 | NSAssert(([protocols containsObject:kMDWampProtocolWamp2json] 45 | ||[protocols containsObject:kMDWampProtocolWamp2msgpack]), @"No valid WAMP protocol found"); 46 | self.request = request; 47 | self.protocols = protocols; 48 | 49 | } 50 | return self; 51 | } 52 | 53 | - (void)setRequestCookies:(NSArray *)requestCookies { 54 | self.socket.requestCookies = requestCookies; 55 | } 56 | 57 | - (void) open 58 | { 59 | self.socket = [[SRWebSocket alloc] initWithURL:_request protocols:_protocols]; 60 | [_socket setDelegate:self]; 61 | [_socket open]; 62 | } 63 | 64 | - (void) close 65 | { 66 | [_socket close]; 67 | self.socket = nil; 68 | } 69 | 70 | - (BOOL) isConnected 71 | { 72 | return (_socket!=nil)? _socket.readyState == SR_OPEN : NO; 73 | } 74 | 75 | - (void)send:(NSData *)data 76 | { 77 | [_socket send:data]; 78 | } 79 | 80 | 81 | #pragma mark SRWebSocket Delegate 82 | - (void)webSocket:(SRWebSocket *)webSocket didReceiveMessage:(id)message 83 | { 84 | [self.delegate transportDidReceiveMessage:message]; 85 | } 86 | 87 | - (void)webSocketDidOpen:(SRWebSocket *)webSocket 88 | { 89 | MDWampDebugLog(@"negotiated protocol is %@", webSocket.protocol); 90 | NSArray *splittedProtocol = [webSocket.protocol componentsSeparatedByString:@"."]; 91 | if ([splittedProtocol count] == 1) { 92 | [self.delegate transportDidOpenWithSerialization:kMDWampSerializationJSON]; 93 | } else if ([splittedProtocol count] > 1 && [splittedProtocol[1] isEqual:@"2"] && [splittedProtocol[2] isEqual:@"msgpack"]){ 94 | [self.delegate transportDidOpenWithSerialization:kMDWampSerializationMsgpack]; 95 | } else if ([splittedProtocol count] > 1 && [splittedProtocol[1] isEqual:@"2"] && [splittedProtocol[2] isEqual:@"json"]){ 96 | [self.delegate transportDidOpenWithSerialization:kMDWampSerializationJSON]; 97 | } 98 | } 99 | 100 | - (void)webSocket:(SRWebSocket *)webSocket didFailWithError:(NSError *)error 101 | { 102 | if (error.code==54) { 103 | // if error is "The operation couldn’t be completed. Connection reset by peer" 104 | // we call the close method 105 | [self.delegate transportDidCloseWithError:error]; 106 | } else { 107 | [self.delegate transportDidFailWithError:error]; 108 | } 109 | } 110 | 111 | - (void)webSocket:(SRWebSocket *)webSocket didCloseWithCode:(NSInteger)code reason:(NSString *)reason wasClean:(BOOL)wasClean 112 | { 113 | NSError *error = [NSError errorWithDomain:kMDWampErrorDomain code:code userInfo:@{NSLocalizedDescriptionKey: reason ? reason : @""}]; 114 | [self.delegate transportDidCloseWithError:error]; 115 | } 116 | 117 | 118 | @end 119 | -------------------------------------------------------------------------------- /MDWamp.xcodeproj/xcshareddata/xcschemes/MDWamp.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 29 | 35 | 36 | 37 | 38 | 39 | 44 | 45 | 47 | 53 | 54 | 55 | 57 | 58 | 60 | 61 | 63 | 64 | 65 | 66 | 67 | 68 | 74 | 75 | 76 | 77 | 78 | 79 | 89 | 90 | 96 | 97 | 98 | 99 | 100 | 101 | 107 | 108 | 114 | 115 | 116 | 117 | 119 | 120 | 123 | 124 | 125 | -------------------------------------------------------------------------------- /MDWampDemo/src/RegisterRPCViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // RegisterRPCViewController.m 3 | // MDWamp 4 | // 5 | // Created by Niko Usai on 03/07/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | 9 | #import "RegisterRPCViewController.h" 10 | 11 | @interface RegisterRPCViewController () 12 | 13 | @end 14 | 15 | @implementation RegisterRPCViewController 16 | 17 | - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 18 | { 19 | self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 20 | if (self) { 21 | // Custom initialization 22 | } 23 | return self; 24 | } 25 | 26 | - (void)viewDidLoad 27 | { 28 | [super viewDidLoad]; 29 | // Do any additional setup after loading the view. 30 | } 31 | - (void) viewDidAppear:(BOOL)animated 32 | { 33 | dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ 34 | if (![[AppDel wampConnection] isConnected]) { 35 | 36 | self.tabBarController.selectedViewController = self.tabBarController.viewControllers[0]; 37 | 38 | UIAlertView *av = [[UIAlertView alloc] initWithTitle:@"!!" message:@"You must first connect!" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil]; 39 | [av show]; 40 | } 41 | 42 | }); 43 | } 44 | 45 | - (void)didReceiveMemoryWarning 46 | { 47 | [super didReceiveMemoryWarning]; 48 | // Dispose of any resources that can be recreated. 49 | } 50 | 51 | 52 | -(BOOL)textFieldShouldReturn:(UITextField *)textField { 53 | //Keyboard becomes visible 54 | [textField resignFirstResponder]; 55 | [self register:nil]; 56 | return YES; 57 | } 58 | 59 | /* 60 | #pragma mark - Navigation 61 | 62 | // In a storyboard-based application, you will often want to do a little preparation before navigation 63 | - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 64 | { 65 | // Get the new view controller using [segue destinationViewController]. 66 | // Pass the selected object to the new view controller. 67 | } 68 | */ 69 | 70 | - (IBAction)register:(id)sender { 71 | 72 | 73 | [self.procedureName resignFirstResponder]; 74 | self.textArea.text = @""; 75 | 76 | if(self.procedureAction.enabled) { 77 | 78 | [[AppDel wampConnection] registerRPC:self.procedureName.text procedure:^(MDWamp *client, MDWampInvocation *invocation) { 79 | 80 | if(self.procedureAction.selectedSegmentIndex == 0) { 81 | CGRect rect=self.view.bounds; 82 | UIGraphicsBeginImageContext(rect.size); 83 | 84 | CGContextRef context=UIGraphicsGetCurrentContext(); 85 | 86 | [[AppDel window].layer renderInContext:context]; 87 | 88 | UIImage *image=UIGraphicsGetImageFromCurrentImageContext(); 89 | UIGraphicsEndImageContext(); 90 | NSData * data = UIImagePNGRepresentation(image); 91 | NSString *b64 = [[NSString alloc] initWithData:[data base64EncodedDataWithOptions:NSDataBase64Encoding64CharacterLineLength] encoding:NSUTF8StringEncoding]; 92 | [client resultForInvocation:invocation arguments:@[b64] argumentsKw:nil]; 93 | } else { 94 | [client resultForInvocation:invocation arguments:nil argumentsKw:@{ 95 | @"systemVersion": [[UIDevice currentDevice] systemVersion], 96 | @"systemName": [[UIDevice currentDevice] systemName], 97 | @"name": [[UIDevice currentDevice] name] 98 | }]; 99 | } 100 | 101 | 102 | } cancelHandler:nil registerResult:^(NSError *error) { 103 | 104 | if(error){ 105 | UIAlertView *av = [[UIAlertView alloc] initWithTitle:@"!" message:error.localizedDescription delegate:nil cancelButtonTitle:@"Close" otherButtonTitles:nil, nil]; 106 | [av show]; 107 | } else { 108 | self.textArea.text = @"Procedure registered!"; 109 | self.procedureName.enabled = NO; 110 | self.procedureAction.enabled = NO; 111 | [self.registerButton setTitle:@"UNREGISTER" forState:UIControlStateNormal]; 112 | } 113 | }]; 114 | } else { 115 | [[AppDel wampConnection] unregisterRPC:self.procedureName.text result:^(NSError *error) { 116 | if(error){ 117 | UIAlertView *av = [[UIAlertView alloc] initWithTitle:@"!" message:error.localizedDescription delegate:nil cancelButtonTitle:@"Close" otherButtonTitles:nil, nil]; 118 | [av show]; 119 | } else { 120 | self.textArea.text = @"Successfully unregistered"; 121 | } 122 | }]; 123 | 124 | self.procedureName.enabled = YES; 125 | self.procedureAction.enabled = YES; 126 | [self.registerButton setTitle:@"Register" forState:UIControlStateNormal]; 127 | } 128 | } 129 | @end 130 | -------------------------------------------------------------------------------- /MDWampTests/MDWampProtocolVersion2Tests.m: -------------------------------------------------------------------------------- 1 | // 2 | // MDWampTests.m 3 | // MDWamp 4 | // 5 | // Created by Niko Usai on 11/03/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | #import 9 | #import "XCTAsyncTestCase.h" 10 | #import 11 | #import 12 | #import "NSMutableArray+MDStack.h" 13 | 14 | @interface MDWampProtocolVersion2Tests : XCTestCase 15 | @property (strong, nonatomic) MDWampProtocolVersion2 *protocol; 16 | @end 17 | 18 | @implementation MDWampProtocolVersion2Tests 19 | 20 | - (void)setUp 21 | { 22 | [super setUp]; 23 | _protocol = [[MDWampProtocolVersion2 alloc] init]; 24 | 25 | } 26 | 27 | - (void)tearDown 28 | { 29 | // Put teardown code here. This method is called after the invocation of each test method in the class. 30 | [super tearDown]; 31 | } 32 | 33 | - (void) testSendHelloAndSendGoodbye 34 | { 35 | XCTAssert([_protocol shouldSendGoodbye] && [_protocol shouldSendHello], @"Vesion 2 of protocol should send Hello and Goodbye"); 36 | } 37 | 38 | - (void)testHello 39 | { 40 | NSArray *payload = @[@1, @"somerealm", @{@"roles": @{@"publisher":@{}}}]; 41 | 42 | 43 | MDWampHello *hello = (MDWampHello *)[_protocol unmarshallMessage:payload]; 44 | 45 | XCTAssertNotNil(hello, @"Message Must not be nil"); 46 | XCTAssertNotNil([hello.roles objectForKey:@"publisher"], @"Checking Message integrity"); 47 | XCTAssertEqualObjects(hello.realm, payload[1], @"Checking Message integrity"); 48 | 49 | NSArray *marshalled = [_protocol marshallMessage:hello]; 50 | 51 | XCTAssertEqualObjects(payload, marshalled, @"Marshalled Message should be equal to payload"); 52 | 53 | } 54 | 55 | - (void)testWelcome 56 | { 57 | NSArray *payload = @[@2, @21233872738, @{@"roles": @{@"broker":@{}}}]; 58 | 59 | MDWampWelcome *msg = (MDWampWelcome *)[_protocol unmarshallMessage:payload]; 60 | 61 | XCTAssertNotNil(msg, @"Message Must not be nil"); 62 | XCTAssertNotNil([msg.roles objectForKey:@"broker"], @"Checking Message integrity"); 63 | XCTAssertEqualObjects(msg.session, payload[1], @"Checking Message integrity"); 64 | 65 | NSArray *marshalled = [_protocol marshallMessage:msg]; 66 | 67 | XCTAssertEqualObjects(payload, marshalled, @"Marshalled Message should be equal to payload"); 68 | } 69 | 70 | - (void)testAbort 71 | { 72 | NSArray *payload = @[@3, @{@"message": @"The realm does not exist."}, @"wamp.error.no_such_realm"]; 73 | 74 | MDWampAbort *msg = (MDWampAbort *)[_protocol unmarshallMessage:payload]; 75 | 76 | XCTAssertNotNil(msg, @"Message Must not be nil"); 77 | XCTAssertNotNil([msg.details objectForKey:@"message"], @"Checking Message integrity"); 78 | XCTAssertEqualObjects(msg.reason, payload[2], @"Checking Message integrity"); 79 | 80 | NSArray *marshalled = [_protocol marshallMessage:msg]; 81 | 82 | XCTAssertEqualObjects(payload, marshalled, @"Marshalled Message should be equal to payload"); 83 | } 84 | 85 | - (void)testChallangeCode 86 | { 87 | NSArray *payload = @[@4, @{@"message": @"The realm does not exist."}, @"wamp.error.no_such_realm"]; 88 | } 89 | 90 | - (void)testAuthenticateCode 91 | { 92 | NSArray *payload = @[@5, @{@"message": @"The realm does not exist."}, @"wamp.error.no_such_realm"]; 93 | } 94 | 95 | - (void)testGoodbye 96 | { 97 | NSArray *payload = @[@6, @{@"message": @"The host is shutting down now."}, @"wamp.error.system_shutdown"]; 98 | 99 | MDWampGoodbye *msg = (MDWampGoodbye *)[_protocol unmarshallMessage:payload]; 100 | 101 | XCTAssertNotNil(msg, @"Message Must not be nil"); 102 | XCTAssertNotNil([msg.details objectForKey:@"message"], @"Checking Message integrity"); 103 | XCTAssertEqualObjects(msg.reason, payload[2], @"Checking Message integrity"); 104 | 105 | NSArray *marshalled = [_protocol marshallMessage:msg]; 106 | 107 | XCTAssertEqualObjects(payload, marshalled, @"Marshalled Message should be equal to payload"); 108 | } 109 | 110 | - (void)testHeartbitCode 111 | { 112 | NSArray *payload = @[@7, @{@"message": @"The realm does not exist."}, @"wamp.error.no_such_realm"]; 113 | } 114 | 115 | - (void)testError 116 | { 117 | NSArray *payload = @[@8, @68, @123456789, @{}, @"com.myapp.error.object_write_protected", @[@"Object is write protected"], @{@"severity": @3}]; 118 | 119 | MDWampError *msg = (MDWampError *)[_protocol unmarshallMessage:payload]; 120 | 121 | XCTAssertNotNil(msg, @"Message Must not be nil"); 122 | 123 | XCTAssertEqualObjects(msg.error, payload[4], @"Checking Message integrity"); 124 | XCTAssertEqualObjects(msg.type, payload[1], @"Checking Message integrity"); 125 | XCTAssertEqualObjects(msg.request, payload[2], @"Checking Message integrity"); 126 | XCTAssertEqualObjects(msg.arguments[0], payload[5][0], @"Checking Message integrity"); 127 | XCTAssertEqualObjects(msg.argumentsKw[@"severity"], payload[6][@"severity"], @"Checking Message integrity"); 128 | 129 | NSArray *marshalled = [_protocol marshallMessage:msg]; 130 | 131 | XCTAssertEqualObjects(payload, marshalled, @"Marshalled Message should be equal to payload"); 132 | } 133 | 134 | @end 135 | -------------------------------------------------------------------------------- /MDWampDemo/src/ChatViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // SecondViewController.m 3 | // MDWampDemo 4 | // 5 | // Created by Niko Usai on 27/06/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | 9 | #import "ChatViewController.h" 10 | 11 | @interface ChatViewController () 12 | @property (nonatomic, strong) NSMutableArray *messages; 13 | @property (assign) BOOL cellIsLeft; 14 | 15 | @end 16 | 17 | @implementation ChatViewController 18 | 19 | - (void)viewDidLoad 20 | { 21 | [super viewDidLoad]; 22 | self.roomNameField.text = self.room; 23 | self.messages = [[NSMutableArray alloc] init]; 24 | MDWamp *wamp = [AppDel wampConnection]; 25 | [wamp subscribe:[NSString stringWithFormat:@"com.mogui.%@", [self.room stringByReplacingOccurrencesOfString:@" " withString:@"-"]] options:nil onEvent:^(MDWampEvent *payload) { 26 | if(payload.arguments && [payload.arguments count] > 0){ 27 | 28 | // message arrives 29 | [self.messages addObject:payload.arguments[0]]; 30 | [self.tableView reloadData]; 31 | NSIndexPath *ip = [NSIndexPath indexPathForRow:([self.messages count]-1) inSection:0]; 32 | [self.tableView scrollToRowAtIndexPath:ip atScrollPosition:UITableViewScrollPositionBottom animated:YES]; 33 | } 34 | } result:^(NSError *error) { 35 | if (error) { 36 | UIAlertView *av = [[UIAlertView alloc] initWithTitle:@"!!" message:error.localizedDescription delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil]; 37 | [av show]; 38 | [self.navigationController popViewControllerAnimated:YES]; 39 | } else { 40 | NSLog(@"Connectd to chat"); 41 | } 42 | }]; 43 | } 44 | 45 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 46 | return self.messages.count; 47 | } 48 | 49 | 50 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 51 | 52 | BOOL samePosterAsBefore = NO; 53 | 54 | if (indexPath.row == 0) { 55 | self.cellIsLeft = YES; 56 | } else { 57 | samePosterAsBefore = [self.messages[indexPath.row][@"nickname"] isEqual:self.messages[indexPath.row-1][@"nickname"]]; 58 | 59 | if (!samePosterAsBefore) { 60 | self.cellIsLeft = !self.cellIsLeft; 61 | } 62 | } 63 | 64 | NSString *identifier; 65 | if (self.cellIsLeft) { 66 | identifier = @"LeftCell"; 67 | } else { 68 | identifier = @"RightCell"; 69 | } 70 | 71 | UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier forIndexPath:indexPath]; 72 | 73 | UILabel *name = (UILabel*)[cell viewWithTag:1]; 74 | UILabel *text = (UILabel*)[cell viewWithTag:2]; 75 | 76 | if (indexPath.row == 0 || !samePosterAsBefore) { 77 | name.text = self.messages[indexPath.row][@"nickname"]; 78 | } else { 79 | name.text = @""; 80 | } 81 | NSLog(@"%@", self.messages[indexPath.row]); 82 | text.text = self.messages[indexPath.row][@"text"]; 83 | return cell; 84 | } 85 | 86 | -(void)textFieldDidBeginEditing:(UITextField *)textField { 87 | //Keyboard becomes visible 88 | self.inputControls.frame = CGRectMake(self.inputControls.frame.origin.x, 89 | self.inputControls.frame.origin.y - 215, 90 | self.inputControls.frame.size.width, 91 | self.inputControls.frame.size.height); //resize 92 | CGRect tv = self.tableView.frame; 93 | tv.size.height = tv.size.height - 215; 94 | self.tableView.frame = tv; 95 | 96 | } 97 | 98 | 99 | - (BOOL)textFieldShouldReturn:(UITextField *)textField 100 | { 101 | [textField resignFirstResponder]; 102 | self.inputControls.frame = CGRectMake(self.inputControls.frame.origin.x, 103 | self.inputControls.frame.origin.y + 215, 104 | self.inputControls.frame.size.width, 105 | self.inputControls.frame.size.height); //resize 106 | CGRect tv = self.tableView.frame; 107 | tv.size.height = tv.size.height + 215; 108 | self.tableView.frame = tv; 109 | 110 | return YES; 111 | } 112 | 113 | - (IBAction)part:(id)sender { 114 | // unregister 115 | MDWamp *wamp = [AppDel wampConnection]; 116 | [wamp unsubscribe:[NSString stringWithFormat:@"com.mogui.%@", [self.room stringByReplacingOccurrencesOfString:@" " withString:@"-"]] result:^(NSError *error) { 117 | NSLog(@"%@", error); 118 | if (!error) { 119 | [self dismissViewControllerAnimated:YES completion:nil]; 120 | } 121 | }]; 122 | 123 | } 124 | 125 | - (IBAction)send:(id)sender { 126 | if (![self.inputText.text isEqual:@""]) { 127 | 128 | 129 | NSDictionary *payload = @{@"nickname":self.nickname, @"text":self.inputText.text}; 130 | 131 | [[AppDel wampConnection] publishTo:[NSString stringWithFormat:@"com.mogui.%@", [self.room stringByReplacingOccurrencesOfString:@" " withString:@"-"]] args:@[payload] kw:nil options:@{@"exclude_me":@NO} result:nil]; 132 | self.inputText.text = @""; 133 | 134 | } 135 | } 136 | @end 137 | -------------------------------------------------------------------------------- /MDWamp/src/MDWampMessages/MDWampMessageFactory.m: -------------------------------------------------------------------------------- 1 | // 2 | // MDWampMessageFactory.m 3 | // MDWamp 4 | // 5 | // Created by Niko Usai on 01/04/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | // 20 | 21 | #import "MDWampMessageFactory.h" 22 | #import "MDWampMessage.h" 23 | 24 | NSString *const kMDWampHello = @"MDWampHello"; 25 | NSString *const kMDWampWelcome = @"MDWampWelcome"; 26 | NSString *const kMDWampAbort = @"MDWampAbort"; 27 | NSString *const kMDWampChallenge = @"MDWampChallenge"; 28 | NSString *const kMDWampAuthenticate = @"MDWampAuthenticate"; 29 | NSString *const kMDWampGoodbye = @"MDWampGoodbye"; 30 | NSString *const kMDWampError = @"MDWampError"; 31 | NSString *const kMDWampPublish = @"MDWampPublish"; 32 | NSString *const kMDWampPublished = @"MDWampPublished"; 33 | NSString *const kMDWampSubscribe = @"MDWampSubscribe"; 34 | NSString *const kMDWampSubscribed = @"MDWampSubscribed"; 35 | NSString *const kMDWampUnsubscribe = @"MDWampUnsubscribe"; 36 | NSString *const kMDWampUnsubscribed = @"MDWampUnsubscribed"; 37 | NSString *const kMDWampEvent = @"MDWampEvent"; 38 | NSString *const kMDWampCall = @"MDWampCall"; 39 | NSString *const kMDWampCancel = @"MDWampCancel"; 40 | NSString *const kMDWampResult = @"MDWampResult"; 41 | NSString *const kMDWampRegister = @"MDWampRegister"; 42 | NSString *const kMDWampRegistered = @"MDWampRegistered"; 43 | NSString *const kMDWampUnregister = @"MDWampUnregister"; 44 | NSString *const kMDWampUnregistered = @"MDWampUnregistered"; 45 | NSString *const kMDWampInvocation = @"MDWampInvocation"; 46 | NSString *const kMDWampInterrupt = @"MDWampInterrupt"; 47 | NSString *const kMDWampYield = @"MDWampYield"; 48 | 49 | @interface MDWampMessageFactory () 50 | @property (nonatomic, strong) NSDictionary *messageMapping; 51 | @end 52 | 53 | @implementation MDWampMessageFactory 54 | 55 | + (instancetype) sharedFactory { 56 | static id sharedInstance = nil; 57 | static dispatch_once_t onceToken; 58 | dispatch_once(&onceToken, ^{ 59 | sharedInstance = [[MDWampMessageFactory alloc] init]; 60 | }); 61 | return sharedInstance; 62 | } 63 | 64 | - (id)init { 65 | self = [super init]; 66 | if (self) { 67 | self.messageMapping = @{ 68 | @1 : kMDWampHello, 69 | @2 : kMDWampWelcome, 70 | @3 : kMDWampAbort, 71 | @4 : kMDWampChallenge, 72 | @5 : kMDWampAuthenticate, 73 | @6 : kMDWampGoodbye, 74 | @8 : kMDWampError, 75 | @16 : kMDWampPublish, 76 | @17 : kMDWampPublished, 77 | @32 : kMDWampSubscribe, 78 | @33 : kMDWampSubscribed, 79 | @34 : kMDWampUnsubscribe, 80 | @35 : kMDWampUnsubscribed, 81 | @36 : kMDWampEvent, 82 | @48 : kMDWampCall, 83 | @49 : kMDWampCancel, 84 | @50 : kMDWampResult, 85 | @64 : kMDWampRegister, 86 | @65 : kMDWampRegistered, 87 | @66 : kMDWampUnregister, 88 | @67 : kMDWampUnregistered, 89 | @68 : kMDWampInvocation, 90 | @69 : kMDWampInterrupt, 91 | @70 : kMDWampYield }; 92 | } 93 | return self; 94 | } 95 | 96 | - (NSString *)nameFromCode:(NSNumber*)code 97 | { 98 | return self.messageMapping[code]; 99 | } 100 | 101 | - (id)objectFromCode:(NSNumber*)code withPayload:(NSArray*)payload 102 | { 103 | NSString *className = self.messageMapping[code]; 104 | if (!className) { 105 | [NSException raise:kMDWampErrorDomain format:@"No registered Message for given code: %@", code]; 106 | } 107 | Class messageClass = NSClassFromString(className); 108 | if (!messageClass) { 109 | [NSException raise:kMDWampErrorDomain format:@"Class %@ is not implemented", className]; 110 | } 111 | return [(id)[messageClass alloc] initWithPayload:payload]; 112 | } 113 | 114 | - (NSNumber *)codeFromObject:(id)object 115 | { 116 | NSString *className = NSStringFromClass([object class]); 117 | 118 | return [self codeFromClassName:className]; 119 | } 120 | 121 | - (NSNumber *)codeFromClassName:(NSString*)className 122 | { 123 | NSArray *keys = [self.messageMapping allKeysForObject:className]; 124 | if ([keys count] != 1) { 125 | [NSException raise:kMDWampErrorDomain format:@"Class %@ is not a registered message in the protocol", className]; 126 | } 127 | return keys[0]; 128 | } 129 | 130 | 131 | @end 132 | -------------------------------------------------------------------------------- /MDWampTests/MDWampTransportWebSocketTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // MDWampTransportWebSocketTests.m 3 | // MDWamp 4 | // 5 | // Created by Niko Usai on 17/06/14. 6 | // Copyright (c) 2014 mogui.it. All rights reserved. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | // 20 | 21 | #import 22 | #import "XCTAsyncTestCase.h" 23 | #import "MDWampTransportWebSocket.h" 24 | #import "MDWampTransportDelegate.h" 25 | @interface MDWampTransportWebSocketTests : XCTAsyncTestCase 26 | { 27 | MDWampTransportWebSocket *transport; 28 | } 29 | @property (assign) BOOL testClose; 30 | @property (assign) BOOL testCloseError; 31 | @property (assign) BOOL testMessage; 32 | @end 33 | 34 | @implementation MDWampTransportWebSocketTests 35 | 36 | - (void)setUp 37 | { 38 | [super setUp]; 39 | self.testClose = NO; 40 | self.testMessage = NO; 41 | [self prepare]; 42 | // Put setup code here. This method is called before the invocation of each test method in the class. 43 | } 44 | 45 | - (void)tearDown 46 | { 47 | // Put teardown code here. This method is called after the invocation of each test method in the class. 48 | [super tearDown]; 49 | } 50 | 51 | - (void)transportDidReceiveMessage:(NSData *)message { 52 | XCTAssertNotNil(message, @"Must receive a message"); 53 | [self notify:kXCTUnitWaitStatusSuccess]; 54 | } 55 | 56 | - (void)transportDidOpenWithSerialization:(NSString*)serialization { 57 | 58 | if (self.testClose) { 59 | [transport close]; 60 | } else if (self.testCloseError) { 61 | 62 | // Send malformed message to force socket close 63 | [transport send:@"[1, \"Realm1\", {}]"]; 64 | } else if (self.testMessage) { 65 | while (![transport isConnected]) { 66 | // just wait 67 | sleep(1); 68 | } 69 | // test hello message just to receive something back 70 | [transport send:@"[1, \"Realm1\", {\"roles\": {\"publisher\": {}}}]"]; 71 | } else { 72 | XCTAssertEqualObjects(serialization, kMDWampSerializationJSON, @"serialization should be json"); 73 | [self notify:kXCTUnitWaitStatusSuccess]; 74 | } 75 | } 76 | 77 | - (void)transportDidFailWithError:(NSError *)error { 78 | XCTAssertNotNil(error, @"error triggered for bad protocol"); 79 | XCTAssertEqual(error.code,2132, @"bad response code error from server 400 must be triggered"); 80 | [self notify:kXCTUnitWaitStatusSuccess]; 81 | } 82 | 83 | - (void)transportDidCloseWithError:(NSError *)error { 84 | if (self.testCloseError) { 85 | XCTAssertNotNil(error, @"Close must be called with a nice error"); 86 | XCTAssertEqual(error.code,1002, @"WAMP Protocol Error (missing mandatory roles attribute in options in HELLO) must be triggered"); 87 | [self notify:kXCTUnitWaitStatusSuccess]; 88 | } else if (self.testClose) { 89 | XCTAssertNotNil(error, @"Close must be called with a nice error"); 90 | XCTAssertEqual(error.code,54, @"Connection resetted by peer must be triggered"); 91 | [self notify:kXCTUnitWaitStatusSuccess]; 92 | } 93 | } 94 | 95 | 96 | - (void)testDidOpen 97 | { 98 | transport = [[MDWampTransportWebSocket alloc] initWithServer:[NSURL URLWithString:@"ws://localhost:8080"] protocolVersions:@[kMDWampProtocolWamp2json]]; 99 | transport.delegate = self; 100 | [transport open]; 101 | [self waitForStatus:kXCTUnitWaitStatusSuccess timeout:1]; 102 | } 103 | 104 | - (void)testDidFailWrongProtocol 105 | { 106 | transport = [[MDWampTransportWebSocket alloc] initWithServer:[NSURL URLWithString:@"ws://localhost:8080"] protocolVersions:@[kMDWampProtocolWamp2json]]; // crossbar fails when giving verison 1 107 | transport.delegate = self; 108 | [transport open]; 109 | [self waitForStatus:kXCTUnitWaitStatusSuccess timeout:1]; 110 | } 111 | 112 | - (void)testSendReceiveMessage 113 | { 114 | transport = [[MDWampTransportWebSocket alloc] initWithServer:[NSURL URLWithString:@"ws://localhost:8080"] protocolVersions:@[kMDWampProtocolWamp2json]]; // crossbar fails when giving verison 1 115 | transport.delegate = self; 116 | self.testMessage = YES; 117 | [transport open]; 118 | [self waitForStatus:kXCTUnitWaitStatusSuccess timeout:3]; 119 | } 120 | 121 | //- (void)testDidClose 122 | //{ 123 | // transport = [[MDWampTransportWebSocket alloc] initWithServer:[NSURL URLWithString:@"ws://localhost:8080/ws"] protocolVersions:@[@"wamp"]]; // crossbar fails when giving verison 1 124 | // transport.delegate = self; 125 | // self.testClose = YES; 126 | // [transport open]; 127 | // [self waitForStatus:kXCTUnitWaitStatusSuccess timeout:1]; 128 | //} 129 | 130 | - (void)testDidCloseError 131 | { 132 | transport = [[MDWampTransportWebSocket alloc] initWithServer:[NSURL URLWithString:@"ws://localhost:8080"] protocolVersions:@[kMDWampProtocolWamp2json]]; // crossbar fails when giving verison 1 133 | transport.delegate = self; 134 | self.testCloseError = YES; 135 | [transport open]; 136 | [self waitForStatus:kXCTUnitWaitStatusSuccess timeout:1]; 137 | } 138 | @end 139 | -------------------------------------------------------------------------------- /MDWampTests/XCTAsyncTestCase.m: -------------------------------------------------------------------------------- 1 | // 2 | // XCTAsyncTestCase.m 3 | // Modified by Sveinung Kval Bakken on 16/10/13 4 | // to serve as a drop-in replacement for GHAsyncTestCase using XCTest 5 | // Original copyright notice below: 6 | // 7 | // GHAsyncTestCase.m 8 | // GHUnit 9 | // 10 | // Created by Gabriel Handford on 4/8/09. 11 | // Copyright 2009. All rights reserved. 12 | // 13 | // Permission is hereby granted, free of charge, to any person 14 | // obtaining a copy of this software and associated documentation 15 | // files (the "Software"), to deal in the Software without 16 | // restriction, including without limitation the rights to use, 17 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 18 | // copies of the Software, and to permit persons to whom the 19 | // Software is furnished to do so, subject to the following 20 | // conditions: 21 | // 22 | // The above copyright notice and this permission notice shall be 23 | // included in all copies or substantial portions of the Software. 24 | // 25 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 26 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 27 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 28 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 29 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 30 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 31 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 32 | // OTHER DEALINGS IN THE SOFTWARE. 33 | // 34 | 35 | #import "XCTAsyncTestCase.h" 36 | #import 37 | 38 | typedef enum { 39 | kXCTUnitAsyncErrorNone, 40 | kXCTUnitAsyncErrorUnprepared, 41 | kXCTUnitAsyncErrorTimedOut, 42 | kXCTUnitAsyncErrorInvalidStatus 43 | } XCTUnitAsyncError; 44 | 45 | @implementation XCTAsyncTestCase 46 | 47 | @synthesize runLoopModes=_runLoopModes; 48 | 49 | 50 | // Internal GHUnit setUp 51 | - (void)setUp { 52 | [super setUp]; 53 | lock_ = [[NSRecursiveLock alloc] init]; 54 | prepared_ = NO; 55 | notifiedStatus_ = kXCTUnitWaitStatusUnknown; 56 | } 57 | 58 | // Internal GHUnit tear down 59 | - (void)tearDown { 60 | [super tearDown]; 61 | waitSelector_ = NULL; 62 | if (prepared_) [lock_ unlock]; // If we prepared but never waited we need to unlock 63 | lock_ = nil; 64 | } 65 | 66 | - (void)prepare { 67 | [self prepare:self.invocation.selector]; 68 | } 69 | 70 | - (void)prepare:(SEL)selector { 71 | [lock_ lock]; 72 | prepared_ = YES; 73 | waitSelector_ = selector; 74 | notifiedStatus_ = kXCTUnitWaitStatusUnknown; 75 | } 76 | 77 | - (XCTUnitAsyncError)_waitFor:(NSInteger)status timeout:(NSTimeInterval)timeout { 78 | if (!prepared_) { 79 | return kXCTUnitAsyncErrorUnprepared; 80 | } 81 | prepared_ = NO; 82 | 83 | waitForStatus_ = status; 84 | 85 | if (!_runLoopModes) 86 | _runLoopModes = [NSArray arrayWithObjects:NSDefaultRunLoopMode, NSRunLoopCommonModes, nil]; 87 | 88 | NSTimeInterval checkEveryInterval = 0.05; 89 | NSDate *runUntilDate = [NSDate dateWithTimeIntervalSinceNow:timeout]; 90 | BOOL timedOut = NO; 91 | NSUInteger runIndex = 0; 92 | while(notifiedStatus_ == kXCTUnitWaitStatusUnknown) { 93 | NSString *mode = [_runLoopModes objectAtIndex:(runIndex++ % [_runLoopModes count])]; 94 | 95 | [lock_ unlock]; 96 | @autoreleasepool { 97 | if (!mode || ![[NSRunLoop currentRunLoop] runMode:mode beforeDate:[NSDate dateWithTimeIntervalSinceNow:checkEveryInterval]]) 98 | // If there were no run loop sources or timers then we should sleep for the interval 99 | [NSThread sleepForTimeInterval:checkEveryInterval]; 100 | } 101 | [lock_ lock]; 102 | 103 | // If current date is after the run until date 104 | if ([runUntilDate compare:[NSDate date]] == NSOrderedAscending) { 105 | timedOut = YES; 106 | break; 107 | } 108 | } 109 | [lock_ unlock]; 110 | 111 | if (timedOut) { 112 | return kXCTUnitAsyncErrorTimedOut; 113 | } else if (waitForStatus_ != notifiedStatus_) { 114 | return kXCTUnitAsyncErrorInvalidStatus; 115 | } 116 | 117 | return kXCTUnitAsyncErrorNone; 118 | } 119 | 120 | - (void)waitFor:(NSInteger)status timeout:(NSTimeInterval)timeout { 121 | [NSException raise:NSDestinationInvalidException format:@"Deprecated; Use waitForStatus:timeout:"]; 122 | } 123 | 124 | - (void)waitForStatus:(NSInteger)status timeout:(NSTimeInterval)timeout { 125 | XCTUnitAsyncError error = [self _waitFor:status timeout:timeout]; 126 | if (error == kXCTUnitAsyncErrorTimedOut) { 127 | XCTFail(@"Request timed out"); 128 | } else if (error == kXCTUnitAsyncErrorInvalidStatus) { 129 | XCTFail(@"Request finished with the wrong status: %ld != %ld", (long)status, (long)notifiedStatus_); 130 | } else if (error == kXCTUnitAsyncErrorUnprepared) { 131 | XCTFail(@"Call prepare before calling asynchronous method and waitForStatus:timeout:"); 132 | } 133 | } 134 | 135 | - (void)waitForTimeout:(NSTimeInterval)timeout { 136 | XCTUnitAsyncError error = [self _waitFor:-1 timeout:timeout]; 137 | if (error != kXCTUnitAsyncErrorTimedOut) { 138 | XCTFail(@"Request should have timed out"); 139 | } 140 | } 141 | 142 | // Similar to _waitFor:timeout: but just runs the loops 143 | // From Robert Palmer, pauseForTimeout 144 | - (void)runForInterval:(NSTimeInterval)interval { 145 | NSTimeInterval checkEveryInterval = 0.05; 146 | NSDate *runUntilDate = [NSDate dateWithTimeIntervalSinceNow:interval]; 147 | 148 | if (!_runLoopModes) 149 | _runLoopModes = [NSArray arrayWithObjects:NSDefaultRunLoopMode, NSRunLoopCommonModes, nil]; 150 | 151 | NSUInteger runIndex = 0; 152 | 153 | while ([runUntilDate compare:[NSDate dateWithTimeIntervalSinceNow:0]] == NSOrderedDescending) { 154 | NSString *mode = [_runLoopModes objectAtIndex:(runIndex++ % [_runLoopModes count])]; 155 | 156 | [lock_ unlock]; 157 | @autoreleasepool { 158 | if (!mode || ![[NSRunLoop currentRunLoop] runMode:mode beforeDate:[NSDate dateWithTimeIntervalSinceNow:checkEveryInterval]]) 159 | // If there were no run loop sources or timers then we should sleep for the interval 160 | [NSThread sleepForTimeInterval:checkEveryInterval]; 161 | } 162 | [lock_ lock]; 163 | } 164 | } 165 | 166 | - (void)notify:(NSInteger)status { 167 | [self notify:status forSelector:NULL]; 168 | } 169 | 170 | - (void)notify:(NSInteger)status forSelector:(SEL)selector { 171 | // Note: If this is called from a stray thread or delayed call, we may not be in an autorelease pool 172 | @autoreleasepool { 173 | 174 | // Make sure the notify is for the currently waiting test 175 | if (selector != NULL && !sel_isEqual(waitSelector_, selector)) { 176 | NSLog(@"Warning: Notified from %@ but we were waiting for %@", NSStringFromSelector(selector), NSStringFromSelector(waitSelector_)); 177 | } else { 178 | [lock_ lock]; 179 | notifiedStatus_ = status; 180 | [lock_ unlock]; 181 | } 182 | 183 | } 184 | } 185 | 186 | @end --------------------------------------------------------------------------------