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 CSotpRtpSession::doRtpData(const tagSotpRtpDataHead& pRtpDataHead,const cgcAttachment::pointer& pAttackment, const cgcRemote::pointer& pcgcRemote)
{
	if (pAttackment.get()==NULL || !pAttackment->isHasAttach())
		return false;
	CSotpRtpRoom::pointer pRtpRoom = GetRtpRoom(ntohll(pRtpDataHead.m_nRoomId),false);
	if (pRtpRoom.get()==NULL)
		return false;

	CSotpRtpSource::pointer pRtpSrcSource = pRtpRoom->GetRtpSource(ntohll(pRtpDataHead.m_nSrcId));
	if (pRtpSrcSource.get()==NULL)
		return false;

	// 
	pRtpSrcSource->CaculateMissedPackets(pRtpDataHead,pcgcRemote);
	if (this->m_bServerMode)
	{
		// save as wait for SOTP_RTP_COMMAND_DATA_REQUEST msg
		//const uint16 nSeq = ntohs(pRtpDataHead.m_nSeq);
		//if ((nSeq%20)==1)
		//{
		//	printf("*** doRtpData seq=%d,srcid=%lld\n",nSeq,ntohll(pRtpDataHead.m_nSrcId));
		//}
		CSotpRtpReliableMsg * pRtpMsgIn = m_pRtpMsgPool.Get();
		memcpy(&pRtpMsgIn->m_pRtpDataHead,&pRtpDataHead,SOTP_RTP_DATA_HEAD_SIZE);
		pRtpMsgIn->m_pAttachment = pAttackment;
		CSotpRtpReliableMsg * pRtpMsgOut = NULL;
		const bool bExistSeq = pRtpSrcSource->UpdateReliableQueue(pRtpMsgIn, &pRtpMsgOut);
		m_pRtpMsgPool.Set(pRtpMsgOut);
		if (!bExistSeq)
			pRtpRoom->BroadcastRtpData(pRtpDataHead,pAttackment);
		//else
		//	printf("*** doRtpData exist seq=%d,srcid=%lld\n",nSeq,ntohll(pRtpDataHead.m_nSrcId));
	}else
	{
		const_cast<tagSotpRtpDataHead&>(pRtpDataHead).m_nRoomId = ntohll(pRtpDataHead.m_nRoomId);
		const_cast<tagSotpRtpDataHead&>(pRtpDataHead).m_nSeq = ntohs(pRtpDataHead.m_nSeq);
		const_cast<tagSotpRtpDataHead&>(pRtpDataHead).m_nSrcId = ntohll(pRtpDataHead.m_nSrcId);
		const_cast<tagSotpRtpDataHead&>(pRtpDataHead).m_nTimestamp = ntohl(pRtpDataHead.m_nTimestamp);
		const_cast<tagSotpRtpDataHead&>(pRtpDataHead).m_nTotleLength = ntohl(pRtpDataHead.m_nTotleLength);
		const_cast<tagSotpRtpDataHead&>(pRtpDataHead).m_nUnitLength = ntohs(pRtpDataHead.m_nUnitLength);
		const_cast<tagSotpRtpDataHead&>(pRtpDataHead).m_nIndex = ntohs(pRtpDataHead.m_nIndex);
		pRtpSrcSource->PushRtpData(pRtpDataHead,pAttackment);
		pRtpSrcSource->GetWholeFrame(m_pRtpFrameCallback,m_nCbUserData);
	}

	return true;
}
Exemplo n.º 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;
}
Exemplo n.º 4
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;
}