soc.2009.transport: 24b9cb2f: Fixed replacing @ in usernames and fixed...
hanzz at soc.pidgin.im
hanzz at soc.pidgin.im
Sat Jun 27 08:37:11 EDT 2009
-----------------------------------------------------------------
Revision: 24b9cb2fdeabf02000876fd202df714b6d201f2e
Ancestor: 6e150dd67c126830fb72cd16be98290acb973953
Author: hanzz at soc.pidgin.im
Date: 2009-06-27T12:31:25
Branch: im.pidgin.soc.2009.transport
URL: http://d.pidgin.im/viewmtn/revision/info/24b9cb2fdeabf02000876fd202df714b6d201f2e
Modified files:
main.cpp main.h user.cpp
ChangeLog:
Fixed replacing @ in usernames and fixed XHTML-IM.
-------------- next part --------------
============================================================
--- main.cpp d95e5e617cf799efea6ccaebb5f351b424250a11
+++ main.cpp 858c56c9bb00faf797e75e46ab58c6eeb32b4a9e
@@ -636,6 +636,8 @@ GlooxMessageHandler::GlooxMessageHandler
Log().Get("gloox") << "connecting to: " << m_configuration.server << " as " << m_configuration.jid << " with password " << m_configuration.password;
j = new HiComponent("jabber:component:accept",m_configuration.server,m_configuration.jid,m_configuration.password,m_configuration.port);
+ parser = new Parser(this);
+
GMainLoop *loop = g_main_loop_new(NULL, FALSE);
signal(SIGCHLD, SIG_IGN);
@@ -1304,7 +1306,13 @@ bool GlooxMessageHandler::onTLSConnect(c
return false;
}
+void GlooxMessageHandler::handleTag (Tag *tag) {
+ m_handleTagCallback(tag, m_userdata);
+}
+
void GlooxMessageHandler::handleMessage (const Message &msg, MessageSession *session) {
+ if (msg.from().bare() == msg.to().bare())
+ return;
User *user = userManager()->getUserByJID(msg.from().bare());
if (user!=NULL){
if (user->isConnected()){
@@ -1312,7 +1320,9 @@ void GlooxMessageHandler::handleMessage
if (!msgTag) return;
Tag *chatstates = msgTag->findChildWithAttrib("xmlns","http://jabber.org/protocol/chatstates");
if (chatstates!=NULL){
- user->receivedChatState(msg.to().username(),chatstates->name());
+ std::string username;
+ std::for_each( username.begin(), username.end(), replaceJidCharacters() );
+ user->receivedChatState(username,chatstates->name());
}
if(msgTag->findChild("body")!=NULL) {
m_stats->messageFromJabber();
============================================================
--- main.h fad25b75f97770f0e3f5f8a40e7b1c0ac57261ac
+++ main.h 45ab628553f099d9f250f84819edfe11460088aa
@@ -104,7 +104,7 @@ struct replaceBadJidCharacters {
struct authData;
struct replaceBadJidCharacters {
- void operator()(char& c) { if(c == '@') c = '%'; }
+ void operator()(char& c) { if(c == '@') c = '%';}
};
struct replaceJidCharacters {
@@ -146,7 +146,7 @@ struct Configuration {
std::string sqlPrefix; // mysql prefix used for tables
};
-class GlooxMessageHandler : public MessageHandler,ConnectionListener,PresenceHandler,SubscriptionHandler
+class GlooxMessageHandler : public MessageHandler,ConnectionListener,PresenceHandler,SubscriptionHandler, TagHandler
{
public:
@@ -174,6 +174,9 @@ public:
void purpleFileReceiveComplete(PurpleXfer *xfer);
void notifyEmail(PurpleConnection *gc,const char *subject, const char *from,const char *to, const char *url);
+ // TagHandler
+ void handleTag (Tag *tag);
+
// MessageHandler
void handleMessage (const Message &msg, MessageSession *session=0);
@@ -193,6 +196,8 @@ public:
bool hasCaps(const std::string &name);
void removeUser(User *user);
+ Parser *parser;
+
UserManager *userManager() { return m_userManager; }
GlooxStatsHandler *stats() { return m_stats; }
Configuration & configuration() { return m_configuration; }
@@ -215,7 +220,10 @@ public:
GlooxGatewayHandler *gatewayHandler;
SOCKS5BytestreamServer* ftServer;
-
+
+ void (*m_handleTagCallback)(Tag *tag, Tag *user_data);
+ Tag *m_userdata;
+
private:
// bool callback(GIOCondition condition);
bool initPurple();
============================================================
--- user.cpp 7e03e45e071edc8601fdf79221605ebd2c9a2ca2
+++ user.cpp da160c0d99b83f69501fa3924a6225af6e9c59e7
@@ -36,6 +36,16 @@ static gboolean sync_cb(gpointer data)
d = (User*) data;
return d->syncCallback();
}
+static void sendXhtmlTag(Tag *tag, Tag *stanzaTag) {
+ Tag *html = new Tag("html");
+ html->addAttribute("xmlns", "http://jabber.org/protocol/xhtml-im");
+ Tag *body = new Tag("body");
+ body->addAttribute("xmlns", "http://www.w3.org/1999/xhtml");
+ body->addChild(tag->clone());
+ html->addChild(body);
+ stanzaTag->addChild(html);
+ GlooxMessageHandler::instance()->j->send(stanzaTag);
+}
User::User(GlooxMessageHandler *parent, const std::string &jid, const std::string &username, const std::string &password){
p = parent;
@@ -533,14 +543,19 @@ void User::purpleConversationWriteIM(Pur
return;
std::string name = (std::string) purple_conversation_get_name(conv);
+
+ int pos = name.find("/");
+ name.erase(pos, name.length() - pos);
+
if (name.empty())
return;
+ std::for_each( name.begin(), name.end(), replaceBadJidCharacters() );
// new message from legacy network has been received
if (!isOpenedConversation(name)) {
m_conversations[name] = conv;
}
- Log().Get(m_jid) << "purpleConversationWriteIM:" << name;
+ Log().Get(m_jid) << "purpleConversationWriteIM:" << name << msg;
// send message to user
char *newline = purple_strdup_withhtml(msg);
@@ -573,17 +588,26 @@ void User::purpleConversationWriteIM(Pur
Tag *stanzaTag = s.tag();
- if (hasFeature(GLOOX_FEATURE_XHTML_IM)) {
- Tag *html = new Tag("html");
- html->addAttribute("xmlns", "http://jabber.org/protocol/xhtml-im");
- Tag *body = new Tag("body", (std::string) msg);
- body->addAttribute("xmlns", "http://www.w3.org/1999/xhtml");
- html->addChild(body);
- stanzaTag->addChild(html);
+ std::string m(msg);
+ if (m.find("<body>") == 0) {
+ m.erase(0,6);
+ m.erase(m.length() - 7, 7);
}
+ Log().Get("TEST") << m << " " << message;
+ if (hasFeature(GLOOX_FEATURE_XHTML_IM) && m != message) {
+ p->m_userdata = stanzaTag;
+ p->m_handleTagCallback = sendXhtmlTag;
+
+ p->parser->cleanup();
+ p->parser->feed(m);
+ g_free(newline);
+ g_free(strip);
+ return;
+ }
+ Log().Get("STANZATAG") << stanzaTag->xml();
+
p->j->send( stanzaTag );
-
g_free(newline);
g_free(strip);
}
@@ -645,6 +669,8 @@ void User::purpleBuddyTypingStopped(cons
if (!purple_value_get_boolean(getSetting("enable_chatstate")))
return;
Log().Get(m_jid) << uin << " stopped typing";
+ std::string username(uin);
+ std::for_each( username.begin(), username.end(), replaceBadJidCharacters() );
Tag *s = new Tag("message");
@@ -652,7 +678,7 @@ void User::purpleBuddyTypingStopped(cons
s->addAttribute("type","chat");
std::string from;
- from.append(uin);
+ from.append(username);
from.append("@");
from.append(p->jid()+"/bot");
s->addAttribute("from",from);
@@ -674,13 +700,15 @@ void User::purpleBuddyTyping(const std::
if (!purple_value_get_boolean(getSetting("enable_chatstate")))
return;
Log().Get(m_jid) << uin << " is typing";
+ std::string username(uin);
+ std::for_each( username.begin(), username.end(), replaceBadJidCharacters() );
Tag *s = new Tag("message");
s->addAttribute("to",m_jid);
s->addAttribute("type","chat");
std::string from;
- from.append(uin);
+ from.append(username);
from.append("@");
from.append(p->jid()+"/bot");
s->addAttribute("from",from);
@@ -714,13 +742,15 @@ void User::receivedMessage(const Message
*/
void User::receivedMessage(const Message& msg){
PurpleConversation * conv;
+ std::string username = msg.to().username();
+ std::for_each( username.begin(), username.end(), replaceJidCharacters() );
// open new conversation or get the opened one
- if (!isOpenedConversation(msg.to().username())){
- conv = purple_conversation_new(PURPLE_CONV_TYPE_IM,m_account,msg.to().username().c_str());
- m_conversations[msg.to().username()]=conv;
+ if (!isOpenedConversation(username)){
+ conv = purple_conversation_new(PURPLE_CONV_TYPE_IM,m_account,username.c_str());
+ m_conversations[username]=conv;
}
else{
- conv = m_conversations[msg.to().username()];
+ conv = m_conversations[username];
}
std::string body = msg.body();
More information about the Commits
mailing list