Back to index

avfs  1.0.1
Classes | Defines | Functions
rsh.c File Reference
#include "remote.h"
#include "runprog.h"
#include "parsels.h"
#include "filebuf.h"
#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>

Go to the source code of this file.

Classes

struct  rshlocalfile

Defines

#define RSH_LIST_TIMEOUT   20000

Functions

static void rsh_parse_line (struct lscache *lc, const char *line, struct remdirlist *dl)
static int rsh_read_list (struct program *pr, struct lscache *lc, struct remdirlist *dl)
static int rsh_isspecial (int c)
static char * rsh_code_name (const char *name)
static char * rsh_split_hostpart (const char *hostpart, const char **hostp)
static int rsh_list (struct remote *rem, struct remdirlist *dl)
static void rsh_free_localfile (struct rshlocalfile *lf)
static int rsh_get (struct remote *rem, struct remgetparam *gp)
static int rsh_wait (struct remote *rem, void *data, avoff_t end)
static void rsh_destroy (struct remote *rem)
static int init_rsh (struct vmodule *module, const char *name)
int av_init_module_rsh (struct vmodule *module)

Class Documentation

struct rshlocalfile

Definition at line 20 of file rsh.c.

Collaboration diagram for rshlocalfile:
Class Members
avoff_t currsize
struct program * pr
char * tmpfile

Define Documentation

#define RSH_LIST_TIMEOUT   20000

Definition at line 18 of file rsh.c.


Function Documentation

int av_init_module_rsh ( struct vmodule module)

Definition at line 256 of file rsh.c.

{
    int res;

    res = init_rsh(module, "rsh");
    if(res < 0)
        return res;

    res = init_rsh(module, "ssh");
    if(res < 0)
        return res;

    return 0;
}

Here is the call graph for this function:

static int init_rsh ( struct vmodule module,
const char *  name 
) [static]

Definition at line 237 of file rsh.c.

{
    struct remote *rem;
    struct avfs *avfs;

    AV_NEW(rem);

    rem->data    = NULL;
    rem->name    = av_strdup(name);
    rem->list    = rsh_list;
    rem->get     = rsh_get;
    rem->wait    = rsh_wait;
    rem->destroy = rsh_destroy;
    
    return av_remote_init(module, rem, &avfs);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static char* rsh_code_name ( const char *  name) [static]

Definition at line 78 of file rsh.c.

{
    char *newname = (char *) av_malloc(strlen(name) * 2 + 1);
    const char *s;
    char *d;
    
    for(s = name, d = newname; *s != '\0'; s++, d++) {
        if(rsh_isspecial((unsigned char) *s))
            *d++ = '\\';
        
        *d = *s;
    }
    *d = '\0';
    
    return newname;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void rsh_destroy ( struct remote rem) [static]

Definition at line 231 of file rsh.c.

{
    av_free(rem->name);
    av_free(rem);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void rsh_free_localfile ( struct rshlocalfile lf) [static]

Definition at line 150 of file rsh.c.

{
    
    if(lf->pr != NULL) {
        av_program_log_output(lf->pr);
        av_unref_obj(lf->pr);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int rsh_get ( struct remote rem,
struct remgetparam gp 
) [static]

Definition at line 159 of file rsh.c.

{
    int res;
    struct rshlocalfile *lf;
    char *tmpfile;
    char *codedpath;
    char *path;
    const char *prog[4];
    char progname[4];

    strcpy(progname, "rcp");
    progname[0] = rem->name[0];

    res = av_get_tmpfile(&tmpfile);
    if(res < 0)
       return res;

    AV_NEW_OBJ(lf, rsh_free_localfile);
    lf->pr = NULL;

    codedpath = rsh_code_name(gp->hostpath.path);
    path = av_stradd(NULL, gp->hostpath.host, ":", codedpath, NULL);
    av_free(codedpath);

    lf->tmpfile = tmpfile;

    prog[0] = progname;
    prog[1] = path;
    prog[2] = lf->tmpfile;
    prog[3] = NULL;

    res = av_start_program(prog, &lf->pr);
    av_free(path);
    if(res < 0) {
        av_unref_obj(lf);
        av_del_tmpfile(tmpfile);
        return res;
    }

    lf->currsize = 0;

    gp->data = lf;
    gp->localname = lf->tmpfile;

    return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int rsh_isspecial ( int  c) [static]

Definition at line 67 of file rsh.c.

{
    const char *normchars = "/.~@#%^-_=+:";

    if((c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z') || 
       (c >= 'a' && c <= 'z') || c >= 160 || strchr(normchars, c) != NULL)
        return 0;
    else
        return 1;
}

Here is the caller graph for this function:

static int rsh_list ( struct remote rem,
struct remdirlist dl 
) [static]

Definition at line 109 of file rsh.c.

{
    int res;
    struct program *pr;
    const char *prog[8];
    char *escaped_path;
    unsigned int arg;
    const char *host;
    char *username;

    escaped_path = rsh_code_name(dl->hostpath.path);
    username = rsh_split_hostpart(dl->hostpath.host, &host);

    arg = 0;
    prog[arg++] = rem->name;
    if(username != NULL) {
        prog[arg++] = "-l";
        prog[arg++] = username;
    }
    prog[arg++] = host;
    prog[arg++] = "/bin/ls";
    if((dl->flags & REM_LIST_SINGLE) != 0)
        prog[arg++] = "-ldn";
    else
        prog[arg++] = "-lan";
    prog[arg++] = escaped_path;
    prog[arg++] = NULL;
  
    res = av_start_program(prog, &pr);
    if(res == 0) {
        struct lscache *lc = av_new_lscache();
        res = rsh_read_list(pr, lc, dl);
        av_unref_obj(lc);
        av_unref_obj(pr);
    }
    av_free(escaped_path);
    av_free(username);

    return res;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void rsh_parse_line ( struct lscache lc,
const char *  line,
struct remdirlist dl 
) [static]

Definition at line 26 of file rsh.c.

{
    int res;
    char *filename;
    char *linkname;
    struct avstat stbuf;

    res = av_parse_ls(lc, line, &stbuf, &filename, &linkname);
    if(res != 1)
        return;

    av_remote_add(dl, filename, linkname, &stbuf);

    av_free(filename);
    av_free(linkname);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int rsh_read_list ( struct program pr,
struct lscache lc,
struct remdirlist dl 
) [static]

Definition at line 44 of file rsh.c.

{
    int res;

    while(1) {
        char *line;

        res = av_program_getline(pr, &line, RSH_LIST_TIMEOUT);
        if(res < 0)
            return res;
        if(res == 0) {
            av_log(AVLOG_ERROR, "RSH: timeout");
            return -EIO;
        }
        if(line == NULL)
            return 0;

        rsh_parse_line(lc, line, dl);
        av_free(line);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static char* rsh_split_hostpart ( const char *  hostpart,
const char **  hostp 
) [static]

Definition at line 95 of file rsh.c.

{
    unsigned int i;
    
    for(i = 0; hostpart[i] != '\0'; i++) {
        if(hostpart[i] == '@') {
            *hostp = hostpart + i + 1;
            return av_strndup(hostpart, i);
        }
    }
    *hostp = hostpart;
    return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int rsh_wait ( struct remote rem,
void *  data,
avoff_t  end 
) [static]

Definition at line 206 of file rsh.c.

{
    int res;
    struct rshlocalfile *lf = (struct rshlocalfile *) data;

    /* FIXME: timeout? */
    do {
        struct stat stbuf;
        
        res = av_program_log_output(lf->pr);
        if(res <= 0)
            return res;

        res = stat(lf->tmpfile, &stbuf);
        if(res == 0)
            lf->currsize = stbuf.st_size;

        if(lf->currsize < end)
            av_sleep(250);

    } while(lf->currsize < end);

    return 1;
}

Here is the call graph for this function:

Here is the caller graph for this function: