示例#1
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;
}
示例#2
0
bool sendCoGroupInfo(cgcResponse::pointer response, unsigned int coId, CCoGroupInfo::pointer cogroupInfo, bool isMyCoGroup)
{
	BOOST_ASSERT (response.get() != 0);
	BOOST_ASSERT (cogroupInfo.get() != 0);

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

	response->lockResponse();
	response->setParameter(cgcParameter::create(_T("CoId"), (long)coId));
	response->setParameter(cgcParameter::create(_T("Id"), cogroupInfo->groupid()));
	response->setParameter(cgcParameter::create(_T("Type"), (long)cogroupInfo->type()));
	response->setParameter(cgcParameter::create(_T("Name"), cogroupInfo->name()));
	if (cogroupInfo->parentgroup().get() != 0)
		response->setParameter(cgcParameter::create(_T("ParentId"), cogroupInfo->parentgroup()->groupid()));
	response->setParameter(cgcParameter::create2(_T("MyCoGroup"), isMyCoGroup));
	response->sendResponse(0, 111);
	return true;
}
示例#3
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;
}
示例#4
0
// sendDataGroupInfo
bool sendDataGroupInfo(cgcResponse::pointer response, CDataGroup::pointer dataGroup)
{
	BOOST_ASSERT (response.get() != 0);
	BOOST_ASSERT (dataGroup.get() != 0);

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

	response->lockResponse();
	response->setParameter(cgcParameter::create(_T("GroupId"), dataGroup->groupid()));
	response->setParameter(cgcParameter::create(_T("Name"), dataGroup->name()));
	if (dataGroup->parentgroup().get() != 0)
		response->setParameter(cgcParameter::create(_T("ParentId"), dataGroup->parentgroup()->groupid()));
	response->sendResponse(0, 151);
	return true;
}
示例#5
0
bool sendDiaInvite(cgcResponse::pointer response, CUserInfo::pointer fromUser, CDialogInfo::pointer dialogInfo, CUserInfo::pointer inviteUserInfo)
{
	BOOST_ASSERT (response.get() != 0);
	BOOST_ASSERT (fromUser.get() != 0);
	BOOST_ASSERT (dialogInfo.get() != 0);
	BOOST_ASSERT (inviteUserInfo.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->setParameter(cgcParameter::create(_T("UA0"), inviteUserInfo->getAccount()));
	response->sendResponse(0, 601);
	return true;
}
示例#6
0
bool sendCompanyInfo(cgcResponse::pointer response, CCompanyInfo::pointer companyInfo)
{
	BOOST_ASSERT (response.get() != 0);
	BOOST_ASSERT (companyInfo.get() != 0);

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

	response->lockResponse();
	response->setParameter(cgcParameter::create(_T("Id"), companyInfo->id()));
	response->setParameter(cgcParameter::create(_T("Name"), companyInfo->name()));
	response->sendResponse(0, 110);
	return true;
}
示例#7
0
// sendDataInfo
bool sendDataInfo(cgcResponse::pointer response, CDataInfo::pointer dataInfo)
{
	BOOST_ASSERT (response.get() != 0);
	BOOST_ASSERT (dataInfo.get() != 0);
	BOOST_ASSERT (dataInfo->parentgroup() != 0);

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

	response->lockResponse();
	response->setParameter(cgcParameter::create(_T("GrouId"), dataInfo->parentgroup()->groupid()));
	response->setParameter(cgcParameter::create(_T("DataId"), dataInfo->dataid()));
	response->setParameter(cgcParameter::create(_T("Name"), dataInfo->name()));
	response->setParameter(cgcParameter::create(_T("Desc"), dataInfo->desc()));
	// ???
	//response->setParameter(cgcParameter::create(_T("AttachName"), dataId));
	response->sendResponse(0, 152);
	return true;
}
示例#8
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;
}
示例#9
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;
}
示例#10
0
bool sendCoGroupUserInfo(cgcResponse::pointer response, unsigned int coId, unsigned cogroupId, CUserInfoPointer userInfo)
{
	BOOST_ASSERT (response.get() != 0);
	BOOST_ASSERT (userInfo.get() != 0);

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

	response->lockResponse();
	response->setParameter(cgcParameter::create(_T("CoId"), (long)coId));
	//response->setParameter(cgcParameter::create(_T("Id"), cogroupId));

	int index = 0;
	CLockMap<unsigned int, CCoGroupInfo::pointer>::const_iterator iterCoGroup;
	boost::mutex::scoped_lock lockCoGroupInfo(const_cast<boost::mutex&>(userInfo->m_cogroups.mutex()));
	for (iterCoGroup=userInfo->m_cogroups.begin(); iterCoGroup!=userInfo->m_cogroups.end(); iterCoGroup++)
	{
		CCoGroupInfo::pointer cogroupInfo = iterCoGroup->second;

		char buffer[10];
		sprintf(buffer, "Id%d", index++);
		response->setParameter(cgcParameter::create(buffer, (long)cogroupInfo->groupid()));
	}

	response->setParameter(cgcParameter::create(_T("Account"), userInfo->getAccount()));
	response->setParameter(cgcParameter::create(_T("Name"), userInfo->getUserName()));
	response->setParameter(cgcParameter::create(_T("Nick"), userInfo->getNick()));
	response->setParameter(cgcParameter::create(_T("Gender"), (long)userInfo->getGender()));
	response->setParameter(cgcParameter::create(_T("Ext"), userInfo->getExtension()));
	response->setParameter(cgcParameter::create(_T("Phone"), userInfo->getPhone()));
	response->setParameter(cgcParameter::create(_T("Mobile"), userInfo->getMobile()));
	response->setParameter(cgcParameter::create(_T("Email"), userInfo->getEmail()));
	//response->setParameter(cgcParameter::create(_T("Desc"), userInfo->getDescription()));
	response->setParameter(cgcParameter::create(_T("LineState"), (long)userInfo->getLineState()));
	response->sendResponse(0, 112);
	return true;
}
示例#11
0
// sendOfflineEvent
bool sendOfflineEvent(cgcResponse::pointer response, COfflineEvent::pointer offlineEvent)
{
	BOOST_ASSERT (response.get() != 0);
	BOOST_ASSERT (offlineEvent.get() != 0);

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

	switch (offlineEvent->getEvent())
	{
	case 501:
		{
			CMessageInfo::pointer messageInfo = offlineEvent->getMessage();
			BOOST_ASSERT (messageInfo.get() != 0);

			long messageid = messageInfo->messageid();
			short msgtype = messageInfo->type();
			bool newflag = messageInfo->newflag();
			size_t sizeSended = 0;
			size_t tosendSize = 0;

			switch (msgtype)
			{
			case 1:
				{
					size_t toSendSizeTotal = messageInfo->total();
					cgc::cgcAttachment::pointer attach(cgcAttachment::create());
					attach->setName("text");
					attach->setTotal(toSendSizeTotal);
					while (sizeSended < toSendSizeTotal)
					{
						tosendSize = (short)(toSendSizeTotal-sizeSended) > MAX_PACKET_SIZE ? MAX_PACKET_SIZE : (toSendSizeTotal-sizeSended);
						attach->setAttach((const unsigned char*)messageInfo->getdata()+sizeSended, tosendSize);
						attach->setIndex(sizeSended);

						if (attach->getIndex() == 0)
						{
							if (!sendMsg(response, offlineEvent->getFromAccount(), offlineEvent->fromInfo(), messageid, msgtype, attach, newflag, offlineEvent->getMessage()->msgtime()))
							{
								return false;
							}
						}else
						{
							if (!sendMsg(response, offlineEvent->getFromAccount(), offlineEvent->fromInfo(), messageid, attach))
							{
								return false;
							}
						}
						sizeSended += tosendSize;

#ifdef WIN32
						Sleep(5);
#else
						usleep(5000);
#endif
					}
				}break;
			case 3:
				{
					std::string filename = messageInfo->tostring();
					size_t nFilesize = messageInfo->filesize();
					char filepath[256];
					sprintf(filepath, "%s/File/%s", gApplication->getAppConfPath().c_str(), filename.c_str());
					FILE * hfile = fopen(filepath, "rb");
					if (hfile == NULL)
					{
						return false;
					}
					unsigned char * imageBuffer = new unsigned char[nFilesize+1];
					size_t imageSize = fread(imageBuffer, 1, nFilesize, hfile);
					fclose(hfile);
					namespace fs = boost::filesystem;
					fs::path pathFile(filepath, fs::native);
					fs::remove(pathFile);

					if (imageSize == 0)
					{
						delete[] imageBuffer;
						return false;
					}

					cgc::cgcAttachment::pointer attach(cgcAttachment::create());
					attach->setName("image");
					attach->setTotal(imageSize);
					while (sizeSended < imageSize)
					{
						tosendSize = (short)(imageSize-sizeSended) > MAX_PACKET_SIZE ? MAX_PACKET_SIZE : (imageSize-sizeSended);
						attach->setAttach((const unsigned char*)imageBuffer+sizeSended, tosendSize);
						attach->setIndex(sizeSended);

						if (attach->getIndex() == 0)
						{
							long nWidth = messageInfo->imageWidth();
							long nHeight = messageInfo->imageHeight();
							if (!sendMsgImage(response, offlineEvent->getFromAccount(), offlineEvent->fromInfo(), messageid, nWidth, nHeight, msgtype, attach, newflag, offlineEvent->getMessage()->msgtime()))
							{
								delete[] imageBuffer;
								return false;
							}
						}else
						{
							if (!sendMsg(response, offlineEvent->getFromAccount(), offlineEvent->fromInfo(), messageid, attach))
							{
								delete[] imageBuffer;
								return false;
							}
						}
						sizeSended += tosendSize;

#ifdef WIN32
						Sleep(5);
#else
						usleep(5000);
#endif
					}
					delete[] imageBuffer;
				}break;
			default:
				break;
			}

		}break;
	default:
		{
			if (offlineEvent->fromInfo()->fromType() == CFromInfo::FromDialogInfo)
			{
				response->setParameter(cgcParameter::create(_T("DID"), offlineEvent->fromInfo()->fromDialog()->dialogId()));
			}
			response->setParameter(cgcParameter::create(_T("FromAccount"), offlineEvent->getFromAccount()->getAccount()));
			response->sendResponse(0, offlineEvent->getEvent());
		}break;
	}
	return true;
}
示例#12
0
extern "C" int CGC_API MsgRequest(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 mid = request->getParameterValue(_T("MID"), 0);
	const tstring & sFriendAccount = request->getParameterValue(_T("SendTo"), _T(""));
	if (sFriendAccount.empty()) return -1;
	long type = request->getParameterValue(_T("Type"), 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;
	}

	CAccountInfo::pointer friendAccountInfo = CGC_POINTER_CAST<CAccountInfo>(gApplication->getAttribute(BMT_ACCOUNTS, sFriendAccount));
	if (friendAccountInfo.get() == NULL)
	//if (!gAVSProxy->m_accounts.find(sFriendAccount, friendAccountInfo))
	{
		// SentTo Account offline state;
		return 17;
	}

	long newmid = ++gCurrentMessageId;

	if (type == 11)
	{
		const tstring & filename = request->getParameterValue(_T("Name"), _T(""));
		if (filename.empty()) return -1;
		long filesize = request->getParameterValue(_T("Size"), 0);
		if (filesize <= 0) return -1;

		response->lockResponse();
		response->setParameter(cgcParameter::create(_T("MID"), mid));
		response->setParameter(cgcParameter::create(_T("NMID"), newmid));
		response->sendResponse();

		sendFileRequest(friendAccountInfo, accountInfo->getUserinfo(), newmid, filename, filesize);
	}else// if ()
	{
		response->lockResponse();
		response->setParameter(cgcParameter::create(_T("MID"), mid));
		response->setParameter(cgcParameter::create(_T("NMID"), newmid));
		response->sendResponse();

		sendMsgRequest(friendAccountInfo, accountInfo->getUserinfo(), newmid, type);
	}

	// Response
	return 0;
}