Example #1
0
static
rc_t StartFileSystem (const char * src, const char * dst)
{
    VFSManager * vmanager;
    rc_t rc;

    rc = VFSManagerMake (&vmanager);
    if (rc)
        LOGERR (klogErr, rc, "Failed to open file system");

    else
    {
        rc = VFSManagerGetKryptoPassword (vmanager, Password, sizeof Password,
                                          &PasswordSize);
        if (rc != 0)
            LOGERR (klogErr, rc, "unable to obtain a password");

        else
        {
            rc = KKeyInitRead (&Key, kkeyAES128, Password, PasswordSize);
            if (rc)
                LOGERR (klogErr, rc, "Unable to make encryption/decryption key");

            else
            {
                KDirectory * cwd;

                rc = VFSManagerGetCWD (vmanager, &cwd);
                if (rc)
                    LOGERR (klogInt, rc, "unable to access current directory");

                else
                {
                    rc = Start (cwd, src, dst);

                    KDirectoryRelease (cwd);
                }
            }
        }
        VFSManagerRelease (vmanager);
    }
    return rc;
}
Example #2
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;
}
Example #3
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;
}