adium/adium

Parents 0fbb04961745
Children eaec4182935a
Cleaned up some indentation. Fix a possible issue with UTF8 secrets/answers. Fix a crash when opening a new chat.

Carbons from ourself are now not passed to OTR, as it gets confused by them. They aren't ignored, just printed as the cyphertext. Maybe we should ignore them or only show an error message.
--- a/Frameworks/Adium Framework/Source/AIContentControllerProtocol.h Tue May 28 00:52:55 2013 +0200
+++ b/Frameworks/Adium Framework/Source/AIContentControllerProtocol.h Tue May 28 01:40:11 2013 +0200
@@ -125,8 +125,9 @@
//Encryption
- (NSAttributedString *)decodedIncomingMessage:(NSString *)inString
- fromContact:(AIListContact *)inListContact
- onAccount:(AIAccount *)inAccount;
+ fromContact:(AIListContact *)inListContact
+ onAccount:(AIAccount *)inAccount
+ tryDecrypt:(BOOL)decrypt;
- (NSString *)decryptedIncomingMessage:(NSString *)inString
fromContact:(AIListContact *)inListContact
onAccount:(AIAccount *)inAccount;
--- a/Plugins/Bonjour/AWBonjourAccount.m Tue May 28 00:52:55 2013 +0200
+++ b/Plugins/Bonjour/AWBonjourAccount.m Tue May 28 01:40:11 2013 +0200
@@ -241,7 +241,8 @@
if (html)
attributedMessage = [adium.contentController decodedIncomingMessage:html
fromContact:listContact
- onAccount:self];
+ onAccount:self
+ tryDecrypt:YES];
else
attributedMessage = [[[NSAttributedString alloc] initWithString:
[adium.contentController decryptedIncomingMessage:message
--- a/Plugins/Purple Service/CBPurpleAccount.m Tue May 28 00:52:55 2013 +0200
+++ b/Plugins/Purple Service/CBPurpleAccount.m Tue May 28 01:40:11 2013 +0200
@@ -1177,13 +1177,14 @@
listContact = chat.listObject;
- attributedMessage = [adium.contentController decodedIncomingMessage:[messageDict objectForKey:@"Message"]
- fromContact:listContact
- onAccount:self];
-
//Clear the typing flag of the chat since a message was just received
[self setTypingFlagOfChat:chat to:nil];
+ attributedMessage = [adium.contentController decodedIncomingMessage:[messageDict objectForKey:@"Message"]
+ fromContact:listContact
+ onAccount:self
+ tryDecrypt:(flags & PURPLE_MESSAGE_SEND) == 0];
+
[self _receivedMessage:attributedMessage
inChat:chat
fromListContact:listContact
--- a/Source/AIContentController.m Tue May 28 00:52:55 2013 +0200
+++ b/Source/AIContentController.m Tue May 28 01:40:11 2013 +0200
@@ -789,11 +789,11 @@
/*!
* @brief Given an incoming message, decrypt it if necessary then convert it to an NSAttributedString, processing HTML if possible
*/
-- (NSAttributedString *)decodedIncomingMessage:(NSString *)inString fromContact:(AIListContact *)inListContact onAccount:(AIAccount *)inAccount
+- (NSAttributedString *)decodedIncomingMessage:(NSString *)inString fromContact:(AIListContact *)inListContact onAccount:(AIAccount *)inAccount tryDecrypt:(BOOL)decrypt
{
- return [AIHTMLDecoder decodeHTML:[self decryptedIncomingMessage:inString
- fromContact:inListContact
- onAccount:inAccount]];
+ return [AIHTMLDecoder decodeHTML:decrypt ? [self decryptedIncomingMessage:inString
+ fromContact:inListContact
+ onAccount:inAccount] : inString];
}
#pragma mark OTR
--- a/Source/AdiumOTREncryption.m Tue May 28 00:52:55 2013 +0200
+++ b/Source/AdiumOTREncryption.m Tue May 28 01:40:11 2013 +0200
@@ -335,7 +335,7 @@
username = [chat.listObject.UID UTF8String];
context = otrl_context_find(otrg_plugin_userstate,
- username, accountname, proto, OTRL_INSTAG_RECENT, 0, NULL,
+ username, accountname, proto, OTRL_INSTAG_RECENT, 1, NULL,
NULL, NULL);
AILogWithSignature(@"%@ -> %p", chat, context);
@@ -725,12 +725,16 @@
switch (smp_event) {
case OTRL_SMPEVENT_ASK_FOR_ANSWER: {
- AIOTRSMPSecretAnswerWindowController *questionController = [[AIOTRSMPSecretAnswerWindowController alloc] initWithQuestion:[NSString stringWithUTF8String:question] from:listContact completionHandler:^(NSString *answer,NSString *_question){
+ AIOTRSMPSecretAnswerWindowController *questionController = [[AIOTRSMPSecretAnswerWindowController alloc]
+ initWithQuestion:[NSString stringWithUTF8String:question]
+ from:listContact
+ completionHandler:^(NSString *answer,NSString *_question){
if(!answer) {
otrl_message_abort_smp(otrg_get_userstate(), &ui_ops, opdata, context);
} else
otrl_message_respond_smp(otrg_get_userstate(), &ui_ops, opdata, context, (const unsigned char*)[answer UTF8String], answer.length);
- } isInitiator:NO];
+ }
+ isInitiator:NO];
[questionController showWindow:nil];
[questionController.window orderFront:nil];
@@ -738,9 +742,12 @@
break;
}
case OTRL_SMPEVENT_ASK_FOR_SECRET: {
- AIOTRSMPSharedSecretWindowController *questionController = [[AIOTRSMPSharedSecretWindowController alloc] initFrom:listContact completionHandler:^(NSString *answer){
+ AIOTRSMPSharedSecretWindowController *questionController = [[AIOTRSMPSharedSecretWindowController alloc]
+ initFrom:listContact
+ completionHandler:^(NSString *answer){
otrl_message_respond_smp(otrg_get_userstate(), &ui_ops, opdata, context, (const unsigned char*)[answer UTF8String], answer.length);
- } isInitiator:NO];
+ }
+ isInitiator:NO];
[questionController showWindow:nil];
[questionController.window orderFront:nil];
@@ -749,7 +756,10 @@
case OTRL_SMPEVENT_ERROR:
/* case OTRL_SMPEVENT_FAILURE: */ // I'm not actually sure what this event indicates, but it's not fatal failure of SMP.
case OTRL_SMPEVENT_ABORT: {
- NSString *localizedMessage = [NSString stringWithFormat:AILocalizedStringFromTableInBundle(@"Failed to verify %@'s identity.", nil, [NSBundle bundleForClass:[AdiumOTREncryption class]], nil), listContact.UID];
+ NSString *localizedMessage = [NSString stringWithFormat:AILocalizedStringFromTableInBundle(@"Failed to verify %@'s identity.",
+ nil,
+ [NSBundle bundleForClass:[AdiumOTREncryption class]], nil),
+ listContact.UID];
AIChat *chat = chatForContext(context);
if (!chat) chat = [adium.chatController chatWithContact:listContact];
@@ -759,7 +769,10 @@
break;
}
case OTRL_SMPEVENT_SUCCESS: {
- NSString *localizedMessage = [NSString stringWithFormat:AILocalizedStringFromTableInBundle(@"Successfully verified %@'s identity.", nil, [NSBundle bundleForClass:[AdiumOTREncryption class]], nil), listContact.UID];
+ NSString *localizedMessage = [NSString stringWithFormat:AILocalizedStringFromTableInBundle(@"Successfully verified %@'s identity.",
+ nil,
+ [NSBundle bundleForClass:[AdiumOTREncryption class]], nil),
+ listContact.UID];
AIChat *chat = chatForContext(context);
if (!chat) chat = [adium.chatController chatWithContact:listContact];
@@ -902,16 +915,18 @@
{
ConnContext *context = contextForChat(inChat);
- AIOTRSMPSecretAnswerWindowController *windowController = [[AIOTRSMPSecretAnswerWindowController alloc] initWithQuestion:@""
- from:inChat.listObject
- completionHandler:^(NSString *answer, NSString *question) {
+ AIOTRSMPSecretAnswerWindowController *windowController = [[AIOTRSMPSecretAnswerWindowController alloc]
+ initWithQuestion:@""
+ from:inChat.listObject
+ completionHandler:^(NSString *answer, NSString *question) {
+ const char *answerStr = [answer UTF8String];
otrl_message_initiate_smp_q(otrg_get_userstate(),
&ui_ops, NULL, context,
(const char *)[question UTF8String],
- (const unsigned char *)[answer UTF8String],
- answer.length);
+ (const unsigned char*)answerStr,
+ strlen(answerStr));
}
- isInitiator:TRUE];
+ isInitiator:TRUE];
[windowController showWindow:nil];
[windowController.window orderFront:nil];
@@ -921,15 +936,17 @@
{
ConnContext *context = contextForChat(inChat);
- AIOTRSMPSharedSecretWindowController *windowController = [[AIOTRSMPSharedSecretWindowController alloc] initFrom:inChat.listObject
- completionHandler:^(NSString *answer) {
+ AIOTRSMPSharedSecretWindowController *windowController = [[AIOTRSMPSharedSecretWindowController alloc]
+ initFrom:inChat.listObject
+ completionHandler:^(NSString *answer) {
+ const char *answerStr = [answer UTF8String];
otrl_message_initiate_smp(otrg_get_userstate(),
&ui_ops, NULL,
context,
- (const unsigned char *)[answer UTF8String],
- answer.length);
+ (const unsigned char*)answerStr,
+ strlen(answerStr));
}
- isInitiator:TRUE];
+ isInitiator:TRUE];
[windowController showWindow:nil];
[windowController.window orderFront:nil];