void ToolManager::addJSTool(gcRefPtr<UserCore::Item::ItemInfo> item, uint32 branchId, gcString name, gcString exe, gcString args, gcString res) { if (!item) return; auto branch = item->getBranchById(branchId); if (!branch) return; auto realBranch = gcRefPtr<UserCore::Item::BranchInfo>::dyn_cast(branch); if (!realBranch) return; bool found = false; gcRefPtr<JSToolInfo> jsinfo; BaseManager<ToolInfo>::for_each([&](gcRefPtr<ToolInfo> info) { auto temp = gcRefPtr<JSToolInfo>::dyn_cast(info); if (!temp) return; if (item->getId() == temp->getItemId() && name == info->getName() && temp->getBranchId() == branchId) { jsinfo = temp; found = true; } }); if (found) { if (!jsinfo->isRealyInstalled()) jsinfo->setExePath(exe.c_str()); return; } DesuraId toolId(m_iLastCustomToolId, DesuraId::TYPE_TOOL); m_iLastCustomToolId--; auto tool = gcRefPtr<JSToolInfo>::create(item->getId(), realBranch->getBranchId(), toolId, name, exe, args, res); realBranch->addJSTool(toolId); addItem(tool); }
SessionContext* CallTracker::createSessionContextAndSetHandle( const SipMessage& request, RouteState& routeState, bool bTrackBranchId, UtlString& sessionContextHandle ) { SessionContext *pSessionContext = 0; if( generateSessionContextHandleFromRequest( sessionContextHandle ) ) { Os::Logger::instance().log(FAC_NAT, PRI_DEBUG, "CallTracker[%zd]::createSessionContextAndSetHandle generated handle: '%s' ", mHandle, sessionContextHandle.data() ); // session context handle successfully generated - allocate a new SessionContext // object to track the session and insert it into our mSessionContextsMap. UtlString* pMapKey = new UtlString( sessionContextHandle ); pSessionContext = new SessionContext( request, mpNatTraversalRules, sessionContextHandle, mpMediaRelayToUse, mpRegDb, this ); if( pSessionContext && mSessionContextsMap.insertKeyAndValue( pMapKey, pSessionContext ) ) { // Session Context successfully inserted into our mSessionContextsMap. Encode // its handle in the RouteState to facilitate SessionContext look-ups while // processing in-dialog requests. setSessionContextHandle( routeState, sessionContextHandle ); // map the branch id of the topmost via to the Session Context handle if requested if( bTrackBranchId ) { UtlString branchId; if( getBranchId( request, 0, branchId ) ) { Os::Logger::instance().log(FAC_NAT, PRI_DEBUG, "CallTracker[%zd]::createSessionContextAndSetHandle now tracking branch Id '%s'", mHandle, branchId.data() ); mBranchIdToSessionHandleMap.destroy( &branchId ); mBranchIdToSessionHandleMap.insertKeyAndValue( new UtlString( branchId ), new UtlString( sessionContextHandle ) ) ; } } } else { delete pSessionContext; delete pMapKey; pSessionContext = 0; Os::Logger::instance().log(FAC_NAT, PRI_ERR, "CallTracker[%zd]::createSessionContextAndSetHandle failed to insert " "new session context into map. key : '%s'", mHandle, sessionContextHandle.data() ); } } else { Os::Logger::instance().log(FAC_NAT, PRI_ERR, "CallTracker[%zd]::createSessionContextAndSetHandle failed to generate new handle", mHandle ); } return pSessionContext; }
void ToolManager::addJSTool(UserCore::Item::ItemInfo* item, uint32 branchId, gcString name, gcString exe, gcString args, gcString res) { if (!item) return; UserCore::Item::BranchInfoI* branch = item->getBranchById(branchId); if (!branch) return; UserCore::Item::BranchInfo* realBranch = dynamic_cast<UserCore::Item::BranchInfo*>(branch); if (!realBranch) return; bool found = false; JSToolInfo* jsinfo = nullptr; BaseManager<ToolInfo>::for_each([&](ToolInfo* info) { auto temp = dynamic_cast<JSToolInfo*>(info); if (!temp) return; if (item->getId() == temp->getItemId() && name == info->getName() && temp->getBranchId() == branchId) { jsinfo = temp; found = true; } }); if (found) { if (!jsinfo->isRealyInstalled()) jsinfo->setExePath(exe.c_str()); return; } DesuraId toolId(m_iLastCustomToolId, DesuraId::TYPE_TOOL); m_iLastCustomToolId--; JSToolInfo* tool = new JSToolInfo(item->getId(), realBranch->getBranchId(), toolId, name, exe, args, res); realBranch->addJSTool(toolId); addItem(tool); }
void BranchInfo::processInstallScript(TiXmlElement* scriptNode) { int crc = 0; scriptNode->Attribute("crc", &crc); if (UTIL::FS::isValidFile(m_szInstallScript)) { if (crc != 0 && m_uiInstallScriptCRC == (uint32)crc) return; } else { m_szInstallScript = UTIL::OS::getAppDataPath(gcWString(L"{0}\\{1}\\install_script.js", m_ItemId.getFolderPathExtension(), getBranchId()).c_str()); } gcString base64 = scriptNode->GetText(); try { UTIL::FS::recMakeFolder(UTIL::FS::Path(m_szInstallScript, "", true)); UTIL::FS::FileHandle fh(m_szInstallScript.c_str(), UTIL::FS::FILE_WRITE); UTIL::STRING::base64_decode(base64, [&fh](const unsigned char* data, uint32 size) -> bool { fh.write((const char*)data, size); return true; }); m_uiInstallScriptCRC = crc; } catch (gcException &e) { Warning(gcString("Failed to save install script for {0} branch {1}: {2}\n", m_ItemId.toInt64(), m_uiBranchId, e)); m_szInstallScript = ""; } }