/* cPmdDaemon implement */ cPmdDaemon::cPmdDaemon( const CHAR *pDMNSvcName ) { SDB_ASSERT( pDMNSvcName, "service name can't be null!" ) ; iPmdProc::regSignalHandler() ; UINT32 len = ossStrlen( pDMNSvcName ) ; if ( len > 0 && len <= OSS_MAX_PATHSIZE ) { ossStrcpy( _procName, pDMNSvcName ) ; } else { ossStrcpy( _procName, PMDDMN_SVCNAME_DEFAULT ) ; } }
/* _pmdExternClient implement */ _pmdExternClient::_pmdExternClient( ossSocket *pSocket ) { SDB_ASSERT( pSocket, "Socket can't be NULL" ) ; _isAuthed = FALSE ; _pSocket = pSocket ; _pEDUCB = NULL ; _localPort = 0 ; _peerPort = 0 ; ossMemset( _localIP, 0, sizeof( _localIP ) ) ; ossMemset( _peerIP, 0, sizeof( _peerIP ) ) ; ossMemset( _fromIP, 0, sizeof( _fromIP ) ) ; ossMemset( _clientName, 0, sizeof( _clientName ) ) ; if ( pSocket ) { _localPort = pSocket->getLocalPort() ; _peerPort = pSocket->getPeerPort() ; pSocket->getLocalAddress( _localIP, PMD_IPADDR_LEN ) ; pSocket->getPeerAddress( _peerIP, PMD_IPADDR_LEN ) ; ossStrcpy( _fromIP, _peerIP ) ; #if defined ( SDB_ENGINE ) if ( 0 == ossStrcmp( _peerIP, "127.0.0.1" ) ) { ossIP2Str( _netFrame::getLocalAddress(), _fromIP, PMD_IPADDR_LEN ) ; } #endif // SDB_ENGINE } _makeName() ; }
_monEDUFull &operator= ( const _monEDUFull &rhs ) { _eduID = rhs._eduID ; _tid = rhs._tid ; _queueSize = rhs._queueSize ; _processEventCount = rhs._processEventCount ; ossStrcpy( _eduStatus, rhs._eduStatus ) ; ossStrcpy( _eduType, rhs._eduType ) ; ossStrcpy( _eduName, rhs._eduName ) ; _eduContextList = rhs._eduContextList ; _monApplCB = rhs._monApplCB ; _threadHdl = rhs._threadHdl ; _relatedNID = rhs._relatedNID ; _relatedTID = rhs._relatedTID ; return *this ; }
void _pmdDMNProcInfo::init() { SDB_ASSERT( sizeof(PMDDMN_SHM_TAG) <= sizeof(szTag), "share-memory-tag is out of length" ) ; if ( !isInit() ) { stat = PMDDMN_SHM_STAT_DAEMON ; pid = OSS_INVALID_PID ; cmd = PMDDMN_SHM_CMD_INVALID ; exitCode = SDB_OK ; sn = 0 ; ossStrcpy( szTag, PMDDMN_SHM_TAG ) ; } }
void _pmdExternClient::_makeName() { if ( 0 == _peerIP[ 0 ] ) { ossStrcpy( _clientName, "noip-Extern" ) ; } else if ( _username.empty() ) { ossSnprintf( _clientName, PMD_CLIENTNAME_LEN, "%s:%u-Extern", _peerIP, _peerPort ) ; } else { ossSnprintf( _clientName, PMD_CLIENTNAME_LEN, "%s@%s:%u-Extern", _username.c_str(), _peerIP, _peerPort ) ; } }
// PD_TRACE_DECLARE_FUNCTION ( SDB_GETEXECNM, "getExecutableName" ) static INT32 getExecutableName ( const CHAR * exeName , CHAR * buf , UINT32 bufSize ) { INT32 rc = SDB_OK ; PD_TRACE_ENTRY ( SDB_GETEXECNM ); SDB_ASSERT ( exeName && buf && bufSize > 0 , "invalid argument" ) ; try { string strName = exeName ; string strEnd = ".exe" ; if ( strName.length() <= strEnd.length() || 0 != strName.compare ( strName.length() - strEnd.length() , strEnd.length() , strEnd ) ) { strName += strEnd ; } if ( strName.length() >= bufSize ) { rc = SDB_INVALIDSIZE ; goto error ; } ossStrcpy ( buf , strName.c_str() ) ; } catch ( std::bad_alloc & ) { rc = SDB_OOM ; goto error ; } done : PD_TRACE_EXITRC ( SDB_GETEXECNM, rc ); return rc ; error : goto done ; }
INT32 iPmdDMNChildProc::init( ossSHMKey shmKey ) { INT32 rc = SDB_OK; UINT32 len = 0; #if defined (_WINDOWS) UINT32 keyLen = 0; #endif ossMemset( _execName, 0, sizeof( _execName) ); rc = ossGetEWD( _execName, OSS_MAX_PATHSIZE ); PD_RC_CHECK( rc, PDERROR, "failed to get working directory(rc=%d)", rc ); len = ossStrlen( _execName ); len = len + 1 + ossStrlen( getProgramName() ); #if defined (_WINDOWS) len += ossStrlen(".exe"); keyLen = ossStrlen( shmKey ); SAFE_OSS_FREE( _shmKey ); _shmKey = (CHAR *)SDB_OSS_MALLOC( keyLen + 1 ); if ( _shmKey ) { ossStrcpy( _shmKey, shmKey ); } #elif defined ( _LINUX ) _shmKey = shmKey; #endif PD_CHECK( len <= OSS_MAX_PATHSIZE, SDB_INVALIDARG, error, PDERROR, "length of working directory is longer than expected!" ); ossStrncat( _execName, OSS_FILE_SEP, 1 ); ossStrncat( _execName, getProgramName(), ossStrlen( getProgramName() ) ); #if defined (_WINDOWS) ossStrncat( _execName, ".exe", ossStrlen(".exe") ); #endif done: return rc; error: goto done; }
INT32 utilBuildFullPath( const CHAR *path, const CHAR *name, UINT32 fullSize, CHAR *full ) { INT32 rc = SDB_OK ; if ( ossStrlen( path ) + ossStrlen( name ) + 2 > fullSize ) { rc = SDB_INVALIDARG ; goto error ; } ossMemset( full, 0, fullSize ); ossStrcpy( full, path ) ; if ( '\0' != path[0] && 0 != ossStrcmp(&path[ossStrlen(path)-1], OSS_FILE_SEP ) ) { ossStrncat( full, OSS_FILE_SEP, 1 ) ; } ossStrncat( full, name, ossStrlen( name ) ) ; done: return rc ; error: goto done ; }
INT32 aggrProjectParser::addObj( const CHAR *pAlias, const bson::BSONObj &Obj, const CHAR *pCLName, qgmOPFieldVec &selectorVec, _qgmPtrTable *pTable ) { INT32 rc = SDB_OK; CHAR *pFuncBuf = NULL; #define FUNC_NAME_BUILDOBJ "buildObj" try { UINT32 nameLen = ossStrlen( FUNC_NAME_BUILDOBJ ); UINT32 paramLen = 0; UINT32 fieldNum = 0; UINT32 curPos = 0; BSONObjIterator iter( Obj ); while ( iter.more() ) { BSONElement beField = iter.next(); PD_CHECK( beField.isNumber(), SDB_INVALIDARG, error, PDERROR, "field type must be number!" ); if ( beField.number() == 0 ) { continue; } ++fieldNum; paramLen += ossStrlen(AGGR_CL_DEFAULT_ALIAS) + 1 + ossStrlen( beField.fieldName() ); } PD_CHECK( fieldNum > 0, SDB_INVALIDARG, error, PDERROR, "Can't add empty obj!" ); paramLen += ( fieldNum - 1 ); pFuncBuf = ( CHAR * )SDB_OSS_MALLOC( nameLen + 3 + paramLen ); PD_CHECK( pFuncBuf != NULL, SDB_OOM, error, PDERROR, "malloc failed(size=%d)", ( nameLen + 3 + paramLen )); ossStrcpy( pFuncBuf, FUNC_NAME_BUILDOBJ ); pFuncBuf[ nameLen ] = '('; curPos = nameLen + 1; iter = BSONObjIterator( Obj ); while ( iter.more() ) { BSONElement beField = iter.next(); if ( beField.number() == 0 ) { continue; } ossStrcpy( ( pFuncBuf + curPos ), AGGR_CL_DEFAULT_ALIAS ); curPos += ossStrlen( AGGR_CL_DEFAULT_ALIAS ); pFuncBuf[ curPos ] = '.'; curPos += 1; ossStrcpy( ( pFuncBuf + curPos ), beField.fieldName() ); curPos += ossStrlen( beField.fieldName() ); if ( fieldNum > 1 ) { pFuncBuf[ curPos ] = ','; curPos += 1; } --fieldNum; } pFuncBuf[ curPos ] = ')'; curPos += 1; pFuncBuf[ curPos ] = 0; qgmField slValAttr; qgmField slValRelegation; rc = pTable->getOwnField( pFuncBuf, slValAttr ); PD_RC_CHECK( rc, PDERROR, "failed to get the field(%s)", pFuncBuf ); qgmDbAttr slVal( slValRelegation, slValAttr ); qgmField slAlias; rc = pTable->getOwnField( pAlias, slAlias ); PD_RC_CHECK( rc, PDERROR, "failed to get the field(%s)", pAlias ); qgmOpField selector; selector.alias = slAlias; selector.value = slVal; selector.type = SQL_GRAMMAR::FUNC; selectorVec.push_back( selector ); } catch ( std::exception &e ) { PD_CHECK( SDB_INVALIDARG, SDB_INVALIDARG, error, PDERROR, "failed to add function-field, received unexpected error:%s", e.what() ); } done: SDB_OSS_FREE( pFuncBuf ); return rc; error: goto done; }
INT32 aggrProjectParser::addFunc( const CHAR *pAlias, const bson::BSONObj &funcObj, const CHAR *pCLName, qgmOPFieldVec &selectorVec, _qgmPtrTable *pTable ) { INT32 rc = SDB_OK; CHAR *pFuncBuf = NULL; try { const CHAR *pFuncName = funcObj.firstElementFieldName(); PD_CHECK( AGGR_KEYWORD_PREFIX == pFuncName[0], SDB_INVALIDARG, error, PDERROR, "failed to parse selector field(%s), function name must begin with \"$\"", pFuncName ); const CHAR *pFuncParam = funcObj.firstElement().valuestr(); PD_CHECK( AGGR_KEYWORD_PREFIX == pFuncParam[0], SDB_INVALIDARG, error, PDERROR, "failed to parse selector field(%s), parameter must begin with \"$\"", pFuncParam ); qgmField slValAttr; qgmField slValRelegation; UINT32 nameLen = ossStrlen(&(pFuncName[1])); UINT32 paramLen = ossStrlen(AGGR_CL_DEFAULT_ALIAS) + 1 + ossStrlen(&(pFuncParam[1])); UINT32 curPos = 0; pFuncBuf = ( CHAR * )SDB_OSS_MALLOC( nameLen + 3 + paramLen ); PD_CHECK( pFuncBuf != NULL, SDB_OOM, error, PDERROR, "malloc failed(size=%d)", (nameLen + 3 + paramLen) ); ossStrcpy( pFuncBuf, &(pFuncName[1]) ); pFuncBuf[ nameLen ]='('; curPos = nameLen + 1; ossStrcpy( ( pFuncBuf + curPos), AGGR_CL_DEFAULT_ALIAS ); curPos += ossStrlen(AGGR_CL_DEFAULT_ALIAS); pFuncBuf[ curPos ] = '.'; curPos += 1; ossStrcpy( ( pFuncBuf + curPos ), &(pFuncParam[1]) ); curPos += ossStrlen(&(pFuncParam[1])); pFuncBuf[ curPos ] = ')'; curPos += 1; pFuncBuf[ curPos ] = 0; rc = pTable->getOwnField( pFuncBuf, slValAttr ); PD_RC_CHECK( rc, PDERROR, "failed to get the field(%s)", pFuncBuf ); qgmDbAttr slVal( slValRelegation, slValAttr ); qgmField slAlias; rc = pTable->getOwnField( pAlias, slAlias ); qgmOpField selector; selector.alias = slAlias; selector.value = slVal; selector.type = SQL_GRAMMAR::FUNC; selectorVec.push_back( selector ); } catch ( std::exception &e ) { PD_CHECK( SDB_INVALIDARG, SDB_INVALIDARG, error, PDERROR, "failed to add function-field, received unexpected error:%s", e.what() ); } done: if ( pFuncBuf != NULL ) { SDB_OSS_FREE( pFuncBuf ); } return rc; error: goto done; }
// PD_TRACE_DECLARE_FUNCTION ( SDB_OSSLCEXEC, "ossLocateExecutable" ) INT32 ossLocateExecutable ( const CHAR * refPath , const CHAR * exeName , CHAR * buf , UINT32 bufSize ) { INT32 rc = SDB_OK ; PD_TRACE_ENTRY ( SDB_OSSLCEXEC ); INT32 dirLen = 0 ; UINT32 exeLen = 0 ; const CHAR * separator = NULL ; CHAR newExeName[ OSS_MAX_PATHSIZE + 1 ] = {0} ; ossMemset ( newExeName , 0 , sizeof ( newExeName ) ) ; if ( ! ( refPath && exeName && buf && bufSize > 0 ) ) { rc = SDB_INVALIDARG ; goto error ; } #ifdef _WINDOWS rc = getExecutableName ( exeName , newExeName , sizeof ( newExeName ) ) ; if ( rc != SDB_OK ) { goto error ; } #else if ( ossStrlen ( exeName ) >= sizeof ( newExeName ) ) { rc = SDB_INVALIDSIZE ; goto error ; } ossStrncpy ( newExeName , exeName, sizeof ( newExeName ) ) ; #endif exeLen = ossStrlen ( newExeName ) ; separator = ossStrrchr ( refPath , OSS_PATH_SEP_CHAR ) ; if ( ! separator ) { if ( exeLen >= bufSize ) { rc = SDB_INVALIDSIZE ; goto error ; } ossStrcpy ( buf , newExeName ) ; goto done ; } dirLen = separator - refPath ; // length without separator if ( dirLen + exeLen + 1 >= bufSize ) { rc = SDB_INVALIDSIZE ; goto error ; } ossStrncpy ( buf , refPath , dirLen + 1 ) ; // 1 for separator buf[dirLen + 1] = '\0' ; ossStrncat ( buf , newExeName , exeLen ) ; done : PD_TRACE_EXITRC ( SDB_OSSLCEXEC, rc ); return rc ; error : goto done ; }