Exemplo n.º 1
0
bool sendMsgImage(cgcResponse::pointer response, CUserInfo::pointer fromUser, CFromInfo::pointer fromInfo, long mid, long width, long height, long type, cgcAttachment::pointer attachment, bool bNew, time_t offeventTime)
{
	BOOST_ASSERT (response.get() != 0);
	BOOST_ASSERT (fromUser.get() != 0);
	BOOST_ASSERT (fromInfo.get() != 0);
	BOOST_ASSERT (attachment.get() != 0);

	if (response->isInvalidate()) return false;

	response->lockResponse();
	if (fromInfo->fromType() == CFromInfo::FromDialogInfo)
	{
		response->setParameter(cgcParameter::create(_T("DID"), fromInfo->fromDialog()->dialogId()));
	}
	response->setParameter(cgcParameter::create(_T("FromAccount"), fromUser->getAccount()));
	response->setParameter(cgcParameter::create(_T("MID"), mid));
	response->setParameter(cgcParameter::create(_T("Type"), type));
	response->setParameter(cgcParameter::create(_T("Width"), width));
	response->setParameter(cgcParameter::create(_T("Height"), height));
	response->setParameter(cgcParameter::create2(_T("New"), bNew));
	if (offeventTime > 0)
	{
		char buffer[20];
		sprintf(buffer, "%ld", offeventTime);
		response->setParameter(cgcParameter::create(cgcParameter::PT_DATETIME, _T("Time"), buffer));
	}
	response->setAttachInfo(attachment->getTotal(), attachment->getIndex());
	response->setAttachData(attachment->getAttachData(), attachment->getAttachSize());
	response->sendResponse(0, 501);
	return true;
}
Exemplo n.º 2
0
bool sendDiaMembers(cgcResponse::pointer response, CUserInfo::pointer fromUser, CDialogInfo::pointer dialogInfo)
{
	BOOST_ASSERT (response.get() != 0);
	BOOST_ASSERT (fromUser.get() != 0);
	BOOST_ASSERT (dialogInfo.get() != 0);

	if (response->isInvalidate()) return false;

	response->lockResponse();
	response->setParameter(cgcParameter::create(_T("DID"), dialogInfo->dialogId()));
	response->setParameter(cgcParameter::create(_T("FromAccount"), fromUser->getAccount()));

	int index = 0;
	CLockMap<std::string, CUserInfo::pointer>::const_iterator iterUserInfo;
	boost::mutex::scoped_lock lockUserInfo(const_cast<boost::mutex&>(dialogInfo->m_members.mutex()));
	for (iterUserInfo=dialogInfo->m_members.begin(); iterUserInfo!=dialogInfo->m_members.end(); iterUserInfo++)
	{
		CUserInfo::pointer memberUserInfo = iterUserInfo->second;

		char uaBuffer[12];
		sprintf(uaBuffer, "UA%d", index++);
		response->setParameter(cgcParameter::create(uaBuffer, memberUserInfo->getAccount()));
	}

	response->sendResponse(0, 601);
	return true;
}
Exemplo n.º 3
0
bool getUserInfo(CAccountInfo::pointer accountInfo, const std::string & userAccount, CUserInfo::pointer & resultUserInfo)
{
	BOOST_ASSERT (accountInfo.get() != 0);

	CFriendInfo::pointer friendInfo;
	if (accountInfo->m_allfriends.find(userAccount, friendInfo))
	{
		resultUserInfo = friendInfo->userinfo();
	}else
	{
		CLockMap<unsigned int, CCompanyInfoPointer>::const_iterator iterCompany;
		boost::mutex::scoped_lock lock(const_cast<boost::mutex&>(accountInfo->getUserinfo()->m_companys.mutex()));
		for (iterCompany=accountInfo->getUserinfo()->m_companys.begin(); iterCompany!=accountInfo->getUserinfo()->m_companys.end(); iterCompany++)
		{
			resultUserInfo = iterCompany->second->getUserInfo(userAccount);
			if (resultUserInfo.get() != 0)
				break;
		}

		if (resultUserInfo.get() == 0)
		{
			// Friend not exist.
			return false;
		}
	}

	return true;
}
Exemplo n.º 4
0
bool sendDiaInvite(CAccountInfo::pointer toAccount, CUserInfo::pointer fromUser, CDialogInfo::pointer dialogInfo, CUserInfo::pointer inviteUserInfo)
{
	BOOST_ASSERT (toAccount.get() != 0);
	BOOST_ASSERT (fromUser.get() != 0);
	BOOST_ASSERT (dialogInfo.get() != 0);
	BOOST_ASSERT (inviteUserInfo.get() != 0);

	cgcSession::pointer toUserCgcSession = gSystem->getcgcSession(toAccount->getSessionId());
	if (toUserCgcSession.get() == NULL) return false;
	cgcResponse::pointer toUserCgcResponse = toUserCgcSession->getLastResponse();
	if (toUserCgcResponse.get() == NULL || toUserCgcResponse->isInvalidate()) return false;

	return sendDiaInvite(toUserCgcResponse, fromUser, dialogInfo, inviteUserInfo);
}
Exemplo n.º 5
0
bool sendDiaQuit(cgcResponse::pointer response, CUserInfo::pointer fromUser, CDialogInfo::pointer dialogInfo)
{
	BOOST_ASSERT (response.get() != 0);
	BOOST_ASSERT (fromUser.get() != 0);
	BOOST_ASSERT (dialogInfo.get() != 0);

	if (response->isInvalidate()) return false;

	response->lockResponse();
	response->setParameter(cgcParameter::create(_T("DID"), dialogInfo->dialogId()));
	response->setParameter(cgcParameter::create(_T("FromAccount"), fromUser->getAccount()));
	response->sendResponse(0, 602);
	return true;
}
Exemplo n.º 6
0
void GroupChatWindow::invitedUser(CUserInfo::pointer userInfo)
{
	assert (userInfo.get() != NULL);

	long item = m_listCtrl->InsertItem(m_listCtrl->GetItemCount(), wxString::Format(_T("%s(%s)"), userInfo->getUserName().c_str(), userInfo->getAccount().c_str()), 0);
	//m_listCtrl->SetItemData(item, );
}
Exemplo n.º 7
0
extern "C" int CGC_API DiaQuit(const cgcRequest::pointer & request, cgcResponse::pointer response, cgcSession::pointer session)
{
	/////////////////////////////////
	// Request
	const tstring & sAccountId = request->getParameterValue(_T("AccountId"), _T(""));
	if (sAccountId.empty()) return -1;
	long dialogId = request->getParameterValue(_T("DID"), 0);

	/////////////////////////////////
	// Process
	CAccountInfo::pointer accountInfo = CGC_POINTER_CAST<CAccountInfo>(gApplication->getAttribute(BMT_ACCOUNTIDS, sAccountId));
	if (accountInfo.get() == NULL)
	{
		// Un register.
		return 14;
	}else if (session->getId().compare(accountInfo->getSessionId()) != 0)
	{
		// SessionId Error
		return -3;
	}

	CDialogInfo::pointer dialogInfo = CGC_POINTER_CAST<CDialogInfo>(gApplication->getAttribute(BMT_DIALOGS, dialogId));
	if (dialogInfo.get() == NULL)
	{
		// Dialog id not exist.
		return 71;
	}

	if (!dialogInfo->m_members.remove(accountInfo->getUserinfo()->getAccount()))
	{
		// Member not exist.
		return 73;
	}

	CLockMap<std::string, CUserInfo::pointer>::const_iterator iterUserInfo;
	boost::mutex::scoped_lock lockUserInfo(const_cast<boost::mutex&>(dialogInfo->m_members.mutex()));
	for (iterUserInfo=dialogInfo->m_members.begin(); iterUserInfo!=dialogInfo->m_members.end(); iterUserInfo++)
	{
		CUserInfo::pointer memberUserInfo = iterUserInfo->second;

		// Not register.
		CAccountInfo::pointer memberAccountInfo = CGC_POINTER_CAST<CAccountInfo>(gApplication->getAttribute(BMT_ACCOUNTS, memberUserInfo->getAccount()));
		if (memberAccountInfo.get() == NULL)
		{
			// offline event
			CMessageInfo::pointer messageInfo = CMessageInfo::create(0, 0, CConversationInfo::CT_QUIT, true);
			COfflineEvent::pointer offlineEvent = COfflineEvent::create(602, CFromInfo::create(dialogInfo), accountInfo->getUserinfo(), messageInfo);
			offlineEvent->toAccount(memberUserInfo);
			gAVSProxy->addOffEvent(memberUserInfo, offlineEvent);
			continue;
		}

		sendDiaQuit(memberAccountInfo, accountInfo->getUserinfo(), dialogInfo);
	}
	lockUserInfo.unlock();

	// Response
	return 0;
}
Exemplo n.º 8
0
bool sendMsgRequest(CAccountInfo::pointer toAccount, CUserInfo::pointer fromUser, long mid, long type)
{
	BOOST_ASSERT (toAccount.get() != 0);
	BOOST_ASSERT (fromUser.get() != 0);

	cgcSession::pointer toUserCgcSession = gSystem->getcgcSession(toAccount->getSessionId());
	if (toUserCgcSession.get() == NULL) return false;
	cgcResponse::pointer toUserCgcResponse = toUserCgcSession->getLastResponse();
	if (toUserCgcResponse.get() == NULL || toUserCgcResponse->isInvalidate()) return false;

	toUserCgcResponse->lockResponse();
	toUserCgcResponse->setParameter(cgcParameter::create(_T("FromAccount"), fromUser->getAccount()));
	toUserCgcResponse->setParameter(cgcParameter::create(_T("Type"), type));
	toUserCgcResponse->setParameter(cgcParameter::create(_T("MID"), mid));
	toUserCgcResponse->sendResponse(0, 511);
	return true;
}
Exemplo n.º 9
0
void MyApp::onDialogInvited(CDialogInfo::pointer dialogInfo, CUserInfo::pointer inviteUserInfo)
{
	assert (dialogInfo.get() != NULL);
	assert (inviteUserInfo.get() != NULL);

	if (gMyCoGroup != NULL)
		gMyCoGroup->onDialogInvited(dialogInfo, inviteUserInfo);
}
Exemplo n.º 10
0
// ResponseP2PUser: 响应一个P2P请求
extern "C" int CGC_API ResponseP2PUser(const cgcSotpRequest::pointer & request, cgcSotpResponse::pointer response)
{
	// Request
	cgcParameter::pointer pFromUser = request->getParameter(_T("FromUser"));
	if (pFromUser == 0 || pFromUser->empty()) return -1;
	cgcParameter::pointer pToUser = request->getParameter(_T("ToUser"));
	if (pToUser == 0 || pToUser->empty()) return -1;
	long nP2PType = request->getParameterValue(_T("P2PType"), 0);
	long nP2PParam = request->getParameterValue(_T("P2PParam"), 0);

	cgcAttributes::pointer attributes = theApplication->getAttributes(true);

	// Send P2P Response
	CUserInfo::pointer pFromUserInfo = CGC_OBJECT_CAST<CUserInfo>(attributes->getAttribute(NAME_USERINFO, pFromUser->getStr()));
	if (pFromUserInfo.get() == NULL) return -2;
	//if (!gAVSProxy->m_mapUserInfo.find(pFromUser->getValue(), pFromUserInfo)) return -2;
	CUserInfo::pointer pToUserInfo = CGC_OBJECT_CAST<CUserInfo>(attributes->getAttribute(NAME_USERINFO, pToUser->getStr()));
	if (pToUserInfo.get() == NULL) return -2;
	//if (!gAVSProxy->m_mapUserInfo.find(pToUser->getValue(), pToUserInfo)) return -2;

	cgcSession::pointer pToUserCgcSession = theSystem->getSession(pToUserInfo->getSessionId());
	if (pToUserCgcSession.get() == NULL) return -3;
	cgcSotpResponse::pointer pToUserCgcResponse = CGC_SOTPRESPONSE_CAST(pToUserCgcSession->getLastResponse());
	if (pToUserCgcResponse.get() == NULL || pToUserCgcResponse->isInvalidate())
	{
		return -3;
	}

	response->sendResponse();
//	response->sendResponse();
//	response->sendResponse();

	// ???
	// Message:
	// 1003: P2P Response Message
//	pToUserCgcResponse->addParameter(CGC_PARAMETER(cgcParameter::PT_INT, _T("MessageType"), _T("1003")));
	pToUserCgcResponse->addParameter(CGC_PARAMETER(_T("FromUser"), pFromUserInfo->getUsername()));
	pToUserCgcResponse->addParameter(CGC_PARAMETER(_T("P2PType"), nP2PType));
	pToUserCgcResponse->addParameter(CGC_PARAMETER(_T("P2PParam"), nP2PParam));
	pToUserCgcResponse->addParameter(CGC_PARAMETER(_T("RemoteAddr"), request->getRemoteAddr()));
	pToUserCgcResponse->sendResponse(0, 1003);

	cgcSession::pointer pFromUserCgcSession = theSystem->getSession(pFromUserInfo->getSessionId());
	if (pFromUserCgcSession.get() == NULL) return -4;
	cgcSotpResponse::pointer pFromUserCgcResponse = CGC_SOTPRESPONSE_CAST(pFromUserCgcSession->getLastResponse());
	if (pFromUserCgcResponse.get() == NULL || pFromUserCgcResponse->isInvalidate())
	{
		return -4;
	}

	pFromUserCgcResponse->addParameter(CGC_PARAMETER(_T("ToUser"), pToUser->getStr()));
	pFromUserCgcResponse->addParameter(CGC_PARAMETER(_T("P2PType"), nP2PType));
	pFromUserCgcResponse->addParameter(CGC_PARAMETER(_T("P2PParam"), nP2PParam));
	pFromUserCgcResponse->sendResponse(0, 1004);
	return 0;
}
Exemplo n.º 11
0
bool sendMsg(cgcResponse::pointer response, CUserInfo::pointer fromUser, CFromInfo::pointer fromInfo, long mid, cgcAttachment::pointer attachment)
{
	BOOST_ASSERT (response.get() != 0);
	BOOST_ASSERT (fromUser.get() != 0);
	BOOST_ASSERT (fromInfo.get() != 0);
	BOOST_ASSERT (attachment.get() != 0);

	if (response->isInvalidate()) return false;

	response->lockResponse();
	if (fromInfo->fromType() == CFromInfo::FromDialogInfo)
	{
		response->setParameter(cgcParameter::create(_T("DID"), fromInfo->fromDialog()->dialogId()));
	}
	response->setParameter(cgcParameter::create(_T("FromAccount"), fromUser->getAccount()));
	response->setParameter(cgcParameter::create(_T("MID"), mid));
	response->setAttachInfo(attachment->getTotal(), attachment->getIndex());
	response->setAttachData(attachment->getAttachData(), attachment->getAttachSize());
	response->sendResponse(0, 501);
	return true;
}
Exemplo n.º 12
0
bool sendMsgImage(CAccountInfo::pointer toAccount, CUserInfo::pointer fromUser, CFromInfo::pointer fromInfo, long mid, long width, long height, long type, cgcAttachment::pointer attachment, bool bNew)
{
	BOOST_ASSERT (fromUser.get() != 0);
	BOOST_ASSERT (fromInfo.get() != 0);
	BOOST_ASSERT (toAccount.get() != 0);

	cgcSession::pointer toUserCgcSession = gSystem->getcgcSession(toAccount->getSessionId());
	if (toUserCgcSession.get() == NULL) return false;
	cgcResponse::pointer toUserCgcResponse = toUserCgcSession->getLastResponse();
	if (toUserCgcResponse.get() == NULL || toUserCgcResponse->isInvalidate()) return false;

	return sendMsgImage(toUserCgcResponse, fromUser, fromInfo, mid, width, height, type, attachment, bNew);
}
Exemplo n.º 13
0
bool sendUserOnOfflineEvent(CAccountInfo::pointer toAccount, CUserInfo::pointer fromUser, bool online, bool quit)
{
	BOOST_ASSERT (toAccount.get() != 0);
	BOOST_ASSERT (fromUser.get() != 0);

	cgcSession::pointer toUserCgcSession = gSystem->getcgcSession(toAccount->getSessionId());
	if (toUserCgcSession.get() == NULL) return false;
	cgcResponse::pointer toUserCgcResponse = toUserCgcSession->getLastResponse();
	if (toUserCgcResponse.get() == NULL || toUserCgcResponse->isInvalidate()) return false;

	toUserCgcResponse->lockResponse();
	toUserCgcResponse->setParameter(cgcParameter::create(_T("FromAccount"), fromUser->getAccount()));
	if (quit)
	{
		toUserCgcResponse->setParameter(cgcParameter::create2(_T("Quit"), true));
	}

	if (online)
		toUserCgcResponse->sendResponse(0, 201);
	else
		toUserCgcResponse->sendResponse(0, 202);
	return true;
}
Exemplo n.º 14
0
void CAVSProxy::addOffEvent(CUserInfo::pointer touserInfo, COfflineEvent::pointer offlineEvent)
{
	BOOST_ASSERT (touserInfo.get() != 0);
	BOOST_ASSERT (offlineEvent.get() != 0);
	BOOST_ASSERT (offlineEvent->fromInfo().get() != 0);

	touserInfo->m_offevents.add(offlineEvent);

	CMessageInfo::pointer messageInfo = offlineEvent->getMessage();
	if (messageInfo.get() == 0)
	{
		return;
	}

	struct timeb tbNow;
	ftime(&tbNow);
	tbNow.time -= (tbNow.timezone*60);
	offlineEvent->getMessage()->msgtime(tbNow.time);

	if (m_bodbHandler->isopen())
	{
		long nFromId = 0;
		if (offlineEvent->fromInfo()->fromType() == CFromInfo::FromDialogInfo)
		{
			nFromId = offlineEvent->fromInfo()->fromDialog()->dialogId();
		}
		char sql[10*1024];
		memset(sql, 0, sizeof(sql));
		switch (offlineEvent->getEvent())
		{
		case 601:	// diainvite
		case 602:	// diaquit
			{
				sprintf(sql, "INSERT INTO offevents_t (event,fromtype,fromid,fromaccount,toaccount,message,msgtype) \
							 VALUES(%d,%d,%ld,'%s','%s','%s',%d)",
							 offlineEvent->getEvent(), (int)offlineEvent->fromInfo()->fromType(), nFromId, offlineEvent->getFromAccount()->getAccount().c_str(),
							 touserInfo->getAccount().c_str(), offlineEvent->toAccount()->getAccount().c_str(), messageInfo->type()
							 );
			}break;
		default:
			{
				switch (messageInfo->type())
				{
				case 3:
					{
						// image
						sprintf(sql, "INSERT INTO offevents_t (event,fromtype,fromid,fromaccount,toaccount,msgtype,newflag,message,msgsize,width,height) \
									 VALUES(%d,%d,%ld,'%s','%s',%d, %s, '%s', %d, %d, %d)",
									 offlineEvent->getEvent(), (int)offlineEvent->fromInfo()->fromType(), nFromId, offlineEvent->getFromAccount()->getAccount().c_str(),
									 touserInfo->getAccount().c_str(), messageInfo->type(),
									 messageInfo->newflag() ? "true" : "false",
									 messageInfo->getdata(), messageInfo->filesize(),
									 messageInfo->imageWidth(), messageInfo->imageHeight()
									 );
					}break;
				case 11:
					{
						// ??
						// Do not support to save the file offevent.
						return;
					}break;
				default:
					{

						sprintf(sql, "INSERT INTO offevents_t (event,fromtype,fromid,fromaccount,toaccount,msgtype,newflag,message,msgsize)\
									 VALUES(%d,%d,%ld,'%s','%s',%d, %s, '%s', %ld)",
									 offlineEvent->getEvent(), (int)offlineEvent->fromInfo()->fromType(), nFromId, offlineEvent->getFromAccount()->getAccount().c_str(),
									 touserInfo->getAccount().c_str(), messageInfo->type(),
									 messageInfo->newflag() ? "true" : "false",
									 messageInfo->getdata(), messageInfo->total()
									 );
					}break;
				}
			}break;
		}

		m_bodbHandler->execsql(sql);

	}
Exemplo n.º 15
0
extern "C" int CGC_API DiaInvite(const cgcRequest::pointer & request, cgcResponse::pointer response, cgcSession::pointer session)
{
	/////////////////////////////////
	// Request
	const tstring & sAccountId = request->getParameterValue(_T("AccountId"), _T(""));
	if (sAccountId.empty()) return -1;
	long dialogId = request->getParameterValue(_T("DID"), 0);

	/////////////////////////////////
	// Process
	CAccountInfo::pointer accountInfo = CGC_POINTER_CAST<CAccountInfo>(gApplication->getAttribute(BMT_ACCOUNTIDS, sAccountId));
	if (accountInfo.get() == NULL)
	//if (!gAVSProxy->m_accountids.find(sAccountId, accountInfo))
	{
		// Un register.
		return 14;
	}else if (session->getId().compare(accountInfo->getSessionId()) != 0)
	{
		// SessionId Error
		return -3;
	}

	CDialogInfo::pointer dialogInfo;
	if (dialogId == 0)
	{
		// New Dialog
		dialogInfo = CDialogInfo::create(gAVSProxy->getNextDialogId(), accountInfo->getUserinfo());
		dialogInfo->m_members.insert(accountInfo->getUserinfo()->getAccount(), accountInfo->getUserinfo());
		gApplication->setAttribute(BMT_DIALOGS, dialogInfo->dialogId(), dialogInfo);
		//gAVSProxy->m_dialogs.insert(dialogInfo->dialogId(), dialogInfo);

		response->setParameter(cgcParameter::create(_T("DID"), dialogInfo->dialogId()));
		response->sendResponse();
	}else
	{
		dialogInfo = CGC_POINTER_CAST<CDialogInfo>(gApplication->getAttribute(BMT_DIALOGS, dialogId));
		if (dialogInfo.get() == NULL)
		//if (!gAVSProxy->m_dialogs.find(dialogId, dialogInfo))
		{
			// Dialog id not exist.
			return 71;
		}/*else if (dialogInfo->manager().get() != accountInfo->getUserinfo().get())
		{
			// ?? Not the manager error.
			return 72;
		}*/
	}

	int index = 0;
	while (true)
	{
		char buffer[20];
		sprintf(buffer, "UA%d", index++);

		const tstring & sInviteUserAccount = request->getParameterValue(buffer, _T(""));
		if (sInviteUserAccount.empty())
		{
			break;
		}

		if (dialogInfo->m_members.exist(sInviteUserAccount))
		{
			// already exist in the dialog.
			continue;
		}

		CUserInfo::pointer inviteUserInfo;
		if (!getUserInfo(accountInfo, sInviteUserAccount, inviteUserInfo))
		{
			// ? continue;
			break;
		}

		// 1 Send the dialog members that invite account event.
		CLockMap<std::string, CUserInfo::pointer>::const_iterator iterUserInfo;
		boost::mutex::scoped_lock lockUserInfo(const_cast<boost::mutex&>(dialogInfo->m_members.mutex()));
		for (iterUserInfo=dialogInfo->m_members.begin(); iterUserInfo!=dialogInfo->m_members.end(); iterUserInfo++)
		{
			CUserInfo::pointer memberUserInfo = iterUserInfo->second;

			// Not register.
			CAccountInfo::pointer memberAccountInfo = CGC_POINTER_CAST<CAccountInfo>(gApplication->getAttribute(BMT_ACCOUNTS, memberUserInfo->getAccount()));
			if (memberAccountInfo.get() == NULL)
			//if (!gAVSProxy->m_accounts.find(memberUserInfo->getAccount(), memberAccountInfo))
			{
				// offline event
				CMessageInfo::pointer messageInfo = CMessageInfo::create(0, 0, CConversationInfo::CT_INVITE, true);
				COfflineEvent::pointer offlineEvent = COfflineEvent::create(601, CFromInfo::create(dialogInfo), accountInfo->getUserinfo(), messageInfo);
				offlineEvent->toAccount(inviteUserInfo);
				gAVSProxy->addOffEvent(memberUserInfo, offlineEvent);
				continue;
			}

			sendDiaInvite(memberAccountInfo, accountInfo->getUserinfo(), dialogInfo, inviteUserInfo);
		}
		lockUserInfo.unlock();

		// 2 Send invite useraccount the dialog members info.
		CAccountInfo::pointer inviteAccountInfo = CGC_POINTER_CAST<CAccountInfo>(gApplication->getAttribute(BMT_ACCOUNTS, sInviteUserAccount));
		if (inviteAccountInfo.get() != NULL)
		{
			// 
			sendDiaMembers(inviteAccountInfo, accountInfo->getUserinfo(), dialogInfo);
		}else
		{
			// Not register.
			// offline event
			CLockMap<std::string, CUserInfo::pointer>::const_iterator iterUserInfo;
			boost::mutex::scoped_lock lockUserInfo(const_cast<boost::mutex&>(dialogInfo->m_members.mutex()));
			for (iterUserInfo=dialogInfo->m_members.begin(); iterUserInfo!=dialogInfo->m_members.end(); iterUserInfo++)
			{
				CUserInfo::pointer memberUserInfo = iterUserInfo->second;

				CMessageInfo::pointer messageInfo = CMessageInfo::create(0, 0, CConversationInfo::CT_INVITE, true);
				COfflineEvent::pointer offlineEvent = COfflineEvent::create(601, CFromInfo::create(dialogInfo), accountInfo->getUserinfo(), messageInfo);
				offlineEvent->toAccount(memberUserInfo);
				gAVSProxy->addOffEvent(inviteUserInfo, offlineEvent);
			}
		}

		dialogInfo->m_members.insert(inviteUserInfo->getAccount(), inviteUserInfo);		
	}

	// Response
	return 0;
}
Exemplo n.º 16
0
int sendtoMsg(const cgcRequest::pointer & request, cgcAttachment::pointer attach, CAccountInfo::pointer fromAccount, CFromInfo::pointer fromInfo, CUserInfo::pointer sendtoUserInfo, long mid)
{
	BOOST_ASSERT (attach.get() != NULL);
	BOOST_ASSERT (fromAccount.get() != NULL);
	BOOST_ASSERT (fromInfo.get() != NULL);
	BOOST_ASSERT (sendtoUserInfo.get() != NULL);

	CMessageInfo::pointer offlineMessageInfo = CGC_POINTER_CAST<CMessageInfo>(gApplication->getAttribute(sendtoUserInfo->getAccount(), mid));
	CAccountInfo::pointer friendAccountInfo = CGC_POINTER_CAST<CAccountInfo>(gApplication->getAttribute(BMT_ACCOUNTS, sendtoUserInfo->getAccount()));
	if (friendAccountInfo.get() == NULL || offlineMessageInfo.get() != NULL)
	{
		// Friend is offline state.
		if (offlineMessageInfo.get() != NULL && offlineMessageInfo->total() != attach->getTotal())
		{
			gApplication->removeAttribute(sendtoUserInfo->getAccount(), mid);
			offlineMessageInfo.reset();
		}

		if (offlineMessageInfo.get() == NULL)
		{
			if (attach->getIndex() == 0)
			{
				long type = request->getParameterValue(_T("Type"), 0);
				bool bNew = request->getParameterValue2(_T("New"), true);
				offlineMessageInfo = CMessageInfo::create(mid, attach->getTotal(), (short)type, bNew);

				if (type == 3)
				{
					long imageWidth = request->getParameterValue(_T("Width"), 0);
					long imageHeight = request->getParameterValue(_T("Height"), 0);
					offlineMessageInfo->imageWH(imageWidth, imageHeight);
				}
			}else
			{
				offlineMessageInfo = CMessageInfo::create(mid, attach->getTotal());
			}

			if (attach->getIndex() + attach->getAttachSize() == attach->getTotal())
			{
				if (attach->getIndex() > 0)
					offlineMessageInfo->m_indexs.insert(attach->getIndex(), true);
				offlineMessageInfo->m_indexs.insert(attach->getTotal(), true);
			}else
			{
				int indexCount = attach->getTotal() / attach->getAttachSize();
				if (attach->getTotal() % attach->getAttachSize() > 0)
					indexCount += 1;

				for (int i=1; i<= indexCount; i++)
				{
					unsigned long index = (i==indexCount) ? attach->getTotal() : i*attach->getAttachSize();
					offlineMessageInfo->m_indexs.insert(index, true);
				}
			}

			gApplication->setAttribute(sendtoUserInfo->getAccount(), mid, offlineMessageInfo);
		}else if (attach->getIndex() == 0)
		{
			long type = request->getParameterValue(_T("Type"), 0);
			bool bNew = request->getParameterValue2(_T("New"), true);

			offlineMessageInfo->type((short)type);
			offlineMessageInfo->newflag(bNew);
			if (type == 3)
			{
				long imageWidth = request->getParameterValue(_T("Width"), 0);
				long imageHeight = request->getParameterValue(_T("Height"), 0);
				offlineMessageInfo->imageWH(imageWidth, imageHeight);
			}
		}
		offlineMessageInfo->setdata((const char*)attach->getAttachData(), attach->getAttachSize(), attach->getIndex());
		offlineMessageInfo->m_indexs.remove(attach->getIndex() + attach->getAttachSize());
		if (!offlineMessageInfo->m_indexs.empty())
		{
			// Already had data.
			return 1;
		}

		gApplication->removeAttribute(sendtoUserInfo->getAccount(), mid);

		switch (offlineMessageInfo->type())
		{
		case 3:
			{
				// Save the image.
				char * filename = new char[50];
#ifdef WIN32
				sprintf(filename, "%I64d%08ld%d", time(0), mid, ++gFileId);
#else
				sprintf(filename, "%ld%08ld%d", time(0), mid, ++gFileId);
#endif
				char filepath[256];
				sprintf(filepath, "%s/File/%s", gApplication->getAppConfPath().c_str(), filename);
				FILE * hfile = fopen(filepath, "wb");
				if (hfile == NULL)
				{
					// System error.
					delete[] filename;
					return -2;
				}
				fwrite(offlineMessageInfo->getdata(), 1, offlineMessageInfo->total(), hfile);
				fclose(hfile);

				offlineMessageInfo->filesize(offlineMessageInfo->total());
				offlineMessageInfo->setdata(filename, strlen(filename));
			}break;
		default:
			break;
		}

		COfflineEvent::pointer offlineEvent = COfflineEvent::create(501, fromInfo, fromAccount->getUserinfo(), offlineMessageInfo);
		gAVSProxy->addOffEvent(sendtoUserInfo, offlineEvent);
		return 2;
	}

	bool ret = false;
	if (attach->getIndex() == 0)
	{
		long nType = request->getParameterValue(_T("Type"), 0);
		bool bNew = request->getParameterValue2(_T("New"), true);

		if (nType == 3)
		{
			long nWidth = request->getParameterValue(_T("Width"), 0);
			long nHeight = request->getParameterValue(_T("Height"), 0);
			ret = sendMsgImage(friendAccountInfo, fromAccount->getUserinfo(), fromInfo, mid, nWidth, nHeight, nType, attach, bNew);
		}else
		{
			ret = sendMsg(friendAccountInfo, fromAccount->getUserinfo(), fromInfo, mid, nType, attach, bNew);
		}
	}else
	{
		ret = sendMsg(friendAccountInfo, fromAccount->getUserinfo(), fromInfo, mid, attach);
	}

	return 0;
}