DepFixture(const char *path) : mgr(NULL) , vmgr(NULL) , resolver(NULL) , siteless(false) { rc_t rc = 0; KDirectory *wd = NULL; if (KDirectoryNativeDir(&wd)) { FAIL("failed to KDirectoryNativeDir"); } const KDirectory *dir = NULL; KConfig *cfg = NULL; if (KDirectoryOpenDirRead(wd, &dir, false, path)) { FAIL("failed to KDirectoryOpenDirRead()"); } if (KConfigMake(&cfg, dir)) { FAIL("failed to KConfigMake()"); } RELEASE(KDirectory, dir); if (VFSManagerMakeFromKfg(&vmgr, cfg)) { FAIL("failed to VFSManagerMakeFromKfg()"); } if (VFSManagerGetResolver(vmgr, &resolver)) { FAIL("failed to VFSManagerGetResolver"); } String *result = NULL; rc = KConfigReadString(cfg, "repository/site/main/tracearc/root", &result); if (rc != 0) { if (rc == SILENT_RC(rcKFG, rcNode, rcOpening, rcPath, rcNotFound)) { rc = 0; siteless = true; } else { FAIL( "failed to KConfigReadString(repository/site/main/tracearc/root)"); } } else { assert(result); KPathType t = KDirectoryPathType(wd, result->addr); if (t != kptDir) { siteless = true; } } RELEASE(String, result); RELEASE(KConfig, cfg); if (VDBManagerMakeReadWithVFSManager(&mgr, NULL, vmgr)) { FAIL("failed to VDBManagerMakeReadWithVFSManager()"); } RELEASE(KDirectory, wd); }
static String* _KConfigAscpString(const KConfig *self, const char *path, const char *name) { String *ascp = NULL; rc_t rc = KConfigReadString(self, path, &ascp); if (rc == 0) { assert(ascp); /* STSMSG(STS_INFO, ("Using %s from configuration: '%s'", name, ascp->addr)); */ return ascp; } else { if (rc != SILENT_RC(rcKFG, rcNode, rcOpening, rcPath, rcNotFound)) { DISP_RC(rc, path); } else { /* STSMSG(STS_DBG, ("'%s': not found in configuration", path)); */ } free(ascp); return NULL; } }
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; }