Changeset 4203
- Timestamp:
- Dec 18, 2007, 8:02:49 PM (14 years ago)
- Location:
- trunk/macosx
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/macosx/PortChecker.h
r3083 r4203 25 25 #import <Cocoa/Cocoa.h> 26 26 27 typedef enum { PORT_STATUS_OPEN, PORT_STATUS_STEALTH, PORT_STATUS_CLOSED, PORT_STATUS_ERROR } port_status_t; 27 typedef enum 28 { 29 PORT_STATUS_OPEN, 30 PORT_STATUS_CLOSED, 31 PORT_STATUS_ERROR 32 } port_status_t; 28 33 29 34 @interface PortChecker : NSObject … … 31 36 id fDelegate; 32 37 port_status_t fStatus; 33 38 39 NSURLConnection * fConnection; 34 40 NSMutableData * fPortProbeData; 35 41 } … … 37 43 - (id) initWithDelegate: (id) delegate; 38 44 - (void) probePort: (int) portNumber; 45 - (void) endProbe; 46 39 47 - (void) callBackWithStatus: (port_status_t) status; 40 48 - (port_status_t) status; -
trunk/macosx/PortChecker.m
r3464 r4203 24 24 25 25 #import "PortChecker.h" 26 #import "NSApplicationAdditions.h" 26 27 27 28 @implementation PortChecker … … 37 38 } 38 39 40 - (void) dealloc 41 { 42 [fPortProbeData release]; 43 [fConnection release]; 44 [super dealloc]; 45 } 46 39 47 - (port_status_t) status 40 48 { … … 45 53 { 46 54 NSURLRequest * portProbeRequest = [NSURLRequest requestWithURL: [NSURL URLWithString: 47 [NSString stringWithFormat: @"https://www.grc.com/x/portprobe=%d", portNumber]] 48 cachePolicy: NSURLRequestReloadIgnoringCacheData timeoutInterval: 15.0]; 55 [NSString stringWithFormat: @"http://transmission.m0k.org/PortCheck.php?port=%d", portNumber]] cachePolicy: 56 [NSApp isOnLeopardOrBetter] ? NSURLRequestReloadIgnoringLocalAndRemoteCacheData : NSURLRequestReloadIgnoringCacheData 57 timeoutInterval: 15.0]; 49 58 50 if ([NSURLConnection connectionWithRequest: portProbeRequest delegate: self]) 59 60 if ((fConnection = [[NSURLConnection alloc] initWithRequest: portProbeRequest delegate: self])) 51 61 fPortProbeData = [[NSMutableData data] retain]; 52 62 else … … 55 65 [self callBackWithStatus: PORT_STATUS_ERROR]; 56 66 } 67 } 68 69 - (void) endProbe 70 { 71 [fConnection cancel]; 57 72 } 58 73 … … 81 96 NSLog(@"Unable to get port status: connection failed (%@)", [error localizedDescription]); 82 97 [self callBackWithStatus: PORT_STATUS_ERROR]; 83 [fPortProbeData release];84 98 } 85 99 86 100 - (void) connectionDidFinishLoading: (NSURLConnection *) connection 87 101 { 88 NSXMLDocument * shieldsUpProbe = [[NSXMLDocument alloc] initWithData: fPortProbeData 89 options: NSXMLDocumentTidyHTML error: nil]; 102 NSString * probeString = [[NSString alloc] initWithData: fPortProbeData encoding: NSASCIIStringEncoding]; 90 103 91 if (shieldsUpProbe) 92 { 93 NSArray * nodes = [shieldsUpProbe nodesForXPath: @"/html/body/center/table[3]/tr/td[2]" error: nil]; 94 if ([nodes count] != 1) 95 { 96 NSArray * title = [shieldsUpProbe nodesForXPath: @"/html/head/title" error: nil]; 97 // This may happen when we probe twice too quickly 98 if ([title count] != 1 || ![[[title objectAtIndex: 0] stringValue] isEqualToString: 99 @"NanoProbe System Already In Use"]) 100 { 101 NSLog(@"Unable to get port status: invalid (outdated) XPath expression"); 102 [[shieldsUpProbe XMLData] writeToFile: @"/tmp/shieldsUpProbe.html" atomically: YES]; 103 [self callBackWithStatus: PORT_STATUS_ERROR]; 104 } 105 } 106 else 107 { 108 NSString * portStatus = [[[[nodes objectAtIndex: 0] stringValue] stringByTrimmingCharactersInSet: 109 [[NSCharacterSet letterCharacterSet] invertedSet]] lowercaseString]; 110 111 if ([portStatus isEqualToString: @"open"]) 112 [self callBackWithStatus: PORT_STATUS_OPEN]; 113 else if ([portStatus isEqualToString: @"stealth"]) 114 [self callBackWithStatus: PORT_STATUS_STEALTH]; 115 else if ([portStatus isEqualToString: @"closed"]) 116 [self callBackWithStatus: PORT_STATUS_CLOSED]; 117 else 118 { 119 NSLog(@"Unable to get port status: unknown port state"); 120 [self callBackWithStatus: PORT_STATUS_ERROR]; 121 } 122 } 123 [shieldsUpProbe release]; 124 } 104 port_status_t status; 105 if ([probeString isEqualToString: @"0"]) 106 status = PORT_STATUS_OPEN; 107 else if ([probeString isEqualToString: @"1"]) 108 status = PORT_STATUS_CLOSED; 125 109 else 126 { 127 NSLog(@"Unable to get port status: failed to create xml document"); 128 [self callBackWithStatus: PORT_STATUS_ERROR]; 129 } 130 131 [fPortProbeData release]; 110 status = PORT_STATUS_ERROR; 111 112 [self callBackWithStatus: status]; 113 114 [probeString release]; 132 115 } 133 116 -
trunk/macosx/PrefsController.h
r4076 r4203 47 47 IBOutlet NSTextField * fUploadField, * fDownloadField, 48 48 * fSpeedLimitUploadField, * fSpeedLimitDownloadField; 49 49 50 PortChecker * fPortChecker; 50 51 IBOutlet NSTextField * fPortField, * fPortStatusField; 51 52 IBOutlet NSButton * fNatCheck; -
trunk/macosx/PrefsController.m
r4080 r4203 229 229 - (void) updatePortStatus 230 230 { 231 #warning look into 231 232 tr_handle_status * stat = tr_handleStatus(fHandle); 232 233 if (fNatStatus != stat->natTraversalStatus || fPublicPort != stat->publicPort) … … 240 241 [fPortStatusProgress startAnimation: self]; 241 242 242 PortChecker * portChecker = [[PortChecker alloc] initWithDelegate: self]; 243 [portChecker probePort: fPublicPort]; 243 if (fPortChecker) 244 { 245 [fPortChecker endProbe]; 246 [fPortChecker release]; 247 } 248 fPortChecker = [[PortChecker alloc] initWithDelegate: self]; 249 [fPortChecker probePort: fPublicPort]; 244 250 } 245 251 } … … 253 259 [fPortStatusField setStringValue: NSLocalizedString(@"Port is open", "Preferences -> Advanced -> port status")]; 254 260 [fPortStatusImage setImage: [NSImage imageNamed: @"GreenDot.png"]]; 255 break;256 case PORT_STATUS_STEALTH:257 [fPortStatusField setStringValue: NSLocalizedString(@"Port is stealth", "Preferences -> Advanced -> port status")];258 [fPortStatusImage setImage: [NSImage imageNamed: @"RedDot.png"]];259 261 break; 260 262 case PORT_STATUS_CLOSED: … … 268 270 break; 269 271 } 270 [portChecker release]; 272 [fPortChecker release]; 273 fPortChecker = nil; 271 274 } 272 275
Note: See TracChangeset
for help on using the changeset viewer.