Example #1
0
void androidRead(const char* pFileName, char** ppContent, unsigned int* pSize) {
	assert( gActivity->assetManager );

	AAsset* pFile = AAssetManager_open(gActivity->assetManager, pFileName,
	                                   AASSET_MODE_STREAMING);

	if (pFile != NULL) {

		off_t fileSize = AAsset_getLength(pFile);

		std::string path = androidGetPath(pFileName);
		char* pData = new char[fileSize];
		AAsset_read(pFile, pData, fileSize);

		*ppContent = new char[fileSize];

		memcpy(*ppContent, pData, fileSize);
		*pSize = fileSize;

		FLOG_DEBUG("File %s length %d", pFileName, *pSize);
		delete pData;

		AAsset_close(pFile);
	}
}
Example #2
0
Animator::Animator(const aiScene* scene) :
	mTimeSinceStartSeconds(0.0) {
	mAnimationsBufferData.reserve(FILLWAVE_MAX_BONES);

	GLuint numBones = 0;

	for (GLuint j = 0; j < scene->mNumMeshes; j++) {
		for (GLuint i = 0; i < scene->mMeshes[j]->mNumBones; i++) {
			mBones.push_back(std::make_unique<Bone>(scene->mMeshes[j]->mBones[i]));
			numBones++;
		}
	}

	if (numBones > FILLWAVE_MAX_BONES) {
		FLOG_FATAL(
		   "Crater can handle maximum %d bones. The model contains %d bones.",
		   FILLWAVE_MAX_BONES, numBones);
	}

	for (GLuint k = 0; k < scene->mNumAnimations; k++) {
		FLOG_DEBUG("Animation %d creation", k);
		mAnimations.push_back(std::make_unique<Animation>(scene->mAnimations[k]));
	}

	/* Init node tree after bones are added */
	mSceneInverseMatrix = glm::inverse(
	                         assimpToGlmMat4(scene->mRootNode->mTransformation));
	mRootAnimationNode = initNode(scene->mRootNode);
}
Example #3
0
inline void Model::initAnimations(const aiScene* scene) {
	if (scene->HasAnimations()) {
		mAnimator = new Animator(scene);
		FLOG_DEBUG("attached TimedBoneUpdateCallback to model");
		this->attachHierarchyCallback(std::make_unique<TimedBoneUpdateCallback>(this));
	}
}
Example #4
0
void Scene::moveCursor(glm::vec2 position) {
	if (mCursor) {
		mCursor->move(position);
	} else {
		FLOG_DEBUG("No cursor set");
	}
}
Example #5
0
bool androidExtract( const std::string& name ) {
	const char* pFile = name.c_str();
	std::string newPath = androidGetPath(pFile);
	AAssetDir* a;
	if ( androidExtracted(name.c_str()) ) {
		FLOG_DEBUG("File %s already extracted", name.c_str());
		return true;
	}

	AAsset* asset = AAssetManager_open(gActivity->assetManager, name.c_str(),
	                                   AASSET_MODE_STREAMING);
	std::string assetContent;

	if (asset != NULL) {
		// Find size
		off_t assetSize = AAsset_getLength(asset);

		// Prepare input buffer
		assetContent.resize(assetSize);

		// Store input buffer
		AAsset_read(asset, &assetContent[0], assetSize);

		// Close
		AAsset_close(asset);

		// Prepare output buffer
		std::ofstream assetExtracted(newPath.c_str(),
		                             std::ios::out | std::ios::binary);
		if (!assetExtracted) {
			FLOG_ERROR("File %s not extracted", newPath.c_str());
			return false;
		}

		// Write output buffer into a file
		assetExtracted.write(assetContent.c_str(), assetSize);
		assetExtracted.close();

		FLOG_DEBUG("File extracted");
		return true;
	} else {
		FLOG_ERROR("File %s not extracted. Returning empty string", name.c_str());
		return false;
	}
}
Example #6
0
bool androidExtractAll() {
	AAssetDir* assetDir = AAssetManager_openDir(gActivity->assetManager, "");
	const char* filename = (const char*)NULL;
	std::string assetContent;
	while ((filename = AAssetDir_getNextFileName(assetDir)) != NULL) {
		std::string newPath = androidGetPath(filename);
		AAsset* asset = AAssetManager_open(gActivity->assetManager, filename,
		                                   AASSET_MODE_STREAMING);
		FLOG_DEBUG("File %s opened for extraction ...", filename );
		// Find size
		off_t assetSize = AAsset_getLength(asset);

		// Prepare input buffer
		assetContent.resize(assetSize);

		// Store input buffer
		AAsset_read(asset, &assetContent[0], assetSize);

		// Close
		AAsset_close(asset);

		// Check if file exists
		std::ifstream f(newPath.c_str());
		if (f.good()) {
			f.close();
			FLOG_DEBUG("Asset %s already extracted", filename);
		} else {
			// Prepare output buffer
			std::ofstream assetExtracted(newPath.c_str(),
			                             std::ios::out | std::ios::binary);
			if (!assetExtracted) {
				FLOG_ERROR("File %s not extracted", newPath.c_str());
				return false;
			}

			// Write output buffer into a file
			assetExtracted.write(assetContent.c_str(), assetSize);
			assetExtracted.close();

			FLOG_DEBUG("File %s extracted", filename);
		}
	}
	return true;
	AAssetDir_close(assetDir);
}
Example #7
0
void Model::setActiveAnimation(GLint animationID) {
	if (mAnimator->getAnimations() > animationID) {
		mActiveAnimation = animationID;
	} else {
		FLOG_ERROR("There is no animation for slot: %d", animationID);
		FLOG_DEBUG("Maximum number of animations: %d",
		           mAnimator->getAnimations());
	}
}
Example #8
0
void Scene::updateRenderer() {
	if (mRenderer->mFlagReload) {
		FLOG_DEBUG("Renderer update");
		mRenderer->clear();
		if (mSkybox) {
			mRenderer->mSkybox = mSkybox.get();
		} else {
			mRenderer->mSkybox = nullptr;
		}
		for (auto& it : mChildren) {
			it->updateRenderer(*(mRenderer.get()));
		}
		mRenderer->mFlagReload = false;
	} else {
		FLOG_DEBUG("Renderer waiting for update");
		mRenderer->mFlagReload = isAttachedDetached();
	}
}
Example #9
0
static
void* write_log(void* arg)
{
    printf("writing thread id = %lu startup\n", pthread_self());
    int num = *((int*)arg);
    int last_miss_count = buff_full_count;
    // divide total msg into some groups
    int max_num_per_group = 5000;
    int group = num / max_num_per_group;
    int sleep_step = max_num_per_group;
    printf("tid=%lu, max_num_per_group:%d, group:%d, last_miss_count:%d, sleep_step:%d\n",
            pthread_self(), max_num_per_group, group, last_miss_count, sleep_step);

    unsigned long long start = ftime_gettime();
    int i = 0, j = 0;
    for ( i = 0; i < group; i++ ) {
        if ( log_mode == FLOG_ASYNC_MODE ) {
            last_miss_count = buff_full_count;
        }

        int step = 0;
        for ( j = 0; j < max_num_per_group; ++j, ++step ) {
            FLOG_DEBUG(log_handler, "%s", log_str);

            if ( log_mode == FLOG_ASYNC_MODE && (step == sleep_step) ) {
                step = 0;
                usleep(1);
            }
        }

        if ( log_mode == FLOG_ASYNC_MODE ) {
            int current_miss_count = buff_full_count;
            int diff = current_miss_count - last_miss_count;

            if ( diff > 0 ) {
                sleep_step /= 2;
                if ( sleep_step == 0 ) sleep_step = 1;
            } else {
                sleep_step += 250;
                if ( sleep_step > max_num_per_group ) sleep_step = max_num_per_group;
            }

            if ( diff ) {
                printf("tid=%lu, group_id:%d, last_miss_count:%d, diff:%d, sleep_step:%d\n",
                        pthread_self(), i, last_miss_count, diff, sleep_step);
            }
        }
    }

    unsigned long long end = ftime_gettime();
    unsigned long long diff_usec = end - start;
    printf("tid=%lu, call interface time cost (usec):%llu, writen msg:%d, final:%f count/s\n", 
            pthread_self(), diff_usec, num, (double)num / ((double)diff_usec / 1000000));

    pthread_exit(NULL);
}
Example #10
0
pProgram ProgramManager::get(const std::string& name) {
	for (auto& it : mProgramObjects) {
		if (it->mName == name) {
			return it->mProgram;
		}
	}
	FLOG_DEBUG("Program %s not found in manager. Returning empty pointer",
			name.c_str());
	return pProgram();
}
Example #11
0
void Texture2D::reload() {
	FLOG_DEBUG("Reload");
	Texture::reload();
	for (GLuint i = 0; i < mHowMany; i++) {
		bind(i);
		setParameters(mParameters);
		sendData();
		generateMipMaps();
//      unbind();
	}
}
Example #12
0
void Programmable::addEffect(pIEffect effect) {
	auto _find_function = [effect](pIEffect & m) -> bool {return m == effect;};
	auto it = std::remove_if(mEffects.begin(), mEffects.end(), _find_function);
	if (it != mEffects.end()) {
		FLOG_DEBUG("Effect already added");
		return;
	}
	mEffects.push_back(effect);
	mProgram->use();
	effect->startAction(mProgram);
	core::Program::disusePrograms();
}
Example #13
0
bool androidExtracted(const char* pFile) {
	FILE* file = ::fopen( androidGetPath(pFile).c_str(), "rb");
	if (!file) {
		AAsset* asset = AAssetManager_open(gActivity->assetManager, pFile,
		                                   AASSET_MODE_UNKNOWN);
		if (!asset) {
			FLOG_ERROR("Could not find %s in asset manager", pFile);
		} else {
			FLOG_DEBUG("%s is not extracted", pFile);
		}
		return false;
	} else {
		::fclose(file);
		return true;
	}
}
Example #14
0
SizedBufferRef HandleIpFragment(IpHeaderStruct* ipHeader)
{
	const time_t now = time(NULL);
	const int timeoutSec = 60;
	static time_t lastCheck = 0;
	static FragmentMap fragmentMap;

	// Delete previous fragments older than timeoutSec 
	if (now-lastCheck >= timeoutSec) {
		std::list <FragmentMap::iterator> toBeDeleted; 
		for (FragmentMap::iterator it=fragmentMap.begin(); it!=fragmentMap.end(); ++it) {
			if (now - it->second->lastUpdate() >= timeoutSec) 
				toBeDeleted.push_back(it);
		}
		if (toBeDeleted.size()) {
			for (std::list <FragmentMap::iterator>::iterator it=toBeDeleted.begin(); it!=toBeDeleted.end();++it) {
				fragmentMap.erase(*it);
			} 
			FLOG_WARN(s_log,"%d fragmented packets older than %u seconds has been removed from the map", toBeDeleted.size(), timeoutSec);
		}
		lastCheck = now;
	}

	FLOG_DEBUG(s_log,"Recieved fragment with packet id:%u, offset:%u, payload length:%u", ipHeader->packetId(), ipHeader->offset(), ipHeader->payloadLen());
	FragmentMap::iterator it = fragmentMap.find(ipHeader->packetId());
	if (it == fragmentMap.end()) { 
		it = fragmentMap.insert(std::make_pair(ipHeader->packetId(), FragmentationAlgorithmRef(new FRAGMENTATION_ALGORITHM()))).first;
	}
	FragmentationAlgorithmRef algorithm = it->second;
	algorithm->addFragment(ipHeader);

	if (algorithm->drop()) {
		fragmentMap.erase(it);
		FLOG_WARN(s_log,"Dropping fragmented packet data with id:%u", ipHeader->packetId());
	} 

	if (algorithm->isComplete()) {
		fragmentMap.erase(it);
		IpHeaderStruct *header = reinterpret_cast<IpHeaderStruct*>(algorithm->packetData()->get());
		FLOG_INFO(s_log, "Reassembled fragmented packet with id:%u, total payload length:%u", header->packetId(), header->payloadLen());
		return algorithm->packetData(); 
	}
	return SizedBufferRef(); // By default return empty ref
}
Example #15
0
void androidReadToString(const char* pFileName, std::string& fileContent) {
	assert( gActivity->assetManager );

	AAsset* pFile = AAssetManager_open(gActivity->assetManager, pFileName,
	                                   AASSET_MODE_UNKNOWN);

	if (pFile != NULL) {
		off_t fileSize = AAsset_getLength(pFile);

		fileContent.resize(fileSize);
		char* pData = new char[fileSize];
		AAsset_read(pFile, &fileContent[0], fileSize);

		AAsset_close(pFile);
		FLOG_DEBUG("File %s found", pFileName);
	} else {
		FLOG_ERROR("File %s not found", pFileName);
	}
}
Example #16
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);
		}
	}

}
Example #17
0
void    _test_log(){
    system("rm -f ./test_log.log");

    FLOG_DEBUG(log_handler, "debug log test\n");
    FLOG_ERROR(log_handler, "error log test\n");
    flog_set_level(LOG_LEVEL_ERROR);
    sleep(2);   // wait for log system

    int fd = open("test_log.log", O_RDONLY);
    FTU_ASSERT_GREATER_THAN_INT(0, fd);

    char assert_info[100];
    memset(assert_info, 0, 100);
    int bytes_read = read(fd, assert_info, 100);
    FTU_ASSERT_GREATER_THAN_INT(0, bytes_read);

    printf("read log info:%s\n", assert_info);
    char* ptr = strstr(assert_info, "error log test");
    printf("find ptr=%p\n", ptr);
    FTU_ASSERT_EXPRESS(ptr!=NULL);

    close(fd);
}
Example #18
0
inline void RendererDR::initGeometryShading() {
	GLint MaxPatchVertices = 0;
	glGetIntegerv(GL_MAX_PATCH_VERTICES, &MaxPatchVertices);
	FLOG_DEBUG("Max supported patch vertices %d\n", MaxPatchVertices);
	glPatchParameteri(GL_PATCH_VERTICES, 3);
}
Example #19
0
bool TrySipInvite(EthernetHeaderStruct* ethernetHeader, IpHeaderStruct* ipHeader, UdpHeaderStruct* udpHeader, u_char* udpPayload, u_char* packetEnd)
{
	CStdString logMsg;
	bool result = false;
	bool drop = false;
	CStdString sipMethod;

	int sipLength = ntohs(udpHeader->len) - sizeof(UdpHeaderStruct);
	char* sipEnd = (char*)udpPayload + sipLength;

	if (DLLCONFIG.m_ipFragmentsReassemble == false && sipEnd > (char*)packetEnd && ipHeader->offset() == 0) {
		FLOG_DEBUG(s_sipExtractionLog, "Will try to process incomplete first fragment with id:%u",ipHeader->packetId());
		sipEnd = (char*)packetEnd;
	}

	if(sipLength < 3 || sipEnd > (char*)packetEnd)
	{
		drop = true;	// packet too short
	}
	else if(memcmp(SIP_METHOD_INVITE, (void*)udpPayload, SIP_METHOD_INVITE_SIZE) == 0)
	{
		sipMethod = SIP_METHOD_INVITE;
	}
	else if(memcmp(SIP_METHOD_ACK, (void*)udpPayload, SIP_METHOD_ACK_SIZE) == 0)
	{
		sipMethod = SIP_METHOD_ACK;
	}
	else if((DLLCONFIG.m_sipTreat200OkAsInvite == true) && (memcmp(SIP_RESPONSE_200_OK, (void*)udpPayload, SIP_RESPONSE_200_OK_SIZE) == 0))
	{
		sipMethod = SIP_METHOD_200_OK;
		LOG4CXX_DEBUG(s_sipExtractionLog, "TrySipInvite: packet matches 200 OK and SipTreat200OkAsInvite is enabled");
	}
	else if((DLLCONFIG.m_sipDetectSessionProgress == true) && (memcmp(SIP_RESPONSE_SESSION_PROGRESS, (void*)udpPayload, SIP_RESPONSE_SESSION_PROGRESS_SIZE) == 0))
	{
		sipMethod = SIP_RESPONSE_SESSION_PROGRESS;
	}
	else
	{
		drop = true;
	}

	if (drop == false)
	{
		result = true;

		SipInviteInfoRef info(new SipInviteInfo());
		info->m_sipMethod = sipMethod;
		char* fromField = memFindAfter("From:", (char*)udpPayload, sipEnd);
		if(!fromField)
		{
			fromField = memFindAfter("\nf:", (char*)udpPayload, sipEnd);
		}
		char* toField = memFindAfter("To:", (char*)udpPayload, sipEnd);
		if(!toField)
		{
			toField = memFindAfter("\nt:", (char*)udpPayload, sipEnd);
		}
		char* callIdField = memFindAfter("Call-ID:", (char*)udpPayload, sipEnd);
		if(!callIdField)
		{
			callIdField = memFindAfter("\ni:", (char*)udpPayload, sipEnd);
		}

		char* replacesField = memFindAfter("Replaces:", (char*)udpPayload, sipEnd);
		if(!replacesField)
		{
			replacesField = memFindAfter("\nr:", (char*)udpPayload, sipEnd);
		}

		char * dialedNumber = NULL;
		if(!(DLLCONFIG.m_sipDialedNumberFieldName.length()==0) )
		{
			dialedNumber = memFindAfter(DLLCONFIG.m_sipDialedNumberFieldName + ":", (char*)udpPayload,sipEnd);
		}

		char * sipRemoteParty = NULL;
		if(!(DLLCONFIG.m_sipRemotePartyFieldName.length()==0) )
		{
			sipRemoteParty = memFindAfter(DLLCONFIG.m_sipRemotePartyFieldName + ":", (char*)udpPayload,sipEnd);
		}

		char* contactField = memFindAfter("Contact:", (char*)udpPayload, sipEnd);
		if(!contactField)
		{
			contactField = memFindAfter("\nc:", (char*)udpPayload, sipEnd);
		}

                char * audioSdpStart = (char*) udpPayload;;
                char * audioSdpEnd   = (char*) sipEnd;;

                char* audioStart = memFindAfter("m=audio", (char*)udpPayload, sipEnd);
                char* videoStart = memFindAfter("m=video", (char*)udpPayload, sipEnd);

                if (audioStart < videoStart) {
                    audioSdpEnd = videoStart;
                }

                if (audioStart > videoStart) {
                    audioSdpStart = audioStart;
                }

		char* localExtensionField = memFindAfter(DLLCONFIG.m_sipLocalPartyFieldName, (char*)udpPayload, sipEnd);
		char* audioField = NULL;
		char* connectionAddressField = NULL;
		char* attribSendonly = memFindAfter("a=sendonly", (char*)audioSdpStart, audioSdpEnd);
		char* attribInactive = memFindAfter("a=inactive", (char*)audioSdpStart, audioSdpEnd);
		char* rtpmapAttribute = memFindAfter("\na=rtpmap:", (char*)audioSdpStart, audioSdpEnd);
		char* userAgentField = memFindAfter("\nUser-Agent:", (char*)udpPayload, sipEnd);

		if(DLLCONFIG.m_sipRequestUriAsLocalParty == true)
		{
			char* sipUriAttribute = memFindAfter("INVITE ", (char*)udpPayload, sipEnd);

			if(sipUriAttribute)
			{
				if(s_sipExtractionLog->isDebugEnabled())
				{
					CStdString uri;
					GrabLine(sipUriAttribute, sipEnd, uri);
					LOG4CXX_DEBUG(s_sipExtractionLog, "uri: " + uri);
				}

				char* sipUriAttributeEnd = memFindEOL(sipUriAttribute, sipEnd);
				char* sipUser = memFindAfter("sip:", sipUriAttribute, sipUriAttributeEnd);

				if(sipUser)
				{
					if(DLLCONFIG.m_sipReportFullAddress)
					{
						GrabSipUserAddress(sipUser, sipUriAttributeEnd, info->m_requestUri);
					}
					else
					{
						GrabSipUriUser(sipUser, sipUriAttributeEnd, info->m_requestUri);
					}
				}
				else
				{
					if(DLLCONFIG.m_sipReportFullAddress)
					{
						GrabSipUserAddress(sipUriAttribute, sipUriAttributeEnd, info->m_requestUri);
					}
					else
					{
						GrabSipUriUser(sipUriAttribute, sipUriAttributeEnd, info->m_requestUri);
					}
				}

				if(s_sipExtractionLog->isDebugEnabled())
				{
					LOG4CXX_DEBUG(s_sipExtractionLog, "extracted uri: " + info->m_requestUri);
				}
			}
		}

		if(fromField)
		{
			if(s_sipExtractionLog->isDebugEnabled())
			{
				CStdString from;
				GrabLine(fromField, sipEnd, from);
				LOG4CXX_DEBUG(s_sipExtractionLog, "from: " + from);
			}

			char* fromFieldEnd = memFindEOL(fromField, sipEnd);

			GrabSipName(fromField, fromFieldEnd, info->m_fromName);

			char* sipUser = memFindAfter("sip:", fromField, fromFieldEnd);
			if(sipUser)
			{
				if(DLLCONFIG.m_sipReportFullAddress)
				{
					GrabSipUserAddress(sipUser, fromFieldEnd, info->m_from);
				}
				else
				{
					GrabSipUriUser(sipUser, fromFieldEnd, info->m_from);
				}
				GrabSipUriDomain(sipUser, fromFieldEnd, info->m_fromDomain);
			}
			else
			{
				if(DLLCONFIG.m_sipReportFullAddress)
				{
					GrabSipUserAddress(fromField, fromFieldEnd, info->m_from);
				}
				else
				{
					GrabSipUriUser(fromField, fromFieldEnd, info->m_from);
				}
				GrabSipUriDomain(fromField, fromFieldEnd, info->m_fromDomain);
			}
		}
		if(toField)
		{
			CStdString to;
			char* toFieldEnd = GrabLine(toField, sipEnd, to);
			LOG4CXX_DEBUG(s_sipExtractionLog, "to: " + to);

			GrabSipName(toField, toFieldEnd, info->m_toName);

			char* sipUser = memFindAfter("sip:", toField, toFieldEnd);
			if(sipUser)
			{
				if(DLLCONFIG.m_sipReportFullAddress)
				{
					GrabSipUserAddress(sipUser, toFieldEnd, info->m_to);
				}
				else
				{
					GrabSipUriUser(sipUser, toFieldEnd, info->m_to);
				}
				GrabSipUriDomain(sipUser, toFieldEnd, info->m_toDomain);
			}
			else
			{
				if(DLLCONFIG.m_sipReportFullAddress)
				{
					GrabSipUserAddress(toField, toFieldEnd, info->m_to);
				}
				else
				{
					GrabSipUriUser(toField, toFieldEnd, info->m_to);
				}
				GrabSipUriDomain(toField, toFieldEnd, info->m_toDomain);
			}
			if(DLLCONFIG.m_sipGroupPickUpPattern == info->m_to)
			{
				info->m_SipGroupPickUpPatternDetected = true;
			}
		}
		if(dialedNumber)
		{
			CStdString token;
			GrabTokenSkipLeadingWhitespaces(dialedNumber, sipEnd, token);
			info->m_sipDialedNumber = token;
		}
		if(sipRemoteParty)
		{
			CStdString token;

			char* sip = memFindAfter("sip:", sipRemoteParty, sipEnd);
			if(sip)
			{
				if(DLLCONFIG.m_sipReportFullAddress)
				{
					GrabSipUserAddress(sip, sipEnd, token);
				}
				else
				{
					GrabSipUriUser(sip, sipEnd, token);
				}
			}
			else
			{
				if(DLLCONFIG.m_sipReportFullAddress)
				{
					GrabSipUserAddress(sipRemoteParty, sipEnd, token);
				}
				else
				{
					GrabSipUriUser(sipRemoteParty, sipEnd, token);
				}
			}
			info->m_sipRemoteParty = token;
		}
		if(callIdField)
		{
			GrabTokenSkipLeadingWhitespaces(callIdField, sipEnd, info->m_callId);
			audioField = memFindAfter("m=audio ", callIdField, sipEnd);
			connectionAddressField = memFindAfter("c=IN IP4 ", callIdField, sipEnd);
		}
		if(replacesField)
		{
			CStdString fieldContent;
			GrabTokenSkipLeadingWhitespaces(replacesField, sipEnd, fieldContent);
			int firstsemicoma;
			firstsemicoma = fieldContent.Find(';');
			if(firstsemicoma != -1)
			{
				info->m_replacesId = fieldContent.substr(0, firstsemicoma);
			}

			LOG4CXX_DEBUG(s_sipExtractionLog, "replaces CallId:" + info->m_replacesId);
		}
		if(localExtensionField)
		{
			CStdString localExtension;
			GrabTokenSkipLeadingWhitespaces(localExtensionField, sipEnd, localExtension);
			if(localExtension.size() > 0)
			{
				info->m_from = localExtension;
			}
		}
		if(userAgentField)
		{
			GrabTokenSkipLeadingWhitespaces(userAgentField, sipEnd, info->m_userAgent);
		}
		if(audioField)
		{
			GrabToken(audioField, sipEnd, info->m_fromRtpPort);
		}
		if(attribSendonly || attribInactive)
		{
			info->m_attrSendonly = true;
		}
		if(connectionAddressField)
		{
			CStdString connectionAddress;
			GrabToken(connectionAddressField, sipEnd, connectionAddress);
			struct in_addr fromIp;
			if(connectionAddress.size())
			{
				if(ACE_OS::inet_aton((PCSTR)connectionAddress, &fromIp))
				{
					info->m_fromRtpIp = fromIp;

					if (DLLCONFIG.m_sipDropIndirectInvite)
					{
						if((unsigned int)fromIp.s_addr != (unsigned int)ipHeader->ip_src.s_addr)
						{
							// SIP invite SDP connection address does not match with SIP packet origin
							drop =true;
						}
					}
				}
			}
		}
		if(contactField && sipMethod == SIP_METHOD_INVITE)
		{
			CStdString contact;
			char* contactFieldEnd = GrabLine(contactField, sipEnd, contact);
			LOG4CXX_DEBUG(s_sipExtractionLog, "contact: " + contact);

			GrabSipName(contactField, contactFieldEnd, info->m_contactName);

			char* sipUser = memFindAfter("sip:", contactField, contactFieldEnd);
			if(sipUser)
			{
				if(DLLCONFIG.m_sipReportFullAddress)
				{
					GrabSipUserAddress(sipUser, contactFieldEnd, info->m_contact);
				}
				else
				{
					GrabSipUriUser(sipUser, contactFieldEnd, info->m_contact);
				}
				GrabSipUriDomain(sipUser, contactFieldEnd, info->m_contactDomain);
			}
			else
			{
				if(DLLCONFIG.m_sipReportFullAddress)
				{
					GrabSipUserAddress(contactField, contactFieldEnd, info->m_contact);
				}
				else
				{
					GrabSipUriUser(contactField, contactFieldEnd, info->m_contact);
				}
				GrabSipUriDomain(contactField, contactFieldEnd, info->m_contactDomain);
			}
		}
		// SIP fields extraction
		for(std::list<CStdString>::iterator it = DLLCONFIG.m_sipExtractFields.begin(); it != DLLCONFIG.m_sipExtractFields.end(); it++)
		{
			CStdString fieldName = *it + ":";
			char* szField = memFindAfter((PSTR)(PCSTR)fieldName, (char*)udpPayload, sipEnd);
			if(szField)
			{
				CStdString field;

				// XXX
				// The line below was replaced because I experienced
				// cases where we would have a leading whitespace in the
				// tag which has been extracted.  However, since we are
				// dealing with SIP, RFC 3261, section 7.3.1 illustrates
				// that any leading whitespaces after the colon is not
				// in fact part of the header value.  Therefore, I
				// created the GrabLineSkipLeadingWhitespace() function
				// which I use in this particular case.
				//
				// Hope this is ok.
				//
				// --Gerald
				//
				//GrabLine(szField, sipEnd, field);

				GrabLineSkipLeadingWhitespace(szField, sipEnd, field);
				info->m_extractedFields.insert(std::make_pair(*it, field));
			}
		}

		if(DLLCONFIG.m_rtpReportDtmf)
		{
			if(rtpmapAttribute)
			{
				CStdString rtpPayloadType, nextToken;
				char *nextStep = NULL;

				while(rtpmapAttribute && rtpmapAttribute < sipEnd)
				{
					rtpPayloadType = "";
					GrabTokenSkipLeadingWhitespaces(rtpmapAttribute, audioSdpEnd, rtpPayloadType);
					nextToken.Format("%s ", rtpPayloadType);
					nextStep = memFindAfter((char*)nextToken.c_str(), rtpmapAttribute, audioSdpEnd);

					/* We need our "nextStep" to contain at least the length
					 * of the string "telephone-event", 15 characters */
					if(nextStep && ((sipEnd - nextStep) >= 15))
					{
						if(ACE_OS::strncasecmp(nextStep, "telephone-event", 15) == 0)
						{
							/* Our DTMF packets are indicated using
							 * the payload type rtpPayloadType */
							info->m_telephoneEventPayloadType = rtpPayloadType;
							info->m_telephoneEventPtDefined = true;
							break;
						}
					}

					rtpmapAttribute = memFindAfter("\na=rtpmap:", rtpmapAttribute, audioSdpEnd);
				}
			}
		}

		//Determine the being used codec: should be the first rtpmap
		if(sipMethod == SIP_METHOD_200_OK || sipMethod == SIP_RESPONSE_SESSION_PROGRESS)
		{
			rtpmapAttribute = memFindAfter("\na=rtpmap:", (char*)audioSdpStart, audioSdpEnd);
			if(rtpmapAttribute)
			{
				CStdString line;
				GrabLineSkipLeadingWhitespace(rtpmapAttribute, sipEnd, line);
				info->m_orekaRtpPayloadType = GetOrekaRtpPayloadTypeForSdpRtpMap(line);
			}
		}

		if((unsigned int)info->m_fromRtpIp.s_addr == 0)
		{
			// In case connection address could not be extracted, use SIP invite sender IP address
			if(DLLCONFIG.m_dahdiIntercept == true)
			{
				info->m_fromRtpIp = ipHeader->ip_dest;
			}
			else
			{
				info->m_fromRtpIp = ipHeader->ip_src;
			}
		}
		if(sipMethod == SIP_METHOD_200_OK)
		{
			info->m_senderIp = ipHeader->ip_dest;
			info->m_receiverIp = ipHeader->ip_src;
		}
		else
		{
			info->m_senderIp = ipHeader->ip_src;
			info->m_receiverIp = ipHeader->ip_dest;
		}
		info->m_originalSenderIp = ipHeader->ip_src;
		info->m_recvTime = time(NULL);
		memcpy(info->m_senderMac, ethernetHeader->sourceMac, sizeof(info->m_senderMac));
		memcpy(info->m_receiverMac, ethernetHeader->destinationMac, sizeof(info->m_receiverMac));

		if(sipMethod.Equals(SIP_METHOD_INVITE) || info->m_fromRtpPort.size())
		{
			// Only log SIP non-INVITE messages that contain SDP (i.e. with a valid RTP port)
			info->ToString(logMsg);
			logMsg = sipMethod + ": " + logMsg;
			LOG4CXX_INFO(s_sipPacketLog, logMsg);
		}

		//Sip INVITE without sdp will be reported, but other methods without sdp will not be
		if(drop == false && sipMethod == SIP_METHOD_INVITE && info->m_from.size() && info->m_to.size() && info->m_callId.size())
		{
			VoIpSessionsSingleton::instance()->ReportSipInvite(info);
		}
		else if(drop == false && info->m_fromRtpPort.size() && info->m_from.size() && info->m_to.size() && info->m_callId.size())
		{
			VoIpSessionsSingleton::instance()->ReportSipInvite(info);
		}
	}
	return result;
}
Example #20
0
Entity::~Entity() {
	detachChildren();
	FLOG_DEBUG("Entity destroyed");
}
Example #21
0
void Entity::onAttached(Entity* parent) {
	FLOG_DEBUG("Attached enity");
}
Example #22
0
void Entity::onDetached() {
	FLOG_DEBUG("Detached enity");
}