LIB_EXPORT rc_t CC XFSOwpListKeys ( const struct XFSOwp * self, const struct KNamelist ** Keys ) { rc_t RCt; struct VNamelist * List; RCt = 0; if ( self == NULL || Keys == NULL ) { return XFS_RC ( rcNull ); } * Keys = NULL; RCt = VNamelistMake ( & List, 16 /* ?? */ ); if ( RCt == 0 ) { BSTreeForEach ( ( BSTree * ) self, false, _ListKeysCallback, List ); RCt = VNamelistToConstNamelist ( List, Keys ); VNamelistRelease ( List ); } return RCt; } /* XFSOwpListKeys () */
static rc_t print_fragments( BSTree * fragments ) { walk_fragment_ctx wctx; wctx.rc = 0; wctx.n = 0; BSTreeForEach ( fragments, false, on_fragment, &wctx ); return wctx.rc; }
void skiplist_report( const struct skiplist * list ) { if ( list != NULL ) { KOutMsg( "\n\nstart skiplist-report:\n" ); BSTreeForEach ( &( list->nodes ), false, skiplist_report_cb, NULL ); KOutMsg( "\nend skiplist-report\n\n" ); } }
rc_t foreach_reference( BSTree * regions, rc_t ( CC * on_reference ) ( const char * name, Vector *ranges, void *data ), void *data ) { foreach_reference_func func; func.on_reference = on_reference; func.data = data; func.rc = 0; BSTreeForEach ( regions, false, foreach_reference_wrapper, &func ); return func.rc; }
struct skiplist * skiplist_make( BSTree * regions ) { struct skiplist *res = calloc( 1, sizeof *res ); if ( res != NULL ) { BSTreeInit( &(res->nodes) ); res->current = NULL; res->node_count = 0; /* walk the given regions-tree to generate the skip-list */ BSTreeForEach ( regions, false, visit_region_node_for_skiplist, res ); if ( res->node_count == 0 ) { skiplist_release( res ); res = NULL; } } return res; }
static rc_t print_headers_by_recalculating( const samdump_opts * opts, input_files * ifs ) { rc_t rc = KOutMsg( "@HD\tVN:1.3\n" ); if ( rc == 0 ) { BSTree tree; /* collect sequenc-id's and names and their lengths, unique by sequence-id */ BSTreeInit( &tree ); rc = build_seq_id_tree( &tree, ifs ); if ( rc == 0 ) { hdr_print_ctx hctx; hctx.rc = 0; hctx.use_seq_id = opts->use_seqid_as_refname; /* ptrint it */ BSTreeForEach( &tree, false, print_header_callback, &hctx ); rc = hctx.rc; } free_seq_id_tree( &tree ); /* collect spot-groups ( unique ) */ if ( rc == 0 ) { VNamelist * spotgroups; rc = VNamelistMake( &spotgroups, 10 ); if ( rc == 0 ) { bool from_stats = false; rc = extract_spotgroups( spotgroups, ifs, from_stats ); if ( rc == 0 ) rc = print_spotgroups( spotgroups, from_stats ); else rc = 0; /* otherwise the tool would be not able to handle something that has no headers */ VNamelistRelease( spotgroups ); } } } return rc; }
static rc_t Load( SParam* param ) { rc_t rc = 0, rc1 = 0; BSTree slides, evidence; param->map_dir = NULL; param->asm_dir = NULL; param->output_dir = ( KDirectory * )param->input_dir; BSTreeInit( &slides ); BSTreeInit( &evidence ); rc = open_dir_or_tar( param->input_dir, ¶m->map_dir, param->map_path ); if ( rc == 0 ) { DirVisit_Data dv; dv.param = param; dv.tree = &slides; dv.dir = param->map_dir; rc = KDirectoryVisit( param->map_dir, true, DirVisitor, &dv, NULL ); if ( rc == 0 ) { if ( param->asm_path != NULL ) { rc_t rc2 = open_dir_or_tar( param->input_dir, ¶m->asm_dir, param->asm_path ); if ( rc2 == 0 ) { dv.tree = &evidence; dv.dir = param->asm_dir; rc = KDirectoryVisit( param->asm_dir, true, DirVisitor, &dv, NULL ); } } if ( rc == 0 ) { /* SHOULD HAVE A BSTreeEmpty FUNCTION OR SOMETHING... MAKE ONE HERE - WITH KNOWLEDGE THAT TREE IS NOT NULL: */ #ifndef BSTreeEmpty #define BSTreeEmpty( bst ) \ ( ( bst ) -> root == NULL ) #endif if ( BSTreeEmpty ( & slides ) && BSTreeEmpty ( & evidence ) ) rc = RC( rcExe, rcFile, rcReading, rcData, rcInsufficient ); else { /* CORRECTED SETTING OF "rc" IN "FGroupMAP_Validate" */ assert ( rc == 0 ); BSTreeForEach( &slides, false, FGroupMAP_Validate, &rc ); BSTreeForEach( &evidence, false, FGroupMAP_Validate, &rc ); } if ( rc == 0 ) { FGroupMAP_LoadData data; PLOGMSG( klogInfo, ( klogInfo, "file set validation complete", "severity=status" ) ); memset( &data, 0, sizeof( data ) ); data.rc = 0; data.param = param; data.reads = &slides; rc = DB_Init( param, &data.db ); if ( rc == 0 ) { BSTreeDoUntil( &slides, false, FGroupMAP_LoadReads, &data ); rc = data.rc; if ( rc == 0 ) { PLOGMSG( klogInfo, ( klogInfo, "MAP loaded", "severity=status" ) ); BSTreeDoUntil( &evidence, false, FGroupMAP_LoadEvidence, &data ); rc = data.rc; if ( rc == 0 ) PLOGMSG( klogInfo, ( klogInfo, "ASM loaded", "severity=status" ) ); } } rc1 = DB_Fini( param, &data.db, rc != 0 ); if ( rc == 0 ) rc = rc1; } } } /* copy the extra library ( file or recursive directory ) */ if ( rc == 0 && param->library != NULL ) { const KDirectory *lib_src; rc = open_dir_or_tar( param->input_dir, &lib_src, param->library ); if ( rc == 0 ) { rc = copy_library( param->input_dir, param->output_dir, param->library, param->out ); if ( rc == 0 ) STSMSG( 0, ( "extra lib copied" ) ); else LOGERR( klogErr, rc, "failed to copy extra library" ); KDirectoryRelease( lib_src ); } /* else { rc = copy_library( param->input_dir, param->output_dir, ".", param->out ); if ( rc == 0 ) STSMSG( 0, ( "extra lib copied" ) ); else LOGERR( klogErr, rc, "failed to copy extra library" ); } */ } KDirectoryRelease( param->map_dir ); KDirectoryRelease( param->asm_dir ); } BSTreeWhack( &slides, FGroupMAP_Whack, NULL ); BSTreeWhack( &evidence, FGroupMAP_Whack, NULL ); return rc; }
uint32_t count_ref_regions( BSTree * regions ) { uint32_t res = 0; BSTreeForEach ( regions, false, count_ref_region_wrapper, &res ); return res; }
void check_ref_regions( BSTree * regions, uint64_t merge_diff ) { BSTreeForEach ( regions, false, check_refrange_wrapper, &merge_diff ); }
void slice_report( BSTree * regions ) { KOutMsg( "\n\nstart slice-report:\n" ); BSTreeForEach ( regions, false, slice_report_wrapper, NULL ); KOutMsg( "\nend slice-report\n\n" ); }
/* TTransValidate * recursively checks structure */ int CC TTransValidate ( const TTrans *trans, const Trie *tt ) { int status = 0; TTValNodeCntData pb; unsigned int i, width; width = tt -> width; pb . depth = trans -> depth; pb . vcnt = pb . tcnt = 0; /* count transition array */ if ( trans -> child != NULL ) { for ( i = 0; i < width; ++ i ) { if ( trans -> child [ i ] != NULL ) ++ pb . tcnt; } } /* count value tree */ BSTreeForEach ( & trans -> vals, 0, TTransCountTNodes, & pb ); /* check validity */ if ( pb . tcnt != trans -> tcnt ) { LOGERR ( status = EINVAL, "bad trans -> tcnt => %u, should be %u", trans -> tcnt, pb . tcnt ); } /* should have a non-zero tcnt if has child array */ else if ( pb . tcnt == 0 && trans -> child != NULL ) { LOGERR ( status = EINVAL, "empty trans -> child", NULL ); /* 3rd parameter is wrong so far... */ } if ( pb . vcnt != trans -> vcnt ) { LOGERR ( status = EINVAL, "bad trans -> vcnt => %u, should be %u", trans -> vcnt, pb . vcnt ); } if ( trans -> child == NULL && pb . tcnt != 0 ) { if ( pb . tcnt + pb . vcnt > tt -> limit ) { /* LOGMSG ( "WARNING: over-limit actual value count => %u, should be %u\n", pb . tcnt + pb . vcnt, tt -> limit ); */ LOGMSG ( status = EINVAL, "WARNING: over-limit actual value count => %u, should be %u\n" ); } } if ( status == 0 && trans -> child != NULL ) { for ( i = 0; i < width; ++ i ) { const TTrans *child = trans -> child [ i ]; if ( child != NULL ) { if ( child -> depth != trans -> depth + 1 ) { LOGERR ( status = EINVAL, "bad trans -> depth => %u, should be %u", child -> depth, trans -> depth + 1 ); } else { int err = TTransValidate ( child, tt ); if ( status == 0 ) status = err; } } } } return status; }
static void check_ref_regions( BSTree * regions ) { BSTreeForEach ( regions, false, check_refrange_wrapper, 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; }