Esempio n. 1
0
static rc_t resolve_accession( VFSManager * vfs_mgr, const char * accession, const String ** path )
{
    VResolver * resolver;
    rc_t rc = VFSManagerGetResolver( vfs_mgr, &resolver );
    if ( rc == 0 )
    {
        const VPath * vpath;
        rc = VPathMakeSysPath( ( VPath** )&vpath, accession );
        if ( rc == 0 )
        {
            const VPath * rpath;
            rc = VResolverLocal( resolver, vpath, &rpath );
            if ( GetRCState( rc ) == rcNotFound )
                rc = VResolverRemote( resolver, vpath, &rpath, NULL );
            if ( rc == 0 )
            {
                const String * s;
                rc = VPathMakeString( rpath, &s );
                if ( rc == 0 )
                {
                    rc = StringCopy ( path, s );
                    free ((void*)s);
                }
                VPathRelease ( rpath );
            }
            VPathRelease ( vpath );
        }
        VResolverRelease( resolver );
    }
    return rc;
}
Esempio n. 2
0
static rc_t report_deletes_spec( const VDBManager *vdb_mgr,
                                 VFSManager * vfs_mgr,
                                 const char * spec,
                                 uint32_t min_len )
{
    rc_t rc = KOutMsg( "\nreporting deletes of '%s'\n", spec );
    if ( rc == 0 )
    {
        VPath * path = NULL;
        const VPath * local_cache = NULL;
        const KFile * remote_file = NULL;
        rc = VFSManagerResolveSpec ( vfs_mgr, spec, &path, &remote_file, &local_cache, true );
        if ( rc != 0 )
        {
            (void)LOGERR( klogErr, rc, "cannot resolve spec via VFSManager" );
        }
        else
        {
            char buffer[ 4096 ];
            size_t num_read;
            rc = VPathReadPath ( path, buffer, sizeof buffer, &num_read );
            if ( rc != 0 )
            {
                (void)LOGERR( klogErr, rc, "cannot read path from vpath" );
            }
            else
            {
                int path_type = ( VDBManagerPathType ( vdb_mgr, "%s", buffer ) & ~ kptAlias );
                switch( path_type )
                {
                    case kptDatabase : rc = report_deletes_db( vdb_mgr, buffer, min_len ); break;

                    case kptTable    : KOutMsg( "cannot report deletes on a table-object\n" );
                                        rc = RC ( rcApp, rcNoTarg, rcAccessing, rcParam, rcInvalid );
                                        (void)LOGERR( klogErr, rc, "cannot report references on a table-object" );
                                       break;

                    default          : KOutMsg( "the given object is not a vdb-database\n" );
                                        rc = RC ( rcApp, rcNoTarg, rcAccessing, rcParam, rcInvalid );
                                        (void)LOGERR( klogErr, rc, "the given object is not a vdb-database" );
                                       break;
                }
            }
            KFileRelease( remote_file );
            VPathRelease ( local_cache );
            VPathRelease ( path );
        }
    }
    return rc;

}
Esempio n. 3
0
static rc_t report_references( const VDBManager *vdb_mgr, VFSManager * vfs_mgr, const char * spec,
                               bool extended )
{
    rc_t rc = KOutMsg( "\nreporting references of '%s'\n", spec );
    if ( rc == 0 )
    {
        VPath * path = NULL;
        const VPath * local_cache = NULL;
        const KFile * remote_file = NULL;
        rc = VFSManagerResolveSpec ( vfs_mgr, spec, &path, &remote_file, &local_cache, true );
        if ( rc != 0 )
        {
            (void)LOGERR( klogErr, rc, "cannot resolve spec via VFSManager" );
        }
        else
        {
            char buffer[ 4096 ];
            size_t num_read;
            rc = VPathReadPath ( path, buffer, sizeof buffer, &num_read );
            if ( rc != 0 )
            {
                (void)LOGERR( klogErr, rc, "cannot read path from vpath" );
            }
            else
            {
                rc = KOutMsg( "resolved into '%s'\n", buffer );
                if ( rc == 0 )
                {
                    int path_type = ( VDBManagerPathType ( vdb_mgr, "%s", buffer ) & ~ kptAlias );
                    switch( path_type )
                    {
                        case kptDatabase : rc = report_ref_database( vdb_mgr, vfs_mgr, buffer, extended );
                                           break;

                        case kptTable    : rc = KOutMsg( "cannot report references on a table-object\n" );
                                           break;

                        default          : rc = KOutMsg( "the given object is not a vdb-database\n" );
                                           break;
                    }
                }
            }
            KFileRelease( remote_file );
            VPathRelease ( local_cache );
            VPathRelease ( path );
        }
    }
    return rc;
}
Esempio n. 4
0
static rc_t split_argument_into_path_and_readgroup( const char *argument, char ** path, char ** attribute )
{
    rc_t rc;
    char * colon_ptr = string_chr ( argument, string_size ( argument ), ':' );
    if ( colon_ptr == NULL )
    {
        /* we do not have a colon in the argument, that means: there is no uri-syntax involved
           ---> we can split the "old fashioned way" at the equal-sign */
        rc = split_argument( argument, path, attribute, '=' );
    }
    else
    {
        VFSManager * mgr;
        rc_t rc = VFSManagerMake ( & mgr );

        *path = NULL;
        *attribute = NULL;

        if ( rc == 0 )
        {
            VPath * vpath;
            rc = VFSManagerMakePath ( mgr, &vpath, argument );
            if ( rc == 0 )
            {
                rc = test_split_vpath_into_path_and_readgroup( vpath, argument, path, attribute );
                VPathRelease( vpath );
            }

            VFSManagerRelease ( mgr );
        }
    }
    return rc;
}
Esempio n. 5
0
/*  ----------------------------------------------------------------------
 */
static
void CC extnode_whack (BSTNode * n, void * data)
{
    if (n)
    {
        VPathRelease (((extnode*)n)->path);
        free (n);
    }
}
Esempio n. 6
0
/*  ----------------------------------------------------------------------
 */
static
void CC build_vpath_whack (void * item, void * data)
{
    VPath * p;

    p = item;

    VPathRelease ( p );
}
Esempio n. 7
0
static rc_t KDBOpenPathTypeReadInt ( const KDBManager * mgr, const KDirectory * dir, const char * path,
                                     const KDirectory ** pdir, int * type,
                                     int pathtype, uint32_t rcobj, bool try_srapath )
{
    VFSManager * vmgr = mgr->vfsmgr;
    const KDirectory * ldir = NULL;
    rc_t rc = 0;

    /* object relative opens can be done using KFS - we hacked in VFS after all */
    if (! try_srapath)
    {
        rc = KDirectoryOpenDirUpdate ((KDirectory*)dir, (KDirectory**)pdir, false, path);
        if ((rc) && (GetRCState(rc) != rcNotFound))
            rc = KDirectoryOpenDirRead (dir, pdir, false, path);
    }
    else
    {
        VPath * vpath;

        /*
         * We've got to decide if the path coming in is a full or relative
         * path and if relative make it relative to dir or possibly its a srapath
         * accession
         *
         */
        rc = VPathMakeDirectoryRelative ( &vpath, dir, path );
        if ( rc == 0 )
        {
            rc = VFSManagerOpenDirectoryReadDirectoryRelativeDecrypt ( vmgr, dir, &ldir, vpath );

            if ( rc == 0 )
            {
                *type = (~kptAlias) & KDBPathType ( ldir, NULL, "." );

                /* just a directory, not a kdb type */
                if ( *type == kptDir )
                    rc = RC (rcDB, rcMgr, rcOpening, rcPath, rcIncorrect);

                else if ( *type != pathtype )
                {
                    KDirectoryRelease( ldir );
                    rc = RC ( rcDB, rcMgr, rcOpening, rcobj, rcIncorrect );
                }
                else
                {
                    if ( pdir != NULL )
                        *pdir = ldir;
                    else
                        KDirectoryRelease( ldir );
                }
            }
            VPathRelease ( vpath );
        }
    }
    return rc;
}
Esempio n. 8
0
static rc_t resolve_accession( VFSManager * vfs_mgr, const char * acc, const String ** resolved )
{
    VResolver * resolver;
    rc_t rc = VFSManagerGetResolver( vfs_mgr, &resolver );
    if ( rc != 0 )
    {
        (void)LOGERR( klogErr, rc, "VFSManagerGetResolver() failed" );
    }
    else
    {
        VPath * acc_vpath;
        rc = VFSManagerMakePath( vfs_mgr, &acc_vpath, "ncbi-acc:%s", acc );
        if ( rc != 0 )
        {
            (void)LOGERR( klogErr, rc, "VFSManagerMakePath() failed" );
        }
        else
        {
            const VPath * local = NULL;
            const VPath * remote = NULL;
            rc = VResolverQuery ( resolver, 0, acc_vpath, &local, &remote, NULL );
            if ( rc != 0 )
            {
                (void)LOGERR( klogErr, rc, "VResolverQuery() failed" );
            }
            else
            {
                if ( local != NULL )
                    rc = VPathMakeString( local, resolved );
                else if ( remote != NULL )
                    rc = VPathMakeString( remote, resolved );
                else
                    rc = KOutMsg( "cannot resolve '%s'\n", acc );

                if ( local != NULL ) VPathRelease ( local );
                if ( remote != NULL ) VPathRelease ( remote );
            }
            VPathRelease ( acc_vpath );
        }
        VResolverRelease( resolver );
    }
    return rc;
}
Esempio n. 9
0
static
rc_t CC
XFS_ReadCEverything_ZHR (
                const char * Url,
                char * Buffer,
                size_t BufferSize,
                const char * Filler,
                XFS_ReadV_ZHR Reader
)
{
    rc_t RCt;
    size_t NR;
    const char * DefaultFiller = "NULL";
    struct VPath * Path;

    RCt = 0;
    NR = 0;
    Path = NULL;

    if ( Buffer == NULL || BufferSize <= 0 ) {
        return XFS_RC ( rcNull );
    }

    * Buffer = 0;

    if ( Url == NULL ) {
        RCt = XFS_RC ( rcNull );

        string_copy_measure (
                        Buffer,
                        sizeof ( Buffer ),
                        ( Filler == NULL ? DefaultFiller : Filler )
                        );
    }
    else {
        RCt = VFSManagerMakePath ( XFS_VfsManager (), & Path, Url );
        if ( RCt == 0 ) {
            RCt = Reader ( Path, Buffer, BufferSize, & NR );

            VPathRelease ( Path );
        }
    }

    return RCt;
}   /* XFS_ReadCEverything_ZHR () */
Esempio n. 10
0
/*  ----------------------------------------------------------------------
 */
static
rc_t open_xml_then_run()
{
    rc_t rc;

    rc = VFSManagerMakePath (options.vfsmgr, &options.xmlpath, "%s", options.xmlstr);
    if (rc)
        PLOGERR (klogInt,
                 (klogInt, rc, "failed to create path for '$(P)'",
                  "P=%s", options.xmlstr));
    else
    {
        rc = VFSManagerOpenFileRead (options.vfsmgr, &options.xml, options.xmlpath);
        if (rc)
            LOGERR (klogErr, rc, "Failed to open output directoryCopycat XML file");
        else
        {
            rc = open_root_then_run ();
        }
        VPathRelease (options.xmlpath);
    }
    return rc;
}
Esempio n. 11
0
/*  ----------------------------------------------------------------------
 */
static
rc_t open_dir_then_run()
{
    rc_t rc;

    rc = VFSManagerMakePath (options.vfsmgr, &options.dirpath, "%s", options.dirstr);
    if (rc)
        PLOGERR (klogInt,
                 (klogInt, rc, "failed to create path for '$(P)'",
                  "P=%s", options.dirstr));
    else
    {
        rc = VFSManagerOpenDirectoryUpdate (options.vfsmgr, &options.dir, options.dirpath);
        if (rc)
            LOGERR (klogErr, rc, "Failed to open output directory");
        else
        {
            rc = open_xml_then_run();
            KDirectoryRelease (options.dir);
        }
        VPathRelease (options.dirpath);
    }
    return rc;
}
Esempio n. 12
0
/* ResolveTablePath
 *  takes either an accession or path
 *  substitutes any arguments
 *  resolves via SRAPath mgr if present
 */
rc_t ResolveTablePath ( const SRAMgr *mgr,
    char *path, size_t psize, const char *spec, va_list args )
{
#if OLD_SRAPATH_MGR
    int len;
    char tblpath [ 4096 ];
    const SRAPath *pmgr = mgr -> _pmgr;

    /* if no path manager or if the spec string has embedded path separators,
       then this can't be an accession - just print it out */
    if ( mgr -> _pmgr == NULL || strchr( spec, '/' ) != NULL )
    {
        len = vsnprintf ( path, psize, spec, args );
        if ( len < 0 || ( size_t ) len >= psize )
            return RC ( rcSRA, rcTable, rcOpening, rcPath, rcExcessive );
        return 0;
    }

    /* create a copy - not likely to be too large */
    len = vsnprintf ( tblpath, sizeof tblpath, spec, args );
    if ( len < 0 || ( size_t ) len >= sizeof tblpath )
        return RC ( rcSRA, rcTable, rcOpening, rcPath, rcExcessive );

    /* test if the path exists in current directory, i.e. with assumed dot */
    if ( ! SRAPathTest ( pmgr, tblpath ) )
    {
        rc_t rc = SRAPathFind ( pmgr, tblpath, path, psize );
        if ( rc == 0 )
            return 0;
    }

    /* use the path given */
    if ( ( size_t ) len >= psize )
        return RC ( rcSRA, rcTable, rcOpening, rcBuffer, rcInsufficient );
    strcpy ( path, tblpath );

    return 0;
#else
    VFSManager *vfs;
    rc_t rc = VFSManagerMake ( & vfs );
    if ( rc == 0 )
    {
        VPath *accession;
        const VPath *tblpath = NULL;
        rc = VFSManagerVMakePath ( vfs, & accession, spec, args );
        if ( rc == 0 )
        {
            rc = VResolverLocal ( ( const VResolver* ) mgr -> _pmgr, accession, & tblpath );
            if ( rc == 0 )
            {
                size_t size;
                rc = VPathReadPath ( tblpath, path, psize, & size );
                VPathRelease ( tblpath );
            }
            VPathRelease ( accession );
        }

        VFSManagerRelease ( vfs );
    }
    return rc;
#endif
}
Esempio n. 13
0
/* KMain
 */
rc_t CC KMain ( int argc, char *argv [] )
{
    Args * args;
    rc_t rc;

    rc = ArgsMakeAndHandle (&args, argc, argv, 0);
    if (rc)
        LOGERR (klogInt, rc, "failed to parse arguments");
    else do
    {
        uint32_t acount;
        rc = ArgsParamCount (args, &acount);
        if (rc)
        {
            LOGERR (klogInt, rc, "failed to count parameters");
            break;
        }

        if (acount == 0)
        {
            rc = MiniUsage (args);
            break;
        }
        else
        {
            VFSManager* mgr;
            rc = VFSManagerMake(&mgr);
            if (rc)
                LOGERR ( klogErr, rc, "failed to create VFSManager object" );
            else
            {
                VResolver * resolver;

                rc = VFSManagerGetResolver (mgr, &resolver);
                if (rc == 0)
                {
                    uint32_t ix;
                    for ( ix = 0; ix < acount; ++ ix )
                    {
                        const char * pc;
                        rc = ArgsParamValue (args, ix, &pc );
                        if (rc)
                            LOGERR (klogInt, rc,
                                    "failed to retrieve parameter value");
                        else
                        {
                            const VPath * upath = NULL;
                            rc = VFSManagerMakePath ( mgr, (VPath**)&upath, "%s", pc);
                            if (rc == 0)
                            {
                                const VPath * local;
                                const VPath * remote;

                                rc = VResolverQuery (resolver, eProtocolHttp, upath, &local, &remote, NULL);

                                if (rc == 0)
                                {
                                    const String * s;

                                    if (local != NULL)
                                        rc = VPathMakeString (local, &s);
                                    else 
                                        rc = VPathMakeString (remote, &s);
                                    if (rc == 0)
                                    {
                                        OUTMSG (("%S\n", s));
                                        free ((void*)s);
                                    }
                                    VPathRelease (local);
                                    VPathRelease (remote);
                                }
                                else
                                {
                                    KDirectory * cwd;
                                    rc_t orc = VFSManagerGetCWD (mgr, &cwd);
                                    if (orc == 0)
                                    {
                                        KPathType kpt
                                            = KDirectoryPathType(cwd, "%s", pc);
                                        switch (kpt &= ~kptAlias)
                                        {
                                        case kptNotFound:
                                            STSMSG(1, ("'%s': not found while "
                                                "searching the file system",
                                                pc));
                                            break;
                                        case kptBadPath:
                                            STSMSG(1, ("'%s': bad path while "
                                                "searching the file system",
                                                pc));
                                            break;
                                        default:
                                            STSMSG(1, ("'%s': "
                                                "found in the file system",
                                                pc));
                                            rc = 0;
                                            break;
                                        }
                                    }
                                    if (orc == 0 && rc == 0) {
                                        if (rc != 0) {
                                            PLOGMSG(klogErr, (klogErr,
                                                              "'$(name)': not found",
                                                              "name=%s", pc));
                                        }
                                        else {
                                            char resolved[PATH_MAX] = "";
                                            rc = KDirectoryResolvePath(cwd, true,
                                                                       resolved, sizeof resolved, "%s", pc);
                                            if (rc == 0) {
                                                STSMSG(1, ("'%s': found in "
                                                           "the current directory at '%s'",
                                                           pc, resolved));
                                                OUTMSG (("%s\n", resolved));
                                            }
                                            else {
                                                STSMSG(1, ("'%s': cannot resolve "
                                                           "in the current directory",
                                                           pc));
                                                OUTMSG (("./%s\n", pc));
                                            }
                                        }
                                    }
                                    KDirectoryRelease(cwd);
                                }
                            }

                            RELEASE(VPath, upath);
                        }
                    }
                    VResolverRelease (resolver);
                }
                VFSManagerRelease(mgr);
            }
        }
        ArgsWhack (args);

    } while (0);

    return rc;
}
Esempio n. 14
0
static
rc_t run (void)
{
    VFSManager * manager;
    rc_t rc = 0, orc = 0;

    STSMSG (1, ("Make VFSManager"));
    rc = VFSManagerMake (&manager);
    STSMSG (2, ("rc %R", orc, orc));
    if (rc == 0)
    {
#if 1
        static const char name[] = "test-kfs-manager-data-file";
#else
        static const char name[] = 
            "ncbi-kfs:test-kfs-manager-data-file?enc&pwfile=password";
#endif
        VPath * path;

        STSMSG (1, ("Make test VPath file '%s'",name));
        rc = VPathMake (&path, name);
        STSMSG (2, ("rc %R", orc, orc));
        if (rc == 0)
        {
            KFile * file;

            STSMSG (1, ("Open File for write using manager and path"));
            rc = VFSManagerCreateFile (manager, &file, false, 0666, kcmCreate,
                                       path);
            STSMSG (2, ("rc %R", rc, rc));
            if (rc == 0)
            {
                char buff[4096];
                size_t ix;
                size_t num_writ;
                uint64_t tot_writ = 0;

                for (ix = 0; ix < sizeof buff; ++ix)
                    buff[ix] = 'A' + (ix%26);

                STSMSG (1, ("writing to file"));
                for (ix = 0; ix < 32; ++ix)
                {
                    rc = KFileWrite (file, tot_writ, buff, sizeof buff, &num_writ);
                    if (rc == 0)
                        tot_writ += num_writ;
                };
                                     





                STSMSG (1, ("Release file - it should whack"));
                orc = KFileRelease (file);
                STSMSG (2, ("rc %R", orc, orc));
                if (rc == 0) rc = orc;


#if 1
                STSMSG (1, ("Remove file"));
                orc = VFSManagerRemove (manager, true, path);
                STSMSG (2, ("rc %R", orc, orc));
                if (rc == 0) rc = orc;
#endif
            }
            STSMSG (1, ("Release VPath - it should Whack"));
            orc = VPathRelease (path);
            STSMSG (2, ("rc %R", orc, orc));
            if (rc == 0) rc = orc;
        }
        STSMSG (1, ("Release VFSManager - it should Whack"));
        orc = VFSManagerRelease (manager);
        STSMSG (2, ("rc %R", orc, orc));
        if (rc == 0) rc = orc;
    }
    return rc;
}
Esempio n. 15
0
/*
 * Try to locate in RefSeq Archives:
 * check for pattern '(\w{4}\d{2})[\.\d]+'; the archive is $1
 * use the scheme "x-ncbi-legrefseq" for vfs to recognize special case
 */
static
rc_t SRAPathFullREFSEQArchive(NCBISRAPath const *self,
                              char const rep[],
                              char const vol[],
                              char const accession[],
                              char path[],
                              size_t path_max
                             )
{
    size_t const rep_sz = strlen(rep);
    size_t const vol_sz = strlen(vol);
    char const *const rep_sep = (rep_sz > 0 && rep[rep_sz - 1] != '/') ? "/" : "";
    char const *const vol_sep = (vol_sz > 0 && vol[vol_sz - 1] != '/') ? "/" : "";
    size_t sz;
    unsigned i;
    VFSManager *vfs;
    rc_t rc = VFSManagerMake(&vfs);
    VPath *vpath;
    KDirectory const *dir;
    KPathType type;
    
    if (rc)
        return rc;
    
    for (i = 0; i < 4; ++i) {
        int const ch = accession[i];
        
        if (ch == 0 || !isalpha(ch))
            return RC(rcSRA, rcMgr, rcAccessing, rcPath, rcIncorrect);
    }
    for ( ; ; ++i) {
        int const ch = accession[i];
        
        if (ch == 0)
            break;
        if (ch != '.' && !isdigit(ch))
            return RC(rcSRA, rcMgr, rcAccessing, rcPath, rcIncorrect);
    }
    if (i < 8)
        return RC(rcSRA, rcMgr, rcAccessing, rcPath, rcIncorrect);
    
    rc = string_printf(path, path_max, &sz, "x-ncbi-legrefseq:%s%s%s%s%.6s", rep, rep_sep, vol, vol_sep, accession);
    if (rc) return rc;
    i = sz;
    
    rc = VPathMake(&vpath, path + 17);
    if (rc) return rc;

    rc = VFSManagerOpenDirectoryRead(vfs, &dir, vpath);
    VPathRelease(vpath);
    VFSManagerRelease(vfs);
    if (rc) return rc;
    
    type = KDirectoryPathType(dir, "tbl/%s", accession);
    KDirectoryRelease(dir);
    
    if (type != kptDir)
        return RC(rcSRA, rcMgr, rcAccessing, rcPath, rcIncorrect);

    rc = string_printf(path + i, path_max - i, &sz, "#tbl/%s", accession);
    
    return rc;
}
Esempio n. 16
0
LIB_EXPORT
rc_t CC
XFS_HttpStreamMake_ZHR (
                    const char * Url,
                    const struct XFSHttpStream ** Stream
)
{
    rc_t RCt;
    struct VPath * Path;
    struct String Host;
    uint32_t Port;
    struct XFSHttpStream * TheStream;

    RCt = 0;
    Path = NULL;

    if ( Stream != NULL ) {
        * Stream = NULL;
    }

    if ( Url == NULL || Stream == NULL ) {
        return XFS_RC ( rcNull );
    }

    RCt = VFSManagerMakePath ( XFS_VfsManager (), & Path, Url );
    if ( RCt == 0 ) {
        RCt = VPathGetHost ( Path, & Host );
        if ( RCt == 0 ) {
            Port = VPathGetPortNum ( Path );

            TheStream = calloc ( 1, sizeof ( struct XFSHttpStream ) );
            if ( TheStream == NULL ) {
                RCt = XFS_RC ( rcExhausted );
            }
            else {
                RCt = KNSManagerMakeHttp (
                                    XFS_KnsManager(),
                                    & ( TheStream -> http ),
                                    NULL,
                                    0x01010000,
                                    & Host,
                                    Port
                                    );
                if ( RCt == 0 ) {
                    RCt = KHttpMakeRequest (
                                        TheStream -> http,
                                        & ( TheStream -> req ),
                                        Url
                                        );
                    if ( RCt == 0 ) {
                        RCt = KHttpRequestGET (
                                        TheStream -> req,
                                        & ( TheStream -> res )
                                        );
                        if ( RCt == 0 ) {
                            RCt = KHttpResultGetInputStream (
                                                TheStream -> res,
                                                & ( TheStream -> str )
                                                );
                            if ( RCt == 0 ) {
                                TheStream -> completed = false;
                                TheStream -> last_error = 0;

                                * Stream = TheStream;
                            }
                        }
                    }
                }
            }
        }

        VPathRelease ( Path );
    }

    if ( RCt != 0 ) {
        * Stream = NULL;

        if ( TheStream != NULL ) {
            XFS_HttpStreamDispose_ZHR ( TheStream );
        }
    }

    return RCt;
}   /* XFS_HttpStreamMake_ZHR () */
Esempio n. 17
0
/*  ----------------------------------------------------------------------
 */
static
void CC build_vpath_one (void * item, void * data)
{
    const char * path;
    rc_data * prc;

    path = item;
    prc = data;

    if (prc->rc == 0)
    {
        static const char ccid [] = "copycat-id:";
        const size_t cz = sizeof (ccid) - 1;
        size_t pz;
        const char * hier;
        const char * ppath;
        VPath * vpath;
        rc_t rc;
        char vbuff [8193];

        rc = 0;
        ppath = path;
        pz = string_size (path);
        hier = string_chr (path, pz, ':');

        if ((hier != NULL) &&
            (0 == string_cmp (path, (hier+1) - path, ccid, cz /*sizeof (ccid) - 1*/, cz)))
        {
            static const char nfile[] = "ncbi-file:";
            char * qmark;
            size_t s, r/*, q */;
            char ibuff [8192];
            char rbuff [8192];

            ++hier;
            s = hier - path;
            r = string_copy (ibuff, sizeof (ibuff), hier, pz - s);

            qmark = string_chr (ibuff, r, '?');
            if (qmark == NULL) /* this is more future with parts */
                qmark = string_chr (ibuff, r, '#');

            if (qmark != NULL)
                *qmark = '\0';

            rc = KDirectoryResolveAlias (options.root, true, rbuff, sizeof (rbuff), "%s", ibuff);

            if (rc)
                PLOGERR (klogErr, (klogErr, rc, "error resolving file id '$(I)", "I=%s", ibuff));

            else 
            {
                char * slash;
                size_t z;

                slash = string_chr (rbuff+1, sizeof (rbuff), '/');
                if (slash == NULL)
                    /* we won't extract the root */
                    return;

                ++slash;

                z = string_size (slash);
                if (z == 0)
                    return;

                if (qmark)
                {
                    s = string_copy (vbuff, sizeof (vbuff), nfile, sizeof (nfile));
                    r = string_copy (vbuff + s, sizeof (vbuff) - s, slash, z);
                    /*q = */string_copy (vbuff + s + r, (sizeof (vbuff) - s) - r, qmark, pz - (qmark - path));
                }
                else
                {
                    s = string_copy (vbuff, sizeof (vbuff), slash, z);
                }
                ppath = vbuff;
            }
        }

        if (rc == 0)
        {
            rc = VFSManagerMakePath (options.vfsmgr, &vpath, "%s", ppath);
            if (rc)
                ;
            else
            {
                rc = VectorAppend (&options.pathvpath, NULL, vpath);
                if (rc)
                {
                    VPathRelease (vpath);
                }
            }
        }
        
        prc->rc = rc;
    }
}
Esempio n. 18
0
int LowLevelTest()
{
    cout << "Running LowLevelTest()." << endl;
    const AlignAccessMgr* mgr = 0;
    CALL(AlignAccessMgrMake(&mgr));
    VFSManager* vfs_mgr;
    CALL(VFSManagerMake(&vfs_mgr));
    VPath* bam_path = 0;
#ifdef _MSC_VER
# define BAM_FILE "//traces04/1kg_pilot_data/ftp/pilot_data/data/NA10851/alignment/NA10851.SLX.maq.SRP000031.2009_08.bam"
#else
# define BAM_FILE "/netmnt/traces04/1kg_pilot_data/ftp/pilot_data/data/NA10851/alignment/NA10851.SLX.maq.SRP000031.2009_08.bam"
#endif
    cout << "Testing BAM file: "<<BAM_FILE<<endl;
    CALL(VFSManagerMakeSysPath(vfs_mgr, &bam_path, BAM_FILE));
    VPath* bai_path = 0;
    CALL(VFSManagerMakeSysPath(vfs_mgr, &bai_path, BAM_FILE ".bai"));
    
    const AlignAccessDB* bam = 0;
    CALL(AlignAccessMgrMakeIndexBAMDB(mgr, &bam, bam_path, bai_path));

#ifdef _MSC_VER
    InitializeCriticalSection(&sdk_mutex);
#endif

    const size_t kNumCursors = 8;
    const size_t kNumThreads = 3;
    SThreadInfo tinfo[kNumCursors];
    const char* ids[kNumCursors] = {
        "NT_113960",
        "NT_113945",
        "NT_113880",
        "NT_113960",
        "NT_113960",
        "NT_113960",
        "NT_113945",
        "NT_113880"
    };
    for ( size_t i = 0; i < kNumThreads; ++i ) {
        tinfo[i].init(i, bam, ids[i]);
    }
    for ( size_t i = 0; i < kNumThreads; ++i ) {
        cout << "Starting thread " << i << " for " << ids[i] << endl;
#ifdef _MSC_VER
        tinfo[i].thread_id = CreateThread(NULL, 0, read_thread_func,
                                            &tinfo[i], 0, NULL);
#else
        pthread_create(&tinfo[i].thread_id, 0, read_thread_func, &tinfo[i]);
#endif
    }
    for ( size_t i = 0; i < kNumThreads; ++i ) {
        cout << "Waiting for thread " << i << endl;
        void* ret = 0;
#ifdef _MSC_VER
        WaitForSingleObject(tinfo[i].thread_id, INFINITE);
        CloseHandle(tinfo[i].thread_id);
#else
        pthread_join(tinfo[i].thread_id, &ret);
#endif
        cout << "Align count: " << tinfo[i].count << endl;
    }

    CALL(AlignAccessDBRelease(bam));
        
    CALL(VPathRelease(bam_path));
    CALL(VPathRelease(bai_path));
    CALL(AlignAccessMgrRelease(mgr));
    CALL(VFSManagerRelease(vfs_mgr));
    cout << "Success." << endl;
    return 0;
}
Esempio n. 19
0
/* return configured password as ASCIZ
 * opertates on vfs/kfs/kfg objects, not kdb objects */
static
rc_t KDBOpenFileGetPassword (char * pw, size_t pwz)
{
    VFSManager * mgr;
    rc_t rc;

    assert (pw);
    assert (pwz);

    pw[0] = '\0';

    rc = VFSManagerMake (&mgr);
    if (rc)
        ;                      /* failure to make VFS manager: pass along rc */
    else
    {
        size_t pwfz;
        char pwf [4096 + 1];

        rc = VFSManagerGetConfigPWFile (mgr, pwf, sizeof (pwf) - 1, &pwfz);
        if (rc)
            /* failure to get password file path: tweak rc */
            rc = RC (rcDB, rcMgr, rcOpening, rcEncryptionKey, rcNotFound);

        else
        {
            VPath * pwp;

            pwf [pwfz] = '\0'; /* force to ASCIZ */

#if 0
            rc = VPathMakeSysPath (&pwp, pwf);
#else
            rc = VFSManagerMakePath (mgr, &pwp, pwf);
#endif

            if (rc)
                ;       /* failure to construct a path from the string */
            
            else
            {
                const KFile * pwf;
          
                rc = VFSManagerOpenFileRead (mgr, &pwf, pwp);
                if (rc)
                    /* failure to open password file */
                    rc = RC (rcDB, rcMgr, rcOpening, rcEncryptionKey, rcNotOpen);

                else
                {
                    size_t z;
                    char pwb [4098]; /* arbitrarily using 4096 as maximum
                                        allowed length */

                    /* at this point we are only getting the password from a 
                     * file but in the future if we can get it from a pipe of
                     * some sort we can't count on the ReadAll to really know
                     * if we hit end of file and not just a pause in the
                     * streaming.  VFS/KFS 2 will have to fix this somehow
                     */

                    rc = KFileReadAll (pwf, 0, pwb, sizeof pwb, &z);
                    if (rc)
                        ;       /* failure to read password file: pass along rc */
                    else
                    {
                        /* trim off EOL if present */
                        char * pc;

                        pwb[z] = '\0';   /* force ASCIZ */

                        pc = string_chr (pwb, z, '\r');
                        if (pc)
                        {
                            *pc = '\0';
                            z = 1 + pc - pwb;
                        }
                        pc = string_chr (pwb, z, '\n');
                        if (pc)
                        {
                            *pc = '\0';
                            z = 1 + pc - pwb;
                        }
                        if (z == 0)
                            rc = RC (rcDB, rcMgr, rcOpening, rcEncryptionKey, rcTooShort);

                        else if (pwz < z) /* pwz came in as 4096 */
                            rc = RC (rcDB, rcMgr, rcOpening, rcEncryptionKey, rcTooLong);

                        else
                        {
                            memmove (pw, pwb, z+1);
                        }
                    }
                    KFileRelease (pwf);
                }
                VPathRelease (pwp);
            }
        }
        VFSManagerRelease (mgr);
    }
    return rc;
}
Esempio n. 20
0
static rc_t ref_walker_prepare_1_src( struct ref_walker * self, const char * name )
{
    VPath * path = NULL;
    const VPath * local_cache = NULL;
    const KFile * remote_file = NULL;
    rc_t rc = VFSManagerResolveSpec ( self->vfs_mgr, name, &path, &remote_file, &local_cache, true );
    if ( rc != 0 )
    {
        PLOGERR( klogErr, ( klogErr, rc, "cannot resolve '$(n)' via VFSManager", "n=%s", name ) );
    }
    else
    {
        char buffer[ 4096 ];
        size_t num_read;
        rc = VPathReadPath ( path, buffer, sizeof buffer, &num_read );
        if ( rc != 0 )
        {
            PLOGERR( klogErr, ( klogErr, rc, "cannot read path from vpath for '$(n)'", "n=%s", name ) );
        }
        else
        {
            if ( rc == 0 )
            {
                int path_type = ( VDBManagerPathType ( self->vmgr, "%s", buffer ) & ~ kptAlias );
                if ( path_type == kptDatabase )
                {
                    const ReferenceList * reflist;
                    uint32_t options = ( ereferencelist_usePrimaryIds | 
                                         ereferencelist_useSecondaryIds |
                                         ereferencelist_useEvidenceIds );
                    rc = ReferenceList_MakePath( &reflist, self->vmgr, name, options, 0, NULL, 0 );
                    if ( rc != 0 )
                    {
                        PLOGERR( klogErr, ( klogErr, rc, "cannot create ReferenceList for '$(n)'", "n=%s", name ) );
                    }
                    else
                    {
                        uint32_t count;
                        rc = ReferenceList_Count( reflist, &count );
                        if ( rc != 0 )
                        {
                            PLOGERR( klogErr, ( klogErr, rc, "ReferenceList_Count() for '$(n)' failed", "n=%s", name ) );
                        }
                        else
                        {
                            uint32_t idx;
                            for ( idx = 0; idx < count && rc == 0; ++idx )
                            {
                                const ReferenceObj * refobj;
                                rc = ReferenceList_Get( reflist, &refobj, idx );
                                if ( rc != 0 )
                                {
                                    LOGERR( klogInt, rc, "ReferenceList_Get() failed" );
                                }
                                else
                                {
                                    const char * seqid;
                                    rc = ReferenceObj_SeqId( refobj, &seqid );
                                    if ( rc == 0 )
                                    {
                                        INSDC_coord_len seqlen;
                                        rc = ReferenceObj_SeqLength( refobj, &seqlen );
                                        if ( rc == 0 )
                                        {
                                            rc = add_region( &self->regions, seqid, 0, seqlen - 1 );
                                        }
                                    }
                                    ReferenceObj_Release( refobj );
                                }
                            }
                        }
                        ReferenceList_Release( reflist );
                    }
                }
            }
        }
        KFileRelease( remote_file );
        VPathRelease ( local_cache );
        VPathRelease ( path );
    }
    return rc;
}
Esempio n. 21
0
/*  ----------------------------------------------------------------------
 * SCHEME:PATH/FILE?QUERY
 *
 * form_one is just a file
 * form_two is just a path and a file (can ignore scheme until more schemes supported)
 * form_three is all parts except path present which for here acts like form_one
 * form_four is all four parts
 *
 * path is the directory path leading to root
 * root will be the directory containing the archive
 * base will be the archive as a directory
 */
static
rc_t open_root_then_run ()
{
    static const char dot[] = ".";
    char         rootstr [8192];
    char         basestr [8192];
    const char * colon;
    rc_t rc;

    colon = strchr (options.arcstr, ':');
    if (colon == NULL) /* no scheme so it has to be a plain path */
    {
        char * last_slash;

        strcpy (basestr, options.arcstr);
        last_slash = strrchr (basestr, '/');

        if (last_slash == NULL) /* in this directory */
        {
            options.rootstr = dot;
            options.basestr = options.arcstr;
            /* done */
        }
        else
        {
            *last_slash = '\0';
            options.rootstr = basestr;
            options.basestr = last_slash + 1;
            /* done */
        }
    }
    else
    {
        char * end_of_root;
        char * last_slash;

        strcpy (rootstr, colon+1);

        end_of_root = strchr (rootstr, '?');

        if (end_of_root == NULL)
            end_of_root = strchr (rootstr, '#');

        if (end_of_root)
            *end_of_root = '\0';

        options.rootstr = rootstr;

        last_slash = strchr (rootstr, '/');
        if (last_slash == NULL)
        {
            /* no path */
            options.rootstr = dot;
            options.basestr = options.arcstr;
            /* done */
        }
        else
        {
            size_t x,z;

            *last_slash = '\0';
            options.rootstr = rootstr;

            /* scheme */
            z = string_size (rootstr);

            x = string_copy (basestr, sizeof (basestr), options.arcstr, (colon + 1) - options.arcstr);
            strcpy (basestr + x, options.arcstr + x + z + 1);
            options.basestr = basestr;
            /* done */
        }
    }
    {
        KDirectory * cwd;

        rc = VFSManagerGetCWD (options.vfsmgr, &cwd);
        if (rc)
            ;
        else
        {
            rc = KDirectoryOpenXTocDirRead (cwd, &options.root, true,
                                            options.xml, "%s", options.rootstr);
            if (rc)
                PLOGERR (klogErr, (klogErr, rc,
                                   "failed to open XFS from '$(P)' using '$(P)'",
                                   "P=%s", options.basestr, options.xmlstr));
            else
            {
                rc = VFSManagerMakePath (options.vfsmgr, &options.basepath, "%s", options.basestr);
                if (rc)
                    PLOGERR (klogErr, (klogErr, rc,
                                       "failed to make vpath from '$(P)'",
                                       "P=%s", options.basestr));
                else
                {
                    rc = VFSManagerOpenDirectoryRead (options.vfsmgr,
                                                      &options.base,
                                                      options.basepath);
                    if (rc == 0)
                    {
                        rc = build_vpath_then_run ();

                        KDirectoryRelease (options.base);
                    }
                    KDirectoryRelease (options.root);
                }
                VPathRelease (options.basepath);
            }
            KDirectoryRelease (cwd);
        }
    }
    return rc;
}
Esempio n. 22
0
static
rc_t nenctool (const char * srcstr, const char * dststr, bool force)
{
    VFSManager * mgr;
    rc_t rc;

    rc = VFSManagerMake (&mgr);
    if (rc)
        LOGERR (klogInt, rc, "failed to create file system manager");
    else
    {
        VPath * srcpath;

        rc = VFSManagerMakePath (mgr, &srcpath, "%s", srcstr);
        if (rc)
            PLOGERR (klogErr,
                     (klogErr, rc, "Failed to parse source path '$(path)'",
                      "path=%s", srcstr));
        else
        {
            VPath * dstpath;

            rc = VFSManagerMakePath (mgr, &dstpath, "%s", dststr);
            if (rc)
                PLOGERR (klogErr,
                         (klogErr, rc, "Failed to parse destination path '$(path)'",
                          "path=%s", dststr));
            else
            {
                const KFile * srcfile;

                rc = VFSManagerOpenFileRead (mgr, &srcfile, srcpath);
                if (rc)
                    PLOGERR (klogErr,
                             (klogErr, rc, "Failed to open source path '$(path)'",
                              "path=%s", srcstr));
                else
                {
                    KFile * dstfile;

                    rc = VFSManagerCreateFile (mgr, &dstfile, false, 0666,
                                               kcmParents | (force ? kcmInit : kcmCreate),
                                               dstpath);
                    if (rc)
                        PLOGERR (klogErr,
                                 (klogErr, rc, "failed to open destination path '$(path)'",
                                  "path=%s", dststr));
                    else
                    {
                        rc = copy_file (srcstr, dststr, srcfile, dstfile);
                        if (rc)
                        {
                            PLOGERR (klogErr,
                                     (klogErr, rc, "failed to copy '$(S)' to '$(D)'",
                                      "S=%s,D=%s", srcstr, dststr));

                            VFSManagerRemove (mgr, true, dstpath);
                        }

                        KFileRelease (dstfile);
                    }
                    KFileRelease (srcfile);
                }
                VPathRelease (dstpath);
            }
            VPathRelease (srcpath);
        }
        VFSManagerRelease (mgr);
    }
    return rc;
}
Esempio n. 23
0
static rc_t tokenize_file_and_progname_into_argv( const char * filename, const char * progname,
                                                  int * argc, char *** argv )
{
    rc_t rc2, rc = 0;
    VFSManager *vfs_mgr;

    ( *argv ) = NULL;
    ( *argc ) = 0;
    rc = VFSManagerMake ( &vfs_mgr );
    if ( rc != 0 )
        LOGERR( klogInt, rc, "VFSManagerMake() failed" );
    else
    {
        VPath * vfs_path;
        rc = VFSManagerMakePath ( vfs_mgr, &vfs_path, "%s", filename );
        if ( rc != 0 )
            LOGERR( klogInt, rc, "VPathMake() failed" );
        else
        {
            struct KFile const *my_file;
            rc = VFSManagerOpenFileRead ( vfs_mgr, &my_file, vfs_path );
            if ( rc != 0 )
                LOGERR( klogInt, rc, "VFSManagerOpenFileRead() failed" );
            else
            {
                tokenzr *t;
                uint64_t pos = 0;
                char buffer[ 4096 + 1 ];
                size_t num_read;

                rc = make_tokenzr( &t, argc, argv );
                if ( rc != 0 )
                    LOGERR( klogInt, rc, "make_tokenzr() failed" );
                else
                {
                    if ( progname != NULL )
                        rc = add_string_to_argv( t, progname, string_size( progname ) );

                    if ( rc == 0 )
                    {
                        do
                        {
                            rc = KFileRead ( my_file, pos, buffer, ( sizeof buffer ) - 1, &num_read );
                            if ( rc != 0 )
                                LOGERR( klogInt, rc, "KFileRead() failed" );
                            else if ( num_read > 0 )
                            {
                                buffer[ num_read ]  = 0;
                                rc = tokenize_buffer( t, buffer, num_read );
                                if ( rc != 0 )
                                    LOGERR( klogInt, rc, "tokenize_buffer() failed" );
                                pos += num_read;
                            }
                        } while ( rc == 0 && num_read > 0 );
                    }

                    if ( rc == 0 && t->used > 0 )
                    {
                        rc = add_token_to_argv( t );
                        if ( rc != 0 )
                            LOGERR( klogInt, rc, "add_token_to_argv() failed" );
                    }
                    free_tokenzr( t );
                }
                rc2 = KFileRelease ( my_file );
                if ( rc2 != 0 )
                    LOGERR( klogInt, rc2, "KFileRelease() failed" );
            }
            rc2 = VPathRelease ( vfs_path );
            if ( rc2 != 0 )
                LOGERR( klogInt, rc2, "VPathRelease() failed" );
        }
        rc2 = VFSManagerRelease ( vfs_mgr );
        if ( rc2 != 0 )
            LOGERR( klogInt, rc2, "VFSManagerRelease() failed" );
    }
    return rc;
}