Permalink
Browse files

initial commit of the iOS SDK

  • Loading branch information...
tyamell committed Jan 18, 2011
0 parents commit baf9a0b64289ba72dbd470cce2b4dbd79757705d
Showing with 7,515 additions and 0 deletions.
  1. +18 −0 .gitignore
  2. +17 −0 StackMob/Constants.m
  3. +18 −0 StackMob/StackMobAdditions.h
  4. +36 −0 StackMob/StackMobAdditions.m
  5. +263 −0 StackMob/StackMobClientData.m
  6. +330 −0 StackMob/StackMobRequest.m
  7. +125 −0 StackMob/StackMobSession.m
  8. +679 −0 StackMobiOS.xcodeproj/project.pbxproj
  9. +1,369 −0 StackMobiOS.xcodeproj/ty.mode1v3
  10. +197 −0 StackMobiOS.xcodeproj/ty.pbxuser
  11. +33 −0 StackMobiOS_Prefix.pch
  12. +20 −0 Tests-Info.plist
  13. +230 −0 external/OAuthConsumer/Crypto/Base64Transcoder.c
  14. +36 −0 external/OAuthConsumer/Crypto/Base64Transcoder.h
  15. +35 −0 external/OAuthConsumer/NSMutableURLRequest+Parameters.h
  16. +92 −0 external/OAuthConsumer/NSMutableURLRequest+Parameters.m
  17. +34 −0 external/OAuthConsumer/NSString+URLEncoding.h
  18. +52 −0 external/OAuthConsumer/NSString+URLEncoding.m
  19. +34 −0 external/OAuthConsumer/NSURL+Base.h
  20. +38 −0 external/OAuthConsumer/NSURL+Base.m
  21. +45 −0 external/OAuthConsumer/OAAsynchronousDataFetcher.h
  22. +134 −0 external/OAuthConsumer/OAAsynchronousDataFetcher.m
  23. +40 −0 external/OAuthConsumer/OAConsumer.h
  24. +51 −0 external/OAuthConsumer/OAConsumer.m
  25. +45 −0 external/OAuthConsumer/OADataFetcher.h
  26. +65 −0 external/OAuthConsumer/OADataFetcher.m
  27. +32 −0 external/OAuthConsumer/OAHMAC_SHA1SignatureProvider.h
  28. +58 −0 external/OAuthConsumer/OAHMAC_SHA1SignatureProvider.m
  29. +68 −0 external/OAuthConsumer/OAMutableURLRequest.h
  30. +229 −0 external/OAuthConsumer/OAMutableURLRequest.m
  31. +31 −0 external/OAuthConsumer/OAPlaintextSignatureProvider.h
  32. +43 −0 external/OAuthConsumer/OAPlaintextSignatureProvider.m
  33. +45 −0 external/OAuthConsumer/OARequestParameter.h
  34. +70 −0 external/OAuthConsumer/OARequestParameter.m
  35. +43 −0 external/OAuthConsumer/OAServiceTicket.h
  36. +51 −0 external/OAuthConsumer/OAServiceTicket.m
  37. +34 −0 external/OAuthConsumer/OASignatureProviding.h
  38. +41 −0 external/OAuthConsumer/OAToken.h
  39. +105 −0 external/OAuthConsumer/OAToken.m
  40. +39 −0 external/OAuthConsumer/OAuthConsumer.h
  41. +1 −0 external/libraries/YAJLIOS.framework/Headers
  42. +1 −0 external/libraries/YAJLIOS.framework/Resources
  43. +50 −0 external/libraries/YAJLIOS.framework/Versions/A/Headers/NSBundle+YAJL.h
  44. +118 −0 external/libraries/YAJLIOS.framework/Versions/A/Headers/NSObject+YAJL.h
  45. +34 −0 external/libraries/YAJLIOS.framework/Versions/A/Headers/YAJL.h
  46. +98 −0 external/libraries/YAJLIOS.framework/Versions/A/Headers/YAJLDocument.h
  47. +104 −0 external/libraries/YAJLIOS.framework/Versions/A/Headers/YAJLGen.h
  48. +34 −0 external/libraries/YAJLIOS.framework/Versions/A/Headers/YAJLIOS.h
  49. +129 −0 external/libraries/YAJLIOS.framework/Versions/A/Headers/YAJLParser.h
  50. +85 −0 external/libraries/YAJLIOS.framework/Versions/A/Headers/yajl_common.h
  51. +159 −0 external/libraries/YAJLIOS.framework/Versions/A/Headers/yajl_gen.h
  52. +193 −0 external/libraries/YAJLIOS.framework/Versions/A/Headers/yajl_parse.h
  53. +18 −0 external/libraries/YAJLIOS.framework/Versions/A/Resources/Info.plist
  54. BIN external/libraries/YAJLIOS.framework/Versions/A/YAJLIOS
  55. +1 −0 external/libraries/YAJLIOS.framework/Versions/Current
  56. +1 −0 external/libraries/YAJLIOS.framework/YAJLIOS
  57. +193 −0 external/reachability/Reachability.h
  58. +814 −0 external/reachability/Reachability.m
  59. +15 −0 include/StackMob/Constants.h
  60. +75 −0 include/StackMob/StackMobClientData.h
  61. +79 −0 include/StackMob/StackMobRequest.h
  62. +139 −0 include/StackMob/StackMobSession.h
  63. +22 −0 resources/Framework.plist
  64. +70 −0 scripts/build.sh
  65. +30 −0 tests/APIRequestTests.h
  66. +127 −0 tests/APIRequestTests.m
@@ -0,0 +1,18 @@
+# use glob syntax.
+syntax: glob
+*.ser
+*.class
+*~
+*.bak
+*.off
+*.old
+.DS_Store
+
+
+# eclipse conf file
+.settings
+.classpath
+.project
+.manager
+
+build/**/*
@@ -0,0 +1,17 @@
+// Copyright 2011 StackMob, Inc
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+
+// http://www.apache.org/licenses/LICENSE-2.0
+
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#import "Constants.h"
+
+NSString * const kAPIVersion = @"1";
@@ -0,0 +1,18 @@
+// Copyright 2011 StackMob, Inc
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+
+// http://www.apache.org/licenses/LICENSE-2.0
+
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#import <Foundation/Foundation.h>
+@interface NSDictionary (StackMobAdditions)
+ - (NSString *)queryString;
+@end
@@ -0,0 +1,36 @@
+// Copyright 2011 StackMob, Inc
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+
+// http://www.apache.org/licenses/LICENSE-2.0
+
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#import "StackMobAdditions.h"
+
+@implementation NSDictionary (StackMobAdditions)
+
+- (NSString*)queryString
+{
+ NSMutableArray* encodedPieces = [NSMutableArray array];
+
+ for(NSString* argumentKey in self)
+ {
+ NSString* argumentValue = [self objectForKey:argumentKey];
+ if(!argumentValue)
+ continue;
+
+ argumentValue = [(NSString*)CFURLCreateStringByAddingPercentEscapes(NULL, (CFStringRef)argumentValue, NULL, CFSTR("?=&+"), CFStringConvertNSStringEncodingToEncoding(NSUTF8StringEncoding)) autorelease];
+ [encodedPieces addObject:[NSString stringWithFormat:@"%@=%@", argumentKey, argumentValue]];
+ }
+
+ return [encodedPieces componentsJoinedByString:@"&"];
+}
+
+@end
@@ -0,0 +1,263 @@
+// Copyright 2011 StackMob, Inc
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+
+// http://www.apache.org/licenses/LICENSE-2.0
+
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#import "StackMobClientData.h"
+#import <CoreLocation/CoreLocation.h>
+#import <UIKit/UIKit.h>
+#import "Reachability.h"
+#include <sys/sysctl.h>
+#include <net/if.h>
+#include <net/if_dl.h>
+
+NSString *bundleVersion = @"";
+NSString *identifier = @"";
+NSString *model = @"";
+NSString *systemVersion = @"";
+NSString *device_name = @"";
+NSString *countryCode = @"";
+NSString *language = @"";
+NSString *jailBroken = @"NO";
+
+static StackMobClientData * _sharedInstance=nil;
+
+@interface StackMobClientData ()
+
+- (void)startLocationUpdates;
+- (void)startReachabilityUpdates;
+- (void)generateClientDataString;
+
+@end
+
+@implementation StackMobClientData
+
+- (id)init {
+ if(self = [super init]) {
+ // Device info.
+ UIDevice *device = [UIDevice currentDevice];
+ identifier = [device uniqueIdentifier];
+ model = [device model];
+ systemVersion = [device systemVersion];
+
+
+ // Locale info.
+ NSLocale *locale = [NSLocale currentLocale];
+ countryCode = [locale objectForKey:NSLocaleCountryCode];
+ language = [[NSLocale currentLocale] objectForKey: NSLocaleLanguageCode];
+
+ // App info.
+ bundleVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:(NSString *)kCFBundleVersionKey];
+
+ jailBroken = [self isJailBrokenStr];
+
+ [self startLocationUpdates];
+ [self startReachabilityUpdates];
+ [self generateClientDataString];
+ }
+
+ return self;
+}
+
++ (StackMobClientData*) sharedClientData;
+{
+ if(!_sharedInstance)
+ {
+ _sharedInstance = [[StackMobClientData alloc] init];
+ }
+ return _sharedInstance;
+}
+
+
+- (NSString *) platform{
+ size_t size;
+ sysctlbyname("hw.machine", NULL, &size, NULL, 0);
+ char *machine = malloc(size);
+ sysctlbyname("hw.machine", machine, &size, NULL, 0);
+ NSString *platform = [NSString stringWithCString:machine encoding: NSUTF8StringEncoding];
+ free(machine);
+ return platform;
+}
+
+- (NSString *) platformString{
+ NSString *platform = [self platform];
+
+ if ([platform isEqualToString:@"iPhone1,1"]) return IPHONE_1G_NAMESTRING;
+ if ([platform isEqualToString:@"iPhone1,2"]) return IPHONE_3G_NAMESTRING;
+ if ([platform hasPrefix:@"iPhone2"]) return IPHONE_3GS_NAMESTRING;
+ if ([platform hasPrefix:@"iPhone3"]) return IPHONE_4_NAMESTRING;
+ if ([platform hasPrefix:@"iPhone4"]) return IPHONE_5_NAMESTRING;
+
+ if ([platform isEqualToString:@"iPod1,1"]) return IPOD_1G_NAMESTRING;
+ if ([platform isEqualToString:@"iPod2,1"]) return IPOD_2G_NAMESTRING;
+ if ([platform isEqualToString:@"iPod3,1"]) return IPOD_3G_NAMESTRING;
+ if ([platform isEqualToString:@"iPod4,1"]) return IPOD_4G_NAMESTRING;
+
+ if ([platform isEqualToString:@"iPad1,1"]) return IPAD_1G_NAMESTRING;
+ if ([platform isEqualToString:@"iPad2,1"]) return IPAD_2G_NAMESTRING;
+
+ if ([platform isEqualToString:@"AppleTV2,1"]) return APPLETV_2G_NAMESTRING;
+
+ if ([platform hasPrefix:@"iPhone"]) return IPHONE_UNKNOWN_NAMESTRING;
+ if ([platform hasPrefix:@"iPod"]) return IPOD_UNKNOWN_NAMESTRING;
+ if ([platform hasPrefix:@"iPad"]) return IPAD_UNKNOWN_NAMESTRING;
+
+ if ([platform hasSuffix:@"86"] || [platform isEqual:@"x86_64"])
+ {
+ if ([[UIScreen mainScreen] bounds].size.width < 768)
+ return IPHONE_SIMULATOR_IPHONE_NAMESTRING;
+ else
+ return IPHONE_SIMULATOR_IPAD_NAMESTRING;
+ }
+ if ([platform isEqualToString:@"iFPGA"]) return IFPGA_NAMESTRING;
+ return IPOD_FAMILY_UNKNOWN_DEVICE;
+}
+
+- (void)dealloc {
+
+ [_locationManager release];
+ [_sharedInstance release];
+ [super dealloc];
+
+}
+
+#pragma mark - Properties
+
+@synthesize clientDataString = _clientDataString;
+
+- (float)longitude {
+ return _location.longitude;
+}
+
+- (float)latitude {
+ return _location.latitude;
+}
+
+#pragma mark -
+
+- (void)generateClientDataString {
+ device_name = [self platformString];
+ NSMutableDictionary* clientDataObject = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
+ identifier, DEVICE_TAG_NAME,
+ model, DEVICE_TYPE_NAME,
+ device_name, DEVICE_NAME,
+ systemVersion, DEVICE_OS_VERSION_NAME,
+ bundleVersion, APP_VERSION_NAME,
+ LIBRARY_VERSION_NUMBER,LIBRARY_VERSION_NAME,
+ countryCode, DEVICE_COUNTRY_CODE,
+ language, DEVICE_LANGUAGE,
+ jailBroken, DEVICE_IS_JAILBORKEN,
+ nil];
+
+
+ if(_locationUpdatesStarted) {
+ [clientDataObject setValue:[NSNumber numberWithFloat:_location.latitude] forKey:LATITUDE];
+ [clientDataObject setValue:[NSNumber numberWithFloat:_location.longitude] forKey:LONGITUDE];
+ }
+
+ NetworkStatus newStatus = [[Reachability reachabilityForInternetConnection] currentReachabilityStatus];
+ switch (newStatus) {
+ case ReachableViaWWAN:
+ [clientDataObject setValue:@"m" forKey:NETWORK_AVAILABILITY]; // reachable via mobile network
+ break;
+ default:
+ [clientDataObject setValue:@"w" forKey:NETWORK_AVAILABILITY]; // reachable via wifi
+ break;
+ }
+
+
+
+ self.clientDataString = [clientDataObject yajl_JSONString];
+}
+
+#pragma mark - Location
+
+- (void)startLocationUpdates {
+ _locationUpdatesStarted = NO;
+ _location.longitude = 0.0;
+ _location.latitude = 0.0;
+
+ _locationManager = [[CLLocationManager alloc] init];
+
+ _locationManager.delegate = self;
+ _locationManager.desiredAccuracy = kCLLocationAccuracyKilometer;
+ _locationManager.distanceFilter = 500;
+ [_locationManager startUpdatingLocation];
+}
+
+- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
+ _locationUpdatesStarted = YES;
+ _location = newLocation.coordinate;
+ [self generateClientDataString];
+}
+
+#pragma mark - Reachability
+
+- (void)startReachabilityUpdates {
+ [Reachability reachabilityWithHostName:@"www.stackmob.com"];
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reachabilityChanged:) name:@"kReachabilityChangedNotification" object:nil];
+}
+
+- (void)reachabilityChanged:(NSNotification *)note {
+ [self generateClientDataString];
+}
+
+static const char* jailbreak_apps[] =
+{
+ "/Applications/Cydia.app",
+ "/Applications/limera1n.app",
+ "/Applications/greenpois0n.app",
+ "/Applications/blackra1n.app",
+ "/Applications/blacksn0w.app",
+ "/Applications/redsn0w.app",
+ NULL,
+};
+
+- (BOOL) isJailBroken
+{
+ NSBundle *bundle = [NSBundle mainBundle];
+ NSDictionary *info = [bundle infoDictionary];
+
+ // This key-value pair should not be in the pinfo file. If it is, we can be reasonably sure that the app has been compromised.
+ if ([info objectForKey: @"SignerIdentity"] != nil)
+ {
+ return YES;
+ }
+
+ // Now check for known jailbreak apps. If we encounter one, the device is jailbroken.
+ for (int i = 0; jailbreak_apps[i] != NULL; ++i)
+ {
+ if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithUTF8String:jailbreak_apps[i]]])
+ {
+ //NSLog(@"isjailbroken: %s", jailbreak_apps[i]);
+ return YES;
+ }
+ }
+
+ // TODO: Add more checks? This is an arms-race we're bound to lose.
+
+ return NO;
+}
+
+
+- (NSString*) isJailBrokenStr
+{
+ if ([self isJailBroken])
+ {
+ return @"42";
+ }
+
+ return @"0";
+}
+
+
+@end
Oops, something went wrong.

0 comments on commit baf9a0b

Please sign in to comment.