Changeset - 2836f390b953
[Not reviewed]
0 2 0
HanzZ - 14 years ago 2011-06-19 20:40:27
hanzz.k@gmail.com
Receive VCard from PurpleAccount and fixed crash on disconnect
2 files changed with 14 insertions and 2 deletions:
0 comments (0 inline, 0 general)
backends/libpurple/main.cpp
Show inline comments
 
@@ -650,103 +650,113 @@ static PurpleConnectionUiOps conn_ui_ops =
 
	NULL
 
};
 

	
 
static void *notify_user_info(PurpleConnection *gc, const char *who, PurpleNotifyUserInfo *user_info) {
 
	std::string name(who);
 
	PurpleAccount *account = purple_connection_get_account(gc);
 
	GList *vcardEntries = purple_notify_user_info_get_entries(user_info);
 
	PurpleNotifyUserInfoEntry *vcardEntry;
 
	std::string firstName;
 
	std::string lastName;
 
	std::string fullName;
 
	std::string nickname;
 
	std::string header;
 
	std::string label;
 
	Swift::ByteArray photo;
 

	
 
	while (vcardEntries) {
 
		vcardEntry = (PurpleNotifyUserInfoEntry *)(vcardEntries->data);
 
		if (purple_notify_user_info_entry_get_label(vcardEntry) && purple_notify_user_info_entry_get_value(vcardEntry)){
 
			label = purple_notify_user_info_entry_get_label(vcardEntry);
 
			if (label == "Given Name" || label == "First Name") {
 
				firstName = purple_notify_user_info_entry_get_value(vcardEntry);
 
			}
 
			else if (label == "Family Name" || label == "Last Name") {
 
				lastName = purple_notify_user_info_entry_get_value(vcardEntry);
 
			}
 
			else if (label=="Nickname" || label == "Nick") {
 
				nickname = purple_notify_user_info_entry_get_value(vcardEntry);
 
			}
 
			else if (label=="Full Name") {
 
				fullName = purple_notify_user_info_entry_get_value(vcardEntry);
 
			}
 
			else {
 
				std::cout << "UNHANDLED VCARD LABEL '" << purple_notify_user_info_entry_get_label(vcardEntry) << "' " << purple_notify_user_info_entry_get_value(vcardEntry) << "\n";
 
			}
 
		}
 
		vcardEntries = vcardEntries->next;
 
	}
 

	
 
	if (name == purple_account_get_username(account)) {
 
		const gchar *displayname = purple_connection_get_display_name(gc);
 
		if (!displayname) {
 
			displayname = purple_account_get_name_for_display(account);
 
		}
 

	
 
		if (displayname) {
 
			nickname = displayname;
 
		}
 

	
 
		// avatar
 
		PurpleStoredImage *avatar = purple_buddy_icons_find_account_icon(account);
 
		if (avatar) {
 
			const gchar * data = (const gchar *) purple_imgstore_get_data(avatar);
 
			size_t len = purple_imgstore_get_size(avatar);
 
			if (len < 300000 && data) {
 
				photo = Swift::createByteArray(data, len);
 
			}
 
		}
 
	}
 

	
 
	if ((!firstName.empty() || !lastName.empty()) && fullName.empty())
 
		fullName = firstName + " " + lastName;
 

	
 
	PurpleBuddy *buddy = purple_find_buddy(purple_connection_get_account(gc), who);
 
	if (buddy) {
 
	if (buddy && photo.size() == 0) {
 
		gsize len;
 
		PurpleBuddyIcon *icon = NULL;
 
		icon = purple_buddy_icons_find(purple_connection_get_account(gc), name.c_str());
 
		if (icon) {
 
			const gchar * data = (gchar*)purple_buddy_icon_get_data(icon, &len);
 
			// Sometimes libpurple returns really broken pointers here
 
			// They weren't able to do anything with that and I don't know what to do too,
 
			// so it's better to hack through it by not trying to forward really broken things...
 
			if (len < 300000 && data) {
 
				photo = Swift::createByteArray(data, len);
 
// 				const gchar *ext = (gchar*)purple_buddy_icon_get_extension(icon);
 
// 				if (ext) {
 
// 					std::string extension(ext);
 
// 					if (extension != "icon") {
 
// 						if (extension == "jpg") {
 
// 							extension = "jpeg";
 
// 						}
 
// 						photo->addChild( new Tag("TYPE", "image/" + extension) );
 
// 					}
 
// 				}
 
			}
 
		}
 
	}
 

	
 
	
 
	np->handleVCard(np->m_accounts[account], np->m_vcards[np->m_accounts[account] + name], name, fullName, nickname, Swift::byteArrayToString(photo));
 
	np->m_vcards.erase(np->m_accounts[account] + name);
 

	
 
	return NULL;
 
}
 

	
 
static PurpleNotifyUiOps notifyUiOps =
 
{
 
		NULL,
 
		NULL,
 
		NULL,
 
		NULL,
 
		NULL,
 
		NULL,
 
		notify_user_info,
 
		NULL,
 
		NULL,
 
		NULL,
 
		NULL,
 
		NULL,
 
		NULL
 
};
 

	
include/Swiften/Server/Server.cpp
Show inline comments
 
@@ -12,97 +12,99 @@
 
#include "Swiften/Base/String.h"
 
#include "Swiften/Base/foreach.h"
 
#include "Swiften/Network/Connection.h"
 
#include "Swiften/Network/ConnectionServer.h"
 
#include "Swiften/Network/ConnectionServerFactory.h"
 
#include "Swiften/Elements/Element.h"
 
#include "Swiften/Elements/Presence.h"
 
#include "Swiften/Elements/RosterPayload.h"
 
#include "Swiften/Network/NetworkFactories.h"
 
#include "Swiften/Session/SessionTracer.h"
 
#include "Swiften/Elements/IQ.h"
 
#include "Swiften/Elements/VCard.h"
 
#include "Swiften/Server/UserRegistry.h"
 
#include <string>
 
#include "Swiften/Network/ConnectionServer.h"
 
#include "Swiften/Network/ConnectionFactory.h"
 
#include "Swiften/Server/ServerFromClientSession.h"
 
#include "Swiften/Server/ServerStanzaChannel.h"
 
#include "Swiften/Queries/IQRouter.h"
 

	
 

	
 
namespace Swift {
 

	
 
Server::Server(
 
		EventLoop* eventLoop,
 
		NetworkFactories* networkFactories,
 
		UserRegistry *userRegistry,
 
		const JID& jid,
 
		int port) :
 
			userRegistry_(userRegistry),
 
			port_(port),
 
			eventLoop(eventLoop),
 
			networkFactories_(networkFactories),
 
			stopping(false),
 
			selfJID(jid),
 
			stanzaChannel_(){
 
	stanzaChannel_ = new ServerStanzaChannel();
 
	iqRouter_ = new IQRouter(stanzaChannel_);
 
	tlsFactory = NULL;
 
}
 

	
 
Server::~Server() {
 
	stop();
 
	delete iqRouter_;
 
	delete stanzaChannel_;
 
}
 

	
 
void Server::start() {
 
	assert(!serverFromClientConnectionServer);
 
	if (serverFromClientConnectionServer) {
 
		return;
 
	}
 
	serverFromClientConnectionServer = networkFactories_->getConnectionServerFactory()->createConnectionServer(port_);
 
	serverFromClientConnectionServerSignalConnections.push_back(
 
		serverFromClientConnectionServer->onNewConnection.connect(
 
				boost::bind(&Server::handleNewClientConnection, this, _1)));
 
// 	serverFromClientConnectionServerSignalConnections.push_back(
 
// 		serverFromClientConnectionServer->onStopped.connect(
 
// 				boost::bind(&Server::handleClientConnectionServerStopped, this, _1)));
 

	
 
	serverFromClientConnectionServer->start();
 
}
 

	
 
void Server::stop() {
 
	if (stopping) {
 
		return;
 
	}
 

	
 
	stopping = true;
 

	
 
	foreach(boost::shared_ptr<ServerFromClientSession> session, serverFromClientSessions) {
 
		session->finishSession();
 
	}
 
	serverFromClientSessions.clear();
 

	
 
	if (serverFromClientConnectionServer) {
 
		serverFromClientConnectionServer->stop();
 
		foreach(boost::bsignals::connection& connection, serverFromClientConnectionServerSignalConnections) {
 
			connection.disconnect();
 
		}
 
		serverFromClientConnectionServerSignalConnections.clear();
 
		serverFromClientConnectionServer.reset();
 
	}
 

	
 
	stopping = false;
 
// 	onStopped(e);
 
}
 

	
 
void Server::handleNewClientConnection(boost::shared_ptr<Connection> connection) {
 

	
 
	boost::shared_ptr<ServerFromClientSession> serverFromClientSession = boost::shared_ptr<ServerFromClientSession>(
 
			new ServerFromClientSession(idGenerator.generateID(), connection, 
 
					&payloadParserFactories, &payloadSerializers, userRegistry_));
 
	//serverFromClientSession->setAllowSASLEXTERNAL();
 

	
 
	serverFromClientSession->onSessionStarted.connect(
 
			boost::bind(&Server::handleSessionStarted, this, serverFromClientSession));
 
	serverFromClientSession->onSessionFinished.connect(
 
			boost::bind(&Server::handleSessionFinished, this, 
 
			serverFromClientSession));
0 comments (0 inline, 0 general)