Ejemplo n.º 1
0
void IMContactListHandler::contactMovedEventHandler(IMContactList & sender, std::string groupName, std::string contactId) 
{
	IMAccount * imAccount = _userProfile.getIMAccountManager().getIMAccount(sender.getIMAccountId());
	
	if (imAccount) 
	{
		IMContact imContact(*imAccount, contactId);

		bool inList = _imContactList.contains( imContact );

		if ( inList )
		{
			LOG_DEBUG("an IMContact has moved:" + contactId + ".  New Group: " + groupName );
			imContactMovedEvent(*this, groupName, imContact);
		} 
		else 
		{
			LOG_DEBUG("this IMContact(" + contactId + ") from group " + groupName
				+ " has not been added yet. Adding it as new IMContact.");
			newContactAddedEventHandler(sender, groupName, contactId);
		}

		OWSAFE_DELETE(imAccount);
	}
}
Ejemplo n.º 2
0
void GaimChatMngr::CreateConversationCbk(GaimConversation *conv, bool userCreated)
{
	GaimAccount *gAccount = gaim_conversation_get_account(conv);
	GaimConversationType chatType = gaim_conversation_get_type(conv);
	const char *gPrclId = gaim_account_get_protocol_id(gAccount);
	IMAccount *account = _accountMngr->FindIMAccount(gaim_account_get_username(gAccount),
		GaimIMPrcl::GetEnumIMProtocol(gPrclId));
	GaimIMChat *mChat = FindIMChat(*account);
	mConvInfo_t *mConv;

	if (chatType == GAIM_CONV_TYPE_IM)
	{
		IMChatSession *chatSession = NULL;

		// Check if it's a jabber contact, and remove his ressource
		std::string contactId = cleanContactId(std::string(gaim_conversation_get_name(conv)),
			GaimIMPrcl::GetEnumIMProtocol(gPrclId));

		IMContact imContact(*account, contactId);

		mConv = mChat->CreateChatSession(userCreated, *mChat);
		mConv->gaim_conv_session = conv;
 		conv->ui_data = mConv;

		chatSession = (IMChatSession *) mConv->conv_session;

		((IMContactSet &) chatSession->getIMContactSet()).insert(imContact);
		mChat->newIMChatSessionCreatedEvent(*mChat, *chatSession);

		mChat->contactAddedEvent(*mChat, *chatSession, imContact);
	}
	else if (chatType == GAIM_CONV_TYPE_CHAT)
	{
		int id = GetGaimConversationId(gaim_conversation_get_name(conv));

		if ((mConv = mChat->FindChatStructById(id)) == NULL)
		{
			mConv = mChat->CreateChatSession(userCreated, *mChat);
		}

		if (mConv->gaim_conv_session)
			gaim_conversation_destroy((GaimConversation *)mConv->gaim_conv_session);

		mConv->gaim_conv_session = conv;
		conv->ui_data = mConv;
	}
}
Ejemplo n.º 3
0
void QtAddIMContact::addIMContact() {
	QString contactId = _ui->contactIdLineEdit->text().trimmed();
	
	if (contactId.isEmpty()) {
		return;
	}
	
	QString protocolName = _ui->protocolComboBox->currentText();

	EnumIMProtocol::IMProtocol imProtocol = EnumIMProtocol::toIMProtocol(protocolName.toStdString());
	
	// sip contact should know their domain
	Config & config = ConfigManager::getInstance().getCurrentConfig();
	QString wengoSuffix = "@" + QString::fromStdString( config.getWengoRealm() );
	if (imProtocol == EnumIMProtocol::IMProtocolWengo) {
		contactId += wengoSuffix;
	} else if (imProtocol == EnumIMProtocol::IMProtocolSIP) {
		if (!contactId.contains("@")) {
			SipAccount * sipaccount = _cUserProfile.getUserProfile().getSipAccount();
			if (sipaccount) {
				contactId += QString("@") + QString::fromStdString(sipaccount->getRealm());
			}
		}
	}
	////
	
	IMContact imContact(imProtocol, contactId.toStdString());

	IMAccountList imAccounts = getSelectedIMAccounts(imProtocol);

	if (imAccounts.empty()) {
		_contactProfile.addIMContact(imContact);
	}

	for (IMAccountList::const_iterator it = imAccounts.begin();
		it != imAccounts.end(); ++it) {

		IMAccount * imAccount =
//			_cUserProfile.getUserProfile().getIMAccountManager().getIMAccount((*it).getUUID());	//VOXOX - JRT - 2009.04.09 
//			_cUserProfile.getUserProfile().getIMAccountManager().getIMAccount( it->second.getUUID());
			_cUserProfile.getUserProfile().getIMAccountManager().getIMAccount( it->second );	//VOXOX - JRT - 2009.04.24
		imContact.setIMAccount(imAccount);
		_contactProfile.addIMContact(imContact);
		OWSAFE_DELETE(imAccount);
	}
}
Ejemplo n.º 4
0
void PurpleChatMngr::ChatAddUsersCbk(PurpleConversation *conv, GList *users, gboolean new_arrivals)
{
	GList *l;
	PurpleAccount	*gAccount	 = purple_conversation_get_account(conv);
	const char		*gPrclId	 = purple_account_get_protocol_id(gAccount);
	IMAccount		*account	 = _accountMngr->FindIMAccount(purple_account_get_username(gAccount), PurpleIMPrcl::GetEnumIMProtocol(gPrclId));
	mConvInfo_t		*mConv		 = NULL;
	IMChatSession	*chatSession = NULL;
	PurpleIMChat	*mChat		 = FindIMChat(*account);

	if (!mChat)
		LOG_FATAL("Can't find IMChat !");

	mConv       = (mConvInfo_t *)   conv->ui_data;
	chatSession = mConv->conv_session;	//VOXOX - JRT - 2009.07.09 

	for (l = users; l != NULL; l = l->next)
	{
		PurpleConvChatBuddy *gCCBuddy = (PurpleConvChatBuddy *) l->data;

		if (gCCBuddy && strcmp(purple_account_get_username(gAccount), (char *) gCCBuddy->name))
		{
			std::string buddy((char *) gCCBuddy->name);
			IMContact imContact(*account, buddy);

			if (chatSession->getIMContactSet().find(imContact) != chatSession->getIMContactSet().end())
			{
				LOG_DEBUG("IMContact for " + imContact.getContactId() + " already in IMContactSet");
			}
			else
			{
				((IMContactSet &) chatSession->getIMContactSet()).insert(imContact);

				if (chatSession->getIMContactSet().size() == 1)
				{
					//Create session when first contact is added.
					mChat->newIMChatSessionCreatedEvent(*mChat, *chatSession);
				}

				LOG_DEBUG("IMContact " + imContact.getContactId() + " added to IMContactSet");
			}
			mChat->contactAddedEvent(*mChat, *chatSession, imContact);
		}
	}
}
Ejemplo n.º 5
0
void IMContactListHandler::newContactAddedEventHandler(IMContactList & sender,
	std::string groupName, std::string contactId) 
{
	IMAccount * imAccount = _userProfile.getIMAccountManager().getIMAccount(sender.getIMAccountId());

	if (imAccount) 
	{
		IMContact imContact(*imAccount, contactId);
		IMContact* pAcct = _imContactList.Add( imContact );

		if ( pAcct )
		{
			newIMContactAddedEvent(*this, groupName, *pAcct);
		}

		OWSAFE_DELETE(imAccount);
	}
}
Ejemplo n.º 6
0
void IMContactListHandler::contactRemovedEventHandler(IMContactList & sender, std::string groupName, std::string contactId) 
{
	IMAccount * imAccount = _userProfile.getIMAccountManager().getIMAccount(sender.getIMAccountId());
	if (imAccount) 
	{
		IMContact imContact(*imAccount, contactId);
		IMContact* pContact = _imContactList.findByIMContact( imContact );

		if ( pContact ) 
		{
			imContactRemovedEvent(*this, groupName, *pContact );
			_imContactList.Delete( *pContact );
		} 
		else 
		{
			LOG_ERROR("contact not found");
		}
		OWSAFE_DELETE(imAccount);
	}
}
Ejemplo n.º 7
0
void PurpleChatMngr::ChatRemoveUsersCbk(PurpleConversation *conv, GList *users)
{
	GList *l;
	PurpleAccount *gAccount = purple_conversation_get_account(conv);
	const char *gPrclId = purple_account_get_protocol_id(gAccount);
	IMAccount *account = _accountMngr->FindIMAccount(purple_account_get_username(gAccount), PurpleIMPrcl::GetEnumIMProtocol(gPrclId));
	mConvInfo_t *mConv = NULL;
	IMChatSession *chatSession = NULL;
	PurpleIMChat *mChat = FindIMChat(*account);

	if (!mChat)
		LOG_FATAL("Can't find IMChat !");

	mConv		= (mConvInfo_t *) conv->ui_data;
	chatSession = mConv->conv_session;		//VOXOX - JRT - 2009.07.09 

	for (l = users; l != NULL; l = l->next)
	{
		if (strcmp(purple_account_get_username(gAccount), (char *) l->data))
		{
			std::string buddy((char *) l->data);
			IMContact imContact(*account, buddy);

			IMContact* imContact2 = chatSession->getIMContactSet().findBy( account->getKey(), buddy );

//			if (chatSession->getIMContactSet().find(imContact) == chatSession->getIMContactSet().end())
			if ( imContact2 == NULL )
			{
				LOG_ERROR("IMContact for " + imContact.getContactId() + " not in IMContactSet");
			}
			else
			{
				LOG_DEBUG("IMContact " + imContact.getContactId() + " removed from IMContactSet");
				mChat->contactRemovedEvent(*mChat, *chatSession, buddy);
			}
		}
	}
}
Ejemplo n.º 8
0
void GaimChatMngr::ChatRemoveUsersCbk(GaimConversation *conv, GList *users)
{
	GList *l;
	GaimAccount *gAccount = gaim_conversation_get_account(conv);
	const char *gPrclId = gaim_account_get_protocol_id(gAccount);
	IMAccount *account = _accountMngr->FindIMAccount(gaim_account_get_username(gAccount),
								GaimIMPrcl::GetEnumIMProtocol(gPrclId));
	mConvInfo_t *mConv = NULL;
	IMChatSession *chatSession = NULL;
	GaimIMChat *mChat = FindIMChat(*account);

	if (!mChat)
		LOG_FATAL("Can't find IMChat !");

	mConv = (mConvInfo_t *) conv->ui_data;
	chatSession = (IMChatSession *) mConv->conv_session;

	for (l = users; l != NULL; l = l->next)
	{
		if (strcmp(gaim_account_get_username(gAccount), (char *) l->data))
		{
			std::string buddy((char *) l->data);
			IMContact imContact(*account, buddy);

			if (chatSession->getIMContactSet().find(imContact) == chatSession->getIMContactSet().end())
			{
				LOG_ERROR("IMContact for " + imContact.getContactId() + " not in IMContactSet");
			}
			else
			{
				LOG_DEBUG("IMContact " + imContact.getContactId() + " removed from IMContactSet");
				mChat->contactRemovedEvent(*mChat, *chatSession, buddy);
			}
		}
	}
}
Ejemplo n.º 9
0
void CommandServer::incomingRequestEventHandler(ServerSocket & sender, const std::string & connectionId, const std::string & data) 
{
	LOG_DEBUG("incoming request connectionId=" + connectionId + " data=" + data);
	String query = String(data);

	if (query == QueryStatus) 
	{
		//Find the phoneline status and answer
		UserProfile * userprofile = _wengoPhone.getUserProfileHandler().getCurrentUserProfile();
		if (userprofile) {
			IPhoneLine * phoneLine = userprofile->getActivePhoneLine();
			if (phoneLine && phoneLine->isConnected()) {
				_serverSocket->writeToClient(connectionId, QueryStatus + "|1");
			} else {
				_serverSocket->writeToClient(connectionId, QueryStatus + "|0");
			}
		}

	} 
	else if (query == QueryBringToFront) 
	{
		bringMainWindowToFrontEvent();
	} 
	else if (query.beginsWith(QueryCall)) 
	{
		//Extract the number from query & place the call
		StringList l = query.split("/");

		if (l.size() == 2) 
		{
			LOG_DEBUG("call peer=" + l[1]);
			UserProfile * userprofile = _wengoPhone.getUserProfileHandler().getCurrentUserProfile();
			if (userprofile) 
			{
				IPhoneLine * phoneLine = userprofile->getActivePhoneLine();
				if (phoneLine && phoneLine->isConnected()) 
				{
					phoneLine->makeCall(l[1]);
					_serverSocket->writeToClient(connectionId, data + "|1");
					return;
				}
			}
		}

		_serverSocket->writeToClient(connectionId, data + "|0");
	} 
	else if (query.beginsWith(QuerySms)) 
	{
		LOG_WARN("not yet implemented");

	} 
	else if (query.contains(QueryChat)) 
	{
		UserProfile * userProfile = _wengoPhone.getUserProfileHandler().getCurrentUserProfile();
		if (userProfile) 
		{
			IPhoneLine * phoneLine = userProfile->getActivePhoneLine();
			if (phoneLine && phoneLine->isConnected()) 
			{
				// extract the nickname from 1|o|chat/pseudo=value&sip=value
				StringList l = query.split("/");
				std::string nickname;
				if (l.size() == 2) 
				{
					int sepPos = l[1].find("&");
					nickname = l[1].substr(7, sepPos - 7);
				}
				////

				// get THE Wengo account
				IMAccountList imAccountList = userProfile->getIMAccountManager().getIMAccountsOfProtocol(EnumIMProtocol::IMProtocolWengo);
				////

				// create the IMContactSet
				IMAccount *imAccount = userProfile->getIMAccountManager().getIMAccount( imAccountList.begin()->second );	//VOXOX - JRT - 2009.04.24 
				IMContact imContact(*imAccount, nickname);
				IMContactSet imContactSet;
				imContactSet.insert(imContact);
				////

				// create the chat session
				std::string temp = "";
				ChatHandler & chatHandler = userProfile->getChatHandler();
				chatHandler.createSession(imAccount->getKey(), imContactSet, IMChat::Chat, temp );	//VOXOX - JRT - 2009.04.24
				////
				
				OWSAFE_DELETE(imAccount);
			}
		}
		// failed
		_serverSocket->writeToClient(connectionId, QueryChat + "|0");

	} else if (query.beginsWith(QueryAddContact)) {

		UserProfile * userProfile = _wengoPhone.getUserProfileHandler().getCurrentUserProfile();
		if (userProfile) {

			ContactInfo contactInfo;
			String tmp = query.substr(QueryAddContact.size(), query.size() - 1);

			StringList args = tmp.split("&");
			for (unsigned i = 0; i < args.size(); i++) {

				String tmp = args[i];
				if (!tmp.size()) {
					continue;
				}

				StringList list = tmp.split("=");
				if ((!(list.size() == 2)) || list[0].empty()) {
					continue;
				}

				// remove the first and the last quote if any
				String value = list[1];

				if (list[0] == NICKNAME_STR) {
					contactInfo.wengoName = value;
				} else if (list[0] == SIP_STR) {
					contactInfo.sip = value;
				} else if (list[0] == FIRSTNAME_STR) {
					contactInfo.firstname = value;
				} else if (list[0] == LASTNAME_STR) {
					contactInfo.lastname = value;
				} else if (list[0] == COUNTRY_STR) {
					contactInfo.country = value;
				} else if (list[0] == CITY_STR) {
					contactInfo.city = value;
				} else if (list[0] == STATE_STR) {
					contactInfo.state = value;
				} else if (list[0] == GROUP_STR) {
					contactInfo.group = value;
				} else if (list[0] == WDEALSERVICETITLE_STR) {
					contactInfo.wdealServiceTitle = value;
				} else if (list[0] == URL_STR) {
					if (value.beginsWith("\"")) {
						value = value.substr(1, value.size() - 2);
					}
					contactInfo.website = value;
				}
			}

			showAddContactEvent(contactInfo);
		}

	} else {

		Config & config = ConfigManager::getInstance().getCurrentConfig();

		//"emulate" a http server. Needed for Flash sockets
		std::string tmp = "<?xml version=\"1.0\"?>\n"
			"<!DOCTYPE cross-domain-policy SYSTEM \"http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd\">\n"
			"<cross-domain-policy>\n";
		StringList domains = config.getCmdServerAuthorizedDomains();
		StringList::const_iterator it = domains.begin(), end = domains.end();
		for (;it!=end; ++it) {
			tmp += "<allow-access-from domain=\"" + *it + "\" to-ports=\"*\" />\n";
		}
		tmp += "<allow-access-from domain=\"localhost\" to-ports=\"*\" />\n"
				"</cross-domain-policy>";
		_serverSocket->writeToClient(connectionId, buildHttpForFlash(tmp));
	}
}
Ejemplo n.º 10
0
void PurpleChatMngr::CreateConversationCbk(PurpleConversation *conv, bool userCreated)
{
	PurpleAccount*			gAccount = purple_conversation_get_account(conv);
	PurpleConversationType	chatType = purple_conversation_get_type(conv);
	const char*				gPrclId  = purple_account_get_protocol_id(gAccount);
	IMAccount*				account  = _accountMngr->FindIMAccount(purple_account_get_username(gAccount), PurpleIMPrcl::GetEnumIMProtocol(gPrclId));

	//VOXOX - JRT - 2009.07.20 - We seem to get a lot of crashes through here, via skype_find_chat.  I suspect account is not being found.
	if ( account == NULL )
	{
		std::string username = purple_account_get_username(gAccount);
		LOG_ERROR(" account == NULL for " + username + "\n");
	}

	PurpleIMChat*			mChat	 = FindIMChat(*account);
	mConvInfo_t*			mConv	 = NULL;

	if (chatType == PURPLE_CONV_TYPE_IM)
	{
		IMChatSession *chatSession = NULL;

		// Check if it's a jabber contact, remove the resource
		std::string contactId = cleanContactId(std::string(purple_conversation_get_name(conv)), PurpleIMPrcl::GetEnumIMProtocol(gPrclId));

		IMContact imContact(*account, contactId);

		mConv = mChat->CreateChatSession(userCreated, *mChat);
		mConv->purple_conv_session = conv;
 		conv->ui_data = mConv;

//		chatSession = (IMChatSession *) mConv->conv_session;
		chatSession = mConv->conv_session;	//VOXOX - JRT - 2009.07.09 - changed def from void* to IMChatSession*

		((IMContactSet &) chatSession->getIMContactSet()).insert(imContact);

		//VOXOX CHANGE CJC - validate if message don't have to be sent automatically
		if(userCreated)
		{
			if(mChat->getAutoMessage() != "")
			{
				mChat->newIMChatAndSendMessageSessionCreatedEvent(*mChat, *((IMChatSession *)(mConv->conv_session)),mChat->getAutoMessage(),true);
			}
			else 
			{
				switch( mChat->getIMChatType() )
				{
				case IMChat::ChatToEmail:
					mChat->newIMChatToEmailSessionCreatedEvent(*mChat, *(mConv->conv_session));	//VOXOX - JRT - 2009.07.09 
					mChat->contactAddedEvent(*mChat, *chatSession, imContact);
					break;

				case IMChat::ChatToSMS:
					mChat->newIMChatToSMSSessionCreatedEvent(*mChat, *(mConv->conv_session));	//VOXOX - JRT - 2009.07.09 
					mChat->contactAddedEvent(*mChat, *chatSession, imContact);
					break;

				case IMChat::Chat:
				case IMChat::ChatGroup:		//VOXOX - JRT - 2009.06.15 - we don't really expect this type.
					mChat->newIMChatSessionCreatedEvent(*mChat, *chatSession);
					mChat->contactAddedEvent(*mChat, *chatSession, imContact);
					break;

				default:
					assert(false);		//New IMChatType?
				}
			}	
		}
		else
		{
			mChat->newIMChatSessionCreatedEvent(*mChat, *chatSession);
			mChat->contactAddedEvent(*mChat, *chatSession, imContact);
		}

	}
	else if (chatType == PURPLE_CONV_TYPE_CHAT)
	{
//		int id = GetPurpleConversationId(purple_conversation_get_name(conv));	//VOXOX - JRT - 2009.06.16 - This does not work because it relies on CR name having ID as part of name.
//		int id = mChat->getGroupChatInfo().getId();

//		if ((mConv = mChat->FindChatStructById(id)) == NULL)
		if ((mConv = mChat->FindChatStructByName( conv->name )) == NULL)
		{
			mConv = mChat->CreateChatSession(userCreated, *mChat);

			IMChatSession* chatSession = mConv->conv_session;	//VOXOX - JRT - 2009.07.09 
			
			if ( chatSession )
			{
				chatSession->setIMChatType( IMChat::ChatGroup );

//				GroupChatInfo& gcInfo = chatSession->getIMChat().getGroupChatInfo();
				GroupChatInfo& gcInfo = chatSession->getGroupChatInfo();

				gcInfo.setId      ( mConv->conv_id );
				gcInfo.setChatRoom( conv->name     );
			}
		}

		if (mConv->purple_conv_session)
			purple_conversation_destroy(mConv->purple_conv_session);	//VOXOX - JRT - 2009.07.09 

		mConv->purple_conv_session = conv;
		conv->ui_data = mConv;
	}
}