adium-1.4 3546:1d83a6d53539: Fail immediately if trying to conne...
commits at adium.im
commits at adium.im
Sat Jun 25 20:06:59 UTC 2011
details: http://hg.adium.im/adium-1.4/rev/1d83a6d53539
revision: 3546:1d83a6d53539
branch: (none)
author: Evan Schoenberg
date: Sat Jun 25 15:06:00 2011 -0500
Fail immediately if trying to connect using X-FACEBOOK-PLATFORM with a non-facebook-id. We shouldn't ever let that happen, but it could prevent debugging confusion in the future
Subject: adium-1.4 3547:aef6880b60d5: Enable and disable the facebook mech on the fly. This means that a previously configured XMPP account for chat.facebook.com can still conncet (unless it tries to connect concurrently with an actual Facebook service account... at which point I just can't help you, mate.) Fixes #15289
details: http://hg.adium.im/adium-1.4/rev/aef6880b60d5
revision: 3547:aef6880b60d5
branch: (none)
author: Evan Schoenberg
date: Sat Jun 25 15:06:54 2011 -0500
Enable and disable the facebook mech on the fly. This means that a previously configured XMPP account for chat.facebook.com can still conncet (unless it tries to connect concurrently with an actual Facebook service account... at which point I just can't help you, mate.) Fixes #15289
diffs (150 lines):
diff -r a1ecaabb29e4 -r aef6880b60d5 Plugins/Purple Service/AIFacebookXMPPAccount.m
--- a/Plugins/Purple Service/AIFacebookXMPPAccount.m Sat Jun 25 14:08:42 2011 -0500
+++ b/Plugins/Purple Service/AIFacebookXMPPAccount.m Sat Jun 25 15:06:54 2011 -0500
@@ -25,6 +25,9 @@
#import <Adium/AIPasswordPromptController.h>
#import <Adium/AIService.h>
+#import <Libpurple/auth.h>
+#import "auth_fb.h"
+
enum {
AINoNetworkState,
AIMeGraphAPINetworkState,
@@ -124,6 +127,40 @@
purple_account_set_string(account, "fb_api_secret", ADIUM_API_SECRET);
}
+
+/* Add the authentication mechanism for X-FACEBOOK-PLATFORM. Note that if the server offers it,
+ * it will be used preferentially over any other mechanism e.g. DIGEST-MD5. */
+- (void)setFacebookMechEnabled:(BOOL)inEnabled
+{
+ static BOOL enabledFacebookMech = NO;
+ if (inEnabled != enabledFacebookMech) {
+ if (inEnabled)
+ jabber_auth_add_mech(jabber_auth_get_fb_mech());
+ else
+ jabber_auth_remove_mech(jabber_auth_get_fb_mech());
+
+ enabledFacebookMech = inEnabled;
+ }
+}
+
+- (void)connect
+{
+ [self setFacebookMechEnabled:YES];
+ [super connect];
+}
+
+- (void)didConnect
+{
+ [self setFacebookMechEnabled:NO];
+ [super didConnect];
+}
+
+- (void)didDisconnect
+{
+ [self setFacebookMechEnabled:NO];
+ [super didDisconnect];
+}
+
- (const char *)purpleAccountName
{
NSString *userNameWithHost = nil, *completeUserName = nil;
@@ -225,7 +262,7 @@
NSString *displayUID = contact.UID;
displayUID = [displayUID stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"-"]];
if ([displayUID hasSuffix:@"@chat.facebook.com"])
- displayUID = [displayUID substringToIndex:displayUID.length - @"@chat.facebook.com".length];
+ displayUID = [displayUID substringToIndex:(displayUID.length - @"@chat.facebook.com".length)];
[array addObject:[NSDictionary dictionaryWithObjectsAndKeys:
AILocalizedString(@"Facebook ID", nil), KEY_KEY,
diff -r a1ecaabb29e4 -r aef6880b60d5 Plugins/Purple Service/AIFacebookXMPPService.m
--- a/Plugins/Purple Service/AIFacebookXMPPService.m Sat Jun 25 14:08:42 2011 -0500
+++ b/Plugins/Purple Service/AIFacebookXMPPService.m Sat Jun 25 15:06:54 2011 -0500
@@ -12,37 +12,8 @@
#import "AIFacebookXMPPService.h"
-#import "AILibpurplePlugin.h"
-#import <Libpurple/auth.h>
-#import "auth_fb.h"
-
@implementation AIFacebookXMPPService
-- (id)init
-{
- if ((self = [super init])) {
- [[NSNotificationCenter defaultCenter] addObserver:self
- selector:@selector(libpurpleDidInit:)
- name:AILibpurpleDidInitialize
- object:nil];
- }
-
- return self;
-}
-
-- (void)dealloc
-{
- [[NSNotificationCenter defaultCenter] removeObserver:self];
-
- [super dealloc];
-}
-
-- (void)libpurpleDidInit:(NSNotification *)notification
-{
- AILog(@"Adding mech for fb");
- jabber_auth_add_mech(jabber_auth_get_fb_mech());
-}
-
//Account Creation
- (Class)accountClass{
return [AIFacebookXMPPAccount class];
diff -r a1ecaabb29e4 -r aef6880b60d5 Plugins/Purple Service/libpurple_extensions/auth_fb.c
--- a/Plugins/Purple Service/libpurple_extensions/auth_fb.c Sat Jun 25 14:08:42 2011 -0500
+++ b/Plugins/Purple Service/libpurple_extensions/auth_fb.c Sat Jun 25 15:06:54 2011 -0500
@@ -130,16 +130,34 @@
static JabberSaslState
fb_start(JabberStream *js, xmlnode *packet, xmlnode **response, char **error)
{
+ PurpleAccount *account;
+ const char *username;
+ gchar **parts;
- /* When connecting with X-FACEBOOK-PLATFORM, the password field must be set to the
- * OAUTH 2.0 session key.
- */
- xmlnode *auth = xmlnode_new("auth");
- xmlnode_set_namespace(auth, "urn:ietf:params:xml:ns:xmpp-sasl");
- xmlnode_set_attrib(auth, "mechanism", "X-FACEBOOK-PLATFORM");
+ account = purple_connection_get_account(js->gc);
+ username = purple_account_get_username(account);
- *response = auth;
- return JABBER_SASL_STATE_CONTINUE;
+ purple_debug_error("auth_fb", "account name is %s", username);
+
+ parts = g_strsplit(username, "@", 0);
+ if (parts[0] && strlen(parts[0]) && g_str_has_prefix(parts[0], "-")) {
+ /* When connecting with X-FACEBOOK-PLATFORM, the password field must be set to the
+ * OAUTH 2.0 session key.
+ *
+ * X-FACEBOOK-PLATFORM is only valid for a facebook userID, which is prefixed with '-'
+ */
+ xmlnode *auth = xmlnode_new("auth");
+ xmlnode_set_namespace(auth, "urn:ietf:params:xml:ns:xmpp-sasl");
+ xmlnode_set_attrib(auth, "mechanism", "X-FACEBOOK-PLATFORM");
+
+ *response = auth;
+
+ g_strfreev(parts);
+ return JABBER_SASL_STATE_CONTINUE;
+ } else {
+ g_strfreev(parts);
+ return JABBER_SASL_STATE_FAIL;
+ }
}
static JabberSaslMech fb_mech = {
More information about the commits
mailing list