-
Notifications
You must be signed in to change notification settings - Fork 87
/
SocksProxyController.mm
802 lines (631 loc) · 22.4 KB
/
SocksProxyController.mm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
//
// SOCKS - SOCKS Proxy for iPhone
// Copyright (C) 2009 Ehud Ben-Reuven
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation version 2.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,USA.
//
// Enhanced by Daniel Sachse on 10/30/10.
// Copyright 2010 coffeecoding. All rights reserved.
//
#import "SocksProxyController.h"
#import "AppDelegate.h"
#import "UIDevice_Extended.h"
#import "MOGlassButton.h"
#import <AVFoundation/AVFoundation.h>
#include <CFNetwork/CFNetwork.h>
#include <SafariServices/SafariServices.h>
#include <sys/socket.h>
#include <unistd.h>
#include <netinet/in.h>
@interface SocksProxyController () <SFSafariViewControllerDelegate>
// Properties that don't need to be seen by the outside world.
@property (nonatomic, readonly) BOOL isSocksProxyStarted;
@property (nonatomic, strong) NSNetService * netService;
@property (nonatomic, assign) CFSocketRef listeningSocket;
@property (nonatomic, assign) NSInteger nConnections;
@property (nonatomic, strong) NSMutableArray* sendreceiveStream;
@property (nonatomic, strong) AVPlayer* bgPlayer;
// Forward declarations
- (void)_stopSocksProxyServer:(NSString *)reason;
@end
/*!
* Specifies the sections of the table
*/
typedef enum {
SocksProxyTableSectionGeneral,
SocksProxyTableSectionConnections,
SocksProxyTableSectionCount
} SocksProxyTableSection;
/*!
* Specifies the rows of the table sections
*/
typedef enum {
SocksProxyTableRowAddress,
SocksProxyTableRowPort,
SocksProxyTableHttpAutoProxyUrl,
// connections section
SocksProxyTableRowConnections = 0,
SocksProxyTableRowConnectionsOpen,
SocksProxyTableRowUpload,
SocksProxyTableRowDownload,
SocksProxyTableRowStatus
} SocksProxyTableRow;
@implementation SocksProxyController
@synthesize nConnections = _nConnections;
// Because sendreceiveStream is declared as an array, you have to use a custom getter.
// A synthesised getter doesn't compile.
@synthesize bgPlayer;
- (NSMutableArray*)sendreceiveStream
{
if(_sendreceiveStream == nil)
_sendreceiveStream = [[NSMutableArray alloc]init];
return _sendreceiveStream;
}
#pragma mark - Status management
// These methods are used by the core transfer code to update the UI.
- (void)_sockProxyServerDidStartOnPort:(int)port
{
assert( (port > 0) && (port < 65536) );
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
// Enable proximity sensor (public as of 3.0)
[UIDevice currentDevice].proximityMonitoringEnabled = YES;
// Enable backgrounding
// Set AVAudioSession
NSError *sessionError = nil;
#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 60000
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback withOptions:AVAudioSessionCategoryOptionMixWithOthers error:&sessionError];
#else
NSLog(@"Warning: iOS 6 is required for background audio hiding.");
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:&sessionError];
#endif
AVPlayerItem *item = [AVPlayerItem playerItemWithURL:[[NSBundle mainBundle] URLForResource:@"silence" withExtension:@"mp3"]];
[self setBgPlayer:[[AVPlayer alloc] initWithPlayerItem:item]];
[[self bgPlayer] setActionAtItemEnd:AVPlayerActionAtItemEndNone];
[[self bgPlayer] play];
self.currentAddress = [UIDevice localWiFiIPAddress];
self.currentPort = port;
self.currentStatusText = NSLocalizedString(@"Started", nil);
[self.startOrStopButton setTitle:NSLocalizedString(@"Stop", nil)
forState:UIControlStateNormal];
[self.startOrStopButton setupAsRedButton];
[self refreshProxyTable];
LOG_NETWORK_SOCKS(NSLOGGER_LEVEL_INFO, @"Server Started");
}
- (void)_serverDidStopWithReason:(NSString *)reason
{
if (reason == nil) {
reason = NSLocalizedString(@"Stopped", nil);
}
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
// Enable device sleep mode
[UIApplication sharedApplication].idleTimerDisabled = NO;
// Disable proximity sensor (public as of 3.0)
[UIDevice currentDevice].proximityMonitoringEnabled = NO;
// Disable backgrounding
[self setBgPlayer:nil];
self.currentAddress = @"";
self.httpAutoProxyURL = @"";
self.currentPort = 0;
self.currentStatusText = reason;
[self.startOrStopButton setTitle:NSLocalizedString(@"Start" , nil)
forState:UIControlStateNormal];
[self.startOrStopButton setupAsGreenButton];
[self refreshProxyTable];
LOG_NETWORK_SOCKS(NSLOGGER_LEVEL_INFO, @"Server Stopped: %@", reason);
}
- (NSInteger)countOpen
{
int countOpen = 0;
for(SocksProxy* asocksProxy in self.sendreceiveStream)
{
if ( ! [asocksProxy isSendingReceiving])
++countOpen;
}
return countOpen;
}
- (void)_sendreceiveDidStart
{
self.currentStatusText = NSLocalizedString(@"Receiving", nil);
NSInteger countOpen = [self countOpen];
self.currentOpenConnections = countOpen;
[self refreshProxyTable];
}
- (void)_updateStatus:(NSString *)statusString
{
assert(statusString != nil);
self.currentStatusText = statusString;
LOG_NETWORK_SOCKS(NSLOGGER_LEVEL_DEBUG, @"Status: %@", statusString);
}
- (void)_sendreceiveDidStopWithStatus:(NSString *)statusString
{
if (statusString == nil) {
statusString = NSLocalizedString(@"Receive succeeded", nil);
}
self.currentStatusText = statusString;
NSInteger countOpen = [self countOpen];
self.currentOpenConnections = countOpen;
[self refreshProxyTable];
LOG_NETWORK_SOCKS(NSLOGGER_LEVEL_INFO, @"Connection ended %ld %ld: %@", (long)countOpen, (long)self.nConnections, statusString);
}
- (void)_downloadData:(NSInteger)bytes
{
self.downloadData += bytes/1024;
[self refreshProxyTable];
}
- (void)_uploadData:(NSInteger)bytes
{
self.uploadData += bytes/1024;
[self refreshProxyTable];
}
#pragma mark - Core transfer code
// This is the code that actually does the networking.
@synthesize netService = _netService;
@synthesize listeningSocket = _listeningSocket;
- (BOOL)isSocksProxyStarted
{
return (self.netService != nil);
}
// Have to write our own setter for listeningSocket because CF gets grumpy
// if you message NULL.
- (void)setListeningSocket:(CFSocketRef)newValue
{
if (newValue != self->_listeningSocket) {
if (self->_listeningSocket != NULL) {
CFRelease(self->_listeningSocket);
}
self->_listeningSocket = newValue;
if (self->_listeningSocket != NULL) {
CFRetain(self->_listeningSocket);
}
}
}
- (void)_acceptConnection:(int)fd
{
SocksProxy *proxy = nil;
BOOL isFoundFreeProxy = NO;
int totalNumProxy = 0;
for(proxy in self.sendreceiveStream)
{
if(![proxy isSendingReceiving])
{
isFoundFreeProxy = YES;
break;
}
totalNumProxy++;
}
if(!isFoundFreeProxy) {
if(totalNumProxy>MAX_CONNECTIONS) {
LOG_NETWORK_SOCKS(NSLOGGER_LEVEL_WARNNING, @"Reach maximum number of concurrent SOCKS connectionss.");
close(fd);
return;
}
proxy = [SocksProxy new];
proxy.delegate = self;
[self.sendreceiveStream addObject:proxy];
++self.nConnections;
self.currentConnectionCount = self.nConnections;
}
//recount open connection
int countOpen = 0;
for (SocksProxy* asocksProxy in self.sendreceiveStream)
{
if (![asocksProxy isSendingReceiving])
++countOpen;
}
LOG_NETWORK_SOCKS(NSLOGGER_LEVEL_INFO, @"Accept connection %d %ld", countOpen, (long)self.nConnections);
if (![proxy startSendReceive:fd])
close(fd);
[self refreshProxyTable];
}
static void AcceptCallback(CFSocketRef s, CFSocketCallBackType type, CFDataRef address, const void *data, void *info)
// Called by CFSocket when someone connects to our listening socket.
// This implementation just bounces the request up to Objective-C.
{
SocksProxyController * obj;
#pragma unused(type)
assert(type == kCFSocketAcceptCallBack);
#pragma unused(address)
// assert(address == NULL);
assert(data != NULL);
obj = (__bridge SocksProxyController *) info;
assert(obj != nil);
#pragma unused(s)
assert(s == obj->_listeningSocket);
[obj _acceptConnection:*(int *)data];
}
- (void)netService:(NSNetService *)sender didNotPublish:(NSDictionary *)errorDict
// A NSNetService delegate callback that's called if our Bonjour registration
// fails.
//
// We only show the error in the status bar and output to the log.
{
#pragma unused(sender)
assert(sender == self.netService);
NSString *msg = [NSString stringWithFormat:@"sock Bonjour registration failed: error code %@",
errorDict[NSNetServicesErrorCode]];
[self _updateStatus:msg];
LOG_NETWORK_HTTP(NSLOGGER_LEVEL_ERROR, @"%@", msg);
}
- (void)_startServers
{
//start socks proxy server
[self _startSocksProxyServer];
//start DNS server
_DNSServer = DNSServer::getInstance();
const char * ipv4Addr = [currentAddress cStringUsingEncoding:NSASCIIStringEncoding];
_DNSServer->startDNSServer(0, ipv4Addr);
//start HTTP server that advertise socks.pac
_HTTPServer = [HTTPServer sharedHTTPServerWithSocksProxyPort:currentPort];
HTTPServerState currentHTTPServerState = [_HTTPServer state] ;
if (currentHTTPServerState == SERVER_STATE_IDLE ||
currentHTTPServerState == SERVER_STATE_STOPPING)
[_HTTPServer start];
if ([_HTTPServer state] == SERVER_STATE_RUNNING &&
_DNSServer->getDNSServerState() == DNS_SERVER_STARTED &&
self.isSocksProxyStarted)
[self _serversDidStart];
}
- (void)_stopServers:(NSString *)reason
{
[self _stopSocksProxyServer:reason];
_DNSServer = DNSServer::getInstance();
_DNSServer->stopDNSServer();
_HTTPServer = [HTTPServer sharedHTTPServerWithSocksProxyPort:currentPort];
[_HTTPServer stop];
}
- (void)_serversDidStart
{
self.httpAutoProxyURL = [_HTTPServer getAutomaticHttpProxyUrl];
}
- (void)_startSocksProxyServer
{
BOOL success;
int err;
int fd;
int junk;
struct sockaddr_in addr;
int port;
const int on = 1;
self.nConnections = 0;
// Create a listening socket and use CFSocket to integrate it into our
// runloop. We bind to port 0, which causes the kernel to give us
// any free port, then use getsockname to find out what port number we
// actually got.
port = 0;
fd = socket(AF_INET, SOCK_STREAM, 0);
success = (fd != -1);
if (success) {
// set scoket to reuse port and ignore TIME_WAIT state
setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
memset(&addr, 0, sizeof(addr));
addr.sin_len = sizeof(addr);
addr.sin_family = AF_INET;
addr.sin_addr.s_addr = INADDR_ANY;
int iport;
int ports[] = {1080,3128,-1};
for (iport = 0 ; ports[iport] >= 0 ; ++iport) {
port=ports[iport];
addr.sin_port = htons(port);
err = bind(fd, (const struct sockaddr *) &addr, sizeof(addr));
success = (err == 0);
if (success)
break;
else{
LOG_NETWORK_SOCKS(NSLOGGER_LEVEL_ERROR, @"Socks Server failed to bind port (%d), errono (%d)", port, errno);
}
}
}
if (success) {
err = listen(fd, 5);
success = (err == 0);
}else{
LOG_NETWORK_SOCKS(NSLOGGER_LEVEL_ERROR, @"Socks Server failed to bind to address, errno(%d)", errno);
}
if (success) {
socklen_t addrLen;
addrLen = sizeof(addr);
err = getsockname(fd, (struct sockaddr *) &addr, &addrLen);
success = (err == 0);
if (success) {
assert(addrLen == sizeof(addr));
port = ntohs(addr.sin_port);
}
}else{
LOG_NETWORK_SOCKS(NSLOGGER_LEVEL_ERROR, @"Socks Server failed to listen, errno(%d)", errno);
}
if (success) {
CFSocketContext context = { 0, (__bridge void*)self, NULL, NULL, NULL };
self.listeningSocket = CFSocketCreateWithNative(
NULL,
fd,
kCFSocketAcceptCallBack,
AcceptCallback,
&context
);
success = (self.listeningSocket != NULL);
if (success) {
CFRunLoopSourceRef rls;
CFRelease(self.listeningSocket); // to balance the create
fd = -1; // listeningSocket is now responsible for closing fd
rls = CFSocketCreateRunLoopSource(NULL, self.listeningSocket, 0);
assert(rls != NULL);
CFRunLoopAddSource(CFRunLoopGetCurrent(), rls, kCFRunLoopDefaultMode);
CFRelease(rls);
}
}
// Now register our service with Bonjour. See the comments in -netService:didNotPublish:
// for more info about this simplifying assumption.
if (success) {
self.netService = [[NSNetService alloc] initWithDomain:@"local"
type:@"_socks._tcp."
name:@""
port:port];
success = (self.netService != nil);
}
if (success) {
self.netService.delegate = self;
[self.netService publishWithOptions:NSNetServiceNoAutoRename];
// continues in -netServiceDidPublish: or -netService:didNotPublish: ...
}
// Clean up after failure.
if ( success ) {
assert(port != 0);
[self _sockProxyServerDidStartOnPort:port];
} else {
[self _stopServers:@"Start failed"];
if (fd != -1) {
junk = close(fd);
assert(junk == 0);
}
}
}
- (void)_stopSocksProxyServer:(NSString *)reason
{
for (SocksProxy* asocksProxy in self.sendreceiveStream)
{
if ([asocksProxy isSendingReceiving])
[asocksProxy stopSendReceiveWithStatus:@"Cancelled"];
}
[self.sendreceiveStream removeAllObjects];
if (self.netService != nil) {
[self.netService stop];
self.netService = nil;
}
if (self.listeningSocket != NULL) {
CFSocketInvalidate(self.listeningSocket);
self.listeningSocket = NULL;
}
[self _serverDidStopWithReason:reason];
}
#pragma mark - Actions
- (IBAction)startOrStopAction:(id)sender
{
#pragma unused(sender)
if (self.isSocksProxyStarted) {
[self _stopServers:nil];
} else {
if(self.currentAddress == nil)
self.currentAddress = [UIDevice localWiFiIPAddress];
if(currentAddress != nil){
[self _startServers];
}else{
[self _updateStatus:@"Please connect to wifi."];
LOG_NETWORK_SOCKS(NSLOGGER_LEVEL_WARNNING, @"No local IP can be retrieved. iPhone may not connect to wifi network\n");
}
}
[self refreshProxyTable];
}
#pragma mark - View controller boilerplate
@synthesize currentPort;
@synthesize currentAddress;
@synthesize httpAutoProxyURL;
@synthesize currentOpenConnections;
@synthesize currentConnectionCount;
@synthesize downloadData, uploadData;
@synthesize currentStatusText;// = _statusLabel;
@synthesize startOrStopButton = _startOrStopButton;
- (void)refreshProxyTable
{
[proxyTableView reloadData];
}
- (void)applicationDidEnterForeground:(NSNotification *)n
{
LOG_NETWORK_SOCKS(NSLOGGER_LEVEL_DEBUG, @"refreshing ip address");
// refresh the IP address, just in case
self.currentAddress = [UIDevice localWiFiIPAddress];
[self refreshProxyTable];
}
- (void)viewDidLoad
{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(applicationDidEnterForeground:)
name:UIApplicationWillEnterForegroundNotification
object:nil];
assert(self.startOrStopButton != nil);
self.currentStatusText = NSLocalizedString(@"Tap Start to start the server", nil);
[self.startOrStopButton setupAsGreenButton];
self.view.backgroundColor = [UIColor groupTableViewBackgroundColor];
self.title = @"Tethering";
// Add info button
UIButton *infoLightButton = [UIButton buttonWithType:UIButtonTypeInfoDark];
infoLightButton.tintColor = [UIColor whiteColor];
[infoLightButton addTarget:self action:@selector(showInfo) forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:infoLightButton];
}
- (void)viewDidUnload
{
[super viewDidUnload];
self.startOrStopButton = nil;
}
- (void)dealloc
{
[self _stopServers:nil];
}
- (UIStatusBarStyle)preferredStatusBarStyle {
return UIStatusBarStyleLightContent;
}
#pragma mark - Custom Methods
- (void)showInfo {
NSString *URLString = @"https://github.com/rickyzhang82/tethering/wiki";
if ([SFSafariViewController class] != nil) {
// Use SFSafariViewController
SFSafariViewController *sfvc = [[SFSafariViewController alloc] initWithURL:[NSURL URLWithString:URLString]];
sfvc.delegate = self;
sfvc.view.tintColor = [UIColor colorWithRed:0.082 green:0.492 blue:0.980 alpha:1.0];
[self presentViewController:sfvc animated:YES completion:nil];
} else {
// Open in Mobile Safari
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:URLString]
options:@{}
completionHandler:nil];
}
}
#pragma mark - SFSafariViewController delegate methods
-(void)safariViewController:(SFSafariViewController *)controller didCompleteInitialLoad:(BOOL)didLoadSuccessfully {
// Load finished
}
-(void)safariViewControllerDidFinish:(SFSafariViewController *)controller {
// Done button pressed
}
#pragma mark - Table View Data Source Methods
- (NSString *)tableView:(UITableView *)table titleForHeaderInSection:(NSInteger)section
{
#pragma unused(table)
/*
if (section == SocksProxyTableSectionConnections)
return @"Connections";
*/
return nil;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)table
{
#pragma unused(table)
return SocksProxyTableSectionCount;
}
- (NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section
{
#pragma unused(table)
switch (section)
{
case SocksProxyTableSectionGeneral:
return 3;
case SocksProxyTableSectionConnections:
return 5;
}
return 0;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//cell.selected = NO;
[tableView deselectRowAtIndexPath:indexPath animated:NO];
}
- (UITableViewCell *)tableView:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
#pragma unused(table)
static NSString * cellId = @"cellid";
UITableViewCellStyle cellStyle = UITableViewCellStyleValue2;
if (indexPath.section == SocksProxyTableSectionGeneral)
{
cellStyle = UITableViewCellStyleSubtitle;
}
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:cellStyle
reuseIdentifier:cellId];
cell.accessoryType = UITableViewCellAccessoryNone;
cell.accessoryView = nil;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
if (indexPath.section == SocksProxyTableSectionGeneral)
{
cell.textLabel.textColor = [UIColor colorWithRed:0.082 green:0.492 blue:0.980 alpha:1.0];
}
NSString *text = nil; // the caption
NSString *detailText = nil;
switch (indexPath.section)
{
case (SocksProxyTableSectionGeneral):
switch (indexPath.row)
{
case (SocksProxyTableRowAddress):
{
text = @"socks address";
detailText = self.currentAddress;
if (self.currentAddress.length == 0)
detailText = @"n/a";
}
break;
case (SocksProxyTableRowPort):
{
text = @"socks port";
if (self.currentPort)
detailText = [@(self.currentPort) stringValue];
else
detailText = @"n/a";
}
break;
case (SocksProxyTableHttpAutoProxyUrl):
{
text = @"automatic proxy";
detailText = self.httpAutoProxyURL;
if (self.httpAutoProxyURL.length == 0)
detailText = @"n/a";
}
break;
}
break;
case (SocksProxyTableSectionConnections):
switch (indexPath.row)
{
case (SocksProxyTableRowConnectionsOpen):
{
text = @"open";
detailText = [@(self.currentOpenConnections) stringValue];
}
break;
case (SocksProxyTableRowConnections):
{
text = @"count";
detailText = [@(self.currentConnectionCount) stringValue];
}
break;
case (SocksProxyTableRowDownload):
{
text = @"down";
detailText = [@(self.downloadData) stringValue];
}
break;
case (SocksProxyTableRowUpload):
{
text = @"up";
detailText = [@(self.uploadData) stringValue];
}
break;
case (SocksProxyTableRowStatus):
{
text = @"status";
detailText = self.currentStatusText;
cell.detailTextLabel.numberOfLines = 0;
cell.detailTextLabel.lineBreakMode = NSLineBreakByCharWrapping;
}
break;
}
break;
}
// set the field label title
cell.textLabel.text = text;
// set the cell text
cell.detailTextLabel.text = detailText;
return cell;
}
@end