[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdenetwork/kopete/plugins/otr
From: Michael Zanetti <michael_zanetti () gmx ! net>
Date: 2009-09-28 21:41:54
Message-ID: 1254174114.934092.32456.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 1029071 by mzanetti:
Correctly handle Rich Text messages
M +12 -12 otrlchatinterface.cpp
M +1 -1 otrlchatinterface.h
M +21 -10 otrplugin.cpp
--- trunk/KDE/kdenetwork/kopete/plugins/otr/otrlchatinterface.cpp #1029070:1029071
@@ -531,18 +531,18 @@
return 2; // internal OTR message. Ignore it.
}
-KDE_EXPORT QString *OtrlChatInterface::encryptMessage( QString *msg, const QString \
&accountId, +KDE_EXPORT int OtrlChatInterface::encryptMessage( QString *msg, const \
QString &accountId, const QString &protocol, const QString &contactId , \
Kopete::ChatSession *chatSession ){ int err;
- char *newMessage;
- char *fragment;
+ char *newMessage = 0;
+ char *fragment = 0;
if( otrl_proto_message_type( msg->toLocal8Bit() ) == OTRL_MSGTYPE_NOTOTR ){
- msg->replace( QString('<'), QString("<") );
+// msg->replace( QString('<'), QString("<") );
err = otrl_message_sending( userstate, &ui_ops, chatSession, \
accountId.toLocal8Bit(), protocol.toLocal8Bit(), contactId.toLocal8Bit(), \
msg->toUtf8(), NULL, &newMessage, NULL, NULL );
if( err != 0 ){
- *msg = i18n("Encryption error");
+ return -1;
} else if( newMessage ){
/* Fragment the message if needed */
@@ -563,15 +563,15 @@
otrl_message_free( newMessage );
otrl_message_free( fragment );
}
+ OtrlMessageType type = otrl_proto_message_type( msg->toLocal8Bit() );
+ if( type == OTRL_MSGTYPE_TAGGEDPLAINTEXT ){
+ return 1; // Message is still plaintext, but tagged for opportunistic mode
+ }
+ return 0; // Encrypted successfully
}
}
- OtrlMessageType type = otrl_proto_message_type( msg->toLocal8Bit() );
- if( type == OTRL_MSGTYPE_NOTOTR | type == OTRL_MSGTYPE_TAGGEDPLAINTEXT ){
- msg->replace( QString("<"), QString("<") );
- }
-
-
- return msg;
+
+ return 2; // Message is still plaintext. Better not touching it
}
KDE_EXPORT QString OtrlChatInterface::getDefaultQuery( const QString &accountId ){
--- trunk/KDE/kdenetwork/kopete/plugins/otr/otrlchatinterface.h #1029070:1029071
@@ -50,7 +50,7 @@
static OtrlChatInterface *self();
int decryptMessage( QString *msg, const QString &accountId, const QString \
&protocol, const QString &contactId, Kopete::ChatSession *chatSession \
);
- QString *encryptMessage( QString *msg, const QString &accountId,
+ int encryptMessage( QString *msg, const QString &accountId,
const QString &protocol, const QString &contactId , Kopete::ChatSession \
*chatSession ); QString getDefaultQuery( const QString &accountId );
void disconnectSession( Kopete::ChatSession *chatSession );
--- trunk/KDE/kdenetwork/kopete/plugins/otr/otrplugin.cpp #1029070:1029071
@@ -153,18 +153,28 @@
void OTRPlugin::slotOutgoingMessage( Kopete::Message& msg )
{
if( msg.direction() == Kopete::Message::Outbound ){
- QString plainBody = msg.plainBody();
- QString cacheBody = msg.plainBody();
+// kDebug(14318) << "Outgoing message: Plain: " << msg.plainBody() << "body:" \
<< msg.escapedBody(); + QString msgBody = msg.parsedBody();
+ QString cacheBody = msg.parsedBody();
QString accountId = msg.manager()->account()->accountId();
Kopete::Contact *contact = msg.to().first();
- QString *encBody = otrlChatInterface->encryptMessage( &plainBody, accountId, \
msg.manager()->account()->protocol()->displayName(), contact->contactId(), \
msg.manager() );
- msg.setPlainBody( *encBody );
- msg.setType(Kopete::Message::TypeNormal);
- if( !msg.plainBody().isEmpty() ){
- messageCache.insert( *encBody, cacheBody );
- } else {
- messageCache.insert( "!OTR:MsgDelByOTR", cacheBody );
+ int encryptionState = otrlChatInterface->encryptMessage( &msgBody, accountId, \
msg.manager()->account()->protocol()->displayName(), contact->contactId(), \
msg.manager() ); + if(encryptionState == -1){
+ msg.setPlainBody(i18n("An error occured while encrypting the message."));
+ } else if(encryptionState == 0){
+// kDebug(14318) << "Encrypted successfully";
+ msg.setPlainBody( msgBody );
+ msg.setType(Kopete::Message::TypeNormal);
+ if( !msg.plainBody().isEmpty() ){
+ messageCache.insert( msgBody, cacheBody );
+ } else {
+ messageCache.insert( "!OTR:MsgDelByOTR", cacheBody );
+ }
+ } else if(encryptionState == 1){
+// kDebug(14318) << "Tagged plaintext!";
+ msg.setHtmlBody(msgBody);
+ messageCache.insert( msgBody, cacheBody );
}
}
}
@@ -258,8 +268,9 @@
return;
}
} else if( msg.direction() == Kopete::Message::Outbound ){
+// kDebug(14318) << "searching cache for" << msg.plainBody();
if( messageCache.contains( msg.plainBody() ) ){
- msg.setPlainBody( messageCache[msg.plainBody()] );
+ msg.setHtmlBody( messageCache[msg.plainBody()] );
messageCache.remove( messageCache[msg.plainBody()] );
if(messageCache.count() > 5) messageCache.clear();
}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic