bool nlt_namelist_is_sub_set_in_full_set( const KNamelist * sub_set, const KNamelist * full_set ) { bool res = false; uint32_t count; rc_t rc = KNamelistCount( sub_set, &count ); if ( rc == 0 ) { uint32_t idx; uint32_t found = 0; for ( idx = 0; idx < count && rc == 0; ++idx ) { const char *s; rc = KNamelistGet( sub_set, idx, &s ); if ( rc == 0 && s != NULL && nlt_is_name_in_namelist( full_set, s ) ) found++; } res = ( rc == 0 && count == found ); } return res; }
static rc_t redactable_types_2_type_id_vector( const VSchema * s, const char * redactable_types, Vector * id_vector ) { const KNamelist *r_types; rc_t rc; if ( redactable_types == NULL || s == NULL || id_vector == NULL ) return RC( rcExe, rcNoTarg, rcResolving, rcParam, rcNull ); rc = nlt_make_namelist_from_string( &r_types, redactable_types ); if ( rc == 0 ) { uint32_t count, idx; rc = KNamelistCount( r_types, &count ); if ( rc == 0 && count > 0 ) for ( idx = 0; idx < count && rc == 0; ++idx ) { const char *name; rc = KNamelistGet( r_types, idx, &name ); if ( rc == 0 ) { VTypedecl td; rc = VSchemaResolveTypedecl ( s, &td, "%s", name ); if ( rc == 0 ) { uint32_t *id = malloc( sizeof *id ); if ( id != NULL ) { *id = td.type_id; rc = VectorAppend ( id_vector, NULL, id ); } else rc = RC( rcExe, rcNoTarg, rcResolving, rcMemory, rcExhausted ); } } } KNamelistRelease( r_types ); } return rc; }
static rc_t matcher_read_dst_types( matcher* self, const VTable *table, const VSchema *schema ) { rc_t rc = 0; uint32_t idx, len; if ( self == NULL ) return RC( rcExe, rcNoTarg, rcResolving, rcSelf, rcNull ); if ( table == NULL || schema == NULL ) return RC( rcExe, rcNoTarg, rcResolving, rcParam, rcNull ); len = VectorLength( &(self->mcols) ); for ( idx = 0; idx < len && rc == 0; ++idx ) { p_mcol item = (p_mcol) VectorGet ( &(self->mcols), idx ); if ( item != NULL ) { KNamelist *names; rc = VTableListWritableDatatypes ( (VTable*)table, item->name, &names ); if ( rc == 0 ) { uint32_t type_count; rc = KNamelistCount( names, &type_count ); if ( rc == 0 && type_count > 0 ) { uint32_t type_idx; item->to_copy = true; /* !!! this column has to be copied */ for ( type_idx = 0; type_idx < type_count && rc == 0; ++type_idx ) { const char *name; rc = KNamelistGet( names, type_idx, &name ); if ( rc == 0 ) rc = matcher_append_type( name, false, idx, schema, &(item->dst_types) ); } } KNamelistRelease( names ); } } } return rc; }
static rc_t copy_metadata_root ( const KMDataNode *src_root, KMDataNode *dst_root, const char * excluded_nodes, const bool show_meta ) { KNamelist *names; const KNamelist *excluded_names = NULL; uint32_t i, count; rc_t rc = KMDataNodeListChild ( src_root, & names ); DISP_RC( rc, "copy_metadata_root:KMDataNodeListChild() failed" ); if ( rc != 0 ) return rc; if ( excluded_nodes != NULL ) { rc = nlt_make_namelist_from_string( &excluded_names, excluded_nodes ); DISP_RC( rc, "copy_metadata_root:nlt_make_namelist_from_string() failed" ); if ( rc != 0 ) return rc; } rc = KNamelistCount ( names, & count ); for ( i = 0; rc == 0 && i < count; ++ i ) { const char *node_path; rc = KNamelistGet ( names, i, & node_path ); DISP_RC( rc, "copy_metadata_root:KNamelistGet() failed" ); if ( rc == 0 ) { bool is_excluded = false; if ( excluded_names != NULL ) is_excluded = nlt_is_name_in_namelist( excluded_names, node_path ); if ( !is_excluded ) rc = copy_metadata_child ( src_root, dst_root, node_path, show_meta ); } } if ( excluded_names != NULL ) KNamelistRelease( excluded_names ); KNamelistRelease ( names ); return rc; }
static rc_t KRepositoryMgrSubCategoryRepositories ( const KConfigNode *sub, KRepCategory category, KRepSubCategory subcategory, KRepositoryVector *repositories ) { KNamelist *repo_names; rc_t rc = KConfigNodeListChildren ( sub, & repo_names ); if ( rc == 0 ) { uint32_t i, count; rc = KNamelistCount ( repo_names, & count ); for ( i = 0; i < count && rc == 0; ++ i ) { const char *repo_name; rc = KNamelistGet ( repo_names, i, & repo_name ); if ( rc == 0 ) { const KConfigNode *node; rc = KConfigNodeOpenNodeRead ( sub, & node, repo_name ); if ( rc == 0 ) { KRepository *repo; rc = KRepositoryMake ( & repo, node, repo_name, category, subcategory ); if ( rc == 0 ) { rc = VectorAppend ( repositories, NULL, repo ); if ( rc != 0 ) KRepositoryWhack ( repo ); } KConfigNodeRelease ( node ); } } } KNamelistRelease ( repo_names ); } return rc; }
rc_t CopyDirectoryDirectories( const KDirectory *source, KDirectory *dest ) { rc_t rc; KNamelist *list; const char *name; int i; uint32_t count; uint32_t mode; uint32_t pathtype; KDirectoryList( source, &list, PathIsDir, NULL, "."); KNamelistCount(list, &count); for (i=0; i<count; i++) { KNamelistGet(list, i, &name); /* fprintf(stderr, "Creating directory %s\n", name); */ mode = DEFAULT_DIR_MODE; rc = KDirectoryAccess( source, &mode, "%s", name); if (rc != 0) { LOGERR ( klogInt, rc, name ); return rc; } pathtype = KDirectoryPathType( dest, "%s", name ); if ((pathtype & ~kptAlias) == kptNotFound) { rc = KDirectoryCreateDir( dest, mode, kcmOpen, "%s", name ); if (rc != 0) { LOGERR ( klogInt, rc, name ); return rc; } } else if ((pathtype & ~kptAlias) == kptDir) { if (clobber_protections) { KDirectorySetAccess( dest, false, mode, 0777, "%s", name); } } CopyDirectoryToExistingDirectory( source, name, dest, (char *)name); } return 0; }
static rc_t extract_spotgroups_from_stats( VNamelist * spotgroups, input_database * id, const KMetadata * meta ) { const KMDataNode * node; rc_t rc = KMetadataOpenNodeRead( meta, &node, "STATS/SPOT_GROUP" ); if ( rc != 0 ) (void)PLOGERR( klogErr, ( klogErr, rc, "cannot open meta-node 'STATS/SPOT_GROUP' from '$(t)'", "t=%s", id->path ) ); else { KNamelist * node_childs; rc = KMDataNodeListChildren( node, &node_childs ); if ( rc != 0 ) (void)PLOGERR( klogErr, ( klogErr, rc, "cannot list children of SPOT_GROUP-node in '$(t)'", "t=%s", id->path ) ); else { uint32_t n_count; rc = KNamelistCount( node_childs, &n_count ); if ( rc == 0 && n_count > 0 ) { uint32_t n_idx; for ( n_idx = 0; n_idx < n_count && rc == 0; ++n_idx ) { const char * spotgroup; rc = KNamelistGet( node_childs, n_idx, &spotgroup ); if ( rc == 0 && spotgroup != NULL ) { uint32_t found; rc_t rc1 = VNamelistIndexOf( spotgroups, spotgroup, &found ); if ( GetRCState( rc1 ) == rcNotFound ) rc = VNamelistAppend( spotgroups, spotgroup ); } } } KNamelistRelease( node_childs ); } KMDataNodeRelease( node ); } return rc; }
static void dump_db ( const KDatabase *db, int argc, char *argv [] ) { if ( argc >= 3 ) dump_tbl_name ( db, argv [ 2 ], argc, argv ); else { KNamelist *names; rc_t rc = KDatabaseListTbl ( db, & names ); if ( rc != 0 ) fprintf ( stderr, "failed to list tables for db '%s'\n", argv [ 1 ] ); else { uint32_t count; rc = KNamelistCount ( names, & count ); if ( rc != 0 ) fprintf ( stderr, "failed to count tables for db '%s'\n", argv [ 1 ] ); else { uint32_t i; for ( i = 0; i < count; ++ i ) { const char *name; rc = KNamelistGet ( names, i, & name ); if ( rc != 0 ) fprintf ( stderr, "failed to access table name [ %u ] for db '%s'\n", i, argv [ 1 ] ); else { dump_tbl_name ( db, name, argc, argv ); } } } KNamelistRelease ( names ); } } }
static rc_t matcher_build_column_vector( matcher* self, const char * columns ) { const KNamelist *list; uint32_t count, idx; rc_t rc = nlt_make_namelist_from_string( &list, columns ); if ( rc != 0 ) return rc; rc = KNamelistCount( list, &count ); if ( rc == 0 ) for ( idx = 0; idx < count && rc == 0; ++idx ) { const char *s; rc = KNamelistGet( list, idx, &s ); if ( rc == 0 ) { p_mcol new_col = matcher_make_col( s ); if ( new_col == NULL ) rc = RC( rcExe, rcNoTarg, rcResolving, rcMemory, rcExhausted ); if ( rc == 0 ) rc = VectorAppend( &(self->mcols), NULL, new_col ); } } KNamelistRelease( list ); return rc; }
static bool does_table_have_column( VTable const * tbl, char const column[] ) { KNamelist * column_names; bool res = false; rc_t rc = VTableListReadableColumns ( tbl, &column_names ); if ( rc == 0 ) { uint32_t count; rc = KNamelistCount ( column_names, &count ); if ( rc == 0 && count > 0 ) { uint32_t idx; size_t col_name_size; const char * col_name = string_chr ( column, string_size( column ), ')' ); if ( col_name == NULL ) col_name = column; else col_name++; col_name_size = string_size( col_name ); for ( idx = 0; idx < count && rc == 0 && !res; ++idx ) { const char * name; rc = KNamelistGet ( column_names, idx, &name ); if ( rc == 0 && name != NULL ) { int cmp = string_cmp( col_name, col_name_size, name, string_size( name ), 0xFFFF ); if ( cmp == 0 ) res = true; } } } KNamelistRelease ( column_names ); } return res; }
static rc_t ShowConfig(const KConfig* cfg, Params* prm) { rc_t rc = 0; bool hasAny = false; bool hasQuery = false; bool xml = true; assert(cfg && prm); xml = prm->xml; while (rc == 0) { KNamelist* names = NULL; const KConfigNode* node = NULL; uint32_t count = 0; uint32_t i = 0; int indent = 0; const char* root = NULL; const char* nodeName = NULL; size_t nodeNameL = 1; rc = ParamsGetNextParam(prm, &root); if (rc == 0) { if (root == NULL) { if (hasQuery) { break; } else { root = "/"; } } else { hasQuery = true; } assert(root); } if (rc == 0) { int64_t len = strlen(root); assert(len > 0); while (len > 0) { if (root[len - 1] == '/') { --len; } else { break; } } assert(len >= 0); if (len == 0) { root += strlen(root) - 1; nodeName = root; } else { char *c = memrchr(root, '/', len); if (c != NULL) { nodeName = c + 1; } else { nodeName = root; } } assert(nodeName && nodeName[0]); nodeNameL = strlen(nodeName); while (nodeNameL > 1 && nodeName[nodeNameL - 1] == '/') { --nodeNameL; } } if (rc == 0) { rc = KConfigOpenNodeRead(cfg, &node, root); DISP_RC(rc, root); } if (rc == 0) { rc = KConfigNodeListChild(node, &names); } if (rc == 0) { rc = KNamelistCount(names, &count); } if (rc == 0 && count == 0) { char buf[512] = ""; size_t num_read = 0; rc = KConfigNodeReadData(node, buf, sizeof buf, &num_read); if (rc == 0 && num_read > 0) { if (prm->showMultiple) { OUTMSG(("<!-- Configuration node %s -->\n", root)); } if (xml) { VDB_CONGIG_OUTMSG(("<%.*s>", nodeNameL, nodeName)); VDB_CONGIG_OUTMSG(("%.*s", (int)num_read, buf)); VDB_CONGIG_OUTMSG(("</%.*s>\n", nodeNameL, nodeName)); } else { OUTMSG(("%.*s = \"%.*s\"\n", nodeNameL, nodeName, (int)num_read, buf)); } hasAny = true; } } else { if (rc == 0) { if (nodeName[0] != '/') { if (prm->showMultiple) { OUTMSG(("<!-- Configuration node %s -->\n", root)); } VDB_CONGIG_OUTMSG(("<%.*s>\n", nodeNameL, nodeName)); } else { if (prm->showMultiple) { OUTMSG(("<!-- Current configuration -->\n")); } VDB_CONGIG_OUTMSG(("<Config>\n")); } hasAny = true; ++indent; } for (i = 0; i < count && rc == 0; ++i) { const char* name = NULL; if (rc == 0) { rc = KNamelistGet(names, i, &name); } if (rc == 0) { char* fullname = NULL; if (strcmp(root, "/") == 0) { fullname = malloc(strlen(name) + 2); if (fullname == NULL) { rc = RC(rcExe, rcStorage, rcAllocating, rcMemory, rcExhausted); } sprintf(fullname, "/%s", name); } else { fullname = strdup(root); if (fullname == NULL) { rc = RC(rcExe, rcStorage, rcAllocating, rcMemory, rcExhausted); } } if (rc == 0) { rc = KConfigNodePrintChildNames (xml, node, name, indent, fullname); hasAny = true; } free(fullname); fullname = NULL; } } if (rc == 0) { if (nodeName[0] != '/') { VDB_CONGIG_OUTMSG(("</%.*s>\n", nodeNameL, nodeName)); } else { VDB_CONGIG_OUTMSG(("</Config>\n")); } } } RELEASE(KConfigNode, node); RELEASE(KNamelist, names); if (rc == 0) { if (hasAny) { OUTMSG(("\n")); } else if (nodeNameL > 0 && nodeName != NULL) { VDB_CONGIG_OUTMSG(("<%.*s/>\n", nodeNameL, nodeName)); } } if (!hasQuery) { break; } } return rc; }
static rc_t ShowModules(const KConfig* cfg, const Params* prm) { rc_t rc = 0; #ifdef _STATIC OUTMSG(("<!-- Modules are not used in static build -->\n")); #else const VDBManager* mgr = NULL; KNamelist* list = NULL; OUTMSG(("<!-- Modules -->\n")); rc = VDBManagerMakeRead(&mgr, NULL); DISP_RC(rc, "while calling VDBManagerMakeRead"); if (rc == 0) { rc = VDBManagerListExternalSchemaModules(mgr, &list); DISP_RC(rc, "while calling VDBManagerListExternalSchemaModules"); } if (rc == 0) { uint32_t count = 0; rc = KNamelistCount(list, &count); DISP_RC(rc, "while calling KNamelistCount " "on VDBManagerListExternalSchemaModules result"); if (rc == 0) { int64_t i = 0; for (i = 0; i < count && rc == 0; ++i) { const char* name = NULL; rc = KNamelistGet(list, i, &name); DISP_RC(rc, "while calling KNamelistGet " "on VDBManagerListExternalSchemaModules result"); if (rc == 0) { OUTMSG(("%s\n", name)); } } } } OUTMSG(("\n")); RELEASE(KNamelist, list); RELEASE(VDBManager, mgr); #endif #if 0 KDirectory* dir = NULL; const char* paths[] = { "vdb/module/paths", "vdb/wmodule/paths" }; int i = 0; assert(cfg); for (i = 0; i < sizeof paths / sizeof paths[0] && rc == 0; ++i) { const KConfigNode* node = NULL; if (rc == 0) { const char* path = paths[i]; rc = KConfigOpenNodeRead(cfg, &node, path); if (rc != 0) { if (GetRCState(rc) == rcNotFound) { rc = 0; continue; } else { DISP_RC(rc, path); } } else { char buf[PATH_MAX + 1]; size_t num_read = 0; size_t remaining = 0; rc = KConfigNodeRead(node, 0, buf, sizeof buf, &num_read, &remaining); assert(remaining == 0); assert(num_read <= sizeof buf); DISP_RC(rc, path); if (rc == 0) { if (num_read < sizeof buf) { buf[num_read] = '\0'; if (dir == NULL) { rc = KDirectoryNativeDir(&dir); } if (rc == 0) { OUTMSG(("%s = %s\n", path, buf)); rc = ShowModDir(dir, buf); if (rc == 0) { OUTMSG(("\n")); } } } } } RELEASE(KConfigNode, node); } } RELEASE(KDirectory, dir); #endif return rc; }
static rc_t KConfigNodePrintChildNames(bool xml, const KConfigNode* self, const char* name, int indent, const char* aFullpath) { rc_t rc = 0; uint32_t count = 0; int i = 0; char buffer[512] = ""; size_t num_read = 0; bool hasChildren = false; bool hasData = false; const KConfigNode* node = NULL; KNamelist* names = NULL; assert(self && name); if (rc == 0) { rc = KConfigNodeOpenNodeRead(self, &node, name); } if (rc == 0) { rc = KConfigNodeReadData(node, buffer, sizeof buffer, &num_read); hasData = num_read; if (hasData) { /* VDB_CONGIG_OUTMSG(("\n%s = \"%.*s\"\n\n", aFullpath, num_read, buffer)); */ } } if (rc == 0) { rc = KConfigNodeListChild(node, &names); } if (rc == 0) { rc = KNamelistCount(names, &count); hasChildren = count; } Indent(xml, indent); VDB_CONGIG_OUTMSG(("<%s", name)); if (!hasChildren && !hasData) { VDB_CONGIG_OUTMSG(("/>\n")); } else { VDB_CONGIG_OUTMSG((">")); } if (hasData) { if (xml) { VDB_CONGIG_OUTMSG(("%.*s", (int)num_read, buffer)); } else { OUTMSG(("%s = \"%.*s\"\n", aFullpath, (int)num_read, buffer)); } } if (hasChildren) { VDB_CONGIG_OUTMSG(("\n"));} if (hasChildren) { for (i = 0; i < count && rc == 0; ++i) { char* fullpath = NULL; const char* name = NULL; rc = KNamelistGet(names, i, &name); if (rc == 0) { fullpath = malloc(strlen(aFullpath) + 1 + strlen(name) + 1); if (fullpath == NULL) { rc = RC (rcExe, rcStorage, rcAllocating, rcMemory, rcExhausted); } else { sprintf(fullpath, "%s/%s", aFullpath, name); } } if (rc == 0) { rc = KConfigNodePrintChildNames (xml, node, name, indent + 1, fullpath); } free(fullpath); } } if (hasChildren) { Indent(xml, indent); } if (hasChildren || hasData) { VDB_CONGIG_OUTMSG(("</%s>\n",name)); } RELEASE(KNamelist, names); RELEASE(KConfigNode, node); return rc; }
static rc_t TarNode_MakeFileList(const KXMLNode* xml_node, const TarFileList** files, char* errmsg, const char* rel_path, const char* name) { rc_t rc = 0; time_t now = time(NULL); uint32_t count = 0; *files = NULL; if( (rc = KXMLNodeCountChildNodes(xml_node, &count)) == 0 ) { if( count == 0 ) { rc = RC(rcExe, rcDoc, rcValidating, rcData, rcEmpty); } else if( (rc = TarFileList_Make(files, count, name)) == 0 ) { uint32_t i = 0; while(rc == 0 && i < count) { const KXMLNode* n = NULL; const char* n_name; if( (rc = KXMLNodeGetNodeRead(xml_node, &n, i++)) == 0 && (rc = KXMLNodeElementName(n, &n_name)) == 0 ) { if( strcmp(n_name, "Item") != 0 ) { rc = RC(rcExe, rcDoc, rcValidating, rcNode, rcUnexpected); strcpy(errmsg, n_name); } else { size_t sz_read; char path[4096], name[4096]; KTime_t ts = now; uint64_t fsz = 0; bool exec = false; if( (rc = KXMLNodeReadAttrCString(n, "path", name, sizeof(name), &sz_read)) == 0 ) { if( name[0] == '\0' ) { rc = RC(rcExe, rcDoc, rcValidating, rcAttr, rcEmpty); } else if( name[0] == '/' ) { memmove(path, name, sz_read + 1); } else { KDirectory* dir = NULL; if( (rc = KDirectoryNativeDir(&dir)) == 0 && (rc = KDirectoryResolvePath(dir, true, path, sizeof(path), "%s/%s", rel_path, name)) == 0 ) { DEBUG_LINE(8, "%s/%s resolved to %s", rel_path, name, path); } KDirectoryRelease(dir); } if( rc != 0 ) { strcpy(errmsg, "TAR/Item/@path"); } } if( rc == 0 && (rc = XML_ParseTimestamp(n, "timestamp", &ts, true)) != 0 ) { strcpy(errmsg, "TAR/Item/@timestamp"); } if( rc == 0 && (rc = XML_ParseBool(n, "executable", &exec, true)) != 0 ) { strcpy(errmsg, "TAR/Item/@executable"); } if( rc == 0 && (rc = KXMLNodeReadAttrAsU64(n, "size", &fsz)) != 0 ) { strcpy(errmsg, "TAR/Item/@size"); } if( rc == 0 ) { name[0] = '\0'; rc = KXMLNodeReadAttrCString(n, "name", name, sizeof(name), &sz_read); if( (GetRCObject(rc) == (enum RCObject)rcAttr && GetRCState(rc) == rcNotFound) || name[0] == '\0' ) { char* x = strrchr(path, '/'); strcpy(name, x ? x + 1 : path); rc = 0; } else if( rc == 0 && name[0] == '/' ) { strcat(errmsg, "Item/@name cannot be absolute"); rc = RC(rcExe, rcDoc, rcValidating, rcName, rcInvalid); } else if( rc != 0 ) { strcpy(errmsg, "Item/@name"); } } if( rc == 0 ) { const KNamelist* attr = NULL; if( (rc = KXMLNodeListAttr(n, &attr)) == 0 ) { uint32_t j = 0, count = 0; if( (rc = KNamelistCount(attr, &count)) == 0 && count > 0 ) { while( rc == 0 && j < count ) { const char *attr_nm = NULL; if( (rc = KNamelistGet(attr, j++, &attr_nm)) != 0 ) { break; } if( strcmp("path", attr_nm) == 0 || strcmp("name", attr_nm) == 0 || strcmp("timestamp", attr_nm) == 0 || strcmp("size", attr_nm) == 0 || strcmp("executable", attr_nm) == 0 ) { continue; } rc = RC(rcExe, rcDoc, rcValidating, rcDirEntry, rcInvalid); strcpy(errmsg, "unknown attribute TAR/Item/@"); strcat(errmsg, attr_nm); } } ReleaseComplain(KNamelistRelease, attr); } } if( rc == 0 && (rc = TarFileList_Add(*files, path, name, fsz, ts, exec)) != 0 ) { strcpy(errmsg, "adding to TAR"); } } ReleaseComplain(KXMLNodeRelease, n); } } if( rc != 0 ) { TarFileList_Release(*files); *files = NULL; } } } return rc; }
static rc_t RefSeqMgr_KfgReadRepositories(const KConfig* kfg, char* paths, size_t paths_sz) { /* servers are children of refseq/repository, e.g.: /refseq/repository/main="..." */ /* volumes are in refseq/repository/<serverName>/volumes, e.g.: /refseq/repository/main/volumes="..." */ /* all server/volume combinations are returned in paths separated by ':' */ rc_t rc = 0; const KConfigNode *node; #define KFG_PATH "/refseq/repository/" paths[0] = 0; rc = KConfigOpenNodeRead ( kfg, & node, KFG_PATH ); if ( rc == 0 ) { KNamelist* children; rc = KConfigNodeListChild ( node, &children ); if ( rc == 0 ) { uint32_t count; rc = KNamelistCount ( children, &count ); if ( rc == 0 ) { uint32_t i; for (i = 0; i < count; ++i) /* for all servers */ { const char* name; rc = KNamelistGet ( children, i, &name ); if ( rc == 0 ) { #define BufSize 4096 char server[ BufSize ]; char buf[ BufSize ]; size_t num_writ; rc = string_printf(buf, BufSize, &num_writ, KFG_PATH "%s", name); if (rc == 0) { rc = RefSeqMgr_ConfigValue ( kfg, buf, server, sizeof(server) ); if (rc == 0) { rc = string_printf(buf, BufSize, &num_writ, KFG_PATH "%s/volumes", name); if (rc == 0) { char volumes[ BufSize ]; rc = RefSeqMgr_ConfigValue ( kfg, buf, volumes, sizeof(volumes) ); if (rc == 0) { /* create a server/volume pair for every combination, append to paths, ':' - separate */ char *vol_rem = volumes; char *vol_sep; do { char const *volume = vol_rem; vol_sep = string_chr(volume, string_size(volume), ':'); if(vol_sep) { vol_rem = vol_sep + 1; *vol_sep = 0; } string_copy(paths + string_size(paths), paths_sz - string_size(paths), server, string_size(server)); if (paths[string_size(paths)-1] != '/') { string_copy(paths + string_size(paths), paths_sz - string_size(paths), "/", 1); } string_copy(paths + string_size(paths), paths_sz - string_size(paths), volume, string_size(volume)); string_copy(paths + string_size(paths), paths_sz - string_size(paths), ":", 1); } while(vol_sep); } } } } #undef BufSize } if ( rc != 0 ) { break; } } } KNamelistRelease ( children ); } KConfigNodeRelease ( node ); } if (GetRCState(rc) == rcNotFound) { paths[0] = '\0'; return 0; } return 0; }
static rc_t qual_stats(const Params* prm, const VDatabase* db) { rc_t rc = 0; const char tblName[] = "SEQUENCE"; const VTable* tbl = NULL; const KMetadata* meta = NULL; const KMDataNode* node = NULL; assert(prm && db); if (rc == 0) { rc = VDatabaseOpenTableRead(db, &tbl, tblName); DISP_RC2(rc, tblName, "while calling VDatabaseOpenTableRead"); } if (rc == 0) { rc = VTableOpenMetadataRead(tbl, &meta); DISP_RC2(rc, tblName, "while calling VTableOpenMetadataRead"); } if (rc == 0) { bool found = false; const char path[] = "STATS/QUALITY"; rc = KMetadataOpenNodeRead(meta, &node, path); if (rc == 0) { found = true; } else if (GetRCState(rc) == rcNotFound) { rc = 0; } DISP_RC2(rc, path, "while calling KMetadataOpenNodeRead"); if (found) { uint32_t i = 0; int nbr = 0; uint32_t count = 0; KNamelist* names = NULL; int* quals = NULL; if (rc == 0) { rc = KMDataNodeListChild(node, &names); DISP_RC2(rc, path, "while calling KMDataNodeListChild"); } if (rc == 0) { rc = KNamelistCount(names, &count); DISP_RC2(rc, path, "while calling KNamelistCount"); if (rc == 0 && count > 0) { quals = calloc(count, sizeof *quals); if (quals == NULL) { rc = RC(rcExe, rcStorage, rcAllocating, rcMemory, rcExhausted); } } } for (i = 0; i < count && rc == 0; ++i) { /* uint64_t u = 0; const KMDataNode* n = NULL; */ const char* nodeName = NULL; const char* name = NULL; rc = KNamelistGet(names, i, &nodeName); DISP_RC2(rc, path, "while calling KNamelistGet"); if (rc) { break; } name = nodeName; /* rc = KMDataNodeOpenNodeRead(node, &n, name); DISP_RC(rc, name); if (rc == 0) { rc = KMDataNodeReadAsU64(n, &u); DISP_RC(rc, name); } */ if (rc == 0) { char* c = strchr(name, '_'); if (c != NULL && *(c + 1) != '\0') { name = c + 1; if (sscanf(name, "%d", &quals[i]) != 1) { rc = RC(rcExe, rcNode, rcParsing, rcName, rcUnexpected); PLOGERR(klogInt, (klogInt, rc, "$(name)", "name=%s", nodeName)); } } /* OUTMSG(("QUALITY %s %lu\n", name, u)); */ } /* DESTRUCT(KMDataNode, n); */ } if (rc == 0 && count > 0) { ksort(quals, count, sizeof *quals, sort_callback, NULL); } if (rc == 0) { OUTMSG(("%s", prm->dbPath)); } for (i = 0, nbr = 0; i < count && rc == 0; ++i, ++nbr) { uint64_t u = 0; char name[64]; const KMDataNode* n = NULL; sprintf(name, "PHRED_%d", quals[i]); rc = KMDataNodeOpenNodeRead(node, &n, name); DISP_RC(rc, name); if (rc == 0) { rc = KMDataNodeReadAsU64(n, &u); DISP_RC(rc, name); if (rc == 0) { while (nbr < quals[i]) { OUTMSG(("\t0")); ++nbr; } OUTMSG(("\t%lu", u)); /* OUTMSG(("QUALITY %d %lu\n", quals[i], u)); */ } } DESTRUCT(KMDataNode, n); } while (rc == 0 && nbr <= 40) { OUTMSG(("\t0")); nbr++; } if (rc == 0) { OUTMSG(("\n")); } DESTRUCT(KNamelist, names); } } DESTRUCT(KMDataNode, node); DESTRUCT(KMetadata, meta); DESTRUCT(VTable, tbl); return rc; }
static rc_t DoDir (const KDirectory * sd, KDirectory * dd) { KNamelist * names; rc_t rc; rc = KDirectoryList (sd, &names, NULL, NULL, "."); if (rc) ; else { uint32_t count; rc = KNamelistCount (names, &count); if (rc) ; else { uint32_t idx; for (idx = 0; idx < count; ++idx) { const char * name; rc = KNamelistGet (names, idx, &name); if (rc) ; else { const KDirectory * nsd; KDirectory * ndd; KPathType kpt; kpt = KDirectoryPathType (sd, name); switch (kpt) { default: break; case kptFile: if (sd == dd) rc = FileInPlace (dd, name, true); else rc = FileToFile (sd, name, dd, name, true, NULL); break; case kptDir: if (sd == dd) { rc = KDirectoryOpenDirUpdate (dd, &ndd, false, "%s", name); if (rc) ; else { /* RECURSION */ STSMSG (1, ("%scrypting directory %s", De, name)); rc = DoDir (ndd, ndd); STSMSG (1, ("done with directory %s", name)); KDirectoryRelease (ndd); } } else { rc = KDirectoryOpenDirRead (sd, &nsd, false, name); if (rc) ; else { rc = KDirectoryCreateDir (dd, 0600, kcmOpen, "%s", name); if (rc) ; else { rc = KDirectoryOpenDirUpdate (dd, &ndd, false, "%s", name); if (rc) ; else { /* RECURSION */ STSMSG (1, ("%scrypting directory %s", De, name)); rc = DoDir (nsd, ndd); STSMSG (1, ("done with directory %s", name)); KDirectoryRelease (ndd); } } KDirectoryRelease (nsd); } } break; } } } } KNamelistRelease (names); } return rc; }
/* filter will let us add the add to and extract by name things to kar */ static rc_t step_through_dir (const KDirectory * dir, const char * path, bool ( CC * filter)(const KDirectory *, const char *, void *), void * fdata, rc_t ( CC * action)(const KDirectory *, const char *, void *), void * adata) { rc_t rc; KNamelist * names; STSMSG (4, ("step_through_dir %s\n", path)); rc = KDirectoryList (dir, &names, NULL, NULL, path); if (rc == 0) { uint32_t limit; rc = KNamelistCount (names, &limit); if (rc == 0) { uint32_t idx; size_t pathlen; pathlen = strlen(path); for (idx = 0; idx < limit; idx ++) { const char * name; rc = KNamelistGet (names, idx, &name); if (rc == 0) { char * new_path; size_t namelen; size_t new_pathlen; size_t rsize; namelen = strlen (name); new_pathlen = pathlen + 1 + namelen; rsize = new_pathlen + 1; new_path = malloc (rsize); if (new_path != NULL) { char * recur_path; if (pathlen == 0) { memcpy (new_path, name, namelen); new_path[namelen] = '\0'; } else { memcpy (new_path, path, pathlen); new_path[pathlen] = '/'; memcpy (&new_path[pathlen+1], name, namelen); new_path[new_pathlen] = '\0'; } recur_path = malloc (rsize); if (recur_path != NULL) { rc = KDirectoryVResolvePath (dir, false, recur_path, rsize, new_path, NULL); if (rc == 0) { bool use_name; if (filter != NULL) { use_name = filter (dir, recur_path, fdata); } else { use_name = true; } if (use_name) { rc = action (dir, recur_path, adata); /* if (rc == 0) */ /* { */ /* enum KPathType type; */ /* type = (enum KPathType)KDirectoryPathType (dir, recur_path); */ /* if (type == kptDir) */ /* rc = step_through_dir (dir, recur_path, filter, fdata, action, adata); */ /* } */ } } free (recur_path); } free (new_path); } } if (rc != 0) break; } } KNamelistRelease (names); } return rc; }
LIB_EXPORT rc_t CC VTableExtendSchema ( const VTable *self ) { rc_t rc; if ( self == NULL ) rc = RC ( rcVDB, rcTable, rcUpdating, rcSelf, rcNull ); else { /* create symbol table for STable */ KSymTable tbl; rc = init_tbl_symtab ( & tbl, self -> schema, self -> stbl ); if ( rc == 0 ) { KNamelist *names; const char *name; uint32_t i, count; /* list all physical tables from KTable */ rc = KTableListCol ( self -> ktbl, & names ); if ( rc != 0 ) rc = 0; else { rc = KNamelistCount ( names, & count ); for ( i = 0; rc == 0 && i < count; ++ i ) { /* if there are any stray columns, add them in */ rc = KNamelistGet ( names, i, & name ); if ( rc == 0 && VTableNameAvail ( & tbl, name ) ) rc = VTablePopulateStrayKColumn ( self, name ); } KNamelistRelease ( names ); } if ( rc == 0 ) { /* access table's static columns */ const KMDataNode *cols = self -> col_node; if ( cols != NULL ) { /* list all columns */ rc = KMDataNodeListChild ( cols, & names ); if (rc == 0) { rc = KNamelistCount ( names, & count ); for ( i = 0; rc == 0 && i < count; ++ i ) { rc = KNamelistGet ( names, i, & name ); if ( rc == 0 && VTableNameAvail ( & tbl, name ) ) { const KMDataNode *node; rc = KMDataNodeOpenNodeRead ( cols, & node, "%s", name ); if ( rc == 0 ) { /* add in static column */ rc = VTablePopulateStrayStatic ( self, name, node ); KMDataNodeRelease ( node ); } } } KNamelistRelease ( names ); } } } } KSymTableWhack ( & tbl ); } return rc; }
static rc_t CC _LoadKartScanChildren ( const struct XFSModel * Model, const struct XFSModelNode * Template, struct XFSKartCollectionNode * Node ) { rc_t RCt; const struct KNamelist * Children; uint32_t ChildrenQty, llp; const char * ChildName, * ChildAlias; const struct XFSNode * TheNode; RCt = 0; Children = NULL; ChildrenQty = 0; ChildName = ChildAlias = NULL; TheNode = NULL; RCt = XFSModelNodeChildrenNames ( Template, & Children ); if ( RCt == 0 ) { RCt = KNamelistCount ( Children, & ChildrenQty ); if ( RCt == 0 ) { for ( llp = 0; llp < ChildrenQty; llp ++ ) { RCt = KNamelistGet ( Children, llp, & ChildName ); if ( RCt == 0 ) { ChildAlias = XFSModelNodeChildAlias ( Template, ChildName ); RCt = XFSNodeMake ( Model, ChildName, ChildAlias, & TheNode ); if ( RCt == 0 ) { RCt = XFSContNodeAddChild ( & ( Node -> node . node ), TheNode ); /* Don't know what to do here */ } if ( RCt != 0 ) { break; } } } } KNamelistRelease ( Children ); } return RCt; } /* _LoadKartScanChildren () */
static rc_t copy_metadata_child ( const KMDataNode *src_root, KMDataNode *dst_root, const char *node_path, const bool show_meta ) { const KMDataNode *snode; KMDataNode *dnode; KNamelist *names; rc_t rc = KMDataNodeOpenNodeRead ( src_root, & snode, node_path ); DISP_RC( rc, "copy_metadata_child:KMDataNodeOpenNodeRead(src) failed" ); if ( rc != 0 ) return rc; if ( show_meta ) KOutMsg( "copy child-node: %s\n", node_path ); rc = KMDataNodeOpenNodeUpdate ( dst_root, & dnode, node_path ); DISP_RC( rc, "copy_metadata_child:KMDataNodeOpenNodeUpdate(dst) failed" ); if ( rc == 0 ) { rc = copy_metadata_data ( snode, dnode ); if ( rc == 0 ) rc = copy_metadata_attribs ( snode, dnode, node_path, show_meta ); KMDataNodeRelease ( dnode ); } else { PLOGMSG( klogInfo, ( klogInfo, "cannot open child-node(dst): $(node)", "node=%s", node_path )); } if ( rc == 0 || ( GetRCState( rc ) == rcBusy ) ) { rc = KMDataNodeListChild ( snode, & names ); DISP_RC( rc, "copy_metadata_child:KMDataNodeListChild(src) failed" ); if ( rc == 0 ) { uint32_t i, count; char temp_path[ 1024 ]; size_t temp_len; string_copy ( temp_path, ( sizeof temp_path ) - 1, node_path, string_size( node_path ) ); temp_len = string_size( temp_path ); temp_path[ temp_len++ ] = '/'; temp_path[ temp_len ] = 0; rc = KNamelistCount ( names, & count ); for ( i = 0; rc == 0 && i < count; ++ i ) { const char *child_name; rc = KNamelistGet ( names, i, & child_name ); if ( rc == 0 ) { string_copy( temp_path + temp_len, ( sizeof temp_path ) - temp_len, child_name, string_size( child_name ) ); rc = copy_metadata_child ( src_root, dst_root, temp_path, show_meta ); temp_path[ temp_len ] = 0; } } KNamelistRelease ( names ); } } KMDataNodeRelease ( snode ); return rc; }
/* ListPhysColumns * avail: 2.4 */ LIB_EXPORT rc_t CC VTableListPhysColumns ( const VTable *self, KNamelist **names ) { rc_t rc; if ( names == NULL ) rc = RC ( rcVDB, rcTable, rcListing, rcParam, rcNull ); else { * names = NULL; if ( self == NULL ) rc = RC ( rcVDB, rcTable, rcListing, rcSelf, rcNull ); else { KNamelist *kcol_names; rc = KTableListCol ( self -> ktbl, & kcol_names ); if ( rc == 0 ) { uint32_t kcol_count; rc = KNamelistCount ( kcol_names, & kcol_count ); if ( rc == 0 ) { uint32_t scol_count = 0; KNamelist *scol_names = NULL; const KMDataNode *col_node = self -> col_node; #if LAZY_OPEN_COL_NODE if ( col_node == NULL ) { rc = KMetadataOpenNodeRead ( self -> meta, & ( ( VTable* ) self ) -> col_node, "col" ); if ( rc == 0 || GetRCState ( rc ) != rcNotFound ) col_node = self -> col_node; } #endif if ( col_node != NULL ) { rc = KMDataNodeListChildren ( col_node, & scol_names ); if ( rc == 0 ) rc = KNamelistCount ( scol_names, & scol_count ); } if ( rc == 0 ) { VNamelist *vnames; rc = VNamelistMake ( & vnames, kcol_count + scol_count ); if ( rc == 0 ) { uint32_t i; const char *name; for ( i = 0; i < kcol_count && rc == 0; ++ i ) { rc = KNamelistGet ( kcol_names, i, & name ); if ( rc == 0 ) rc = VNamelistAppend ( vnames, name ); } for ( i = 0; i < scol_count && rc == 0; ++ i ) { rc = KNamelistGet ( scol_names, i, & name ); if ( rc == 0 ) rc = VNamelistAppend ( vnames, name ); } if ( rc == 0 ) { rc = VNamelistToNamelist ( vnames, names ); if ( rc == 0 ) VNamelistReorder ( vnames, false ); } } VNamelistRelease ( vnames ); } KNamelistRelease ( scol_names ); } KNamelistRelease ( kcol_names ); } } } return rc; }
/* filter will let us add the add to and extract by name things to kar */ static rc_t step_through_dir (const KDirectory * dir, const char * path, rc_t (*action)(const KDirectory *, const char *, void *), void * adata) { rc_t rc; KNamelist * names; STSMSG (4, ("step_through_dir %s\n", path)); rc = KDirectoryList (dir, &names, NULL, NULL, "%s", path); if (rc == 0) { uint32_t limit; rc = KNamelistCount (names, &limit); if (rc == 0) { uint32_t idx; size_t pathlen; pathlen = strlen(path); for (idx = 0; (rc == 0) && (idx < limit); idx ++) { const char * name; rc = KNamelistGet (names, idx, &name); if (rc == 0) { size_t namelen = strlen (name); size_t new_pathlen = pathlen + 1 + namelen; char * new_path = malloc (new_pathlen + 1); if (new_path != NULL) { char * recur_path; if (pathlen == 0) { memmove (new_path, name, namelen); new_path[namelen] = '\0'; } else { memmove (new_path, path, pathlen); new_path[pathlen] = '/'; memmove (new_path + pathlen + 1, name, namelen); new_path[pathlen+1+namelen] = '\0'; } recur_path = malloc (pathlen + 1 + namelen + 1); if (recur_path != NULL) { rc = KDirectoryResolvePath (dir, false, recur_path, pathlen + 1 + namelen + 1, "%s", new_path); if (rc == 0) rc = action (dir, recur_path, adata); free (recur_path); } free (new_path); } } } } KNamelistRelease (names); } return rc; }
static rc_t foreach_path_obj( visit_ctx * ctx, on_path_t func ) { rc_t rc = 0; ctx->path_type = ( KDirectoryPathType ( ctx->dir, "%s", ctx->path ) & ~ kptAlias ); if ( ctx->path_type == kptDir ) { KNamelist * path_objects; rc = KDirectoryList ( ctx->dir, &path_objects, NULL, NULL, "%s", ctx->path ); if ( rc != 0 ) { PLOGERR( klogErr, ( klogErr, rc, "KDirectoryList( $(path) ) failed in $(func)", "path=%s,func=%s", ctx->path, __func__ ) ); } else { uint32_t idx, count; rc = KNamelistCount ( path_objects, &count ); if ( rc != 0 ) { PLOGERR( klogErr, ( klogErr, rc, "KNamelistCount() failed in $(func)", "func=%s", __func__ ) ); } for ( idx = 0; idx < count && rc == 0 && !ctx->terminate; ++idx ) { const char * obj_name = NULL; rc = KNamelistGet ( path_objects, idx, &obj_name ); if ( rc != 0 ) { PLOGERR( klogErr, ( klogErr, rc, "KNamelistGet( $(idx) ) failed in $(func)", "idx=%d,func=%s", idx, __func__ ) ); } else if ( obj_name != NULL ) { char obj_path[ 4096 ]; rc = KDirectoryResolvePath ( ctx->dir, true, obj_path, sizeof obj_path, "%s/%s", ctx->path, obj_name ); if ( rc != 0 ) { PLOGERR( klogErr, ( klogErr, rc, "KDirectoryResolvePath( $(path) ) failed in $(func)", "path=%s,func=%s", ctx->path, __func__ ) ); } else { visit_ctx octx; octx.dir = ctx->dir; octx.options = ctx->options; octx.path = obj_path; octx.data = ctx->data; octx.path_type = ( KDirectoryPathType ( ctx->dir, "%s", obj_path ) & ~ kptAlias ); if ( octx.path_type == kptDir ) { rc = foreach_path_obj( &octx, func ); /* recursion !!! */ } else if ( octx.path_type == kptFile ) { rc = func( &octx ); } } } } { rc_t rc2 = KNamelistRelease ( path_objects ); if ( rc2 != 0 ) { PLOGERR( klogErr, ( klogErr, rc2, "KNamelistRelease() failed in $(func)", "func=%s", __func__ ) ); } } } } if ( rc == 0 && ( ctx->path_type == kptDir || ctx->path_type == kptFile ) && !ctx->terminate ) { /* at the very end of it, call the function for the path itself */ rc = func( ctx ); } return rc; }