* Fix directory listing and recursive mountpoint listing

* Fix RSocket build without SSL support
This commit is contained in:
earada 2011-05-18 01:27:09 +02:00
parent 0e4183a0a3
commit 7d7a9e27d6
4 changed files with 107 additions and 52 deletions

View File

@ -57,8 +57,12 @@ R_API void r_fs_del (RFS *fs, RFSPlugin *p) {
/* mountpoint */ /* mountpoint */
R_API RFSRoot *r_fs_mount (RFS* fs, const char *fstype, const char *path, ut64 delta) { R_API RFSRoot *r_fs_mount (RFS* fs, const char *fstype, const char *path, ut64 delta) {
RFSPlugin *p; RFSPlugin *p;
RFSRoot *root = NULL; RFSRoot *root;
RFSFile *file;
RList *list;
RListIter *iter;
char *str; char *str;
int len, lenstr;
if (path[0] != '/') { if (path[0] != '/') {
eprintf ("r_fs_mount: invalid mountpoint\n"); eprintf ("r_fs_mount: invalid mountpoint\n");
@ -70,6 +74,32 @@ R_API RFSRoot *r_fs_mount (RFS* fs, const char *fstype, const char *path, ut64 d
} }
str = strdup (path); str = strdup (path);
r_str_chop_path (str); r_str_chop_path (str);
/* Check if path exists */
r_list_foreach (fs->roots, iter, root) {
len = strlen (root->path);
lenstr = strlen (str);
if (!strncmp (str, root->path, len)) {
if (len < lenstr && str[len] != '/')
continue;
else if (len > lenstr && root->path[lenstr] == '/')
continue;
eprintf ("r_fs_mount: Invalid mount point\n");
return NULL;
}
}
file = r_fs_open (fs, str);
if (file) {
r_fs_close (fs, file);
eprintf ("r_fs_mount: Invalid mount point\n");
return NULL;
} else {
list = r_fs_dir (fs, str);
if (!r_list_empty (list)) {
//XXX: list need free ??
eprintf ("r_fs_mount: Invalid mount point\n");
return NULL;
}
}
root = r_fs_root_new (str, delta); root = r_fs_root_new (str, delta);
root->p = p; root->p = p;
//memcpy (&root->iob, &fs->iob, sizeof (root->iob)); //memcpy (&root->iob, &fs->iob, sizeof (root->iob));
@ -86,63 +116,74 @@ R_API RFSRoot *r_fs_mount (RFS* fs, const char *fstype, const char *path, ut64 d
return root; return root;
} }
static inline int r_fs_match (const char *root, const char *path, int len, int olen) { static inline int r_fs_match (const char *root, const char *path, int len) {
return ((len>olen) && (!strncmp (path, root, len))); return (!strncmp (path, root, len));
} }
R_API int r_fs_umount (RFS* fs, const char *path) { R_API int r_fs_umount (RFS* fs, const char *path) {
int olen = 0; int len;
RFSRoot *root; RFSRoot *root;
RListIter *iter, *riter = NULL; RListIter *iter, *riter = NULL;
r_list_foreach (fs->roots, iter, root) { r_list_foreach (fs->roots, iter, root) {
int len = strlen (root->path); len = strlen (root->path);
if (r_fs_match (path, root->path, len, olen)) { if (r_fs_match (path, root->path, len)) {
olen = len;
riter = iter; riter = iter;
} }
} }
if (riter) { if (riter) {
r_list_delete (fs->roots, riter); r_list_delete (fs->roots, riter);
return R_TRUE; return R_TRUE;
} }
return R_FALSE; return R_FALSE;
} }
R_API RFSRoot *r_fs_root (RFS *fs, const char *p) { R_API RList *r_fs_root (RFS *fs, const char *p) {
RFSRoot *root, *oroot = NULL; RList *roots = r_list_new ();
RFSRoot *root;
RListIter *iter; RListIter *iter;
int olen = 0; int len, olen;
char *path = strdup (p); char *path = strdup (p);
r_str_chop_path (path); r_str_chop_path (path);
r_list_foreach (fs->roots, iter, root) { r_list_foreach (fs->roots, iter, root) {
int len = strlen (root->path); len = strlen (root->path);
if (r_fs_match (path, root->path, len, olen)) { if (r_fs_match (path, root->path, len)) {
olen = len; olen = strlen (path);
oroot = root; if (len == 1 || olen == len)
r_list_append (roots, root);
else if ( olen > len && path[len] == '/')
r_list_append (roots, root);
} }
} }
free (path); free (path);
return oroot; return roots;
} }
/* filez */ /* filez */
R_API RFSFile *r_fs_open (RFS* fs, const char *p) { R_API RFSFile *r_fs_open (RFS* fs, const char *p) {
RFSRoot *root; RFSRoot *root;
RList *roots;
RListIter *iter;
RFSFile *f = NULL;
const char *dir; const char *dir;
char *path = strdup (p); char *path = strdup (p);
//r_str_chop_path (path); //r_str_chop_path (path);
root = r_fs_root (fs, path); roots = r_fs_root (fs, path);
if (root && root->p && root->p->open) { if (!r_list_empty (roots)) {
if (strlen (root->path) == 1) r_list_foreach (roots, iter, root) {
dir = path; if (root && root->p && root->p->open) {
else if (strlen (root->path) == 1)
dir = path + strlen (root->path); dir = path;
RFSFile *f = root->p->open (root, dir); else
free (path); dir = path + strlen (root->path);
return f; f = root->p->open (root, dir);
} else eprintf ("r_fs_open: null root->p->open\n"); if (f)
break;
}
}
}
free (roots);
free (path); free (path);
return NULL; return f;
} }
// TODO: close or free? // TODO: close or free?
@ -168,20 +209,26 @@ R_API int r_fs_read (RFS* fs, RFSFile *file, ut64 addr, int len) {
} }
R_API RList *r_fs_dir(RFS* fs, const char *p) { R_API RList *r_fs_dir(RFS* fs, const char *p) {
RList *ret = NULL; RList *roots, *ret = NULL;
RFSRoot *root; RFSRoot *root;
RListIter *iter;
const char *dir; const char *dir;
char *path = strdup (p); char *path = strdup (p);
r_str_chop_path (path); r_str_chop_path (path);
root = r_fs_root (fs, path); roots = r_fs_root (fs, path);
if (root) { r_list_foreach (roots, iter, root) {
if (strlen (root->path) == 1) if (root) {
dir = path; if (strlen (root->path) == 1)
else dir = path;
dir = path + strlen (root->path); else
if (!*dir) dir = "/"; dir = path + strlen (root->path);
ret = root->p->dir (root, dir, fs->view); if (!*dir) dir = "/";
} else eprintf ("r_fs_dir: not mounted '%s'\n", path); ret = root->p->dir (root, dir, fs->view);
if (ret)
break;
}
}
free (roots);
free (path); free (path);
return ret; return ret;
} }
@ -273,17 +320,22 @@ R_API RList *r_fs_find (RFS* fs, const char *name, const char *glob) {
R_API RFSFile *r_fs_slurp(RFS* fs, const char *path) { R_API RFSFile *r_fs_slurp(RFS* fs, const char *path) {
RFSFile *file = NULL; RFSFile *file = NULL;
RFSRoot *root = r_fs_root (fs, path); RFSRoot *root;
if (root && root->p) { RList * roots = r_fs_root (fs, path);
if (root->p->open && root->p->read && root->p->close) { RListIter *iter;
file = root->p->open (root, path); r_list_foreach (roots, iter, root) {
if (file) root->p->read (file, 0, file->size); //file->data if (root && root->p) {
else eprintf ("r_fs_slurp: cannot open file\n"); if (root->p->open && root->p->read && root->p->close) {
} else { file = root->p->open (root, path);
if (root->p->slurp) return root->p->slurp (root, path); if (file) root->p->read (file, 0, file->size); //file->data
else eprintf ("r_fs_slurp: null root->p->slurp\n"); else eprintf ("r_fs_slurp: cannot open file\n");
} else {
if (root->p->slurp) return root->p->slurp (root, path);
else eprintf ("r_fs_slurp: null root->p->slurp\n");
}
} }
} }
free (roots);
return file; return file;
} }
@ -382,7 +434,8 @@ R_API int r_fs_prompt (RFS *fs, char *root) {
if (root && *root) { if (root && *root) {
r_str_chop_path (root); r_str_chop_path (root);
if (!r_fs_root (fs, root)) { list = r_fs_root (fs, root);
if (r_list_empty (list)) {
printf ("Unknown root\n"); printf ("Unknown root\n");
return R_FALSE; return R_FALSE;
} }

View File

@ -82,7 +82,7 @@ R_API void r_fs_add (RFS *fs, RFSPlugin *p);
R_API void r_fs_del (RFS *fs, RFSPlugin *p); R_API void r_fs_del (RFS *fs, RFSPlugin *p);
R_API RFSRoot *r_fs_mount (RFS* fs, const char *fstype, const char *path, ut64 delta); R_API RFSRoot *r_fs_mount (RFS* fs, const char *fstype, const char *path, ut64 delta);
R_API boolt r_fs_umount (RFS* fs, const char *path); R_API boolt r_fs_umount (RFS* fs, const char *path);
R_API RFSRoot *r_fs_root (RFS *fs, const char *path); R_API RList *r_fs_root (RFS *fs, const char *path);
R_API RFSFile *r_fs_open (RFS* fs, const char *path); R_API RFSFile *r_fs_open (RFS* fs, const char *path);
R_API void r_fs_close (RFS* fs, RFSFile *file); R_API void r_fs_close (RFS* fs, RFSFile *file);
R_API int r_fs_read (RFS* fs, RFSFile *file, ut64 addr, int len); R_API int r_fs_read (RFS* fs, RFSFile *file, ut64 addr, int len);

View File

@ -3,7 +3,9 @@ include ../config.mk
NAME=r_socket NAME=r_socket
#DEPS=r_util #DEPS=r_util
OBJ=socket.o proc.o http.o OBJ=socket.o proc.o http.o
ifeq (${HAVE_LIB_SSL},1)
LDFLAGS+=-lssl -lcrypto LDFLAGS+=-lssl -lcrypto
endif
# on solaris only # on solaris only
ifeq (${OSTYPE},solaris) ifeq (${OSTYPE},solaris)

View File

@ -8,7 +8,7 @@ namespace Radare {
public RFS(); public RFS();
public unowned RFSRoot? mount (string fstype, string path, uint64 delta); public unowned RFSRoot? mount (string fstype, string path, uint64 delta);
public bool umount (string path); public bool umount (string path);
public RFSRoot root (string path); public RList<RFSRoot> root (string path);
public RFSFile open (string path); public RFSFile open (string path);
public void close (RFSFile file); public void close (RFSFile file);
public int read(RFSFile file, uint64 addr, int len); public int read(RFSFile file, uint64 addr, int len);