Permalink
Browse files

Fixed memory issues and disappearing auth cookie bug

  • Loading branch information...
Ryan Connelly
Ryan Connelly committed Dec 13, 2011
1 parent 498c379 commit 09acc05da5e29d44847b70442c187a7340178d7b
@@ -46,6 +46,8 @@
03DD8489142AE55E000F2318 /* StackMobSession.m in Sources */ = {isa = PBXBuildFile; fileRef = 03DD846D142AE55E000F2318 /* StackMobSession.m */; };
03DD848A142AE55E000F2318 /* NSData+Base64.m in Sources */ = {isa = PBXBuildFile; fileRef = 03DD8470142AE55E000F2318 /* NSData+Base64.m */; };
03DD848B142AE55E000F2318 /* NSData+JSON.m in Sources */ = {isa = PBXBuildFile; fileRef = 03DD8472142AE55E000F2318 /* NSData+JSON.m */; };
+ C63FB3751497FC8A007961C1 /* SMFile.m in Sources */ = {isa = PBXBuildFile; fileRef = C63FB3741497FC8A007961C1 /* SMFile.m */; };
+ C63FB3791497FCAA007961C1 /* StackMobBulkRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = C63FB3781497FCAA007961C1 /* StackMobBulkRequest.m */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
@@ -121,6 +123,10 @@
03DD8470142AE55E000F2318 /* NSData+Base64.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSData+Base64.m"; sourceTree = "<group>"; };
03DD8471142AE55E000F2318 /* NSData+JSON.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSData+JSON.h"; sourceTree = "<group>"; };
03DD8472142AE55E000F2318 /* NSData+JSON.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSData+JSON.m"; sourceTree = "<group>"; };
+ C63FB3731497FC8A007961C1 /* SMFile.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SMFile.h; path = ../SMFile.h; sourceTree = "<group>"; };
+ C63FB3741497FC8A007961C1 /* SMFile.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SMFile.m; path = ../SMFile.m; sourceTree = "<group>"; };
+ C63FB3771497FCAA007961C1 /* StackMobBulkRequest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StackMobBulkRequest.h; sourceTree = "<group>"; };
+ C63FB3781497FCAA007961C1 /* StackMobBulkRequest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = StackMobBulkRequest.m; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -215,6 +221,8 @@
03DD8467142AE55E000F2318 /* StackMobHerokuRequest.m */,
03DD8468142AE55E000F2318 /* StackMobPushRequest.h */,
03DD8469142AE55E000F2318 /* StackMobPushRequest.m */,
+ C63FB3771497FCAA007961C1 /* StackMobBulkRequest.h */,
+ C63FB3781497FCAA007961C1 /* StackMobBulkRequest.m */,
03DD846A142AE55E000F2318 /* StackMobRequest.h */,
03DD846B142AE55E000F2318 /* StackMobRequest.m */,
03DD846C142AE55E000F2318 /* StackMobSession.h */,
@@ -308,6 +316,8 @@
03DD846E142AE55E000F2318 /* Utils */ = {
isa = PBXGroup;
children = (
+ C63FB3731497FC8A007961C1 /* SMFile.h */,
+ C63FB3741497FC8A007961C1 /* SMFile.m */,
03DD846F142AE55E000F2318 /* NSData+Base64.h */,
03DD8470142AE55E000F2318 /* NSData+Base64.m */,
03DD8471142AE55E000F2318 /* NSData+JSON.h */,
@@ -409,6 +419,8 @@
03DD8489142AE55E000F2318 /* StackMobSession.m in Sources */,
03DD848A142AE55E000F2318 /* NSData+Base64.m in Sources */,
03DD848B142AE55E000F2318 /* NSData+JSON.m in Sources */,
+ C63FB3751497FC8A007961C1 /* SMFile.m in Sources */,
+ C63FB3791497FCAA007961C1 /* StackMobBulkRequest.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -0,0 +1,84 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Scheme
+ version = "1.3">
+ <BuildAction
+ parallelizeBuildables = "YES"
+ buildImplicitDependencies = "YES">
+ <BuildActionEntries>
+ <BuildActionEntry
+ buildForTesting = "YES"
+ buildForRunning = "YES"
+ buildForProfiling = "YES"
+ buildForArchiving = "YES"
+ buildForAnalyzing = "YES">
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "0393E2A61409D87B00D643AA"
+ BuildableName = "DemoApp.app"
+ BlueprintName = "DemoApp"
+ ReferencedContainer = "container:DemoApp.xcodeproj">
+ </BuildableReference>
+ </BuildActionEntry>
+ </BuildActionEntries>
+ </BuildAction>
+ <TestAction
+ selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.GDB"
+ selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.GDB"
+ shouldUseLaunchSchemeArgsEnv = "YES"
+ buildConfiguration = "Debug">
+ <Testables>
+ </Testables>
+ <MacroExpansion>
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "0393E2A61409D87B00D643AA"
+ BuildableName = "DemoApp.app"
+ BlueprintName = "DemoApp"
+ ReferencedContainer = "container:DemoApp.xcodeproj">
+ </BuildableReference>
+ </MacroExpansion>
+ </TestAction>
+ <LaunchAction
+ selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.GDB"
+ selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.GDB"
+ launchStyle = "0"
+ useCustomWorkingDirectory = "NO"
+ buildConfiguration = "Debug"
+ debugDocumentVersioning = "YES"
+ allowLocationSimulation = "YES">
+ <BuildableProductRunnable>
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "0393E2A61409D87B00D643AA"
+ BuildableName = "DemoApp.app"
+ BlueprintName = "DemoApp"
+ ReferencedContainer = "container:DemoApp.xcodeproj">
+ </BuildableReference>
+ </BuildableProductRunnable>
+ <AdditionalOptions>
+ </AdditionalOptions>
+ </LaunchAction>
+ <ProfileAction
+ shouldUseLaunchSchemeArgsEnv = "YES"
+ savedToolIdentifier = ""
+ useCustomWorkingDirectory = "NO"
+ buildConfiguration = "Release"
+ debugDocumentVersioning = "YES">
+ <BuildableProductRunnable>
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "0393E2A61409D87B00D643AA"
+ BuildableName = "DemoApp.app"
+ BlueprintName = "DemoApp"
+ ReferencedContainer = "container:DemoApp.xcodeproj">
+ </BuildableReference>
+ </BuildableProductRunnable>
+ </ProfileAction>
+ <AnalyzeAction
+ buildConfiguration = "Debug">
+ </AnalyzeAction>
+ <ArchiveAction
+ buildConfiguration = "Release"
+ revealArchiveInOrganizer = "YES">
+ </ArchiveAction>
+</Scheme>
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>SchemeUserState</key>
+ <dict>
+ <key>DemoApp.xcscheme</key>
+ <dict>
+ <key>orderHint</key>
+ <integer>0</integer>
+ </dict>
+ </dict>
+ <key>SuppressBuildableAutocreation</key>
+ <dict>
+ <key>0393E2A61409D87B00D643AA</key>
+ <dict>
+ <key>primary</key>
+ <true/>
+ </dict>
+ </dict>
+</dict>
+</plist>
@@ -31,14 +31,12 @@ @implementation NSMutableURLRequest (OAParameterAdditions)
- (NSArray *)parameters
{
NSString *encodedParameters;
- BOOL shouldfree = NO;
if ([[self HTTPMethod] isEqualToString:@"GET"] || [[self HTTPMethod] isEqualToString:@"DELETE"])
encodedParameters = [[self URL] query];
else{
// POST, PUT
- shouldfree = YES;
- encodedParameters = [[NSString alloc] initWithData:[self HTTPBody] encoding:NSASCIIStringEncoding];
+ encodedParameters = [[[NSString alloc] initWithData:[self HTTPBody] encoding:NSASCIIStringEncoding] autorelease];
}
if ((encodedParameters == nil) || ([encodedParameters isEqualToString:@""]))
@@ -53,10 +51,6 @@ - (NSArray *)parameters
value:[[encodedPairElements objectAtIndex:1] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
[requestParameters addObject:parameter];
}
-
- // Cleanup
- if (shouldfree)
- [encodedParameters release];
return [requestParameters autorelease];
}
@@ -193,7 +193,7 @@ - (void)_generateNonce
NSMakeCollectable(theUUID);
nonce = (NSString *)string;
[nonce retain];
- CFRelease(theUUID);
+ CFRelease(theUUID); // Ignore warning for now
}
- (NSString *)_signatureBaseString
View
@@ -13,7 +13,6 @@
@property (nonatomic, retain) NSString *name;
@property (nonatomic, retain) NSString *contentType;
@property (nonatomic, retain) NSData *data;
-@property (nonatomic, retain) NSString *encodingType;
- (id) initWithFileName:(NSString *)name_ data:(NSData *)data_ contentType:(NSString *)contentType_;
+ (id) fileWithName:(NSString *)name_ data:(NSData *)data_ contentType:(NSString *)contentType_;
View
@@ -13,16 +13,15 @@ @implementation SMFile
@synthesize data;
@synthesize name;
@synthesize contentType;
-@synthesize encodingType;
- (id) initWithFileName:(NSString *)name_ data:(NSData *)data_ contentType:(NSString *)contentType_
{
self = [super init];
if(self)
{
- data = [data_ retain];
- name = [name_ retain];
- contentType = [contentType_ retain];
+ data = [data_ retain];
+ name = [name_ retain];
+ contentType = [contentType_ retain];
}
return self;
}
@@ -39,9 +38,9 @@ - (id)JSON
Content-Disposition: attachment; filename=%@\n\
Content-Transfer-Encoding: %@\n\n\
%@",
- self.data,
- self.name,
self.contentType,
+ self.name,
+ @"base64",
[self.data base64EncodedString]];
}
@@ -51,5 +50,4 @@ - (void)dealloc {
[contentType release];
[super dealloc];
}
-//fileWithName:@"resume.txt" data:data]
@end
View
@@ -37,6 +37,7 @@ typedef void (^StackMobCallback)(BOOL success, id result);
@property (nonatomic, retain) StackMobSession *session;
@property (nonatomic, retain) NSMutableArray *callbacks;
@property (nonatomic, retain) NSMutableArray *requests;
+@property (nonatomic, retain) NSString *authCookie;
/*
View
@@ -36,6 +36,7 @@ @implementation StackMob
@synthesize requests;
@synthesize callbacks;
@synthesize session;
+@synthesize authCookie;
static StackMob *_sharedManager = nil;
static SMEnvironment environment;
@@ -45,13 +46,13 @@ + (StackMob *)setApplication:(NSString *)apiKey secret:(NSString *)apiSecret app
if (_sharedManager == nil) {
_sharedManager = [[super allocWithZone:NULL] init];
environment = SMEnvironmentProduction;
- _sharedManager.session = [[StackMobSession sessionForApplication:apiKey
+ _sharedManager.session = [StackMobSession sessionForApplication:apiKey
secret:apiSecret
appName:appName
subDomain:subDomain
domain:SMDefaultDomain
userObjectName:userObjectName
- apiVersionNumber:apiVersion] retain];
+ apiVersionNumber:apiVersion];
_sharedManager.requests = [NSMutableArray array];
_sharedManager.callbacks = [NSMutableArray array];
}
@@ -129,6 +130,7 @@ - (StackMobRequest *)loginWithArguments:(NSDictionary *)arguments andCallback:(S
withArguments:arguments
withHttpVerb:GET];
request.isSecure = YES;
+
[self queueRequest:request andCallback:callback];
return request;
@@ -140,6 +142,7 @@ - (StackMobRequest *)logoutWithCallback:(StackMobCallback)callback
withArguments:[NSDictionary dictionary]
withHttpVerb:GET];
request.isSecure = YES;
+ self.authCookie = nil;
[self queueRequest:request andCallback:callback];
return request;
@@ -556,6 +559,15 @@ - (NSDictionary *)loadInfo
#pragma mark - StackMobRequestDelegate
+- (void) setAuthCookieIfFound:(StackMobRequest *)request
+{
+ NSHTTPURLResponse *response = request.httpResponse;
+ NSDictionary *fields = [response allHeaderFields];
+ NSString *cookie = [fields valueForKey:@"Set-Cookie"];
+ if(cookie)
+ self.authCookie = cookie;
+}
+
- (void)requestCompleted:(StackMobRequest*)request {
if([self.requests containsObject:request]){
NSInteger idx = [self.requests indexOfObject:request];
@@ -564,6 +576,9 @@ - (void)requestCompleted:(StackMobRequest*)request {
if(callback != [NSNull null]){
StackMobCallback mCallback = (StackMobCallback)callback;
BOOL wasSuccessful = request.httpResponse.statusCode < 300 && request.httpResponse.statusCode > 199;
+
+ // hack for release
+ [self setAuthCookieIfFound:request];
mCallback(wasSuccessful, [request result]);
Block_release(mCallback);
}else{
@@ -20,10 +20,19 @@
#define StackMobDebug(format, ...) {NSLog([[NSString stringWithFormat:@"[%s, %@, %d] ", __PRETTY_FUNCTION__, [[NSString stringWithUTF8String:__FILE__] lastPathComponent], __LINE__] stringByAppendingFormat:format, ##__VA_ARGS__]);}
#endif
-#define STACKMOB_PUBLIC_KEY @"YOUR_PUBLIC_KEY"
-#define STACKMOB_PRIVATE_KEY @"YOUR_PRIVATE_KEY"
-#define STACKMOB_APP_NAME @"YOUR_APP_NAME"
-#define STACKMOB_APP_SUBDOMAIN @"YOUR_SUBDOMAIN"
+
+#define STACKMOB_PUBLIC_KEY @"201543b9-7b81-4934-a353-c22d979c891a"
+#define STACKMOB_PRIVATE_KEY @"7a099db4-e09a-4e71-8348-3fea8ef5164f"
+#define STACKMOB_APP_NAME @"DemoApp"
+#define STACKMOB_APP_SUBDOMAIN @"stackmob"
#define STACKMOB_APP_DOMAIN @"stackmob.com"
-#define STACKMOB_USER_OBJECT_NAME @"YOUR_USER_OBJECT_NAME"
+#define STACKMOB_USER_OBJECT_NAME @"user"
#define STACKMOB_API_VERSION 0
+
+/*
+NSString * const kAPIKey = @"201543b9-7b81-4934-a353-c22d979c891a";
+NSString * const kAPISecret = @"7a099db4-e09a-4e71-8348-3fea8ef5164f";
+NSString * const kSubDomain = @"stackmob";
+NSString * const kAppName = @"DemoApp";
+#define STACKMOB_USER_OBJECT_NAME @"user"
+NSInteger const kVersion = 0;*/
Oops, something went wrong.

0 comments on commit 09acc05

Please sign in to comment.