コード例 #1
0
ファイル: wu64idx-v3.c プロジェクト: ImAWolf/ncbi-vdb
rc_t KU64IndexDelete_v3(KU64Index_v3* self, uint64_t key)
{
    KU64Index_Node node;
    BSTNode* n = NULL;

    self->rc = 0;
    node.key = key;
    n = BSTreeFind(&self->tree, &node, KU64Index_Cmp4Delete);
    if( n != NULL ) {
        if( !BSTreeUnlink(&self->tree, n) ) {
            self->rc = RC(rcDB, rcIndex, rcDestroying, rcId, rcCorrupt);
        }
    } else {
        self->rc = RC(rcDB, rcIndex, rcDestroying, rcId, rcNotFound);
    }
    return self->rc;
}
コード例 #2
0
ファイル: proxy.c プロジェクト: ncbi/ncbi-vdb
KNSProxies * KNSManagerKNSProxiesMake ( struct KNSManager * mgr,
                                        const KConfig * kfg )
{
    rc_t rc = 0;

    int i = 0;
    int n = 2;

    typedef enum {
        eEnv,
        eKfg,
    } EType;

    EType type [ 2 ] = { eKfg, eEnv };

    KNSProxies * self = calloc ( 1, sizeof * self ); 
    if ( self == NULL )
        return NULL;

    assert ( self );

    BSTreeInit ( & self -> proxie_tree );

    rc = KConfigReadBool
        ( kfg, "/http/proxy/enabled", & self -> http_proxy_enabled );
    if ( rc != 0 ) {
        if ( GetRCState ( rc ) == rcNotFound )
            rc = 0;
        else {
            KNSManagerSetHTTPProxyPath ( mgr, NULL );
            assert ( self -> http_proxy_enabled == false );
        }
    }
    else if ( ! self -> http_proxy_enabled )
        return self;

    {
        bool proxy_only = false;
        rc_t rc = KConfigReadBool ( kfg, "/http/proxy/only",  & proxy_only );
        if ( rc == 0 && proxy_only )
            self-> http_proxy_only = true;
    }

    {
        String * result = NULL;
        rc = KConfigReadString ( kfg, "/http/proxy/use", & result );
        if ( rc == 0 ) {
            if ( StringCmp ( result, "env") ) {
                n = 1;
                type [ 0 ] = eEnv;
            } else if ( StringCmp ( result, "kfg") ) {
                n = 1;
                type [ 0 ] = eKfg;
            } else if ( StringCmp ( result, "none") ) {
                n = 0;
            } else if ( StringCmp ( result, "env,kfg") ) {
                n = 2;
                type [ 0 ] = eEnv;
                type [ 1 ] = eKfg;
            } else if ( StringCmp ( result, "kfg,env") ) {
                n = 2;
                type [ 0 ] = eKfg;
                type [ 1 ] = eEnv;
            }
        }
        RELEASE ( String, result );
    }

    for ( i = 0; i < n; ++ i ) {
        switch ( type [ i ] ) {
            case eEnv:
                KNSProxiesHttpProxyInitFromEnv ( self );
                break;
            case eKfg:
                KNSProxiesHttpProxyInitFromKfg ( self, kfg );
                break;
            default:
                assert ( 0 );
                break;
        }
    }

    BSTreeForEach ( & self -> proxie_tree, false, KNSProxiesBSTreeCount,
                    & self -> http_proxies_cnt );

    if ( self -> http_proxies_cnt > 0 ) {
        self -> http_proxies = calloc ( self -> http_proxies_cnt,
                                        sizeof * self -> http_proxies );
        if ( self -> http_proxies == NULL )
            return NULL;
        DBGMSG ( DBG_KNS, DBG_FLAG ( DBG_KNS_PROXY ),
            ( "Will use %zu proxy spec%s%s\n", self -> http_proxies_cnt,
              self -> http_proxies_cnt > 1 ? "s" : "",
              self -> http_proxy_only ? "" : " and direct connection") );
    }

    self -> tmpS = 0;
    n = self -> http_proxies_cnt;
    srand ( time ( NULL ) );
    while ( n > 0 ) {
        self -> rand = rand () % n;
        self -> tmpI = 0;
        if ( ! BSTreeDoUntil ( & self -> proxie_tree, false,
                               KNSProxiesBSTreeSetRand, self ) )
        {
            BSTreeForEach ( & self -> proxie_tree, false,
                               KNSProxiesBSTreeInit, self ) ;
            n = 0;
        }
        else {
            const BSTItem * item = ( BSTItem * ) self -> tmpB;
            self -> http_proxies [ self -> tmpS ++ ] = item -> proxy;
            BSTreeUnlink ( & self -> proxie_tree, self -> tmpB );
            BSTItemWhack ( self -> tmpB, NULL );
            self -> tmpB = NULL;
            -- n;
        }
    }

/* BSTreeForEach ( & self -> proxie_tree, false, KNSProxiesBSTreeInit, self );*/

    for ( self -> tmpS = 1; self -> tmpS < self ->http_proxies_cnt;
       ++ self -> tmpS )
    {
        self -> http_proxies [ self -> tmpS - 1 ] -> next
            = self -> http_proxies [ self -> tmpS ];
    }

    return self;
}