Add header.
[vlendec/samba-autobuild/.git] / source4 / scripting / ejs / smbcalls_options.c
index 9fbfd312a99168f1630ce7cff83bd2d7e47717ba..93872baa40dda7fc79d1c8eabbf832b9e03901b7 100644 (file)
@@ -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,
    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 <http://www.gnu.org/licenses/>.
 */
 
 #include "includes.h"
 #include "lib/cmdline/popt_common.h"
 #include "scripting/ejs/smbcalls.h"
-#include "lib/appweb/ejs/ejs.h"
 
 
 /*
   usage:
-      var options = new Object();
-      result = GetOptions(argv, options, 
+      options = GetOptions(argv, 
                           "realm=s", 
                           "enablexx", 
                           "myint=i");
@@ -41,6 +38,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 +50,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 +66,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);
@@ -83,7 +80,7 @@ static int ejs_GetOptions(MprVarHandle eid, int argc, struct MprVar **argv)
        }
 
        /* create the long_options array */
-       for (i=2;i<argc;i++) {
+       for (i=1;i<argc;i++) {
                const char *optstr = mprToString(argv[i]);
                int t, opt_type = POPT_ARG_NONE;
                const char *s;
@@ -157,7 +154,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;
@@ -178,7 +175,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;
 }