From f439be18a2fd3f876406685e3eb314531652fdba Mon Sep 17 00:00:00 2001 From: Michael Lamb Date: Thu, 28 Feb 2013 15:06:58 -0800 Subject: [PATCH] adium/purple: Better solution to auto-detect for Adium - This reverts commit 9cdb9648f82e300782760c904e1bf23b84fa9f01. ("purple: Single Sign-On default must be OFF") - Provides a more robust solution that stays inside the Adium Plugin codebase. --- src/adium/ESPurpleSIPEAccount.h | 1 + src/adium/ESPurpleSIPEAccount.m | 36 +++++++++++++-- src/adium/ESSIPEAccountViewController.h | 2 + src/adium/ESSIPEAccountViewController.m | 6 +++ src/adium/English.lproj/ESSIPEAccountView.xib | 54 +++++++--------------- src/adium/PurpleDefaultsSIPE.plist | 2 + .../SIPEAdiumPlugin.xcodeproj/project.pbxproj | 4 ++ src/purple/purple-plugin.c | 12 +---- 8 files changed, 65 insertions(+), 52 deletions(-) diff --git a/src/adium/ESPurpleSIPEAccount.h b/src/adium/ESPurpleSIPEAccount.h index 7573af9d..aaaf3055 100644 --- a/src/adium/ESPurpleSIPEAccount.h +++ b/src/adium/ESPurpleSIPEAccount.h @@ -10,6 +10,7 @@ #import #define KEY_SIPE_WINDOWS_LOGIN @"SIPE:Windows Login" +#define KEY_SIPE_CONNECT_HOST @"SIPE:Connect Host" #define KEY_SIPE_PASSWORD @"SIPE:Password" // TODO: Do we need to keep this key? PurpleAccount should store this for us #define KEY_SIPE_CONNECTION_TYPE @"SIPE:Connection Type" #define KEY_SIPE_EMAIL @"SIPE:Email" diff --git a/src/adium/ESPurpleSIPEAccount.m b/src/adium/ESPurpleSIPEAccount.m index bc1ee165..850133f4 100644 --- a/src/adium/ESPurpleSIPEAccount.m +++ b/src/adium/ESPurpleSIPEAccount.m @@ -24,13 +24,17 @@ return "prpl-sipe"; } + - (NSString *)hostForPurple { - if([self preferenceForKey:KEY_CONNECT_HOST]) + NSString *server = [self preferenceForKey:KEY_SIPE_CONNECT_HOST group:GROUP_ACCOUNT_STATUS]; + if (!server || [server length] == 0) { - return self.host; + // set the KEY_CONNECT_HOST to "autodetect" just to make sure we don't lose it from the defaults + [self setPreference:@"autodetect" forKey:KEY_CONNECT_HOST group:GROUP_ACCOUNT_STATUS]; + return @"autodetect"; } else { - return @"host_placeholder"; + return server; } } @@ -41,6 +45,32 @@ // Account preferences NSLog(@"Configuring account: %s\n", self.purpleAccountName); + + // !!! ------ HACK/Kludge alert! ------ + /* + * Adium's CBPurpleAccount class's implementation of configurePurpleAccount (called above) + * has the following line: + * + * if (hostName && [hostName length]) { + * + * Which doesn't allow us to leave the KEY_CONNECT_HOST preference empty (Adium prompts for the user to fill it out) + * sipe-core is expecting the server account setting to be empty to engage the auto-detection piece. The only way + * to fix this is to fake out Adium by storing the servername in a different key (KEY_SIPE_CONNECT_HOST) and setting a + * default KEY_CONNECT_HOST to something. We then need to detect that we have an empty servername here, and + * "overwrite" the default placeholder with an empty string. + */ + + // if there is no host specified, we're looking to auto-detect + // TODO: change this to a checkbox, and enable/disable based on that. Leaving a field blank is bad UI design. + NSString *server = [self preferenceForKey:KEY_SIPE_CONNECT_HOST group:GROUP_ACCOUNT_STATUS]; + + // if the server is empty, clear it in purple account (because the defaults hack for the superclass set it to "autodetect"). Otherwise, use the one provided + if([server isEqualToString:@""]) + { + purple_account_set_string(account,"server", ""); + } else { + // NOP. Superclass already set this via the [self hostForPurple] response. + } NSString *winLogin = [self preferenceForKey:KEY_SIPE_WINDOWS_LOGIN group:GROUP_ACCOUNT_STATUS]; NSString *completeUserName = [NSString stringWithUTF8String:[self purpleAccountName]]; diff --git a/src/adium/ESSIPEAccountViewController.h b/src/adium/ESSIPEAccountViewController.h index 6d990183..db1a1725 100644 --- a/src/adium/ESSIPEAccountViewController.h +++ b/src/adium/ESSIPEAccountViewController.h @@ -15,6 +15,8 @@ IBOutlet NSTextField *textField_windowsLogin; + IBOutlet NSTextField *textField_server; + IBOutlet NSTextField *textField_userAgent; IBOutlet NSTextField *textField_emailURL; IBOutlet NSTextField *textField_email; diff --git a/src/adium/ESSIPEAccountViewController.m b/src/adium/ESSIPEAccountViewController.m index ed63e70f..b9ce0823 100644 --- a/src/adium/ESSIPEAccountViewController.m +++ b/src/adium/ESSIPEAccountViewController.m @@ -26,6 +26,9 @@ { [super configureForAccount:inAccount]; + NSString *server = [account preferenceForKey:KEY_SIPE_CONNECT_HOST group:GROUP_ACCOUNT_STATUS]; + [textField_server setStringValue:(server ? server : @"")]; + NSString *windowsLogin = [account preferenceForKey:KEY_SIPE_WINDOWS_LOGIN group:GROUP_ACCOUNT_STATUS]; [textField_windowsLogin setStringValue:(windowsLogin ? windowsLogin : @"")]; @@ -73,6 +76,9 @@ [account setPreference:[textField_windowsLogin stringValue] forKey:KEY_SIPE_WINDOWS_LOGIN group:GROUP_ACCOUNT_STATUS]; + [account setPreference:[textField_server stringValue] + forKey:KEY_SIPE_CONNECT_HOST group:GROUP_ACCOUNT_STATUS]; + // TODO: Figure out how to only save the password if the user has "Save password" checked [account setPreference:[textField_password stringValue] forKey:KEY_SIPE_PASSWORD group:GROUP_ACCOUNT_STATUS]; diff --git a/src/adium/English.lproj/ESSIPEAccountView.xib b/src/adium/English.lproj/ESSIPEAccountView.xib index 68889243..95750508 100644 --- a/src/adium/English.lproj/ESSIPEAccountView.xib +++ b/src/adium/English.lproj/ESSIPEAccountView.xib @@ -48,7 +48,6 @@ 268 {{18, 188}, {144, 18}} - _NS:9 YES @@ -83,7 +82,7 @@ 268 {{184, 20}, {156, 22}} - + _NS:9 YES @@ -119,7 +118,6 @@ 268 {{184, 52}, {156, 22}} - _NS:9 YES @@ -140,7 +138,6 @@ 268 {{184, 84}, {156, 22}} - _NS:9 YES @@ -161,7 +158,6 @@ 268 {{184, 116}, {156, 22}} - _NS:9 YES @@ -182,7 +178,6 @@ 268 {{184, 148}, {156, 22}} - _NS:9 YES @@ -203,7 +198,6 @@ 268 {{17, 23}, {120, 17}} - _NS:1535 YES @@ -236,7 +230,6 @@ 268 {{17, 55}, {107, 17}} - _NS:1535 YES @@ -256,7 +249,6 @@ 268 {{17, 87}, {78, 17}} - _NS:1535 YES @@ -276,7 +268,6 @@ 268 {{17, 119}, {96, 17}} - _NS:1535 YES @@ -296,7 +287,6 @@ 268 {{17, 151}, {125, 17}} - _NS:1535 YES @@ -316,7 +306,6 @@ 268 {{181, 215}, {162, 26}} - _NS:9 YES @@ -394,7 +383,6 @@ 268 {{184, 247}, {156, 22}} - _NS:9 YES @@ -415,7 +403,6 @@ 268 {{181, 276}, {162, 26}} - _NS:9 YES @@ -486,7 +473,6 @@ 268 {{184, 314}, {156, 22}} - _NS:9 YES @@ -507,7 +493,6 @@ 268 {{17, 220}, {153, 17}} - _NS:1535 YES @@ -527,7 +512,6 @@ 268 {{17, 250}, {78, 17}} - _NS:1535 YES @@ -547,7 +531,6 @@ 268 {{17, 281}, {111, 17}} - _NS:1535 YES @@ -567,7 +550,6 @@ 268 {{17, 317}, {81, 17}} - _NS:1535 YES @@ -585,12 +567,11 @@ {360, 348} - NSView - + 268 @@ -598,7 +579,6 @@ 264 {{123, 61}, {231, 22}} - YES @@ -618,7 +598,6 @@ 268 {{123, 31}, {231, 22}} - _NS:9 YES @@ -638,7 +617,6 @@ 268 {{123, 91}, {231, 22}} - _NS:9 YES @@ -660,7 +638,6 @@ 268 {{12, 34}, {68, 17}} - _NS:1535 YES @@ -680,7 +657,6 @@ 268 {{12, 64}, {103, 17}} - _NS:1535 YES @@ -700,7 +676,6 @@ 268 {{12, 94}, {71, 17}} - _NS:1535 YES @@ -717,8 +692,6 @@ {374, 132} - - _NS:9 NSView @@ -752,14 +725,6 @@ - textField_connectHost - - - - 223 - - - textField_userAgent @@ -846,6 +811,14 @@ 259 + + + textField_server + + + + 260 + @@ -1369,7 +1342,7 @@ - 259 + 260 @@ -1518,6 +1491,7 @@ NSTextField NSTextField NSTextField + NSTextField NSTextField NSTextField @@ -1554,6 +1528,10 @@ textField_groupchatUser NSTextField + + textField_server + NSTextField + textField_userAgent NSTextField diff --git a/src/adium/PurpleDefaultsSIPE.plist b/src/adium/PurpleDefaultsSIPE.plist index 6724cfdc..47beeeb1 100644 --- a/src/adium/PurpleDefaultsSIPE.plist +++ b/src/adium/PurpleDefaultsSIPE.plist @@ -6,5 +6,7 @@ SIPE:Connection Type auto + Connect Host + autodetect diff --git a/src/adium/SIPEAdiumPlugin.xcodeproj/project.pbxproj b/src/adium/SIPEAdiumPlugin.xcodeproj/project.pbxproj index 30812949..069fba10 100644 --- a/src/adium/SIPEAdiumPlugin.xcodeproj/project.pbxproj +++ b/src/adium/SIPEAdiumPlugin.xcodeproj/project.pbxproj @@ -69,6 +69,7 @@ 7B5DD2F116DB1E0A00B3D188 /* libsmime3.dylib in CopyFiles */ = {isa = PBXBuildFile; fileRef = 1C1DC3CB14A80038001F6A0F /* libsmime3.dylib */; }; 7B5DD2F216DB1E0A00B3D188 /* libnspr4.dylib in CopyFiles */ = {isa = PBXBuildFile; fileRef = 1C1DC3C514A7FFED001F6A0F /* libnspr4.dylib */; }; 7B78055816DEC73400B844A6 /* ESSIPEAccountView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 7B78055716DEC73400B844A6 /* ESSIPEAccountView.xib */; }; + 7B78059A16DFF8D300B844A6 /* sip-sec-negotiate.c in Sources */ = {isa = PBXBuildFile; fileRef = 7B78059916DFF8D200B844A6 /* sip-sec-negotiate.c */; }; 7B85598F166F1875005868B4 /* libnss3.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 7B57773F166EC5FB000DBCD5 /* libnss3.dylib */; }; 7B855990166F1878005868B4 /* libsoftokn3.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 7B577733166EBF7D000DBCD5 /* libsoftokn3.dylib */; }; 7B855991166F187B005868B4 /* libfreebl3.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 7B577730166EBEB6000DBCD5 /* libfreebl3.dylib */; }; @@ -275,6 +276,7 @@ 7B577733166EBF7D000DBCD5 /* libsoftokn3.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libsoftokn3.dylib; path = "../nss-3.14/mozilla/security/nss/lib/softoken/Darwin11.4.2_64_OPT.OBJ/libsoftokn3.dylib"; sourceTree = ADIUM_SRCPATH; }; 7B57773F166EC5FB000DBCD5 /* libnss3.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libnss3.dylib; path = mozilla/security/nss/lib/nss/Darwin11.4.2_64_OPT.OBJ/libnss3.dylib; sourceTree = NSS_SRCPATH; }; 7B78055716DEC73400B844A6 /* ESSIPEAccountView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = ESSIPEAccountView.xib; path = English.lproj/ESSIPEAccountView.xib; sourceTree = ""; }; + 7B78059916DFF8D200B844A6 /* sip-sec-negotiate.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = "sip-sec-negotiate.c"; sourceTree = ""; }; 8D5B49B6048680CD000E48DA /* SIPEAdiumPlugin.AdiumLibpurplePlugin */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SIPEAdiumPlugin.AdiumLibpurplePlugin; sourceTree = BUILT_PRODUCTS_DIR; }; 8D5B49B7048680CD000E48DA /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = SOURCE_ROOT; }; B13FAB4F119D5155001CE037 /* purple-connection.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = "purple-connection.c"; sourceTree = ""; }; @@ -545,6 +547,7 @@ 1CE49FFE14A17FD100663393 /* sip-sec-ntlm-tests.c */, B13FABA5119D585A001CE037 /* sip-sec-krb5.c */, 1CE4A00014A17FD100663393 /* sip-sec-tls-dsk.c */, + 7B78059916DFF8D200B844A6 /* sip-sec-negotiate.c */, 1CE4A00214A17FD100663393 /* sipe-certificate.c */, 1CE4A00414A17FD100663393 /* sipe-tls-tester.c */, 1CE4A00514A17FD100663393 /* sipe-tls.c */, @@ -766,6 +769,7 @@ 1CF2612D12C2E7420045B6CC /* ESSIPEService.m in Sources */, 1CF2612E12C2E7430045B6CC /* ESSIPELibpurpleServicePlugin.m in Sources */, 1CDEE46112C35DAD00790CAF /* ESSIPEAccountViewController.m in Sources */, + 7B78059A16DFF8D300B844A6 /* sip-sec-negotiate.c in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/src/purple/purple-plugin.c b/src/purple/purple-plugin.c index 49747d11..ee1e53ca 100644 --- a/src/purple/purple-plugin.c +++ b/src/purple/purple-plugin.c @@ -369,17 +369,7 @@ static void connect_to_core(PurpleConnection *gc, purple_connection_set_display_name(gc, sipe_public->sip_name); purple_connection_update_progress(gc, _("Connecting"), 1, 2); - errmsg = purple_account_get_string(account, "server", ""); -#ifdef ADIUM - /* - * The Adium client requires a server string be supplied. If the user - * entered "adium.im" assume they really want autodiscovery. - */ - if (sipe_strequal(errmsg, "adium.im")) - errmsg = ""; -#endif - username_split = g_strsplit(errmsg, ":", 2); - + username_split = g_strsplit(purple_account_get_string(account, "server", ""), ":", 2); if (sipe_strequal(transport, "auto")) { transport_type = (username_split[0] == NULL) ? SIPE_TRANSPORT_AUTO : SIPE_TRANSPORT_TLS; -- 2.11.4.GIT