static void printUsage(Mpr *mpr) { mprEprintf("usage: makerom [options] files... >output.c\n"); mprEprintf(" Makerom options:\n"); mprEprintf(" --prefix prefix # File prefix to remove\n"); mprEprintf(" --name structName # Name of top level C struct\n"); }
MAIN(benchMpr, int argc, char **argv, char **envp) { MprThread *thread; Mpr *mpr; char *argp; int err, nextArg; if ((mpr = mprCreate(argc, argv, MPR_USER_EVENTS_THREAD)) == 0) { return MPR_ERR_MEMORY; } if ((app = mprAllocObj(App, manageApp)) == 0) { return MPR_ERR_MEMORY; } mprAddRoot(app); app->mutex = mprCreateLock(mpr); app->complete = mprCreateCond(); app->iterations = 5; err = 0; for (nextArg = 1; nextArg < argc; nextArg++) { argp = argv[nextArg]; if (*argp != '-') { break; } if (strcmp(argp, "--iterations") == 0 || strcmp(argp, "-i") == 0) { if (nextArg >= argc) { err++; } else { app->iterations = atoi(argv[++nextArg]); } } else if (strcmp(argp, "--alloc") == 0 || strcmp(argp, "-a") == 0) { app->testAllocOnly++; } else { err++; } } if (err) { mprEprintf("usage: bench [-a] [-i iterations]\n"); mprEprintf("usage: %s [options]\n" " -a # Alloc test only\n" " --iterations count # Number of iterations to run the test\n", mprGetAppName(mpr)); exit(2); } mprStart(mpr); thread = mprCreateThread("bench", (MprThreadProc) doBenchmark, (void*) MPR, 0); mprStartThread(thread); while (!testComplete) { mprServiceEvents(250, 0); } mprPrintMem("Memory Report", 0); mprDestroy(); return 0; }
static void usageError(Mpr *mpr) { cchar *name; name = mprGetAppName(); mprEprintf("\n%s Usage:\n\n" " %s [options]\n" " %s [options] documents ip[:port] ...\n\n" " Without [documents ip:port], %s will read the appweb.conf configuration file.\n\n" " Options:\n" " --config configFile # Use named config file instead appweb.conf\n" " --chroot directory # Change root directory to run more securely (Unix)\n" " --debugger # Disable timeouts to make debugging easier\n" " --exe path # Set path to Appweb executable on Vxworks\n" " --home directory # Change to directory to run\n" " --log logFile:level # Log to file at verbosity level (0-5)\n" " --name uniqueName # Unique name for this instance\n" " --show # Show route table\n" " --trace traceFile:level # Trace to file at verbosity level (0-5)\n" " --verbose # Same as --log stderr:2\n" " --version # Output version information\n" " --DIGIT # Same as --log stderr:DIGIT\n\n", mprGetAppTitle(), name, name, name); exit(10); }
int main(int argc, char *argv[]) { Mpr *mpr; int rc; mpr = mprCreate(argc, argv, MPR_USER_EVENTS_THREAD); mprAddStandardSignals(); app = mprAllocObj(App, manageApp); mprAddRoot(app); app->host = sclone("127.0.0.1"); app->port = 4100; if ((ts = mprCreateTestService(mpr)) == 0) { mprLog("appweb test", 0, "Cannot create test service"); exit(2); } if (mprParseTestArgs(ts, argc, argv, parseArgs) < 0) { mprEprintf("\n" " Commands specifically for %s\n" " --host ip:port # Set the default host address for testing\n\n", mprGetAppName(mpr)); exit(3); } if (mprAddTestGroup(ts, &master) == 0) { exit(4); } #if BIT_PACK_SSL if (mprLoadSsl(0) < 0) { return 0; } #endif /* Need a background event thread as we use the main thread to run the tests. */ if (mprStart(mpr)) { mprLog("appweb test", 0, "Cannot start mpr services"); exit(5); } /* Run the tests and return zero if 100% success */ rc = mprRunTests(ts); mprReportTestResults(ts); mprDestroy(); return (rc == 0) ? 0 : -1; }
static int showUsage() { mprEprintf("usage: %s [options] [files] url\n" " Options:\n" " --auth basic|digest # Set authentication type.\n" " --benchmark # Compute benchmark results.\n" " --ca file # Certificate bundle to use when validating the server certificate.\n" " --cert file # Certificate to send to the server to identify the client.\n" " --chunk size # Request response data to use this chunk size.\n" " --ciphers cipher,... # List of suitable ciphers.\n" " --continue # Continue on errors.\n" " --cookie CookieString # Define a cookie header. Multiple uses okay.\n" " --data bodyData # Body data to send with PUT or POST.\n" " --debugger # Disable timeouts to make running in a debugger easier.\n" " --delete # Use the DELETE method. Shortcut for --method DELETE..\n" " --form string # Form data. Must already be form-www-urlencoded.\n" " --header 'key: value' # Add a custom request header.\n" " --host hostName # Host name or IP address for unqualified URLs.\n" " --iterations count # Number of times to fetch the URLs per thread (default 1).\n" " --key file # Private key file.\n" " --log logFile:level # Log to the file at the verbosity level.\n" " --method KIND # HTTP request method GET|OPTIONS|POST|PUT|TRACE (default GET).\n" " --nofollow # Don't automatically follow redirects.\n" " --noout # Don't output files to stdout.\n" " --out file # Send output to file.\n" " --password pass # Password for authentication.\n" " --post # Use POST method. Shortcut for --method POST.\n" " --printable # Make binary output printable.\n" " --protocol PROTO # Set HTTP protocol to HTTP/1.0 or HTTP/1.1 .\n" " --put # Use PUT method. Shortcut for --method PUT.\n" " --range byteRanges # Request a subset range of the document.\n" " --retries count # Number of times to retry failing requests.\n" " --sequence # Sequence requests with a custom header.\n" " --showHeaders # Output response headers.\n" " --showStatus # Output the Http response status code.\n" " --single # Single step. Pause for input between requests.\n" " --threads count # Number of thread instances to spawn.\n" " --timeout secs # Request timeout period in seconds.\n" " --upload # Use multipart mime upload.\n" " --user name # User name for authentication.\n" " --verify # Validate server certificates when using SSL.\n" " --verbose # Verbose operation. Trace progress.\n" " --workers count # Set maximum worker threads.\n" " --zero # Exit with zero status for any valid HTTP response.\n" , mprGetAppName()); return MPR_ERR_BAD_ARGS; }
static void usageError() { cchar *name; name = mprGetAppName(); mprEprintf("\n%s Usage:\n\n" " %s [options]\n" " Options:\n" " --config configFile # Use named config file instead http.json\n" " --debugger # Disable timeouts to make debugging easier\n" " --log logFile:level # Log to file at verbosity level (0-5)\n" " --name uniqueName # Unique name for this instance\n" " --show # Show route table\n" " --trace traceFile:level # Trace to file at verbosity level (0-5)\n" " --verbose # Same as --log stderr:2\n" " --version # Output version information\n" " --DIGIT # Same as --log stderr:DIGIT\n\n", mprGetAppTitle(), name); exit(7); }
MAIN(ejsMain, int argc, char **argv, char **envp) { Mpr *mpr; EcCompiler *cp; Ejs *ejs; cchar *cmd, *className, *method, *homeDir, *logSpec, *traceSpec; char *argp, *searchPath, *modules, *name, *tok, *extraFiles; int nextArg, err, ecFlags, stats, merge, bind, noout, debug, optimizeLevel, warnLevel, strict, i, next; /* Initialize Multithreaded Portable Runtime (MPR) */ mpr = mprCreate(argc, argv, 0); app = mprAllocObj(App, manageApp); mprAddRoot(app); mprAddStandardSignals(); if (mprStart(mpr) < 0) { mprLog("ejs", 0, "Cannot start mpr services"); return EJS_ERR; } err = 0; className = 0; cmd = 0; method = 0; searchPath = 0; stats = 0; merge = 0; bind = 1; noout = 1; debug = 1; warnLevel = 1; optimizeLevel = 9; strict = 0; logSpec = 0; traceSpec = 0; app->files = mprCreateList(-1, 0); app->iterations = 1; argc = mpr->argc; argv = (char**) mpr->argv; for (nextArg = 1; nextArg < argc; nextArg++) { argp = argv[nextArg]; if (*argp != '-') { break; } if (smatch(argp, "--bind")) { bind = 1; } else if (smatch(argp, "--class")) { if (nextArg >= argc) { err++; } else { className = argv[++nextArg]; } } else if (smatch(argp, "--chdir") || smatch(argp, "--home") || smatch(argp, "-C")) { if (nextArg >= argc) { err++; } else { homeDir = argv[++nextArg]; if (chdir((char*) homeDir) < 0) { mprLog("ejs", 0, "Cannot change directory to %s", homeDir); } } #if ME_UNIX_LIKE } else if (smatch(argp, "--chroot")) { /* Not documented or supported */ if (nextArg >= argc) { err++; } else { homeDir = mprGetAbsPath(argv[++nextArg]); if (chroot(homeDir) < 0) { if (errno == EPERM) { mprEprintf("%s: Must be super user to use the --chroot option", mprGetAppName(mpr)); } else { mprEprintf("%s: Cannot change change root directory to %s, errno %d", mprGetAppName(), homeDir, errno); } return 4; } } #endif } else if (smatch(argp, "--cmd") || smatch(argp, "-c")) { if (nextArg >= argc) { err++; } else { cmd = argv[++nextArg]; } #if ME_WIN_LIKE } else if (smatch(argp, "--cygroot")) { if (nextArg >= argc) { err++; } else { app->cygroot = sclone(argv[++nextArg]); } #endif } else if (smatch(argp, "--debug")) { debug = 1; } else if (smatch(argp, "--debugger") || smatch(argp, "-D")) { mprSetDebugMode(1); } else if (smatch(argp, "--files") || smatch(argp, "-f")) { /* Compatibility with mozilla shell */ if (nextArg >= argc) { err++; } else { extraFiles = sclone(argv[++nextArg]); name = stok(extraFiles, " \t", &tok); while (name != NULL) { mprAddItem(app->files, sclone(name)); name = stok(NULL, " \t", &tok); } } } else if (smatch(argp, "--iterations") || smatch(argp, "-i")) { if (nextArg >= argc) { err++; } else { app->iterations = atoi(argv[++nextArg]); } } else if (smatch(argp, "--log")) { if (nextArg >= argc) { err++; } else { logSpec = argv[++nextArg]; } } else if (smatch(argp, "--method")) { if (nextArg >= argc) { err++; } else { method = argv[++nextArg]; } } else if (smatch(argp, "--name")) { /* Just ignore. Used to tag commands with a unique command line */ nextArg++; } else if (smatch(argp, "--nobind")) { bind = 0; } else if (smatch(argp, "--nodebug")) { debug = 0; } else if (smatch(argp, "--optimize")) { if (nextArg >= argc) { err++; } else { optimizeLevel = atoi(argv[++nextArg]); } } else if (smatch(argp, "--require")) { if (nextArg >= argc) { err++; } else { if (app->modules == 0) { app->modules = mprCreateList(-1, 0); } modules = sclone(argv[++nextArg]); name = stok(modules, " \t", &tok); while (name != NULL) { require(name); name = stok(NULL, " \t", &tok); } } } else if (smatch(argp, "-s")) { /* Compatibility with mozilla shell. Just ignore */ } else if (smatch(argp, "--search") || smatch(argp, "--searchpath")) { if (nextArg >= argc) { err++; } else { searchPath = argv[++nextArg]; } } else if (smatch(argp, "--standard")) { strict = 0; } else if (smatch(argp, "--stats")) { stats = 1; } else if (smatch(argp, "--strict")) { strict = 1; } else if (smatch(argp, "--trace") || smatch(argp, "-t")) { if (nextArg >= argc) { err++; } else { traceSpec = argv[++nextArg]; } } else if (smatch(argp, "--verbose") || smatch(argp, "-v")) { logSpec = "stderr:2"; } else if (smatch(argp, "--version") || smatch(argp, "-V")) { mprPrintf("%s\n", EJS_VERSION); return 0; } else if (smatch(argp, "--warn")) { if (nextArg >= argc) { err++; } else { warnLevel = atoi(argv[++nextArg]); } } else if (*argp == '-' && isdigit((uchar) argp[1])) { if (!logSpec) { logSpec = sfmt("stderr:%d", (int) stoi(&argp[1])); } if (!traceSpec) { traceSpec = sfmt("stderr:%d", (int) stoi(&argp[1])); } } else { err++; break; } } if (err) { /* If --method or --class is specified, then the named class.method will be run (method defaults to "main", class defaults to first class with a "main"). Examples: ejs ejs script.es arg1 arg2 arg3 ejs --class "Customer" --method "start" --files "script1.es script2.es" main.es */ mprEprintf("Usage: %s [options] script.es [arguments] ...\n" " Ejscript shell program options:\n" " --class className # Name of class containing method to run\n" " --cmd ejscriptCode # Literal ejscript statements to execute\n" " --cygroot path # Set cygwin root for resolving script paths\n" " --debug # Use symbolic debugging information (default)\n" " --debugger # Disable timeouts to make using a debugger easier\n" " --files \"files..\" # Extra source to compile\n" " --log logSpec # Internal compiler diagnostics logging\n" " --method methodName # Name of method to run. Defaults to main\n" " --nodebug # Omit symbolic debugging information\n" " --optimize level # Set the optimization level (0-9 default is 9)\n" " --require 'module,...' # Required list of modules to pre-load\n" " --search ejsPath # Module search path\n" " --standard # Default compilation mode to standard (default)\n" " --stats # Print memory stats on exit\n" " --strict # Default compilation mode to strict\n" " --trace traceSpec # HTTP request tracing\n" " --verbose | -v # Same as --log stderr:2 \n" " --version # Emit the compiler version information\n" " --warn level # Set the warning message level (0-9 default is 0)\n\n", mpr->name); return -1; } if (logSpec) { mprStartLogging(logSpec, MPR_LOG_CMDLINE); } if (traceSpec) { httpCreate(HTTP_CLIENT_SIDE | HTTP_SERVER_SIDE); httpStartTracing(traceSpec); } if ((ejs = ejsCreateVM(argc - nextArg, (cchar **) &argv[nextArg], 0)) == 0) { return MPR_ERR_MEMORY; } mprStartDispatcher(ejs->dispatcher); app->ejs = ejs; if (ejsLoadModules(ejs, searchPath, app->modules) < 0) { return MPR_ERR_CANT_READ; } mprGC(MPR_GC_FORCE); ecFlags = 0; ecFlags |= (merge) ? EC_FLAGS_MERGE: 0; ecFlags |= (bind) ? EC_FLAGS_BIND: 0; ecFlags |= (noout) ? EC_FLAGS_NO_OUT: 0; ecFlags |= (debug) ? EC_FLAGS_DEBUG: 0; cp = app->compiler = ecCreateCompiler(ejs, ecFlags); if (cp == 0) { return MPR_ERR_MEMORY; } ecSetRequire(cp, app->modules); ecSetOptimizeLevel(cp, optimizeLevel); ecSetWarnLevel(cp, warnLevel); ecSetStrictMode(cp, strict); if (nextArg < argc) { mprAddItem(app->files, sclone(argv[nextArg])); } if (app->cygroot) { /* When cygwin invokes a script with shebang, it passes a cygwin path to the script The ejs --cygroot option permits ejscript to conver this to a native path */ for (next = 0; (name = mprGetNextItem(app->files, &next)) != 0; ) { if (*name == '/' || *name == '\\') { mprSetItem(app->files, next - 1, sjoin(app->cygroot, name, NULL)); } } } for (i = 0; !err && i < app->iterations; i++) { if (cmd) { if (interpretCommands(cp, cmd) < 0) { err++; } } else if (mprGetListLength(app->files) > 0) { if (interpretFiles(cp, app->files, argc - nextArg, &argv[nextArg], className, method) < 0) { err++; } } else { /* No args - run as an interactive shell */ if (interpretCommands(cp, NULL) < 0) { err++; } } } if (stats) { #if ME_DEBUG mprSetLogLevel(1); mprPrintMem("Memory Usage", 1); #endif } if (err) { mprSetExitStatus(err); } app->ejs = 0; app->compiler = 0; ejsDestroy(ejs); mprDestroy(); return mprGetExitStatus(); }
MAIN(ejscMain, int argc, char **argv, char **envp) { Mpr *mpr; MprList *args; Ejs *ejs; EcCompiler *cp; char *argp, *searchPath, *outputFile, *outputDir, *certFile, *name, *tok, *modules; int nextArg, err, ejsFlags, ecFlags, bind, debug, doc, merge, modver; int warnLevel, noout, parseOnly, tabWidth, optimizeLevel, strict; /* Initialize the Multithreaded Portable Runtime (MPR) */ mpr = mprCreate(argc, argv, 0); app = mprAllocObj(App, manageApp); mprAddRoot(app); mprAddStandardSignals(); if (mprStart() < 0) { mprLog("ejsc", 0, "Cannot start mpr services"); return EJS_ERR; } err = 0; searchPath = 0; strict = 0; certFile = 0; ecFlags = 0; bind = 0; debug = 0; doc = 0; merge = 0; modver = 0; noout = 0; parseOnly = 0; tabWidth = 4; warnLevel = 1; outputFile = 0; outputDir = 0; optimizeLevel = 9; for (nextArg = 1; nextArg < argc; nextArg++) { argp = argv[nextArg]; if (*argp != '-') { break; } if (strcmp(argp, "--bind") == 0) { bind = 1; } else if (strcmp(argp, "--debug") == 0) { debug = 1; } else if (strcmp(argp, "--debugger") == 0 || strcmp(argp, "-D") == 0) { mprSetDebugMode(1); } else if (strcmp(argp, "--dir") == 0) { /* Set the output directory for modules */ if (nextArg >= argc) { err++; } else { outputDir = argv[++nextArg]; } } else if (strcmp(argp, "--doc") == 0) { doc = 1; } else if (strcmp(argp, "--log") == 0) { /* Undocumented logging switch */ if (nextArg >= argc) { err++; } else { mprStartLogging(argv[++nextArg], 0); mprSetCmdlineLogging(1); } } else if (strcmp(argp, "--merge") == 0) { merge = 1; } else if (strcmp(argp, "--modver") == 0) { if (nextArg >= argc) { err++; } else { modver = ejsParseModuleVersion(argv[++nextArg]); } } else if (strcmp(argp, "--nobind") == 0) { bind = 0; } else if (strcmp(argp, "--noout") == 0) { noout = 1; } else if (strcmp(argp, "--standard") == 0) { strict = 0; } else if (strcmp(argp, "--strict") == 0) { strict = 1; } else if (strcmp(argp, "--optimize") == 0) { if (nextArg >= argc) { err++; } else { optimizeLevel = atoi(argv[++nextArg]); } } else if (strcmp(argp, "--out") == 0) { /* Create a single output module file containing all modules */ if (nextArg >= argc) { err++; } else { outputFile = argv[++nextArg]; } } else if (strcmp(argp, "--parse") == 0) { parseOnly = 1; } else if (strcmp(argp, "--search") == 0 || strcmp(argp, "--searchpath") == 0) { if (nextArg >= argc) { err++; } else { searchPath = argv[++nextArg]; } } else if (strcmp(argp, "--require") == 0) { if (nextArg >= argc) { err++; } else { if (app->modules == 0) { app->modules = mprCreateList(-1, 0); } modules = sclone(argv[++nextArg]); /* Fix for Xcode and Visual Studio */ if (modules[0] == ' ' || scmp(modules, "null") == 0) { modules[0] = '\0'; } name = stok(modules, " \t,", &tok); while (name != NULL) { require(name); name = stok(NULL, " \t", &tok); } } } else if (strcmp(argp, "--sign") == 0) { if (nextArg >= argc) { err++; } else { certFile = argv[++nextArg]; } #if FUTURE } else if (strcmp(argp, "--strip") == 0) { strip = 1; #endif } else if (strcmp(argp, "--tabWidth") == 0) { if (nextArg >= argc) { err++; } else { tabWidth = atoi(argv[++nextArg]); } } else if (strcmp(argp, "--version") == 0 || strcmp(argp, "-V") == 0) { mprPrintf("%s\n", ME_TITLE, EJS_VERSION); return 0; } else if (strcmp(argp, "--warn") == 0) { if (nextArg >= argc) { err++; } else { warnLevel = atoi(argv[++nextArg]); } } else if (strcmp(argp, "--web") == 0) { if (app->modules == 0) { app->modules = mprCreateList(-1, 0); } require("ejs"); require("ejs.unix"); require("ejs.db"); // TODO - decouple and remove this require("ejs.db.mapper"); require("ejs.web"); } else { err++; break; } } if (noout || merge) { bind = 1; } if (outputFile && noout) { mprEprintf("Cannot use --out and --noout\n"); err++; } if (argc == nextArg) { err++; } if (err) { /* Usage Examples: ejsc Person.es User.es Customer.es ejsc --out group.mod Person.es User.es Customer.es ejsc --out group.mod Person.es User.es Customer.es NOTE: bind is deliberately not documented and is for internal use only. */ mprEprintf("Usage: %s [options] files...\n" " Ejscript compiler options:\n" " --debug # Include symbolic debugging information in output\n" " --doc # Include documentation strings in output\n" " --dir directory # Set the output directory for modules (default: \".\")\n" " --merge # Merge dependent input modules into the output\n" " --modver version # Set the default module version\n" " --noout # Do not generate any output\n" " --optimize level # Set optimization level (0-9)\n" " --out filename # Name a single output module (default: \"default.mod\")\n" " --parse # Just parse source. No output\n" " --require 'module ...' # List of required modules to pre-load\n" " --search ejsPath # Module search path\n" " --standard # Default compilation mode to standard (default)\n" " --strict # Default compilation mode to strict\n" #if FUTURE " --sign certFile # Sign the module file (not implemented) \n" " --strip # Strip all symbolic names (Cannot import)\n" " --tabwidth # Tab width for '^' error reporting\n" #endif " --version # Emit the compiler version information\n" " --warn level # Set the warning message level (0-9)\n\n", mpr->name); return -1; } ejsFlags = EJS_FLAG_NO_INIT; if (doc) { ejsFlags |= EJS_FLAG_DOC; } if ((ejs = ejsCreateVM(0, 0, ejsFlags)) == 0) { return MPR_ERR_MEMORY; } #if UNUSED mprRunDispatcher(ejs->dispatcher); #endif if (ejsLoadModules(ejs, searchPath, app->modules) < 0) { return MPR_ERR_CANT_READ; } app->ejs = ejs; ecFlags |= (debug) ? EC_FLAGS_DEBUG: 0; ecFlags |= (merge) ? EC_FLAGS_MERGE: 0; ecFlags |= (bind) ? EC_FLAGS_BIND: 0; ecFlags |= (noout) ? EC_FLAGS_NO_OUT: 0; ecFlags |= (parseOnly) ? EC_FLAGS_PARSE_ONLY: 0; ecFlags |= (doc) ? EC_FLAGS_DOC: 0; cp = app->compiler = ecCreateCompiler(ejs, ecFlags); if (cp == 0) { return MPR_ERR_MEMORY; } cp->require = app->modules; cp->modver = modver; ecSetOptimizeLevel(cp, optimizeLevel); ecSetWarnLevel(cp, warnLevel); ecSetStrictMode(cp, strict); ecSetTabWidth(cp, tabWidth); ecSetOutputDir(cp, outputDir); ecSetOutputFile(cp, outputFile); ecSetCertFile(cp, certFile); if (nextArg < argc) { /* Compile the source files supplied on the command line. This will compile in-memory and optionally also save to module files. */ if ((args = expandWild(ejs, argc - nextArg, &argv[nextArg])) == 0) { err++; } else if (ecCompile(cp, args->length, (char**) args->items) < 0) { err++; } if (cp->warningCount > 0 || cp->errorCount > 0) { mprLog("ejs", 0, "%s\n", cp->errorMsg); } } if (cp->errorCount > 0) { err++; } app->ejs = 0; app->compiler = 0; ejsDestroy(ejs); mprDestroy(); return err; }
static int parseArgs(int argc, char **argv) { char *argp, *key, *value; int i, setWorkers, nextArg, ssl; setWorkers = 0; ssl = 0; for (nextArg = 1; nextArg < argc; nextArg++) { argp = argv[nextArg]; if (*argp != '-') { break; } if (smatch(argp, "--auth")) { if (nextArg >= argc) { return showUsage(); } else { app->authType = slower(argv[++nextArg]); } } else if (smatch(argp, "--benchmark") || smatch(argp, "-b")) { app->benchmark++; } else if (smatch(argp, "--ca")) { if (nextArg >= argc) { return showUsage(); } else { app->ca = sclone(argv[++nextArg]); if (!mprPathExists(app->ca, R_OK)) { mprError("Cannot find ca file %s", app->ca); return MPR_ERR_BAD_ARGS; } } ssl = 1; } else if (smatch(argp, "--cert")) { if (nextArg >= argc) { return showUsage(); } else { app->cert = sclone(argv[++nextArg]); if (!mprPathExists(app->cert, R_OK)) { mprError("Cannot find cert file %s", app->cert); return MPR_ERR_BAD_ARGS; } } ssl = 1; } else if (smatch(argp, "--chunk")) { if (nextArg >= argc) { return showUsage(); } else { value = argv[++nextArg]; app->chunkSize = atoi(value); if (app->chunkSize < 0) { mprError("Bad chunksize %d", app->chunkSize); return MPR_ERR_BAD_ARGS; } } } else if (smatch(argp, "--ciphers")) { if (nextArg >= argc) { return showUsage(); } else { app->ciphers = sclone(argv[++nextArg]); } ssl = 1; } else if (smatch(argp, "--continue") || smatch(argp, "-c")) { app->continueOnErrors++; } else if (smatch(argp, "--cookie")) { if (nextArg >= argc) { return showUsage(); } else { mprAddItem(app->headers, mprCreateKeyPair("Cookie", argv[++nextArg], 0)); } } else if (smatch(argp, "--data")) { if (nextArg >= argc) { return showUsage(); } else { if (app->bodyData == 0) { app->bodyData = mprCreateBuf(-1, -1); } mprPutStringToBuf(app->bodyData, argv[++nextArg]); } } else if (smatch(argp, "--debugger") || smatch(argp, "-D")) { mprSetDebugMode(1); app->retries = 0; app->timeout = MAXINT; } else if (smatch(argp, "--delete")) { app->method = "DELETE"; } else if (smatch(argp, "--form") || smatch(argp, "-f")) { if (nextArg >= argc) { return showUsage(); } else { if (app->formData == 0) { app->formData = mprCreateList(-1, 0); } addFormVars(argv[++nextArg]); } } else if (smatch(argp, "--header")) { if (nextArg >= argc) { return showUsage(); } else { key = argv[++nextArg]; if ((value = strchr(key, ':')) == 0) { mprError("Bad header format. Must be \"key: value\""); return MPR_ERR_BAD_ARGS; } *value++ = '\0'; while (isspace((uchar) *value)) { value++; } mprAddItem(app->headers, mprCreateKeyPair(key, value, 0)); } } else if (smatch(argp, "--host")) { if (nextArg >= argc) { return showUsage(); } else { app->host = argv[++nextArg]; if (*app->host == ':') { app->host = &app->host[1]; } if (isPort(app->host)) { app->host = sfmt("http://127.0.0.1:%s", app->host); } else { app->host = sclone(app->host); } } } else if (smatch(argp, "--iterations") || smatch(argp, "-i")) { if (nextArg >= argc) { return showUsage(); } else { app->iterations = atoi(argv[++nextArg]); } } else if (smatch(argp, "--key")) { if (nextArg >= argc) { return showUsage(); } else { app->key = sclone(argv[++nextArg]); if (!mprPathExists(app->key, R_OK)) { mprError("Cannot find key file %s", app->key); return MPR_ERR_BAD_ARGS; } } ssl = 1; } else if (smatch(argp, "--log") || smatch(argp, "-l")) { if (nextArg >= argc) { return showUsage(); } else { mprStartLogging(argv[++nextArg], 0); } } else if (smatch(argp, "--method") || smatch(argp, "-m")) { if (nextArg >= argc) { return showUsage(); } else { app->method = argv[++nextArg]; } } else if (smatch(argp, "--out") || smatch(argp, "-o")) { if (nextArg >= argc) { return showUsage(); } else { app->outFilename = sclone(argv[++nextArg]); } } else if (smatch(argp, "--noout") || smatch(argp, "-n") || smatch(argp, "--quiet") || smatch(argp, "-q")) { app->noout++; } else if (smatch(argp, "--nofollow")) { app->nofollow++; } else if (smatch(argp, "--password") || smatch(argp, "-p")) { if (nextArg >= argc) { return showUsage(); } else { app->password = sclone(argv[++nextArg]); } } else if (smatch(argp, "--post")) { app->method = "POST"; } else if (smatch(argp, "--printable")) { app->printable++; } else if (smatch(argp, "--protocol")) { if (nextArg >= argc) { return showUsage(); } else { app->protocol = supper(argv[++nextArg]); } } else if (smatch(argp, "--provider")) { /* Undocumented SSL provider selection */ if (nextArg >= argc) { return showUsage(); } else { app->provider = sclone(argv[++nextArg]); } ssl = 1; } else if (smatch(argp, "--put")) { app->method = "PUT"; } else if (smatch(argp, "--range")) { if (nextArg >= argc) { return showUsage(); } else { if (app->ranges == 0) { app->ranges = sfmt("bytes=%s", argv[++nextArg]); } else { app->ranges = srejoin(app->ranges, ",", argv[++nextArg], NULL); } } } else if (smatch(argp, "--retries") || smatch(argp, "-r")) { if (nextArg >= argc) { return showUsage(); } else { app->retries = atoi(argv[++nextArg]); } } else if (smatch(argp, "--self")) { /* Undocumented. Allow self-signed certs. Users should just not set --verify */ app->verifyIssuer = 0; ssl = 1; } else if (smatch(argp, "--sequence")) { app->sequence++; } else if (smatch(argp, "--showHeaders") || smatch(argp, "--show") || smatch(argp, "-s")) { app->showHeaders++; } else if (smatch(argp, "--showStatus") || smatch(argp, "--showCode")) { app->showStatus++; } else if (smatch(argp, "--single") || smatch(argp, "-s")) { app->singleStep++; } else if (smatch(argp, "--text")) { app->text++; } else if (smatch(argp, "--threads") || smatch(argp, "-t")) { if (nextArg >= argc) { return showUsage(); } else { app->loadThreads = atoi(argv[++nextArg]); } } else if (smatch(argp, "--timeout")) { if (nextArg >= argc) { return showUsage(); } else { app->timeout = atoi(argv[++nextArg]) * MPR_TICKS_PER_SEC; } } else if (smatch(argp, "--upload") || smatch(argp, "-u")) { app->upload++; } else if (smatch(argp, "--user") || smatch(argp, "--username")) { if (nextArg >= argc) { return showUsage(); } else { app->username = argv[++nextArg]; } // DEPRECATE validate. Preserve verify. } else if (smatch(argp, "--validate") || smatch(argp, "--verify")) { app->verifyPeer = 1; ssl = 1; } else if (smatch(argp, "--verbose") || smatch(argp, "-v")) { app->verbose++; } else if (smatch(argp, "--version") || smatch(argp, "-V")) { mprEprintf("%s %s\n" "Copyright (C) Embedthis Software 2003-2013\n" "Copyright (C) Michael O'Brien 2003-2013\n", BIT_TITLE, BIT_VERSION); exit(0); } else if (smatch(argp, "--workerTheads") || smatch(argp, "-w")) { if (nextArg >= argc) { return showUsage(); } else { app->workers = atoi(argv[++nextArg]); } setWorkers++; } else if (smatch(argp, "--zero")) { app->zeroOnErrors++; } else if (smatch(argp, "--")) { nextArg++; break; } else if (smatch(argp, "-")) { break; } else { return showUsage(); } } if (argc == nextArg) { return showUsage(); } app->nextArg = nextArg; argc = argc - nextArg; argv = &argv[nextArg]; app->target = argv[argc - 1]; if (--argc > 0) { /* Files present on command line */ app->files = mprCreateList(argc, MPR_LIST_STATIC_VALUES); for (i = 0; i < argc; i++) { mprAddItem(app->files, argv[i]); } } if (!setWorkers) { app->workers = app->loadThreads + 2; } if (app->method == 0) { if (app->bodyData || app->formData || app->upload) { app->method = "POST"; } else if (app->files) { app->method = "PUT"; } else { app->method = "GET"; } } #if BIT_PACK_SSL { HttpUri *uri = httpCreateUri(app->target, 0); if (uri->secure || ssl) { app->ssl = mprCreateSsl(0); if (app->provider) { mprSetSslProvider(app->ssl, app->provider); } if (app->cert) { if (!app->key) { mprError("Must specify key file"); return 0; } mprSetSslCertFile(app->ssl, app->cert); mprSetSslKeyFile(app->ssl, app->key); } if (app->ca) { mprLog(4, "Using CA: \"%s\"", app->ca); mprSetSslCaFile(app->ssl, app->ca); } if (app->verifyIssuer == -1) { app->verifyIssuer = app->verifyPeer ? 1 : 0; } mprVerifySslPeer(app->ssl, app->verifyPeer); mprVerifySslIssuer(app->ssl, app->verifyIssuer); if (app->ciphers) { mprSetSslCiphers(app->ssl, app->ciphers); } } else { mprVerifySslPeer(NULL, 0); } } #else /* Suppress comp warning */ mprNop(&ssl); #endif return 0; }