|
|
@ -94,6 +94,61 @@ static int __cwd(sxlink_t *link, char **argv, int argc)
|
|
|
|
return r;
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int __stat(sxlink_t *link, char **argv, int argc)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
sxchnl_t *channel = sxchannel_open(link, READONLY_CHANNEL);
|
|
|
|
|
|
|
|
sxmsg_t *msg;
|
|
|
|
|
|
|
|
sexp_t *sx = NULL, *isx, *rsx;
|
|
|
|
|
|
|
|
char buf[1024];
|
|
|
|
|
|
|
|
char *cmsg = NULL, *entry = NULL;
|
|
|
|
|
|
|
|
int r = SXE_SUCCESS, i;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(!channel) return SXE_FAILED;
|
|
|
|
|
|
|
|
if(argc < 2) return SXE_SUCCESS; /* nothing to do if we don't have any parameters */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
snprintf(buf, 1024, "(%s %s)", STAT_CMD, argv[1]);
|
|
|
|
|
|
|
|
r = sxmsg_send(channel, buf, strlen(buf), &msg);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(r == SXE_RAPIDMSG) {
|
|
|
|
|
|
|
|
cmsg = strdup(strdup(sxmsg_payload(msg)));
|
|
|
|
|
|
|
|
sxmsg_clean(msg);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(channel) sxchannel_close(channel);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(cmsg) {
|
|
|
|
|
|
|
|
sx = parse_sexp(cmsg, strlen(cmsg));
|
|
|
|
|
|
|
|
if(!sx) { r = SXE_ENOMEM; goto __fini; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SEXP_ITERATE_LIST(sx, isx, i) {
|
|
|
|
|
|
|
|
if(isx->ty != SEXP_LIST) {
|
|
|
|
|
|
|
|
__badproto:
|
|
|
|
|
|
|
|
r = SXE_BADPROTO;
|
|
|
|
|
|
|
|
goto __fini;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
sexp_list_car(isx, &rsx);
|
|
|
|
|
|
|
|
if(rsx && rsx->ty != SEXP_LIST) {
|
|
|
|
|
|
|
|
entry = rsx->val;
|
|
|
|
|
|
|
|
sexp_list_cdr(isx, &rsx);
|
|
|
|
|
|
|
|
if(!rsx || rsx->ty == SEXP_LIST) goto __badproto;
|
|
|
|
|
|
|
|
if(entry == rsx->val) goto __badproto;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(!strcmp(entry, ":user")) fprintf(stdout, "User: %s\n", rsx->val);
|
|
|
|
|
|
|
|
else if(!strcmp(entry, ":group")) fprintf(stdout, "Group: %s\n", rsx->val);
|
|
|
|
|
|
|
|
else if(!strcmp(entry, ":size")) fprintf(stdout, "Size: %s\n", rsx->val);
|
|
|
|
|
|
|
|
else if(!strcmp(entry, ":mode")) fprintf(stdout, "Mode: %s\n", rsx->val);
|
|
|
|
|
|
|
|
else goto __badproto;
|
|
|
|
|
|
|
|
} else goto __badproto;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else r = SXE_FAILED;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
__fini:
|
|
|
|
|
|
|
|
if(cmsg) free(cmsg);
|
|
|
|
|
|
|
|
if(sx) destroy_sexp(sx);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return r;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void __dirlist_out(FILE *f, list_head_t *list)
|
|
|
|
static void __dirlist_out(FILE *f, list_head_t *list)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
char *dname = NULL, *dtype = NULL;
|
|
|
|
char *dname = NULL, *dtype = NULL;
|
|
|
@ -113,7 +168,6 @@ static void __dirlist_out(FILE *f, list_head_t *list)
|
|
|
|
|
|
|
|
|
|
|
|
static int __list(sxlink_t *link, char **argv, int argc)
|
|
|
|
static int __list(sxlink_t *link, char **argv, int argc)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
sxmsg_t *msg;
|
|
|
|
|
|
|
|
char *opt = NULL;
|
|
|
|
char *opt = NULL;
|
|
|
|
int r = SXE_SUCCESS;
|
|
|
|
int r = SXE_SUCCESS;
|
|
|
|
sxstream_t *stream;
|
|
|
|
sxstream_t *stream;
|
|
|
@ -142,6 +196,7 @@ static int __list(sxlink_t *link, char **argv, int argc)
|
|
|
|
struct _shll_cmds shcmds[] = {
|
|
|
|
struct _shll_cmds shcmds[] = {
|
|
|
|
{ "cd", __cwd },
|
|
|
|
{ "cd", __cwd },
|
|
|
|
{ "ls", __list },
|
|
|
|
{ "ls", __list },
|
|
|
|
|
|
|
|
{ "stat", __stat },
|
|
|
|
{ "", NULL},
|
|
|
|
{ "", NULL},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|