Exemplo n.º 1
0
LIB_EXPORT rc_t CC KNSManagerVSetHTTPProxyPath ( KNSManager * self, const char * fmt, va_list args )
{
    rc_t rc = 0;

    if ( self == NULL )
        rc = RC ( rcNS, rcMgr, rcUpdating, rcSelf, rcNull );
    else
    {
        uint16_t proxy_port = 0;
        const String * proxy = NULL;

        if ( fmt != NULL && fmt [ 0 ] != 0 )
        {
            size_t psize;
            char path [ 4096 ];
            rc = string_vprintf ( path, sizeof path, & psize, fmt, args );
            if ( rc == 0 && psize != 0 )
            {
                char * colon = string_rchr ( path, psize, ':' );
                if ( colon != NULL )
                {
                    char * end;
                    const char * port_spec = colon + 1;
                    /* it is true that some day we might read symbolic port names... */
                    long port_num = strtol ( port_spec, & end, 10 );
                    if ( port_num <= 0 || port_num >= 0x10000 || end [ 0 ] != 0 )
                        rc = RC ( rcNS, rcMgr, rcUpdating, rcPath, rcInvalid );
                    else
                    {
                        proxy_port = ( uint64_t ) port_num;
                        psize = colon - path;
                    }
                }

                if ( rc == 0 )
                {
                    String tmp;
                    StringInit ( & tmp, path, psize, string_len ( path, psize ) );
                    rc = StringCopy ( & proxy, & tmp );
                }
            }
        }

        if ( rc == 0 )
        {
            if ( self -> http_proxy != NULL )
            {
                StringWhack ( self -> http_proxy );
                self -> http_proxy_port = 0;
            }

            self -> http_proxy = proxy;
            self -> http_proxy_enabled = ( proxy != NULL );
            self -> http_proxy_port = proxy_port;
        }
    }

    return rc;
}
Exemplo n.º 2
0
int KDBPathType ( const KDirectory *dir, bool *pHasZombies, const char *path )
{
    const char *leaf, *parent;


    rc_t rc;
    int type = KDirectoryPathType ( dir, "%s", path );
    
    if (pHasZombies)
        *pHasZombies = false;

    switch ( type )
    {
    case kptDir:
    case kptDir | kptAlias:
        type = KDBPathTypeDir (dir, type, pHasZombies, path);
        break;

    case kptFile:
    case kptFile | kptAlias:
    {
        /* if we hit a file first try it as an archive */
        const KDirectory * ldir;

        rc = KDirectoryOpenSraArchiveRead_silent ( dir, &ldir, false, "%s", path );
#if SUPPORT_KDB_TAR
        if ( rc != 0 )
            rc = KDirectoryOpenTarArchiveRead_silent ( dir, &ldir, false, "%s", path );
#endif
        /* it was an archive so recur */
        if ( rc == 0 )
        {
            /* recheck this newly opened directory for KDB/KFS type */
            int type2;

            type2 = KDBPathType ( ldir, NULL, "." );
            if ((type2 != kptDir) || (type != (kptDir|kptAlias)))
                type = type2;

            KDirectoryRelease (ldir);
        }
        /* it was not an archive so see if it it's an idx file */
        else
        {
            leaf = strrchr ( path, '/' );
            if ( leaf != NULL )
            {
                parent = string_rchr ( path, leaf - path, '/' );
                if ( parent ++ == NULL )
                    parent = path;
                if ( memcmp ( parent, "idx/", 4 ) == 0 )
                    type += kptIndex - kptFile;
            }
        }
        break;
    }
    }
    return type;
}
Exemplo n.º 3
0
static char * vdb_fastq_extract_run_name( const char * acc_or_path )
{
    char * delim = string_rchr ( acc_or_path, string_size( acc_or_path ), '/' );
    if ( delim == NULL )
        return string_dup_measure ( acc_or_path, NULL );
    else
        return string_dup_measure ( delim + 1, NULL );    
}
Exemplo n.º 4
0
/* KMain - EXTERN
 *  executable entrypoint "main" is implemented by
 *  an OS-specific wrapper that takes care of establishing
 *  signal handlers, logging, etc.
 *
 *  in turn, OS-specific "main" will invoke "KMain" as
 *  platform independent main entrypoint.
 *
 *  "argc" [ IN ] - the number of textual parameters in "argv"
 *  should never be < 0, but has been left as a signed int
 *  for reasons of tradition.
 *
 *  "argv" [ IN ] - array of NUL terminated strings expected
 *  to be in the shell-native character set: ASCII or UTF-8
 *  element 0 is expected to be executable identity or path.
 */
    rc_t CC KMain ( int argc, char *argv [] )
{
    Args * args;
    rc_t rc;

    default_log_level = KLogLevelGet();

    rc = ArgsMakeAndHandle (&args, argc, argv, 1, Options, sizeof Options / sizeof (OptDef));
    if (rc == 0)
    {
        do
        {
            srakar_parms pb;
            KDirectory * pwd;
            const char * name;
            uint32_t pcount;
            char archive_name [256];

            rc = KDirectoryNativeDir (&pwd);
            if (rc)
                break;

            pb.lite = false;
            pb.force = false;
            pb.dir = pwd;

            rc = ArgsOptionCount (args, OPTION_LITE, &pcount);
            if (rc)
                break;

            if (pcount == 1)
            {
                STSMSG (1, ("Using lite option"));
                pb.lite = true;
            }

#if USE_FORCE
            rc = ArgsOptionCount (args, OPTION_FORCE, &pcount);
            if (rc)
                break;

            if (pcount == 1)
            {
                STSMSG (1, ("Using force option"));
                pb.force = true;
            }
#endif
            rc = ArgsParamCount (args, &pcount);
            if (rc)
                break;

            if (pcount == 0)
            {
                KOutMsg ("missing source table\n");
                rc = MiniUsage (args);
                break;
            }
            else if (pcount > 2)
            {
                KOutMsg ("Too many parameters\n");
                rc = MiniUsage (args);
                break;
            }

            rc = ArgsParamValue (args, 0, &pb.src_path);
            if (rc)
            {
                KOutMsg ("failure to get source path/name\n");
                break;
            }

            pb.dst_path = archive_name;

            name = string_rchr (pb.src_path, string_size (pb.src_path), '/');
            if (name == NULL)
                name = pb.src_path;

            if (pcount == 1)
            {
                size_t size;

                rc = string_printf (archive_name, sizeof (archive_name), & size,
                                 "%s%s", name, pb.lite ? ".lite.sra" : ".sra");
                if ( rc != 0 )
                {
                    rc = RC (rcExe, rcArgv, rcParsing, rcPath, rcInsufficient);
                    PLOGERR (klogFatal, (klogFatal, rc, "Failure building archive name $(P)", "P=%s", archive_name));
                    break;
                }
            }
            else
            {
                rc = ArgsParamValue (args, 1, &pb.dst_path);
                if (rc)
                {
                    LOGERR (klogInt, rc, "failure to get destination path");
                    break;
                }
            }

            if (rc == 0)
            {
                KPathType kpt;

                kpt = KDirectoryPathType (pwd, "%s", pb.dst_path);

                switch (kpt & ~kptAlias)
                {
                case kptNotFound:
                    /* found nothing so assume its a valid new file name
                     * not gonna tweak extensions at this point but that can be upgraded */
                    break;
                case kptFile:
                    /* got a file name, use it  - would need force... */
                    if (pb.force == false)
                    {
                        rc = RC (rcExe, rcArgv, rcParsing, rcPath, rcBusy);
                        PLOGERR (klogFatal, (klogFatal, rc, 
                                             "Output file already exists $(P)",
                                             "P=%s", archive_name));
                    }
                    break;

                case kptDir:
                {
                    size_t size;

                    rc = string_printf (archive_name, sizeof (archive_name), & size,
                                     "%s/%s%s", pb.dst_path, name, pb.lite ? ".lite.sra" : ".sra");
                    if ( rc != 0 )
                    {
                        rc = RC (rcExe, rcArgv, rcParsing, rcPath, rcInsufficient);
                        PLOGERR (klogFatal, (klogFatal, rc, "Failure building archive name $(P)", "P=%s", archive_name));
                        break;
                    }
                    pb.dst_path = archive_name;
                    break;
                }
                default:
                    rc = RC (rcExe, rcArgv, rcParsing, rcPath, rcInvalid);
                    break;
                }
                if (rc == 0)
                {
                    STSMSG (1,("Creating archive (%s) from table (%s)\n", pb.dst_path, pb.src_path));

                    rc = run (&pb);
                    STSMSG (5, ("Run exits with %d %R\n", rc, rc));
                }
            }

        } while (0);
    }
    STSMSG (1, ("Exit status %u %R", rc, rc));
    return rc;
}
Exemplo n.º 5
0
/* ----------------------------------------------------------------------
 */
static
rc_t walk_path_file (char * path, size_t z, uint64_t * offset, KPathType kpt)
{
    uint64_t this_offset;
    char * pc;
    rc_t rc;

    assert (path);
    assert (offset);

    this_offset = 0;
    rc = 0;
    if (kpt == kptFile)
    {
        rc = KDirectoryFileLocator (options.base, &this_offset, "%s", path);
        if (rc)
            PLOGERR (klogErr,
                     (klogErr, rc, "failure walking path '$(P)'",
                      "P=%s", path));
    }
    if (rc == 0)
    {
        pc = string_rchr (path, z, '/');
        if (pc)
        {
            uint64_t that_offset;
            KPathType lkpt;

            *pc = '\0';
            lkpt = KDirectoryPathType (options.base, "%s", path);

            switch (lkpt)
            {
            default:
                rc = RC (rcExe, rcPath, rcAccessing, rcPath, rcInvalid);
                break;
            case kptNotFound:
            case kptZombieFile:
                rc = RC (rcExe, rcPath, rcAccessing, rcPath, rcNotFound);
                break;

            case kptBadPath:
                rc = RC (rcExe, rcPath, rcAccessing, rcPath, rcInvalid);
                break;

            case kptFile:
            case kptDir:
                /* we should always hit here */
                rc = walk_path_file (path, z, &that_offset, lkpt);
                if (rc == 0)
                {
                    this_offset += that_offset;
                }
                break;

            case kptCharDev:
            case kptBlockDev:
            case kptFIFO:
                rc = RC (rcExe, rcPath, rcAccessing, rcPath, rcIncorrect);
                break;
            }
            *pc = '/';
        }
    }
    *offset = this_offset;
    return rc;
}
Exemplo n.º 6
0
int KDBPathTypeDir (const KDirectory * dir, int type, bool * pHasZombies, const char * path)
{
    const char * leaf, * parent;
    uint32_t bits;
    rc_t rc;

    bits = 0;

    assert ((type == kptDir) || (type == (kptDir|kptAlias)));

    rc = KDirectoryVVisit ( dir, false, scan_dbdir, & bits, path, NULL );
    if ( rc == 0 ) do
    {
        if ( ( bits & scan_zombie ) != 0 ) {
            bits &= ~scan_zombie;
            if (pHasZombies)
                *pHasZombies = true;
        }
        /* look for a column */
        if ( ( bits & scan_idxN ) != 0 &&
             ( bits & ( scan_data | scan_dataN ) ) != 0 )
        {
            if ( ( bits & ( scan_db | scan_tbl | scan_idx | scan_col ) ) == 0 )
                type += kptColumn - kptDir;
            break;
        }

        /* look for a table */
        if ( ( bits & scan_col ) != 0 )
        {
            /* can't have sub-tables or a db */
            if ( ( bits & ( scan_db | scan_tbl ) ) == 0 )
            {
                /* look for an old-structure table */
                if ( ( bits & ( scan_meta | scan_md ) ) == scan_meta ||
                     ( bits & ( scan_skey | scan_idx ) ) == scan_skey )
                    type += kptPrereleaseTbl - kptDir;
                else
                    type += kptTable - kptDir;
            }
            break;
        }

        /* look for metadata */
        if ( ( bits & ( scan_cur | scan_rNNN ) ) != 0 )
        {
            if ( ( bits & ( scan_db | scan_tbl | scan_idx | scan_col ) ) == 0 )
                type += kptMetadata - kptDir;
            break;
        }

        /* look for a database */
        if ( ( bits & scan_tbl ) != 0 )
        {
            if ( ( bits & scan_col ) == 0 )
                type += kptDatabase - kptDir;
            break;
        }

        /* look for a structured column */
        if ( ( bits & scan_odir ) != 0 )
        {
            leaf = strrchr ( path, '/' );
            if ( leaf != NULL )
            {
                parent = string_rchr ( path, leaf - path, '/' );
                if ( parent ++ == NULL )
                    parent = path;
                if ( memcmp ( parent, "col/", 4 ) != 0 )
                    break;

                bits = 0;
                if ( KDirectoryVVisit ( dir, 1, scan_dbdir, & bits, path, NULL ) == 0 )
                {
                    if ( ( bits & scan_idxN ) != 0 &&
                         ( bits & ( scan_data | scan_dataN ) ) != 0 )
                    {
                        if ( ( bits & ( scan_db | scan_tbl | scan_idx | scan_col ) ) == 0 )
                            type += kptColumn - kptDir;
                        break;
                    }
                }
            }
        }
    } while (0);

    return type;
}
Exemplo n.º 7
0
/* LoadSchema
 *  looks in metadata for stored schema
 */
static
rc_t CC VPhysicalLoadV1Schema ( VPhysical *self,
    VTypedecl *td, VSchema *schema, const KMDataNode *node )
{
    rc_t rc;

    KMDataNodeSchemaFillData pb;
    pb . node = node;
    pb . pos = 0;
    pb . add_v0 = true;

    /* add stored declaration to cursor schema */
    rc = VSchemaParseTextCallback ( schema,
        "VPhysicalLoadV1Schema", KMDataNodeFillSchema, & pb );
   if ( rc == 0 )
    {
        size_t size;
        char type_expr [ 256 ];

        /* retrieve and resolve "type" attribute */
        rc = KMDataNodeReadAttr ( node, "type",
            type_expr, sizeof type_expr, & size );
        if ( rc == 0 )
            rc = VSchemaResolveTypedecl ( schema, td, type_expr );

        /* if a decoding schema exists */
        if ( rc == 0 && pb . pos != 0 )
        {
            char sphysical_name [ 512 ];

            /* preserve schema function expression */
            size_t decoding_xsize;
            char decoding_expr [ 256 ];
            rc = KMDataNodeReadAttr ( node, "schema",
                decoding_expr, sizeof decoding_expr, & decoding_xsize );
            if ( rc == 0 )
            {
                /* look for "encoding" */
                const KMDataNode *enc;
                rc = KMetadataOpenNodeRead ( self -> meta, & enc, "encoding" );
                if ( rc == 0 )
                {
#if ALLOW_V1_UPDATE
                    if ( ! self -> read_only )
                    {
                        /* add stored declaration to cursor schema */
                        pb . node = enc;
                        pb . pos = 0;
                        pb . add_v0 = true;
                        rc = VSchemaParseTextCallback ( schema,
                            "VPhysicalLoadV1Schema", KMDataNodeFillSchema, & pb );
                    }
                    if ( rc == 0 )
#endif
                    {
                        /* preserve schema function expression */
                        size_t encoding_xsize;
                        char encoding_expr [ 256 ], enc_type [ 256 ];
                        rc = KMDataNodeReadAttr ( enc, "schema",
                            encoding_expr, sizeof encoding_expr, & encoding_xsize );
                        if ( rc == 0 )
                        {
                            rc = KMDataNodeReadAttr ( enc, "type",
                                enc_type, sizeof enc_type, & size );
                        }
                        if ( rc == 0 )
                        {
#if ALLOW_V1_UPDATE
                            if ( self -> read_only )
                            {
#endif
                                /* build sphysical name */
                                sprintf ( sphysical_name, "%s_only", decoding_expr );

                                /* build physical decl */
                                pb . pos = sprintf ( pb . buff, "version 1;"
                                                     "physical %s %s:phys#1"
                                                     "{decode{%s k=@;return %s(k);}}"
                                                     , type_expr
                                                     , sphysical_name
                                                     , enc_type
                                                     , decoding_expr
                                    );
#if ALLOW_V1_UPDATE
                            }
                            else
                            {
                                /* strip off common namespace */
                                size_t i, ns_size;
                                string_match ( decoding_expr, decoding_xsize,
                                    encoding_expr, encoding_xsize, -1, & ns_size );
                                if ( ns_size != 0 )
                                {
                                    char *p = string_rchr ( decoding_expr, ns_size, ':' );
                                    ns_size = ( p == NULL ) ? 0U : ( uint32_t ) ( p - decoding_expr ) + 1U;
                                }

                                /* build sphysical name */
                                sprintf ( sphysical_name, "%s_%s", decoding_expr, & encoding_expr [ ns_size ] );
                                for ( i = ns_size; sphysical_name [ i ] != 0; ++ i )
                                {
                                    if ( sphysical_name [ i ] == ':' )
                                        sphysical_name [ i ] = '_';
                                }

                                /* build physical decl */
                                pb . pos = sprintf ( pb . buff, "version 1;"
                                                     "physical %s %s:phys#1"
                                                     "{encode{return %s(@);}"
                                                     "decode{%s k=@;return %s(k);}}"
                                                     , type_expr
                                                     , sphysical_name
                                                     , encoding_expr
                                                     , enc_type
                                                     , decoding_expr
                                    );
                            }
#endif
                        }
                    }

                    KMDataNodeRelease ( enc );
                }
                else if ( GetRCState ( rc ) == rcNotFound )
                {
                    /* build sphysical name */
                    sprintf ( sphysical_name, "%s_only", decoding_expr );

                    /* build decode-only physical decl */
                    pb . pos = sprintf ( pb . buff, "version 1;"
                                         "physical %s %s:phys#1"
                                         "{decode{opaque k=@;return %s(k);}}"
                                         , type_expr
                                         , sphysical_name
                                         , decoding_expr
                        );
                    rc = 0;
                }
                if ( rc == 0 )
                {
                    /* parse synthesized schema into cursor VSchema */
                    rc = VSchemaParseText ( schema,
                        "VPhysicalLoadV1Schema", pb . buff, pb . pos );
                    if ( rc == 0 )
                    {
                        VTypedecl etd;

                        /* create a new expression object */
                        sprintf ( pb . buff, "%s:phys#1", sphysical_name );
                        rc = VSchemaImplicitPhysEncExpr ( schema, & etd,
                            & self -> enc, pb . buff, "VPhysicalLoadV1Schema" );
                        if ( rc != 0 )
                        {
                            PLOGERR ( klogInt, ( klogInt, rc, "failed to establish column type from '$(expr)'",
                                       "expr=%s", pb . buff ));
                        }
                        else if ( self -> smbr != NULL && self -> smbr -> type == NULL )
                        {
                            /* back-patch schema */
                            ( ( SPhysMember* ) self -> smbr ) -> type = self -> enc;
                            atomic32_inc ( & ( ( SExpression* ) self -> enc ) -> refcount );
                        }
                    }
                }
            }
        }
    }

    KMDataNodeRelease ( node );
    return rc;
}