Exemplo n.º 1
0
void EventStreamingSession::AddMessage(MessageRef message)
{
	if(m_messages.size() > 10000)
	{
		m_messages.pop_front();
	}

	IReportable *reportable = dynamic_cast<IReportable*>(message.get());
	if (!reportable) {
		return;
	}

	//For unknown reason, singlelineserialization the message can cause crash since the pointer somehow got modified somewhere else
	//This would lead to some pointed memory address become inaccessible
	//To avoid this, we create a cloned local pointer
	m_messages.push_back(reportable->Clone());
	m_semaphore.release();
}
Exemplo n.º 2
0
void TapeMsg::HandleResponse(MessageRef responseRef) {
	CStdString logMsg;

	TapeResponse* tr = dynamic_cast<TapeResponse*>(responseRef.get());
	if (!tr) {
		LOG4CXX_WARN(LOG.messaging,"Ignoring wrong response type");
		return;
	}

	if(tr->m_deleteTape && this->m_stage.Equals("ready") )
	{
		CStdString tapeFilename = this->m_fileName;

		CStdString absoluteFilename = CONFIG.m_audioOutputPath + "/" + tapeFilename;
		if (ACE_OS::unlink((PCSTR)absoluteFilename) == 0)
		{
			FLOG_INFO(LOG.messaging,"deleted tape: %s", tapeFilename);
		}
		else
		{
			FLOG_DEBUG(LOG.messaging,"could not delete tape: %s ", tapeFilename);
		}

	}
	else if(tr->m_deleteTape && this->m_stage.Equals("start") && CONFIG.m_pauseRecordingOnRejectedStart == true)
	{
		CStdString orkUid = this->m_recId;
		CStdString empty;
		CapturePluginProxy::Singleton()->PauseCapture(empty, orkUid, empty);
	}
	else 
	{
		// Tape is wanted
		if(CONFIG.m_lookBackRecording == false && CONFIG.m_allowAutomaticRecording && this->m_stage.Equals("start"))
		{
			CStdString orkuid = "", nativecallid = "", side = "";
			CapturePluginProxy::Singleton()->StartCapture(this->m_localParty, orkuid, nativecallid, side);
			CapturePluginProxy::Singleton()->StartCapture(this->m_remoteParty, orkuid, nativecallid, side);
		}
	}

}
Exemplo n.º 3
0
int EventStreamingServer::svc(void)
{
	ACE_Time_Value timeout;
	char buf[2048];
	CStdString logMsg;
	CStdString sessionId;
	int messagesSent = 0;

	ssize_t size = peer().recv(buf, 2040);

	if(size <= 5)
	{
		CStdString notFound("HTTP/1.0 404 not found\r\nContent-type: text/html\r\n\r\nNot found\r\n");
		peer().send(notFound, notFound.GetLength(), MSG_NOSIGNAL);
		return 0;
	}

	try
	{
		int startUrlOffset = 5;
		char* stopUrl = ACE_OS::strstr(buf+startUrlOffset, " HTTP");

		if(!stopUrl)
		{
			throw (CStdString("Malformed http request"));
		}

		CStdString header;
		struct tm date = {0};
		time_t now = time(NULL);
		CStdString rfc822Date;

		ACE_OS::gmtime_r(&now, &date);
		rfc822Date.Format("Tue, %.2d Nov %.4d %.2d:%.2d:%.2d GMT", date.tm_mday, (date.tm_year+1900), date.tm_hour, date.tm_min, date.tm_sec);
		header.Format("HTTP/1.1 200 OK\r\nLast-Modified:%s\r\nContent-Type:text/plain\r\n\r\n", rfc822Date);
		peer().send(header, header.GetLength(), MSG_NOSIGNAL);

		time_t startTime = time(NULL);

		sessionId = EventStreamingSingleton::instance()->GetNewSessionId() + " -";
		logMsg.Format("%s Event streaming start", sessionId);
		LOG4CXX_INFO(s_log, logMsg);

		EventStreamingSessionRef session(new EventStreamingSession());
		EventStreamingSingleton::instance()->AddSession(session);

		int sendRes = 0;
		while(sendRes >= 0)
		{
			session->WaitForMessages();

			while(session->GetNumMessages() && sendRes >= 0)
			{
				MessageRef message;

				session->GetTapeMessage(message);
				if(message.get())
				{
					CStdString msgAsSingleLineString;
					msgAsSingleLineString = message->SerializeUrl() + "\r\n";

					sendRes = peer().send(msgAsSingleLineString, msgAsSingleLineString.GetLength(), MSG_NOSIGNAL);
					if(sendRes >= 0)
					{
						messagesSent += 1;
					}
				}
			}
		}

		EventStreamingSingleton::instance()->RemoveSession(session);
		logMsg.Format("%s Stream client stop - sent %d messages in %d sec", sessionId, messagesSent, (time(NULL) - startTime));
		LOG4CXX_INFO(s_log, logMsg);
	}
	catch (CStdString& e)
	{
		CStdString error("HTTP/1.0 404 not found\r\nContent-type: text/html\r\n\r\nError\r\n");
		error = error + e + "\r\n";
		LOG4CXX_ERROR(s_log, e);
		peer().send(error, error.GetLength(), MSG_NOSIGNAL);
	}

	return 0;
}