From f583a85d4d520b0ab6ca83efd36e71563108b370 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 11 Jul 2005 07:42:43 +0000 Subject: r8316: give full access to the popt command line parsing in ejs scripts, including access to the samba common options. For example: ok = GetOptions(ARGV, options, "POPT_AUTOHELP", "POPT_COMMON_SAMBA", "myopt=s", "intopt=i", "noopt"); this allows scripts to support their own extended options properly (This used to be commit 775fb56ac287b8d485b38f633b9480d7b7ab64e3) --- source4/scripting/ejs/smbcalls_options.c | 193 +++++++++++++++++++++++++++++++ 1 file changed, 193 insertions(+) create mode 100644 source4/scripting/ejs/smbcalls_options.c (limited to 'source4/scripting/ejs/smbcalls_options.c') diff --git a/source4/scripting/ejs/smbcalls_options.c b/source4/scripting/ejs/smbcalls_options.c new file mode 100644 index 0000000000..335663acfe --- /dev/null +++ b/source4/scripting/ejs/smbcalls_options.c @@ -0,0 +1,193 @@ +/* + Unix SMB/CIFS implementation. + + provide a command line options parsing function for ejs + + Copyright (C) Andrew Tridgell 2005 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" +#include "lib/cmdline/popt_common.h" +#include "scripting/ejs/smbcalls.h" +#include "lib/ejs/ejs.h" + + +/* + usage: + var options = new Object(); + result = GetOptions(argv, options, + "realm=s", + "enablexx", + "myint=i"); + + the special options POPT_COMMON_* options are recognised and replaced + with the Samba internal options + + resulting parsed options are placed in the options object + + additional command line arguments are placed in options.ARGV +*/ +static int ejs_GetOptions(MprVarHandle eid, int argc, struct MprVar **argv) +{ + poptContext pc; + int opt; + struct { + const char *name; + struct poptOption *table; + const char *description; + } tables[] = { + { "POPT_AUTOHELP", poptHelpOptions, "Help options:" }, + { "POPT_COMMON_SAMBA", popt_common_samba, "Common Samba options:" }, + { "POPT_COMMON_CONNECTION", popt_common_connection, "Connection options:" }, + { "POPT_COMMON_CREDENTIALS", popt_common_credentials, "Authentication options:" }, + { "POPT_COMMON_VERSION", popt_common_version, "Common Samba options:" } + }; + TALLOC_CTX *tmp_ctx = talloc_new(mprMemCtx()); + struct poptOption *long_options = NULL; + struct MprVar *options; + int i, num_options = 0; + int opt_argc; + const char **opt_argv; + const char **opt_names = NULL; + const int BASE_OPTNUM = 0x100000; + + /* validate arguments */ + if (argc < 2 || + argv[0]->type != MPR_TYPE_OBJECT || + argv[1]->type != MPR_TYPE_OBJECT) { + ejsSetErrorMsg(eid, "GetOptions invalid arguments"); + return -1; + } + + opt_argv = mprToList(tmp_ctx, argv[0]); + options = argv[1]; + opt_argc = str_list_length(opt_argv); + + long_options = talloc_array(tmp_ctx, struct poptOption, 1); + if (long_options == NULL) { + return -1; + } + + /* create the long_options array */ + for (i=2;itype != MPR_TYPE_STRING) { + ejsSetErrorMsg(eid, "GetOptions string argument"); + return -1; + } + + long_options = talloc_realloc(tmp_ctx, long_options, + struct poptOption, num_options+2); + if (long_options == NULL) { + return -1; + } + ZERO_STRUCT(long_options[num_options]); + + /* see if its one of the special samba option tables */ + for (t=0;t= num_options + BASE_OPTNUM) { + char *err; + err = talloc_asprintf(tmp_ctx, "%s: %s", + poptBadOption(pc, POPT_BADOPTION_NOALIAS), + poptStrerror(opt)); + mprSetVar(options, "ERROR", mprCreateStringVar(err, 1)); + talloc_free(tmp_ctx); + mpr_Return(eid, mprCreateBoolVar(0)); + return 0; + } + opt -= BASE_OPTNUM; + arg = poptGetOptArg(pc); + if (arg == NULL) { + mprSetVar(options, opt_names[opt], mprCreateBoolVar(1)); + } else if (long_options[opt].argInfo == POPT_ARG_INT) { + int v = strtol(arg, NULL, 0); + mprSetVar(options, opt_names[opt], mprCreateIntegerVar(v)); + } else { + mprSetVar(options, opt_names[opt], mprCreateStringVar(arg, 1)); + } + } + + /* setup options.argv list */ + mprSetVar(options, "ARGV", mprList("ARGV", poptGetArgs(pc))); + + poptFreeContext(pc); + + talloc_free(tmp_ctx); + mpr_Return(eid, mprCreateBoolVar(1)); + return 0; +} + + + +/* + setup C functions that be called from ejs +*/ +void smb_setup_ejs_options(void) +{ + ejsDefineCFunction(-1, "GetOptions", ejs_GetOptions, NULL, MPR_VAR_SCRIPT_HANDLE); +} -- cgit From b1e93b296ea8f62ce0f15ccef5f6ae5339f4929f Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 12 Jul 2005 02:34:49 +0000 Subject: r8337: - use 64 bit access functions in ejs calls - added access to smbd random functions - fixed ordering in join() - added sys_interfaces(), sys_hostname(), sys_nttime() and sys_ldaptime() (This used to be commit 28c1a1f3c0cd2f8228fd8c3c695ab6f45226fa3f) --- source4/scripting/ejs/smbcalls_options.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/scripting/ejs/smbcalls_options.c') diff --git a/source4/scripting/ejs/smbcalls_options.c b/source4/scripting/ejs/smbcalls_options.c index 335663acfe..df871cbb96 100644 --- a/source4/scripting/ejs/smbcalls_options.c +++ b/source4/scripting/ejs/smbcalls_options.c @@ -73,7 +73,7 @@ static int ejs_GetOptions(MprVarHandle eid, int argc, struct MprVar **argv) return -1; } - opt_argv = mprToList(tmp_ctx, argv[0]); + opt_argv = mprToArray(tmp_ctx, argv[0]); options = argv[1]; opt_argc = str_list_length(opt_argv); -- cgit From 9f86e202865807ed898eff684d7cf3be7daae0fc Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 12 Jul 2005 05:53:51 +0000 Subject: r8340: - added sys_gmtime() - added sys_unlink() - added sys_file_load() and sys_file_save() - use mprString() instead of mprCreateStringVar() to cope with NULL strings - removed smbcalls_irpc.c as its not needed any more - allow ldbAdd() and ldbModify() to take multiple ldif records - added a sprintf() function to ejs. Quite complex, but very useful! (This used to be commit 625628a3f6e78349d2240ebcc79081f350672070) --- source4/scripting/ejs/smbcalls_options.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/scripting/ejs/smbcalls_options.c') diff --git a/source4/scripting/ejs/smbcalls_options.c b/source4/scripting/ejs/smbcalls_options.c index df871cbb96..005a3bcb9a 100644 --- a/source4/scripting/ejs/smbcalls_options.c +++ b/source4/scripting/ejs/smbcalls_options.c @@ -155,7 +155,7 @@ static int ejs_GetOptions(MprVarHandle eid, int argc, struct MprVar **argv) err = talloc_asprintf(tmp_ctx, "%s: %s", poptBadOption(pc, POPT_BADOPTION_NOALIAS), poptStrerror(opt)); - mprSetVar(options, "ERROR", mprCreateStringVar(err, 1)); + mprSetVar(options, "ERROR", mprString(err)); talloc_free(tmp_ctx); mpr_Return(eid, mprCreateBoolVar(0)); return 0; @@ -168,7 +168,7 @@ static int ejs_GetOptions(MprVarHandle eid, int argc, struct MprVar **argv) int v = strtol(arg, NULL, 0); mprSetVar(options, opt_names[opt], mprCreateIntegerVar(v)); } else { - mprSetVar(options, opt_names[opt], mprCreateStringVar(arg, 1)); + mprSetVar(options, opt_names[opt], mprString(arg)); } } -- cgit From adbb1612c12d03fa94e4ee23fbc2fa96c09d9dcd Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 13 Jul 2005 00:06:38 +0000 Subject: r8399: move the ejs and esp code closer to the directory layout used by the upstream sources. This makes it much easier to keep it up to date. I will separate out the mpr code into lib/appweb/mpr next (This used to be commit 52db7a052baeb0f11361ed69b71cb790039e3cc9) --- source4/scripting/ejs/smbcalls_options.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/scripting/ejs/smbcalls_options.c') diff --git a/source4/scripting/ejs/smbcalls_options.c b/source4/scripting/ejs/smbcalls_options.c index 005a3bcb9a..9fbfd312a9 100644 --- a/source4/scripting/ejs/smbcalls_options.c +++ b/source4/scripting/ejs/smbcalls_options.c @@ -23,7 +23,7 @@ #include "includes.h" #include "lib/cmdline/popt_common.h" #include "scripting/ejs/smbcalls.h" -#include "lib/ejs/ejs.h" +#include "lib/appweb/ejs/ejs.h" /* -- cgit From 55e746ad560d4406821bc2d721cbb929b79a7a0a Mon Sep 17 00:00:00 2001 From: Rafal Szczesniak Date: Mon, 22 Aug 2005 14:32:58 +0000 Subject: r9477: Convert popt options to an ejs object. Doesn't seem to break anything except of popt help (-h) option (unexpected ?). rafal (This used to be commit 1990793b23d6198a85ce1bdf6ad43e12015db203) --- source4/scripting/ejs/smbcalls_options.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'source4/scripting/ejs/smbcalls_options.c') diff --git a/source4/scripting/ejs/smbcalls_options.c b/source4/scripting/ejs/smbcalls_options.c index 9fbfd312a9..8eca9ebcaa 100644 --- a/source4/scripting/ejs/smbcalls_options.c +++ b/source4/scripting/ejs/smbcalls_options.c @@ -28,8 +28,7 @@ /* usage: - var options = new Object(); - result = GetOptions(argv, options, + options = GetOptions(argv, "realm=s", "enablexx", "myint=i"); @@ -41,6 +40,7 @@ additional command line arguments are placed in options.ARGV */ + static int ejs_GetOptions(MprVarHandle eid, int argc, struct MprVar **argv) { poptContext pc; @@ -52,13 +52,15 @@ static int ejs_GetOptions(MprVarHandle eid, int argc, struct MprVar **argv) } tables[] = { { "POPT_AUTOHELP", poptHelpOptions, "Help options:" }, { "POPT_COMMON_SAMBA", popt_common_samba, "Common Samba options:" }, - { "POPT_COMMON_CONNECTION", popt_common_connection, "Connection options:" }, + { "POPT_COMMON_CONNECTION", popt_common_connection, "Connection options:" }, { "POPT_COMMON_CREDENTIALS", popt_common_credentials, "Authentication options:" }, { "POPT_COMMON_VERSION", popt_common_version, "Common Samba options:" } }; + + struct MprVar *options = mprInitObject(eid, "options", 0, NULL); + TALLOC_CTX *tmp_ctx = talloc_new(mprMemCtx()); struct poptOption *long_options = NULL; - struct MprVar *options; int i, num_options = 0; int opt_argc; const char **opt_argv; @@ -66,15 +68,12 @@ static int ejs_GetOptions(MprVarHandle eid, int argc, struct MprVar **argv) const int BASE_OPTNUM = 0x100000; /* validate arguments */ - if (argc < 2 || - argv[0]->type != MPR_TYPE_OBJECT || - argv[1]->type != MPR_TYPE_OBJECT) { + if (argc < 1 || argv[0]->type != MPR_TYPE_OBJECT) { ejsSetErrorMsg(eid, "GetOptions invalid arguments"); return -1; } opt_argv = mprToArray(tmp_ctx, argv[0]); - options = argv[1]; opt_argc = str_list_length(opt_argv); long_options = talloc_array(tmp_ctx, struct poptOption, 1); @@ -178,7 +177,10 @@ static int ejs_GetOptions(MprVarHandle eid, int argc, struct MprVar **argv) poptFreeContext(pc); talloc_free(tmp_ctx); - mpr_Return(eid, mprCreateBoolVar(1)); + + /* setup methods */ + mprSetCFunction(options, "get_credentials", ejs_credentials_cmdline); + return 0; } -- cgit From da6dc01ae2c7bc26a14af2189d345e0ec38a9660 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 22 Aug 2005 23:33:47 +0000 Subject: r9492: it is more usual to return 'undefined' instead of 'false' on a call failing (unless the call is returning a boolean anyway). Unfortunately the new GetOptions syntax loses the ability for the caller to know why the command line arguments were bad. Maybe we would be better always returning an object and having an is_error element? (This used to be commit 516ba6d20bd1bd8d0235028515e94a8c4fd6574d) --- source4/scripting/ejs/smbcalls_options.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/scripting/ejs/smbcalls_options.c') diff --git a/source4/scripting/ejs/smbcalls_options.c b/source4/scripting/ejs/smbcalls_options.c index 8eca9ebcaa..3ba51bb2f4 100644 --- a/source4/scripting/ejs/smbcalls_options.c +++ b/source4/scripting/ejs/smbcalls_options.c @@ -156,7 +156,7 @@ static int ejs_GetOptions(MprVarHandle eid, int argc, struct MprVar **argv) poptStrerror(opt)); mprSetVar(options, "ERROR", mprString(err)); talloc_free(tmp_ctx); - mpr_Return(eid, mprCreateBoolVar(0)); + mpr_Return(eid, mprCreateUndefinedVar()); return 0; } opt -= BASE_OPTNUM; -- cgit From 2e35b720862e1a48a8b3ff1400262d4185258121 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 26 Aug 2005 11:37:52 +0000 Subject: r9645: fixed the ejs GetOptions() call to look at the first option passed (this is what broke --help) (This used to be commit 88a7e9e00f3714f89067ef97dfca46bc0688222e) --- source4/scripting/ejs/smbcalls_options.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/scripting/ejs/smbcalls_options.c') diff --git a/source4/scripting/ejs/smbcalls_options.c b/source4/scripting/ejs/smbcalls_options.c index 3ba51bb2f4..2e94b7d72b 100644 --- a/source4/scripting/ejs/smbcalls_options.c +++ b/source4/scripting/ejs/smbcalls_options.c @@ -82,7 +82,7 @@ static int ejs_GetOptions(MprVarHandle eid, int argc, struct MprVar **argv) } /* create the long_options array */ - for (i=2;i Date: Fri, 30 Dec 2005 13:16:54 +0000 Subject: r12608: Remove some unused #include lines. (This used to be commit 70e7449318aa0e9d2639c76730a7d1683b2f4981) --- source4/scripting/ejs/smbcalls_options.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source4/scripting/ejs/smbcalls_options.c') diff --git a/source4/scripting/ejs/smbcalls_options.c b/source4/scripting/ejs/smbcalls_options.c index 2e94b7d72b..d24d689cf3 100644 --- a/source4/scripting/ejs/smbcalls_options.c +++ b/source4/scripting/ejs/smbcalls_options.c @@ -23,7 +23,6 @@ #include "includes.h" #include "lib/cmdline/popt_common.h" #include "scripting/ejs/smbcalls.h" -#include "lib/appweb/ejs/ejs.h" /* -- cgit From 0479a2f1cbae51fcd8dbdc3c148c808421fb4d25 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 02:07:03 +0000 Subject: r23792: convert Samba4 to GPLv3 There are still a few tidyups of old FSF addresses to come (in both s3 and s4). More commits soon. (This used to be commit fcf38a38ac691abd0fa51b89dc951a08e89fdafa) --- source4/scripting/ejs/smbcalls_options.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'source4/scripting/ejs/smbcalls_options.c') diff --git a/source4/scripting/ejs/smbcalls_options.c b/source4/scripting/ejs/smbcalls_options.c index d24d689cf3..93872baa40 100644 --- a/source4/scripting/ejs/smbcalls_options.c +++ b/source4/scripting/ejs/smbcalls_options.c @@ -7,7 +7,7 @@ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -16,8 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ #include "includes.h" -- cgit