Esempio n. 1
0
static PyObject *
k5_cc_default(PyObject *self, PyObject *args)
{
    krb5_context ctx;
    krb5_error_code code;
    krb5_ccache ccache;
    const char *name;
    PyObject *ret;

    code = krb5_init_context(&ctx);
    RETURN_ON_ERROR("krb5_init_context()", code);
    code = krb5_cc_default(ctx, &ccache);
    RETURN_ON_ERROR("krb5_cc_default()", code);
    name = krb5_cc_get_name(ctx, ccache);
    if (name == NULL)
    {
	PyErr_Format(k5_error, "krb5_cc_default() returned NULL");
	return NULL;
    }

    ret = PyString_FromString(name);
    if (ret == NULL)
	return ret;

    code = krb5_cc_close(ctx, ccache);
    RETURN_ON_ERROR("krb5_cc_close()", code);
    krb5_free_context(ctx);

    return ret;
}
Esempio n. 2
0
/***********************************************************
 * DESCRIPTION: 
 *    Write a number of blocks to the file at specified location
 * PARAMETERS:
 *    pFile - file handle
 *    writeBuf - write buffer
 *    fbo - file block offset
 *    numOfBlock - total number of file block offset
 * RETURN:
 *    NO_ERROR if success
 *    other number if something wrong
 ***********************************************************/
int DbFileOp::writeDBFile( CommBlock& cb, const unsigned char* writeBuf, 
                           const uint64_t lbid, const int numOfBlock ) 
{ 
    CacheKey key;
    int ret;

    if( Cache::getUseCache() )
    {
        if( Cache::cacheKeyExist( cb.file.oid, lbid ) ) {
            key = Cache::getCacheKey( cb.file.oid, lbid );
            RETURN_ON_ERROR( Cache::modifyCacheBlock( key, writeBuf ) );
            return NO_ERROR;
        }
    }
	if (BRMWrapper::getUseVb())
	{
		RETURN_ON_ERROR( writeVB( cb.file.pFile, cb.file.oid, lbid ) ); 
	}
    ret = writeDBFile( cb.file.pFile, writeBuf, lbid, numOfBlock );
	if (BRMWrapper::getUseVb())
	{
		LBIDRange_v ranges;
		LBIDRange range;
		range.start = lbid;
		range.size = 1;
		ranges.push_back(range);
		BRMWrapper::getInstance()->writeVBEnd(getTransId(), ranges);
	}

    return ret;
}
Esempio n. 3
0
static PyObject *
k5_cc_get_principal(PyObject *self, PyObject *args)
{
    krb5_context ctx;
    char *ccname, *name;
    krb5_error_code code;
    krb5_ccache ccache;
    krb5_principal principal;
    PyObject *ret;

    if (!PyArg_ParseTuple( args, "s", &ccname))
	return NULL;

    code = krb5_init_context(&ctx);
    RETURN_ON_ERROR("krb5_init_context()", code);
    code = krb5_cc_resolve(ctx, ccname, &ccache);
    RETURN_ON_ERROR("krb5_cc_resolve()", code);
    code = krb5_cc_get_principal(ctx, ccache, &principal);
    RETURN_ON_ERROR("krb5_cc_get_principal()", code);
    code = krb5_unparse_name(ctx, principal, &name);
    RETURN_ON_ERROR("krb5_unparse_name()", code);

    ret = PyString_FromString(name);
    if (ret == NULL)
	return ret;

    code = krb5_cc_close(ctx, ccache);
    RETURN_ON_ERROR("krb5_cc_close()", code);
    krb5_free_unparsed_name(ctx, name);
    krb5_free_principal(ctx, principal);
    krb5_free_context(ctx);

    return ret;
}
Esempio n. 4
0
/**@brief Function for extracting the BSP event valid at startup.
 *
 * @details When a button was used to wake up the device, the button press will not generate an
 *          interrupt. This function reads which button was pressed at startup, and returns the
 *          appropriate BSP event.
 *
 * @param[out] p_startup_event  Where to put the extracted BSP event.
 *
 * @retval NRF_SUCCESS  Extraction was successful.
 * @return A propagated error code.
 */
static uint32_t startup_event_extract(bsp_event_t * p_startup_event)
{
    uint32_t err_code;
    bool wakeup_button_is_pressed, bond_erase_button_is_pressed;

    // Read buttons
    err_code = bsp_button_is_pressed(BTN_ID_WAKEUP, &wakeup_button_is_pressed);
    RETURN_ON_ERROR(err_code);

    err_code = bsp_button_is_pressed(BTN_ID_WAKEUP_BOND_DELETE, &bond_erase_button_is_pressed);
    RETURN_ON_ERROR(err_code);

    // React to button states
    if (bond_erase_button_is_pressed)
    {
        *p_startup_event = BSP_EVENT_CLEAR_BONDING_DATA;
    }
    else if (wakeup_button_is_pressed)
    {
        *p_startup_event = BSP_EVENT_WAKEUP;
    }
    else
    {
        *p_startup_event = BSP_EVENT_NOTHING;
    }

    return NRF_SUCCESS;
}
Esempio n. 5
0
//------------------------------------------------------------------------------
// Flush the contents of internal fCBuf (column buffer) to disk.
//------------------------------------------------------------------------------
int ColumnBufferManager::flush( ) {

    if(fBufFreeOffset == fBufWriteOffset) {
        if (fLog->isDebug( DEBUG_2 )) {
            std::ostringstream oss;
            oss << "Skipping write flush for: OID-" <<
                fColInfo->curCol.dataFile.fid <<
                "; DBRoot-" << fColInfo->curCol.dataFile.fDbRoot    <<
                "; part-"   << fColInfo->curCol.dataFile.fPartition <<
                "; seg-"    << fColInfo->curCol.dataFile.fSegment   <<
                "; both fBufFreeOffset and fBufWriteOffset = "      <<
                fBufFreeOffset;
            fLog->logMsg( oss.str(), MSGLVL_INFO2 );
        }
        return NO_ERROR;
    }
    int bufferSize = fCBuf->getSize();

    // Account for circular buffer by making 2 calls to write the data,
    // if we are wrapping around at the end of the buffer.
    if(fBufFreeOffset < fBufWriteOffset) {
        RETURN_ON_ERROR( writeToFileExtentCheck(
            fBufWriteOffset, bufferSize - fBufWriteOffset) );
        fBufWriteOffset = 0;
    }
    RETURN_ON_ERROR( writeToFileExtentCheck(
        fBufWriteOffset, fBufFreeOffset - fBufWriteOffset) );
    fBufWriteOffset = fBufFreeOffset;

    return NO_ERROR;
}
//------------------------------------------------------------------------------
// Reinitializes ColBuf buffer, and resets
// file offset data member attributes where new extent will start.
//------------------------------------------------------------------------------
int ColumnInfoCompressed::resetFileOffsetsNewExtent(const char* hdr)
{
    setFileSize( curCol.dataFile.hwm, false );
    long long byteOffset = (long long)curCol.dataFile.hwm *
                           (long long)BYTE_PER_BLOCK;
    fSizeWritten      = byteOffset;
    fSizeWrittenStart = fSizeWritten;
    availFileSize     = fileSize - fSizeWritten;

    // If we are adding an extent as part of preliminary block skipping, then
    // we won't have a ColumnBufferManager object yet, but that's okay, because
    // we are only adding the empty extent at this point.
    if (fColBufferMgr)
    {
        RETURN_ON_ERROR( fColBufferMgr->setDbFile(curCol.dataFile.pFile,
                         curCol.dataFile.hwm, hdr) );

        // Reinitialize ColBuf for the next extent
        long long startFileOffset;
        RETURN_ON_ERROR( fColBufferMgr->resetToBeCompressedColBuf(
                         startFileOffset ) );

        // Set the file offset to point to the chunk we are adding or updating
        RETURN_ON_ERROR( colOp->setFileOffset(curCol.dataFile.pFile,
                         startFileOffset) );
    }

    return NO_ERROR;
}
Esempio n. 7
0
int CAPECompressCreate::Finish(const void * pTerminatingData, int nTerminatingBytes, int nWAVTerminatingBytes)
{
    // clear the bit array
    RETURN_ON_ERROR(m_spAPECompressCore->GetBitArray()->OutputBitArray(TRUE));
    
    // finalize the file
    RETURN_ON_ERROR(FinalizeFile(m_spIO, m_nFrameIndex, m_nLastFrameBlocks, 
        pTerminatingData, nTerminatingBytes, nWAVTerminatingBytes, m_spAPECompressCore->GetPeakLevel()));
    
    return ERROR_SUCCESS;
}
Esempio n. 8
0
/***********************************************************
 * DESCRIPTION: 
 *    Core function for writing data using VB cache
 ***********************************************************/
int DbFileOp::writeDBFile( IDBDataFile* pFile, const unsigned char* writeBuf,
                           const uint64_t lbid, const int numOfBlock  )
{
    RETURN_ON_ERROR( setFileOffsetBlock( pFile, lbid ) );

    for( int i = 0; i < numOfBlock; i++ ) {
        Stats::incIoBlockWrite();
        RETURN_ON_ERROR( writeFile( pFile, writeBuf, BYTE_PER_BLOCK ) );
    }

    return NO_ERROR;
}
Esempio n. 9
0
static PyObject *
k5_change_password(PyObject *self, PyObject *args)
{
    int result_code;
    char *name, *oldpass, *newpass;
    krb5_context ctx;
    krb5_error_code code;
    krb5_principal principal;
    krb5_get_init_creds_opt options;
    krb5_creds creds;
    krb5_data result_code_string, result_string;

    if (!PyArg_ParseTuple(args, "sss", &name, &oldpass, &newpass))
        return NULL;

    /* Initialize parameters. */
    code = krb5_init_context(&ctx);
    RETURN_ON_ERROR("krb5_init_context()", code);
    code = krb5_parse_name(ctx, name, &principal);
    RETURN_ON_ERROR("krb5_parse_name()", code);

    /* Get credentials using the password. */
    krb5_get_init_creds_opt_init(&options);
    krb5_get_init_creds_opt_set_tkt_life(&options, 5*60);
    krb5_get_init_creds_opt_set_renew_life(&options, 0);
    krb5_get_init_creds_opt_set_forwardable(&options, 0);
    krb5_get_init_creds_opt_set_proxiable(&options, 0);
    memset(&creds, 0, sizeof (creds));
    code = krb5_get_init_creds_password(ctx, &creds, principal, oldpass,
					NULL, NULL, 0, "kadmin/changepw",
					&options);
    RETURN_ON_ERROR("krb5_get_init_creds_password()", code);

    code = krb5_change_password(ctx, &creds, newpass, &result_code,
				&result_code_string, &result_string);
    RETURN_ON_ERROR("krb5_change_password()", code);

    /* Any other error? */
    if (result_code != 0)
    {
	_k5_set_password_error(&result_code_string, &result_string);
	return NULL;
    }

    /* Free up results. */
    if (result_code_string.data != NULL)
	free(result_code_string.data);
    if (result_string.data != NULL)
	free(result_string.data);

    Py_INCREF(Py_None);
    return Py_None;
}
Esempio n. 10
0
int CAPECompressCreate::InitializeFile(CIO * pIO, const WAVEFORMATEX * pwfeInput, int nMaxFrames, int nCompressionLevel, const void * pHeaderData, int nHeaderBytes)
{
    // error check the parameters
    if (pIO == NULL || pwfeInput == NULL || nMaxFrames <= 0)
        return ERROR_BAD_PARAMETER;
    
    APE_DESCRIPTOR APEDescriptor; memset(&APEDescriptor, 0, sizeof(APEDescriptor));
    APE_HEADER APEHeader; memset(&APEHeader, 0, sizeof(APEHeader));

    // create the descriptor (only fill what we know)
    APEDescriptor.cID[0] = 'M';
    APEDescriptor.cID[1] = 'A';
    APEDescriptor.cID[2] = 'C';
    APEDescriptor.cID[3] = ' ';
    APEDescriptor.nVersion = MAC_VERSION_NUMBER;
    
    APEDescriptor.nDescriptorBytes = sizeof(APEDescriptor);
    APEDescriptor.nHeaderBytes = sizeof(APEHeader);
    APEDescriptor.nSeekTableBytes = nMaxFrames * sizeof(unsigned int);
    APEDescriptor.nHeaderDataBytes = (nHeaderBytes == CREATE_WAV_HEADER_ON_DECOMPRESSION) ? 0 : nHeaderBytes;

    // create the header (only fill what we know now)
    APEHeader.nBitsPerSample = pwfeInput->wBitsPerSample;
    APEHeader.nChannels = pwfeInput->nChannels;
    APEHeader.nSampleRate = pwfeInput->nSamplesPerSec;
    
    APEHeader.nCompressionLevel = (uint16) nCompressionLevel;
    APEHeader.nFormatFlags = (nHeaderBytes == CREATE_WAV_HEADER_ON_DECOMPRESSION) ? MAC_FORMAT_FLAG_CREATE_WAV_HEADER : 0;

    APEHeader.nBlocksPerFrame = m_nSamplesPerFrame;

    // write the data to the file
    unsigned int nBytesWritten = 0;
    RETURN_ON_ERROR(pIO->Write(&APEDescriptor, sizeof(APEDescriptor), &nBytesWritten))
    RETURN_ON_ERROR(pIO->Write(&APEHeader, sizeof(APEHeader), &nBytesWritten))
        
    // write an empty seek table
    m_spSeekTable.Assign(new uint32 [nMaxFrames], TRUE);
    if (m_spSeekTable == NULL) { return ERROR_INSUFFICIENT_MEMORY; }
    ZeroMemory(m_spSeekTable, nMaxFrames * 4);
    RETURN_ON_ERROR(pIO->Write(m_spSeekTable, (nMaxFrames * 4), &nBytesWritten))
    m_nMaxFrames = nMaxFrames;

    // write the WAV data
    if ((pHeaderData != NULL) && (nHeaderBytes > 0) && (nHeaderBytes != CREATE_WAV_HEADER_ON_DECOMPRESSION))
    {
        m_spAPECompressCore->GetBitArray()->GetMD5Helper().AddData(pHeaderData, nHeaderBytes);
        RETURN_ON_ERROR(pIO->Write((void *) pHeaderData, nHeaderBytes, &nBytesWritten))
    }
Esempio n. 11
0
// just don't have a good solution to consolidate with above functions
// Note: This is used with absolute FBO, no lbid involved
int DbFileOp::writeDBFileFbo(IDBDataFile* pFile, const unsigned char* writeBuf,
                             const uint64_t fbo, const int numOfBlock  )
{
    long long  fboOffset = 0;

    fboOffset = (fbo)*(long)BYTE_PER_BLOCK;
    RETURN_ON_ERROR( setFileOffset( pFile, fboOffset ) );

    for( int i = 0; i < numOfBlock; i++ ) {
        Stats::incIoBlockWrite();
        RETURN_ON_ERROR( writeFile( pFile, writeBuf, BYTE_PER_BLOCK ) );
    }

    return NO_ERROR;
}
Esempio n. 12
0
//------------------------------------------------------------------------------
// Release the data in the specified ColumnBufferSection, meaning the data in
// that section is ready to be written to the database.
//------------------------------------------------------------------------------
int ColumnBufferManager::releaseSection(ColumnBufferSection* cbs) {
#ifdef PROFILE
    Stats::startParseEvent(WE_STATS_WAIT_TO_RELEASE_OUT_BUF);
#endif
    boost::mutex::scoped_lock lock(fColInfo->colMutex());
#ifdef PROFILE
    Stats::stopParseEvent(WE_STATS_WAIT_TO_RELEASE_OUT_BUF);
#endif
    cbs->setStatus(WRITE_COMPLETE);
     
    int lastWriteOffset = fBufWriteOffset;

    std::list<ColumnBufferSection*>::iterator it = fSectionsInUse.begin();
    if (it != fSectionsInUse.end())
    {
        ColumnBufferSection* cbs_temp = *it;
        while (WRITE_COMPLETE == cbs_temp->getStatus())
        {
            lastWriteOffset = cbs_temp->getStartOffset() +
                              cbs_temp->getSectionSize() - 1;

            delete cbs_temp;
            it = fSectionsInUse.erase(it);
            if (it == fSectionsInUse.end())
                break;
            cbs_temp = *it;
        }
    }
    fBufInUse.notify_all();

    RETURN_ON_ERROR( writeToFile(lastWriteOffset) );

    return NO_ERROR;
}
Esempio n. 13
0
static PyObject *
py_cpg_initialize(PyObject *self, PyObject *args)
{
    int ret;
    cpg_handle_t handle;
    cpg_callbacks_t callbacks;
    PyObject *Phandle, *Pcallbacks;
    
    if (!PyArg_ParseTuple(args, "O", &Pcallbacks))
	return NULL;

    callbacks.cpg_deliver_fn = py_cpg_deliver_fn;
    callbacks.cpg_confchg_fn = py_cpg_confchg_fn;
    callbacks.cpg_groups_get_fn = py_cpg_groups_get_fn;

    ret = cpg_initialize(&handle, &callbacks);
    RETURN_ON_ERROR(ret, "cpg_initialize");

    ret = py_cpg_add_callbacks(handle, Pcallbacks);
    if (ret == -1)
	return NULL;

    Phandle = PyLong_FromLong(handle);
    return Phandle;
}
Esempio n. 14
0
gboolean battery_os_init()
{
	GDir *directory = 0;
	GError *error = NULL;
	const char *entryname;

	battery_os_free();

	directory = g_dir_open("/sys/class/power_supply", 0, &error);
	RETURN_ON_ERROR(error);

	while ((entryname = g_dir_read_name(directory))) {
		enum psy_type type = power_supply_get_type(entryname);

		switch (type) {
		case PSY_BATTERY:
			add_battery(entryname);
			break;
		case PSY_MAINS:
			add_mains(entryname);
			break;
		default:
			break;
		}
	}

	g_dir_close(directory);

	uevent_register_notifier(&psy_change);
	uevent_register_notifier(&psy_plug);

	return batteries != NULL;
}
Esempio n. 15
0
//------------------------------------------------------------------------------
// In the middle of parsing a Read buffer, if we detect that the buffer will
// need to be split among 2 different extents, then this function should be
// called to flush the first part of the buffer into the first extent, before
// writing the second part of the buffer into the second extent.  This function
// will wait for the pending sections to be parsed so that they can all be
// flushed to the segment file containing the first extent.  This function is
// currently only needed for Dictionary column processing.
//------------------------------------------------------------------------------
int ColumnBufferManager::intermediateFlush() {
    boost::posix_time::seconds wait_seconds(COND_WAIT_SECONDS);
    boost::mutex::scoped_lock lock(fColInfo->colMutex());

    // Wait for all other threads which are currently parsing rows,
    // to finish parsing the data in those sections.
#ifdef PROFILE
    Stats::startParseEvent(WE_STATS_WAIT_FOR_INTERMEDIATE_FLUSH);
#endif
    while(fSectionsInUse.size() > 0) {
        fBufInUse.timed_wait(lock, wait_seconds);

        // See if JobStatus has been set to terminate by another thread
        if (BulkStatus::getJobStatus() == EXIT_FAILURE)
        {
            throw SecondaryShutdownException( "ColumnBufferManager::"
                "intermediateFlush() responding to job termination");
        }
    }
#ifdef PROFILE
    Stats::stopParseEvent(WE_STATS_WAIT_FOR_INTERMEDIATE_FLUSH);
#endif

    RETURN_ON_ERROR( flush( ) );

    return NO_ERROR;
}
Esempio n. 16
0
//------------------------------------------------------------------------------
// Write out the updated compression headers.
//------------------------------------------------------------------------------
int ColumnBufferCompressed::saveCompressionHeaders( )
{
    // Construct the header records
    char hdrBuf[IDBCompressInterface::HDR_BUF_LEN*2];
    fCompressor->initHdr( hdrBuf, fColInfo->column.compressionType );
    fCompressor->setBlockCount(hdrBuf,
        (fColInfo->getFileSize()/BYTE_PER_BLOCK) );

    std::vector<uint64_t> ptrs;
    for (unsigned i=0; i<fChunkPtrs.size(); i++)
    {
        ptrs.push_back( fChunkPtrs[i].first );
    }
    unsigned lastIdx = fChunkPtrs.size() - 1;
    ptrs.push_back( fChunkPtrs[lastIdx].first + fChunkPtrs[lastIdx].second );
    fCompressor->storePtrs( ptrs, hdrBuf );

    // Write out the header records
    //char resp;
    //std::cout << "dbg: before writeHeaders" << std::endl;
    //std::cin  >> resp;
    RETURN_ON_ERROR( fColInfo->colOp->writeHeaders(fFile, hdrBuf) );
    //std::cout << "dbg: after writeHeaders" << std::endl;
    //std::cin  >> resp;

    return NO_ERROR;
}
Esempio n. 17
0
static PyObject *
py_cpg_leave(PyObject *self, PyObject *args)
{
    char *name;
    int length, ret;
    cpg_handle_t handle;
    struct cpg_name group_name;

    if (!PyArg_ParseTuple(args, "ls#", &handle, &name, &length))
	return NULL;

    if (length > CPG_MAX_NAME_LENGTH)
    {
	PyErr_Format(py_cpg_error, "Group name too long (%d, max length = %d)",
		     length, CPG_MAX_NAME_LENGTH);
	return NULL;
    }
    group_name.length = length;
    memcpy(group_name.value, name, length);
    
    ret = cpg_leave(handle, &group_name);
    RETURN_ON_ERROR(ret, "cpg_leave");

    Py_INCREF(Py_None);
    return Py_None;
}
Esempio n. 18
0
/***********************************************************
 * DESCRIPTION: 
 *    Read a block from a file at specified location
 * PARAMETERS:
 *    pFile - file handle
 *    readBuf - read buffer
 *    fbo - file block offset
 * RETURN:
 *    NO_ERROR if success
 *    other number if something wrong
 ***********************************************************/
int DbFileOp::readDBFile( IDBDataFile* pFile,
                          unsigned char* readBuf,
                          const uint64_t lbid,
                          const bool isFbo )
{
    long long  fboOffset = 0;

    if( !isFbo ) {
        RETURN_ON_ERROR( setFileOffsetBlock( pFile, lbid ) );
    }
    else {  
        fboOffset = (lbid)*(long)BYTE_PER_BLOCK;                 
        RETURN_ON_ERROR( setFileOffset( pFile, fboOffset ) );
    }

    return readFile( pFile, readBuf, BYTE_PER_BLOCK );
}
Esempio n. 19
0
static PyObject *
k5_set_password(PyObject *self, PyObject *args)
{
    int result_code;
    char *name, *newpass;
    krb5_context ctx;
    krb5_error_code code;
    krb5_principal principal;
    krb5_data result_code_string, result_string;
    krb5_ccache ccache;

    if (!PyArg_ParseTuple(args, "ss", &name, &newpass))
        return NULL;

    /* Initialize parameters. */
    code = krb5_init_context(&ctx);
    RETURN_ON_ERROR("krb5_init_context()", code);
    code = krb5_parse_name(ctx, name, &principal);
    RETURN_ON_ERROR("krb5_parse_name()", code);

    /* Get credentials */
    code = krb5_cc_default(ctx, &ccache);
    RETURN_ON_ERROR("krb5_cc_default()", code);

    /* Set password */
    code = krb5_set_password_using_ccache(ctx, ccache, newpass, principal,
					  &result_code, &result_code_string,
					  &result_string);
    RETURN_ON_ERROR("krb5_set_password_using_ccache()", code);

    /* Any other error? */
    if (result_code != 0)
    {
	_k5_set_password_error(&result_code_string, &result_string);
	return NULL;
    }

    /* Free up results. */
    if (result_code_string.data != NULL)
	free(result_code_string.data);
    if (result_string.data != NULL)
	free(result_string.data);

    Py_INCREF(Py_None);
    return Py_None;
}
Esempio n. 20
0
int ColumnOpCompress1::expandAbbrevColumnExtent(
   IDBDataFile* pFile, uint16_t dbRoot, uint64_t emptyVal, int width)
{
   // update the uncompressed initial chunk to full chunk
   RETURN_ON_ERROR(m_chunkManager->expandAbbrevColumnExtent(pFile, emptyVal, width));

   // let the base to physically expand extent.
   return FileOp::expandAbbrevColumnExtent(pFile, dbRoot, emptyVal, width);
}
Esempio n. 21
0
/***********************************************************
 * DESCRIPTION: 
 *    flush the cache
 * PARAMETERS:
 *    none
 * RETURN:
 *    NO_ERROR if success, otherwise if fail
 ***********************************************************/
int DbFileOp::flushCache()
{
    BlockBuffer*   curBuf;

    if( !Cache::getUseCache() )
        return NO_ERROR;

    for( CacheMapIt it = Cache::m_writeList->begin();
                    it != Cache::m_writeList->end(); it++ ) {
        curBuf = it->second;
        RETURN_ON_ERROR( writeDBFile( (*curBuf).cb.file.pFile,
                                      (*curBuf).block.data,
                                      (*curBuf).block.lbid ) );
    }

    RETURN_ON_ERROR( Cache::flushCache() );
    return NO_ERROR;
}
Esempio n. 22
0
int DbFileOp::readDBFile( CommBlock& cb,
                          unsigned char* readBuf,
                          const uint64_t lbid ) 
{ 
    CacheKey key;

    if( Cache::getUseCache() )
    {
        if( Cache::cacheKeyExist( cb.file.oid, lbid ) ) {
            key = Cache::getCacheKey( cb.file.oid, lbid );
            RETURN_ON_ERROR( Cache::loadCacheBlock( key, readBuf ) );
            return NO_ERROR;
        }
    }

    RETURN_ON_ERROR( readDBFile( cb.file.pFile, readBuf, lbid ) ); 
    if( Cache::getUseCache() )
    {
        int  fbo = lbid;

        uint16_t  dbRoot;
        uint32_t  partition;
        uint16_t  segment;
        RETURN_ON_ERROR( BRMWrapper::getInstance()->getFboOffset(
            lbid, dbRoot, partition, segment, fbo ) );
      
        if( Cache::getListSize( FREE_LIST ) == 0 ) {
            if ( isDebug( DEBUG_1 ) ) {
                printf( "\nBefore flushing cache " );
                Cache::printCacheList();
            }

            // flush cache to give up more space
            RETURN_ON_ERROR( flushCache() );
            if ( isDebug( DEBUG_1 ) ) {
                printf( "\nAfter flushing cache " );
                Cache::printCacheList();
            }
        }
        RETURN_ON_ERROR( Cache::insertLRUList( cb, lbid, fbo, readBuf ) );
    }

    return NO_ERROR;
}
int CAPECompressCore::EncodeFrame(const void * pInputData, int nInputBytes)
{
    // variables
    const int nInputBlocks = nInputBytes / m_wfeInput.nBlockAlign;
    int nSpecialCodes = 0;

    // always start a new frame on a byte boundary
    m_spBitArray->AdvanceToByteBoundary();
    
    // do the preparation stage
    RETURN_ON_ERROR(Prepare(pInputData, nInputBytes, &nSpecialCodes))

    m_spPredictorX->Flush();
    m_spPredictorY->Flush();

    m_spBitArray->FlushState(m_BitArrayStateX);
    m_spBitArray->FlushState(m_BitArrayStateY);

    m_spBitArray->FlushBitArray();

    if (m_wfeInput.nChannels == 2) 
    {
        BOOL bEncodeX = TRUE;
        BOOL bEncodeY = TRUE;
        
        if ((nSpecialCodes & SPECIAL_FRAME_LEFT_SILENCE) && 
            (nSpecialCodes & SPECIAL_FRAME_RIGHT_SILENCE)) 
        {
            bEncodeX = FALSE;
            bEncodeY = FALSE;
        }
        
        if (nSpecialCodes & SPECIAL_FRAME_PSEUDO_STEREO) 
        {
            bEncodeY = FALSE;
        }
        
        if (bEncodeX && bEncodeY)
        {
            int nLastX = 0;
            for (int z = 0; z < nInputBlocks; z++)
            {
                m_spBitArray->EncodeValue(m_spPredictorY->CompressValue(m_spDataY[z], nLastX), m_BitArrayStateY);
                m_spBitArray->EncodeValue(m_spPredictorX->CompressValue(m_spDataX[z], m_spDataY[z]), m_BitArrayStateX);
                
                nLastX = m_spDataX[z];
            }
        }
        else if (bEncodeX) 
        {
            for (int z = 0; z < nInputBlocks; z++)
            {
                RETURN_ON_ERROR(m_spBitArray->EncodeValue(m_spPredictorX->CompressValue(m_spDataX[z]), m_BitArrayStateX))
            }
        }
        else if (bEncodeY) 
Esempio n. 24
0
const int DbFileOp::readSubBlockEntry( CommBlock& cb, DataBlock* block, 
                                       const uint64_t lbid, const int sbid, 
                                       const int entryNo, const int width, 
                                       void* pStruct )
{
    RETURN_ON_ERROR( readDBFile( cb, block->data, lbid ) );
    getSubBlockEntry( block->data, sbid, entryNo, width, pStruct );

    return NO_ERROR;
}
Esempio n. 25
0
//------------------------------------------------------------------------------
// Writes data from our output buffer starting at fBufWriteOffset, through the
// "endOffset" that is specified (rounded down to nearest 8192-byte block).
// Trailing data (less than 1 block) is left in the output buffer.
// Keep in mind that the output buffer is a circular buffer, so if the
// applicable bytes "wrap-around" in the buffer, then this function will
// perform 2 I/O operations to write the 2 noncontiguous chunks of data.
//------------------------------------------------------------------------------
int ColumnBufferManager::writeToFile(int endOffset) {
    int bufferSize = fCBuf->getSize();

    if (endOffset == fBufWriteOffset)
        return NO_ERROR;

    unsigned int writeSize =
        (endOffset - fBufWriteOffset + bufferSize)%bufferSize + 1;

    // Don't bother writing anything if we don't at least have a BLOCK_SIZE
    // set of bytes to write out; which means we need to be sure to flush
    // the buffer at the end, because we could have leftover bytes that we
    // have not yet written out.
    if (writeSize < BLOCK_SIZE)
        return NO_ERROR;

    writeSize = writeSize - writeSize%BLOCK_SIZE; //round down to mult of blksiz
    endOffset = (fBufWriteOffset + writeSize - 1) % bufferSize;

    if (fLog->isDebug( DEBUG_3 )) {
        std::ostringstream oss;
        oss << "Writing OID-" << fColInfo->curCol.dataFile.fid <<
            "; bufWriteOff-"      << fBufWriteOffset <<
            "; bufFreeOff-"       << fBufFreeOffset  <<
            "; endWrite-"         << endOffset <<
            "; bytesToWrite-"     << writeSize <<
            "; bufSize-"          << bufferSize;
        fLog->logMsg( oss.str(), MSGLVL_INFO2 );
    }

    // Account for circular buffer by making 2 calls to write the data,
    // if we are wrapping around at the end of the buffer.
    if(endOffset < fBufWriteOffset) {
        RETURN_ON_ERROR( writeToFileExtentCheck(
            fBufWriteOffset, bufferSize - fBufWriteOffset) );
        fBufWriteOffset = 0;
    }
    RETURN_ON_ERROR( writeToFileExtentCheck(
        fBufWriteOffset, endOffset - fBufWriteOffset + 1) );
    fBufWriteOffset = (endOffset + 1)%bufferSize;

    return NO_ERROR;
}
Esempio n. 26
0
static PyObject *
k5_get_init_creds_keytab(PyObject *self, PyObject *args)
{
    char *name, *ktname;
    krb5_context ctx;
    krb5_error_code code;
    krb5_keytab keytab;
    krb5_ccache ccache;
    krb5_principal principal;
    krb5_get_init_creds_opt options;
    krb5_creds creds;

    if (!PyArg_ParseTuple(args, "sz", &name, &ktname))
        return NULL;

    /* Initialize parameters. */
    code = krb5_init_context(&ctx);
    RETURN_ON_ERROR("krb5_init_context()", code);
    code = krb5_parse_name(ctx, name, &principal);
    RETURN_ON_ERROR("krb5_parse_name()", code);
    krb5_get_init_creds_opt_init(&options);
    memset(&creds, 0, sizeof (creds));

    /* Resolve keytab */
    if (ktname)
    {
	code = krb5_kt_resolve(ctx, ktname, &keytab);
	RETURN_ON_ERROR("krb5_kt_resolve()", code);
    } else
    {
	code = krb5_kt_default(ctx, &keytab);
	RETURN_ON_ERROR("krb5_kt_resolve()", code);
    }

    /* Get the credentials. */
    code = krb5_get_init_creds_keytab(ctx, &creds, principal,
                                      keytab, 0, NULL, &options);
    RETURN_ON_ERROR("krb5_get_init_creds_keytab()", code);

    /* Store the credential in the credential cache. */
    code = krb5_cc_default(ctx, &ccache);
    RETURN_ON_ERROR("krb5_cc_default()", code);
    code = krb5_cc_initialize(ctx, ccache, principal);
    RETURN_ON_ERROR("krb5_cc_initialize()", code);
    code = krb5_cc_store_cred(ctx, ccache, &creds);
    RETURN_ON_ERROR("krb5_cc_store_creds()", code);
    krb5_cc_close(ctx, ccache);

    Py_INCREF(Py_None);
    return Py_None;
}
Esempio n. 27
0
static PyObject *
k5_c_valid_enctype(PyObject *self, PyObject *args)
{
    char *name;
    krb5_context ctx;
    krb5_enctype type;
    krb5_error_code code;
    krb5_boolean valid;
    PyObject *ret;

    if (!PyArg_ParseTuple( args, "s", &name))
	return NULL;

    code = krb5_init_context(&ctx);
    RETURN_ON_ERROR("krb5_init_context()", code);
    code = krb5_string_to_enctype(name, &type);
    RETURN_ON_ERROR("krb5_string_to_enctype()", code);
    valid = krb5_c_valid_enctype(type);
    ret = PyBool_FromLong((long) valid);
    krb5_free_context(ctx);

    return ret;
}
Esempio n. 28
0
static gboolean update_linux_mains(struct psy_mains *ac)
{
	GError *error = NULL;
	gchar *data;
	gsize datalen;
	ac->online = FALSE;

	/* online */
	g_file_get_contents(ac->path_online, &data, &datalen, &error);
	RETURN_ON_ERROR(error);
	ac->online = (atoi(data) == 1);
	g_free(data);

	return TRUE;
}
Esempio n. 29
0
static PyObject *
py_cpg_dispatch(PyObject *self, PyObject *args)
{
    int ret;
    cpg_handle_t handle;
    cs_dispatch_flags_t dispatch;

    if (!PyArg_ParseTuple(args, "li", &handle, &dispatch))
	return NULL;

    ret = cpg_dispatch(handle, dispatch);
    RETURN_ON_ERROR(ret, "cpg_dispach");

    Py_INCREF(Py_None);
    return Py_None;
}
Esempio n. 30
0
static PyObject *
py_cpg_fd_get(PyObject *self, PyObject *args)
{
    int fd, ret;
    cpg_handle_t handle;
    PyObject *Phandle;

    if (!PyArg_ParseTuple(args, "l", &handle))
	return NULL;

    ret = cpg_fd_get(handle, &fd);
    RETURN_ON_ERROR(ret, "cpg_fd_get");

    Phandle = PyInt_FromLong(fd);
    return Phandle;
}