get ipc fully working with ipc

This commit is contained in:
Mitchell Livingston
2007-12-24 03:48:42 +00:00
parent 54f1ee06d4
commit 63e7a8597e
7 changed files with 67 additions and 10 deletions

View File

@@ -638,7 +638,9 @@ strmsg( enum ipc_msg id, benc_val_t * val, int64_t tag, void * arg )
switch( id )
{
case IPC_MSG_CRYPTO:
if(!strcasecmp(val->val.s.s, "preferred"))
if(!strcasecmp(val->val.s.s, "plaintext"))
torrent_set_encryption(TR_PLAINTEXT_PREFERRED);
else if(!strcasecmp(val->val.s.s, "preferred"))
torrent_set_encryption(TR_ENCRYPTION_PREFERRED);
else if(!strcasecmp(val->val.s.s, "required"))
torrent_set_encryption(TR_ENCRYPTION_REQUIRED);
@@ -930,6 +932,9 @@ prefmsg( enum ipc_msg id, benc_val_t * val UNUSED, int64_t tag, void * arg )
case IPC_MSG_GETCRYPTO:
switch(torrent_get_encryption())
{
case TR_PLAINTEXT_PREFERRED:
strval = "plaintext";
break;
case TR_ENCRYPTION_PREFERRED:
strval = "preferred";
break;

View File

@@ -198,7 +198,7 @@ Replies: "succeeded", "failed", "not-supported", "bad-format"
Example: 10:encryption8:required
"encryption", "required"
Details: Set the encryption mode for peer connections. Valid values
are "required" and "preferred".
are "required", "preferred" and "plaintext".
Key: "failed"
Version: 2

View File

@@ -207,8 +207,9 @@ void sleepCallBack(void * controller, io_service_t y, natural_t messageType, voi
fBadger = [[Badger alloc] initWithLib: fLib];
fIPCController = [[IPCController alloc] initWithHandle: fPrefsController];
fIPCController = [[IPCController alloc] init];
[fIPCController setDelegate: self];
[fIPCController setPrefsController: fPrefsController];
fRemoteQuit = NO;
[GrowlApplicationBridge setGrowlDelegate: self];
@@ -2490,7 +2491,6 @@ void sleepCallBack(void * controller, io_service_t y, natural_t messageType, voi
NSEnumerator * enumerator = [files objectEnumerator];
NSString * file;
BOOL torrent = NO;
int canAdd;
tr_ctor * ctor;
while ((file = [enumerator nextObject]))
{

View File

@@ -58,8 +58,10 @@
id _delegate;
}
- (id) initWithHandle: (PrefsController *) thePrefsController;
- (id) init;
- (id) delegate;
- (void) setDelegate: (id) newdelegate;
- (void) setPrefsController: (id) thePrefsController;
@end

View File

@@ -118,9 +118,8 @@ PrefsController * fPrefsController;
@implementation IPCController
- (id) initWithHandle : (PrefsController *) thePrefsController
- (id) init
{
fPrefsController = thePrefsController;
struct sockaddr_un sun;
self = [super init];
@@ -150,10 +149,12 @@ PrefsController * fPrefsController;
0 > ipc_addmsg( _funcs, IPC_MSG_ADDONEFILE, msg_addnew ) ||
0 > ipc_addmsg( _funcs, IPC_MSG_AUTOMAP, msg_setbool ) ||
0 > ipc_addmsg( _funcs, IPC_MSG_AUTOSTART, msg_setbool ) ||
0 > ipc_addmsg( _funcs, IPC_MSG_CRYPTO, msg_setstr ) ||
0 > ipc_addmsg( _funcs, IPC_MSG_DIR, msg_setstr ) ||
0 > ipc_addmsg( _funcs, IPC_MSG_DOWNLIMIT, msg_setint ) ||
0 > ipc_addmsg( _funcs, IPC_MSG_GETAUTOMAP, msg_getbool ) ||
0 > ipc_addmsg( _funcs, IPC_MSG_GETAUTOSTART, msg_getbool ) ||
0 > ipc_addmsg( _funcs, IPC_MSG_GETCRYPTO, msg_getstr ) ||
0 > ipc_addmsg( _funcs, IPC_MSG_GETDIR, msg_getstr ) ||
0 > ipc_addmsg( _funcs, IPC_MSG_GETDOWNLIMIT, msg_getint ) ||
0 > ipc_addmsg( _funcs, IPC_MSG_GETINFO, msg_info ) ||
@@ -216,6 +217,11 @@ PrefsController * fPrefsController;
_delegate = newdelegate;
}
- (void) setPrefsController: (id) thePrefsController
{
fPrefsController = thePrefsController;
}
@end
@implementation IPCController (Private)
@@ -786,7 +792,7 @@ void msg_getbool( enum ipc_msg msgid, benc_val_t * val, int64_t tag, void * arg
[client sendrespInt:IPC_MSG_AUTOSTART tag:tag val:[fDefaults boolForKey:@"AutoStartDownload"]];
break;
case IPC_MSG_GETPEX:
// we dont support this :(
//warning we dont support this :(
[client sendrespEmpty: IPC_MSG_FAIL tag: tag];
break;
default:
@@ -821,6 +827,7 @@ void msg_getint( enum ipc_msg msgid, benc_val_t * val, int64_t tag, void * arg )
void msg_getstr( enum ipc_msg msgid, benc_val_t * val, int64_t tag, void * arg )
{
IPCClient * client = arg;
NSString * cryptoValue;
fDefaults = [NSUserDefaults standardUserDefaults];
@@ -830,6 +837,19 @@ void msg_getstr( enum ipc_msg msgid, benc_val_t * val, int64_t tag, void * arg )
case IPC_MSG_GETDIR:
[client sendrespStr:IPC_MSG_DIR tag:tag val:[fDefaults stringForKey:@"DownloadFolder"]];
break;
case IPC_MSG_GETCRYPTO:
if ([fDefaults boolForKey: @"EncryptionPrefer"])
if ([fDefaults boolForKey: @"EncryptionRequire"])
cryptoValue = @"required";
else
cryptoValue = @"preferred";
else
cryptoValue = @"plaintext";
[client sendrespStr:IPC_MSG_CRYPTO tag:tag val:cryptoValue];
break;
default:
assert( 0 );
break;
@@ -860,7 +880,7 @@ void msg_setbool( enum ipc_msg msgid, benc_val_t * val, int64_t tag, void * arg
[client sendrespEmpty:IPC_MSG_OK tag:tag];
break;
case IPC_MSG_PEX:
//we dont support this :(
//warning we dont support this :(
[client sendrespEmpty: IPC_MSG_FAIL tag: tag];
break;
default:
@@ -889,8 +909,8 @@ void msg_setint( enum ipc_msg msgid, benc_val_t * val, int64_t tag, void * arg )
[fPrefsController applySpeedSettings: nil];
break;
case IPC_MSG_PORT:
#warning show in preference window
[fPrefsController setPort:[NSNumber numberWithInt:val->val.i]];
[fPrefsController updatePortField];
break;
case IPC_MSG_UPLIMIT:
[fDefaults setInteger:val->val.i forKey:@"UploadLimit"];
@@ -924,6 +944,29 @@ void msg_setstr( enum ipc_msg msgid, benc_val_t * val, int64_t tag, void * arg )
[fDefaults setObject: @"Constant" forKey: @"DownloadChoice"]; //not sure about this line
[client sendrespEmpty: IPC_MSG_OK tag: tag];
break;
case IPC_MSG_CRYPTO:
if(!strcasecmp(val->val.s.s, "required"))
{
[fDefaults setBool:TRUE forKey: @"EncryptionPrefer"];
[fDefaults setBool:TRUE forKey: @"EncryptionRequire"];
}
else if(!strcasecmp(val->val.s.s, "preferred"))
{
[fDefaults setBool:TRUE forKey: @"EncryptionPrefer"];
[fDefaults setBool:FALSE forKey: @"EncryptionRequire"];
}
else if(!strcasecmp(val->val.s.s, "plaintext"))
{
[fDefaults setBool:FALSE forKey: @"EncryptionPrefer"];
[fDefaults setBool:FALSE forKey: @"EncryptionRequire"];
}
[client sendrespEmpty: IPC_MSG_OK tag: tag];
break;
default:
assert( 0 );
break;

View File

@@ -61,6 +61,7 @@
- (id) initWithHandle: (tr_handle *) handle;
- (void) setUpdater: (SUUpdater *) updater;
- (void) updatePortField;
- (void) setPort: (id) sender;
- (void) setNat: (id) sender;
- (void) updatePortStatus;

View File

@@ -222,6 +222,12 @@
return [NSArray arrayWithObjects: TOOLBAR_GENERAL, TOOLBAR_TRANSFERS, TOOLBAR_BANDWIDTH, TOOLBAR_ADVANCED, nil];
}
//used by ipc
- (void) updatePortField
{
[fPortField setIntValue: [fDefaults integerForKey: @"BindPort"]];
}
- (void) setPort: (id) sender
{
int port = [sender intValue];