diff options
author | Tim Potter <tpot@samba.org> | 2005-06-26 07:34:55 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 13:18:51 -0500 |
commit | c36e1ae46c266c9a6f012e5715a8df69faad04cd (patch) | |
tree | 4b0cf5e1f4a08b82a73fd9145903d03658f01945 /source4/scripting/ejs | |
parent | 382fc485b2285434f7613255da7b3e894222dcf3 (diff) | |
download | samba-c36e1ae46c266c9a6f012e5715a8df69faad04cd.tar.gz samba-c36e1ae46c266c9a6f012e5715a8df69faad04cd.tar.bz2 samba-c36e1ae46c266c9a6f012e5715a8df69faad04cd.zip |
r7928: Add rename, unlink and list commands.
list() returns a list of strings, but maybe it should be a list of
objects with size, attrib, short name etc.
(This used to be commit 696aa182d5a159c26b80829e1eae9a9894cb7986)
Diffstat (limited to 'source4/scripting/ejs')
-rw-r--r-- | source4/scripting/ejs/smbcalls_cli.c | 141 |
1 files changed, 139 insertions, 2 deletions
diff --git a/source4/scripting/ejs/smbcalls_cli.c b/source4/scripting/ejs/smbcalls_cli.c index 46813f8f23..ca8fbd3ea2 100644 --- a/source4/scripting/ejs/smbcalls_cli.c +++ b/source4/scripting/ejs/smbcalls_cli.c @@ -24,6 +24,7 @@ #include "lib/ejs/ejs.h" #include "libcli/raw/libcliraw.h" #include "libcli/composite/composite.h" +#include "clilist.h" #if 0 @@ -482,7 +483,7 @@ static int ejs_tree_disconnect(MprVarHandle eid, int argc, MprVar **argv) return 0; } -/* Perform a tree connect: +/* Create a directory: result = mkdir(tree_handle, DIRNAME); */ @@ -516,7 +517,7 @@ static int ejs_mkdir(MprVarHandle eid, int argc, MprVar **argv) return 0; } -/* Perform a tree connect: +/* Remove a directory: result = rmdir(tree_handle, DIRNAME); */ @@ -550,6 +551,138 @@ static int ejs_rmdir(MprVarHandle eid, int argc, MprVar **argv) return 0; } +/* Rename a file or directory: + + result = rename(tree_handle, SRCFILE, DESTFILE); + */ + +static int ejs_rename(MprVarHandle eid, int argc, MprVar **argv) +{ + struct smbcli_tree *tree; + NTSTATUS result; + + if (argc != 3) { + ejsSetErrorMsg(eid, "rename(): invalid number of args"); + return -1; + } + + if (!IS_TREE_HANDLE(argv[0])) { + ejsSetErrorMsg(eid, "first arg is not a tree handle"); + return -1; + } + + tree = argv[0]->ptr; + + if (!mprVarIsString(argv[1]->type)) { + ejsSetErrorMsg(eid, "arg 2 must be a string"); + return -1; + } + + if (!mprVarIsString(argv[2]->type)) { + ejsSetErrorMsg(eid, "arg 3 must be a string"); + return -1; + } + + result = smbcli_rename(tree, argv[1]->string, argv[2]->string); + + ejsSetReturnValue(eid, mprNTSTATUS(result)); + + return 0; +} + +/* Unlink a file or directory: + + result = unlink(tree_handle, FILENAME); + */ + +static int ejs_unlink(MprVarHandle eid, int argc, MprVar **argv) +{ + struct smbcli_tree *tree; + NTSTATUS result; + + if (argc != 2) { + ejsSetErrorMsg(eid, "unlink(): invalid number of args"); + return -1; + } + + if (!IS_TREE_HANDLE(argv[0])) { + ejsSetErrorMsg(eid, "first arg is not a tree handle"); + return -1; + } + + tree = argv[0]->ptr; + + if (!mprVarIsString(argv[1]->type)) { + ejsSetErrorMsg(eid, "arg 2 must be a string"); + return -1; + } + + result = smbcli_unlink(tree, argv[1]->string); + + ejsSetReturnValue(eid, mprNTSTATUS(result)); + + return 0; +} + +/* List directory contents + + result = list(tree_handle, ARG1, ...); + */ + +static void ejs_list_helper(struct clilist_file_info *info, const char *mask, + void *state) + +{ + MprVar *result = (MprVar *)state, value; + char idx[16]; + + mprItoa(result->properties->numDataItems, idx, sizeof(idx)); + value = mprCreateStringVar(info->name, 1); + mprCreateProperty(result, idx, &value); +} + +static int ejs_list(MprVarHandle eid, int argc, MprVar **argv) +{ + struct smbcli_tree *tree; + char *mask; + uint16_t attribute; + MprVar result; + + if (argc != 3) { + ejsSetErrorMsg(eid, "list(): invalid number of args"); + return -1; + } + + if (!IS_TREE_HANDLE(argv[0])) { + ejsSetErrorMsg(eid, "first arg is not a tree handle"); + return -1; + } + + tree = argv[0]->ptr; + + if (!mprVarIsString(argv[1]->type)) { + ejsSetErrorMsg(eid, "arg 2 must be a string"); + return -1; + } + + mask = argv[1]->string; + + if (!mprVarIsNumber(argv[2]->type)) { + ejsSetErrorMsg(eid, "arg 3 must be a number"); + return -1; + } + + attribute = mprVarToInteger(argv[2]); + + result = mprCreateObjVar("list", MPR_DEFAULT_HASH_SIZE); + + smbcli_list(tree, mask, attribute, ejs_list_helper, &result); + + ejsSetReturnValue(eid, result); + + return 0; +} + /* setup C functions that be called from ejs */ @@ -560,6 +693,10 @@ void smb_setup_ejs_cli(void) ejsDefineCFunction(-1, "mkdir", ejs_mkdir, NULL, MPR_VAR_SCRIPT_HANDLE); ejsDefineCFunction(-1, "rmdir", ejs_rmdir, NULL, MPR_VAR_SCRIPT_HANDLE); + ejsDefineCFunction(-1, "rename", ejs_rename, NULL, MPR_VAR_SCRIPT_HANDLE); + ejsDefineCFunction(-1, "unlink", ejs_unlink, NULL, MPR_VAR_SCRIPT_HANDLE); + ejsDefineCFunction(-1, "list", ejs_list, NULL, MPR_VAR_SCRIPT_HANDLE); + #if 0 ejsDefineStringCFunction(-1, "connect", ejs_cli_connect, NULL, MPR_VAR_SCRIPT_HANDLE); |