* Adium is the legal property of its developers, whose names are listed in the copyright file included * with this source distribution. * 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; either version 2 of the License, * or (at your option) any later version. * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #import "AIIRCServicesPasswordPlugin.h" #import <AIUtilities/AIStringAdditions.h> #import <Adium/AIPasswordPromptController.h> #import <Adium/AIAccountControllerProtocol.h> #import <Adium/AIContentControllerProtocol.h> #import <Adium/AIContentObject.h> #import <Adium/AIContentMessage.h> #import <Adium/AIListObject.h> #import <Adium/AIAccount.h> @interface AIIRCServicesPasswordPlugin() - (BOOL)message:(NSString *)message containsFragments:(NSArray *)fragments; - (void)willReceiveContent:(NSNotification *)notification; - (void)passwordReturned:(NSString *)inPassword returnCode:(AIPasswordPromptReturn)returnCode context:(NSDictionary *)inDict; @implementation AIIRCServicesPasswordPlugin [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willReceiveContent:) name:Content_WillReceiveContent [[NSNotificationCenter defaultCenter] removeObserver:self]; #pragma mark Content handling - (void)willReceiveContent:(NSNotification *)notification AIContentObject *contentObject = [[notification userInfo] objectForKey:@"Object"]; if (![contentObject isKindOfClass:[AIContentMessage class]]) { NSString *nick = contentObject.source.UID; NSString *server = contentObject.chat.account.host; AISpecialPasswordType serviceType; AIAccount *account = contentObject.chat.account; if ([nick isCaseInsensitivelyEqualToString:@"NickServ"]) { serviceType = AINickServPassword; identNick = account.displayName; } else if ([nick isCaseInsensitivelyEqualToString:@"Q"] && [server rangeOfString:@"quakenet" options:NSCaseInsensitiveSearch].location != NSNotFound) { serviceType = AIQPassword; } else if ([nick isCaseInsensitivelyEqualToString:@"X"] && [server rangeOfString:@"undernet" options:NSCaseInsensitiveSearch].location != NSNotFound) { serviceType = AIXPassword; } else if ([nick isCaseInsensitivelyEqualToString:@"AuthServ"] && [server rangeOfString:@"gamesurge" options:NSCaseInsensitiveSearch].location != NSNotFound) { serviceType = AIAuthServPassword; NSString *message = contentObject.message.string; if([self message:message containsFragments:[NSArray arrayWithObjects: @"authentication required", @"nickname is registered", @"nick belongs to another user", @"incorrect password", nil]]) { [account setValue:nil forProperty:@"Identifying" notify:NotifyNever]; AILogWithSignature(@"%@ received challenge from %@ :%@", account.displayName, nick, message); BOOL forcePrompt = [self message:message containsFragments:[NSArray arrayWithObjects:@"invalid", @"incorrect", nil]]; [adium.accountController passwordForType:serviceType promptOption:(forcePrompt ? AIPromptAlways : AIPromptAsNeeded) selector:@selector(passwordReturned:returnCode:context:) context:[NSDictionary dictionaryWithObjectsAndKeys:account, @"Account", identNick, @"Name", nil]]; contentObject.displayContent = NO; } else if ([self message:message containsFragments:[NSArray arrayWithObjects: @"you are now identified", @"you are now logged in", @"you are already logged in", @"authentication successful", @"i recognize you", nil]]) { if ([account boolValueForProperty:@"Identifying"]) { [account setValue:nil forProperty:@"Identifying" notify:NotifyNever]; contentObject.displayContent = NO; } else if ([self message:message containsFragments:[NSArray arrayWithObjects: @"changed in 60 seconds", @"Remember: Nobody from CService will ever ask you for your password, do NOT give out your password to anyone claiming to be CService.", @"you are seeking their assistance. See", @"REMINDER: Do not share your password with anyone. DALnet staff will not ask for your password unless", @"You have been invited to", nil]]) { contentObject.displayContent = NO; - (BOOL)message:(NSString *)message containsFragments:(NSArray *)fragments for (NSString *fragment in fragments) { if ([message rangeOfString:fragment options:NSCaseInsensitiveSearch].location != NSNotFound) { #pragma mark Password Return - (void)passwordReturned:(NSString *)inPassword returnCode:(AIPasswordPromptReturn)returnCode context:(NSDictionary *)inDict ESIRCAccount *account = [inDict objectForKey:@"Account"]; NSString *displayName = [inDict objectForKey:@"Name"]; AILogWithSignature(@"%@ password returned with any: %d", displayName, inPassword.length > 0); if (inPassword && inPassword.length) { [account setValue:[NSNumber numberWithBool:YES] forProperty:@"Identifying" notify:NotifyNever]; [(ESIRCAccount *)account identifyForName:displayName password:[inPassword stringByReplacingOccurrencesOfString:@" "