//--------------------------------------------------------------------------- // createProcess //--------------------------------------------------------------------------- int invoke_program(const char *command_line, StringBuffer& response) { char buffer[128]; FILE *fp; /* Run the command so that it writes its output to a pipe. Open this * pipe with read text attribute so that we can read it * like a text file. */ if (getEspLogLevel()>8) { DBGLOG("command_line=<%s>", command_line); } #ifdef CHECK_LINUX_COMMAND return -1; #else if( (fp = popen( command_line, "r" )) == NULL ) return -1; /* Read pipe until end of file. End of file indicates that * the stream closed its standard out (probably meaning it * terminated). */ while ( !feof(fp) ) if ( fgets( buffer, 128, fp) ) response.append( buffer ); /* Close pipe and print return value of CHKDSK. */ return pclose( fp ); #endif }
virtual void flushTraceSummary() { StringBuffer logstr; logstr.appendf("activeReqs=").append(m_active).append(';'); logstr.append("user="******"exception@%dms=%d;", m_exceptionTime, m_exceptionCode); } StringBuffer value; value.append("total=").appendulong(m_processingTime).append("ms"); if (m_hasException || (getEspLogLevel() > LogNormal)) { m_traceValues.append(value.str()); if (m_traceValues.length()) { ForEachItemIn(idx, m_traceValues) logstr.append(m_traceValues.item(idx)).append(";"); m_traceValues.kill(); } } else { logstr.appendf("%s;", value.str()); } DBGLOG("TxSummary[%s]", logstr.str()); }
bool CLoggingManager::saveToTankFile(IEspUpdateLogRequestWrap& logRequest, CLogRequestInFile* reqInFile) { if (!logFailSafe.get()) { ERRLOG("CLoggingManager::saveToTankFile: logFailSafe not configured."); return false; } unsigned startTime = (getEspLogLevel()>=LogNormal) ? msTick() : 0; StringBuffer GUID; logFailSafe->GenerateGUID(GUID, NULL); reqInFile->setGUID(GUID); reqInFile->setOption(logRequest.getOption()); StringBuffer reqBuf; Owned<IEspUpdateLogRequestWrap> logRequestFiltered = logContentFilter.filterLogContent(&logRequest); if (!serializeLogRequestContent(logRequestFiltered, GUID, reqBuf)) { ERRLOG("CLoggingManager::saveToTankFile: failed in serializeLogRequestContent()."); return false; } logFailSafe->AddACK(GUID);//Ack this logging request since the task will be done as soon as the next line is called. logFailSafe->Add(GUID, reqBuf, reqInFile); ESPLOG(LogNormal, "LThread:saveToTankFile: %dms\n", msTick() - startTime); return true; }
virtual void flushTraceSummary() { if (m_txSummary) { if (!m_hasException && (getEspLogLevel() <= LogNormal)) m_txSummary->clear(); updateTraceSummaryHeader(); m_txSummary->append("total", m_processingTime, "ms"); } }
bool CCassandraLogAgent::executeSimpleSelectStatement(const char* st, unsigned& resultValue) { CassandraStatement statement(cassSession->prepareStatement(st, getEspLogLevel()>LogNormal)); CassandraFuture future(cass_session_execute(cassSession->querySession(), statement)); future.wait("execute"); CassandraResult result(cass_future_get_result(future)); if (cass_result_row_count(result) == 0) return false; resultValue = getUnsignedResult(NULL, getSingleResult(result)); return true; }
bool SecHandler::authorizeSecFeature(const char * pszFeatureUrl, const char* UserID, const char* CompanyID, SecAccessFlags & required_access,bool bCheckTrial,int DebitUnits, SecUserStatus & user_status) { if(m_user.get()==0) throw MakeStringException(500,"No user defined in SecHandler::authorizeSecFeature"); user_status = SecUserStatus_Unknown; //lets see is our primary user allowed to access the resource. bool bPrimaryAccessAllowed = authorizeSecFeature(pszFeatureUrl,required_access); if(bPrimaryAccessAllowed==false) return false; //by now the prime ISecUser will have been fully initialized. We should be able //..to tell its status. if(m_user->getStatus() == SecUserStatus_FreeTrial || m_user->getStatus() == SecUserStatus_Rollover) { bool bReturn = true; if(bCheckTrial==true) bReturn = authorizeTrial(*m_user.get(),pszFeatureUrl,required_access); user_status = m_user->getStatus(); return bReturn; } //m_user should be the user who logs in. This may not be the user whose resource we are looking for. //if userid and companyid are blank then we must be authenticating a normal user.. so continue on.. if(UserID==0 || *UserID=='\0' || CompanyID==0 || *CompanyID=='\0') return bPrimaryAccessAllowed; //see do we have a cached version of our secondary user..... //.. if we do then check it... Owned<ISecUser> pSecondaryUser; pSecondaryUser.set(m_secmgr->findUser(UserID)); if(pSecondaryUser.get()== NULL) { pSecondaryUser.setown(m_secmgr->createUser(UserID)); if (!pSecondaryUser) return false; pSecondaryUser->setRealm(CompanyID); bool bSecondaryAccessAllowed = m_secmgr->initUser(*pSecondaryUser.get()); if(bSecondaryAccessAllowed==false) return false; m_secmgr->addUser(*pSecondaryUser.get()); } // currently not the responsibility of this service to authenticate the secondary user. //we just need to chech and see if on a free trial whether they should be allowed continue if(pSecondaryUser->getStatus() == SecUserStatus_FreeTrial || pSecondaryUser->getStatus() == SecUserStatus_Rollover) { //if the primary user is inhouse then we only want to check for a free trial // if a debit units value has been passed in. if(m_user->getStatus() == SecUserStatus_Inhouse && DebitUnits == 0) { if (getEspLogLevel() >= LogNormal) DBGLOG("Inhouse primary user and DebitUtits are 0 so not decrementing free trial"); return true; } if (DebitUnits > 0) pSecondaryUser->setPropertyInt("debitunits",DebitUnits); bool bReturn = true; if(bCheckTrial==true) bReturn = authorizeTrial(*pSecondaryUser,pszFeatureUrl,required_access); user_status = pSecondaryUser->getStatus(); return bReturn; } return true; }
void CPooledHttpThread::threadmain() { TimeSection timing("CPooledHttpThread::threadmain()"); Owned<CEspHttpServer> httpserver; Owned<ISecureSocket> secure_sock; if(m_is_ssl && m_ssctx && m_persistentHandler == nullptr) { secure_sock.setown(m_ssctx->createSecureSocket(m_socket.getLink(), getEspLogLevel())); int res = 0; try { res = secure_sock->secure_accept(); if(res < 0) { return; } } catch(IException* e) { StringBuffer emsg; e->errorMessage(emsg); IERRLOG("%s", emsg.str()); return; } catch(...) { return; } m_socket.set(secure_sock); httpserver.setown(new CEspHttpServer(*m_socket, m_apport, false, getMaxRequestEntityLength())); } else { httpserver.setown(new CEspHttpServer(*m_socket, m_apport, false, getMaxRequestEntityLength())); } httpserver->setShouldClose(m_shouldClose); time_t t = time(NULL); initThreadLocal(sizeof(t), &t); bool keepAlive = false; try { ESP_TIME_SECTION("CPooledHttpThread::threadmain: httpserver->processRequest()"); httpserver->processRequest(); if (m_persistentHandler == nullptr) { keepAlive = !m_shouldClose && m_apport->queryProtocol()->persistentEnabled() && httpserver->persistentEligible(); if (keepAlive) m_apport->queryProtocol()->addPersistent(m_socket.get()); } else { keepAlive = !m_shouldClose && httpserver->persistentEligible(); m_persistentHandler->doneUsing(m_socket, keepAlive); } } catch (IException *e) { StringBuffer estr; IERRLOG("Exception(%d, %s) in CPooledHttpThread::threadmain().", e->errorCode(), e->errorMessage(estr).str()); e->Release(); } catch(...) { IERRLOG("General Exception - in CPooledHttpThread::threadmain()."); } clearThreadLocal(); try { if (m_socket != nullptr) { if (!keepAlive) m_socket->shutdown(SHUTDOWN_WRITE); m_socket.clear(); } } catch (IException *e) { StringBuffer estr; IERRLOG("Exception(%d, %s) - CPooledHttpThread::threadmain(), closing socket.", e->errorCode(), e->errorMessage(estr).str()); e->Release(); } catch(...) { IERRLOG("General Exception - CPooledHttpThread::threadmain(), closing socket."); } }
bool CHttpThread::onRequest() { keepAlive = false; ActiveRequests recording; Owned<CEspHttpServer> httpserver; Owned<ISecureSocket> secure_sock; if(m_is_ssl && m_ssctx && m_persistentHandler == nullptr) { ESPLOG(LogMax, "Creating secure socket"); secure_sock.setown(m_ssctx->createSecureSocket(m_socket.getLink(), getEspLogLevel())); int res = 0; try { ESPLOG(LogMax, "Accepting from secure socket"); res = secure_sock->secure_accept(); if(res < 0) { ESPLOG(LogMin, "Error accepting from secure socket"); return false; } } catch(IException* e) { StringBuffer emsg; e->errorMessage(emsg); IERRLOG("%s", emsg.str()); return false; } catch(...) { IERRLOG("Unknown exception accepting from secure socket"); return false; } ESPLOG(LogMax, "Request from secure socket"); m_socket.set(secure_sock); httpserver.setown(new CEspHttpServer(*secure_sock.get(), m_apport, m_viewConfig, getMaxRequestEntityLength())); } else { httpserver.setown(new CEspHttpServer(*m_socket, m_apport, m_viewConfig, getMaxRequestEntityLength())); } time_t t = time(NULL); initThreadLocal(sizeof(t), &t); httpserver->setIsSSL(m_is_ssl); httpserver->setShouldClose(m_shouldClose); httpserver->processRequest(); if (m_persistentHandler == nullptr) { keepAlive = !m_shouldClose && m_apport->queryProtocol()->persistentEnabled() && httpserver->persistentEligible(); if (keepAlive) m_apport->queryProtocol()->addPersistent(m_socket.get()); } else { keepAlive = !m_shouldClose && httpserver->persistentEligible(); m_persistentHandler->doneUsing(m_socket, keepAlive); } clearThreadLocal(); return false; }
void CCassandraLogAgent::executeSimpleStatement(const char* st) { CassandraStatement statement(cassSession->prepareStatement(st, getEspLogLevel()>LogNormal)); CassandraFuture future(cass_session_execute(cassSession->querySession(), statement)); future.wait("execute"); }