Skip to content

Commit

Permalink
Refactor code to enable ARC.
Browse files Browse the repository at this point in the history
  • Loading branch information
rickyzhang82 committed Nov 16, 2013
1 parent a8fbcf3 commit 583f529
Show file tree
Hide file tree
Showing 15 changed files with 71 additions and 101 deletions.
6 changes: 3 additions & 3 deletions AncillaryCode/AppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@
BOOL _warningTimeAlertShown;
}

@property (nonatomic, retain) IBOutlet UIWindow * window;
@property (nonatomic, retain) IBOutlet UITabBarController * tabs;
@property (nonatomic, retain) IBOutlet SocksProxyController * viewController;
@property (nonatomic, strong) IBOutlet UIWindow * window;
@property (nonatomic, strong) IBOutlet UITabBarController * tabs;
@property (nonatomic, strong) IBOutlet SocksProxyController * viewController;


+ (AppDelegate *)sharedAppDelegate;
Expand Down
2 changes: 0 additions & 2 deletions AncillaryCode/AppDelegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ - (void)checkBackgroundTimeRemaining:(NSTimer *)timer
badge = [UILocalNotification new];
[badge setApplicationIconBadgeNumber:(int)timeLeft/60];
[[UIApplication sharedApplication] presentLocalNotificationNow:badge];
[badge release];
if (timeLeft < MINS(1))
{
[UIApplication sharedApplication].applicationIconBadgeNumber = 0;
Expand Down Expand Up @@ -186,7 +185,6 @@ - (void)checkBackgroundTimeRemaining:(NSTimer *)timer

// show the alert immediately
[[UIApplication sharedApplication] presentLocalNotificationNow:notif];
[notif release];
}
}
@end
2 changes: 1 addition & 1 deletion AncillaryCode/InfoController.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,6 @@
UIWebView * _webView;
}

@property (nonatomic, retain) IBOutlet UIWebView * webView;
@property (nonatomic, strong) IBOutlet UIWebView * webView;

@end
6 changes: 0 additions & 6 deletions AncillaryCode/InfoController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ - (void)viewDidLoad
target:self
action:@selector(doneButtonPressed:)];
self.navigationItem.rightBarButtonItem = doneButton;
[doneButton release];

[self _loadInfoContent];
}
Expand All @@ -117,10 +116,5 @@ - (void)viewDidUnload
self.webView = nil;
}

- (void)dealloc
{
[self->_webView release];
[super dealloc];
}

@end
6 changes: 0 additions & 6 deletions AncillaryCode/main.mm
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,8 @@ INCIDENTAL OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
int main(int argc, char **argv)
{
int retVal;
NSAutoreleasePool * pool;

pool = [[NSAutoreleasePool alloc] init];
assert(pool != nil);

retVal = UIApplicationMain(argc, argv, nil, nil);

[pool drain];

return retVal;
}
6 changes: 3 additions & 3 deletions MOButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
UIColor* disabledBackgroundColor;
}

@property(nonatomic,retain) UIColor* normalBackgroundColor;
@property(nonatomic,retain) UIColor* highlightedBackgroundColor;
@property(nonatomic,retain) UIColor* disabledBackgroundColor;
@property(nonatomic,strong) UIColor* normalBackgroundColor;
@property(nonatomic,strong) UIColor* highlightedBackgroundColor;
@property(nonatomic,strong) UIColor* disabledBackgroundColor;

- (void)setBackgroundColor:(UIColor*)aColor forState:(UIControlState)aState;

Expand Down
7 changes: 0 additions & 7 deletions MOButton.mm
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,6 @@ - (void)awakeFromNib {
}


- (void)dealloc {
self.normalBackgroundColor = nil;
self.highlightedBackgroundColor = nil;
self.disabledBackgroundColor = nil;

[super dealloc];
}


- (void)setBackgroundColor:(UIColor*)aColor forState:(UIControlState)aState {
Expand Down
6 changes: 3 additions & 3 deletions MOGlassButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
CALayer* outlineLayer;
}

@property(nonatomic,retain) CAGradientLayer* gradientLayer1;
@property(nonatomic,retain) CAGradientLayer* gradientLayer2;
@property(nonatomic,retain) CALayer* outlineLayer;
@property(nonatomic,strong) CAGradientLayer* gradientLayer1;
@property(nonatomic,strong) CAGradientLayer* gradientLayer2;
@property(nonatomic,strong) CALayer* outlineLayer;

- (void)setupAsGreenButton;
- (void)setupAsRedButton;
Expand Down
13 changes: 3 additions & 10 deletions MOGlassButton.mm
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ - (void)setupLayers {
self.layer.borderColor = [[UIColor colorFromRGBIntegers:100 green:103 blue:107 alpha:1.0f] CGColor];
self.layer.borderWidth = 1.0f;

self.gradientLayer1 = [[[CAGradientLayer alloc] init] autorelease];
self.gradientLayer1 = [[CAGradientLayer alloc] init];
gradientLayer1.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height/2);
gradientLayer1.colors = [NSArray arrayWithObjects:(id)[[UIColor colorFromRGBIntegers:255 green:255 blue:255 alpha:0.45f] CGColor], (id)[[UIColor colorFromRGBIntegers:255 green:235 blue:255 alpha:0.1f] CGColor], nil];
[self.layer insertSublayer:gradientLayer1 atIndex:0];

self.gradientLayer2 = [[[CAGradientLayer alloc] init] autorelease];
self.gradientLayer2 = [[CAGradientLayer alloc] init];
gradientLayer2.frame = CGRectMake(0, self.frame.size.height/2, self.frame.size.width, self.frame.size.height/2);
gradientLayer2.colors = [NSArray arrayWithObjects:(id)[[UIColor colorFromRGBIntegers:205 green:205 blue:205 alpha:0.0f] CGColor], (id)[[UIColor colorFromRGBIntegers:235 green:215 blue:215 alpha:0.2f] CGColor], nil];

self.outlineLayer = [[[CALayer alloc] init] autorelease];
self.outlineLayer = [[CALayer alloc] init];
outlineLayer.frame = CGRectMake(0, 1, self.frame.size.width, self.frame.size.height);
outlineLayer.borderColor = [[UIColor colorFromRGBIntegers:255 green:255 blue:255 alpha:1.0f] CGColor];
outlineLayer.borderWidth = 1.0f;
Expand All @@ -58,13 +58,6 @@ - (void)awakeFromNib {
}


- (void)dealloc {
self.gradientLayer1 = nil;
self.gradientLayer2 = nil;
self.outlineLayer = nil;

[super dealloc];
}


- (void)layoutSubviews {
Expand Down
2 changes: 2 additions & 0 deletions SOCKS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@
1D6058940D05DD3E006BFB54 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_OBJC_ARC = YES;
"CODE_SIGN_ENTITLEMENTS[sdk=*]" = "";
CODE_SIGN_IDENTITY = "iPhone Developer: Chaowang Zhang (JQPDQJAGUB)";
GCC_PRECOMPILE_PREFIX_HEADER = YES;
Expand All @@ -319,6 +320,7 @@
1D6058950D05DD3E006BFB54 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_OBJC_ARC = YES;
CODE_SIGN_ENTITLEMENTS = entitlements.plist;
CODE_SIGN_IDENTITY = "iPhone Developer: Chaowang Zhang (JQPDQJAGUB)";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution";
Expand Down
4 changes: 2 additions & 2 deletions SocksProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ enum {
NSOutputStream * _sendnetworkStream;
NSOutputStream * _remoteSendNetworkStream;
NSInputStream * _remoteReceiveNetworkStream;
id <SocksProxyDelegate> delegate;
id <SocksProxyDelegate> __weak delegate;
uint8_t _sendbuffer[kSendBufferSize];
size_t _sendbufferOffset;
size_t _sendbufferLimit;
Expand All @@ -48,7 +48,7 @@ enum {
NSString * _remoteName;
}

@property (nonatomic, assign) id <SocksProxyDelegate> delegate;
@property (nonatomic, weak) id <SocksProxyDelegate> delegate;
@property (nonatomic, readonly) BOOL isSendingReceiving;

- (void)stopSendReceiveWithStatus:(NSString *)statusString;
Expand Down
25 changes: 10 additions & 15 deletions SocksProxy.mm
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,18 @@ - (void)socksProtocol;

// Properties that don't need to be seen by the outside world.

@property (nonatomic, retain) NSInputStream * receivenetworkStream;
@property (nonatomic, retain) NSOutputStream * sendnetworkStream;
@property (nonatomic, retain) NSOutputStream * remoteSendNetworkStream;
@property (nonatomic, retain) NSInputStream * remoteReceiveNetworkStream;
@property (nonatomic, strong) NSInputStream * receivenetworkStream;
@property (nonatomic, strong) NSOutputStream * sendnetworkStream;
@property (nonatomic, strong) NSOutputStream * remoteSendNetworkStream;
@property (nonatomic, strong) NSInputStream * remoteReceiveNetworkStream;
@property (nonatomic, readonly) uint8_t * sendbuffer;
@property (nonatomic, assign) size_t sendbufferOffset;
@property (nonatomic, assign) size_t sendbufferLimit;
@property (nonatomic, readonly) uint8_t * receivebuffer;
@property (nonatomic, assign) size_t receivebufferOffset;
@property (nonatomic, assign) size_t receivebufferLimit;
@property (nonatomic, assign) NSUInteger protocolLocation;
@property (nonatomic, retain) NSString * remoteName;
@property (nonatomic, strong) NSString * remoteName;

@end

Expand Down Expand Up @@ -106,12 +106,9 @@ - (BOOL)startSendReceive:(int)fd
if(writeStream == NULL)
return NO;

self.receivenetworkStream = (NSInputStream *) readStream;
self.sendnetworkStream = (NSOutputStream *) writeStream;
self.receivenetworkStream = (NSInputStream *) CFBridgingRelease(readStream);
self.sendnetworkStream = (NSOutputStream *) CFBridgingRelease(writeStream);

CFRelease(readStream);
CFRelease(writeStream);

[self.receivenetworkStream setProperty:(id)kCFBooleanTrue forKey:(NSString *)kCFStreamPropertyShouldCloseNativeSocket];
[self.sendnetworkStream setProperty:(id)kCFBooleanTrue forKey:(NSString *)kCFStreamPropertyShouldCloseNativeSocket];

Expand Down Expand Up @@ -405,7 +402,7 @@ - (void)socksProtocol
if (command == 1) {
CFHostRef host;
if(!rc){
host = CFHostCreateWithName(NULL,(CFStringRef)addr);
host = CFHostCreateWithName(NULL,(__bridge CFStringRef)addr);
if (host == NULL) {
rc=4; //host unreachable
}
Expand All @@ -420,14 +417,12 @@ - (void)socksProtocol
CFRelease(host);
}
if(!rc) {
self.remoteReceiveNetworkStream = (NSInputStream *)readStream;
CFRelease(readStream);
self.remoteReceiveNetworkStream = (NSInputStream *)CFBridgingRelease(readStream);
self.remoteReceiveNetworkStream.delegate = self;
[self.remoteReceiveNetworkStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[self.remoteReceiveNetworkStream open];

self.remoteSendNetworkStream = (NSOutputStream *)writeStream;
CFRelease(writeStream);
self.remoteSendNetworkStream = (NSOutputStream *)CFBridgingRelease(writeStream);
self.remoteSendNetworkStream.delegate = self;
[self.remoteSendNetworkStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[self.remoteSendNetworkStream open];
Expand Down
5 changes: 2 additions & 3 deletions SocksProxyController.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ enum {
CFSocketRef _listeningSocket;

NSInteger _nConnections;
SocksProxy * _sendreceiveStream[NCONNECTIONS];
IBOutlet UITableView * proxyTableView;

@private
Expand All @@ -66,8 +65,8 @@ enum {
@property (nonatomic, assign) NSInteger currentConnectionCount;
@property (nonatomic, assign) NSInteger uploadData;
@property (nonatomic, assign) NSInteger downloadData;
@property (nonatomic, retain) IBOutlet MOGlassButton * gettingStartedButton;
@property (nonatomic, retain) IBOutlet MOGlassButton * startOrStopButton;
@property (nonatomic, strong) IBOutlet MOGlassButton * gettingStartedButton;
@property (nonatomic, strong) IBOutlet MOGlassButton * startOrStopButton;

- (IBAction)startOrStopAction:(id)sender;
- (IBAction)showGettingStartedAction:(id)sender;
Expand Down
Loading

0 comments on commit 583f529

Please sign in to comment.