_pmdAddrPair( const string &hostname, const string &svcname ) { ossStrncpy( _host, hostname.c_str(), OSS_MAX_HOSTNAME ) ; _host[ OSS_MAX_HOSTNAME ] = 0 ; ossStrncpy( _service, svcname.c_str(), OSS_MAX_SERVICENAME ) ; _service[ OSS_MAX_SERVICENAME ] = 0 ; }
INT32 _utilESActionUpdate::_outputSrcData( CHAR *buffer, INT32 size, INT32 &length ) const { INT32 rc = SDB_OK ; UINT32 writePos = 0 ; const CHAR *upsertStr = ",\"doc_as_upsert\":true" ; UINT32 upsertLen = ossStrlen( upsertStr ) ; if ( size < (INT32)( _srcDataLen + BULK_UPDATE_PREFIX_LEN + upsertLen + BULK_UPDATE_SUFFIX_LEN + 1 ) ) { rc = SDB_INVALIDARG ; PD_LOG( PDERROR, "Buffer size[ %d ] is too small", size ) ; goto error ; } ossStrncpy( buffer, BULK_UPDATE_PREFIX, BULK_UPDATE_PREFIX_LEN ) ; writePos = BULK_UPDATE_PREFIX_LEN ; ossStrncpy( buffer + writePos, _sourceData, _srcDataLen ) ; writePos += _srcDataLen ; ossStrncpy( buffer + writePos, upsertStr, upsertLen ) ; writePos += upsertLen ; ossStrncpy( buffer + writePos, BULK_UPDATE_SUFFIX, BULK_UPDATE_SUFFIX_LEN ) ; writePos += BULK_UPDATE_SUFFIX_LEN ; buffer[ writePos ] = '\n' ; length = writePos + 1 ; done: return rc ; error: goto done ; }
// PD_TRACE_DECLARE_FUNCTION ( SDB_OSSGETSYMBNFA, "ossGetSymbolNameFromAddress" ) void ossGetSymbolNameFromAddress( OSS_INSTRUCTION_PTR pInstruction, CHAR *pName, size_t nameSize, UINT32_64 *pOffset ) { PD_TRACE_ENTRY ( SDB_OSSGETSYMBNFA ); Dl_info dlip ; UINT32_64 offset = 0 ; BOOLEAN bErr = false ; INT32 rc = 0 ; if ( ( ! pInstruction ) || ( ! pName ) ) { bErr = true ; goto exit ; } rc = dladdr( (void *)pInstruction, &dlip ) ; if ( rc && dlip.dli_sname ) { ossStrncpy( pName, dlip.dli_sname, nameSize ) ; if ( dlip.dli_saddr ) { offset = (UINT32_64)pInstruction - (UINT32_64)dlip.dli_saddr ; } } else if ( rc && dlip.dli_fname ) { ossStrncpy( pName, dlip.dli_fname, nameSize ) ; offset = (UINT32_64)pInstruction - (UINT32_64)dlip.dli_fbase ; } else { bErr = true ; } exit : if ( bErr ) { if ( pInstruction ) { ossSnprintf(pName, nameSize, "0x" OSS_PRIXPTR, (UINT32_64)pInstruction) ; } else { ossStrncpy (pName, OSS_UNKNOWN_STACKFRAME_NAME, nameSize); } } if ( pOffset ) { *pOffset = offset ; } PD_TRACE_EXIT ( SDB_OSSGETSYMBNFA ); }
_ossModuleHandle::_ossModuleHandle ( const CHAR *pModuleName, const CHAR *pLibraryPath, UINT32 dlOpenMode ) : _isInitialized(FALSE), _moduleHandle(OSS_MINVALIDHANDLE), _flags(dlOpenMode) { ossStrncpy ( _moduleName, pModuleName, sizeof(_moduleName) ) ; if ( pLibraryPath ) ossStrncpy ( _libPath, pLibraryPath, sizeof(_libPath) ) ; else ossMemset ( _libPath, 0, sizeof(_libPath) ) ; }
// PD_TRACE_DECLARE_FUNCTION ( SDB___PMDEDUCB_DUMPINFO, "_pmdEDUCB::dumpInfo" ) void _pmdEDUCB::dumpInfo ( monEDUSimple &simple ) { PD_TRACE_ENTRY ( SDB___PMDEDUCB_DUMPINFO ); ossScopedLock _lock ( &_mutex, SHARED ) ; ossMemset ( &simple._eduStatus, 0, MON_EDU_STATUS_SZ ) ; ossMemset ( &simple._eduType, 0, MON_EDU_TYPE_SZ ) ; ossMemset ( &simple._eduName, 0, MON_EDU_NAME_SZ ) ; simple._eduID = _eduID ; simple._tid = _tid ; ossStrncpy ( simple._eduStatus, getEDUStatusDesp(_status), MON_EDU_STATUS_SZ ) ; ossStrncpy ( simple._eduType, getEDUName (_eduType), MON_EDU_TYPE_SZ ) ; ossStrncpy ( simple._eduName, _Name, MON_EDU_NAME_SZ ) ; PD_TRACE_EXIT ( SDB___PMDEDUCB_DUMPINFO ); }
restSessionInfo* _pmdController::newSessionInfo( const string & userName, UINT32 localIP ) { restSessionInfo *newSession = SDB_OSS_NEW restSessionInfo ; if( !newSession ) { PD_LOG( PDERROR, "Alloc rest session info failed" ) ; goto error ; } _ctrlLatch.get() ; newSession->_attr._sessionID = ossPack32To64( localIP, _sequence++ ) ; ossStrncpy( newSession->_attr._userName, userName.c_str(), SESSION_USER_NAME_LEN ) ; _mapSessions[ _makeID( newSession ) ] = newSession ; _add2UserMap( userName, newSession ) ; newSession->_inNum.inc() ; _ctrlLatch.release() ; newSession->lock() ; done: return newSession ; error: goto done ; }
// PD_TRACE_DECLARE_FUNCTION ( SDB__DMSSU_DUMPINFO, "_dmsStorageUnit::dumpInfo" ) void _dmsStorageUnit::dumpInfo ( vector<CHAR*> &collectionList, BOOLEAN sys ) { PD_TRACE_ENTRY( SDB__DMSSU_DUMPINFO ) ; _pDataSu->_metadataLatch.get_shared() ; dmsStorageData::COLNAME_MAP_IT it = _pDataSu->_collectionNameMap.begin() ; while ( it != _pDataSu->_collectionNameMap.end() ) { if ( !sys && dmsIsSysCLName( it->first ) ) { ++it ; continue ; } CHAR *pBuffer = (CHAR*)SDB_OSS_MALLOC ( DMS_COLLECTION_NAME_SZ + 1 ) ; if ( !pBuffer ) { PD_LOG( PDERROR, "Allocate memory failed" ) ; goto error ; } ossStrncpy ( pBuffer, it->first, DMS_COLLECTION_NAME_SZ ) ; pBuffer[ DMS_COLLECTION_NAME_SZ ] = 0 ; collectionList.push_back ( pBuffer ) ; ++it ; } done : _pDataSu->_metadataLatch.release_shared() ; PD_TRACE_EXIT ( SDB__DMSSU_DUMPINFO ) ; return ; error : goto done ; }
// The caller is responsible to free memory restSessionInfo* _pmdController::newSessionInfo( const string & userName, UINT32 localIP ) { // memory will be freed in releaseSessionInfo ( manual release )and // _checkSession ( timeout release ) restSessionInfo *newSession = SDB_OSS_NEW restSessionInfo ; if( !newSession ) { PD_LOG( PDERROR, "Alloc rest session info failed" ) ; goto error ; } // get lock _ctrlLatch.get() ; newSession->_attr._sessionID = ossPack32To64( localIP, _sequence++ ) ; ossStrncpy( newSession->_attr._userName, userName.c_str(), SESSION_USER_NAME_LEN ) ; // add to session map _mapSessions[ _makeID( newSession ) ] = newSession ; // add to user session map _add2UserMap( userName, newSession ) ; // attach session newSession->_inNum.inc() ; // release lock _ctrlLatch.release() ; // The session will be locked once it's created, and the caller will // start working on the session. Once the work is done, the session will // be unlocked ( detached or destroyed ) newSession->lock() ; done: return newSession ; error: goto done ; }
_optAccessPlan ( _dmsStorageUnit *su, const CHAR *collectionName, const BSONObj &query, const BSONObj &orderBy, const BSONObj &hint ) :_useCount(0) { ossMemset( _idxName, 0, sizeof( _idxName ) ) ; ossMemset ( _collectionName, 0, sizeof(_collectionName) ) ; ossStrncpy ( _collectionName, collectionName, sizeof(_collectionName) - 1 ) ; _isInitialized = FALSE ; _scanType = TBSCAN ; _indexCBExtent = DMS_INVALID_EXTENT ; _indexLID = DMS_INVALID_EXTENT ; _su = su ; _query = query.copy() ; _orderBy = orderBy.copy() ; _hint = hint.copy() ; _hintFailed = FALSE ; _predList = NULL ; _hashValue = hash(query, orderBy, hint) ; _apm = NULL ; _sortRequired = FALSE ; _isAutoPlan = FALSE ; }
_dmsReorgUnit::_dmsReorgUnit ( CHAR *pFileName, SINT32 pageSize ) { _pCurrentExtent = NULL ; ossMemset ( _fileName, 0, sizeof(_fileName) ) ; ossStrncpy ( _fileName, pFileName, OSS_MAX_PATHSIZE ) ; _pageSize = pageSize ; }
// PD_TRACE_DECLARE_FUNCTION ( SDB__DMSSU, "_dmsStorageUnit::_dmsStorageUnit" ) _dmsStorageUnit::_dmsStorageUnit ( const CHAR *pSUName, UINT32 sequence, INT32 pageSize, INT32 lobPageSize ) :_apm(this), _pDataSu( NULL ), _pIndexSu( NULL ), _pLobSu( NULL ) { PD_TRACE_ENTRY ( SDB__DMSSU ) ; SDB_ASSERT ( pSUName, "name can't be null" ) ; if ( 0 == pageSize ) { pageSize = DMS_PAGE_SIZE_DFT ; } if ( 0 == lobPageSize ) { lobPageSize = DMS_DEFAULT_LOB_PAGE_SZ ; } CHAR dataFileName[DMS_SU_FILENAME_SZ + 1] = {0} ; CHAR idxFileName[DMS_SU_FILENAME_SZ + 1] = {0} ; _storageInfo._pageSize = pageSize ; _storageInfo._lobdPageSize = lobPageSize ; ossStrncpy( _storageInfo._suName, pSUName, DMS_SU_NAME_SZ ) ; _storageInfo._suName[DMS_SU_NAME_SZ] = 0 ; _storageInfo._sequence = sequence ; _storageInfo._secretValue = ossPack32To64( (UINT32)time(NULL), (UINT32)(ossRand()*239641) ) ; ossSnprintf( dataFileName, DMS_SU_FILENAME_SZ, "%s.%d.%s", _storageInfo._suName, sequence, DMS_DATA_SU_EXT_NAME ) ; ossSnprintf( idxFileName, DMS_SU_FILENAME_SZ, "%s.%d.%s", _storageInfo._suName, sequence, DMS_INDEX_SU_EXT_NAME ) ; _pDataSu = SDB_OSS_NEW dmsStorageData( dataFileName, &_storageInfo ) ; if ( _pDataSu ) { _pIndexSu = SDB_OSS_NEW dmsStorageIndex( idxFileName, &_storageInfo, _pDataSu ) ; } if ( NULL != _pDataSu && NULL != _pIndexSu ) { ossMemset( dataFileName, 0, sizeof( dataFileName ) ) ; ossMemset( idxFileName, 0 , sizeof( idxFileName ) ) ; ossSnprintf( dataFileName, DMS_SU_FILENAME_SZ, "%s.%d.%s", _storageInfo._suName, _storageInfo._sequence, DMS_LOB_META_SU_EXT_NAME ) ; ossSnprintf( idxFileName, DMS_SU_FILENAME_SZ, "%s.%d.%s", _storageInfo._suName, _storageInfo._sequence, DMS_LOB_DATA_SU_EXT_NAME ) ; _pLobSu = SDB_OSS_NEW dmsStorageLob( dataFileName, idxFileName, &_storageInfo, _pDataSu ) ; } PD_TRACE_EXIT ( SDB__DMSSU ) ; }
// PD_TRACE_DECLARE_FUNCTION ( SDB__DMSSU_DUMPINFO2, "_dmsStorageUnit::dumpInfo" ) void _dmsStorageUnit::dumpInfo ( set<_monStorageUnit> &storageUnitList, BOOLEAN sys ) { monStorageUnit su ; const dmsStorageUnitHeader *dataHeader = _pDataSu->getHeader() ; PD_TRACE_ENTRY ( SDB__DMSSU_DUMPINFO2 ) ; if ( !sys && dmsIsSysCSName( CSName() ) ) { goto done ; } ossMemset ( su._name, 0, sizeof ( su._name ) ) ; ossStrncpy ( su._name, CSName(), DMS_SU_NAME_SZ ) ; su._pageSize = getPageSize() ; su._lobPageSize = getLobPageSize() ; su._sequence = CSSequence() ; su._numCollections = dataHeader->_numMB ; su._collectionHWM = dataHeader->_MBHWM ; su._size = totalSize() ; su._CSID = CSID() ; su._logicalCSID = LogicalCSID() ; storageUnitList.insert ( su ) ; done : PD_TRACE_EXIT ( SDB__DMSSU_DUMPINFO2 ) ; }
CHAR *getGroupName ( CHAR *pBuffer, UINT32 size ) const { if ( !pBuffer || 0 == size ) return NULL; ossStrncpy ( pBuffer, _groupName, size ) ; pBuffer[ size - 1 ] = 0 ; return pBuffer ; }
INT32 clsStrategy2String( INT32 sty, CHAR * str, UINT32 len ) { INT32 rc = SDB_OK ; switch ( sty ) { case CLS_SYNC_NONE : ossStrncpy( str, CLS_SYNC_NONE_STR, len - 1 ) ; break ; case CLS_SYNC_KEEPNORMAL : ossStrncpy( str, CLS_SYNC_KEEPNORMAL_STR, len -1 ) ; break ; case CLS_SYNC_KEEPALL : ossStrncpy( str, CLS_SYNC_KEEPALL_STR, len -1 ) ; break ; default : str[0] = 0 ; rc = SDB_INVALIDARG ; } str[ len -1 ] = 0 ; return rc ; }
// PD_TRACE_DECLARE_FUNCTION ( SDB___PMDEDUCB_DUMPINFO2, "_pmdEDUCB::dumpInfo" ) void _pmdEDUCB::dumpInfo ( monEDUFull &full ) { PD_TRACE_ENTRY ( SDB___PMDEDUCB_DUMPINFO2 ); ossScopedLock _lock ( &_mutex, SHARED ) ; ossMemset ( &full._eduStatus, 0, MON_EDU_STATUS_SZ ) ; ossMemset ( &full._eduType, 0, MON_EDU_TYPE_SZ ) ; ossMemset ( &full._eduName, 0, MON_EDU_NAME_SZ ) ; full._eduID = _eduID ; full._tid = _tid ; full._processEventCount = _processEventCount ; full._queueSize = _queue.size() ; ossStrncpy ( full._eduStatus, getEDUStatusDesp(_status), MON_EDU_STATUS_SZ ) ; ossStrncpy ( full._eduType, getEDUName (_eduType), MON_EDU_TYPE_SZ ) ; ossStrncpy ( full._eduName, _Name, MON_EDU_NAME_SZ ) ; full._monApplCB = _monApplCB ; full._threadHdl = _threadHdl ; full._eduContextList = _contextList ; PD_TRACE_EXIT ( SDB___PMDEDUCB_DUMPINFO2 ); }
INT32 setProgramName( const CHAR* name ) { INT32 rc = SDB_OK ; if ( !name || ossStrlen( name ) > OSS_MAX_PATHSIZE + 1 ) { rc = SDB_INVALIDARG ; goto error ; } ossStrncpy ( progName, name, ossStrlen( name ) ) ; done : return rc ; error : goto done ; }
void reset ( const CHAR *clName = NULL, UINT16 mbID = DMS_INVALID_MBID, UINT32 clLID = DMS_INVALID_CLID, UINT32 attr = 0 ) { INT32 i = 0 ; ossMemset( _collectionName, 0, sizeof( _collectionName ) ) ; if ( clName ) { ossStrncpy( _collectionName, clName, DMS_COLLECTION_NAME_SZ ) ; } if ( DMS_INVALID_MBID != mbID ) { DMS_SET_MB_INUSE( _flag ) ; } else { DMS_SET_MB_FREE( _flag ) ; } _blockID = mbID ; _firstExtentID = DMS_INVALID_EXTENT ; _lastExtentID = DMS_INVALID_EXTENT ; _numIndexes = 0 ; for ( i = 0 ; i < _max ; ++i ) { _deleteList[i].reset() ; } for ( i = 0 ; i < DMS_COLLECTION_MAX_INDEX ; ++i ) { _indexExtent[i] = DMS_INVALID_EXTENT ; } _logicalID = clLID ; _indexHWCount = 0 ; _attributes = attr ; _loadFirstExtentID = DMS_INVALID_EXTENT ; _loadLastExtentID = DMS_INVALID_EXTENT ; _mbExExtentID = DMS_INVALID_EXTENT ; _totalRecords = 0 ; _totalDataPages = 0 ; _totalIndexPages = 0 ; _totalDataFreeSpace = 0 ; _totalIndexFreeSpace = 0 ; _totalLobPages = 0 ; ossMemset( _pad, 0, sizeof( _pad ) ) ; }
INT32 _utilESBulkActionBase::setSourceData( const CHAR *sourceData, INT32 length, BOOLEAN copy ) { INT32 rc = SDB_OK ; if ( !sourceData || length <=0 ) { rc = SDB_INVALIDARG ; PD_LOG( PDERROR, "Invalid source data or length" ) ; goto error ; } if ( _sourceData ) { if ( _ownData ) { SDB_OSS_FREE( _sourceData ) ; _ownData = FALSE ; } _sourceData = NULL ; } if ( copy ) { _sourceData = (CHAR *)SDB_OSS_MALLOC( length ) ; if ( !_sourceData ) { rc = SDB_OOM ; PD_LOG( PDERROR, "Allocate memory for source data failed, requested" " size[ %d ]", length ) ; goto error ; } ossStrncpy( _sourceData, sourceData, length ) ; _ownData = TRUE ; } else { _sourceData = (CHAR *)sourceData ; } _srcDataLen = length ; done: return rc ; error: goto done ; }
// PD_TRACE_DECLARE_FUNCTION ( SDB__DMSSU_DUMPINFO1, "_dmsStorageUnit::dumpInfo" ) void _dmsStorageUnit::dumpInfo ( set<_monCollection> &collectionList, BOOLEAN sys ) { dmsMB *mb = NULL ; dmsMBStatInfo *mbStat = NULL ; PD_TRACE_ENTRY ( SDB__DMSSU_DUMPINFO1 ) ; _pDataSu->_metadataLatch.get_shared() ; dmsStorageData::COLNAME_MAP_IT it = _pDataSu->_collectionNameMap.begin() ; while ( it != _pDataSu->_collectionNameMap.end() ) { monCollection collection ; if ( !sys && dmsIsSysCLName( it->first ) ) { ++it ; continue ; } mb = &_pDataSu->_dmsMME->_mbList[it->second] ; mbStat = &_pDataSu->_mbStatInfo[it->second] ; ossMemset ( collection._name, 0, sizeof(collection._name) ) ; ossStrncpy ( collection._name, CSName(), DMS_SU_NAME_SZ ) ; ossStrncat ( collection._name, ".", 1 ) ; ossStrncat ( collection._name, mb->_collectionName, DMS_COLLECTION_NAME_SZ ) ; collection.addDetails ( CSSequence(), mb->_numIndexes, mb->_blockID, mb->_flag, mb->_logicalID, mbStat->_totalRecords, mbStat->_totalDataPages, mbStat->_totalIndexPages, mbStat->_totalLobPages, mbStat->_totalDataFreeSpace, mbStat->_totalIndexFreeSpace ) ; collectionList.insert ( collection ) ; ++it ; } _pDataSu->_metadataLatch.release_shared() ; PD_TRACE_EXIT ( SDB__DMSSU_DUMPINFO1 ) ; }
INT32 _utilESActionDelete::_outputSrcData( CHAR *buffer, INT32 size, INT32 &length ) const { INT32 rc = SDB_OK ; if ( size < _srcDataLen + 1 ) { rc = SDB_INVALIDARG ; PD_LOG( PDERROR, "Buffer size[ %d ] is too small", size ) ; goto error ; } ossStrncpy( buffer, _sourceData, _srcDataLen ) ; buffer[ _srcDataLen ] = '\n' ; length = _srcDataLen + 1 ; done: return rc ; error: goto done ; }
// PD_TRACE_DECLARE_FUNCTION ( SDB_COORDCB_ADDCATNDADDR, "CoordCB::addCatNodeAddr" ) INT32 _CoordCB::addCatNodeAddr( const _MsgRouteID &id, const CHAR *pHost, const CHAR *pService ) { INT32 rc = SDB_OK; PD_TRACE_ENTRY ( SDB_COORDCB_ADDCATNDADDR ) ; CoordNodeInfo nodeInfo ; nodeInfo._id = id ; nodeInfo._id.columns.groupID = 0 ; ossStrncpy( nodeInfo._host, pHost, OSS_MAX_HOSTNAME ); nodeInfo._host[OSS_MAX_HOSTNAME] = 0 ; nodeInfo._service[MSG_ROUTE_CAT_SERVICE] = pService ; _cataNodeAddrList.push_back( nodeInfo ) ; _multiRouteAgent.updateRoute( nodeInfo._id, nodeInfo._host, nodeInfo._service[MSG_ROUTE_CAT_SERVICE].c_str() ); PD_TRACE_EXIT ( SDB_COORDCB_ADDCATNDADDR ); return rc ; }
INT32 utilSplitStr( const string & input, vector < string > & listServices, const string & seperators ) { INT32 rc = SDB_OK ; CHAR *cstr = NULL ; CHAR *p = NULL ; CHAR *pContext = NULL ; INT32 bufSize = input.size() ; cstr = (CHAR*)SDB_OSS_MALLOC ( bufSize + 1 ) ; if ( !cstr ) { std::cout << "Alloc memory(" << bufSize + 1 << ") failed" << std::endl ; rc = SDB_OOM ; goto error ; } ossMemset ( cstr, 0, bufSize + 1 ) ; ossStrncpy ( cstr, input.c_str(), bufSize ) ; p = ossStrtok ( cstr, seperators.c_str(), &pContext ) ; while ( p ) { string ts ( p ) ; listServices.push_back ( ts ) ; p = ossStrtok ( NULL, seperators.c_str(), &pContext ) ; } done : if ( cstr ) { SDB_OSS_FREE ( cstr ) ; } return rc ; error : goto done ; }
void setGroupName ( const CHAR *groupName ) { ossMemset( _groupName, 0, sizeof(_groupName) ) ; ossStrncpy ( _groupName, groupName, sizeof(_groupName)-1 ); }
void ossSetTrapExceptionPath ( const CHAR *path ) { ossMemset ( ossTrapExceptionPath, 0, sizeof(ossTrapExceptionPath ) ) ; ossStrncpy ( ossTrapExceptionPath, path, OSS_MAX_PATHSIZE ) ; }
INT32 restAdaptor::appendHttpHeader( pmdRestSession *pSession, const CHAR *pKey, const CHAR *pValue ) { INT32 rc = SDB_OK ; PD_TRACE_ENTRY( SDB__RESTADP_APPENDHEADER ) ; SDB_ASSERT ( pSession, "pSession is NULL" ) ; INT32 keySize = ossStrlen( pKey ) ; INT32 valueSize = ossStrlen( pValue ) ; INT32 newHeaderSize = keySize + valueSize + 2 ; INT32 tempSize = 0 ; CHAR *pNewHeaderBuf = NULL ; CHAR *pNewKey = NULL ; CHAR *pNewValue = NULL ; httpConnection *pHttpCon = pSession->getRestConn() ; COLNAME_MAP_IT it ; if( REST_STRING_TRANSFER_SIZE == ossStrlen( pKey ) && 0 == ossStrncmp( pKey, REST_STRING_TRANSFER, REST_STRING_TRANSFER_SIZE ) && REST_STRING_CHUNKED_SIZE == ossStrlen( pValue ) && 0 == ossStrncmp( pValue, REST_STRING_CHUNKED, REST_STRING_CHUNKED_SIZE ) ) { pHttpCon->_isChunk = TRUE ; } it = pHttpCon->_responseHeaders.find( pKey ) ; if ( it == pHttpCon->_responseHeaders.end() ) { rc = pSession->allocBuff( newHeaderSize, &pNewHeaderBuf, tempSize ) ; if ( rc ) { PD_LOG ( PDERROR, "Unable to allocate %d bytes memory, rc=%d", newHeaderSize, rc ) ; goto error ; } pNewKey = pNewHeaderBuf ; pNewValue = pNewHeaderBuf + keySize + 1 ; ossStrncpy( pNewKey, pKey, keySize ) ; ossStrncpy( pNewValue, pValue, valueSize ) ; pNewKey[ keySize ] = 0 ; pNewValue[ valueSize ] = 0 ; pHttpCon->_responseHeaders.insert( std::make_pair( pNewKey, pNewValue ) ) ; } else { rc = pSession->allocBuff( valueSize + 1, &pNewValue, tempSize ) ; if ( rc ) { PD_LOG ( PDERROR, "Unable to allocate %d bytes memory, rc=%d", valueSize, rc ) ; goto error ; } ossStrncpy( pNewValue, pValue, valueSize ) ; pNewValue[ valueSize ] = 0 ; it->second = pNewValue ; } done: PD_TRACE_EXITRC( SDB__RESTADP_APPENDHEADER, rc ) ; return rc ; error: goto done ; }
INT32 _utilESBulkActionBase::_outputActionAndMeta( CHAR *buffer, INT32 size, INT32 &length, BOOLEAN withIndex, BOOLEAN withType, BOOLEAN withID ) const { INT32 rc = SDB_OK ; BOOLEAN begin = TRUE ; std::string metaData = std::string( "{\"" ) + _getActionName() + "\":{" ; if ( withIndex ) { if ( _index.empty() ) { rc = SDB_INVALIDARG ; PD_LOG( PDERROR, "Index name is empty" ) ; goto error ; } metaData += "\"_index\":\"" + _index + "\"" ; begin = FALSE ; } if ( withType ) { if ( _type.empty() ) { rc = SDB_INVALIDARG ; PD_LOG( PDERROR, "Type name is empty" ) ; goto error ; } if ( !begin ) { metaData += "," ; } metaData += "\"_type\":\"" + _type + "\"" ; begin = FALSE ; } if ( withID ) { if ( _id.empty() ) { rc = SDB_INVALIDARG ; PD_LOG( PDERROR, "_id is empty" ) ; goto error ; } if ( !begin ) { metaData += "," ; } metaData += "\"_id\":\"" + _id + "\"" ; } metaData += "}}\n" ; if ( (UINT32)size < metaData.size() ) { rc = SDB_INVALIDARG ; PD_LOG( PDERROR, "Buffer size[ %d ] is too small", size ) ; goto error ; } SDB_ASSERT( buffer, "Buffer is NULL" ) ; ossStrncpy( buffer, metaData.c_str(), metaData.length() ) ; length = metaData.length() ; done: return rc ; error: goto done ; }
void setHostName ( const CHAR* hostName ) { ossMemset( _hostName, 0, sizeof(_hostName) ) ; ossStrncpy ( _hostName, hostName, sizeof(_hostName) - 1 ); }
void _pmdEDUCB::setName ( const CHAR * name ) { ossScopedLock _lock ( &_mutex, EXCLUSIVE ) ; ossStrncpy ( _Name, name, PMD_EDU_NAME_LENGTH ) ; _Name[PMD_EDU_NAME_LENGTH] = 0 ; }
INT32 _ossModuleHandle::init () { INT32 rc = SDB_OK ; CHAR strPath [ 2*OSS_MAX_PATHSIZE + 1 ] = {0} ; CHAR strModule [ OSS_MAX_PATHSIZE + 1 ] = {0} ; OSS_MHANDLE handle = 0 ; CHAR *p = NULL ; #if defined (_WINDOWS) UINT32 errorMode ; #endif PD_TRACE_ENTRY ( SDB_OSSMODULEHANDLE_INIT ) ; if ( _moduleName[0] == '\0' ) { PD_LOG ( PDERROR, "Module name can't be empty" ) ; rc = SDB_INVALIDARG ; goto error ; } PD_TRACE3 ( SDB_OSSMODULEHANDLE_INIT, PD_PACK_STRING(_moduleName), PD_PACK_STRING(_libPath), PD_PACK_UINT(_flags) ) ; ossStrncpy ( strModule, _moduleName, sizeof(strModule) ) ; p = ossStrchr ( strModule, '(' ) ; if ( p ) { *p = '\0' ; } rc = patchModuleName( strModule, _moduleName, sizeof(_moduleName) ); PD_RC_CHECK ( rc, PDERROR, "Failed to patch module name, rc = %d", rc ) ; if ( _libPath[0] ) { INT32 pathLen = 0 ; rc = ossAccess ( _libPath, #if defined (_LINUX) F_OK #elif defined (_WINDOWS) 0 #endif ) ; PD_RC_CHECK ( rc, PDERROR, "Failed to access path %s, rc = %d", _libPath, rc ) ; ossStrncat ( strPath, _libPath, sizeof(strPath) ) ; pathLen = ossStrlen ( strPath ) ; if ( strPath[pathLen-1] != OSS_FILE_SEP_CHAR ) { if ( pathLen >= OSS_MAX_PATHSIZE ) { PD_LOG ( PDERROR, "library path is too long: %s", _libPath ) ; rc = SDB_INVALIDARG ; goto error ; } strPath[pathLen-1] = OSS_FILE_SEP_CHAR ; strPath[pathLen] = '\0' ; } } if ( ossStrlen ( strPath ) + ossStrlen ( _moduleName ) >= sizeof(strPath) ) { PD_LOG ( PDERROR, "path + module name is too long: %s:%s", strPath, _moduleName ) ; rc = SDB_INVALIDARG ; goto error ; } ossStrncat ( strPath, _moduleName, OSS_MAX_PATHSIZE ) ; #if defined (_LINUX) handle = dlopen ( strPath, _flags | RTLD_NOW ) ; if ( !handle ) { PD_LOG ( PDERROR, "Failed to load module %s, error = %s", strPath, dlerror() ) ; rc = SDB_SYS ; goto error ; } _isInitialized = TRUE ; _moduleHandle = handle ; dlerror() ; #elif defined (_WINDOWS) errorMode = SetErrorMode ( SEM_NOOPENFILEERRORBOX | SEM_FAILCRITICALERRORS ) ; _moduleHandle = LoadLibrary ( (LPCTSTR)strPath ) ; SetErrorMode ( errorMode ) ; if ( NULL == _moduleHandle ) { rc = ossGetLastError () ; PD_LOG ( PDERROR, "Failed to load module %s, error = %d", _moduleName, rc ) ; OSSMODULEHANDLE_ERR(rc) ; goto error ; } #endif done : PD_TRACE_EXITRC ( SDB_OSSMODULEHANDLE_INIT, rc ) ; return rc ; error : _isInitialized = FALSE ; _moduleHandle = OSS_MINVALIDHANDLE ; 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 ; }