You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by al...@apache.org on 2017/02/22 20:51:56 UTC

[01/51] [partial] nifi-minifi-cpp git commit: MINIFI-183 Added civet 1.9.1 sources Added onScheduled hook Added initial two-way TLS-enabled ListenHTTP implementation

Repository: nifi-minifi-cpp
Updated Branches:
  refs/heads/master 3c874a0df -> a9485aeb0


http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_heap_hashstring.c
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_heap_hashstring.c b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_heap_hashstring.c
new file mode 100644
index 0000000..5cad795
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_heap_hashstring.c
@@ -0,0 +1,120 @@
+/*
+ *  String hash computation (interning).
+ *
+ *  String hashing is performance critical because a string hash is computed
+ *  for all new strings which are candidates to be added to the string table.
+ *  However, strings actually added to the string table go through a codepoint
+ *  length calculation which dominates performance because it goes through
+ *  every byte of the input string (but only for strings added).
+ *
+ *  The string hash algorithm should be fast, but on the other hand provide
+ *  good enough hashes to ensure both string table and object property table
+ *  hash tables work reasonably well (i.e., there aren't too many collisions
+ *  with real world inputs).  Unless the hash is cryptographic, it's always
+ *  possible to craft inputs with maximal hash collisions.
+ *
+ *  NOTE: The hash algorithms must match src/dukutil.py:duk_heap_hashstring()
+ *  for ROM string support!
+ */
+
+#include "duk_internal.h"
+
+#if defined(DUK_USE_STRHASH_DENSE)
+/* Constants for duk_hashstring(). */
+#define DUK__STRHASH_SHORTSTRING   4096L
+#define DUK__STRHASH_MEDIUMSTRING  (256L * 1024L)
+#define DUK__STRHASH_BLOCKSIZE     256L
+
+DUK_INTERNAL duk_uint32_t duk_heap_hashstring(duk_heap *heap, const duk_uint8_t *str, duk_size_t len) {
+	duk_uint32_t hash;
+
+	/* Use Murmurhash2 directly for short strings, and use "block skipping"
+	 * for long strings: hash an initial part and then sample the rest of
+	 * the string with reasonably sized chunks.  An initial offset for the
+	 * sampling is computed based on a hash of the initial part of the string;
+	 * this is done to (usually) avoid the case where all long strings have
+	 * certain offset ranges which are never sampled.
+	 *
+	 * Skip should depend on length and bound the total time to roughly
+	 * logarithmic.  With current values:
+	 *
+	 *   1M string => 256 * 241 = 61696 bytes (0.06M) of hashing
+	 *   1G string => 256 * 16321 = 4178176 bytes (3.98M) of hashing
+	 *
+	 * XXX: It would be better to compute the skip offset more "smoothly"
+	 * instead of having a few boundary values.
+	 */
+
+	/* note: mixing len into seed improves hashing when skipping */
+	duk_uint32_t str_seed = heap->hash_seed ^ ((duk_uint32_t) len);
+
+	if (len <= DUK__STRHASH_SHORTSTRING) {
+		hash = duk_util_hashbytes(str, len, str_seed);
+	} else {
+		duk_size_t off;
+		duk_size_t skip;
+
+		if (len <= DUK__STRHASH_MEDIUMSTRING) {
+			skip = (duk_size_t) (16 * DUK__STRHASH_BLOCKSIZE + DUK__STRHASH_BLOCKSIZE);
+		} else {
+			skip = (duk_size_t) (256 * DUK__STRHASH_BLOCKSIZE + DUK__STRHASH_BLOCKSIZE);
+		}
+
+		hash = duk_util_hashbytes(str, (duk_size_t) DUK__STRHASH_SHORTSTRING, str_seed);
+		off = DUK__STRHASH_SHORTSTRING + (skip * (hash % 256)) / 256;
+
+		/* XXX: inefficient loop */
+		while (off < len) {
+			duk_size_t left = len - off;
+			duk_size_t now = (duk_size_t) (left > DUK__STRHASH_BLOCKSIZE ? DUK__STRHASH_BLOCKSIZE : left);
+			hash ^= duk_util_hashbytes(str + off, now, str_seed);
+			off += skip;
+		}
+	}
+
+#if defined(DUK_USE_STRHASH16)
+	/* Truncate to 16 bits here, so that a computed hash can be compared
+	 * against a hash stored in a 16-bit field.
+	 */
+	hash &= 0x0000ffffUL;
+#endif
+	return hash;
+}
+
+#undef DUK__STRHASH_SHORTSTRING
+#undef DUK__STRHASH_MEDIUMSTRING
+#undef DUK__STRHASH_BLOCKSIZE
+#else  /* DUK_USE_STRHASH_DENSE */
+DUK_INTERNAL duk_uint32_t duk_heap_hashstring(duk_heap *heap, const duk_uint8_t *str, duk_size_t len) {
+	duk_uint32_t hash;
+	duk_size_t step;
+	duk_size_t off;
+
+	/* Slightly modified "Bernstein hash" from:
+	 *
+	 *     http://eternallyconfuzzled.com/tuts/algorithms/jsw_tut_hashing.aspx
+	 *
+	 * Modifications: string skipping and reverse direction similar to
+	 * Lua 5.1.5, and different hash initializer.
+	 *
+	 * The reverse direction ensures last byte it always included in the
+	 * hash which is a good default as changing parts of the string are
+	 * more often in the suffix than in the prefix.
+	 */
+
+	hash = heap->hash_seed ^ ((duk_uint32_t) len);  /* Bernstein hash init value is normally 5381 */
+	step = (len >> DUK_USE_STRHASH_SKIP_SHIFT) + 1;
+	for (off = len; off >= step; off -= step) {
+		DUK_ASSERT(off >= 1);  /* off >= step, and step >= 1 */
+		hash = (hash * 33) + str[off - 1];
+	}
+
+#if defined(DUK_USE_STRHASH16)
+	/* Truncate to 16 bits here, so that a computed hash can be compared
+	 * against a hash stored in a 16-bit field.
+	 */
+	hash &= 0x0000ffffUL;
+#endif
+	return hash;
+}
+#endif  /* DUK_USE_STRHASH_DENSE */


[46/51] [partial] nifi-minifi-cpp git commit: MINIFI-183 Added civet 1.9.1 sources Added onScheduled hook Added initial two-way TLS-enabled ListenHTTP implementation

Posted by al...@apache.org.
http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/docs/Building.md
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/docs/Building.md b/thirdparty/civetweb-1.9.1/docs/Building.md
new file mode 100644
index 0000000..9668f61
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/docs/Building.md
@@ -0,0 +1,191 @@
+Building CivetWeb
+=========
+
+This guide covers the build instructions for the stand-alone web server.
+See [Embedding.md](https://github.com/civetweb/civetweb/blob/master/docs/Embedding.md) for information on extending an existing C or C++ application. A brief overview of the source code files can be found in [Embedding.md](https://github.com/civetweb/civetweb/blob/master/docs/Embedding.md) as well.
+
+#### Where to get the source code?
+
+The latest version can be found at
+https://github.com/civetweb/civetweb
+
+Released versions can be found at
+https://github.com/civetweb/civetweb/releases
+
+
+Building for Windows
+---------
+
+#### Using Visual Studio
+
+Open the *VS/civetweb.sln* in Visual Studio.
+To include SSL support, you may have to add an extra library for the cryptography support. You might wish to use yaSSL.  However, it is GPL licensed or uses a commercial license. See [yaSSL.md](https://github.com/civetweb/civetweb/blob/master/docs/yaSSL.md) for more information.
+Alternatively, you might wish to use OpenSSL. See [OpenSSL.md](https://github.com/civetweb/civetweb/blob/master/docs/OpenSSL.md) for more information.
+
+#### Using MinGW-w64 or TDM-GCC
+In the start menu locate and run the "Run terminal" batch file. For TDM-GCC this is named "MinGW Command Prompt".
+Navigate to the civetweb sources directory and run:
+```
+mingw32-make CC=gcc
+```
+
+#### Using Qt Creator
+Open the Qt Designer project in the Qt folder
+
+#### Using CMake
+Except for the components in the `third_party` folder (e.g., Lua and Duktape), CivetWeb can also be built with CMake.
+CMake can be used for all supported operating systems.
+
+
+Building for Linux, BSD, and OSX
+---------
+
+## Using Make
+
+```
+make help
+```
+Get a list of all supported make option
+
+```
+make build
+```
+compile the code
+
+```
+make install
+```
+Install on the system, Linux only.
+
+```
+make lib WITH_CPP=1 WITH_IPV6=1
+make clean slib WITH_CPP=1 WITH_LUA=1 WITH_WEBSOCKET=1
+```
+Build the static and shared libraries.
+The *WITH_CPP* make option is to include the CivetServer class.
+The additional make options configure the library just as it would the application.
+
+The *slib* option should be done on a separate clean build as position
+independent code (PIC) is required for it.  Trying to run it after
+building the static library or the server will result in a link error.
+
+```
+make clean
+```
+Clean up files generated during the build
+
+## Setting build options
+
+Make options can be set on the command line with the make command like so.
+```
+make build WITH_LUA=1
+```
+
+
+| Make Options              | Description                              |
+| ------------------------- | ---------------------------------------- |
+| WITH_LUA=1                | build with Lua support                   |
+| WITH_DEBUG=1              | build with GDB debug support             |
+| WITH_IPV6=1               | with IPV6 support                        |
+| WITH_WEBSOCKET=1          | build with web socket support            |
+| WITH_CPP=1                | build libraries with c++ classes         |
+| CONFIG_FILE=file          | use 'file' as the config file            |
+| CONFIG_FILE2=file         | use 'file' as the backup config file     |
+| HTMLDIR=/path             | place to install initial web pages       |
+| DOCUMENT_ROOT=/path       | HTMLDIR override, config option, install |
+|                           | nothing is installed here.               |
+| PORTS=8080                | listening ports override when installing |
+| SSL_LIB=libssl.so.0       | use versioned SSL library                |
+| CRYPTO_LIB=libcrypto.so.0 | system versioned CRYPTO library          |
+| PREFIX=/usr/local         | sets the install directory               |
+| COPT='-DNO_SSL'           | method to insert compile flags           |
+
+Note that the WITH_* options used for *make* are not identical to the
+preprocessor defines in the source code - usually USE_* is used there.
+
+## Setting compile flags
+
+Compile flags can be set using the *COPT* make option like so.
+```
+make build COPT="-DNDEBUG -DNO_CGI"
+```
+
+| Compile Flags             | Description                          |
+| ------------------------- | ------------------------------------ |
+| NDEBUG                    | strip off all debug code             |
+| DEBUG                     | build debug version (very noisy)     |
+| NO_CGI                    | disable CGI support                  |
+| NO_CACHING                | disable caching functionality        |
+| NO_SSL                    | disable SSL functionality            |
+| NO_SSL_DL                 | link against system libssl library   |
+| NO_FILES                  | do not serve files from a directory  |
+| SQLITE_DISABLE_LFS        | disables large files (Lua only)      |
+| SSL_ALREADY_INITIALIZED   | do not initialize libcrypto          |
+
+## Cross Compiling
+
+Take total control with *CC*, *COPT* and *TARGET_OS* as make options.
+TARGET_OS is used to determine some compile details as will as code function.
+TARGET_OS values should be be one found in *resources/Makefile.in-os*.
+
+```
+make CC=arm-none-linux-gnueabi-gcc COPT="-march=armv7-a  -mfpu=vfp -mfloat-abi=softfp" TARGET_OS=FROG
+```
+
+## Cocoa DMG Packaging (OSX Only)
+
+Use the alternate *Makefile.osx* to do the build.  The entire build has
+to be done using *Makefile.osx* because additional compile and link options
+are required.  This Makefile has all the same options as the other one plus
+one additional *package* rule.
+
+```
+make -f Makefile.osx package
+```
+
+Building with Buildroot
+---------
+
+[Buildroot](http://buildroot.uclibc.org/) is a tool for creating cross compiled file systems.  Including Civetweb in buildroot is fairly easy.  There is even support for various build options.
+
+1. First, check if it already there.
+  - In buildroot, make menuconfig
+     - Package Selection for the target --->
+     - Networking applications  --->
+     - civetweb
+2. If not there, just add it
+  - copy *Config.in* and *civetweb.mk* from Civetweb's *contrib/buildroot/* to Buildroot's *package/civetweb/* directory.
+  - In Buildroot's *package/Config.in, insert the following line in were you will know how to find it in the menu.
+    > ``` source "package/civetweb/Config.in" ```
+
+
+Building on Android
+---------
+
+This is a small guide to help you run civetweb on Android. Currently it is
+tested on the HTC Wildfire. If you have managed to run it on other devices
+as well, please comment or drop an email in the mailing list.
+Note: You do not need root access to run civetweb on Android.
+
+- Download the source from the Downloads page.
+- Download the Android NDK from [http://developer.android.com/tools/sdk/ndk/index.html](http://developer.android.com/tools/sdk/ndk/index.html)
+- Run `/path-to-ndk/ndk-build -C /path-to-civetweb/resources`
+  That should generate civetweb/lib/armeabi/civetweb
+- Using the adb tool (you need to have Android SDK installed for that),
+  push the generated civetweb binary to `/data/local` folder on device.
+- From adb shell, navigate to `/data/local` and execute `./civetweb`.
+- To test if the server is running fine, visit your web-browser and
+  navigate to `http://127.0.0.1:8080` You should see the `Index of /` page.
+
+![screenshot](https://a248.e.akamai.net/camo.github.com/b88428bf009a2b6141000937ab684e04cc8586af/687474703a2f2f692e696d6775722e636f6d2f62676f6b702e706e67)
+
+
+Notes:
+
+- `jni` stands for Java Native Interface. Read up on Android NDK if you want
+  to know how to interact with the native C functions of civetweb in Android
+  Java applications.
+- TODO: A Java application that interacts with the native binary or a
+  shared library.
+
+

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/docs/Contribution.md
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/docs/Contribution.md b/thirdparty/civetweb-1.9.1/docs/Contribution.md
new file mode 100644
index 0000000..de3ff43
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/docs/Contribution.md
@@ -0,0 +1,10 @@
+Contributing to CivetWeb
+====
+
+Contributions to CivetWeb are welcome, provided all contributions carry the MIT license.
+
+- Please first create an issue on GitHub or create a thread on the CivetWeb discussion group.
+- If possible, create a pull request on GitHub. Please take care your modifications pass the continuous integration checks. These checks are performed automatically when you create a pull request, but it may take some hours until all tests are completed.
+- Alternatively, you can post a patch. However, pull requests are preferred.
+- Contributor names are listed in CREDITS.md, unless you explicitly state you don't want your name to be listed there.
+

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/docs/Embedding.md
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/docs/Embedding.md b/thirdparty/civetweb-1.9.1/docs/Embedding.md
new file mode 100644
index 0000000..3f2a2db
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/docs/Embedding.md
@@ -0,0 +1,200 @@
+Embedding CivetWeb
+=========
+
+CivetWeb is primarily designed so applications can easily add HTTP and HTTPS server as well as WebSocket functionality.  For example, an application server could use CivetWeb to enable a web service interface for automation or remote control.
+
+However, it can also be used as a stand-alone executable. It can deliver static files and offers built-in server side Lua, JavaScript and CGI support. Some instructions how to build the stand-alone server can be found in [Building.md](https://github.com/civetweb/civetweb/blob/master/docs/Building.md).
+
+Files
+------
+
+There is just a small set of files to compile in to the application,
+but if a library is desired, see [Building.md](https://github.com/CivetWeb/CivetWeb/blob/master/docs/Building.md)
+
+#### Regarding the INL file extension
+The *INL* file extension represents code that is statically included inline in a source file.  Slightly different from C++ where it means "inline" code which is technically not the same as static code. CivetWeb overloads this extension for the sake of clarity as opposed to having .c extensions on files that should not be directly compiled.
+
+#### HTTP Server Source Files
+
+These files constitute the CivetWeb library.  They do not contain a `main` function,
+but all functions required to run a HTTP server.
+
+  - HTTP server API
+    - include/civetweb.h
+  - C implementation
+    - src/civetweb.c
+    - src/md5.inl (MD5 calculation)
+    - src/handle_form.inl (HTML form handling functions)
+  - Optional: C++ wrapper
+    - include/CivetServer.h (C++ interface)
+    - src/CivetServer.cpp (C++ wrapper implementation)
+  - Optional: Third party components
+    - src/third_party/* (third party components, mainly used for the standalone server)
+    - src/mod_*.inl (modules to access third party components from civetweb)
+
+Note: The C++ wrapper uses the official C interface (civetweb.h) and does not add new features to the server. Some features available in the C interface might be missing in the C++ interface.
+
+#### Additional Source Files for Executables
+
+These files can be used to build a server executable. They contain a `main` function
+starting the HTTP server.
+
+  - Stand-alone C Server
+      - src/main.c
+  - Reference embedded C Server
+      - examples/embedded_c/embedded_c.c
+  - Reference embedded C++ Server
+      - examples/embedded_cpp/embedded_cpp.cpp
+
+Note: The "embedded" example is actively maintained, updated, extended and tested. Other examples in the examples/ folder might be outdated and remain there for reference.
+
+Quick Start
+------
+
+By default, the server will automatically serve up files like a normal HTTP server.  An embedded server is most likely going to overload this functionality.
+
+### C
+  - Include the C interface ```civetweb.h```.
+  - Use `mg_start()` to start the server.
+      - Use *options* to select the port and document root among other things.
+      - Use *callbacks* to add your own hooks.
+  - Use `mg_set_request_handler()` to easily add your own request handlers.
+  - Use `mg_stop()` to stop the server.
+
+### C++
+  - Note that CivetWeb is Clean C, and C++ interface ```CivetServer.h``` is only a wrapper layer around the C interface.
+    Not all CivetWeb features available in C are also available in C++.
+  - Create CivetHandlers for each URI.
+  - Register the handlers with `CivetServer::addHandler()`
+  - `CivetServer` starts on contruction and stops on destruction.
+  - Use contructor *options* to select the port and document root among other things.
+  - Use constructor *callbacks* to add your own hooks.
+
+Lua Support
+------
+
+Lua is a server side include functionality.  Files ending in .lua will be processed with Lua.
+
+##### Add the following CFLAGS
+
+  - -DLUA_COMPAT_ALL
+  - -DUSE_LUA
+  - -DUSE_LUA_SQLITE3
+  - -DUSE_LUA_FILE_SYSTEM
+
+##### Add the following sources
+
+  - src/mod_lua.inl
+  - src/third_party/lua-5.2.4/src
+     + lapi.c
+     + lauxlib.c
+     + lbaselib.c
+     + lbitlib.c
+     + lcode.c
+     + lcorolib.c
+     + lctype.c
+     + ldblib.c
+     + ldebug.c
+     + ldo.c
+     + ldump.c
+     + lfunc.c
+     + lgc.c
+     + linit.c
+     + liolib.c
+     + llex.c
+     + lmathlib.c
+     + lmem.c
+     + loadlib.c
+     + lobject.c
+     + lopcodes.c
+     + loslib.c
+     + lparser.c
+     + lstate.c
+     + lstring.c
+     + lstrlib.c
+     + ltable.c
+     + ltablib.c
+     + ltm.c
+     + lundump.c
+     + lvm.c
+     + lzio.c
+  - src/third_party/sqlite3.c
+  - src/third_party/sqlite3.h
+  - src/third_party/lsqlite3.c
+  - src/third_party/lfs.c
+  - src/third_party/lfs.h
+
+This build is valid for Lua version Lua 5.2. It is also possible to build with Lua 5.1 (including LuaJIT) or Lua 5.3.
+
+
+JavaScript Support
+------
+
+CivetWeb can be built with server side JavaScript support by including the Duktape library.
+
+
+CivetWeb internals
+------
+
+CivetWeb is multithreaded web server. `mg_start()` function allocates
+web server context (`struct mg_context`), which holds all information
+about web server instance:
+
+- configuration options. Note that CivetWeb makes internal copies of
+  passed options.
+- SSL context, if any
+- user-defined callbacks
+- opened listening sockets
+- a queue for accepted sockets
+- mutexes and condition variables for inter-thread synchronization
+
+When `mg_start()` returns, all initialization is guaranteed to be complete
+(e.g. listening ports are opened, SSL is initialized, etc). `mg_start()` starts
+some threads: a master thread, that accepts new connections, and several
+worker threads, that process accepted connections. The number of worker threads
+is configurable via `num_threads` configuration option. That number puts a
+limit on number of simultaneous requests that can be handled by CivetWeb.
+If you embed CivetWeb into a program that uses SSL outside CivetWeb as well,
+you may need to initialize SSL before calling `mg_start()`, and set the pre-
+processor define SSL_ALREADY_INITIALIZED. This is not required if SSL is used
+only within CivetWeb.
+
+When master thread accepts new a connection, a new accepted socket (described
+by `struct socket`) it placed into the accepted sockets queue,
+which has size of `MGSQLEN` (default 20).
+Any idle worker thread can grab accepted sockets from that queue.
+If all worker threads are busy, master thread can accept and queue up to
+20 more TCP connections, filling up the queue.
+In the attempt to queue even more accepted connection, the master thread blocks
+until there is space in the queue. When the master thread is blocked on a
+full queue, the operating system can also queue incoming connection.
+The number is limited by the `listen()` call parameter,
+which is `SOMAXCONN` and depends on the platform.
+
+Worker threads are running in an infinite loop, which in a simplified form
+looks something like this:
+
+    static void *worker_thread() {
+      while (consume_socket()) {
+        process_new_connection();
+      }
+    }
+
+Function `consume_socket()` gets a new accepted socket from the CivetWeb socket
+queue, atomically removing it from the queue. If the queue is empty,
+`consume_socket()` blocks and waits until a new socket is placed in the queue
+by the master thread.
+
+`process_new_connection()` actually processes the
+connection, i.e. reads the request, parses it, and performs appropriate action
+depending on the parsed request.
+
+Master thread uses `poll()` and `accept()` to accept new connections on
+listening sockets. `poll()` is used to avoid `FD_SETSIZE` limitation of
+`select()`. Since there are only a few listening sockets, there is no reason
+to use hi-performance alternatives like `epoll()` or `kqueue()`. Worker
+threads use blocking IO on accepted sockets for reading and writing data.
+All accepted sockets have `SO_RCVTIMEO` and `SO_SNDTIMEO` socket options set
+(controlled by the `request_timeout_ms` CivetWeb option, 30 seconds default)
+which specifies a read/write timeout on client connections.
+

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/docs/Installing.md
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/docs/Installing.md b/thirdparty/civetweb-1.9.1/docs/Installing.md
new file mode 100644
index 0000000..d5e87cc
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/docs/Installing.md
@@ -0,0 +1,36 @@
+Civetweb Install Guide
+====
+
+This guide covers the distributions for CivetWeb.  The latest source code is available at [https://github.com/civetweb/civetweb](https://github.com/civetweb/civetweb).
+
+Windows
+---
+
+This pre-built version comes pre-built wit Lua support. Libraries for SSL support are not included due to licensing restrictions;
+however, users may add an SSL library themselves.
+Instructions for adding SSL support can be found in [https://github.com/civetweb/civetweb/tree/master/docs](https://github.com/civetweb/civetweb/tree/master/docs)
+
+1a. 32 Bit: Install the [Visual C++ Redistributable for Visual Studio 2010](http://www.microsoft.com/en-us/download/details.aspx?id=8328)
+1b. 64 Bit: Install the [Visual C++ Redistributable for Visual Studio 2013](http://www.microsoft.com/en-us/download/details.aspx?id=40784)
+2. Download latest *civetweb-win.zip* from [SourceForge](https://sourceforge.net/projects/civetweb/files/)
+3. When started, Civetweb puts itself into the tray.
+
+OS X
+---
+
+This pre-built version comes with Lua, IPV6 and SSL support.
+
+1. Download the latest *Civetweb.dmg* from [SourceForge](https://sourceforge.net/projects/civetweb/files/)
+2. Click on the it and look for the attachment in the finder.
+4. Drag Civetweb to the Applications folder.
+5. When started, Civetweb puts itself into top menu.
+
+Linux
+---
+
+1. Download the latest *civetweb.tar.gz* from [SourceForge](https://sourceforge.net/projects/civetweb/files/)
+2. Open archive and change to the new directory.
+3. make help
+4. make
+5. make install
+6. Run the program ```/usr/local/bin/civetweb```, it will use the configuration file */usr/local/etc/civetweb.conf*.

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/docs/OpenSSL.md
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/docs/OpenSSL.md b/thirdparty/civetweb-1.9.1/docs/OpenSSL.md
new file mode 100644
index 0000000..1f01cca
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/docs/OpenSSL.md
@@ -0,0 +1,153 @@
+Adding OpenSSL Support
+=====
+
+Civetweb supports *HTTPS* connections using the OpenSSL transport layer
+security (TLS) library. OpenSSL is a free, open source library (see
+http://www.openssl.org/).
+
+
+Getting Started
+----
+
+- Install OpenSSL on your system. There are OpenSSL install packages for all
+  major Linux distributions as well as a setup for Windows.
+- The default build configuration of the civetweb web server will load the
+  required OpenSSL libraries, if a HTTPS certificate has been configured.
+
+
+Civetweb Configuration
+----
+
+The configuration file must contain an https port, identified by a letter 's'
+attached to the port number.
+To serve http and https from their standard ports use the following line in
+the configuration file 'civetweb.conf':
+<pre>
+  listening_ports 80, 443s
+</pre>
+To serve only https use:
+<pre>
+  listening_ports 443s
+</pre>
+
+Furthermore the SSL certificate file must be set:
+<pre>
+  ssl_certificate d:\civetweb\certificate\server.pem
+</pre>
+
+
+Creating a self signed certificate
+----
+
+OpenSSL provides a command line interface, that can be used to create the
+certificate file required by civetweb (server.pem).
+
+One can use the following steps in Windows (in Linux replace "copy" by "cp"
+and "type" by "cat"):
+
+<pre>
+  openssl genrsa -des3 -out server.key 1024
+
+  openssl req -new -key server.key -out server.csr
+
+  copy server.key server.key.orig
+
+  openssl rsa -in server.key.orig -out server.key
+
+  openssl x509 -req -days 3650 -in server.csr -signkey server.key -out server.crt
+
+  copy server.crt server.pem
+
+  type server.key >> server.pem
+</pre>
+
+The server.pem file created must contain a 'CERTIFICATE' section as well as a
+'RSA PRIVATE KEY' section. It should look like this (x represents BASE64
+encoded data):
+
+<pre>
+-----BEGIN CERTIFICATE-----
+xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
+xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
+xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
+xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
+xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
+xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
+xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
+xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
+xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
+xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
+xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
+xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
+xxxxxxxxxxxxxxxxxxxxxxxxxxxx
+-----END CERTIFICATE-----
+-----BEGIN RSA PRIVATE KEY-----
+xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
+xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
+xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
+xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
+xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
+xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
+xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
+xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
+xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
+xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
+xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
+xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
+xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
+-----END RSA PRIVATE KEY-----
+</pre>
+
+
+Including a certificate from a certificate authority
+----
+
+CivetWeb requires one certificate file in PEM format.
+If you got multiple files from your certificate authority,
+you need to copy their content together into one file.
+Make sure the file has one section BEGIN RSA PRIVATE KEY /
+END RSA PRIVATE KEY, and at least one section
+BEGIN CERTIFICATE / END CERTIFICATE.
+In case you received a file with a section
+BEGIN PRIVATE KEY / END PRIVATE KEY,
+you may get a suitable file by adding the letters RSA manually.
+
+Set the "ssl_certificate" configuration parameter to the
+file name (including path) of the resulting *.pem file.
+
+The file must look like the file in the section
+"Creating a self signed certificate", but it will have several
+BEGIN CERTIFICATE / END CERTIFICATE sections.
+
+
+Common Problems
+----
+
+In case the OpenSSL configuration is not set up correctly, the server will not
+start. Configure an error log file in 'civetweb.conf' to get more information:
+<pre>
+  error_log_file error.log
+</pre>
+
+Check the content of 'error.log':
+
+<pre>
+load_dll: cannot load libeay32.*/libcrypto.*/ssleay32.*/libssl.*
+</pre>
+This error message means, the SSL library has not been installed (correctly).
+For Windows you might use the pre-built binaries. A link is available at the
+OpenSSL project home page (http://www.openssl.org/related/binaries.html).
+Choose the windows system folder as installation directory - this is the
+default location.
+
+<pre>
+set_ssl_option: cannot open server.pem: error:PEM routines:*:PEM_read_bio:no start line
+set_ssl_option: cannot open server.pem: error:PEM routines:*:PEM_read_bio:bad end line
+</pre>
+These error messages indicate, that the format of the ssl_certificate file does
+not match the expectations of the SSL library. The PEM file must contain both,
+a 'CERTIFICATE' and a 'RSA PRIVATE KEY' section. It should be a strict ASCII
+file without byte-order marks.
+The instructions above may be used to create a valid ssl_certificate file.
+
+

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/docs/README.md
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/docs/README.md b/thirdparty/civetweb-1.9.1/docs/README.md
new file mode 100644
index 0000000..8fcf2c4
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/docs/README.md
@@ -0,0 +1,40 @@
+![CivetWeb](https://raw.github.com/civetweb/civetweb/master/resources/civetweb_64x64.png "CivetWeb") CivetWeb
+=======
+
+CivetWeb is an easy to use, powerful, C/C++ embeddable web server with optional CGI, SSL and Lua support.
+
+CivetWeb can be used by developers as a library, to add web server functionality to an existing application.
+CivetWeb uses an [MIT license](https://github.com/civetweb/civetweb/blob/master/LICENSE.md).
+
+It can also be used by end users as a stand-alone web server. It is available as single executable, no installation is required.
+
+The current stable version is 1.9.1 - [release notes](https://github.com/civetweb/civetweb/blob/master/RELEASE_NOTES.md)
+
+
+End users can download CivetWeb at SourceForge
+[https://sourceforge.net/projects/civetweb/](https://sourceforge.net/projects/civetweb/)
+
+Developers can contribute to CivetWeb via GitHub
+[https://github.com/civetweb/civetweb](https://github.com/civetweb/civetweb)
+
+Trouble tickets should be filed on GitHub
+[https://github.com/civetweb/civetweb/issues](https://github.com/civetweb/civetweb/issues)
+
+Discussion/support group and announcements are at Google Groups
+[https://groups.google.com/d/forum/civetweb](https://groups.google.com/d/forum/civetweb)
+
+Source releases can be found on GitHub
+[https://github.com/civetweb/civetweb/releases](https://github.com/civetweb/civetweb/releases)
+
+
+Documentation
+---------------
+
+- [Installing.md](Installing.md) - Install Guide (for end users using pre-built binaries)
+- [UserManual.md](UserManual.md) - End User Guide
+- [Building.md](Building.md) - Building the Server (quick start guide)
+- [Embedding.md](Embedding.md) - Embedding (how to add HTTP support to an existing application)
+- [OpenSSL.md](OpenSSL.md) - Adding HTTPS (SSL/TLS) support using OpenSSL.
+- [API documentation](api) - Additional documentation on the civetweb application programming interface ([civetweb.h](https://github.com/civetweb/civetweb/blob/master/include/civetweb.h)).
+
+[Authors](https://github.com/civetweb/civetweb/blob/master/CREDITS.md)

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/docs/UserManual.md
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/docs/UserManual.md b/thirdparty/civetweb-1.9.1/docs/UserManual.md
new file mode 100644
index 0000000..d9692fc
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/docs/UserManual.md
@@ -0,0 +1,708 @@
+
+Overview
+=====
+
+Civetweb is small and easy to use web server.
+It may be embedded into C/C++ host applications or used as a stand-alone
+server. See `Embedding.md` for information on embedding civetweb into
+host applications.
+
+The stand-alone server is self-contained, and does not require any external
+software to run. Some Windows users may need to install the
+[Visual C++ Redistributable](http://www.microsoft.com/en-us/download/details.aspx?id=30679).
+
+Installation
+----
+
+On Windows, UNIX and Mac, the civetweb stand-alone executable may be started
+from the command line.
+Running `civetweb` in a terminal, optionally followed by configuration parameters
+(`civetweb [OPTIONS]`) or a configuration file name (`civetweb [config_file_name]`),
+starts the web server.
+
+For UNIX and Mac, civetweb does not detach from the terminal.
+Pressing `Ctrl-C` keys will stop the server.
+
+On Windows, civetweb iconifies itself to the system tray icon when started.
+Right-click on the icon pops up a menu, where it is possible to stop
+civetweb, or configure it, or install it as Windows service.
+
+When started without options, the server exposes the local directory at
+[http](http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol) port 8080.
+Thus, the easiest way to share a folder on Windows is to copy `civetweb.exe`
+to this folder, double-click the exe, and launch a browser at
+[http://localhost:8080](http://localhost:8080). Note that 'localhost' should
+be changed to a machine's name if a folder is accessed from other computer.
+
+When started, civetweb first searches for the configuration file.
+If configuration file is specified explicitly in the command line, i.e.
+`civetweb path_to_config_file`, then specified configuration file is used.
+Otherwise, civetweb would search for file `civetweb.conf` in the same directory
+the executable is located, and use it. This configuration file is optional.
+
+The configuration file is a sequence of lines, each line containing one
+command line argument name and the corresponding value.
+Empty lines, and lines beginning with `#`, are ignored.
+Here is the example of `civetweb.conf` file:
+
+    document_root c:\www
+    listening_ports 80,443s
+    ssl_certificate c:\civetweb\ssl_cert.pem
+
+When a configuration file is used, additional command line arguments may
+override the configuration file settings.
+All command line arguments must start with `-`.
+
+For example: The above `civetweb.conf` file is used, and civetweb started as
+`civetweb -document_root D:\web`. Then the `D:\web` directory will be served
+as document root, because command line options take priority over the
+configuration file. The configuration options section below provides a good
+overview of the Civetweb features.
+
+Note that configuration options on the command line must start with `-`,
+but their names are the same as in the config file. All option names are
+listed in the next section. Thus, the following two setups are equivalent:
+
+    # Using command line arguments
+    $ civetweb -listening_ports 1234 -document_root /var/www
+
+    # Using config file
+    $ cat civetweb.conf
+    listening_ports 1234
+    document_root /var/www
+    $ civetweb
+
+Civetweb can also be used to modify `.htpasswd` passwords files:
+
+    civetweb -A <htpasswd_file> <realm> <user> <passwd>
+
+Unlike other web servers, civetweb does not require CGI scripts to be located
+in a special directory. CGI scripts can be anywhere. CGI (and SSI) files are
+recognized by the file name pattern. Civetweb uses shell-like glob
+patterns. Pattern match starts at the beginning of the string, so essentially
+patterns are prefix patterns. Syntax is as follows:
+
+     **      Matches everything
+     *       Matches everything but slash character, '/'
+     ?       Matches any character
+     $       Matches the end of the string
+     |       Matches if pattern on the left side or the right side matches.
+
+All other characters in the pattern match themselves. Examples:
+
+    **.cgi$      Any string that ends with .cgi
+    /foo         Any string that begins with /foo
+    **a$|**b$    Any string that ends with a or b
+
+# Configuration Options
+
+Below is a list of configuration options understood by Civetweb.
+Every option is followed by it's default value. If a default value is not
+present, then the default is empty.
+
+### cgi\_pattern `**.cgi$|**.pl$|**.php$`
+All files that match `cgi_pattern` are treated as CGI files. Default pattern
+allows CGI files be anywhere. To restrict CGIs to a certain directory,
+use `/path/to/cgi-bin/**.cgi` as pattern. Note that the full file path is
+matched against the pattern, not the URI.
+
+### cgi\_environment
+Extra environment variables to be passed to the CGI script in
+addition to standard ones. The list must be comma-separated list
+of name=value pairs, like this: `VARIABLE1=VALUE1,VARIABLE2=VALUE2`.
+
+### put\_delete\_auth\_file
+Passwords file for PUT and DELETE requests. Without password file, it will not
+be possible to, PUT new files to the server or DELETE existing ones. PUT and
+DELETE requests might still be handled by Lua scripts and CGI paged.
+
+### cgi\_interpreter
+Path to an executable to use as CGI interpreter for __all__ CGI scripts
+regardless of the script file extension. If this option is not set (which is
+the default), Civetweb looks at first line of a CGI script,
+[shebang line](http://en.wikipedia.org/wiki/Shebang_(Unix\)), for an
+interpreter (not only on Linux and Mac but also for Windows).
+
+For example, if both PHP and Perl CGIs are used, then
+`#!/path/to/php-cgi.exe` and `#!/path/to/perl.exe` must be first lines of the
+respective CGI scripts. Note that paths should be either full file paths,
+or file paths relative to the current working directory of the civetweb
+server. If civetweb is started by mouse double-click on Windows, the current
+working directory is the directory where the civetweb executable is located.
+
+If all CGIs use the same interpreter, for example they are all PHP, it is
+more efficient to set `cgi_interpreter` to the path to `php-cgi.exe`.
+The  shebang line in the CGI scripts can be omitted in this case.
+Note that PHP scripts must use `php-cgi.exe` as executable, not `php.exe`.
+
+### protect\_uri
+Comma separated list of URI=PATH pairs, specifying that given
+URIs must be protected with password files specified by PATH.
+All Paths must be full file paths.
+
+### authentication\_domain `mydomain.com`
+Authorization realm used for HTTP digest authentication. This domain is
+used in the encoding of the `.htpasswd` authorization files as well.
+Changing the domain retroactively will render the existing passwords useless.
+
+### ssi\_pattern `**.shtml$|**.shtm$`
+All files that match `ssi_pattern` are treated as Server Side Includes (SSI).
+
+SSI is a simple interpreted server-side scripting language which is most
+commonly used to include the contents of another file into a web page.
+It can be useful when it is desirable to include a common piece
+of code throughout a website, for example, headers and footers.
+
+In order for a webpage to recognize an SSI-enabled HTML file, the filename
+should end with a special extension, by default the extension should be
+either `.shtml` or `.shtm`. These extentions may be changed using the
+`ssi_pattern` option.
+
+Unknown SSI directives are silently ignored by civetweb. Currently, two SSI
+directives are supported, `<!--#include ...>` and
+`<!--#exec "command">`. Note that the `<!--#include ...>` directive supports
+three path specifications:
+
+    <!--#include virtual="path">  Path is relative to web server root
+    <!--#include abspath="path">  Path is absolute or relative to
+                                  web server working dir
+    <!--#include file="path">,    Path is relative to current document
+    <!--#include "path">
+
+The `include` directive may be used to include the contents of a file or the
+result of running a CGI script. The `exec` directive is used to execute a
+command on a server, and show the output that would have been printed to
+stdout (the terminal window) otherwise. Example:
+
+    <!--#exec "ls -l" -->
+
+For more information on Server Side Includes, take a look at the Wikipedia:
+[Server Side Includes](http://en.wikipedia.org/wiki/Server_Side_Includes)
+
+### throttle
+Limit download speed for clients.  `throttle` is a comma-separated
+list of key=value pairs, where key could be:
+
+    *                   limit speed for all connections
+    x.x.x.x/mask        limit speed for specified subnet
+    uri_prefix_pattern  limit speed for given URIs
+
+The value is a floating-point number of bytes per second, optionally
+followed by a `k` or `m` character, meaning kilobytes and
+megabytes respectively. A limit of 0 means unlimited rate. The
+last matching rule wins. Examples:
+
+    *=1k,10.0.0.0/8=0   limit all accesses to 1 kilobyte per second,
+                        but give connections the from 10.0.0.0/8 subnet
+                        unlimited speed
+
+    /downloads/=5k      limit accesses to all URIs in `/downloads/` to
+                        5 kilobytes per second. All other accesses are unlimited
+
+### access\_log\_file
+Path to a file for access logs. Either full path, or relative to the current
+working directory. If absent (default), then accesses are not logged.
+
+### enable\_directory\_listing `yes`
+Enable directory listing, either `yes` or `no`.
+
+### error\_log\_file
+Path to a file for error logs. Either full path, or relative to the current
+working directory. If absent (default), then errors are not logged.
+
+### global\_auth\_file
+Path to a global passwords file, either full path or relative to the current
+working directory. If set, per-directory `.htpasswd` files are ignored,
+and all requests are authorized against that file.
+
+The file has to include the realm set through `authentication_domain` and the
+password in digest format:
+
+    user:realm:digest
+    test:test.com:ce0220efc2dd2fad6185e1f1af5a4327
+
+Password files may be generated using `civetweb -A` as explained above, or
+online tools e.g. [this generator](http://www.askapache.com/online-tools/htpasswd-generator).
+
+### index\_files `index.xhtml,index.html,index.htm,index.cgi,index.shtml,index.php`
+Comma-separated list of files to be treated as directory index files.
+If more than one matching file is present in a directory, the one listed to the left
+is used as a directory index.
+
+In case built-in Lua support has been enabled, `index.lp,index.lsp,index.lua`
+are additional default index files, ordered before `index.cgi`.
+
+### enable\_keep\_alive `no`
+Enable connection keep alive, either `yes` or `no`.
+
+Allows clients to reuse TCP connection for subsequent HTTP requests, 
+which improves performance.
+For this to work when using request handlers it is important to add the
+correct Content-Length HTTP header for each request. If this is forgotten the
+client will time out.
+
+Note: If you set keep\_alive to `yes`, you should set keep\_alive\_timeout\_ms
+to some value > 0 (e.g. 500). If you set keep\_alive to `no`, you should set
+keep\_alive\_timeout\_ms to 0. Currently, this is done as a default value,
+but this configuration is redundant. In a future version, the keep\_alive 
+configuration option might be removed and automatically set to `yes` if 
+a timeout > 0 is set.
+
+### access\_control\_list
+An Access Control List (ACL) allows restrictions to be put on the list of IP
+addresses which have access to the web server. In the case of the Civetweb
+web server, the ACL is a comma separated list of IP subnets, where each
+subnet is pre-pended by either a `-` or a `+` sign. A plus sign means allow,
+where a minus sign means deny. If a subnet mask is omitted, such as `-1.2.3.4`,
+this means to deny only that single IP address.
+
+Subnet masks may vary from 0 to 32, inclusive. The default setting is to allow
+all accesses. On each request the full list is traversed, and
+the last match wins. Examples:
+
+    -0.0.0.0/0,+192.168/16    deny all accesses, only allow 192.168/16 subnet
+
+To learn more about subnet masks, see the
+[Wikipedia page on Subnetwork](http://en.wikipedia.org/wiki/Subnetwork).
+
+### extra\_mime\_types
+Extra mime types, in tha form `extension1=type1,exten-sion2=type2,...`.
+See the [Wikipedia page on Internet media types](http://en.wikipedia.org/wiki/Internet_media_type).
+Extension must include a leading dot. Example:
+`.cpp=plain/text,.java=plain/text`
+
+### listening\_ports `8080`
+Comma-separated list of ports to listen on. If the port is SSL, a
+letter `s` must be appended, for example, `80,443s` will open
+port 80 and port 443, and connections on port 443 will be SSL-ed.
+For non-SSL ports, it is allowed to append letter `r`, meaning 'redirect'.
+Redirect ports will redirect all their traffic to the first configured
+SSL port. For example, if `listening_ports` is `80r,443s`, then all
+HTTP traffic coming at port 80 will be redirected to HTTPS port 443.
+
+It is possible to specify an IP address to bind to. In this case,
+an IP address and a colon must be pre-pended to the port number.
+For example, to bind to a loopback interface on port 80 and to
+all interfaces on HTTPS port 443, use `127.0.0.1:80,443s`.
+
+If the server is built with IPv6 support, `[::]:8080` can be used to
+listen to IPv6 connections to port 8080. IPv6 addresses of network
+interfaces can be specified as well,
+e.g. `[::1]:8080` for the IPv6 loopback interface.
+
+[::]:80 will bind to port 80 IPv6 only. In order to use port 80 for
+all interfaces, both IPv4 and IPv6, use either the configuration
+`80,[::]:80` (create one socket for IPv4 and one for IPv6 only),
+or `+80` (create one socket for both, IPv4 and IPv6). 
+The `+`-notation to use IPv4 and IPv6 will only work in no network
+interface is specified. Depending on your IPv6 network environment,
+some configurations might not work (properly), so you have to test
+to find the configuration most suitable for your needs.
+
+It is possible to use network interface addresses (e.g., `192.0.2.3:80`,
+`[2001:0db8::1234]:80`). To get a list of available network interface
+addresses, use `ipconfig` (in a `cmd` window in Windows) or `ifconfig` 
+(in a Linux shell).
+
+### document\_root `.`
+A directory to serve. By default, the current working directory is served.
+The current directory is commonly referenced as dot (`.`).
+It is recommended to use an absolute path for document\_root, in order to 
+avoid accidentally serving the wrong directory.
+
+### ssl\_certificate
+Path to the SSL certificate file. This option is only required when at least
+one of the `listening\_ports` is SSL. The file must be in PEM format,
+and it must have both, private key and certificate, see for example
+[ssl_cert.pem](https://github.com/civetweb/civetweb/blob/master/resources/ssl_cert.pem)
+A description how to create a certificate can be found in doc/OpenSSL.md
+
+### num\_threads `50`
+Number of worker threads. Civetweb handles each incoming connection in a
+separate thread. Therefore, the value of this option is effectively the number
+of concurrent HTTP connections Civetweb can handle.
+
+### run\_as\_user
+Switch to given user credentials after startup. Usually, this option is
+required when civetweb needs to bind on privileged ports on UNIX. To do
+that, civetweb needs to be started as root. From a security point of view,
+running as root is not advisable, therefore this option can be used to drop
+privileges. Example:
+
+    civetweb -listening_ports 80 -run_as_user webserver
+
+### url\_rewrite\_patterns
+Comma-separated list of URL rewrites in the form of
+`uri_pattern=file_or_directory_path`. When Civetweb receives any request,
+it constructs the file name to show by combining `document_root` and the URI.
+However, if the rewrite option is used and `uri_pattern` matches the
+requested URI, then `document_root` is ignored. Instead,
+`file_or_directory_path` is used, which should be a full path name or
+a path relative to the web server's current working directory. Note that
+`uri_pattern`, as all civetweb patterns, is a prefix pattern.
+
+This makes it possible to serve many directories outside from `document_root`,
+redirect all requests to scripts, and do other tricky things. For example,
+to redirect all accesses to `.doc` files to a special script, do:
+
+    civetweb -url_rewrite_patterns **.doc$=/path/to/cgi-bin/handle_doc.cgi
+
+Or, to imitate support for user home directories, do:
+
+    civetweb -url_rewrite_patterns /~joe/=/home/joe/,/~bill=/home/bill/
+
+### hide\_files\_patterns
+A pattern for the files to hide. Files that match the pattern will not
+show up in directory listing and return `404 Not Found` if requested. Pattern
+must be for a file name only, not including directory names. Example:
+
+    civetweb -hide_files_patterns secret.txt|*.hide
+
+### request\_timeout\_ms `30000`
+Timeout for network read and network write operations, in milliseconds.
+If a client intends to keep long-running connection, either increase this
+value or (better) use keep-alive messages.
+
+### keep\_alive\_timeout\_ms `500` or `0`
+Idle timeout between two requests in one keep-alive connection.
+If keep alive is enabled, multiple requests using the same connection 
+are possible. This reduces the overhead for opening and closing connections
+when loading several resources from one server, but it also blocks one port
+and one thread at the server during the lifetime of this connection.
+Unfortunately, browsers do not close the keep-alive connection after loading
+all resources required to show a website.
+The server closes a keep-alive connection, if there is no additional request
+from the client during this timeout.
+
+Note: if enable\_keep\_alive is set to `no` the value of 
+keep\_alive\_timeout\_ms should be set to `0`, if enable\_keep\_alive is set 
+to `yes`, the value of keep\_alive\_timeout\_ms must be >0.
+Currently keep\_alive\_timeout\_ms is ignored if enable\_keep\_alive is no,
+but future versions my drop the enable\_keep\_alive configuration value and
+automatically use keep-alive if keep\_alive\_timeout\_ms is not 0.
+
+### linger\_timeout\_ms
+Set TCP socket linger timeout before closing sockets (SO\_LINGER option).
+The configured value is a timeout in milliseconds. Setting the value to 0
+will yield in abortive close (if the socket is closed from the server side).
+Setting the value to -1 will turn off linger.
+If the value is not set (or set to -2), CivetWeb will not set the linger
+option at all.
+
+Note: For consistency with other timeouts, the value is configured in
+milliseconds. However, the TCP socket layer usually only offers a timeout in 
+seconds, so the value should be an integer multiple of 1000.
+
+### lua\_preload\_file
+This configuration option can be used to specify a Lua script file, which
+is executed before the actual web page script (Lua script, Lua server page
+or Lua websocket). It can be used to modify the Lua environment of all web
+page scripts, e.g., by loading additional libraries or defining functions
+required by all scripts.
+It may be used to achieve backward compatibility by defining obsolete
+functions as well.
+
+### lua\_script\_pattern `"**.lua$`
+A pattern for files that are interpreted as Lua scripts by the server.
+In contrast to Lua server pages, Lua scripts use plain Lua syntax.
+An example can be found in the test directory.
+
+### lua\_server\_page\_pattern `**.lp$|**.lsp$`
+Files matching this pattern are treated as Lua server pages.
+In contrast to Lua scripts, the content of a Lua server pages is delivered
+directly to the client. Lua script parts are delimited from the standard
+content by including them between <? and ?> tags.
+An example can be found in the test directory.
+
+### lua\_background\_script
+Experimental feature, and subject to change.
+Run a Lua script in the background, independent from any connection.
+The script is started before network access to the server is available.
+It can be used to prepare the document root (e.g., update files, compress
+files, ...), check for external resources, remove old log files, etc.
+
+The Lua state remains open until the server is stopped.
+In the future, some callback functions will be available to notify the
+script on changes of the server state.
+
+
+### websocket\_root
+In case civetweb is built with Lua and websocket support, Lua scripts may
+be used for websockets as well. Since websockets use a different URL scheme
+(ws, wss) than other http pages (http, https), the Lua scripts used for
+websockets may also be served from a different directory. By default,
+the document_root is used as websocket_root as well.
+
+### access\_control\_allow\_origin
+Access-Control-Allow-Origin header field, used for cross-origin resource
+sharing (CORS).
+See the [Wikipedia page on CORS](http://en.wikipedia.org/wiki/Cross-origin_resource_sharing).
+
+### error\_pages
+This option may be used to specify a directory for user defined error pages.
+The error pages may be specified for an individual http status code (e.g.,
+404 - page requested by the client not found), a group of http status codes
+(e.g., 4xx - all client errors) or all errors. The corresponding error pages
+must be called error404.ext, error4xx.ext or error.ext, whereas the file
+extention may be one of the extentions specified for the index_files option.
+See the [Wikipedia page on HTTP status codes](http://en.wikipedia.org/wiki/HTTP_status_code).
+
+### tcp\_nodelay `0`
+Enable TCP_NODELAY socket option on client connections.
+
+If set the socket option will disable Nagle's algorithm on the connection
+which means that packets will be sent as soon as possible instead of waiting
+for a full buffer or timeout to occur.
+
+    0    Keep the default: Nagel's algorithm enabled
+    1    Disable Nagel's algorithm for all sockets
+
+### static\_file\_max\_age `3600`
+Set the maximum time (in seconds) a cache may store a static files.
+
+This option will set the `Cache-Control: max-age` value for static files.
+Dynamically generated content, i.e., content created by a script or callback,
+must send cache control headers by themselfes.
+
+A value >0 corresponds to a maximum allowed caching time in seconds.
+This value should not exceed one year (RFC 2616, Section 14.21).
+A value of 0 will send "do not cache" headers for all static files.
+For values <0 and values >31622400, the behavior is undefined.
+
+### decode\_url `yes`
+URL encoded request strings are decoded in the server, unless it is disabled
+by setting this option to `no`.
+
+### ssl\_verify\_peer `no`
+Enable client's certificate verification by the server.
+
+### ssl\_ca\_path
+Name of a directory containing trusted CA certificates. Each file in the
+directory must contain only a single CA certificate. The files must be named
+by the subject name\u2019s hash and an extension of \u201c.0\u201d. If there is more than one
+certificate with the same subject name they should have extensions ".0", ".1",
+".2" and so on respectively.
+
+### ssl\_ca\_file
+Path to a .pem file containing trusted certificates. The file may contain
+more than one certificate.
+
+### ssl\_verify\_depth `9`
+Sets maximum depth of certificate chain. If client's certificate chain is longer
+than the depth set here connection is refused.
+
+### ssl\_default\_verify\_paths `yes`
+Loads default trusted certificates locations set at openssl compile time.
+
+### ssl\_cipher\_list
+List of ciphers to present to the client. Entries should be separated by
+colons, commas or spaces.
+
+    ALL           All available ciphers
+    ALL:!eNULL    All ciphers excluding NULL ciphers
+    AES128:!MD5   AES 128 with digests other than MD5
+
+See [this entry](https://www.openssl.org/docs/manmaster/apps/ciphers.html) in
+OpenSSL documentation for full list of options and additional examples.
+
+### ssl\_protocol\_version `0`
+Sets the minimal accepted version of SSL/TLS protocol according to the table:
+
+Protocols | Value
+------------ | -------------
+SSL2+SSL3+TLS1.0+TLS1.1+TLS1.2  | 0
+SSL3+TLS1.0+TLS1.1+TLS1.2  | 1
+TLS1.0+TLS1.1+TLS1.2 | 2
+TLS1.1+TLS1.2 | 3
+TLS1.2 | 4
+
+### ssl\_short\_trust `no`
+Enables the use of short lived certificates. This will allow for the certificates
+and keys specified in `ssl_certificate`, `ssl_ca_file` and `ssl_ca_path` to be
+exchanged and reloaded while the server is running.
+
+In an automated environment it is advised to first write the new pem file to
+a different filename and then to rename it to the configured pem file name to
+increase performance while swapping the certificate.
+
+Disk IO performance can be improved when keeping the certificates and keys stored
+on a tmpfs (linux) on a system with very high throughput.
+
+### allow\_sendfile\_call `yes`
+This option can be used to enable or disable the use of the Linux `sendfile` system call. It is only available for Linux systems and only affecting HTTP (not HTTPS) connections if `throttle` is not enabled. While using the `sendfile` call will lead to a performance boost for HTTP connections, this call may be broken for some file systems and some operating system versions.
+
+### case\_sensitive `no`
+This option can be uset to enable case URLs for Windows servers. It is only available for Windows systems. Windows file systems are not case sensitive, but they still store the file name including case. If this option is set to `yes`, the comparison for URIs and Windows file names will be case sensitive.
+
+
+# Lua Scripts and Lua Server Pages
+Pre-built Windows and Mac civetweb binaries have built-in Lua scripting
+support as well as support for Lua Server Pages.
+
+Lua scripts (default extension: *.lua) use plain Lua syntax.
+The body of the script file is not sent directly to the client,
+the Lua script must send header and content of the web page by calling
+the function mg.write(text).
+
+Lua Server Pages (default extensions: *.lsp, *.lp) are html pages containing
+script elements similar to PHP, using the Lua programming language instead of
+PHP. Lua script elements must be enclosed in `<?  ?>` blocks, and can appear
+anywhere on the page. Furthermore, Lua Server Pages offer the opportunity to
+insert the content of a variable by enclosing the Lua variable name in
+`<?=  ?>` blocks, similar to PHP.
+For example, to print the current weekday name and the URI of the current
+page, one can write:
+
+    <p>
+      <span>Today is:</span>
+      <? mg.write(os.date("%A")) ?>
+    </p>
+    <p>
+      URI is <?=mg.request_info.uri?>
+    </p>
+
+Lua is known for it's speed and small size. Civetweb currently uses Lua
+version 5.2.4. The documentation for it can be found in the
+[Lua 5.2 reference manual](http://www.lua.org/manual/5.2/).
+
+
+Note that this example uses function `mg.write()`, which sends data to the
+web client. Using `mg.write()` is the way to generate web content from inside
+Lua code. In addition to `mg.write()`, all standard Lua library functions
+are accessible from the Lua code (please check the reference manual for
+details). Lua functions working on files (e.g., `io.open`) use a path
+relative to the working path of the civetweb process. The web server content
+is located in the path `mg.document_root`.
+Information on the request is available in the `mg.request_info`
+object, like the request method, all HTTP headers, etcetera.
+
+[page2.lua](https://github.com/civetweb/civetweb/blob/master/test/page2.lua)
+is an example for a plain Lua script.
+
+[page2.lp](https://github.com/civetweb/civetweb/blob/master/test/page2.lp)
+is an example for a Lua Server Page.
+
+Both examples show the content of the `mg.request_info` object as the page
+content. Please refer to `struct mg_request_info` definition in
+[civetweb.h](https://github.com/civetweb/civetweb/blob/master/include/civetweb.h)
+to see additional information on the elements of the `mg.request_info` object.
+
+Civetweb also provides access to the [SQlite3 database](http://www.sqlite.org/)
+through the [LuaSQLite3 interface](http://lua.sqlite.org/index.cgi/doc/tip/doc/lsqlite3.wiki)
+in Lua. Examples are given in
+[page.lua](https://github.com/civetweb/civetweb/blob/master/test/page.lua) and
+[page.lp](https://github.com/civetweb/civetweb/blob/master/test/page.lp).
+
+
+Civetweb exports the following functions to Lua:
+
+mg (table):
+
+    mg.read()                  -- reads a chunk from POST data, returns it as a string
+    mg.write(str)              -- writes string to the client
+    mg.include(path)           -- sources another Lua file
+    mg.redirect(uri)           -- internal redirect to a given URI
+    mg.onerror(msg)            -- error handler, can be overridden
+    mg.version                 -- a string that holds Civetweb version
+    mg.document_root           -- a string that holds the document root directory
+    mg.auth_domain             -- a string that holds the HTTP authentication domain
+    mg.get_var(str, varname)   -- extract variable from (query) string
+    mg.get_cookie(str, cookie) -- extract cookie from a string
+    mg.get_mime_type(filename) -- get MIME type of a file
+    mg.send_file(filename)     -- send a file, including MIME type
+    mg.url_encode(str)         -- URL encode a string
+    mg.url_decode(str, [form]) -- URL decode a string. If form=true, replace + by space.
+    mg.base64_encode(str)      -- BASE64 encode a string
+    mg.base64_decode(str)      -- BASE64 decode a string
+    mg.md5(str)                -- return the MD5 hash of a string
+    mg.keep_alive(bool)        -- allow/forbid to use http keep-alive for this request
+    mg.request_info            -- a table with the following request information
+         .remote_addr          -- IP address of the client as string
+         .remote_port          -- remote port number
+         .server_port          -- server port number
+         .request_method       -- HTTP method (e.g.: GET, POST)
+         .http_version         -- HTTP protocol version (e.g.: 1.1)
+         .uri                  -- resource name
+         .query_string         -- query string if present, nil otherwise
+         .script_name          -- name of the Lua script
+         .https                -- true if accessed by https://, false otherwise
+         .remote_user          -- user name if authenticated, nil otherwise
+
+connect (function):
+
+    -- Connect to the remote TCP server. This function is an implementation
+    -- of simple socket interface. It returns a socket object with three
+    -- methods: send, recv, close, which are synchronous (blocking).
+    -- connect() throws an exception on connection error.
+    connect(host, port, use_ssl)
+
+    -- Example of using connect() interface:
+    local host = 'code.google.com'  -- IP address or domain name
+    local ok, sock = pcall(connect, host, 80, 1)
+    if ok then
+      sock:send('GET /p/civetweb/ HTTP/1.0\r\n' ..
+                'Host: ' .. host .. '\r\n\r\n')
+      local reply = sock:recv()
+      sock:close()
+      -- reply now contains the web page https://code.google.com/p/civetweb
+    end
+
+
+**IMPORTANT: Civetweb does not send HTTP headers for Lua pages. Therefore,
+every Lua Page must begin with a HTTP reply line and headers**, like this:
+
+    <? print('HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n') ?>
+    <html><body>
+      ... the rest of the web page ...
+
+To serve a Lua Page, civetweb creates a Lua context. That context is used for
+all Lua blocks within the page. That means, all Lua blocks on the same page
+share the same context. If one block defines a variable, for example, that
+variable is visible in all block that follow.
+
+## Websockets for Lua
+Civetweb offers support for websockets in Lua as well. In contrast to plain
+Lua scripts and Lua server pages, Lua websocket scripts are shared by all clients.
+
+Lua websocket scripts must define a few functions:
+    open(arg)    -- callback to accept or reject a connection
+    ready(arg)   -- called after a connection has been established
+    data(arg)    -- called when the server receives data from the client
+    close(arg)   -- called when a websocket connection is closed
+All function are called with one argument of type table with at least one field
+"client" to identify the client. When "open" is called, the argument table additionally
+contains the "request_info" table as defined above. For the "data" handler, an
+additional field "data" is available. The functions "open", "ready" and "data"
+must return true in order to keep the connetion open.
+
+Lua websocket pages do support single shot (timeout) and interval timers.
+
+An example is shown in
+[websocket.lua](https://github.com/civetweb/civetweb/blob/master/test/websocket.lua).
+
+
+# Common Problems
+- PHP doesn't work - getting empty page, or 'File not found' error. The
+  reason for that is wrong paths to the interpreter. Remember that with PHP,
+  the correct interpreter is `php-cgi.exe` (`php-cgi` on UNIX).
+  Solution: specify the full path to the PHP interpreter, e.g.:
+    `civetweb -cgi_interpreter /full/path/to/php-cgi`
+
+- `php-cgi` is unavailable, for example on Mac OS X. As long as the `php` binary is installed, you can run CGI programs in command line mode (see the example below). Note that in this mode, `$_GET` and friends will be unavailable, and you'll have to parse the query string manually using [parse_str](http://php.net/manual/en/function.parse-str.php) and the `QUERY_STRING` environmental variable.
+
+        #!/usr/bin/php
+        <?php
+        echo "Content-Type: text/html\r\n\r\n";
+        echo "Hello World!\n";
+        ?>
+
+- Civetweb fails to start. If Civetweb exits immediately when started, this
+  usually indicates a syntax error in the configuration file
+  (named `civetweb.conf` by default) or the command-line arguments.
+  Syntax checking is omitted from Civetweb to keep its size low. However,
+  the Manual should be of help. Note: the syntax changes from time to time,
+  so updating the config file might be necessary after executable update.
+
+- Embedding with OpenSSL on Windows might fail because of calling convention.
+  To force Civetweb to use `__stdcall` convention, add `/Gz` compilation
+  flag in Visual Studio compiler.

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/docs/_config.yml
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/docs/_config.yml b/thirdparty/civetweb-1.9.1/docs/_config.yml
new file mode 100644
index 0000000..259a24e
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/docs/_config.yml
@@ -0,0 +1 @@
+theme: jekyll-theme-tactile
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/docs/api/client_cert.md
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/docs/api/client_cert.md b/thirdparty/civetweb-1.9.1/docs/api/client_cert.md
new file mode 100644
index 0000000..2d1a510
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/docs/api/client_cert.md
@@ -0,0 +1,21 @@
+# Civetweb API Reference
+
+### `struct client_cert;`
+
+### Fields
+
+| Field | Type | Description |
+| :--- | :--- | :--- |
+|**`subject`**|`const char *`| The subject of the certificate |
+|**`issuer`**|`const char *`| The issuer of the certificate |
+|**`serial`**|`const char *`| The serial number of the certificate |
+|**`finger`**|`const char *`| The fingerprint of the certificate |
+
+### Description
+
+The structure `client_cert` is used as a sub-structure in the [`mg_request_info`](mg_request_info.md) structure to store information of an optional client supplied certificate.
+
+### See Also
+
+* [`struct mg_request_info;`](mg_request_info.md)
+* [`mg_get_request_info();`](mg_get_request_info.md)

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/docs/api/mg_callbacks.md
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/docs/api/mg_callbacks.md b/thirdparty/civetweb-1.9.1/docs/api/mg_callbacks.md
new file mode 100644
index 0000000..b68a1c3
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/docs/api/mg_callbacks.md
@@ -0,0 +1,60 @@
+# Civetweb API Reference
+
+### `struct mg_callbacks;`
+
+### Fields
+
+| Field | Description |
+| :--- | :--- | 
+|**`begin_request`**|**`int (*begin_request)( struct mg_connection * conn );`**|
+| |The `begin_request()` callback function is called when CivetWeb has received a new HTTP request. If the callback function does not process the request, it should return 0. In that case CivetWeb will handle the request with the default callback routine. If the callback function returns a value between 1 and 999, CivetWeb does nothing and the callback function should do all the processing, including sending the proper HTTP headers etc. Starting at CivetWeb version 1.7, the function `begin_request()` is called before any authorization is done. If an authorization check is required, `request_handler()` should be used instead. The return value of the callback function is not only used to signal CivetWeb to not further process the request. The returned value is also stored as HTTP status code in the access log. |
+|**`connection_close`**|**`void (*connection_close)( const struct mg_connection *conn );`**|
+| |The callback function `connection_close()` is called when CivetWeb is closing a connection. The per-context mutex is locked when the callback function is invoked. The function is primarly useful for noting when a websocket is closing and removing it from any application-maintained list of clients. *Using this callback for websocket connections is deprecated. Use* `mg_set_websocket_handler()` *instead.*|
+|**`end_request`**|**`void (*end_request)( const struct mg_connection * conn );`**|
+| |The callback function `end_request()` is called by CivetWeb when a request has been completely processed. It sends the reply status code which was sent to the client to the application.|
+|**`exit_context`**|**`void (*exit_context)( const struct mg_context *ctx );`**|
+| |The callback function `exit_context()` is called by CivetWeb when the server is stopped. It allows the application to do some cleanup on the application side.|
+|**`http_error`**|**`int (*http_error)( struct mg_connection *conn, int status );`**|
+| |The callback function `http_error()` is called by CivetWeb just before an HTTP error is to be sent to the client. The function allows the application to send a custom error page. The status code of the error is provided as a parameter. If the application sends their own error page, it must return 1 to signal CivetWeb that no further processing is needed. If the returned value is 0, CivetWeb will send a built-in error page to the client.|
+|**`init_context`**|**`void (*init_context)( const struct mg_context *ctx );`**|
+| |The callback function `init_context()` is called after the CivetWeb server has been started and initialized, but before any requests are served. This allowes the application to perform some initialization activities before the first requests are handled.|
+|**`init_lua`**|**`void (*init_lua)( const struct mg_connection *conn, void *lua_context );`**|
+| |The callback function `init_lua()` is called just before a Lua server page is to be served. Lua page serving must have been enabled at compile time for this callback function to be called. The parameter `lua_context` is a `lua_State *` pointer.|
+|**`init_ssl`**|**`int (*init_ssl)( void *ssl_context, void *user_data );`**|
+| |The callback function `init_ssl()` is called when CivetWeb initializes the SSL library. The parameter `user_data` contains a pointer to the data which was provided to `mg_start()` when the server was started. The callback function can return 0 to signal that CivetWeb should setup the SSL certificate. With a return value of 1 the callback function signals CivetWeb that the certificate has already been setup and no further processing is necessary. The value -1 should be returned when the SSL initialization fails.|
+|**`init_thread`**|**`void (*init_thread)( const struct mg_context *ctx, int thread_type );`**|
+| |The callback function `init_thread()` is called when a new thread is created by CivetWeb. The `thread_type` parameter indicates which type of thread has been created. following thread types are recognized:|
+| |**0** - The master thread is created |
+| |**1** - A worker thread which handles client connections has been created|
+| |**2** - An internal helper thread (timer thread) has been created|
+|**`log_access`**|**`int (*log_access)( const struct mg_connection *conn, const char *message );`**|
+| |The callback function `log_access()` is called when CivetWeb is about to log a message. If the callback function returns 0, CivetWeb will use the default internal access log routines to log the access. If a non-zero value is returned, CivetWeb assumes that access logging has already been done and no further action is performed.|
+|**`log_message`**|**`int (*log_message)( const struct mg_connection *conn, const char *message );`**|
+| |The callback function `log_message()` is called when CivetWeb is about to log a message. If the callback function returns 0, CivetWeb will use the default internal log routines to log the message. If a non-zero value is returned CivetWeb assumes that logging has already been done and no further action is performed.|
+|**`open_file`**|**`const char *(*open_file)( const struct mg_connection *conn, const char *path, size_t *data_len );`**|
+| |The callback function `open_file()` is called when a file is to be opened by CivetWeb. The callback can return a pointer to a memory location and set the memory block size in the variable pointed to by `data_len` to signal CivetWeb that the file should not be loaded from disk, but that instead a stored version in memory should be used. If the callback function returns NULL, CivetWeb will open the file from disk. This callback allows caching to be implementedi at the application side, or to serve specific files from static memory instead of from disk.|
+|~~`upload`~~|**`void (*upload)( struct mg_connection * conn, const char *file_name );`**|
+| |*Deprecated. Use* `mg_handle_form_request()` *instead.* The callback function `upload()` is called when CivetWeb has uploaded a file to a temporary directory as result of a call to `mg_upload()`. The parameter `file_name` contains the full file name including path to the uploaded file.|
+|~~`websocket_connect`~~|**`int (*websocket_connect)( const struct mg_connection *conn );`**|
+| |*Deprecated. Use* `mg_set_websocket_handler()` *instead.* The callback function `websocket_connect()` is called when a websocket request is received, before the actual websocket handshake has taken place. The callback function can signal to CivetWeb if it should accept or deny the incoming request with one of the following return values: |
+| |**0** - CivetWeb can proceed with the handshake to accept the connection |
+| |**1** - CivetWeb must close the connection immediately without performing a handshake |
+|~~`websocket_data`~~|**`int (*websocket_data)( struct mg_connection *conn, int bits, char *data, size_t data_len );`**|
+| |*Deprecated. Use* `mg_set_websocket_handler()` *instead.* The callback function `websocket_data()` is called when a data frame has been received from the client. The parameters contain the following information: |
+| | **`bits`** - The first byte of the websocket frame. See [RFC-6455](http://tools.ietf.org/html/rfc6455) at section 5.2 for more information. |
+| | **`data`** - The pointer to the received data block. Masks--if any--have already been applied. |
+| | **`data_len`** - The length of the received data block |
+| | If the application wants to keep the websocket open to receive more data, the callback function should return the value **1**. If the value **0** is returned by the callback function, CivetWeb will close the websocket connection and no more frames will be received.|
+|~~`websocket_ready`~~|**`int (*websocket_ready)( struct mg_connection *conn );`**|
+| |*Deprecated. Use* `mg_set_websocket_handler()` *instead.* The callback function `websocket_ready()` is called after the handshake of a websocket connection has succeeded succesfully to signal the application that the connection is ready for use. |
+
+### Description
+
+Much of the functionality in the Civetweb library is provided through callback functions. The application registers their own processing functions with the Civetweb library and when an event happens, the appropriate callback function is called. In this way an application is able to have their processing code right at the heart of the webserver, without the need to change the code of the webserver itself. A number of callback functions are registered when the civetweb subsystem is started. Other may be added or changed at runtime with helper functions.
+
+A pointer to a `mg_callbacks` structure is passed as parameter to the [`mg_start()`](mg_start.md) function to provide links to callback functions which the webserver will call at specific events. If a specific callback function is not supplied, CivetWeb will fallback to default internal callback routines. Callback functions give the application detailed control over how specific events should be handled.
+
+### See Also
+
+* [`mg_start();`](mg_start.md)
+* [`mg_stop();`](mg_stop.md)

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/docs/api/mg_check_feature.md
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/docs/api/mg_check_feature.md b/thirdparty/civetweb-1.9.1/docs/api/mg_check_feature.md
new file mode 100644
index 0000000..1da1b07
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/docs/api/mg_check_feature.md
@@ -0,0 +1,40 @@
+# Civetweb API Reference
+
+### `mg_check_feature( feature );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`feature`**|`unsigned`| A value indicating the feature to be checked |
+
+### Return Value
+
+| Type | Description |
+| :--- | :--- |
+|`unsigned`| A value indicating if a feature is available. A positive value indicates available, while **0** is returned for an unavailable feature |
+
+### Description
+
+The function `mg_check_feature()` can be called from an application program to check of specific features have been compiled in the civetweb version which the application has been linked to. The feature to check is provided as an unsigned integer parameter. If the function is available in the currently linked library version, a value **> 0** is returned. Otherwise the function `mg_check_feature()` returns the value **0**.
+
+The following parameter values can be used:
+
+| Value | Compilation option | Description |
+| :---: | :---: | :--- |
+| **1** | NO_FILES | *Able to serve files*.  If this feature is available, the webserver is able to serve files directly from a directory tree. |
+| **2** | NO_SSL | *Support for HTTPS*. If this feature is available, the webserver van use encryption in the client-server connection. SSLv2, SSLv3, TLSv1.0, TLSv1.1 and TLSv1.2 are supported depending on the SSL library CivetWeb has been compiled with, but which protocols are used effectively when the server is running is dependent on the options used when the server is started. |
+| **4** | NO_CGI | *Support for CGI*. If this feature is available, external CGI scripts can be called by the webserver. |
+| **8** | USE_IPV6 | *Support IPv6*. The CivetWeb library is capable of communicating over both IPv4 and IPv6, but IPv6 support is only available if it has been enabled at compile time. |
+| **16** | USE_WEBSOCKET | Support for web sockets. WebSockets support is available in the CivetWeb library if the proper options has been used during cimpile time. |
+| **32** | USE_LUA | *Support for Lua scripts and Lua server pages*. CivetWeb supports server side scripting through the Lua language, if that has been enabled at compile time. Lua is an efficient scripting language which is less resource heavy than for example PHP. |
+| **64** | USE_DUKTAPE | *Support for server side JavaScript*. Server side JavaScript can be used for dynamic page generation if the proper options have been set at compile time. Please note that client side JavaScript execution is always available if it has been enabled in the connecting browser. |
+| **128** | NO_CACHING | *Support for caching*. The webserver will support caching, if it has not been disabled while compiling the library. |
+
+Parameter values other than the values mentioned above will give undefined results. Therefore&mdash;although the parameter values for the `mg_check_feature()` function are effectively bitmasks, you should't assume that combining two of those values with an OR to a new value will give any meaningful results when the function returns.
+
+### See Also
+
+* [`mg_get_option();`](mg_get_option.md)
+* [~~`mg_get_valid_option_names();`~~](mg_get_valid_option_names.md)
+* [`mg_get_valid_options();`](mg_get_valid_options.md)

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/docs/api/mg_client_options.md
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/docs/api/mg_client_options.md b/thirdparty/civetweb-1.9.1/docs/api/mg_client_options.md
new file mode 100644
index 0000000..f3b9b68
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/docs/api/mg_client_options.md
@@ -0,0 +1,21 @@
+# Civetweb API Reference
+
+### `struct mg_client_options;`
+
+### Fields
+
+| Field | Type | Description |
+| :--- | :--- | :--- |
+|**`host`**|`const char *`|The hostname or IP address to connect to|
+|**`port`**|`int`|The port on the server|
+|**`client_cert`**|`const char *`|Pointer to client certificate|
+|**`server_cert`**|`const char *`|Pointer to a server certificate|
+
+### Description
+
+The the `mgclient_options` structure contains host and security information to connect as a client to another host. A parameter of this type is used in the call to the function [`mg_connect_client_secure();`](mg_connect_client_secure.md). Please note that IPv6 addresses are only permitted if IPv6 support was enabled during compilation. You can use the function [`mg_check_feature()`](mg_check_feature.md) with the parameter `USE_IPV6` while running your application to check if IPv6 is supported.
+
+### See Also
+
+* [`mg_check_feature();`](mg_check_feature.md)
+* [`mg_connect_client_secure();`](mg_connect_client_secure.md)

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/docs/api/mg_close_connection.md
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/docs/api/mg_close_connection.md b/thirdparty/civetweb-1.9.1/docs/api/mg_close_connection.md
new file mode 100644
index 0000000..ca8d2a1
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/docs/api/mg_close_connection.md
@@ -0,0 +1,21 @@
+# Civetweb API Reference
+
+### `mg_close_connection( conn );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`conn`**|`struct mg_connection *`|The connection which must be closed|
+
+### Return Value
+
+*none*
+
+### Description
+
+The function `mg_close_connection()` is used to close a connection which was opened with the [`mg_download()`](mg_download.md) function. Use of this function to close a connection which was opened in another way is undocumented and may give unexpected results.
+
+### See Also
+
+* [`mg_download();`](mg_download.md)

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/docs/api/mg_connect_client.md
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/docs/api/mg_connect_client.md b/thirdparty/civetweb-1.9.1/docs/api/mg_connect_client.md
new file mode 100644
index 0000000..e2aa773
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/docs/api/mg_connect_client.md
@@ -0,0 +1,29 @@
+# Civetweb API Reference
+
+### `mg_connect_client( host, port, use_ssl, error_buffer, error_buffer_size );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`host`**|`const char *`|hostname or IP address of the server|
+|**`port`**|`int`|The port to connect to on the server|
+|**`use_ssl`**|`int`|Connects using SSL of this value is not zero|
+|**`error_buffer`**|`char *`|Buffer to store an error message|
+|**`error_buffer_size`**|`size_t`|Maximum size of the error buffer including the NUL terminator|
+
+### Return Value
+
+| Type | Description |
+| :--- | :--- |
+|`struct mg_connection *`||
+
+### Description
+
+The function `mg_connect_client()` connects to a TCP server as a client. This server can be a HTTP server but this is not necessary. The function returns a pointer to a connection structure when the connection is established and NULL otherwise. The host may be on IPv4 or IPv6, but IPv6 is not enabled in every Civetweb installation. Specifically the use of IPv6 communications has to be enabled when the library is compiled. At runtime you can use the [`mg_check_feature()`](mg_check_feature.md) function with the parameter `USE_IPV6` to check if IPv6 communication is supported.
+ 
+### See Also
+
+* [`mg_check_feature();`](mg_check_feature.md)
+* [`mg_connect_client_secure();`](mg_connect_client_secure.md)
+* [`mg_connect_websocket_client();`](mg_connect_websocket_client.md)

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/docs/api/mg_connect_client_secure.md
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/docs/api/mg_connect_client_secure.md b/thirdparty/civetweb-1.9.1/docs/api/mg_connect_client_secure.md
new file mode 100644
index 0000000..a87949b
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/docs/api/mg_connect_client_secure.md
@@ -0,0 +1,30 @@
+# Civetweb API Reference
+
+### `mg_connect_client_secure( client_options, error_buffer, error_buffer_size );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`client_options`**|`const struct mg_client_options *`|Settings about the server connection|
+|**`error_buffer`**|`char *`|Buffer to store an error message|
+|**`error_buffer_size`**|`size_t`|Size of the error message buffer including the NUL terminator|
+
+### Return Value
+
+| Type | Description |
+| :--- | :--- |
+|`struct mg_connection *`||
+
+### Description
+
+The function `mg_connect_client_secure()` creates a secure connection with a server. The information about the connection and server is passed in a structure and an error message may be returned in a local buffer. The function returns a pointer to a `struct mg_connection` structure when successful and NULL otherwise.
+
+Please note that IPv6 communication is supported by Civetweb, but only if the use of IPv6 was enabled at compile time. The check while running a program if IPv6 communication is possible you can call [`mg_check_feature()`](mg_check_feature.md) with the `USE_IPV6` parameter to check if IPv6 communications can be used.
+
+### See Also
+
+* [`struct mg_client_options;`](mg_client_options.md)
+* [`mg_check_feature();`](mg_check_feature.md)
+* [`mg_connect_client();`](mg_connect_client.md)
+* [`mg_connect_websocket_client();`](mg_connect_websocket_client.md)

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/docs/api/mg_connect_websocket_client.md
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/docs/api/mg_connect_websocket_client.md b/thirdparty/civetweb-1.9.1/docs/api/mg_connect_websocket_client.md
new file mode 100644
index 0000000..8562b25
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/docs/api/mg_connect_websocket_client.md
@@ -0,0 +1,36 @@
+# Civetweb API Reference
+
+### `mg_connect_websocket_client( host, port, use_ssl, error_buffer, error_buffer_size, path, origin, data_func, close_func, user-data);`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`host`**|`const char *`|The hostname or IP address of the server|
+|**`port`**|`int`|The port on the server|
+|**`use_ssl`**|`int`|Use SSL if this parameter is not equal to zero|
+|**`error_buffer`**|`char *`|Buffer to store an error message|
+|**`error_buffer_size`**|`size_t`|Size of the error message buffer including the NUL terminator|
+|**`path`**|`const char *`|The server path to connect to, for example `/app` if you want to connect to `localhost/app`|
+|**`origin`**|`const char *`|The value of the `Origin` HTTP header|
+|**`data_func`**|`mg_websocket_data_handler`|Callback which is used to process data coming back from the server|
+|**`close_func`**|`mg_websocket_close_handler`|Callback which is called when the connection is to be closed|
+|**`user_data`**|`void *`|User supplied argument|
+
+### Return Value
+
+| Type | Description |
+| :--- | :--- |
+|`struct mg_connection *`|A pointer to the connection structure, or NULL if connecting failed|
+
+### Description
+
+The function `mg_connect_websocket_client()` connects to a websocket on a server as a client. Data and close events are processed with callback functions which must be provided in the call.
+
+Civetweb supports both IPv4 and IPv6 communication, but only if the use if IPv6 has been enabled at compile time. When running an application it is possible to check if IPv6 addressing is available by calling the [`mg_check_feature()`](mg_check_feature.md) function with the `USE_IPV6` parameter.
+
+### See Also
+
+* [`mg_check_feature();`](mg_check_feature.md)
+* [`mg_connect_client();`](mg_connect_client.md)
+* [`mg_connect_client_secure();`](mg_connect_client_secure.md)

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/docs/api/mg_cry.md
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/docs/api/mg_cry.md b/thirdparty/civetweb-1.9.1/docs/api/mg_cry.md
new file mode 100644
index 0000000..0cf45c9
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/docs/api/mg_cry.md
@@ -0,0 +1,23 @@
+# Civetweb API Reference
+
+### `mg_cry( conn, fmt, ... );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`conn`**|`const struct mg_connection *`|The connection on which a problem occured|
+|**`fmt`**|`const char *`|Format string without a line return|
+|**`...`**|*various*|Parameters depending on the format string|
+
+### Return Value
+
+*none*
+
+### Description
+
+The function `mg_cry()` is called when something happens on a connection. The function takes a format string similar to the `printf()` series of functions with parameters and creates a text string which can then be used for logging. The `mg_cry()` function prints the output to the opened error log stream. Log messages can be processed with the `log_message()` callback function specified in the `struct mg_callbacks` structure.
+
+### See Also
+
+* [`struct mg_callbacks;`](mg_callbacks.md)


[34/51] [partial] nifi-minifi-cpp git commit: MINIFI-183 Added civet 1.9.1 sources Added onScheduled hook Added initial two-way TLS-enabled ListenHTTP implementation

Posted by al...@apache.org.
http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/civetweb_lua.h
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/civetweb_lua.h b/thirdparty/civetweb-1.9.1/src/third_party/civetweb_lua.h
new file mode 100644
index 0000000..5ffefbe
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/civetweb_lua.h
@@ -0,0 +1,73 @@
+/* Copyright (c) 2015-2017 the Civetweb developers
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+/* This header is intended to support Lua 5.1, Lua 5.2 and Lua 5.3 in the same
+ * C source code.
+ */
+
+#ifndef CIVETWEB_LUA_H
+#define CIVETWEB_LUA_H
+
+#define LUA_LIB
+#include "lua.h"
+#include "lauxlib.h"
+#include "lualib.h"
+
+#ifndef LUA_VERSION_NUM
+#error "Unknown Lua version"
+
+#elif LUA_VERSION_NUM == 501
+/* Lua 5.1 detected */
+#define LUA_OK 0
+#define LUA_ERRGCMM 999 /* not supported */
+#define mg_lua_load(a, b, c, d, e) lua_load(a, b, c, d)
+#define lua_rawlen lua_objlen
+#define lua_newstate(a, b)                                                     \
+	luaL_newstate() /* Must use luaL_newstate() for 64 bit target */
+#define lua_pushinteger lua_pushnumber
+#define luaL_newlib(L, t)                                                      \
+	{                                                                          \
+		luaL_Reg const *r = t;                                                 \
+		while (r->name) {                                                      \
+			lua_register(L, r->name, r->func);                                 \
+			r++;                                                               \
+		}                                                                      \
+	}
+#define luaL_setfuncs(L, r, u) lua_register(L, r->name, r->func)
+
+#elif LUA_VERSION_NUM == 502
+/* Lua 5.2 detected */
+#define mg_lua_load lua_load
+
+#elif LUA_VERSION_NUM == 503
+/* Lua 5.3 detected */
+#define mg_lua_load lua_load
+
+#endif
+
+#ifdef LUA_VERSION_MAKEFILE
+#if LUA_VERSION_MAKEFILE != LUA_VERSION_NUM
+#error                                                                         \
+    "Mismatch between Lua version specified in Makefile and Lua version in lua.h"
+#endif
+#endif
+
+#endif /* #ifndef CIVETWEB_LUA_H */

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/AUTHORS.rst
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/AUTHORS.rst b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/AUTHORS.rst
new file mode 100644
index 0000000..2799f70
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/AUTHORS.rst
@@ -0,0 +1,72 @@
+===============
+Duktape authors
+===============
+
+Copyright
+=========
+
+Duktape copyrights are held by its authors.  Each author has a copyright
+to their contribution, and agrees to irrevocably license the contribution
+under the Duktape ``LICENSE.txt``.
+
+Authors
+=======
+
+Please include an e-mail address, a link to your GitHub profile, or something
+similar to allow your contribution to be identified accurately.
+
+The following people have contributed code, website contents, or Wiki contents,
+and agreed to irrevocably license their contributions under the Duktape
+``LICENSE.txt`` (in order of appearance):
+
+* Sami Vaarala <sa...@iki.fi>
+* Niki Dobrev
+* Andreas �man <an...@lonelycoder.com>
+* L�szl� Lang� <ll...@partner.samsung.com>
+* Legimet <le...@gmail.com>
+* Karl Skomski <ka...@skomski.com>
+* Bruce Pascoe <fa...@gmail.com>
+* Ren� Hollander <re...@rene8888.at>
+* Julien Hamaide (https://github.com/crazyjul)
+* Sebastian G�tte (https://github.com/jaseg)
+
+Other contributions
+===================
+
+The following people have contributed something other than code (e.g. reported
+bugs, provided ideas, etc; roughly in order of appearance):
+
+* Greg Burns
+* Anthony Rabine
+* Carlos Costa
+* Aur�lien Bouilland
+* Preet Desai (Pris Matic)
+* judofyr (http://www.reddit.com/user/judofyr)
+* Jason Woofenden
+* Micha\u0142 Przyby\u015b
+* Anthony Howe
+* Conrad Pankoff
+* Jim Schimpf
+* Rajaran Gaunker (https://github.com/zimbabao)
+* Andreas �man
+* Doug Sanden
+* Josh Engebretson (https://github.com/JoshEngebretson)
+* Remo Eichenberger (https://github.com/remoe)
+* Mamod Mehyar (https://github.com/mamod)
+* David Demelier (https://github.com/markand)
+* Tim Caswell (https://github.com/creationix)
+* Mitchell Blank Jr (https://github.com/mitchblank)
+* https://github.com/yushli
+* Seo Sanghyeon (https://github.com/sanxiyn)
+* Han ChoongWoo (https://github.com/tunz)
+* Joshua Peek (https://github.com/josh)
+* Bruce E. Pascoe (https://github.com/fatcerberus)
+* https://github.com/Kelledin
+* https://github.com/sstruchtrup
+* Michael Drake (https://github.com/tlsa)
+* https://github.com/chris-y
+* Laurent Zubiaur (https://github.com/lzubiaur)
+* Ole Andr� Vadla Ravn�s (https://github.com/oleavr)
+
+If you are accidentally missing from this list, send me an e-mail
+(``sami.vaarala@iki.fi``) and I'll fix the omission.

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/LICENSE.txt
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/LICENSE.txt b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/LICENSE.txt
new file mode 100644
index 0000000..1b1c382
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/LICENSE.txt
@@ -0,0 +1,25 @@
+===============
+Duktape license
+===============
+
+(http://opensource.org/licenses/MIT)
+
+Copyright (c) 2013-2016 by Duktape authors (see AUTHORS.rst)
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/Makefile.cmdline
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/Makefile.cmdline b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/Makefile.cmdline
new file mode 100644
index 0000000..68a25d4
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/Makefile.cmdline
@@ -0,0 +1,34 @@
+#
+#  Example Makefile for building a program with embedded Duktape.
+#  The example program here is the Duktape command line tool.
+#
+
+DUKTAPE_SOURCES = src/duktape.c
+
+DUKTAPE_CMDLINE_SOURCES = \
+	examples/cmdline/duk_cmdline.c
+
+CC	= gcc
+CCOPTS	= -Os -pedantic -std=c99 -Wall -fstrict-aliasing -fomit-frame-pointer
+CCOPTS += -I./src   # duktape.h and duk_config.h must be in include path
+CCLIBS	= -lm
+
+# If you want linenoise, you can enable these.  At the moment linenoise
+# will cause some harmless compilation warnings.
+#CCOPTS += -DDUK_CMDLINE_FANCY
+#DUKTAPE_CMDLINE_SOURCES += linenoise/linenoise.c
+#CCOPTS += -I./linenoise
+#duk:	linenoise
+
+# Optional feature defines, see: http://duktape.org/guide.html#compiling
+CCOPTS += -DDUK_OPT_SELF_TESTS
+#CCOPTS += -DDUK_OPT_DEBUG
+#CCOPTS += -DDUK_OPT_DPRINT
+# ...
+
+duk:	$(DUKTAPE_SOURCES) $(DUKTAPE_CMDLINE_SOURCES)
+	$(CC) -o $@ $(DEFINES) $(CCOPTS) $(DUKTAPE_SOURCES) $(DUKTAPE_CMDLINE_SOURCES) $(CCLIBS)
+
+linenoise/linenoise.c: linenoise
+linenoise:
+	git clone https://github.com/antirez/linenoise.git

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/Makefile.codepage
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/Makefile.codepage b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/Makefile.codepage
new file mode 100644
index 0000000..cdce9ab
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/Makefile.codepage
@@ -0,0 +1,4 @@
+codepage:
+	gcc -o $@ -std=c99 -O2 -Wall -Wextra -Isrc/ \
+		src/duktape.c examples/codepage-conv/duk_codepage_conv.c \
+		examples/codepage-conv/test.c -lm

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/Makefile.coffee
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/Makefile.coffee b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/Makefile.coffee
new file mode 100644
index 0000000..b99eea2
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/Makefile.coffee
@@ -0,0 +1,4 @@
+dummy:
+	coffee -c examples/coffee/globals.coffee
+	coffee -c examples/coffee/hello.coffee
+	coffee -c examples/coffee/mandel.coffee

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/Makefile.dukdebug
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/Makefile.dukdebug b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/Makefile.dukdebug
new file mode 100644
index 0000000..dbbe6c8
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/Makefile.dukdebug
@@ -0,0 +1,26 @@
+#
+#  Duktape command line tool with debugger support.
+#
+
+DUKTAPE_SOURCES = src/duktape.c
+
+# Windows (MinGW): use examples/debug-trans-socket/duk_trans_socket_windows.c
+# and link with -lws2_32.
+DUKTAPE_CMDLINE_SOURCES = \
+	examples/cmdline/duk_cmdline.c \
+	examples/debug-trans-socket/duk_trans_socket_unix.c
+
+CC	= gcc
+CCOPTS	= -Os -pedantic -std=c99 -Wall -fstrict-aliasing -fomit-frame-pointer
+CCOPTS += -I./src -I./examples/debug-trans-socket
+CCOPTS += -DDUK_CMDLINE_DEBUGGER_SUPPORT     # enable --debugger in ./duk
+CCOPTS += -DDUK_OPT_DEBUGGER_SUPPORT         # enable debugger support in Duktape
+CCOPTS += -DDUK_OPT_INTERRUPT_COUNTER        # prerequisite for debugging
+CCOPTS += -DDUK_OPT_DEBUGGER_FWD_PRINTALERT  # optional debugger features
+CCOPTS += -DDUK_OPT_DEBUGGER_FWD_LOGGING
+CCOPTS += -DDUK_OPT_DEBUGGER_DUMPHEAP
+CCOPTS += -DDUK_OPT_DEBUGGER_INSPECT
+CCLIBS	= -lm
+
+duk:	$(DUKTAPE_SOURCES) $(DUKTAPE_CMDLINE_SOURCES)
+	$(CC) -o $@ $(DEFINES) $(CCOPTS) $(DUKTAPE_SOURCES) $(DUKTAPE_CMDLINE_SOURCES) $(CCLIBS)

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/Makefile.eval
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/Makefile.eval b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/Makefile.eval
new file mode 100644
index 0000000..73c5225
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/Makefile.eval
@@ -0,0 +1,7 @@
+#
+#  Example Makefile for building the eval example
+#
+
+eval:
+	gcc -o $@ -std=c99 -O2 -Wall -Wextra -Isrc/ \
+		src/duktape.c examples/eval/eval.c -lm

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/Makefile.eventloop
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/Makefile.eventloop b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/Makefile.eventloop
new file mode 100644
index 0000000..14806ac
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/Makefile.eventloop
@@ -0,0 +1,22 @@
+#
+#  Example Makefile for building the eventloop example
+#
+
+evloop:
+	@echo "NOTE: The eventloop is example is intended to be used on Linux"
+	@echo "      or other common UNIX variants.  It is not fully portable."
+	@echo ""
+
+	gcc -o $@ -std=c99 -Wall -Wextra -O2 -Isrc \
+		examples/eventloop/main.c \
+		examples/eventloop/c_eventloop.c \
+		examples/eventloop/poll.c \
+		examples/eventloop/socket.c \
+		examples/eventloop/fileio.c \
+		examples/eventloop/ncurses.c \
+		src/duktape.c \
+		-lm -lncurses
+
+	@echo ""
+	@echo "NOTE: You must 'cd examples/eventloop' before you execute the"
+	@echo "      eventloop binary: it relies on finding .js files in CWD"

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/Makefile.hello
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/Makefile.hello b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/Makefile.hello
new file mode 100644
index 0000000..82e9ab6
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/Makefile.hello
@@ -0,0 +1,35 @@
+#
+#  Example Makefile for building a program with embedded Duktape.
+#
+#  There are two source sets in the distribution: (1) combined sources where
+#  you only need duktape.c, duktape.h, and duk_config.h, and (2) separate
+#  sources where you have a bunch of source and header files.  Whichever
+#  you use, simply include the relevant sources into your C project.  This
+#  Makefile uses the combined source file.
+#
+
+DUKTAPE_SOURCES = src/duktape.c
+
+# Compiler options are quite flexible.  GCC versions have a significant impact
+# on the size of -Os code, e.g. gcc-4.6 is much worse than gcc-4.5.
+
+CC	= gcc
+CCOPTS	= -Os -pedantic -std=c99 -Wall -fstrict-aliasing -fomit-frame-pointer
+CCOPTS += -I./src  # for combined sources
+CCLIBS	= -lm
+DEFINES =
+
+# If you want a 32-bit build on a 64-bit host
+#CCOPTS += -m32
+
+# Optional feature defines, see: http://duktape.org/guide.html#compiling
+DEFINES += -DDUK_OPT_SELF_TESTS
+#DEFINES += -DDUK_OPT_DEBUG
+#DEFINES += -DDUK_OPT_DPRINT
+#DEFINES += -DDUK_OPT_NO_TRACEBACKS
+# ...
+
+# For debugging, use -O0 -g -ggdb, and don't add -fomit-frame-pointer
+
+hello:	$(DUKTAPE_SOURCES) examples/hello/hello.c
+	$(CC) -o $@ $(DEFINES) $(CCOPTS) $(DUKTAPE_SOURCES) examples/hello/hello.c $(CCLIBS)

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/Makefile.jxpretty
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/Makefile.jxpretty b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/Makefile.jxpretty
new file mode 100644
index 0000000..199247e
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/Makefile.jxpretty
@@ -0,0 +1,8 @@
+#
+#  Example Makefile for building the jxpretty example
+#
+
+jxpretty:
+	gcc -o $@ -std=c99 -Wall -Wextra -O2 -Isrc \
+		src/duktape.c examples/jxpretty/jxpretty.c \
+		-lm

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/Makefile.sandbox
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/Makefile.sandbox b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/Makefile.sandbox
new file mode 100644
index 0000000..acd922a
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/Makefile.sandbox
@@ -0,0 +1,7 @@
+#
+#  Example Makefile for building the sandbox example
+#
+
+sandbox:
+	gcc -o $@ -std=c99 -O2 -Wall -Wextra -Isrc/ \
+		src/duktape.c examples/sandbox/sandbox.c -lm

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/Makefile.sharedlibrary
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/Makefile.sharedlibrary b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/Makefile.sharedlibrary
new file mode 100644
index 0000000..32138ce
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/Makefile.sharedlibrary
@@ -0,0 +1,71 @@
+#
+#  Example of how to build and install locally as a shared library
+#
+#  Usage:
+#
+#    $ make -f Makefile.sharedlibrary
+#    $ sudo make -f Makefile.sharedlibrary install
+#    $ make -f Makefile.sharedlibrary duk  # --> example 'duk' linked to shared libduktape
+#
+#    $ ls -l duk
+#    -rwxrwxr-x 1 duktape duktape 19407 Nov 30 15:48 duk
+#
+#    $ ldd ./duk
+#            linux-vdso.so.1 =>  (0x00007ffd5ed3c000)
+#            libduktape.so.104 => /usr/local/lib/libduktape.so.104 (0x00007fb2f9753000)
+#            libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fb2f944d000)
+#            libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fb2f9088000)
+#            /lib64/ld-linux-x86-64.so.2 (0x00007fb2f9991000)
+#
+#  Based on: http://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html
+
+# Soname version must be bumped whenever a binary compatibility change occurs
+# (and should not be bumped when the library is compatible).  A simple Duktape
+# convention is to set soname version to (100*MAJOR + MINOR), e.g. 104 for
+# Duktape 1.4.x, so that it gets automatically bumped for major and minor
+# releases (potentially binary incompatible), but not for patch releases.
+DUK_VERSION=10502
+SONAME_VERSION=105
+REAL_VERSION=$(SONAME_VERSION).$(DUK_VERSION)
+
+# Change to actual path for actual distribution packaging.
+INSTALL_PREFIX=/usr/local
+
+# The 'noline' variant may be more appropriate for some distributions; it
+# doesn't have #line directives in the combined source.
+DUKTAPE_SRCDIR=./src
+#DUKTAPE_SRCDIR=./src-noline
+
+.PHONY: all
+all: libduktape.so.$(REAL_VERSION) libduktaped.so.$(REAL_VERSION)
+
+# If the default duk_config.h is not suitable for the distribution, modify it
+# before compiling the shared library and copy the same, edited duk_config.h
+# to $INSTALL_PREFIX/include on installation.
+
+libduktape.so.$(REAL_VERSION):
+	gcc -shared -fPIC -Wall -Wextra -Os -Wl,-soname,libduktape.so.$(SONAME_VERSION) \
+		-o $@ $(DUKTAPE_SRCDIR)/duktape.c
+
+libduktaped.so.$(REAL_VERSION):
+	gcc -shared -fPIC -g -Wall -Wextra -Os -Wl,-soname,libduktaped.so.$(SONAME_VERSION) \
+		-o $@ $(DUKTAPE_SRCDIR)/duktape.c
+
+# Symlinks depend on platform conventions.
+.PHONY: install
+install: libduktape.so.$(REAL_VERSION) libduktaped.so.$(REAL_VERSION)
+	cp $+ $(INSTALL_PREFIX)/lib/
+	rm -f $(INSTALL_PREFIX)/lib/libduktape.so $(INSTALL_PREFIX)/lib/libduktape.so.$(SONAME_VERSION)
+	ln -s libduktape.so.$(REAL_VERSION) $(INSTALL_PREFIX)/lib/libduktape.so
+	ln -s libduktape.so.$(REAL_VERSION) $(INSTALL_PREFIX)/lib/libduktape.so.$(SONAME_VERSION)
+	rm -f $(INSTALL_PREFIX)/lib/libduktaped.so $(INSTALL_PREFIX)/lib/libduktaped.so.$(SONAME_VERSION)
+	ln -s libduktaped.so.$(REAL_VERSION) $(INSTALL_PREFIX)/lib/libduktaped.so
+	ln -s libduktaped.so.$(REAL_VERSION) $(INSTALL_PREFIX)/lib/libduktaped.so.$(SONAME_VERSION)
+	cp $(DUKTAPE_SRCDIR)/duktape.h $(DUKTAPE_SRCDIR)/duk_config.h $(INSTALL_PREFIX)/include/
+
+# Note: assumes /usr/local/include/ and /usr/local/lib/ are in include/link
+# path which may not be the case for all distributions.
+#CCOPTS=-I/usr/local/include -L/usr/local/lib
+CCOPTS=
+duk:
+	gcc $(CCOPTS) -Wall -Wextra -Os -o $@ ./examples/cmdline/duk_cmdline.c -lduktape -lm

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/README.rst
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/README.rst b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/README.rst
new file mode 100644
index 0000000..65311a7
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/README.rst
@@ -0,0 +1,110 @@
+=======
+Duktape
+=======
+
+Duktape is a small and portable Ecmascript E5/E5.1 implementation.  It is
+intended to be easily embeddable into C programs, with a C API similar in
+spirit to Lua's.
+
+Duktape supports the full E5/E5.1 feature set including errors, Unicode
+strings, and regular expressions, a subset of E6 features (e.g. Proxy
+objects), Khronos/ES6 ArrayBuffer/TypedView, and Node.js Buffer bindings.
+
+Duktape also provides a number of custom features such as error tracebacks,
+additional data types for better C integration, combined reference counting
+and mark-and sweep garbage collector, object finalizers, co-operative
+threads a.k.a. coroutines, tail calls, built-in logging and module frameworks,
+a built-in debugger protocol, function bytecode dump/load, and so on.
+
+You can browse Duktape programmer's API and other documentation at:
+
+* http://duktape.org/
+
+In particular, you should read the getting started section:
+
+* http://duktape.org/guide.html#gettingstarted
+
+More examples and how-to articles are in the Duktape Wiki:
+
+* http://wiki.duktape.org/
+
+Building and integrating Duktape into your project is very straightforward:
+
+* http://duktape.org/guide.html#compiling
+
+See Makefile.hello for a concrete example::
+
+  $ cd <dist_root>
+  $ make -f Makefile.hello
+  [...]
+  $ ./hello
+  Hello world!
+  2+3=5
+
+To build an example command line tool, use the following::
+
+  $ cd <dist_root>
+  $ make -f Makefile.cmdline
+  [...]
+
+  $ ./duk
+  ((o) Duktape
+  duk> print('Hello world!');
+  Hello world!
+  = undefined
+
+  $ ./duk mandel.js
+  [...]
+
+This distributable contains:
+
+* ``src/``: main Duktape library in a "single source file" format (duktape.c,
+  duktape.h, and duk_config.h).
+
+* ``src-noline/``: contains a variant of ``src/duktape.c`` with no ``#line``
+  directives which is preferable for some users.  See discussion in
+  https://github.com/svaarala/duktape/pull/363.
+
+* ``src-separate/``: main Duktape library in multiple files format.
+
+* ``config/``: genconfig utility for creating duk_config.h configuration
+  files, see: http://wiki.duktape.org/Configuring.html.
+
+* ``examples/``: further examples for using Duktape.  Although Duktape
+  itself is widely portable, some of the examples are Linux only.
+  For instance the ``eventloop`` example illustrates how ``setTimeout()``
+  and other standard timer functions could be implemented on Unix/Linux.
+
+* ``extras/``: utilities and modules which don't comfortably fit into the
+  main Duktape library because of footprint or portability concerns.
+  Extras are maintained and bug fixed code, but don't have the same version
+  guarantees as the main Duktape library.
+
+* ``polyfills/``: a few replacement suggestions for non-standard Javascript
+  functions provided by other implementations.
+
+* ``debugger/``: a debugger with a web UI, see ``debugger/README.rst`` and
+  https://github.com/svaarala/duktape/blob/master/doc/debugger.rst for
+  details on Duktape debugger support.  Also contains a JSON debug proxy
+  (one written in Node.js and another in DukLuv) to make talking to the
+  debug target easier.
+
+* ``licenses/``: licensing information.
+
+You can find release notes at:
+
+* https://github.com/svaarala/duktape/blob/master/RELEASES.rst
+
+This distributable contains Duktape version 1.5.2, created from git
+commit cad34ae155acb0846545ca6bf2d29f9463b22bbb (v1.5.2).
+
+Duktape is copyrighted by its authors (see ``AUTHORS.rst``) and licensed
+under the MIT license (see ``LICENSE.txt``).  String hashing algorithms are
+based on the algorithm from Lua (MIT license), djb2 hash, and Murmurhash2
+(MIT license).  Duktape module loader is based on the CommonJS module
+loading specification (without sharing any code), CommonJS is under the
+MIT license.
+
+Have fun!
+
+Sami Vaarala (sami.vaarala@iki.fi)

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/config/README.rst
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/config/README.rst b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/config/README.rst
new file mode 100644
index 0000000..1d17226
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/config/README.rst
@@ -0,0 +1,39 @@
+=================
+Duktape genconfig
+=================
+
+Overview
+========
+
+``genconfig`` is a helper script for coming up with a ``duk_config.h`` for
+compiling Duktape for your platform.
+
+To support this:
+
+* It creates a Duktape 1.2.x compatible ``duk_config.h`` with automatic
+  platform detection and ``DUK_OPT_xxx`` feature options.
+
+* It helps to create a ``duk_config.h`` for your platform/compiler
+  combination.  You can give a base configuration and then force certain
+  values manually based on a YAML configuration file.
+
+* It autogenerates documentation for config options (and Duktape 1.2.x
+  feature options) based on option metadata files written in YAML.
+
+Usage
+=====
+
+To create an autodetect duk_config.h header (compatible with Duktape 1.2.x)::
+
+    $ python config/genconfig.py --metadata config --output /tmp/duk_config.h \
+          autodetect-header
+
+To create a barebones duk_config.h header for a specific platform (easier to
+edit manually)::
+
+    $ python config/genconfig.py --metadata config --output /tmp/duk_config.h \
+          --platform linux --compiler gcc --architecture x64 \
+          barebones-header
+
+There are further commands to e.g. autogenerate config option documentation;
+see ``genconfig.py`` for details.


[37/51] [partial] nifi-minifi-cpp git commit: MINIFI-183 Added civet 1.9.1 sources Added onScheduled hook Added initial two-way TLS-enabled ListenHTTP implementation

Posted by al...@apache.org.
http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/civetweb_private_lua.h
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/civetweb_private_lua.h b/thirdparty/civetweb-1.9.1/src/civetweb_private_lua.h
new file mode 100644
index 0000000..47c6566
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/civetweb_private_lua.h
@@ -0,0 +1,11 @@
+/* "civetweb_private_lua.h" */
+/* Project internal header to allow main.c to call a non-public function in
+ * mod_lua.inl */
+
+#ifndef CIVETWEB_PRIVATE_LUA_H
+#define CIVETWEB_PRIVATE_LUA_H
+
+int run_lua(const char *file_name);
+
+
+#endif

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/file_ops.inl
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/file_ops.inl b/thirdparty/civetweb-1.9.1/src/file_ops.inl
new file mode 100644
index 0000000..cfaadea
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/file_ops.inl
@@ -0,0 +1 @@
+/* currently not required */

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/handle_form.inl
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/handle_form.inl b/thirdparty/civetweb-1.9.1/src/handle_form.inl
new file mode 100644
index 0000000..04867df
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/handle_form.inl
@@ -0,0 +1,810 @@
+/* Copyright (c) 2016-2017 the Civetweb developers
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+
+static int
+url_encoded_field_found(const struct mg_connection *conn,
+                        const char *key,
+                        size_t key_len,
+                        const char *filename,
+                        size_t filename_len,
+                        char *path,
+                        size_t path_len,
+                        struct mg_form_data_handler *fdh)
+{
+	char key_dec[1024];
+	char filename_dec[1024];
+	int key_dec_len;
+	int filename_dec_len;
+	int ret;
+
+	key_dec_len =
+	    mg_url_decode(key, (int)key_len, key_dec, (int)sizeof(key_dec), 1);
+
+	if (((size_t)key_dec_len >= (size_t)sizeof(key_dec)) || (key_dec_len < 0)) {
+		return FORM_FIELD_STORAGE_SKIP;
+	}
+
+	if (filename) {
+		filename_dec_len = mg_url_decode(filename,
+		                                 (int)filename_len,
+		                                 filename_dec,
+		                                 (int)sizeof(filename_dec),
+		                                 1);
+
+		if (((size_t)filename_dec_len >= (size_t)sizeof(filename_dec))
+		    || (filename_dec_len < 0)) {
+			/* Log error message and skip this field. */
+			mg_cry(conn, "%s: Cannot decode filename", __func__);
+			return FORM_FIELD_STORAGE_SKIP;
+		}
+	} else {
+		filename_dec[0] = 0;
+	}
+
+	ret =
+	    fdh->field_found(key_dec, filename_dec, path, path_len, fdh->user_data);
+
+	if ((ret & 0xF) == FORM_FIELD_STORAGE_GET) {
+		if (fdh->field_get == NULL) {
+			mg_cry(conn, "%s: Function \"Get\" not available", __func__);
+			return FORM_FIELD_STORAGE_SKIP;
+		}
+	}
+	if ((ret & 0xF) == FORM_FIELD_STORAGE_STORE) {
+		if (fdh->field_store == NULL) {
+			mg_cry(conn, "%s: Function \"Store\" not available", __func__);
+			return FORM_FIELD_STORAGE_SKIP;
+		}
+	}
+
+	return ret;
+}
+
+
+static int
+url_encoded_field_get(const struct mg_connection *conn,
+                      const char *key,
+                      size_t key_len,
+                      const char *value,
+                      size_t value_len,
+                      struct mg_form_data_handler *fdh)
+{
+	char key_dec[1024];
+
+	char *value_dec = mg_malloc(value_len + 1);
+	int value_dec_len, ret;
+
+	if (!value_dec) {
+		/* Log error message and stop parsing the form data. */
+		mg_cry(conn,
+		       "%s: Not enough memory (required: %lu)",
+		       __func__,
+		       (unsigned long)(value_len + 1));
+		return FORM_FIELD_STORAGE_ABORT;
+	}
+
+	mg_url_decode(key, (int)key_len, key_dec, (int)sizeof(key_dec), 1);
+
+	value_dec_len =
+	    mg_url_decode(value, (int)value_len, value_dec, (int)value_len + 1, 1);
+
+	ret = fdh->field_get(key_dec,
+	                     value_dec,
+	                     (size_t)value_dec_len,
+	                     fdh->user_data);
+
+	mg_free(value_dec);
+
+	return ret;
+}
+
+
+static int
+unencoded_field_get(const struct mg_connection *conn,
+                    const char *key,
+                    size_t key_len,
+                    const char *value,
+                    size_t value_len,
+                    struct mg_form_data_handler *fdh)
+{
+	char key_dec[1024];
+	(void)conn;
+
+	mg_url_decode(key, (int)key_len, key_dec, (int)sizeof(key_dec), 1);
+
+	return fdh->field_get(key_dec, value, value_len, fdh->user_data);
+}
+
+
+static int
+field_stored(const struct mg_connection *conn,
+             const char *path,
+             long long file_size,
+             struct mg_form_data_handler *fdh)
+{
+	/* Equivalent to "upload" callback of "mg_upload". */
+
+	(void)conn; /* we do not need mg_cry here, so conn is currently unused */
+
+	return fdh->field_store(path, file_size, fdh->user_data);
+}
+
+
+static const char *
+search_boundary(const char *buf,
+                size_t buf_len,
+                const char *boundary,
+                size_t boundary_len)
+{
+	/* We must do a binary search here, not a string search, since the buffer
+	 * may contain '\x00' bytes, if binary data is transferred. */
+	int clen = (int)buf_len - (int)boundary_len - 4;
+	int i;
+
+	for (i = 0; i <= clen; i++) {
+		if (!memcmp(buf + i, "\r\n--", 4)) {
+			if (!memcmp(buf + i + 4, boundary, boundary_len)) {
+				return buf + i;
+			}
+		}
+	}
+	return NULL;
+}
+
+
+int
+mg_handle_form_request(struct mg_connection *conn,
+                       struct mg_form_data_handler *fdh)
+{
+	const char *content_type;
+	char path[512];
+	char buf[1024];
+	int field_storage;
+	int buf_fill = 0;
+	int r;
+	int field_count = 0;
+	struct mg_file fstore = STRUCT_FILE_INITIALIZER;
+	int64_t file_size = 0; /* init here, to a avoid a false positive
+	                         "uninitialized variable used" warning */
+
+	int has_body_data =
+	    (conn->request_info.content_length > 0) || (conn->is_chunked);
+
+	/* There are three ways to encode data from a HTML form:
+	 * 1) method: GET (default)
+	 *    The form data is in the HTTP query string.
+	 * 2) method: POST, enctype: "application/x-www-form-urlencoded"
+	 *    The form data is in the request body.
+	 *    The body is url encoded (the default encoding for POST).
+	 * 3) method: POST, enctype: "multipart/form-data".
+	 *    The form data is in the request body of a multipart message.
+	 *    This is the typical way to handle file upload from a form.
+	 */
+
+	if (!has_body_data) {
+		const char *data;
+
+		if (strcmp(conn->request_info.request_method, "GET")) {
+			/* No body data, but not a GET request.
+			 * This is not a valid form request. */
+			return -1;
+		}
+
+		/* GET request: form data is in the query string. */
+		/* The entire data has already been loaded, so there is no nead to
+		 * call mg_read. We just need to split the query string into key-value
+		 * pairs. */
+		data = conn->request_info.query_string;
+		if (!data) {
+			/* No query string. */
+			return -1;
+		}
+
+		/* Split data in a=1&b=xy&c=3&c=4 ... */
+		while (*data) {
+			const char *val = strchr(data, '=');
+			const char *next;
+			ptrdiff_t keylen, vallen;
+
+			if (!val) {
+				break;
+			}
+			keylen = val - data;
+
+			/* In every "field_found" callback we ask what to do with the
+			 * data ("field_storage"). This could be:
+			 * FORM_FIELD_STORAGE_SKIP (0) ... ignore the value of this field
+			 * FORM_FIELD_STORAGE_GET (1) ... read the data and call the get
+			 *                              callback function
+			 * FORM_FIELD_STORAGE_STORE (2) ... store the data in a file
+			 * FORM_FIELD_STORAGE_READ (3) ... let the user read the data
+			 *                               (for parsing long data on the fly)
+			 *                               (currently not implemented)
+			 * FORM_FIELD_STORAGE_ABORT (flag) ... stop parsing
+			 */
+			memset(path, 0, sizeof(path));
+			field_count++;
+			field_storage = url_encoded_field_found(conn,
+			                                        data,
+			                                        (size_t)keylen,
+			                                        NULL,
+			                                        0,
+			                                        path,
+			                                        sizeof(path) - 1,
+			                                        fdh);
+
+			val++;
+			next = strchr(val, '&');
+			if (next) {
+				vallen = next - val;
+				next++;
+			} else {
+				vallen = (ptrdiff_t)strlen(val);
+				next = val + vallen;
+			}
+
+			if (field_storage == FORM_FIELD_STORAGE_GET) {
+				/* Call callback */
+				url_encoded_field_get(
+				    conn, data, (size_t)keylen, val, (size_t)vallen, fdh);
+			}
+			if (field_storage == FORM_FIELD_STORAGE_STORE) {
+				/* Store the content to a file */
+				if (mg_fopen(conn, path, MG_FOPEN_MODE_WRITE, &fstore) == 0) {
+					fstore.access.fp = NULL;
+				}
+				file_size = 0;
+				if (fstore.access.fp != NULL) {
+					size_t n = (size_t)
+					    fwrite(val, 1, (size_t)vallen, fstore.access.fp);
+					if ((n != (size_t)vallen) || (ferror(fstore.access.fp))) {
+						mg_cry(conn,
+						       "%s: Cannot write file %s",
+						       __func__,
+						       path);
+						(void)mg_fclose(&fstore.access);
+						remove_bad_file(conn, path);
+					}
+					file_size += (int64_t)n;
+
+					if (fstore.access.fp) {
+						r = mg_fclose(&fstore.access);
+						if (r == 0) {
+							/* stored successfully */
+							field_stored(conn, path, file_size, fdh);
+						} else {
+							mg_cry(conn,
+							       "%s: Error saving file %s",
+							       __func__,
+							       path);
+							remove_bad_file(conn, path);
+						}
+						fstore.access.fp = NULL;
+					}
+
+				} else {
+					mg_cry(conn, "%s: Cannot create file %s", __func__, path);
+				}
+			}
+
+			/* if (field_storage == FORM_FIELD_STORAGE_READ) { */
+			/* The idea of "field_storage=read" is to let the API user read
+			 * data chunk by chunk and to some data processing on the fly.
+			 * This should avoid the need to store data in the server:
+			 * It should neither be stored in memory, like
+			 * "field_storage=get" does, nor in a file like
+			 * "field_storage=store".
+			 * However, for a "GET" request this does not make any much
+			 * sense, since the data is already stored in memory, as it is
+			 * part of the query string.
+			 */
+			/* } */
+
+			if ((field_storage & FORM_FIELD_STORAGE_ABORT)
+			    == FORM_FIELD_STORAGE_ABORT) {
+				/* Stop parsing the request */
+				break;
+			}
+
+			/* Proceed to next entry */
+			data = next;
+		}
+
+		return field_count;
+	}
+
+	content_type = mg_get_header(conn, "Content-Type");
+
+	if (!content_type
+	    || !mg_strcasecmp(content_type, "APPLICATION/X-WWW-FORM-URLENCODED")
+	    || !mg_strcasecmp(content_type, "APPLICATION/WWW-FORM-URLENCODED")) {
+		/* The form data is in the request body data, encoded in key/value
+		 * pairs. */
+		int all_data_read = 0;
+
+		/* Read body data and split it in keys and values.
+		 * The encoding is like in the "GET" case above: a=1&b&c=3&c=4.
+		 * Here we use "POST", and read the data from the request body.
+		 * The data read on the fly, so it is not required to buffer the
+		 * entire request in memory before processing it. */
+		for (;;) {
+			const char *val;
+			const char *next;
+			ptrdiff_t keylen, vallen;
+			ptrdiff_t used;
+			int end_of_key_value_pair_found = 0;
+			int get_block;
+
+			if ((size_t)buf_fill < (sizeof(buf) - 1)) {
+
+				size_t to_read = sizeof(buf) - 1 - (size_t)buf_fill;
+				r = mg_read(conn, buf + (size_t)buf_fill, to_read);
+				if (r < 0) {
+					/* read error */
+					return -1;
+				}
+				if (r != (int)to_read) {
+					/* TODO: Create a function to get "all_data_read" from
+					 * the conn object. All data is read if the Content-Length
+					 * has been reached, or if chunked encoding is used and
+					 * the end marker has been read, or if the connection has
+					 * been closed. */
+					all_data_read = 1;
+				}
+				buf_fill += r;
+				buf[buf_fill] = 0;
+				if (buf_fill < 1) {
+					break;
+				}
+			}
+
+			val = strchr(buf, '=');
+
+			if (!val) {
+				break;
+			}
+			keylen = val - buf;
+			val++;
+
+			/* Call callback */
+			memset(path, 0, sizeof(path));
+			field_count++;
+			field_storage = url_encoded_field_found(conn,
+			                                        buf,
+			                                        (size_t)keylen,
+			                                        NULL,
+			                                        0,
+			                                        path,
+			                                        sizeof(path) - 1,
+			                                        fdh);
+
+			if ((field_storage & FORM_FIELD_STORAGE_ABORT)
+			    == FORM_FIELD_STORAGE_ABORT) {
+				/* Stop parsing the request */
+				break;
+			}
+
+			if (field_storage == FORM_FIELD_STORAGE_STORE) {
+				if (mg_fopen(conn, path, MG_FOPEN_MODE_WRITE, &fstore) == 0) {
+					fstore.access.fp = NULL;
+				}
+				file_size = 0;
+				if (!fstore.access.fp) {
+					mg_cry(conn, "%s: Cannot create file %s", __func__, path);
+				}
+			}
+
+			get_block = 0;
+			/* Loop to read values larger than sizeof(buf)-keylen-2 */
+			do {
+				next = strchr(val, '&');
+				if (next) {
+					vallen = next - val;
+					next++;
+					end_of_key_value_pair_found = 1;
+				} else {
+					vallen = (ptrdiff_t)strlen(val);
+					next = val + vallen;
+				}
+
+				if (field_storage == FORM_FIELD_STORAGE_GET) {
+#if 0
+					if (!end_of_key_value_pair_found && !all_data_read) {
+						/* This callback will deliver partial contents */
+					}
+#else
+					(void)all_data_read; /* avoid warning */
+#endif
+
+					/* Call callback */
+					url_encoded_field_get(conn,
+					                      ((get_block > 0) ? NULL : buf),
+					                      ((get_block > 0) ? 0
+					                                       : (size_t)keylen),
+					                      val,
+					                      (size_t)vallen,
+					                      fdh);
+					get_block++;
+				}
+				if (fstore.access.fp) {
+					size_t n = (size_t)
+					    fwrite(val, 1, (size_t)vallen, fstore.access.fp);
+					if ((n != (size_t)vallen) || (ferror(fstore.access.fp))) {
+						mg_cry(conn,
+						       "%s: Cannot write file %s",
+						       __func__,
+						       path);
+						mg_fclose(&fstore.access);
+						remove_bad_file(conn, path);
+					}
+					file_size += (int64_t)n;
+				}
+
+				if (!end_of_key_value_pair_found) {
+					used = next - buf;
+					memmove(buf,
+					        buf + (size_t)used,
+					        sizeof(buf) - (size_t)used);
+					buf_fill -= (int)used;
+					if ((size_t)buf_fill < (sizeof(buf) - 1)) {
+
+						size_t to_read = sizeof(buf) - 1 - (size_t)buf_fill;
+						r = mg_read(conn, buf + (size_t)buf_fill, to_read);
+						if (r < 0) {
+							/* read error */
+							return -1;
+						}
+						if (r != (int)to_read) {
+							/* TODO: Create a function to get "all_data_read"
+							 * from the conn object. All data is read if the
+							 * Content-Length has been reached, or if chunked
+							 * encoding is used and the end marker has been
+							 * read, or if the connection has been closed. */
+							all_data_read = 1;
+						}
+						buf_fill += r;
+						buf[buf_fill] = 0;
+						if (buf_fill < 1) {
+							break;
+						}
+						val = buf;
+					}
+				}
+
+			} while (!end_of_key_value_pair_found);
+
+			if (fstore.access.fp) {
+				r = mg_fclose(&fstore.access);
+				if (r == 0) {
+					/* stored successfully */
+					field_stored(conn, path, file_size, fdh);
+				} else {
+					mg_cry(conn, "%s: Error saving file %s", __func__, path);
+					remove_bad_file(conn, path);
+				}
+				fstore.access.fp = NULL;
+			}
+
+			/* Proceed to next entry */
+			used = next - buf;
+			memmove(buf, buf + (size_t)used, sizeof(buf) - (size_t)used);
+			buf_fill -= (int)used;
+		}
+
+		return field_count;
+	}
+
+	if (!mg_strncasecmp(content_type, "MULTIPART/FORM-DATA;", 20)) {
+		/* The form data is in the request body data, encoded as multipart
+		 * content (see https://www.ietf.org/rfc/rfc1867.txt,
+		 * https://www.ietf.org/rfc/rfc2388.txt). */
+		const char *boundary;
+		size_t bl;
+		ptrdiff_t used;
+		struct mg_request_info part_header;
+		char *hbuf, *hend, *fbeg, *fend, *nbeg, *nend;
+		const char *content_disp;
+		const char *next;
+
+		memset(&part_header, 0, sizeof(part_header));
+
+		/* Skip all spaces between MULTIPART/FORM-DATA; and BOUNDARY= */
+		bl = 20;
+		while (content_type[bl] == ' ') {
+			bl++;
+		}
+
+		/* There has to be a BOUNDARY definition in the Content-Type header */
+		if (mg_strncasecmp(content_type + bl, "BOUNDARY=", 9)) {
+			/* Malformed request */
+			return -1;
+		}
+
+		boundary = content_type + bl + 9;
+		bl = strlen(boundary);
+
+		if (bl + 800 > sizeof(buf)) {
+			/* Sanity check:  The algorithm can not work if bl >= sizeof(buf),
+			 * and it will not work effectively, if the buf is only a few byte
+			 * larger than bl, or it buf can not hold the multipart header
+			 * plus the boundary.
+			 * Check some reasonable number here, that should be fulfilled by
+			 * any reasonable request from every browser. If it is not
+			 * fulfilled, it might be a hand-made request, intended to
+			 * interfere with the algorithm. */
+			return -1;
+		}
+
+		for (;;) {
+			size_t towrite, n;
+			int get_block;
+
+			r = mg_read(conn,
+			            buf + (size_t)buf_fill,
+			            sizeof(buf) - 1 - (size_t)buf_fill);
+			if (r < 0) {
+				/* read error */
+				return -1;
+			}
+			buf_fill += r;
+			buf[buf_fill] = 0;
+			if (buf_fill < 1) {
+				/* No data */
+				return -1;
+			}
+
+			if (buf[0] != '-' || buf[1] != '-') {
+				/* Malformed request */
+				return -1;
+			}
+			if (strncmp(buf + 2, boundary, bl)) {
+				/* Malformed request */
+				return -1;
+			}
+			if (buf[bl + 2] != '\r' || buf[bl + 3] != '\n') {
+				/* Every part must end with \r\n, if there is another part.
+				 * The end of the request has an extra -- */
+				if (((size_t)buf_fill != (size_t)(bl + 6))
+				    || (strncmp(buf + bl + 2, "--\r\n", 4))) {
+					/* Malformed request */
+					return -1;
+				}
+				/* End of the request */
+				break;
+			}
+
+			/* Next, we need to get the part header: Read until \r\n\r\n */
+			hbuf = buf + bl + 4;
+			hend = strstr(hbuf, "\r\n\r\n");
+			if (!hend) {
+				/* Malformed request */
+				return -1;
+			}
+
+			parse_http_headers(&hbuf, &part_header);
+			if ((hend + 2) != hbuf) {
+				/* Malformed request */
+				return -1;
+			}
+
+			/* Skip \r\n\r\n */
+			hend += 4;
+
+			/* According to the RFC, every part has to have a header field like:
+			 * Content-Disposition: form-data; name="..." */
+			content_disp = get_header(&part_header, "Content-Disposition");
+			if (!content_disp) {
+				/* Malformed request */
+				return -1;
+			}
+
+			/* Get the mandatory name="..." part of the Content-Disposition
+			 * header. */
+			nbeg = strstr(content_disp, "name=\"");
+			if (!nbeg) {
+				/* Malformed request */
+				return -1;
+			}
+			nbeg += 6;
+			nend = strchr(nbeg, '\"');
+			if (!nend) {
+				/* Malformed request */
+				return -1;
+			}
+
+			/* Get the optional filename="..." part of the Content-Disposition
+			 * header. */
+			fbeg = strstr(content_disp, "filename=\"");
+			if (fbeg) {
+				fbeg += 10;
+				fend = strchr(fbeg, '\"');
+				if (!fend) {
+					/* Malformed request (the filename field is optional, but if
+					 * it exists, it needs to be terminated correctly). */
+					return -1;
+				}
+
+				/* TODO: check Content-Type */
+				/* Content-Type: application/octet-stream */
+
+			} else {
+				fend = fbeg;
+			}
+
+			memset(path, 0, sizeof(path));
+			field_count++;
+			field_storage = url_encoded_field_found(conn,
+			                                        nbeg,
+			                                        (size_t)(nend - nbeg),
+			                                        fbeg,
+			                                        (size_t)(fend - fbeg),
+			                                        path,
+			                                        sizeof(path) - 1,
+			                                        fdh);
+
+			/* If the boundary is already in the buffer, get the address,
+			 * otherwise next will be NULL. */
+			next = search_boundary(hbuf,
+			                       (size_t)((buf - hbuf) + buf_fill),
+			                       boundary,
+			                       bl);
+
+			if (field_storage == FORM_FIELD_STORAGE_STORE) {
+				/* Store the content to a file */
+				if (mg_fopen(conn, path, MG_FOPEN_MODE_WRITE, &fstore) == 0) {
+					fstore.access.fp = NULL;
+				}
+				file_size = 0;
+
+				if (!fstore.access.fp) {
+					mg_cry(conn, "%s: Cannot create file %s", __func__, path);
+				}
+			}
+
+			get_block = 0;
+			while (!next) {
+				/* Set "towrite" to the number of bytes available
+				 * in the buffer */
+				towrite = (size_t)(buf - hend + buf_fill);
+				/* Subtract the boundary length, to deal with
+				 * cases the boundary is only partially stored
+				 * in the buffer. */
+				towrite -= bl + 4;
+
+				if (field_storage == FORM_FIELD_STORAGE_GET) {
+					unencoded_field_get(conn,
+					                    ((get_block > 0) ? NULL : nbeg),
+					                    ((get_block > 0)
+					                         ? 0
+					                         : (size_t)(nend - nbeg)),
+					                    hend,
+					                    towrite,
+					                    fdh);
+					get_block++;
+				}
+
+				if (field_storage == FORM_FIELD_STORAGE_STORE) {
+					if (fstore.access.fp) {
+
+						/* Store the content of the buffer. */
+						n = (size_t)fwrite(hend, 1, towrite, fstore.access.fp);
+						if ((n != towrite) || (ferror(fstore.access.fp))) {
+							mg_cry(conn,
+							       "%s: Cannot write file %s",
+							       __func__,
+							       path);
+							mg_fclose(&fstore.access);
+							remove_bad_file(conn, path);
+						}
+						file_size += (int64_t)n;
+					}
+				}
+
+				memmove(buf, hend + towrite, bl + 4);
+				buf_fill = (int)(bl + 4);
+				hend = buf;
+
+				/* Read new data */
+				r = mg_read(conn,
+				            buf + (size_t)buf_fill,
+				            sizeof(buf) - 1 - (size_t)buf_fill);
+				if (r < 0) {
+					/* read error */
+					return -1;
+				}
+				buf_fill += r;
+				buf[buf_fill] = 0;
+				if (buf_fill < 1) {
+					/* No data */
+					return -1;
+				}
+
+				/* Find boundary */
+				next = search_boundary(buf, (size_t)buf_fill, boundary, bl);
+			}
+
+			towrite = (size_t)(next - hend);
+
+			if (field_storage == FORM_FIELD_STORAGE_GET) {
+				/* Call callback */
+				unencoded_field_get(conn,
+				                    ((get_block > 0) ? NULL : nbeg),
+				                    ((get_block > 0) ? 0
+				                                     : (size_t)(nend - nbeg)),
+				                    hend,
+				                    towrite,
+				                    fdh);
+			}
+
+			if (field_storage == FORM_FIELD_STORAGE_STORE) {
+
+				if (fstore.access.fp) {
+					n = (size_t)fwrite(hend, 1, towrite, fstore.access.fp);
+					if ((n != towrite) || (ferror(fstore.access.fp))) {
+						mg_cry(conn,
+						       "%s: Cannot write file %s",
+						       __func__,
+						       path);
+						mg_fclose(&fstore.access);
+						remove_bad_file(conn, path);
+					}
+					file_size += (int64_t)n;
+				}
+			}
+
+			if (field_storage == FORM_FIELD_STORAGE_STORE) {
+
+				if (fstore.access.fp) {
+					r = mg_fclose(&fstore.access);
+					if (r == 0) {
+						/* stored successfully */
+						field_stored(conn, path, file_size, fdh);
+					} else {
+						mg_cry(conn,
+						       "%s: Error saving file %s",
+						       __func__,
+						       path);
+						remove_bad_file(conn, path);
+					}
+					fstore.access.fp = NULL;
+				}
+			}
+
+			if ((field_storage & FORM_FIELD_STORAGE_ABORT)
+			    == FORM_FIELD_STORAGE_ABORT) {
+				/* Stop parsing the request */
+				break;
+			}
+
+			/* Remove from the buffer */
+			used = next - buf + 2;
+			memmove(buf, buf + (size_t)used, sizeof(buf) - (size_t)used);
+			buf_fill -= (int)used;
+		}
+
+		/* All parts handled */
+		return field_count;
+	}
+
+	/* Unknown Content-Type */
+	return -1;
+}


[36/51] [partial] nifi-minifi-cpp git commit: MINIFI-183 Added civet 1.9.1 sources Added onScheduled hook Added initial two-way TLS-enabled ListenHTTP implementation

Posted by al...@apache.org.
http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/main.c
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/main.c b/thirdparty/civetweb-1.9.1/src/main.c
new file mode 100644
index 0000000..6299066
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/main.c
@@ -0,0 +1,2633 @@
+/* Copyright (c) 2013-2017 the Civetweb developers
+ * Copyright (c) 2004-2013 Sergey Lyubka
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+*/
+
+#if defined(_WIN32)
+
+#ifndef _CRT_SECURE_NO_WARNINGS
+#define _CRT_SECURE_NO_WARNINGS /* Disable deprecation warning in VS2005 */
+#endif
+#ifndef _CRT_SECURE_NO_DEPRECATE
+#define _CRT_SECURE_NO_DEPRECATE
+#endif
+#ifdef WIN32_LEAN_AND_MEAN
+#undef WIN32_LEAN_AND_MEAN /* Required for some functions (tray icons, ...) */
+#endif
+
+#else
+
+#define _XOPEN_SOURCE 600 /* For PATH_MAX on linux */
+/* This should also be sufficient for "realpath", according to
+ * http://man7.org/linux/man-pages/man3/realpath.3.html, but in
+ * reality it does not seem to work. */
+/* In case this causes a problem, disable the warning:
+ * #pragma GCC diagnostic ignored "-Wimplicit-function-declaration"
+ * #pragma clang diagnostic ignored "-Wimplicit-function-declaration"
+ */
+#endif
+
+#ifndef IGNORE_UNUSED_RESULT
+#define IGNORE_UNUSED_RESULT(a) ((void)((a) && 1))
+#endif
+
+#if defined(__cplusplus) && (__cplusplus >= 201103L)
+#define NO_RETURN [[noreturn]]
+#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
+#define NO_RETURN _Noreturn
+#else
+#define NO_RETURN
+#endif
+
+/* Use same defines as in civetweb.c before including system headers. */
+#ifndef _LARGEFILE_SOURCE
+#define _LARGEFILE_SOURCE /* For fseeko(), ftello() */
+#endif
+#ifndef _FILE_OFFSET_BITS
+#define _FILE_OFFSET_BITS 64 /* Use 64-bit file offsets by default */
+#endif
+#ifndef __STDC_FORMAT_MACROS
+#define __STDC_FORMAT_MACROS /* <inttypes.h> wants this for C++ */
+#endif
+#ifndef __STDC_LIMIT_MACROS
+#define __STDC_LIMIT_MACROS /* C++ wants that for INT64_MAX */
+#endif
+
+#include <string.h>
+#include <errno.h>
+#include <sys/stat.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <limits.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <stddef.h>
+#include <stdarg.h>
+#include <ctype.h>
+#include <assert.h>
+
+#include "civetweb.h"
+
+#define printf                                                                 \
+	DO_NOT_USE_THIS_FUNCTION__USE_fprintf /* Required for unit testing */
+
+#if defined(_WIN32)                                                            \
+    && !defined(__SYMBIAN32__) /* WINDOWS / UNIX include block */
+#ifndef _WIN32_WINNT
+#define _WIN32_WINNT 0x0501 /* for tdm-gcc so we can use getconsolewindow */
+#endif
+#undef UNICODE
+#include <windows.h>
+#include <winsvc.h>
+#include <shlobj.h>
+#include <io.h>
+
+#define getcwd(a, b) (_getcwd(a, b))
+#if !defined(__MINGW32__)
+extern char *_getcwd(char *buf, size_t size);
+#endif
+
+#ifndef PATH_MAX
+#define PATH_MAX MAX_PATH
+#endif
+
+#ifndef S_ISDIR
+#define S_ISDIR(x) ((x)&_S_IFDIR)
+#endif
+
+#define DIRSEP '\\'
+#define snprintf _snprintf
+#define vsnprintf _vsnprintf
+#define sleep(x) (Sleep((x)*1000))
+#define WINCDECL __cdecl
+#define abs_path(rel, abs, abs_size) (_fullpath((abs), (rel), (abs_size)))
+
+#else /* defined(_WIN32) && !defined(__SYMBIAN32__) - WINDOWS / UNIX include   \
+         block */
+
+#include <unistd.h>
+#include <sys/utsname.h>
+#include <sys/wait.h>
+
+#define DIRSEP '/'
+#define WINCDECL
+#define abs_path(rel, abs, abs_size) (realpath((rel), (abs)))
+
+#endif /* defined(_WIN32) && !defined(__SYMBIAN32__) - WINDOWS / UNIX include  \
+          block */
+
+#ifndef PATH_MAX
+#define PATH_MAX (1024)
+#endif
+
+#define MAX_OPTIONS (50)
+#define MAX_CONF_FILE_LINE_SIZE (8 * 1024)
+
+struct tuser_data {
+	char *first_message;
+};
+
+
+static int g_exit_flag = 0;         /* Main loop should exit */
+static char g_server_base_name[40]; /* Set by init_server_name() */
+static const char *g_server_name;   /* Set by init_server_name() */
+static const char *g_icon_name;     /* Set by init_server_name() */
+static const char *g_website;       /* Set by init_server_name() */
+static char *g_system_info;         /* Set by init_system_info() */
+static char g_config_file_name[PATH_MAX] =
+    "";                          /* Set by process_command_line_arguments() */
+static struct mg_context *g_ctx; /* Set by start_civetweb() */
+static struct tuser_data
+    g_user_data; /* Passed to mg_start() by start_civetweb() */
+
+#if !defined(CONFIG_FILE)
+#define CONFIG_FILE "civetweb.conf"
+#endif /* !CONFIG_FILE */
+
+#if !defined(PASSWORDS_FILE_NAME)
+#define PASSWORDS_FILE_NAME ".htpasswd"
+#endif
+
+/* backup config file */
+#if !defined(CONFIG_FILE2) && defined(__linux__)
+#define CONFIG_FILE2 "/usr/local/etc/civetweb.conf"
+#endif
+
+enum { OPTION_TITLE, OPTION_ICON, OPTION_WEBPAGE, NUM_MAIN_OPTIONS };
+
+static struct mg_option main_config_options[] = {
+    {"title", CONFIG_TYPE_STRING, NULL},
+    {"icon", CONFIG_TYPE_STRING, NULL},
+	{"website", CONFIG_TYPE_STRING, NULL },
+    {NULL, CONFIG_TYPE_UNKNOWN, NULL}};
+
+
+static void WINCDECL
+signal_handler(int sig_num)
+{
+	g_exit_flag = sig_num;
+}
+
+
+static NO_RETURN void
+die(const char *fmt, ...)
+{
+	va_list ap;
+	char msg[200] = "";
+
+	va_start(ap, fmt);
+	(void)vsnprintf(msg, sizeof(msg) - 1, fmt, ap);
+	msg[sizeof(msg) - 1] = 0;
+	va_end(ap);
+
+#if defined(_WIN32)
+	MessageBox(NULL, msg, "Error", MB_OK);
+#else
+	fprintf(stderr, "%s\n", msg);
+#endif
+
+	exit(EXIT_FAILURE);
+}
+
+
+#ifdef WIN32
+static int MakeConsole(void);
+#endif
+
+
+static void
+show_server_name(void)
+{
+#ifdef WIN32
+	(void)MakeConsole();
+#endif
+
+	fprintf(stderr, "CivetWeb v%s, built on %s\n", mg_version(), __DATE__);
+}
+
+
+static NO_RETURN void
+show_usage_and_exit(const char *exeName)
+{
+	const struct mg_option *options;
+	int i;
+
+	if (exeName == 0 || *exeName == 0) {
+		exeName = "civetweb";
+	}
+
+	show_server_name();
+
+	fprintf(stderr, "\nUsage:\n");
+	fprintf(stderr, "  Start server with a set of options:\n");
+	fprintf(stderr, "    %s [config_file]\n", exeName);
+	fprintf(stderr, "    %s [-option value ...]\n", exeName);
+	fprintf(stderr, "  Show system information:\n");
+	fprintf(stderr, "    %s -I\n", exeName);
+	fprintf(stderr, "  Add user/change password:\n");
+	fprintf(stderr,
+	        "    %s -A <htpasswd_file> <realm> <user> <passwd>\n",
+	        exeName);
+	fprintf(stderr, "  Remove user:\n");
+	fprintf(stderr, "    %s -R <htpasswd_file> <realm> <user>\n", exeName);
+	fprintf(stderr, "\nOPTIONS:\n");
+
+	options = mg_get_valid_options();
+	for (i = 0; options[i].name != NULL; i++) {
+		fprintf(stderr,
+		        "  -%s %s\n",
+		        options[i].name,
+		        ((options[i].default_value == NULL)
+		             ? "<empty>"
+		             : options[i].default_value));
+	}
+
+	options = main_config_options;
+	for (i = 0; options[i].name != NULL; i++) {
+		fprintf(stderr,
+		        "  -%s %s\n",
+		        options[i].name,
+		        ((options[i].default_value == NULL)
+		             ? "<empty>"
+		             : options[i].default_value));
+	}
+
+	exit(EXIT_FAILURE);
+}
+
+
+#if defined(_WIN32) || defined(USE_COCOA)
+static const char *config_file_top_comment =
+    "# Civetweb web server configuration file.\n"
+    "# For detailed description of every option, visit\n"
+    "# https://github.com/civetweb/civetweb/blob/master/docs/UserManual.md\n"
+    "# Lines starting with '#' and empty lines are ignored.\n"
+    "# To make a change, remove leading '#', modify option's value,\n"
+    "# save this file and then restart Civetweb.\n\n";
+
+static const char *
+get_url_to_first_open_port(const struct mg_context *ctx)
+{
+	static char url[100];
+	const char *open_ports = mg_get_option(ctx, "listening_ports");
+	int a, b, c, d, port, n;
+
+	if (sscanf(open_ports, "%d.%d.%d.%d:%d%n", &a, &b, &c, &d, &port, &n)
+	    == 5) {
+		snprintf(url,
+		         sizeof(url),
+		         "%s://%d.%d.%d.%d:%d",
+		         open_ports[n] == 's' ? "https" : "http",
+		         a,
+		         b,
+		         c,
+		         d,
+		         port);
+	} else if (sscanf(open_ports, "%d%n", &port, &n) == 1) {
+		snprintf(url,
+		         sizeof(url),
+		         "%s://localhost:%d",
+		         open_ports[n] == 's' ? "https" : "http",
+		         port);
+	} else {
+		snprintf(url, sizeof(url), "%s", "http://localhost:8080");
+	}
+
+	return url;
+}
+
+
+#ifdef ENABLE_CREATE_CONFIG_FILE
+static void
+create_config_file(const struct mg_context *ctx, const char *path)
+{
+	const struct mg_option *options;
+	const char *value;
+	FILE *fp;
+	int i;
+
+	/* Create config file if it is not present yet */
+	if ((fp = fopen(path, "r")) != NULL) {
+		fclose(fp);
+	} else if ((fp = fopen(path, "a+")) != NULL) {
+		fprintf(fp, "%s", config_file_top_comment);
+		options = mg_get_valid_options();
+		for (i = 0; options[i].name != NULL; i++) {
+			value = mg_get_option(ctx, options[i].name);
+			fprintf(fp,
+			        "# %s %s\n",
+			        options[i].name,
+			        value ? value : "<value>");
+		}
+		fclose(fp);
+	}
+}
+#endif
+#endif
+
+
+static char *
+sdup(const char *str)
+{
+	size_t len;
+	char *p;
+
+	len = strlen(str) + 1;
+	if ((p = (char *)malloc(len)) != NULL) {
+		memcpy(p, str, len);
+	}
+	return p;
+}
+
+
+static const char *
+get_option(char **options, const char *option_name)
+{
+	int i = 0;
+	const char *opt_value = NULL;
+
+	/* TODO (low, api makeover): options should be an array of key-value-pairs,
+	 * like
+	 *     struct {const char * key, const char * value} options[]
+	 * but it currently is an array with
+	 *     options[2*i] = key, options[2*i + 1] = value
+	 * (probably with a MG_LEGACY_INTERFACE definition)
+	 */
+	while (options[2 * i] != NULL) {
+		if (strcmp(options[2 * i], option_name) == 0) {
+			opt_value = options[2 * i + 1];
+			break;
+		}
+		i++;
+	}
+	return opt_value;
+}
+
+
+static int
+set_option(char **options, const char *name, const char *value)
+{
+	int i, type;
+	const struct mg_option *default_options = mg_get_valid_options();
+
+	for (i = 0; main_config_options[i].name != NULL; i++) {
+		if (0 == strcmp(name, main_config_options[i].name)) {
+			/* This option is evaluated by main.c, not civetweb.c - just skip it
+			 * and return OK */
+			return 1;
+		}
+	}
+
+	type = CONFIG_TYPE_UNKNOWN;
+	for (i = 0; default_options[i].name != NULL; i++) {
+		if (!strcmp(default_options[i].name, name)) {
+			type = default_options[i].type;
+		}
+	}
+	switch (type) {
+	case CONFIG_TYPE_UNKNOWN:
+		/* unknown option */
+		return 0;
+	case CONFIG_TYPE_NUMBER:
+		/* integer number > 0, e.g. number of threads */
+		if (atol(value) < 0) {
+			/* invalid number */
+			return 0;
+		}
+		break;
+	case CONFIG_TYPE_STRING:
+		/* any text */
+		break;
+	case CONFIG_TYPE_BOOLEAN:
+		/* boolean value, yes or no */
+		if ((0 != strcmp(value, "yes")) && (0 != strcmp(value, "no"))) {
+			/* invalid boolean */
+			return 0;
+		}
+		break;
+	case CONFIG_TYPE_FILE:
+	case CONFIG_TYPE_DIRECTORY:
+		/* TODO (low): check this option when it is set, instead of calling
+		 * verify_existence later */
+		break;
+	case CONFIG_TYPE_EXT_PATTERN:
+		/* list of file extentions */
+		break;
+	default:
+		die("Unknown option type - option %s", name);
+	}
+
+	for (i = 0; i < MAX_OPTIONS; i++) {
+		if (options[2 * i] == NULL) {
+			options[2 * i] = sdup(name);
+			options[2 * i + 1] = sdup(value);
+			options[2 * i + 2] = NULL;
+			break;
+		} else if (!strcmp(options[2 * i], name)) {
+			free(options[2 * i + 1]);
+			options[2 * i + 1] = sdup(value);
+			break;
+		}
+	}
+
+	if (i == MAX_OPTIONS) {
+		die("Too many options specified");
+	}
+
+	if (options[2 * i] == NULL || options[2 * i + 1] == NULL) {
+		die("Out of memory");
+	}
+
+	/* option set correctly */
+	return 1;
+}
+
+
+static int
+read_config_file(const char *config_file, char **options)
+{
+	char line[MAX_CONF_FILE_LINE_SIZE], *p;
+	FILE *fp = NULL;
+	size_t i, j, line_no = 0;
+
+	/* Open the config file */
+	fp = fopen(config_file, "r");
+	if (fp == NULL) {
+		/* Failed to open the file. Keep errno for the caller. */
+		return 0;
+	}
+
+	/* Load config file settings first */
+	if (fp != NULL) {
+		fprintf(stderr, "Loading config file %s\n", config_file);
+
+		/* Loop over the lines in config file */
+		while (fgets(line, sizeof(line), fp) != NULL) {
+
+			if (!line_no && !memcmp(line, "\xEF\xBB\xBF", 3)) {
+				/* strip UTF-8 BOM */
+				p = line + 3;
+			} else {
+				p = line;
+			}
+			line_no++;
+
+			/* Ignore empty lines and comments */
+			for (i = 0; isspace(*(unsigned char *)&line[i]);)
+				i++;
+			if (p[i] == '#' || p[i] == '\0') {
+				continue;
+			}
+
+			/* Skip spaces, \r and \n at the end of the line */
+			for (j = strlen(line) - 1;
+			     isspace(*(unsigned char *)&line[j])
+			         || iscntrl(*(unsigned char *)&line[j]);)
+				line[j--] = 0;
+
+			/* Find the space character between option name and value */
+			for (j = i; !isspace(*(unsigned char *)&line[j]) && (line[j] != 0);)
+				j++;
+
+			/* Terminate the string - then the string at (line+i) contains the
+			 * option name */
+			line[j] = 0;
+			j++;
+
+			/* Trim additional spaces between option name and value - then
+			 * (line+j) contains the option value */
+			while (isspace(line[j]))
+				j++;
+
+			/* Set option */
+			if (!set_option(options, line + i, line + j)) {
+				fprintf(stderr,
+				        "%s: line %d is invalid, ignoring it:\n %s",
+				        config_file,
+				        (int)line_no,
+				        p);
+			}
+		}
+
+		(void)fclose(fp);
+	}
+	return 1;
+}
+
+
+static void
+process_command_line_arguments(int argc, char *argv[], char **options)
+{
+	char *p;
+	size_t i, cmd_line_opts_start = 1;
+#ifdef CONFIG_FILE2
+	FILE *fp = NULL;
+#endif
+
+	/* Should we use a config file ? */
+	if ((argc > 1) && (argv[1] != NULL) && (argv[1][0] != '-')
+	    && (argv[1][0] != 0)) {
+		/* The first command line parameter is a config file name. */
+		snprintf(g_config_file_name,
+		         sizeof(g_config_file_name) - 1,
+		         "%s",
+		         argv[1]);
+		cmd_line_opts_start = 2;
+	} else if ((p = strrchr(argv[0], DIRSEP)) == NULL) {
+		/* No config file set. No path in arg[0] found.
+		 * Use default file name in the current path. */
+		snprintf(g_config_file_name,
+		         sizeof(g_config_file_name) - 1,
+		         "%s",
+		         CONFIG_FILE);
+	} else {
+		/* No config file set. Path to exe found in arg[0].
+		 * Use default file name next to the executable. */
+		snprintf(g_config_file_name,
+		         sizeof(g_config_file_name) - 1,
+		         "%.*s%c%s",
+		         (int)(p - argv[0]),
+		         argv[0],
+		         DIRSEP,
+		         CONFIG_FILE);
+	}
+	g_config_file_name[sizeof(g_config_file_name) - 1] = 0;
+
+#ifdef CONFIG_FILE2
+	fp = fopen(g_config_file_name, "r");
+
+	/* try alternate config file */
+	if (fp == NULL) {
+		fp = fopen(CONFIG_FILE2, "r");
+		if (fp != NULL) {
+			strcpy(g_config_file_name, CONFIG_FILE2);
+		}
+	}
+	if (fp != NULL) {
+		fclose(fp);
+	}
+#endif
+
+	/* read all configurations from a config file */
+	if (0 == read_config_file(g_config_file_name, options)) {
+		if (cmd_line_opts_start == 2) {
+			/* If config file was set in command line and open failed, die. */
+			/* Errno will still hold the error from fopen. */
+			die("Cannot open config file %s: %s",
+			    g_config_file_name,
+			    strerror(errno));
+		}
+		/* Otherwise: CivetWeb can work without a config file */
+	}
+
+	/* If we're under MacOS and started by launchd, then the second
+	   argument is process serial number, -psn_.....
+	   In this case, don't process arguments at all. */
+	if (argv[1] == NULL || memcmp(argv[1], "-psn_", 5) != 0) {
+		/* Handle command line flags.
+		   They override config file and default settings. */
+		for (i = cmd_line_opts_start; argv[i] != NULL; i += 2) {
+			if (argv[i][0] != '-' || argv[i + 1] == NULL) {
+				show_usage_and_exit(argv[0]);
+			}
+			if (!set_option(options, &argv[i][1], argv[i + 1])) {
+				fprintf(
+				    stderr,
+				    "command line option is invalid, ignoring it:\n %s %s\n",
+				    argv[i],
+				    argv[i + 1]);
+			}
+		}
+	}
+}
+
+
+static void
+init_server_name(int argc, const char *argv[])
+{
+	int i;
+	assert(sizeof(main_config_options) / sizeof(main_config_options[0])
+	       == NUM_MAIN_OPTIONS + 1);
+	assert((strlen(mg_version()) + 12) < sizeof(g_server_base_name));
+	snprintf(g_server_base_name,
+	         sizeof(g_server_base_name),
+	         "CivetWeb V%s",
+	         mg_version());
+
+	g_server_name = g_server_base_name;
+	for (i = 0; i < argc - 1; i++) {
+		if ((argv[i][0] == '-')
+		    && (0 == strcmp(argv[i] + 1,
+		                    main_config_options[OPTION_TITLE].name))) {
+			g_server_name = (const char *)(argv[i + 1]);
+		}
+	}
+
+	g_icon_name = NULL;
+	for (i = 0; i < argc - 1; i++) {
+		if ((argv[i][0] == '-')
+		    && (0 == strcmp(argv[i] + 1,
+		                    main_config_options[OPTION_ICON].name))) {
+			g_icon_name = (const char *)(argv[i + 1]);
+		}
+	}
+
+	g_website = "http://civetweb.github.io/civetweb/";
+	for (i = 0; i < argc - 1; i++) {
+		if ((argv[i][0] == '-')
+			&& (0 == strcmp(argv[i] + 1,
+				main_config_options[OPTION_WEBPAGE].name))) {
+			g_website = (const char *)(argv[i + 1]);
+		}
+	}
+
+}
+
+
+static void
+init_system_info(void)
+{
+	int len = mg_get_system_info(NULL, 0);
+	if (len > 0) {
+		g_system_info = (char *)malloc((unsigned)len + 1);
+		(void)mg_get_system_info(g_system_info, len + 1);
+	} else {
+		g_system_info = sdup("Not available");
+	}
+}
+
+
+static void
+free_system_info(void)
+{
+	free(g_system_info);
+}
+
+
+static int
+log_message(const struct mg_connection *conn, const char *message)
+{
+	const struct mg_context *ctx = mg_get_context(conn);
+	struct tuser_data *ud = (struct tuser_data *)mg_get_user_data(ctx);
+
+	fprintf(stderr, "%s\n", message);
+
+	if (ud->first_message == NULL) {
+		ud->first_message = sdup(message);
+	}
+
+	return 0;
+}
+
+
+static int
+is_path_absolute(const char *path)
+{
+#ifdef _WIN32
+	return path != NULL
+	       && ((path[0] == '\\' && path[1] == '\\') || /* UNC path, e.g.
+	                                                      \\server\dir */
+	           (isalpha(path[0]) && path[1] == ':'
+	            && path[2] == '\\')); /* E.g. X:\dir */
+#else
+	return path != NULL && path[0] == '/';
+#endif
+}
+
+
+static void
+verify_existence(char **options, const char *option_name, int must_be_dir)
+{
+	struct stat st;
+	const char *path = get_option(options, option_name);
+
+#ifdef _WIN32
+	wchar_t wbuf[1024];
+	char mbbuf[1024];
+	int len;
+
+	if (path) {
+		memset(wbuf, 0, sizeof(wbuf));
+		memset(mbbuf, 0, sizeof(mbbuf));
+		len = MultiByteToWideChar(CP_UTF8,
+		                          0,
+		                          path,
+		                          -1,
+		                          wbuf,
+		                          (int)sizeof(wbuf) / sizeof(wbuf[0]) - 1);
+		wcstombs(mbbuf, wbuf, sizeof(mbbuf) - 1);
+		path = mbbuf;
+		(void)len;
+	}
+#endif
+
+	if (path != NULL && (stat(path, &st) != 0
+	                     || ((S_ISDIR(st.st_mode) ? 1 : 0) != must_be_dir))) {
+		die("Invalid path for %s: [%s]: (%s). Make sure that path is either "
+		    "absolute, or it is relative to civetweb executable.",
+		    option_name,
+		    path,
+		    strerror(errno));
+	}
+}
+
+
+static void
+set_absolute_path(char *options[],
+                  const char *option_name,
+                  const char *path_to_civetweb_exe)
+{
+	char path[PATH_MAX] = "", absolute[PATH_MAX] = "";
+	const char *option_value;
+	const char *p;
+
+	/* Check whether option is already set */
+	option_value = get_option(options, option_name);
+
+	/* If option is already set and it is an absolute path,
+	   leave it as it is -- it's already absolute. */
+	if (option_value != NULL && !is_path_absolute(option_value)) {
+		/* Not absolute. Use the directory where civetweb executable lives
+		   be the relative directory for everything.
+		   Extract civetweb executable directory into path. */
+		if ((p = strrchr(path_to_civetweb_exe, DIRSEP)) == NULL) {
+			IGNORE_UNUSED_RESULT(getcwd(path, sizeof(path)));
+		} else {
+			snprintf(path,
+			         sizeof(path) - 1,
+			         "%.*s",
+			         (int)(p - path_to_civetweb_exe),
+			         path_to_civetweb_exe);
+			path[sizeof(path) - 1] = 0;
+		}
+
+		strncat(path, "/", sizeof(path) - strlen(path) - 1);
+		strncat(path, option_value, sizeof(path) - strlen(path) - 1);
+
+		/* Absolutize the path, and set the option */
+		IGNORE_UNUSED_RESULT(abs_path(path, absolute, sizeof(absolute)));
+		set_option(options, option_name, absolute);
+	}
+}
+
+
+#ifdef USE_LUA
+
+#include "civetweb_private_lua.h"
+
+#endif
+
+
+#ifdef USE_DUKTAPE
+
+#include "duktape.h"
+
+static int
+run_duktape(const char *file_name)
+{
+	duk_context *ctx = NULL;
+
+	ctx = duk_create_heap_default();
+	if (!ctx) {
+		fprintf(stderr, "Failed to create a Duktape heap.\n");
+		goto finished;
+	}
+
+	if (duk_peval_file(ctx, file_name) != 0) {
+		fprintf(stderr, "%s\n", duk_safe_to_string(ctx, -1));
+		goto finished;
+	}
+	duk_pop(ctx); /* ignore result */
+
+finished:
+	duk_destroy_heap(ctx);
+
+	return 0;
+}
+#endif
+
+
+#if defined(__MINGW32__) || defined(__MINGW64__)
+/* For __MINGW32/64_MAJOR/MINOR_VERSION define */
+#include <_mingw.h>
+#endif
+
+
+static void
+start_civetweb(int argc, char *argv[])
+{
+	struct mg_callbacks callbacks;
+	char *options[2 * MAX_OPTIONS + 1];
+	int i;
+
+	/* Start option -I:
+	 * Show system information and exit
+	 * This is very useful for diagnosis. */
+	if (argc > 1 && !strcmp(argv[1], "-I")) {
+
+#ifdef WIN32
+		(void)MakeConsole();
+#endif
+		fprintf(stdout,
+		        "\n%s (%s)\n%s\n",
+		        g_server_base_name,
+		        g_server_name,
+		        g_system_info);
+
+		exit(EXIT_SUCCESS);
+	}
+
+	/* Edit passwords file: Add user or change password, if -A option is
+	 * specified */
+	if (argc > 1 && !strcmp(argv[1], "-A")) {
+		if (argc != 6) {
+			show_usage_and_exit(argv[0]);
+		}
+		exit(mg_modify_passwords_file(argv[2], argv[3], argv[4], argv[5])
+		         ? EXIT_SUCCESS
+		         : EXIT_FAILURE);
+	}
+
+	/* Edit passwords file: Remove user, if -R option is specified */
+	if (argc > 1 && !strcmp(argv[1], "-R")) {
+		if (argc != 5) {
+			show_usage_and_exit(argv[0]);
+		}
+		exit(mg_modify_passwords_file(argv[2], argv[3], argv[4], NULL)
+		         ? EXIT_SUCCESS
+		         : EXIT_FAILURE);
+	}
+
+	/* Call Lua with additional CivetWeb specific Lua functions, if -L option
+	 * is specified */
+	if (argc > 1 && !strcmp(argv[1], "-L")) {
+
+#ifdef USE_LUA
+		if (argc != 3) {
+			show_usage_and_exit(argv[0]);
+		}
+#ifdef WIN32
+		(void)MakeConsole();
+#endif
+		exit(run_lua(argv[2]));
+#else
+		show_server_name();
+		fprintf(stderr, "\nError: Lua support not enabled\n");
+		exit(EXIT_FAILURE);
+#endif
+	}
+
+	/* Call Duktape, if -E option is specified */
+	if (argc > 1 && !strcmp(argv[1], "-E")) {
+
+#ifdef USE_DUKTAPE
+		if (argc != 3) {
+			show_usage_and_exit(argv[0]);
+		}
+#ifdef WIN32
+		(void)MakeConsole();
+#endif
+		exit(run_duktape(argv[2]));
+#else
+		show_server_name();
+		fprintf(stderr, "\nError: Ecmascript support not enabled\n");
+		exit(EXIT_FAILURE);
+#endif
+	}
+
+	/* Show usage if -h or --help options are specified */
+	if (argc == 2 && (!strcmp(argv[1], "-h") || !strcmp(argv[1], "-H")
+	                  || !strcmp(argv[1], "--help"))) {
+		show_usage_and_exit(argv[0]);
+	}
+
+	options[0] = NULL;
+	set_option(options, "document_root", ".");
+
+	/* Update config based on command line arguments */
+	process_command_line_arguments(argc, argv, options);
+
+	/* Make sure we have absolute paths for files and directories */
+	set_absolute_path(options, "document_root", argv[0]);
+	set_absolute_path(options, "put_delete_auth_file", argv[0]);
+	set_absolute_path(options, "cgi_interpreter", argv[0]);
+	set_absolute_path(options, "access_log_file", argv[0]);
+	set_absolute_path(options, "error_log_file", argv[0]);
+	set_absolute_path(options, "global_auth_file", argv[0]);
+#ifdef USE_LUA
+	set_absolute_path(options, "lua_preload_file", argv[0]);
+#endif
+	set_absolute_path(options, "ssl_certificate", argv[0]);
+
+	/* Make extra verification for certain options */
+	verify_existence(options, "document_root", 1);
+	verify_existence(options, "cgi_interpreter", 0);
+	verify_existence(options, "ssl_certificate", 0);
+	verify_existence(options, "ssl_ca_path", 1);
+	verify_existence(options, "ssl_ca_file", 0);
+#ifdef USE_LUA
+	verify_existence(options, "lua_preload_file", 0);
+#endif
+
+	/* Setup signal handler: quit on Ctrl-C */
+	signal(SIGTERM, signal_handler);
+	signal(SIGINT, signal_handler);
+
+	/* Initialize user data */
+	memset(&g_user_data, 0, sizeof(g_user_data));
+
+	/* Start Civetweb */
+	memset(&callbacks, 0, sizeof(callbacks));
+	callbacks.log_message = &log_message;
+	g_ctx = mg_start(&callbacks, &g_user_data, (const char **)options);
+
+	/* mg_start copies all options to an internal buffer.
+	 * The options data field here is not required anymore. */
+	for (i = 0; options[i] != NULL; i++) {
+		free(options[i]);
+	}
+
+	/* If mg_start fails, it returns NULL */
+	if (g_ctx == NULL) {
+		die("Failed to start %s:\n%s",
+		    g_server_name,
+		    ((g_user_data.first_message == NULL) ? "unknown reason"
+		                                         : g_user_data.first_message));
+	}
+}
+
+
+static void
+stop_civetweb(void)
+{
+	mg_stop(g_ctx);
+	free(g_user_data.first_message);
+	g_user_data.first_message = NULL;
+}
+
+
+#ifdef _WIN32
+/* Win32 has a small GUI.
+ * Define some GUI elements and Windows message handlers. */
+
+enum {
+	ID_ICON = 100,
+	ID_QUIT,
+	ID_SETTINGS,
+	ID_SEPARATOR,
+	ID_INSTALL_SERVICE,
+	ID_REMOVE_SERVICE,
+	ID_STATIC,
+	ID_GROUP,
+	ID_PASSWORD,
+	ID_SAVE,
+	ID_RESET_DEFAULTS,
+	ID_RESET_FILE,
+	ID_RESET_ACTIVE,
+	ID_STATUS,
+	ID_CONNECT,
+	ID_ADD_USER,
+	ID_ADD_USER_NAME,
+	ID_ADD_USER_REALM,
+	ID_INPUT_LINE,
+	ID_SYSINFO,
+	ID_WEBSITE,
+
+	/* All dynamically created text boxes for options have IDs starting from
+   ID_CONTROLS, incremented by one. */
+	ID_CONTROLS = 200,
+
+	/* Text boxes for files have "..." buttons to open file browser. These
+   buttons have IDs that are ID_FILE_BUTTONS_DELTA higher than associated
+   text box ID. */
+	ID_FILE_BUTTONS_DELTA = 1000
+};
+
+
+static HICON hIcon;
+static SERVICE_STATUS ss;
+static SERVICE_STATUS_HANDLE hStatus;
+static const char *service_magic_argument = "--";
+static NOTIFYICONDATA TrayIcon;
+
+static void WINAPI
+ControlHandler(DWORD code)
+{
+	if (code == SERVICE_CONTROL_STOP || code == SERVICE_CONTROL_SHUTDOWN) {
+		ss.dwWin32ExitCode = 0;
+		ss.dwCurrentState = SERVICE_STOPPED;
+	}
+	SetServiceStatus(hStatus, &ss);
+}
+
+
+static void WINAPI
+ServiceMain(void)
+{
+	ss.dwServiceType = SERVICE_WIN32;
+	ss.dwCurrentState = SERVICE_RUNNING;
+	ss.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN;
+
+	hStatus = RegisterServiceCtrlHandler(g_server_name, ControlHandler);
+	SetServiceStatus(hStatus, &ss);
+
+	while (ss.dwCurrentState == SERVICE_RUNNING) {
+		Sleep(1000);
+	}
+	stop_civetweb();
+
+	ss.dwCurrentState = SERVICE_STOPPED;
+	ss.dwWin32ExitCode = (DWORD)-1;
+	SetServiceStatus(hStatus, &ss);
+}
+
+
+static void
+show_error(void)
+{
+	char buf[256];
+	FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
+	              NULL,
+	              GetLastError(),
+	              MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
+	              buf,
+	              sizeof(buf),
+	              NULL);
+	MessageBox(NULL, buf, "Error", MB_OK);
+}
+
+
+static void *
+align(void *ptr, uintptr_t alig)
+{
+	uintptr_t ul = (uintptr_t)ptr;
+	ul += alig;
+	ul &= ~alig;
+	return ((void *)ul);
+}
+
+
+static void
+save_config(HWND hDlg, FILE *fp)
+{
+	char value[2000] = "";
+	const char *default_value;
+	const struct mg_option *options;
+	int i, id;
+
+	fprintf(fp, "%s", config_file_top_comment);
+	options = mg_get_valid_options();
+	for (i = 0; options[i].name != NULL; i++) {
+		id = ID_CONTROLS + i;
+		if (options[i].type == CONFIG_TYPE_BOOLEAN) {
+			snprintf(value,
+			         sizeof(value) - 1,
+			         "%s",
+			         IsDlgButtonChecked(hDlg, id) ? "yes" : "no");
+			value[sizeof(value) - 1] = 0;
+		} else {
+			GetDlgItemText(hDlg, id, value, sizeof(value));
+		}
+		default_value =
+		    options[i].default_value == NULL ? "" : options[i].default_value;
+		/* If value is the same as default, skip it */
+		if (strcmp(value, default_value) != 0) {
+			fprintf(fp, "%s %s\n", options[i].name, value);
+		}
+	}
+}
+
+
+/* LPARAM pointer passed to WM_INITDIALOG */
+struct dlg_proc_param {
+	int guard;
+	HWND hWnd;
+	const char *name;
+	char *buffer;
+	unsigned buflen;
+};
+
+
+/* Dialog proc for settings dialog */
+static INT_PTR CALLBACK
+SettingsDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
+{
+	FILE *fp;
+	int i, j;
+	const char *name, *value;
+	const struct mg_option *default_options = mg_get_valid_options();
+	char *file_options[MAX_OPTIONS * 2 + 1] = {0};
+	char *title;
+	struct dlg_proc_param *pdlg_proc_param;
+
+	switch (msg) {
+
+	case WM_CLOSE:
+		DestroyWindow(hDlg);
+		break;
+
+	case WM_COMMAND:
+		switch (LOWORD(wParam)) {
+
+		case ID_SAVE:
+			EnableWindow(GetDlgItem(hDlg, ID_SAVE), FALSE);
+			if ((fp = fopen(g_config_file_name, "w+")) != NULL) {
+				save_config(hDlg, fp);
+				fclose(fp);
+				stop_civetweb();
+				start_civetweb(__argc, __argv);
+			}
+			EnableWindow(GetDlgItem(hDlg, ID_SAVE), TRUE);
+			break;
+
+		case ID_RESET_DEFAULTS:
+			for (i = 0; default_options[i].name != NULL; i++) {
+				name = default_options[i].name;
+				value = default_options[i].default_value == NULL
+				            ? ""
+				            : default_options[i].default_value;
+				if (default_options[i].type == CONFIG_TYPE_BOOLEAN) {
+					CheckDlgButton(hDlg,
+					               ID_CONTROLS + i,
+					               !strcmp(value, "yes") ? BST_CHECKED
+					                                     : BST_UNCHECKED);
+				} else {
+					SetWindowText(GetDlgItem(hDlg, ID_CONTROLS + i), value);
+				}
+			}
+			break;
+
+		case ID_RESET_FILE:
+			read_config_file(g_config_file_name, file_options);
+			for (i = 0; default_options[i].name != NULL; i++) {
+				name = default_options[i].name;
+				value = default_options[i].default_value;
+				for (j = 0; file_options[j * 2] != NULL; j++) {
+					if (!strcmp(name, file_options[j * 2])) {
+						value = file_options[j * 2 + 1];
+					}
+				}
+				if (value == NULL) {
+					value = "";
+				}
+				if (default_options[i].type == CONFIG_TYPE_BOOLEAN) {
+					CheckDlgButton(hDlg,
+					               ID_CONTROLS + i,
+					               !strcmp(value, "yes") ? BST_CHECKED
+					                                     : BST_UNCHECKED);
+				} else {
+					SetWindowText(GetDlgItem(hDlg, ID_CONTROLS + i), value);
+				}
+			}
+			for (i = 0; i < MAX_OPTIONS; i++) {
+				free(file_options[2 * i]);
+				free(file_options[2 * i + 1]);
+			}
+			break;
+
+		case ID_RESET_ACTIVE:
+			for (i = 0; default_options[i].name != NULL; i++) {
+				name = default_options[i].name;
+				value = mg_get_option(g_ctx, name);
+				if (default_options[i].type == CONFIG_TYPE_BOOLEAN) {
+					CheckDlgButton(hDlg,
+					               ID_CONTROLS + i,
+					               !strcmp(value, "yes") ? BST_CHECKED
+					                                     : BST_UNCHECKED);
+				} else {
+					SetDlgItemText(hDlg,
+					               ID_CONTROLS + i,
+					               value == NULL ? "" : value);
+				}
+			}
+			break;
+		}
+
+		for (i = 0; default_options[i].name != NULL; i++) {
+			name = default_options[i].name;
+			if (((default_options[i].type == CONFIG_TYPE_FILE)
+			     || (default_options[i].type == CONFIG_TYPE_DIRECTORY))
+			    && LOWORD(wParam) == ID_CONTROLS + i + ID_FILE_BUTTONS_DELTA) {
+				OPENFILENAME of;
+				BROWSEINFO bi;
+				char path[PATH_MAX] = "";
+
+				memset(&of, 0, sizeof(of));
+				of.lStructSize = sizeof(of);
+				of.hwndOwner = (HWND)hDlg;
+				of.lpstrFile = path;
+				of.nMaxFile = sizeof(path);
+				of.lpstrInitialDir = mg_get_option(g_ctx, "document_root");
+				of.Flags =
+				    OFN_CREATEPROMPT | OFN_NOCHANGEDIR | OFN_HIDEREADONLY;
+
+				memset(&bi, 0, sizeof(bi));
+				bi.hwndOwner = (HWND)hDlg;
+				bi.lpszTitle = "Choose WWW root directory:";
+				bi.ulFlags = BIF_RETURNONLYFSDIRS;
+
+				if (default_options[i].type == CONFIG_TYPE_DIRECTORY) {
+					SHGetPathFromIDList(SHBrowseForFolder(&bi), path);
+				} else {
+					GetOpenFileName(&of);
+				}
+
+				if (path[0] != '\0') {
+					SetWindowText(GetDlgItem(hDlg, ID_CONTROLS + i), path);
+				}
+			}
+		}
+		break;
+
+	case WM_INITDIALOG:
+		/* Store hWnd in a parameter accessible by the parent, so we can
+		 * bring this window to front if required. */
+		pdlg_proc_param = (struct dlg_proc_param *)lParam;
+		pdlg_proc_param->hWnd = hDlg;
+
+		/* Initialize the dialog elements */
+		SendMessage(hDlg, WM_SETICON, (WPARAM)ICON_SMALL, (LPARAM)hIcon);
+		SendMessage(hDlg, WM_SETICON, (WPARAM)ICON_BIG, (LPARAM)hIcon);
+		title = malloc(strlen(g_server_name) + 16);
+		if (title) {
+			strcpy(title, g_server_name);
+			strcat(title, " settings");
+			SetWindowText(hDlg, title);
+			free(title);
+		}
+		SetFocus(GetDlgItem(hDlg, ID_SAVE));
+
+		/* Init dialog with active settings */
+		SendMessage(hDlg, WM_COMMAND, ID_RESET_ACTIVE, 0);
+		/* alternative: SendMessage(hDlg, WM_COMMAND, ID_RESET_FILE, 0); */
+		break;
+
+	default:
+		break;
+	}
+
+	return FALSE;
+}
+
+
+/* Dialog proc for input dialog */
+static INT_PTR CALLBACK
+InputDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
+{
+	static struct dlg_proc_param *inBuf = 0;
+	WORD ctrlId;
+	HWND hIn;
+
+	switch (msg) {
+	case WM_CLOSE:
+		inBuf = 0;
+		DestroyWindow(hDlg);
+		break;
+
+	case WM_COMMAND:
+		ctrlId = LOWORD(wParam);
+		if (ctrlId == IDOK) {
+			/* Get handle of input line */
+			hIn = GetDlgItem(hDlg, ID_INPUT_LINE);
+
+			if (hIn) {
+				/* Get content of input line */
+				GetWindowText(hIn, inBuf->buffer, (int)inBuf->buflen);
+				if (strlen(inBuf->buffer) > 0) {
+					/* Input dialog is not empty. */
+					EndDialog(hDlg, IDOK);
+				}
+			} else {
+				/* There is no input line in this dialog. */
+				EndDialog(hDlg, IDOK);
+			}
+		} else if (ctrlId == IDCANCEL) {
+			EndDialog(hDlg, IDCANCEL);
+		}
+		break;
+
+	case WM_INITDIALOG:
+		/* Get handle of input line */
+		hIn = GetDlgItem(hDlg, ID_INPUT_LINE);
+
+		/* Get dialog parameters */
+		inBuf = (struct dlg_proc_param *)lParam;
+
+		/* Set dialog handle for the caller */
+		inBuf->hWnd = hDlg;
+
+		/* Set dialog name */
+		SetWindowText(hDlg, inBuf->name);
+
+		if (hIn) {
+			/* This is an input dialog */
+			assert(inBuf != NULL);
+			assert((inBuf->buffer != NULL) && (inBuf->buflen != 0));
+			assert(strlen(inBuf->buffer) < inBuf->buflen);
+			SendMessage(hDlg, WM_SETICON, (WPARAM)ICON_SMALL, (LPARAM)hIcon);
+			SendMessage(hDlg, WM_SETICON, (WPARAM)ICON_BIG, (LPARAM)hIcon);
+			SendMessage(hIn, EM_LIMITTEXT, inBuf->buflen - 1, 0);
+			SetWindowText(hIn, inBuf->buffer);
+			SetFocus(hIn);
+		}
+
+		break;
+
+	default:
+		break;
+	}
+
+	return FALSE;
+}
+
+
+static void
+suggest_passwd(char *passwd)
+{
+	unsigned u;
+	char *p;
+	union {
+		FILETIME ft;
+		LARGE_INTEGER li;
+	} num;
+
+	/* valid characters are 32 to 126 */
+	GetSystemTimeAsFileTime(&num.ft);
+	num.li.HighPart |= (LONG)GetCurrentProcessId();
+	p = passwd;
+	while (num.li.QuadPart) {
+		u = (unsigned)(num.li.QuadPart % 95);
+		num.li.QuadPart -= u;
+		num.li.QuadPart /= 95;
+		*p = (char)(u + 32);
+		p++;
+	}
+}
+
+
+static void add_control(unsigned char **mem,
+                        DLGTEMPLATE *dia,
+                        WORD type,
+                        WORD id,
+                        DWORD style,
+                        short x,
+                        short y,
+                        short cx,
+                        short cy,
+                        const char *caption);
+
+
+static int
+get_password(const char *user,
+             const char *realm,
+             char *passwd,
+             unsigned passwd_len)
+{
+#define HEIGHT (15)
+#define WIDTH (280)
+#define LABEL_WIDTH (90)
+
+	unsigned char mem[4096], *p;
+	DLGTEMPLATE *dia = (DLGTEMPLATE *)mem;
+	int ok;
+	short y;
+	static struct dlg_proc_param s_dlg_proc_param;
+
+	static struct {
+		DLGTEMPLATE template; /* 18 bytes */
+		WORD menu, class;
+		wchar_t caption[1];
+		WORD fontsiz;
+		wchar_t fontface[7];
+	} dialog_header = {{WS_CAPTION | WS_POPUP | WS_SYSMENU | WS_VISIBLE
+	                        | DS_SETFONT | WS_DLGFRAME,
+	                    WS_EX_TOOLWINDOW,
+	                    0,
+	                    200,
+	                    200,
+	                    WIDTH,
+	                    0},
+	                   0,
+	                   0,
+	                   L"",
+	                   8,
+	                   L"Tahoma"};
+
+	assert((user != NULL) && (realm != NULL) && (passwd != NULL));
+
+	/* Only allow one instance of this dialog to be open. */
+	if (s_dlg_proc_param.guard == 0) {
+		memset(&s_dlg_proc_param, 0, sizeof(s_dlg_proc_param));
+		s_dlg_proc_param.guard = 1;
+	} else {
+		SetForegroundWindow(s_dlg_proc_param.hWnd);
+		return 0;
+	}
+
+	/* Do not open a password dialog, if the username is empty */
+	if (user[0] == 0) {
+		s_dlg_proc_param.guard = 0;
+		return 0;
+	}
+
+	/* Create a password suggestion */
+	memset(passwd, 0, passwd_len);
+	suggest_passwd(passwd);
+
+	/* Make buffer available for input dialog */
+	s_dlg_proc_param.buffer = passwd;
+	s_dlg_proc_param.buflen = passwd_len;
+
+	/* Create the dialog */
+	(void)memset(mem, 0, sizeof(mem));
+	(void)memcpy(mem, &dialog_header, sizeof(dialog_header));
+	p = mem + sizeof(dialog_header);
+
+	y = HEIGHT;
+	add_control(&p,
+	            dia,
+	            0x82,
+	            ID_STATIC,
+	            WS_VISIBLE | WS_CHILD,
+	            10,
+	            y,
+	            LABEL_WIDTH,
+	            HEIGHT,
+	            "User:");
+	add_control(&p,
+	            dia,
+	            0x81,
+	            ID_CONTROLS + 1,
+	            WS_CHILD | WS_VISIBLE | WS_BORDER | ES_AUTOHSCROLL
+	                | ES_READONLY,
+	            15 + LABEL_WIDTH,
+	            y,
+	            WIDTH - LABEL_WIDTH - 25,
+	            HEIGHT,
+	            user);
+
+	y += HEIGHT;
+	add_control(&p,
+	            dia,
+	            0x82,
+	            ID_STATIC,
+	            WS_VISIBLE | WS_CHILD,
+	            10,
+	            y,
+	            LABEL_WIDTH,
+	            HEIGHT,
+	            "Realm:");
+	add_control(&p,
+	            dia,
+	            0x81,
+	            ID_CONTROLS + 2,
+	            WS_CHILD | WS_VISIBLE | WS_BORDER | ES_AUTOHSCROLL
+	                | ES_READONLY,
+	            15 + LABEL_WIDTH,
+	            y,
+	            WIDTH - LABEL_WIDTH - 25,
+	            HEIGHT,
+	            realm);
+
+	y += HEIGHT;
+	add_control(&p,
+	            dia,
+	            0x82,
+	            ID_STATIC,
+	            WS_VISIBLE | WS_CHILD,
+	            10,
+	            y,
+	            LABEL_WIDTH,
+	            HEIGHT,
+	            "Password:");
+	add_control(&p,
+	            dia,
+	            0x81,
+	            ID_INPUT_LINE,
+	            WS_CHILD | WS_VISIBLE | WS_BORDER | ES_AUTOHSCROLL | WS_TABSTOP,
+	            15 + LABEL_WIDTH,
+	            y,
+	            WIDTH - LABEL_WIDTH - 25,
+	            HEIGHT,
+	            "");
+
+	y += (WORD)(HEIGHT * 2);
+	add_control(&p,
+	            dia,
+	            0x80,
+	            IDOK,
+	            WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | WS_TABSTOP,
+	            80,
+	            y,
+	            55,
+	            12,
+	            "Ok");
+	add_control(&p,
+	            dia,
+	            0x80,
+	            IDCANCEL,
+	            WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | WS_TABSTOP,
+	            140,
+	            y,
+	            55,
+	            12,
+	            "Cancel");
+
+	assert((intptr_t)p - (intptr_t)mem < (intptr_t)sizeof(mem));
+
+	dia->cy = y + (WORD)(HEIGHT * 1.5);
+
+	s_dlg_proc_param.name = "Modify password";
+
+	ok =
+	    (IDOK == DialogBoxIndirectParam(
+	                 NULL, dia, NULL, InputDlgProc, (LPARAM)&s_dlg_proc_param));
+
+	s_dlg_proc_param.hWnd = NULL;
+	s_dlg_proc_param.guard = 0;
+
+	return ok;
+
+#undef HEIGHT
+#undef WIDTH
+#undef LABEL_WIDTH
+}
+
+
+/* Dialog proc for password dialog */
+static INT_PTR CALLBACK
+PasswordDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
+{
+	static const char *passfile = 0;
+	char domain[256], user[256], password[256];
+	WORD ctrlId;
+	struct dlg_proc_param *pdlg_proc_param;
+
+	switch (msg) {
+	case WM_CLOSE:
+		passfile = 0;
+		DestroyWindow(hDlg);
+		break;
+
+	case WM_COMMAND:
+		ctrlId = LOWORD(wParam);
+		if (ctrlId == ID_ADD_USER) {
+			/* Add user */
+			GetWindowText(GetDlgItem(hDlg, ID_ADD_USER_NAME),
+			              user,
+			              sizeof(user));
+			GetWindowText(GetDlgItem(hDlg, ID_ADD_USER_REALM),
+			              domain,
+			              sizeof(domain));
+			if (get_password(user, domain, password, sizeof(password))) {
+				mg_modify_passwords_file(passfile, domain, user, password);
+				EndDialog(hDlg, IDOK);
+			}
+		} else if ((ctrlId >= (ID_CONTROLS + ID_FILE_BUTTONS_DELTA * 3))
+		           && (ctrlId < (ID_CONTROLS + ID_FILE_BUTTONS_DELTA * 4))) {
+			/* Modify password */
+			GetWindowText(GetDlgItem(hDlg, ctrlId - ID_FILE_BUTTONS_DELTA * 3),
+			              user,
+			              sizeof(user));
+			GetWindowText(GetDlgItem(hDlg, ctrlId - ID_FILE_BUTTONS_DELTA * 2),
+			              domain,
+			              sizeof(domain));
+			if (get_password(user, domain, password, sizeof(password))) {
+				mg_modify_passwords_file(passfile, domain, user, password);
+				EndDialog(hDlg, IDOK);
+			}
+		} else if ((ctrlId >= (ID_CONTROLS + ID_FILE_BUTTONS_DELTA * 2))
+		           && (ctrlId < (ID_CONTROLS + ID_FILE_BUTTONS_DELTA * 3))) {
+			/* Remove user */
+			GetWindowText(GetDlgItem(hDlg, ctrlId - ID_FILE_BUTTONS_DELTA * 2),
+			              user,
+			              sizeof(user));
+			GetWindowText(GetDlgItem(hDlg, ctrlId - ID_FILE_BUTTONS_DELTA),
+			              domain,
+			              sizeof(domain));
+			mg_modify_passwords_file(passfile, domain, user, NULL);
+			EndDialog(hDlg, IDOK);
+		}
+		break;
+
+	case WM_INITDIALOG:
+		pdlg_proc_param = (struct dlg_proc_param *)lParam;
+		pdlg_proc_param->hWnd = hDlg;
+		passfile = pdlg_proc_param->name;
+		SendMessage(hDlg, WM_SETICON, (WPARAM)ICON_SMALL, (LPARAM)hIcon);
+		SendMessage(hDlg, WM_SETICON, (WPARAM)ICON_BIG, (LPARAM)hIcon);
+		SetWindowText(hDlg, passfile);
+		SetFocus(GetDlgItem(hDlg, ID_ADD_USER_NAME));
+		break;
+
+	default:
+		break;
+	}
+
+	return FALSE;
+}
+
+
+static void
+add_control(unsigned char **mem,
+            DLGTEMPLATE *dia,
+            WORD type,
+            WORD id,
+            DWORD style,
+            short x,
+            short y,
+            short cx,
+            short cy,
+            const char *caption)
+{
+	DLGITEMTEMPLATE *tp;
+	LPWORD p;
+
+	dia->cdit++;
+
+	*mem = align(*mem, 3);
+	tp = (DLGITEMTEMPLATE *)*mem;
+
+	tp->id = id;
+	tp->style = style;
+	tp->dwExtendedStyle = 0;
+	tp->x = x;
+	tp->y = y;
+	tp->cx = cx;
+	tp->cy = cy;
+
+	p = align(*mem + sizeof(*tp), 1);
+	*p++ = 0xffff;
+	*p++ = type;
+
+	while (*caption != '\0') {
+		*p++ = (WCHAR)*caption++;
+	}
+	*p++ = 0;
+	p = align(p, 1);
+
+	*p++ = 0;
+	*mem = (unsigned char *)p;
+}
+
+
+static void
+show_settings_dialog()
+{
+#define HEIGHT (15)
+#define WIDTH (460)
+#define LABEL_WIDTH (90)
+
+	unsigned char mem[16 * 1024], *p;
+	const struct mg_option *options;
+	DWORD style;
+	DLGTEMPLATE *dia = (DLGTEMPLATE *)mem;
+	WORD i, cl, nelems = 0;
+	short width, x, y;
+	static struct dlg_proc_param s_dlg_proc_param;
+
+	static struct {
+		DLGTEMPLATE template; /* 18 bytes */
+		WORD menu, class;
+		wchar_t caption[1];
+		WORD fontsiz;
+		wchar_t fontface[7];
+	} dialog_header = {{WS_CAPTION | WS_POPUP | WS_SYSMENU | WS_VISIBLE
+	                        | DS_SETFONT | WS_DLGFRAME,
+	                    WS_EX_TOOLWINDOW,
+	                    0,
+	                    200,
+	                    200,
+	                    WIDTH,
+	                    0},
+	                   0,
+	                   0,
+	                   L"",
+	                   8,
+	                   L"Tahoma"};
+
+	if (s_dlg_proc_param.guard == 0) {
+		memset(&s_dlg_proc_param, 0, sizeof(s_dlg_proc_param));
+		s_dlg_proc_param.guard = 1;
+	} else {
+		SetForegroundWindow(s_dlg_proc_param.hWnd);
+		return;
+	}
+
+	(void)memset(mem, 0, sizeof(mem));
+	(void)memcpy(mem, &dialog_header, sizeof(dialog_header));
+	p = mem + sizeof(dialog_header);
+
+	options = mg_get_valid_options();
+	for (i = 0; options[i].name != NULL; i++) {
+		style = WS_CHILD | WS_VISIBLE | WS_TABSTOP;
+		x = 10 + (WIDTH / 2) * (nelems % 2);
+		y = (nelems / 2 + 1) * HEIGHT + 5;
+		width = WIDTH / 2 - 20 - LABEL_WIDTH;
+		if (options[i].type == CONFIG_TYPE_NUMBER) {
+			style |= ES_NUMBER;
+			cl = 0x81;
+			style |= WS_BORDER | ES_AUTOHSCROLL;
+		} else if (options[i].type == CONFIG_TYPE_BOOLEAN) {
+			cl = 0x80;
+			style |= BS_AUTOCHECKBOX;
+		} else if ((options[i].type == CONFIG_TYPE_FILE)
+		           || (options[i].type == CONFIG_TYPE_DIRECTORY)) {
+			style |= WS_BORDER | ES_AUTOHSCROLL;
+			width -= 20;
+			cl = 0x81;
+			add_control(&p,
+			            dia,
+			            0x80,
+			            ID_CONTROLS + i + ID_FILE_BUTTONS_DELTA,
+			            WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON,
+			            x + width + LABEL_WIDTH + 5,
+			            y,
+			            15,
+			            12,
+			            "...");
+		} else {
+			cl = 0x81;
+			style |= WS_BORDER | ES_AUTOHSCROLL;
+		}
+		add_control(&p,
+		            dia,
+		            0x82,
+		            ID_STATIC,
+		            WS_VISIBLE | WS_CHILD,
+		            x,
+		            y,
+		            LABEL_WIDTH,
+		            HEIGHT,
+		            options[i].name);
+		add_control(&p,
+		            dia,
+		            cl,
+		            ID_CONTROLS + i,
+		            style,
+		            x + LABEL_WIDTH,
+		            y,
+		            width,
+		            12,
+		            "");
+		nelems++;
+
+		assert(((intptr_t)p - (intptr_t)mem) < (intptr_t)sizeof(mem));
+	}
+
+	y = (((nelems + 1) / 2 + 1) * HEIGHT + 5);
+	add_control(&p,
+	            dia,
+	            0x80,
+	            ID_GROUP,
+	            WS_CHILD | WS_VISIBLE | BS_GROUPBOX,
+	            5,
+	            5,
+	            WIDTH - 10,
+	            y,
+	            " Settings ");
+	y += 10;
+	add_control(&p,
+	            dia,
+	            0x80,
+	            ID_SAVE,
+	            WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | WS_TABSTOP,
+	            WIDTH - 70,
+	            y,
+	            65,
+	            12,
+	            "Save Settings");
+	add_control(&p,
+	            dia,
+	            0x80,
+	            ID_RESET_DEFAULTS,
+	            WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | WS_TABSTOP,
+	            WIDTH - 140,
+	            y,
+	            65,
+	            12,
+	            "Reset to defaults");
+	add_control(&p,
+	            dia,
+	            0x80,
+	            ID_RESET_FILE,
+	            WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | WS_TABSTOP,
+	            WIDTH - 210,
+	            y,
+	            65,
+	            12,
+	            "Reload from file");
+	add_control(&p,
+	            dia,
+	            0x80,
+	            ID_RESET_ACTIVE,
+	            WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | WS_TABSTOP,
+	            WIDTH - 280,
+	            y,
+	            65,
+	            12,
+	            "Reload active");
+	add_control(&p,
+	            dia,
+	            0x82,
+	            ID_STATIC,
+	            WS_CHILD | WS_VISIBLE | WS_DISABLED,
+	            5,
+	            y,
+	            100,
+	            12,
+	            g_server_base_name);
+
+	assert(((intptr_t)p - (intptr_t)mem) < (intptr_t)sizeof(mem));
+
+	dia->cy = ((nelems + 1) / 2 + 1) * HEIGHT + 30;
+
+	DialogBoxIndirectParam(
+	    NULL, dia, NULL, SettingsDlgProc, (LPARAM)&s_dlg_proc_param);
+
+	s_dlg_proc_param.hWnd = NULL;
+	s_dlg_proc_param.guard = 0;
+
+#undef HEIGHT
+#undef WIDTH
+#undef LABEL_WIDTH
+}
+
+
+static void
+change_password_file()
+{
+#define HEIGHT (15)
+#define WIDTH (320)
+#define LABEL_WIDTH (90)
+
+	OPENFILENAME of;
+	char path[PATH_MAX] = PASSWORDS_FILE_NAME;
+	char strbuf[256], u[256], d[256];
+	HWND hDlg = NULL;
+	FILE *f;
+	short y, nelems;
+	unsigned char mem[4096], *p;
+	DLGTEMPLATE *dia = (DLGTEMPLATE *)mem;
+	const char *domain = mg_get_option(g_ctx, "authentication_domain");
+	static struct dlg_proc_param s_dlg_proc_param;
+
+	static struct {
+		DLGTEMPLATE template; /* 18 bytes */
+		WORD menu, class;
+		wchar_t caption[1];
+		WORD fontsiz;
+		wchar_t fontface[7];
+	} dialog_header = {{WS_CAPTION | WS_POPUP | WS_SYSMENU | WS_VISIBLE
+	                        | DS_SETFONT | WS_DLGFRAME,
+	                    WS_EX_TOOLWINDOW,
+	                    0,
+	                    200,
+	                    200,
+	                    WIDTH,
+	                    0},
+	                   0,
+	                   0,
+	                   L"",
+	                   8,
+	                   L"Tahoma"};
+
+	if (s_dlg_proc_param.guard == 0) {
+		memset(&s_dlg_proc_param, 0, sizeof(s_dlg_proc_param));
+		s_dlg_proc_param.guard = 1;
+	} else {
+		SetForegroundWindow(s_dlg_proc_param.hWnd);
+		return;
+	}
+
+	memset(&of, 0, sizeof(of));
+	of.lStructSize = sizeof(of);
+	of.hwndOwner = (HWND)hDlg;
+	of.lpstrFile = path;
+	of.nMaxFile = sizeof(path);
+	of.lpstrInitialDir = mg_get_option(g_ctx, "document_root");
+	of.Flags = OFN_CREATEPROMPT | OFN_NOCHANGEDIR | OFN_HIDEREADONLY;
+
+	if (IDOK != GetSaveFileName(&of)) {
+		s_dlg_proc_param.guard = 0;
+		return;
+	}
+
+	f = fopen(path, "a+");
+	if (f) {
+		fclose(f);
+	} else {
+		MessageBox(NULL, path, "Can not open file", MB_ICONERROR);
+		s_dlg_proc_param.guard = 0;
+		return;
+	}
+
+	do {
+		s_dlg_proc_param.hWnd = NULL;
+		(void)memset(mem, 0, sizeof(mem));
+		(void)memcpy(mem, &dialog_header, sizeof(dialog_header));
+		p = mem + sizeof(dialog_header);
+
+		f = fopen(path, "r+");
+		if (!f) {
+			MessageBox(NULL, path, "Can not open file", MB_ICONERROR);
+			s_dlg_proc_param.guard = 0;
+			return;
+		}
+
+		nelems = 0;
+		while (fgets(strbuf, sizeof(strbuf), f)) {
+			if (sscanf(strbuf, "%255[^:]:%255[^:]:%*s", u, d) != 2) {
+				continue;
+			}
+			u[255] = 0;
+			d[255] = 0;
+			y = (nelems + 1) * HEIGHT + 5;
+			add_control(&p,
+			            dia,
+			            0x80,
+			            ID_CONTROLS + nelems + ID_FILE_BUTTONS_DELTA * 3,
+			            WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | WS_TABSTOP,
+			            10,
+			            y,
+			            65,
+			            12,
+			            "Modify password");
+			add_control(&p,
+			            dia,
+			            0x80,
+			            ID_CONTROLS + nelems + ID_FILE_BUTTONS_DELTA * 2,
+			            WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | WS_TABSTOP,
+			            80,
+			            y,
+			            55,
+			            12,
+			            "Remove user");
+			add_control(&p,
+			            dia,
+			            0x81,
+			            ID_CONTROLS + nelems + ID_FILE_BUTTONS_DELTA,
+			            WS_CHILD | WS_VISIBLE | WS_BORDER | ES_AUTOHSCROLL
+			                | ES_READONLY,
+			            245,
+			            y,
+			            60,
+			            12,
+			            d);
+			add_control(&p,
+			            dia,
+			            0x81,
+			            ID_CONTROLS + nelems,
+			            WS_CHILD | WS_VISIBLE | WS_BORDER | ES_AUTOHSCROLL
+			                | ES_READONLY,
+			            140,
+			            y,
+			            100,
+			            12,
+			            u);
+
+			nelems++;
+			assert(((intptr_t)p - (intptr_t)mem) < (intptr_t)sizeof(mem));
+		}
+		fclose(f);
+
+		y = (nelems + 1) * HEIGHT + 10;
+		add_control(&p,
+		            dia,
+		            0x80,
+		            ID_ADD_USER,
+		            WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | WS_TABSTOP,
+		            80,
+		            y,
+		            55,
+		            12,
+		            "Add user");
+		add_control(&p,
+		            dia,
+		            0x81,
+		            ID_ADD_USER_NAME,
+		            WS_CHILD | WS_VISIBLE | WS_BORDER | ES_AUTOHSCROLL
+		                | WS_TABSTOP,
+		            140,
+		            y,
+		            100,
+		            12,
+		            "");
+		add_control(&p,
+		            dia,
+		            0x81,
+		            ID_ADD_USER_REALM,
+		            WS_CHILD | WS_VISIBLE | WS_BORDER | ES_AUTOHSCROLL
+		                | WS_TABSTOP,
+		            245,
+		            y,
+		            60,
+		            12,
+		            domain);
+
+		y = (nelems + 2) * HEIGHT + 10;
+		add_control(&p,
+		            dia,
+		            0x80,
+		            ID_GROUP,
+		            WS_CHILD | WS_VISIBLE | BS_GROUPBOX,
+		            5,
+		            5,
+		            WIDTH - 10,
+		            y,
+		            " Users ");
+
+		y += HEIGHT;
+		add_control(&p,
+		            dia,
+		            0x82,
+		            ID_STATIC,
+		            WS_CHILD | WS_VISIBLE | WS_DISABLED,
+		            5,
+		            y,
+		            100,
+		            12,
+		            g_server_base_name);
+
+		assert(((intptr_t)p - (intptr_t)mem) < (intptr_t)sizeof(mem));
+
+		dia->cy = y + 20;
+
+		s_dlg_proc_param.name = path;
+
+	} while ((IDOK == DialogBoxIndirectParam(NULL,
+	                                         dia,
+	                                         NULL,
+	                                         PasswordDlgProc,
+	                                         (LPARAM)&s_dlg_proc_param))
+	         && (!g_exit_flag));
+
+	s_dlg_proc_param.hWnd = NULL;
+	s_dlg_proc_param.guard = 0;
+
+#undef HEIGHT
+#undef WIDTH
+#undef LABEL_WIDTH
+}
+
+
+int
+show_system_info()
+{
+#define HEIGHT (15)
+#define WIDTH (320)
+#define LABEL_WIDTH (50)
+
+	unsigned char mem[4096], *p;
+	DLGTEMPLATE *dia = (DLGTEMPLATE *)mem;
+	int ok;
+	short y;
+	static struct dlg_proc_param s_dlg_proc_param;
+
+	static struct {
+		DLGTEMPLATE template; /* 18 bytes */
+		WORD menu, class;
+		wchar_t caption[1];
+		WORD fontsiz;
+		wchar_t fontface[7];
+	} dialog_header = {{WS_CAPTION | WS_POPUP | WS_SYSMENU | WS_VISIBLE
+	                        | DS_SETFONT | WS_DLGFRAME,
+	                    WS_EX_TOOLWINDOW,
+	                    0,
+	                    200,
+	                    200,
+	                    WIDTH,
+	                    0},
+	                   0,
+	                   0,
+	                   L"",
+	                   8,
+	                   L"Tahoma"};
+
+	/* Only allow one instance of this dialog to be open. */
+	if (s_dlg_proc_param.guard == 0) {
+		memset(&s_dlg_proc_param, 0, sizeof(s_dlg_proc_param));
+		s_dlg_proc_param.guard = 1;
+	} else {
+		SetForegroundWindow(s_dlg_proc_param.hWnd);
+		return 0;
+	}
+
+	/* Create the dialog */
+	(void)memset(mem, 0, sizeof(mem));
+	(void)memcpy(mem, &dialog_header, sizeof(dialog_header));
+	p = mem + sizeof(dialog_header);
+
+	y = HEIGHT;
+	add_control(&p,
+	            dia,
+	            0x82,
+	            ID_STATIC,
+	            WS_VISIBLE | WS_CHILD,
+	            10,
+	            y,
+	            LABEL_WIDTH,
+	            HEIGHT,
+	            "System Information:");
+	add_control(&p,
+	            dia,
+	            0x81,
+	            ID_CONTROLS + 1,
+	            WS_CHILD | WS_VISIBLE | WS_BORDER | ES_AUTOHSCROLL
+	                | ES_AUTOVSCROLL | ES_MULTILINE | ES_READONLY,
+	            15 + LABEL_WIDTH,
+	            y,
+	            WIDTH - LABEL_WIDTH - 25,
+	            HEIGHT * 7,
+	            g_system_info);
+
+	y += (WORD)(HEIGHT * 8);
+	add_control(&p,
+	            dia,
+	            0x80,
+	            IDOK,
+	            WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | WS_TABSTOP,
+	            (WIDTH - 55) / 2,
+	            y,
+	            55,
+	            12,
+	            "Ok");
+
+	assert((intptr_t)p - (intptr_t)mem < (intptr_t)sizeof(mem));
+
+	dia->cy = y + (WORD)(HEIGHT * 1.5);
+
+	s_dlg_proc_param.name = "System information";
+
+	ok =
+	    (IDOK == DialogBoxIndirectParam(
+	                 NULL, dia, NULL, InputDlgProc, (LPARAM)&s_dlg_proc_param));
+
+	s_dlg_proc_param.hWnd = NULL;
+	s_dlg_proc_param.guard = 0;
+
+	return ok;
+
+#undef HEIGHT
+#undef WIDTH
+#undef LABEL_WIDTH
+}
+
+
+static int
+manage_service(int action)
+{
+	const char *service_name = g_server_name;
+	SC_HANDLE hSCM = NULL, hService = NULL;
+	SERVICE_DESCRIPTION descr;
+	char path[PATH_MAX + 20] = ""; /* Path to executable plus magic argument */
+	int success = 1;
+
+	descr.lpDescription = (LPSTR)g_server_name;
+
+	if ((hSCM = OpenSCManager(NULL,
+	                          NULL,
+	                          action == ID_INSTALL_SERVICE ? GENERIC_WRITE
+	                                                       : GENERIC_READ))
+	    == NULL) {
+		success = 0;
+		show_error();
+	} else if (action == ID_INSTALL_SERVICE) {
+		path[sizeof(path) - 1] = 0;
+		GetModuleFileName(NULL, path, sizeof(path) - 1);
+		strncat(path, " ", sizeof(path) - 1);
+		strncat(path, service_magic_argument, sizeof(path) - 1);
+		hService = CreateService(hSCM,
+		                         service_name,
+		                         service_name,
+		                         SERVICE_ALL_ACCESS,
+		                         SERVICE_WIN32_OWN_PROCESS,
+		                         SERVICE_AUTO_START,
+		                         SERVICE_ERROR_NORMAL,
+		                         path,
+		                         NULL,
+		                         NULL,
+		                         NULL,
+		                         NULL,
+		                         NULL);
+		if (hService) {
+			ChangeServiceConfig2(hService, SERVICE_CONFIG_DESCRIPTION, &descr);
+		} else {
+			show_error();
+		}
+	} else if (action == ID_REMOVE_SERVICE) {
+		if ((hService = OpenService(hSCM, service_name, DELETE)) == NULL
+		    || !DeleteService(hService)) {
+			show_error();
+		}
+	} else if ((hService =
+	                OpenService(hSCM, service_name, SERVICE_QUERY_STATUS))
+	           == NULL) {
+		success = 0;
+	}
+
+	if (hService)
+		CloseServiceHandle(hService);
+	if (hSCM)
+		CloseServiceHandle(hSCM);
+
+	return success;
+}
+
+
+/* Window proc for taskbar icon */
+static LRESULT CALLBACK
+WindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
+{
+	static SERVICE_TABLE_ENTRY service_table[2];
+	int service_installed;
+	char buf[200], *service_argv[2];
+	POINT pt;
+	HMENU hMenu;
+	static UINT s_uTaskbarRestart; /* for taskbar creation */
+
+	service_argv[0] = __argv[0];
+	service_argv[1] = NULL;
+
+	memset(service_table, 0, sizeof(service_table));
+	service_table[0].lpServiceName = (LPSTR)g_server_name;
+	service_table[0].lpServiceProc = (LPSERVICE_MAIN_FUNCTION)ServiceMain;
+
+	switch (msg) {
+
+	case WM_CREATE:
+		if (__argv[1] != NULL && !strcmp(__argv[1], service_magic_argument)) {
+			start_civetweb(1, service_argv);
+			StartServiceCtrlDispatcher(service_table);
+			exit(EXIT_SUCCESS);
+		} else {
+			start_civetweb(__argc, __argv);
+			s_uTaskbarRestart = RegisterWindowMessage(TEXT("TaskbarCreated"));
+		}
+		break;
+
+	case WM_COMMAND:
+		switch (LOWORD(wParam)) {
+		case ID_QUIT:
+			stop_civetweb();
+			Shell_NotifyIcon(NIM_DELETE, &TrayIcon);
+			g_exit_flag = 1;
+			PostQuitMessage(0);
+			return 0;
+		case ID_SETTINGS:
+			show_settings_dialog();
+			break;
+		case ID_PASSWORD:
+			change_password_file();
+			break;
+		case ID_SYSINFO:
+			show_system_info();
+			break;
+		case ID_INSTALL_SERVICE:
+		case ID_REMOVE_SERVICE:
+			manage_service(LOWORD(wParam));
+			break;
+		case ID_CONNECT:
+			fprintf(stdout, "[%s]\n", get_url_to_first_open_port(g_ctx));
+			ShellExecute(NULL,
+			             "open",
+			             get_url_to_first_open_port(g_ctx),
+			             NULL,
+			             NULL,
+			             SW_SHOW);
+			break;
+		case ID_WEBSITE:
+			fprintf(stdout, "[%s]\n", g_website);
+			ShellExecute(NULL,
+				"open",
+				g_website,
+				NULL,
+				NULL,
+				SW_SHOW);
+			break;
+		}
+		break;
+
+	case WM_USER:
+		switch (lParam) {
+		case WM_RBUTTONUP:
+		case WM_LBUTTONUP:
+		case WM_LBUTTONDBLCLK:
+			hMenu = CreatePopupMenu();
+			AppendMenu(hMenu,
+			           MF_STRING | MF_GRAYED,
+			           ID_SEPARATOR,
+			           g_server_name);
+			AppendMenu(hMenu, MF_SEPARATOR, ID_SEPARATOR, "");
+			service_installed = manage_service(0);
+			snprintf(buf,
+			         sizeof(buf) - 1,
+			         "NT service: %s installed",
+			         service_installed ? "" : "not");
+			buf[sizeof(buf) - 1] = 0;
+			AppendMenu(hMenu, MF_STRING | MF_GRAYED, ID_SEPARATOR, buf);
+			AppendMenu(hMenu,
+			           MF_STRING | (service_installed ? MF_GRAYED : 0),
+			           ID_INSTALL_SERVICE,
+			           "Install service");
+			AppendMenu(hMenu,
+			           MF_STRING | (!service_installed ? MF_GRAYED : 0),
+			           ID_REMOVE_SERVICE,
+			           "Deinstall service");
+			AppendMenu(hMenu, MF_SEPARATOR, ID_SEPARATOR, "");
+			AppendMenu(hMenu, MF_STRING, ID_CONNECT, "Start browser");
+			AppendMenu(hMenu, MF_STRING, ID_SETTINGS, "Edit settings");
+			AppendMenu(hMenu, MF_STRING, ID_PASSWORD, "Modify password file");
+			AppendMenu(hMenu, MF_STRING, ID_SYSINFO, "Show system info");
+			AppendMenu(hMenu, MF_STRING, ID_WEBSITE, "Visit website");
+			AppendMenu(hMenu, MF_SEPARATOR, ID_SEPARATOR, "");
+			AppendMenu(hMenu, MF_STRING, ID_QUIT, "Exit");
+			GetCursorPos(&pt);
+			SetForegroundWindow(hWnd);
+			TrackPopupMenu(hMenu, 0, pt.x, pt.y, 0, hWnd, NULL);
+			PostMessage(hWnd, WM_NULL, 0, 0);
+			DestroyMenu(hMenu);
+			break;
+		}
+		break;
+
+	case WM_CLOSE:
+		stop_civetweb();
+		Shell_NotifyIcon(NIM_DELETE, &TrayIcon);
+		g_exit_flag = 1;
+		PostQuitMessage(0);
+		return 0; /* We've just sent our own quit message, with proper hwnd. */
+
+	default:
+		if (msg == s_uTaskbarRestart)
+			Shell_NotifyIcon(NIM_ADD, &TrayIcon);
+	}
+
+	return DefWindowProc(hWnd, msg, wParam, lParam);
+}
+
+
+static int
+MakeConsole(void)
+{
+	DWORD err;
+	int ok = (GetConsoleWindow() != NULL);
+	if (!ok) {
+		if (!AttachConsole(ATTACH_PARENT_PROCESS)) {
+			FreeConsole();
+			if (!AllocConsole()) {
+				err = GetLastError();
+				if (err == ERROR_ACCESS_DENIED) {
+					MessageBox(NULL,
+					           "Insufficient rights to create a console window",
+					           "Error",
+					           MB_ICONERROR);
+				}
+			}
+			AttachConsole(GetCurrentProcessId());
+		}
+
+		ok = (GetConsoleWindow() != NULL);
+		if (ok) {
+			freopen("CONIN$", "r", stdin);
+			freopen("CONOUT$", "w", stdout);
+			freopen("CONOUT$", "w", stderr);
+		}
+	}
+
+	if (ok) {
+		SetConsoleTitle(g_server_name);
+	}
+
+	return ok;
+}
+
+
+int WINAPI
+WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR cmdline, int show)
+{
+	WNDCLASS cls;
+	HWND hWnd;
+	MSG msg;
+
+#if defined(DEBUG)
+	(void)MakeConsole();
+#endif
+
+	(void)hInst;
+	(void)hPrev;
+	(void)cmdline;
+	(void)show;
+
+	init_server_name((int)__argc, (const char **)__argv);
+	init_system_info();
+	memset(&cls, 0, sizeof(cls));
+	cls.lpfnWndProc = (WNDPROC)WindowProc;
+	cls.hIcon = LoadIcon(NULL, IDI_APPLICATION);
+	cls.lpszClassName = g_server_base_name;
+
+	RegisterClass(&cls);
+	hWnd = CreateWindow(cls.lpszClassName,
+	                    g_server_name,
+	                    WS_OVERLAPPEDWINDOW,
+	                    0,
+	                    0,
+	                    0,
+	                    0,
+	                    NULL,
+	                    NULL,
+	                    NULL,
+	                    NULL);
+	ShowWindow(hWnd, SW_HIDE);
+
+	if (g_icon_name) {
+		hIcon =
+		    LoadImage(NULL, g_icon_name, IMAGE_ICON, 16, 16, LR_LOADFROMFILE);
+	} else {
+		hIcon = LoadImage(GetModuleHandle(NULL),
+		                  MAKEINTRESOURCE(ID_ICON),
+		                  IMAGE_ICON,
+		                  16,
+		                  16,
+		                  0);
+	}
+
+	TrayIcon.cbSize = sizeof(TrayIcon);
+	TrayIcon.uID = ID_ICON;
+	TrayIcon.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
+	TrayIcon.hIcon = hIcon;
+	TrayIcon.hWnd = hWnd;
+	snprintf(TrayIcon.szTip, sizeof(TrayIcon.szTip), "%s", g_server_name);
+	TrayIcon.uCallbackMessage = WM_USER;
+	Shell_NotifyIcon(NIM_ADD, &TrayIcon);
+
+	while (GetMessage(&msg, hWnd, 0, 0) > 0) {
+		TranslateMessage(&msg);
+		DispatchMessage(&msg);
+	}
+
+	free_system_info();
+
+	/* Return the WM_QUIT value. */
+	return (int)msg.wParam;
+}
+
+
+int
+main(int argc, char *argv[])
+{
+	(void)argc;
+	(void)argv;
+
+	return WinMain(0, 0, 0, 0);
+}
+
+
+#elif defined(USE_COCOA)
+#import <Cocoa/Cocoa.h>
+
+@interface Civetweb : NSObject <NSApplicationDelegate>
+- (void)openBrowser;
+- (void)shutDown;
+@end
+
+@implementation Civetweb
+- (void)openBrowser
+{
+	[[NSWorkspace sharedWorkspace]
+	    openURL:[NSURL URLWithString:[NSString stringWithUTF8String:
+	                                               get_url_to_first_open_port(
+	                                                   g_ctx)]]];
+}
+- (void)editConfig
+{
+	create_config_file(g_ctx, g_config_file_name);
+	NSString *path = [NSString stringWithUTF8String:g_config_file_name];
+	if (![[NSWorkspace sharedWorkspace] openFile:path
+	                             withApplication:@"TextEdit"]) {
+		NSAlert *alert = [[[NSAlert alloc] init] autorelease];
+		[alert setAlertStyle:NSWarningAlertStyle];
+		[alert setMessageText:NSLocalizedString(@"Unable to open config file.",
+		                                        "")];
+		[alert setInformativeText:path];
+		(void)[alert runModal];
+	}
+}
+- (void)shutDown
+{
+	[NSApp terminate:nil];
+}
+@end
+
+int
+main(int argc, char *argv[])
+{
+	init_server_name(argc, (const char **)argv);
+	init_system_info();
+	start_civetweb(argc, argv);
+
+	[NSAutoreleasePool new];
+	[NSApplication sharedApplication];
+
+	/* Add delegate to process menu item actions */
+	Civetweb *myDelegate = [[Civetweb alloc] autorelease];
+	[NSApp setDelegate:myDelegate];
+
+	/* Run this app as agent */
+	ProcessSerialNumber psn = {0, kCurrentProcess};
+	TransformProcessType(&psn, kProcessTransformToBackgroundApplication);
+	SetFrontProcess(&psn);
+
+	/* Add status bar menu */
+	id menu = [[NSMenu new] autorelease];
+
+	/* Add version menu item */
+	[menu
+	    addItem:
+	        [[[NSMenuItem alloc]
+	            /*initWithTitle:[NSString stringWithFormat:@"%s", server_name]*/
+	            initWithTitle:[NSString stringWithUTF8String:g_server_name]
+	                   action:@selector(noexist)
+	            keyEquivalent:@""] autorelease]];
+
+	/* Add configuration menu item */
+	[menu addItem:[[[NSMenuItem alloc] initWithTitle:@"Edit configuration"
+	                                          action:@selector(editConfig)
+	                                   keyEquivalent:@""] autorelease]];
+
+	/* Add connect menu item */
+	[menu
+	    addItem:[[[NSMenuItem alloc] initWithTitle:@"Open web root in a browser"
+	                                        action:@selector(openBrowser)
+	                                 keyEquivalent:@""] autorelease]];
+
+	/* Separator */
+	[menu addItem:[NSMenuItem separatorItem]];
+
+	/* Add quit menu item */
+	[menu addItem:[[[NSMenuItem alloc] initWithTitle:@"Quit"
+	                                          action:@selector(shutDown)
+	                                   keyEquivalent:@"q"] autorelease]];
+
+	/* Attach menu to the status bar */
+	id item = [[[NSStatusBar systemStatusBar]
+	    statusItemWithLength:NSVariableStatusItemLength] retain];
+	[item setHighlightMode:YES];
+	[item setImage:[NSImage imageNamed:@"civetweb_22x22.png"]];
+	[item setMenu:menu];
+
+	/* Run the app */
+	[NSApp activateIgnoringOtherApps:YES];
+	[NSApp run];
+
+	stop_civetweb();
+	free_system_info();
+
+	return EXIT_SUCCESS;
+}
+
+#else
+
+int
+main(int argc, char *argv[])
+{
+	init_server_name(argc, (const char **)argv);
+	init_system_info();
+	start_civetweb(argc, argv);
+	fprintf(stdout,
+	        "%s started on port(s) %s with web root [%s]\n",
+	        g_server_name,
+	        mg_get_option(g_ctx, "listening_ports"),
+	        mg_get_option(g_ctx, "document_root"));
+	while (g_exit_flag == 0) {
+		sleep(1);
+	}
+	fprintf(stdout,
+	        "Exiting on signal %d, waiting for all threads to finish...",
+	        g_exit_flag);
+	fflush(stdout);
+	stop_civetweb();
+	fprintf(stdout, "%s", " done.\n");
+
+	free_system_info();
+
+	return EXIT_SUCCESS;
+}
+#endif /* _WIN32 */

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/md5.inl
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/md5.inl b/thirdparty/civetweb-1.9.1/src/md5.inl
new file mode 100644
index 0000000..733f176
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/md5.inl
@@ -0,0 +1,468 @@
+/*
+ * This an amalgamation of md5.c and md5.h into a single file
+ * with all static declaration to reduce linker conflicts
+ * in Civetweb.
+ *
+ * The MD5_STATIC declaration was added to facilitate static
+ * inclusion.
+ * No Face Press, LLC
+ */
+
+/* $Id: md5.h,v 1.4 2002/04/13 19:20:28 lpd Exp $ */
+/*
+  Independent implementation of MD5 (RFC 1321).
+
+  This code implements the MD5 Algorithm defined in RFC 1321, whose
+  text is available at
+    http://www.ietf.org/rfc/rfc1321.txt
+  The code is derived from the text of the RFC, including the test suite
+  (section A.5) but excluding the rest of Appendix A.  It does not include
+  any code or documentation that is identified in the RFC as being
+  copyrighted.
+
+  The original and principal author of md5.h is L. Peter Deutsch
+  <gh...@aladdin.com>.  Other authors are noted in the change history
+  that follows (in reverse chronological order):
+
+  2002-04-13 lpd Removed support for non-ANSI compilers; removed
+    references to Ghostscript; clarified derivation from RFC 1321;
+    now handles byte order either statically or dynamically.
+  1999-11-04 lpd Edited comments slightly for automatic TOC extraction.
+  1999-10-18 lpd Fixed typo in header comment (ansi2knr rather than md5);
+    added conditionalization for C++ compilation from Martin
+    Purschke <pu...@bnl.gov>.
+  1999-05-03 lpd Original version.
+ */
+
+#ifndef md5_INCLUDED
+#define md5_INCLUDED
+
+/*
+ * This package supports both compile-time and run-time determination of CPU
+ * byte order.  If ARCH_IS_BIG_ENDIAN is defined as 0, the code will be
+ * compiled to run only on little-endian CPUs; if ARCH_IS_BIG_ENDIAN is
+ * defined as non-zero, the code will be compiled to run only on big-endian
+ * CPUs; if ARCH_IS_BIG_ENDIAN is not defined, the code will be compiled to
+ * run on either big- or little-endian CPUs, but will run slightly less
+ * efficiently on either one than if ARCH_IS_BIG_ENDIAN is defined.
+ */
+
+typedef unsigned char md5_byte_t; /* 8-bit byte */
+typedef unsigned int md5_word_t;  /* 32-bit word */
+
+/* Define the state of the MD5 Algorithm. */
+typedef struct md5_state_s {
+	md5_word_t count[2]; /* message length in bits, lsw first */
+	md5_word_t abcd[4];  /* digest buffer */
+	md5_byte_t buf[64];  /* accumulate block */
+} md5_state_t;
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Initialize the algorithm. */
+MD5_STATIC void md5_init(md5_state_t *pms);
+
+/* Append a string to the message. */
+MD5_STATIC void
+md5_append(md5_state_t *pms, const md5_byte_t *data, size_t nbytes);
+
+/* Finish the message and return the digest. */
+MD5_STATIC void md5_finish(md5_state_t *pms, md5_byte_t digest[16]);
+
+#ifdef __cplusplus
+} /* end extern "C" */
+#endif
+
+#endif /* md5_INCLUDED */
+
+/*
+  Copyright (C) 1999, 2000, 2002 Aladdin Enterprises.  All rights reserved.
+
+  This software is provided 'as-is', without any express or implied
+  warranty.  In no event will the authors be held liable for any damages
+  arising from the use of this software.
+
+  Permission is granted to anyone to use this software for any purpose,
+  including commercial applications, and to alter it and redistribute it
+  freely, subject to the following restrictions:
+
+  1. The origin of this software must not be misrepresented; you must not
+     claim that you wrote the original software. If you use this software
+     in a product, an acknowledgment in the product documentation would be
+     appreciated but is not required.
+  2. Altered source versions must be plainly marked as such, and must not be
+     misrepresented as being the original software.
+  3. This notice may not be removed or altered from any source distribution.
+
+  L. Peter Deutsch
+  ghost@aladdin.com
+
+ */
+/* $Id: md5.c,v 1.6 2002/04/13 19:20:28 lpd Exp $ */
+/*
+  Independent implementation of MD5 (RFC 1321).
+
+  This code implements the MD5 Algorithm defined in RFC 1321, whose
+  text is available at
+    http://www.ietf.org/rfc/rfc1321.txt
+  The code is derived from the text of the RFC, including the test suite
+  (section A.5) but excluding the rest of Appendix A.  It does not include
+  any code or documentation that is identified in the RFC as being
+  copyrighted.
+
+  The original and principal author of md5.c is L. Peter Deutsch
+  <gh...@aladdin.com>.  Other authors are noted in the change history
+  that follows (in reverse chronological order):
+
+  2002-04-13 lpd Clarified derivation from RFC 1321; now handles byte order
+    either statically or dynamically; added missing #include <string.h>
+    in library.
+  2002-03-11 lpd Corrected argument list for main(), and added int return
+    type, in test program and T value program.
+  2002-02-21 lpd Added missing #include <stdio.h> in test program.
+  2000-07-03 lpd Patched to eliminate warnings about "constant is
+    unsigned in ANSI C, signed in traditional"; made test program
+    self-checking.
+  1999-11-04 lpd Edited comments slightly for automatic TOC extraction.
+  1999-10-18 lpd Fixed typo in header comment (ansi2knr rather than md5).
+  1999-05-03 lpd Original version.
+ */
+
+#ifndef MD5_STATIC
+#include <string.h>
+#endif
+
+#undef BYTE_ORDER /* 1 = big-endian, -1 = little-endian, 0 = unknown */
+#ifdef ARCH_IS_BIG_ENDIAN
+#define BYTE_ORDER (ARCH_IS_BIG_ENDIAN ? 1 : -1)
+#else
+#define BYTE_ORDER (0)
+#endif
+
+#define T_MASK ((md5_word_t)~0)
+#define T1 /* 0xd76aa478 */ (T_MASK ^ 0x28955b87)
+#define T2 /* 0xe8c7b756 */ (T_MASK ^ 0x173848a9)
+#define T3 (0x242070db)
+#define T4 /* 0xc1bdceee */ (T_MASK ^ 0x3e423111)
+#define T5 /* 0xf57c0faf */ (T_MASK ^ 0x0a83f050)
+#define T6 (0x4787c62a)
+#define T7 /* 0xa8304613 */ (T_MASK ^ 0x57cfb9ec)
+#define T8 /* 0xfd469501 */ (T_MASK ^ 0x02b96afe)
+#define T9 (0x698098d8)
+#define T10 /* 0x8b44f7af */ (T_MASK ^ 0x74bb0850)
+#define T11 /* 0xffff5bb1 */ (T_MASK ^ 0x0000a44e)
+#define T12 /* 0x895cd7be */ (T_MASK ^ 0x76a32841)
+#define T13 (0x6b901122)
+#define T14 /* 0xfd987193 */ (T_MASK ^ 0x02678e6c)
+#define T15 /* 0xa679438e */ (T_MASK ^ 0x5986bc71)
+#define T16 (0x49b40821)
+#define T17 /* 0xf61e2562 */ (T_MASK ^ 0x09e1da9d)
+#define T18 /* 0xc040b340 */ (T_MASK ^ 0x3fbf4cbf)
+#define T19 (0x265e5a51)
+#define T20 /* 0xe9b6c7aa */ (T_MASK ^ 0x16493855)
+#define T21 /* 0xd62f105d */ (T_MASK ^ 0x29d0efa2)
+#define T22 (0x02441453)
+#define T23 /* 0xd8a1e681 */ (T_MASK ^ 0x275e197e)
+#define T24 /* 0xe7d3fbc8 */ (T_MASK ^ 0x182c0437)
+#define T25 (0x21e1cde6)
+#define T26 /* 0xc33707d6 */ (T_MASK ^ 0x3cc8f829)
+#define T27 /* 0xf4d50d87 */ (T_MASK ^ 0x0b2af278)
+#define T28 (0x455a14ed)
+#define T29 /* 0xa9e3e905 */ (T_MASK ^ 0x561c16fa)
+#define T30 /* 0xfcefa3f8 */ (T_MASK ^ 0x03105c07)
+#define T31 (0x676f02d9)
+#define T32 /* 0x8d2a4c8a */ (T_MASK ^ 0x72d5b375)
+#define T33 /* 0xfffa3942 */ (T_MASK ^ 0x0005c6bd)
+#define T34 /* 0x8771f681 */ (T_MASK ^ 0x788e097e)
+#define T35 (0x6d9d6122)
+#define T36 /* 0xfde5380c */ (T_MASK ^ 0x021ac7f3)
+#define T37 /* 0xa4beea44 */ (T_MASK ^ 0x5b4115bb)
+#define T38 (0x4bdecfa9)
+#define T39 /* 0xf6bb4b60 */ (T_MASK ^ 0x0944b49f)
+#define T40 /* 0xbebfbc70 */ (T_MASK ^ 0x4140438f)
+#define T41 (0x289b7ec6)
+#define T42 /* 0xeaa127fa */ (T_MASK ^ 0x155ed805)
+#define T43 /* 0xd4ef3085 */ (T_MASK ^ 0x2b10cf7a)
+#define T44 (0x04881d05)
+#define T45 /* 0xd9d4d039 */ (T_MASK ^ 0x262b2fc6)
+#define T46 /* 0xe6db99e5 */ (T_MASK ^ 0x1924661a)
+#define T47 (0x1fa27cf8)
+#define T48 /* 0xc4ac5665 */ (T_MASK ^ 0x3b53a99a)
+#define T49 /* 0xf4292244 */ (T_MASK ^ 0x0bd6ddbb)
+#define T50 (0x432aff97)
+#define T51 /* 0xab9423a7 */ (T_MASK ^ 0x546bdc58)
+#define T52 /* 0xfc93a039 */ (T_MASK ^ 0x036c5fc6)
+#define T53 (0x655b59c3)
+#define T54 /* 0x8f0ccc92 */ (T_MASK ^ 0x70f3336d)
+#define T55 /* 0xffeff47d */ (T_MASK ^ 0x00100b82)
+#define T56 /* 0x85845dd1 */ (T_MASK ^ 0x7a7ba22e)
+#define T57 (0x6fa87e4f)
+#define T58 /* 0xfe2ce6e0 */ (T_MASK ^ 0x01d3191f)
+#define T59 /* 0xa3014314 */ (T_MASK ^ 0x5cfebceb)
+#define T60 (0x4e0811a1)
+#define T61 /* 0xf7537e82 */ (T_MASK ^ 0x08ac817d)
+#define T62 /* 0xbd3af235 */ (T_MASK ^ 0x42c50dca)
+#define T63 (0x2ad7d2bb)
+#define T64 /* 0xeb86d391 */ (T_MASK ^ 0x14792c6e)
+
+static void
+md5_process(md5_state_t *pms, const md5_byte_t *data /*[64]*/)
+{
+	md5_word_t a = pms->abcd[0], b = pms->abcd[1], c = pms->abcd[2],
+	           d = pms->abcd[3];
+	md5_word_t t;
+#if BYTE_ORDER > 0
+	/* Define storage only for big-endian CPUs. */
+	md5_word_t X[16];
+#else
+	/* Define storage for little-endian or both types of CPUs. */
+	md5_word_t xbuf[16];
+	const md5_word_t *X;
+#endif
+
+	{
+#if BYTE_ORDER == 0
+		/*
+		 * Determine dynamically whether this is a big-endian or
+		 * little-endian machine, since we can use a more efficient
+		 * algorithm on the latter.
+		 */
+		static const int w = 1;
+
+		if (*((const md5_byte_t *)&w)) /* dynamic little-endian */
+#endif
+#if BYTE_ORDER <= 0 /* little-endian */
+		{
+			/*
+			 * On little-endian machines, we can process properly aligned
+			 * data without copying it.
+			 */
+			if (!((data - (const md5_byte_t *)0) & 3)) {
+				/* data are properly aligned, a direct assignment is possible */
+				/* cast through a (void *) should avoid a compiler warning,
+				   see
+				   https://github.com/bel2125/civetweb/issues/94#issuecomment-98112861
+				   */
+				X = (const md5_word_t *)(const void *)data;
+			} else {
+				/* not aligned */
+				memcpy(xbuf, data, 64);
+				X = xbuf;
+			}
+		}
+#endif
+#if BYTE_ORDER == 0
+		else /* dynamic big-endian */
+#endif
+#if BYTE_ORDER >= 0 /* big-endian */
+		{
+			/*
+			 * On big-endian machines, we must arrange the bytes in the
+			 * right order.
+			 */
+			const md5_byte_t *xp = data;
+			int i;
+
+#if BYTE_ORDER == 0
+			X = xbuf; /* (dynamic only) */
+#else
+#define xbuf X /* (static only) */
+#endif
+			for (i = 0; i < 16; ++i, xp += 4)
+				xbuf[i] = (md5_word_t)(xp[0]) + (md5_word_t)(xp[1] << 8)
+				          + (md5_word_t)(xp[2] << 16)
+				          + (md5_word_t)(xp[3] << 24);
+		}
+#endif
+	}
+
+#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32 - (n))))
+
+/* Round 1. */
+/* Let [abcd k s i] denote the operation
+   a = b + ((a + F(b,c,d) + X[k] + T[i]) <<< s). */
+#define F(x, y, z) (((x) & (y)) | (~(x) & (z)))
+#define SET(a, b, c, d, k, s, Ti)                                              \
+	t = a + F(b, c, d) + X[k] + Ti;                                            \
+	a = ROTATE_LEFT(t, s) + b
+
+	/* Do the following 16 operations. */
+	SET(a, b, c, d, 0, 7, T1);
+	SET(d, a, b, c, 1, 12, T2);
+	SET(c, d, a, b, 2, 17, T3);
+	SET(b, c, d, a, 3, 22, T4);
+	SET(a, b, c, d, 4, 7, T5);
+	SET(d, a, b, c, 5, 12, T6);
+	SET(c, d, a, b, 6, 17, T7);
+	SET(b, c, d, a, 7, 22, T8);
+	SET(a, b, c, d, 8, 7, T9);
+	SET(d, a, b, c, 9, 12, T10);
+	SET(c, d, a, b, 10, 17, T11);
+	SET(b, c, d, a, 11, 22, T12);
+	SET(a, b, c, d, 12, 7, T13);
+	SET(d, a, b, c, 13, 12, T14);
+	SET(c, d, a, b, 14, 17, T15);
+	SET(b, c, d, a, 15, 22, T16);
+#undef SET
+
+/* Round 2. */
+/* Let [abcd k s i] denote the operation
+     a = b + ((a + G(b,c,d) + X[k] + T[i]) <<< s). */
+#define G(x, y, z) (((x) & (z)) | ((y) & ~(z)))
+#define SET(a, b, c, d, k, s, Ti)                                              \
+	t = a + G(b, c, d) + X[k] + Ti;                                            \
+	a = ROTATE_LEFT(t, s) + b
+
+	/* Do the following 16 operations. */
+	SET(a, b, c, d, 1, 5, T17);
+	SET(d, a, b, c, 6, 9, T18);
+	SET(c, d, a, b, 11, 14, T19);
+	SET(b, c, d, a, 0, 20, T20);
+	SET(a, b, c, d, 5, 5, T21);
+	SET(d, a, b, c, 10, 9, T22);
+	SET(c, d, a, b, 15, 14, T23);
+	SET(b, c, d, a, 4, 20, T24);
+	SET(a, b, c, d, 9, 5, T25);
+	SET(d, a, b, c, 14, 9, T26);
+	SET(c, d, a, b, 3, 14, T27);
+	SET(b, c, d, a, 8, 20, T28);
+	SET(a, b, c, d, 13, 5, T29);
+	SET(d, a, b, c, 2, 9, T30);
+	SET(c, d, a, b, 7, 14, T31);
+	SET(b, c, d, a, 12, 20, T32);
+#undef SET
+
+/* Round 3. */
+/* Let [abcd k s t] denote the operation
+     a = b + ((a + H(b,c,d) + X[k] + T[i]) <<< s). */
+#define H(x, y, z) ((x) ^ (y) ^ (z))
+#define SET(a, b, c, d, k, s, Ti)                                              \
+	t = a + H(b, c, d) + X[k] + Ti;                                            \
+	a = ROTATE_LEFT(t, s) + b
+
+	/* Do the following 16 operations. */
+	SET(a, b, c, d, 5, 4, T33);
+	SET(d, a, b, c, 8, 11, T34);
+	SET(c, d, a, b, 11, 16, T35);
+	SET(b, c, d, a, 14, 23, T36);
+	SET(a, b, c, d, 1, 4, T37);
+	SET(d, a, b, c, 4, 11, T38);
+	SET(c, d, a, b, 7, 16, T39);
+	SET(b, c, d, a, 10, 23, T40);
+	SET(a, b, c, d, 13, 4, T41);
+	SET(d, a, b, c, 0, 11, T42);
+	SET(c, d, a, b, 3, 16, T43);
+	SET(b, c, d, a, 6, 23, T44);
+	SET(a, b, c, d, 9, 4, T45);
+	SET(d, a, b, c, 12, 11, T46);
+	SET(c, d, a, b, 15, 16, T47);
+	SET(b, c, d, a, 2, 23, T48);
+#undef SET
+
+/* Round 4. */
+/* Let [abcd k s t] denote the operation
+     a = b + ((a + I(b,c,d) + X[k] + T[i]) <<< s). */
+#define I(x, y, z) ((y) ^ ((x) | ~(z)))
+#define SET(a, b, c, d, k, s, Ti)                                              \
+	t = a + I(b, c, d) + X[k] + Ti;                                            \
+	a = ROTATE_LEFT(t, s) + b
+
+	/* Do the following 16 operations. */
+	SET(a, b, c, d, 0, 6, T49);
+	SET(d, a, b, c, 7, 10, T50);
+	SET(c, d, a, b, 14, 15, T51);
+	SET(b, c, d, a, 5, 21, T52);
+	SET(a, b, c, d, 12, 6, T53);
+	SET(d, a, b, c, 3, 10, T54);
+	SET(c, d, a, b, 10, 15, T55);
+	SET(b, c, d, a, 1, 21, T56);
+	SET(a, b, c, d, 8, 6, T57);
+	SET(d, a, b, c, 15, 10, T58);
+	SET(c, d, a, b, 6, 15, T59);
+	SET(b, c, d, a, 13, 21, T60);
+	SET(a, b, c, d, 4, 6, T61);
+	SET(d, a, b, c, 11, 10, T62);
+	SET(c, d, a, b, 2, 15, T63);
+	SET(b, c, d, a, 9, 21, T64);
+#undef SET
+
+	/* Then perform the following additions. (That is increment each
+	   of the four registers by the value it had before this block
+	   was started.) */
+	pms->abcd[0] += a;
+	pms->abcd[1] += b;
+	pms->abcd[2] += c;
+	pms->abcd[3] += d;
+}
+
+MD5_STATIC void
+md5_init(md5_state_t *pms)
+{
+	pms->count[0] = pms->count[1] = 0;
+	pms->abcd[0] = 0x67452301;
+	pms->abcd[1] = /*0xefcdab89*/ T_MASK ^ 0x10325476;
+	pms->abcd[2] = /*0x98badcfe*/ T_MASK ^ 0x67452301;
+	pms->abcd[3] = 0x10325476;
+}
+
+MD5_STATIC void
+md5_append(md5_state_t *pms, const md5_byte_t *data, size_t nbytes)
+{
+	const md5_byte_t *p = data;
+	size_t left = nbytes;
+	size_t offset = (pms->count[0] >> 3) & 63;
+	md5_word_t nbits = (md5_word_t)(nbytes << 3);
+
+	if (nbytes <= 0)
+		return;
+
+	/* Update the message length. */
+	pms->count[1] += (md5_word_t)(nbytes >> 29);
+	pms->count[0] += nbits;
+	if (pms->count[0] < nbits)
+		pms->count[1]++;
+
+	/* Process an initial partial block. */
+	if (offset) {
+		size_t copy = (offset + nbytes > 64 ? 64 - offset : nbytes);
+
+		memcpy(pms->buf + offset, p, copy);
+		if (offset + copy < 64)
+			return;
+		p += copy;
+		left -= copy;
+		md5_process(pms, pms->buf);
+	}
+
+	/* Process full blocks. */
+	for (; left >= 64; p += 64, left -= 64)
+		md5_process(pms, p);
+
+	/* Process a final partial block. */
+	if (left)
+		memcpy(pms->buf, p, left);
+}
+
+MD5_STATIC void
+md5_finish(md5_state_t *pms, md5_byte_t digest[16])
+{
+	static const md5_byte_t pad[64] = {0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+	                                   0,    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+	                                   0,    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+	                                   0,    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+	                                   0,    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
+	md5_byte_t data[8];
+	int i;
+
+	/* Save the length before padding. */
+	for (i = 0; i < 8; ++i)
+		data[i] = (md5_byte_t)(pms->count[i >> 2] >> ((i & 3) << 3));
+	/* Pad to 56 bytes mod 64. */
+	md5_append(pms, pad, ((55 - (pms->count[0] >> 3)) & 63) + 1);
+	/* Append the length. */
+	md5_append(pms, data, 8);
+	for (i = 0; i < 16; ++i)
+		digest[i] = (md5_byte_t)(pms->abcd[i >> 2] >> ((i & 3) << 3));
+}


[22/51] [partial] nifi-minifi-cpp git commit: MINIFI-183 Added civet 1.9.1 sources Added onScheduled hook Added initial two-way TLS-enabled ListenHTTP implementation

Posted by al...@apache.org.
http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/licenses/commonjs.txt
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/licenses/commonjs.txt b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/licenses/commonjs.txt
new file mode 100644
index 0000000..54a1cd7
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/licenses/commonjs.txt
@@ -0,0 +1,2 @@
+CommonJS specification snapshots are included in the references/
+directory.  CommonJS is under the MIT license: http://www.commonjs.org/.

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/licenses/lua.txt
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/licenses/lua.txt b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/licenses/lua.txt
new file mode 100644
index 0000000..24e65f1
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/licenses/lua.txt
@@ -0,0 +1 @@
+Lua is under the MIT license: http://www.lua.org/license.html.

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/licenses/murmurhash2.txt
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/licenses/murmurhash2.txt b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/licenses/murmurhash2.txt
new file mode 100644
index 0000000..7029925
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/licenses/murmurhash2.txt
@@ -0,0 +1,21 @@
+The MIT License
+
+Copyright (c) <year> <copyright holders>
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/mandel.js
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/mandel.js b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/mandel.js
new file mode 100644
index 0000000..79b5195
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/mandel.js
@@ -0,0 +1,53 @@
+/*
+ *  Mandelbrot example:
+ *
+ *    $ ./duk mandel.js
+ *    [...]
+ */
+
+function mandel() {
+    var w = 76, h = 28, iter = 100;
+    var i, j, k, c;
+    var x0, y0, xx, yy, xx2, yy2;
+    var line;
+
+    for (i = 0; i < h; i++) {
+        y0 = (i / h) * 2.5 - 1.25;
+
+        for (j = 0, line = []; j < w; j++) {
+            x0 = (j / w) * 3.0 - 2.0;
+
+            for (k = 0, xx = 0, yy = 0, c = '#'; k < iter; k++) {
+                /* z -> z^2 + c
+                 *   -> (xx+i*yy)^2 + (x0+i*y0)
+                 *   -> xx*xx+i*2*xx*yy-yy*yy + x0 + i*y0
+                 *   -> (xx*xx - yy*yy + x0) + i*(2*xx*yy + y0)
+                 */
+
+                xx2 = xx*xx; yy2 = yy*yy;
+
+                if (xx2 + yy2 < 4.0) {
+                    yy = 2*xx*yy + y0;
+                    xx = xx2 - yy2 + x0;
+                } else {
+                    /* xx^2 + yy^2 >= 4.0 */
+                    if (k < 3) { c = '.'; }
+                    else if (k < 5) { c = ','; }
+                    else if (k < 10) { c = '-'; }
+                    else { c = '='; }
+                    break;
+                }
+            }
+
+            line.push(c);
+        }
+
+        print(line.join(''));
+    }
+}
+
+try {
+    mandel();
+} catch (e) {
+    print(e.stack || e);
+}

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/polyfills/console-minimal.js
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/polyfills/console-minimal.js b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/polyfills/console-minimal.js
new file mode 100644
index 0000000..1876c5f
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/polyfills/console-minimal.js
@@ -0,0 +1,20 @@
+/*
+ *  Minimal console.log() polyfill
+ */
+
+if (typeof console === 'undefined') {
+    Object.defineProperty(this, 'console', {
+        value: {}, writable: true, enumerable: false, configurable: true
+    });
+}
+if (typeof console.log === 'undefined') {
+    (function () {
+        var origPrint = print;  // capture in closure in case changed later
+        Object.defineProperty(this.console, 'log', {
+            value: function () {
+                var strArgs = Array.prototype.map.call(arguments, function (v) { return String(v); });
+                origPrint(Array.prototype.join.call(strArgs, ' '));
+            }, writable: true, enumerable: false, configurable: true
+        });
+    })();
+}

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/polyfills/duktape-error-setter-nonwritable.js
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/polyfills/duktape-error-setter-nonwritable.js b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/polyfills/duktape-error-setter-nonwritable.js
new file mode 100644
index 0000000..236c706
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/polyfills/duktape-error-setter-nonwritable.js
@@ -0,0 +1,20 @@
+/*
+ *  Ensure Error .fileName, .lineNumber, and .stack are not directly writable,
+ *  but can be written using Object.defineProperty().  This matches Duktape
+ *  1.3.0 and prior.
+ *
+ *  See: https://github.com/svaarala/duktape/pull/390.
+ */
+
+(function () {
+    var err = new Error('test');
+    err.fileName = 999;
+    if (err.fileName !== 999) { return; }  // already non-writable
+
+    var fn = new Function('');  // nop
+    Object.defineProperties(Error.prototype, {
+        fileName: { set: fn },
+        lineNumber: { set: fn },
+        stack: { set: fn }
+    });
+})();

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/polyfills/duktape-error-setter-writable.js
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/polyfills/duktape-error-setter-writable.js b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/polyfills/duktape-error-setter-writable.js
new file mode 100644
index 0000000..5d487cd
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/polyfills/duktape-error-setter-writable.js
@@ -0,0 +1,19 @@
+/*
+ *  Ensure Error .fileName, .lineNumber, and .stack are directly writable
+ *  without having to use Object.defineProperty().  This matches Duktape
+ *  1.4.0 behavior.
+ *
+ *  See: https://github.com/svaarala/duktape/pull/390.
+ */
+
+(function () {
+    var err = new Error('test');
+    err.fileName = 999;
+    if (err.fileName === 999) { return; }  // already writable
+
+    Object.defineProperties(Error.prototype, {
+        fileName: { set: new Function('v', 'Object.defineProperty(this, "fileName", { value: v, writable: true, enumerable: false, configurable: true });') },
+        lineNumber: { set: new Function('v', 'Object.defineProperty(this, "lineNumber", { value: v, writable: true, enumerable: false, configurable: true });') },
+        stack: { set: new Function('v', 'Object.defineProperty(this, "stack", { value: v, writable: true, enumerable: false, configurable: true });') },
+    });
+})();

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/polyfills/duktape-isfastint.js
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/polyfills/duktape-isfastint.js b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/polyfills/duktape-isfastint.js
new file mode 100644
index 0000000..68219e4
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/polyfills/duktape-isfastint.js
@@ -0,0 +1,38 @@
+/*
+ *  Helper to check if a number is internally represented as a fastint:
+ *
+ *    if (Duktape.isFastint(x)) {
+ *        print('fastint');
+ *    } else {
+ *        print('not a fastint (or not a number)');
+ *    }
+ *
+ *  NOTE: This helper depends on the internal tag numbering (defined in
+ *  duk_tval.h) which is both version specific and depends on whether
+ *  duk_tval is packed or not.
+ */
+
+if (typeof Duktape === 'object') {
+    if (typeof Duktape.fastintTag === 'undefined') {
+        Object.defineProperty(Duktape, 'fastintTag', {
+            /* Tag number depends on duk_tval packing. */
+            value: (Duktape.info(true)[1] >= 0xfff0) ?
+                    0xfff1 /* tag for packed duk_tval */ :
+                    1 /* tag for unpacked duk_tval */,
+            writable: false,
+            enumerable: false,
+            configurable: true
+        });
+    }
+    if (typeof Duktape.isFastint === 'undefined') {
+        Object.defineProperty(Duktape, 'isFastint', {
+            value: function (v) {
+                return Duktape.info(v)[0] === 4 &&                 /* public type is DUK_TYPE_NUMBER */
+                       Duktape.info(v)[1] === Duktape.fastintTag;  /* internal tag is fastint */
+            },
+            writable: false,
+            enumerable: false,
+            configurable: true
+        });
+    }
+}

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/polyfills/object-assign.js
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/polyfills/object-assign.js b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/polyfills/object-assign.js
new file mode 100644
index 0000000..dfa5a44
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/polyfills/object-assign.js
@@ -0,0 +1,45 @@
+/*
+ *  Object.assign(), described in E6 Section 19.1.2.1
+ *
+ *  http://www.ecma-international.org/ecma-262/6.0/index.html#sec-object.assign
+ */
+
+if (typeof Object.assign === 'undefined') {
+   Object.defineProperty(Object, 'assign', {
+       value: function (target) {
+           var i, n, j, m, k;
+           var source, keys;
+           var gotError;
+           var pendingError;
+
+           if (target == null) {
+               throw new Exception('target null or undefined');
+           }
+
+           for (i = 1, n = arguments.length; i < n; i++) {
+               source = arguments[i];
+               if (source == null) {
+                   continue;  // null or undefined
+               }
+               source = Object(source);
+               keys = Object.keys(source);  // enumerable own keys
+
+               for (j = 0, m = keys.length; j < m; j++) {
+                   k = keys[j];
+                   try {
+                       target[k] = source[k];
+                   } catch (e) {
+                       if (!gotError) {
+                           gotError = true;
+                           pendingError = e;
+                       }
+                   }
+               }
+           }
+
+           if (gotError) {
+               throw pendingError;
+           }
+       }, writable: true, enumerable: false, configurable: true
+   });
+}

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/polyfills/object-prototype-definegetter.js
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/polyfills/object-prototype-definegetter.js b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/polyfills/object-prototype-definegetter.js
new file mode 100644
index 0000000..8d8cabb
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/polyfills/object-prototype-definegetter.js
@@ -0,0 +1,11 @@
+/*
+ *  Object.prototype.__defineGetter__ polyfill
+ */
+
+if (typeof Object.prototype.__defineGetter__ === 'undefined') {
+    Object.defineProperty(Object.prototype, '__defineGetter__', {
+        value: function (n, f) {
+            Object.defineProperty(this, n, { enumerable: true, configurable: true, get: f });
+        }, writable: true, enumerable: false, configurable: true
+    });
+}

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/polyfills/object-prototype-definesetter.js
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/polyfills/object-prototype-definesetter.js b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/polyfills/object-prototype-definesetter.js
new file mode 100644
index 0000000..6bd1722
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/polyfills/object-prototype-definesetter.js
@@ -0,0 +1,11 @@
+/*
+ *  Object.prototype.__defineSetter__ polyfill
+ */
+
+if (typeof Object.prototype.__defineSetter__ === 'undefined') {
+    Object.defineProperty(Object.prototype, '__defineSetter__', {
+        value: function (n, f) {
+            Object.defineProperty(this, n, { enumerable: true, configurable: true, set: f });
+        }, writable: true, enumerable: false, configurable: true
+    });
+}

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/polyfills/performance-now.js
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/polyfills/performance-now.js b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/polyfills/performance-now.js
new file mode 100644
index 0000000..dfb0a1d
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/polyfills/performance-now.js
@@ -0,0 +1,25 @@
+/*
+ *  Performance.now() polyfill
+ *
+ *  http://www.w3.org/TR/hr-time/#sec-high-resolution-time
+ *
+ *  Dummy implementation which uses the Date built-in and has no higher
+ *  resolution.  If/when Duktape has a built-in high resolution timer
+ *  interface, reimplement this.
+ */
+
+var _perfNowZeroTime = Date.now();
+
+if (typeof Performance === 'undefined') {
+    Object.defineProperty(this, 'Performance', {
+        value: {},
+        writable: true, enumerable: false, configurable: true
+    });
+}
+if (typeof Performance.now === 'undefined') {
+    Object.defineProperty(Performance, 'now', {
+        value: function () {
+            return Date.now() - _perfNowZeroTime;
+        }, writable: true, enumerable: false, configurable: true
+    });
+}


[20/51] [partial] nifi-minifi-cpp git commit: MINIFI-183 Added civet 1.9.1 sources Added onScheduled hook Added initial two-way TLS-enabled ListenHTTP implementation

Posted by al...@apache.org.
http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-noline/duktape.c
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-noline/duktape.c b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-noline/duktape.c
new file mode 100644
index 0000000..9a65f55
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-noline/duktape.c
@@ -0,0 +1,86570 @@
+/*
+ *  Single source autogenerated distributable for Duktape 1.5.2.
+ *
+ *  Git commit cad34ae155acb0846545ca6bf2d29f9463b22bbb (v1.5.2).
+ *  Git branch HEAD.
+ *
+ *  See Duktape AUTHORS.rst and LICENSE.txt for copyright and
+ *  licensing information.
+ */
+
+/* LICENSE.txt */
+/*
+*  ===============
+*  Duktape license
+*  ===============
+*
+*  (http://opensource.org/licenses/MIT)
+*
+*  Copyright (c) 2013-2016 by Duktape authors (see AUTHORS.rst)
+*
+*  Permission is hereby granted, free of charge, to any person obtaining a copy
+*  of this software and associated documentation files (the "Software"), to deal
+*  in the Software without restriction, including without limitation the rights
+*  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+*  copies of the Software, and to permit persons to whom the Software is
+*  furnished to do so, subject to the following conditions:
+*
+*  The above copyright notice and this permission notice shall be included in
+*  all copies or substantial portions of the Software.
+*
+*  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+*  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+*  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+*  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+*  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+*  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+*  THE SOFTWARE.
+*/
+/* AUTHORS.rst */
+/*
+*  ===============
+*  Duktape authors
+*  ===============
+*
+*  Copyright
+*  =========
+*
+*  Duktape copyrights are held by its authors.  Each author has a copyright
+*  to their contribution, and agrees to irrevocably license the contribution
+*  under the Duktape ``LICENSE.txt``.
+*
+*  Authors
+*  =======
+*
+*  Please include an e-mail address, a link to your GitHub profile, or something
+*  similar to allow your contribution to be identified accurately.
+*
+*  The following people have contributed code, website contents, or Wiki contents,
+*  and agreed to irrevocably license their contributions under the Duktape
+*  ``LICENSE.txt`` (in order of appearance):
+*
+*  * Sami Vaarala <sa...@iki.fi>
+*  * Niki Dobrev
+*  * Andreas \u00d6man <an...@lonelycoder.com>
+*  * L\u00e1szl\u00f3 Lang\u00f3 <ll...@partner.samsung.com>
+*  * Legimet <le...@gmail.com>
+*  * Karl Skomski <ka...@skomski.com>
+*  * Bruce Pascoe <fa...@gmail.com>
+*  * Ren\u00e9 Hollander <re...@rene8888.at>
+*  * Julien Hamaide (https://github.com/crazyjul)
+*  * Sebastian G\u00f6tte (https://github.com/jaseg)
+*
+*  Other contributions
+*  ===================
+*
+*  The following people have contributed something other than code (e.g. reported
+*  bugs, provided ideas, etc; roughly in order of appearance):
+*
+*  * Greg Burns
+*  * Anthony Rabine
+*  * Carlos Costa
+*  * Aur\u00e9lien Bouilland
+*  * Preet Desai (Pris Matic)
+*  * judofyr (http://www.reddit.com/user/judofyr)
+*  * Jason Woofenden
+*  * Micha\u0142 Przyby\u015b
+*  * Anthony Howe
+*  * Conrad Pankoff
+*  * Jim Schimpf
+*  * Rajaran Gaunker (https://github.com/zimbabao)
+*  * Andreas \u00d6man
+*  * Doug Sanden
+*  * Josh Engebretson (https://github.com/JoshEngebretson)
+*  * Remo Eichenberger (https://github.com/remoe)
+*  * Mamod Mehyar (https://github.com/mamod)
+*  * David Demelier (https://github.com/markand)
+*  * Tim Caswell (https://github.com/creationix)
+*  * Mitchell Blank Jr (https://github.com/mitchblank)
+*  * https://github.com/yushli
+*  * Seo Sanghyeon (https://github.com/sanxiyn)
+*  * Han ChoongWoo (https://github.com/tunz)
+*  * Joshua Peek (https://github.com/josh)
+*  * Bruce E. Pascoe (https://github.com/fatcerberus)
+*  * https://github.com/Kelledin
+*  * https://github.com/sstruchtrup
+*  * Michael Drake (https://github.com/tlsa)
+*  * https://github.com/chris-y
+*  * Laurent Zubiaur (https://github.com/lzubiaur)
+*  * Ole Andr\u00e9 Vadla Ravn\u00e5s (https://github.com/oleavr)
+*
+*  If you are accidentally missing from this list, send me an e-mail
+*  (``sami.vaarala@iki.fi``) and I'll fix the omission.
+*/
+/*
+ *  Top-level include file to be used for all (internal) source files.
+ *
+ *  Source files should not include individual header files, as they
+ *  have not been designed to be individually included.
+ */
+
+#ifndef DUK_INTERNAL_H_INCLUDED
+#define DUK_INTERNAL_H_INCLUDED
+
+/*
+ *  The 'duktape.h' header provides the public API, but also handles all
+ *  compiler and platform specific feature detection, Duktape feature
+ *  resolution, inclusion of system headers, etc.  These have been merged
+ *  because the public API is also dependent on e.g. detecting appropriate
+ *  C types which is quite platform/compiler specific especially for a non-C99
+ *  build.  The public API is also dependent on the resolved feature set.
+ *
+ *  Some actions taken by the merged header (such as including system headers)
+ *  are not appropriate for building a user application.  The define
+ *  DUK_COMPILING_DUKTAPE allows the merged header to skip/include some
+ *  sections depending on what is being built.
+ */
+
+#define DUK_COMPILING_DUKTAPE
+#include "duktape.h"
+
+/*
+ *  User declarations, e.g. prototypes for user functions used by Duktape
+ *  macros.  Concretely, if DUK_USE_PANIC_HANDLER is used and the macro
+ *  value calls a user function, it needs to be declared for Duktape
+ *  compilation to avoid warnings.
+ */
+
+DUK_USE_USER_DECLARE()
+
+/*
+ *  Duktape includes (other than duk_features.h)
+ *
+ *  The header files expect to be included in an order which satisfies header
+ *  dependencies correctly (the headers themselves don't include any other
+ *  includes).  Forward declarations are used to break circular struct/typedef
+ *  dependencies.
+ */
+
+#ifndef DUK_REPLACEMENTS_H_INCLUDED
+#define DUK_REPLACEMENTS_H_INCLUDED
+
+#if !defined(DUK_SINGLE_FILE)
+#if defined(DUK_USE_COMPUTED_INFINITY)
+DUK_INTERNAL_DECL double duk_computed_infinity;
+#endif
+#if defined(DUK_USE_COMPUTED_NAN)
+DUK_INTERNAL_DECL double duk_computed_nan;
+#endif
+#if defined(DUK_USE_REPL_FPCLASSIFY)
+DUK_INTERNAL_DECL int duk_repl_fpclassify(double x);
+#endif
+#if defined(DUK_USE_REPL_SIGNBIT)
+DUK_INTERNAL_DECL int duk_repl_signbit(double x);
+#endif
+#if defined(DUK_USE_REPL_ISFINITE)
+DUK_INTERNAL_DECL int duk_repl_isfinite(double x);
+#endif
+#if defined(DUK_USE_REPL_ISNAN)
+DUK_INTERNAL_DECL int duk_repl_isnan(double x);
+#endif
+#if defined(DUK_USE_REPL_ISINF)
+DUK_INTERNAL_DECL int duk_repl_isinf(double x);
+#endif
+#endif  /* !DUK_SINGLE_FILE */
+
+#endif  /* DUK_REPLACEMENTS_H_INCLUDED */
+/*
+ *  Wrapper for jmp_buf.
+ *
+ *  This is used because jmp_buf is an array type for backward compatibility.
+ *  Wrapping jmp_buf in a struct makes pointer references, sizeof, etc,
+ *  behave more intuitively.
+ *
+ *  http://en.wikipedia.org/wiki/Setjmp.h#Member_types
+ */
+
+#ifndef DUK_JMPBUF_H_INCLUDED
+#define DUK_JMPBUF_H_INCLUDED
+
+#if defined(DUK_USE_CPP_EXCEPTIONS)
+struct duk_jmpbuf {
+	duk_small_int_t dummy;  /* unused */
+};
+#else
+struct duk_jmpbuf {
+	DUK_JMPBUF_TYPE jb;
+};
+#endif
+
+#endif  /* DUK_JMPBUF_H_INCLUDED */
+/*
+ *  Exception for Duktape internal throws when C++ exceptions are used
+ *  for long control transfers.
+ *
+ *  Doesn't inherit from any exception base class to minimize the chance
+ *  that user code would accidentally catch this exception.
+ */
+
+#ifndef DUK_EXCEPTION_H_INCLUDED
+#define DUK_EXCEPTION_H_INCLUDED
+
+#if defined(DUK_USE_CPP_EXCEPTIONS)
+class duk_internal_exception {
+	/* intentionally empty */
+};
+#endif
+
+#endif  /* DUK_EXCEPTION_H_INCLUDED */
+/*
+ *  Forward declarations for all Duktape structures.
+ */
+
+#ifndef DUK_FORWDECL_H_INCLUDED
+#define DUK_FORWDECL_H_INCLUDED
+
+/*
+ *  Forward declarations
+ */
+
+#if defined(DUK_USE_CPP_EXCEPTIONS)
+class duk_internal_exception;
+#else
+struct duk_jmpbuf;
+#endif
+
+/* duk_tval intentionally skipped */
+struct duk_heaphdr;
+struct duk_heaphdr_string;
+struct duk_hstring;
+struct duk_hstring_external;
+struct duk_hobject;
+struct duk_hcompiledfunction;
+struct duk_hnativefunction;
+struct duk_hthread;
+struct duk_hbufferobject;
+struct duk_hbuffer;
+struct duk_hbuffer_fixed;
+struct duk_hbuffer_dynamic;
+struct duk_hbuffer_external;
+
+struct duk_propaccessor;
+union duk_propvalue;
+struct duk_propdesc;
+
+struct duk_heap;
+struct duk_breakpoint;
+
+struct duk_activation;
+struct duk_catcher;
+struct duk_strcache;
+struct duk_ljstate;
+struct duk_strtab_entry;
+
+#ifdef DUK_USE_DEBUG
+struct duk_fixedbuffer;
+#endif
+
+struct duk_bitdecoder_ctx;
+struct duk_bitencoder_ctx;
+struct duk_bufwriter_ctx;
+
+struct duk_token;
+struct duk_re_token;
+struct duk_lexer_point;
+struct duk_lexer_ctx;
+struct duk_lexer_codepoint;
+
+struct duk_compiler_instr;
+struct duk_compiler_func;
+struct duk_compiler_ctx;
+
+struct duk_re_matcher_ctx;
+struct duk_re_compiler_ctx;
+
+#if defined(DUK_USE_CPP_EXCEPTIONS)
+/* no typedef */
+#else
+typedef struct duk_jmpbuf duk_jmpbuf;
+#endif
+
+/* duk_tval intentionally skipped */
+typedef struct duk_heaphdr duk_heaphdr;
+typedef struct duk_heaphdr_string duk_heaphdr_string;
+typedef struct duk_hstring duk_hstring;
+typedef struct duk_hstring_external duk_hstring_external;
+typedef struct duk_hobject duk_hobject;
+typedef struct duk_hcompiledfunction duk_hcompiledfunction;
+typedef struct duk_hnativefunction duk_hnativefunction;
+typedef struct duk_hbufferobject duk_hbufferobject;
+typedef struct duk_hthread duk_hthread;
+typedef struct duk_hbuffer duk_hbuffer;
+typedef struct duk_hbuffer_fixed duk_hbuffer_fixed;
+typedef struct duk_hbuffer_dynamic duk_hbuffer_dynamic;
+typedef struct duk_hbuffer_external duk_hbuffer_external;
+
+typedef struct duk_propaccessor duk_propaccessor;
+typedef union duk_propvalue duk_propvalue;
+typedef struct duk_propdesc duk_propdesc;
+
+typedef struct duk_heap duk_heap;
+typedef struct duk_breakpoint duk_breakpoint;
+
+typedef struct duk_activation duk_activation;
+typedef struct duk_catcher duk_catcher;
+typedef struct duk_strcache duk_strcache;
+typedef struct duk_ljstate duk_ljstate;
+typedef struct duk_strtab_entry duk_strtab_entry;
+
+#ifdef DUK_USE_DEBUG
+typedef struct duk_fixedbuffer duk_fixedbuffer;
+#endif
+
+typedef struct duk_bitdecoder_ctx duk_bitdecoder_ctx;
+typedef struct duk_bitencoder_ctx duk_bitencoder_ctx;
+typedef struct duk_bufwriter_ctx duk_bufwriter_ctx;
+
+typedef struct duk_token duk_token;
+typedef struct duk_re_token duk_re_token;
+typedef struct duk_lexer_point duk_lexer_point;
+typedef struct duk_lexer_ctx duk_lexer_ctx;
+typedef struct duk_lexer_codepoint duk_lexer_codepoint;
+
+typedef struct duk_compiler_instr duk_compiler_instr;
+typedef struct duk_compiler_func duk_compiler_func;
+typedef struct duk_compiler_ctx duk_compiler_ctx;
+
+typedef struct duk_re_matcher_ctx duk_re_matcher_ctx;
+typedef struct duk_re_compiler_ctx duk_re_compiler_ctx;
+
+#endif  /* DUK_FORWDECL_H_INCLUDED */
+/*
+ *  Tagged type definition (duk_tval) and accessor macros.
+ *
+ *  Access all fields through the accessor macros, as the representation
+ *  is quite tricky.
+ *
+ *  There are two packed type alternatives: an 8-byte representation
+ *  based on an IEEE double (preferred for compactness), and a 12-byte
+ *  representation (portability).  The latter is needed also in e.g.
+ *  64-bit environments (it usually pads to 16 bytes per value).
+ *
+ *  Selecting the tagged type format involves many trade-offs (memory
+ *  use, size and performance of generated code, portability, etc),
+ *  see doc/types.rst for a detailed discussion (especially of how the
+ *  IEEE double format is used to pack tagged values).
+ *
+ *  NB: because macro arguments are often expressions, macros should
+ *  avoid evaluating their argument more than once.
+ */
+
+#ifndef DUK_TVAL_H_INCLUDED
+#define DUK_TVAL_H_INCLUDED
+
+/* sanity */
+#if !defined(DUK_USE_DOUBLE_LE) && !defined(DUK_USE_DOUBLE_ME) && !defined(DUK_USE_DOUBLE_BE)
+#error unsupported: cannot determine byte order variant
+#endif
+
+#if defined(DUK_USE_PACKED_TVAL)
+/* ======================================================================== */
+
+/*
+ *  Packed 8-byte representation
+ */
+
+/* use duk_double_union as duk_tval directly */
+typedef union duk_double_union duk_tval;
+
+/* tags */
+#define DUK_TAG_NORMALIZED_NAN    0x7ff8UL   /* the NaN variant we use */
+/* avoid tag 0xfff0, no risk of confusion with negative infinity */
+#if defined(DUK_USE_FASTINT)
+#define DUK_TAG_FASTINT           0xfff1UL   /* embed: integer value */
+#endif
+#define DUK_TAG_UNUSED            0xfff2UL   /* marker; not actual tagged value */
+#define DUK_TAG_UNDEFINED         0xfff3UL   /* embed: nothing */
+#define DUK_TAG_NULL              0xfff4UL   /* embed: nothing */
+#define DUK_TAG_BOOLEAN           0xfff5UL   /* embed: 0 or 1 (false or true) */
+/* DUK_TAG_NUMBER would logically go here, but it has multiple 'tags' */
+#define DUK_TAG_POINTER           0xfff6UL   /* embed: void ptr */
+#define DUK_TAG_LIGHTFUNC         0xfff7UL   /* embed: func ptr */
+#define DUK_TAG_STRING            0xfff8UL   /* embed: duk_hstring ptr */
+#define DUK_TAG_OBJECT            0xfff9UL   /* embed: duk_hobject ptr */
+#define DUK_TAG_BUFFER            0xfffaUL   /* embed: duk_hbuffer ptr */
+
+/* for convenience */
+#define DUK_XTAG_BOOLEAN_FALSE    0xfff50000UL
+#define DUK_XTAG_BOOLEAN_TRUE     0xfff50001UL
+
+/* two casts to avoid gcc warning: "warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]" */
+#if defined(DUK_USE_64BIT_OPS)
+#if defined(DUK_USE_DOUBLE_ME)
+#define DUK__TVAL_SET_TAGGEDPOINTER(v,h,tag)  do { \
+		(v)->ull[DUK_DBL_IDX_ULL0] = (((duk_uint64_t) (tag)) << 16) | (((duk_uint64_t) (duk_uint32_t) (h)) << 32); \
+	} while (0)
+#else
+#define DUK__TVAL_SET_TAGGEDPOINTER(v,h,tag)  do { \
+		(v)->ull[DUK_DBL_IDX_ULL0] = (((duk_uint64_t) (tag)) << 48) | ((duk_uint64_t) (duk_uint32_t) (h)); \
+	} while (0)
+#endif
+#else  /* DUK_USE_64BIT_OPS */
+#define DUK__TVAL_SET_TAGGEDPOINTER(v,h,tag)  do { \
+		(v)->ui[DUK_DBL_IDX_UI0] = ((duk_uint32_t) (tag)) << 16; \
+		(v)->ui[DUK_DBL_IDX_UI1] = (duk_uint32_t) (h); \
+	} while (0)
+#endif  /* DUK_USE_64BIT_OPS */
+
+#if defined(DUK_USE_64BIT_OPS)
+/* Double casting for pointer to avoid gcc warning (cast from pointer to integer of different size) */
+#if defined(DUK_USE_DOUBLE_ME)
+#define DUK__TVAL_SET_LIGHTFUNC(v,fp,flags)  do { \
+		(v)->ull[DUK_DBL_IDX_ULL0] = (((duk_uint64_t) DUK_TAG_LIGHTFUNC) << 16) | \
+		                             ((duk_uint64_t) (flags)) | \
+		                             (((duk_uint64_t) (duk_uint32_t) (fp)) << 32); \
+	} while (0)
+#else
+#define DUK__TVAL_SET_LIGHTFUNC(v,fp,flags)  do { \
+		(v)->ull[DUK_DBL_IDX_ULL0] = (((duk_uint64_t) DUK_TAG_LIGHTFUNC) << 48) | \
+		                             (((duk_uint64_t) (flags)) << 32) | \
+		                             ((duk_uint64_t) (duk_uint32_t) (fp)); \
+	} while (0)
+#endif
+#else  /* DUK_USE_64BIT_OPS */
+#define DUK__TVAL_SET_LIGHTFUNC(v,fp,flags)  do { \
+		(v)->ui[DUK_DBL_IDX_UI0] = (((duk_uint32_t) DUK_TAG_LIGHTFUNC) << 16) | ((duk_uint32_t) (flags)); \
+		(v)->ui[DUK_DBL_IDX_UI1] = (duk_uint32_t) (fp); \
+	} while (0)
+#endif  /* DUK_USE_64BIT_OPS */
+
+#if defined(DUK_USE_FASTINT)
+/* Note: masking is done for 'i' to deal with negative numbers correctly */
+#if defined(DUK_USE_DOUBLE_ME)
+#define DUK__TVAL_SET_FASTINT(v,i)  do { \
+		(v)->ui[DUK_DBL_IDX_UI0] = ((duk_uint32_t) DUK_TAG_FASTINT) << 16 | (((duk_uint32_t) ((i) >> 32)) & 0x0000ffffUL); \
+		(v)->ui[DUK_DBL_IDX_UI1] = (duk_uint32_t) (i); \
+	} while (0)
+#define DUK__TVAL_SET_FASTINT_U32(v,i)  do { \
+		(v)->ui[DUK_DBL_IDX_UI0] = ((duk_uint32_t) DUK_TAG_FASTINT) << 16; \
+		(v)->ui[DUK_DBL_IDX_UI1] = (duk_uint32_t) (i); \
+	} while (0)
+#else
+#define DUK__TVAL_SET_FASTINT(v,i)  do { \
+		(v)->ull[DUK_DBL_IDX_ULL0] = (((duk_uint64_t) DUK_TAG_FASTINT) << 48) | (((duk_uint64_t) (i)) & 0x0000ffffffffffffULL); \
+	} while (0)
+#define DUK__TVAL_SET_FASTINT_U32(v,i)  do { \
+		(v)->ull[DUK_DBL_IDX_ULL0] = (((duk_uint64_t) DUK_TAG_FASTINT) << 48) | (duk_uint64_t) (i); \
+	} while (0)
+#endif
+
+#define DUK__TVAL_SET_FASTINT_I32(v,i)  do { \
+		duk_int64_t duk__tmp = (duk_int64_t) (i); \
+		DUK_TVAL_SET_FASTINT((v), duk__tmp); \
+	} while (0)
+
+/* XXX: clumsy sign extend and masking of 16 topmost bits */
+#if defined(DUK_USE_DOUBLE_ME)
+#define DUK__TVAL_GET_FASTINT(v)      (((duk_int64_t) ((((duk_uint64_t) (v)->ui[DUK_DBL_IDX_UI0]) << 32) | ((duk_uint64_t) (v)->ui[DUK_DBL_IDX_UI1]))) << 16 >> 16)
+#else
+#define DUK__TVAL_GET_FASTINT(v)      ((((duk_int64_t) (v)->ull[DUK_DBL_IDX_ULL0]) << 16) >> 16)
+#endif
+#define DUK__TVAL_GET_FASTINT_U32(v)  ((v)->ui[DUK_DBL_IDX_UI1])
+#define DUK__TVAL_GET_FASTINT_I32(v)  ((duk_int32_t) (v)->ui[DUK_DBL_IDX_UI1])
+#endif  /* DUK_USE_FASTINT */
+
+#define DUK_TVAL_SET_UNDEFINED(v)  do { \
+		(v)->us[DUK_DBL_IDX_US0] = (duk_uint16_t) DUK_TAG_UNDEFINED; \
+	} while (0)
+#define DUK_TVAL_SET_UNUSED(v)  do { \
+		(v)->us[DUK_DBL_IDX_US0] = (duk_uint16_t) DUK_TAG_UNUSED; \
+	} while (0)
+#define DUK_TVAL_SET_NULL(v)  do { \
+		(v)->us[DUK_DBL_IDX_US0] = (duk_uint16_t) DUK_TAG_NULL; \
+	} while (0)
+
+#define DUK_TVAL_SET_BOOLEAN(v,val)         DUK_DBLUNION_SET_HIGH32((v), (((duk_uint32_t) DUK_TAG_BOOLEAN) << 16) | ((duk_uint32_t) (val)))
+
+#define DUK_TVAL_SET_NAN(v)                 DUK_DBLUNION_SET_NAN_FULL((v))
+
+/* Assumes that caller has normalized NaNs, otherwise trouble ahead. */
+#if defined(DUK_USE_FASTINT)
+#define DUK_TVAL_SET_DOUBLE(v,d)  do { \
+		duk_double_t duk__dblval; \
+		duk__dblval = (d); \
+		DUK_ASSERT_DOUBLE_IS_NORMALIZED(duk__dblval); \
+		DUK_DBLUNION_SET_DOUBLE((v), duk__dblval); \
+	} while (0)
+#define DUK_TVAL_SET_FASTINT(v,i)           DUK__TVAL_SET_FASTINT((v), (i))
+#define DUK_TVAL_SET_FASTINT_I32(v,i)       DUK__TVAL_SET_FASTINT_I32((v), (i))
+#define DUK_TVAL_SET_FASTINT_U32(v,i)       DUK__TVAL_SET_FASTINT_U32((v), (i))
+#define DUK_TVAL_SET_NUMBER_CHKFAST(v,d)    duk_tval_set_number_chkfast((v), (d))
+#define DUK_TVAL_SET_NUMBER(v,d)            DUK_TVAL_SET_DOUBLE((v), (d))
+#define DUK_TVAL_CHKFAST_INPLACE(v)  do { \
+		duk_tval *duk__tv; \
+		duk_double_t duk__d; \
+		duk__tv = (v); \
+		if (DUK_TVAL_IS_DOUBLE(duk__tv)) { \
+			duk__d = DUK_TVAL_GET_DOUBLE(duk__tv); \
+			DUK_TVAL_SET_NUMBER_CHKFAST(duk__tv, duk__d); \
+		} \
+	} while (0)
+#else
+#define DUK_TVAL_SET_DOUBLE(v,d)  do { \
+		duk_double_t duk__dblval; \
+		duk__dblval = (d); \
+		DUK_ASSERT_DOUBLE_IS_NORMALIZED(duk__dblval); \
+		DUK_DBLUNION_SET_DOUBLE((v), duk__dblval); \
+	} while (0)
+#define DUK_TVAL_SET_FASTINT(v,i)           DUK_TVAL_SET_DOUBLE((v), (duk_double_t) (i))  /* XXX: fast int-to-double */
+#define DUK_TVAL_SET_FASTINT_I32(v,i)       DUK_TVAL_SET_DOUBLE((v), (duk_double_t) (i))
+#define DUK_TVAL_SET_FASTINT_U32(v,i)       DUK_TVAL_SET_DOUBLE((v), (duk_double_t) (i))
+#define DUK_TVAL_SET_NUMBER_CHKFAST(v,d)    DUK_TVAL_SET_DOUBLE((v), (d))
+#define DUK_TVAL_SET_NUMBER(v,d)            DUK_TVAL_SET_DOUBLE((v), (d))
+#define DUK_TVAL_CHKFAST_INPLACE(v)  do { } while (0)
+#endif
+
+#define DUK_TVAL_SET_LIGHTFUNC(v,fp,flags)  DUK__TVAL_SET_LIGHTFUNC((v), (fp), (flags))
+#define DUK_TVAL_SET_STRING(v,h)            DUK__TVAL_SET_TAGGEDPOINTER((v), (h), DUK_TAG_STRING)
+#define DUK_TVAL_SET_OBJECT(v,h)            DUK__TVAL_SET_TAGGEDPOINTER((v), (h), DUK_TAG_OBJECT)
+#define DUK_TVAL_SET_BUFFER(v,h)            DUK__TVAL_SET_TAGGEDPOINTER((v), (h), DUK_TAG_BUFFER)
+#define DUK_TVAL_SET_POINTER(v,p)           DUK__TVAL_SET_TAGGEDPOINTER((v), (p), DUK_TAG_POINTER)
+
+#define DUK_TVAL_SET_TVAL(v,x)              do { *(v) = *(x); } while (0)
+
+/* getters */
+#define DUK_TVAL_GET_BOOLEAN(v)             ((int) (v)->us[DUK_DBL_IDX_US1])
+#if defined(DUK_USE_FASTINT)
+#define DUK_TVAL_GET_DOUBLE(v)              ((v)->d)
+#define DUK_TVAL_GET_FASTINT(v)             DUK__TVAL_GET_FASTINT((v))
+#define DUK_TVAL_GET_FASTINT_U32(v)         DUK__TVAL_GET_FASTINT_U32((v))
+#define DUK_TVAL_GET_FASTINT_I32(v)         DUK__TVAL_GET_FASTINT_I32((v))
+#define DUK_TVAL_GET_NUMBER(v)              duk_tval_get_number_packed((v))
+#else
+#define DUK_TVAL_GET_NUMBER(v)              ((v)->d)
+#define DUK_TVAL_GET_DOUBLE(v)              ((v)->d)
+#endif
+#define DUK_TVAL_GET_LIGHTFUNC(v,out_fp,out_flags)  do { \
+		(out_flags) = (v)->ui[DUK_DBL_IDX_UI0] & 0xffffUL; \
+		(out_fp) = (duk_c_function) (v)->ui[DUK_DBL_IDX_UI1]; \
+	} while (0)
+#define DUK_TVAL_GET_LIGHTFUNC_FUNCPTR(v)   ((duk_c_function) ((v)->ui[DUK_DBL_IDX_UI1]))
+#define DUK_TVAL_GET_LIGHTFUNC_FLAGS(v)     (((int) (v)->ui[DUK_DBL_IDX_UI0]) & 0xffffUL)
+#define DUK_TVAL_GET_STRING(v)              ((duk_hstring *) (v)->vp[DUK_DBL_IDX_VP1])
+#define DUK_TVAL_GET_OBJECT(v)              ((duk_hobject *) (v)->vp[DUK_DBL_IDX_VP1])
+#define DUK_TVAL_GET_BUFFER(v)              ((duk_hbuffer *) (v)->vp[DUK_DBL_IDX_VP1])
+#define DUK_TVAL_GET_POINTER(v)             ((void *) (v)->vp[DUK_DBL_IDX_VP1])
+#define DUK_TVAL_GET_HEAPHDR(v)             ((duk_heaphdr *) (v)->vp[DUK_DBL_IDX_VP1])
+
+/* decoding */
+#define DUK_TVAL_GET_TAG(v)                 ((duk_small_uint_t) (v)->us[DUK_DBL_IDX_US0])
+
+#define DUK_TVAL_IS_UNDEFINED(v)            (DUK_TVAL_GET_TAG((v)) == DUK_TAG_UNDEFINED)
+#define DUK_TVAL_IS_UNUSED(v)               (DUK_TVAL_GET_TAG((v)) == DUK_TAG_UNUSED)
+#define DUK_TVAL_IS_NULL(v)                 (DUK_TVAL_GET_TAG((v)) == DUK_TAG_NULL)
+#define DUK_TVAL_IS_BOOLEAN(v)              (DUK_TVAL_GET_TAG((v)) == DUK_TAG_BOOLEAN)
+#define DUK_TVAL_IS_BOOLEAN_TRUE(v)         ((v)->ui[DUK_DBL_IDX_UI0] == DUK_XTAG_BOOLEAN_TRUE)
+#define DUK_TVAL_IS_BOOLEAN_FALSE(v)        ((v)->ui[DUK_DBL_IDX_UI0] == DUK_XTAG_BOOLEAN_FALSE)
+#define DUK_TVAL_IS_LIGHTFUNC(v)            (DUK_TVAL_GET_TAG((v)) == DUK_TAG_LIGHTFUNC)
+#define DUK_TVAL_IS_STRING(v)               (DUK_TVAL_GET_TAG((v)) == DUK_TAG_STRING)
+#define DUK_TVAL_IS_OBJECT(v)               (DUK_TVAL_GET_TAG((v)) == DUK_TAG_OBJECT)
+#define DUK_TVAL_IS_BUFFER(v)               (DUK_TVAL_GET_TAG((v)) == DUK_TAG_BUFFER)
+#define DUK_TVAL_IS_POINTER(v)              (DUK_TVAL_GET_TAG((v)) == DUK_TAG_POINTER)
+#if defined(DUK_USE_FASTINT)
+/* 0xfff0 is -Infinity */
+#define DUK_TVAL_IS_DOUBLE(v)               (DUK_TVAL_GET_TAG((v)) <= 0xfff0UL)
+#define DUK_TVAL_IS_FASTINT(v)              (DUK_TVAL_GET_TAG((v)) == DUK_TAG_FASTINT)
+#define DUK_TVAL_IS_NUMBER(v)               (DUK_TVAL_GET_TAG((v)) <= 0xfff1UL)
+#else
+#define DUK_TVAL_IS_NUMBER(v)               (DUK_TVAL_GET_TAG((v)) <= 0xfff0UL)
+#define DUK_TVAL_IS_DOUBLE(v)               DUK_TVAL_IS_NUMBER((v))
+#endif
+
+/* This is performance critical because it appears in every DECREF. */
+#define DUK_TVAL_IS_HEAP_ALLOCATED(v)       (DUK_TVAL_GET_TAG((v)) >= DUK_TAG_STRING)
+
+#if defined(DUK_USE_FASTINT)
+DUK_INTERNAL_DECL duk_double_t duk_tval_get_number_packed(duk_tval *tv);
+#endif
+
+#else  /* DUK_USE_PACKED_TVAL */
+/* ======================================================================== */
+
+/*
+ *  Portable 12-byte representation
+ */
+
+/* Note: not initializing all bytes is normally not an issue: Duktape won't
+ * read or use the uninitialized bytes so valgrind won't issue warnings.
+ * In some special cases a harmless valgrind warning may be issued though.
+ * For example, the DumpHeap debugger command writes out a compiled function's
+ * 'data' area as is, including any uninitialized bytes, which causes a
+ * valgrind warning.
+ */
+
+typedef struct duk_tval_struct duk_tval;
+
+struct duk_tval_struct {
+	duk_small_uint_t t;
+	duk_small_uint_t v_extra;
+	union {
+		duk_double_t d;
+		duk_small_int_t i;
+#if defined(DUK_USE_FASTINT)
+		duk_int64_t fi;  /* if present, forces 16-byte duk_tval */
+#endif
+		void *voidptr;
+		duk_hstring *hstring;
+		duk_hobject *hobject;
+		duk_hcompiledfunction *hcompiledfunction;
+		duk_hnativefunction *hnativefunction;
+		duk_hthread *hthread;
+		duk_hbuffer *hbuffer;
+		duk_heaphdr *heaphdr;
+		duk_c_function lightfunc;
+	} v;
+};
+
+#define DUK__TAG_NUMBER               0  /* not exposed */
+#if defined(DUK_USE_FASTINT)
+#define DUK_TAG_FASTINT               1
+#endif
+#define DUK_TAG_UNDEFINED             2
+#define DUK_TAG_NULL                  3
+#define DUK_TAG_BOOLEAN               4
+#define DUK_TAG_POINTER               5
+#define DUK_TAG_LIGHTFUNC             6
+#define DUK_TAG_UNUSED                7  /* marker; not actual tagged type */
+#define DUK_TAG_STRING                8  /* first heap allocated, match bit boundary */
+#define DUK_TAG_OBJECT                9
+#define DUK_TAG_BUFFER                10
+
+/* DUK__TAG_NUMBER is intentionally first, as it is the default clause in code
+ * to support the 8-byte representation.  Further, it is a non-heap-allocated
+ * type so it should come before DUK_TAG_STRING.  Finally, it should not break
+ * the tag value ranges covered by case-clauses in a switch-case.
+ */
+
+/* setters */
+#define DUK_TVAL_SET_UNDEFINED(tv)  do { \
+		(tv)->t = DUK_TAG_UNDEFINED; \
+	} while (0)
+
+#define DUK_TVAL_SET_UNUSED(tv)  do { \
+		(tv)->t = DUK_TAG_UNUSED; \
+	} while (0)
+
+#define DUK_TVAL_SET_NULL(tv)  do { \
+		(tv)->t = DUK_TAG_NULL; \
+	} while (0)
+
+#define DUK_TVAL_SET_BOOLEAN(tv,val)  do { \
+		(tv)->t = DUK_TAG_BOOLEAN; \
+		(tv)->v.i = (val); \
+	} while (0)
+
+#if defined(DUK_USE_FASTINT)
+#define DUK_TVAL_SET_DOUBLE(tv,val)  do { \
+		(tv)->t = DUK__TAG_NUMBER; \
+		(tv)->v.d = (val); \
+	} while (0)
+#define DUK_TVAL_SET_FASTINT(tv,val)  do { \
+		(tv)->t = DUK_TAG_FASTINT; \
+		(tv)->v.fi = (val); \
+	} while (0)
+#define DUK_TVAL_SET_FASTINT_U32(tv,val)  do { \
+		(tv)->t = DUK_TAG_FASTINT; \
+		(tv)->v.fi = (duk_int64_t) (val); \
+	} while (0)
+#define DUK_TVAL_SET_FASTINT_I32(tv,val)  do { \
+		(tv)->t = DUK_TAG_FASTINT; \
+		(tv)->v.fi = (duk_int64_t) (val); \
+	} while (0)
+#define DUK_TVAL_SET_NUMBER_CHKFAST(tv,d) \
+	duk_tval_set_number_chkfast((tv), (d))
+#define DUK_TVAL_SET_NUMBER(tv,val) \
+	DUK_TVAL_SET_DOUBLE((tv), (val))
+#define DUK_TVAL_CHKFAST_INPLACE(v)  do { \
+		duk_tval *duk__tv; \
+		duk_double_t duk__d; \
+		duk__tv = (v); \
+		if (DUK_TVAL_IS_DOUBLE(duk__tv)) { \
+			duk__d = DUK_TVAL_GET_DOUBLE(duk__tv); \
+			DUK_TVAL_SET_NUMBER_CHKFAST(duk__tv, duk__d); \
+		} \
+	} while (0)
+#else
+#define DUK_TVAL_SET_DOUBLE(tv,d) \
+	DUK_TVAL_SET_NUMBER((tv), (d))
+#define DUK_TVAL_SET_FASTINT(tv,val) \
+	DUK_TVAL_SET_NUMBER((tv), (duk_double_t) (val))  /* XXX: fast int-to-double */
+#define DUK_TVAL_SET_FASTINT_U32(tv,val) \
+	DUK_TVAL_SET_NUMBER((tv), (duk_double_t) (val))
+#define DUK_TVAL_SET_FASTINT_I32(tv,val) \
+	DUK_TVAL_SET_NUMBER((tv), (duk_double_t) (val))
+#define DUK_TVAL_SET_NUMBER(tv,val)  do { \
+		(tv)->t = DUK__TAG_NUMBER; \
+		(tv)->v.d = (val); \
+	} while (0)
+#define DUK_TVAL_SET_NUMBER_CHKFAST(tv,d) \
+	DUK_TVAL_SET_NUMBER((tv), (d))
+#define DUK_TVAL_CHKFAST_INPLACE(v)  do { } while (0)
+#endif  /* DUK_USE_FASTINT */
+
+#define DUK_TVAL_SET_POINTER(tv,hptr)  do { \
+		(tv)->t = DUK_TAG_POINTER; \
+		(tv)->v.voidptr = (hptr); \
+	} while (0)
+
+#define DUK_TVAL_SET_LIGHTFUNC(tv,fp,flags)  do { \
+		(tv)->t = DUK_TAG_LIGHTFUNC; \
+		(tv)->v_extra = (flags); \
+		(tv)->v.lightfunc = (duk_c_function) (fp); \
+	} while (0)
+
+#define DUK_TVAL_SET_STRING(tv,hptr)  do { \
+		(tv)->t = DUK_TAG_STRING; \
+		(tv)->v.hstring = (hptr); \
+	} while (0)
+
+#define DUK_TVAL_SET_OBJECT(tv,hptr)  do { \
+		(tv)->t = DUK_TAG_OBJECT; \
+		(tv)->v.hobject = (hptr); \
+	} while (0)
+
+#define DUK_TVAL_SET_BUFFER(tv,hptr)  do { \
+		(tv)->t = DUK_TAG_BUFFER; \
+		(tv)->v.hbuffer = (hptr); \
+	} while (0)
+
+#define DUK_TVAL_SET_NAN(tv)  do { \
+		/* in non-packed representation we don't care about which NaN is used */ \
+		(tv)->t = DUK__TAG_NUMBER; \
+		(tv)->v.d = DUK_DOUBLE_NAN; \
+	} while (0)
+
+#define DUK_TVAL_SET_TVAL(v,x)             do { *(v) = *(x); } while (0)
+
+/* getters */
+#define DUK_TVAL_GET_BOOLEAN(tv)           ((tv)->v.i)
+#if defined(DUK_USE_FASTINT)
+#define DUK_TVAL_GET_DOUBLE(tv)            ((tv)->v.d)
+#define DUK_TVAL_GET_FASTINT(tv)           ((tv)->v.fi)
+#define DUK_TVAL_GET_FASTINT_U32(tv)       ((duk_uint32_t) ((tv)->v.fi))
+#define DUK_TVAL_GET_FASTINT_I32(tv)       ((duk_int32_t) ((tv)->v.fi))
+#if 0
+#define DUK_TVAL_GET_NUMBER(tv)            (DUK_TVAL_IS_FASTINT((tv)) ? \
+                                               (duk_double_t) DUK_TVAL_GET_FASTINT((tv)) : \
+                                               DUK_TVAL_GET_DOUBLE((tv)))
+#define DUK_TVAL_GET_NUMBER(tv)            duk_tval_get_number_unpacked((tv))
+#else
+/* This seems reasonable overall. */
+#define DUK_TVAL_GET_NUMBER(tv)            (DUK_TVAL_IS_FASTINT((tv)) ? \
+                                               duk_tval_get_number_unpacked_fastint((tv)) : \
+                                               DUK_TVAL_GET_DOUBLE((tv)))
+#endif
+#else
+#define DUK_TVAL_GET_NUMBER(tv)            ((tv)->v.d)
+#define DUK_TVAL_GET_DOUBLE(tv)            ((tv)->v.d)
+#endif  /* DUK_USE_FASTINT */
+#define DUK_TVAL_GET_POINTER(tv)           ((tv)->v.voidptr)
+#define DUK_TVAL_GET_LIGHTFUNC(tv,out_fp,out_flags)  do { \
+		(out_flags) = (duk_uint32_t) (tv)->v_extra; \
+		(out_fp) = (tv)->v.lightfunc; \
+	} while (0)
+#define DUK_TVAL_GET_LIGHTFUNC_FUNCPTR(tv) ((tv)->v.lightfunc)
+#define DUK_TVAL_GET_LIGHTFUNC_FLAGS(tv)   ((duk_uint32_t) ((tv)->v_extra))
+#define DUK_TVAL_GET_STRING(tv)            ((tv)->v.hstring)
+#define DUK_TVAL_GET_OBJECT(tv)            ((tv)->v.hobject)
+#define DUK_TVAL_GET_BUFFER(tv)            ((tv)->v.hbuffer)
+#define DUK_TVAL_GET_HEAPHDR(tv)           ((tv)->v.heaphdr)
+
+/* decoding */
+#define DUK_TVAL_GET_TAG(tv)               ((tv)->t)
+#define DUK_TVAL_IS_UNDEFINED(tv)          ((tv)->t == DUK_TAG_UNDEFINED)
+#define DUK_TVAL_IS_UNUSED(tv)             ((tv)->t == DUK_TAG_UNUSED)
+#define DUK_TVAL_IS_NULL(tv)               ((tv)->t == DUK_TAG_NULL)
+#define DUK_TVAL_IS_BOOLEAN(tv)            ((tv)->t == DUK_TAG_BOOLEAN)
+#define DUK_TVAL_IS_BOOLEAN_TRUE(tv)       (((tv)->t == DUK_TAG_BOOLEAN) && ((tv)->v.i != 0))
+#define DUK_TVAL_IS_BOOLEAN_FALSE(tv)      (((tv)->t == DUK_TAG_BOOLEAN) && ((tv)->v.i == 0))
+#if defined(DUK_USE_FASTINT)
+#define DUK_TVAL_IS_DOUBLE(tv)             ((tv)->t == DUK__TAG_NUMBER)
+#define DUK_TVAL_IS_FASTINT(tv)            ((tv)->t == DUK_TAG_FASTINT)
+#define DUK_TVAL_IS_NUMBER(tv)             ((tv)->t == DUK__TAG_NUMBER || \
+                                            (tv)->t == DUK_TAG_FASTINT)
+#else
+#define DUK_TVAL_IS_NUMBER(tv)             ((tv)->t == DUK__TAG_NUMBER)
+#define DUK_TVAL_IS_DOUBLE(v)              DUK_TVAL_IS_NUMBER((v))
+#endif  /* DUK_USE_FASTINT */
+#define DUK_TVAL_IS_POINTER(tv)            ((tv)->t == DUK_TAG_POINTER)
+#define DUK_TVAL_IS_LIGHTFUNC(tv)          ((tv)->t == DUK_TAG_LIGHTFUNC)
+#define DUK_TVAL_IS_STRING(tv)             ((tv)->t == DUK_TAG_STRING)
+#define DUK_TVAL_IS_OBJECT(tv)             ((tv)->t == DUK_TAG_OBJECT)
+#define DUK_TVAL_IS_BUFFER(tv)             ((tv)->t == DUK_TAG_BUFFER)
+
+/* This is performance critical because it's needed for every DECREF.
+ * Take advantage of the fact that the first heap allocated tag is 8,
+ * so that bit 3 is set for all heap allocated tags (and never set for
+ * non-heap-allocated tags).
+ */
+#if 0
+#define DUK_TVAL_IS_HEAP_ALLOCATED(tv)     ((tv)->t >= DUK_TAG_STRING)
+#endif
+#define DUK_TVAL_IS_HEAP_ALLOCATED(tv)     ((tv)->t & 0x08)
+
+#if defined(DUK_USE_FASTINT)
+#if 0
+DUK_INTERNAL_DECL duk_double_t duk_tval_get_number_unpacked(duk_tval *tv);
+#endif
+DUK_INTERNAL_DECL duk_double_t duk_tval_get_number_unpacked_fastint(duk_tval *tv);
+#endif
+
+#endif  /* DUK_USE_PACKED_TVAL */
+
+/*
+ *  Convenience (independent of representation)
+ */
+
+#define DUK_TVAL_SET_BOOLEAN_TRUE(v)        DUK_TVAL_SET_BOOLEAN(v, 1)
+#define DUK_TVAL_SET_BOOLEAN_FALSE(v)       DUK_TVAL_SET_BOOLEAN(v, 0)
+
+/* Lightfunc flags packing and unpacking. */
+/* Sign extend: 0x0000##00 -> 0x##000000 -> sign extend to 0xssssss## */
+#define DUK_LFUNC_FLAGS_GET_MAGIC(lf_flags) \
+	((((duk_int32_t) (lf_flags)) << 16) >> 24)
+#define DUK_LFUNC_FLAGS_GET_LENGTH(lf_flags) \
+	(((lf_flags) >> 4) & 0x0f)
+#define DUK_LFUNC_FLAGS_GET_NARGS(lf_flags) \
+	((lf_flags) & 0x0f)
+#define DUK_LFUNC_FLAGS_PACK(magic,length,nargs) \
+	(((magic) & 0xff) << 8) | ((length) << 4) | (nargs)
+
+#define DUK_LFUNC_NARGS_VARARGS             0x0f   /* varargs marker */
+#define DUK_LFUNC_NARGS_MIN                 0x00
+#define DUK_LFUNC_NARGS_MAX                 0x0e   /* max, excl. varargs marker */
+#define DUK_LFUNC_LENGTH_MIN                0x00
+#define DUK_LFUNC_LENGTH_MAX                0x0f
+#define DUK_LFUNC_MAGIC_MIN                 (-0x80)
+#define DUK_LFUNC_MAGIC_MAX                 0x7f
+
+/* fastint constants etc */
+#if defined(DUK_USE_FASTINT)
+#define DUK_FASTINT_MIN           (-0x800000000000LL)
+#define DUK_FASTINT_MAX           0x7fffffffffffLL
+#define DUK_FASTINT_BITS          48
+
+DUK_INTERNAL_DECL void duk_tval_set_number_chkfast(duk_tval *tv, duk_double_t x);
+#endif
+
+#endif  /* DUK_TVAL_H_INCLUDED */
+/*
+ *  Automatically generated by genbuiltins.py, do not edit!
+ */
+
+#ifndef DUK_BUILTINS_H_INCLUDED
+#define DUK_BUILTINS_H_INCLUDED
+
+#if defined(DUK_USE_ROM_STRINGS)
+#error ROM support not enabled, rerun make_dist.py with --rom-support
+#else  /* DUK_USE_ROM_STRINGS */
+#define DUK_STRIDX_UC_UNDEFINED                                       0                              /* 'Undefined' */
+#define DUK_HEAP_STRING_UC_UNDEFINED(heap)                            DUK_HEAP_GET_STRING((heap),DUK_STRIDX_UC_UNDEFINED)
+#define DUK_HTHREAD_STRING_UC_UNDEFINED(thr)                          DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_UC_UNDEFINED)
+#define DUK_STRIDX_UC_NULL                                            1                              /* 'Null' */
+#define DUK_HEAP_STRING_UC_NULL(heap)                                 DUK_HEAP_GET_STRING((heap),DUK_STRIDX_UC_NULL)
+#define DUK_HTHREAD_STRING_UC_NULL(thr)                               DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_UC_NULL)
+#define DUK_STRIDX_UC_ARGUMENTS                                       2                              /* 'Arguments' */
+#define DUK_HEAP_STRING_UC_ARGUMENTS(heap)                            DUK_HEAP_GET_STRING((heap),DUK_STRIDX_UC_ARGUMENTS)
+#define DUK_HTHREAD_STRING_UC_ARGUMENTS(thr)                          DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_UC_ARGUMENTS)
+#define DUK_STRIDX_UC_OBJECT                                          3                              /* 'Object' */
+#define DUK_HEAP_STRING_UC_OBJECT(heap)                               DUK_HEAP_GET_STRING((heap),DUK_STRIDX_UC_OBJECT)
+#define DUK_HTHREAD_STRING_UC_OBJECT(thr)                             DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_UC_OBJECT)
+#define DUK_STRIDX_UC_FUNCTION                                        4                              /* 'Function' */
+#define DUK_HEAP_STRING_UC_FUNCTION(heap)                             DUK_HEAP_GET_STRING((heap),DUK_STRIDX_UC_FUNCTION)
+#define DUK_HTHREAD_STRING_UC_FUNCTION(thr)                           DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_UC_FUNCTION)
+#define DUK_STRIDX_ARRAY                                              5                              /* 'Array' */
+#define DUK_HEAP_STRING_ARRAY(heap)                                   DUK_HEAP_GET_STRING((heap),DUK_STRIDX_ARRAY)
+#define DUK_HTHREAD_STRING_ARRAY(thr)                                 DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_ARRAY)
+#define DUK_STRIDX_UC_STRING                                          6                              /* 'String' */
+#define DUK_HEAP_STRING_UC_STRING(heap)                               DUK_HEAP_GET_STRING((heap),DUK_STRIDX_UC_STRING)
+#define DUK_HTHREAD_STRING_UC_STRING(thr)                             DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_UC_STRING)
+#define DUK_STRIDX_UC_BOOLEAN                                         7                              /* 'Boolean' */
+#define DUK_HEAP_STRING_UC_BOOLEAN(heap)                              DUK_HEAP_GET_STRING((heap),DUK_STRIDX_UC_BOOLEAN)
+#define DUK_HTHREAD_STRING_UC_BOOLEAN(thr)                            DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_UC_BOOLEAN)
+#define DUK_STRIDX_UC_NUMBER                                          8                              /* 'Number' */
+#define DUK_HEAP_STRING_UC_NUMBER(heap)                               DUK_HEAP_GET_STRING((heap),DUK_STRIDX_UC_NUMBER)
+#define DUK_HTHREAD_STRING_UC_NUMBER(thr)                             DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_UC_NUMBER)
+#define DUK_STRIDX_DATE                                               9                              /* 'Date' */
+#define DUK_HEAP_STRING_DATE(heap)                                    DUK_HEAP_GET_STRING((heap),DUK_STRIDX_DATE)
+#define DUK_HTHREAD_STRING_DATE(thr)                                  DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_DATE)
+#define DUK_STRIDX_REG_EXP                                            10                             /* 'RegExp' */
+#define DUK_HEAP_STRING_REG_EXP(heap)                                 DUK_HEAP_GET_STRING((heap),DUK_STRIDX_REG_EXP)
+#define DUK_HTHREAD_STRING_REG_EXP(thr)                               DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_REG_EXP)
+#define DUK_STRIDX_UC_ERROR                                           11                             /* 'Error' */
+#define DUK_HEAP_STRING_UC_ERROR(heap)                                DUK_HEAP_GET_STRING((heap),DUK_STRIDX_UC_ERROR)
+#define DUK_HTHREAD_STRING_UC_ERROR(thr)                              DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_UC_ERROR)
+#define DUK_STRIDX_MATH                                               12                             /* 'Math' */
+#define DUK_HEAP_STRING_MATH(heap)                                    DUK_HEAP_GET_STRING((heap),DUK_STRIDX_MATH)
+#define DUK_HTHREAD_STRING_MATH(thr)                                  DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_MATH)
+#define DUK_STRIDX_JSON                                               13                             /* 'JSON' */
+#define DUK_HEAP_STRING_JSON(heap)                                    DUK_HEAP_GET_STRING((heap),DUK_STRIDX_JSON)
+#define DUK_HTHREAD_STRING_JSON(thr)                                  DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_JSON)
+#define DUK_STRIDX_EMPTY_STRING                                       14                             /* '' */
+#define DUK_HEAP_STRING_EMPTY_STRING(heap)                            DUK_HEAP_GET_STRING((heap),DUK_STRIDX_EMPTY_STRING)
+#define DUK_HTHREAD_STRING_EMPTY_STRING(thr)                          DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_EMPTY_STRING)
+#define DUK_STRIDX_ARRAY_BUFFER                                       15                             /* 'ArrayBuffer' */
+#define DUK_HEAP_STRING_ARRAY_BUFFER(heap)                            DUK_HEAP_GET_STRING((heap),DUK_STRIDX_ARRAY_BUFFER)
+#define DUK_HTHREAD_STRING_ARRAY_BUFFER(thr)                          DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_ARRAY_BUFFER)
+#define DUK_STRIDX_DATA_VIEW                                          16                             /* 'DataView' */
+#define DUK_HEAP_STRING_DATA_VIEW(heap)                               DUK_HEAP_GET_STRING((heap),DUK_STRIDX_DATA_VIEW)
+#define DUK_HTHREAD_STRING_DATA_VIEW(thr)                             DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_DATA_VIEW)
+#define DUK_STRIDX_INT8_ARRAY                                         17                             /* 'Int8Array' */
+#define DUK_HEAP_STRING_INT8_ARRAY(heap)                              DUK_HEAP_GET_STRING((heap),DUK_STRIDX_INT8_ARRAY)
+#define DUK_HTHREAD_STRING_INT8_ARRAY(thr)                            DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_INT8_ARRAY)
+#define DUK_STRIDX_UINT8_ARRAY                                        18                             /* 'Uint8Array' */
+#define DUK_HEAP_STRING_UINT8_ARRAY(heap)                             DUK_HEAP_GET_STRING((heap),DUK_STRIDX_UINT8_ARRAY)
+#define DUK_HTHREAD_STRING_UINT8_ARRAY(thr)                           DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_UINT8_ARRAY)
+#define DUK_STRIDX_UINT8_CLAMPED_ARRAY                                19                             /* 'Uint8ClampedArray' */
+#define DUK_HEAP_STRING_UINT8_CLAMPED_ARRAY(heap)                     DUK_HEAP_GET_STRING((heap),DUK_STRIDX_UINT8_CLAMPED_ARRAY)
+#define DUK_HTHREAD_STRING_UINT8_CLAMPED_ARRAY(thr)                   DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_UINT8_CLAMPED_ARRAY)
+#define DUK_STRIDX_INT16_ARRAY                                        20                             /* 'Int16Array' */
+#define DUK_HEAP_STRING_INT16_ARRAY(heap)                             DUK_HEAP_GET_STRING((heap),DUK_STRIDX_INT16_ARRAY)
+#define DUK_HTHREAD_STRING_INT16_ARRAY(thr)                           DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_INT16_ARRAY)
+#define DUK_STRIDX_UINT16_ARRAY                                       21                             /* 'Uint16Array' */
+#define DUK_HEAP_STRING_UINT16_ARRAY(heap)                            DUK_HEAP_GET_STRING((heap),DUK_STRIDX_UINT16_ARRAY)
+#define DUK_HTHREAD_STRING_UINT16_ARRAY(thr)                          DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_UINT16_ARRAY)
+#define DUK_STRIDX_INT32_ARRAY                                        22                             /* 'Int32Array' */
+#define DUK_HEAP_STRING_INT32_ARRAY(heap)                             DUK_HEAP_GET_STRING((heap),DUK_STRIDX_INT32_ARRAY)
+#define DUK_HTHREAD_STRING_INT32_ARRAY(thr)                           DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_INT32_ARRAY)
+#define DUK_STRIDX_UINT32_ARRAY                                       23                             /* 'Uint32Array' */
+#define DUK_HEAP_STRING_UINT32_ARRAY(heap)                            DUK_HEAP_GET_STRING((heap),DUK_STRIDX_UINT32_ARRAY)
+#define DUK_HTHREAD_STRING_UINT32_ARRAY(thr)                          DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_UINT32_ARRAY)
+#define DUK_STRIDX_FLOAT32_ARRAY                                      24                             /* 'Float32Array' */
+#define DUK_HEAP_STRING_FLOAT32_ARRAY(heap)                           DUK_HEAP_GET_STRING((heap),DUK_STRIDX_FLOAT32_ARRAY)
+#define DUK_HTHREAD_STRING_FLOAT32_ARRAY(thr)                         DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_FLOAT32_ARRAY)
+#define DUK_STRIDX_FLOAT64_ARRAY                                      25                             /* 'Float64Array' */
+#define DUK_HEAP_STRING_FLOAT64_ARRAY(heap)                           DUK_HEAP_GET_STRING((heap),DUK_STRIDX_FLOAT64_ARRAY)
+#define DUK_HTHREAD_STRING_FLOAT64_ARRAY(thr)                         DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_FLOAT64_ARRAY)
+#define DUK_STRIDX_GLOBAL                                             26                             /* 'global' */
+#define DUK_HEAP_STRING_GLOBAL(heap)                                  DUK_HEAP_GET_STRING((heap),DUK_STRIDX_GLOBAL)
+#define DUK_HTHREAD_STRING_GLOBAL(thr)                                DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_GLOBAL)
+#define DUK_STRIDX_OBJ_ENV                                            27                             /* 'ObjEnv' */
+#define DUK_HEAP_STRING_OBJ_ENV(heap)                                 DUK_HEAP_GET_STRING((heap),DUK_STRIDX_OBJ_ENV)
+#define DUK_HTHREAD_STRING_OBJ_ENV(thr)                               DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_OBJ_ENV)
+#define DUK_STRIDX_DEC_ENV                                            28                             /* 'DecEnv' */
+#define DUK_HEAP_STRING_DEC_ENV(heap)                                 DUK_HEAP_GET_STRING((heap),DUK_STRIDX_DEC_ENV)
+#define DUK_HTHREAD_STRING_DEC_ENV(thr)                               DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_DEC_ENV)
+#define DUK_STRIDX_UC_BUFFER                                          29                             /* 'Buffer' */
+#define DUK_HEAP_STRING_UC_BUFFER(heap)                               DUK_HEAP_GET_STRING((heap),DUK_STRIDX_UC_BUFFER)
+#define DUK_HTHREAD_STRING_UC_BUFFER(thr)                             DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_UC_BUFFER)
+#define DUK_STRIDX_UC_POINTER                                         30                             /* 'Pointer' */
+#define DUK_HEAP_STRING_UC_POINTER(heap)                              DUK_HEAP_GET_STRING((heap),DUK_STRIDX_UC_POINTER)
+#define DUK_HTHREAD_STRING_UC_POINTER(thr)                            DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_UC_POINTER)
+#define DUK_STRIDX_UC_THREAD                                          31                             /* 'Thread' */
+#define DUK_HEAP_STRING_UC_THREAD(heap)                               DUK_HEAP_GET_STRING((heap),DUK_STRIDX_UC_THREAD)
+#define DUK_HTHREAD_STRING_UC_THREAD(thr)                             DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_UC_THREAD)
+#define DUK_STRIDX_EVAL                                               32                             /* 'eval' */
+#define DUK_HEAP_STRING_EVAL(heap)                                    DUK_HEAP_GET_STRING((heap),DUK_STRIDX_EVAL)
+#define DUK_HTHREAD_STRING_EVAL(thr)                                  DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_EVAL)
+#define DUK_STRIDX_DEFINE_PROPERTY                                    33                             /* 'defineProperty' */
+#define DUK_HEAP_STRING_DEFINE_PROPERTY(heap)                         DUK_HEAP_GET_STRING((heap),DUK_STRIDX_DEFINE_PROPERTY)
+#define DUK_HTHREAD_STRING_DEFINE_PROPERTY(thr)                       DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_DEFINE_PROPERTY)
+#define DUK_STRIDX_VALUE                                              34                             /* 'value' */
+#define DUK_HEAP_STRING_VALUE(heap)                                   DUK_HEAP_GET_STRING((heap),DUK_STRIDX_VALUE)
+#define DUK_HTHREAD_STRING_VALUE(thr)                                 DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_VALUE)
+#define DUK_STRIDX_WRITABLE                                           35                             /* 'writable' */
+#define DUK_HEAP_STRING_WRITABLE(heap)                                DUK_HEAP_GET_STRING((heap),DUK_STRIDX_WRITABLE)
+#define DUK_HTHREAD_STRING_WRITABLE(thr)                              DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_WRITABLE)
+#define DUK_STRIDX_CONFIGURABLE                                       36                             /* 'configurable' */
+#define DUK_HEAP_STRING_CONFIGURABLE(heap)                            DUK_HEAP_GET_STRING((heap),DUK_STRIDX_CONFIGURABLE)
+#define DUK_HTHREAD_STRING_CONFIGURABLE(thr)                          DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_CONFIGURABLE)
+#define DUK_STRIDX_ENUMERABLE                                         37                             /* 'enumerable' */
+#define DUK_HEAP_STRING_ENUMERABLE(heap)                              DUK_HEAP_GET_STRING((heap),DUK_STRIDX_ENUMERABLE)
+#define DUK_HTHREAD_STRING_ENUMERABLE(thr)                            DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_ENUMERABLE)
+#define DUK_STRIDX_JOIN                                               38                             /* 'join' */
+#define DUK_HEAP_STRING_JOIN(heap)                                    DUK_HEAP_GET_STRING((heap),DUK_STRIDX_JOIN)
+#define DUK_HTHREAD_STRING_JOIN(thr)                                  DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_JOIN)
+#define DUK_STRIDX_TO_LOCALE_STRING                                   39                             /* 'toLocaleString' */
+#define DUK_HEAP_STRING_TO_LOCALE_STRING(heap)                        DUK_HEAP_GET_STRING((heap),DUK_STRIDX_TO_LOCALE_STRING)
+#define DUK_HTHREAD_STRING_TO_LOCALE_STRING(thr)                      DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_TO_LOCALE_STRING)
+#define DUK_STRIDX_VALUE_OF                                           40                             /* 'valueOf' */
+#define DUK_HEAP_STRING_VALUE_OF(heap)                                DUK_HEAP_GET_STRING((heap),DUK_STRIDX_VALUE_OF)
+#define DUK_HTHREAD_STRING_VALUE_OF(thr)                              DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_VALUE_OF)
+#define DUK_STRIDX_TO_UTC_STRING                                      41                             /* 'toUTCString' */
+#define DUK_HEAP_STRING_TO_UTC_STRING(heap)                           DUK_HEAP_GET_STRING((heap),DUK_STRIDX_TO_UTC_STRING)
+#define DUK_HTHREAD_STRING_TO_UTC_STRING(thr)                         DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_TO_UTC_STRING)
+#define DUK_STRIDX_TO_ISO_STRING                                      42                             /* 'toISOString' */
+#define DUK_HEAP_STRING_TO_ISO_STRING(heap)                           DUK_HEAP_GET_STRING((heap),DUK_STRIDX_TO_ISO_STRING)
+#define DUK_HTHREAD_STRING_TO_ISO_STRING(thr)                         DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_TO_ISO_STRING)
+#define DUK_STRIDX_TO_GMT_STRING                                      43                             /* 'toGMTString' */
+#define DUK_HEAP_STRING_TO_GMT_STRING(heap)                           DUK_HEAP_GET_STRING((heap),DUK_STRIDX_TO_GMT_STRING)
+#define DUK_HTHREAD_STRING_TO_GMT_STRING(thr)                         DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_TO_GMT_STRING)
+#define DUK_STRIDX_SOURCE                                             44                             /* 'source' */
+#define DUK_HEAP_STRING_SOURCE(heap)                                  DUK_HEAP_GET_STRING((heap),DUK_STRIDX_SOURCE)
+#define DUK_HTHREAD_STRING_SOURCE(thr)                                DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_SOURCE)
+#define DUK_STRIDX_IGNORE_CASE                                        45                             /* 'ignoreCase' */
+#define DUK_HEAP_STRING_IGNORE_CASE(heap)                             DUK_HEAP_GET_STRING((heap),DUK_STRIDX_IGNORE_CASE)
+#define DUK_HTHREAD_STRING_IGNORE_CASE(thr)                           DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_IGNORE_CASE)
+#define DUK_STRIDX_MULTILINE                                          46                             /* 'multiline' */
+#define DUK_HEAP_STRING_MULTILINE(heap)                               DUK_HEAP_GET_STRING((heap),DUK_STRIDX_MULTILINE)
+#define DUK_HTHREAD_STRING_MULTILINE(thr)                             DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_MULTILINE)
+#define DUK_STRIDX_LAST_INDEX                                         47                             /* 'lastIndex' */
+#define DUK_HEAP_STRING_LAST_INDEX(heap)                              DUK_HEAP_GET_STRING((heap),DUK_STRIDX_LAST_INDEX)
+#define DUK_HTHREAD_STRING_LAST_INDEX(thr)                            DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_LAST_INDEX)
+#define DUK_STRIDX_ESCAPED_EMPTY_REGEXP                               48                             /* '(?:)' */
+#define DUK_HEAP_STRING_ESCAPED_EMPTY_REGEXP(heap)                    DUK_HEAP_GET_STRING((heap),DUK_STRIDX_ESCAPED_EMPTY_REGEXP)
+#define DUK_HTHREAD_STRING_ESCAPED_EMPTY_REGEXP(thr)                  DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_ESCAPED_EMPTY_REGEXP)
+#define DUK_STRIDX_INDEX                                              49                             /* 'index' */
+#define DUK_HEAP_STRING_INDEX(heap)                                   DUK_HEAP_GET_STRING((heap),DUK_STRIDX_INDEX)
+#define DUK_HTHREAD_STRING_INDEX(thr)                                 DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_INDEX)
+#define DUK_STRIDX_PROTOTYPE                                          50                             /* 'prototype' */
+#define DUK_HEAP_STRING_PROTOTYPE(heap)                               DUK_HEAP_GET_STRING((heap),DUK_STRIDX_PROTOTYPE)
+#define DUK_HTHREAD_STRING_PROTOTYPE(thr)                             DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_PROTOTYPE)
+#define DUK_STRIDX_CONSTRUCTOR                                        51                             /* 'constructor' */
+#define DUK_HEAP_STRING_CONSTRUCTOR(heap)                             DUK_HEAP_GET_STRING((heap),DUK_STRIDX_CONSTRUCTOR)
+#define DUK_HTHREAD_STRING_CONSTRUCTOR(thr)                           DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_CONSTRUCTOR)
+#define DUK_STRIDX_MESSAGE                                            52                             /* 'message' */
+#define DUK_HEAP_STRING_MESSAGE(heap)                                 DUK_HEAP_GET_STRING((heap),DUK_STRIDX_MESSAGE)
+#define DUK_HTHREAD_STRING_MESSAGE(thr)                               DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_MESSAGE)
+#define DUK_STRIDX_LC_BOOLEAN                                         53                             /* 'boolean' */
+#define DUK_HEAP_STRING_LC_BOOLEAN(heap)                              DUK_HEAP_GET_STRING((heap),DUK_STRIDX_LC_BOOLEAN)
+#define DUK_HTHREAD_STRING_LC_BOOLEAN(thr)                            DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_LC_BOOLEAN)
+#define DUK_STRIDX_LC_NUMBER                                          54                             /* 'number' */
+#define DUK_HEAP_STRING_LC_NUMBER(heap)                               DUK_HEAP_GET_STRING((heap),DUK_STRIDX_LC_NUMBER)
+#define DUK_HTHREAD_STRING_LC_NUMBER(thr)                             DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_LC_NUMBER)
+#define DUK_STRIDX_LC_STRING                                          55                             /* 'string' */
+#define DUK_HEAP_STRING_LC_STRING(heap)                               DUK_HEAP_GET_STRING((heap),DUK_STRIDX_LC_STRING)
+#define DUK_HTHREAD_STRING_LC_STRING(thr)                             DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_LC_STRING)
+#define DUK_STRIDX_LC_OBJECT                                          56                             /* 'object' */
+#define DUK_HEAP_STRING_LC_OBJECT(heap)                               DUK_HEAP_GET_STRING((heap),DUK_STRIDX_LC_OBJECT)
+#define DUK_HTHREAD_STRING_LC_OBJECT(thr)                             DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_LC_OBJECT)
+#define DUK_STRIDX_LC_UNDEFINED                                       57                             /* 'undefined' */
+#define DUK_HEAP_STRING_LC_UNDEFINED(heap)                            DUK_HEAP_GET_STRING((heap),DUK_STRIDX_LC_UNDEFINED)
+#define DUK_HTHREAD_STRING_LC_UNDEFINED(thr)                          DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_LC_UNDEFINED)
+#define DUK_STRIDX_NAN                                                58                             /* 'NaN' */
+#define DUK_HEAP_STRING_NAN(heap)                                     DUK_HEAP_GET_STRING((heap),DUK_STRIDX_NAN)
+#define DUK_HTHREAD_STRING_NAN(thr)                                   DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_NAN)
+#define DUK_STRIDX_INFINITY                                           59                             /* 'Infinity' */
+#define DUK_HEAP_STRING_INFINITY(heap)                                DUK_HEAP_GET_STRING((heap),DUK_STRIDX_INFINITY)
+#define DUK_HTHREAD_STRING_INFINITY(thr)                              DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_INFINITY)
+#define DUK_STRIDX_MINUS_INFINITY                                     60                             /* '-Infinity' */
+#define DUK_HEAP_STRING_MINUS_INFINITY(heap)                          DUK_HEAP_GET_STRING((heap),DUK_STRIDX_MINUS_INFINITY)
+#define DUK_HTHREAD_STRING_MINUS_INFINITY(thr)                        DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_MINUS_INFINITY)
+#define DUK_STRIDX_MINUS_ZERO                                         61                             /* '-0' */
+#define DUK_HEAP_STRING_MINUS_ZERO(heap)                              DUK_HEAP_GET_STRING((heap),DUK_STRIDX_MINUS_ZERO)
+#define DUK_HTHREAD_STRING_MINUS_ZERO(thr)                            DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_MINUS_ZERO)
+#define DUK_STRIDX_COMMA                                              62                             /* ',' */
+#define DUK_HEAP_STRING_COMMA(heap)                                   DUK_HEAP_GET_STRING((heap),DUK_STRIDX_COMMA)
+#define DUK_HTHREAD_STRING_COMMA(thr)                                 DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_COMMA)
+#define DUK_STRIDX_SPACE                                              63                             /* ' ' */
+#define DUK_HEAP_STRING_SPACE(heap)                                   DUK_HEAP_GET_STRING((heap),DUK_STRIDX_SPACE)
+#define DUK_HTHREAD_STRING_SPACE(thr)                                 DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_SPACE)
+#define DUK_STRIDX_NEWLINE_4SPACE                                     64                             /* '\n    ' */
+#define DUK_HEAP_STRING_NEWLINE_4SPACE(heap)                          DUK_HEAP_GET_STRING((heap),DUK_STRIDX_NEWLINE_4SPACE)
+#define DUK_HTHREAD_STRING_NEWLINE_4SPACE(thr)                        DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_NEWLINE_4SPACE)
+#define DUK_STRIDX_BRACKETED_ELLIPSIS                                 65                             /* '[...]' */
+#define DUK_HEAP_STRING_BRACKETED_ELLIPSIS(heap)                      DUK_HEAP_GET_STRING((heap),DUK_STRIDX_BRACKETED_ELLIPSIS)
+#define DUK_HTHREAD_STRING_BRACKETED_ELLIPSIS(thr)                    DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_BRACKETED_ELLIPSIS)
+#define DUK_STRIDX_INVALID_DATE                                       66                             /* 'Invalid Date' */
+#define DUK_HEAP_STRING_INVALID_DATE(heap)                            DUK_HEAP_GET_STRING((heap),DUK_STRIDX_INVALID_DATE)
+#define DUK_HTHREAD_STRING_INVALID_DATE(thr)                          DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_INVALID_DATE)
+#define DUK_STRIDX_LC_ARGUMENTS                                       67                             /* 'arguments' */
+#define DUK_HEAP_STRING_LC_ARGUMENTS(heap)                            DUK_HEAP_GET_STRING((heap),DUK_STRIDX_LC_ARGUMENTS)
+#define DUK_HTHREAD_STRING_LC_ARGUMENTS(thr)                          DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_LC_ARGUMENTS)
+#define DUK_STRIDX_CALLEE                                             68                             /* 'callee' */
+#define DUK_HEAP_STRING_CALLEE(heap)                                  DUK_HEAP_GET_STRING((heap),DUK_STRIDX_CALLEE)
+#define DUK_HTHREAD_STRING_CALLEE(thr)                                DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_CALLEE)
+#define DUK_STRIDX_CALLER                                             69                             /* 'caller' */
+#define DUK_HEAP_STRING_CALLER(heap)                                  DUK_HEAP_GET_STRING((heap),DUK_STRIDX_CALLER)
+#define DUK_HTHREAD_STRING_CALLER(thr)                                DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_CALLER)
+#define DUK_STRIDX_HAS                                                70                             /* 'has' */
+#define DUK_HEAP_STRING_HAS(heap)                                     DUK_HEAP_GET_STRING((heap),DUK_STRIDX_HAS)
+#define DUK_HTHREAD_STRING_HAS(thr)                                   DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_HAS)
+#define DUK_STRIDX_GET                                                71                             /* 'get' */
+#define DUK_HEAP_STRING_GET(heap)                                     DUK_HEAP_GET_STRING((heap),DUK_STRIDX_GET)
+#define DUK_HTHREAD_STRING_GET(thr)                                   DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_GET)
+#define DUK_STRIDX_DELETE_PROPERTY                                    72                             /* 'deleteProperty' */
+#define DUK_HEAP_STRING_DELETE_PROPERTY(heap)                         DUK_HEAP_GET_STRING((heap),DUK_STRIDX_DELETE_PROPERTY)
+#define DUK_HTHREAD_STRING_DELETE_PROPERTY(thr)                       DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_DELETE_PROPERTY)
+#define DUK_STRIDX_ENUMERATE                                          73                             /* 'enumerate' */
+#define DUK_HEAP_STRING_ENUMERATE(heap)                               DUK_HEAP_GET_STRING((heap),DUK_STRIDX_ENUMERATE)
+#define DUK_HTHREAD_STRING_ENUMERATE(thr)                             DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_ENUMERATE)
+#define DUK_STRIDX_OWN_KEYS                                           74                             /* 'ownKeys' */
+#define DUK_HEAP_STRING_OWN_KEYS(heap)                                DUK_HEAP_GET_STRING((heap),DUK_STRIDX_OWN_KEYS)
+#define DUK_HTHREAD_STRING_OWN_KEYS(thr)                              DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_OWN_KEYS)
+#define DUK_STRIDX_SET_PROTOTYPE_OF                                   75                             /* 'setPrototypeOf' */
+#define DUK_HEAP_STRING_SET_PROTOTYPE_OF(heap)                        DUK_HEAP_GET_STRING((heap),DUK_STRIDX_SET_PROTOTYPE_OF)
+#define DUK_HTHREAD_STRING_SET_PROTOTYPE_OF(thr)                      DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_SET_PROTOTYPE_OF)
+#define DUK_STRIDX___PROTO__                                          76                             /* '__proto__' */
+#define DUK_HEAP_STRING___PROTO__(heap)                               DUK_HEAP_GET_STRING((heap),DUK_STRIDX___PROTO__)
+#define DUK_HTHREAD_STRING___PROTO__(thr)                             DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX___PROTO__)
+#define DUK_STRIDX_REQUIRE                                            77                             /* 'require' */
+#define DUK_HEAP_STRING_REQUIRE(heap)                                 DUK_HEAP_GET_STRING((heap),DUK_STRIDX_REQUIRE)
+#define DUK_HTHREAD_STRING_REQUIRE(thr)                               DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_REQUIRE)
+#define DUK_STRIDX_ID                                                 78                             /* 'id' */
+#define DUK_HEAP_STRING_ID(heap)                                      DUK_HEAP_GET_STRING((heap),DUK_STRIDX_ID)
+#define DUK_HTHREAD_STRING_ID(thr)                                    DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_ID)
+#define DUK_STRIDX_EXPORTS                                            79                             /* 'exports' */
+#define DUK_HEAP_STRING_EXPORTS(heap)                                 DUK_HEAP_GET_STRING((heap),DUK_STRIDX_EXPORTS)
+#define DUK_HTHREAD_STRING_EXPORTS(thr)                               DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_EXPORTS)
+#define DUK_STRIDX_FILENAME                                           80                             /* 'filename' */
+#define DUK_HEAP_STRING_FILENAME(heap)                                DUK_HEAP_GET_STRING((heap),DUK_STRIDX_FILENAME)
+#define DUK_HTHREAD_STRING_FILENAME(thr)                              DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_FILENAME)
+#define DUK_STRIDX_TO_STRING                                          81                             /* 'toString' */
+#define DUK_HEAP_STRING_TO_STRING(heap)                               DUK_HEAP_GET_STRING((heap),DUK_STRIDX_TO_STRING)
+#define DUK_HTHREAD_STRING_TO_STRING(thr)                             DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_TO_STRING)
+#define DUK_STRIDX_TO_JSON                                            82                             /* 'toJSON' */
+#define DUK_HEAP_STRING_TO_JSON(heap)                                 DUK_HEAP_GET_STRING((heap),DUK_STRIDX_TO_JSON)
+#define DUK_HTHREAD_STRING_TO_JSON(thr)                               DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_TO_JSON)
+#define DUK_STRIDX_TYPE                                               83                             /* 'type' */
+#define DUK_HEAP_STRING_TYPE(heap)                                    DUK_HEAP_GET_STRING((heap),DUK_STRIDX_TYPE)
+#define DUK_HTHREAD_STRING_TYPE(thr)                                  DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_TYPE)
+#define DUK_STRIDX_DATA                                               84                             /* 'data' */
+#define DUK_HEAP_STRING_DATA(heap)                                    DUK_HEAP_GET_STRING((heap),DUK_STRIDX_DATA)
+#define DUK_HTHREAD_STRING_DATA(thr)                                  DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_DATA)
+#define DUK_STRIDX_LENGTH                                             85                             /* 'length' */
+#define DUK_HEAP_STRING_LENGTH(heap)                                  DUK_HEAP_GET_STRING((heap),DUK_STRIDX_LENGTH)
+#define DUK_HTHREAD_STRING_LENGTH(thr)                                DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_LENGTH)
+#define DUK_STRIDX_BYTE_LENGTH                                        86                             /* 'byteLength' */
+#define DUK_HEAP_STRING_BYTE_LENGTH(heap)                             DUK_HEAP_GET_STRING((heap),DUK_STRIDX_BYTE_LENGTH)
+#define DUK_HTHREAD_STRING_BYTE_LENGTH(thr)                           DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_BYTE_LENGTH)
+#define DUK_STRIDX_BYTE_OFFSET                                        87                             /* 'byteOffset' */
+#define DUK_HEAP_STRING_BYTE_OFFSET(heap)                             DUK_HEAP_GET_STRING((heap),DUK_STRIDX_BYTE_OFFSET)
+#define DUK_HTHREAD_STRING_BYTE_OFFSET(thr)                           DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_BYTE_OFFSET)
+#define DUK_STRIDX_BYTES_PER_ELEMENT                                  88                             /* 'BYTES_PER_ELEMENT' */
+#define DUK_HEAP_STRING_BYTES_PER_ELEMENT(heap)                       DUK_HEAP_GET_STRING((heap),DUK_STRIDX_BYTES_PER_ELEMENT)
+#define DUK_HTHREAD_STRING_BYTES_PER_ELEMENT(thr)                     DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_BYTES_PER_ELEMENT)
+#define DUK_STRIDX_SET                                                89                             /* 'set' */
+#define DUK_HEAP_STRING_SET(heap)                                     DUK_HEAP_GET_STRING((heap),DUK_STRIDX_SET)
+#define DUK_HTHREAD_STRING_SET(thr)                                   DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_SET)
+#define DUK_STRIDX_STACK                                              90                             /* 'stack' */
+#define DUK_HEAP_STRING_STACK(heap)                                   DUK_HEAP_GET_STRING((heap),DUK_STRIDX_STACK)
+#define DUK_HTHREAD_STRING_STACK(thr)                                 DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_STACK)
+#define DUK_STRIDX_PC                                                 91                             /* 'pc' */
+#define DUK_HEAP_STRING_PC(heap)                                      DUK_HEAP_GET_STRING((heap),DUK_STRIDX_PC)
+#define DUK_HTHREAD_STRING_PC(thr)                                    DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_PC)
+#define DUK_STRIDX_LINE_NUMBER                                        92                             /* 'lineNumber' */
+#define DUK_HEAP_STRING_LINE_NUMBER(heap)                             DUK_HEAP_GET_STRING((heap),DUK_STRIDX_LINE_NUMBER)
+#define DUK_HTHREAD_STRING_LINE_NUMBER(thr)                           DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_LINE_NUMBER)
+#define DUK_STRIDX_INT_TRACEDATA                                      93                             /* '\xffTracedata' */
+#define DUK_HEAP_STRING_INT_TRACEDATA(heap)                           DUK_HEAP_GET_STRING((heap),DUK_STRIDX_INT_TRACEDATA)
+#define DUK_HTHREAD_STRING_INT_TRACEDATA(thr)                         DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_INT_TRACEDATA)
+#define DUK_STRIDX_NAME                                               94                             /* 'name' */
+#define DUK_HEAP_STRING_NAME(heap)                                    DUK_HEAP_GET_STRING((heap),DUK_STRIDX_NAME)
+#define DUK_HTHREAD_STRING_NAME(thr)                                  DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_NAME)
+#define DUK_STRIDX_FILE_NAME                                          95                             /* 'fileName' */
+#define DUK_HEAP_STRING_FILE_NAME(heap)                               DUK_HEAP_GET_STRING((heap),DUK_STRIDX_FILE_NAME)
+#define DUK_HTHREAD_STRING_FILE_NAME(thr)                             DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_FILE_NAME)
+#define DUK_STRIDX_LC_BUFFER                                          96                             /* 'buffer' */
+#define DUK_HEAP_STRING_LC_BUFFER(heap)                               DUK_HEAP_GET_STRING((heap),DUK_STRIDX_LC_BUFFER)
+#define DUK_HTHREAD_STRING_LC_BUFFER(thr)                             DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_LC_BUFFER)
+#define DUK_STRIDX_LC_POINTER                                         97                             /* 'pointer' */
+#define DUK_HEAP_STRING_LC_POINTER(heap)                              DUK_HEAP_GET_STRING((heap),DUK_STRIDX_LC_POINTER)
+#define DUK_HTHREAD_STRING_LC_POINTER(thr)                            DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_LC_POINTER)
+#define DUK_STRIDX_INT_VALUE                                          98                             /* '\xffValue' */
+#define DUK_HEAP_STRING_INT_VALUE(heap)                               DUK_HEAP_GET_STRING((heap),DUK_STRIDX_INT_VALUE)
+#define DUK_HTHREAD_STRING_INT_VALUE(thr)                             DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_INT_VALUE)
+#define DUK_STRIDX_INT_NEXT                                           99                             /* '\xffNext' */
+#define DUK_HEAP_STRING_INT_NEXT(heap)                                DUK_HEAP_GET_STRING((heap),DUK_STRIDX_INT_NEXT)
+#define DUK_HTHREAD_STRING_INT_NEXT(thr)                              DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_INT_NEXT)
+#define DUK_STRIDX_INT_BYTECODE                                       100                            /* '\xffBytecode' */
+#define DUK_HEAP_STRING_INT_BYTECODE(heap)                            DUK_HEAP_GET_STRING((heap),DUK_STRIDX_INT_BYTECODE)
+#define DUK_HTHREAD_STRING_INT_BYTECODE(thr)                          DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_INT_BYTECODE)
+#define DUK_STRIDX_INT_FORMALS                                        101                            /* '\xffFormals' */
+#define DUK_HEAP_STRING_INT_FORMALS(heap)                             DUK_HEAP_GET_STRING((heap),DUK_STRIDX_INT_FORMALS)
+#define DUK_HTHREAD_STRING_INT_FORMALS(thr)                           DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_INT_FORMALS)
+#define DUK_STRIDX_INT_VARMAP                                         102                            /* '\xffVarmap' */
+#define DUK_HEAP_STRING_INT_VARMAP(heap)                              DUK_HEAP_GET_STRING((heap),DUK_STRIDX_INT_VARMAP)
+#define DUK_HTHREAD_STRING_INT_VARMAP(thr)                            DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_INT_VARMAP)
+#define DUK_STRIDX_INT_LEXENV                                         103                            /* '\xffLexenv' */
+#define DUK_HEAP_STRING_INT_LEXENV(heap)                              DUK_HEAP_GET_STRING((heap),DUK_STRIDX_INT_LEXENV)
+#define DUK_HTHREAD_STRING_INT_LEXENV(thr)                            DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_INT_LEXENV)
+#define DUK_STRIDX_INT_VARENV                                         104                            /* '\xffVarenv' */
+#define DUK_HEAP_STRING_INT_VARENV(heap)                              DUK_HEAP_GET_STRING((heap),DUK_STRIDX_INT_VARENV)
+#define DUK_HTHREAD_STRING_INT_VARENV(thr)                            DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_INT_VARENV)
+#define DUK_STRIDX_INT_SOURCE                                         105                            /* '\xffSource' */
+#define DUK_HEAP_STRING_INT_SOURCE(heap)                              DUK_HEAP_GET_STRING((heap),DUK_STRIDX_INT_SOURCE)
+#define DUK_HTHREAD_STRING_INT_SOURCE(thr)                            DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_INT_SOURCE)
+#define DUK_STRIDX_INT_PC2LINE                                        106                            /* '\xffPc2line' */
+#define DUK_HEAP_STRING_INT_PC2LINE(heap)                             DUK_HEAP_GET_STRING((heap),DUK_STRIDX_INT_PC2LINE)
+#define DUK_HTHREAD_STRING_INT_PC2LINE(thr)                           DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_INT_PC2LINE)
+#define DUK_STRIDX_INT_ARGS                                           107                            /* '\xffArgs' */
+#define DUK_HEAP_STRING_INT_ARGS(heap)                                DUK_HEAP_GET_STRING((heap),DUK_STRIDX_INT_ARGS)
+#define DUK_HTHREAD_STRING_INT_ARGS(thr)                              DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_INT_ARGS)
+#define DUK_STRIDX_INT_MAP                                            108                            /* '\xffMap' */
+#define DUK_HEAP_STRING_INT_MAP(heap)                                 DUK_HEAP_GET_STRING((heap),DUK_STRIDX_INT_MAP)
+#define DUK_HTHREAD_STRING_INT_MAP(thr)                               DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_INT_MAP)
+#define DUK_STRIDX_INT_FINALIZER                                      109                            /* '\xffFinalizer' */
+#define DUK_HEAP_STRING_INT_FINALIZER(heap)                           DUK_HEAP_GET_STRING((heap),DUK_STRIDX_INT_FINALIZER)
+#define DUK_HTHREAD_STRING_INT_FINALIZER(thr)                         DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_INT_FINALIZER)
+#define DUK_STRIDX_INT_HANDLER                                        110                            /* '\xffHandler' */
+#define DUK_HEAP_STRING_INT_HANDLER(heap)                             DUK_HEAP_GET_STRING((heap),DUK_STRIDX_INT_HANDLER)
+#define DUK_HTHREAD_STRING_INT_HANDLER(thr)                           DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_INT_HANDLER)
+#define DUK_STRIDX_INT_CALLEE                                         111                            /* '\xffCallee' */
+#define DUK_HEAP_STRING_INT_CALLEE(heap)                              DUK_HEAP_GET_STRING((heap),DUK_STRIDX_INT_CALLEE)
+#define DUK_HTHREAD_STRING_INT_CALLEE(thr)                            DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_INT_CALLEE)
+#define DUK_STRIDX_INT_THREAD                                         112                            /* '\xffThread' */
+#define DUK_HEAP_STRING_INT_THREAD(heap)                              DUK_HEAP_GET_STRING((heap),DUK_STRIDX_INT_THREAD)
+#define DUK_HTHREAD_STRING_INT_THREAD(thr)                            DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_INT_THREAD)
+#define DUK_STRIDX_INT_REGBASE                                        113                            /* '\xffRegbase' */
+#define DUK_HEAP_STRING_INT_REGBASE(heap)                             DUK_HEAP_GET_STRING((heap),DUK_STRIDX_INT_REGBASE)
+#define DUK_HTHREAD_STRING_INT_REGBASE(thr)                           DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_INT_REGBASE)
+#define DUK_STRIDX_INT_TARGET                                         114                            /* '\xffTarget' */
+#define DUK_HEAP_STRING_INT_TARGET(heap)                              DUK_HEAP_GET_STRING((heap),DUK_STRIDX_INT_TARGET)
+#define DUK_HTHREAD_STRING_INT_TARGET(thr)                            DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_INT_TARGET)
+#define DUK_STRIDX_INT_THIS                                           115                            /* '\xffThis' */
+#define DUK_HEAP_STRING_INT_THIS(heap)                                DUK_HEAP_GET_STRING((heap),DUK_STRIDX_INT_THIS)
+#define DUK_HTHREAD_STRING_INT_THIS(thr)                              DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_INT_THIS)
+#define DUK_STRIDX_COMPILE                                            116                            /* 'compile' */
+#define DUK_HEAP_STRING_COMPILE(heap)                                 DUK_HEAP_GET_STRING((heap),DUK_STRIDX_COMPILE)
+#define DUK_HTHREAD_STRING_COMPILE(thr)                               DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_COMPILE)
+#define DUK_STRIDX_INPUT                                              117                            /* 'input' */
+#define DUK_HEAP_STRING_INPUT(heap)                                   DUK_HEAP_GET_STRING((heap),DUK_STRIDX_INPUT)
+#define DUK_HTHREAD_STRING_INPUT(thr)                                 DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_INPUT)
+#define DUK_STRIDX_ERR_CREATE                                         118                            /* 'errCreate' */
+#define DUK_HEAP_STRING_ERR_CREATE(heap)                              DUK_HEAP_GET_STRING((heap),DUK_STRIDX_ERR_CREATE)
+#define DUK_HTHREAD_STRING_ERR_CREATE(thr)                            DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_ERR_CREATE)
+#define DUK_STRIDX_ERR_THROW                                          119                            /* 'errThrow' */
+#define DUK_HEAP_STRING_ERR_THROW(heap)                               DUK_HEAP_GET_STRING((heap),DUK_STRIDX_ERR_THROW)
+#define DUK_HTHREAD_STRING_ERR_THROW(thr)                             DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_ERR_THROW)
+#define DUK_STRIDX_MOD_SEARCH                                         120                            /* 'modSearch' */
+#define DUK_HEAP_STRING_MOD_SEARCH(heap)                              DUK_HEAP_GET_STRING((heap),DUK_STRIDX_MOD_SEARCH)
+#define DUK_HTHREAD_STRING_MOD_SEARCH(thr)                            DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_MOD_SEARCH)
+#define DUK_STRIDX_MOD_LOADED                                         121                            /* 'modLoaded' */
+#define DUK_HEAP_STRING_MOD_LOADED(heap)                              DUK_HEAP_GET_STRING((heap),DUK_STRIDX_MOD_LOADED)
+#define DUK_HTHREAD_STRING_MOD_LOADED(thr)                            DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_MOD_LOADED)
+#define DUK_STRIDX_ENV                                                122                            /* 'env' */
+#define DUK_HEAP_STRING_ENV(heap)                                     DUK_HEAP_GET_STRING((heap),DUK_STRIDX_ENV)
+#define DUK_HTHREAD_STRING_ENV(thr)                                   DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_ENV)
+#define DUK_STRIDX_HEX                                                123                            /* 'hex' */
+#define DUK_HEAP_STRING_HEX(heap)                                     DUK_HEAP_GET_STRING((heap),DUK_STRIDX_HEX)
+#define DUK_HTHREAD_STRING_HEX(thr)                                   DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_HEX)
+#define DUK_STRIDX_BASE64                                             124                            /* 'base64' */
+#define DUK_HEAP_STRING_BASE64(heap)                                  DUK_HEAP_GET_STRING((heap),DUK_STRIDX_BASE64)
+#define DUK_HTHREAD_STRING_BASE64(thr)                                DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_BASE64)
+#define DUK_STRIDX_JX                                                 125                            /* 'jx' */
+#define DUK_HEAP_STRING_JX(heap)                                      DUK_HEAP_GET_STRING((heap),DUK_STRIDX_JX)
+#define DUK_HTHREAD_STRING_JX(thr)                                    DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_JX)
+#define DUK_STRIDX_JC                                                 126                            /* 'jc' */
+#define DUK_HEAP_STRING_JC(heap)                                      DUK_HEAP_GET_STRING((heap),DUK_STRIDX_JC)
+#define DUK_HTHREAD_STRING_JC(thr)                                    DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_JC)
+#define DUK_STRIDX_RESUME                                             127                            /* 'resume' */
+#define DUK_HEAP_STRING_RESUME(heap)                                  DUK_HEAP_GET_STRING((heap),DUK_STRIDX_RESUME)
+#define DUK_HTHREAD_STRING_RESUME(thr)                                DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_RESUME)
+#define DUK_STRIDX_FMT                                                128                            /* 'fmt' */
+#define DUK_HEAP_STRING_FMT(heap)                                     DUK_HEAP_GET_STRING((heap),DUK_STRIDX_FMT)
+#define DUK_HTHREAD_STRING_FMT(thr)                                   DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_FMT)
+#define DUK_STRIDX_RAW                                                129                            /* 'raw' */
+#define DUK_HEAP_STRING_RAW(heap)                                     DUK_HEAP_GET_STRING((heap),DUK_STRIDX_RAW)
+#define DUK_HTHREAD_STRING_RAW(thr)                                   DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_RAW)
+#define DUK_STRIDX_LC_TRACE                                           130                            /* 'trace' */
+#define DUK_HEAP_STRING_LC_TRACE(heap)                                DUK_HEAP_GET_STRING((heap),DUK_STRIDX_LC_TRACE)
+#define DUK_HTHREAD_STRING_LC_TRACE(thr)                              DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_LC_TRACE)
+#define DUK_STRIDX_LC_DEBUG                                           131                            /* 'debug' */
+#define DUK_HEAP_STRING_LC_DEBUG(heap)                                DUK_HEAP_GET_STRING((heap),DUK_STRIDX_LC_DEBUG)
+#define DUK_HTHREAD_STRING_LC_DEBUG(thr)                              DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_LC_DEBUG)
+#define DUK_STRIDX_LC_INFO                                            132                            /* 'info' */
+#define DUK_HEAP_STRING_LC_INFO(heap)                                 DUK_HEAP_GET_STRING((heap),DUK_STRIDX_LC_INFO)
+#define DUK_HTHREAD_STRING_LC_INFO(thr)                               DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_LC_INFO)
+#define DUK_STRIDX_LC_WARN                                            133                            /* 'warn' */
+#define DUK_HEAP_STRING_LC_WARN(heap)                                 DUK_HEAP_GET_STRING((heap),DUK_STRIDX_LC_WARN)
+#define DUK_HTHREAD_STRING_LC_WARN(thr)                               DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_LC_WARN)
+#define DUK_STRIDX_LC_ERROR                                           134                            /* 'error' */
+#define DUK_HEAP_STRING_LC_ERROR(heap)                                DUK_HEAP_GET_STRING((heap),DUK_STRIDX_LC_ERROR)
+#define DUK_HTHREAD_STRING_LC_ERROR(thr)                              DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_LC_ERROR)
+#define DUK_STRIDX_LC_FATAL                                           135                            /* 'fatal' */
+#define DUK_HEAP_STRING_LC_FATAL(heap)                                DUK_HEAP_GET_STRING((heap),DUK_STRIDX_LC_FATAL)
+#define DUK_HTHREAD_STRING_LC_FATAL(thr)                              DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_LC_FATAL)
+#define DUK_STRIDX_LC_N                                               136                            /* 'n' */
+#define DUK_HEAP_STRING_LC_N(heap)                                    DUK_HEAP_GET_STRING((heap),DUK_STRIDX_LC_N)
+#define DUK_HTHREAD_STRING_LC_N(thr)                                  DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_LC_N)
+#define DUK_STRIDX_LC_L                                               137                            /* 'l' */
+#define DUK_HEAP_STRING_LC_L(heap)                                    DUK_HEAP_GET_STRING((heap),DUK_STRIDX_LC_L)
+#define DUK_HTHREAD_STRING_LC_L(thr)                                  DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_LC_L)
+#define DUK_STRIDX_CLOG                                               138                            /* 'clog' */
+#define DUK_HEAP_STRING_CLOG(heap)                                    DUK_HEAP_GET_STRING((heap),DUK_STRIDX_CLOG)
+#define DUK_HTHREAD_STRING_CLOG(thr)                                  DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_CLOG)
+#define DUK_STRIDX_TO_LOG_STRING                                      139                            /* 'toLogString' */
+#define DUK_HEAP_STRING_TO_LOG_STRING(heap)                           DUK_HEAP_GET_STRING((heap),DUK_STRIDX_TO_LOG_STRING)
+#define DUK_HTHREAD_STRING_TO_LOG_STRING(thr)                         DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_TO_LOG_STRING)
+#define DUK_STRIDX_JSON_EXT_UNDEFINED                                 140                            /* '{"_undef":true}' */
+#define DUK_HEAP_STRING_JSON_EXT_UNDEFINED(heap)                      DUK_HEAP_GET_STRING((heap),DUK_STRIDX_JSON_EXT_UNDEFINED)
+#define DUK_HTHREAD_STRING_JSON_EXT_UNDEFINED(thr)                    DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_JSON_EXT_UNDEFINED)
+#define DUK_STRIDX_JSON_EXT_NAN                                       141                            /* '{"_nan":true}' */
+#define DUK_HEAP_STRING_JSON_EXT_NAN(heap)                            DUK_HEAP_GET_STRING((heap),DUK_STRIDX_JSON_EXT_NAN)
+#define DUK_HTHREAD_STRING_JSON_EXT_NAN(thr)                          DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_JSON_EXT_NAN)
+#define DUK_STRIDX_JSON_EXT_POSINF                                    142                            /* '{"_inf":true}' */
+#define DUK_HEAP_STRING_JSON_EXT_POSINF(heap)                         DUK_HEAP_GET_STRING((heap),DUK_STRIDX_JSON_EXT_POSINF)
+#define DUK_HTHREAD_STRING_JSON_EXT_POSINF(thr)                       DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_JSON_EXT_POSINF)
+#define DUK_STRIDX_JSON_EXT_NEGINF                                    143                            /* '{"_ninf":true}' */
+#define DUK_HEAP_STRING_JSON_EXT_NEGINF(heap)                         DUK_HEAP_GET_STRING((heap),DUK_STRIDX_JSON_EXT_NEGINF)
+#define DUK_HTHREAD_STRING_JSON_EXT_NEGINF(thr)                       DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_JSON_EXT_NEGINF)
+#define DUK_STRIDX_JSON_EXT_FUNCTION1                                 144                            /* '{"_func":true}' */
+#define DUK_HEAP_STRING_JSON_EXT_FUNCTION1(heap)                      DUK_HEAP_GET_STRING((heap),DUK_STRIDX_JSON_EXT_FUNCTION1)
+#define DUK_HTHREAD_STRING_JSON_EXT_FUNCTION1(thr)                    DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_JSON_EXT_FUNCTION1)
+#define DUK_STRIDX_JSON_EXT_FUNCTION2                                 145                            /* '{_func:true}' */
+#define DUK_HEAP_STRING_JSON_EXT_FUNCTION2(heap)                      DUK_HEAP_GET_STRING((heap),DUK_STRIDX_JSON_EXT_FUNCTION2)
+#define DUK_HTHREAD_STRING_JSON_EXT_FUNCTION2(thr)                    DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_JSON_EXT_FUNCTION2)
+#define DUK_STRIDX_BREAK                                              146                            /* 'break' */
+#define DUK_HEAP_STRING_BREAK(heap)                                   DUK_HEAP_GET_STRING((heap),DUK_STRIDX_BREAK)
+#define DUK_HTHREAD_STRING_BREAK(thr)                                 DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_BREAK)
+#define DUK_STRIDX_CASE                                               147                            /* 'case' */
+#define DUK_HEAP_STRING_CASE(heap)                                    DUK_HEAP_GET_STRING((heap),DUK_STRIDX_CASE)
+#define DUK_HTHREAD_STRING_CASE(thr)                                  DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_CASE)
+#define DUK_STRIDX_CATCH                                              148                            /* 'catch' */
+#define DUK_HEAP_STRING_CATCH(heap)                                   DUK_HEAP_GET_STRING((heap),DUK_STRIDX_CATCH)
+#define DUK_HTHREAD_STRING_CATCH(thr)                                 DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_CATCH)
+#define DUK_STRIDX_CONTINUE                                           149                            /* 'continue' */
+#define DUK_HEAP_STRING_CONTINUE(heap)                                DUK_HEAP_GET_STRING((heap),DUK_STRIDX_CONTINUE)
+#define DUK_HTHREAD_STRING_CONTINUE(thr)                              DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_CONTINUE)
+#define DUK_STRIDX_DEBUGGER                                           150                            /* 'debugger' */
+#define DUK_HEAP_STRING_DEBUGGER(heap)                                DUK_HEAP_GET_STRING((heap),DUK_STRIDX_DEBUGGER)
+#define DUK_HTHREAD_STRING_DEBUGGER(thr)                              DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_DEBUGGER)
+#define DUK_STRIDX_DEFAULT                                            151                            /* 'default' */
+#define DUK_HEAP_STRING_DEFAULT(heap)                                 DUK_HEAP_GET_STRING((heap),DUK_STRIDX_DEFAULT)
+#define DUK_HTHREAD_STRING_DEFAULT(thr)                               DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_DEFAULT)
+#define DUK_STRIDX_DELETE                                             152                            /* 'delete' */
+#define DUK_HEAP_STRING_DELETE(heap)                                  DUK_HEAP_GET_STRING((heap),DUK_STRIDX_DELETE)
+#define DUK_HTHREAD_STRING_DELETE(thr)                                DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_DELETE)
+#define DUK_STRIDX_DO                                                 153                            /* 'do' */
+#define

<TRUNCATED>

[30/51] [partial] nifi-minifi-cpp git commit: MINIFI-183 Added civet 1.9.1 sources Added onScheduled hook Added initial two-way TLS-enabled ListenHTTP implementation

Posted by al...@apache.org.
http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/debugger/duk_debug.js
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/debugger/duk_debug.js b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/debugger/duk_debug.js
new file mode 100644
index 0000000..ab0623f
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/debugger/duk_debug.js
@@ -0,0 +1,2473 @@
+/*
+ *  Minimal debug web console for Duktape command line tool
+ *
+ *  See debugger/README.rst.
+ *
+ *  The web UI socket.io communication can easily become a bottleneck and
+ *  it's important to ensure that the web UI remains responsive.  Basic rate
+ *  limiting mechanisms (token buckets, suppressing identical messages, etc)
+ *  are used here now.  Ideally the web UI would pull data on its own terms
+ *  which would provide natural rate limiting.
+ *
+ *  Promises are used to structure callback chains.
+ *
+ *  https://github.com/petkaantonov/bluebird
+ *  https://github.com/petkaantonov/bluebird/blob/master/API.md
+ *  https://github.com/petkaantonov/bluebird/wiki/Promise-anti-patterns
+ */
+
+var Promise = require('bluebird');
+var events = require('events');
+var stream = require('stream');
+var path = require('path');
+var fs = require('fs');
+var net = require('net');
+var byline = require('byline');
+var util = require('util');
+var readline = require('readline');
+var sprintf = require('sprintf').sprintf;
+var utf8 = require('utf8');
+var wrench = require('wrench');  // https://github.com/ryanmcgrath/wrench-js
+var yaml = require('yamljs');
+
+// Command line options (defaults here, overwritten if necessary)
+var optTargetHost = '127.0.0.1';
+var optTargetPort = 9091;
+var optHttpPort = 9092;
+var optJsonProxyPort = 9093;
+var optJsonProxy = false;
+var optSourceSearchDirs = [ '../tests/ecmascript' ];
+var optDumpDebugRead = null;
+var optDumpDebugWrite = null;
+var optDumpDebugPretty = null;
+var optLogMessages = false;
+
+// Constants
+var UI_MESSAGE_CLIPLEN = 128;
+var LOCALS_CLIPLEN = 64;
+var EVAL_CLIPLEN = 4096;
+var GETVAR_CLIPLEN = 4096;
+
+// Commands initiated by Duktape
+var CMD_STATUS = 0x01;
+var CMD_PRINT = 0x02;
+var CMD_ALERT = 0x03;
+var CMD_LOG = 0x04;
+var CMD_THROW = 0x05;
+var CMD_DETACHING = 0x06;
+
+// Commands initiated by the debug client (= us)
+var CMD_BASICINFO = 0x10;
+var CMD_TRIGGERSTATUS = 0x11;
+var CMD_PAUSE = 0x12;
+var CMD_RESUME = 0x13;
+var CMD_STEPINTO = 0x14;
+var CMD_STEPOVER = 0x15;
+var CMD_STEPOUT = 0x16;
+var CMD_LISTBREAK = 0x17;
+var CMD_ADDBREAK = 0x18;
+var CMD_DELBREAK = 0x19;
+var CMD_GETVAR = 0x1a;
+var CMD_PUTVAR = 0x1b;
+var CMD_GETCALLSTACK = 0x1c;
+var CMD_GETLOCALS = 0x1d;
+var CMD_EVAL = 0x1e;
+var CMD_DETACH = 0x1f;
+var CMD_DUMPHEAP = 0x20;
+var CMD_GETBYTECODE = 0x21;
+
+// Errors
+var ERR_UNKNOWN = 0x00;
+var ERR_UNSUPPORTED = 0x01;
+var ERR_TOOMANY = 0x02;
+var ERR_NOTFOUND = 0x03;
+
+// Marker objects for special protocol values
+var DVAL_EOM = { type: 'eom' };
+var DVAL_REQ = { type: 'req' };
+var DVAL_REP = { type: 'rep' };
+var DVAL_ERR = { type: 'err' };
+var DVAL_NFY = { type: 'nfy' };
+
+// String map for commands (debug dumping).  A single map works (instead of
+// separate maps for each direction) because command numbers don't currently
+// overlap.  So merge the YAML metadata.
+var debugCommandMeta = yaml.load('duk_debugcommands.yaml');
+var debugCommandNames = [];  // list of command names, merged client/target
+debugCommandMeta.target_commands.forEach(function (k, i) {
+    debugCommandNames[i] = k;
+});
+debugCommandMeta.client_commands.forEach(function (k, i) {  // override
+    debugCommandNames[i] = k;
+});
+var debugCommandNumbers = {};  // map from (merged) command name to number
+debugCommandNames.forEach(function (k, i) {
+    debugCommandNumbers[k] = i;
+});
+
+// Duktape heaphdr type constants, must match C headers
+var DUK_HTYPE_STRING = 1;
+var DUK_HTYPE_OBJECT = 2;
+var DUK_HTYPE_BUFFER = 3;
+
+// Duktape internal class numbers, must match C headers
+var dukClassNameMeta = yaml.load('duk_classnames.yaml');
+var dukClassNames = dukClassNameMeta.class_names;
+
+// Bytecode opcode/extraop metadata
+var dukOpcodes = yaml.load('duk_opcodes.yaml');
+if (dukOpcodes.opcodes.length != 64) {
+    throw new Error('opcode metadata length incorrect');
+}
+if (dukOpcodes.extra.length != 256) {
+    throw new Error('extraop metadata length incorrect');
+}
+
+/*
+ *  Miscellaneous helpers
+ */
+
+var nybbles = '0123456789abcdef';
+
+/* Convert a buffer into a string using Unicode codepoints U+0000...U+00FF.
+ * This is the NodeJS 'binary' encoding, but since it's being deprecated,
+ * reimplement it here.  We need to avoid parsing strings as e.g. UTF-8:
+ * although Duktape strings are usually UTF-8/CESU-8 that's not always the
+ * case, e.g. for internal strings.  Buffer values are also represented as
+ * strings in the debug protocol, so we must deal accurately with arbitrary
+ * byte arrays.
+ */
+function bufferToDebugString(buf) {
+    var cp = [];
+    var i, n;
+
+/*
+    // This fails with "RangeError: Maximum call stack size exceeded" for some
+    // reason, so use a much slower variant.
+
+    for (i = 0, n = buf.length; i < n; i++) {
+        cp[i] = buf[i];
+    }
+
+    return String.fromCharCode.apply(String, cp);
+*/
+
+    for (i = 0, n = buf.length; i < n; i++) {
+        cp[i] = String.fromCharCode(buf[i]);
+    }
+
+    return cp.join('');
+}
+
+/* Write a string into a buffer interpreting codepoints U+0000...U+00FF
+ * as bytes.  Drop higher bits.
+ */
+function writeDebugStringToBuffer(str, buf, off) {
+    var i, n;
+
+    for (i = 0, n = str.length; i < n; i++) {
+        buf[off + i] = str.charCodeAt(i) & 0xff;  // truncate higher bits
+    }
+}
+
+/* Encode an ordinary Unicode string into a dvalue compatible format, i.e.
+ * into a byte array represented as codepoints U+0000...U+00FF.  Concretely,
+ * encode with UTF-8 and then represent the bytes with U+0000...U+00FF.
+ */
+function stringToDebugString(str) {
+    return utf8.encode(str);
+}
+
+/* Pretty print a dvalue.  Useful for dumping etc. */
+function prettyDebugValue(x) {
+    if (typeof x === 'object' && x !== null) {
+        if (x.type === 'eom') {
+            return 'EOM';
+        } else if (x.type === 'req') {
+            return 'REQ';
+        } else if (x.type === 'rep') {
+            return 'REP';
+        } else if (x.type === 'err') {
+            return 'ERR';
+        } else if (x.type === 'nfy') {
+            return 'NFY';
+        }
+    }
+    return JSON.stringify(x);
+}
+
+/* Pretty print a number for UI usage.  Types and values should be easy to
+ * read and typing should be obvious.  For numbers, support Infinity, NaN,
+ * and signed zeroes properly.
+ */
+function prettyUiNumber(x) {
+    if (x === 1 / 0) { return 'Infinity'; }
+    if (x === -1 / 0) { return '-Infinity'; }
+    if (Number.isNaN(x)) { return 'NaN'; }
+    if (x === 0 && 1 / x > 0) { return '0'; }
+    if (x === 0 && 1 / x < 0) { return '-0'; }
+    return x.toString();
+}
+
+/* Pretty print a dvalue string (bytes represented as U+0000...U+00FF)
+ * for UI usage.  Try UTF-8 decoding to get a nice Unicode string (JSON
+ * encoded) but if that fails, ensure that bytes are encoded transparently.
+ * The result is a quoted string with a special quote marker for a "raw"
+ * string when UTF-8 decoding fails.  Very long strings are optionally
+ * clipped.
+ */
+function prettyUiString(x, cliplen) {
+    var ret;
+
+    if (typeof x !== 'string') {
+        throw new Error('invalid input to prettyUiString: ' + typeof x);
+    }
+    try {
+        // Here utf8.decode() is better than decoding using NodeJS buffer
+        // operations because we want strict UTF-8 interpretation.
+        ret = JSON.stringify(utf8.decode(x));
+    } catch (e) {
+        // When we fall back to representing bytes, indicate that the string
+        // is "raw" with a 'r"' prefix (a somewhat arbitrary convention).
+        // U+0022 = ", U+0027 = '
+        ret = 'r"' + x.replace(/[\u0022\u0027\u0000-\u001f\u0080-\uffff]/g, function (match) {
+            var cp = match.charCodeAt(0);
+            return '\\x' + nybbles[(cp >> 4) & 0x0f] + nybbles[cp & 0x0f];
+        }) + '"';
+    }
+
+    if (cliplen && ret.length > cliplen) {
+        ret = ret.substring(0, cliplen) + '...';  // trailing '"' intentionally missing
+    }
+    return ret;
+}
+
+/* Pretty print a dvalue string (bytes represented as U+0000...U+00FF)
+ * for UI usage without quotes.
+ */
+function prettyUiStringUnquoted(x, cliplen) {
+    var ret;
+
+    if (typeof x !== 'string') {
+        throw new Error('invalid input to prettyUiStringUnquoted: ' + typeof x);
+    }
+
+    try {
+        // Here utf8.decode() is better than decoding using NodeJS buffer
+        // operations because we want strict UTF-8 interpretation.
+
+        // XXX: unprintable characters etc?  In some UI cases we'd want to
+        // e.g. escape newlines and in others not.
+        ret = utf8.decode(x);
+    } catch (e) {
+        // For the unquoted version we don't need to escape single or double
+        // quotes.
+        ret = x.replace(/[\u0000-\u001f\u0080-\uffff]/g, function (match) {
+            var cp = match.charCodeAt(0);
+            return '\\x' + nybbles[(cp >> 4) & 0x0f] + nybbles[cp & 0x0f];
+        });
+    }
+
+    if (cliplen && ret.length > cliplen) {
+        ret = ret.substring(0, cliplen) + '...';
+    }
+    return ret;
+}
+
+/* Pretty print a dvalue for UI usage.  Everything comes out as a ready-to-use
+ * string.
+ *
+ * XXX: Currently the debug client formats all values for UI use.  A better
+ * solution would be to pass values in typed form and let the UI format them,
+ * so that styling etc. could take typing into account.
+ */
+function prettyUiDebugValue(x, cliplen) {
+    if (typeof x === 'object' && x !== null) {
+        // Note: typeof null === 'object', so null special case explicitly
+        if (x.type === 'eom') {
+            return 'EOM';
+        } else if (x.type === 'req') {
+            return 'REQ';
+        } else if (x.type === 'rep') {
+            return 'REP';
+        } else if (x.type === 'err') {
+            return 'ERR';
+        } else if (x.type === 'nfy') {
+            return 'NFY';
+        } else if (x.type === 'unused') {
+            return 'unused';
+        } else if (x.type === 'undefined') {
+            return 'undefined';
+        } else if (x.type === 'buffer') {
+            return '|' + x.data + '|';
+        } else if (x.type === 'object') {
+            return '[object ' + (dukClassNames[x.class] || ('class ' + x.class)) + ' ' + x.pointer + ']';
+        } else if (x.type === 'pointer') {
+            return '<pointer ' + x.pointer + '>';
+        } else if (x.type === 'lightfunc') {
+            return '<lightfunc 0x' + x.flags.toString(16) + ' ' + x.pointer + '>';
+        } else if (x.type === 'number') {
+            // duk_tval number, any IEEE double
+            var tmp = new Buffer(x.data, 'hex');  // decode into hex
+            var val = tmp.readDoubleBE(0);        // big endian ieee double
+            return prettyUiNumber(val);
+        }
+    } else if (x === null) {
+        return 'null';
+    } else if (typeof x === 'boolean') {
+        return x ? 'true' : 'false';
+    } else if (typeof x === 'string') {
+        return prettyUiString(x, cliplen);
+    } else if (typeof x === 'number') {
+        // Debug protocol integer
+        return prettyUiNumber(x);
+    }
+
+    // We shouldn't come here, but if we do, JSON is a reasonable default.
+    return JSON.stringify(x);
+}
+
+/* Pretty print a debugger message given as an array of parsed dvalues.
+ * Result should be a pure ASCII one-liner.
+ */
+function prettyDebugMessage(msg) {
+    return msg.map(prettyDebugValue).join(' ');
+}
+
+/* Pretty print a debugger command. */
+function prettyDebugCommand(cmd) {
+    return debugCommandNames[cmd] || String(cmd);
+}
+
+/* Decode and normalize source file contents: UTF-8, tabs to 8,
+ * CR LF to LF.
+ */
+function decodeAndNormalizeSource(data) {
+    var tmp;
+    var lines, line, repl;
+    var i, n;
+    var j, m;
+
+    try {
+        tmp = data.toString('utf8');
+    } catch (e) {
+        console.log('Failed to UTF-8 decode source file, ignoring: ' + e);
+        tmp = String(data);
+    }
+
+    lines = tmp.split(/\r?\n/);
+    for (i = 0, n = lines.length; i < n; i++) {
+        line = lines[i];
+        if (/\t/.test(line)) {
+            repl = '';
+            for (j = 0, m = line.length; j < m; j++) {
+                if (line.charAt(j) === '\t') {
+                    repl += ' ';
+                    while ((repl.length % 8) != 0) {
+                        repl += ' ';
+                    }
+                } else {
+                    repl += line.charAt(j);
+                }
+            }
+            lines[i] = repl;
+        }
+    }
+
+    // XXX: normalize last newline (i.e. force a newline if contents don't
+    // end with a newline)?
+
+    return lines.join('\n');
+}
+
+/* Token bucket rate limiter for a given callback.  Calling code calls
+ * trigger() to request 'cb' to be called, and the rate limiter ensures
+ * that 'cb' is not called too often.
+ */
+function RateLimited(tokens, rate, cb) {
+    var _this = this;
+    this.maxTokens = tokens;
+    this.tokens = this.maxTokens;
+    this.rate = rate;
+    this.cb = cb;
+    this.delayedCb = false;
+
+    // Right now the implementation is setInterval-based, but could also be
+    // made timerless.  There are so few rate limited resources that this
+    // doesn't matter in practice.
+
+    this.tokenAdder = setInterval(function () {
+        if (_this.tokens < _this.maxTokens) {
+            _this.tokens++;
+        }
+        if (_this.delayedCb) {
+            _this.delayedCb = false;
+            _this.tokens--;
+            _this.cb();
+        }
+    }, this.rate);
+}
+RateLimited.prototype.trigger = function () {
+    if (this.tokens > 0) {
+        this.tokens--;
+        this.cb();
+    } else {
+        this.delayedCb = true;
+    }
+};
+
+/*
+ *  Source file manager
+ *
+ *  Scan the list of search directories for Ecmascript source files and
+ *  build an index of them.  Provides a mechanism to find a source file
+ *  based on a raw 'fileName' property provided by the debug target, and
+ *  to provide a file list for the web UI.
+ *
+ *  NOTE: it's tempting to do loose matching for filenames, but this does
+ *  not work in practice.  Filenames must match 1:1 with the debug target
+ *  so that e.g. breakpoints assigned based on filenames found from the
+ *  search paths will match 1:1 on the debug target.  If this is not the
+ *  case, breakpoints won't work as expected.
+ */
+
+function SourceFileManager(directories) {
+    this.directories = directories;
+    this.extensions = { '.js': true, '.jsm': true };
+    this.files;
+}
+
+SourceFileManager.prototype.scan = function () {
+    var _this = this;
+    var fileMap = {};   // absFn -> true
+    var files;
+
+    this.directories.forEach(function (dir) {
+        console.log('Scanning source files: ' + dir);
+        try {
+            wrench.readdirSyncRecursive(dir).forEach(function (fn) {
+                var absFn = path.normalize(path.join(dir, fn));   // './foo/bar.js' -> 'foo/bar.js'
+                var ent;
+
+                if (fs.existsSync(absFn) &&
+                    fs.lstatSync(absFn).isFile() &&
+                    _this.extensions[path.extname(fn)]) {
+                    // We want the fileMap to contain the filename relative to
+                    // the search dir root.
+                    fileMap[fn] = true;
+                }
+            });
+        } catch (e) {
+            console.log('Failed to scan ' + dir + ': ' + e);
+        }
+    });
+
+    files = Object.keys(fileMap);
+    files.sort();
+    this.files = files;
+
+    console.log('Found ' + files.length + ' source files in ' + this.directories.length + ' search directories');
+};
+
+SourceFileManager.prototype.getFiles = function () {
+    return this.files;
+};
+
+SourceFileManager.prototype.search = function (fileName) {
+    var _this = this;
+
+    // Loose matching is tempting but counterproductive: filenames must
+    // match 1:1 between the debug client and the debug target for e.g.
+    // breakpoints to work as expected.  Note that a breakpoint may be
+    // assigned by selecting a file from a dropdown populated by scanning
+    // the filesystem for available sources and there's no way of knowing
+    // if the debug target uses the exact same name.
+
+    function tryLookup() {
+        var i, fn, data;
+
+        for (i = 0; i < _this.directories.length; i++) {
+            fn = path.join(_this.directories[i], fileName);
+            if (fs.existsSync(fn) && fs.lstatSync(fn).isFile()) {
+                data = fs.readFileSync(fn);             // Raw bytes
+                return decodeAndNormalizeSource(data);  // Unicode string
+            }
+        }
+        return null;
+    }
+
+    return tryLookup(fileName);
+};
+
+/*
+ *  Debug protocol parser
+ *
+ *  The debug protocol parser is an EventEmitter which parses debug messages
+ *  from an input stream and emits 'debug-message' events for completed
+ *  messages ending in an EOM.  The parser also provides debug dumping, stream
+ *  logging functionality, and statistics gathering functionality.
+ *
+ *  This parser is used to parse both incoming and outgoing messages.  For
+ *  outgoing messages the only function is to validate and debug dump the
+ *  messages we're about to send.  The downside of dumping at this low level
+ *  is that we can't match request and reply/error messages here.
+ *
+ *  http://www.sitepoint.com/nodejs-events-and-eventemitter/
+ */
+
+function DebugProtocolParser(inputStream,
+                             protocolVersion,
+                             rawDumpFileName,
+                             textDumpFileName,
+                             textDumpFilePrefix,
+                             hexDumpConsolePrefix,
+                             textDumpConsolePrefix) {
+    var _this = this;
+    this.inputStream = inputStream;
+    this.closed = false;       // stream is closed/broken, don't parse anymore
+    this.bytes = 0;
+    this.dvalues = 0;
+    this.messages = 0;
+    this.requests = 0;
+    this.prevBytes = 0;
+    this.bytesPerSec = 0;
+    this.statsTimer = null;
+    this.readableNumberValue = true;
+
+    events.EventEmitter.call(this);
+
+    var buf = new Buffer(0);    // accumulate data
+    var msg = [];               // accumulated message until EOM
+    var versionIdentification;
+
+    var statsInterval = 2000;
+    var statsIntervalSec = statsInterval / 1000;
+    this.statsTimer = setInterval(function () {
+        _this.bytesPerSec = (_this.bytes - _this.prevBytes) / statsIntervalSec;
+        _this.prevBytes = _this.bytes;
+        _this.emit('stats-update');
+    }, statsInterval);
+
+    function consume(n) {
+        var tmp = new Buffer(buf.length - n);
+        buf.copy(tmp, 0, n);
+        buf = tmp;
+    }
+
+    inputStream.on('data', function (data) {
+        var i, n, x, v, gotValue, len, t, tmpbuf, verstr;
+        var prettyMsg;
+
+        if (_this.closed || !_this.inputStream) {
+            console.log('Ignoring incoming data from closed input stream, len ' + data.length);
+            return;
+        }
+
+        _this.bytes += data.length;
+        if (rawDumpFileName) {
+            fs.appendFileSync(rawDumpFileName, data);
+        }
+        if (hexDumpConsolePrefix) {
+            console.log(hexDumpConsolePrefix + data.toString('hex'));
+        }
+
+        buf = Buffer.concat([ buf, data ]);
+
+        // Protocol version handling.  When dumping an output stream, the
+        // caller gives a non-null protocolVersion so we don't read one here.
+        if (protocolVersion == null) {
+            if (buf.length > 1024) {
+                _this.emit('transport-error', 'Parse error (version identification too long), dropping connection');
+                _this.close();
+                return;
+            }
+
+            for (i = 0, n = buf.length; i < n; i++) {
+                if (buf[i] == 0x0a) {
+                    tmpbuf = new Buffer(i);
+                    buf.copy(tmpbuf, 0, 0, i);
+                    consume(i + 1);
+                    verstr = tmpbuf.toString('utf-8');
+                    t = verstr.split(' ');
+                    protocolVersion = Number(t[0]);
+                    versionIdentification = verstr;
+
+                    _this.emit('protocol-version', {
+                        protocolVersion: protocolVersion,
+                        versionIdentification: versionIdentification
+                    });
+                    break;
+                }
+            }
+
+            if (protocolVersion == null) {
+                // Still waiting for version identification to complete.
+                return;
+            }
+        }
+
+        // Parse complete dvalues (quite inefficient now) by trial parsing.
+        // Consume a value only when it's fully present in 'buf'.
+        // See doc/debugger.rst for format description.
+
+        while (buf.length > 0) {
+            x = buf[0];
+            v = undefined;
+            gotValue = false;  // used to flag special values like undefined
+
+            if (x >= 0xc0) {
+                // 0xc0...0xff: integers 0-16383
+                if (buf.length >= 2) {
+                    v = ((x - 0xc0) << 8) + buf[1];
+                    consume(2);
+                }
+            } else if (x >= 0x80) {
+                // 0x80...0xbf: integers 0-63
+                v = x - 0x80;
+                consume(1);
+            } else if (x >= 0x60) {
+                // 0x60...0x7f: strings with length 0-31
+                len = x - 0x60;
+                if (buf.length >= 1 + len) {
+                    v = new Buffer(len);
+                    buf.copy(v, 0, 1, 1 + len);
+                    v = bufferToDebugString(v);
+                    consume(1 + len);
+                }
+            } else {
+                switch (x) {
+                case 0x00: v = DVAL_EOM; consume(1); break;
+                case 0x01: v = DVAL_REQ; consume(1); break;
+                case 0x02: v = DVAL_REP; consume(1); break;
+                case 0x03: v = DVAL_ERR; consume(1); break;
+                case 0x04: v = DVAL_NFY; consume(1); break;
+                case 0x10:  // 4-byte signed integer
+                    if (buf.length >= 5) {
+                        v = buf.readInt32BE(1);
+                        consume(5);
+                    }
+                    break;
+                case 0x11:  // 4-byte string
+                    if (buf.length >= 5) {
+                        len = buf.readUInt32BE(1);
+                        if (buf.length >= 5 + len) {
+                            v = new Buffer(len);
+                            buf.copy(v, 0, 5, 5 + len);
+                            v = bufferToDebugString(v);
+                            consume(5 + len);
+                        }
+                    }
+                    break;
+                case 0x12:  // 2-byte string
+                    if (buf.length >= 3) {
+                        len = buf.readUInt16BE(1);
+                        if (buf.length >= 3 + len) {
+                            v = new Buffer(len);
+                            buf.copy(v, 0, 3, 3 + len);
+                            v = bufferToDebugString(v);
+                            consume(3 + len);
+                        }
+                    }
+                    break;
+                case 0x13:  // 4-byte buffer
+                    if (buf.length >= 5) {
+                        len = buf.readUInt32BE(1);
+                        if (buf.length >= 5 + len) {
+                            v = new Buffer(len);
+                            buf.copy(v, 0, 5, 5 + len);
+                            v = { type: 'buffer', data: v.toString('hex') };
+                            consume(5 + len);
+                            // Value could be a Node.js buffer directly, but
+                            // we prefer all dvalues to be JSON compatible
+                        }
+                    }
+                    break;
+                case 0x14:  // 2-byte buffer
+                    if (buf.length >= 3) {
+                        len = buf.readUInt16BE(1);
+                        if (buf.length >= 3 + len) {
+                            v = new Buffer(len);
+                            buf.copy(v, 0, 3, 3 + len);
+                            v = { type: 'buffer', data: v.toString('hex') };
+                            consume(3 + len);
+                            // Value could be a Node.js buffer directly, but
+                            // we prefer all dvalues to be JSON compatible
+                        }
+                    }
+                    break;
+                case 0x15:  // unused/none
+                    v = { type: 'unused' };
+                    consume(1);
+                    break;
+                case 0x16:  // undefined
+                    v = { type: 'undefined' };
+                    gotValue = true;  // indicate 'v' is actually set
+                    consume(1);
+                    break;
+                case 0x17:  // null
+                    v = null;
+                    gotValue = true;  // indicate 'v' is actually set
+                    consume(1);
+                    break;
+                case 0x18:  // true
+                    v = true;
+                    consume(1);
+                    break;
+                case 0x19:  // false
+                    v = false;
+                    consume(1);
+                    break;
+                case 0x1a:  // number (IEEE double), big endian
+                    if (buf.length >= 9) {
+                        v = new Buffer(8);
+                        buf.copy(v, 0, 1, 9);
+                        v = { type: 'number', data: v.toString('hex') };
+
+                        if (_this.readableNumberValue) {
+                            // The value key should not be used programmatically,
+                            // it is just there to make the dumps more readable.
+                            v.value = buf.readDoubleBE(1);
+                        }
+                        consume(9);
+                    }
+                    break;
+                case 0x1b:  // object
+                    if (buf.length >= 3) {
+                        len = buf[2];
+                        if (buf.length >= 3 + len) {
+                            v = new Buffer(len);
+                            buf.copy(v, 0, 3, 3 + len);
+                            v = { type: 'object', 'class': buf[1], pointer: v.toString('hex') };
+                            consume(3 + len);
+                        }
+                    }
+                    break;
+                case 0x1c:  // pointer
+                    if (buf.length >= 2) {
+                        len = buf[1];
+                        if (buf.length >= 2 + len) {
+                            v = new Buffer(len);
+                            buf.copy(v, 0, 2, 2 + len);
+                            v = { type: 'pointer', pointer: v.toString('hex') };
+                            consume(2 + len);
+                        }
+                    }
+                    break;
+                case 0x1d:  // lightfunc
+                    if (buf.length >= 4) {
+                        len = buf[3];
+                        if (buf.length >= 4 + len) {
+                            v = new Buffer(len);
+                            buf.copy(v, 0, 4, 4 + len);
+                            v = { type: 'lightfunc', flags: buf.readUInt16BE(1), pointer: v.toString('hex') };
+                            consume(4 + len);
+                        }
+                    }
+                    break;
+                case 0x1e:  // heapptr
+                    if (buf.length >= 2) {
+                        len = buf[1];
+                        if (buf.length >= 2 + len) {
+                            v = new Buffer(len);
+                            buf.copy(v, 0, 2, 2 + len);
+                            v = { type: 'heapptr', pointer: v.toString('hex') };
+                            consume(2 + len);
+                        }
+                    }
+                    break;
+                default:
+                    _this.emit('transport-error', 'Parse error, dropping connection');
+                    _this.close();
+                }
+            }
+
+            if (typeof v === 'undefined' && !gotValue) {
+                break;
+            }
+            msg.push(v);
+            _this.dvalues++;
+
+            // Could emit a 'debug-value' event here, but that's not necessary
+            // because the receiver will just collect statistics which can also
+            // be done using the finished message.
+
+            if (v === DVAL_EOM) {
+                _this.messages++;
+
+                if (textDumpFileName || textDumpConsolePrefix) {
+                    prettyMsg = prettyDebugMessage(msg);
+                    if (textDumpFileName) {
+                        fs.appendFileSync(textDumpFileName, (textDumpFilePrefix || '') + prettyMsg + '\n');
+                    }
+                    if (textDumpConsolePrefix) {
+                        console.log(textDumpConsolePrefix + prettyMsg);
+                    }
+                }
+
+                _this.emit('debug-message', msg);
+                msg = [];  // new object, old may be in circulation for a while
+            }
+        }
+    });
+
+    // Not all streams will emit this.
+    inputStream.on('error', function (err) {
+        _this.emit('transport-error', err);
+        _this.close();
+    });
+
+    // Not all streams will emit this.
+    inputStream.on('close', function () {
+        _this.close();
+    });
+}
+DebugProtocolParser.prototype = Object.create(events.EventEmitter.prototype);
+
+DebugProtocolParser.prototype.close = function () {
+    // Although the underlying transport may not have a close() or destroy()
+    // method or even a 'close' event, this method is always available and
+    // will generate a 'transport-close'.
+    //
+    // The caller is responsible for closing the underlying stream if that
+    // is necessary.
+
+    if (this.closed) { return; }
+
+    this.closed = true;
+    if (this.statsTimer) {
+        clearInterval(this.statsTimer);
+        this.statsTimer = null;
+    }
+    this.emit('transport-close');
+};
+
+/*
+ *  Debugger output formatting
+ */
+
+function formatDebugValue(v) {
+    var buf, dec, len;
+
+    // See doc/debugger.rst for format description.
+
+    if (typeof v === 'object' && v !== null) {
+        // Note: typeof null === 'object', so null special case explicitly
+        if (v.type === 'eom') {
+            return new Buffer([ 0x00 ]);
+        } else if (v.type === 'req') {
+            return new Buffer([ 0x01 ]);
+        } else if (v.type === 'rep') {
+            return new Buffer([ 0x02 ]);
+        } else if (v.type === 'err') {
+            return new Buffer([ 0x03 ]);
+        } else if (v.type === 'nfy') {
+            return new Buffer([ 0x04 ]);
+        } else if (v.type === 'unused') {
+            return new Buffer([ 0x15 ]);
+        } else if (v.type === 'undefined') {
+            return new Buffer([ 0x16 ]);
+        } else if (v.type === 'number') {
+            dec = new Buffer(v.data, 'hex');
+            len = dec.length;
+            if (len !== 8) {
+                throw new TypeError('value cannot be converted to dvalue: ' + JSON.stringify(v));
+            }
+            buf = new Buffer(1 + len);
+            buf[0] = 0x1a;
+            dec.copy(buf, 1);
+            return buf;
+        } else if (v.type === 'buffer') {
+            dec = new Buffer(v.data, 'hex');
+            len = dec.length;
+            if (len <= 0xffff) {
+                buf = new Buffer(3 + len);
+                buf[0] = 0x14;
+                buf[1] = (len >> 8) & 0xff;
+                buf[2] = (len >> 0) & 0xff;
+                dec.copy(buf, 3);
+                return buf;
+            } else {
+                buf = new Buffer(5 + len);
+                buf[0] = 0x13;
+                buf[1] = (len >> 24) & 0xff;
+                buf[2] = (len >> 16) & 0xff;
+                buf[3] = (len >> 8) & 0xff;
+                buf[4] = (len >> 0) & 0xff;
+                dec.copy(buf, 5);
+                return buf;
+            }
+        } else if (v.type === 'object') {
+            dec = new Buffer(v.pointer, 'hex');
+            len = dec.length;
+            buf = new Buffer(3 + len);
+            buf[0] = 0x1b;
+            buf[1] = v.class;
+            buf[2] = len;
+            dec.copy(buf, 3);
+            return buf;
+        } else if (v.type === 'pointer') {
+            dec = new Buffer(v.pointer, 'hex');
+            len = dec.length;
+            buf = new Buffer(2 + len);
+            buf[0] = 0x1c;
+            buf[1] = len;
+            dec.copy(buf, 2);
+            return buf;
+        } else if (v.type === 'lightfunc') {
+            dec = new Buffer(v.pointer, 'hex');
+            len = dec.length;
+            buf = new Buffer(4 + len);
+            buf[0] = 0x1d;
+            buf[1] = (v.flags >> 8) & 0xff;
+            buf[2] = v.flags & 0xff;
+            buf[3] = len;
+            dec.copy(buf, 4);
+            return buf;
+        } else if (v.type === 'heapptr') {
+            dec = new Buffer(v.pointer, 'hex');
+            len = dec.length;
+            buf = new Buffer(2 + len);
+            buf[0] = 0x1e;
+            buf[1] = len;
+            dec.copy(buf, 2);
+            return buf;
+        }
+    } else if (v === null) {
+        return new Buffer([ 0x17 ]);
+    } else if (typeof v === 'boolean') {
+        return new Buffer([ v ? 0x18 : 0x19 ]);
+    } else if (typeof v === 'number') {
+        if (Math.floor(v) === v &&     /* whole */
+            (v !== 0 || 1 / v > 0) &&  /* not negative zero */
+            v >= -0x80000000 && v <= 0x7fffffff) {
+            // Represented signed 32-bit integers as plain integers.
+            // Debugger code expects this for all fields that are not
+            // duk_tval representations (e.g. command numbers and such).
+            if (v >= 0x00 && v <= 0x3f) {
+                return new Buffer([ 0x80 + v ]);
+            } else if (v >= 0x0000 && v <= 0x3fff) {
+                return new Buffer([ 0xc0 + (v >> 8), v & 0xff ]);
+            } else if (v >= -0x80000000 && v <= 0x7fffffff) {
+                return new Buffer([ 0x10,
+                                    (v >> 24) & 0xff,
+                                    (v >> 16) & 0xff,
+                                    (v >> 8) & 0xff,
+                                    (v >> 0) & 0xff ]);
+            } else {
+                throw new Error('internal error when encoding integer to dvalue: ' + v);
+            }
+        } else {
+            // Represent non-integers as IEEE double dvalues
+            buf = new Buffer(1 + 8);
+            buf[0] = 0x1a;
+            buf.writeDoubleBE(v, 1);
+            return buf;
+        }
+    } else if (typeof v === 'string') {
+        if (v.length < 0 || v.length > 0xffffffff) {
+            // Not possible in practice.
+            throw new TypeError('cannot convert to dvalue, invalid string length: ' + v.length);
+        }
+        if (v.length <= 0x1f) {
+            buf = new Buffer(1 + v.length);
+            buf[0] = 0x60 + v.length;
+            writeDebugStringToBuffer(v, buf, 1);
+            return buf;
+        } else if (v.length <= 0xffff) {
+            buf = new Buffer(3 + v.length);
+            buf[0] = 0x12;
+            buf[1] = (v.length >> 8) & 0xff;
+            buf[2] = (v.length >> 0) & 0xff;
+            writeDebugStringToBuffer(v, buf, 3);
+            return buf;
+        } else {
+            buf = new Buffer(5 + v.length);
+            buf[0] = 0x11;
+            buf[1] = (v.length >> 24) & 0xff;
+            buf[2] = (v.length >> 16) & 0xff;
+            buf[3] = (v.length >> 8) & 0xff;
+            buf[4] = (v.length >> 0) & 0xff;
+            writeDebugStringToBuffer(v, buf, 5);
+            return buf;
+        }
+    }
+
+    // Shouldn't come here.
+    throw new TypeError('value cannot be converted to dvalue: ' + JSON.stringify(v));
+}
+
+/*
+ *  Debugger implementation
+ *
+ *  A debugger instance communicates with the debug target and maintains
+ *  persistent debug state so that the current state can be resent to the
+ *  socket.io client (web UI) if it reconnects.  Whenever the debugger state
+ *  is changed an event is generated.  The socket.io handler will listen to
+ *  state change events and push the necessary updates to the web UI, often
+ *  in a rate limited fashion or using a client pull to ensure the web UI
+ *  is not overloaded.
+ *
+ *  The debugger instance assumes that if the debug protocol connection is
+ *  re-established, it is always to the same target.  There is no separate
+ *  abstraction for a debugger session.
+ */
+
+function Debugger() {
+    events.EventEmitter.call(this);
+
+    this.web = null;                      // web UI singleton
+    this.targetStream = null;             // transport connection to target
+    this.outputPassThroughStream = null;  // dummy passthrough for message dumping
+    this.inputParser = null;              // parser for incoming debug messages
+    this.outputParser = null;             // parser for outgoing debug messages (stats, dumping)
+    this.protocolVersion = null;
+    this.dukVersion = null;
+    this.dukGitDescribe = null;
+    this.targetInfo = null;
+    this.attached = false;
+    this.handshook = false;
+    this.reqQueue = null;
+    this.stats = {                        // stats for current debug connection
+        rxBytes: 0, rxDvalues: 0, rxMessages: 0, rxBytesPerSec: 0,
+        txBytes: 0, txDvalues: 0, txMessages: 0, txBytesPerSec: 0
+    };
+    this.execStatus = {
+        attached: false,
+        state: 'detached',
+        fileName: '',
+        funcName: '',
+        line: 0,
+        pc: 0
+    };
+    this.breakpoints = [];
+    this.callstack = [];
+    this.locals = [];
+    this.messageLines = [];
+    this.messageScrollBack = 100;
+}
+Debugger.prototype = events.EventEmitter.prototype;
+
+Debugger.prototype.decodeBytecodeFromBuffer = function (buf, consts, funcs) {
+    var i, j, n, m, ins, pc;
+    var res = [];
+    var op, str, args, comments;
+
+    // XXX: add constants inline to preformatted output (e.g. for strings,
+    // add a short escaped snippet as a comment on the line after the
+    // compact argument list).
+
+    for (i = 0, n = buf.length; i < n; i += 4) {
+        pc = i / 4;
+
+        // shift forces unsigned
+        if (this.endianness === 'little') {
+            ins = buf.readInt32LE(i) >>> 0;
+        } else {
+            ins = buf.readInt32BE(i) >>> 0;
+        }
+
+        op = dukOpcodes.opcodes[ins & 0x3f];
+        if (op.extra) {
+            op = dukOpcodes.extra[(ins >> 6) & 0xff];
+        }
+
+        args = [];
+        comments = [];
+        if (op.args) {
+            for (j = 0, m = op.args.length; j < m; j++) {
+                switch (op.args[j]) {
+                case 'A_R':   args.push('r' + ((ins >>> 6) & 0xff)); break;
+                case 'A_RI':  args.push('r' + ((ins >>> 6) & 0xff) + '(indirect)'); break;
+                case 'A_C':   args.push('c' + ((ins >>> 6) & 0xff)); break;
+                case 'A_H':   args.push('0x' + ((ins >>> 6) & 0xff).toString(16)); break;
+                case 'A_I':   args.push(((ins >>> 6) & 0xff).toString(10)); break;
+                case 'A_B':   args.push(((ins >>> 6) & 0xff) ? 'true' : 'false'); break;
+                case 'B_RC':  args.push((ins & (1 << 22) ? 'c' : 'r') + ((ins >>> 14) & 0x0ff)); break;
+                case 'B_R':   args.push('r' + ((ins >>> 14) & 0x1ff)); break;
+                case 'B_RI':  args.push('r' + ((ins >>> 14) & 0x1ff) + '(indirect)'); break;
+                case 'B_C':   args.push('c' + ((ins >>> 14) & 0x1ff)); break;
+                case 'B_H':   args.push('0x' + ((ins >>> 14) & 0x1ff).toString(16)); break;
+                case 'B_I':   args.push(((ins >>> 14) & 0x1ff).toString(10)); break;
+                case 'C_RC':  args.push((ins & (1 << 31) ? 'c' : 'r') + ((ins >>> 23) & 0x0ff)); break;
+                case 'C_R':   args.push('r' + ((ins >>> 23) & 0x1ff)); break;
+                case 'C_RI':  args.push('r' + ((ins >>> 23) & 0x1ff) + '(indirect)'); break;
+                case 'C_C':   args.push('c' + ((ins >>> 23) & 0x1ff)); break;
+                case 'C_H':   args.push('0x' + ((ins >>> 23) & 0x1ff).toString(16)); break;
+                case 'C_I':   args.push(((ins >>> 23) & 0x1ff).toString(10)); break;
+                case 'BC_R':  args.push('r' + ((ins >>> 14) & 0x3ffff)); break;
+                case 'BC_C':  args.push('c' + ((ins >>> 14) & 0x3ffff)); break;
+                case 'BC_H':  args.push('0x' + ((ins >>> 14) & 0x3ffff).toString(16)); break;
+                case 'BC_I':  args.push(((ins >>> 14) & 0x3ffff).toString(10)); break;
+                case 'ABC_H': args.push(((ins >>> 6) & 0x03ffffff).toString(16)); break;
+                case 'ABC_I': args.push(((ins >>> 6) & 0x03ffffff).toString(10)); break;
+                case 'BC_LDINT': args.push(((ins >>> 14) & 0x3ffff) - (1 << 17)); break;
+                case 'BC_LDINTX': args.push(((ins >>> 14) & 0x3ffff) - 0); break;  // no bias in LDINTX
+                case 'ABC_JUMP': {
+                    var pc_add = ((ins >>> 6) & 0x03ffffff) - (1 << 25) + 1;  // pc is preincremented before adding
+                    var pc_dst = pc + pc_add;
+                    args.push(pc_dst + ' (' + (pc_add >= 0 ? '+' : '') + pc_add + ')');
+                    break;
+                }
+                default:      args.push('?'); break;
+                }
+            }
+        }
+        if (op.flags) {
+            for (j = 0, m = op.flags.length; j < m; j++) {
+                if (ins & op.flags[j].mask) {
+                    comments.push(op.flags[j].name);
+                }
+            }
+        }
+
+        if (args.length > 0) {
+            str = sprintf('%05d %08x   %-10s %s', pc, ins, op.name, args.join(', '));
+        } else {
+            str = sprintf('%05d %08x   %-10s', pc, ins, op.name);
+        }
+        if (comments.length > 0) {
+            str = sprintf('%-44s ; %s', str, comments.join(', '));
+        }
+
+        res.push({
+            str: str,
+            ins: ins
+        });
+    }
+
+    return res;
+};
+
+Debugger.prototype.uiMessage = function (type, val) {
+    var msg;
+    if (typeof type === 'object') {
+        msg = type;
+    } else if (typeof type === 'string') {
+        msg = { type: type, message: val };
+    } else {
+        throw new TypeError('invalid ui message: ' + type);
+    }
+    this.messageLines.push(msg);
+    while (this.messageLines.length > this.messageScrollBack) {
+        this.messageLines.shift();
+    }
+    this.emit('ui-message-update');  // just trigger a sync, gets rate limited
+};
+
+Debugger.prototype.sendRequest = function (msg) {
+    var _this = this;
+    return new Promise(function (resolve, reject) {
+        var dvals = [];
+        var dval;
+        var data;
+        var i;
+
+        if (!_this.attached || !_this.handshook || !_this.reqQueue || !_this.targetStream) {
+            throw new Error('invalid state for sendRequest');
+        }
+
+        for (i = 0; i < msg.length; i++) {
+            try {
+                dval = formatDebugValue(msg[i]);
+            } catch (e) {
+                console.log('Failed to format dvalue, dropping connection: ' + e);
+                console.log(e.stack || e);
+                _this.targetStream.destroy();
+                throw new Error('failed to format dvalue');
+            }
+            dvals.push(dval);
+        }
+
+        data = Buffer.concat(dvals);
+
+        _this.targetStream.write(data);
+        _this.outputPassThroughStream.write(data);  // stats and dumping
+
+        if (optLogMessages) {
+            console.log('Request ' + prettyDebugCommand(msg[1]) + ': ' + prettyDebugMessage(msg));
+        }
+
+        if (!_this.reqQueue) {
+            throw new Error('no reqQueue');
+        }
+
+        _this.reqQueue.push({
+            reqMsg: msg,
+            reqCmd: msg[1],
+            resolveCb: resolve,
+            rejectCb: reject
+        });
+    });
+};
+
+Debugger.prototype.sendBasicInfoRequest = function () {
+    var _this = this;
+    return this.sendRequest([ DVAL_REQ, CMD_BASICINFO, DVAL_EOM ]).then(function (msg) {
+        _this.dukVersion = msg[1];
+        _this.dukGitDescribe = msg[2];
+        _this.targetInfo = msg[3];
+        _this.endianness = { 1: 'little', 2: 'mixed', 3: 'big' }[msg[4]] || 'unknown';
+        _this.emit('basic-info-update');
+        return msg;
+    });
+};
+
+Debugger.prototype.sendGetVarRequest = function (varname, level) {
+    var _this = this;
+    return this.sendRequest([ DVAL_REQ, CMD_GETVAR, varname, (typeof level === 'number' ? level : -1), DVAL_EOM ]).then(function (msg) {
+        return { found: msg[1] === 1, value: msg[2] };
+    });
+};
+
+Debugger.prototype.sendPutVarRequest = function (varname, varvalue, level) {
+    var _this = this;
+    return this.sendRequest([ DVAL_REQ, CMD_PUTVAR, varname, varvalue, (typeof level === 'number' ? level : -1), DVAL_EOM ]);
+};
+
+Debugger.prototype.sendInvalidCommandTestRequest = function () {
+    // Intentional invalid command
+    var _this = this;
+    return this.sendRequest([ DVAL_REQ, 0xdeadbeef, DVAL_EOM ]);
+};
+
+Debugger.prototype.sendStatusRequest = function () {
+    // Send a status request to trigger a status notify, result is ignored:
+    // target sends a status notify instead of a meaningful reply
+    var _this = this;
+    return this.sendRequest([ DVAL_REQ, CMD_TRIGGERSTATUS, DVAL_EOM ]);
+};
+
+Debugger.prototype.sendBreakpointListRequest = function () {
+    var _this = this;
+    return this.sendRequest([ DVAL_REQ, CMD_LISTBREAK, DVAL_EOM ]).then(function (msg) {
+        var i, n;
+        var breakpts = [];
+
+        for (i = 1, n = msg.length - 1; i < n; i += 2) {
+            breakpts.push({ fileName: msg[i], lineNumber: msg[i + 1] });
+        }
+
+        _this.breakpoints = breakpts;
+        _this.emit('breakpoints-update');
+        return msg;
+    });
+};
+
+Debugger.prototype.sendGetLocalsRequest = function (level) {
+    var _this = this;
+    return this.sendRequest([ DVAL_REQ, CMD_GETLOCALS, (typeof level === 'number' ? level : -1), DVAL_EOM ]).then(function (msg) {
+        var i;
+        var locals = [];
+
+        for (i = 1; i <= msg.length - 2; i += 2) {
+            // XXX: do pretty printing in debug client for now
+            locals.push({ key: msg[i], value: prettyUiDebugValue(msg[i + 1], LOCALS_CLIPLEN) });
+        }
+
+        _this.locals = locals;
+        _this.emit('locals-update');
+        return msg;
+    });
+};
+
+Debugger.prototype.sendGetCallStackRequest = function () {
+    var _this = this;
+    return this.sendRequest([ DVAL_REQ, CMD_GETCALLSTACK, DVAL_EOM ]).then(function (msg) {
+        var i;
+        var stack = [];
+
+        for (i = 1; i + 3 <= msg.length - 1; i += 4) {
+            stack.push({
+                fileName: msg[i],
+                funcName: msg[i + 1],
+                lineNumber: msg[i + 2],
+                pc: msg[i + 3]
+            });
+        }
+
+        _this.callstack = stack;
+        _this.emit('callstack-update');
+        return msg;
+    });
+};
+
+Debugger.prototype.sendStepIntoRequest = function () {
+    var _this = this;
+    return this.sendRequest([ DVAL_REQ, CMD_STEPINTO, DVAL_EOM ]);
+};
+
+Debugger.prototype.sendStepOverRequest = function () {
+    var _this = this;
+    return this.sendRequest([ DVAL_REQ, CMD_STEPOVER, DVAL_EOM ]);
+};
+
+Debugger.prototype.sendStepOutRequest = function () {
+    var _this = this;
+    return this.sendRequest([ DVAL_REQ, CMD_STEPOUT, DVAL_EOM ]);
+};
+
+Debugger.prototype.sendPauseRequest = function () {
+    var _this = this;
+    return this.sendRequest([ DVAL_REQ, CMD_PAUSE, DVAL_EOM ]);
+};
+
+Debugger.prototype.sendResumeRequest = function () {
+    var _this = this;
+    return this.sendRequest([ DVAL_REQ, CMD_RESUME, DVAL_EOM ]);
+};
+
+Debugger.prototype.sendEvalRequest = function (evalInput, level) {
+    var _this = this;
+    return this.sendRequest([ DVAL_REQ, CMD_EVAL, evalInput, (typeof level === 'number' ? level : -1), DVAL_EOM ]).then(function (msg) {
+        return { error: msg[1] === 1 /*error*/, value: msg[2] };
+    });
+};
+
+Debugger.prototype.sendDetachRequest = function () {
+    var _this = this;
+    return this.sendRequest([ DVAL_REQ, CMD_DETACH, DVAL_EOM ]);
+};
+
+Debugger.prototype.sendDumpHeapRequest = function () {
+    var _this = this;
+
+    return this.sendRequest([ DVAL_REQ, CMD_DUMPHEAP, DVAL_EOM ]).then(function (msg) {
+        var res = {};
+        var objs = [];
+        var i, j, n, m, o, prop;
+
+        res.type = 'heapDump';
+        res.heapObjects = objs;
+
+        for (i = 1, n = msg.length - 1; i < n; /*nop*/) {
+            o = {};
+            o.ptr = msg[i++];
+            o.type = msg[i++];
+            o.flags = msg[i++] >>> 0;  /* unsigned */
+            o.refc = msg[i++];
+
+            if (o.type === DUK_HTYPE_STRING) {
+                o.blen = msg[i++];
+                o.clen = msg[i++];
+                o.hash = msg[i++] >>> 0;  /* unsigned */
+                o.data = msg[i++];
+            } else if (o.type === DUK_HTYPE_BUFFER) {
+                o.len = msg[i++];
+                o.data = msg[i++];
+            } else if (o.type === DUK_HTYPE_OBJECT) {
+                o['class'] = msg[i++];
+                o.proto = msg[i++];
+                o.esize = msg[i++];
+                o.enext = msg[i++];
+                o.asize = msg[i++];
+                o.hsize = msg[i++];
+                o.props = [];
+                for (j = 0, m = o.enext; j < m; j++) {
+                    prop = {};
+                    prop.flags = msg[i++];
+                    prop.key = msg[i++];
+                    prop.accessor = (msg[i++] == 1);
+                    if (prop.accessor) {
+                        prop.getter = msg[i++];
+                        prop.setter = msg[i++];
+                    } else {
+                        prop.value = msg[i++];
+                    }
+                    o.props.push(prop);
+                }
+                o.array = [];
+                for (j = 0, m = o.asize; j < m; j++) {
+                    prop = {};
+                    prop.value = msg[i++];
+                    o.array.push(prop);
+                }
+            } else {
+                console.log('invalid htype: ' + o.type + ', disconnect');
+                _this.disconnectDebugger();
+                throw new Error('invalid htype');
+                return;
+            }
+
+            objs.push(o);
+        }
+
+        return res;
+    });
+};
+
+Debugger.prototype.sendGetBytecodeRequest = function () {
+    var _this = this;
+
+    return this.sendRequest([ DVAL_REQ, CMD_GETBYTECODE, DVAL_EOM ]).then(function (msg) {
+        var idx = 1;
+        var nconst;
+        var nfunc;
+        var val;
+        var buf;
+        var i, n;
+        var consts = [];
+        var funcs = [];
+        var bcode;
+        var preformatted;
+        var ret;
+        var idxPreformattedInstructions;
+
+        //console.log(JSON.stringify(msg));
+
+        nconst = msg[idx++];
+        for (i = 0; i < nconst; i++) {
+            val = msg[idx++];
+            consts.push(val);
+        }
+
+        nfunc = msg[idx++];
+        for (i = 0; i < nfunc; i++) {
+            val = msg[idx++];
+            funcs.push(val);
+        }
+        val = msg[idx++];
+
+        // Right now bytecode is a string containing a direct dump of the
+        // bytecode in target endianness.  Decode here so that the web UI
+        // doesn't need to.
+
+        buf = new Buffer(val.length);
+        writeDebugStringToBuffer(val, buf, 0);
+        bcode = _this.decodeBytecodeFromBuffer(buf, consts, funcs);
+
+        preformatted = [];
+        consts.forEach(function (v, i) {
+            preformatted.push('; c' + i + ' ' + JSON.stringify(v));
+        });
+        preformatted.push('');
+        idxPreformattedInstructions = preformatted.length;
+        bcode.forEach(function (v) {
+            preformatted.push(v.str);
+        });
+        preformatted = preformatted.join('\n') + '\n';
+
+        ret = {
+            constants: consts,
+            functions: funcs,
+            bytecode: bcode,
+            preformatted: preformatted,
+            idxPreformattedInstructions: idxPreformattedInstructions
+        };
+
+        return ret;
+    });
+};
+
+Debugger.prototype.changeBreakpoint = function (fileName, lineNumber, mode) {
+    var _this = this;
+
+    return this.sendRequest([ DVAL_REQ, CMD_LISTBREAK, DVAL_EOM ]).then(function (msg) {
+        var i, n;
+        var breakpts = [];
+        var deleted = false;
+
+        // Up-to-date list of breakpoints on target
+        for (i = 1, n = msg.length - 1; i < n; i += 2) {
+            breakpts.push({ fileName: msg[i], lineNumber: msg[i + 1] });
+        }
+
+        // Delete matching breakpoints in reverse order so that indices
+        // remain valid.  We do this for all operations so that duplicates
+        // are eliminated if present.
+        for (i = breakpts.length - 1; i >= 0; i--) {
+            var bp = breakpts[i];
+            if (mode === 'deleteall' || (bp.fileName === fileName && bp.lineNumber === lineNumber)) {
+                deleted = true;
+                _this.sendRequest([ DVAL_REQ, CMD_DELBREAK, i, DVAL_EOM ], function (msg) {
+                    // nop
+                }, function (err) {
+                    // nop
+                });
+            }
+        }
+
+        // Technically we should wait for each delbreak reply but because
+        // target processes the requests in order, it doesn't matter.
+        if ((mode === 'add') || (mode === 'toggle' && !deleted)) {
+            _this.sendRequest([ DVAL_REQ, CMD_ADDBREAK, fileName, lineNumber, DVAL_EOM ], function (msg) {
+                // nop
+            }, function (err) {
+                _this.uiMessage('debugger-info', 'Failed to add breakpoint: ' + err);
+            });
+        }
+
+        // Read final, effective breakpoints from the target
+        _this.sendBreakpointListRequest();
+    });
+};
+
+Debugger.prototype.disconnectDebugger = function () {
+    if (this.targetStream) {
+        // We require a destroy() method from the actual target stream
+        this.targetStream.destroy();
+        this.targetStream = null;
+    }
+    if (this.inputParser) {
+        this.inputParser.close();
+        this.inputParser = null;
+    }
+    if (this.outputPassThroughStream) {
+        // There is no close() or destroy() for a passthrough stream, so just
+        // close the outputParser which will cancel timers etc.
+    }
+    if (this.outputParser) {
+        this.outputParser.close();
+        this.outputParser = null;
+    }
+
+    this.attached = false;
+    this.handshook = false;
+    this.reqQueue = null;
+    this.execStatus = {
+        attached: false,
+        state: 'detached',
+        fileName: '',
+        funcName: '',
+        line: 0,
+        pc: 0
+    };
+};
+
+Debugger.prototype.connectDebugger = function () {
+    var _this = this;
+
+    this.disconnectDebugger();  // close previous target connection
+
+    // CUSTOMTRANSPORT: to use a custom transport, change this.targetStream to
+    // use your custom transport.
+
+    console.log('Connecting to ' + optTargetHost + ':' + optTargetPort + '...');
+    this.targetStream = new net.Socket();
+    this.targetStream.connect(optTargetPort, optTargetHost, function () {
+        console.log('Debug transport connected');
+        _this.attached = true;
+        _this.reqQueue = [];
+        _this.uiMessage('debugger-info', 'Debug transport connected');
+    });
+
+    this.inputParser = new DebugProtocolParser(
+        this.targetStream,
+        null,
+        optDumpDebugRead,
+        optDumpDebugPretty,
+        optDumpDebugPretty ? 'Recv: ' : null,
+        null,
+        null   // console logging is done at a higher level to match request/response
+    );
+
+    // Use a PassThrough stream to debug dump and get stats for output messages.
+    // Simply write outgoing data to both the targetStream and this passthrough
+    // separately.
+    this.outputPassThroughStream = stream.PassThrough();
+    this.outputParser = new DebugProtocolParser(
+        this.outputPassThroughStream,
+        1,
+        optDumpDebugWrite,
+        optDumpDebugPretty,
+        optDumpDebugPretty ? 'Send: ' : null,
+        null,
+        null   // console logging is done at a higher level to match request/response
+    );
+
+    this.inputParser.on('transport-close', function () {
+        _this.uiMessage('debugger-info', 'Debug transport closed');
+        _this.disconnectDebugger();
+        _this.emit('exec-status-update');
+        _this.emit('detached');
+    });
+
+    this.inputParser.on('transport-error', function (err) {
+        _this.uiMessage('debugger-info', 'Debug transport error: ' + err);
+        _this.disconnectDebugger();
+    });
+
+    this.inputParser.on('protocol-version', function (msg) {
+        var ver = msg.protocolVersion;
+        console.log('Debug version identification:', msg.versionIdentification);
+        _this.protocolVersion = ver;
+        _this.uiMessage('debugger-info', 'Debug version identification: ' + msg.versionIdentification);
+        if (ver !== 1) {
+            _this.uiMessage('debugger-info', 'Protocol version ' + ver + ' unsupported, dropping connection');
+            _this.targetStream.destroy();
+        } else {
+            _this.uiMessage('debugger-info', 'Debug protocol version: ' + ver);
+            _this.handshook = true;
+            _this.execStatus = {
+                attached: true,
+                state: 'attached',
+                fileName: '',
+                funcName: '',
+                line: 0,
+                pc: 0
+            };
+            _this.emit('exec-status-update');
+            _this.emit('attached');  // inform web UI
+
+            // Fetch basic info right away
+            _this.sendBasicInfoRequest();
+        }
+    });
+
+    this.inputParser.on('debug-message', function (msg) {
+        _this.processDebugMessage(msg);
+    });
+
+    this.inputParser.on('stats-update', function () {
+        _this.stats.rxBytes = this.bytes;
+        _this.stats.rxDvalues = this.dvalues;
+        _this.stats.rxMessages = this.messages;
+        _this.stats.rxBytesPerSec = this.bytesPerSec;
+        _this.emit('debug-stats-update');
+    });
+
+    this.outputParser.on('stats-update', function () {
+        _this.stats.txBytes = this.bytes;
+        _this.stats.txDvalues = this.dvalues;
+        _this.stats.txMessages = this.messages;
+        _this.stats.txBytesPerSec = this.bytesPerSec;
+        _this.emit('debug-stats-update');
+    });
+};
+
+Debugger.prototype.processDebugMessage = function (msg) {
+    var req;
+    var prevState, newState;
+    var err;
+
+    if (msg[0] === DVAL_REQ) {
+        // No actual requests sent by the target right now (just notifys).
+        console.log('Unsolicited reply message, dropping connection: ' + prettyDebugMessage(msg));
+    } else if (msg[0] === DVAL_REP) {
+        if (this.reqQueue.length <= 0) {
+            console.log('Unsolicited reply message, dropping connection: ' + prettyDebugMessage(msg));
+            this.targetStream.destroy();
+        }
+        req = this.reqQueue.shift();
+
+        if (optLogMessages) {
+            console.log('Reply for ' + prettyDebugCommand(req.reqCmd) + ': ' + prettyDebugMessage(msg));
+        }
+
+        if (req.resolveCb) {
+            req.resolveCb(msg);
+        } else {
+            // nop: no callback
+        }
+    } else if (msg[0] === DVAL_ERR) {
+        if (this.reqQueue.length <= 0) {
+            console.log('Unsolicited error message, dropping connection: ' + prettyDebugMessage(msg));
+            this.targetStream.destroy();
+        }
+        err = new Error(String(msg[2]) + ' (code ' + String(msg[1]) + ')');
+        err.errorCode = msg[1] || 0;
+        req = this.reqQueue.shift();
+
+        if (optLogMessages) {
+            console.log('Error for ' + prettyDebugCommand(req.reqCmd) + ': ' + prettyDebugMessage(msg));
+        }
+
+        if (req.rejectCb) {
+            req.rejectCb(err);
+        } else {
+            // nop: no callback
+        }
+    } else if (msg[0] === DVAL_NFY) {
+        if (optLogMessages) {
+            console.log('Notify ' + prettyDebugCommand(msg[1]) + ': ' + prettyDebugMessage(msg));
+        }
+
+        if (msg[1] === CMD_STATUS) {
+            prevState = this.execStatus.state;
+            newState = msg[2] === 0 ? 'running' : 'paused';
+            this.execStatus = {
+                attached: true,
+                state: newState,
+                fileName: msg[3],
+                funcName: msg[4],
+                line: msg[5],
+                pc: msg[6]
+            };
+
+            if (prevState !== newState && newState === 'paused') {
+                // update run state now that we're paused
+                this.sendBreakpointListRequest();
+                this.sendGetLocalsRequest();
+                this.sendGetCallStackRequest();
+            }
+
+            this.emit('exec-status-update');
+        } else if (msg[1] === CMD_PRINT) {
+            this.uiMessage('print', prettyUiStringUnquoted(msg[2], UI_MESSAGE_CLIPLEN));
+        } else if (msg[1] === CMD_ALERT) {
+            this.uiMessage('alert', prettyUiStringUnquoted(msg[2], UI_MESSAGE_CLIPLEN));
+        } else if (msg[1] === CMD_LOG) {
+            this.uiMessage({ type: 'log', level: msg[2], message: prettyUiStringUnquoted(msg[3], UI_MESSAGE_CLIPLEN) });
+        } else if (msg[1] === CMD_THROW) {
+            this.uiMessage({ type: 'throw', fatal: msg[2], message: (msg[2] ? 'UNCAUGHT: ' : 'THROW: ') + prettyUiStringUnquoted(msg[3], UI_MESSAGE_CLIPLEN), fileName: msg[4], lineNumber: msg[5] });
+        } else if (msg[1] === CMD_DETACHING) {
+            this.uiMessage({ type: 'detaching', reason: msg[2], message: 'DETACH: ' + (msg.length >= 5 ? prettyUiStringUnquoted(msg[3]) : 'detaching') });
+        } else {
+            // Ignore unknown notify messages
+            console.log('Unknown notify, ignoring: ' + prettyDebugMessage(msg));
+
+            //this.targetStream.destroy();
+        }
+    } else {
+        console.log('Invalid initial dvalue, dropping connection: ' + prettyDebugMessage(msg));
+        this.targetStream.destroy();
+    }
+};
+
+Debugger.prototype.run = function () {
+    var _this = this;
+
+    // Initial debugger connection
+
+    this.connectDebugger();
+
+    // Poll various state items when running
+
+    var sendRound = 0;
+    var statusPending = false;
+    var bplistPending = false;
+    var localsPending = false;
+    var callStackPending = false;
+
+    setInterval(function () {
+        if (_this.execStatus.state !== 'running') {
+            return;
+        }
+
+        // Could also check for an empty request queue, but that's probably
+        // too strict?
+
+        // Pending flags are used to avoid requesting the same thing twice
+        // while a previous request is pending.  The flag-based approach is
+        // quite awkward.  Rework to use promises.
+
+        switch (sendRound) {
+        case 0:
+            if (!statusPending) {
+                statusPending = true;
+                _this.sendStatusRequest().finally(function () { statusPending = false; });
+            }
+            break;
+        case 1:
+            if (!bplistPending) {
+                bplistPending = true;
+                _this.sendBreakpointListRequest().finally(function () { bplistPending = false; });
+            }
+            break;
+        case 2:
+            if (!localsPending) {
+                localsPending = true;
+                _this.sendGetLocalsRequest().finally(function () { localsPending = false; });
+            }
+            break;
+        case 3:
+            if (!callStackPending) {
+                callStackPending = true;
+                _this.sendGetCallStackRequest().finally(function () { callStackPending = false; });
+            }
+            break;
+        }
+        sendRound = (sendRound + 1) % 4;
+    }, 500);
+};
+
+/*
+ *  Express setup and socket.io
+ */
+
+function DebugWebServer() {
+    this.dbg = null;       // debugger singleton
+    this.socket = null;    // current socket (or null)
+    this.keepaliveTimer = null;
+    this.uiMessageLimiter = null;
+    this.cachedJson = {};  // cache to avoid resending identical data
+    this.sourceFileManager = new SourceFileManager(optSourceSearchDirs);
+    this.sourceFileManager.scan();
+}
+
+DebugWebServer.prototype.handleSourcePost = function (req, res) {
+    var fileName = req.body && req.body.fileName;
+    var fileData;
+
+    console.log('Source request: ' + fileName);
+
+    if (typeof fileName !== 'string') {
+        res.status(500).send('invalid request');
+        return;
+    }
+    fileData = this.sourceFileManager.search(fileName, optSourceSearchDirs);
+    if (typeof fileData !== 'string') {
+        res.status(404).send('not found');
+        return;
+    }
+    res.status(200).send(fileData);  // UTF-8
+};
+
+DebugWebServer.prototype.handleSourceListPost = function (req, res) {
+    console.log('Source list request');
+
+    var files = this.sourceFileManager.getFiles();
+    res.header('Content-Type', 'application/json');
+    res.status(200).json(files);
+};
+
+DebugWebServer.prototype.handleHeapDumpGet = function (req, res) {
+    console.log('Heap dump get');
+
+    this.dbg.sendDumpHeapRequest().then(function (val) {
+        res.header('Content-Type', 'application/json');
+        //res.status(200).json(val);
+        res.status(200).send(JSON.stringify(val, null, 4));
+    }).catch(function (err) {
+        res.status(500).send('Failed to get heap dump: ' + (err.stack || err));
+    });
+};
+
+DebugWebServer.prototype.run = function () {
+    var _this = this;
+
+    var express = require('express');
+    var bodyParser = require('body-parser');
+    var app = express();
+    var http = require('http').Server(app);
+    var io = require('socket.io')(http);
+
+    app.use(bodyParser.json());
+    app.post('/source', this.handleSourcePost.bind(this));
+    app.post('/sourceList', this.handleSourceListPost.bind(this));
+    app.get('/heapDump.json', this.handleHeapDumpGet.bind(this));
+    app.use('/', express.static(__dirname + '/static'));
+
+    http.listen(optHttpPort, function () {
+        console.log('Listening on *:' + optHttpPort);
+    });
+
+    io.on('connection', this.handleNewSocketIoConnection.bind(this));
+
+    this.dbg.on('attached', function () {
+        console.log('Debugger attached');
+    });
+
+    this.dbg.on('detached', function () {
+        console.log('Debugger detached');
+    });
+
+    this.dbg.on('debug-stats-update', function () {
+        _this.debugStatsLimiter.trigger();
+    });
+
+    this.dbg.on('ui-message-update', function () {
+        // Explicit rate limiter because this is a source of a lot of traffic.
+        _this.uiMessageLimiter.trigger();
+    });
+
+    this.dbg.on('basic-info-update', function () {
+        _this.emitBasicInfo();
+    });
+
+    this.dbg.on('breakpoints-update', function () {
+        _this.emitBreakpoints();
+    });
+
+    this.dbg.on('exec-status-update', function () {
+        // Explicit rate limiter because this is a source of a lot of traffic.
+        _this.execStatusLimiter.trigger();
+    });
+
+    this.dbg.on('locals-update', function () {
+        _this.emitLocals();
+    });
+
+    this.dbg.on('callstack-update', function () {
+        _this.emitCallStack();
+    });
+
+    this.uiMessageLimiter = new RateLimited(10, 1000, this.uiMessageLimiterCallback.bind(this));
+    this.execStatusLimiter = new RateLimited(50, 500, this.execStatusLimiterCallback.bind(this));
+    this.debugStatsLimiter = new RateLimited(1, 2000, this.debugStatsLimiterCallback.bind(this));
+
+    this.keepaliveTimer = setInterval(this.emitKeepalive.bind(this), 30000);
+};
+
+DebugWebServer.prototype.handleNewSocketIoConnection = function (socket) {
+    var _this = this;
+
+    console.log('Socket.io connected');
+    if (this.socket) {
+        console.log('Closing previous socket.io socket');
+        this.socket.emit('replaced');
+    }
+    this.socket = socket;
+
+    this.emitKeepalive();
+
+    socket.on('disconnect', function () {
+        console.log('Socket.io disconnected');
+        if (_this.socket === socket) {
+             _this.socket = null;
+        }
+    });
+
+    socket.on('keepalive', function (msg) {
+        // nop
+    });
+
+    socket.on('attach', function (msg) {
+        if (_this.dbg.targetStream) {
+            console.log('Attach request when debugger already has a connection, ignoring');
+        } else {
+            _this.dbg.connectDebugger();
+        }
+    });
+
+    socket.on('detach', function (msg) {
+        // Try to detach cleanly, timeout if no response
+        Promise.any([
+            _this.dbg.sendDetachRequest(),
+            Promise.delay(3000)
+        ]).finally(function () {
+            _this.dbg.disconnectDebugger();
+        });
+    });
+
+    socket.on('stepinto', function (msg) {
+        _this.dbg.sendStepIntoRequest();
+    });
+
+    socket.on('stepover', function (msg) {
+        _this.dbg.sendStepOverRequest();
+    });
+
+    socket.on('stepout', function (msg) {
+        _this.dbg.sendStepOutRequest();
+    });
+
+    socket.on('pause', function (msg) {
+        _this.dbg.sendPauseRequest();
+    });
+
+    socket.on('resume', function (msg) {
+        _this.dbg.sendResumeRequest();
+    });
+
+    socket.on('eval', function (msg) {
+        // msg.input is a proper Unicode strings here, and needs to be
+        // converted into a protocol string (U+0000...U+00FF).
+        var input = stringToDebugString(msg.input);
+        _this.dbg.sendEvalRequest(input, msg.level).then(function (v) {
+            socket.emit('eval-result', { error: v.error, result: prettyUiDebugValue(v.value, EVAL_CLIPLEN) });
+        });
+
+        // An eval call quite possibly changes the local variables so always
+        // re-read locals afterwards.  We don't need to wait for Eval to
+        // complete here; the requests will pipeline automatically and be
+        // executed in order.
+
+        // XXX: move this to the web UI so that the UI can control what
+        // locals are listed (or perhaps show locals for all levels with
+        // an expandable tree view).
+        _this.dbg.sendGetLocalsRequest();
+    });
+
+    socket.on('getvar', function (msg) {
+        // msg.varname is a proper Unicode strings here, and needs to be
+        // converted into a protocol string (U+0000...U+00FF).
+        var varname = stringToDebugString(msg.varname);
+        _this.dbg.sendGetVarRequest(varname, msg.level)
+        .then(function (v) {
+            socket.emit('getvar-result', { found: v.found, result: prettyUiDebugValue(v.value, GETVAR_CLIPLEN) });
+        });
+    });
+
+    socket.on('putvar', function (msg) {
+        // msg.varname and msg.varvalue are proper Unicode strings here, they
+        // need to be converted into protocol strings (U+0000...U+00FF).
+        var varname = stringToDebugString(msg.varname);
+        var varvalue = msg.varvalue;
+
+        // varvalue is JSON parsed by the web UI for now, need special string
+        // encoding here.
+        if (typeof varvalue === 'string') {
+            varvalue = stringToDebugString(msg.varvalue);
+        }
+
+        _this.dbg.sendPutVarRequest(varname, varvalue, msg.level)
+        .then(function (v) {
+            console.log('putvar done');  // XXX: signal success to UI?
+        });
+
+        // A PutVar call quite possibly changes the local variables so always
+        // re-read locals afterwards.  We don't need to wait for PutVar to
+        // complete here; the requests will pipeline automatically and be
+        // executed in order.
+
+        // XXX: make the client do this?
+        _this.dbg.sendGetLocalsRequest();
+    });
+
+    socket.on('add-breakpoint', function (msg) {
+        _this.dbg.changeBreakpoint(msg.fileName, msg.lineNumber, 'add');
+    });
+
+    socket.on('delete-breakpoint', function (msg) {
+        _this.dbg.changeBreakpoint(msg.fileName, msg.lineNumber, 'delete');
+    });
+
+    socket.on('toggle-breakpoint', function (msg) {
+        _this.dbg.changeBreakpoint(msg.fileName, msg.lineNumber, 'toggle');
+    });
+
+    socket.on('delete-all-breakpoints', function (msg) {
+        _this.dbg.changeBreakpoint(null, null, 'deleteall');
+    });
+
+    socket.on('get-bytecode', function (msg) {
+        _this.dbg.sendGetBytecodeRequest().then(function (res) {
+            socket.emit('bytecode', res);
+        });
+    });
+
+    // Resend all debugger state for new client
+    this.cachedJson = {};  // clear client state cache
+    this.emitBasicInfo();
+    this.emitStats();
+    this.emitExecStatus();
+    this.emitUiMessages();
+    this.emitBreakpoints();
+    this.emitCallStack();
+    this.emitLocals();
+};
+
+// Check if 'msg' would encode to the same JSON which was previously sent
+// to the web client.  The caller then avoid resending unnecessary stuff.
+DebugWebServer.prototype.cachedJsonCheck = function (cacheKey, msg) {
+    var newJson = JSON.stringify(msg);
+    if (this.cachedJson[cacheKey] === newJson) {
+        return true;  // cached
+    }
+    this.cachedJson[cacheKey] = newJson;
+    return false;  // not cached, send (cache already updated)
+};
+
+DebugWebServer.prototype.uiMessageLimiterCallback = function () {
+    this.emitUiMessages();
+};
+
+DebugWebServer.prototype.execStatusLimiterCallback = function () {
+    this.emitExecStatus();
+};
+
+DebugWebServer.prototype.debugStatsLimiterCallback = function () {
+    this.emitStats();
+};
+
+DebugWebServer.prototype.emitKeepalive = function () {
+    if (!this.socket) { return; }
+
+    this.socket.emit('keepalive', { nodeVersion: process.version });
+};
+
+DebugWebServer.prototype.emitBasicInfo = function () {
+    if (!this.socket) { return; }
+
+    var newMsg = {
+        duk_version: this.dbg.dukVersion,
+        duk_git_describe: this.dbg.dukGitDescribe,
+        target_info: this.dbg.targetInfo,
+        endianness: this.dbg.endianness
+    };
+    if (this.cachedJsonCheck('basic-info', newMsg)) {
+        return;
+    }
+    this.socket.emit('basic-info', newMsg);
+};
+
+DebugWebServer.prototype.emitStats = function () {
+    if (!this.socket) { return; }
+
+    this.socket.emit('debug-stats', this.dbg.stats);
+};
+
+DebugWebServer.prototype.emitExecStatus = function () {
+    if (!this.socket) { return; }
+
+    var newMsg = this.dbg.execStatus;
+    if (this.cachedJsonCheck('exec-status', newMsg)) {
+        return;
+    }
+    this.socket.emit('exec-status', newMsg);
+};
+
+DebugWebServer.prototype.emitUiMessages = function () {
+    if (!this.socket) { return; }
+
+    var newMsg = this.dbg.messageLines;
+    if (this.cachedJsonCheck('output-lines', newMsg)) {
+        return;
+    }
+    this.socket.emit('output-lines', newMsg);
+};
+
+DebugWebServer.prototype.emitBreakpoints = function () {
+    if (!this.socket) { return; }
+
+    var newMsg = { breakpoints: this.dbg.breakpoints };
+    if (this.cachedJsonCheck('breakpoints', newMsg)) {
+        return;
+    }
+    this.socket.emit('breakpoints', newMsg);
+};
+
+DebugWebServer.prototype.emitCallStack = function () {
+    if (!this.socket) { return; }
+
+    var newMsg = { callstack: this.dbg.callstack };
+    if (this.cachedJsonCheck('callstack', newMsg)) {
+        return;
+    }
+    this.socket.emit('callstack', newMsg);
+};
+
+DebugWebServer.prototype.emitLocals = function () {
+    if (!this.socket) { return; }
+
+    var newMsg = { locals: this.dbg.locals };
+    if (this.cachedJsonCheck('locals', newMsg)) {
+        return;
+    }
+    this.socket.emit('locals', newMsg);
+};
+
+/*
+ *  JSON debug proxy
+ */
+
+function DebugProxy(serverPort) {
+    this.serverPort = serverPort;
+    this.server = null;
+    this.socket = null;
+    this.targetStream = null;
+    this.inputParser = null;
+
+    // preformatted dvalues
+    this.dval_eom = formatDebugValue(DVAL_EOM);
+    this.dval_req = formatDebugValue(DVAL_REQ);
+    this.dval_rep = formatDebugValue(DVAL_REP);
+    this.dval_nfy = formatDebugValue(DVAL_NFY);
+    this.dval_err = formatDebugValue(DVAL_ERR);
+}
+
+DebugProxy.prototype.determineCommandNumber = function (cmdName, cmdNumber) {
+    var ret;
+    if (typeof cmdName === 'string') {
+        ret = debugCommandNumbers[cmdName];
+    } else if (typeof cmdName === 'number') {
+        ret = cmdName;
+    }
+    ret = ret || cmdNumber;
+    if (typeof ret !== 'number') {
+        throw Error('cannot figure out command number for "' + cmdName + '" (' + cmdNumber + ')');
+    }
+    return ret;
+};
+
+DebugProxy.prototype.commandNumberToString = function (id) {
+    return debugCommandNames[id] || String(id);
+};
+
+DebugProxy.prototype.formatDvalues = function (args) {
+    if (!args) {
+        return [];
+    }
+    return args.map(function (v) {
+        return formatDebugValue(v);
+    });
+};
+
+DebugProxy.prototype.writeJson = function (val) {
+    this.socket.write(JSON.stringify(val) + '\n');
+};
+
+DebugProxy.prototype.writeJsonSafe = function (val) {
+    try {
+        this.writeJson(val);
+    } catch (e) {
+        console.log('Failed to write JSON in writeJsonSafe, ignoring: ' + e);
+    }
+};
+
+DebugProxy.prototype.disconnectJsonClient = function () {
+    if (this.socket) {
+        this.socket.destroy();
+        this.socket = null;
+    }
+};
+
+DebugProxy.prototype.disconnectTarget = function () {
+    if (this.inputParser) {
+        this.inputParser.close();
+        this.inputParser = null;
+    }
+    if (this.targetStream) {
+        this.targetStream.destroy();
+        this.targetStream = null;
+    }
+};
+
+DebugProxy.prototype.run = function () {
+    var _this = this;
+
+    console.log('Waiting for client connections on port ' + this.serverPort);
+    this.server = net.createServer(function (socket) {
+        console.log('JSON proxy client connected');
+
+        _this.disconnectJsonClient();
+        _this.disconnectTarget();
+
+        // A byline-parser is simple and good enough for now (assume
+        // compact JSON with no newlines).
+        var socketByline = byline(socket);
+        _this.socket = socket;
+
+        socketByline.on('data', function (line) {
+            try {
+                // console.log('Received json proxy input line: ' + line.toString('utf8'));
+                var msg = JSON.parse(line.toString('utf8'));
+                var first_dval;
+                var args_dvalues = _this.formatDvalues(msg.args);
+                var last_dval = _this.dval_eom;
+                var cmd;
+
+                if (msg.request) {
+                    // "request" can be a string or "true"
+                    first_dval = _this.dval_req;
+                    cmd = _this.determineCommandNumber(msg.request, msg.command);
+                } else if (msg.reply) {
+                    first_dval = _this.dval_rep;
+                } else if (msg.notify) {
+                    // "notify" can be a string or "true"
+                    first_dval = _this.dval_nfy;
+                    cmd = _this.determineCommandNumber(msg.notify, msg.command);
+                } else if (msg.error) {
+                    first_dval = _this.dval_err;
+                } else {
+                    throw new Error('Invalid input JSON message: ' + JSON.stringify(msg));
+                }
+
+                _this.targetStream.write(first_dval);
+                if (cmd) {
+                    _this.targetStream.write(formatDebugValue(cmd));
+                }
+                args_dvalues.forEach(function (v) {
+                    _this.targetStream.write(v);
+                });
+                _this.targetStream.write(last_dval);
+            } catch (e) {
+                console.log(e);
+
+                _this.writeJsonSafe({
+                    notify: '_Error',
+                    args: [ 'Failed to handle input json message: ' + e ]
+                });
+
+                _this.disconnectJsonClient();
+                _this.disconnectTarget();
+            }
+        });
+
+        _this.connectToTarget();
+    }).listen(this.serverPort);
+};
+
+DebugProxy.prototype.connectToTarget = function () {
+    var _this = this;
+
+    console.log('Connecting to ' + optTargetHost + ':' + optTargetPort + '...');
+    this.targetStream = new net.Socket();
+    this.targetStream.connect(optTargetPort, optTargetHost, function () {
+        console.log('Debug transport connected');
+    });
+
+    this.inputParser = new DebugProtocolParser(
+        this.targetStream,
+        null,
+        optDumpDebugRead,
+        optDumpDebugPretty,
+        optDumpDebugPretty ? 'Recv: ' : null,
+        null,
+        null   // console logging is done at a higher level to match request/response
+    );
+
+    // Don't add a 'value' key to numbers.
+    this.inputParser.readableNumberValue = false;
+
+    this.inputParser.on('transport-close', function () {
+        console.log('Debug transport closed');
+
+        _this.writeJsonSafe({
+            notify: '_Disconnecting'
+        });
+
+        _this.disconnectJsonClient();
+        _this.disconnectTarget();
+    });
+
+    this.inputParser.on('transport-error', function (err) {
+        console.log('Debug transport error', err);
+
+        _this.writeJsonSafe({
+            notify: '_Error',
+            args: [ String(err) ]
+        });
+    });
+
+    this.inputParser.on('protocol-version', function (msg) {
+        var ver = msg.protocolVersion;
+        console.log('Debug version identification:', msg.versionIdentification);
+
+        _this.writeJson({
+            notify: '_TargetConnected',
+            args: [ msg.versionIdentification ]  // raw identification string
+        });
+
+        if (ver !== 1) {
+            console.log('Protocol version ' + ver + ' unsupported, dropping connection');
+        }
+    });
+
+    this.inputParser.on('debug-message', function (msg) {
+        var t;
+
+        //console.log(msg);
+
+        if (typeof msg[0] !== 'object' || msg[0] === null) {
+            throw new Error('unexpected initial dvalue: ' + msg[0]);
+        } else if (msg[0].type === 'eom') {
+            throw new Error('unexpected initial dvalue: ' + msg[0]);
+        } else if (msg[0].type === 'req') {
+            if (typeof msg[1] !== 'number') {
+                throw new Error('unexpected request command number: ' + msg[1]);
+            }
+            t = {
+                request: _this.commandNumberToString(msg[1]),
+                command: msg[1],
+                args: msg.slice(2, msg.length - 1)
+            };
+            _this.writeJson(t);
+        } else if (msg[0].type === 'rep') {
+            t = {
+                reply: true,
+                args: msg.slice(1, msg.length - 1)
+            };
+            _this.writeJson(t);
+        } else if (msg[0].type === 'err') {
+            t = {
+                error: true,
+                args: msg.slice(1, msg.length - 1)
+            };
+            _this.writeJson(t);
+        } else if (msg[0].type === 'nfy') {
+            if (typeof msg[1] !== 'number') {
+                throw new Error('unexpected notify command number: ' + msg[1]);
+            }
+            t = {
+                notify: _this.commandNumberToString(msg[1]),
+                command: msg[1],
+                args: msg.slice(2, msg.length - 1)
+            };
+            _this.writeJson(t);
+        } else {
+            throw new Error('unexpected initial dvalue: ' + msg[0]);
+        }
+    });
+
+    this.inputParser.on('stats-update', function () {
+    });
+};
+
+/*
+ *  Command line parsing and initialization
+ */
+
+function main() {
+    console.log('((o) Duktape debugger');
+
+    // Parse arguments.
+
+    var argv = require('minimist')(process.argv.slice(2));
+    //console.dir(argv);
+    if (argv['target-host']) {
+        optTargetHost = argv['target-host'];
+    }
+    if (argv['target-port']) {
+        optTargetPort = argv['target-port'];
+    }
+    if (argv['http-port']) {
+        optHttpPort = argv['http-port'];
+    }
+    if (argv['json-proxy-port']) {
+        optJsonProxyPort = argv['json-proxy-port'];
+    }
+    if (argv['json-proxy']) {
+        optJsonProxy = argv['json-proxy'];
+    }
+    if (argv['source-dirs']) {
+        optSourceSearchDirs = argv['source-dirs'].split(path.delimiter);
+    }
+    if (argv['dump-debug-read']) {
+        optDumpDebugRead = argv['dump-debug-read'];
+    }
+    if (argv['dump-debug-write']) {
+        optDumpDebugWrite = argv['dump-debug-write'];
+    }
+    if (argv['dump-debug-pretty']) {
+        optDumpDebugPretty = argv['dump-debug-pretty'];
+    }
+    if (argv['log-messages']) {
+        optLogMessages = true;
+    }
+
+    // Dump effective options.  Also provides a list of option names.
+
+    console.log('');
+    console.log('Effective options:');
+    console.log('  --target-host:       ' + optTargetHost);
+    console.log('  --target-port:       ' + optTargetPort);
+    console.log('  --http-port:         ' + optHttpPort);
+    console.log('  --json-proxy-port:   ' + optJsonProxyPort);
+    console.log('  --json-proxy:        ' + optJsonProxy);
+    console.log('  --source-dirs:       ' + optSourceSearchDirs.join(' '));
+    console.log('  --dump-debug-read:   ' + optDumpDebugRead);
+    console.log('  --dump-debug-write:  ' + optDumpDebugWrite);
+    console.log('  --dump-debug-pretty: ' + optDumpDebugPretty);
+    console.log('  --log-messages:      ' + optLogMessages);
+    console.log('');
+
+    // Create debugger and web UI singletons, tie them together and
+    // start them.
+
+    if (optJsonProxy) {
+        console.log('Starting in JSON proxy mode, JSON port: ' + optJsonProxyPort);
+
+        var prx = new DebugProxy(optJsonProxyPort);
+        prx.run();
+    } else {
+        var dbg = new Debugger();
+        var web = new DebugWebServer();
+        dbg.web = web;
+        web.dbg = dbg;
+        dbg.run();
+        web.run();
+    }
+}
+
+main();


[44/51] [partial] nifi-minifi-cpp git commit: MINIFI-183 Added civet 1.9.1 sources Added onScheduled hook Added initial two-way TLS-enabled ListenHTTP implementation

Posted by al...@apache.org.
http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/examples/_obsolete/chat/chat.c
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/examples/_obsolete/chat/chat.c b/thirdparty/civetweb-1.9.1/examples/_obsolete/chat/chat.c
new file mode 100644
index 0000000..ad14618
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/examples/_obsolete/chat/chat.c
@@ -0,0 +1,403 @@
+// This file is part of the Civetweb project, http://code.google.com/p/civetweb
+// It implements an online chat server. For more details,
+// see the documentation on the project web site.
+// To test the application,
+// 1. type "make" in the directory where this file lives
+// 2. point your browser to http://127.0.0.1:8081
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <string.h>
+#include <time.h>
+#include <stdarg.h>
+#include <pthread.h>
+
+#include "civetweb.h"
+
+#define MAX_USER_LEN  20
+#define MAX_MESSAGE_LEN  100
+#define MAX_MESSAGES 5
+#define MAX_SESSIONS 2
+#define SESSION_TTL 120
+
+static const char *authorize_url = "/authorize";
+static const char *login_url = "/login.html";
+static const char *ajax_reply_start =
+    "HTTP/1.1 200 OK\r\n"
+    "Cache: no-cache\r\n"
+    "Content-Type: application/x-javascript\r\n"
+    "\r\n";
+
+// Describes single message sent to a chat. If user is empty (0 length),
+// the message is then originated from the server itself.
+struct message {
+    long id;                     // Message ID
+    char user[MAX_USER_LEN];     // User that have sent the message
+    char text[MAX_MESSAGE_LEN];  // Message text
+    time_t timestamp;            // Message timestamp, UTC
+};
+
+// Describes web session.
+struct session {
+    char session_id[33];      // Session ID, must be unique
+    char random[20];          // Random data used for extra user validation
+    char user[MAX_USER_LEN];  // Authenticated user
+    time_t expire;            // Expiration timestamp, UTC
+};
+
+static struct message messages[MAX_MESSAGES];  // Ringbuffer for messages
+static struct session sessions[MAX_SESSIONS];  // Current sessions
+static long last_message_id;
+
+// Protects messages, sessions, last_message_id
+static pthread_rwlock_t rwlock = PTHREAD_RWLOCK_INITIALIZER;
+
+// Get session object for the connection. Caller must hold the lock.
+static struct session *get_session(const struct mg_connection *conn)
+{
+    int i;
+    const char *cookie = mg_get_header(conn, "Cookie");
+    char session_id[33];
+    time_t now = time(NULL);
+    mg_get_cookie(cookie, "session", session_id, sizeof(session_id));
+    for (i = 0; i < MAX_SESSIONS; i++) {
+        if (sessions[i].expire != 0 &&
+            sessions[i].expire > now &&
+            strcmp(sessions[i].session_id, session_id) == 0) {
+            break;
+        }
+    }
+    return i == MAX_SESSIONS ? NULL : &sessions[i];
+}
+
+static void get_qsvar(const struct mg_request_info *request_info,
+                      const char *name, char *dst, size_t dst_len)
+{
+    const char *qs = request_info->query_string;
+    mg_get_var(qs, strlen(qs == NULL ? "" : qs), name, dst, dst_len);
+}
+
+// Get a get of messages with IDs greater than last_id and transform them
+// into a JSON string. Return that string to the caller. The string is
+// dynamically allocated, caller must free it. If there are no messages,
+// NULL is returned.
+static char *messages_to_json(long last_id)
+{
+    const struct message *message;
+    int max_msgs, len;
+    char buf[sizeof(messages)];  // Large enough to hold all messages
+
+    // Read-lock the ringbuffer. Loop over all messages, making a JSON string.
+    pthread_rwlock_rdlock(&rwlock);
+    len = 0;
+    max_msgs = sizeof(messages) / sizeof(messages[0]);
+    // If client is too far behind, return all messages.
+    if (last_message_id - last_id > max_msgs) {
+        last_id = last_message_id - max_msgs;
+    }
+    for (; last_id < last_message_id; last_id++) {
+        message = &messages[last_id % max_msgs];
+        if (message->timestamp == 0) {
+            break;
+        }
+        // buf is allocated on stack and hopefully is large enough to hold all
+        // messages (it may be too small if the ringbuffer is full and all
+        // messages are large. in this case asserts will trigger).
+        len += snprintf(buf + len, sizeof(buf) - len,
+                        "{user: '%s', text: '%s', timestamp: %lu, id: %ld},",
+                        message->user, message->text, message->timestamp, message->id);
+        assert(len > 0);
+        assert((size_t) len < sizeof(buf));
+    }
+    pthread_rwlock_unlock(&rwlock);
+
+    return len == 0 ? NULL : strdup(buf);
+}
+
+// If "callback" param is present in query string, this is JSONP call.
+// Return 1 in this case, or 0 if "callback" is not specified.
+// Wrap an output in Javascript function call.
+static int handle_jsonp(struct mg_connection *conn,
+                        const struct mg_request_info *request_info)
+{
+    char cb[64];
+
+    get_qsvar(request_info, "callback", cb, sizeof(cb));
+    if (cb[0] != '\0') {
+        mg_printf(conn, "%s(", cb);
+    }
+
+    return cb[0] == '\0' ? 0 : 1;
+}
+
+// A handler for the /ajax/get_messages endpoint.
+// Return a list of messages with ID greater than requested.
+static void ajax_get_messages(struct mg_connection *conn,
+                              const struct mg_request_info *request_info)
+{
+    char last_id[32], *json;
+    int is_jsonp;
+
+    mg_printf(conn, "%s", ajax_reply_start);
+    is_jsonp = handle_jsonp(conn, request_info);
+
+    get_qsvar(request_info, "last_id", last_id, sizeof(last_id));
+    if ((json = messages_to_json(strtoul(last_id, NULL, 10))) != NULL) {
+        mg_printf(conn, "[%s]", json);
+        free(json);
+    }
+
+    if (is_jsonp) {
+        mg_printf(conn, "%s", ")");
+    }
+}
+
+// Allocate new message. Caller must hold the lock.
+static struct message *new_message(void)
+{
+    static int size = sizeof(messages) / sizeof(messages[0]);
+    struct message *message = &messages[last_message_id % size];
+    message->id = last_message_id++;
+    message->timestamp = time(0);
+    return message;
+}
+
+static void my_strlcpy(char *dst, const char *src, size_t len)
+{
+    strncpy(dst, src, len);
+    dst[len - 1] = '\0';
+}
+
+// A handler for the /ajax/send_message endpoint.
+static void ajax_send_message(struct mg_connection *conn,
+                              const struct mg_request_info *request_info)
+{
+    struct message *message;
+    struct session *session;
+    char text[sizeof(message->text) - 1];
+    int is_jsonp;
+
+    mg_printf(conn, "%s", ajax_reply_start);
+    is_jsonp = handle_jsonp(conn, request_info);
+
+    get_qsvar(request_info, "text", text, sizeof(text));
+    if (text[0] != '\0') {
+        // We have a message to store. Write-lock the ringbuffer,
+        // grab the next message and copy data into it.
+        pthread_rwlock_wrlock(&rwlock);
+        message = new_message();
+        // TODO(lsm): JSON-encode all text strings
+        session = get_session(conn);
+        assert(session != NULL);
+        my_strlcpy(message->text, text, sizeof(text));
+        my_strlcpy(message->user, session->user, sizeof(message->user));
+        pthread_rwlock_unlock(&rwlock);
+    }
+
+    mg_printf(conn, "%s", text[0] == '\0' ? "false" : "true");
+
+    if (is_jsonp) {
+        mg_printf(conn, "%s", ")");
+    }
+}
+
+// Redirect user to the login form. In the cookie, store the original URL
+// we came from, so that after the authorization we could redirect back.
+static void redirect_to_login(struct mg_connection *conn,
+                              const struct mg_request_info *request_info)
+{
+    mg_printf(conn, "HTTP/1.1 302 Found\r\n"
+              "Set-Cookie: original_url=%s\r\n"
+              "Location: %s\r\n\r\n",
+              request_info->uri, login_url);
+}
+
+// Return 1 if username/password is allowed, 0 otherwise.
+static int check_password(const char *user, const char *password)
+{
+    // In production environment we should ask an authentication system
+    // to authenticate the user.
+    // Here however we do trivial check that user and password are not empty
+    return (user[0] && password[0]);
+}
+
+// Allocate new session object
+static struct session *new_session(void)
+{
+    int i;
+    time_t now = time(NULL);
+    pthread_rwlock_wrlock(&rwlock);
+    for (i = 0; i < MAX_SESSIONS; i++) {
+        if (sessions[i].expire == 0 || sessions[i].expire < now) {
+            sessions[i].expire = time(0) + SESSION_TTL;
+            break;
+        }
+    }
+    pthread_rwlock_unlock(&rwlock);
+    return i == MAX_SESSIONS ? NULL : &sessions[i];
+}
+
+// Generate session ID. buf must be 33 bytes in size.
+// Note that it is easy to steal session cookies by sniffing traffic.
+// This is why all communication must be SSL-ed.
+static void generate_session_id(char *buf, const char *random,
+                                const char *user)
+{
+    mg_md5(buf, random, user, NULL);
+}
+
+static void send_server_message(const char *fmt, ...)
+{
+    va_list ap;
+    struct message *message;
+
+    pthread_rwlock_wrlock(&rwlock);
+    message = new_message();
+    message->user[0] = '\0';  // Empty user indicates server message
+    va_start(ap, fmt);
+    vsnprintf(message->text, sizeof(message->text), fmt, ap);
+    va_end(ap);
+
+    pthread_rwlock_unlock(&rwlock);
+}
+
+// A handler for the /authorize endpoint.
+// Login page form sends user name and password to this endpoint.
+static void authorize(struct mg_connection *conn,
+                      const struct mg_request_info *request_info)
+{
+    char user[MAX_USER_LEN], password[MAX_USER_LEN];
+    struct session *session;
+
+    // Fetch user name and password.
+    get_qsvar(request_info, "user", user, sizeof(user));
+    get_qsvar(request_info, "password", password, sizeof(password));
+
+    if (check_password(user, password) && (session = new_session()) != NULL) {
+        // Authentication success:
+        //   1. create new session
+        //   2. set session ID token in the cookie
+        //   3. remove original_url from the cookie - not needed anymore
+        //   4. redirect client back to the original URL
+        //
+        // The most secure way is to stay HTTPS all the time. However, just to
+        // show the technique, we redirect to HTTP after the successful
+        // authentication. The danger of doing this is that session cookie can
+        // be stolen and an attacker may impersonate the user.
+        // Secure application must use HTTPS all the time.
+        my_strlcpy(session->user, user, sizeof(session->user));
+        snprintf(session->random, sizeof(session->random), "%d", rand());
+        generate_session_id(session->session_id, session->random, session->user);
+        send_server_message("<%s> joined", session->user);
+        mg_printf(conn, "HTTP/1.1 302 Found\r\n"
+                  "Set-Cookie: session=%s; max-age=3600; http-only\r\n"  // Session ID
+                  "Set-Cookie: user=%s\r\n"  // Set user, needed by Javascript code
+                  "Set-Cookie: original_url=/; max-age=0\r\n"  // Delete original_url
+                  "Location: /\r\n\r\n",
+                  session->session_id, session->user);
+    } else {
+        // Authentication failure, redirect to login.
+        redirect_to_login(conn, request_info);
+    }
+}
+
+// Return 1 if request is authorized, 0 otherwise.
+static int is_authorized(const struct mg_connection *conn,
+                         const struct mg_request_info *request_info)
+{
+    struct session *session;
+    char valid_id[33];
+    int authorized = 0;
+
+    // Always authorize accesses to login page and to authorize URI
+    if (!strcmp(request_info->uri, login_url) ||
+        !strcmp(request_info->uri, authorize_url)) {
+        return 1;
+    }
+
+    pthread_rwlock_rdlock(&rwlock);
+    if ((session = get_session(conn)) != NULL) {
+        generate_session_id(valid_id, session->random, session->user);
+        if (strcmp(valid_id, session->session_id) == 0) {
+            session->expire = time(0) + SESSION_TTL;
+            authorized = 1;
+        }
+    }
+    pthread_rwlock_unlock(&rwlock);
+
+    return authorized;
+}
+
+static void redirect_to_ssl(struct mg_connection *conn,
+                            const struct mg_request_info *request_info)
+{
+    const char *p, *host = mg_get_header(conn, "Host");
+    if (host != NULL && (p = strchr(host, ':')) != NULL) {
+        mg_printf(conn, "HTTP/1.1 302 Found\r\n"
+                  "Location: https://%.*s:8082/%s:8082\r\n\r\n",
+                  (int) (p - host), host, request_info->uri);
+    } else {
+        mg_printf(conn, "%s", "HTTP/1.1 500 Error\r\n\r\nHost: header is not set");
+    }
+}
+
+static int begin_request_handler(struct mg_connection *conn)
+{
+    const struct mg_request_info *request_info = mg_get_request_info(conn);
+    int processed = 1;
+
+    if (!request_info->is_ssl) {
+        redirect_to_ssl(conn, request_info);
+    } else if (!is_authorized(conn, request_info)) {
+        redirect_to_login(conn, request_info);
+    } else if (strcmp(request_info->uri, authorize_url) == 0) {
+        authorize(conn, request_info);
+    } else if (strcmp(request_info->uri, "/ajax/get_messages") == 0) {
+        ajax_get_messages(conn, request_info);
+    } else if (strcmp(request_info->uri, "/ajax/send_message") == 0) {
+        ajax_send_message(conn, request_info);
+    } else {
+        // No suitable handler found, mark as not processed. Civetweb will
+        // try to serve the request.
+        processed = 0;
+    }
+    return processed;
+}
+
+static const char *options[] = {
+    "document_root", "html",
+    "listening_ports", "8081,8082s",
+    "ssl_certificate", "ssl_cert.pem",
+    "num_threads", "5",
+    NULL
+};
+
+int main(void)
+{
+    struct mg_callbacks callbacks;
+    struct mg_context *ctx;
+
+    // Initialize random number generator. It will be used later on for
+    // the session identifier creation.
+    srand((unsigned) time(0));
+
+    // Setup and start Civetweb
+    memset(&callbacks, 0, sizeof(callbacks));
+    callbacks.begin_request = begin_request_handler;
+    if ((ctx = mg_start(&callbacks, NULL, options)) == NULL) {
+        printf("%s\n", "Cannot start chat server, fatal exit");
+        exit(EXIT_FAILURE);
+    }
+
+    // Wait until enter is pressed, then exit
+    printf("Chat server started on ports %s, press enter to quit.\n",
+           mg_get_option(ctx, "listening_ports"));
+    getchar();
+    mg_stop(ctx);
+    printf("%s\n", "Chat server stopped.");
+
+    return EXIT_SUCCESS;
+}
+
+// vim:ts=2:sw=2:et

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/examples/_obsolete/docroot/favicon.ico
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/examples/_obsolete/docroot/favicon.ico b/thirdparty/civetweb-1.9.1/examples/_obsolete/docroot/favicon.ico
new file mode 100644
index 0000000..2179aba
Binary files /dev/null and b/thirdparty/civetweb-1.9.1/examples/_obsolete/docroot/favicon.ico differ

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/examples/_obsolete/docroot/index.html
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/examples/_obsolete/docroot/index.html b/thirdparty/civetweb-1.9.1/examples/_obsolete/docroot/index.html
new file mode 100644
index 0000000..c85bec9
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/examples/_obsolete/docroot/index.html
@@ -0,0 +1,73 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
+<html xmlns="http://www.w3.org/1999/xhtml" lang="en" dir="ltr"> 
+  <!-- This file is part of the  Civetweb project,
+    http://sourceforge.net/projects/civetweb/ -->
+  <head>
+    <title>Civetweb chat server</title>
+    <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
+    <link type="text/css" rel="stylesheet" href="style.css"/>
+    <script src="jquery.js"></script>
+    <script src="main.js"></script>
+  </head>
+
+  <body>
+  <div id="header">
+    <div id="logo"></div>
+    <div class="rounded infobox help-message" id="motd">
+      Chat room implemented using
+      <a href="http://sourceforge.net/projects/civetweb/" target="_blank">Civetweb</a>
+      embeddable web server.
+      This application was written for educational purposes demonstrating
+      how web interface could be decoupled from the business logic. Not a
+      single line of HTML is generated by the server, instead, server
+      gives data to the client in JSON format.
+    </div>
+  </div>
+  <div>
+
+  <div id="middle">
+    <div><center><span id="error" class="rounded"></span><center></div>
+
+    <div id="menu">
+      <div class="menu-item left-rounded menu-item-selected"
+      	name="chat">Chat</div>
+      <div class="menu-item left-rounded" name="settings">Settings</div>
+    </div>
+
+    <div id="content" class="rounded">
+
+      <div id="chat" class="main">
+        <div class="chat-window">
+          <span class="top-rounded chat-title">Main room</span>
+          <div class="bottom-rounded chat-content">
+            <div class="message-list" id="mml">
+            </div>
+            <input type="text" size="40" class="message-input"></input>
+            <span class="help-message">
+              Type your message here and press enter</span>
+          </div>
+        </div>
+      </div>
+
+      <div id="settings" class="hidden main">
+        <div>
+          <span class="top-rounded chat-title">Settings</span>
+          <div class="bottom-rounded chat-content">
+	    <table>
+	      <tr><td>Max messages to display:</td><td>blah blah</td></tr>
+	      <tr><td>Text color:</td><td>blah blah</td></tr>
+	    </table>
+          </div>
+        </div>
+      </div>
+
+    </div>
+  </div>
+
+  <div id="footer">
+    Copyright &copy; 2004-2010 by Sergey Lyubka
+  </div>
+
+  </body>
+</html>


[19/51] [partial] nifi-minifi-cpp git commit: MINIFI-183 Added civet 1.9.1 sources Added onScheduled hook Added initial two-way TLS-enabled ListenHTTP implementation

Posted by al...@apache.org.
http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-noline/duktape.h
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-noline/duktape.h b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-noline/duktape.h
new file mode 100644
index 0000000..84a32f8
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-noline/duktape.h
@@ -0,0 +1,1567 @@
+/*
+ *  Duktape public API for Duktape 1.5.2.
+ *
+ *  See the API reference for documentation on call semantics.
+ *  The exposed API is inside the DUK_API_PUBLIC_H_INCLUDED
+ *  include guard.  Other parts of the header are Duktape
+ *  internal and related to platform/compiler/feature detection.
+ *
+ *  Git commit cad34ae155acb0846545ca6bf2d29f9463b22bbb (v1.5.2).
+ *  Git branch HEAD.
+ *
+ *  See Duktape AUTHORS.rst and LICENSE.txt for copyright and
+ *  licensing information.
+ */
+
+/* LICENSE.txt */
+/*
+ *  ===============
+ *  Duktape license
+ *  ===============
+ *  
+ *  (http://opensource.org/licenses/MIT)
+ *  
+ *  Copyright (c) 2013-2016 by Duktape authors (see AUTHORS.rst)
+ *  
+ *  Permission is hereby granted, free of charge, to any person obtaining a copy
+ *  of this software and associated documentation files (the "Software"), to deal
+ *  in the Software without restriction, including without limitation the rights
+ *  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ *  copies of the Software, and to permit persons to whom the Software is
+ *  furnished to do so, subject to the following conditions:
+ *  
+ *  The above copyright notice and this permission notice shall be included in
+ *  all copies or substantial portions of the Software.
+ *  
+ *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ *  THE SOFTWARE.
+ */
+
+/* AUTHORS.rst */
+/*
+ *  ===============
+ *  Duktape authors
+ *  ===============
+ *  
+ *  Copyright
+ *  =========
+ *  
+ *  Duktape copyrights are held by its authors.  Each author has a copyright
+ *  to their contribution, and agrees to irrevocably license the contribution
+ *  under the Duktape ``LICENSE.txt``.
+ *  
+ *  Authors
+ *  =======
+ *  
+ *  Please include an e-mail address, a link to your GitHub profile, or something
+ *  similar to allow your contribution to be identified accurately.
+ *  
+ *  The following people have contributed code, website contents, or Wiki contents,
+ *  and agreed to irrevocably license their contributions under the Duktape
+ *  ``LICENSE.txt`` (in order of appearance):
+ *  
+ *  * Sami Vaarala <sa...@iki.fi>
+ *  * Niki Dobrev
+ *  * Andreas \u00d6man <an...@lonelycoder.com>
+ *  * L\u00e1szl\u00f3 Lang\u00f3 <ll...@partner.samsung.com>
+ *  * Legimet <le...@gmail.com>
+ *  * Karl Skomski <ka...@skomski.com>
+ *  * Bruce Pascoe <fa...@gmail.com>
+ *  * Ren\u00e9 Hollander <re...@rene8888.at>
+ *  * Julien Hamaide (https://github.com/crazyjul)
+ *  * Sebastian G\u00f6tte (https://github.com/jaseg)
+ *  
+ *  Other contributions
+ *  ===================
+ *  
+ *  The following people have contributed something other than code (e.g. reported
+ *  bugs, provided ideas, etc; roughly in order of appearance):
+ *  
+ *  * Greg Burns
+ *  * Anthony Rabine
+ *  * Carlos Costa
+ *  * Aur\u00e9lien Bouilland
+ *  * Preet Desai (Pris Matic)
+ *  * judofyr (http://www.reddit.com/user/judofyr)
+ *  * Jason Woofenden
+ *  * Micha\u0142 Przyby\u015b
+ *  * Anthony Howe
+ *  * Conrad Pankoff
+ *  * Jim Schimpf
+ *  * Rajaran Gaunker (https://github.com/zimbabao)
+ *  * Andreas \u00d6man
+ *  * Doug Sanden
+ *  * Josh Engebretson (https://github.com/JoshEngebretson)
+ *  * Remo Eichenberger (https://github.com/remoe)
+ *  * Mamod Mehyar (https://github.com/mamod)
+ *  * David Demelier (https://github.com/markand)
+ *  * Tim Caswell (https://github.com/creationix)
+ *  * Mitchell Blank Jr (https://github.com/mitchblank)
+ *  * https://github.com/yushli
+ *  * Seo Sanghyeon (https://github.com/sanxiyn)
+ *  * Han ChoongWoo (https://github.com/tunz)
+ *  * Joshua Peek (https://github.com/josh)
+ *  * Bruce E. Pascoe (https://github.com/fatcerberus)
+ *  * https://github.com/Kelledin
+ *  * https://github.com/sstruchtrup
+ *  * Michael Drake (https://github.com/tlsa)
+ *  * https://github.com/chris-y
+ *  * Laurent Zubiaur (https://github.com/lzubiaur)
+ *  * Ole Andr\u00e9 Vadla Ravn\u00e5s (https://github.com/oleavr)
+ *  
+ *  If you are accidentally missing from this list, send me an e-mail
+ *  (``sami.vaarala@iki.fi``) and I'll fix the omission.
+ */
+
+#ifndef DUKTAPE_H_INCLUDED
+#define DUKTAPE_H_INCLUDED
+
+#define DUK_SINGLE_FILE
+
+/* External duk_config.h provides platform/compiler/OS dependent
+ * typedefs and macros, and DUK_USE_xxx config options so that
+ * the rest of Duktape doesn't need to do any feature detection.
+ */
+#include "duk_config.h"
+
+/*
+ *  BEGIN PUBLIC API
+ */
+
+#ifndef DUK_API_PUBLIC_H_INCLUDED
+#define DUK_API_PUBLIC_H_INCLUDED
+
+/*
+ *  Avoid C++ name mangling
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ *  Some defines forwarded from feature detection
+ */
+
+#undef DUK_API_VARIADIC_MACROS
+#ifdef DUK_USE_VARIADIC_MACROS
+#define DUK_API_VARIADIC_MACROS
+#endif
+
+#define DUK_API_NORETURN(decl) DUK_NORETURN(decl)
+
+/*
+ *  Public API specific typedefs
+ *
+ *  Many types are wrapped by Duktape for portability to rare platforms
+ *  where e.g. 'int' is a 16-bit type.  See practical typing discussion
+ *  in Duktape web documentation.
+ */
+
+struct duk_memory_functions;
+struct duk_function_list_entry;
+struct duk_number_list_entry;
+
+/* duk_context is now defined in duk_config.h because it may also be
+ * referenced there by prototypes.
+ */
+typedef struct duk_memory_functions duk_memory_functions;
+typedef struct duk_function_list_entry duk_function_list_entry;
+typedef struct duk_number_list_entry duk_number_list_entry;
+
+typedef duk_ret_t (*duk_c_function)(duk_context *ctx);
+typedef void *(*duk_alloc_function) (void *udata, duk_size_t size);
+typedef void *(*duk_realloc_function) (void *udata, void *ptr, duk_size_t size);
+typedef void (*duk_free_function) (void *udata, void *ptr);
+typedef void (*duk_fatal_function) (duk_context *ctx, duk_errcode_t code, const char *msg);
+typedef void (*duk_decode_char_function) (void *udata, duk_codepoint_t codepoint);
+typedef duk_codepoint_t (*duk_map_char_function) (void *udata, duk_codepoint_t codepoint);
+typedef duk_ret_t (*duk_safe_call_function) (duk_context *ctx);
+typedef duk_size_t (*duk_debug_read_function) (void *udata, char *buffer, duk_size_t length);
+typedef duk_size_t (*duk_debug_write_function) (void *udata, const char *buffer, duk_size_t length);
+typedef duk_size_t (*duk_debug_peek_function) (void *udata);
+typedef void (*duk_debug_read_flush_function) (void *udata);
+typedef void (*duk_debug_write_flush_function) (void *udata);
+typedef duk_idx_t (*duk_debug_request_function) (duk_context *ctx, void *udata, duk_idx_t nvalues);
+typedef void (*duk_debug_detached_function) (void *udata);
+
+struct duk_memory_functions {
+	duk_alloc_function alloc_func;
+	duk_realloc_function realloc_func;
+	duk_free_function free_func;
+	void *udata;
+};
+
+struct duk_function_list_entry {
+	const char *key;
+	duk_c_function value;
+	duk_idx_t nargs;
+};
+
+struct duk_number_list_entry {
+	const char *key;
+	duk_double_t value;
+};
+
+/*
+ *  Constants
+ */
+
+/* Duktape version, (major * 10000) + (minor * 100) + patch.  Allows C code
+ * to #ifdef against Duktape API version.  The same value is also available
+ * to Ecmascript code in Duktape.version.  Unofficial development snapshots
+ * have 99 for patch level (e.g. 0.10.99 would be a development version
+ * after 0.10.0 but before the next official release).
+ */
+#define DUK_VERSION                       10502L
+
+/* Git commit, describe, and branch for Duktape build.  Useful for
+ * non-official snapshot builds so that application code can easily log
+ * which Duktape snapshot was used.  Not available in the Ecmascript
+ * environment.
+ */
+#define DUK_GIT_COMMIT                    "cad34ae155acb0846545ca6bf2d29f9463b22bbb"
+#define DUK_GIT_DESCRIBE                  "v1.5.2"
+#define DUK_GIT_BRANCH                    "HEAD"
+
+/* Duktape debug protocol version used by this build. */
+#define DUK_DEBUG_PROTOCOL_VERSION        1
+
+/* Used to represent invalid index; if caller uses this without checking,
+ * this index will map to a non-existent stack entry.  Also used in some
+ * API calls as a marker to denote "no value".
+ */
+#define DUK_INVALID_INDEX                 DUK_IDX_MIN
+
+/* Indicates that a native function does not have a fixed number of args,
+ * and the argument stack should not be capped/extended at all.
+ */
+#define DUK_VARARGS                       ((duk_int_t) (-1))
+
+/* Number of value stack entries (in addition to actual call arguments)
+ * guaranteed to be allocated on entry to a Duktape/C function.
+ */
+#define DUK_API_ENTRY_STACK               64
+
+/* Value types, used by e.g. duk_get_type() */
+#define DUK_TYPE_MIN                      0
+#define DUK_TYPE_NONE                     0    /* no value, e.g. invalid index */
+#define DUK_TYPE_UNDEFINED                1    /* Ecmascript undefined */
+#define DUK_TYPE_NULL                     2    /* Ecmascript null */
+#define DUK_TYPE_BOOLEAN                  3    /* Ecmascript boolean: 0 or 1 */
+#define DUK_TYPE_NUMBER                   4    /* Ecmascript number: double */
+#define DUK_TYPE_STRING                   5    /* Ecmascript string: CESU-8 / extended UTF-8 encoded */
+#define DUK_TYPE_OBJECT                   6    /* Ecmascript object: includes objects, arrays, functions, threads */
+#define DUK_TYPE_BUFFER                   7    /* fixed or dynamic, garbage collected byte buffer */
+#define DUK_TYPE_POINTER                  8    /* raw void pointer */
+#define DUK_TYPE_LIGHTFUNC                9    /* lightweight function pointer */
+#define DUK_TYPE_MAX                      9
+
+/* Value mask types, used by e.g. duk_get_type_mask() */
+#define DUK_TYPE_MASK_NONE                (1 << DUK_TYPE_NONE)
+#define DUK_TYPE_MASK_UNDEFINED           (1 << DUK_TYPE_UNDEFINED)
+#define DUK_TYPE_MASK_NULL                (1 << DUK_TYPE_NULL)
+#define DUK_TYPE_MASK_BOOLEAN             (1 << DUK_TYPE_BOOLEAN)
+#define DUK_TYPE_MASK_NUMBER              (1 << DUK_TYPE_NUMBER)
+#define DUK_TYPE_MASK_STRING              (1 << DUK_TYPE_STRING)
+#define DUK_TYPE_MASK_OBJECT              (1 << DUK_TYPE_OBJECT)
+#define DUK_TYPE_MASK_BUFFER              (1 << DUK_TYPE_BUFFER)
+#define DUK_TYPE_MASK_POINTER             (1 << DUK_TYPE_POINTER)
+#define DUK_TYPE_MASK_LIGHTFUNC           (1 << DUK_TYPE_LIGHTFUNC)
+#define DUK_TYPE_MASK_THROW               (1 << 10)  /* internal flag value: throw if mask doesn't match */
+
+/* Coercion hints */
+#define DUK_HINT_NONE                     0    /* prefer number, unless input is a Date, in which
+                                                * case prefer string (E5 Section 8.12.8)
+                                                */
+#define DUK_HINT_STRING                   1    /* prefer string */
+#define DUK_HINT_NUMBER                   2    /* prefer number */
+
+/* Enumeration flags for duk_enum() */
+#define DUK_ENUM_INCLUDE_NONENUMERABLE    (1 << 0)    /* enumerate non-numerable properties in addition to enumerable */
+#define DUK_ENUM_INCLUDE_INTERNAL         (1 << 1)    /* enumerate internal properties (regardless of enumerability) */
+#define DUK_ENUM_OWN_PROPERTIES_ONLY      (1 << 2)    /* don't walk prototype chain, only check own properties */
+#define DUK_ENUM_ARRAY_INDICES_ONLY       (1 << 3)    /* only enumerate array indices */
+#define DUK_ENUM_SORT_ARRAY_INDICES       (1 << 4)    /* sort array indices, use with DUK_ENUM_ARRAY_INDICES_ONLY */
+#define DUK_ENUM_NO_PROXY_BEHAVIOR        (1 << 5)    /* enumerate a proxy object itself without invoking proxy behavior */
+
+/* Compilation flags for duk_compile() and duk_eval() */
+/* DUK_COMPILE_xxx bits 0-2 are reserved for an internal 'nargs' argument
+ * (the nargs value passed is direct stack arguments + 1 to account for an
+ * internal extra argument).
+ */
+#define DUK_COMPILE_EVAL                  (1 << 3)    /* compile eval code (instead of global code) */
+#define DUK_COMPILE_FUNCTION              (1 << 4)    /* compile function code (instead of global code) */
+#define DUK_COMPILE_STRICT                (1 << 5)    /* use strict (outer) context for global, eval, or function code */
+#define DUK_COMPILE_SAFE                  (1 << 6)    /* (internal) catch compilation errors */
+#define DUK_COMPILE_NORESULT              (1 << 7)    /* (internal) omit eval result */
+#define DUK_COMPILE_NOSOURCE              (1 << 8)    /* (internal) no source string on stack */
+#define DUK_COMPILE_STRLEN                (1 << 9)    /* (internal) take strlen() of src_buffer (avoids double evaluation in macro) */
+#define DUK_COMPILE_NOFILENAME            (1 << 10)    /* (internal) no filename on stack */
+
+/* Flags for duk_def_prop() and its variants */
+#define DUK_DEFPROP_WRITABLE              (1 << 0)    /* set writable (effective if DUK_DEFPROP_HAVE_WRITABLE set) */
+#define DUK_DEFPROP_ENUMERABLE            (1 << 1)    /* set enumerable (effective if DUK_DEFPROP_HAVE_ENUMERABLE set) */
+#define DUK_DEFPROP_CONFIGURABLE          (1 << 2)    /* set configurable (effective if DUK_DEFPROP_HAVE_CONFIGURABLE set) */
+#define DUK_DEFPROP_HAVE_WRITABLE         (1 << 3)    /* set/clear writable */
+#define DUK_DEFPROP_HAVE_ENUMERABLE       (1 << 4)    /* set/clear enumerable */
+#define DUK_DEFPROP_HAVE_CONFIGURABLE     (1 << 5)    /* set/clear configurable */
+#define DUK_DEFPROP_HAVE_VALUE            (1 << 6)    /* set value (given on value stack) */
+#define DUK_DEFPROP_HAVE_GETTER           (1 << 7)    /* set getter (given on value stack) */
+#define DUK_DEFPROP_HAVE_SETTER           (1 << 8)    /* set setter (given on value stack) */
+#define DUK_DEFPROP_FORCE                 (1 << 9)    /* force change if possible, may still fail for e.g. virtual properties */
+#define DUK_DEFPROP_SET_WRITABLE          (DUK_DEFPROP_HAVE_WRITABLE | DUK_DEFPROP_WRITABLE)
+#define DUK_DEFPROP_CLEAR_WRITABLE        DUK_DEFPROP_HAVE_WRITABLE
+#define DUK_DEFPROP_SET_ENUMERABLE        (DUK_DEFPROP_HAVE_ENUMERABLE | DUK_DEFPROP_ENUMERABLE)
+#define DUK_DEFPROP_CLEAR_ENUMERABLE      DUK_DEFPROP_HAVE_ENUMERABLE
+#define DUK_DEFPROP_SET_CONFIGURABLE      (DUK_DEFPROP_HAVE_CONFIGURABLE | DUK_DEFPROP_CONFIGURABLE)
+#define DUK_DEFPROP_CLEAR_CONFIGURABLE    DUK_DEFPROP_HAVE_CONFIGURABLE
+
+/* Flags for duk_push_thread_raw() */
+#define DUK_THREAD_NEW_GLOBAL_ENV         (1 << 0)    /* create a new global environment */
+
+/* Flags for duk_push_string_file_raw() */
+#define DUK_STRING_PUSH_SAFE              (1 << 0)    /* no error if file does not exist */
+
+/* Duktape specific error codes (must be 8 bits at most, see duk_error.h) */
+#define DUK_ERR_NONE                      0    /* no error (e.g. from duk_get_error_code()) */
+#define DUK_ERR_UNIMPLEMENTED_ERROR       50   /* UnimplementedError */  /* XXX: replace with TypeError? */
+#define DUK_ERR_UNSUPPORTED_ERROR         51   /* UnsupportedError */    /* XXX: replace with TypeError? */
+#define DUK_ERR_INTERNAL_ERROR            52   /* InternalError */       /* XXX: replace with plain Error? */
+#define DUK_ERR_ALLOC_ERROR               53   /* AllocError */          /* XXX: replace with RangeError? */
+#define DUK_ERR_ASSERTION_ERROR           54   /* AssertionError */      /* XXX: to be removed? */
+#define DUK_ERR_API_ERROR                 55   /* APIError */            /* XXX: replace with TypeError? */
+#define DUK_ERR_UNCAUGHT_ERROR            56   /* UncaughtError */       /* XXX: to be removed? */
+
+/* Ecmascript E5 specification error codes */
+#define DUK_ERR_ERROR                     100  /* Error */
+#define DUK_ERR_EVAL_ERROR                101  /* EvalError */
+#define DUK_ERR_RANGE_ERROR               102  /* RangeError */
+#define DUK_ERR_REFERENCE_ERROR           103  /* ReferenceError */
+#define DUK_ERR_SYNTAX_ERROR              104  /* SyntaxError */
+#define DUK_ERR_TYPE_ERROR                105  /* TypeError */
+#define DUK_ERR_URI_ERROR                 106  /* URIError */
+
+/* Return codes for C functions (shortcut for throwing an error) */
+#define DUK_RET_UNIMPLEMENTED_ERROR       (-DUK_ERR_UNIMPLEMENTED_ERROR)
+#define DUK_RET_UNSUPPORTED_ERROR         (-DUK_ERR_UNSUPPORTED_ERROR)
+#define DUK_RET_INTERNAL_ERROR            (-DUK_ERR_INTERNAL_ERROR)
+#define DUK_RET_ALLOC_ERROR               (-DUK_ERR_ALLOC_ERROR)
+#define DUK_RET_ASSERTION_ERROR           (-DUK_ERR_ASSERTION_ERROR)
+#define DUK_RET_API_ERROR                 (-DUK_ERR_API_ERROR)
+#define DUK_RET_UNCAUGHT_ERROR            (-DUK_ERR_UNCAUGHT_ERROR)
+#define DUK_RET_ERROR                     (-DUK_ERR_ERROR)
+#define DUK_RET_EVAL_ERROR                (-DUK_ERR_EVAL_ERROR)
+#define DUK_RET_RANGE_ERROR               (-DUK_ERR_RANGE_ERROR)
+#define DUK_RET_REFERENCE_ERROR           (-DUK_ERR_REFERENCE_ERROR)
+#define DUK_RET_SYNTAX_ERROR              (-DUK_ERR_SYNTAX_ERROR)
+#define DUK_RET_TYPE_ERROR                (-DUK_ERR_TYPE_ERROR)
+#define DUK_RET_URI_ERROR                 (-DUK_ERR_URI_ERROR)
+
+/* Return codes for protected calls (duk_safe_call(), duk_pcall()) */
+#define DUK_EXEC_SUCCESS                  0
+#define DUK_EXEC_ERROR                    1
+
+/* Log levels */
+#define DUK_LOG_TRACE                     0
+#define DUK_LOG_DEBUG                     1
+#define DUK_LOG_INFO                      2
+#define DUK_LOG_WARN                      3
+#define DUK_LOG_ERROR                     4
+#define DUK_LOG_FATAL                     5
+
+/*
+ *  If no variadic macros, __FILE__ and __LINE__ are passed through globals
+ *  which is ugly and not thread safe.
+ */
+
+#ifndef DUK_API_VARIADIC_MACROS
+DUK_EXTERNAL_DECL const char *duk_api_global_filename;
+DUK_EXTERNAL_DECL duk_int_t duk_api_global_line;
+#endif
+
+/*
+ *  Context management
+ */
+
+DUK_EXTERNAL_DECL
+duk_context *duk_create_heap(duk_alloc_function alloc_func,
+                             duk_realloc_function realloc_func,
+                             duk_free_function free_func,
+                             void *heap_udata,
+                             duk_fatal_function fatal_handler);
+DUK_EXTERNAL_DECL void duk_destroy_heap(duk_context *ctx);
+
+#define duk_create_heap_default() \
+	duk_create_heap(NULL, NULL, NULL, NULL, NULL)
+
+/*
+ *  Memory management
+ *
+ *  Raw functions have no side effects (cannot trigger GC).
+ */
+
+DUK_EXTERNAL_DECL void *duk_alloc_raw(duk_context *ctx, duk_size_t size);
+DUK_EXTERNAL_DECL void duk_free_raw(duk_context *ctx, void *ptr);
+DUK_EXTERNAL_DECL void *duk_realloc_raw(duk_context *ctx, void *ptr, duk_size_t size);
+DUK_EXTERNAL_DECL void *duk_alloc(duk_context *ctx, duk_size_t size);
+DUK_EXTERNAL_DECL void duk_free(duk_context *ctx, void *ptr);
+DUK_EXTERNAL_DECL void *duk_realloc(duk_context *ctx, void *ptr, duk_size_t size);
+DUK_EXTERNAL_DECL void duk_get_memory_functions(duk_context *ctx, duk_memory_functions *out_funcs);
+DUK_EXTERNAL_DECL void duk_gc(duk_context *ctx, duk_uint_t flags);
+
+/*
+ *  Error handling
+ */
+
+DUK_API_NORETURN(DUK_EXTERNAL_DECL void duk_throw(duk_context *ctx));
+DUK_API_NORETURN(DUK_EXTERNAL_DECL void duk_fatal(duk_context *ctx, duk_errcode_t err_code, const char *err_msg));
+
+DUK_API_NORETURN(DUK_EXTERNAL_DECL void duk_error_raw(duk_context *ctx, duk_errcode_t err_code, const char *filename, duk_int_t line, const char *fmt, ...));
+
+#ifdef DUK_API_VARIADIC_MACROS
+#define duk_error(ctx,err_code,...)  \
+	duk_error_raw((ctx), (duk_errcode_t) (err_code), (const char *) (DUK_FILE_MACRO), (duk_int_t) (DUK_LINE_MACRO), __VA_ARGS__)
+#else
+DUK_API_NORETURN(DUK_EXTERNAL_DECL void duk_error_stash(duk_context *ctx, duk_errcode_t err_code, const char *fmt, ...));
+/* One problem with this macro is that expressions like the following fail
+ * to compile: "(void) duk_error(...)".  But because duk_error() is noreturn,
+ * they make little sense anyway.
+ */
+#define duk_error  \
+	(duk_api_global_filename = (const char *) (DUK_FILE_MACRO), \
+	 duk_api_global_line = (duk_int_t) (DUK_LINE_MACRO), \
+	 duk_error_stash)  /* last value is func pointer, arguments follow in parens */
+#endif
+
+DUK_API_NORETURN(DUK_EXTERNAL_DECL void duk_error_va_raw(duk_context *ctx, duk_errcode_t err_code, const char *filename, duk_int_t line, const char *fmt, va_list ap));
+#define duk_error_va(ctx,err_code,fmt,ap)  \
+	duk_error_va_raw((ctx), (duk_errcode_t) (err_code), (const char *) (DUK_FILE_MACRO), (duk_int_t) (DUK_LINE_MACRO), (fmt), (ap))
+
+/*
+ *  Other state related functions
+ */
+
+DUK_EXTERNAL_DECL duk_bool_t duk_is_strict_call(duk_context *ctx);
+DUK_EXTERNAL_DECL duk_bool_t duk_is_constructor_call(duk_context *ctx);
+
+/*
+ *  Stack management
+ */
+
+DUK_EXTERNAL_DECL duk_idx_t duk_normalize_index(duk_context *ctx, duk_idx_t index);
+DUK_EXTERNAL_DECL duk_idx_t duk_require_normalize_index(duk_context *ctx, duk_idx_t index);
+DUK_EXTERNAL_DECL duk_bool_t duk_is_valid_index(duk_context *ctx, duk_idx_t index);
+DUK_EXTERNAL_DECL void duk_require_valid_index(duk_context *ctx, duk_idx_t index);
+
+DUK_EXTERNAL_DECL duk_idx_t duk_get_top(duk_context *ctx);
+DUK_EXTERNAL_DECL void duk_set_top(duk_context *ctx, duk_idx_t index);
+DUK_EXTERNAL_DECL duk_idx_t duk_get_top_index(duk_context *ctx);
+DUK_EXTERNAL_DECL duk_idx_t duk_require_top_index(duk_context *ctx);
+
+/* Although extra/top could be an unsigned type here, using a signed type
+ * makes the API more robust to calling code calculation errors or corner
+ * cases (where caller might occasionally come up with negative values).
+ * Negative values are treated as zero, which is better than casting them
+ * to a large unsigned number.  (This principle is used elsewhere in the
+ * API too.)
+ */
+DUK_EXTERNAL_DECL duk_bool_t duk_check_stack(duk_context *ctx, duk_idx_t extra);
+DUK_EXTERNAL_DECL void duk_require_stack(duk_context *ctx, duk_idx_t extra);
+DUK_EXTERNAL_DECL duk_bool_t duk_check_stack_top(duk_context *ctx, duk_idx_t top);
+DUK_EXTERNAL_DECL void duk_require_stack_top(duk_context *ctx, duk_idx_t top);
+
+/*
+ *  Stack manipulation (other than push/pop)
+ */
+
+DUK_EXTERNAL_DECL void duk_swap(duk_context *ctx, duk_idx_t index1, duk_idx_t index2);
+DUK_EXTERNAL_DECL void duk_swap_top(duk_context *ctx, duk_idx_t index);
+DUK_EXTERNAL_DECL void duk_dup(duk_context *ctx, duk_idx_t from_index);
+DUK_EXTERNAL_DECL void duk_dup_top(duk_context *ctx);
+DUK_EXTERNAL_DECL void duk_insert(duk_context *ctx, duk_idx_t to_index);
+DUK_EXTERNAL_DECL void duk_replace(duk_context *ctx, duk_idx_t to_index);
+DUK_EXTERNAL_DECL void duk_copy(duk_context *ctx, duk_idx_t from_index, duk_idx_t to_index);
+DUK_EXTERNAL_DECL void duk_remove(duk_context *ctx, duk_idx_t index);
+DUK_EXTERNAL_DECL void duk_xcopymove_raw(duk_context *to_ctx, duk_context *from_ctx, duk_idx_t count, duk_bool_t is_copy);
+
+#define duk_xmove_top(to_ctx,from_ctx,count) \
+	duk_xcopymove_raw((to_ctx), (from_ctx), (count), 0 /*is_copy*/)
+#define duk_xcopy_top(to_ctx,from_ctx,count) \
+	duk_xcopymove_raw((to_ctx), (from_ctx), (count), 1 /*is_copy*/)
+
+/*
+ *  Push operations
+ *
+ *  Push functions return the absolute (relative to bottom of frame)
+ *  position of the pushed value for convenience.
+ *
+ *  Note: duk_dup() is technically a push.
+ */
+
+DUK_EXTERNAL_DECL void duk_push_undefined(duk_context *ctx);
+DUK_EXTERNAL_DECL void duk_push_null(duk_context *ctx);
+DUK_EXTERNAL_DECL void duk_push_boolean(duk_context *ctx, duk_bool_t val);
+DUK_EXTERNAL_DECL void duk_push_true(duk_context *ctx);
+DUK_EXTERNAL_DECL void duk_push_false(duk_context *ctx);
+DUK_EXTERNAL_DECL void duk_push_number(duk_context *ctx, duk_double_t val);
+DUK_EXTERNAL_DECL void duk_push_nan(duk_context *ctx);
+DUK_EXTERNAL_DECL void duk_push_int(duk_context *ctx, duk_int_t val);
+DUK_EXTERNAL_DECL void duk_push_uint(duk_context *ctx, duk_uint_t val);
+DUK_EXTERNAL_DECL const char *duk_push_string(duk_context *ctx, const char *str);
+DUK_EXTERNAL_DECL const char *duk_push_lstring(duk_context *ctx, const char *str, duk_size_t len);
+DUK_EXTERNAL_DECL void duk_push_pointer(duk_context *ctx, void *p);
+DUK_EXTERNAL_DECL const char *duk_push_sprintf(duk_context *ctx, const char *fmt, ...);
+DUK_EXTERNAL_DECL const char *duk_push_vsprintf(duk_context *ctx, const char *fmt, va_list ap);
+
+DUK_EXTERNAL_DECL const char *duk_push_string_file_raw(duk_context *ctx, const char *path, duk_uint_t flags);
+#define duk_push_string_file(ctx,path) \
+	duk_push_string_file_raw((ctx), (path), 0)
+
+DUK_EXTERNAL_DECL void duk_push_this(duk_context *ctx);
+DUK_EXTERNAL_DECL void duk_push_current_function(duk_context *ctx);
+DUK_EXTERNAL_DECL void duk_push_current_thread(duk_context *ctx);
+DUK_EXTERNAL_DECL void duk_push_global_object(duk_context *ctx);
+DUK_EXTERNAL_DECL void duk_push_heap_stash(duk_context *ctx);
+DUK_EXTERNAL_DECL void duk_push_global_stash(duk_context *ctx);
+DUK_EXTERNAL_DECL void duk_push_thread_stash(duk_context *ctx, duk_context *target_ctx);
+
+DUK_EXTERNAL_DECL duk_idx_t duk_push_object(duk_context *ctx);
+DUK_EXTERNAL_DECL duk_idx_t duk_push_array(duk_context *ctx);
+DUK_EXTERNAL_DECL duk_idx_t duk_push_c_function(duk_context *ctx, duk_c_function func, duk_idx_t nargs);
+DUK_EXTERNAL_DECL duk_idx_t duk_push_c_lightfunc(duk_context *ctx, duk_c_function func, duk_idx_t nargs, duk_idx_t length, duk_int_t magic);
+DUK_EXTERNAL_DECL duk_idx_t duk_push_thread_raw(duk_context *ctx, duk_uint_t flags);
+
+#define duk_push_thread(ctx) \
+	duk_push_thread_raw((ctx), 0 /*flags*/)
+
+#define duk_push_thread_new_globalenv(ctx) \
+	duk_push_thread_raw((ctx), DUK_THREAD_NEW_GLOBAL_ENV /*flags*/)
+
+DUK_EXTERNAL_DECL duk_idx_t duk_push_error_object_raw(duk_context *ctx, duk_errcode_t err_code, const char *filename, duk_int_t line, const char *fmt, ...);
+
+#ifdef DUK_API_VARIADIC_MACROS
+#define duk_push_error_object(ctx,err_code,...)  \
+	duk_push_error_object_raw((ctx), (err_code), (const char *) (DUK_FILE_MACRO), (duk_int_t) (DUK_LINE_MACRO), __VA_ARGS__)
+#else
+DUK_EXTERNAL_DECL duk_idx_t duk_push_error_object_stash(duk_context *ctx, duk_errcode_t err_code, const char *fmt, ...);
+/* Note: parentheses are required so that the comma expression works in assignments. */
+#define duk_push_error_object  \
+	(duk_api_global_filename = (const char *) (DUK_FILE_MACRO), \
+	 duk_api_global_line = (duk_int_t) (DUK_LINE_MACRO), \
+	 duk_push_error_object_stash)  /* last value is func pointer, arguments follow in parens */
+#endif
+
+DUK_EXTERNAL_DECL duk_idx_t duk_push_error_object_va_raw(duk_context *ctx, duk_errcode_t err_code, const char *filename, duk_int_t line, const char *fmt, va_list ap);
+#define duk_push_error_object_va(ctx,err_code,fmt,ap)  \
+	duk_push_error_object_va_raw((ctx), (err_code), (const char *) (DUK_FILE_MACRO), (duk_int_t) (DUK_LINE_MACRO), (fmt), (ap))
+
+#define DUK_BUF_FLAG_DYNAMIC   (1 << 0)    /* internal flag: dynamic buffer */
+#define DUK_BUF_FLAG_EXTERNAL  (1 << 1)    /* internal flag: external buffer */
+#define DUK_BUF_FLAG_NOZERO    (1 << 2)    /* internal flag: don't zero allocated buffer */
+
+DUK_EXTERNAL_DECL void *duk_push_buffer_raw(duk_context *ctx, duk_size_t size, duk_small_uint_t flags);
+
+#define duk_push_buffer(ctx,size,dynamic) \
+	duk_push_buffer_raw((ctx), (size), (dynamic) ? DUK_BUF_FLAG_DYNAMIC : 0)
+#define duk_push_fixed_buffer(ctx,size) \
+	duk_push_buffer_raw((ctx), (size), 0 /*flags*/)
+#define duk_push_dynamic_buffer(ctx,size) \
+	duk_push_buffer_raw((ctx), (size), DUK_BUF_FLAG_DYNAMIC /*flags*/)
+#define duk_push_external_buffer(ctx) \
+	((void) duk_push_buffer_raw((ctx), 0, DUK_BUF_FLAG_DYNAMIC | DUK_BUF_FLAG_EXTERNAL))
+
+#define DUK_BUFOBJ_CREATE_ARRBUF       (1 << 4)  /* internal flag: create backing ArrayBuffer; keep in one byte */
+#define DUK_BUFOBJ_DUKTAPE_BUFFER      0
+#define DUK_BUFOBJ_NODEJS_BUFFER       1
+#define DUK_BUFOBJ_ARRAYBUFFER         2
+#define DUK_BUFOBJ_DATAVIEW            (3 | DUK_BUFOBJ_CREATE_ARRBUF)
+#define DUK_BUFOBJ_INT8ARRAY           (4 | DUK_BUFOBJ_CREATE_ARRBUF)
+#define DUK_BUFOBJ_UINT8ARRAY          (5 | DUK_BUFOBJ_CREATE_ARRBUF)
+#define DUK_BUFOBJ_UINT8CLAMPEDARRAY   (6 | DUK_BUFOBJ_CREATE_ARRBUF)
+#define DUK_BUFOBJ_INT16ARRAY          (7 | DUK_BUFOBJ_CREATE_ARRBUF)
+#define DUK_BUFOBJ_UINT16ARRAY         (8 | DUK_BUFOBJ_CREATE_ARRBUF)
+#define DUK_BUFOBJ_INT32ARRAY          (9 | DUK_BUFOBJ_CREATE_ARRBUF)
+#define DUK_BUFOBJ_UINT32ARRAY         (10 | DUK_BUFOBJ_CREATE_ARRBUF)
+#define DUK_BUFOBJ_FLOAT32ARRAY        (11 | DUK_BUFOBJ_CREATE_ARRBUF)
+#define DUK_BUFOBJ_FLOAT64ARRAY        (12 | DUK_BUFOBJ_CREATE_ARRBUF)
+
+DUK_EXTERNAL_DECL void duk_push_buffer_object(duk_context *ctx, duk_idx_t idx_buffer, duk_size_t byte_offset, duk_size_t byte_length, duk_uint_t flags);
+
+DUK_EXTERNAL_DECL duk_idx_t duk_push_heapptr(duk_context *ctx, void *ptr);
+
+/*
+ *  Pop operations
+ */
+
+DUK_EXTERNAL_DECL void duk_pop(duk_context *ctx);
+DUK_EXTERNAL_DECL void duk_pop_n(duk_context *ctx, duk_idx_t count);
+DUK_EXTERNAL_DECL void duk_pop_2(duk_context *ctx);
+DUK_EXTERNAL_DECL void duk_pop_3(duk_context *ctx);
+
+/*
+ *  Type checks
+ *
+ *  duk_is_none(), which would indicate whether index it outside of stack,
+ *  is not needed; duk_is_valid_index() gives the same information.
+ */
+
+DUK_EXTERNAL_DECL duk_int_t duk_get_type(duk_context *ctx, duk_idx_t index);
+DUK_EXTERNAL_DECL duk_bool_t duk_check_type(duk_context *ctx, duk_idx_t index, duk_int_t type);
+DUK_EXTERNAL_DECL duk_uint_t duk_get_type_mask(duk_context *ctx, duk_idx_t index);
+DUK_EXTERNAL_DECL duk_bool_t duk_check_type_mask(duk_context *ctx, duk_idx_t index, duk_uint_t mask);
+
+DUK_EXTERNAL_DECL duk_bool_t duk_is_undefined(duk_context *ctx, duk_idx_t index);
+DUK_EXTERNAL_DECL duk_bool_t duk_is_null(duk_context *ctx, duk_idx_t index);
+DUK_EXTERNAL_DECL duk_bool_t duk_is_null_or_undefined(duk_context *ctx, duk_idx_t index);
+DUK_EXTERNAL_DECL duk_bool_t duk_is_boolean(duk_context *ctx, duk_idx_t index);
+DUK_EXTERNAL_DECL duk_bool_t duk_is_number(duk_context *ctx, duk_idx_t index);
+DUK_EXTERNAL_DECL duk_bool_t duk_is_nan(duk_context *ctx, duk_idx_t index);
+DUK_EXTERNAL_DECL duk_bool_t duk_is_string(duk_context *ctx, duk_idx_t index);
+DUK_EXTERNAL_DECL duk_bool_t duk_is_object(duk_context *ctx, duk_idx_t index);
+DUK_EXTERNAL_DECL duk_bool_t duk_is_buffer(duk_context *ctx, duk_idx_t index);
+DUK_EXTERNAL_DECL duk_bool_t duk_is_pointer(duk_context *ctx, duk_idx_t index);
+DUK_EXTERNAL_DECL duk_bool_t duk_is_lightfunc(duk_context *ctx, duk_idx_t index);
+
+DUK_EXTERNAL_DECL duk_bool_t duk_is_array(duk_context *ctx, duk_idx_t index);
+DUK_EXTERNAL_DECL duk_bool_t duk_is_function(duk_context *ctx, duk_idx_t index);
+DUK_EXTERNAL_DECL duk_bool_t duk_is_c_function(duk_context *ctx, duk_idx_t index);
+DUK_EXTERNAL_DECL duk_bool_t duk_is_ecmascript_function(duk_context *ctx, duk_idx_t index);
+DUK_EXTERNAL_DECL duk_bool_t duk_is_bound_function(duk_context *ctx, duk_idx_t index);
+DUK_EXTERNAL_DECL duk_bool_t duk_is_thread(duk_context *ctx, duk_idx_t index);
+
+#define duk_is_callable(ctx,index) \
+	duk_is_function((ctx), (index))
+DUK_EXTERNAL_DECL duk_bool_t duk_is_dynamic_buffer(duk_context *ctx, duk_idx_t index);
+DUK_EXTERNAL_DECL duk_bool_t duk_is_fixed_buffer(duk_context *ctx, duk_idx_t index);
+DUK_EXTERNAL_DECL duk_bool_t duk_is_external_buffer(duk_context *ctx, duk_idx_t index);
+
+#define duk_is_primitive(ctx,index) \
+	duk_check_type_mask((ctx), (index), DUK_TYPE_MASK_UNDEFINED | \
+	                                    DUK_TYPE_MASK_NULL | \
+	                                    DUK_TYPE_MASK_BOOLEAN | \
+	                                    DUK_TYPE_MASK_NUMBER | \
+	                                    DUK_TYPE_MASK_STRING | \
+	                                    DUK_TYPE_MASK_BUFFER | \
+	                                    DUK_TYPE_MASK_POINTER | \
+	                                    DUK_TYPE_MASK_LIGHTFUNC)
+
+#define duk_is_object_coercible(ctx,index) \
+	duk_check_type_mask((ctx), (index), DUK_TYPE_MASK_BOOLEAN | \
+	                                    DUK_TYPE_MASK_NUMBER | \
+	                                    DUK_TYPE_MASK_STRING | \
+	                                    DUK_TYPE_MASK_OBJECT | \
+	                                    DUK_TYPE_MASK_BUFFER | \
+	                                    DUK_TYPE_MASK_POINTER | \
+	                                    DUK_TYPE_MASK_LIGHTFUNC)
+
+DUK_EXTERNAL_DECL duk_errcode_t duk_get_error_code(duk_context *ctx, duk_idx_t index);
+#define duk_is_error(ctx,index) \
+	(duk_get_error_code((ctx), (index)) != 0)
+#define duk_is_eval_error(ctx,index) \
+	(duk_get_error_code((ctx), (index)) == DUK_ERR_EVAL_ERROR)
+#define duk_is_range_error(ctx,index) \
+	(duk_get_error_code((ctx), (index)) == DUK_ERR_RANGE_ERROR)
+#define duk_is_reference_error(ctx,index) \
+	(duk_get_error_code((ctx), (index)) == DUK_ERR_REFERENCE_ERROR)
+#define duk_is_syntax_error(ctx,index) \
+	(duk_get_error_code((ctx), (index)) == DUK_ERR_SYNTAX_ERROR)
+#define duk_is_type_error(ctx,index) \
+	(duk_get_error_code((ctx), (index)) == DUK_ERR_TYPE_ERROR)
+#define duk_is_uri_error(ctx,index) \
+	(duk_get_error_code((ctx), (index)) == DUK_ERR_URI_ERROR)
+
+/*
+ *  Get operations: no coercion, returns default value for invalid
+ *  indices and invalid value types.
+ *
+ *  duk_get_undefined() and duk_get_null() would be pointless and
+ *  are not included.
+ */
+
+DUK_EXTERNAL_DECL duk_bool_t duk_get_boolean(duk_context *ctx, duk_idx_t index);
+DUK_EXTERNAL_DECL duk_double_t duk_get_number(duk_context *ctx, duk_idx_t index);
+DUK_EXTERNAL_DECL duk_int_t duk_get_int(duk_context *ctx, duk_idx_t index);
+DUK_EXTERNAL_DECL duk_uint_t duk_get_uint(duk_context *ctx, duk_idx_t index);
+DUK_EXTERNAL_DECL const char *duk_get_string(duk_context *ctx, duk_idx_t index);
+DUK_EXTERNAL_DECL const char *duk_get_lstring(duk_context *ctx, duk_idx_t index, duk_size_t *out_len);
+DUK_EXTERNAL_DECL void *duk_get_buffer(duk_context *ctx, duk_idx_t index, duk_size_t *out_size);
+DUK_EXTERNAL_DECL void *duk_get_buffer_data(duk_context *ctx, duk_idx_t index, duk_size_t *out_size);
+DUK_EXTERNAL_DECL void *duk_get_pointer(duk_context *ctx, duk_idx_t index);
+DUK_EXTERNAL_DECL duk_c_function duk_get_c_function(duk_context *ctx, duk_idx_t index);
+DUK_EXTERNAL_DECL duk_context *duk_get_context(duk_context *ctx, duk_idx_t index);
+DUK_EXTERNAL_DECL void *duk_get_heapptr(duk_context *ctx, duk_idx_t index);
+DUK_EXTERNAL_DECL duk_size_t duk_get_length(duk_context *ctx, duk_idx_t index);
+
+/*
+ *  Require operations: no coercion, throw error if index or type
+ *  is incorrect.  No defaulting.
+ */
+
+#define duk_require_type_mask(ctx,index,mask) \
+	((void) duk_check_type_mask((ctx), (index), (mask) | DUK_TYPE_MASK_THROW))
+
+DUK_EXTERNAL_DECL void duk_require_undefined(duk_context *ctx, duk_idx_t index);
+DUK_EXTERNAL_DECL void duk_require_null(duk_context *ctx, duk_idx_t index);
+DUK_EXTERNAL_DECL duk_bool_t duk_require_boolean(duk_context *ctx, duk_idx_t index);
+DUK_EXTERNAL_DECL duk_double_t duk_require_number(duk_context *ctx, duk_idx_t index);
+DUK_EXTERNAL_DECL duk_int_t duk_require_int(duk_context *ctx, duk_idx_t index);
+DUK_EXTERNAL_DECL duk_uint_t duk_require_uint(duk_context *ctx, duk_idx_t index);
+DUK_EXTERNAL_DECL const char *duk_require_string(duk_context *ctx, duk_idx_t index);
+DUK_EXTERNAL_DECL const char *duk_require_lstring(duk_context *ctx, duk_idx_t index, duk_size_t *out_len);
+DUK_EXTERNAL_DECL void *duk_require_buffer(duk_context *ctx, duk_idx_t index, duk_size_t *out_size);
+DUK_EXTERNAL_DECL void *duk_require_buffer_data(duk_context *ctx, duk_idx_t index, duk_size_t *out_size);
+DUK_EXTERNAL_DECL void *duk_require_pointer(duk_context *ctx, duk_idx_t index);
+DUK_EXTERNAL_DECL duk_c_function duk_require_c_function(duk_context *ctx, duk_idx_t index);
+DUK_EXTERNAL_DECL duk_context *duk_require_context(duk_context *ctx, duk_idx_t index);
+DUK_EXTERNAL_DECL void duk_require_function(duk_context *ctx, duk_idx_t index);
+#define duk_require_callable(ctx,index) \
+	duk_require_function((ctx), (index))
+DUK_EXTERNAL_DECL void *duk_require_heapptr(duk_context *ctx, duk_idx_t index);
+
+#define duk_require_object_coercible(ctx,index) \
+	((void) duk_check_type_mask((ctx), (index), DUK_TYPE_MASK_BOOLEAN | \
+	                                            DUK_TYPE_MASK_NUMBER | \
+	                                            DUK_TYPE_MASK_STRING | \
+	                                            DUK_TYPE_MASK_OBJECT | \
+	                                            DUK_TYPE_MASK_BUFFER | \
+	                                            DUK_TYPE_MASK_POINTER | \
+	                                            DUK_TYPE_MASK_LIGHTFUNC | \
+	                                            DUK_TYPE_MASK_THROW))
+
+/*
+ *  Coercion operations: in-place coercion, return coerced value where
+ *  applicable.  If index is invalid, throw error.  Some coercions may
+ *  throw an expected error (e.g. from a toString() or valueOf() call)
+ *  or an internal error (e.g. from out of memory).
+ */
+
+DUK_EXTERNAL_DECL void duk_to_undefined(duk_context *ctx, duk_idx_t index);
+DUK_EXTERNAL_DECL void duk_to_null(duk_context *ctx, duk_idx_t index);
+DUK_EXTERNAL_DECL duk_bool_t duk_to_boolean(duk_context *ctx, duk_idx_t index);
+DUK_EXTERNAL_DECL duk_double_t duk_to_number(duk_context *ctx, duk_idx_t index);
+DUK_EXTERNAL_DECL duk_int_t duk_to_int(duk_context *ctx, duk_idx_t index);
+DUK_EXTERNAL_DECL duk_uint_t duk_to_uint(duk_context *ctx, duk_idx_t index);
+DUK_EXTERNAL_DECL duk_int32_t duk_to_int32(duk_context *ctx, duk_idx_t index);
+DUK_EXTERNAL_DECL duk_uint32_t duk_to_uint32(duk_context *ctx, duk_idx_t index);
+DUK_EXTERNAL_DECL duk_uint16_t duk_to_uint16(duk_context *ctx, duk_idx_t index);
+DUK_EXTERNAL_DECL const char *duk_to_string(duk_context *ctx, duk_idx_t index);
+DUK_EXTERNAL_DECL const char *duk_to_lstring(duk_context *ctx, duk_idx_t index, duk_size_t *out_len);
+DUK_EXTERNAL_DECL void *duk_to_buffer_raw(duk_context *ctx, duk_idx_t index, duk_size_t *out_size, duk_uint_t flags);
+DUK_EXTERNAL_DECL void *duk_to_pointer(duk_context *ctx, duk_idx_t index);
+DUK_EXTERNAL_DECL void duk_to_object(duk_context *ctx, duk_idx_t index);
+DUK_EXTERNAL_DECL void duk_to_defaultvalue(duk_context *ctx, duk_idx_t index, duk_int_t hint);
+DUK_EXTERNAL_DECL void duk_to_primitive(duk_context *ctx, duk_idx_t index, duk_int_t hint);
+
+#define DUK_BUF_MODE_FIXED      0   /* internal: request fixed buffer result */
+#define DUK_BUF_MODE_DYNAMIC    1   /* internal: request dynamic buffer result */
+#define DUK_BUF_MODE_DONTCARE   2   /* internal: don't care about fixed/dynamic nature */
+
+#define duk_to_buffer(ctx,index,out_size) \
+	duk_to_buffer_raw((ctx), (index), (out_size), DUK_BUF_MODE_DONTCARE)
+#define duk_to_fixed_buffer(ctx,index,out_size) \
+	duk_to_buffer_raw((ctx), (index), (out_size), DUK_BUF_MODE_FIXED)
+#define duk_to_dynamic_buffer(ctx,index,out_size) \
+	duk_to_buffer_raw((ctx), (index), (out_size), DUK_BUF_MODE_DYNAMIC)
+
+/* safe variants of a few coercion operations */
+DUK_EXTERNAL_DECL const char *duk_safe_to_lstring(duk_context *ctx, duk_idx_t index, duk_size_t *out_len);
+#define duk_safe_to_string(ctx,index) \
+	duk_safe_to_lstring((ctx), (index), NULL)
+
+/*
+ *  Misc conversion
+ */
+
+DUK_EXTERNAL_DECL const char *duk_base64_encode(duk_context *ctx, duk_idx_t index);
+DUK_EXTERNAL_DECL void duk_base64_decode(duk_context *ctx, duk_idx_t index);
+DUK_EXTERNAL_DECL const char *duk_hex_encode(duk_context *ctx, duk_idx_t index);
+DUK_EXTERNAL_DECL void duk_hex_decode(duk_context *ctx, duk_idx_t index);
+DUK_EXTERNAL_DECL const char *duk_json_encode(duk_context *ctx, duk_idx_t index);
+DUK_EXTERNAL_DECL void duk_json_decode(duk_context *ctx, duk_idx_t index);
+
+/*
+ *  Buffer
+ */
+
+DUK_EXTERNAL_DECL void *duk_resize_buffer(duk_context *ctx, duk_idx_t index, duk_size_t new_size);
+DUK_EXTERNAL_DECL void *duk_steal_buffer(duk_context *ctx, duk_idx_t index, duk_size_t *out_size);
+DUK_EXTERNAL_DECL void duk_config_buffer(duk_context *ctx, duk_idx_t index, void *ptr, duk_size_t len);
+
+/*
+ *  Property access
+ *
+ *  The basic function assumes key is on stack.  The _string variant takes
+ *  a C string as a property name, while the _index variant takes an array
+ *  index as a property name (e.g. 123 is equivalent to the key "123").
+ */
+
+DUK_EXTERNAL_DECL duk_bool_t duk_get_prop(duk_context *ctx, duk_idx_t obj_index);
+DUK_EXTERNAL_DECL duk_bool_t duk_get_prop_string(duk_context *ctx, duk_idx_t obj_index, const char *key);
+DUK_EXTERNAL_DECL duk_bool_t duk_get_prop_index(duk_context *ctx, duk_idx_t obj_index, duk_uarridx_t arr_index);
+DUK_EXTERNAL_DECL duk_bool_t duk_put_prop(duk_context *ctx, duk_idx_t obj_index);
+DUK_EXTERNAL_DECL duk_bool_t duk_put_prop_string(duk_context *ctx, duk_idx_t obj_index, const char *key);
+DUK_EXTERNAL_DECL duk_bool_t duk_put_prop_index(duk_context *ctx, duk_idx_t obj_index, duk_uarridx_t arr_index);
+DUK_EXTERNAL_DECL duk_bool_t duk_del_prop(duk_context *ctx, duk_idx_t obj_index);
+DUK_EXTERNAL_DECL duk_bool_t duk_del_prop_string(duk_context *ctx, duk_idx_t obj_index, const char *key);
+DUK_EXTERNAL_DECL duk_bool_t duk_del_prop_index(duk_context *ctx, duk_idx_t obj_index, duk_uarridx_t arr_index);
+DUK_EXTERNAL_DECL duk_bool_t duk_has_prop(duk_context *ctx, duk_idx_t obj_index);
+DUK_EXTERNAL_DECL duk_bool_t duk_has_prop_string(duk_context *ctx, duk_idx_t obj_index, const char *key);
+DUK_EXTERNAL_DECL duk_bool_t duk_has_prop_index(duk_context *ctx, duk_idx_t obj_index, duk_uarridx_t arr_index);
+DUK_EXTERNAL_DECL void duk_def_prop(duk_context *ctx, duk_idx_t obj_index, duk_uint_t flags);
+
+DUK_EXTERNAL_DECL duk_bool_t duk_get_global_string(duk_context *ctx, const char *key);
+DUK_EXTERNAL_DECL duk_bool_t duk_put_global_string(duk_context *ctx, const char *key);
+
+/*
+ *  Object prototype
+ */
+
+DUK_EXTERNAL_DECL void duk_get_prototype(duk_context *ctx, duk_idx_t index);
+DUK_EXTERNAL_DECL void duk_set_prototype(duk_context *ctx, duk_idx_t index);
+
+/*
+ *  Object finalizer
+ */
+
+DUK_EXTERNAL_DECL void duk_get_finalizer(duk_context *ctx, duk_idx_t index);
+DUK_EXTERNAL_DECL void duk_set_finalizer(duk_context *ctx, duk_idx_t index);
+
+/*
+ *  Global object
+ */
+
+DUK_EXTERNAL_DECL void duk_set_global_object(duk_context *ctx);
+
+/*
+ *  Duktape/C function magic value
+ */
+
+DUK_EXTERNAL_DECL duk_int_t duk_get_magic(duk_context *ctx, duk_idx_t index);
+DUK_EXTERNAL_DECL void duk_set_magic(duk_context *ctx, duk_idx_t index, duk_int_t magic);
+DUK_EXTERNAL_DECL duk_int_t duk_get_current_magic(duk_context *ctx);
+
+/*
+ *  Module helpers: put multiple function or constant properties
+ */
+
+DUK_EXTERNAL_DECL void duk_put_function_list(duk_context *ctx, duk_idx_t obj_index, const duk_function_list_entry *funcs);
+DUK_EXTERNAL_DECL void duk_put_number_list(duk_context *ctx, duk_idx_t obj_index, const duk_number_list_entry *numbers);
+
+/*
+ *  Variable access
+ */
+
+/* XXX: These calls are incomplete and not usable now.  They are not (yet)
+ * part of the public API.
+ */
+DUK_EXTERNAL_DECL void duk_get_var(duk_context *ctx);
+DUK_EXTERNAL_DECL void duk_put_var(duk_context *ctx);
+DUK_EXTERNAL_DECL duk_bool_t duk_del_var(duk_context *ctx);
+DUK_EXTERNAL_DECL duk_bool_t duk_has_var(duk_context *ctx);
+
+/*
+ *  Object operations
+ */
+
+DUK_EXTERNAL_DECL void duk_compact(duk_context *ctx, duk_idx_t obj_index);
+DUK_EXTERNAL_DECL void duk_enum(duk_context *ctx, duk_idx_t obj_index, duk_uint_t enum_flags);
+DUK_EXTERNAL_DECL duk_bool_t duk_next(duk_context *ctx, duk_idx_t enum_index, duk_bool_t get_value);
+
+/*
+ *  String manipulation
+ */
+
+DUK_EXTERNAL_DECL void duk_concat(duk_context *ctx, duk_idx_t count);
+DUK_EXTERNAL_DECL void duk_join(duk_context *ctx, duk_idx_t count);
+DUK_EXTERNAL_DECL void duk_decode_string(duk_context *ctx, duk_idx_t index, duk_decode_char_function callback, void *udata);
+DUK_EXTERNAL_DECL void duk_map_string(duk_context *ctx, duk_idx_t index, duk_map_char_function callback, void *udata);
+DUK_EXTERNAL_DECL void duk_substring(duk_context *ctx, duk_idx_t index, duk_size_t start_char_offset, duk_size_t end_char_offset);
+DUK_EXTERNAL_DECL void duk_trim(duk_context *ctx, duk_idx_t index);
+DUK_EXTERNAL_DECL duk_codepoint_t duk_char_code_at(duk_context *ctx, duk_idx_t index, duk_size_t char_offset);
+
+/*
+ *  Ecmascript operators
+ */
+
+DUK_EXTERNAL_DECL duk_bool_t duk_equals(duk_context *ctx, duk_idx_t index1, duk_idx_t index2);
+DUK_EXTERNAL_DECL duk_bool_t duk_strict_equals(duk_context *ctx, duk_idx_t index1, duk_idx_t index2);
+DUK_EXTERNAL_DECL duk_bool_t duk_instanceof(duk_context *ctx, duk_idx_t index1, duk_idx_t index2);
+
+/*
+ *  Function (method) calls
+ */
+
+DUK_EXTERNAL_DECL void duk_call(duk_context *ctx, duk_idx_t nargs);
+DUK_EXTERNAL_DECL void duk_call_method(duk_context *ctx, duk_idx_t nargs);
+DUK_EXTERNAL_DECL void duk_call_prop(duk_context *ctx, duk_idx_t obj_index, duk_idx_t nargs);
+DUK_EXTERNAL_DECL duk_int_t duk_pcall(duk_context *ctx, duk_idx_t nargs);
+DUK_EXTERNAL_DECL duk_int_t duk_pcall_method(duk_context *ctx, duk_idx_t nargs);
+DUK_EXTERNAL_DECL duk_int_t duk_pcall_prop(duk_context *ctx, duk_idx_t obj_index, duk_idx_t nargs);
+DUK_EXTERNAL_DECL void duk_new(duk_context *ctx, duk_idx_t nargs);
+DUK_EXTERNAL_DECL duk_int_t duk_pnew(duk_context *ctx, duk_idx_t nargs);
+DUK_EXTERNAL_DECL duk_int_t duk_safe_call(duk_context *ctx, duk_safe_call_function func, duk_idx_t nargs, duk_idx_t nrets);
+
+/*
+ *  Thread management
+ */
+
+/* There are currently no native functions to yield/resume, due to the internal
+ * limitations on coroutine handling.  These will be added later.
+ */
+
+/*
+ *  Compilation and evaluation
+ */
+
+DUK_EXTERNAL_DECL duk_int_t duk_eval_raw(duk_context *ctx, const char *src_buffer, duk_size_t src_length, duk_uint_t flags);
+DUK_EXTERNAL_DECL duk_int_t duk_compile_raw(duk_context *ctx, const char *src_buffer, duk_size_t src_length, duk_uint_t flags);
+
+/* plain */
+#define duk_eval(ctx)  \
+	((void) duk_eval_raw((ctx), NULL, 0, 2 /*args*/ | DUK_COMPILE_EVAL | DUK_COMPILE_NOFILENAME))
+
+#define duk_eval_noresult(ctx)  \
+	((void) duk_eval_raw((ctx), NULL, 0, 2 /*args*/ | DUK_COMPILE_EVAL | DUK_COMPILE_NORESULT | DUK_COMPILE_NOFILENAME))
+
+#define duk_peval(ctx)  \
+	(duk_eval_raw((ctx), NULL, 0, 2 /*args*/ | DUK_COMPILE_EVAL | DUK_COMPILE_SAFE | DUK_COMPILE_NOFILENAME))
+
+#define duk_peval_noresult(ctx)  \
+	(duk_eval_raw((ctx), NULL, 0, 2 /*args*/ | DUK_COMPILE_EVAL | DUK_COMPILE_SAFE | DUK_COMPILE_NORESULT | DUK_COMPILE_NOFILENAME))
+
+#define duk_compile(ctx,flags)  \
+	((void) duk_compile_raw((ctx), NULL, 0, 3 /*args*/ | (flags)))
+
+#define duk_pcompile(ctx,flags)  \
+	(duk_compile_raw((ctx), NULL, 0, 3 /*args*/ | (flags) | DUK_COMPILE_SAFE))
+
+/* string */
+#define duk_eval_string(ctx,src)  \
+	((void) duk_eval_raw((ctx), (src), 0, 1 /*args*/ | DUK_COMPILE_EVAL | DUK_COMPILE_NOSOURCE | DUK_COMPILE_STRLEN | DUK_COMPILE_NOFILENAME))
+
+#define duk_eval_string_noresult(ctx,src)  \
+	((void) duk_eval_raw((ctx), (src), 0, 1 /*args*/ | DUK_COMPILE_EVAL | DUK_COMPILE_NOSOURCE | DUK_COMPILE_STRLEN | DUK_COMPILE_NORESULT | DUK_COMPILE_NOFILENAME))
+
+#define duk_peval_string(ctx,src)  \
+	(duk_eval_raw((ctx), (src), 0, 1 /*args*/ | DUK_COMPILE_EVAL | DUK_COMPILE_SAFE | DUK_COMPILE_NOSOURCE | DUK_COMPILE_STRLEN | DUK_COMPILE_NOFILENAME))
+
+#define duk_peval_string_noresult(ctx,src)  \
+	(duk_eval_raw((ctx), (src), 0, 1 /*args*/ | DUK_COMPILE_EVAL | DUK_COMPILE_SAFE | DUK_COMPILE_NOSOURCE | DUK_COMPILE_STRLEN | DUK_COMPILE_NORESULT | DUK_COMPILE_NOFILENAME))
+
+#define duk_compile_string(ctx,flags,src)  \
+	((void) duk_compile_raw((ctx), (src), 0, 1 /*args*/ | (flags) | DUK_COMPILE_NOSOURCE | DUK_COMPILE_STRLEN | DUK_COMPILE_NOFILENAME))
+
+#define duk_compile_string_filename(ctx,flags,src)  \
+	((void) duk_compile_raw((ctx), (src), 0, 2 /*args*/ | (flags) | DUK_COMPILE_NOSOURCE | DUK_COMPILE_STRLEN))
+
+#define duk_pcompile_string(ctx,flags,src)  \
+	(duk_compile_raw((ctx), (src), 0, 1 /*args*/ | (flags) | DUK_COMPILE_SAFE | DUK_COMPILE_NOSOURCE | DUK_COMPILE_STRLEN | DUK_COMPILE_NOFILENAME))
+
+#define duk_pcompile_string_filename(ctx,flags,src)  \
+	(duk_compile_raw((ctx), (src), 0, 2 /*args*/ | (flags) | DUK_COMPILE_SAFE | DUK_COMPILE_NOSOURCE | DUK_COMPILE_STRLEN))
+
+/* lstring */
+#define duk_eval_lstring(ctx,buf,len)  \
+	((void) duk_eval_raw((ctx), buf, len, 1 /*args*/ | DUK_COMPILE_EVAL | DUK_COMPILE_NOSOURCE | DUK_COMPILE_NOFILENAME))
+
+#define duk_eval_lstring_noresult(ctx,buf,len)  \
+	((void) duk_eval_raw((ctx), buf, len, 1 /*args*/ | DUK_COMPILE_EVAL | DUK_COMPILE_NOSOURCE | DUK_COMPILE_NORESULT | DUK_COMPILE_NOFILENAME))
+
+#define duk_peval_lstring(ctx,buf,len)  \
+	(duk_eval_raw((ctx), buf, len, 1 /*args*/ | DUK_COMPILE_EVAL | DUK_COMPILE_NOSOURCE | DUK_COMPILE_SAFE | DUK_COMPILE_NOFILENAME))
+
+#define duk_peval_lstring_noresult(ctx,buf,len)  \
+	(duk_eval_raw((ctx), buf, len, 1 /*args*/ | DUK_COMPILE_EVAL | DUK_COMPILE_SAFE | DUK_COMPILE_NOSOURCE | DUK_COMPILE_NORESULT | DUK_COMPILE_NOFILENAME))
+
+#define duk_compile_lstring(ctx,flags,buf,len)  \
+	((void) duk_compile_raw((ctx), buf, len, 1 /*args*/ | (flags) | DUK_COMPILE_NOSOURCE | DUK_COMPILE_NOFILENAME))
+
+#define duk_compile_lstring_filename(ctx,flags,buf,len)  \
+	((void) duk_compile_raw((ctx), buf, len, 2 /*args*/ | (flags) | DUK_COMPILE_NOSOURCE))
+
+#define duk_pcompile_lstring(ctx,flags,buf,len)  \
+	(duk_compile_raw((ctx), buf, len, 1 /*args*/ | (flags) | DUK_COMPILE_SAFE | DUK_COMPILE_NOSOURCE | DUK_COMPILE_NOFILENAME))
+
+#define duk_pcompile_lstring_filename(ctx,flags,buf,len)  \
+	(duk_compile_raw((ctx), buf, len, 2 /*args*/ | (flags) | DUK_COMPILE_SAFE | DUK_COMPILE_NOSOURCE))
+
+/* file */
+#define duk_eval_file(ctx,path)  \
+	((void) duk_push_string_file_raw((ctx), (path), 0), \
+	 (void) duk_push_string((ctx), (path)), \
+	 (void) duk_eval_raw((ctx), NULL, 0, 3 /*args*/ | DUK_COMPILE_EVAL))
+
+#define duk_eval_file_noresult(ctx,path)  \
+	((void) duk_push_string_file_raw((ctx), (path), 0), \
+	 (void) duk_push_string((ctx), (path)), \
+	 (void) duk_eval_raw((ctx), NULL, 0, 3 /*args*/ | DUK_COMPILE_EVAL | DUK_COMPILE_NORESULT))
+
+#define duk_peval_file(ctx,path)  \
+	((void) duk_push_string_file_raw((ctx), (path), DUK_STRING_PUSH_SAFE), \
+	 (void) duk_push_string((ctx), (path)), \
+	 duk_eval_raw((ctx), NULL, 0, 3 /*args*/ | DUK_COMPILE_EVAL | DUK_COMPILE_SAFE))
+
+#define duk_peval_file_noresult(ctx,path)  \
+	((void) duk_push_string_file_raw((ctx), (path), DUK_STRING_PUSH_SAFE), \
+	 (void) duk_push_string((ctx), (path)), \
+	 duk_eval_raw((ctx), NULL, 0, 3 /*args*/ | DUK_COMPILE_EVAL | DUK_COMPILE_SAFE | DUK_COMPILE_NORESULT))
+
+#define duk_compile_file(ctx,flags,path)  \
+	((void) duk_push_string_file_raw((ctx), (path), 0), \
+	 (void) duk_push_string((ctx), (path)), \
+	 (void) duk_compile_raw((ctx), NULL, 0, 3 /*args*/ | (flags)))
+
+#define duk_pcompile_file(ctx,flags,path)  \
+	((void) duk_push_string_file_raw((ctx), (path), DUK_STRING_PUSH_SAFE), \
+	 (void) duk_push_string((ctx), (path)), \
+	 duk_compile_raw((ctx), NULL, 0, 3 /*args*/ | (flags) | DUK_COMPILE_SAFE))
+
+/*
+ *  Bytecode load/dump
+ */
+
+DUK_EXTERNAL_DECL void duk_dump_function(duk_context *ctx);
+DUK_EXTERNAL_DECL void duk_load_function(duk_context *ctx);
+
+/*
+ *  Logging
+ */
+
+DUK_EXTERNAL_DECL void duk_log(duk_context *ctx, duk_int_t level, const char *fmt, ...);
+DUK_EXTERNAL_DECL void duk_log_va(duk_context *ctx, duk_int_t level, const char *fmt, va_list ap);
+
+/*
+ *  Debugging
+ */
+
+DUK_EXTERNAL_DECL void duk_push_context_dump(duk_context *ctx);
+
+#if defined(DUK_USE_FILE_IO)
+/* internal use */
+#define duk_dump_context_filehandle(ctx,fh) \
+	(duk_push_context_dump((ctx)), \
+	 DUK_FPRINTF((fh), "%s\n", duk_safe_to_string(ctx, -1)), \
+	 duk_pop(ctx))
+
+/* external use */
+#define duk_dump_context_stdout(ctx) \
+	duk_dump_context_filehandle((ctx), DUK_STDOUT)
+#define duk_dump_context_stderr(ctx) \
+	duk_dump_context_filehandle((ctx), DUK_STDERR)
+#else  /* DUK_USE_FILE_IO */
+#define duk_dump_context_stdout(ctx)  ((void) 0)
+#define duk_dump_context_stderr(ctx)  ((void) 0)
+#endif  /* DUK_USE_FILE_IO */
+
+/*
+ *  Debugger (debug protocol)
+ */
+
+#define duk_debugger_attach(ctx,read_cb,write_cb,peek_cb,read_flush_cb,write_flush_cb,detached_cb,udata) \
+	duk_debugger_attach_custom((ctx), (read_cb), (write_cb), (peek_cb), (read_flush_cb), (write_flush_cb), \
+	                           NULL, (detached_cb), (udata))
+
+DUK_EXTERNAL_DECL void duk_debugger_attach_custom(duk_context *ctx,
+                                                  duk_debug_read_function read_cb,
+                                                  duk_debug_write_function write_cb,
+                                                  duk_debug_peek_function peek_cb,
+                                                  duk_debug_read_flush_function read_flush_cb,
+                                                  duk_debug_write_flush_function write_flush_cb,
+                                                  duk_debug_request_function request_cb,
+                                                  duk_debug_detached_function detached_cb,
+                                                  void *udata);
+DUK_EXTERNAL_DECL void duk_debugger_detach(duk_context *ctx);
+DUK_EXTERNAL_DECL void duk_debugger_cooperate(duk_context *ctx);
+DUK_EXTERNAL_DECL duk_bool_t duk_debugger_notify(duk_context *ctx, duk_idx_t nvalues);
+DUK_EXTERNAL_DECL void duk_debugger_pause(duk_context *ctx);
+
+/*
+ *  Date provider related constants
+ *
+ *  NOTE: These are "semi public" - you should only use these if you write
+ *  your own platform specific Date provider, see doc/datetime.rst.
+ */
+
+/* Millisecond count constants. */
+#define DUK_DATE_MSEC_SECOND          1000L
+#define DUK_DATE_MSEC_MINUTE          (60L * 1000L)
+#define DUK_DATE_MSEC_HOUR            (60L * 60L * 1000L)
+#define DUK_DATE_MSEC_DAY             (24L * 60L * 60L * 1000L)
+
+/* Ecmascript date range is 100 million days from Epoch:
+ * > 100e6 * 24 * 60 * 60 * 1000  // 100M days in millisecs
+ * 8640000000000000
+ * (= 8.64e15)
+ */
+#define DUK_DATE_MSEC_100M_DAYS         (8.64e15)
+#define DUK_DATE_MSEC_100M_DAYS_LEEWAY  (8.64e15 + 24 * 3600e3)
+
+/* Ecmascript year range:
+ * > new Date(100e6 * 24 * 3600e3).toISOString()
+ * '+275760-09-13T00:00:00.000Z'
+ * > new Date(-100e6 * 24 * 3600e3).toISOString()
+ * '-271821-04-20T00:00:00.000Z'
+ */
+#define DUK_DATE_MIN_ECMA_YEAR     (-271821L)
+#define DUK_DATE_MAX_ECMA_YEAR     275760L
+
+/* Part indices for internal breakdowns.  Part order from DUK_DATE_IDX_YEAR
+ * to DUK_DATE_IDX_MILLISECOND matches argument ordering of Ecmascript API
+ * calls (like Date constructor call).  Some functions in duk_bi_date.c
+ * depend on the specific ordering, so change with care.  16 bits are not
+ * enough for all parts (year, specifically).
+ *
+ * (Must be in-sync with genbuiltins.py.)
+ */
+#define DUK_DATE_IDX_YEAR           0  /* year */
+#define DUK_DATE_IDX_MONTH          1  /* month: 0 to 11 */
+#define DUK_DATE_IDX_DAY            2  /* day within month: 0 to 30 */
+#define DUK_DATE_IDX_HOUR           3
+#define DUK_DATE_IDX_MINUTE         4
+#define DUK_DATE_IDX_SECOND         5
+#define DUK_DATE_IDX_MILLISECOND    6
+#define DUK_DATE_IDX_WEEKDAY        7  /* weekday: 0 to 6, 0=sunday, 1=monday, etc */
+#define DUK_DATE_IDX_NUM_PARTS      8
+
+/* Internal API call flags, used for various functions in this file.
+ * Certain flags are used by only certain functions, but since the flags
+ * don't overlap, a single flags value can be passed around to multiple
+ * functions.
+ *
+ * The unused top bits of the flags field are also used to pass values
+ * to helpers (duk__get_part_helper() and duk__set_part_helper()).
+ *
+ * (Must be in-sync with genbuiltins.py.)
+ */
+
+/* NOTE: when writing a Date provider you only need a few specific
+ * flags from here, the rest are internal.  Avoid using anything you
+ * don't need.
+ */
+
+#define DUK_DATE_FLAG_NAN_TO_ZERO          (1 << 0)  /* timeval breakdown: internal time value NaN -> zero */
+#define DUK_DATE_FLAG_NAN_TO_RANGE_ERROR   (1 << 1)  /* timeval breakdown: internal time value NaN -> RangeError (toISOString) */
+#define DUK_DATE_FLAG_ONEBASED             (1 << 2)  /* timeval breakdown: convert month and day-of-month parts to one-based (default is zero-based) */
+#define DUK_DATE_FLAG_EQUIVYEAR            (1 << 3)  /* timeval breakdown: replace year with equivalent year in the [1971,2037] range for DST calculations */
+#define DUK_DATE_FLAG_LOCALTIME            (1 << 4)  /* convert time value to local time */
+#define DUK_DATE_FLAG_SUB1900              (1 << 5)  /* getter: subtract 1900 from year when getting year part */
+#define DUK_DATE_FLAG_TOSTRING_DATE        (1 << 6)  /* include date part in string conversion result */
+#define DUK_DATE_FLAG_TOSTRING_TIME        (1 << 7)  /* include time part in string conversion result */
+#define DUK_DATE_FLAG_TOSTRING_LOCALE      (1 << 8)  /* use locale specific formatting if available */
+#define DUK_DATE_FLAG_TIMESETTER           (1 << 9)  /* setter: call is a time setter (affects hour, min, sec, ms); otherwise date setter (affects year, month, day-in-month) */
+#define DUK_DATE_FLAG_YEAR_FIXUP           (1 << 10) /* setter: perform 2-digit year fixup (00...99 -> 1900...1999) */
+#define DUK_DATE_FLAG_SEP_T                (1 << 11) /* string conversion: use 'T' instead of ' ' as a separator */
+#define DUK_DATE_FLAG_VALUE_SHIFT          12        /* additional values begin at bit 12 */
+
+/*
+ *  ROM pointer compression
+ */
+
+/* Support array for ROM pointer compression.  Only declared when ROM
+ * pointer compression is active.
+ */
+#if defined(DUK_USE_ROM_OBJECTS) && defined(DUK_USE_HEAPPTR16)
+DUK_EXTERNAL_DECL const void * const duk_rom_compressed_pointers[];
+#endif
+
+/*
+ *  C++ name mangling
+ */
+
+#ifdef __cplusplus
+/* end 'extern "C"' wrapper */
+}
+#endif
+
+#endif  /* DUK_API_PUBLIC_H_INCLUDED */
+
+/*
+ *  END PUBLIC API
+ */
+
+/*
+ *  Union to access IEEE double memory representation, indexes for double
+ *  memory representation, and some macros for double manipulation.
+ *
+ *  Also used by packed duk_tval.  Use a union for bit manipulation to
+ *  minimize aliasing issues in practice.  The C99 standard does not
+ *  guarantee that this should work, but it's a very widely supported
+ *  practice for low level manipulation.
+ *
+ *  IEEE double format summary:
+ *
+ *    seeeeeee eeeeffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff
+ *       A        B        C        D        E        F        G        H
+ *
+ *    s       sign bit
+ *    eee...  exponent field
+ *    fff...  fraction
+ *
+ *  See http://en.wikipedia.org/wiki/Double_precision_floating-point_format.
+ *
+ *  NaNs are represented as exponent 0x7ff and mantissa != 0.  The NaN is a
+ *  signaling NaN when the highest bit of the mantissa is zero, and a quiet
+ *  NaN when the highest bit is set.
+ *
+ *  At least three memory layouts are relevant here:
+ *
+ *    A B C D E F G H    Big endian (e.g. 68k)           DUK_USE_DOUBLE_BE
+ *    H G F E D C B A    Little endian (e.g. x86)        DUK_USE_DOUBLE_LE
+ *    D C B A H G F E    Mixed/cross endian (e.g. ARM)   DUK_USE_DOUBLE_ME
+ *
+ *  ARM is a special case: ARM double values are in mixed/cross endian
+ *  format while ARM duk_uint64_t values are in standard little endian
+ *  format (H G F E D C B A).  When a double is read as a duk_uint64_t
+ *  from memory, the register will contain the (logical) value
+ *  E F G H A B C D.  This requires some special handling below.
+ *
+ *  Indexes of various types (8-bit, 16-bit, 32-bit) in memory relative to
+ *  the logical (big endian) order:
+ *
+ *  byte order      duk_uint8_t    duk_uint16_t     duk_uint32_t
+ *    BE             01234567         0123               01
+ *    LE             76543210         3210               10
+ *    ME (ARM)       32107654         1032               01
+ *
+ *  Some processors may alter NaN values in a floating point load+store.
+ *  For instance, on X86 a FLD + FSTP may convert a signaling NaN to a
+ *  quiet one.  This is catastrophic when NaN space is used in packed
+ *  duk_tval values.  See: misc/clang_aliasing.c.
+ */
+
+#ifndef DUK_DBLUNION_H_INCLUDED
+#define DUK_DBLUNION_H_INCLUDED
+
+/*
+ *  Union for accessing double parts, also serves as packed duk_tval
+ */
+
+union duk_double_union {
+	double d;
+	float f[2];
+#if defined(DUK_USE_64BIT_OPS)
+	duk_uint64_t ull[1];
+#endif
+	duk_uint32_t ui[2];
+	duk_uint16_t us[4];
+	duk_uint8_t uc[8];
+#if defined(DUK_USE_PACKED_TVAL)
+	void *vp[2];  /* used by packed duk_tval, assumes sizeof(void *) == 4 */
+#endif
+};
+
+typedef union duk_double_union duk_double_union;
+
+/*
+ *  Indexes of various types with respect to big endian (logical) layout
+ */
+
+#if defined(DUK_USE_DOUBLE_LE)
+#ifdef DUK_USE_64BIT_OPS
+#define DUK_DBL_IDX_ULL0   0
+#endif
+#define DUK_DBL_IDX_UI0    1
+#define DUK_DBL_IDX_UI1    0
+#define DUK_DBL_IDX_US0    3
+#define DUK_DBL_IDX_US1    2
+#define DUK_DBL_IDX_US2    1
+#define DUK_DBL_IDX_US3    0
+#define DUK_DBL_IDX_UC0    7
+#define DUK_DBL_IDX_UC1    6
+#define DUK_DBL_IDX_UC2    5
+#define DUK_DBL_IDX_UC3    4
+#define DUK_DBL_IDX_UC4    3
+#define DUK_DBL_IDX_UC5    2
+#define DUK_DBL_IDX_UC6    1
+#define DUK_DBL_IDX_UC7    0
+#define DUK_DBL_IDX_VP0    DUK_DBL_IDX_UI0  /* packed tval */
+#define DUK_DBL_IDX_VP1    DUK_DBL_IDX_UI1  /* packed tval */
+#elif defined(DUK_USE_DOUBLE_BE)
+#ifdef DUK_USE_64BIT_OPS
+#define DUK_DBL_IDX_ULL0   0
+#endif
+#define DUK_DBL_IDX_UI0    0
+#define DUK_DBL_IDX_UI1    1
+#define DUK_DBL_IDX_US0    0
+#define DUK_DBL_IDX_US1    1
+#define DUK_DBL_IDX_US2    2
+#define DUK_DBL_IDX_US3    3
+#define DUK_DBL_IDX_UC0    0
+#define DUK_DBL_IDX_UC1    1
+#define DUK_DBL_IDX_UC2    2
+#define DUK_DBL_IDX_UC3    3
+#define DUK_DBL_IDX_UC4    4
+#define DUK_DBL_IDX_UC5    5
+#define DUK_DBL_IDX_UC6    6
+#define DUK_DBL_IDX_UC7    7
+#define DUK_DBL_IDX_VP0    DUK_DBL_IDX_UI0  /* packed tval */
+#define DUK_DBL_IDX_VP1    DUK_DBL_IDX_UI1  /* packed tval */
+#elif defined(DUK_USE_DOUBLE_ME)
+#ifdef DUK_USE_64BIT_OPS
+#define DUK_DBL_IDX_ULL0   0  /* not directly applicable, byte order differs from a double */
+#endif
+#define DUK_DBL_IDX_UI0    0
+#define DUK_DBL_IDX_UI1    1
+#define DUK_DBL_IDX_US0    1
+#define DUK_DBL_IDX_US1    0
+#define DUK_DBL_IDX_US2    3
+#define DUK_DBL_IDX_US3    2
+#define DUK_DBL_IDX_UC0    3
+#define DUK_DBL_IDX_UC1    2
+#define DUK_DBL_IDX_UC2    1
+#define DUK_DBL_IDX_UC3    0
+#define DUK_DBL_IDX_UC4    7
+#define DUK_DBL_IDX_UC5    6
+#define DUK_DBL_IDX_UC6    5
+#define DUK_DBL_IDX_UC7    4
+#define DUK_DBL_IDX_VP0    DUK_DBL_IDX_UI0  /* packed tval */
+#define DUK_DBL_IDX_VP1    DUK_DBL_IDX_UI1  /* packed tval */
+#else
+#error internal error
+#endif
+
+/*
+ *  Helper macros for reading/writing memory representation parts, used
+ *  by duk_numconv.c and duk_tval.h.
+ */
+
+#define DUK_DBLUNION_SET_DOUBLE(u,v)  do {  \
+		(u)->d = (v); \
+	} while (0)
+
+#define DUK_DBLUNION_SET_HIGH32(u,v)  do {  \
+		(u)->ui[DUK_DBL_IDX_UI0] = (duk_uint32_t) (v); \
+	} while (0)
+
+#ifdef DUK_USE_64BIT_OPS
+#ifdef DUK_USE_DOUBLE_ME
+#define DUK_DBLUNION_SET_HIGH32_ZERO_LOW32(u,v)  do { \
+		(u)->ull[DUK_DBL_IDX_ULL0] = (duk_uint64_t) (v); \
+	} while (0)
+#else
+#define DUK_DBLUNION_SET_HIGH32_ZERO_LOW32(u,v)  do { \
+		(u)->ull[DUK_DBL_IDX_ULL0] = ((duk_uint64_t) (v)) << 32; \
+	} while (0)
+#endif
+#else  /* DUK_USE_64BIT_OPS */
+#define DUK_DBLUNION_SET_HIGH32_ZERO_LOW32(u,v)  do { \
+		(u)->ui[DUK_DBL_IDX_UI0] = (duk_uint32_t) (v); \
+		(u)->ui[DUK_DBL_IDX_UI1] = (duk_uint32_t) 0; \
+	} while (0)
+#endif  /* DUK_USE_64BIT_OPS */
+
+#define DUK_DBLUNION_SET_LOW32(u,v)  do {  \
+		(u)->ui[DUK_DBL_IDX_UI1] = (duk_uint32_t) (v); \
+	} while (0)
+
+#define DUK_DBLUNION_GET_DOUBLE(u)  ((u)->d)
+#define DUK_DBLUNION_GET_HIGH32(u)  ((u)->ui[DUK_DBL_IDX_UI0])
+#define DUK_DBLUNION_GET_LOW32(u)   ((u)->ui[DUK_DBL_IDX_UI1])
+
+#ifdef DUK_USE_64BIT_OPS
+#ifdef DUK_USE_DOUBLE_ME
+#define DUK_DBLUNION_SET_UINT64(u,v)  do { \
+		(u)->ui[DUK_DBL_IDX_UI0] = (duk_uint32_t) ((v) >> 32); \
+		(u)->ui[DUK_DBL_IDX_UI1] = (duk_uint32_t) (v); \
+	} while (0)
+#define DUK_DBLUNION_GET_UINT64(u) \
+	((((duk_uint64_t) (u)->ui[DUK_DBL_IDX_UI0]) << 32) | \
+	 ((duk_uint64_t) (u)->ui[DUK_DBL_IDX_UI1]))
+#else
+#define DUK_DBLUNION_SET_UINT64(u,v)  do { \
+		(u)->ull[DUK_DBL_IDX_ULL0] = (duk_uint64_t) (v); \
+	} while (0)
+#define DUK_DBLUNION_GET_UINT64(u)  ((u)->ull[DUK_DBL_IDX_ULL0])
+#endif
+#define DUK_DBLUNION_SET_INT64(u,v) DUK_DBLUNION_SET_UINT64((u), (duk_uint64_t) (v))
+#define DUK_DBLUNION_GET_INT64(u)   ((duk_int64_t) DUK_DBLUNION_GET_UINT64((u)))
+#endif  /* DUK_USE_64BIT_OPS */
+
+/*
+ *  Double NaN manipulation macros related to NaN normalization needed when
+ *  using the packed duk_tval representation.  NaN normalization is necessary
+ *  to keep double values compatible with the duk_tval format.
+ *
+ *  When packed duk_tval is used, the NaN space is used to store pointers
+ *  and other tagged values in addition to NaNs.  Actual NaNs are normalized
+ *  to a specific quiet NaN.  The macros below are used by the implementation
+ *  to check and normalize NaN values when they might be created.  The macros
+ *  are essentially NOPs when the non-packed duk_tval representation is used.
+ *
+ *  A FULL check is exact and checks all bits.  A NOTFULL check is used by
+ *  the packed duk_tval and works correctly for all NaNs except those that
+ *  begin with 0x7ff0.  Since the 'normalized NaN' values used with packed
+ *  duk_tval begin with 0x7ff8, the partial check is reliable when packed
+ *  duk_tval is used.  The 0x7ff8 prefix means the normalized NaN will be a
+ *  quiet NaN regardless of its remaining lower bits.
+ *
+ *  The ME variant below is specifically for ARM byte order, which has the
+ *  feature that while doubles have a mixed byte order (32107654), unsigned
+ *  long long values has a little endian byte order (76543210).  When writing
+ *  a logical double value through a ULL pointer, the 32-bit words need to be
+ *  swapped; hence the #ifdefs below for ULL writes with DUK_USE_DOUBLE_ME.
+ *  This is not full ARM support but suffices for some environments.
+ */
+
+#ifdef DUK_USE_64BIT_OPS
+#ifdef DUK_USE_DOUBLE_ME
+#define DUK__DBLUNION_SET_NAN_FULL(u)  do { \
+		(u)->ull[DUK_DBL_IDX_ULL0] = 0x000000007ff80000ULL; \
+	} while (0)
+#else
+#define DUK__DBLUNION_SET_NAN_FULL(u)  do { \
+		(u)->ull[DUK_DBL_IDX_ULL0] = 0x7ff8000000000000ULL; \
+	} while (0)
+#endif
+#else  /* DUK_USE_64BIT_OPS */
+#define DUK__DBLUNION_SET_NAN_FULL(u)  do { \
+		(u)->ui[DUK_DBL_IDX_UI0] = (duk_uint32_t) 0x7ff80000UL; \
+		(u)->ui[DUK_DBL_IDX_UI1] = (duk_uint32_t) 0x00000000UL; \
+	} while (0)
+#endif  /* DUK_USE_64BIT_OPS */
+
+#define DUK__DBLUNION_SET_NAN_NOTFULL(u)  do { \
+		(u)->us[DUK_DBL_IDX_US0] = 0x7ff8UL; \
+	} while (0)
+
+#ifdef DUK_USE_64BIT_OPS
+#ifdef DUK_USE_DOUBLE_ME
+#define DUK__DBLUNION_IS_NAN_FULL(u) \
+	/* E == 0x7ff, F != 0 => NaN */ \
+	((((u)->us[DUK_DBL_IDX_US0] & 0x7ff0UL) == 0x7ff0UL) && \
+	 ((((u)->ull[DUK_DBL_IDX_ULL0]) & 0xffffffff000fffffULL) != 0))
+#else
+#define DUK__DBLUNION_IS_NAN_FULL(u) \
+	/* E == 0x7ff, F != 0 => NaN */ \
+	((((u)->us[DUK_DBL_IDX_US0] & 0x7ff0UL) == 0x7ff0UL) && \
+	 ((((u)->ull[DUK_DBL_IDX_ULL0]) & 0x000fffffffffffffULL) != 0))
+#endif
+#else  /* DUK_USE_64BIT_OPS */
+#define DUK__DBLUNION_IS_NAN_FULL(u) \
+	/* E == 0x7ff, F != 0 => NaN */ \
+	((((u)->ui[DUK_DBL_IDX_UI0] & 0x7ff00000UL) == 0x7ff00000UL) && \
+	 (((u)->ui[DUK_DBL_IDX_UI0] & 0x000fffffUL) != 0 || \
+          (u)->ui[DUK_DBL_IDX_UI1] != 0))
+#endif  /* DUK_USE_64BIT_OPS */
+
+#define DUK__DBLUNION_IS_NAN_NOTFULL(u) \
+	/* E == 0x7ff, topmost four bits of F != 0 => assume NaN */ \
+	((((u)->us[DUK_DBL_IDX_US0] & 0x7ff0UL) == 0x7ff0UL) && \
+	 (((u)->us[DUK_DBL_IDX_US0] & 0x000fUL) != 0x0000UL))
+
+#ifdef DUK_USE_64BIT_OPS
+#ifdef DUK_USE_DOUBLE_ME
+#define DUK__DBLUNION_IS_NORMALIZED_NAN_FULL(u) \
+	((u)->ull[DUK_DBL_IDX_ULL0] == 0x000000007ff80000ULL)
+#else
+#define DUK__DBLUNION_IS_NORMALIZED_NAN_FULL(u) \
+	((u)->ull[DUK_DBL_IDX_ULL0] == 0x7ff8000000000000ULL)
+#endif
+#else  /* DUK_USE_64BIT_OPS */
+#define DUK__DBLUNION_IS_NORMALIZED_NAN_FULL(u) \
+	(((u)->ui[DUK_DBL_IDX_UI0] == 0x7ff80000UL) && \
+	 ((u)->ui[DUK_DBL_IDX_UI1] == 0x00000000UL))
+#endif  /* DUK_USE_64BIT_OPS */
+
+#define DUK__DBLUNION_IS_NORMALIZED_NAN_NOTFULL(u) \
+	/* E == 0x7ff, F == 8 => normalized NaN */ \
+	((u)->us[DUK_DBL_IDX_US0] == 0x7ff8UL)
+
+#define DUK__DBLUNION_NORMALIZE_NAN_CHECK_FULL(u)  do { \
+		if (DUK__DBLUNION_IS_NAN_FULL((u))) { \
+			DUK__DBLUNION_SET_NAN_FULL((u)); \
+		} \
+	} while (0)
+
+#define DUK__DBLUNION_NORMALIZE_NAN_CHECK_NOTFULL(u)  do { \
+		if (DUK__DBLUNION_IS_NAN_NOTFULL((u))) { \
+			DUK__DBLUNION_SET_NAN_NOTFULL((u)); \
+		} \
+	} while (0)
+
+/* Concrete macros for NaN handling used by the implementation internals.
+ * Chosen so that they match the duk_tval representation: with a packed
+ * duk_tval, ensure NaNs are properly normalized; with a non-packed duk_tval
+ * these are essentially NOPs.
+ */
+
+#if defined(DUK_USE_PACKED_TVAL)
+#if defined(DUK_USE_FULL_TVAL)
+#define DUK_DBLUNION_NORMALIZE_NAN_CHECK(u)  DUK__DBLUNION_NORMALIZE_NAN_CHECK_FULL((u))
+#define DUK_DBLUNION_IS_NAN(u)               DUK__DBLUNION_IS_NAN_FULL((u))
+#define DUK_DBLUNION_IS_NORMALIZED_NAN(u)    DUK__DBLUNION_IS_NORMALIZED_NAN_FULL((u))
+#define DUK_DBLUNION_SET_NAN(d)              DUK__DBLUNION_SET_NAN_FULL((d))
+#else
+#define DUK_DBLUNION_NORMALIZE_NAN_CHECK(u)  DUK__DBLUNION_NORMALIZE_NAN_CHECK_NOTFULL((u))
+#define DUK_DBLUNION_IS_NAN(u)               DUK__DBLUNION_IS_NAN_NOTFULL((u))
+#define DUK_DBLUNION_IS_NORMALIZED_NAN(u)    DUK__DBLUNION_IS_NORMALIZED_NAN_NOTFULL((u))
+#define DUK_DBLUNION_SET_NAN(d)              DUK__DBLUNION_SET_NAN_NOTFULL((d))
+#endif
+#define DUK_DBLUNION_IS_NORMALIZED(u) \
+	(!DUK_DBLUNION_IS_NAN((u)) ||  /* either not a NaN */ \
+	 DUK_DBLUNION_IS_NORMALIZED_NAN((u)))  /* or is a normalized NaN */
+#else  /* DUK_USE_PACKED_TVAL */
+#define DUK_DBLUNION_NORMALIZE_NAN_CHECK(u)  /* nop: no need to normalize */
+#define DUK_DBLUNION_IS_NAN(u)               (DUK_ISNAN((u)->d))
+#define DUK_DBLUNION_IS_NORMALIZED_NAN(u)    (DUK_ISNAN((u)->d))
+#define DUK_DBLUNION_IS_NORMALIZED(u)        1  /* all doubles are considered normalized */
+#define DUK_DBLUNION_SET_NAN(u)  do { \
+		/* in non-packed representation we don't care about which NaN is used */ \
+		(u)->d = DUK_DOUBLE_NAN; \
+	} while (0)
+#endif  /* DUK_USE_PACKED_TVAL */
+
+/* XXX: native 64-bit byteswaps when available */
+
+/* 64-bit byteswap, same operation independent of target endianness. */
+#define DUK_DBLUNION_BSWAP64(u) do { \
+		duk_uint32_t duk__bswaptmp1, duk__bswaptmp2; \
+		duk__bswaptmp1 = (u)->ui[0]; \
+		duk__bswaptmp2 = (u)->ui[1]; \
+		duk__bswaptmp1 = DUK_BSWAP32(duk__bswaptmp1); \
+		duk__bswaptmp2 = DUK_BSWAP32(duk__bswaptmp2); \
+		(u)->ui[0] = duk__bswaptmp2; \
+		(u)->ui[1] = duk__bswaptmp1; \
+	} while (0)
+
+/* Byteswap an IEEE double in the duk_double_union from host to network
+ * order.  For a big endian target this is a no-op.
+ */
+#if defined(DUK_USE_DOUBLE_LE)
+#define DUK_DBLUNION_DOUBLE_HTON(u) do { \
+		duk_uint32_t duk__bswaptmp1, duk__bswaptmp2; \
+		duk__bswaptmp1 = (u)->ui[0]; \
+		duk__bswaptmp2 = (u)->ui[1]; \
+		duk__bswaptmp1 = DUK_BSWAP32(duk__bswaptmp1); \
+		duk__bswaptmp2 = DUK_BSWAP32(duk__bswaptmp2); \
+		(u)->ui[0] = duk__bswaptmp2; \
+		(u)->ui[1] = duk__bswaptmp1; \
+	} while (0)
+#elif defined(DUK_USE_DOUBLE_ME)
+#define DUK_DBLUNION_DOUBLE_HTON(u) do { \
+		duk_uint32_t duk__bswaptmp1, duk__bswaptmp2; \
+		duk__bswaptmp1 = (u)->ui[0]; \
+		duk__bswaptmp2 = (u)->ui[1]; \
+		duk__bswaptmp1 = DUK_BSWAP32(duk__bswaptmp1); \
+		duk__bswaptmp2 = DUK_BSWAP32(duk__bswaptmp2); \
+		(u)->ui[0] = duk__bswaptmp1; \
+		(u)->ui[1] = duk__bswaptmp2; \
+	} while (0)
+#elif defined(DUK_USE_DOUBLE_BE)
+#define DUK_DBLUNION_DOUBLE_HTON(u) do { } while (0)
+#else
+#error internal error, double endianness insane
+#endif
+
+/* Reverse operation is the same. */
+#define DUK_DBLUNION_DOUBLE_NTOH(u) DUK_DBLUNION_DOUBLE_HTON((u))
+
+#endif  /* DUK_DBLUNION_H_INCLUDED */
+
+#endif  /* DUKTAPE_H_INCLUDED */


[12/51] [partial] nifi-minifi-cpp git commit: MINIFI-183 Added civet 1.9.1 sources Added onScheduled hook Added initial two-way TLS-enabled ListenHTTP implementation

Posted by al...@apache.org.
http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_bi_error.c
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_bi_error.c b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_bi_error.c
new file mode 100644
index 0000000..b575fff
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_bi_error.c
@@ -0,0 +1,383 @@
+/*
+ *  Error built-ins
+ */
+
+#include "duk_internal.h"
+
+DUK_INTERNAL duk_ret_t duk_bi_error_constructor_shared(duk_context *ctx) {
+	/* Behavior for constructor and non-constructor call is
+	 * the same except for augmenting the created error.  When
+	 * called as a constructor, the caller (duk_new()) will handle
+	 * augmentation; when called as normal function, we need to do
+	 * it here.
+	 */
+
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_small_int_t bidx_prototype = duk_get_current_magic(ctx);
+
+	/* same for both error and each subclass like TypeError */
+	duk_uint_t flags_and_class = DUK_HOBJECT_FLAG_EXTENSIBLE |
+	                             DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_ERROR);
+
+	DUK_UNREF(thr);
+
+	duk_push_object_helper(ctx, flags_and_class, bidx_prototype);
+
+	/* If message is undefined, the own property 'message' is not set at
+	 * all to save property space.  An empty message is inherited anyway.
+	 */
+	if (!duk_is_undefined(ctx, 0)) {
+		duk_to_string(ctx, 0);
+		duk_dup(ctx, 0);  /* [ message error message ] */
+		duk_xdef_prop_stridx(ctx, -2, DUK_STRIDX_MESSAGE, DUK_PROPDESC_FLAGS_WC);
+	}
+
+	/* Augment the error if called as a normal function.  __FILE__ and __LINE__
+	 * are not desirable in this case.
+	 */
+
+#ifdef DUK_USE_AUGMENT_ERROR_CREATE
+	if (!duk_is_constructor_call(ctx)) {
+		duk_err_augment_error_create(thr, thr, NULL, 0, 1 /*noblame_fileline*/);
+	}
+#endif
+
+	return 1;
+}
+
+DUK_INTERNAL duk_ret_t duk_bi_error_prototype_to_string(duk_context *ctx) {
+	/* XXX: optimize with more direct internal access */
+
+	duk_push_this(ctx);
+	(void) duk_require_hobject_or_lfunc_coerce(ctx, -1);
+
+	/* [ ... this ] */
+
+	duk_get_prop_stridx(ctx, -1, DUK_STRIDX_NAME);
+	if (duk_is_undefined(ctx, -1)) {
+		duk_pop(ctx);
+		duk_push_string(ctx, "Error");
+	} else {
+		duk_to_string(ctx, -1);
+	}
+
+	/* [ ... this name ] */
+
+	/* XXX: Are steps 6 and 7 in E5 Section 15.11.4.4 duplicated by
+	 * accident or are they actually needed?  The first ToString()
+	 * could conceivably return 'undefined'.
+	 */
+	duk_get_prop_stridx(ctx, -2, DUK_STRIDX_MESSAGE);
+	if (duk_is_undefined(ctx, -1)) {
+		duk_pop(ctx);
+		duk_push_string(ctx, "");
+	} else {
+		duk_to_string(ctx, -1);
+	}
+
+	/* [ ... this name message ] */
+
+	if (duk_get_length(ctx, -2) == 0) {
+		/* name is empty -> return message */
+		return 1;
+	}
+	if (duk_get_length(ctx, -1) == 0) {
+		/* message is empty -> return name */
+		duk_pop(ctx);
+		return 1;
+	}
+	duk_push_string(ctx, ": ");
+	duk_insert(ctx, -2);  /* ... name ': ' message */
+	duk_concat(ctx, 3);
+
+	return 1;
+}
+
+#if defined(DUK_USE_TRACEBACKS)
+
+/*
+ *  Traceback handling
+ *
+ *  The unified helper decodes the traceback and produces various requested
+ *  outputs.  It should be optimized for size, and may leave garbage on stack,
+ *  only the topmost return value matters.  For instance, traceback separator
+ *  and decoded strings are pushed even when looking for filename only.
+ *
+ *  NOTE: although _Tracedata is an internal property, user code can currently
+ *  write to the array (or replace it with something other than an array).
+ *  The code below must tolerate arbitrary _Tracedata.  It can throw errors
+ *  etc, but cannot cause a segfault or memory unsafe behavior.
+ */
+
+/* constants arbitrary, chosen for small loads */
+#define DUK__OUTPUT_TYPE_TRACEBACK   (-1)
+#define DUK__OUTPUT_TYPE_FILENAME    0
+#define DUK__OUTPUT_TYPE_LINENUMBER  1
+
+DUK_LOCAL duk_ret_t duk__error_getter_helper(duk_context *ctx, duk_small_int_t output_type) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_idx_t idx_td;
+	duk_small_int_t i;  /* traceback depth fits into 16 bits */
+	duk_small_int_t t;  /* stack type fits into 16 bits */
+	duk_small_int_t count_func = 0;  /* traceback depth ensures fits into 16 bits */
+	const char *str_tailcall = " tailcall";
+	const char *str_strict = " strict";
+	const char *str_construct = " construct";
+	const char *str_prevyield = " preventsyield";
+	const char *str_directeval = " directeval";
+	const char *str_empty = "";
+
+	DUK_ASSERT_TOP(ctx, 0);  /* fixed arg count */
+	DUK_UNREF(thr);
+
+	duk_push_this(ctx);
+	duk_get_prop_stridx(ctx, -1, DUK_STRIDX_INT_TRACEDATA);
+	idx_td = duk_get_top_index(ctx);
+
+	duk_push_hstring_stridx(ctx, DUK_STRIDX_NEWLINE_4SPACE);
+	duk_push_this(ctx);
+
+	/* [ ... this tracedata sep this ] */
+
+	/* XXX: skip null filename? */
+
+	if (duk_check_type(ctx, idx_td, DUK_TYPE_OBJECT)) {
+		/* Current tracedata contains 2 entries per callstack entry. */
+		for (i = 0; ; i += 2) {
+			duk_int_t pc;
+			duk_int_t line;
+			duk_int_t flags;
+			duk_double_t d;
+			const char *funcname;
+			const char *filename;
+			duk_hobject *h_func;
+			duk_hstring *h_name;
+
+			duk_require_stack(ctx, 5);
+			duk_get_prop_index(ctx, idx_td, i);
+			duk_get_prop_index(ctx, idx_td, i + 1);
+			d = duk_to_number(ctx, -1);
+			pc = (duk_int_t) DUK_FMOD(d, DUK_DOUBLE_2TO32);
+			flags = (duk_int_t) DUK_FLOOR(d / DUK_DOUBLE_2TO32);
+			t = (duk_small_int_t) duk_get_type(ctx, -2);
+
+			if (t == DUK_TYPE_OBJECT || t == DUK_TYPE_LIGHTFUNC) {
+				/*
+				 *  Ecmascript/native function call or lightfunc call
+				 */
+
+				count_func++;
+
+				/* [ ... v1(func) v2(pc+flags) ] */
+
+				h_func = duk_get_hobject(ctx, -2);  /* NULL for lightfunc */
+
+				duk_get_prop_stridx(ctx, -2, DUK_STRIDX_NAME);
+				duk_get_prop_stridx(ctx, -3, DUK_STRIDX_FILE_NAME);
+
+#if defined(DUK_USE_PC2LINE)
+				line = duk_hobject_pc2line_query(ctx, -4, (duk_uint_fast32_t) pc);
+#else
+				line = 0;
+#endif
+
+				/* [ ... v1 v2 name filename ] */
+
+				/* When looking for .fileName/.lineNumber, blame first
+				 * function which has a .fileName.
+				 */
+				if (duk_is_string(ctx, -1)) {
+					if (output_type == DUK__OUTPUT_TYPE_FILENAME) {
+						return 1;
+					} else if (output_type == DUK__OUTPUT_TYPE_LINENUMBER) {
+						duk_push_int(ctx, line);
+						return 1;
+					}
+				}
+
+				/* XXX: Change 'anon' handling here too, to use empty string for anonymous functions? */
+				/* XXX: Could be improved by coercing to a readable duk_tval (especially string escaping) */
+				h_name = duk_get_hstring(ctx, -2);  /* may be NULL */
+				funcname = (h_name == NULL || h_name == DUK_HTHREAD_STRING_EMPTY_STRING(thr)) ?
+				           "[anon]" : (const char *) DUK_HSTRING_GET_DATA(h_name);
+				filename = duk_get_string(ctx, -1);
+				filename = filename ? filename : "";
+				DUK_ASSERT(funcname != NULL);
+				DUK_ASSERT(filename != NULL);
+
+				if (h_func == NULL) {
+					duk_push_sprintf(ctx, "at %s light%s%s%s%s%s",
+					                 (const char *) funcname,
+					                 (const char *) ((flags & DUK_ACT_FLAG_STRICT) ? str_strict : str_empty),
+					                 (const char *) ((flags & DUK_ACT_FLAG_TAILCALLED) ? str_tailcall : str_empty),
+					                 (const char *) ((flags & DUK_ACT_FLAG_CONSTRUCT) ? str_construct : str_empty),
+					                 (const char *) ((flags & DUK_ACT_FLAG_DIRECT_EVAL) ? str_directeval : str_empty),
+					                 (const char *) ((flags & DUK_ACT_FLAG_PREVENT_YIELD) ? str_prevyield : str_empty));
+				} else if (DUK_HOBJECT_HAS_NATIVEFUNCTION(h_func)) {
+					duk_push_sprintf(ctx, "at %s (%s) native%s%s%s%s%s",
+					                 (const char *) funcname,
+					                 (const char *) filename,
+					                 (const char *) ((flags & DUK_ACT_FLAG_STRICT) ? str_strict : str_empty),
+					                 (const char *) ((flags & DUK_ACT_FLAG_TAILCALLED) ? str_tailcall : str_empty),
+					                 (const char *) ((flags & DUK_ACT_FLAG_CONSTRUCT) ? str_construct : str_empty),
+					                 (const char *) ((flags & DUK_ACT_FLAG_DIRECT_EVAL) ? str_directeval : str_empty),
+					                 (const char *) ((flags & DUK_ACT_FLAG_PREVENT_YIELD) ? str_prevyield : str_empty));
+				} else {
+					duk_push_sprintf(ctx, "at %s (%s:%ld)%s%s%s%s%s",
+					                 (const char *) funcname,
+					                 (const char *) filename,
+					                 (long) line,
+					                 (const char *) ((flags & DUK_ACT_FLAG_STRICT) ? str_strict : str_empty),
+					                 (const char *) ((flags & DUK_ACT_FLAG_TAILCALLED) ? str_tailcall : str_empty),
+					                 (const char *) ((flags & DUK_ACT_FLAG_CONSTRUCT) ? str_construct : str_empty),
+					                 (const char *) ((flags & DUK_ACT_FLAG_DIRECT_EVAL) ? str_directeval : str_empty),
+					                 (const char *) ((flags & DUK_ACT_FLAG_PREVENT_YIELD) ? str_prevyield : str_empty));
+				}
+				duk_replace(ctx, -5);   /* [ ... v1 v2 name filename str ] -> [ ... str v2 name filename ] */
+				duk_pop_n(ctx, 3);      /* -> [ ... str ] */
+			} else if (t == DUK_TYPE_STRING) {
+				/*
+				 *  __FILE__ / __LINE__ entry, here 'pc' is line number directly.
+				 *  Sometimes __FILE__ / __LINE__ is reported as the source for
+				 *  the error (fileName, lineNumber), sometimes not.
+				 */
+
+				/* [ ... v1(filename) v2(line+flags) ] */
+
+				/* When looking for .fileName/.lineNumber, blame compilation
+				 * or C call site unless flagged not to do so.
+				 */
+				if (!(flags & DUK_TB_FLAG_NOBLAME_FILELINE)) {
+					if (output_type == DUK__OUTPUT_TYPE_FILENAME) {
+						duk_pop(ctx);
+						return 1;
+					} else if (output_type == DUK__OUTPUT_TYPE_LINENUMBER) {
+						duk_push_int(ctx, pc);
+						return 1;
+					}
+				}
+
+				duk_push_sprintf(ctx, "at [anon] (%s:%ld) internal",
+				                 (const char *) duk_get_string(ctx, -2), (long) pc);
+				duk_replace(ctx, -3);  /* [ ... v1 v2 str ] -> [ ... str v2 ] */
+				duk_pop(ctx);          /* -> [ ... str ] */
+			} else {
+				/* unknown, ignore */
+				duk_pop_2(ctx);
+				break;
+			}
+		}
+
+		if (count_func >= DUK_USE_TRACEBACK_DEPTH) {
+			/* Possibly truncated; there is no explicit truncation
+			 * marker so this is the best we can do.
+			 */
+
+			duk_push_hstring_stridx(ctx, DUK_STRIDX_BRACKETED_ELLIPSIS);
+		}
+	}
+
+	/* [ ... this tracedata sep this str1 ... strN ] */
+
+	if (output_type != DUK__OUTPUT_TYPE_TRACEBACK) {
+		return 0;
+	} else {
+		/* The 'this' after 'sep' will get ToString() coerced by
+		 * duk_join() automatically.  We don't want to do that
+		 * coercion when providing .fileName or .lineNumber (GH-254).
+		 */
+		duk_join(ctx, duk_get_top(ctx) - (idx_td + 2) /*count, not including sep*/);
+		return 1;
+	}
+}
+
+/* XXX: Output type could be encoded into native function 'magic' value to
+ * save space.  For setters the stridx could be encoded into 'magic'.
+ */
+
+DUK_INTERNAL duk_ret_t duk_bi_error_prototype_stack_getter(duk_context *ctx) {
+	return duk__error_getter_helper(ctx, DUK__OUTPUT_TYPE_TRACEBACK);
+}
+
+DUK_INTERNAL duk_ret_t duk_bi_error_prototype_filename_getter(duk_context *ctx) {
+	return duk__error_getter_helper(ctx, DUK__OUTPUT_TYPE_FILENAME);
+}
+
+DUK_INTERNAL duk_ret_t duk_bi_error_prototype_linenumber_getter(duk_context *ctx) {
+	return duk__error_getter_helper(ctx, DUK__OUTPUT_TYPE_LINENUMBER);
+}
+
+#undef DUK__OUTPUT_TYPE_TRACEBACK
+#undef DUK__OUTPUT_TYPE_FILENAME
+#undef DUK__OUTPUT_TYPE_LINENUMBER
+
+#else  /* DUK_USE_TRACEBACKS */
+
+/*
+ *  Traceback handling when tracebacks disabled.
+ *
+ *  The fileName / lineNumber stubs are now necessary because built-in
+ *  data will include the accessor properties in Error.prototype.  If those
+ *  are removed for builds without tracebacks, these can also be removed.
+ *  'stack' should still be present and produce a ToString() equivalent:
+ *  this is useful for user code which prints a stacktrace and expects to
+ *  see something useful.  A normal stacktrace also begins with a ToString()
+ *  of the error so this makes sense.
+ */
+
+DUK_INTERNAL duk_ret_t duk_bi_error_prototype_stack_getter(duk_context *ctx) {
+	/* XXX: remove this native function and map 'stack' accessor
+	 * to the toString() implementation directly.
+	 */
+	return duk_bi_error_prototype_to_string(ctx);
+}
+
+DUK_INTERNAL duk_ret_t duk_bi_error_prototype_filename_getter(duk_context *ctx) {
+	DUK_UNREF(ctx);
+	return 0;
+}
+
+DUK_INTERNAL duk_ret_t duk_bi_error_prototype_linenumber_getter(duk_context *ctx) {
+	DUK_UNREF(ctx);
+	return 0;
+}
+
+#endif  /* DUK_USE_TRACEBACKS */
+
+DUK_LOCAL duk_ret_t duk__error_setter_helper(duk_context *ctx, duk_small_uint_t stridx_key) {
+	/* Attempt to write 'stack', 'fileName', 'lineNumber' works as if
+	 * user code called Object.defineProperty() to create an overriding
+	 * own property.  This allows user code to overwrite .fileName etc
+	 * intuitively as e.g. "err.fileName = 'dummy'" as one might expect.
+	 * See https://github.com/svaarala/duktape/issues/387.
+	 */
+
+	DUK_ASSERT_TOP(ctx, 1);  /* fixed arg count: value */
+
+	duk_push_this(ctx);
+	duk_push_hstring_stridx(ctx, (duk_small_int_t) stridx_key);
+	duk_dup(ctx, 0);
+
+	/* [ ... obj key value ] */
+
+	DUK_DD(DUK_DDPRINT("error setter: %!T %!T %!T",
+	                   duk_get_tval(ctx, -3), duk_get_tval(ctx, -2), duk_get_tval(ctx, -1)));
+
+	duk_def_prop(ctx, -3, DUK_DEFPROP_HAVE_VALUE |
+	                      DUK_DEFPROP_HAVE_WRITABLE | DUK_DEFPROP_WRITABLE |
+	                      DUK_DEFPROP_HAVE_ENUMERABLE | /*not enumerable*/
+	                      DUK_DEFPROP_HAVE_CONFIGURABLE | DUK_DEFPROP_CONFIGURABLE);
+	return 0;
+}
+
+DUK_INTERNAL duk_ret_t duk_bi_error_prototype_stack_setter(duk_context *ctx) {
+	return duk__error_setter_helper(ctx, DUK_STRIDX_STACK);
+}
+
+DUK_INTERNAL duk_ret_t duk_bi_error_prototype_filename_setter(duk_context *ctx) {
+	return duk__error_setter_helper(ctx, DUK_STRIDX_FILE_NAME);
+}
+
+DUK_INTERNAL duk_ret_t duk_bi_error_prototype_linenumber_setter(duk_context *ctx) {
+	return duk__error_setter_helper(ctx, DUK_STRIDX_LINE_NUMBER);
+}

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_bi_function.c
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_bi_function.c b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_bi_function.c
new file mode 100644
index 0000000..2596a4a
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_bi_function.c
@@ -0,0 +1,346 @@
+/*
+ *  Function built-ins
+ */
+
+#include "duk_internal.h"
+
+DUK_INTERNAL duk_ret_t duk_bi_function_constructor(duk_context *ctx) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_hstring *h_sourcecode;
+	duk_idx_t nargs;
+	duk_idx_t i;
+	duk_small_uint_t comp_flags;
+	duk_hcompiledfunction *func;
+	duk_hobject *outer_lex_env;
+	duk_hobject *outer_var_env;
+
+	/* normal and constructor calls have identical semantics */
+
+	nargs = duk_get_top(ctx);
+	for (i = 0; i < nargs; i++) {
+		duk_to_string(ctx, i);
+	}
+
+	if (nargs == 0) {
+		duk_push_string(ctx, "");
+		duk_push_string(ctx, "");
+	} else if (nargs == 1) {
+		/* XXX: cover this with the generic >1 case? */
+		duk_push_string(ctx, "");
+	} else {
+		duk_insert(ctx, 0);   /* [ arg1 ... argN-1 body] -> [body arg1 ... argN-1] */
+		duk_push_string(ctx, ",");
+		duk_insert(ctx, 1);
+		duk_join(ctx, nargs - 1);
+	}
+
+	/* [ body formals ], formals is comma separated list that needs to be parsed */
+
+	DUK_ASSERT_TOP(ctx, 2);
+
+	/* XXX: this placeholder is not always correct, but use for now.
+	 * It will fail in corner cases; see test-dev-func-cons-args.js.
+	 */
+	duk_push_string(ctx, "function(");
+	duk_dup(ctx, 1);
+	duk_push_string(ctx, "){");
+	duk_dup(ctx, 0);
+	duk_push_string(ctx, "}");
+	duk_concat(ctx, 5);
+
+	/* [ body formals source ] */
+
+	DUK_ASSERT_TOP(ctx, 3);
+
+	/* strictness is not inherited, intentional */
+	comp_flags = DUK_JS_COMPILE_FLAG_FUNCEXPR;
+
+	duk_push_hstring_stridx(ctx, DUK_STRIDX_COMPILE);  /* XXX: copy from caller? */  /* XXX: ignored now */
+	h_sourcecode = duk_require_hstring(ctx, -2);
+	duk_js_compile(thr,
+	               (const duk_uint8_t *) DUK_HSTRING_GET_DATA(h_sourcecode),
+	               (duk_size_t) DUK_HSTRING_GET_BYTELEN(h_sourcecode),
+	               comp_flags);
+	func = (duk_hcompiledfunction *) duk_get_hobject(ctx, -1);
+	DUK_ASSERT(func != NULL);
+	DUK_ASSERT(DUK_HOBJECT_IS_COMPILEDFUNCTION((duk_hobject *) func));
+
+	/* [ body formals source template ] */
+
+	/* only outer_lex_env matters, as functions always get a new
+	 * variable declaration environment.
+	 */
+
+	outer_lex_env = thr->builtins[DUK_BIDX_GLOBAL_ENV];
+	outer_var_env = thr->builtins[DUK_BIDX_GLOBAL_ENV];
+
+	duk_js_push_closure(thr, func, outer_var_env, outer_lex_env, 1 /*add_auto_proto*/);
+
+	/* [ body formals source template closure ] */
+
+	return 1;
+}
+
+DUK_INTERNAL duk_ret_t duk_bi_function_prototype(duk_context *ctx) {
+	/* ignore arguments, return undefined (E5 Section 15.3.4) */
+	DUK_UNREF(ctx);
+	return 0;
+}
+
+DUK_INTERNAL duk_ret_t duk_bi_function_prototype_to_string(duk_context *ctx) {
+	duk_tval *tv;
+
+	/*
+	 *  E5 Section 15.3.4.2 places few requirements on the output of
+	 *  this function:
+	 *
+	 *    - The result is an implementation dependent representation
+	 *      of the function; in particular
+	 *
+	 *    - The result must follow the syntax of a FunctionDeclaration.
+	 *      In particular, the function must have a name (even in the
+	 *      case of an anonymous function or a function with an empty
+	 *      name).
+	 *
+	 *    - Note in particular that the output does NOT need to compile
+	 *      into anything useful.
+	 */
+
+
+	/* XXX: faster internal way to get this */
+	duk_push_this(ctx);
+	tv = duk_get_tval(ctx, -1);
+	DUK_ASSERT(tv != NULL);
+
+	if (DUK_TVAL_IS_OBJECT(tv)) {
+		duk_hobject *obj = DUK_TVAL_GET_OBJECT(tv);
+		const char *func_name;
+
+		/* Function name: missing/undefined is mapped to empty string,
+		 * otherwise coerce to string.
+		 */
+		/* XXX: currently no handling for non-allowed identifier characters,
+		 * e.g. a '{' in the function name.
+		 */
+		duk_get_prop_stridx(ctx, -1, DUK_STRIDX_NAME);
+		if (duk_is_undefined(ctx, -1)) {
+			func_name = "";
+		} else {
+			func_name = duk_to_string(ctx, -1);
+			DUK_ASSERT(func_name != NULL);
+		}
+
+		/* Indicate function type in the function body using a dummy
+		 * directive.
+		 */
+		if (DUK_HOBJECT_HAS_COMPILEDFUNCTION(obj)) {
+			duk_push_sprintf(ctx, "function %s() {\"ecmascript\"}", (const char *) func_name);
+		} else if (DUK_HOBJECT_HAS_NATIVEFUNCTION(obj)) {
+			duk_push_sprintf(ctx, "function %s() {\"native\"}", (const char *) func_name);
+		} else if (DUK_HOBJECT_HAS_BOUND(obj)) {
+			duk_push_sprintf(ctx, "function %s() {\"bound\"}", (const char *) func_name);
+		} else {
+			goto type_error;
+		}
+	} else if (DUK_TVAL_IS_LIGHTFUNC(tv)) {
+		duk_push_lightfunc_tostring(ctx, tv);
+	} else {
+		goto type_error;
+	}
+
+	return 1;
+
+ type_error:
+	return DUK_RET_TYPE_ERROR;
+}
+
+DUK_INTERNAL duk_ret_t duk_bi_function_prototype_apply(duk_context *ctx) {
+	duk_idx_t len;
+	duk_idx_t i;
+
+	DUK_ASSERT_TOP(ctx, 2);  /* not a vararg function */
+
+	duk_push_this(ctx);
+	if (!duk_is_callable(ctx, -1)) {
+		DUK_DDD(DUK_DDDPRINT("func is not callable"));
+		goto type_error;
+	}
+	duk_insert(ctx, 0);
+	DUK_ASSERT_TOP(ctx, 3);
+
+	DUK_DDD(DUK_DDDPRINT("func=%!iT, thisArg=%!iT, argArray=%!iT",
+	                     (duk_tval *) duk_get_tval(ctx, 0),
+	                     (duk_tval *) duk_get_tval(ctx, 1),
+	                     (duk_tval *) duk_get_tval(ctx, 2)));
+
+	/* [ func thisArg argArray ] */
+
+	if (duk_is_null_or_undefined(ctx, 2)) {
+		DUK_DDD(DUK_DDDPRINT("argArray is null/undefined, no args"));
+		len = 0;
+	} else if (!duk_is_object(ctx, 2)) {
+		goto type_error;
+	} else {
+		DUK_DDD(DUK_DDDPRINT("argArray is an object"));
+
+		/* XXX: make this an internal helper */
+		duk_get_prop_stridx(ctx, 2, DUK_STRIDX_LENGTH);
+		len = (duk_idx_t) duk_to_uint32(ctx, -1);  /* ToUint32() coercion required */
+		duk_pop(ctx);
+
+		duk_require_stack(ctx, len);
+
+		DUK_DDD(DUK_DDDPRINT("argArray length is %ld", (long) len));
+		for (i = 0; i < len; i++) {
+			duk_get_prop_index(ctx, 2, i);
+		}
+	}
+	duk_remove(ctx, 2);
+	DUK_ASSERT_TOP(ctx, 2 + len);
+
+	/* [ func thisArg arg1 ... argN ] */
+
+	DUK_DDD(DUK_DDDPRINT("apply, func=%!iT, thisArg=%!iT, len=%ld",
+	                     (duk_tval *) duk_get_tval(ctx, 0),
+	                     (duk_tval *) duk_get_tval(ctx, 1),
+	                     (long) len));
+	duk_call_method(ctx, len);
+	return 1;
+
+ type_error:
+	return DUK_RET_TYPE_ERROR;
+}
+
+DUK_INTERNAL duk_ret_t duk_bi_function_prototype_call(duk_context *ctx) {
+	duk_idx_t nargs;
+
+	/* Step 1 is not necessary because duk_call_method() will take
+	 * care of it.
+	 */
+
+	/* vararg function, thisArg needs special handling */
+	nargs = duk_get_top(ctx);  /* = 1 + arg count */
+	if (nargs == 0) {
+		duk_push_undefined(ctx);
+		nargs++;
+	}
+	DUK_ASSERT(nargs >= 1);
+
+	/* [ thisArg arg1 ... argN ] */
+
+	duk_push_this(ctx);  /* 'func' in the algorithm */
+	duk_insert(ctx, 0);
+
+	/* [ func thisArg arg1 ... argN ] */
+
+	DUK_DDD(DUK_DDDPRINT("func=%!iT, thisArg=%!iT, argcount=%ld, top=%ld",
+	                     (duk_tval *) duk_get_tval(ctx, 0),
+	                     (duk_tval *) duk_get_tval(ctx, 1),
+	                     (long) (nargs - 1),
+	                     (long) duk_get_top(ctx)));
+	duk_call_method(ctx, nargs - 1);
+	return 1;
+}
+
+/* XXX: the implementation now assumes "chained" bound functions,
+ * whereas "collapsed" bound functions (where there is ever only
+ * one bound function which directly points to a non-bound, final
+ * function) would require a "collapsing" implementation which
+ * merges argument lists etc here.
+ */
+DUK_INTERNAL duk_ret_t duk_bi_function_prototype_bind(duk_context *ctx) {
+	duk_hobject *h_bound;
+	duk_hobject *h_target;
+	duk_idx_t nargs;
+	duk_idx_t i;
+
+	/* vararg function, careful arg handling (e.g. thisArg may not be present) */
+	nargs = duk_get_top(ctx);  /* = 1 + arg count */
+	if (nargs == 0) {
+		duk_push_undefined(ctx);
+		nargs++;
+	}
+	DUK_ASSERT(nargs >= 1);
+
+	duk_push_this(ctx);
+	if (!duk_is_callable(ctx, -1)) {
+		DUK_DDD(DUK_DDDPRINT("func is not callable"));
+		goto type_error;
+	}
+
+	/* [ thisArg arg1 ... argN func ]  (thisArg+args == nargs total) */
+	DUK_ASSERT_TOP(ctx, nargs + 1);
+
+	/* create bound function object */
+	duk_push_object_helper(ctx,
+	                       DUK_HOBJECT_FLAG_EXTENSIBLE |
+	                       DUK_HOBJECT_FLAG_BOUND |
+	                       DUK_HOBJECT_FLAG_CONSTRUCTABLE |
+	                       DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_FUNCTION),
+	                       DUK_BIDX_FUNCTION_PROTOTYPE);
+	h_bound = duk_get_hobject(ctx, -1);
+	DUK_ASSERT(h_bound != NULL);
+
+	/* [ thisArg arg1 ... argN func boundFunc ] */
+	duk_dup(ctx, -2);  /* func */
+	duk_xdef_prop_stridx(ctx, -2, DUK_STRIDX_INT_TARGET, DUK_PROPDESC_FLAGS_NONE);
+
+	duk_dup(ctx, 0);   /* thisArg */
+	duk_xdef_prop_stridx(ctx, -2, DUK_STRIDX_INT_THIS, DUK_PROPDESC_FLAGS_NONE);
+
+	duk_push_array(ctx);
+
+	/* [ thisArg arg1 ... argN func boundFunc argArray ] */
+
+	for (i = 0; i < nargs - 1; i++) {
+		duk_dup(ctx, 1 + i);
+		duk_put_prop_index(ctx, -2, i);
+	}
+	duk_xdef_prop_stridx(ctx, -2, DUK_STRIDX_INT_ARGS, DUK_PROPDESC_FLAGS_NONE);
+
+	/* [ thisArg arg1 ... argN func boundFunc ] */
+
+	/* bound function 'length' property is interesting */
+	h_target = duk_get_hobject(ctx, -2);
+	if (h_target == NULL ||  /* lightfunc */
+	    DUK_HOBJECT_GET_CLASS_NUMBER(h_target) == DUK_HOBJECT_CLASS_FUNCTION) {
+		/* For lightfuncs, simply read the virtual property. */
+		duk_int_t tmp;
+		duk_get_prop_stridx(ctx, -2, DUK_STRIDX_LENGTH);
+		tmp = duk_to_int(ctx, -1) - (nargs - 1);  /* step 15.a */
+		duk_pop(ctx);
+		duk_push_int(ctx, (tmp < 0 ? 0 : tmp));
+	} else {
+		duk_push_int(ctx, 0);
+	}
+	duk_xdef_prop_stridx(ctx, -2, DUK_STRIDX_LENGTH, DUK_PROPDESC_FLAGS_NONE);  /* attrs in E5 Section 15.3.5.1 */
+
+	/* caller and arguments must use the same thrower, [[ThrowTypeError]] */
+	duk_xdef_prop_stridx_thrower(ctx, -1, DUK_STRIDX_CALLER, DUK_PROPDESC_FLAGS_NONE);
+	duk_xdef_prop_stridx_thrower(ctx, -1, DUK_STRIDX_LC_ARGUMENTS, DUK_PROPDESC_FLAGS_NONE);
+
+	/* these non-standard properties are copied for convenience */
+	/* XXX: 'copy properties' API call? */
+	duk_get_prop_stridx(ctx, -2, DUK_STRIDX_NAME);
+	duk_xdef_prop_stridx(ctx, -2, DUK_STRIDX_NAME, DUK_PROPDESC_FLAGS_WC);
+	duk_get_prop_stridx(ctx, -2, DUK_STRIDX_FILE_NAME);
+	duk_xdef_prop_stridx(ctx, -2, DUK_STRIDX_FILE_NAME, DUK_PROPDESC_FLAGS_WC);
+
+	/* The 'strict' flag is copied to get the special [[Get]] of E5.1
+	 * Section 15.3.5.4 to apply when a 'caller' value is a strict bound
+	 * function.  Not sure if this is correct, because the specification
+	 * is a bit ambiguous on this point but it would make sense.
+	 */
+	if (h_target == NULL) {
+		/* Lightfuncs are always strict. */
+		DUK_HOBJECT_SET_STRICT(h_bound);
+	} else if (DUK_HOBJECT_HAS_STRICT(h_target)) {
+		DUK_HOBJECT_SET_STRICT(h_bound);
+	}
+	DUK_DDD(DUK_DDDPRINT("created bound function: %!iT", (duk_tval *) duk_get_tval(ctx, -1)));
+
+	return 1;
+
+ type_error:
+	return DUK_RET_TYPE_ERROR;
+}

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_bi_global.c
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_bi_global.c b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_bi_global.c
new file mode 100644
index 0000000..c01f7c1
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_bi_global.c
@@ -0,0 +1,1288 @@
+/*
+ *  Global object built-ins
+ */
+
+#include "duk_internal.h"
+
+/*
+ *  Encoding/decoding helpers
+ */
+
+/* XXX: Could add fast path (for each transform callback) with direct byte
+ * lookups (no shifting) and no explicit check for x < 0x80 before table
+ * lookup.
+ */
+
+/* Macros for creating and checking bitmasks for character encoding.
+ * Bit number is a bit counterintuitive, but minimizes code size.
+ */
+#define DUK__MKBITS(a,b,c,d,e,f,g,h)  ((duk_uint8_t) ( \
+	((a) << 0) | ((b) << 1) | ((c) << 2) | ((d) << 3) | \
+	((e) << 4) | ((f) << 5) | ((g) << 6) | ((h) << 7) \
+	))
+#define DUK__CHECK_BITMASK(table,cp)  ((table)[(cp) >> 3] & (1 << ((cp) & 0x07)))
+
+/* E5.1 Section 15.1.3.3: uriReserved + uriUnescaped + '#' */
+DUK_LOCAL const duk_uint8_t duk__encode_uriunescaped_table[16] = {
+	DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0),  /* 0x00-0x0f */
+	DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0),  /* 0x10-0x1f */
+	DUK__MKBITS(0, 1, 0, 1, 1, 0, 1, 1), DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1),  /* 0x20-0x2f */
+	DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 1, 0, 1, 0, 1),  /* 0x30-0x3f */
+	DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1),  /* 0x40-0x4f */
+	DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 0, 0, 0, 0, 1),  /* 0x50-0x5f */
+	DUK__MKBITS(0, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1),  /* 0x60-0x6f */
+	DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 0, 0, 0, 1, 0),  /* 0x70-0x7f */
+};
+
+/* E5.1 Section 15.1.3.4: uriUnescaped */
+DUK_LOCAL const duk_uint8_t duk__encode_uricomponent_unescaped_table[16] = {
+	DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0),  /* 0x00-0x0f */
+	DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0),  /* 0x10-0x1f */
+	DUK__MKBITS(0, 1, 0, 0, 0, 0, 0, 1), DUK__MKBITS(1, 1, 1, 0, 0, 1, 1, 0),  /* 0x20-0x2f */
+	DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 0, 0, 0, 0, 0, 0),  /* 0x30-0x3f */
+	DUK__MKBITS(0, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1),  /* 0x40-0x4f */
+	DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 0, 0, 0, 0, 1),  /* 0x50-0x5f */
+	DUK__MKBITS(0, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1),  /* 0x60-0x6f */
+	DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 0, 0, 0, 1, 0),  /* 0x70-0x7f */
+};
+
+/* E5.1 Section 15.1.3.1: uriReserved + '#' */
+DUK_LOCAL const duk_uint8_t duk__decode_uri_reserved_table[16] = {
+	DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0),  /* 0x00-0x0f */
+	DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0),  /* 0x10-0x1f */
+	DUK__MKBITS(0, 0, 0, 1, 1, 0, 1, 0), DUK__MKBITS(0, 0, 0, 1, 1, 0, 0, 1),  /* 0x20-0x2f */
+	DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 1, 1, 0, 1, 0, 1),  /* 0x30-0x3f */
+	DUK__MKBITS(1, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0),  /* 0x40-0x4f */
+	DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0),  /* 0x50-0x5f */
+	DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0),  /* 0x60-0x6f */
+	DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0),  /* 0x70-0x7f */
+};
+
+/* E5.1 Section 15.1.3.2: empty */
+DUK_LOCAL const duk_uint8_t duk__decode_uri_component_reserved_table[16] = {
+	DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0),  /* 0x00-0x0f */
+	DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0),  /* 0x10-0x1f */
+	DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0),  /* 0x20-0x2f */
+	DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0),  /* 0x30-0x3f */
+	DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0),  /* 0x40-0x4f */
+	DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0),  /* 0x50-0x5f */
+	DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0),  /* 0x60-0x6f */
+	DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0),  /* 0x70-0x7f */
+};
+
+#ifdef DUK_USE_SECTION_B
+/* E5.1 Section B.2.2, step 7. */
+DUK_LOCAL const duk_uint8_t duk__escape_unescaped_table[16] = {
+	DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0),  /* 0x00-0x0f */
+	DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0),  /* 0x10-0x1f */
+	DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 1, 1, 0, 1, 1, 1),  /* 0x20-0x2f */
+	DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 0, 0, 0, 0, 0, 0),  /* 0x30-0x3f */
+	DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1),  /* 0x40-0x4f */
+	DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 0, 0, 0, 0, 1),  /* 0x50-0x5f */
+	DUK__MKBITS(0, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1),  /* 0x60-0x6f */
+	DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 0, 0, 0, 0, 0)   /* 0x70-0x7f */
+};
+#endif  /* DUK_USE_SECTION_B */
+
+#undef DUK__MKBITS
+
+typedef struct {
+	duk_hthread *thr;
+	duk_hstring *h_str;
+	duk_bufwriter_ctx bw;
+	const duk_uint8_t *p;
+	const duk_uint8_t *p_start;
+	const duk_uint8_t *p_end;
+} duk__transform_context;
+
+typedef void (*duk__transform_callback)(duk__transform_context *tfm_ctx, const void *udata, duk_codepoint_t cp);
+
+/* XXX: refactor and share with other code */
+DUK_LOCAL duk_small_int_t duk__decode_hex_escape(const duk_uint8_t *p, duk_small_int_t n) {
+	duk_small_int_t ch;
+	duk_small_int_t t = 0;
+
+	while (n > 0) {
+		t = t * 16;
+		ch = (duk_small_int_t) duk_hex_dectab[*p++];
+		if (DUK_LIKELY(ch >= 0)) {
+			t += ch;
+		} else {
+			return -1;
+		}
+		n--;
+	}
+	return t;
+}
+
+DUK_LOCAL int duk__transform_helper(duk_context *ctx, duk__transform_callback callback, const void *udata) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk__transform_context tfm_ctx_alloc;
+	duk__transform_context *tfm_ctx = &tfm_ctx_alloc;
+	duk_codepoint_t cp;
+
+	tfm_ctx->thr = thr;
+
+	tfm_ctx->h_str = duk_to_hstring(ctx, 0);
+	DUK_ASSERT(tfm_ctx->h_str != NULL);
+
+	DUK_BW_INIT_PUSHBUF(thr, &tfm_ctx->bw, DUK_HSTRING_GET_BYTELEN(tfm_ctx->h_str));  /* initial size guess */
+
+	tfm_ctx->p_start = DUK_HSTRING_GET_DATA(tfm_ctx->h_str);
+	tfm_ctx->p_end = tfm_ctx->p_start + DUK_HSTRING_GET_BYTELEN(tfm_ctx->h_str);
+	tfm_ctx->p = tfm_ctx->p_start;
+
+	while (tfm_ctx->p < tfm_ctx->p_end) {
+		cp = (duk_codepoint_t) duk_unicode_decode_xutf8_checked(thr, &tfm_ctx->p, tfm_ctx->p_start, tfm_ctx->p_end);
+		callback(tfm_ctx, udata, cp);
+	}
+
+	DUK_BW_COMPACT(thr, &tfm_ctx->bw);
+
+	duk_to_string(ctx, -1);
+	return 1;
+}
+
+DUK_LOCAL void duk__transform_callback_encode_uri(duk__transform_context *tfm_ctx, const void *udata, duk_codepoint_t cp) {
+	duk_uint8_t xutf8_buf[DUK_UNICODE_MAX_XUTF8_LENGTH];
+	duk_small_int_t len;
+	duk_codepoint_t cp1, cp2;
+	duk_small_int_t i, t;
+	const duk_uint8_t *unescaped_table = (const duk_uint8_t *) udata;
+
+	/* UTF-8 encoded bytes escaped as %xx%xx%xx... -> 3 * nbytes.
+	 * Codepoint range is restricted so this is a slightly too large
+	 * but doesn't matter.
+	 */
+	DUK_BW_ENSURE(tfm_ctx->thr, &tfm_ctx->bw, 3 * DUK_UNICODE_MAX_XUTF8_LENGTH);
+
+	if (cp < 0) {
+		goto uri_error;
+	} else if ((cp < 0x80L) && DUK__CHECK_BITMASK(unescaped_table, cp)) {
+		DUK_BW_WRITE_RAW_U8(tfm_ctx->thr, &tfm_ctx->bw, (duk_uint8_t) cp);
+		return;
+	} else if (cp >= 0xdc00L && cp <= 0xdfffL) {
+		goto uri_error;
+	} else if (cp >= 0xd800L && cp <= 0xdbffL) {
+		/* Needs lookahead */
+		if (duk_unicode_decode_xutf8(tfm_ctx->thr, &tfm_ctx->p, tfm_ctx->p_start, tfm_ctx->p_end, (duk_ucodepoint_t *) &cp2) == 0) {
+			goto uri_error;
+		}
+		if (!(cp2 >= 0xdc00L && cp2 <= 0xdfffL)) {
+			goto uri_error;
+		}
+		cp1 = cp;
+		cp = ((cp1 - 0xd800L) << 10) + (cp2 - 0xdc00L) + 0x10000L;
+	} else if (cp > 0x10ffffL) {
+		/* Although we can allow non-BMP characters (they'll decode
+		 * back into surrogate pairs), we don't allow extended UTF-8
+		 * characters; they would encode to URIs which won't decode
+		 * back because of strict UTF-8 checks in URI decoding.
+		 * (However, we could just as well allow them here.)
+		 */
+		goto uri_error;
+	} else {
+		/* Non-BMP characters within valid UTF-8 range: encode as is.
+		 * They'll decode back into surrogate pairs if the escaped
+		 * output is decoded.
+		 */
+		;
+	}
+
+	len = duk_unicode_encode_xutf8((duk_ucodepoint_t) cp, xutf8_buf);
+	for (i = 0; i < len; i++) {
+		t = (int) xutf8_buf[i];
+		DUK_BW_WRITE_RAW_U8_3(tfm_ctx->thr,
+		                      &tfm_ctx->bw,
+		                      DUK_ASC_PERCENT,
+		                      (duk_uint8_t) duk_uc_nybbles[t >> 4],
+                                      (duk_uint8_t) duk_uc_nybbles[t & 0x0f]);
+	}
+
+	return;
+
+ uri_error:
+	DUK_ERROR(tfm_ctx->thr, DUK_ERR_URI_ERROR, "invalid input");
+}
+
+DUK_LOCAL void duk__transform_callback_decode_uri(duk__transform_context *tfm_ctx, const void *udata, duk_codepoint_t cp) {
+	const duk_uint8_t *reserved_table = (const duk_uint8_t *) udata;
+	duk_small_uint_t utf8_blen;
+	duk_codepoint_t min_cp;
+	duk_small_int_t t;  /* must be signed */
+	duk_small_uint_t i;
+
+	/* Maximum write size: XUTF8 path writes max DUK_UNICODE_MAX_XUTF8_LENGTH,
+	 * percent escape path writes max two times CESU-8 encoded BMP length.
+	 */
+	DUK_BW_ENSURE(tfm_ctx->thr,
+	              &tfm_ctx->bw,
+	              (DUK_UNICODE_MAX_XUTF8_LENGTH >= 2 * DUK_UNICODE_MAX_CESU8_BMP_LENGTH ?
+	              DUK_UNICODE_MAX_XUTF8_LENGTH : DUK_UNICODE_MAX_CESU8_BMP_LENGTH));
+
+	if (cp == (duk_codepoint_t) '%') {
+		const duk_uint8_t *p = tfm_ctx->p;
+		duk_size_t left = (duk_size_t) (tfm_ctx->p_end - p);  /* bytes left */
+
+		DUK_DDD(DUK_DDDPRINT("percent encoding, left=%ld", (long) left));
+
+		if (left < 2) {
+			goto uri_error;
+		}
+
+		t = duk__decode_hex_escape(p, 2);
+		DUK_DDD(DUK_DDDPRINT("first byte: %ld", (long) t));
+		if (t < 0) {
+			goto uri_error;
+		}
+
+		if (t < 0x80) {
+			if (DUK__CHECK_BITMASK(reserved_table, t)) {
+				/* decode '%xx' to '%xx' if decoded char in reserved set */
+				DUK_ASSERT(tfm_ctx->p - 1 >= tfm_ctx->p_start);
+				DUK_BW_WRITE_RAW_U8_3(tfm_ctx->thr,
+				                      &tfm_ctx->bw,
+				                      DUK_ASC_PERCENT,
+				                      p[0],
+				                      p[1]);
+			} else {
+				DUK_BW_WRITE_RAW_U8(tfm_ctx->thr, &tfm_ctx->bw, (duk_uint8_t) t);
+			}
+			tfm_ctx->p += 2;
+			return;
+		}
+
+		/* Decode UTF-8 codepoint from a sequence of hex escapes.  The
+		 * first byte of the sequence has been decoded to 't'.
+		 *
+		 * Note that UTF-8 validation must be strict according to the
+		 * specification: E5.1 Section 15.1.3, decode algorithm step
+		 * 4.d.vii.8.  URIError from non-shortest encodings is also
+		 * specifically noted in the spec.
+		 */
+
+		DUK_ASSERT(t >= 0x80);
+		if (t < 0xc0) {
+			/* continuation byte */
+			goto uri_error;
+		} else if (t < 0xe0) {
+			/* 110x xxxx; 2 bytes */
+			utf8_blen = 2;
+			min_cp = 0x80L;
+			cp = t & 0x1f;
+		} else if (t < 0xf0) {
+			/* 1110 xxxx; 3 bytes */
+			utf8_blen = 3;
+			min_cp = 0x800L;
+			cp = t & 0x0f;
+		} else if (t < 0xf8) {
+			/* 1111 0xxx; 4 bytes */
+			utf8_blen = 4;
+			min_cp = 0x10000L;
+			cp = t & 0x07;
+		} else {
+			/* extended utf-8 not allowed for URIs */
+			goto uri_error;
+		}
+
+		if (left < utf8_blen * 3 - 1) {
+			/* '%xx%xx...%xx', p points to char after first '%' */
+			goto uri_error;
+		}
+
+		p += 3;
+		for (i = 1; i < utf8_blen; i++) {
+			/* p points to digit part ('%xy', p points to 'x') */
+			t = duk__decode_hex_escape(p, 2);
+			DUK_DDD(DUK_DDDPRINT("i=%ld utf8_blen=%ld cp=%ld t=0x%02lx",
+			                     (long) i, (long) utf8_blen, (long) cp, (unsigned long) t));
+			if (t < 0) {
+				goto uri_error;
+			}
+			if ((t & 0xc0) != 0x80) {
+				goto uri_error;
+			}
+			cp = (cp << 6) + (t & 0x3f);
+			p += 3;
+		}
+		p--;  /* p overshoots */
+		tfm_ctx->p = p;
+
+		DUK_DDD(DUK_DDDPRINT("final cp=%ld, min_cp=%ld", (long) cp, (long) min_cp));
+
+		if (cp < min_cp || cp > 0x10ffffL || (cp >= 0xd800L && cp <= 0xdfffL)) {
+			goto uri_error;
+		}
+
+		/* The E5.1 algorithm checks whether or not a decoded codepoint
+		 * is below 0x80 and perhaps may be in the "reserved" set.
+		 * This seems pointless because the single byte UTF-8 case is
+		 * handled separately, and non-shortest encodings are rejected.
+		 * So, 'cp' cannot be below 0x80 here, and thus cannot be in
+		 * the reserved set.
+		 */
+
+		/* utf-8 validation ensures these */
+		DUK_ASSERT(cp >= 0x80L && cp <= 0x10ffffL);
+
+		if (cp >= 0x10000L) {
+			cp -= 0x10000L;
+			DUK_ASSERT(cp < 0x100000L);
+
+			DUK_BW_WRITE_RAW_XUTF8(tfm_ctx->thr, &tfm_ctx->bw, ((cp >> 10) + 0xd800L));
+			DUK_BW_WRITE_RAW_XUTF8(tfm_ctx->thr, &tfm_ctx->bw, ((cp & 0x03ffUL) + 0xdc00L));
+		} else {
+			DUK_BW_WRITE_RAW_XUTF8(tfm_ctx->thr, &tfm_ctx->bw, cp);
+		}
+	} else {
+		DUK_BW_WRITE_RAW_XUTF8(tfm_ctx->thr, &tfm_ctx->bw, cp);
+	}
+	return;
+
+ uri_error:
+	DUK_ERROR(tfm_ctx->thr, DUK_ERR_URI_ERROR, "invalid input");
+}
+
+#ifdef DUK_USE_SECTION_B
+DUK_LOCAL void duk__transform_callback_escape(duk__transform_context *tfm_ctx, const void *udata, duk_codepoint_t cp) {
+	DUK_UNREF(udata);
+
+	DUK_BW_ENSURE(tfm_ctx->thr, &tfm_ctx->bw, 6);
+
+	if (cp < 0) {
+		goto esc_error;
+	} else if ((cp < 0x80L) && DUK__CHECK_BITMASK(duk__escape_unescaped_table, cp)) {
+		DUK_BW_WRITE_RAW_U8(tfm_ctx->thr, &tfm_ctx->bw, (duk_uint8_t) cp);
+	} else if (cp < 0x100L) {
+		DUK_BW_WRITE_RAW_U8_3(tfm_ctx->thr,
+		                      &tfm_ctx->bw,
+		                      (duk_uint8_t) DUK_ASC_PERCENT,
+		                      (duk_uint8_t) duk_uc_nybbles[cp >> 4],
+		                      (duk_uint8_t) duk_uc_nybbles[cp & 0x0f]);
+	} else if (cp < 0x10000L) {
+		DUK_BW_WRITE_RAW_U8_6(tfm_ctx->thr,
+		                      &tfm_ctx->bw,
+		                      (duk_uint8_t) DUK_ASC_PERCENT,
+		                      (duk_uint8_t) DUK_ASC_LC_U,
+		                      (duk_uint8_t) duk_uc_nybbles[cp >> 12],
+		                      (duk_uint8_t) duk_uc_nybbles[(cp >> 8) & 0x0f],
+		                      (duk_uint8_t) duk_uc_nybbles[(cp >> 4) & 0x0f],
+		                      (duk_uint8_t) duk_uc_nybbles[cp & 0x0f]);
+	} else {
+		/* Characters outside BMP cannot be escape()'d.  We could
+		 * encode them as surrogate pairs (for codepoints inside
+		 * valid UTF-8 range, but not extended UTF-8).  Because
+		 * escape() and unescape() are legacy functions, we don't.
+		 */
+		goto esc_error;
+	}
+
+	return;
+
+ esc_error:
+	DUK_ERROR_TYPE(tfm_ctx->thr, "invalid input");
+}
+
+DUK_LOCAL void duk__transform_callback_unescape(duk__transform_context *tfm_ctx, const void *udata, duk_codepoint_t cp) {
+	duk_small_int_t t;
+
+	DUK_UNREF(udata);
+
+	if (cp == (duk_codepoint_t) '%') {
+		const duk_uint8_t *p = tfm_ctx->p;
+		duk_size_t left = (duk_size_t) (tfm_ctx->p_end - p);  /* bytes left */
+
+		if (left >= 5 && p[0] == 'u' &&
+		    ((t = duk__decode_hex_escape(p + 1, 4)) >= 0)) {
+			cp = (duk_codepoint_t) t;
+			tfm_ctx->p += 5;
+		} else if (left >= 2 &&
+		           ((t = duk__decode_hex_escape(p, 2)) >= 0)) {
+			cp = (duk_codepoint_t) t;
+			tfm_ctx->p += 2;
+		}
+	}
+
+	DUK_BW_WRITE_ENSURE_XUTF8(tfm_ctx->thr, &tfm_ctx->bw, cp);
+}
+#endif  /* DUK_USE_SECTION_B */
+
+/*
+ *  Eval
+ *
+ *  Eval needs to handle both a "direct eval" and an "indirect eval".
+ *  Direct eval handling needs access to the caller's activation so that its
+ *  lexical environment can be accessed.  A direct eval is only possible from
+ *  Ecmascript code; an indirect eval call is possible also from C code.
+ *  When an indirect eval call is made from C code, there may not be a
+ *  calling activation at all which needs careful handling.
+ */
+
+DUK_INTERNAL duk_ret_t duk_bi_global_object_eval(duk_context *ctx) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_hstring *h;
+	duk_activation *act_caller;
+	duk_activation *act_eval;
+	duk_activation *act;
+	duk_hcompiledfunction *func;
+	duk_hobject *outer_lex_env;
+	duk_hobject *outer_var_env;
+	duk_bool_t this_to_global = 1;
+	duk_small_uint_t comp_flags;
+	duk_int_t level = -2;
+
+	DUK_ASSERT(duk_get_top(ctx) == 1 || duk_get_top(ctx) == 2);  /* 2 when called by debugger */
+	DUK_ASSERT(thr->callstack_top >= 1);  /* at least this function exists */
+	DUK_ASSERT(((thr->callstack + thr->callstack_top - 1)->flags & DUK_ACT_FLAG_DIRECT_EVAL) == 0 || /* indirect eval */
+	           (thr->callstack_top >= 2));  /* if direct eval, calling activation must exist */
+
+	/*
+	 *  callstack_top - 1 --> this function
+	 *  callstack_top - 2 --> caller (may not exist)
+	 *
+	 *  If called directly from C, callstack_top might be 1.  If calling
+	 *  activation doesn't exist, call must be indirect.
+	 */
+
+	h = duk_get_hstring(ctx, 0);
+	if (!h) {
+		return 1;  /* return arg as-is */
+	}
+
+#if defined(DUK_USE_DEBUGGER_SUPPORT)
+	/* NOTE: level is used only by the debugger and should never be present
+	 * for an Ecmascript eval().
+	 */
+	DUK_ASSERT(level == -2);  /* by default, use caller's environment */
+	if (duk_get_top(ctx) >= 2 && duk_is_number(ctx, 1)) {
+		level = duk_get_int(ctx, 1);
+	}
+	DUK_ASSERT(level <= -2);  /* This is guaranteed by debugger code. */
+#endif
+
+	/* [ source ] */
+
+	comp_flags = DUK_JS_COMPILE_FLAG_EVAL;
+	act_eval = thr->callstack + thr->callstack_top - 1;    /* this function */
+	if (thr->callstack_top >= (duk_size_t) -level) {
+		/* Have a calling activation, check for direct eval (otherwise
+		 * assume indirect eval.
+		 */
+		act_caller = thr->callstack + thr->callstack_top + level;  /* caller */
+		if ((act_caller->flags & DUK_ACT_FLAG_STRICT) &&
+		    (act_eval->flags & DUK_ACT_FLAG_DIRECT_EVAL)) {
+			/* Only direct eval inherits strictness from calling code
+			 * (E5.1 Section 10.1.1).
+			 */
+			comp_flags |= DUK_JS_COMPILE_FLAG_STRICT;
+		}
+	} else {
+		DUK_ASSERT((act_eval->flags & DUK_ACT_FLAG_DIRECT_EVAL) == 0);
+	}
+	act_caller = NULL;  /* avoid dereference after potential callstack realloc */
+	act_eval = NULL;
+
+	duk_push_hstring_stridx(ctx, DUK_STRIDX_INPUT);  /* XXX: copy from caller? */
+	duk_js_compile(thr,
+	               (const duk_uint8_t *) DUK_HSTRING_GET_DATA(h),
+	               (duk_size_t) DUK_HSTRING_GET_BYTELEN(h),
+	               comp_flags);
+	func = (duk_hcompiledfunction *) duk_get_hobject(ctx, -1);
+	DUK_ASSERT(func != NULL);
+	DUK_ASSERT(DUK_HOBJECT_IS_COMPILEDFUNCTION((duk_hobject *) func));
+
+	/* [ source template ] */
+
+	/* E5 Section 10.4.2 */
+	DUK_ASSERT(thr->callstack_top >= 1);
+	act = thr->callstack + thr->callstack_top - 1;  /* this function */
+	if (act->flags & DUK_ACT_FLAG_DIRECT_EVAL) {
+		DUK_ASSERT(thr->callstack_top >= 2);
+		act = thr->callstack + thr->callstack_top + level;  /* caller */
+		if (act->lex_env == NULL) {
+			DUK_ASSERT(act->var_env == NULL);
+			DUK_DDD(DUK_DDDPRINT("delayed environment initialization"));
+
+			/* this may have side effects, so re-lookup act */
+			duk_js_init_activation_environment_records_delayed(thr, act);
+			act = thr->callstack + thr->callstack_top + level;
+		}
+		DUK_ASSERT(act->lex_env != NULL);
+		DUK_ASSERT(act->var_env != NULL);
+
+		this_to_global = 0;
+
+		if (DUK_HOBJECT_HAS_STRICT((duk_hobject *) func)) {
+			duk_hobject *new_env;
+			duk_hobject *act_lex_env;
+
+			DUK_DDD(DUK_DDDPRINT("direct eval call to a strict function -> "
+			                     "var_env and lex_env to a fresh env, "
+			                     "this_binding to caller's this_binding"));
+
+			act = thr->callstack + thr->callstack_top + level;  /* caller */
+			act_lex_env = act->lex_env;
+			act = NULL;  /* invalidated */
+
+			(void) duk_push_object_helper_proto(ctx,
+			                                    DUK_HOBJECT_FLAG_EXTENSIBLE |
+			                                    DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_DECENV),
+			                                    act_lex_env);
+			new_env = duk_require_hobject(ctx, -1);
+			DUK_ASSERT(new_env != NULL);
+			DUK_DDD(DUK_DDDPRINT("new_env allocated: %!iO",
+			                     (duk_heaphdr *) new_env));
+
+			outer_lex_env = new_env;
+			outer_var_env = new_env;
+
+			duk_insert(ctx, 0);  /* stash to bottom of value stack to keep new_env reachable for duration of eval */
+
+			/* compiler's responsibility */
+			DUK_ASSERT(DUK_HOBJECT_HAS_NEWENV((duk_hobject *) func));
+		} else {
+			DUK_DDD(DUK_DDDPRINT("direct eval call to a non-strict function -> "
+			                     "var_env and lex_env to caller's envs, "
+			                     "this_binding to caller's this_binding"));
+
+			outer_lex_env = act->lex_env;
+			outer_var_env = act->var_env;
+
+			/* compiler's responsibility */
+			DUK_ASSERT(!DUK_HOBJECT_HAS_NEWENV((duk_hobject *) func));
+		}
+	} else {
+		DUK_DDD(DUK_DDDPRINT("indirect eval call -> var_env and lex_env to "
+		                     "global object, this_binding to global object"));
+
+		this_to_global = 1;
+		outer_lex_env = thr->builtins[DUK_BIDX_GLOBAL_ENV];
+		outer_var_env = thr->builtins[DUK_BIDX_GLOBAL_ENV];
+	}
+	act = NULL;
+
+	/* Eval code doesn't need an automatic .prototype object. */
+	duk_js_push_closure(thr, func, outer_var_env, outer_lex_env, 0 /*add_auto_proto*/);
+
+	/* [ source template closure ] */
+
+	if (this_to_global) {
+		DUK_ASSERT(thr->builtins[DUK_BIDX_GLOBAL] != NULL);
+		duk_push_hobject_bidx(ctx, DUK_BIDX_GLOBAL);
+	} else {
+		duk_tval *tv;
+		DUK_ASSERT(thr->callstack_top >= 2);
+		act = thr->callstack + thr->callstack_top + level;  /* caller */
+		tv = thr->valstack + act->idx_bottom - 1;  /* this is just beneath bottom */
+		DUK_ASSERT(tv >= thr->valstack);
+		duk_push_tval(ctx, tv);
+	}
+
+	DUK_DDD(DUK_DDDPRINT("eval -> lex_env=%!iO, var_env=%!iO, this_binding=%!T",
+	                     (duk_heaphdr *) outer_lex_env,
+	                     (duk_heaphdr *) outer_var_env,
+	                     duk_get_tval(ctx, -1)));
+
+	/* [ source template closure this ] */
+
+	duk_call_method(ctx, 0);
+
+	/* [ source template result ] */
+
+	return 1;
+}
+
+/*
+ *  Parsing of ints and floats
+ */
+
+DUK_INTERNAL duk_ret_t duk_bi_global_object_parse_int(duk_context *ctx) {
+	duk_int32_t radix;
+	duk_small_uint_t s2n_flags;
+
+	DUK_ASSERT_TOP(ctx, 2);
+	duk_to_string(ctx, 0);
+
+	radix = duk_to_int32(ctx, 1);
+
+	s2n_flags = DUK_S2N_FLAG_TRIM_WHITE |
+	            DUK_S2N_FLAG_ALLOW_GARBAGE |
+	            DUK_S2N_FLAG_ALLOW_PLUS |
+	            DUK_S2N_FLAG_ALLOW_MINUS |
+	            DUK_S2N_FLAG_ALLOW_LEADING_ZERO |
+	            DUK_S2N_FLAG_ALLOW_AUTO_HEX_INT;
+
+	/* Specification stripPrefix maps to DUK_S2N_FLAG_ALLOW_AUTO_HEX_INT.
+	 *
+	 * Don't autodetect octals (from leading zeroes), require user code to
+	 * provide an explicit radix 8 for parsing octal.  See write-up from Mozilla:
+	 * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt#ECMAScript_5_Removes_Octal_Interpretation
+	 */
+
+	if (radix != 0) {
+		if (radix < 2 || radix > 36) {
+			goto ret_nan;
+		}
+		if (radix != 16) {
+			s2n_flags &= ~DUK_S2N_FLAG_ALLOW_AUTO_HEX_INT;
+		}
+	} else {
+		radix = 10;
+	}
+
+	duk_dup(ctx, 0);
+	duk_numconv_parse(ctx, radix, s2n_flags);
+	return 1;
+
+ ret_nan:
+	duk_push_nan(ctx);
+	return 1;
+}
+
+DUK_INTERNAL duk_ret_t duk_bi_global_object_parse_float(duk_context *ctx) {
+	duk_small_uint_t s2n_flags;
+	duk_int32_t radix;
+
+	DUK_ASSERT_TOP(ctx, 1);
+	duk_to_string(ctx, 0);
+
+	radix = 10;
+
+	/* XXX: check flags */
+	s2n_flags = DUK_S2N_FLAG_TRIM_WHITE |
+	            DUK_S2N_FLAG_ALLOW_EXP |
+	            DUK_S2N_FLAG_ALLOW_GARBAGE |
+	            DUK_S2N_FLAG_ALLOW_PLUS |
+	            DUK_S2N_FLAG_ALLOW_MINUS |
+	            DUK_S2N_FLAG_ALLOW_INF |
+	            DUK_S2N_FLAG_ALLOW_FRAC |
+	            DUK_S2N_FLAG_ALLOW_NAKED_FRAC |
+	            DUK_S2N_FLAG_ALLOW_EMPTY_FRAC |
+	            DUK_S2N_FLAG_ALLOW_LEADING_ZERO;
+
+	duk_numconv_parse(ctx, radix, s2n_flags);
+	return 1;
+}
+
+/*
+ *  Number checkers
+ */
+
+DUK_INTERNAL duk_ret_t duk_bi_global_object_is_nan(duk_context *ctx) {
+	duk_double_t d = duk_to_number(ctx, 0);
+	duk_push_boolean(ctx, DUK_ISNAN(d));
+	return 1;
+}
+
+DUK_INTERNAL duk_ret_t duk_bi_global_object_is_finite(duk_context *ctx) {
+	duk_double_t d = duk_to_number(ctx, 0);
+	duk_push_boolean(ctx, DUK_ISFINITE(d));
+	return 1;
+}
+
+/*
+ *  URI handling
+ */
+
+DUK_INTERNAL duk_ret_t duk_bi_global_object_decode_uri(duk_context *ctx) {
+	return duk__transform_helper(ctx, duk__transform_callback_decode_uri, (const void *) duk__decode_uri_reserved_table);
+}
+
+DUK_INTERNAL duk_ret_t duk_bi_global_object_decode_uri_component(duk_context *ctx) {
+	return duk__transform_helper(ctx, duk__transform_callback_decode_uri, (const void *) duk__decode_uri_component_reserved_table);
+}
+
+DUK_INTERNAL duk_ret_t duk_bi_global_object_encode_uri(duk_context *ctx) {
+	return duk__transform_helper(ctx, duk__transform_callback_encode_uri, (const void *) duk__encode_uriunescaped_table);
+}
+
+DUK_INTERNAL duk_ret_t duk_bi_global_object_encode_uri_component(duk_context *ctx) {
+	return duk__transform_helper(ctx, duk__transform_callback_encode_uri, (const void *) duk__encode_uricomponent_unescaped_table);
+}
+
+#ifdef DUK_USE_SECTION_B
+DUK_INTERNAL duk_ret_t duk_bi_global_object_escape(duk_context *ctx) {
+	return duk__transform_helper(ctx, duk__transform_callback_escape, (const void *) NULL);
+}
+
+DUK_INTERNAL duk_ret_t duk_bi_global_object_unescape(duk_context *ctx) {
+	return duk__transform_helper(ctx, duk__transform_callback_unescape, (const void *) NULL);
+}
+#else  /* DUK_USE_SECTION_B */
+DUK_INTERNAL duk_ret_t duk_bi_global_object_escape(duk_context *ctx) {
+	DUK_UNREF(ctx);
+	return DUK_RET_UNSUPPORTED_ERROR;
+}
+
+DUK_INTERNAL duk_ret_t duk_bi_global_object_unescape(duk_context *ctx) {
+	DUK_UNREF(ctx);
+	return DUK_RET_UNSUPPORTED_ERROR;
+}
+#endif  /* DUK_USE_SECTION_B */
+
+#if defined(DUK_USE_BROWSER_LIKE) && (defined(DUK_USE_FILE_IO) || defined(DUK_USE_DEBUGGER_SUPPORT))
+DUK_INTERNAL duk_ret_t duk_bi_global_object_print_helper(duk_context *ctx) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_int_t magic;
+	duk_idx_t nargs;
+	const duk_uint8_t *buf;
+	duk_size_t sz_buf;
+	const char nl = (const char) DUK_ASC_LF;
+#ifndef DUK_USE_PREFER_SIZE
+	duk_uint8_t buf_stack[256];
+#endif
+#ifdef DUK_USE_FILE_IO
+	duk_file *f_out;
+#endif
+
+	DUK_UNREF(thr);
+
+	magic = duk_get_current_magic(ctx);
+	DUK_UNREF(magic);
+
+	nargs = duk_get_top(ctx);
+
+	/* If argument count is 1 and first argument is a buffer, write the buffer
+	 * as raw data into the file without a newline; this allows exact control
+	 * over stdout/stderr without an additional entrypoint (useful for now).
+	 *
+	 * Otherwise current print/alert semantics are to ToString() coerce
+	 * arguments, join them with a single space, and append a newline.
+	 */
+
+	if (nargs == 1 && duk_is_buffer(ctx, 0)) {
+		buf = (const duk_uint8_t *) duk_get_buffer(ctx, 0, &sz_buf);
+		DUK_ASSERT(buf != NULL);
+	} else if (nargs > 0) {
+#ifdef DUK_USE_PREFER_SIZE
+		/* Compact but lots of churn. */
+		duk_push_hstring_stridx(thr, DUK_STRIDX_SPACE);
+		duk_insert(ctx, 0);
+		duk_join(ctx, nargs);
+		duk_push_string(thr, "\n");
+		duk_concat(ctx, 2);
+		buf = (const duk_uint8_t *) duk_get_lstring(ctx, -1, &sz_buf);
+		DUK_ASSERT(buf != NULL);
+#else  /* DUK_USE_PREFER_SIZE */
+		/* Higher footprint, less churn. */
+		duk_idx_t i;
+		duk_size_t sz_str;
+		const duk_uint8_t *p_str;
+		duk_uint8_t *p;
+
+		sz_buf = (duk_size_t) nargs;  /* spaces (nargs - 1) + newline */
+		for (i = 0; i < nargs; i++) {
+			(void) duk_to_lstring(ctx, i, &sz_str);
+			sz_buf += sz_str;
+		}
+
+		if (sz_buf <= sizeof(buf_stack)) {
+			p = (duk_uint8_t *) buf_stack;
+		} else {
+			p = (duk_uint8_t *) duk_push_fixed_buffer(ctx, sz_buf);
+			DUK_ASSERT(p != NULL);
+		}
+
+		buf = (const duk_uint8_t *) p;
+		for (i = 0; i < nargs; i++) {
+			p_str = (const duk_uint8_t *) duk_get_lstring(ctx, i, &sz_str);
+			DUK_ASSERT(p_str != NULL);
+			DUK_MEMCPY((void *) p, (const void *) p_str, sz_str);
+			p += sz_str;
+			*p++ = (duk_uint8_t) (i == nargs - 1 ? DUK_ASC_LF : DUK_ASC_SPACE);
+		}
+		DUK_ASSERT((const duk_uint8_t *) p == buf + sz_buf);
+#endif  /* DUK_USE_PREFER_SIZE */
+	} else {
+		buf = (const duk_uint8_t *) &nl;
+		sz_buf = 1;
+	}
+
+	/* 'buf' contains the string to write, 'sz_buf' contains the length
+	 * (which may be zero).
+	 */
+	DUK_ASSERT(buf != NULL);
+
+	if (sz_buf == 0) {
+		return 0;
+	}
+
+#ifdef DUK_USE_FILE_IO
+	f_out = (magic ? DUK_STDERR : DUK_STDOUT);
+	DUK_FWRITE((const void *) buf, 1, (size_t) sz_buf, f_out);
+	DUK_FFLUSH(f_out);
+#endif
+
+#if defined(DUK_USE_DEBUGGER_SUPPORT) && defined(DUK_USE_DEBUGGER_FWD_PRINTALERT)
+	if (DUK_HEAP_IS_DEBUGGER_ATTACHED(thr->heap)) {
+		duk_debug_write_notify(thr, magic ? DUK_DBG_CMD_ALERT : DUK_DBG_CMD_PRINT);
+		duk_debug_write_string(thr, (const char *) buf, sz_buf);
+		duk_debug_write_eom(thr);
+	}
+#endif
+	return 0;
+}
+#elif defined(DUK_USE_BROWSER_LIKE)  /* print provider */
+DUK_INTERNAL duk_ret_t duk_bi_global_object_print_helper(duk_context *ctx) {
+	DUK_UNREF(ctx);
+	return 0;
+}
+#else  /* print provider */
+DUK_INTERNAL duk_ret_t duk_bi_global_object_print_helper(duk_context *ctx) {
+	DUK_UNREF(ctx);
+	return DUK_RET_UNSUPPORTED_ERROR;
+}
+#endif  /* print provider */
+
+/*
+ *  CommonJS require() and modules support
+ */
+
+#if defined(DUK_USE_COMMONJS_MODULES)
+DUK_LOCAL void duk__bi_global_resolve_module_id(duk_context *ctx, const char *req_id, const char *mod_id) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_uint8_t buf[DUK_BI_COMMONJS_MODULE_ID_LIMIT];
+	duk_uint8_t *p;
+	duk_uint8_t *q;
+	duk_uint8_t *q_last;  /* last component */
+	duk_int_t int_rc;
+
+	DUK_ASSERT(req_id != NULL);
+	/* mod_id may be NULL */
+
+	/*
+	 *  A few notes on the algorithm:
+	 *
+	 *    - Terms are not allowed to begin with a period unless the term
+	 *      is either '.' or '..'.  This simplifies implementation (and
+	 *      is within CommonJS modules specification).
+	 *
+	 *    - There are few output bound checks here.  This is on purpose:
+	 *      the resolution input is length checked and the output is never
+	 *      longer than the input.  The resolved output is written directly
+	 *      over the input because it's never longer than the input at any
+	 *      point in the algorithm.
+	 *
+	 *    - Non-ASCII characters are processed as individual bytes and
+	 *      need no special treatment.  However, U+0000 terminates the
+	 *      algorithm; this is not an issue because U+0000 is not a
+	 *      desirable term character anyway.
+	 */
+
+	/*
+	 *  Set up the resolution input which is the requested ID directly
+	 *  (if absolute or no current module path) or with current module
+	 *  ID prepended (if relative and current module path exists).
+	 *
+	 *  Suppose current module is 'foo/bar' and relative path is './quux'.
+	 *  The 'bar' component must be replaced so the initial input here is
+	 *  'foo/bar/.././quux'.
+	 */
+
+	if (mod_id != NULL && req_id[0] == '.') {
+		int_rc = DUK_SNPRINTF((char *) buf, sizeof(buf), "%s/../%s", mod_id, req_id);
+	} else {
+		int_rc = DUK_SNPRINTF((char *) buf, sizeof(buf), "%s", req_id);
+	}
+	if (int_rc >= (duk_int_t) sizeof(buf) || int_rc < 0) {
+		/* Potentially truncated, NUL not guaranteed in any case.
+		 * The (int_rc < 0) case should not occur in practice.
+		 */
+		DUK_DD(DUK_DDPRINT("resolve error: temporary working module ID doesn't fit into resolve buffer"));
+		goto resolve_error;
+	}
+	DUK_ASSERT(DUK_STRLEN((const char *) buf) < sizeof(buf));  /* at most sizeof(buf) - 1 */
+
+	DUK_DDD(DUK_DDDPRINT("input module id: '%s'", (const char *) buf));
+
+	/*
+	 *  Resolution loop.  At the top of the loop we're expecting a valid
+	 *  term: '.', '..', or a non-empty identifier not starting with a period.
+	 */
+
+	p = buf;
+	q = buf;
+	for (;;) {
+		duk_uint_fast8_t c;
+
+		/* Here 'p' always points to the start of a term.
+		 *
+		 * We can also unconditionally reset q_last here: if this is
+		 * the last (non-empty) term q_last will have the right value
+		 * on loop exit.
+		 */
+
+		DUK_ASSERT(p >= q);  /* output is never longer than input during resolution */
+
+		DUK_DDD(DUK_DDDPRINT("resolve loop top: p -> '%s', q=%p, buf=%p",
+		                     (const char *) p, (void *) q, (void *) buf));
+
+		q_last = q;
+
+		c = *p++;
+		if (DUK_UNLIKELY(c == 0)) {
+			DUK_DD(DUK_DDPRINT("resolve error: requested ID must end with a non-empty term"));
+			goto resolve_error;
+		} else if (DUK_UNLIKELY(c == '.')) {
+			c = *p++;
+			if (c == '/') {
+				/* Term was '.' and is eaten entirely (including dup slashes). */
+				goto eat_dup_slashes;
+			}
+			if (c == '.' && *p == '/') {
+				/* Term was '..', backtrack resolved name by one component.
+				 *  q[-1] = previous slash (or beyond start of buffer)
+				 *  q[-2] = last char of previous component (or beyond start of buffer)
+				 */
+				p++;  /* eat (first) input slash */
+				DUK_ASSERT(q >= buf);
+				if (q == buf) {
+					DUK_DD(DUK_DDPRINT("resolve error: term was '..' but nothing to backtrack"));
+					goto resolve_error;
+				}
+				DUK_ASSERT(*(q - 1) == '/');
+				q--;  /* backtrack to last output slash (dups already eliminated) */
+				for (;;) {
+					/* Backtrack to previous slash or start of buffer. */
+					DUK_ASSERT(q >= buf);
+					if (q == buf) {
+						break;
+					}
+					if (*(q - 1) == '/') {
+						break;
+					}
+					q--;
+				}
+				goto eat_dup_slashes;
+			}
+			DUK_DD(DUK_DDPRINT("resolve error: term begins with '.' but is not '.' or '..' (not allowed now)"));
+			goto resolve_error;
+		} else if (DUK_UNLIKELY(c == '/')) {
+			/* e.g. require('/foo'), empty terms not allowed */
+			DUK_DD(DUK_DDPRINT("resolve error: empty term (not allowed now)"));
+			goto resolve_error;
+		} else {
+			for (;;) {
+				/* Copy term name until end or '/'. */
+				*q++ = c;
+				c = *p++;
+				if (DUK_UNLIKELY(c == 0)) {
+					/* This was the last term, and q_last was
+					 * updated to match this term at loop top.
+					 */
+					goto loop_done;
+				} else if (DUK_UNLIKELY(c == '/')) {
+					*q++ = '/';
+					break;
+				} else {
+					/* write on next loop */
+				}
+			}
+		}
+
+	 eat_dup_slashes:
+		for (;;) {
+			/* eat dup slashes */
+			c = *p;
+			if (DUK_LIKELY(c != '/')) {
+				break;
+			}
+			p++;
+		}
+	}
+ loop_done:
+	/* Output #1: resolved absolute name */
+	DUK_ASSERT(q >= buf);
+	duk_push_lstring(ctx, (const char *) buf, (size_t) (q - buf));
+
+	/* Output #2: last component name */
+	DUK_ASSERT(q >= q_last);
+	DUK_ASSERT(q_last >= buf);
+	duk_push_lstring(ctx, (const char *) q_last, (size_t) (q - q_last));
+
+	DUK_DD(DUK_DDPRINT("after resolving module name: buf=%p, q_last=%p, q=%p",
+	                   (void *) buf, (void *) q_last, (void *) q));
+	return;
+
+ resolve_error:
+	DUK_ERROR_FMT1(thr, DUK_ERR_TYPE_ERROR, "cannot resolve module id: %s", (const char *) req_id);
+}
+#endif  /* DUK_USE_COMMONJS_MODULES */
+
+#if defined(DUK_USE_COMMONJS_MODULES)
+/* Stack indices for better readability */
+#define DUK__IDX_REQUESTED_ID   0  /* Module id requested */
+#define DUK__IDX_REQUIRE        1  /* Current require() function */
+#define DUK__IDX_REQUIRE_ID     2  /* The base ID of the current require() function, resolution base */
+#define DUK__IDX_RESOLVED_ID    3  /* Resolved, normalized absolute module ID */
+#define DUK__IDX_LASTCOMP       4  /* Last component name in resolved path */
+#define DUK__IDX_DUKTAPE        5  /* Duktape object */
+#define DUK__IDX_MODLOADED      6  /* Duktape.modLoaded[] module cache */
+#define DUK__IDX_UNDEFINED      7  /* 'undefined', artifact of lookup */
+#define DUK__IDX_FRESH_REQUIRE  8  /* New require() function for module, updated resolution base */
+#define DUK__IDX_EXPORTS        9  /* Default exports table */
+#define DUK__IDX_MODULE         10  /* Module object containing module.exports, etc */
+
+DUK_INTERNAL duk_ret_t duk_bi_global_object_require(duk_context *ctx) {
+	const char *str_req_id;  /* requested identifier */
+	const char *str_mod_id;  /* require.id of current module */
+	duk_int_t pcall_rc;
+
+	/* NOTE: we try to minimize code size by avoiding unnecessary pops,
+	 * so the stack looks a bit cluttered in this function.  DUK_ASSERT_TOP()
+	 * assertions are used to ensure stack configuration is correct at each
+	 * step.
+	 */
+
+	/*
+	 *  Resolve module identifier into canonical absolute form.
+	 */
+
+	str_req_id = duk_require_string(ctx, DUK__IDX_REQUESTED_ID);
+	duk_push_current_function(ctx);
+	duk_get_prop_stridx(ctx, -1, DUK_STRIDX_ID);
+	str_mod_id = duk_get_string(ctx, DUK__IDX_REQUIRE_ID);  /* ignore non-strings */
+	DUK_DDD(DUK_DDDPRINT("resolve module id: requested=%!T, currentmodule=%!T",
+	                     duk_get_tval(ctx, DUK__IDX_REQUESTED_ID),
+	                     duk_get_tval(ctx, DUK__IDX_REQUIRE_ID)));
+	duk__bi_global_resolve_module_id(ctx, str_req_id, str_mod_id);
+	str_req_id = NULL;
+	str_mod_id = NULL;
+	DUK_DDD(DUK_DDDPRINT("resolved module id: requested=%!T, currentmodule=%!T, result=%!T, lastcomp=%!T",
+	                     duk_get_tval(ctx, DUK__IDX_REQUESTED_ID),
+	                     duk_get_tval(ctx, DUK__IDX_REQUIRE_ID),
+	                     duk_get_tval(ctx, DUK__IDX_RESOLVED_ID),
+	                     duk_get_tval(ctx, DUK__IDX_LASTCOMP)));
+
+	/* [ requested_id require require.id resolved_id last_comp ] */
+	DUK_ASSERT_TOP(ctx, DUK__IDX_LASTCOMP + 1);
+
+	/*
+	 *  Cached module check.
+	 *
+	 *  If module has been loaded or its loading has already begun without
+	 *  finishing, return the same cached value ('exports').  The value is
+	 *  registered when module load starts so that circular references can
+	 *  be supported to some extent.
+	 */
+
+	duk_push_hobject_bidx(ctx, DUK_BIDX_DUKTAPE);
+	duk_get_prop_stridx(ctx, DUK__IDX_DUKTAPE, DUK_STRIDX_MOD_LOADED);  /* Duktape.modLoaded */
+	(void) duk_require_hobject(ctx, DUK__IDX_MODLOADED);
+	DUK_ASSERT_TOP(ctx, DUK__IDX_MODLOADED + 1);
+
+	duk_dup(ctx, DUK__IDX_RESOLVED_ID);
+	if (duk_get_prop(ctx, DUK__IDX_MODLOADED)) {
+		/* [ requested_id require require.id resolved_id last_comp Duktape Duktape.modLoaded Duktape.modLoaded[id] ] */
+		DUK_DD(DUK_DDPRINT("module already loaded: %!T",
+		                   duk_get_tval(ctx, DUK__IDX_RESOLVED_ID)));
+		duk_get_prop_stridx(ctx, -1, DUK_STRIDX_EXPORTS);  /* return module.exports */
+		return 1;
+	}
+	DUK_ASSERT_TOP(ctx, DUK__IDX_UNDEFINED + 1);
+
+	/* [ requested_id require require.id resolved_id last_comp Duktape Duktape.modLoaded undefined ] */
+
+	/*
+	 *  Module not loaded (and loading not started previously).
+	 *
+	 *  Create a new require() function with 'id' set to resolved ID
+	 *  of module being loaded.  Also create 'exports' and 'module'
+	 *  tables but don't register exports to the loaded table yet.
+	 *  We don't want to do that unless the user module search callbacks
+	 *  succeeds in finding the module.
+	 */
+
+	DUK_D(DUK_DPRINT("loading module %!T, resolution base %!T, requested ID %!T -> resolved ID %!T, last component %!T",
+                         duk_get_tval(ctx, DUK__IDX_RESOLVED_ID),
+                         duk_get_tval(ctx, DUK__IDX_REQUIRE_ID),
+                         duk_get_tval(ctx, DUK__IDX_REQUESTED_ID),
+                         duk_get_tval(ctx, DUK__IDX_RESOLVED_ID),
+                         duk_get_tval(ctx, DUK__IDX_LASTCOMP)));
+
+	/* Fresh require: require.id is left configurable (but not writable)
+	 * so that is not easy to accidentally tweak it, but it can still be
+	 * done with Object.defineProperty().
+	 *
+	 * XXX: require.id could also be just made non-configurable, as there
+	 * is no practical reason to touch it.
+	 */
+	duk_push_c_function(ctx, duk_bi_global_object_require, 1 /*nargs*/);
+	duk_push_hstring_stridx(ctx, DUK_STRIDX_REQUIRE);
+	duk_xdef_prop_stridx(ctx, DUK__IDX_FRESH_REQUIRE, DUK_STRIDX_NAME, DUK_PROPDESC_FLAGS_NONE);
+	duk_dup(ctx, DUK__IDX_RESOLVED_ID);
+	duk_xdef_prop_stridx(ctx, DUK__IDX_FRESH_REQUIRE, DUK_STRIDX_ID, DUK_PROPDESC_FLAGS_C);  /* a fresh require() with require.id = resolved target module id */
+
+	/* Module table:
+	 * - module.exports: initial exports table (may be replaced by user)
+	 * - module.id is non-writable and non-configurable, as the CommonJS
+	 *   spec suggests this if possible
+	 * - module.filename: not set, defaults to resolved ID if not explicitly
+	 *   set by modSearch() (note capitalization, not .fileName, matches Node.js)
+	 * - module.name: not set, defaults to last component of resolved ID if
+	 *   not explicitly set by modSearch()
+	 */
+	duk_push_object(ctx);  /* exports */
+	duk_push_object(ctx);  /* module */
+	duk_dup(ctx, DUK__IDX_EXPORTS);
+	duk_xdef_prop_stridx(ctx, DUK__IDX_MODULE, DUK_STRIDX_EXPORTS, DUK_PROPDESC_FLAGS_WC);  /* module.exports = exports */
+	duk_dup(ctx, DUK__IDX_RESOLVED_ID);  /* resolved id: require(id) must return this same module */
+	duk_xdef_prop_stridx(ctx, DUK__IDX_MODULE, DUK_STRIDX_ID, DUK_PROPDESC_FLAGS_NONE);  /* module.id = resolved_id */
+	duk_compact(ctx, DUK__IDX_MODULE);  /* module table remains registered to modLoaded, minimize its size */
+	DUK_ASSERT_TOP(ctx, DUK__IDX_MODULE + 1);
+
+	DUK_DD(DUK_DDPRINT("module table created: %!T", duk_get_tval(ctx, DUK__IDX_MODULE)));
+
+	/* [ requested_id require require.id resolved_id last_comp Duktape Duktape.modLoaded undefined fresh_require exports module ] */
+
+	/* Register the module table early to modLoaded[] so that we can
+	 * support circular references even in modSearch().  If an error
+	 * is thrown, we'll delete the reference.
+	 */
+	duk_dup(ctx, DUK__IDX_RESOLVED_ID);
+	duk_dup(ctx, DUK__IDX_MODULE);
+	duk_put_prop(ctx, DUK__IDX_MODLOADED);  /* Duktape.modLoaded[resolved_id] = module */
+
+	/*
+	 *  Call user provided module search function and build the wrapped
+	 *  module source code (if necessary).  The module search function
+	 *  can be used to implement pure Ecmacsript, pure C, and mixed
+	 *  Ecmascript/C modules.
+	 *
+	 *  The module search function can operate on the exports table directly
+	 *  (e.g. DLL code can register values to it).  It can also return a
+	 *  string which is interpreted as module source code (if a non-string
+	 *  is returned the module is assumed to be a pure C one).  If a module
+	 *  cannot be found, an error must be thrown by the user callback.
+	 *
+	 *  Because Duktape.modLoaded[] already contains the module being
+	 *  loaded, circular references for C modules should also work
+	 *  (although expected to be quite rare).
+	 */
+
+	duk_push_string(ctx, "(function(require,exports,module){");
+
+	/* Duktape.modSearch(resolved_id, fresh_require, exports, module). */
+	duk_get_prop_stridx(ctx, DUK__IDX_DUKTAPE, DUK_STRIDX_MOD_SEARCH);  /* Duktape.modSearch */
+	duk_dup(ctx, DUK__IDX_RESOLVED_ID);
+	duk_dup(ctx, DUK__IDX_FRESH_REQUIRE);
+	duk_dup(ctx, DUK__IDX_EXPORTS);
+	duk_dup(ctx, DUK__IDX_MODULE);  /* [ ... Duktape.modSearch resolved_id last_comp fresh_require exports module ] */
+	pcall_rc = duk_pcall(ctx, 4 /*nargs*/);  /* -> [ ... source ] */
+	DUK_ASSERT_TOP(ctx, DUK__IDX_MODULE + 3);
+
+	if (pcall_rc != DUK_EXEC_SUCCESS) {
+		/* Delete entry in Duktape.modLoaded[] and rethrow. */
+		goto delete_rethrow;
+	}
+
+	/* If user callback did not return source code, module loading
+	 * is finished (user callback initialized exports table directly).
+	 */
+	if (!duk_is_string(ctx, -1)) {
+		/* User callback did not return source code, so module loading
+		 * is finished: just update modLoaded with final module.exports
+		 * and we're done.
+		 */
+		goto return_exports;
+	}
+
+	/* Finish the wrapped module source.  Force module.filename as the
+	 * function .fileName so it gets set for functions defined within a
+	 * module.  This also ensures loggers created within the module get
+	 * the module ID (or overridden filename) as their default logger name.
+	 * (Note capitalization: .filename matches Node.js while .fileName is
+	 * used elsewhere in Duktape.)
+	 */
+	duk_push_string(ctx, "})");
+	duk_concat(ctx, 3);
+	if (!duk_get_prop_stridx(ctx, DUK__IDX_MODULE, DUK_STRIDX_FILENAME)) {
+		/* module.filename for .fileName, default to resolved ID if
+		 * not present.
+		 */
+		duk_pop(ctx);
+		duk_dup(ctx, DUK__IDX_RESOLVED_ID);
+	}
+	duk_eval_raw(ctx, NULL, 0, DUK_COMPILE_EVAL);
+
+	/* Module has now evaluated to a wrapped module function.  Force its
+	 * .name to match module.name (defaults to last component of resolved
+	 * ID) so that it is shown in stack traces too.  Note that we must not
+	 * introduce an actual name binding into the function scope (which is
+	 * usually the case with a named function) because it would affect the
+	 * scope seen by the module and shadow accesses to globals of the same name.
+	 * This is now done by compiling the function as anonymous and then forcing
+	 * its .name without setting a "has name binding" flag.
+	 */
+
+	duk_push_hstring_stridx(ctx, DUK_STRIDX_NAME);
+	if (!duk_get_prop_stridx(ctx, DUK__IDX_MODULE, DUK_STRIDX_NAME)) {
+		/* module.name for .name, default to last component if
+		 * not present.
+		 */
+		duk_pop(ctx);
+		duk_dup(ctx, DUK__IDX_LASTCOMP);
+	}
+	duk_def_prop(ctx, -3, DUK_DEFPROP_HAVE_VALUE | DUK_DEFPROP_FORCE);
+
+	/*
+	 *  Call the wrapped module function.
+	 *
+	 *  Use a protected call so that we can update Duktape.modLoaded[resolved_id]
+	 *  even if the module throws an error.
+	 */
+
+	/* [ requested_id require require.id resolved_id last_comp Duktape Duktape.modLoaded undefined fresh_require exports module mod_func ] */
+	DUK_ASSERT_TOP(ctx, DUK__IDX_MODULE + 2);
+
+	duk_dup(ctx, DUK__IDX_EXPORTS);  /* exports (this binding) */
+	duk_dup(ctx, DUK__IDX_FRESH_REQUIRE);  /* fresh require (argument) */
+	duk_get_prop_stridx(ctx, DUK__IDX_MODULE, DUK_STRIDX_EXPORTS);  /* relookup exports from module.exports in case it was changed by modSearch */
+	duk_dup(ctx, DUK__IDX_MODULE);  /* module (argument) */
+	DUK_ASSERT_TOP(ctx, DUK__IDX_MODULE + 6);
+
+	/* [ requested_id require require.id resolved_id last_comp Duktape Duktape.modLoaded undefined fresh_require exports module mod_func exports fresh_require exports module ] */
+
+	pcall_rc = duk_pcall_method(ctx, 3 /*nargs*/);
+	if (pcall_rc != DUK_EXEC_SUCCESS) {
+		/* Module loading failed.  Node.js will forget the module
+		 * registration so that another require() will try to load
+		 * the module again.  Mimic that behavior.
+		 */
+		goto delete_rethrow;
+	}
+
+	/* [ requested_id require require.id resolved_id last_comp Duktape Duktape.modLoaded undefined fresh_require exports module result(ignored) ] */
+	DUK_ASSERT_TOP(ctx, DUK__IDX_MODULE + 2);
+
+	/* fall through */
+
+ return_exports:
+	duk_get_prop_stridx(ctx, DUK__IDX_MODULE, DUK_STRIDX_EXPORTS);
+	duk_compact(ctx, -1);  /* compact the exports table */
+	return 1;  /* return module.exports */
+
+ delete_rethrow:
+	duk_dup(ctx, DUK__IDX_RESOLVED_ID);
+	duk_del_prop(ctx, DUK__IDX_MODLOADED);  /* delete Duktape.modLoaded[resolved_id] */
+	duk_throw(ctx);  /* rethrow original error */
+	return 0;  /* not reachable */
+}
+
+#undef DUK__IDX_REQUESTED_ID
+#undef DUK__IDX_REQUIRE
+#undef DUK__IDX_REQUIRE_ID
+#undef DUK__IDX_RESOLVED_ID
+#undef DUK__IDX_LASTCOMP
+#undef DUK__IDX_DUKTAPE
+#undef DUK__IDX_MODLOADED
+#undef DUK__IDX_UNDEFINED
+#undef DUK__IDX_FRESH_REQUIRE
+#undef DUK__IDX_EXPORTS
+#undef DUK__IDX_MODULE
+#else
+DUK_INTERNAL duk_ret_t duk_bi_global_object_require(duk_context *ctx) {
+	DUK_UNREF(ctx);
+	return DUK_RET_UNSUPPORTED_ERROR;
+}
+#endif  /* DUK_USE_COMMONJS_MODULES */


[27/51] [partial] nifi-minifi-cpp git commit: MINIFI-183 Added civet 1.9.1 sources Added onScheduled hook Added initial two-way TLS-enabled ListenHTTP implementation

Posted by al...@apache.org.
http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/alloc-logging/log2gnuplot.py
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/alloc-logging/log2gnuplot.py b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/alloc-logging/log2gnuplot.py
new file mode 100644
index 0000000..0528259
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/alloc-logging/log2gnuplot.py
@@ -0,0 +1,41 @@
+#!/usr/bin/env python2
+#
+#  Analyze allocator logs and write total-bytes-in-use after every
+#  operation to stdout.  The output can be gnuplotted as:
+#
+#  $ python log2gnuplot.py </tmp/duk-alloc-log.txt >/tmp/output.txt
+#  $ gnuplot
+#  > plot "output.txt" with lines
+#
+
+import os
+import sys
+
+def main():
+	allocated = 0
+
+	for line in sys.stdin:
+		line = line.strip()
+		parts = line.split(' ')
+
+		# A ptr/NULL/FAIL size
+		# F ptr/NULL size
+		# R ptr/NULL oldsize ptr/NULL/FAIL newsize
+
+		# Note: ajduk doesn't log oldsize (uses -1 instead)
+
+		if parts[0] == 'A':
+			if parts[1] != 'NULL' and parts[1] != 'FAIL':
+				allocated += long(parts[2])
+		elif parts[0] == 'F':
+			allocated -= long(parts[2])
+		elif parts[0] == 'R':
+			allocated -= long(parts[2])
+			if parts[3] != 'NULL' and parts[3] != 'FAIL':
+				allocated += long(parts[4])
+		print(allocated)
+
+	print(allocated)
+
+if __name__ == '__main__':
+	main()

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/alloc-torture/README.rst
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/alloc-torture/README.rst b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/alloc-torture/README.rst
new file mode 100644
index 0000000..f3278bb
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/alloc-torture/README.rst
@@ -0,0 +1,10 @@
+==========================================
+Allocator with memory wiping and red zones
+==========================================
+
+Example allocator that wipes memory on free and checks that no out-of-bounds
+writes have been made to bytes just before and after the allocated area.
+
+Valgrind is a better tool for detecting these memory issues, but it's not
+available for all targets so you can use something like this to detect
+memory lifecycle or out-of-bounds issues.

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/alloc-torture/duk_alloc_torture.c
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/alloc-torture/duk_alloc_torture.c b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/alloc-torture/duk_alloc_torture.c
new file mode 100644
index 0000000..abca2f7
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/alloc-torture/duk_alloc_torture.c
@@ -0,0 +1,182 @@
+/*
+ *  Example torture memory allocator with memory wiping and check for
+ *  out-of-bounds writes.
+ *
+ *  Allocation structure:
+ *
+ *    [ alloc_hdr | red zone before | user area | red zone after ]
+ *
+ *     ^                             ^
+ *     |                             `--- pointer returned to Duktape
+ *     `--- underlying malloc ptr
+ */
+
+#include "duktape.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdint.h>
+
+#define  RED_ZONE_SIZE  16
+#define  RED_ZONE_BYTE  0x5a
+#define  INIT_BYTE      0xa5
+#define  WIPE_BYTE      0x27
+
+typedef struct {
+	/* The double value in the union is there to ensure alignment is
+	 * good for IEEE doubles too.  In many 32-bit environments 4 bytes
+	 * would be sufficiently aligned and the double value is unnecessary.
+	 */
+	union {
+		size_t sz;
+		double d;
+	} u;
+} alloc_hdr;
+
+static void check_red_zone(alloc_hdr *hdr) {
+	size_t size;
+	int i;
+	int err;
+	unsigned char *p;
+	unsigned char *userptr;
+
+	size = hdr->u.sz;
+	userptr = (unsigned char *) hdr + sizeof(alloc_hdr) + RED_ZONE_SIZE;
+
+	err = 0;
+	p = (unsigned char *) hdr + sizeof(alloc_hdr);
+	for (i = 0; i < RED_ZONE_SIZE; i++) {
+		if (p[i] != RED_ZONE_BYTE) {
+			err = 1;
+		}
+	}
+	if (err) {
+		fprintf(stderr, "RED ZONE CORRUPTED BEFORE ALLOC: hdr=%p ptr=%p size=%ld\n",
+		        (void *) hdr, (void *) userptr, (long) size);
+		fflush(stderr);
+	}
+
+	err = 0;
+	p = (unsigned char *) hdr + sizeof(alloc_hdr) + RED_ZONE_SIZE + size;
+	for (i = 0; i < RED_ZONE_SIZE; i++) {
+		if (p[i] != RED_ZONE_BYTE) {
+			err = 1;
+		}
+	}
+	if (err) {
+		fprintf(stderr, "RED ZONE CORRUPTED AFTER ALLOC: hdr=%p ptr=%p size=%ld\n",
+		        (void *) hdr, (void *) userptr, (long) size);
+		fflush(stderr);
+	}
+}
+
+void *duk_alloc_torture(void *udata, duk_size_t size) {
+	unsigned char *p;
+
+	(void) udata;  /* Suppress warning. */
+
+	if (size == 0) {
+		return NULL;
+	}
+
+	p = (unsigned char *) malloc(size + sizeof(alloc_hdr) + 2 * RED_ZONE_SIZE);
+	if (!p) {
+		return NULL;
+	}
+
+	((alloc_hdr *) (void *) p)->u.sz = size;
+	p += sizeof(alloc_hdr);
+	memset((void *) p, RED_ZONE_BYTE, RED_ZONE_SIZE);
+	p += RED_ZONE_SIZE;
+	memset((void *) p, INIT_BYTE, size);
+	p += size;
+	memset((void *) p, RED_ZONE_BYTE, RED_ZONE_SIZE);
+	p -= size;
+	return (void *) p;
+}
+
+void *duk_realloc_torture(void *udata, void *ptr, duk_size_t size) {
+	unsigned char *p, *old_p;
+	size_t old_size;
+
+	(void) udata;  /* Suppress warning. */
+
+	/* Handle the ptr-NULL vs. size-zero cases explicitly to minimize
+	 * platform assumptions.  You can get away with much less in specific
+	 * well-behaving environments.
+	 */
+
+	if (ptr) {
+		old_p = (unsigned char *) ptr - sizeof(alloc_hdr) - RED_ZONE_SIZE;
+		old_size = ((alloc_hdr *) (void *) old_p)->u.sz;
+		check_red_zone((alloc_hdr *) (void *) old_p);
+
+		if (size == 0) {
+			memset((void *) old_p, WIPE_BYTE, old_size + sizeof(alloc_hdr) + 2 * RED_ZONE_SIZE);
+			free((void *) old_p);
+			return NULL;
+		} else {
+			/* Force address change on every realloc. */
+			p = (unsigned char *) malloc(size + sizeof(alloc_hdr) + 2 * RED_ZONE_SIZE);
+			if (!p) {
+				return NULL;
+			}
+
+			((alloc_hdr *) (void *) p)->u.sz = size;
+			p += sizeof(alloc_hdr);
+			memset((void *) p, RED_ZONE_BYTE, RED_ZONE_SIZE);
+			p += RED_ZONE_SIZE;
+			if (size > old_size) {
+				memcpy((void *) p, (void *) (old_p + sizeof(alloc_hdr) + RED_ZONE_SIZE), old_size);
+				memset((void *) (p + old_size), INIT_BYTE, size - old_size);
+			} else {
+				memcpy((void *) p, (void *) (old_p + sizeof(alloc_hdr) + RED_ZONE_SIZE), size);
+			}
+			p += size;
+			memset((void *) p, RED_ZONE_BYTE, RED_ZONE_SIZE);
+			p -= size;
+
+			memset((void *) old_p, WIPE_BYTE, old_size + sizeof(alloc_hdr) + 2 * RED_ZONE_SIZE);
+			free((void *) old_p);
+
+			return (void *) p;
+		}
+	} else {
+		if (size == 0) {
+			return NULL;
+		} else {
+			p = (unsigned char *) malloc(size + sizeof(alloc_hdr) + 2 * RED_ZONE_SIZE);
+			if (!p) {
+				return NULL;
+			}
+
+			((alloc_hdr *) (void *) p)->u.sz = size;
+			p += sizeof(alloc_hdr);
+			memset((void *) p, RED_ZONE_BYTE, RED_ZONE_SIZE);
+			p += RED_ZONE_SIZE;
+			memset((void *) p, INIT_BYTE, size);
+			p += size;
+			memset((void *) p, RED_ZONE_BYTE, RED_ZONE_SIZE);
+			p -= size;
+			return (void *) p;
+		}
+	}
+}
+
+void duk_free_torture(void *udata, void *ptr) {
+	unsigned char *p;
+	size_t old_size;
+
+	(void) udata;  /* Suppress warning. */
+
+	if (!ptr) {
+		return;
+	}
+
+	p = (unsigned char *) ptr - sizeof(alloc_hdr) - RED_ZONE_SIZE;
+	old_size = ((alloc_hdr *) (void *) p)->u.sz;
+
+	check_red_zone((alloc_hdr *) (void *) p);
+	memset((void *) p, WIPE_BYTE, old_size + sizeof(alloc_hdr) + 2 * RED_ZONE_SIZE);
+	free((void *) p);
+}

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/alloc-torture/duk_alloc_torture.h
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/alloc-torture/duk_alloc_torture.h b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/alloc-torture/duk_alloc_torture.h
new file mode 100644
index 0000000..a12153a
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/alloc-torture/duk_alloc_torture.h
@@ -0,0 +1,10 @@
+#ifndef DUK_ALLOC_TORTURE_H_INCLUDED
+#define DUK_ALLOC_TORTURE_H_INCLUDED
+
+#include "duktape.h"
+
+void *duk_alloc_torture(void *udata, duk_size_t size);
+void *duk_realloc_torture(void *udata, void *ptr, duk_size_t size);
+void duk_free_torture(void *udata, void *ptr);
+
+#endif  /* DUK_ALLOC_TORTURE_H_INCLUDED */

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/cmdline/README.rst
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/cmdline/README.rst b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/cmdline/README.rst
new file mode 100644
index 0000000..e0c6bce
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/cmdline/README.rst
@@ -0,0 +1,6 @@
+====================
+Duktape command line
+====================
+
+Ecmascript command line execution tool, useful for running Ecmascript code
+from a file, stdin, or interactively.  Also used by automatic testing.

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/cmdline/duk_cmdline.c
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/cmdline/duk_cmdline.c b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/cmdline/duk_cmdline.c
new file mode 100644
index 0000000..ea5af55
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/cmdline/duk_cmdline.c
@@ -0,0 +1,1463 @@
+/*
+ *  Command line execution tool.  Useful for test cases and manual testing.
+ *
+ *  To enable linenoise and other fancy stuff, compile with -DDUK_CMDLINE_FANCY.
+ *  It is not the default to maximize portability.  You can also compile in
+ *  support for example allocators, grep for DUK_CMDLINE_*.
+ */
+
+/* Helper define to enable a feature set; can also use separate defines. */
+#if defined(DUK_CMDLINE_FANCY)
+#define DUK_CMDLINE_LINENOISE
+#define DUK_CMDLINE_LINENOISE_COMPLETION
+#define DUK_CMDLINE_RLIMIT
+#define DUK_CMDLINE_SIGNAL
+#endif
+
+#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || \
+    defined(WIN64) || defined(_WIN64) || defined(__WIN64__)
+/* Suppress warnings about plain fopen() etc. */
+#define _CRT_SECURE_NO_WARNINGS
+#if defined(_MSC_VER) && (_MSC_VER < 1900)
+/* Workaround for snprintf() missing in older MSVC versions.
+ * Note that _snprintf() may not NUL terminate the string, but
+ * this difference does not matter here as a NUL terminator is
+ * always explicitly added.
+ */
+#define snprintf _snprintf
+#endif
+#endif
+
+#define  GREET_CODE(variant)  \
+	"print('((o) Duktape" variant " ' + " \
+	"Math.floor(Duktape.version / 10000) + '.' + " \
+	"Math.floor(Duktape.version / 100) % 100 + '.' + " \
+	"Duktape.version % 100" \
+	", '(" DUK_GIT_DESCRIBE ")');"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#if defined(DUK_CMDLINE_SIGNAL)
+#include <signal.h>
+#endif
+#if defined(DUK_CMDLINE_RLIMIT)
+#include <sys/resource.h>
+#endif
+#if defined(DUK_CMDLINE_LINENOISE)
+#include "linenoise.h"
+#endif
+#if defined(DUK_CMDLINE_FILEIO)
+#include <errno.h>
+#endif
+#if defined(EMSCRIPTEN)
+#include <emscripten.h>
+#endif
+#if defined(DUK_CMDLINE_ALLOC_LOGGING)
+#include "duk_alloc_logging.h"
+#endif
+#if defined(DUK_CMDLINE_ALLOC_TORTURE)
+#include "duk_alloc_torture.h"
+#endif
+#if defined(DUK_CMDLINE_ALLOC_HYBRID)
+#include "duk_alloc_hybrid.h"
+#endif
+#include "duktape.h"
+
+#if defined(DUK_CMDLINE_AJSHEAP)
+/* Defined in duk_cmdline_ajduk.c or alljoyn.js headers. */
+void ajsheap_init(void);
+void ajsheap_free(void);
+void ajsheap_dump(void);
+void ajsheap_register(duk_context *ctx);
+void ajsheap_start_exec_timeout(void);
+void ajsheap_clear_exec_timeout(void);
+void *ajsheap_alloc_wrapped(void *udata, duk_size_t size);
+void *ajsheap_realloc_wrapped(void *udata, void *ptr, duk_size_t size);
+void ajsheap_free_wrapped(void *udata, void *ptr);
+void *AJS_Alloc(void *udata, duk_size_t size);
+void *AJS_Realloc(void *udata, void *ptr, duk_size_t size);
+void AJS_Free(void *udata, void *ptr);
+#endif
+
+#if defined(DUK_CMDLINE_DEBUGGER_SUPPORT)
+#include "duk_trans_socket.h"
+#endif
+
+#define  MEM_LIMIT_NORMAL   (128*1024*1024)   /* 128 MB */
+#define  MEM_LIMIT_HIGH     (2047*1024*1024)  /* ~2 GB */
+#define  LINEBUF_SIZE       65536
+
+static int main_argc = 0;
+static char **main_argv = NULL;
+static int interactive_mode = 0;
+#if defined(DUK_CMDLINE_DEBUGGER_SUPPORT)
+static int debugger_reattach = 0;
+#endif
+
+/*
+ *  Misc helpers
+ */
+
+#if defined(DUK_CMDLINE_RLIMIT)
+static void set_resource_limits(rlim_t mem_limit_value) {
+	int rc;
+	struct rlimit lim;
+
+	rc = getrlimit(RLIMIT_AS, &lim);
+	if (rc != 0) {
+		fprintf(stderr, "Warning: cannot read RLIMIT_AS\n");
+		return;
+	}
+
+	if (lim.rlim_max < mem_limit_value) {
+		fprintf(stderr, "Warning: rlim_max < mem_limit_value (%d < %d)\n", (int) lim.rlim_max, (int) mem_limit_value);
+		return;
+	}
+
+	lim.rlim_cur = mem_limit_value;
+	lim.rlim_max = mem_limit_value;
+
+	rc = setrlimit(RLIMIT_AS, &lim);
+	if (rc != 0) {
+		fprintf(stderr, "Warning: setrlimit failed\n");
+		return;
+	}
+
+#if 0
+	fprintf(stderr, "Set RLIMIT_AS to %d\n", (int) mem_limit_value);
+#endif
+}
+#endif  /* DUK_CMDLINE_RLIMIT */
+
+#if defined(DUK_CMDLINE_SIGNAL)
+static void my_sighandler(int x) {
+	fprintf(stderr, "Got signal %d\n", x);
+	fflush(stderr);
+}
+static void set_sigint_handler(void) {
+	(void) signal(SIGINT, my_sighandler);
+	(void) signal(SIGPIPE, SIG_IGN);  /* avoid SIGPIPE killing process */
+}
+#endif  /* DUK_CMDLINE_SIGNAL */
+
+static int get_stack_raw(duk_context *ctx) {
+	if (!duk_is_object(ctx, -1)) {
+		return 1;
+	}
+	if (!duk_has_prop_string(ctx, -1, "stack")) {
+		return 1;
+	}
+	if (!duk_is_error(ctx, -1)) {
+		/* Not an Error instance, don't read "stack". */
+		return 1;
+	}
+
+	duk_get_prop_string(ctx, -1, "stack");  /* caller coerces */
+	duk_remove(ctx, -2);
+	return 1;
+}
+
+/* Print error to stderr and pop error. */
+static void print_pop_error(duk_context *ctx, FILE *f) {
+	/* Print error objects with a stack trace specially.
+	 * Note that getting the stack trace may throw an error
+	 * so this also needs to be safe call wrapped.
+	 */
+	(void) duk_safe_call(ctx, get_stack_raw, 1 /*nargs*/, 1 /*nrets*/);
+	fprintf(f, "%s\n", duk_safe_to_string(ctx, -1));
+	fflush(f);
+	duk_pop(ctx);
+}
+
+static int wrapped_compile_execute(duk_context *ctx) {
+	const char *src_data;
+	duk_size_t src_len;
+	int comp_flags;
+
+	/* XXX: Here it'd be nice to get some stats for the compilation result
+	 * when a suitable command line is given (e.g. code size, constant
+	 * count, function count.  These are available internally but not through
+	 * the public API.
+	 */
+
+	/* Use duk_compile_lstring_filename() variant which avoids interning
+	 * the source code.  This only really matters for low memory environments.
+	 */
+
+	/* [ ... bytecode_filename src_data src_len filename ] */
+
+	src_data = (const char *) duk_require_pointer(ctx, -3);
+	src_len = (duk_size_t) duk_require_uint(ctx, -2);
+
+	if (src_data != NULL && src_len >= 2 && src_data[0] == (char) 0xff) {
+		/* Bytecode. */
+		duk_push_lstring(ctx, src_data, src_len);
+		duk_to_buffer(ctx, -1, NULL);
+		duk_load_function(ctx);
+	} else {
+		/* Source code. */
+		comp_flags = 0;
+		duk_compile_lstring_filename(ctx, comp_flags, src_data, src_len);
+	}
+
+	/* [ ... bytecode_filename src_data src_len function ] */
+
+	/* Optional bytecode dump. */
+	if (duk_is_string(ctx, -4)) {
+		FILE *f;
+		void *bc_ptr;
+		duk_size_t bc_len;
+		size_t wrote;
+		char fnbuf[256];
+		const char *filename;
+
+		duk_dup_top(ctx);
+		duk_dump_function(ctx);
+		bc_ptr = duk_require_buffer(ctx, -1, &bc_len);
+		filename = duk_require_string(ctx, -5);
+#if defined(EMSCRIPTEN)
+		if (filename[0] == '/') {
+			snprintf(fnbuf, sizeof(fnbuf), "%s", filename);
+		} else {
+			snprintf(fnbuf, sizeof(fnbuf), "/working/%s", filename);
+		}
+#else
+		snprintf(fnbuf, sizeof(fnbuf), "%s", filename);
+#endif
+		fnbuf[sizeof(fnbuf) - 1] = (char) 0;
+
+		f = fopen(fnbuf, "wb");
+		if (!f) {
+			duk_error(ctx, DUK_ERR_ERROR, "failed to open bytecode output file");
+		}
+		wrote = fwrite(bc_ptr, 1, (size_t) bc_len, f);  /* XXX: handle partial writes */
+		(void) fclose(f);
+		if (wrote != bc_len) {
+			duk_error(ctx, DUK_ERR_ERROR, "failed to write all bytecode");
+		}
+
+		return 0;  /* duk_safe_call() cleans up */
+	}
+
+#if 0
+	/* Manual test for bytecode dump/load cycle: dump and load before
+	 * execution.  Enable manually, then run "make qecmatest" for a
+	 * reasonably good coverage of different functions and programs.
+	 */
+	duk_dump_function(ctx);
+	duk_load_function(ctx);
+#endif
+
+#if defined(DUK_CMDLINE_AJSHEAP)
+	ajsheap_start_exec_timeout();
+#endif
+
+	duk_push_global_object(ctx);  /* 'this' binding */
+	duk_call_method(ctx, 0);
+
+#if defined(DUK_CMDLINE_AJSHEAP)
+	ajsheap_clear_exec_timeout();
+#endif
+
+	if (interactive_mode) {
+		/*
+		 *  In interactive mode, write to stdout so output won't
+		 *  interleave as easily.
+		 *
+		 *  NOTE: the ToString() coercion may fail in some cases;
+		 *  for instance, if you evaluate:
+		 *
+		 *    ( {valueOf: function() {return {}},
+		 *       toString: function() {return {}}});
+		 *
+		 *  The error is:
+		 *
+		 *    TypeError: failed to coerce with [[DefaultValue]]
+		 *            duk_api.c:1420
+		 *
+		 *  These are handled now by the caller which also has stack
+		 *  trace printing support.  User code can print out errors
+		 *  safely using duk_safe_to_string().
+		 */
+
+		fprintf(stdout, "= %s\n", duk_to_string(ctx, -1));
+		fflush(stdout);
+	} else {
+		/* In non-interactive mode, success results are not written at all.
+		 * It is important that the result value is not string coerced,
+		 * as the string coercion may cause an error in some cases.
+		 */
+	}
+
+	return 0;  /* duk_safe_call() cleans up */
+}
+
+/*
+ *  Minimal Linenoise completion support
+ */
+
+#if defined(DUK_CMDLINE_LINENOISE_COMPLETION)
+static duk_context *completion_ctx;
+
+static int completion_idpart(unsigned char c) {
+	/* Very simplified "is identifier part" check. */
+	if ((c >= (unsigned char) 'a' && c <= (unsigned char) 'z') ||
+	    (c >= (unsigned char) 'A' && c <= (unsigned char) 'Z') ||
+	    (c >= (unsigned char) '0' && c <= (unsigned char) '9') ||
+	    c == (unsigned char) '$' || c == (unsigned char) '_') {
+		return 1;
+	}
+	return 0;
+}
+
+static int completion_digit(unsigned char c) {
+	return (c >= (unsigned char) '0' && c <= (unsigned char) '9');
+}
+
+static duk_ret_t linenoise_completion_lookup(duk_context *ctx) {
+	duk_size_t len;
+	const char *orig;
+	const unsigned char *p;
+	const unsigned char *p_curr;
+	const unsigned char *p_end;
+	const char *key;
+	const char *prefix;
+	linenoiseCompletions *lc;
+	duk_idx_t idx_obj;
+
+	orig = duk_require_string(ctx, -3);
+	p_curr = (const unsigned char *) duk_require_lstring(ctx, -2, &len);
+	p_end = p_curr + len;
+	lc = duk_require_pointer(ctx, -1);
+
+	duk_push_global_object(ctx);
+	idx_obj = duk_require_top_index(ctx);
+
+	while (p_curr <= p_end) {
+		/* p_curr == p_end allowed on purpose, to handle 'Math.' for example. */
+		p = p_curr;
+		while (p < p_end && p[0] != (unsigned char) '.') {
+			p++;
+		}
+		/* 'p' points to a NUL (p == p_end) or a period. */
+		prefix = duk_push_lstring(ctx, (const char *) p_curr, (duk_size_t) (p - p_curr));
+
+#if 0
+		fprintf(stderr, "Completion check: '%s'\n", prefix);
+		fflush(stderr);
+#endif
+
+		if (p == p_end) {
+			/* 'idx_obj' points to the object matching the last
+			 * full component, use [p_curr,p[ as a filter for
+			 * that object.
+			 */
+
+			duk_enum(ctx, idx_obj, DUK_ENUM_INCLUDE_NONENUMERABLE);
+			while (duk_next(ctx, -1, 0 /*get_value*/)) {
+				key = duk_get_string(ctx, -1);
+#if 0
+				fprintf(stderr, "Key: %s\n", key ? key : "");
+				fflush(stderr);
+#endif
+				if (!key) {
+					/* Should never happen, just in case. */
+					goto next;
+				}
+
+				/* Ignore array index keys: usually not desirable, and would
+				 * also require ['0'] quoting.
+				 */
+				if (completion_digit(key[0])) {
+					goto next;
+				}
+
+				/* XXX: There's no key quoting now, it would require replacing the
+				 * last component with a ['foo\nbar'] style lookup when appropriate.
+				 */
+
+				if (strlen(prefix) == 0) {
+					/* Partial ends in a period, e.g. 'Math.' -> complete all Math properties. */
+					duk_push_string(ctx, orig);  /* original, e.g. 'Math.' */
+					duk_push_string(ctx, key);
+					duk_concat(ctx, 2);
+					linenoiseAddCompletion(lc, duk_require_string(ctx, -1));
+					duk_pop(ctx);
+				} else if (prefix && strcmp(key, prefix) == 0) {
+					/* Full completion, add a period, e.g. input 'Math' -> 'Math.'. */
+					duk_push_string(ctx, orig);  /* original, including partial last component */
+					duk_push_string(ctx, ".");
+					duk_concat(ctx, 2);
+					linenoiseAddCompletion(lc, duk_require_string(ctx, -1));
+					duk_pop(ctx);
+				} else if (prefix && strncmp(key, prefix, strlen(prefix)) == 0) {
+					/* Last component is partial, complete. */
+					duk_push_string(ctx, orig);  /* original, including partial last component */
+					duk_push_string(ctx, key + strlen(prefix));  /* completion to last component */
+					duk_concat(ctx, 2);
+					linenoiseAddCompletion(lc, duk_require_string(ctx, -1));
+					duk_pop(ctx);
+				}
+
+			 next:
+				duk_pop(ctx);
+			}
+			return 0;
+		} else {
+			if (duk_get_prop(ctx, idx_obj)) {
+				duk_to_object(ctx, -1);  /* for properties of plain strings etc */
+				duk_replace(ctx, idx_obj);
+				p_curr = p + 1;
+			} else {
+				/* Not found. */
+				return 0;
+			}
+		}
+	}
+
+	return 0;
+}
+
+static void linenoise_completion(const char *buf, linenoiseCompletions *lc) {
+	duk_context *ctx;
+	const unsigned char *p_start;
+	const unsigned char *p_end;
+	const unsigned char *p;
+	duk_int_t rc;
+
+	if (!buf) {
+		return;
+	}
+	ctx = completion_ctx;
+	if (!ctx) {
+		return;
+	}
+
+	p_start = (const unsigned char *) buf;
+	p_end = (const unsigned char *) (buf + strlen(buf));
+	p = p_end;
+
+	/* Scan backwards for a maximal string which looks like a property
+	 * chain (e.g. foo.bar.quux).
+	 */
+
+	while (--p >= p_start) {
+		if (p[0] == (unsigned char) '.') {
+			if (p <= p_start) {
+				break;
+			}
+			if (!completion_idpart(p[-1])) {
+				/* Catches e.g. 'foo..bar' -> we want 'bar' only. */
+				break;
+			}
+		} else if (!completion_idpart(p[0])) {
+			break;
+		}
+	}
+	/* 'p' will either be p_start - 1 (ran out of buffer) or point to
+	 * the first offending character.
+	 */
+	p++;
+	if (p < p_start || p >= p_end) {
+		return;  /* should never happen, but just in case */
+	}
+
+	/* 'p' now points to a string of the form 'foo.bar.quux'.  Look up
+	 * all the components except the last; treat the last component as
+	 * a partial name which is used as a filter for the previous full
+	 * component.  All lookups are from the global object now.
+	 */
+
+#if 0
+	fprintf(stderr, "Completion starting point: '%s'\n", p);
+	fflush(stderr);
+#endif
+
+	duk_push_string(ctx, (const char *) buf);
+	duk_push_lstring(ctx, (const char *) p, (duk_size_t) (p_end - p));
+	duk_push_pointer(ctx, (void *) lc);
+
+	rc = duk_safe_call(ctx, linenoise_completion_lookup, 3 /*nargs*/, 1 /*nrets*/);
+	if (rc != DUK_EXEC_SUCCESS) {
+		fprintf(stderr, "Completion handling failure: %s\n", duk_safe_to_string(ctx, -1));
+	}
+	duk_pop(ctx);
+}
+#endif  /* DUK_CMDLINE_LINENOISE_COMPLETION */
+
+/*
+ *  Execute from file handle etc
+ */
+
+static int handle_fh(duk_context *ctx, FILE *f, const char *filename, const char *bytecode_filename) {
+	char *buf = NULL;
+	size_t bufsz;
+	size_t bufoff;
+	size_t got;
+	int rc;
+	int retval = -1;
+
+	buf = (char *) malloc(1024);
+	if (!buf) {
+		goto error;
+	}
+	bufsz = 1024;
+	bufoff = 0;
+
+	/* Read until EOF, avoid fseek/stat because it won't work with stdin. */
+	for (;;) {
+		size_t avail;
+
+		avail = bufsz - bufoff;
+		if (avail < 1024) {
+			size_t newsz;
+			char *buf_new;
+#if 0
+			fprintf(stderr, "resizing read buffer: %ld -> %ld\n", (long) bufsz, (long) (bufsz * 2));
+#endif
+			newsz = bufsz + (bufsz >> 2) + 1024;  /* +25% and some extra */
+			buf_new = (char *) realloc(buf, newsz);
+			if (!buf_new) {
+				goto error;
+			}
+			buf = buf_new;
+			bufsz = newsz;
+		}
+
+		avail = bufsz - bufoff;
+#if 0
+		fprintf(stderr, "reading input: buf=%p bufsz=%ld bufoff=%ld avail=%ld\n",
+		        (void *) buf, (long) bufsz, (long) bufoff, (long) avail);
+#endif
+
+		got = fread((void *) (buf + bufoff), (size_t) 1, avail, f);
+#if 0
+		fprintf(stderr, "got=%ld\n", (long) got);
+#endif
+		if (got == 0) {
+			break;
+		}
+		bufoff += got;
+
+		/* Emscripten specific: stdin EOF doesn't work as expected.
+		 * Instead, when 'emduk' is executed using Node.js, a file
+		 * piped to stdin repeats (!).  Detect that repeat and cut off
+		 * the stdin read.  Ensure the loop repeats enough times to
+		 * avoid detecting spurious loops.
+		 *
+		 * This only seems to work for inputs up to 256 bytes long.
+		 */
+#if defined(EMSCRIPTEN)
+		if (bufoff >= 16384) {
+			size_t i, j, nloops;
+			int looped = 0;
+
+			for (i = 16; i < bufoff / 8; i++) {
+				int ok;
+
+				nloops = bufoff / i;
+				ok = 1;
+				for (j = 1; j < nloops; j++) {
+					if (memcmp((void *) buf, (void *) (buf + i * j), i) != 0) {
+						ok = 0;
+						break;
+					}
+				}
+				if (ok) {
+					fprintf(stderr, "emscripten workaround: detect looping at index %ld, verified with %ld loops\n", (long) i, (long) (nloops - 1));
+					bufoff = i;
+					looped = 1;
+					break;
+				}
+			}
+
+			if (looped) {
+				break;
+			}
+		}
+#endif
+	}
+
+	duk_push_string(ctx, bytecode_filename);
+	duk_push_pointer(ctx, (void *) buf);
+	duk_push_uint(ctx, (duk_uint_t) bufoff);
+	duk_push_string(ctx, filename);
+
+	interactive_mode = 0;  /* global */
+
+	rc = duk_safe_call(ctx, wrapped_compile_execute, 4 /*nargs*/, 1 /*nret*/);
+
+#if defined(DUK_CMDLINE_AJSHEAP)
+	ajsheap_clear_exec_timeout();
+#endif
+
+	free(buf);
+	buf = NULL;
+
+	if (rc != DUK_EXEC_SUCCESS) {
+		print_pop_error(ctx, stderr);
+		goto error;
+	} else {
+		duk_pop(ctx);
+		retval = 0;
+	}
+	/* fall thru */
+
+ cleanup:
+	if (buf) {
+		free(buf);
+		buf = NULL;
+	}
+	return retval;
+
+ error:
+	fprintf(stderr, "error in executing file %s\n", filename);
+	fflush(stderr);
+	goto cleanup;
+}
+
+static int handle_file(duk_context *ctx, const char *filename, const char *bytecode_filename) {
+	FILE *f = NULL;
+	int retval;
+	char fnbuf[256];
+
+	/* Example of sending an application specific debugger notification. */
+	duk_push_string(ctx, "DebuggerHandleFile");
+	duk_push_string(ctx, filename);
+	duk_debugger_notify(ctx, 2);
+
+#if defined(EMSCRIPTEN)
+	if (filename[0] == '/') {
+		snprintf(fnbuf, sizeof(fnbuf), "%s", filename);
+	} else {
+		snprintf(fnbuf, sizeof(fnbuf), "/working/%s", filename);
+	}
+#else
+	snprintf(fnbuf, sizeof(fnbuf), "%s", filename);
+#endif
+	fnbuf[sizeof(fnbuf) - 1] = (char) 0;
+
+	f = fopen(fnbuf, "rb");
+	if (!f) {
+		fprintf(stderr, "failed to open source file: %s\n", filename);
+		fflush(stderr);
+		goto error;
+	}
+
+	retval = handle_fh(ctx, f, filename, bytecode_filename);
+
+	fclose(f);
+	return retval;
+
+ error:
+	return -1;
+}
+
+static int handle_eval(duk_context *ctx, char *code) {
+	int rc;
+	int retval = -1;
+
+	duk_push_pointer(ctx, (void *) code);
+	duk_push_uint(ctx, (duk_uint_t) strlen(code));
+	duk_push_string(ctx, "eval");
+
+	interactive_mode = 0;  /* global */
+
+	rc = duk_safe_call(ctx, wrapped_compile_execute, 3 /*nargs*/, 1 /*nret*/);
+
+#if defined(DUK_CMDLINE_AJSHEAP)
+	ajsheap_clear_exec_timeout();
+#endif
+
+	if (rc != DUK_EXEC_SUCCESS) {
+		print_pop_error(ctx, stderr);
+	} else {
+		duk_pop(ctx);
+		retval = 0;
+	}
+
+	return retval;
+}
+
+#if defined(DUK_CMDLINE_LINENOISE)
+static int handle_interactive(duk_context *ctx) {
+	const char *prompt = "duk> ";
+	char *buffer = NULL;
+	int retval = 0;
+	int rc;
+
+	duk_eval_string(ctx, GREET_CODE(" [linenoise]"));
+	duk_pop(ctx);
+
+	linenoiseSetMultiLine(1);
+	linenoiseHistorySetMaxLen(64);
+#if defined(DUK_CMDLINE_LINENOISE_COMPLETION)
+	linenoiseSetCompletionCallback(linenoise_completion);
+#endif
+
+	for (;;) {
+		if (buffer) {
+			linenoiseFree(buffer);
+			buffer = NULL;
+		}
+
+#if defined(DUK_CMDLINE_LINENOISE_COMPLETION)
+		completion_ctx = ctx;
+#endif
+		buffer = linenoise(prompt);
+#if defined(DUK_CMDLINE_LINENOISE_COMPLETION)
+		completion_ctx = NULL;
+#endif
+
+		if (!buffer) {
+			break;
+		}
+
+		if (buffer && buffer[0] != (char) 0) {
+			linenoiseHistoryAdd(buffer);
+		}
+
+		duk_push_pointer(ctx, (void *) buffer);
+		duk_push_uint(ctx, (duk_uint_t) strlen(buffer));
+		duk_push_string(ctx, "input");
+
+		interactive_mode = 1;  /* global */
+
+		rc = duk_safe_call(ctx, wrapped_compile_execute, 3 /*nargs*/, 1 /*nret*/);
+
+#if defined(DUK_CMDLINE_AJSHEAP)
+		ajsheap_clear_exec_timeout();
+#endif
+
+		if (buffer) {
+			linenoiseFree(buffer);
+			buffer = NULL;
+		}
+
+		if (rc != DUK_EXEC_SUCCESS) {
+			/* in interactive mode, write to stdout */
+			print_pop_error(ctx, stdout);
+			retval = -1;  /* an error 'taints' the execution */
+		} else {
+			duk_pop(ctx);
+		}
+	}
+
+	if (buffer) {
+		linenoiseFree(buffer);
+		buffer = NULL;
+	}
+
+	return retval;
+}
+#else  /* DUK_CMDLINE_LINENOISE */
+static int handle_interactive(duk_context *ctx) {
+	const char *prompt = "duk> ";
+	char *buffer = NULL;
+	int retval = 0;
+	int rc;
+	int got_eof = 0;
+
+	duk_eval_string(ctx, GREET_CODE(""));
+	duk_pop(ctx);
+
+	buffer = (char *) malloc(LINEBUF_SIZE);
+	if (!buffer) {
+		fprintf(stderr, "failed to allocated a line buffer\n");
+		fflush(stderr);
+		retval = -1;
+		goto done;
+	}
+
+	while (!got_eof) {
+		size_t idx = 0;
+
+		fwrite(prompt, 1, strlen(prompt), stdout);
+		fflush(stdout);
+
+		for (;;) {
+			int c = fgetc(stdin);
+			if (c == EOF) {
+				got_eof = 1;
+				break;
+			} else if (c == '\n') {
+				break;
+			} else if (idx >= LINEBUF_SIZE) {
+				fprintf(stderr, "line too long\n");
+				fflush(stderr);
+				retval = -1;
+				goto done;
+			} else {
+				buffer[idx++] = (char) c;
+			}
+		}
+
+		duk_push_pointer(ctx, (void *) buffer);
+		duk_push_uint(ctx, (duk_uint_t) idx);
+		duk_push_string(ctx, "input");
+
+		interactive_mode = 1;  /* global */
+
+		rc = duk_safe_call(ctx, wrapped_compile_execute, 3 /*nargs*/, 1 /*nret*/);
+
+#if defined(DUK_CMDLINE_AJSHEAP)
+		ajsheap_clear_exec_timeout();
+#endif
+
+		if (rc != DUK_EXEC_SUCCESS) {
+			/* in interactive mode, write to stdout */
+			print_pop_error(ctx, stdout);
+			retval = -1;  /* an error 'taints' the execution */
+		} else {
+			duk_pop(ctx);
+		}
+	}
+
+ done:
+	if (buffer) {
+		free(buffer);
+		buffer = NULL;
+	}
+
+	return retval;
+}
+#endif  /* DUK_CMDLINE_LINENOISE */
+
+/*
+ *  Simple file read/write bindings
+ */
+
+#if defined(DUK_CMDLINE_FILEIO)
+static duk_ret_t fileio_read_file(duk_context *ctx) {
+	const char *fn;
+	char *buf;
+	size_t len;
+	size_t off;
+	int rc;
+	FILE *f;
+
+	fn = duk_require_string(ctx, 0);
+	f = fopen(fn, "rb");
+	if (!f) {
+		duk_error(ctx, DUK_ERR_TYPE_ERROR, "cannot open file %s for reading, errno %ld: %s",
+		          fn, (long) errno, strerror(errno));
+	}
+
+	rc = fseek(f, 0, SEEK_END);
+	if (rc < 0) {
+		(void) fclose(f);
+		duk_error(ctx, DUK_ERR_TYPE_ERROR, "fseek() failed for %s, errno %ld: %s",
+		          fn, (long) errno, strerror(errno));
+	}
+	len = (size_t) ftell(f);
+	rc = fseek(f, 0, SEEK_SET);
+	if (rc < 0) {
+		(void) fclose(f);
+		duk_error(ctx, DUK_ERR_TYPE_ERROR, "fseek() failed for %s, errno %ld: %s",
+		          fn, (long) errno, strerror(errno));
+	}
+
+	buf = (char *) duk_push_fixed_buffer(ctx, (duk_size_t) len);
+	for (off = 0; off < len;) {
+		size_t got;
+		got = fread((void *) (buf + off), 1, len - off, f);
+		if (ferror(f)) {
+			(void) fclose(f);
+			duk_error(ctx, DUK_ERR_TYPE_ERROR, "error while reading %s", fn);
+		}
+		if (got == 0) {
+			if (feof(f)) {
+				break;
+			} else {
+				(void) fclose(f);
+				duk_error(ctx, DUK_ERR_TYPE_ERROR, "error while reading %s", fn);
+			}
+		}
+		off += got;
+	}
+
+	if (f) {
+		(void) fclose(f);
+	}
+
+	return 1;
+}
+
+static duk_ret_t fileio_write_file(duk_context *ctx) {
+	const char *fn;
+	const char *buf;
+	size_t len;
+	size_t off;
+	FILE *f;
+
+	fn = duk_require_string(ctx, 0);
+	f = fopen(fn, "wb");
+	if (!f) {
+		duk_error(ctx, DUK_ERR_TYPE_ERROR, "cannot open file %s for writing, errno %ld: %s",
+		          fn, (long) errno, strerror(errno));
+	}
+
+	len = 0;
+	buf = (char *) duk_to_buffer(ctx, 1, &len);
+	for (off = 0; off < len;) {
+		size_t got;
+		got = fwrite((const void *) (buf + off), 1, len - off, f);
+		if (ferror(f)) {
+			(void) fclose(f);
+			duk_error(ctx, DUK_ERR_TYPE_ERROR, "error while writing %s", fn);
+		}
+		if (got == 0) {
+			(void) fclose(f);
+			duk_error(ctx, DUK_ERR_TYPE_ERROR, "error while writing %s", fn);
+		}
+		off += got;
+	}
+
+	if (f) {
+		(void) fclose(f);
+	}
+
+	return 0;
+}
+#endif  /* DUK_CMDLINE_FILEIO */
+
+/*
+ *  Duktape heap lifecycle
+ */
+
+#if defined(DUK_CMDLINE_DEBUGGER_SUPPORT)
+static duk_idx_t debugger_request(duk_context *ctx, void *udata, duk_idx_t nvalues) {
+	const char *cmd;
+	int i;
+
+	(void) udata;
+
+	if (nvalues < 1) {
+		duk_push_string(ctx, "missing AppRequest argument(s)");
+		return -1;
+	}
+
+	cmd = duk_get_string(ctx, -nvalues + 0);
+
+	if (cmd && strcmp(cmd, "CommandLine") == 0) {
+		if (!duk_check_stack(ctx, main_argc)) {
+			/* Callback should avoid errors for now, so use
+			 * duk_check_stack() rather than duk_require_stack().
+			 */
+			duk_push_string(ctx, "failed to extend stack");
+			return -1;
+		}
+		for (i = 0; i < main_argc; i++) {
+			duk_push_string(ctx, main_argv[i]);
+		}
+		return main_argc;
+	}
+	duk_push_sprintf(ctx, "command not supported");
+	return -1;
+}
+
+static void debugger_detached(void *udata) {
+	duk_context *ctx = (duk_context *) udata;
+	(void) ctx;
+	fprintf(stderr, "Debugger detached, udata: %p\n", (void *) udata);
+	fflush(stderr);
+
+	/* Ensure socket is closed even when detach is initiated by Duktape
+	 * rather than debug client.
+	 */
+        duk_trans_socket_finish();
+
+	if (debugger_reattach) {
+		/* For automatic reattach testing. */
+		duk_trans_socket_init();
+		duk_trans_socket_waitconn();
+		fprintf(stderr, "Debugger reconnected, call duk_debugger_attach()\n");
+		fflush(stderr);
+#if 0
+		/* This is not necessary but should be harmless. */
+		duk_debugger_detach(ctx);
+#endif
+		duk_debugger_attach_custom(ctx,
+		                           duk_trans_socket_read_cb,
+		                           duk_trans_socket_write_cb,
+		                           duk_trans_socket_peek_cb,
+		                           duk_trans_socket_read_flush_cb,
+		                           duk_trans_socket_write_flush_cb,
+		                           debugger_request,
+		                           debugger_detached,
+		                           (void *) ctx);
+	}
+}
+#endif
+
+#define  ALLOC_DEFAULT  0
+#define  ALLOC_LOGGING  1
+#define  ALLOC_TORTURE  2
+#define  ALLOC_HYBRID   3
+#define  ALLOC_AJSHEAP  4
+
+static duk_context *create_duktape_heap(int alloc_provider, int debugger, int ajsheap_log) {
+	duk_context *ctx;
+
+	(void) ajsheap_log;  /* suppress warning */
+
+	ctx = NULL;
+	if (!ctx && alloc_provider == ALLOC_LOGGING) {
+#if defined(DUK_CMDLINE_ALLOC_LOGGING)
+		ctx = duk_create_heap(duk_alloc_logging,
+		                      duk_realloc_logging,
+		                      duk_free_logging,
+		                      (void *) 0xdeadbeef,
+		                      NULL);
+#else
+		fprintf(stderr, "Warning: option --alloc-logging ignored, no logging allocator support\n");
+		fflush(stderr);
+#endif
+	}
+	if (!ctx && alloc_provider == ALLOC_TORTURE) {
+#if defined(DUK_CMDLINE_ALLOC_TORTURE)
+		ctx = duk_create_heap(duk_alloc_torture,
+		                      duk_realloc_torture,
+		                      duk_free_torture,
+		                      (void *) 0xdeadbeef,
+		                      NULL);
+#else
+		fprintf(stderr, "Warning: option --alloc-torture ignored, no torture allocator support\n");
+		fflush(stderr);
+#endif
+	}
+	if (!ctx && alloc_provider == ALLOC_HYBRID) {
+#if defined(DUK_CMDLINE_ALLOC_HYBRID)
+		void *udata = duk_alloc_hybrid_init();
+		if (!udata) {
+			fprintf(stderr, "Failed to init hybrid allocator\n");
+			fflush(stderr);
+		} else {
+			ctx = duk_create_heap(duk_alloc_hybrid,
+			                      duk_realloc_hybrid,
+			                      duk_free_hybrid,
+			                      udata,
+			                      NULL);
+		}
+#else
+		fprintf(stderr, "Warning: option --alloc-hybrid ignored, no hybrid allocator support\n");
+		fflush(stderr);
+#endif
+	}
+	if (!ctx && alloc_provider == ALLOC_AJSHEAP) {
+#if defined(DUK_CMDLINE_AJSHEAP)
+		ajsheap_init();
+
+		ctx = duk_create_heap(
+			ajsheap_log ? ajsheap_alloc_wrapped : AJS_Alloc,
+			ajsheap_log ? ajsheap_realloc_wrapped : AJS_Realloc,
+			ajsheap_log ? ajsheap_free_wrapped : AJS_Free,
+			(void *) 0xdeadbeef,  /* heap_udata: ignored by AjsHeap, use as marker */
+			NULL
+		);                /* fatal_handler */
+#else
+		fprintf(stderr, "Warning: option --alloc-ajsheap ignored, no ajsheap allocator support\n");
+		fflush(stderr);
+#endif
+	}
+	if (!ctx && alloc_provider == ALLOC_DEFAULT) {
+		ctx = duk_create_heap_default();
+	}
+
+	if (!ctx) {
+		fprintf(stderr, "Failed to create Duktape heap\n");
+		fflush(stderr);
+		exit(-1);
+	}
+
+#if defined(DUK_CMDLINE_AJSHEAP)
+	if (alloc_provider == ALLOC_AJSHEAP) {
+		fprintf(stdout, "Pool dump after heap creation\n");
+		ajsheap_dump();
+	}
+#endif
+
+#if defined(DUK_CMDLINE_AJSHEAP)
+	if (alloc_provider == ALLOC_AJSHEAP) {
+		ajsheap_register(ctx);
+	}
+#endif
+
+#if defined(DUK_CMDLINE_FILEIO)
+	duk_push_c_function(ctx, fileio_read_file, 1 /*nargs*/);
+	duk_put_global_string(ctx, "readFile");
+	duk_push_c_function(ctx, fileio_write_file, 2 /*nargs*/);
+	duk_put_global_string(ctx, "writeFile");
+#endif
+
+	if (debugger) {
+#if defined(DUK_CMDLINE_DEBUGGER_SUPPORT)
+		fprintf(stderr, "Debugger enabled, create socket and wait for connection\n");
+		fflush(stderr);
+		duk_trans_socket_init();
+		duk_trans_socket_waitconn();
+		fprintf(stderr, "Debugger connected, call duk_debugger_attach() and then execute requested file(s)/eval\n");
+		fflush(stderr);
+		duk_debugger_attach_custom(ctx,
+		                           duk_trans_socket_read_cb,
+		                           duk_trans_socket_write_cb,
+		                           duk_trans_socket_peek_cb,
+		                           duk_trans_socket_read_flush_cb,
+		                           duk_trans_socket_write_flush_cb,
+		                           debugger_request,
+		                           debugger_detached,
+		                           (void *) ctx);
+#else
+		fprintf(stderr, "Warning: option --debugger ignored, no debugger support\n");
+		fflush(stderr);
+#endif
+	}
+
+#if 0
+	/* Manual test for duk_debugger_cooperate() */
+	{
+		for (i = 0; i < 60; i++) {
+			printf("cooperate: %d\n", i);
+			usleep(1000000);
+			duk_debugger_cooperate(ctx);
+		}
+	}
+#endif
+
+	return ctx;
+}
+
+static void destroy_duktape_heap(duk_context *ctx, int alloc_provider) {
+	(void) alloc_provider;
+
+#if defined(DUK_CMDLINE_AJSHEAP)
+	if (alloc_provider == ALLOC_AJSHEAP) {
+		fprintf(stdout, "Pool dump before duk_destroy_heap(), before forced gc\n");
+		ajsheap_dump();
+
+		duk_gc(ctx, 0);
+
+		fprintf(stdout, "Pool dump before duk_destroy_heap(), after forced gc\n");
+		ajsheap_dump();
+	}
+#endif
+
+	if (ctx) {
+		duk_destroy_heap(ctx);
+	}
+
+#if defined(DUK_CMDLINE_AJSHEAP)
+	if (alloc_provider == ALLOC_AJSHEAP) {
+		fprintf(stdout, "Pool dump after duk_destroy_heap() (should have zero allocs)\n");
+		ajsheap_dump();
+	}
+	ajsheap_free();
+#endif
+}
+
+/*
+ *  Main
+ */
+
+int main(int argc, char *argv[]) {
+	duk_context *ctx = NULL;
+	int retval = 0;
+	int have_files = 0;
+	int have_eval = 0;
+	int interactive = 0;
+	int memlimit_high = 1;
+	int alloc_provider = ALLOC_DEFAULT;
+	int ajsheap_log = 0;
+	int debugger = 0;
+	int recreate_heap = 0;
+	int no_heap_destroy = 0;
+	int verbose = 0;
+	int run_stdin = 0;
+	const char *compile_filename = NULL;
+	int i;
+
+	main_argc = argc;
+	main_argv = (char **) argv;
+
+#if defined(EMSCRIPTEN)
+	/* Try to use NODEFS to provide access to local files.  Mount the
+	 * CWD as /working, and then prepend "/working/" to relative native
+	 * paths in file calls to get something that works reasonably for
+	 * relative paths.  Emscripten doesn't support replacing virtual
+	 * "/" with host "/" (the default MEMFS at "/" can't be unmounted)
+	 * but we can mount "/tmp" as host "/tmp" to allow testcase runs.
+	 *
+	 * https://kripken.github.io/emscripten-site/docs/api_reference/Filesystem-API.html#filesystem-api-nodefs
+	 * https://github.com/kripken/emscripten/blob/master/tests/fs/test_nodefs_rw.c
+	 */
+	EM_ASM(
+		/* At the moment it's not possible to replace the default MEMFS mounted at '/':
+		 * https://github.com/kripken/emscripten/issues/2040
+		 * https://github.com/kripken/emscripten/blob/incoming/src/library_fs.js#L1341-L1358
+		 */
+		/*
+		try {
+			FS.unmount("/");
+		} catch (e) {
+			console.log("Failed to unmount default '/' MEMFS mount: " + e);
+		}
+		*/
+		try {
+			FS.mkdir("/working");
+			FS.mount(NODEFS, { root: "." }, "/working");
+		} catch (e) {
+			console.log("Failed to mount NODEFS /working: " + e);
+		}
+		/* A virtual '/tmp' exists by default:
+		 * https://gist.github.com/evanw/e6be28094f34451bd5bd#file-temp-js-L3806-L3809
+		 */
+		/*
+		try {
+			FS.mkdir("/tmp");
+		} catch (e) {
+			console.log("Failed to create virtual /tmp: " + e);
+		}
+		*/
+		try {
+			FS.mount(NODEFS, { root: "/tmp" }, "/tmp");
+		} catch (e) {
+			console.log("Failed to mount NODEFS /tmp: " + e);
+		}
+	);
+#endif  /* EMSCRIPTEN */
+
+#if defined(DUK_CMDLINE_AJSHEAP)
+	alloc_provider = ALLOC_AJSHEAP;
+#endif
+	(void) ajsheap_log;
+
+	/*
+	 *  Signal handling setup
+	 */
+
+#if defined(DUK_CMDLINE_SIGNAL)
+	set_sigint_handler();
+
+	/* This is useful at the global level; libraries should avoid SIGPIPE though */
+	/*signal(SIGPIPE, SIG_IGN);*/
+#endif
+
+	/*
+	 *  Parse options
+	 */
+
+	for (i = 1; i < argc; i++) {
+		char *arg = argv[i];
+		if (!arg) {
+			goto usage;
+		}
+		if (strcmp(arg, "--restrict-memory") == 0) {
+			memlimit_high = 0;
+		} else if (strcmp(arg, "-i") == 0) {
+			interactive = 1;
+		} else if (strcmp(arg, "-c") == 0) {
+			if (i == argc - 1) {
+				goto usage;
+			}
+			i++;
+			compile_filename = argv[i];
+		} else if (strcmp(arg, "-e") == 0) {
+			have_eval = 1;
+			if (i == argc - 1) {
+				goto usage;
+			}
+			i++;  /* skip code */
+		} else if (strcmp(arg, "--alloc-default") == 0) {
+			alloc_provider = ALLOC_DEFAULT;
+		} else if (strcmp(arg, "--alloc-logging") == 0) {
+			alloc_provider = ALLOC_LOGGING;
+		} else if (strcmp(arg, "--alloc-torture") == 0) {
+			alloc_provider = ALLOC_TORTURE;
+		} else if (strcmp(arg, "--alloc-hybrid") == 0) {
+			alloc_provider = ALLOC_HYBRID;
+		} else if (strcmp(arg, "--alloc-ajsheap") == 0) {
+			alloc_provider = ALLOC_AJSHEAP;
+		} else if (strcmp(arg, "--ajsheap-log") == 0) {
+			ajsheap_log = 1;
+		} else if (strcmp(arg, "--debugger") == 0) {
+			debugger = 1;
+#if defined(DUK_CMDLINE_DEBUGGER_SUPPORT)
+		} else if (strcmp(arg, "--reattach") == 0) {
+			debugger_reattach = 1;
+#endif
+		} else if (strcmp(arg, "--recreate-heap") == 0) {
+			recreate_heap = 1;
+		} else if (strcmp(arg, "--no-heap-destroy") == 0) {
+			no_heap_destroy = 1;
+		} else if (strcmp(arg, "--verbose") == 0) {
+			verbose = 1;
+		} else if (strcmp(arg, "--run-stdin") == 0) {
+			run_stdin = 1;
+		} else if (strlen(arg) >= 1 && arg[0] == '-') {
+			goto usage;
+		} else {
+			have_files = 1;
+		}
+	}
+	if (!have_files && !have_eval && !run_stdin) {
+		interactive = 1;
+	}
+
+	/*
+	 *  Memory limit
+	 */
+
+#if defined(DUK_CMDLINE_RLIMIT)
+	set_resource_limits(memlimit_high ? MEM_LIMIT_HIGH : MEM_LIMIT_NORMAL);
+#else
+	if (memlimit_high == 0) {
+		fprintf(stderr, "Warning: option --restrict-memory ignored, no rlimit support\n");
+		fflush(stderr);
+	}
+#endif
+
+	/*
+	 *  Create heap
+	 */
+
+	ctx = create_duktape_heap(alloc_provider, debugger, ajsheap_log);
+
+	/*
+	 *  Execute any argument file(s)
+	 */
+
+	for (i = 1; i < argc; i++) {
+		char *arg = argv[i];
+		if (!arg) {
+			continue;
+		} else if (strlen(arg) == 2 && strcmp(arg, "-e") == 0) {
+			/* Here we know the eval arg exists but check anyway */
+			if (i == argc - 1) {
+				retval = 1;
+				goto cleanup;
+			}
+			if (handle_eval(ctx, argv[i + 1]) != 0) {
+				retval = 1;
+				goto cleanup;
+			}
+			i++;  /* skip code */
+			continue;
+		} else if (strlen(arg) == 2 && strcmp(arg, "-c") == 0) {
+			i++;  /* skip filename */
+			continue;
+		} else if (strlen(arg) >= 1 && arg[0] == '-') {
+			continue;
+		}
+
+		if (verbose) {
+			fprintf(stderr, "*** Executing file: %s\n", arg);
+			fflush(stderr);
+		}
+
+		if (handle_file(ctx, arg, compile_filename) != 0) {
+			retval = 1;
+			goto cleanup;
+		}
+
+		if (recreate_heap) {
+			if (verbose) {
+				fprintf(stderr, "*** Recreating heap...\n");
+				fflush(stderr);
+			}
+
+			destroy_duktape_heap(ctx, alloc_provider);
+			ctx = create_duktape_heap(alloc_provider, debugger, ajsheap_log);
+		}
+	}
+
+	if (run_stdin) {
+		/* Running stdin like a full file (reading all lines before
+		 * compiling) is useful with emduk:
+		 * cat test.js | ./emduk --run-stdin
+		 */
+		if (handle_fh(ctx, stdin, "stdin", compile_filename) != 0) {
+			retval = 1;
+			goto cleanup;
+		}
+
+		if (recreate_heap) {
+			if (verbose) {
+				fprintf(stderr, "*** Recreating heap...\n");
+				fflush(stderr);
+			}
+
+			destroy_duktape_heap(ctx, alloc_provider);
+			ctx = create_duktape_heap(alloc_provider, debugger, ajsheap_log);
+		}
+	}
+
+	/*
+	 *  Enter interactive mode if options indicate it
+	 */
+
+	if (interactive) {
+		if (handle_interactive(ctx) != 0) {
+			retval = 1;
+			goto cleanup;
+		}
+	}
+
+	/*
+	 *  Cleanup and exit
+	 */
+
+ cleanup:
+	if (interactive) {
+		fprintf(stderr, "Cleaning up...\n");
+		fflush(stderr);
+	}
+
+	if (ctx && no_heap_destroy) {
+		duk_gc(ctx, 0);
+	}
+	if (ctx && !no_heap_destroy) {
+		destroy_duktape_heap(ctx, alloc_provider);
+	}
+	ctx = NULL;
+
+	return retval;
+
+	/*
+	 *  Usage
+	 */
+
+ usage:
+	fprintf(stderr, "Usage: duk [options] [<filenames>]\n"
+	                "\n"
+	                "   -i                 enter interactive mode after executing argument file(s) / eval code\n"
+	                "   -e CODE            evaluate code\n"
+			"   -c FILE            compile into bytecode (use with only one file argument)\n"
+			"   --run-stdin        treat stdin like a file, i.e. compile full input (not line by line)\n"
+			"   --verbose          verbose messages to stderr\n"
+	                "   --restrict-memory  use lower memory limit (used by test runner)\n"
+	                "   --alloc-default    use Duktape default allocator\n"
+#if defined(DUK_CMDLINE_ALLOC_LOGGING)
+	                "   --alloc-logging    use logging allocator (writes to /tmp)\n"
+#endif
+#if defined(DUK_CMDLINE_ALLOC_TORTURE)
+	                "   --alloc-torture    use torture allocator\n"
+#endif
+#if defined(DUK_CMDLINE_ALLOC_HYBRID)
+	                "   --alloc-hybrid     use hybrid allocator\n"
+#endif
+#if defined(DUK_CMDLINE_AJSHEAP)
+	                "   --alloc-ajsheap    use ajsheap allocator (enabled by default with 'ajduk')\n"
+	                "   --ajsheap-log      write alloc log to /tmp/ajduk-alloc-log.txt\n"
+#endif
+#if defined(DUK_CMDLINE_DEBUGGER_SUPPORT)
+			"   --debugger         start example debugger\n"
+			"   --reattach         automatically reattach debugger on detach\n"
+#endif
+			"   --recreate-heap    recreate heap after every file\n"
+			"   --no-heap-destroy  force GC, but don't destroy heap at end (leak testing)\n"
+	                "\n"
+	                "If <filename> is omitted, interactive mode is started automatically.\n");
+	fflush(stderr);
+	exit(1);
+}

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/cmdline/duk_cmdline_ajduk.c
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/cmdline/duk_cmdline_ajduk.c b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/cmdline/duk_cmdline_ajduk.c
new file mode 100644
index 0000000..ae28ede
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/cmdline/duk_cmdline_ajduk.c
@@ -0,0 +1,1008 @@
+/*
+ *  'ajduk' specific functionality, examples for low memory techniques
+ */
+
+#ifdef DUK_CMDLINE_AJSHEAP
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include "ajs.h"
+#include "ajs_heap.h"
+#include "duktape.h"
+
+extern uint8_t dbgHEAPDUMP;
+
+#if defined(DUK_USE_ROM_OBJECTS) && defined(DUK_USE_HEAPPTR16)
+/* Pointer compression with ROM strings/objects:
+ *
+ * For now, use DUK_USE_ROM_OBJECTS to signal the need for compressed ROM
+ * pointers.  DUK_USE_ROM_PTRCOMP_FIRST is provided for the ROM pointer
+ * compression range minimum to avoid duplication in user code.
+ */
+#if 0  /* This extern declaration is provided by duktape.h, array provided by duktape.c. */
+extern const void * const duk_rom_compressed_pointers[];
+#endif
+static const void *duk__romptr_low = NULL;
+static const void *duk__romptr_high = NULL;
+#define DUK__ROMPTR_COMPRESSION
+#define DUK__ROMPTR_FIRST DUK_USE_ROM_PTRCOMP_FIRST
+#endif
+
+/*
+ *  Helpers
+ */
+
+static void *ajduk__lose_const(const void *ptr) {
+	/* Somewhat portable way of losing a const without warnings.
+	 * Another approach is to cast through intptr_t, but that
+	 * type is not always available.
+	 */
+	union {
+		const void *p;
+		void *q;
+	} u;
+	u.p = ptr;
+	return u.q;
+}
+
+static void safe_print_chars(const char *p, duk_size_t len, int until_nul) {
+	duk_size_t i;
+
+	printf("\"");
+	for (i = 0; i < len; i++) {
+		unsigned char x = (unsigned char) p[i];
+		if (until_nul && x == 0U) {
+			break;
+		}
+		if (x < 0x20 || x >= 0x7e || x == '"' || x == '\'' || x == '\\') {
+			printf("\\x%02x", (int) x);
+		} else {
+			printf("%c", (char) x);
+		}
+	}
+	printf("\"");
+}
+
+/*
+ *  Heap initialization when using AllJoyn.js pool allocator (without any
+ *  other AllJoyn.js integration).  This serves as an example of how to
+ *  integrate Duktape with a pool allocator and is useful for low memory
+ *  testing.
+ *
+ *  The pool sizes are not optimized here.  The sizes are chosen so that
+ *  you can look at the high water mark (hwm) and use counts (use) and see
+ *  how much allocations are needed for each pool size.  To optimize pool
+ *  sizes more accurately, you can use --alloc-logging and inspect the memory
+ *  allocation log which provides exact byte counts etc.
+ *
+ *  https://git.allseenalliance.org/cgit/core/alljoyn-js.git
+ *  https://git.allseenalliance.org/cgit/core/alljoyn-js.git/tree/ajs.c
+ */
+
+static const AJS_HeapConfig ajsheap_config[] = {
+	{ 8,      10,   AJS_POOL_BORROW,  0 },
+	{ 12,     600,  AJS_POOL_BORROW,  0 },
+	{ 16,     300,  AJS_POOL_BORROW,  0 },
+	{ 20,     300,  AJS_POOL_BORROW,  0 },
+	{ 24,     300,  AJS_POOL_BORROW,  0 },
+	{ 28,     150,  AJS_POOL_BORROW,  0 },
+	{ 32,     150,  AJS_POOL_BORROW,  0 },
+	{ 40,     150,  AJS_POOL_BORROW,  0 },
+	{ 48,     50,   AJS_POOL_BORROW,  0 },
+	{ 52,     50,   AJS_POOL_BORROW,  0 },
+	{ 56,     50,   AJS_POOL_BORROW,  0 },
+	{ 60,     50,   AJS_POOL_BORROW,  0 },
+	{ 64,     50,   AJS_POOL_BORROW,  0 },
+	{ 128,    80,   AJS_POOL_BORROW,  0 },
+	{ 256,    16,   AJS_POOL_BORROW,  0 },
+	{ 320,    1,    AJS_POOL_BORROW,  0 },
+	{ 392,    1,    AJS_POOL_BORROW,  0 },  /* duk_hthread, with heap ptr compression, ROM strings+objects */
+	{ 512,    16,   AJS_POOL_BORROW,  0 },
+	{ 964,    1,    AJS_POOL_BORROW,  0 },  /* duk_heap, with heap ptr compression, ROM strings+objects */
+	{ 1024,   6,    AJS_POOL_BORROW,  0 },
+	{ 1344,   1,    AJS_POOL_BORROW,  0 },  /* duk_heap, with heap ptr compression, RAM strings+objects */
+	{ 2048,   5,    AJS_POOL_BORROW,  0 },
+	{ 4096,   3,    0,                0 },
+	{ 8192,   3,    0,                0 },
+	{ 16384,  1,    0,                0 },
+	{ 32768,  1,    0,                0 }
+};
+
+uint8_t *ajsheap_ram = NULL;
+
+void ajsheap_init(void) {
+	size_t heap_sz[1];
+	uint8_t *heap_array[1];
+	uint8_t num_pools, i;
+	AJ_Status ret;
+
+	num_pools = (uint8_t) (sizeof(ajsheap_config) / sizeof(AJS_HeapConfig));
+	heap_sz[0] = AJS_HeapRequired(ajsheap_config,  /* heapConfig */
+	                              num_pools,       /* numPools */
+	                              0);              /* heapNum */
+	ajsheap_ram = (uint8_t *) malloc(heap_sz[0]);
+	if (ajsheap_ram == NULL) {
+		fprintf(stderr, "Failed to allocate AJS heap\n");
+		fflush(stderr);
+		exit(1);
+	}
+	heap_array[0] = ajsheap_ram;
+
+	fprintf(stderr, "Allocated AJS heap of %ld bytes, pools:", (long) heap_sz[0]);
+	for (i = 0; i < num_pools; i++) {
+		fprintf(stderr, " (sz:%ld,num:%ld,brw:%ld,idx:%ld)",
+		        (long) ajsheap_config[i].size, (long) ajsheap_config[i].entries,
+		        (long) ajsheap_config[i].borrow, (long) ajsheap_config[i].heapIndex);
+	}
+	fprintf(stderr, "\n");
+	fflush(stderr);
+
+	ret = AJS_HeapInit((void **) heap_array,   /* heap */
+	                   (size_t *) heap_sz,     /* heapSz */
+	                   ajsheap_config,         /* heapConfig */
+	                   num_pools,              /* numPools */
+	                   1);                     /* numHeaps */
+	fprintf(stderr, "AJS_HeapInit() -> %ld\n", (long) ret);
+	fflush(stderr);
+
+	/* Enable heap dumps */
+	dbgHEAPDUMP = 1;
+
+#if defined(DUK__ROMPTR_COMPRESSION)
+	/* Scan ROM pointer range for faster detection of "is 'p' a ROM pointer"
+	 * later on.
+	 */
+	if (1) {
+		const void * const * ptrs = (const void * const *) duk_rom_compressed_pointers;
+		duk__romptr_low = duk__romptr_high = (const void *) *ptrs;
+		while (*ptrs) {
+			if (*ptrs > duk__romptr_high) {
+				duk__romptr_high = (const void *) *ptrs;
+			}
+			if (*ptrs < duk__romptr_low) {
+				duk__romptr_low = (const void *) *ptrs;
+			}
+			ptrs++;
+		}
+		fprintf(stderr, "romptrs: low=%p high=%p\n",
+		        (const void *) duk__romptr_low, (const void *) duk__romptr_high);
+		fflush(stderr);
+	}
+#endif
+}
+
+void ajsheap_free(void) {
+	if (ajsheap_ram != NULL) {
+		free(ajsheap_ram);
+		ajsheap_ram = NULL;
+	}
+}
+
+/* AjsHeap.dump(), allows Ecmascript code to dump heap status at suitable
+ * points.
+ */
+duk_ret_t ajsheap_dump_binding(duk_context *ctx) {
+	AJS_HeapDump();
+	fflush(stdout);
+	return 0;
+}
+
+void ajsheap_dump(void) {
+	AJS_HeapDump();
+	fflush(stdout);
+}
+
+void ajsheap_register(duk_context *ctx) {
+	duk_push_object(ctx);
+	duk_push_c_function(ctx, ajsheap_dump_binding, 0);
+	duk_put_prop_string(ctx, -2, "dump");
+	duk_put_global_string(ctx, "AjsHeap");
+}
+
+/*
+ *  Wrapped ajs_heap.c alloc functions
+ *
+ *  Used to write an alloc log.
+ */
+
+static FILE *ajsheap_alloc_log = NULL;
+
+static void ajsheap_write_alloc_log(const char *fmt, ...) {
+	va_list ap;
+	char buf[256];
+
+	va_start(ap, fmt);
+	vsnprintf(buf, sizeof(buf), fmt, ap);
+	buf[sizeof(buf) - 1] = (char) 0;
+	va_end(ap);
+
+	if (ajsheap_alloc_log == NULL) {
+		ajsheap_alloc_log = fopen("/tmp/ajduk-alloc-log.txt", "wb");
+		if (ajsheap_alloc_log == NULL) {
+			fprintf(stderr, "WARNING: failed to write alloc log, ignoring\n");
+			fflush(stderr);
+			return;
+		}
+	}
+
+	(void) fwrite((const void *) buf, 1, strlen(buf), ajsheap_alloc_log);
+	(void) fflush(ajsheap_alloc_log);
+}
+
+void *ajsheap_alloc_wrapped(void *udata, duk_size_t size) {
+	void *ret = AJS_Alloc(udata, size);
+	if (size > 0 && ret == NULL) {
+		ajsheap_write_alloc_log("A FAIL %ld\n", (long) size);
+	} else if (ret == NULL) {
+		ajsheap_write_alloc_log("A NULL %ld\n", (long) size);
+	} else {
+		ajsheap_write_alloc_log("A %p %ld\n", ret, (long) size);
+	}
+	return ret;
+}
+
+void *ajsheap_realloc_wrapped(void *udata, void *ptr, duk_size_t size) {
+	void *ret = AJS_Realloc(udata, ptr, size);
+	if (size > 0 && ret == NULL) {
+		if (ptr == NULL) {
+			ajsheap_write_alloc_log("R NULL -1 FAIL %ld\n", (long) size);
+		} else {
+			ajsheap_write_alloc_log("R %p -1 FAIL %ld\n", ptr, (long) size);
+		}
+	} else if (ret == NULL) {
+		if (ptr == NULL) {
+			ajsheap_write_alloc_log("R NULL -1 NULL %ld\n", (long) size);
+		} else {
+			ajsheap_write_alloc_log("R %p -1 NULL %ld\n", ptr, (long) size);
+		}
+	} else {
+		if (ptr == NULL) {
+			ajsheap_write_alloc_log("R NULL -1 %p %ld\n", ret, (long) size);
+		} else {
+			ajsheap_write_alloc_log("R %p -1 %p %ld\n", ptr, ret, (long) size);
+		}
+	}
+	return ret;
+}
+
+void ajsheap_free_wrapped(void *udata, void *ptr) {
+	AJS_Free(udata, ptr);
+	if (ptr == NULL) {
+	} else {
+		ajsheap_write_alloc_log("F %p -1\n", ptr);
+	}
+}
+
+/*
+ *  Example pointer compression functions.
+ *
+ *  'base' is chosen so that no non-NULL pointer results in a zero result
+ *  which is reserved for NULL pointers.
+ */
+
+duk_uint16_t ajsheap_enc16(void *ud, void *p) {
+	duk_uint32_t ret;
+	char *base = (char *) ajsheap_ram - 4;
+
+#if defined(DUK__ROMPTR_COMPRESSION)
+	if (p >= duk__romptr_low && p <= duk__romptr_high) {
+		/* The if-condition should be the fastest possible check
+		 * for "is 'p' in ROM?".  If pointer is in ROM, we'd like
+		 * to compress it quickly.  Here we just scan a ~1K array
+		 * which is very bad for performance and for illustration
+		 * only.
+		 */
+		const void * const * ptrs = duk_rom_compressed_pointers;
+		while (*ptrs) {
+			if (*ptrs == p) {
+				ret = DUK__ROMPTR_FIRST + (ptrs - duk_rom_compressed_pointers);
+#if 0
+				fprintf(stderr, "ajsheap_enc16: rom pointer: %p -> 0x%04lx\n", (void *) p, (long) ret);
+				fflush(stderr);
+#endif
+				return (duk_uint16_t) ret;
+			}
+			ptrs++;
+		}
+
+		/* We should really never be here: Duktape should only be
+		 * compressing pointers which are in the ROM compressed
+		 * pointers list, which are known at 'make dist' time.
+		 * We go on, causing a pointer compression error.
+		 */
+		fprintf(stderr, "ajsheap_enc16: rom pointer: %p could not be compressed, should never happen\n", (void *) p);
+		fflush(stderr);
+	}
+#endif
+
+	/* Userdata is not needed in this case but would be useful if heap
+	 * pointer compression were used for multiple heaps.  The userdata
+	 * allows the callback to distinguish between heaps and their base
+	 * pointers.
+	 *
+	 * If not needed, the userdata can be left out during compilation
+	 * by simply ignoring the userdata argument of the pointer encode
+	 * and decode macros.  It is kept here so that any bugs in actually
+	 * providing the value inside Duktape are revealed during compilation.
+	 */
+	(void) ud;
+#if 1
+	/* Ensure that we always get the heap_udata given in heap creation.
+	 * (Useful for Duktape development, not needed for user programs.)
+	 */
+	if (ud != (void *) 0xdeadbeef) {
+		fprintf(stderr, "invalid udata for ajsheap_enc16: %p\n", ud);
+		fflush(stderr);
+	}
+#endif
+
+	if (p == NULL) {
+		ret = 0;
+	} else {
+		ret = (duk_uint32_t) (((char *) p - base) >> 2);
+	}
+#if 0
+	printf("ajsheap_enc16: %p -> %u\n", p, (unsigned int) ret);
+#endif
+	if (ret > 0xffffUL) {
+		fprintf(stderr, "Failed to compress pointer: %p (ret was %ld)\n", (void *) p, (long) ret);
+		fflush(stderr);
+		abort();
+	}
+#if defined(DUK__ROMPTR_COMPRESSION)
+	if (ret >= DUK__ROMPTR_FIRST) {
+		fprintf(stderr, "Failed to compress pointer, in 16-bit range but matches romptr range: %p (ret was %ld)\n", (void *) p, (long) ret);
+		fflush(stderr);
+		abort();
+	}
+#endif
+	return (duk_uint16_t) ret;
+}
+
+void *ajsheap_dec16(void *ud, duk_uint16_t x) {
+	void *ret;
+	char *base = (char *) ajsheap_ram - 4;
+
+#if defined(DUK__ROMPTR_COMPRESSION)
+	if (x >= DUK__ROMPTR_FIRST) {
+		/* This is a blind lookup, could check index validity.
+		 * Duktape should never decompress a pointer which would
+		 * be out-of-bounds here.
+		 */
+		ret = (void *) ajduk__lose_const(duk_rom_compressed_pointers[x - DUK__ROMPTR_FIRST]);
+#if 0
+		fprintf(stderr, "ajsheap_dec16: rom pointer: 0x%04lx -> %p\n", (long) x, ret);
+		fflush(stderr);
+#endif
+		return ret;
+	}
+#endif
+
+	/* See userdata discussion in ajsheap_enc16(). */
+	(void) ud;
+#if 1
+	/* Ensure that we always get the heap_udata given in heap creation. */
+	if (ud != (void *) 0xdeadbeef) {
+		fprintf(stderr, "invalid udata for ajsheap_dec16: %p\n", ud);
+		fflush(stderr);
+	}
+#endif
+
+	if (x == 0) {
+		ret = NULL;
+	} else {
+		ret = (void *) (base + (((duk_uint32_t) x) << 2));
+	}
+#if 0
+	printf("ajsheap_dec16: %u -> %p\n", (unsigned int) x, ret);
+#endif
+	return ret;
+}
+
+/*
+ *  Simplified example of an external strings strategy where incoming strings
+ *  are written sequentially into a fixed, memory mapped flash area.
+ *
+ *  The example first scans if the string is already in the flash (which may
+ *  happen if the same string is interned multiple times), then adds it to
+ *  flash if there is space.
+ *
+ *  This example is too slow to be used in a real world application: there
+ *  should be e.g. a hash table to quickly check for strings that are already
+ *  present in the string data (similarly to how string interning works in
+ *  Duktape itself).
+ */
+
+static uint8_t ajsheap_strdata[65536];
+static size_t ajsheap_strdata_used = 0;
+
+const void *ajsheap_extstr_check_1(const void *ptr, duk_size_t len) {
+	uint8_t *p, *p_end;
+	uint8_t initial;
+	uint8_t *ret;
+	size_t left;
+
+	(void) safe_print_chars;  /* potentially unused */
+
+	if (len <= 3) {
+		/* It's not worth it to make very small strings external, as
+		 * they would take the same space anyway.  Also avoids zero
+		 * length degenerate case.
+		 */
+		return NULL;
+	}
+
+	/*
+	 *  Check if we already have the string.  Be careful to compare for
+	 *  NUL terminator too, it is NOT present in 'ptr'.  This algorithm
+	 *  is too simplistic and way too slow for actual use.
+	 */
+
+	initial = ((const uint8_t *) ptr)[0];
+	for (p = ajsheap_strdata, p_end = p + ajsheap_strdata_used; p != p_end; p++) {
+		if (*p != initial) {
+			continue;
+		}
+		left = (size_t) (p_end - p);
+		if (left >= len + 1 &&
+		    memcmp(p, ptr, len) == 0 &&
+		    p[len] == 0) {
+			ret = p;
+#if 0
+			printf("ajsheap_extstr_check_1: ptr=%p, len=%ld ",
+			       (void *) ptr, (long) len);
+			safe_print_chars((const char *) ptr, len, 0 /*until_nul*/);
+			printf(" -> existing %p (used=%ld)\n",
+			       (void *) ret, (long) ajsheap_strdata_used);
+#endif
+			return ret;
+		}
+	}
+
+	/*
+	 *  Not present yet, check if we have space.  Again, be careful to
+	 *  ensure there is space for a NUL following the input data.
+	 */
+
+	if (ajsheap_strdata_used + len + 1 > sizeof(ajsheap_strdata)) {
+#if 0
+		printf("ajsheap_extstr_check_1: ptr=%p, len=%ld ", (void *) ptr, (long) len);
+		safe_print_chars((const char *) ptr, len, 0 /*until_nul*/);
+		printf(" -> no space (used=%ld)\n", (long) ajsheap_strdata_used);
+#endif
+		return NULL;
+	}
+
+	/*
+	 *  There is space, add the string to our collection, being careful
+	 *  to append the NUL.
+	 */
+
+	ret = ajsheap_strdata + ajsheap_strdata_used;
+	memcpy(ret, ptr, len);
+	ret[len] = (uint8_t) 0;
+	ajsheap_strdata_used += len + 1;
+
+#if 0
+	printf("ajsheap_extstr_check_1: ptr=%p, len=%ld -> ", (void *) ptr, (long) len);
+	safe_print_chars((const char *) ptr, len, 0 /*until_nul*/);
+	printf(" -> %p (used=%ld)\n", (void *) ret, (long) ajsheap_strdata_used);
+#endif
+	return (const void *) ret;
+}
+
+void ajsheap_extstr_free_1(const void *ptr) {
+	(void) ptr;
+#if 0
+	printf("ajsheap_extstr_free_1: freeing extstr %p -> ", ptr);
+	safe_print_chars((const char *) ptr, DUK_SIZE_MAX, 1 /*until_nul*/);
+	printf("\n");
+#endif
+}
+
+/*
+ *  Simplified example of an external strings strategy where a set of strings
+ *  is gathered during application compile time and baked into the application
+ *  binary.
+ *
+ *  Duktape built-in strings are available from duk_build_meta.json, see
+ *  util/duk_meta_to_strarray.py.  There may also be a lot of application
+ *  specific strings, e.g. those used by application specific APIs.  These
+ *  must be gathered through some other means, see e.g. util/scan_strings.py.
+ */
+
+static const char *strdata_duk_builtin_strings[] = {
+	/*
+	 *  These strings are from util/duk_meta_to_strarray.py
+	 */
+
+	"Logger",
+	"Thread",
+	"Pointer",
+	"Buffer",
+	"DecEnv",
+	"ObjEnv",
+	"",
+	"global",
+	"Arguments",
+	"JSON",
+	"Math",
+	"Error",
+	"RegExp",
+	"Date",
+	"Number",
+	"Boolean",
+	"String",
+	"Array",
+	"Function",
+	"Object",
+	"Null",
+	"Undefined",
+	"{_func:true}",
+	"{\x22" "_func\x22" ":true}",
+	"{\x22" "_ninf\x22" ":true}",
+	"{\x22" "_inf\x22" ":true}",
+	"{\x22" "_nan\x22" ":true}",
+	"{\x22" "_undef\x22" ":true}",
+	"toLogString",
+	"clog",
+	"l",
+	"n",
+	"fatal",
+	"error",
+	"warn",
+	"debug",
+	"trace",
+	"raw",
+	"fmt",
+	"current",
+	"resume",
+	"compact",
+	"jc",
+	"jx",
+	"base64",
+	"hex",
+	"dec",
+	"enc",
+	"fin",
+	"gc",
+	"act",
+	"info",
+	"version",
+	"env",
+	"modLoaded",
+	"modSearch",
+	"errThrow",
+	"errCreate",
+	"compile",
+	"\xff" "Regbase",
+	"\xff" "Thread",
+	"\xff" "Handler",
+	"\xff" "Finalizer",
+	"\xff" "Callee",
+	"\xff" "Map",
+	"\xff" "Args",
+	"\xff" "This",
+	"\xff" "Pc2line",
+	"\xff" "Source",
+	"\xff" "Varenv",
+	"\xff" "Lexenv",
+	"\xff" "Varmap",
+	"\xff" "Formals",
+	"\xff" "Bytecode",
+	"\xff" "Next",
+	"\xff" "Target",
+	"\xff" "Value",
+	"pointer",
+	"buffer",
+	"\xff" "Tracedata",
+	"lineNumber",
+	"fileName",
+	"pc",
+	"stack",
+	"ThrowTypeError",
+	"Duktape",
+	"id",
+	"require",
+	"__proto__",
+	"setPrototypeOf",
+	"ownKeys",
+	"enumerate",
+	"deleteProperty",
+	"has",
+	"Proxy",
+	"callee",
+	"Invalid Date",
+	"[...]",
+	"\x0a" "\x09",
+	" ",
+	",",
+	"-0",
+	"+0",
+	"0",
+	"-Infinity",
+	"+Infinity",
+	"Infinity",
+	"object",
+	"string",
+	"number",
+	"boolean",
+	"undefined",
+	"stringify",
+	"tan",
+	"sqrt",
+	"sin",
+	"round",
+	"random",
+	"pow",
+	"min",
+	"max",
+	"log",
+	"floor",
+	"exp",
+	"cos",
+	"ceil",
+	"atan2",
+	"atan",
+	"asin",
+	"acos",
+	"abs",
+	"SQRT2",
+	"SQRT1_2",
+	"PI",
+	"LOG10E",
+	"LOG2E",
+	"LN2",
+	"LN10",
+	"E",
+	"message",
+	"name",
+	"input",
+	"index",
+	"(?:)",
+	"lastIndex",
+	"multiline",
+	"ignoreCase",
+	"source",
+	"test",
+	"exec",
+	"toGMTString",
+	"setYear",
+	"getYear",
+	"toJSON",
+	"toISOString",
+	"toUTCString",
+	"setUTCFullYear",
+	"setFullYear",
+	"setUTCMonth",
+	"setMonth",
+	"setUTCDate",
+	"setDate",
+	"setUTCHours",
+	"setHours",
+	"setUTCMinutes",
+	"setMinutes",
+	"setUTCSeconds",
+	"setSeconds",
+	"setUTCMilliseconds",
+	"setMilliseconds",
+	"setTime",
+	"getTimezoneOffset",
+	"getUTCMilliseconds",
+	"getMilliseconds",
+	"getUTCSeconds",
+	"getSeconds",
+	"getUTCMinutes",
+	"getMinutes",
+	"getUTCHours",
+	"getHours",
+	"getUTCDay",
+	"getDay",
+	"getUTCDate",
+	"getDate",
+	"getUTCMonth",
+	"getMonth",
+	"getUTCFullYear",
+	"getFullYear",
+	"getTime",
+	"toLocaleTimeString",
+	"toLocaleDateString",
+	"toTimeString",
+	"toDateString",
+	"now",
+	"UTC",
+	"parse",
+	"toPrecision",
+	"toExponential",
+	"toFixed",
+	"POSITIVE_INFINITY",
+	"NEGATIVE_INFINITY",
+	"NaN",
+	"MIN_VALUE",
+	"MAX_VALUE",
+	"substr",
+	"trim",
+	"toLocaleUpperCase",
+	"toUpperCase",
+	"toLocaleLowerCase",
+	"toLowerCase",
+	"substring",
+	"split",
+	"search",
+	"replace",
+	"match",
+	"localeCompare",
+	"charCodeAt",
+	"charAt",
+	"fromCharCode",
+	"reduceRight",
+	"reduce",
+	"filter",
+	"map",
+	"forEach",
+	"some",
+	"every",
+	"lastIndexOf",
+	"indexOf",
+	"unshift",
+	"splice",
+	"sort",
+	"slice",
+	"shift",
+	"reverse",
+	"push",
+	"pop",
+	"join",
+	"concat",
+	"isArray",
+	"arguments",
+	"caller",
+	"bind",
+	"call",
+	"apply",
+	"propertyIsEnumerable",
+	"isPrototypeOf",
+	"hasOwnProperty",
+	"valueOf",
+	"toLocaleString",
+	"toString",
+	"constructor",
+	"set",
+	"get",
+	"enumerable",
+	"configurable",
+	"writable",
+	"value",
+	"keys",
+	"isExtensible",
+	"isFrozen",
+	"isSealed",
+	"preventExtensions",
+	"freeze",
+	"seal",
+	"defineProperties",
+	"defineProperty",
+	"create",
+	"getOwnPropertyNames",
+	"getOwnPropertyDescriptor",
+	"getPrototypeOf",
+	"prototype",
+	"length",
+	"alert",
+	"print",
+	"unescape",
+	"escape",
+	"encodeURIComponent",
+	"encodeURI",
+	"decodeURIComponent",
+	"decodeURI",
+	"isFinite",
+	"isNaN",
+	"parseFloat",
+	"parseInt",
+	"eval",
+	"URIError",
+	"TypeError",
+	"SyntaxError",
+	"ReferenceError",
+	"RangeError",
+	"EvalError",
+	"break",
+	"case",
+	"catch",
+	"continue",
+	"debugger",
+	"default",
+	"delete",
+	"do",
+	"else",
+	"finally",
+	"for",
+	"function",
+	"if",
+	"in",
+	"instanceof",
+	"new",
+	"return",
+	"switch",
+	"this",
+	"throw",
+	"try",
+	"typeof",
+	"var",
+	"void",
+	"while",
+	"with",
+	"class",
+	"const",
+	"enum",
+	"export",
+	"extends",
+	"import",
+	"super",
+	"null",
+	"true",
+	"false",
+	"implements",
+	"interface",
+	"let",
+	"package",
+	"private",
+	"protected",
+	"public",
+	"static",
+	"yield",
+
+	/*
+	 *  These strings are manually added, and would be gathered in some
+	 *  application specific manner.
+	 */
+
+	"foo",
+	"bar",
+	"quux",
+	"enableFrob",
+	"disableFrob"
+	/* ... */
+};
+
+const void *ajsheap_extstr_check_2(const void *ptr, duk_size_t len) {
+	int i, n;
+
+	(void) safe_print_chars;  /* potentially unused */
+
+	/* Linear scan.  An actual implementation would need some acceleration
+	 * structure, e.g. select a sublist based on first character.
+	 *
+	 * NOTE: input string (behind 'ptr' with 'len' bytes) DOES NOT have a
+	 * trailing NUL character.  Any strings returned from this function
+	 * MUST have a trailing NUL character.
+	 */
+
+	n = (int) (sizeof(strdata_duk_builtin_strings) / sizeof(const char *));
+	for (i = 0; i < n; i++) {
+		const char *str;
+
+		str = strdata_duk_builtin_strings[i];
+		if (strlen(str) == len && memcmp(ptr, (const void *) str, len) == 0) {
+#if 0
+			printf("ajsheap_extstr_check_2: ptr=%p, len=%ld ",
+			       (void *) ptr, (long) len);
+			safe_print_chars((const char *) ptr, len, 0 /*until_nul*/);
+			printf(" -> constant string index %ld\n", (long) i);
+#endif
+			return (void *) ajduk__lose_const(strdata_duk_builtin_strings[i]);
+		}
+	}
+
+#if 0
+	printf("ajsheap_extstr_check_2: ptr=%p, len=%ld ",
+	       (void *) ptr, (long) len);
+	safe_print_chars((const char *) ptr, len, 0 /*until_nul*/);
+	printf(" -> not found\n");
+#endif
+	return NULL;
+}
+
+void ajsheap_extstr_free_2(const void *ptr) {
+	(void) ptr;
+#if 0
+	printf("ajsheap_extstr_free_2: freeing extstr %p -> ", ptr);
+	safe_print_chars((const char *) ptr, DUK_SIZE_MAX, 1 /*until_nul*/);
+	printf("\n");
+#endif
+}
+
+/*
+ *  External strings strategy intended for valgrind testing: external strings
+ *  are allocated using malloc()/free() so that valgrind can be used to ensure
+ *  that strings are e.g. freed exactly once.
+ */
+
+const void *ajsheap_extstr_check_3(const void *ptr, duk_size_t len) {
+	duk_uint8_t *ret;
+
+	(void) safe_print_chars;  /* potentially unused */
+
+	ret = malloc((size_t) len + 1);
+	if (ret == NULL) {
+#if 0
+		printf("ajsheap_extstr_check_3: ptr=%p, len=%ld ",
+		       (void *) ptr, (long) len);
+		safe_print_chars((const char *) ptr, len, 0 /*until_nul*/);
+		printf(" -> malloc failed, return NULL\n");
+#endif
+		return (const void *) NULL;
+	}
+
+	if (len > 0) {
+		memcpy((void *) ret, ptr, (size_t) len);
+	}
+	ret[len] = (duk_uint8_t) 0;
+
+#if 0
+	printf("ajsheap_extstr_check_3: ptr=%p, len=%ld ",
+	       (void *) ptr, (long) len);
+	safe_print_chars((const char *) ptr, len, 0 /*until_nul*/);
+	printf(" -> %p\n", (void *) ret);
+#endif
+	return (const void *) ret;
+}
+
+void ajsheap_extstr_free_3(const void *ptr) {
+	(void) ptr;
+#if 0
+	printf("ajsheap_extstr_free_3: freeing extstr %p -> ", ptr);
+	safe_print_chars((const char *) ptr, DUK_SIZE_MAX, 1 /*until_nul*/);
+	printf("\n");
+#endif
+	free((void *) ajduk__lose_const(ptr));
+}
+
+/*
+ *  Execution timeout example
+ */
+
+#define  AJSHEAP_EXEC_TIMEOUT  5  /* seconds */
+
+static time_t curr_pcall_start = 0;
+static long exec_timeout_check_counter = 0;
+
+void ajsheap_start_exec_timeout(void) {
+	curr_pcall_start = time(NULL);
+}
+
+void ajsheap_clear_exec_timeout(void) {
+	curr_pcall_start = 0;
+}
+
+duk_bool_t ajsheap_exec_timeout_check(void *udata) {
+	time_t now = time(NULL);
+	time_t diff = now - curr_pcall_start;
+
+	(void) udata;  /* not needed */
+
+	exec_timeout_check_counter++;
+#if 0
+	printf("exec timeout check %ld: now=%ld, start=%ld, diff=%ld\n",
+	       (long) exec_timeout_check_counter, (long) now, (long) curr_pcall_start, (long) diff);
+	fflush(stdout);
+#endif
+
+	if (curr_pcall_start == 0) {
+		/* protected call not yet running */
+		return 0;
+	}
+	if (diff > AJSHEAP_EXEC_TIMEOUT) {
+		return 1;
+	}
+	return 0;
+}
+
+#else  /* DUK_CMDLINE_AJSHEAP */
+
+int ajs_dummy = 0;  /* to avoid empty source file */
+
+#endif  /* DUK_CMDLINE_AJSHEAP */

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/codepage-conv/README.rst
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/codepage-conv/README.rst b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/codepage-conv/README.rst
new file mode 100644
index 0000000..98b53d2
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/codepage-conv/README.rst
@@ -0,0 +1,8 @@
+Codepage conversion example
+===========================
+
+Example of how to convert an 8-bit input string (e.g. ISO-8859-1 or Windows
+codepage 1252) into CESU-8 without using an external library like iconv.
+
+This is useful e.g. when compiling non-UTF-8 source code which cannot be
+converted to UTF-8 (CESU-8) at build time.

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/codepage-conv/duk_codepage_conv.c
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/codepage-conv/duk_codepage_conv.c b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/codepage-conv/duk_codepage_conv.c
new file mode 100644
index 0000000..932e9a6
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/codepage-conv/duk_codepage_conv.c
@@ -0,0 +1,54 @@
+/*
+ *  Convert an 8-bit input string (e.g. ISO-8859-1) into CESU-8.
+ *  Calling code supplies the "code page" as a 256-entry array of
+ *  codepoints for the conversion.
+ *
+ *  This is useful when input data is in non-UTF-8 format and must
+ *  be converted at runtime, e.g. when compiling non-UTF-8 source
+ *  code.  Another alternative is to use e.g. iconv.
+ */
+
+#include "duktape.h"
+
+/* Decode an 8-bit string using 'codepage' into Unicode codepoints and
+ * re-encode into CESU-8.  Codepage argument must point to a 256-entry
+ * table.  Only supports BMP (codepoints U+0000 to U+FFFF).
+ */
+void duk_decode_string_codepage(duk_context *ctx, const char *str, size_t len, unsigned int *codepage) {
+	unsigned char *tmp;
+	size_t tmplen, i;
+	unsigned char *p;
+	unsigned int cp;
+
+	tmplen = 3 * len;  /* max expansion is 1 input byte -> 3 output bytes */
+	if (tmplen / 3 != len) {
+		/* Temporary buffer length wraps. */
+		duk_error(ctx, DUK_ERR_RANGE_ERROR, "input string too long");
+		return;
+	}
+
+	tmp = (unsigned char *) duk_push_fixed_buffer(ctx, tmplen);
+
+	for (i = 0, p = tmp; i < len; i++) {
+		cp = codepage[((unsigned char *) str)[i]] & 0xffffUL;
+		if (cp < 0x80UL) {
+			*p++ = (unsigned char) cp;
+		} else if (cp < 0x800UL) {
+			*p++ = (unsigned char) (0xc0 + ((cp >> 6) & 0x1f));
+			*p++ = (unsigned char) (0x80 + (cp & 0x3f));
+		} else {
+			/* In CESU-8 all codepoints in [0x0000,0xFFFF] are
+			 * allowed, including surrogates.
+			 */
+			*p++ = (unsigned char) (0xe0 + ((cp >> 12) & 0x0f));
+			*p++ = (unsigned char) (0x80 + ((cp >> 6) & 0x3f));
+			*p++ = (unsigned char) (0x80 + (cp & 0x3f));
+		}
+	}
+
+	duk_push_lstring(ctx, (const char *) tmp, (duk_size_t) (p - tmp));
+
+	/* [ ... tmp res ] */
+
+	duk_remove(ctx, -2);
+}

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/codepage-conv/duk_codepage_conv.h
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/codepage-conv/duk_codepage_conv.h b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/codepage-conv/duk_codepage_conv.h
new file mode 100644
index 0000000..d2705a0
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/codepage-conv/duk_codepage_conv.h
@@ -0,0 +1,8 @@
+#ifndef DUK_CODEPAGE_CONV_H_INCLUDED
+#define DUK_CODEPAGE_CONV_H_INCLUDED
+
+#include "duktape.h"
+
+void duk_decode_string_codepage(duk_context *ctx, const char *str, size_t len, unsigned int *codepage);
+
+#endif  /* DUK_CODEPAGE_CONV_H_INCLUDED */

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/codepage-conv/test.c
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/codepage-conv/test.c b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/codepage-conv/test.c
new file mode 100644
index 0000000..c34299a
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/codepage-conv/test.c
@@ -0,0 +1,286 @@
+#include "duktape.h"
+#include "duk_codepage_conv.h"
+
+/* http://www.unicode.org/Public/MAPPINGS/VENDORS/MICSFT/WINDOWS/CP1252.TXT */
+unsigned int cp1252[256] = {
+	(unsigned int) 0x0000,
+	(unsigned int) 0x0001,
+	(unsigned int) 0x0002,
+	(unsigned int) 0x0003,
+	(unsigned int) 0x0004,
+	(unsigned int) 0x0005,
+	(unsigned int) 0x0006,
+	(unsigned int) 0x0007,
+	(unsigned int) 0x0008,
+	(unsigned int) 0x0009,
+	(unsigned int) 0x000A,
+	(unsigned int) 0x000B,
+	(unsigned int) 0x000C,
+	(unsigned int) 0x000D,
+	(unsigned int) 0x000E,
+	(unsigned int) 0x000F,
+	(unsigned int) 0x0010,
+	(unsigned int) 0x0011,
+	(unsigned int) 0x0012,
+	(unsigned int) 0x0013,
+	(unsigned int) 0x0014,
+	(unsigned int) 0x0015,
+	(unsigned int) 0x0016,
+	(unsigned int) 0x0017,
+	(unsigned int) 0x0018,
+	(unsigned int) 0x0019,
+	(unsigned int) 0x001A,
+	(unsigned int) 0x001B,
+	(unsigned int) 0x001C,
+	(unsigned int) 0x001D,
+	(unsigned int) 0x001E,
+	(unsigned int) 0x001F,
+	(unsigned int) 0x0020,
+	(unsigned int) 0x0021,
+	(unsigned int) 0x0022,
+	(unsigned int) 0x0023,
+	(unsigned int) 0x0024,
+	(unsigned int) 0x0025,
+	(unsigned int) 0x0026,
+	(unsigned int) 0x0027,
+	(unsigned int) 0x0028,
+	(unsigned int) 0x0029,
+	(unsigned int) 0x002A,
+	(unsigned int) 0x002B,
+	(unsigned int) 0x002C,
+	(unsigned int) 0x002D,
+	(unsigned int) 0x002E,
+	(unsigned int) 0x002F,
+	(unsigned int) 0x0030,
+	(unsigned int) 0x0031,
+	(unsigned int) 0x0032,
+	(unsigned int) 0x0033,
+	(unsigned int) 0x0034,
+	(unsigned int) 0x0035,
+	(unsigned int) 0x0036,
+	(unsigned int) 0x0037,
+	(unsigned int) 0x0038,
+	(unsigned int) 0x0039,
+	(unsigned int) 0x003A,
+	(unsigned int) 0x003B,
+	(unsigned int) 0x003C,
+	(unsigned int) 0x003D,
+	(unsigned int) 0x003E,
+	(unsigned int) 0x003F,
+	(unsigned int) 0x0040,
+	(unsigned int) 0x0041,
+	(unsigned int) 0x0042,
+	(unsigned int) 0x0043,
+	(unsigned int) 0x0044,
+	(unsigned int) 0x0045,
+	(unsigned int) 0x0046,
+	(unsigned int) 0x0047,
+	(unsigned int) 0x0048,
+	(unsigned int) 0x0049,
+	(unsigned int) 0x004A,
+	(unsigned int) 0x004B,
+	(unsigned int) 0x004C,
+	(unsigned int) 0x004D,
+	(unsigned int) 0x004E,
+	(unsigned int) 0x004F,
+	(unsigned int) 0x0050,
+	(unsigned int) 0x0051,
+	(unsigned int) 0x0052,
+	(unsigned int) 0x0053,
+	(unsigned int) 0x0054,
+	(unsigned int) 0x0055,
+	(unsigned int) 0x0056,
+	(unsigned int) 0x0057,
+	(unsigned int) 0x0058,
+	(unsigned int) 0x0059,
+	(unsigned int) 0x005A,
+	(unsigned int) 0x005B,
+	(unsigned int) 0x005C,
+	(unsigned int) 0x005D,
+	(unsigned int) 0x005E,
+	(unsigned int) 0x005F,
+	(unsigned int) 0x0060,
+	(unsigned int) 0x0061,
+	(unsigned int) 0x0062,
+	(unsigned int) 0x0063,
+	(unsigned int) 0x0064,
+	(unsigned int) 0x0065,
+	(unsigned int) 0x0066,
+	(unsigned int) 0x0067,
+	(unsigned int) 0x0068,
+	(unsigned int) 0x0069,
+	(unsigned int) 0x006A,
+	(unsigned int) 0x006B,
+	(unsigned int) 0x006C,
+	(unsigned int) 0x006D,
+	(unsigned int) 0x006E,
+	(unsigned int) 0x006F,
+	(unsigned int) 0x0070,
+	(unsigned int) 0x0071,
+	(unsigned int) 0x0072,
+	(unsigned int) 0x0073,
+	(unsigned int) 0x0074,
+	(unsigned int) 0x0075,
+	(unsigned int) 0x0076,
+	(unsigned int) 0x0077,
+	(unsigned int) 0x0078,
+	(unsigned int) 0x0079,
+	(unsigned int) 0x007A,
+	(unsigned int) 0x007B,
+	(unsigned int) 0x007C,
+	(unsigned int) 0x007D,
+	(unsigned int) 0x007E,
+	(unsigned int) 0x007F,
+	(unsigned int) 0x20AC,
+	(unsigned int) 0xFFFD,  /* undefined */
+	(unsigned int) 0x201A,
+	(unsigned int) 0x0192,
+	(unsigned int) 0x201E,
+	(unsigned int) 0x2026,
+	(unsigned int) 0x2020,
+	(unsigned int) 0x2021,
+	(unsigned int) 0x02C6,
+	(unsigned int) 0x2030,
+	(unsigned int) 0x0160,
+	(unsigned int) 0x2039,
+	(unsigned int) 0x0152,
+	(unsigned int) 0xFFFD,  /* undefined */
+	(unsigned int) 0x017D,
+	(unsigned int) 0xFFFD,  /* undefined */
+	(unsigned int) 0xFFFD,  /* undefined */
+	(unsigned int) 0x2018,
+	(unsigned int) 0x2019,
+	(unsigned int) 0x201C,
+	(unsigned int) 0x201D,
+	(unsigned int) 0x2022,
+	(unsigned int) 0x2013,
+	(unsigned int) 0x2014,
+	(unsigned int) 0x02DC,
+	(unsigned int) 0x2122,
+	(unsigned int) 0x0161,
+	(unsigned int) 0x203A,
+	(unsigned int) 0x0153,
+	(unsigned int) 0xFFFD,  /* undefined */
+	(unsigned int) 0x017E,
+	(unsigned int) 0x0178,
+	(unsigned int) 0x00A0,
+	(unsigned int) 0x00A1,
+	(unsigned int) 0x00A2,
+	(unsigned int) 0x00A3,
+	(unsigned int) 0x00A4,
+	(unsigned int) 0x00A5,
+	(unsigned int) 0x00A6,
+	(unsigned int) 0x00A7,
+	(unsigned int) 0x00A8,
+	(unsigned int) 0x00A9,
+	(unsigned int) 0x00AA,
+	(unsigned int) 0x00AB,
+	(unsigned int) 0x00AC,
+	(unsigned int) 0x00AD,
+	(unsigned int) 0x00AE,
+	(unsigned int) 0x00AF,
+	(unsigned int) 0x00B0,
+	(unsigned int) 0x00B1,
+	(unsigned int) 0x00B2,
+	(unsigned int) 0x00B3,
+	(unsigned int) 0x00B4,
+	(unsigned int) 0x00B5,
+	(unsigned int) 0x00B6,
+	(unsigned int) 0x00B7,
+	(unsigned int) 0x00B8,
+	(unsigned int) 0x00B9,
+	(unsigned int) 0x00BA,
+	(unsigned int) 0x00BB,
+	(unsigned int) 0x00BC,
+	(unsigned int) 0x00BD,
+	(unsigned int) 0x00BE,
+	(unsigned int) 0x00BF,
+	(unsigned int) 0x00C0,
+	(unsigned int) 0x00C1,
+	(unsigned int) 0x00C2,
+	(unsigned int) 0x00C3,
+	(unsigned int) 0x00C4,
+	(unsigned int) 0x00C5,
+	(unsigned int) 0x00C6,
+	(unsigned int) 0x00C7,
+	(unsigned int) 0x00C8,
+	(unsigned int) 0x00C9,
+	(unsigned int) 0x00CA,
+	(unsigned int) 0x00CB,
+	(unsigned int) 0x00CC,
+	(unsigned int) 0x00CD,
+	(unsigned int) 0x00CE,
+	(unsigned int) 0x00CF,
+	(unsigned int) 0x00D0,
+	(unsigned int) 0x00D1,
+	(unsigned int) 0x00D2,
+	(unsigned int) 0x00D3,
+	(unsigned int) 0x00D4,
+	(unsigned int) 0x00D5,
+	(unsigned int) 0x00D6,
+	(unsigned int) 0x00D7,
+	(unsigned int) 0x00D8,
+	(unsigned int) 0x00D9,
+	(unsigned int) 0x00DA,
+	(unsigned int) 0x00DB,
+	(unsigned int) 0x00DC,
+	(unsigned int) 0x00DD,
+	(unsigned int) 0x00DE,
+	(unsigned int) 0x00DF,
+	(unsigned int) 0x00E0,
+	(unsigned int) 0x00E1,
+	(unsigned int) 0x00E2,
+	(unsigned int) 0x00E3,
+	(unsigned int) 0x00E4,
+	(unsigned int) 0x00E5,
+	(unsigned int) 0x00E6,
+	(unsigned int) 0x00E7,
+	(unsigned int) 0x00E8,
+	(unsigned int) 0x00E9,
+	(unsigned int) 0x00EA,
+	(unsigned int) 0x00EB,
+	(unsigned int) 0x00EC,
+	(unsigned int) 0x00ED,
+	(unsigned int) 0x00EE,
+	(unsigned int) 0x00EF,
+	(unsigned int) 0x00F0,
+	(unsigned int) 0x00F1,
+	(unsigned int) 0x00F2,
+	(unsigned int) 0x00F3,
+	(unsigned int) 0x00F4,
+	(unsigned int) 0x00F5,
+	(unsigned int) 0x00F6,
+	(unsigned int) 0x00F7,
+	(unsigned int) 0x00F8,
+	(unsigned int) 0x00F9,
+	(unsigned int) 0x00FA,
+	(unsigned int) 0x00FB,
+	(unsigned int) 0x00FC,
+	(unsigned int) 0x00FD,
+	(unsigned int) 0x00FE,
+	(unsigned int) 0x00FF
+};
+
+/* Exercise all 3 byte lengths: any ASCII character is 1 byte, 0xFC maps to
+ * U+00FC which is 2 bytes, and 0x80 maps to U+20AC which is 3 bytes.
+ */
+static const char *example_source = "print('Hello w\xfcrld - \x80');";
+
+/* Example: compile and run test source encoded in Windows codepage 1252. */
+int main(int argc, char *argv[]) {
+	duk_context *ctx;
+
+	(void) argc; (void) argv;
+
+	ctx = duk_create_heap_default();
+	if (!ctx) {
+		printf("Failed to create Duktape heap.\n");
+		return 1;
+	}
+
+	duk_decode_string_codepage(ctx, example_source, strlen(example_source), cp1252);
+	duk_eval_noresult(ctx);
+
+	duk_destroy_heap(ctx);
+	return 0;
+}

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/coffee/README.rst
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/coffee/README.rst b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/coffee/README.rst
new file mode 100644
index 0000000..f147522
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/coffee/README.rst
@@ -0,0 +1,10 @@
+=====================
+Coffeescript examples
+=====================
+
+A few tests to see how CoffeeScript works with Duktape.  Just convert the
+Coffeescript files to Javascript with the ``Makefile.coffee`` in the
+distributable, or manually::
+
+  $ coffee -c hello.coffee
+  $ cat hello.js

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/coffee/globals.coffee
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/coffee/globals.coffee b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/coffee/globals.coffee
new file mode 100644
index 0000000..25773cd
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/coffee/globals.coffee
@@ -0,0 +1,7 @@
+
+print '*** All globals'
+print(name) for name in Object.getOwnPropertyNames(this)
+
+print '*** Globals with a short name (<= 8 chars)'
+print(name) for name in Object.getOwnPropertyNames(this) when name.length <= 8
+

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/coffee/hello.coffee
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/coffee/hello.coffee b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/coffee/hello.coffee
new file mode 100644
index 0000000..088ed8d
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/coffee/hello.coffee
@@ -0,0 +1,2 @@
+print 'Hello world!'
+print 'version: ' + Duktape.version

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/coffee/mandel.coffee
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/coffee/mandel.coffee b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/coffee/mandel.coffee
new file mode 100644
index 0000000..8e3e170
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/coffee/mandel.coffee
@@ -0,0 +1,28 @@
+mandel = (x0, y0, x1, y1, w, h, maxiter) ->
+  [dx, dy] = [(x1 - x0) / w, (y1 - y0) / h]
+  res = []
+
+  y = y0
+  for yc in [0..h-1]
+    x = x0
+    for xc in [0..w-1]
+      [xx, yy] = [x, y]
+      c = '*'
+      for i in [0..maxiter-1]
+        # (xx+i*yy)^2 + (x+i*y) = xx^2 + i*2*xx*yy - yy^2 + x + i*y
+        # = (xx^2 - yy^2 + x) + i*(2*xx*yy + y)
+        [xx2, yy2] = [xx*xx, yy*yy]
+        if xx2 + yy2 >= 4.0
+          c = '.'
+          break
+        [xx, yy] = [xx2 - yy2 + x, 2*xx*yy + y]
+      res.push(c)
+      x += dx
+    res.push('\n')
+    y += dy
+
+  print(res.join(''))
+  return
+
+mandel(-2, 2, 2, -2, 200, 100, 1000)
+


[02/51] [partial] nifi-minifi-cpp git commit: MINIFI-183 Added civet 1.9.1 sources Added onScheduled hook Added initial two-way TLS-enabled ListenHTTP implementation

Posted by al...@apache.org.
http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_hbuffer_alloc.c
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_hbuffer_alloc.c b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_hbuffer_alloc.c
new file mode 100644
index 0000000..425ad33
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_hbuffer_alloc.c
@@ -0,0 +1,132 @@
+/*
+ *  duk_hbuffer allocation and freeing.
+ */
+
+#include "duk_internal.h"
+
+/* Allocate a new duk_hbuffer of a certain type and return a pointer to it
+ * (NULL on error).  Write buffer data pointer to 'out_bufdata' (only if
+ * allocation successful).
+ */
+DUK_INTERNAL duk_hbuffer *duk_hbuffer_alloc(duk_heap *heap, duk_size_t size, duk_small_uint_t flags, void **out_bufdata) {
+	duk_hbuffer *res = NULL;
+	duk_size_t header_size;
+	duk_size_t alloc_size;
+
+	DUK_ASSERT(heap != NULL);
+	DUK_ASSERT(out_bufdata != NULL);
+
+	DUK_DDD(DUK_DDDPRINT("allocate hbuffer"));
+
+	/* Size sanity check.  Should not be necessary because caller is
+	 * required to check this, but we don't want to cause a segfault
+	 * if the size wraps either in duk_size_t computation or when
+	 * storing the size in a 16-bit field.
+	 */
+	if (size > DUK_HBUFFER_MAX_BYTELEN) {
+		DUK_D(DUK_DPRINT("hbuffer alloc failed: size too large: %ld", (long) size));
+		return NULL;  /* no need to write 'out_bufdata' */
+	}
+
+	if (flags & DUK_BUF_FLAG_EXTERNAL) {
+		header_size = sizeof(duk_hbuffer_external);
+		alloc_size = sizeof(duk_hbuffer_external);
+	} else if (flags & DUK_BUF_FLAG_DYNAMIC) {
+		header_size = sizeof(duk_hbuffer_dynamic);
+		alloc_size = sizeof(duk_hbuffer_dynamic);
+	} else {
+		header_size = sizeof(duk_hbuffer_fixed);
+		alloc_size = sizeof(duk_hbuffer_fixed) + size;
+		DUK_ASSERT(alloc_size >= sizeof(duk_hbuffer_fixed));  /* no wrapping */
+	}
+
+	res = (duk_hbuffer *) DUK_ALLOC(heap, alloc_size);
+	if (!res) {
+		goto error;
+	}
+
+	/* zero everything unless requested not to do so */
+#if defined(DUK_USE_ZERO_BUFFER_DATA)
+	DUK_MEMZERO((void *) res,
+	            (flags & DUK_BUF_FLAG_NOZERO) ? header_size : alloc_size);
+#else
+	DUK_MEMZERO((void *) res, header_size);
+#endif
+
+	if (flags & DUK_BUF_FLAG_EXTERNAL) {
+		duk_hbuffer_external *h;
+		h = (duk_hbuffer_external *) res;
+		DUK_UNREF(h);
+		*out_bufdata = NULL;
+#if defined(DUK_USE_EXPLICIT_NULL_INIT)
+#if defined(DUK_USE_HEAPPTR16)
+/* the compressed pointer is zeroed which maps to NULL, so nothing to do. */
+#else
+		DUK_HBUFFER_EXTERNAL_SET_DATA_PTR(heap, h, NULL);
+#endif
+#endif
+		DUK_ASSERT(DUK_HBUFFER_EXTERNAL_GET_DATA_PTR(heap, h) == NULL);
+	} else if (flags & DUK_BUF_FLAG_DYNAMIC) {
+		duk_hbuffer_dynamic *h = (duk_hbuffer_dynamic *) res;
+		void *ptr;
+
+		if (size > 0) {
+			DUK_ASSERT(!(flags & DUK_BUF_FLAG_EXTERNAL));  /* alloc external with size zero */
+			DUK_DDD(DUK_DDDPRINT("dynamic buffer with nonzero size, alloc actual buffer"));
+#ifdef DUK_USE_ZERO_BUFFER_DATA
+			ptr = DUK_ALLOC_ZEROED(heap, size);
+#else
+			ptr = DUK_ALLOC(heap, size);
+#endif
+			if (!ptr) {
+				/* Because size > 0, NULL check is correct */
+				goto error;
+			}
+			*out_bufdata = ptr;
+
+			DUK_HBUFFER_DYNAMIC_SET_DATA_PTR(heap, h, ptr);
+		} else {
+			*out_bufdata = NULL;
+#if defined(DUK_USE_EXPLICIT_NULL_INIT)
+#if defined(DUK_USE_HEAPPTR16)
+/* the compressed pointer is zeroed which maps to NULL, so nothing to do. */
+#else
+			DUK_HBUFFER_DYNAMIC_SET_DATA_PTR(heap, h, NULL);
+#endif
+#endif
+			DUK_ASSERT(DUK_HBUFFER_DYNAMIC_GET_DATA_PTR(heap, h) == NULL);
+		}
+	} else {
+		*out_bufdata = (void *) ((duk_hbuffer_fixed *) res + 1);
+	}
+
+	DUK_HBUFFER_SET_SIZE(res, size);
+
+	DUK_HEAPHDR_SET_TYPE(&res->hdr, DUK_HTYPE_BUFFER);
+	if (flags & DUK_BUF_FLAG_DYNAMIC) {
+		DUK_HBUFFER_SET_DYNAMIC(res);
+		if (flags & DUK_BUF_FLAG_EXTERNAL) {
+			DUK_HBUFFER_SET_EXTERNAL(res);
+		}
+	} else {
+		DUK_ASSERT(!(flags & DUK_BUF_FLAG_EXTERNAL));
+	}
+        DUK_HEAP_INSERT_INTO_HEAP_ALLOCATED(heap, &res->hdr);
+
+	DUK_DDD(DUK_DDDPRINT("allocated hbuffer: %p", (void *) res));
+	return res;
+
+ error:
+	DUK_DD(DUK_DDPRINT("hbuffer allocation failed"));
+
+	DUK_FREE(heap, res);
+	return NULL;  /* no need to write 'out_bufdata' */
+}
+
+/* For indirect allocs. */
+
+DUK_INTERNAL void *duk_hbuffer_get_dynalloc_ptr(duk_heap *heap, void *ud) {
+	duk_hbuffer_dynamic *buf = (duk_hbuffer_dynamic *) ud;
+	DUK_UNREF(heap);
+	return (void *) DUK_HBUFFER_DYNAMIC_GET_DATA_PTR(heap, buf);
+}

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_hbuffer_ops.c
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_hbuffer_ops.c b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_hbuffer_ops.c
new file mode 100644
index 0000000..4cdf598
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_hbuffer_ops.c
@@ -0,0 +1,82 @@
+/*
+ *  duk_hbuffer operations such as resizing and inserting/appending data to
+ *  a dynamic buffer.
+ *
+ *  Append operations append to the end of the buffer and they are relatively
+ *  efficient: the buffer is grown with a "spare" part relative to the buffer
+ *  size to minimize reallocations.  Insert operations need to move existing
+ *  data forward in the buffer with memmove() and are not very efficient.
+ *  They are used e.g. by the regexp compiler to "backpatch" regexp bytecode.
+ */
+
+#include "duk_internal.h"
+
+/*
+ *  Resizing
+ */
+
+DUK_INTERNAL void duk_hbuffer_resize(duk_hthread *thr, duk_hbuffer_dynamic *buf, duk_size_t new_size) {
+	void *res;
+	duk_size_t prev_size;
+
+	DUK_ASSERT(thr != NULL);
+	DUK_ASSERT(buf != NULL);
+	DUK_ASSERT(DUK_HBUFFER_HAS_DYNAMIC(buf));
+	DUK_ASSERT(!DUK_HBUFFER_HAS_EXTERNAL(buf));
+
+	/*
+	 *  Maximum size check
+	 */
+
+	if (new_size > DUK_HBUFFER_MAX_BYTELEN) {
+		DUK_ERROR_RANGE(thr, "buffer too long");
+	}
+
+	/*
+	 *  Note: use indirect realloc variant just in case mark-and-sweep
+	 *  (finalizers) might resize this same buffer during garbage
+	 *  collection.
+	 */
+
+	res = DUK_REALLOC_INDIRECT(thr->heap, duk_hbuffer_get_dynalloc_ptr, (void *) buf, new_size);
+	if (res != NULL || new_size == 0) {
+		/* 'res' may be NULL if new allocation size is 0. */
+
+		DUK_DDD(DUK_DDDPRINT("resized dynamic buffer %p:%ld -> %p:%ld",
+		                     (void *) DUK_HBUFFER_DYNAMIC_GET_DATA_PTR(thr->heap, buf),
+		                     (long) DUK_HBUFFER_DYNAMIC_GET_SIZE(buf),
+		                     (void *) res,
+		                     (long) new_size));
+
+		/*
+		 *  The entire allocated buffer area, regardless of actual used
+		 *  size, is kept zeroed in resizes for simplicity.  If the buffer
+		 *  is grown, zero the new part.
+		 */
+
+		prev_size = DUK_HBUFFER_DYNAMIC_GET_SIZE(buf);
+		if (new_size > prev_size) {
+			DUK_ASSERT(new_size - prev_size > 0);
+#ifdef DUK_USE_ZERO_BUFFER_DATA
+			DUK_MEMZERO((void *) ((char *) res + prev_size),
+			            (duk_size_t) (new_size - prev_size));
+#endif
+		}
+
+		DUK_HBUFFER_DYNAMIC_SET_SIZE(buf, new_size);
+		DUK_HBUFFER_DYNAMIC_SET_DATA_PTR(thr->heap, buf, res);
+	} else {
+		DUK_ERROR_ALLOC_DEFMSG(thr);
+	}
+
+	DUK_ASSERT(res != NULL || new_size == 0);
+}
+
+DUK_INTERNAL void duk_hbuffer_reset(duk_hthread *thr, duk_hbuffer_dynamic *buf) {
+	DUK_ASSERT(thr != NULL);
+	DUK_ASSERT(buf != NULL);
+	DUK_ASSERT(DUK_HBUFFER_HAS_DYNAMIC(buf));
+	DUK_ASSERT(!DUK_HBUFFER_HAS_EXTERNAL(buf));
+
+	duk_hbuffer_resize(thr, buf, 0);
+}

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_hbufferobject.h
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_hbufferobject.h b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_hbufferobject.h
new file mode 100644
index 0000000..dd93902
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_hbufferobject.h
@@ -0,0 +1,133 @@
+/*
+ *  Heap Buffer object representation.  Used for all Buffer variants.
+ */
+
+#ifndef DUK_HBUFFEROBJECT_H_INCLUDED
+#define DUK_HBUFFEROBJECT_H_INCLUDED
+
+/* All element accessors are host endian now (driven by TypedArray spec). */
+#define DUK_HBUFFEROBJECT_ELEM_UINT8           0
+#define DUK_HBUFFEROBJECT_ELEM_UINT8CLAMPED    1
+#define DUK_HBUFFEROBJECT_ELEM_INT8            2
+#define DUK_HBUFFEROBJECT_ELEM_UINT16          3
+#define DUK_HBUFFEROBJECT_ELEM_INT16           4
+#define DUK_HBUFFEROBJECT_ELEM_UINT32          5
+#define DUK_HBUFFEROBJECT_ELEM_INT32           6
+#define DUK_HBUFFEROBJECT_ELEM_FLOAT32         7
+#define DUK_HBUFFEROBJECT_ELEM_FLOAT64         8
+#define DUK_HBUFFEROBJECT_ELEM_MAX             8
+
+#define DUK_ASSERT_HBUFFEROBJECT_VALID(h) do { \
+		DUK_ASSERT((h) != NULL); \
+		DUK_ASSERT((h)->shift <= 3); \
+		DUK_ASSERT((h)->elem_type <= DUK_HBUFFEROBJECT_ELEM_MAX); \
+		DUK_ASSERT(((h)->shift == 0 && (h)->elem_type == DUK_HBUFFEROBJECT_ELEM_UINT8) || \
+		           ((h)->shift == 0 && (h)->elem_type == DUK_HBUFFEROBJECT_ELEM_UINT8CLAMPED) || \
+		           ((h)->shift == 0 && (h)->elem_type == DUK_HBUFFEROBJECT_ELEM_INT8) || \
+		           ((h)->shift == 1 && (h)->elem_type == DUK_HBUFFEROBJECT_ELEM_UINT16) || \
+		           ((h)->shift == 1 && (h)->elem_type == DUK_HBUFFEROBJECT_ELEM_INT16) || \
+		           ((h)->shift == 2 && (h)->elem_type == DUK_HBUFFEROBJECT_ELEM_UINT32) || \
+		           ((h)->shift == 2 && (h)->elem_type == DUK_HBUFFEROBJECT_ELEM_INT32) || \
+		           ((h)->shift == 2 && (h)->elem_type == DUK_HBUFFEROBJECT_ELEM_FLOAT32) || \
+		           ((h)->shift == 3 && (h)->elem_type == DUK_HBUFFEROBJECT_ELEM_FLOAT64)); \
+		DUK_ASSERT((h)->is_view == 0 || (h)->is_view == 1); \
+		DUK_ASSERT(DUK_HOBJECT_IS_BUFFEROBJECT((duk_hobject *) (h))); \
+		if ((h)->buf == NULL) { \
+			DUK_ASSERT((h)->offset == 0); \
+			DUK_ASSERT((h)->length == 0); \
+		} else { \
+			/* No assertions for offset or length; in particular, \
+			 * it's OK for length to be longer than underlying \
+			 * buffer.  Just ensure they don't wrap when added. \
+			 */ \
+			DUK_ASSERT((h)->offset + (h)->length >= (h)->offset); \
+		} \
+	} while (0)
+
+/* Get the current data pointer (caller must ensure buf != NULL) as a
+ * duk_uint8_t ptr.
+ */
+#define DUK_HBUFFEROBJECT_GET_SLICE_BASE(heap,h) \
+	(DUK_ASSERT_EXPR((h) != NULL), DUK_ASSERT_EXPR((h)->buf != NULL), \
+	(((duk_uint8_t *) DUK_HBUFFER_GET_DATA_PTR((heap), (h)->buf)) + (h)->offset))
+
+/* True if slice is full, i.e. offset is zero and length covers the entire
+ * buffer.  This status may change independently of the duk_hbufferobject if
+ * the underlying buffer is dynamic and changes without the hbufferobject
+ * being changed.
+ */
+#define DUK_HBUFFEROBJECT_FULL_SLICE(h) \
+	(DUK_ASSERT_EXPR((h) != NULL), DUK_ASSERT_EXPR((h)->buf != NULL), \
+	((h)->offset == 0 && (h)->length == DUK_HBUFFER_GET_SIZE((h)->buf)))
+
+/* Validate that the whole slice [0,length[ is contained in the underlying
+ * buffer.  Caller must ensure 'buf' != NULL.
+ */
+#define DUK_HBUFFEROBJECT_VALID_SLICE(h) \
+	(DUK_ASSERT_EXPR((h) != NULL), DUK_ASSERT_EXPR((h)->buf != NULL), \
+	((h)->offset + (h)->length <= DUK_HBUFFER_GET_SIZE((h)->buf)))
+
+/* Validate byte read/write for virtual 'offset', i.e. check that the
+ * offset, taking into account h->offset, is within the underlying
+ * buffer size.  This is a safety check which is needed to ensure
+ * that even a misconfigured duk_hbufferobject never causes memory
+ * unsafe behavior (e.g. if an underlying dynamic buffer changes
+ * after being setup).  Caller must ensure 'buf' != NULL.
+ */
+#define DUK_HBUFFEROBJECT_VALID_BYTEOFFSET_INCL(h,off) \
+	(DUK_ASSERT_EXPR((h) != NULL), DUK_ASSERT_EXPR((h)->buf != NULL), \
+	((h)->offset + (off) < DUK_HBUFFER_GET_SIZE((h)->buf)))
+
+#define DUK_HBUFFEROBJECT_VALID_BYTEOFFSET_EXCL(h,off) \
+	(DUK_ASSERT_EXPR((h) != NULL), DUK_ASSERT_EXPR((h)->buf != NULL), \
+	((h)->offset + (off) <= DUK_HBUFFER_GET_SIZE((h)->buf)))
+
+/* Clamp an input byte length (already assumed to be within the nominal
+ * duk_hbufferobject 'length') to the current dynamic buffer limits to
+ * yield a byte length limit that's safe for memory accesses.  This value
+ * can be invalidated by any side effect because it may trigger a user
+ * callback that resizes the underlying buffer.
+ */
+#define DUK_HBUFFEROBJECT_CLAMP_BYTELENGTH(h,len) \
+	(DUK_ASSERT_EXPR((h) != NULL), \
+	duk_hbufferobject_clamp_bytelength((h), (len)))
+
+struct duk_hbufferobject {
+	/* Shared object part. */
+	duk_hobject obj;
+
+	/* Underlying buffer (refcounted), may be NULL. */
+	duk_hbuffer *buf;
+
+	/* Slice and accessor information.
+	 *
+	 * Because the underlying buffer may be dynamic, these may be
+	 * invalidated by the buffer being modified so that both offset
+	 * and length should be validated before every access.  Behavior
+	 * when the underlying buffer has changed doesn't need to be clean:
+	 * virtual 'length' doesn't need to be affected, reads can return
+	 * zero/NaN, and writes can be ignored.
+	 *
+	 * Note that a data pointer cannot be precomputed because 'buf' may
+	 * be dynamic and its pointer unstable.
+	 */
+
+	duk_uint_t offset;       /* byte offset to buf */
+	duk_uint_t length;       /* byte index limit for element access, exclusive */
+	duk_uint8_t shift;       /* element size shift:
+	                          *   0 = u8/i8
+	                          *   1 = u16/i16
+	                          *   2 = u32/i32/float
+	                          *   3 = double
+	                          */
+	duk_uint8_t elem_type;   /* element type */
+	duk_uint8_t is_view;
+};
+
+#if defined(DUK_USE_BUFFEROBJECT_SUPPORT)
+DUK_INTERNAL_DECL duk_uint_t duk_hbufferobject_clamp_bytelength(duk_hbufferobject *h_bufobj, duk_uint_t len);
+#endif
+DUK_INTERNAL_DECL void duk_hbufferobject_push_validated_read(duk_context *ctx, duk_hbufferobject *h_bufobj, duk_uint8_t *p, duk_small_uint_t elem_size);
+DUK_INTERNAL_DECL void duk_hbufferobject_validated_write(duk_context *ctx, duk_hbufferobject *h_bufobj, duk_uint8_t *p, duk_small_uint_t elem_size);
+
+#endif  /* DUK_HBUFFEROBJECT_H_INCLUDED */

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_hbufferobject_misc.c
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_hbufferobject_misc.c b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_hbufferobject_misc.c
new file mode 100644
index 0000000..f692918
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_hbufferobject_misc.c
@@ -0,0 +1,20 @@
+#include "duk_internal.h"
+
+#if defined(DUK_USE_BUFFEROBJECT_SUPPORT)
+DUK_INTERNAL duk_uint_t duk_hbufferobject_clamp_bytelength(duk_hbufferobject *h_bufobj, duk_uint_t len) {
+	duk_uint_t buf_size;
+	duk_uint_t buf_avail;
+
+	DUK_ASSERT(h_bufobj != NULL);
+	DUK_ASSERT(h_bufobj->buf != NULL);
+
+	buf_size = (duk_uint_t) DUK_HBUFFER_GET_SIZE(h_bufobj->buf);
+	if (h_bufobj->offset > buf_size) {
+		/* Slice starting point is beyond current length. */
+		return 0;
+	}
+	buf_avail = buf_size - h_bufobj->offset;
+
+	return buf_avail >= len ? len : buf_avail;
+}
+#endif  /* DUK_USE_BUFFEROBJECT_SUPPORT */

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_hcompiledfunction.h
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_hcompiledfunction.h b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_hcompiledfunction.h
new file mode 100644
index 0000000..04b9ea1
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_hcompiledfunction.h
@@ -0,0 +1,239 @@
+/*
+ *  Heap compiled function (Ecmascript function) representation.
+ *
+ *  There is a single data buffer containing the Ecmascript function's
+ *  bytecode, constants, and inner functions.
+ */
+
+#ifndef DUK_HCOMPILEDFUNCTION_H_INCLUDED
+#define DUK_HCOMPILEDFUNCTION_H_INCLUDED
+
+/*
+ *  Field accessor macros
+ */
+
+/* XXX: casts could be improved, especially for GET/SET DATA */
+
+#if defined(DUK_USE_HEAPPTR16)
+#define DUK_HCOMPILEDFUNCTION_GET_DATA(heap,h) \
+	((duk_hbuffer_fixed *) (void *) DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, (h)->data16))
+#define DUK_HCOMPILEDFUNCTION_SET_DATA(heap,h,v) do { \
+		(h)->data16 = DUK_USE_HEAPPTR_ENC16((heap)->heap_udata, (void *) (v)); \
+	} while (0)
+#define DUK_HCOMPILEDFUNCTION_GET_FUNCS(heap,h)  \
+	((duk_hobject **) (void *) (DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, (h)->funcs16)))
+#define DUK_HCOMPILEDFUNCTION_SET_FUNCS(heap,h,v)  do { \
+		(h)->funcs16 = DUK_USE_HEAPPTR_ENC16((heap)->heap_udata, (void *) (v)); \
+	} while (0)
+#define DUK_HCOMPILEDFUNCTION_GET_BYTECODE(heap,h)  \
+	((duk_instr_t *) (void *) (DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, (h)->bytecode16)))
+#define DUK_HCOMPILEDFUNCTION_SET_BYTECODE(heap,h,v)  do { \
+		(h)->bytecode16 = DUK_USE_HEAPPTR_ENC16((heap)->heap_udata, (void *) (v)); \
+	} while (0)
+#else
+#define DUK_HCOMPILEDFUNCTION_GET_DATA(heap,h) \
+	((duk_hbuffer_fixed *) (void *) (h)->data)
+#define DUK_HCOMPILEDFUNCTION_SET_DATA(heap,h,v) do { \
+		(h)->data = (duk_hbuffer *) (v); \
+	} while (0)
+#define DUK_HCOMPILEDFUNCTION_GET_FUNCS(heap,h)  \
+	((h)->funcs)
+#define DUK_HCOMPILEDFUNCTION_SET_FUNCS(heap,h,v)  do { \
+		(h)->funcs = (v); \
+	} while (0)
+#define DUK_HCOMPILEDFUNCTION_GET_BYTECODE(heap,h)  \
+	((h)->bytecode)
+#define DUK_HCOMPILEDFUNCTION_SET_BYTECODE(heap,h,v)  do { \
+		(h)->bytecode = (v); \
+	} while (0)
+#endif
+
+/*
+ *  Accessor macros for function specific data areas
+ */
+
+/* Note: assumes 'data' is always a fixed buffer */
+#define DUK_HCOMPILEDFUNCTION_GET_BUFFER_BASE(heap,h)  \
+	DUK_HBUFFER_FIXED_GET_DATA_PTR((heap), DUK_HCOMPILEDFUNCTION_GET_DATA((heap), (h)))
+
+#define DUK_HCOMPILEDFUNCTION_GET_CONSTS_BASE(heap,h)  \
+	((duk_tval *) (void *) DUK_HCOMPILEDFUNCTION_GET_BUFFER_BASE((heap), (h)))
+
+#define DUK_HCOMPILEDFUNCTION_GET_FUNCS_BASE(heap,h)  \
+	DUK_HCOMPILEDFUNCTION_GET_FUNCS((heap), (h))
+
+#define DUK_HCOMPILEDFUNCTION_GET_CODE_BASE(heap,h)  \
+	DUK_HCOMPILEDFUNCTION_GET_BYTECODE((heap), (h))
+
+#define DUK_HCOMPILEDFUNCTION_GET_CONSTS_END(heap,h)  \
+	((duk_tval *) (void *) DUK_HCOMPILEDFUNCTION_GET_FUNCS((heap), (h)))
+
+#define DUK_HCOMPILEDFUNCTION_GET_FUNCS_END(heap,h)  \
+	((duk_hobject **) (void *) DUK_HCOMPILEDFUNCTION_GET_BYTECODE((heap), (h)))
+
+/* XXX: double evaluation of DUK_HCOMPILEDFUNCTION_GET_DATA() */
+#define DUK_HCOMPILEDFUNCTION_GET_CODE_END(heap,h)  \
+	((duk_instr_t *) (void *) (DUK_HBUFFER_FIXED_GET_DATA_PTR((heap), DUK_HCOMPILEDFUNCTION_GET_DATA((heap), (h))) + \
+	                DUK_HBUFFER_GET_SIZE((duk_hbuffer *) DUK_HCOMPILEDFUNCTION_GET_DATA((heap), h))))
+
+#define DUK_HCOMPILEDFUNCTION_GET_CONSTS_SIZE(heap,h)  \
+	( \
+	 (duk_size_t) \
+	 ( \
+	   ((const duk_uint8_t *) DUK_HCOMPILEDFUNCTION_GET_CONSTS_END((heap), (h))) - \
+	   ((const duk_uint8_t *) DUK_HCOMPILEDFUNCTION_GET_CONSTS_BASE((heap), (h))) \
+	 ) \
+	)
+
+#define DUK_HCOMPILEDFUNCTION_GET_FUNCS_SIZE(heap,h)  \
+	( \
+	 (duk_size_t) \
+	 ( \
+	   ((const duk_uint8_t *) DUK_HCOMPILEDFUNCTION_GET_FUNCS_END((heap), (h))) - \
+	   ((const duk_uint8_t *) DUK_HCOMPILEDFUNCTION_GET_FUNCS_BASE((heap), (h))) \
+	 ) \
+	)
+
+#define DUK_HCOMPILEDFUNCTION_GET_CODE_SIZE(heap,h)  \
+	( \
+	 (duk_size_t) \
+	 ( \
+	   ((const duk_uint8_t *) DUK_HCOMPILEDFUNCTION_GET_CODE_END((heap),(h))) - \
+	   ((const duk_uint8_t *) DUK_HCOMPILEDFUNCTION_GET_CODE_BASE((heap),(h))) \
+	 ) \
+	)
+
+#define DUK_HCOMPILEDFUNCTION_GET_CONSTS_COUNT(heap,h)  \
+	((duk_size_t) (DUK_HCOMPILEDFUNCTION_GET_CONSTS_SIZE((heap), (h)) / sizeof(duk_tval)))
+
+#define DUK_HCOMPILEDFUNCTION_GET_FUNCS_COUNT(heap,h)  \
+	((duk_size_t) (DUK_HCOMPILEDFUNCTION_GET_FUNCS_SIZE((heap), (h)) / sizeof(duk_hobject *)))
+
+#define DUK_HCOMPILEDFUNCTION_GET_CODE_COUNT(heap,h)  \
+	((duk_size_t) (DUK_HCOMPILEDFUNCTION_GET_CODE_SIZE((heap), (h)) / sizeof(duk_instr_t)))
+
+
+/*
+ *  Main struct
+ */
+
+struct duk_hcompiledfunction {
+	/* shared object part */
+	duk_hobject obj;
+
+	/*
+	 *  Pointers to function data area for faster access.  Function
+	 *  data is a buffer shared between all closures of the same
+	 *  "template" function.  The data buffer is always fixed (non-
+	 *  dynamic, hence stable), with a layout as follows:
+	 *
+	 *    constants (duk_tval)
+	 *    inner functions (duk_hobject *)
+	 *    bytecode (duk_instr_t)
+	 *
+	 *  Note: bytecode end address can be computed from 'data' buffer
+	 *  size.  It is not strictly necessary functionally, assuming
+	 *  bytecode never jumps outside its allocated area.  However,
+	 *  it's a safety/robustness feature for avoiding the chance of
+	 *  executing random data as bytecode due to a compiler error.
+	 *
+	 *  Note: values in the data buffer must be incref'd (they will
+	 *  be decref'd on release) for every compiledfunction referring
+	 *  to the 'data' element.
+	 */
+
+	/* Data area, fixed allocation, stable data ptrs. */
+#if defined(DUK_USE_HEAPPTR16)
+	duk_uint16_t data16;
+#else
+	duk_hbuffer *data;
+#endif
+
+	/* No need for constants pointer (= same as data).
+	 *
+	 * When using 16-bit packing alignment to 4 is nice.  'funcs' will be
+	 * 4-byte aligned because 'constants' are duk_tvals.  For now the
+	 * inner function pointers are not compressed, so that 'bytecode' will
+	 * also be 4-byte aligned.
+	 */
+#if defined(DUK_USE_HEAPPTR16)
+	duk_uint16_t funcs16;
+	duk_uint16_t bytecode16;
+#else
+	duk_hobject **funcs;
+	duk_instr_t *bytecode;
+#endif
+
+	/*
+	 *  'nregs' registers are allocated on function entry, at most 'nargs'
+	 *  are initialized to arguments, and the rest to undefined.  Arguments
+	 *  above 'nregs' are not mapped to registers.  All registers in the
+	 *  active stack range must be initialized because they are GC reachable.
+	 *  'nargs' is needed so that if the function is given more than 'nargs'
+	 *  arguments, the additional arguments do not 'clobber' registers
+	 *  beyond 'nregs' which must be consistently initialized to undefined.
+	 *
+	 *  Usually there is no need to know which registers are mapped to
+	 *  local variables.  Registers may be allocated to variable in any
+	 *  way (even including gaps).  However, a register-variable mapping
+	 *  must be the same for the duration of the function execution and
+	 *  the register cannot be used for anything else.
+	 *
+	 *  When looking up variables by name, the '_Varmap' map is used.
+	 *  When an activation closes, registers mapped to arguments are
+	 *  copied into the environment record based on the same map.  The
+	 *  reverse map (from register to variable) is not currently needed
+	 *  at run time, except for debugging, so it is not maintained.
+	 */
+
+	duk_uint16_t nregs;                /* regs to allocate */
+	duk_uint16_t nargs;                /* number of arguments allocated to regs */
+
+	/*
+	 *  Additional control information is placed into the object itself
+	 *  as internal properties to avoid unnecessary fields for the
+	 *  majority of functions.  The compiler tries to omit internal
+	 *  control fields when possible.
+	 *
+	 *  Function templates:
+	 *
+	 *    {
+	 *      name: "func",    // declaration, named function expressions
+	 *      fileName: <debug info for creating nice errors>
+	 *      _Varmap: { "arg1": 0, "arg2": 1, "varname": 2 },
+	 *      _Formals: [ "arg1", "arg2" ],
+	 *      _Source: "function func(arg1, arg2) { ... }",
+	 *      _Pc2line: <debug info for pc-to-line mapping>,
+	 *    }
+	 *
+	 *  Function instances:
+	 *
+	 *    {
+	 *      length: 2,
+	 *      prototype: { constructor: <func> },
+	 *      caller: <thrower>,
+	 *      arguments: <thrower>,
+	 *      name: "func",    // declaration, named function expressions
+	 *      fileName: <debug info for creating nice errors>
+	 *      _Varmap: { "arg1": 0, "arg2": 1, "varname": 2 },
+	 *      _Formals: [ "arg1", "arg2" ],
+	 *      _Source: "function func(arg1, arg2) { ... }",
+	 *      _Pc2line: <debug info for pc-to-line mapping>,
+	 *      _Varenv: <variable environment of closure>,
+	 *      _Lexenv: <lexical environment of closure (if differs from _Varenv)>
+	 *    }
+	 *
+	 *  More detailed description of these properties can be found
+	 *  in the documentation.
+	 */
+
+#if defined(DUK_USE_DEBUGGER_SUPPORT)
+	/* Line number range for function.  Needed during debugging to
+	 * determine active breakpoints.
+	 */
+	duk_uint32_t start_line;
+	duk_uint32_t end_line;
+#endif
+};
+
+#endif  /* DUK_HCOMPILEDFUNCTION_H_INCLUDED */

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_heap.h
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_heap.h b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_heap.h
new file mode 100644
index 0000000..5f96b1a
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_heap.h
@@ -0,0 +1,596 @@
+/*
+ *  Heap structure.
+ *
+ *  Heap contains allocated heap objects, interned strings, and built-in
+ *  strings for one or more threads.
+ */
+
+#ifndef DUK_HEAP_H_INCLUDED
+#define DUK_HEAP_H_INCLUDED
+
+/* alloc function typedefs in duktape.h */
+
+/*
+ *  Heap flags
+ */
+
+#define DUK_HEAP_FLAG_MARKANDSWEEP_RUNNING                     (1 << 0)  /* mark-and-sweep is currently running */
+#define DUK_HEAP_FLAG_MARKANDSWEEP_RECLIMIT_REACHED            (1 << 1)  /* mark-and-sweep marking reached a recursion limit and must use multi-pass marking */
+#define DUK_HEAP_FLAG_REFZERO_FREE_RUNNING                     (1 << 2)  /* refcount code is processing refzero list */
+#define DUK_HEAP_FLAG_ERRHANDLER_RUNNING                       (1 << 3)  /* an error handler (user callback to augment/replace error) is running */
+#define DUK_HEAP_FLAG_INTERRUPT_RUNNING                        (1 << 4)  /* executor interrupt running (used to avoid nested interrupts) */
+#define DUK_HEAP_FLAG_FINALIZER_NORESCUE                       (1 << 5)  /* heap destruction ongoing, finalizer rescue no longer possible */
+
+#define DUK__HEAP_HAS_FLAGS(heap,bits)               ((heap)->flags & (bits))
+#define DUK__HEAP_SET_FLAGS(heap,bits)  do { \
+		(heap)->flags |= (bits); \
+	} while (0)
+#define DUK__HEAP_CLEAR_FLAGS(heap,bits)  do { \
+		(heap)->flags &= ~(bits); \
+	} while (0)
+
+#define DUK_HEAP_HAS_MARKANDSWEEP_RUNNING(heap)            DUK__HEAP_HAS_FLAGS((heap), DUK_HEAP_FLAG_MARKANDSWEEP_RUNNING)
+#define DUK_HEAP_HAS_MARKANDSWEEP_RECLIMIT_REACHED(heap)   DUK__HEAP_HAS_FLAGS((heap), DUK_HEAP_FLAG_MARKANDSWEEP_RECLIMIT_REACHED)
+#define DUK_HEAP_HAS_REFZERO_FREE_RUNNING(heap)            DUK__HEAP_HAS_FLAGS((heap), DUK_HEAP_FLAG_REFZERO_FREE_RUNNING)
+#define DUK_HEAP_HAS_ERRHANDLER_RUNNING(heap)              DUK__HEAP_HAS_FLAGS((heap), DUK_HEAP_FLAG_ERRHANDLER_RUNNING)
+#define DUK_HEAP_HAS_INTERRUPT_RUNNING(heap)               DUK__HEAP_HAS_FLAGS((heap), DUK_HEAP_FLAG_INTERRUPT_RUNNING)
+#define DUK_HEAP_HAS_FINALIZER_NORESCUE(heap)              DUK__HEAP_HAS_FLAGS((heap), DUK_HEAP_FLAG_FINALIZER_NORESCUE)
+
+#define DUK_HEAP_SET_MARKANDSWEEP_RUNNING(heap)            DUK__HEAP_SET_FLAGS((heap), DUK_HEAP_FLAG_MARKANDSWEEP_RUNNING)
+#define DUK_HEAP_SET_MARKANDSWEEP_RECLIMIT_REACHED(heap)   DUK__HEAP_SET_FLAGS((heap), DUK_HEAP_FLAG_MARKANDSWEEP_RECLIMIT_REACHED)
+#define DUK_HEAP_SET_REFZERO_FREE_RUNNING(heap)            DUK__HEAP_SET_FLAGS((heap), DUK_HEAP_FLAG_REFZERO_FREE_RUNNING)
+#define DUK_HEAP_SET_ERRHANDLER_RUNNING(heap)              DUK__HEAP_SET_FLAGS((heap), DUK_HEAP_FLAG_ERRHANDLER_RUNNING)
+#define DUK_HEAP_SET_INTERRUPT_RUNNING(heap)               DUK__HEAP_SET_FLAGS((heap), DUK_HEAP_FLAG_INTERRUPT_RUNNING)
+#define DUK_HEAP_SET_FINALIZER_NORESCUE(heap)              DUK__HEAP_SET_FLAGS((heap), DUK_HEAP_FLAG_FINALIZER_NORESCUE)
+
+#define DUK_HEAP_CLEAR_MARKANDSWEEP_RUNNING(heap)          DUK__HEAP_CLEAR_FLAGS((heap), DUK_HEAP_FLAG_MARKANDSWEEP_RUNNING)
+#define DUK_HEAP_CLEAR_MARKANDSWEEP_RECLIMIT_REACHED(heap) DUK__HEAP_CLEAR_FLAGS((heap), DUK_HEAP_FLAG_MARKANDSWEEP_RECLIMIT_REACHED)
+#define DUK_HEAP_CLEAR_REFZERO_FREE_RUNNING(heap)          DUK__HEAP_CLEAR_FLAGS((heap), DUK_HEAP_FLAG_REFZERO_FREE_RUNNING)
+#define DUK_HEAP_CLEAR_ERRHANDLER_RUNNING(heap)            DUK__HEAP_CLEAR_FLAGS((heap), DUK_HEAP_FLAG_ERRHANDLER_RUNNING)
+#define DUK_HEAP_CLEAR_INTERRUPT_RUNNING(heap)             DUK__HEAP_CLEAR_FLAGS((heap), DUK_HEAP_FLAG_INTERRUPT_RUNNING)
+#define DUK_HEAP_CLEAR_FINALIZER_NORESCUE(heap)            DUK__HEAP_CLEAR_FLAGS((heap), DUK_HEAP_FLAG_FINALIZER_NORESCUE)
+
+/*
+ *  Longjmp types, also double as identifying continuation type for a rethrow (in 'finally')
+ */
+
+#define DUK_LJ_TYPE_UNKNOWN      0    /* unused */
+#define DUK_LJ_TYPE_THROW        1    /* value1 -> error object */
+#define DUK_LJ_TYPE_YIELD        2    /* value1 -> yield value, iserror -> error / normal */
+#define DUK_LJ_TYPE_RESUME       3    /* value1 -> resume value, value2 -> resumee thread, iserror -> error/normal */
+#define DUK_LJ_TYPE_BREAK        4    /* value1 -> label number, pseudo-type to indicate a break continuation (for ENDFIN) */
+#define DUK_LJ_TYPE_CONTINUE     5    /* value1 -> label number, pseudo-type to indicate a continue continuation (for ENDFIN) */
+#define DUK_LJ_TYPE_RETURN       6    /* value1 -> return value, pseudo-type to indicate a return continuation (for ENDFIN) */
+#define DUK_LJ_TYPE_NORMAL       7    /* no value, pseudo-type to indicate a normal continuation (for ENDFIN) */
+
+/*
+ *  Mark-and-sweep flags
+ *
+ *  These are separate from heap level flags now but could be merged.
+ *  The heap structure only contains a 'base mark-and-sweep flags'
+ *  field and the GC caller can impose further flags.
+ */
+
+#define DUK_MS_FLAG_EMERGENCY                (1 << 0)   /* emergency mode: try extra hard */
+#define DUK_MS_FLAG_NO_STRINGTABLE_RESIZE    (1 << 1)   /* don't resize stringtable (but may sweep it); needed during stringtable resize */
+#define DUK_MS_FLAG_NO_OBJECT_COMPACTION     (1 << 2)   /* don't compact objects; needed during object property allocation resize */
+#define DUK_MS_FLAG_NO_FINALIZERS            (1 << 3)   /* don't run finalizers; leave finalizable objects in finalize_list for next round */
+#define DUK_MS_FLAG_SKIP_FINALIZERS          (1 << 4)   /* don't run finalizers; queue finalizable objects back to heap_allocated */
+
+/*
+ *  Thread switching
+ *
+ *  To switch heap->curr_thread, use the macro below so that interrupt counters
+ *  get updated correctly.  The macro allows a NULL target thread because that
+ *  happens e.g. in call handling.
+ */
+
+#if defined(DUK_USE_INTERRUPT_COUNTER)
+#define DUK_HEAP_SWITCH_THREAD(heap,newthr)  duk_heap_switch_thread((heap), (newthr))
+#else
+#define DUK_HEAP_SWITCH_THREAD(heap,newthr)  do { \
+		(heap)->curr_thread = (newthr); \
+	} while (0)
+#endif
+
+/*
+ *  Other heap related defines
+ */
+
+/* Mark-and-sweep interval is relative to combined count of objects and
+ * strings kept in the heap during the latest mark-and-sweep pass.
+ * Fixed point .8 multiplier and .0 adder.  Trigger count (interval) is
+ * decreased by each (re)allocation attempt (regardless of size), and each
+ * refzero processed object.
+ *
+ * 'SKIP' indicates how many (re)allocations to wait until a retry if
+ * GC is skipped because there is no thread do it with yet (happens
+ * only during init phases).
+ */
+#if defined(DUK_USE_MARK_AND_SWEEP)
+#if defined(DUK_USE_REFERENCE_COUNTING)
+#define DUK_HEAP_MARK_AND_SWEEP_TRIGGER_MULT              12800L  /* 50x heap size */
+#define DUK_HEAP_MARK_AND_SWEEP_TRIGGER_ADD               1024L
+#define DUK_HEAP_MARK_AND_SWEEP_TRIGGER_SKIP              256L
+#else
+#define DUK_HEAP_MARK_AND_SWEEP_TRIGGER_MULT              256L    /* 1x heap size */
+#define DUK_HEAP_MARK_AND_SWEEP_TRIGGER_ADD               1024L
+#define DUK_HEAP_MARK_AND_SWEEP_TRIGGER_SKIP              256L
+#endif
+#endif
+
+/* Stringcache is used for speeding up char-offset-to-byte-offset
+ * translations for non-ASCII strings.
+ */
+#define DUK_HEAP_STRCACHE_SIZE                            4
+#define DUK_HEAP_STRINGCACHE_NOCACHE_LIMIT                16  /* strings up to the this length are not cached */
+
+/* helper to insert a (non-string) heap object into heap allocated list */
+#define DUK_HEAP_INSERT_INTO_HEAP_ALLOCATED(heap,hdr)     duk_heap_insert_into_heap_allocated((heap),(hdr))
+
+/*
+ *  Stringtable
+ */
+
+/* initial stringtable size, must be prime and higher than DUK_UTIL_MIN_HASH_PRIME */
+#define DUK_STRTAB_INITIAL_SIZE            17
+
+/* indicates a deleted string; any fixed non-NULL, non-hstring pointer works */
+#define DUK_STRTAB_DELETED_MARKER(heap)    ((duk_hstring *) heap)
+
+/* resizing parameters */
+#define DUK_STRTAB_MIN_FREE_DIVISOR        4                /* load factor max 75% */
+#define DUK_STRTAB_MIN_USED_DIVISOR        4                /* load factor min 25% */
+#define DUK_STRTAB_GROW_ST_SIZE(n)         ((n) + (n))      /* used entries + approx 100% -> reset load to 50% */
+
+#define DUK_STRTAB_U32_MAX_STRLEN          10               /* 4'294'967'295 */
+#define DUK_STRTAB_HIGHEST_32BIT_PRIME     0xfffffffbUL
+
+/* probe sequence (open addressing) */
+#define DUK_STRTAB_HASH_INITIAL(hash,h_size)    ((hash) % (h_size))
+#define DUK_STRTAB_HASH_PROBE_STEP(hash)        DUK_UTIL_GET_HASH_PROBE_STEP((hash))
+
+/* fixed top level hashtable size (separate chaining) */
+#define DUK_STRTAB_CHAIN_SIZE              DUK_USE_STRTAB_CHAIN_SIZE
+
+/*
+ *  Built-in strings
+ */
+
+/* heap string indices are autogenerated in duk_strings.h */
+#if defined(DUK_USE_ROM_STRINGS)
+#define DUK_HEAP_GET_STRING(heap,idx) \
+	((duk_hstring *) DUK_LOSE_CONST(duk_rom_strings_stridx[(idx)]))
+#else  /* DUK_USE_ROM_STRINGS */
+#if defined(DUK_USE_HEAPPTR16)
+#define DUK_HEAP_GET_STRING(heap,idx) \
+	((duk_hstring *) DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, (heap)->strs16[(idx)]))
+#else
+#define DUK_HEAP_GET_STRING(heap,idx) \
+	((heap)->strs[(idx)])
+#endif
+#endif  /* DUK_USE_ROM_STRINGS */
+
+/*
+ *  Raw memory calls: relative to heap, but no GC interaction
+ */
+
+#define DUK_ALLOC_RAW(heap,size) \
+	((heap)->alloc_func((heap)->heap_udata, (size)))
+
+#define DUK_REALLOC_RAW(heap,ptr,newsize) \
+	((heap)->realloc_func((heap)->heap_udata, (void *) (ptr), (newsize)))
+
+#define DUK_FREE_RAW(heap,ptr) \
+	((heap)->free_func((heap)->heap_udata, (void *) (ptr)))
+
+/*
+ *  Memory calls: relative to heap, GC interaction, but no error throwing.
+ *
+ *  XXX: Currently a mark-and-sweep triggered by memory allocation will run
+ *  using the heap->heap_thread.  This thread is also used for running
+ *  mark-and-sweep finalization; this is not ideal because it breaks the
+ *  isolation between multiple global environments.
+ *
+ *  Notes:
+ *
+ *    - DUK_FREE() is required to ignore NULL and any other possible return
+ *      value of a zero-sized alloc/realloc (same as ANSI C free()).
+ *
+ *    - There is no DUK_REALLOC_ZEROED because we don't assume to know the
+ *      old size.  Caller must zero the reallocated memory.
+ *
+ *    - DUK_REALLOC_INDIRECT() must be used when a mark-and-sweep triggered
+ *      by an allocation failure might invalidate the original 'ptr', thus
+ *      causing a realloc retry to use an invalid pointer.  Example: we're
+ *      reallocating the value stack and a finalizer resizes the same value
+ *      stack during mark-and-sweep.  The indirect variant requests for the
+ *      current location of the pointer being reallocated using a callback
+ *      right before every realloc attempt; this circuitous approach is used
+ *      to avoid strict aliasing issues in a more straightforward indirect
+ *      pointer (void **) approach.  Note: the pointer in the storage
+ *      location is read but is NOT updated; the caller must do that.
+ */
+
+/* callback for indirect reallocs, request for current pointer */
+typedef void *(*duk_mem_getptr)(duk_heap *heap, void *ud);
+
+#define DUK_ALLOC(heap,size)                            duk_heap_mem_alloc((heap), (size))
+#define DUK_ALLOC_ZEROED(heap,size)                     duk_heap_mem_alloc_zeroed((heap), (size))
+#define DUK_REALLOC(heap,ptr,newsize)                   duk_heap_mem_realloc((heap), (ptr), (newsize))
+#define DUK_REALLOC_INDIRECT(heap,cb,ud,newsize)        duk_heap_mem_realloc_indirect((heap), (cb), (ud), (newsize))
+#define DUK_FREE(heap,ptr)                              duk_heap_mem_free((heap), (ptr))
+
+/*
+ *  Memory constants
+ */
+
+#define DUK_HEAP_ALLOC_FAIL_MARKANDSWEEP_LIMIT           5   /* Retry allocation after mark-and-sweep for this
+                                                              * many times.  A single mark-and-sweep round is
+                                                              * not guaranteed to free all unreferenced memory
+                                                              * because of finalization (in fact, ANY number of
+                                                              * rounds is strictly not enough).
+                                                              */
+
+#define DUK_HEAP_ALLOC_FAIL_MARKANDSWEEP_EMERGENCY_LIMIT  3  /* Starting from this round, use emergency mode
+                                                              * for mark-and-sweep.
+                                                              */
+
+/*
+ *  Debugger support
+ */
+
+/* Maximum number of breakpoints.  Only breakpoints that are set are
+ * consulted so increasing this has no performance impact.
+ */
+#define DUK_HEAP_MAX_BREAKPOINTS          16
+
+/* Opcode interval for a Date-based status/peek rate limit check.  Only
+ * relevant when debugger is attached.  Requesting a timestamp may be a
+ * slow operation on some platforms so this shouldn't be too low.  On the
+ * other hand a high value makes Duktape react to a pause request slowly.
+ */
+#define DUK_HEAP_DBG_RATELIMIT_OPCODES    4000
+
+/* Milliseconds between status notify and transport peeks. */
+#define DUK_HEAP_DBG_RATELIMIT_MILLISECS  200
+
+/* Step types */
+#define DUK_STEP_TYPE_NONE  0
+#define DUK_STEP_TYPE_INTO  1
+#define DUK_STEP_TYPE_OVER  2
+#define DUK_STEP_TYPE_OUT   3
+
+struct duk_breakpoint {
+	duk_hstring *filename;
+	duk_uint32_t line;
+};
+
+#if defined(DUK_USE_DEBUGGER_SUPPORT)
+#define DUK_HEAP_IS_DEBUGGER_ATTACHED(heap) ((heap)->dbg_read_cb != NULL)
+#define DUK_HEAP_CLEAR_STEP_STATE(heap) do { \
+		(heap)->dbg_step_type = DUK_STEP_TYPE_NONE; \
+		(heap)->dbg_step_thread = NULL; \
+		(heap)->dbg_step_csindex = 0; \
+		(heap)->dbg_step_startline = 0; \
+	} while (0)
+#define DUK_HEAP_SET_PAUSED(heap) do { \
+		(heap)->dbg_paused = 1; \
+		(heap)->dbg_state_dirty = 1; \
+		DUK_HEAP_CLEAR_STEP_STATE((heap)); \
+	} while (0)
+#define DUK_HEAP_CLEAR_PAUSED(heap) do { \
+		(heap)->dbg_paused = 0; \
+		(heap)->dbg_state_dirty = 1; \
+		DUK_HEAP_CLEAR_STEP_STATE((heap)); \
+	} while (0)
+#define DUK_HEAP_IS_PAUSED(heap) ((heap)->dbg_paused)
+#endif  /* DUK_USE_DEBUGGER_SUPPORT */
+
+/*
+ *  String cache should ideally be at duk_hthread level, but that would
+ *  cause string finalization to slow down relative to the number of
+ *  threads; string finalization must check the string cache for "weak"
+ *  references to the string being finalized to avoid dead pointers.
+ *
+ *  Thus, string caches are now at the heap level now.
+ */
+
+struct duk_strcache {
+	duk_hstring *h;
+	duk_uint32_t bidx;
+	duk_uint32_t cidx;
+};
+
+/*
+ *  Longjmp state, contains the information needed to perform a longjmp.
+ *  Longjmp related values are written to value1, value2, and iserror.
+ */
+
+struct duk_ljstate {
+	duk_jmpbuf *jmpbuf_ptr;   /* current setjmp() catchpoint */
+	duk_small_uint_t type;    /* longjmp type */
+	duk_bool_t iserror;       /* isError flag for yield */
+	duk_tval value1;          /* 1st related value (type specific) */
+	duk_tval value2;          /* 2nd related value (type specific) */
+};
+
+/*
+ *  Stringtable entry for fixed size stringtable
+ */
+
+struct duk_strtab_entry {
+#if defined(DUK_USE_HEAPPTR16)
+	/* A 16-bit listlen makes sense with 16-bit heap pointers: there
+	 * won't be space for 64k strings anyway.
+	 */
+	duk_uint16_t listlen;  /* if 0, 'str16' used, if > 0, 'strlist16' used */
+	union {
+		duk_uint16_t strlist16;
+		duk_uint16_t str16;
+	} u;
+#else
+	duk_size_t listlen;  /* if 0, 'str' used, if > 0, 'strlist' used */
+	union {
+		duk_hstring **strlist;
+		duk_hstring *str;
+	} u;
+#endif
+};
+
+/*
+ *  Main heap structure
+ */
+
+struct duk_heap {
+	duk_small_uint_t flags;
+
+	/* Allocator functions. */
+	duk_alloc_function alloc_func;
+	duk_realloc_function realloc_func;
+	duk_free_function free_func;
+
+	/* Heap udata, used for allocator functions but also for other heap
+	 * level callbacks like pointer compression, etc.
+	 */
+	void *heap_udata;
+
+	/* Precomputed pointers when using 16-bit heap pointer packing. */
+#if defined(DUK_USE_HEAPPTR16)
+	duk_uint16_t heapptr_null16;
+	duk_uint16_t heapptr_deleted16;
+#endif
+
+	/* Fatal error handling, called e.g. when a longjmp() is needed but
+	 * lj.jmpbuf_ptr is NULL.  fatal_func must never return; it's not
+	 * declared as "noreturn" because doing that for typedefs is a bit
+	 * challenging portability-wise.
+	 */
+	duk_fatal_function fatal_func;
+
+	/* allocated heap objects */
+	duk_heaphdr *heap_allocated;
+
+	/* work list for objects whose refcounts are zero but which have not been
+	 * "finalized"; avoids recursive C calls when refcounts go to zero in a
+	 * chain of objects.
+	 */
+#if defined(DUK_USE_REFERENCE_COUNTING)
+	duk_heaphdr *refzero_list;
+	duk_heaphdr *refzero_list_tail;
+#endif
+
+#if defined(DUK_USE_MARK_AND_SWEEP)
+	/* mark-and-sweep control */
+#if defined(DUK_USE_VOLUNTARY_GC)
+	duk_int_t mark_and_sweep_trigger_counter;
+#endif
+	duk_int_t mark_and_sweep_recursion_depth;
+
+	/* mark-and-sweep flags automatically active (used for critical sections) */
+	duk_small_uint_t mark_and_sweep_base_flags;
+
+	/* work list for objects to be finalized (by mark-and-sweep) */
+	duk_heaphdr *finalize_list;
+#endif
+
+	/* longjmp state */
+	duk_ljstate lj;
+
+	/* marker for detecting internal "double faults", see duk_error_throw.c */
+	duk_bool_t handling_error;
+
+	/* heap thread, used internally and for finalization */
+	duk_hthread *heap_thread;
+
+	/* current thread */
+	duk_hthread *curr_thread;  /* currently running thread */
+
+	/* heap level "stash" object (e.g., various reachability roots) */
+	duk_hobject *heap_object;
+
+	/* duk_handle_call / duk_handle_safe_call recursion depth limiting */
+	duk_int_t call_recursion_depth;
+	duk_int_t call_recursion_limit;
+
+	/* mix-in value for computing string hashes; should be reasonably unpredictable */
+	duk_uint32_t hash_seed;
+
+	/* rnd_state for duk_util_tinyrandom.c */
+	duk_uint32_t rnd_state;
+
+	/* For manual debugging: instruction count based on executor and
+	 * interrupt counter book-keeping.  Inspect debug logs to see how
+	 * they match up.
+	 */
+#if defined(DUK_USE_INTERRUPT_COUNTER) && defined(DUK_USE_DEBUG)
+	duk_int_t inst_count_exec;
+	duk_int_t inst_count_interrupt;
+#endif
+
+	/* debugger */
+
+#if defined(DUK_USE_DEBUGGER_SUPPORT)
+	/* callbacks and udata; dbg_read_cb != NULL is used to indicate attached state */
+	duk_debug_read_function dbg_read_cb;                /* required, NULL implies detached */
+	duk_debug_write_function dbg_write_cb;              /* required */
+	duk_debug_peek_function dbg_peek_cb;
+	duk_debug_read_flush_function dbg_read_flush_cb;
+	duk_debug_write_flush_function dbg_write_flush_cb;
+	duk_debug_request_function dbg_request_cb;
+	duk_debug_detached_function dbg_detached_cb;
+	void *dbg_udata;
+
+	/* debugger state, only relevant when attached */
+	duk_bool_t dbg_processing;              /* currently processing messages or breakpoints: don't enter message processing recursively (e.g. no breakpoints when processing debugger eval) */
+	duk_bool_t dbg_paused;                  /* currently paused: talk with debug client until step/resume */
+	duk_bool_t dbg_state_dirty;             /* resend state next time executor is about to run */
+	duk_bool_t dbg_force_restart;           /* force executor restart to recheck breakpoints; used to handle function returns (see GH-303) */
+	duk_bool_t dbg_detaching;               /* debugger detaching; used to avoid calling detach handler recursively */
+	duk_small_uint_t dbg_step_type;         /* step type: none, step into, step over, step out */
+	duk_hthread *dbg_step_thread;           /* borrowed; NULL if no step state (NULLed in unwind) */
+	duk_size_t dbg_step_csindex;            /* callstack index */
+	duk_uint32_t dbg_step_startline;        /* starting line number */
+	duk_breakpoint dbg_breakpoints[DUK_HEAP_MAX_BREAKPOINTS];  /* breakpoints: [0,breakpoint_count[ gc reachable */
+	duk_small_uint_t dbg_breakpoint_count;
+	duk_breakpoint *dbg_breakpoints_active[DUK_HEAP_MAX_BREAKPOINTS + 1];  /* currently active breakpoints: NULL term, borrowed pointers */
+	/* XXX: make active breakpoints actual copies instead of pointers? */
+
+	/* These are for rate limiting Status notifications and transport peeking. */
+	duk_uint32_t dbg_exec_counter;          /* cumulative opcode execution count (overflows are OK) */
+	duk_uint32_t dbg_last_counter;          /* value of dbg_exec_counter when we last did a Date-based check */
+	duk_double_t dbg_last_time;             /* time when status/peek was last done (Date-based rate limit) */
+
+	/* Used to support single-byte stream lookahead. */
+	duk_bool_t dbg_have_next_byte;
+	duk_uint8_t dbg_next_byte;
+#endif
+
+	/* string intern table (weak refs) */
+#if defined(DUK_USE_STRTAB_PROBE)
+#if defined(DUK_USE_HEAPPTR16)
+	duk_uint16_t *strtable16;
+#else
+	duk_hstring **strtable;
+#endif
+	duk_uint32_t st_size;     /* alloc size in elements */
+	duk_uint32_t st_used;     /* used elements (includes DELETED) */
+#endif
+
+	/* XXX: static alloc is OK until separate chaining stringtable
+	 * resizing is implemented.
+	 */
+#if defined(DUK_USE_STRTAB_CHAIN)
+	duk_strtab_entry strtable[DUK_STRTAB_CHAIN_SIZE];
+#endif
+
+	/* string access cache (codepoint offset -> byte offset) for fast string
+	 * character looping; 'weak' reference which needs special handling in GC.
+	 */
+	duk_strcache strcache[DUK_HEAP_STRCACHE_SIZE];
+
+	/* built-in strings */
+#if defined(DUK_USE_ROM_STRINGS)
+	/* No field needed when strings are in ROM. */
+#else
+#if defined(DUK_USE_HEAPPTR16)
+	duk_uint16_t strs16[DUK_HEAP_NUM_STRINGS];
+#else
+	duk_hstring *strs[DUK_HEAP_NUM_STRINGS];
+#endif
+#endif
+};
+
+/*
+ *  Prototypes
+ */
+
+DUK_INTERNAL_DECL
+duk_heap *duk_heap_alloc(duk_alloc_function alloc_func,
+                         duk_realloc_function realloc_func,
+                         duk_free_function free_func,
+                         void *heap_udata,
+                         duk_fatal_function fatal_func);
+DUK_INTERNAL_DECL void duk_heap_free(duk_heap *heap);
+DUK_INTERNAL_DECL void duk_free_hobject_inner(duk_heap *heap, duk_hobject *h);
+DUK_INTERNAL_DECL void duk_free_hbuffer_inner(duk_heap *heap, duk_hbuffer *h);
+DUK_INTERNAL_DECL void duk_free_hstring_inner(duk_heap *heap, duk_hstring *h);
+DUK_INTERNAL_DECL void duk_heap_free_heaphdr_raw(duk_heap *heap, duk_heaphdr *hdr);
+
+DUK_INTERNAL_DECL void duk_heap_insert_into_heap_allocated(duk_heap *heap, duk_heaphdr *hdr);
+#if defined(DUK_USE_DOUBLE_LINKED_HEAP) && defined(DUK_USE_REFERENCE_COUNTING)
+DUK_INTERNAL_DECL void duk_heap_remove_any_from_heap_allocated(duk_heap *heap, duk_heaphdr *hdr);
+#endif
+#if defined(DUK_USE_INTERRUPT_COUNTER)
+DUK_INTERNAL_DECL void duk_heap_switch_thread(duk_heap *heap, duk_hthread *new_thr);
+#endif
+
+#if 0  /*unused*/
+DUK_INTERNAL_DECL duk_hstring *duk_heap_string_lookup(duk_heap *heap, const duk_uint8_t *str, duk_uint32_t blen);
+#endif
+DUK_INTERNAL_DECL duk_hstring *duk_heap_string_intern(duk_heap *heap, const duk_uint8_t *str, duk_uint32_t blen);
+DUK_INTERNAL_DECL duk_hstring *duk_heap_string_intern_checked(duk_hthread *thr, const duk_uint8_t *str, duk_uint32_t len);
+#if 0  /*unused*/
+DUK_INTERNAL_DECL duk_hstring *duk_heap_string_lookup_u32(duk_heap *heap, duk_uint32_t val);
+#endif
+DUK_INTERNAL_DECL duk_hstring *duk_heap_string_intern_u32(duk_heap *heap, duk_uint32_t val);
+DUK_INTERNAL_DECL duk_hstring *duk_heap_string_intern_u32_checked(duk_hthread *thr, duk_uint32_t val);
+#if defined(DUK_USE_REFERENCE_COUNTING)
+DUK_INTERNAL_DECL void duk_heap_string_remove(duk_heap *heap, duk_hstring *h);
+#endif
+#if defined(DUK_USE_MARK_AND_SWEEP) && defined(DUK_USE_MS_STRINGTABLE_RESIZE)
+DUK_INTERNAL_DECL void duk_heap_force_strtab_resize(duk_heap *heap);
+#endif
+DUK_INTERNAL void duk_heap_free_strtab(duk_heap *heap);
+#if defined(DUK_USE_DEBUG)
+DUK_INTERNAL void duk_heap_dump_strtab(duk_heap *heap);
+#endif
+
+
+DUK_INTERNAL_DECL void duk_heap_strcache_string_remove(duk_heap *heap, duk_hstring *h);
+DUK_INTERNAL_DECL duk_uint_fast32_t duk_heap_strcache_offset_char2byte(duk_hthread *thr, duk_hstring *h, duk_uint_fast32_t char_offset);
+
+#if defined(DUK_USE_PROVIDE_DEFAULT_ALLOC_FUNCTIONS)
+DUK_INTERNAL_DECL void *duk_default_alloc_function(void *udata, duk_size_t size);
+DUK_INTERNAL_DECL void *duk_default_realloc_function(void *udata, void *ptr, duk_size_t newsize);
+DUK_INTERNAL_DECL void duk_default_free_function(void *udata, void *ptr);
+#endif
+
+DUK_INTERNAL_DECL void *duk_heap_mem_alloc(duk_heap *heap, duk_size_t size);
+DUK_INTERNAL_DECL void *duk_heap_mem_alloc_zeroed(duk_heap *heap, duk_size_t size);
+DUK_INTERNAL_DECL void *duk_heap_mem_realloc(duk_heap *heap, void *ptr, duk_size_t newsize);
+DUK_INTERNAL_DECL void *duk_heap_mem_realloc_indirect(duk_heap *heap, duk_mem_getptr cb, void *ud, duk_size_t newsize);
+DUK_INTERNAL_DECL void duk_heap_mem_free(duk_heap *heap, void *ptr);
+
+#ifdef DUK_USE_REFERENCE_COUNTING
+#if !defined(DUK_USE_FAST_REFCOUNT_DEFAULT)
+DUK_INTERNAL_DECL void duk_tval_incref(duk_tval *tv);
+#endif
+#if 0  /* unused */
+DUK_INTERNAL_DECL void duk_tval_incref_allownull(duk_tval *tv);
+#endif
+DUK_INTERNAL_DECL void duk_tval_decref(duk_hthread *thr, duk_tval *tv);
+#if 0  /* unused */
+DUK_INTERNAL_DECL void duk_tval_decref_allownull(duk_hthread *thr, duk_tval *tv);
+#endif
+#if !defined(DUK_USE_FAST_REFCOUNT_DEFAULT)
+DUK_INTERNAL_DECL void duk_heaphdr_incref(duk_heaphdr *h);
+#endif
+#if 0  /* unused */
+DUK_INTERNAL_DECL void duk_heaphdr_incref_allownull(duk_heaphdr *h);
+#endif
+DUK_INTERNAL_DECL void duk_heaphdr_decref(duk_hthread *thr, duk_heaphdr *h);
+DUK_INTERNAL_DECL void duk_heaphdr_decref_allownull(duk_hthread *thr, duk_heaphdr *h);
+DUK_INTERNAL_DECL void duk_heaphdr_refzero(duk_hthread *thr, duk_heaphdr *h);
+DUK_INTERNAL_DECL void duk_heaphdr_refcount_finalize(duk_hthread *thr, duk_heaphdr *hdr);
+#else
+/* no refcounting */
+#endif
+
+#if defined(DUK_USE_MARK_AND_SWEEP)
+DUK_INTERNAL_DECL duk_bool_t duk_heap_mark_and_sweep(duk_heap *heap, duk_small_uint_t flags);
+#endif
+
+DUK_INTERNAL_DECL duk_uint32_t duk_heap_hashstring(duk_heap *heap, const duk_uint8_t *str, duk_size_t len);
+
+#endif  /* DUK_HEAP_H_INCLUDED */

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_heap_alloc.c
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_heap_alloc.c b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_heap_alloc.c
new file mode 100644
index 0000000..b89fe48
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_heap_alloc.c
@@ -0,0 +1,1042 @@
+/*
+ *  duk_heap allocation and freeing.
+ */
+
+#include "duk_internal.h"
+
+/* Constants for built-in string data depacking. */
+#define DUK__BITPACK_LETTER_LIMIT  26
+#define DUK__BITPACK_UNDERSCORE    26
+#define DUK__BITPACK_FF            27
+#define DUK__BITPACK_SWITCH1       29
+#define DUK__BITPACK_SWITCH        30
+#define DUK__BITPACK_SEVENBIT      31
+
+#if defined(DUK_USE_ROM_STRINGS)
+/* Fixed seed value used with ROM strings. */
+#define DUK__FIXED_HASH_SEED       0xabcd1234
+#endif
+
+/*
+ *  Free a heap object.
+ *
+ *  Free heap object and its internal (non-heap) pointers.  Assumes that
+ *  caller has removed the object from heap allocated list or the string
+ *  intern table, and any weak references (which strings may have) have
+ *  been already dealt with.
+ */
+
+DUK_INTERNAL void duk_free_hobject_inner(duk_heap *heap, duk_hobject *h) {
+	DUK_ASSERT(heap != NULL);
+	DUK_ASSERT(h != NULL);
+
+	DUK_FREE(heap, DUK_HOBJECT_GET_PROPS(heap, h));
+
+	if (DUK_HOBJECT_IS_COMPILEDFUNCTION(h)) {
+		duk_hcompiledfunction *f = (duk_hcompiledfunction *) h;
+		DUK_UNREF(f);
+		/* Currently nothing to free; 'data' is a heap object */
+	} else if (DUK_HOBJECT_IS_NATIVEFUNCTION(h)) {
+		duk_hnativefunction *f = (duk_hnativefunction *) h;
+		DUK_UNREF(f);
+		/* Currently nothing to free */
+	} else if (DUK_HOBJECT_IS_THREAD(h)) {
+		duk_hthread *t = (duk_hthread *) h;
+		DUK_FREE(heap, t->valstack);
+		DUK_FREE(heap, t->callstack);
+		DUK_FREE(heap, t->catchstack);
+		/* Don't free h->resumer because it exists in the heap.
+		 * Callstack entries also contain function pointers which
+		 * are not freed for the same reason.
+		 */
+
+		/* XXX: with 'caller' property the callstack would need
+		 * to be unwound to update the 'caller' properties of
+		 * functions in the callstack.
+		 */
+	}
+}
+
+DUK_INTERNAL void duk_free_hbuffer_inner(duk_heap *heap, duk_hbuffer *h) {
+	DUK_ASSERT(heap != NULL);
+	DUK_ASSERT(h != NULL);
+
+	if (DUK_HBUFFER_HAS_DYNAMIC(h) && !DUK_HBUFFER_HAS_EXTERNAL(h)) {
+		duk_hbuffer_dynamic *g = (duk_hbuffer_dynamic *) h;
+		DUK_DDD(DUK_DDDPRINT("free dynamic buffer %p", (void *) DUK_HBUFFER_DYNAMIC_GET_DATA_PTR(heap, g)));
+		DUK_FREE(heap, DUK_HBUFFER_DYNAMIC_GET_DATA_PTR(heap, g));
+	}
+}
+
+DUK_INTERNAL void duk_free_hstring_inner(duk_heap *heap, duk_hstring *h) {
+	DUK_ASSERT(heap != NULL);
+	DUK_ASSERT(h != NULL);
+
+	DUK_UNREF(heap);
+	DUK_UNREF(h);
+
+#if defined(DUK_USE_HSTRING_EXTDATA) && defined(DUK_USE_EXTSTR_FREE)
+	if (DUK_HSTRING_HAS_EXTDATA(h)) {
+		DUK_DDD(DUK_DDDPRINT("free extstr: hstring %!O, extdata: %p",
+		                     h, DUK_HSTRING_GET_EXTDATA((duk_hstring_external *) h)));
+		DUK_USE_EXTSTR_FREE(heap->heap_udata, (const void *) DUK_HSTRING_GET_EXTDATA((duk_hstring_external *) h));
+	}
+#endif
+}
+
+DUK_INTERNAL void duk_heap_free_heaphdr_raw(duk_heap *heap, duk_heaphdr *hdr) {
+	DUK_ASSERT(heap);
+	DUK_ASSERT(hdr);
+
+	DUK_DDD(DUK_DDDPRINT("free heaphdr %p, htype %ld", (void *) hdr, (long) DUK_HEAPHDR_GET_TYPE(hdr)));
+
+	switch ((int) DUK_HEAPHDR_GET_TYPE(hdr)) {
+	case DUK_HTYPE_STRING:
+		duk_free_hstring_inner(heap, (duk_hstring *) hdr);
+		break;
+	case DUK_HTYPE_OBJECT:
+		duk_free_hobject_inner(heap, (duk_hobject *) hdr);
+		break;
+	case DUK_HTYPE_BUFFER:
+		duk_free_hbuffer_inner(heap, (duk_hbuffer *) hdr);
+		break;
+	default:
+		DUK_UNREACHABLE();
+	}
+
+	DUK_FREE(heap, hdr);
+}
+
+/*
+ *  Free the heap.
+ *
+ *  Frees heap-related non-heap-tracked allocations such as the
+ *  string intern table; then frees the heap allocated objects;
+ *  and finally frees the heap structure itself.  Reference counts
+ *  and GC markers are ignored (and not updated) in this process,
+ *  and finalizers won't be called.
+ *
+ *  The heap pointer and heap object pointers must not be used
+ *  after this call.
+ */
+
+DUK_LOCAL void duk__free_allocated(duk_heap *heap) {
+	duk_heaphdr *curr;
+	duk_heaphdr *next;
+
+	curr = heap->heap_allocated;
+	while (curr) {
+		/* We don't log or warn about freeing zero refcount objects
+		 * because they may happen with finalizer processing.
+		 */
+
+		DUK_DDD(DUK_DDDPRINT("FINALFREE (allocated): %!iO",
+		                     (duk_heaphdr *) curr));
+		next = DUK_HEAPHDR_GET_NEXT(heap, curr);
+		duk_heap_free_heaphdr_raw(heap, curr);
+		curr = next;
+	}
+}
+
+#if defined(DUK_USE_REFERENCE_COUNTING)
+DUK_LOCAL void duk__free_refzero_list(duk_heap *heap) {
+	duk_heaphdr *curr;
+	duk_heaphdr *next;
+
+	curr = heap->refzero_list;
+	while (curr) {
+		DUK_DDD(DUK_DDDPRINT("FINALFREE (refzero_list): %!iO",
+		                     (duk_heaphdr *) curr));
+		next = DUK_HEAPHDR_GET_NEXT(heap, curr);
+		duk_heap_free_heaphdr_raw(heap, curr);
+		curr = next;
+	}
+}
+#endif
+
+#if defined(DUK_USE_MARK_AND_SWEEP)
+DUK_LOCAL void duk__free_markandsweep_finalize_list(duk_heap *heap) {
+	duk_heaphdr *curr;
+	duk_heaphdr *next;
+
+	curr = heap->finalize_list;
+	while (curr) {
+		DUK_DDD(DUK_DDDPRINT("FINALFREE (finalize_list): %!iO",
+		                     (duk_heaphdr *) curr));
+		next = DUK_HEAPHDR_GET_NEXT(heap, curr);
+		duk_heap_free_heaphdr_raw(heap, curr);
+		curr = next;
+	}
+}
+#endif
+
+DUK_LOCAL void duk__free_stringtable(duk_heap *heap) {
+	/* strings are only tracked by stringtable */
+	duk_heap_free_strtab(heap);
+}
+
+DUK_LOCAL void duk__free_run_finalizers(duk_heap *heap) {
+	duk_hthread *thr;
+	duk_heaphdr *curr;
+	duk_uint_t round_no;
+	duk_size_t count_all;
+	duk_size_t count_finalized;
+	duk_size_t curr_limit;
+
+	DUK_ASSERT(heap != NULL);
+	DUK_ASSERT(heap->heap_thread != NULL);
+
+#if defined(DUK_USE_REFERENCE_COUNTING)
+	DUK_ASSERT(heap->refzero_list == NULL);  /* refzero not running -> must be empty */
+#endif
+#if defined(DUK_USE_MARK_AND_SWEEP)
+	DUK_ASSERT(heap->finalize_list == NULL);  /* mark-and-sweep not running -> must be empty */
+#endif
+
+	/* XXX: here again finalizer thread is the heap_thread which needs
+	 * to be coordinated with finalizer thread fixes.
+	 */
+	thr = heap->heap_thread;
+	DUK_ASSERT(thr != NULL);
+
+	/* Prevent mark-and-sweep for the pending finalizers, also prevents
+	 * refzero handling from moving objects away from the heap_allocated
+	 * list.  (The flag meaning is slightly abused here.)
+	 */
+	DUK_ASSERT(!DUK_HEAP_HAS_MARKANDSWEEP_RUNNING(heap));
+	DUK_HEAP_SET_MARKANDSWEEP_RUNNING(heap);
+
+	curr_limit = 0;  /* suppress warning, not used */
+	for (round_no = 0; ; round_no++) {
+		curr = heap->heap_allocated;
+		count_all = 0;
+		count_finalized = 0;
+		while (curr) {
+			count_all++;
+			if (DUK_HEAPHDR_GET_TYPE(curr) == DUK_HTYPE_OBJECT) {
+				/* Only objects in heap_allocated may have finalizers.  Check that
+				 * the object itself has a _Finalizer property (own or inherited)
+				 * so that we don't execute finalizers for e.g. Proxy objects.
+				 */
+				DUK_ASSERT(thr != NULL);
+				DUK_ASSERT(curr != NULL);
+
+				if (duk_hobject_hasprop_raw(thr, (duk_hobject *) curr, DUK_HTHREAD_STRING_INT_FINALIZER(thr))) {
+					if (!DUK_HEAPHDR_HAS_FINALIZED((duk_heaphdr *) curr)) {
+						DUK_ASSERT(DUK_HEAP_HAS_FINALIZER_NORESCUE(heap));  /* maps to finalizer 2nd argument */
+						duk_hobject_run_finalizer(thr, (duk_hobject *) curr);
+						count_finalized++;
+					}
+				}
+			}
+			curr = DUK_HEAPHDR_GET_NEXT(heap, curr);
+		}
+
+		/* Each round of finalizer execution may spawn new finalizable objects
+		 * which is normal behavior for some applications.  Allow multiple
+		 * rounds of finalization, but use a shrinking limit based on the
+		 * first round to detect the case where a runaway finalizer creates
+		 * an unbounded amount of new finalizable objects.  Finalizer rescue
+		 * is not supported: the semantics are unclear because most of the
+		 * objects being finalized here are already reachable.  The finalizer
+		 * is given a boolean to indicate that rescue is not possible.
+		 *
+		 * See discussion in: https://github.com/svaarala/duktape/pull/473
+		 */
+
+		if (round_no == 0) {
+			/* Cannot wrap: each object is at least 8 bytes so count is
+			 * at most 1/8 of that.
+			 */
+			curr_limit = count_all * 2;
+		} else {
+			curr_limit = (curr_limit * 3) / 4;   /* Decrease by 25% every round */
+		}
+		DUK_D(DUK_DPRINT("finalizer round %ld complete, %ld objects, tried to execute %ld finalizers, current limit is %ld",
+		                 (long) round_no, (long) count_all, (long) count_finalized, (long) curr_limit));
+
+		if (count_finalized == 0) {
+			DUK_D(DUK_DPRINT("no more finalizable objects, forced finalization finished"));
+			break;
+		}
+		if (count_finalized >= curr_limit) {
+			DUK_D(DUK_DPRINT("finalizer count above limit, potentially runaway finalizer; skip remaining finalizers"));
+			break;
+		}
+	}
+
+	DUK_ASSERT(DUK_HEAP_HAS_MARKANDSWEEP_RUNNING(heap));
+	DUK_HEAP_CLEAR_MARKANDSWEEP_RUNNING(heap);
+}
+
+DUK_INTERNAL void duk_heap_free(duk_heap *heap) {
+	DUK_D(DUK_DPRINT("free heap: %p", (void *) heap));
+
+#if defined(DUK_USE_DEBUG)
+	duk_heap_dump_strtab(heap);
+#endif
+
+#if defined(DUK_USE_DEBUGGER_SUPPORT)
+	/* Detach a debugger if attached (can be called multiple times)
+	 * safely.
+	 */
+	/* XXX: Add a flag to reject an attempt to re-attach?  Otherwise
+	 * the detached callback may immediately reattach.
+	 */
+	duk_debug_do_detach(heap);
+#endif
+
+	/* Execute finalizers before freeing the heap, even for reachable
+	 * objects, and regardless of whether or not mark-and-sweep is
+	 * enabled.  This gives finalizers the chance to free any native
+	 * resources like file handles, allocations made outside Duktape,
+	 * etc.  This is quite tricky to get right, so that all finalizer
+	 * guarantees are honored.
+	 *
+	 * XXX: this perhaps requires an execution time limit.
+	 */
+	DUK_D(DUK_DPRINT("execute finalizers before freeing heap"));
+#if defined(DUK_USE_MARK_AND_SWEEP)
+	/* Run mark-and-sweep a few times just in case (unreachable object
+	 * finalizers run already here).  The last round must rescue objects
+	 * from the previous round without running any more finalizers.  This
+	 * ensures rescued objects get their FINALIZED flag cleared so that
+	 * their finalizer is called once more in forced finalization to
+	 * satisfy finalizer guarantees.  However, we don't want to run any
+	 * more finalizer because that'd required one more loop, and so on.
+	 */
+	DUK_D(DUK_DPRINT("forced gc #1 in heap destruction"));
+	duk_heap_mark_and_sweep(heap, 0);
+	DUK_D(DUK_DPRINT("forced gc #2 in heap destruction"));
+	duk_heap_mark_and_sweep(heap, 0);
+	DUK_D(DUK_DPRINT("forced gc #3 in heap destruction (don't run finalizers)"));
+	duk_heap_mark_and_sweep(heap, DUK_MS_FLAG_SKIP_FINALIZERS);  /* skip finalizers; queue finalizable objects to heap_allocated */
+#endif
+
+	DUK_HEAP_SET_FINALIZER_NORESCUE(heap);  /* rescue no longer supported */
+	duk__free_run_finalizers(heap);
+
+	/* Note: heap->heap_thread, heap->curr_thread, and heap->heap_object
+	 * are on the heap allocated list.
+	 */
+
+	DUK_D(DUK_DPRINT("freeing heap objects of heap: %p", (void *) heap));
+	duk__free_allocated(heap);
+
+#if defined(DUK_USE_REFERENCE_COUNTING)
+	DUK_D(DUK_DPRINT("freeing refzero list of heap: %p", (void *) heap));
+	duk__free_refzero_list(heap);
+#endif
+
+#if defined(DUK_USE_MARK_AND_SWEEP)
+	DUK_D(DUK_DPRINT("freeing mark-and-sweep finalize list of heap: %p", (void *) heap));
+	duk__free_markandsweep_finalize_list(heap);
+#endif
+
+	DUK_D(DUK_DPRINT("freeing string table of heap: %p", (void *) heap));
+	duk__free_stringtable(heap);
+
+	DUK_D(DUK_DPRINT("freeing heap structure: %p", (void *) heap));
+	heap->free_func(heap->heap_udata, heap);
+}
+
+/*
+ *  Allocate a heap.
+ *
+ *  String table is initialized with built-in strings from genbuiltins.py,
+ *  either by dynamically creating the strings or by referring to ROM strings.
+ */
+
+#if defined(DUK_USE_ROM_STRINGS)
+DUK_LOCAL duk_bool_t duk__init_heap_strings(duk_heap *heap) {
+#if defined(DUK_USE_ASSERTIONS)
+	duk_small_uint_t i;
+#endif
+
+	/* With ROM-based strings, heap->strs[] and thr->strs[] are omitted
+	 * so nothing to initialize for strs[].
+	 */
+
+#if defined(DUK_USE_ASSERTIONS)
+	for (i = 0; i < sizeof(duk_rom_strings) / sizeof(const duk_hstring *); i++) {
+		duk_uint32_t hash;
+		const duk_hstring *h;
+		h = duk_rom_strings[i];
+		DUK_ASSERT(h != NULL);
+		hash = duk_heap_hashstring(heap, (const duk_uint8_t *) DUK_HSTRING_GET_DATA(h), DUK_HSTRING_GET_BYTELEN(h));
+		DUK_DD(DUK_DDPRINT("duk_rom_strings[%d] -> hash 0x%08lx, computed 0x%08lx",
+		                   (int) i, (unsigned long) DUK_HSTRING_GET_HASH(h), (unsigned long) hash));
+		DUK_ASSERT(hash == (duk_uint32_t) DUK_HSTRING_GET_HASH(h));
+	}
+#endif
+	return 1;
+}
+#else  /* DUK_USE_ROM_STRINGS */
+DUK_LOCAL duk_bool_t duk__init_heap_strings(duk_heap *heap) {
+	duk_bitdecoder_ctx bd_ctx;
+	duk_bitdecoder_ctx *bd = &bd_ctx;  /* convenience */
+	duk_small_uint_t i, j;
+
+	DUK_MEMZERO(&bd_ctx, sizeof(bd_ctx));
+	bd->data = (const duk_uint8_t *) duk_strings_data;
+	bd->length = (duk_size_t) DUK_STRDATA_DATA_LENGTH;
+
+	for (i = 0; i < DUK_HEAP_NUM_STRINGS; i++) {
+		duk_uint8_t tmp[DUK_STRDATA_MAX_STRLEN];
+		duk_hstring *h;
+		duk_small_uint_t len;
+		duk_small_uint_t mode;
+		duk_small_uint_t t;
+
+		len = duk_bd_decode(bd, 5);
+		mode = 32;  /* 0 = uppercase, 32 = lowercase (= 'a' - 'A') */
+		for (j = 0; j < len; j++) {
+			t = duk_bd_decode(bd, 5);
+			if (t < DUK__BITPACK_LETTER_LIMIT) {
+				t = t + DUK_ASC_UC_A + mode;
+			} else if (t == DUK__BITPACK_UNDERSCORE) {
+				t = DUK_ASC_UNDERSCORE;
+			} else if (t == DUK__BITPACK_FF) {
+				/* Internal keys are prefixed with 0xFF in the stringtable
+				 * (which makes them invalid UTF-8 on purpose).
+				 */
+				t = 0xff;
+			} else if (t == DUK__BITPACK_SWITCH1) {
+				t = duk_bd_decode(bd, 5);
+				DUK_ASSERT_DISABLE(t >= 0);  /* unsigned */
+				DUK_ASSERT(t <= 25);
+				t = t + DUK_ASC_UC_A + (mode ^ 32);
+			} else if (t == DUK__BITPACK_SWITCH) {
+				mode = mode ^ 32;
+				t = duk_bd_decode(bd, 5);
+				DUK_ASSERT_DISABLE(t >= 0);
+				DUK_ASSERT(t <= 25);
+				t = t + DUK_ASC_UC_A + mode;
+			} else if (t == DUK__BITPACK_SEVENBIT) {
+				t = duk_bd_decode(bd, 7);
+			}
+			tmp[j] = (duk_uint8_t) t;
+		}
+
+		/* No need to length check string: it will never exceed even
+		 * the 16-bit length maximum.
+		 */
+		DUK_ASSERT(len <= 0xffffUL);
+		DUK_DDD(DUK_DDDPRINT("intern built-in string %ld", (long) i));
+		h = duk_heap_string_intern(heap, tmp, len);
+		if (!h) {
+			goto error;
+		}
+		DUK_ASSERT(!DUK_HEAPHDR_HAS_READONLY((duk_heaphdr *) h));
+
+		/* Special flags checks.  Since these strings are always
+		 * reachable and a string cannot appear twice in the string
+		 * table, there's no need to check/set these flags elsewhere.
+		 * The 'internal' flag is set by string intern code.
+		 */
+		if (i == DUK_STRIDX_EVAL || i == DUK_STRIDX_LC_ARGUMENTS) {
+			DUK_HSTRING_SET_EVAL_OR_ARGUMENTS(h);
+		}
+		if (i >= DUK_STRIDX_START_RESERVED && i < DUK_STRIDX_END_RESERVED) {
+			DUK_HSTRING_SET_RESERVED_WORD(h);
+			if (i >= DUK_STRIDX_START_STRICT_RESERVED) {
+				DUK_HSTRING_SET_STRICT_RESERVED_WORD(h);
+			}
+		}
+
+		DUK_DDD(DUK_DDDPRINT("interned: %!O", (duk_heaphdr *) h));
+
+		/* XXX: The incref macro takes a thread pointer but doesn't
+		 * use it right now.
+		 */
+		DUK_HSTRING_INCREF(_never_referenced_, h);
+
+#if defined(DUK_USE_HEAPPTR16)
+		heap->strs16[i] = DUK_USE_HEAPPTR_ENC16(heap->heap_udata, (void *) h);
+#else
+		heap->strs[i] = h;
+#endif
+	}
+
+	return 1;
+
+ error:
+	return 0;
+}
+#endif  /* DUK_USE_ROM_STRINGS */
+
+DUK_LOCAL duk_bool_t duk__init_heap_thread(duk_heap *heap) {
+	duk_hthread *thr;
+
+	DUK_DD(DUK_DDPRINT("heap init: alloc heap thread"));
+	thr = duk_hthread_alloc(heap,
+	                        DUK_HOBJECT_FLAG_EXTENSIBLE |
+	                        DUK_HOBJECT_FLAG_THREAD |
+	                        DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_THREAD));
+	if (!thr) {
+		DUK_D(DUK_DPRINT("failed to alloc heap_thread"));
+		return 0;
+	}
+	thr->state = DUK_HTHREAD_STATE_INACTIVE;
+#if defined(DUK_USE_ROM_STRINGS)
+	/* No strs[] pointer. */
+#else  /* DUK_USE_ROM_STRINGS */
+#if defined(DUK_USE_HEAPPTR16)
+	thr->strs16 = heap->strs16;
+#else
+	thr->strs = heap->strs;
+#endif
+#endif  /* DUK_USE_ROM_STRINGS */
+
+	heap->heap_thread = thr;
+	DUK_HTHREAD_INCREF(thr, thr);  /* Note: first argument not really used */
+
+	/* 'thr' is now reachable */
+
+	if (!duk_hthread_init_stacks(heap, thr)) {
+		return 0;
+	}
+
+	/* XXX: this may now fail, and is not handled correctly */
+	duk_hthread_create_builtin_objects(thr);
+
+	/* default prototype (Note: 'thr' must be reachable) */
+	DUK_HOBJECT_SET_PROTOTYPE_UPDREF(thr, (duk_hobject *) thr, thr->builtins[DUK_BIDX_THREAD_PROTOTYPE]);
+
+	return 1;
+}
+
+#if defined(DUK_USE_DEBUG)
+#define DUK__DUMPSZ(t)  do { \
+		DUK_D(DUK_DPRINT("" #t "=%ld", (long) sizeof(t))); \
+	} while (0)
+
+/* These is not 100% because format would need to be non-portable "long long".
+ * Also print out as doubles to catch cases where the "long" type is not wide
+ * enough; the limits will then not be printed accurately but the magnitude
+ * will be correct.
+ */
+#define DUK__DUMPLM_SIGNED_RAW(t,a,b)  do { \
+		DUK_D(DUK_DPRINT(t "=[%ld,%ld]=[%lf,%lf]", \
+		                 (long) (a), (long) (b), \
+		                 (double) (a), (double) (b))); \
+	} while (0)
+#define DUK__DUMPLM_UNSIGNED_RAW(t,a,b)  do { \
+		DUK_D(DUK_DPRINT(t "=[%lu,%lu]=[%lf,%lf]", \
+		                 (unsigned long) (a), (unsigned long) (b), \
+		                 (double) (a), (double) (b))); \
+	} while (0)
+#define DUK__DUMPLM_SIGNED(t)  do { \
+		DUK__DUMPLM_SIGNED_RAW("DUK_" #t "_{MIN,MAX}", DUK_##t##_MIN, DUK_##t##_MAX); \
+	} while (0)
+#define DUK__DUMPLM_UNSIGNED(t)  do { \
+		DUK__DUMPLM_UNSIGNED_RAW("DUK_" #t "_{MIN,MAX}", DUK_##t##_MIN, DUK_##t##_MAX); \
+	} while (0)
+
+DUK_LOCAL void duk__dump_type_sizes(void) {
+	DUK_D(DUK_DPRINT("sizeof()"));
+
+	/* basic platform types */
+	DUK__DUMPSZ(char);
+	DUK__DUMPSZ(short);
+	DUK__DUMPSZ(int);
+	DUK__DUMPSZ(long);
+	DUK__DUMPSZ(double);
+	DUK__DUMPSZ(void *);
+	DUK__DUMPSZ(size_t);
+
+	/* basic types from duk_features.h */
+	DUK__DUMPSZ(duk_uint8_t);
+	DUK__DUMPSZ(duk_int8_t);
+	DUK__DUMPSZ(duk_uint16_t);
+	DUK__DUMPSZ(duk_int16_t);
+	DUK__DUMPSZ(duk_uint32_t);
+	DUK__DUMPSZ(duk_int32_t);
+	DUK__DUMPSZ(duk_uint64_t);
+	DUK__DUMPSZ(duk_int64_t);
+	DUK__DUMPSZ(duk_uint_least8_t);
+	DUK__DUMPSZ(duk_int_least8_t);
+	DUK__DUMPSZ(duk_uint_least16_t);
+	DUK__DUMPSZ(duk_int_least16_t);
+	DUK__DUMPSZ(duk_uint_least32_t);
+	DUK__DUMPSZ(duk_int_least32_t);
+#if defined(DUK_USE_64BIT_OPS)
+	DUK__DUMPSZ(duk_uint_least64_t);
+	DUK__DUMPSZ(duk_int_least64_t);
+#endif
+	DUK__DUMPSZ(duk_uint_fast8_t);
+	DUK__DUMPSZ(duk_int_fast8_t);
+	DUK__DUMPSZ(duk_uint_fast16_t);
+	DUK__DUMPSZ(duk_int_fast16_t);
+	DUK__DUMPSZ(duk_uint_fast32_t);
+	DUK__DUMPSZ(duk_int_fast32_t);
+#if defined(DUK_USE_64BIT_OPS)
+	DUK__DUMPSZ(duk_uint_fast64_t);
+	DUK__DUMPSZ(duk_int_fast64_t);
+#endif
+	DUK__DUMPSZ(duk_uintptr_t);
+	DUK__DUMPSZ(duk_intptr_t);
+	DUK__DUMPSZ(duk_uintmax_t);
+	DUK__DUMPSZ(duk_intmax_t);
+	DUK__DUMPSZ(duk_double_t);
+
+	/* important chosen base types */
+	DUK__DUMPSZ(duk_int_t);
+	DUK__DUMPSZ(duk_uint_t);
+	DUK__DUMPSZ(duk_int_fast_t);
+	DUK__DUMPSZ(duk_uint_fast_t);
+	DUK__DUMPSZ(duk_small_int_t);
+	DUK__DUMPSZ(duk_small_uint_t);
+	DUK__DUMPSZ(duk_small_int_fast_t);
+	DUK__DUMPSZ(duk_small_uint_fast_t);
+
+	/* some derived types */
+	DUK__DUMPSZ(duk_codepoint_t);
+	DUK__DUMPSZ(duk_ucodepoint_t);
+	DUK__DUMPSZ(duk_idx_t);
+	DUK__DUMPSZ(duk_errcode_t);
+	DUK__DUMPSZ(duk_uarridx_t);
+
+	/* tval */
+	DUK__DUMPSZ(duk_double_union);
+	DUK__DUMPSZ(duk_tval);
+
+	/* structs from duk_forwdecl.h */
+	DUK__DUMPSZ(duk_jmpbuf);  /* just one 'int' for C++ exceptions */
+	DUK__DUMPSZ(duk_heaphdr);
+	DUK__DUMPSZ(duk_heaphdr_string);
+	DUK__DUMPSZ(duk_hstring);
+	DUK__DUMPSZ(duk_hstring_external);
+	DUK__DUMPSZ(duk_hobject);
+	DUK__DUMPSZ(duk_hcompiledfunction);
+	DUK__DUMPSZ(duk_hnativefunction);
+	DUK__DUMPSZ(duk_hthread);
+	DUK__DUMPSZ(duk_hbuffer);
+	DUK__DUMPSZ(duk_hbuffer_fixed);
+	DUK__DUMPSZ(duk_hbuffer_dynamic);
+	DUK__DUMPSZ(duk_hbuffer_external);
+	DUK__DUMPSZ(duk_propaccessor);
+	DUK__DUMPSZ(duk_propvalue);
+	DUK__DUMPSZ(duk_propdesc);
+	DUK__DUMPSZ(duk_heap);
+#if defined(DUK_USE_STRTAB_CHAIN)
+	DUK__DUMPSZ(duk_strtab_entry);
+#endif
+	DUK__DUMPSZ(duk_activation);
+	DUK__DUMPSZ(duk_catcher);
+	DUK__DUMPSZ(duk_strcache);
+	DUK__DUMPSZ(duk_ljstate);
+	DUK__DUMPSZ(duk_fixedbuffer);
+	DUK__DUMPSZ(duk_bitdecoder_ctx);
+	DUK__DUMPSZ(duk_bitencoder_ctx);
+	DUK__DUMPSZ(duk_token);
+	DUK__DUMPSZ(duk_re_token);
+	DUK__DUMPSZ(duk_lexer_point);
+	DUK__DUMPSZ(duk_lexer_ctx);
+	DUK__DUMPSZ(duk_compiler_instr);
+	DUK__DUMPSZ(duk_compiler_func);
+	DUK__DUMPSZ(duk_compiler_ctx);
+	DUK__DUMPSZ(duk_re_matcher_ctx);
+	DUK__DUMPSZ(duk_re_compiler_ctx);
+}
+DUK_LOCAL void duk__dump_type_limits(void) {
+	DUK_D(DUK_DPRINT("limits"));
+
+	/* basic types */
+	DUK__DUMPLM_SIGNED(INT8);
+	DUK__DUMPLM_UNSIGNED(UINT8);
+	DUK__DUMPLM_SIGNED(INT_FAST8);
+	DUK__DUMPLM_UNSIGNED(UINT_FAST8);
+	DUK__DUMPLM_SIGNED(INT_LEAST8);
+	DUK__DUMPLM_UNSIGNED(UINT_LEAST8);
+	DUK__DUMPLM_SIGNED(INT16);
+	DUK__DUMPLM_UNSIGNED(UINT16);
+	DUK__DUMPLM_SIGNED(INT_FAST16);
+	DUK__DUMPLM_UNSIGNED(UINT_FAST16);
+	DUK__DUMPLM_SIGNED(INT_LEAST16);
+	DUK__DUMPLM_UNSIGNED(UINT_LEAST16);
+	DUK__DUMPLM_SIGNED(INT32);
+	DUK__DUMPLM_UNSIGNED(UINT32);
+	DUK__DUMPLM_SIGNED(INT_FAST32);
+	DUK__DUMPLM_UNSIGNED(UINT_FAST32);
+	DUK__DUMPLM_SIGNED(INT_LEAST32);
+	DUK__DUMPLM_UNSIGNED(UINT_LEAST32);
+#if defined(DUK_USE_64BIT_OPS)
+	DUK__DUMPLM_SIGNED(INT64);
+	DUK__DUMPLM_UNSIGNED(UINT64);
+	DUK__DUMPLM_SIGNED(INT_FAST64);
+	DUK__DUMPLM_UNSIGNED(UINT_FAST64);
+	DUK__DUMPLM_SIGNED(INT_LEAST64);
+	DUK__DUMPLM_UNSIGNED(UINT_LEAST64);
+#endif
+	DUK__DUMPLM_SIGNED(INTPTR);
+	DUK__DUMPLM_UNSIGNED(UINTPTR);
+	DUK__DUMPLM_SIGNED(INTMAX);
+	DUK__DUMPLM_UNSIGNED(UINTMAX);
+
+	/* derived types */
+	DUK__DUMPLM_SIGNED(INT);
+	DUK__DUMPLM_UNSIGNED(UINT);
+	DUK__DUMPLM_SIGNED(INT_FAST);
+	DUK__DUMPLM_UNSIGNED(UINT_FAST);
+	DUK__DUMPLM_SIGNED(SMALL_INT);
+	DUK__DUMPLM_UNSIGNED(SMALL_UINT);
+	DUK__DUMPLM_SIGNED(SMALL_INT_FAST);
+	DUK__DUMPLM_UNSIGNED(SMALL_UINT_FAST);
+}
+#undef DUK__DUMPSZ
+#undef DUK__DUMPLM_SIGNED_RAW
+#undef DUK__DUMPLM_UNSIGNED_RAW
+#undef DUK__DUMPLM_SIGNED
+#undef DUK__DUMPLM_UNSIGNED
+
+DUK_LOCAL void duk__dump_misc_options(void) {
+	DUK_D(DUK_DPRINT("DUK_VERSION: %ld", (long) DUK_VERSION));
+	DUK_D(DUK_DPRINT("DUK_GIT_DESCRIBE: %s", DUK_GIT_DESCRIBE));
+	DUK_D(DUK_DPRINT("OS string: %s", DUK_USE_OS_STRING));
+	DUK_D(DUK_DPRINT("architecture string: %s", DUK_USE_ARCH_STRING));
+	DUK_D(DUK_DPRINT("compiler string: %s", DUK_USE_COMPILER_STRING));
+#if defined(DUK_USE_PACKED_TVAL)
+	DUK_D(DUK_DPRINT("DUK_USE_PACKED_TVAL: yes"));
+#else
+	DUK_D(DUK_DPRINT("DUK_USE_PACKED_TVAL: no"));
+#endif
+#if defined(DUK_USE_VARIADIC_MACROS)
+	DUK_D(DUK_DPRINT("DUK_USE_VARIADIC_MACROS: yes"));
+#else
+	DUK_D(DUK_DPRINT("DUK_USE_VARIADIC_MACROS: no"));
+#endif
+#if defined(DUK_USE_INTEGER_LE)
+	DUK_D(DUK_DPRINT("integer endianness: little"));
+#elif defined(DUK_USE_INTEGER_ME)
+	DUK_D(DUK_DPRINT("integer endianness: mixed"));
+#elif defined(DUK_USE_INTEGER_BE)
+	DUK_D(DUK_DPRINT("integer endianness: big"));
+#else
+	DUK_D(DUK_DPRINT("integer endianness: ???"));
+#endif
+#if defined(DUK_USE_DOUBLE_LE)
+	DUK_D(DUK_DPRINT("IEEE double endianness: little"));
+#elif defined(DUK_USE_DOUBLE_ME)
+	DUK_D(DUK_DPRINT("IEEE double endianness: mixed"));
+#elif defined(DUK_USE_DOUBLE_BE)
+	DUK_D(DUK_DPRINT("IEEE double endianness: big"));
+#else
+	DUK_D(DUK_DPRINT("IEEE double endianness: ???"));
+#endif
+}
+#endif  /* DUK_USE_DEBUG */
+
+DUK_INTERNAL
+duk_heap *duk_heap_alloc(duk_alloc_function alloc_func,
+                         duk_realloc_function realloc_func,
+                         duk_free_function free_func,
+                         void *heap_udata,
+                         duk_fatal_function fatal_func) {
+	duk_heap *res = NULL;
+
+	/* Silence a few global unused warnings here. */
+	DUK_UNREF(duk_str_unsupported);
+
+	DUK_D(DUK_DPRINT("allocate heap"));
+
+	/*
+	 *  Debug dump type sizes
+	 */
+
+#if defined(DUK_USE_DEBUG)
+	duk__dump_misc_options();
+	duk__dump_type_sizes();
+	duk__dump_type_limits();
+#endif
+
+	/*
+	 *  If selftests enabled, run them as early as possible
+	 */
+#if defined(DUK_USE_SELF_TESTS)
+	DUK_D(DUK_DPRINT("running self tests"));
+	duk_selftest_run_tests();
+	DUK_D(DUK_DPRINT("self tests passed"));
+#endif
+
+	/*
+	 *  Computed values (e.g. INFINITY)
+	 */
+
+#if defined(DUK_USE_COMPUTED_NAN)
+	do {
+		/* Workaround for some exotic platforms where NAN is missing
+		 * and the expression (0.0 / 0.0) does NOT result in a NaN.
+		 * Such platforms use the global 'duk_computed_nan' which must
+		 * be initialized at runtime.  Use 'volatile' to ensure that
+		 * the compiler will actually do the computation and not try
+		 * to do constant folding which might result in the original
+		 * problem.
+		 */
+		volatile double dbl1 = 0.0;
+		volatile double dbl2 = 0.0;
+		duk_computed_nan = dbl1 / dbl2;
+	} while (0);
+#endif
+
+#if defined(DUK_USE_COMPUTED_INFINITY)
+	do {
+		/* Similar workaround for INFINITY. */
+		volatile double dbl1 = 1.0;
+		volatile double dbl2 = 0.0;
+		duk_computed_infinity = dbl1 / dbl2;
+	} while (0);
+#endif
+
+	/*
+	 *  Allocate heap struct
+	 *
+	 *  Use a raw call, all macros expect the heap to be initialized
+	 */
+
+	res = (duk_heap *) alloc_func(heap_udata, sizeof(duk_heap));
+	if (!res) {
+		goto error;
+	}
+
+	/*
+	 *  Zero the struct, and start initializing roughly in order
+	 */
+
+	DUK_MEMZERO(res, sizeof(*res));
+
+	/* explicit NULL inits */
+#if defined(DUK_USE_EXPLICIT_NULL_INIT)
+	res->heap_udata = NULL;
+	res->heap_allocated = NULL;
+#if defined(DUK_USE_REFERENCE_COUNTING)
+	res->refzero_list = NULL;
+	res->refzero_list_tail = NULL;
+#endif
+#if defined(DUK_USE_MARK_AND_SWEEP)
+	res->finalize_list = NULL;
+#endif
+	res->heap_thread = NULL;
+	res->curr_thread = NULL;
+	res->heap_object = NULL;
+#if defined(DUK_USE_STRTAB_CHAIN)
+	/* nothing to NULL */
+#elif defined(DUK_USE_STRTAB_PROBE)
+#if defined(DUK_USE_HEAPPTR16)
+	res->strtable16 = (duk_uint16_t *) NULL;
+#else
+	res->strtable = (duk_hstring **) NULL;
+#endif
+#endif
+#if defined(DUK_USE_ROM_STRINGS)
+	/* no res->strs[] */
+#else  /* DUK_USE_ROM_STRINGS */
+#if defined(DUK_USE_HEAPPTR16)
+	/* res->strs16[] is zeroed and zero decodes to NULL, so no NULL inits. */
+#else
+	{
+		duk_small_uint_t i;
+	        for (i = 0; i < DUK_HEAP_NUM_STRINGS; i++) {
+			res->strs[i] = NULL;
+	        }
+	}
+#endif
+#endif  /* DUK_USE_ROM_STRINGS */
+#if defined(DUK_USE_DEBUGGER_SUPPORT)
+	res->dbg_read_cb = NULL;
+	res->dbg_write_cb = NULL;
+	res->dbg_peek_cb = NULL;
+	res->dbg_read_flush_cb = NULL;
+	res->dbg_write_flush_cb = NULL;
+	res->dbg_request_cb = NULL;
+	res->dbg_udata = NULL;
+	res->dbg_step_thread = NULL;
+#endif
+#endif  /* DUK_USE_EXPLICIT_NULL_INIT */
+
+	res->alloc_func = alloc_func;
+	res->realloc_func = realloc_func;
+	res->free_func = free_func;
+	res->heap_udata = heap_udata;
+	res->fatal_func = fatal_func;
+
+#if defined(DUK_USE_HEAPPTR16)
+	/* XXX: zero assumption */
+	res->heapptr_null16 = DUK_USE_HEAPPTR_ENC16(res->heap_udata, (void *) NULL);
+	res->heapptr_deleted16 = DUK_USE_HEAPPTR_ENC16(res->heap_udata, (void *) DUK_STRTAB_DELETED_MARKER(res));
+#endif
+
+	/* res->mark_and_sweep_trigger_counter == 0 -> now causes immediate GC; which is OK */
+
+	res->call_recursion_depth = 0;
+	res->call_recursion_limit = DUK_USE_NATIVE_CALL_RECLIMIT;
+
+	/* XXX: use the pointer as a seed for now: mix in time at least */
+
+	/* The casts through duk_intr_pt is to avoid the following GCC warning:
+	 *
+	 *   warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
+	 *
+	 * This still generates a /Wp64 warning on VS2010 when compiling for x86.
+	 */
+#if defined(DUK_USE_ROM_STRINGS)
+	/* XXX: make a common DUK_USE_ option, and allow custom fixed seed? */
+	DUK_D(DUK_DPRINT("using rom strings, force heap hash_seed to fixed value 0x%08lx", (long) DUK__FIXED_HASH_SEED));
+	res->hash_seed = (duk_uint32_t) DUK__FIXED_HASH_SEED;
+#else  /* DUK_USE_ROM_STRINGS */
+	res->hash_seed = (duk_uint32_t) (duk_intptr_t) res;
+	res->rnd_state = (duk_uint32_t) (duk_intptr_t) res;
+#if !defined(DUK_USE_STRHASH_DENSE)
+	res->hash_seed ^= 5381;  /* Bernstein hash init value is normally 5381; XOR it in in case pointer low bits are 0 */
+#endif
+#endif  /* DUK_USE_ROM_STRINGS */
+
+#if defined(DUK_USE_EXPLICIT_NULL_INIT)
+	res->lj.jmpbuf_ptr = NULL;
+#endif
+	DUK_ASSERT(res->lj.type == DUK_LJ_TYPE_UNKNOWN);  /* zero */
+
+	DUK_TVAL_SET_UNDEFINED(&res->lj.value1);
+	DUK_TVAL_SET_UNDEFINED(&res->lj.value2);
+
+#if (DUK_STRTAB_INITIAL_SIZE < DUK_UTIL_MIN_HASH_PRIME)
+#error initial heap stringtable size is defined incorrectly
+#endif
+
+	/*
+	 *  Init stringtable: fixed variant
+	 */
+
+#if defined(DUK_USE_STRTAB_CHAIN)
+	DUK_MEMZERO(res->strtable, sizeof(duk_strtab_entry) * DUK_STRTAB_CHAIN_SIZE);
+#if defined(DUK_USE_EXPLICIT_NULL_INIT)
+	{
+		duk_small_uint_t i;
+	        for (i = 0; i < DUK_STRTAB_CHAIN_SIZE; i++) {
+#if defined(DUK_USE_HEAPPTR16)
+			res->strtable[i].u.str16 = res->heapptr_null16;
+#else
+			res->strtable[i].u.str = NULL;
+#endif
+	        }
+	}
+#endif  /* DUK_USE_EXPLICIT_NULL_INIT */
+#endif  /* DUK_USE_STRTAB_CHAIN */
+
+	/*
+	 *  Init stringtable: probe variant
+	 */
+
+#if defined(DUK_USE_STRTAB_PROBE)
+#if defined(DUK_USE_HEAPPTR16)
+	res->strtable16 = (duk_uint16_t *) alloc_func(heap_udata, sizeof(duk_uint16_t) * DUK_STRTAB_INITIAL_SIZE);
+	if (!res->strtable16) {
+		goto error;
+	}
+#else  /* DUK_USE_HEAPPTR16 */
+	res->strtable = (duk_hstring **) alloc_func(heap_udata, sizeof(duk_hstring *) * DUK_STRTAB_INITIAL_SIZE);
+	if (!res->strtable) {
+		goto error;
+	}
+#endif  /* DUK_USE_HEAPPTR16 */
+	res->st_size = DUK_STRTAB_INITIAL_SIZE;
+#if defined(DUK_USE_EXPLICIT_NULL_INIT)
+	{
+		duk_small_uint_t i;
+		DUK_ASSERT(res->st_size == DUK_STRTAB_INITIAL_SIZE);
+	        for (i = 0; i < DUK_STRTAB_INITIAL_SIZE; i++) {
+#if defined(DUK_USE_HEAPPTR16)
+			res->strtable16[i] = res->heapptr_null16;
+#else
+			res->strtable[i] = NULL;
+#endif
+	        }
+	}
+#else  /* DUK_USE_EXPLICIT_NULL_INIT */
+#if defined(DUK_USE_HEAPPTR16)
+	DUK_MEMZERO(res->strtable16, sizeof(duk_uint16_t) * DUK_STRTAB_INITIAL_SIZE);
+#else
+	DUK_MEMZERO(res->strtable, sizeof(duk_hstring *) * DUK_STRTAB_INITIAL_SIZE);
+#endif
+#endif  /* DUK_USE_EXPLICIT_NULL_INIT */
+#endif  /* DUK_USE_STRTAB_PROBE */
+
+	/*
+	 *  Init stringcache
+	 */
+
+#if defined(DUK_USE_EXPLICIT_NULL_INIT)
+	{
+		duk_small_uint_t i;
+		for (i = 0; i < DUK_HEAP_STRCACHE_SIZE; i++) {
+			res->strcache[i].h = NULL;
+		}
+	}
+#endif
+
+	/* XXX: error handling is incomplete.  It would be cleanest if
+	 * there was a setjmp catchpoint, so that all init code could
+	 * freely throw errors.  If that were the case, the return code
+	 * passing here could be removed.
+	 */
+
+	/*
+	 *  Init built-in strings
+	 */
+
+	DUK_DD(DUK_DDPRINT("HEAP: INIT STRINGS"));
+	if (!duk__init_heap_strings(res)) {
+		goto error;
+	}
+
+	/*
+	 *  Init the heap thread
+	 */
+
+	DUK_DD(DUK_DDPRINT("HEAP: INIT HEAP THREAD"));
+	if (!duk__init_heap_thread(res)) {
+		goto error;
+	}
+
+	/*
+	 *  Init the heap object
+	 */
+
+	DUK_DD(DUK_DDPRINT("HEAP: INIT HEAP OBJECT"));
+	DUK_ASSERT(res->heap_thread != NULL);
+	res->heap_object = duk_hobject_alloc(res, DUK_HOBJECT_FLAG_EXTENSIBLE |
+	                                          DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJECT));
+	if (!res->heap_object) {
+		goto error;
+	}
+	DUK_HOBJECT_INCREF(res->heap_thread, res->heap_object);
+
+	/*
+	 *  All done
+	 */
+
+	DUK_D(DUK_DPRINT("allocated heap: %p", (void *) res));
+	return res;
+
+ error:
+	DUK_D(DUK_DPRINT("heap allocation failed"));
+
+	if (res) {
+		/* assumes that allocated pointers and alloc funcs are valid
+		 * if res exists
+		 */
+		DUK_ASSERT(res->alloc_func != NULL);
+		DUK_ASSERT(res->realloc_func != NULL);
+		DUK_ASSERT(res->free_func != NULL);
+		duk_heap_free(res);
+	}
+	return NULL;
+}
+
+#undef DUK__BITPACK_LETTER_LIMIT
+#undef DUK__BITPACK_UNDERSCORE
+#undef DUK__BITPACK_FF
+#undef DUK__BITPACK_SWITCH1
+#undef DUK__BITPACK_SWITCH
+#undef DUK__BITPACK_SEVENBIT
+#undef DUK__FIXED_HASH_SEED


[05/51] [partial] nifi-minifi-cpp git commit: MINIFI-183 Added civet 1.9.1 sources Added onScheduled hook Added initial two-way TLS-enabled ListenHTTP implementation

Posted by al...@apache.org.
http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_debug.h
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_debug.h b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_debug.h
new file mode 100644
index 0000000..256d2dc
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_debug.h
@@ -0,0 +1,185 @@
+/*
+ *  Debugging macros, DUK_DPRINT() and its variants in particular.
+ *
+ *  DUK_DPRINT() allows formatted debug prints, and supports standard
+ *  and Duktape specific formatters.  See duk_debug_vsnprintf.c for details.
+ *
+ *  DUK_D(x), DUK_DD(x), and DUK_DDD(x) are used together with log macros
+ *  for technical reasons.  They are concretely used to hide 'x' from the
+ *  compiler when the corresponding log level is disabled.  This allows
+ *  clean builds on non-C99 compilers, at the cost of more verbose code.
+ *  Examples:
+ *
+ *    DUK_D(DUK_DPRINT("foo"));
+ *    DUK_DD(DUK_DDPRINT("foo"));
+ *    DUK_DDD(DUK_DDDPRINT("foo"));
+ *
+ *  This approach is preferable to the old "double parentheses" hack because
+ *  double parentheses make the C99 solution worse: __FILE__ and __LINE__ can
+ *  no longer be added transparently without going through globals, which
+ *  works poorly with threading.
+ */
+
+#ifndef DUK_DEBUG_H_INCLUDED
+#define DUK_DEBUG_H_INCLUDED
+
+#ifdef DUK_USE_DEBUG
+
+#if defined(DUK_USE_DPRINT)
+#define DUK_D(x) x
+#else
+#define DUK_D(x) do { } while (0) /* omit */
+#endif
+
+#if defined(DUK_USE_DDPRINT)
+#define DUK_DD(x) x
+#else
+#define DUK_DD(x) do { } while (0) /* omit */
+#endif
+
+#if defined(DUK_USE_DDDPRINT)
+#define DUK_DDD(x) x
+#else
+#define DUK_DDD(x) do { } while (0) /* omit */
+#endif
+
+/*
+ *  Exposed debug macros: debugging enabled
+ */
+
+#define DUK_LEVEL_DEBUG    1
+#define DUK_LEVEL_DDEBUG   2
+#define DUK_LEVEL_DDDEBUG  3
+
+#ifdef DUK_USE_VARIADIC_MACROS
+
+/* Note: combining __FILE__, __LINE__, and __func__ into fmt would be
+ * possible compile time, but waste some space with shared function names.
+ */
+#define DUK__DEBUG_LOG(lev,...)  duk_debug_log((duk_small_int_t) (lev), DUK_FILE_MACRO, (duk_int_t) DUK_LINE_MACRO, DUK_FUNC_MACRO, __VA_ARGS__);
+
+#define DUK_DPRINT(...)          DUK__DEBUG_LOG(DUK_LEVEL_DEBUG, __VA_ARGS__)
+
+#ifdef DUK_USE_DDPRINT
+#define DUK_DDPRINT(...)         DUK__DEBUG_LOG(DUK_LEVEL_DDEBUG, __VA_ARGS__)
+#else
+#define DUK_DDPRINT(...)
+#endif
+
+#ifdef DUK_USE_DDDPRINT
+#define DUK_DDDPRINT(...)        DUK__DEBUG_LOG(DUK_LEVEL_DDDEBUG, __VA_ARGS__)
+#else
+#define DUK_DDDPRINT(...)
+#endif
+
+#else  /* DUK_USE_VARIADIC_MACROS */
+
+#define DUK__DEBUG_STASH(lev)    \
+	(void) DUK_SNPRINTF(duk_debug_file_stash, DUK_DEBUG_STASH_SIZE, "%s", (const char *) DUK_FILE_MACRO), \
+	duk_debug_file_stash[DUK_DEBUG_STASH_SIZE - 1] = (char) 0; \
+	(void) DUK_SNPRINTF(duk_debug_line_stash, DUK_DEBUG_STASH_SIZE, "%ld", (long) DUK_LINE_MACRO), \
+	duk_debug_line_stash[DUK_DEBUG_STASH_SIZE - 1] = (char) 0; \
+	(void) DUK_SNPRINTF(duk_debug_func_stash, DUK_DEBUG_STASH_SIZE, "%s", (const char *) DUK_FUNC_MACRO), \
+	duk_debug_func_stash[DUK_DEBUG_STASH_SIZE - 1] = (char) 0; \
+	(void) (duk_debug_level_stash = (lev))
+
+/* Without variadic macros resort to comma expression trickery to handle debug
+ * prints.  This generates a lot of harmless warnings.  These hacks are not
+ * needed normally because DUK_D() and friends will hide the entire debug log
+ * statement from the compiler.
+ */
+
+#ifdef DUK_USE_DPRINT
+#define DUK_DPRINT  DUK__DEBUG_STASH(DUK_LEVEL_DEBUG), (void) duk_debug_log  /* args go here in parens */
+#else
+#define DUK_DPRINT  0 && /* args go here as a comma expression in parens */
+#endif
+
+#ifdef DUK_USE_DDPRINT
+#define DUK_DDPRINT  DUK__DEBUG_STASH(DUK_LEVEL_DDEBUG), (void) duk_debug_log  /* args go here in parens */
+#else
+#define DUK_DDPRINT  0 && /* args */
+#endif
+
+#ifdef DUK_USE_DDDPRINT
+#define DUK_DDDPRINT  DUK__DEBUG_STASH(DUK_LEVEL_DDDEBUG), (void) duk_debug_log  /* args go here in parens */
+#else
+#define DUK_DDDPRINT  0 && /* args */
+#endif
+
+#endif  /* DUK_USE_VARIADIC_MACROS */
+
+#else  /* DUK_USE_DEBUG */
+
+/*
+ *  Exposed debug macros: debugging disabled
+ */
+
+#define DUK_D(x) do { } while (0) /* omit */
+#define DUK_DD(x) do { } while (0) /* omit */
+#define DUK_DDD(x) do { } while (0) /* omit */
+
+#ifdef DUK_USE_VARIADIC_MACROS
+
+#define DUK_DPRINT(...)
+#define DUK_DDPRINT(...)
+#define DUK_DDDPRINT(...)
+
+#else  /* DUK_USE_VARIADIC_MACROS */
+
+#define DUK_DPRINT    0 && /* args go here as a comma expression in parens */
+#define DUK_DDPRINT   0 && /* args */
+#define DUK_DDDPRINT  0 && /* args */
+
+#endif  /* DUK_USE_VARIADIC_MACROS */
+
+#endif  /* DUK_USE_DEBUG */
+
+/*
+ *  Structs
+ */
+
+#ifdef DUK_USE_DEBUG
+struct duk_fixedbuffer {
+	duk_uint8_t *buffer;
+	duk_size_t length;
+	duk_size_t offset;
+	duk_bool_t truncated;
+};
+#endif
+
+/*
+ *  Prototypes
+ */
+
+#ifdef DUK_USE_DEBUG
+DUK_INTERNAL_DECL duk_int_t duk_debug_vsnprintf(char *str, duk_size_t size, const char *format, va_list ap);
+#if 0  /*unused*/
+DUK_INTERNAL_DECL duk_int_t duk_debug_snprintf(char *str, duk_size_t size, const char *format, ...);
+#endif
+DUK_INTERNAL_DECL void duk_debug_format_funcptr(char *buf, duk_size_t buf_size, duk_uint8_t *fptr, duk_size_t fptr_size);
+
+#ifdef DUK_USE_VARIADIC_MACROS
+DUK_INTERNAL_DECL void duk_debug_log(duk_small_int_t level, const char *file, duk_int_t line, const char *func, const char *fmt, ...);
+#else  /* DUK_USE_VARIADIC_MACROS */
+/* parameter passing, not thread safe */
+#define DUK_DEBUG_STASH_SIZE  128
+#if !defined(DUK_SINGLE_FILE)
+DUK_INTERNAL_DECL char duk_debug_file_stash[DUK_DEBUG_STASH_SIZE];
+DUK_INTERNAL_DECL char duk_debug_line_stash[DUK_DEBUG_STASH_SIZE];
+DUK_INTERNAL_DECL char duk_debug_func_stash[DUK_DEBUG_STASH_SIZE];
+DUK_INTERNAL_DECL duk_small_int_t duk_debug_level_stash;
+#endif
+DUK_INTERNAL_DECL void duk_debug_log(const char *fmt, ...);
+#endif  /* DUK_USE_VARIADIC_MACROS */
+
+DUK_INTERNAL_DECL void duk_fb_put_bytes(duk_fixedbuffer *fb, const duk_uint8_t *buffer, duk_size_t length);
+DUK_INTERNAL_DECL void duk_fb_put_byte(duk_fixedbuffer *fb, duk_uint8_t x);
+DUK_INTERNAL_DECL void duk_fb_put_cstring(duk_fixedbuffer *fb, const char *x);
+DUK_INTERNAL_DECL void duk_fb_sprintf(duk_fixedbuffer *fb, const char *fmt, ...);
+DUK_INTERNAL_DECL void duk_fb_put_funcptr(duk_fixedbuffer *fb, duk_uint8_t *fptr, duk_size_t fptr_size);
+DUK_INTERNAL_DECL duk_bool_t duk_fb_is_full(duk_fixedbuffer *fb);
+
+#endif  /* DUK_USE_DEBUG */
+
+#endif  /* DUK_DEBUG_H_INCLUDED */

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_debug_fixedbuffer.c
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_debug_fixedbuffer.c b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_debug_fixedbuffer.c
new file mode 100644
index 0000000..b8538af
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_debug_fixedbuffer.c
@@ -0,0 +1,69 @@
+/*
+ *  Fixed buffer helper useful for debugging, requires no allocation
+ *  which is critical for debugging.
+ */
+
+#include "duk_internal.h"
+
+#ifdef DUK_USE_DEBUG
+
+DUK_INTERNAL void duk_fb_put_bytes(duk_fixedbuffer *fb, const duk_uint8_t *buffer, duk_size_t length) {
+	duk_size_t avail;
+	duk_size_t copylen;
+
+	avail = (fb->offset >= fb->length ? (duk_size_t) 0 : (duk_size_t) (fb->length - fb->offset));
+	if (length > avail) {
+		copylen = avail;
+		fb->truncated = 1;
+	} else {
+		copylen = length;
+	}
+	DUK_MEMCPY(fb->buffer + fb->offset, buffer, copylen);
+	fb->offset += copylen;
+}
+
+DUK_INTERNAL void duk_fb_put_byte(duk_fixedbuffer *fb, duk_uint8_t x) {
+	duk_fb_put_bytes(fb, (const duk_uint8_t *) &x, 1);
+}
+
+DUK_INTERNAL void duk_fb_put_cstring(duk_fixedbuffer *fb, const char *x) {
+	duk_fb_put_bytes(fb, (const duk_uint8_t *) x, (duk_size_t) DUK_STRLEN(x));
+}
+
+DUK_INTERNAL void duk_fb_sprintf(duk_fixedbuffer *fb, const char *fmt, ...) {
+	duk_size_t avail;
+	va_list ap;
+
+	va_start(ap, fmt);
+	avail = (fb->offset >= fb->length ? (duk_size_t) 0 : (duk_size_t) (fb->length - fb->offset));
+	if (avail > 0) {
+		duk_int_t res = (duk_int_t) DUK_VSNPRINTF((char *) (fb->buffer + fb->offset), avail, fmt, ap);
+		if (res < 0) {
+			/* error */
+		} else if ((duk_size_t) res >= avail) {
+			/* (maybe) truncated */
+			fb->offset += avail;
+			if ((duk_size_t) res > avail) {
+				/* actual chars dropped (not just NUL term) */
+				fb->truncated = 1;
+			}
+		} else {
+			/* normal */
+			fb->offset += res;
+		}
+	}
+	va_end(ap);
+}
+
+DUK_INTERNAL void duk_fb_put_funcptr(duk_fixedbuffer *fb, duk_uint8_t *fptr, duk_size_t fptr_size) {
+	char buf[64+1];
+	duk_debug_format_funcptr(buf, sizeof(buf), fptr, fptr_size);
+	buf[sizeof(buf) - 1] = (char) 0;
+	duk_fb_put_cstring(fb, buf);
+}
+
+DUK_INTERNAL duk_bool_t duk_fb_is_full(duk_fixedbuffer *fb) {
+	return (fb->offset >= fb->length);
+}
+
+#endif  /* DUK_USE_DEBUG */

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_debug_heap.c
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_debug_heap.c b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_debug_heap.c
new file mode 100644
index 0000000..134e634
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_debug_heap.c
@@ -0,0 +1,247 @@
+/*
+ *  Debug dumping of duk_heap.
+ */
+
+#include "duk_internal.h"
+
+#ifdef DUK_USE_DEBUG
+
+#if 0  /*unused*/
+DUK_LOCAL void duk__sanitize_snippet(char *buf, duk_size_t buf_size, duk_hstring *str) {
+	duk_size_t i;
+	duk_size_t nchars;
+	duk_size_t maxchars;
+	duk_uint8_t *data;
+
+	DUK_MEMZERO(buf, buf_size);
+
+	maxchars = (duk_size_t) (buf_size - 1);
+	data = DUK_HSTRING_GET_DATA(str);
+	nchars = ((duk_size_t) str->blen < maxchars ? (duk_size_t) str->blen : maxchars);
+	for (i = 0; i < nchars; i++) {
+		duk_small_int_t c = (duk_small_int_t) data[i];
+		if (c < 0x20 || c > 0x7e) {
+			c = '.';
+		}
+		buf[i] = (char) c;
+	}
+}
+#endif
+
+#if 0
+DUK_LOCAL const char *duk__get_heap_type_string(duk_heaphdr *hdr) {
+	switch (DUK_HEAPHDR_GET_TYPE(hdr)) {
+	case DUK_HTYPE_STRING:
+		return "string";
+	case DUK_HTYPE_OBJECT:
+		return "object";
+	case DUK_HTYPE_BUFFER:
+		return "buffer";
+	default:
+		return "???";
+	}
+}
+#endif
+
+#if 0
+DUK_LOCAL void duk__dump_indented(duk_heaphdr *obj, int index) {
+	DUK_UNREF(obj);
+	DUK_UNREF(index);
+	DUK_UNREF(duk__get_heap_type_string);
+
+#ifdef DUK_USE_REFERENCE_COUNTING
+	DUK_D(DUK_DPRINT("  [%ld]: %p %s (flags: 0x%08lx, ref: %ld) -> %!O",
+	                 (long) index,
+	                 (void *) obj,
+	                 (const char *) duk__get_heap_type_string(obj),
+	                 (unsigned long) DUK_HEAPHDR_GET_FLAGS(obj),
+	                 (long) DUK_HEAPHDR_GET_REFCOUNT(obj),
+	                 (duk_heaphdr *) obj));
+#else
+	DUK_D(DUK_DPRINT("  [%ld]: %p %s (flags: 0x%08lx) -> %!O",
+	                 (long) index,
+	                 (void *) obj,
+	                 (const char *) duk__get_heap_type_string(obj),
+	                 (unsigned long) DUK_HEAPHDR_GET_FLAGS(obj),
+	                 (duk_heaphdr *) obj));
+#endif
+}
+#endif
+
+#if 0  /*unused*/
+DUK_LOCAL void duk__dump_heaphdr_list(duk_heap *heap, duk_heaphdr *root, const char *name) {
+	duk_int_t count;
+	duk_heaphdr *curr;
+
+	DUK_UNREF(heap);
+	DUK_UNREF(name);
+
+	count = 0;
+	curr = root;
+	while (curr) {
+		count++;
+		curr = DUK_HEAPHDR_GET_NEXT(curr);
+	}
+
+	DUK_D(DUK_DPRINT("%s, %ld objects", (const char *) name, (long) count));
+
+	count = 0;
+	curr = root;
+	while (curr) {
+		count++;
+		duk__dump_indented(curr, count);
+		curr = DUK_HEAPHDR_GET_NEXT(curr);
+	}
+}
+#endif
+
+#if 0  /*unused*/
+DUK_LOCAL void duk__dump_stringtable(duk_heap *heap) {
+	duk_uint_fast32_t i;
+	char buf[64+1];
+
+	DUK_D(DUK_DPRINT("stringtable %p, used %ld, size %ld, load %ld%%",
+	                 (void *) heap->strtable,
+	                 (long) heap->st_used,
+	                 (long) heap->st_size,
+	                 (long) (((double) heap->st_used) / ((double) heap->st_size) * 100.0)));
+
+	for (i = 0; i < (duk_uint_fast32_t) heap->st_size; i++) {
+		duk_hstring *e = heap->strtable[i];
+
+		if (!e) {
+			DUK_D(DUK_DPRINT("  [%ld]: NULL", (long) i));
+		} else if (e == DUK_STRTAB_DELETED_MARKER(heap)) {
+			DUK_D(DUK_DPRINT("  [%ld]: DELETED", (long) i));
+		} else {
+			duk__sanitize_snippet(buf, sizeof(buf), e);
+
+#ifdef DUK_USE_REFERENCE_COUNTING
+			DUK_D(DUK_DPRINT("  [%ld]: %p (flags: 0x%08lx, ref: %ld) '%s', strhash=0x%08lx, blen=%ld, clen=%ld, "
+			                 "arridx=%ld, internal=%ld, reserved_word=%ld, strict_reserved_word=%ld, eval_or_arguments=%ld",
+			                 (long) i,
+			                 (void *) e,
+			                 (unsigned long) DUK_HEAPHDR_GET_FLAGS((duk_heaphdr *) e),
+			                 (long) DUK_HEAPHDR_GET_REFCOUNT((duk_heaphdr *) e),
+			                 (const char *) buf,
+			                 (unsigned long) e->hash,
+			                 (long) e->blen,
+			                 (long) e->clen,
+			                 (long) (DUK_HSTRING_HAS_ARRIDX(e) ? 1 : 0),
+			                 (long) (DUK_HSTRING_HAS_INTERNAL(e) ? 1 : 0),
+			                 (long) (DUK_HSTRING_HAS_RESERVED_WORD(e) ? 1 : 0),
+			                 (long) (DUK_HSTRING_HAS_STRICT_RESERVED_WORD(e) ? 1 : 0),
+			                 (long) (DUK_HSTRING_HAS_EVAL_OR_ARGUMENTS(e) ? 1 : 0)));
+#else
+			DUK_D(DUK_DPRINT("  [%ld]: %p (flags: 0x%08lx) '%s', strhash=0x%08lx, blen=%ld, clen=%ld, "
+			                 "arridx=%ld, internal=%ld, reserved_word=%ld, strict_reserved_word=%ld, eval_or_arguments=%ld",
+			                 (long) i,
+			                 (void *) e,
+			                 (unsigned long) DUK_HEAPHDR_GET_FLAGS((duk_heaphdr *) e),
+			                 (const char *) buf,
+			                 (long) e->hash,
+			                 (long) e->blen,
+			                 (long) e->clen,
+			                 (long) (DUK_HSTRING_HAS_ARRIDX(e) ? 1 : 0),
+			                 (long) (DUK_HSTRING_HAS_INTERNAL(e) ? 1 : 0),
+			                 (long) (DUK_HSTRING_HAS_RESERVED_WORD(e) ? 1 : 0),
+			                 (long) (DUK_HSTRING_HAS_STRICT_RESERVED_WORD(e) ? 1 : 0),
+			                 (long) (DUK_HSTRING_HAS_EVAL_OR_ARGUMENTS(e) ? 1 : 0)));
+#endif
+		}
+	}
+}
+#endif
+
+#if 0  /*unused*/
+DUK_LOCAL void duk__dump_strcache(duk_heap *heap) {
+	duk_uint_fast32_t i;
+	char buf[64+1];
+
+	DUK_D(DUK_DPRINT("stringcache"));
+
+	for (i = 0; i < (duk_uint_fast32_t) DUK_HEAP_STRCACHE_SIZE; i++) {
+		duk_strcache *c = &heap->strcache[i];
+		if (!c->h) {
+			DUK_D(DUK_DPRINT("  [%ld]: bidx=%ld, cidx=%ld, str=NULL",
+			                 (long) i, (long) c->bidx, (long) c->cidx));
+		} else {
+			duk__sanitize_snippet(buf, sizeof(buf), c->h);
+			DUK_D(DUK_DPRINT("  [%ld]: bidx=%ld cidx=%ld str=%s",
+			                 (long) i, (long) c->bidx, (long) c->cidx, (const char *) buf));
+		}
+	}
+}
+#endif
+
+#if 0  /*unused*/
+DUK_INTERNAL void duk_debug_dump_heap(duk_heap *heap) {
+	char buf[64+1];
+
+	DUK_D(DUK_DPRINT("=== heap %p ===", (void *) heap));
+	DUK_D(DUK_DPRINT("  flags: 0x%08lx", (unsigned long) heap->flags));
+
+	/* Note: there is no standard formatter for function pointers */
+#ifdef DUK_USE_GCC_PRAGMAS
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-pedantic"
+#endif
+	duk_debug_format_funcptr(buf, sizeof(buf), (duk_uint8_t *) &heap->alloc_func, sizeof(heap->alloc_func));
+	DUK_D(DUK_DPRINT("  alloc_func: %s", (const char *) buf));
+	duk_debug_format_funcptr(buf, sizeof(buf), (duk_uint8_t *) &heap->realloc_func, sizeof(heap->realloc_func));
+	DUK_D(DUK_DPRINT("  realloc_func: %s", (const char *) buf));
+	duk_debug_format_funcptr(buf, sizeof(buf), (duk_uint8_t *) &heap->free_func, sizeof(heap->free_func));
+	DUK_D(DUK_DPRINT("  free_func: %s", (const char *) buf));
+	duk_debug_format_funcptr(buf, sizeof(buf), (duk_uint8_t *) &heap->fatal_func, sizeof(heap->fatal_func));
+	DUK_D(DUK_DPRINT("  fatal_func: %s", (const char *) buf));
+#ifdef DUK_USE_GCC_PRAGMAS
+#pragma GCC diagnostic pop
+#endif
+
+	DUK_D(DUK_DPRINT("  heap_udata: %p", (void *) heap->heap_udata));
+
+#ifdef DUK_USE_MARK_AND_SWEEP
+#ifdef DUK_USE_VOLUNTARY_GC
+	DUK_D(DUK_DPRINT("  mark-and-sweep trig counter: %ld", (long) heap->mark_and_sweep_trigger_counter));
+#endif
+	DUK_D(DUK_DPRINT("  mark-and-sweep rec depth: %ld", (long) heap->mark_and_sweep_recursion_depth));
+	DUK_D(DUK_DPRINT("  mark-and-sweep base flags: 0x%08lx", (unsigned long) heap->mark_and_sweep_base_flags));
+#endif
+
+	DUK_D(DUK_DPRINT("  lj.jmpbuf_ptr: %p", (void *) heap->lj.jmpbuf_ptr));
+	DUK_D(DUK_DPRINT("  lj.type: %ld", (long) heap->lj.type));
+	DUK_D(DUK_DPRINT("  lj.value1: %!T", (duk_tval *) &heap->lj.value1));
+	DUK_D(DUK_DPRINT("  lj.value2: %!T", (duk_tval *) &heap->lj.value2));
+	DUK_D(DUK_DPRINT("  lj.iserror: %ld", (long) heap->lj.iserror));
+
+	DUK_D(DUK_DPRINT("  handling_error: %ld", (long) heap->handling_error));
+
+	DUK_D(DUK_DPRINT("  heap_thread: %!@O", (duk_heaphdr *) heap->heap_thread));
+	DUK_D(DUK_DPRINT("  curr_thread: %!@O", (duk_heaphdr *) heap->curr_thread));
+	DUK_D(DUK_DPRINT("  heap_object: %!@O", (duk_heaphdr *) heap->heap_object));
+
+	DUK_D(DUK_DPRINT("  call_recursion_depth: %ld", (long) heap->call_recursion_depth));
+	DUK_D(DUK_DPRINT("  call_recursion_limit: %ld", (long) heap->call_recursion_limit));
+
+	DUK_D(DUK_DPRINT("  hash_seed: 0x%08lx", (unsigned long) heap->hash_seed));
+	DUK_D(DUK_DPRINT("  rnd_state: 0x%08lx", (unsigned long) heap->rnd_state));
+
+	duk__dump_strcache(heap);
+
+	duk__dump_heaphdr_list(heap, heap->heap_allocated, "heap allocated");
+
+#ifdef DUK_USE_REFERENCE_COUNTING
+	duk__dump_heaphdr_list(heap, heap->refzero_list, "refcounting refzero list");
+#endif
+
+#ifdef DUK_USE_MARK_AND_SWEEP
+	duk__dump_heaphdr_list(heap, heap->finalize_list, "mark-and-sweep finalize list");
+#endif
+
+	duk__dump_stringtable(heap);
+
+	/* heap->strs: not worth dumping */
+}
+#endif
+
+#endif  /* DUK_USE_DEBUG */

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_debug_macros.c
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_debug_macros.c b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_debug_macros.c
new file mode 100644
index 0000000..582a981
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_debug_macros.c
@@ -0,0 +1,144 @@
+/*
+ *  Debugging macro calls.
+ */
+
+#include "duk_internal.h"
+
+#ifdef DUK_USE_DEBUG
+
+/*
+ *  Debugging enabled
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+
+#define DUK__DEBUG_BUFSIZE  DUK_USE_DEBUG_BUFSIZE
+DUK_LOCAL char duk__debug_buf[DUK__DEBUG_BUFSIZE];
+
+DUK_LOCAL const char *duk__get_level_string(duk_small_int_t level) {
+	switch ((int) level) {
+	case DUK_LEVEL_DEBUG:
+		return "D";
+	case DUK_LEVEL_DDEBUG:
+		return "DD";
+	case DUK_LEVEL_DDDEBUG:
+		return "DDD";
+	}
+	return "???";
+}
+
+#ifdef DUK_USE_DPRINT_COLORS
+
+/* http://en.wikipedia.org/wiki/ANSI_escape_code */
+#define DUK__TERM_REVERSE  "\x1b[7m"
+#define DUK__TERM_BRIGHT   "\x1b[1m"
+#define DUK__TERM_RESET    "\x1b[0m"
+#define DUK__TERM_BLUE     "\x1b[34m"
+#define DUK__TERM_RED      "\x1b[31m"
+
+DUK_LOCAL const char *duk__get_term_1(duk_small_int_t level) {
+	DUK_UNREF(level);
+	return (const char *) DUK__TERM_RED;
+}
+
+DUK_LOCAL const char *duk__get_term_2(duk_small_int_t level) {
+	switch ((int) level) {
+	case DUK_LEVEL_DEBUG:
+		return (const char *) (DUK__TERM_RESET DUK__TERM_BRIGHT);
+	case DUK_LEVEL_DDEBUG:
+		return (const char *) (DUK__TERM_RESET);
+	case DUK_LEVEL_DDDEBUG:
+		return (const char *) (DUK__TERM_RESET DUK__TERM_BLUE);
+	}
+	return (const char *) DUK__TERM_RESET;
+}
+
+DUK_LOCAL const char *duk__get_term_3(duk_small_int_t level) {
+	DUK_UNREF(level);
+	return (const char *) DUK__TERM_RESET;
+}
+
+#else
+
+DUK_LOCAL const char *duk__get_term_1(duk_small_int_t level) {
+	DUK_UNREF(level);
+	return (const char *) "";
+}
+
+DUK_LOCAL const char *duk__get_term_2(duk_small_int_t level) {
+	DUK_UNREF(level);
+	return (const char *) "";
+}
+
+DUK_LOCAL const char *duk__get_term_3(duk_small_int_t level) {
+	DUK_UNREF(level);
+	return (const char *) "";
+}
+
+#endif  /* DUK_USE_DPRINT_COLORS */
+
+#ifdef DUK_USE_VARIADIC_MACROS
+
+DUK_INTERNAL void duk_debug_log(duk_small_int_t level, const char *file, duk_int_t line, const char *func, const char *fmt, ...) {
+	va_list ap;
+
+	va_start(ap, fmt);
+
+	DUK_MEMZERO((void *) duk__debug_buf, (size_t) DUK__DEBUG_BUFSIZE);
+	duk_debug_vsnprintf(duk__debug_buf, DUK__DEBUG_BUFSIZE - 1, fmt, ap);
+
+	DUK_FPRINTF(DUK_STDERR, "%s[%s] %s:%ld (%s):%s %s%s\n",
+	            (const char *) duk__get_term_1(level),
+	            (const char *) duk__get_level_string(level),
+	            (const char *) file,
+	            (long) line,
+	            (const char *) func,
+	            (const char *) duk__get_term_2(level),
+	            (const char *) duk__debug_buf,
+	            (const char *) duk__get_term_3(level));
+	DUK_FFLUSH(DUK_STDERR);
+
+	va_end(ap);
+}
+
+#else  /* DUK_USE_VARIADIC_MACROS */
+
+DUK_INTERNAL char duk_debug_file_stash[DUK_DEBUG_STASH_SIZE];
+DUK_INTERNAL char duk_debug_line_stash[DUK_DEBUG_STASH_SIZE];
+DUK_INTERNAL char duk_debug_func_stash[DUK_DEBUG_STASH_SIZE];
+DUK_INTERNAL duk_small_int_t duk_debug_level_stash;
+
+DUK_INTERNAL void duk_debug_log(const char *fmt, ...) {
+	va_list ap;
+	duk_small_int_t level = duk_debug_level_stash;
+
+	va_start(ap, fmt);
+
+	DUK_MEMZERO((void *) duk__debug_buf, (size_t) DUK__DEBUG_BUFSIZE);
+	duk_debug_vsnprintf(duk__debug_buf, DUK__DEBUG_BUFSIZE - 1, fmt, ap);
+
+	DUK_FPRINTF(DUK_STDERR, "%s[%s] %s:%s (%s):%s %s%s\n",
+	            (const char *) duk__get_term_1(level),
+	            (const char *) duk__get_level_string(duk_debug_level_stash),
+	            (const char *) duk_debug_file_stash,
+	            (const char *) duk_debug_line_stash,
+	            (const char *) duk_debug_func_stash,
+	            (const char *) duk__get_term_2(level),
+	            (const char *) duk__debug_buf,
+	            (const char *) duk__get_term_3(level));
+	DUK_FFLUSH(DUK_STDERR);
+
+	va_end(ap);
+}
+
+#endif  /* DUK_USE_VARIADIC_MACROS */
+
+#else  /* DUK_USE_DEBUG */
+
+/*
+ *  Debugging disabled
+ */
+
+#endif  /* DUK_USE_DEBUG */

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_debug_vsnprintf.c
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_debug_vsnprintf.c b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_debug_vsnprintf.c
new file mode 100644
index 0000000..50881c5
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_debug_vsnprintf.c
@@ -0,0 +1,1049 @@
+/*
+ *  Custom formatter for debug printing, allowing Duktape specific data
+ *  structures (such as tagged values and heap objects) to be printed with
+ *  a nice format string.  Because debug printing should not affect execution
+ *  state, formatting here must be independent of execution (see implications
+ *  below) and must not allocate memory.
+ *
+ *  Custom format tags begin with a '%!' to safely distinguish them from
+ *  standard format tags.  The following conversions are supported:
+ *
+ *     %!T    tagged value (duk_tval *)
+ *     %!O    heap object (duk_heaphdr *)
+ *     %!I    decoded bytecode instruction
+ *     %!C    bytecode instruction opcode name (arg is long)
+ *
+ *  Everything is serialized in a JSON-like manner.  The default depth is one
+ *  level, internal prototype is not followed, and internal properties are not
+ *  serialized.  The following modifiers change this behavior:
+ *
+ *     @      print pointers
+ *     #      print binary representations (where applicable)
+ *     d      deep traversal of own properties (not prototype)
+ *     p      follow prototype chain (useless without 'd')
+ *     i      include internal properties (other than prototype)
+ *     x      hexdump buffers
+ *     h      heavy formatting
+ *
+ *  For instance, the following serializes objects recursively, but does not
+ *  follow the prototype chain nor print internal properties: "%!dO".
+ *
+ *  Notes:
+ *
+ *    * Standard snprintf return value semantics seem to vary.  This
+ *      implementation returns the number of bytes it actually wrote
+ *      (excluding the null terminator).  If retval == buffer size,
+ *      output was truncated (except for corner cases).
+ *
+ *    * Output format is intentionally different from Ecmascript
+ *      formatting requirements, as formatting here serves debugging
+ *      of internals.
+ *
+ *    * Depth checking (and updating) is done in each type printer
+ *      separately, to allow them to call each other freely.
+ *
+ *    * Some pathological structures might take ages to print (e.g.
+ *      self recursion with 100 properties pointing to the object
+ *      itself).  To guard against these, each printer also checks
+ *      whether the output buffer is full; if so, early exit.
+ *
+ *    * Reference loops are detected using a loop stack.
+ */
+
+#include "duk_internal.h"
+
+#ifdef DUK_USE_DEBUG
+
+#include <stdio.h>
+#include <stdarg.h>
+#include <string.h>
+
+/* list of conversion specifiers that terminate a format tag;
+ * this is unfortunately guesswork.
+ */
+#define DUK__ALLOWED_STANDARD_SPECIFIERS  "diouxXeEfFgGaAcsCSpnm"
+
+/* maximum length of standard format tag that we support */
+#define DUK__MAX_FORMAT_TAG_LENGTH  32
+
+/* heapobj recursion depth when deep printing is selected */
+#define DUK__DEEP_DEPTH_LIMIT  8
+
+/* maximum recursion depth for loop detection stacks */
+#define DUK__LOOP_STACK_DEPTH  256
+
+/* must match bytecode defines now; build autogenerate? */
+DUK_LOCAL const char *duk__bc_optab[64] = {
+	"LDREG",    "STREG",    "LDCONST",  "LDINT",    "LDINTX",   "MPUTOBJ",  "MPUTOBJI", "MPUTARR",  "MPUTARRI", "NEW",
+	"NEWI",     "REGEXP",   "CSREG",    "CSREGI",   "GETVAR",   "PUTVAR",   "DECLVAR",  "DELVAR",   "CSVAR",    "CSVARI",
+	"CLOSURE",  "GETPROP",  "PUTPROP",  "DELPROP",  "CSPROP",   "CSPROPI",  "ADD",      "SUB",      "MUL",      "DIV",
+	"MOD",      "BAND",     "BOR",      "BXOR",     "BASL",     "BLSR",     "BASR",     "EQ",       "NEQ",      "SEQ",
+	"SNEQ",     "GT",       "GE",       "LT",       "LE",       "IF",       "JUMP",     "RETURN",   "CALL",     "CALLI",
+	"TRYCATCH", "EXTRA",    "PREINCR",  "PREDECR",  "POSTINCR", "POSTDECR", "PREINCV",  "PREDECV",  "POSTINCV", "POSTDECV",
+	"PREINCP",  "PREDECP",  "POSTINCP", "POSTDECP"
+};
+
+DUK_LOCAL const char *duk__bc_extraoptab[256] = {
+	"NOP", "INVALID", "LDTHIS", "LDUNDEF", "LDNULL", "LDTRUE", "LDFALSE", "NEWOBJ", "NEWARR", "SETALEN",
+	"TYPEOF", "TYPEOFID", "INITENUM", "NEXTENUM", "INITSET", "INITSETI", "INITGET", "INITGETI", "ENDTRY", "ENDCATCH",
+	"ENDFIN", "THROW", "INVLHS", "UNM", "UNP", "DEBUGGER", "BREAK", "CONTINUE", "BNOT", "LNOT",
+	"INSTOF", "IN", "LABEL", "ENDLABEL", "XXX", "XXX", "XXX", "XXX", "XXX", "XXX",
+	"XXX", "XXX", "XXX", "XXX", "XXX", "XXX", "XXX", "XXX", "XXX", "XXX",
+
+	"XXX", "XXX", "XXX", "XXX", "XXX", "XXX", "XXX", "XXX", "XXX", "XXX",
+	"XXX", "XXX", "XXX", "XXX", "XXX", "XXX", "XXX", "XXX", "XXX", "XXX",
+	"XXX", "XXX", "XXX", "XXX", "XXX", "XXX", "XXX", "XXX", "XXX", "XXX",
+	"XXX", "XXX", "XXX", "XXX", "XXX", "XXX", "XXX", "XXX", "XXX", "XXX",
+	"XXX", "XXX", "XXX", "XXX", "XXX", "XXX", "XXX", "XXX", "XXX", "XXX",
+
+	"XXX", "XXX", "XXX", "XXX", "XXX", "XXX", "XXX", "XXX", "XXX", "XXX",
+	"XXX", "XXX", "XXX", "XXX", "XXX", "XXX", "XXX", "XXX", "XXX", "XXX",
+	"XXX", "XXX", "XXX", "XXX", "XXX", "XXX", "XXX", "XXX", "XXX", "XXX",
+	"XXX", "XXX", "XXX", "XXX", "XXX", "XXX", "XXX", "XXX", "XXX", "XXX",
+	"XXX", "XXX", "XXX", "XXX", "XXX", "XXX", "XXX", "XXX", "XXX", "XXX",
+
+	"XXX", "XXX", "XXX", "XXX", "XXX", "XXX", "XXX", "XXX", "XXX", "XXX",
+	"XXX", "XXX", "XXX", "XXX", "XXX", "XXX", "XXX", "XXX", "XXX", "XXX",
+	"XXX", "XXX", "XXX", "XXX", "XXX", "XXX", "XXX", "XXX", "XXX", "XXX",
+	"XXX", "XXX", "XXX", "XXX", "XXX", "XXX", "XXX", "XXX", "XXX", "XXX",
+	"XXX", "XXX", "XXX", "XXX", "XXX", "XXX", "XXX", "XXX", "XXX", "XXX",
+
+	"XXX", "XXX", "XXX", "XXX", "XXX", "XXX", "XXX", "XXX", "XXX", "XXX",
+	"XXX", "XXX", "XXX", "XXX", "XXX", "XXX", "XXX", "XXX", "XXX", "XXX",
+	"XXX", "XXX", "XXX", "XXX", "XXX", "XXX", "XXX", "XXX", "XXX", "XXX",
+	"XXX", "XXX", "XXX", "XXX", "XXX", "XXX", "XXX", "XXX", "XXX", "XXX",
+	"XXX", "XXX", "XXX", "XXX", "XXX", "XXX", "XXX", "XXX", "XXX", "XXX",
+
+	"XXX", "XXX", "XXX", "XXX", "XXX", "XXX"
+};
+
+typedef struct duk__dprint_state duk__dprint_state;
+struct duk__dprint_state {
+	duk_fixedbuffer *fb;
+
+	/* loop_stack_index could be perhaps be replaced by 'depth', but it's nice
+	 * to not couple these two mechanisms unnecessarily.
+	 */
+	duk_hobject *loop_stack[DUK__LOOP_STACK_DEPTH];
+	duk_int_t loop_stack_index;
+	duk_int_t loop_stack_limit;
+
+	duk_int_t depth;
+	duk_int_t depth_limit;
+
+	duk_bool_t pointer;
+	duk_bool_t heavy;
+	duk_bool_t binary;
+	duk_bool_t follow_proto;
+	duk_bool_t internal;
+	duk_bool_t hexdump;
+};
+
+/* helpers */
+DUK_LOCAL_DECL void duk__print_hstring(duk__dprint_state *st, duk_hstring *k, duk_bool_t quotes);
+DUK_LOCAL_DECL void duk__print_hobject(duk__dprint_state *st, duk_hobject *h);
+DUK_LOCAL_DECL void duk__print_hbuffer(duk__dprint_state *st, duk_hbuffer *h);
+DUK_LOCAL_DECL void duk__print_tval(duk__dprint_state *st, duk_tval *tv);
+DUK_LOCAL_DECL void duk__print_instr(duk__dprint_state *st, duk_instr_t ins);
+DUK_LOCAL_DECL void duk__print_heaphdr(duk__dprint_state *st, duk_heaphdr *h);
+DUK_LOCAL_DECL void duk__print_shared_heaphdr(duk__dprint_state *st, duk_heaphdr *h);
+DUK_LOCAL_DECL void duk__print_shared_heaphdr_string(duk__dprint_state *st, duk_heaphdr_string *h);
+
+DUK_LOCAL void duk__print_shared_heaphdr(duk__dprint_state *st, duk_heaphdr *h) {
+	duk_fixedbuffer *fb = st->fb;
+
+	if (st->heavy) {
+		duk_fb_sprintf(fb, "(%p)", (void *) h);
+	}
+
+	if (!h) {
+		return;
+	}
+
+	if (st->binary) {
+		duk_size_t i;
+		duk_fb_put_byte(fb, (duk_uint8_t) DUK_ASC_LBRACKET);
+		for (i = 0; i < (duk_size_t) sizeof(*h); i++) {
+			duk_fb_sprintf(fb, "%02lx", (unsigned long) ((duk_uint8_t *)h)[i]);
+		}
+		duk_fb_put_byte(fb, (duk_uint8_t) DUK_ASC_RBRACKET);
+	}
+
+#ifdef DUK_USE_REFERENCE_COUNTING  /* currently implicitly also DUK_USE_DOUBLE_LINKED_HEAP */
+	if (st->heavy) {
+		duk_fb_sprintf(fb, "[h_next=%p,h_prev=%p,h_refcount=%lu,h_flags=%08lx,type=%ld,"
+		               "reachable=%ld,temproot=%ld,finalizable=%ld,finalized=%ld]",
+		               (void *) DUK_HEAPHDR_GET_NEXT(NULL, h),
+		               (void *) DUK_HEAPHDR_GET_PREV(NULL, h),
+		               (unsigned long) DUK_HEAPHDR_GET_REFCOUNT(h),
+		               (unsigned long) DUK_HEAPHDR_GET_FLAGS(h),
+		               (long) DUK_HEAPHDR_GET_TYPE(h),
+		               (long) (DUK_HEAPHDR_HAS_REACHABLE(h) ? 1 : 0),
+		               (long) (DUK_HEAPHDR_HAS_TEMPROOT(h) ? 1 : 0),
+		               (long) (DUK_HEAPHDR_HAS_FINALIZABLE(h) ? 1 : 0),
+		               (long) (DUK_HEAPHDR_HAS_FINALIZED(h) ? 1 : 0));
+	}
+#else
+	if (st->heavy) {
+		duk_fb_sprintf(fb, "[h_next=%p,h_flags=%08lx,type=%ld,reachable=%ld,temproot=%ld,finalizable=%ld,finalized=%ld]",
+		               (void *) DUK_HEAPHDR_GET_NEXT(NULL, h),
+		               (unsigned long) DUK_HEAPHDR_GET_FLAGS(h),
+		               (long) DUK_HEAPHDR_GET_TYPE(h),
+		               (long) (DUK_HEAPHDR_HAS_REACHABLE(h) ? 1 : 0),
+		               (long) (DUK_HEAPHDR_HAS_TEMPROOT(h) ? 1 : 0),
+		               (long) (DUK_HEAPHDR_HAS_FINALIZABLE(h) ? 1 : 0),
+		               (long) (DUK_HEAPHDR_HAS_FINALIZED(h) ? 1 : 0));
+	}
+#endif
+}
+
+DUK_LOCAL void duk__print_shared_heaphdr_string(duk__dprint_state *st, duk_heaphdr_string *h) {
+	duk_fixedbuffer *fb = st->fb;
+
+	if (st->heavy) {
+		duk_fb_sprintf(fb, "(%p)", (void *) h);
+	}
+
+	if (!h) {
+		return;
+	}
+
+	if (st->binary) {
+		duk_size_t i;
+		duk_fb_put_byte(fb, (duk_uint8_t) DUK_ASC_LBRACKET);
+		for (i = 0; i < (duk_size_t) sizeof(*h); i++) {
+			duk_fb_sprintf(fb, "%02lx", (unsigned long) ((duk_uint8_t *)h)[i]);
+		}
+		duk_fb_put_byte(fb, (duk_uint8_t) DUK_ASC_RBRACKET);
+	}
+
+#ifdef DUK_USE_REFERENCE_COUNTING
+	if (st->heavy) {
+		duk_fb_sprintf(fb, "[h_refcount=%lu,h_flags=%08lx,type=%ld,reachable=%ld,temproot=%ld,finalizable=%ld,finalized=%ld]",
+		               (unsigned long) DUK_HEAPHDR_GET_REFCOUNT((duk_heaphdr *) h),
+		               (unsigned long) DUK_HEAPHDR_GET_FLAGS((duk_heaphdr *) h),
+		               (long) DUK_HEAPHDR_GET_TYPE((duk_heaphdr *) h),
+		               (long) (DUK_HEAPHDR_HAS_REACHABLE((duk_heaphdr *) h) ? 1 : 0),
+		               (long) (DUK_HEAPHDR_HAS_TEMPROOT((duk_heaphdr *) h) ? 1 : 0),
+		               (long) (DUK_HEAPHDR_HAS_FINALIZABLE((duk_heaphdr *) h) ? 1 : 0),
+		               (long) (DUK_HEAPHDR_HAS_FINALIZED((duk_heaphdr *) h) ? 1 : 0));
+	}
+#else
+	if (st->heavy) {
+		duk_fb_sprintf(fb, "[h_flags=%08lx,type=%ld,reachable=%ld,temproot=%ld,finalizable=%ld,finalized=%ld]",
+		               (unsigned long) DUK_HEAPHDR_GET_FLAGS((duk_heaphdr *) h),
+		               (long) DUK_HEAPHDR_GET_TYPE((duk_heaphdr *) h),
+		               (long) (DUK_HEAPHDR_HAS_REACHABLE((duk_heaphdr *) h) ? 1 : 0),
+		               (long) (DUK_HEAPHDR_HAS_TEMPROOT((duk_heaphdr *) h) ? 1 : 0),
+		               (long) (DUK_HEAPHDR_HAS_FINALIZABLE((duk_heaphdr *) h) ? 1 : 0),
+		               (long) (DUK_HEAPHDR_HAS_FINALIZED((duk_heaphdr *) h) ? 1 : 0));
+	}
+#endif
+}
+
+DUK_LOCAL void duk__print_hstring(duk__dprint_state *st, duk_hstring *h, duk_bool_t quotes) {
+	duk_fixedbuffer *fb = st->fb;
+	const duk_uint8_t *p;
+	const duk_uint8_t *p_end;
+
+	/* terminal type: no depth check */
+
+	if (duk_fb_is_full(fb)) {
+		return;
+	}
+
+	duk__print_shared_heaphdr_string(st, &h->hdr);
+
+	if (!h) {
+		duk_fb_put_cstring(fb, "NULL");
+		return;
+	}
+
+	p = DUK_HSTRING_GET_DATA(h);
+	p_end = p + DUK_HSTRING_GET_BYTELEN(h);
+
+	if (p_end > p && p[0] == DUK_ASC_UNDERSCORE) {
+		/* if property key begins with underscore, encode it with
+		 * forced quotes (e.g. "_Foo") to distinguish it from encoded
+		 * internal properties (e.g. \xffBar -> _Bar).
+		 */
+		quotes = 1;
+	}
+
+	if (quotes) {
+		duk_fb_put_byte(fb, (duk_uint8_t) DUK_ASC_DOUBLEQUOTE);
+	}
+	while (p < p_end) {
+		duk_uint8_t ch = *p++;
+
+		/* two special escapes: '\' and '"', other printables as is */
+		if (ch == '\\') {
+			duk_fb_sprintf(fb, "\\\\");
+		} else if (ch == '"') {
+			duk_fb_sprintf(fb, "\\\"");
+		} else if (ch >= 0x20 && ch <= 0x7e) {
+			duk_fb_put_byte(fb, ch);
+		} else if (ch == 0xff && !quotes) {
+			/* encode \xffBar as _Bar if no quotes are applied, this is for
+			 * readable internal keys.
+			 */
+			duk_fb_put_byte(fb, (duk_uint8_t) DUK_ASC_UNDERSCORE);
+		} else {
+			duk_fb_sprintf(fb, "\\x%02lx", (unsigned long) ch);
+		}
+	}
+	if (quotes) {
+		duk_fb_put_byte(fb, (duk_uint8_t) DUK_ASC_DOUBLEQUOTE);
+	}
+#ifdef DUK_USE_REFERENCE_COUNTING
+	/* XXX: limit to quoted strings only, to save keys from being cluttered? */
+	duk_fb_sprintf(fb, "/%lu", (unsigned long) DUK_HEAPHDR_GET_REFCOUNT(&h->hdr));
+#endif
+}
+
+#ifdef DUK__COMMA
+#undef DUK__COMMA
+#endif
+#define DUK__COMMA()  do { \
+		if (first) { \
+			first = 0; \
+		} else { \
+			duk_fb_put_byte(fb, (duk_uint8_t) DUK_ASC_COMMA); \
+		} \
+	} while (0)
+
+DUK_LOCAL void duk__print_hobject(duk__dprint_state *st, duk_hobject *h) {
+	duk_fixedbuffer *fb = st->fb;
+	duk_uint_fast32_t i;
+	duk_tval *tv;
+	duk_hstring *key;
+	duk_bool_t first = 1;
+	const char *brace1 = "{";
+	const char *brace2 = "}";
+	duk_bool_t pushed_loopstack = 0;
+
+	if (duk_fb_is_full(fb)) {
+		return;
+	}
+
+	duk__print_shared_heaphdr(st, &h->hdr);
+
+	if (h && DUK_HOBJECT_HAS_ARRAY_PART(h)) {
+		brace1 = "[";
+		brace2 = "]";
+	}
+
+	if (!h) {
+		duk_fb_put_cstring(fb, "NULL");
+		goto finished;
+	}
+
+	if (st->depth >= st->depth_limit) {
+		if (DUK_HOBJECT_IS_COMPILEDFUNCTION(h)) {
+			duk_fb_sprintf(fb, "%sobject/compiledfunction %p%s", (const char *) brace1, (void *) h, (const char *) brace2);
+		} else if (DUK_HOBJECT_IS_NATIVEFUNCTION(h)) {
+			duk_fb_sprintf(fb, "%sobject/nativefunction %p%s", (const char *) brace1, (void *) h, (const char *) brace2);
+		} else if (DUK_HOBJECT_IS_THREAD(h)) {
+			duk_fb_sprintf(fb, "%sobject/thread %p%s", (const char *) brace1, (void *) h, (const char *) brace2);
+		} else {
+			duk_fb_sprintf(fb, "%sobject %p%s", (const char *) brace1, (void *) h, (const char *) brace2);  /* may be NULL */
+		}
+		return;
+	}
+
+	for (i = 0; i < (duk_uint_fast32_t) st->loop_stack_index; i++) {
+		if (st->loop_stack[i] == h) {
+			duk_fb_sprintf(fb, "%sLOOP:%p%s", (const char *) brace1, (void *) h, (const char *) brace2);
+			return;
+		}
+	}
+
+	/* after this, return paths should 'goto finished' for decrement */
+	st->depth++;
+
+	if (st->loop_stack_index >= st->loop_stack_limit) {
+		duk_fb_sprintf(fb, "%sOUT-OF-LOOP-STACK%s", (const char *) brace1, (const char *) brace2);
+		goto finished;
+	}
+	st->loop_stack[st->loop_stack_index++] = h;
+	pushed_loopstack = 1;
+
+	/*
+	 *  Notation: double underscore used for internal properties which are not
+	 *  stored in the property allocation (e.g. '__valstack').
+	 */
+
+	duk_fb_put_cstring(fb, brace1);
+
+	if (DUK_HOBJECT_GET_PROPS(NULL, h)) {
+		duk_uint32_t a_limit;
+
+		a_limit = DUK_HOBJECT_GET_ASIZE(h);
+		if (st->internal) {
+			/* dump all allocated entries, unused entries print as 'unused',
+			 * note that these may extend beyond current 'length' and look
+			 * a bit funny.
+			 */
+		} else {
+			/* leave out trailing 'unused' elements */
+			while (a_limit > 0) {
+				tv = DUK_HOBJECT_A_GET_VALUE_PTR(NULL, h, a_limit - 1);
+				if (!DUK_TVAL_IS_UNUSED(tv)) {
+					break;
+				}
+				a_limit--;
+			}
+		}
+
+		for (i = 0; i < a_limit; i++) {
+			tv = DUK_HOBJECT_A_GET_VALUE_PTR(NULL, h, i);
+			DUK__COMMA();
+			duk__print_tval(st, tv);
+		}
+		for (i = 0; i < DUK_HOBJECT_GET_ENEXT(h); i++) {
+			key = DUK_HOBJECT_E_GET_KEY(NULL, h, i);
+			if (!key) {
+				continue;
+			}
+			if (!st->internal &&
+			    DUK_HSTRING_GET_BYTELEN(key) > 0 &&
+			    DUK_HSTRING_GET_DATA(key)[0] == 0xff) {
+				/* XXX: use DUK_HSTRING_FLAG_INTERNAL? */
+				continue;
+			}
+			DUK__COMMA();
+			duk__print_hstring(st, key, 0);
+			duk_fb_put_byte(fb, (duk_uint8_t) DUK_ASC_COLON);
+			if (DUK_HOBJECT_E_SLOT_IS_ACCESSOR(NULL, h, i)) {
+				duk_fb_sprintf(fb, "[get:%p,set:%p]",
+				               (void *) DUK_HOBJECT_E_GET_VALUE(NULL, h, i).a.get,
+				               (void *) DUK_HOBJECT_E_GET_VALUE(NULL, h, i).a.set);
+			} else {
+				tv = &DUK_HOBJECT_E_GET_VALUE(NULL, h, i).v;
+				duk__print_tval(st, tv);
+			}
+			if (st->heavy) {
+				duk_fb_sprintf(fb, "<%02lx>", (unsigned long) DUK_HOBJECT_E_GET_FLAGS(NULL, h, i));
+			}
+		}
+	}
+	if (st->internal) {
+		if (DUK_HOBJECT_HAS_EXTENSIBLE(h)) {
+			DUK__COMMA(); duk_fb_sprintf(fb, "__extensible:true");
+		} else {
+			;
+		}
+		if (DUK_HOBJECT_HAS_CONSTRUCTABLE(h)) {
+			DUK__COMMA(); duk_fb_sprintf(fb, "__constructable:true");
+		} else {
+			;
+		}
+		if (DUK_HOBJECT_HAS_BOUND(h)) {
+			DUK__COMMA(); duk_fb_sprintf(fb, "__bound:true");
+		} else {
+			;
+		}
+		if (DUK_HOBJECT_HAS_COMPILEDFUNCTION(h)) {
+			DUK__COMMA(); duk_fb_sprintf(fb, "__compiledfunction:true");
+		} else {
+			;
+		}
+		if (DUK_HOBJECT_HAS_NATIVEFUNCTION(h)) {
+			DUK__COMMA(); duk_fb_sprintf(fb, "__nativefunction:true");
+		} else {
+			;
+		}
+		if (DUK_HOBJECT_HAS_THREAD(h)) {
+			DUK__COMMA(); duk_fb_sprintf(fb, "__thread:true");
+		} else {
+			;
+		}
+		if (DUK_HOBJECT_HAS_ARRAY_PART(h)) {
+			DUK__COMMA(); duk_fb_sprintf(fb, "__array_part:true");
+		} else {
+			;
+		}
+		if (DUK_HOBJECT_HAS_STRICT(h)) {
+			DUK__COMMA(); duk_fb_sprintf(fb, "__strict:true");
+		} else {
+			;
+		}
+		if (DUK_HOBJECT_HAS_NEWENV(h)) {
+			DUK__COMMA(); duk_fb_sprintf(fb, "__newenv:true");
+		} else {
+			;
+		}
+		if (DUK_HOBJECT_HAS_NAMEBINDING(h)) {
+			DUK__COMMA(); duk_fb_sprintf(fb, "__namebinding:true");
+		} else {
+			;
+		}
+		if (DUK_HOBJECT_HAS_CREATEARGS(h)) {
+			DUK__COMMA(); duk_fb_sprintf(fb, "__createargs:true");
+		} else {
+			;
+		}
+		if (DUK_HOBJECT_HAS_ENVRECCLOSED(h)) {
+			DUK__COMMA(); duk_fb_sprintf(fb, "__envrecclosed:true");
+		} else {
+			;
+		}
+		if (DUK_HOBJECT_HAS_EXOTIC_ARRAY(h)) {
+			DUK__COMMA(); duk_fb_sprintf(fb, "__exotic_array:true");
+		} else {
+			;
+		}
+		if (DUK_HOBJECT_HAS_EXOTIC_STRINGOBJ(h)) {
+			DUK__COMMA(); duk_fb_sprintf(fb, "__exotic_stringobj:true");
+		} else {
+			;
+		}
+		if (DUK_HOBJECT_HAS_EXOTIC_ARGUMENTS(h)) {
+			DUK__COMMA(); duk_fb_sprintf(fb, "__exotic_arguments:true");
+		} else {
+			;
+		}
+		if (DUK_HOBJECT_HAS_EXOTIC_DUKFUNC(h)) {
+			DUK__COMMA(); duk_fb_sprintf(fb, "__exotic_dukfunc:true");
+		} else {
+			;
+		}
+		if (DUK_HOBJECT_IS_BUFFEROBJECT(h)) {
+			DUK__COMMA(); duk_fb_sprintf(fb, "__exotic_bufferobj:true");
+		} else {
+			;
+		}
+		if (DUK_HOBJECT_HAS_EXOTIC_PROXYOBJ(h)) {
+			DUK__COMMA(); duk_fb_sprintf(fb, "__exotic_proxyobj:true");
+		} else {
+			;
+		}
+	}
+	if (st->internal && DUK_HOBJECT_IS_COMPILEDFUNCTION(h)) {
+		duk_hcompiledfunction *f = (duk_hcompiledfunction *) h;
+		DUK__COMMA(); duk_fb_put_cstring(fb, "__data:");
+		duk__print_hbuffer(st, (duk_hbuffer *) DUK_HCOMPILEDFUNCTION_GET_DATA(NULL, f));
+		DUK__COMMA(); duk_fb_sprintf(fb, "__nregs:%ld", (long) f->nregs);
+		DUK__COMMA(); duk_fb_sprintf(fb, "__nargs:%ld", (long) f->nargs);
+#if defined(DUK_USE_DEBUGGER_SUPPORT)
+		DUK__COMMA(); duk_fb_sprintf(fb, "__start_line:%ld", (long) f->start_line);
+		DUK__COMMA(); duk_fb_sprintf(fb, "__end_line:%ld", (long) f->end_line);
+#endif
+		DUK__COMMA(); duk_fb_put_cstring(fb, "__data:");
+		duk__print_hbuffer(st, (duk_hbuffer *) DUK_HCOMPILEDFUNCTION_GET_DATA(NULL, f));
+	} else if (st->internal && DUK_HOBJECT_IS_NATIVEFUNCTION(h)) {
+		duk_hnativefunction *f = (duk_hnativefunction *) h;
+		DUK__COMMA(); duk_fb_sprintf(fb, "__func:");
+		duk_fb_put_funcptr(fb, (duk_uint8_t *) &f->func, sizeof(f->func));
+		DUK__COMMA(); duk_fb_sprintf(fb, "__nargs:%ld", (long) f->nargs);
+		DUK__COMMA(); duk_fb_sprintf(fb, "__magic:%ld", (long) f->magic);
+	} else if (st->internal && DUK_HOBJECT_IS_BUFFEROBJECT(h)) {
+		duk_hbufferobject *b = (duk_hbufferobject *) h;
+		DUK__COMMA(); duk_fb_sprintf(fb, "__buf:");
+		duk__print_hbuffer(st, (duk_hbuffer *) b->buf);
+		DUK__COMMA(); duk_fb_sprintf(fb, "__offset:%ld", (long) b->offset);
+		DUK__COMMA(); duk_fb_sprintf(fb, "__length:%ld", (long) b->length);
+		DUK__COMMA(); duk_fb_sprintf(fb, "__shift:%ld", (long) b->shift);
+		DUK__COMMA(); duk_fb_sprintf(fb, "__elemtype:%ld", (long) b->elem_type);
+	} else if (st->internal && DUK_HOBJECT_IS_THREAD(h)) {
+		duk_hthread *t = (duk_hthread *) h;
+		DUK__COMMA(); duk_fb_sprintf(fb, "__strict:%ld", (long) t->strict);
+		DUK__COMMA(); duk_fb_sprintf(fb, "__state:%ld", (long) t->state);
+		DUK__COMMA(); duk_fb_sprintf(fb, "__unused1:%ld", (long) t->unused1);
+		DUK__COMMA(); duk_fb_sprintf(fb, "__unused2:%ld", (long) t->unused2);
+		DUK__COMMA(); duk_fb_sprintf(fb, "__valstack_max:%ld", (long) t->valstack_max);
+		DUK__COMMA(); duk_fb_sprintf(fb, "__callstack_max:%ld", (long) t->callstack_max);
+		DUK__COMMA(); duk_fb_sprintf(fb, "__catchstack_max:%ld", (long) t->catchstack_max);
+		DUK__COMMA(); duk_fb_sprintf(fb, "__valstack:%p", (void *) t->valstack);
+		DUK__COMMA(); duk_fb_sprintf(fb, "__valstack_end:%p/%ld", (void *) t->valstack_end, (long) (t->valstack_end - t->valstack));
+		DUK__COMMA(); duk_fb_sprintf(fb, "__valstack_bottom:%p/%ld", (void *) t->valstack_bottom, (long) (t->valstack_bottom - t->valstack));
+		DUK__COMMA(); duk_fb_sprintf(fb, "__valstack_top:%p/%ld", (void *) t->valstack_top, (long) (t->valstack_top - t->valstack));
+		DUK__COMMA(); duk_fb_sprintf(fb, "__catchstack:%p", (void *) t->catchstack);
+		DUK__COMMA(); duk_fb_sprintf(fb, "__catchstack_size:%ld", (long) t->catchstack_size);
+		DUK__COMMA(); duk_fb_sprintf(fb, "__catchstack_top:%ld", (long) t->catchstack_top);
+		DUK__COMMA(); duk_fb_sprintf(fb, "__resumer:"); duk__print_hobject(st, (duk_hobject *) t->resumer);
+		/* XXX: print built-ins array? */
+
+	}
+#ifdef DUK_USE_REFERENCE_COUNTING
+	if (st->internal) {
+		DUK__COMMA(); duk_fb_sprintf(fb, "__refcount:%lu", (unsigned long) DUK_HEAPHDR_GET_REFCOUNT((duk_heaphdr *) h));
+	}
+#endif
+	if (st->internal) {
+		DUK__COMMA(); duk_fb_sprintf(fb, "__class:%ld", (long) DUK_HOBJECT_GET_CLASS_NUMBER(h));
+	}
+
+	DUK__COMMA(); duk_fb_sprintf(fb, "__heapptr:%p", (void *) h);  /* own pointer */
+
+	/* prototype should be last, for readability */
+	if (DUK_HOBJECT_GET_PROTOTYPE(NULL, h)) {
+		if (st->follow_proto) {
+			DUK__COMMA(); duk_fb_put_cstring(fb, "__prototype:"); duk__print_hobject(st, DUK_HOBJECT_GET_PROTOTYPE(NULL, h));
+		} else {
+			DUK__COMMA(); duk_fb_sprintf(fb, "__prototype:%p", (void *) DUK_HOBJECT_GET_PROTOTYPE(NULL, h));
+		}
+	}
+
+	duk_fb_put_cstring(fb, brace2);
+
+#if defined(DUK_USE_HOBJECT_HASH_PART)
+	if (st->heavy && DUK_HOBJECT_GET_HSIZE(h) > 0) {
+		duk_fb_put_byte(fb, (duk_uint8_t) DUK_ASC_LANGLE);
+		for (i = 0; i < DUK_HOBJECT_GET_HSIZE(h); i++) {
+			duk_uint_t h_idx = DUK_HOBJECT_H_GET_INDEX(NULL, h, i);
+			if (i > 0) {
+				duk_fb_put_byte(fb, (duk_uint8_t) DUK_ASC_COMMA);
+			}
+			if (h_idx == DUK_HOBJECT_HASHIDX_UNUSED) {
+				duk_fb_sprintf(fb, "u");
+			} else if (h_idx == DUK_HOBJECT_HASHIDX_DELETED) {
+				duk_fb_sprintf(fb, "d");
+			} else {
+				duk_fb_sprintf(fb, "%ld", (long) h_idx);
+			}
+		}
+		duk_fb_put_byte(fb, (duk_uint8_t) DUK_ASC_RANGLE);
+	}
+#endif
+
+ finished:
+	st->depth--;
+	if (pushed_loopstack) {
+		st->loop_stack_index--;
+		st->loop_stack[st->loop_stack_index] = NULL;
+	}
+}
+
+#undef DUK__COMMA
+
+DUK_LOCAL void duk__print_hbuffer(duk__dprint_state *st, duk_hbuffer *h) {
+	duk_fixedbuffer *fb = st->fb;
+	duk_size_t i, n;
+	duk_uint8_t *p;
+
+	if (duk_fb_is_full(fb)) {
+		return;
+	}
+
+	/* terminal type: no depth check */
+
+	if (!h) {
+		duk_fb_put_cstring(fb, "NULL");
+		return;
+	}
+
+	if (DUK_HBUFFER_HAS_DYNAMIC(h)) {
+		if (DUK_HBUFFER_HAS_EXTERNAL(h)) {
+			duk_hbuffer_external *g = (duk_hbuffer_external *) h;
+			duk_fb_sprintf(fb, "buffer:external:%p:%ld",
+			               (void *) DUK_HBUFFER_EXTERNAL_GET_DATA_PTR(NULL, g),
+			               (long) DUK_HBUFFER_EXTERNAL_GET_SIZE(g));
+		} else {
+			duk_hbuffer_dynamic *g = (duk_hbuffer_dynamic *) h;
+			duk_fb_sprintf(fb, "buffer:dynamic:%p:%ld",
+			               (void *) DUK_HBUFFER_DYNAMIC_GET_DATA_PTR(NULL, g),
+			               (long) DUK_HBUFFER_DYNAMIC_GET_SIZE(g));
+		}
+	} else {
+		duk_fb_sprintf(fb, "buffer:fixed:%ld", (long) DUK_HBUFFER_GET_SIZE(h));
+	}
+
+#ifdef DUK_USE_REFERENCE_COUNTING
+	duk_fb_sprintf(fb, "/%lu", (unsigned long) DUK_HEAPHDR_GET_REFCOUNT(&h->hdr));
+#endif
+
+	if (st->hexdump) {
+		duk_fb_sprintf(fb, "=[");
+		n = DUK_HBUFFER_GET_SIZE(h);
+		p = (duk_uint8_t *) DUK_HBUFFER_GET_DATA_PTR(NULL, h);
+		for (i = 0; i < n; i++) {
+			duk_fb_sprintf(fb, "%02lx", (unsigned long) p[i]);
+		}
+		duk_fb_sprintf(fb, "]");
+	}
+}
+
+DUK_LOCAL void duk__print_heaphdr(duk__dprint_state *st, duk_heaphdr *h) {
+	duk_fixedbuffer *fb = st->fb;
+
+	if (duk_fb_is_full(fb)) {
+		return;
+	}
+
+	if (!h) {
+		duk_fb_put_cstring(fb, "NULL");
+		return;
+	}
+
+	switch (DUK_HEAPHDR_GET_TYPE(h)) {
+	case DUK_HTYPE_STRING:
+		duk__print_hstring(st, (duk_hstring *) h, 1);
+		break;
+	case DUK_HTYPE_OBJECT:
+		duk__print_hobject(st, (duk_hobject *) h);
+		break;
+	case DUK_HTYPE_BUFFER:
+		duk__print_hbuffer(st, (duk_hbuffer *) h);
+		break;
+	default:
+		duk_fb_sprintf(fb, "[unknown htype %ld]", (long) DUK_HEAPHDR_GET_TYPE(h));
+		break;
+	}
+}
+
+DUK_LOCAL void duk__print_tval(duk__dprint_state *st, duk_tval *tv) {
+	duk_fixedbuffer *fb = st->fb;
+
+	if (duk_fb_is_full(fb)) {
+		return;
+	}
+
+	/* depth check is done when printing an actual type */
+
+	if (st->heavy) {
+		duk_fb_sprintf(fb, "(%p)", (void *) tv);
+	}
+
+	if (!tv) {
+		duk_fb_put_cstring(fb, "NULL");
+		return;
+	}
+
+	if (st->binary) {
+		duk_size_t i;
+		duk_fb_put_byte(fb, (duk_uint8_t) DUK_ASC_LBRACKET);
+		for (i = 0; i < (duk_size_t) sizeof(*tv); i++) {
+			duk_fb_sprintf(fb, "%02lx", (unsigned long) ((duk_uint8_t *)tv)[i]);
+		}
+		duk_fb_put_byte(fb, (duk_uint8_t) DUK_ASC_RBRACKET);
+	}
+
+	if (st->heavy) {
+		duk_fb_put_byte(fb, (duk_uint8_t) DUK_ASC_LANGLE);
+	}
+	switch (DUK_TVAL_GET_TAG(tv)) {
+	case DUK_TAG_UNDEFINED: {
+		duk_fb_put_cstring(fb, "undefined");
+		break;
+	}
+	case DUK_TAG_UNUSED: {
+		duk_fb_put_cstring(fb, "unused");
+		break;
+	}
+	case DUK_TAG_NULL: {
+		duk_fb_put_cstring(fb, "null");
+		break;
+	}
+	case DUK_TAG_BOOLEAN: {
+		duk_fb_put_cstring(fb, DUK_TVAL_GET_BOOLEAN(tv) ? "true" : "false");
+		break;
+	}
+	case DUK_TAG_STRING: {
+		/* Note: string is a terminal heap object, so no depth check here */
+		duk__print_hstring(st, DUK_TVAL_GET_STRING(tv), 1);
+		break;
+	}
+	case DUK_TAG_OBJECT: {
+		duk__print_hobject(st, DUK_TVAL_GET_OBJECT(tv));
+		break;
+	}
+	case DUK_TAG_BUFFER: {
+		duk__print_hbuffer(st, DUK_TVAL_GET_BUFFER(tv));
+		break;
+	}
+	case DUK_TAG_POINTER: {
+		duk_fb_sprintf(fb, "pointer:%p", (void *) DUK_TVAL_GET_POINTER(tv));
+		break;
+	}
+	case DUK_TAG_LIGHTFUNC: {
+		duk_c_function func;
+		duk_small_uint_t lf_flags;
+
+		DUK_TVAL_GET_LIGHTFUNC(tv, func, lf_flags);
+		duk_fb_sprintf(fb, "lightfunc:");
+		duk_fb_put_funcptr(fb, (duk_uint8_t *) &func, sizeof(func));
+		duk_fb_sprintf(fb, ":%04lx", (long) lf_flags);
+		break;
+	}
+#if defined(DUK_USE_FASTINT)
+	case DUK_TAG_FASTINT:
+#endif
+	default: {
+		/* IEEE double is approximately 16 decimal digits; print a couple extra */
+		DUK_ASSERT(!DUK_TVAL_IS_UNUSED(tv));
+		DUK_ASSERT(DUK_TVAL_IS_NUMBER(tv));
+		duk_fb_sprintf(fb, "%.18g", (double) DUK_TVAL_GET_NUMBER(tv));
+		break;
+	}
+	}
+	if (st->heavy) {
+		duk_fb_put_byte(fb, (duk_uint8_t) DUK_ASC_RANGLE);
+	}
+}
+
+DUK_LOCAL void duk__print_instr(duk__dprint_state *st, duk_instr_t ins) {
+	duk_fixedbuffer *fb = st->fb;
+	duk_small_int_t op;
+	const char *op_name;
+	const char *extraop_name;
+
+	op = (duk_small_int_t) DUK_DEC_OP(ins);
+	op_name = duk__bc_optab[op];
+
+	/* XXX: option to fix opcode length so it lines up nicely */
+
+	if (op == DUK_OP_EXTRA) {
+		extraop_name = duk__bc_extraoptab[DUK_DEC_A(ins)];
+
+		duk_fb_sprintf(fb, "%s %ld, %ld",
+		               (const char *) extraop_name, (long) DUK_DEC_B(ins), (long) DUK_DEC_C(ins));
+	} else if (op == DUK_OP_JUMP) {
+		duk_int_t diff1 = DUK_DEC_ABC(ins) - DUK_BC_JUMP_BIAS;  /* from next pc */
+		duk_int_t diff2 = diff1 + 1;                            /* from curr pc */
+
+		duk_fb_sprintf(fb, "%s %ld (to pc%c%ld)",
+		               (const char *) op_name, (long) diff1,
+		               (int) (diff2 >= 0 ? '+' : '-'),  /* char format: use int */
+		               (long) (diff2 >= 0 ? diff2 : -diff2));
+	} else {
+		duk_fb_sprintf(fb, "%s %ld, %ld, %ld",
+		               (const char *) op_name, (long) DUK_DEC_A(ins),
+		               (long) DUK_DEC_B(ins), (long) DUK_DEC_C(ins));
+	}
+}
+
+DUK_LOCAL void duk__print_opcode(duk__dprint_state *st, duk_small_int_t opcode) {
+	duk_fixedbuffer *fb = st->fb;
+
+	if (opcode < DUK_BC_OP_MIN || opcode > DUK_BC_OP_MAX) {
+		duk_fb_sprintf(fb, "?(%ld)", (long) opcode);
+	} else {
+		duk_fb_sprintf(fb, "%s", (const char *) duk__bc_optab[opcode]);
+	}
+}
+
+DUK_INTERNAL duk_int_t duk_debug_vsnprintf(char *str, duk_size_t size, const char *format, va_list ap) {
+	duk_fixedbuffer fb;
+	const char *p = format;
+	const char *p_end = p + DUK_STRLEN(format);
+	duk_int_t retval;
+
+	DUK_MEMZERO(&fb, sizeof(fb));
+	fb.buffer = (duk_uint8_t *) str;
+	fb.length = size;
+	fb.offset = 0;
+	fb.truncated = 0;
+
+	while (p < p_end) {
+		char ch = *p++;
+		const char *p_begfmt = NULL;
+		duk_bool_t got_exclamation = 0;
+		duk_bool_t got_long = 0;  /* %lf, %ld etc */
+		duk__dprint_state st;
+
+		if (ch != DUK_ASC_PERCENT) {
+			duk_fb_put_byte(&fb, (duk_uint8_t) ch);
+			continue;
+		}
+
+		/*
+		 *  Format tag parsing.  Since we don't understand all the
+		 *  possible format tags allowed, we just scan for a terminating
+		 *  specifier and keep track of relevant modifiers that we do
+		 *  understand.  See man 3 printf.
+		 */
+
+		DUK_MEMZERO(&st, sizeof(st));
+		st.fb = &fb;
+		st.depth = 0;
+		st.depth_limit = 1;
+		st.loop_stack_index = 0;
+		st.loop_stack_limit = DUK__LOOP_STACK_DEPTH;
+
+		p_begfmt = p - 1;
+		while (p < p_end) {
+			ch = *p++;
+
+			if (ch == DUK_ASC_STAR) {
+				/* unsupported: would consume multiple args */
+				goto error;
+			} else if (ch == DUK_ASC_PERCENT) {
+				duk_fb_put_byte(&fb, (duk_uint8_t) DUK_ASC_PERCENT);
+				break;
+			} else if (ch == DUK_ASC_EXCLAMATION) {
+				got_exclamation = 1;
+			} else if (!got_exclamation && ch == DUK_ASC_LC_L) {
+				got_long = 1;
+			} else if (got_exclamation && ch == DUK_ASC_LC_D) {
+				st.depth_limit = DUK__DEEP_DEPTH_LIMIT;
+			} else if (got_exclamation && ch == DUK_ASC_LC_P) {
+				st.follow_proto = 1;
+			} else if (got_exclamation && ch == DUK_ASC_LC_I) {
+				st.internal = 1;
+			} else if (got_exclamation && ch == DUK_ASC_LC_X) {
+				st.hexdump = 1;
+			} else if (got_exclamation && ch == DUK_ASC_LC_H) {
+				st.heavy = 1;
+			} else if (got_exclamation && ch == DUK_ASC_ATSIGN) {
+				st.pointer = 1;
+			} else if (got_exclamation && ch == DUK_ASC_HASH) {
+				st.binary = 1;
+			} else if (got_exclamation && ch == DUK_ASC_UC_T) {
+				duk_tval *t = va_arg(ap, duk_tval *);
+				if (st.pointer && !st.heavy) {
+					duk_fb_sprintf(&fb, "(%p)", (void *) t);
+				}
+				duk__print_tval(&st, t);
+				break;
+			} else if (got_exclamation && ch == DUK_ASC_UC_O) {
+				duk_heaphdr *t = va_arg(ap, duk_heaphdr *);
+				if (st.pointer && !st.heavy) {
+					duk_fb_sprintf(&fb, "(%p)", (void *) t);
+				}
+				duk__print_heaphdr(&st, t);
+				break;
+			} else if (got_exclamation && ch == DUK_ASC_UC_I) {
+				duk_instr_t t = va_arg(ap, duk_instr_t);
+				duk__print_instr(&st, t);
+				break;
+			} else if (got_exclamation && ch == DUK_ASC_UC_C) {
+				long t = va_arg(ap, long);
+				duk__print_opcode(&st, (duk_small_int_t) t);
+				break;
+			} else if (!got_exclamation && strchr(DUK__ALLOWED_STANDARD_SPECIFIERS, (int) ch)) {
+				char fmtbuf[DUK__MAX_FORMAT_TAG_LENGTH];
+				duk_size_t fmtlen;
+
+				DUK_ASSERT(p >= p_begfmt);
+				fmtlen = (duk_size_t) (p - p_begfmt);
+				if (fmtlen >= sizeof(fmtbuf)) {
+					/* format is too large, abort */
+					goto error;
+				}
+				DUK_MEMZERO(fmtbuf, sizeof(fmtbuf));
+				DUK_MEMCPY(fmtbuf, p_begfmt, fmtlen);
+
+				/* assume exactly 1 arg, which is why '*' is forbidden; arg size still
+				 * depends on type though.
+				 */
+
+				if (ch == DUK_ASC_LC_F || ch == DUK_ASC_LC_G || ch == DUK_ASC_LC_E) {
+					/* %f and %lf both consume a 'long' */
+					double arg = va_arg(ap, double);
+					duk_fb_sprintf(&fb, fmtbuf, arg);
+				} else if (ch == DUK_ASC_LC_D && got_long) {
+					/* %ld */
+					long arg = va_arg(ap, long);
+					duk_fb_sprintf(&fb, fmtbuf, arg);
+				} else if (ch == DUK_ASC_LC_D) {
+					/* %d; only 16 bits are guaranteed */
+					int arg = va_arg(ap, int);
+					duk_fb_sprintf(&fb, fmtbuf, arg);
+				} else if (ch == DUK_ASC_LC_U && got_long) {
+					/* %lu */
+					unsigned long arg = va_arg(ap, unsigned long);
+					duk_fb_sprintf(&fb, fmtbuf, arg);
+				} else if (ch == DUK_ASC_LC_U) {
+					/* %u; only 16 bits are guaranteed */
+					unsigned int arg = va_arg(ap, unsigned int);
+					duk_fb_sprintf(&fb, fmtbuf, arg);
+				} else if (ch == DUK_ASC_LC_X && got_long) {
+					/* %lx */
+					unsigned long arg = va_arg(ap, unsigned long);
+					duk_fb_sprintf(&fb, fmtbuf, arg);
+				} else if (ch == DUK_ASC_LC_X) {
+					/* %x; only 16 bits are guaranteed */
+					unsigned int arg = va_arg(ap, unsigned int);
+					duk_fb_sprintf(&fb, fmtbuf, arg);
+				} else if (ch == DUK_ASC_LC_S) {
+					/* %s */
+					const char *arg = va_arg(ap, const char *);
+					if (arg == NULL) {
+						/* '%s' and NULL is not portable, so special case
+						 * it for debug printing.
+						 */
+						duk_fb_sprintf(&fb, "NULL");
+					} else {
+						duk_fb_sprintf(&fb, fmtbuf, arg);
+					}
+				} else if (ch == DUK_ASC_LC_P) {
+					/* %p */
+					void *arg = va_arg(ap, void *);
+					if (arg == NULL) {
+						/* '%p' and NULL is portable, but special case it
+						 * anyway to get a standard NULL marker in logs.
+						 */
+						duk_fb_sprintf(&fb, "NULL");
+					} else {
+						duk_fb_sprintf(&fb, fmtbuf, arg);
+					}
+				} else if (ch == DUK_ASC_LC_C) {
+					/* '%c', passed concretely as int */
+					int arg = va_arg(ap, int);
+					duk_fb_sprintf(&fb, fmtbuf, arg);
+				} else {
+					/* Should not happen. */
+					duk_fb_sprintf(&fb, "INVALID-FORMAT(%s)", (const char *) fmtbuf);
+				}
+				break;
+			} else {
+				/* ignore */
+			}
+		}
+	}
+	goto done;
+
+ error:
+	duk_fb_put_cstring(&fb, "FMTERR");
+	/* fall through */
+
+ done:
+	retval = (duk_int_t) fb.offset;
+	duk_fb_put_byte(&fb, (duk_uint8_t) 0);
+
+	/* return total chars written excluding terminator */
+	return retval;
+}
+
+#if 0  /*unused*/
+DUK_INTERNAL duk_int_t duk_debug_snprintf(char *str, duk_size_t size, const char *format, ...) {
+	duk_int_t retval;
+	va_list ap;
+	va_start(ap, format);
+	retval = duk_debug_vsnprintf(str, size, format, ap);
+	va_end(ap);
+	return retval;
+}
+#endif
+
+/* Formatting function pointers is tricky: there is no standard pointer for
+ * function pointers and the size of a function pointer may depend on the
+ * specific pointer type.  This helper formats a function pointer based on
+ * its memory layout to get something useful on most platforms.
+ */
+DUK_INTERNAL void duk_debug_format_funcptr(char *buf, duk_size_t buf_size, duk_uint8_t *fptr, duk_size_t fptr_size) {
+	duk_size_t i;
+	duk_uint8_t *p = (duk_uint8_t *) buf;
+	duk_uint8_t *p_end = (duk_uint8_t *) (buf + buf_size - 1);
+
+	DUK_MEMZERO(buf, buf_size);
+
+	for (i = 0; i < fptr_size; i++) {
+		duk_int_t left = (duk_int_t) (p_end - p);
+		duk_uint8_t ch;
+		if (left <= 0) {
+			break;
+		}
+
+		/* Quite approximate but should be useful for little and big endian. */
+#ifdef DUK_USE_INTEGER_BE
+		ch = fptr[i];
+#else
+		ch = fptr[fptr_size - 1 - i];
+#endif
+		p += DUK_SNPRINTF((char *) p, left, "%02lx", (unsigned long) ch);
+	}
+}
+
+#endif  /* DUK_USE_DEBUG */


[41/51] [partial] nifi-minifi-cpp git commit: MINIFI-183 Added civet 1.9.1 sources Added onScheduled hook Added initial two-way TLS-enabled ListenHTTP implementation

Posted by al...@apache.org.
http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/examples/embedded_cpp/embedded_cpp.cpp
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/examples/embedded_cpp/embedded_cpp.cpp b/thirdparty/civetweb-1.9.1/examples/embedded_cpp/embedded_cpp.cpp
new file mode 100644
index 0000000..0144d62
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/examples/embedded_cpp/embedded_cpp.cpp
@@ -0,0 +1,316 @@
+/* Copyright (c) 2013-2017 the Civetweb developers
+ * Copyright (c) 2013 No Face Press, LLC
+ * License http://opensource.org/licenses/mit-license.php MIT License
+ */
+
+// Simple example program on how to use Embedded C++ interface.
+
+#include "CivetServer.h"
+
+#ifdef _WIN32
+#include <windows.h>
+#else
+#include <unistd.h>
+#endif
+
+#define DOCUMENT_ROOT "."
+#define PORT "8081"
+#define EXAMPLE_URI "/example"
+#define EXIT_URI "/exit"
+bool exitNow = false;
+
+class ExampleHandler : public CivetHandler
+{
+  public:
+	bool
+	handleGet(CivetServer *server, struct mg_connection *conn)
+	{
+		mg_printf(conn,
+		          "HTTP/1.1 200 OK\r\nContent-Type: "
+		          "text/html\r\nConnection: close\r\n\r\n");
+		mg_printf(conn, "<html><body>\r\n");
+		mg_printf(conn,
+		          "<h2>This is an example text from a C++ handler</h2>\r\n");
+		mg_printf(conn,
+		          "<p>To see a page from the A handler <a "
+		          "href=\"a\">click here</a></p>\r\n");
+		mg_printf(conn,
+		          "<p>To see a page from the A handler with a parameter "
+		          "<a href=\"a?param=1\">click here</a></p>\r\n");
+		mg_printf(conn,
+		          "<p>To see a page from the A/B handler <a "
+		          "href=\"a/b\">click here</a></p>\r\n");
+		mg_printf(conn,
+		          "<p>To see a page from the *.foo handler <a "
+		          "href=\"xy.foo\">click here</a></p>\r\n");
+		mg_printf(conn,
+		          "<p>To exit <a href=\"%s\">click here</a></p>\r\n",
+		          EXIT_URI);
+		mg_printf(conn, "</body></html>\r\n");
+		return true;
+	}
+};
+
+class ExitHandler : public CivetHandler
+{
+  public:
+	bool
+	handleGet(CivetServer *server, struct mg_connection *conn)
+	{
+		mg_printf(conn,
+		          "HTTP/1.1 200 OK\r\nContent-Type: "
+		          "text/plain\r\nConnection: close\r\n\r\n");
+		mg_printf(conn, "Bye!\n");
+		exitNow = true;
+		return true;
+	}
+};
+
+class AHandler : public CivetHandler
+{
+  private:
+	bool
+	handleAll(const char *method,
+	          CivetServer *server,
+	          struct mg_connection *conn)
+	{
+		std::string s = "";
+		mg_printf(conn,
+		          "HTTP/1.1 200 OK\r\nContent-Type: "
+		          "text/html\r\nConnection: close\r\n\r\n");
+		mg_printf(conn, "<html><body>");
+		mg_printf(conn, "<h2>This is the A handler for \"%s\" !</h2>", method);
+		if (CivetServer::getParam(conn, "param", s)) {
+			mg_printf(conn, "<p>param set to %s</p>", s.c_str());
+		} else {
+			mg_printf(conn, "<p>param not set</p>");
+		}
+		mg_printf(conn, "</body></html>\n");
+		return true;
+	}
+
+  public:
+	bool
+	handleGet(CivetServer *server, struct mg_connection *conn)
+	{
+		return handleAll("GET", server, conn);
+	}
+	bool
+	handlePost(CivetServer *server, struct mg_connection *conn)
+	{
+		return handleAll("POST", server, conn);
+	}
+};
+
+class ABHandler : public CivetHandler
+{
+  public:
+	bool
+	handleGet(CivetServer *server, struct mg_connection *conn)
+	{
+		mg_printf(conn,
+		          "HTTP/1.1 200 OK\r\nContent-Type: "
+		          "text/html\r\nConnection: close\r\n\r\n");
+		mg_printf(conn, "<html><body>");
+		mg_printf(conn, "<h2>This is the AB handler!!!</h2>");
+		mg_printf(conn, "</body></html>\n");
+		return true;
+	}
+};
+
+class FooHandler : public CivetHandler
+{
+  public:
+	bool
+	handleGet(CivetServer *server, struct mg_connection *conn)
+	{
+		/* Handler may access the request info using mg_get_request_info */
+		const struct mg_request_info *req_info = mg_get_request_info(conn);
+
+		mg_printf(conn,
+		          "HTTP/1.1 200 OK\r\nContent-Type: "
+		          "text/html\r\nConnection: close\r\n\r\n");
+
+		mg_printf(conn, "<html><body>\n");
+		mg_printf(conn, "<h2>This is the Foo GET handler!!!</h2>\n");
+		mg_printf(conn,
+		          "<p>The request was:<br><pre>%s %s HTTP/%s</pre></p>\n",
+		          req_info->request_method,
+		          req_info->uri,
+		          req_info->http_version);
+		mg_printf(conn, "</body></html>\n");
+
+		return true;
+	}
+	bool
+	handlePost(CivetServer *server, struct mg_connection *conn)
+	{
+		/* Handler may access the request info using mg_get_request_info */
+		const struct mg_request_info *req_info = mg_get_request_info(conn);
+		long long rlen, wlen;
+		long long nlen = 0;
+		long long tlen = req_info->content_length;
+		char buf[1024];
+
+		mg_printf(conn,
+		          "HTTP/1.1 200 OK\r\nContent-Type: "
+		          "text/html\r\nConnection: close\r\n\r\n");
+
+		mg_printf(conn, "<html><body>\n");
+		mg_printf(conn, "<h2>This is the Foo POST handler!!!</h2>\n");
+		mg_printf(conn,
+		          "<p>The request was:<br><pre>%s %s HTTP/%s</pre></p>\n",
+		          req_info->request_method,
+		          req_info->uri,
+		          req_info->http_version);
+		mg_printf(conn, "<p>Content Length: %li</p>\n", (long)tlen);
+		mg_printf(conn, "<pre>\n");
+
+		while (nlen < tlen) {
+			rlen = tlen - nlen;
+			if (rlen > sizeof(buf)) {
+				rlen = sizeof(buf);
+			}
+			rlen = mg_read(conn, buf, (size_t)rlen);
+			if (rlen <= 0) {
+				break;
+			}
+			wlen = mg_write(conn, buf, (size_t)rlen);
+			if (rlen != rlen) {
+				break;
+			}
+			nlen += wlen;
+		}
+
+		mg_printf(conn, "\n</pre>\n");
+		mg_printf(conn, "</body></html>\n");
+
+		return true;
+	}
+
+    #define fopen_recursive fopen
+
+    bool
+        handlePut(CivetServer *server, struct mg_connection *conn)
+    {
+        /* Handler may access the request info using mg_get_request_info */
+        const struct mg_request_info *req_info = mg_get_request_info(conn);
+        long long rlen, wlen;
+        long long nlen = 0;
+        long long tlen = req_info->content_length;
+        FILE * f;
+        char buf[1024];
+        int fail = 0;
+
+#ifdef _WIN32
+        _snprintf(buf, sizeof(buf), "D:\\somewhere\\%s\\%s", req_info->remote_user, req_info->local_uri);
+        buf[sizeof(buf)-1] = 0;
+        if (strlen(buf)>255) {
+            /* Windows will not work with path > 260 (MAX_PATH), unless we use
+             * the unicode API. However, this is just an example code: A real
+             * code will probably never store anything to D:\\somewhere and
+             * must be adapted to the specific needs anyhow. */
+            fail = 1;
+            f = NULL;
+        } else {
+            f = fopen_recursive(buf, "wb");
+        }
+#else
+        snprintf(buf, sizeof(buf), "~/somewhere/%s/%s", req_info->remote_user, req_info->local_uri);
+        buf[sizeof(buf)-1] = 0;
+        if (strlen(buf)>1020) {
+            /* The string is too long and probably truncated. Make sure an
+             * UTF-8 string is never truncated between the UTF-8 code bytes.
+             * This example code must be adapted to the specific needs. */
+            fail = 1;
+            f = NULL;
+        } else {
+            f = fopen_recursive(buf, "w");
+        }
+#endif
+
+        if (!f) {
+            fail = 1;
+        } else {
+            while (nlen < tlen) {
+                rlen = tlen - nlen;
+                if (rlen > sizeof(buf)) {
+                    rlen = sizeof(buf);
+                }
+                rlen = mg_read(conn, buf, (size_t)rlen);
+                if (rlen <= 0) {
+                    fail = 1;
+                    break;
+                }
+                wlen = fwrite(buf, 1, (size_t)rlen, f);
+                if (rlen != rlen) {
+                    fail = 1;
+                    break;
+                }
+                nlen += wlen;
+            }
+            fclose(f);
+        }
+
+        if (fail) {
+            mg_printf(conn,
+                "HTTP/1.1 409 Conflict\r\n"
+                "Content-Type: text/plain\r\n"
+                "Connection: close\r\n\r\n");
+        } else {
+            mg_printf(conn,
+                "HTTP/1.1 201 Created\r\n"
+                "Content-Type: text/plain\r\n"
+                "Connection: close\r\n\r\n");
+        }
+
+        return true;
+    }
+};
+
+
+int
+main(int argc, char *argv[])
+{
+	const char *options[] = {
+	    "document_root", DOCUMENT_ROOT, "listening_ports", PORT, 0};
+    
+    std::vector<std::string> cpp_options;
+    for (int i=0; i<(sizeof(options)/sizeof(options[0])-1); i++) {
+        cpp_options.push_back(options[i]);
+    }
+
+	// CivetServer server(options); // <-- C style start
+    CivetServer server(cpp_options); // <-- C++ style start
+
+	ExampleHandler h_ex;
+	server.addHandler(EXAMPLE_URI, h_ex);
+
+	ExitHandler h_exit;
+	server.addHandler(EXIT_URI, h_exit);
+
+	AHandler h_a;
+	server.addHandler("/a", h_a);
+
+	ABHandler h_ab;
+	server.addHandler("/a/b", h_ab);
+
+	FooHandler h_foo;
+	server.addHandler("", h_foo);
+
+	printf("Browse files at http://localhost:%s/\n", PORT);
+	printf("Run example at http://localhost:%s%s\n", PORT, EXAMPLE_URI);
+	printf("Exit at http://localhost:%s%s\n", PORT, EXIT_URI);
+
+	while (!exitNow) {
+#ifdef _WIN32
+		Sleep(1000);
+#else
+		sleep(1);
+#endif
+	}
+
+	printf("Bye!\n");
+
+	return 0;
+}

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/format.bat
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/format.bat b/thirdparty/civetweb-1.9.1/format.bat
new file mode 100644
index 0000000..e1ce640
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/format.bat
@@ -0,0 +1,33 @@
+#!/bin/sh
+clang-format -i src/civetweb.c
+clang-format -i src/main.c
+clang-format -i src/CivetServer.cpp
+clang-format -i src/civetweb_private_lua.h
+clang-format -i src/md5.inl
+clang-format -i src/sha1.inl
+clang-format -i src/mod_lua.inl
+clang-format -i src/mod_duktape.inl
+clang-format -i src/timer.inl
+clang-format -i src/handle_form.inl
+
+clang-format -i src/third_party/civetweb_lua.h
+
+clang-format -i include/civetweb.h
+clang-format -i include/CivetServer.h
+
+clang-format -i test/public_func.h
+clang-format -i test/public_func.c
+clang-format -i test/public_server.h
+clang-format -i test/public_server.c
+clang-format -i test/private.h
+clang-format -i test/private.c
+clang-format -i test/private_exe.h
+clang-format -i test/private_exe.c
+clang-format -i test/shared.h
+clang-format -i test/shared.c
+clang-format -i test/timertest.h
+clang-format -i test/timertest.c
+clang-format -i test/civetweb_check.h
+clang-format -i test/main.c
+
+clang-format -i examples/embedded_c/embedded_c.c

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/include/CivetServer.h
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/include/CivetServer.h b/thirdparty/civetweb-1.9.1/include/CivetServer.h
new file mode 100644
index 0000000..68191e0
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/include/CivetServer.h
@@ -0,0 +1,597 @@
+/* Copyright (c) 2013-2017 the Civetweb developers
+ * Copyright (c) 2013 No Face Press, LLC
+ *
+ * License http://opensource.org/licenses/mit-license.php MIT License
+ */
+
+#ifndef _CIVETWEB_SERVER_H_
+#define _CIVETWEB_SERVER_H_
+#ifdef __cplusplus
+
+#include "civetweb.h"
+#include <map>
+#include <string>
+#include <vector>
+#include <stdexcept>
+
+// forward declaration
+class CivetServer;
+
+/**
+ * Exception class for thrown exceptions within the CivetHandler object.
+ */
+class CIVETWEB_API CivetException : public std::runtime_error
+{
+  public:
+	CivetException(const std::string &msg) : std::runtime_error(msg)
+	{
+	}
+};
+
+/**
+ * Basic interface for a URI request handler.  Handlers implementations
+ * must be reentrant.
+ */
+class CIVETWEB_API CivetHandler
+{
+  public:
+	/**
+	 * Destructor
+	 */
+	virtual ~CivetHandler()
+	{
+	}
+
+	/**
+	 * Callback method for GET request.
+	 *
+	 * @param server - the calling server
+	 * @param conn - the connection information
+	 * @returns true if implemented, false otherwise
+	 */
+	virtual bool handleGet(CivetServer *server, struct mg_connection *conn);
+
+	/**
+	 * Callback method for POST request.
+	 *
+	 * @param server - the calling server
+	 * @param conn - the connection information
+	 * @returns true if implemented, false otherwise
+	 */
+	virtual bool handlePost(CivetServer *server, struct mg_connection *conn);
+
+	/**
+	 * Callback method for HEAD request.
+	 *
+	 * @param server - the calling server
+	 * @param conn - the connection information
+	 * @returns true if implemented, false otherwise
+	 */
+	virtual bool handleHead(CivetServer *server, struct mg_connection *conn);
+
+	/**
+	 * Callback method for PUT request.
+	 *
+	 * @param server - the calling server
+	 * @param conn - the connection information
+	 * @returns true if implemented, false otherwise
+	 */
+	virtual bool handlePut(CivetServer *server, struct mg_connection *conn);
+
+	/**
+	 * Callback method for DELETE request.
+	 *
+	 * @param server - the calling server
+	 * @param conn - the connection information
+	 * @returns true if implemented, false otherwise
+	 */
+	virtual bool handleDelete(CivetServer *server, struct mg_connection *conn);
+
+	/**
+	 * Callback method for OPTIONS request.
+	 *
+	 * @param server - the calling server
+	 * @param conn - the connection information
+	 * @returns true if implemented, false otherwise
+	 */
+	virtual bool handleOptions(CivetServer *server, struct mg_connection *conn);
+
+	/**
+	 * Callback method for PATCH request.
+	 *
+	 * @param server - the calling server
+	 * @param conn - the connection information
+	 * @returns true if implemented, false otherwise
+	 */
+	virtual bool handlePatch(CivetServer *server, struct mg_connection *conn);
+};
+
+/**
+ * Basic interface for a URI authorization handler.  Handler implementations
+ * must be reentrant.
+ */
+class CIVETWEB_API CivetAuthHandler
+{
+  public:
+	/**
+	 * Destructor
+	 */
+	virtual ~CivetAuthHandler()
+	{
+	}
+
+	/**
+	 * Callback method for authorization requests. It is up the this handler
+	 * to generate 401 responses if authorization fails.
+	 *
+	 * @param server - the calling server
+	 * @param conn - the connection information
+	 * @returns true if authorization succeeded, false otherwise
+	 */
+	virtual bool authorize(CivetServer *server, struct mg_connection *conn) = 0;
+};
+
+/**
+ * Basic interface for a websocket handler.  Handlers implementations
+ * must be reentrant.
+ */
+class CIVETWEB_API CivetWebSocketHandler
+{
+  public:
+	/**
+	 * Destructor
+	 */
+	virtual ~CivetWebSocketHandler()
+	{
+	}
+
+	/**
+	 * Callback method for when the client intends to establish a websocket
+	 *connection, before websocket handshake.
+	 *
+	 * @param server - the calling server
+	 * @param conn - the connection information
+	 * @returns true to keep socket open, false to close it
+	 */
+	virtual bool handleConnection(CivetServer *server,
+	                              const struct mg_connection *conn);
+
+	/**
+	 * Callback method for when websocket handshake is successfully completed,
+	 *and connection is ready for data exchange.
+	 *
+	 * @param server - the calling server
+	 * @param conn - the connection information
+	 */
+	virtual void handleReadyState(CivetServer *server,
+	                              struct mg_connection *conn);
+
+	/**
+	 * Callback method for when a data frame has been received from the client.
+	 *
+	 * @param server - the calling server
+	 * @param conn - the connection information
+	 * @bits: first byte of the websocket frame, see websocket RFC at
+	 *http://tools.ietf.org/html/rfc6455, section 5.2
+	 * @data, data_len: payload, with mask (if any) already applied.
+	 * @returns true to keep socket open, false to close it
+	 */
+	virtual bool handleData(CivetServer *server,
+	                        struct mg_connection *conn,
+	                        int bits,
+	                        char *data,
+	                        size_t data_len);
+
+	/**
+	 * Callback method for when the connection is closed.
+	 *
+	 * @param server - the calling server
+	 * @param conn - the connection information
+	 */
+	virtual void handleClose(CivetServer *server,
+	                         const struct mg_connection *conn);
+};
+
+/**
+ * CivetCallbacks
+ *
+ * wrapper for mg_callbacks
+ */
+struct CIVETWEB_API CivetCallbacks : public mg_callbacks {
+	CivetCallbacks();
+};
+
+/**
+ * CivetServer
+ *
+ * Basic class for embedded web server.  This has an URL mapping built-in.
+ */
+class CIVETWEB_API CivetServer
+{
+  public:
+	/**
+	 * Constructor
+	 *
+	 * This automatically starts the sever.
+	 * It is good practice to call getContext() after this in case there
+	 * were errors starting the server.
+	 *
+	 * Note: CivetServer should not be used as a static instance in a Windows
+	 * DLL, since the constructor creates threads and the destructor joins
+	 * them again (creating/joining threads should not be done in static
+	 * constructors).
+	 *
+	 * @param options - the web server options.
+	 * @param callbacks - optional web server callback methods.
+	 *
+	 * @throws CivetException
+	 */
+	CivetServer(const char **options,
+	            const struct CivetCallbacks *callbacks = 0);
+	CivetServer(std::vector<std::string> options,
+	            const struct CivetCallbacks *callbacks = 0);
+
+	/**
+	 * Destructor
+	 */
+	virtual ~CivetServer();
+
+	/**
+	 * close()
+	 *
+	 * Stops server and frees resources.
+	 */
+	void close();
+
+	/**
+	 * getContext()
+	 *
+	 * @return the context or 0 if not running.
+	 */
+	const struct mg_context *
+	getContext() const
+	{
+		return context;
+	}
+
+	/**
+	 * addHandler(const std::string &, CivetHandler *)
+	 *
+	 * Adds a URI handler.  If there is existing URI handler, it will
+	 * be replaced with this one.
+	 *
+	 * URI's are ordered and prefix (REST) URI's are supported.
+	 *
+	 *  @param uri - URI to match.
+	 *  @param handler - handler instance to use.
+	 */
+	void addHandler(const std::string &uri, CivetHandler *handler);
+
+	void
+	addHandler(const std::string &uri, CivetHandler &handler)
+	{
+		addHandler(uri, &handler);
+	}
+
+	/**
+	 * addWebSocketHandler
+	 *
+	 * Adds a WebSocket handler for a specific URI.  If there is existing URI
+	 *handler, it will
+	 * be replaced with this one.
+	 *
+	 * URI's are ordered and prefix (REST) URI's are supported.
+	 *
+	 *  @param uri - URI to match.
+	 *  @param handler - handler instance to use.
+	 */
+	void addWebSocketHandler(const std::string &uri,
+	                         CivetWebSocketHandler *handler);
+
+	void
+	addWebSocketHandler(const std::string &uri, CivetWebSocketHandler &handler)
+	{
+		addWebSocketHandler(uri, &handler);
+	}
+
+	/**
+	 * removeHandler(const std::string &)
+	 *
+	 * Removes a handler.
+	 *
+	 * @param uri - the exact URL used in addHandler().
+	 */
+	void removeHandler(const std::string &uri);
+
+	/**
+	 * removeWebSocketHandler(const std::string &)
+	 *
+	 * Removes a web socket handler.
+	 *
+	 * @param uri - the exact URL used in addWebSocketHandler().
+	 */
+	void removeWebSocketHandler(const std::string &uri);
+
+	/**
+	 * addAuthHandler(const std::string &, CivetAuthHandler *)
+	 *
+	 * Adds a URI authorization handler.  If there is existing URI authorization
+	 * handler, it will be replaced with this one.
+	 *
+	 * URI's are ordered and prefix (REST) URI's are supported.
+	 *
+	 * @param uri - URI to match.
+	 * @param handler - authorization handler instance to use.
+	 */
+	void addAuthHandler(const std::string &uri, CivetAuthHandler *handler);
+
+	void
+	addAuthHandler(const std::string &uri, CivetAuthHandler &handler)
+	{
+		addAuthHandler(uri, &handler);
+	}
+
+	/**
+	 * removeAuthHandler(const std::string &)
+	 *
+	 * Removes an authorization handler.
+	 *
+	 * @param uri - the exact URL used in addAuthHandler().
+	 */
+	void removeAuthHandler(const std::string &uri);
+
+	/**
+	 * getListeningPorts()
+	 *
+	 * Returns a list of ports that are listening
+	 *
+	 * @return A vector of ports
+	 */
+
+	std::vector<int> getListeningPorts();
+
+	/**
+	 * getCookie(struct mg_connection *conn, const std::string &cookieName,
+	 *std::string &cookieValue)
+	 *
+	 * Puts the cookie value string that matches the cookie name in the
+	 *cookieValue destinaton string.
+	 *
+	 * @param conn - the connection information
+	 * @param cookieName - cookie name to get the value from
+	 * @param cookieValue - cookie value is returned using thiis reference
+	 * @returns the size of the cookie value string read.
+	*/
+	static int getCookie(struct mg_connection *conn,
+	                     const std::string &cookieName,
+	                     std::string &cookieValue);
+
+	/**
+	 * getHeader(struct mg_connection *conn, const std::string &headerName)
+	 * @param conn - the connection information
+	 * @param headerName - header name to get the value from
+	 * @returns a char array whcih contains the header value as string
+	*/
+	static const char *getHeader(struct mg_connection *conn,
+	                             const std::string &headerName);
+
+	/**
+	 * getParam(struct mg_connection *conn, const char *, std::string &, size_t)
+	 *
+	 * Returns a query paramter contained in the supplied buffer.  The
+	 * occurance value is a zero-based index of a particular key name.  This
+	 * should not be confused with the index over all of the keys.  Note that
+	 *this
+	 * function assumes that parameters are sent as text in http query string
+	 * format, which is the default for web forms. This function will work for
+	 * html forms with method="GET" and method="POST" attributes. In other
+	 *cases,
+	 * you may use a getParam version that directly takes the data instead of
+	 *the
+	 * connection as a first argument.
+	 *
+	 * @param conn - parameters are read from the data sent through this
+	 *connection
+	 * @param name - the key to search for
+	 * @param dst - the destination string
+	 * @param occurrence - the occurrence of the selected name in the query (0
+	 *based).
+	 * @return true if key was found
+	 */
+	static bool getParam(struct mg_connection *conn,
+	                     const char *name,
+	                     std::string &dst,
+	                     size_t occurrence = 0);
+
+	/**
+	 * getParam(const std::string &, const char *, std::string &, size_t)
+	 *
+	 * Returns a query paramter contained in the supplied buffer.  The
+	 * occurance value is a zero-based index of a particular key name.  This
+	 * should not be confused with the index over all of the keys.
+	 *
+	 * @param data - the query string (text)
+	 * @param name - the key to search for
+	 * @param dst - the destination string
+	 * @param occurrence - the occurrence of the selected name in the query (0
+	 *based).
+	 * @return true if key was found
+	 */
+	static bool
+	getParam(const std::string &data,
+	         const char *name,
+	         std::string &dst,
+	         size_t occurrence = 0)
+	{
+		return getParam(data.c_str(), data.length(), name, dst, occurrence);
+	}
+
+	/**
+	 * getParam(const char *, size_t, const char *, std::string &, size_t)
+	 *
+	 * Returns a query paramter contained in the supplied buffer.  The
+	 * occurance value is a zero-based index of a particular key name.  This
+	 * should not be confused with the index over all of the keys.
+	 *
+	 * @param data the - query string (text)
+	 * @param data_len - length of the query string
+	 * @param name - the key to search for
+	 * @param dst - the destination string
+	 * @param occurrence - the occurrence of the selected name in the query (0
+	 *based).
+	 * @return true if key was found
+	 */
+	static bool getParam(const char *data,
+	                     size_t data_len,
+	                     const char *name,
+	                     std::string &dst,
+	                     size_t occurrence = 0);
+
+	/**
+	 * urlDecode(const std::string &, std::string &, bool)
+	 *
+	 * @param src - string to be decoded
+	 * @param dst - destination string
+	 * @param is_form_url_encoded - true if form url encoded
+	 *       form-url-encoded data differs from URI encoding in a way that it
+	 *       uses '+' as character for space, see RFC 1866 section 8.2.1
+	 *       http://ftp.ics.uci.edu/pub/ietf/html/rfc1866.txt
+	 */
+	static void
+	urlDecode(const std::string &src,
+	          std::string &dst,
+	          bool is_form_url_encoded = true)
+	{
+		urlDecode(src.c_str(), src.length(), dst, is_form_url_encoded);
+	}
+
+	/**
+	 * urlDecode(const char *, size_t, std::string &, bool)
+	 *
+	 * @param src - buffer to be decoded
+	 * @param src_len - length of buffer to be decoded
+	 * @param dst - destination string
+	 * @param is_form_url_encoded - true if form url encoded
+	 *       form-url-encoded data differs from URI encoding in a way that it
+	 *       uses '+' as character for space, see RFC 1866 section 8.2.1
+	 *       http://ftp.ics.uci.edu/pub/ietf/html/rfc1866.txt
+	 */
+	static void urlDecode(const char *src,
+	                      size_t src_len,
+	                      std::string &dst,
+	                      bool is_form_url_encoded = true);
+
+	/**
+	 * urlDecode(const char *, std::string &, bool)
+	 *
+	 * @param src - buffer to be decoded (0 terminated)
+	 * @param dst - destination string
+	 * @param is_form_url_encoded true - if form url encoded
+	 *       form-url-encoded data differs from URI encoding in a way that it
+	 *       uses '+' as character for space, see RFC 1866 section 8.2.1
+	 *       http://ftp.ics.uci.edu/pub/ietf/html/rfc1866.txt
+	 */
+	static void urlDecode(const char *src,
+	                      std::string &dst,
+	                      bool is_form_url_encoded = true);
+
+	/**
+	 * urlEncode(const std::string &, std::string &, bool)
+	 *
+	 * @param src - buffer to be encoded
+	 * @param dst - destination string
+	 * @param append - true if string should not be cleared before encoding.
+	 */
+	static void
+	urlEncode(const std::string &src, std::string &dst, bool append = false)
+	{
+		urlEncode(src.c_str(), src.length(), dst, append);
+	}
+
+	/**
+	 * urlEncode(const char *, size_t, std::string &, bool)
+	 *
+	 * @param src - buffer to be encoded (0 terminated)
+	 * @param dst - destination string
+	 * @param append - true if string should not be cleared before encoding.
+	 */
+	static void
+	urlEncode(const char *src, std::string &dst, bool append = false);
+
+	/**
+	 * urlEncode(const char *, size_t, std::string &, bool)
+	 *
+	 * @param src - buffer to be encoded
+	 * @param src_len - length of buffer to be decoded
+	 * @param dst - destination string
+	 * @param append - true if string should not be cleared before encoding.
+	 */
+	static void urlEncode(const char *src,
+	                      size_t src_len,
+	                      std::string &dst,
+	                      bool append = false);
+
+  protected:
+	class CivetConnection
+	{
+	  public:
+		char *postData;
+		unsigned long postDataLen;
+
+		CivetConnection();
+		~CivetConnection();
+	};
+
+	struct mg_context *context;
+	std::map<struct mg_connection *, class CivetConnection> connections;
+
+  private:
+	/**
+	 * requestHandler(struct mg_connection *, void *cbdata)
+	 *
+	 * Handles the incomming request.
+	 *
+	 * @param conn - the connection information
+	 * @param cbdata - pointer to the CivetHandler instance.
+	 * @returns 0 if implemented, false otherwise
+	 */
+	static int requestHandler(struct mg_connection *conn, void *cbdata);
+
+	static int webSocketConnectionHandler(const struct mg_connection *conn,
+	                                      void *cbdata);
+	static void webSocketReadyHandler(struct mg_connection *conn, void *cbdata);
+	static int webSocketDataHandler(struct mg_connection *conn,
+	                                int bits,
+	                                char *data,
+	                                size_t data_len,
+	                                void *cbdata);
+	static void webSocketCloseHandler(const struct mg_connection *conn,
+	                                  void *cbdata);
+	/**
+	 * authHandler(struct mg_connection *, void *cbdata)
+	 *
+	 * Handles the authorization requests.
+	 *
+	 * @param conn - the connection information
+	 * @param cbdata - pointer to the CivetAuthHandler instance.
+	 * @returns 1 if authorized, 0 otherwise
+	 */
+	static int authHandler(struct mg_connection *conn, void *cbdata);
+
+	/**
+	 * closeHandler(struct mg_connection *)
+	 *
+	 * Handles closing a request (internal handler)
+	 *
+	 * @param conn - the connection information
+	 */
+	static void closeHandler(const struct mg_connection *conn);
+
+	/**
+	 * Stores the user provided close handler
+	 */
+	void (*userCloseHandler)(const struct mg_connection *conn);
+};
+
+#endif /*  __cplusplus */
+#endif /* _CIVETWEB_SERVER_H_ */

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/include/civetweb.h
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/include/civetweb.h b/thirdparty/civetweb-1.9.1/include/civetweb.h
new file mode 100644
index 0000000..7254587
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/include/civetweb.h
@@ -0,0 +1,1121 @@
+/* Copyright (c) 2013-2017 the Civetweb developers
+ * Copyright (c) 2004-2013 Sergey Lyubka
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#ifndef CIVETWEB_HEADER_INCLUDED
+#define CIVETWEB_HEADER_INCLUDED
+
+#define CIVETWEB_VERSION "1.9.1"
+#define CIVETWEB_VERSION_MAJOR (1)
+#define CIVETWEB_VERSION_MINOR (9)
+#define CIVETWEB_VERSION_PATCH (1)
+
+#ifndef CIVETWEB_API
+#if defined(_WIN32)
+#if defined(CIVETWEB_DLL_EXPORTS)
+#define CIVETWEB_API __declspec(dllexport)
+#elif defined(CIVETWEB_DLL_IMPORTS)
+#define CIVETWEB_API __declspec(dllimport)
+#else
+#define CIVETWEB_API
+#endif
+#elif __GNUC__ >= 4
+#define CIVETWEB_API __attribute__((visibility("default")))
+#else
+#define CIVETWEB_API
+#endif
+#endif
+
+#include <stdio.h>
+#include <stddef.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+
+/* Initialize this library. This should be called once before any other
+ * function from this library. This function is not guaranteed to be
+ * thread safe.
+ * Parameters:
+ *   features: bit mask for features to be initialized.
+ * Return value:
+ *   initialized features
+ *   0: error
+ */
+CIVETWEB_API unsigned mg_init_library(unsigned features);
+
+
+/* Un-initialize this library.
+ * Return value:
+ *   0: error
+ */
+CIVETWEB_API unsigned mg_exit_library(void);
+
+
+struct mg_context;    /* Handle for the HTTP service itself */
+struct mg_connection; /* Handle for the individual connection */
+
+
+/* This structure contains information about the HTTP request. */
+struct mg_request_info {
+	const char *request_method; /* "GET", "POST", etc */
+	const char *request_uri;    /* URL-decoded URI (absolute or relative,
+	                             * as in the request) */
+	const char *local_uri;      /* URL-decoded URI (relative). Can be NULL
+	                             * if the request_uri does not address a
+	                             * resource at the server host. */
+	const char *uri;            /* Deprecated: use local_uri instead */
+	const char *http_version;   /* E.g. "1.0", "1.1" */
+	const char *query_string;   /* URL part after '?', not including '?', or
+	                               NULL */
+	const char *remote_user;    /* Authenticated user, or NULL if no auth
+	                               used */
+	char remote_addr[48];       /* Client's IP address as a string. */
+
+#if defined(MG_LEGACY_INTERFACE)
+	long remote_ip; /* Client's IP address. Deprecated: use remote_addr instead
+	                   */
+#endif
+
+	long long content_length; /* Length (in bytes) of the request body,
+	                             can be -1 if no length was given. */
+	int remote_port;          /* Client's port */
+	int is_ssl;               /* 1 if SSL-ed, 0 if not */
+	void *user_data;          /* User data pointer passed to mg_start() */
+	void *conn_data;          /* Connection-specific user data */
+
+	int num_headers; /* Number of HTTP headers */
+	struct mg_header {
+		const char *name;  /* HTTP header name */
+		const char *value; /* HTTP header value */
+	} http_headers[64];    /* Maximum 64 headers */
+
+	struct client_cert *client_cert; /* Client certificate information */
+
+	const char *acceptedWebSocketSubprotocol; /* websocket subprotocol,
+	                                           * accepted during handshake */
+};
+
+
+/* Client certificate information (part of mg_request_info) */
+struct client_cert {
+	const char *subject;
+	const char *issuer;
+	const char *serial;
+	const char *finger;
+};
+
+
+/* This structure needs to be passed to mg_start(), to let civetweb know
+   which callbacks to invoke. For a detailed description, see
+   https://github.com/civetweb/civetweb/blob/master/docs/UserManual.md */
+struct mg_callbacks {
+	/* Called when civetweb has received new HTTP request.
+	   If the callback returns one, it must process the request
+	   by sending valid HTTP headers and a body. Civetweb will not do
+	   any further processing. Otherwise it must return zero.
+	   Note that since V1.7 the "begin_request" function is called
+	   before an authorization check. If an authorization check is
+	   required, use a request_handler instead.
+	   Return value:
+	     0: civetweb will process the request itself. In this case,
+	        the callback must not send any data to the client.
+	     1-999: callback already processed the request. Civetweb will
+	            not send any data after the callback returned. The
+	            return code is stored as a HTTP status code for the
+	            access log. */
+	int (*begin_request)(struct mg_connection *);
+
+	/* Called when civetweb has finished processing request. */
+	void (*end_request)(const struct mg_connection *, int reply_status_code);
+
+	/* Called when civetweb is about to log a message. If callback returns
+	   non-zero, civetweb does not log anything. */
+	int (*log_message)(const struct mg_connection *, const char *message);
+
+	/* Called when civetweb is about to log access. If callback returns
+	   non-zero, civetweb does not log anything. */
+	int (*log_access)(const struct mg_connection *, const char *message);
+
+	/* Called when civetweb initializes SSL library.
+	   Parameters:
+	     user_data: parameter user_data passed when starting the server.
+	   Return value:
+	     0: civetweb will set up the SSL certificate.
+	     1: civetweb assumes the callback already set up the certificate.
+	    -1: initializing ssl fails. */
+	int (*init_ssl)(void *ssl_context, void *user_data);
+
+#if defined(MG_LEGACY_INTERFACE)
+	/* Called when websocket request is received, before websocket handshake.
+	   Return value:
+	     0: civetweb proceeds with websocket handshake.
+	     1: connection is closed immediately.
+	   This callback is deprecated: Use mg_set_websocket_handler instead. */
+	int (*websocket_connect)(const struct mg_connection *);
+
+	/* Called when websocket handshake is successfully completed, and
+	   connection is ready for data exchange.
+	   This callback is deprecated: Use mg_set_websocket_handler instead. */
+	void (*websocket_ready)(struct mg_connection *);
+
+	/* Called when data frame has been received from the client.
+	   Parameters:
+	     bits: first byte of the websocket frame, see websocket RFC at
+	           http://tools.ietf.org/html/rfc6455, section 5.2
+	     data, data_len: payload, with mask (if any) already applied.
+	   Return value:
+	     1: keep this websocket connection open.
+	     0: close this websocket connection.
+	   This callback is deprecated: Use mg_set_websocket_handler instead. */
+	int (*websocket_data)(struct mg_connection *,
+	                      int bits,
+	                      char *data,
+	                      size_t data_len);
+#endif /* MG_LEGACY_INTERFACE */
+
+	/* Called when civetweb is closing a connection.  The per-context mutex is
+	   locked when this is invoked.  This is primarily useful for noting when
+	   a websocket is closing and removing it from any application-maintained
+	   list of clients.
+	   Using this callback for websocket connections is deprecated: Use
+	   mg_set_websocket_handler instead. */
+	void (*connection_close)(const struct mg_connection *);
+
+	/* Called when civetweb tries to open a file. Used to intercept file open
+	   calls, and serve file data from memory instead.
+	   Parameters:
+	      path:     Full path to the file to open.
+	      data_len: Placeholder for the file size, if file is served from
+	                memory.
+	   Return value:
+	     NULL: do not serve file from memory, proceed with normal file open.
+	     non-NULL: pointer to the file contents in memory. data_len must be
+	       initialized with the size of the memory block. */
+	const char *(*open_file)(const struct mg_connection *,
+	                         const char *path,
+	                         size_t *data_len);
+
+	/* Called when civetweb is about to serve Lua server page, if
+	   Lua support is enabled.
+	   Parameters:
+	     lua_context: "lua_State *" pointer. */
+	void (*init_lua)(const struct mg_connection *, void *lua_context);
+
+#if defined(MG_LEGACY_INTERFACE)
+	/* Called when civetweb has uploaded a file to a temporary directory as a
+	   result of mg_upload() call.
+	   Note that mg_upload is deprecated. Use mg_handle_form_request instead.
+	   Parameters:
+	     file_name: full path name to the uploaded file. */
+	void (*upload)(struct mg_connection *, const char *file_name);
+#endif
+
+	/* Called when civetweb is about to send HTTP error to the client.
+	   Implementing this callback allows to create custom error pages.
+	   Parameters:
+	     status: HTTP error status code.
+	   Return value:
+	     1: run civetweb error handler.
+	     0: callback already handled the error. */
+	int (*http_error)(struct mg_connection *, int status);
+
+	/* Called after civetweb context has been created, before requests
+	   are processed.
+	   Parameters:
+	     ctx: context handle */
+	void (*init_context)(const struct mg_context *ctx);
+
+	/* Called when a new worker thread is initialized.
+	   Parameters:
+	     ctx: context handle
+	     thread_type:
+	       0 indicates the master thread
+	       1 indicates a worker thread handling client connections
+	       2 indicates an internal helper thread (timer thread)
+	       */
+	void (*init_thread)(const struct mg_context *ctx, int thread_type);
+
+	/* Called when civetweb context is deleted.
+	   Parameters:
+	     ctx: context handle */
+	void (*exit_context)(const struct mg_context *ctx);
+};
+
+
+/* Start web server.
+
+   Parameters:
+     callbacks: mg_callbacks structure with user-defined callbacks.
+     options: NULL terminated list of option_name, option_value pairs that
+              specify Civetweb configuration parameters.
+
+   Side-effects: on UNIX, ignores SIGCHLD and SIGPIPE signals. If custom
+      processing is required for these, signal handlers must be set up
+      after calling mg_start().
+
+
+   Example:
+     const char *options[] = {
+       "document_root", "/var/www",
+       "listening_ports", "80,443s",
+       NULL
+     };
+     struct mg_context *ctx = mg_start(&my_func, NULL, options);
+
+   Refer to https://github.com/civetweb/civetweb/blob/master/docs/UserManual.md
+   for the list of valid option and their possible values.
+
+   Return:
+     web server context, or NULL on error. */
+CIVETWEB_API struct mg_context *mg_start(const struct mg_callbacks *callbacks,
+                                         void *user_data,
+                                         const char **configuration_options);
+
+
+/* Stop the web server.
+
+   Must be called last, when an application wants to stop the web server and
+   release all associated resources. This function blocks until all Civetweb
+   threads are stopped. Context pointer becomes invalid. */
+CIVETWEB_API void mg_stop(struct mg_context *);
+
+
+/* mg_request_handler
+
+   Called when a new request comes in.  This callback is URI based
+   and configured with mg_set_request_handler().
+
+   Parameters:
+      conn: current connection information.
+      cbdata: the callback data configured with mg_set_request_handler().
+   Returns:
+      0: the handler could not handle the request, so fall through.
+      1 - 999: the handler processed the request. The return code is
+               stored as a HTTP status code for the access log. */
+typedef int (*mg_request_handler)(struct mg_connection *conn, void *cbdata);
+
+
+/* mg_set_request_handler
+
+   Sets or removes a URI mapping for a request handler.
+   This function uses mg_lock_context internally.
+
+   URI's are ordered and prefixed URI's are supported. For example,
+   consider two URIs: /a/b and /a
+           /a   matches /a
+           /a/b matches /a/b
+           /a/c matches /a
+
+   Parameters:
+      ctx: server context
+      uri: the URI (exact or pattern) for the handler
+      handler: the callback handler to use when the URI is requested.
+               If NULL, an already registered handler for this URI will be
+   removed.
+               The URI used to remove a handler must match exactly the one used
+   to
+               register it (not only a pattern match).
+      cbdata: the callback data to give to the handler when it is called. */
+CIVETWEB_API void mg_set_request_handler(struct mg_context *ctx,
+                                         const char *uri,
+                                         mg_request_handler handler,
+                                         void *cbdata);
+
+
+/* Callback types for websocket handlers in C/C++.
+
+   mg_websocket_connect_handler
+       Is called when the client intends to establish a websocket connection,
+       before websocket handshake.
+       Return value:
+         0: civetweb proceeds with websocket handshake.
+         1: connection is closed immediately.
+
+   mg_websocket_ready_handler
+       Is called when websocket handshake is successfully completed, and
+       connection is ready for data exchange.
+
+   mg_websocket_data_handler
+       Is called when a data frame has been received from the client.
+       Parameters:
+         bits: first byte of the websocket frame, see websocket RFC at
+               http://tools.ietf.org/html/rfc6455, section 5.2
+         data, data_len: payload, with mask (if any) already applied.
+       Return value:
+         1: keep this websocket connection open.
+         0: close this websocket connection.
+
+   mg_connection_close_handler
+       Is called, when the connection is closed.*/
+typedef int (*mg_websocket_connect_handler)(const struct mg_connection *,
+                                            void *);
+typedef void (*mg_websocket_ready_handler)(struct mg_connection *, void *);
+typedef int (*mg_websocket_data_handler)(struct mg_connection *,
+                                         int,
+                                         char *,
+                                         size_t,
+                                         void *);
+typedef void (*mg_websocket_close_handler)(const struct mg_connection *,
+                                           void *);
+
+/* struct mg_websocket_subprotocols
+ *
+ * List of accepted subprotocols
+ */
+struct mg_websocket_subprotocols {
+	int nb_subprotocols;
+	char **subprotocols;
+};
+
+/* mg_set_websocket_handler
+
+   Set or remove handler functions for websocket connections.
+   This function works similar to mg_set_request_handler - see there. */
+CIVETWEB_API void
+mg_set_websocket_handler(struct mg_context *ctx,
+                         const char *uri,
+                         mg_websocket_connect_handler connect_handler,
+                         mg_websocket_ready_handler ready_handler,
+                         mg_websocket_data_handler data_handler,
+                         mg_websocket_close_handler close_handler,
+                         void *cbdata);
+
+/* mg_set_websocket_handler
+
+   Set or remove handler functions for websocket connections.
+   This function works similar to mg_set_request_handler - see there. */
+CIVETWEB_API void mg_set_websocket_handler_with_subprotocols(
+    struct mg_context *ctx,
+    const char *uri,
+    struct mg_websocket_subprotocols *subprotocols,
+    mg_websocket_connect_handler connect_handler,
+    mg_websocket_ready_handler ready_handler,
+    mg_websocket_data_handler data_handler,
+    mg_websocket_close_handler close_handler,
+    void *cbdata);
+
+
+/* mg_authorization_handler
+
+   Some description here
+
+   Parameters:
+      conn: current connection information.
+      cbdata: the callback data configured with mg_set_request_handler().
+   Returns:
+      0: access denied
+      1: access granted
+ */
+typedef int (*mg_authorization_handler)(struct mg_connection *conn,
+                                        void *cbdata);
+
+
+/* mg_set_auth_handler
+
+   Sets or removes a URI mapping for an authorization handler.
+   This function works similar to mg_set_request_handler - see there. */
+CIVETWEB_API void mg_set_auth_handler(struct mg_context *ctx,
+                                      const char *uri,
+                                      mg_authorization_handler handler,
+                                      void *cbdata);
+
+
+/* Get the value of particular configuration parameter.
+   The value returned is read-only. Civetweb does not allow changing
+   configuration at run time.
+   If given parameter name is not valid, NULL is returned. For valid
+   names, return value is guaranteed to be non-NULL. If parameter is not
+   set, zero-length string is returned. */
+CIVETWEB_API const char *mg_get_option(const struct mg_context *ctx,
+                                       const char *name);
+
+
+/* Get context from connection. */
+CIVETWEB_API struct mg_context *
+mg_get_context(const struct mg_connection *conn);
+
+
+/* Get user data passed to mg_start from context. */
+CIVETWEB_API void *mg_get_user_data(const struct mg_context *ctx);
+
+
+/* Set user data for the current connection. */
+CIVETWEB_API void mg_set_user_connection_data(struct mg_connection *conn,
+                                              void *data);
+
+
+/* Get user data set for the current connection. */
+CIVETWEB_API void *
+mg_get_user_connection_data(const struct mg_connection *conn);
+
+
+#if defined(MG_LEGACY_INTERFACE)
+/* Return array of strings that represent valid configuration options.
+   For each option, option name and default value is returned, i.e. the
+   number of entries in the array equals to number_of_options x 2.
+   Array is NULL terminated. */
+/* Deprecated: Use mg_get_valid_options instead. */
+CIVETWEB_API const char **mg_get_valid_option_names(void);
+#endif
+
+
+struct mg_option {
+	const char *name;
+	int type;
+	const char *default_value;
+};
+
+
+enum {
+	CONFIG_TYPE_UNKNOWN = 0x0,
+	CONFIG_TYPE_NUMBER = 0x1,
+	CONFIG_TYPE_STRING = 0x2,
+	CONFIG_TYPE_FILE = 0x3,
+	CONFIG_TYPE_DIRECTORY = 0x4,
+	CONFIG_TYPE_BOOLEAN = 0x5,
+	CONFIG_TYPE_EXT_PATTERN = 0x6
+};
+
+
+/* Return array of struct mg_option, representing all valid configuration
+   options of civetweb.c.
+   The array is terminated by a NULL name option. */
+CIVETWEB_API const struct mg_option *mg_get_valid_options(void);
+
+
+struct mg_server_ports {
+	int protocol;    /* 1 = IPv4, 2 = IPv6, 3 = both */
+	int port;        /* port number */
+	int is_ssl;      /* https port: 0 = no, 1 = yes */
+	int is_redirect; /* redirect all requests: 0 = no, 1 = yes */
+	int _reserved1;
+	int _reserved2;
+	int _reserved3;
+	int _reserved4;
+};
+
+
+/* Get the list of ports that civetweb is listening on.
+   The parameter size is the size of the ports array in elements.
+   The caller is responsibility to allocate the required memory.
+   This function returns the number of struct mg_server_ports elements
+   filled in, or <0 in case of an error. */
+CIVETWEB_API int mg_get_server_ports(const struct mg_context *ctx,
+                                     int size,
+                                     struct mg_server_ports *ports);
+
+
+/* Deprecated: Use mg_get_server_ports instead. */
+CIVETWEB_API size_t
+mg_get_ports(const struct mg_context *ctx, size_t size, int *ports, int *ssl);
+
+
+/* Add, edit or delete the entry in the passwords file.
+
+   This function allows an application to manipulate .htpasswd files on the
+   fly by adding, deleting and changing user records. This is one of the
+   several ways of implementing authentication on the server side. For another,
+   cookie-based way please refer to the examples/chat in the source tree.
+
+   If password is not NULL, entry is added (or modified if already exists).
+   If password is NULL, entry is deleted.
+
+   Return:
+     1 on success, 0 on error. */
+CIVETWEB_API int mg_modify_passwords_file(const char *passwords_file_name,
+                                          const char *domain,
+                                          const char *user,
+                                          const char *password);
+
+
+/* Return information associated with the request. */
+CIVETWEB_API const struct mg_request_info *
+mg_get_request_info(const struct mg_connection *);
+
+
+/* Send data to the client.
+   Return:
+    0   when the connection has been closed
+    -1  on error
+    >0  number of bytes written on success */
+CIVETWEB_API int mg_write(struct mg_connection *, const void *buf, size_t len);
+
+
+/* Send data to a websocket client wrapped in a websocket frame.  Uses
+   mg_lock_connection to ensure that the transmission is not interrupted,
+   i.e., when the application is proactively communicating and responding to
+   a request simultaneously.
+
+   Send data to a websocket client wrapped in a websocket frame.
+   This function is available when civetweb is compiled with -DUSE_WEBSOCKET
+
+   Return:
+    0   when the connection has been closed
+    -1  on error
+    >0  number of bytes written on success */
+CIVETWEB_API int mg_websocket_write(struct mg_connection *conn,
+                                    int opcode,
+                                    const char *data,
+                                    size_t data_len);
+
+
+/* Send data to a websocket server wrapped in a masked websocket frame.  Uses
+   mg_lock_connection to ensure that the transmission is not interrupted,
+   i.e., when the application is proactively communicating and responding to
+   a request simultaneously.
+
+   Send data to a websocket server wrapped in a masked websocket frame.
+   This function is available when civetweb is compiled with -DUSE_WEBSOCKET
+
+   Return:
+    0   when the connection has been closed
+    -1  on error
+    >0  number of bytes written on success */
+CIVETWEB_API int mg_websocket_client_write(struct mg_connection *conn,
+                                           int opcode,
+                                           const char *data,
+                                           size_t data_len);
+
+
+/* Blocks until unique access is obtained to this connection. Intended for use
+   with websockets only.
+   Invoke this before mg_write or mg_printf when communicating with a
+   websocket if your code has server-initiated communication as well as
+   communication in direct response to a message. */
+CIVETWEB_API void mg_lock_connection(struct mg_connection *conn);
+CIVETWEB_API void mg_unlock_connection(struct mg_connection *conn);
+
+
+#if defined(MG_LEGACY_INTERFACE)
+#define mg_lock mg_lock_connection
+#define mg_unlock mg_unlock_connection
+#endif
+
+
+/* Lock server context.  This lock may be used to protect resources
+   that are shared between different connection/worker threads. */
+CIVETWEB_API void mg_lock_context(struct mg_context *ctx);
+CIVETWEB_API void mg_unlock_context(struct mg_context *ctx);
+
+
+/* Opcodes, from http://tools.ietf.org/html/rfc6455 */
+enum {
+	WEBSOCKET_OPCODE_CONTINUATION = 0x0,
+	WEBSOCKET_OPCODE_TEXT = 0x1,
+	WEBSOCKET_OPCODE_BINARY = 0x2,
+	WEBSOCKET_OPCODE_CONNECTION_CLOSE = 0x8,
+	WEBSOCKET_OPCODE_PING = 0x9,
+	WEBSOCKET_OPCODE_PONG = 0xa
+};
+
+
+/* Macros for enabling compiler-specific checks for printf-like arguments. */
+#undef PRINTF_FORMAT_STRING
+#if defined(_MSC_VER) && _MSC_VER >= 1400
+#include <sal.h>
+#if defined(_MSC_VER) && _MSC_VER > 1400
+#define PRINTF_FORMAT_STRING(s) _Printf_format_string_ s
+#else
+#define PRINTF_FORMAT_STRING(s) __format_string s
+#endif
+#else
+#define PRINTF_FORMAT_STRING(s) s
+#endif
+
+#ifdef __GNUC__
+#define PRINTF_ARGS(x, y) __attribute__((format(printf, x, y)))
+#else
+#define PRINTF_ARGS(x, y)
+#endif
+
+
+/* Send data to the client using printf() semantics.
+   Works exactly like mg_write(), but allows to do message formatting. */
+CIVETWEB_API int mg_printf(struct mg_connection *,
+                           PRINTF_FORMAT_STRING(const char *fmt),
+                           ...) PRINTF_ARGS(2, 3);
+
+
+/* Send contents of the entire file together with HTTP headers. */
+CIVETWEB_API void mg_send_file(struct mg_connection *conn, const char *path);
+
+/* Send contents of the entire file together with HTTP headers.
+   Parameters:
+     conn: Current connection information.
+     path: Full path to the file to send.
+     mime_type: Content-Type for file.  NULL will cause the type to be
+                looked up by the file extension.
+*/
+CIVETWEB_API void mg_send_mime_file(struct mg_connection *conn,
+                                    const char *path,
+                                    const char *mime_type);
+
+/* Send contents of the entire file together with HTTP headers.
+   Parameters:
+     conn: Current connection information.
+     path: Full path to the file to send.
+     mime_type: Content-Type for file.  NULL will cause the type to be
+                looked up by the file extension.
+     additional_headers: Additional custom header fields appended to the header.
+                         Each header must start with an X- to ensure it is not
+   included twice.
+                         NULL does not append anything.
+*/
+CIVETWEB_API void mg_send_mime_file2(struct mg_connection *conn,
+                                     const char *path,
+                                     const char *mime_type,
+                                     const char *additional_headers);
+
+/* Store body data into a file. */
+CIVETWEB_API long long mg_store_body(struct mg_connection *conn,
+                                     const char *path);
+/* Read entire request body and store it in a file "path".
+   Return:
+     < 0   Error
+     >= 0  Number of bytes stored in file "path".
+*/
+
+
+/* Read data from the remote end, return number of bytes read.
+   Return:
+     0     connection has been closed by peer. No more data could be read.
+     < 0   read error. No more data could be read from the connection.
+     > 0   number of bytes read into the buffer. */
+CIVETWEB_API int mg_read(struct mg_connection *, void *buf, size_t len);
+
+
+/* Get the value of particular HTTP header.
+
+   This is a helper function. It traverses request_info->http_headers array,
+   and if the header is present in the array, returns its value. If it is
+   not present, NULL is returned. */
+CIVETWEB_API const char *mg_get_header(const struct mg_connection *,
+                                       const char *name);
+
+
+/* Get a value of particular form variable.
+
+   Parameters:
+     data: pointer to form-uri-encoded buffer. This could be either POST data,
+           or request_info.query_string.
+     data_len: length of the encoded data.
+     var_name: variable name to decode from the buffer
+     dst: destination buffer for the decoded variable
+     dst_len: length of the destination buffer
+
+   Return:
+     On success, length of the decoded variable.
+     On error:
+        -1 (variable not found).
+        -2 (destination buffer is NULL, zero length or too small to hold the
+            decoded variable).
+
+   Destination buffer is guaranteed to be '\0' - terminated if it is not
+   NULL or zero length. */
+CIVETWEB_API int mg_get_var(const char *data,
+                            size_t data_len,
+                            const char *var_name,
+                            char *dst,
+                            size_t dst_len);
+
+
+/* Get a value of particular form variable.
+
+   Parameters:
+     data: pointer to form-uri-encoded buffer. This could be either POST data,
+           or request_info.query_string.
+     data_len: length of the encoded data.
+     var_name: variable name to decode from the buffer
+     dst: destination buffer for the decoded variable
+     dst_len: length of the destination buffer
+     occurrence: which occurrence of the variable, 0 is the first, 1 the
+                 second...
+                this makes it possible to parse a query like
+                b=x&a=y&a=z which will have occurrence values b:0, a:0 and a:1
+
+   Return:
+     On success, length of the decoded variable.
+     On error:
+        -1 (variable not found).
+        -2 (destination buffer is NULL, zero length or too small to hold the
+            decoded variable).
+
+   Destination buffer is guaranteed to be '\0' - terminated if it is not
+   NULL or zero length. */
+CIVETWEB_API int mg_get_var2(const char *data,
+                             size_t data_len,
+                             const char *var_name,
+                             char *dst,
+                             size_t dst_len,
+                             size_t occurrence);
+
+
+/* Fetch value of certain cookie variable into the destination buffer.
+
+   Destination buffer is guaranteed to be '\0' - terminated. In case of
+   failure, dst[0] == '\0'. Note that RFC allows many occurrences of the same
+   parameter. This function returns only first occurrence.
+
+   Return:
+     On success, value length.
+     On error:
+        -1 (either "Cookie:" header is not present at all or the requested
+            parameter is not found).
+        -2 (destination buffer is NULL, zero length or too small to hold the
+            value). */
+CIVETWEB_API int mg_get_cookie(const char *cookie,
+                               const char *var_name,
+                               char *buf,
+                               size_t buf_len);
+
+
+/* Download data from the remote web server.
+     host: host name to connect to, e.g. "foo.com", or "10.12.40.1".
+     port: port number, e.g. 80.
+     use_ssl: wether to use SSL connection.
+     error_buffer, error_buffer_size: error message placeholder.
+     request_fmt,...: HTTP request.
+   Return:
+     On success, valid pointer to the new connection, suitable for mg_read().
+     On error, NULL. error_buffer contains error message.
+   Example:
+     char ebuf[100];
+     struct mg_connection *conn;
+     conn = mg_download("google.com", 80, 0, ebuf, sizeof(ebuf),
+                        "%s", "GET / HTTP/1.0\r\nHost: google.com\r\n\r\n");
+ */
+CIVETWEB_API struct mg_connection *
+mg_download(const char *host,
+            int port,
+            int use_ssl,
+            char *error_buffer,
+            size_t error_buffer_size,
+            PRINTF_FORMAT_STRING(const char *request_fmt),
+            ...) PRINTF_ARGS(6, 7);
+
+
+/* Close the connection opened by mg_download(). */
+CIVETWEB_API void mg_close_connection(struct mg_connection *conn);
+
+
+#if defined(MG_LEGACY_INTERFACE)
+/* File upload functionality. Each uploaded file gets saved into a temporary
+   file and MG_UPLOAD event is sent.
+   Return number of uploaded files.
+   Deprecated: Use mg_handle_form_request instead. */
+CIVETWEB_API int mg_upload(struct mg_connection *conn,
+                           const char *destination_dir);
+#endif
+
+
+/* This structure contains callback functions for handling form fields.
+   It is used as an argument to mg_handle_form_request. */
+struct mg_form_data_handler {
+	/* This callback function is called, if a new field has been found.
+	 * The return value of this callback is used to define how the field
+	 * should be processed.
+	 *
+	 * Parameters:
+	 *   key: Name of the field ("name" property of the HTML input field).
+	 *   filename: Name of a file to upload, at the client computer.
+	 *             Only set for input fields of type "file", otherwise NULL.
+	 *   path: Output parameter: File name (incl. path) to store the file
+	 *         at the server computer. Only used if FORM_FIELD_STORAGE_STORE
+	 *         is returned by this callback. Existing files will be
+	 *         overwritten.
+	 *   pathlen: Length of the buffer for path.
+	 *   user_data: Value of the member user_data of mg_form_data_handler
+	 *
+	 * Return value:
+	 *   The callback must return the intended storage for this field
+	 *   (See FORM_FIELD_STORAGE_*).
+	 */
+	int (*field_found)(const char *key,
+	                   const char *filename,
+	                   char *path,
+	                   size_t pathlen,
+	                   void *user_data);
+
+	/* If the "field_found" callback returned FORM_FIELD_STORAGE_GET,
+	 * this callback will receive the field data.
+	 *
+	 * Parameters:
+	 *   key: Name of the field ("name" property of the HTML input field).
+	 *   value: Value of the input field.
+	 *   user_data: Value of the member user_data of mg_form_data_handler
+	 *
+	 * Return value:
+	 *   TODO: Needs to be defined.
+	 */
+	int (*field_get)(const char *key,
+	                 const char *value,
+	                 size_t valuelen,
+	                 void *user_data);
+
+	/* If the "field_found" callback returned FORM_FIELD_STORAGE_STORE,
+	 * the data will be stored into a file. If the file has been written
+	 * successfully, this callback will be called. This callback will
+	 * not be called for only partially uploaded files. The
+	 * mg_handle_form_request function will either store the file completely
+	 * and call this callback, or it will remove any partial content and
+	 * not call this callback function.
+	 *
+	 * Parameters:
+	 *   path: Path of the file stored at the server.
+	 *   file_size: Size of the stored file in bytes.
+	 *   user_data: Value of the member user_data of mg_form_data_handler
+	 *
+	 * Return value:
+	 *   TODO: Needs to be defined.
+	 */
+	int (*field_store)(const char *path, long long file_size, void *user_data);
+
+	/* User supplied argument, passed to all callback functions. */
+	void *user_data;
+};
+
+
+/* Return values definition for the "field_found" callback in
+ * mg_form_data_handler. */
+enum {
+	/* Skip this field (neither get nor store it). Continue with the
+     * next field. */
+	FORM_FIELD_STORAGE_SKIP = 0x0,
+	/* Get the field value. */
+	FORM_FIELD_STORAGE_GET = 0x1,
+	/* Store the field value into a file. */
+	FORM_FIELD_STORAGE_STORE = 0x2,
+	/* Stop parsing this request. Skip the remaining fields. */
+	FORM_FIELD_STORAGE_ABORT = 0x10
+};
+
+
+/* Process form data.
+ * Returns the number of fields handled, or < 0 in case of an error.
+ * Note: It is possible that several fields are already handled successfully
+ * (e.g., stored into files), before the request handling is stopped with an
+ * error. In this case a number < 0 is returned as well.
+ * In any case, it is the duty of the caller to remove files once they are
+ * no longer required. */
+CIVETWEB_API int mg_handle_form_request(struct mg_connection *conn,
+                                        struct mg_form_data_handler *fdh);
+
+
+/* Convenience function -- create detached thread.
+   Return: 0 on success, non-0 on error. */
+typedef void *(*mg_thread_func_t)(void *);
+CIVETWEB_API int mg_start_thread(mg_thread_func_t f, void *p);
+
+
+/* Return builtin mime type for the given file name.
+   For unrecognized extensions, "text/plain" is returned. */
+CIVETWEB_API const char *mg_get_builtin_mime_type(const char *file_name);
+
+
+/* Get text representation of HTTP status code. */
+CIVETWEB_API const char *mg_get_response_code_text(struct mg_connection *conn,
+                                                   int response_code);
+
+
+/* Return CivetWeb version. */
+CIVETWEB_API const char *mg_version(void);
+
+
+/* URL-decode input buffer into destination buffer.
+   0-terminate the destination buffer.
+   form-url-encoded data differs from URI encoding in a way that it
+   uses '+' as character for space, see RFC 1866 section 8.2.1
+   http://ftp.ics.uci.edu/pub/ietf/html/rfc1866.txt
+   Return: length of the decoded data, or -1 if dst buffer is too small. */
+CIVETWEB_API int mg_url_decode(const char *src,
+                               int src_len,
+                               char *dst,
+                               int dst_len,
+                               int is_form_url_encoded);
+
+
+/* URL-encode input buffer into destination buffer.
+   returns the length of the resulting buffer or -1
+   is the buffer is too small. */
+CIVETWEB_API int mg_url_encode(const char *src, char *dst, size_t dst_len);
+
+
+/* MD5 hash given strings.
+   Buffer 'buf' must be 33 bytes long. Varargs is a NULL terminated list of
+   ASCIIz strings. When function returns, buf will contain human-readable
+   MD5 hash. Example:
+     char buf[33];
+     mg_md5(buf, "aa", "bb", NULL); */
+CIVETWEB_API char *mg_md5(char buf[33], ...);
+
+
+/* Print error message to the opened error log stream.
+   This utilizes the provided logging configuration.
+     conn: connection
+     fmt: format string without the line return
+     ...: variable argument list
+   Example:
+     mg_cry(conn,"i like %s", "logging"); */
+CIVETWEB_API void mg_cry(const struct mg_connection *conn,
+                         PRINTF_FORMAT_STRING(const char *fmt),
+                         ...) PRINTF_ARGS(2, 3);
+
+
+/* utility methods to compare two buffers, case insensitive. */
+CIVETWEB_API int mg_strcasecmp(const char *s1, const char *s2);
+CIVETWEB_API int mg_strncasecmp(const char *s1, const char *s2, size_t len);
+
+
+/* Connect to a websocket as a client
+   Parameters:
+     host: host to connect to, i.e. "echo.websocket.org" or "192.168.1.1" or
+   "localhost"
+     port: server port
+     use_ssl: make a secure connection to server
+     error_buffer, error_buffer_size: buffer for an error message
+     path: server path you are trying to connect to, i.e. if connection to
+   localhost/app, path should be "/app"
+     origin: value of the Origin HTTP header
+     data_func: callback that should be used when data is received from the
+   server
+     user_data: user supplied argument
+
+   Return:
+     On success, valid mg_connection object.
+     On error, NULL. Se error_buffer for details.
+*/
+CIVETWEB_API struct mg_connection *
+mg_connect_websocket_client(const char *host,
+                            int port,
+                            int use_ssl,
+                            char *error_buffer,
+                            size_t error_buffer_size,
+                            const char *path,
+                            const char *origin,
+                            mg_websocket_data_handler data_func,
+                            mg_websocket_close_handler close_func,
+                            void *user_data);
+
+
+/* Connect to a TCP server as a client (can be used to connect to a HTTP server)
+   Parameters:
+     host: host to connect to, i.e. "www.wikipedia.org" or "192.168.1.1" or
+   "localhost"
+     port: server port
+     use_ssl: make a secure connection to server
+     error_buffer, error_buffer_size: buffer for an error message
+
+   Return:
+     On success, valid mg_connection object.
+     On error, NULL. Se error_buffer for details.
+*/
+CIVETWEB_API struct mg_connection *mg_connect_client(const char *host,
+                                                     int port,
+                                                     int use_ssl,
+                                                     char *error_buffer,
+                                                     size_t error_buffer_size);
+
+
+struct mg_client_options {
+	const char *host;
+	int port;
+	const char *client_cert;
+	const char *server_cert;
+	/* TODO: add more data */
+};
+
+
+CIVETWEB_API struct mg_connection *
+mg_connect_client_secure(const struct mg_client_options *client_options,
+                         char *error_buffer,
+                         size_t error_buffer_size);
+
+
+enum { TIMEOUT_INFINITE = -1 };
+
+
+/* Wait for a response from the server
+   Parameters:
+     conn: connection
+     ebuf, ebuf_len: error message placeholder.
+     timeout: time to wait for a response in milliseconds (if < 0 then wait
+   forever)
+
+   Return:
+     On success, >= 0
+     On error/timeout, < 0
+*/
+CIVETWEB_API int mg_get_response(struct mg_connection *conn,
+                                 char *ebuf,
+                                 size_t ebuf_len,
+                                 int timeout);
+
+
+/* Check which features where set when the civetweb library has been compiled.
+   The function explicitly addresses compile time defines used when building
+   the library - it does not mean, the feature has been initialized using a
+   mg_init_library call.
+   mg_check_feature can be called anytime, even before mg_init_library has
+   been called.
+
+   Parameters:
+     feature: specifies which feature should be checked
+       The value is a bit mask. The individual bits are defined as:
+         1  serve files (NO_FILES not set)
+         2  support HTTPS (NO_SSL not set)
+         4  support CGI (NO_CGI not set)
+         8  support IPv6 (USE_IPV6 set)
+        16  support WebSocket (USE_WEBSOCKET set)
+        32  support Lua scripts and Lua server pages (USE_LUA is set)
+        64  support server side JavaScript (USE_DUKTAPE is set)
+       128  support caching (NO_CACHING not set)
+       The result is undefined, if bits are set that do not represent a
+       defined feature (currently: feature >= 256).
+       The result is undefined, if no bit is set (feature == 0).
+
+   Return:
+     If feature is available, the corresponding bit is set
+     If feature is not available, the bit is 0
+*/
+CIVETWEB_API unsigned mg_check_feature(unsigned feature);
+
+
+/* Get information on the system. Useful, if in support requests.
+   Parameters:
+     buffer: Store system information as string here.
+     buflen: Length of buffer (including a byte required for a terminating 0).
+   Return:
+     Available size of system information, exluding a terminating 0.
+     The information is complete, if the return value is smaller than buflen.
+   Note:
+     It is possible to determine the required buflen, by first calling this
+     function with  buffer = NULL and buflen = NULL. The required buflen is
+     one byte more than the returned value.
+*/
+CIVETWEB_API int mg_get_system_info(char *buffer, int buflen);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* CIVETWEB_HEADER_INCLUDED */


[13/51] [partial] nifi-minifi-cpp git commit: MINIFI-183 Added civet 1.9.1 sources Added onScheduled hook Added initial two-way TLS-enabled ListenHTTP implementation

Posted by al...@apache.org.
http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_bi_date.c
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_bi_date.c b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_bi_date.c
new file mode 100644
index 0000000..1d5c7b7
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_bi_date.c
@@ -0,0 +1,1728 @@
+/*
+ *  Date built-ins
+ *
+ *  Unlike most built-ins, Date has some platform dependencies for getting
+ *  UTC time, converting between UTC and local time, and parsing and
+ *  formatting time values.  These are all abstracted behind DUK_USE_xxx
+ *  config options.  There are built-in platform specific providers for
+ *  POSIX and Windows, but external providers can also be used.
+ *
+ *  See doc/datetime.rst.
+ *
+ */
+
+#include "duk_internal.h"
+
+/*
+ *  Forward declarations
+ */
+
+DUK_LOCAL_DECL duk_double_t duk__push_this_get_timeval_tzoffset(duk_context *ctx, duk_small_uint_t flags, duk_int_t *out_tzoffset);
+DUK_LOCAL_DECL duk_double_t duk__push_this_get_timeval(duk_context *ctx, duk_small_uint_t flags);
+DUK_LOCAL_DECL void duk__twodigit_year_fixup(duk_context *ctx, duk_idx_t idx_val);
+DUK_LOCAL_DECL duk_ret_t duk__set_this_timeval_from_dparts(duk_context *ctx, duk_double_t *dparts, duk_small_uint_t flags);
+
+/*
+ *  Other file level defines
+ */
+
+/* Debug macro to print all parts and dparts (used manually because of debug level). */
+#define  DUK__DPRINT_PARTS_AND_DPARTS(parts,dparts)  do { \
+		DUK_D(DUK_DPRINT("parts: %ld %ld %ld %ld %ld %ld %ld %ld, dparts: %lf %lf %lf %lf %lf %lf %lf %lf", \
+		                 (long) (parts)[0], (long) (parts)[1], \
+		                 (long) (parts)[2], (long) (parts)[3], \
+		                 (long) (parts)[4], (long) (parts)[5], \
+		                 (long) (parts)[6], (long) (parts)[7], \
+		                 (double) (dparts)[0], (double) (dparts)[1], \
+		                 (double) (dparts)[2], (double) (dparts)[3], \
+		                 (double) (dparts)[4], (double) (dparts)[5], \
+		                 (double) (dparts)[6], (double) (dparts)[7])); \
+	} while (0)
+#define  DUK__DPRINT_PARTS(parts)  do { \
+		DUK_D(DUK_DPRINT("parts: %ld %ld %ld %ld %ld %ld %ld %ld", \
+		                 (long) (parts)[0], (long) (parts)[1], \
+		                 (long) (parts)[2], (long) (parts)[3], \
+		                 (long) (parts)[4], (long) (parts)[5], \
+		                 (long) (parts)[6], (long) (parts)[7])); \
+	} while (0)
+#define  DUK__DPRINT_DPARTS(dparts)  do { \
+		DUK_D(DUK_DPRINT("dparts: %lf %lf %lf %lf %lf %lf %lf %lf", \
+		                 (double) (dparts)[0], (double) (dparts)[1], \
+		                 (double) (dparts)[2], (double) (dparts)[3], \
+		                 (double) (dparts)[4], (double) (dparts)[5], \
+		                 (double) (dparts)[6], (double) (dparts)[7])); \
+	} while (0)
+
+/* Equivalent year for DST calculations outside [1970,2038[ range, see
+ * E5 Section 15.9.1.8.  Equivalent year has the same leap-year-ness and
+ * starts with the same weekday on Jan 1.
+ * https://bugzilla.mozilla.org/show_bug.cgi?id=351066
+ */
+#define DUK__YEAR(x) ((duk_uint8_t) ((x) - 1970))
+DUK_LOCAL duk_uint8_t duk__date_equivyear[14] = {
+#if 1
+	/* This is based on V8 EquivalentYear() algorithm (see src/genequivyear.py):
+	 * http://code.google.com/p/v8/source/browse/trunk/src/date.h#146
+	 */
+
+	/* non-leap year: sunday, monday, ... */
+	DUK__YEAR(2023), DUK__YEAR(2035), DUK__YEAR(2019), DUK__YEAR(2031),
+	DUK__YEAR(2015), DUK__YEAR(2027), DUK__YEAR(2011),
+
+	/* leap year: sunday, monday, ... */
+	DUK__YEAR(2012), DUK__YEAR(2024), DUK__YEAR(2008), DUK__YEAR(2020),
+	DUK__YEAR(2032), DUK__YEAR(2016), DUK__YEAR(2028)
+#endif
+
+#if 0
+	/* This is based on Rhino EquivalentYear() algorithm:
+	 * https://github.com/mozilla/rhino/blob/f99cc11d616f0cdda2c42bde72b3484df6182947/src/org/mozilla/javascript/NativeDate.java
+	 */
+
+	/* non-leap year: sunday, monday, ... */
+	DUK__YEAR(1978), DUK__YEAR(1973), DUK__YEAR(1985), DUK__YEAR(1986),
+	DUK__YEAR(1981), DUK__YEAR(1971), DUK__YEAR(1977),
+
+	/* leap year: sunday, monday, ... */
+	DUK__YEAR(1984), DUK__YEAR(1996), DUK__YEAR(1980), DUK__YEAR(1992),
+	DUK__YEAR(1976), DUK__YEAR(1988), DUK__YEAR(1972)
+#endif
+};
+#undef DUK__YEAR
+
+/*
+ *  ISO 8601 subset parser.
+ */
+
+/* Parser part count. */
+#define DUK__NUM_ISO8601_PARSER_PARTS  9
+
+/* Parser part indices. */
+#define DUK__PI_YEAR         0
+#define DUK__PI_MONTH        1
+#define DUK__PI_DAY          2
+#define DUK__PI_HOUR         3
+#define DUK__PI_MINUTE       4
+#define DUK__PI_SECOND       5
+#define DUK__PI_MILLISECOND  6
+#define DUK__PI_TZHOUR       7
+#define DUK__PI_TZMINUTE     8
+
+/* Parser part masks. */
+#define DUK__PM_YEAR         (1 << DUK__PI_YEAR)
+#define DUK__PM_MONTH        (1 << DUK__PI_MONTH)
+#define DUK__PM_DAY          (1 << DUK__PI_DAY)
+#define DUK__PM_HOUR         (1 << DUK__PI_HOUR)
+#define DUK__PM_MINUTE       (1 << DUK__PI_MINUTE)
+#define DUK__PM_SECOND       (1 << DUK__PI_SECOND)
+#define DUK__PM_MILLISECOND  (1 << DUK__PI_MILLISECOND)
+#define DUK__PM_TZHOUR       (1 << DUK__PI_TZHOUR)
+#define DUK__PM_TZMINUTE     (1 << DUK__PI_TZMINUTE)
+
+/* Parser separator indices. */
+#define DUK__SI_PLUS         0
+#define DUK__SI_MINUS        1
+#define DUK__SI_T            2
+#define DUK__SI_SPACE        3
+#define DUK__SI_COLON        4
+#define DUK__SI_PERIOD       5
+#define DUK__SI_Z            6
+#define DUK__SI_NUL          7
+
+/* Parser separator masks. */
+#define DUK__SM_PLUS         (1 << DUK__SI_PLUS)
+#define DUK__SM_MINUS        (1 << DUK__SI_MINUS)
+#define DUK__SM_T            (1 << DUK__SI_T)
+#define DUK__SM_SPACE        (1 << DUK__SI_SPACE)
+#define DUK__SM_COLON        (1 << DUK__SI_COLON)
+#define DUK__SM_PERIOD       (1 << DUK__SI_PERIOD)
+#define DUK__SM_Z            (1 << DUK__SI_Z)
+#define DUK__SM_NUL          (1 << DUK__SI_NUL)
+
+/* Rule control flags. */
+#define DUK__CF_NEG          (1 << 0)  /* continue matching, set neg_tzoffset flag */
+#define DUK__CF_ACCEPT       (1 << 1)  /* accept string */
+#define DUK__CF_ACCEPT_NUL   (1 << 2)  /* accept string if next char is NUL (otherwise reject) */
+
+#define DUK__PACK_RULE(partmask,sepmask,nextpart,flags)  \
+	((duk_uint32_t) (partmask) + \
+	 (((duk_uint32_t) (sepmask)) << 9) + \
+	 (((duk_uint32_t) (nextpart)) << 17) + \
+	 (((duk_uint32_t) (flags)) << 21))
+
+#define DUK__UNPACK_RULE(rule,var_nextidx,var_flags)  do { \
+		(var_nextidx) = (duk_small_uint_t) (((rule) >> 17) & 0x0f); \
+		(var_flags) = (duk_small_uint_t) ((rule) >> 21); \
+	} while (0)
+
+#define DUK__RULE_MASK_PART_SEP  0x1ffffUL
+
+/* Matching separator index is used in the control table */
+DUK_LOCAL const duk_uint8_t duk__parse_iso8601_seps[] = {
+	DUK_ASC_PLUS /*0*/, DUK_ASC_MINUS /*1*/, DUK_ASC_UC_T /*2*/, DUK_ASC_SPACE /*3*/,
+	DUK_ASC_COLON /*4*/, DUK_ASC_PERIOD /*5*/, DUK_ASC_UC_Z /*6*/, DUK_ASC_NUL /*7*/
+};
+
+/* Rule table: first matching rule is used to determine what to do next. */
+DUK_LOCAL const duk_uint32_t duk__parse_iso8601_control[] = {
+	DUK__PACK_RULE(DUK__PM_YEAR, DUK__SM_MINUS, DUK__PI_MONTH, 0),
+	DUK__PACK_RULE(DUK__PM_MONTH, DUK__SM_MINUS, DUK__PI_DAY, 0),
+	DUK__PACK_RULE(DUK__PM_YEAR | DUK__PM_MONTH | DUK__PM_DAY, DUK__SM_T | DUK__SM_SPACE, DUK__PI_HOUR, 0),
+	DUK__PACK_RULE(DUK__PM_HOUR, DUK__SM_COLON, DUK__PI_MINUTE, 0),
+	DUK__PACK_RULE(DUK__PM_MINUTE, DUK__SM_COLON, DUK__PI_SECOND, 0),
+	DUK__PACK_RULE(DUK__PM_SECOND, DUK__SM_PERIOD, DUK__PI_MILLISECOND, 0),
+	DUK__PACK_RULE(DUK__PM_TZHOUR, DUK__SM_COLON, DUK__PI_TZMINUTE, 0),
+	DUK__PACK_RULE(DUK__PM_YEAR | DUK__PM_MONTH | DUK__PM_DAY | DUK__PM_HOUR /*Note1*/ | DUK__PM_MINUTE | DUK__PM_SECOND | DUK__PM_MILLISECOND, DUK__SM_PLUS, DUK__PI_TZHOUR, 0),
+	DUK__PACK_RULE(DUK__PM_YEAR | DUK__PM_MONTH | DUK__PM_DAY | DUK__PM_HOUR /*Note1*/ | DUK__PM_MINUTE | DUK__PM_SECOND | DUK__PM_MILLISECOND, DUK__SM_MINUS, DUK__PI_TZHOUR, DUK__CF_NEG),
+	DUK__PACK_RULE(DUK__PM_YEAR | DUK__PM_MONTH | DUK__PM_DAY | DUK__PM_HOUR /*Note1*/ | DUK__PM_MINUTE | DUK__PM_SECOND | DUK__PM_MILLISECOND, DUK__SM_Z, 0, DUK__CF_ACCEPT_NUL),
+	DUK__PACK_RULE(DUK__PM_YEAR | DUK__PM_MONTH | DUK__PM_DAY | DUK__PM_HOUR /*Note1*/ | DUK__PM_MINUTE | DUK__PM_SECOND | DUK__PM_MILLISECOND | DUK__PM_TZHOUR /*Note2*/ | DUK__PM_TZMINUTE, DUK__SM_NUL, 0, DUK__CF_ACCEPT)
+
+	/* Note1: the specification doesn't require matching a time form with
+	 *        just hours ("HH"), but we accept it here, e.g. "2012-01-02T12Z".
+	 *
+	 * Note2: the specification doesn't require matching a timezone offset
+	 *        with just hours ("HH"), but accept it here, e.g. "2012-01-02T03:04:05+02"
+	 */
+};
+
+DUK_LOCAL duk_bool_t duk__parse_string_iso8601_subset(duk_context *ctx, const char *str) {
+	duk_int_t parts[DUK__NUM_ISO8601_PARSER_PARTS];
+	duk_double_t dparts[DUK_DATE_IDX_NUM_PARTS];
+	duk_double_t d;
+	const duk_uint8_t *p;
+	duk_small_uint_t part_idx = 0;
+	duk_int_t accum = 0;
+	duk_small_uint_t ndigits = 0;
+	duk_bool_t neg_year = 0;
+	duk_bool_t neg_tzoffset = 0;
+	duk_uint_fast8_t ch;
+	duk_small_uint_t i;
+
+	/* During parsing, month and day are one-based; set defaults here. */
+	DUK_MEMZERO(parts, sizeof(parts));
+	DUK_ASSERT(parts[DUK_DATE_IDX_YEAR] == 0);  /* don't care value, year is mandatory */
+	parts[DUK_DATE_IDX_MONTH] = 1;
+	parts[DUK_DATE_IDX_DAY] = 1;
+
+	/* Special handling for year sign. */
+	p = (const duk_uint8_t *) str;
+	ch = p[0];
+	if (ch == DUK_ASC_PLUS) {
+		p++;
+	} else if (ch == DUK_ASC_MINUS) {
+		neg_year = 1;
+		p++;
+	}
+
+	for (;;) {
+		ch = *p++;
+		DUK_DDD(DUK_DDDPRINT("parsing, part_idx=%ld, char=%ld ('%c')",
+		                     (long) part_idx, (long) ch,
+		                     (int) ((ch >= 0x20 && ch <= 0x7e) ? ch : DUK_ASC_QUESTION)));
+
+		if (ch >= DUK_ASC_0 && ch <= DUK_ASC_9) {
+			if (ndigits >= 9) {
+				DUK_DDD(DUK_DDDPRINT("too many digits -> reject"));
+				goto reject;
+			}
+			if (part_idx == DUK__PI_MILLISECOND /*msec*/ && ndigits >= 3) {
+				/* ignore millisecond fractions after 3 */
+			} else {
+				accum = accum * 10 + ((duk_int_t) ch) - ((duk_int_t) DUK_ASC_0) + 0x00;
+				ndigits++;
+			}
+		} else {
+			duk_uint_fast32_t match_val;
+			duk_small_int_t sep_idx;
+
+			if (ndigits <= 0) {
+				goto reject;
+			}
+			if (part_idx == DUK__PI_MILLISECOND) {
+				/* complete the millisecond field */
+				while (ndigits < 3) {
+					accum *= 10;
+					ndigits++;
+				}
+			}
+			parts[part_idx] = accum;
+			DUK_DDD(DUK_DDDPRINT("wrote part %ld -> value %ld", (long) part_idx, (long) accum));
+
+			accum = 0;
+			ndigits = 0;
+
+			for (i = 0; i < (duk_small_uint_t) (sizeof(duk__parse_iso8601_seps) / sizeof(duk_uint8_t)); i++) {
+				if (duk__parse_iso8601_seps[i] == ch) {
+					break;
+				}
+			}
+			if (i == (duk_small_uint_t) (sizeof(duk__parse_iso8601_seps) / sizeof(duk_uint8_t))) {
+				DUK_DDD(DUK_DDDPRINT("separator character doesn't match -> reject"));
+				goto reject;
+			}
+
+			sep_idx = i;
+			match_val = (1UL << part_idx) + (1UL << (sep_idx + 9));  /* match against rule part/sep bits */
+
+			for (i = 0; i < (duk_small_uint_t) (sizeof(duk__parse_iso8601_control) / sizeof(duk_uint32_t)); i++) {
+				duk_uint_fast32_t rule = duk__parse_iso8601_control[i];
+				duk_small_uint_t nextpart;
+				duk_small_uint_t cflags;
+
+				DUK_DDD(DUK_DDDPRINT("part_idx=%ld, sep_idx=%ld, match_val=0x%08lx, considering rule=0x%08lx",
+				                     (long) part_idx, (long) sep_idx,
+				                     (unsigned long) match_val, (unsigned long) rule));
+
+				if ((rule & match_val) != match_val) {
+					continue;
+				}
+
+				DUK__UNPACK_RULE(rule, nextpart, cflags);
+
+				DUK_DDD(DUK_DDDPRINT("rule match -> part_idx=%ld, sep_idx=%ld, match_val=0x%08lx, "
+				                     "rule=0x%08lx -> nextpart=%ld, cflags=0x%02lx",
+				                     (long) part_idx, (long) sep_idx,
+				                     (unsigned long) match_val, (unsigned long) rule,
+				                     (long) nextpart, (unsigned long) cflags));
+
+				if (cflags & DUK__CF_NEG) {
+					neg_tzoffset = 1;
+				}
+
+				if (cflags & DUK__CF_ACCEPT) {
+					goto accept;
+				}
+
+				if (cflags & DUK__CF_ACCEPT_NUL) {
+					DUK_ASSERT(*(p - 1) != (char) 0);
+					if (*p == DUK_ASC_NUL) {
+						goto accept;
+					}
+					goto reject;
+				}
+
+				part_idx = nextpart;
+				break;
+			}  /* rule match */
+
+			if (i == (duk_small_uint_t) (sizeof(duk__parse_iso8601_control) / sizeof(duk_uint32_t))) {
+				DUK_DDD(DUK_DDDPRINT("no rule matches -> reject"));
+				goto reject;
+			}
+
+			if (ch == 0) {
+				/* This shouldn't be necessary, but check just in case
+				 * to avoid any chance of overruns.
+				 */
+				DUK_DDD(DUK_DDDPRINT("NUL after rule matching (should not happen) -> reject"));
+				goto reject;
+			}
+		}  /* if-digit-else-ctrl */
+	}  /* char loop */
+
+	/* We should never exit the loop above. */
+	DUK_UNREACHABLE();
+
+ reject:
+	DUK_DDD(DUK_DDDPRINT("reject"));
+	return 0;
+
+ accept:
+	DUK_DDD(DUK_DDDPRINT("accept"));
+
+	/* Apply timezone offset to get the main parts in UTC */
+	if (neg_year) {
+		parts[DUK__PI_YEAR] = -parts[DUK__PI_YEAR];
+	}
+	if (neg_tzoffset) {
+		parts[DUK__PI_HOUR] += parts[DUK__PI_TZHOUR];
+		parts[DUK__PI_MINUTE] += parts[DUK__PI_TZMINUTE];
+	} else {
+		parts[DUK__PI_HOUR] -= parts[DUK__PI_TZHOUR];
+		parts[DUK__PI_MINUTE] -= parts[DUK__PI_TZMINUTE];
+	}
+	parts[DUK__PI_MONTH] -= 1;  /* zero-based month */
+	parts[DUK__PI_DAY] -= 1;  /* zero-based day */
+
+	/* Use double parts, they tolerate unnormalized time.
+	 *
+	 * Note: DUK_DATE_IDX_WEEKDAY is initialized with a bogus value (DUK__PI_TZHOUR)
+	 * on purpose.  It won't be actually used by duk_bi_date_get_timeval_from_dparts(),
+	 * but will make the value initialized just in case, and avoid any
+	 * potential for Valgrind issues.
+	 */
+	for (i = 0; i < DUK_DATE_IDX_NUM_PARTS; i++) {
+		DUK_DDD(DUK_DDDPRINT("part[%ld] = %ld", (long) i, (long) parts[i]));
+		dparts[i] = parts[i];
+	}
+
+	d = duk_bi_date_get_timeval_from_dparts(dparts, 0 /*flags*/);
+	duk_push_number(ctx, d);
+	return 1;
+}
+
+/*
+ *  Date/time parsing helper.
+ *
+ *  Parse a datetime string into a time value.  We must first try to parse
+ *  the input according to the standard format in E5.1 Section 15.9.1.15.
+ *  If that fails, we can try to parse using custom parsing, which can
+ *  either be platform neutral (custom code) or platform specific (using
+ *  existing platform API calls).
+ *
+ *  Note in particular that we must parse whatever toString(), toUTCString(),
+ *  and toISOString() can produce; see E5.1 Section 15.9.4.2.
+ *
+ *  Returns 1 to allow tail calling.
+ *
+ *  There is much room for improvement here with respect to supporting
+ *  alternative datetime formats.  For instance, V8 parses '2012-01-01' as
+ *  UTC and '2012/01/01' as local time.
+ */
+
+DUK_LOCAL duk_ret_t duk__parse_string(duk_context *ctx, const char *str) {
+	/* XXX: there is a small risk here: because the ISO 8601 parser is
+	 * very loose, it may end up parsing some datetime values which
+	 * would be better parsed with a platform specific parser.
+	 */
+
+	DUK_ASSERT(str != NULL);
+	DUK_DDD(DUK_DDDPRINT("parse datetime from string '%s'", (const char *) str));
+
+	if (duk__parse_string_iso8601_subset(ctx, str) != 0) {
+		return 1;
+	}
+
+#if defined(DUK_USE_DATE_PARSE_STRING)
+	/* Contract, either:
+	 * - Push value on stack and return 1
+	 * - Don't push anything on stack and return 0
+	 */
+
+	if (DUK_USE_DATE_PARSE_STRING(ctx, str) != 0) {
+		return 1;
+	}
+#else
+	/* No platform-specific parsing, this is not an error. */
+#endif
+
+	duk_push_nan(ctx);
+	return 1;
+}
+
+/*
+ *  Calendar helpers
+ *
+ *  Some helpers are used for getters and can operate on normalized values
+ *  which can be represented with 32-bit signed integers.  Other helpers are
+ *  needed by setters and operate on un-normalized double values, must watch
+ *  out for non-finite numbers etc.
+ */
+
+DUK_LOCAL duk_uint8_t duk__days_in_month[12] = {
+	(duk_uint8_t) 31, (duk_uint8_t) 28, (duk_uint8_t) 31, (duk_uint8_t) 30,
+	(duk_uint8_t) 31, (duk_uint8_t) 30, (duk_uint8_t) 31, (duk_uint8_t) 31,
+	(duk_uint8_t) 30, (duk_uint8_t) 31, (duk_uint8_t) 30, (duk_uint8_t) 31
+};
+
+/* Maximum iteration count for computing UTC-to-local time offset when
+ * creating an Ecmascript time value from local parts.
+ */
+#define DUK__LOCAL_TZOFFSET_MAXITER   4
+
+/* Because 'day since epoch' can be negative and is used to compute weekday
+ * using a modulo operation, add this multiple of 7 to avoid negative values
+ * when year is below 1970 epoch.  Ecmascript time values are restricted to
+ * +/- 100 million days from epoch, so this adder fits nicely into 32 bits.
+ * Round to a multiple of 7 (= floor(100000000 / 7) * 7) and add margin.
+ */
+#define DUK__WEEKDAY_MOD_ADDER  (20000000 * 7)  /* 0x08583b00 */
+
+DUK_INTERNAL duk_bool_t duk_bi_date_is_leap_year(duk_int_t year) {
+	if ((year % 4) != 0) {
+		return 0;
+	}
+	if ((year % 100) != 0) {
+		return 1;
+	}
+	if ((year % 400) != 0) {
+		return 0;
+	}
+	return 1;
+}
+
+DUK_INTERNAL duk_bool_t duk_bi_date_timeval_in_valid_range(duk_double_t x) {
+	return (x >= -DUK_DATE_MSEC_100M_DAYS && x <= DUK_DATE_MSEC_100M_DAYS);
+}
+
+DUK_INTERNAL duk_bool_t duk_bi_date_timeval_in_leeway_range(duk_double_t x) {
+	return (x >= -DUK_DATE_MSEC_100M_DAYS_LEEWAY && x <= DUK_DATE_MSEC_100M_DAYS_LEEWAY);
+}
+
+DUK_INTERNAL duk_bool_t duk_bi_date_year_in_valid_range(duk_double_t x) {
+	return (x >= DUK_DATE_MIN_ECMA_YEAR && x <= DUK_DATE_MAX_ECMA_YEAR);
+}
+
+DUK_LOCAL duk_double_t duk__timeclip(duk_double_t x) {
+	if (!DUK_ISFINITE(x)) {
+		return DUK_DOUBLE_NAN;
+	}
+
+	if (!duk_bi_date_timeval_in_valid_range(x)) {
+		return DUK_DOUBLE_NAN;
+	}
+
+	x = duk_js_tointeger_number(x);
+
+	/* Here we'd have the option to normalize -0 to +0. */
+	return x;
+}
+
+/* Integer division which floors also negative values correctly. */
+DUK_LOCAL duk_int_t duk__div_floor(duk_int_t a, duk_int_t b) {
+	DUK_ASSERT(b > 0);
+	if (a >= 0) {
+		return a / b;
+	} else {
+		/* e.g. a = -4, b = 5  -->  -4 - 5 + 1 / 5  -->  -8 / 5  -->  -1
+		 *      a = -5, b = 5  -->  -5 - 5 + 1 / 5  -->  -9 / 5  -->  -1
+		 *      a = -6, b = 5  -->  -6 - 5 + 1 / 5  -->  -10 / 5  -->  -2
+		 */
+		return (a - b + 1) / b;
+	}
+}
+
+/* Compute day number of the first day of a given year. */
+DUK_LOCAL duk_int_t duk__day_from_year(duk_int_t year) {
+	/* Note: in integer arithmetic, (x / 4) is same as floor(x / 4) for non-negative
+	 * values, but is incorrect for negative ones.
+	 */
+	return 365 * (year - 1970)
+	       + duk__div_floor(year - 1969, 4)
+	       - duk__div_floor(year - 1901, 100)
+	       + duk__div_floor(year - 1601, 400);
+}
+
+/* Given a day number, determine year and day-within-year. */
+DUK_LOCAL duk_int_t duk__year_from_day(duk_int_t day, duk_small_int_t *out_day_within_year) {
+	duk_int_t year;
+	duk_int_t diff_days;
+
+	/* estimate year upwards (towards positive infinity), then back down;
+	 * two iterations should be enough
+	 */
+
+	if (day >= 0) {
+		year = 1970 + day / 365;
+	} else {
+		year = 1970 + day / 366;
+	}
+
+	for (;;) {
+		diff_days = duk__day_from_year(year) - day;
+		DUK_DDD(DUK_DDDPRINT("year=%ld day=%ld, diff_days=%ld", (long) year, (long) day, (long) diff_days));
+		if (diff_days <= 0) {
+			DUK_ASSERT(-diff_days < 366);  /* fits into duk_small_int_t */
+			*out_day_within_year = -diff_days;
+			DUK_DDD(DUK_DDDPRINT("--> year=%ld, day-within-year=%ld",
+			                     (long) year, (long) *out_day_within_year));
+			DUK_ASSERT(*out_day_within_year >= 0);
+			DUK_ASSERT(*out_day_within_year < (duk_bi_date_is_leap_year(year) ? 366 : 365));
+			return year;
+		}
+
+		/* Note: this is very tricky; we must never 'overshoot' the
+		 * correction downwards.
+		 */
+		year -= 1 + (diff_days - 1) / 366;  /* conservative */
+	}
+}
+
+/* Given a (year, month, day-within-month) triple, compute day number.
+ * The input triple is un-normalized and may contain non-finite values.
+ */
+DUK_LOCAL duk_double_t duk__make_day(duk_double_t year, duk_double_t month, duk_double_t day) {
+	duk_int_t day_num;
+	duk_bool_t is_leap;
+	duk_small_int_t i, n;
+
+	/* Assume that year, month, day are all coerced to whole numbers.
+	 * They may also be NaN or infinity, in which case this function
+	 * must return NaN or infinity to ensure time value becomes NaN.
+	 * If 'day' is NaN, the final return will end up returning a NaN,
+	 * so it doesn't need to be checked here.
+	 */
+
+	if (!DUK_ISFINITE(year) || !DUK_ISFINITE(month)) {
+		return DUK_DOUBLE_NAN;
+	}
+
+	year += DUK_FLOOR(month / 12.0);
+
+	month = DUK_FMOD(month, 12.0);
+	if (month < 0.0) {
+		/* handle negative values */
+		month += 12.0;
+	}
+
+	/* The algorithm in E5.1 Section 15.9.1.12 normalizes month, but
+	 * does not normalize the day-of-month (nor check whether or not
+	 * it is finite) because it's not necessary for finding the day
+	 * number which matches the (year,month) pair.
+	 *
+	 * We assume that duk__day_from_year() is exact here.
+	 *
+	 * Without an explicit infinity / NaN check in the beginning,
+	 * day_num would be a bogus integer here.
+	 *
+	 * It's possible for 'year' to be out of integer range here.
+	 * If so, we need to return NaN without integer overflow.
+	 * This fixes test-bug-setyear-overflow.js.
+	 */
+
+	if (!duk_bi_date_year_in_valid_range(year)) {
+		DUK_DD(DUK_DDPRINT("year not in ecmascript valid range, avoid integer overflow: %lf", (double) year));
+		return DUK_DOUBLE_NAN;
+	}
+	day_num = duk__day_from_year((duk_int_t) year);
+	is_leap = duk_bi_date_is_leap_year((duk_int_t) year);
+
+	n = (duk_small_int_t) month;
+	for (i = 0; i < n; i++) {
+		day_num += duk__days_in_month[i];
+		if (i == 1 && is_leap) {
+			day_num++;
+		}
+	}
+
+	/* If 'day' is NaN, returns NaN. */
+	return (duk_double_t) day_num + day;
+}
+
+/* Split time value into parts.  The time value is assumed to be an internal
+ * one, i.e. finite, no fractions.  Possible local time adjustment has already
+ * been applied when reading the time value.
+ */
+DUK_INTERNAL void duk_bi_date_timeval_to_parts(duk_double_t d, duk_int_t *parts, duk_double_t *dparts, duk_small_uint_t flags) {
+	duk_double_t d1, d2;
+	duk_int_t t1, t2;
+	duk_int_t day_since_epoch;
+	duk_int_t year;  /* does not fit into 16 bits */
+	duk_small_int_t day_in_year;
+	duk_small_int_t month;
+	duk_small_int_t day;
+	duk_small_int_t dim;
+	duk_int_t jan1_since_epoch;
+	duk_small_int_t jan1_weekday;
+	duk_int_t equiv_year;
+	duk_small_uint_t i;
+	duk_bool_t is_leap;
+	duk_small_int_t arridx;
+
+	DUK_ASSERT(DUK_ISFINITE(d));    /* caller checks */
+	DUK_ASSERT(DUK_FLOOR(d) == d);  /* no fractions in internal time */
+
+	/* The timevalue must be in valid Ecmascript range, but since a local
+	 * time offset can be applied, we need to allow a +/- 24h leeway to
+	 * the value.  In other words, although the UTC time is within the
+	 * Ecmascript range, the local part values can be just outside of it.
+	 */
+	DUK_UNREF(duk_bi_date_timeval_in_leeway_range);
+	DUK_ASSERT(duk_bi_date_timeval_in_leeway_range(d));
+
+	/* these computations are guaranteed to be exact for the valid
+	 * E5 time value range, assuming milliseconds without fractions.
+	 */
+	d1 = (duk_double_t) DUK_FMOD(d, (double) DUK_DATE_MSEC_DAY);
+	if (d1 < 0.0) {
+		/* deal with negative values */
+		d1 += (duk_double_t) DUK_DATE_MSEC_DAY;
+	}
+	d2 = DUK_FLOOR((double) (d / (duk_double_t) DUK_DATE_MSEC_DAY));
+	DUK_ASSERT(d2 * ((duk_double_t) DUK_DATE_MSEC_DAY) + d1 == d);
+	/* now expected to fit into a 32-bit integer */
+	t1 = (duk_int_t) d1;
+	t2 = (duk_int_t) d2;
+	day_since_epoch = t2;
+	DUK_ASSERT((duk_double_t) t1 == d1);
+	DUK_ASSERT((duk_double_t) t2 == d2);
+
+	/* t1 = milliseconds within day (fits 32 bit)
+	 * t2 = day number from epoch (fits 32 bit, may be negative)
+	 */
+
+	parts[DUK_DATE_IDX_MILLISECOND] = t1 % 1000; t1 /= 1000;
+	parts[DUK_DATE_IDX_SECOND] = t1 % 60; t1 /= 60;
+	parts[DUK_DATE_IDX_MINUTE] = t1 % 60; t1 /= 60;
+	parts[DUK_DATE_IDX_HOUR] = t1;
+	DUK_ASSERT(parts[DUK_DATE_IDX_MILLISECOND] >= 0 && parts[DUK_DATE_IDX_MILLISECOND] <= 999);
+	DUK_ASSERT(parts[DUK_DATE_IDX_SECOND] >= 0 && parts[DUK_DATE_IDX_SECOND] <= 59);
+	DUK_ASSERT(parts[DUK_DATE_IDX_MINUTE] >= 0 && parts[DUK_DATE_IDX_MINUTE] <= 59);
+	DUK_ASSERT(parts[DUK_DATE_IDX_HOUR] >= 0 && parts[DUK_DATE_IDX_HOUR] <= 23);
+
+	DUK_DDD(DUK_DDDPRINT("d=%lf, d1=%lf, d2=%lf, t1=%ld, t2=%ld, parts: hour=%ld min=%ld sec=%ld msec=%ld",
+	                     (double) d, (double) d1, (double) d2, (long) t1, (long) t2,
+	                     (long) parts[DUK_DATE_IDX_HOUR],
+	                     (long) parts[DUK_DATE_IDX_MINUTE],
+	                     (long) parts[DUK_DATE_IDX_SECOND],
+	                     (long) parts[DUK_DATE_IDX_MILLISECOND]));
+
+	/* This assert depends on the input parts representing time inside
+	 * the Ecmascript range.
+	 */
+	DUK_ASSERT(t2 + DUK__WEEKDAY_MOD_ADDER >= 0);
+	parts[DUK_DATE_IDX_WEEKDAY] = (t2 + 4 + DUK__WEEKDAY_MOD_ADDER) % 7;  /* E5.1 Section 15.9.1.6 */
+	DUK_ASSERT(parts[DUK_DATE_IDX_WEEKDAY] >= 0 && parts[DUK_DATE_IDX_WEEKDAY] <= 6);
+
+	year = duk__year_from_day(t2, &day_in_year);
+	day = day_in_year;
+	is_leap = duk_bi_date_is_leap_year(year);
+	for (month = 0; month < 12; month++) {
+		dim = duk__days_in_month[month];
+		if (month == 1 && is_leap) {
+			dim++;
+		}
+		DUK_DDD(DUK_DDDPRINT("month=%ld, dim=%ld, day=%ld",
+		                     (long) month, (long) dim, (long) day));
+		if (day < dim) {
+			break;
+		}
+		day -= dim;
+	}
+	DUK_DDD(DUK_DDDPRINT("final month=%ld", (long) month));
+	DUK_ASSERT(month >= 0 && month <= 11);
+	DUK_ASSERT(day >= 0 && day <= 31);
+
+	/* Equivalent year mapping, used to avoid DST trouble when platform
+	 * may fail to provide reasonable DST answers for dates outside the
+	 * ordinary range (e.g. 1970-2038).  An equivalent year has the same
+	 * leap-year-ness as the original year and begins on the same weekday
+	 * (Jan 1).
+	 *
+	 * The year 2038 is avoided because there seem to be problems with it
+	 * on some platforms.  The year 1970 is also avoided as there were
+	 * practical problems with it; an equivalent year is used for it too,
+	 * which breaks some DST computations for 1970 right now, see e.g.
+	 * test-bi-date-tzoffset-brute-fi.js.
+	 */
+	if ((flags & DUK_DATE_FLAG_EQUIVYEAR) && (year < 1971 || year > 2037)) {
+		DUK_ASSERT(is_leap == 0 || is_leap == 1);
+
+		jan1_since_epoch = day_since_epoch - day_in_year;  /* day number for Jan 1 since epoch */
+		DUK_ASSERT(jan1_since_epoch + DUK__WEEKDAY_MOD_ADDER >= 0);
+		jan1_weekday = (jan1_since_epoch + 4 + DUK__WEEKDAY_MOD_ADDER) % 7;  /* E5.1 Section 15.9.1.6 */
+		DUK_ASSERT(jan1_weekday >= 0 && jan1_weekday <= 6);
+		arridx = jan1_weekday;
+		if (is_leap) {
+			arridx += 7;
+		}
+		DUK_ASSERT(arridx >= 0 && arridx < (duk_small_int_t) (sizeof(duk__date_equivyear) / sizeof(duk_uint8_t)));
+
+		equiv_year = (duk_int_t) duk__date_equivyear[arridx] + 1970;
+		year = equiv_year;
+		DUK_DDD(DUK_DDDPRINT("equiv year mapping, year=%ld, day_in_year=%ld, day_since_epoch=%ld, "
+		                     "jan1_since_epoch=%ld, jan1_weekday=%ld -> equiv year %ld",
+		                     (long) year, (long) day_in_year, (long) day_since_epoch,
+		                     (long) jan1_since_epoch, (long) jan1_weekday, (long) equiv_year));
+	}
+
+	parts[DUK_DATE_IDX_YEAR] = year;
+	parts[DUK_DATE_IDX_MONTH] = month;
+	parts[DUK_DATE_IDX_DAY] = day;
+
+	if (flags & DUK_DATE_FLAG_ONEBASED) {
+		parts[DUK_DATE_IDX_MONTH]++;  /* zero-based -> one-based */
+		parts[DUK_DATE_IDX_DAY]++;    /* -""- */
+	}
+
+	if (dparts != NULL) {
+		for (i = 0; i < DUK_DATE_IDX_NUM_PARTS; i++) {
+			dparts[i] = (duk_double_t) parts[i];
+		}
+	}
+}
+
+/* Compute time value from (double) parts.  The parts can be either UTC
+ * or local time; if local, they need to be (conceptually) converted into
+ * UTC time.  The parts may represent valid or invalid time, and may be
+ * wildly out of range (but may cancel each other and still come out in
+ * the valid Date range).
+ */
+DUK_INTERNAL duk_double_t duk_bi_date_get_timeval_from_dparts(duk_double_t *dparts, duk_small_uint_t flags) {
+#if defined(DUK_USE_PARANOID_DATE_COMPUTATION)
+	/* See comments below on MakeTime why these are volatile. */
+	volatile duk_double_t tmp_time;
+	volatile duk_double_t tmp_day;
+	volatile duk_double_t d;
+#else
+	duk_double_t tmp_time;
+	duk_double_t tmp_day;
+	duk_double_t d;
+#endif
+	duk_small_uint_t i;
+	duk_int_t tzoff, tzoffprev1, tzoffprev2;
+
+	/* Expects 'this' at top of stack on entry. */
+
+	/* Coerce all finite parts with ToInteger().  ToInteger() must not
+	 * be called for NaN/Infinity because it will convert e.g. NaN to
+	 * zero.  If ToInteger() has already been called, this has no side
+	 * effects and is idempotent.
+	 *
+	 * Don't read dparts[DUK_DATE_IDX_WEEKDAY]; it will cause Valgrind
+	 * issues if the value is uninitialized.
+	 */
+	for (i = 0; i <= DUK_DATE_IDX_MILLISECOND; i++) {
+		/* SCANBUILD: scan-build complains here about assigned value
+		 * being garbage or undefined.  This is correct but operating
+		 * on undefined values has no ill effect and is ignored by the
+		 * caller in the case where this happens.
+		 */
+		d = dparts[i];
+		if (DUK_ISFINITE(d)) {
+			dparts[i] = duk_js_tointeger_number(d);
+		}
+	}
+
+	/* Use explicit steps in computation to try to ensure that
+	 * computation happens with intermediate results coerced to
+	 * double values (instead of using something more accurate).
+	 * E.g. E5.1 Section 15.9.1.11 requires use of IEEE 754
+	 * rules (= Ecmascript '+' and '*' operators).
+	 *
+	 * Without 'volatile' even this approach fails on some platform
+	 * and compiler combinations.  For instance, gcc 4.8.1 on Ubuntu
+	 * 64-bit, with -m32 and without -std=c99, test-bi-date-canceling.js
+	 * would fail because of some optimizations when computing tmp_time
+	 * (MakeTime below).  Adding 'volatile' to tmp_time solved this
+	 * particular problem (annoyingly, also adding debug prints or
+	 * running the executable under valgrind hides it).
+	 */
+
+	/* MakeTime */
+	tmp_time = 0.0;
+	tmp_time += dparts[DUK_DATE_IDX_HOUR] * ((duk_double_t) DUK_DATE_MSEC_HOUR);
+	tmp_time += dparts[DUK_DATE_IDX_MINUTE] * ((duk_double_t) DUK_DATE_MSEC_MINUTE);
+	tmp_time += dparts[DUK_DATE_IDX_SECOND] * ((duk_double_t) DUK_DATE_MSEC_SECOND);
+	tmp_time += dparts[DUK_DATE_IDX_MILLISECOND];
+
+	/* MakeDay */
+	tmp_day = duk__make_day(dparts[DUK_DATE_IDX_YEAR], dparts[DUK_DATE_IDX_MONTH], dparts[DUK_DATE_IDX_DAY]);
+
+	/* MakeDate */
+	d = tmp_day * ((duk_double_t) DUK_DATE_MSEC_DAY) + tmp_time;
+
+	DUK_DDD(DUK_DDDPRINT("time=%lf day=%lf --> timeval=%lf",
+	                     (double) tmp_time, (double) tmp_day, (double) d));
+
+	/* Optional UTC conversion. */
+	if (flags & DUK_DATE_FLAG_LOCALTIME) {
+		/* DUK_USE_DATE_GET_LOCAL_TZOFFSET() needs to be called with a
+		 * time value computed from UTC parts.  At this point we only
+		 * have 'd' which is a time value computed from local parts, so
+		 * it is off by the UTC-to-local time offset which we don't know
+		 * yet.  The current solution for computing the UTC-to-local
+		 * time offset is to iterate a few times and detect a fixed
+		 * point or a two-cycle loop (or a sanity iteration limit),
+		 * see test-bi-date-local-parts.js and test-bi-date-tzoffset-basic-fi.js.
+		 *
+		 * E5.1 Section 15.9.1.9:
+		 * UTC(t) = t - LocalTZA - DaylightSavingTA(t - LocalTZA)
+		 *
+		 * For NaN/inf, DUK_USE_DATE_GET_LOCAL_TZOFFSET() returns 0.
+		 */
+
+#if 0
+		/* Old solution: don't iterate, incorrect */
+		tzoff = DUK_USE_DATE_GET_LOCAL_TZOFFSET(d);
+		DUK_DDD(DUK_DDDPRINT("tzoffset w/o iteration, tzoff=%ld", (long) tzoff));
+		d -= tzoff * 1000L;
+		DUK_UNREF(tzoffprev1);
+		DUK_UNREF(tzoffprev2);
+#endif
+
+		/* Iteration solution */
+		tzoff = 0;
+		tzoffprev1 = 999999999L;  /* invalid value which never matches */
+		for (i = 0; i < DUK__LOCAL_TZOFFSET_MAXITER; i++) {
+			tzoffprev2 = tzoffprev1;
+			tzoffprev1 = tzoff;
+			tzoff = DUK_USE_DATE_GET_LOCAL_TZOFFSET(d - tzoff * 1000L);
+			DUK_DDD(DUK_DDDPRINT("tzoffset iteration, i=%d, tzoff=%ld, tzoffprev1=%ld tzoffprev2=%ld",
+			                     (int) i, (long) tzoff, (long) tzoffprev1, (long) tzoffprev2));
+			if (tzoff == tzoffprev1) {
+				DUK_DDD(DUK_DDDPRINT("tzoffset iteration finished, i=%d, tzoff=%ld, tzoffprev1=%ld, tzoffprev2=%ld",
+				                     (int) i, (long) tzoff, (long) tzoffprev1, (long) tzoffprev2));
+				break;
+			} else if (tzoff == tzoffprev2) {
+				/* Two value cycle, see e.g. test-bi-date-tzoffset-basic-fi.js.
+				 * In these cases, favor a higher tzoffset to get a consistent
+				 * result which is independent of iteration count.  Not sure if
+				 * this is a generically correct solution.
+				 */
+				DUK_DDD(DUK_DDDPRINT("tzoffset iteration two-value cycle, i=%d, tzoff=%ld, tzoffprev1=%ld, tzoffprev2=%ld",
+				                     (int) i, (long) tzoff, (long) tzoffprev1, (long) tzoffprev2));
+				if (tzoffprev1 > tzoff) {
+					tzoff = tzoffprev1;
+				}
+				break;
+			}
+		}
+		DUK_DDD(DUK_DDDPRINT("tzoffset iteration, tzoff=%ld", (long) tzoff));
+		d -= tzoff * 1000L;
+	}
+
+	/* TimeClip(), which also handles Infinity -> NaN conversion */
+	d = duk__timeclip(d);
+
+	return d;
+}
+
+/*
+ *  API oriented helpers
+ */
+
+/* Push 'this' binding, check that it is a Date object; then push the
+ * internal time value.  At the end, stack is: [ ... this timeval ].
+ * Returns the time value.  Local time adjustment is done if requested.
+ */
+DUK_LOCAL duk_double_t duk__push_this_get_timeval_tzoffset(duk_context *ctx, duk_small_uint_t flags, duk_int_t *out_tzoffset) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_hobject *h;
+	duk_double_t d;
+	duk_int_t tzoffset = 0;
+
+	duk_push_this(ctx);
+	h = duk_get_hobject(ctx, -1);  /* XXX: getter with class check, useful in built-ins */
+	if (h == NULL || DUK_HOBJECT_GET_CLASS_NUMBER(h) != DUK_HOBJECT_CLASS_DATE) {
+		DUK_ERROR_TYPE(thr, "expected Date");
+	}
+
+	duk_get_prop_stridx(ctx, -1, DUK_STRIDX_INT_VALUE);
+	d = duk_to_number(ctx, -1);
+	duk_pop(ctx);
+
+	if (DUK_ISNAN(d)) {
+		if (flags & DUK_DATE_FLAG_NAN_TO_ZERO) {
+			d = 0.0;
+		}
+		if (flags & DUK_DATE_FLAG_NAN_TO_RANGE_ERROR) {
+			DUK_ERROR_RANGE(thr, "Invalid Date");
+		}
+	}
+	/* if no NaN handling flag, may still be NaN here, but not Inf */
+	DUK_ASSERT(!DUK_ISINF(d));
+
+	if (flags & DUK_DATE_FLAG_LOCALTIME) {
+		/* Note: DST adjustment is determined using UTC time.
+		 * If 'd' is NaN, tzoffset will be 0.
+		 */
+		tzoffset = DUK_USE_DATE_GET_LOCAL_TZOFFSET(d);  /* seconds */
+		d += tzoffset * 1000L;
+	}
+	if (out_tzoffset) {
+		*out_tzoffset = tzoffset;
+	}
+
+	/* [ ... this ] */
+	return d;
+}
+
+DUK_LOCAL duk_double_t duk__push_this_get_timeval(duk_context *ctx, duk_small_uint_t flags) {
+	return duk__push_this_get_timeval_tzoffset(ctx, flags, NULL);
+}
+
+/* Set timeval to 'this' from dparts, push the new time value onto the
+ * value stack and return 1 (caller can then tail call us).  Expects
+ * the value stack to contain 'this' on the stack top.
+ */
+DUK_LOCAL duk_ret_t duk__set_this_timeval_from_dparts(duk_context *ctx, duk_double_t *dparts, duk_small_uint_t flags) {
+	duk_double_t d;
+
+	/* [ ... this ] */
+
+	d = duk_bi_date_get_timeval_from_dparts(dparts, flags);
+	duk_push_number(ctx, d);  /* -> [ ... this timeval_new ] */
+	duk_dup_top(ctx);         /* -> [ ... this timeval_new timeval_new ] */
+	duk_put_prop_stridx(ctx, -3, DUK_STRIDX_INT_VALUE);
+
+	/* stack top: new time value, return 1 to allow tail calls */
+	return 1;
+}
+
+/* 'out_buf' must be at least DUK_BI_DATE_ISO8601_BUFSIZE long. */
+DUK_LOCAL void duk__format_parts_iso8601(duk_int_t *parts, duk_int_t tzoffset, duk_small_uint_t flags, duk_uint8_t *out_buf) {
+	char yearstr[8];   /* "-123456\0" */
+	char tzstr[8];     /* "+11:22\0" */
+	char sep = (flags & DUK_DATE_FLAG_SEP_T) ? DUK_ASC_UC_T : DUK_ASC_SPACE;
+
+	DUK_ASSERT(parts[DUK_DATE_IDX_MONTH] >= 1 && parts[DUK_DATE_IDX_MONTH] <= 12);
+	DUK_ASSERT(parts[DUK_DATE_IDX_DAY] >= 1 && parts[DUK_DATE_IDX_DAY] <= 31);
+	DUK_ASSERT(parts[DUK_DATE_IDX_YEAR] >= -999999 && parts[DUK_DATE_IDX_YEAR] <= 999999);
+
+	/* Note: %06d for positive value, %07d for negative value to include
+	 * sign and 6 digits.
+	 */
+	DUK_SNPRINTF(yearstr,
+	             sizeof(yearstr),
+	             (parts[DUK_DATE_IDX_YEAR] >= 0 && parts[DUK_DATE_IDX_YEAR] <= 9999) ? "%04ld" :
+	                    ((parts[DUK_DATE_IDX_YEAR] >= 0) ? "+%06ld" : "%07ld"),
+	             (long) parts[DUK_DATE_IDX_YEAR]);
+	yearstr[sizeof(yearstr) - 1] = (char) 0;
+
+	if (flags & DUK_DATE_FLAG_LOCALTIME) {
+		/* tzoffset seconds are dropped; 16 bits suffice for
+		 * time offset in minutes
+		 */
+		if (tzoffset >= 0) {
+			duk_small_int_t tmp = tzoffset / 60;
+			DUK_SNPRINTF(tzstr, sizeof(tzstr), "+%02d:%02d", (int) (tmp / 60), (int) (tmp % 60));
+		} else {
+			duk_small_int_t tmp = -tzoffset / 60;
+			DUK_SNPRINTF(tzstr, sizeof(tzstr), "-%02d:%02d", (int) (tmp / 60), (int) (tmp % 60));
+		}
+		tzstr[sizeof(tzstr) - 1] = (char) 0;
+	} else {
+		tzstr[0] = DUK_ASC_UC_Z;
+		tzstr[1] = (char) 0;
+	}
+
+	/* Unlike year, the other parts fit into 16 bits so %d format
+	 * is portable.
+	 */
+	if ((flags & DUK_DATE_FLAG_TOSTRING_DATE) && (flags & DUK_DATE_FLAG_TOSTRING_TIME)) {
+		DUK_SPRINTF((char *) out_buf, "%s-%02d-%02d%c%02d:%02d:%02d.%03d%s",
+		            (const char *) yearstr, (int) parts[DUK_DATE_IDX_MONTH], (int) parts[DUK_DATE_IDX_DAY], (int) sep,
+		            (int) parts[DUK_DATE_IDX_HOUR], (int) parts[DUK_DATE_IDX_MINUTE],
+		            (int) parts[DUK_DATE_IDX_SECOND], (int) parts[DUK_DATE_IDX_MILLISECOND], (const char *) tzstr);
+	} else if (flags & DUK_DATE_FLAG_TOSTRING_DATE) {
+		DUK_SPRINTF((char *) out_buf, "%s-%02d-%02d",
+		            (const char *) yearstr, (int) parts[DUK_DATE_IDX_MONTH], (int) parts[DUK_DATE_IDX_DAY]);
+	} else {
+		DUK_ASSERT(flags & DUK_DATE_FLAG_TOSTRING_TIME);
+		DUK_SPRINTF((char *) out_buf, "%02d:%02d:%02d.%03d%s",
+		            (int) parts[DUK_DATE_IDX_HOUR], (int) parts[DUK_DATE_IDX_MINUTE],
+		            (int) parts[DUK_DATE_IDX_SECOND], (int) parts[DUK_DATE_IDX_MILLISECOND],
+		            (const char *) tzstr);
+	}
+}
+
+/* Helper for string conversion calls: check 'this' binding, get the
+ * internal time value, and format date and/or time in a few formats.
+ * Return value allows tail calls.
+ */
+DUK_LOCAL duk_ret_t duk__to_string_helper(duk_context *ctx, duk_small_uint_t flags) {
+	duk_double_t d;
+	duk_int_t parts[DUK_DATE_IDX_NUM_PARTS];
+	duk_int_t tzoffset;  /* seconds, doesn't fit into 16 bits */
+	duk_bool_t rc;
+	duk_uint8_t buf[DUK_BI_DATE_ISO8601_BUFSIZE];
+
+	DUK_UNREF(rc);  /* unreferenced with some options */
+
+	d = duk__push_this_get_timeval_tzoffset(ctx, flags, &tzoffset);
+	if (DUK_ISNAN(d)) {
+		duk_push_hstring_stridx(ctx, DUK_STRIDX_INVALID_DATE);
+		return 1;
+	}
+	DUK_ASSERT(DUK_ISFINITE(d));
+
+	/* formatters always get one-based month/day-of-month */
+	duk_bi_date_timeval_to_parts(d, parts, NULL, DUK_DATE_FLAG_ONEBASED);
+	DUK_ASSERT(parts[DUK_DATE_IDX_MONTH] >= 1 && parts[DUK_DATE_IDX_MONTH] <= 12);
+	DUK_ASSERT(parts[DUK_DATE_IDX_DAY] >= 1 && parts[DUK_DATE_IDX_DAY] <= 31);
+
+	if (flags & DUK_DATE_FLAG_TOSTRING_LOCALE) {
+		/* try locale specific formatter; if it refuses to format the
+		 * string, fall back to an ISO 8601 formatted value in local
+		 * time.
+		 */
+#if defined(DUK_USE_DATE_FORMAT_STRING)
+		/* Contract, either:
+		 * - Push string to value stack and return 1
+		 * - Don't push anything and return 0
+		 */
+
+		rc = DUK_USE_DATE_FORMAT_STRING(ctx, parts, tzoffset, flags);
+		if (rc != 0) {
+			return 1;
+		}
+#else
+		/* No locale specific formatter; this is OK, we fall back
+		 * to ISO 8601.
+		 */
+#endif
+	}
+
+	/* Different calling convention than above used because the helper
+	 * is shared.
+	 */
+	duk__format_parts_iso8601(parts, tzoffset, flags, buf);
+	duk_push_string(ctx, (const char *) buf);
+	return 1;
+}
+
+/* Helper for component getter calls: check 'this' binding, get the
+ * internal time value, split it into parts (either as UTC time or
+ * local time), push a specified component as a return value to the
+ * value stack and return 1 (caller can then tail call us).
+ */
+DUK_LOCAL duk_ret_t duk__get_part_helper(duk_context *ctx, duk_small_uint_t flags_and_idx) {
+	duk_double_t d;
+	duk_int_t parts[DUK_DATE_IDX_NUM_PARTS];
+	duk_small_uint_t idx_part = (duk_small_uint_t) (flags_and_idx >> DUK_DATE_FLAG_VALUE_SHIFT);  /* unpack args */
+
+	DUK_ASSERT_DISABLE(idx_part >= 0);  /* unsigned */
+	DUK_ASSERT(idx_part < DUK_DATE_IDX_NUM_PARTS);
+
+	d = duk__push_this_get_timeval(ctx, flags_and_idx);
+	if (DUK_ISNAN(d)) {
+		duk_push_nan(ctx);
+		return 1;
+	}
+	DUK_ASSERT(DUK_ISFINITE(d));
+
+	duk_bi_date_timeval_to_parts(d, parts, NULL, flags_and_idx);  /* no need to mask idx portion */
+
+	/* Setter APIs detect special year numbers (0...99) and apply a +1900
+	 * only in certain cases.  The legacy getYear() getter applies -1900
+	 * unconditionally.
+	 */
+	duk_push_int(ctx, (flags_and_idx & DUK_DATE_FLAG_SUB1900) ? parts[idx_part] - 1900 : parts[idx_part]);
+	return 1;
+}
+
+/* Helper for component setter calls: check 'this' binding, get the
+ * internal time value, split it into parts (either as UTC time or
+ * local time), modify one or more components as specified, recompute
+ * the time value, set it as the internal value.  Finally, push the
+ * new time value as a return value to the value stack and return 1
+ * (caller can then tail call us).
+ */
+DUK_LOCAL duk_ret_t duk__set_part_helper(duk_context *ctx, duk_small_uint_t flags_and_maxnargs) {
+	duk_double_t d;
+	duk_int_t parts[DUK_DATE_IDX_NUM_PARTS];
+	duk_double_t dparts[DUK_DATE_IDX_NUM_PARTS];
+	duk_idx_t nargs;
+	duk_small_uint_t maxnargs = (duk_small_uint_t) (flags_and_maxnargs >> DUK_DATE_FLAG_VALUE_SHIFT);  /* unpack args */
+	duk_small_uint_t idx_first, idx;
+	duk_small_uint_t i;
+
+	nargs = duk_get_top(ctx);
+	d = duk__push_this_get_timeval(ctx, flags_and_maxnargs);
+	DUK_ASSERT(DUK_ISFINITE(d) || DUK_ISNAN(d));
+
+	if (DUK_ISFINITE(d)) {
+		duk_bi_date_timeval_to_parts(d, parts, dparts, flags_and_maxnargs);
+	} else {
+		/* NaN timevalue: we need to coerce the arguments, but
+		 * the resulting internal timestamp needs to remain NaN.
+		 * This works but is not pretty: parts and dparts will
+		 * be partially uninitialized, but we only write to them.
+		 */
+	}
+
+	/*
+	 *  Determining which datetime components to overwrite based on
+	 *  stack arguments is a bit complicated, but important to factor
+	 *  out from setters themselves for compactness.
+	 *
+	 *  If DUK_DATE_FLAG_TIMESETTER, maxnargs indicates setter type:
+	 *
+	 *   1 -> millisecond
+	 *   2 -> second, [millisecond]
+	 *   3 -> minute, [second], [millisecond]
+	 *   4 -> hour, [minute], [second], [millisecond]
+	 *
+	 *  Else:
+	 *
+	 *   1 -> date
+	 *   2 -> month, [date]
+	 *   3 -> year, [month], [date]
+	 *
+	 *  By comparing nargs and maxnargs (and flags) we know which
+	 *  components to override.  We rely on part index ordering.
+	 */
+
+	if (flags_and_maxnargs & DUK_DATE_FLAG_TIMESETTER) {
+		DUK_ASSERT(maxnargs >= 1 && maxnargs <= 4);
+		idx_first = DUK_DATE_IDX_MILLISECOND - (maxnargs - 1);
+	} else {
+		DUK_ASSERT(maxnargs >= 1 && maxnargs <= 3);
+		idx_first = DUK_DATE_IDX_DAY - (maxnargs - 1);
+	}
+	DUK_ASSERT_DISABLE(idx_first >= 0);  /* unsigned */
+	DUK_ASSERT(idx_first < DUK_DATE_IDX_NUM_PARTS);
+
+	for (i = 0; i < maxnargs; i++) {
+		if ((duk_idx_t) i >= nargs) {
+			/* no argument given -> leave components untouched */
+			break;
+		}
+		idx = idx_first + i;
+		DUK_ASSERT_DISABLE(idx >= 0);  /* unsigned */
+		DUK_ASSERT(idx < DUK_DATE_IDX_NUM_PARTS);
+
+		if (idx == DUK_DATE_IDX_YEAR && (flags_and_maxnargs & DUK_DATE_FLAG_YEAR_FIXUP)) {
+			duk__twodigit_year_fixup(ctx, (duk_idx_t) i);
+		}
+
+		dparts[idx] = duk_to_number(ctx, i);
+
+		if (idx == DUK_DATE_IDX_DAY) {
+			/* Day-of-month is one-based in the API, but zero-based
+			 * internally, so fix here.  Note that month is zero-based
+			 * both in the API and internally.
+			 */
+			/* SCANBUILD: complains about use of uninitialized values.
+			 * The complaint is correct, but operating in undefined
+			 * values here is intentional in some cases and the caller
+			 * ignores the results.
+			 */
+			dparts[idx] -= 1.0;
+		}
+	}
+
+	/* Leaves new timevalue on stack top and returns 1, which is correct
+	 * for part setters.
+	 */
+	if (DUK_ISFINITE(d)) {
+		return duk__set_this_timeval_from_dparts(ctx, dparts, flags_and_maxnargs);
+	} else {
+		/* Internal timevalue is already NaN, so don't touch it. */
+		duk_push_nan(ctx);
+		return 1;
+	}
+}
+
+/* Apply ToNumber() to specified index; if ToInteger(val) in [0,99], add
+ * 1900 and replace value at idx_val.
+ */
+DUK_LOCAL void duk__twodigit_year_fixup(duk_context *ctx, duk_idx_t idx_val) {
+	duk_double_t d;
+
+	/* XXX: idx_val would fit into 16 bits, but using duk_small_uint_t
+	 * might not generate better code due to casting.
+	 */
+
+	/* E5 Sections 15.9.3.1, B.2.4, B.2.5 */
+	duk_to_number(ctx, idx_val);
+	if (duk_is_nan(ctx, idx_val)) {
+		return;
+	}
+	duk_dup(ctx, idx_val);
+	duk_to_int(ctx, -1);
+	d = duk_get_number(ctx, -1);  /* get as double to handle huge numbers correctly */
+	if (d >= 0.0 && d <= 99.0) {
+		d += 1900.0;
+		duk_push_number(ctx, d);
+		duk_replace(ctx, idx_val);
+	}
+	duk_pop(ctx);
+}
+
+/* Set datetime parts from stack arguments, defaulting any missing values.
+ * Day-of-week is not set; it is not required when setting the time value.
+ */
+DUK_LOCAL void duk__set_parts_from_args(duk_context *ctx, duk_double_t *dparts, duk_idx_t nargs) {
+	duk_double_t d;
+	duk_small_uint_t i;
+	duk_small_uint_t idx;
+
+	/* Causes a ToNumber() coercion, but doesn't break coercion order since
+	 * year is coerced first anyway.
+	 */
+	duk__twodigit_year_fixup(ctx, 0);
+
+	/* There are at most 7 args, but we use 8 here so that also
+	 * DUK_DATE_IDX_WEEKDAY gets initialized (to zero) to avoid the potential
+	 * for any Valgrind gripes later.
+	 */
+	for (i = 0; i < 8; i++) {
+		/* Note: rely on index ordering */
+		idx = DUK_DATE_IDX_YEAR + i;
+		if ((duk_idx_t) i < nargs) {
+			d = duk_to_number(ctx, (duk_idx_t) i);
+			if (idx == DUK_DATE_IDX_DAY) {
+				/* Convert day from one-based to zero-based (internal).  This may
+				 * cause the day part to be negative, which is OK.
+				 */
+				d -= 1.0;
+			}
+		} else {
+			/* All components default to 0 except day-of-month which defaults
+			 * to 1.  However, because our internal day-of-month is zero-based,
+			 * it also defaults to zero here.
+			 */
+			d = 0.0;
+		}
+		dparts[idx] = d;
+	}
+
+	DUK_DDD(DUK_DDDPRINT("parts from args -> %lf %lf %lf %lf %lf %lf %lf %lf",
+	                     (double) dparts[0], (double) dparts[1],
+	                     (double) dparts[2], (double) dparts[3],
+	                     (double) dparts[4], (double) dparts[5],
+	                     (double) dparts[6], (double) dparts[7]));
+}
+
+/*
+ *  Helper to format a time value into caller buffer, used by logging.
+ *  'out_buf' must be at least DUK_BI_DATE_ISO8601_BUFSIZE long.
+ */
+
+DUK_INTERNAL void duk_bi_date_format_timeval(duk_double_t timeval, duk_uint8_t *out_buf) {
+	duk_int_t parts[DUK_DATE_IDX_NUM_PARTS];
+
+	duk_bi_date_timeval_to_parts(timeval,
+	                             parts,
+	                             NULL,
+	                             DUK_DATE_FLAG_ONEBASED);
+
+	duk__format_parts_iso8601(parts,
+	                          0 /*tzoffset*/,
+	                          DUK_DATE_FLAG_TOSTRING_DATE |
+	                          DUK_DATE_FLAG_TOSTRING_TIME |
+	                          DUK_DATE_FLAG_SEP_T /*flags*/,
+	                          out_buf);
+}
+
+/*
+ *  Indirect magic value lookup for Date methods.
+ *
+ *  Date methods don't put their control flags into the function magic value
+ *  because they wouldn't fit into a LIGHTFUNC's magic field.  Instead, the
+ *  magic value is set to an index pointing to the array of control flags
+ *  below.
+ *
+ *  This must be kept in strict sync with genbuiltins.py!
+ */
+
+static duk_uint16_t duk__date_magics[] = {
+	/* 0: toString */
+	DUK_DATE_FLAG_TOSTRING_DATE + DUK_DATE_FLAG_TOSTRING_TIME + DUK_DATE_FLAG_LOCALTIME,
+
+	/* 1: toDateString */
+	DUK_DATE_FLAG_TOSTRING_DATE + DUK_DATE_FLAG_LOCALTIME,
+
+	/* 2: toTimeString */
+	DUK_DATE_FLAG_TOSTRING_TIME + DUK_DATE_FLAG_LOCALTIME,
+
+	/* 3: toLocaleString */
+	DUK_DATE_FLAG_TOSTRING_DATE + DUK_DATE_FLAG_TOSTRING_TIME + DUK_DATE_FLAG_TOSTRING_LOCALE + DUK_DATE_FLAG_LOCALTIME,
+
+	/* 4: toLocaleDateString */
+	DUK_DATE_FLAG_TOSTRING_DATE + DUK_DATE_FLAG_TOSTRING_LOCALE + DUK_DATE_FLAG_LOCALTIME,
+
+	/* 5: toLocaleTimeString */
+	DUK_DATE_FLAG_TOSTRING_TIME + DUK_DATE_FLAG_TOSTRING_LOCALE + DUK_DATE_FLAG_LOCALTIME,
+
+	/* 6: toUTCString */
+	DUK_DATE_FLAG_TOSTRING_DATE + DUK_DATE_FLAG_TOSTRING_TIME,
+
+	/* 7: toISOString */
+	DUK_DATE_FLAG_TOSTRING_DATE + DUK_DATE_FLAG_TOSTRING_TIME + DUK_DATE_FLAG_NAN_TO_RANGE_ERROR + DUK_DATE_FLAG_SEP_T,
+
+	/* 8: getFullYear */
+	DUK_DATE_FLAG_LOCALTIME + (DUK_DATE_IDX_YEAR << DUK_DATE_FLAG_VALUE_SHIFT),
+
+	/* 9: getUTCFullYear */
+	0 + (DUK_DATE_IDX_YEAR << DUK_DATE_FLAG_VALUE_SHIFT),
+
+	/* 10: getMonth */
+	DUK_DATE_FLAG_LOCALTIME + (DUK_DATE_IDX_MONTH << DUK_DATE_FLAG_VALUE_SHIFT),
+
+	/* 11: getUTCMonth */
+	0 + (DUK_DATE_IDX_MONTH << DUK_DATE_FLAG_VALUE_SHIFT),
+
+	/* 12: getDate */
+	DUK_DATE_FLAG_ONEBASED + DUK_DATE_FLAG_LOCALTIME + (DUK_DATE_IDX_DAY << DUK_DATE_FLAG_VALUE_SHIFT),
+
+	/* 13: getUTCDate */
+	DUK_DATE_FLAG_ONEBASED + (DUK_DATE_IDX_DAY << DUK_DATE_FLAG_VALUE_SHIFT),
+
+	/* 14: getDay */
+	DUK_DATE_FLAG_LOCALTIME + (DUK_DATE_IDX_WEEKDAY << DUK_DATE_FLAG_VALUE_SHIFT),
+
+	/* 15: getUTCDay */
+	0 + (DUK_DATE_IDX_WEEKDAY << DUK_DATE_FLAG_VALUE_SHIFT),
+
+	/* 16: getHours */
+	DUK_DATE_FLAG_LOCALTIME + (DUK_DATE_IDX_HOUR << DUK_DATE_FLAG_VALUE_SHIFT),
+
+	/* 17: getUTCHours */
+	0 + (DUK_DATE_IDX_HOUR << DUK_DATE_FLAG_VALUE_SHIFT),
+
+	/* 18: getMinutes */
+	DUK_DATE_FLAG_LOCALTIME + (DUK_DATE_IDX_MINUTE << DUK_DATE_FLAG_VALUE_SHIFT),
+
+	/* 19: getUTCMinutes */
+	0 + (DUK_DATE_IDX_MINUTE << DUK_DATE_FLAG_VALUE_SHIFT),
+
+	/* 20: getSeconds */
+	DUK_DATE_FLAG_LOCALTIME + (DUK_DATE_IDX_SECOND << DUK_DATE_FLAG_VALUE_SHIFT),
+
+	/* 21: getUTCSeconds */
+	0 + (DUK_DATE_IDX_SECOND << DUK_DATE_FLAG_VALUE_SHIFT),
+
+	/* 22: getMilliseconds */
+	DUK_DATE_FLAG_LOCALTIME + (DUK_DATE_IDX_MILLISECOND << DUK_DATE_FLAG_VALUE_SHIFT),
+
+	/* 23: getUTCMilliseconds */
+	0 + (DUK_DATE_IDX_MILLISECOND << DUK_DATE_FLAG_VALUE_SHIFT),
+
+	/* 24: setMilliseconds */
+	DUK_DATE_FLAG_TIMESETTER + DUK_DATE_FLAG_LOCALTIME + (1 << DUK_DATE_FLAG_VALUE_SHIFT),
+
+	/* 25: setUTCMilliseconds */
+	DUK_DATE_FLAG_TIMESETTER + (1 << DUK_DATE_FLAG_VALUE_SHIFT),
+
+	/* 26: setSeconds */
+	DUK_DATE_FLAG_TIMESETTER + DUK_DATE_FLAG_LOCALTIME + (2 << DUK_DATE_FLAG_VALUE_SHIFT),
+
+	/* 27: setUTCSeconds */
+	DUK_DATE_FLAG_TIMESETTER + (2 << DUK_DATE_FLAG_VALUE_SHIFT),
+
+	/* 28: setMinutes */
+	DUK_DATE_FLAG_TIMESETTER + DUK_DATE_FLAG_LOCALTIME + (3 << DUK_DATE_FLAG_VALUE_SHIFT),
+
+	/* 29: setUTCMinutes */
+	DUK_DATE_FLAG_TIMESETTER + (3 << DUK_DATE_FLAG_VALUE_SHIFT),
+
+	/* 30: setHours */
+	DUK_DATE_FLAG_TIMESETTER + DUK_DATE_FLAG_LOCALTIME + (4 << DUK_DATE_FLAG_VALUE_SHIFT),
+
+	/* 31: setUTCHours */
+	DUK_DATE_FLAG_TIMESETTER + (4 << DUK_DATE_FLAG_VALUE_SHIFT),
+
+	/* 32: setDate */
+	DUK_DATE_FLAG_LOCALTIME + (1 << DUK_DATE_FLAG_VALUE_SHIFT),
+
+	/* 33: setUTCDate */
+	0 + (1 << DUK_DATE_FLAG_VALUE_SHIFT),
+
+	/* 34: setMonth */
+	DUK_DATE_FLAG_LOCALTIME + (2 << DUK_DATE_FLAG_VALUE_SHIFT),
+
+	/* 35: setUTCMonth */
+	0 + (2 << DUK_DATE_FLAG_VALUE_SHIFT),
+
+	/* 36: setFullYear */
+	DUK_DATE_FLAG_NAN_TO_ZERO + DUK_DATE_FLAG_LOCALTIME + (3 << DUK_DATE_FLAG_VALUE_SHIFT),
+
+	/* 37: setUTCFullYear */
+	DUK_DATE_FLAG_NAN_TO_ZERO + (3 << DUK_DATE_FLAG_VALUE_SHIFT),
+
+	/* 38: getYear */
+	DUK_DATE_FLAG_LOCALTIME + DUK_DATE_FLAG_SUB1900 + (DUK_DATE_IDX_YEAR << DUK_DATE_FLAG_VALUE_SHIFT),
+
+	/* 39: setYear */
+	DUK_DATE_FLAG_NAN_TO_ZERO + DUK_DATE_FLAG_YEAR_FIXUP + (3 << DUK_DATE_FLAG_VALUE_SHIFT),
+};
+
+DUK_LOCAL duk_small_uint_t duk__date_get_indirect_magic(duk_context *ctx) {
+	duk_small_int_t magicidx = (duk_small_uint_t) duk_get_current_magic(ctx);
+	DUK_ASSERT(magicidx >= 0 && magicidx < (duk_small_int_t) (sizeof(duk__date_magics) / sizeof(duk_uint16_t)));
+	return (duk_small_uint_t) duk__date_magics[magicidx];
+}
+
+/*
+ *  Constructor calls
+ */
+
+DUK_INTERNAL duk_ret_t duk_bi_date_constructor(duk_context *ctx) {
+	duk_idx_t nargs = duk_get_top(ctx);
+	duk_bool_t is_cons = duk_is_constructor_call(ctx);
+	duk_double_t dparts[DUK_DATE_IDX_NUM_PARTS];
+	duk_double_t d;
+
+	DUK_DDD(DUK_DDDPRINT("Date constructor, nargs=%ld, is_cons=%ld", (long) nargs, (long) is_cons));
+
+	duk_push_object_helper(ctx,
+	                       DUK_HOBJECT_FLAG_EXTENSIBLE |
+	                       DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_DATE),
+	                       DUK_BIDX_DATE_PROTOTYPE);
+
+	/* Unlike most built-ins, the internal [[PrimitiveValue]] of a Date
+	 * is mutable.
+	 */
+
+	if (nargs == 0 || !is_cons) {
+		d = duk__timeclip(DUK_USE_DATE_GET_NOW(ctx));
+		duk_push_number(ctx, d);
+		duk_xdef_prop_stridx(ctx, -2, DUK_STRIDX_INT_VALUE, DUK_PROPDESC_FLAGS_W);
+		if (!is_cons) {
+			/* called as a normal function: return new Date().toString() */
+			duk_to_string(ctx, -1);
+		}
+		return 1;
+	} else if (nargs == 1) {
+		duk_to_primitive(ctx, 0, DUK_HINT_NONE);
+		if (duk_is_string(ctx, 0)) {
+			duk__parse_string(ctx, duk_to_string(ctx, 0));
+			duk_replace(ctx, 0);  /* may be NaN */
+		}
+		d = duk__timeclip(duk_to_number(ctx, 0));
+		duk_push_number(ctx, d);
+		duk_xdef_prop_stridx(ctx, -2, DUK_STRIDX_INT_VALUE, DUK_PROPDESC_FLAGS_W);
+		return 1;
+	}
+
+	duk__set_parts_from_args(ctx, dparts, nargs);
+
+	/* Parts are in local time, convert when setting. */
+
+	(void) duk__set_this_timeval_from_dparts(ctx, dparts, DUK_DATE_FLAG_LOCALTIME /*flags*/);  /* -> [ ... this timeval ] */
+	duk_pop(ctx);  /* -> [ ... this ] */
+	return 1;
+}
+
+DUK_INTERNAL duk_ret_t duk_bi_date_constructor_parse(duk_context *ctx) {
+	return duk__parse_string(ctx, duk_to_string(ctx, 0));
+}
+
+DUK_INTERNAL duk_ret_t duk_bi_date_constructor_utc(duk_context *ctx) {
+	duk_idx_t nargs = duk_get_top(ctx);
+	duk_double_t dparts[DUK_DATE_IDX_NUM_PARTS];
+	duk_double_t d;
+
+	/* Behavior for nargs < 2 is implementation dependent: currently we'll
+	 * set a NaN time value (matching V8 behavior) in this case.
+	 */
+
+	if (nargs < 2) {
+		duk_push_nan(ctx);
+	} else {
+		duk__set_parts_from_args(ctx, dparts, nargs);
+		d = duk_bi_date_get_timeval_from_dparts(dparts, 0 /*flags*/);
+		duk_push_number(ctx, d);
+	}
+	return 1;
+}
+
+DUK_INTERNAL duk_ret_t duk_bi_date_constructor_now(duk_context *ctx) {
+	duk_double_t d;
+
+	d = DUK_USE_DATE_GET_NOW(ctx);
+	DUK_ASSERT(duk__timeclip(d) == d);  /* TimeClip() should never be necessary */
+	duk_push_number(ctx, d);
+	return 1;
+}
+
+/*
+ *  String/JSON conversions
+ *
+ *  Human readable conversions are now basically ISO 8601 with a space
+ *  (instead of 'T') as the date/time separator.  This is a good baseline
+ *  and is platform independent.
+ *
+ *  A shared native helper to provide many conversions.  Magic value contains
+ *  a set of flags.  The helper provides:
+ *
+ *    toString()
+ *    toDateString()
+ *    toTimeString()
+ *    toLocaleString()
+ *    toLocaleDateString()
+ *    toLocaleTimeString()
+ *    toUTCString()
+ *    toISOString()
+ *
+ *  Notes:
+ *
+ *    - Date.prototype.toGMTString() and Date.prototype.toUTCString() are
+ *      required to be the same Ecmascript function object (!), so it is
+ *      omitted from here.
+ *
+ *    - Date.prototype.toUTCString(): E5.1 specification does not require a
+ *      specific format, but result should be human readable.  The
+ *      specification suggests using ISO 8601 format with a space (instead
+ *      of 'T') separator if a more human readable format is not available.
+ *
+ *    - Date.prototype.toISOString(): unlike other conversion functions,
+ *      toISOString() requires a RangeError for invalid date values.
+ */
+
+DUK_INTERNAL duk_ret_t duk_bi_date_prototype_tostring_shared(duk_context *ctx) {
+	duk_small_uint_t flags = duk__date_get_indirect_magic(ctx);
+	return duk__to_string_helper(ctx, flags);
+}
+
+DUK_INTERNAL duk_ret_t duk_bi_date_prototype_value_of(duk_context *ctx) {
+	/* This native function is also used for Date.prototype.getTime()
+	 * as their behavior is identical.
+	 */
+
+	duk_double_t d = duk__push_this_get_timeval(ctx, 0 /*flags*/);  /* -> [ this ] */
+	DUK_ASSERT(DUK_ISFINITE(d) || DUK_ISNAN(d));
+	duk_push_number(ctx, d);
+	return 1;
+}
+
+DUK_INTERNAL duk_ret_t duk_bi_date_prototype_to_json(duk_context *ctx) {
+	/* Note: toJSON() is a generic function which works even if 'this'
+	 * is not a Date.  The sole argument is ignored.
+	 */
+
+	duk_push_this(ctx);
+	duk_to_object(ctx, -1);
+
+	duk_dup_top(ctx);
+	duk_to_primitive(ctx, -1, DUK_HINT_NUMBER);
+	if (duk_is_number(ctx, -1)) {
+		duk_double_t d = duk_get_number(ctx, -1);
+		if (!DUK_ISFINITE(d)) {
+			duk_push_null(ctx);
+			return 1;
+		}
+	}
+	duk_pop(ctx);
+
+	duk_get_prop_stridx(ctx, -1, DUK_STRIDX_TO_ISO_STRING);
+	duk_dup(ctx, -2);  /* -> [ O toIsoString O ] */
+	duk_call_method(ctx, 0);
+	return 1;
+}
+
+/*
+ *  Getters.
+ *
+ *  Implementing getters is quite easy.  The internal time value is either
+ *  NaN, or represents milliseconds (without fractions) from Jan 1, 1970.
+ *  The internal time value can be converted to integer parts, and each
+ *  part will be normalized and will fit into a 32-bit signed integer.
+ *
+ *  A shared native helper to provide all getters.  Magic value contains
+ *  a set of flags and also packs the date component index argument.  The
+ *  helper provides:
+ *
+ *    getFullYear()
+ *    getUTCFullYear()
+ *    getMonth()
+ *    getUTCMonth()
+ *    getDate()
+ *    getUTCDate()
+ *    getDay()
+ *    getUTCDay()
+ *    getHours()
+ *    getUTCHours()
+ *    getMinutes()
+ *    getUTCMinutes()
+ *    getSeconds()
+ *    getUTCSeconds()
+ *    getMilliseconds()
+ *    getUTCMilliseconds()
+ *    getYear()
+ *
+ *  Notes:
+ *
+ *    - Date.prototype.getDate(): 'date' means day-of-month, and is
+ *      zero-based in internal calculations but public API expects it to
+ *      be one-based.
+ *
+ *    - Date.prototype.getTime() and Date.prototype.valueOf() have identical
+ *      behavior.  They have separate function objects, but share the same C
+ *      function (duk_bi_date_prototype_value_of).
+ */
+
+DUK_INTERNAL duk_ret_t duk_bi_date_prototype_get_shared(duk_context *ctx) {
+	duk_small_uint_t flags_and_idx = duk__date_get_indirect_magic(ctx);
+	return duk__get_part_helper(ctx, flags_and_idx);
+}
+
+DUK_INTERNAL duk_ret_t duk_bi_date_prototype_get_timezone_offset(duk_context *ctx) {
+	/*
+	 *  Return (t - LocalTime(t)) in minutes:
+	 *
+	 *    t - LocalTime(t) = t - (t + LocalTZA + DaylightSavingTA(t))
+	 *                     = -(LocalTZA + DaylightSavingTA(t))
+	 *
+	 *  where DaylightSavingTA() is checked for time 't'.
+	 *
+	 *  Note that the sign of the result is opposite to common usage,
+	 *  e.g. for EE(S)T which normally is +2h or +3h from UTC, this
+	 *  function returns -120 or -180.
+	 *
+	 */
+
+	duk_double_t d;
+	duk_int_t tzoffset;
+
+	/* Note: DST adjustment is determined using UTC time. */
+	d = duk__push_this_get_timeval(ctx, 0 /*flags*/);
+	DUK_ASSERT(DUK_ISFINITE(d) || DUK_ISNAN(d));
+	if (DUK_ISNAN(d)) {
+		duk_push_nan(ctx);
+	} else {
+		DUK_ASSERT(DUK_ISFINITE(d));
+		tzoffset = DUK_USE_DATE_GET_LOCAL_TZOFFSET(d);
+		duk_push_int(ctx, -tzoffset / 60);
+	}
+	return 1;
+}
+
+/*
+ *  Setters.
+ *
+ *  Setters are a bit more complicated than getters.  Component setters
+ *  break down the current time value into its (normalized) component
+ *  parts, replace one or more components with -unnormalized- new values,
+ *  and the components are then converted back into a time value.  As an
+ *  example of using unnormalized values:
+ *
+ *    var d = new Date(1234567890);
+ *
+ *  is equivalent to:
+ *
+ *    var d = new Date(0);
+ *    d.setUTCMilliseconds(1234567890);
+ *
+ *  A shared native helper to provide almost all setters.  Magic value
+ *  contains a set of flags and also packs the "maxnargs" argument.  The
+ *  helper provides:
+ *
+ *    setMilliseconds()
+ *    setUTCMilliseconds()
+ *    setSeconds()
+ *    setUTCSeconds()
+ *    setMinutes()
+ *    setUTCMinutes()
+ *    setHours()
+ *    setUTCHours()
+ *    setDate()
+ *    setUTCDate()
+ *    setMonth()
+ *    setUTCMonth()
+ *    setFullYear()
+ *    setUTCFullYear()
+ *    setYear()
+ *
+ *  Notes:
+ *
+ *    - Date.prototype.setYear() (Section B addition): special year check
+ *      is omitted.  NaN / Infinity will just flow through and ultimately
+ *      result in a NaN internal time value.
+ *
+ *    - Date.prototype.setYear() does not have optional arguments for
+ *      setting month and day-in-month (like setFullYear()), but we indicate
+ *      'maxnargs' to be 3 to get the year written to the correct component
+ *      index in duk__set_part_helper().  The function has nargs == 1, so only
+ *      the year will be set regardless of actual argument count.
+ */
+
+DUK_INTERNAL duk_ret_t duk_bi_date_prototype_set_shared(duk_context *ctx) {
+	duk_small_uint_t flags_and_maxnargs = duk__date_get_indirect_magic(ctx);
+	return duk__set_part_helper(ctx, flags_and_maxnargs);
+}
+
+DUK_INTERNAL duk_ret_t duk_bi_date_prototype_set_time(duk_context *ctx) {
+	duk_double_t d;
+
+	(void) duk__push_this_get_timeval(ctx, 0 /*flags*/); /* -> [ timeval this ] */
+	d = duk__timeclip(duk_to_number(ctx, 0));
+	duk_push_number(ctx, d);
+	duk_dup_top(ctx);
+	duk_put_prop_stridx(ctx, -3, DUK_STRIDX_INT_VALUE); /* -> [ timeval this timeval ] */
+
+	return 1;
+}

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_bi_date_unix.c
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_bi_date_unix.c b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_bi_date_unix.c
new file mode 100644
index 0000000..e1e7c42
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_bi_date_unix.c
@@ -0,0 +1,309 @@
+/*
+ *  Unix-like Date providers
+ *
+ *  Generally useful Unix / POSIX / ANSI Date providers.
+ */
+
+#include "duk_internal.h"
+
+/* The necessary #includes are in place in duk_config.h. */
+
+/* Buffer sizes for some UNIX calls.  Larger than strictly necessary
+ * to avoid Valgrind errors.
+ */
+#define DUK__STRPTIME_BUF_SIZE  64
+#define DUK__STRFTIME_BUF_SIZE  64
+
+#if defined(DUK_USE_DATE_NOW_GETTIMEOFDAY)
+/* Get current Ecmascript time (= UNIX/Posix time, but in milliseconds). */
+DUK_INTERNAL duk_double_t duk_bi_date_get_now_gettimeofday(duk_context *ctx) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	struct timeval tv;
+	duk_double_t d;
+
+	if (gettimeofday(&tv, NULL) != 0) {
+		DUK_ERROR_INTERNAL_DEFMSG(thr);
+	}
+
+	d = ((duk_double_t) tv.tv_sec) * 1000.0 +
+	    ((duk_double_t) (tv.tv_usec / 1000));
+	DUK_ASSERT(DUK_FLOOR(d) == d);  /* no fractions */
+
+	return d;
+}
+#endif  /* DUK_USE_DATE_NOW_GETTIMEOFDAY */
+
+#if defined(DUK_USE_DATE_NOW_TIME)
+/* Not a very good provider: only full seconds are available. */
+DUK_INTERNAL duk_double_t duk_bi_date_get_now_time(duk_context *ctx) {
+	time_t t;
+
+	DUK_UNREF(ctx);
+	t = time(NULL);
+	return ((duk_double_t) t) * 1000.0;
+}
+#endif  /* DUK_USE_DATE_NOW_TIME */
+
+#if defined(DUK_USE_DATE_TZO_GMTIME) || defined(DUK_USE_DATE_TZO_GMTIME_R)
+/* Get local time offset (in seconds) for a certain (UTC) instant 'd'. */
+DUK_INTERNAL duk_int_t duk_bi_date_get_local_tzoffset_gmtime(duk_double_t d) {
+	time_t t, t1, t2;
+	duk_int_t parts[DUK_DATE_IDX_NUM_PARTS];
+	duk_double_t dparts[DUK_DATE_IDX_NUM_PARTS];
+	struct tm tms[2];
+#ifdef DUK_USE_DATE_TZO_GMTIME
+	struct tm *tm_ptr;
+#endif
+
+	/* For NaN/inf, the return value doesn't matter. */
+	if (!DUK_ISFINITE(d)) {
+		return 0;
+	}
+
+	/* If not within Ecmascript range, some integer time calculations
+	 * won't work correctly (and some asserts will fail), so bail out
+	 * if so.  This fixes test-bug-date-insane-setyear.js.  There is
+	 * a +/- 24h leeway in this range check to avoid a test262 corner
+	 * case documented in test-bug-date-timeval-edges.js.
+	 */
+	if (!duk_bi_date_timeval_in_leeway_range(d)) {
+		DUK_DD(DUK_DDPRINT("timeval not within valid range, skip tzoffset computation to avoid integer overflows"));
+		return 0;
+	}
+
+	/*
+	 *  This is a bit tricky to implement portably.  The result depends
+	 *  on the timestamp (specifically, DST depends on the timestamp).
+	 *  If e.g. UNIX APIs are used, they'll have portability issues with
+	 *  very small and very large years.
+	 *
+	 *  Current approach:
+	 *
+	 *  - Stay within portable UNIX limits by using equivalent year mapping.
+	 *    Avoid year 1970 and 2038 as some conversions start to fail, at
+	 *    least on some platforms.  Avoiding 1970 means that there are
+	 *    currently DST discrepancies for 1970.
+	 *
+	 *  - Create a UTC and local time breakdowns from 't'.  Then create
+	 *    a time_t using gmtime() and localtime() and compute the time
+	 *    difference between the two.
+	 *
+	 *  Equivalent year mapping (E5 Section 15.9.1.8):
+	 *
+	 *    If the host environment provides functionality for determining
+	 *    daylight saving time, the implementation of ECMAScript is free
+	 *    to map the year in question to an equivalent year (same
+	 *    leap-year-ness and same starting week day for the year) for which
+	 *    the host environment provides daylight saving time information.
+	 *    The only restriction is that all equivalent years should produce
+	 *    the same result.
+	 *
+	 *  This approach is quite reasonable but not entirely correct, e.g.
+	 *  the specification also states (E5 Section 15.9.1.8):
+	 *
+	 *    The implementation of ECMAScript should not try to determine
+	 *    whether the exact time was subject to daylight saving time, but
+	 *    just whether daylight saving time would have been in effect if
+	 *    the _current daylight saving time algorithm_ had been used at the
+	 *    time.  This avoids complications such as taking into account the
+	 *    years that the locale observed daylight saving time year round.
+	 *
+	 *  Since we rely on the platform APIs for conversions between local
+	 *  time and UTC, we can't guarantee the above.  Rather, if the platform
+	 *  has historical DST rules they will be applied.  This seems to be the
+	 *  general preferred direction in Ecmascript standardization (or at least
+	 *  implementations) anyway, and even the equivalent year mapping should
+	 *  be disabled if the platform is known to handle DST properly for the
+	 *  full Ecmascript range.
+	 *
+	 *  The following has useful discussion and links:
+	 *
+	 *    https://bugzilla.mozilla.org/show_bug.cgi?id=351066
+	 */
+
+	duk_bi_date_timeval_to_parts(d, parts, dparts, DUK_DATE_FLAG_EQUIVYEAR /*flags*/);
+	DUK_ASSERT(parts[DUK_DATE_IDX_YEAR] >= 1970 && parts[DUK_DATE_IDX_YEAR] <= 2038);
+
+	d = duk_bi_date_get_timeval_from_dparts(dparts, 0 /*flags*/);
+	DUK_ASSERT(d >= 0 && d < 2147483648.0 * 1000.0);  /* unsigned 31-bit range */
+	t = (time_t) (d / 1000.0);
+	DUK_DDD(DUK_DDDPRINT("timeval: %lf -> time_t %ld", (double) d, (long) t));
+
+	DUK_MEMZERO((void *) tms, sizeof(struct tm) * 2);
+
+#if defined(DUK_USE_DATE_TZO_GMTIME_R)
+	(void) gmtime_r(&t, &tms[0]);
+	(void) localtime_r(&t, &tms[1]);
+#elif defined(DUK_USE_DATE_TZO_GMTIME)
+	tm_ptr = gmtime(&t);
+	DUK_MEMCPY((void *) &tms[0], tm_ptr, sizeof(struct tm));
+	tm_ptr = localtime(&t);
+	DUK_MEMCPY((void *) &tms[1], tm_ptr, sizeof(struct tm));
+#else
+#error internal error
+#endif
+	DUK_DDD(DUK_DDDPRINT("gmtime result: tm={sec:%ld,min:%ld,hour:%ld,mday:%ld,mon:%ld,year:%ld,"
+	                     "wday:%ld,yday:%ld,isdst:%ld}",
+	                     (long) tms[0].tm_sec, (long) tms[0].tm_min, (long) tms[0].tm_hour,
+	                     (long) tms[0].tm_mday, (long) tms[0].tm_mon, (long) tms[0].tm_year,
+	                     (long) tms[0].tm_wday, (long) tms[0].tm_yday, (long) tms[0].tm_isdst));
+	DUK_DDD(DUK_DDDPRINT("localtime result: tm={sec:%ld,min:%ld,hour:%ld,mday:%ld,mon:%ld,year:%ld,"
+	                     "wday:%ld,yday:%ld,isdst:%ld}",
+	                     (long) tms[1].tm_sec, (long) tms[1].tm_min, (long) tms[1].tm_hour,
+	                     (long) tms[1].tm_mday, (long) tms[1].tm_mon, (long) tms[1].tm_year,
+	                     (long) tms[1].tm_wday, (long) tms[1].tm_yday, (long) tms[1].tm_isdst));
+
+	/* tm_isdst is both an input and an output to mktime(), use 0 to
+	 * avoid DST handling in mktime():
+	 * - https://github.com/svaarala/duktape/issues/406
+	 * - http://stackoverflow.com/questions/8558919/mktime-and-tm-isdst
+	 */
+	tms[0].tm_isdst = 0;
+	tms[1].tm_isdst = 0;
+	t1 = mktime(&tms[0]);  /* UTC */
+	t2 = mktime(&tms[1]);  /* local */
+	if (t1 == (time_t) -1 || t2 == (time_t) -1) {
+		/* This check used to be for (t < 0) but on some platforms
+		 * time_t is unsigned and apparently the proper way to detect
+		 * an mktime() error return is the cast above.  See e.g.:
+		 * http://pubs.opengroup.org/onlinepubs/009695299/functions/mktime.html
+		 */
+		goto error;
+	}
+	DUK_DDD(DUK_DDDPRINT("t1=%ld (utc), t2=%ld (local)", (long) t1, (long) t2));
+
+	/* Compute final offset in seconds, positive if local time ahead of
+	 * UTC (returned value is UTC-to-local offset).
+	 *
+	 * difftime() returns a double, so coercion to int generates quite
+	 * a lot of code.  Direct subtraction is not portable, however.
+	 * XXX: allow direct subtraction on known platforms.
+	 */
+#if 0
+	return (duk_int_t) (t2 - t1);
+#endif
+	return (duk_int_t) difftime(t2, t1);
+
+ error:
+	/* XXX: return something more useful, so that caller can throw? */
+	DUK_D(DUK_DPRINT("mktime() failed, d=%lf", (double) d));
+	return 0;
+}
+#endif  /* DUK_USE_DATE_TZO_GMTIME */
+
+#if defined(DUK_USE_DATE_PRS_STRPTIME)
+DUK_INTERNAL duk_bool_t duk_bi_date_parse_string_strptime(duk_context *ctx, const char *str) {
+	struct tm tm;
+	time_t t;
+	char buf[DUK__STRPTIME_BUF_SIZE];
+
+	/* copy to buffer with spare to avoid Valgrind gripes from strptime */
+	DUK_ASSERT(str != NULL);
+	DUK_MEMZERO(buf, sizeof(buf));  /* valgrind whine without this */
+	DUK_SNPRINTF(buf, sizeof(buf), "%s", (const char *) str);
+	buf[sizeof(buf) - 1] = (char) 0;
+
+	DUK_DDD(DUK_DDDPRINT("parsing: '%s'", (const char *) buf));
+
+	DUK_MEMZERO(&tm, sizeof(tm));
+	if (strptime((const char *) buf, "%c", &tm) != NULL) {
+		DUK_DDD(DUK_DDDPRINT("before mktime: tm={sec:%ld,min:%ld,hour:%ld,mday:%ld,mon:%ld,year:%ld,"
+		                     "wday:%ld,yday:%ld,isdst:%ld}",
+		                     (long) tm.tm_sec, (long) tm.tm_min, (long) tm.tm_hour,
+		                     (long) tm.tm_mday, (long) tm.tm_mon, (long) tm.tm_year,
+		                     (long) tm.tm_wday, (long) tm.tm_yday, (long) tm.tm_isdst));
+		tm.tm_isdst = -1;  /* negative: dst info not available */
+
+		t = mktime(&tm);
+		DUK_DDD(DUK_DDDPRINT("mktime() -> %ld", (long) t));
+		if (t >= 0) {
+			duk_push_number(ctx, ((duk_double_t) t) * 1000.0);
+			return 1;
+		}
+	}
+
+	return 0;
+}
+#endif  /* DUK_USE_DATE_PRS_STRPTIME */
+
+#if defined(DUK_USE_DATE_PRS_GETDATE)
+DUK_INTERNAL duk_bool_t duk_bi_date_parse_string_getdate(duk_context *ctx, const char *str) {
+	struct tm tm;
+	duk_small_int_t rc;
+	time_t t;
+
+	/* For this to work, DATEMSK must be set, so this is not very
+	 * convenient for an embeddable interpreter.
+	 */
+
+	DUK_MEMZERO(&tm, sizeof(struct tm));
+	rc = (duk_small_int_t) getdate_r(str, &tm);
+	DUK_DDD(DUK_DDDPRINT("getdate_r() -> %ld", (long) rc));
+
+	if (rc == 0) {
+		t = mktime(&tm);
+		DUK_DDD(DUK_DDDPRINT("mktime() -> %ld", (long) t));
+		if (t >= 0) {
+			duk_push_number(ctx, (duk_double_t) t);
+			return 1;
+		}
+	}
+
+	return 0;
+}
+#endif  /* DUK_USE_DATE_PRS_GETDATE */
+
+#if defined(DUK_USE_DATE_FMT_STRFTIME)
+DUK_INTERNAL duk_bool_t duk_bi_date_format_parts_strftime(duk_context *ctx, duk_int_t *parts, duk_int_t tzoffset, duk_small_uint_t flags) {
+	char buf[DUK__STRFTIME_BUF_SIZE];
+	struct tm tm;
+	const char *fmt;
+
+	DUK_UNREF(tzoffset);
+
+	/* If the platform doesn't support the entire Ecmascript range, we need
+	 * to return 0 so that the caller can fall back to the default formatter.
+	 *
+	 * For now, assume that if time_t is 8 bytes or more, the whole Ecmascript
+	 * range is supported.  For smaller time_t values (4 bytes in practice),
+	 * assumes that the signed 32-bit range is supported.
+	 *
+	 * XXX: detect this more correctly per platform.  The size of time_t is
+	 * probably not an accurate guarantee of strftime() supporting or not
+	 * supporting a large time range (the full Ecmascript range).
+	 */
+	if (sizeof(time_t) < 8 &&
+	   (parts[DUK_DATE_IDX_YEAR] < 1970 || parts[DUK_DATE_IDX_YEAR] > 2037)) {
+		/* be paranoid for 32-bit time values (even avoiding negative ones) */
+		return 0;
+	}
+
+	DUK_MEMZERO(&tm, sizeof(tm));
+	tm.tm_sec = parts[DUK_DATE_IDX_SECOND];
+	tm.tm_min = parts[DUK_DATE_IDX_MINUTE];
+	tm.tm_hour = parts[DUK_DATE_IDX_HOUR];
+	tm.tm_mday = parts[DUK_DATE_IDX_DAY];       /* already one-based */
+	tm.tm_mon = parts[DUK_DATE_IDX_MONTH] - 1;  /* one-based -> zero-based */
+	tm.tm_year = parts[DUK_DATE_IDX_YEAR] - 1900;
+	tm.tm_wday = parts[DUK_DATE_IDX_WEEKDAY];
+	tm.tm_isdst = 0;
+
+	DUK_MEMZERO(buf, sizeof(buf));
+	if ((flags & DUK_DATE_FLAG_TOSTRING_DATE) && (flags & DUK_DATE_FLAG_TOSTRING_TIME)) {
+		fmt = "%c";
+	} else if (flags & DUK_DATE_FLAG_TOSTRING_DATE) {
+		fmt = "%x";
+	} else {
+		DUK_ASSERT(flags & DUK_DATE_FLAG_TOSTRING_TIME);
+		fmt = "%X";
+	}
+	(void) strftime(buf, sizeof(buf) - 1, fmt, &tm);
+	DUK_ASSERT(buf[sizeof(buf) - 1] == 0);
+
+	duk_push_string(ctx, buf);
+	return 1;
+}
+#endif  /* DUK_USE_DATE_FMT_STRFTIME */
+
+#undef DUK__STRPTIME_BUF_SIZE
+#undef DUK__STRFTIME_BUF_SIZE

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_bi_date_windows.c
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_bi_date_windows.c b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_bi_date_windows.c
new file mode 100644
index 0000000..c131d22
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_bi_date_windows.c
@@ -0,0 +1,98 @@
+/*
+ *  Windows Date providers
+ *
+ *  Platform specific links:
+ *
+ *    - http://msdn.microsoft.com/en-us/library/windows/desktop/ms725473(v=vs.85).aspx
+ */
+
+#include "duk_internal.h"
+
+/* The necessary #includes are in place in duk_config.h. */
+
+#if defined(DUK_USE_DATE_NOW_WINDOWS) || defined(DUK_USE_DATE_TZO_WINDOWS)
+/* Shared Windows helpers. */
+DUK_LOCAL void duk__convert_systime_to_ularge(const SYSTEMTIME *st, ULARGE_INTEGER *res) {
+	FILETIME ft;
+	if (SystemTimeToFileTime(st, &ft) == 0) {
+		DUK_D(DUK_DPRINT("SystemTimeToFileTime() failed, returning 0"));
+		res->QuadPart = 0;
+	} else {
+		res->LowPart = ft.dwLowDateTime;
+		res->HighPart = ft.dwHighDateTime;
+	}
+}
+DUK_LOCAL void duk__set_systime_jan1970(SYSTEMTIME *st) {
+	DUK_MEMZERO((void *) st, sizeof(*st));
+	st->wYear = 1970;
+	st->wMonth = 1;
+	st->wDayOfWeek = 4;  /* not sure whether or not needed; Thursday */
+	st->wDay = 1;
+	DUK_ASSERT(st->wHour == 0);
+	DUK_ASSERT(st->wMinute == 0);
+	DUK_ASSERT(st->wSecond == 0);
+	DUK_ASSERT(st->wMilliseconds == 0);
+}
+#endif  /* defined(DUK_USE_DATE_NOW_WINDOWS) || defined(DUK_USE_DATE_TZO_WINDOWS) */
+
+#ifdef DUK_USE_DATE_NOW_WINDOWS
+DUK_INTERNAL duk_double_t duk_bi_date_get_now_windows(duk_context *ctx) {
+	/* Suggested step-by-step method from documentation of RtlTimeToSecondsSince1970:
+	 * http://msdn.microsoft.com/en-us/library/windows/desktop/ms724928(v=vs.85).aspx
+	 */
+	SYSTEMTIME st1, st2;
+	ULARGE_INTEGER tmp1, tmp2;
+
+	DUK_UNREF(ctx);
+
+	GetSystemTime(&st1);
+	duk__convert_systime_to_ularge((const SYSTEMTIME *) &st1, &tmp1);
+
+	duk__set_systime_jan1970(&st2);
+	duk__convert_systime_to_ularge((const SYSTEMTIME *) &st2, &tmp2);
+
+	/* Difference is in 100ns units, convert to milliseconds w/o fractions */
+	return (duk_double_t) ((tmp1.QuadPart - tmp2.QuadPart) / 10000LL);
+}
+#endif  /* DUK_USE_DATE_NOW_WINDOWS */
+
+
+#if defined(DUK_USE_DATE_TZO_WINDOWS)
+DUK_INTERNAL_DECL duk_int_t duk_bi_date_get_local_tzoffset_windows(duk_double_t d) {
+	SYSTEMTIME st1;
+	SYSTEMTIME st2;
+	SYSTEMTIME st3;
+	ULARGE_INTEGER tmp1;
+	ULARGE_INTEGER tmp2;
+	ULARGE_INTEGER tmp3;
+	FILETIME ft1;
+
+	/* XXX: handling of timestamps outside Windows supported range.
+	 * How does Windows deal with dates before 1600?  Does windows
+	 * support all Ecmascript years (like -200000 and +200000)?
+	 * Should equivalent year mapping be used here too?  If so, use
+	 * a shared helper (currently integrated into timeval-to-parts).
+	 */
+
+	/* Use the approach described in "Remarks" of FileTimeToLocalFileTime:
+	 * http://msdn.microsoft.com/en-us/library/windows/desktop/ms724277(v=vs.85).aspx
+	 */
+
+	duk__set_systime_jan1970(&st1);
+	duk__convert_systime_to_ularge((const SYSTEMTIME *) &st1, &tmp1);
+	tmp2.QuadPart = (ULONGLONG) (d * 10000.0);  /* millisec -> 100ns units since jan 1, 1970 */
+	tmp2.QuadPart += tmp1.QuadPart;             /* input 'd' in Windows UTC, 100ns units */
+
+	ft1.dwLowDateTime = tmp2.LowPart;
+	ft1.dwHighDateTime = tmp2.HighPart;
+	FileTimeToSystemTime((const FILETIME *) &ft1, &st2);
+	if (SystemTimeToTzSpecificLocalTime((LPTIME_ZONE_INFORMATION) NULL, &st2, &st3) == 0) {
+		DUK_D(DUK_DPRINT("SystemTimeToTzSpecificLocalTime() failed, return tzoffset 0"));
+		return 0;
+	}
+	duk__convert_systime_to_ularge((const SYSTEMTIME *) &st3, &tmp3);
+
+	/* Positive if local time ahead of UTC. */
+	return (duk_int_t) (((LONGLONG) tmp3.QuadPart - (LONGLONG) tmp2.QuadPart) / 10000000LL);  /* seconds */
+}
+#endif  /* DUK_USE_DATE_TZO_WINDOWS */

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_bi_duktape.c
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_bi_duktape.c b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_bi_duktape.c
new file mode 100644
index 0000000..79d6919
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_bi_duktape.c
@@ -0,0 +1,321 @@
+/*
+ *  Duktape built-ins
+ *
+ *  Size optimization note: it might seem that vararg multipurpose functions
+ *  like fin(), enc(), and dec() are not very size optimal, but using a single
+ *  user-visible Ecmascript function saves a lot of run-time footprint; each
+ *  Function instance takes >100 bytes.  Using a shared native helper and a
+ *  'magic' value won't save much if there are multiple Function instances
+ *  anyway.
+ */
+
+#include "duk_internal.h"
+
+/* Raw helper to extract internal information / statistics about a value.
+ * The return values are version specific and must not expose anything
+ * that would lead to security issues (e.g. exposing compiled function
+ * 'data' buffer might be an issue).  Currently only counts and sizes and
+ * such are given so there should not be a security impact.
+ */
+DUK_INTERNAL duk_ret_t duk_bi_duktape_object_info(duk_context *ctx) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_tval *tv;
+	duk_heaphdr *h;
+	duk_int_t i, n;
+
+	DUK_UNREF(thr);
+
+	/* result array */
+	duk_push_array(ctx);  /* -> [ val arr ] */
+
+	/* type tag (public) */
+	duk_push_int(ctx, duk_get_type(ctx, 0));
+
+	/* address */
+	tv = duk_get_tval(ctx, 0);
+	DUK_ASSERT(tv != NULL);  /* because arg count is 1 */
+	if (DUK_TVAL_IS_HEAP_ALLOCATED(tv)) {
+		h = DUK_TVAL_GET_HEAPHDR(tv);
+		duk_push_pointer(ctx, (void *) h);
+	} else {
+		/* internal type tag */
+		duk_push_int(ctx, (duk_int_t) DUK_TVAL_GET_TAG(tv));
+		goto done;
+	}
+	DUK_ASSERT(h != NULL);
+
+	/* refcount */
+#ifdef DUK_USE_REFERENCE_COUNTING
+	duk_push_size_t(ctx, DUK_HEAPHDR_GET_REFCOUNT(h));
+#else
+	duk_push_undefined(ctx);
+#endif
+
+	/* heaphdr size and additional allocation size, followed by
+	 * type specific stuff (with varying value count)
+	 */
+	switch ((duk_small_int_t) DUK_HEAPHDR_GET_TYPE(h)) {
+	case DUK_HTYPE_STRING: {
+		duk_hstring *h_str = (duk_hstring *) h;
+		duk_push_uint(ctx, (duk_uint_t) (sizeof(duk_hstring) + DUK_HSTRING_GET_BYTELEN(h_str) + 1));
+		break;
+	}
+	case DUK_HTYPE_OBJECT: {
+		duk_hobject *h_obj = (duk_hobject *) h;
+		duk_small_uint_t hdr_size;
+		if (DUK_HOBJECT_IS_COMPILEDFUNCTION(h_obj)) {
+			hdr_size = (duk_small_uint_t) sizeof(duk_hcompiledfunction);
+		} else if (DUK_HOBJECT_IS_NATIVEFUNCTION(h_obj)) {
+			hdr_size = (duk_small_uint_t) sizeof(duk_hnativefunction);
+		} else if (DUK_HOBJECT_IS_THREAD(h_obj)) {
+			hdr_size = (duk_small_uint_t) sizeof(duk_hthread);
+#if defined(DUK_USE_BUFFEROBJECT_SUPPORT)
+		} else if (DUK_HOBJECT_IS_BUFFEROBJECT(h_obj)) {
+			hdr_size = (duk_small_uint_t) sizeof(duk_hbufferobject);
+#endif
+		} else {
+			hdr_size = (duk_small_uint_t) sizeof(duk_hobject);
+		}
+		duk_push_uint(ctx, (duk_uint_t) hdr_size);
+		duk_push_uint(ctx, (duk_uint_t) DUK_HOBJECT_P_ALLOC_SIZE(h_obj));
+		duk_push_uint(ctx, (duk_uint_t) DUK_HOBJECT_GET_ESIZE(h_obj));
+		/* Note: e_next indicates the number of gc-reachable entries
+		 * in the entry part, and also indicates the index where the
+		 * next new property would be inserted.  It does *not* indicate
+		 * the number of non-NULL keys present in the object.  That
+		 * value could be counted separately but requires a pass through
+		 * the key list.
+		 */
+		duk_push_uint(ctx, (duk_uint_t) DUK_HOBJECT_GET_ENEXT(h_obj));
+		duk_push_uint(ctx, (duk_uint_t) DUK_HOBJECT_GET_ASIZE(h_obj));
+		duk_push_uint(ctx, (duk_uint_t) DUK_HOBJECT_GET_HSIZE(h_obj));
+		if (DUK_HOBJECT_IS_COMPILEDFUNCTION(h_obj)) {
+			duk_hbuffer *h_data = (duk_hbuffer *) DUK_HCOMPILEDFUNCTION_GET_DATA(thr->heap, (duk_hcompiledfunction *) h_obj);
+			if (h_data) {
+				duk_push_uint(ctx, (duk_uint_t) DUK_HBUFFER_GET_SIZE(h_data));
+			} else {
+				duk_push_uint(ctx, 0);
+			}
+		}
+		break;
+	}
+	case DUK_HTYPE_BUFFER: {
+		duk_hbuffer *h_buf = (duk_hbuffer *) h;
+		if (DUK_HBUFFER_HAS_DYNAMIC(h_buf)) {
+			if (DUK_HBUFFER_HAS_EXTERNAL(h_buf)) {
+				duk_push_uint(ctx, (duk_uint_t) (sizeof(duk_hbuffer_external)));
+			} else {
+				/* When alloc_size == 0 the second allocation may not
+				 * actually exist.
+				 */
+				duk_push_uint(ctx, (duk_uint_t) (sizeof(duk_hbuffer_dynamic)));
+			}
+			duk_push_uint(ctx, (duk_uint_t) (DUK_HBUFFER_GET_SIZE(h_buf)));
+		} else {
+			duk_push_uint(ctx, (duk_uint_t) (sizeof(duk_hbuffer_fixed) + DUK_HBUFFER_GET_SIZE(h_buf) + 1));
+		}
+		break;
+
+	}
+	}
+
+ done:
+	/* set values into ret array */
+	/* XXX: primitive to make array from valstack slice */
+	n = duk_get_top(ctx);
+	for (i = 2; i < n; i++) {
+		duk_dup(ctx, i);
+		duk_put_prop_index(ctx, 1, i - 2);
+	}
+	duk_dup(ctx, 1);
+	return 1;
+}
+
+DUK_INTERNAL duk_ret_t duk_bi_duktape_object_act(duk_context *ctx) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_activation *act;
+	duk_uint_fast32_t pc;
+	duk_uint_fast32_t line;
+	duk_int_t level;
+
+	/* -1             = top callstack entry, callstack[callstack_top - 1]
+	 * -callstack_top = bottom callstack entry, callstack[0]
+	 */
+	level = duk_to_int(ctx, 0);
+	if (level >= 0 || -level > (duk_int_t) thr->callstack_top) {
+		return 0;
+	}
+	DUK_ASSERT(level >= -((duk_int_t) thr->callstack_top) && level <= -1);
+	act = thr->callstack + thr->callstack_top + level;
+
+	duk_push_object(ctx);
+
+	duk_push_tval(ctx, &act->tv_func);
+
+	/* Relevant PC is just before current one because PC is
+	 * post-incremented.  This should match what error augment
+	 * code does.
+	 */
+	pc = duk_hthread_get_act_prev_pc(thr, act);
+	duk_push_uint(ctx, (duk_uint_t) pc);
+
+#if defined(DUK_USE_PC2LINE)
+	line = duk_hobject_pc2line_query(ctx, -2, pc);
+#else
+	line = 0;
+#endif
+	duk_push_uint(ctx, (duk_uint_t) line);
+
+	/* Providing access to e.g. act->lex_env would be dangerous: these
+	 * internal structures must never be accessible to the application.
+	 * Duktape relies on them having consistent data, and this consistency
+	 * is only asserted for, not checked for.
+	 */
+
+	/* [ level obj func pc line ] */
+
+	/* XXX: version specific array format instead? */
+	duk_xdef_prop_stridx_wec(ctx, -4, DUK_STRIDX_LINE_NUMBER);
+	duk_xdef_prop_stridx_wec(ctx, -3, DUK_STRIDX_PC);
+	duk_xdef_prop_stridx_wec(ctx, -2, DUK_STRIDX_LC_FUNCTION);
+	return 1;
+}
+
+DUK_INTERNAL duk_ret_t duk_bi_duktape_object_gc(duk_context *ctx) {
+#ifdef DUK_USE_MARK_AND_SWEEP
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_small_uint_t flags;
+	duk_bool_t rc;
+
+	flags = (duk_small_uint_t) duk_get_uint(ctx, 0);
+	rc = duk_heap_mark_and_sweep(thr->heap, flags);
+
+	/* XXX: Not sure what the best return value would be in the API.
+	 * Return a boolean for now.  Note that rc == 0 is success (true).
+	 */
+	duk_push_boolean(ctx, !rc);
+	return 1;
+#else
+	DUK_UNREF(ctx);
+	return 0;
+#endif
+}
+
+DUK_INTERNAL duk_ret_t duk_bi_duktape_object_fin(duk_context *ctx) {
+	(void) duk_require_hobject(ctx, 0);
+	if (duk_get_top(ctx) >= 2) {
+		/* Set: currently a finalizer is disabled by setting it to
+		 * undefined; this does not remove the property at the moment.
+		 * The value could be type checked to be either a function
+		 * or something else; if something else, the property could
+		 * be deleted.
+		 */
+		duk_set_top(ctx, 2);
+		(void) duk_put_prop_stridx(ctx, 0, DUK_STRIDX_INT_FINALIZER);
+		return 0;
+	} else {
+		/* Get. */
+		DUK_ASSERT(duk_get_top(ctx) == 1);
+		duk_get_prop_stridx(ctx, 0, DUK_STRIDX_INT_FINALIZER);
+		return 1;
+	}
+}
+
+DUK_INTERNAL duk_ret_t duk_bi_duktape_object_enc(duk_context *ctx) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_hstring *h_str;
+
+	DUK_UNREF(thr);
+
+	/* Vararg function: must be careful to check/require arguments.
+	 * The JSON helpers accept invalid indices and treat them like
+	 * non-existent optional parameters.
+	 */
+
+	h_str = duk_require_hstring(ctx, 0);
+	duk_require_valid_index(ctx, 1);
+
+	if (h_str == DUK_HTHREAD_STRING_HEX(thr)) {
+		duk_set_top(ctx, 2);
+		duk_hex_encode(ctx, 1);
+		DUK_ASSERT_TOP(ctx, 2);
+	} else if (h_str == DUK_HTHREAD_STRING_BASE64(thr)) {
+		duk_set_top(ctx, 2);
+		duk_base64_encode(ctx, 1);
+		DUK_ASSERT_TOP(ctx, 2);
+#ifdef DUK_USE_JX
+	} else if (h_str == DUK_HTHREAD_STRING_JX(thr)) {
+		duk_bi_json_stringify_helper(ctx,
+		                             1 /*idx_value*/,
+		                             2 /*idx_replacer*/,
+		                             3 /*idx_space*/,
+		                             DUK_JSON_FLAG_EXT_CUSTOM |
+		                             DUK_JSON_FLAG_ASCII_ONLY |
+		                             DUK_JSON_FLAG_AVOID_KEY_QUOTES /*flags*/);
+#endif
+#ifdef DUK_USE_JC
+	} else if (h_str == DUK_HTHREAD_STRING_JC(thr)) {
+		duk_bi_json_stringify_helper(ctx,
+		                             1 /*idx_value*/,
+		                             2 /*idx_replacer*/,
+		                             3 /*idx_space*/,
+		                             DUK_JSON_FLAG_EXT_COMPATIBLE |
+		                             DUK_JSON_FLAG_ASCII_ONLY /*flags*/);
+#endif
+	} else {
+		return DUK_RET_TYPE_ERROR;
+	}
+	return 1;
+}
+
+DUK_INTERNAL duk_ret_t duk_bi_duktape_object_dec(duk_context *ctx) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_hstring *h_str;
+
+	DUK_UNREF(thr);
+
+	/* Vararg function: must be careful to check/require arguments.
+	 * The JSON helpers accept invalid indices and treat them like
+	 * non-existent optional parameters.
+	 */
+
+	h_str = duk_require_hstring(ctx, 0);
+	duk_require_valid_index(ctx, 1);
+
+	if (h_str == DUK_HTHREAD_STRING_HEX(thr)) {
+		duk_set_top(ctx, 2);
+		duk_hex_decode(ctx, 1);
+		DUK_ASSERT_TOP(ctx, 2);
+	} else if (h_str == DUK_HTHREAD_STRING_BASE64(thr)) {
+		duk_set_top(ctx, 2);
+		duk_base64_decode(ctx, 1);
+		DUK_ASSERT_TOP(ctx, 2);
+#ifdef DUK_USE_JX
+	} else if (h_str == DUK_HTHREAD_STRING_JX(thr)) {
+		duk_bi_json_parse_helper(ctx,
+		                         1 /*idx_value*/,
+		                         2 /*idx_replacer*/,
+		                         DUK_JSON_FLAG_EXT_CUSTOM /*flags*/);
+#endif
+#ifdef DUK_USE_JC
+	} else if (h_str == DUK_HTHREAD_STRING_JC(thr)) {
+		duk_bi_json_parse_helper(ctx,
+		                         1 /*idx_value*/,
+		                         2 /*idx_replacer*/,
+		                         DUK_JSON_FLAG_EXT_COMPATIBLE /*flags*/);
+#endif
+	} else {
+		return DUK_RET_TYPE_ERROR;
+	}
+	return 1;
+}
+
+/*
+ *  Compact an object
+ */
+
+DUK_INTERNAL duk_ret_t duk_bi_duktape_object_compact(duk_context *ctx) {
+	DUK_ASSERT_TOP(ctx, 1);
+	duk_compact(ctx, 0);
+	return 1;  /* return the argument object */
+}


[35/51] [partial] nifi-minifi-cpp git commit: MINIFI-183 Added civet 1.9.1 sources Added onScheduled hook Added initial two-way TLS-enabled ListenHTTP implementation

Posted by al...@apache.org.
http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/mod_duktape.inl
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/mod_duktape.inl b/thirdparty/civetweb-1.9.1/src/mod_duktape.inl
new file mode 100644
index 0000000..d4e53cd
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/mod_duktape.inl
@@ -0,0 +1,250 @@
+/* This file is part of the CivetWeb web server.
+ * See https://github.com/civetweb/civetweb/
+ * (C) 2015-2017 by the CivetWeb authors, MIT license.
+ */
+
+#include "duktape.h"
+
+/* TODO: the mg context should be added to duktape as well */
+/* Alternative: redefine a new, clean API from scratch (instead of using mg),
+ * or at least do not add problematic functions. */
+/* For evaluation purposes, currently only "send" is supported.
+ * All other ~50 functions will be added later. */
+
+/* Note: This is only experimental support, so the API may still change. */
+
+static const char *civetweb_conn_id = "\xFF"
+                                      "civetweb_conn";
+static const char *civetweb_ctx_id = "\xFF"
+                                     "civetweb_ctx";
+
+
+static void *
+mg_duk_mem_alloc(void *udata, duk_size_t size)
+{
+	return mg_malloc(size);
+}
+
+
+static void *
+mg_duk_mem_realloc(void *udata, void *ptr, duk_size_t newsize)
+{
+	return mg_realloc(ptr, newsize);
+}
+
+
+static void
+mg_duk_mem_free(void *udata, void *ptr)
+{
+	mg_free(ptr);
+}
+
+
+static void
+mg_duk_fatal_handler(duk_context *ctx, duk_errcode_t code, const char *msg)
+{
+	/* Script is called "protected" (duk_peval_file), so script errors should
+	 * never yield in a call to this function. Maybe calls prior to executing
+	 * the script could raise a fatal error. */
+	struct mg_connection *conn;
+
+	duk_push_global_stash(ctx);
+	duk_get_prop_string(ctx, -1, civetweb_conn_id);
+	conn = (struct mg_connection *)duk_to_pointer(ctx, -1);
+
+	mg_cry(conn, "%s", msg);
+}
+
+
+static duk_ret_t
+duk_itf_write(duk_context *ctx)
+{
+	struct mg_connection *conn;
+	duk_double_t ret;
+	duk_size_t len = 0;
+	const char *val = duk_require_lstring(ctx, -1, &len);
+
+	/*
+	    duk_push_global_stash(ctx);
+	    duk_get_prop_string(ctx, -1, civetweb_conn_id);
+	    conn = (struct mg_connection *)duk_to_pointer(ctx, -1);
+	*/
+	duk_push_current_function(ctx);
+	duk_get_prop_string(ctx, -1, civetweb_conn_id);
+	conn = (struct mg_connection *)duk_to_pointer(ctx, -1);
+
+	if (!conn) {
+		duk_error(ctx,
+		          DUK_ERR_INTERNAL_ERROR,
+		          "function not available without connection object");
+		/* probably never reached, but satisfies static code analysis */
+		return DUK_RET_INTERNAL_ERROR;
+	}
+
+	ret = mg_write(conn, val, len);
+
+	duk_push_number(ctx, ret);
+	return 1;
+}
+
+
+static duk_ret_t
+duk_itf_read(duk_context *ctx)
+{
+	struct mg_connection *conn;
+	char buf[1024];
+	int len;
+
+	duk_push_global_stash(ctx);
+	duk_get_prop_string(ctx, -1, civetweb_conn_id);
+	conn = (struct mg_connection *)duk_to_pointer(ctx, -1);
+
+	if (!conn) {
+		duk_error(ctx,
+		          DUK_ERR_INTERNAL_ERROR,
+		          "function not available without connection object");
+		/* probably never reached, but satisfies static code analysis */
+		return DUK_RET_INTERNAL_ERROR;
+	}
+
+	len = mg_read(conn, buf, sizeof(buf));
+
+	duk_push_lstring(ctx, buf, len);
+	return 1;
+}
+
+
+static duk_ret_t
+duk_itf_getoption(duk_context *ctx)
+{
+	struct mg_context *cv_ctx;
+	const char *ret;
+	duk_size_t len = 0;
+	const char *val = duk_require_lstring(ctx, -1, &len);
+
+	duk_push_current_function(ctx);
+	duk_get_prop_string(ctx, -1, civetweb_ctx_id);
+	cv_ctx = (struct mg_context *)duk_to_pointer(ctx, -1);
+
+	if (!cv_ctx) {
+		duk_error(ctx,
+		          DUK_ERR_INTERNAL_ERROR,
+		          "function not available without connection object");
+		/* probably never reached, but satisfies static code analysis */
+		return DUK_RET_INTERNAL_ERROR;
+	}
+
+	ret = mg_get_option(cv_ctx, val);
+	if (ret) {
+		duk_push_string(ctx, ret);
+	} else {
+		duk_push_null(ctx);
+	}
+
+	return 1;
+}
+
+
+static void
+mg_exec_duktape_script(struct mg_connection *conn, const char *script_name)
+{
+	int i;
+	duk_context *ctx = NULL;
+
+	conn->must_close = 1;
+
+	/* Create Duktape interpreter state */
+	ctx = duk_create_heap(mg_duk_mem_alloc,
+	                      mg_duk_mem_realloc,
+	                      mg_duk_mem_free,
+	                      NULL,
+	                      mg_duk_fatal_handler);
+	if (!ctx) {
+		mg_cry(conn, "Failed to create a Duktape heap.");
+		goto exec_duktape_finished;
+	}
+
+	/* Add "conn" object */
+	duk_push_global_object(ctx);
+	duk_push_object(ctx); /* create a new table/object ("conn") */
+
+	duk_push_c_function(ctx, duk_itf_write, 1 /* 1 = nargs */);
+	duk_push_pointer(ctx, (void *)conn);
+	duk_put_prop_string(ctx, -2, civetweb_conn_id);
+	duk_put_prop_string(ctx, -2, "write"); /* add function conn.write */
+
+	duk_push_c_function(ctx, duk_itf_read, 0 /* 0 = nargs */);
+	duk_push_pointer(ctx, (void *)conn);
+	duk_put_prop_string(ctx, -2, civetweb_conn_id);
+	duk_put_prop_string(ctx, -2, "read"); /* add function conn.read */
+
+	duk_push_string(ctx, conn->request_info.request_method);
+	duk_put_prop_string(ctx, -2, "request_method"); /* add string conn.r... */
+
+	duk_push_string(ctx, conn->request_info.request_uri);
+	duk_put_prop_string(ctx, -2, "request_uri");
+
+	duk_push_string(ctx, conn->request_info.local_uri);
+	duk_put_prop_string(ctx, -2, "uri");
+
+	duk_push_string(ctx, conn->request_info.http_version);
+	duk_put_prop_string(ctx, -2, "http_version");
+
+	duk_push_string(ctx, conn->request_info.query_string);
+	duk_put_prop_string(ctx, -2, "query_string");
+
+	duk_push_string(ctx, conn->request_info.remote_addr);
+	duk_put_prop_string(ctx, -2, "remote_addr");
+
+	duk_push_int(ctx, conn->request_info.remote_port);
+	duk_put_prop_string(ctx, -2, "remote_port");
+
+	duk_push_int(ctx, ntohs(conn->client.lsa.sin.sin_port));
+	duk_put_prop_string(ctx, -2, "server_port");
+
+	duk_push_object(ctx); /* subfolder "conn.http_headers" */
+	for (i = 0; i < conn->request_info.num_headers; i++) {
+		duk_push_string(ctx, conn->request_info.http_headers[i].value);
+		duk_put_prop_string(ctx, -2, conn->request_info.http_headers[i].name);
+	}
+	duk_put_prop_string(ctx, -2, "http_headers");
+
+	duk_put_prop_string(ctx, -2, "conn"); /* call the table "conn" */
+
+	/* Add "civetweb" object */
+	duk_push_global_object(ctx);
+	duk_push_object(ctx); /* create a new table/object ("conn") */
+
+	duk_push_string(ctx, CIVETWEB_VERSION);
+	duk_put_prop_string(ctx, -2, "version");
+
+	duk_push_string(ctx, script_name);
+	duk_put_prop_string(ctx, -2, "script_name");
+
+	if (conn->ctx != NULL) {
+		duk_push_c_function(ctx, duk_itf_getoption, 1 /* 1 = nargs */);
+		duk_push_pointer(ctx, (void *)(conn->ctx));
+		duk_put_prop_string(ctx, -2, civetweb_ctx_id);
+		duk_put_prop_string(ctx, -2, "getoption"); /* add function conn.write */
+
+		if (conn->ctx->systemName != NULL) {
+			duk_push_string(ctx, conn->ctx->systemName);
+			duk_put_prop_string(ctx, -2, "system");
+		}
+	}
+
+	duk_put_prop_string(ctx, -2, "civetweb"); /* call the table "civetweb" */
+
+	duk_push_global_stash(ctx);
+	duk_push_pointer(ctx, (void *)conn);
+	duk_put_prop_string(ctx, -2, civetweb_conn_id);
+
+	if (duk_peval_file(ctx, script_name) != 0) {
+		mg_cry(conn, "%s", duk_safe_to_string(ctx, -1));
+		goto exec_duktape_finished;
+	}
+	duk_pop(ctx); /* ignore result */
+
+exec_duktape_finished:
+	duk_destroy_heap(ctx);
+}

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/mod_lua.inl
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/mod_lua.inl b/thirdparty/civetweb-1.9.1/src/mod_lua.inl
new file mode 100644
index 0000000..58a67dc
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/mod_lua.inl
@@ -0,0 +1,2000 @@
+/* This file is part of the CivetWeb web server.
+ * See https://github.com/civetweb/civetweb/
+ */
+
+#include "civetweb_lua.h"
+#include "civetweb_private_lua.h"
+
+#ifdef _WIN32
+static void *
+mmap(void *addr, int64_t len, int prot, int flags, int fd, int offset)
+{
+	/* TODO (low): This is an incomplete implementation of mmap for windows.
+	 * Currently it is sufficient, but there are a lot of unused parameters.
+	 * Better use a function "mg_map" which only has the required parameters,
+	 * and implement it using mmap in Linux and CreateFileMapping in Windows.
+	 * Noone should expect a full mmap for Windows here.
+	 */
+	HANDLE fh = (HANDLE)_get_osfhandle(fd);
+	HANDLE mh = CreateFileMapping(fh, 0, PAGE_READONLY, 0, 0, 0);
+	void *p = MapViewOfFile(mh, FILE_MAP_READ, 0, 0, (size_t)len);
+	CloseHandle(mh);
+
+	/* unused parameters */
+	(void)addr;
+	(void)prot;
+	(void)flags;
+	(void)offset;
+
+	return p;
+}
+
+static void
+munmap(void *addr, int64_t length)
+{
+	/* unused parameters */
+	(void)length;
+
+	UnmapViewOfFile(addr);
+}
+
+#define MAP_FAILED (NULL)
+#define MAP_PRIVATE (0)
+#define PROT_READ (0)
+#else
+#include <sys/mman.h>
+#endif
+
+static const char *LUASOCKET = "luasocket";
+static const char lua_regkey_ctx = 1;
+static const char lua_regkey_connlist = 2;
+
+/* Forward declarations */
+static void handle_request(struct mg_connection *);
+static int handle_lsp_request(struct mg_connection *,
+                              const char *,
+                              struct mg_file *,
+                              struct lua_State *);
+
+static void
+reg_lstring(struct lua_State *L,
+            const char *name,
+            const void *buffer,
+            size_t buflen)
+{
+	if (name != NULL && buffer != NULL) {
+		lua_pushstring(L, name);
+		lua_pushlstring(L, (const char *)buffer, buflen);
+		lua_rawset(L, -3);
+	}
+}
+
+#define reg_string(L, name, val)                                               \
+	reg_lstring(L, name, val, val ? strlen(val) : 0)
+
+static void
+reg_int(struct lua_State *L, const char *name, int val)
+{
+	if (name != NULL) {
+		lua_pushstring(L, name);
+		lua_pushinteger(L, val);
+		lua_rawset(L, -3);
+	}
+}
+
+static void
+reg_boolean(struct lua_State *L, const char *name, int val)
+{
+	if (name != NULL) {
+		lua_pushstring(L, name);
+		lua_pushboolean(L, val != 0);
+		lua_rawset(L, -3);
+	}
+}
+
+static void
+reg_conn_function(struct lua_State *L,
+                  const char *name,
+                  lua_CFunction func,
+                  struct mg_connection *conn)
+{
+	if (name != NULL && func != NULL && conn != NULL) {
+		lua_pushstring(L, name);
+		lua_pushlightuserdata(L, conn);
+		lua_pushcclosure(L, func, 1);
+		lua_rawset(L, -3);
+	}
+}
+
+static void
+reg_function(struct lua_State *L, const char *name, lua_CFunction func)
+{
+	if (name != NULL && func != NULL) {
+		lua_pushstring(L, name);
+		lua_pushcclosure(L, func, 0);
+		lua_rawset(L, -3);
+	}
+}
+
+static void
+lua_cry(struct mg_connection *conn,
+        int err,
+        lua_State *L,
+        const char *lua_title,
+        const char *lua_operation)
+{
+	switch (err) {
+	case LUA_OK:
+	case LUA_YIELD:
+		break;
+	case LUA_ERRRUN:
+		mg_cry(conn,
+		       "%s: %s failed: runtime error: %s",
+		       lua_title,
+		       lua_operation,
+		       lua_tostring(L, -1));
+		break;
+	case LUA_ERRSYNTAX:
+		mg_cry(conn,
+		       "%s: %s failed: syntax error: %s",
+		       lua_title,
+		       lua_operation,
+		       lua_tostring(L, -1));
+		break;
+	case LUA_ERRMEM:
+		mg_cry(conn, "%s: %s failed: out of memory", lua_title, lua_operation);
+		break;
+	case LUA_ERRGCMM:
+		mg_cry(conn,
+		       "%s: %s failed: error during garbage collection",
+		       lua_title,
+		       lua_operation);
+		break;
+	case LUA_ERRERR:
+		mg_cry(conn,
+		       "%s: %s failed: error in error handling: %s",
+		       lua_title,
+		       lua_operation,
+		       lua_tostring(L, -1));
+		break;
+	default:
+		mg_cry(conn, "%s: %s failed: error %i", lua_title, lua_operation, err);
+		break;
+	}
+}
+
+static int
+lsp_sock_close(lua_State *L)
+{
+	int num_args = lua_gettop(L);
+	size_t s;
+	SOCKET *psock;
+
+	if ((num_args == 1) && lua_istable(L, -1)) {
+		lua_getfield(L, -1, "sock");
+		psock = (SOCKET *)lua_tolstring(L, -1, &s);
+		if (s != sizeof(SOCKET)) {
+			return luaL_error(L, "invalid internal state in :close() call");
+		}
+		/* Do not closesocket(*psock); here, close it in __gc */
+		(void)psock;
+	} else {
+		return luaL_error(L, "invalid :close() call");
+	}
+	return 0;
+}
+
+static int
+lsp_sock_recv(lua_State *L)
+{
+	int num_args = lua_gettop(L);
+	char buf[2000];
+	int n;
+	size_t s;
+	SOCKET *psock;
+
+	if ((num_args == 1) && lua_istable(L, -1)) {
+		lua_getfield(L, -1, "sock");
+		psock = (SOCKET *)lua_tolstring(L, -1, &s);
+		if (s != sizeof(SOCKET)) {
+			return luaL_error(L, "invalid internal state in :recv() call");
+		}
+		n = recv(*psock, buf, sizeof(buf), 0);
+		if (n <= 0) {
+			lua_pushnil(L);
+		} else {
+			lua_pushlstring(L, buf, n);
+		}
+	} else {
+		return luaL_error(L, "invalid :recv() call");
+	}
+	return 1;
+}
+
+static int
+lsp_sock_send(lua_State *L)
+{
+	int num_args = lua_gettop(L);
+	const char *buf;
+	size_t len, sent = 0;
+	int n = 0;
+	size_t s;
+	SOCKET *psock;
+
+	if ((num_args == 2) && lua_istable(L, -2) && lua_isstring(L, -1)) {
+		buf = lua_tolstring(L, -1, &len);
+		lua_getfield(L, -2, "sock");
+		psock = (SOCKET *)lua_tolstring(L, -1, &s);
+		if (s != sizeof(SOCKET)) {
+			return luaL_error(L, "invalid internal state in :close() call");
+		}
+
+		while (sent < len) {
+			if ((n = send(*psock, buf + sent, (int)(len - sent), 0)) <= 0) {
+				break;
+			}
+			sent += n;
+		}
+		lua_pushnumber(L, n);
+	} else {
+		return luaL_error(L, "invalid :close() call");
+	}
+	return 1;
+}
+
+static int
+lsp_sock_gc(lua_State *L)
+{
+	int num_args = lua_gettop(L);
+	size_t s;
+	SOCKET *psock;
+
+	if ((num_args == 1) && lua_istable(L, -1)) {
+		lua_getfield(L, -1, "sock");
+		psock = (SOCKET *)lua_tolstring(L, -1, &s);
+		if (s != sizeof(SOCKET)) {
+			return luaL_error(
+			    L,
+			    "invalid internal state in __gc for object created by connect");
+		}
+		closesocket(*psock);
+	} else {
+		return luaL_error(L, "__gc for object created by connect failed");
+	}
+	return 0;
+}
+
+/* Methods and meta-methods supported by the object returned by connect.
+ * For meta-methods, see http://lua-users.org/wiki/MetatableEvents */
+static const struct luaL_Reg luasocket_methods[] = {{"close", lsp_sock_close},
+                                                    {"send", lsp_sock_send},
+                                                    {"recv", lsp_sock_recv},
+                                                    {"__gc", lsp_sock_gc},
+                                                    {NULL, NULL}};
+
+static int
+lsp_connect(lua_State *L)
+{
+	int num_args = lua_gettop(L);
+	char ebuf[100];
+	SOCKET sock;
+	union usa sa;
+	int ok;
+
+	if ((num_args == 3) && lua_isstring(L, -3) && lua_isnumber(L, -2)
+	    && lua_isnumber(L, -1)) {
+		ok = connect_socket(NULL,
+		                    lua_tostring(L, -3),
+		                    (int)lua_tonumber(L, -2),
+		                    (int)lua_tonumber(L, -1),
+		                    ebuf,
+		                    sizeof(ebuf),
+		                    &sock,
+		                    &sa);
+		if (!ok) {
+			return luaL_error(L, ebuf);
+		} else {
+			lua_newtable(L);
+			reg_lstring(L, "sock", (const char *)&sock, sizeof(SOCKET));
+			reg_string(L, "host", lua_tostring(L, -4));
+			luaL_getmetatable(L, LUASOCKET);
+			lua_setmetatable(L, -2);
+		}
+	} else {
+		return luaL_error(
+		    L, "connect(host,port,is_ssl): invalid parameter given.");
+	}
+	return 1;
+}
+
+static int
+lsp_error(lua_State *L)
+{
+	lua_getglobal(L, "mg");
+	lua_getfield(L, -1, "onerror");
+	lua_pushvalue(L, -3);
+	lua_pcall(L, 1, 0, 0);
+	return 0;
+}
+
+/* Silently stop processing chunks. */
+static void
+lsp_abort(lua_State *L)
+{
+	int top = lua_gettop(L);
+	lua_getglobal(L, "mg");
+	lua_pushnil(L);
+	lua_setfield(L, -2, "onerror");
+	lua_settop(L, top);
+	lua_pushstring(L, "aborting");
+	lua_error(L);
+}
+
+struct lsp_var_reader_data {
+	const char *begin;
+	unsigned len;
+	unsigned state;
+};
+
+
+static const char *
+lsp_var_reader(lua_State *L, void *ud, size_t *sz)
+{
+	struct lsp_var_reader_data *reader = (struct lsp_var_reader_data *)ud;
+	const char *ret;
+	(void)(L); /* unused */
+
+	switch (reader->state) {
+	case 0:
+		ret = "mg.write(";
+		*sz = strlen(ret);
+		break;
+	case 1:
+		ret = reader->begin;
+		*sz = reader->len;
+		break;
+	case 2:
+		ret = ")";
+		*sz = strlen(ret);
+		break;
+	default:
+		ret = 0;
+		*sz = 0;
+	}
+
+	reader->state++;
+	return ret;
+}
+
+
+static int
+lsp(struct mg_connection *conn,
+    const char *path,
+    const char *p,
+    int64_t len,
+    lua_State *L)
+{
+	int i, j, pos = 0, lines = 1, lualines = 0, is_var, lua_ok;
+	char chunkname[MG_BUF_LEN];
+	struct lsp_var_reader_data data;
+
+	for (i = 0; i < len; i++) {
+		if (p[i] == '\n')
+			lines++;
+		if (((i + 1) < len) && (p[i] == '<') && (p[i + 1] == '?')) {
+
+			/* <?= ?> means a variable is enclosed and its value should be
+			 * printed */
+			is_var = (((i + 2) < len) && (p[i + 2] == '='));
+
+			if (is_var)
+				j = i + 2;
+			else
+				j = i + 1;
+
+			while (j < len) {
+				if (p[j] == '\n')
+					lualines++;
+				if (((j + 1) < len) && (p[j] == '?') && (p[j + 1] == '>')) {
+					mg_write(conn, p + pos, i - pos);
+
+					mg_snprintf(conn,
+					            NULL, /* name only used for debugging */
+					            chunkname,
+					            sizeof(chunkname),
+					            "@%s+%i",
+					            path,
+					            lines);
+					lua_pushlightuserdata(L, conn);
+					lua_pushcclosure(L, lsp_error, 1);
+
+					if (is_var) {
+						data.begin = p + (i + 3);
+						data.len = j - (i + 3);
+						data.state = 0;
+						lua_ok = mg_lua_load(
+						    L, lsp_var_reader, &data, chunkname, NULL);
+					} else {
+						lua_ok = luaL_loadbuffer(L,
+						                         p + (i + 2),
+						                         j - (i + 2),
+						                         chunkname);
+					}
+
+					if (lua_ok) {
+						/* Syntax error or OOM. Error message is pushed on
+						 * stack. */
+						lua_pcall(L, 1, 0, 0);
+					} else {
+						/* Success loading chunk. Call it. */
+						lua_pcall(L, 0, 0, 1);
+					}
+
+					pos = j + 2;
+					i = pos - 1;
+					break;
+				}
+				j++;
+			}
+
+			if (lualines > 0) {
+				lines += lualines;
+				lualines = 0;
+			}
+		}
+	}
+
+	if (i > pos) {
+		mg_write(conn, p + pos, i - pos);
+	}
+
+	return 0;
+}
+
+
+/* mg.write: Send data to the client */
+static int
+lsp_write(lua_State *L)
+{
+	struct mg_connection *conn =
+	    (struct mg_connection *)lua_touserdata(L, lua_upvalueindex(1));
+	int num_args = lua_gettop(L);
+	const char *str;
+	size_t size;
+	int i;
+	int rv = 1;
+
+	for (i = 1; i <= num_args; i++) {
+		if (lua_isstring(L, i)) {
+			str = lua_tolstring(L, i, &size);
+			if (mg_write(conn, str, size) != (int)size) {
+				rv = 0;
+			}
+		}
+	}
+	lua_pushboolean(L, rv);
+
+	return 1;
+}
+
+
+/* mg.read: Read data from the client (e.g., from a POST request) */
+static int
+lsp_read(lua_State *L)
+{
+	struct mg_connection *conn =
+	    (struct mg_connection *)lua_touserdata(L, lua_upvalueindex(1));
+	char buf[1024];
+	int len = mg_read(conn, buf, sizeof(buf));
+
+	if (len <= 0)
+		return 0;
+	lua_pushlstring(L, buf, len);
+
+	return 1;
+}
+
+
+/* mg.keep_alive: Allow Lua pages to use the http keep-alive mechanism */
+static int
+lsp_keep_alive(lua_State *L)
+{
+	struct mg_connection *conn =
+	    (struct mg_connection *)lua_touserdata(L, lua_upvalueindex(1));
+	int num_args = lua_gettop(L);
+
+	/* This function may be called with one parameter (boolean) to set the
+	keep_alive state.
+	Or without a parameter to just query the current keep_alive state. */
+	if ((num_args == 1) && lua_isboolean(L, 1)) {
+		conn->must_close = !lua_toboolean(L, 1);
+	} else if (num_args != 0) {
+		/* Syntax error */
+		return luaL_error(L, "invalid keep_alive() call");
+	}
+
+	/* Return the current "keep_alive" state. This may be false, even it
+	 * keep_alive(true) has been called. */
+	lua_pushboolean(L, should_keep_alive(conn));
+	return 1;
+}
+
+
+/* mg.include: Include another .lp file */
+static int
+lsp_include(lua_State *L)
+{
+	struct mg_connection *conn =
+	    (struct mg_connection *)lua_touserdata(L, lua_upvalueindex(1));
+	int num_args = lua_gettop(L);
+	struct mg_file file = STRUCT_FILE_INITIALIZER;
+	const char *filename = (num_args == 1) ? lua_tostring(L, 1) : NULL;
+
+	if (filename) {
+		if (handle_lsp_request(conn, filename, &file, L)) {
+			/* handle_lsp_request returned an error code, meaning an error
+			occured in
+			the included page and mg.onerror returned non-zero. Stop processing.
+			*/
+			lsp_abort(L);
+		}
+	} else {
+		/* Syntax error */
+		return luaL_error(L, "invalid include() call");
+	}
+	return 0;
+}
+
+
+/* mg.cry: Log an error. Default value for mg.onerror. */
+static int
+lsp_cry(lua_State *L)
+{
+	struct mg_connection *conn =
+	    (struct mg_connection *)lua_touserdata(L, lua_upvalueindex(1));
+	int num_args = lua_gettop(L);
+	const char *text = (num_args == 1) ? lua_tostring(L, 1) : NULL;
+
+	if (text) {
+		mg_cry(conn, "%s", lua_tostring(L, -1));
+	} else {
+		/* Syntax error */
+		return luaL_error(L, "invalid cry() call");
+	}
+	return 0;
+}
+
+
+/* mg.redirect: Redirect the request (internally). */
+static int
+lsp_redirect(lua_State *L)
+{
+	struct mg_connection *conn =
+	    (struct mg_connection *)lua_touserdata(L, lua_upvalueindex(1));
+	int num_args = lua_gettop(L);
+	const char *target = (num_args == 1) ? lua_tostring(L, 1) : NULL;
+
+	if (target) {
+		conn->request_info.local_uri = target;
+		handle_request(conn);
+		lsp_abort(L);
+	} else {
+		/* Syntax error */
+		return luaL_error(L, "invalid redirect() call");
+	}
+	return 0;
+}
+
+
+/* mg.send_file */
+static int
+lsp_send_file(lua_State *L)
+{
+	struct mg_connection *conn =
+	    (struct mg_connection *)lua_touserdata(L, lua_upvalueindex(1));
+	int num_args = lua_gettop(L);
+	const char *filename = (num_args == 1) ? lua_tostring(L, 1) : NULL;
+
+	if (filename) {
+		mg_send_file(conn, filename);
+	} else {
+		/* Syntax error */
+		return luaL_error(L, "invalid send_file() call");
+	}
+	return 0;
+}
+
+
+/* mg.get_time */
+static int
+lsp_get_time(lua_State *L)
+{
+	int num_args = lua_gettop(L);
+	int monotonic = (num_args > 0) ? lua_toboolean(L, 1) : 0;
+	struct timespec ts;
+	double d;
+
+	clock_gettime(monotonic ? CLOCK_MONOTONIC : CLOCK_REALTIME, &ts);
+	d = (double)ts.tv_sec + ((double)ts.tv_nsec * 1.0E-9);
+	lua_pushnumber(L, d);
+	return 1;
+}
+
+
+/* mg.get_var */
+static int
+lsp_get_var(lua_State *L)
+{
+	int num_args = lua_gettop(L);
+	const char *data, *var_name;
+	size_t data_len, occurrence;
+	int ret;
+	char dst[512];
+
+	if (num_args >= 2 && num_args <= 3) {
+		data = lua_tolstring(L, 1, &data_len);
+		var_name = lua_tostring(L, 2);
+		occurrence = (num_args > 2) ? (long)lua_tonumber(L, 3) : 0;
+
+		ret =
+		    mg_get_var2(data, data_len, var_name, dst, sizeof(dst), occurrence);
+		if (ret >= 0) {
+			/* Variable found: return value to Lua */
+			lua_pushstring(L, dst);
+		} else {
+			/* Variable not found (TODO (mid): may be string too long) */
+			lua_pushnil(L);
+		}
+	} else {
+		/* Syntax error */
+		return luaL_error(L, "invalid get_var() call");
+	}
+	return 1;
+}
+
+
+/* mg.get_mime_type */
+static int
+lsp_get_mime_type(lua_State *L)
+{
+	int num_args = lua_gettop(L);
+	struct vec mime_type = {0, 0};
+	struct mg_context *ctx;
+	const char *text;
+
+	lua_pushlightuserdata(L, (void *)&lua_regkey_ctx);
+	lua_gettable(L, LUA_REGISTRYINDEX);
+	ctx = (struct mg_context *)lua_touserdata(L, -1);
+
+	if (num_args == 1) {
+		text = lua_tostring(L, 1);
+		if (text) {
+			if (ctx) {
+				get_mime_type(ctx, text, &mime_type);
+				lua_pushlstring(L, mime_type.ptr, mime_type.len);
+			} else {
+				text = mg_get_builtin_mime_type(text);
+				lua_pushstring(L, text);
+			}
+		} else {
+			/* Syntax error */
+			return luaL_error(L, "invalid argument for get_mime_type() call");
+		}
+	} else {
+		/* Syntax error */
+		return luaL_error(L, "invalid get_mime_type() call");
+	}
+	return 1;
+}
+
+
+/* mg.get_cookie */
+static int
+lsp_get_cookie(lua_State *L)
+{
+	int num_args = lua_gettop(L);
+	const char *cookie;
+	const char *var_name;
+	int ret;
+	char dst[512];
+
+	if (num_args == 2) {
+		cookie = lua_tostring(L, 1);
+		var_name = lua_tostring(L, 2);
+		if (cookie != NULL && var_name != NULL) {
+			ret = mg_get_cookie(cookie, var_name, dst, sizeof(dst));
+		} else {
+			ret = -1;
+		}
+
+		if (ret >= 0) {
+			lua_pushlstring(L, dst, ret);
+		} else {
+			lua_pushnil(L);
+		}
+	} else {
+		/* Syntax error */
+		return luaL_error(L, "invalid get_cookie() call");
+	}
+	return 1;
+}
+
+
+/* mg.md5 */
+static int
+lsp_md5(lua_State *L)
+{
+	int num_args = lua_gettop(L);
+	const char *text;
+	md5_byte_t hash[16];
+	md5_state_t ctx;
+	size_t text_len;
+	char buf[40];
+
+	if (num_args == 1) {
+		text = lua_tolstring(L, 1, &text_len);
+		if (text) {
+			md5_init(&ctx);
+			md5_append(&ctx, (const md5_byte_t *)text, text_len);
+			md5_finish(&ctx, hash);
+			bin2str(buf, hash, sizeof(hash));
+			lua_pushstring(L, buf);
+		} else {
+			lua_pushnil(L);
+		}
+	} else {
+		/* Syntax error */
+		return luaL_error(L, "invalid md5() call");
+	}
+	return 1;
+}
+
+
+/* mg.url_encode */
+static int
+lsp_url_encode(lua_State *L)
+{
+	int num_args = lua_gettop(L);
+	const char *text;
+	size_t text_len;
+	char dst[512 * 3];
+
+	if (num_args == 1) {
+		text = lua_tolstring(L, 1, &text_len);
+		if (text) {
+			mg_url_encode(text, dst, sizeof(dst));
+			lua_pushstring(L, dst);
+		} else {
+			lua_pushnil(L);
+		}
+	} else {
+		/* Syntax error */
+		return luaL_error(L, "invalid url_encode() call");
+	}
+	return 1;
+}
+
+
+/* mg.url_decode */
+static int
+lsp_url_decode(lua_State *L)
+{
+	int num_args = lua_gettop(L);
+	const char *text;
+	size_t text_len;
+	int is_form;
+	char dst[512];
+
+	if (num_args == 1 || (num_args == 2 && lua_isboolean(L, 2))) {
+		text = lua_tolstring(L, 1, &text_len);
+		is_form = (num_args == 2) ? lua_isboolean(L, 2) : 0;
+		if (text) {
+			mg_url_decode(text, (int)text_len, dst, (int)sizeof(dst), is_form);
+			lua_pushstring(L, dst);
+		} else {
+			lua_pushnil(L);
+		}
+	} else {
+		/* Syntax error */
+		return luaL_error(L, "invalid url_decode() call");
+	}
+	return 1;
+}
+
+
+/* mg.base64_encode */
+static int
+lsp_base64_encode(lua_State *L)
+{
+	int num_args = lua_gettop(L);
+	const char *text;
+	size_t text_len;
+	char *dst;
+
+	if (num_args == 1) {
+		text = lua_tolstring(L, 1, &text_len);
+		if (text) {
+			dst = (char *)mg_malloc(text_len * 8 / 6 + 4);
+			if (dst) {
+				base64_encode((const unsigned char *)text, (int)text_len, dst);
+				lua_pushstring(L, dst);
+				mg_free(dst);
+			} else {
+				return luaL_error(L, "out of memory in base64_encode() call");
+			}
+		} else {
+			lua_pushnil(L);
+		}
+	} else {
+		/* Syntax error */
+		return luaL_error(L, "invalid base64_encode() call");
+	}
+	return 1;
+}
+
+
+/* mg.base64_encode */
+static int
+lsp_base64_decode(lua_State *L)
+{
+	int num_args = lua_gettop(L);
+	const char *text;
+	size_t text_len, dst_len;
+	int ret;
+	char *dst;
+
+	if (num_args == 1) {
+		text = lua_tolstring(L, 1, &text_len);
+		if (text) {
+			dst = (char *)mg_malloc(text_len);
+			if (dst) {
+				ret = base64_decode((const unsigned char *)text,
+				                    (int)text_len,
+				                    dst,
+				                    &dst_len);
+				if (ret != -1) {
+					mg_free(dst);
+					return luaL_error(
+					    L, "illegal character in lsp_base64_decode() call");
+				} else {
+					lua_pushlstring(L, dst, dst_len);
+					mg_free(dst);
+				}
+			} else {
+				return luaL_error(L,
+				                  "out of memory in lsp_base64_decode() call");
+			}
+		} else {
+			lua_pushnil(L);
+		}
+	} else {
+		/* Syntax error */
+		return luaL_error(L, "invalid lsp_base64_decode() call");
+	}
+	return 1;
+}
+
+
+/* mg.get_response_code_text */
+static int
+lsp_get_response_code_text(lua_State *L)
+{
+	int num_args = lua_gettop(L);
+	int type1;
+	double code;
+	const char *text;
+
+	if (num_args == 1) {
+		type1 = lua_type(L, 1);
+		if (type1 == LUA_TNUMBER) {
+			/* If the first argument is a number,
+			   convert it to the corresponding text. */
+			code = lua_tonumber(L, 1);
+			text = mg_get_response_code_text(NULL, (int)code);
+			if (text)
+				lua_pushstring(L, text);
+			return text ? 1 : 0;
+		}
+	}
+
+	/* Syntax error */
+	return luaL_error(L, "invalid get_response_code_text() call");
+}
+
+
+/* mg.random - might be better than math.random on some systems */
+static int
+lsp_random(lua_State *L)
+{
+	int num_args = lua_gettop(L);
+	if (num_args == 0) {
+		/* The civetweb internal random number generator will generate
+		         * a 64 bit random number. */
+		uint64_t r = get_random();
+		/* Lua "number" is a IEEE 754 double precission float:
+ * https://en.wikipedia.org/wiki/Double-precision_floating-point_format
+		 * Thus, mask with 2^53-1 to get an integer with the maximum
+ * precission available. */
+		r &= ((((uint64_t)1) << 53) - 1);
+		lua_pushnumber(L, (double)r);
+		return 1;
+	}
+
+	/* Syntax error */
+	return luaL_error(L, "invalid random() call");
+}
+
+
+union {
+	void *p;
+	void (*f)(unsigned char uuid[16]);
+} pf_uuid_generate;
+
+
+/* mg.uuid */
+static int
+lsp_uuid(lua_State *L)
+{
+	union {
+		unsigned char uuid_array[16];
+		struct uuid_struct_type {
+			uint32_t data1;
+			uint16_t data2;
+			uint16_t data3;
+			uint8_t data4[8];
+		} uuid_struct;
+	} uuid;
+
+	char uuid_str[40];
+	int num_args = lua_gettop(L);
+
+	memset(&uuid, 0, sizeof(uuid));
+	memset(uuid_str, 0, sizeof(uuid_str));
+
+	if (num_args == 0) {
+
+		pf_uuid_generate.f(uuid.uuid_array);
+
+		sprintf(uuid_str,
+		        "{%08lX-%04X-%04X-%02X%02X-"
+		        "%02X%02X%02X%02X%02X%02X}",
+		        (unsigned long)uuid.uuid_struct.data1,
+		        (unsigned)uuid.uuid_struct.data2,
+		        (unsigned)uuid.uuid_struct.data3,
+		        (unsigned)uuid.uuid_struct.data4[0],
+		        (unsigned)uuid.uuid_struct.data4[1],
+		        (unsigned)uuid.uuid_struct.data4[2],
+		        (unsigned)uuid.uuid_struct.data4[3],
+		        (unsigned)uuid.uuid_struct.data4[4],
+		        (unsigned)uuid.uuid_struct.data4[5],
+		        (unsigned)uuid.uuid_struct.data4[6],
+		        (unsigned)uuid.uuid_struct.data4[7]);
+
+		lua_pushstring(L, uuid_str);
+		return 1;
+	}
+
+	/* Syntax error */
+	return luaL_error(L, "invalid random() call");
+}
+
+
+#ifdef USE_WEBSOCKET
+struct lua_websock_data {
+	lua_State *state;
+	char *script;
+	unsigned references;
+	struct mg_connection *conn[MAX_WORKER_THREADS];
+	pthread_mutex_t ws_mutex;
+};
+#endif
+
+
+/* mg.write for websockets */
+static int
+lwebsock_write(lua_State *L)
+{
+#ifdef USE_WEBSOCKET
+	int num_args = lua_gettop(L);
+	struct lua_websock_data *ws;
+	const char *str;
+	size_t size;
+	int opcode = -1;
+	unsigned i;
+	struct mg_connection *client = NULL;
+
+	lua_pushlightuserdata(L, (void *)&lua_regkey_connlist);
+	lua_gettable(L, LUA_REGISTRYINDEX);
+	ws = (struct lua_websock_data *)lua_touserdata(L, -1);
+
+	(void)pthread_mutex_lock(&(ws->ws_mutex));
+
+	if (num_args == 1) {
+		/* just one text: send it to all client */
+		if (lua_isstring(L, 1)) {
+			opcode = WEBSOCKET_OPCODE_TEXT;
+		}
+	} else if (num_args == 2) {
+		if (lua_isnumber(L, 1)) {
+			/* opcode number and message text */
+			opcode = (int)lua_tointeger(L, 1);
+		} else if (lua_isstring(L, 1)) {
+			/* opcode string and message text */
+			str = lua_tostring(L, 1);
+			if (!mg_strncasecmp(str, "text", 4))
+				opcode = WEBSOCKET_OPCODE_TEXT;
+			else if (!mg_strncasecmp(str, "bin", 3))
+				opcode = WEBSOCKET_OPCODE_BINARY;
+			else if (!mg_strncasecmp(str, "close", 5))
+				opcode = WEBSOCKET_OPCODE_CONNECTION_CLOSE;
+			else if (!mg_strncasecmp(str, "ping", 4))
+				opcode = WEBSOCKET_OPCODE_PING;
+			else if (!mg_strncasecmp(str, "pong", 4))
+				opcode = WEBSOCKET_OPCODE_PONG;
+			else if (!mg_strncasecmp(str, "cont", 4))
+				opcode = WEBSOCKET_OPCODE_CONTINUATION;
+		} else if (lua_isuserdata(L, 1)) {
+			/* client id and message text */
+			client = (struct mg_connection *)lua_touserdata(L, 1);
+			opcode = WEBSOCKET_OPCODE_TEXT;
+		}
+	} else if (num_args == 3) {
+		if (lua_isuserdata(L, 1)) {
+			client = (struct mg_connection *)lua_touserdata(L, 1);
+			if (lua_isnumber(L, 2)) {
+				/* client id, opcode number and message text */
+				opcode = (int)lua_tointeger(L, 2);
+			} else if (lua_isstring(L, 2)) {
+				/* client id, opcode string and message text */
+				str = lua_tostring(L, 2);
+				if (!mg_strncasecmp(str, "text", 4))
+					opcode = WEBSOCKET_OPCODE_TEXT;
+				else if (!mg_strncasecmp(str, "bin", 3))
+					opcode = WEBSOCKET_OPCODE_BINARY;
+				else if (!mg_strncasecmp(str, "close", 5))
+					opcode = WEBSOCKET_OPCODE_CONNECTION_CLOSE;
+				else if (!mg_strncasecmp(str, "ping", 4))
+					opcode = WEBSOCKET_OPCODE_PING;
+				else if (!mg_strncasecmp(str, "pong", 4))
+					opcode = WEBSOCKET_OPCODE_PONG;
+				else if (!mg_strncasecmp(str, "cont", 4))
+					opcode = WEBSOCKET_OPCODE_CONTINUATION;
+			}
+		}
+	}
+
+	if (opcode >= 0 && opcode < 16 && lua_isstring(L, num_args)) {
+		str = lua_tolstring(L, num_args, &size);
+		if (client) {
+			for (i = 0; i < ws->references; i++) {
+				if (client == ws->conn[i]) {
+					mg_websocket_write(ws->conn[i], opcode, str, size);
+				}
+			}
+		} else {
+			for (i = 0; i < ws->references; i++) {
+				mg_websocket_write(ws->conn[i], opcode, str, size);
+			}
+		}
+	} else {
+		(void)pthread_mutex_unlock(&(ws->ws_mutex));
+		return luaL_error(L, "invalid websocket write() call");
+	}
+
+	(void)pthread_mutex_unlock(&(ws->ws_mutex));
+
+#else
+	(void)(L);           /* unused */
+#endif
+	return 0;
+}
+
+
+struct laction_arg {
+	lua_State *state;
+	const char *script;
+	pthread_mutex_t *pmutex;
+	char txt[1];
+};
+
+
+static int
+lua_action(struct laction_arg *arg)
+{
+	int err, ok;
+	struct mg_context *ctx;
+
+	(void)pthread_mutex_lock(arg->pmutex);
+
+	lua_pushlightuserdata(arg->state, (void *)&lua_regkey_ctx);
+	lua_gettable(arg->state, LUA_REGISTRYINDEX);
+	ctx = (struct mg_context *)lua_touserdata(arg->state, -1);
+
+	err = luaL_loadstring(arg->state, arg->txt);
+	if (err != 0) {
+		lua_cry(fc(ctx), err, arg->state, arg->script, "timer");
+		(void)pthread_mutex_unlock(arg->pmutex);
+		mg_free(arg);
+		return 0;
+	}
+	err = lua_pcall(arg->state, 0, 1, 0);
+	if (err != 0) {
+		lua_cry(fc(ctx), err, arg->state, arg->script, "timer");
+		(void)pthread_mutex_unlock(arg->pmutex);
+		mg_free(arg);
+		return 0;
+	}
+
+	ok = lua_type(arg->state, -1);
+	if (lua_isboolean(arg->state, -1)) {
+		ok = lua_toboolean(arg->state, -1);
+	} else {
+		ok = 0;
+	}
+	lua_pop(arg->state, 1);
+
+	(void)pthread_mutex_unlock(arg->pmutex);
+
+	if (!ok) {
+		mg_free(arg);
+	}
+	return ok;
+}
+
+
+static int
+lua_action_free(struct laction_arg *arg)
+{
+	if (lua_action(arg)) {
+		mg_free(arg);
+	}
+	return 0;
+}
+
+
+static int
+lwebsocket_set_timer(lua_State *L, int is_periodic)
+{
+#if defined(USE_TIMERS) && defined(USE_WEBSOCKET)
+	int num_args = lua_gettop(L);
+	struct lua_websock_data *ws;
+	int type1, type2, ok = 0;
+	double timediff;
+	struct mg_context *ctx;
+	struct laction_arg *arg;
+	const char *txt;
+	size_t txt_len;
+
+	lua_pushlightuserdata(L, (void *)&lua_regkey_ctx);
+	lua_gettable(L, LUA_REGISTRYINDEX);
+	ctx = (struct mg_context *)lua_touserdata(L, -1);
+
+	lua_pushlightuserdata(L, (void *)&lua_regkey_connlist);
+	lua_gettable(L, LUA_REGISTRYINDEX);
+	ws = (struct lua_websock_data *)lua_touserdata(L, -1);
+
+	if (num_args < 2) {
+		return luaL_error(L,
+		                  "not enough arguments for set_timer/interval() call");
+	}
+
+	type1 = lua_type(L, 1);
+	type2 = lua_type(L, 2);
+
+	if (type1 == LUA_TSTRING && type2 == LUA_TNUMBER && num_args == 2) {
+		timediff = (double)lua_tonumber(L, 2);
+		txt = lua_tostring(L, 1);
+		txt_len = strlen(txt);
+		arg = (struct laction_arg *)mg_malloc(sizeof(struct laction_arg)
+		                                      + txt_len + 10);
+		arg->state = L;
+		arg->script = ws->script;
+		arg->pmutex = &(ws->ws_mutex);
+		memcpy(arg->txt, "return(", 7);
+		memcpy(arg->txt + 7, txt, txt_len);
+		arg->txt[txt_len + 7] = ')';
+		arg->txt[txt_len + 8] = 0;
+		ok =
+		    (0
+		     == timer_add(ctx,
+		                  timediff,
+		                  is_periodic,
+		                  1,
+		                  (taction)(is_periodic ? lua_action : lua_action_free),
+		                  (void *)arg));
+	} else if (type1 == LUA_TFUNCTION && type2 == LUA_TNUMBER) {
+		/* TODO (mid): not implemented yet */
+		return luaL_error(L, "invalid arguments for set_timer/interval() call");
+	} else {
+		return luaL_error(L, "invalid arguments for set_timer/interval() call");
+	}
+
+	lua_pushboolean(L, ok);
+	return 1;
+
+#else
+	(void)(L);           /* unused */
+	(void)(is_periodic); /* unused */
+	return 0;
+#endif
+}
+
+
+/* mg.set_timeout for websockets */
+static int
+lwebsocket_set_timeout(lua_State *L)
+{
+	return lwebsocket_set_timer(L, 0);
+}
+
+
+/* mg.set_interval for websockets */
+static int
+lwebsocket_set_interval(lua_State *L)
+{
+	return lwebsocket_set_timer(L, 1);
+}
+
+enum {
+	LUA_ENV_TYPE_LUA_SERVER_PAGE = 0,
+	LUA_ENV_TYPE_PLAIN_LUA_PAGE = 1,
+	LUA_ENV_TYPE_LUA_WEBSOCKET = 2,
+};
+
+
+static void
+prepare_lua_request_info(struct mg_connection *conn, lua_State *L)
+{
+	const char *s;
+	int i;
+
+	/* Export mg.request_info */
+	lua_pushstring(L, "request_info");
+	lua_newtable(L);
+	reg_string(L, "request_method", conn->request_info.request_method);
+	reg_string(L, "request_uri", conn->request_info.request_uri);
+	reg_string(L, "uri", conn->request_info.local_uri);
+	reg_string(L, "http_version", conn->request_info.http_version);
+	reg_string(L, "query_string", conn->request_info.query_string);
+#if defined(MG_LEGACY_INTERFACE)
+	reg_int(L, "remote_ip", conn->request_info.remote_ip); /* remote_ip is
+	                                                          deprecated, use
+	                                                          remote_addr
+	                                                          instead */
+#endif
+	reg_string(L, "remote_addr", conn->request_info.remote_addr);
+	/* TODO (high): ip version */
+	reg_int(L, "remote_port", conn->request_info.remote_port);
+	reg_int(L, "num_headers", conn->request_info.num_headers);
+	reg_int(L, "server_port", ntohs(conn->client.lsa.sin.sin_port));
+
+	if (conn->path_info != NULL) {
+		reg_string(L, "path_info", conn->path_info);
+	}
+
+	if (conn->request_info.content_length >= 0) {
+		/* reg_int64: content_length */
+		lua_pushstring(L, "content_length");
+		lua_pushnumber(
+		    L,
+		    (lua_Number)conn->request_info
+		        .content_length); /* lua_Number may be used as 52 bit integer */
+		lua_rawset(L, -3);
+	}
+	if ((s = mg_get_header(conn, "Content-Type")) != NULL) {
+		reg_string(L, "content_type", s);
+	}
+
+	if (conn->request_info.remote_user != NULL) {
+		reg_string(L, "remote_user", conn->request_info.remote_user);
+		reg_string(L, "auth_type", "Digest");
+	}
+
+	reg_boolean(L, "https", conn->ssl != NULL);
+
+	if (conn->status_code > 0) {
+		/* Lua error handler should show the status code */
+		reg_int(L, "status", conn->status_code);
+	}
+
+	lua_pushstring(L, "http_headers");
+	lua_newtable(L);
+	for (i = 0; i < conn->request_info.num_headers; i++) {
+		reg_string(L,
+		           conn->request_info.http_headers[i].name,
+		           conn->request_info.http_headers[i].value);
+	}
+	lua_rawset(L, -3);
+
+	lua_rawset(L, -3);
+}
+
+
+void
+civetweb_open_lua_libs(lua_State *L)
+{
+	{
+		extern void luaL_openlibs(lua_State *);
+		luaL_openlibs(L);
+	}
+
+#ifdef USE_LUA_SQLITE3
+	{
+		extern int luaopen_lsqlite3(lua_State *);
+		luaopen_lsqlite3(L);
+	}
+#endif
+#ifdef USE_LUA_LUAXML
+	{
+		extern int luaopen_LuaXML_lib(lua_State *);
+		luaopen_LuaXML_lib(L);
+	}
+#endif
+#ifdef USE_LUA_FILE_SYSTEM
+	{
+		extern int luaopen_lfs(lua_State *);
+		luaopen_lfs(L);
+	}
+#endif
+#ifdef USE_LUA_BINARY
+	{
+		/* TODO (low): Test if this could be used as a replacement for bit32.
+		 * Check again with Lua 5.3 later. */
+		extern int luaopen_binary(lua_State *);
+
+		luaL_requiref(L, "binary", luaopen_binary, 1);
+		lua_pop(L, 1);
+	}
+#endif
+}
+
+
+static void
+prepare_lua_environment(struct mg_context *ctx,
+                        struct mg_connection *conn,
+                        struct lua_websock_data *ws_conn_list,
+                        lua_State *L,
+                        const char *script_name,
+                        int lua_env_type)
+{
+	civetweb_open_lua_libs(L);
+
+#if LUA_VERSION_NUM == 502
+	/* Keep the "connect" method for compatibility,
+	 * but do not backport it to Lua 5.1.
+	 * TODO: Redesign the interface.
+	 */
+	luaL_newmetatable(L, LUASOCKET);
+	lua_pushliteral(L, "__index");
+	luaL_newlib(L, luasocket_methods);
+	lua_rawset(L, -3);
+	lua_pop(L, 1);
+	lua_register(L, "connect", lsp_connect);
+#endif
+
+	/* Store context in the registry */
+	if (ctx != NULL) {
+		lua_pushlightuserdata(L, (void *)&lua_regkey_ctx);
+		lua_pushlightuserdata(L, (void *)ctx);
+		lua_settable(L, LUA_REGISTRYINDEX);
+	}
+	if (ws_conn_list != NULL) {
+		lua_pushlightuserdata(L, (void *)&lua_regkey_connlist);
+		lua_pushlightuserdata(L, (void *)ws_conn_list);
+		lua_settable(L, LUA_REGISTRYINDEX);
+	}
+
+	/* Register mg module */
+	lua_newtable(L);
+
+	switch (lua_env_type) {
+	case LUA_ENV_TYPE_LUA_SERVER_PAGE:
+		reg_string(L, "lua_type", "page");
+		break;
+	case LUA_ENV_TYPE_PLAIN_LUA_PAGE:
+		reg_string(L, "lua_type", "script");
+		break;
+	case LUA_ENV_TYPE_LUA_WEBSOCKET:
+		reg_string(L, "lua_type", "websocket");
+		break;
+	}
+
+	if (lua_env_type == LUA_ENV_TYPE_LUA_SERVER_PAGE
+	    || lua_env_type == LUA_ENV_TYPE_PLAIN_LUA_PAGE) {
+		reg_conn_function(L, "cry", lsp_cry, conn);
+		reg_conn_function(L, "read", lsp_read, conn);
+		reg_conn_function(L, "write", lsp_write, conn);
+		reg_conn_function(L, "keep_alive", lsp_keep_alive, conn);
+		reg_conn_function(L, "send_file", lsp_send_file, conn);
+	}
+
+	if (lua_env_type == LUA_ENV_TYPE_LUA_SERVER_PAGE) {
+		reg_conn_function(L, "include", lsp_include, conn);
+		reg_conn_function(L, "redirect", lsp_redirect, conn);
+	}
+
+	if (lua_env_type == LUA_ENV_TYPE_LUA_WEBSOCKET) {
+		reg_function(L, "write", lwebsock_write);
+#ifdef USE_TIMERS
+		reg_function(L, "set_timeout", lwebsocket_set_timeout);
+		reg_function(L, "set_interval", lwebsocket_set_interval);
+#endif
+		/* reg_conn_function(L, "send_file", lsp_send_file, conn); */
+	}
+
+	reg_function(L, "time", lsp_get_time);
+	reg_function(L, "get_var", lsp_get_var);
+	reg_function(L, "get_mime_type", lsp_get_mime_type);
+	reg_function(L, "get_cookie", lsp_get_cookie);
+	reg_function(L, "md5", lsp_md5);
+	reg_function(L, "url_encode", lsp_url_encode);
+	reg_function(L, "url_decode", lsp_url_decode);
+	reg_function(L, "base64_encode", lsp_base64_encode);
+	reg_function(L, "base64_decode", lsp_base64_decode);
+	reg_function(L, "get_response_code_text", lsp_get_response_code_text);
+	reg_function(L, "random", lsp_random);
+	if (pf_uuid_generate.f) {
+		reg_function(L, "uuid", lsp_uuid);
+	}
+
+	reg_string(L, "version", CIVETWEB_VERSION);
+
+	reg_string(L, "script_name", script_name);
+
+	if (ctx != NULL) {
+		reg_string(L, "document_root", ctx->config[DOCUMENT_ROOT]);
+		reg_string(L, "auth_domain", ctx->config[AUTHENTICATION_DOMAIN]);
+#if defined(USE_WEBSOCKET)
+		if (ctx->config[WEBSOCKET_ROOT]) {
+			reg_string(L, "websocket_root", ctx->config[WEBSOCKET_ROOT]);
+		} else {
+			reg_string(L, "websocket_root", ctx->config[DOCUMENT_ROOT]);
+		}
+#endif
+
+		if (ctx->systemName != NULL) {
+			reg_string(L, "system", ctx->systemName);
+		}
+	}
+
+	/* Export connection specific info */
+	if (conn != NULL) {
+		prepare_lua_request_info(conn, L);
+	}
+
+	lua_setglobal(L, "mg");
+
+	/* Register default mg.onerror function */
+	IGNORE_UNUSED_RESULT(
+	    luaL_dostring(L,
+	                  "mg.onerror = function(e) mg.write('\\nLua error:\\n', "
+	                  "debug.traceback(e, 1)) end"));
+
+	if (ctx != NULL) {
+		/* Preload */
+		if (ctx->config[LUA_PRELOAD_FILE] != NULL) {
+			IGNORE_UNUSED_RESULT(luaL_dofile(L, ctx->config[LUA_PRELOAD_FILE]));
+		}
+
+		if (ctx->callbacks.init_lua != NULL) {
+			ctx->callbacks.init_lua(conn, L);
+		}
+	}
+}
+
+
+static int
+lua_error_handler(lua_State *L)
+{
+	const char *error_msg = lua_isstring(L, -1) ? lua_tostring(L, -1) : "?\n";
+
+	lua_getglobal(L, "mg");
+	if (!lua_isnil(L, -1)) {
+		lua_getfield(L, -1, "write"); /* call mg.write() */
+		lua_pushstring(L, error_msg);
+		lua_pushliteral(L, "\n");
+		lua_call(L, 2, 0);
+		IGNORE_UNUSED_RESULT(
+		    luaL_dostring(L, "mg.write(debug.traceback(), '\\n')"));
+	} else {
+		printf("Lua error: [%s]\n", error_msg);
+		IGNORE_UNUSED_RESULT(
+		    luaL_dostring(L, "print(debug.traceback(), '\\n')"));
+	}
+	/* TODO(lsm, low): leave the stack balanced */
+
+	return 0;
+}
+
+
+static void *
+lua_allocator(void *ud, void *ptr, size_t osize, size_t nsize)
+{
+	(void)ud;
+	(void)osize; /* not used */
+
+	if (nsize == 0) {
+		mg_free(ptr);
+		return NULL;
+	}
+	return mg_realloc(ptr, nsize);
+}
+
+
+static void
+mg_exec_lua_script(struct mg_connection *conn,
+                   const char *path,
+                   const void **exports)
+{
+	int i;
+	lua_State *L;
+
+	/* Assume the script does not support keep_alive. The script may change this
+	 * by calling mg.keep_alive(true). */
+	conn->must_close = 1;
+
+	/* Execute a plain Lua script. */
+	if (path != NULL && (L = lua_newstate(lua_allocator, NULL)) != NULL) {
+		prepare_lua_environment(
+		    conn->ctx, conn, NULL, L, path, LUA_ENV_TYPE_PLAIN_LUA_PAGE);
+		lua_pushcclosure(L, &lua_error_handler, 0);
+
+		if (exports != NULL) {
+#if LUA_VERSION_NUM > 501
+			lua_pushglobaltable(L);
+			for (i = 0; exports[i] != NULL && exports[i + 1] != NULL; i += 2) {
+				lua_CFunction func;
+				lua_pushstring(L, (const char *)(exports[i]));
+				*(const void **)(&func) = exports[i + 1];
+				lua_pushcclosure(L, func, 0);
+				lua_rawset(L, -3);
+			}
+#else
+			for (i = 0; exports[i] != NULL && exports[i + 1] != NULL; i += 2) {
+				lua_CFunction func;
+				const char *name = (const char *)(exports[i]);
+				*(const void **)(&func) = exports[i + 1];
+				lua_register(L, name, func);
+			}
+#endif
+		}
+
+		if (luaL_loadfile(L, path) != 0) {
+			lua_error_handler(L);
+		}
+		lua_pcall(L, 0, 0, -2);
+		lua_close(L);
+	}
+}
+
+
+static int
+handle_lsp_request(struct mg_connection *conn,
+                   const char *path,
+                   struct mg_file *filep,
+                   struct lua_State *ls)
+{
+	void *p = NULL;
+	lua_State *L = NULL;
+	int error = 1;
+	struct mg_file filesize = STRUCT_FILE_INITIALIZER;
+
+	/* Assume the script does not support keep_alive. The script may change this
+	 * by calling mg.keep_alive(true). */
+	conn->must_close = 1;
+
+	/* We need both mg_stat to get file size, and mg_fopen to get fd */
+	if (!mg_stat(conn, path, &filesize.stat)) {
+
+		/* File not found */
+		if (ls == NULL) {
+			send_http_error(conn, 500, "Error: File %s not found", path);
+		} else {
+			luaL_error(ls, "File [%s] not found", path);
+		}
+
+		goto cleanup_handle_lsp_request;
+	}
+
+	if (!mg_fopen(conn, path, MG_FOPEN_MODE_READ, filep)) {
+
+		/* File not found or not accessible */
+		if (ls == NULL) {
+			send_http_error(conn,
+			                500,
+			                "Error: Cannot open script file %s",
+			                path);
+		} else {
+			luaL_error(ls, "Cannot  [%s] not found", path);
+		}
+
+		goto cleanup_handle_lsp_request;
+	}
+
+	/* TODO: Operations mg_fopen and mg_stat should do what their names
+	 * indicate. They should not fill in different members of the same
+	 * struct mg_file.
+	 * See Github issue #225 */
+	filep->stat.size = filesize.stat.size;
+
+	if (filep->access.membuf == NULL
+	    && (p = mmap(NULL,
+	                 (size_t)filep->stat.size,
+	                 PROT_READ,
+	                 MAP_PRIVATE,
+	                 fileno(filep->access.fp),
+	                 0)) == MAP_FAILED) {
+
+		/* mmap failed */
+		if (ls == NULL) {
+			send_http_error(
+			    conn,
+			    500,
+			    "Error: Cannot open script\nFile %s can not be mapped",
+			    path);
+		} else {
+			luaL_error(ls,
+			           "mmap(%s, %zu, %d): %s",
+			           path,
+			           (size_t)filep->stat.size,
+			           fileno(filep->access.fp),
+			           strerror(errno));
+		}
+
+		goto cleanup_handle_lsp_request;
+	}
+
+	if (ls != NULL) {
+		L = ls;
+	} else {
+		L = lua_newstate(lua_allocator, NULL);
+		if (L == NULL) {
+			send_http_error(
+			    conn,
+			    500,
+			    "%s",
+			    "Error: Cannot execute script\nlua_newstate failed");
+
+			goto cleanup_handle_lsp_request;
+		}
+		prepare_lua_environment(
+		    conn->ctx, conn, NULL, L, path, LUA_ENV_TYPE_LUA_SERVER_PAGE);
+	}
+
+	/* Lua state is ready to use */
+	/* We're not sending HTTP headers here, Lua page must do it. */
+	error =
+	    lsp(conn,
+	        path,
+	        (filep->access.membuf == NULL) ? (const char *)p
+	                                       : (const char *)filep->access.membuf,
+	        filep->stat.size,
+	        L);
+
+cleanup_handle_lsp_request:
+
+	if (L != NULL && ls == NULL)
+		lua_close(L);
+	if (p != NULL)
+		munmap(p, filep->stat.size);
+	(void)mg_fclose(&filep->access);
+
+	return error;
+}
+
+
+#ifdef USE_WEBSOCKET
+struct mg_shared_lua_websocket_list {
+	struct lua_websock_data ws;
+	struct mg_shared_lua_websocket_list *next;
+};
+
+
+static void *
+lua_websocket_new(const char *script, struct mg_connection *conn)
+{
+	struct mg_shared_lua_websocket_list **shared_websock_list =
+	    &(conn->ctx->shared_lua_websockets);
+	struct lua_websock_data *ws;
+	int err, ok = 0;
+
+	assert(conn->lua_websocket_state == NULL);
+
+	/* lock list (mg_context global) */
+	mg_lock_context(conn->ctx);
+	while (*shared_websock_list) {
+		/* check if ws already in list */
+		if (0 == strcmp(script, (*shared_websock_list)->ws.script)) {
+			break;
+		}
+		shared_websock_list = &((*shared_websock_list)->next);
+	}
+
+	if (*shared_websock_list == NULL) {
+		/* add ws to list */
+		*shared_websock_list = (struct mg_shared_lua_websocket_list *)
+		    mg_calloc(sizeof(struct mg_shared_lua_websocket_list), 1);
+		if (*shared_websock_list == NULL) {
+			mg_unlock_context(conn->ctx);
+			mg_cry(conn, "Cannot create shared websocket struct, OOM");
+			return NULL;
+		}
+		/* init ws list element */
+		ws = &(*shared_websock_list)->ws;
+		ws->script = mg_strdup(script); /* TODO (low): handle OOM */
+		pthread_mutex_init(&(ws->ws_mutex), &pthread_mutex_attr);
+		(void)pthread_mutex_lock(&(ws->ws_mutex));
+		ws->state = lua_newstate(lua_allocator, NULL);
+		ws->conn[0] = conn;
+		ws->references = 1;
+		prepare_lua_environment(
+		    conn->ctx, NULL, ws, ws->state, script, LUA_ENV_TYPE_LUA_WEBSOCKET);
+		err = luaL_loadfile(ws->state, script);
+		if (err != 0) {
+			lua_cry(conn, err, ws->state, script, "load");
+		}
+		err = lua_pcall(ws->state, 0, 0, 0);
+		if (err != 0) {
+			lua_cry(conn, err, ws->state, script, "init");
+		}
+	} else {
+		/* inc ref count */
+		ws = &(*shared_websock_list)->ws;
+		(void)pthread_mutex_lock(&(ws->ws_mutex));
+		(*shared_websock_list)->ws.conn[(ws->references)++] = conn;
+	}
+	mg_unlock_context(conn->ctx);
+
+	/* call add */
+	lua_getglobal(ws->state, "open");
+	lua_newtable(ws->state);
+	prepare_lua_request_info(conn, ws->state);
+	lua_pushstring(ws->state, "client");
+	lua_pushlightuserdata(ws->state, (void *)conn);
+	lua_rawset(ws->state, -3);
+
+	err = lua_pcall(ws->state, 1, 1, 0);
+	if (err != 0) {
+		lua_cry(conn, err, ws->state, script, "open handler");
+	} else {
+		if (lua_isboolean(ws->state, -1)) {
+			ok = lua_toboolean(ws->state, -1);
+		}
+		lua_pop(ws->state, 1);
+	}
+	if (!ok) {
+		/* Remove from ws connection list. */
+		/* TODO (mid): Check if list entry and Lua state needs to be deleted
+		 * (see websocket_close). */
+		(*shared_websock_list)->ws.conn[--(ws->references)] = 0;
+	}
+
+	(void)pthread_mutex_unlock(&(ws->ws_mutex));
+
+	return ok ? (void *)ws : NULL;
+}
+
+
+static int
+lua_websocket_data(struct mg_connection *conn,
+                   int bits,
+                   char *data,
+                   size_t data_len,
+                   void *ws_arg)
+{
+	struct lua_websock_data *ws = (struct lua_websock_data *)(ws_arg);
+	int err, ok = 0;
+
+	assert(ws != NULL);
+	assert(ws->state != NULL);
+
+	(void)pthread_mutex_lock(&(ws->ws_mutex));
+
+	lua_getglobal(ws->state, "data");
+	lua_newtable(ws->state);
+	lua_pushstring(ws->state, "client");
+	lua_pushlightuserdata(ws->state, (void *)conn);
+	lua_rawset(ws->state, -3);
+	lua_pushstring(ws->state, "bits"); /* TODO: dont use "bits" but fields with
+	                                      a meaning according to
+	                                      http://tools.ietf.org/html/rfc6455,
+	                                      section 5.2 */
+	lua_pushnumber(ws->state, bits);
+	lua_rawset(ws->state, -3);
+	lua_pushstring(ws->state, "data");
+	lua_pushlstring(ws->state, data, data_len);
+	lua_rawset(ws->state, -3);
+
+	err = lua_pcall(ws->state, 1, 1, 0);
+	if (err != 0) {
+		lua_cry(conn, err, ws->state, ws->script, "data handler");
+	} else {
+		if (lua_isboolean(ws->state, -1)) {
+			ok = lua_toboolean(ws->state, -1);
+		}
+		lua_pop(ws->state, 1);
+	}
+	(void)pthread_mutex_unlock(&(ws->ws_mutex));
+
+	return ok;
+}
+
+
+static int
+lua_websocket_ready(struct mg_connection *conn, void *ws_arg)
+{
+	struct lua_websock_data *ws = (struct lua_websock_data *)(ws_arg);
+	int err, ok = 0;
+
+	assert(ws != NULL);
+	assert(ws->state != NULL);
+
+	(void)pthread_mutex_lock(&(ws->ws_mutex));
+
+	lua_getglobal(ws->state, "ready");
+	lua_newtable(ws->state);
+	lua_pushstring(ws->state, "client");
+	lua_pushlightuserdata(ws->state, (void *)conn);
+	lua_rawset(ws->state, -3);
+	err = lua_pcall(ws->state, 1, 1, 0);
+	if (err != 0) {
+		lua_cry(conn, err, ws->state, ws->script, "ready handler");
+	} else {
+		if (lua_isboolean(ws->state, -1)) {
+			ok = lua_toboolean(ws->state, -1);
+		}
+		lua_pop(ws->state, 1);
+	}
+
+	(void)pthread_mutex_unlock(&(ws->ws_mutex));
+
+	return ok;
+}
+
+
+static void
+lua_websocket_close(struct mg_connection *conn, void *ws_arg)
+{
+	struct lua_websock_data *ws = (struct lua_websock_data *)(ws_arg);
+	struct mg_shared_lua_websocket_list **shared_websock_list =
+	    &(conn->ctx->shared_lua_websockets);
+	int err = 0;
+	unsigned i;
+
+	assert(ws != NULL);
+	assert(ws->state != NULL);
+
+	(void)pthread_mutex_lock(&(ws->ws_mutex));
+
+	lua_getglobal(ws->state, "close");
+	lua_newtable(ws->state);
+	lua_pushstring(ws->state, "client");
+	lua_pushlightuserdata(ws->state, (void *)conn);
+	lua_rawset(ws->state, -3);
+
+	err = lua_pcall(ws->state, 1, 0, 0);
+	if (err != 0) {
+		lua_cry(conn, err, ws->state, ws->script, "close handler");
+	}
+	for (i = 0; i < ws->references; i++) {
+		if (ws->conn[i] == conn) {
+			ws->references--;
+			ws->conn[i] = ws->conn[ws->references];
+		}
+	}
+	/* TODO: Delete lua_websock_data and remove it from the websocket list.
+	   This must only be done, when all connections are closed, and all
+	   asynchronous operations and timers are completed/expired. */
+	(void)shared_websock_list; /* shared_websock_list unused (see open TODO) */
+
+	(void)pthread_mutex_unlock(&(ws->ws_mutex));
+}
+#endif
+
+
+lua_State *
+mg_prepare_lua_context_script(const char *file_name,
+                              struct mg_context *ctx,
+                              char *ebuf,
+                              size_t ebuf_len)
+{
+	struct lua_State *L;
+	int lua_ret;
+	const char *lua_err_txt;
+
+	L = luaL_newstate();
+	if (L == NULL) {
+		mg_snprintf(NULL,
+		            NULL, /* No truncation check for ebuf */
+		            ebuf,
+		            ebuf_len,
+		            "Error: %s",
+		            "Cannot create Lua state");
+		return 0;
+	}
+	civetweb_open_lua_libs(L);
+
+	lua_ret = luaL_loadfile(L, file_name);
+	if (lua_ret != LUA_OK) {
+		/* Error when loading the file (e.g. file not found, out of memory, ...)
+		 */
+		lua_err_txt = lua_tostring(L, -1);
+		mg_snprintf(NULL,
+		            NULL, /* No truncation check for ebuf */
+		            ebuf,
+		            ebuf_len,
+		            "Error loading file %s: %s\n",
+		            file_name,
+		            lua_err_txt);
+		return 0;
+	}
+
+	/* The script file is loaded, now call it */
+	lua_ret = lua_pcall(L,
+	                    /* no arguments */ 0,
+	                    /* zero or one return value */ 1,
+	                    /* errors as strint return value */ 0);
+
+	if (lua_ret != LUA_OK) {
+		/* Error when executing the script */
+		lua_err_txt = lua_tostring(L, -1);
+		mg_snprintf(NULL,
+		            NULL, /* No truncation check for ebuf */
+		            ebuf,
+		            ebuf_len,
+		            "Error running file %s: %s\n",
+		            file_name,
+		            lua_err_txt);
+		return 0;
+	}
+	/*	lua_close(L); must be done somewhere else */
+
+	return L;
+}
+
+
+int
+run_lua(const char *file_name)
+{
+	int func_ret = EXIT_FAILURE;
+	char ebuf[512] = {0};
+	lua_State *L =
+	    mg_prepare_lua_context_script(file_name, NULL, ebuf, sizeof(ebuf));
+	if (L) {
+		/* Script executed */
+		if (lua_type(L, -1) == LUA_TNUMBER) {
+			func_ret = (int)lua_tonumber(L, -1);
+		} else {
+			func_ret = EXIT_SUCCESS;
+		}
+		lua_close(L);
+	} else {
+		fprintf(stderr, "%s\n", ebuf);
+	}
+	return func_ret;
+}
+
+
+static void *lib_handle_uuid = NULL;
+
+static void
+lua_init_optional_libraries(void)
+{
+#if !defined(_WIN32)
+	lib_handle_uuid = dlopen("libuuid.so", RTLD_LAZY);
+	pf_uuid_generate.p = dlsym(lib_handle_uuid, "uuid_generate");
+#else
+	pf_uuid_generate.p = 0;
+#endif
+}
+
+
+static void
+lua_exit_optional_libraries(void)
+{
+#if !defined(_WIN32)
+	dlclose(lib_handle_uuid);
+#endif
+	pf_uuid_generate.p = 0;
+	lib_handle_uuid = NULL;
+}

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/sha1.inl
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/sha1.inl b/thirdparty/civetweb-1.9.1/src/sha1.inl
new file mode 100644
index 0000000..a629c2f
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/sha1.inl
@@ -0,0 +1,323 @@
+/*
+SHA-1 in C
+By Steve Reid <sr...@sea-to-sky.net>
+100% Public Domain
+
+-----------------
+Modified 7/98
+By James H. Brown <jb...@burgoyne.com>
+Still 100% Public Domain
+
+Corrected a problem which generated improper hash values on 16 bit machines
+Routine SHA1Update changed from
+    void SHA1Update(SHA1_CTX* context, unsigned char* data, unsigned int
+len)
+to
+    void SHA1Update(SHA1_CTX* context, unsigned char* data, unsigned
+long len)
+
+The 'len' parameter was declared an int which works fine on 32 bit machines.
+However, on 16 bit machines an int is too small for the shifts being done
+against
+it.  This caused the hash function to generate incorrect values if len was
+greater than 8191 (8K - 1) due to the 'len << 3' on line 3 of SHA1Update().
+
+Since the file IO in main() reads 16K at a time, any file 8K or larger would
+be guaranteed to generate the wrong hash (e.g. Test Vector #3, a million
+"a"s).
+
+I also changed the declaration of variables i & j in SHA1Update to
+unsigned long from unsigned int for the same reason.
+
+These changes should make no difference to any 32 bit implementations since
+an
+int and a long are the same size in those environments.
+
+--
+I also corrected a few compiler warnings generated by Borland C.
+1. Added #include <process.h> for exit() prototype
+2. Removed unused variable 'j' in SHA1Final
+3. Changed exit(0) to return(0) at end of main.
+
+ALL changes I made can be located by searching for comments containing 'JHB'
+-----------------
+Modified 8/98
+By Steve Reid <sr...@sea-to-sky.net>
+Still 100% public domain
+
+1- Removed #include <process.h> and used return() instead of exit()
+2- Fixed overwriting of finalcount in SHA1Final() (discovered by Chris Hall)
+3- Changed email address from steve@edmweb.com to sreid@sea-to-sky.net
+
+-----------------
+Modified 4/01
+By Saul Kravitz <Sa...@celera.com>
+Still 100% PD
+Modified to run on Compaq Alpha hardware.
+
+-----------------
+Modified 07/2002
+By Ralph Giles <gi...@ghostscript.com>
+Still 100% public domain
+modified for use with stdint types, autoconf
+code cleanup, removed attribution comments
+switched SHA1Final() argument order for consistency
+use SHA1_ prefix for public api
+move public api to sha1.h
+*/
+
+/*
+11/2016 adapted for CivetWeb:
+  include sha1.h in sha1.c,
+  rename to sha1.inl
+  remove unused #ifdef sections
+  make endian independent
+  align buffer to 4 bytes
+*/
+
+/*
+Test Vectors (from FIPS PUB 180-1)
+"abc"
+  A9993E36 4706816A BA3E2571 7850C26C 9CD0D89D
+"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
+  84983E44 1C3BD26E BAAE4AA1 F95129E5 E54670F1
+A million repetitions of "a"
+  34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F
+*/
+
+#include <string.h>
+#include <stdint.h>
+
+typedef struct {
+	uint32_t state[5];
+	uint32_t count[2];
+	uint8_t buffer[64];
+} SHA1_CTX;
+
+#define SHA1_DIGEST_SIZE 20
+
+#define rol(value, bits) (((value) << (bits)) | ((value) >> (32 - (bits))))
+
+/* blk0() and blk() perform the initial expand. */
+/* I got the idea of expanding during the round function from SSLeay */
+
+
+typedef union {
+	uint8_t c[64];
+	uint32_t l[16];
+} CHAR64LONG16;
+
+
+static uint32_t
+blk0(CHAR64LONG16 *block, int i)
+{
+	static const uint32_t n = 1u;
+	if ((*((uint8_t *)(&n))) == 1) {
+		/* little endian / intel byte order */
+		block->l[i] = (rol(block->l[i], 24) & 0xFF00FF00)
+		              | (rol(block->l[i], 8) & 0x00FF00FF);
+	}
+	return block->l[i];
+}
+
+#define blk(block, i)                                                          \
+	(block->l[i & 15] = rol(block->l[(i + 13) & 15] ^ block->l[(i + 8) & 15]   \
+	                            ^ block->l[(i + 2) & 15] ^ block->l[i & 15],   \
+	                        1))
+
+/* (R0+R1), R2, R3, R4 are the different operations used in SHA1 */
+#define R0(v, w, x, y, z, i)                                                   \
+	z += ((w & (x ^ y)) ^ y) + blk0(block, i) + 0x5A827999 + rol(v, 5);        \
+	w = rol(w, 30);
+#define R1(v, w, x, y, z, i)                                                   \
+	z += ((w & (x ^ y)) ^ y) + blk(block, i) + 0x5A827999 + rol(v, 5);         \
+	w = rol(w, 30);
+#define R2(v, w, x, y, z, i)                                                   \
+	z += (w ^ x ^ y) + blk(block, i) + 0x6ED9EBA1 + rol(v, 5);                 \
+	w = rol(w, 30);
+#define R3(v, w, x, y, z, i)                                                   \
+	z += (((w | x) & y) | (w & x)) + blk(block, i) + 0x8F1BBCDC + rol(v, 5);   \
+	w = rol(w, 30);
+#define R4(v, w, x, y, z, i)                                                   \
+	z += (w ^ x ^ y) + blk(block, i) + 0xCA62C1D6 + rol(v, 5);                 \
+	w = rol(w, 30);
+
+
+/* Hash a single 512-bit block. This is the core of the algorithm. */
+static void
+SHA1_Transform(uint32_t state[5], const uint8_t buffer[64])
+{
+	uint32_t a, b, c, d, e;
+
+	/* Must use an aligned, read/write buffer */
+	CHAR64LONG16 block[1];
+	memcpy(block, buffer, sizeof(block));
+
+	/* Copy context->state[] to working vars */
+	a = state[0];
+	b = state[1];
+	c = state[2];
+	d = state[3];
+	e = state[4];
+
+	/* 4 rounds of 20 operations each. Loop unrolled. */
+	R0(a, b, c, d, e, 0);
+	R0(e, a, b, c, d, 1);
+	R0(d, e, a, b, c, 2);
+	R0(c, d, e, a, b, 3);
+	R0(b, c, d, e, a, 4);
+	R0(a, b, c, d, e, 5);
+	R0(e, a, b, c, d, 6);
+	R0(d, e, a, b, c, 7);
+	R0(c, d, e, a, b, 8);
+	R0(b, c, d, e, a, 9);
+	R0(a, b, c, d, e, 10);
+	R0(e, a, b, c, d, 11);
+	R0(d, e, a, b, c, 12);
+	R0(c, d, e, a, b, 13);
+	R0(b, c, d, e, a, 14);
+	R0(a, b, c, d, e, 15);
+	R1(e, a, b, c, d, 16);
+	R1(d, e, a, b, c, 17);
+	R1(c, d, e, a, b, 18);
+	R1(b, c, d, e, a, 19);
+	R2(a, b, c, d, e, 20);
+	R2(e, a, b, c, d, 21);
+	R2(d, e, a, b, c, 22);
+	R2(c, d, e, a, b, 23);
+	R2(b, c, d, e, a, 24);
+	R2(a, b, c, d, e, 25);
+	R2(e, a, b, c, d, 26);
+	R2(d, e, a, b, c, 27);
+	R2(c, d, e, a, b, 28);
+	R2(b, c, d, e, a, 29);
+	R2(a, b, c, d, e, 30);
+	R2(e, a, b, c, d, 31);
+	R2(d, e, a, b, c, 32);
+	R2(c, d, e, a, b, 33);
+	R2(b, c, d, e, a, 34);
+	R2(a, b, c, d, e, 35);
+	R2(e, a, b, c, d, 36);
+	R2(d, e, a, b, c, 37);
+	R2(c, d, e, a, b, 38);
+	R2(b, c, d, e, a, 39);
+	R3(a, b, c, d, e, 40);
+	R3(e, a, b, c, d, 41);
+	R3(d, e, a, b, c, 42);
+	R3(c, d, e, a, b, 43);
+	R3(b, c, d, e, a, 44);
+	R3(a, b, c, d, e, 45);
+	R3(e, a, b, c, d, 46);
+	R3(d, e, a, b, c, 47);
+	R3(c, d, e, a, b, 48);
+	R3(b, c, d, e, a, 49);
+	R3(a, b, c, d, e, 50);
+	R3(e, a, b, c, d, 51);
+	R3(d, e, a, b, c, 52);
+	R3(c, d, e, a, b, 53);
+	R3(b, c, d, e, a, 54);
+	R3(a, b, c, d, e, 55);
+	R3(e, a, b, c, d, 56);
+	R3(d, e, a, b, c, 57);
+	R3(c, d, e, a, b, 58);
+	R3(b, c, d, e, a, 59);
+	R4(a, b, c, d, e, 60);
+	R4(e, a, b, c, d, 61);
+	R4(d, e, a, b, c, 62);
+	R4(c, d, e, a, b, 63);
+	R4(b, c, d, e, a, 64);
+	R4(a, b, c, d, e, 65);
+	R4(e, a, b, c, d, 66);
+	R4(d, e, a, b, c, 67);
+	R4(c, d, e, a, b, 68);
+	R4(b, c, d, e, a, 69);
+	R4(a, b, c, d, e, 70);
+	R4(e, a, b, c, d, 71);
+	R4(d, e, a, b, c, 72);
+	R4(c, d, e, a, b, 73);
+	R4(b, c, d, e, a, 74);
+	R4(a, b, c, d, e, 75);
+	R4(e, a, b, c, d, 76);
+	R4(d, e, a, b, c, 77);
+	R4(c, d, e, a, b, 78);
+	R4(b, c, d, e, a, 79);
+
+	/* Add the working vars back into context.state[] */
+	state[0] += a;
+	state[1] += b;
+	state[2] += c;
+	state[3] += d;
+	state[4] += e;
+
+	/* Wipe variables */
+	a = b = c = d = e = 0;
+}
+
+
+/* SHA1Init - Initialize new context */
+SHA_API void
+SHA1_Init(SHA1_CTX *context)
+{
+	/* SHA1 initialization constants */
+	context->state[0] = 0x67452301;
+	context->state[1] = 0xEFCDAB89;
+	context->state[2] = 0x98BADCFE;
+	context->state[3] = 0x10325476;
+	context->state[4] = 0xC3D2E1F0;
+	context->count[0] = context->count[1] = 0;
+}
+
+
+SHA_API void
+SHA1_Update(SHA1_CTX *context, const uint8_t *data, const uint32_t len)
+{
+	uint32_t i, j;
+
+	j = context->count[0];
+	if ((context->count[0] += (len << 3)) < j) {
+		context->count[1]++;
+	}
+	context->count[1] += (len >> 29);
+	j = (j >> 3) & 63;
+	if ((j + len) > 63) {
+		i = 64 - j;
+		memcpy(&context->buffer[j], data, i);
+		SHA1_Transform(context->state, context->buffer);
+		for (; i + 63 < len; i += 64) {
+			SHA1_Transform(context->state, &data[i]);
+		}
+		j = 0;
+	} else {
+		i = 0;
+	}
+	memcpy(&context->buffer[j], &data[i], len - i);
+}
+
+
+/* Add padding and return the message digest. */
+SHA_API void
+SHA1_Final(SHA1_CTX *context, uint8_t digest[SHA1_DIGEST_SIZE])
+{
+	uint32_t i;
+	uint8_t finalcount[8];
+
+	for (i = 0; i < 8; i++) {
+		finalcount[i] =
+		    (uint8_t)((context->count[(i >= 4 ? 0 : 1)] >> ((3 - (i & 3)) * 8))
+		              & 255); /* Endian independent */
+	}
+	SHA1_Update(context, (uint8_t *)"\x80", 1);
+	while ((context->count[0] & 504) != 448) {
+		SHA1_Update(context, (uint8_t *)"\x00", 1);
+	}
+	SHA1_Update(context, finalcount, 8); /* Should cause a SHA1_Transform() */
+	for (i = 0; i < SHA1_DIGEST_SIZE; i++) {
+		digest[i] =
+		    (uint8_t)((context->state[i >> 2] >> ((3 - (i & 3)) * 8)) & 255);
+	}
+
+	/* Wipe variables */
+	i = 0;
+	memset(context, '\0', sizeof(*context));
+	memset(&finalcount, '\0', sizeof(finalcount));
+}

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/LuaXML.lua
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/LuaXML.lua b/thirdparty/civetweb-1.9.1/src/third_party/LuaXML.lua
new file mode 100644
index 0000000..357be7e
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/LuaXML.lua
@@ -0,0 +1,116 @@
+local base = _G
+
+-- symbolic name for tag index, this allows accessing the tag by var[xml.TAG]
+xml.TAG = 0
+
+-- sets or returns tag of a LuaXML object
+function xml.tag(var,tag)
+	if base.type(var)~="table" then return end
+	if base.type(tag)=="nil" then 
+		return var[xml.TAG]
+	end
+	var[xml.TAG] = tag
+end
+
+-- creates a new LuaXML object either by setting the metatable of an existing Lua table or by setting its tag
+function xml.new(arg)
+	if base.type(arg)=="table" then 
+		base.setmetatable(arg,{__index=xml, __tostring=xml.str})
+		return arg
+	end
+	local var={}
+	base.setmetatable(var,{__index=xml, __tostring=xml.str})
+	if base.type(arg)=="string" then var[xml.TAG]=arg end
+	return var
+end
+
+-- appends a new subordinate LuaXML object to an existing one, optionally sets tag
+function xml.append(var,tag)
+	if base.type(var)~="table" then return end
+	local newVar = xml.new(tag)
+	var[#var+1] = newVar
+	return newVar
+end
+
+-- converts any Lua var into an XML string
+function xml.str(var,indent,tagValue)
+	if base.type(var)=="nil" then return end
+	local indent = indent or 0
+	local indentStr=""
+	for i = 1,indent do indentStr=indentStr.."	" end
+	local tableStr=""
+
+	if base.type(var)=="table" then
+		local tag = var[0] or tagValue or base.type(var)
+		local s = indentStr.."<"..tag
+		for k,v in base.pairs(var) do -- attributes 
+			if base.type(k)=="string" then
+				if base.type(v)=="table" and k~="_M" then -- otherwise recursiveness imminent
+					tableStr = tableStr..xml.str(v,indent+1,k)
+				else
+					s = s.." "..k.."=\""..xml.encode(base.tostring(v)).."\""
+				end
+			end
+		end
+		if #var==0 and #tableStr==0 then
+			s = s.." />\n"
+		elseif #var==1 and base.type(var[1])~="table" and #tableStr==0 then -- single element
+			s = s..">"..xml.encode(base.tostring(var[1])).."</"..tag..">\n"
+		else
+			s = s..">\n"
+			for k,v in base.ipairs(var) do -- elements
+				if base.type(v)=="string" then
+					s = s..indentStr.."	"..xml.encode(v).." \n"
+				else
+					s = s..xml.str(v,indent+1)
+				end
+			end
+			s=s..tableStr..indentStr.."</"..tag..">\n"
+		end
+		return s
+	else
+		local tag = base.type(var)
+		return indentStr.."<"..tag.."> "..xml.encode(base.tostring(var)).." </"..tag..">\n"
+	end
+end
+
+
+-- saves a Lua var as xml file
+function xml.save(var,filename)
+	if not var then return end
+	if not filename or #filename==0 then return end
+	local file = base.io.open(filename,"w")
+	file:write("<?xml version=\"1.0\"?>\n<!-- file \"",filename, "\", generated by LuaXML -->\n\n")
+	file:write(xml.str(var))
+	base.io.close(file)
+end
+
+
+-- recursively parses a Lua table for a substatement fitting to the provided tag and attribute
+function xml.find(var, tag, attributeKey,attributeValue)
+	-- check input:
+	if base.type(var)~="table" then return end
+	if base.type(tag)=="string" and #tag==0 then tag=nil end
+	if base.type(attributeKey)~="string" or #attributeKey==0 then attributeKey=nil end
+	if base.type(attributeValue)=="string" and #attributeValue==0 then attributeValue=nil end
+	-- compare this table:
+	if tag~=nil then
+		if var[0]==tag and ( attributeValue == nil or var[attributeKey]==attributeValue ) then
+			base.setmetatable(var,{__index=xml, __tostring=xml.str})
+			return var
+		end
+	else
+		if attributeValue == nil or var[attributeKey]==attributeValue then
+			base.setmetatable(var,{__index=xml, __tostring=xml.str})
+			return var
+		end
+	end
+	-- recursively parse subtags:
+	for k,v in base.ipairs(var) do
+		if base.type(v)=="table" then
+			local ret = xml.find(v, tag, attributeKey,attributeValue)
+			if ret ~= nil then return ret end
+		end
+	end
+end
+

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/LuaXML_lib.c
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/LuaXML_lib.c b/thirdparty/civetweb-1.9.1/src/third_party/LuaXML_lib.c
new file mode 100644
index 0000000..9ac7f9f
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/LuaXML_lib.c
@@ -0,0 +1,476 @@
+/**
+LuaXML License
+
+LuaXml is licensed under the terms of the MIT license reproduced below,
+the same as Lua itself. This means that LuaXml is free software and can be
+used for both academic and commercial purposes at absolutely no cost.
+
+Copyright (C) 2007-2013 Gerald Franz, eludi.net
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+*/
+
+#if defined __WIN32__ || defined WIN32
+# include <windows.h>
+# define _EXPORT __declspec(dllexport)
+#else
+# define _EXPORT
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "civetweb_lua.h"
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
+
+#include <stdio.h>
+#include <string.h>
+#include <ctype.h>
+#include <stdlib.h>
+
+static const char ESC=27;
+static const char OPN=28;
+static const char CLS=29;
+
+//--- auxliary functions -------------------------------------------
+
+static const char* char2code(unsigned char ch, char buf[8]) {
+    unsigned char i=0;
+    buf[i++]='&';
+    buf[i++]='#';
+    if(ch>99) buf[i++]=ch/100+48;
+    if(ch>9) buf[i++]=(ch%100)/10+48;
+    buf[i++]=ch%10+48;
+    buf[i++]=';';
+    buf[i]=0;
+    return buf;
+}
+
+static size_t find(const char* s, const char* pattern, size_t start) {
+    const char* found =strstr(s+start, pattern);
+    return found ? found-s : strlen(s);
+}
+
+//--- internal tokenizer -------------------------------------------
+
+typedef struct Tokenizer_s  {
+    /// stores string to be tokenized
+    const char* s;
+    /// stores size of string to be tokenized
+    size_t s_size;
+    /// stores current read position
+    size_t i;
+    /// stores current read context
+    int tagMode;
+    /// stores next token, if already determined
+    const char* m_next;
+    /// size of next token
+    size_t m_next_size;
+    /// pointer to current token
+    char* m_token;
+    /// size of current token
+    size_t m_token_size;
+    /// capacity of current token
+    size_t m_token_capacity;
+} Tokenizer;
+
+Tokenizer* Tokenizer_new(const char* str, size_t str_size) {
+    Tokenizer *tok = (Tokenizer*)malloc(sizeof(Tokenizer));
+    memset(tok, 0, sizeof(Tokenizer));
+    tok->s_size = str_size;
+    tok->s = str;
+    return tok;
+}
+
+void Tokenizer_delete(Tokenizer* tok) {
+    free(tok->m_token);
+    free(tok);
+}
+
+//void Tokenizer_print(Tokenizer* tok) { printf("  @%u %s\n", tok->i, !tok->m_token ? "(null)" : (tok->m_token[0]==ESC)?"(esc)" : (tok->m_token[0]==OPN)?"(open)": (tok->m_token[0]==CLS)?"(close)" : tok->m_token); fflush(stdout); }
+
+static const char* Tokenizer_set(Tokenizer* tok, const char* s, size_t size) {
+    if(!size||!s) return 0;
+    free(tok->m_token);
+    tok->m_token = (char*)malloc(size+1);
+    strncpy(tok->m_token,s, size);
+    tok->m_token[size] = 0;
+    tok->m_token_size = tok->m_token_capacity = size;
+    //Tokenizer_print(tok);
+    return tok->m_token;
+}
+
+static void Tokenizer_append(Tokenizer* tok, char ch) {
+    if(tok->m_token_size+1>=tok->m_token_capacity) {
+        tok->m_token_capacity = (tok->m_token_capacity==0) ? 16 : tok->m_token_capacity*2;
+        tok->m_token = (char*)realloc(tok->m_token, tok->m_token_capacity);
+    }
+    tok->m_token[tok->m_token_size]=ch;
+    tok->m_token[++tok->m_token_size]=0;
+}
+
+const char* Tokenizer_next(Tokenizer* tok) {
+    const char* ESC_str = "\033";
+    const char* OPEN_str = "\034";
+    const char* CLOSE_str = "\035";
+    int quotMode=0;
+    int tokenComplete = 0;
+
+    if(tok->m_token) {
+        free(tok->m_token);
+        tok->m_token = 0;
+        tok->m_token_size=tok->m_token_capacity = 0;
+    }
+
+    while(tok->m_next_size || (tok->i < tok->s_size)) {
+
+        if(tok->m_next_size) {
+            Tokenizer_set(tok, tok->m_next, tok->m_next_size);
+            tok->m_next=0;
+            tok->m_next_size=0;
+            return tok->m_token;
+        }
+
+        switch(tok->s[tok->i]) {
+            case '"':
+            case '\'':
+            if(tok->tagMode) {
+                if(!quotMode) quotMode=tok->s[tok->i];
+                else if(quotMode==tok->s[tok->i]) quotMode=0;
+            }
+            Tokenizer_append(tok, tok->s[tok->i]);
+            break;
+            case '<':
+            if(!quotMode&&(tok->i+4<tok->s_size)&&(strncmp(tok->s+tok->i,"<!--",4)==0)) // strip comments
+                tok->i=find(tok->s, "-->", tok->i+4)+2;
+            else if(!quotMode&&(tok->i+9<tok->s_size)&&(strncmp(tok->s+tok->i,"<![CDATA[",9)==0)) { // interpet CDATA
+                size_t b=tok->i+9;
+                tok->i=find(tok->s, "]]>",b)+3;
+                if(!tok->m_token_size) return Tokenizer_set(tok, tok->s+b, tok->i-b-3);
+                tokenComplete = 1;
+                tok->m_next = tok->s+b;
+                tok->m_next_size = tok->i-b-3;
+                --tok->i;
+            }
+            else if(!quotMode&&(tok->i+1<tok->s_size)&&((tok->s[tok->i+1]=='?')||(tok->s[tok->i+1]=='!'))) // strip meta information
+                tok->i=find(tok->s, ">", tok->i+2);
+            else if(!quotMode&&!tok->tagMode) {
+                if((tok->i+1<tok->s_size)&&(tok->s[tok->i+1]=='/')) {
+                    tok->m_next=ESC_str;
+                    tok->m_next_size = 1;
+                    tok->i=find(tok->s, ">", tok->i+2);
+                }
+                else {
+                    tok->m_next = OPEN_str;
+                    tok->m_next_size = 1;
+                    tok->tagMode=1;
+                }
+                tokenComplete = 1;
+            }
+            else Tokenizer_append(tok, tok->s[tok->i]);
+            break;
+            case '/':
+            if(tok->tagMode&&!quotMode) {
+                tokenComplete = 1;
+                if((tok->i+1 < tok->s_size) && (tok->s[tok->i+1]=='>')) {
+                    tok->tagMode=0;
+                    tok->m_next=ESC_str;
+                    tok->m_next_size = 1;
+                    ++tok->i;
+                }
+                else Tokenizer_append(tok, tok->s[tok->i]);
+            }
+            else Tokenizer_append(tok, tok->s[tok->i]);
+            break;
+            case '>':
+            if(!quotMode&&tok->tagMode) {
+                tok->tagMode=0;
+                tokenComplete = 1;
+                tok->m_next = CLOSE_str;
+                tok->m_next_size = 1;
+            }
+            else Tokenizer_append(tok, tok->s[tok->i]);
+            break;
+            case ' ':
+            case '\r':
+            case '\n':
+            case '\t':
+            if(tok->tagMode&&!quotMode) {
+                if(tok->m_token_size) tokenComplete=1;
+            }
+            else if(tok->m_token_size) Tokenizer_append(tok, tok->s[tok->i]);
+            break;
+            default: Tokenizer_append(tok, tok->s[tok->i]);
+        }
+        ++tok->i;
+        if((tok->i>=tok->s_size)||(tokenComplete&&tok->m_token_size)) {
+            tokenComplete=0;
+            while(tok->m_token_size&&isspace(tok->m_token[tok->m_token_size-1])) // trim whitespace
+                tok->m_token[--tok->m_token_size]=0;
+            if(tok->m_token_size) break;
+        }
+    }
+    //Tokenizer_print(tok);
+    return tok->m_token;
+}
+
+//--- local variables ----------------------------------------------
+
+/// stores number of special character codes
+static size_t sv_code_size=0;
+/// stores currently allocated capacity for special character codes
+static size_t sv_code_capacity=16;
+/// stores code table for special characters
+static char** sv_code=0;
+
+//--- public methods -----------------------------------------------
+
+static void Xml_pushDecode(lua_State* L, const char* s, size_t s_size) {
+
+    luaL_Buffer b;
+    const char* found = strstr(s, "&#");
+    size_t start=0, pos, i;
+
+    if(!s_size)
+        s_size=strlen(s);
+
+    luaL_buffinit(L, &b);
+    found = strstr(s, "&#");
+    pos = found ? found-s : s_size;
+
+    while(found) {
+        char ch = 0;
+        size_t i=0;
+        for(found += 2; i<3; ++i, ++found)
+            if(isdigit(*found))
+                ch = ch * 10 + (*found - 48);
+            else break;
+        if(*found == ';') {
+            if(pos>start)
+                luaL_addlstring(&b, s+start, pos-start);
+            luaL_addchar(&b, ch);
+            start = pos + 3 + i;
+        }
+        found = strstr(found+1, "&#");
+        pos = found ? found-s : s_size;
+    }
+    if(pos>start)
+        luaL_addlstring(&b,s+start, pos-start);
+    luaL_pushresult(&b);
+
+    for(i=sv_code_size-1; i<sv_code_size; i-=2) {
+        luaL_gsub(L, lua_tostring(L,-1), sv_code[i], sv_code[i-1]);
+        lua_remove(L,-2);
+    }
+}
+
+int Xml_eval(lua_State *L) {
+    char* str = 0;
+    size_t str_size=0;
+    Tokenizer* tok;
+    const char* token=0;
+    int firstStatement = 1;
+
+    if(lua_isuserdata(L,1))
+        str = (char*)lua_touserdata(L,1);
+    else {
+        const char * sTmp = luaL_checklstring(L,1,&str_size);
+        str = (char*)malloc(str_size+1);
+        memcpy(str, sTmp, str_size);
+        str[str_size]=0;
+    }
+    tok = Tokenizer_new(str, str_size ? str_size : strlen(str));
+    lua_settop(L,0);
+
+    while((token=Tokenizer_next(tok))!=0) if(token[0]==OPN) { // new tag found
+        if(lua_gettop(L)) {
+            size_t newIndex=lua_rawlen(L,-1)+1;
+            lua_pushnumber(L, (lua_Number)newIndex);
+            lua_newtable(L);
+            lua_settable(L, -3);
+            lua_pushnumber(L, (lua_Number)newIndex);
+            lua_gettable(L,-2);
+        }
+        else {
+            if (firstStatement) {
+                lua_newtable(L);
+                firstStatement = 0;
+            }
+            else return lua_gettop(L);
+        }
+        // set metatable:
+        lua_newtable(L);
+        lua_pushliteral(L, "__index");
+        lua_getglobal(L, "xml");
+        lua_settable(L, -3);
+
+        lua_pushliteral(L, "__tostring"); // set __tostring metamethod
+        lua_getglobal(L, "xml");
+        lua_pushliteral(L,"str");
+        lua_gettable(L, -2);
+        lua_remove(L, -2);
+        lua_settable(L, -3);
+        lua_setmetatable(L, -2);
+
+        // parse tag and content:
+        lua_pushnumber(L,0); // use index 0 for storing the tag
+        lua_pushstring(L, Tokenizer_next(tok));
+        lua_settable(L, -3);
+
+        while(((token = Tokenizer_next(tok))!=0)&&(token[0]!=CLS)&&(token[0]!=ESC)) { // parse tag header
+            size_t sepPos=find(token, "=", 0);
+            if(token[sepPos]) { // regular attribute
+                const char* aVal =token+sepPos+2;
+                size_t lenVal;
+
+                lua_pushlstring(L, token, sepPos);
+                lenVal = strlen(aVal)-1;
+                if(!lenVal) Xml_pushDecode(L, "", 0);
+                else Xml_pushDecode(L, aVal, lenVal);
+                lua_settable(L, -3);
+            }
+        }
+        if(!token||(token[0]==ESC)) {
+            if(lua_gettop(L)>1) lua_settop(L,-2); // this tag has no content, only attributes
+            else break;
+        }
+    }
+    else if(token[0]==ESC) { // previous tag is over
+        if(lua_gettop(L)>1) lua_settop(L,-2); // pop current table
+        else break;
+    }
+    else { // read elements
+        lua_pushnumber(L,(lua_Number)lua_rawlen(L,-1)+1);
+        Xml_pushDecode(L, token, 0);
+        lua_settable(L, -3);
+    }
+    Tokenizer_delete(tok);
+    free(str);
+    return lua_gettop(L);
+}
+
+int Xml_load (lua_State *L) {
+    const char * filename = luaL_checkstring(L,1);
+    FILE * file=fopen(filename,"r");
+    char* buffer;
+    size_t sz;
+
+    if(!file)
+        return luaL_error(L,"LuaXml ERROR: \"%s\" file error or file not found!",filename);
+
+    fseek (file , 0 , SEEK_END);
+    sz = ftell (file);
+    rewind (file);
+    buffer = (char*)malloc(sz+1);
+    sz = fread (buffer,1,sz,file);
+    fclose(file);
+    buffer[sz]=0;
+    lua_pushlightuserdata(L,buffer);
+    lua_replace(L,1);
+    return Xml_eval(L);
+};
+
+int Xml_registerCode(lua_State *L) {
+    const char * decoded = luaL_checkstring(L,1);
+    const char * encoded = luaL_checkstring(L,2);
+
+    size_t i;
+    for(i=0; i<sv_code_size; i+=2)
+        if(strcmp(sv_code[i],decoded)==0)
+            return luaL_error(L,"LuaXml ERROR: code already exists.");
+    if(sv_code_size+2>sv_code_capacity) {
+        sv_code_capacity*=2;
+        sv_code = (char**)realloc(sv_code, sv_code_capacity*sizeof(char*));
+    }
+    sv_code[sv_code_size]=(char*)malloc(strlen(decoded)+1);
+    strcpy(sv_code[sv_code_size++], decoded);
+    sv_code[sv_code_size]=(char*)malloc(strlen(encoded)+1);
+    strcpy(sv_code[sv_code_size++],encoded);
+    return 0;
+}
+
+int Xml_encode(lua_State *L) {
+
+    char buf[8];
+    size_t start, pos;
+    luaL_Buffer b;
+    const char* s;
+    size_t i;
+
+    if(lua_gettop(L)!=1)
+        return 0;
+    luaL_checkstring(L,-1);
+
+    for(i=0; i<sv_code_size; i+=2) {
+        luaL_gsub(L, lua_tostring(L,-1), sv_code[i], sv_code[i+1]);
+        lua_remove(L,-2);
+    }
+    s=lua_tostring(L,1);
+    luaL_buffinit(L, &b);
+    for(start=pos=0; s[pos]!=0; ++pos) if(s[pos]<0) {
+        if(pos>start) luaL_addlstring(&b,s+start, pos-start);
+        luaL_addstring(&b,char2code((unsigned char)(s[pos]),buf));
+        start=pos+1;
+    }
+    if(pos>start)
+        luaL_addlstring(&b,s+start, pos-start);
+    luaL_pushresult(&b);
+    lua_remove(L,-2);
+    return 1;
+}
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+int _EXPORT luaopen_LuaXML_lib (lua_State* L) {
+    static const struct luaL_Reg funcs[] = {
+        {"load", Xml_load},
+        {"eval", Xml_eval},
+        {"encode", Xml_encode},
+        {"registerCode", Xml_registerCode},
+        {NULL, NULL}
+    };
+
+    luaL_newlibtable(L, funcs);
+    luaL_setfuncs(L, funcs, 0);
+    lua_setglobal(L, "xml");
+
+    // register default codes:
+    if(!sv_code) {
+        sv_code=(char**)malloc(sv_code_capacity*sizeof(char*));
+        sv_code[sv_code_size++]="&";
+        sv_code[sv_code_size++]="&amp;";
+        sv_code[sv_code_size++]="<";
+        sv_code[sv_code_size++]="&lt;";
+        sv_code[sv_code_size++]=">";
+        sv_code[sv_code_size++]="&gt;";
+        sv_code[sv_code_size++]="\"";
+        sv_code[sv_code_size++]="&quot;";
+        sv_code[sv_code_size++]="'";
+        sv_code[sv_code_size++]="&apos;";
+    }
+    return 1;
+}
+#ifdef __cplusplus
+} // extern "C"
+#endif


[25/51] [partial] nifi-minifi-cpp git commit: MINIFI-183 Added civet 1.9.1 sources Added onScheduled hook Added initial two-way TLS-enabled ListenHTTP implementation

Posted by al...@apache.org.
http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/eventloop/README.rst
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/eventloop/README.rst b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/eventloop/README.rst
new file mode 100644
index 0000000..5b1b147
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/eventloop/README.rst
@@ -0,0 +1,76 @@
+==================
+Eventloop examples
+==================
+
+Overview and usage
+==================
+
+A few examples on how an event loop can be implemented with Duktape, mainly
+illlustrating how the Duktape interface works (not how event loops should be
+built otherwise).
+
+To test (Linux only, perhaps other Unix)::
+
+  $ make
+  $ ./evloop curses-timers.js     # run with Ecmascript eventloop
+  $ ./evloop -c curses-timers.js  # run with C eventloop
+
+Implementation approaches
+=========================
+
+There are several approaches to implementation timers.  Here we demonstrate
+two main approaches:
+
+1. Using a C eventloop which calls into Javascript.  All the event loop state
+   like timers, sockets, etc, is held in C structures.
+   (See ``c_eventloop.c`` and ``c_eventloop.js``.)
+
+2. Using an Ecmascript eventloop which never returns.  All the event loop state
+   can be managed with Ecmascript code instead of C structures.  The Ecmascript
+   eventloop calls a Duktape/C helper to do the lowest level poll() call.
+   (See ``ecma_eventloop.js``.)
+
+Services provided
+=================
+
+The event loop API provided by both examples is the same, and includes:
+
+* Timers: setTimeout, clearTimeout, setInterval, clearInterval
+
+* Sockets: simple network sockets
+
+In addition there are a few synchronous API bindings which are not event loop
+related:
+
+* File I/O
+
+* Curses, for doing beautiful character graphics
+
+Limitations
+===========
+
+This is **not** a production quality event loop.  This is on purpose, to
+keep the example somewhat simple.  Some shortcomings include:
+
+* A production quality event loop would track its internal state (active
+  timers and sockets) much more efficiently.  In general memory usage and
+  code footprint can be reduced.
+
+* Buffer churn caused by allocating a new buffer for every socket read
+  should be eliminated by reusing buffers where appropriate.  Although
+  churn doesn't increase memory footprint with reference counting, it
+  is slower than reusing buffers and might increase memory fragmentation.
+
+* There is no way to suspend reading or writing in the example.  Adding
+  them is straightforward: the poll set needs to be managed dynamically.
+
+* The example uses poll() while one should use epoll() on Linux, kqueue()
+  on BSD systems, etc.
+
+* Timers are not very accurate, e.g. setInterval() does not try to guarantee
+  a steady schedule.  Instead, the next interval is scheduled after the
+  current callback has finished.  This is not the best behavior for some
+  environments, but avoids bunching callbacks.
+
+* Error handling is mostly missing.  Debug prints don't interact well
+  with curses.

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/eventloop/basic-test.js
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/eventloop/basic-test.js b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/eventloop/basic-test.js
new file mode 100644
index 0000000..04b3392
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/eventloop/basic-test.js
@@ -0,0 +1,17 @@
+/*
+ *  A few basic tests
+ */
+
+var count = 0;
+var intervalId;
+
+setTimeout(function (x) { print('timer 1', x); }, 1234, 'foo');
+setTimeout('print("timer 2");', 4321);
+setTimeout(function () { print('timer 3'); }, 2345);
+intervalId = setInterval(function (x, y) {
+    print('interval', ++count, x, y);
+    if (count >= 10) {
+        clearInterval(intervalId);
+    }
+}, 400, 'foo', 'bar');
+

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/eventloop/c_eventloop.c
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/eventloop/c_eventloop.c b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/eventloop/c_eventloop.c
new file mode 100644
index 0000000..75d768b
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/eventloop/c_eventloop.c
@@ -0,0 +1,618 @@
+/*
+ *  C eventloop example.
+ *
+ *  Timer management is similar to eventloop.js but implemented in C.
+ *  In particular, timer insertion is an O(n) operation; in a real world
+ *  eventloop based on a heap insertion would be O(log N).
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdint.h>
+#include <sys/time.h>
+#include <poll.h>
+
+#include "duktape.h"
+
+#define  MAX_TIMERS             4096     /* this is quite excessive for embedded use, but good for testing */
+#define  MIN_DELAY              1.0
+#define  MIN_WAIT               1.0
+#define  MAX_WAIT               60000.0
+#define  MAX_EXPIRYS            10
+
+#define  MAX_FDS                256
+
+typedef struct {
+	int64_t id;       /* numeric ID (returned from e.g. setTimeout); zero if unused */
+	double target;    /* next target time */
+	double delay;     /* delay/interval */
+	int oneshot;      /* oneshot=1 (setTimeout), repeated=0 (setInterval) */
+	int removed;      /* timer has been requested for removal */
+
+	/* The callback associated with the timer is held in the "global stash",
+	 * in <stash>.eventTimers[String(id)].  The references must be deleted
+	 * when a timer struct is deleted.
+	 */
+} ev_timer;
+
+/* Active timers.  Dense list, terminates to end of list or first unused timer.
+ * The list is sorted by 'target', with lowest 'target' (earliest expiry) last
+ * in the list.  When a timer's callback is being called, the timer is moved
+ * to 'timer_expiring' as it needs special handling should the user callback
+ * delete that particular timer.
+ */
+static ev_timer timer_list[MAX_TIMERS];
+static ev_timer timer_expiring;
+static int timer_count;  /* last timer at timer_count - 1 */
+static int64_t timer_next_id = 1;
+
+/* Socket poll state. */
+static struct pollfd poll_list[MAX_FDS];
+static int poll_count = 0;
+
+/* Misc */
+static int exit_requested = 0;
+
+/* Get Javascript compatible 'now' timestamp (millisecs since 1970). */
+static double get_now(void) {
+	struct timeval tv;
+	int rc;
+
+	rc = gettimeofday(&tv, NULL);
+	if (rc != 0) {
+		/* Should never happen, so return whatever. */
+		return 0.0;
+	}
+	return ((double) tv.tv_sec) * 1000.0 + ((double) tv.tv_usec) / 1000.0;
+}
+
+static ev_timer *find_nearest_timer(void) {
+	/* Last timer expires first (list is always kept sorted). */
+	if (timer_count <= 0) {
+		return NULL;
+	}
+	return timer_list + timer_count - 1;
+}
+
+/* Bubble last timer on timer list backwards until it has been moved to
+ * its proper sorted position (based on 'target' time).
+ */
+static void bubble_last_timer(void) {
+	int i;
+	int n = timer_count;
+	ev_timer *t;
+	ev_timer tmp;
+
+	for (i = n - 1; i > 0; i--) {
+		/* Timer to bubble is at index i, timer to compare to is
+		 * at i-1 (both guaranteed to exist).
+		 */
+		t = timer_list + i;
+		if (t->target <= (t-1)->target) {
+			/* 't' expires earlier than (or same time as) 't-1', so we're done. */
+			break;
+		} else {
+			/* 't' expires later than 't-1', so swap them and repeat. */
+			memcpy((void *) &tmp, (void *) (t - 1), sizeof(ev_timer));
+			memcpy((void *) (t - 1), (void *) t, sizeof(ev_timer));
+			memcpy((void *) t, (void *) &tmp, sizeof(ev_timer));
+		}
+	}
+}
+
+static void expire_timers(duk_context *ctx) {
+	ev_timer *t;
+	int sanity = MAX_EXPIRYS;
+	double now;
+	int rc;
+
+	/* Because a user callback can mutate the timer list (by adding or deleting
+	 * a timer), we expire one timer and then rescan from the end again.  There
+	 * is a sanity limit on how many times we do this per expiry round.
+	 */
+
+	duk_push_global_stash(ctx);
+	duk_get_prop_string(ctx, -1, "eventTimers");
+
+	/* [ ... stash eventTimers ] */
+
+	now = get_now();
+	while (sanity-- > 0) {
+		/*
+		 *  If exit has been requested, exit without running further
+		 *  callbacks.
+		 */
+
+		if (exit_requested) {
+#if 0
+			fprintf(stderr, "exit requested, exiting timer expiry loop\n");
+			fflush(stderr);
+#endif
+			break;
+		}
+
+		/*
+		 *  Expired timer(s) still exist?
+		 */
+
+		if (timer_count <= 0) {
+			break;
+		}
+		t = timer_list + timer_count - 1;
+		if (t->target > now) {
+			break;
+		}
+
+		/*
+		 *  Move the timer to 'expiring' for the duration of the callback.
+		 *  Mark a one-shot timer deleted, compute a new target for an interval.
+		 */
+
+		memcpy((void *) &timer_expiring, (void *) t, sizeof(ev_timer));
+		memset((void *) t, 0, sizeof(ev_timer));
+		timer_count--;
+		t = &timer_expiring;
+
+		if (t->oneshot) {
+			t->removed = 1;
+		} else {
+			t->target = now + t->delay;  /* XXX: or t->target + t->delay? */
+		}
+
+		/*
+		 *  Call timer callback.  The callback can operate on the timer list:
+		 *  add new timers, remove timers.  The callback can even remove the
+		 *  expired timer whose callback we're calling.  However, because the
+		 *  timer being expired has been moved to 'timer_expiring', we don't
+		 *  need to worry about the timer's offset changing on the timer list.
+		 */
+
+#if 0
+		fprintf(stderr, "calling user callback for timer id %d\n", (int) t->id);
+		fflush(stderr);
+#endif
+
+		duk_push_number(ctx, (double) t->id);
+		duk_get_prop(ctx, -2);  /* -> [ ... stash eventTimers func ] */
+		rc = duk_pcall(ctx, 0 /*nargs*/);  /* -> [ ... stash eventTimers retval ] */
+		if (rc != 0) {
+#if 0
+			fprintf(stderr, "timer callback failed for timer %d: %s\n", (int) t->id, duk_to_string(ctx, -1));
+			fflush(stderr);
+#endif
+		}
+		duk_pop(ctx);    /* ignore errors for now -> [ ... stash eventTimers ] */
+
+		if (t->removed) {
+			/* One-shot timer (always removed) or removed by user callback. */
+#if 0
+			fprintf(stderr, "deleting callback state for timer %d\n", (int) t->id);
+			fflush(stderr);
+#endif
+			duk_push_number(ctx, (double) t->id);
+			duk_del_prop(ctx, -2);
+		} else {
+			/* Interval timer, not removed by user callback.  Queue back to
+			 * timer list and bubble to its final sorted position.
+			 */
+#if 0
+			fprintf(stderr, "queueing timer %d back into active list\n", (int) t->id);
+			fflush(stderr);
+#endif
+			if (timer_count >= MAX_TIMERS) {
+				duk_error(ctx, DUK_ERR_RANGE_ERROR, "out of timer slots");
+			}
+			memcpy((void *) (timer_list + timer_count), (void *) t, sizeof(ev_timer));
+			timer_count++;
+			bubble_last_timer();
+		}
+	}
+
+	memset((void *) &timer_expiring, 0, sizeof(ev_timer));
+
+	duk_pop_2(ctx);  /* -> [ ... ] */
+}
+
+static void compact_poll_list(void) {
+	int i, j, n;
+
+	/* i = input index
+	 * j = output index (initially same as i)
+	 */
+
+	n = poll_count;
+	for (i = 0, j = 0; i < n; i++) {
+		struct pollfd *pfd = poll_list + i;
+		if (pfd->fd == 0) {
+			/* keep output index the same */
+#if 0
+			fprintf(stderr, "remove pollfd (index %d): fd=%d, events=%d, revents=%d\n",
+			        i, pfd->fd, pfd->events, pfd->revents),
+			fflush(stderr);
+#endif
+
+			continue;
+		}
+#if 0
+		fprintf(stderr, "keep pollfd (index %d -> %d): fd=%d, events=%d, revents=%d\n",
+		        i, j, pfd->fd, pfd->events, pfd->revents),
+		fflush(stderr);
+#endif
+		if (i != j) {
+			/* copy only if indices have diverged */
+			memcpy((void *) (poll_list + j), (void *) (poll_list + i), sizeof(struct pollfd));
+		}
+		j++;
+	}
+
+	if (j < poll_count) {
+		/* zeroize unused entries for sanity */
+		memset((void *) (poll_list + j), 0, (poll_count - j) * sizeof(struct pollfd));
+	}
+
+	poll_count = j;
+}
+
+int eventloop_run(duk_context *ctx) {
+	ev_timer *t;
+	double now;
+	double diff;
+	int timeout;
+	int rc;
+	int i, n;
+	int idx_eventloop;
+	int idx_fd_handler;
+
+	/* The Ecmascript poll handler is passed through EventLoop.fdPollHandler
+	 * which c_eventloop.js sets before we come here.
+	 */
+	duk_push_global_object(ctx);
+	duk_get_prop_string(ctx, -1, "EventLoop");
+	duk_get_prop_string(ctx, -1, "fdPollHandler");  /* -> [ global EventLoop fdPollHandler ] */
+	idx_fd_handler = duk_get_top_index(ctx);
+	idx_eventloop = idx_fd_handler - 1;
+
+	for (;;) {
+		/*
+		 *  Expire timers.
+		 */
+
+		expire_timers(ctx);
+
+		/*
+		 *  If exit requested, bail out as fast as possible.
+		 */
+
+		if (exit_requested) {
+#if 0
+			fprintf(stderr, "exit requested, exiting event loop\n");
+			fflush(stderr);
+#endif
+			break;
+		}
+
+		/*
+		 *  Compact poll list by removing pollfds with fd == 0.
+		 */
+
+		compact_poll_list();
+
+		/*
+		 *  Determine poll() timeout (as close to poll() as possible as
+		 *  the wait is relative).
+		 */
+
+		now = get_now();
+		t = find_nearest_timer();
+		if (t) {
+			diff = t->target - now;
+			if (diff < MIN_WAIT) {
+				diff = MIN_WAIT;
+			} else if (diff > MAX_WAIT) {
+				diff = MAX_WAIT;
+			}
+			timeout = (int) diff;  /* clamping ensures that fits */
+		} else {
+			if (poll_count == 0) {
+#if 0
+				fprintf(stderr, "no timers and no sockets to poll, exiting\n");
+				fflush(stderr);
+#endif
+				break;
+			}
+			timeout = (int) MAX_WAIT;
+		}
+
+		/*
+		 *  Poll for activity or timeout.
+		 */
+
+#if 0
+		fprintf(stderr, "going to poll, timeout %d ms, pollfd count %d\n", timeout, poll_count);
+		fflush(stderr);
+#endif
+
+		rc = poll(poll_list, poll_count, timeout);
+#if 0
+		fprintf(stderr, "poll rc: %d\n", rc);
+		fflush(stderr);
+#endif
+		if (rc < 0) {
+			/* error */
+		} else if (rc == 0) {
+			/* timeout */
+		} else {
+			/* 'rc' fds active */
+		}
+
+		/*
+		 *  Check socket activity, handle all sockets.  Handling is offloaded to
+		 *  Ecmascript code (fd + revents).
+		 *
+		 *  If FDs are removed from the poll list while we're processing callbacks,
+		 *  the entries are simply marked unused (fd set to 0) without actually
+		 *  removing them from the poll list.  This ensures indices are not
+		 *  disturbed.  The poll list is compacted before next poll().
+		 */
+
+		n = (rc == 0 ? 0 : poll_count);  /* if timeout, no need to check pollfd */
+		for (i = 0; i < n; i++) {
+			struct pollfd *pfd = poll_list + i;
+
+			if (pfd->fd == 0) {
+				/* deleted, perhaps by previous callback */
+				continue;
+			}
+
+			if (pfd->revents) {
+#if 0
+				fprintf(stderr, "fd %d has revents: %d\n", (int) pfd->fd, (int) pfd->revents);
+				fflush(stderr);
+#endif
+				duk_dup(ctx, idx_fd_handler);
+				duk_dup(ctx, idx_eventloop);
+				duk_push_int(ctx, pfd->fd);
+				duk_push_int(ctx, pfd->revents);
+				rc = duk_pcall_method(ctx, 2 /*nargs*/);
+				if (rc) {
+#if 0
+					fprintf(stderr, "fd callback failed for fd %d: %s\n", (int) pfd->fd, duk_to_string(ctx, -1));
+					fflush(stderr);
+#endif
+				}
+				duk_pop(ctx);
+
+				pfd->revents = 0;
+			}
+
+		}
+	}
+
+	duk_pop_n(ctx, 3);
+
+	return 0;
+}
+
+static int create_timer(duk_context *ctx) {
+	double delay;
+	int oneshot;
+	int idx;
+	int64_t timer_id;
+	double now;
+	ev_timer *t;
+
+	now = get_now();
+
+	/* indexes:
+	 *   0 = function (callback)
+	 *   1 = delay
+	 *   2 = boolean: oneshot
+	 */
+
+	delay = duk_require_number(ctx, 1);
+	if (delay < MIN_DELAY) {
+		delay = MIN_DELAY;
+	}
+	oneshot = duk_require_boolean(ctx, 2);
+
+	if (timer_count >= MAX_TIMERS) {
+		duk_error(ctx, DUK_ERR_RANGE_ERROR, "out of timer slots");
+	}
+	idx = timer_count++;
+	timer_id = timer_next_id++;
+	t = timer_list + idx;
+
+	memset((void *) t, 0, sizeof(ev_timer));
+	t->id = timer_id;
+	t->target = now + delay;
+	t->delay = delay;
+	t->oneshot = oneshot;
+	t->removed = 0;
+
+	/* Timer is now at the last position; use swaps to "bubble" it to its
+	 * correct sorted position.
+	 */
+
+	bubble_last_timer();
+
+	/* Finally, register the callback to the global stash 'eventTimers' object. */
+
+	duk_push_global_stash(ctx);
+	duk_get_prop_string(ctx, -1, "eventTimers");  /* -> [ func delay oneshot stash eventTimers ] */
+	duk_push_number(ctx, (double) timer_id);
+	duk_dup(ctx, 0);
+	duk_put_prop(ctx, -3);  /* eventTimers[timer_id] = callback */
+
+	/* Return timer id. */
+
+	duk_push_number(ctx, (double) timer_id);
+#if 0
+	fprintf(stderr, "created timer id: %d\n", (int) timer_id);
+	fflush(stderr);
+#endif
+	return 1;
+}
+
+static int delete_timer(duk_context *ctx) {
+	int i, n;
+	int64_t timer_id;
+	ev_timer *t;
+	int found = 0;
+
+	/* indexes:
+	 *   0 = timer id
+	 */
+
+	timer_id = (int64_t) duk_require_number(ctx, 0);
+
+	/*
+	 *  Unlike insertion, deletion needs a full scan of the timer list
+	 *  and an expensive remove.  If no match is found, nothing is deleted.
+	 *  Caller gets a boolean return code indicating match.
+	 *
+	 *  When a timer is being expired and its user callback is running,
+	 *  the timer has been moved to 'timer_expiring' and its deletion
+	 *  needs special handling: just mark it to-be-deleted and let the
+	 *  expiry code remove it.
+	 */
+
+	t = &timer_expiring;
+	if (t->id == timer_id) {
+		t->removed = 1;
+		duk_push_true(ctx);
+#if 0
+		fprintf(stderr, "deleted expiring timer id: %d\n", (int) timer_id);
+		fflush(stderr);
+#endif
+		return 1;
+	}
+
+	n = timer_count;
+	for (i = 0; i < n; i++) {
+		t = timer_list + i;
+		if (t->id == timer_id) {
+			found = 1;
+
+			/* Shift elements downwards to keep the timer list dense
+			 * (no need if last element).
+			 */
+			if (i < timer_count - 1) {
+				memmove((void *) t, (void *) (t + 1), (timer_count - i - 1) * sizeof(ev_timer));
+			}
+
+			/* Zero last element for clarity. */
+			memset((void *) (timer_list + n - 1), 0, sizeof(ev_timer));
+
+			/* Update timer_count. */
+			timer_count--;
+
+			/* The C state is now up-to-date, but we still need to delete
+			 * the timer callback state from the global 'stash'.
+			 */
+
+			duk_push_global_stash(ctx);
+			duk_get_prop_string(ctx, -1, "eventTimers");  /* -> [ timer_id stash eventTimers ] */
+			duk_push_number(ctx, (double) timer_id);
+			duk_del_prop(ctx, -2);  /* delete eventTimers[timer_id] */
+
+#if 0
+			fprintf(stderr, "deleted timer id: %d\n", (int) timer_id);
+			fflush(stderr);
+#endif
+			break;
+		}
+	}
+
+#if 0
+	if (!found) {
+		fprintf(stderr, "trying to delete timer id %d, but not found; ignoring\n", (int) timer_id);
+		fflush(stderr);
+	}
+#endif
+
+	duk_push_boolean(ctx, found);
+	return 1;
+}
+
+static int listen_fd(duk_context *ctx) {
+	int fd = duk_require_int(ctx, 0);
+	int events = duk_require_int(ctx, 1);
+	int i, n;
+	struct pollfd *pfd;
+
+#if 0
+	fprintf(stderr, "listen_fd: fd=%d, events=%d\n", fd, events);
+	fflush(stderr);
+#endif
+	/* events == 0 means stop listening to the FD */
+
+	n = poll_count;
+	for (i = 0; i < n; i++) {
+		pfd = poll_list + i;
+		if (pfd->fd == fd) {
+#if 0
+			fprintf(stderr, "listen_fd: fd found at index %d\n", i);
+			fflush(stderr);
+#endif
+			if (events == 0) {
+				/* mark to-be-deleted, cleaned up by next poll */
+				pfd->fd = 0;
+			} else {
+				pfd->events = events;
+			}
+			return 0;
+		}
+	}
+
+	/* not found, append to list */
+#if 0
+	fprintf(stderr, "listen_fd: fd not found on list, add new entry\n");
+	fflush(stderr);
+#endif
+
+	if (poll_count >= MAX_FDS) {
+		duk_error(ctx, DUK_ERR_ERROR, "out of fd slots");
+	}
+
+	pfd = poll_list + poll_count;
+	pfd->fd = fd;
+	pfd->events = events;
+	pfd->revents = 0;
+	poll_count++;
+
+	return 0;
+}
+
+static int request_exit(duk_context *ctx) {
+	(void) ctx;
+	exit_requested = 1;
+	return 0;
+}
+
+static duk_function_list_entry eventloop_funcs[] = {
+	{ "createTimer", create_timer, 3 },
+	{ "deleteTimer", delete_timer, 1 },
+	{ "listenFd", listen_fd, 2 },
+	{ "requestExit", request_exit, 0 },
+	{ NULL, NULL, 0 }
+};
+
+void eventloop_register(duk_context *ctx) {
+	memset((void *) timer_list, 0, MAX_TIMERS * sizeof(ev_timer));
+	memset((void *) &timer_expiring, 0, sizeof(ev_timer));
+	memset((void *) poll_list, 0, MAX_FDS * sizeof(struct pollfd));
+
+	/* Set global 'EventLoop'. */
+	duk_push_global_object(ctx);
+	duk_push_object(ctx);
+	duk_put_function_list(ctx, -1, eventloop_funcs);
+	duk_put_prop_string(ctx, -2, "EventLoop");
+	duk_pop(ctx);
+
+	/* Initialize global stash 'eventTimers'. */
+	duk_push_global_stash(ctx);
+	duk_push_object(ctx);
+	duk_put_prop_string(ctx, -2, "eventTimers");
+	duk_pop(ctx);
+}

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/eventloop/c_eventloop.js
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/eventloop/c_eventloop.js b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/eventloop/c_eventloop.js
new file mode 100644
index 0000000..b9e2d63
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/eventloop/c_eventloop.js
@@ -0,0 +1,179 @@
+/*
+ *  C eventloop example (c_eventloop.c).
+ *
+ *  Ecmascript code to initialize the exposed API (setTimeout() etc) when
+ *  using the C eventloop.
+ *
+ *  https://developer.mozilla.org/en-US/docs/Web/JavaScript/Timers
+ */
+
+/*
+ *  Timer API
+ */
+
+function setTimeout(func, delay) {
+    var cb_func;
+    var bind_args;
+    var timer_id;
+
+    if (typeof delay !== 'number') {
+        throw new TypeError('delay is not a number');
+    }
+
+    if (typeof func === 'string') {
+        // Legacy case: callback is a string.
+        cb_func = eval.bind(this, func);
+    } else if (typeof func !== 'function') {
+        throw new TypeError('callback is not a function/string');
+    } else if (arguments.length > 2) {
+        // Special case: callback arguments are provided.
+        bind_args = Array.prototype.slice.call(arguments, 2);  // [ arg1, arg2, ... ]
+        bind_args.unshift(this);  // [ global(this), arg1, arg2, ... ]
+        cb_func = func.bind.apply(func, bind_args);
+    } else {
+        // Normal case: callback given as a function without arguments.
+        cb_func = func;
+    }
+
+    timer_id = EventLoop.createTimer(cb_func, delay, true /*oneshot*/);
+
+    return timer_id;
+}
+
+function clearTimeout(timer_id) {
+    if (typeof timer_id !== 'number') {
+        throw new TypeError('timer ID is not a number');
+    }
+    var success = EventLoop.deleteTimer(timer_id);  /* retval ignored */
+}
+
+function setInterval(func, delay) {
+    var cb_func;
+    var bind_args;
+    var timer_id;
+
+    if (typeof delay !== 'number') {
+        throw new TypeError('delay is not a number');
+    }
+
+    if (typeof func === 'string') {
+        // Legacy case: callback is a string.
+        cb_func = eval.bind(this, func);
+    } else if (typeof func !== 'function') {
+        throw new TypeError('callback is not a function/string');
+    } else if (arguments.length > 2) {
+        // Special case: callback arguments are provided.
+        bind_args = Array.prototype.slice.call(arguments, 2);  // [ arg1, arg2, ... ]
+        bind_args.unshift(this);  // [ global(this), arg1, arg2, ... ]
+        cb_func = func.bind.apply(func, bind_args);
+    } else {
+        // Normal case: callback given as a function without arguments.
+        cb_func = func;
+    }
+
+    timer_id = EventLoop.createTimer(cb_func, delay, false /*oneshot*/);
+
+    return timer_id;
+}
+
+function clearInterval(timer_id) {
+    if (typeof timer_id !== 'number') {
+        throw new TypeError('timer ID is not a number');
+    }
+    EventLoop.deleteTimer(timer_id);
+}
+
+function requestEventLoopExit() {
+    EventLoop.requestExit();
+}
+
+/*
+ *  Socket handling
+ *
+ *  Ideally this would be implemented more in C than here for more speed
+ *  and smaller footprint: C code would directly maintain the callback state
+ *  and such.
+ *
+ *  Also for more optimal I/O, the buffer churn caused by allocating and
+ *  freeing a lot of buffer values could be eliminated by reusing buffers.
+ *  Socket reads would then go into a pre-allocated buffer, for instance.
+ */
+
+EventLoop.socketListening = {};
+EventLoop.socketReading = {};
+EventLoop.socketConnecting = {};
+
+EventLoop.fdPollHandler = function(fd, revents) {
+    var data;
+    var cb;
+    var rc;
+    var acc_res;
+
+    //print('activity on fd', fd, 'revents', revents);
+
+    if (revents & Poll.POLLIN) {
+        cb = this.socketReading[fd];
+        if (cb) {
+            data = Socket.read(fd);  // no size control now
+            //print('READ', Duktape.enc('jx', data));
+            if (data.length === 0) {
+                this.close(fd);
+                return;
+            }
+            cb(fd, data);
+        } else {
+            cb = this.socketListening[fd];
+            if (cb) {
+                acc_res = Socket.accept(fd);
+                //print('ACCEPT:', Duktape.enc('jx', acc_res));
+                cb(acc_res.fd, acc_res.addr, acc_res.port);
+            } else {
+                //print('UNKNOWN');
+            }
+        }
+    }
+
+    if (revents & Poll.POLLOUT) {
+        // Connected
+        cb = this.socketConnecting[fd];
+        if (cb) {
+            delete this.socketConnecting[fd];
+            cb(fd);
+        }
+    }
+
+    if ((revents & ~(Poll.POLLIN | Poll.POLLOUT)) !== 0) {
+        //print('unexpected revents, close fd');
+        this.close(fd);
+    }
+}
+
+EventLoop.server = function(address, port, cb_accepted) {
+    var fd = Socket.createServerSocket(address, port);
+    this.socketListening[fd] = cb_accepted;
+    this.listenFd(fd, Poll.POLLIN);
+}
+
+EventLoop.connect = function(address, port, cb_connected) {
+    var fd = Socket.connect(address, port);
+    this.socketConnecting[fd] = cb_connected;
+    this.listenFd(fd, Poll.POLLOUT);
+}
+
+EventLoop.close = function(fd) {
+    EventLoop.listenFd(fd, 0);
+    delete this.socketListening[fd];
+    delete this.socketReading[fd];
+    delete this.socketConnecting[fd];
+    Socket.close(fd);
+}
+
+EventLoop.setReader = function(fd, cb_read) {
+    this.socketReading[fd] = cb_read;
+    this.listenFd(fd, Poll.POLLIN);
+}
+
+EventLoop.write = function(fd, data) {
+    // This simple example doesn't have support for write blocking / draining
+    var rc = Socket.write(fd, Duktape.Buffer(data));
+}

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/eventloop/client-socket-test.js
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/eventloop/client-socket-test.js b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/eventloop/client-socket-test.js
new file mode 100644
index 0000000..ff87784
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/eventloop/client-socket-test.js
@@ -0,0 +1,24 @@
+
+var HOST = 'localhost';
+var PORT = 80;
+var EXIT_TIMEOUT = 300e3;
+
+print('automatic exit after ' + (EXIT_TIMEOUT / 1e3) + ' seconds');
+setTimeout(function () {
+    print('exit timer');
+    EventLoop.requestExit();
+}, EXIT_TIMEOUT);
+
+EventLoop.connect(HOST, PORT, function (fd) {
+    print('connected to ' + HOST + ':' + PORT + ', fd', fd);
+    EventLoop.setReader(fd, function (fd, data) {
+        print('read from fd', fd);
+        print(data);
+        EventLoop.close(fd);
+    });
+    EventLoop.write(fd, "GET / HTTP/1.1\r\n" +
+                        "Host: " + HOST + "\r\n" +
+                        "User-Agent: client-socket-test.js\r\n" +
+                        "\r\n");
+});
+

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/eventloop/curses-timers.js
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/eventloop/curses-timers.js b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/eventloop/curses-timers.js
new file mode 100644
index 0000000..4508665
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/eventloop/curses-timers.js
@@ -0,0 +1,79 @@
+/*
+ *  Test using timers and intervals with curses.
+ */
+
+if (typeof Ncurses !== 'object') {
+    throw new Error('Ncurses required');
+}
+
+function fillScreen(ch) {
+    var size, w, h;
+    var i, j;
+
+    size = Ncurses.getmaxyx();
+    h = size[0];
+    w = size[1];
+
+    for (i = 0; i < h; i++) {
+        for (j = 0; j < w; j++) {
+            Ncurses.mvprintw(i, j, ch);
+        }
+    }
+    Ncurses.refresh();
+}
+
+function main() {
+    var i, j;
+    var counters = [];
+    var size, w, h;
+
+    Ncurses.initscr();
+    size = Ncurses.getmaxyx();
+    h = size[0];
+    w = size[1];
+
+    fillScreen('.');
+
+    setInterval(function () {
+        Ncurses.mvprintw(1, 4, new Date().toISOString());
+        Ncurses.refresh();
+    }, 1000);
+
+    function addCounter(row, index, interval) {
+        counters[index] = 0;
+        setInterval(function () {
+            counters[index]++;
+            Ncurses.mvprintw(row, 4, '' + Date.now() + ' ' + counters[index]);
+            Ncurses.refresh();
+        }, interval);
+    }
+
+    function addRandomChar(row, col, interval) {
+        setTimeout(function () {
+            Ncurses.mvprintw(row, col, String.fromCharCode(Math.random() * 64 + 0x20));
+            Ncurses.refresh();
+        }, interval);
+    }
+
+    for (i = 0; i < h - 5; i++) {
+        addCounter(3 + i, i, 363 * i + 400);
+    }
+
+    /* Here the inserts take a lot of time because the underlying timer manager
+     * data structure has O(n) insertion performance.
+     */
+    for (i = 0; i < h - 5; i++) {
+        for (j = 0; j < w - 50; j++) {
+            // Math.exp(0)...Math.exp(8) is an uneven distribution between 1...~2980.
+            addRandomChar(3 + i, 28 + j, 58000 - Math.exp(Math.random() * 8) * 20);
+        }
+    }
+
+    setTimeout(function () {
+        Ncurses.endwin();
+        Ncurses.delscreen();
+        requestEventLoopExit();
+    }, 120e3);
+}
+
+main();

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/eventloop/ecma_eventloop.js
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/eventloop/ecma_eventloop.js b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/eventloop/ecma_eventloop.js
new file mode 100644
index 0000000..bad4e4d
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/eventloop/ecma_eventloop.js
@@ -0,0 +1,466 @@
+/*
+ *  Pure Ecmascript eventloop example.
+ *
+ *  Timer state handling is inefficient in this trivial example.  Timers are
+ *  kept in an array sorted by their expiry time which works well for expiring
+ *  timers, but has O(n) insertion performance.  A better implementation would
+ *  use a heap or some other efficient structure for managing timers so that
+ *  all operations (insert, remove, get nearest timer) have good performance.
+ *
+ *  https://developer.mozilla.org/en-US/docs/Web/JavaScript/Timers
+ */
+
+/*
+ *  Event loop
+ *
+ *  Timers are sorted by 'target' property which indicates expiry time of
+ *  the timer.  The timer expiring next is last in the array, so that
+ *  removals happen at the end, and inserts for timers expiring in the
+ *  near future displace as few elements in the array as possible.
+ */
+
+EventLoop = {
+    // timers
+    timers: [],         // active timers, sorted (nearest expiry last)
+    expiring: null,     // set to timer being expired (needs special handling in clearTimeout/clearInterval)
+    nextTimerId: 1,
+    minimumDelay: 1,
+    minimumWait: 1,
+    maximumWait: 60000,
+    maxExpirys: 10,
+
+    // sockets
+    socketListening: {},  // fd -> callback
+    socketReading: {},    // fd -> callback
+    socketConnecting: {}, // fd -> callback
+
+    // misc
+    exitRequested: false
+};
+
+EventLoop.dumpState = function() {
+    print('TIMER STATE:');
+    this.timers.forEach(function(t) {
+        print('    ' + Duktape.enc('jx', t));
+    });
+    if (this.expiring) {
+        print('    EXPIRING: ' + Duktape.enc('jx', this.expiring));
+    }
+}
+
+// Get timer with lowest expiry time.  Since the active timers list is
+// sorted, it's always the last timer.
+EventLoop.getEarliestTimer = function() {
+    var timers = this.timers;
+    n = timers.length;
+    return (n > 0 ? timers[n - 1] : null);
+}
+
+EventLoop.getEarliestWait = function() {
+    var t = this.getEarliestTimer();
+    return (t ? t.target - Date.now() : null);
+}
+
+EventLoop.insertTimer = function(timer) {
+    var timers = this.timers;
+    var i, n, t;
+
+    /*
+     *  Find 'i' such that we want to insert *after* timers[i] at index i+1.
+     *  If no such timer, for-loop terminates with i-1, and we insert at -1+1=0.
+     */
+
+    n = timers.length;
+    for (i = n - 1; i >= 0; i--) {
+        t = timers[i];
+        if (timer.target <= t.target) {
+            // insert after 't', to index i+1
+            break;
+        }
+    }
+
+    timers.splice(i + 1 /*start*/, 0 /*deleteCount*/, timer);
+}
+
+// Remove timer/interval with a timer ID.  The timer/interval can reside
+// either on the active list or it may be an expired timer (this.expiring)
+// whose user callback we're running when this function gets called.
+EventLoop.removeTimerById = function(timer_id) {
+    var timers = this.timers;
+    var i, n, t;
+
+    t = this.expiring;
+    if (t) {
+        if (t.id === timer_id) {
+            // Timer has expired and we're processing its callback.  User
+            // callback has requested timer deletion.  Mark removed, so
+            // that the timer is not reinserted back into the active list.
+            // This is actually a common case because an interval may very
+            // well cancel itself.
+            t.removed = true;
+            return;
+        }
+    }
+
+    n = timers.length;
+    for (i = 0; i < n; i++) {
+        t = timers[i];
+        if (t.id === timer_id) {
+            // Timer on active list: mark removed (not really necessary, but
+            // nice for dumping), and remove from active list.
+            t.removed = true;
+            this.timers.splice(i /*start*/, 1 /*deleteCount*/);
+            return;
+        }
+    }
+
+   // no such ID, ignore
+}
+
+EventLoop.processTimers = function() {
+    var now = Date.now();
+    var timers = this.timers;
+    var sanity = this.maxExpirys;
+    var n, t;
+
+    /*
+     *  Here we must be careful with mutations: user callback may add and
+     *  delete an arbitrary number of timers.
+     *
+     *  Current solution is simple: check whether the timer at the end of
+     *  the list has expired.  If not, we're done.  If it has expired,
+     *  remove it from the active list, record it in this.expiring, and call
+     *  the user callback.  If user code deletes the this.expiring timer,
+     *  there is special handling which just marks the timer deleted so
+     *  it won't get inserted back into the active list.
+     *
+     *  This process is repeated at most maxExpirys times to ensure we don't
+     *  get stuck forever; user code could in principle add more and more
+     *  already expired timers.
+     */
+
+    while (sanity-- > 0) {
+        // If exit requested, don't call any more callbacks.  This allows
+        // a callback to do cleanups and request exit, and can be sure that
+        // no more callbacks are processed.
+
+        if (this.exitRequested) {
+            //print('exit requested, exit');
+            break;
+        }
+
+        // Timers to expire?
+
+        n = timers.length;
+        if (n <= 0) {
+            break;
+        }
+        t = timers[n - 1];
+        if (now <= t.target) {
+            // Timer has not expired, and no other timer could have expired
+            // either because the list is sorted.
+            break;
+        }
+        timers.pop();
+
+        // Remove the timer from the active list and process it.  The user
+        // callback may add new timers which is not a problem.  The callback
+        // may also delete timers which is not a problem unless the timer
+        // being deleted is the timer whose callback we're running; this is
+        // why the timer is recorded in this.expiring so that clearTimeout()
+        // and clearInterval() can detect this situation.
+
+        if (t.oneshot) {
+            t.removed = true;  // flag for removal
+        } else {
+            t.target = now + t.delay;
+        }
+        this.expiring = t;
+        try {
+            t.cb();
+        } catch (e) {
+            print('timer callback failed, ignored: ' + e);
+        }
+        this.expiring = null;
+
+        // If the timer was one-shot, it's marked 'removed'.  If the user callback
+        // requested deletion for the timer, it's also marked 'removed'.  If the
+        // timer is an interval (and is not marked removed), insert it back into
+        // the timer list.
+
+        if (!t.removed) {
+            // Reinsert interval timer to correct sorted position.  The timer
+            // must be an interval timer because one-shot timers are marked
+            // 'removed' above.
+            this.insertTimer(t);
+        }
+    }
+}
+
+EventLoop.run = function() {
+    var wait;
+    var POLLIN = Poll.POLLIN;
+    var POLLOUT = Poll.POLLOUT;
+    var poll_set;
+    var poll_count;
+    var fd;
+    var t, rev;
+    var rc;
+    var acc_res;
+
+    for (;;) {
+        /*
+         *  Process expired timers.
+         */
+
+        this.processTimers();
+        //this.dumpState();
+
+        /*
+         *  Exit check (may be requested by a user callback)
+         */
+
+        if (this.exitRequested) {
+            //print('exit requested, exit');
+            break;
+        }
+
+        /*
+         *  Create poll socket list.  This is a very naive approach.
+         *  On Linux, one could use e.g. epoll() and manage socket lists
+         *  incrementally.
+         */
+
+        poll_set = {};
+        poll_count = 0;
+        for (fd in this.socketListening) {
+            poll_set[fd] = { events: POLLIN, revents: 0 };
+            poll_count++;
+        }
+        for (fd in this.socketReading) {
+            poll_set[fd] = { events: POLLIN, revents: 0 };
+            poll_count++;
+        }
+        for (fd in this.socketConnecting) {
+            poll_set[fd] = { events: POLLOUT, revents: 0 };
+            poll_count++;
+        }
+        //print(new Date(), 'poll_set IN:', Duktape.enc('jx', poll_set));
+
+        /*
+         *  Wait timeout for timer closest to expiry.  Since the poll
+         *  timeout is relative, get this as close to poll() as possible.
+         */
+
+        wait = this.getEarliestWait();
+        if (wait === null) {
+            if (poll_count === 0) {
+                print('no active timers and no sockets to poll, exit');
+                break;
+            } else {
+                wait = this.maximumWait;
+            }
+        } else {
+            wait = Math.min(this.maximumWait, Math.max(this.minimumWait, wait));
+        }
+
+        /*
+         *  Do the actual poll.
+         */
+
+        try {
+            Poll.poll(poll_set, wait);
+        } catch (e) {
+            // Eat errors silently.  When resizing curses window an EINTR
+            // happens now.
+        }
+
+        /*
+         *  Process all sockets so that nothing is left unhandled for the
+         *  next round.
+         */
+
+        //print(new Date(), 'poll_set OUT:', Duktape.enc('jx', poll_set));
+        for (fd in poll_set) {
+            t = poll_set[fd];
+            rev = t.revents;
+
+            if (rev & POLLIN) {
+                cb = this.socketReading[fd];
+                if (cb) {
+                    data = Socket.read(fd);  // no size control now
+                    //print('READ', Duktape.enc('jx', data));
+                    if (data.length === 0) {
+                        //print('zero read for fd ' + fd + ', closing forcibly');
+                        rc = Socket.close(fd);  // ignore result
+                        delete this.socketListening[fd];
+                        delete this.socketReading[fd];
+                    } else {
+                        cb(fd, data);
+                    }
+                } else {
+                    cb = this.socketListening[fd];
+                    if (cb) {
+                        acc_res = Socket.accept(fd);
+                        //print('ACCEPT:', Duktape.enc('jx', acc_res));
+                        cb(acc_res.fd, acc_res.addr, acc_res.port);
+                    } else {
+                        //print('UNKNOWN');
+                    }
+                }
+            }
+
+            if (rev & POLLOUT) {
+                cb = this.socketConnecting[fd];
+                if (cb) {
+                    delete this.socketConnecting[fd];
+                    cb(fd);
+                } else {
+                    //print('UNKNOWN POLLOUT');
+                }
+            }
+
+            if ((rev & ~(POLLIN | POLLOUT)) !== 0) {
+                //print('revents ' + t.revents + ' for fd ' + fd + ', closing forcibly');
+                rc = Socket.close(fd);  // ignore result
+                delete this.socketListening[fd];
+                delete this.socketReading[fd];
+            }
+        }
+    }
+}
+
+EventLoop.requestExit = function() {
+    this.exitRequested = true;
+}
+
+EventLoop.server = function(address, port, cb_accepted) {
+    var fd = Socket.createServerSocket(address, port);
+    this.socketListening[fd] = cb_accepted;
+}
+
+EventLoop.connect = function(address, port, cb_connected) {
+    var fd = Socket.connect(address, port);
+    this.socketConnecting[fd] = cb_connected;
+}
+
+EventLoop.close = function(fd) {
+    delete this.socketReading[fd];
+    delete this.socketListening[fd];
+}
+
+EventLoop.setReader = function(fd, cb_read) {
+    this.socketReading[fd] = cb_read;
+}
+
+EventLoop.write = function(fd, data) {
+    // This simple example doesn't have support for write blocking / draining
+    var rc = Socket.write(fd, Duktape.Buffer(data));
+}
+
+/*
+ *  Timer API
+ *
+ *  These interface with the singleton EventLoop.
+ */
+
+function setTimeout(func, delay) {
+    var cb_func;
+    var bind_args;
+    var timer_id;
+    var evloop = EventLoop;
+
+    if (typeof delay !== 'number') {
+        throw new TypeError('delay is not a number');
+    }
+    delay = Math.max(evloop.minimumDelay, delay);
+
+    if (typeof func === 'string') {
+        // Legacy case: callback is a string.
+        cb_func = eval.bind(this, func);
+    } else if (typeof func !== 'function') {
+        throw new TypeError('callback is not a function/string');
+    } else if (arguments.length > 2) {
+        // Special case: callback arguments are provided.
+        bind_args = Array.prototype.slice.call(arguments, 2);  // [ arg1, arg2, ... ]
+        bind_args.unshift(this);  // [ global(this), arg1, arg2, ... ]
+        cb_func = func.bind.apply(func, bind_args);
+    } else {
+        // Normal case: callback given as a function without arguments.
+        cb_func = func;
+    }
+
+    timer_id = evloop.nextTimerId++;
+
+    evloop.insertTimer({
+        id: timer_id,
+        oneshot: true,
+        cb: cb_func,
+        delay: delay,
+        target: Date.now() + delay
+    });
+
+    return timer_id;
+}
+
+function clearTimeout(timer_id) {
+    var evloop = EventLoop;
+
+    if (typeof timer_id !== 'number') {
+        throw new TypeError('timer ID is not a number');
+    }
+    evloop.removeTimerById(timer_id);
+}
+
+function setInterval(func, delay) {
+    var cb_func;
+    var bind_args;
+    var timer_id;
+    var evloop = EventLoop;
+
+    if (typeof delay !== 'number') {
+        throw new TypeError('delay is not a number');
+    }
+    delay = Math.max(evloop.minimumDelay, delay);
+
+    if (typeof func === 'string') {
+        // Legacy case: callback is a string.
+        cb_func = eval.bind(this, func);
+    } else if (typeof func !== 'function') {
+        throw new TypeError('callback is not a function/string');
+    } else if (arguments.length > 2) {
+        // Special case: callback arguments are provided.
+        bind_args = Array.prototype.slice.call(arguments, 2);  // [ arg1, arg2, ... ]
+        bind_args.unshift(this);  // [ global(this), arg1, arg2, ... ]
+        cb_func = func.bind.apply(func, bind_args);
+    } else {
+        // Normal case: callback given as a function without arguments.
+        cb_func = func;
+    }
+
+    timer_id = evloop.nextTimerId++;
+
+    evloop.insertTimer({
+        id: timer_id,
+        oneshot: false,
+        cb: cb_func,
+        delay: delay,
+        target: Date.now() + delay
+    });
+
+    return timer_id;
+}
+
+function clearInterval(timer_id) {
+    var evloop = EventLoop;
+
+    if (typeof timer_id !== 'number') {
+        throw new TypeError('timer ID is not a number');
+    }
+    evloop.removeTimerById(timer_id);
+}
+
+/* custom call */
+function requestEventLoopExit() {
+    EventLoop.requestExit();
+}

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/eventloop/fileio.c
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/eventloop/fileio.c b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/eventloop/fileio.c
new file mode 100644
index 0000000..df94cd4
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/eventloop/fileio.c
@@ -0,0 +1,69 @@
+/*
+ *  File I/O binding example.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "duktape.h"
+
+static int fileio_readfile(duk_context *ctx) {
+	const char *filename = duk_to_string(ctx, 0);
+	FILE *f = NULL;
+	long len;
+	void *buf;
+	size_t got;
+
+	if (!filename) {
+		goto error;
+	}
+
+	f = fopen(filename, "rb");
+	if (!f) {
+		goto error;
+	}
+
+	if (fseek(f, 0, SEEK_END) != 0) {
+		goto error;
+	}
+
+	len = ftell(f);
+
+	if (fseek(f, 0, SEEK_SET) != 0) {
+		goto error;
+	}
+
+	buf = duk_push_fixed_buffer(ctx, (size_t) len);
+
+	got = fread(buf, 1, len, f);
+	if (got != (size_t) len) {
+		goto error;
+	}
+
+	fclose(f);
+	f = NULL;
+
+	return 1;
+
+ error:
+	if (f) {
+		fclose(f);
+	}
+
+	return DUK_RET_ERROR;
+}
+
+static duk_function_list_entry fileio_funcs[] = {
+	{ "readfile", fileio_readfile, 1 },
+	{ NULL, NULL, 0 }
+};
+
+void fileio_register(duk_context *ctx) {
+	/* Set global 'FileIo'. */
+	duk_push_global_object(ctx);
+	duk_push_object(ctx);
+	duk_put_function_list(ctx, -1, fileio_funcs);
+	duk_put_prop_string(ctx, -2, "FileIo");
+	duk_pop(ctx);
+}

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/eventloop/main.c
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/eventloop/main.c b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/eventloop/main.c
new file mode 100644
index 0000000..7627921
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/eventloop/main.c
@@ -0,0 +1,256 @@
+/*
+ *  Main for evloop command line tool.
+ *
+ *  Runs a given script from file or stdin inside an eventloop.  The
+ *  script can then access setTimeout() etc.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#ifndef NO_SIGNAL
+#include <signal.h>
+#endif
+
+#include "duktape.h"
+
+extern void poll_register(duk_context *ctx);
+extern void ncurses_register(duk_context *ctx);
+extern void socket_register(duk_context *ctx);
+extern void fileio_register(duk_context *ctx);
+extern void eventloop_register(duk_context *ctx);
+extern int eventloop_run(duk_context *ctx);  /* Duktape/C function, safe called */
+
+static int c_evloop = 0;
+
+#ifndef NO_SIGNAL
+static void my_sighandler(int x) {
+	fprintf(stderr, "Got signal %d\n", x);
+	fflush(stderr);
+}
+static void set_sigint_handler(void) {
+	(void) signal(SIGINT, my_sighandler);
+}
+#endif  /* NO_SIGNAL */
+
+/* Print error to stderr and pop error. */
+static void print_error(duk_context *ctx, FILE *f) {
+	if (duk_is_object(ctx, -1) && duk_has_prop_string(ctx, -1, "stack")) {
+		/* XXX: print error objects specially */
+		/* XXX: pcall the string coercion */
+		duk_get_prop_string(ctx, -1, "stack");
+		if (duk_is_string(ctx, -1)) {
+			fprintf(f, "%s\n", duk_get_string(ctx, -1));
+			fflush(f);
+			duk_pop_2(ctx);
+			return;
+		} else {
+			duk_pop(ctx);
+		}
+	}
+	duk_to_string(ctx, -1);
+	fprintf(f, "%s\n", duk_get_string(ctx, -1));
+	fflush(f);
+	duk_pop(ctx);
+}
+
+int wrapped_compile_execute(duk_context *ctx) {
+	int comp_flags = 0;
+	int rc;
+
+	/* Compile input and place it into global _USERCODE */
+	duk_compile(ctx, comp_flags);
+	duk_push_global_object(ctx);
+	duk_insert(ctx, -2);  /* [ ... global func ] */
+	duk_put_prop_string(ctx, -2, "_USERCODE");
+	duk_pop(ctx);
+#if 0
+	printf("compiled usercode\n");
+#endif
+
+	/* Start a zero timer which will call _USERCODE from within
+	 * the event loop.
+	 */
+	fprintf(stderr, "set _USERCODE timer\n");
+	fflush(stderr);
+	duk_eval_string(ctx, "setTimeout(function() { _USERCODE(); }, 0);");
+	duk_pop(ctx);
+
+	/* Finally, launch eventloop.  This call only returns after the
+	 * eventloop terminates.
+	 */
+	if (c_evloop) {
+		fprintf(stderr, "calling eventloop_run()\n");
+		fflush(stderr);
+		rc = duk_safe_call(ctx, eventloop_run, 0 /*nargs*/, 1 /*nrets*/);
+		if (rc != 0) {
+			fprintf(stderr, "eventloop_run() failed: %s\n", duk_to_string(ctx, -1));
+			fflush(stderr);
+		}
+		duk_pop(ctx);
+	} else {
+		fprintf(stderr, "calling EventLoop.run()\n");
+		fflush(stderr);
+		duk_eval_string(ctx, "EventLoop.run();");
+		duk_pop(ctx);
+	}
+
+	return 0;
+}
+
+int handle_fh(duk_context *ctx, FILE *f, const char *filename) {
+	char *buf = NULL;
+	int len;
+	int got;
+	int rc;
+	int retval = -1;
+
+	if (fseek(f, 0, SEEK_END) < 0) {
+		goto error;
+	}
+	len = (int) ftell(f);
+	if (fseek(f, 0, SEEK_SET) < 0) {
+		goto error;
+	}
+	buf = (char *) malloc(len);
+	if (!buf) {
+		goto error;
+	}
+
+	got = fread((void *) buf, (size_t) 1, (size_t) len, f);
+
+	duk_push_lstring(ctx, buf, got);
+	duk_push_string(ctx, filename);
+
+	free(buf);
+	buf = NULL;
+
+	rc = duk_safe_call(ctx, wrapped_compile_execute, 2 /*nargs*/, 1 /*nret*/);
+	if (rc != DUK_EXEC_SUCCESS) {
+		print_error(ctx, stderr);
+		goto error;
+	} else {
+		duk_pop(ctx);
+		retval = 0;
+	}
+	/* fall thru */
+
+ error:
+	if (buf) {
+		free(buf);
+	}
+	return retval;
+}
+
+int handle_file(duk_context *ctx, const char *filename) {
+	FILE *f = NULL;
+	int retval;
+
+	f = fopen(filename, "rb");
+	if (!f) {
+		fprintf(stderr, "failed to open source file: %s\n", filename);
+		fflush(stderr);
+		goto error;
+	}
+
+	retval = handle_fh(ctx, f, filename);
+
+	fclose(f);
+	return retval;
+
+ error:
+	return -1;
+}
+
+int handle_stdin(duk_context *ctx) {
+	int retval;
+
+	retval = handle_fh(ctx, stdin, "stdin");
+
+	return retval;
+}
+
+int main(int argc, char *argv[]) {
+	duk_context *ctx = NULL;
+	int retval = 0;
+	const char *filename = NULL;
+	int i;
+
+#ifndef NO_SIGNAL
+	set_sigint_handler();
+
+	/* This is useful at the global level; libraries should avoid SIGPIPE though */
+	/*signal(SIGPIPE, SIG_IGN);*/
+#endif
+
+	for (i = 1; i < argc; i++) {
+		char *arg = argv[i];
+		if (!arg) {
+			goto usage;
+		}
+		if (strcmp(arg, "-c") == 0) {
+			c_evloop = 1;
+		} else if (strlen(arg) > 1 && arg[0] == '-') {
+			goto usage;
+		} else {
+			if (filename) {
+				goto usage;
+			}
+			filename = arg;
+		}
+	}
+	if (!filename) {
+		goto usage;
+	}
+
+	ctx = duk_create_heap_default();
+
+	poll_register(ctx);
+	ncurses_register(ctx);
+	socket_register(ctx);
+	fileio_register(ctx);
+
+	if (c_evloop) {
+		fprintf(stderr, "Using C based eventloop (omit -c to use Ecmascript based eventloop)\n");
+		fflush(stderr);
+
+		eventloop_register(ctx);
+		duk_eval_file(ctx, "c_eventloop.js");
+	} else {
+		fprintf(stderr, "Using Ecmascript based eventloop (give -c to use C based eventloop)\n");
+		fflush(stderr);
+
+		duk_eval_file(ctx, "ecma_eventloop.js");
+	}
+
+	fprintf(stderr, "Executing code from: '%s'\n", filename);
+	fflush(stderr);
+
+	if (strcmp(filename, "-") == 0) {
+		if (handle_stdin(ctx) != 0) {
+			retval = 1;
+			goto cleanup;
+		}
+	} else {
+		if (handle_file(ctx, filename) != 0) {
+			retval = 1;
+			goto cleanup;
+		}
+	}
+
+ cleanup:
+	if (ctx) {
+		duk_destroy_heap(ctx);
+	}
+
+	return retval;
+
+ usage:
+	fprintf(stderr, "Usage: evloop [-c] <filename>\n");
+	fprintf(stderr, "\n");
+	fprintf(stderr, "Uses an Ecmascript based eventloop (ecma_eventloop.js) by default.\n");
+	fprintf(stderr, "If -c option given, uses a C based eventloop (c_eventloop.{c,js}).\n");
+	fprintf(stderr, "If <filename> is '-', the entire STDIN executed.\n");
+	fflush(stderr);
+	exit(1);
+}

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/eventloop/ncurses.c
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/eventloop/ncurses.c b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/eventloop/ncurses.c
new file mode 100644
index 0000000..7734fcc
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/eventloop/ncurses.c
@@ -0,0 +1,105 @@
+/*
+ *  Ncurses bindings example.
+ *
+ *  VALGRIND NOTE: when you use ncurses, there seems to be no way to get a
+ *  clean valgrind run.  Even if ncurses state is properly shut down, there
+ *  will still be some residual leaks.
+ *
+ *  Debian: install libncurses5-dev
+ */
+
+#include <curses.h>
+#include "duktape.h"
+
+static int ncurses_initscr(duk_context *ctx) {
+	WINDOW *win;
+
+	win = initscr();
+	duk_push_pointer(ctx, (void *) win);
+	return 1;
+}
+
+static int ncurses_endwin(duk_context *ctx) {
+	int rc;
+
+	rc = endwin();
+	duk_push_int(ctx, rc);
+	return 1;
+}
+
+static int ncurses_delscreen(duk_context *ctx) {
+	/* XXX: no screen management now */
+	(void) ctx;
+	return 0;
+}
+
+static int ncurses_getmaxyx(duk_context *ctx) {
+	int row, col;
+
+	getmaxyx(stdscr, row, col);
+
+	duk_push_array(ctx);
+	duk_push_int(ctx, row);
+	duk_put_prop_index(ctx, -2, 0);
+	duk_push_int(ctx, col);
+	duk_put_prop_index(ctx, -2, 1);
+	return 1;
+}
+
+static int ncurses_printw(duk_context *ctx) {
+	int rc;
+	const char *str;
+
+	str = duk_to_string(ctx, 0);
+	rc = printw("%s", str);
+	duk_push_int(ctx, rc);
+	return 1;
+}
+
+static int ncurses_mvprintw(duk_context *ctx) {
+	int y = duk_to_int(ctx, 0);
+	int x = duk_to_int(ctx, 1);
+	const char *str = duk_to_string(ctx, 2);
+	int rc;
+
+	rc = mvprintw(y, x, "%s", str);
+	duk_push_int(ctx, rc);
+	return 1;
+}
+
+static int ncurses_refresh(duk_context *ctx) {
+	int rc;
+
+	rc = refresh();
+	duk_push_int(ctx, rc);
+	return 1;
+}
+
+static int ncurses_getch(duk_context *ctx) {
+	int rc;
+
+	rc = getch();
+	duk_push_int(ctx, rc);
+	return 1;
+}
+
+static duk_function_list_entry ncurses_funcs[] = {
+	{ "initscr", ncurses_initscr, 0 },
+	{ "endwin", ncurses_endwin, 0 },
+	{ "delscreen", ncurses_delscreen, 0 },
+	{ "getmaxyx", ncurses_getmaxyx, 0 },
+	{ "printw", ncurses_printw, 1 },
+	{ "mvprintw", ncurses_mvprintw, 3 },
+	{ "refresh", ncurses_refresh, 0 },
+	{ "getch", ncurses_getch, 0 },
+	{ NULL, NULL, 0 }
+};
+
+void ncurses_register(duk_context *ctx) {
+	/* Set global 'Ncurses'. */
+	duk_push_global_object(ctx);
+	duk_push_object(ctx);
+	duk_put_function_list(ctx, -1, ncurses_funcs);
+	duk_put_prop_string(ctx, -2, "Ncurses");
+	duk_pop(ctx);
+}

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/eventloop/poll.c
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/eventloop/poll.c b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/eventloop/poll.c
new file mode 100644
index 0000000..c78745d
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/eventloop/poll.c
@@ -0,0 +1,111 @@
+/*
+ *  C wrapper for poll().
+ */
+
+#define _GNU_SOURCE
+#include <errno.h>
+#include <string.h>
+#include <stdio.h>
+#include <poll.h>
+#include <time.h>
+
+#include "duktape.h"
+
+static int poll_poll(duk_context *ctx) {
+	int timeout = duk_to_int(ctx, 1);
+	int i, n, nchanged;
+	int fd, rc;
+	struct pollfd fds[20];
+	struct timespec ts;
+
+	memset(fds, 0, sizeof(fds));
+
+	n = 0;
+	duk_enum(ctx, 0, 0 /*enum_flags*/);
+	while (duk_next(ctx, -1, 0)) {
+		if ((size_t) n >= sizeof(fds) / sizeof(struct pollfd)) {
+			return -1;
+		}
+
+		/* [... enum key] */
+		duk_dup_top(ctx);  /* -> [... enum key key] */
+		duk_get_prop(ctx, 0);  /* -> [... enum key val] */
+		fd = duk_to_int(ctx, -2);
+
+		duk_push_string(ctx, "events");
+		duk_get_prop(ctx, -2);  /* -> [... enum key val events] */
+
+		fds[n].fd = fd;
+		fds[n].events = duk_to_int(ctx, -1);
+		fds[n].revents = 0;
+
+		duk_pop_n(ctx, 3);  /* -> [... enum] */
+
+		n++;
+	}
+	/* leave enum on stack */
+
+	memset(&ts, 0, sizeof(ts));
+	ts.tv_nsec = (timeout % 1000) * 1000000;
+	ts.tv_sec = timeout / 1000;
+
+	/*rc = ppoll(fds, n, &ts, NULL);*/
+	rc = poll(fds, n, timeout);
+	if (rc < 0) {
+		duk_error(ctx, DUK_ERR_ERROR, "%s (errno=%d)", strerror(errno), errno);
+	}
+
+	duk_push_array(ctx);
+	nchanged = 0;
+	for (i = 0; i < n; i++) {
+		/* update revents */
+
+		if (fds[i].revents) {
+			duk_push_int(ctx, fds[i].fd);  /* -> [... retarr fd] */
+			duk_put_prop_index(ctx, -2, nchanged);
+			nchanged++;
+		}
+
+		duk_push_int(ctx, fds[i].fd);  /* -> [... retarr key] */
+		duk_get_prop(ctx, 0);  /* -> [... retarr val] */
+		duk_push_string(ctx, "revents");
+		duk_push_int(ctx, fds[i].revents);  /* -> [... retarr val "revents" fds[i].revents] */
+		duk_put_prop(ctx, -3);  /* -> [... retarr val] */
+		duk_pop(ctx);
+	}
+
+	/* [retarr] */
+
+	return 1;
+}
+
+static duk_function_list_entry poll_funcs[] = {
+	{ "poll", poll_poll, 2 },
+	{ NULL, NULL, 0 }
+};
+
+static duk_number_list_entry poll_consts[] = {
+	{ "POLLIN", (double) POLLIN },
+	{ "POLLPRI", (double) POLLPRI },
+	{ "POLLOUT", (double) POLLOUT },
+#if 0
+	/* Linux 2.6.17 and upwards, requires _GNU_SOURCE etc, not added
+	 * now because we don't use it.
+	 */
+	{ "POLLRDHUP", (double) POLLRDHUP },
+#endif
+	{ "POLLERR", (double) POLLERR },
+	{ "POLLHUP", (double) POLLHUP },
+	{ "POLLNVAL", (double) POLLNVAL },
+	{ NULL, 0.0 }
+};
+
+void poll_register(duk_context *ctx) {
+	/* Set global 'Poll' with functions and constants. */
+	duk_push_global_object(ctx);
+	duk_push_object(ctx);
+	duk_put_function_list(ctx, -1, poll_funcs);
+	duk_put_number_list(ctx, -1, poll_consts);
+	duk_put_prop_string(ctx, -2, "Poll");
+	duk_pop(ctx);
+}

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/eventloop/server-socket-test.js
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/eventloop/server-socket-test.js b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/eventloop/server-socket-test.js
new file mode 100644
index 0000000..68510af
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/eventloop/server-socket-test.js
@@ -0,0 +1,34 @@
+
+var HOST = 'localhost'
+var PORT = 12345;
+var EXIT_TIMEOUT = 300e3;
+
+print('automatic exit after ' + (EXIT_TIMEOUT / 1e3) + ' seconds');
+setTimeout(function () {
+    print('exit timer');
+    EventLoop.requestExit();
+}, EXIT_TIMEOUT);
+
+print('listen on ' + HOST + ':' + PORT);
+EventLoop.server(HOST, PORT, function (fd, addr, port) {
+    print('new connection on fd ' + fd + ' from ' + addr + ':' + port);
+    EventLoop.setReader(fd, function (fd, data) {
+        var b, i, n, x;
+
+        // Handle socket data carefully: if you convert it to a string,
+        // it may not be valid UTF-8 etc.  Here we operate on the data
+        // directly in the buffer.
+
+        b = data.valueOf();  // ensure we get a plain buffer
+        n = b.length;
+        for (i = 0; i < n; i++) {
+            x = b[i];
+            if (x >= 0x61 && x <= 0x7a) {
+                b[i] = x - 0x20;  // uppercase
+            }
+        }
+
+        print('read data on fd ' + fd + ', length ' + data.length);
+        EventLoop.write(fd, data);
+    });
+});

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/eventloop/socket.c
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/eventloop/socket.c b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/eventloop/socket.c
new file mode 100644
index 0000000..a1587fa
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/eventloop/socket.c
@@ -0,0 +1,286 @@
+/*
+ *  TCP sockets binding example.
+ */
+
+#define _GNU_SOURCE
+#include <errno.h>
+#include <string.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <netdb.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <time.h>
+
+#include "duktape.h"
+
+#define  ERROR_FROM_ERRNO(ctx)  do { \
+		duk_error(ctx, DUK_ERR_ERROR, "%s (errno=%d)", strerror(errno), errno); \
+	} while (0)
+
+static void set_nonblocking(duk_context *ctx, int fd) {
+	int rc;
+	int flags;
+
+	rc = fcntl(fd, F_GETFL);
+	if (rc < 0) {
+		ERROR_FROM_ERRNO(ctx);
+	}
+	flags = rc;
+
+	flags |= O_NONBLOCK;
+
+	rc = fcntl(fd, F_SETFL, flags);
+	if (rc < 0) {
+		ERROR_FROM_ERRNO(ctx);
+	}
+}
+
+static void set_reuseaddr(duk_context *ctx, int fd) {
+	int val;
+	int rc;
+
+	val = 1;
+	rc = setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (const void *) &val, sizeof(val));
+	if (rc != 0) {
+		ERROR_FROM_ERRNO(ctx);
+	}
+}
+
+#ifdef __APPLE__
+static void set_nosigpipe(duk_context *ctx, int fd) {
+	int val;
+	int rc;
+
+	val = 1;
+	rc = setsockopt(fd, SOL_SOCKET, SO_NOSIGPIPE, (const void *) &val, sizeof(val));
+	if (rc != 0) {
+		ERROR_FROM_ERRNO(ctx);
+	}
+}
+#endif
+
+static int socket_create_server_socket(duk_context *ctx) {
+	const char *addr = duk_to_string(ctx, 0);
+	int port = duk_to_int(ctx, 1);
+	int sock;
+	struct sockaddr_in sockaddr;
+	struct hostent *ent;
+	struct in_addr **addr_list;
+	struct in_addr *addr_inet;
+	int i;
+	int rc;
+
+	sock = socket(AF_INET, SOCK_STREAM, 0);
+	if (sock < 0) {
+		ERROR_FROM_ERRNO(ctx);
+	}
+
+	set_nonblocking(ctx, sock);
+	set_reuseaddr(ctx, sock);
+#ifdef __APPLE__
+	set_nosigpipe(ctx, sock);
+#endif
+
+	ent = gethostbyname(addr);
+	if (!ent) {
+		ERROR_FROM_ERRNO(ctx);
+	}
+
+	addr_list = (struct in_addr **) ent->h_addr_list;
+	addr_inet = NULL;
+	for (i = 0; addr_list[i]; i++) {
+		addr_inet = addr_list[i];
+		break;
+	}
+	if (!addr_inet) {
+		duk_error(ctx, DUK_ERR_ERROR, "cannot resolve %s", addr);
+	}
+
+	memset(&sockaddr, 0, sizeof(sockaddr));
+	sockaddr.sin_family = AF_INET;
+	sockaddr.sin_port = htons(port);
+	sockaddr.sin_addr = *addr_inet;
+
+	rc = bind(sock, (const struct sockaddr *) &sockaddr, sizeof(sockaddr));
+	if (rc < 0) {
+		ERROR_FROM_ERRNO(ctx);
+	}
+
+	rc = listen(sock, 10 /*backlog*/);
+	if (rc < 0) {
+		(void) close(sock);
+		ERROR_FROM_ERRNO(ctx);
+	}
+
+	duk_push_int(ctx, sock);
+	return 1;
+}
+
+static int socket_close(duk_context *ctx) {
+	int sock = duk_to_int(ctx, 0);
+	int rc;
+
+	rc = close(sock);
+	if (rc < 0) {
+		ERROR_FROM_ERRNO(ctx);
+	}
+	return 0;
+}
+
+static int socket_accept(duk_context *ctx) {
+	int sock = duk_to_int(ctx, 0);
+	int rc;
+	struct sockaddr_in addr;
+	socklen_t addrlen;
+
+	memset(&addr, 0, sizeof(addr));
+	addr.sin_family = AF_INET;
+	addrlen = sizeof(addr);
+
+	rc = accept(sock, (struct sockaddr *) &addr, &addrlen);
+	if (rc < 0) {
+		ERROR_FROM_ERRNO(ctx);
+	}
+
+	set_nonblocking(ctx, sock);
+#ifdef __APPLE__
+	set_nosigpipe(ctx, sock);
+#endif
+
+	if (addrlen == sizeof(addr)) {
+		uint32_t tmp = ntohl(addr.sin_addr.s_addr);
+
+		duk_push_object(ctx);
+
+		duk_push_string(ctx, "fd");
+		duk_push_int(ctx, rc);
+		duk_put_prop(ctx, -3);
+		duk_push_string(ctx, "addr");
+		duk_push_sprintf(ctx, "%d.%d.%d.%d", ((tmp >> 24) & 0xff), ((tmp >> 16) & 0xff), ((tmp >> 8) & 0xff), (tmp & 0xff));
+		duk_put_prop(ctx, -3);
+		duk_push_string(ctx, "port");
+		duk_push_int(ctx, ntohs(addr.sin_port));
+		duk_put_prop(ctx, -3);
+
+		return 1;
+	}
+
+	return 0;
+}
+
+static int socket_connect(duk_context *ctx) {
+	const char *addr = duk_to_string(ctx, 0);
+	int port = duk_to_int(ctx, 1);
+	int sock;
+	struct sockaddr_in sockaddr;
+	struct hostent *ent;
+	struct in_addr **addr_list;
+	struct in_addr *addr_inet;
+	int i;
+	int rc;
+
+	sock = socket(AF_INET, SOCK_STREAM, 0);
+	if (sock < 0) {
+		ERROR_FROM_ERRNO(ctx);
+	}
+
+	set_nonblocking(ctx, sock);
+#ifdef __APPLE__
+	set_nosigpipe(ctx, sock);
+#endif
+
+	ent = gethostbyname(addr);
+	if (!ent) {
+		ERROR_FROM_ERRNO(ctx);
+	}
+
+	addr_list = (struct in_addr **) ent->h_addr_list;
+	addr_inet = NULL;
+	for (i = 0; addr_list[i]; i++) {
+		addr_inet = addr_list[i];
+		break;
+	}
+	if (!addr_inet) {
+		duk_error(ctx, DUK_ERR_ERROR, "cannot resolve %s", addr);
+	}
+
+	memset(&sockaddr, 0, sizeof(sockaddr));
+	sockaddr.sin_family = AF_INET;
+	sockaddr.sin_port = htons(port);
+	sockaddr.sin_addr = *addr_inet;
+
+	rc = connect(sock, (const struct sockaddr *) &sockaddr, (socklen_t) sizeof(sockaddr));
+	if (rc < 0) {
+		if (errno == EINPROGRESS) {
+#if 0
+			fprintf(stderr, "connect() returned EINPROGRESS as expected, need to poll writability\n");
+			fflush(stderr);
+#endif
+		} else {
+			ERROR_FROM_ERRNO(ctx);
+		}
+	}
+
+	duk_push_int(ctx, sock);
+	return 1;
+}
+
+static int socket_read(duk_context *ctx) {
+	int sock = duk_to_int(ctx, 0);
+	char readbuf[1024];
+	int rc;
+	void *data;
+
+	rc = recvfrom(sock, (void *) readbuf, sizeof(readbuf), 0, NULL, NULL);
+	if (rc < 0) {
+		ERROR_FROM_ERRNO(ctx);
+	}
+
+	data = duk_push_fixed_buffer(ctx, rc);
+	memcpy(data, readbuf, rc);
+	return 1;
+}
+
+static int socket_write(duk_context *ctx) {
+	int sock = duk_to_int(ctx, 0);
+	const char *data;
+	size_t len;
+	ssize_t rc;
+
+	data = duk_to_buffer(ctx, 1, &len);
+
+	/* MSG_NOSIGNAL: avoid SIGPIPE */
+#ifdef __APPLE__
+	rc = sendto(sock, (void *) data, len, 0, NULL, 0);
+#else
+	rc = sendto(sock, (void *) data, len, MSG_NOSIGNAL, NULL, 0);
+#endif
+	if (rc < 0) {
+		ERROR_FROM_ERRNO(ctx);
+	}
+
+	duk_push_int(ctx, rc);
+	return 1;
+}
+
+static duk_function_list_entry socket_funcs[] = {
+	{ "createServerSocket", socket_create_server_socket, 2 },
+	{ "close", socket_close, 1 },
+	{ "accept", socket_accept, 1 },
+	{ "connect", socket_connect, 2 },
+	{ "read", socket_read, 1 },
+	{ "write", socket_write, 2 },
+	{ NULL, NULL, 0 }
+};
+
+void socket_register(duk_context *ctx) {
+	/* Set global 'Socket'. */
+	duk_push_global_object(ctx);
+	duk_push_object(ctx);
+	duk_put_function_list(ctx, -1, socket_funcs);
+	duk_put_prop_string(ctx, -2, "Socket");
+	duk_pop(ctx);
+}

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/guide/README.rst
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/guide/README.rst b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/guide/README.rst
new file mode 100644
index 0000000..1933094
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/guide/README.rst
@@ -0,0 +1,5 @@
+===========================
+Duktape guide example files
+===========================
+
+Examples used in the Duktape guide.

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/guide/fib.js
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/guide/fib.js b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/guide/fib.js
new file mode 100644
index 0000000..2b2982f
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/guide/fib.js
@@ -0,0 +1,16 @@
+// fib.js
+function fib(n) {
+    if (n == 0) { return 0; }
+    if (n == 1) { return 1; }
+    return fib(n-1) + fib(n-2);
+}
+
+function test() {
+    var res = [];
+    for (i = 0; i < 20; i++) {
+        res.push(fib(i));
+    }
+    print(res.join(' '));
+}
+
+test();

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/guide/prime.js
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/guide/prime.js b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/guide/prime.js
new file mode 100644
index 0000000..8959754
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/guide/prime.js
@@ -0,0 +1,32 @@
+// prime.js
+
+// Pure Ecmascript version of low level helper
+function primeCheckEcmascript(val, limit) {
+    for (var i = 2; i <= limit; i++) {
+        if ((val % i) == 0) { return false; }
+    }
+    return true;
+}
+
+// Select available helper at load time
+var primeCheckHelper = (this.primeCheckNative || primeCheckEcmascript);
+
+// Check 'val' for primality
+function primeCheck(val) {
+    if (val == 1 || val == 2) { return true; }
+    var limit = Math.ceil(Math.sqrt(val));
+    while (limit * limit < val) { limit += 1; }
+    return primeCheckHelper(val, limit);
+}
+
+// Find primes below one million ending in '9999'.
+function primeTest() {
+    var res = [];
+
+    print('Have native helper: ' + (primeCheckHelper !== primeCheckEcmascript));
+    for (var i = 1; i < 1000000; i++) {
+        if (primeCheck(i) && (i % 10000) == 9999) { res.push(i); }
+    } 
+    print(res.join(' '));
+}
+

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/guide/primecheck.c
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/guide/primecheck.c b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/guide/primecheck.c
new file mode 100644
index 0000000..36fa5d6
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/guide/primecheck.c
@@ -0,0 +1,52 @@
+/* primecheck.c */
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "duktape.h"
+
+static duk_ret_t native_prime_check(duk_context *ctx) {
+    int val = duk_require_int(ctx, 0);
+    int lim = duk_require_int(ctx, 1);
+    int i;
+
+    for (i = 2; i <= lim; i++) {
+        if (val % i == 0) {
+            duk_push_false(ctx);
+            return 1;
+        }
+    }
+
+    duk_push_true(ctx);
+    return 1;
+}
+
+int main(int argc, const char *argv[]) {
+    duk_context *ctx = NULL;
+
+    ctx = duk_create_heap_default();
+    if (!ctx) {
+        printf("Failed to create a Duktape heap.\n");
+        exit(1);
+    }
+
+    duk_push_global_object(ctx);
+    duk_push_c_function(ctx, native_prime_check, 2 /*nargs*/);
+    duk_put_prop_string(ctx, -2, "primeCheckNative");
+
+    if (duk_peval_file(ctx, "prime.js") != 0) {
+        printf("Error: %s\n", duk_safe_to_string(ctx, -1));
+        goto finished;
+    }
+    duk_pop(ctx);  /* ignore result */
+
+    duk_get_prop_string(ctx, -1, "primeTest");
+    if (duk_pcall(ctx, 0) != 0) {
+        printf("Error: %s\n", duk_safe_to_string(ctx, -1));
+    }
+    duk_pop(ctx);  /* ignore result */
+
+ finished:
+    duk_destroy_heap(ctx);
+
+    exit(0);
+}

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/guide/process.js
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/guide/process.js b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/guide/process.js
new file mode 100644
index 0000000..62b5011
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/guide/process.js
@@ -0,0 +1,12 @@
+// process.js
+function processLine(line) {
+    return line.trim()
+        .replace(/[<>&"'\u0000-\u001F\u007E-\uFFFF]/g, function(x) {
+            // escape HTML characters
+            return '&#' + x.charCodeAt(0) + ';'
+         })
+        .replace(/\*(.*?)\*/g, function(x, m) {
+            // automatically bold text between stars
+            return '<b>' + m + '</b>';
+         });
+}

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/guide/processlines.c
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/guide/processlines.c b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/guide/processlines.c
new file mode 100644
index 0000000..f91bdff
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/guide/processlines.c
@@ -0,0 +1,59 @@
+/* processlines.c */
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "duktape.h"
+
+int main(int argc, const char *argv[]) {
+    duk_context *ctx = NULL;
+    char line[4096];
+    char idx;
+    int ch;
+
+    ctx = duk_create_heap_default();
+    if (!ctx) {
+        printf("Failed to create a Duktape heap.\n");
+        exit(1);
+    }
+
+    if (duk_peval_file(ctx, "process.js") != 0) {
+        printf("Error: %s\n", duk_safe_to_string(ctx, -1));
+        goto finished;
+    }
+    duk_pop(ctx);  /* ignore result */
+
+    memset(line, 0, sizeof(line));
+    idx = 0;
+    for (;;) {
+        if (idx >= sizeof(line)) {
+            printf("Line too long\n");
+            exit(1);
+        }
+
+        ch = fgetc(stdin);
+        if (ch == 0x0a) {
+            line[idx++] = '\0';
+
+            duk_push_global_object(ctx);
+            duk_get_prop_string(ctx, -1 /*index*/, "processLine");
+            duk_push_string(ctx, line);
+            if (duk_pcall(ctx, 1 /*nargs*/) != 0) {
+                printf("Error: %s\n", duk_safe_to_string(ctx, -1));
+            } else {
+                printf("%s\n", duk_safe_to_string(ctx, -1));
+            }
+            duk_pop(ctx);  /* pop result/error */
+
+            idx = 0;
+        } else if (ch == EOF) {
+            break;
+        } else {
+            line[idx++] = (char) ch;
+        }
+    }
+
+ finished:
+    duk_destroy_heap(ctx);
+
+    exit(0);
+}

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/guide/uppercase.c
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/guide/uppercase.c b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/guide/uppercase.c
new file mode 100644
index 0000000..03d0869
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/guide/uppercase.c
@@ -0,0 +1,42 @@
+/* uppercase.c */
+#include <stdio.h>
+#include <stdlib.h>
+#include "duktape.h"
+
+static int dummy_upper_case(duk_context *ctx) {
+    size_t sz;
+    const char *val = duk_require_lstring(ctx, 0, &sz);
+    size_t i;
+
+    /* We're going to need 'sz' additional entries on the stack. */
+    duk_require_stack(ctx, sz);
+
+    for (i = 0; i < sz; i++) {
+        char ch = val[i];
+        if (ch >= 'a' && ch <= 'z') {
+            ch = ch - 'a' + 'A';
+        }
+        duk_push_lstring(ctx, (const char *) &ch, 1);
+    }
+
+    duk_concat(ctx, sz);
+    return 1;
+}
+
+int main(int argc, char *argv[]) {
+    duk_context *ctx;
+
+    if (argc < 2) { exit(1); }
+
+    ctx = duk_create_heap_default();
+    if (!ctx) { exit(1); }
+
+    duk_push_c_function(ctx, dummy_upper_case, 1);
+    duk_push_string(ctx, argv[1]);
+    duk_call(ctx, 1);
+    printf("%s -> %s\n", argv[1], duk_to_string(ctx, -1));
+    duk_pop(ctx);
+
+    duk_destroy_heap(ctx);
+    return 0;
+}

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/hello/README.rst
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/hello/README.rst b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/hello/README.rst
new file mode 100644
index 0000000..7afef53
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/hello/README.rst
@@ -0,0 +1,5 @@
+===================
+Hello world example
+===================
+
+Very simple example, most useful for compilation tests.

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/hello/hello.c
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/hello/hello.c b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/hello/hello.c
new file mode 100644
index 0000000..9113d2f
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/hello/hello.c
@@ -0,0 +1,38 @@
+/*
+ *  Very simple example program
+ */
+
+#include "duktape.h"
+
+int adder(duk_context *ctx) {
+	int i;
+	int n = duk_get_top(ctx);  /* #args */
+	double res = 0.0;
+
+	for (i = 0; i < n; i++) {
+		res += duk_to_number(ctx, i);
+	}
+
+	duk_push_number(ctx, res);
+	return 1;  /* one return value */
+}
+
+int main(int argc, char *argv[]) {
+	duk_context *ctx = duk_create_heap_default();
+
+	(void) argc; (void) argv;  /* suppress warning */
+
+	duk_eval_string(ctx, "print('Hello world!');");
+
+	duk_push_global_object(ctx);
+	duk_push_c_function(ctx, adder, DUK_VARARGS);
+	duk_put_prop_string(ctx, -2, "adder");
+	duk_pop(ctx);  /* pop global */
+
+	duk_eval_string(ctx, "print('2+3=' + adder(2, 3));");
+	duk_pop(ctx);  /* pop eval result */
+
+	duk_destroy_heap(ctx);
+
+	return 0;
+}

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/jxpretty/README.rst
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/jxpretty/README.rst b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/jxpretty/README.rst
new file mode 100644
index 0000000..5ab43a8
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/jxpretty/README.rst
@@ -0,0 +1,5 @@
+================
+Jxpretty example
+================
+
+Simple command line utility to pretty print JSON in the JX format.

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/jxpretty/jxpretty.c
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/jxpretty/jxpretty.c b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/jxpretty/jxpretty.c
new file mode 100644
index 0000000..1e483ef
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/jxpretty/jxpretty.c
@@ -0,0 +1,63 @@
+/*
+ *  Pretty print JSON from stdin into indented JX.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include "duktape.h"
+
+static duk_ret_t do_jxpretty(duk_context *ctx) {
+	FILE *f = stdin;
+	char buf[4096];
+	size_t ret;
+
+	for (;;) {
+		if (ferror(f)) {
+			duk_error(ctx, DUK_ERR_ERROR, "ferror() on stdin");
+		}
+		if (feof(f)) {
+			break;
+		}
+
+		ret = fread(buf, 1, sizeof(buf), f);
+#if 0
+		fprintf(stderr, "Read: %ld\n", (long) ret);
+		fflush(stderr);
+#endif
+		if (ret == 0) {
+			break;
+		}
+
+		duk_require_stack(ctx, 1);
+		duk_push_lstring(ctx, (const char *) buf, ret);
+	}
+
+	duk_concat(ctx, duk_get_top(ctx));
+
+	duk_eval_string(ctx, "(function (v) { print(Duktape.enc('jx', JSON.parse(v), null, 4)); })");
+	duk_insert(ctx, -2);
+	duk_call(ctx, 1);
+
+	return 0;
+}
+
+int main(int argc, char *argv[]) {
+	duk_context *ctx;
+	duk_int_t rc;
+
+	/* suppress warnings */
+	(void) argc;
+	(void) argv;
+
+	ctx = duk_create_heap_default();
+
+	rc = duk_safe_call(ctx, do_jxpretty, 0 /*nargs*/, 1 /*nrets*/);
+	if (rc) {
+		fprintf(stderr, "ERROR: %s\n", duk_safe_to_string(ctx, -1));
+		fflush(stderr);
+	}
+
+	duk_destroy_heap(ctx);
+
+	return 0;
+}

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/sandbox/README.rst
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/sandbox/README.rst b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/sandbox/README.rst
new file mode 100644
index 0000000..24df0a2
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/sandbox/README.rst
@@ -0,0 +1,5 @@
+===============
+Sandbox example
+===============
+
+Very simple, minimal sandboxing example.

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/sandbox/sandbox.c
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/sandbox/sandbox.c b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/sandbox/sandbox.c
new file mode 100644
index 0000000..915faa9
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/sandbox/sandbox.c
@@ -0,0 +1,252 @@
+/*
+ *  Sandboxing example
+ *
+ *  Uses custom memory allocation functions which keep track of total amount
+ *  of memory allocated, imposing a maximum total allocation size.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include "duktape.h"
+
+/*
+ *  Memory allocator which backs to standard library memory functions but
+ *  keeps a small header to track current allocation size.
+ *
+ *  Many other sandbox allocation models are useful, e.g. preallocated pools.
+ */
+
+typedef struct {
+	/* The double value in the union is there to ensure alignment is
+	 * good for IEEE doubles too.  In many 32-bit environments 4 bytes
+	 * would be sufficiently aligned and the double value is unnecessary.
+	 */
+	union {
+		size_t sz;
+		double d;
+	} u;
+} alloc_hdr;
+
+static size_t total_allocated = 0;
+static size_t max_allocated = 256 * 1024;  /* 256kB sandbox */
+
+static void sandbox_dump_memstate(void) {
+#if 0
+	fprintf(stderr, "Total allocated: %ld\n", (long) total_allocated);
+	fflush(stderr);
+#endif
+}
+
+static void *sandbox_alloc(void *udata, duk_size_t size) {
+	alloc_hdr *hdr;
+
+	(void) udata;  /* Suppress warning. */
+
+	if (size == 0) {
+		return NULL;
+	}
+
+	if (total_allocated + size > max_allocated) {
+		fprintf(stderr, "Sandbox maximum allocation size reached, %ld requested in sandbox_alloc\n",
+		        (long) size);
+		fflush(stderr);
+		return NULL;
+	}
+
+	hdr = (alloc_hdr *) malloc(size + sizeof(alloc_hdr));
+	if (!hdr) {
+		return NULL;
+	}
+	hdr->u.sz = size;
+	total_allocated += size;
+	sandbox_dump_memstate();
+	return (void *) (hdr + 1);
+}
+
+static void *sandbox_realloc(void *udata, void *ptr, duk_size_t size) {
+	alloc_hdr *hdr;
+	size_t old_size;
+	void *t;
+
+	(void) udata;  /* Suppress warning. */
+
+	/* Handle the ptr-NULL vs. size-zero cases explicitly to minimize
+	 * platform assumptions.  You can get away with much less in specific
+	 * well-behaving environments.
+	 */
+
+	if (ptr) {
+		hdr = (alloc_hdr *) (((char *) ptr) - sizeof(alloc_hdr));
+		old_size = hdr->u.sz;
+
+		if (size == 0) {
+			total_allocated -= old_size;
+			free((void *) hdr);
+			sandbox_dump_memstate();
+			return NULL;
+		} else {
+			if (total_allocated - old_size + size > max_allocated) {
+				fprintf(stderr, "Sandbox maximum allocation size reached, %ld requested in sandbox_realloc\n",
+				        (long) size);
+				fflush(stderr);
+				return NULL;
+			}
+
+			t = realloc((void *) hdr, size + sizeof(alloc_hdr));
+			if (!t) {
+				return NULL;
+			}
+			hdr = (alloc_hdr *) t;
+			total_allocated -= old_size;
+			total_allocated += size;
+			hdr->u.sz = size;
+			sandbox_dump_memstate();
+			return (void *) (hdr + 1);
+		}
+	} else {
+		if (size == 0) {
+			return NULL;
+		} else {
+			if (total_allocated + size > max_allocated) {
+				fprintf(stderr, "Sandbox maximum allocation size reached, %ld requested in sandbox_realloc\n",
+				        (long) size);
+				fflush(stderr);
+				return NULL;
+			}
+
+			hdr = (alloc_hdr *) malloc(size + sizeof(alloc_hdr));
+			if (!hdr) {
+				return NULL;
+			}
+			hdr->u.sz = size;
+			total_allocated += size;
+			sandbox_dump_memstate();
+			return (void *) (hdr + 1);
+		}
+	}
+}
+
+static void sandbox_free(void *udata, void *ptr) {
+	alloc_hdr *hdr;
+
+	(void) udata;  /* Suppress warning. */
+
+	if (!ptr) {
+		return;
+	}
+	hdr = (alloc_hdr *) (((char *) ptr) - sizeof(alloc_hdr));
+	total_allocated -= hdr->u.sz;
+	free((void *) hdr);
+	sandbox_dump_memstate();
+}
+
+/*
+ *  Sandbox setup and test
+ */
+
+static duk_ret_t do_sandbox_test(duk_context *ctx) {
+	FILE *f;
+	char buf[4096];
+	size_t ret;
+	const char *globobj;
+
+	/*
+	 *  Setup sandbox
+	 */
+
+	globobj =
+		"({\n"
+		"    print: print,\n"
+		"    Math: {\n"
+		"        max: Math.max\n"
+		"    }\n"
+		"})\n";
+#if 1
+	fprintf(stderr, "Sandbox global object:\n----------------\n%s----------------\n", globobj);
+	fflush(stderr);
+#endif
+	duk_eval_string(ctx, globobj);
+	duk_set_global_object(ctx);
+
+	/*
+	 *  Execute code from specified file
+	 */
+
+	f = fopen(duk_require_string(ctx, -1), "rb");
+	if (!f) {
+		duk_error(ctx, DUK_ERR_ERROR, "failed to open file");
+	}
+
+	for (;;) {
+		if (ferror(f)) {
+			fclose(f);
+			duk_error(ctx, DUK_ERR_ERROR, "ferror when reading file");
+		}
+		if (feof(f)) {
+			break;
+		}
+
+		ret = fread(buf, 1, sizeof(buf), f);
+		if (ret == 0) {
+			break;
+		}
+
+		duk_push_lstring(ctx, (const char *) buf, ret);
+	}
+
+	duk_concat(ctx, duk_get_top(ctx) - 1);  /* -1 for filename */
+
+	/* -> [ ... filename source ] */
+
+	duk_insert(ctx, -2);
+
+	/* -> [ ... source filename ] */
+
+	duk_compile(ctx, 0 /*flags*/);  /* Compile as program */
+	duk_call(ctx, 0 /*nargs*/);
+
+	return 0;
+}
+
+/*
+ *  Main
+ */
+
+static void sandbox_fatal(duk_context *ctx, duk_errcode_t code, const char *msg) {
+	(void) ctx;  /* Suppress warning. */
+	fprintf(stderr, "FATAL %ld: %s\n", (long) code, (msg ? msg : "no message"));
+	fflush(stderr);
+	exit(1);  /* must not return */
+}
+
+int main(int argc, char *argv[]) {
+	duk_context *ctx;
+	duk_int_t rc;
+
+	if (argc < 2) {
+		fprintf(stderr, "Usage: sandbox <test.js>\n");
+		fflush(stderr);
+		exit(1);
+	}
+
+	ctx = duk_create_heap(sandbox_alloc,
+	                      sandbox_realloc,
+	                      sandbox_free,
+	                      NULL,
+	                      sandbox_fatal);
+
+	duk_push_string(ctx, argv[1]);
+	rc = duk_safe_call(ctx, do_sandbox_test, 1 /*nargs*/, 1 /*nrets*/);
+	if (rc) {
+		fprintf(stderr, "ERROR: %s\n", duk_safe_to_string(ctx, -1));
+		fflush(stderr);
+	}
+
+	duk_destroy_heap(ctx);
+
+	/* Should be zero. */
+	fprintf(stderr, "Final allocation: %ld\n", (long) total_allocated);
+	fflush(stderr);
+
+	return 1;
+}


[48/51] [partial] nifi-minifi-cpp git commit: MINIFI-183 Added civet 1.9.1 sources Added onScheduled hook Added initial two-way TLS-enabled ListenHTTP implementation

Posted by al...@apache.org.
http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/VisualStudio/civetweb_yassl/yassl_lib/yassl_lib.vcxproj.filters
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/VisualStudio/civetweb_yassl/yassl_lib/yassl_lib.vcxproj.filters b/thirdparty/civetweb-1.9.1/VisualStudio/civetweb_yassl/yassl_lib/yassl_lib.vcxproj.filters
new file mode 100644
index 0000000..566b892
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/VisualStudio/civetweb_yassl/yassl_lib/yassl_lib.vcxproj.filters
@@ -0,0 +1,124 @@
+\ufeff<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <ItemGroup>
+    <Filter Include="Source Files">
+      <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
+      <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
+    </Filter>
+    <Filter Include="Header Files">
+      <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
+      <Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
+    </Filter>
+    <Filter Include="Resource Files">
+      <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
+      <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
+    </Filter>
+  </ItemGroup>
+  <ItemGroup>
+    <ClCompile Include="..\..\..\..\cyassl-2.7.0\ctaocrypt\src\aes.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\..\..\cyassl-2.7.0\ctaocrypt\src\arc4.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\..\..\cyassl-2.7.0\ctaocrypt\src\asn.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\..\..\cyassl-2.7.0\ctaocrypt\src\coding.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\..\..\cyassl-2.7.0\ctaocrypt\src\des3.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\..\..\cyassl-2.7.0\ctaocrypt\src\dh.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\..\..\cyassl-2.7.0\ctaocrypt\src\dsa.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\..\..\cyassl-2.7.0\ctaocrypt\src\ecc.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\..\..\cyassl-2.7.0\ctaocrypt\src\error.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\..\..\cyassl-2.7.0\ctaocrypt\src\hc128.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\..\..\cyassl-2.7.0\ctaocrypt\src\hmac.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\..\..\cyassl-2.7.0\ctaocrypt\src\integer.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\..\..\cyassl-2.7.0\ctaocrypt\src\logging.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\..\..\cyassl-2.7.0\ctaocrypt\src\md2.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\..\..\cyassl-2.7.0\ctaocrypt\src\md4.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\..\..\cyassl-2.7.0\ctaocrypt\src\md5.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\..\..\cyassl-2.7.0\ctaocrypt\src\memory.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\..\..\cyassl-2.7.0\ctaocrypt\src\misc.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\..\..\cyassl-2.7.0\ctaocrypt\src\pwdbased.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\..\..\cyassl-2.7.0\ctaocrypt\src\rabbit.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\..\..\cyassl-2.7.0\ctaocrypt\src\random.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\..\..\cyassl-2.7.0\ctaocrypt\src\ripemd.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\..\..\cyassl-2.7.0\ctaocrypt\src\rsa.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\..\..\cyassl-2.7.0\ctaocrypt\src\sha.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\..\..\cyassl-2.7.0\ctaocrypt\src\sha256.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\..\..\cyassl-2.7.0\ctaocrypt\src\sha512.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\..\..\cyassl-2.7.0\ctaocrypt\src\tfm.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\..\..\cyassl-2.7.0\src\crl.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\..\..\cyassl-2.7.0\src\internal.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\..\..\cyassl-2.7.0\src\io.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\..\..\cyassl-2.7.0\src\keys.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\..\..\cyassl-2.7.0\src\ocsp.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\..\..\cyassl-2.7.0\src\sniffer.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\..\..\cyassl-2.7.0\src\ssl.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\..\..\cyassl-2.7.0\src\tls.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+  </ItemGroup>
+</Project>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/VisualStudio/duktape_lib/duktape_lib.vcxproj
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/VisualStudio/duktape_lib/duktape_lib.vcxproj b/thirdparty/civetweb-1.9.1/VisualStudio/duktape_lib/duktape_lib.vcxproj
new file mode 100644
index 0000000..c48669f
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/VisualStudio/duktape_lib/duktape_lib.vcxproj
@@ -0,0 +1,156 @@
+\ufeff<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <ItemGroup Label="ProjectConfigurations">
+    <ProjectConfiguration Include="Debug|Win32">
+      <Configuration>Debug</Configuration>
+      <Platform>Win32</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Debug|x64">
+      <Configuration>Debug</Configuration>
+      <Platform>x64</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Release|Win32">
+      <Configuration>Release</Configuration>
+      <Platform>Win32</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Release|x64">
+      <Configuration>Release</Configuration>
+      <Platform>x64</Platform>
+    </ProjectConfiguration>
+  </ItemGroup>
+  <PropertyGroup Label="Globals">
+    <ProjectGuid>{0A11689C-DB6A-4BF6-97B2-AD32DB863FBD}</ProjectGuid>
+    <Keyword>Win32Proj</Keyword>
+    <RootNamespace>duktape_lib</RootNamespace>
+    <WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
+  </PropertyGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
+    <ConfigurationType>StaticLibrary</ConfigurationType>
+    <UseDebugLibraries>true</UseDebugLibraries>
+    <CharacterSet>MultiByte</CharacterSet>
+    <PlatformToolset>v140</PlatformToolset>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
+    <ConfigurationType>StaticLibrary</ConfigurationType>
+    <UseDebugLibraries>true</UseDebugLibraries>
+    <PlatformToolset>v140</PlatformToolset>
+    <CharacterSet>MultiByte</CharacterSet>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
+    <ConfigurationType>StaticLibrary</ConfigurationType>
+    <UseDebugLibraries>false</UseDebugLibraries>
+    <WholeProgramOptimization>true</WholeProgramOptimization>
+    <CharacterSet>MultiByte</CharacterSet>
+    <PlatformToolset>v140</PlatformToolset>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
+    <ConfigurationType>StaticLibrary</ConfigurationType>
+    <UseDebugLibraries>false</UseDebugLibraries>
+    <PlatformToolset>v140</PlatformToolset>
+    <WholeProgramOptimization>true</WholeProgramOptimization>
+    <CharacterSet>MultiByte</CharacterSet>
+  </PropertyGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+  <ImportGroup Label="ExtensionSettings">
+  </ImportGroup>
+  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <PropertyGroup Label="UserMacros" />
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+    <OutDir>$(SolutionDir)\$(Configuration)\$(Platform)\</OutDir>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+    <OutDir>$(SolutionDir)\$(Configuration)\$(Platform)\</OutDir>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <OutDir>$(SolutionDir)\$(Configuration)\$(Platform)\</OutDir>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <OutDir>$(SolutionDir)\$(Configuration)\$(Platform)\</OutDir>
+  </PropertyGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <ClCompile>
+      <PrecompiledHeader>
+      </PrecompiledHeader>
+      <WarningLevel>TurnOffAllWarnings</WarningLevel>
+      <Optimization>Disabled</Optimization>
+      <PreprocessorDefinitions>duktape_COMPAT_ALL;THREADSAFE=1;SQLITE_ENABLE_FTS3;SQLITE_ENABLE_FTS3_PARENTHESIS;WIN32;_DEBUG;_WINDOWS;_CRT_SECURE_NO_DEPRECATE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <AdditionalIncludeDirectories>$(ProjectDir)..\..\src\third_party\lua-5.2.4\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+    </ClCompile>
+    <Link>
+      <SubSystem>Windows</SubSystem>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+    <ClCompile>
+      <PrecompiledHeader>
+      </PrecompiledHeader>
+      <WarningLevel>Level3</WarningLevel>
+      <Optimization>Disabled</Optimization>
+      <PreprocessorDefinitions>duktape_COMPAT_ALL;THREADSAFE=1;SQLITE_ENABLE_FTS3;SQLITE_ENABLE_FTS3_PARENTHESIS;WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <AdditionalIncludeDirectories>$(ProjectDir)..\..\src\third_party\lua-5.2.4\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+    </ClCompile>
+    <Link>
+      <SubSystem>Windows</SubSystem>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <ClCompile>
+      <WarningLevel>Level3</WarningLevel>
+      <PrecompiledHeader>
+      </PrecompiledHeader>
+      <Optimization>MaxSpeed</Optimization>
+      <FunctionLevelLinking>true</FunctionLevelLinking>
+      <IntrinsicFunctions>true</IntrinsicFunctions>
+      <PreprocessorDefinitions>duktape_COMPAT_ALL;THREADSAFE=1;SQLITE_ENABLE_FTS3;SQLITE_ENABLE_FTS3_PARENTHESIS;WIN32;NDEBUG;_WINDOWS;_CRT_SECURE_NO_DEPRECATE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <AdditionalIncludeDirectories>$(ProjectDir)..\..\src\third_party\lua-5.2.4\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+    </ClCompile>
+    <Link>
+      <SubSystem>Windows</SubSystem>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>
+      <OptimizeReferences>true</OptimizeReferences>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+    <ClCompile>
+      <WarningLevel>Level3</WarningLevel>
+      <PrecompiledHeader>
+      </PrecompiledHeader>
+      <Optimization>MaxSpeed</Optimization>
+      <FunctionLevelLinking>true</FunctionLevelLinking>
+      <IntrinsicFunctions>true</IntrinsicFunctions>
+      <PreprocessorDefinitions>duktape_COMPAT_ALL;THREADSAFE=1;SQLITE_ENABLE_FTS3;SQLITE_ENABLE_FTS3_PARENTHESIS;WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <AdditionalIncludeDirectories>$(ProjectDir)..\..\src\third_party\lua-5.2.4\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+    </ClCompile>
+    <Link>
+      <SubSystem>Windows</SubSystem>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>
+      <OptimizeReferences>true</OptimizeReferences>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemGroup>
+    <ClInclude Include="..\..\src\third_party\duktape-1.5.2\src\duktape.h" />
+    <ClInclude Include="..\..\src\third_party\duktape-1.5.2\src\duk_config.h" />
+  </ItemGroup>
+  <ItemGroup>
+    <ClCompile Include="..\..\src\third_party\duktape-1.5.2\src\duktape.c" />
+  </ItemGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+  <ImportGroup Label="ExtensionTargets">
+  </ImportGroup>
+</Project>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/VisualStudio/duktape_lib/duktape_lib.vcxproj.filters
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/VisualStudio/duktape_lib/duktape_lib.vcxproj.filters b/thirdparty/civetweb-1.9.1/VisualStudio/duktape_lib/duktape_lib.vcxproj.filters
new file mode 100644
index 0000000..1aab8c8
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/VisualStudio/duktape_lib/duktape_lib.vcxproj.filters
@@ -0,0 +1,30 @@
+\ufeff<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <ItemGroup>
+    <Filter Include="Source Files">
+      <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
+      <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
+    </Filter>
+    <Filter Include="Header Files">
+      <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
+      <Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
+    </Filter>
+    <Filter Include="Resource Files">
+      <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
+      <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
+    </Filter>
+  </ItemGroup>
+  <ItemGroup>
+    <ClInclude Include="..\..\src\third_party\duktape-1.5.2\src\duk_config.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+    <ClInclude Include="..\..\src\third_party\duktape-1.5.2\src\duktape.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+  </ItemGroup>
+  <ItemGroup>
+    <ClCompile Include="..\..\src\third_party\duktape-1.5.2\src\duktape.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+  </ItemGroup>
+</Project>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/VisualStudio/ex_embed_cpp/ex_embed_cpp.vcxproj
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/VisualStudio/ex_embed_cpp/ex_embed_cpp.vcxproj b/thirdparty/civetweb-1.9.1/VisualStudio/ex_embed_cpp/ex_embed_cpp.vcxproj
new file mode 100644
index 0000000..3941edb
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/VisualStudio/ex_embed_cpp/ex_embed_cpp.vcxproj
@@ -0,0 +1,162 @@
+\ufeff<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <ItemGroup Label="ProjectConfigurations">
+    <ProjectConfiguration Include="Debug|Win32">
+      <Configuration>Debug</Configuration>
+      <Platform>Win32</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Debug|x64">
+      <Configuration>Debug</Configuration>
+      <Platform>x64</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Release|Win32">
+      <Configuration>Release</Configuration>
+      <Platform>Win32</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Release|x64">
+      <Configuration>Release</Configuration>
+      <Platform>x64</Platform>
+    </ProjectConfiguration>
+  </ItemGroup>
+  <PropertyGroup Label="Globals">
+    <ProjectGuid>{4308C5EE-45E4-45D8-9D73-6C4E2587AD78}</ProjectGuid>
+    <Keyword>Win32Proj</Keyword>
+    <RootNamespace>ex_embed_cpp</RootNamespace>
+    <WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
+  </PropertyGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>true</UseDebugLibraries>
+    <PlatformToolset>v140</PlatformToolset>
+    <CharacterSet>MultiByte</CharacterSet>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>true</UseDebugLibraries>
+    <PlatformToolset>v140</PlatformToolset>
+    <CharacterSet>MultiByte</CharacterSet>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>false</UseDebugLibraries>
+    <PlatformToolset>v140</PlatformToolset>
+    <WholeProgramOptimization>true</WholeProgramOptimization>
+    <CharacterSet>MultiByte</CharacterSet>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>false</UseDebugLibraries>
+    <PlatformToolset>v140</PlatformToolset>
+    <WholeProgramOptimization>true</WholeProgramOptimization>
+    <CharacterSet>MultiByte</CharacterSet>
+  </PropertyGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+  <ImportGroup Label="ExtensionSettings">
+  </ImportGroup>
+  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <PropertyGroup Label="UserMacros" />
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <LinkIncremental>true</LinkIncremental>
+    <OutDir>$(SolutionDir)\$(Configuration)\$(Platform)\</OutDir>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+    <LinkIncremental>true</LinkIncremental>
+    <OutDir>$(SolutionDir)\$(Configuration)\$(Platform)\</OutDir>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <LinkIncremental>false</LinkIncremental>
+    <OutDir>$(SolutionDir)\$(Configuration)\$(Platform)\</OutDir>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+    <LinkIncremental>false</LinkIncremental>
+    <OutDir>$(SolutionDir)\$(Configuration)\$(Platform)\</OutDir>
+  </PropertyGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <ClCompile>
+      <PrecompiledHeader>
+      </PrecompiledHeader>
+      <WarningLevel>Level3</WarningLevel>
+      <Optimization>Disabled</Optimization>
+      <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <AdditionalIncludeDirectories>$(ProjectDir)..\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+    </ClCompile>
+    <Link>
+      <SubSystem>Console</SubSystem>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+    <ClCompile>
+      <PrecompiledHeader>
+      </PrecompiledHeader>
+      <WarningLevel>Level3</WarningLevel>
+      <Optimization>Disabled</Optimization>
+      <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <AdditionalIncludeDirectories>$(ProjectDir)..\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+    </ClCompile>
+    <Link>
+      <SubSystem>Console</SubSystem>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <ClCompile>
+      <WarningLevel>Level3</WarningLevel>
+      <PrecompiledHeader>
+      </PrecompiledHeader>
+      <Optimization>MaxSpeed</Optimization>
+      <FunctionLevelLinking>true</FunctionLevelLinking>
+      <IntrinsicFunctions>true</IntrinsicFunctions>
+      <PreprocessorDefinitions>WIN32;_CONSOLE;_CRT_SECURE_NO_DEPRECATE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <AdditionalIncludeDirectories>$(ProjectDir)..\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+    </ClCompile>
+    <Link>
+      <SubSystem>Console</SubSystem>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>
+      <OptimizeReferences>true</OptimizeReferences>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+    <ClCompile>
+      <WarningLevel>Level3</WarningLevel>
+      <PrecompiledHeader>
+      </PrecompiledHeader>
+      <Optimization>MaxSpeed</Optimization>
+      <FunctionLevelLinking>true</FunctionLevelLinking>
+      <IntrinsicFunctions>true</IntrinsicFunctions>
+      <PreprocessorDefinitions>WIN32;_CONSOLE;_CRT_SECURE_NO_DEPRECATE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <AdditionalIncludeDirectories>$(ProjectDir)..\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+    </ClCompile>
+    <Link>
+      <SubSystem>Console</SubSystem>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>
+      <OptimizeReferences>true</OptimizeReferences>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemGroup>
+    <ClInclude Include="..\..\include\civetweb.h" />
+    <ClInclude Include="..\..\include\CivetServer.h" />
+  </ItemGroup>
+  <ItemGroup>
+    <ClCompile Include="..\..\src\civetweb.c" />
+    <ClCompile Include="..\..\src\CivetServer.cpp" />
+    <ClCompile Include="..\..\examples\embedded_cpp\embedded_cpp.cpp" />
+  </ItemGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+  <ImportGroup Label="ExtensionTargets">
+  </ImportGroup>
+</Project>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/VisualStudio/ex_embed_cpp/ex_embed_cpp.vcxproj.filters
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/VisualStudio/ex_embed_cpp/ex_embed_cpp.vcxproj.filters b/thirdparty/civetweb-1.9.1/VisualStudio/ex_embed_cpp/ex_embed_cpp.vcxproj.filters
new file mode 100644
index 0000000..68671e6
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/VisualStudio/ex_embed_cpp/ex_embed_cpp.vcxproj.filters
@@ -0,0 +1,36 @@
+\ufeff<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <ItemGroup>
+    <Filter Include="Source Files">
+      <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
+      <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
+    </Filter>
+    <Filter Include="Header Files">
+      <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
+      <Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
+    </Filter>
+    <Filter Include="Resource Files">
+      <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
+      <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
+    </Filter>
+  </ItemGroup>
+  <ItemGroup>
+    <ClInclude Include="..\..\include\civetweb.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+    <ClInclude Include="..\..\include\CivetServer.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+  </ItemGroup>
+  <ItemGroup>
+    <ClCompile Include="..\..\examples\embedded_cpp\embedded_cpp.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\civetweb.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\CivetServer.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+  </ItemGroup>
+</Project>

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/VisualStudio/ex_embedded_c/ex_embedded_c.vcxproj
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/VisualStudio/ex_embedded_c/ex_embedded_c.vcxproj b/thirdparty/civetweb-1.9.1/VisualStudio/ex_embedded_c/ex_embedded_c.vcxproj
new file mode 100644
index 0000000..fb81aff
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/VisualStudio/ex_embedded_c/ex_embedded_c.vcxproj
@@ -0,0 +1,161 @@
+\ufeff<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <ItemGroup Label="ProjectConfigurations">
+    <ProjectConfiguration Include="Debug|Win32">
+      <Configuration>Debug</Configuration>
+      <Platform>Win32</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Debug|x64">
+      <Configuration>Debug</Configuration>
+      <Platform>x64</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Release|Win32">
+      <Configuration>Release</Configuration>
+      <Platform>Win32</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Release|x64">
+      <Configuration>Release</Configuration>
+      <Platform>x64</Platform>
+    </ProjectConfiguration>
+  </ItemGroup>
+  <ItemGroup>
+    <ClCompile Include="..\..\examples\embedded_c\embedded_c.c" />
+    <ClCompile Include="..\..\src\civetweb.c" />
+  </ItemGroup>
+  <ItemGroup>
+    <ClInclude Include="..\..\include\civetweb.h" />
+  </ItemGroup>
+  <PropertyGroup Label="Globals">
+    <ProjectGuid>{882EC43C-2EEE-434B-A711-C844108D29C6}</ProjectGuid>
+    <Keyword>Win32Proj</Keyword>
+    <RootNamespace>ex_embedded_c</RootNamespace>
+    <WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
+  </PropertyGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>true</UseDebugLibraries>
+    <PlatformToolset>v140</PlatformToolset>
+    <CharacterSet>MultiByte</CharacterSet>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>true</UseDebugLibraries>
+    <PlatformToolset>v140</PlatformToolset>
+    <CharacterSet>MultiByte</CharacterSet>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>false</UseDebugLibraries>
+    <PlatformToolset>v140</PlatformToolset>
+    <WholeProgramOptimization>true</WholeProgramOptimization>
+    <CharacterSet>MultiByte</CharacterSet>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>false</UseDebugLibraries>
+    <PlatformToolset>v140</PlatformToolset>
+    <WholeProgramOptimization>true</WholeProgramOptimization>
+    <CharacterSet>MultiByte</CharacterSet>
+  </PropertyGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+  <ImportGroup Label="ExtensionSettings">
+  </ImportGroup>
+  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <PropertyGroup Label="UserMacros" />
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <LinkIncremental>true</LinkIncremental>
+    <OutDir>$(SolutionDir)\$(Configuration)\$(Platform)\</OutDir>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+    <LinkIncremental>true</LinkIncremental>
+    <OutDir>$(SolutionDir)\$(Configuration)\$(Platform)\</OutDir>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <LinkIncremental>false</LinkIncremental>
+    <OutDir>$(SolutionDir)\$(Configuration)\$(Platform)\</OutDir>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+    <LinkIncremental>false</LinkIncremental>
+    <OutDir>$(SolutionDir)\$(Configuration)\$(Platform)\</OutDir>
+  </PropertyGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <ClCompile>
+      <PrecompiledHeader>
+      </PrecompiledHeader>
+      <WarningLevel>Level3</WarningLevel>
+      <Optimization>Disabled</Optimization>
+      <PreprocessorDefinitions>USE_IPV6;USE_WEBSOCKET;WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <AdditionalIncludeDirectories>$(ProjectDir)..\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+    </ClCompile>
+    <Link>
+      <SubSystem>Console</SubSystem>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <AdditionalDependencies>winmm.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+    <ClCompile>
+      <PrecompiledHeader>
+      </PrecompiledHeader>
+      <WarningLevel>Level3</WarningLevel>
+      <Optimization>Disabled</Optimization>
+      <PreprocessorDefinitions>USE_IPV6;USE_WEBSOCKET;WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <AdditionalIncludeDirectories>$(ProjectDir)..\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+    </ClCompile>
+    <Link>
+      <SubSystem>Console</SubSystem>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <ClCompile>
+      <WarningLevel>Level3</WarningLevel>
+      <PrecompiledHeader>
+      </PrecompiledHeader>
+      <Optimization>MaxSpeed</Optimization>
+      <FunctionLevelLinking>true</FunctionLevelLinking>
+      <IntrinsicFunctions>true</IntrinsicFunctions>
+      <PreprocessorDefinitions>USE_IPV6;USE_WEBSOCKET;WIN32;_CONSOLE;_CRT_SECURE_NO_DEPRECATE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <AdditionalIncludeDirectories>$(ProjectDir)..\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+    </ClCompile>
+    <Link>
+      <SubSystem>Console</SubSystem>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>
+      <OptimizeReferences>true</OptimizeReferences>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+    <ClCompile>
+      <WarningLevel>Level3</WarningLevel>
+      <PrecompiledHeader>
+      </PrecompiledHeader>
+      <Optimization>MaxSpeed</Optimization>
+      <FunctionLevelLinking>true</FunctionLevelLinking>
+      <IntrinsicFunctions>true</IntrinsicFunctions>
+      <PreprocessorDefinitions>USE_IPV6;USE_WEBSOCKET;WIN32;_CONSOLE;_CRT_SECURE_NO_DEPRECATE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <AdditionalIncludeDirectories>$(ProjectDir)..\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+    </ClCompile>
+    <Link>
+      <SubSystem>Console</SubSystem>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>
+      <OptimizeReferences>true</OptimizeReferences>
+    </Link>
+  </ItemDefinitionGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+  <ImportGroup Label="ExtensionTargets">
+  </ImportGroup>
+</Project>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/VisualStudio/ex_embedded_c/ex_embedded_c.vcxproj.filters
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/VisualStudio/ex_embedded_c/ex_embedded_c.vcxproj.filters b/thirdparty/civetweb-1.9.1/VisualStudio/ex_embedded_c/ex_embedded_c.vcxproj.filters
new file mode 100644
index 0000000..cf2e4d0
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/VisualStudio/ex_embedded_c/ex_embedded_c.vcxproj.filters
@@ -0,0 +1,30 @@
+\ufeff<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <ItemGroup>
+    <Filter Include="Source Files">
+      <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
+      <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
+    </Filter>
+    <Filter Include="Header Files">
+      <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
+      <Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
+    </Filter>
+    <Filter Include="Resource Files">
+      <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
+      <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
+    </Filter>
+  </ItemGroup>
+  <ItemGroup>
+    <ClCompile Include="..\..\src\civetweb.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\examples\embedded_c\embedded_c.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+  </ItemGroup>
+  <ItemGroup>
+    <ClInclude Include="..\..\include\civetweb.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+  </ItemGroup>
+</Project>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/VisualStudio/ex_websocket/ex_websocket.vcxproj
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/VisualStudio/ex_websocket/ex_websocket.vcxproj b/thirdparty/civetweb-1.9.1/VisualStudio/ex_websocket/ex_websocket.vcxproj
new file mode 100644
index 0000000..8076f89
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/VisualStudio/ex_websocket/ex_websocket.vcxproj
@@ -0,0 +1,162 @@
+\ufeff<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <ItemGroup Label="ProjectConfigurations">
+    <ProjectConfiguration Include="Debug|Win32">
+      <Configuration>Debug</Configuration>
+      <Platform>Win32</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Debug|x64">
+      <Configuration>Debug</Configuration>
+      <Platform>x64</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Release|Win32">
+      <Configuration>Release</Configuration>
+      <Platform>Win32</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Release|x64">
+      <Configuration>Release</Configuration>
+      <Platform>x64</Platform>
+    </ProjectConfiguration>
+  </ItemGroup>
+  <PropertyGroup Label="Globals">
+    <ProjectGuid>{58B93E94-7766-435E-93AE-42A2FB5D99B1}</ProjectGuid>
+    <Keyword>Win32Proj</Keyword>
+    <RootNamespace>ex_websocket</RootNamespace>
+    <WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
+  </PropertyGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>true</UseDebugLibraries>
+    <CharacterSet>MultiByte</CharacterSet>
+    <PlatformToolset>v140</PlatformToolset>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>true</UseDebugLibraries>
+    <PlatformToolset>v140</PlatformToolset>
+    <CharacterSet>MultiByte</CharacterSet>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>false</UseDebugLibraries>
+    <WholeProgramOptimization>true</WholeProgramOptimization>
+    <CharacterSet>MultiByte</CharacterSet>
+    <PlatformToolset>v140</PlatformToolset>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>false</UseDebugLibraries>
+    <PlatformToolset>v140</PlatformToolset>
+    <WholeProgramOptimization>true</WholeProgramOptimization>
+    <CharacterSet>MultiByte</CharacterSet>
+  </PropertyGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+  <ImportGroup Label="ExtensionSettings">
+  </ImportGroup>
+  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <PropertyGroup Label="UserMacros" />
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <LinkIncremental>true</LinkIncremental>
+    <OutDir>$(SolutionDir)\$(Configuration)\$(Platform)\</OutDir>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+    <LinkIncremental>true</LinkIncremental>
+    <OutDir>$(SolutionDir)\$(Configuration)\$(Platform)\</OutDir>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <LinkIncremental>false</LinkIncremental>
+    <OutDir>$(SolutionDir)\$(Configuration)\$(Platform)\</OutDir>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+    <LinkIncremental>false</LinkIncremental>
+    <OutDir>$(SolutionDir)\$(Configuration)\$(Platform)\</OutDir>
+  </PropertyGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <ClCompile>
+      <PrecompiledHeader>
+      </PrecompiledHeader>
+      <WarningLevel>Level3</WarningLevel>
+      <Optimization>Disabled</Optimization>
+      <PreprocessorDefinitions>USE_WEBSOCKET;WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <AdditionalIncludeDirectories>$(ProjectDir)..\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+    </ClCompile>
+    <Link>
+      <SubSystem>Console</SubSystem>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+    <ClCompile>
+      <PrecompiledHeader>
+      </PrecompiledHeader>
+      <WarningLevel>Level3</WarningLevel>
+      <Optimization>Disabled</Optimization>
+      <PreprocessorDefinitions>USE_WEBSOCKET;WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <AdditionalIncludeDirectories>$(ProjectDir)..\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+    </ClCompile>
+    <Link>
+      <SubSystem>Console</SubSystem>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <ClCompile>
+      <WarningLevel>Level3</WarningLevel>
+      <PrecompiledHeader>
+      </PrecompiledHeader>
+      <Optimization>MaxSpeed</Optimization>
+      <FunctionLevelLinking>true</FunctionLevelLinking>
+      <IntrinsicFunctions>true</IntrinsicFunctions>
+      <PreprocessorDefinitions>USE_WEBSOCKET;WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <AdditionalIncludeDirectories>$(ProjectDir)..\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+    </ClCompile>
+    <Link>
+      <SubSystem>Console</SubSystem>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>
+      <OptimizeReferences>true</OptimizeReferences>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+    <ClCompile>
+      <WarningLevel>Level3</WarningLevel>
+      <PrecompiledHeader>
+      </PrecompiledHeader>
+      <Optimization>MaxSpeed</Optimization>
+      <FunctionLevelLinking>true</FunctionLevelLinking>
+      <IntrinsicFunctions>true</IntrinsicFunctions>
+      <PreprocessorDefinitions>USE_WEBSOCKET;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <AdditionalIncludeDirectories>$(ProjectDir)..\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+    </ClCompile>
+    <Link>
+      <SubSystem>Console</SubSystem>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>
+      <OptimizeReferences>true</OptimizeReferences>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemGroup>
+    <ClInclude Include="..\..\examples\websocket\WebSockCallbacks.h" />
+    <ClInclude Include="..\..\include\civetweb.h" />
+  </ItemGroup>
+  <ItemGroup>
+    <ClCompile Include="..\..\examples\websocket\WebSockCallbacks.c" />
+    <ClCompile Include="..\..\src\civetweb.c" />
+    <ClCompile Include="..\..\examples\websocket\websocket.c" />
+  </ItemGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+  <ImportGroup Label="ExtensionTargets">
+  </ImportGroup>
+</Project>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/VisualStudio/ex_websocket/ex_websocket.vcxproj.filters
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/VisualStudio/ex_websocket/ex_websocket.vcxproj.filters b/thirdparty/civetweb-1.9.1/VisualStudio/ex_websocket/ex_websocket.vcxproj.filters
new file mode 100644
index 0000000..9adb8fb
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/VisualStudio/ex_websocket/ex_websocket.vcxproj.filters
@@ -0,0 +1,36 @@
+\ufeff<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <ItemGroup>
+    <Filter Include="Source Files">
+      <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
+      <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
+    </Filter>
+    <Filter Include="Header Files">
+      <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
+      <Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
+    </Filter>
+    <Filter Include="Resource Files">
+      <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
+      <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
+    </Filter>
+  </ItemGroup>
+  <ItemGroup>
+    <ClInclude Include="..\..\include\civetweb.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+    <ClInclude Include="..\..\examples\websocket\WebSockCallbacks.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+  </ItemGroup>
+  <ItemGroup>
+    <ClCompile Include="..\..\examples\websocket\websocket.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\civetweb.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\examples\websocket\WebSockCallbacks.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+  </ItemGroup>
+</Project>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/VisualStudio/ex_websocket_client/ex_websocket_client.vcxproj
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/VisualStudio/ex_websocket_client/ex_websocket_client.vcxproj b/thirdparty/civetweb-1.9.1/VisualStudio/ex_websocket_client/ex_websocket_client.vcxproj
new file mode 100644
index 0000000..013c887
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/VisualStudio/ex_websocket_client/ex_websocket_client.vcxproj
@@ -0,0 +1,160 @@
+\ufeff<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <ItemGroup Label="ProjectConfigurations">
+    <ProjectConfiguration Include="Debug|Win32">
+      <Configuration>Debug</Configuration>
+      <Platform>Win32</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Debug|x64">
+      <Configuration>Debug</Configuration>
+      <Platform>x64</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Release|Win32">
+      <Configuration>Release</Configuration>
+      <Platform>Win32</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Release|x64">
+      <Configuration>Release</Configuration>
+      <Platform>x64</Platform>
+    </ProjectConfiguration>
+  </ItemGroup>
+  <PropertyGroup Label="Globals">
+    <ProjectGuid>{58B93E94-7766-435E-93AE-42A2FB5D99B2}</ProjectGuid>
+    <Keyword>Win32Proj</Keyword>
+    <RootNamespace>ex_websocket_client</RootNamespace>
+    <WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
+  </PropertyGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>true</UseDebugLibraries>
+    <CharacterSet>MultiByte</CharacterSet>
+    <PlatformToolset>v140</PlatformToolset>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>true</UseDebugLibraries>
+    <PlatformToolset>v140</PlatformToolset>
+    <CharacterSet>MultiByte</CharacterSet>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>false</UseDebugLibraries>
+    <WholeProgramOptimization>true</WholeProgramOptimization>
+    <CharacterSet>MultiByte</CharacterSet>
+    <PlatformToolset>v140</PlatformToolset>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>false</UseDebugLibraries>
+    <PlatformToolset>v140</PlatformToolset>
+    <WholeProgramOptimization>true</WholeProgramOptimization>
+    <CharacterSet>MultiByte</CharacterSet>
+  </PropertyGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+  <ImportGroup Label="ExtensionSettings">
+  </ImportGroup>
+  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <PropertyGroup Label="UserMacros" />
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <LinkIncremental>true</LinkIncremental>
+    <OutDir>$(SolutionDir)\$(Configuration)\$(Platform)\</OutDir>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+    <LinkIncremental>true</LinkIncremental>
+    <OutDir>$(SolutionDir)\$(Configuration)\$(Platform)\</OutDir>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <LinkIncremental>false</LinkIncremental>
+    <OutDir>$(SolutionDir)\$(Configuration)\$(Platform)\</OutDir>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+    <LinkIncremental>false</LinkIncremental>
+    <OutDir>$(SolutionDir)\$(Configuration)\$(Platform)\</OutDir>
+  </PropertyGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <ClCompile>
+      <PrecompiledHeader>
+      </PrecompiledHeader>
+      <WarningLevel>Level3</WarningLevel>
+      <Optimization>Disabled</Optimization>
+      <PreprocessorDefinitions>USE_WEBSOCKET;WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <AdditionalIncludeDirectories>$(ProjectDir)..\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+    </ClCompile>
+    <Link>
+      <SubSystem>Console</SubSystem>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+    <ClCompile>
+      <PrecompiledHeader>
+      </PrecompiledHeader>
+      <WarningLevel>Level3</WarningLevel>
+      <Optimization>Disabled</Optimization>
+      <PreprocessorDefinitions>USE_WEBSOCKET;WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <AdditionalIncludeDirectories>$(ProjectDir)..\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+    </ClCompile>
+    <Link>
+      <SubSystem>Console</SubSystem>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <ClCompile>
+      <WarningLevel>Level3</WarningLevel>
+      <PrecompiledHeader>
+      </PrecompiledHeader>
+      <Optimization>MaxSpeed</Optimization>
+      <FunctionLevelLinking>true</FunctionLevelLinking>
+      <IntrinsicFunctions>true</IntrinsicFunctions>
+      <PreprocessorDefinitions>USE_WEBSOCKET;WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <AdditionalIncludeDirectories>$(ProjectDir)..\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+    </ClCompile>
+    <Link>
+      <SubSystem>Console</SubSystem>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>
+      <OptimizeReferences>true</OptimizeReferences>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+    <ClCompile>
+      <WarningLevel>Level3</WarningLevel>
+      <PrecompiledHeader>
+      </PrecompiledHeader>
+      <Optimization>MaxSpeed</Optimization>
+      <FunctionLevelLinking>true</FunctionLevelLinking>
+      <IntrinsicFunctions>true</IntrinsicFunctions>
+      <PreprocessorDefinitions>USE_WEBSOCKET;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <AdditionalIncludeDirectories>$(ProjectDir)..\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+    </ClCompile>
+    <Link>
+      <SubSystem>Console</SubSystem>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>
+      <OptimizeReferences>true</OptimizeReferences>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemGroup>
+    <ClInclude Include="..\..\include\civetweb.h" />
+  </ItemGroup>
+  <ItemGroup>
+    <ClCompile Include="..\..\src\civetweb.c" />
+    <ClCompile Include="..\..\examples\websocket_client\websocket_client.c" />
+  </ItemGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+  <ImportGroup Label="ExtensionTargets">
+  </ImportGroup>
+</Project>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/VisualStudio/ex_websocket_client/ex_websocket_client.vcxproj.filters
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/VisualStudio/ex_websocket_client/ex_websocket_client.vcxproj.filters b/thirdparty/civetweb-1.9.1/VisualStudio/ex_websocket_client/ex_websocket_client.vcxproj.filters
new file mode 100644
index 0000000..c91ce3e
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/VisualStudio/ex_websocket_client/ex_websocket_client.vcxproj.filters
@@ -0,0 +1,30 @@
+\ufeff<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <ItemGroup>
+    <Filter Include="Source Files">
+      <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
+      <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
+    </Filter>
+    <Filter Include="Header Files">
+      <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
+      <Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
+    </Filter>
+    <Filter Include="Resource Files">
+      <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
+      <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
+    </Filter>
+  </ItemGroup>
+  <ItemGroup>
+    <ClInclude Include="..\..\include\civetweb.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+  </ItemGroup>
+  <ItemGroup>
+    <ClCompile Include="..\..\examples\websocket_client\websocket_client.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\civetweb.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+  </ItemGroup>
+</Project>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/VisualStudio/lua_lib/lua_lib.vcxproj
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/VisualStudio/lua_lib/lua_lib.vcxproj b/thirdparty/civetweb-1.9.1/VisualStudio/lua_lib/lua_lib.vcxproj
new file mode 100644
index 0000000..33d007f
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/VisualStudio/lua_lib/lua_lib.vcxproj
@@ -0,0 +1,191 @@
+\ufeff<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <ItemGroup Label="ProjectConfigurations">
+    <ProjectConfiguration Include="Debug|Win32">
+      <Configuration>Debug</Configuration>
+      <Platform>Win32</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Debug|x64">
+      <Configuration>Debug</Configuration>
+      <Platform>x64</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Release|Win32">
+      <Configuration>Release</Configuration>
+      <Platform>Win32</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Release|x64">
+      <Configuration>Release</Configuration>
+      <Platform>x64</Platform>
+    </ProjectConfiguration>
+  </ItemGroup>
+  <PropertyGroup Label="Globals">
+    <ProjectGuid>{8F5E5D77-D269-4665-9E27-1045DA6CF0D8}</ProjectGuid>
+    <Keyword>Win32Proj</Keyword>
+    <RootNamespace>lua_lib</RootNamespace>
+    <WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
+  </PropertyGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
+    <ConfigurationType>StaticLibrary</ConfigurationType>
+    <UseDebugLibraries>true</UseDebugLibraries>
+    <CharacterSet>MultiByte</CharacterSet>
+    <PlatformToolset>v140</PlatformToolset>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
+    <ConfigurationType>StaticLibrary</ConfigurationType>
+    <UseDebugLibraries>true</UseDebugLibraries>
+    <PlatformToolset>v140</PlatformToolset>
+    <CharacterSet>MultiByte</CharacterSet>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
+    <ConfigurationType>StaticLibrary</ConfigurationType>
+    <UseDebugLibraries>false</UseDebugLibraries>
+    <WholeProgramOptimization>true</WholeProgramOptimization>
+    <CharacterSet>MultiByte</CharacterSet>
+    <PlatformToolset>v140</PlatformToolset>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
+    <ConfigurationType>StaticLibrary</ConfigurationType>
+    <UseDebugLibraries>false</UseDebugLibraries>
+    <PlatformToolset>v140</PlatformToolset>
+    <WholeProgramOptimization>true</WholeProgramOptimization>
+    <CharacterSet>MultiByte</CharacterSet>
+  </PropertyGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+  <ImportGroup Label="ExtensionSettings">
+  </ImportGroup>
+  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <PropertyGroup Label="UserMacros" />
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+    <OutDir>$(SolutionDir)\$(Configuration)\$(Platform)\</OutDir>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+    <OutDir>$(SolutionDir)\$(Configuration)\$(Platform)\</OutDir>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <OutDir>$(SolutionDir)\$(Configuration)\$(Platform)\</OutDir>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <OutDir>$(SolutionDir)\$(Configuration)\$(Platform)\</OutDir>
+  </PropertyGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <ClCompile>
+      <PrecompiledHeader>
+      </PrecompiledHeader>
+      <WarningLevel>TurnOffAllWarnings</WarningLevel>
+      <Optimization>Disabled</Optimization>
+      <PreprocessorDefinitions>LUA_COMPAT_ALL;THREADSAFE=1;SQLITE_ENABLE_FTS3;SQLITE_ENABLE_FTS3_PARENTHESIS;WIN32;_DEBUG;_WINDOWS;_CRT_SECURE_NO_DEPRECATE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <AdditionalIncludeDirectories>$(ProjectDir)..\..\src\third_party\lua-5.2.4\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+    </ClCompile>
+    <Link>
+      <SubSystem>Windows</SubSystem>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+    <ClCompile>
+      <PrecompiledHeader>
+      </PrecompiledHeader>
+      <WarningLevel>Level3</WarningLevel>
+      <Optimization>Disabled</Optimization>
+      <PreprocessorDefinitions>LUA_COMPAT_ALL;THREADSAFE=1;SQLITE_ENABLE_FTS3;SQLITE_ENABLE_FTS3_PARENTHESIS;WIN32;_DEBUG;_WINDOWS;_CRT_SECURE_NO_DEPRECATE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <AdditionalIncludeDirectories>$(ProjectDir)..\..\src\third_party\lua-5.2.4\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+    </ClCompile>
+    <Link>
+      <SubSystem>Windows</SubSystem>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <ClCompile>
+      <WarningLevel>Level3</WarningLevel>
+      <PrecompiledHeader>
+      </PrecompiledHeader>
+      <Optimization>MaxSpeed</Optimization>
+      <FunctionLevelLinking>true</FunctionLevelLinking>
+      <IntrinsicFunctions>true</IntrinsicFunctions>
+      <PreprocessorDefinitions>LUA_COMPAT_ALL;THREADSAFE=1;SQLITE_ENABLE_FTS3;SQLITE_ENABLE_FTS3_PARENTHESIS;WIN32;NDEBUG;_WINDOWS;_CRT_SECURE_NO_DEPRECATE;_CRT_SECURE_NO_WARNINGS;_CRT_SECURE_NO_DEPRECATE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <AdditionalIncludeDirectories>$(ProjectDir)..\..\src\third_party\lua-5.2.4\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+    </ClCompile>
+    <Link>
+      <SubSystem>Windows</SubSystem>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>
+      <OptimizeReferences>true</OptimizeReferences>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+    <ClCompile>
+      <WarningLevel>Level3</WarningLevel>
+      <PrecompiledHeader>
+      </PrecompiledHeader>
+      <Optimization>MaxSpeed</Optimization>
+      <FunctionLevelLinking>true</FunctionLevelLinking>
+      <IntrinsicFunctions>true</IntrinsicFunctions>
+      <PreprocessorDefinitions>LUA_COMPAT_ALL;THREADSAFE=1;SQLITE_ENABLE_FTS3;SQLITE_ENABLE_FTS3_PARENTHESIS;WIN32;NDEBUG;_WINDOWS;_CRT_SECURE_NO_DEPRECATE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <AdditionalIncludeDirectories>$(ProjectDir)..\..\src\third_party\lua-5.2.4\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+    </ClCompile>
+    <Link>
+      <SubSystem>Windows</SubSystem>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>
+      <OptimizeReferences>true</OptimizeReferences>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemGroup>
+    <ClCompile Include="..\..\src\third_party\lfs.c" />
+    <ClCompile Include="..\..\src\third_party\lua-5.2.4\src\lapi.c" />
+    <ClCompile Include="..\..\src\third_party\lua-5.2.4\src\lauxlib.c" />
+    <ClCompile Include="..\..\src\third_party\lua-5.2.4\src\lbaselib.c" />
+    <ClCompile Include="..\..\src\third_party\lua-5.2.4\src\lbitlib.c" />
+    <ClCompile Include="..\..\src\third_party\lua-5.2.4\src\lcode.c" />
+    <ClCompile Include="..\..\src\third_party\lua-5.2.4\src\lcorolib.c" />
+    <ClCompile Include="..\..\src\third_party\lua-5.2.4\src\lctype.c" />
+    <ClCompile Include="..\..\src\third_party\lua-5.2.4\src\ldblib.c" />
+    <ClCompile Include="..\..\src\third_party\lua-5.2.4\src\ldebug.c" />
+    <ClCompile Include="..\..\src\third_party\lua-5.2.4\src\ldo.c" />
+    <ClCompile Include="..\..\src\third_party\lua-5.2.4\src\ldump.c" />
+    <ClCompile Include="..\..\src\third_party\lua-5.2.4\src\lfunc.c" />
+    <ClCompile Include="..\..\src\third_party\lua-5.2.4\src\lgc.c" />
+    <ClCompile Include="..\..\src\third_party\lua-5.2.4\src\linit.c" />
+    <ClCompile Include="..\..\src\third_party\lua-5.2.4\src\liolib.c" />
+    <ClCompile Include="..\..\src\third_party\lua-5.2.4\src\llex.c" />
+    <ClCompile Include="..\..\src\third_party\lua-5.2.4\src\lmathlib.c" />
+    <ClCompile Include="..\..\src\third_party\lua-5.2.4\src\lmem.c" />
+    <ClCompile Include="..\..\src\third_party\lua-5.2.4\src\loadlib.c" />
+    <ClCompile Include="..\..\src\third_party\lua-5.2.4\src\lobject.c" />
+    <ClCompile Include="..\..\src\third_party\lua-5.2.4\src\lopcodes.c" />
+    <ClCompile Include="..\..\src\third_party\lua-5.2.4\src\loslib.c" />
+    <ClCompile Include="..\..\src\third_party\lua-5.2.4\src\lparser.c" />
+    <ClCompile Include="..\..\src\third_party\lua-5.2.4\src\lstate.c" />
+    <ClCompile Include="..\..\src\third_party\lua-5.2.4\src\lstring.c" />
+    <ClCompile Include="..\..\src\third_party\lua-5.2.4\src\lstrlib.c" />
+    <ClCompile Include="..\..\src\third_party\lua-5.2.4\src\ltable.c" />
+    <ClCompile Include="..\..\src\third_party\lua-5.2.4\src\ltablib.c" />
+    <ClCompile Include="..\..\src\third_party\lua-5.2.4\src\ltm.c" />
+    <ClCompile Include="..\..\src\third_party\lua-5.2.4\src\lundump.c" />
+    <ClCompile Include="..\..\src\third_party\lua-5.2.4\src\lvm.c" />
+    <ClCompile Include="..\..\src\third_party\lua-5.2.4\src\lzio.c" />
+    <ClCompile Include="..\..\src\third_party\lsqlite3.c" />
+    <ClCompile Include="..\..\src\third_party\LuaXML_lib.c" />
+    <ClCompile Include="..\..\src\third_party\sqlite3.c" />
+  </ItemGroup>
+  <ItemGroup>
+    <ClInclude Include="..\..\src\third_party\lfs.h" />
+    <ClInclude Include="..\..\src\third_party\sqlite3.h" />
+  </ItemGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+  <ImportGroup Label="ExtensionTargets">
+  </ImportGroup>
+</Project>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/VisualStudio/lua_lib/lua_lib.vcxproj.filters
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/VisualStudio/lua_lib/lua_lib.vcxproj.filters b/thirdparty/civetweb-1.9.1/VisualStudio/lua_lib/lua_lib.vcxproj.filters
new file mode 100644
index 0000000..657c5f2
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/VisualStudio/lua_lib/lua_lib.vcxproj.filters
@@ -0,0 +1,135 @@
+\ufeff<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <ItemGroup>
+    <Filter Include="Source Files">
+      <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
+      <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
+    </Filter>
+    <Filter Include="Header Files">
+      <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
+      <Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
+    </Filter>
+    <Filter Include="Resource Files">
+      <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
+      <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
+    </Filter>
+  </ItemGroup>
+  <ItemGroup>
+    <ClCompile Include="..\..\src\third_party\lsqlite3.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\third_party\sqlite3.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\third_party\lfs.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\third_party\lua-5.2.4\src\lapi.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\third_party\lua-5.2.4\src\lauxlib.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\third_party\lua-5.2.4\src\lbaselib.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\third_party\lua-5.2.4\src\lbitlib.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\third_party\lua-5.2.4\src\lcode.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\third_party\lua-5.2.4\src\lcorolib.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\third_party\lua-5.2.4\src\lctype.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\third_party\lua-5.2.4\src\ldblib.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\third_party\lua-5.2.4\src\ldebug.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\third_party\lua-5.2.4\src\ldo.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\third_party\lua-5.2.4\src\ldump.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\third_party\lua-5.2.4\src\lfunc.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\third_party\lua-5.2.4\src\lgc.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\third_party\lua-5.2.4\src\linit.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\third_party\lua-5.2.4\src\liolib.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\third_party\lua-5.2.4\src\llex.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\third_party\lua-5.2.4\src\lmathlib.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\third_party\lua-5.2.4\src\lmem.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\third_party\lua-5.2.4\src\loadlib.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\third_party\lua-5.2.4\src\lobject.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\third_party\lua-5.2.4\src\lopcodes.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\third_party\lua-5.2.4\src\loslib.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\third_party\lua-5.2.4\src\lparser.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\third_party\lua-5.2.4\src\lstate.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\third_party\lua-5.2.4\src\lstring.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\third_party\lua-5.2.4\src\lstrlib.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\third_party\lua-5.2.4\src\ltable.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\third_party\lua-5.2.4\src\ltablib.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\third_party\lua-5.2.4\src\ltm.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\third_party\lua-5.2.4\src\lundump.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\third_party\lua-5.2.4\src\lvm.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\third_party\lua-5.2.4\src\lzio.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\third_party\LuaXML_lib.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+  </ItemGroup>
+  <ItemGroup>
+    <ClInclude Include="..\..\src\third_party\sqlite3.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+    <ClInclude Include="..\..\src\third_party\lfs.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+  </ItemGroup>
+</Project>

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/VisualStudio/unit_test/unit_test.vcxproj
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/VisualStudio/unit_test/unit_test.vcxproj b/thirdparty/civetweb-1.9.1/VisualStudio/unit_test/unit_test.vcxproj
new file mode 100644
index 0000000..516c527
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/VisualStudio/unit_test/unit_test.vcxproj
@@ -0,0 +1,104 @@
+\ufeff<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <ItemGroup Label="ProjectConfigurations">
+    <ProjectConfiguration Include="Debug|Win32">
+      <Configuration>Debug</Configuration>
+      <Platform>Win32</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Release|Win32">
+      <Configuration>Release</Configuration>
+      <Platform>Win32</Platform>
+    </ProjectConfiguration>
+  </ItemGroup>
+  <ItemGroup>
+    <ClInclude Include="..\..\include\civetweb.h" />
+    <ClInclude Include="..\..\test\civetweb_check.h" />
+    <ClInclude Include="..\..\test\private.h" />
+    <ClInclude Include="..\..\test\private_exe.h" />
+    <ClInclude Include="..\..\test\public_func.h" />
+    <ClInclude Include="..\..\test\public_server.h" />
+    <ClInclude Include="..\..\test\timertest.h" />
+    <ClInclude Include="..\..\test\shared.h" />
+  </ItemGroup>
+  <ItemGroup>
+    <ClCompile Include="..\..\src\civetweb.c" />
+    <ClCompile Include="..\..\test\private.c" />
+    <ClCompile Include="..\..\test\private_exe.c" />
+    <ClCompile Include="..\..\test\public_func.c" />
+    <ClCompile Include="..\..\test\public_server.c" />
+    <ClInclude Include="..\..\test\timertest.c" />
+    <ClCompile Include="..\..\test\shared.c" />
+  </ItemGroup>
+  <PropertyGroup Label="Globals">
+    <ProjectGuid>{1AC4A7A6-0100-4287-97F4-B95807BE5607}</ProjectGuid>
+    <Keyword>Win32Proj</Keyword>
+    <RootNamespace>unit_test</RootNamespace>
+  </PropertyGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>true</UseDebugLibraries>
+    <CharacterSet>MultiByte</CharacterSet>
+    <PlatformToolset>v140</PlatformToolset>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>false</UseDebugLibraries>
+    <WholeProgramOptimization>true</WholeProgramOptimization>
+    <CharacterSet>MultiByte</CharacterSet>
+    <PlatformToolset>v140</PlatformToolset>
+  </PropertyGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+  <ImportGroup Label="ExtensionSettings">
+  </ImportGroup>
+  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <PropertyGroup Label="UserMacros" />
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <LinkIncremental>true</LinkIncremental>
+    <OutDir>$(SolutionDir)\$(Configuration)\$(Platform)\</OutDir>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <LinkIncremental>false</LinkIncremental>
+    <OutDir>$(SolutionDir)\$(Configuration)\$(Platform)\</OutDir>
+  </PropertyGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <ClCompile>
+      <PrecompiledHeader>
+      </PrecompiledHeader>
+      <WarningLevel>Level3</WarningLevel>
+      <Optimization>Disabled</Optimization>
+      <PreprocessorDefinitions>LOCAL_TEST;REPLACE_CHECK_FOR_LOCAL_DEBUGGING;USE_IPV6;USE_WEBSOCKET;MEMORY_DEBUGGING;WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <AdditionalIncludeDirectories>$(ProjectDir)..\..\src;$(ProjectDir)..\..\include;$(ProjectDir)..\..\src\third_party\lua-5.2.4\src;$(ProjectDir)..\..\..\check-0.10.0\;$(ProjectDir)..\..\..\check-0.10.0\src\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+    </ClCompile>
+    <Link>
+      <SubSystem>Console</SubSystem>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <ClCompile>
+      <WarningLevel>Level3</WarningLevel>
+      <PrecompiledHeader>
+      </PrecompiledHeader>
+      <Optimization>MaxSpeed</Optimization>
+      <FunctionLevelLinking>true</FunctionLevelLinking>
+      <IntrinsicFunctions>true</IntrinsicFunctions>
+      <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <AdditionalIncludeDirectories>$(ProjectDir)..\..\src;$(ProjectDir)..\..\include;$(ProjectDir)..\..\src\third_party\lua-5.2.4\src;$(ProjectDir)..\..\..\check-0.10.0\;$(ProjectDir)..\..\..\check-0.10.0\src\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+    </ClCompile>
+    <Link>
+      <SubSystem>Console</SubSystem>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>
+      <OptimizeReferences>true</OptimizeReferences>
+    </Link>
+  </ItemDefinitionGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+  <ImportGroup Label="ExtensionTargets">
+  </ImportGroup>
+</Project>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/VisualStudio/unit_test/unit_test.vcxproj.filters
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/VisualStudio/unit_test/unit_test.vcxproj.filters b/thirdparty/civetweb-1.9.1/VisualStudio/unit_test/unit_test.vcxproj.filters
new file mode 100644
index 0000000..fde5e11
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/VisualStudio/unit_test/unit_test.vcxproj.filters
@@ -0,0 +1,66 @@
+\ufeff<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <ItemGroup>
+    <Filter Include="Quelldateien">
+      <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
+      <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
+    </Filter>
+    <Filter Include="Headerdateien">
+      <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
+      <Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
+    </Filter>
+    <Filter Include="Ressourcendateien">
+      <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
+      <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
+    </Filter>
+  </ItemGroup>
+  <ItemGroup>
+    <ClInclude Include="..\..\include\civetweb.h">
+      <Filter>Headerdateien</Filter>
+    </ClInclude>
+    <ClInclude Include="..\..\test\public_server.h">
+      <Filter>Headerdateien</Filter>
+    </ClInclude>
+    <ClInclude Include="..\..\test\public_func.h">
+      <Filter>Headerdateien</Filter>
+    </ClInclude>
+    <ClInclude Include="..\..\test\private_exe.h">
+      <Filter>Headerdateien</Filter>
+    </ClInclude>
+    <ClInclude Include="..\..\test\private.h">
+      <Filter>Headerdateien</Filter>
+    </ClInclude>
+    <ClInclude Include="..\..\test\timertest.h">
+      <Filter>Headerdateien</Filter>
+    </ClInclude>
+    <ClInclude Include="..\..\test\shared.h">
+      <Filter>Headerdateien</Filter>
+    </ClInclude>
+    <ClInclude Include="..\..\test\civetweb_check.h">
+      <Filter>Headerdateien</Filter>
+    </ClInclude>
+  </ItemGroup>
+  <ItemGroup>
+    <ClCompile Include="..\..\test\public_server.c">
+      <Filter>Quelldateien</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\test\public_func.c">
+      <Filter>Quelldateien</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\test\private.c">
+      <Filter>Quelldateien</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\test\private_exe.c">
+      <Filter>Quelldateien</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\test\timertest.c">
+      <Filter>Quelldateien</Filter>
+    </ClCompile>    
+    <ClCompile Include="..\..\test\shared.c">
+      <Filter>Quelldateien</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\civetweb.c">
+      <Filter>Quelldateien</Filter>
+    </ClCompile>
+  </ItemGroup>
+</Project>
\ No newline at end of file


[33/51] [partial] nifi-minifi-cpp git commit: MINIFI-183 Added civet 1.9.1 sources Added onScheduled hook Added initial two-way TLS-enabled ListenHTTP implementation

Posted by al...@apache.org.
http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/config/duk_config.h-modular-dll
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/config/duk_config.h-modular-dll b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/config/duk_config.h-modular-dll
new file mode 100644
index 0000000..5d5d013
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/config/duk_config.h-modular-dll
@@ -0,0 +1,3415 @@
+/*
+ *  duk_config.h configuration header generated by genconfig.py.
+ *
+ *  Git commit: cad34ae155acb0846545ca6bf2d29f9463b22bbb
+ *  Git describe: v1.5.2
+ *  Git branch: HEAD
+ *
+ *  Supported platforms:
+ *      - Mac OSX, iPhone, Darwin
+ *      - OpenBSD
+ *      - Generic BSD
+ *      - Atari ST TOS
+ *      - AmigaOS
+ *      - Windows
+ *      - Flashplayer (Crossbridge)
+ *      - QNX
+ *      - TI-Nspire
+ *      - Emscripten
+ *      - Linux
+ *      - Solaris
+ *      - Generic POSIX
+ *      - Cygwin
+ *      - Generic UNIX
+ *      - Generic fallback
+ *
+ *  Supported architectures:
+ *      - x86
+ *      - x64
+ *      - x32
+ *      - ARM 32-bit
+ *      - ARM 64-bit
+ *      - MIPS 32-bit
+ *      - MIPS 64-bit
+ *      - PowerPC 32-bit
+ *      - PowerPC 64-bit
+ *      - SPARC 32-bit
+ *      - SPARC 64-bit
+ *      - SuperH
+ *      - Motorola 68k
+ *      - Emscripten
+ *      - Generic
+ *
+ *  Supported compilers:
+ *      - Clang
+ *      - GCC
+ *      - MSVC
+ *      - Emscripten
+ *      - TinyC
+ *      - VBCC
+ *      - Bruce's C compiler
+ *      - Generic
+ *
+ */
+
+#if !defined(DUK_CONFIG_H_INCLUDED)
+#define DUK_CONFIG_H_INCLUDED
+
+/*
+ *  Intermediate helper defines
+ */
+
+/* DLL build detection */
+#if defined(DUK_OPT_DLL_BUILD)
+#define DUK_F_DLL_BUILD
+#elif defined(DUK_OPT_NO_DLL_BUILD)
+#undef DUK_F_DLL_BUILD
+#else
+/* configured for DLL build */
+#define DUK_F_DLL_BUILD
+#endif
+
+/* Apple OSX, iOS */
+#if defined(__APPLE__)
+#define DUK_F_APPLE
+#endif
+
+/* OpenBSD */
+#if defined(__OpenBSD__) || defined(__OpenBSD)
+#define DUK_F_OPENBSD
+#endif
+
+/* NetBSD */
+#if defined(__NetBSD__) || defined(__NetBSD)
+#define DUK_F_NETBSD
+#endif
+
+/* FreeBSD */
+#if defined(__FreeBSD__) || defined(__FreeBSD)
+#define DUK_F_FREEBSD
+#endif
+
+/* BSD variant */
+#if defined(DUK_F_FREEBSD) || defined(DUK_F_NETBSD) || defined(DUK_F_OPENBSD) || \
+    defined(__bsdi__) || defined(__DragonFly__)
+#define DUK_F_BSD
+#endif
+
+/* Atari ST TOS.  __TOS__ defined by PureC.  No platform define in VBCC
+ * apparently, so to use with VBCC user must define __TOS__ manually.
+  */
+#if defined(__TOS__)
+#define DUK_F_TOS
+#endif
+
+/* Motorola 68K.  Not defined by VBCC, so user must define one of these
+ * manually when using VBCC.
+ */
+#if defined(__m68k__) || defined(M68000) || defined(__MC68K__)
+#define DUK_F_M68K
+#endif
+
+/* AmigaOS.  Neither AMIGA nor __amigaos__ is defined on VBCC, so user must
+ * define 'AMIGA' manually when using VBCC.
+ */
+#if defined(AMIGA) || defined(__amigaos__)
+#define DUK_F_AMIGAOS
+#endif
+
+/* PowerPC */
+#if defined(__powerpc) || defined(__powerpc__) || defined(__PPC__)
+#define DUK_F_PPC
+#if defined(__PPC64__) || defined(__LP64__) || defined(_LP64)
+#define DUK_F_PPC64
+#else
+#define DUK_F_PPC32
+#endif
+#endif
+
+/* Windows, both 32-bit and 64-bit */
+#if defined(_WIN32) || defined(WIN32) || defined(_WIN64) || defined(WIN64) || \
+    defined(__WIN32__) || defined(__TOS_WIN__) || defined(__WINDOWS__)
+#define DUK_F_WINDOWS
+#if defined(_WIN64) || defined(WIN64)
+#define DUK_F_WIN64
+#else
+#define DUK_F_WIN32
+#endif
+#endif
+
+/* Flash player (e.g. Crossbridge) */
+#if defined(__FLASHPLAYER__)
+#define DUK_F_FLASHPLAYER
+#endif
+
+/* QNX */
+#if defined(__QNX__)
+#define DUK_F_QNX
+#endif
+
+/* TI-Nspire (using Ndless) */
+#if defined(_TINSPIRE)
+#define DUK_F_TINSPIRE
+#endif
+
+/* Emscripten (provided explicitly by user), improve if possible */
+#if defined(EMSCRIPTEN)
+#define DUK_F_EMSCRIPTEN
+#endif
+
+/* BCC (Bruce's C compiler): this is a "torture target" for compilation */
+#if defined(__BCC__) || defined(__BCC_VERSION__)
+#define DUK_F_BCC
+#endif
+
+/* Linux */
+#if defined(__linux) || defined(__linux__) || defined(linux)
+#define DUK_F_LINUX
+#endif
+
+/* illumos / Solaris */
+#if defined(__sun) && defined(__SVR4)
+#define DUK_F_SUN
+#endif
+
+/* POSIX */
+#if defined(__posix)
+#define DUK_F_POSIX
+#endif
+
+/* Cygwin */
+#if defined(__CYGWIN__)
+#define DUK_F_CYGWIN
+#endif
+
+/* Generic Unix (includes Cygwin) */
+#if defined(__unix) || defined(__unix__) || defined(unix) || \
+    defined(DUK_F_LINUX) || defined(DUK_F_BSD)
+#define DUK_F_UNIX
+#endif
+
+/* stdint.h not available */
+#if defined(DUK_F_WINDOWS) && defined(_MSC_VER)
+#if (_MSC_VER < 1700)
+/* VS2012+ has stdint.h, < VS2012 does not (but it's available for download). */
+#define DUK_F_NO_STDINT_H
+#endif
+#endif
+#if !defined(DUK_F_NO_STDINT_H) && (defined(DUK_F_TOS) || defined(DUK_F_BCC))
+#define DUK_F_NO_STDINT_H
+#endif
+
+/* C++ */
+#undef DUK_F_CPP
+#if defined(__cplusplus)
+#define DUK_F_CPP
+#endif
+
+/* Intel x86 (32-bit), x64 (64-bit) or x32 (64-bit but 32-bit pointers),
+ * define only one of DUK_F_X86, DUK_F_X64, DUK_F_X32.
+ * https://sites.google.com/site/x32abi/
+ */
+#if defined(__amd64__) || defined(__amd64) || \
+    defined(__x86_64__) || defined(__x86_64) || \
+    defined(_M_X64) || defined(_M_AMD64)
+#if defined(__ILP32__) || defined(_ILP32)
+#define DUK_F_X32
+#else
+#define DUK_F_X64
+#endif
+#elif defined(i386) || defined(__i386) || defined(__i386__) || \
+      defined(__i486__) || defined(__i586__) || defined(__i686__) || \
+      defined(__IA32__) || defined(_M_IX86) || defined(__X86__) || \
+      defined(_X86_) || defined(__THW_INTEL__) || defined(__I86__)
+#if defined(__LP64__) || defined(_LP64)
+/* This should not really happen, but would indicate x64. */
+#define DUK_F_X64
+#else
+#define DUK_F_X86
+#endif
+#endif
+
+/* ARM */
+#if defined(__arm__) || defined(__thumb__) || defined(_ARM) || defined(_M_ARM)
+#define DUK_F_ARM
+#if defined(__LP64__) || defined(_LP64) || defined(__arm64) || defined(__arm64__)
+#define DUK_F_ARM64
+#else
+#define DUK_F_ARM32
+#endif
+#endif
+
+/* MIPS.  Related defines: __MIPSEB__, __MIPSEL__, __mips_isa_rev, __LP64__ */
+#if defined(__mips__) || defined(mips) || defined(_MIPS_ISA) || \
+    defined(_R3000) || defined(_R4000) || defined(_R5900) || \
+    defined(_MIPS_ISA_MIPS1) || defined(_MIPS_ISA_MIPS2) || \
+    defined(_MIPS_ISA_MIPS3) || defined(_MIPS_ISA_MIPS4) || \
+    defined(__mips) || defined(__MIPS__)
+#define DUK_F_MIPS
+#if defined(__LP64__) || defined(_LP64) || defined(__mips64) || \
+    defined(__mips64__) || defined(__mips_n64)
+#define DUK_F_MIPS64
+#else
+#define DUK_F_MIPS32
+#endif
+#endif
+
+/* SPARC */
+#if defined(sparc) || defined(__sparc) || defined(__sparc__)
+#define DUK_F_SPARC
+#if defined(__LP64__) || defined(_LP64)
+#define DUK_F_SPARC64
+#else
+#define DUK_F_SPARC32
+#endif
+#endif
+
+/* SuperH */
+#if defined(__sh__) || \
+    defined(__sh1__) || defined(__SH1__) || \
+    defined(__sh2__) || defined(__SH2__) || \
+    defined(__sh3__) || defined(__SH3__) || \
+    defined(__sh4__) || defined(__SH4__) || \
+    defined(__sh5__) || defined(__SH5__)
+#define DUK_F_SUPERH
+#endif
+
+/* Clang */
+#if defined(__clang__)
+#define DUK_F_CLANG
+#endif
+
+/* C99 or above */
+#undef DUK_F_C99
+#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
+#define DUK_F_C99
+#endif
+
+/* C++11 or above */
+#undef DUK_F_CPP11
+#if defined(__cplusplus) && (__cplusplus >= 201103L)
+#define DUK_F_CPP11
+#endif
+
+/* GCC.  Clang also defines __GNUC__ so don't detect GCC if using Clang. */
+#if defined(__GNUC__) && !defined(__clang__) && !defined(DUK_F_CLANG)
+#define DUK_F_GCC
+#if defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__)
+/* Convenience, e.g. gcc 4.5.1 == 40501; http://stackoverflow.com/questions/6031819/emulating-gccs-builtin-unreachable */
+#define DUK_F_GCC_VERSION  (__GNUC__ * 10000L + __GNUC_MINOR__ * 100L + __GNUC_PATCHLEVEL__)
+#else
+#error cannot figure out gcc version
+#endif
+#endif
+
+/* MinGW.  Also GCC flags (DUK_F_GCC) are enabled now. */
+#if defined(__MINGW32__) || defined(__MINGW64__)
+#define DUK_F_MINGW
+#endif
+
+/* MSVC */
+#if defined(_MSC_VER)
+/* MSVC preprocessor defines: http://msdn.microsoft.com/en-us/library/b0084kay.aspx
+ * _MSC_FULL_VER includes the build number, but it has at least two formats, see e.g.
+ * BOOST_MSVC_FULL_VER in http://www.boost.org/doc/libs/1_52_0/boost/config/compiler/visualc.hpp
+ */
+#define DUK_F_MSVC
+#if defined(_MSC_FULL_VER)
+#if (_MSC_FULL_VER > 100000000)
+#define DUK_F_MSVC_FULL_VER _MSC_FULL_VER
+#else
+#define DUK_F_MSCV_FULL_VER (_MSC_FULL_VER * 10)
+#endif
+#endif
+#endif  /* _MSC_VER */
+
+/* TinyC */
+#if defined(__TINYC__)
+/* http://bellard.org/tcc/tcc-doc.html#SEC9 */
+#define DUK_F_TINYC
+#endif
+
+/* VBCC */
+#if defined(__VBCC__)
+#define DUK_F_VBCC
+#endif
+
+/* Atari Mint */
+#if defined(__MINT__)
+#define DUK_F_MINT
+#endif
+
+/*
+ *  Platform autodetection
+ */
+
+/* Workaround for older C++ compilers before including <inttypes.h>,
+ * see e.g.: https://sourceware.org/bugzilla/show_bug.cgi?id=15366
+ */
+#if defined(__cplusplus) && !defined(__STDC_LIMIT_MACROS)
+#define __STDC_LIMIT_MACROS
+#endif
+#if defined(__cplusplus) && !defined(__STDC_CONSTANT_MACROS)
+#define __STDC_CONSTANT_MACROS
+#endif
+
+#if defined(DUK_F_APPLE)
+/* --- Mac OSX, iPhone, Darwin --- */
+#define DUK_USE_DATE_NOW_GETTIMEOFDAY
+#define DUK_USE_DATE_TZO_GMTIME_R
+#define DUK_USE_DATE_PRS_STRPTIME
+#define DUK_USE_DATE_FMT_STRFTIME
+#include <TargetConditionals.h>
+#include <architecture/byte_order.h>
+#include <sys/param.h>
+#include <sys/time.h>
+#include <time.h>
+
+/* http://stackoverflow.com/questions/5919996/how-to-detect-reliably-mac-os-x-ios-linux-windows-in-c-preprocessor */
+#if TARGET_IPHONE_SIMULATOR
+#define DUK_USE_OS_STRING "iphone-sim"
+#elif TARGET_OS_IPHONE
+#define DUK_USE_OS_STRING "iphone"
+#elif TARGET_OS_MAC
+#define DUK_USE_OS_STRING "osx"
+#else
+#define DUK_USE_OS_STRING "osx-unknown"
+#endif
+
+/* Use _setjmp() on Apple by default, see GH-55. */
+#define DUK_JMPBUF_TYPE       jmp_buf
+#define DUK_SETJMP(jb)        _setjmp((jb))
+#define DUK_LONGJMP(jb)       _longjmp((jb), 1)
+#elif defined(DUK_F_OPENBSD)
+/* --- OpenBSD --- */
+/* http://www.monkey.org/openbsd/archive/ports/0401/msg00089.html */
+#define DUK_USE_DATE_NOW_GETTIMEOFDAY
+#define DUK_USE_DATE_TZO_GMTIME_R
+#define DUK_USE_DATE_PRS_STRPTIME
+#define DUK_USE_DATE_FMT_STRFTIME
+#include <sys/types.h>
+#include <sys/endian.h>
+#include <sys/param.h>
+#include <sys/time.h>
+#include <time.h>
+
+#define DUK_USE_OS_STRING  "openbsd"
+#elif defined(DUK_F_BSD)
+/* --- Generic BSD --- */
+#define DUK_USE_DATE_NOW_GETTIMEOFDAY
+#define DUK_USE_DATE_TZO_GMTIME_R
+#define DUK_USE_DATE_PRS_STRPTIME
+#define DUK_USE_DATE_FMT_STRFTIME
+#include <sys/types.h>
+#include <sys/endian.h>
+#include <sys/param.h>
+#include <sys/time.h>
+#include <time.h>
+
+#define DUK_USE_OS_STRING  "bsd"
+#elif defined(DUK_F_TOS)
+/* --- Atari ST TOS --- */
+#define DUK_USE_DATE_NOW_TIME
+#define DUK_USE_DATE_TZO_GMTIME
+/* no parsing (not an error) */
+#define DUK_USE_DATE_FMT_STRFTIME
+#include <time.h>
+
+#define DUK_USE_OS_STRING  "tos"
+
+/* TOS on M68K is always big endian. */
+#if !defined(DUK_USE_BYTEORDER) && defined(DUK_F_M68K)
+#define DUK_USE_BYTEORDER 3
+#endif
+#elif defined(DUK_F_AMIGAOS)
+/* --- AmigaOS --- */
+#if defined(DUK_F_M68K)
+/* AmigaOS on M68k */
+#define DUK_USE_DATE_NOW_TIME
+#define DUK_USE_DATE_TZO_GMTIME
+/* no parsing (not an error) */
+#define DUK_USE_DATE_FMT_STRFTIME
+#include <time.h>
+#elif defined(DUK_F_PPC)
+#define DUK_USE_DATE_NOW_GETTIMEOFDAY
+#define DUK_USE_DATE_TZO_GMTIME_R
+#define DUK_USE_DATE_PRS_STRPTIME
+#define DUK_USE_DATE_FMT_STRFTIME
+#include <time.h>
+#ifndef UINTPTR_MAX
+#define UINTPTR_MAX UINT_MAX
+#endif
+#else
+#error AmigaOS but not M68K/PPC, not supported now
+#endif
+
+#define DUK_USE_OS_STRING "amigaos"
+
+/* AmigaOS on M68K or PPC is always big endian. */
+#if !defined(DUK_USE_BYTEORDER) && (defined(DUK_F_M68K) || defined(DUK_F_PPC))
+#define DUK_USE_BYTEORDER 3
+#endif
+#elif defined(DUK_F_WINDOWS)
+/* --- Windows --- */
+/* Initial fix: disable secure CRT related warnings when compiling Duktape
+ * itself (must be defined before including Windows headers).  Don't define
+ * for user code including duktape.h.
+ */
+#if defined(DUK_COMPILING_DUKTAPE) && !defined(_CRT_SECURE_NO_WARNINGS)
+#define _CRT_SECURE_NO_WARNINGS
+#endif
+
+/* Windows 32-bit and 64-bit are currently the same. */
+/* MSVC does not have sys/param.h */
+#define DUK_USE_DATE_NOW_WINDOWS
+#define DUK_USE_DATE_TZO_WINDOWS
+/* Note: PRS and FMT are intentionally left undefined for now.  This means
+ * there is no platform specific date parsing/formatting but there is still
+ * the ISO 8601 standard format.
+ */
+#if defined(DUK_COMPILING_DUKTAPE)
+/* Only include when compiling Duktape to avoid polluting application build
+ * with a lot of unnecessary defines.
+ */
+#include <windows.h>
+#endif
+
+#define DUK_USE_OS_STRING "windows"
+
+/* On Windows, assume we're little endian.  Even Itanium which has a
+ * configurable endianness runs little endian in Windows.
+ */
+#if !defined(DUK_USE_BYTEORDER)
+#define DUK_USE_BYTEORDER 1
+#endif
+#elif defined(DUK_F_FLASHPLAYER)
+/* --- Flashplayer (Crossbridge) --- */
+#define DUK_USE_DATE_NOW_GETTIMEOFDAY
+#define DUK_USE_DATE_TZO_GMTIME_R
+#define DUK_USE_DATE_PRS_STRPTIME
+#define DUK_USE_DATE_FMT_STRFTIME
+#include <endian.h>
+#include <sys/param.h>
+#include <sys/time.h>
+#include <time.h>
+
+#define DUK_USE_OS_STRING "flashplayer"
+
+#if !defined(DUK_USE_BYTEORDER) && defined(DUK_F_FLASHPLAYER)
+#define DUK_USE_BYTEORDER 1
+#endif
+#elif defined(DUK_F_QNX)
+/* --- QNX --- */
+#if defined(DUK_F_QNX) && defined(DUK_COMPILING_DUKTAPE)
+/* See: /opt/qnx650/target/qnx6/usr/include/sys/platform.h */
+#define _XOPEN_SOURCE    600
+#define _POSIX_C_SOURCE  200112L
+#endif
+
+#define DUK_USE_DATE_NOW_GETTIMEOFDAY
+#define DUK_USE_DATE_TZO_GMTIME_R
+#define DUK_USE_DATE_PRS_STRPTIME
+#define DUK_USE_DATE_FMT_STRFTIME
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/time.h>
+#include <time.h>
+
+#define DUK_USE_OS_STRING "qnx"
+#elif defined(DUK_F_TINSPIRE)
+/* --- TI-Nspire --- */
+#define DUK_USE_DATE_NOW_GETTIMEOFDAY
+#define DUK_USE_DATE_TZO_GMTIME_R
+#define DUK_USE_DATE_PRS_STRPTIME
+#define DUK_USE_DATE_FMT_STRFTIME
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/time.h>
+#include <time.h>
+
+#define DUK_USE_OS_STRING "tinspire"
+#elif defined(DUK_F_EMSCRIPTEN)
+/* --- Emscripten --- */
+#if defined(DUK_COMPILING_DUKTAPE)
+#ifndef _POSIX_C_SOURCE
+#define _POSIX_C_SOURCE  200809L
+#endif
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE      /* e.g. getdate_r */
+#endif
+#ifndef _XOPEN_SOURCE
+#define _XOPEN_SOURCE    /* e.g. strptime */
+#endif
+#endif  /* DUK_COMPILING_DUKTAPE */
+
+#include <sys/types.h>
+#if defined(DUK_F_BCC)
+/* no endian.h */
+#else
+#include <endian.h>
+#endif  /* DUK_F_BCC */
+#include <sys/param.h>
+#include <sys/time.h>
+#include <time.h>
+#include <stdint.h>
+
+#define DUK_USE_DATE_NOW_GETTIMEOFDAY
+#define DUK_USE_DATE_TZO_GMTIME_R
+#define DUK_USE_DATE_PRS_STRPTIME
+#define DUK_USE_DATE_FMT_STRFTIME
+
+#define DUK_USE_OS_STRING "emscripten"
+#elif defined(DUK_F_LINUX)
+/* --- Linux --- */
+#if defined(DUK_COMPILING_DUKTAPE)
+#ifndef _POSIX_C_SOURCE
+#define _POSIX_C_SOURCE  200809L
+#endif
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE      /* e.g. getdate_r */
+#endif
+#ifndef _XOPEN_SOURCE
+#define _XOPEN_SOURCE    /* e.g. strptime */
+#endif
+#endif  /* DUK_COMPILING_DUKTAPE */
+
+#include <sys/types.h>
+#if defined(DUK_F_BCC)
+/* no endian.h or stdint.h */
+#else
+#include <endian.h>
+#include <stdint.h>
+#endif  /* DUK_F_BCC */
+#include <sys/param.h>
+#include <sys/time.h>
+#include <time.h>
+
+#define DUK_USE_DATE_NOW_GETTIMEOFDAY
+#define DUK_USE_DATE_TZO_GMTIME_R
+#define DUK_USE_DATE_PRS_STRPTIME
+#define DUK_USE_DATE_FMT_STRFTIME
+
+#define DUK_USE_OS_STRING "linux"
+#elif defined(DUK_F_SUN)
+/* --- Solaris --- */
+#define DUK_USE_DATE_NOW_GETTIMEOFDAY
+#define DUK_USE_DATE_TZO_GMTIME_R
+#define DUK_USE_DATE_PRS_STRPTIME
+#define DUK_USE_DATE_FMT_STRFTIME
+
+#include <sys/types.h>
+#include <ast/endian.h>
+#include <sys/param.h>
+#include <sys/time.h>
+#include <time.h>
+
+#define DUK_USE_OS_STRING "solaris"
+#elif defined(DUK_F_POSIX)
+/* --- Generic POSIX --- */
+#define DUK_USE_DATE_NOW_GETTIMEOFDAY
+#define DUK_USE_DATE_TZO_GMTIME_R
+#define DUK_USE_DATE_PRS_STRPTIME
+#define DUK_USE_DATE_FMT_STRFTIME
+#include <sys/types.h>
+#include <endian.h>
+#include <sys/param.h>
+#include <sys/time.h>
+#include <time.h>
+
+#define DUK_USE_OS_STRING "posix"
+#elif defined(DUK_F_CYGWIN)
+/* --- Cygwin --- */
+/* don't use strptime() for now */
+#define DUK_USE_DATE_NOW_GETTIMEOFDAY
+#define DUK_USE_DATE_TZO_GMTIME_R
+#define DUK_USE_DATE_FMT_STRFTIME
+#include <sys/types.h>
+#include <endian.h>
+#include <sys/param.h>
+#include <sys/time.h>
+#include <time.h>
+
+#define DUK_JMPBUF_TYPE       jmp_buf
+#define DUK_SETJMP(jb)        _setjmp((jb))
+#define DUK_LONGJMP(jb)       _longjmp((jb), 1)
+
+#define DUK_USE_OS_STRING "windows"
+#elif defined(DUK_F_UNIX)
+/* --- Generic UNIX --- */
+#define DUK_USE_DATE_NOW_GETTIMEOFDAY
+#define DUK_USE_DATE_TZO_GMTIME_R
+#define DUK_USE_DATE_PRS_STRPTIME
+#define DUK_USE_DATE_FMT_STRFTIME
+#include <time.h>
+#include <sys/time.h>
+#define DUK_USE_OS_STRING "unknown"
+#else
+/* --- Generic fallback --- */
+/* The most portable current time provider is time(), but it only has a
+ * one second resolution.
+ */
+#define DUK_USE_DATE_NOW_TIME
+
+/* The most portable way to figure out local time offset is gmtime(),
+ * but it's not thread safe so use with caution.
+ */
+#define DUK_USE_DATE_TZO_GMTIME
+
+/* Avoid custom date parsing and formatting for portability. */
+#undef DUK_USE_DATE_PRS_STRPTIME
+#undef DUK_USE_DATE_FMT_STRFTIME
+
+/* Rely on C89 headers only; time.h must be here. */
+#include <time.h>
+
+#define DUK_USE_OS_STRING "unknown"
+#endif  /* autodetect platform */
+
+/* Shared includes: C89 */
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdarg.h>  /* varargs */
+#include <setjmp.h>
+#include <stddef.h>  /* e.g. ptrdiff_t */
+#include <math.h>
+#include <limits.h>
+
+/* date.h is omitted, and included per platform */
+
+/* Shared includes: stdint.h is C99 */
+#if defined(DUK_F_NO_STDINT_H)
+/* stdint.h not available */
+#else
+/* Technically C99 (C++11) but found in many systems.  On some systems
+ * __STDC_LIMIT_MACROS and __STDC_CONSTANT_MACROS must be defined before
+ * including stdint.h (see above).
+ */
+#include <stdint.h>
+#endif
+
+#if defined(DUK_F_CPP)
+#include <exception>  /* std::exception */
+#endif
+
+/*
+ *  Architecture autodetection
+ */
+
+#if defined(DUK_F_X86)
+/* --- x86 --- */
+#define DUK_USE_ARCH_STRING "x86"
+#if !defined(DUK_USE_BYTEORDER)
+#define DUK_USE_BYTEORDER 1
+#endif
+/* XXX: This is technically not guaranteed because it's possible to configure
+ * an x86 to require aligned accesses with Alignment Check (AC) flag.
+ */
+#if !defined(DUK_USE_ALIGN_BY)
+#define DUK_USE_ALIGN_BY 1
+#endif
+#define DUK_USE_PACKED_TVAL
+#define DUK_F_PACKED_TVAL_PROVIDED
+#elif defined(DUK_F_X64)
+/* --- x64 --- */
+#define DUK_USE_ARCH_STRING "x64"
+#if !defined(DUK_USE_BYTEORDER)
+#define DUK_USE_BYTEORDER 1
+#endif
+/* XXX: This is technically not guaranteed because it's possible to configure
+ * an x86 to require aligned accesses with Alignment Check (AC) flag.
+ */
+#if !defined(DUK_USE_ALIGN_BY)
+#define DUK_USE_ALIGN_BY 1
+#endif
+#undef DUK_USE_PACKED_TVAL
+#define DUK_F_PACKED_TVAL_PROVIDED
+#elif defined(DUK_F_X32)
+/* --- x32 --- */
+#define DUK_USE_ARCH_STRING "x32"
+#if !defined(DUK_USE_BYTEORDER)
+#define DUK_USE_BYTEORDER 1
+#endif
+/* XXX: This is technically not guaranteed because it's possible to configure
+ * an x86 to require aligned accesses with Alignment Check (AC) flag.
+ */
+#if !defined(DUK_USE_ALIGN_BY)
+#define DUK_USE_ALIGN_BY 1
+#endif
+#define DUK_USE_PACKED_TVAL
+#define DUK_F_PACKED_TVAL_PROVIDED
+#elif defined(DUK_F_ARM32)
+/* --- ARM 32-bit --- */
+#define DUK_USE_ARCH_STRING "arm32"
+/* Byte order varies, so rely on autodetect. */
+#if !defined(DUK_USE_ALIGN_BY)
+#define DUK_USE_ALIGN_BY 4
+#endif
+#define DUK_USE_PACKED_TVAL
+#define DUK_F_PACKED_TVAL_PROVIDED
+#elif defined(DUK_F_ARM64)
+/* --- ARM 64-bit --- */
+#define DUK_USE_ARCH_STRING "arm64"
+/* Byte order varies, so rely on autodetect. */
+#if !defined(DUK_USE_ALIGN_BY)
+#define DUK_USE_ALIGN_BY 8
+#endif
+#undef DUK_USE_PACKED_TVAL
+#define DUK_F_PACKED_TVAL_PROVIDED
+#elif defined(DUK_F_MIPS32)
+/* --- MIPS 32-bit --- */
+#define DUK_USE_ARCH_STRING "mips32"
+/* MIPS byte order varies so rely on autodetection. */
+/* Based on 'make checkalign' there are no alignment requirements on
+ * Linux MIPS except for doubles, which need align by 4.  Alignment
+ * requirements vary based on target though.
+ */
+#if !defined(DUK_USE_ALIGN_BY)
+#define DUK_USE_ALIGN_BY 4
+#endif
+#define DUK_USE_PACKED_TVAL
+#define DUK_F_PACKED_TVAL_PROVIDED
+#elif defined(DUK_F_MIPS64)
+/* --- MIPS 64-bit --- */
+#define DUK_USE_ARCH_STRING "mips64"
+/* MIPS byte order varies so rely on autodetection. */
+/* Good default is a bit arbitrary because alignment requirements
+ * depend on target.  See https://github.com/svaarala/duktape/issues/102.
+ */
+#if !defined(DUK_USE_ALIGN_BY)
+#define DUK_USE_ALIGN_BY 8
+#endif
+#undef DUK_USE_PACKED_TVAL
+#define DUK_F_PACKED_TVAL_PROVIDED
+#elif defined(DUK_F_PPC32)
+/* --- PowerPC 32-bit --- */
+#define DUK_USE_ARCH_STRING "ppc32"
+#if !defined(DUK_USE_BYTEORDER)
+#define DUK_USE_BYTEORDER 3
+#endif
+#if !defined(DUK_USE_ALIGN_BY)
+#define DUK_USE_ALIGN_BY 8
+#endif
+#define DUK_USE_PACKED_TVAL
+#define DUK_F_PACKED_TVAL_PROVIDED
+#elif defined(DUK_F_PPC64)
+/* --- PowerPC 64-bit --- */
+#define DUK_USE_ARCH_STRING "ppc64"
+#if !defined(DUK_USE_BYTEORDER)
+#define DUK_USE_BYTEORDER 3
+#endif
+#if !defined(DUK_USE_ALIGN_BY)
+#define DUK_USE_ALIGN_BY 8
+#endif
+#undef DUK_USE_PACKED_TVAL
+#define DUK_F_PACKED_TVAL_PROVIDED
+#elif defined(DUK_F_SPARC32)
+/* --- SPARC 32-bit --- */
+#define DUK_USE_ARCH_STRING "sparc32"
+/* SPARC byte order varies so rely on autodetection. */
+#if !defined(DUK_USE_ALIGN_BY)
+#define DUK_USE_ALIGN_BY 8
+#endif
+#define DUK_USE_PACKED_TVAL
+#define DUK_F_PACKED_TVAL_PROVIDED
+#elif defined(DUK_F_SPARC64)
+/* --- SPARC 64-bit --- */
+#define DUK_USE_ARCH_STRING "sparc64"
+/* SPARC byte order varies so rely on autodetection. */
+#if !defined(DUK_USE_ALIGN_BY)
+#define DUK_USE_ALIGN_BY 8
+#endif
+#undef DUK_USE_PACKED_TVAL
+#define DUK_F_PACKED_TVAL_PROVIDED
+#elif defined(DUK_F_SUPERH)
+/* --- SuperH --- */
+#define DUK_USE_ARCH_STRING "sh"
+/* Byte order varies, rely on autodetection. */
+/* Based on 'make checkalign' there are no alignment requirements on
+ * Linux SH4, but align by 4 is probably a good basic default.
+ */
+#if !defined(DUK_USE_ALIGN_BY)
+#define DUK_USE_ALIGN_BY 4
+#endif
+#define DUK_USE_PACKED_TVAL
+#define DUK_F_PACKED_TVAL_PROVIDED
+#elif defined(DUK_F_M68K)
+/* --- Motorola 68k --- */
+#define DUK_USE_ARCH_STRING "m68k"
+#if !defined(DUK_USE_BYTEORDER)
+#define DUK_USE_BYTEORDER 3
+#endif
+#if !defined(DUK_USE_ALIGN_BY)
+#define DUK_USE_ALIGN_BY 8
+#endif
+#define DUK_USE_PACKED_TVAL
+#define DUK_F_PACKED_TVAL_PROVIDED
+#elif defined(DUK_F_EMSCRIPTEN)
+/* --- Emscripten --- */
+#define DUK_USE_ARCH_STRING "emscripten"
+#if !defined(DUK_USE_BYTEORDER)
+#define DUK_USE_BYTEORDER 1
+#endif
+#if !defined(DUK_USE_ALIGN_BY)
+#define DUK_USE_ALIGN_BY 8
+#endif
+#undef DUK_USE_PACKED_TVAL
+#define DUK_F_PACKED_TVAL_PROVIDED
+#else
+/* --- Generic --- */
+/* These are necessary wild guesses. */
+#define DUK_USE_ARCH_STRING "generic"
+/* Rely on autodetection for byte order, alignment, and packed tval. */
+#endif  /* autodetect architecture */
+
+/*
+ *  Compiler autodetection
+ */
+
+#if defined(DUK_F_CLANG)
+/* --- Clang --- */
+#if defined(DUK_F_C99) || defined(DUK_F_CPP11)
+/* C99 / C++11 and above: rely on va_copy() which is required. */
+#define DUK_VA_COPY(dest,src) va_copy(dest,src)
+#else
+/* Clang: assume we have __va_copy() in non-C99 mode. */
+#define DUK_VA_COPY(dest,src) __va_copy(dest,src)
+#endif
+
+#define DUK_NORETURN(decl)  decl __attribute__((noreturn))
+
+#if defined(__clang__) && defined(__has_builtin)
+#if __has_builtin(__builtin_unreachable)
+#define DUK_UNREACHABLE()  do { __builtin_unreachable(); } while (0)
+#endif
+#endif
+
+#define DUK_USE_BRANCH_HINTS
+#define DUK_LIKELY(x)    __builtin_expect((x), 1)
+#define DUK_UNLIKELY(x)  __builtin_expect((x), 0)
+
+#if defined(DUK_F_C99) || defined(DUK_F_CPP11)
+#define DUK_NOINLINE        __attribute__((noinline))
+#define DUK_INLINE          inline
+#define DUK_ALWAYS_INLINE   inline __attribute__((always_inline))
+#endif
+
+#if defined(DUK_F_DLL_BUILD) && defined(DUK_F_WINDOWS)
+/* MSVC dllexport/dllimport: appropriate __declspec depends on whether we're
+ * compiling Duktape or the application.
+ */
+#if defined(DUK_COMPILING_DUKTAPE)
+#define DUK_EXTERNAL_DECL  extern __declspec(dllexport)
+#define DUK_EXTERNAL       __declspec(dllexport)
+#else
+#define DUK_EXTERNAL_DECL  extern __declspec(dllimport)
+#define DUK_EXTERNAL       should_not_happen
+#endif
+#if defined(DUK_SINGLE_FILE)
+#define DUK_INTERNAL_DECL  static
+#define DUK_INTERNAL       static
+#else
+#define DUK_INTERNAL_DECL  extern
+#define DUK_INTERNAL       /*empty*/
+#endif
+#define DUK_LOCAL_DECL     static
+#define DUK_LOCAL          static
+#else
+#define DUK_EXTERNAL_DECL  __attribute__ ((visibility("default"))) extern
+#define DUK_EXTERNAL       __attribute__ ((visibility("default")))
+#if defined(DUK_SINGLE_FILE)
+#if (defined(DUK_F_GCC_VERSION) && DUK_F_GCC_VERSION >= 30101) || defined(DUK_F_CLANG)
+/* Minimize warnings for unused internal functions with GCC >= 3.1.1 and
+ * Clang.  Based on documentation it should suffice to have the attribute
+ * in the declaration only, but in practice some warnings are generated unless
+ * the attribute is also applied to the definition.
+ */
+#define DUK_INTERNAL_DECL  static __attribute__ ((unused))
+#define DUK_INTERNAL       static __attribute__ ((unused))
+#else
+#define DUK_INTERNAL_DECL  static
+#define DUK_INTERNAL       static
+#endif
+#else
+#if (defined(DUK_F_GCC_VERSION) && DUK_F_GCC_VERSION >= 30101) || defined(DUK_F_CLANG)
+#define DUK_INTERNAL_DECL  __attribute__ ((visibility("hidden"))) __attribute__ ((unused)) extern
+#define DUK_INTERNAL       __attribute__ ((visibility("hidden"))) __attribute__ ((unused))
+#else
+#define DUK_INTERNAL_DECL  __attribute__ ((visibility("hidden"))) extern
+#define DUK_INTERNAL       __attribute__ ((visibility("hidden")))
+#endif
+#endif
+#define DUK_LOCAL_DECL     static
+#define DUK_LOCAL          static
+#endif
+
+#if defined(DUK_F_CPP)
+#define DUK_USE_COMPILER_STRING "clang"
+#else
+#define DUK_USE_COMPILER_STRING "clang"
+#endif
+
+#undef DUK_USE_VARIADIC_MACROS
+#if defined(DUK_F_C99) || defined(DUK_F_CPP11)
+#define DUK_USE_VARIADIC_MACROS
+#endif
+
+#define DUK_USE_UNION_INITIALIZERS
+
+#undef DUK_USE_FLEX_C99
+#undef DUK_USE_FLEX_ZEROSIZE
+#undef DUK_USE_FLEX_ONESIZE
+#if defined(DUK_F_C99)
+#define DUK_USE_FLEX_C99
+#else
+#define DUK_USE_FLEX_ZEROSIZE
+#endif
+
+#undef DUK_USE_GCC_PRAGMAS
+#define DUK_USE_PACK_CLANG_ATTR
+#elif defined(DUK_F_GCC)
+/* --- GCC --- */
+#if defined(DUK_F_C99) || defined(DUK_F_CPP11)
+/* C99 / C++11 and above: rely on va_copy() which is required. */
+#define DUK_VA_COPY(dest,src) va_copy(dest,src)
+#else
+/* GCC: assume we have __va_copy() in non-C99 mode. */
+#define DUK_VA_COPY(dest,src) __va_copy(dest,src)
+#endif
+
+#if defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION >= 20500L)
+/* since gcc-2.5 */
+#define DUK_NORETURN(decl)  decl __attribute__((noreturn))
+#endif
+
+#if defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION >= 40500L)
+/* since gcc-4.5 */
+#define DUK_UNREACHABLE()  do { __builtin_unreachable(); } while (0)
+#endif
+
+#define DUK_USE_BRANCH_HINTS
+#if defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION >= 40500L)
+/* GCC: test not very accurate; enable only in relatively recent builds
+ * because of bugs in gcc-4.4 (http://lists.debian.org/debian-gcc/2010/04/msg00000.html)
+ */
+#define DUK_LIKELY(x)    __builtin_expect((x), 1)
+#define DUK_UNLIKELY(x)  __builtin_expect((x), 0)
+#endif
+
+#if (defined(DUK_F_C99) || defined(DUK_F_CPP11)) && \
+    defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION >= 30101)
+#define DUK_NOINLINE        __attribute__((noinline))
+#define DUK_INLINE          inline
+#define DUK_ALWAYS_INLINE   inline __attribute__((always_inline))
+#endif
+
+#if defined(DUK_F_DLL_BUILD) && defined(DUK_F_WINDOWS)
+/* MSVC dllexport/dllimport: appropriate __declspec depends on whether we're
+ * compiling Duktape or the application.
+ */
+#if defined(DUK_COMPILING_DUKTAPE)
+#define DUK_EXTERNAL_DECL  extern __declspec(dllexport)
+#define DUK_EXTERNAL       __declspec(dllexport)
+#else
+#define DUK_EXTERNAL_DECL  extern __declspec(dllimport)
+#define DUK_EXTERNAL       should_not_happen
+#endif
+#if defined(DUK_SINGLE_FILE)
+#define DUK_INTERNAL_DECL  static
+#define DUK_INTERNAL       static
+#else
+#define DUK_INTERNAL_DECL  extern
+#define DUK_INTERNAL       /*empty*/
+#endif
+#define DUK_LOCAL_DECL     static
+#define DUK_LOCAL          static
+#elif defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION >= 40000)
+#define DUK_EXTERNAL_DECL  __attribute__ ((visibility("default"))) extern
+#define DUK_EXTERNAL       __attribute__ ((visibility("default")))
+#if defined(DUK_SINGLE_FILE)
+#if (defined(DUK_F_GCC_VERSION) && DUK_F_GCC_VERSION >= 30101) || defined(DUK_F_CLANG)
+/* Minimize warnings for unused internal functions with GCC >= 3.1.1 and
+ * Clang.  Based on documentation it should suffice to have the attribute
+ * in the declaration only, but in practice some warnings are generated unless
+ * the attribute is also applied to the definition.
+ */
+#define DUK_INTERNAL_DECL  static __attribute__ ((unused))
+#define DUK_INTERNAL       static __attribute__ ((unused))
+#else
+#define DUK_INTERNAL_DECL  static
+#define DUK_INTERNAL       static
+#endif
+#else
+#if (defined(DUK_F_GCC_VERSION) && DUK_F_GCC_VERSION >= 30101) || defined(DUK_F_CLANG)
+#define DUK_INTERNAL_DECL  __attribute__ ((visibility("hidden"))) __attribute__ ((unused)) extern
+#define DUK_INTERNAL       __attribute__ ((visibility("hidden"))) __attribute__ ((unused))
+#else
+#define DUK_INTERNAL_DECL  __attribute__ ((visibility("hidden"))) extern
+#define DUK_INTERNAL       __attribute__ ((visibility("hidden")))
+#endif
+#endif
+#define DUK_LOCAL_DECL     static
+#define DUK_LOCAL          static
+#endif
+
+#if defined(DUK_F_MINGW)
+#if defined(DUK_F_CPP)
+#define DUK_USE_COMPILER_STRING "mingw++"
+#else
+#define DUK_USE_COMPILER_STRING "mingw"
+#endif
+#else
+#if defined(DUK_F_CPP)
+#define DUK_USE_COMPILER_STRING "g++"
+#else
+#define DUK_USE_COMPILER_STRING "gcc"
+#endif
+#endif
+
+#undef DUK_USE_VARIADIC_MACROS
+#if defined(DUK_F_C99) || (defined(DUK_F_CPP11) && defined(__GNUC__))
+#define DUK_USE_VARIADIC_MACROS
+#endif
+
+#define DUK_USE_UNION_INITIALIZERS
+
+#undef DUK_USE_FLEX_C99
+#undef DUK_USE_FLEX_ZEROSIZE
+#undef DUK_USE_FLEX_ONESIZE
+#if defined(DUK_F_C99)
+#define DUK_USE_FLEX_C99
+#else
+#define DUK_USE_FLEX_ZEROSIZE
+#endif
+
+#if defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION >= 40600)
+#define DUK_USE_GCC_PRAGMAS
+#else
+#undef DUK_USE_GCC_PRAGMAS
+#endif
+
+#define DUK_USE_PACK_GCC_ATTR
+#elif defined(DUK_F_MSVC)
+/* --- MSVC --- */
+/* http://msdn.microsoft.com/en-us/library/aa235362(VS.60).aspx */
+#define DUK_NORETURN(decl)  __declspec(noreturn) decl
+
+/* XXX: DUK_UNREACHABLE for msvc? */
+
+#undef DUK_USE_BRANCH_HINTS
+
+/* XXX: DUK_LIKELY, DUK_UNLIKELY for msvc? */
+/* XXX: DUK_NOINLINE, DUK_INLINE, DUK_ALWAYS_INLINE for msvc? */
+
+#if defined(DUK_F_DLL_BUILD) && defined(DUK_F_WINDOWS)
+/* MSVC dllexport/dllimport: appropriate __declspec depends on whether we're
+ * compiling Duktape or the application.
+ */
+#if defined(DUK_COMPILING_DUKTAPE)
+#define DUK_EXTERNAL_DECL  extern __declspec(dllexport)
+#define DUK_EXTERNAL       __declspec(dllexport)
+#else
+#define DUK_EXTERNAL_DECL  extern __declspec(dllimport)
+#define DUK_EXTERNAL       should_not_happen
+#endif
+#if defined(DUK_SINGLE_FILE)
+#define DUK_INTERNAL_DECL  static
+#define DUK_INTERNAL       static
+#else
+#define DUK_INTERNAL_DECL  extern
+#define DUK_INTERNAL       /*empty*/
+#endif
+#define DUK_LOCAL_DECL     static
+#define DUK_LOCAL          static
+#endif
+
+#if defined(DUK_F_CPP)
+#define DUK_USE_COMPILER_STRING "msvc++"
+#else
+#define DUK_USE_COMPILER_STRING "msvc"
+#endif
+
+#undef DUK_USE_VARIADIC_MACROS
+#if defined(DUK_F_C99)
+#define DUK_USE_VARIADIC_MACROS
+#elif defined(_MSC_VER) && (_MSC_VER >= 1400)
+/* VS2005+ should have variadic macros even when they're not C99. */
+#define DUK_USE_VARIADIC_MACROS
+#endif
+
+#undef DUK_USE_UNION_INITIALIZERS
+#if defined(_MSC_VER) && (_MSC_VER >= 1800)
+/* VS2013+ supports union initializers but there's a bug involving union-inside-struct:
+ * https://connect.microsoft.com/VisualStudio/feedback/details/805981
+ * The bug was fixed (at least) in VS2015 so check for VS2015 for now:
+ * https://blogs.msdn.microsoft.com/vcblog/2015/07/01/c-compiler-front-end-fixes-in-vs2015/
+ * Manually tested using VS2013, CL reports 18.00.31101, so enable for VS2013 too.
+ */
+#define DUK_USE_UNION_INITIALIZERS
+#endif
+
+#undef DUK_USE_FLEX_C99
+#undef DUK_USE_FLEX_ZEROSIZE
+#undef DUK_USE_FLEX_ONESIZE
+#if defined(DUK_F_C99)
+#define DUK_USE_FLEX_C99
+#else
+#define DUK_USE_FLEX_ZEROSIZE
+#endif
+
+#undef DUK_USE_GCC_PRAGMAS
+
+#define DUK_USE_PACK_MSVC_PRAGMA
+
+/* These have been tested from VS2008 onwards; may work in older VS versions
+ * too but not enabled by default.
+ */
+#if defined(_MSC_VER) && (_MSC_VER >= 1500)
+#define DUK_NOINLINE        __declspec(noinline)
+#define DUK_INLINE          __inline
+#define DUK_ALWAYS_INLINE   __forceinline
+#endif
+
+#if defined(_MSC_VER) && (_MSC_VER >= 1900)
+#define DUK_SNPRINTF     snprintf
+#define DUK_VSNPRINTF    vsnprintf
+#else
+/* (v)snprintf() is missing before MSVC 2015.  Note that _(v)snprintf() does
+ * NOT NUL terminate on truncation, but Duktape code never assumes that.
+ * http://stackoverflow.com/questions/2915672/snprintf-and-visual-studio-2010
+ */
+#define DUK_SNPRINTF     _snprintf
+#define DUK_VSNPRINTF    _vsnprintf
+#endif
+#elif defined(DUK_F_EMSCRIPTEN)
+/* --- Emscripten --- */
+#define DUK_NORETURN(decl)  decl __attribute__((noreturn))
+
+#if defined(__clang__) && defined(__has_builtin)
+#if __has_builtin(__builtin_unreachable)
+#define DUK_UNREACHABLE()  do { __builtin_unreachable(); } while (0)
+#endif
+#endif
+
+#define DUK_USE_BRANCH_HINTS
+#define DUK_LIKELY(x)    __builtin_expect((x), 1)
+#define DUK_UNLIKELY(x)  __builtin_expect((x), 0)
+
+#if defined(DUK_F_C99) || defined(DUK_F_CPP11)
+#define DUK_NOINLINE        __attribute__((noinline))
+#define DUK_INLINE          inline
+#define DUK_ALWAYS_INLINE   inline __attribute__((always_inline))
+#endif
+
+#define DUK_EXTERNAL_DECL  __attribute__ ((visibility("default"))) extern
+#define DUK_EXTERNAL       __attribute__ ((visibility("default")))
+#if defined(DUK_SINGLE_FILE)
+#if (defined(DUK_F_GCC_VERSION) && DUK_F_GCC_VERSION >= 30101) || defined(DUK_F_CLANG)
+/* Minimize warnings for unused internal functions with GCC >= 3.1.1 and
+ * Clang.  Based on documentation it should suffice to have the attribute
+ * in the declaration only, but in practice some warnings are generated unless
+ * the attribute is also applied to the definition.
+ */
+#define DUK_INTERNAL_DECL  static __attribute__ ((unused))
+#define DUK_INTERNAL       static __attribute__ ((unused))
+#else
+#define DUK_INTERNAL_DECL  static
+#define DUK_INTERNAL       static
+#endif
+#else
+#if (defined(DUK_F_GCC_VERSION) && DUK_F_GCC_VERSION >= 30101) || defined(DUK_F_CLANG)
+#define DUK_INTERNAL_DECL  __attribute__ ((visibility("hidden"))) __attribute__ ((unused)) extern
+#define DUK_INTERNAL       __attribute__ ((visibility("hidden"))) __attribute__ ((unused))
+#else
+#define DUK_INTERNAL_DECL  __attribute__ ((visibility("hidden"))) extern
+#define DUK_INTERNAL       __attribute__ ((visibility("hidden")))
+#endif
+#endif
+#define DUK_LOCAL_DECL     static
+#define DUK_LOCAL          static
+
+#define DUK_USE_COMPILER_STRING "emscripten"
+
+#undef DUK_USE_VARIADIC_MACROS
+#if defined(DUK_F_C99) || defined(DUK_F_CPP11)
+#define DUK_USE_VARIADIC_MACROS
+#endif
+
+#define DUK_USE_UNION_INITIALIZERS
+
+#undef DUK_USE_FLEX_C99
+#undef DUK_USE_FLEX_ZEROSIZE
+#undef DUK_USE_FLEX_ONESIZE
+#if defined(DUK_F_C99)
+#define DUK_USE_FLEX_C99
+#else
+#define DUK_USE_FLEX_ZEROSIZE
+#endif
+
+#undef DUK_USE_GCC_PRAGMAS
+#define DUK_USE_PACK_CLANG_ATTR
+#elif defined(DUK_F_TINYC)
+/* --- TinyC --- */
+#undef DUK_USE_BRANCH_HINTS
+
+#if defined(DUK_F_CPP)
+#define DUK_USE_COMPILER_STRING "tinyc++"
+#else
+#define DUK_USE_COMPILER_STRING "tinyc"
+#endif
+
+/* http://bellard.org/tcc/tcc-doc.html#SEC7 */
+#define DUK_USE_VARIADIC_MACROS
+
+#define DUK_USE_UNION_INITIALIZERS
+
+/* Most portable, wastes space */
+#define DUK_USE_FLEX_ONESIZE
+
+/* Most portable, potentially wastes space */
+#define DUK_USE_PACK_DUMMY_MEMBER
+#elif defined(DUK_F_VBCC)
+/* --- VBCC --- */
+#undef DUK_USE_BRANCH_HINTS
+
+#if defined(DUK_F_CPP)
+#define DUK_USE_COMPILER_STRING "vbcc-c++"
+#else
+#define DUK_USE_COMPILER_STRING "vbcc"
+#endif
+
+#undef DUK_USE_VARIADIC_MACROS
+#if defined(DUK_F_C99) || defined(DUK_F_CPP11)
+#define DUK_USE_VARIADIC_MACROS
+#endif
+
+/* VBCC supports C99 so check only for C99 for union initializer support.
+ * Designated union initializers would possibly work even without a C99 check.
+ */
+#undef DUK_USE_UNION_INITIALIZERS
+#if defined(DUK_F_C99)
+#define DUK_USE_UNION_INITIALIZERS
+#endif
+
+#define DUK_USE_FLEX_ZEROSIZE
+#define DUK_USE_PACK_DUMMY_MEMBER
+#elif defined(DUK_F_BCC)
+/* --- Bruce's C compiler --- */
+#undef DUK_USE_BRANCH_HINTS
+
+#if defined(DUK_F_CPP)
+#define DUK_USE_COMPILER_STRING "bcc++"
+#else
+#define DUK_USE_COMPILER_STRING "bcc"
+#endif
+
+/* Most portable */
+#undef DUK_USE_VARIADIC_MACROS
+
+/* Most portable, wastes space */
+#undef DUK_USE_UNION_INITIALIZERS
+
+/* Most portable, wastes space */
+#define DUK_USE_FLEX_ONESIZE
+
+/* Most portable, potentially wastes space */
+#define DUK_USE_PACK_DUMMY_MEMBER
+
+/* BCC, assume we're on x86. */
+#if !defined(DUK_USE_BYTEORDER)
+#define DUK_USE_BYTEORDER 1
+#endif
+#else
+/* --- Generic --- */
+#undef DUK_USE_BRANCH_HINTS
+
+#if defined(DUK_F_CPP)
+#define DUK_USE_COMPILER_STRING "generic-c++"
+#else
+#define DUK_USE_COMPILER_STRING "generic"
+#endif
+
+#undef DUK_USE_VARIADIC_MACROS
+#if defined(DUK_F_C99) || defined(DUK_F_CPP11)
+#define DUK_USE_VARIADIC_MACROS
+#endif
+
+/* C++ doesn't have standard designated union initializers ({ .foo = 1 }). */
+#undef DUK_USE_UNION_INITIALIZERS
+#if defined(DUK_F_C99)
+#define DUK_USE_UNION_INITIALIZERS
+#endif
+
+/* Most portable, wastes space */
+#define DUK_USE_FLEX_ONESIZE
+
+/* Most portable, potentially wastes space */
+#define DUK_USE_PACK_DUMMY_MEMBER
+#endif  /* autodetect compiler */
+
+/* uclibc */
+#if defined(__UCLIBC__)
+#define DUK_F_UCLIBC
+#endif
+
+/*
+ *  Wrapper typedefs and constants for integer types, also sanity check types.
+ *
+ *  C99 typedefs are quite good but not always available, and we want to avoid
+ *  forcibly redefining the C99 typedefs.  So, there are Duktape wrappers for
+ *  all C99 typedefs and Duktape code should only use these typedefs.  Type
+ *  detection when C99 is not supported is best effort and may end up detecting
+ *  some types incorrectly.
+ *
+ *  Pointer sizes are a portability problem: pointers to different types may
+ *  have a different size and function pointers are very difficult to manage
+ *  portably.
+ *
+ *  http://en.wikipedia.org/wiki/C_data_types#Fixed-width_integer_types
+ *
+ *  Note: there's an interesting corner case when trying to define minimum
+ *  signed integer value constants which leads to the current workaround of
+ *  defining e.g. -0x80000000 as (-0x7fffffffL - 1L).  See doc/code-issues.txt
+ *  for a longer discussion.
+ *
+ *  Note: avoid typecasts and computations in macro integer constants as they
+ *  can then no longer be used in macro relational expressions (such as
+ *  #if DUK_SIZE_MAX < 0xffffffffUL).  There is internal code which relies on
+ *  being able to compare DUK_SIZE_MAX against a limit.
+ */
+
+/* XXX: add feature options to force basic types from outside? */
+
+#if !defined(INT_MAX)
+#error INT_MAX not defined
+#endif
+
+/* Check that architecture is two's complement, standard C allows e.g.
+ * INT_MIN to be -2**31+1 (instead of -2**31).
+ */
+#if defined(INT_MAX) && defined(INT_MIN)
+#if INT_MAX != -(INT_MIN + 1)
+#error platform does not seem complement of two
+#endif
+#else
+#error cannot check complement of two
+#endif
+
+/* Pointer size determination based on __WORDSIZE or architecture when
+ * that's not available.
+ */
+#if defined(DUK_F_X86) || defined(DUK_F_X32) || \
+    defined(DUK_F_M68K) || defined(DUK_F_PPC32) || \
+    defined(DUK_F_BCC) || \
+    (defined(__WORDSIZE) && (__WORDSIZE == 32))
+#define DUK_F_32BIT_PTRS
+#elif defined(DUK_F_X64) || \
+      (defined(__WORDSIZE) && (__WORDSIZE == 64))
+#define DUK_F_64BIT_PTRS
+#else
+/* not sure, not needed with C99 anyway */
+#endif
+
+/* Intermediate define for 'have inttypes.h' */
+#undef DUK_F_HAVE_INTTYPES
+#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && \
+    !(defined(DUK_F_AMIGAOS) && defined(DUK_F_VBCC))
+/* vbcc + AmigaOS has C99 but no inttypes.h */
+#define DUK_F_HAVE_INTTYPES
+#elif defined(__cplusplus) && (__cplusplus >= 201103L)
+/* C++11 apparently ratified stdint.h */
+#define DUK_F_HAVE_INTTYPES
+#endif
+
+/* Basic integer typedefs and limits, preferably from inttypes.h, otherwise
+ * through automatic detection.
+ */
+#if defined(DUK_F_HAVE_INTTYPES)
+/* C99 or compatible */
+
+#define DUK_F_HAVE_64BIT
+#include <inttypes.h>
+
+typedef uint8_t duk_uint8_t;
+typedef int8_t duk_int8_t;
+typedef uint16_t duk_uint16_t;
+typedef int16_t duk_int16_t;
+typedef uint32_t duk_uint32_t;
+typedef int32_t duk_int32_t;
+typedef uint64_t duk_uint64_t;
+typedef int64_t duk_int64_t;
+typedef uint_least8_t duk_uint_least8_t;
+typedef int_least8_t duk_int_least8_t;
+typedef uint_least16_t duk_uint_least16_t;
+typedef int_least16_t duk_int_least16_t;
+typedef uint_least32_t duk_uint_least32_t;
+typedef int_least32_t duk_int_least32_t;
+typedef uint_least64_t duk_uint_least64_t;
+typedef int_least64_t duk_int_least64_t;
+typedef uint_fast8_t duk_uint_fast8_t;
+typedef int_fast8_t duk_int_fast8_t;
+typedef uint_fast16_t duk_uint_fast16_t;
+typedef int_fast16_t duk_int_fast16_t;
+typedef uint_fast32_t duk_uint_fast32_t;
+typedef int_fast32_t duk_int_fast32_t;
+typedef uint_fast64_t duk_uint_fast64_t;
+typedef int_fast64_t duk_int_fast64_t;
+typedef uintptr_t duk_uintptr_t;
+typedef intptr_t duk_intptr_t;
+typedef uintmax_t duk_uintmax_t;
+typedef intmax_t duk_intmax_t;
+
+#define DUK_UINT8_MIN         0
+#define DUK_UINT8_MAX         UINT8_MAX
+#define DUK_INT8_MIN          INT8_MIN
+#define DUK_INT8_MAX          INT8_MAX
+#define DUK_UINT_LEAST8_MIN   0
+#define DUK_UINT_LEAST8_MAX   UINT_LEAST8_MAX
+#define DUK_INT_LEAST8_MIN    INT_LEAST8_MIN
+#define DUK_INT_LEAST8_MAX    INT_LEAST8_MAX
+#define DUK_UINT_FAST8_MIN    0
+#define DUK_UINT_FAST8_MAX    UINT_FAST8_MAX
+#define DUK_INT_FAST8_MIN     INT_FAST8_MIN
+#define DUK_INT_FAST8_MAX     INT_FAST8_MAX
+#define DUK_UINT16_MIN        0
+#define DUK_UINT16_MAX        UINT16_MAX
+#define DUK_INT16_MIN         INT16_MIN
+#define DUK_INT16_MAX         INT16_MAX
+#define DUK_UINT_LEAST16_MIN  0
+#define DUK_UINT_LEAST16_MAX  UINT_LEAST16_MAX
+#define DUK_INT_LEAST16_MIN   INT_LEAST16_MIN
+#define DUK_INT_LEAST16_MAX   INT_LEAST16_MAX
+#define DUK_UINT_FAST16_MIN   0
+#define DUK_UINT_FAST16_MAX   UINT_FAST16_MAX
+#define DUK_INT_FAST16_MIN    INT_FAST16_MIN
+#define DUK_INT_FAST16_MAX    INT_FAST16_MAX
+#define DUK_UINT32_MIN        0
+#define DUK_UINT32_MAX        UINT32_MAX
+#define DUK_INT32_MIN         INT32_MIN
+#define DUK_INT32_MAX         INT32_MAX
+#define DUK_UINT_LEAST32_MIN  0
+#define DUK_UINT_LEAST32_MAX  UINT_LEAST32_MAX
+#define DUK_INT_LEAST32_MIN   INT_LEAST32_MIN
+#define DUK_INT_LEAST32_MAX   INT_LEAST32_MAX
+#define DUK_UINT_FAST32_MIN   0
+#define DUK_UINT_FAST32_MAX   UINT_FAST32_MAX
+#define DUK_INT_FAST32_MIN    INT_FAST32_MIN
+#define DUK_INT_FAST32_MAX    INT_FAST32_MAX
+#define DUK_UINT64_MIN        0
+#define DUK_UINT64_MAX        UINT64_MAX
+#define DUK_INT64_MIN         INT64_MIN
+#define DUK_INT64_MAX         INT64_MAX
+#define DUK_UINT_LEAST64_MIN  0
+#define DUK_UINT_LEAST64_MAX  UINT_LEAST64_MAX
+#define DUK_INT_LEAST64_MIN   INT_LEAST64_MIN
+#define DUK_INT_LEAST64_MAX   INT_LEAST64_MAX
+#define DUK_UINT_FAST64_MIN   0
+#define DUK_UINT_FAST64_MAX   UINT_FAST64_MAX
+#define DUK_INT_FAST64_MIN    INT_FAST64_MIN
+#define DUK_INT_FAST64_MAX    INT_FAST64_MAX
+
+#define DUK_UINTPTR_MIN       0
+#define DUK_UINTPTR_MAX       UINTPTR_MAX
+#define DUK_INTPTR_MIN        INTPTR_MIN
+#define DUK_INTPTR_MAX        INTPTR_MAX
+
+#define DUK_UINTMAX_MIN       0
+#define DUK_UINTMAX_MAX       UINTMAX_MAX
+#define DUK_INTMAX_MIN        INTMAX_MIN
+#define DUK_INTMAX_MAX        INTMAX_MAX
+
+#define DUK_SIZE_MIN          0
+#define DUK_SIZE_MAX          SIZE_MAX
+#undef DUK_SIZE_MAX_COMPUTED
+
+#else  /* C99 types */
+
+/* When C99 types are not available, we use heuristic detection to get
+ * the basic 8, 16, 32, and (possibly) 64 bit types.  The fast/least
+ * types are then assumed to be exactly the same for now: these could
+ * be improved per platform but C99 types are very often now available.
+ * 64-bit types are not available on all platforms; this is OK at least
+ * on 32-bit platforms.
+ *
+ * This detection code is necessarily a bit hacky and can provide typedefs
+ * and defines that won't work correctly on some exotic platform.
+ */
+
+#if (defined(CHAR_BIT) && (CHAR_BIT == 8)) || \
+    (defined(UCHAR_MAX) && (UCHAR_MAX == 255))
+typedef unsigned char duk_uint8_t;
+typedef signed char duk_int8_t;
+#else
+#error cannot detect 8-bit type
+#endif
+
+#if defined(USHRT_MAX) && (USHRT_MAX == 65535UL)
+typedef unsigned short duk_uint16_t;
+typedef signed short duk_int16_t;
+#elif defined(UINT_MAX) && (UINT_MAX == 65535UL)
+/* On some platforms int is 16-bit but long is 32-bit (e.g. PureC) */
+typedef unsigned int duk_uint16_t;
+typedef signed int duk_int16_t;
+#else
+#error cannot detect 16-bit type
+#endif
+
+#if defined(UINT_MAX) && (UINT_MAX == 4294967295UL)
+typedef unsigned int duk_uint32_t;
+typedef signed int duk_int32_t;
+#elif defined(ULONG_MAX) && (ULONG_MAX == 4294967295UL)
+/* On some platforms int is 16-bit but long is 32-bit (e.g. PureC) */
+typedef unsigned long duk_uint32_t;
+typedef signed long duk_int32_t;
+#else
+#error cannot detect 32-bit type
+#endif
+
+/* 64-bit type detection is a bit tricky.
+ *
+ * ULLONG_MAX is a standard define.  __LONG_LONG_MAX__ and __ULONG_LONG_MAX__
+ * are used by at least GCC (even if system headers don't provide ULLONG_MAX).
+ * Some GCC variants may provide __LONG_LONG_MAX__ but not __ULONG_LONG_MAX__.
+ *
+ * ULL / LL constants are rejected / warned about by some compilers, even if
+ * the compiler has a 64-bit type and the compiler/system headers provide an
+ * unsupported constant (ULL/LL)!  Try to avoid using ULL / LL constants.
+ * As a side effect we can only check that e.g. ULONG_MAX is larger than 32
+ * bits but can't be sure it is exactly 64 bits.  Self tests will catch such
+ * cases.
+ */
+#undef DUK_F_HAVE_64BIT
+#if !defined(DUK_F_HAVE_64BIT) && defined(ULONG_MAX)
+#if (ULONG_MAX > 4294967295UL)
+#define DUK_F_HAVE_64BIT
+typedef unsigned long duk_uint64_t;
+typedef signed long duk_int64_t;
+#endif
+#endif
+#if !defined(DUK_F_HAVE_64BIT) && defined(ULLONG_MAX)
+#if (ULLONG_MAX > 4294967295UL)
+#define DUK_F_HAVE_64BIT
+typedef unsigned long long duk_uint64_t;
+typedef signed long long duk_int64_t;
+#endif
+#endif
+#if !defined(DUK_F_HAVE_64BIT) && defined(__ULONG_LONG_MAX__)
+#if (__ULONG_LONG_MAX__ > 4294967295UL)
+#define DUK_F_HAVE_64BIT
+typedef unsigned long long duk_uint64_t;
+typedef signed long long duk_int64_t;
+#endif
+#endif
+#if !defined(DUK_F_HAVE_64BIT) && defined(__LONG_LONG_MAX__)
+#if (__LONG_LONG_MAX__ > 2147483647L)
+#define DUK_F_HAVE_64BIT
+typedef unsigned long long duk_uint64_t;
+typedef signed long long duk_int64_t;
+#endif
+#endif
+#if !defined(DUK_F_HAVE_64BIT) && \
+    (defined(DUK_F_MINGW) || defined(DUK_F_MSVC))
+/* Both MinGW and MSVC have a 64-bit type. */
+#define DUK_F_HAVE_64BIT
+typedef unsigned long duk_uint64_t;
+typedef signed long duk_int64_t;
+#endif
+#if !defined(DUK_F_HAVE_64BIT)
+/* cannot detect 64-bit type, not always needed so don't error */
+#endif
+
+typedef duk_uint8_t duk_uint_least8_t;
+typedef duk_int8_t duk_int_least8_t;
+typedef duk_uint16_t duk_uint_least16_t;
+typedef duk_int16_t duk_int_least16_t;
+typedef duk_uint32_t duk_uint_least32_t;
+typedef duk_int32_t duk_int_least32_t;
+typedef duk_uint8_t duk_uint_fast8_t;
+typedef duk_int8_t duk_int_fast8_t;
+typedef duk_uint16_t duk_uint_fast16_t;
+typedef duk_int16_t duk_int_fast16_t;
+typedef duk_uint32_t duk_uint_fast32_t;
+typedef duk_int32_t duk_int_fast32_t;
+#if defined(DUK_F_HAVE_64BIT)
+typedef duk_uint64_t duk_uint_least64_t;
+typedef duk_int64_t duk_int_least64_t;
+typedef duk_uint64_t duk_uint_fast64_t;
+typedef duk_int64_t duk_int_fast64_t;
+#endif
+#if defined(DUK_F_HAVE_64BIT)
+typedef duk_uint64_t duk_uintmax_t;
+typedef duk_int64_t duk_intmax_t;
+#else
+typedef duk_uint32_t duk_uintmax_t;
+typedef duk_int32_t duk_intmax_t;
+#endif
+
+/* Note: the funny looking computations for signed minimum 16-bit, 32-bit, and
+ * 64-bit values are intentional as the obvious forms (e.g. -0x80000000L) are
+ * -not- portable.  See code-issues.txt for a detailed discussion.
+ */
+#define DUK_UINT8_MIN         0UL
+#define DUK_UINT8_MAX         0xffUL
+#define DUK_INT8_MIN          (-0x80L)
+#define DUK_INT8_MAX          0x7fL
+#define DUK_UINT_LEAST8_MIN   0UL
+#define DUK_UINT_LEAST8_MAX   0xffUL
+#define DUK_INT_LEAST8_MIN    (-0x80L)
+#define DUK_INT_LEAST8_MAX    0x7fL
+#define DUK_UINT_FAST8_MIN    0UL
+#define DUK_UINT_FAST8_MAX    0xffUL
+#define DUK_INT_FAST8_MIN     (-0x80L)
+#define DUK_INT_FAST8_MAX     0x7fL
+#define DUK_UINT16_MIN        0UL
+#define DUK_UINT16_MAX        0xffffUL
+#define DUK_INT16_MIN         (-0x7fffL - 1L)
+#define DUK_INT16_MAX         0x7fffL
+#define DUK_UINT_LEAST16_MIN  0UL
+#define DUK_UINT_LEAST16_MAX  0xffffUL
+#define DUK_INT_LEAST16_MIN   (-0x7fffL - 1L)
+#define DUK_INT_LEAST16_MAX   0x7fffL
+#define DUK_UINT_FAST16_MIN   0UL
+#define DUK_UINT_FAST16_MAX   0xffffUL
+#define DUK_INT_FAST16_MIN    (-0x7fffL - 1L)
+#define DUK_INT_FAST16_MAX    0x7fffL
+#define DUK_UINT32_MIN        0UL
+#define DUK_UINT32_MAX        0xffffffffUL
+#define DUK_INT32_MIN         (-0x7fffffffL - 1L)
+#define DUK_INT32_MAX         0x7fffffffL
+#define DUK_UINT_LEAST32_MIN  0UL
+#define DUK_UINT_LEAST32_MAX  0xffffffffUL
+#define DUK_INT_LEAST32_MIN   (-0x7fffffffL - 1L)
+#define DUK_INT_LEAST32_MAX   0x7fffffffL
+#define DUK_UINT_FAST32_MIN   0UL
+#define DUK_UINT_FAST32_MAX   0xffffffffUL
+#define DUK_INT_FAST32_MIN    (-0x7fffffffL - 1L)
+#define DUK_INT_FAST32_MAX    0x7fffffffL
+
+/* 64-bit constants.  Since LL / ULL constants are not always available,
+ * use computed values.  These values can't be used in preprocessor
+ * comparisons; flag them as such.
+ */
+#if defined(DUK_F_HAVE_64BIT)
+#define DUK_UINT64_MIN        ((duk_uint64_t) 0)
+#define DUK_UINT64_MAX        ((duk_uint64_t) -1)
+#define DUK_INT64_MIN         ((duk_int64_t) (~(DUK_UINT64_MAX >> 1)))
+#define DUK_INT64_MAX         ((duk_int64_t) (DUK_UINT64_MAX >> 1))
+#define DUK_UINT_LEAST64_MIN  DUK_UINT64_MIN
+#define DUK_UINT_LEAST64_MAX  DUK_UINT64_MAX
+#define DUK_INT_LEAST64_MIN   DUK_INT64_MIN
+#define DUK_INT_LEAST64_MAX   DUK_INT64_MAX
+#define DUK_UINT_FAST64_MIN   DUK_UINT64_MIN
+#define DUK_UINT_FAST64_MAX   DUK_UINT64_MAX
+#define DUK_INT_FAST64_MIN    DUK_INT64_MIN
+#define DUK_INT_FAST64_MAX    DUK_INT64_MAX
+#define DUK_UINT64_MIN_COMPUTED
+#define DUK_UINT64_MAX_COMPUTED
+#define DUK_INT64_MIN_COMPUTED
+#define DUK_INT64_MAX_COMPUTED
+#define DUK_UINT_LEAST64_MIN_COMPUTED
+#define DUK_UINT_LEAST64_MAX_COMPUTED
+#define DUK_INT_LEAST64_MIN_COMPUTED
+#define DUK_INT_LEAST64_MAX_COMPUTED
+#define DUK_UINT_FAST64_MIN_COMPUTED
+#define DUK_UINT_FAST64_MAX_COMPUTED
+#define DUK_INT_FAST64_MIN_COMPUTED
+#define DUK_INT_FAST64_MAX_COMPUTED
+#endif
+
+#if defined(DUK_F_HAVE_64BIT)
+#define DUK_UINTMAX_MIN       DUK_UINT64_MIN
+#define DUK_UINTMAX_MAX       DUK_UINT64_MAX
+#define DUK_INTMAX_MIN        DUK_INT64_MIN
+#define DUK_INTMAX_MAX        DUK_INT64_MAX
+#define DUK_UINTMAX_MIN_COMPUTED
+#define DUK_UINTMAX_MAX_COMPUTED
+#define DUK_INTMAX_MIN_COMPUTED
+#define DUK_INTMAX_MAX_COMPUTED
+#else
+#define DUK_UINTMAX_MIN       0UL
+#define DUK_UINTMAX_MAX       0xffffffffUL
+#define DUK_INTMAX_MIN        (-0x7fffffffL - 1L)
+#define DUK_INTMAX_MAX        0x7fffffffL
+#endif
+
+/* This detection is not very reliable. */
+#if defined(DUK_F_32BIT_PTRS)
+typedef duk_int32_t duk_intptr_t;
+typedef duk_uint32_t duk_uintptr_t;
+#define DUK_UINTPTR_MIN       DUK_UINT32_MIN
+#define DUK_UINTPTR_MAX       DUK_UINT32_MAX
+#define DUK_INTPTR_MIN        DUK_INT32_MIN
+#define DUK_INTPTR_MAX        DUK_INT32_MAX
+#elif defined(DUK_F_64BIT_PTRS) && defined(DUK_F_HAVE_64BIT)
+typedef duk_int64_t duk_intptr_t;
+typedef duk_uint64_t duk_uintptr_t;
+#define DUK_UINTPTR_MIN       DUK_UINT64_MIN
+#define DUK_UINTPTR_MAX       DUK_UINT64_MAX
+#define DUK_INTPTR_MIN        DUK_INT64_MIN
+#define DUK_INTPTR_MAX        DUK_INT64_MAX
+#define DUK_UINTPTR_MIN_COMPUTED
+#define DUK_UINTPTR_MAX_COMPUTED
+#define DUK_INTPTR_MIN_COMPUTED
+#define DUK_INTPTR_MAX_COMPUTED
+#else
+#error cannot determine intptr type
+#endif
+
+/* SIZE_MAX may be missing so use an approximate value for it. */
+#undef DUK_SIZE_MAX_COMPUTED
+#if !defined(SIZE_MAX)
+#define DUK_SIZE_MAX_COMPUTED
+#define SIZE_MAX              ((size_t) (-1))
+#endif
+#define DUK_SIZE_MIN          0
+#define DUK_SIZE_MAX          SIZE_MAX
+
+#endif  /* C99 types */
+
+/* A few types are assumed to always exist. */
+typedef size_t duk_size_t;
+typedef ptrdiff_t duk_ptrdiff_t;
+
+/* The best type for an "all around int" in Duktape internals is "at least
+ * 32 bit signed integer" which is most convenient.  Same for unsigned type.
+ * Prefer 'int' when large enough, as it is almost always a convenient type.
+ */
+#if defined(UINT_MAX) && (UINT_MAX >= 0xffffffffUL)
+typedef int duk_int_t;
+typedef unsigned int duk_uint_t;
+#define DUK_INT_MIN           INT_MIN
+#define DUK_INT_MAX           INT_MAX
+#define DUK_UINT_MIN          0
+#define DUK_UINT_MAX          UINT_MAX
+#else
+typedef duk_int_fast32_t duk_int_t;
+typedef duk_uint_fast32_t duk_uint_t;
+#define DUK_INT_MIN           DUK_INT_FAST32_MIN
+#define DUK_INT_MAX           DUK_INT_FAST32_MAX
+#define DUK_UINT_MIN          DUK_UINT_FAST32_MIN
+#define DUK_UINT_MAX          DUK_UINT_FAST32_MAX
+#endif
+
+/* Same as 'duk_int_t' but guaranteed to be a 'fast' variant if this
+ * distinction matters for the CPU.  These types are used mainly in the
+ * executor where it might really matter.
+ */
+typedef duk_int_fast32_t duk_int_fast_t;
+typedef duk_uint_fast32_t duk_uint_fast_t;
+#define DUK_INT_FAST_MIN      DUK_INT_FAST32_MIN
+#define DUK_INT_FAST_MAX      DUK_INT_FAST32_MAX
+#define DUK_UINT_FAST_MIN     DUK_UINT_FAST32_MIN
+#define DUK_UINT_FAST_MAX     DUK_UINT_FAST32_MAX
+
+/* Small integers (16 bits or more) can fall back to the 'int' type, but
+ * have a typedef so they are marked "small" explicitly.
+ */
+typedef int duk_small_int_t;
+typedef unsigned int duk_small_uint_t;
+#define DUK_SMALL_INT_MIN     INT_MIN
+#define DUK_SMALL_INT_MAX     INT_MAX
+#define DUK_SMALL_UINT_MIN    0
+#define DUK_SMALL_UINT_MAX    UINT_MAX
+
+/* Fast variants of small integers, again for really fast paths like the
+ * executor.
+ */
+typedef duk_int_fast16_t duk_small_int_fast_t;
+typedef duk_uint_fast16_t duk_small_uint_fast_t;
+#define DUK_SMALL_INT_FAST_MIN    DUK_INT_FAST16_MIN
+#define DUK_SMALL_INT_FAST_MAX    DUK_INT_FAST16_MAX
+#define DUK_SMALL_UINT_FAST_MIN   DUK_UINT_FAST16_MIN
+#define DUK_SMALL_UINT_FAST_MAX   DUK_UINT_FAST16_MAX
+
+/* Boolean values are represented with the platform 'int'. */
+typedef duk_small_int_t duk_bool_t;
+#define DUK_BOOL_MIN              DUK_SMALL_INT_MIN
+#define DUK_BOOL_MAX              DUK_SMALL_INT_MAX
+
+/* Index values must have at least 32-bit signed range. */
+typedef duk_int_t duk_idx_t;
+#define DUK_IDX_MIN               DUK_INT_MIN
+#define DUK_IDX_MAX               DUK_INT_MAX
+
+/* Unsigned index variant. */
+typedef duk_uint_t duk_uidx_t;
+#define DUK_UIDX_MIN              DUK_UINT_MIN
+#define DUK_UIDX_MAX              DUK_UINT_MAX
+
+/* Array index values, could be exact 32 bits.
+ * Currently no need for signed duk_arridx_t.
+ */
+typedef duk_uint_t duk_uarridx_t;
+#define DUK_UARRIDX_MIN           DUK_UINT_MIN
+#define DUK_UARRIDX_MAX           DUK_UINT_MAX
+
+/* Duktape/C function return value, platform int is enough for now to
+ * represent 0, 1, or negative error code.  Must be compatible with
+ * assigning truth values (e.g. duk_ret_t rc = (foo == bar);).
+ */
+typedef duk_small_int_t duk_ret_t;
+#define DUK_RET_MIN               DUK_SMALL_INT_MIN
+#define DUK_RET_MAX               DUK_SMALL_INT_MAX
+
+/* Error codes are represented with platform int.  High bits are used
+ * for flags and such, so 32 bits are needed.
+ */
+typedef duk_int_t duk_errcode_t;
+#define DUK_ERRCODE_MIN           DUK_INT_MIN
+#define DUK_ERRCODE_MAX           DUK_INT_MAX
+
+/* Codepoint type.  Must be 32 bits or more because it is used also for
+ * internal codepoints.  The type is signed because negative codepoints
+ * are used as internal markers (e.g. to mark EOF or missing argument).
+ * (X)UTF-8/CESU-8 encode/decode take and return an unsigned variant to
+ * ensure duk_uint32_t casts back and forth nicely.  Almost everything
+ * else uses the signed one.
+ */
+typedef duk_int_t duk_codepoint_t;
+typedef duk_uint_t duk_ucodepoint_t;
+#define DUK_CODEPOINT_MIN         DUK_INT_MIN
+#define DUK_CODEPOINT_MAX         DUK_INT_MAX
+#define DUK_UCODEPOINT_MIN        DUK_UINT_MIN
+#define DUK_UCODEPOINT_MAX        DUK_UINT_MAX
+
+/* IEEE float/double typedef. */
+typedef float duk_float_t;
+typedef double duk_double_t;
+
+/* We're generally assuming that we're working on a platform with a 32-bit
+ * address space.  If DUK_SIZE_MAX is a typecast value (which is necessary
+ * if SIZE_MAX is missing), the check must be avoided because the
+ * preprocessor can't do a comparison.
+ */
+#if !defined(DUK_SIZE_MAX)
+#error DUK_SIZE_MAX is undefined, probably missing SIZE_MAX
+#elif !defined(DUK_SIZE_MAX_COMPUTED)
+#if DUK_SIZE_MAX < 0xffffffffUL
+/* On some systems SIZE_MAX can be smaller than max unsigned 32-bit value
+ * which seems incorrect if size_t is (at least) an unsigned 32-bit type.
+ * However, it doesn't seem useful to error out compilation if this is the
+ * case.
+ */
+#endif
+#endif
+
+/* Type for public API calls. */
+typedef struct duk_hthread duk_context;
+
+/* Check whether we should use 64-bit integers or not.
+ *
+ * Quite incomplete now.  Use 64-bit types if detected (C99 or other detection)
+ * unless they are known to be unreliable.  For instance, 64-bit types are
+ * available on VBCC but seem to misbehave.
+ */
+#if defined(DUK_F_HAVE_64BIT) && !defined(DUK_F_VBCC)
+#define DUK_USE_64BIT_OPS
+#else
+#undef DUK_USE_64BIT_OPS
+#endif
+
+/*
+ *  Fill-ins for platform, architecture, and compiler
+ */
+
+#if !defined(DUK_SETJMP)
+#define DUK_JMPBUF_TYPE       jmp_buf
+#define DUK_SETJMP(jb)        setjmp((jb))
+#define DUK_LONGJMP(jb)       longjmp((jb), 1)
+#endif
+
+#if 0
+/* sigsetjmp() alternative */
+#define DUK_JMPBUF_TYPE       sigjmp_buf
+#define DUK_SETJMP(jb)        sigsetjmp((jb))
+#define DUK_LONGJMP(jb)       siglongjmp((jb), 1)
+#endif
+
+typedef FILE duk_file;
+#if !defined(DUK_STDIN)
+#define DUK_STDIN       stdin
+#endif
+#if !defined(DUK_STDOUT)
+#define DUK_STDOUT      stdout
+#endif
+#if !defined(DUK_STDERR)
+#define DUK_STDERR      stderr
+#endif
+
+/* Special naming to avoid conflict with e.g. DUK_FREE() in duk_heap.h
+ * (which is unfortunately named).  May sometimes need replacement, e.g.
+ * some compilers don't handle zero length or NULL correctly in realloc().
+ */
+#if !defined(DUK_ANSI_MALLOC)
+#define DUK_ANSI_MALLOC      malloc
+#endif
+#if !defined(DUK_ANSI_REALLOC)
+#define DUK_ANSI_REALLOC     realloc
+#endif
+#if !defined(DUK_ANSI_CALLOC)
+#define DUK_ANSI_CALLOC      calloc
+#endif
+#if !defined(DUK_ANSI_FREE)
+#define DUK_ANSI_FREE        free
+#endif
+
+/* ANSI C (various versions) and some implementations require that the
+ * pointer arguments to memset(), memcpy(), and memmove() be valid values
+ * even when byte size is 0 (even a NULL pointer is considered invalid in
+ * this context).  Zero-size operations as such are allowed, as long as their
+ * pointer arguments point to a valid memory area.  The DUK_MEMSET(),
+ * DUK_MEMCPY(), and DUK_MEMMOVE() macros require this same behavior, i.e.:
+ * (1) pointers must be valid and non-NULL, (2) zero size must otherwise be
+ * allowed.  If these are not fulfilled, a macro wrapper is needed.
+ *
+ *   http://stackoverflow.com/questions/5243012/is-it-guaranteed-to-be-safe-to-perform-memcpy0-0-0
+ *   http://lists.cs.uiuc.edu/pipermail/llvmdev/2007-October/011065.html
+ *
+ * Not sure what's the required behavior when a pointer points just past the
+ * end of a buffer, which often happens in practice (e.g. zero size memmoves).
+ * For example, if allocation size is 3, the following pointer would not
+ * technically point to a valid memory byte:
+ *
+ *   <-- alloc -->
+ *   | 0 | 1 | 2 | .....
+ *                 ^-- p=3, points after last valid byte (2)
+ */
+#if !defined(DUK_MEMCPY)
+#if defined(DUK_F_UCLIBC)
+/* Old uclibcs have a broken memcpy so use memmove instead (this is overly wide
+ * now on purpose): http://lists.uclibc.org/pipermail/uclibc-cvs/2008-October/025511.html
+ */
+#define DUK_MEMCPY       memmove
+#else
+#define DUK_MEMCPY       memcpy
+#endif
+#endif
+#if !defined(DUK_MEMMOVE)
+#define DUK_MEMMOVE      memmove
+#endif
+#if !defined(DUK_MEMCMP)
+#define DUK_MEMCMP       memcmp
+#endif
+#if !defined(DUK_MEMSET)
+#define DUK_MEMSET       memset
+#endif
+#if !defined(DUK_STRLEN)
+#define DUK_STRLEN       strlen
+#endif
+#if !defined(DUK_STRCMP)
+#define DUK_STRCMP       strcmp
+#endif
+#if !defined(DUK_STRNCMP)
+#define DUK_STRNCMP      strncmp
+#endif
+#if !defined(DUK_PRINTF)
+#define DUK_PRINTF       printf
+#endif
+#if !defined(DUK_FPRINTF)
+#define DUK_FPRINTF      fprintf
+#endif
+#if !defined(DUK_SPRINTF)
+#define DUK_SPRINTF      sprintf
+#endif
+#if !defined(DUK_SNPRINTF)
+/* snprintf() is technically not part of C89 but usually available. */
+#define DUK_SNPRINTF     snprintf
+#endif
+#if !defined(DUK_VSPRINTF)
+#define DUK_VSPRINTF     vsprintf
+#endif
+#if !defined(DUK_VSNPRINTF)
+/* vsnprintf() is technically not part of C89 but usually available. */
+#define DUK_VSNPRINTF    vsnprintf
+#endif
+#if !defined(DUK_SSCANF)
+#define DUK_SSCANF       sscanf
+#endif
+#if !defined(DUK_VSSCANF)
+#define DUK_VSSCANF      vsscanf
+#endif
+#if !defined(DUK_FOPEN)
+#define DUK_FOPEN        fopen
+#endif
+#if !defined(DUK_FCLOSE)
+#define DUK_FCLOSE       fclose
+#endif
+#if !defined(DUK_FREAD)
+#define DUK_FREAD        fread
+#endif
+#if !defined(DUK_FWRITE)
+#define DUK_FWRITE       fwrite
+#endif
+#if !defined(DUK_FSEEK)
+#define DUK_FSEEK        fseek
+#endif
+#if !defined(DUK_FTELL)
+#define DUK_FTELL        ftell
+#endif
+#if !defined(DUK_FFLUSH)
+#define DUK_FFLUSH       fflush
+#endif
+#if !defined(DUK_FPUTC)
+#define DUK_FPUTC        fputc
+#endif
+#if !defined(DUK_MEMZERO)
+#define DUK_MEMZERO(p,n) DUK_MEMSET((p), 0, (n))
+#endif
+#if !defined(DUK_ABORT)
+#define DUK_ABORT        abort
+#endif
+#if !defined(DUK_EXIT)
+#define DUK_EXIT         exit
+#endif
+
+#if !defined(DUK_DOUBLE_2TO32)
+#define DUK_DOUBLE_2TO32     4294967296.0
+#endif
+#if !defined(DUK_DOUBLE_2TO31)
+#define DUK_DOUBLE_2TO31     2147483648.0
+#endif
+
+#if !defined(DUK_DOUBLE_INFINITY)
+#undef DUK_USE_COMPUTED_INFINITY
+#if defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION < 40600)
+/* GCC older than 4.6: avoid overflow warnings related to using INFINITY */
+#define DUK_DOUBLE_INFINITY  (__builtin_inf())
+#elif defined(INFINITY)
+#define DUK_DOUBLE_INFINITY  ((double) INFINITY)
+#elif !defined(DUK_F_VBCC) && !defined(DUK_F_MSVC) && !defined(DUK_F_BCC)
+#define DUK_DOUBLE_INFINITY  (1.0 / 0.0)
+#else
+/* In VBCC (1.0 / 0.0) results in a warning and 0.0 instead of infinity.
+ * Use a computed infinity (initialized when a heap is created at the
+ * latest).
+ */
+#define DUK_USE_COMPUTED_INFINITY
+#define DUK_DOUBLE_INFINITY  duk_computed_infinity
+#endif
+#endif
+
+#if !defined(DUK_DOUBLE_NAN)
+#undef DUK_USE_COMPUTED_NAN
+#if defined(NAN)
+#define DUK_DOUBLE_NAN       NAN
+#elif !defined(DUK_F_VBCC) && !defined(DUK_F_MSVC) && !defined(DUK_F_BCC)
+#define DUK_DOUBLE_NAN       (0.0 / 0.0)
+#else
+/* In VBCC (0.0 / 0.0) results in a warning and 0.0 instead of NaN.
+ * In MSVC (VS2010 Express) (0.0 / 0.0) results in a compile error.
+ * Use a computed NaN (initialized when a heap is created at the
+ * latest).
+ */
+#define DUK_USE_COMPUTED_NAN
+#define DUK_DOUBLE_NAN       duk_computed_nan
+#endif
+#endif
+
+/* Many platforms are missing fpclassify() and friends, so use replacements
+ * if necessary.  The replacement constants (FP_NAN etc) can be anything but
+ * match Linux constants now.
+ */
+#undef DUK_USE_REPL_FPCLASSIFY
+#undef DUK_USE_REPL_SIGNBIT
+#undef DUK_USE_REPL_ISFINITE
+#undef DUK_USE_REPL_ISNAN
+#undef DUK_USE_REPL_ISINF
+
+/* Complex condition broken into separate parts. */
+#undef DUK_F_USE_REPL_ALL
+#if !(defined(FP_NAN) && defined(FP_INFINITE) && defined(FP_ZERO) && \
+      defined(FP_SUBNORMAL) && defined(FP_NORMAL))
+/* Missing some obvious constants. */
+#define DUK_F_USE_REPL_ALL
+#elif defined(DUK_F_AMIGAOS) && defined(DUK_F_VBCC)
+/* VBCC is missing the built-ins even in C99 mode (perhaps a header issue). */
+#define DUK_F_USE_REPL_ALL
+#elif defined(DUK_F_AMIGAOS) && defined(DUK_F_M68K)
+/* AmigaOS + M68K seems to have math issues even when using GCC cross
+ * compilation.  Use replacements for all AmigaOS versions on M68K
+ * regardless of compiler.
+ */
+#define DUK_F_USE_REPL_ALL
+#elif defined(DUK_F_FREEBSD) && defined(DUK_F_CLANG)
+/* Placeholder fix for (detection is wider than necessary):
+ * http://llvm.org/bugs/show_bug.cgi?id=17788
+ */
+#define DUK_F_USE_REPL_ALL
+#elif defined(DUK_F_UCLIBC)
+/* At least some uclibc versions have broken floating point math.  For
+ * example, fpclassify() can incorrectly classify certain NaN formats.
+ * To be safe, use replacements.
+ */
+#define DUK_F_USE_REPL_ALL
+#endif
+
+#if defined(DUK_F_USE_REPL_ALL)
+#define DUK_USE_REPL_FPCLASSIFY
+#define DUK_USE_REPL_SIGNBIT
+#define DUK_USE_REPL_ISFINITE
+#define DUK_USE_REPL_ISNAN
+#define DUK_USE_REPL_ISINF
+#define DUK_FPCLASSIFY       duk_repl_fpclassify
+#define DUK_SIGNBIT          duk_repl_signbit
+#define DUK_ISFINITE         duk_repl_isfinite
+#define DUK_ISNAN            duk_repl_isnan
+#define DUK_ISINF            duk_repl_isinf
+#define DUK_FP_NAN           0
+#define DUK_FP_INFINITE      1
+#define DUK_FP_ZERO          2
+#define DUK_FP_SUBNORMAL     3
+#define DUK_FP_NORMAL        4
+#else
+#define DUK_FPCLASSIFY       fpclassify
+#define DUK_SIGNBIT          signbit
+#define DUK_ISFINITE         isfinite
+#define DUK_ISNAN            isnan
+#define DUK_ISINF            isinf
+#define DUK_FP_NAN           FP_NAN
+#define DUK_FP_INFINITE      FP_INFINITE
+#define DUK_FP_ZERO          FP_ZERO
+#define DUK_FP_SUBNORMAL     FP_SUBNORMAL
+#define DUK_FP_NORMAL        FP_NORMAL
+#endif
+
+#if defined(DUK_F_USE_REPL_ALL)
+#undef DUK_F_USE_REPL_ALL
+#endif
+
+/* Some math functions are C99 only.  This is also an issue with some
+ * embedded environments using uclibc where uclibc has been configured
+ * not to provide some functions.  For now, use replacements whenever
+ * using uclibc.
+ */
+#undef DUK_USE_MATH_FMIN
+#undef DUK_USE_MATH_FMAX
+#undef DUK_USE_MATH_ROUND
+#if defined(DUK_F_UCLIBC)
+/* uclibc may be missing these */
+#elif defined(DUK_F_AMIGAOS) && defined(DUK_F_VBCC)
+/* vbcc + AmigaOS may be missing these */
+#elif defined(DUK_F_MINT)
+/* mint clib is missing these */
+#elif !defined(DUK_F_C99) && !defined(DUK_F_CPP11)
+/* build is not C99 or C++11, play it safe */
+#else
+/* C99 or C++11, no known issues */
+#define DUK_USE_MATH_FMIN
+#define DUK_USE_MATH_FMAX
+#define DUK_USE_MATH_ROUND
+#endif
+
+/* These functions don't currently need replacement but are wrapped for
+ * completeness.  Because these are used as function pointers, they need
+ * to be defined as concrete C functions (not macros).
+ */
+#if !defined(DUK_FABS)
+#define DUK_FABS             fabs
+#endif
+#if !defined(DUK_FMIN)
+#define DUK_FMIN             fmin
+#endif
+#if !defined(DUK_FMAX)
+#define DUK_FMAX             fmax
+#endif
+#if !defined(DUK_FLOOR)
+#define DUK_FLOOR            floor
+#endif
+#if !defined(DUK_CEIL)
+#define DUK_CEIL             ceil
+#endif
+#if !defined(DUK_FMOD)
+#define DUK_FMOD             fmod
+#endif
+#if !defined(DUK_POW)
+#define DUK_POW              pow
+#endif
+#if !defined(DUK_ACOS)
+#define DUK_ACOS             acos
+#endif
+#if !defined(DUK_ASIN)
+#define DUK_ASIN             asin
+#endif
+#if !defined(DUK_ATAN)
+#define DUK_ATAN             atan
+#endif
+#if !defined(DUK_ATAN2)
+#define DUK_ATAN2            atan2
+#endif
+#if !defined(DUK_SIN)
+#define DUK_SIN              sin
+#endif
+#if !defined(DUK_COS)
+#define DUK_COS              cos
+#endif
+#if !defined(DUK_TAN)
+#define DUK_TAN              tan
+#endif
+#if !defined(DUK_EXP)
+#define DUK_EXP              exp
+#endif
+#if !defined(DUK_LOG)
+#define DUK_LOG              log
+#endif
+#if !defined(DUK_SQRT)
+#define DUK_SQRT             sqrt
+#endif
+
+/* NetBSD 6.0 x86 (at least) has a few problems with pow() semantics,
+ * see test-bug-netbsd-math-pow.js.  Use NetBSD specific workaround.
+ * (This might be a wider problem; if so, generalize the define name.)
+ */
+#undef DUK_USE_POW_NETBSD_WORKAROUND
+#if defined(DUK_F_NETBSD)
+#define DUK_USE_POW_NETBSD_WORKAROUND
+#endif
+
+/* Rely as little as possible on compiler behavior for NaN comparison,
+ * signed zero handling, etc.  Currently never activated but may be needed
+ * for broken compilers.
+ */
+#undef DUK_USE_PARANOID_MATH
+
+/* There was a curious bug where test-bi-date-canceling.js would fail e.g.
+ * on 64-bit Ubuntu, gcc-4.8.1, -m32, and no -std=c99.  Some date computations
+ * using doubles would be optimized which then broke some corner case tests.
+ * The problem goes away by adding 'volatile' to the datetime computations.
+ * Not sure what the actual triggering conditions are, but using this on
+ * non-C99 systems solves the known issues and has relatively little cost
+ * on other platforms.
+ */
+#undef DUK_USE_PARANOID_DATE_COMPUTATION
+#if !defined(DUK_F_C99)
+#define DUK_USE_PARANOID_DATE_COMPUTATION
+#endif
+
+/*
+ *  Byte order and double memory layout detection
+ *
+ *  Endianness detection is a major portability hassle because the macros
+ *  and headers are not standardized.  There's even variance across UNIX
+ *  platforms.  Even with "standard" headers, details like underscore count
+ *  varies between platforms, e.g. both __BYTE_ORDER and _BYTE_ORDER are used
+ *  (Crossbridge has a single underscore, for instance).
+ *
+ *  The checks below are structured with this in mind: several approaches are
+ *  used, and at the end we check if any of them worked.  This allows generic
+ *  approaches to be tried first, and platform/compiler specific hacks tried
+ *  last.  As a last resort, the user can force a specific endianness, as it's
+ *  not likely that automatic detection will work on the most exotic platforms.
+ *
+ *  Duktape supports little and big endian machines.  There's also support
+ *  for a hybrid used by some ARM machines where integers are little endian
+ *  but IEEE double values use a mixed order (12345678 -> 43218765).  This
+ *  byte order for doubles is referred to as "mixed endian".
+ */
+
+/* For custom platforms allow user to define byteorder explicitly.
+ * Since endianness headers are not standardized, this is a useful
+ * workaround for custom platforms for which endianness detection
+ * is not directly supported.  Perhaps custom hardware is used and
+ * user cannot submit upstream patches.
+ */
+#if defined(DUK_OPT_FORCE_BYTEORDER)
+#undef DUK_USE_BYTEORDER
+#if (DUK_OPT_FORCE_BYTEORDER == 1)
+#define DUK_USE_BYTEORDER 1
+#elif (DUK_OPT_FORCE_BYTEORDER == 2)
+#define DUK_USE_BYTEORDER 2
+#elif (DUK_OPT_FORCE_BYTEORDER == 3)
+#define DUK_USE_BYTEORDER 3
+#else
+#error invalid DUK_OPT_FORCE_BYTEORDER value
+#endif
+#endif  /* DUK_OPT_FORCE_BYTEORDER */
+
+/* GCC and Clang provide endianness defines as built-in predefines, with
+ * leading and trailing double underscores (e.g. __BYTE_ORDER__).  See
+ * output of "make gccpredefs" and "make clangpredefs".  Clang doesn't
+ * seem to provide __FLOAT_WORD_ORDER__; assume not mixed endian for clang.
+ * http://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html
+ */
+#if !defined(DUK_USE_BYTEORDER) && defined(__BYTE_ORDER__)
+#if defined(__ORDER_LITTLE_ENDIAN__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
+#if defined(__FLOAT_WORD_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && (__FLOAT_WORD_ORDER__ == __ORDER_LITTLE_ENDIAN__)
+#define DUK_USE_BYTEORDER 1
+#elif defined(__FLOAT_WORD_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && (__FLOAT_WORD_ORDER__ == __ORDER_BIG_ENDIAN__)
+#define DUK_USE_BYTEORDER 2
+#elif !defined(__FLOAT_WORD_ORDER__)
+/* Float word order not known, assume not a hybrid. */
+#define DUK_USE_BYTEORDER 1
+#else
+/* Byte order is little endian but cannot determine IEEE double word order. */
+#endif  /* float word order */
+#elif defined(__ORDER_BIG_ENDIAN__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
+#if defined(__FLOAT_WORD_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && (__FLOAT_WORD_ORDER__ == __ORDER_BIG_ENDIAN__)
+#define DUK_USE_BYTEORDER 3
+#elif !defined(__FLOAT_WORD_ORDER__)
+/* Float word order not known, assume not a hybrid. */
+#define DUK_USE_BYTEORDER 3
+#else
+/* Byte order is big endian but cannot determine IEEE double word order. */
+#endif  /* float word order */
+#else
+/* Cannot determine byte order; __ORDER_PDP_ENDIAN__ is related to 32-bit
+ * integer ordering and is not relevant.
+ */
+#endif  /* integer byte order */
+#endif  /* !defined(DUK_USE_BYTEORDER) && defined(__BYTE_ORDER__) */
+
+/* More or less standard endianness predefines provided by header files.
+ * The ARM hybrid case is detected by assuming that __FLOAT_WORD_ORDER
+ * will be big endian, see: http://lists.mysql.com/internals/443.
+ * On some platforms some defines may be present with an empty value which
+ * causes comparisons to fail: https://github.com/svaarala/duktape/issues/453.
+ */
+#if !defined(DUK_USE_BYTEORDER)
+#if defined(__BYTE_ORDER) && defined(__LITTLE_ENDIAN) && (__BYTE_ORDER == __LITTLE_ENDIAN) || \
+    defined(_BYTE_ORDER) && defined(_LITTLE_ENDIAN) && (_BYTE_ORDER == _LITTLE_ENDIAN) || \
+    defined(__LITTLE_ENDIAN__)
+#if defined(__FLOAT_WORD_ORDER) && defined(__LITTLE_ENDIAN) && (__FLOAT_WORD_ORDER == __LITTLE_ENDIAN) || \
+    defined(_FLOAT_WORD_ORDER) && defined(_LITTLE_ENDIAN) && (_FLOAT_WORD_ORDER == _LITTLE_ENDIAN)
+#define DUK_USE_BYTEORDER 1
+#elif defined(__FLOAT_WORD_ORDER) && defined(__BIG_ENDIAN) && (__FLOAT_WORD_ORDER == __BIG_ENDIAN) || \
+      defined(_FLOAT_WORD_ORDER) && defined(_BIG_ENDIAN) && (_FLOAT_WORD_ORDER == _BIG_ENDIAN)
+#define DUK_USE_BYTEORDER 2
+#elif !defined(__FLOAT_WORD_ORDER) && !defined(_FLOAT_WORD_ORDER)
+/* Float word order not known, assume not a hybrid. */
+#define DUK_USE_BYTEORDER 1
+#else
+/* Byte order is little endian but cannot determine IEEE double word order. */
+#endif  /* float word order */
+#elif defined(__BYTE_ORDER) && defined(__BIG_ENDIAN) && (__BYTE_ORDER == __BIG_ENDIAN) || \
+      defined(_BYTE_ORDER) && defined(_BIG_ENDIAN) && (_BYTE_ORDER == _BIG_ENDIAN) || \
+      defined(__BIG_ENDIAN__)
+#if defined(__FLOAT_WORD_ORDER) && defined(__BIG_ENDIAN) && (__FLOAT_WORD_ORDER == __BIG_ENDIAN) || \
+    defined(_FLOAT_WORD_ORDER) && defined(_BIG_ENDIAN) && (_FLOAT_WORD_ORDER == _BIG_ENDIAN)
+#define DUK_USE_BYTEORDER 3
+#elif !defined(__FLOAT_WORD_ORDER) && !defined(_FLOAT_WORD_ORDER)
+/* Float word order not known, assume not a hybrid. */
+#define DUK_USE_BYTEORDER 3
+#else
+/* Byte order is big endian but cannot determine IEEE double word order. */
+#endif  /* float word order */
+#else
+/* Cannot determine byte order. */
+#endif  /* integer byte order */
+#endif  /* !defined(DUK_USE_BYTEORDER) */
+
+/* QNX gcc cross compiler seems to define e.g. __LITTLEENDIAN__ or __BIGENDIAN__:
+ *  $ /opt/qnx650/host/linux/x86/usr/bin/i486-pc-nto-qnx6.5.0-gcc -dM -E - </dev/null | grep -ni endian
+ *  67:#define __LITTLEENDIAN__ 1
+ *  $ /opt/qnx650/host/linux/x86/usr/bin/mips-unknown-nto-qnx6.5.0-gcc -dM -E - </dev/null | grep -ni endian
+ *  81:#define __BIGENDIAN__ 1
+ *  $ /opt/qnx650/host/linux/x86/usr/bin/arm-unknown-nto-qnx6.5.0-gcc -dM -E - </dev/null | grep -ni endian
+ *  70:#define __LITTLEENDIAN__ 1
+ */
+#if !defined(DUK_USE_BYTEORDER)
+#if defined(__LITTLEENDIAN__)
+#define DUK_USE_BYTEORDER 1
+#elif defined(__BIGENDIAN__)
+#define DUK_USE_BYTEORDER 3
+#endif
+#endif
+
+/*
+ *  Alignment requirement and support for unaligned accesses
+ *
+ *  Assume unaligned accesses are not supported unless specifically allowed
+ *  in the target platform.  Some platforms may support unaligned accesses
+ *  but alignment to 4 or 8 may still be desirable.
+ */
+
+/* If not provided, use safe default for alignment. */
+#if !defined(DUK_USE_ALIGN_BY)
+#define DUK_USE_ALIGN_BY 8
+#endif
+
+/* User forced alignment to 4 or 8. */
+#if defined(DUK_OPT_FORCE_ALIGN)
+#undef DUK_USE_ALIGN_BY
+#if (DUK_OPT_FORCE_ALIGN == 4)
+#define DUK_USE_ALIGN_BY 4
+#elif (DUK_OPT_FORCE_ALIGN == 8)
+#define DUK_USE_ALIGN_BY 8
+#else
+#error invalid DUK_OPT_FORCE_ALIGN value
+#endif
+#endif
+
+/* Compiler specific hackery needed to force struct size to match aligment,
+ * see e.g. duk_hbuffer.h.
+ *
+ * http://stackoverflow.com/questions/11130109/c-struct-size-alignment
+ * http://stackoverflow.com/questions/10951039/specifying-64-bit-alignment
+ */
+#if !(defined(DUK_USE_PACK_MSVC_PRAGMA) || defined(DUK_USE_PACK_GCC_ATTR) || \
+      defined(DUK_USE_PACK_CLANG_ATTR) || defined(DUK_USE_PACK_DUMMY_MEMBER))
+#define DUK_USE_PACK_DUMMY_MEMBER
+#endif
+
+#if !defined(DUK_VA_COPY)
+/* We need va_copy() which is defined in C99 / C++11, so an awkward
+ * replacement is needed for pre-C99 / pre-C++11 environments.  This
+ * will quite likely need portability hacks for some non-C99
+ * environments.
+ */
+#if defined(DUK_F_C99) || defined(DUK_F_CPP11)
+/* C99 / C++11 and above: rely on va_copy() which is required.
+ * Omit parenthesis on macro right side on purpose to minimize differences
+ * to direct use.
+ */
+#define DUK_VA_COPY(dest,src) va_copy(dest,src)
+#else
+/* Pre-C99: va_list type is implementation dependent.  This replacement
+ * assumes it is a plain value so that a simple assignment will work.
+ * This is not the case on all platforms (it may be a single-array element,
+ * for instance).
+ */
+#define DUK_VA_COPY(dest,src) do { (dest) = (src); } while (0)
+#endif
+#endif
+
+#if !defined(DUK_MACRO_STRINGIFY)
+/* Macro hackery to convert e.g. __LINE__ to a string without formatting,
+ * see: http://stackoverflow.com/questions/240353/convert-a-preprocessor-token-to-a-string
+ */
+#define DUK_MACRO_STRINGIFY_HELPER(x)  #x
+#define DUK_MACRO_STRINGIFY(x)  DUK_MACRO_STRINGIFY_HELPER(x)
+#endif
+
+#if !defined(DUK_CAUSE_SEGFAULT)
+/* This is optionally used by panic handling to cause the program to segfault
+ * (instead of e.g. abort()) on panic.  Valgrind will then indicate the C
+ * call stack leading to the panic.
+ */
+#define DUK_CAUSE_SEGFAULT()  do { *((volatile duk_uint32_t *) NULL) = (duk_uint32_t) 0xdeadbeefUL; } while (0)
+#endif
+#if !defined(DUK_UNREF)
+/* Macro for suppressing warnings for potentially unreferenced variables.
+ * The variables can be actually unreferenced or unreferenced in some
+ * specific cases only; for instance, if a variable is only debug printed,
+ * it is unreferenced when debug printing is disabled.
+ */
+#define DUK_UNREF(x)  do { (void) (x); } while (0)
+#endif
+#if !defined(DUK_NORETURN)
+#define DUK_NORETURN(decl)  decl
+#endif
+#if !defined(DUK_UNREACHABLE)
+/* Don't know how to declare unreachable point, so don't do it; this
+ * may cause some spurious compilation warnings (e.g. "variable used
+ * uninitialized").
+ */
+#define DUK_UNREACHABLE()  do { } while (0)
+#endif
+#if !defined(DUK_LOSE_CONST)
+/* Convert any input pointer into a "void *", losing a const qualifier.
+ * This is not fully portable because casting through duk_uintptr_t may
+ * not work on all architectures (e.g. those with long, segmented pointers).
+ */
+#define DUK_LOSE_CONST(src) ((void *) (duk_uintptr_t) (src))
+#endif
+
+#if !defined(DUK_LIKELY)
+#define DUK_LIKELY(x)    (x)
+#endif
+#if !defined(DUK_UNLIKELY)
+#define DUK_UNLIKELY(x)  (x)
+#endif
+
+#if !defined(DUK_NOINLINE)
+#define DUK_NOINLINE       /*nop*/
+#endif
+#if !defined(DUK_INLINE)
+#define DUK_INLINE         /*nop*/
+#endif
+#if !defined(DUK_ALWAYS_INLINE)
+#define DUK_ALWAYS_INLINE  /*nop*/
+#endif
+
+#if !defined(DUK_EXTERNAL_DECL)
+#define DUK_EXTERNAL_DECL  extern
+#endif
+#if !defined(DUK_EXTERNAL)
+#define DUK_EXTERNAL       /*empty*/
+#endif
+#if !defined(DUK_INTERNAL_DECL)
+#if defined(DUK_SINGLE_FILE)
+#define DUK_INTERNAL_DECL  static
+#else
+#define DUK_INTERNAL_DECL  extern
+#endif
+#endif
+#if !defined(DUK_INTERNAL)
+#if defined(DUK_SINGLE_FILE)
+#define DUK_INTERNAL       static
+#else
+#define DUK_INTERNAL       /*empty*/
+#endif
+#endif
+#if !defined(DUK_LOCAL_DECL)
+#define DUK_LOCAL_DECL     static
+#endif
+#if !defined(DUK_LOCAL)
+#define DUK_LOCAL          static
+#endif
+
+#if !defined(DUK_FILE_MACRO)
+#define DUK_FILE_MACRO  __FILE__
+#endif
+#if !defined(DUK_LINE_MACRO)
+#define DUK_LINE_MACRO  __LINE__
+#endif
+#if !defined(DUK_FUNC_MACRO)
+#if defined(DUK_F_C99) || defined(DUK_F_CPP11)
+#define DUK_FUNC_MACRO  __func__
+#elif defined(__FUNCTION__)
+#define DUK_FUNC_MACRO  __FUNCTION__
+#else
+#define DUK_FUNC_MACRO  "unknown"
+#endif
+#endif
+
+#if !defined(DUK_BSWAP32)
+#define DUK_BSWAP32(x) \
+	((((duk_uint32_t) (x)) >> 24) | \
+	 ((((duk_uint32_t) (x)) >> 8) & 0xff00UL) | \
+	 ((((duk_uint32_t) (x)) << 8) & 0xff0000UL) | \
+	 (((duk_uint32_t) (x)) << 24))
+#endif
+#if !defined(DUK_BSWAP16)
+#define DUK_BSWAP16(x) \
+	((duk_uint16_t) (x) >> 8) | \
+	((duk_uint16_t) (x) << 8)
+#endif
+
+/* DUK_USE_VARIADIC_MACROS: required from compilers, so no fill-in. */
+/* DUK_USE_UNION_INITIALIZERS: required from compilers, so no fill-in. */
+
+#if !(defined(DUK_USE_FLEX_C99) || defined(DUK_USE_FLEX_ZEROSIZE) || defined(DUK_USE_FLEX_ONESIZE))
+#if defined(DUK_F_C99)
+#define DUK_USE_FLEX_C99
+#else
+#define DUK_USE_FLEX_ZEROSIZE  /* Not standard but common enough */
+#endif
+#endif
+
+#if !(defined(DUK_USE_PACK_GCC_ATTR) || defined(DUK_USE_PACK_CLANG_ATTR) || \
+      defined(DUK_USE_PACK_MSVC_PRAGMA) || defined(DUK_USE_PACK_DUMMY_MEMBER))
+#define DUK_USE_PACK_DUMMY_MEMBER
+#endif
+
+#if 0  /* not defined by default */
+#undef DUK_USE_GCC_PRAGMAS
+#endif
+
+/* Workaround for GH-323: avoid inlining control when compiling from
+ * multiple sources, as it causes compiler portability trouble.
+ */
+#if !defined(DUK_SINGLE_FILE)
+#undef DUK_NOINLINE
+#undef DUK_INLINE
+#undef DUK_ALWAYS_INLINE
+#define DUK_NOINLINE       /*nop*/
+#define DUK_INLINE         /*nop*/
+#define DUK_ALWAYS_INLINE  /*nop*/
+#endif
+
+/*
+ *  Check whether or not a packed duk_tval representation is possible.
+ *  What's basically required is that pointers are 32-bit values
+ *  (sizeof(void *) == 4).  Best effort check, not always accurate.
+ *  If guess goes wrong, crashes may result; self tests also verify
+ *  the guess.
+ */
+
+/* Explicit marker needed; may be 'defined', 'undefined, 'or 'not provided'. */
+#if !defined(DUK_F_PACKED_TVAL_PROVIDED)
+#undef DUK_F_PACKED_TVAL_POSSIBLE
+
+/* Strict C99 case: DUK_UINTPTR_MAX (= UINTPTR_MAX) should be very reliable */
+#if !defined(DUK_F_PACKED_TVAL_POSSIBLE) && defined(DUK_UINTPTR_MAX)
+#if (DUK_UINTPTR_MAX <= 0xffffffffUL)
+#define DUK_F_PACKED_TVAL_POSSIBLE
+#endif
+#endif
+
+/* Non-C99 case, still relying on DUK_UINTPTR_MAX, as long as it is not a computed value */
+#if !defined(DUK_F_PACKED_TVAL_POSSIBLE) && defined(DUK_UINTPTR_MAX) && !defined(DUK_UINTPTR_MAX_COMPUTED)
+#if (DUK_UINTPTR_MAX <= 0xffffffffUL)
+#define DUK_F_PACKED_TVAL_POSSIBLE
+#endif
+#endif
+
+/* DUK_SIZE_MAX (= SIZE_MAX) is often reliable */
+#if !defined(DUK_F_PACKED_TVAL_POSSIBLE) && defined(DUK_SIZE_MAX) && !defined(DUK_SIZE_MAX_COMPUTED)
+#if (DUK_SIZE_MAX <= 0xffffffffUL)
+#define DUK_F_PACKED_TVAL_POSSIBLE
+#endif
+#endif
+
+#undef DUK_USE_PACKED_TVAL
+#if defined(DUK_F_PACKED_TVAL_POSSIBLE)
+#define DUK_USE_PACKED_TVAL
+#endif
+
+#undef DUK_F_PACKED_TVAL_POSSIBLE
+#endif  /* DUK_F_PACKED_TVAL_PROVIDED */
+
+/* Feature option forcing. */
+#if defined(DUK_OPT_NO_PACKED_TVAL)
+#undef DUK_USE_PACKED_TVAL
+#elif defined(DUK_OPT_PACKED_TVAL)
+#undef DUK_USE_PACKED_TVAL
+#define DUK_USE_PACKED_TVAL
+#endif
+/* Object property allocation layout has implications for memory and code
+ * footprint and generated code size/speed.  The best layout also depends
+ * on whether the platform has alignment requirements or benefits from
+ * having mostly aligned accesses.
+ */
+#undef DUK_USE_HOBJECT_LAYOUT_1
+#undef DUK_USE_HOBJECT_LAYOUT_2
+#undef DUK_USE_HOBJECT_LAYOUT_3
+#if (DUK_USE_ALIGN_BY == 1)
+/* On platforms without any alignment issues, layout 1 is preferable
+ * because it compiles to slightly less code and provides direct access
+ * to property keys.
+ */
+#define DUK_USE_HOBJECT_LAYOUT_1
+#else
+/* On other platforms use layout 2, which requires some padding but
+ * is a bit more natural than layout 3 in ordering the entries.  Layout
+ * 3 is currently not used.
+ */
+#define DUK_USE_HOBJECT_LAYOUT_2
+#endif
+
+/* GCC/clang inaccurate math would break compliance and probably duk_tval,
+ * so refuse to compile.  Relax this if -ffast-math is tested to work.
+ */
+#if defined(__FAST_MATH__)
+#error __FAST_MATH__ defined, refusing to compile
+#endif
+
+/*
+ *  Autogenerated defaults
+ */
+
+#undef DUK_USE_ASSERTIONS
+#define DUK_USE_AUGMENT_ERROR_CREATE
+#define DUK_USE_AUGMENT_ERROR_THROW
+#define DUK_USE_AVOID_PLATFORM_FUNCPTRS
+#define DUK_USE_BASE64_FASTPATH
+#define DUK_USE_BROWSER_LIKE
+#define DUK_USE_BUFFEROBJECT_SUPPORT
+#undef DUK_USE_BUFLEN16
+#define DUK_USE_BUILTIN_INITJS
+#define DUK_USE_BYTECODE_DUMP_SUPPORT
+#define DUK_USE_COMMONJS_MODULES
+#define DUK_USE_COMPILER_RECLIMIT 2500
+#undef DUK_USE_CPP_EXCEPTIONS
+#undef DUK_USE_DATAPTR16
+#undef DUK_USE_DATAPTR_DEC16
+#undef DUK_USE_DATAPTR_ENC16
+#undef DUK_USE_DATE_FORMAT_STRING
+#undef DUK_USE_DATE_GET_LOCAL_TZOFFSET
+#undef DUK_USE_DATE_GET_NOW
+#undef DUK_USE_DATE_PARSE_STRING
+#undef DUK_USE_DATE_PRS_GETDATE
+#undef DUK_USE_DDDPRINT
+#undef DUK_USE_DDPRINT
+#undef DUK_USE_DEBUG
+#undef DUK_USE_DEBUGGER_DUMPHEAP
+#undef DUK_USE_DEBUGGER_FWD_LOGGING
+#undef DUK_USE_DEBUGGER_FWD_PRINTALERT
+#undef DUK_USE_DEBUGGER_INSPECT
+#undef DUK_USE_DEBUGGER_PAUSE_UNCAUGHT
+#undef DUK_USE_DEBUGGER_SUPPORT
+#define DUK_USE_DEBUGGER_THROW_NOTIFY
+#undef DUK_USE_DEBUGGER_TRANSPORT_TORTURE
+#define DUK_USE_DEBUG_BUFSIZE 65536L
+#define DUK_USE_DOUBLE_LINKED_HEAP
+#undef DUK_USE_DPRINT
+#undef DUK_USE_DPRINT_COLORS
+#undef DUK_USE_DPRINT_RDTSC
+#define DUK_USE_ERRCREATE
+#define DUK_USE_ERRTHROW
+#define DUK_USE_ES6_OBJECT_PROTO_PROPERTY
+#define DUK_USE_ES6_OBJECT_SETPROTOTYPEOF
+#define DUK_USE_ES6_PROXY
+#define DUK_USE_ES6_REGEXP_BRACES
+#define DUK_USE_ESBC_LIMITS
+#define DUK_USE_ESBC_MAX_BYTES 2147418112L
+#define DUK_USE_ESBC_MAX_LINENUMBER 2147418112L
+#undef DUK_USE_EXEC_FUN_LOCAL
+#undef DUK_USE_EXEC_INDIRECT_BOUND_C

<TRUNCATED>

[03/51] [partial] nifi-minifi-cpp git commit: MINIFI-183 Added civet 1.9.1 sources Added onScheduled hook Added initial two-way TLS-enabled ListenHTTP implementation

Posted by al...@apache.org.
http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_debugger.h
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_debugger.h b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_debugger.h
new file mode 100644
index 0000000..f79557b
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_debugger.h
@@ -0,0 +1,144 @@
+#ifndef DUK_DEBUGGER_H_INCLUDED
+#define DUK_DEBUGGER_H_INCLUDED
+
+/* Debugger protocol version is defined in the public API header. */
+
+/* Initial bytes for markers. */
+#define DUK_DBG_IB_EOM                   0x00
+#define DUK_DBG_IB_REQUEST               0x01
+#define DUK_DBG_IB_REPLY                 0x02
+#define DUK_DBG_IB_ERROR                 0x03
+#define DUK_DBG_IB_NOTIFY                0x04
+
+/* Other initial bytes. */
+#define DUK_DBG_IB_INT4                  0x10
+#define DUK_DBG_IB_STR4                  0x11
+#define DUK_DBG_IB_STR2                  0x12
+#define DUK_DBG_IB_BUF4                  0x13
+#define DUK_DBG_IB_BUF2                  0x14
+#define DUK_DBG_IB_UNUSED                0x15
+#define DUK_DBG_IB_UNDEFINED             0x16
+#define DUK_DBG_IB_NULL                  0x17
+#define DUK_DBG_IB_TRUE                  0x18
+#define DUK_DBG_IB_FALSE                 0x19
+#define DUK_DBG_IB_NUMBER                0x1a
+#define DUK_DBG_IB_OBJECT                0x1b
+#define DUK_DBG_IB_POINTER               0x1c
+#define DUK_DBG_IB_LIGHTFUNC             0x1d
+#define DUK_DBG_IB_HEAPPTR               0x1e
+/* The short string/integer initial bytes starting from 0x60 don't have
+ * defines now.
+ */
+
+/* Error codes. */
+#define DUK_DBG_ERR_UNKNOWN              0x00
+#define DUK_DBG_ERR_UNSUPPORTED          0x01
+#define DUK_DBG_ERR_TOOMANY              0x02
+#define DUK_DBG_ERR_NOTFOUND             0x03
+#define DUK_DBG_ERR_APPLICATION          0x04
+
+/* Commands and notifys initiated by Duktape. */
+#define DUK_DBG_CMD_STATUS               0x01
+#define DUK_DBG_CMD_PRINT                0x02
+#define DUK_DBG_CMD_ALERT                0x03
+#define DUK_DBG_CMD_LOG                  0x04
+#define DUK_DBG_CMD_THROW                0x05
+#define DUK_DBG_CMD_DETACHING            0x06
+#define DUK_DBG_CMD_APPNOTIFY            0x07
+
+/* Commands initiated by debug client. */
+#define DUK_DBG_CMD_BASICINFO            0x10
+#define DUK_DBG_CMD_TRIGGERSTATUS        0x11
+#define DUK_DBG_CMD_PAUSE                0x12
+#define DUK_DBG_CMD_RESUME               0x13
+#define DUK_DBG_CMD_STEPINTO             0x14
+#define DUK_DBG_CMD_STEPOVER             0x15
+#define DUK_DBG_CMD_STEPOUT              0x16
+#define DUK_DBG_CMD_LISTBREAK            0x17
+#define DUK_DBG_CMD_ADDBREAK             0x18
+#define DUK_DBG_CMD_DELBREAK             0x19
+#define DUK_DBG_CMD_GETVAR               0x1a
+#define DUK_DBG_CMD_PUTVAR               0x1b
+#define DUK_DBG_CMD_GETCALLSTACK         0x1c
+#define DUK_DBG_CMD_GETLOCALS            0x1d
+#define DUK_DBG_CMD_EVAL                 0x1e
+#define DUK_DBG_CMD_DETACH               0x1f
+#define DUK_DBG_CMD_DUMPHEAP             0x20
+#define DUK_DBG_CMD_GETBYTECODE          0x21
+#define DUK_DBG_CMD_APPREQUEST           0x22
+#define DUK_DBG_CMD_GETHEAPOBJINFO       0x23
+#define DUK_DBG_CMD_GETOBJPROPDESC       0x24
+#define DUK_DBG_CMD_GETOBJPROPDESCRANGE  0x25
+
+/* The low 8 bits map directly to duk_hobject.h DUK_PROPDESC_FLAG_xxx.
+ * The remaining flags are specific to the debugger.
+ */
+#define DUK_DBG_PROPFLAG_INTERNAL        (1 << 8)
+
+#if defined(DUK_USE_DEBUGGER_SUPPORT)
+DUK_INTERNAL_DECL void duk_debug_do_detach(duk_heap *heap);
+
+DUK_INTERNAL_DECL duk_bool_t duk_debug_read_peek(duk_hthread *thr);
+DUK_INTERNAL_DECL void duk_debug_write_flush(duk_hthread *thr);
+
+DUK_INTERNAL_DECL void duk_debug_skip_bytes(duk_hthread *thr, duk_size_t length);
+DUK_INTERNAL_DECL void duk_debug_skip_byte(duk_hthread *thr);
+
+DUK_INTERNAL_DECL void duk_debug_read_bytes(duk_hthread *thr, duk_uint8_t *data, duk_size_t length);
+DUK_INTERNAL_DECL duk_uint8_t duk_debug_read_byte(duk_hthread *thr);
+DUK_INTERNAL_DECL duk_int32_t duk_debug_read_int(duk_hthread *thr);
+DUK_INTERNAL_DECL duk_hstring *duk_debug_read_hstring(duk_hthread *thr);
+/* XXX: exposed duk_debug_read_pointer */
+/* XXX: exposed duk_debug_read_buffer */
+/* XXX: exposed duk_debug_read_hbuffer */
+#if 0
+DUK_INTERNAL_DECL duk_heaphdr *duk_debug_read_heapptr(duk_hthread *thr);
+#endif
+#if defined(DUK_USE_DEBUGGER_INSPECT)
+DUK_INTERNAL_DECL duk_heaphdr *duk_debug_read_any_ptr(duk_hthread *thr);
+#endif
+DUK_INTERNAL_DECL duk_tval *duk_debug_read_tval(duk_hthread *thr);
+
+DUK_INTERNAL_DECL void duk_debug_write_bytes(duk_hthread *thr, const duk_uint8_t *data, duk_size_t length);
+DUK_INTERNAL_DECL void duk_debug_write_byte(duk_hthread *thr, duk_uint8_t x);
+DUK_INTERNAL_DECL void duk_debug_write_unused(duk_hthread *thr);
+DUK_INTERNAL_DECL void duk_debug_write_undefined(duk_hthread *thr);
+#if defined(DUK_USE_DEBUGGER_INSPECT)
+DUK_INTERNAL_DECL void duk_debug_write_null(duk_hthread *thr);
+#endif
+DUK_INTERNAL_DECL void duk_debug_write_boolean(duk_hthread *thr, duk_uint_t val);
+DUK_INTERNAL_DECL void duk_debug_write_int(duk_hthread *thr, duk_int32_t x);
+DUK_INTERNAL_DECL void duk_debug_write_uint(duk_hthread *thr, duk_uint32_t x);
+DUK_INTERNAL_DECL void duk_debug_write_string(duk_hthread *thr, const char *data, duk_size_t length);
+DUK_INTERNAL_DECL void duk_debug_write_cstring(duk_hthread *thr, const char *data);
+DUK_INTERNAL_DECL void duk_debug_write_hstring(duk_hthread *thr, duk_hstring *h);
+DUK_INTERNAL_DECL void duk_debug_write_buffer(duk_hthread *thr, const char *data, duk_size_t length);
+DUK_INTERNAL_DECL void duk_debug_write_hbuffer(duk_hthread *thr, duk_hbuffer *h);
+DUK_INTERNAL_DECL void duk_debug_write_pointer(duk_hthread *thr, void *ptr);
+#if defined(DUK_USE_DEBUGGER_DUMPHEAP) || defined(DUK_USE_DEBUGGER_INSPECT)
+DUK_INTERNAL_DECL void duk_debug_write_heapptr(duk_hthread *thr, duk_heaphdr *h);
+#endif
+DUK_INTERNAL_DECL void duk_debug_write_hobject(duk_hthread *thr, duk_hobject *obj);
+DUK_INTERNAL_DECL void duk_debug_write_tval(duk_hthread *thr, duk_tval *tv);
+#if 0  /* unused */
+DUK_INTERNAL_DECL void duk_debug_write_request(duk_hthread *thr, duk_small_uint_t command);
+#endif
+DUK_INTERNAL_DECL void duk_debug_write_reply(duk_hthread *thr);
+DUK_INTERNAL_DECL void duk_debug_write_error_eom(duk_hthread *thr, duk_small_uint_t err_code, const char *msg);
+DUK_INTERNAL_DECL void duk_debug_write_notify(duk_hthread *thr, duk_small_uint_t command);
+DUK_INTERNAL_DECL void duk_debug_write_eom(duk_hthread *thr);
+
+DUK_INTERNAL_DECL duk_uint_fast32_t duk_debug_curr_line(duk_hthread *thr);
+DUK_INTERNAL_DECL void duk_debug_send_status(duk_hthread *thr);
+#if defined(DUK_USE_DEBUGGER_THROW_NOTIFY)
+DUK_INTERNAL_DECL void duk_debug_send_throw(duk_hthread *thr, duk_bool_t fatal);
+#endif
+
+DUK_INTERNAL_DECL void duk_debug_halt_execution(duk_hthread *thr, duk_bool_t use_prev_pc);
+DUK_INTERNAL_DECL duk_bool_t duk_debug_process_messages(duk_hthread *thr, duk_bool_t no_block);
+
+DUK_INTERNAL_DECL duk_small_int_t duk_debug_add_breakpoint(duk_hthread *thr, duk_hstring *filename, duk_uint32_t line);
+DUK_INTERNAL_DECL duk_bool_t duk_debug_remove_breakpoint(duk_hthread *thr, duk_small_uint_t breakpoint_index);
+#endif
+
+#endif  /* DUK_DEBUGGER_H_INCLUDED */

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_error.h
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_error.h b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_error.h
new file mode 100644
index 0000000..2b00a78
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_error.h
@@ -0,0 +1,439 @@
+/*
+ *  Error handling macros, assertion macro, error codes.
+ *
+ *  There are three level of 'errors':
+ *
+ *    1. Ordinary errors, relative to a thread, cause a longjmp, catchable.
+ *    2. Fatal errors, relative to a heap, cause fatal handler to be called.
+ *    3. Panic errors, unrelated to a heap and cause a process exit.
+ *
+ *  Panics are used by the default fatal error handler and by debug code
+ *  such as assertions.  By providing a proper fatal error handler, user
+ *  code can avoid panics in non-debug builds.
+ */
+
+#ifndef DUK_ERROR_H_INCLUDED
+#define DUK_ERROR_H_INCLUDED
+
+/*
+ *  Error codes: defined in duktape.h
+ *
+ *  Error codes are used as a shorthand to throw exceptions from inside
+ *  the implementation.  The appropriate Ecmascript object is constructed
+ *  based on the code.  Ecmascript code throws objects directly.  The error
+ *  codes are defined in the public API header because they are also used
+ *  by calling code.
+ */
+
+/*
+ *  Normal error
+ *
+ *  Normal error is thrown with a longjmp() through the current setjmp()
+ *  catchpoint record in the duk_heap.  The 'curr_thread' of the duk_heap
+ *  identifies the throwing thread.
+ *
+ *  Error formatting is usually unnecessary.  The error macros provide a
+ *  zero argument version (no formatting) and separate macros for small
+ *  argument counts.  Variadic macros are not used to avoid portability
+ *  issues and avoid the need for stash-based workarounds when they're not
+ *  available.  Vararg calls are avoided for non-formatted error calls
+ *  because vararg call sites are larger than normal, and there are a lot
+ *  of call sites with no formatting.
+ *
+ *  Note that special formatting provided by debug macros is NOT available.
+ *
+ *  The _RAW variants allow the caller to specify file and line.  This makes
+ *  it easier to write checked calls which want to use the call site of the
+ *  checked function, not the error macro call inside the checked function.
+ */
+
+#if defined(DUK_USE_VERBOSE_ERRORS)
+
+/* Because there are quite many call sites, pack error code (require at most
+ * 8-bit) into a single argument.
+ */
+#define DUK_ERROR(thr,err,msg) do { \
+		duk_errcode_t duk__err = (err); duk_int_t duk__line = (duk_int_t) DUK_LINE_MACRO; \
+		DUK_ASSERT(duk__err >= 0 && duk__err <= 0xff); DUK_ASSERT(duk__line >= 0 && duk__line <= 0x00ffffffL); \
+		duk_err_handle_error((thr), DUK_FILE_MACRO, (((duk_uint_t) duk__err) << 24) | ((duk_uint_t) duk__line), (msg)); \
+	} while (0)
+#define DUK_ERROR_RAW(thr,file,line,err,msg) do { \
+		duk_errcode_t duk__err = (err); duk_int_t duk__line = (duk_int_t) (line); \
+		DUK_ASSERT(duk__err >= 0 && duk__err <= 0xff); DUK_ASSERT(duk__line >= 0 && duk__line <= 0x00ffffffL); \
+		duk_err_handle_error((thr), (file), (((duk_uint_t) duk__err) << 24) | ((duk_uint_t) duk__line), (msg)); \
+	} while (0)
+
+#define DUK_ERROR_FMT1(thr,err,fmt,arg1) do { \
+		duk_errcode_t duk__err = (err); duk_int_t duk__line = (duk_int_t) DUK_LINE_MACRO; \
+		DUK_ASSERT(duk__err >= 0 && duk__err <= 0xff); DUK_ASSERT(duk__line >= 0 && duk__line <= 0x00ffffffL); \
+		duk_err_handle_error_fmt((thr), DUK_FILE_MACRO, (((duk_uint_t) duk__err) << 24) | ((duk_uint_t) duk__line), (fmt), (arg1)); \
+	} while (0)
+#define DUK_ERROR_RAW_FMT1(thr,file,line,err,fmt,arg1) do { \
+		duk_errcode_t duk__err = (err); duk_int_t duk__line = (duk_int_t) (line); \
+		DUK_ASSERT(duk__err >= 0 && duk__err <= 0xff); DUK_ASSERT(duk__line >= 0 && duk__line <= 0x00ffffffL); \
+		duk_err_handle_error_fmt((thr), (file), (((duk_uint_t) duk__err) << 24) | ((duk_uint_t) duk__line), (fmt), (arg1)); \
+	} while (0)
+
+#define DUK_ERROR_FMT2(thr,err,fmt,arg1,arg2) do { \
+		duk_errcode_t duk__err = (err); duk_int_t duk__line = (duk_int_t) DUK_LINE_MACRO; \
+		DUK_ASSERT(duk__err >= 0 && duk__err <= 0xff); DUK_ASSERT(duk__line >= 0 && duk__line <= 0x00ffffffL); \
+		duk_err_handle_error_fmt((thr), DUK_FILE_MACRO, (((duk_uint_t) duk__err) << 24) | ((duk_uint_t) duk__line), (fmt), (arg1), (arg2)); \
+	} while (0)
+#define DUK_ERROR_RAW_FMT2(thr,file,line,err,fmt,arg1,arg2) do { \
+		duk_errcode_t duk__err = (err); duk_int_t duk__line = (duk_int_t) (line); \
+		DUK_ASSERT(duk__err >= 0 && duk__err <= 0xff); DUK_ASSERT(duk__line >= 0 && duk__line <= 0x00ffffffL); \
+		duk_err_handle_error_fmt((thr), (file), (((duk_uint_t) duk__err) << 24) | ((duk_uint_t) duk__line), (fmt), (arg1), (arg2)); \
+	} while (0)
+
+#define DUK_ERROR_FMT3(thr,err,fmt,arg1,arg2,arg3) do { \
+		duk_errcode_t duk__err = (err); duk_int_t duk__line = (duk_int_t) DUK_LINE_MACRO; \
+		DUK_ASSERT(duk__err >= 0 && duk__err <= 0xff); DUK_ASSERT(duk__line >= 0 && duk__line <= 0x00ffffffL); \
+		duk_err_handle_error_fmt((thr), DUK_FILE_MACRO, (((duk_uint_t) duk__err) << 24) | ((duk_uint_t) duk__line), (fmt), (arg1), (arg2), (arg3)); \
+	} while (0)
+#define DUK_ERROR_RAW_FMT3(thr,file,line,err,fmt,arg1,arg2,arg3) do { \
+		duk_errcode_t duk__err = (err); duk_int_t duk__line = (duk_int_t) (line); \
+		DUK_ASSERT(duk__err >= 0 && duk__err <= 0xff); DUK_ASSERT(duk__line >= 0 && duk__line <= 0x00ffffffL); \
+		duk_err_handle_error_fmt((thr), (file), (((duk_uint_t) duk__err) << 24) | ((duk_uint_t) duk__line), (fmt), (arg1), (arg2), (arg3)); \
+	} while (0)
+
+#define DUK_ERROR_FMT4(thr,err,fmt,arg1,arg2,arg3,arg4) do { \
+		duk_errcode_t duk__err = (err); duk_int_t duk__line = (duk_int_t) DUK_LINE_MACRO; \
+		DUK_ASSERT(duk__err >= 0 && duk__err <= 0xff); DUK_ASSERT(duk__line >= 0 && duk__line <= 0x00ffffffL); \
+		duk_err_handle_error_fmt((thr), DUK_FILE_MACRO, (((duk_uint_t) duk__err) << 24) | ((duk_uint_t) duk__line), (fmt), (arg1), (arg2), (arg3), (arg4)); \
+	} while (0)
+#define DUK_ERROR_RAW_FMT4(thr,file,line,err,fmt,arg1,arg2,arg3,arg4) do { \
+		duk_errcode_t duk__err = (err); duk_int_t duk__line = (duk_int_t) (line); \
+		DUK_ASSERT(duk__err >= 0 && duk__err <= 0xff); DUK_ASSERT(duk__line >= 0 && duk__line <= 0x00ffffffL); \
+		duk_err_handle_error_fmt((thr), (file), (((duk_uint_t) duk__err) << 24) | ((duk_uint_t) duk__line), (fmt), (arg1), (arg2), (arg3), (arg4)); \
+	} while (0)
+
+#else  /* DUK_USE_VERBOSE_ERRORS */
+
+#define DUK_ERROR(thr,err,msg)                    duk_err_handle_error((thr), (err))
+#define DUK_ERROR_RAW(thr,file,line,err,msg)      duk_err_handle_error((thr), (err))
+
+#define DUK_ERROR_FMT1(thr,err,fmt,arg1) DUK_ERROR((thr),(err),(fmt))
+#define DUK_ERROR_RAW_FMT1(thr,file,line,err,fmt,arg1) DUK_ERROR_RAW((thr),(file),(line),(err),(fmt))
+
+#define DUK_ERROR_FMT2(thr,err,fmt,arg1,arg2) DUK_ERROR((thr),(err),(fmt))
+#define DUK_ERROR_RAW_FMT2(thr,file,line,err,fmt,arg1,arg2) DUK_ERROR_RAW((thr),(file),(line),(err),(fmt))
+
+#define DUK_ERROR_FMT3(thr,err,fmt,arg1,arg2,arg3) DUK_ERROR((thr),(err),(fmt))
+#define DUK_ERROR_RAW_FMT3(thr,file,line,err,fmt,arg1,arg2,arg3) DUK_ERROR_RAW((thr),(file),(line),(err),(fmt))
+
+#define DUK_ERROR_FMT4(thr,err,fmt,arg1,arg2,arg3,arg4) DUK_ERROR((thr),(err),(fmt))
+#define DUK_ERROR_RAW_FMT4(thr,file,line,err,fmt,arg1,arg2,arg3,arg4) DUK_ERROR_RAW((thr),(file),(line),(err),(fmt))
+
+#endif  /* DUK_USE_VERBOSE_ERRORS */
+
+/*
+ *  Fatal error
+ *
+ *  There are no fatal error macros at the moment.  There are so few call
+ *  sites that the fatal error handler is called directly.
+ */
+
+/*
+ *  Panic error
+ *
+ *  Panic errors are not relative to either a heap or a thread, and cause
+ *  DUK_PANIC() macro to be invoked.  Unless a user provides DUK_USE_PANIC_HANDLER,
+ *  DUK_PANIC() calls a helper which prints out the error and causes a process
+ *  exit.
+ *
+ *  The user can override the macro to provide custom handling.  A macro is
+ *  used to allow the user to have inline panic handling if desired (without
+ *  causing a potentially risky function call).
+ *
+ *  Panics are only used in debug code such as assertions, and by the default
+ *  fatal error handler.
+ */
+
+#if defined(DUK_USE_PANIC_HANDLER)
+/* already defined, good */
+#define DUK_PANIC(code,msg)  DUK_USE_PANIC_HANDLER((code),(msg))
+#else
+#define DUK_PANIC(code,msg)  duk_default_panic_handler((code),(msg))
+#endif  /* DUK_USE_PANIC_HANDLER */
+
+/*
+ *  Assert macro: failure causes panic.
+ */
+
+#if defined(DUK_USE_ASSERTIONS)
+
+/* the message should be a compile time constant without formatting (less risk);
+ * we don't care about assertion text size because they're not used in production
+ * builds.
+ */
+#define DUK_ASSERT(x)  do { \
+	if (!(x)) { \
+		DUK_PANIC(DUK_ERR_ASSERTION_ERROR, \
+			"assertion failed: " #x \
+			" (" DUK_FILE_MACRO ":" DUK_MACRO_STRINGIFY(DUK_LINE_MACRO) ")"); \
+	} \
+	} while (0)
+
+/* Assertion compatible inside a comma expression, evaluates to void.
+ * Currently not compatible with DUK_USE_PANIC_HANDLER() which may have
+ * a statement block.
+ */
+#if defined(DUK_USE_PANIC_HANDLER)
+/* XXX: resolve macro definition issue or call through a helper function? */
+#define DUK_ASSERT_EXPR(x)  ((void) 0)
+#else
+#define DUK_ASSERT_EXPR(x) \
+	((void) ((x) ? 0 : (DUK_PANIC(DUK_ERR_ASSERTION_ERROR, \
+				"assertion failed: " #x \
+				" (" DUK_FILE_MACRO ":" DUK_MACRO_STRINGIFY(DUK_LINE_MACRO) ")"), 0)))
+#endif
+
+#else  /* DUK_USE_ASSERTIONS */
+
+#define DUK_ASSERT(x)  do { /* assertion omitted */ } while (0)
+
+#define DUK_ASSERT_EXPR(x)  ((void) 0)
+
+#endif  /* DUK_USE_ASSERTIONS */
+
+/* this variant is used when an assert would generate a compile warning by
+ * being always true (e.g. >= 0 comparison for an unsigned value
+ */
+#define DUK_ASSERT_DISABLE(x)  do { /* assertion disabled */ } while (0)
+
+/*
+ *  Assertion helpers
+ */
+
+#if defined(DUK_USE_ASSERTIONS) && defined(DUK_USE_REFERENCE_COUNTING)
+#define DUK_ASSERT_REFCOUNT_NONZERO_HEAPHDR(h)  do { \
+		DUK_ASSERT((h) == NULL || DUK_HEAPHDR_GET_REFCOUNT((duk_heaphdr *) (h)) > 0); \
+	} while (0)
+#define DUK_ASSERT_REFCOUNT_NONZERO_TVAL(tv)  do { \
+		if ((tv) != NULL && DUK_TVAL_IS_HEAP_ALLOCATED((tv))) { \
+			DUK_ASSERT(DUK_HEAPHDR_GET_REFCOUNT(DUK_TVAL_GET_HEAPHDR((tv))) > 0); \
+		} \
+	} while (0)
+#else
+#define DUK_ASSERT_REFCOUNT_NONZERO_HEAPHDR(h)  /* no refcount check */
+#define DUK_ASSERT_REFCOUNT_NONZERO_TVAL(tv)    /* no refcount check */
+#endif
+
+#define DUK_ASSERT_TOP(ctx,n)  DUK_ASSERT((duk_idx_t) duk_get_top((ctx)) == (duk_idx_t) (n))
+
+#if defined(DUK_USE_ASSERTIONS) && defined(DUK_USE_PACKED_TVAL)
+#define DUK_ASSERT_DOUBLE_IS_NORMALIZED(dval)  do { \
+		duk_double_union duk__assert_tmp_du; \
+		duk__assert_tmp_du.d = (dval); \
+		DUK_ASSERT(DUK_DBLUNION_IS_NORMALIZED(&duk__assert_tmp_du)); \
+	} while (0)
+#else
+#define DUK_ASSERT_DOUBLE_IS_NORMALIZED(dval)  /* nop */
+#endif
+
+/*
+ *  Helper for valstack space
+ *
+ *  Caller of DUK_ASSERT_VALSTACK_SPACE() estimates the number of free stack entries
+ *  required for its own use, and any child calls which are not (a) Duktape API calls
+ *  or (b) Duktape calls which involve extending the valstack (e.g. getter call).
+ */
+
+#define DUK_VALSTACK_ASSERT_EXTRA  5  /* this is added to checks to allow for Duktape
+                                       * API calls in addition to function's own use
+                                       */
+#if defined(DUK_USE_ASSERTIONS)
+#define DUK_ASSERT_VALSTACK_SPACE(thr,n)   do { \
+		DUK_ASSERT((thr) != NULL); \
+		DUK_ASSERT((thr)->valstack_end - (thr)->valstack_top >= (n) + DUK_VALSTACK_ASSERT_EXTRA); \
+	} while (0)
+#else
+#define DUK_ASSERT_VALSTACK_SPACE(thr,n)   /* no valstack space check */
+#endif
+
+/*
+ *  Error throwing helpers
+ *
+ *  The goal is to provide verbose and configurable error messages.  Call
+ *  sites should be clean in source code and compile to a small footprint.
+ *  Small footprint is also useful for performance because small cold paths
+ *  reduce code cache pressure.  Adding macros here only makes sense if there
+ *  are enough call sites to get concrete benefits.
+ */
+
+#if defined(DUK_USE_VERBOSE_ERRORS)
+/* Verbose errors with key/value summaries (non-paranoid) or without key/value
+ * summaries (paranoid, for some security sensitive environments), the paranoid
+ * vs. non-paranoid distinction affects only a few specific errors.
+ */
+#if defined(DUK_USE_PARANOID_ERRORS)
+#define DUK_ERROR_REQUIRE_TYPE_INDEX(thr,index,expectname,lowmemstr) do { \
+		duk_err_require_type_index((thr), DUK_FILE_MACRO, (duk_int_t) DUK_LINE_MACRO, (index), (expectname)); \
+	} while (0)
+#else  /* DUK_USE_PARANOID_ERRORS */
+#define DUK_ERROR_REQUIRE_TYPE_INDEX(thr,index,expectname,lowmemstr) do { \
+		duk_err_require_type_index((thr), DUK_FILE_MACRO, (duk_int_t) DUK_LINE_MACRO, (index), (expectname)); \
+	} while (0)
+#endif  /* DUK_USE_PARANOID_ERRORS */
+
+#define DUK_ERROR_UNIMPLEMENTED(thr,msg) do { \
+		DUK_ERROR((thr), DUK_ERR_UNIMPLEMENTED_ERROR, (msg)); \
+	} while (0)
+#define DUK_ERROR_UNIMPLEMENTED_DEFMSG(thr) do { \
+		duk_err_unimplemented_defmsg((thr), DUK_FILE_MACRO, (duk_int_t) DUK_LINE_MACRO); \
+	} while (0)
+#define DUK_ERROR_UNSUPPORTED(thr,msg) do { \
+		DUK_ERROR((thr), DUK_ERR_UNSUPPORTED_ERROR, (msg)); \
+	} while (0)
+#if !defined(DUK_USE_BYTECODE_DUMP_SUPPORT)
+#define DUK_ERROR_UNSUPPORTED_DEFMSG(thr) do { \
+		duk_err_unsupported_defmsg((thr), DUK_FILE_MACRO, (duk_int_t) DUK_LINE_MACRO); \
+	} while (0)
+#endif
+#define DUK_ERROR_INTERNAL(thr,msg) do { \
+		duk_err_internal((thr), DUK_FILE_MACRO, (duk_int_t) DUK_LINE_MACRO, (msg)); \
+	} while (0)
+#define DUK_ERROR_INTERNAL_DEFMSG(thr) do { \
+		duk_err_internal_defmsg((thr), DUK_FILE_MACRO, (duk_int_t) DUK_LINE_MACRO); \
+	} while (0)
+#define DUK_ERROR_ALLOC(thr,msg) do { \
+		duk_err_alloc((thr), DUK_FILE_MACRO, (duk_int_t) DUK_LINE_MACRO, (msg)); \
+	} while (0)
+#define DUK_ERROR_ALLOC_DEFMSG(thr) do { \
+		DUK_ERROR_ALLOC((thr), DUK_STR_ALLOC_FAILED); \
+	} while (0)
+/* DUK_ERR_ASSERTION_ERROR: no macros needed */
+#define DUK_ERROR_API_INDEX(thr,index) do { \
+		duk_err_api_index((thr), DUK_FILE_MACRO, (duk_int_t) DUK_LINE_MACRO, (index)); \
+	} while (0)
+#define DUK_ERROR_API(thr,msg) do { \
+		duk_err_api((thr), DUK_FILE_MACRO, (duk_int_t) DUK_LINE_MACRO, (msg)); \
+	} while (0)
+/* DUK_ERR_UNCAUGHT_ERROR: no macros needed */
+/* DUK_ERR_ERROR: no macros needed */
+/* DUK_ERR_EVAL: no macros needed */
+#define DUK_ERROR_RANGE(thr,msg) do { \
+		duk_err_range((thr), DUK_FILE_MACRO, (duk_int_t) DUK_LINE_MACRO, (msg)); \
+	} while (0)
+/* DUK_ERR_REFERENCE_ERROR: no macros needed */
+#define DUK_ERROR_SYNTAX(thr,msg) do { \
+		DUK_ERROR((thr), DUK_ERR_SYNTAX_ERROR, (msg)); \
+	} while (0)
+#define DUK_ERROR_TYPE(thr,msg) do { \
+		DUK_ERROR((thr), DUK_ERR_TYPE_ERROR, (msg)); \
+	} while (0)
+/* DUK_ERR_URI_ERROR: no macros needed */
+#else  /* DUK_USE_VERBOSE_ERRORS */
+/* Non-verbose errors for low memory targets: no file, line, or message. */
+
+#define DUK_ERROR_REQUIRE_TYPE_INDEX(thr,index,expectname,lowmemstr) do { \
+		duk_err_type((thr)); \
+	} while (0)
+
+#define DUK_ERROR_UNIMPLEMENTED(thr,msg) do { \
+		duk_err_unimplemented((thr)); \
+	} while (0)
+#define DUK_ERROR_UNIMPLEMENTED_DEFMSG(thr) do { \
+		duk_err_unimplemented((thr)); \
+	} while (0)
+#define DUK_ERROR_UNSUPPORTED(thr,msg) do { \
+		duk_err_unsupported((thr)); \
+	} while (0)
+#define DUK_ERROR_UNSUPPORTED_DEFMSG(thr) do { \
+		duk_err_unsupported((thr)); \
+	} while (0)
+#define DUK_ERROR_INTERNAL(thr,msg) do { \
+		duk_err_internal((thr)); \
+	} while (0)
+#define DUK_ERROR_INTERNAL_DEFMSG(thr) do { \
+		duk_err_internal((thr)); \
+	} while (0)
+#define DUK_ERROR_ALLOC(thr,msg) do { \
+		duk_err_alloc((thr)); \
+	} while (0)
+#define DUK_ERROR_ALLOC_DEFMSG(thr) do { \
+		duk_err_alloc((thr)); \
+	} while (0)
+#define DUK_ERROR_API_INDEX(thr,index) do { \
+		duk_err_api((thr)); \
+	} while (0)
+#define DUK_ERROR_API(thr,msg) do { \
+		duk_err_api((thr)); \
+	} while (0)
+#define DUK_ERROR_RANGE(thr,msg) do { \
+		duk_err_range((thr)); \
+	} while (0)
+#define DUK_ERROR_SYNTAX(thr,msg) do { \
+		duk_err_syntax((thr)); \
+	} while (0)
+#define DUK_ERROR_TYPE(thr,msg) do { \
+		duk_err_type((thr)); \
+	} while (0)
+#endif  /* DUK_USE_VERBOSE_ERRORS */
+
+/*
+ *  Prototypes
+ */
+
+#if defined(DUK_USE_VERBOSE_ERRORS)
+DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_handle_error(duk_hthread *thr, const char *filename, duk_uint_t line_and_code, const char *msg));
+DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_handle_error_fmt(duk_hthread *thr, const char *filename, duk_uint_t line_and_code, const char *fmt, ...));
+#else  /* DUK_USE_VERBOSE_ERRORS */
+DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_handle_error(duk_hthread *thr, duk_errcode_t code));
+#endif  /* DUK_USE_VERBOSE_ERRORS */
+
+#if defined(DUK_USE_VERBOSE_ERRORS)
+DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_create_and_throw(duk_hthread *thr, duk_errcode_t code, const char *msg, const char *filename, duk_int_t line));
+#else
+DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_create_and_throw(duk_hthread *thr, duk_errcode_t code));
+#endif
+
+DUK_NORETURN(DUK_INTERNAL_DECL void duk_error_throw_from_negative_rc(duk_hthread *thr, duk_ret_t rc));
+
+#if defined(DUK_USE_AUGMENT_ERROR_CREATE)
+DUK_INTERNAL_DECL void duk_err_augment_error_create(duk_hthread *thr, duk_hthread *thr_callstack, const char *filename, duk_int_t line, duk_bool_t noblame_fileline);
+#endif
+#if defined(DUK_USE_AUGMENT_ERROR_THROW)
+DUK_INTERNAL_DECL void duk_err_augment_error_throw(duk_hthread *thr);
+#endif
+
+#if defined(DUK_USE_VERBOSE_ERRORS)
+#if defined(DUK_USE_PARANOID_ERRORS)
+DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_require_type_index(duk_hthread *thr, const char *filename, duk_int_t linenumber, duk_idx_t index, const char *expect_name));
+#else
+DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_require_type_index(duk_hthread *thr, const char *filename, duk_int_t linenumber, duk_idx_t index, const char *expect_name));
+#endif
+DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_api_index(duk_hthread *thr, const char *filename, duk_int_t linenumber, duk_idx_t index));
+DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_api(duk_hthread *thr, const char *filename, duk_int_t linenumber, const char *message));
+DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_range(duk_hthread *thr, const char *filename, duk_int_t linenumber, const char *message));
+DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_unimplemented_defmsg(duk_hthread *thr, const char *filename, duk_int_t linenumber));
+#if !defined(DUK_USE_BYTECODE_DUMP_SUPPORT)
+DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_unsupported_defmsg(duk_hthread *thr, const char *filename, duk_int_t linenumber));
+#endif
+DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_internal_defmsg(duk_hthread *thr, const char *filename, duk_int_t linenumber));
+DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_internal(duk_hthread *thr, const char *filename, duk_int_t linenumber, const char *message));
+DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_alloc(duk_hthread *thr, const char *filename, duk_int_t linenumber, const char *message));
+#else  /* DUK_VERBOSE_ERRORS */
+DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_range(duk_hthread *thr));
+DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_syntax(duk_hthread *thr));
+DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_type(duk_hthread *thr));
+DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_api(duk_hthread *thr));
+DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_unimplemented(duk_hthread *thr));
+DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_unsupported(duk_hthread *thr));
+DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_internal(duk_hthread *thr));
+DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_alloc(duk_hthread *thr));
+#endif /* DUK_VERBOSE_ERRORS */
+
+DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_longjmp(duk_hthread *thr));
+
+DUK_NORETURN(DUK_INTERNAL_DECL void duk_default_fatal_handler(duk_context *ctx, duk_errcode_t code, const char *msg));
+
+#if !defined(DUK_USE_PANIC_HANDLER)
+DUK_NORETURN(DUK_INTERNAL_DECL void duk_default_panic_handler(duk_errcode_t code, const char *msg));
+#endif
+
+DUK_INTERNAL_DECL void duk_err_setup_heap_ljstate(duk_hthread *thr, duk_small_int_t lj_type);
+
+DUK_INTERNAL_DECL duk_hobject *duk_error_prototype_from_code(duk_hthread *thr, duk_errcode_t err_code);
+
+#endif  /* DUK_ERROR_H_INCLUDED */

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_error_augment.c
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_error_augment.c b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_error_augment.c
new file mode 100644
index 0000000..ea15690
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_error_augment.c
@@ -0,0 +1,567 @@
+/*
+ *  Augmenting errors at their creation site and their throw site.
+ *
+ *  When errors are created, traceback data is added by built-in code
+ *  and a user error handler (if defined) can process or replace the
+ *  error.  Similarly, when errors are thrown, a user error handler
+ *  (if defined) can process or replace the error.
+ *
+ *  Augmentation and other processing at error creation time is nice
+ *  because an error is only created once, but it may be thrown and
+ *  rethrown multiple times.  User error handler registered for processing
+ *  an error at its throw site must be careful to handle rethrowing in
+ *  a useful manner.
+ *
+ *  Error augmentation may throw an internal error (e.g. alloc error).
+ *
+ *  Ecmascript allows throwing any values, so all values cannot be
+ *  augmented.  Currently, the built-in augmentation at error creation
+ *  only augments error values which are Error instances (= have the
+ *  built-in Error.prototype in their prototype chain) and are also
+ *  extensible.  User error handlers have no limitations in this respect.
+ */
+
+#include "duk_internal.h"
+
+/*
+ *  Helper for calling a user error handler.
+ *
+ *  'thr' must be the currently active thread; the error handler is called
+ *  in its context.  The valstack of 'thr' must have the error value on
+ *  top, and will be replaced by another error value based on the return
+ *  value of the error handler.
+ *
+ *  The helper calls duk_handle_call() recursively in protected mode.
+ *  Before that call happens, no longjmps should happen; as a consequence,
+ *  we must assume that the valstack contains enough temporary space for
+ *  arguments and such.
+ *
+ *  While the error handler runs, any errors thrown will not trigger a
+ *  recursive error handler call (this is implemented using a heap level
+ *  flag which will "follow" through any coroutines resumed inside the
+ *  error handler).  If the error handler is not callable or throws an
+ *  error, the resulting error replaces the original error (for Duktape
+ *  internal errors, duk_error_throw.c further substitutes this error with
+ *  a DoubleError which is not ideal).  This would be easy to change and
+ *  even signal to the caller.
+ *
+ *  The user error handler is stored in 'Duktape.errCreate' or
+ *  'Duktape.errThrow' depending on whether we're augmenting the error at
+ *  creation or throw time.  There are several alternatives to this approach,
+ *  see doc/error-objects.rst for discussion.
+ *
+ *  Note: since further longjmp()s may occur while calling the error handler
+ *  (for many reasons, e.g. a labeled 'break' inside the handler), the
+ *  caller can make no assumptions on the thr->heap->lj state after the
+ *  call (this affects especially duk_error_throw.c).  This is not an issue
+ *  as long as the caller writes to the lj state only after the error handler
+ *  finishes.
+ */
+
+#if defined(DUK_USE_ERRTHROW) || defined(DUK_USE_ERRCREATE)
+DUK_LOCAL void duk__err_augment_user(duk_hthread *thr, duk_small_uint_t stridx_cb) {
+	duk_context *ctx = (duk_context *) thr;
+	duk_tval *tv_hnd;
+	duk_small_uint_t call_flags;
+	duk_int_t rc;
+
+	DUK_ASSERT(thr != NULL);
+	DUK_ASSERT(thr->heap != NULL);
+	DUK_ASSERT_DISABLE(stridx_cb >= 0);  /* unsigned */
+	DUK_ASSERT(stridx_cb < DUK_HEAP_NUM_STRINGS);
+
+	if (DUK_HEAP_HAS_ERRHANDLER_RUNNING(thr->heap)) {
+		DUK_DD(DUK_DDPRINT("recursive call to error handler, ignore"));
+		return;
+	}
+
+	/*
+	 *  Check whether or not we have an error handler.
+	 *
+	 *  We must be careful of not triggering an error when looking up the
+	 *  property.  For instance, if the property is a getter, we don't want
+	 *  to call it, only plain values are allowed.  The value, if it exists,
+	 *  is not checked.  If the value is not a function, a TypeError happens
+	 *  when it is called and that error replaces the original one.
+	 */
+
+	DUK_ASSERT_VALSTACK_SPACE(thr, 4);  /* 3 entries actually needed below */
+
+	/* [ ... errval ] */
+
+	if (thr->builtins[DUK_BIDX_DUKTAPE] == NULL) {
+		/* When creating built-ins, some of the built-ins may not be set
+		 * and we want to tolerate that when throwing errors.
+		 */
+		DUK_DD(DUK_DDPRINT("error occurred when DUK_BIDX_DUKTAPE is NULL, ignoring"));
+		return;
+	}
+	tv_hnd = duk_hobject_find_existing_entry_tval_ptr(thr->heap,
+	                                                  thr->builtins[DUK_BIDX_DUKTAPE],
+	                                                  DUK_HTHREAD_GET_STRING(thr, stridx_cb));
+	if (tv_hnd == NULL) {
+		DUK_DD(DUK_DDPRINT("error handler does not exist or is not a plain value: %!T",
+		                   (duk_tval *) tv_hnd));
+		return;
+	}
+	DUK_DDD(DUK_DDDPRINT("error handler dump (callability not checked): %!T",
+	                     (duk_tval *) tv_hnd));
+	duk_push_tval(ctx, tv_hnd);
+
+	/* [ ... errval errhandler ] */
+
+	duk_insert(ctx, -2);  /* -> [ ... errhandler errval ] */
+	duk_push_undefined(ctx);
+	duk_insert(ctx, -2);  /* -> [ ... errhandler undefined(= this) errval ] */
+
+	/* [ ... errhandler undefined errval ] */
+
+	/*
+	 *  DUK_CALL_FLAG_IGNORE_RECLIMIT causes duk_handle_call() to ignore C
+	 *  recursion depth limit (and won't increase it either).  This is
+	 *  dangerous, but useful because it allows the error handler to run
+	 *  even if the original error is caused by C recursion depth limit.
+	 *
+	 *  The heap level DUK_HEAP_FLAG_ERRHANDLER_RUNNING is set for the
+	 *  duration of the error handler and cleared afterwards.  This flag
+	 *  prevents the error handler from running recursively.  The flag is
+	 *  heap level so that the flag properly controls even coroutines
+	 *  launched by an error handler.  Since the flag is heap level, it is
+	 *  critical to restore it correctly.
+	 *
+	 *  We ignore errors now: a success return and an error value both
+	 *  replace the original error value.  (This would be easy to change.)
+	 */
+
+	DUK_ASSERT(!DUK_HEAP_HAS_ERRHANDLER_RUNNING(thr->heap));  /* since no recursive error handler calls */
+	DUK_HEAP_SET_ERRHANDLER_RUNNING(thr->heap);
+
+	call_flags = DUK_CALL_FLAG_IGNORE_RECLIMIT;  /* ignore reclimit, not constructor */
+
+	rc = duk_handle_call_protected(thr,
+	                               1,            /* num args */
+	                               call_flags);  /* call_flags */
+	DUK_UNREF(rc);  /* no need to check now: both success and error are OK */
+
+	DUK_ASSERT(DUK_HEAP_HAS_ERRHANDLER_RUNNING(thr->heap));
+	DUK_HEAP_CLEAR_ERRHANDLER_RUNNING(thr->heap);
+
+	/* [ ... errval ] */
+}
+#endif  /* DUK_USE_ERRTHROW || DUK_USE_ERRCREATE */
+
+/*
+ *  Add ._Tracedata to an error on the stack top.
+ */
+
+#if defined(DUK_USE_TRACEBACKS)
+DUK_LOCAL void duk__add_traceback(duk_hthread *thr, duk_hthread *thr_callstack, const char *c_filename, duk_int_t c_line, duk_bool_t noblame_fileline) {
+	duk_context *ctx = (duk_context *) thr;
+	duk_small_uint_t depth;
+	duk_int_t i, i_min;
+	duk_uarridx_t arr_idx;
+	duk_double_t d;
+
+	DUK_ASSERT(thr != NULL);
+	DUK_ASSERT(thr_callstack != NULL);
+	DUK_ASSERT(ctx != NULL);
+
+	/* [ ... error ] */
+
+	/*
+	 *  The traceback format is pretty arcane in an attempt to keep it compact
+	 *  and cheap to create.  It may change arbitrarily from version to version.
+	 *  It should be decoded/accessed through version specific accessors only.
+	 *
+	 *  See doc/error-objects.rst.
+	 */
+
+	DUK_DDD(DUK_DDDPRINT("adding traceback to object: %!T",
+	                     (duk_tval *) duk_get_tval(ctx, -1)));
+
+	duk_push_array(ctx);  /* XXX: specify array size, as we know it */
+	arr_idx = 0;
+
+	/* Compiler SyntaxErrors (and other errors) come first, and are
+	 * blamed by default (not flagged "noblame").
+	 */
+	if (thr->compile_ctx != NULL && thr->compile_ctx->h_filename != NULL) {
+		duk_push_hstring(ctx, thr->compile_ctx->h_filename);
+		duk_xdef_prop_index_wec(ctx, -2, arr_idx);
+		arr_idx++;
+
+		duk_push_uint(ctx, (duk_uint_t) thr->compile_ctx->curr_token.start_line);  /* (flags<<32) + (line), flags = 0 */
+		duk_xdef_prop_index_wec(ctx, -2, arr_idx);
+		arr_idx++;
+	}
+
+	/* Filename/line from C macros (__FILE__, __LINE__) are added as an
+	 * entry with a special format: (string, number).  The number contains
+	 * the line and flags.
+	 */
+
+	/* XXX: optimize: allocate an array part to the necessary size (upwards
+	 * estimate) and fill in the values directly into the array part; finally
+	 * update 'length'.
+	 */
+
+	/* XXX: using duk_put_prop_index() would cause obscure error cases when Array.prototype
+	 * has write-protected array index named properties.  This was seen as DoubleErrors
+	 * in e.g. some test262 test cases.  Using duk_xdef_prop_index() is better but heavier.
+	 * The best fix is to fill in the tracedata directly into the array part.  There are
+	 * no side effect concerns if the array part is allocated directly and only INCREFs
+	 * happen after that.
+	 */
+
+	/* [ ... error arr ] */
+
+	if (c_filename) {
+		duk_push_string(ctx, c_filename);
+		duk_xdef_prop_index_wec(ctx, -2, arr_idx);
+		arr_idx++;
+
+		d = (noblame_fileline ? ((duk_double_t) DUK_TB_FLAG_NOBLAME_FILELINE) * DUK_DOUBLE_2TO32 : 0.0) +
+		    (duk_double_t) c_line;
+		duk_push_number(ctx, d);
+		duk_xdef_prop_index_wec(ctx, -2, arr_idx);
+		arr_idx++;
+	}
+
+	/* traceback depth doesn't take into account the filename/line
+	 * special handling above (intentional)
+	 */
+	depth = DUK_USE_TRACEBACK_DEPTH;
+	i_min = (thr_callstack->callstack_top > (duk_size_t) depth ? (duk_int_t) (thr_callstack->callstack_top - depth) : 0);
+	DUK_ASSERT(i_min >= 0);
+
+	/* [ ... error arr ] */
+
+	DUK_ASSERT(thr_callstack->callstack_top <= DUK_INT_MAX);  /* callstack limits */
+	for (i = (duk_int_t) (thr_callstack->callstack_top - 1); i >= i_min; i--) {
+		duk_uint32_t pc;
+
+		/*
+		 *  Note: each API operation potentially resizes the callstack,
+		 *  so be careful to re-lookup after every operation.  Currently
+		 *  these is no issue because we don't store a temporary 'act'
+		 *  pointer at all.  (This would be a non-issue if we operated
+		 *  directly on the array part.)
+		 */
+
+		/* [... arr] */
+
+		DUK_ASSERT_DISABLE(thr_callstack->callstack[i].pc >= 0);  /* unsigned */
+
+		/* Add function object. */
+		duk_push_tval(ctx, &(thr_callstack->callstack + i)->tv_func);
+		duk_xdef_prop_index_wec(ctx, -2, arr_idx);
+		arr_idx++;
+
+		/* Add a number containing: pc, activation flags.
+		 *
+		 * PC points to next instruction, find offending PC.  Note that
+		 * PC == 0 for native code.
+		 */
+		pc = duk_hthread_get_act_prev_pc(thr_callstack, thr_callstack->callstack + i);
+		DUK_ASSERT_DISABLE(pc >= 0);  /* unsigned */
+		DUK_ASSERT((duk_double_t) pc < DUK_DOUBLE_2TO32);  /* assume PC is at most 32 bits and non-negative */
+		d = ((duk_double_t) thr_callstack->callstack[i].flags) * DUK_DOUBLE_2TO32 + (duk_double_t) pc;
+		duk_push_number(ctx, d);  /* -> [... arr num] */
+		duk_xdef_prop_index_wec(ctx, -2, arr_idx);
+		arr_idx++;
+	}
+
+	/* XXX: set with duk_hobject_set_length() when tracedata is filled directly */
+	duk_push_uint(ctx, (duk_uint_t) arr_idx);
+	duk_xdef_prop_stridx(ctx, -2, DUK_STRIDX_LENGTH, DUK_PROPDESC_FLAGS_WC);
+
+	/* [ ... error arr ] */
+
+	duk_xdef_prop_stridx_wec(ctx, -2, DUK_STRIDX_INT_TRACEDATA);  /* -> [ ... error ] */
+}
+#endif  /* DUK_USE_TRACEBACKS */
+
+/*
+ *  Add .fileName and .lineNumber to an error on the stack top.
+ */
+
+#if !defined(DUK_USE_TRACEBACKS)
+DUK_LOCAL void duk__add_fileline(duk_hthread *thr, duk_hthread *thr_callstack, const char *c_filename, duk_int_t c_line, duk_bool_t noblame_fileline) {
+	duk_context *ctx;
+#if defined(DUK_USE_ASSERTIONS)
+	duk_int_t entry_top;
+#endif
+
+	ctx = (duk_context *) thr;
+#if defined(DUK_USE_ASSERTIONS)
+	entry_top = duk_get_top(ctx);
+#endif
+
+	/*
+	 *  If tracebacks are disabled, 'fileName' and 'lineNumber' are added
+	 *  as plain own properties.  Since Error.prototype has accessors of
+	 *  the same name, we need to define own properties directly (cannot
+	 *  just use e.g. duk_put_prop_stridx).  Existing properties are not
+	 *  overwritten in case they already exist.
+	 */
+
+	if (thr->compile_ctx != NULL && thr->compile_ctx->h_filename != NULL) {
+		/* Compiler SyntaxError (or other error) gets the primary blame.
+		 * Currently no flag to prevent blaming.
+		 */
+		duk_push_uint(ctx, (duk_uint_t) thr->compile_ctx->curr_token.start_line);
+		duk_push_hstring(ctx, thr->compile_ctx->h_filename);
+	} else if (c_filename && !noblame_fileline) {
+		/* C call site gets blamed next, unless flagged not to do so.
+		 * XXX: file/line is disabled in minimal builds, so disable this
+		 * too when appropriate.
+		 */
+		duk_push_int(ctx, c_line);
+		duk_push_string(ctx, c_filename);
+	} else {
+		/* Finally, blame the innermost callstack entry which has a
+		 * .fileName property.
+		 */
+		duk_small_uint_t depth;
+		duk_int_t i, i_min;
+		duk_uint32_t ecma_line;
+
+		depth = DUK_USE_TRACEBACK_DEPTH;
+		i_min = (thr_callstack->callstack_top > (duk_size_t) depth ? (duk_int_t) (thr_callstack->callstack_top - depth) : 0);
+		DUK_ASSERT(i_min >= 0);
+
+		DUK_ASSERT(thr_callstack->callstack_top <= DUK_INT_MAX);  /* callstack limits */
+		for (i = (duk_int_t) (thr_callstack->callstack_top - 1); i >= i_min; i--) {
+			duk_activation *act;
+			duk_hobject *func;
+			duk_uint32_t pc;
+
+			DUK_UNREF(pc);
+			act = thr_callstack->callstack + i;
+			DUK_ASSERT(act >= thr_callstack->callstack && act < thr_callstack->callstack + thr_callstack->callstack_size);
+
+			func = DUK_ACT_GET_FUNC(act);
+			if (func == NULL) {
+				/* Lightfunc, not blamed now. */
+				continue;
+			}
+
+			/* PC points to next instruction, find offending PC,
+			 * PC == 0 for native code.
+			 */
+			pc = duk_hthread_get_act_prev_pc(thr, act);  /* thr argument only used for thr->heap, so specific thread doesn't matter */
+			DUK_ASSERT_DISABLE(pc >= 0);  /* unsigned */
+			DUK_ASSERT((duk_double_t) pc < DUK_DOUBLE_2TO32);  /* assume PC is at most 32 bits and non-negative */
+			act = NULL;  /* invalidated by pushes, so get out of the way */
+
+			duk_push_hobject(ctx, func);
+
+			/* [ ... error func ] */
+
+			duk_get_prop_stridx(ctx, -1, DUK_STRIDX_FILE_NAME);
+			if (!duk_is_string(ctx, -1)) {
+				duk_pop_2(ctx);
+				continue;
+			}
+
+			/* [ ... error func fileName ] */
+
+			ecma_line = 0;
+#if defined(DUK_USE_PC2LINE)
+			if (DUK_HOBJECT_IS_COMPILEDFUNCTION(func)) {
+				ecma_line = duk_hobject_pc2line_query(ctx, -2, (duk_uint_fast32_t) pc);
+			} else {
+				/* Native function, no relevant lineNumber. */
+			}
+#endif  /* DUK_USE_PC2LINE */
+			duk_push_u32(ctx, ecma_line);
+
+			/* [ ... error func fileName lineNumber ] */
+
+			duk_replace(ctx, -3);
+
+			/* [ ... error lineNumber fileName ] */
+			goto define_props;
+		}
+
+		/* No activation matches, use undefined for both .fileName and
+		 * .lineNumber (matches what we do with a _Tracedata based
+		 * no-match lookup.
+		 */
+		duk_push_undefined(ctx);
+		duk_push_undefined(ctx);
+	}
+
+ define_props:
+	/* [ ... error lineNumber fileName ] */
+#if defined(DUK_USE_ASSERTIONS)
+	DUK_ASSERT(duk_get_top(ctx) == entry_top + 2);
+#endif
+	duk_xdef_prop_stridx(ctx, -3, DUK_STRIDX_FILE_NAME, DUK_PROPDESC_FLAGS_WC | DUK_PROPDESC_FLAG_NO_OVERWRITE);
+	duk_xdef_prop_stridx(ctx, -2, DUK_STRIDX_LINE_NUMBER, DUK_PROPDESC_FLAGS_WC | DUK_PROPDESC_FLAG_NO_OVERWRITE);
+}
+#endif  /* !DUK_USE_TRACEBACKS */
+
+/*
+ *  Add line number to a compiler error.
+ */
+
+DUK_LOCAL void duk__add_compiler_error_line(duk_hthread *thr) {
+	duk_context *ctx;
+
+	/* Append a "(line NNN)" to the "message" property of any error
+	 * thrown during compilation.  Usually compilation errors are
+	 * SyntaxErrors but they can also be out-of-memory errors and
+	 * the like.
+	 */
+
+	/* [ ... error ] */
+
+	ctx = (duk_context *) thr;
+	DUK_ASSERT(duk_is_object(ctx, -1));
+
+	if (!(thr->compile_ctx != NULL && thr->compile_ctx->h_filename != NULL)) {
+		return;
+	}
+
+	DUK_DDD(DUK_DDDPRINT("compile error, before adding line info: %!T",
+	                     (duk_tval *) duk_get_tval(ctx, -1)));
+
+	if (duk_get_prop_stridx(ctx, -1, DUK_STRIDX_MESSAGE)) {
+		duk_push_sprintf(ctx, " (line %ld)", (long) thr->compile_ctx->curr_token.start_line);
+		duk_concat(ctx, 2);
+		duk_put_prop_stridx(ctx, -2, DUK_STRIDX_MESSAGE);
+	} else {
+		duk_pop(ctx);
+	}
+
+	DUK_DDD(DUK_DDDPRINT("compile error, after adding line info: %!T",
+	                     (duk_tval *) duk_get_tval(ctx, -1)));
+}
+
+/*
+ *  Augment an error being created using Duktape specific properties
+ *  like _Tracedata or .fileName/.lineNumber.
+ */
+
+#if defined(DUK_USE_AUGMENT_ERROR_CREATE)
+DUK_LOCAL void duk__err_augment_builtin_create(duk_hthread *thr, duk_hthread *thr_callstack, const char *c_filename, duk_int_t c_line, duk_small_int_t noblame_fileline, duk_hobject *obj) {
+	duk_context *ctx = (duk_context *) thr;
+#if defined(DUK_USE_ASSERTIONS)
+	duk_int_t entry_top;
+#endif
+
+#if defined(DUK_USE_ASSERTIONS)
+	entry_top = duk_get_top(ctx);
+#endif
+	DUK_ASSERT(obj != NULL);
+
+	DUK_UNREF(obj);  /* unreferenced w/o tracebacks */
+	DUK_UNREF(ctx);  /* unreferenced w/o asserts */
+
+	duk__add_compiler_error_line(thr);
+
+#if defined(DUK_USE_TRACEBACKS)
+	/* If tracebacks are enabled, the '_Tracedata' property is the only
+	 * thing we need: 'fileName' and 'lineNumber' are virtual properties
+	 * which use '_Tracedata'.
+	 */
+	if (duk_hobject_hasprop_raw(thr, obj, DUK_HTHREAD_STRING_INT_TRACEDATA(thr))) {
+		DUK_DDD(DUK_DDDPRINT("error value already has a '_Tracedata' property, not modifying it"));
+	} else {
+		duk__add_traceback(thr, thr_callstack, c_filename, c_line, noblame_fileline);
+	}
+#else
+	/* Without tracebacks the concrete .fileName and .lineNumber need
+	 * to be added directly.
+	 */
+	duk__add_fileline(thr, thr_callstack, c_filename, c_line, noblame_fileline);
+#endif
+
+#if defined(DUK_USE_ASSERTIONS)
+	DUK_ASSERT(duk_get_top(ctx) == entry_top);
+#endif
+}
+#endif  /* DUK_USE_AUGMENT_ERROR_CREATE */
+
+/*
+ *  Augment an error at creation time with _Tracedata/fileName/lineNumber
+ *  and allow a user error handler (if defined) to process/replace the error.
+ *  The error to be augmented is at the stack top.
+ *
+ *  thr: thread containing the error value
+ *  thr_callstack: thread which should be used for generating callstack etc.
+ *  c_filename: C __FILE__ related to the error
+ *  c_line: C __LINE__ related to the error
+ *  noblame_fileline: if true, don't fileName/line as error source, otherwise use traceback
+ *                    (needed because user code filename/line are reported but internal ones
+ *                    are not)
+ *
+ *  XXX: rename noblame_fileline to flags field; combine it to some existing
+ *  field (there are only a few call sites so this may not be worth it).
+ */
+
+#if defined(DUK_USE_AUGMENT_ERROR_CREATE)
+DUK_INTERNAL void duk_err_augment_error_create(duk_hthread *thr, duk_hthread *thr_callstack, const char *c_filename, duk_int_t c_line, duk_bool_t noblame_fileline) {
+	duk_context *ctx = (duk_context *) thr;
+	duk_hobject *obj;
+
+	DUK_ASSERT(thr != NULL);
+	DUK_ASSERT(thr_callstack != NULL);
+	DUK_ASSERT(ctx != NULL);
+
+	/* [ ... error ] */
+
+	/*
+	 *  Criteria for augmenting:
+	 *
+	 *   - augmentation enabled in build (naturally)
+	 *   - error value internal prototype chain contains the built-in
+	 *     Error prototype object (i.e. 'val instanceof Error')
+	 *
+	 *  Additional criteria for built-in augmenting:
+	 *
+	 *   - error value is an extensible object
+	 */
+
+	obj = duk_get_hobject(ctx, -1);
+	if (!obj) {
+		DUK_DDD(DUK_DDDPRINT("value is not an object, skip both built-in and user augment"));
+		return;
+	}
+	if (!duk_hobject_prototype_chain_contains(thr, obj, thr->builtins[DUK_BIDX_ERROR_PROTOTYPE], 1 /*ignore_loop*/)) {
+		/* If the value has a prototype loop, it's critical not to
+		 * throw here.  Instead, assume the value is not to be
+		 * augmented.
+		 */
+		DUK_DDD(DUK_DDDPRINT("value is not an error instance, skip both built-in and user augment"));
+		return;
+	}
+	if (DUK_HOBJECT_HAS_EXTENSIBLE(obj)) {
+		DUK_DDD(DUK_DDDPRINT("error meets criteria, built-in augment"));
+		duk__err_augment_builtin_create(thr, thr_callstack, c_filename, c_line, noblame_fileline, obj);
+	} else {
+		DUK_DDD(DUK_DDDPRINT("error does not meet criteria, no built-in augment"));
+	}
+
+	/* [ ... error ] */
+
+#if defined(DUK_USE_ERRCREATE)
+	duk__err_augment_user(thr, DUK_STRIDX_ERR_CREATE);
+#endif
+}
+#endif  /* DUK_USE_AUGMENT_ERROR_CREATE */
+
+/*
+ *  Augment an error at throw time; allow a user error handler (if defined)
+ *  to process/replace the error.  The error to be augmented is at the
+ *  stack top.
+ */
+
+#if defined(DUK_USE_AUGMENT_ERROR_THROW)
+DUK_INTERNAL void duk_err_augment_error_throw(duk_hthread *thr) {
+#if defined(DUK_USE_ERRTHROW)
+	duk__err_augment_user(thr, DUK_STRIDX_ERR_THROW);
+#endif  /* DUK_USE_ERRTHROW */
+}
+#endif  /* DUK_USE_AUGMENT_ERROR_THROW */

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_error_longjmp.c
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_error_longjmp.c b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_error_longjmp.c
new file mode 100644
index 0000000..bfb1b46
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_error_longjmp.c
@@ -0,0 +1,45 @@
+/*
+ *  Do a longjmp call, calling the fatal error handler if no
+ *  catchpoint exists.
+ */
+
+#include "duk_internal.h"
+
+DUK_INTERNAL void duk_err_longjmp(duk_hthread *thr) {
+	DUK_ASSERT(thr != NULL);
+
+	DUK_DD(DUK_DDPRINT("longjmp error: type=%d iserror=%d value1=%!T value2=%!T",
+	                   (int) thr->heap->lj.type, (int) thr->heap->lj.iserror,
+	                   &thr->heap->lj.value1, &thr->heap->lj.value2));
+
+#if !defined(DUK_USE_CPP_EXCEPTIONS)
+	/* If we don't have a jmpbuf_ptr, there is little we can do
+	 * except panic.  The caller's expectation is that we never
+	 * return.
+	 *
+	 * With C++ exceptions we now just propagate an uncaught error
+	 * instead of invoking the fatal error handler.  Because there's
+	 * a dummy jmpbuf for C++ exceptions now, this could be changed.
+	 */
+	if (!thr->heap->lj.jmpbuf_ptr) {
+
+		DUK_D(DUK_DPRINT("uncaught error: type=%d iserror=%d value1=%!T value2=%!T",
+		                 (int) thr->heap->lj.type, (int) thr->heap->lj.iserror,
+		                 &thr->heap->lj.value1, &thr->heap->lj.value2));
+
+		duk_fatal((duk_context *) thr, DUK_ERR_UNCAUGHT_ERROR, "uncaught error");
+		DUK_UNREACHABLE();
+	}
+#endif  /* DUK_USE_CPP_EXCEPTIONS */
+
+#if defined(DUK_USE_CPP_EXCEPTIONS)
+	{
+		duk_internal_exception exc;  /* dummy */
+		throw exc;
+	}
+#else  /* DUK_USE_CPP_EXCEPTIONS */
+	DUK_LONGJMP(thr->heap->lj.jmpbuf_ptr->jb);
+#endif  /* DUK_USE_CPP_EXCEPTIONS */
+
+	DUK_UNREACHABLE();
+}

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_error_macros.c
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_error_macros.c b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_error_macros.c
new file mode 100644
index 0000000..9334d1f
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_error_macros.c
@@ -0,0 +1,163 @@
+/*
+ *  Error, fatal, and panic handling.
+ */
+
+#include "duk_internal.h"
+
+#define DUK__ERRFMT_BUFSIZE  256  /* size for formatting buffers */
+
+#if defined(DUK_USE_VERBOSE_ERRORS)
+
+DUK_INTERNAL void duk_err_handle_error_fmt(duk_hthread *thr, const char *filename, duk_uint_t line_and_code, const char *fmt, ...) {
+	va_list ap;
+	char msg[DUK__ERRFMT_BUFSIZE];
+	va_start(ap, fmt);
+	(void) DUK_VSNPRINTF(msg, sizeof(msg), fmt, ap);
+	msg[sizeof(msg) - 1] = (char) 0;
+	duk_err_create_and_throw(thr, (duk_errcode_t) (line_and_code >> 24), msg, filename, (duk_int_t) (line_and_code & 0x00ffffffL));
+	va_end(ap);  /* dead code, but ensures portability (see Linux man page notes) */
+}
+
+DUK_INTERNAL void duk_err_handle_error(duk_hthread *thr, const char *filename, duk_uint_t line_and_code, const char *msg) {
+	duk_err_create_and_throw(thr, (duk_errcode_t) (line_and_code >> 24), msg, filename, (duk_int_t) (line_and_code & 0x00ffffffL));
+}
+
+#else  /* DUK_USE_VERBOSE_ERRORS */
+
+DUK_INTERNAL void duk_err_handle_error(duk_hthread *thr, duk_errcode_t code) {
+	duk_err_create_and_throw(thr, code);
+}
+
+#endif  /* DUK_USE_VERBOSE_ERRORS */
+
+/*
+ *  Error throwing helpers
+ */
+
+#if defined(DUK_USE_VERBOSE_ERRORS)
+#if defined(DUK_USE_PARANOID_ERRORS)
+DUK_INTERNAL void duk_err_require_type_index(duk_hthread *thr, const char *filename, duk_int_t linenumber, duk_idx_t index, const char *expect_name) {
+	DUK_ERROR_RAW_FMT3(thr, filename, linenumber, DUK_ERR_TYPE_ERROR, "%s required, found %s (stack index %ld)",
+	                   expect_name, duk_get_type_name((duk_context *) thr, index), (long) index);
+}
+#else
+DUK_INTERNAL void duk_err_require_type_index(duk_hthread *thr, const char *filename, duk_int_t linenumber, duk_idx_t index, const char *expect_name) {
+	DUK_ERROR_RAW_FMT3(thr, filename, linenumber, DUK_ERR_TYPE_ERROR, "%s required, found %s (stack index %ld)",
+	                   expect_name, duk_push_string_readable((duk_context *) thr, index), (long) index);
+}
+#endif
+DUK_INTERNAL void duk_err_range(duk_hthread *thr, const char *filename, duk_int_t linenumber, const char *message) {
+	DUK_ERROR_RAW(thr, filename, linenumber, DUK_ERR_RANGE_ERROR, message);
+}
+DUK_INTERNAL void duk_err_api_index(duk_hthread *thr, const char *filename, duk_int_t linenumber, duk_idx_t index) {
+	DUK_ERROR_RAW_FMT1(thr, filename, linenumber, DUK_ERR_API_ERROR, "invalid stack index %ld", (long) (index));
+}
+DUK_INTERNAL void duk_err_api(duk_hthread *thr, const char *filename, duk_int_t linenumber, const char *message) {
+	DUK_ERROR_RAW(thr, filename, linenumber, DUK_ERR_API_ERROR, message);
+}
+DUK_INTERNAL void duk_err_unimplemented_defmsg(duk_hthread *thr, const char *filename, duk_int_t linenumber) {
+	DUK_ERROR_RAW(thr, filename, linenumber, DUK_ERR_UNIMPLEMENTED_ERROR, DUK_STR_UNIMPLEMENTED);
+}
+#if !defined(DUK_USE_BYTECODE_DUMP_SUPPORT)
+DUK_INTERNAL void duk_err_unsupported_defmsg(duk_hthread *thr, const char *filename, duk_int_t linenumber) {
+	DUK_ERROR_RAW(thr, filename, linenumber, DUK_ERR_UNSUPPORTED_ERROR, DUK_STR_UNSUPPORTED);
+}
+#endif
+DUK_INTERNAL void duk_err_internal_defmsg(duk_hthread *thr, const char *filename, duk_int_t linenumber) {
+	DUK_ERROR_RAW(thr, filename, linenumber, DUK_ERR_INTERNAL_ERROR, DUK_STR_INTERNAL_ERROR);
+}
+DUK_INTERNAL void duk_err_internal(duk_hthread *thr, const char *filename, duk_int_t linenumber, const char *message) {
+	DUK_ERROR_RAW(thr, filename, linenumber, DUK_ERR_INTERNAL_ERROR, message);
+}
+DUK_INTERNAL void duk_err_alloc(duk_hthread *thr, const char *filename, duk_int_t linenumber, const char *message) {
+	DUK_ERROR_RAW(thr, filename, linenumber, DUK_ERR_ALLOC_ERROR, message);
+}
+#else
+/* The file/line arguments are NULL and 0, they're ignored by DUK_ERROR_RAW()
+ * when non-verbose errors are used.
+ */
+DUK_INTERNAL void duk_err_type(duk_hthread *thr) {
+	DUK_ERROR_RAW(thr, NULL, 0, DUK_ERR_TYPE_ERROR, NULL);
+}
+DUK_INTERNAL void duk_err_api(duk_hthread *thr) {
+	DUK_ERROR_RAW(thr, NULL, 0, DUK_ERR_API_ERROR, NULL);
+}
+DUK_INTERNAL void duk_err_range(duk_hthread *thr) {
+	DUK_ERROR_RAW(thr, NULL, 0, DUK_ERR_RANGE_ERROR, NULL);
+}
+DUK_INTERNAL void duk_err_syntax(duk_hthread *thr) {
+	DUK_ERROR_RAW(thr, NULL, 0, DUK_ERR_SYNTAX_ERROR, NULL);
+}
+DUK_INTERNAL void duk_err_unimplemented(duk_hthread *thr) {
+	DUK_ERROR_RAW(thr, NULL, 0, DUK_ERR_UNIMPLEMENTED_ERROR, NULL);
+}
+DUK_INTERNAL void duk_err_unsupported(duk_hthread *thr) {
+	DUK_ERROR_RAW(thr, NULL, 0, DUK_ERR_UNSUPPORTED_ERROR, NULL);
+}
+DUK_INTERNAL void duk_err_internal(duk_hthread *thr) {
+	DUK_ERROR_RAW(thr, NULL, 0, DUK_ERR_INTERNAL_ERROR, NULL);
+}
+DUK_INTERNAL void duk_err_alloc(duk_hthread *thr) {
+	DUK_ERROR_RAW(thr, NULL, thr, DUK_ERR_ALLOC_ERROR, NULL);
+}
+#endif
+
+/*
+ *  Default fatal error handler
+ */
+
+DUK_INTERNAL void duk_default_fatal_handler(duk_context *ctx, duk_errcode_t code, const char *msg) {
+	DUK_UNREF(ctx);
+#if defined(DUK_USE_FILE_IO)
+	DUK_FPRINTF(DUK_STDERR, "FATAL %ld: %s\n", (long) code, (const char *) (msg ? msg : "null"));
+	DUK_FFLUSH(DUK_STDERR);
+#else
+	/* omit print */
+#endif
+	DUK_D(DUK_DPRINT("default fatal handler called, code %ld -> calling DUK_PANIC()", (long) code));
+	DUK_PANIC(code, msg);
+	DUK_UNREACHABLE();
+}
+
+/*
+ *  Default panic handler
+ */
+
+#if !defined(DUK_USE_PANIC_HANDLER)
+DUK_INTERNAL void duk_default_panic_handler(duk_errcode_t code, const char *msg) {
+#if defined(DUK_USE_FILE_IO)
+	DUK_FPRINTF(DUK_STDERR, "PANIC %ld: %s ("
+#if defined(DUK_USE_PANIC_ABORT)
+	            "calling abort"
+#elif defined(DUK_USE_PANIC_EXIT)
+	            "calling exit"
+#elif defined(DUK_USE_PANIC_SEGFAULT)
+	            "segfaulting on purpose"
+#else
+#error no DUK_USE_PANIC_xxx macro defined
+#endif
+	            ")\n", (long) code, (const char *) (msg ? msg : "null"));
+	DUK_FFLUSH(DUK_STDERR);
+#else
+	/* omit print */
+	DUK_UNREF(code);
+	DUK_UNREF(msg);
+#endif
+
+#if defined(DUK_USE_PANIC_ABORT)
+	DUK_ABORT();
+#elif defined(DUK_USE_PANIC_EXIT)
+	DUK_EXIT(-1);
+#elif defined(DUK_USE_PANIC_SEGFAULT)
+	/* exit() afterwards to satisfy "noreturn" */
+	DUK_CAUSE_SEGFAULT();  /* SCANBUILD: "Dereference of null pointer", normal */
+	DUK_EXIT(-1);
+#else
+#error no DUK_USE_PANIC_xxx macro defined
+#endif
+
+	DUK_UNREACHABLE();
+}
+#endif  /* !DUK_USE_PANIC_HANDLER */
+
+#undef DUK__ERRFMT_BUFSIZE

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_error_misc.c
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_error_misc.c b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_error_misc.c
new file mode 100644
index 0000000..5b37855
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_error_misc.c
@@ -0,0 +1,132 @@
+/*
+ *  Error helpers
+ */
+
+#include "duk_internal.h"
+
+/*
+ *  Helper to walk the thread chain and see if there is an active error
+ *  catcher.  Protected calls or finally blocks aren't considered catching.
+ */
+
+#if defined(DUK_USE_DEBUGGER_SUPPORT) && \
+    (defined(DUK_USE_DEBUGGER_THROW_NOTIFY) || defined(DUK_USE_DEBUGGER_PAUSE_UNCAUGHT))
+DUK_LOCAL duk_bool_t duk__have_active_catcher(duk_hthread *thr) {
+	/*
+	 * XXX: As noted above, a protected API call won't be counted as a
+	 * catcher. This is usually convenient, e.g. in the case of a top-
+	 * level duk_pcall(), but may not always be desirable. Perhaps add an
+	 * argument to treat them as catchers?
+	 */
+
+	duk_size_t i;
+
+	DUK_ASSERT(thr != NULL);
+
+	while (thr != NULL) {
+		for (i = 0; i < thr->catchstack_top; i++) {
+			duk_catcher *cat = thr->catchstack + i;
+			if (DUK_CAT_HAS_CATCH_ENABLED(cat)) {
+				return 1;  /* all we need to know */
+			}
+		}
+		thr = thr->resumer;
+	}
+	return 0;
+}
+#endif  /* DUK_USE_DEBUGGER_SUPPORT && (DUK_USE_DEBUGGER_THROW_NOTIFY || DUK_USE_DEBUGGER_PAUSE_UNCAUGHT) */
+
+/*
+ *  Get prototype object for an integer error code.
+ */
+
+DUK_INTERNAL duk_hobject *duk_error_prototype_from_code(duk_hthread *thr, duk_errcode_t code) {
+	switch (code) {
+	case DUK_ERR_EVAL_ERROR:
+		return thr->builtins[DUK_BIDX_EVAL_ERROR_PROTOTYPE];
+	case DUK_ERR_RANGE_ERROR:
+		return thr->builtins[DUK_BIDX_RANGE_ERROR_PROTOTYPE];
+	case DUK_ERR_REFERENCE_ERROR:
+		return thr->builtins[DUK_BIDX_REFERENCE_ERROR_PROTOTYPE];
+	case DUK_ERR_SYNTAX_ERROR:
+		return thr->builtins[DUK_BIDX_SYNTAX_ERROR_PROTOTYPE];
+	case DUK_ERR_TYPE_ERROR:
+		return thr->builtins[DUK_BIDX_TYPE_ERROR_PROTOTYPE];
+	case DUK_ERR_URI_ERROR:
+		return thr->builtins[DUK_BIDX_URI_ERROR_PROTOTYPE];
+
+	/* XXX: more specific error classes? */
+	case DUK_ERR_UNIMPLEMENTED_ERROR:
+	case DUK_ERR_INTERNAL_ERROR:
+	case DUK_ERR_ALLOC_ERROR:
+	case DUK_ERR_ASSERTION_ERROR:
+	case DUK_ERR_API_ERROR:
+	case DUK_ERR_ERROR:
+	default:
+		return thr->builtins[DUK_BIDX_ERROR_PROTOTYPE];
+	}
+}
+
+/*
+ *  Exposed helper for setting up heap longjmp state.
+ */
+
+DUK_INTERNAL void duk_err_setup_heap_ljstate(duk_hthread *thr, duk_small_int_t lj_type) {
+#if defined(DUK_USE_DEBUGGER_SUPPORT)
+	/* If something is thrown with the debugger attached and nobody will
+	 * catch it, execution is paused before the longjmp, turning over
+	 * control to the debug client.  This allows local state to be examined
+	 * before the stack is unwound.  Errors are not intercepted when debug
+	 * message loop is active (e.g. for Eval).
+	 */
+
+	/* XXX: Allow customizing the pause and notify behavior at runtime
+	 * using debugger runtime flags.  For now the behavior is fixed using
+	 * config options.
+	 */
+#if defined(DUK_USE_DEBUGGER_THROW_NOTIFY) || defined(DUK_USE_DEBUGGER_PAUSE_UNCAUGHT)
+	if (DUK_HEAP_IS_DEBUGGER_ATTACHED(thr->heap) &&
+	    !thr->heap->dbg_processing &&
+	    lj_type == DUK_LJ_TYPE_THROW) {
+		duk_context *ctx = (duk_context *) thr;
+		duk_bool_t fatal;
+		duk_hobject *h_obj;
+
+		/* Don't intercept a DoubleError, we may have caused the initial double
+		 * fault and attempting to intercept it will cause us to be called
+		 * recursively and exhaust the C stack.
+		 */
+		h_obj = duk_get_hobject(ctx, -1);
+		if (h_obj == thr->builtins[DUK_BIDX_DOUBLE_ERROR]) {
+			DUK_D(DUK_DPRINT("built-in DoubleError instance thrown, not intercepting"));
+			goto skip_throw_intercept;
+		}
+
+		DUK_D(DUK_DPRINT("throw with debugger attached, report to client"));
+
+		fatal = !duk__have_active_catcher(thr);
+
+#if defined(DUK_USE_DEBUGGER_THROW_NOTIFY)
+		/* Report it to the debug client */
+		duk_debug_send_throw(thr, fatal);
+#endif
+
+#if defined(DUK_USE_DEBUGGER_PAUSE_UNCAUGHT)
+		if (fatal) {
+			DUK_D(DUK_DPRINT("throw will be fatal, halt before longjmp"));
+			duk_debug_halt_execution(thr, 1 /*use_prev_pc*/);
+		}
+#endif
+	}
+
+ skip_throw_intercept:
+#endif  /* DUK_USE_DEBUGGER_THROW_NOTIFY || DUK_USE_DEBUGGER_PAUSE_UNCAUGHT */
+#endif  /* DUK_USE_DEBUGGER_SUPPORT */
+
+	thr->heap->lj.type = lj_type;
+
+	DUK_ASSERT(thr->valstack_top > thr->valstack);
+	DUK_TVAL_SET_TVAL_UPDREF(thr, &thr->heap->lj.value1, thr->valstack_top - 1);  /* side effects */
+
+	duk_pop((duk_context *) thr);
+}

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_error_throw.c
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_error_throw.c b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_error_throw.c
new file mode 100644
index 0000000..69b75f0
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_error_throw.c
@@ -0,0 +1,181 @@
+/*
+ *  Create and throw an Ecmascript error object based on a code and a message.
+ *
+ *  Used when we throw errors internally.  Ecmascript generated error objects
+ *  are created by Ecmascript code, and the throwing is handled by the bytecode
+ *  executor.
+ */
+
+#include "duk_internal.h"
+
+/*
+ *  Create and throw an error (originating from Duktape internally)
+ *
+ *  Push an error object on top of the stack, possibly throw augmenting
+ *  the error, and finally longjmp.
+ *
+ *  If an error occurs while we're dealing with the current error, we might
+ *  enter an infinite recursion loop.  This is prevented by detecting a
+ *  "double fault" through the heap->handling_error flag; the recursion
+ *  then stops at the second level.
+ */
+
+#ifdef DUK_USE_VERBOSE_ERRORS
+DUK_INTERNAL void duk_err_create_and_throw(duk_hthread *thr, duk_errcode_t code, const char *msg, const char *filename, duk_int_t line) {
+#else
+DUK_INTERNAL void duk_err_create_and_throw(duk_hthread *thr, duk_errcode_t code) {
+#endif
+	duk_context *ctx = (duk_context *) thr;
+	duk_bool_t double_error = thr->heap->handling_error;
+
+#ifdef DUK_USE_VERBOSE_ERRORS
+	DUK_DD(DUK_DDPRINT("duk_err_create_and_throw(): code=%ld, msg=%s, filename=%s, line=%ld",
+	                   (long) code, (const char *) msg,
+	                   (const char *) filename, (long) line));
+#else
+	DUK_DD(DUK_DDPRINT("duk_err_create_and_throw(): code=%ld", (long) code));
+#endif
+
+	DUK_ASSERT(thr != NULL);
+	DUK_ASSERT(ctx != NULL);
+
+	thr->heap->handling_error = 1;
+
+	if (!double_error) {
+		/* Allow headroom for calls during error handling (see GH-191).
+		 * We allow space for 10 additional recursions, with one extra
+		 * for, e.g. a print() call at the deepest level.
+		 */
+		DUK_ASSERT(thr->callstack_max == DUK_CALLSTACK_DEFAULT_MAX);
+		thr->callstack_max = DUK_CALLSTACK_DEFAULT_MAX + DUK_CALLSTACK_GROW_STEP + 11;
+	}
+
+	DUK_ASSERT(thr->callstack_max == DUK_CALLSTACK_DEFAULT_MAX + DUK_CALLSTACK_GROW_STEP + 11);  /* just making sure */
+
+	/* Sync so that augmentation sees up-to-date activations, NULL
+	 * thr->ptr_curr_pc so that it's not used if side effects occur
+	 * in augmentation or longjmp handling.
+	 */
+	duk_hthread_sync_and_null_currpc(thr);
+
+	/*
+	 *  Create and push an error object onto the top of stack.
+	 *  If a "double error" occurs, use a fixed error instance
+	 *  to avoid further trouble.
+	 */
+
+	/* XXX: if attempt to push beyond allocated valstack, this double fault
+	 * handling fails miserably.  We should really write the double error
+	 * directly to thr->heap->lj.value1 and avoid valstack use entirely.
+	 */
+
+	if (double_error) {
+		if (thr->builtins[DUK_BIDX_DOUBLE_ERROR]) {
+			DUK_D(DUK_DPRINT("double fault detected -> push built-in fixed 'double error' instance"));
+			duk_push_hobject_bidx(ctx, DUK_BIDX_DOUBLE_ERROR);
+		} else {
+			DUK_D(DUK_DPRINT("double fault detected; there is no built-in fixed 'double error' instance "
+			                 "-> push the error code as a number"));
+			duk_push_int(ctx, (duk_int_t) code);
+		}
+	} else {
+		/* Error object is augmented at its creation here. */
+		duk_require_stack(ctx, 1);
+		/* XXX: unnecessary '%s' formatting here, but cannot use
+		 * 'msg' as a format string directly.
+		 */
+#ifdef DUK_USE_VERBOSE_ERRORS
+		duk_push_error_object_raw(ctx,
+		                          code | DUK_ERRCODE_FLAG_NOBLAME_FILELINE,
+		                          filename,
+		                          line,
+		                          "%s",
+		                          (const char *) msg);
+#else
+		duk_push_error_object_raw(ctx,
+		                          code | DUK_ERRCODE_FLAG_NOBLAME_FILELINE,
+		                          NULL,
+		                          0,
+		                          NULL);
+#endif
+	}
+
+	/*
+	 *  Augment error (throw time), unless alloc/double error
+	 */
+
+	if (double_error || code == DUK_ERR_ALLOC_ERROR) {
+		DUK_D(DUK_DPRINT("alloc or double error: skip throw augmenting to avoid further trouble"));
+	} else {
+#if defined(DUK_USE_AUGMENT_ERROR_THROW)
+		DUK_DDD(DUK_DDDPRINT("THROW ERROR (INTERNAL): %!iT (before throw augment)",
+		                     (duk_tval *) duk_get_tval(ctx, -1)));
+		duk_err_augment_error_throw(thr);
+#endif
+	}
+
+	/*
+	 *  Finally, longjmp
+	 */
+
+	duk_err_setup_heap_ljstate(thr, DUK_LJ_TYPE_THROW);
+
+	thr->callstack_max = DUK_CALLSTACK_DEFAULT_MAX;  /* reset callstack limit */
+	thr->heap->handling_error = 0;
+
+	DUK_DDD(DUK_DDDPRINT("THROW ERROR (INTERNAL): %!iT, %!iT (after throw augment)",
+	                     (duk_tval *) &thr->heap->lj.value1, (duk_tval *) &thr->heap->lj.value2));
+
+	duk_err_longjmp(thr);
+	DUK_UNREACHABLE();
+}
+
+/*
+ *  Helper for C function call negative return values.
+ */
+
+DUK_INTERNAL void duk_error_throw_from_negative_rc(duk_hthread *thr, duk_ret_t rc) {
+	duk_context *ctx = (duk_context *) thr;
+	const char *msg;
+	duk_errcode_t code;
+
+	DUK_ASSERT(thr != NULL);
+	DUK_ASSERT(rc < 0);
+
+	/* XXX: this generates quite large code - perhaps select the error
+	 * class based on the code and then just use the error 'name'?
+	 */
+	/* XXX: shared strings */
+
+	code = -rc;
+
+	switch (rc) {
+	case DUK_RET_UNIMPLEMENTED_ERROR:  msg = "unimplemented"; break;
+	case DUK_RET_UNSUPPORTED_ERROR:    msg = "unsupported"; break;
+	case DUK_RET_INTERNAL_ERROR:       msg = "internal"; break;
+	case DUK_RET_ALLOC_ERROR:          msg = "alloc"; break;
+	case DUK_RET_ASSERTION_ERROR:      msg = "assertion"; break;
+	case DUK_RET_API_ERROR:            msg = "api"; break;
+	case DUK_RET_UNCAUGHT_ERROR:       msg = "uncaught"; break;
+	case DUK_RET_ERROR:                msg = "error"; break;
+	case DUK_RET_EVAL_ERROR:           msg = "eval"; break;
+	case DUK_RET_RANGE_ERROR:          msg = "range"; break;
+	case DUK_RET_REFERENCE_ERROR:      msg = "reference"; break;
+	case DUK_RET_SYNTAX_ERROR:         msg = "syntax"; break;
+	case DUK_RET_TYPE_ERROR:           msg = "type"; break;
+	case DUK_RET_URI_ERROR:            msg = "uri"; break;
+	default:                           msg = "unknown"; break;
+	}
+
+	DUK_ASSERT(msg != NULL);
+
+	/*
+	 *  The __FILE__ and __LINE__ information is intentionally not used in the
+	 *  creation of the error object, as it isn't useful in the tracedata.  The
+	 *  tracedata still contains the function which returned the negative return
+	 *  code, and having the file/line of this function isn't very useful.
+	 */
+
+	duk_error_raw(ctx, code, NULL, 0, "%s error (rc %ld)", (const char *) msg, (long) rc);
+	DUK_UNREACHABLE();
+}

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_exception.h
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_exception.h b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_exception.h
new file mode 100644
index 0000000..7df24de
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_exception.h
@@ -0,0 +1,18 @@
+/*
+ *  Exception for Duktape internal throws when C++ exceptions are used
+ *  for long control transfers.
+ *
+ *  Doesn't inherit from any exception base class to minimize the chance
+ *  that user code would accidentally catch this exception.
+ */
+
+#ifndef DUK_EXCEPTION_H_INCLUDED
+#define DUK_EXCEPTION_H_INCLUDED
+
+#if defined(DUK_USE_CPP_EXCEPTIONS)
+class duk_internal_exception {
+	/* intentionally empty */
+};
+#endif
+
+#endif  /* DUK_EXCEPTION_H_INCLUDED */

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_forwdecl.h
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_forwdecl.h b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_forwdecl.h
new file mode 100644
index 0000000..865d307
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_forwdecl.h
@@ -0,0 +1,122 @@
+/*
+ *  Forward declarations for all Duktape structures.
+ */
+
+#ifndef DUK_FORWDECL_H_INCLUDED
+#define DUK_FORWDECL_H_INCLUDED
+
+/*
+ *  Forward declarations
+ */
+
+#if defined(DUK_USE_CPP_EXCEPTIONS)
+class duk_internal_exception;
+#else
+struct duk_jmpbuf;
+#endif
+
+/* duk_tval intentionally skipped */
+struct duk_heaphdr;
+struct duk_heaphdr_string;
+struct duk_hstring;
+struct duk_hstring_external;
+struct duk_hobject;
+struct duk_hcompiledfunction;
+struct duk_hnativefunction;
+struct duk_hthread;
+struct duk_hbufferobject;
+struct duk_hbuffer;
+struct duk_hbuffer_fixed;
+struct duk_hbuffer_dynamic;
+struct duk_hbuffer_external;
+
+struct duk_propaccessor;
+union duk_propvalue;
+struct duk_propdesc;
+
+struct duk_heap;
+struct duk_breakpoint;
+
+struct duk_activation;
+struct duk_catcher;
+struct duk_strcache;
+struct duk_ljstate;
+struct duk_strtab_entry;
+
+#ifdef DUK_USE_DEBUG
+struct duk_fixedbuffer;
+#endif
+
+struct duk_bitdecoder_ctx;
+struct duk_bitencoder_ctx;
+struct duk_bufwriter_ctx;
+
+struct duk_token;
+struct duk_re_token;
+struct duk_lexer_point;
+struct duk_lexer_ctx;
+struct duk_lexer_codepoint;
+
+struct duk_compiler_instr;
+struct duk_compiler_func;
+struct duk_compiler_ctx;
+
+struct duk_re_matcher_ctx;
+struct duk_re_compiler_ctx;
+
+#if defined(DUK_USE_CPP_EXCEPTIONS)
+/* no typedef */
+#else
+typedef struct duk_jmpbuf duk_jmpbuf;
+#endif
+
+/* duk_tval intentionally skipped */
+typedef struct duk_heaphdr duk_heaphdr;
+typedef struct duk_heaphdr_string duk_heaphdr_string;
+typedef struct duk_hstring duk_hstring;
+typedef struct duk_hstring_external duk_hstring_external;
+typedef struct duk_hobject duk_hobject;
+typedef struct duk_hcompiledfunction duk_hcompiledfunction;
+typedef struct duk_hnativefunction duk_hnativefunction;
+typedef struct duk_hbufferobject duk_hbufferobject;
+typedef struct duk_hthread duk_hthread;
+typedef struct duk_hbuffer duk_hbuffer;
+typedef struct duk_hbuffer_fixed duk_hbuffer_fixed;
+typedef struct duk_hbuffer_dynamic duk_hbuffer_dynamic;
+typedef struct duk_hbuffer_external duk_hbuffer_external;
+
+typedef struct duk_propaccessor duk_propaccessor;
+typedef union duk_propvalue duk_propvalue;
+typedef struct duk_propdesc duk_propdesc;
+
+typedef struct duk_heap duk_heap;
+typedef struct duk_breakpoint duk_breakpoint;
+
+typedef struct duk_activation duk_activation;
+typedef struct duk_catcher duk_catcher;
+typedef struct duk_strcache duk_strcache;
+typedef struct duk_ljstate duk_ljstate;
+typedef struct duk_strtab_entry duk_strtab_entry;
+
+#ifdef DUK_USE_DEBUG
+typedef struct duk_fixedbuffer duk_fixedbuffer;
+#endif
+
+typedef struct duk_bitdecoder_ctx duk_bitdecoder_ctx;
+typedef struct duk_bitencoder_ctx duk_bitencoder_ctx;
+typedef struct duk_bufwriter_ctx duk_bufwriter_ctx;
+
+typedef struct duk_token duk_token;
+typedef struct duk_re_token duk_re_token;
+typedef struct duk_lexer_point duk_lexer_point;
+typedef struct duk_lexer_ctx duk_lexer_ctx;
+typedef struct duk_lexer_codepoint duk_lexer_codepoint;
+
+typedef struct duk_compiler_instr duk_compiler_instr;
+typedef struct duk_compiler_func duk_compiler_func;
+typedef struct duk_compiler_ctx duk_compiler_ctx;
+
+typedef struct duk_re_matcher_ctx duk_re_matcher_ctx;
+typedef struct duk_re_compiler_ctx duk_re_compiler_ctx;
+
+#endif  /* DUK_FORWDECL_H_INCLUDED */

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_hbuffer.h
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_hbuffer.h b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_hbuffer.h
new file mode 100644
index 0000000..e9417c0
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_hbuffer.h
@@ -0,0 +1,328 @@
+/*
+ *  Heap buffer representation.
+ *
+ *  Heap allocated user data buffer which is either:
+ *
+ *    1. A fixed size buffer (data follows header statically)
+ *    2. A dynamic size buffer (data pointer follows header)
+ *
+ *  The data pointer for a variable size buffer of zero size may be NULL.
+ */
+
+#ifndef DUK_HBUFFER_H_INCLUDED
+#define DUK_HBUFFER_H_INCLUDED
+
+/*
+ *  Flags
+ *
+ *  Fixed buffer:     0
+ *  Dynamic buffer:   DUK_HBUFFER_FLAG_DYNAMIC
+ *  External buffer:  DUK_HBUFFER_FLAG_DYNAMIC | DUK_HBUFFER_FLAG_EXTERNAL
+ */
+
+#define DUK_HBUFFER_FLAG_DYNAMIC                  DUK_HEAPHDR_USER_FLAG(0)    /* buffer is behind a pointer, dynamic or external */
+#define DUK_HBUFFER_FLAG_EXTERNAL                 DUK_HEAPHDR_USER_FLAG(1)    /* buffer pointer is to an externally allocated buffer */
+
+#define DUK_HBUFFER_HAS_DYNAMIC(x)                DUK_HEAPHDR_CHECK_FLAG_BITS(&(x)->hdr, DUK_HBUFFER_FLAG_DYNAMIC)
+#define DUK_HBUFFER_HAS_EXTERNAL(x)               DUK_HEAPHDR_CHECK_FLAG_BITS(&(x)->hdr, DUK_HBUFFER_FLAG_EXTERNAL)
+
+#define DUK_HBUFFER_SET_DYNAMIC(x)                DUK_HEAPHDR_SET_FLAG_BITS(&(x)->hdr, DUK_HBUFFER_FLAG_DYNAMIC)
+#define DUK_HBUFFER_SET_EXTERNAL(x)               DUK_HEAPHDR_SET_FLAG_BITS(&(x)->hdr, DUK_HBUFFER_FLAG_EXTERNAL)
+
+#define DUK_HBUFFER_CLEAR_DYNAMIC(x)              DUK_HEAPHDR_CLEAR_FLAG_BITS(&(x)->hdr, DUK_HBUFFER_FLAG_DYNAMIC)
+#define DUK_HBUFFER_CLEAR_EXTERNAL(x)             DUK_HEAPHDR_CLEAR_FLAG_BITS(&(x)->hdr, DUK_HBUFFER_FLAG_EXTERNAL)
+
+/*
+ *  Misc defines
+ */
+
+/* Impose a maximum buffer length for now.  Restricted artificially to
+ * ensure resize computations or adding a heap header length won't
+ * overflow size_t and that a signed duk_int_t can hold a buffer
+ * length.  The limit should be synchronized with DUK_HSTRING_MAX_BYTELEN.
+ */
+
+#if defined(DUK_USE_BUFLEN16)
+#define DUK_HBUFFER_MAX_BYTELEN                   (0x0000ffffUL)
+#else
+/* Intentionally not 0x7fffffffUL; at least JSON code expects that
+ * 2*len + 2 fits in 32 bits.
+ */
+#define DUK_HBUFFER_MAX_BYTELEN                   (0x7ffffffeUL)
+#endif
+
+/*
+ *  Field access
+ */
+
+/* Get/set the current user visible size, without accounting for a dynamic
+ * buffer's "spare" (= usable size).
+ */
+#if defined(DUK_USE_BUFLEN16)
+/* size stored in duk_heaphdr unused flag bits */
+#define DUK_HBUFFER_GET_SIZE(x)     ((x)->hdr.h_flags >> 16)
+#define DUK_HBUFFER_SET_SIZE(x,v)   do { \
+		duk_size_t duk__v; \
+		duk__v = (v); \
+		DUK_ASSERT(duk__v <= 0xffffUL); \
+		(x)->hdr.h_flags = ((x)->hdr.h_flags & 0x0000ffffUL) | (((duk_uint32_t) duk__v) << 16); \
+	} while (0)
+#define DUK_HBUFFER_ADD_SIZE(x,dv)  do { \
+		(x)->hdr.h_flags += ((dv) << 16); \
+	} while (0)
+#define DUK_HBUFFER_SUB_SIZE(x,dv)  do { \
+		(x)->hdr.h_flags -= ((dv) << 16); \
+	} while (0)
+#else
+#define DUK_HBUFFER_GET_SIZE(x)     (((duk_hbuffer *) (x))->size)
+#define DUK_HBUFFER_SET_SIZE(x,v)   do { \
+		((duk_hbuffer *) (x))->size = (v); \
+	} while (0)
+#define DUK_HBUFFER_ADD_SIZE(x,dv)  do { \
+		(x)->size += (dv); \
+	} while (0)
+#define DUK_HBUFFER_SUB_SIZE(x,dv)  do { \
+		(x)->size -= (dv); \
+	} while (0)
+#endif
+
+#define DUK_HBUFFER_FIXED_GET_SIZE(x)       DUK_HBUFFER_GET_SIZE((duk_hbuffer *) (x))
+#define DUK_HBUFFER_FIXED_SET_SIZE(x,v)     DUK_HBUFFER_SET_SIZE((duk_hbuffer *) (x))
+
+#define DUK_HBUFFER_DYNAMIC_GET_SIZE(x)     DUK_HBUFFER_GET_SIZE((duk_hbuffer *) (x))
+#define DUK_HBUFFER_DYNAMIC_SET_SIZE(x,v)   DUK_HBUFFER_SET_SIZE((duk_hbuffer *) (x), (v))
+#define DUK_HBUFFER_DYNAMIC_ADD_SIZE(x,dv)  DUK_HBUFFER_ADD_SIZE((duk_hbuffer *) (x), (dv))
+#define DUK_HBUFFER_DYNAMIC_SUB_SIZE(x,dv)  DUK_HBUFFER_SUB_SIZE((duk_hbuffer *) (x), (dv))
+
+#define DUK_HBUFFER_EXTERNAL_GET_SIZE(x)    DUK_HBUFFER_GET_SIZE((duk_hbuffer *) (x))
+#define DUK_HBUFFER_EXTERNAL_SET_SIZE(x,v)  DUK_HBUFFER_SET_SIZE((duk_hbuffer *) (x), (v))
+
+#define DUK_HBUFFER_FIXED_GET_DATA_PTR(heap,x)    ((duk_uint8_t *) (((duk_hbuffer_fixed *) (x)) + 1))
+
+#if defined(DUK_USE_HEAPPTR16)
+#define DUK_HBUFFER_DYNAMIC_GET_DATA_PTR(heap,x) \
+	((void *) DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, ((duk_heaphdr *) (x))->h_extra16))
+#define DUK_HBUFFER_DYNAMIC_SET_DATA_PTR(heap,x,v)     do { \
+		((duk_heaphdr *) (x))->h_extra16 = DUK_USE_HEAPPTR_ENC16((heap)->heap_udata, (void *) (v)); \
+	} while (0)
+#define DUK_HBUFFER_DYNAMIC_SET_DATA_PTR_NULL(heap,x)  do { \
+		((duk_heaphdr *) (x))->h_extra16 = 0;  /* assume 0 <=> NULL */ \
+	} while (0)
+#else
+#define DUK_HBUFFER_DYNAMIC_GET_DATA_PTR(heap,x)       ((x)->curr_alloc)
+#define DUK_HBUFFER_DYNAMIC_SET_DATA_PTR(heap,x,v)     do { \
+		(x)->curr_alloc = (void *) (v); \
+	} while (0)
+#define DUK_HBUFFER_DYNAMIC_SET_DATA_PTR_NULL(heap,x)  do { \
+		(x)->curr_alloc = (void *) NULL; \
+	} while (0)
+#endif
+
+/* No pointer compression because pointer is potentially outside of
+ * Duktape heap.
+ */
+#if defined(DUK_USE_HEAPPTR16)
+#define DUK_HBUFFER_EXTERNAL_GET_DATA_PTR(heap,x) \
+	((void *) (x)->curr_alloc)
+#define DUK_HBUFFER_EXTERNAL_SET_DATA_PTR(heap,x,v)     do { \
+		(x)->curr_alloc = (void *) (v); \
+	} while (0)
+#define DUK_HBUFFER_EXTERNAL_SET_DATA_PTR_NULL(heap,x)  do { \
+		(x)->curr_alloc = (void *) NULL; \
+	} while (0)
+#else
+#define DUK_HBUFFER_EXTERNAL_GET_DATA_PTR(heap,x) \
+	((void *) (x)->curr_alloc)
+#define DUK_HBUFFER_EXTERNAL_SET_DATA_PTR(heap,x,v)     do { \
+		(x)->curr_alloc = (void *) (v); \
+	} while (0)
+#define DUK_HBUFFER_EXTERNAL_SET_DATA_PTR_NULL(heap,x)  do { \
+		(x)->curr_alloc = (void *) NULL; \
+	} while (0)
+#endif
+
+/* Get a pointer to the current buffer contents (matching current allocation
+ * size).  May be NULL for zero size dynamic/external buffer.
+ */
+#if defined(DUK_USE_HEAPPTR16)
+#define DUK_HBUFFER_GET_DATA_PTR(heap,x)  ( \
+	DUK_HBUFFER_HAS_DYNAMIC((x)) ? \
+		( \
+			DUK_HBUFFER_HAS_EXTERNAL((x)) ? \
+				DUK_HBUFFER_EXTERNAL_GET_DATA_PTR((heap), (duk_hbuffer_external *) (x)) : \
+				DUK_HBUFFER_DYNAMIC_GET_DATA_PTR((heap), (duk_hbuffer_dynamic *) (x)) \
+		) : \
+		DUK_HBUFFER_FIXED_GET_DATA_PTR((heap), (duk_hbuffer_fixed *) (x)) \
+	)
+#else
+/* Without heap pointer compression duk_hbuffer_dynamic and duk_hbuffer_external
+ * have the same layout so checking for fixed vs. dynamic (or external) is enough.
+ */
+#define DUK_HBUFFER_GET_DATA_PTR(heap,x)  ( \
+	DUK_HBUFFER_HAS_DYNAMIC((x)) ? \
+		DUK_HBUFFER_DYNAMIC_GET_DATA_PTR((heap), (duk_hbuffer_dynamic *) (x)) : \
+		DUK_HBUFFER_FIXED_GET_DATA_PTR((heap), (duk_hbuffer_fixed *) (x)) \
+	)
+#endif
+
+/*
+ *  Structs
+ */
+
+/* Shared prefix for all buffer types. */
+struct duk_hbuffer {
+	duk_heaphdr hdr;
+
+	/* It's not strictly necessary to track the current size, but
+	 * it is useful for writing robust native code.
+	 */
+
+	/* Current size (not counting a dynamic buffer's "spare"). */
+#if defined(DUK_USE_BUFLEN16)
+	/* Stored in duk_heaphdr unused flags. */
+#else
+	duk_size_t size;
+#endif
+
+	/*
+	 *  Data following the header depends on the DUK_HBUFFER_FLAG_DYNAMIC
+	 *  flag.
+	 *
+	 *  If the flag is clear (the buffer is a fixed size one), the buffer
+	 *  data follows the header directly, consisting of 'size' bytes.
+	 *
+	 *  If the flag is set, the actual buffer is allocated separately, and
+	 *  a few control fields follow the header.  Specifically:
+	 *
+	 *    - a "void *" pointing to the current allocation
+	 *    - a duk_size_t indicating the full allocated size (always >= 'size')
+	 *
+	 *  If DUK_HBUFFER_FLAG_EXTERNAL is set, the buffer has been allocated
+	 *  by user code, so that Duktape won't be able to resize it and won't
+	 *  free it.  This allows buffers to point to e.g. an externally
+	 *  allocated structure such as a frame buffer.
+	 *
+	 *  Unlike strings, no terminator byte (NUL) is guaranteed after the
+	 *  data.  This would be convenient, but would pad aligned user buffers
+	 *  unnecessarily upwards in size.  For instance, if user code requested
+	 *  a 64-byte dynamic buffer, 65 bytes would actually be allocated which
+	 *  would then potentially round upwards to perhaps 68 or 72 bytes.
+	 */
+};
+
+/* Fixed buffer; data follows struct, with proper alignment guaranteed by
+ * struct size.
+ */
+#if (DUK_USE_ALIGN_BY == 8) && defined(DUK_USE_PACK_MSVC_PRAGMA)
+#pragma pack(push, 8)
+#endif
+struct duk_hbuffer_fixed {
+	/* A union is used here as a portable struct size / alignment trick:
+	 * by adding a 32-bit or a 64-bit (unused) union member, the size of
+	 * the struct is effectively forced to be a multiple of 4 or 8 bytes
+	 * (respectively) without increasing the size of the struct unless
+	 * necessary.
+	 */
+	union {
+		struct {
+			duk_heaphdr hdr;
+#if defined(DUK_USE_BUFLEN16)
+			/* Stored in duk_heaphdr unused flags. */
+#else
+			duk_size_t size;
+#endif
+		} s;
+#if (DUK_USE_ALIGN_BY == 4)
+		duk_uint32_t dummy_for_align4;
+#elif (DUK_USE_ALIGN_BY == 8)
+		duk_double_t dummy_for_align8;
+#elif (DUK_USE_ALIGN_BY == 1)
+		/* no extra padding */
+#else
+#error invalid DUK_USE_ALIGN_BY
+#endif
+	} u;
+
+	/*
+	 *  Data follows the struct header.  The struct size is padded by the
+	 *  compiler based on the struct members.  This guarantees that the
+	 *  buffer data will be aligned-by-4 but not necessarily aligned-by-8.
+	 *
+	 *  On platforms where alignment does not matter, the struct padding
+	 *  could be removed (if there is any).  On platforms where alignment
+	 *  by 8 is required, the struct size must be forced to be a multiple
+	 *  of 8 by some means.  Without it, some user code may break, and also
+	 *  Duktape itself breaks (e.g. the compiler stores duk_tvals in a
+	 *  dynamic buffer).
+	 */
+}
+#if (DUK_USE_ALIGN_BY == 8) && defined(DUK_USE_PACK_GCC_ATTR)
+__attribute__ ((aligned (8)))
+#elif (DUK_USE_ALIGN_BY == 8) && defined(DUK_USE_PACK_CLANG_ATTR)
+__attribute__ ((aligned (8)))
+#endif
+;
+#if (DUK_USE_ALIGN_BY == 8) && defined(DUK_USE_PACK_MSVC_PRAGMA)
+#pragma pack(pop)
+#endif
+
+/* Dynamic buffer with 'curr_alloc' pointing to a dynamic area allocated using
+ * heap allocation primitives.  Also used for external buffers when low memory
+ * options are not used.
+ */
+struct duk_hbuffer_dynamic {
+	duk_heaphdr hdr;
+
+#if defined(DUK_USE_BUFLEN16)
+	/* Stored in duk_heaphdr unused flags. */
+#else
+	duk_size_t size;
+#endif
+
+#if defined(DUK_USE_HEAPPTR16)
+	/* Stored in duk_heaphdr h_extra16. */
+#else
+	void *curr_alloc;  /* may be NULL if alloc_size == 0 */
+#endif
+
+	/*
+	 *  Allocation size for 'curr_alloc' is alloc_size.  There is no
+	 *  automatic NUL terminator for buffers (see above for rationale).
+	 *
+	 *  'curr_alloc' is explicitly allocated with heap allocation
+	 *  primitives and will thus always have alignment suitable for
+	 *  e.g. duk_tval and an IEEE double.
+	 */
+};
+
+/* External buffer with 'curr_alloc' managed by user code and pointing to an
+ * arbitrary address.  When heap pointer compression is not used, this struct
+ * has the same layout as duk_hbuffer_dynamic.
+ */
+struct duk_hbuffer_external {
+	duk_heaphdr hdr;
+
+#if defined(DUK_USE_BUFLEN16)
+	/* Stored in duk_heaphdr unused flags. */
+#else
+	duk_size_t size;
+#endif
+
+	/* Cannot be compressed as a heap pointer because may point to
+	 * an arbitrary address.
+	 */
+	void *curr_alloc;  /* may be NULL if alloc_size == 0 */
+};
+
+/*
+ *  Prototypes
+ */
+
+DUK_INTERNAL_DECL duk_hbuffer *duk_hbuffer_alloc(duk_heap *heap, duk_size_t size, duk_small_uint_t flags, void **out_bufdata);
+DUK_INTERNAL_DECL void *duk_hbuffer_get_dynalloc_ptr(duk_heap *heap, void *ud);  /* indirect allocs */
+
+/* dynamic buffer ops */
+DUK_INTERNAL_DECL void duk_hbuffer_resize(duk_hthread *thr, duk_hbuffer_dynamic *buf, duk_size_t new_size);
+DUK_INTERNAL_DECL void duk_hbuffer_reset(duk_hthread *thr, duk_hbuffer_dynamic *buf);
+
+#endif  /* DUK_HBUFFER_H_INCLUDED */


[42/51] [partial] nifi-minifi-cpp git commit: MINIFI-183 Added civet 1.9.1 sources Added onScheduled hook Added initial two-way TLS-enabled ListenHTTP implementation

Posted by al...@apache.org.
http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/examples/_obsolete/upload/upload.c
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/examples/_obsolete/upload/upload.c b/thirdparty/civetweb-1.9.1/examples/_obsolete/upload/upload.c
new file mode 100644
index 0000000..56c4be4
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/examples/_obsolete/upload/upload.c
@@ -0,0 +1,110 @@
+/* Copyright (c) 2014 the Civetweb developers
+ * Copyright (c) 2004-2012 Sergey Lyubka
+ * This file is a part of civetweb project, http://github.com/bel2125/civetweb
+ */
+
+/* This example is deprecated and no longer maintained.
+ * All relevant parts have been merged into the embedded_c example. */
+
+
+#ifdef _WIN32
+#ifndef _CRT_SECURE_NO_WARNINGS
+#define _CRT_SECURE_NO_WARNINGS
+#endif
+#include <windows.h>
+#include <io.h>
+#define strtoll strtol
+typedef __int64 int64_t;
+#else
+#include <inttypes.h>
+#include <unistd.h>
+#endif /* !_WIN32 */
+
+#include <stdio.h>
+#include <string.h>
+#include <fcntl.h>
+#include <stdlib.h>
+
+#include "civetweb.h"
+
+
+/* callback: used to generate all content */
+static int begin_request_handler(struct mg_connection *conn)
+{
+    const char * tempPath = ".";
+#ifdef _WIN32
+    const char * env = getenv("TEMP");
+    if (!env) env = getenv("TMP");
+    if (env) tempPath = env;
+#else
+    tempPath = "/tmp";
+#endif
+
+    if (!strcmp(mg_get_request_info(conn)->uri, "/handle_post_request")) {
+
+        mg_printf(conn, "%s", "HTTP/1.0 200 OK\r\n\r\n");
+        mg_upload(conn, tempPath);
+    } else {
+        /* Show HTML form. */
+        /* See http://www.w3.org/TR/html401/interact/forms.html#h-17.13.4.1 */
+        static const char *html_form =
+            "<html><body>Upload example."
+            ""
+            /* enctype="multipart/form-data" */
+            "<form method=\"POST\" action=\"/handle_post_request\" "
+            "  enctype=\"multipart/form-data\">"
+            "<input type=\"file\" name=\"file\" /> <br/>"
+            "<input type=\"file\" name=\"file2\" /> <br/>"
+            "<input type=\"submit\" value=\"Upload\" />"
+            "</form>"
+            ""
+            "</body></html>";
+
+        mg_printf(conn, "HTTP/1.0 200 OK\r\n"
+                  "Content-Length: %d\r\n"
+                  "Content-Type: text/html\r\n\r\n%s",
+                  (int) strlen(html_form), html_form);
+    }
+
+    /* Mark request as processed */
+    return 1;
+}
+
+
+/* callback: called after uploading a file is completed */
+static void upload_handler(struct mg_connection *conn, const char *path)
+{
+    mg_printf(conn, "Saved [%s]", path);
+}
+
+
+/* Main program: Set callbacks and start the server.  */
+int main(void)
+{
+    /* Test server will use this port */
+    const char * PORT = "8080";
+
+    /* Startup options for the server */
+    struct mg_context *ctx;
+    const char *options[] = {
+        "listening_ports", PORT,
+        NULL};
+    struct mg_callbacks callbacks;
+
+    memset(&callbacks, 0, sizeof(callbacks));
+    callbacks.begin_request = begin_request_handler;
+    callbacks.upload = upload_handler;
+
+    /* Display a welcome message */
+    printf("File upload demo.\n");
+    printf("Open http://localhost:%s/ in your browser.\n\n", PORT);
+
+    /* Start the server */
+    ctx = mg_start(&callbacks, NULL, options);
+
+    /* Wait until thr user hits "enter", then stop the server */
+    getchar();
+    mg_stop(ctx);
+
+    return 0;
+}

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/examples/_obsolete/websocket/WebSockCallbacks.c
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/examples/_obsolete/websocket/WebSockCallbacks.c b/thirdparty/civetweb-1.9.1/examples/_obsolete/websocket/WebSockCallbacks.c
new file mode 100644
index 0000000..bb81fb0
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/examples/_obsolete/websocket/WebSockCallbacks.c
@@ -0,0 +1,225 @@
+/* This example uses deprecated interfaces: global websocket callbacks.
+   They have been superseeded by URI specific callbacks.
+   See examples/embedded_c for an up to date example.
+   */
+
+#include <assert.h>
+#include <stdlib.h>
+#include <time.h>
+#include <string.h>
+#include "WebSockCallbacks.h"
+
+#ifdef _WIN32
+#include <windows.h>
+#define mg_sleep(x) Sleep(x)
+#else
+#include <unistd.h>
+#include <pthread.h>
+#define mg_sleep(x) usleep((x)*1000)
+#endif
+
+
+static void
+send_to_all_websockets(struct mg_context *ctx, const char *data, int data_len)
+{
+
+	int i;
+	tWebSockContext *ws_ctx = (tWebSockContext *)mg_get_user_data(ctx);
+
+	mg_lock_context(ctx);
+	for (i = 0; i < MAX_NUM_OF_WEBSOCKS; i++) {
+		if (ws_ctx->socketList[i]
+		    && (ws_ctx->socketList[i]->webSockState == 2)) {
+			mg_websocket_write(ws_ctx->socketList[i]->conn,
+			                   WEBSOCKET_OPCODE_TEXT,
+			                   data,
+			                   data_len);
+		}
+	}
+	mg_unlock_context(ctx);
+}
+
+
+void
+websocket_ready_handler(struct mg_connection *conn, void *_ignored)
+{
+
+	int i;
+	const struct mg_request_info *rq = mg_get_request_info(conn);
+	struct mg_context *ctx = mg_get_context(conn);
+	tWebSockContext *ws_ctx = (tWebSockContext *)mg_get_user_data(ctx);
+	tWebSockInfo *wsock = malloc(sizeof(tWebSockInfo));
+	assert(wsock);
+	wsock->webSockState = 0;
+	mg_set_user_connection_data(conn, wsock);
+
+	mg_lock_context(ctx);
+	for (i = 0; i < MAX_NUM_OF_WEBSOCKS; i++) {
+		if (0 == ws_ctx->socketList[i]) {
+			ws_ctx->socketList[i] = wsock;
+			wsock->conn = conn;
+			wsock->webSockState = 1;
+			break;
+		}
+	}
+	printf("\nNew websocket attached: %s:%u\n",
+	       rq->remote_addr,
+	       rq->remote_port);
+	mg_unlock_context(ctx);
+}
+
+
+static void
+websocket_done(tWebSockContext *ws_ctx, tWebSockInfo *wsock)
+{
+
+	int i;
+
+	if (wsock) {
+		wsock->webSockState = 99;
+		for (i = 0; i < MAX_NUM_OF_WEBSOCKS; i++) {
+			if (wsock == ws_ctx->socketList[i]) {
+				ws_ctx->socketList[i] = 0;
+				break;
+			}
+		}
+		printf("\nClose websocket attached: %s:%u\n",
+		       mg_get_request_info(wsock->conn)->remote_addr,
+		       mg_get_request_info(wsock->conn)->remote_port);
+		free(wsock);
+	}
+}
+
+
+int
+websocket_data_handler(struct mg_connection *conn,
+                       int flags,
+                       char *data,
+                       size_t data_len,
+                       void *_ignored)
+{
+
+	const struct mg_request_info *rq = mg_get_request_info(conn);
+	tWebSockInfo *wsock = (tWebSockInfo *)rq->conn_data;
+	struct mg_context *ctx = mg_get_context(conn);
+	tWebSockContext *ws_ctx = (tWebSockContext *)mg_get_user_data(ctx);
+	char msg[128];
+
+	mg_lock_context(ctx);
+	if (flags == 136) {
+		// close websock
+		websocket_done(ws_ctx, wsock);
+		mg_set_user_connection_data(conn, NULL);
+		mg_unlock_context(ctx);
+		return 1;
+	}
+	if (((data_len >= 5) && (data_len < 100) && (flags == 129))
+	    || (flags == 130)) {
+
+		// init command
+		if ((wsock->webSockState == 1) && (!memcmp(data, "init ", 5))) {
+			char *chk;
+			unsigned long gid;
+			memcpy(msg, data + 5, data_len - 5);
+			msg[data_len - 5] = 0;
+			gid = strtoul(msg, &chk, 10);
+			wsock->initId = gid;
+			if (gid > 0 && chk != NULL && *chk == 0) {
+				wsock->webSockState = 2;
+			}
+			mg_unlock_context(ctx);
+			return 1;
+		}
+
+		// chat message
+		if ((wsock->webSockState == 2) && (!memcmp(data, "msg ", 4))) {
+			send_to_all_websockets(ctx, data, data_len);
+			mg_unlock_context(ctx);
+			return 1;
+		}
+	}
+
+	// keep alive
+	if ((data_len == 4) && !memcmp(data, "ping", 4)) {
+		mg_unlock_context(ctx);
+		return 1;
+	}
+
+	mg_unlock_context(ctx);
+	return 0;
+}
+
+
+void
+connection_close_handler(const struct mg_connection *conn, void *_ignored)
+{
+
+	const struct mg_request_info *rq = mg_get_request_info(conn);
+	tWebSockInfo *wsock = (tWebSockInfo *)rq->conn_data;
+	struct mg_context *ctx = mg_get_context(conn);
+	tWebSockContext *ws_ctx = (tWebSockContext *)mg_get_user_data(ctx);
+
+	mg_lock_context(ctx);
+	websocket_done(ws_ctx, wsock);
+	mg_set_user_connection_data(conn, NULL);
+	mg_unlock_context(ctx);
+}
+
+
+static void *
+eventMain(void *arg)
+{
+
+	char msg[256];
+	struct mg_context *ctx = (struct mg_context *)arg;
+	tWebSockContext *ws_ctx = (tWebSockContext *)mg_get_user_data(ctx);
+
+	ws_ctx->runLoop = 1;
+	while (ws_ctx->runLoop) {
+		time_t t = time(0);
+		struct tm *timestr = localtime(&t);
+		strftime(msg, sizeof(msg), "title %c", timestr);
+		send_to_all_websockets(ctx, msg, strlen(msg));
+
+		mg_sleep(1000);
+	}
+
+	return NULL;
+}
+
+
+void
+websock_send_broadcast(struct mg_context *ctx, const char *data, int data_len)
+{
+
+	char buffer[260];
+
+	if (data_len <= 256) {
+		strcpy(buffer, "msg ");
+		memcpy(buffer + 4, data, data_len);
+
+		send_to_all_websockets(ctx, buffer, data_len + 4);
+	}
+}
+
+
+void
+websock_init_lib(const struct mg_context *ctx)
+{
+
+	tWebSockContext *ws_ctx = (tWebSockContext *)mg_get_user_data(ctx);
+	memset(ws_ctx, 0, sizeof(*ws_ctx));
+	/* todo: use mg_start_thread_id instead of mg_start_thread */
+	mg_start_thread(eventMain, (void *)ctx);
+}
+
+
+void
+websock_exit_lib(const struct mg_context *ctx)
+{
+
+	tWebSockContext *ws_ctx = (tWebSockContext *)mg_get_user_data(ctx);
+	ws_ctx->runLoop = 0;
+	/* todo: wait for the thread instead of a timeout */
+	mg_sleep(2000);
+}

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/examples/_obsolete/websocket/WebSockCallbacks.h
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/examples/_obsolete/websocket/WebSockCallbacks.h b/thirdparty/civetweb-1.9.1/examples/_obsolete/websocket/WebSockCallbacks.h
new file mode 100644
index 0000000..f44821d
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/examples/_obsolete/websocket/WebSockCallbacks.h
@@ -0,0 +1,44 @@
+
+#ifndef WEBSOCKCALLBACKS_H_INCLUDED
+#define WEBSOCKCALLBACKS_H_INCLUDED
+
+#include "civetweb.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct tWebSockInfo {
+	int webSockState;
+	unsigned long initId;
+	struct mg_connection *conn;
+} tWebSockInfo;
+
+#define MAX_NUM_OF_WEBSOCKS (256)
+typedef struct tWebSockContext {
+	int runLoop;
+	void *thread_id;
+	tWebSockInfo *socketList[MAX_NUM_OF_WEBSOCKS];
+} tWebSockContext;
+
+
+void websock_init_lib(const struct mg_context *ctx);
+void websock_exit_lib(const struct mg_context *ctx);
+
+void
+websock_send_broadcast(struct mg_context *ctx, const char *data, int data_len);
+
+void websocket_ready_handler(struct mg_connection *conn, void *_ignored);
+int websocket_data_handler(struct mg_connection *conn,
+                           int flags,
+                           char *data,
+                           size_t data_len,
+                           void *_ignored);
+void connection_close_handler(const struct mg_connection *conn, void *_ignored);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/examples/_obsolete/websocket/websock.htm
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/examples/_obsolete/websocket/websock.htm b/thirdparty/civetweb-1.9.1/examples/_obsolete/websocket/websock.htm
new file mode 100644
index 0000000..4ff3a5f
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/examples/_obsolete/websocket/websock.htm
@@ -0,0 +1,55 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
+<html>
+<head>
+  <title>Test</title>
+  <script type='text/javascript' language="javascript">
+  <!--
+  var connection;
+  var keepAlive = false;
+
+  function webSockKeepAlive() {
+    if (keepAlive) {
+      connection.send('ping'); // Send the message 'ping' to the server
+      setTimeout("webSockKeepAlive()", 10000);
+    }
+  }
+
+  function load() {
+    connection = new WebSocket("ws://127.0.0.1/MyWebSock");
+
+    connection.onopen = function () {
+        var send = "init " + Math.round(Math.random()*4294967294+1);
+        console.log('Client: ' + send);
+        connection.send(send);
+        keepAlive = true;
+        webSockKeepAlive();
+      };
+
+    connection.onerror = function (error) {
+        keepAlive = false;
+        connection.close();
+        console.log('WebSocket error: ' + error);
+        alert("WebSocket error");
+      };
+
+    connection.onmessage = function (e) {
+        console.log('Server: ' + e.data);
+        if (e.data.substring(0,5) == "title") {window.document.title = e.data.substring(6);}
+        else if (e.data.substring(0,3) == "msg") {
+          var msgStr = document.getElementById('msg');
+          msgStr.innerHTML = msgStr.innerHTML + e.data.substring(4);
+        }        
+      };
+  }
+  //-->
+  </script>
+
+</head>
+<body onload="load()">
+  <input type="button" onclick="connection.send('msg A');" value="A"></button>
+  <input type="button" onclick="connection.send('msg B');" value="B"></button>
+  <input type="button" onclick="connection.send('msg C');" value="C"></button>
+  <input type="button" onclick="connection.send('msg D');" value="D"></button>
+  <b id="msg"></b>
+</body>
+</html>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/examples/_obsolete/websocket/websocket.c
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/examples/_obsolete/websocket/websocket.c b/thirdparty/civetweb-1.9.1/examples/_obsolete/websocket/websocket.c
new file mode 100644
index 0000000..3aadf98
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/examples/_obsolete/websocket/websocket.c
@@ -0,0 +1,65 @@
+/* This example uses deprecated interfaces: global websocket callbacks.
+   They have been superseeded by URI specific callbacks.
+   See examples/embedded_c for an up to date example.
+   */
+
+#include <stdio.h>
+#include <ctype.h>
+#include <string.h>
+
+#include "civetweb.h"
+#include "WebSockCallbacks.h"
+
+int
+main(void)
+{
+	struct mg_context *ctx = 0;
+	struct mg_callbacks callback_funcs = {0};
+	tWebSockContext ws_ctx;
+	char inbuf[4];
+
+	const char *server_options[] = {
+	    /* document_root: The path to the test function websock.htm */
+	    "document_root",
+	    "../../examples/websocket",
+
+	    /* port: use http standard to match websocket url in websock.htm:
+	       ws://127.0.0.1/MyWebSock  */
+	    /*       if the port is changed here, it needs to be changed in
+	       websock.htm as well         */
+	    "listening_ports",
+	    "80",
+
+	    NULL};
+
+	callback_funcs.init_context = websock_init_lib;
+	callback_funcs.exit_context = websock_exit_lib;
+
+	ctx = mg_start(&callback_funcs, &ws_ctx, server_options);
+
+	mg_set_websocket_handler(ctx,
+	                         "/MyWebSock",
+	                         NULL,
+	                         websocket_ready_handler,
+	                         websocket_data_handler,
+	                         connection_close_handler,
+	                         NULL);
+
+	printf("Connect to localhost:%s/websock.htm\n",
+	       mg_get_option(ctx, "listening_ports"));
+
+	puts("Enter an (ASCII) character or * to exit:");
+	for (;;) {
+		fgets(inbuf, sizeof(inbuf), stdin);
+
+		if (inbuf[0] == '*') {
+			break;
+		}
+		inbuf[0] = toupper(inbuf[0]);
+		websock_send_broadcast(ctx, inbuf, 1);
+	}
+
+	mg_stop(ctx);
+
+	return 0;
+}

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/examples/_obsolete/websocket_client/ssl/server.crt
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/examples/_obsolete/websocket_client/ssl/server.crt b/thirdparty/civetweb-1.9.1/examples/_obsolete/websocket_client/ssl/server.crt
new file mode 100644
index 0000000..a26359a
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/examples/_obsolete/websocket_client/ssl/server.crt
@@ -0,0 +1,13 @@
+-----BEGIN CERTIFICATE-----
+MIICATCCAWoCCQC2BCIqIvgSUTANBgkqhkiG9w0BAQUFADBFMQswCQYDVQQGEwJB
+VTETMBEGA1UECAwKU29tZS1TdGF0ZTEhMB8GA1UECgwYSW50ZXJuZXQgV2lkZ2l0
+cyBQdHkgTHRkMB4XDTE0MDgyMTEyMzAwMVoXDTI0MDgxODEyMzAwMVowRTELMAkG
+A1UEBhMCQVUxEzARBgNVBAgMClNvbWUtU3RhdGUxITAfBgNVBAoMGEludGVybmV0
+IFdpZGdpdHMgUHR5IEx0ZDCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEA9k9s
+gH22BCo9neTeB/YnilK7n0sMe0+pjS9KSWhU59Q4w8hqPrW0tuYikIDd0wVggkJF
+BZNg4WPoulTdwXsgNBeG88q2wnNtUosXTS+KQTQBSiQof9Ay9GHQtgxnogI1zIXb
+HOppyyG5zre8a/X6fzDOnFc4iJMBwxTAnjCqObkCAwEAATANBgkqhkiG9w0BAQUF
+AAOBgQBX9V46VUVsB9P9fb8sFuMx2ezFE42ynEeJPrKRrof+dFYbjvR1OUZFSLCy
+aZKwVH7iCnVBJiU12JxO7PR3L6ob3FYPyNHQWYq1/IFUvqBRagehldj5H8iFeEDz
+Wtz2+p1rUyVxcSUqTjobaji0aC8lzPZio0nd1KKM6A92/adHyQ==
+-----END CERTIFICATE-----

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/examples/_obsolete/websocket_client/ssl/server.csr
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/examples/_obsolete/websocket_client/ssl/server.csr b/thirdparty/civetweb-1.9.1/examples/_obsolete/websocket_client/ssl/server.csr
new file mode 100644
index 0000000..4d4723b
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/examples/_obsolete/websocket_client/ssl/server.csr
@@ -0,0 +1,11 @@
+-----BEGIN CERTIFICATE REQUEST-----
+MIIBhDCB7gIBADBFMQswCQYDVQQGEwJBVTETMBEGA1UECAwKU29tZS1TdGF0ZTEh
+MB8GA1UECgwYSW50ZXJuZXQgV2lkZ2l0cyBQdHkgTHRkMIGfMA0GCSqGSIb3DQEB
+AQUAA4GNADCBiQKBgQD2T2yAfbYEKj2d5N4H9ieKUrufSwx7T6mNL0pJaFTn1DjD
+yGo+tbS25iKQgN3TBWCCQkUFk2DhY+i6VN3BeyA0F4bzyrbCc21SixdNL4pBNAFK
+JCh/0DL0YdC2DGeiAjXMhdsc6mnLIbnOt7xr9fp/MM6cVziIkwHDFMCeMKo5uQID
+AQABoAAwDQYJKoZIhvcNAQEFBQADgYEA1EOFwyFJ2NAnRNktZCy5yVcLx9C78HoC
+oHPPCOElu0VDIqe6ZecYdaqWbYlhGE0+isbOQn2CwHOeBGN8mIDsNUYzVEpsEfgg
+9OK873LpE5pf4mdjSiRBXkk/h8BxuqkcKi+Qx+qEE7+dH2nK5aKeIHVvbLyfGOch
+9I85q+msBNE=
+-----END CERTIFICATE REQUEST-----

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/examples/_obsolete/websocket_client/ssl/server.key
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/examples/_obsolete/websocket_client/ssl/server.key b/thirdparty/civetweb-1.9.1/examples/_obsolete/websocket_client/ssl/server.key
new file mode 100644
index 0000000..f09cc38
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/examples/_obsolete/websocket_client/ssl/server.key
@@ -0,0 +1,15 @@
+-----BEGIN RSA PRIVATE KEY-----
+MIICXQIBAAKBgQD2T2yAfbYEKj2d5N4H9ieKUrufSwx7T6mNL0pJaFTn1DjDyGo+
+tbS25iKQgN3TBWCCQkUFk2DhY+i6VN3BeyA0F4bzyrbCc21SixdNL4pBNAFKJCh/
+0DL0YdC2DGeiAjXMhdsc6mnLIbnOt7xr9fp/MM6cVziIkwHDFMCeMKo5uQIDAQAB
+AoGAYwospr3lomcZv5N3c9wWqhf6OWMD8dFma87IIBxDh7Rd3tuHXQ/TSnffDhvD
+FkbjN31OI5/PJNH3knTtdg78MywPloE4jYsbt4+fEaW7Fzww2nU61N1p+mYk5d/b
+SCTAHhGzF9g9ZMw25CCUFGjDU2z+Ty6my22Euxhk2Qq8tMECQQD9ZYIxWkPhywDW
+pX3v70dqIv7411hEYpuL/ZJl26UCmQsj4HPtXQCraQksVPs74WY5aTtd6MAV9V3M
+UnErHO5/AkEA+NdG2MmfBOBPusDB/WwQaUPiCWGITS9llGTR2JXbvDqmKgL1+UTG
+o27sLNIFCrF1wejpyRGqwjcObFYR0yKrxwJBAOB2uPuK4DL1psp9Uq/mIDbOxVod
+OF1rlCpP9w0vol5Iv+uJ+mc7SUqOAsg4h0yl/+2/YA1yDiXlcq96IDF2sXUCQGAv
+Nh9Nr72+xpK1N0axopZNuu1NWdYb3/PAFKzXIBxdvyS2CEXVo8JAeeHJPFGpzo6p
+bNRfk9WGWnjdu/4UhLkCQQCekR9zpIpzdJiPYCd6XMya+TPCDYlOQL1jlnJIRa2V
+BEOz0rSpzXAGh0PyCB/kMneyVk87LWn8joE6179RoUfv
+-----END RSA PRIVATE KEY-----

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/examples/_obsolete/websocket_client/ssl/server.pem
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/examples/_obsolete/websocket_client/ssl/server.pem b/thirdparty/civetweb-1.9.1/examples/_obsolete/websocket_client/ssl/server.pem
new file mode 100644
index 0000000..300834e
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/examples/_obsolete/websocket_client/ssl/server.pem
@@ -0,0 +1,28 @@
+-----BEGIN CERTIFICATE-----
+MIICATCCAWoCCQC2BCIqIvgSUTANBgkqhkiG9w0BAQUFADBFMQswCQYDVQQGEwJB
+VTETMBEGA1UECAwKU29tZS1TdGF0ZTEhMB8GA1UECgwYSW50ZXJuZXQgV2lkZ2l0
+cyBQdHkgTHRkMB4XDTE0MDgyMTEyMzAwMVoXDTI0MDgxODEyMzAwMVowRTELMAkG
+A1UEBhMCQVUxEzARBgNVBAgMClNvbWUtU3RhdGUxITAfBgNVBAoMGEludGVybmV0
+IFdpZGdpdHMgUHR5IEx0ZDCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEA9k9s
+gH22BCo9neTeB/YnilK7n0sMe0+pjS9KSWhU59Q4w8hqPrW0tuYikIDd0wVggkJF
+BZNg4WPoulTdwXsgNBeG88q2wnNtUosXTS+KQTQBSiQof9Ay9GHQtgxnogI1zIXb
+HOppyyG5zre8a/X6fzDOnFc4iJMBwxTAnjCqObkCAwEAATANBgkqhkiG9w0BAQUF
+AAOBgQBX9V46VUVsB9P9fb8sFuMx2ezFE42ynEeJPrKRrof+dFYbjvR1OUZFSLCy
+aZKwVH7iCnVBJiU12JxO7PR3L6ob3FYPyNHQWYq1/IFUvqBRagehldj5H8iFeEDz
+Wtz2+p1rUyVxcSUqTjobaji0aC8lzPZio0nd1KKM6A92/adHyQ==
+-----END CERTIFICATE-----
+-----BEGIN RSA PRIVATE KEY-----
+MIICXQIBAAKBgQD2T2yAfbYEKj2d5N4H9ieKUrufSwx7T6mNL0pJaFTn1DjDyGo+
+tbS25iKQgN3TBWCCQkUFk2DhY+i6VN3BeyA0F4bzyrbCc21SixdNL4pBNAFKJCh/
+0DL0YdC2DGeiAjXMhdsc6mnLIbnOt7xr9fp/MM6cVziIkwHDFMCeMKo5uQIDAQAB
+AoGAYwospr3lomcZv5N3c9wWqhf6OWMD8dFma87IIBxDh7Rd3tuHXQ/TSnffDhvD
+FkbjN31OI5/PJNH3knTtdg78MywPloE4jYsbt4+fEaW7Fzww2nU61N1p+mYk5d/b
+SCTAHhGzF9g9ZMw25CCUFGjDU2z+Ty6my22Euxhk2Qq8tMECQQD9ZYIxWkPhywDW
+pX3v70dqIv7411hEYpuL/ZJl26UCmQsj4HPtXQCraQksVPs74WY5aTtd6MAV9V3M
+UnErHO5/AkEA+NdG2MmfBOBPusDB/WwQaUPiCWGITS9llGTR2JXbvDqmKgL1+UTG
+o27sLNIFCrF1wejpyRGqwjcObFYR0yKrxwJBAOB2uPuK4DL1psp9Uq/mIDbOxVod
+OF1rlCpP9w0vol5Iv+uJ+mc7SUqOAsg4h0yl/+2/YA1yDiXlcq96IDF2sXUCQGAv
+Nh9Nr72+xpK1N0axopZNuu1NWdYb3/PAFKzXIBxdvyS2CEXVo8JAeeHJPFGpzo6p
+bNRfk9WGWnjdu/4UhLkCQQCekR9zpIpzdJiPYCd6XMya+TPCDYlOQL1jlnJIRa2V
+BEOz0rSpzXAGh0PyCB/kMneyVk87LWn8joE6179RoUfv
+-----END RSA PRIVATE KEY-----

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/examples/_obsolete/websocket_client/websocket_client.c
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/examples/_obsolete/websocket_client/websocket_client.c b/thirdparty/civetweb-1.9.1/examples/_obsolete/websocket_client/websocket_client.c
new file mode 100644
index 0000000..158ad7d
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/examples/_obsolete/websocket_client/websocket_client.c
@@ -0,0 +1,421 @@
+/*
+* Copyright (c) 2014-2016 the Civetweb developers
+* Copyright (c) 2014 Jordan Shelley
+* https://github.com/jshelley
+* License http://opensource.org/licenses/mit-license.php MIT License
+*/
+
+/* This example is superseeded by other examples, and no longer 
+ * actively maintained.
+ * See examples/embedded_c for an up to date example.
+ */
+
+// Simple example program on how to use websocket client embedded C interface.
+#ifdef _WIN32
+#include <windows.h>
+#define sleep(x) Sleep(1000 * (x))
+#else
+#include <unistd.h>
+#endif
+
+#include <assert.h>
+#include <string.h>
+#include "civetweb.h"
+
+#define DOCUMENT_ROOT "."
+#define PORT "8888"
+#define SSL_CERT "./ssl/server.pem"
+
+const char *websocket_welcome_msg = "websocket welcome\n";
+const size_t websocket_welcome_msg_len = 18 /* strlen(websocket_welcome_msg) */;
+const char *websocket_acknowledge_msg = "websocket msg ok\n";
+const size_t websocket_acknowledge_msg_len =
+    17 /* strlen(websocket_acknowledge_msg) */;
+const char *websocket_goodbye_msg = "websocket bye\n";
+const size_t websocket_goodbye_msg_len = 14 /* strlen(websocket_goodbye_msg) */;
+
+
+/*************************************************************************************/
+/* WEBSOCKET SERVER */
+/*************************************************************************************/
+#if defined(MG_LEGACY_INTERFACE)
+int
+websock_server_connect(const struct mg_connection *conn)
+#else
+int
+websocket_server_connect(const struct mg_connection *conn, void *_ignored)
+#endif
+{
+	printf("Server: Websocket connected\n");
+	return 0; /* return 0 to accept every connection */
+}
+
+
+#if defined(MG_LEGACY_INTERFACE)
+void
+websocket_server_ready(struct mg_connection *conn)
+#else
+void
+websocket_server_ready(struct mg_connection *conn, void *_ignored)
+#endif
+{
+	printf("Server: Websocket ready\n");
+
+	/* Send websocket welcome message */
+	mg_lock_connection(conn);
+	mg_websocket_write(conn,
+	                   WEBSOCKET_OPCODE_TEXT,
+	                   websocket_welcome_msg,
+	                   websocket_welcome_msg_len);
+	mg_unlock_connection(conn);
+}
+
+
+#if defined(MG_LEGACY_INTERFACE)
+int
+websocket_server_data(struct mg_connection *conn,
+                      int bits,
+                      char *data,
+                      size_t data_len)
+#else
+int
+websocket_server_data(struct mg_connection *conn,
+                      int bits,
+                      char *data,
+                      size_t data_len,
+                      void *_ignored)
+#endif
+{
+	printf("Server: Got %lu bytes from the client\n", (unsigned long)data_len);
+	printf("Server received data from client: ");
+	fwrite(data, 1, data_len, stdout);
+	printf("\n");
+
+	if (data_len < 3 || 0 != memcmp(data, "bye", 3)) {
+		/* Send websocket acknowledge message */
+		mg_lock_connection(conn);
+		mg_websocket_write(conn,
+		                   WEBSOCKET_OPCODE_TEXT,
+		                   websocket_acknowledge_msg,
+		                   websocket_acknowledge_msg_len);
+		mg_unlock_connection(conn);
+	} else {
+		/* Send websocket acknowledge message */
+		mg_lock_connection(conn);
+		mg_websocket_write(conn,
+		                   WEBSOCKET_OPCODE_TEXT,
+		                   websocket_goodbye_msg,
+		                   websocket_goodbye_msg_len);
+		mg_unlock_connection(conn);
+	}
+
+	return 1; /* return 1 to keep the connetion open */
+}
+
+
+#if defined(MG_LEGACY_INTERFACE)
+void
+websocket_server_connection_close(const struct mg_connection *conn)
+#else
+void
+websocket_server_connection_close(const struct mg_connection *conn,
+                                  void *_ignored)
+#endif
+{
+	printf("Server: Close connection\n");
+
+	/* Can not send a websocket goodbye message here - the connection is already
+	 * closed */
+}
+
+
+struct mg_context *
+start_websocket_server()
+{
+	const char *options[] = {"document_root",
+	                         DOCUMENT_ROOT,
+	                         "ssl_certificate",
+	                         SSL_CERT,
+	                         "listening_ports",
+	                         PORT,
+	                         "request_timeout_ms",
+	                         "5000",
+	                         0};
+	struct mg_callbacks callbacks;
+	struct mg_context *ctx;
+
+	memset(&callbacks, 0, sizeof(callbacks));
+
+#if defined(MG_LEGACY_INTERFACE)
+	/* Obsolete: */
+	callbacks.websocket_connect = websock_server_connect;
+	callbacks.websocket_ready = websocket_server_ready;
+	callbacks.websocket_data = websocket_server_data;
+	callbacks.connection_close = websocket_server_connection_close;
+
+	ctx = mg_start(&callbacks, 0, options);
+#else
+	/* New interface: */
+	ctx = mg_start(&callbacks, 0, options);
+
+	mg_set_websocket_handler(ctx,
+	                         "/websocket",
+	                         websocket_server_connect,
+	                         websocket_server_ready,
+	                         websocket_server_data,
+	                         websocket_server_connection_close,
+	                         NULL);
+#endif
+
+	return ctx;
+}
+
+
+/*************************************************************************************/
+/* WEBSOCKET CLIENT */
+/*************************************************************************************/
+struct tclient_data {
+	void *data;
+	size_t len;
+	int closed;
+};
+
+static int
+websocket_client_data_handler(struct mg_connection *conn,
+                              int flags,
+                              char *data,
+                              size_t data_len,
+                              void *user_data)
+{
+	struct mg_context *ctx = mg_get_context(conn);
+	struct tclient_data *pclient_data =
+	    (struct tclient_data *)mg_get_user_data(ctx);
+
+	printf("Client received data from server: ");
+	fwrite(data, 1, data_len, stdout);
+	printf("\n");
+
+	pclient_data->data = malloc(data_len);
+	assert(pclient_data->data != NULL);
+	memcpy(pclient_data->data, data, data_len);
+	pclient_data->len = data_len;
+
+	return 1;
+}
+
+static void
+websocket_client_close_handler(const struct mg_connection *conn,
+                               void *user_data)
+{
+	struct mg_context *ctx = mg_get_context(conn);
+	struct tclient_data *pclient_data =
+	    (struct tclient_data *)mg_get_user_data(ctx);
+
+	printf("Client: Close handler\n");
+	pclient_data->closed++;
+}
+
+
+int
+main(int argc, char *argv[])
+{
+	struct mg_context *ctx = NULL;
+	struct tclient_data client1_data = {NULL, 0, 0};
+	struct tclient_data client2_data = {NULL, 0, 0};
+	struct tclient_data client3_data = {NULL, 0, 0};
+	struct mg_connection *newconn1 = NULL;
+	struct mg_connection *newconn2 = NULL;
+	struct mg_connection *newconn3 = NULL;
+	char ebuf[100] = {0};
+
+	assert(websocket_welcome_msg_len == strlen(websocket_welcome_msg));
+
+	/* First set up a websocket server */
+	ctx = start_websocket_server();
+	assert(ctx != NULL);
+	printf("Server init\n\n");
+
+	/* Then connect a first client */
+	newconn1 = mg_connect_websocket_client("localhost",
+	                                       atoi(PORT),
+	                                       0,
+	                                       ebuf,
+	                                       sizeof(ebuf),
+	                                       "/websocket",
+	                                       NULL,
+	                                       websocket_client_data_handler,
+	                                       websocket_client_close_handler,
+	                                       &client1_data);
+
+	if (newconn1 == NULL) {
+		printf("Error: %s", ebuf);
+		return 1;
+	}
+
+	sleep(1); /* Should get the websocket welcome message */
+	assert(client1_data.closed == 0);
+	assert(client2_data.closed == 0);
+	assert(client2_data.data == NULL);
+	assert(client2_data.len == 0);
+	assert(client1_data.data != NULL);
+	assert(client1_data.len == websocket_welcome_msg_len);
+	assert(!memcmp(client1_data.data,
+	               websocket_welcome_msg,
+	               websocket_welcome_msg_len));
+	free(client1_data.data);
+	client1_data.data = NULL;
+	client1_data.len = 0;
+
+	mg_websocket_client_write(newconn1, WEBSOCKET_OPCODE_TEXT, "data1", 5);
+
+	sleep(1); /* Should get the acknowledge message */
+	assert(client1_data.closed == 0);
+	assert(client2_data.closed == 0);
+	assert(client2_data.data == NULL);
+	assert(client2_data.len == 0);
+	assert(client1_data.data != NULL);
+	assert(client1_data.len == websocket_acknowledge_msg_len);
+	assert(!memcmp(client1_data.data,
+	               websocket_acknowledge_msg,
+	               websocket_acknowledge_msg_len));
+	free(client1_data.data);
+	client1_data.data = NULL;
+	client1_data.len = 0;
+
+	/* Now connect a second client */
+	newconn2 = mg_connect_websocket_client("localhost",
+	                                       atoi(PORT),
+	                                       0,
+	                                       ebuf,
+	                                       sizeof(ebuf),
+	                                       "/websocket",
+	                                       NULL,
+	                                       websocket_client_data_handler,
+	                                       websocket_client_close_handler,
+	                                       &client2_data);
+
+	if (newconn2 == NULL) {
+		printf("Error: %s", ebuf);
+		return 1;
+	}
+
+	sleep(1); /* Client 2 should get the websocket welcome message */
+	assert(client1_data.closed == 0);
+	assert(client2_data.closed == 0);
+	assert(client1_data.data == NULL);
+	assert(client1_data.len == 0);
+	assert(client2_data.data != NULL);
+	assert(client2_data.len == websocket_welcome_msg_len);
+	assert(!memcmp(client2_data.data,
+	               websocket_welcome_msg,
+	               websocket_welcome_msg_len));
+	free(client2_data.data);
+	client2_data.data = NULL;
+	client2_data.len = 0;
+
+	mg_websocket_client_write(newconn1, WEBSOCKET_OPCODE_TEXT, "data2", 5);
+
+	sleep(1); /* Should get the acknowledge message */
+	assert(client1_data.closed == 0);
+	assert(client2_data.closed == 0);
+	assert(client2_data.data == NULL);
+	assert(client2_data.len == 0);
+	assert(client1_data.data != NULL);
+	assert(client1_data.len == websocket_acknowledge_msg_len);
+	assert(!memcmp(client1_data.data,
+	               websocket_acknowledge_msg,
+	               websocket_acknowledge_msg_len));
+	free(client1_data.data);
+	client1_data.data = NULL;
+	client1_data.len = 0;
+
+	mg_websocket_client_write(newconn1, WEBSOCKET_OPCODE_TEXT, "bye", 3);
+
+	sleep(1); /* Should get the goodbye message */
+	assert(client1_data.closed == 0);
+	assert(client2_data.closed == 0);
+	assert(client2_data.data == NULL);
+	assert(client2_data.len == 0);
+	assert(client1_data.data != NULL);
+	assert(client1_data.len == websocket_goodbye_msg_len);
+	assert(!memcmp(client1_data.data,
+	               websocket_goodbye_msg,
+	               websocket_goodbye_msg_len));
+	free(client1_data.data);
+	client1_data.data = NULL;
+	client1_data.len = 0;
+
+	mg_close_connection(newconn1);
+
+	sleep(1); /* Won't get any message */
+	assert(client1_data.closed == 1);
+	assert(client2_data.closed == 0);
+	assert(client1_data.data == NULL);
+	assert(client1_data.len == 0);
+	assert(client2_data.data == NULL);
+	assert(client2_data.len == 0);
+
+	mg_websocket_client_write(newconn2, WEBSOCKET_OPCODE_TEXT, "bye", 3);
+
+	sleep(1); /* Should get the goodbye message */
+	assert(client1_data.closed == 1);
+	assert(client2_data.closed == 0);
+	assert(client1_data.data == NULL);
+	assert(client1_data.len == 0);
+	assert(client2_data.data != NULL);
+	assert(client2_data.len == websocket_goodbye_msg_len);
+	assert(!memcmp(client2_data.data,
+	               websocket_goodbye_msg,
+	               websocket_goodbye_msg_len));
+	free(client2_data.data);
+	client2_data.data = NULL;
+	client2_data.len = 0;
+
+	mg_close_connection(newconn2);
+
+	sleep(1); /* Won't get any message */
+	assert(client1_data.closed == 1);
+	assert(client2_data.closed == 1);
+	assert(client1_data.data == NULL);
+	assert(client1_data.len == 0);
+	assert(client2_data.data == NULL);
+	assert(client2_data.len == 0);
+
+	/* Connect client 3 */
+	newconn3 = mg_connect_websocket_client("localhost",
+	                                       atoi(PORT),
+	                                       0,
+	                                       ebuf,
+	                                       sizeof(ebuf),
+	                                       "/websocket",
+	                                       NULL,
+	                                       websocket_client_data_handler,
+	                                       websocket_client_close_handler,
+	                                       &client3_data);
+
+	sleep(1); /* Client 3 should get the websocket welcome message */
+	assert(client1_data.closed == 1);
+	assert(client2_data.closed == 1);
+	assert(client3_data.closed == 0);
+	assert(client1_data.data == NULL);
+	assert(client1_data.len == 0);
+	assert(client2_data.data == NULL);
+	assert(client2_data.len == 0);
+	assert(client3_data.data != NULL);
+	assert(client3_data.len == websocket_welcome_msg_len);
+	assert(!memcmp(client3_data.data,
+	               websocket_welcome_msg,
+	               websocket_welcome_msg_len));
+	free(client3_data.data);
+	client3_data.data = NULL;
+	client3_data.len = 0;
+
+	mg_stop(ctx);
+	printf("Server shutdown\n");
+
+	sleep(10);
+
+	assert(client3_data.closed == 1);
+
+	return 0;
+}

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/examples/_obsolete/ws_server/docroot/index.html
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/examples/_obsolete/ws_server/docroot/index.html b/thirdparty/civetweb-1.9.1/examples/_obsolete/ws_server/docroot/index.html
new file mode 100644
index 0000000..f1d1af3
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/examples/_obsolete/ws_server/docroot/index.html
@@ -0,0 +1,316 @@
+<!DOCTYPE html>
+<html>
+
+<head>
+	<meta charset='UTF-8'>
+	
+	<title>Websocket Meters</title>
+    <!-- 
+        Version 0.1 Contributed by William Greathouse    9-Sep-2013
+        Simple demo of WebSocket connection use. Not a great example of web coding,
+        but it is functional.
+
+        The meter displays are adapted from CSS-TRICKS Progress Bars by Chris Coyier 
+        at http://css-tricks.com/css3-progress-bars/
+    -->
+	<style>
+        body {
+            background: #222;
+        }
+        h1 {
+            color: white;
+            text-align: center;
+        }
+        button {
+            width: 225px;
+            height: 30px;
+            margin: auto 10px;
+            background-color: #ccc;
+            -moz-border-radius: 5px;
+            -webkit-border-radius: 5px;
+            border-radius:6px;
+            color: blue;
+            font-size: 20px;
+        }
+        button:hover {
+            background-color: #888;
+        }
+        button:hover:disabled {
+            background-color: #ccc;
+        }
+        button:disabled {
+            color: lightgray;
+        }
+
+        .button_container {
+            width:550px;
+            display:block;
+            margin-left:auto;
+            margin-right:auto;
+        }
+
+		.meter { 
+			height: 20px;  /* Can be anything */
+			position: relative;
+			background: #555;
+			-moz-border-radius: 25px;
+			-webkit-border-radius: 25px;
+			border-radius: 25px;
+			padding: 10px;
+			-webkit-box-shadow: inset 0 -1px 1px rgba(255,255,255,0.3);
+			-moz-box-shadow   : inset 0 -1px 1px rgba(255,255,255,0.3);
+			box-shadow        : inset 0 -1px 1px rgba(255,255,255,0.3);
+		}
+		.meter > span {
+			display: block;
+			height: 100%;
+			   -webkit-border-top-right-radius: 20px;
+			-webkit-border-bottom-right-radius: 20px;
+			       -moz-border-radius-topright: 20px;
+			    -moz-border-radius-bottomright: 20px;
+			           border-top-right-radius: 20px;
+			        border-bottom-right-radius: 20px;
+			    -webkit-border-top-left-radius: 20px;
+			 -webkit-border-bottom-left-radius: 20px;
+			        -moz-border-radius-topleft: 20px;
+			     -moz-border-radius-bottomleft: 20px;
+			            border-top-left-radius: 20px;
+			         border-bottom-left-radius: 20px;
+			background-color: rgb(43,194,83);
+			background-image: -webkit-gradient(
+			  linear,
+			  left bottom,
+			  left top,
+			  color-stop(0, rgb(43,194,83)),
+			  color-stop(1, rgb(84,240,84))
+			 );
+			background-image: -moz-linear-gradient(
+			  center bottom,
+			  rgb(43,194,83) 37%,
+			  rgb(84,240,84) 69%
+			 );
+			-webkit-box-shadow: 
+			  inset 0 2px 9px  rgba(255,255,255,0.3),
+			  inset 0 -2px 6px rgba(0,0,0,0.4);
+			-moz-box-shadow: 
+			  inset 0 2px 9px  rgba(255,255,255,0.3),
+			  inset 0 -2px 6px rgba(0,0,0,0.4);
+			box-shadow: 
+			  inset 0 2px 9px  rgba(255,255,255,0.3),
+			  inset 0 -2px 6px rgba(0,0,0,0.4);
+			position: relative;
+			overflow: hidden;
+		}
+		.meter > span:after, .animate > span > span {
+			content: "";
+			position: absolute;
+			top: 0; left: 0; bottom: 0; right: 0;
+			background-image: 
+			   -webkit-gradient(linear, 0 0, 100% 100%, 
+			      color-stop(.25, rgba(255, 255, 255, .2)), 
+			      color-stop(.25, transparent), color-stop(.5, transparent), 
+			      color-stop(.5, rgba(255, 255, 255, .2)), 
+			      color-stop(.75, rgba(255, 255, 255, .2)), 
+			      color-stop(.75, transparent), to(transparent)
+			   );
+			background-image: 
+				-moz-linear-gradient(
+				  -45deg, 
+			      rgba(255, 255, 255, .2) 25%, 
+			      transparent 25%, 
+			      transparent 50%, 
+			      rgba(255, 255, 255, .2) 50%, 
+			      rgba(255, 255, 255, .2) 75%, 
+			      transparent 75%, 
+			      transparent
+			   );
+			z-index: 1;
+			-webkit-background-size: 50px 50px;
+			-moz-background-size: 50px 50px;
+			-webkit-animation: move 2s linear infinite;
+			   -webkit-border-top-right-radius: 20px;
+			-webkit-border-bottom-right-radius: 20px;
+			       -moz-border-radius-topright: 20px;
+			    -moz-border-radius-bottomright: 20px;
+			           border-top-right-radius: 20px;
+			        border-bottom-right-radius: 20px;
+			    -webkit-border-top-left-radius: 20px;
+			 -webkit-border-bottom-left-radius: 20px;
+			        -moz-border-radius-topleft: 20px;
+			     -moz-border-radius-bottomleft: 20px;
+			            border-top-left-radius: 20px;
+			         border-bottom-left-radius: 20px;
+			overflow: hidden;
+		}
+		
+		.animate > span:after {
+			display: none;
+		}
+		
+		@-webkit-keyframes move {
+		    0% {
+		       background-position: 0 0;
+		    }
+		    100% {
+		       background-position: 50px 50px;
+		    }
+		}
+		
+		.orange > span {
+			background-color: #f1a165;
+			background-image: -moz-linear-gradient(top, #f1a165, #f36d0a);
+			background-image: -webkit-gradient(linear,left top,left bottom,color-stop(0, #f1a165),color-stop(1, #f36d0a));
+			background-image: -webkit-linear-gradient(#f1a165, #f36d0a); 
+		}
+		
+		.red > span {
+			background-color: #f0a3a3;
+			background-image: -moz-linear-gradient(top, #f0a3a3, #f42323);
+			background-image: -webkit-gradient(linear,left top,left bottom,color-stop(0, #f0a3a3),color-stop(1, #f42323));
+			background-image: -webkit-linear-gradient(#f0a3a3, #f42323);
+		}
+		
+		.nostripes > span > span, .nostripes > span:after {
+			-webkit-animation: none;
+			background-image: none;
+		}
+
+        #output {
+            background-color: #ccc;
+            height: 240px;
+            overflow-y: auto;
+        }
+
+	</style>
+</head>
+
+<body>
+	<div id="page_wrap">
+		
+	  <h1>Meter Updates via WebSocket</h1>
+	  
+	  <p/>
+
+		<div class="meter">
+			<span id="meter1" style="width: 25%"></span>
+		</div>
+
+        <p/>
+		
+		<div class="meter orange nostripes">
+			<span id="meter2" style="width: 33.3%"></span>
+		</div>
+
+        <p/>
+		
+		<div class="meter red">
+			<span id="meter3" style="width: 80%"></span>
+		</div>
+
+        <p/>
+
+	</div>
+    <div class="button_container">
+        <div>
+            <button id="connection" onclick="toggleConnection(this)">WebSocket Connect</button>
+            <button id="update" disabled onclick="toggleUpdate(this)">Disable Update</button>
+        </div>
+    </div>
+    <p/>
+    <div id="output"></div>
+	
+</body>
+
+<script language="javascript" type="text/javascript">
+    var connection; // websocket connection
+
+    function writeToScreen (message) {
+        var div = document.createElement('div');
+        var output = document.getElementById('output');
+        div.innerHTML = message;
+        output.appendChild(div);
+        output.scrollTop = output.scrollHeight;
+    }
+
+    function ws_connect() {
+        // check for websocket support
+        // for Internet Explorer < 10 there are options for websocket support that
+        // could be integrated into production code, but for now, we are expecting 
+        // browser support to be present for this demo
+        if ('WebSocket' in window) {
+
+            writeToScreen('Connecting');
+            connection = new WebSocket('ws://' + window.location.host + '/meters');
+            connection.onopen = function(ev) {
+                document.getElementById("connection").innerHTML = "WebSocket Disconnect";
+                document.getElementById("update").disabled=false;
+                document.getElementById("update").innerHTML = "Disable Update";
+                writeToScreen('CONNECTED');
+                var message = 'update on';
+                writeToScreen('SENT: ' + message);
+                connection.send(message);
+            };
+
+            connection.onclose = function(ev) {
+                document.getElementById("update").disabled=true;
+                document.getElementById("update").innerHTML = "Enable Update";
+                document.getElementById("connection").innerHTML = "WebSocket Connect";
+                writeToScreen('DISCONNECTED');
+            };
+
+            connection.onmessage = function(ev) {
+                if (ev.data.substr(0,5) == "meter")
+                {
+                    var target = ev.data.split(":")[0];
+                    var meter = document.getElementById(target);
+                    var data = ev.data.split(":")[1].split(",");
+                    var percent = (data[0]*100)/data[1];
+                    meter.style.width = percent+"%";
+                }
+                else
+                    writeToScreen('RECEIVED: ' + ev.data);
+            };
+
+            connection.onerror = function(ev) {
+                alert("WebSocket error");
+            };
+
+        } else {
+            alert("WebSocket is not available!!!\n" +
+                  "Demo will not function.");
+        }
+    }
+
+    // user connect/disconnect
+    function toggleConnection(el) {
+        var tag=el.innerHTML;
+        if (tag == "WebSocket Connect")
+        {
+            ws_connect();
+        }
+        else
+        {
+            connection.close();
+        }
+    }
+
+    // user turn updates on/off
+    function toggleUpdate(el) {
+        var tag=el.innerHTML;
+        var message;
+        if (tag == "Enable Update")
+        {
+            message = 'update on';
+            el.innerHTML = "Disable Update";
+        }
+        else
+        {
+            message = 'update off';
+            el.innerHTML = "Enable Update";
+        }
+        writeToScreen('SENT: ' + message);
+        connection.send(message);
+    }
+</script>
+
+</html>

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/examples/_obsolete/ws_server/ws_server.c
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/examples/_obsolete/ws_server/ws_server.c b/thirdparty/civetweb-1.9.1/examples/_obsolete/ws_server/ws_server.c
new file mode 100644
index 0000000..575a26a
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/examples/_obsolete/ws_server/ws_server.c
@@ -0,0 +1,271 @@
+// Copyright (c) 2004-2012 Sergey Lyubka
+// This file is a part of civetweb project, http://github.com/bel2125/civetweb
+//
+// v 0.1 Contributed by William Greathouse    9-Sep-2013
+
+#include <stdio.h>
+#include <string.h>
+#include <time.h>
+#include <unistd.h>
+
+#include "civetweb.h"
+
+// simple structure for keeping track of websocket connection
+struct ws_connection {
+    struct mg_connection    *conn;
+    int     update;
+    int     closing;
+};
+
+// time base and structure periodic updates to client for demo
+#define BASETIME 100000 /* 0.1 seconds */
+struct progress {
+    int     limit;
+    int     increment;
+    int     period;
+    int     value;
+};
+
+// up to 16 independent client connections
+#define CONNECTIONS 16
+static struct ws_connection ws_conn[CONNECTIONS];
+
+
+// ws_server_thread()
+// Simple demo server thread. Sends periodic updates to connected clients
+static void *ws_server_thread(void *parm)
+{
+    int wsd = (long)parm;
+    struct mg_connection    *conn = ws_conn[wsd].conn;
+    int timer = 0;
+    char tstr[32];
+    int i;
+    struct progress meter[] = {
+        /* first meter 0 to 1000, by 5 every 0.1 second */
+        { 1000, 5, 1, 0 },
+        /* second meter 0 to 500, by 10 every 0.5 second */
+        { 500, 10, 5, 0 },
+        /* third meter 0 to 100, by 10 every 1.0 second */
+        { 100, 10, 10, 0},
+        /* end of list */
+        { 0, 0, 0, 0}
+    };
+
+    fprintf(stderr, "ws_server_thread %d\n", wsd);
+
+    /* Send initial meter updates */
+    for (i=0; meter[i].period != 0; i++) {
+        if (meter[i].value >= meter[i].limit)
+            meter[i].value = 0;
+        if (meter[i].value >= meter[i].limit)
+            meter[i].value = meter[i].limit;
+        sprintf(tstr, "meter%d:%d,%d", i+1,
+                meter[i].value, meter[i].limit);
+        mg_websocket_write(conn, WEBSOCKET_OPCODE_TEXT, tstr, strlen(tstr));
+    }
+
+    /* While the connection is open, send periodic updates */
+    while(!ws_conn[wsd].closing) {
+        usleep(100000); /* 0.1 second */
+        timer++;
+
+        /* Send meter updates */
+        if (ws_conn[wsd].update) {
+            for (i=0; meter[i].period != 0; i++) {
+                if (timer%meter[i].period == 0) {
+                    if (meter[i].value >= meter[i].limit)
+                        meter[i].value = 0;
+                    else
+                        meter[i].value += meter[i].increment;
+                    if (meter[i].value >= meter[i].limit)
+                        meter[i].value = meter[i].limit;
+                    // if we are closing, server should not send new data
+                    if (!ws_conn[wsd].closing) {
+                        sprintf(tstr, "meter%d:%d,%d", i+1,
+                                meter[i].value, meter[i].limit);
+                        mg_websocket_write(conn, WEBSOCKET_OPCODE_TEXT, tstr, strlen(tstr));
+                    }
+                }
+            }
+        }
+
+        /* Send periodic PING to assure websocket remains connected, except if we are closing */
+        if (timer%100 == 0 && !ws_conn[wsd].closing)
+            mg_websocket_write(conn, WEBSOCKET_OPCODE_PING, NULL, 0);
+    }
+
+    fprintf(stderr, "ws_server_thread %d exiting\n", wsd);
+
+    // reset connection information to allow reuse by new client
+    ws_conn[wsd].conn = NULL;
+    ws_conn[wsd].update = 0;
+    ws_conn[wsd].closing = 2;
+
+    return NULL;
+}
+
+// websocket_connect_handler()
+// On new client connection, find next available server connection and store
+// new connection information. If no more server connections are available
+// tell civetweb to not accept the client request.
+static int websocket_connect_handler(const struct mg_connection *conn)
+{
+    int i;
+
+    fprintf(stderr, "connect handler\n");
+
+    for(i=0; i < CONNECTIONS; ++i) {
+        if (ws_conn[i].conn == NULL) {
+            fprintf(stderr, "...prep for server %d\n", i);
+            ws_conn[i].conn = (struct mg_connection *)conn;
+            ws_conn[i].closing = 0;
+            ws_conn[i].update = 0;
+            break;
+        }
+    }
+    if (i >= CONNECTIONS) {
+        fprintf(stderr, "Refused connection: Max connections exceeded\n");
+        return 1;
+    }
+
+    return 0;
+}
+
+// websocket_ready_handler()
+// Once websocket negotiation is complete, start a server for the connection
+static void websocket_ready_handler(struct mg_connection *conn)
+{
+    int i;
+
+    fprintf(stderr, "ready handler\n");
+
+    for(i=0; i < CONNECTIONS; ++i) {
+        if (ws_conn[i].conn == conn) {
+            fprintf(stderr, "...start server %d\n", i);
+            mg_start_thread(ws_server_thread, (void *)(long)i);
+            break;
+        }
+    }
+}
+
+// websocket_close_handler()
+// When websocket is closed, tell the associated server to shut down
+static void websocket_close_handler(struct mg_connection *conn)
+{
+    int i;
+
+    //fprintf(stderr, "close handler\n");   /* called for every close, not just websockets */
+
+    for(i=0; i < CONNECTIONS; ++i) {
+        if (ws_conn[i].conn == conn) {
+            fprintf(stderr, "...close server %d\n", i);
+            ws_conn[i].closing = 1;
+        }
+    }
+}
+
+// Arguments:
+//   flags: first byte of websocket frame, see websocket RFC,
+//          http://tools.ietf.org/html/rfc6455, section 5.2
+//   data, data_len: payload data. Mask, if any, is already applied.
+static int websocket_data_handler(struct mg_connection *conn, int flags,
+                                  char *data, size_t data_len)
+{
+    int i;
+    int wsd;
+
+    for(i=0; i < CONNECTIONS; ++i) {
+        if (ws_conn[i].conn == conn) {
+            wsd = i;
+            break;
+        }
+    }
+    if (i >= CONNECTIONS) {
+        fprintf(stderr, "Received websocket data from unknown connection\n");
+        return 1;
+    }
+
+    if (flags & 0x80) {
+        flags &= 0x7f;
+        switch (flags) {
+        case WEBSOCKET_OPCODE_CONTINUATION:
+            fprintf(stderr, "CONTINUATION...\n");
+            break;
+        case WEBSOCKET_OPCODE_TEXT:
+            fprintf(stderr, "TEXT: %-.*s\n", (int)data_len, data);
+            /*** interpret data as commands here ***/
+            if (strncmp("update on", data, data_len)== 0) {
+                /* turn on updates */
+                ws_conn[wsd].update = 1;
+                /* echo back */
+                mg_websocket_write(conn, WEBSOCKET_OPCODE_TEXT, data, data_len);
+            } else if (strncmp("update off", data, data_len)== 0) {
+                /* turn off updates */
+                ws_conn[wsd].update = 0;
+                /* echo back */
+                mg_websocket_write(conn, WEBSOCKET_OPCODE_TEXT, data, data_len);
+            }
+            break;
+        case WEBSOCKET_OPCODE_BINARY:
+            fprintf(stderr, "BINARY...\n");
+            break;
+        case WEBSOCKET_OPCODE_CONNECTION_CLOSE:
+            fprintf(stderr, "CLOSE...\n");
+            /* If client initiated close, respond with close message in acknowlegement */
+            if (!ws_conn[wsd].closing) {
+                mg_websocket_write(conn, WEBSOCKET_OPCODE_CONNECTION_CLOSE, data, data_len);
+                ws_conn[wsd].closing = 1; /* we should not send addional messages when close requested/acknowledged */
+            }
+            return 0; /* time to close the connection */
+            break;
+        case WEBSOCKET_OPCODE_PING:
+            /* client sent PING, respond with PONG */
+            mg_websocket_write(conn, WEBSOCKET_OPCODE_PONG, data, data_len);
+            break;
+        case WEBSOCKET_OPCODE_PONG:
+            /* received PONG to our PING, no action */
+            break;
+        default:
+            fprintf(stderr, "Unknown flags: %02x\n", flags);
+            break;
+        }
+    }
+
+    return 1;   /* keep connection open */
+}
+
+
+int main(void)
+{
+    char server_name[40];
+    struct mg_context *ctx;
+    struct mg_callbacks callbacks;
+    const char *options[] = {
+        "listening_ports", "8080",
+        "document_root", "docroot",
+        NULL
+    };
+
+    /* get simple greeting for the web server */
+    snprintf(server_name, sizeof(server_name),
+             "Civetweb websocket server v. %s",
+             mg_version());
+
+    memset(&callbacks, 0, sizeof(callbacks));
+    callbacks.websocket_connect = websocket_connect_handler;
+    callbacks.websocket_ready = websocket_ready_handler;
+    callbacks.websocket_data = websocket_data_handler;
+    callbacks.connection_close = websocket_close_handler;
+
+    ctx = mg_start(&callbacks, NULL, options);
+
+    /* show the greeting and some basic information */
+    printf("%s started on port(s) %s with web root [%s]\n",
+           server_name, mg_get_option(ctx, "listening_ports"),
+           mg_get_option(ctx, "document_root"));
+
+    getchar();  // Wait until user hits "enter"
+    mg_stop(ctx);
+
+    return 0;
+}

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/examples/embedded_c/embedded_c.c
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/examples/embedded_c/embedded_c.c b/thirdparty/civetweb-1.9.1/examples/embedded_c/embedded_c.c
new file mode 100644
index 0000000..5dc91f0
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/examples/embedded_c/embedded_c.c
@@ -0,0 +1,922 @@
+/*
+* Copyright (c) 2013-2017 the CivetWeb developers
+* Copyright (c) 2013 No Face Press, LLC
+* License http://opensource.org/licenses/mit-license.php MIT License
+*/
+
+/* Simple example program on how to use CivetWeb embedded into a C program. */
+#ifdef _WIN32
+#include <windows.h>
+#else
+#include <unistd.h>
+#endif
+
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+
+#include "civetweb.h"
+
+
+#define DOCUMENT_ROOT "."
+#ifdef NO_SSL
+#ifdef USE_IPV6
+#define PORT "[::]:8888"
+#else
+#define PORT "8888"
+#endif
+#else
+#ifdef USE_IPV6
+#define PORT "[::]:8888r,[::]:8843s,8884"
+#else
+#define PORT "8888r,8843s"
+#endif
+#endif
+#define EXAMPLE_URI "/example"
+#define EXIT_URI "/exit"
+int exitNow = 0;
+
+
+int
+ExampleHandler(struct mg_connection *conn, void *cbdata)
+{
+	mg_printf(conn,
+	          "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nConnection: "
+	          "close\r\n\r\n");
+	mg_printf(conn, "<html><body>");
+	mg_printf(conn, "<h2>This is an example text from a C handler</h2>");
+	mg_printf(
+	    conn,
+	    "<p>To see a page from the A handler <a href=\"A\">click A</a></p>");
+	mg_printf(conn,
+	          "<p>To see a page from the A handler <a href=\"A/A\">click "
+	          "A/A</a></p>");
+	mg_printf(conn,
+	          "<p>To see a page from the A/B handler <a "
+	          "href=\"A/B\">click A/B</a></p>");
+	mg_printf(conn,
+	          "<p>To see a page from the B handler (0) <a "
+	          "href=\"B\">click B</a></p>");
+	mg_printf(conn,
+	          "<p>To see a page from the B handler (1) <a "
+	          "href=\"B/A\">click B/A</a></p>");
+	mg_printf(conn,
+	          "<p>To see a page from the B handler (2) <a "
+	          "href=\"B/B\">click B/B</a></p>");
+	mg_printf(conn,
+	          "<p>To see a page from the *.foo handler <a "
+	          "href=\"xy.foo\">click xy.foo</a></p>");
+	mg_printf(conn,
+	          "<p>To see a page from the close handler <a "
+	          "href=\"close\">click close</a></p>");
+	mg_printf(conn,
+	          "<p>To see a page from the FileHandler handler <a "
+	          "href=\"form\">click form</a> (the starting point of the "
+	          "<b>form</b> test)</p>");
+	mg_printf(conn,
+	          "<p>To see a page from the CookieHandler handler <a "
+	          "href=\"cookie\">click cookie</a></p>");
+	mg_printf(conn,
+	          "<p>To see an example for parsing files on the fly <a "
+	          "href=\"on_the_fly_form\">click form</a> (form for "
+	          "uploading files)</p>");
+
+#ifdef USE_WEBSOCKET
+	mg_printf(conn,
+	          "<p>To test websocket handler <a href=\"/websocket\">click "
+	          "websocket</a></p>");
+#endif
+	mg_printf(conn, "<p>To exit <a href=\"%s\">click exit</a></p>", EXIT_URI);
+	mg_printf(conn, "</body></html>\n");
+	return 1;
+}
+
+
+int
+ExitHandler(struct mg_connection *conn, void *cbdata)
+{
+	mg_printf(conn,
+	          "HTTP/1.1 200 OK\r\nContent-Type: "
+	          "text/plain\r\nConnection: close\r\n\r\n");
+	mg_printf(conn, "Server will shut down.\n");
+	mg_printf(conn, "Bye!\n");
+	exitNow = 1;
+	return 1;
+}
+
+
+int
+AHandler(struct mg_connection *conn, void *cbdata)
+{
+	mg_printf(conn,
+	          "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nConnection: "
+	          "close\r\n\r\n");
+	mg_printf(conn, "<html><body>");
+	mg_printf(conn, "<h2>This is the A handler!!!</h2>");
+	mg_printf(conn, "</body></html>\n");
+	return 1;
+}
+
+
+int
+ABHandler(struct mg_connection *conn, void *cbdata)
+{
+	mg_printf(conn,
+	          "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nConnection: "
+	          "close\r\n\r\n");
+	mg_printf(conn, "<html><body>");
+	mg_printf(conn, "<h2>This is the AB handler!!!</h2>");
+	mg_printf(conn, "</body></html>\n");
+	return 1;
+}
+
+
+int
+BXHandler(struct mg_connection *conn, void *cbdata)
+{
+	/* Handler may access the request info using mg_get_request_info */
+	const struct mg_request_info *req_info = mg_get_request_info(conn);
+
+	mg_printf(conn,
+	          "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nConnection: "
+	          "close\r\n\r\n");
+	mg_printf(conn, "<html><body>");
+	mg_printf(conn, "<h2>This is the BX handler %p!!!</h2>", cbdata);
+	mg_printf(conn, "<p>The actual uri is %s</p>", req_info->uri);
+	mg_printf(conn, "</body></html>\n");
+	return 1;
+}
+
+
+int
+FooHandler(struct mg_connection *conn, void *cbdata)
+{
+	/* Handler may access the request info using mg_get_request_info */
+	const struct mg_request_info *req_info = mg_get_request_info(conn);
+
+	mg_printf(conn,
+	          "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nConnection: "
+	          "close\r\n\r\n");
+	mg_printf(conn, "<html><body>");
+	mg_printf(conn, "<h2>This is the Foo handler!!!</h2>");
+	mg_printf(conn,
+	          "<p>The request was:<br><pre>%s %s HTTP/%s</pre></p>",
+	          req_info->request_method,
+	          req_info->uri,
+	          req_info->http_version);
+	mg_printf(conn, "</body></html>\n");
+	return 1;
+}
+
+
+int
+CloseHandler(struct mg_connection *conn, void *cbdata)
+{
+	/* Handler may access the request info using mg_get_request_info */
+	const struct mg_request_info *req_info = mg_get_request_info(conn);
+
+	mg_printf(conn,
+	          "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nConnection: "
+	          "close\r\n\r\n");
+	mg_printf(conn, "<html><body>");
+	mg_printf(conn,
+	          "<h2>This handler will close the connection in a second</h2>");
+#ifdef _WIN32
+	Sleep(1000);
+#else
+	sleep(1);
+#endif
+	mg_printf(conn, "bye");
+	printf("CloseHandler: close connection\n");
+	mg_close_connection(conn);
+	printf("CloseHandler: wait 10 sec\n");
+#ifdef _WIN32
+	Sleep(10000);
+#else
+	sleep(10);
+#endif
+	printf("CloseHandler: return from function\n");
+	return 1;
+}
+
+
+int
+FileHandler(struct mg_connection *conn, void *cbdata)
+{
+	/* In this handler, we ignore the req_info and send the file "fileName". */
+	const char *fileName = (const char *)cbdata;
+
+	mg_send_file(conn, fileName);
+	return 1;
+}
+
+
+int
+field_found(const char *key,
+            const char *filename,
+            char *path,
+            size_t pathlen,
+            void *user_data)
+{
+	struct mg_connection *conn = (struct mg_connection *)user_data;
+
+	mg_printf(conn, "\r\n\r\n%s:\r\n", key);
+
+	if (filename && *filename) {
+#ifdef _WIN32
+		_snprintf(path, pathlen, "D:\\tmp\\%s", filename);
+#else
+		snprintf(path, pathlen, "/tmp/%s", filename);
+#endif
+		return FORM_FIELD_STORAGE_STORE;
+	}
+	return FORM_FIELD_STORAGE_GET;
+}
+
+
+int
+field_get(const char *key, const char *value, size_t valuelen, void *user_data)
+{
+	struct mg_connection *conn = (struct mg_connection *)user_data;
+
+	if (key[0]) {
+		mg_printf(conn, "%s = ", key);
+	}
+	mg_write(conn, value, valuelen);
+
+	return 0;
+}
+
+
+int
+field_stored(const char *path, long long file_size, void *user_data)
+{
+	struct mg_connection *conn = (struct mg_connection *)user_data;
+
+	mg_printf(conn,
+	          "stored as %s (%lu bytes)\r\n\r\n",
+	          path,
+	          (unsigned long)file_size);
+
+	return 0;
+}
+
+
+int
+FormHandler(struct mg_connection *conn, void *cbdata)
+{
+	/* Handler may access the request info using mg_get_request_info */
+	const struct mg_request_info *req_info = mg_get_request_info(conn);
+	int ret;
+	struct mg_form_data_handler fdh = {field_found, field_get, field_stored, 0};
+
+	/* It would be possible to check the request info here before calling
+	 * mg_handle_form_request. */
+	(void)req_info;
+
+	mg_printf(conn,
+	          "HTTP/1.1 200 OK\r\nContent-Type: "
+	          "text/plain\r\nConnection: close\r\n\r\n");
+	fdh.user_data = (void *)conn;
+
+	/* Call the form handler */
+	mg_printf(conn, "Form data:");
+	ret = mg_handle_form_request(conn, &fdh);
+	mg_printf(conn, "\r\n%i fields found", ret);
+
+	return 1;
+}
+
+
+int
+FileUploadForm(struct mg_connection *conn, void *cbdata)
+{
+	mg_printf(conn,
+	          "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nConnection: "
+	          "close\r\n\r\n");
+
+	mg_printf(conn, "<!DOCTYPE html>\n");
+	mg_printf(conn, "<html>\n<head>\n");
+	mg_printf(conn, "<meta charset=\"UTF-8\">\n");
+	mg_printf(conn, "<title>File upload</title>\n");
+	mg_printf(conn, "</head>\n<body>\n");
+	mg_printf(conn,
+	          "<form action=\"%s\" method=\"POST\" "
+	          "enctype=\"multipart/form-data\">\n",
+	          (const char *)cbdata);
+	mg_printf(conn, "<input type=\"file\" name=\"filesin\" multiple>\n");
+	mg_printf(conn, "<input type=\"submit\" value=\"Submit\">\n");
+	mg_printf(conn, "</form>\n</body>\n</html>\n");
+	return 1;
+}
+
+#define MD5_STATIC static
+#include "../src/md5.inl"
+
+struct tfile_checksum {
+	char name[128];
+	unsigned long long length;
+	md5_state_t chksum;
+};
+
+#define MAX_FILES (10)
+
+struct tfiles_checksums {
+	int index;
+	struct tfile_checksum file[MAX_FILES];
+};
+
+
+int
+field_disp_read_on_the_fly(const char *key,
+                           const char *filename,
+                           char *path,
+                           size_t pathlen,
+                           void *user_data)
+{
+	struct tfiles_checksums *context = (struct tfiles_checksums *)user_data;
+
+	(void)key;
+	(void)path;
+	(void)pathlen;
+
+	if (context->index < MAX_FILES) {
+		context->index++;
+		strncpy(context->file[context->index - 1].name, filename, 128);
+		context->file[context->index - 1].name[127] = 0;
+		context->file[context->index - 1].length = 0;
+		md5_init(&(context->file[context->index - 1].chksum));
+		return FORM_FIELD_STORAGE_GET;
+	}
+	return FORM_FIELD_STORAGE_ABORT;
+}
+
+
+int
+field_get_checksum(const char *key,
+                   const char *value,
+                   size_t valuelen,
+                   void *user_data)
+{
+	struct tfiles_checksums *context = (struct tfiles_checksums *)user_data;
+	(void)key;
+
+	context->file[context->index - 1].length += valuelen;
+	md5_append(&(context->file[context->index - 1].chksum),
+	           (const md5_byte_t *)value,
+	           valuelen);
+
+	return 0;
+}
+
+
+int
+CheckSumHandler(struct mg_connection *conn, void *cbdata)
+{
+	/* Handler may access the request info using mg_get_request_info */
+	const struct mg_request_info *req_info = mg_get_request_info(conn);
+	int i, j, ret;
+	struct tfiles_checksums chksums;
+	md5_byte_t digest[16];
+	struct mg_form_data_handler fdh = {field_disp_read_on_the_fly,
+	                                   field_get_checksum,
+	                                   0,
+	                                   (void *)&chksums};
+
+	/* It would be possible to check the request info here before calling
+	 * mg_handle_form_request. */
+	(void)req_info;
+
+	memset(&chksums, 0, sizeof(chksums));
+
+	mg_printf(conn,
+	          "HTTP/1.1 200 OK\r\n"
+	          "Content-Type: text/plain\r\n"
+	          "Connection: close\r\n\r\n");
+
+	/* Call the form handler */
+	mg_printf(conn, "File checksums:");
+	ret = mg_handle_form_request(conn, &fdh);
+	for (i = 0; i < chksums.index; i++) {
+		md5_finish(&(chksums.file[i].chksum), digest);
+		/* Visual Studio 2010+ support llu */
+		mg_printf(conn,
+		          "\r\n%s %llu ",
+		          chksums.file[i].name,
+		          chksums.file[i].length);
+		for (j = 0; j < 16; j++) {
+			mg_printf(conn, "%02x", (unsigned int)digest[j]);
+		}
+	}
+	mg_printf(conn, "\r\n%i files\r\n", ret);
+
+	return 1;
+}
+
+
+int
+CookieHandler(struct mg_connection *conn, void *cbdata)
+{
+	/* Handler may access the request info using mg_get_request_info */
+	const struct mg_request_info *req_info = mg_get_request_info(conn);
+	const char *cookie = mg_get_header(conn, "Cookie");
+	char first_str[64], count_str[64];
+	int count;
+
+	(void)mg_get_cookie(cookie, "first", first_str, sizeof(first_str));
+	(void)mg_get_cookie(cookie, "count", count_str, sizeof(count_str));
+
+	mg_printf(conn, "HTTP/1.1 200 OK\r\nConnection: close\r\n");
+	if (first_str[0] == 0) {
+		time_t t = time(0);
+		struct tm *ptm = localtime(&t);
+		mg_printf(conn,
+		          "Set-Cookie: first=%04i-%02i-%02iT%02i:%02i:%02i\r\n",
+		          ptm->tm_year + 1900,
+		          ptm->tm_mon + 1,
+		          ptm->tm_mday,
+		          ptm->tm_hour,
+		          ptm->tm_min,
+		          ptm->tm_sec);
+	}
+	count = (count_str[0] == 0) ? 0 : atoi(count_str);
+	mg_printf(conn, "Set-Cookie: count=%i\r\n", count + 1);
+	mg_printf(conn, "Content-Type: text/html\r\n\r\n");
+
+	mg_printf(conn, "<html><body>");
+	mg_printf(conn, "<h2>This is the CookieHandler.</h2>");
+	mg_printf(conn, "<p>The actual uri is %s</p>", req_info->uri);
+
+	if (first_str[0] == 0) {
+		mg_printf(conn, "<p>This is the first time, you opened this page</p>");
+	} else {
+		mg_printf(conn, "<p>You opened this page %i times before.</p>", count);
+		mg_printf(conn, "<p>You first opened this page on %s.</p>", first_str);
+	}
+
+	mg_printf(conn, "</body></html>\n");
+	return 1;
+}
+
+
+int
+WebSocketStartHandler(struct mg_connection *conn, void *cbdata)
+{
+	mg_printf(conn,
+	          "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nConnection: "
+	          "close\r\n\r\n");
+
+	mg_printf(conn, "<!DOCTYPE html>\n");
+	mg_printf(conn, "<html>\n<head>\n");
+	mg_printf(conn, "<meta charset=\"UTF-8\">\n");
+	mg_printf(conn, "<title>Embedded websocket example</title>\n");
+
+#ifdef USE_WEBSOCKET
+	/* mg_printf(conn, "<script type=\"text/javascript\"><![CDATA[\n"); ...
+	 * xhtml style */
+	mg_printf(conn, "<script>\n");
+	mg_printf(
+	    conn,
+	    "function load() {\n"
+	    "  var wsproto = (location.protocol === 'https:') ? 'wss:' : 'ws:';\n"
+	    "  connection = new WebSocket(wsproto + '//' + window.location.host + "
+	    "'/websocket');\n"
+	    "  websock_text_field = "
+	    "document.getElementById('websock_text_field');\n"
+	    "  connection.onmessage = function (e) {\n"
+	    "    websock_text_field.innerHTML=e.data;\n"
+	    "  }\n"
+	    "  connection.onerror = function (error) {\n"
+	    "    alert('WebSocket error');\n"
+	    "    connection.close();\n"
+	    "  }\n"
+	    "}\n");
+	/* mg_printf(conn, "]]></script>\n"); ... xhtml style */
+	mg_printf(conn, "</script>\n");
+	mg_printf(conn, "</head>\n<body onload=\"load()\">\n");
+	mg_printf(
+	    conn,
+	    "<div id='websock_text_field'>No websocket connection yet</div>\n");
+#else
+	mg_printf(conn, "</head>\n<body>\n");
+	mg_printf(conn, "Example not compiled with USE_WEBSOCKET\n");
+#endif
+	mg_printf(conn, "</body>\n</html>\n");
+
+	return 1;
+}
+
+
+#ifdef USE_WEBSOCKET
+
+/* MAX_WS_CLIENTS defines how many clients can connect to a websocket at the
+ * same time. The value 5 is very small and used here only for demonstration;
+ * it can be easily tested to connect more than MAX_WS_CLIENTS clients.
+ * A real server should use a much higher number, or better use a dynamic list
+ * of currently connected websocket clients. */
+#define MAX_WS_CLIENTS (5)
+
+struct t_ws_client {
+	struct mg_connection *conn;
+	int state;
+} static ws_clients[MAX_WS_CLIENTS];
+
+
+#define ASSERT(x)                                                              \
+	{                                                                          \
+		if (!(x)) {                                                            \
+			fprintf(stderr,                                                    \
+			        "Assertion failed in line %u\n",                           \
+			        (unsigned)__LINE__);                                       \
+		}                                                                      \
+	}
+
+
+int
+WebSocketConnectHandler(const struct mg_connection *conn, void *cbdata)
+{
+	struct mg_context *ctx = mg_get_context(conn);
+	int reject = 1;
+	int i;
+
+	mg_lock_context(ctx);
+	for (i = 0; i < MAX_WS_CLIENTS; i++) {
+		if (ws_clients[i].conn == NULL) {
+			ws_clients[i].conn = (struct mg_connection *)conn;
+			ws_clients[i].state = 1;
+			mg_set_user_connection_data(ws_clients[i].conn,
+			                            (void *)(ws_clients + i));
+			reject = 0;
+			break;
+		}
+	}
+	mg_unlock_context(ctx);
+
+	fprintf(stdout,
+	        "Websocket client %s\r\n\r\n",
+	        (reject ? "rejected" : "accepted"));
+	return reject;
+}
+
+
+void
+WebSocketReadyHandler(struct mg_connection *conn, void *cbdata)
+{
+	const char *text = "Hello from the websocket ready handler";
+	struct t_ws_client *client = mg_get_user_connection_data(conn);
+
+	mg_websocket_write(conn, WEBSOCKET_OPCODE_TEXT, text, strlen(text));
+	fprintf(stdout, "Greeting message sent to websocket client\r\n\r\n");
+	ASSERT(client->conn == conn);
+	ASSERT(client->state == 1);
+
+	client->state = 2;
+}
+
+
+int
+WebsocketDataHandler(struct mg_connection *conn,
+                     int bits,
+                     char *data,
+                     size_t len,
+                     void *cbdata)
+{
+	struct t_ws_client *client = mg_get_user_connection_data(conn);
+	ASSERT(client->conn == conn);
+	ASSERT(client->state >= 1);
+
+	fprintf(stdout, "Websocket got data:\r\n");
+	fwrite(data, len, 1, stdout);
+	fprintf(stdout, "\r\n\r\n");
+
+	return 1;
+}
+
+
+void
+WebSocketCloseHandler(const struct mg_connection *conn, void *cbdata)
+{
+	struct mg_context *ctx = mg_get_context(conn);
+	struct t_ws_client *client = mg_get_user_connection_data(conn);
+	ASSERT(client->conn == conn);
+	ASSERT(client->state >= 1);
+
+	mg_lock_context(ctx);
+	client->state = 0;
+	client->conn = NULL;
+	mg_unlock_context(ctx);
+
+	fprintf(stdout,
+	        "Client droped from the set of webserver connections\r\n\r\n");
+}
+
+
+void
+InformWebsockets(struct mg_context *ctx)
+{
+	static unsigned long cnt = 0;
+	char text[32];
+	int i;
+
+	sprintf(text, "%lu", ++cnt);
+
+	mg_lock_context(ctx);
+	for (i = 0; i < MAX_WS_CLIENTS; i++) {
+		if (ws_clients[i].state == 2) {
+			mg_websocket_write(ws_clients[i].conn,
+			                   WEBSOCKET_OPCODE_TEXT,
+			                   text,
+			                   strlen(text));
+		}
+	}
+	mg_unlock_context(ctx);
+}
+#endif
+
+
+#ifdef USE_SSL_DH
+#include "openssl/ssl.h"
+#include "openssl/dh.h"
+#include "openssl/ec.h"
+#include "openssl/evp.h"
+#include "openssl/ecdsa.h"
+
+DH *
+get_dh2236()
+{
+	static unsigned char dh2236_p[] = {
+	    0x0E, 0x97, 0x6E, 0x6A, 0x88, 0x84, 0xD2, 0xD7, 0x55, 0x6A, 0x17, 0xB7,
+	    0x81, 0x9A, 0x98, 0xBC, 0x7E, 0xD1, 0x6A, 0x44, 0xB1, 0x18, 0xE6, 0x25,
+	    0x3A, 0x62, 0x35, 0xF0, 0x41, 0x91, 0xE2, 0x16, 0x43, 0x9D, 0x8F, 0x7D,
+	    0x5D, 0xDA, 0x85, 0x47, 0x25, 0xC4, 0xBA, 0x68, 0x0A, 0x87, 0xDC, 0x2C,
+	    0x33, 0xF9, 0x75, 0x65, 0x17, 0xCB, 0x8B, 0x80, 0xFE, 0xE0, 0xA8, 0xAF,
+	    0xC7, 0x9E, 0x82, 0xBE, 0x6F, 0x1F, 0x00, 0x04, 0xBD, 0x69, 0x50, 0x8D,
+	    0x9C, 0x3C, 0x41, 0x69, 0x21, 0x4E, 0x86, 0xC8, 0x2B, 0xCC, 0x07, 0x4D,
+	    0xCF, 0xE4, 0xA2, 0x90, 0x8F, 0x66, 0xA9, 0xEF, 0xF7, 0xFC, 0x6F, 0x5F,
+	    0x06, 0x22, 0x00, 0xCB, 0xCB, 0xC3, 0x98, 0x3F, 0x06, 0xB9, 0xEC, 0x48,
+	    0x3B, 0x70, 0x6E, 0x94, 0xE9, 0x16, 0xE1, 0xB7, 0x63, 0x2E, 0xAB, 0xB2,
+	    0xF3, 0x84, 0xB5, 0x3D, 0xD7, 0x74, 0xF1, 0x6A, 0xD1, 0xEF, 0xE8, 0x04,
+	    0x18, 0x76, 0xD2, 0xD6, 0xB0, 0xB7, 0x71, 0xB6, 0x12, 0x8F, 0xD1, 0x33,
+	    0xAB, 0x49, 0xAB, 0x09, 0x97, 0x35, 0x9D, 0x4B, 0xBB, 0x54, 0x22, 0x6E,
+	    0x1A, 0x33, 0x18, 0x02, 0x8A, 0xF4, 0x7C, 0x0A, 0xCE, 0x89, 0x75, 0x2D,
+	    0x10, 0x68, 0x25, 0xA9, 0x6E, 0xCD, 0x97, 0x49, 0xED, 0xAE, 0xE6, 0xA7,
+	    0xB0, 0x07, 0x26, 0x25, 0x60, 0x15, 0x2B, 0x65, 0x88, 0x17, 0xF2, 0x5D,
+	    0x2C, 0xF6, 0x2A, 0x7A, 0x8C, 0xAD, 0xB6, 0x0A, 0xA2, 0x57, 0xB0, 0xC1,
+	    0x0E, 0x5C, 0xA8, 0xA1, 0x96, 0x58, 0x9A, 0x2B, 0xD4, 0xC0, 0x8A, 0xCF,
+	    0x91, 0x25, 0x94, 0xB4, 0x14, 0xA7, 0xE4, 0xE2, 0x1B, 0x64, 0x5F, 0xD2,
+	    0xCA, 0x70, 0x46, 0xD0, 0x2C, 0x95, 0x6B, 0x9A, 0xFB, 0x83, 0xF9, 0x76,
+	    0xE6, 0xD4, 0xA4, 0xA1, 0x2B, 0x2F, 0xF5, 0x1D, 0xE4, 0x06, 0xAF, 0x7D,
+	    0x22, 0xF3, 0x04, 0x30, 0x2E, 0x4C, 0x64, 0x12, 0x5B, 0xB0, 0x55, 0x3E,
+	    0xC0, 0x5E, 0x56, 0xCB, 0x99, 0xBC, 0xA8, 0xD9, 0x23, 0xF5, 0x57, 0x40,
+	    0xF0, 0x52, 0x85, 0x9B,
+	};
+	static unsigned char dh2236_g[] = {
+	    0x02,
+	};
+	DH *dh;
+
+	if ((dh = DH_new()) == NULL)
+		return (NULL);
+	dh->p = BN_bin2bn(dh2236_p, sizeof(dh2236_p), NULL);
+	dh->g = BN_bin2bn(dh2236_g, sizeof(dh2236_g), NULL);
+	if ((dh->p == NULL) || (dh->g == NULL)) {
+		DH_free(dh);
+		return (NULL);
+	}
+	return (dh);
+}
+#endif
+
+
+#ifndef NO_SSL
+int
+init_ssl(void *ssl_context, void *user_data)
+{
+	/* Add application specific SSL initialization */
+	struct ssl_ctx_st *ctx = (struct ssl_ctx_st *)ssl_context;
+
+#ifdef USE_SSL_DH
+	/* example from https://github.com/civetweb/civetweb/issues/347 */
+	DH *dh = get_dh2236();
+	if (!dh)
+		return -1;
+	if (1 != SSL_CTX_set_tmp_dh(ctx, dh))
+		return -1;
+	DH_free(dh);
+
+	EC_KEY *ecdh = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1);
+	if (!ecdh)
+		return -1;
+	if (1 != SSL_CTX_set_tmp_ecdh(ctx, ecdh))
+		return -1;
+	EC_KEY_free(ecdh);
+
+	printf("ECDH ciphers initialized\n");
+#endif
+	return 0;
+}
+#endif
+
+
+int
+log_message(const struct mg_connection *conn, const char *message)
+{
+	puts(message);
+	return 1;
+}
+
+
+int
+main(int argc, char *argv[])
+{
+	const char *options[] = {
+	    "document_root",
+	    DOCUMENT_ROOT,
+	    "listening_ports",
+	    PORT,
+	    "request_timeout_ms",
+	    "10000",
+	    "error_log_file",
+	    "error.log",
+#ifdef USE_WEBSOCKET
+	    "websocket_timeout_ms",
+	    "3600000",
+#endif
+#ifndef NO_SSL
+	    "ssl_certificate",
+	    "../../resources/cert/server.pem",
+	    "ssl_protocol_version",
+	    "3",
+	    "ssl_cipher_list",
+#ifdef USE_SSL_DH
+	    "ECDHE-RSA-AES256-GCM-SHA384:DES-CBC3-SHA:AES128-SHA:AES128-GCM-SHA256",
+#else
+	    "DES-CBC3-SHA:AES128-SHA:AES128-GCM-SHA256",
+#endif
+#endif
+	    0};
+	struct mg_callbacks callbacks;
+	struct mg_context *ctx;
+	struct mg_server_ports ports[32];
+	int port_cnt, n;
+	int err = 0;
+
+/* Check if libcivetweb has been built with all required features. */
+#ifdef USE_IPV6
+	if (!mg_check_feature(8)) {
+		fprintf(stderr,
+		        "Error: Embedded example built with IPv6 support, "
+		        "but civetweb library build without.\n");
+		err = 1;
+	}
+#endif
+#ifdef USE_WEBSOCKET
+	if (!mg_check_feature(16)) {
+		fprintf(stderr,
+		        "Error: Embedded example built with websocket support, "
+		        "but civetweb library build without.\n");
+		err = 1;
+	}
+#endif
+#ifndef NO_SSL
+	if (!mg_check_feature(2)) {
+		fprintf(stderr,
+		        "Error: Embedded example built with SSL support, "
+		        "but civetweb library build without.\n");
+		err = 1;
+	}
+#endif
+	if (err) {
+		fprintf(stderr, "Cannot start CivetWeb - inconsistent build.\n");
+		return EXIT_FAILURE;
+	}
+
+	/* Start CivetWeb web server */
+	memset(&callbacks, 0, sizeof(callbacks));
+#ifndef NO_SSL
+	callbacks.init_ssl = init_ssl;
+#endif
+	callbacks.log_message = log_message;
+	ctx = mg_start(&callbacks, 0, options);
+
+	/* Check return value: */
+	if (ctx == NULL) {
+		fprintf(stderr, "Cannot start CivetWeb - mg_start failed.\n");
+		return EXIT_FAILURE;
+	}
+
+	/* Add handler EXAMPLE_URI, to explain the example */
+	mg_set_request_handler(ctx, EXAMPLE_URI, ExampleHandler, 0);
+	mg_set_request_handler(ctx, EXIT_URI, ExitHandler, 0);
+
+	/* Add handler for /A* and special handler for /A/B */
+	mg_set_request_handler(ctx, "/A", AHandler, 0);
+	mg_set_request_handler(ctx, "/A/B", ABHandler, 0);
+
+	/* Add handler for /B, /B/A, /B/B but not for /B* */
+	mg_set_request_handler(ctx, "/B$", BXHandler, (void *)0);
+	mg_set_request_handler(ctx, "/B/A$", BXHandler, (void *)1);
+	mg_set_request_handler(ctx, "/B/B$", BXHandler, (void *)2);
+
+	/* Add handler for all files with .foo extention */
+	mg_set_request_handler(ctx, "**.foo$", FooHandler, 0);
+
+	/* Add handler for /close extention */
+	mg_set_request_handler(ctx, "/close", CloseHandler, 0);
+
+	/* Add handler for /form  (serve a file outside the document root) */
+	mg_set_request_handler(ctx,
+	                       "/form",
+	                       FileHandler,
+	                       (void *)"../../test/form.html");
+
+	/* Add handler for form data */
+	mg_set_request_handler(ctx,
+	                       "/handle_form.embedded_c.example.callback",
+	                       FormHandler,
+	                       (void *)0);
+
+	/* Add a file upload handler for parsing files on the fly */
+	mg_set_request_handler(ctx,
+	                       "/on_the_fly_form",
+	                       FileUploadForm,
+	                       (void *)"/on_the_fly_form.md5.callback");
+	mg_set_request_handler(ctx,
+	                       "/on_the_fly_form.md5.callback",
+	                       CheckSumHandler,
+	                       (void *)0);
+
+	/* Add handler for /cookie example */
+	mg_set_request_handler(ctx, "/cookie", CookieHandler, 0);
+
+	/* Add HTTP site to open a websocket connection */
+	mg_set_request_handler(ctx, "/websocket", WebSocketStartHandler, 0);
+
+#ifdef USE_WEBSOCKET
+	/* WS site for the websocket connection */
+	mg_set_websocket_handler(ctx,
+	                         "/websocket",
+	                         WebSocketConnectHandler,
+	                         WebSocketReadyHandler,
+	                         WebsocketDataHandler,
+	                         WebSocketCloseHandler,
+	                         0);
+#endif
+
+	/* List all listening ports */
+	memset(ports, 0, sizeof(ports));
+	port_cnt = mg_get_server_ports(ctx, 32, ports);
+	printf("\n%i listening ports:\n\n", port_cnt);
+
+	for (n = 0; n < port_cnt && n < 32; n++) {
+		const char *proto = ports[n].is_ssl ? "https" : "http";
+		const char *host;
+
+		if ((ports[n].protocol & 1) == 1) {
+			/* IPv4 */
+			host = "127.0.0.1";
+			printf("Browse files at %s://%s:%i/\n", proto, host, ports[n].port);
+			printf("Run example at %s://%s:%i%s\n",
+			       proto,
+			       host,
+			       ports[n].port,
+			       EXAMPLE_URI);
+			printf(
+			    "Exit at %s://%s:%i%s\n", proto, host, ports[n].port, EXIT_URI);
+			printf("\n");
+		}
+
+		if ((ports[n].protocol & 2) == 2) {
+			/* IPv6 */
+			host = "[::1]";
+			printf("Browse files at %s://%s:%i/\n", proto, host, ports[n].port);
+			printf("Run example at %s://%s:%i%s\n",
+			       proto,
+			       host,
+			       ports[n].port,
+			       EXAMPLE_URI);
+			printf(
+			    "Exit at %s://%s:%i%s\n", proto, host, ports[n].port, EXIT_URI);
+			printf("\n");
+		}
+	}
+
+	/* Wait until the server should be closed */
+	while (!exitNow) {
+#ifdef _WIN32
+		Sleep(1000);
+#else
+		sleep(1);
+#endif
+#ifdef USE_WEBSOCKET
+		InformWebsockets(ctx);
+#endif
+	}
+
+	/* Stop the server */
+	mg_stop(ctx);
+	printf("Server stopped.\n");
+	printf("Bye!\n");
+
+	return EXIT_SUCCESS;
+}


[29/51] [partial] nifi-minifi-cpp git commit: MINIFI-183 Added civet 1.9.1 sources Added onScheduled hook Added initial two-way TLS-enabled ListenHTTP implementation

Posted by al...@apache.org.
http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/debugger/duk_debug_meta.json
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/debugger/duk_debug_meta.json b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/debugger/duk_debug_meta.json
new file mode 100644
index 0000000..41de1c2
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/debugger/duk_debug_meta.json
@@ -0,0 +1,1497 @@
+{
+    "opcodes": [
+        {
+            "args": [
+                "A_R", 
+                "BC_R"
+            ], 
+            "name": "LDREG"
+        }, 
+        {
+            "args": [
+                "A_R", 
+                "BC_R"
+            ], 
+            "name": "STREG"
+        }, 
+        {
+            "args": [
+                "A_R", 
+                "BC_C"
+            ], 
+            "name": "LDCONST"
+        }, 
+        {
+            "args": [
+                "A_R", 
+                "BC_LDINT"
+            ], 
+            "name": "LDINT"
+        }, 
+        {
+            "args": [
+                "A_R", 
+                "BC_LDINTX"
+            ], 
+            "name": "LDINTX"
+        }, 
+        {
+            "args": [
+                "A_R", 
+                "B_R", 
+                "C_I"
+            ], 
+            "name": "MPUTOBJ"
+        }, 
+        {
+            "args": [
+                "A_R", 
+                "B_RI", 
+                "C_I"
+            ], 
+            "name": "MPUTOBJI"
+        }, 
+        {
+            "args": [
+                "A_R", 
+                "B_R", 
+                "C_I"
+            ], 
+            "name": "MPUTARR"
+        }, 
+        {
+            "args": [
+                "A_R", 
+                "B_RI", 
+                "C_I"
+            ], 
+            "name": "MPUTARRI"
+        }, 
+        {
+            "args": [
+                "B_R", 
+                "C_I"
+            ], 
+            "name": "NEW"
+        }, 
+        {
+            "args": [
+                "B_RI", 
+                "C_I"
+            ], 
+            "name": "NEWI"
+        }, 
+        {
+            "args": [
+                "A_R", 
+                "B_RC", 
+                "C_RC"
+            ], 
+            "name": "REGEXP"
+        }, 
+        {
+            "args": [
+                "A_R", 
+                "B_R"
+            ], 
+            "name": "CSREG"
+        }, 
+        {
+            "args": [
+                "A_RI", 
+                "B_R"
+            ], 
+            "name": "CSREGI"
+        }, 
+        {
+            "args": [
+                "A_R", 
+                "BC_C"
+            ], 
+            "name": "GETVAR"
+        }, 
+        {
+            "args": [
+                "A_R", 
+                "BC_C"
+            ], 
+            "name": "PUTVAR"
+        }, 
+        {
+            "args": [
+                "A_H", 
+                "B_RC", 
+                "C_RC"
+            ], 
+            "flags": [
+                {
+                    "mask": 64, 
+                    "name": "writable"
+                }, 
+                {
+                    "mask": 128, 
+                    "name": "enumerable"
+                }, 
+                {
+                    "mask": 256, 
+                    "name": "configurable"
+                }, 
+                {
+                    "mask": 512, 
+                    "name": "accessor"
+                }, 
+                {
+                    "mask": 1024, 
+                    "name": "undef_value"
+                }, 
+                {
+                    "mask": 2048, 
+                    "name": "func_decl"
+                }
+            ], 
+            "name": "DECLVAR"
+        }, 
+        {
+            "args": [
+                "A_R", 
+                "B_RC"
+            ], 
+            "name": "DELVAR"
+        }, 
+        {
+            "args": [
+                "A_R", 
+                "B_RC"
+            ], 
+            "name": "CSVAR"
+        }, 
+        {
+            "args": [
+                "A_RI", 
+                "B_RC"
+            ], 
+            "name": "CSVARI"
+        }, 
+        {
+            "args": [
+                "A_R", 
+                "BC_I"
+            ], 
+            "name": "CLOSURE"
+        }, 
+        {
+            "args": [
+                "A_R", 
+                "B_RC", 
+                "C_RC"
+            ], 
+            "name": "GETPROP"
+        }, 
+        {
+            "args": [
+                "A_R", 
+                "B_RC", 
+                "C_RC"
+            ], 
+            "name": "PUTPROP"
+        }, 
+        {
+            "args": [
+                "A_R", 
+                "B_R", 
+                "C_RC"
+            ], 
+            "name": "DELPROP"
+        }, 
+        {
+            "args": [
+                "A_R", 
+                "B_R", 
+                "C_RC"
+            ], 
+            "name": "CSPROP"
+        }, 
+        {
+            "args": [
+                "A_RI", 
+                "B_R", 
+                "C_RC"
+            ], 
+            "name": "CSPROPI"
+        }, 
+        {
+            "args": [
+                "A_R", 
+                "B_RC", 
+                "C_RC"
+            ], 
+            "name": "ADD"
+        }, 
+        {
+            "args": [
+                "A_R", 
+                "B_RC", 
+                "C_RC"
+            ], 
+            "name": "SUB"
+        }, 
+        {
+            "args": [
+                "A_R", 
+                "B_RC", 
+                "C_RC"
+            ], 
+            "name": "MUL"
+        }, 
+        {
+            "args": [
+                "A_R", 
+                "B_RC", 
+                "C_RC"
+            ], 
+            "name": "DIV"
+        }, 
+        {
+            "args": [
+                "A_R", 
+                "B_RC", 
+                "C_RC"
+            ], 
+            "name": "MOD"
+        }, 
+        {
+            "args": [
+                "A_R", 
+                "B_RC", 
+                "C_RC"
+            ], 
+            "name": "BAND"
+        }, 
+        {
+            "args": [
+                "A_R", 
+                "B_RC", 
+                "C_RC"
+            ], 
+            "name": "BOR"
+        }, 
+        {
+            "args": [
+                "A_R", 
+                "B_RC", 
+                "C_RC"
+            ], 
+            "name": "BXOR"
+        }, 
+        {
+            "args": [
+                "A_R", 
+                "B_RC", 
+                "C_RC"
+            ], 
+            "name": "BASL"
+        }, 
+        {
+            "args": [
+                "A_R", 
+                "B_RC", 
+                "C_RC"
+            ], 
+            "name": "BLSR"
+        }, 
+        {
+            "args": [
+                "A_R", 
+                "B_RC", 
+                "C_RC"
+            ], 
+            "name": "BASR"
+        }, 
+        {
+            "args": [
+                "A_R", 
+                "B_RC", 
+                "C_RC"
+            ], 
+            "name": "EQ"
+        }, 
+        {
+            "args": [
+                "A_R", 
+                "B_RC", 
+                "C_RC"
+            ], 
+            "name": "NEQ"
+        }, 
+        {
+            "args": [
+                "A_R", 
+                "B_RC", 
+                "C_RC"
+            ], 
+            "name": "SEQ"
+        }, 
+        {
+            "args": [
+                "A_R", 
+                "B_RC", 
+                "C_RC"
+            ], 
+            "name": "SNEQ"
+        }, 
+        {
+            "args": [
+                "A_R", 
+                "B_RC", 
+                "C_RC"
+            ], 
+            "name": "GT"
+        }, 
+        {
+            "args": [
+                "A_R", 
+                "B_RC", 
+                "C_RC"
+            ], 
+            "name": "GE"
+        }, 
+        {
+            "args": [
+                "A_R", 
+                "B_RC", 
+                "C_RC"
+            ], 
+            "name": "LT"
+        }, 
+        {
+            "args": [
+                "A_R", 
+                "B_RC", 
+                "C_RC"
+            ], 
+            "name": "LE"
+        }, 
+        {
+            "args": [
+                "A_B", 
+                "B_RC"
+            ], 
+            "name": "IF"
+        }, 
+        {
+            "args": [
+                "ABC_JUMP"
+            ], 
+            "name": "JUMP"
+        }, 
+        {
+            "args": [
+                "A_H", 
+                "B_RC"
+            ], 
+            "flags": [
+                {
+                    "mask": 64, 
+                    "name": "have_retval"
+                }
+            ], 
+            "name": "RETURN"
+        }, 
+        {
+            "args": [
+                "A_H", 
+                "B_R", 
+                "C_I"
+            ], 
+            "flags": [
+                {
+                    "mask": 64, 
+                    "name": "tailcall"
+                }, 
+                {
+                    "mask": 128, 
+                    "name": "evalcall"
+                }
+            ], 
+            "name": "CALL"
+        }, 
+        {
+            "args": [
+                "A_H", 
+                "B_RI", 
+                "C_I"
+            ], 
+            "name": "CALLI"
+        }, 
+        {
+            "args": [
+                "A_H", 
+                "BC_R"
+            ], 
+            "flags": [
+                {
+                    "mask": 64, 
+                    "name": "have_catch"
+                }, 
+                {
+                    "mask": 128, 
+                    "name": "have_finally"
+                }, 
+                {
+                    "mask": 256, 
+                    "name": "catch_binding"
+                }, 
+                {
+                    "mask": 512, 
+                    "name": "with_binding"
+                }
+            ], 
+            "name": "TRYCATCH"
+        }, 
+        {
+            "name": "EXTRA", 
+            "extra": true
+        }, 
+        {
+            "args": [
+                "A_R", 
+                "BC_R"
+            ], 
+            "name": "PREINCR"
+        }, 
+        {
+            "args": [
+                "A_R", 
+                "BC_R"
+            ], 
+            "name": "PREDECR"
+        }, 
+        {
+            "args": [
+                "A_R", 
+                "BC_R"
+            ], 
+            "name": "POSTINCR"
+        }, 
+        {
+            "args": [
+                "A_R", 
+                "BC_R"
+            ], 
+            "name": "POSTDECR"
+        }, 
+        {
+            "args": [
+                "A_R", 
+                "BC_C"
+            ], 
+            "name": "PREINCV"
+        }, 
+        {
+            "args": [
+                "A_R", 
+                "BC_C"
+            ], 
+            "name": "PREDECV"
+        }, 
+        {
+            "args": [
+                "A_R", 
+                "BC_C"
+            ], 
+            "name": "POSTINCV"
+        }, 
+        {
+            "args": [
+                "A_R", 
+                "BC_C"
+            ], 
+            "name": "POSTDECV"
+        }, 
+        {
+            "args": [
+                "A_R", 
+                "B_RC", 
+                "C_RC"
+            ], 
+            "name": "PREINCP"
+        }, 
+        {
+            "args": [
+                "A_R", 
+                "B_RC", 
+                "C_RC"
+            ], 
+            "name": "PREDECP"
+        }, 
+        {
+            "args": [
+                "A_R", 
+                "B_RC", 
+                "C_RC"
+            ], 
+            "name": "POSTINCP"
+        }, 
+        {
+            "args": [
+                "A_R", 
+                "B_RC", 
+                "C_RC"
+            ], 
+            "name": "POSTDECP"
+        }
+    ], 
+    "client_commands": [
+        "Reserved_0", 
+        "Status", 
+        "Print", 
+        "Alert", 
+        "Log", 
+        "Throw", 
+        "Detaching", 
+        "AppNotify"
+    ], 
+    "extra": [
+        {
+            "name": "NOP"
+        }, 
+        {
+            "args": [
+                "BC_I"
+            ], 
+            "name": "INVALID"
+        }, 
+        {
+            "args": [
+                "BC_R"
+            ], 
+            "name": "LDTHIS"
+        }, 
+        {
+            "args": [
+                "BC_R"
+            ], 
+            "name": "LDUNDEF"
+        }, 
+        {
+            "args": [
+                "BC_R"
+            ], 
+            "name": "LDNULL"
+        }, 
+        {
+            "args": [
+                "BC_R"
+            ], 
+            "name": "LDTRUE"
+        }, 
+        {
+            "args": [
+                "BC_R"
+            ], 
+            "name": "LDFALSE"
+        }, 
+        {
+            "args": [
+                "B_R"
+            ], 
+            "name": "NEWOBJ"
+        }, 
+        {
+            "args": [
+                "B_R"
+            ], 
+            "name": "NEWARR"
+        }, 
+        {
+            "args": [
+                "B_R", 
+                "C_R"
+            ], 
+            "name": "SETALEN"
+        }, 
+        {
+            "args": [
+                "BC_R"
+            ], 
+            "name": "TYPEOF"
+        }, 
+        {
+            "args": [
+                "B_R", 
+                "C_RC"
+            ], 
+            "name": "TYPEOFID"
+        }, 
+        {
+            "args": [
+                "B_R", 
+                "C_R"
+            ], 
+            "name": "INITENUM"
+        }, 
+        {
+            "args": [
+                "B_R", 
+                "C_R"
+            ], 
+            "name": "NEXTENUM"
+        }, 
+        {
+            "args": [
+                "B_R", 
+                "C_R"
+            ], 
+            "name": "INITSET"
+        }, 
+        {
+            "args": [
+                "B_R", 
+                "C_RI"
+            ], 
+            "name": "INITSETI"
+        }, 
+        {
+            "args": [
+                "B_R", 
+                "C_RI"
+            ], 
+            "name": "INITGET"
+        }, 
+        {
+            "args": [
+                "B_R", 
+                "C_RI"
+            ], 
+            "name": "INITGETI"
+        }, 
+        {
+            "name": "ENDTRY"
+        }, 
+        {
+            "name": "ENDCATCH"
+        }, 
+        {
+            "name": "ENDFIN"
+        }, 
+        {
+            "args": [
+                "BC_R"
+            ], 
+            "name": "THROW"
+        }, 
+        {
+            "name": "INVLHS"
+        }, 
+        {
+            "args": [
+                "BC_R"
+            ], 
+            "name": "UNM"
+        }, 
+        {
+            "args": [
+                "BC_R"
+            ], 
+            "name": "UNP"
+        }, 
+        {
+            "name": "DEBUGGER"
+        }, 
+        {
+            "args": [
+                "BC_I"
+            ], 
+            "name": "BREAK"
+        }, 
+        {
+            "args": [
+                "BC_I"
+            ], 
+            "name": "CONTINUE"
+        }, 
+        {
+            "args": [
+                "BC_R"
+            ], 
+            "name": "BNOT"
+        }, 
+        {
+            "args": [
+                "BC_R"
+            ], 
+            "name": "LNOT"
+        }, 
+        {
+            "args": [
+                "B_R", 
+                "C_RC"
+            ], 
+            "name": "INSTOF"
+        }, 
+        {
+            "args": [
+                "B_R", 
+                "C_RC"
+            ], 
+            "name": "IN"
+        }, 
+        {
+            "args": [
+                "BC_I"
+            ], 
+            "name": "LABEL"
+        }, 
+        {
+            "args": [
+                "BC_I"
+            ], 
+            "name": "ENDLABEL"
+        }, 
+        {
+            "name": "EXTRA34"
+        }, 
+        {
+            "name": "EXTRA35"
+        }, 
+        {
+            "name": "EXTRA36"
+        }, 
+        {
+            "name": "EXTRA37"
+        }, 
+        {
+            "name": "EXTRA38"
+        }, 
+        {
+            "name": "EXTRA39"
+        }, 
+        {
+            "name": "EXTRA40"
+        }, 
+        {
+            "name": "EXTRA41"
+        }, 
+        {
+            "name": "EXTRA42"
+        }, 
+        {
+            "name": "EXTRA43"
+        }, 
+        {
+            "name": "EXTRA44"
+        }, 
+        {
+            "name": "EXTRA45"
+        }, 
+        {
+            "name": "EXTRA46"
+        }, 
+        {
+            "name": "EXTRA47"
+        }, 
+        {
+            "name": "EXTRA48"
+        }, 
+        {
+            "name": "EXTRA49"
+        }, 
+        {
+            "name": "EXTRA50"
+        }, 
+        {
+            "name": "EXTRA51"
+        }, 
+        {
+            "name": "EXTRA52"
+        }, 
+        {
+            "name": "EXTRA53"
+        }, 
+        {
+            "name": "EXTRA54"
+        }, 
+        {
+            "name": "EXTRA55"
+        }, 
+        {
+            "name": "EXTRA56"
+        }, 
+        {
+            "name": "EXTRA57"
+        }, 
+        {
+            "name": "EXTRA58"
+        }, 
+        {
+            "name": "EXTRA59"
+        }, 
+        {
+            "name": "EXTRA60"
+        }, 
+        {
+            "name": "EXTRA61"
+        }, 
+        {
+            "name": "EXTRA62"
+        }, 
+        {
+            "name": "EXTRA63"
+        }, 
+        {
+            "name": "EXTRA64"
+        }, 
+        {
+            "name": "EXTRA65"
+        }, 
+        {
+            "name": "EXTRA66"
+        }, 
+        {
+            "name": "EXTRA67"
+        }, 
+        {
+            "name": "EXTRA68"
+        }, 
+        {
+            "name": "EXTRA69"
+        }, 
+        {
+            "name": "EXTRA70"
+        }, 
+        {
+            "name": "EXTRA71"
+        }, 
+        {
+            "name": "EXTRA72"
+        }, 
+        {
+            "name": "EXTRA73"
+        }, 
+        {
+            "name": "EXTRA74"
+        }, 
+        {
+            "name": "EXTRA75"
+        }, 
+        {
+            "name": "EXTRA76"
+        }, 
+        {
+            "name": "EXTRA77"
+        }, 
+        {
+            "name": "EXTRA78"
+        }, 
+        {
+            "name": "EXTRA79"
+        }, 
+        {
+            "name": "EXTRA80"
+        }, 
+        {
+            "name": "EXTRA81"
+        }, 
+        {
+            "name": "EXTRA82"
+        }, 
+        {
+            "name": "EXTRA83"
+        }, 
+        {
+            "name": "EXTRA84"
+        }, 
+        {
+            "name": "EXTRA85"
+        }, 
+        {
+            "name": "EXTRA86"
+        }, 
+        {
+            "name": "EXTRA87"
+        }, 
+        {
+            "name": "EXTRA88"
+        }, 
+        {
+            "name": "EXTRA89"
+        }, 
+        {
+            "name": "EXTRA90"
+        }, 
+        {
+            "name": "EXTRA91"
+        }, 
+        {
+            "name": "EXTRA92"
+        }, 
+        {
+            "name": "EXTRA93"
+        }, 
+        {
+            "name": "EXTRA94"
+        }, 
+        {
+            "name": "EXTRA95"
+        }, 
+        {
+            "name": "EXTRA96"
+        }, 
+        {
+            "name": "EXTRA97"
+        }, 
+        {
+            "name": "EXTRA98"
+        }, 
+        {
+            "name": "EXTRA99"
+        }, 
+        {
+            "name": "EXTRA100"
+        }, 
+        {
+            "name": "EXTRA101"
+        }, 
+        {
+            "name": "EXTRA102"
+        }, 
+        {
+            "name": "EXTRA103"
+        }, 
+        {
+            "name": "EXTRA104"
+        }, 
+        {
+            "name": "EXTRA105"
+        }, 
+        {
+            "name": "EXTRA106"
+        }, 
+        {
+            "name": "EXTRA107"
+        }, 
+        {
+            "name": "EXTRA108"
+        }, 
+        {
+            "name": "EXTRA109"
+        }, 
+        {
+            "name": "EXTRA110"
+        }, 
+        {
+            "name": "EXTRA111"
+        }, 
+        {
+            "name": "EXTRA112"
+        }, 
+        {
+            "name": "EXTRA113"
+        }, 
+        {
+            "name": "EXTRA114"
+        }, 
+        {
+            "name": "EXTRA115"
+        }, 
+        {
+            "name": "EXTRA116"
+        }, 
+        {
+            "name": "EXTRA117"
+        }, 
+        {
+            "name": "EXTRA118"
+        }, 
+        {
+            "name": "EXTRA119"
+        }, 
+        {
+            "name": "EXTRA120"
+        }, 
+        {
+            "name": "EXTRA121"
+        }, 
+        {
+            "name": "EXTRA122"
+        }, 
+        {
+            "name": "EXTRA123"
+        }, 
+        {
+            "name": "EXTRA124"
+        }, 
+        {
+            "name": "EXTRA125"
+        }, 
+        {
+            "name": "EXTRA126"
+        }, 
+        {
+            "name": "EXTRA127"
+        }, 
+        {
+            "name": "EXTRA128"
+        }, 
+        {
+            "name": "EXTRA129"
+        }, 
+        {
+            "name": "EXTRA130"
+        }, 
+        {
+            "name": "EXTRA131"
+        }, 
+        {
+            "name": "EXTRA132"
+        }, 
+        {
+            "name": "EXTRA133"
+        }, 
+        {
+            "name": "EXTRA134"
+        }, 
+        {
+            "name": "EXTRA135"
+        }, 
+        {
+            "name": "EXTRA136"
+        }, 
+        {
+            "name": "EXTRA137"
+        }, 
+        {
+            "name": "EXTRA138"
+        }, 
+        {
+            "name": "EXTRA139"
+        }, 
+        {
+            "name": "EXTRA140"
+        }, 
+        {
+            "name": "EXTRA141"
+        }, 
+        {
+            "name": "EXTRA142"
+        }, 
+        {
+            "name": "EXTRA143"
+        }, 
+        {
+            "name": "EXTRA144"
+        }, 
+        {
+            "name": "EXTRA145"
+        }, 
+        {
+            "name": "EXTRA146"
+        }, 
+        {
+            "name": "EXTRA147"
+        }, 
+        {
+            "name": "EXTRA148"
+        }, 
+        {
+            "name": "EXTRA149"
+        }, 
+        {
+            "name": "EXTRA150"
+        }, 
+        {
+            "name": "EXTRA151"
+        }, 
+        {
+            "name": "EXTRA152"
+        }, 
+        {
+            "name": "EXTRA153"
+        }, 
+        {
+            "name": "EXTRA154"
+        }, 
+        {
+            "name": "EXTRA155"
+        }, 
+        {
+            "name": "EXTRA156"
+        }, 
+        {
+            "name": "EXTRA157"
+        }, 
+        {
+            "name": "EXTRA158"
+        }, 
+        {
+            "name": "EXTRA159"
+        }, 
+        {
+            "name": "EXTRA160"
+        }, 
+        {
+            "name": "EXTRA161"
+        }, 
+        {
+            "name": "EXTRA162"
+        }, 
+        {
+            "name": "EXTRA163"
+        }, 
+        {
+            "name": "EXTRA164"
+        }, 
+        {
+            "name": "EXTRA165"
+        }, 
+        {
+            "name": "EXTRA166"
+        }, 
+        {
+            "name": "EXTRA167"
+        }, 
+        {
+            "name": "EXTRA168"
+        }, 
+        {
+            "name": "EXTRA169"
+        }, 
+        {
+            "name": "EXTRA170"
+        }, 
+        {
+            "name": "EXTRA171"
+        }, 
+        {
+            "name": "EXTRA172"
+        }, 
+        {
+            "name": "EXTRA173"
+        }, 
+        {
+            "name": "EXTRA174"
+        }, 
+        {
+            "name": "EXTRA175"
+        }, 
+        {
+            "name": "EXTRA176"
+        }, 
+        {
+            "name": "EXTRA177"
+        }, 
+        {
+            "name": "EXTRA178"
+        }, 
+        {
+            "name": "EXTRA179"
+        }, 
+        {
+            "name": "EXTRA180"
+        }, 
+        {
+            "name": "EXTRA181"
+        }, 
+        {
+            "name": "EXTRA182"
+        }, 
+        {
+            "name": "EXTRA183"
+        }, 
+        {
+            "name": "EXTRA184"
+        }, 
+        {
+            "name": "EXTRA185"
+        }, 
+        {
+            "name": "EXTRA186"
+        }, 
+        {
+            "name": "EXTRA187"
+        }, 
+        {
+            "name": "EXTRA188"
+        }, 
+        {
+            "name": "EXTRA189"
+        }, 
+        {
+            "name": "EXTRA190"
+        }, 
+        {
+            "name": "EXTRA191"
+        }, 
+        {
+            "name": "EXTRA192"
+        }, 
+        {
+            "name": "EXTRA193"
+        }, 
+        {
+            "name": "EXTRA194"
+        }, 
+        {
+            "name": "EXTRA195"
+        }, 
+        {
+            "name": "EXTRA196"
+        }, 
+        {
+            "name": "EXTRA197"
+        }, 
+        {
+            "name": "EXTRA198"
+        }, 
+        {
+            "name": "EXTRA199"
+        }, 
+        {
+            "name": "EXTRA200"
+        }, 
+        {
+            "name": "EXTRA201"
+        }, 
+        {
+            "name": "EXTRA202"
+        }, 
+        {
+            "name": "EXTRA203"
+        }, 
+        {
+            "name": "EXTRA204"
+        }, 
+        {
+            "name": "EXTRA205"
+        }, 
+        {
+            "name": "EXTRA206"
+        }, 
+        {
+            "name": "EXTRA207"
+        }, 
+        {
+            "name": "EXTRA208"
+        }, 
+        {
+            "name": "EXTRA209"
+        }, 
+        {
+            "name": "EXTRA210"
+        }, 
+        {
+            "name": "EXTRA211"
+        }, 
+        {
+            "name": "EXTRA212"
+        }, 
+        {
+            "name": "EXTRA213"
+        }, 
+        {
+            "name": "EXTRA214"
+        }, 
+        {
+            "name": "EXTRA215"
+        }, 
+        {
+            "name": "EXTRA216"
+        }, 
+        {
+            "name": "EXTRA217"
+        }, 
+        {
+            "name": "EXTRA218"
+        }, 
+        {
+            "name": "EXTRA219"
+        }, 
+        {
+            "name": "EXTRA220"
+        }, 
+        {
+            "name": "EXTRA221"
+        }, 
+        {
+            "name": "EXTRA222"
+        }, 
+        {
+            "name": "EXTRA223"
+        }, 
+        {
+            "name": "EXTRA224"
+        }, 
+        {
+            "name": "EXTRA225"
+        }, 
+        {
+            "name": "EXTRA226"
+        }, 
+        {
+            "name": "EXTRA227"
+        }, 
+        {
+            "name": "EXTRA228"
+        }, 
+        {
+            "name": "EXTRA229"
+        }, 
+        {
+            "name": "EXTRA230"
+        }, 
+        {
+            "name": "EXTRA231"
+        }, 
+        {
+            "name": "EXTRA232"
+        }, 
+        {
+            "name": "EXTRA233"
+        }, 
+        {
+            "name": "EXTRA234"
+        }, 
+        {
+            "name": "EXTRA235"
+        }, 
+        {
+            "name": "EXTRA236"
+        }, 
+        {
+            "name": "EXTRA237"
+        }, 
+        {
+            "name": "EXTRA238"
+        }, 
+        {
+            "name": "EXTRA239"
+        }, 
+        {
+            "name": "EXTRA240"
+        }, 
+        {
+            "name": "EXTRA241"
+        }, 
+        {
+            "name": "EXTRA242"
+        }, 
+        {
+            "name": "EXTRA243"
+        }, 
+        {
+            "name": "EXTRA244"
+        }, 
+        {
+            "name": "EXTRA245"
+        }, 
+        {
+            "name": "EXTRA246"
+        }, 
+        {
+            "name": "EXTRA247"
+        }, 
+        {
+            "name": "EXTRA248"
+        }, 
+        {
+            "name": "EXTRA249"
+        }, 
+        {
+            "name": "EXTRA250"
+        }, 
+        {
+            "name": "EXTRA251"
+        }, 
+        {
+            "name": "EXTRA252"
+        }, 
+        {
+            "name": "EXTRA253"
+        }, 
+        {
+            "name": "EXTRA254"
+        }, 
+        {
+            "name": "EXTRA255"
+        }
+    ], 
+    "target_commands": [
+        "Reserved_0", 
+        "Reserved_1", 
+        "Reserved_2", 
+        "Reserved_3", 
+        "Reserved_4", 
+        "Reserved_5", 
+        "Reserved_6", 
+        "Reserved_7", 
+        "Reserved_8", 
+        "Reserved_9", 
+        "Reserved_10", 
+        "Reserved_11", 
+        "Reserved_12", 
+        "Reserved_13", 
+        "Reserved_14", 
+        "Reserved_15", 
+        "BasicInfo", 
+        "TriggerStatus", 
+        "Pause", 
+        "Resume", 
+        "StepInto", 
+        "StepOver", 
+        "StepOut", 
+        "ListBreak", 
+        "AddBreak", 
+        "DelBreak", 
+        "GetVar", 
+        "PutVar", 
+        "GetCallStack", 
+        "GetLocals", 
+        "Eval", 
+        "Detach", 
+        "DumpHeap", 
+        "GetBytecode", 
+        "AppRequest", 
+        "GetHeapObjInfo", 
+        "GetObjPropDesc", 
+        "GetObjPropDescRange"
+    ], 
+    "error_codes": [
+        "Unknown", 
+        "UnsupportedCommand", 
+        "TooMany", 
+        "NotFound", 
+        "ApplicationError"
+    ], 
+    "class_names": [
+        "unused", 
+        "Arguments", 
+        "Array", 
+        "Boolean", 
+        "Date", 
+        "Error", 
+        "Function", 
+        "JSON", 
+        "Math", 
+        "Number", 
+        "Object", 
+        "RegExp", 
+        "String", 
+        "global", 
+        "ObjEnv", 
+        "DecEnv", 
+        "Buffer", 
+        "Pointer", 
+        "Thread", 
+        "ArrayBuffer", 
+        "DataView", 
+        "Int8Array", 
+        "Uint8Array", 
+        "Uint8ClampedArray", 
+        "Int16Array", 
+        "Uint16Array", 
+        "Int32Array", 
+        "Uint32Array", 
+        "Float32Array", 
+        "Float64Array"
+    ]
+}

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/debugger/duk_debug_proxy.js
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/debugger/duk_debug_proxy.js b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/debugger/duk_debug_proxy.js
new file mode 100644
index 0000000..10ba614
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/debugger/duk_debug_proxy.js
@@ -0,0 +1,1029 @@
+/*
+ *  JSON debug proxy written in DukLuv
+ *
+ *  This single file JSON debug proxy implementation is an alternative to the
+ *  Node.js-based proxy in duk_debug.js.  DukLuv is a much smaller dependency
+ *  than Node.js so embedding DukLuv in a debug client is easier.
+ */
+
+'use strict';
+
+// XXX: Code assumes uv.write() will write fully.  This is not necessarily
+// true; should add support for partial writes (or at least failing when
+// a partial write occurs).
+
+var log = new Duktape.Logger('Proxy');  // default logger
+//log.l = 0;  // enable debug and trace logging
+
+/*
+ *  Config
+ */
+
+var serverHost = '0.0.0.0';
+var serverPort = 9093;
+var targetHost = '127.0.0.1';
+var targetPort = 9091;
+var singleConnection = false;
+var readableNumberValue = false;
+var lenientJsonParse = false;
+var jxParse = false;
+var metadataFile = null;
+var metadata = {};
+var TORTURE = false;  // for manual testing of binary/json parsing robustness
+
+/*
+ *  Detect missing 'var' declarations
+ */
+
+// Prevent new bindings on global object.  This detects missing 'var'
+// declarations, e.g. "x = 123;" in a function without declaring it.
+var global = new Function('return this;')();
+log.debug('Preventing extensions on global object');
+log.debug('Global is extensible:', Object.isExtensible(global));
+Object.preventExtensions(global);
+log.debug('Global is extensible:', Object.isExtensible(global));
+
+/*
+ *  Misc helpers
+ */
+
+function plainBufferCopy(typedarray) {
+    // This is still pretty awkward in Duktape 1.4.x.
+    // Argument may be a "slice" and we want a copy of the slice
+    // (not the full underlying buffer).
+
+    var u8 = new Uint8Array(typedarray.length);
+    u8.set(typedarray);  // make a copy, ensuring there's no slice offset
+    return Duktape.Buffer(u8);  // get underlying plain buffer
+}
+
+function isObject(x) {
+    // Note that typeof null === 'object'.
+    return (typeof x === 'object' && x !== null);
+}
+
+function readFully(filename, cb) {
+    uv.fs_open(metadataFile, 'r', 0, function (handle, err) {
+        var fileOff = 0;
+        var data = new Uint8Array(256);
+        var dataOff = 0;
+
+        if (err) {
+            return cb(null, err);
+        }
+        function readCb(buf, err) {
+            var res;
+            var newData;
+
+            log.debug('Read callback:', buf.length, err);
+            if (err) {
+                uv.fs_close(handle);
+                return cb(null, err);
+            }
+            if (buf.length == 0) {
+                uv.fs_close(handle);
+                res = new Uint8Array(dataOff);
+                res.set(data.subarray(0, dataOff));
+                res = Duktape.Buffer(res);  // plain buffer
+                log.debug('Read', res.length, 'bytes from', filename);
+                return cb(res, null);
+            }
+            while (data.length - dataOff < buf.length) {
+                log.debug('Resize file read buffer:', data.length, '->', data.length * 2);
+                newData = new Uint8Array(data.length * 2);
+                newData.set(data);
+                data = newData;
+            }
+            data.set(new Uint8Array(buf), dataOff);
+            dataOff += buf.length;
+            fileOff += buf.length;
+            uv.fs_read(handle, 4096, fileOff, readCb);
+        }
+        uv.fs_read(handle, 4096, fileOff, readCb);
+    });
+}
+
+/*
+ *  JSON proxy server
+ *
+ *  Accepts an incoming JSON proxy client and connects to a debug target,
+ *  tying the two connections together.  Supports both a single connection
+ *  and a persistent mode.
+ */
+
+function JsonProxyServer(host, port) {
+    this.name = 'JsonProxyServer';
+    this.handle = uv.new_tcp();
+    uv.tcp_bind(this.handle, host, port);
+    uv.listen(this.handle, 128, this.onConnection.bind(this));
+}
+
+JsonProxyServer.prototype.onConnection = function onConnection(err) {
+    if (err) {
+        log.error('JSON proxy onConnection error:', err);
+        return;
+    }
+    log.info('JSON proxy client connected');  // XXX: it'd be nice to log remote peer host:port
+
+    var jsonSock = new JsonConnHandler(this);
+    var targSock = new TargetConnHandler(this);
+    jsonSock.targetHandler = targSock;
+    targSock.jsonHandler = jsonSock;
+    uv.accept(this.handle, jsonSock.handle);
+
+    log.info('Connecting to debug target at', targetHost + ':' + targetPort);
+    jsonSock.writeJson({ notify: '_TargetConnecting', args: [ targetHost, targetPort ] });
+    uv.tcp_connect(targSock.handle, targetHost, targetPort, targSock.onConnect.bind(targSock));
+
+    if (singleConnection) {
+        log.info('Single connection mode, stop listening for more connections');
+        uv.shutdown(this.handle);
+        uv.read_stop(this.handle);  // unnecessary but just in case
+        uv.close(this.handle);
+        this.handle = null;
+    }
+};
+
+JsonProxyServer.prototype.onProxyClientDisconnected = function onProxyClientDisconnected() {
+    // When this is invoked the proxy connection and the target connection
+    // have both been closed.
+    if (singleConnection) {
+        log.info('Proxy connection finished (single connection mode: we should be exiting now)');
+    } else {
+        log.info('Proxy connection finished (persistent mode: wait for more connections)');
+    }
+};
+
+/*
+ *  JSON connection handler
+ */
+
+function JsonConnHandler(server) {
+    var i, n;
+
+    this.name = 'JsonConnHandler';
+    this.server = server;
+    this.handle = uv.new_tcp();
+    this.incoming = new Uint8Array(4096);
+    this.incomingOffset = 0;
+    this.targetHandler = null;
+
+    this.commandNumberLookup = {};
+    if (metadata && metadata.target_commands) {
+        for (i = 0, n = metadata.target_commands.length; i < n; i++) {
+            this.commandNumberLookup[metadata.target_commands[i]] = i;
+        }
+    }
+}
+
+JsonConnHandler.prototype.finish = function finish(msg) {
+    var args;
+
+    if (!this.handle) {
+        log.info('JsonConnHandler already disconnected, ignore finish()');
+        return;
+    }
+    log.info('JsonConnHandler finished:', msg);
+    try {
+        args = msg ? [ msg ] : void 0;
+        this.writeJson({ notify: '_Disconnecting', args: args });
+    } catch (e) {
+        log.info('Failed to write _Disconnecting notify, ignoring:', e);
+    }
+    uv.shutdown(this.handle);
+    uv.read_stop(this.handle);
+    uv.close(this.handle);
+    this.handle = null;
+
+    this.targetHandler.finish(msg);  // disconnect target too (if not already disconnected)
+
+    this.server.onProxyClientDisconnected();
+};
+
+JsonConnHandler.prototype.onRead = function onRead(err, data) {
+    var newIncoming;
+    var msg;
+    var errmsg;
+    var tmpBuf;
+
+    log.trace('Received data from JSON socket, err:', err, 'data length:', data ? data.length : 'null');
+
+    if (err) {
+        errmsg = 'Error reading data from JSON debug client: ' + err;
+        this.finish(errmsg);
+        return;
+    }
+    if (data) {
+        // Feed the data one byte at a time when torture testing.
+        if (TORTURE && data.length > 1) {
+            for (var i = 0; i < data.length; i++) {
+                tmpBuf = Duktape.Buffer(1);
+                tmpBuf[0] = data[i];
+                this.onRead(null, tmpBuf);
+            }
+            return;
+        }
+
+        // Receive data into 'incoming', resizing as necessary.
+        while (data.length > this.incoming.length - this.incomingOffset) {
+            newIncoming = new Uint8Array(this.incoming.length * 1.3 + 16);
+            newIncoming.set(this.incoming);
+            this.incoming = newIncoming;
+            log.debug('Resize incoming JSON buffer to ' + this.incoming.length);
+        }
+        this.incoming.set(new Uint8Array(data), this.incomingOffset);
+        this.incomingOffset += data.length;
+
+        // Trial parse JSON message(s).
+        while (true) {
+            msg = this.trialParseJsonMessage();
+            if (!msg) {
+                break;
+            }
+            try {
+                this.dispatchJsonMessage(msg);
+            } catch (e) {
+                errmsg = 'JSON message dispatch failed: ' + e;
+                this.writeJson({ notify: '_Error', args: [ errmsg ] });
+                if (lenientJsonParse) {
+                    log.warn('JSON message dispatch failed (lenient mode, ignoring):', e);
+                } else {
+                    log.warn('JSON message dispatch failed (dropping connection):', e);
+                    this.finish(errmsg);
+                }
+            }
+        }
+    } else {
+        this.finish('JSON proxy client disconnected');
+    }
+};
+
+JsonConnHandler.prototype.writeJson = function writeJson(msg) {
+    log.info('PROXY --> CLIENT:', JSON.stringify(msg));
+    if (this.handle) {
+        uv.write(this.handle, JSON.stringify(msg) + '\n');
+    }
+};
+
+JsonConnHandler.prototype.handleDebugMessage = function handleDebugMessage(dvalues) {
+    var msg = {};
+    var idx = 0;
+    var cmd;
+
+    if (dvalues.length <= 0) {
+        throw new Error('invalid dvalues list: length <= 0');
+    }
+    var x = dvalues[idx++];
+    if (!isObject(x)) {
+        throw new Error('invalid initial dvalue: ' + Duktape.enc('jx', dvalues));
+    }
+    if (x.type === 'req') {
+        cmd = dvalues[idx++];
+        if (typeof cmd !== 'number') {
+            throw new Error('invalid command: ' + Duktape.enc('jx', cmd));
+        }
+        msg.request = this.determineCommandName(cmd) || true;
+        msg.command = cmd;
+    } else if (x.type === 'rep') {
+        msg.reply = true;
+    } else if (x.type === 'err') {
+        msg.error = true;
+    } else if (x.type === 'nfy') {
+        cmd = dvalues[idx++];
+        if (typeof cmd !== 'number') {
+            throw new Error('invalid command: ' + Duktape.enc('jx', cmd));
+        }
+        msg.notify = this.determineCommandName(cmd) || true;
+        msg.command = cmd;
+    } else {
+        throw new Error('invalid initial dvalue: ' + Duktape.enc('jx', dvalues));
+    }
+
+    for (; idx < dvalues.length - 1; idx++) {
+        if (!msg.args) {
+            msg.args = [];
+        }
+        msg.args.push(dvalues[idx]);
+    }
+
+    if (!isObject(dvalues[idx]) || dvalues[idx].type !== 'eom') {
+        throw new Error('invalid final dvalue: ' + Duktape.enc('jx', dvalues));
+    }
+
+    this.writeJson(msg);
+};
+
+JsonConnHandler.prototype.determineCommandName = function determineCommandName(cmd) {
+    if (!(metadata && metadata.client_commands)) {
+        return;
+    }
+    return metadata.client_commands[cmd];
+};
+
+JsonConnHandler.prototype.trialParseJsonMessage = function trialParseJsonMessage() {
+    var buf = this.incoming;
+    var avail = this.incomingOffset;
+    var i;
+    var msg, str, errmsg;
+
+    for (i = 0; i < avail; i++) {
+        if (buf[i] == 0x0a) {
+            str = String(plainBufferCopy(buf.subarray(0, i)));
+            try {
+                if (jxParse) {
+                    msg = Duktape.dec('jx', str);
+                } else {
+                    msg = JSON.parse(str);
+                }
+            } catch (e) {
+                // In lenient mode if JSON parse fails just send back an _Error
+                // and ignore the line (useful for initial development).
+                //
+                // In non-lenient mode drop the connection here; if the failed line
+                // was a request the client is expecting a reply/error message back
+                // (otherwise it may go out of sync) but we can't send a synthetic
+                // one (as we can't parse the request).
+                errmsg = 'JSON parse failed for: ' + JSON.stringify(str) + ': ' + e;
+                this.writeJson({ notify: '_Error', args: [ errmsg ] });
+                if (lenientJsonParse) {
+                    log.warn('JSON parse failed (lenient mode, ignoring):', e);
+                } else {
+                    log.warn('JSON parse failed (dropping connection):', e);
+                    this.finish(errmsg);
+                }
+            }
+
+            this.incoming.set(this.incoming.subarray(i + 1));
+            this.incomingOffset -= i + 1;
+            return msg;
+        }
+    }
+};
+
+JsonConnHandler.prototype.dispatchJsonMessage = function dispatchJsonMessage(msg) {
+    var cmd;
+    var dvalues = [];
+    var i, n;
+
+    log.info('PROXY <-- CLIENT:', JSON.stringify(msg));
+
+    // Parse message type, determine initial marker for binary message.
+    if (msg.request) {
+        cmd = this.determineCommandNumber(msg.request, msg.command);
+        dvalues.push(new Uint8Array([ 0x01 ]));
+        dvalues.push(this.encodeJsonDvalue(cmd));
+    } else if (msg.reply) {
+        dvalues.push(new Uint8Array([ 0x02 ]));
+    } else if (msg.notify) {
+        cmd = this.determineCommandNumber(msg.notify, msg.command);
+        dvalues.push(new Uint8Array([ 0x04 ]));
+        dvalues.push(this.encodeJsonDvalue(cmd));
+    } else if (msg.error) {
+        dvalues.push(new Uint8Array([ 0x03 ]));
+    } else {
+        throw new Error('invalid input JSON message: ' + JSON.stringify(msg));
+    }
+
+    // Encode arguments into dvalues.
+    for (i = 0, n = (msg.args ? msg.args.length : 0); i < n; i++) {
+        dvalues.push(this.encodeJsonDvalue(msg.args[i]));
+    }
+
+    // Add an EOM, and write out the dvalues to the debug target.
+    dvalues.push(new Uint8Array([ 0x00 ]));
+    for (i = 0, n = dvalues.length; i < n; i++) {
+        this.targetHandler.writeBinary(dvalues[i]);
+    }
+};
+
+JsonConnHandler.prototype.determineCommandNumber = function determineCommandNumber(name, val) {
+    var res;
+
+    if (typeof name === 'string') {
+        res = this.commandNumberLookup[name];
+        if (!res) {
+            log.info('Unknown command name: ' + name + ', command number: ' + val);
+        }
+    } else if (typeof name === 'number') {
+        res = name;
+    } else if (name !== true) {
+        throw new Error('invalid command name (must be string, number, or "true"): ' + name);
+    }
+    if (typeof res === 'undefined' && typeof val === 'undefined') {
+        throw new Error('cannot determine command number from name: ' + name);
+    }
+    if (typeof val !== 'number' && typeof val !== 'undefined') {
+        throw new Error('invalid command number: ' + val);
+    }
+    res = res || val;
+    return res;
+};
+
+JsonConnHandler.prototype.writeDebugStringToBuffer = function writeDebugStringToBuffer(v, buf, off) {
+    var i, n;
+
+    for (i = 0, n = v.length; i < n; i++) {
+        buf[off + i] = v.charCodeAt(i) & 0xff;  // truncate higher bits
+    }
+};
+
+JsonConnHandler.prototype.encodeJsonDvalue = function encodeJsonDvalue(v) {
+    var buf, dec, len, dv;
+
+    if (isObject(v)) {
+        if (v.type === 'eom') {
+            return new Uint8Array([ 0x00 ]);
+        } else if (v.type === 'req') {
+            return new Uint8Array([ 0x01 ]);
+        } else if (v.type === 'rep') {
+            return new Uint8Array([ 0x02 ]);
+        } else if (v.type === 'err') {
+            return new Uint8Array([ 0x03 ]);
+        } else if (v.type === 'nfy') {
+            return new Uint8Array([ 0x04 ]);
+        } else if (v.type === 'unused') {
+            return new Uint8Array([ 0x15 ]);
+        } else if (v.type === 'undefined') {
+            return new Uint8Array([ 0x16 ]);
+        } else if (v.type === 'number') {
+            dec = Duktape.dec('hex', v.data);
+            len = dec.length;
+            if (len !== 8) {
+                throw new TypeError('value cannot be converted to dvalue: ' + JSON.stringify(v));
+            }
+            buf = new Uint8Array(1 + len);
+            buf[0] = 0x1a;
+            buf.set(new Uint8Array(dec), 1);
+            return buf;
+        } else if (v.type === 'buffer') {
+            dec = Duktape.dec('hex', v.data);
+            len = dec.length;
+            if (len <= 0xffff) {
+                buf = new Uint8Array(3 + len);
+                buf[0] = 0x14;
+                buf[1] = (len >> 8) & 0xff;
+                buf[2] = (len >> 0) & 0xff;
+                buf.set(new Uint8Arrau(dec), 3);
+                return buf;
+            } else {
+                buf = new Uint8Array(5 + len);
+                buf[0] = 0x13;
+                buf[1] = (len >> 24) & 0xff;
+                buf[2] = (len >> 16) & 0xff;
+                buf[3] = (len >> 8) & 0xff;
+                buf[4] = (len >> 0) & 0xff;
+                buf.set(new Uint8Array(dec), 5);
+                return buf;
+            }
+        } else if (v.type === 'object') {
+            dec = Duktape.dec('hex', v.pointer);
+            len = dec.length;
+            buf = new Uint8Array(3 + len);
+            buf[0] = 0x1b;
+            buf[1] = v.class;
+            buf[2] = len;
+            buf.set(new Uint8Array(dec), 3);
+            return buf;
+        } else if (v.type === 'pointer') {
+            dec = Duktape.dec('hex', v.pointer);
+            len = dec.length;
+            buf = new Uint8Array(2 + len);
+            buf[0] = 0x1c;
+            buf[1] = len;
+            buf.set(new Uint8Array(dec), 2);
+            return buf;
+        } else if (v.type === 'lightfunc') {
+            dec = Duktape.dec('hex', v.pointer);
+            len = dec.length;
+            buf = new Uint8Array(4 + len);
+            buf[0] = 0x1d;
+            buf[1] = (v.flags >> 8) & 0xff;
+            buf[2] = v.flags & 0xff;
+            buf[3] = len;
+            buf.set(new Uint8Array(dec), 4);
+            return buf;
+        } else if (v.type === 'heapptr') {
+            dec = Duktape.dec('hex', v.pointer);
+            len = dec.length;
+            buf = new Uint8Array(2 + len);
+            buf[0] = 0x1e;
+            buf[1] = len;
+            buf.set(new Uint8Array(dec), 2);
+            return buf;
+        }
+    } else if (v === null) {
+        return new Uint8Array([ 0x17 ]);
+    } else if (typeof v === 'boolean') {
+        return new Uint8Array([ v ? 0x18 : 0x19 ]);
+    } else if (typeof v === 'number') {
+        if (Math.floor(v) === v &&     /* whole */
+            (v !== 0 || 1 / v > 0) &&  /* not negative zero */
+            v >= -0x80000000 && v <= 0x7fffffff) {
+            // Represented signed 32-bit integers as plain integers.
+            // Debugger code expects this for all fields that are not
+            // duk_tval representations (e.g. command numbers and such).
+            if (v >= 0x00 && v <= 0x3f) {
+                return new Uint8Array([ 0x80 + v ]);
+            } else if (v >= 0x0000 && v <= 0x3fff) {
+                return new Uint8Array([ 0xc0 + (v >> 8), v & 0xff ]);
+            } else if (v >= -0x80000000 && v <= 0x7fffffff) {
+                return new Uint8Array([ 0x10,
+                                    (v >> 24) & 0xff,
+                                    (v >> 16) & 0xff,
+                                    (v >> 8) & 0xff,
+                                    (v >> 0) & 0xff ]);
+            } else {
+                throw new Error('internal error when encoding integer to dvalue: ' + v);
+            }
+        } else {
+            // Represent non-integers as IEEE double dvalues.
+            buf = new Uint8Array(1 + 8);
+            buf[0] = 0x1a;
+            new DataView(buf).setFloat64(1, v, false);
+            return buf;
+        }
+    } else if (typeof v === 'string') {
+        if (v.length < 0 || v.length > 0xffffffff) {
+            // Not possible in practice.
+            throw new TypeError('cannot convert to dvalue, invalid string length: ' + v.length);
+        }
+        if (v.length <= 0x1f) {
+            buf = new Uint8Array(1 + v.length);
+            buf[0] = 0x60 + v.length;
+            this.writeDebugStringToBuffer(v, buf, 1);
+            return buf;
+        } else if (v.length <= 0xffff) {
+            buf = new Uint8Array(3 + v.length);
+            buf[0] = 0x12;
+            buf[1] = (v.length >> 8) & 0xff;
+            buf[2] = (v.length >> 0) & 0xff;
+            this.writeDebugStringToBuffer(v, buf, 3);
+            return buf;
+        } else {
+            buf = new Uint8Array(5 + v.length);
+            buf[0] = 0x11;
+            buf[1] = (v.length >> 24) & 0xff;
+            buf[2] = (v.length >> 16) & 0xff;
+            buf[3] = (v.length >> 8) & 0xff;
+            buf[4] = (v.length >> 0) & 0xff;
+            this.writeDebugStringToBuffer(v, buf, 5);
+            return buf;
+        }
+    }
+
+    throw new TypeError('value cannot be converted to dvalue: ' + JSON.stringify(v));
+};
+
+/*
+ *  Target binary connection handler
+ */
+
+function TargetConnHandler(server) {
+    this.name = 'TargetConnHandler';
+    this.server = server;
+    this.handle = uv.new_tcp();
+    this.jsonHandler = null;
+    this.incoming = new Uint8Array(4096);
+    this.incomingOffset = 0;
+    this.dvalues = [];
+}
+
+TargetConnHandler.prototype.finish = function finish(msg) {
+    if (!this.handle) {
+        log.info('TargetConnHandler already disconnected, ignore finish()');
+        return;
+    }
+    log.info('TargetConnHandler finished:', msg);
+
+    this.jsonHandler.writeJson({ notify: '_TargetDisconnected' });
+
+    // XXX: write a notify to target?
+
+    uv.shutdown(this.handle);
+    uv.read_stop(this.handle);
+    uv.close(this.handle);
+    this.handle = null;
+
+    this.jsonHandler.finish(msg);  // disconnect JSON client too (if not already disconnected)
+};
+
+TargetConnHandler.prototype.onConnect = function onConnect(err) {
+    var errmsg;
+
+    if (err) {
+        errmsg = 'Failed to connect to target: ' + err;
+        log.warn(errmsg);
+        this.jsonHandler.writeJson({ notify: '_Error', args: [ String(err) ] });
+        this.finish(errmsg);
+        return;
+    }
+
+    // Once we're connected to the target, start read both binary and JSON
+    // input.  We don't want to read JSON input before this so that we can
+    // always translate incoming messages to dvalues and write them out
+    // without queueing.  Any pending JSON messages will be queued by the
+    // OS instead.
+
+    log.info('Connected to debug target at', targetHost + ':' + targetPort);
+    uv.read_start(this.jsonHandler.handle, this.jsonHandler.onRead.bind(this.jsonHandler));
+    uv.read_start(this.handle, this.onRead.bind(this));
+};
+
+TargetConnHandler.prototype.writeBinary = function writeBinary(buf) {
+    var plain = plainBufferCopy(buf);
+    log.info('PROXY --> TARGET:', Duktape.enc('jx', plain));
+    if (this.handle) {
+        uv.write(this.handle, plain);
+    }
+};
+
+TargetConnHandler.prototype.onRead = function onRead(err, data) {
+    var res;
+    var errmsg;
+    var tmpBuf;
+    var newIncoming;
+
+    log.trace('Received data from target socket, err:', err, 'data length:', data ? data.length : 'null');
+
+    if (err) {
+        errmsg = 'Error reading data from debug target: ' + err;
+        this.finish(errmsg);
+        return;
+    }
+
+    if (data) {
+        // Feed the data one byte at a time when torture testing.
+        if (TORTURE && data.length > 1) {
+            for (var i = 0; i < data.length; i++) {
+                tmpBuf = Duktape.Buffer(1);
+                tmpBuf[0] = data[i];
+                this.onRead(null, tmpBuf);
+            }
+            return;
+        }
+
+        // Receive data into 'incoming', resizing as necessary.
+        while (data.length > this.incoming.length - this.incomingOffset) {
+            newIncoming = new Uint8Array(this.incoming.length * 1.3 + 16);
+            newIncoming.set(this.incoming);
+            this.incoming = newIncoming;
+            log.debug('Resize incoming binary buffer to ' + this.incoming.length);
+        }
+        this.incoming.set(new Uint8Array(data), this.incomingOffset);
+        this.incomingOffset += data.length;
+
+        // Trial parse handshake unless done.
+        if (!this.handshake) {
+            this.trialParseHandshake();
+        }
+
+        // Trial parse dvalue(s) and debug messages.
+        if (this.handshake) {
+            for (;;) {
+                res = this.trialParseDvalue();
+                if (!res) {
+                    break;
+                }
+                log.trace('Got dvalue:', Duktape.enc('jx', res.dvalue));
+                this.dvalues.push(res.dvalue);
+                if (isObject(res.dvalue) && res.dvalue.type === 'eom') {
+                    try {
+                        this.jsonHandler.handleDebugMessage(this.dvalues);
+                        this.dvalues = [];
+                    } catch (e) {
+                        errmsg = 'JSON message handling failed: ' + e;
+                        this.jsonHandler.writeJson({ notify: '_Error', args: [ errmsg ] });
+                        if (lenientJsonParse) {
+                            log.warn('JSON message handling failed (lenient mode, ignoring):', e);
+                        } else {
+                            log.warn('JSON message handling failed (dropping connection):', e);
+                            this.finish(errmsg);
+                        }
+                    }
+                }
+            }
+        }
+    } else {
+        log.info('Target disconnected');
+        this.finish('Target disconnected');
+    }
+};
+
+TargetConnHandler.prototype.trialParseHandshake = function trialParseHandshake() {
+    var buf = this.incoming;
+    var avail = this.incomingOffset;
+    var i;
+    var msg;
+    var m;
+    var protocolVersion;
+
+    for (i = 0; i < avail; i++) {
+        if (buf[i] == 0x0a) {
+            msg = String(plainBufferCopy(buf.subarray(0, i)));
+            this.incoming.set(this.incoming.subarray(i + 1));
+            this.incomingOffset -= i + 1;
+
+            // Generic handshake format: only relies on initial version field.
+            m = /^(\d+) (.*)$/.exec(msg) || {};
+            protocolVersion = +m[1];
+            this.handshake = {
+                line: msg,
+                protocolVersion: protocolVersion,
+                text: m[2]
+            };
+
+            // More detailed v1 handshake line.
+            if (protocolVersion === 1) {
+                m = /^(\d+) (\d+) (.*?) (.*?) (.*)$/.exec(msg) || {};
+                this.handshake.dukVersion = m[1];
+                this.handshake.dukGitDescribe = m[2];
+                this.handshake.targetString = m[3];
+            }
+
+            this.jsonHandler.writeJson({ notify: '_TargetConnected', args: [ msg ] });
+
+            log.info('Target handshake: ' + JSON.stringify(this.handshake));
+            return;
+        }
+    }
+};
+
+TargetConnHandler.prototype.bufferToDebugString = function bufferToDebugString(buf) {
+    return String.fromCharCode.apply(null, buf);
+};
+
+TargetConnHandler.prototype.trialParseDvalue = function trialParseDvalue() {
+    var _this = this;
+    var buf = this.incoming;
+    var avail = this.incomingOffset;
+    var v;
+    var gotValue = false;  // explicit flag for e.g. v === undefined
+    var dv = new DataView(buf);
+    var tmp;
+    var x;
+    var len;
+
+    function consume(n) {
+        log.info('PROXY <-- TARGET:', Duktape.enc('jx', _this.incoming.subarray(0, n)));
+        _this.incoming.set(_this.incoming.subarray(n));
+        _this.incomingOffset -= n;
+    }
+
+    x = buf[0];
+    if (avail <= 0) {
+        ;
+    } else if (x >= 0xc0) {
+        // 0xc0...0xff: integers 0-16383
+        if (avail >= 2) {
+            v = ((x - 0xc0) << 8) + buf[1];
+            consume(2);
+        }
+    } else if (x >= 0x80) {
+        // 0x80...0xbf: integers 0-63
+        v = x - 0x80;
+        consume(1);
+    } else if (x >= 0x60) {
+        // 0x60...0x7f: strings with length 0-31
+        len = x - 0x60;
+        if (avail >= 1 + len) {
+            v = new Uint8Array(len);
+            v.set(buf.subarray(1, 1 + len));
+            v = this.bufferToDebugString(v);
+            consume(1 + len);
+        }
+    } else {
+        switch (x) {
+        case 0x00: consume(1); v = { type: 'eom' }; break;
+        case 0x01: consume(1); v = { type: 'req' }; break;
+        case 0x02: consume(1); v = { type: 'rep' }; break;
+        case 0x03: consume(1); v = { type: 'err' }; break;
+        case 0x04: consume(1); v = { type: 'nfy' }; break;
+        case 0x10:  // 4-byte signed integer
+            if (avail >= 5) {
+                v = dv.getInt32(1, false);
+                consume(5);
+            }
+            break;
+        case 0x11:  // 4-byte string
+            if (avail >= 5) {
+                len = dv.getUint32(1, false);
+                if (avail >= 5 + len) {
+                    v = new Uint8Array(len);
+                    v.set(buf.subarray(5, 5 + len));
+                    v = this.bufferToDebugString(v);
+                    consume(5 + len);
+                }
+            }
+            break;
+        case 0x12:  // 2-byte string
+            if (avail >= 3) {
+                len = dv.getUint16(1, false);
+                if (avail >= 3 + len) {
+                    v = new Uint8Array(len);
+                    v.set(buf.subarray(3, 3 + len));
+                    v = this.bufferToDebugString(v);
+                    consume(3 + len);
+                }
+            }
+            break;
+        case 0x13:  // 4-byte buffer
+            if (avail >= 5) {
+                len = dv.getUint32(1, false);
+                if (avail >= 5 + len) {
+                    v = new Uint8Array(len);
+                    v.set(buf.subarray(5, 5 + len));
+                    v = { type: 'buffer', data: Duktape.enc('hex', Duktape.Buffer(v)) };
+                    consume(5 + len);
+                }
+            }
+            break;
+        case 0x14:  // 2-byte buffer
+            if (avail >= 3) {
+                len = dv.getUint16(1, false);
+                if (avail >= 3 + len) {
+                    v = new Uint8Array(len);
+                    v.set(buf.subarray(3, 3 + len));
+                    v = { type: 'buffer', data: Duktape.enc('hex', Duktape.Buffer(v)) };
+                    consume(3 + len);
+                }
+            }
+            break;
+        case 0x15:  // unused/none
+            v = { type: 'unused' };
+            consume(1);
+            break;
+        case 0x16:  // undefined
+            v = { type: 'undefined' };
+            gotValue = true;  // indicate 'v' is actually set
+            consume(1);
+            break;
+        case 0x17:  // null
+            v = null;
+            gotValue = true;  // indicate 'v' is actually set
+            consume(1);
+            break;
+        case 0x18:  // true
+            v = true;
+            consume(1);
+            break;
+        case 0x19:  // false
+            v = false;
+            consume(1);
+            break;
+        case 0x1a:  // number (IEEE double), big endian
+            if (avail >= 9) {
+                tmp = new Uint8Array(8);
+                tmp.set(buf.subarray(1, 9));
+                v = { type: 'number', data: Duktape.enc('hex', Duktape.Buffer(tmp)) };
+                if (readableNumberValue) {
+                    // The value key should not be used programmatically,
+                    // it is just there to make the dumps more readable.
+                    v.value = new DataView(tmp.buffer).getFloat64(0, false);
+                }
+                consume(9);
+            }
+            break;
+        case 0x1b:  // object
+            if (avail >= 3) {
+                len = buf[2];
+                if (avail >= 3 + len) {
+                    v = new Uint8Array(len);
+                    v.set(buf.subarray(3, 3 + len));
+                    v = { type: 'object', 'class': buf[1], pointer: Duktape.enc('hex', Duktape.Buffer(v)) };
+                    consume(3 + len);
+                }
+            }
+            break;
+        case 0x1c:  // pointer
+            if (avail >= 2) {
+                len = buf[1];
+                if (avail >= 2 + len) {
+                    v = new Uint8Array(len);
+                    v.set(buf.subarray(2, 2 + len));
+                    v = { type: 'pointer', pointer: Duktape.enc('hex', Duktape.Buffer(v)) };
+                    consume(2 + len);
+                }
+            }
+            break;
+        case 0x1d:  // lightfunc
+            if (avail >= 4) {
+                len = buf[3];
+                if (avail >= 4 + len) {
+                    v = new Uint8Array(len);
+                    v.set(buf.subarray(4, 4 + len));
+                    v = { type: 'lightfunc', flags: dv.getUint16(1, false), pointer: Duktape.enc('hex', Duktape.Buffer(v)) };
+                    consume(4 + len);
+                }
+            }
+            break;
+        case 0x1e:  // heapptr
+            if (avail >= 2) {
+                len = buf[1];
+                if (avail >= 2 + len) {
+                    v = new Uint8Array(len);
+                    v.set(buf.subarray(2, 2 + len));
+                    v = { type: 'heapptr', pointer: Duktape.enc('hex', Duktape.Buffer(v)) };
+                    consume(2 + len);
+                }
+            }
+            break;
+        default:
+            throw new Error('failed parse initial byte: ' + buf[0]);
+        }
+    }
+
+    if (typeof v !== 'undefined' || gotValue) {
+        return { dvalue: v };
+    }
+};
+
+/*
+ *  Main
+ */
+
+function main() {
+    var argv = typeof uv.argv === 'function' ? uv.argv() : [];
+    var i;
+    for (i = 2; i < argv.length; i++) {  // skip dukluv and script name
+        if (argv[i] == '--help') {
+            print('Usage: dukluv ' + argv[1] + ' [option]+');
+            print('');
+            print('    --server-host HOST    JSON proxy server listen address');
+            print('    --server-port PORT    JSON proxy server listen port');
+            print('    --target-host HOST    Debug target address');
+            print('    --target-port PORT    Debug target port');
+            print('    --metadata FILE       Proxy metadata file (usually named duk_debug_meta.json)');
+            print('    --log-level LEVEL     Set log level, default is 2; 0=trace, 1=debug, 2=info, 3=warn, etc');
+            print('    --single              Run a single proxy connection and exit (default: persist for multiple connections)');
+            print('    --readable-numbers    Add a non-programmatic "value" key for IEEE doubles help readability');
+            print('    --lenient             Ignore (with warning) invalid JSON without dropping connection');
+            print('    --jx-parse            Parse JSON proxy input with JX, useful when testing manually');
+            print('');
+            return;  // don't register any sockets/timers etc to exit
+        } else if (argv[i] == '--single') {
+            singleConnection = true;
+            continue;
+        } else if (argv[i] == '--readable-numbers') {
+            readableNumberValue = true;
+            continue;
+        } else if (argv[i] == '--lenient') {
+            lenientJsonParse = true;
+            continue;
+        } else if (argv[i] == '--jx-parse') {
+            jxParse = true;
+            continue;
+        }
+        if (i >= argv.length - 1) {
+            throw new Error('missing option value for ' + argv[i]);
+        }
+        if (argv[i] == '--server-host') {
+            serverHost = argv[i + 1];
+            i++;
+        } else if (argv[i] == '--server-port') {
+            serverPort = Math.floor(+argv[i + 1]);
+            i++;
+        } else if (argv[i] == '--target-host') {
+            targetHost = argv[i + 1];
+            i++;
+        } else if (argv[i] == '--target-port') {
+            targetPort = Math.floor(+argv[i + 1]);
+            i++;
+        } else if (argv[i] == '--metadata') {
+            metadataFile = argv[i + 1];
+            i++;
+        } else if (argv[i] == '--log-level') {
+            log.l = Math.floor(+argv[i + 1]);
+            i++;
+        } else {
+            throw new Error('invalid option ' + argv[i]);
+        }
+    }
+
+    function runServer() {
+        var serverSocket = new JsonProxyServer(serverHost, serverPort);
+        var connMode = singleConnection ? 'single connection mode' : 'persistent connection mode';
+        log.info('Listening for incoming JSON debug connection on ' + serverHost + ':' + serverPort +
+                 ', target is ' + targetHost + ':' + targetPort + ', ' + connMode);
+    }
+
+    if (metadataFile) {
+        log.info('Read proxy metadata from', metadataFile);
+        readFully(metadataFile, function (data, err) {
+            if (err) {
+                log.error('Failed to load metadata:', err);
+                throw err;
+            }
+            try {
+                metadata = JSON.parse(String(data));
+            } catch (e) {
+                log.error('Failed to parse JSON metadata from ' + metadataFile + ': ' + e);
+                throw e;
+            }
+            runServer();
+        });
+    } else {
+        runServer();
+    }
+}
+
+main();

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/debugger/duk_debugcommands.yaml
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/debugger/duk_debugcommands.yaml b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/debugger/duk_debugcommands.yaml
new file mode 100644
index 0000000..14555c1
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/debugger/duk_debugcommands.yaml
@@ -0,0 +1,52 @@
+# Debug request/notify command names provided by the debug client.
+# These are concretely notify names now.
+client_commands:
+  - Reserved_0
+  - Status
+  - Print
+  - Alert
+  - Log
+  - Throw
+  - Detaching
+  - AppNotify
+
+# Debug request/notify command names provided by the debug target (Duktape).
+target_commands:
+  - Reserved_0
+  - Reserved_1
+  - Reserved_2
+  - Reserved_3
+  - Reserved_4
+  - Reserved_5
+  - Reserved_6
+  - Reserved_7
+  - Reserved_8
+  - Reserved_9
+  - Reserved_10
+  - Reserved_11
+  - Reserved_12
+  - Reserved_13
+  - Reserved_14
+  - Reserved_15
+  - BasicInfo
+  - TriggerStatus
+  - Pause
+  - Resume
+  - StepInto
+  - StepOver
+  - StepOut
+  - ListBreak
+  - AddBreak
+  - DelBreak
+  - GetVar
+  - PutVar
+  - GetCallStack
+  - GetLocals
+  - Eval
+  - Detach
+  - DumpHeap
+  - GetBytecode
+  - AppRequest
+  - GetHeapObjInfo
+  - GetObjPropDesc
+  - GetObjPropDescRange

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/debugger/duk_debugerrors.yaml
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/debugger/duk_debugerrors.yaml b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/debugger/duk_debugerrors.yaml
new file mode 100644
index 0000000..500265f
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/debugger/duk_debugerrors.yaml
@@ -0,0 +1,6 @@
+error_codes:
+  - Unknown
+  - UnsupportedCommand
+  - TooMany
+  - NotFound
+  - ApplicationError

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/debugger/duk_opcodes.yaml
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/debugger/duk_opcodes.yaml b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/debugger/duk_opcodes.yaml
new file mode 100644
index 0000000..67dbefb
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/debugger/duk_opcodes.yaml
@@ -0,0 +1,658 @@
+# Duktape opcode metadata for debugger.
+# - See duk_debug.js for the argument formats (A_R etc).
+# - Flag bits are for the whole instruction as a 32-bit integer,
+#   they are not field shifted
+#
+# NOTE: Use YAML comments only on comment-only lines (not trailing content):
+# Node.js 'yamljs' seems to refuse parsing trailing comments in some cases.
+
+opcodes:
+  - name: LDREG
+    args:
+      - A_R
+      - BC_R
+  - name: STREG
+    args:
+      - A_R
+      - BC_R
+  - name: LDCONST
+    args:
+      - A_R
+      - BC_C
+  - name: LDINT
+    args:
+      - A_R
+      - BC_LDINT
+  - name: LDINTX
+    args:
+      - A_R
+      - BC_LDINTX
+  - name: MPUTOBJ
+    args:
+      - A_R
+      - B_R
+      - C_I
+  - name: MPUTOBJI
+    args:
+      - A_R
+      - B_RI
+      - C_I
+  - name: MPUTARR
+    args:
+      - A_R
+      - B_R
+      - C_I
+  - name: MPUTARRI
+    args:
+      - A_R
+      - B_RI
+      - C_I
+  - name: NEW
+    args:
+      - B_R
+      - C_I
+  - name: NEWI
+    args:
+      - B_RI
+      - C_I
+  - name: REGEXP
+    args:
+      - A_R
+      - B_RC
+      - C_RC
+  - name: CSREG
+    args:
+      - A_R
+      - B_R
+  - name: CSREGI
+    args:
+      - A_RI
+      - B_R
+  - name: GETVAR
+    args:
+      - A_R
+      - BC_C
+  - name: PUTVAR
+    args:
+      - A_R
+      - BC_C
+  - name: DECLVAR
+    args:
+      - A_H
+      - B_RC
+      - C_RC
+    flags:
+      - mask: 0x40
+        name: writable
+      - mask: 0x80
+        name: enumerable
+      - mask: 0x100
+        name: configurable
+      - mask: 0x200
+        name: accessor
+      - mask: 0x400
+        name: undef_value
+      - mask: 0x800
+        name: func_decl
+  - name: DELVAR
+    args:
+      - A_R
+      - B_RC
+  - name: CSVAR
+    args:
+      - A_R
+      - B_RC
+  - name: CSVARI
+    args:
+      - A_RI
+      - B_RC
+  - name: CLOSURE
+    args:
+      - A_R
+      - BC_I
+  - name: GETPROP
+    args:
+      - A_R
+      - B_RC
+      - C_RC
+  - name: PUTPROP
+    args:
+      - A_R
+      - B_RC
+      - C_RC
+  - name: DELPROP
+    args:
+      - A_R
+      - B_R
+      - C_RC
+  - name: CSPROP
+    args:
+      - A_R
+      - B_R
+      - C_RC
+  - name: CSPROPI
+    args:
+      - A_RI
+      - B_R
+      - C_RC
+  - name: ADD
+    args:
+      - A_R
+      - B_RC
+      - C_RC
+  - name: SUB
+    args:
+      - A_R
+      - B_RC
+      - C_RC
+  - name: MUL
+    args:
+      - A_R
+      - B_RC
+      - C_RC
+  - name: DIV
+    args:
+      - A_R
+      - B_RC
+      - C_RC
+  - name: MOD
+    args:
+      - A_R
+      - B_RC
+      - C_RC
+  - name: BAND
+    args:
+      - A_R
+      - B_RC
+      - C_RC
+  - name: BOR
+    args:
+      - A_R
+      - B_RC
+      - C_RC
+  - name: BXOR
+    args:
+      - A_R
+      - B_RC
+      - C_RC
+  - name: BASL
+    args:
+      - A_R
+      - B_RC
+      - C_RC
+  - name: BLSR
+    args:
+      - A_R
+      - B_RC
+      - C_RC
+  - name: BASR
+    args:
+      - A_R
+      - B_RC
+      - C_RC
+  - name: EQ
+    args:
+      - A_R
+      - B_RC
+      - C_RC
+  - name: NEQ
+    args:
+      - A_R
+      - B_RC
+      - C_RC
+  - name: SEQ
+    args:
+      - A_R
+      - B_RC
+      - C_RC
+  - name: SNEQ
+    args:
+      - A_R
+      - B_RC
+      - C_RC
+  - name: GT
+    args:
+      - A_R
+      - B_RC
+      - C_RC
+  - name: GE
+    args:
+      - A_R
+      - B_RC
+      - C_RC
+  - name: LT
+    args:
+      - A_R
+      - B_RC
+      - C_RC
+  - name: LE
+    args:
+      - A_R
+      - B_RC
+      - C_RC
+  - name: IF
+    args:
+      - A_B
+      - B_RC
+  - name: JUMP
+    args:
+      - ABC_JUMP
+  - name: RETURN
+    args:
+      - A_H
+      - B_RC
+    flags:
+      - mask: 0x40
+        name: have_retval
+  - name: CALL
+    args:
+      - A_H
+      - B_R
+      - C_I
+    flags:
+      - mask: 0x40
+        name: tailcall
+      - mask: 0x80
+        name: evalcall
+  - name: CALLI
+    args:
+      - A_H
+      - B_RI
+      - C_I
+  - name: TRYCATCH
+    args:
+      - A_H
+      # base register for two consecutive regs (base_reg + 0, base_reg + 1) used for two things:
+      # - input: either 'with' target register or catch varname constant (base_reg + 0), depending on flags
+      # - output: when caught, catch value (base_reg + 0) and type (base_reg + 1)
+      - BC_R
+    flags:
+      - mask: 0x40
+        name: have_catch
+      - mask: 0x80
+        name: have_finally
+      - mask: 0x100
+        name: catch_binding
+      - mask: 0x200
+        name: with_binding
+  - name: EXTRA
+    extra: true
+  - name: PREINCR
+    args:
+      - A_R
+      - BC_R
+  - name: PREDECR
+    args:
+      - A_R
+      - BC_R
+  - name: POSTINCR
+    args:
+      - A_R
+      - BC_R
+  - name: POSTDECR
+    args:
+      - A_R
+      - BC_R
+  - name: PREINCV
+    args:
+      - A_R
+      - BC_C
+  - name: PREDECV
+    args:
+      - A_R
+      - BC_C
+  - name: POSTINCV
+    args:
+      - A_R
+      - BC_C
+  - name: POSTDECV
+    args:
+      - A_R
+      - BC_C
+  - name: PREINCP
+    args:
+      - A_R
+      - B_RC
+      - C_RC
+  - name: PREDECP
+    args:
+      - A_R
+      - B_RC
+      - C_RC
+  - name: POSTINCP
+    args:
+      - A_R
+      - B_RC
+      - C_RC
+  - name: POSTDECP
+    args:
+      - A_R
+      - B_RC
+      - C_RC
+
+extra:
+  - name: NOP
+  - name: INVALID
+    args:
+      - BC_I
+  - name: LDTHIS
+    args:
+      - BC_R
+  - name: LDUNDEF
+    args:
+      - BC_R
+  - name: LDNULL
+    args:
+      - BC_R
+  - name: LDTRUE
+    args:
+      - BC_R
+  - name: LDFALSE
+    args:
+      - BC_R
+  - name: NEWOBJ
+    args:
+      # XXX: extend to BC?
+      - B_R
+  - name: NEWARR
+    args:
+      # XXX: extend to BC?
+      - B_R
+  - name: SETALEN
+    args:
+      - B_R
+      - C_R
+  - name: TYPEOF
+    args:
+      - BC_R
+  - name: TYPEOFID
+    args:
+      - B_R
+      # maybe changed to C_C later
+      - C_RC
+  - name: INITENUM
+    args:
+      - B_R
+      - C_R
+  - name: NEXTENUM
+    args:
+      - B_R
+      - C_R
+  - name: INITSET
+    args:
+      - B_R
+      - C_R
+  - name: INITSETI
+    args:
+      - B_R
+      - C_RI
+  - name: INITGET
+    args:
+      - B_R
+      - C_RI
+  - name: INITGETI
+    args:
+      - B_R
+      - C_RI
+  - name: ENDTRY
+  - name: ENDCATCH
+  - name: ENDFIN
+  - name: THROW
+    args:
+      - BC_R
+  - name: INVLHS
+  - name: UNM
+    args:
+      - BC_R
+  - name: UNP
+    args:
+      - BC_R
+  - name: DEBUGGER
+  - name: BREAK
+    args:
+      - BC_I
+  - name: CONTINUE
+    args:
+      - BC_I
+  - name: BNOT
+    args:
+      - BC_R
+  - name: LNOT
+    args:
+      - BC_R
+  - name: INSTOF
+    args:
+      - B_R
+      - C_RC
+  - name: IN
+    args:
+      - B_R
+      - C_RC
+  - name: LABEL
+    args:
+      - BC_I
+  - name: ENDLABEL
+    args:
+      - BC_I
+  - name: EXTRA34
+  - name: EXTRA35
+  - name: EXTRA36
+  - name: EXTRA37
+  - name: EXTRA38
+  - name: EXTRA39
+  - name: EXTRA40
+  - name: EXTRA41
+  - name: EXTRA42
+  - name: EXTRA43
+  - name: EXTRA44
+  - name: EXTRA45
+  - name: EXTRA46
+  - name: EXTRA47
+  - name: EXTRA48
+  - name: EXTRA49
+  - name: EXTRA50
+  - name: EXTRA51
+  - name: EXTRA52
+  - name: EXTRA53
+  - name: EXTRA54
+  - name: EXTRA55
+  - name: EXTRA56
+  - name: EXTRA57
+  - name: EXTRA58
+  - name: EXTRA59
+  - name: EXTRA60
+  - name: EXTRA61
+  - name: EXTRA62
+  - name: EXTRA63
+  - name: EXTRA64
+  - name: EXTRA65
+  - name: EXTRA66
+  - name: EXTRA67
+  - name: EXTRA68
+  - name: EXTRA69
+  - name: EXTRA70
+  - name: EXTRA71
+  - name: EXTRA72
+  - name: EXTRA73
+  - name: EXTRA74
+  - name: EXTRA75
+  - name: EXTRA76
+  - name: EXTRA77
+  - name: EXTRA78
+  - name: EXTRA79
+  - name: EXTRA80
+  - name: EXTRA81
+  - name: EXTRA82
+  - name: EXTRA83
+  - name: EXTRA84
+  - name: EXTRA85
+  - name: EXTRA86
+  - name: EXTRA87
+  - name: EXTRA88
+  - name: EXTRA89
+  - name: EXTRA90
+  - name: EXTRA91
+  - name: EXTRA92
+  - name: EXTRA93
+  - name: EXTRA94
+  - name: EXTRA95
+  - name: EXTRA96
+  - name: EXTRA97
+  - name: EXTRA98
+  - name: EXTRA99
+  - name: EXTRA100
+  - name: EXTRA101
+  - name: EXTRA102
+  - name: EXTRA103
+  - name: EXTRA104
+  - name: EXTRA105
+  - name: EXTRA106
+  - name: EXTRA107
+  - name: EXTRA108
+  - name: EXTRA109
+  - name: EXTRA110
+  - name: EXTRA111
+  - name: EXTRA112
+  - name: EXTRA113
+  - name: EXTRA114
+  - name: EXTRA115
+  - name: EXTRA116
+  - name: EXTRA117
+  - name: EXTRA118
+  - name: EXTRA119
+  - name: EXTRA120
+  - name: EXTRA121
+  - name: EXTRA122
+  - name: EXTRA123
+  - name: EXTRA124
+  - name: EXTRA125
+  - name: EXTRA126
+  - name: EXTRA127
+  - name: EXTRA128
+  - name: EXTRA129
+  - name: EXTRA130
+  - name: EXTRA131
+  - name: EXTRA132
+  - name: EXTRA133
+  - name: EXTRA134
+  - name: EXTRA135
+  - name: EXTRA136
+  - name: EXTRA137
+  - name: EXTRA138
+  - name: EXTRA139
+  - name: EXTRA140
+  - name: EXTRA141
+  - name: EXTRA142
+  - name: EXTRA143
+  - name: EXTRA144
+  - name: EXTRA145
+  - name: EXTRA146
+  - name: EXTRA147
+  - name: EXTRA148
+  - name: EXTRA149
+  - name: EXTRA150
+  - name: EXTRA151
+  - name: EXTRA152
+  - name: EXTRA153
+  - name: EXTRA154
+  - name: EXTRA155
+  - name: EXTRA156
+  - name: EXTRA157
+  - name: EXTRA158
+  - name: EXTRA159
+  - name: EXTRA160
+  - name: EXTRA161
+  - name: EXTRA162
+  - name: EXTRA163
+  - name: EXTRA164
+  - name: EXTRA165
+  - name: EXTRA166
+  - name: EXTRA167
+  - name: EXTRA168
+  - name: EXTRA169
+  - name: EXTRA170
+  - name: EXTRA171
+  - name: EXTRA172
+  - name: EXTRA173
+  - name: EXTRA174
+  - name: EXTRA175
+  - name: EXTRA176
+  - name: EXTRA177
+  - name: EXTRA178
+  - name: EXTRA179
+  - name: EXTRA180
+  - name: EXTRA181
+  - name: EXTRA182
+  - name: EXTRA183
+  - name: EXTRA184
+  - name: EXTRA185
+  - name: EXTRA186
+  - name: EXTRA187
+  - name: EXTRA188
+  - name: EXTRA189
+  - name: EXTRA190
+  - name: EXTRA191
+  - name: EXTRA192
+  - name: EXTRA193
+  - name: EXTRA194
+  - name: EXTRA195
+  - name: EXTRA196
+  - name: EXTRA197
+  - name: EXTRA198
+  - name: EXTRA199
+  - name: EXTRA200
+  - name: EXTRA201
+  - name: EXTRA202
+  - name: EXTRA203
+  - name: EXTRA204
+  - name: EXTRA205
+  - name: EXTRA206
+  - name: EXTRA207
+  - name: EXTRA208
+  - name: EXTRA209
+  - name: EXTRA210
+  - name: EXTRA211
+  - name: EXTRA212
+  - name: EXTRA213
+  - name: EXTRA214
+  - name: EXTRA215
+  - name: EXTRA216
+  - name: EXTRA217
+  - name: EXTRA218
+  - name: EXTRA219
+  - name: EXTRA220
+  - name: EXTRA221
+  - name: EXTRA222
+  - name: EXTRA223
+  - name: EXTRA224
+  - name: EXTRA225
+  - name: EXTRA226
+  - name: EXTRA227
+  - name: EXTRA228
+  - name: EXTRA229
+  - name: EXTRA230
+  - name: EXTRA231
+  - name: EXTRA232
+  - name: EXTRA233
+  - name: EXTRA234
+  - name: EXTRA235
+  - name: EXTRA236
+  - name: EXTRA237
+  - name: EXTRA238
+  - name: EXTRA239
+  - name: EXTRA240
+  - name: EXTRA241
+  - name: EXTRA242
+  - name: EXTRA243
+  - name: EXTRA244
+  - name: EXTRA245
+  - name: EXTRA246
+  - name: EXTRA247
+  - name: EXTRA248
+  - name: EXTRA249
+  - name: EXTRA250
+  - name: EXTRA251
+  - name: EXTRA252
+  - name: EXTRA253
+  - name: EXTRA254
+  - name: EXTRA255

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/debugger/merge_debug_meta.py
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/debugger/merge_debug_meta.py b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/debugger/merge_debug_meta.py
new file mode 100644
index 0000000..ba9b38e
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/debugger/merge_debug_meta.py
@@ -0,0 +1,32 @@
+#!/usr/bin/env python2
+#
+#  Merge debugger YAML metadata files and output a merged JSON metadata file.
+#
+
+import os, sys, json, yaml
+import optparse
+
+if __name__ == '__main__':
+	parser = optparse.OptionParser()
+	parser.add_option('--output', dest='output', default=None, help='output JSON filename')
+	parser.add_option('--class-names', dest='class_names', help='YAML metadata for class names')
+	parser.add_option('--debug-commands', dest='debug_commands', help='YAML metadata for debug commands')
+	parser.add_option('--debug-errors', dest='debug_errors', help='YAML metadata for debug protocol error codes')
+	parser.add_option('--opcodes', dest='opcodes', help='YAML metadata for opcodes')
+	(opts, args) = parser.parse_args()
+
+	res = {}
+	def merge(fn):
+		with open(fn, 'rb') as f:
+			doc = yaml.load(f)
+		for k in doc.keys():
+			res[k] = doc[k]
+
+	merge(opts.class_names)
+	merge(opts.debug_commands)
+	merge(opts.debug_errors)
+	merge(opts.opcodes)
+
+	with open(opts.output, 'wb') as f:
+		f.write(json.dumps(res, indent=4) + '\n')
+	print('Wrote merged debugger metadata to ' + str(opts.output))

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/debugger/package.json
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/debugger/package.json b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/debugger/package.json
new file mode 100644
index 0000000..9616574
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/debugger/package.json
@@ -0,0 +1,27 @@
+{
+  "name": "duk-debug",
+  "version": "0.1.0",
+  "description": "Duktape debugger",
+  "author": {
+    "name": "Sami Vaarala",
+    "email": "sami.vaarala@iki.fi"
+  },
+  "dependencies": {
+    "bluebird": "~2.6.4",
+    "minimist": "~1.1.0",
+    "express": "~4.10.1",
+    "body-parser": "~1.9.3",
+    "socket.io": "~1.2.1",
+    "utf8": "~2.0.0",
+    "wrench": "~1.5.8",
+    "sprintf": "~0.1.5",
+    "events": "~1.0.2",
+    "stream": "0.0.2",
+    "readline": "0.0.5",
+    "util": "~0.10.3",
+    "http": "0.0.0",
+    "yamljs": "~0.2.1",
+    "byline": "~4.2.1"
+  },
+  "main": "duk_debug.js"
+}

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/debugger/static/index.html
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/debugger/static/index.html b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/debugger/static/index.html
new file mode 100644
index 0000000..5e5e2e0
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/debugger/static/index.html
@@ -0,0 +1,96 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8" />
+<link rel="stylesheet" href="reset.css" type="text/css" />
+<link rel="stylesheet" href="jquery-ui.min.css" type="text/css" />
+<link rel="stylesheet" href="style.css" type="text/css" />
+<title>Duktape debugger</title>
+</head>
+<body>
+
+<div id="part-header">
+((o) Duktape debugger
+</div>  <!-- #part-header -->
+
+<div id="part-middle">
+
+<div id="left-area">
+<button id="stepinto-button">Step&#x00a0;into</button>
+<button id="stepover-button">Step&#x00a0;over</button>
+<button id="stepout-button">Step&#x00a0;out</button>
+<button id="resume-button">Resume</button>
+<button id="pause-button">Pause</button>
+<br />
+<br />
+<br />
+<br />
+<button id="attach-button">Attach</button>
+<button id="detach-button">Detach</button>
+<button id="about-button">About</button>
+<button id="heap-dump-download-button"><a id="heap-dump-download" href="/heapDump.json" target="_blank">Dump&#x00a0;heap</a></button>
+<button id="show-bytecode-button">Show bytecode</button>
+</div>  <!-- #left-area -->
+
+<div id="center-area">
+<pre id="source-pre" class="sourcecode"><code id="source-code" class="sourcecode">
+// No source loaded
+</code></pre>
+<div>
+<select id="source-select"></select><br />
+<!-- <span id="source-filename">?</span> -->
+</div>
+<div id="exec-status">
+<div id="exec-state"><span id="current-state">?</span></div>
+<div id="exec-other"><span id="current-fileline">?</span><br /><span id="current-funcpc">?</span></div>
+</div>  <!-- #exec-status -->
+<div id="output">
+<div style="color: #dddddd">(output from script, print() and alert() calls)</div>
+</div>
+</div>  <!-- #center-area -->
+
+<div id="right-area">
+<div id="callstack">
+<div style="color: #dddddd">(callstack)</div>
+</div>
+<div id="locals">
+<div style="color: #dddddd">(locals)</div>
+</div>
+<div id="breakpoints">
+<div style="color: #dddddd">(breakpoints)</div>
+</div>
+<div id="eval">
+<input id="eval-input" value="print('hello world'); 1+2" /><button id="eval-button">Eval</button><input id="eval-watch" type="checkbox" />&#xa0;watch (eval on pause)
+<div id="eval-output"></div>
+<button id="putvar-button">PutVar</button><button id="getvar-button">GetVar</button><input id="varname-input" value="varname" /><input id="varvalue-input" value="varvalue" />
+<div id="var-output"></div>
+</div>
+</div>  <!-- #right-area -->
+
+</div>  <!-- #part-middle -->
+
+<div id="part-footer">
+<div>DUK_VERSION: <span id="duk-version">?</span>, DUK_GIT_DESCRIBE: <span id="duk-git-describe">?</span>, Target info: <span id="target-info">?</span>, Endianness: <span id="endianness">?</span><br />
+Debug protocol stats:
+recv <span id="debug-rx-bytes">?</span> (<span id="debug-rx-kbrate">?</span> kB/s), <span id="debug-rx-dvalues">?</span> dvalues, <span id="debug-rx-messages">?</span> messages;
+send <span id="debug-tx-bytes">?</span> (<span id="debug-tx-kbrate">?</span> kB/s), <span id="debug-tx-dvalues">?</span> dvalues, <span id="debug-tx-messages">?</span> messages
+</div>
+</div>  <!-- #part-footer -->
+
+<div id="about-dialog" title="About Duktape debugger">
+<p>Duktape debugger is a web UI for debugging Ecmascript on a target device.</p>
+<p>This web UI talks to a NodeJS debug server using <a href="http://socket.io/" target="_blank">socket.io</a>.
+The debug server talks to the target device using the Duktape debug protocol
+(see <a href="https://github.com/svaarala/duktape/blob/master/doc/debugger.rst" target="_blank">debugger.rst</a>).</p>
+</div>  <!-- #about-dialog -->
+
+<div id="bytecode-dialog" title="Bytecode for current function">
+<pre id="bytecode-preformatted"></pre>
+</div>
+
+<script src="jquery-1.11.1.min.js" type="text/javascript"></script>
+<script src="jquery-ui.min.js" type="text/javascript"></script>
+<script src="socket.io-1.2.0.js" type="text/javascript"></script>
+<script src="webui.js" type="text/javascript"></script>
+</body>
+</html>


[26/51] [partial] nifi-minifi-cpp git commit: MINIFI-183 Added civet 1.9.1 sources Added onScheduled hook Added initial two-way TLS-enabled ListenHTTP implementation

Posted by al...@apache.org.
http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/cpp-exceptions/README.rst
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/cpp-exceptions/README.rst b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/cpp-exceptions/README.rst
new file mode 100644
index 0000000..bbc26a0
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/cpp-exceptions/README.rst
@@ -0,0 +1,29 @@
+=========================================
+C++ exceptions for long control transfers
+=========================================
+
+Normally Duktape uses ``setjmp()`` / ``longjmp()`` or their variants for
+internal long control transfers.  One downside of these functions is that
+C++ automatic destructors (scope-based resource management, SBRM, a special
+case of RAII) in Duktape/C functions won't be executed which is awkward for
+C++ programmers.
+
+When ``DUK_USE_CPP_EXCEPTIONS`` (``DUK_OPT_CPP_EXCEPTIONS``) is defined, and
+both Duktape and application code is compiled using a C++ compiler, Duktape
+uses C++ ``try-catch`` and ``throw`` for internal long control transfers.
+This allows automatic destructors to run as expected.  The config option is
+not enabled by default because C++ exceptions are sometimes disabled even
+when a C++ compiler is used (e.g. for performance reasons).
+
+The ``cpp_exceptions.cpp`` example illustrates how C++ exceptions can be
+used in Duktape/C functions at the moment:
+
+* Duktape uses C++ try/catch/throw internally; this is not visible to user
+  code directly.
+
+* Automatic destructors (scope-based resource management) work as expected.
+
+* C++ exceptions can be used in Duktape/C functions normally, but user
+  exceptions must be caught before they reach Duktape.  If this is not
+  done, such exceptions are caught by Duktape and converted to API errors
+  (in other words, they won't propagate "through" Duktape at the moment).

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/cpp-exceptions/cpp_exceptions.cpp
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/cpp-exceptions/cpp_exceptions.cpp b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/cpp-exceptions/cpp_exceptions.cpp
new file mode 100644
index 0000000..6fb3194
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/cpp-exceptions/cpp_exceptions.cpp
@@ -0,0 +1,274 @@
+/*
+ *  Example of how to use DUK_USE_CPP_EXCEPTIONS to support automatic
+ *  variables (e.g. destructor calls) in Duktape/C functions.
+ *
+ *  Compile with -DDUK_OPT_CPP_EXCEPTIONS:
+ *
+ *    $ g++ -otest -DDUK_OPT_CPP_EXCEPTIONS -I<duktape_dist>/src/ \
+ *      <duktape_dist>/src/duktape.c cpp_exceptions.cpp -lm
+ *
+ *  or ensure duk_config.h has DUK_USE_CPP_EXCEPTIONS enabled using
+ *  genconfig.  When executed you should see something like:
+ *
+ *    $ ./test
+ *    my_class instance created
+ *    my_class instance destroyed      <== destructor gets called
+ *    --> rc=1 (SyntaxError: parse error (line 1))
+ *    [...]
+ *
+ *  Duktape uses a custom exception class (duk_internal_exception) which
+ *  doesn't inherit from any base class, so that catching any base classes
+ *  in user code won't accidentally catch exceptions thrown by Duktape.
+ */
+
+#if !defined(__cplusplus)
+#error compile using a c++ compiler
+#endif
+
+#include <stdio.h>
+#include <exception>
+#include "duktape.h"
+
+#if defined(__cplusplus) && (__cplusplus >= 201103L)
+#define NOEXCEPT noexcept
+#else
+#define NOEXCEPT throw()
+#endif
+
+/*
+ *  Example class with a destructor
+ */
+
+class my_class {
+ public:
+	my_class();
+	~my_class();
+};
+
+my_class::my_class() {
+	printf("my_class instance created\n");
+}
+
+my_class::~my_class() {
+	printf("my_class instance destroyed\n");
+}
+
+/*
+ *  SyntaxError caused by eval exits Duktape/C function but destructors
+ *  are executed.
+ */
+
+duk_ret_t test1(duk_context *ctx) {
+	my_class myclass;
+
+	duk_eval_string(ctx, "aiee=");
+
+	return 0;
+}
+
+/*
+ *  You can use C++ exceptions inside Duktape/C functions for your own
+ *  purposes but you should catch them before they propagate to Duktape.
+ */
+
+duk_ret_t test2(duk_context *ctx) {
+	my_class myclass;
+
+	try {
+		throw 123;
+	} catch (int myvalue) {
+		printf("Caught: %d\n", myvalue);
+	}
+
+	return 0;
+}
+
+/*
+ *  If you let your own C++ exceptions propagate out of a Duktape/C function
+ *  it will be caught by Duktape and considered a programming error.  Duktape
+ *  will catch the exception and convert it to a Duktape error.
+ *
+ *  This may be allowed in a later version once all the implications have been
+ *  worked out.
+ */
+
+duk_ret_t test3(duk_context *ctx) {
+	my_class myclass;
+
+	throw 123;  /* ERROR: exception propagated to Duktape */
+
+	return 0;
+}
+
+/*
+ *  Same as above, but if the exception inherits from std::exception, it's
+ *  "what()" will be included in the error message.
+ */
+
+class my_exception : public std::exception {
+	virtual const char *what() const NOEXCEPT {
+		return "my_exception";
+	}
+};
+
+duk_ret_t test4(duk_context *ctx) {
+	my_class myclass;
+	my_exception myexc;
+
+	throw myexc;  /* ERROR: exception propagated to Duktape */
+
+	return 0;
+}
+
+/*
+ *  Same as above, but if the exception inherits from std::exception with
+ *  a NULL what().  Duktape will describe the error as 'unknown' if so.
+ */
+
+class my_exception2 : public std::exception {
+	virtual const char *what() const NOEXCEPT {
+		return NULL;
+	}
+};
+
+duk_ret_t test5(duk_context *ctx) {
+	my_class myclass;
+	my_exception2 myexc;
+
+	throw myexc;  /* ERROR: exception propagated to Duktape */
+
+	return 0;
+}
+
+int main(int argc, char *argv[]) {
+	duk_context *ctx = duk_create_heap_default();
+	duk_int_t rc;
+
+	(void) argc; (void) argv;  /* suppress warning */
+
+	printf("*** test1 - duk_pcall()\n");
+	duk_push_c_function(ctx, test1, 0);
+	rc = duk_pcall(ctx, 0);
+	printf("--> rc=%ld (%s)\n", (long) rc, duk_safe_to_string(ctx, -1));
+	duk_pop(ctx);
+	printf("\n");
+
+	printf("*** test1 - duk_safe_call()\n");
+	rc = duk_safe_call(ctx, test1, 0, 1);
+	printf("--> rc=%ld (%s)\n", (long) rc, duk_safe_to_string(ctx, -1));
+	duk_pop(ctx);
+	printf("\n");
+
+	printf("*** test1 - ecmascript try-catch\n");
+	duk_push_c_function(ctx, test1, 0);
+	duk_put_global_string(ctx, "test1");
+	duk_eval_string_noresult(ctx,
+		"try {\n"
+		"    test1();\n"
+		"} catch (e) {\n"
+		"    print(e.stack || e);\n"
+		"}\n");
+	printf("\n");
+
+	printf("*** test2 - duk_pcall()\n");
+	duk_push_c_function(ctx, test2, 0);
+	rc = duk_pcall(ctx, 0);
+	printf("--> rc=%ld (%s)\n", (long) rc, duk_safe_to_string(ctx, -1));
+	duk_pop(ctx);
+	printf("\n");
+
+	printf("*** test2 - duk_safe_call()\n");
+	rc = duk_safe_call(ctx, test2, 0, 1);
+	printf("--> rc=%ld (%s)\n", (long) rc, duk_safe_to_string(ctx, -1));
+	duk_pop(ctx);
+	printf("\n");
+
+	printf("*** test2 - ecmascript try-catch\n");
+	duk_push_c_function(ctx, test2, 0);
+	duk_put_global_string(ctx, "test2");
+	duk_eval_string_noresult(ctx,
+		"try {\n"
+		"    test2();\n"
+		"} catch (e) {\n"
+		"    print(e.stack || e);\n"
+		"}\n");
+	printf("\n");
+
+	printf("*** test3 - duk_pcall()\n");
+	duk_push_c_function(ctx, test3, 0);
+	rc = duk_pcall(ctx, 0);
+	printf("--> rc=%ld (%s)\n", (long) rc, duk_safe_to_string(ctx, -1));
+	duk_pop(ctx);
+	printf("\n");
+
+	printf("*** test3 - duk_safe_call()\n");
+	rc = duk_safe_call(ctx, test3, 0, 1);
+	printf("--> rc=%ld (%s)\n", (long) rc, duk_safe_to_string(ctx, -1));
+	duk_pop(ctx);
+	printf("\n");
+
+	printf("*** test3 - ecmascript try-catch\n");
+	duk_push_c_function(ctx, test3, 0);
+	duk_put_global_string(ctx, "test3");
+	duk_eval_string_noresult(ctx,
+		"try {\n"
+		"    test3();\n"
+		"} catch (e) {\n"
+		"    print(e.stack || e);\n"
+		"}\n");
+	printf("\n");
+
+	printf("*** test4 - duk_pcall()\n");
+	duk_push_c_function(ctx, test4, 0);
+	rc = duk_pcall(ctx, 0);
+	printf("--> rc=%ld (%s)\n", (long) rc, duk_safe_to_string(ctx, -1));
+	duk_pop(ctx);
+	printf("\n");
+
+	printf("*** test4 - duk_safe_call()\n");
+	rc = duk_safe_call(ctx, test4, 0, 1);
+	printf("--> rc=%ld (%s)\n", (long) rc, duk_safe_to_string(ctx, -1));
+	duk_pop(ctx);
+	printf("\n");
+
+	printf("*** test4 - ecmascript try-catch\n");
+	duk_push_c_function(ctx, test4, 0);
+	duk_put_global_string(ctx, "test4");
+	duk_eval_string_noresult(ctx,
+		"try {\n"
+		"    test4();\n"
+		"} catch (e) {\n"
+		"    print(e.stack || e);\n"
+		"}\n");
+	printf("\n");
+
+	printf("*** test5 - duk_pcall()\n");
+	duk_push_c_function(ctx, test5, 0);
+	rc = duk_pcall(ctx, 0);
+	printf("--> rc=%ld (%s)\n", (long) rc, duk_safe_to_string(ctx, -1));
+	duk_pop(ctx);
+	printf("\n");
+
+	printf("*** test5 - duk_safe_call()\n");
+	rc = duk_safe_call(ctx, test5, 0, 1);
+	printf("--> rc=%ld (%s)\n", (long) rc, duk_safe_to_string(ctx, -1));
+	duk_pop(ctx);
+	printf("\n");
+
+	printf("*** test5 - ecmascript try-catch\n");
+	duk_push_c_function(ctx, test5, 0);
+	duk_put_global_string(ctx, "test5");
+	duk_eval_string_noresult(ctx,
+		"try {\n"
+		"    test5();\n"
+		"} catch (e) {\n"
+		"    print(e.stack || e);\n"
+		"}\n");
+	printf("\n");
+
+	printf("*** done\n");
+
+	duk_destroy_heap(ctx);
+
+	return 0;
+}

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/debug-trans-dvalue/README.rst
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/debug-trans-dvalue/README.rst b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/debug-trans-dvalue/README.rst
new file mode 100644
index 0000000..86b2bb5
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/debug-trans-dvalue/README.rst
@@ -0,0 +1,8 @@
+===========================================================
+Debug transport with local debug protocol encoding/decoding
+===========================================================
+
+This example implements a debug transport which decodes/encodes the Duktape
+debug protocol locally into a more easy to use C interface, which is useful
+for debug clients implemented locally on the target.  The example also
+demonstrates how to trial parse dvalues in C.

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/debug-trans-dvalue/duk_trans_dvalue.c
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/debug-trans-dvalue/duk_trans_dvalue.c b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/debug-trans-dvalue/duk_trans_dvalue.c
new file mode 100644
index 0000000..8470a5f
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/debug-trans-dvalue/duk_trans_dvalue.c
@@ -0,0 +1,1239 @@
+/*
+ *  Example debug transport with a local debug message encoder/decoder.
+ *
+ *  Provides a "received dvalue" callback for a fully parsed dvalue (user
+ *  code frees dvalue) and a "cooperate" callback for e.g. UI integration.
+ *  There are a few other callbacks.  See test.c for usage examples.
+ *
+ *  This transport implementation is not multithreaded which means that:
+ *
+ *    - Callbacks to "received dvalue" callback come from the Duktape thread,
+ *      either during normal execution or from duk_debugger_cooperate().
+ *
+ *    - Calls into duk_trans_dvalue_send() must be made from the callbacks
+ *      provided (e.g. "received dvalue" or "cooperate") which use the active
+ *      Duktape thread.
+ *
+ *    - The only exception to this is when Duktape is idle: you can then call
+ *      duk_trans_dvalue_send() from any thread (only one thread at a time).
+ *      When you next call into Duktape or call duk_debugger_cooperate(), the
+ *      queued data will be read and processed by Duktape.
+ *
+ *  There are functions for creating and freeing values; internally they use
+ *  malloc() and free() for memory management.  Duktape heap alloc functions
+ *  are not used to minimize disturbances to the Duktape heap under debugging.
+ *
+ *  Doesn't depend on C99 types; assumes "int" is at least 32 bits, and makes
+ *  a few assumptions about format specifiers.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "duktape.h"
+#include "duk_trans_dvalue.h"
+
+/* Define to enable debug prints to stderr. */
+#if 0
+#define DEBUG_PRINTS
+#endif
+
+/* Define to enable error prints to stderr. */
+#if 1
+#define ERROR_PRINTS
+#endif
+
+/*
+ *  Dvalue handling
+ */
+
+duk_dvalue *duk_dvalue_alloc(void) {
+	duk_dvalue *dv = (duk_dvalue *) malloc(sizeof(duk_dvalue));
+	if (dv) {
+		memset((void *) dv, 0, sizeof(duk_dvalue));
+		dv->buf = NULL;
+	}
+	return dv;
+}
+
+void duk_dvalue_free(duk_dvalue *dv) {
+	if (dv) {
+		free(dv->buf);  /* tolerates NULL */
+		dv->buf = NULL;
+		free(dv);
+	}
+}
+
+static void duk__dvalue_bufesc(duk_dvalue *dv, char *buf, size_t maxbytes, int stresc) {
+	size_t i, limit;
+
+	*buf = (char) 0;
+	limit = dv->len > maxbytes ? maxbytes : dv->len;
+	for (i = 0; i < limit; i++) {
+		unsigned char c = dv->buf[i];
+		if (stresc) {
+			if (c >= 0x20 && c <= 0x7e && c != (char) '"' && c != (char) '\'') {
+				sprintf(buf, "%c", c);
+				buf++;
+			} else {
+				sprintf(buf, "\\x%02x", (unsigned int) c);
+				buf += 4;
+			}
+		} else {
+			sprintf(buf, "%02x", (unsigned int) c);
+			buf += 2;
+		}
+	}
+	if (dv->len > maxbytes) {
+		sprintf(buf, "...");
+		buf += 3;
+	}
+}
+
+/* Caller must provide a buffer at least DUK_DVALUE_TOSTRING_BUFLEN in size. */
+void duk_dvalue_to_string(duk_dvalue *dv, char *buf) {
+	char hexbuf[32 * 4 + 4];  /* 32 hex encoded or \xXX escaped bytes, possible "...", NUL */
+
+	if (!dv) {
+		sprintf(buf, "NULL");
+		return;
+	}
+
+	switch (dv->tag) {
+	case DUK_DVALUE_EOM:
+		sprintf(buf, "EOM");
+		break;
+	case DUK_DVALUE_REQ:
+		sprintf(buf, "REQ");
+		break;
+	case DUK_DVALUE_REP:
+		sprintf(buf, "REP");
+		break;
+	case DUK_DVALUE_ERR:
+		sprintf(buf, "ERR");
+		break;
+	case DUK_DVALUE_NFY:
+		sprintf(buf, "NFY");
+		break;
+	case DUK_DVALUE_INTEGER:
+		sprintf(buf, "%d", dv->i);
+		break;
+	case DUK_DVALUE_STRING:
+		duk__dvalue_bufesc(dv, hexbuf, 32, 1);
+		sprintf(buf, "str:%ld:\"%s\"", (long) dv->len, hexbuf);
+		break;
+	case DUK_DVALUE_BUFFER:
+		duk__dvalue_bufesc(dv, hexbuf, 32, 0);
+		sprintf(buf, "buf:%ld:%s", (long) dv->len, hexbuf);
+		break;
+	case DUK_DVALUE_UNUSED:
+		sprintf(buf, "undefined");
+		break;
+	case DUK_DVALUE_UNDEFINED:
+		sprintf(buf, "undefined");
+		break;
+	case DUK_DVALUE_NULL:
+		sprintf(buf, "null");
+		break;
+	case DUK_DVALUE_TRUE:
+		sprintf(buf, "true");
+		break;
+	case DUK_DVALUE_FALSE:
+		sprintf(buf, "false");
+		break;
+	case DUK_DVALUE_NUMBER:
+		if (fpclassify(dv->d) == FP_ZERO) {
+			if (signbit(dv->d)) {
+				sprintf(buf, "-0");
+			} else {
+				sprintf(buf, "0");
+			}
+		} else {
+			sprintf(buf, "%lg", dv->d);
+		}
+		break;
+	case DUK_DVALUE_OBJECT:
+		duk__dvalue_bufesc(dv, hexbuf, 32, 0);
+		sprintf(buf, "obj:%d:%s", (int) dv->i, hexbuf);
+		break;
+	case DUK_DVALUE_POINTER:
+		duk__dvalue_bufesc(dv, hexbuf, 32, 0);
+		sprintf(buf, "ptr:%s", hexbuf);
+		break;
+	case DUK_DVALUE_LIGHTFUNC:
+		duk__dvalue_bufesc(dv, hexbuf, 32, 0);
+		sprintf(buf, "lfunc:%04x:%s", (unsigned int) dv->i, hexbuf);
+		break;
+	case DUK_DVALUE_HEAPPTR:
+		duk__dvalue_bufesc(dv, hexbuf, 32, 0);
+		sprintf(buf, "heapptr:%s", hexbuf);
+		break;
+	default:
+		sprintf(buf, "unknown:%d", (int) dv->tag);
+	}
+}
+
+duk_dvalue *duk_dvalue_make_tag(int tag) {
+	duk_dvalue *dv = duk_dvalue_alloc();
+	if (!dv) { return NULL; }
+	dv->tag = tag;
+	return dv;
+}
+
+duk_dvalue *duk_dvalue_make_tag_int(int tag, int intval) {
+	duk_dvalue *dv = duk_dvalue_alloc();
+	if (!dv) { return NULL; }
+	dv->tag = tag;
+	dv->i = intval;
+	return dv;
+}
+
+duk_dvalue *duk_dvalue_make_tag_double(int tag, double dblval) {
+	duk_dvalue *dv = duk_dvalue_alloc();
+	if (!dv) { return NULL; }
+	dv->tag = tag;
+	dv->d = dblval;
+	return dv;
+}
+
+duk_dvalue *duk_dvalue_make_tag_data(int tag, const char *buf, size_t len) {
+	unsigned char *p;
+	duk_dvalue *dv = duk_dvalue_alloc();
+	if (!dv) { return NULL; }
+	/* Alloc size is len + 1 so that a NUL terminator is always
+	 * guaranteed which is convenient, e.g. you can printf() the
+	 * value safely.
+	 */
+	p = (unsigned char *) malloc(len + 1);
+	if (!p) {
+		free(dv);
+		return NULL;
+	}
+	memcpy((void *) p, (const void *) buf, len);
+	p[len] = (unsigned char) 0;
+	dv->tag = tag;
+	dv->buf = p;
+	dv->len = len;
+	return dv;
+}
+
+duk_dvalue *duk_dvalue_make_tag_int_data(int tag, int intval, const char *buf, size_t len) {
+	duk_dvalue *dv = duk_dvalue_make_tag_data(tag, buf, len);
+	if (!dv) { return NULL; }
+	dv->i = intval;
+	return dv;
+}
+
+/*
+ *  Dvalue transport handling
+ */
+
+static void duk__trans_dvalue_double_byteswap(duk_trans_dvalue_ctx *ctx, volatile unsigned char *p) {
+	unsigned char t;
+
+	/* Portable IEEE double byteswap.  Relies on runtime detection of
+	 * host endianness.
+	 */
+
+	if (ctx->double_byteorder == 0) {
+		/* little endian */
+		t = p[0]; p[0] = p[7]; p[7] = t;
+		t = p[1]; p[1] = p[6]; p[6] = t;
+		t = p[2]; p[2] = p[5]; p[5] = t;
+		t = p[3]; p[3] = p[4]; p[4] = t;
+	} else if (ctx->double_byteorder == 1) {
+		/* big endian: ok as is */
+		;
+	} else {
+		/* mixed endian */
+		t = p[0]; p[0] = p[3]; p[3] = t;
+		t = p[1]; p[1] = p[2]; p[2] = t;
+		t = p[4]; p[4] = p[7]; p[7] = t;
+		t = p[5]; p[5] = p[6]; p[6] = t;
+	}
+}
+
+static unsigned int duk__trans_dvalue_parse_u32(duk_trans_dvalue_ctx *ctx, unsigned char *p) {
+	/* Integers are network endian, read back into host format in
+	 * a portable manner.
+	 */
+	(void) ctx;
+	return (((unsigned int) p[0]) << 24) +
+	       (((unsigned int) p[1]) << 16) +
+	       (((unsigned int) p[2]) << 8) +
+	       (((unsigned int) p[3]) << 0);
+}
+
+static int duk__trans_dvalue_parse_i32(duk_trans_dvalue_ctx *ctx, unsigned char *p) {
+	/* Portable sign handling, doesn't assume 'int' is exactly 32 bits
+	 * like a direct cast would.
+	 */
+	unsigned int tmp = duk__trans_dvalue_parse_u32(ctx, p);
+	if (tmp & 0x80000000UL) {
+		return -((int) ((tmp ^ 0xffffffffUL) + 1UL));
+	} else {
+		return tmp;
+	}
+}
+
+static unsigned int duk__trans_dvalue_parse_u16(duk_trans_dvalue_ctx *ctx, unsigned char *p) {
+	/* Integers are network endian, read back into host format. */
+	(void) ctx;
+	return (((unsigned int) p[0]) << 8) +
+	       (((unsigned int) p[1]) << 0);
+}
+
+static double duk__trans_dvalue_parse_double(duk_trans_dvalue_ctx *ctx, unsigned char *p) {
+	/* IEEE doubles are network endian, read back into host format. */
+	volatile union {
+		double d;
+		unsigned char b[8];
+	} u;
+	memcpy((void *) u.b, (const void *) p, 8);
+	duk__trans_dvalue_double_byteswap(ctx, u.b);
+	return u.d;
+}
+
+static unsigned char *duk__trans_dvalue_encode_u32(duk_trans_dvalue_ctx *ctx, unsigned char *p, unsigned int val) {
+	/* Integers are written in network endian format. */
+	(void) ctx;
+	*p++ = (unsigned char) ((val >> 24) & 0xff);
+	*p++ = (unsigned char) ((val >> 16) & 0xff);
+	*p++ = (unsigned char) ((val >> 8) & 0xff);
+	*p++ = (unsigned char) (val & 0xff);
+	return p;
+}
+
+static unsigned char *duk__trans_dvalue_encode_i32(duk_trans_dvalue_ctx *ctx, unsigned char *p, int val) {
+	return duk__trans_dvalue_encode_u32(ctx, p, (unsigned int) val & 0xffffffffUL);
+}
+
+static unsigned char *duk__trans_dvalue_encode_u16(duk_trans_dvalue_ctx *ctx, unsigned char *p, unsigned int val) {
+	/* Integers are written in network endian format. */
+	(void) ctx;
+	*p++ = (unsigned char) ((val >> 8) & 0xff);
+	*p++ = (unsigned char) (val & 0xff);
+	return p;
+}
+
+static unsigned char *duk__trans_dvalue_encode_double(duk_trans_dvalue_ctx *ctx, unsigned char *p, double val) {
+	/* IEEE doubles are written in network endian format. */
+	volatile union {
+		double d;
+		unsigned char b[8];
+	} u;
+	u.d = val;
+	duk__trans_dvalue_double_byteswap(ctx, u.b);
+	memcpy((void *) p, (const void *) u.b, 8);
+	p += 8;
+	return p;
+}
+
+static unsigned char *duk__trans_buffer_ensure(duk_trans_buffer *dbuf, size_t space) {
+	size_t avail;
+	size_t used;
+	size_t new_size;
+	void *new_alloc;
+
+	used = dbuf->write_offset;
+	avail = dbuf->alloc_size - dbuf->write_offset;
+
+	if (avail >= space) {
+		if (avail - space > 256) {
+			/* Too big, resize so that we reclaim memory if we have just
+			 * received a large string/buffer value.
+			 */
+			goto do_realloc;
+		}
+	} else {
+		/* Too small, resize. */
+		goto do_realloc;
+	}
+
+	return dbuf->base + dbuf->write_offset;
+
+ do_realloc:
+	new_size = used + space + 256;  /* some extra to reduce resizes */
+	new_alloc = realloc(dbuf->base, new_size);
+	if (new_alloc) {
+		dbuf->base = (unsigned char *) new_alloc;
+		dbuf->alloc_size = new_size;
+#if defined(DEBUG_PRINTS)
+		fprintf(stderr, "%s: resized buffer %p to %ld bytes, read_offset=%ld, write_offset=%ld\n",
+		        __func__, (void *) dbuf, (long) new_size, (long) dbuf->read_offset, (long) dbuf->write_offset);
+		fflush(stderr);
+#endif
+		return dbuf->base + dbuf->write_offset;
+	} else {
+		return NULL;
+	}
+}
+
+/* When read_offset is large enough, "rebase" buffer by deleting already
+ * read data and updating offsets.
+ */
+static void duk__trans_buffer_rebase(duk_trans_buffer *dbuf) {
+	if (dbuf->read_offset > 64) {
+#if defined(DEBUG_PRINTS)
+		fprintf(stderr, "%s: rebasing buffer %p, read_offset=%ld, write_offset=%ld\n",
+		        __func__, (void *) dbuf, (long) dbuf->read_offset, (long) dbuf->write_offset);
+		fflush(stderr);
+#endif
+		if (dbuf->write_offset > dbuf->read_offset) {
+			memmove((void *) dbuf->base, (const void *) (dbuf->base + dbuf->read_offset), dbuf->write_offset - dbuf->read_offset);
+		}
+		dbuf->write_offset -= dbuf->read_offset;
+		dbuf->read_offset = 0;
+	}
+}
+
+duk_trans_dvalue_ctx *duk_trans_dvalue_init(void) {
+	volatile union {
+		double d;
+		unsigned char b[8];
+	} u;
+	duk_trans_dvalue_ctx *ctx = NULL;
+
+	ctx = (duk_trans_dvalue_ctx *) malloc(sizeof(duk_trans_dvalue_ctx));
+	if (!ctx) { goto fail; }
+	memset((void *) ctx, 0, sizeof(duk_trans_dvalue_ctx));
+	ctx->received = NULL;
+	ctx->cooperate = NULL;
+	ctx->handshake = NULL;
+	ctx->detached = NULL;
+	ctx->send_buf.base = NULL;
+	ctx->recv_buf.base = NULL;
+
+	ctx->send_buf.base = malloc(256);
+	if (!ctx->send_buf.base) { goto fail; }
+	ctx->send_buf.alloc_size = 256;
+
+	ctx->recv_buf.base = malloc(256);
+	if (!ctx->recv_buf.base) { goto fail; }
+	ctx->recv_buf.alloc_size = 256;
+
+	/* IEEE double byte order, detect at run time (could also use
+	 * preprocessor defines but that's verbose to make portable).
+	 *
+	 * >>> struct.unpack('>d', '1122334455667788'.decode('hex'))
+	 * (3.841412024471731e-226,)
+	 * >>> struct.unpack('>d', '8877665544332211'.decode('hex'))
+	 * (-7.086876636573014e-268,)
+	 * >>> struct.unpack('>d', '4433221188776655'.decode('hex'))
+	 * (3.5294303071877444e+20,)
+	 */
+	u.b[0] = 0x11; u.b[1] = 0x22; u.b[2] = 0x33; u.b[3] = 0x44;
+	u.b[4] = 0x55; u.b[5] = 0x66; u.b[6] = 0x77; u.b[7] = 0x88;
+	if (u.d < 0.0) {
+		ctx->double_byteorder = 0;  /* little endian */
+	} else if (u.d < 1.0) {
+		ctx->double_byteorder = 1;  /* big endian */
+	} else {
+		ctx->double_byteorder = 2;  /* mixed endian (arm) */
+	}
+#if defined(DEBUG_PRINTS)
+	fprintf(stderr, "double endianness test value is %lg -> byteorder %d\n",
+	        u.d, ctx->double_byteorder);
+	fflush(stderr);
+#endif
+
+	return ctx;
+
+ fail:
+	if (ctx) {
+		free(ctx->recv_buf.base);  /* tolerates NULL */
+		free(ctx->send_buf.base);  /* tolerates NULL */
+		free(ctx);
+	}
+	return NULL;
+}
+
+void duk_trans_dvalue_free(duk_trans_dvalue_ctx *ctx) {
+	if (ctx) {
+		free(ctx->send_buf.base);  /* tolerates NULL */
+		free(ctx->recv_buf.base);  /* tolerates NULL */
+		free(ctx);
+	}
+}
+
+void duk_trans_dvalue_send(duk_trans_dvalue_ctx *ctx, duk_dvalue *dv) {
+	unsigned char *p;
+
+	/* Convert argument dvalue into Duktape debug protocol format.
+	 * Literal constants are used here for the debug protocol,
+	 * e.g. initial byte 0x02 is REP, see doc/debugger.rst.
+	 */
+
+#if defined(DEBUG_PRINTS)
+	{
+		char buf[DUK_DVALUE_TOSTRING_BUFLEN];
+		duk_dvalue_to_string(dv, buf);
+		fprintf(stderr, "%s: sending dvalue: %s\n", __func__, buf);
+		fflush(stderr);
+	}
+#endif
+
+	switch (dv->tag) {
+	case DUK_DVALUE_EOM: {
+		p = duk__trans_buffer_ensure(&ctx->send_buf, 1);
+		if (!p) { goto alloc_error; }
+		*p++ = 0x00;
+		ctx->send_buf.write_offset += 1;
+		break;
+	}
+	case DUK_DVALUE_REQ: {
+		p = duk__trans_buffer_ensure(&ctx->send_buf, 1);
+		if (!p) { goto alloc_error; }
+		*p++ = 0x01;
+		ctx->send_buf.write_offset += 1;
+		break;
+	}
+	case DUK_DVALUE_REP: {
+		p = duk__trans_buffer_ensure(&ctx->send_buf, 1);
+		if (!p) { goto alloc_error; }
+		*p++ = 0x02;
+		ctx->send_buf.write_offset += 1;
+		break;
+	}
+	case DUK_DVALUE_ERR: {
+		p = duk__trans_buffer_ensure(&ctx->send_buf, 1);
+		if (!p) { goto alloc_error; }
+		*p++ = 0x03;
+		ctx->send_buf.write_offset += 1;
+		break;
+	}
+	case DUK_DVALUE_NFY: {
+		p = duk__trans_buffer_ensure(&ctx->send_buf, 1);
+		if (!p) { goto alloc_error; }
+		*p++ = 0x04;
+		ctx->send_buf.write_offset += 1;
+		break;
+	}
+	case DUK_DVALUE_INTEGER: {
+		int i = dv->i;
+		if (i >= 0 && i <= 63) {
+			p = duk__trans_buffer_ensure(&ctx->send_buf, 1);
+			if (!p) { goto alloc_error; }
+			*p++ = (unsigned char) (0x80 + i);
+			ctx->send_buf.write_offset += 1;
+		} else if (i >= 0 && i <= 16383L) {
+			p = duk__trans_buffer_ensure(&ctx->send_buf, 2);
+			if (!p) { goto alloc_error; }
+			*p++ = (unsigned char) (0xc0 + (i >> 8));
+			*p++ = (unsigned char) (i & 0xff);
+			ctx->send_buf.write_offset += 2;
+		} else if (i >= -0x80000000L && i <= 0x7fffffffL) {  /* Harmless warning on some platforms (re: range) */
+			p = duk__trans_buffer_ensure(&ctx->send_buf, 5);
+			if (!p) { goto alloc_error; }
+			*p++ = 0x10;
+			p = duk__trans_dvalue_encode_i32(ctx, p, i);
+			ctx->send_buf.write_offset += 5;
+		} else {
+			goto dvalue_error;
+		}
+		break;
+	}
+	case DUK_DVALUE_STRING: {
+		size_t i = dv->len;
+		if (i <= 0x1fUL) {
+			p = duk__trans_buffer_ensure(&ctx->send_buf, 1 + i);
+			if (!p) { goto alloc_error; }
+			*p++ = (unsigned char) (0x60 + i);
+			memcpy((void *) p, (const void *) dv->buf, i);
+			p += i;
+			ctx->send_buf.write_offset += 1 + i;
+		} else if (i <= 0xffffUL) {
+			p = duk__trans_buffer_ensure(&ctx->send_buf, 3 + i);
+			if (!p) { goto alloc_error; }
+			*p++ = 0x12;
+			p = duk__trans_dvalue_encode_u16(ctx, p, (unsigned int) i);
+			memcpy((void *) p, (const void *) dv->buf, i);
+			p += i;
+			ctx->send_buf.write_offset += 3 + i;
+		} else if (i <= 0xffffffffUL) {
+			p = duk__trans_buffer_ensure(&ctx->send_buf, 5 + i);
+			if (!p) { goto alloc_error; }
+			*p++ = 0x11;
+			p = duk__trans_dvalue_encode_u32(ctx, p, (unsigned int) i);
+			memcpy((void *) p, (const void *) dv->buf, i);
+			p += i;
+			ctx->send_buf.write_offset += 5 + i;
+		} else {
+			goto dvalue_error;
+		}
+		break;
+	}
+	case DUK_DVALUE_BUFFER: {
+		size_t i = dv->len;
+		if (i <= 0xffffUL) {
+			p = duk__trans_buffer_ensure(&ctx->send_buf, 3 + i);
+			if (!p) { goto alloc_error; }
+			*p++ = 0x14;
+			p = duk__trans_dvalue_encode_u16(ctx, p, (unsigned int) i);
+			memcpy((void *) p, (const void *) dv->buf, i);
+			p += i;
+			ctx->send_buf.write_offset += 3 + i;
+		} else if (i <= 0xffffffffUL) {
+			p = duk__trans_buffer_ensure(&ctx->send_buf, 5 + i);
+			if (!p) { goto alloc_error; }
+			*p++ = 0x13;
+			p = duk__trans_dvalue_encode_u32(ctx, p, (unsigned int) i);
+			memcpy((void *) p, (const void *) dv->buf, i);
+			p += i;
+			ctx->send_buf.write_offset += 5 + i;
+		} else {
+			goto dvalue_error;
+		}
+		break;
+	}
+	case DUK_DVALUE_UNUSED: {
+		p = duk__trans_buffer_ensure(&ctx->send_buf, 1);
+		if (!p) { goto alloc_error; }
+		*p++ = 0x15;
+		ctx->send_buf.write_offset += 1;
+		break;
+	}
+	case DUK_DVALUE_UNDEFINED: {
+		p = duk__trans_buffer_ensure(&ctx->send_buf, 1);
+		if (!p) { goto alloc_error; }
+		*p++ = 0x16;
+		ctx->send_buf.write_offset += 1;
+		break;
+	}
+	case DUK_DVALUE_NULL: {
+		p = duk__trans_buffer_ensure(&ctx->send_buf, 1);
+		if (!p) { goto alloc_error; }
+		*p++ = 0x17;
+		ctx->send_buf.write_offset += 1;
+		break;
+	}
+	case DUK_DVALUE_TRUE: {
+		p = duk__trans_buffer_ensure(&ctx->send_buf, 1);
+		if (!p) { goto alloc_error; }
+		*p++ = 0x18;
+		ctx->send_buf.write_offset += 1;
+		break;
+	}
+	case DUK_DVALUE_FALSE: {
+		p = duk__trans_buffer_ensure(&ctx->send_buf, 1);
+		if (!p) { goto alloc_error; }
+		*p++ = 0x19;
+		ctx->send_buf.write_offset += 1;
+		break;
+	}
+	case DUK_DVALUE_NUMBER: {
+		p = duk__trans_buffer_ensure(&ctx->send_buf, 9);
+		if (!p) { goto alloc_error; }
+		*p++ = 0x1a;
+		p = duk__trans_dvalue_encode_double(ctx, p, dv->d);
+		ctx->send_buf.write_offset += 9;
+		break;
+	}
+	case DUK_DVALUE_OBJECT: {
+		size_t i = dv->len;
+		if (i <= 0xffUL && dv->i >= 0 && dv->i <= 0xffL) {
+			p = duk__trans_buffer_ensure(&ctx->send_buf, 3 + i);
+			if (!p) { goto alloc_error; }
+			*p++ = 0x1b;
+			*p++ = (unsigned char) dv->i;
+			*p++ = (unsigned char) i;
+			memcpy((void *) p, (const void *) dv->buf, i);
+			ctx->send_buf.write_offset += 3 + i;
+		} else {
+			goto dvalue_error;
+		}
+		break;
+	}
+	case DUK_DVALUE_POINTER: {
+		size_t i = dv->len;
+		if (i <= 0xffUL) {
+			p = duk__trans_buffer_ensure(&ctx->send_buf, 2 + i);
+			if (!p) { goto alloc_error; }
+			*p++ = 0x1c;
+			*p++ = (unsigned char) i;
+			memcpy((void *) p, (const void *) dv->buf, i);
+			ctx->send_buf.write_offset += 2 + i;
+		} else {
+			goto dvalue_error;
+		}
+		break;
+	}
+	case DUK_DVALUE_LIGHTFUNC: {
+		size_t i = dv->len;
+		if (i <= 0xffUL && dv->i >= 0 && dv->i <= 0xffffL) {
+			p = duk__trans_buffer_ensure(&ctx->send_buf, 4 + i);
+			if (!p) { goto alloc_error; }
+			*p++ = 0x1d;
+			p = duk__trans_dvalue_encode_u16(ctx, p, (unsigned int) dv->i);
+			*p++ = (unsigned char) i;
+			memcpy((void *) p, (const void *) dv->buf, i);
+			ctx->send_buf.write_offset += 4 + i;
+		} else {
+			goto dvalue_error;
+		}
+		break;
+	}
+	case DUK_DVALUE_HEAPPTR: {
+		size_t i = dv->len;
+		if (i <= 0xffUL) {
+			p = duk__trans_buffer_ensure(&ctx->send_buf, 2 + i);
+			if (!p) { goto alloc_error; }
+			*p++ = 0x1e;
+			*p++ = (unsigned char) i;
+			memcpy((void *) p, (const void *) dv->buf, i);
+			ctx->send_buf.write_offset += 2 + i;
+		} else {
+			goto dvalue_error;
+		}
+		break;
+	}
+	default: {
+		goto dvalue_error;
+	}
+	}  /* end switch */
+
+	return;
+
+ dvalue_error:
+#if defined(ERROR_PRINTS)
+	fprintf(stderr, "%s: internal error, argument dvalue is invalid\n", __func__);
+	fflush(stdout);
+#endif
+	return;
+
+ alloc_error:
+#if defined(ERROR_PRINTS)
+	fprintf(stderr, "%s: internal error, failed to allocate space for write\n", __func__);
+	fflush(stdout);
+#endif
+	return;
+}
+
+static void duk__trans_dvalue_send_and_free(duk_trans_dvalue_ctx *ctx, duk_dvalue *dv) {
+	if (!dv) { return; }
+	duk_trans_dvalue_send(ctx, dv);
+	duk_dvalue_free(dv);
+}
+
+void duk_trans_dvalue_send_eom(duk_trans_dvalue_ctx *ctx) {
+	duk__trans_dvalue_send_and_free(ctx, duk_dvalue_make_tag(DUK_DVALUE_EOM));
+}
+
+void duk_trans_dvalue_send_req(duk_trans_dvalue_ctx *ctx) {
+	duk__trans_dvalue_send_and_free(ctx, duk_dvalue_make_tag(DUK_DVALUE_REQ));
+}
+
+void duk_trans_dvalue_send_rep(duk_trans_dvalue_ctx *ctx) {
+	duk__trans_dvalue_send_and_free(ctx, duk_dvalue_make_tag(DUK_DVALUE_REP));
+}
+
+void duk_trans_dvalue_send_err(duk_trans_dvalue_ctx *ctx) {
+	duk__trans_dvalue_send_and_free(ctx, duk_dvalue_make_tag(DUK_DVALUE_ERR));
+}
+
+void duk_trans_dvalue_send_nfy(duk_trans_dvalue_ctx *ctx) {
+	duk__trans_dvalue_send_and_free(ctx, duk_dvalue_make_tag(DUK_DVALUE_NFY));
+}
+
+void duk_trans_dvalue_send_integer(duk_trans_dvalue_ctx *ctx, int val) {
+	duk__trans_dvalue_send_and_free(ctx, duk_dvalue_make_tag_int(DUK_DVALUE_INTEGER, val));
+}
+
+void duk_trans_dvalue_send_string(duk_trans_dvalue_ctx *ctx, const char *str) {
+	duk__trans_dvalue_send_and_free(ctx, duk_dvalue_make_tag_data(DUK_DVALUE_STRING, str, strlen(str)));
+}
+
+void duk_trans_dvalue_send_lstring(duk_trans_dvalue_ctx *ctx, const char *str, size_t len) {
+	duk__trans_dvalue_send_and_free(ctx, duk_dvalue_make_tag_data(DUK_DVALUE_STRING, str, len));
+}
+
+void duk_trans_dvalue_send_buffer(duk_trans_dvalue_ctx *ctx, const char *buf, size_t len) {
+	duk__trans_dvalue_send_and_free(ctx, duk_dvalue_make_tag_data(DUK_DVALUE_BUFFER, buf, len));
+}
+
+void duk_trans_dvalue_send_unused(duk_trans_dvalue_ctx *ctx) {
+	duk__trans_dvalue_send_and_free(ctx, duk_dvalue_make_tag(DUK_DVALUE_UNUSED));
+}
+
+void duk_trans_dvalue_send_undefined(duk_trans_dvalue_ctx *ctx) {
+	duk__trans_dvalue_send_and_free(ctx, duk_dvalue_make_tag(DUK_DVALUE_UNDEFINED));
+}
+
+void duk_trans_dvalue_send_null(duk_trans_dvalue_ctx *ctx) {
+	duk__trans_dvalue_send_and_free(ctx, duk_dvalue_make_tag(DUK_DVALUE_NULL));
+}
+
+void duk_trans_dvalue_send_true(duk_trans_dvalue_ctx *ctx) {
+	duk__trans_dvalue_send_and_free(ctx, duk_dvalue_make_tag(DUK_DVALUE_TRUE));
+}
+
+void duk_trans_dvalue_send_false(duk_trans_dvalue_ctx *ctx) {
+	duk__trans_dvalue_send_and_free(ctx, duk_dvalue_make_tag(DUK_DVALUE_FALSE));
+}
+
+void duk_trans_dvalue_send_number(duk_trans_dvalue_ctx *ctx, double val) {
+	duk__trans_dvalue_send_and_free(ctx, duk_dvalue_make_tag_double(DUK_DVALUE_NUMBER, val));
+}
+
+void duk_trans_dvalue_send_object(duk_trans_dvalue_ctx *ctx, int classnum, const char *ptr_data, size_t ptr_len) {
+	duk__trans_dvalue_send_and_free(ctx, duk_dvalue_make_tag_int_data(DUK_DVALUE_OBJECT, classnum, ptr_data, ptr_len));
+}
+
+void duk_trans_dvalue_send_pointer(duk_trans_dvalue_ctx *ctx, const char *ptr_data, size_t ptr_len) {
+	duk__trans_dvalue_send_and_free(ctx, duk_dvalue_make_tag_data(DUK_DVALUE_POINTER, ptr_data, ptr_len));
+}
+
+void duk_trans_dvalue_send_lightfunc(duk_trans_dvalue_ctx *ctx, int lf_flags, const char *ptr_data, size_t ptr_len) {
+	duk__trans_dvalue_send_and_free(ctx, duk_dvalue_make_tag_int_data(DUK_DVALUE_LIGHTFUNC, lf_flags, ptr_data, ptr_len));
+}
+
+void duk_trans_dvalue_send_heapptr(duk_trans_dvalue_ctx *ctx, const char *ptr_data, size_t ptr_len) {
+	duk__trans_dvalue_send_and_free(ctx, duk_dvalue_make_tag_data(DUK_DVALUE_HEAPPTR, ptr_data, ptr_len));
+}
+
+void duk_trans_dvalue_send_req_cmd(duk_trans_dvalue_ctx *ctx, int cmd) {
+	duk_trans_dvalue_send_req(ctx);
+	duk_trans_dvalue_send_integer(ctx, cmd);
+}
+
+static duk_dvalue *duk__trans_trial_parse_dvalue(duk_trans_dvalue_ctx *ctx) {
+	unsigned char *p;
+	size_t len;
+	unsigned char ib;
+	duk_dvalue *dv;
+	size_t datalen;
+
+	p = ctx->recv_buf.base + ctx->recv_buf.read_offset;
+	len = ctx->recv_buf.write_offset - ctx->recv_buf.read_offset;
+
+	if (len == 0) {
+		return NULL;
+	}
+	ib = p[0];
+
+#if defined(DEBUG_PRINTS)
+	{
+		size_t i;
+		fprintf(stderr, "%s: parsing dvalue, window:", __func__);
+		for (i = 0; i < 16; i++) {
+			if (i < len) {
+				fprintf(stderr, " %02x", (unsigned int) p[i]);
+			} else {
+				fprintf(stderr, " ??");
+			}
+		}
+		fprintf(stderr, " (length %ld, read_offset %ld, write_offset %ld, alloc_size %ld)\n",
+		        (long) len, (long) ctx->recv_buf.read_offset, (long) ctx->recv_buf.write_offset,
+		        (long) ctx->recv_buf.alloc_size);
+		fflush(stderr);
+	}
+#endif
+
+	if (ib <= 0x1fU) {
+		/* 0x00 ... 0x1f */
+		switch (ib) {
+		case 0x00: {
+			ctx->recv_buf.read_offset += 1;
+			dv = duk_dvalue_make_tag(DUK_DVALUE_EOM);
+			if (!dv) { goto alloc_error; }
+			return dv;
+		}
+		case 0x01: {
+			ctx->recv_buf.read_offset += 1;
+			dv = duk_dvalue_make_tag(DUK_DVALUE_REQ);
+			if (!dv) { goto alloc_error; }
+			return dv;
+		}
+		case 0x02: {
+			ctx->recv_buf.read_offset += 1;
+			dv = duk_dvalue_make_tag(DUK_DVALUE_REP);
+			if (!dv) { goto alloc_error; }
+			return dv;
+		}
+		case 0x03: {
+			ctx->recv_buf.read_offset += 1;
+			dv = duk_dvalue_make_tag(DUK_DVALUE_ERR);
+			if (!dv) { goto alloc_error; }
+			return dv;
+		}
+		case 0x04: {
+			ctx->recv_buf.read_offset += 1;
+			dv = duk_dvalue_make_tag(DUK_DVALUE_NFY);
+			if (!dv) { goto alloc_error; }
+			return dv;
+		}
+		case 0x10: {
+			int intval;
+			if (len < 5) { goto partial; }
+			intval = duk__trans_dvalue_parse_i32(ctx, p + 1);
+			ctx->recv_buf.read_offset += 5;
+			dv = duk_dvalue_make_tag_int(DUK_DVALUE_INTEGER, intval);
+			if (!dv) { goto alloc_error; }
+			return dv;
+		}
+		case 0x11: {
+			if (len < 5) { goto partial; }
+			datalen = (size_t) duk__trans_dvalue_parse_u32(ctx, p + 1);
+			if (len < 5 + datalen) { goto partial; }
+			ctx->recv_buf.read_offset += 5 + datalen;
+			dv = duk_dvalue_make_tag_data(DUK_DVALUE_STRING, (const char *) (p + 5), datalen);
+			if (!dv) { goto alloc_error; }
+			return dv;
+		}
+		case 0x12: {
+			if (len < 3) { goto partial; }
+			datalen = (size_t) duk__trans_dvalue_parse_u16(ctx, p + 1);
+			if (len < 3 + datalen) { goto partial; }
+			ctx->recv_buf.read_offset += 3 + datalen;
+			dv = duk_dvalue_make_tag_data(DUK_DVALUE_STRING, (const char *) (p + 3), datalen);
+			if (!dv) { goto alloc_error; }
+			return dv;
+		}
+		case 0x13: {
+			if (len < 5) { goto partial; }
+			datalen = (size_t) duk__trans_dvalue_parse_u32(ctx, p + 1);
+			if (len < 5 + datalen) { goto partial; }
+			ctx->recv_buf.read_offset += 5 + datalen;
+			dv = duk_dvalue_make_tag_data(DUK_DVALUE_BUFFER, (const char *) (p + 5), datalen);
+			if (!dv) { goto alloc_error; }
+			return dv;
+		}
+		case 0x14: {
+			if (len < 3) { goto partial; }
+			datalen = (size_t) duk__trans_dvalue_parse_u16(ctx, p + 1);
+			if (len < 3 + datalen) { goto partial; }
+			ctx->recv_buf.read_offset += 3 + datalen;
+			dv = duk_dvalue_make_tag_data(DUK_DVALUE_BUFFER, (const char *) (p + 3), datalen);
+			if (!dv) { goto alloc_error; }
+			return dv;
+		}
+		case 0x15: {
+			ctx->recv_buf.read_offset += 1;
+			dv = duk_dvalue_make_tag(DUK_DVALUE_UNUSED);
+			if (!dv) { goto alloc_error; }
+			return dv;
+		}
+		case 0x16: {
+			ctx->recv_buf.read_offset += 1;
+			dv = duk_dvalue_make_tag(DUK_DVALUE_UNDEFINED);
+			if (!dv) { goto alloc_error; }
+			return dv;
+		}
+		case 0x17: {
+			ctx->recv_buf.read_offset += 1;
+			dv = duk_dvalue_make_tag(DUK_DVALUE_NULL);
+			if (!dv) { goto alloc_error; }
+			return dv;
+		}
+		case 0x18: {
+			ctx->recv_buf.read_offset += 1;
+			dv = duk_dvalue_make_tag(DUK_DVALUE_TRUE);
+			if (!dv) { goto alloc_error; }
+			return dv;
+		}
+		case 0x19: {
+			ctx->recv_buf.read_offset += 1;
+			dv = duk_dvalue_make_tag(DUK_DVALUE_FALSE);
+			if (!dv) { goto alloc_error; }
+			return dv;
+		}
+		case 0x1a: {
+			double dblval;
+			if (len < 9) { goto partial; }
+			dblval = duk__trans_dvalue_parse_double(ctx, p + 1);
+			ctx->recv_buf.read_offset += 9;
+			dv = duk_dvalue_make_tag_double(DUK_DVALUE_NUMBER, dblval);
+			if (!dv) { goto alloc_error; }
+			return dv;
+		}
+		case 0x1b: {
+			int classnum;
+			if (len < 3) { goto partial; }
+			datalen = (size_t) p[2];
+			if (len < 3 + datalen) { goto partial; }
+			classnum = (int) p[1];
+			ctx->recv_buf.read_offset += 3 + datalen;
+			dv = duk_dvalue_make_tag_int_data(DUK_DVALUE_OBJECT, classnum, (const char *) (p + 3), datalen);
+			if (!dv) { goto alloc_error; }
+			return dv;
+		}
+		case 0x1c: {
+			if (len < 2) { goto partial; }
+			datalen = (size_t) p[1];
+			if (len < 2 + datalen) { goto partial; }
+			ctx->recv_buf.read_offset += 2 + datalen;
+			dv = duk_dvalue_make_tag_data(DUK_DVALUE_POINTER, (const char *) (p + 2), datalen);
+			if (!dv) { goto alloc_error; }
+			return dv;
+		}
+		case 0x1d: {
+			int lf_flags;
+			if (len < 4) { goto partial; }
+			datalen = (size_t) p[3];
+			if (len < 4 + datalen) { goto partial; }
+			lf_flags = (int) duk__trans_dvalue_parse_u16(ctx, p + 1);
+			ctx->recv_buf.read_offset += 4 + datalen;
+			dv = duk_dvalue_make_tag_int_data(DUK_DVALUE_LIGHTFUNC, lf_flags, (const char *) (p + 4), datalen);
+			if (!dv) { goto alloc_error; }
+			return dv;
+		}
+		case 0x1e: {
+			if (len < 2) { goto partial; }
+			datalen = (size_t) p[1];
+			if (len < 2 + datalen) { goto partial; }
+			ctx->recv_buf.read_offset += 2 + datalen;
+			dv = duk_dvalue_make_tag_data(DUK_DVALUE_HEAPPTR, (const char *) (p + 2), datalen);
+			if (!dv) { goto alloc_error; }
+			return dv;
+		}
+		default: {
+			goto format_error;
+		}
+		}  /* end switch */
+	} else if (ib <= 0x5fU) {
+		/* 0x20 ... 0x5f */
+		goto format_error;
+	} else if (ib <= 0x7fU) {
+		/* 0x60 ... 0x7f */
+		datalen = (size_t) (ib - 0x60U);
+		if (len < 1 + datalen) { goto partial; }
+		ctx->recv_buf.read_offset += 1 + datalen;
+		dv = duk_dvalue_make_tag_data(DUK_DVALUE_STRING, (const char *) (p + 1), datalen);
+		if (!dv) { goto alloc_error; }
+		return dv;
+	} else if (ib <= 0xbfU) {
+		/* 0x80 ... 0xbf */
+		int intval;
+		intval = (int) (ib - 0x80U);
+		ctx->recv_buf.read_offset += 1;
+		dv = duk_dvalue_make_tag_int(DUK_DVALUE_INTEGER, intval);
+		if (!dv) { goto alloc_error; }
+		return dv;
+	} else {
+		/* 0xc0 ... 0xff */
+		int intval;
+		if (len < 2) { goto partial; }
+		intval = (((int) (ib - 0xc0U)) << 8) + (int) p[1];
+		ctx->recv_buf.read_offset += 2;
+		dv = duk_dvalue_make_tag_int(DUK_DVALUE_INTEGER, intval);
+		if (!dv) { goto alloc_error; }
+		return dv;
+	}
+
+	/* never here */
+
+ partial:
+	return NULL;
+
+ alloc_error:
+#if defined(ERROR_PRINTS)
+	fprintf(stderr, "%s: internal error, cannot allocate space for dvalue\n", __func__);
+	fflush(stdout);
+#endif
+	return NULL;
+
+ format_error:
+#if defined(ERROR_PRINTS)
+	fprintf(stderr, "%s: internal error, dvalue format error\n", __func__);
+	fflush(stdout);
+#endif
+	return NULL;
+}
+
+static duk_dvalue *duk__trans_trial_parse_handshake(duk_trans_dvalue_ctx *ctx) {
+	unsigned char *p;
+	size_t len;
+	duk_dvalue *dv;
+	size_t i;
+
+	p = ctx->recv_buf.base + ctx->recv_buf.read_offset;
+	len = ctx->recv_buf.write_offset - ctx->recv_buf.read_offset;
+
+	for (i = 0; i < len; i++) {
+		if (p[i] == 0x0a) {
+			/* Handshake line is returned as a dvalue for convenience; it's
+			 * not actually a part of the dvalue phase of the protocol.
+			 */
+			ctx->recv_buf.read_offset += i + 1;
+			dv = duk_dvalue_make_tag_data(DUK_DVALUE_STRING, (const char *) p, i);
+			if (!dv) { goto alloc_error; }
+			return dv;
+		}
+	}
+
+	return NULL;
+
+ alloc_error:
+#if defined(ERROR_PRINTS)
+	fprintf(stderr, "%s: internal error, cannot allocate space for handshake line\n", __func__);
+	fflush(stdout);
+#endif
+	return NULL;
+}
+
+static void duk__trans_call_cooperate(duk_trans_dvalue_ctx *ctx, int block) {
+	if (ctx->cooperate) {
+		ctx->cooperate(ctx, block);
+	}
+}
+
+static void duk__trans_call_received(duk_trans_dvalue_ctx *ctx, duk_dvalue *dv) {
+	if (ctx->received) {
+		ctx->received(ctx, dv);
+	}
+}
+
+static void duk__trans_call_handshake(duk_trans_dvalue_ctx *ctx, const char *line) {
+	if (ctx->handshake) {
+		ctx->handshake(ctx, line);
+	}
+}
+
+static void duk__trans_call_detached(duk_trans_dvalue_ctx *ctx) {
+	if (ctx->detached) {
+		ctx->detached(ctx);
+	}
+}
+
+/*
+ *  Duktape callbacks
+ */
+
+duk_size_t duk_trans_dvalue_read_cb(void *udata, char *buffer, duk_size_t length) {
+	duk_trans_dvalue_ctx *ctx = (duk_trans_dvalue_ctx *) udata;
+
+#if defined(DEBUG_PRINTS)
+	fprintf(stderr, "%s: %p %p %ld\n", __func__, udata, (void *) buffer, (long) length);
+	fflush(stderr);
+#endif
+
+	duk__trans_call_cooperate(ctx, 0);
+
+	for (;;) {
+		size_t avail, now;
+
+		avail = (size_t) (ctx->send_buf.write_offset - ctx->send_buf.read_offset);
+		if (avail == 0) {
+			/* Must cooperate until user callback provides data.  From
+			 * Duktape's perspective we MUST block until data is received.
+			 */
+			duk__trans_call_cooperate(ctx, 1);
+		} else {
+			now = avail;
+			if (now > length) {
+				now = length;
+			}
+			memcpy((void *) buffer, (const void *) (ctx->send_buf.base + ctx->send_buf.read_offset), now);
+			duk__trans_buffer_rebase(&ctx->send_buf);
+			ctx->send_buf.read_offset += now;
+			return now;
+		}
+	}
+}
+
+duk_size_t duk_trans_dvalue_write_cb(void *udata, const char *buffer, duk_size_t length) {
+	duk_trans_dvalue_ctx *ctx = (duk_trans_dvalue_ctx *) udata;
+	unsigned char *p;
+
+#if defined(DEBUG_PRINTS)
+	fprintf(stderr, "%s: %p %p %ld\n", __func__, udata, (void *) buffer, (long) length);
+	fflush(stderr);
+#endif
+
+	duk__trans_call_cooperate(ctx, 0);
+
+	/* Append data. */
+	duk__trans_buffer_rebase(&ctx->recv_buf);
+	p = duk__trans_buffer_ensure(&ctx->recv_buf, length);
+	memcpy((void *) p, (const void *) buffer, (size_t) length);
+	ctx->recv_buf.write_offset += length;
+
+	/* Trial parse handshake line or dvalue(s). */
+	if (!ctx->handshake_done) {
+		duk_dvalue *dv = duk__trans_trial_parse_handshake(ctx);
+		if (dv) {
+			/* Handshake line is available for caller for the
+			 * duration of the callback, and must not be freed
+			 * by the caller.
+			 */
+			duk__trans_call_handshake(ctx, (const char *) dv->buf);
+#if defined(DEBUG_PRINTS)
+			fprintf(stderr, "%s: handshake ok\n", __func__);
+			fflush(stderr);
+#endif
+			duk_dvalue_free(dv);
+			ctx->handshake_done = 1;
+		}
+	}
+	if (ctx->handshake_done) {
+		for (;;) {
+			duk_dvalue *dv = duk__trans_trial_parse_dvalue(ctx);
+			if (dv) {
+#if defined(DEBUG_PRINTS)
+				{
+					char buf[DUK_DVALUE_TOSTRING_BUFLEN];
+					duk_dvalue_to_string(dv, buf);
+					fprintf(stderr, "%s: received dvalue: %s\n", __func__, buf);
+					fflush(stderr);
+				}
+#endif
+
+				duk__trans_call_received(ctx, dv);
+			} else {
+				break;
+			}
+		}
+	}
+
+	duk__trans_call_cooperate(ctx, 0);  /* just in case, if dvalues changed something */
+
+	return length;
+}
+
+duk_size_t duk_trans_dvalue_peek_cb(void *udata) {
+	duk_trans_dvalue_ctx *ctx = (duk_trans_dvalue_ctx *) udata;
+	size_t avail;
+
+#if defined(DEBUG_PRINTS)
+	fprintf(stderr, "%s: %p\n", __func__, udata);
+	fflush(stderr);
+#endif
+
+	duk__trans_call_cooperate(ctx, 0);
+	avail = (size_t) (ctx->send_buf.write_offset - ctx->send_buf.read_offset);
+	return (duk_size_t) avail;
+}
+
+void duk_trans_dvalue_read_flush_cb(void *udata) {
+	duk_trans_dvalue_ctx *ctx = (duk_trans_dvalue_ctx *) udata;
+
+#if defined(DEBUG_PRINTS)
+	fprintf(stderr, "%s: %p\n", __func__, udata);
+	fflush(stderr);
+#endif
+
+	duk__trans_call_cooperate(ctx, 0);
+}
+
+void duk_trans_dvalue_write_flush_cb(void *udata) {
+	duk_trans_dvalue_ctx *ctx = (duk_trans_dvalue_ctx *) udata;
+
+#if defined(DEBUG_PRINTS)
+	fprintf(stderr, "%s: %p\n", __func__, udata);
+	fflush(stderr);
+#endif
+
+	duk__trans_call_cooperate(ctx, 0);
+}
+
+void duk_trans_dvalue_detached_cb(void *udata) {
+	duk_trans_dvalue_ctx *ctx = (duk_trans_dvalue_ctx *) udata;
+
+#if defined(DEBUG_PRINTS)
+	fprintf(stderr, "%s: %p\n", __func__, udata);
+	fflush(stderr);
+#endif
+
+	duk__trans_call_detached(ctx);
+}

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/debug-trans-dvalue/duk_trans_dvalue.h
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/debug-trans-dvalue/duk_trans_dvalue.h b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/debug-trans-dvalue/duk_trans_dvalue.h
new file mode 100644
index 0000000..e0ba731
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/debug-trans-dvalue/duk_trans_dvalue.h
@@ -0,0 +1,113 @@
+#ifndef DUK_TRANS_DVALUE_H_INCLUDED
+#define DUK_TRANS_DVALUE_H_INCLUDED
+
+#include "duktape.h"
+
+typedef struct duk_dvalue duk_dvalue;
+typedef struct duk_trans_buffer duk_trans_buffer;
+typedef struct duk_trans_dvalue_ctx duk_trans_dvalue_ctx;
+
+typedef void (*duk_trans_dvalue_received_function)(duk_trans_dvalue_ctx *ctx, duk_dvalue *dv);
+typedef void (*duk_trans_dvalue_cooperate_function)(duk_trans_dvalue_ctx *ctx, int block);
+typedef void (*duk_trans_dvalue_handshake_function)(duk_trans_dvalue_ctx *ctx, const char *handshake_line);
+typedef void (*duk_trans_dvalue_detached_function)(duk_trans_dvalue_ctx *ctx);
+
+/* struct duk_dvalue 'tag' values, note that these have nothing to do with
+ * Duktape debug protocol inital byte.  Struct fields used with the type
+ * are noted next to the define.
+ */
+#define DUK_DVALUE_EOM         1   /* no fields */
+#define DUK_DVALUE_REQ         2   /* no fields */
+#define DUK_DVALUE_REP         3   /* no fields */
+#define DUK_DVALUE_ERR         4   /* no fields */
+#define DUK_DVALUE_NFY         5   /* no fields */
+#define DUK_DVALUE_INTEGER     6   /* i: 32-bit signed integer */
+#define DUK_DVALUE_STRING      7   /* buf: string data, len: string length */
+#define DUK_DVALUE_BUFFER      8   /* buf: buffer data, len: buffer length */
+#define DUK_DVALUE_UNUSED      9   /* no fields */
+#define DUK_DVALUE_UNDEFINED   10  /* no fields */
+#define DUK_DVALUE_NULL        11  /* no fields */
+#define DUK_DVALUE_TRUE        12  /* no fields */
+#define DUK_DVALUE_FALSE       13  /* no fields */
+#define DUK_DVALUE_NUMBER      14  /* d: ieee double */
+#define DUK_DVALUE_OBJECT      15  /* i: class number, buf: pointer data, len: pointer length */
+#define DUK_DVALUE_POINTER     16  /* buf: pointer data, len: pointer length */
+#define DUK_DVALUE_LIGHTFUNC   17  /* i: lightfunc flags, buf: pointer data, len: pointer length */
+#define DUK_DVALUE_HEAPPTR     18  /* buf: pointer data, len: pointer length */
+
+struct duk_dvalue {
+	/* Could use a union for the value but the gain would be relatively small. */
+	int tag;
+	int i;
+	double d;
+	size_t len;
+	unsigned char *buf;
+};
+
+struct duk_trans_buffer {
+	unsigned char *base;
+	size_t write_offset;
+	size_t read_offset;
+	size_t alloc_size;
+};
+
+struct duk_trans_dvalue_ctx {
+	duk_trans_dvalue_received_function received;
+	duk_trans_dvalue_cooperate_function cooperate;
+	duk_trans_dvalue_handshake_function handshake;
+	duk_trans_dvalue_detached_function detached;
+	duk_trans_buffer send_buf;  /* sending towards Duktape (duktape read callback) */
+	duk_trans_buffer recv_buf;  /* receiving from Duktape (duktape write callback) */
+	int handshake_done;
+	int double_byteorder;  /* 0=little endian, 1=big endian, 2=mixed endian */
+};
+
+/* Buffer size needed by duk_dvalue_to_string(). */
+#define DUK_DVALUE_TOSTRING_BUFLEN 256
+
+/* Dvalue handling. */
+duk_dvalue *duk_dvalue_alloc(void);
+void duk_dvalue_free(duk_dvalue *dv);
+void duk_dvalue_to_string(duk_dvalue *dv, char *buf);
+duk_dvalue *duk_dvalue_make_tag(int tag);
+duk_dvalue *duk_dvalue_make_tag_int(int tag, int intval);
+duk_dvalue *duk_dvalue_make_tag_double(int tag, double dblval);
+duk_dvalue *duk_dvalue_make_tag_data(int tag, const char *buf, size_t len);
+duk_dvalue *duk_dvalue_make_tag_int_data(int tag, int intval, const char *buf, size_t len);
+
+/* Initializing and freeing the transport context. */
+duk_trans_dvalue_ctx *duk_trans_dvalue_init(void);
+void duk_trans_dvalue_free(duk_trans_dvalue_ctx *ctx);
+
+/* Sending dvalues towards Duktape. */
+void duk_trans_dvalue_send(duk_trans_dvalue_ctx *ctx, duk_dvalue *dv);
+void duk_trans_dvalue_send_eom(duk_trans_dvalue_ctx *ctx);
+void duk_trans_dvalue_send_req(duk_trans_dvalue_ctx *ctx);
+void duk_trans_dvalue_send_rep(duk_trans_dvalue_ctx *ctx);
+void duk_trans_dvalue_send_err(duk_trans_dvalue_ctx *ctx);
+void duk_trans_dvalue_send_nfy(duk_trans_dvalue_ctx *ctx);
+void duk_trans_dvalue_send_integer(duk_trans_dvalue_ctx *ctx, int val);
+void duk_trans_dvalue_send_string(duk_trans_dvalue_ctx *ctx, const char *str);
+void duk_trans_dvalue_send_lstring(duk_trans_dvalue_ctx *ctx, const char *str, size_t len);
+void duk_trans_dvalue_send_buffer(duk_trans_dvalue_ctx *ctx, const char *buf, size_t len);
+void duk_trans_dvalue_send_unused(duk_trans_dvalue_ctx *ctx);
+void duk_trans_dvalue_send_undefined(duk_trans_dvalue_ctx *ctx);
+void duk_trans_dvalue_send_null(duk_trans_dvalue_ctx *ctx);
+void duk_trans_dvalue_send_true(duk_trans_dvalue_ctx *ctx);
+void duk_trans_dvalue_send_false(duk_trans_dvalue_ctx *ctx);
+void duk_trans_dvalue_send_number(duk_trans_dvalue_ctx *ctx, double val);
+void duk_trans_dvalue_send_object(duk_trans_dvalue_ctx *ctx, int classnum, const char *ptr_data, size_t ptr_len);
+void duk_trans_dvalue_send_pointer(duk_trans_dvalue_ctx *ctx, const char *ptr_data, size_t ptr_len);
+void duk_trans_dvalue_send_lightfunc(duk_trans_dvalue_ctx *ctx, int lf_flags, const char *ptr_data, size_t ptr_len);
+void duk_trans_dvalue_send_heapptr(duk_trans_dvalue_ctx *ctx, const char *ptr_data, size_t ptr_len);
+void duk_trans_dvalue_send_req_cmd(duk_trans_dvalue_ctx *ctx, int cmd);
+
+/* Duktape debug callbacks provided by the transport. */
+duk_size_t duk_trans_dvalue_read_cb(void *udata, char *buffer, duk_size_t length);
+duk_size_t duk_trans_dvalue_write_cb(void *udata, const char *buffer, duk_size_t length);
+duk_size_t duk_trans_dvalue_peek_cb(void *udata);
+void duk_trans_dvalue_read_flush_cb(void *udata);
+void duk_trans_dvalue_write_flush_cb(void *udata);
+void duk_trans_dvalue_detached_cb(void *udata);
+
+#endif  /* DUK_TRANS_DVALUE_H_INCLUDED */

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/debug-trans-dvalue/test.c
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/debug-trans-dvalue/test.c b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/debug-trans-dvalue/test.c
new file mode 100644
index 0000000..7830ec2
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/debug-trans-dvalue/test.c
@@ -0,0 +1,236 @@
+/*
+ *  Example program using the dvalue debug transport.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "duktape.h"
+#include "duk_trans_dvalue.h"
+
+void my_cooperate(duk_trans_dvalue_ctx *ctx, int block) {
+	static int first_blocked = 1;
+
+	if (!block) {
+		/* Duktape is not blocked; you can cooperate with e.g. a user
+		 * interface here and send dvalues to Duktape, but don't block.
+		 */
+		return;
+	}
+
+	/* Duktape is blocked on a read and won't continue until debug
+	 * command(s) are sent.
+	 *
+	 * Normally you'd enter your own event loop here, and process
+	 * events until something needs to be sent to Duktape.  For
+	 * example, the user might press a "Step over" button in the
+	 * UI which would cause dvalues to be sent.  You can then
+	 * return from this callback.
+	 *
+	 * The code below sends some example messages for testing the
+	 * dvalue handling of the transport.
+	 *
+	 * If you create dvalues manually and send them using
+	 * duk_trans_dvalue_send(), you must free the dvalues after
+	 * the send call returns using duk_dvalue_free().
+	 */
+
+	if (first_blocked) {
+		char *tmp;
+		int i;
+
+		/* First time Duktape becomes blocked, send DumpHeap which
+		 * exercises a lot of parsing code.
+		 *
+		 * NOTE: Valgrind may complain about reading uninitialized
+		 * bytes.  This is caused by the DumpHeap command writing out
+		 * verbatim duk_tval values which are intentionally not
+		 * always fully initialized for performance reasons.
+		 */
+		first_blocked = 0;
+
+		fprintf(stderr, "Duktape is blocked, send DumpHeap\n");
+		fflush(stderr);
+
+		duk_trans_dvalue_send_req(ctx);
+		duk_trans_dvalue_send_integer(ctx, 0x20);  /* DumpHeap */
+		duk_trans_dvalue_send_eom(ctx);
+
+		/* Also send a dummy TriggerStatus request with trailing dvalues
+		 * ignored by Duktape; Duktape will parse the dvalues to be able to
+		 * skip them, so that the dvalue encoding is exercised.
+		 */
+
+		tmp = malloc(100000);  /* long buffer, >= 65536 chars */
+		for (i = 0; i < 100000; i++) {
+			tmp[i] = (char) i;
+		}
+		duk_trans_dvalue_send_req(ctx);
+		duk_trans_dvalue_send_integer(ctx, 0x11);  /* TriggerStatus */
+		duk_trans_dvalue_send_string(ctx, "dummy");  /* short, <= 31 chars */
+		duk_trans_dvalue_send_string(ctx, "123456789012345678901234567890foobar");  /* medium, >= 32 chars */
+		duk_trans_dvalue_send_lstring(ctx, (const char *) tmp, 65535UL);
+		duk_trans_dvalue_send_lstring(ctx, (const char *) tmp, 65536UL);
+		duk_trans_dvalue_send_lstring(ctx, (const char *) tmp, 100000UL);
+		duk_trans_dvalue_send_buffer(ctx, (const char *) tmp, 255U);
+		duk_trans_dvalue_send_buffer(ctx, (const char *) tmp, 65535UL);
+		duk_trans_dvalue_send_buffer(ctx, (const char *) tmp, 65536UL);
+		duk_trans_dvalue_send_buffer(ctx, (const char *) tmp, 100000UL);
+		duk_trans_dvalue_send_unused(ctx);
+		duk_trans_dvalue_send_undefined(ctx);
+		duk_trans_dvalue_send_null(ctx);
+		duk_trans_dvalue_send_true(ctx);
+		duk_trans_dvalue_send_false(ctx);
+		duk_trans_dvalue_send_number(ctx, 123.456);
+		duk_trans_dvalue_send_object(ctx, 12 /*classnum*/, (const char *) tmp, 8);  /* fake ptr len */
+		duk_trans_dvalue_send_pointer(ctx, (const char *) tmp, 8);  /* fake ptr len */
+		duk_trans_dvalue_send_lightfunc(ctx, 0xdabc /*lf_flags*/, (const char *) tmp, 8);  /* fake ptr len */
+		duk_trans_dvalue_send_heapptr(ctx, (const char *) tmp, 8);  /* fake ptr len */
+
+		duk_trans_dvalue_send_eom(ctx);
+	}
+
+	fprintf(stderr, "Duktape is blocked, send Eval and StepInto to resume execution\n");
+	fflush(stderr);
+
+	/* duk_trans_dvalue_send_req_cmd() sends a REQ dvalue followed by
+	 * an integer dvalue (command) for convenience.
+	 */
+
+	duk_trans_dvalue_send_req_cmd(ctx, 0x1e);  /* 0x1e = Eval */
+	duk_trans_dvalue_send_string(ctx, "evalMe");
+	duk_trans_dvalue_send_eom(ctx);
+
+	duk_trans_dvalue_send_req_cmd(ctx, 0x14);  /* 0x14 = StepOver */
+	duk_trans_dvalue_send_eom(ctx);
+}
+
+void my_received(duk_trans_dvalue_ctx *ctx, duk_dvalue *dv) {
+	char buf[DUK_DVALUE_TOSTRING_BUFLEN];
+	(void) ctx;
+
+	duk_dvalue_to_string(dv, buf);
+	fprintf(stderr, "Received dvalue: %s\n", buf);
+	fflush(stderr);
+
+	/* Here a normal debug client would wait for dvalues until an EOM
+	 * dvalue was received (which completes a debug message).  The
+	 * debug message would then be handled, possibly causing UI changes
+	 * and/or causing debug commands to be sent to Duktape.
+	 *
+	 * The callback is responsible for eventually freeing the dvalue.
+	 * Here we free it immediately, but an actual client would probably
+	 * gather dvalues into an array or linked list to handle when the
+	 * debug message was complete.
+	 */
+
+	duk_dvalue_free(dv);
+}
+
+void my_handshake(duk_trans_dvalue_ctx *ctx, const char *line) {
+	(void) ctx;
+
+	/* The Duktape handshake line is given in 'line' (without LF).
+	 * The 'line' argument can be accessed for the duration of the
+	 * callback (read only).  Don't free 'line' here, the transport
+	 * handles that.
+	 */
+
+	fprintf(stderr, "Received handshake line: '%s'\n", line);
+	fflush(stderr);
+}
+
+void my_detached(duk_trans_dvalue_ctx *ctx) {
+	(void) ctx;
+
+	/* Detached call forwarded as is. */
+
+	fprintf(stderr, "Debug transport detached\n");
+	fflush(stderr);
+}
+
+int main(int argc, char *argv[]) {
+	duk_context *ctx;
+	duk_trans_dvalue_ctx *trans_ctx;
+	int exitval = 0;
+
+	(void) argc; (void) argv;  /* suppress warning */
+
+	ctx = duk_create_heap_default();
+	if (!ctx) {
+		fprintf(stderr, "Failed to create Duktape heap\n");
+		fflush(stderr);
+		exitval = 1;
+		goto cleanup;
+	}
+
+	trans_ctx = duk_trans_dvalue_init();
+	if (!trans_ctx) {
+		fprintf(stderr, "Failed to create debug transport context\n");
+		fflush(stderr);
+		exitval = 1;
+		goto cleanup;
+	}
+	trans_ctx->cooperate = my_cooperate;
+	trans_ctx->received = my_received;
+	trans_ctx->handshake = my_handshake;
+	trans_ctx->detached = my_detached;
+
+	/* Attach debugger; this will fail with a fatal error here unless
+	 * debugger support is compiled in.  To fail more gracefully, call
+	 * this under a duk_safe_call() to catch the error.
+	 */
+	duk_debugger_attach(ctx,
+	                    duk_trans_dvalue_read_cb,
+	                    duk_trans_dvalue_write_cb,
+	                    duk_trans_dvalue_peek_cb,
+	                    duk_trans_dvalue_read_flush_cb,
+	                    duk_trans_dvalue_write_flush_cb,
+	                    duk_trans_dvalue_detached_cb,
+	                    (void *) trans_ctx);
+
+	fprintf(stderr, "Debugger attached, running eval\n");
+	fflush(stderr);
+
+	/* Evaluate simple test code, callbacks will "step over" until end.
+	 *
+	 * The test code here is just for exercising the debug transport.
+	 * The 'evalMe' variable is evaluated (using debugger command Eval)
+	 * before every step to force different dvalues to be carried over
+	 * the transport.
+	 */
+
+	duk_eval_string(ctx,
+		"var evalMe;\n"
+		"\n"
+		"print('Hello world!');\n"
+		"[ undefined, null, true, false, 123, -123, 123.1, 0, -0, 1/0, 0/0, -1/0, \n"
+		"  'foo', Duktape.Buffer('bar'), Duktape.Pointer('dummy'), Math.cos, \n"
+		"].forEach(function (val) {\n"
+		"    print(val);\n"
+		"    evalMe = val;\n"
+		"});\n"
+		"\n"
+		"var str = 'xxx'\n"
+		"for (i = 0; i < 10; i++) {\n"
+		"    print(i, str);\n"
+		"    evalMe = str;\n"
+		"    evalMe = Duktape.Buffer(str);\n"
+		"    str = str + str;\n"
+		"}\n"
+	);
+	duk_pop(ctx);
+
+	duk_debugger_detach(ctx);
+
+ cleanup:
+	if (trans_ctx) {
+		duk_trans_dvalue_free(trans_ctx);
+		trans_ctx = NULL;
+	}
+	if (ctx) {
+		duk_destroy_heap(ctx);
+	}
+
+	return exitval;
+}

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/debug-trans-socket/README.rst
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/debug-trans-socket/README.rst b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/debug-trans-socket/README.rst
new file mode 100644
index 0000000..78522cd
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/debug-trans-socket/README.rst
@@ -0,0 +1,17 @@
+================================================
+Debug transport using a simple socket connection
+================================================
+
+This example implements an example debug transport which uses a Linux or
+Windows TCP server socket on the debug target.
+
+Files:
+
+* ``duk_trans_socket.h``: header file for the transport, used for both Linux
+  and Windows socket variants.
+
+* ``duk_trans_socket_unix.c``: implementation for Linux/Unix.
+
+* ``duk_trans_socket_windows.c``: implementation for Windows.
+
+Compile either Unix or Windows source file only.

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/debug-trans-socket/duk_trans_socket.h
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/debug-trans-socket/duk_trans_socket.h b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/debug-trans-socket/duk_trans_socket.h
new file mode 100644
index 0000000..43f4a34
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/debug-trans-socket/duk_trans_socket.h
@@ -0,0 +1,15 @@
+#ifndef DUK_TRANS_SOCKET_H_INCLUDED
+#define DUK_TRANS_SOCKET_H_INCLUDED
+
+#include "duktape.h"
+
+void duk_trans_socket_init(void);
+void duk_trans_socket_finish(void);
+void duk_trans_socket_waitconn(void);
+duk_size_t duk_trans_socket_read_cb(void *udata, char *buffer, duk_size_t length);
+duk_size_t duk_trans_socket_write_cb(void *udata, const char *buffer, duk_size_t length);
+duk_size_t duk_trans_socket_peek_cb(void *udata);
+void duk_trans_socket_read_flush_cb(void *udata);
+void duk_trans_socket_write_flush_cb(void *udata);
+
+#endif  /* DUK_TRANS_SOCKET_H_INCLUDED */

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/debug-trans-socket/duk_trans_socket_unix.c
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/debug-trans-socket/duk_trans_socket_unix.c b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/debug-trans-socket/duk_trans_socket_unix.c
new file mode 100644
index 0000000..ac74de2
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/debug-trans-socket/duk_trans_socket_unix.c
@@ -0,0 +1,340 @@
+/*
+ *  Example debug transport using a Linux/Unix TCP socket
+ *
+ *  Provides a TCP server socket which a debug client can connect to.
+ *  After that data is just passed through.
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <unistd.h>
+#include <poll.h>
+#include <errno.h>
+#include "duktape.h"
+
+#if !defined(DUK_DEBUG_PORT)
+#define DUK_DEBUG_PORT 9091
+#endif
+
+#if 0
+#define DEBUG_PRINTS
+#endif
+
+static int server_sock = -1;
+static int client_sock = -1;
+
+/*
+ *  Transport init and finish
+ */
+
+void duk_trans_socket_init(void) {
+	struct sockaddr_in addr;
+	int on;
+
+	server_sock = socket(AF_INET, SOCK_STREAM, 0);
+	if (server_sock < 0) {
+		fprintf(stderr, "%s: failed to create server socket: %s\n",
+		        __FILE__, strerror(errno));
+		fflush(stderr);
+		goto fail;
+	}
+
+	on = 1;
+	if (setsockopt(server_sock, SOL_SOCKET, SO_REUSEADDR, (const char *) &on, sizeof(on)) < 0) {
+		fprintf(stderr, "%s: failed to set SO_REUSEADDR for server socket: %s\n",
+		        __FILE__, strerror(errno));
+		fflush(stderr);
+		goto fail;
+	}
+
+	memset((void *) &addr, 0, sizeof(addr));
+	addr.sin_family = AF_INET;
+	addr.sin_addr.s_addr = INADDR_ANY;
+	addr.sin_port = htons(DUK_DEBUG_PORT);
+
+	if (bind(server_sock, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
+		fprintf(stderr, "%s: failed to bind server socket: %s\n",
+		        __FILE__, strerror(errno));
+		fflush(stderr);
+		goto fail;
+	}
+
+	listen(server_sock, 1 /*backlog*/);
+	return;
+
+ fail:
+	if (server_sock >= 0) {
+		(void) close(server_sock);
+		server_sock = -1;
+	}
+}
+
+void duk_trans_socket_finish(void) {
+	if (client_sock >= 0) {
+		(void) close(client_sock);
+		client_sock = -1;
+	}
+	if (server_sock >= 0) {
+		(void) close(server_sock);
+		server_sock = -1;
+	}
+}
+
+void duk_trans_socket_waitconn(void) {
+	struct sockaddr_in addr;
+	socklen_t sz;
+
+	if (server_sock < 0) {
+		fprintf(stderr, "%s: no server socket, skip waiting for connection\n",
+		        __FILE__);
+		fflush(stderr);
+		return;
+	}
+	if (client_sock >= 0) {
+		(void) close(client_sock);
+		client_sock = -1;
+	}
+
+	fprintf(stderr, "Waiting for debug connection on port %d\n", (int) DUK_DEBUG_PORT);
+	fflush(stderr);
+
+	sz = (socklen_t) sizeof(addr);
+	client_sock = accept(server_sock, (struct sockaddr *) &addr, &sz);
+	if (client_sock < 0) {
+		fprintf(stderr, "%s: accept() failed, skip waiting for connection: %s\n",
+		        __FILE__, strerror(errno));
+		fflush(stderr);
+		goto fail;
+	}
+
+	fprintf(stderr, "Debug connection established\n");
+	fflush(stderr);
+
+	/* XXX: For now, close the listen socket because we won't accept new
+	 * connections anyway.  A better implementation would allow multiple
+	 * debug attaches.
+	 */
+
+	if (server_sock >= 0) {
+		(void) close(server_sock);
+		server_sock = -1;
+	}
+	return;
+
+ fail:
+	if (client_sock >= 0) {
+		(void) close(client_sock);
+		client_sock = -1;
+	}
+}
+
+/*
+ *  Duktape callbacks
+ */
+
+/* Duktape debug transport callback: (possibly partial) read. */
+duk_size_t duk_trans_socket_read_cb(void *udata, char *buffer, duk_size_t length) {
+	ssize_t ret;
+
+	(void) udata;  /* not needed by the example */
+
+#if defined(DEBUG_PRINTS)
+	fprintf(stderr, "%s: udata=%p, buffer=%p, length=%ld\n",
+	        __func__, (void *) udata, (void *) buffer, (long) length);
+	fflush(stderr);
+#endif
+
+	if (client_sock < 0) {
+		return 0;
+	}
+
+	if (length == 0) {
+		/* This shouldn't happen. */
+		fprintf(stderr, "%s: read request length == 0, closing connection\n",
+		        __FILE__);
+		fflush(stderr);
+		goto fail;
+	}
+
+	if (buffer == NULL) {
+		/* This shouldn't happen. */
+		fprintf(stderr, "%s: read request buffer == NULL, closing connection\n",
+		        __FILE__);
+		fflush(stderr);
+		goto fail;
+	}
+
+	/* In a production quality implementation there would be a sanity
+	 * timeout here to recover from "black hole" disconnects.
+	 */
+
+	ret = read(client_sock, (void *) buffer, (size_t) length);
+	if (ret < 0) {
+		fprintf(stderr, "%s: debug read failed, closing connection: %s\n",
+		        __FILE__, strerror(errno));
+		fflush(stderr);
+		goto fail;
+	} else if (ret == 0) {
+		fprintf(stderr, "%s: debug read failed, ret == 0 (EOF), closing connection\n",
+		        __FILE__);
+		fflush(stderr);
+		goto fail;
+	} else if (ret > (ssize_t) length) {
+		fprintf(stderr, "%s: debug read failed, ret too large (%ld > %ld), closing connection\n",
+		        __FILE__, (long) ret, (long) length);
+		fflush(stderr);
+		goto fail;
+	}
+
+	return (duk_size_t) ret;
+
+ fail:
+	if (client_sock >= 0) {
+		(void) close(client_sock);
+		client_sock = -1;
+	}
+	return 0;
+}
+
+/* Duktape debug transport callback: (possibly partial) write. */
+duk_size_t duk_trans_socket_write_cb(void *udata, const char *buffer, duk_size_t length) {
+	ssize_t ret;
+
+	(void) udata;  /* not needed by the example */
+
+#if defined(DEBUG_PRINTS)
+	fprintf(stderr, "%s: udata=%p, buffer=%p, length=%ld\n",
+	        __func__, (void *) udata, (const void *) buffer, (long) length);
+	fflush(stderr);
+#endif
+
+	if (client_sock < 0) {
+		return 0;
+	}
+
+	if (length == 0) {
+		/* This shouldn't happen. */
+		fprintf(stderr, "%s: write request length == 0, closing connection\n",
+		        __FILE__);
+		fflush(stderr);
+		goto fail;
+	}
+
+	if (buffer == NULL) {
+		/* This shouldn't happen. */
+		fprintf(stderr, "%s: write request buffer == NULL, closing connection\n",
+		        __FILE__);
+		fflush(stderr);
+		goto fail;
+	}
+
+	/* In a production quality implementation there would be a sanity
+	 * timeout here to recover from "black hole" disconnects.
+	 */
+
+	ret = write(client_sock, (const void *) buffer, (size_t) length);
+	if (ret <= 0 || ret > (ssize_t) length) {
+		fprintf(stderr, "%s: debug write failed, closing connection: %s\n",
+		        __FILE__, strerror(errno));
+		fflush(stderr);
+		goto fail;
+	}
+
+	return (duk_size_t) ret;
+
+ fail:
+	if (client_sock >= 0) {
+		(void) close(client_sock);
+		client_sock = -1;
+	}
+	return 0;
+}
+
+duk_size_t duk_trans_socket_peek_cb(void *udata) {
+	struct pollfd fds[1];
+	int poll_rc;
+
+	(void) udata;  /* not needed by the example */
+
+#if defined(DEBUG_PRINTS)
+	fprintf(stderr, "%s: udata=%p\n", __func__, (void *) udata);
+	fflush(stderr);
+#endif
+
+	if (client_sock < 0) {
+		return 0;
+	}
+
+	fds[0].fd = client_sock;
+	fds[0].events = POLLIN;
+	fds[0].revents = 0;
+
+	poll_rc = poll(fds, 1, 0);
+	if (poll_rc < 0) {
+		fprintf(stderr, "%s: poll returned < 0, closing connection: %s\n",
+		        __FILE__, strerror(errno));
+		fflush(stderr);
+		goto fail;  /* also returns 0, which is correct */
+	} else if (poll_rc > 1) {
+		fprintf(stderr, "%s: poll returned > 1, treating like 1\n",
+		        __FILE__);
+		fflush(stderr);
+		return 1;  /* should never happen */
+	} else if (poll_rc == 0) {
+		return 0;  /* nothing to read */
+	} else {
+		return 1;  /* something to read */
+	}
+
+ fail:
+	if (client_sock >= 0) {
+		(void) close(client_sock);
+		client_sock = -1;
+	}
+	return 0;
+}
+
+void duk_trans_socket_read_flush_cb(void *udata) {
+	(void) udata;  /* not needed by the example */
+
+#if defined(DEBUG_PRINTS)
+	fprintf(stderr, "%s: udata=%p\n", __func__, (void *) udata);
+	fflush(stderr);
+#endif
+
+	/* Read flush: Duktape may not be making any more read calls at this
+	 * time.  If the transport maintains a receive window, it can use a
+	 * read flush as a signal to update the window status to the remote
+	 * peer.  A read flush is guaranteed to occur before Duktape stops
+	 * reading for a while; it may occur in other situations as well so
+	 * it's not a 100% reliable indication.
+	 */
+
+	/* This TCP transport requires no read flush handling so ignore.
+	 * You can also pass a NULL to duk_debugger_attach() and not
+	 * implement this callback at all.
+	 */
+}
+
+void duk_trans_socket_write_flush_cb(void *udata) {
+	(void) udata;  /* not needed by the example */
+
+#if defined(DEBUG_PRINTS)
+	fprintf(stderr, "%s: udata=%p\n", __func__, (void *) udata);
+	fflush(stderr);
+#endif
+
+	/* Write flush.  If the transport combines multiple writes
+	 * before actually sending, a write flush is an indication
+	 * to write out any pending bytes: Duktape may not be doing
+	 * any more writes on this occasion.
+	 */
+
+	/* This TCP transport requires no write flush handling so ignore.
+	 * You can also pass a NULL to duk_debugger_attach() and not
+	 * implement this callback at all.
+	 */
+	return;
+}

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/debug-trans-socket/duk_trans_socket_windows.c
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/debug-trans-socket/duk_trans_socket_windows.c b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/debug-trans-socket/duk_trans_socket_windows.c
new file mode 100644
index 0000000..e92ac26
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/debug-trans-socket/duk_trans_socket_windows.c
@@ -0,0 +1,414 @@
+/*
+ *  Example debug transport using a Windows TCP socket
+ *
+ *  Provides a TCP server socket which a debug client can connect to.
+ *  After that data is just passed through.
+ *
+ *  https://msdn.microsoft.com/en-us/library/windows/desktop/ms737593(v=vs.85).aspx
+ *
+ *  Compiling 'duk' with debugger support using MSVC (Visual Studio):
+ *
+ *    > cl /W3 /O2 /Feduk.exe
+ *          /DDUK_OPT_DEBUGGER_SUPPORT /DDUK_OPT_INTERRUPT_COUNTER
+ *          /DDUK_CMDLINE_DEBUGGER_SUPPORT
+ *          /Iexamples\debug-trans-socket /Isrc
+ *          examples\cmdline\duk_cmdline.c
+ *          examples\debug-trans-socket\duk_trans_socket_windows.c
+ *          src\duktape.c
+ *
+ *  With MinGW:
+ *
+ *    $ gcc -oduk.exe -Wall -O2 \
+ *          -DDUK_OPT_DEBUGGER_SUPPORT -DDUK_OPT_INTERRUPT_COUNTER \
+ *          -DDUK_CMDLINE_DEBUGGER_SUPPORT \
+ *          -Iexamples/debug-trans-socket -Isrc \
+ *          examples/cmdline/duk_cmdline.c \
+ *          examples/debug-trans-socket/duk_trans_socket_windows.c \
+ *          src/duktape.c -lm -lws2_32
+ */
+
+#undef UNICODE
+#if !defined(WIN32_LEAN_AND_MEAN)
+#define WIN32_LEAN_AND_MEAN
+#endif
+
+/* MinGW workaround for missing getaddrinfo() etc:
+ * http://programmingrants.blogspot.fi/2009/09/tips-on-undefined-reference-to.html
+ */
+#if defined(__MINGW32__) || defined(__MINGW64__)
+#if !defined(_WIN32_WINNT)
+#define _WIN32_WINNT 0x0501
+#endif
+#endif
+
+#include <windows.h>
+#include <winsock2.h>
+#include <ws2tcpip.h>
+#include <stdio.h>
+#include <string.h>
+#include "duktape.h"
+
+#if defined(_MSC_VER)
+#pragma comment (lib, "Ws2_32.lib")
+#endif
+
+#if !defined(DUK_DEBUG_PORT)
+#define DUK_DEBUG_PORT 9091
+#endif
+#if !defined(DUK_DEBUG_ADDRESS)
+#define DUK_DEBUG_ADDRESS "0.0.0.0"
+#endif
+#define DUK__STRINGIFY_HELPER(x) #x
+#define DUK__STRINGIFY(x) DUK__STRINGIFY_HELPER(x)
+
+#if 0
+#define DEBUG_PRINTS
+#endif
+
+static SOCKET server_sock = INVALID_SOCKET;
+static SOCKET client_sock = INVALID_SOCKET;
+static int wsa_inited = 0;
+
+/*
+ *  Transport init and finish
+ */
+
+void duk_trans_socket_init(void) {
+	WSADATA wsa_data;
+	struct addrinfo hints;
+	struct addrinfo *result = NULL;
+	int rc;
+
+	memset((void *) &wsa_data, 0, sizeof(wsa_data));
+	memset((void *) &hints, 0, sizeof(hints));
+
+	rc = WSAStartup(MAKEWORD(2, 2), &wsa_data);
+	if (rc != 0) {
+		fprintf(stderr, "%s: WSAStartup() failed: %d\n", __FILE__, rc);
+		fflush(stderr);
+		goto fail;
+	}
+	wsa_inited = 1;
+
+	hints.ai_family = AF_UNSPEC;
+	hints.ai_socktype = SOCK_STREAM;
+	hints.ai_protocol = IPPROTO_TCP;
+	hints.ai_flags = AI_PASSIVE;
+
+	rc = getaddrinfo(DUK_DEBUG_ADDRESS, DUK__STRINGIFY(DUK_DEBUG_PORT), &hints, &result);
+	if (rc != 0) {
+		fprintf(stderr, "%s: getaddrinfo() failed: %d\n", __FILE__, rc);
+		fflush(stderr);
+		goto fail;
+	}
+
+	server_sock = socket(result->ai_family, result->ai_socktype, result->ai_protocol);
+	if (server_sock == INVALID_SOCKET) {
+		fprintf(stderr, "%s: socket() failed with error: %ld\n",
+		        __FILE__, (long) WSAGetLastError());
+		fflush(stderr);
+		goto fail;
+	}
+
+	rc = bind(server_sock, result->ai_addr, (int) result->ai_addrlen);
+	if (rc == SOCKET_ERROR) {
+		fprintf(stderr, "%s: bind() failed with error: %ld\n",
+		        __FILE__, (long) WSAGetLastError());
+		fflush(stderr);
+		goto fail;
+	}
+
+	rc = listen(server_sock, SOMAXCONN);
+	if (rc == SOCKET_ERROR) {
+		fprintf(stderr, "%s: listen() failed with error: %ld\n",
+		        __FILE__, (long) WSAGetLastError());
+		fflush(stderr);
+		goto fail;
+	}
+
+	if (result != NULL) {
+		freeaddrinfo(result);
+		result = NULL;
+	}
+	return;
+
+ fail:
+	if (result != NULL) {
+		freeaddrinfo(result);
+		result = NULL;
+	}
+	if (server_sock != INVALID_SOCKET) {
+		(void) closesocket(server_sock);
+		server_sock = INVALID_SOCKET;
+	}
+	if (wsa_inited) {
+		WSACleanup();
+		wsa_inited = 0;
+	}
+}
+
+void duk_trans_socket_finish(void) {
+	if (client_sock != INVALID_SOCKET) {
+		(void) closesocket(client_sock);
+		client_sock = INVALID_SOCKET;
+	}
+	if (server_sock != INVALID_SOCKET) {
+		(void) closesocket(server_sock);
+		server_sock = INVALID_SOCKET;
+	}
+	if (wsa_inited) {
+		WSACleanup();
+		wsa_inited = 0;
+	}
+}
+
+void duk_trans_socket_waitconn(void) {
+	if (server_sock == INVALID_SOCKET) {
+		fprintf(stderr, "%s: no server socket, skip waiting for connection\n",
+		        __FILE__);
+		fflush(stderr);
+		return;
+	}
+	if (client_sock != INVALID_SOCKET) {
+		(void) closesocket(client_sock);
+		client_sock = INVALID_SOCKET;
+	}
+
+	fprintf(stderr, "Waiting for debug connection on port %d\n", (int) DUK_DEBUG_PORT);
+	fflush(stderr);
+
+	client_sock = accept(server_sock, NULL, NULL);
+	if (client_sock == INVALID_SOCKET) {
+		fprintf(stderr, "%s: accept() failed with error %ld, skip waiting for connection\n",
+		        __FILE__, (long) WSAGetLastError());
+		fflush(stderr);
+		goto fail;
+	}
+
+	fprintf(stderr, "Debug connection established\n");
+	fflush(stderr);
+
+	/* XXX: For now, close the listen socket because we won't accept new
+	 * connections anyway.  A better implementation would allow multiple
+	 * debug attaches.
+	 */
+
+	if (server_sock != INVALID_SOCKET) {
+		(void) closesocket(server_sock);
+		server_sock = INVALID_SOCKET;
+	}
+	return;
+
+ fail:
+	if (client_sock != INVALID_SOCKET) {
+		(void) closesocket(client_sock);
+		client_sock = INVALID_SOCKET;
+	}
+}
+
+/*
+ *  Duktape callbacks
+ */
+
+/* Duktape debug transport callback: (possibly partial) read. */
+duk_size_t duk_trans_socket_read_cb(void *udata, char *buffer, duk_size_t length) {
+	int ret;
+
+	(void) udata;  /* not needed by the example */
+
+#if defined(DEBUG_PRINTS)
+	fprintf(stderr, "%s: udata=%p, buffer=%p, length=%ld\n",
+	        __FUNCTION__, (void *) udata, (void *) buffer, (long) length);
+	fflush(stderr);
+#endif
+
+	if (client_sock == INVALID_SOCKET) {
+		return 0;
+	}
+
+	if (length == 0) {
+		/* This shouldn't happen. */
+		fprintf(stderr, "%s: read request length == 0, closing connection\n",
+		        __FILE__);
+		fflush(stderr);
+		goto fail;
+	}
+
+	if (buffer == NULL) {
+		/* This shouldn't happen. */
+		fprintf(stderr, "%s: read request buffer == NULL, closing connection\n",
+		        __FILE__);
+		fflush(stderr);
+		goto fail;
+	}
+
+	/* In a production quality implementation there would be a sanity
+	 * timeout here to recover from "black hole" disconnects.
+	 */
+
+	ret = recv(client_sock, (void *) buffer, (int) length, 0);
+	if (ret < 0) {
+		fprintf(stderr, "%s: debug read failed, error %d, closing connection\n",
+		        __FILE__, ret);
+		fflush(stderr);
+		goto fail;
+	} else if (ret == 0) {
+		fprintf(stderr, "%s: debug read failed, ret == 0 (EOF), closing connection\n",
+		        __FILE__);
+		fflush(stderr);
+		goto fail;
+	} else if (ret > (int) length) {
+		fprintf(stderr, "%s: debug read failed, ret too large (%ld > %ld), closing connection\n",
+		        __FILE__, (long) ret, (long) length);
+		fflush(stderr);
+		goto fail;
+	}
+
+	return (duk_size_t) ret;
+
+ fail:
+	if (client_sock != INVALID_SOCKET) {
+		(void) closesocket(client_sock);
+		client_sock = INVALID_SOCKET;
+	}
+	return 0;
+}
+
+/* Duktape debug transport callback: (possibly partial) write. */
+duk_size_t duk_trans_socket_write_cb(void *udata, const char *buffer, duk_size_t length) {
+	int ret;
+
+	(void) udata;  /* not needed by the example */
+
+#if defined(DEBUG_PRINTS)
+	fprintf(stderr, "%s: udata=%p, buffer=%p, length=%ld\n",
+	        __FUNCTION__, (void *) udata, (const void *) buffer, (long) length);
+	fflush(stderr);
+#endif
+
+	if (client_sock == INVALID_SOCKET) {
+		return 0;
+	}
+
+	if (length == 0) {
+		/* This shouldn't happen. */
+		fprintf(stderr, "%s: write request length == 0, closing connection\n",
+		        __FILE__);
+		fflush(stderr);
+		goto fail;
+	}
+
+	if (buffer == NULL) {
+		/* This shouldn't happen. */
+		fprintf(stderr, "%s: write request buffer == NULL, closing connection\n",
+		        __FILE__);
+		fflush(stderr);
+		goto fail;
+	}
+
+	/* In a production quality implementation there would be a sanity
+	 * timeout here to recover from "black hole" disconnects.
+	 */
+
+	ret = send(client_sock, (const void *) buffer, (int) length, 0);
+	if (ret <= 0 || ret > (int) length) {
+		fprintf(stderr, "%s: debug write failed, ret %d, closing connection\n",
+		        __FILE__, ret);
+		fflush(stderr);
+		goto fail;
+	}
+
+	return (duk_size_t) ret;
+
+ fail:
+	if (client_sock != INVALID_SOCKET) {
+		(void) closesocket(INVALID_SOCKET);
+		client_sock = INVALID_SOCKET;
+	}
+	return 0;
+}
+
+duk_size_t duk_trans_socket_peek_cb(void *udata) {
+	u_long avail;
+	int rc;
+
+	(void) udata;  /* not needed by the example */
+
+#if defined(DEBUG_PRINTS)
+	fprintf(stderr, "%s: udata=%p\n", __FUNCTION__, (void *) udata);
+	fflush(stderr);
+#endif
+
+	if (client_sock == INVALID_SOCKET) {
+		return 0;
+	}
+
+	avail = 0;
+	rc = ioctlsocket(client_sock, FIONREAD, &avail);
+	if (rc != 0) {
+		fprintf(stderr, "%s: ioctlsocket() returned %d, closing connection\n",
+		        __FILE__, rc);
+		fflush(stderr);
+		goto fail;  /* also returns 0, which is correct */
+	} else {
+		if (avail == 0) {
+			return 0;  /* nothing to read */
+		} else {
+			return 1;  /* something to read */
+		}
+	}
+	/* never here */
+
+ fail:
+	if (client_sock != INVALID_SOCKET) {
+		(void) closesocket(client_sock);
+		client_sock = INVALID_SOCKET;
+	}
+	return 0;
+}
+
+void duk_trans_socket_read_flush_cb(void *udata) {
+	(void) udata;  /* not needed by the example */
+
+#if defined(DEBUG_PRINTS)
+	fprintf(stderr, "%s: udata=%p\n", __FUNCTION__, (void *) udata);
+	fflush(stderr);
+#endif
+
+	/* Read flush: Duktape may not be making any more read calls at this
+	 * time.  If the transport maintains a receive window, it can use a
+	 * read flush as a signal to update the window status to the remote
+	 * peer.  A read flush is guaranteed to occur before Duktape stops
+	 * reading for a while; it may occur in other situations as well so
+	 * it's not a 100% reliable indication.
+	 */
+
+	/* This TCP transport requires no read flush handling so ignore.
+	 * You can also pass a NULL to duk_debugger_attach() and not
+	 * implement this callback at all.
+	 */
+}
+
+void duk_trans_socket_write_flush_cb(void *udata) {
+	(void) udata;  /* not needed by the example */
+
+#if defined(DEBUG_PRINTS)
+	fprintf(stderr, "%s: udata=%p\n", __FUNCTION__, (void *) udata);
+	fflush(stderr);
+#endif
+
+	/* Write flush.  If the transport combines multiple writes
+	 * before actually sending, a write flush is an indication
+	 * to write out any pending bytes: Duktape may not be doing
+	 * any more writes on this occasion.
+	 */
+
+	/* This TCP transport requires no write flush handling so ignore.
+	 * You can also pass a NULL to duk_debugger_attach() and not
+	 * implement this callback at all.
+	 */
+	return;
+}
+
+#undef DUK__STRINGIFY_HELPER
+#undef DUK__STRINGIFY

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/dummy-date-provider/README.rst
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/dummy-date-provider/README.rst b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/dummy-date-provider/README.rst
new file mode 100644
index 0000000..bc62779
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/dummy-date-provider/README.rst
@@ -0,0 +1,5 @@
+====================================
+Dummy external Date provider example
+====================================
+
+This example implements a dummy, minimal external Date provider.

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/dummy-date-provider/dummy_date_provider.c
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/dummy-date-provider/dummy_date_provider.c b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/dummy-date-provider/dummy_date_provider.c
new file mode 100644
index 0000000..9c9e716
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/dummy-date-provider/dummy_date_provider.c
@@ -0,0 +1,27 @@
+/*
+ *  Dummy Date provider
+ *
+ *  There are two minimally required macros which you must provide in
+ *  duk_config.h:
+ *
+ *    extern duk_double_t dummy_get_now(void);
+ *
+ *    #define DUK_USE_DATE_GET_NOW(ctx) dummy_get_now()
+ *    #define DUK_USE_DATE_GET_LOCAL_TZOFFSET(d)  0
+ *
+ *  Note that since the providers are macros, you don't need to use
+ *  all arguments.  Similarly, you can "return" fixed values as
+ *  constants.  Above, local timezone offset is always zero i.e.
+ *  we're always in UTC.
+ *
+ *  You can also provide optional macros to parse and format timestamps
+ *  in a platform specific format.  If not provided, Duktape will use
+ *  ISO 8601 only (which is often good enough).
+ */
+
+#include "duktape.h"
+
+duk_double_t dummy_get_now(void) {
+	/* Return a fixed time here as a dummy example. */
+	return -11504520000.0;
+}

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/eval/README.rst
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/eval/README.rst b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/eval/README.rst
new file mode 100644
index 0000000..eed1806
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/eval/README.rst
@@ -0,0 +1,5 @@
+============
+Eval example
+============
+
+Evaluate expressions from command line.

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/eval/eval.c
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/eval/eval.c b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/eval/eval.c
new file mode 100644
index 0000000..4409926
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/eval/eval.c
@@ -0,0 +1,48 @@
+/*
+ *  Very simple example program for evaluating expressions from
+ *  command line
+ */
+
+#include "duktape.h"
+#include <stdio.h>
+
+static int eval_raw(duk_context *ctx) {
+	duk_eval(ctx);
+	return 1;
+}
+
+static int tostring_raw(duk_context *ctx) {
+	duk_to_string(ctx, -1);
+	return 1;
+}
+
+static void usage_exit(void) {
+	fprintf(stderr, "Usage: eval <expression> [<expression>] ...\n");
+	fflush(stderr);
+	exit(1);
+}
+
+int main(int argc, char *argv[]) {
+	duk_context *ctx;
+	int i;
+	const char *res;
+
+	if (argc < 2) {
+		usage_exit();
+	}
+
+	ctx = duk_create_heap_default();
+	for (i = 1; i < argc; i++) {
+		printf("=== eval: '%s' ===\n", argv[i]);
+		duk_push_string(ctx, argv[i]);
+		duk_safe_call(ctx, eval_raw, 1 /*nargs*/, 1 /*nrets*/);
+		duk_safe_call(ctx, tostring_raw, 1 /*nargs*/, 1 /*nrets*/);
+		res = duk_get_string(ctx, -1);
+		printf("%s\n", res ? res : "null");
+		duk_pop(ctx);
+	}
+
+	duk_destroy_heap(ctx);
+
+	return 0;
+}


[06/51] [partial] nifi-minifi-cpp git commit: MINIFI-183 Added civet 1.9.1 sources Added onScheduled hook Added initial two-way TLS-enabled ListenHTTP implementation

Posted by al...@apache.org.
http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_config.h
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_config.h b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_config.h
new file mode 100644
index 0000000..ef62235
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_config.h
@@ -0,0 +1,3804 @@
+/*
+ *  duk_config.h configuration header generated by genconfig.py.
+ *
+ *  Git commit: cad34ae155acb0846545ca6bf2d29f9463b22bbb
+ *  Git describe: v1.5.2
+ *  Git branch: HEAD
+ *
+ *  Supported platforms:
+ *      - Mac OSX, iPhone, Darwin
+ *      - OpenBSD
+ *      - Generic BSD
+ *      - Atari ST TOS
+ *      - AmigaOS
+ *      - Windows
+ *      - Flashplayer (Crossbridge)
+ *      - QNX
+ *      - TI-Nspire
+ *      - Emscripten
+ *      - Linux
+ *      - Solaris
+ *      - Generic POSIX
+ *      - Cygwin
+ *      - Generic UNIX
+ *      - Generic fallback
+ *
+ *  Supported architectures:
+ *      - x86
+ *      - x64
+ *      - x32
+ *      - ARM 32-bit
+ *      - ARM 64-bit
+ *      - MIPS 32-bit
+ *      - MIPS 64-bit
+ *      - PowerPC 32-bit
+ *      - PowerPC 64-bit
+ *      - SPARC 32-bit
+ *      - SPARC 64-bit
+ *      - SuperH
+ *      - Motorola 68k
+ *      - Emscripten
+ *      - Generic
+ *
+ *  Supported compilers:
+ *      - Clang
+ *      - GCC
+ *      - MSVC
+ *      - Emscripten
+ *      - TinyC
+ *      - VBCC
+ *      - Bruce's C compiler
+ *      - Generic
+ *
+ */
+
+#if !defined(DUK_CONFIG_H_INCLUDED)
+#define DUK_CONFIG_H_INCLUDED
+
+/*
+ *  Intermediate helper defines
+ */
+
+/* DLL build detection */
+#if defined(DUK_OPT_DLL_BUILD)
+#define DUK_F_DLL_BUILD
+#elif defined(DUK_OPT_NO_DLL_BUILD)
+#undef DUK_F_DLL_BUILD
+#else
+/* not configured for DLL build */
+#undef DUK_F_DLL_BUILD
+#endif
+
+/* Apple OSX, iOS */
+#if defined(__APPLE__)
+#define DUK_F_APPLE
+#endif
+
+/* OpenBSD */
+#if defined(__OpenBSD__) || defined(__OpenBSD)
+#define DUK_F_OPENBSD
+#endif
+
+/* NetBSD */
+#if defined(__NetBSD__) || defined(__NetBSD)
+#define DUK_F_NETBSD
+#endif
+
+/* FreeBSD */
+#if defined(__FreeBSD__) || defined(__FreeBSD)
+#define DUK_F_FREEBSD
+#endif
+
+/* BSD variant */
+#if defined(DUK_F_FREEBSD) || defined(DUK_F_NETBSD) || defined(DUK_F_OPENBSD) || \
+    defined(__bsdi__) || defined(__DragonFly__)
+#define DUK_F_BSD
+#endif
+
+/* Atari ST TOS.  __TOS__ defined by PureC.  No platform define in VBCC
+ * apparently, so to use with VBCC user must define __TOS__ manually.
+  */
+#if defined(__TOS__)
+#define DUK_F_TOS
+#endif
+
+/* Motorola 68K.  Not defined by VBCC, so user must define one of these
+ * manually when using VBCC.
+ */
+#if defined(__m68k__) || defined(M68000) || defined(__MC68K__)
+#define DUK_F_M68K
+#endif
+
+/* AmigaOS.  Neither AMIGA nor __amigaos__ is defined on VBCC, so user must
+ * define 'AMIGA' manually when using VBCC.
+ */
+#if defined(AMIGA) || defined(__amigaos__)
+#define DUK_F_AMIGAOS
+#endif
+
+/* PowerPC */
+#if defined(__powerpc) || defined(__powerpc__) || defined(__PPC__)
+#define DUK_F_PPC
+#if defined(__PPC64__) || defined(__LP64__) || defined(_LP64)
+#define DUK_F_PPC64
+#else
+#define DUK_F_PPC32
+#endif
+#endif
+
+/* Windows, both 32-bit and 64-bit */
+#if defined(_WIN32) || defined(WIN32) || defined(_WIN64) || defined(WIN64) || \
+    defined(__WIN32__) || defined(__TOS_WIN__) || defined(__WINDOWS__)
+#define DUK_F_WINDOWS
+#if defined(_WIN64) || defined(WIN64)
+#define DUK_F_WIN64
+#else
+#define DUK_F_WIN32
+#endif
+#endif
+
+/* Flash player (e.g. Crossbridge) */
+#if defined(__FLASHPLAYER__)
+#define DUK_F_FLASHPLAYER
+#endif
+
+/* QNX */
+#if defined(__QNX__)
+#define DUK_F_QNX
+#endif
+
+/* TI-Nspire (using Ndless) */
+#if defined(_TINSPIRE)
+#define DUK_F_TINSPIRE
+#endif
+
+/* Emscripten (provided explicitly by user), improve if possible */
+#if defined(EMSCRIPTEN)
+#define DUK_F_EMSCRIPTEN
+#endif
+
+/* BCC (Bruce's C compiler): this is a "torture target" for compilation */
+#if defined(__BCC__) || defined(__BCC_VERSION__)
+#define DUK_F_BCC
+#endif
+
+/* Linux */
+#if defined(__linux) || defined(__linux__) || defined(linux)
+#define DUK_F_LINUX
+#endif
+
+/* illumos / Solaris */
+#if defined(__sun) && defined(__SVR4)
+#define DUK_F_SUN
+#endif
+
+/* POSIX */
+#if defined(__posix)
+#define DUK_F_POSIX
+#endif
+
+/* Cygwin */
+#if defined(__CYGWIN__)
+#define DUK_F_CYGWIN
+#endif
+
+/* Generic Unix (includes Cygwin) */
+#if defined(__unix) || defined(__unix__) || defined(unix) || \
+    defined(DUK_F_LINUX) || defined(DUK_F_BSD)
+#define DUK_F_UNIX
+#endif
+
+/* stdint.h not available */
+#if defined(DUK_F_WINDOWS) && defined(_MSC_VER)
+#if (_MSC_VER < 1700)
+/* VS2012+ has stdint.h, < VS2012 does not (but it's available for download). */
+#define DUK_F_NO_STDINT_H
+#endif
+#endif
+#if !defined(DUK_F_NO_STDINT_H) && (defined(DUK_F_TOS) || defined(DUK_F_BCC))
+#define DUK_F_NO_STDINT_H
+#endif
+
+/* C++ */
+#undef DUK_F_CPP
+#if defined(__cplusplus)
+#define DUK_F_CPP
+#endif
+
+/* Intel x86 (32-bit), x64 (64-bit) or x32 (64-bit but 32-bit pointers),
+ * define only one of DUK_F_X86, DUK_F_X64, DUK_F_X32.
+ * https://sites.google.com/site/x32abi/
+ */
+#if defined(__amd64__) || defined(__amd64) || \
+    defined(__x86_64__) || defined(__x86_64) || \
+    defined(_M_X64) || defined(_M_AMD64)
+#if defined(__ILP32__) || defined(_ILP32)
+#define DUK_F_X32
+#else
+#define DUK_F_X64
+#endif
+#elif defined(i386) || defined(__i386) || defined(__i386__) || \
+      defined(__i486__) || defined(__i586__) || defined(__i686__) || \
+      defined(__IA32__) || defined(_M_IX86) || defined(__X86__) || \
+      defined(_X86_) || defined(__THW_INTEL__) || defined(__I86__)
+#if defined(__LP64__) || defined(_LP64)
+/* This should not really happen, but would indicate x64. */
+#define DUK_F_X64
+#else
+#define DUK_F_X86
+#endif
+#endif
+
+/* ARM */
+#if defined(__arm__) || defined(__thumb__) || defined(_ARM) || defined(_M_ARM)
+#define DUK_F_ARM
+#if defined(__LP64__) || defined(_LP64) || defined(__arm64) || defined(__arm64__)
+#define DUK_F_ARM64
+#else
+#define DUK_F_ARM32
+#endif
+#endif
+
+/* MIPS.  Related defines: __MIPSEB__, __MIPSEL__, __mips_isa_rev, __LP64__ */
+#if defined(__mips__) || defined(mips) || defined(_MIPS_ISA) || \
+    defined(_R3000) || defined(_R4000) || defined(_R5900) || \
+    defined(_MIPS_ISA_MIPS1) || defined(_MIPS_ISA_MIPS2) || \
+    defined(_MIPS_ISA_MIPS3) || defined(_MIPS_ISA_MIPS4) || \
+    defined(__mips) || defined(__MIPS__)
+#define DUK_F_MIPS
+#if defined(__LP64__) || defined(_LP64) || defined(__mips64) || \
+    defined(__mips64__) || defined(__mips_n64)
+#define DUK_F_MIPS64
+#else
+#define DUK_F_MIPS32
+#endif
+#endif
+
+/* SPARC */
+#if defined(sparc) || defined(__sparc) || defined(__sparc__)
+#define DUK_F_SPARC
+#if defined(__LP64__) || defined(_LP64)
+#define DUK_F_SPARC64
+#else
+#define DUK_F_SPARC32
+#endif
+#endif
+
+/* SuperH */
+#if defined(__sh__) || \
+    defined(__sh1__) || defined(__SH1__) || \
+    defined(__sh2__) || defined(__SH2__) || \
+    defined(__sh3__) || defined(__SH3__) || \
+    defined(__sh4__) || defined(__SH4__) || \
+    defined(__sh5__) || defined(__SH5__)
+#define DUK_F_SUPERH
+#endif
+
+/* Clang */
+#if defined(__clang__)
+#define DUK_F_CLANG
+#endif
+
+/* C99 or above */
+#undef DUK_F_C99
+#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
+#define DUK_F_C99
+#endif
+
+/* C++11 or above */
+#undef DUK_F_CPP11
+#if defined(__cplusplus) && (__cplusplus >= 201103L)
+#define DUK_F_CPP11
+#endif
+
+/* GCC.  Clang also defines __GNUC__ so don't detect GCC if using Clang. */
+#if defined(__GNUC__) && !defined(__clang__) && !defined(DUK_F_CLANG)
+#define DUK_F_GCC
+#if defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__)
+/* Convenience, e.g. gcc 4.5.1 == 40501; http://stackoverflow.com/questions/6031819/emulating-gccs-builtin-unreachable */
+#define DUK_F_GCC_VERSION  (__GNUC__ * 10000L + __GNUC_MINOR__ * 100L + __GNUC_PATCHLEVEL__)
+#else
+#error cannot figure out gcc version
+#endif
+#endif
+
+/* MinGW.  Also GCC flags (DUK_F_GCC) are enabled now. */
+#if defined(__MINGW32__) || defined(__MINGW64__)
+#define DUK_F_MINGW
+#endif
+
+/* MSVC */
+#if defined(_MSC_VER)
+/* MSVC preprocessor defines: http://msdn.microsoft.com/en-us/library/b0084kay.aspx
+ * _MSC_FULL_VER includes the build number, but it has at least two formats, see e.g.
+ * BOOST_MSVC_FULL_VER in http://www.boost.org/doc/libs/1_52_0/boost/config/compiler/visualc.hpp
+ */
+#define DUK_F_MSVC
+#if defined(_MSC_FULL_VER)
+#if (_MSC_FULL_VER > 100000000)
+#define DUK_F_MSVC_FULL_VER _MSC_FULL_VER
+#else
+#define DUK_F_MSCV_FULL_VER (_MSC_FULL_VER * 10)
+#endif
+#endif
+#endif  /* _MSC_VER */
+
+/* TinyC */
+#if defined(__TINYC__)
+/* http://bellard.org/tcc/tcc-doc.html#SEC9 */
+#define DUK_F_TINYC
+#endif
+
+/* VBCC */
+#if defined(__VBCC__)
+#define DUK_F_VBCC
+#endif
+
+/* Atari Mint */
+#if defined(__MINT__)
+#define DUK_F_MINT
+#endif
+
+/*
+ *  Platform autodetection
+ */
+
+/* Workaround for older C++ compilers before including <inttypes.h>,
+ * see e.g.: https://sourceware.org/bugzilla/show_bug.cgi?id=15366
+ */
+#if defined(__cplusplus) && !defined(__STDC_LIMIT_MACROS)
+#define __STDC_LIMIT_MACROS
+#endif
+#if defined(__cplusplus) && !defined(__STDC_CONSTANT_MACROS)
+#define __STDC_CONSTANT_MACROS
+#endif
+
+#if defined(DUK_F_APPLE)
+/* --- Mac OSX, iPhone, Darwin --- */
+#define DUK_USE_DATE_NOW_GETTIMEOFDAY
+#define DUK_USE_DATE_TZO_GMTIME_R
+#define DUK_USE_DATE_PRS_STRPTIME
+#define DUK_USE_DATE_FMT_STRFTIME
+#include <TargetConditionals.h>
+#include <architecture/byte_order.h>
+#include <sys/param.h>
+#include <sys/time.h>
+#include <time.h>
+
+/* http://stackoverflow.com/questions/5919996/how-to-detect-reliably-mac-os-x-ios-linux-windows-in-c-preprocessor */
+#if TARGET_IPHONE_SIMULATOR
+#define DUK_USE_OS_STRING "iphone-sim"
+#elif TARGET_OS_IPHONE
+#define DUK_USE_OS_STRING "iphone"
+#elif TARGET_OS_MAC
+#define DUK_USE_OS_STRING "osx"
+#else
+#define DUK_USE_OS_STRING "osx-unknown"
+#endif
+
+/* Use _setjmp() on Apple by default, see GH-55. */
+#define DUK_JMPBUF_TYPE       jmp_buf
+#define DUK_SETJMP(jb)        _setjmp((jb))
+#define DUK_LONGJMP(jb)       _longjmp((jb), 1)
+#elif defined(DUK_F_OPENBSD)
+/* --- OpenBSD --- */
+/* http://www.monkey.org/openbsd/archive/ports/0401/msg00089.html */
+#define DUK_USE_DATE_NOW_GETTIMEOFDAY
+#define DUK_USE_DATE_TZO_GMTIME_R
+#define DUK_USE_DATE_PRS_STRPTIME
+#define DUK_USE_DATE_FMT_STRFTIME
+#include <sys/types.h>
+#include <sys/endian.h>
+#include <sys/param.h>
+#include <sys/time.h>
+#include <time.h>
+
+#define DUK_USE_OS_STRING  "openbsd"
+#elif defined(DUK_F_BSD)
+/* --- Generic BSD --- */
+#define DUK_USE_DATE_NOW_GETTIMEOFDAY
+#define DUK_USE_DATE_TZO_GMTIME_R
+#define DUK_USE_DATE_PRS_STRPTIME
+#define DUK_USE_DATE_FMT_STRFTIME
+#include <sys/types.h>
+#include <sys/endian.h>
+#include <sys/param.h>
+#include <sys/time.h>
+#include <time.h>
+
+#define DUK_USE_OS_STRING  "bsd"
+#elif defined(DUK_F_TOS)
+/* --- Atari ST TOS --- */
+#define DUK_USE_DATE_NOW_TIME
+#define DUK_USE_DATE_TZO_GMTIME
+/* no parsing (not an error) */
+#define DUK_USE_DATE_FMT_STRFTIME
+#include <time.h>
+
+#define DUK_USE_OS_STRING  "tos"
+
+/* TOS on M68K is always big endian. */
+#if !defined(DUK_USE_BYTEORDER) && defined(DUK_F_M68K)
+#define DUK_USE_BYTEORDER 3
+#endif
+#elif defined(DUK_F_AMIGAOS)
+/* --- AmigaOS --- */
+#if defined(DUK_F_M68K)
+/* AmigaOS on M68k */
+#define DUK_USE_DATE_NOW_TIME
+#define DUK_USE_DATE_TZO_GMTIME
+/* no parsing (not an error) */
+#define DUK_USE_DATE_FMT_STRFTIME
+#include <time.h>
+#elif defined(DUK_F_PPC)
+#define DUK_USE_DATE_NOW_GETTIMEOFDAY
+#define DUK_USE_DATE_TZO_GMTIME_R
+#define DUK_USE_DATE_PRS_STRPTIME
+#define DUK_USE_DATE_FMT_STRFTIME
+#include <time.h>
+#ifndef UINTPTR_MAX
+#define UINTPTR_MAX UINT_MAX
+#endif
+#else
+#error AmigaOS but not M68K/PPC, not supported now
+#endif
+
+#define DUK_USE_OS_STRING "amigaos"
+
+/* AmigaOS on M68K or PPC is always big endian. */
+#if !defined(DUK_USE_BYTEORDER) && (defined(DUK_F_M68K) || defined(DUK_F_PPC))
+#define DUK_USE_BYTEORDER 3
+#endif
+#elif defined(DUK_F_WINDOWS)
+/* --- Windows --- */
+/* Initial fix: disable secure CRT related warnings when compiling Duktape
+ * itself (must be defined before including Windows headers).  Don't define
+ * for user code including duktape.h.
+ */
+#if defined(DUK_COMPILING_DUKTAPE) && !defined(_CRT_SECURE_NO_WARNINGS)
+#define _CRT_SECURE_NO_WARNINGS
+#endif
+
+/* Windows 32-bit and 64-bit are currently the same. */
+/* MSVC does not have sys/param.h */
+#define DUK_USE_DATE_NOW_WINDOWS
+#define DUK_USE_DATE_TZO_WINDOWS
+/* Note: PRS and FMT are intentionally left undefined for now.  This means
+ * there is no platform specific date parsing/formatting but there is still
+ * the ISO 8601 standard format.
+ */
+#if defined(DUK_COMPILING_DUKTAPE)
+/* Only include when compiling Duktape to avoid polluting application build
+ * with a lot of unnecessary defines.
+ */
+#include <windows.h>
+#endif
+
+#define DUK_USE_OS_STRING "windows"
+
+/* On Windows, assume we're little endian.  Even Itanium which has a
+ * configurable endianness runs little endian in Windows.
+ */
+#if !defined(DUK_USE_BYTEORDER)
+#define DUK_USE_BYTEORDER 1
+#endif
+#elif defined(DUK_F_FLASHPLAYER)
+/* --- Flashplayer (Crossbridge) --- */
+#define DUK_USE_DATE_NOW_GETTIMEOFDAY
+#define DUK_USE_DATE_TZO_GMTIME_R
+#define DUK_USE_DATE_PRS_STRPTIME
+#define DUK_USE_DATE_FMT_STRFTIME
+#include <endian.h>
+#include <sys/param.h>
+#include <sys/time.h>
+#include <time.h>
+
+#define DUK_USE_OS_STRING "flashplayer"
+
+#if !defined(DUK_USE_BYTEORDER) && defined(DUK_F_FLASHPLAYER)
+#define DUK_USE_BYTEORDER 1
+#endif
+#elif defined(DUK_F_QNX)
+/* --- QNX --- */
+#if defined(DUK_F_QNX) && defined(DUK_COMPILING_DUKTAPE)
+/* See: /opt/qnx650/target/qnx6/usr/include/sys/platform.h */
+#define _XOPEN_SOURCE    600
+#define _POSIX_C_SOURCE  200112L
+#endif
+
+#define DUK_USE_DATE_NOW_GETTIMEOFDAY
+#define DUK_USE_DATE_TZO_GMTIME_R
+#define DUK_USE_DATE_PRS_STRPTIME
+#define DUK_USE_DATE_FMT_STRFTIME
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/time.h>
+#include <time.h>
+
+#define DUK_USE_OS_STRING "qnx"
+#elif defined(DUK_F_TINSPIRE)
+/* --- TI-Nspire --- */
+#define DUK_USE_DATE_NOW_GETTIMEOFDAY
+#define DUK_USE_DATE_TZO_GMTIME_R
+#define DUK_USE_DATE_PRS_STRPTIME
+#define DUK_USE_DATE_FMT_STRFTIME
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/time.h>
+#include <time.h>
+
+#define DUK_USE_OS_STRING "tinspire"
+#elif defined(DUK_F_EMSCRIPTEN)
+/* --- Emscripten --- */
+#if defined(DUK_COMPILING_DUKTAPE)
+#ifndef _POSIX_C_SOURCE
+#define _POSIX_C_SOURCE  200809L
+#endif
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE      /* e.g. getdate_r */
+#endif
+#ifndef _XOPEN_SOURCE
+#define _XOPEN_SOURCE    /* e.g. strptime */
+#endif
+#endif  /* DUK_COMPILING_DUKTAPE */
+
+#include <sys/types.h>
+#if defined(DUK_F_BCC)
+/* no endian.h */
+#else
+#include <endian.h>
+#endif  /* DUK_F_BCC */
+#include <sys/param.h>
+#include <sys/time.h>
+#include <time.h>
+#include <stdint.h>
+
+#define DUK_USE_DATE_NOW_GETTIMEOFDAY
+#define DUK_USE_DATE_TZO_GMTIME_R
+#define DUK_USE_DATE_PRS_STRPTIME
+#define DUK_USE_DATE_FMT_STRFTIME
+
+#define DUK_USE_OS_STRING "emscripten"
+#elif defined(DUK_F_LINUX)
+/* --- Linux --- */
+#if defined(DUK_COMPILING_DUKTAPE)
+#ifndef _POSIX_C_SOURCE
+#define _POSIX_C_SOURCE  200809L
+#endif
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE      /* e.g. getdate_r */
+#endif
+#ifndef _XOPEN_SOURCE
+#define _XOPEN_SOURCE    /* e.g. strptime */
+#endif
+#endif  /* DUK_COMPILING_DUKTAPE */
+
+#include <sys/types.h>
+#if defined(DUK_F_BCC)
+/* no endian.h or stdint.h */
+#else
+#include <endian.h>
+#include <stdint.h>
+#endif  /* DUK_F_BCC */
+#include <sys/param.h>
+#include <sys/time.h>
+#include <time.h>
+
+#define DUK_USE_DATE_NOW_GETTIMEOFDAY
+#define DUK_USE_DATE_TZO_GMTIME_R
+#define DUK_USE_DATE_PRS_STRPTIME
+#define DUK_USE_DATE_FMT_STRFTIME
+
+#define DUK_USE_OS_STRING "linux"
+#elif defined(DUK_F_SUN)
+/* --- Solaris --- */
+#define DUK_USE_DATE_NOW_GETTIMEOFDAY
+#define DUK_USE_DATE_TZO_GMTIME_R
+#define DUK_USE_DATE_PRS_STRPTIME
+#define DUK_USE_DATE_FMT_STRFTIME
+
+#include <sys/types.h>
+#include <ast/endian.h>
+#include <sys/param.h>
+#include <sys/time.h>
+#include <time.h>
+
+#define DUK_USE_OS_STRING "solaris"
+#elif defined(DUK_F_POSIX)
+/* --- Generic POSIX --- */
+#define DUK_USE_DATE_NOW_GETTIMEOFDAY
+#define DUK_USE_DATE_TZO_GMTIME_R
+#define DUK_USE_DATE_PRS_STRPTIME
+#define DUK_USE_DATE_FMT_STRFTIME
+#include <sys/types.h>
+#include <endian.h>
+#include <sys/param.h>
+#include <sys/time.h>
+#include <time.h>
+
+#define DUK_USE_OS_STRING "posix"
+#elif defined(DUK_F_CYGWIN)
+/* --- Cygwin --- */
+/* don't use strptime() for now */
+#define DUK_USE_DATE_NOW_GETTIMEOFDAY
+#define DUK_USE_DATE_TZO_GMTIME_R
+#define DUK_USE_DATE_FMT_STRFTIME
+#include <sys/types.h>
+#include <endian.h>
+#include <sys/param.h>
+#include <sys/time.h>
+#include <time.h>
+
+#define DUK_JMPBUF_TYPE       jmp_buf
+#define DUK_SETJMP(jb)        _setjmp((jb))
+#define DUK_LONGJMP(jb)       _longjmp((jb), 1)
+
+#define DUK_USE_OS_STRING "windows"
+#elif defined(DUK_F_UNIX)
+/* --- Generic UNIX --- */
+#define DUK_USE_DATE_NOW_GETTIMEOFDAY
+#define DUK_USE_DATE_TZO_GMTIME_R
+#define DUK_USE_DATE_PRS_STRPTIME
+#define DUK_USE_DATE_FMT_STRFTIME
+#include <time.h>
+#include <sys/time.h>
+#define DUK_USE_OS_STRING "unknown"
+#else
+/* --- Generic fallback --- */
+/* The most portable current time provider is time(), but it only has a
+ * one second resolution.
+ */
+#define DUK_USE_DATE_NOW_TIME
+
+/* The most portable way to figure out local time offset is gmtime(),
+ * but it's not thread safe so use with caution.
+ */
+#define DUK_USE_DATE_TZO_GMTIME
+
+/* Avoid custom date parsing and formatting for portability. */
+#undef DUK_USE_DATE_PRS_STRPTIME
+#undef DUK_USE_DATE_FMT_STRFTIME
+
+/* Rely on C89 headers only; time.h must be here. */
+#include <time.h>
+
+#define DUK_USE_OS_STRING "unknown"
+#endif  /* autodetect platform */
+
+/* Shared includes: C89 */
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdarg.h>  /* varargs */
+#include <setjmp.h>
+#include <stddef.h>  /* e.g. ptrdiff_t */
+#include <math.h>
+#include <limits.h>
+
+/* date.h is omitted, and included per platform */
+
+/* Shared includes: stdint.h is C99 */
+#if defined(DUK_F_NO_STDINT_H)
+/* stdint.h not available */
+#else
+/* Technically C99 (C++11) but found in many systems.  On some systems
+ * __STDC_LIMIT_MACROS and __STDC_CONSTANT_MACROS must be defined before
+ * including stdint.h (see above).
+ */
+#include <stdint.h>
+#endif
+
+#if defined(DUK_F_CPP)
+#include <exception>  /* std::exception */
+#endif
+
+/*
+ *  Architecture autodetection
+ */
+
+#if defined(DUK_F_X86)
+/* --- x86 --- */
+#define DUK_USE_ARCH_STRING "x86"
+#if !defined(DUK_USE_BYTEORDER)
+#define DUK_USE_BYTEORDER 1
+#endif
+/* XXX: This is technically not guaranteed because it's possible to configure
+ * an x86 to require aligned accesses with Alignment Check (AC) flag.
+ */
+#if !defined(DUK_USE_ALIGN_BY)
+#define DUK_USE_ALIGN_BY 1
+#endif
+#define DUK_USE_PACKED_TVAL
+#define DUK_F_PACKED_TVAL_PROVIDED
+#elif defined(DUK_F_X64)
+/* --- x64 --- */
+#define DUK_USE_ARCH_STRING "x64"
+#if !defined(DUK_USE_BYTEORDER)
+#define DUK_USE_BYTEORDER 1
+#endif
+/* XXX: This is technically not guaranteed because it's possible to configure
+ * an x86 to require aligned accesses with Alignment Check (AC) flag.
+ */
+#if !defined(DUK_USE_ALIGN_BY)
+#define DUK_USE_ALIGN_BY 1
+#endif
+#undef DUK_USE_PACKED_TVAL
+#define DUK_F_PACKED_TVAL_PROVIDED
+#elif defined(DUK_F_X32)
+/* --- x32 --- */
+#define DUK_USE_ARCH_STRING "x32"
+#if !defined(DUK_USE_BYTEORDER)
+#define DUK_USE_BYTEORDER 1
+#endif
+/* XXX: This is technically not guaranteed because it's possible to configure
+ * an x86 to require aligned accesses with Alignment Check (AC) flag.
+ */
+#if !defined(DUK_USE_ALIGN_BY)
+#define DUK_USE_ALIGN_BY 1
+#endif
+#define DUK_USE_PACKED_TVAL
+#define DUK_F_PACKED_TVAL_PROVIDED
+#elif defined(DUK_F_ARM32)
+/* --- ARM 32-bit --- */
+#define DUK_USE_ARCH_STRING "arm32"
+/* Byte order varies, so rely on autodetect. */
+#if !defined(DUK_USE_ALIGN_BY)
+#define DUK_USE_ALIGN_BY 4
+#endif
+#define DUK_USE_PACKED_TVAL
+#define DUK_F_PACKED_TVAL_PROVIDED
+#elif defined(DUK_F_ARM64)
+/* --- ARM 64-bit --- */
+#define DUK_USE_ARCH_STRING "arm64"
+/* Byte order varies, so rely on autodetect. */
+#if !defined(DUK_USE_ALIGN_BY)
+#define DUK_USE_ALIGN_BY 8
+#endif
+#undef DUK_USE_PACKED_TVAL
+#define DUK_F_PACKED_TVAL_PROVIDED
+#elif defined(DUK_F_MIPS32)
+/* --- MIPS 32-bit --- */
+#define DUK_USE_ARCH_STRING "mips32"
+/* MIPS byte order varies so rely on autodetection. */
+/* Based on 'make checkalign' there are no alignment requirements on
+ * Linux MIPS except for doubles, which need align by 4.  Alignment
+ * requirements vary based on target though.
+ */
+#if !defined(DUK_USE_ALIGN_BY)
+#define DUK_USE_ALIGN_BY 4
+#endif
+#define DUK_USE_PACKED_TVAL
+#define DUK_F_PACKED_TVAL_PROVIDED
+#elif defined(DUK_F_MIPS64)
+/* --- MIPS 64-bit --- */
+#define DUK_USE_ARCH_STRING "mips64"
+/* MIPS byte order varies so rely on autodetection. */
+/* Good default is a bit arbitrary because alignment requirements
+ * depend on target.  See https://github.com/svaarala/duktape/issues/102.
+ */
+#if !defined(DUK_USE_ALIGN_BY)
+#define DUK_USE_ALIGN_BY 8
+#endif
+#undef DUK_USE_PACKED_TVAL
+#define DUK_F_PACKED_TVAL_PROVIDED
+#elif defined(DUK_F_PPC32)
+/* --- PowerPC 32-bit --- */
+#define DUK_USE_ARCH_STRING "ppc32"
+#if !defined(DUK_USE_BYTEORDER)
+#define DUK_USE_BYTEORDER 3
+#endif
+#if !defined(DUK_USE_ALIGN_BY)
+#define DUK_USE_ALIGN_BY 8
+#endif
+#define DUK_USE_PACKED_TVAL
+#define DUK_F_PACKED_TVAL_PROVIDED
+#elif defined(DUK_F_PPC64)
+/* --- PowerPC 64-bit --- */
+#define DUK_USE_ARCH_STRING "ppc64"
+#if !defined(DUK_USE_BYTEORDER)
+#define DUK_USE_BYTEORDER 3
+#endif
+#if !defined(DUK_USE_ALIGN_BY)
+#define DUK_USE_ALIGN_BY 8
+#endif
+#undef DUK_USE_PACKED_TVAL
+#define DUK_F_PACKED_TVAL_PROVIDED
+#elif defined(DUK_F_SPARC32)
+/* --- SPARC 32-bit --- */
+#define DUK_USE_ARCH_STRING "sparc32"
+/* SPARC byte order varies so rely on autodetection. */
+#if !defined(DUK_USE_ALIGN_BY)
+#define DUK_USE_ALIGN_BY 8
+#endif
+#define DUK_USE_PACKED_TVAL
+#define DUK_F_PACKED_TVAL_PROVIDED
+#elif defined(DUK_F_SPARC64)
+/* --- SPARC 64-bit --- */
+#define DUK_USE_ARCH_STRING "sparc64"
+/* SPARC byte order varies so rely on autodetection. */
+#if !defined(DUK_USE_ALIGN_BY)
+#define DUK_USE_ALIGN_BY 8
+#endif
+#undef DUK_USE_PACKED_TVAL
+#define DUK_F_PACKED_TVAL_PROVIDED
+#elif defined(DUK_F_SUPERH)
+/* --- SuperH --- */
+#define DUK_USE_ARCH_STRING "sh"
+/* Byte order varies, rely on autodetection. */
+/* Based on 'make checkalign' there are no alignment requirements on
+ * Linux SH4, but align by 4 is probably a good basic default.
+ */
+#if !defined(DUK_USE_ALIGN_BY)
+#define DUK_USE_ALIGN_BY 4
+#endif
+#define DUK_USE_PACKED_TVAL
+#define DUK_F_PACKED_TVAL_PROVIDED
+#elif defined(DUK_F_M68K)
+/* --- Motorola 68k --- */
+#define DUK_USE_ARCH_STRING "m68k"
+#if !defined(DUK_USE_BYTEORDER)
+#define DUK_USE_BYTEORDER 3
+#endif
+#if !defined(DUK_USE_ALIGN_BY)
+#define DUK_USE_ALIGN_BY 8
+#endif
+#define DUK_USE_PACKED_TVAL
+#define DUK_F_PACKED_TVAL_PROVIDED
+#elif defined(DUK_F_EMSCRIPTEN)
+/* --- Emscripten --- */
+#define DUK_USE_ARCH_STRING "emscripten"
+#if !defined(DUK_USE_BYTEORDER)
+#define DUK_USE_BYTEORDER 1
+#endif
+#if !defined(DUK_USE_ALIGN_BY)
+#define DUK_USE_ALIGN_BY 8
+#endif
+#undef DUK_USE_PACKED_TVAL
+#define DUK_F_PACKED_TVAL_PROVIDED
+#else
+/* --- Generic --- */
+/* These are necessary wild guesses. */
+#define DUK_USE_ARCH_STRING "generic"
+/* Rely on autodetection for byte order, alignment, and packed tval. */
+#endif  /* autodetect architecture */
+
+/*
+ *  Compiler autodetection
+ */
+
+#if defined(DUK_F_CLANG)
+/* --- Clang --- */
+#if defined(DUK_F_C99) || defined(DUK_F_CPP11)
+/* C99 / C++11 and above: rely on va_copy() which is required. */
+#define DUK_VA_COPY(dest,src) va_copy(dest,src)
+#else
+/* Clang: assume we have __va_copy() in non-C99 mode. */
+#define DUK_VA_COPY(dest,src) __va_copy(dest,src)
+#endif
+
+#define DUK_NORETURN(decl)  decl __attribute__((noreturn))
+
+#if defined(__clang__) && defined(__has_builtin)
+#if __has_builtin(__builtin_unreachable)
+#define DUK_UNREACHABLE()  do { __builtin_unreachable(); } while (0)
+#endif
+#endif
+
+#define DUK_USE_BRANCH_HINTS
+#define DUK_LIKELY(x)    __builtin_expect((x), 1)
+#define DUK_UNLIKELY(x)  __builtin_expect((x), 0)
+
+#if defined(DUK_F_C99) || defined(DUK_F_CPP11)
+#define DUK_NOINLINE        __attribute__((noinline))
+#define DUK_INLINE          inline
+#define DUK_ALWAYS_INLINE   inline __attribute__((always_inline))
+#endif
+
+#if defined(DUK_F_DLL_BUILD) && defined(DUK_F_WINDOWS)
+/* MSVC dllexport/dllimport: appropriate __declspec depends on whether we're
+ * compiling Duktape or the application.
+ */
+#if defined(DUK_COMPILING_DUKTAPE)
+#define DUK_EXTERNAL_DECL  extern __declspec(dllexport)
+#define DUK_EXTERNAL       __declspec(dllexport)
+#else
+#define DUK_EXTERNAL_DECL  extern __declspec(dllimport)
+#define DUK_EXTERNAL       should_not_happen
+#endif
+#if defined(DUK_SINGLE_FILE)
+#define DUK_INTERNAL_DECL  static
+#define DUK_INTERNAL       static
+#else
+#define DUK_INTERNAL_DECL  extern
+#define DUK_INTERNAL       /*empty*/
+#endif
+#define DUK_LOCAL_DECL     static
+#define DUK_LOCAL          static
+#else
+#define DUK_EXTERNAL_DECL  __attribute__ ((visibility("default"))) extern
+#define DUK_EXTERNAL       __attribute__ ((visibility("default")))
+#if defined(DUK_SINGLE_FILE)
+#if (defined(DUK_F_GCC_VERSION) && DUK_F_GCC_VERSION >= 30101) || defined(DUK_F_CLANG)
+/* Minimize warnings for unused internal functions with GCC >= 3.1.1 and
+ * Clang.  Based on documentation it should suffice to have the attribute
+ * in the declaration only, but in practice some warnings are generated unless
+ * the attribute is also applied to the definition.
+ */
+#define DUK_INTERNAL_DECL  static __attribute__ ((unused))
+#define DUK_INTERNAL       static __attribute__ ((unused))
+#else
+#define DUK_INTERNAL_DECL  static
+#define DUK_INTERNAL       static
+#endif
+#else
+#if (defined(DUK_F_GCC_VERSION) && DUK_F_GCC_VERSION >= 30101) || defined(DUK_F_CLANG)
+#define DUK_INTERNAL_DECL  __attribute__ ((visibility("hidden"))) __attribute__ ((unused)) extern
+#define DUK_INTERNAL       __attribute__ ((visibility("hidden"))) __attribute__ ((unused))
+#else
+#define DUK_INTERNAL_DECL  __attribute__ ((visibility("hidden"))) extern
+#define DUK_INTERNAL       __attribute__ ((visibility("hidden")))
+#endif
+#endif
+#define DUK_LOCAL_DECL     static
+#define DUK_LOCAL          static
+#endif
+
+#if defined(DUK_F_CPP)
+#define DUK_USE_COMPILER_STRING "clang"
+#else
+#define DUK_USE_COMPILER_STRING "clang"
+#endif
+
+#undef DUK_USE_VARIADIC_MACROS
+#if defined(DUK_F_C99) || defined(DUK_F_CPP11)
+#define DUK_USE_VARIADIC_MACROS
+#endif
+
+#define DUK_USE_UNION_INITIALIZERS
+
+#undef DUK_USE_FLEX_C99
+#undef DUK_USE_FLEX_ZEROSIZE
+#undef DUK_USE_FLEX_ONESIZE
+#if defined(DUK_F_C99)
+#define DUK_USE_FLEX_C99
+#else
+#define DUK_USE_FLEX_ZEROSIZE
+#endif
+
+#undef DUK_USE_GCC_PRAGMAS
+#define DUK_USE_PACK_CLANG_ATTR
+#elif defined(DUK_F_GCC)
+/* --- GCC --- */
+#if defined(DUK_F_C99) || defined(DUK_F_CPP11)
+/* C99 / C++11 and above: rely on va_copy() which is required. */
+#define DUK_VA_COPY(dest,src) va_copy(dest,src)
+#else
+/* GCC: assume we have __va_copy() in non-C99 mode. */
+#define DUK_VA_COPY(dest,src) __va_copy(dest,src)
+#endif
+
+#if defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION >= 20500L)
+/* since gcc-2.5 */
+#define DUK_NORETURN(decl)  decl __attribute__((noreturn))
+#endif
+
+#if defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION >= 40500L)
+/* since gcc-4.5 */
+#define DUK_UNREACHABLE()  do { __builtin_unreachable(); } while (0)
+#endif
+
+#define DUK_USE_BRANCH_HINTS
+#if defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION >= 40500L)
+/* GCC: test not very accurate; enable only in relatively recent builds
+ * because of bugs in gcc-4.4 (http://lists.debian.org/debian-gcc/2010/04/msg00000.html)
+ */
+#define DUK_LIKELY(x)    __builtin_expect((x), 1)
+#define DUK_UNLIKELY(x)  __builtin_expect((x), 0)
+#endif
+
+#if (defined(DUK_F_C99) || defined(DUK_F_CPP11)) && \
+    defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION >= 30101)
+#define DUK_NOINLINE        __attribute__((noinline))
+#define DUK_INLINE          inline
+#define DUK_ALWAYS_INLINE   inline __attribute__((always_inline))
+#endif
+
+#if defined(DUK_F_DLL_BUILD) && defined(DUK_F_WINDOWS)
+/* MSVC dllexport/dllimport: appropriate __declspec depends on whether we're
+ * compiling Duktape or the application.
+ */
+#if defined(DUK_COMPILING_DUKTAPE)
+#define DUK_EXTERNAL_DECL  extern __declspec(dllexport)
+#define DUK_EXTERNAL       __declspec(dllexport)
+#else
+#define DUK_EXTERNAL_DECL  extern __declspec(dllimport)
+#define DUK_EXTERNAL       should_not_happen
+#endif
+#if defined(DUK_SINGLE_FILE)
+#define DUK_INTERNAL_DECL  static
+#define DUK_INTERNAL       static
+#else
+#define DUK_INTERNAL_DECL  extern
+#define DUK_INTERNAL       /*empty*/
+#endif
+#define DUK_LOCAL_DECL     static
+#define DUK_LOCAL          static
+#elif defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION >= 40000)
+#define DUK_EXTERNAL_DECL  __attribute__ ((visibility("default"))) extern
+#define DUK_EXTERNAL       __attribute__ ((visibility("default")))
+#if defined(DUK_SINGLE_FILE)
+#if (defined(DUK_F_GCC_VERSION) && DUK_F_GCC_VERSION >= 30101) || defined(DUK_F_CLANG)
+/* Minimize warnings for unused internal functions with GCC >= 3.1.1 and
+ * Clang.  Based on documentation it should suffice to have the attribute
+ * in the declaration only, but in practice some warnings are generated unless
+ * the attribute is also applied to the definition.
+ */
+#define DUK_INTERNAL_DECL  static __attribute__ ((unused))
+#define DUK_INTERNAL       static __attribute__ ((unused))
+#else
+#define DUK_INTERNAL_DECL  static
+#define DUK_INTERNAL       static
+#endif
+#else
+#if (defined(DUK_F_GCC_VERSION) && DUK_F_GCC_VERSION >= 30101) || defined(DUK_F_CLANG)
+#define DUK_INTERNAL_DECL  __attribute__ ((visibility("hidden"))) __attribute__ ((unused)) extern
+#define DUK_INTERNAL       __attribute__ ((visibility("hidden"))) __attribute__ ((unused))
+#else
+#define DUK_INTERNAL_DECL  __attribute__ ((visibility("hidden"))) extern
+#define DUK_INTERNAL       __attribute__ ((visibility("hidden")))
+#endif
+#endif
+#define DUK_LOCAL_DECL     static
+#define DUK_LOCAL          static
+#endif
+
+#if defined(DUK_F_MINGW)
+#if defined(DUK_F_CPP)
+#define DUK_USE_COMPILER_STRING "mingw++"
+#else
+#define DUK_USE_COMPILER_STRING "mingw"
+#endif
+#else
+#if defined(DUK_F_CPP)
+#define DUK_USE_COMPILER_STRING "g++"
+#else
+#define DUK_USE_COMPILER_STRING "gcc"
+#endif
+#endif
+
+#undef DUK_USE_VARIADIC_MACROS
+#if defined(DUK_F_C99) || (defined(DUK_F_CPP11) && defined(__GNUC__))
+#define DUK_USE_VARIADIC_MACROS
+#endif
+
+#define DUK_USE_UNION_INITIALIZERS
+
+#undef DUK_USE_FLEX_C99
+#undef DUK_USE_FLEX_ZEROSIZE
+#undef DUK_USE_FLEX_ONESIZE
+#if defined(DUK_F_C99)
+#define DUK_USE_FLEX_C99
+#else
+#define DUK_USE_FLEX_ZEROSIZE
+#endif
+
+#if defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION >= 40600)
+#define DUK_USE_GCC_PRAGMAS
+#else
+#undef DUK_USE_GCC_PRAGMAS
+#endif
+
+#define DUK_USE_PACK_GCC_ATTR
+#elif defined(DUK_F_MSVC)
+/* --- MSVC --- */
+/* http://msdn.microsoft.com/en-us/library/aa235362(VS.60).aspx */
+#define DUK_NORETURN(decl)  __declspec(noreturn) decl
+
+/* XXX: DUK_UNREACHABLE for msvc? */
+
+#undef DUK_USE_BRANCH_HINTS
+
+/* XXX: DUK_LIKELY, DUK_UNLIKELY for msvc? */
+/* XXX: DUK_NOINLINE, DUK_INLINE, DUK_ALWAYS_INLINE for msvc? */
+
+#if defined(DUK_F_DLL_BUILD) && defined(DUK_F_WINDOWS)
+/* MSVC dllexport/dllimport: appropriate __declspec depends on whether we're
+ * compiling Duktape or the application.
+ */
+#if defined(DUK_COMPILING_DUKTAPE)
+#define DUK_EXTERNAL_DECL  extern __declspec(dllexport)
+#define DUK_EXTERNAL       __declspec(dllexport)
+#else
+#define DUK_EXTERNAL_DECL  extern __declspec(dllimport)
+#define DUK_EXTERNAL       should_not_happen
+#endif
+#if defined(DUK_SINGLE_FILE)
+#define DUK_INTERNAL_DECL  static
+#define DUK_INTERNAL       static
+#else
+#define DUK_INTERNAL_DECL  extern
+#define DUK_INTERNAL       /*empty*/
+#endif
+#define DUK_LOCAL_DECL     static
+#define DUK_LOCAL          static
+#endif
+
+#if defined(DUK_F_CPP)
+#define DUK_USE_COMPILER_STRING "msvc++"
+#else
+#define DUK_USE_COMPILER_STRING "msvc"
+#endif
+
+#undef DUK_USE_VARIADIC_MACROS
+#if defined(DUK_F_C99)
+#define DUK_USE_VARIADIC_MACROS
+#elif defined(_MSC_VER) && (_MSC_VER >= 1400)
+/* VS2005+ should have variadic macros even when they're not C99. */
+#define DUK_USE_VARIADIC_MACROS
+#endif
+
+#undef DUK_USE_UNION_INITIALIZERS
+#if defined(_MSC_VER) && (_MSC_VER >= 1800)
+/* VS2013+ supports union initializers but there's a bug involving union-inside-struct:
+ * https://connect.microsoft.com/VisualStudio/feedback/details/805981
+ * The bug was fixed (at least) in VS2015 so check for VS2015 for now:
+ * https://blogs.msdn.microsoft.com/vcblog/2015/07/01/c-compiler-front-end-fixes-in-vs2015/
+ * Manually tested using VS2013, CL reports 18.00.31101, so enable for VS2013 too.
+ */
+#define DUK_USE_UNION_INITIALIZERS
+#endif
+
+#undef DUK_USE_FLEX_C99
+#undef DUK_USE_FLEX_ZEROSIZE
+#undef DUK_USE_FLEX_ONESIZE
+#if defined(DUK_F_C99)
+#define DUK_USE_FLEX_C99
+#else
+#define DUK_USE_FLEX_ZEROSIZE
+#endif
+
+#undef DUK_USE_GCC_PRAGMAS
+
+#define DUK_USE_PACK_MSVC_PRAGMA
+
+/* These have been tested from VS2008 onwards; may work in older VS versions
+ * too but not enabled by default.
+ */
+#if defined(_MSC_VER) && (_MSC_VER >= 1500)
+#define DUK_NOINLINE        __declspec(noinline)
+#define DUK_INLINE          __inline
+#define DUK_ALWAYS_INLINE   __forceinline
+#endif
+
+#if defined(_MSC_VER) && (_MSC_VER >= 1900)
+#define DUK_SNPRINTF     snprintf
+#define DUK_VSNPRINTF    vsnprintf
+#else
+/* (v)snprintf() is missing before MSVC 2015.  Note that _(v)snprintf() does
+ * NOT NUL terminate on truncation, but Duktape code never assumes that.
+ * http://stackoverflow.com/questions/2915672/snprintf-and-visual-studio-2010
+ */
+#define DUK_SNPRINTF     _snprintf
+#define DUK_VSNPRINTF    _vsnprintf
+#endif
+#elif defined(DUK_F_EMSCRIPTEN)
+/* --- Emscripten --- */
+#define DUK_NORETURN(decl)  decl __attribute__((noreturn))
+
+#if defined(__clang__) && defined(__has_builtin)
+#if __has_builtin(__builtin_unreachable)
+#define DUK_UNREACHABLE()  do { __builtin_unreachable(); } while (0)
+#endif
+#endif
+
+#define DUK_USE_BRANCH_HINTS
+#define DUK_LIKELY(x)    __builtin_expect((x), 1)
+#define DUK_UNLIKELY(x)  __builtin_expect((x), 0)
+
+#if defined(DUK_F_C99) || defined(DUK_F_CPP11)
+#define DUK_NOINLINE        __attribute__((noinline))
+#define DUK_INLINE          inline
+#define DUK_ALWAYS_INLINE   inline __attribute__((always_inline))
+#endif
+
+#define DUK_EXTERNAL_DECL  __attribute__ ((visibility("default"))) extern
+#define DUK_EXTERNAL       __attribute__ ((visibility("default")))
+#if defined(DUK_SINGLE_FILE)
+#if (defined(DUK_F_GCC_VERSION) && DUK_F_GCC_VERSION >= 30101) || defined(DUK_F_CLANG)
+/* Minimize warnings for unused internal functions with GCC >= 3.1.1 and
+ * Clang.  Based on documentation it should suffice to have the attribute
+ * in the declaration only, but in practice some warnings are generated unless
+ * the attribute is also applied to the definition.
+ */
+#define DUK_INTERNAL_DECL  static __attribute__ ((unused))
+#define DUK_INTERNAL       static __attribute__ ((unused))
+#else
+#define DUK_INTERNAL_DECL  static
+#define DUK_INTERNAL       static
+#endif
+#else
+#if (defined(DUK_F_GCC_VERSION) && DUK_F_GCC_VERSION >= 30101) || defined(DUK_F_CLANG)
+#define DUK_INTERNAL_DECL  __attribute__ ((visibility("hidden"))) __attribute__ ((unused)) extern
+#define DUK_INTERNAL       __attribute__ ((visibility("hidden"))) __attribute__ ((unused))
+#else
+#define DUK_INTERNAL_DECL  __attribute__ ((visibility("hidden"))) extern
+#define DUK_INTERNAL       __attribute__ ((visibility("hidden")))
+#endif
+#endif
+#define DUK_LOCAL_DECL     static
+#define DUK_LOCAL          static
+
+#define DUK_USE_COMPILER_STRING "emscripten"
+
+#undef DUK_USE_VARIADIC_MACROS
+#if defined(DUK_F_C99) || defined(DUK_F_CPP11)
+#define DUK_USE_VARIADIC_MACROS
+#endif
+
+#define DUK_USE_UNION_INITIALIZERS
+
+#undef DUK_USE_FLEX_C99
+#undef DUK_USE_FLEX_ZEROSIZE
+#undef DUK_USE_FLEX_ONESIZE
+#if defined(DUK_F_C99)
+#define DUK_USE_FLEX_C99
+#else
+#define DUK_USE_FLEX_ZEROSIZE
+#endif
+
+#undef DUK_USE_GCC_PRAGMAS
+#define DUK_USE_PACK_CLANG_ATTR
+#elif defined(DUK_F_TINYC)
+/* --- TinyC --- */
+#undef DUK_USE_BRANCH_HINTS
+
+#if defined(DUK_F_CPP)
+#define DUK_USE_COMPILER_STRING "tinyc++"
+#else
+#define DUK_USE_COMPILER_STRING "tinyc"
+#endif
+
+/* http://bellard.org/tcc/tcc-doc.html#SEC7 */
+#define DUK_USE_VARIADIC_MACROS
+
+#define DUK_USE_UNION_INITIALIZERS
+
+/* Most portable, wastes space */
+#define DUK_USE_FLEX_ONESIZE
+
+/* Most portable, potentially wastes space */
+#define DUK_USE_PACK_DUMMY_MEMBER
+#elif defined(DUK_F_VBCC)
+/* --- VBCC --- */
+#undef DUK_USE_BRANCH_HINTS
+
+#if defined(DUK_F_CPP)
+#define DUK_USE_COMPILER_STRING "vbcc-c++"
+#else
+#define DUK_USE_COMPILER_STRING "vbcc"
+#endif
+
+#undef DUK_USE_VARIADIC_MACROS
+#if defined(DUK_F_C99) || defined(DUK_F_CPP11)
+#define DUK_USE_VARIADIC_MACROS
+#endif
+
+/* VBCC supports C99 so check only for C99 for union initializer support.
+ * Designated union initializers would possibly work even without a C99 check.
+ */
+#undef DUK_USE_UNION_INITIALIZERS
+#if defined(DUK_F_C99)
+#define DUK_USE_UNION_INITIALIZERS
+#endif
+
+#define DUK_USE_FLEX_ZEROSIZE
+#define DUK_USE_PACK_DUMMY_MEMBER
+#elif defined(DUK_F_BCC)
+/* --- Bruce's C compiler --- */
+#undef DUK_USE_BRANCH_HINTS
+
+#if defined(DUK_F_CPP)
+#define DUK_USE_COMPILER_STRING "bcc++"
+#else
+#define DUK_USE_COMPILER_STRING "bcc"
+#endif
+
+/* Most portable */
+#undef DUK_USE_VARIADIC_MACROS
+
+/* Most portable, wastes space */
+#undef DUK_USE_UNION_INITIALIZERS
+
+/* Most portable, wastes space */
+#define DUK_USE_FLEX_ONESIZE
+
+/* Most portable, potentially wastes space */
+#define DUK_USE_PACK_DUMMY_MEMBER
+
+/* BCC, assume we're on x86. */
+#if !defined(DUK_USE_BYTEORDER)
+#define DUK_USE_BYTEORDER 1
+#endif
+#else
+/* --- Generic --- */
+#undef DUK_USE_BRANCH_HINTS
+
+#if defined(DUK_F_CPP)
+#define DUK_USE_COMPILER_STRING "generic-c++"
+#else
+#define DUK_USE_COMPILER_STRING "generic"
+#endif
+
+#undef DUK_USE_VARIADIC_MACROS
+#if defined(DUK_F_C99) || defined(DUK_F_CPP11)
+#define DUK_USE_VARIADIC_MACROS
+#endif
+
+/* C++ doesn't have standard designated union initializers ({ .foo = 1 }). */
+#undef DUK_USE_UNION_INITIALIZERS
+#if defined(DUK_F_C99)
+#define DUK_USE_UNION_INITIALIZERS
+#endif
+
+/* Most portable, wastes space */
+#define DUK_USE_FLEX_ONESIZE
+
+/* Most portable, potentially wastes space */
+#define DUK_USE_PACK_DUMMY_MEMBER
+#endif  /* autodetect compiler */
+
+/* uclibc */
+#if defined(__UCLIBC__)
+#define DUK_F_UCLIBC
+#endif
+
+/*
+ *  Wrapper typedefs and constants for integer types, also sanity check types.
+ *
+ *  C99 typedefs are quite good but not always available, and we want to avoid
+ *  forcibly redefining the C99 typedefs.  So, there are Duktape wrappers for
+ *  all C99 typedefs and Duktape code should only use these typedefs.  Type
+ *  detection when C99 is not supported is best effort and may end up detecting
+ *  some types incorrectly.
+ *
+ *  Pointer sizes are a portability problem: pointers to different types may
+ *  have a different size and function pointers are very difficult to manage
+ *  portably.
+ *
+ *  http://en.wikipedia.org/wiki/C_data_types#Fixed-width_integer_types
+ *
+ *  Note: there's an interesting corner case when trying to define minimum
+ *  signed integer value constants which leads to the current workaround of
+ *  defining e.g. -0x80000000 as (-0x7fffffffL - 1L).  See doc/code-issues.txt
+ *  for a longer discussion.
+ *
+ *  Note: avoid typecasts and computations in macro integer constants as they
+ *  can then no longer be used in macro relational expressions (such as
+ *  #if DUK_SIZE_MAX < 0xffffffffUL).  There is internal code which relies on
+ *  being able to compare DUK_SIZE_MAX against a limit.
+ */
+
+/* XXX: add feature options to force basic types from outside? */
+
+#if !defined(INT_MAX)
+#error INT_MAX not defined
+#endif
+
+/* Check that architecture is two's complement, standard C allows e.g.
+ * INT_MIN to be -2**31+1 (instead of -2**31).
+ */
+#if defined(INT_MAX) && defined(INT_MIN)
+#if INT_MAX != -(INT_MIN + 1)
+#error platform does not seem complement of two
+#endif
+#else
+#error cannot check complement of two
+#endif
+
+/* Pointer size determination based on __WORDSIZE or architecture when
+ * that's not available.
+ */
+#if defined(DUK_F_X86) || defined(DUK_F_X32) || \
+    defined(DUK_F_M68K) || defined(DUK_F_PPC32) || \
+    defined(DUK_F_BCC) || \
+    (defined(__WORDSIZE) && (__WORDSIZE == 32))
+#define DUK_F_32BIT_PTRS
+#elif defined(DUK_F_X64) || \
+      (defined(__WORDSIZE) && (__WORDSIZE == 64))
+#define DUK_F_64BIT_PTRS
+#else
+/* not sure, not needed with C99 anyway */
+#endif
+
+/* Intermediate define for 'have inttypes.h' */
+#undef DUK_F_HAVE_INTTYPES
+#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && \
+    !(defined(DUK_F_AMIGAOS) && defined(DUK_F_VBCC))
+/* vbcc + AmigaOS has C99 but no inttypes.h */
+#define DUK_F_HAVE_INTTYPES
+#elif defined(__cplusplus) && (__cplusplus >= 201103L)
+/* C++11 apparently ratified stdint.h */
+#define DUK_F_HAVE_INTTYPES
+#endif
+
+/* Basic integer typedefs and limits, preferably from inttypes.h, otherwise
+ * through automatic detection.
+ */
+#if defined(DUK_F_HAVE_INTTYPES)
+/* C99 or compatible */
+
+#define DUK_F_HAVE_64BIT
+#include <inttypes.h>
+
+typedef uint8_t duk_uint8_t;
+typedef int8_t duk_int8_t;
+typedef uint16_t duk_uint16_t;
+typedef int16_t duk_int16_t;
+typedef uint32_t duk_uint32_t;
+typedef int32_t duk_int32_t;
+typedef uint64_t duk_uint64_t;
+typedef int64_t duk_int64_t;
+typedef uint_least8_t duk_uint_least8_t;
+typedef int_least8_t duk_int_least8_t;
+typedef uint_least16_t duk_uint_least16_t;
+typedef int_least16_t duk_int_least16_t;
+typedef uint_least32_t duk_uint_least32_t;
+typedef int_least32_t duk_int_least32_t;
+typedef uint_least64_t duk_uint_least64_t;
+typedef int_least64_t duk_int_least64_t;
+typedef uint_fast8_t duk_uint_fast8_t;
+typedef int_fast8_t duk_int_fast8_t;
+typedef uint_fast16_t duk_uint_fast16_t;
+typedef int_fast16_t duk_int_fast16_t;
+typedef uint_fast32_t duk_uint_fast32_t;
+typedef int_fast32_t duk_int_fast32_t;
+typedef uint_fast64_t duk_uint_fast64_t;
+typedef int_fast64_t duk_int_fast64_t;
+typedef uintptr_t duk_uintptr_t;
+typedef intptr_t duk_intptr_t;
+typedef uintmax_t duk_uintmax_t;
+typedef intmax_t duk_intmax_t;
+
+#define DUK_UINT8_MIN         0
+#define DUK_UINT8_MAX         UINT8_MAX
+#define DUK_INT8_MIN          INT8_MIN
+#define DUK_INT8_MAX          INT8_MAX
+#define DUK_UINT_LEAST8_MIN   0
+#define DUK_UINT_LEAST8_MAX   UINT_LEAST8_MAX
+#define DUK_INT_LEAST8_MIN    INT_LEAST8_MIN
+#define DUK_INT_LEAST8_MAX    INT_LEAST8_MAX
+#define DUK_UINT_FAST8_MIN    0
+#define DUK_UINT_FAST8_MAX    UINT_FAST8_MAX
+#define DUK_INT_FAST8_MIN     INT_FAST8_MIN
+#define DUK_INT_FAST8_MAX     INT_FAST8_MAX
+#define DUK_UINT16_MIN        0
+#define DUK_UINT16_MAX        UINT16_MAX
+#define DUK_INT16_MIN         INT16_MIN
+#define DUK_INT16_MAX         INT16_MAX
+#define DUK_UINT_LEAST16_MIN  0
+#define DUK_UINT_LEAST16_MAX  UINT_LEAST16_MAX
+#define DUK_INT_LEAST16_MIN   INT_LEAST16_MIN
+#define DUK_INT_LEAST16_MAX   INT_LEAST16_MAX
+#define DUK_UINT_FAST16_MIN   0
+#define DUK_UINT_FAST16_MAX   UINT_FAST16_MAX
+#define DUK_INT_FAST16_MIN    INT_FAST16_MIN
+#define DUK_INT_FAST16_MAX    INT_FAST16_MAX
+#define DUK_UINT32_MIN        0
+#define DUK_UINT32_MAX        UINT32_MAX
+#define DUK_INT32_MIN         INT32_MIN
+#define DUK_INT32_MAX         INT32_MAX
+#define DUK_UINT_LEAST32_MIN  0
+#define DUK_UINT_LEAST32_MAX  UINT_LEAST32_MAX
+#define DUK_INT_LEAST32_MIN   INT_LEAST32_MIN
+#define DUK_INT_LEAST32_MAX   INT_LEAST32_MAX
+#define DUK_UINT_FAST32_MIN   0
+#define DUK_UINT_FAST32_MAX   UINT_FAST32_MAX
+#define DUK_INT_FAST32_MIN    INT_FAST32_MIN
+#define DUK_INT_FAST32_MAX    INT_FAST32_MAX
+#define DUK_UINT64_MIN        0
+#define DUK_UINT64_MAX        UINT64_MAX
+#define DUK_INT64_MIN         INT64_MIN
+#define DUK_INT64_MAX         INT64_MAX
+#define DUK_UINT_LEAST64_MIN  0
+#define DUK_UINT_LEAST64_MAX  UINT_LEAST64_MAX
+#define DUK_INT_LEAST64_MIN   INT_LEAST64_MIN
+#define DUK_INT_LEAST64_MAX   INT_LEAST64_MAX
+#define DUK_UINT_FAST64_MIN   0
+#define DUK_UINT_FAST64_MAX   UINT_FAST64_MAX
+#define DUK_INT_FAST64_MIN    INT_FAST64_MIN
+#define DUK_INT_FAST64_MAX    INT_FAST64_MAX
+
+#define DUK_UINTPTR_MIN       0
+#define DUK_UINTPTR_MAX       UINTPTR_MAX
+#define DUK_INTPTR_MIN        INTPTR_MIN
+#define DUK_INTPTR_MAX        INTPTR_MAX
+
+#define DUK_UINTMAX_MIN       0
+#define DUK_UINTMAX_MAX       UINTMAX_MAX
+#define DUK_INTMAX_MIN        INTMAX_MIN
+#define DUK_INTMAX_MAX        INTMAX_MAX
+
+#define DUK_SIZE_MIN          0
+#define DUK_SIZE_MAX          SIZE_MAX
+#undef DUK_SIZE_MAX_COMPUTED
+
+#else  /* C99 types */
+
+/* When C99 types are not available, we use heuristic detection to get
+ * the basic 8, 16, 32, and (possibly) 64 bit types.  The fast/least
+ * types are then assumed to be exactly the same for now: these could
+ * be improved per platform but C99 types are very often now available.
+ * 64-bit types are not available on all platforms; this is OK at least
+ * on 32-bit platforms.
+ *
+ * This detection code is necessarily a bit hacky and can provide typedefs
+ * and defines that won't work correctly on some exotic platform.
+ */
+
+#if (defined(CHAR_BIT) && (CHAR_BIT == 8)) || \
+    (defined(UCHAR_MAX) && (UCHAR_MAX == 255))
+typedef unsigned char duk_uint8_t;
+typedef signed char duk_int8_t;
+#else
+#error cannot detect 8-bit type
+#endif
+
+#if defined(USHRT_MAX) && (USHRT_MAX == 65535UL)
+typedef unsigned short duk_uint16_t;
+typedef signed short duk_int16_t;
+#elif defined(UINT_MAX) && (UINT_MAX == 65535UL)
+/* On some platforms int is 16-bit but long is 32-bit (e.g. PureC) */
+typedef unsigned int duk_uint16_t;
+typedef signed int duk_int16_t;
+#else
+#error cannot detect 16-bit type
+#endif
+
+#if defined(UINT_MAX) && (UINT_MAX == 4294967295UL)
+typedef unsigned int duk_uint32_t;
+typedef signed int duk_int32_t;
+#elif defined(ULONG_MAX) && (ULONG_MAX == 4294967295UL)
+/* On some platforms int is 16-bit but long is 32-bit (e.g. PureC) */
+typedef unsigned long duk_uint32_t;
+typedef signed long duk_int32_t;
+#else
+#error cannot detect 32-bit type
+#endif
+
+/* 64-bit type detection is a bit tricky.
+ *
+ * ULLONG_MAX is a standard define.  __LONG_LONG_MAX__ and __ULONG_LONG_MAX__
+ * are used by at least GCC (even if system headers don't provide ULLONG_MAX).
+ * Some GCC variants may provide __LONG_LONG_MAX__ but not __ULONG_LONG_MAX__.
+ *
+ * ULL / LL constants are rejected / warned about by some compilers, even if
+ * the compiler has a 64-bit type and the compiler/system headers provide an
+ * unsupported constant (ULL/LL)!  Try to avoid using ULL / LL constants.
+ * As a side effect we can only check that e.g. ULONG_MAX is larger than 32
+ * bits but can't be sure it is exactly 64 bits.  Self tests will catch such
+ * cases.
+ */
+#undef DUK_F_HAVE_64BIT
+#if !defined(DUK_F_HAVE_64BIT) && defined(ULONG_MAX)
+#if (ULONG_MAX > 4294967295UL)
+#define DUK_F_HAVE_64BIT
+typedef unsigned long duk_uint64_t;
+typedef signed long duk_int64_t;
+#endif
+#endif
+#if !defined(DUK_F_HAVE_64BIT) && defined(ULLONG_MAX)
+#if (ULLONG_MAX > 4294967295UL)
+#define DUK_F_HAVE_64BIT
+typedef unsigned long long duk_uint64_t;
+typedef signed long long duk_int64_t;
+#endif
+#endif
+#if !defined(DUK_F_HAVE_64BIT) && defined(__ULONG_LONG_MAX__)
+#if (__ULONG_LONG_MAX__ > 4294967295UL)
+#define DUK_F_HAVE_64BIT
+typedef unsigned long long duk_uint64_t;
+typedef signed long long duk_int64_t;
+#endif
+#endif
+#if !defined(DUK_F_HAVE_64BIT) && defined(__LONG_LONG_MAX__)
+#if (__LONG_LONG_MAX__ > 2147483647L)
+#define DUK_F_HAVE_64BIT
+typedef unsigned long long duk_uint64_t;
+typedef signed long long duk_int64_t;
+#endif
+#endif
+#if !defined(DUK_F_HAVE_64BIT) && \
+    (defined(DUK_F_MINGW) || defined(DUK_F_MSVC))
+/* Both MinGW and MSVC have a 64-bit type. */
+#define DUK_F_HAVE_64BIT
+typedef unsigned long duk_uint64_t;
+typedef signed long duk_int64_t;
+#endif
+#if !defined(DUK_F_HAVE_64BIT)
+/* cannot detect 64-bit type, not always needed so don't error */
+#endif
+
+typedef duk_uint8_t duk_uint_least8_t;
+typedef duk_int8_t duk_int_least8_t;
+typedef duk_uint16_t duk_uint_least16_t;
+typedef duk_int16_t duk_int_least16_t;
+typedef duk_uint32_t duk_uint_least32_t;
+typedef duk_int32_t duk_int_least32_t;
+typedef duk_uint8_t duk_uint_fast8_t;
+typedef duk_int8_t duk_int_fast8_t;
+typedef duk_uint16_t duk_uint_fast16_t;
+typedef duk_int16_t duk_int_fast16_t;
+typedef duk_uint32_t duk_uint_fast32_t;
+typedef duk_int32_t duk_int_fast32_t;
+#if defined(DUK_F_HAVE_64BIT)
+typedef duk_uint64_t duk_uint_least64_t;
+typedef duk_int64_t duk_int_least64_t;
+typedef duk_uint64_t duk_uint_fast64_t;
+typedef duk_int64_t duk_int_fast64_t;
+#endif
+#if defined(DUK_F_HAVE_64BIT)
+typedef duk_uint64_t duk_uintmax_t;
+typedef duk_int64_t duk_intmax_t;
+#else
+typedef duk_uint32_t duk_uintmax_t;
+typedef duk_int32_t duk_intmax_t;
+#endif
+
+/* Note: the funny looking computations for signed minimum 16-bit, 32-bit, and
+ * 64-bit values are intentional as the obvious forms (e.g. -0x80000000L) are
+ * -not- portable.  See code-issues.txt for a detailed discussion.
+ */
+#define DUK_UINT8_MIN         0UL
+#define DUK_UINT8_MAX         0xffUL
+#define DUK_INT8_MIN          (-0x80L)
+#define DUK_INT8_MAX          0x7fL
+#define DUK_UINT_LEAST8_MIN   0UL
+#define DUK_UINT_LEAST8_MAX   0xffUL
+#define DUK_INT_LEAST8_MIN    (-0x80L)
+#define DUK_INT_LEAST8_MAX    0x7fL
+#define DUK_UINT_FAST8_MIN    0UL
+#define DUK_UINT_FAST8_MAX    0xffUL
+#define DUK_INT_FAST8_MIN     (-0x80L)
+#define DUK_INT_FAST8_MAX     0x7fL
+#define DUK_UINT16_MIN        0UL
+#define DUK_UINT16_MAX        0xffffUL
+#define DUK_INT16_MIN         (-0x7fffL - 1L)
+#define DUK_INT16_MAX         0x7fffL
+#define DUK_UINT_LEAST16_MIN  0UL
+#define DUK_UINT_LEAST16_MAX  0xffffUL
+#define DUK_INT_LEAST16_MIN   (-0x7fffL - 1L)
+#define DUK_INT_LEAST16_MAX   0x7fffL
+#define DUK_UINT_FAST16_MIN   0UL
+#define DUK_UINT_FAST16_MAX   0xffffUL
+#define DUK_INT_FAST16_MIN    (-0x7fffL - 1L)
+#define DUK_INT_FAST16_MAX    0x7fffL
+#define DUK_UINT32_MIN        0UL
+#define DUK_UINT32_MAX        0xffffffffUL
+#define DUK_INT32_MIN         (-0x7fffffffL - 1L)
+#define DUK_INT32_MAX         0x7fffffffL
+#define DUK_UINT_LEAST32_MIN  0UL
+#define DUK_UINT_LEAST32_MAX  0xffffffffUL
+#define DUK_INT_LEAST32_MIN   (-0x7fffffffL - 1L)
+#define DUK_INT_LEAST32_MAX   0x7fffffffL
+#define DUK_UINT_FAST32_MIN   0UL
+#define DUK_UINT_FAST32_MAX   0xffffffffUL
+#define DUK_INT_FAST32_MIN    (-0x7fffffffL - 1L)
+#define DUK_INT_FAST32_MAX    0x7fffffffL
+
+/* 64-bit constants.  Since LL / ULL constants are not always available,
+ * use computed values.  These values can't be used in preprocessor
+ * comparisons; flag them as such.
+ */
+#if defined(DUK_F_HAVE_64BIT)
+#define DUK_UINT64_MIN        ((duk_uint64_t) 0)
+#define DUK_UINT64_MAX        ((duk_uint64_t) -1)
+#define DUK_INT64_MIN         ((duk_int64_t) (~(DUK_UINT64_MAX >> 1)))
+#define DUK_INT64_MAX         ((duk_int64_t) (DUK_UINT64_MAX >> 1))
+#define DUK_UINT_LEAST64_MIN  DUK_UINT64_MIN
+#define DUK_UINT_LEAST64_MAX  DUK_UINT64_MAX
+#define DUK_INT_LEAST64_MIN   DUK_INT64_MIN
+#define DUK_INT_LEAST64_MAX   DUK_INT64_MAX
+#define DUK_UINT_FAST64_MIN   DUK_UINT64_MIN
+#define DUK_UINT_FAST64_MAX   DUK_UINT64_MAX
+#define DUK_INT_FAST64_MIN    DUK_INT64_MIN
+#define DUK_INT_FAST64_MAX    DUK_INT64_MAX
+#define DUK_UINT64_MIN_COMPUTED
+#define DUK_UINT64_MAX_COMPUTED
+#define DUK_INT64_MIN_COMPUTED
+#define DUK_INT64_MAX_COMPUTED
+#define DUK_UINT_LEAST64_MIN_COMPUTED
+#define DUK_UINT_LEAST64_MAX_COMPUTED
+#define DUK_INT_LEAST64_MIN_COMPUTED
+#define DUK_INT_LEAST64_MAX_COMPUTED
+#define DUK_UINT_FAST64_MIN_COMPUTED
+#define DUK_UINT_FAST64_MAX_COMPUTED
+#define DUK_INT_FAST64_MIN_COMPUTED
+#define DUK_INT_FAST64_MAX_COMPUTED
+#endif
+
+#if defined(DUK_F_HAVE_64BIT)
+#define DUK_UINTMAX_MIN       DUK_UINT64_MIN
+#define DUK_UINTMAX_MAX       DUK_UINT64_MAX
+#define DUK_INTMAX_MIN        DUK_INT64_MIN
+#define DUK_INTMAX_MAX        DUK_INT64_MAX
+#define DUK_UINTMAX_MIN_COMPUTED
+#define DUK_UINTMAX_MAX_COMPUTED
+#define DUK_INTMAX_MIN_COMPUTED
+#define DUK_INTMAX_MAX_COMPUTED
+#else
+#define DUK_UINTMAX_MIN       0UL
+#define DUK_UINTMAX_MAX       0xffffffffUL
+#define DUK_INTMAX_MIN        (-0x7fffffffL - 1L)
+#define DUK_INTMAX_MAX        0x7fffffffL
+#endif
+
+/* This detection is not very reliable. */
+#if defined(DUK_F_32BIT_PTRS)
+typedef duk_int32_t duk_intptr_t;
+typedef duk_uint32_t duk_uintptr_t;
+#define DUK_UINTPTR_MIN       DUK_UINT32_MIN
+#define DUK_UINTPTR_MAX       DUK_UINT32_MAX
+#define DUK_INTPTR_MIN        DUK_INT32_MIN
+#define DUK_INTPTR_MAX        DUK_INT32_MAX
+#elif defined(DUK_F_64BIT_PTRS) && defined(DUK_F_HAVE_64BIT)
+typedef duk_int64_t duk_intptr_t;
+typedef duk_uint64_t duk_uintptr_t;
+#define DUK_UINTPTR_MIN       DUK_UINT64_MIN
+#define DUK_UINTPTR_MAX       DUK_UINT64_MAX
+#define DUK_INTPTR_MIN        DUK_INT64_MIN
+#define DUK_INTPTR_MAX        DUK_INT64_MAX
+#define DUK_UINTPTR_MIN_COMPUTED
+#define DUK_UINTPTR_MAX_COMPUTED
+#define DUK_INTPTR_MIN_COMPUTED
+#define DUK_INTPTR_MAX_COMPUTED
+#else
+#error cannot determine intptr type
+#endif
+
+/* SIZE_MAX may be missing so use an approximate value for it. */
+#undef DUK_SIZE_MAX_COMPUTED
+#if !defined(SIZE_MAX)
+#define DUK_SIZE_MAX_COMPUTED
+#define SIZE_MAX              ((size_t) (-1))
+#endif
+#define DUK_SIZE_MIN          0
+#define DUK_SIZE_MAX          SIZE_MAX
+
+#endif  /* C99 types */
+
+/* A few types are assumed to always exist. */
+typedef size_t duk_size_t;
+typedef ptrdiff_t duk_ptrdiff_t;
+
+/* The best type for an "all around int" in Duktape internals is "at least
+ * 32 bit signed integer" which is most convenient.  Same for unsigned type.
+ * Prefer 'int' when large enough, as it is almost always a convenient type.
+ */
+#if defined(UINT_MAX) && (UINT_MAX >= 0xffffffffUL)
+typedef int duk_int_t;
+typedef unsigned int duk_uint_t;
+#define DUK_INT_MIN           INT_MIN
+#define DUK_INT_MAX           INT_MAX
+#define DUK_UINT_MIN          0
+#define DUK_UINT_MAX          UINT_MAX
+#else
+typedef duk_int_fast32_t duk_int_t;
+typedef duk_uint_fast32_t duk_uint_t;
+#define DUK_INT_MIN           DUK_INT_FAST32_MIN
+#define DUK_INT_MAX           DUK_INT_FAST32_MAX
+#define DUK_UINT_MIN          DUK_UINT_FAST32_MIN
+#define DUK_UINT_MAX          DUK_UINT_FAST32_MAX
+#endif
+
+/* Same as 'duk_int_t' but guaranteed to be a 'fast' variant if this
+ * distinction matters for the CPU.  These types are used mainly in the
+ * executor where it might really matter.
+ */
+typedef duk_int_fast32_t duk_int_fast_t;
+typedef duk_uint_fast32_t duk_uint_fast_t;
+#define DUK_INT_FAST_MIN      DUK_INT_FAST32_MIN
+#define DUK_INT_FAST_MAX      DUK_INT_FAST32_MAX
+#define DUK_UINT_FAST_MIN     DUK_UINT_FAST32_MIN
+#define DUK_UINT_FAST_MAX     DUK_UINT_FAST32_MAX
+
+/* Small integers (16 bits or more) can fall back to the 'int' type, but
+ * have a typedef so they are marked "small" explicitly.
+ */
+typedef int duk_small_int_t;
+typedef unsigned int duk_small_uint_t;
+#define DUK_SMALL_INT_MIN     INT_MIN
+#define DUK_SMALL_INT_MAX     INT_MAX
+#define DUK_SMALL_UINT_MIN    0
+#define DUK_SMALL_UINT_MAX    UINT_MAX
+
+/* Fast variants of small integers, again for really fast paths like the
+ * executor.
+ */
+typedef duk_int_fast16_t duk_small_int_fast_t;
+typedef duk_uint_fast16_t duk_small_uint_fast_t;
+#define DUK_SMALL_INT_FAST_MIN    DUK_INT_FAST16_MIN
+#define DUK_SMALL_INT_FAST_MAX    DUK_INT_FAST16_MAX
+#define DUK_SMALL_UINT_FAST_MIN   DUK_UINT_FAST16_MIN
+#define DUK_SMALL_UINT_FAST_MAX   DUK_UINT_FAST16_MAX
+
+/* Boolean values are represented with the platform 'int'. */
+typedef duk_small_int_t duk_bool_t;
+#define DUK_BOOL_MIN              DUK_SMALL_INT_MIN
+#define DUK_BOOL_MAX              DUK_SMALL_INT_MAX
+
+/* Index values must have at least 32-bit signed range. */
+typedef duk_int_t duk_idx_t;
+#define DUK_IDX_MIN               DUK_INT_MIN
+#define DUK_IDX_MAX               DUK_INT_MAX
+
+/* Unsigned index variant. */
+typedef duk_uint_t duk_uidx_t;
+#define DUK_UIDX_MIN              DUK_UINT_MIN
+#define DUK_UIDX_MAX              DUK_UINT_MAX
+
+/* Array index values, could be exact 32 bits.
+ * Currently no need for signed duk_arridx_t.
+ */
+typedef duk_uint_t duk_uarridx_t;
+#define DUK_UARRIDX_MIN           DUK_UINT_MIN
+#define DUK_UARRIDX_MAX           DUK_UINT_MAX
+
+/* Duktape/C function return value, platform int is enough for now to
+ * represent 0, 1, or negative error code.  Must be compatible with
+ * assigning truth values (e.g. duk_ret_t rc = (foo == bar);).
+ */
+typedef duk_small_int_t duk_ret_t;
+#define DUK_RET_MIN               DUK_SMALL_INT_MIN
+#define DUK_RET_MAX               DUK_SMALL_INT_MAX
+
+/* Error codes are represented with platform int.  High bits are used
+ * for flags and such, so 32 bits are needed.
+ */
+typedef duk_int_t duk_errcode_t;
+#define DUK_ERRCODE_MIN           DUK_INT_MIN
+#define DUK_ERRCODE_MAX           DUK_INT_MAX
+
+/* Codepoint type.  Must be 32 bits or more because it is used also for
+ * internal codepoints.  The type is signed because negative codepoints
+ * are used as internal markers (e.g. to mark EOF or missing argument).
+ * (X)UTF-8/CESU-8 encode/decode take and return an unsigned variant to
+ * ensure duk_uint32_t casts back and forth nicely.  Almost everything
+ * else uses the signed one.
+ */
+typedef duk_int_t duk_codepoint_t;
+typedef duk_uint_t duk_ucodepoint_t;
+#define DUK_CODEPOINT_MIN         DUK_INT_MIN
+#define DUK_CODEPOINT_MAX         DUK_INT_MAX
+#define DUK_UCODEPOINT_MIN        DUK_UINT_MIN
+#define DUK_UCODEPOINT_MAX        DUK_UINT_MAX
+
+/* IEEE float/double typedef. */
+typedef float duk_float_t;
+typedef double duk_double_t;
+
+/* We're generally assuming that we're working on a platform with a 32-bit
+ * address space.  If DUK_SIZE_MAX is a typecast value (which is necessary
+ * if SIZE_MAX is missing), the check must be avoided because the
+ * preprocessor can't do a comparison.
+ */
+#if !defined(DUK_SIZE_MAX)
+#error DUK_SIZE_MAX is undefined, probably missing SIZE_MAX
+#elif !defined(DUK_SIZE_MAX_COMPUTED)
+#if DUK_SIZE_MAX < 0xffffffffUL
+/* On some systems SIZE_MAX can be smaller than max unsigned 32-bit value
+ * which seems incorrect if size_t is (at least) an unsigned 32-bit type.
+ * However, it doesn't seem useful to error out compilation if this is the
+ * case.
+ */
+#endif
+#endif
+
+/* Type for public API calls. */
+typedef struct duk_hthread duk_context;
+
+/* Check whether we should use 64-bit integers or not.
+ *
+ * Quite incomplete now.  Use 64-bit types if detected (C99 or other detection)
+ * unless they are known to be unreliable.  For instance, 64-bit types are
+ * available on VBCC but seem to misbehave.
+ */
+#if defined(DUK_F_HAVE_64BIT) && !defined(DUK_F_VBCC)
+#define DUK_USE_64BIT_OPS
+#else
+#undef DUK_USE_64BIT_OPS
+#endif
+
+/*
+ *  Fill-ins for platform, architecture, and compiler
+ */
+
+#if !defined(DUK_SETJMP)
+#define DUK_JMPBUF_TYPE       jmp_buf
+#define DUK_SETJMP(jb)        setjmp((jb))
+#define DUK_LONGJMP(jb)       longjmp((jb), 1)
+#endif
+
+#if 0
+/* sigsetjmp() alternative */
+#define DUK_JMPBUF_TYPE       sigjmp_buf
+#define DUK_SETJMP(jb)        sigsetjmp((jb))
+#define DUK_LONGJMP(jb)       siglongjmp((jb), 1)
+#endif
+
+typedef FILE duk_file;
+#if !defined(DUK_STDIN)
+#define DUK_STDIN       stdin
+#endif
+#if !defined(DUK_STDOUT)
+#define DUK_STDOUT      stdout
+#endif
+#if !defined(DUK_STDERR)
+#define DUK_STDERR      stderr
+#endif
+
+/* Special naming to avoid conflict with e.g. DUK_FREE() in duk_heap.h
+ * (which is unfortunately named).  May sometimes need replacement, e.g.
+ * some compilers don't handle zero length or NULL correctly in realloc().
+ */
+#if !defined(DUK_ANSI_MALLOC)
+#define DUK_ANSI_MALLOC      malloc
+#endif
+#if !defined(DUK_ANSI_REALLOC)
+#define DUK_ANSI_REALLOC     realloc
+#endif
+#if !defined(DUK_ANSI_CALLOC)
+#define DUK_ANSI_CALLOC      calloc
+#endif
+#if !defined(DUK_ANSI_FREE)
+#define DUK_ANSI_FREE        free
+#endif
+
+/* ANSI C (various versions) and some implementations require that the
+ * pointer arguments to memset(), memcpy(), and memmove() be valid values
+ * even when byte size is 0 (even a NULL pointer is considered invalid in
+ * this context).  Zero-size operations as such are allowed, as long as their
+ * pointer arguments point to a valid memory area.  The DUK_MEMSET(),
+ * DUK_MEMCPY(), and DUK_MEMMOVE() macros require this same behavior, i.e.:
+ * (1) pointers must be valid and non-NULL, (2) zero size must otherwise be
+ * allowed.  If these are not fulfilled, a macro wrapper is needed.
+ *
+ *   http://stackoverflow.com/questions/5243012/is-it-guaranteed-to-be-safe-to-perform-memcpy0-0-0
+ *   http://lists.cs.uiuc.edu/pipermail/llvmdev/2007-October/011065.html
+ *
+ * Not sure what's the required behavior when a pointer points just past the
+ * end of a buffer, which often happens in practice (e.g. zero size memmoves).
+ * For example, if allocation size is 3, the following pointer would not
+ * technically point to a valid memory byte:
+ *
+ *   <-- alloc -->
+ *   | 0 | 1 | 2 | .....
+ *                 ^-- p=3, points after last valid byte (2)
+ */
+#if !defined(DUK_MEMCPY)
+#if defined(DUK_F_UCLIBC)
+/* Old uclibcs have a broken memcpy so use memmove instead (this is overly wide
+ * now on purpose): http://lists.uclibc.org/pipermail/uclibc-cvs/2008-October/025511.html
+ */
+#define DUK_MEMCPY       memmove
+#else
+#define DUK_MEMCPY       memcpy
+#endif
+#endif
+#if !defined(DUK_MEMMOVE)
+#define DUK_MEMMOVE      memmove
+#endif
+#if !defined(DUK_MEMCMP)
+#define DUK_MEMCMP       memcmp
+#endif
+#if !defined(DUK_MEMSET)
+#define DUK_MEMSET       memset
+#endif
+#if !defined(DUK_STRLEN)
+#define DUK_STRLEN       strlen
+#endif
+#if !defined(DUK_STRCMP)
+#define DUK_STRCMP       strcmp
+#endif
+#if !defined(DUK_STRNCMP)
+#define DUK_STRNCMP      strncmp
+#endif
+#if !defined(DUK_PRINTF)
+#define DUK_PRINTF       printf
+#endif
+#if !defined(DUK_FPRINTF)
+#define DUK_FPRINTF      fprintf
+#endif
+#if !defined(DUK_SPRINTF)
+#define DUK_SPRINTF      sprintf
+#endif
+#if !defined(DUK_SNPRINTF)
+/* snprintf() is technically not part of C89 but usually available. */
+#define DUK_SNPRINTF     snprintf
+#endif
+#if !defined(DUK_VSPRINTF)
+#define DUK_VSPRINTF     vsprintf
+#endif
+#if !defined(DUK_VSNPRINTF)
+/* vsnprintf() is technically not part of C89 but usually available. */
+#define DUK_VSNPRINTF    vsnprintf
+#endif
+#if !defined(DUK_SSCANF)
+#define DUK_SSCANF       sscanf
+#endif
+#if !defined(DUK_VSSCANF)
+#define DUK_VSSCANF      vsscanf
+#endif
+#if !defined(DUK_FOPEN)
+#define DUK_FOPEN        fopen
+#endif
+#if !defined(DUK_FCLOSE)
+#define DUK_FCLOSE       fclose
+#endif
+#if !defined(DUK_FREAD)
+#define DUK_FREAD        fread
+#endif
+#if !defined(DUK_FWRITE)
+#define DUK_FWRITE       fwrite
+#endif
+#if !defined(DUK_FSEEK)
+#define DUK_FSEEK        fseek
+#endif
+#if !defined(DUK_FTELL)
+#define DUK_FTELL        ftell
+#endif
+#if !defined(DUK_FFLUSH)
+#define DUK_FFLUSH       fflush
+#endif
+#if !defined(DUK_FPUTC)
+#define DUK_FPUTC        fputc
+#endif
+#if !defined(DUK_MEMZERO)
+#define DUK_MEMZERO(p,n) DUK_MEMSET((p), 0, (n))
+#endif
+#if !defined(DUK_ABORT)
+#define DUK_ABORT        abort
+#endif
+#if !defined(DUK_EXIT)
+#define DUK_EXIT         exit
+#endif
+
+#if !defined(DUK_DOUBLE_2TO32)
+#define DUK_DOUBLE_2TO32     4294967296.0
+#endif
+#if !defined(DUK_DOUBLE_2TO31)
+#define DUK_DOUBLE_2TO31     2147483648.0
+#endif
+
+#if !defined(DUK_DOUBLE_INFINITY)
+#undef DUK_USE_COMPUTED_INFINITY
+#if defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION < 40600)
+/* GCC older than 4.6: avoid overflow warnings related to using INFINITY */
+#define DUK_DOUBLE_INFINITY  (__builtin_inf())
+#elif defined(INFINITY)
+#define DUK_DOUBLE_INFINITY  ((double) INFINITY)
+#elif !defined(DUK_F_VBCC) && !defined(DUK_F_MSVC) && !defined(DUK_F_BCC)
+#define DUK_DOUBLE_INFINITY  (1.0 / 0.0)
+#else
+/* In VBCC (1.0 / 0.0) results in a warning and 0.0 instead of infinity.
+ * Use a computed infinity (initialized when a heap is created at the
+ * latest).
+ */
+#define DUK_USE_COMPUTED_INFINITY
+#define DUK_DOUBLE_INFINITY  duk_computed_infinity
+#endif
+#endif
+
+#if !defined(DUK_DOUBLE_NAN)
+#undef DUK_USE_COMPUTED_NAN
+#if defined(NAN)
+#define DUK_DOUBLE_NAN       NAN
+#elif !defined(DUK_F_VBCC) && !defined(DUK_F_MSVC) && !defined(DUK_F_BCC)
+#define DUK_DOUBLE_NAN       (0.0 / 0.0)
+#else
+/* In VBCC (0.0 / 0.0) results in a warning and 0.0 instead of NaN.
+ * In MSVC (VS2010 Express) (0.0 / 0.0) results in a compile error.
+ * Use a computed NaN (initialized when a heap is created at the
+ * latest).
+ */
+#define DUK_USE_COMPUTED_NAN
+#define DUK_DOUBLE_NAN       duk_computed_nan
+#endif
+#endif
+
+/* Many platforms are missing fpclassify() and friends, so use replacements
+ * if necessary.  The replacement constants (FP_NAN etc) can be anything but
+ * match Linux constants now.
+ */
+#undef DUK_USE_REPL_FPCLASSIFY
+#undef DUK_USE_REPL_SIGNBIT
+#undef DUK_USE_REPL_ISFINITE
+#undef DUK_USE_REPL_ISNAN
+#undef DUK_USE_REPL_ISINF
+
+/* Complex condition broken into separate parts. */
+#undef DUK_F_USE_REPL_ALL
+#if !(defined(FP_NAN) && defined(FP_INFINITE) && defined(FP_ZERO) && \
+      defined(FP_SUBNORMAL) && defined(FP_NORMAL))
+/* Missing some obvious constants. */
+#define DUK_F_USE_REPL_ALL
+#elif defined(DUK_F_AMIGAOS) && defined(DUK_F_VBCC)
+/* VBCC is missing the built-ins even in C99 mode (perhaps a header issue). */
+#define DUK_F_USE_REPL_ALL
+#elif defined(DUK_F_AMIGAOS) && defined(DUK_F_M68K)
+/* AmigaOS + M68K seems to have math issues even when using GCC cross
+ * compilation.  Use replacements for all AmigaOS versions on M68K
+ * regardless of compiler.
+ */
+#define DUK_F_USE_REPL_ALL
+#elif defined(DUK_F_FREEBSD) && defined(DUK_F_CLANG)
+/* Placeholder fix for (detection is wider than necessary):
+ * http://llvm.org/bugs/show_bug.cgi?id=17788
+ */
+#define DUK_F_USE_REPL_ALL
+#elif defined(DUK_F_UCLIBC)
+/* At least some uclibc versions have broken floating point math.  For
+ * example, fpclassify() can incorrectly classify certain NaN formats.
+ * To be safe, use replacements.
+ */
+#define DUK_F_USE_REPL_ALL
+#endif
+
+#if defined(DUK_F_USE_REPL_ALL)
+#define DUK_USE_REPL_FPCLASSIFY
+#define DUK_USE_REPL_SIGNBIT
+#define DUK_USE_REPL_ISFINITE
+#define DUK_USE_REPL_ISNAN
+#define DUK_USE_REPL_ISINF
+#define DUK_FPCLASSIFY       duk_repl_fpclassify
+#define DUK_SIGNBIT          duk_repl_signbit
+#define DUK_ISFINITE         duk_repl_isfinite
+#define DUK_ISNAN            duk_repl_isnan
+#define DUK_ISINF            duk_repl_isinf
+#define DUK_FP_NAN           0
+#define DUK_FP_INFINITE      1
+#define DUK_FP_ZERO          2
+#define DUK_FP_SUBNORMAL     3
+#define DUK_FP_NORMAL        4
+#else
+#define DUK_FPCLASSIFY       fpclassify
+#define DUK_SIGNBIT          signbit
+#define DUK_ISFINITE         isfinite
+#define DUK_ISNAN            isnan
+#define DUK_ISINF            isinf
+#define DUK_FP_NAN           FP_NAN
+#define DUK_FP_INFINITE      FP_INFINITE
+#define DUK_FP_ZERO          FP_ZERO
+#define DUK_FP_SUBNORMAL     FP_SUBNORMAL
+#define DUK_FP_NORMAL        FP_NORMAL
+#endif
+
+#if defined(DUK_F_USE_REPL_ALL)
+#undef DUK_F_USE_REPL_ALL
+#endif
+
+/* Some math functions are C99 only.  This is also an issue with some
+ * embedded environments using uclibc where uclibc has been configured
+ * not to provide some functions.  For now, use replacements whenever
+ * using uclibc.
+ */
+#undef DUK_USE_MATH_FMIN
+#undef DUK_USE_MATH_FMAX
+#undef DUK_USE_MATH_ROUND
+#if defined(DUK_F_UCLIBC)
+/* uclibc may be missing these */
+#elif defined(DUK_F_AMIGAOS) && defined(DUK_F_VBCC)
+/* vbcc + AmigaOS may be missing these */
+#elif defined(DUK_F_MINT)
+/* mint clib is missing these */
+#elif !defined(DUK_F_C99) && !defined(DUK_F_CPP11)
+/* build is not C99 or C++11, play it safe */
+#else
+/* C99 or C++11, no known issues */
+#define DUK_USE_MATH_FMIN
+#define DUK_USE_MATH_FMAX
+#define DUK_USE_MATH_ROUND
+#endif
+
+/* These functions don't currently need replacement but are wrapped for
+ * completeness.  Because these are used as function pointers, they need
+ * to be defined as concrete C functions (not macros).
+ */
+#if !defined(DUK_FABS)
+#define DUK_FABS             fabs
+#endif
+#if !defined(DUK_FMIN)
+#define DUK_FMIN             fmin
+#endif
+#if !defined(DUK_FMAX)
+#define DUK_FMAX             fmax
+#endif
+#if !defined(DUK_FLOOR)
+#define DUK_FLOOR            floor
+#endif
+#if !defined(DUK_CEIL)
+#define DUK_CEIL             ceil
+#endif
+#if !defined(DUK_FMOD)
+#define DUK_FMOD             fmod
+#endif
+#if !defined(DUK_POW)
+#define DUK_POW              pow
+#endif
+#if !defined(DUK_ACOS)
+#define DUK_ACOS             acos
+#endif
+#if !defined(DUK_ASIN)
+#define DUK_ASIN             asin
+#endif
+#if !defined(DUK_ATAN)
+#define DUK_ATAN             atan
+#endif
+#if !defined(DUK_ATAN2)
+#define DUK_ATAN2            atan2
+#endif
+#if !defined(DUK_SIN)
+#define DUK_SIN              sin
+#endif
+#if !defined(DUK_COS)
+#define DUK_COS              cos
+#endif
+#if !defined(DUK_TAN)
+#define DUK_TAN              tan
+#endif
+#if !defined(DUK_EXP)
+#define DUK_EXP              exp
+#endif
+#if !defined(DUK_LOG)
+#define DUK_LOG              log
+#endif
+#if !defined(DUK_SQRT)
+#define DUK_SQRT             sqrt
+#endif
+
+/* NetBSD 6.0 x86 (at least) has a few problems with pow() semantics,
+ * see test-bug-netbsd-math-pow.js.  Use NetBSD specific workaround.
+ * (This might be a wider problem; if so, generalize the define name.)
+ */
+#undef DUK_USE_POW_NETBSD_WORKAROUND
+#if defined(DUK_F_NETBSD)
+#define DUK_USE_POW_NETBSD_WORKAROUND
+#endif
+
+/* Rely as little as possible on compiler behavior for NaN comparison,
+ * signed zero handling, etc.  Currently never activated but may be needed
+ * for broken compilers.
+ */
+#undef DUK_USE_PARANOID_MATH
+
+/* There was a curious bug where test-bi-date-canceling.js would fail e.g.
+ * on 64-bit Ubuntu, gcc-4.8.1, -m32, and no -std=c99.  Some date computations
+ * using doubles would be optimized which then broke some corner case tests.
+ * The problem goes away by adding 'volatile' to the datetime computations.
+ * Not sure what the actual triggering conditions are, but using this on
+ * non-C99 systems solves the known issues and has relatively little cost
+ * on other platforms.
+ */
+#undef DUK_USE_PARANOID_DATE_COMPUTATION
+#if !defined(DUK_F_C99)
+#define DUK_USE_PARANOID_DATE_COMPUTATION
+#endif
+
+/*
+ *  Byte order and double memory layout detection
+ *
+ *  Endianness detection is a major portability hassle because the macros
+ *  and headers are not standardized.  There's even variance across UNIX
+ *  platforms.  Even with "standard" headers, details like underscore count
+ *  varies between platforms, e.g. both __BYTE_ORDER and _BYTE_ORDER are used
+ *  (Crossbridge has a single underscore, for instance).
+ *
+ *  The checks below are structured with this in mind: several approaches are
+ *  used, and at the end we check if any of them worked.  This allows generic
+ *  approaches to be tried first, and platform/compiler specific hacks tried
+ *  last.  As a last resort, the user can force a specific endianness, as it's
+ *  not likely that automatic detection will work on the most exotic platforms.
+ *
+ *  Duktape supports little and big endian machines.  There's also support
+ *  for a hybrid used by some ARM machines where integers are little endian
+ *  but IEEE double values use a mixed order (12345678 -> 43218765).  This
+ *  byte order for doubles is referred to as "mixed endian".
+ */
+
+/* For custom platforms allow user to define byteorder explicitly.
+ * Since endianness headers are not standardized, this is a useful
+ * workaround for custom platforms for which endianness detection
+ * is not directly supported.  Perhaps custom hardware is used and
+ * user cannot submit upstream patches.
+ */
+#if defined(DUK_OPT_FORCE_BYTEORDER)
+#undef DUK_USE_BYTEORDER
+#if (DUK_OPT_FORCE_BYTEORDER == 1)
+#define DUK_USE_BYTEORDER 1
+#elif (DUK_OPT_FORCE_BYTEORDER == 2)
+#define DUK_USE_BYTEORDER 2
+#elif (DUK_OPT_FORCE_BYTEORDER == 3)
+#define DUK_USE_BYTEORDER 3
+#else
+#error invalid DUK_OPT_FORCE_BYTEORDER value
+#endif
+#endif  /* DUK_OPT_FORCE_BYTEORDER */
+
+/* GCC and Clang provide endianness defines as built-in predefines, with
+ * leading and trailing double underscores (e.g. __BYTE_ORDER__).  See
+ * output of "make gccpredefs" and "make clangpredefs".  Clang doesn't
+ * seem to provide __FLOAT_WORD_ORDER__; assume not mixed endian for clang.
+ * http://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html
+ */
+#if !defined(DUK_USE_BYTEORDER) && defined(__BYTE_ORDER__)
+#if defined(__ORDER_LITTLE_ENDIAN__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
+#if defined(__FLOAT_WORD_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && (__FLOAT_WORD_ORDER__ == __ORDER_LITTLE_ENDIAN__)
+#define DUK_USE_BYTEORDER 1
+#elif defined(__FLOAT_WORD_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && (__FLOAT_WORD_ORDER__ == __ORDER_BIG_ENDIAN__)
+#define DUK_USE_BYTEORDER 2
+#elif !defined(__FLOAT_WORD_ORDER__)
+/* Float word order not known, assume not a hybrid. */
+#define DUK_USE_BYTEORDER 1
+#else
+/* Byte order is little endian but cannot determine IEEE double word order. */
+#endif  /* float word order */
+#elif defined(__ORDER_BIG_ENDIAN__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
+#if defined(__FLOAT_WORD_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && (__FLOAT_WORD_ORDER__ == __ORDER_BIG_ENDIAN__)
+#define DUK_USE_BYTEORDER 3
+#elif !defined(__FLOAT_WORD_ORDER__)
+/* Float word order not known, assume not a hybrid. */
+#define DUK_USE_BYTEORDER 3
+#else
+/* Byte order is big endian but cannot determine IEEE double word order. */
+#endif  /* float word order */
+#else
+/* Cannot determine byte order; __ORDER_PDP_ENDIAN__ is related to 32-bit
+ * integer ordering and is not relevant.
+ */
+#endif  /* integer byte order */
+#endif  /* !defined(DUK_USE_BYTEORDER) && defined(__BYTE_ORDER__) */
+
+/* More or less standard endianness predefines provided by header files.
+ * The ARM hybrid case is detected by assuming that __FLOAT_WORD_ORDER
+ * will be big endian, see: http://lists.mysql.com/internals/443.
+ * On some platforms some defines may be present with an empty value which
+ * causes comparisons to fail: https://github.com/svaarala/duktape/issues/453.
+ */
+#if !defined(DUK_USE_BYTEORDER)
+#if defined(__BYTE_ORDER) && defined(__LITTLE_ENDIAN) && (__BYTE_ORDER == __LITTLE_ENDIAN) || \
+    defined(_BYTE_ORDER) && defined(_LITTLE_ENDIAN) && (_BYTE_ORDER == _LITTLE_ENDIAN) || \
+    defined(__LITTLE_ENDIAN__)
+#if defined(__FLOAT_WORD_ORDER) && defined(__LITTLE_ENDIAN) && (__FLOAT_WORD_ORDER == __LITTLE_ENDIAN) || \
+    defined(_FLOAT_WORD_ORDER) && defined(_LITTLE_ENDIAN) && (_FLOAT_WORD_ORDER == _LITTLE_ENDIAN)
+#define DUK_USE_BYTEORDER 1
+#elif defined(__FLOAT_WORD_ORDER) && defined(__BIG_ENDIAN) && (__FLOAT_WORD_ORDER == __BIG_ENDIAN) || \
+      defined(_FLOAT_WORD_ORDER) && defined(_BIG_ENDIAN) && (_FLOAT_WORD_ORDER == _BIG_ENDIAN)
+#define DUK_USE_BYTEORDER 2
+#elif !defined(__FLOAT_WORD_ORDER) && !defined(_FLOAT_WORD_ORDER)
+/* Float word order not known, assume not a hybrid. */
+#define DUK_USE_BYTEORDER 1
+#else
+/* Byte order is little endian but cannot determine IEEE double word order. */
+#endif  /* float word order */
+#elif defined(__BYTE_ORDER) && defined(__BIG_ENDIAN) && (__BYTE_ORDER == __BIG_ENDIAN) || \
+      defined(_BYTE_ORDER) && defined(_BIG_ENDIAN) && (_BYTE_ORDER == _BIG_ENDIAN) || \
+      defined(__BIG_ENDIAN__)
+#if defined(__FLOAT_WORD_ORDER) && defined(__BIG_ENDIAN) && (__FLOAT_WORD_ORDER == __BIG_ENDIAN) || \
+    defined(_FLOAT_WORD_ORDER) && defined(_BIG_ENDIAN) && (_FLOAT_WORD_ORDER == _BIG_ENDIAN)
+#define DUK_USE_BYTEORDER 3
+#elif !defined(__FLOAT_WORD_ORDER) && !defined(_FLOAT_WORD_ORDER)
+/* Float word order not known, assume not a hybrid. */
+#define DUK_USE_BYTEORDER 3
+#else
+/* Byte order is big endian but cannot determine IEEE double word order. */
+#endif  /* float word order */
+#else
+/* Cannot determine byte order. */
+#endif  /* integer byte order */
+#endif  /* !defined(DUK_USE_BYTEORDER) */
+
+/* QNX gcc cross compiler seems to define e.g. __LITTLEENDIAN__ or __BIGENDIAN__:
+ *  $ /opt/qnx650/host/linux/x86/usr/bin/i486-pc-nto-qnx6.5.0-gcc -dM -E - </dev/null | grep -ni endian
+ *  67:#define __LITTLEENDIAN__ 1
+ *  $ /opt/qnx650/host/linux/x86/usr/bin/mips-unknown-nto-qnx6.5.0-gcc -dM -E - </dev/null | grep -ni endian
+ *  81:#define __BIGENDIAN__ 1
+ *  $ /opt/qnx650/host/linux/x86/usr/bin/arm-unknown-nto-qnx6.5.0-gcc -dM -E - </dev/null | grep -ni endian
+ *  70:#define __LITTLEENDIAN__ 1
+ */
+#if !defined(DUK_USE_BYTEORDER)
+#if defined(__LITTLEENDIAN__)
+#define DUK_USE_BYTEORDER 1
+#elif defined(__BIGENDIAN__)
+#define DUK_USE_BYTEORDER 3
+#endif
+#endif
+
+/*
+ *  Alignment requirement and support for unaligned accesses
+ *
+ *  Assume unaligned accesses are not supported unless specifically allowed
+ *  in the target platform.  Some platforms may support unaligned accesses
+ *  but alignment to 4 or 8 may still be desirable.
+ */
+
+/* If not provided, use safe default for alignment. */
+#if !defined(DUK_USE_ALIGN_BY)
+#define DUK_USE_ALIGN_BY 8
+#endif
+
+/* User forced alignment to 4 or 8. */
+#if defined(DUK_OPT_FORCE_ALIGN)
+#undef DUK_USE_ALIGN_BY
+#if (DUK_OPT_FORCE_ALIGN == 4)
+#define DUK_USE_ALIGN_BY 4
+#elif (DUK_OPT_FORCE_ALIGN == 8)
+#define DUK_USE_ALIGN_BY 8
+#else
+#error invalid DUK_OPT_FORCE_ALIGN value
+#endif
+#endif
+
+/* Compiler specific hackery needed to force struct size to match aligment,
+ * see e.g. duk_hbuffer.h.
+ *
+ * http://stackoverflow.com/questions/11130109/c-struct-size-alignment
+ * http://stackoverflow.com/questions/10951039/specifying-64-bit-alignment
+ */
+#if !(defined(DUK_USE_PACK_MSVC_PRAGMA) || defined(DUK_USE_PACK_GCC_ATTR) || \
+      defined(DUK_USE_PACK_CLANG_ATTR) || defined(DUK_USE_PACK_DUMMY_MEMBER))
+#define DUK_USE_PACK_DUMMY_MEMBER
+#endif
+
+#if !defined(DUK_VA_COPY)
+/* We need va_copy() which is defined in C99 / C++11, so an awkward
+ * replacement is needed for pre-C99 / pre-C++11 environments.  This
+ * will quite likely need portability hacks for some non-C99
+ * environments.
+ */
+#if defined(DUK_F_C99) || defined(DUK_F_CPP11)
+/* C99 / C++11 and above: rely on va_copy() which is required.
+ * Omit parenthesis on macro right side on purpose to minimize differences
+ * to direct use.
+ */
+#define DUK_VA_COPY(dest,src) va_copy(dest,src)
+#else
+/* Pre-C99: va_list type is implementation dependent.  This replacement
+ * assumes it is a plain value so that a simple assignment will work.
+ * This is not the case on all platforms (it may be a single-array element,
+ * for instance).
+ */
+#define DUK_VA_COPY(dest,src) do { (dest) = (src); } while (0)
+#endif
+#endif
+
+#if !defined(DUK_MACRO_STRINGIFY)
+/* Macro hackery to convert e.g. __LINE__ to a string without formatting,
+ * see: http://stackoverflow.com/questions/240353/convert-a-preprocessor-token-to-a-string
+ */
+#define DUK_MACRO_STRINGIFY_HELPER(x)  #x
+#define DUK_MACRO_STRINGIFY(x)  DUK_MACRO_STRINGIFY_HELPER(x)
+#endif
+
+#if !defined(DUK_CAUSE_SEGFAULT)
+/* This is optionally used by panic handling to cause the program to segfault
+ * (instead of e.g. abort()) on panic.  Valgrind will then indicate the C
+ * call stack leading to the panic.
+ */
+#define DUK_CAUSE_SEGFAULT()  do { *((volatile duk_uint32_t *) NULL) = (duk_uint32_t) 0xdeadbeefUL; } while (0)
+#endif
+#if !defined(DUK_UNREF)
+/* Macro for suppressing warnings for potentially unreferenced variables.
+ * The variables can be actually unreferenced or unreferenced in some
+ * specific cases only; for instance, if a variable is only debug printed,
+ * it is unreferenced when debug printing is disabled.
+ */
+#define DUK_UNREF(x)  do { (void) (x); } while (0)
+#endif
+#if !defined(DUK_NORETURN)
+#define DUK_NORETURN(decl)  decl
+#endif
+#if !defined(DUK_UNREACHABLE)
+/* Don't know how to declare unreachable point, so don't do it; this
+ * may cause some spurious compilation warnings (e.g. "variable used
+ * uninitialized").
+ */
+#define DUK_UNREACHABLE()  do { } while (0)
+#endif
+#if !defined(DUK_LOSE_CONST)
+/* Convert any input pointer into a "void *", losing a const qualifier.
+ * This is not fully portable because casting through duk_uintptr_t may
+ * not work on all architectures (e.g. those with long, segmented pointers).
+ */
+#define DUK_LOSE_CONST(src) ((void *) (duk_uintptr_t) (src))
+#endif
+
+#if !defined(DUK_LIKELY)
+#define DUK_LIKELY(x)    (x)
+#endif
+#if !defined(DUK_UNLIKELY)
+#define DUK_UNLIKELY(x)  (x)
+#endif
+
+#if !defined(DUK_NOINLINE)
+#define DUK_NOINLINE       /*nop*/
+#endif
+#if !defined(DUK_INLINE)
+#define DUK_INLINE         /*nop*/
+#endif
+#if !defined(DUK_ALWAYS_INLINE)
+#define DUK_ALWAYS_INLINE  /*nop*/
+#endif
+
+#if !defined(DUK_EXTERNAL_DECL)
+#define DUK_EXTERNAL_DECL  extern
+#endif
+#if !defined(DUK_EXTERNAL)
+#define DUK_EXTERNAL       /*empty*/
+#endif
+#if !defined(DUK_INTERNAL_DECL)
+#if defined(DUK_SINGLE_FILE)
+#define DUK_INTERNAL_DECL  static
+#else
+#define DUK_INTERNAL_DECL  extern
+#endif
+#endif
+#if !defined(DUK_INTERNAL)
+#if defined(DUK_SINGLE_FILE)
+#define DUK_INTERNAL       static
+#else
+#define DUK_INTERNAL       /*empty*/
+#endif
+#endif
+#if !defined(DUK_LOCAL_DECL)
+#define DUK_LOCAL_DECL     static
+#endif
+#if !defined(DUK_LOCAL)
+#define DUK_LOCAL          static
+#endif
+
+#if !defined(DUK_FILE_MACRO)
+#define DUK_FILE_MACRO  __FILE__
+#endif
+#if !defined(DUK_LINE_MACRO)
+#define DUK_LINE_MACRO  __LINE__
+#endif
+#if !defined(DUK_FUNC_MACRO)
+#if defined(DUK_F_C99) || defined(DUK_F_CPP11)
+#define DUK_FUNC_MACRO  __func__
+#elif defined(__FUNCTION__)
+#define DUK_FUNC_MACRO  __FUNCTION__
+#else
+#define DUK_FUNC_MACRO  "unknown"
+#endif
+#endif
+
+#if !defined(DUK_BSWAP32)
+#define DUK_BSWAP32(x) \
+	((((duk_uint32_t) (x)) >> 24) | \
+	 ((((duk_uint32_t) (x)) >> 8) & 0xff00UL) | \
+	 ((((duk_uint32_t) (x)) << 8) & 0xff0000UL) | \
+	 (((duk_uint32_t) (x)) << 24))
+#endif
+#if !defined(DUK_BSWAP16)
+#define DUK_BSWAP16(x) \
+	((duk_uint16_t) (x) >> 8) | \
+	((duk_uint16_t) (x) << 8)
+#endif
+
+/* DUK_USE_VARIADIC_MACROS: required from compilers, so no fill-in. */
+/* DUK_USE_UNION_INITIALIZERS: required from compilers, so no fill-in. */
+
+#if !(defined(DUK_USE_FLEX_C99) || defined(DUK_USE_FLEX_ZEROSIZE) || defined(DUK_USE_FLEX_ONESIZE))
+#if defined(DUK_F_C99)
+#define DUK_USE_FLEX_C99
+#else
+#define DUK_USE_FLEX_ZEROSIZE  /* Not standard but common enough */
+#endif
+#endif
+
+#if !(defined(DUK_USE_PACK_GCC_ATTR) || defined(DUK_USE_PACK_CLANG_ATTR) || \
+      defined(DUK_USE_PACK_MSVC_PRAGMA) || defined(DUK_USE_PACK_DUMMY_MEMBER))
+#define DUK_USE_PACK_DUMMY_MEMBER
+#endif
+
+#if 0  /* not defined by default */
+#undef DUK_USE_GCC_PRAGMAS
+#endif
+
+/* Workaround for GH-323: avoid inlining control when compiling from
+ * multiple sources, as it causes compiler portability trouble.
+ */
+#if !defined(DUK_SINGLE_FILE)
+#undef DUK_NOINLINE
+#undef DUK_INLINE
+#undef DUK_ALWAYS_INLINE
+#define DUK_NOINLINE       /*nop*/
+#define DUK_INLINE         /*nop*/
+#define DUK_ALWAYS_INLINE  /*nop*/
+#endif
+
+/*
+ *  Check whether or not a packed duk_tval representation is possible.
+ *  What's basically required is that pointers are 32-bit values
+ *  (sizeof(void *) == 4).  Best effort check, not always accurate.
+ *  If guess goes wrong, crashes may result; self tests also verify
+ *  the guess.
+ */
+
+/* Explicit marker needed; may be 'defined', 'undefined, 'or 'not provided'. */
+#if !defined(DUK_F_PACKED_TVAL_PROVIDED)
+#undef DUK_F_PACKED_TVAL_POSSIBLE
+
+/* Strict C99 case: DUK_UINTPTR_MAX (= UINTPTR_MAX) should be very reliable */
+#if !defined(DUK_F_PACKED_TVAL_POSSIBLE) && defined(DUK_UINTPTR_MAX)
+#if (DUK_UINTPTR_MAX <= 0xffffffffUL)
+#define DUK_F_PACKED_TVAL_POSSIBLE
+#endif
+#endif
+
+/* Non-C99 case, still relying on DUK_UINTPTR_MAX, as long as it is not a computed value */
+#if !defined(DUK_F_PACKED_TVAL_POSSIBLE) && defined(DUK_UINTPTR_MAX) && !defined(DUK_UINTPTR_MAX_COMPUTED)
+#if (DUK_UINTPTR_MAX <= 0xffffffffUL)
+#define DUK_F_PACKED_TVAL_POSSIBLE
+#endif
+#endif
+
+/* DUK_SIZE_MAX (= SIZE_MAX) is often reliable */
+#if !defined(DUK_F_PACKED_TVAL_POSSIBLE) && defined(DUK_SIZE_MAX) && !defined(DUK_SIZE_MAX_COMPUTED)
+#if (DUK_SIZE_MAX <= 0xffffffffUL)
+#define DUK_F_PACKED_TVAL_POSSIBLE
+#endif
+#endif
+
+#undef DUK_USE_PACKED_TVAL
+#if defined(DUK_F_PACKED_TVAL_POSSIBLE)
+#define DUK_USE_PACKED_TVAL
+#endif
+
+#undef DUK_F_PACKED_TVAL_POSSIBLE
+#endif  /* DUK_F_PACKED_TVAL_PROVIDED */
+
+/* Feature option forcing. */
+#if defined(DUK_OPT_NO_PACKED_TVAL)
+#undef DUK_USE_PACKED_TVAL
+#elif defined(DUK_OPT_PACKED_TVAL)
+#undef DUK_USE_PACKED_TVAL
+#define DUK_USE_PACKED_TVAL
+#endif
+/* Object property allocation layout has implications for memory and code
+ * footprint and generated code size/speed.  The best layout also depends
+ * on whether the platform has alignment requirements or benefits from
+ * having mostly aligned accesses.
+ */
+#undef DUK_USE_HOBJECT_LAYOUT_1
+#undef DUK_USE_HOBJECT_LAYOUT_2
+#undef DUK_USE_HOBJECT_LAYOUT_3
+#if (DUK_USE_ALIGN_BY == 1)
+/* On platforms without any alignment issues, layout 1 is preferable
+ * because it compiles to slightly less code and provides direct access
+ * to property keys.
+ */
+#define DUK_USE_HOBJECT_LAYOUT_1
+#else
+/* On other platforms use layout 2, which requires some padding but
+ * is a bit more natural than layout 3 in ordering the entries.  Layout
+ * 3 is currently not used.
+ */
+#define DUK_USE_HOBJECT_LAYOUT_2
+#endif
+
+/* GCC/clang inaccurate math would break compliance and probably duk_tval,
+ * so refuse to compile.  Relax this if -ffast-math is tested to work.
+ */
+#if defined(__FAST_MATH__)
+#error __FAST_MATH__ defined, refusing to compile
+#endif
+
+/*
+ *  Feature option handling
+ */
+
+#if !defined(DUK_USE_ALIGN_BY)
+#if defined(DUK_OPT_FORCE_ALIGN)
+#define DUK_USE_ALIGN_BY DUK_OPT_FORCE_ALIGN
+#else
+#define DUK_USE_ALIGN_BY 8
+#endif
+#endif
+
+#if defined(DUK_OPT_ASSERTIONS)
+#define DUK_USE_ASSERTIONS
+#elif defined(DUK_OPT_NO_ASSERTIONS)
+#undef DUK_USE_ASSERTIONS
+#else
+#undef DUK_USE_ASSERTIONS
+#endif
+
+#if defined(DUK_OPT_AUGMENT_ERRORS)
+#define DUK_USE_AUGMENT_ERROR_CREATE
+#elif defined(DUK_OPT_NO_AUGMENT_ERRORS)
+#undef DUK_USE_AUGMENT_ERROR_CREATE
+#else
+#define DUK_USE_AUGMENT_ERROR_CREATE
+#endif
+
+#if defined(DUK_OPT_AUGMENT_ERRORS)
+#define DUK_USE_AUGMENT_ERROR_THROW
+#elif defined(DUK_OPT_NO_AUGMENT_ERRORS)
+#undef DUK_USE_AUGMENT_ERROR_THROW
+#else
+#define DUK_USE_AUGMENT_ERROR_THROW
+#endif
+
+#if defined(DUK_OPT_BROWSER_LIKE)
+#define DUK_USE_BROWSER_LIKE
+#elif defined(DUK_OPT_NO_BROWSER_LIKE)
+#undef DUK_USE_BROWSER_LIKE
+#else
+#define DUK_USE_BROWSER_LIKE
+#endif
+
+#if defined(DUK_OPT_BUFFEROBJECT_SUPPORT)
+#define DUK_USE_BUFFEROBJECT_SUPPORT
+#elif defined(DUK_OPT_NO_BUFFEROBJECT_SUPPORT)
+#undef DUK_USE_BUFFEROBJECT_SUPPORT
+#else
+#define DUK_USE_BUFFEROBJECT_SUPPORT
+#endif
+
+#if defined(DUK_OPT_BUFLEN16)
+#define DUK_USE_BUFLEN16
+#elif defined(DUK_OPT_NO_BUFLEN16)
+#undef DUK_USE_BUFLEN16
+#else
+#undef DUK_USE_BUFLEN16
+#endif
+
+#if defined(DUK_OPT_BYTECODE_DUMP_SUPPORT)
+#define DUK_USE_BYTECODE_DUMP_SUPPORT
+#elif defined(DUK_OPT_NO_BYTECODE_DUMP_SUPPORT)
+#undef DUK_USE_BYTECODE_DUMP_SUPPORT
+#else
+#define DUK_USE_BYTECODE_DUMP_SUPPORT
+#endif
+
+#if defined(DUK_OPT_COMMONJS_MODULES)
+#define DUK_USE_COMMONJS_MODULES
+#elif defined(DUK_OPT_NO_CO

<TRUNCATED>

[40/51] [partial] nifi-minifi-cpp git commit: MINIFI-183 Added civet 1.9.1 sources Added onScheduled hook Added initial two-way TLS-enabled ListenHTTP implementation

Posted by al...@apache.org.
http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/mingw.cmd
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/mingw.cmd b/thirdparty/civetweb-1.9.1/mingw.cmd
new file mode 100644
index 0000000..4b26215
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/mingw.cmd
@@ -0,0 +1,884 @@
+:: Make sure the extensions are enabled
+@verify other 2>nul
+@setlocal EnableExtensions EnableDelayedExpansion
+@if errorlevel 1 (
+  @call :print_usage "Failed to enable extensions"
+  @exit /b 1
+)
+
+::Change the code page to unicode
+@chcp 65001 1>nul 2>nul
+@if errorlevel 1 (
+  @call :print_usage "Failed to change the code page to unicode"
+  @exit /b 1
+)
+
+:: Set up some global variables
+@set "script_name=%~nx0"
+@set "script_folder=%~dp0"
+@set "script_folder=%script_folder:~0,-1%"
+@set "dependency_path=%TEMP%\mingw-build-dependencies"
+
+:: Check the command line parameters
+@set logging_level=1
+:options_loop
+@if [%1] == [] goto :options_parsed
+@set "arg=%~1"
+@set one=%arg:~0,1%
+@set two=%arg:~0,2%
+@set three=%arg:~0,3%
+@if /i [%arg%] == [/?] (
+  @call :print_usage "Downloads a specific version of MinGW"
+  @exit /b 0
+)
+@if /i [%arg%] == [/q] set quiet=true
+@if /i [%two%] == [/v] @if /i not [%three%] == [/ve] @call :verbosity "!arg!"
+@if /i [%arg%] == [/version] set "version=%~2" & shift
+@if /i [%arg%] == [/arch] set "arch=%~2" & shift
+@if /i [%arg%] == [/exceptions] set "exceptions=%~2" & shift
+@if /i [%arg%] == [/threading] set "threading=%~2" & shift
+@if /i [%arg%] == [/revision] set "revision=%~2" & shift
+@if /i not [!one!] == [/] (
+  if not defined output_path (
+    set output_path=!arg!
+  ) else (
+    @call :print_usage "Too many output locations: !output_path! !arg!" ^
+                       "There should only be one output location"
+    @exit /b 1
+  )
+)
+@shift
+@goto :options_loop
+:options_parsed
+@if defined quiet set logging_level=0
+@if not defined output_path set "output_path=%script_folder%\mingw-builds"
+@set "output_path=%output_path:/=\%"
+
+:: Set up the logging
+@set "log_folder=%output_path%\logs"
+@call :iso8601 timestamp
+@set "log_path=%log_folder%\%timestamp%.log"
+@set log_keep=10
+
+:: Get default architecture
+@if not defined arch @call :architecture arch
+
+:: Only keep a certain amount of logs
+@set /a "log_keep=log_keep-1"
+@if not exist %log_folder% @mkdir %log_folder%
+@for /f "skip=%log_keep%" %%f in ('dir /b /o-D /tc %log_folder%') do @(
+  @call :log 4 "Removing old log file %log_folder%\%%f"
+  del %log_folder%\%%f
+)
+
+:: Set up some more global variables
+@call :windows_version win_ver win_ver_major win_ver_minor win_ver_rev
+@call :script_source script_source
+@if [%script_source%] == [explorer] (
+  set /a "logging_level=logging_level+1"
+)
+
+:: Execute the main function
+@call :main "%arch%" "%version%" "%threading%" "%exceptions%" "%revision%"
+@if errorlevel 1 (
+  @call :log 0 "Failed to download MinGW"
+  @call :log 0 "View the log at %log_path%"
+  @exit /b 1
+)
+
+:: Stop the script if the user double clicked
+@if [%script_source%] == [explorer] (
+  pause
+)
+
+@endlocal
+@goto :eof
+
+:: -------------------------- Functions start here ----------------------------
+
+:main - Main function that performs the download
+:: %1 - Target architecture
+:: %2 - Version of MinGW to get [optional]
+:: %3 - Threading model [optional]
+:: %4 - Exception model [optional]
+:: %5 - Package revision [optional]
+@setlocal
+@call :log 6
+@call :log 2 "Welcome to the MinGW download script"
+@call :log 6 "------------------------------------"
+@call :log 6
+@call :log 2 "This script downloads a specific version of MinGW"
+@set "arch=%~1"
+@if "%arch%" == "" @exit /b 1
+@set "version=%~2"
+@set "threading=%~3"
+@set "exceptions=%~4"
+@set "revision=%~5"
+@call :log 3 "arch       = %arch%"
+@call :log 3 "version    = %version%"
+@call :log 3 "exceptions = %exceptions%"
+@call :log 3 "threading  = %threading%"
+@call :log 3 "revision   = %revision%"
+@call :repository repo
+@if errorlevel 1 (
+  @call :log 0 "Failed to get the MinGW-builds repository information"
+  @exit /b 1
+)
+@call :resolve slug url "%repo%" "%arch%" "%version%" "%threading%" "%exceptions%" "%revision%"
+@if errorlevel 1 (
+  @call :log 0 "Failed to resolve the correct URL of MinGW"
+  @exit /b 1
+)
+@call :unpack compiler_path "%url%" "%output_path%\mingw\%slug%"
+@if errorlevel 1 (
+  @call :log 0 "Failed to unpack the MinGW archive"
+  @exit /b 1
+)
+@rmdir /s /q "%dependency_path%"
+@echo.%compiler_path%
+@endlocal
+@goto :eof
+
+:repository - Gets the MinGW-builds repository
+:: %1 - The return variable for the repository file path
+@verify other 2>nul
+@setlocal EnableDelayedExpansion
+@if errorlevel 1 (
+  @call :log 0 "Failed to enable extensions"
+  @exit /b 1
+)
+@set "var=%~1"
+@if "%var%" == "" @exit /b 1
+@call :log 7
+@call :log 2 "Getting MinGW repository information"
+@set "url=http://downloads.sourceforge.net/project/mingw-w64/Toolchains targetting Win32/Personal Builds/mingw-builds/installer/repository.txt"
+@call :log 6
+@call :log 1 "Downloading MinGW repository"
+@set "file_path=%dependency_path%\mingw-repository.txt"
+@call :download "%url%" "%file_path%"
+@if errorlevel 1 (
+  @call :log 0 "Failed to download the MinGW repository information"
+  @exit /b 1
+)
+@set "repository_path=%dependency_path%\repository.txt"
+@del "%repository_path%" 2>nul
+@for /f "delims=| tokens=1-6,*" %%a in (%file_path%) do @(
+  @set "version=%%~a"
+  @set "version=!version: =!"
+  @set "arch=%%~b"
+  @set "arch=!arch: =!"
+  @set "threading=%%~c"
+  @set "threading=!threading: =!"
+  @set "exceptions=%%~d"
+  @set "exceptions=!exceptions: =!"
+  @set "revision=%%~e"
+  @set "revision=!revision: =!"
+  @set "revision=!revision:rev=!"
+  @set "url=%%~f"
+  @set "url=!url:%%20= !"
+  @for /l %%a in (1,1,32) do @if "!url:~-1!" == " " set url=!url:~0,-1!
+  @echo !arch!^|!version!^|!threading!^|!exceptions!^|!revision!^|!url!>> "%repository_path%"
+)
+@del "%file_path%" 2>nul
+@endlocal & set "%var%=%repository_path%"
+@goto :eof
+
+:resolve - Gets the MinGW-builds repository
+:: %1 - The return variable for the MinGW slug
+:: %2 - The return variable for the MinGW URL
+:: %3 - The repository information to use
+:: %4 - Target architecture
+:: %5 - Version of MinGW to get [optional]
+:: %6 - Threading model [optional]
+:: %7 - Exception model [optional]
+:: %8 - Package revision [optional]
+@setlocal
+@set "slug_var=%~1"
+@if "%slug_var%" == "" @exit /b 1
+@set "url_var=%~2"
+@if "%url_var%" == "" @exit /b 1
+@set "repository=%~3"
+@if "%repository%" == "" @exit /b 1
+@set "arch=%~4"
+@if "%arch%" == "" @exit /b 1
+@call :resolve_version version "%repository%" "%arch%" "%~5"
+@if errorlevel 1 @exit /b 1
+@call :resolve_threading threading "%repository%" "%arch%" "%version%" "%~6"
+@if errorlevel 1 @exit /b 1
+@call :resolve_exceptions exceptions "%repository%" "%arch%" "%version%" "%threading%" "%~7"
+@if errorlevel 1 @exit /b 1
+@call :resolve_revision revision "%repository%" "%arch%" "%version%" "%threading%" "%exceptions%" "%~8"
+@if errorlevel 1 @exit /b 1
+@call :log 3 "Finding URL"
+@for /f "delims=| tokens=1-6" %%a in (%repository%) do @(
+  @if "%arch%" == "%%a" (
+    @if "%version%" == "%%b" (
+      @if "%threading%" == "%%c" (
+        @if "%exceptions%" == "%%d" (
+          @if "%revision%" == "%%e" (
+            @set "url=%%f"
+) ) ) ) ) )
+@if "%url%" == "" (
+  @call :log 0 "Failed to resolve URL"
+  @exit /b 1
+)
+@set slug=gcc-%version%-%arch%-%threading%-%exceptions%-rev%revision%
+@call :log 2 "Resolved slug: %slug%"
+@call :log 2 "Resolved url: %url%"
+@endlocal & set "%slug_var%=%slug%" & set "%url_var%=%url%"
+@goto :eof
+
+:unpack - Unpacks the MinGW archive
+:: %1 - The return variable name for the compiler path
+:: %2 - The filepath or URL of the archive
+:: %3 - The folder to unpack to
+@verify other 2>nul
+@setlocal EnableDelayedExpansion
+@if errorlevel 1 (
+  @call :log 0 "Failed to enable extensions"
+  @exit /b 1
+)
+@set "var=%~1"
+@if "%var%" == "" @exit /b 1
+@set "archive_path=%~2"
+@if "%archive_path%" == "" @exit /b 1
+@set "folder_path=%~3"
+@if "%folder_path%" == "" @exit /b 1
+@set "compiler_path=%folder_path%\bin"
+@if exist "%compiler_path%" goto :unpack_done
+@call :log 7
+@call :log 2 "Unpacking MinGW archive"
+@set "http=%archive_path:~0,4%"
+@if "%http%" == "http" (
+  @set "url=%archive_path%"
+  @for /f %%a in ("!url: =-!") do @set "file_name=%%~na"
+  @for /f %%a in ("!url: =-!") do @set "file_ext=%%~xa"
+  @set "archive_path=%dependency_path%\!file_name!!file_ext!"
+  @if not exist "!archive_path!" (
+    @call :log 6
+    @call :log 1 "Downloading MinGW archive"
+    @call :download "!url!" "!archive_path!"
+    @if errorlevel 1 (
+      @del "!archive_path!" 2>nul
+      @call :log 0 "Failed to download: !file_name!!file_ext!"
+      @exit /b 1
+    )
+  )
+)
+@if not exist "%archive_path%" (
+  @call :log 0 "The archive did not exist to unpack: %archive_path%"
+  @exit /b 1
+)
+@for /f %%a in ("%archive_path: =-%") do @set "file_name=%%~na"
+@for /f %%a in ("%archive_path: =-%") do @set "file_ext=%%~xa"
+@call :log 6
+@call :log 1 "Unpacking MinGW %file_name%%file_ext%"
+@call :find_sevenzip sevenzip_executable
+@if errorlevel 1 (
+  @call :log 0 "Need 7zip to unpack the MinGW archive"
+  @exit /b 1
+)
+@call :iso8601 iso8601
+@for /f %%a in ("%folder_path%") do @set "tmp_path=%%~dpatmp-%iso8601%"
+@"%sevenzip_executable%" x -y "-o%tmp_path%" "%archive_path%" > nul
+@if errorlevel 1 (
+  @rmdir /s /q "%folder_path%"
+  @call :log 0 "Failed to unpack the MinGW archive"
+  @exit /b 1
+)
+@set "expected_path=%tmp_path%\mingw64"
+@if not exist "%expected_path%" (
+  @set "expected_path=%tmp_path%\mingw32"
+)
+@move /y "%expected_path%" "%folder_path%" > nul
+@if errorlevel 1 (
+  @rmdir /s /q "%tmp_path%" 2>nul
+  @call :log 0 "Failed to move MinGW folder"
+  @call :log 0 "%expected_path%"
+  @call :log 0 "%folder_path%"
+  @exit /b 1
+)
+@rmdir /s /q %tmp_path%
+@set "compiler_path=%folder_path%\bin"
+:unpack_done
+@if not exist "%compiler_path%\gcc.exe" (
+  @call :log 0 "Failed to find gcc: %compiler_path%"
+  @exit /b 1
+)
+@endlocal & set "%var%=%compiler_path%"
+@goto :eof
+
+:find_sevenzip - Finds (or downloads) the 7zip executable
+:: %1 - The return variable for the 7zip executable path
+@setlocal
+@set "var=%~1"
+@if "%var%" == "" @exit /b 1
+@call :log 2 "Finding 7zip"
+@call :find_in_path sevenzip_executable 7z.exe
+@if not errorlevel 1 goto :find_sevenzip_done
+@call :find_in_path sevenzip_executable 7za.exe
+@if not errorlevel 1 goto :find_sevenzip_done
+@set checksum=2FAC454A90AE96021F4FFC607D4C00F8
+@set "url=http://7-zip.org/a/7za920.zip"
+@for /f %%a in ("%url: =-%") do @set "file_name=%%~na"
+@for /f %%a in ("%url: =-%") do @set "file_ext=%%~xa"
+@set "archive_path=%dependency_path%\%file_name%%file_ext%"
+@if not exist "%archive_path%" (
+  @call :log 6
+  @call :log 1 "Downloading 7zip archive"
+  @call :download "%url%" "%archive_path%" %checksum%
+  @if errorlevel 1 (
+    @del "%archive_path%" 2>nul
+    @call :log 0 "Failed to download: %file_name%%file_ext%"
+    @exit /b 1
+  )
+)
+@set "sevenzip_path=%dependency_path%\sevenzip"
+@if not exist "%sevenzip_path%" (
+  @call :unzip "%archive_path%" "%sevenzip_path%"
+  @if errorlevel 1 (
+    @call :log 0 "Failed to unzip the7zip archive"
+    @exit /b 1
+  )
+)
+@set "sevenzip_executable=%sevenzip_path%\7za.exe"
+@if not exist "%sevenzip_executable%" (
+  @call :log 0 "Failed to find unpacked 7zip: %sevenzip_executable%"
+  @exit /b 1
+)
+:find_sevenzip_done
+@call :log 2 "Found 7zip: %sevenzip_executable%"
+@endlocal & set "%var%=%sevenzip_executable%"
+@goto :eof
+
+:unzip - Unzips a .zip archive
+:: %1 - The archive to unzip
+:: %2 - The location to unzip to
+@setlocal
+@set "archive_path=%~1"
+@if "%archive_path%" == "" @exit /b 1
+@set "folder_path=%~2"
+@if "%folder_path%" == "" @exit /b 1
+@for /f %%a in ("%archive_path: =-%") do @set "file_name=%%~na"
+@for /f %%a in ("%archive_path: =-%") do @set "file_ext=%%~xa"
+@call :log 2 "Unzipping: %file_name%%file_ext%"
+@call :iso8601 iso8601
+@set "log_path=%temp%\unzip-%iso8601%-%file_name%.log"
+@powershell ^
+  Add-Type -assembly "system.io.compression.filesystem"; ^
+  [io.compression.zipfile]::ExtractToDirectory(^
+    '%archive_path%', '%folder_path%') 2>"%log_path%"
+@if errorlevel 1 (
+  @call :log 0 "Failed to unzip: %file_name%%file_ext%"
+  @call :log_append "%log_path%"
+  @exit /b 1
+)
+@endlocal
+@goto :eof
+
+:resolve_version - Gets the version of the MinGW compiler
+:: %1 - The return variable for the version
+:: %2 - The repository information to use
+:: %3 - The architecture of the compiler
+:: %4 - Version of MinGW to get [optional]
+@verify other 2>nul
+@setlocal EnableDelayedExpansion
+@if errorlevel 1 (
+  @call :log 0 "Failed to enable extensions"
+  @exit /b 1
+)
+@set "var=%~1"
+@if "%var%" == "" @exit /b 1
+@set "repository=%~2"
+@if "%repository%" == "" @exit /b 1
+@set "arch=%~3"
+@if "%arch%" == "" @exit /b 1
+@set "version=%~4"
+@if not "%version%" == "" goto :resolve_version_done
+:: Find the latest version
+@call :log 3 "Finding latest version"
+@set version=0.0.0
+@for /f "delims=| tokens=1-6" %%a in (%repository%) do @(
+  @if "%arch%" == "%%a" (
+    @call :version_compare result "%version%" "%%b"
+    @if errorlevel 1 (
+      @call :log 0 "Failed to compare versions: %version% %%a"
+      @exit /b 1
+    )
+    @if !result! lss 0 set version=%%b
+  )
+)
+:resolve_version_done
+@if "%version%" == "" (
+  @call :log 0 "Failed to resolve latest version number"
+  @exit /b 1
+)
+@call :log 2 "Resolved version: %version%"
+@endlocal & set "%var%=%version%"
+@goto :eof
+
+:resolve_threading - Gets the threading model of the MinGW compiler
+:: %1 - The return variable for the threading model
+:: %2 - The repository information to use
+:: %3 - The architecture of the compiler
+:: %4 - The version of the compiler
+:: %5 - threading model of MinGW to use [optional]
+@verify other 2>nul
+@setlocal EnableDelayedExpansion
+@if errorlevel 1 (
+  @call :log 0 "Failed to enable extensions"
+  @exit /b 1
+)
+@set "var=%~1"
+@if "%var%" == "" @exit /b 1
+@set "repository=%~2"
+@if "%repository%" == "" @exit /b 1
+@set "arch=%~3"
+@if "%arch%" == "" @exit /b 1
+@set "version=%~4"
+@if "%version%" == "" @exit /b 1
+@set "threading=%~5"
+@if not "%threading%" == "" goto :resolve_threading_done
+@call :log 3 "Finding best threading model"
+@for /f "delims=| tokens=1-6" %%a in (%repository%) do @(
+  @if "%arch%" == "%%a" (
+    @if "%version%" == "%%b" (
+      @if not defined threading (
+        @set "threading=%%c"
+      )
+      @if "%%c" == "posix" (
+        @set "threading=%%c"
+) ) ) )
+:resolve_threading_done
+@if "%threading%" == "" (
+  @call :log 0 "Failed to resolve the best threading model"
+  @exit /b 1
+)
+@call :log 2 "Resolved threading model: %threading%"
+@endlocal & set "%var%=%threading%"
+@goto :eof
+
+:resolve_exceptions - Gets the exception model of the MinGW compiler
+:: %1 - The return variable for the exception model
+:: %2 - The repository information to use
+:: %3 - The architecture of the compiler
+:: %4 - The version of the compiler
+:: %4 - The threading model of the compiler
+:: %5 - exception model of MinGW to use [optional]
+@verify other 2>nul
+@setlocal EnableDelayedExpansion
+@if errorlevel 1 (
+  @call :log 0 "Failed to enable extensions"
+  @exit /b 1
+)
+@set "var=%~1"
+@if "%var%" == "" @exit /b 1
+@set "repository=%~2"
+@if "%repository%" == "" @exit /b 1
+@set "arch=%~3"
+@if "%arch%" == "" @exit /b 1
+@set "version=%~4"
+@if "%version%" == "" @exit /b 1
+@set "threading=%~5"
+@if "%threading%" == "" @exit /b 1
+@set "exceptions=%~6"
+@if not "%exceptions%" == "" goto :resolve_exceptions_done
+@call :log 3 "Finding best exception model"
+@for /f "delims=| tokens=1-6" %%a in (%repository%) do @(
+  @if "%arch%" == "%%a" (
+    @if "%version%" == "%%b" (
+      @if "%threading%" == "%%c" (
+        @if not defined exceptions (
+          @set "exceptions=%%d"
+        )
+        @if "%%d" == "dwarf" (
+          @set "exceptions=%%d"
+        )
+        @if "%%d" == "seh" (
+          @set "exceptions=%%d"
+) ) ) ) )
+:resolve_exceptions_done
+@if "%exceptions%" == "" (
+  @call :log 0 "Failed to resolve the best exception model"
+  @exit /b 1
+)
+@call :log 2 "Resolved exception model: %exceptions%"
+@endlocal & set "%var%=%exceptions%"
+@goto :eof
+
+:resolve_revision - Gets the revision of the MinGW compiler
+:: %1 - The return variable for the revision
+:: %2 - The repository information to use
+:: %3 - The architecture of the compiler
+:: %4 - The version of the compiler
+:: %4 - The threading model of the compiler
+:: %4 - The exception model of the compiler
+:: %5 - revision of the MinGW package to use [optional]
+@verify other 2>nul
+@setlocal EnableDelayedExpansion
+@if errorlevel 1 (
+  @call :log 0 "Failed to enable extensions"
+  @exit /b 1
+)
+@set "var=%~1"
+@if "%var%" == "" @exit /b 1
+@set "repository=%~2"
+@if "%repository%" == "" @exit /b 1
+@set "arch=%~3"
+@if "%arch%" == "" @exit /b 1
+@set "version=%~4"
+@if "%version%" == "" @exit /b 1
+@set "threading=%~5"
+@if "%threading%" == "" @exit /b 1
+@set "exceptions=%~6"
+@if "%exceptions%" == "" @exit /b 1
+@set "revision=%~7"
+@if not "%revision%" == "" goto :resolve_revision_done
+@call :log 3 "Finding latest revision"
+@for /f "delims=| tokens=1-6" %%a in (%repository%) do @(
+  @if "%arch%" == "%%a" (
+    @if "%version%" == "%%b" (
+      @if "%threading%" == "%%c" (
+        @if "%exceptions%" == "%%d" (
+          @if "%%e" gtr "%revision%" (
+            @set "revision=%%e"
+) ) ) ) ) )
+:resolve_revision_done
+@if "%revision%" == "" (
+  @call :log 0 "Failed to resolve latest revision"
+  @exit /b 1
+)
+@call :log 2 "Resolved revision: %revision%"
+@endlocal & set "%var%=%revision%"
+@goto :eof
+
+:version_compare - Compares two semantic version numbers
+:: %1 - The return variable:
+::        - < 0 : if %2 < %3
+::        -   0 : if %2 == %3
+::        - > 0 : if %2 > %3
+:: %2 - The first version to compare
+:: %3 - The second version to compare
+@setlocal
+@set "var=%~1"
+@if "%var%" == "" @exit /b 1
+@set "lhs=%~2"
+@if "%lhs%" == "" @exit /b 1
+@set "rhs=%~3"
+@if "%lhs%" == "" @exit /b 1
+@set result=0
+@for /f "delims=. tokens=1-6" %%a in ("%lhs%.%rhs%") do @(
+  @if %%a lss %%d (
+    set result=-1
+    goto :version_compare_done
+  ) else (
+    @if %%a gtr %%d (
+      set result=1
+      goto :version_compare_done
+    ) else (
+      @if %%b lss %%e (
+        set result=-1
+        goto :version_compare_done
+      ) else (
+        @if %%b gtr %%e (
+          set result=1
+          goto :version_compare_done
+        ) else (
+          @if %%c lss %%f (
+            set result=-1
+            goto :version_compare_done
+          ) else (
+            @if %%c gtr %%f (
+              set result=1
+              goto :version_compare_done
+            )
+          )
+        )
+      )
+    )
+  )
+)
+:version_compare_done
+@endlocal & set "%var%=%result%"
+@goto :eof
+
+:print_usage - Prints the usage of the script
+:: %* - message to print, each argument on it's own line
+@setlocal
+@for %%a in (%*) do @echo.%%~a
+@echo.
+@echo.build [/?][/v[v...]^|/q][/version][/arch a][/threading t]
+@echo.      [/exceptions e][/revision r] location
+@echo.
+@echo.  /version v  The version of MinGW to download
+@echo.  /arch a     The target architecture [i686^|x86_64]
+@echo.  /threading t
+@echo.              Threading model to use [posix^|win32]
+@echo.  /exceptions e
+@echo.              Exception model to use [sjlj^|seh^|dwarf]
+@echo.  /revision e Revision of the release to use
+@echo.  /v          Sets the output to be more verbose
+@echo.  /v[v...]    Extra verbosity, /vv, /vvv, etc
+@echo.  /q          Quiets the output
+@echo.  /?          Shows this usage message
+@echo.
+@endlocal
+@goto :eof
+
+:script_source - Determines if the script was ran from the cli or explorer
+:: %1 - The return variable [cli|explorer]
+@verify other 2>nul
+@setlocal EnableDelayedExpansion
+@if errorlevel 1 (
+  @call :log 0 "Failed to enable extensions"
+  @exit /b 1
+)
+@call :log 3 "Attempting to detect the script source"
+@echo "The invocation command was: '%cmdcmdline%'" >> %log_path%
+@for /f "tokens=1-3,*" %%a in ("%cmdcmdline%") do @(
+  set cmd=%%~a
+  set arg1=%%~b
+  set arg2=%%~c
+  set rest=%%~d
+)
+@set quote="
+@if "!arg2:~0,1!" equ "!quote!" (
+  if "!arg2:~-1!" neq "!quote!" (
+    set "arg2=!arg2:~1!"
+  )
+)
+@call :log 4 "cmd  = %cmd%"
+@call :log 4 "arg1 = %arg1%"
+@call :log 4 "arg2 = %arg2%"
+@call :log 4 "rest = %rest%"
+@call :log 4 "src  = %~f0"
+@if /i "%arg2%" == "call" (
+  set script_source=cli
+) else (
+  @if /i "%arg1%" == "/c" (
+    set script_source=explorer
+  ) else (
+    set script_source=cli
+  )
+)
+@call :log 3 "The script was invoked from %script_source%"
+@endlocal & set "%~1=%script_source%"
+@goto :eof
+
+:architecture - Finds the system architecture
+:: %1 - The return variable [i686|x86_64]
+@setlocal
+@call :log 3 "Determining the processor architecture"
+@set "key=HKLM\System\CurrentControlSet\Control\Session Manager\Environment"
+@set "var=PROCESSOR_ARCHITECTURE"
+@for /f "skip=2 tokens=2,*" %%a in ('reg query "%key%" /v "%var%"') do @set "arch=%%b"
+@if "%arch%" == "AMD64" set arch=x86_64
+@if "%arch%" == "x64" set arch=i686
+@call :log 4 "arch = %arch%"
+@endlocal & set "%~1=%arch%"
+@goto :eof
+
+:md5 - Gets the MD5 checksum for a file
+:: %1 - The hash
+:: %2 - The file path
+@setlocal
+@set "var=%~1"
+@set "file_path=%~2"
+@if "%var%" == "" @exit /b 1
+@if "%file_path%" == "" @exit /b 1
+@if not exist "%file_path%" @exit /b 1
+@for /f "skip=3 tokens=1,*" %%a in ('powershell Get-FileHash -Algorithm MD5 "'%file_path%'"') do @set hash=%%b
+@if not defined hash (
+  @call :log 6
+  @call :log 0 "Failed to get MD5 hash for %file_path%"
+  @exit /b 1
+)
+@endlocal & set "%var%=%hash: =%"
+@goto :eof
+
+:windows_version - Checks the windows version
+:: %1 - The windows version
+:: %2 - The major version number return variable
+:: %3 - The minor version number return variable
+:: %4 - The revision version number return variable
+@setlocal
+@call :log 3 "Retrieving the Windows version"
+@for /f "tokens=2 delims=[]" %%x in ('ver') do @set win_ver=%%x
+@set win_ver=%win_ver:Version =%
+@set win_ver_major=%win_ver:~0,1%
+@set win_ver_minor=%win_ver:~2,1%
+@set win_ver_rev=%win_ver:~4%
+@call :log 4 "win_ver = %win_ver%"
+@endlocal & set "%~1=%win_ver%" ^
+          & set "%~2=%win_ver_major%" ^
+          & set "%~3=%win_ver_minor%" ^
+          & set "%~4=%win_ver_rev%"
+@goto :eof
+
+:find_in_path - Finds a program of file in the PATH
+:: %1 - return variable of the file path
+@setlocal
+@set "var=%~1"
+@if "%var%" == "" @exit /b 1
+@set "file=%~2"
+@if "%file%" == "" @exit /b 1
+@call :log 3 "Searching PATH for %file%"
+@for %%x in ("%file%") do @set "file_path=%%~f$PATH:x"
+@if not defined file_path @exit /b 1
+@endlocal & set "%var%=%file_path%"
+@goto :eof
+
+:log_append - Appends another file into the current logging file
+:: %1 - the file_path to the file to concatenate
+@setlocal
+@set "file_path=%~1"
+@if "%file_path%" == "" @exit /b 1
+@call :log 3 "Appending to log: %file_path%"
+@call :iso8601 iso8601
+@set temp_log=%temp%\append-%iso8601%.log
+@call :log 4 "Using temp file %temp_log%"
+@type "%log_path%" "%file_path%" > "%temp_log%" 2>nul
+@move /y "%temp_log%" "%log_path%" 1>nul
+@del "%file_path% 2>nul
+@del "%temp_log% 2>nul
+@endlocal
+@goto :eof
+
+:iso8601 - Returns the current time in ISO8601 format
+:: %1 - the return variable
+:: %2 - format [extended|basic*]
+:: iso8601 - contains the resulting timestamp
+@setlocal
+@wmic Alias /? >NUL 2>&1 || @exit /b 1
+@set "var=%~1"
+@if "%var%" == "" @exit /b 1
+@set "format=%~2"
+@if "%format%" == "" set format=basic
+@for /F "skip=1 tokens=1-6" %%g IN ('wmic Path Win32_UTCTime Get Day^,Hour^,Minute^,Month^,Second^,Year /Format:table') do @(
+  @if "%%~l"=="" goto :iso8601_done
+  @set "yyyy=%%l"
+  @set "mm=00%%j"
+  @set "dd=00%%g"
+  @set "hour=00%%h"
+  @set "minute=00%%i"
+  @set "seconds=00%%k"
+)
+:iso8601_done
+@set mm=%mm:~-2%
+@set dd=%dd:~-2%
+@set hour=%hour:~-2%
+@set minute=%minute:~-2%
+@set seconds=%seconds:~-2%
+@if /i [%format%] == [extended] (
+  set iso8601=%yyyy%-%mm%-%dd%T%hour%:%minute%:%seconds%Z
+) else (
+  if /i [%format%] == [basic] (
+    set iso8601=%yyyy%%mm%%dd%T%hour%%minute%%seconds%Z
+  ) else (
+    @exit /b 1
+  )
+)
+@set iso8601=%iso8601: =0%
+@endlocal & set %var%=%iso8601%
+@goto :eof
+
+:verbosity - Processes the verbosity parameter '/v[v...]
+:: %1 - verbosity given on the command line
+:: logging_level - set to the number of v's
+@setlocal
+@set logging_level=0
+@set verbosity=%~1
+:verbosity_loop
+@set verbosity=%verbosity:~1%
+@if not [%verbosity%] == [] @(
+  set /a "logging_level=logging_level+1"
+  goto verbosity_loop
+)
+@endlocal & set logging_level=%logging_level%
+@goto :eof
+
+:log - Logs a message, depending on verbosity
+:: %1 - level
+::       [0-4] for CLI logging
+::       [5-9] for GUI logging
+:: %2 - message to print
+@setlocal
+@set "level=%~1"
+@set "msg=%~2"
+@if "%log_folder%" == "" (
+  echo Logging was used to early in the script, log_folder isn't set yet
+  goto :eof
+)
+@if "%log_path%" == "" (
+  echo Logging was used to early in the script, log_path isn't set yet
+  goto :eof
+)
+@if not exist "%log_folder%" mkdir "%log_folder%"
+@if not exist "%log_path%" echo. 1>nul 2>"%log_path%"
+@echo.%msg% >> "%log_path%"
+@if %level% geq 5 (
+  @if [%script_source%] == [explorer] (
+    set /a "level=level-5"
+  ) else (
+    @goto :eof
+  )
+)
+@if "%logging_level%" == "" (
+  echo Logging was used to early in the script, logging_level isn't set yet
+  goto :eof
+)
+@if %logging_level% geq %level% echo.%msg% 1>&2
+@endlocal
+@goto :eof
+
+:download - Downloads a file from the internet
+:: %1 - the url of the file to download
+:: %2 - the file to download to
+:: %3 - the MD5 checksum of the file (optional)
+@setlocal EnableDelayedExpansion
+@if errorlevel 1 (
+  @call :print_usage "Failed to enable extensions"
+  @exit /b 1
+)
+@set "url=%~1"
+@set "file_path=%~2"
+@set "checksum=%~3"
+@for %%a in (%file_path%) do @set dir_path=%%~dpa
+@for %%a in (%file_path%) do @set file_name=%%~nxa
+@if "%url%" == "" @exit /b 1
+@if "%file_path%" == "" @exit /b 1
+@if "%dir_path%" == "" @exit /b 1
+@if "%file_name%" == "" @exit /b 1
+@if not exist "%dir_path%" mkdir "%dir_path%"
+@call :log 2 "Downloading %url%"
+@call :iso8601 iso8601
+@set "temp_path=%temp%\download-%iso8601%-%file_name%"
+@set "log_path=%temp%\download-%iso8601%-log-%file_name%"
+@call :log 4 "Using temp file %temp_path%"
+@powershell Invoke-WebRequest "'%url%'" ^
+  -OutFile "'%temp_path%'" ^
+  -UserAgent [Microsoft.PowerShell.Commands.PSUserAgent]::IE ^
+  1>nul 2>"%log_path%"
+@if errorlevel 1 (
+  @call :log 0 "Failed to download %url%"
+  @call :log_append "%log_path%"
+  @exit /b 1
+)
+@if [%checksum%] neq [] (
+  @call :log 4 "Checking %checksum% against %temp_path%"
+  @call :md5 hash "%temp_path%"
+  if "!hash!" neq "%checksum%" (
+    @call :log 0 "Failed to match checksum: %temp_path%"
+    @call :log 0 "Hash    : !hash!"
+    @call :log 0 "Checksum: %checksum%"
+    @exit /b 1
+  ) else (
+    @call :log 3 "Checksum matched: %temp_path%"
+    @call :log 3 "Hash    : !hash!"
+    @call :log 3 "Checksum: %checksum%"
+  )
+)
+@call :log 4 "Renaming %temp_path% to %file_path%"
+@move /y "%temp_path%" "%file_path%" 1>nul
+@endlocal
+@goto :eof

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/resources/Info.plist
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/resources/Info.plist b/thirdparty/civetweb-1.9.1/resources/Info.plist
new file mode 100644
index 0000000..f02e19a
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/resources/Info.plist
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+  <key>CFBundleExecutable</key> <string>Civetweb</string>
+  <key>CFBundlePackageType</key> <string>APPL</string>
+  <key>CFBundleTypeRole</key> <string>None</string>
+  <key>CFBundleIconFile</key> <string>civetweb</string>
+  <key>CFBundleIconFiles</key> <array>
+    <string>civetweb_16x16.png</string>
+    <string>civetweb_22x22.png</string>
+    <string>civetweb_32x32.png</string>
+    <string>civetweb_64x64.png</string>
+  </array>
+  <key>LSUIElement</key> <true/>
+  <key>RunAtLoad</key> <true/>
+  <key>Label</key> <string>com.nofacepress.civetweb</string>
+  <key>ProgramArguments</key> <array> </array>
+  <key>KeepAlive</key> <true/>
+</dict>
+</plist>

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/resources/Makefile.in-duktape
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/resources/Makefile.in-duktape b/thirdparty/civetweb-1.9.1/resources/Makefile.in-duktape
new file mode 100644
index 0000000..869e21b
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/resources/Makefile.in-duktape
@@ -0,0 +1,60 @@
+#
+# Copyright (c) 2015-2017 the Civetweb developers
+#
+# License http://opensource.org/licenses/mit-license.php MIT License
+#
+
+ifndef WITH_DUKTAPE
+  $(error WITH_DUKTAPE is not defined)
+endif
+
+# Duktape default version is 1.5.2 (105)
+WITH_DUKTAPE_VERSION ?= 105
+DUKTAPE_VERSION_KNOWN = 0
+
+# Select src and header according to the Duktape version
+ifeq ($(WITH_DUKTAPE_VERSION), 105)
+  $(info Duktape: Using version 1.5.2)
+  DUKTAPE_DIR = src/third_party/duktape-1.5.2/src
+  DUKTAPE_SHARED_LIB_FLAG = -lduktape1.5
+  DUKTAPE_CFLAGS = -DDUKTAPE_VERSION_MAKEFILE=105
+  DUKTAPE_VERSION_KNOWN = 1
+endif
+
+ifneq ($(DUKTAPE_VERSION_KNOWN), 1)
+  $(error Duktape: Unknwon version - $(WITH_DUKTAPE_VERSION))
+endif
+
+
+# Add flags for all Duktape versions
+DUKTAPE_CFLAGS += -I$(DUKTAPE_DIR) -DUSE_DUKTAPE
+
+ifneq ($(TARGET_OS),WIN32)
+#  DUKTAPE_CFLAGS += 
+endif
+
+ifdef WITH_DUKTAPE_SHARED
+
+  DUKTAPE_SOURCE_FILES =
+
+  $(info Duktape: using dynamic linking)
+
+else
+
+  DUKTAPE_SOURCE_FILES = duktape.c
+
+ifeq ($(WITH_DUKTAPE_VERSION), 104)
+#    DUKTAPE_SOURCE_FILES += ... TODO ...
+endif
+
+  $(info Duktape: using static library)
+
+endif
+
+DUKTAPE_SOURCES = $(addprefix $(DUKTAPE_DIR)/, $(DUKTAPE_SOURCE_FILES))
+DUKTAPE_OBJECTS = $(DUKTAPE_SOURCES:.c=.o)
+
+OBJECTS += $(DUKTAPE_OBJECTS)
+CFLAGS += $(DUKTAPE_CFLAGS)
+SOURCE_DIRS = $(DUKTAPE_DIR)
+

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/resources/Makefile.in-lua
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/resources/Makefile.in-lua b/thirdparty/civetweb-1.9.1/resources/Makefile.in-lua
new file mode 100644
index 0000000..630b580
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/resources/Makefile.in-lua
@@ -0,0 +1,148 @@
+#
+# Copyright (c) 2013 No Face Press, LLC
+# Copyright (c) 2014-2017 the Civetweb developers
+#
+# License http://opensource.org/licenses/mit-license.php MIT License
+#
+
+ifndef WITH_LUA
+  $(error WITH_LUA is not defined)
+endif
+
+# Lua Default version is 502
+WITH_LUA_VERSION ?= 502
+LUA_VERSION_KNOWN = 0
+
+# Select src and header according to the Lua version
+ifeq ($(WITH_LUA_VERSION), 501)
+  $(info Lua: Using version 5.1.5)
+  LUA_DIR = src/third_party/lua-5.1.5/src
+  LUA_SHARED_LIB_FLAG = -llua5.1
+  LUA_CFLAGS = -DLUA_VERSION_MAKEFILE=501
+  LUA_VERSION_KNOWN = 1
+endif
+ifeq ($(WITH_LUA_VERSION), 502)
+  $(info Lua: Using version 5.2.4)
+  LUA_DIR = src/third_party/lua-5.2.4/src
+  LUA_SHARED_LIB_FLAG = -llua5.2
+  LUA_CFLAGS = -DLUA_VERSION_MAKEFILE=502
+  LUA_VERSION_KNOWN = 1
+endif
+ifeq ($(WITH_LUA_VERSION), 503)
+  $(info Lua: Using version 5.3.3)
+  LUA_DIR = src/third_party/lua-5.3.3/src
+  LUA_SHARED_LIB_FLAG = -llua5.3
+  LUA_CFLAGS = -DLUA_COMPAT_5_2 -DLUA_VERSION_MAKEFILE=503
+  LUA_VERSION_KNOWN = 1
+endif
+
+ifneq ($(LUA_VERSION_KNOWN), 1)
+  $(error Lua: Unknwon version - $(WITH_LUA_VERSION))
+endif
+
+
+# Add flags for all Lua versions
+LUA_CFLAGS += -I$(LUA_DIR) -DLUA_COMPAT_ALL -DUSE_LUA
+
+ifneq ($(TARGET_OS),WIN32)
+  LUA_CFLAGS += -DLUA_USE_POSIX -DLUA_USE_DLOPEN
+endif
+
+ifdef WITH_LUA_SHARED
+
+  LUA_SOURCE_FILES =
+
+  $(info Lua: using dynamic linking)
+
+else
+
+  LUA_SOURCE_FILES = lapi.c  \
+    lauxlib.c \
+    lbaselib.c  \
+    lcode.c  \
+    ldblib.c  \
+    ldebug.c  \
+    ldo.c  \
+    ldump.c \
+    lfunc.c  \
+    lgc.c  \
+    linit.c \
+    liolib.c  \
+    llex.c \
+    lmathlib.c \
+    lmem.c  \
+    loadlib.c  \
+    lobject.c  \
+    lopcodes.c \
+    loslib.c  \
+    lparser.c  \
+    lstate.c  \
+    lstring.c \
+    lstrlib.c  \
+    ltable.c  \
+    ltablib.c \
+    ltm.c  \
+    lundump.c \
+    lvm.c  \
+    lzio.c
+
+ifeq ($(WITH_LUA_VERSION), 502)
+    LUA_SOURCE_FILES += lbitlib.c  \
+    lcorolib.c  \
+    lctype.c
+endif
+ifeq ($(WITH_LUA_VERSION), 503)
+    LUA_SOURCE_FILES += lbitlib.c  \
+    lcorolib.c  \
+    lctype.c  \
+    lutf8lib.c
+endif
+
+  $(info Lua: using static library)
+
+endif
+
+LUA_SOURCES = $(addprefix $(LUA_DIR)/, $(LUA_SOURCE_FILES))
+LUA_OBJECTS = $(LUA_SOURCES:.c=.o)
+
+OBJECTS += $(LUA_OBJECTS)
+CFLAGS += $(LUA_CFLAGS)
+SOURCE_DIRS = $(LUA_DIR)
+
+
+ifneq ($(WITH_LUA_VERSION), 501)
+  SQLITE_DIR = src/third_party
+  SQLITE_SOURCE_FILES = sqlite3.c lsqlite3.c
+  SQLITE_SOURCES = $(addprefix $(SQLITE_DIR)/, $(SQLITE_SOURCE_FILES))
+  SQLITE_OBJECTS = $(SQLITE_SOURCES:.c=.o)
+  SQLITE_CFLAGS = -I$(SQLITE_DIR) -DTHREADSAFE=1 -DSQLITE_ENABLE_FTS3 -DSQLITE_ENABLE_FTS3_PARENTHESIS
+  OBJECTS += $(SQLITE_OBJECTS)
+  CFLAGS += $(SQLITE_CFLAGS)
+  CFLAGS += -DUSE_LUA_SQLITE3
+  #SOURCE_DIRS = $(SQLITE_DIR)
+endif
+
+
+LFS_DIR = src/third_party
+LFS_SOURCE_FILES = lfs.c
+LFS_SOURCES = $(addprefix $(LFS_DIR)/, $(LFS_SOURCE_FILES))
+LFS_OBJECTS = $(LFS_SOURCES:.c=.o)
+LFS_CFLAGS = -I$(LFS_DIR)
+OBJECTS += $(LFS_OBJECTS)
+CFLAGS += $(LFS_CFLAGS)
+CFLAGS += -DUSE_LUA_FILE_SYSTEM
+#SOURCE_DIRS = $(LFS_DIR)
+
+
+ifneq ($(WITH_LUA_VERSION), 501)
+  LXML_DIR = src/third_party
+  LXML_SOURCE_FILES = LuaXML_lib.c
+  LXML_SOURCES = $(addprefix $(LXML_DIR)/, $(LXML_SOURCE_FILES))
+  LXML_OBJECTS = $(LXML_SOURCES:.c=.o)
+  LXML_CFLAGS = -I$(LXML_DIR)
+  OBJECTS += $(LXML_OBJECTS)
+  CFLAGS += $(LXML_CFLAGS)
+  CFLAGS += -DUSE_LUA_LUAXML
+  #SOURCE_DIRS = $(LXML_DIR)
+endif
+

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/resources/Makefile.in-os
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/resources/Makefile.in-os b/thirdparty/civetweb-1.9.1/resources/Makefile.in-os
new file mode 100644
index 0000000..9ad1132
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/resources/Makefile.in-os
@@ -0,0 +1,22 @@
+# 
+# Copyright (c) 2013 No Face Press, LLC
+# License http://opensource.org/licenses/mit-license.php MIT License
+#
+
+# Override this using TARGET_OS=LINUX on the command line
+ifeq ($(TARGET_OS),)
+  ifeq ($(OS),Windows_NT)
+    TARGET_OS = WIN32
+  else
+    UNAME_S := $(shell uname -s)
+    ifeq ($(UNAME_S),Linux)
+        TARGET_OS = LINUX
+    else
+        ifeq ($(UNAME_S),Darwin)
+            TARGET_OS = OSX
+        else
+            TARGET_OS = BSD
+        endif
+    endif
+  endif
+endif

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/resources/cert/client.crt
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/resources/cert/client.crt b/thirdparty/civetweb-1.9.1/resources/cert/client.crt
new file mode 100644
index 0000000..d6cd7ef
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/resources/cert/client.crt
@@ -0,0 +1,14 @@
+-----BEGIN CERTIFICATE-----
+MIICOTCCAaICCQCXNPrLNIw8IDANBgkqhkiG9w0BAQsFADBhMQswCQYDVQQGEwJ4
+eDELMAkGA1UECAwCeHgxCzAJBgNVBAcMAnh4MQswCQYDVQQKDAJ4eDELMAkGA1UE
+CwwCeHgxCzAJBgNVBAMMAnh4MREwDwYJKoZIhvcNAQkBFgJ4eDAeFw0xNTEwMjUy
+MzMxNDJaFw0yNTEwMjIyMzMxNDJaMGExCzAJBgNVBAYTAnh4MQswCQYDVQQIDAJ4
+eDELMAkGA1UEBwwCeHgxCzAJBgNVBAoMAnh4MQswCQYDVQQLDAJ4eDELMAkGA1UE
+AwwCeHgxETAPBgkqhkiG9w0BCQEWAnh4MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCB
+iQKBgQDGwWIIU2KUEufa0Ga5lnm7I8cX4LPRIFX4zL3g1Kuw27eRaJWJLz3Y97oi
+m0fUmhhKJoEFDxj9U4UbXZWMxzH5F8RfupUu+9yDqTWjTRaUQiM/C7dSPEevfqNP
+zBoERPrMzm9W5d8Ke04vpUzk0duoE6vyNQVECroNlHY7R4zQjwIDAQABMA0GCSqG
+SIb3DQEBCwUAA4GBAKZiZ2+sYJWFnQcfqcDJBwrbTo98SSxfryPmeVQSuM8AXC4I
+baX+fqkatdFidDBl96Aq8pDfqeAz+gqRoJ+Dx7opn5/b0WcB0lD+v25x+nO8g4z7
+HBzpVtvRTkC7dGase72csnqvyWm1xTSiHNRIghl0kZy8wb6V9GmJsHxBoKWN
+-----END CERTIFICATE-----

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/resources/cert/client.csr
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/resources/cert/client.csr b/thirdparty/civetweb-1.9.1/resources/cert/client.csr
new file mode 100644
index 0000000..8c5dbdc
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/resources/cert/client.csr
@@ -0,0 +1,11 @@
+-----BEGIN CERTIFICATE REQUEST-----
+MIIBoTCCAQoCAQAwYTELMAkGA1UEBhMCeHgxCzAJBgNVBAgMAnh4MQswCQYDVQQH
+DAJ4eDELMAkGA1UECgwCeHgxCzAJBgNVBAsMAnh4MQswCQYDVQQDDAJ4eDERMA8G
+CSqGSIb3DQEJARYCeHgwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAMbBYghT
+YpQS59rQZrmWebsjxxfgs9EgVfjMveDUq7Dbt5FolYkvPdj3uiKbR9SaGEomgQUP
+GP1ThRtdlYzHMfkXxF+6lS773IOpNaNNFpRCIz8Lt1I8R69+o0/MGgRE+szOb1bl
+3wp7Ti+lTOTR26gTq/I1BUQKug2UdjtHjNCPAgMBAAGgADANBgkqhkiG9w0BAQsF
+AAOBgQCVJKEisDii5qFbV75rOGF+tTChv3c051pWerl8U42s/MQ3jhzNb8+i7f2n
+Kn4yZU3u91xtAruAoKFPSnFpgQKyBRv57g5eM03nrUUImZcRT5Kkf4YsqRMsZ2yH
+MYk6QbTrJwibUoqEUUFgv0n5ONUBoEvhzZr0K9KZ3DLyIg1rpQ==
+-----END CERTIFICATE REQUEST-----

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/resources/cert/client.key
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/resources/cert/client.key b/thirdparty/civetweb-1.9.1/resources/cert/client.key
new file mode 100644
index 0000000..ea9e739
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/resources/cert/client.key
@@ -0,0 +1,15 @@
+-----BEGIN RSA PRIVATE KEY-----
+MIICXAIBAAKBgQDGwWIIU2KUEufa0Ga5lnm7I8cX4LPRIFX4zL3g1Kuw27eRaJWJ
+Lz3Y97oim0fUmhhKJoEFDxj9U4UbXZWMxzH5F8RfupUu+9yDqTWjTRaUQiM/C7dS
+PEevfqNPzBoERPrMzm9W5d8Ke04vpUzk0duoE6vyNQVECroNlHY7R4zQjwIDAQAB
+AoGAUPrNxHKlAYvKZ77te8QxiOwE3FezLAuuu5Y/7vD3mzGKU3Z3JtPWsSYN8ret
+xpOaPev+OV9zYRO8ce/pVNh8JTcvywU9SaaxzrMVIq+8rOfM8oCXwpKr7FqV6fO3
+a9JzofV6A2x3mzWqyixRVSGBWTC3Oc5+uaTX5pmJvMFgKLECQQDxFopXbhgPUVtQ
+Wa5onj3qDtYsuJALBDaHDV7nSoQySZpHn1DS/w1n+INOuwkXXfMzqdRDKGDh5VVe
+5rF1k1nVAkEA0wyI7aXYIJuYli5fCN6bwGQTwmwoWbyDDE+VkZlMUm8KhIzdnFjP
+j9+ntNshNYyKf6H9XqxuizNyiLyiWl+u0wJAXLWgSXLKycktZj62dQC1Kna+IcBv
+k+zw0wpvPl5Ha9cl/vji6eCu1RaZ2ALQwi2cwndCavjyGKxKIg5wm5goaQJAc4dC
+EW0ecUMbdOJvbWiGM/vUgTI5qF20EvIhuvECwYE9ba+6xBItlOFmaW8mr6x+SD3B
+d6jGXnbMNKOl7/i+twJBANIFBVZBal85Wn0V5MJFDWLB1vPSxXwb4OBwVD+j52H7
+YwpRbUn3/4CkiagDPdzio80WkWdkqpGZoVyDUpZi5Fg=
+-----END RSA PRIVATE KEY-----

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/resources/cert/client.pem
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/resources/cert/client.pem b/thirdparty/civetweb-1.9.1/resources/cert/client.pem
new file mode 100644
index 0000000..331fd70
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/resources/cert/client.pem
@@ -0,0 +1,29 @@
+-----BEGIN CERTIFICATE-----
+MIICOTCCAaICCQCXNPrLNIw8IDANBgkqhkiG9w0BAQsFADBhMQswCQYDVQQGEwJ4
+eDELMAkGA1UECAwCeHgxCzAJBgNVBAcMAnh4MQswCQYDVQQKDAJ4eDELMAkGA1UE
+CwwCeHgxCzAJBgNVBAMMAnh4MREwDwYJKoZIhvcNAQkBFgJ4eDAeFw0xNTEwMjUy
+MzMxNDJaFw0yNTEwMjIyMzMxNDJaMGExCzAJBgNVBAYTAnh4MQswCQYDVQQIDAJ4
+eDELMAkGA1UEBwwCeHgxCzAJBgNVBAoMAnh4MQswCQYDVQQLDAJ4eDELMAkGA1UE
+AwwCeHgxETAPBgkqhkiG9w0BCQEWAnh4MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCB
+iQKBgQDGwWIIU2KUEufa0Ga5lnm7I8cX4LPRIFX4zL3g1Kuw27eRaJWJLz3Y97oi
+m0fUmhhKJoEFDxj9U4UbXZWMxzH5F8RfupUu+9yDqTWjTRaUQiM/C7dSPEevfqNP
+zBoERPrMzm9W5d8Ke04vpUzk0duoE6vyNQVECroNlHY7R4zQjwIDAQABMA0GCSqG
+SIb3DQEBCwUAA4GBAKZiZ2+sYJWFnQcfqcDJBwrbTo98SSxfryPmeVQSuM8AXC4I
+baX+fqkatdFidDBl96Aq8pDfqeAz+gqRoJ+Dx7opn5/b0WcB0lD+v25x+nO8g4z7
+HBzpVtvRTkC7dGase72csnqvyWm1xTSiHNRIghl0kZy8wb6V9GmJsHxBoKWN
+-----END CERTIFICATE-----
+-----BEGIN RSA PRIVATE KEY-----
+MIICXAIBAAKBgQDGwWIIU2KUEufa0Ga5lnm7I8cX4LPRIFX4zL3g1Kuw27eRaJWJ
+Lz3Y97oim0fUmhhKJoEFDxj9U4UbXZWMxzH5F8RfupUu+9yDqTWjTRaUQiM/C7dS
+PEevfqNPzBoERPrMzm9W5d8Ke04vpUzk0duoE6vyNQVECroNlHY7R4zQjwIDAQAB
+AoGAUPrNxHKlAYvKZ77te8QxiOwE3FezLAuuu5Y/7vD3mzGKU3Z3JtPWsSYN8ret
+xpOaPev+OV9zYRO8ce/pVNh8JTcvywU9SaaxzrMVIq+8rOfM8oCXwpKr7FqV6fO3
+a9JzofV6A2x3mzWqyixRVSGBWTC3Oc5+uaTX5pmJvMFgKLECQQDxFopXbhgPUVtQ
+Wa5onj3qDtYsuJALBDaHDV7nSoQySZpHn1DS/w1n+INOuwkXXfMzqdRDKGDh5VVe
+5rF1k1nVAkEA0wyI7aXYIJuYli5fCN6bwGQTwmwoWbyDDE+VkZlMUm8KhIzdnFjP
+j9+ntNshNYyKf6H9XqxuizNyiLyiWl+u0wJAXLWgSXLKycktZj62dQC1Kna+IcBv
+k+zw0wpvPl5Ha9cl/vji6eCu1RaZ2ALQwi2cwndCavjyGKxKIg5wm5goaQJAc4dC
+EW0ecUMbdOJvbWiGM/vUgTI5qF20EvIhuvECwYE9ba+6xBItlOFmaW8mr6x+SD3B
+d6jGXnbMNKOl7/i+twJBANIFBVZBal85Wn0V5MJFDWLB1vPSxXwb4OBwVD+j52H7
+YwpRbUn3/4CkiagDPdzio80WkWdkqpGZoVyDUpZi5Fg=
+-----END RSA PRIVATE KEY-----

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/resources/cert/make_cert.bat
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/resources/cert/make_cert.bat b/thirdparty/civetweb-1.9.1/resources/cert/make_cert.bat
new file mode 100644
index 0000000..27f8850
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/resources/cert/make_cert.bat
@@ -0,0 +1,22 @@
+del server.*
+
+c:\OpenSSL-Win32\bin\openssl.exe genrsa -des3 -out server.key 4096
+
+c:\OpenSSL-Win32\bin\openssl.exe req -sha256 -new -key server.key -out server.csr -utf8
+
+copy server.key server.key.orig
+
+c:\OpenSSL-Win32\bin\openssl.exe rsa -in server.key.orig -out server.key
+
+echo [ v3_ca ] > server.ext.txt
+echo [ req ] >> server.ext.txt
+echo req_extensions = my_extensions >> server.ext.txt
+echo [ my_extensions ] >> server.ext.txt
+echo extendedKeyUsage=serverAuth >> server.ext.txt
+echo crlDistributionPoints=URI:http://localhost/crl.pem >> server.ext.txt
+
+c:\OpenSSL-Win32\bin\openssl.exe x509 -req -days 365 -extensions v3_ca -extfile server.ext.txt -in server.csr -signkey server.key -out server.crt
+
+copy server.crt server.pem
+
+type server.key >> server.pem

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/resources/cert/make_certs
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/resources/cert/make_certs b/thirdparty/civetweb-1.9.1/resources/cert/make_certs
new file mode 100644
index 0000000..1dcf32b
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/resources/cert/make_certs
@@ -0,0 +1,31 @@
+#using "pass" for every password
+
+openssl genrsa -des3 -out client.key 1024
+openssl req -new -key client.key -out client.csr
+
+cp client.key client.key.orig
+
+openssl rsa -in client.key.orig -out client.key
+
+openssl x509 -req -days 3650 -in client.csr -signkey client.key -out client.crt
+
+cp client.crt client.pem
+cat client.key >> client.pem
+
+openssl pkcs12 -export -inkey client.key -in client.pem -name ClientName -out client.pfx
+
+
+
+openssl genrsa -des3 -out server.key 1024
+openssl req -new -key server.key -out server.csr
+
+cp server.key server.key.orig
+
+openssl rsa -in server.key.orig -out server.key
+
+openssl x509 -req -days 3650 -in server.csr -signkey server.key -out server.crt
+
+cp server.crt server.pem
+cat server.key >> server.pem
+
+openssl pkcs12 -export -inkey server.key -in server.pem -name ServerName -out server.pfx

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/resources/cert/server.crt
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/resources/cert/server.crt b/thirdparty/civetweb-1.9.1/resources/cert/server.crt
new file mode 100644
index 0000000..b43ac60
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/resources/cert/server.crt
@@ -0,0 +1,30 @@
+-----BEGIN CERTIFICATE-----
+MIIFOzCCAyOgAwIBAgIJAPbrrAobpdmKMA0GCSqGSIb3DQEBCwUAMF0xCzAJBgNV
+BAYTAkFVMRMwEQYDVQQIDApTb21lLVN0YXRlMSEwHwYDVQQKDBhJbnRlcm5ldCBX
+aWRnaXRzIFB0eSBMdGQxFjAUBgNVBAMMDTkwLjE0Ni4xMTguOTgwHhcNMTYwODI1
+MjIyMjE2WhcNMTcwODI1MjIyMjE2WjBdMQswCQYDVQQGEwJBVTETMBEGA1UECAwK
+U29tZS1TdGF0ZTEhMB8GA1UECgwYSW50ZXJuZXQgV2lkZ2l0cyBQdHkgTHRkMRYw
+FAYDVQQDDA05MC4xNDYuMTE4Ljk4MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIIC
+CgKCAgEA3xlvVgYrxmac+wYp9d5K9MdKmFgh5kcY1vOyxQxhFARtJdpgqH/qQDXb
+/z61N4baElCJUvwJtmGkIEXS/8PXROFdyr87+qHZsq641uATXz8PZG2N9KRGfd7m
+gXTIz1j/0cl6DFYT7/EsOS1gGhcyvdh6MRGBwPHhanVf9jIMWeM06P85SPgQu4pK
+WOyT+jSLJp2V3MTriuskJtTu9ViBR/J6s1qxfKVlaMOsFlqh1wLuGgmeFclpFCXm
+qi3a4x4PFU1PNOHCeS7WFnFiLtD8kR2cnOpXl0lgqFNAHh7vLbTwqfOyAU70Bs5k
+FO00nXc6zVFLcT4OPMg/0GO8VUmZ7WbwAhBqNo/CBb6CSSbfzk/vY4SiiBsvVP3p
+PCM0Y63v6p/85FkwIWP6Waa4Y3mzuO6X+Msis/pruVvO0R6wE5vBERqGVOIDbJbR
+hq8ef4m28GjBS+bbO+zs6BPJuEAEpnLfyaALHdzwNPTtNsK2vFk83ydajc78I4pk
+z7izX4YU1bX0nB2vDJPMMXiDecPd1pd8vRb6z2J4EWH7kmXjHDctPHJEnAi4nH5d
+7AW/b2ay6lwkZCKM3xwv/7f8IM7/kJQsFrYGEP5Ihzf8a8xZNKODWfWoYeb0kFxB
+BlAFY7aaxUJE4KuZ5JuhB/jVXGRCg414kjAvGk5RxlRoUgpfFBkCAwEAATANBgkq
+hkiG9w0BAQsFAAOCAgEAw5ECEdusFNszqpgEZ540uOq81RuY1p2eGg6p/NoBXpmN
++1PVhEagDIDgMYGdQpuDxpQsx8m6wolz9HlzvUlafQ/+1bTX8IzbWhi3Zpl+NoYP
+0oNCILAuIdXb7Lm4ZCoGYI/ig7YyDUp5P+7po3UDuWCTi8xRdZ92EG39cJu5GfHl
+rdtoG3bMn8TcwiK5H5la6hwuBoRn88yXNScT+WIlsKoQ+9YroC1uhj51yjit0J28
+vSyxMeN0380W9S4YakuDzLYz0elm1xvkdH4kcKx1x1mMYfppFuIR9O0c0uVdGI95
+ElJoU+4AhGg6YWR2BWw0vNjFThB2uPmvgvmHos00i/81LcDqxeUm7PbN7/sXxp+I
+GAXqZ2+ffKh0aKfNB8IuTg6NL5S3+9oo8ZOLyHwnuMMsKQOKR8tKghEXdxHkfuxk
+a4RJmzNT477NOPEO+2cKuYbbQ6uL5zJxTDWhCfEEh0s2o4/0T0A8ClkgGKP6SgC7
+hp/yW0/rTeaRURK6fGnmxAl8cg7979OMqa/KaK2vnqJQFxlJg1qwJzu078NZ/KUX
++obupnukdyRJPxFAgdYOfwdaFz1RmCz1VznlrDoGcJnHPeI7ZY0fze/U83TW2qOx
+b2GGlQ62LeovgnKel4XE2NxwmshcnDR5CCs3tkNFDXNjKSNeNgxR4/bddGpomO0=
+-----END CERTIFICATE-----

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/resources/cert/server.csr
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/resources/cert/server.csr b/thirdparty/civetweb-1.9.1/resources/cert/server.csr
new file mode 100644
index 0000000..002e0ba
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/resources/cert/server.csr
@@ -0,0 +1,28 @@
+-----BEGIN CERTIFICATE REQUEST-----
+MIIE1TCCAr0CAQAwXTELMAkGA1UEBhMCQVUxEzARBgNVBAgMClNvbWUtU3RhdGUx
+ITAfBgNVBAoMGEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZDEWMBQGA1UEAwwNOTAu
+MTQ2LjExOC45ODCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIBAN8Zb1YG
+K8ZmnPsGKfXeSvTHSphYIeZHGNbzssUMYRQEbSXaYKh/6kA12/8+tTeG2hJQiVL8
+CbZhpCBF0v/D10ThXcq/O/qh2bKuuNbgE18/D2RtjfSkRn3e5oF0yM9Y/9HJegxW
+E+/xLDktYBoXMr3YejERgcDx4Wp1X/YyDFnjNOj/OUj4ELuKSljsk/o0iyadldzE
+64rrJCbU7vVYgUfyerNasXylZWjDrBZaodcC7hoJnhXJaRQl5qot2uMeDxVNTzTh
+wnku1hZxYi7Q/JEdnJzqV5dJYKhTQB4e7y208KnzsgFO9AbOZBTtNJ13Os1RS3E+
+DjzIP9BjvFVJme1m8AIQajaPwgW+gkkm385P72OEoogbL1T96TwjNGOt7+qf/ORZ
+MCFj+lmmuGN5s7jul/jLIrP6a7lbztEesBObwREahlTiA2yW0YavHn+JtvBowUvm
+2zvs7OgTybhABKZy38mgCx3c8DT07TbCtrxZPN8nWo3O/COKZM+4s1+GFNW19Jwd
+rwyTzDF4g3nD3daXfL0W+s9ieBFh+5Jl4xw3LTxyRJwIuJx+XewFv29msupcJGQi
+jN8cL/+3/CDO/5CULBa2BhD+SIc3/GvMWTSjg1n1qGHm9JBcQQZQBWO2msVCROCr
+meSboQf41VxkQoONeJIwLxpOUcZUaFIKXxQZAgMBAAGgMzATBgkqhkiG9w0BCQcx
+BgwEcGFzczAcBgkqhkiG9w0BCQIxDwwNOTAuMTQ2LjExOC45ODANBgkqhkiG9w0B
+AQsFAAOCAgEAy1IsV9s+BxoKAtnfKwTns7lwgNr4FGwHDAxLwJz7MWLwfI+KTG/j
+o7lRYwNXHfAq8+jxu/7Ucag3s74RcknnIxydqlSa9U76HYRc9GHc0mPDm4tWVfQ+
+gl+0yjzIRSoSFGVkeuh0DomZq/p5HcUk1z1k6lDCNvJGdxvGIKh3ZysAaehKLtzz
+R9Xk71f2MPDtX2dzbRsgLKU8KAhwLRWO480asq1ampWjgkcT0kBj9KWBekB461yL
+rbaxYwuLY+z5uSsHyEfSt22mRtuuFcb7L+kxOQnFYnyfhVWeHknKxBF+JUM31Keu
+T92I/gQlxbcTW1BfNHDp8JtwS1RFFDFdFDyikbejyYqx+N/zHPh26BASrgn0Hi7o
+zpqkyq8XiNzANWroY+n0Br8yvghLVfsM600Vw3msiBeBZPYzfPgoSM3l1rMb9lak
+Nw0+VFJmKzpfiJNECGoI2rdFjvsGmgtPUMGCYutURb5Ic5kbkwk4tgHg95DFl1H+
+fsWaEYZ9lmWrK+dV/5DYAfMqdBEkKMH4j0PqjQAhulYbf/Mo8HnQoL4SxUb/Yd1J
+l6979lflRVEBPxNt2OOWgUAFQBef0HnHYf/2XQo32Sdy/Q/bcANtDK7MkFahFNK5
+kNQtD7P+oUZZNstTogL+IaH5AiyGJ7igho4HKMsXeCrs3npxrJM0ppo=
+-----END CERTIFICATE REQUEST-----

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/resources/cert/server.key
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/resources/cert/server.key b/thirdparty/civetweb-1.9.1/resources/cert/server.key
new file mode 100644
index 0000000..b67ef52
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/resources/cert/server.key
@@ -0,0 +1,51 @@
+-----BEGIN RSA PRIVATE KEY-----
+MIIJKgIBAAKCAgEA3xlvVgYrxmac+wYp9d5K9MdKmFgh5kcY1vOyxQxhFARtJdpg
+qH/qQDXb/z61N4baElCJUvwJtmGkIEXS/8PXROFdyr87+qHZsq641uATXz8PZG2N
+9KRGfd7mgXTIz1j/0cl6DFYT7/EsOS1gGhcyvdh6MRGBwPHhanVf9jIMWeM06P85
+SPgQu4pKWOyT+jSLJp2V3MTriuskJtTu9ViBR/J6s1qxfKVlaMOsFlqh1wLuGgme
+FclpFCXmqi3a4x4PFU1PNOHCeS7WFnFiLtD8kR2cnOpXl0lgqFNAHh7vLbTwqfOy
+AU70Bs5kFO00nXc6zVFLcT4OPMg/0GO8VUmZ7WbwAhBqNo/CBb6CSSbfzk/vY4Si
+iBsvVP3pPCM0Y63v6p/85FkwIWP6Waa4Y3mzuO6X+Msis/pruVvO0R6wE5vBERqG
+VOIDbJbRhq8ef4m28GjBS+bbO+zs6BPJuEAEpnLfyaALHdzwNPTtNsK2vFk83yda
+jc78I4pkz7izX4YU1bX0nB2vDJPMMXiDecPd1pd8vRb6z2J4EWH7kmXjHDctPHJE
+nAi4nH5d7AW/b2ay6lwkZCKM3xwv/7f8IM7/kJQsFrYGEP5Ihzf8a8xZNKODWfWo
+Yeb0kFxBBlAFY7aaxUJE4KuZ5JuhB/jVXGRCg414kjAvGk5RxlRoUgpfFBkCAwEA
+AQKCAgEAwVqK6rRYdg/y14AlF6j7r5+VX+lqH+jYd1soQa0T6cRYUGkuQnryK4pC
+S7ouVpxyHVNdYOV9CWsgUrQRRYeW52Sm5BPPSM3DHiBdpCT5xR+jGHf2guNpEKgB
+gIsVitboiAok09I6X0bW/Ar+cj5OxMh8RlCU8wLvSVPGwlnn6HOJJLImFL6hydf1
+zZHkQgIN437KJlcoiPJ4F4uOOmblTNSzUQQ2NQAnnp+PYqRUBUPN1hUlxF4Vytd6
+TV2GijY//kdNcViEMoDMHRFRdZ+8dYyDcl+LYFvBAMF+HVzUD/n0ZmcFjCrARbHU
+fWqDokF2XgGp79BHiJhI7jOyQvySANb7Fxcrj5nGkp6KeddLKVuPbB0huZuWJfCf
+Z5CgxBiK83GYPAbHJdKd7DHzxb833X8A9bxdK3yLwxRyknLZpEcjQVVft41bHGx/
+RN/IaeMisKFdf7GFJujCyngFt7etzfTP708veIPk7R7L4OUvoTQuK4jd416qxLYX
+efvaLM8c3JLOPVMW2Wt6fUU/r/NRX5uCSWx7hkfQO05sxgfY88ozgNQGgt3DnPPG
+EXqegXe7qu54JVNMtPYT1sWBAA/SXCJLxhIlrzvaGOcrN3eQnXaRt47rutOn5Uo2
+OEeZ8DnF3yZs/OLEF9du1yMlfpgg5u6wnixzdGqNzfFCymq5w80CggEBAPomSkET
+/rr1IzDL6xE51nZt/tP3J8nfE0U4tg7/8a+Utj4wDguW1plftuNg7Q3xwiRjIKbs
+gWs4poig3JrcltoEpvUXwr7HLs21gfMJ/iqFbJrWaWeBC1s0xMcM/zFaIniHUwfi
+m2YrBBLyZJoJDrCnKGI2MHhGvEGdNMm90n6YMOMKEWocM9QJtc89nC8m77Lejf/7
+PzRvHzh2anX1srwlronjw6XDpVcyGa4TXCFKZv5ncbggJ9OrliO/zTPekGzXD15h
+w4g4xLm0q9zieI4xqFxVReBV8NfXDWbAUA5Qt76Gz/rhZwT0PtxzoCViZFi489JO
+mUkSrzut0/FDDC8CggEBAORRMDB/leJknY2z8zHYSGEvL1USais2Hhf7aKI9pUPk
+VXdi3g0Bpt97cDdcD6rooJ1CZNWUtT/IbFcE1k5qlDjLMP0TLia9Joj87mNdeP7B
+pi83eDFCEx69TVDkVSe4BBldMx9JiN8V6v326P8Gl9TWq/92WRvIKQ9CTDg2dHkg
+Xc+psn9z1dvH6AAFjEuCIgSa/RtdrW8caDt3lmdqb8yDLz4FZpgREGnnTaG18gsm
+CgQLxwTm0A0GLXmbzYrdhSo0Hts6c3w/k6+FIR5zPv3mOIoNn9Nsqpqx4r75WVIc
+15qFVAFaaSMsIJJVtiUIrmPfW78jSDeagF1YmpXUajcCggEBANzbx72zsLlSzHI9
+6Nq5rS+9KDvvwPKMgZAhZSTTN4lljI5VkWEMGYcrKeeR4VrpdBb6ao7Wy+FmECsb
+lAsq7gmqB9rn0qrsY9d+BTEXRpA2Y1BGNKQNHIC3k3GHeR0SztKJ8HZKzhejrSIp
+X0dc7dpsi8xCugLHuVlZOo1QirP5HVinv/5mzh/NPveuFuLOxt2vf8JeC0z5O6B3
+dMGXX+qcfoECVvBZT/cvpdq6/yHpdgvyO0ZtJZzOp24C32OHgw6Fxuz29lOkg5TO
+/tq0Heq1z0dOhrZuSonXNt7ctxIclE6k6qZAMtv95i5v7Bp1x9FJ4wRxHweUdqED
+ddhS8UMCggEAUx+L39xTgV0IT3LYc6k+kMNRBDP0G09UnX6WlZrD9HfI9fI0zZ9w
+VaTnMgB+Y8bV0us9MtU1N8eMShIkw9/hntu7NigpgUkUIoOTdvGs/3MZQc98HtLj
+iyl4YJ8Asbk5JNLdreJjxnSAXX3rTg3kcUTG0fcQciDpcfi9LyoENaUnAlfR+Lz/
+e0jImllqvoLeR7b1t2Tfo7g/6oabZ4NEuLx6EqZ8t5he1W+0v88yFAUBWH/BMXOn
+A1bgb4ndx1TnCnp3UXFyYiXzas+ZQzDKGj4bD4fuTFcftbpVxxmY/2AozsUD1IpK
+BNgn857o9Yq3kvzatjfuLvA9E78SaMIw+QKCAQEAlTSQh3qA6BB/iZS0EWFac4Qe
+P7k5Eth+tCXoMHSf/i1IZoIreKiW9n4uT902UEhxJEPR2gtJulyAnul4xH+9txAB
+u/SdKm7ZmqNUlARdvSUp02PeFbkAe14/dK9LOEJ4Rr979BqTCi/prD1w1OaYCkuT
+UD1QcHYSHiHeht5WHDY4ig2ImGw34C0qFvgKeJKCfZwPwOTyqNNT/2MLmGnPF1Tx
+0rS7xBRe2dyPZAeJZB0ilz0ykE+mTcNSLVmWJHDl7YkMIfbnJGGOjmce+tKkkrfA
+lq0Myvx9q0Rj+RWhjI+iCHcAnOUJLIdK1TmFS4DxCzRPqx3rCiY8SBbWXJUTwA==
+-----END RSA PRIVATE KEY-----

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/resources/cert/server.pem
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/resources/cert/server.pem b/thirdparty/civetweb-1.9.1/resources/cert/server.pem
new file mode 100644
index 0000000..5b443e1
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/resources/cert/server.pem
@@ -0,0 +1,81 @@
+-----BEGIN CERTIFICATE-----
+MIIFOzCCAyOgAwIBAgIJAPbrrAobpdmKMA0GCSqGSIb3DQEBCwUAMF0xCzAJBgNV
+BAYTAkFVMRMwEQYDVQQIDApTb21lLVN0YXRlMSEwHwYDVQQKDBhJbnRlcm5ldCBX
+aWRnaXRzIFB0eSBMdGQxFjAUBgNVBAMMDTkwLjE0Ni4xMTguOTgwHhcNMTYwODI1
+MjIyMjE2WhcNMTcwODI1MjIyMjE2WjBdMQswCQYDVQQGEwJBVTETMBEGA1UECAwK
+U29tZS1TdGF0ZTEhMB8GA1UECgwYSW50ZXJuZXQgV2lkZ2l0cyBQdHkgTHRkMRYw
+FAYDVQQDDA05MC4xNDYuMTE4Ljk4MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIIC
+CgKCAgEA3xlvVgYrxmac+wYp9d5K9MdKmFgh5kcY1vOyxQxhFARtJdpgqH/qQDXb
+/z61N4baElCJUvwJtmGkIEXS/8PXROFdyr87+qHZsq641uATXz8PZG2N9KRGfd7m
+gXTIz1j/0cl6DFYT7/EsOS1gGhcyvdh6MRGBwPHhanVf9jIMWeM06P85SPgQu4pK
+WOyT+jSLJp2V3MTriuskJtTu9ViBR/J6s1qxfKVlaMOsFlqh1wLuGgmeFclpFCXm
+qi3a4x4PFU1PNOHCeS7WFnFiLtD8kR2cnOpXl0lgqFNAHh7vLbTwqfOyAU70Bs5k
+FO00nXc6zVFLcT4OPMg/0GO8VUmZ7WbwAhBqNo/CBb6CSSbfzk/vY4SiiBsvVP3p
+PCM0Y63v6p/85FkwIWP6Waa4Y3mzuO6X+Msis/pruVvO0R6wE5vBERqGVOIDbJbR
+hq8ef4m28GjBS+bbO+zs6BPJuEAEpnLfyaALHdzwNPTtNsK2vFk83ydajc78I4pk
+z7izX4YU1bX0nB2vDJPMMXiDecPd1pd8vRb6z2J4EWH7kmXjHDctPHJEnAi4nH5d
+7AW/b2ay6lwkZCKM3xwv/7f8IM7/kJQsFrYGEP5Ihzf8a8xZNKODWfWoYeb0kFxB
+BlAFY7aaxUJE4KuZ5JuhB/jVXGRCg414kjAvGk5RxlRoUgpfFBkCAwEAATANBgkq
+hkiG9w0BAQsFAAOCAgEAw5ECEdusFNszqpgEZ540uOq81RuY1p2eGg6p/NoBXpmN
++1PVhEagDIDgMYGdQpuDxpQsx8m6wolz9HlzvUlafQ/+1bTX8IzbWhi3Zpl+NoYP
+0oNCILAuIdXb7Lm4ZCoGYI/ig7YyDUp5P+7po3UDuWCTi8xRdZ92EG39cJu5GfHl
+rdtoG3bMn8TcwiK5H5la6hwuBoRn88yXNScT+WIlsKoQ+9YroC1uhj51yjit0J28
+vSyxMeN0380W9S4YakuDzLYz0elm1xvkdH4kcKx1x1mMYfppFuIR9O0c0uVdGI95
+ElJoU+4AhGg6YWR2BWw0vNjFThB2uPmvgvmHos00i/81LcDqxeUm7PbN7/sXxp+I
+GAXqZ2+ffKh0aKfNB8IuTg6NL5S3+9oo8ZOLyHwnuMMsKQOKR8tKghEXdxHkfuxk
+a4RJmzNT477NOPEO+2cKuYbbQ6uL5zJxTDWhCfEEh0s2o4/0T0A8ClkgGKP6SgC7
+hp/yW0/rTeaRURK6fGnmxAl8cg7979OMqa/KaK2vnqJQFxlJg1qwJzu078NZ/KUX
++obupnukdyRJPxFAgdYOfwdaFz1RmCz1VznlrDoGcJnHPeI7ZY0fze/U83TW2qOx
+b2GGlQ62LeovgnKel4XE2NxwmshcnDR5CCs3tkNFDXNjKSNeNgxR4/bddGpomO0=
+-----END CERTIFICATE-----
+-----BEGIN RSA PRIVATE KEY-----
+MIIJKgIBAAKCAgEA3xlvVgYrxmac+wYp9d5K9MdKmFgh5kcY1vOyxQxhFARtJdpg
+qH/qQDXb/z61N4baElCJUvwJtmGkIEXS/8PXROFdyr87+qHZsq641uATXz8PZG2N
+9KRGfd7mgXTIz1j/0cl6DFYT7/EsOS1gGhcyvdh6MRGBwPHhanVf9jIMWeM06P85
+SPgQu4pKWOyT+jSLJp2V3MTriuskJtTu9ViBR/J6s1qxfKVlaMOsFlqh1wLuGgme
+FclpFCXmqi3a4x4PFU1PNOHCeS7WFnFiLtD8kR2cnOpXl0lgqFNAHh7vLbTwqfOy
+AU70Bs5kFO00nXc6zVFLcT4OPMg/0GO8VUmZ7WbwAhBqNo/CBb6CSSbfzk/vY4Si
+iBsvVP3pPCM0Y63v6p/85FkwIWP6Waa4Y3mzuO6X+Msis/pruVvO0R6wE5vBERqG
+VOIDbJbRhq8ef4m28GjBS+bbO+zs6BPJuEAEpnLfyaALHdzwNPTtNsK2vFk83yda
+jc78I4pkz7izX4YU1bX0nB2vDJPMMXiDecPd1pd8vRb6z2J4EWH7kmXjHDctPHJE
+nAi4nH5d7AW/b2ay6lwkZCKM3xwv/7f8IM7/kJQsFrYGEP5Ihzf8a8xZNKODWfWo
+Yeb0kFxBBlAFY7aaxUJE4KuZ5JuhB/jVXGRCg414kjAvGk5RxlRoUgpfFBkCAwEA
+AQKCAgEAwVqK6rRYdg/y14AlF6j7r5+VX+lqH+jYd1soQa0T6cRYUGkuQnryK4pC
+S7ouVpxyHVNdYOV9CWsgUrQRRYeW52Sm5BPPSM3DHiBdpCT5xR+jGHf2guNpEKgB
+gIsVitboiAok09I6X0bW/Ar+cj5OxMh8RlCU8wLvSVPGwlnn6HOJJLImFL6hydf1
+zZHkQgIN437KJlcoiPJ4F4uOOmblTNSzUQQ2NQAnnp+PYqRUBUPN1hUlxF4Vytd6
+TV2GijY//kdNcViEMoDMHRFRdZ+8dYyDcl+LYFvBAMF+HVzUD/n0ZmcFjCrARbHU
+fWqDokF2XgGp79BHiJhI7jOyQvySANb7Fxcrj5nGkp6KeddLKVuPbB0huZuWJfCf
+Z5CgxBiK83GYPAbHJdKd7DHzxb833X8A9bxdK3yLwxRyknLZpEcjQVVft41bHGx/
+RN/IaeMisKFdf7GFJujCyngFt7etzfTP708veIPk7R7L4OUvoTQuK4jd416qxLYX
+efvaLM8c3JLOPVMW2Wt6fUU/r/NRX5uCSWx7hkfQO05sxgfY88ozgNQGgt3DnPPG
+EXqegXe7qu54JVNMtPYT1sWBAA/SXCJLxhIlrzvaGOcrN3eQnXaRt47rutOn5Uo2
+OEeZ8DnF3yZs/OLEF9du1yMlfpgg5u6wnixzdGqNzfFCymq5w80CggEBAPomSkET
+/rr1IzDL6xE51nZt/tP3J8nfE0U4tg7/8a+Utj4wDguW1plftuNg7Q3xwiRjIKbs
+gWs4poig3JrcltoEpvUXwr7HLs21gfMJ/iqFbJrWaWeBC1s0xMcM/zFaIniHUwfi
+m2YrBBLyZJoJDrCnKGI2MHhGvEGdNMm90n6YMOMKEWocM9QJtc89nC8m77Lejf/7
+PzRvHzh2anX1srwlronjw6XDpVcyGa4TXCFKZv5ncbggJ9OrliO/zTPekGzXD15h
+w4g4xLm0q9zieI4xqFxVReBV8NfXDWbAUA5Qt76Gz/rhZwT0PtxzoCViZFi489JO
+mUkSrzut0/FDDC8CggEBAORRMDB/leJknY2z8zHYSGEvL1USais2Hhf7aKI9pUPk
+VXdi3g0Bpt97cDdcD6rooJ1CZNWUtT/IbFcE1k5qlDjLMP0TLia9Joj87mNdeP7B
+pi83eDFCEx69TVDkVSe4BBldMx9JiN8V6v326P8Gl9TWq/92WRvIKQ9CTDg2dHkg
+Xc+psn9z1dvH6AAFjEuCIgSa/RtdrW8caDt3lmdqb8yDLz4FZpgREGnnTaG18gsm
+CgQLxwTm0A0GLXmbzYrdhSo0Hts6c3w/k6+FIR5zPv3mOIoNn9Nsqpqx4r75WVIc
+15qFVAFaaSMsIJJVtiUIrmPfW78jSDeagF1YmpXUajcCggEBANzbx72zsLlSzHI9
+6Nq5rS+9KDvvwPKMgZAhZSTTN4lljI5VkWEMGYcrKeeR4VrpdBb6ao7Wy+FmECsb
+lAsq7gmqB9rn0qrsY9d+BTEXRpA2Y1BGNKQNHIC3k3GHeR0SztKJ8HZKzhejrSIp
+X0dc7dpsi8xCugLHuVlZOo1QirP5HVinv/5mzh/NPveuFuLOxt2vf8JeC0z5O6B3
+dMGXX+qcfoECVvBZT/cvpdq6/yHpdgvyO0ZtJZzOp24C32OHgw6Fxuz29lOkg5TO
+/tq0Heq1z0dOhrZuSonXNt7ctxIclE6k6qZAMtv95i5v7Bp1x9FJ4wRxHweUdqED
+ddhS8UMCggEAUx+L39xTgV0IT3LYc6k+kMNRBDP0G09UnX6WlZrD9HfI9fI0zZ9w
+VaTnMgB+Y8bV0us9MtU1N8eMShIkw9/hntu7NigpgUkUIoOTdvGs/3MZQc98HtLj
+iyl4YJ8Asbk5JNLdreJjxnSAXX3rTg3kcUTG0fcQciDpcfi9LyoENaUnAlfR+Lz/
+e0jImllqvoLeR7b1t2Tfo7g/6oabZ4NEuLx6EqZ8t5he1W+0v88yFAUBWH/BMXOn
+A1bgb4ndx1TnCnp3UXFyYiXzas+ZQzDKGj4bD4fuTFcftbpVxxmY/2AozsUD1IpK
+BNgn857o9Yq3kvzatjfuLvA9E78SaMIw+QKCAQEAlTSQh3qA6BB/iZS0EWFac4Qe
+P7k5Eth+tCXoMHSf/i1IZoIreKiW9n4uT902UEhxJEPR2gtJulyAnul4xH+9txAB
+u/SdKm7ZmqNUlARdvSUp02PeFbkAe14/dK9LOEJ4Rr979BqTCi/prD1w1OaYCkuT
+UD1QcHYSHiHeht5WHDY4ig2ImGw34C0qFvgKeJKCfZwPwOTyqNNT/2MLmGnPF1Tx
+0rS7xBRe2dyPZAeJZB0ilz0ykE+mTcNSLVmWJHDl7YkMIfbnJGGOjmce+tKkkrfA
+lq0Myvx9q0Rj+RWhjI+iCHcAnOUJLIdK1TmFS4DxCzRPqx3rCiY8SBbWXJUTwA==
+-----END RSA PRIVATE KEY-----

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/resources/civetweb.conf
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/resources/civetweb.conf b/thirdparty/civetweb-1.9.1/resources/civetweb.conf
new file mode 100644
index 0000000..00aacde
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/resources/civetweb.conf
@@ -0,0 +1,32 @@
+# Civetweb web server configuration file.
+# For detailed description of every option, visit
+# https://github.com/civetweb/civetweb/blob/master/docs/UserManual.md
+# Lines starting with '#' and empty lines are ignored.
+# To make a change, remove leading '#', modify option's value,
+# save this file and then restart Civetweb.
+
+document_root .
+listening_ports 8080
+
+# cgi_pattern **.cgi$|**.pl$|**.php$
+# cgi_environment 
+# put_delete_auth_file 
+# cgi_interpreter 
+# protect_uri 
+# authentication_domain mydomain.com
+# ssi_pattern **.shtml$|**.shtm$
+# throttle 
+# access_log_file 
+# enable_directory_listing yes
+# error_log_file 
+# global_auth_file 
+# index_files index.html,index.htm,index.cgi,index.shtml,index.php,index.lp
+# enable_keep_alive no
+# access_control_list 
+# extra_mime_types 
+# ssl_certificate 
+# num_threads 50
+# run_as_user 
+# url_rewrite_patterns 
+# hide_files_patterns 
+# request_timeout_ms 30000

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/resources/civetweb.icns
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/resources/civetweb.icns b/thirdparty/civetweb-1.9.1/resources/civetweb.icns
new file mode 100644
index 0000000..af1f121
Binary files /dev/null and b/thirdparty/civetweb-1.9.1/resources/civetweb.icns differ

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/resources/civetweb.psd
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/resources/civetweb.psd b/thirdparty/civetweb-1.9.1/resources/civetweb.psd
new file mode 100644
index 0000000..accbe31
Binary files /dev/null and b/thirdparty/civetweb-1.9.1/resources/civetweb.psd differ

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/resources/civetweb_16x16.png
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/resources/civetweb_16x16.png b/thirdparty/civetweb-1.9.1/resources/civetweb_16x16.png
new file mode 100644
index 0000000..10ea1d2
Binary files /dev/null and b/thirdparty/civetweb-1.9.1/resources/civetweb_16x16.png differ

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/resources/civetweb_16x16@2.png
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/resources/civetweb_16x16@2.png b/thirdparty/civetweb-1.9.1/resources/civetweb_16x16@2.png
new file mode 100644
index 0000000..7621fb1
Binary files /dev/null and b/thirdparty/civetweb-1.9.1/resources/civetweb_16x16@2.png differ

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/resources/civetweb_22x22.png
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/resources/civetweb_22x22.png b/thirdparty/civetweb-1.9.1/resources/civetweb_22x22.png
new file mode 100644
index 0000000..f0b9094
Binary files /dev/null and b/thirdparty/civetweb-1.9.1/resources/civetweb_22x22.png differ

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/resources/civetweb_22x22@2.png
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/resources/civetweb_22x22@2.png b/thirdparty/civetweb-1.9.1/resources/civetweb_22x22@2.png
new file mode 100644
index 0000000..bdb3614
Binary files /dev/null and b/thirdparty/civetweb-1.9.1/resources/civetweb_22x22@2.png differ

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/resources/civetweb_32x32.png
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/resources/civetweb_32x32.png b/thirdparty/civetweb-1.9.1/resources/civetweb_32x32.png
new file mode 100644
index 0000000..62471e3
Binary files /dev/null and b/thirdparty/civetweb-1.9.1/resources/civetweb_32x32.png differ

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/resources/civetweb_32x32@2.png
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/resources/civetweb_32x32@2.png b/thirdparty/civetweb-1.9.1/resources/civetweb_32x32@2.png
new file mode 100644
index 0000000..e192a45
Binary files /dev/null and b/thirdparty/civetweb-1.9.1/resources/civetweb_32x32@2.png differ

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/resources/civetweb_64x64.png
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/resources/civetweb_64x64.png b/thirdparty/civetweb-1.9.1/resources/civetweb_64x64.png
new file mode 100644
index 0000000..bc8b995
Binary files /dev/null and b/thirdparty/civetweb-1.9.1/resources/civetweb_64x64.png differ

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/resources/civetweb_64x64@2.png
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/resources/civetweb_64x64@2.png b/thirdparty/civetweb-1.9.1/resources/civetweb_64x64@2.png
new file mode 100644
index 0000000..d6ad7b4
Binary files /dev/null and b/thirdparty/civetweb-1.9.1/resources/civetweb_64x64@2.png differ

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/resources/cleanup.lua
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/resources/cleanup.lua b/thirdparty/civetweb-1.9.1/resources/cleanup.lua
new file mode 100644
index 0000000..ab9557d
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/resources/cleanup.lua
@@ -0,0 +1,92 @@
+-- Lua script used to clean up tabs and spaces in C, CPP and H files.
+-- Copyright (c) 2014, bel
+-- MIT License (http://opensource.org/licenses/mit-license.php)
+--
+-- It can be used from the command line:
+-- Call Lua5.1 or Lua5.2 + this script file + the C/CPP/H file to clean
+--
+-- It can be used in Visual Studio as an external tool:
+-- command: Lua5.1.exe or Lua5.2.exe
+-- argument: "X:\civetweb\resources\cleanup.lua" $(ItemPath)
+--
+
+clean = arg[1]
+print("Cleaning " .. clean)
+
+lines = io.lines(clean)
+if not lines then
+    print("Can not open file " .. clean)
+    return
+end
+
+function trimright(s)
+  return s:match "^(.-)%s*$"
+end
+
+local lineend = false
+local tabspace = false
+local changed = false
+local invalid = false
+local newfile = {}
+
+lineno = 0
+incmt = false
+
+for l in lines do
+    lineno = lineno + 1
+    local lt = trimright(l)
+    if (lt ~= l) then
+        lineend = true
+        changed = true
+    end
+    local mcmt = l:find("%/%*");
+    if mcmt then
+        if incmt then
+            print("line " .. lineno .. " nested comment")
+        end
+        if not (l:sub(mcmt):find("%*%/")) then
+            -- multiline comment begins here
+            incmt = true
+        end
+    elseif incmt then
+        if not l:find("^%s*%*") then
+            print("line " .. lineno .. " multiline comment without leading *")
+        end
+        if l:find("%*%/") then
+            incmt = false
+        end
+    else
+        local cmt = l:find("//")
+        if (cmt) and (l:sub(cmt-5, cmt+1) ~= "http://") and (l:sub(cmt-6, cmt+1) ~= "https://") then
+            print("line " .. lineno .. " has C++ comment //")
+        end
+    end
+    local lts = lt:gsub('\t', '    ')
+    if (lts ~= lt) then
+        tabspace = true
+        changed = true
+    end
+    for i=1,#lts do
+        local b = string.byte(lts,i)
+        if b<32 or b>=127 then
+            print("Letter " .. string.byte(l,i) .. " (" .. b .. ") found in line " .. lts)
+            invalid = true
+        end
+    end
+
+    newfile[#newfile + 1] = lts
+end
+
+print("Line endings trimmed:     " .. tostring(lineend))
+print("Tabs converted to spaces: " .. tostring(tabspace))
+print("Invalid characters:       " .. tostring(invalid))
+
+if changed then
+    local f = io.open(clean, "wb")
+    for i=1,#newfile do
+        f:write(newfile[i])
+        f:write("\n")
+    end
+    f:close()
+    print("File cleaned")
+end

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/resources/coverity_check.sh
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/resources/coverity_check.sh b/thirdparty/civetweb-1.9.1/resources/coverity_check.sh
new file mode 100644
index 0000000..7cb8439
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/resources/coverity_check.sh
@@ -0,0 +1,33 @@
+#! /bin/sh
+
+ls src/civetweb.c
+if [ "$?" = "0" ]; then
+	echo "Building files for coverity check ..."
+else
+	echo "Run this script from the root directory of project!" 1>&2
+	echo "username@hostname:/somewhere/civetweb$ ./resources/coverity_check.sh" 1>&2
+	exit 1
+fi
+
+rm -rf cov_int/
+make clean
+
+../cov-analysis-linux64-7.6.0/bin/cov-build  --dir cov-int make WITH_IPV6=1 WITH_WEBSOCKET=1 WITH_LUA_SHARED=1
+
+rm civetweb_coverity_check.tgz
+tar czvf civetweb_coverity_check.tgz cov-int
+
+echo
+ls -la civetweb_coverity_check.tgz
+
+if [ "$?" = "0" ]; then
+	echo "... done"
+        echo
+else
+	echo "No civetweb_coverity_check.tgz file" 1>&2
+        echo
+	exit 1
+fi
+
+exit 0
+

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/resources/duktape-logo.png
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/resources/duktape-logo.png b/thirdparty/civetweb-1.9.1/resources/duktape-logo.png
new file mode 100644
index 0000000..afdc0f8
Binary files /dev/null and b/thirdparty/civetweb-1.9.1/resources/duktape-logo.png differ

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/resources/itworks.html
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/resources/itworks.html b/thirdparty/civetweb-1.9.1/resources/itworks.html
new file mode 100644
index 0000000..cba3bad
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/resources/itworks.html
@@ -0,0 +1,23 @@
+<html>
+<head>
+<title>Civetweb: It Works!</title>
+</head>
+<body>
+<div style="float:right; width:100%; text-align:center;">
+</div>
+<div style="float:left; height:50%; margin-bottom:-200px;"></div>
+<div style="clear:both; height:400px; width:400px; margin: auto; position:relative;">
+<img src="civetweb_64x64.png" alt="logo"/>
+<p>
+<b style="font-size:larger"><a style="text-decoration:none" href="https://sourceforge.net/projects/civetweb/">Civetweb</a></b><br>
+<i>Your web server</i>
+<ul>
+<li><a href="https://github.com/civetweb/civetweb/blob/master/docs/UserManual.md">User Manual</a></li>
+<li><a href="https://github.com/civetweb/civetweb/blob/master/RELEASE_NOTES.md">Release Notes</a></li>
+<li><a href="https://sourceforge.net/projects/civetweb/">Downloads</a></li>
+<li><a href="https://github.com/civetweb/civetweb">GitHub</a></li>
+</ul>
+</p>
+</div>
+</body>
+</html>

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/resources/jni/Android.mk
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/resources/jni/Android.mk b/thirdparty/civetweb-1.9.1/resources/jni/Android.mk
new file mode 100644
index 0000000..f24981a
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/resources/jni/Android.mk
@@ -0,0 +1,6 @@
+LOCAL_PATH := $(call my-dir)/../..
+include $(CLEAR_VARS)
+LOCAL_CFLAGS    := -std=c99 -O2 -W -Wall -pthread -pipe $(COPT)
+LOCAL_MODULE    := civetweb
+LOCAL_SRC_FILES := src\main.c src\civetweb.c
+include $(BUILD_EXECUTABLE)

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/resources/lua-logo.jpg
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/resources/lua-logo.jpg b/thirdparty/civetweb-1.9.1/resources/lua-logo.jpg
new file mode 100644
index 0000000..67de666
Binary files /dev/null and b/thirdparty/civetweb-1.9.1/resources/lua-logo.jpg differ

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/resources/luafilesystem-logo.jpg
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/resources/luafilesystem-logo.jpg b/thirdparty/civetweb-1.9.1/resources/luafilesystem-logo.jpg
new file mode 100644
index 0000000..4a2e855
Binary files /dev/null and b/thirdparty/civetweb-1.9.1/resources/luafilesystem-logo.jpg differ

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/resources/luasqlite-logo.jpg
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/resources/luasqlite-logo.jpg b/thirdparty/civetweb-1.9.1/resources/luasqlite-logo.jpg
new file mode 100644
index 0000000..9388126
Binary files /dev/null and b/thirdparty/civetweb-1.9.1/resources/luasqlite-logo.jpg differ

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/resources/luaxml-logo.jpg
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/resources/luaxml-logo.jpg b/thirdparty/civetweb-1.9.1/resources/luaxml-logo.jpg
new file mode 100644
index 0000000..9916f6e
Binary files /dev/null and b/thirdparty/civetweb-1.9.1/resources/luaxml-logo.jpg differ

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/resources/mingw.bat
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/resources/mingw.bat b/thirdparty/civetweb-1.9.1/resources/mingw.bat
new file mode 100644
index 0000000..8703266
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/resources/mingw.bat
@@ -0,0 +1,15 @@
+@rem MinGW build test - used to test MinGW builds locally
+@rem Adapt path/versions before use
+
+@rem This batch file must be used from the repository root
+@if exist mingw.bat cd ..
+
+
+@set PATH=%ProgramFiles%\mingw-w64\i686-4.9.2-win32-dwarf-rt_v3-rev1\mingw32\bin;%PATH%
+@set PATH=%ProgramFiles%\GnuWin32\bin;%PATH%
+
+@rem Alternative ways to use mingw
+@rem make CC=gcc CFLAGS=-w CFLAGS+=-Iinclude/ CFLAGS+=-lws2_32 CFLAGS+=-liphlpapi
+@rem gcc src\civetweb.c src\main.c -Iinclude\ -lws2_32 -lpthread -lcomdlg32 -w
+
+make build CC=gcc WITH_LUA=1 WITH_WEBSOCKET=1

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/resources/res.rc
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/resources/res.rc b/thirdparty/civetweb-1.9.1/resources/res.rc
new file mode 100644
index 0000000..38a80bb
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/resources/res.rc
@@ -0,0 +1 @@
+100 ICON DISCARDABLE "systray.ico"

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/resources/sqlite3-logo.jpg
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/resources/sqlite3-logo.jpg b/thirdparty/civetweb-1.9.1/resources/sqlite3-logo.jpg
new file mode 100644
index 0000000..14b01df
Binary files /dev/null and b/thirdparty/civetweb-1.9.1/resources/sqlite3-logo.jpg differ

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/resources/ssl_cert.pem
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/resources/ssl_cert.pem b/thirdparty/civetweb-1.9.1/resources/ssl_cert.pem
new file mode 100644
index 0000000..f7e15a0
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/resources/ssl_cert.pem
@@ -0,0 +1,50 @@
+-----BEGIN RSA PRIVATE KEY-----
+MIIEogIBAAKCAQEAwONaLOP7EdegqjRuQKSDXzvHmFMZfBufjhELhNjo5KsL4ieH
+hMSGCcSV6y32hzhqR5lvTViaQez+xhc58NZRu+OUgEhodRBW/vAOjpz/xdMz5HaC
+EhP3E9W1pkitVseS8B5rrgJo1BfCGai1fPav1nutPq2Kj7vMy24+g460Lonf6ln1
+di4aTIRtAqXtUU6RFpPJP35PkCXbTK65O8HJSxxt/XtfoezHCU5+UIwmZGYx46UB
+Wzg3IfK6bGPSiHU3pdiTol0uMPt/GUK+x4NyZJ4/ImsNAicRwMBdja4ywHKXJehH
+gXBthsVIHbL21x+4ibsg9eVM/XioTV6tW3IrdwIDAQABAoIBACFfdLutmkQFBcRN
+HAJNNHmmsyr0vcUOVnXTFyYeDXV67qxrYHQlOHe6LqIpKq1Mon7O2kYMnWvooFAP
+trOnsS6L+qaTYJdYg2TKjgo4ubw1hZXytyB/mdExuaMSkgMgtpia+tB5lD+V+LxN
+x1DesZ+veFMO3Zluyckswt4qM5yVa04YFrt31H0E1rJfIen61lidXIKYmHHWuRxK
+SadjFfbcqJ6P9ZF22BOkleg5Fm5NaxJmyQynOWaAkSZa5w1XySFfRjRfsbDr64G6
++LSG8YtRuvfxnvUNhynVPHcpE40eiPo6v8Ho6yZKXpV5klCKciodXAORsswSoGJa
+N3nnu/ECgYEA6Yb2rM3QUEPIALdL8f/OzZ1GBSdiQB2WSAxzl9pR/dLF2H+0pitS
+to0830mk92ppVmRVD3JGxYDRZQ56tlFXyGaCzJBMRIcsotAhBoNbjV0i9n5bLJYf
+BmjU9yvWcgsTt0tr3B0FrtYyp2tCvwHqlxvFpFdUCj2oRw2uGpkhmNkCgYEA03M6
+WxFhsix3y6eVCVvShfbLBSOqp8l0qiTEty+dgVQcWN4CO/5eyaZXKxlCG9KMmKxy
+Yx+YgxZrDhfaZ0cxhHGPRKEAxM3IKwT2C8/wCaSiLWXZZpTifnSD99vtOt4wEfrG
++AghNd5kamFiM9tU0AyvhJc2vdJFuXrfeC7ntM8CgYBGDA+t4cZcbRhu7ow/OKYF
+kulP3nJgHP/Y+LMrl3cEldZ2jEfZmCElVNQvfd2XwTl7injhOzvzPiKRF3jDez7D
+g8w0JAxceddvttJRK9GoY4l7OoeKpjUELSnEQkf+yUfOsTbXPXVY7jMfeNL6jE6b
+qN7t3qv8rmXtejMBE3G6cQKBgGR5W2BMiRSlxqKx1cKlrApV87BUe1HRCyuR3xuA
+d6Item7Lx1oEi7vb242yKdSYnpApWQ06xTh83Y/Ly87JaIEbiM0+h+P8OEIg0F1a
+iB+86AcUX1I8KseVy+Np0HbpfwP8GrFfA5DaRPK7pXMopEtby8cAJ1XZZaI1/ZvZ
+BebHAoGAcQU9WvCkT+nIp9FpXfBybYUsvgkaizMIqp66/l3GYgYAq8p1VLGvN4v5
+ec0dW58SJrCpqsM3NP78DtEzQf9OOsk+FsjBFzDU2RkeUreyt2/nQBj/2mN/+hEy
+hYN0Zii2yTb63jGxKY6gH1R/r9dL8kXaJmcZrfSa3AgywnteJWg=
+-----END RSA PRIVATE KEY-----
+-----BEGIN CERTIFICATE-----
+MIIDBjCCAe4CCQCX05m0b053QzANBgkqhkiG9w0BAQQFADBFMQswCQYDVQQGEwJB
+VTETMBEGA1UECBMKU29tZS1TdGF0ZTEhMB8GA1UEChMYSW50ZXJuZXQgV2lkZ2l0
+cyBQdHkgTHRkMB4XDTA4MTIwNzEwMjUyMloXDTE4MTIwNTEwMjUyMlowRTELMAkG
+A1UEBhMCQVUxEzARBgNVBAgTClNvbWUtU3RhdGUxITAfBgNVBAoTGEludGVybmV0
+IFdpZGdpdHMgUHR5IEx0ZDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEB
+AMDjWizj+xHXoKo0bkCkg187x5hTGXwbn44RC4TY6OSrC+Inh4TEhgnElest9oc4
+akeZb01YmkHs/sYXOfDWUbvjlIBIaHUQVv7wDo6c/8XTM+R2ghIT9xPVtaZIrVbH
+kvAea64CaNQXwhmotXz2r9Z7rT6tio+7zMtuPoOOtC6J3+pZ9XYuGkyEbQKl7VFO
+kRaTyT9+T5Al20yuuTvByUscbf17X6HsxwlOflCMJmRmMeOlAVs4NyHyumxj0oh1
+N6XYk6JdLjD7fxlCvseDcmSePyJrDQInEcDAXY2uMsBylyXoR4FwbYbFSB2y9tcf
+uIm7IPXlTP14qE1erVtyK3cCAwEAATANBgkqhkiG9w0BAQQFAAOCAQEAW4yZdqpB
+oIdiuXRosr86Sg9FiMg/cn+2OwQ0QIaA8ZBwKsc+wIIHEgXCS8J6316BGQeUvMD+
+plNe0r4GWzzmlDMdobeQ5arPRB89qd9skE6pAMdLg3FyyfEjz3A0VpskolW5VBMr
+P5R7uJ1FLgH12RyAjZCWYcCRqEMOffqvyMCH6oAjyDmQOA5IssRKX/HsHntSH/HW
+W7slTcP45ty1b44Nq22/ubYk0CJRQgqKOIQ3cLgPomN1jNFQbAbfVTaK1DpEysrQ
+5V8a8gNW+3sVZmV6d1Mj3pN2Le62wUKuV2g6BNU7iiwcoY8HI68aRxz2hVMS+t5f
+SEGI4JSxV56lYg==
+-----END CERTIFICATE-----
+-----BEGIN DH PARAMETERS-----
+MEYCQQD+ef8hZ4XbdoyIpJyCTF2UrUEfX6mYDvxuS5O1UNYcslUqlj6JkA11e/yS
+6DK8Z86W6mSj5CEk4IjbyEOECXH7AgEC
+-----END DH PARAMETERS-----

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/resources/systray.ico
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/resources/systray.ico b/thirdparty/civetweb-1.9.1/resources/systray.ico
new file mode 100644
index 0000000..380c0ee
Binary files /dev/null and b/thirdparty/civetweb-1.9.1/resources/systray.ico differ

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/CMakeLists.txt b/thirdparty/civetweb-1.9.1/src/CMakeLists.txt
new file mode 100644
index 0000000..281c324
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/CMakeLists.txt
@@ -0,0 +1,291 @@
+# The C API library
+add_library(c-library civetweb.c)
+set_target_properties(c-library PROPERTIES
+  OUTPUT_NAME "civetweb"
+  VERSION ${CIVETWEB_VERSION}
+  SOVERSION ${CIVETWEB_VERSION}
+)
+if (BUILD_SHARED_LIBS)
+  target_compile_definitions(c-library PRIVATE CIVETWEB_DLL_EXPORTS)
+endif()
+target_include_directories(
+  c-library PUBLIC
+  ${PROJECT_SOURCE_DIR}/include)
+install(
+  TARGETS c-library
+  ARCHIVE DESTINATION lib
+  LIBRARY DESTINATION lib
+  RUNTIME DESTINATION bin
+  COMPONENT c-library)
+install(FILES
+  ${PROJECT_SOURCE_DIR}/include/civetweb.h
+  DESTINATION include
+  COMPONENT c-library)
+
+# Need Windows sockets if available
+find_package(WinSock)
+if (WINSOCK_FOUND)
+  target_link_libraries(c-library WINSOCK::WINSOCK)
+endif()
+
+# We need threading
+find_package(Threads)
+target_link_libraries(c-library ${CMAKE_THREAD_LIBS_INIT})
+
+# Need the realtime library if we're using timers
+find_package(LibRt)
+if (CIVETWEB_ENABLE_WEBSOCKETS AND CIVETWEB_ENABLE_LUA AND LIBRT_FOUND)
+  target_link_libraries(c-library LIBRT::LIBRT)
+endif()
+
+# We need to link OpenSSL if not dynamically loading
+if (CIVETWEB_ENABLE_SLL AND NOT CIVETWEB_ENABLE_OPENSLL_DYNAMIC_LOADING)
+  find_package(OpenSSL)
+  target_link_libraries(c-library ${OPENSSL_LIBRARIES})
+else()
+  find_package(LibDl)
+  if (LIBDL_FOUND)
+    target_link_libraries(c-library -ldl)
+  endif()
+endif()
+
+# If Lua support is needed we build some extra Lua libraries
+if (CIVETWEB_ENABLE_LUA)
+  include(ExternalProject)
+
+  # Determine if we should print to the output
+  if (CIVETWEB_ENABLE_THIRD_PARTY_OUTPUT)
+    set(THIRD_PARTY_LOGGING 0)
+  else()
+    set(THIRD_PARTY_LOGGING 1)
+  endif()
+
+  # If Lua is static we must build it from source
+  if (NOT CIVETWEB_ENABLE_LUA_SHARED)
+    if (LINUX)
+      set(LUA_MAKE_TARGET linux)
+    elseif(DARWIN)
+      set(LUA_MAKE_TARGET macosx)
+    elseif(FREEBSD)
+      set(LUA_MAKE_TARGET freebsd)
+    elseif(WINDOWS)
+      set(LUA_MAKE_TARGET mingw)
+    elseif(UNIX)
+      set(LUA_MAKE_TARGET posix)
+    else()
+      set(LUA_MAKE_TARGET generic)
+    endif()
+    set(LUA_BUILD_COMMAND "${CMAKE_MAKE_PROGRAM};${LUA_MAKE_TARGET}")
+    if (BUILD_SHARED_LIBS)
+      set(LUA_BUILD_COMMAND "${LUA_BUILD_COMMAND};MYCFLAGS=-fPIC")
+    endif()
+    ExternalProject_Add(lua
+      URL "http://www.lua.org/ftp/lua-${CIVETWEB_LUA_VERSION}.tar.gz"
+      URL_MD5 ${CIVETWEB_LUA_MD5_HASH}
+      PREFIX "${CIVETWEB_THIRD_PARTY_DIR}"
+      CONFIGURE_COMMAND ""
+      BUILD_COMMAND ${LUA_BUILD_COMMAND}
+      BUILD_IN_SOURCE 1
+      INSTALL_COMMAND make install "INSTALL_TOP=<INSTALL_DIR>"
+      LOG_DOWNLOAD ${THIRD_PARTY_LOGGING}
+      LOG_UPDATE ${THIRD_PARTY_LOGGING}
+      LOG_CONFIGURE ${THIRD_PARTY_LOGGING}
+      LOG_BUILD ${THIRD_PARTY_LOGGING}
+      LOG_TEST ${THIRD_PARTY_LOGGING}
+      LOG_INSTALL ${THIRD_PARTY_LOGGING})
+    ExternalProject_Get_Property(lua INSTALL_DIR)
+    set(LUA_INSTALL_DIR ${INSTALL_DIR})
+    unset(INSTALL_DIR)
+    link_directories("${LUA_INSTALL_DIR}/lib")
+    include_directories("${LUA_INSTALL_DIR}/include")
+    set(LUA_LIBRARIES "${LUA_INSTALL_DIR}/lib/liblua.a")
+    add_dependencies(c-library lua)
+  else()
+    find_package(Lua)
+  endif()
+
+  # Lua Filesystem Support
+  string(REPLACE "." "_" LUA_FILESYSTEM_VERSION_UNDERSCORE ${CIVETWEB_LUA_FILESYSTEM_VERSION})
+  ExternalProject_Add(luafilesystem
+    URL "https://github.com/keplerproject/luafilesystem/archive/v_${LUA_FILESYSTEM_VERSION_UNDERSCORE}.tar.gz"
+    URL_MD5 ${CIVETWEB_LUA_FILESYSTEM_MD5_HASH}
+    PREFIX "${CIVETWEB_THIRD_PARTY_DIR}"
+    PATCH_COMMAND ${CMAKE_COMMAND} -E copy
+      "${CMAKE_CURRENT_SOURCE_DIR}/cmake/luafilesystem/CMakeLists.txt" <SOURCE_DIR>/CMakeLists.txt
+    CMAKE_ARGS
+      "-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}"
+      "-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>"
+    LOG_DOWNLOAD ${THIRD_PARTY_LOGGING}
+    LOG_UPDATE ${THIRD_PARTY_LOGGING}
+    LOG_CONFIGURE ${THIRD_PARTY_LOGGING}
+    LOG_BUILD ${THIRD_PARTY_LOGGING}
+    LOG_TEST ${THIRD_PARTY_LOGGING}
+    LOG_INSTALL ${THIRD_PARTY_LOGGING})
+  ExternalProject_Get_Property(luafilesystem INSTALL_DIR)
+  set(LUA_FILESYSTEM_INSTALL_DIR ${INSTALL_DIR})
+  unset(INSTALL_DIR)
+  link_directories("${LUA_FILESYSTEM_INSTALL_DIR}/lib")
+  include_directories("${LUA_FILESYSTEM_INSTALL_DIR}/include")
+  set(LUA_LIBRARIES "${LUA_LIBRARIES};${LUA_FILESYSTEM_INSTALL_DIR}/lib/libluafilesystem.a")
+  add_dependencies(c-library luafilesystem)
+
+  # Lua SQLite Support
+  if (${CIVETWEB_LUA_SQLITE_VERSION} VERSION_EQUAL "0.9.3")
+    set(LUA_SQLITE_FILENAME lsqlite3_fsl09w.zip)
+  elseif (${CIVETWEB_LUA_SQLITE_VERSION} VERSION_EQUAL "0.9.2")
+    set(LUA_SQLITE_FILENAME lsqlite3_fsl09v.zip)
+  elseif (${CIVETWEB_LUA_SQLITE_VERSION} VERSION_EQUAL "0.9.1")
+    set(LUA_SQLITE_FILENAME lsqlite3_fsl09t.zip)
+  else()
+    message(FATAL_ERROR "The Lua SQLite archive filename is unknown for version ${CIVETWEB_LUA_SQLITE_VERSION}")
+  endif()
+  ExternalProject_Add(luasqlite
+    URL "http://lua.sqlite.org/index.cgi/zip/${LUA_SQLITE_FILENAME}"
+    URL_MD5 ${CIVETWEB_LUA_SQLITE_MD5_HASH}
+    PREFIX "${CIVETWEB_THIRD_PARTY_DIR}"
+    PATCH_COMMAND ${CMAKE_COMMAND} -E copy
+      "${CMAKE_CURRENT_SOURCE_DIR}/cmake/luasqlite/CMakeLists.txt" <SOURCE_DIR>/CMakeLists.txt
+    CMAKE_ARGS
+      "-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}"
+      "-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>"
+    LOG_DOWNLOAD ${THIRD_PARTY_LOGGING}
+    LOG_UPDATE ${THIRD_PARTY_LOGGING}
+    LOG_CONFIGURE ${THIRD_PARTY_LOGGING}
+    LOG_BUILD ${THIRD_PARTY_LOGGING}
+    LOG_TEST ${THIRD_PARTY_LOGGING}
+    LOG_INSTALL ${THIRD_PARTY_LOGGING})
+  ExternalProject_Get_Property(luasqlite INSTALL_DIR)
+  set(LUA_SQLITE_INSTALL_DIR ${INSTALL_DIR})
+  unset(INSTALL_DIR)
+  link_directories("${LUA_SQLITE_INSTALL_DIR}/lib")
+  set(LUA_LIBRARIES "${LUA_LIBRARIES};${LUA_SQLITE_INSTALL_DIR}/lib/libluasqlite.a")
+  add_dependencies(c-library luasqlite)
+
+  # Lua XML Support
+  if (${CIVETWEB_LUA_XML_VERSION} VERSION_EQUAL "1.8.0")
+    set(LUA_XML_FILENAME LuaXML_130610.zip)
+  elseif (${CIVETWEB_LUA_XML_VERSION} VERSION_EQUAL "1.7.4")
+    set(LUA_XML_FILENAME LuaXML_101012.zip)
+  else()
+    message(FATAL_ERROR "The Lua XML archive filename is unknown for version ${CIVETWEB_LUA_XML_VERSION}")
+  endif()
+  ExternalProject_Add(luaxml
+    URL "http://viremo.eludi.net/LuaXML/${LUA_XML_FILENAME}"
+    URL_MD5 ${CIVETWEB_LUA_XML_MD5_HASH}
+    PREFIX "${CIVETWEB_THIRD_PARTY_DIR}"
+    PATCH_COMMAND ${CMAKE_COMMAND} -E copy
+      "${CMAKE_CURRENT_SOURCE_DIR}/cmake/luaxml/CMakeLists.txt" <SOURCE_DIR>/CMakeLists.txt
+    CMAKE_ARGS
+      "-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}"
+      "-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>"
+    LOG_DOWNLOAD ${THIRD_PARTY_LOGGING}
+    LOG_UPDATE ${THIRD_PARTY_LOGGING}
+    LOG_CONFIGURE ${THIRD_PARTY_LOGGING}
+    LOG_BUILD ${THIRD_PARTY_LOGGING}
+    LOG_TEST ${THIRD_PARTY_LOGGING}
+    LOG_INSTALL ${THIRD_PARTY_LOGGING})
+  ExternalProject_Get_Property(luaxml INSTALL_DIR)
+  set(LUA_XML_INSTALL_DIR ${INSTALL_DIR})
+  unset(INSTALL_DIR)
+  link_directories("${LUA_XML_INSTALL_DIR}/lib")
+  set(LUA_LIBRARIES "${LUA_LIBRARIES};${LUA_XML_INSTALL_DIR}/lib/libluaxml.a")
+  add_dependencies(c-library luaxml)
+
+  # SQLite Support
+  string (REGEX MATCHALL "[0-9]+" SQLITE_VERSION_MATCHES ${CIVETWEB_SQLITE_VERSION})
+  list(GET SQLITE_VERSION_MATCHES 0 SQLITE_VERSION_MAJOR)
+  list(GET SQLITE_VERSION_MATCHES 1 SQLITE_VERSION_MINOR)
+  list(GET SQLITE_VERSION_MATCHES 2 SQLITE_VERSION_PATCH)
+  set(SQLITE_FILE_VERSION ${SQLITE_VERSION_MAJOR}0${SQLITE_VERSION_MINOR}0${SQLITE_VERSION_PATCH}00)
+  ExternalProject_Add(sqlite
+    URL "http://www.sqlite.org/2015/sqlite-amalgamation-${SQLITE_FILE_VERSION}.zip"
+    URL_MD5 ${CIVETWEB_SQLITE_MD5_HASH}
+    PREFIX "${CIVETWEB_THIRD_PARTY_DIR}"
+    PATCH_COMMAND ${CMAKE_COMMAND} -E copy
+      "${CMAKE_CURRENT_SOURCE_DIR}/cmake/sqlite/CMakeLists.txt" <SOURCE_DIR>/CMakeLists.txt
+    CMAKE_ARGS
+      "-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}"
+      "-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>"
+    LOG_DOWNLOAD ${THIRD_PARTY_LOGGING}
+    LOG_UPDATE ${THIRD_PARTY_LOGGING}
+    LOG_CONFIGURE ${THIRD_PARTY_LOGGING}
+    LOG_BUILD ${THIRD_PARTY_LOGGING}
+    LOG_TEST ${THIRD_PARTY_LOGGING}
+    LOG_INSTALL ${THIRD_PARTY_LOGGING})
+  ExternalProject_Get_Property(sqlite INSTALL_DIR)
+  set(SQLITE_INSTALL_DIR ${INSTALL_DIR})
+  unset(INSTALL_DIR)
+  link_directories("${SQLITE_INSTALL_DIR}/lib")
+  include_directories("${SQLITE_INSTALL_DIR}/include")
+  set(LUA_LIBRARIES "${LUA_LIBRARIES};${SQLITE_INSTALL_DIR}/lib/libsqlite.a")
+  add_dependencies(c-library sqlite)
+
+  # Link all the Lua libraries
+  target_link_libraries(c-library ${LUA_LIBRARIES})
+endif()
+
+# The web server executable
+add_executable(c-executable main.c)
+set_target_properties(c-executable PROPERTIES
+  OUTPUT_NAME "civetweb"
+)
+install(
+  TARGETS c-executable
+  ARCHIVE DESTINATION lib
+  LIBRARY DESTINATION lib
+  RUNTIME DESTINATION bin
+  COMPONENT server)
+if (BUILD_SHARED_LIBS)
+  target_compile_definitions(c-executable PRIVATE CIVETWEB_DLL_IMPORTS)
+endif()
+target_include_directories(
+  c-executable PUBLIC
+  ${PROJECT_SOURCE_DIR}/include)
+target_link_libraries(c-executable c-library)
+if (LIBRT_FOUND)
+  target_link_libraries(c-executable LIBRT::LIBRT)
+endif()
+
+if (CIVETWEB_ENABLE_LUA)
+  add_library(lua-library third_party/lfs.c third_party/lsqlite3.c third_party/LuaXML_lib.c third_party/sqlite3.c)
+  set_target_properties(lua-library PROPERTIES
+    OUTPUT_NAME "lua-library"
+    VERSION ${CIVETWEB_VERSION}
+    SOVERSION ${CIVETWEB_VERSION}
+  )
+  target_include_directories(
+    lua-library PUBLIC
+    ${PROJECT_SOURCE_DIR}/src/third_party/lua-5.2.4)
+  install(
+    TARGETS lua-library
+    ARCHIVE DESTINATION lib
+    LIBRARY DESTINATION lib
+    RUNTIME DESTINATION bin
+    COMPONENT lua-library)  
+endif()
+
+# The C++ API library
+if (CIVETWEB_ENABLE_CXX)
+  add_library(civetweb-cpp CivetServer.cpp)
+  set_target_properties(civetweb-cpp PROPERTIES
+    OUTPUT_NAME "civetweb-cpp"
+    VERSION ${CIVETWEB_VERSION}
+    SOVERSION ${CIVETWEB_VERSION}
+  )
+  if (BUILD_SHARED_LIBS)
+    target_compile_definitions(civetweb-cpp PRIVATE CIVETWEB_DLL_EXPORTS)
+  endif()
+  target_include_directories(
+    civetweb-cpp PUBLIC
+    ${PROJECT_SOURCE_DIR}/include)
+  install(
+    TARGETS civetweb-cpp
+    ARCHIVE DESTINATION lib
+    LIBRARY DESTINATION lib
+    RUNTIME DESTINATION bin
+    COMPONENT civetweb-cpp)
+  install(FILES
+    ${PROJECT_SOURCE_DIR}/include/CivetServer.h
+    DESTINATION include
+    COMPONENT civetweb-cpp)
+endif()


[14/51] [partial] nifi-minifi-cpp git commit: MINIFI-183 Added civet 1.9.1 sources Added onScheduled hook Added initial two-way TLS-enabled ListenHTTP implementation

Posted by al...@apache.org.
http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_bi_buffer.c
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_bi_buffer.c b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_bi_buffer.c
new file mode 100644
index 0000000..0d8efb0
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_bi_buffer.c
@@ -0,0 +1,2882 @@
+/*
+ *  Duktape.Buffer, Node.js Buffer, and Khronos/ES6 TypedArray built-ins
+ */
+
+#include "duk_internal.h"
+
+/*
+ *  Misc helpers
+ */
+
+#if defined(DUK_USE_BUFFEROBJECT_SUPPORT)
+/* Map DUK_HBUFFEROBJECT_ELEM_xxx to duk_hobject class number.
+ * Sync with duk_hbufferobject.h and duk_hobject.h.
+ */
+static const duk_uint8_t duk__buffer_class_from_elemtype[9] = {
+	DUK_HOBJECT_CLASS_UINT8ARRAY,
+	DUK_HOBJECT_CLASS_UINT8CLAMPEDARRAY,
+	DUK_HOBJECT_CLASS_INT8ARRAY,
+	DUK_HOBJECT_CLASS_UINT16ARRAY,
+	DUK_HOBJECT_CLASS_INT16ARRAY,
+	DUK_HOBJECT_CLASS_UINT32ARRAY,
+	DUK_HOBJECT_CLASS_INT32ARRAY,
+	DUK_HOBJECT_CLASS_FLOAT32ARRAY,
+	DUK_HOBJECT_CLASS_FLOAT64ARRAY
+};
+#endif  /* DUK_USE_BUFFEROBJECT_SUPPORT */
+
+#if defined(DUK_USE_BUFFEROBJECT_SUPPORT)
+/* Map DUK_HBUFFEROBJECT_ELEM_xxx to prototype object built-in index.
+ * Sync with duk_hbufferobject.h.
+ */
+static const duk_uint8_t duk__buffer_proto_from_elemtype[9] = {
+	DUK_BIDX_UINT8ARRAY_PROTOTYPE,
+	DUK_BIDX_UINT8CLAMPEDARRAY_PROTOTYPE,
+	DUK_BIDX_INT8ARRAY_PROTOTYPE,
+	DUK_BIDX_UINT16ARRAY_PROTOTYPE,
+	DUK_BIDX_INT16ARRAY_PROTOTYPE,
+	DUK_BIDX_UINT32ARRAY_PROTOTYPE,
+	DUK_BIDX_INT32ARRAY_PROTOTYPE,
+	DUK_BIDX_FLOAT32ARRAY_PROTOTYPE,
+	DUK_BIDX_FLOAT64ARRAY_PROTOTYPE
+};
+#endif  /* DUK_USE_BUFFEROBJECT_SUPPORT */
+
+#if defined(DUK_USE_BUFFEROBJECT_SUPPORT)
+/* Map DUK__FLX_xxx to byte size.
+ */
+static const duk_uint8_t duk__buffer_nbytes_from_fldtype[6] = {
+	1,  /* DUK__FLD_8BIT */
+	2,  /* DUK__FLD_16BIT */
+	4,  /* DUK__FLD_32BIT */
+	4,  /* DUK__FLD_FLOAT */
+	8,  /* DUK__FLD_DOUBLE */
+	0   /* DUK__FLD_VARINT; not relevant here */
+};
+#endif  /* DUK_USE_BUFFEROBJECT_SUPPORT */
+
+#if defined(DUK_USE_BUFFEROBJECT_SUPPORT)
+/* Bitfield for each DUK_HBUFFEROBJECT_ELEM_xxx indicating which element types
+ * are compatible with a blind byte copy for the TypedArray set() method (also
+ * used for TypedArray constructor).  Array index is target buffer elem type,
+ * bitfield indicates compatible source types.  The types must have same byte
+ * size and they must be coercion compatible.
+ */
+static duk_uint16_t duk__buffer_elemtype_copy_compatible[9] = {
+	/* xxx -> DUK_HBUFFEROBJECT_ELEM_UINT8 */
+	(1U << DUK_HBUFFEROBJECT_ELEM_UINT8) |
+		(1U << DUK_HBUFFEROBJECT_ELEM_UINT8CLAMPED) |
+		(1U << DUK_HBUFFEROBJECT_ELEM_INT8),
+
+	/* xxx -> DUK_HBUFFEROBJECT_ELEM_UINT8CLAMPED
+	 * Note: INT8 is -not- copy compatible, e.g. -1 would coerce to 0x00.
+	 */
+	(1U << DUK_HBUFFEROBJECT_ELEM_UINT8) |
+		(1U << DUK_HBUFFEROBJECT_ELEM_UINT8CLAMPED),
+
+	/* xxx -> DUK_HBUFFEROBJECT_ELEM_INT8 */
+	(1U << DUK_HBUFFEROBJECT_ELEM_UINT8) |
+		(1U << DUK_HBUFFEROBJECT_ELEM_UINT8CLAMPED) |
+		(1U << DUK_HBUFFEROBJECT_ELEM_INT8),
+
+	/* xxx -> DUK_HBUFFEROBJECT_ELEM_UINT16 */
+	(1U << DUK_HBUFFEROBJECT_ELEM_UINT16) |
+		(1U << DUK_HBUFFEROBJECT_ELEM_INT16),
+
+	/* xxx -> DUK_HBUFFEROBJECT_ELEM_INT16 */
+	(1U << DUK_HBUFFEROBJECT_ELEM_UINT16) |
+		(1U << DUK_HBUFFEROBJECT_ELEM_INT16),
+
+	/* xxx -> DUK_HBUFFEROBJECT_ELEM_UINT32 */
+	(1U << DUK_HBUFFEROBJECT_ELEM_UINT32) |
+		(1U << DUK_HBUFFEROBJECT_ELEM_INT32),
+
+	/* xxx -> DUK_HBUFFEROBJECT_ELEM_INT32 */
+	(1U << DUK_HBUFFEROBJECT_ELEM_UINT32) |
+		(1U << DUK_HBUFFEROBJECT_ELEM_INT32),
+
+	/* xxx -> DUK_HBUFFEROBJECT_ELEM_FLOAT32 */
+	(1U << DUK_HBUFFEROBJECT_ELEM_FLOAT32),
+
+	/* xxx -> DUK_HBUFFEROBJECT_ELEM_FLOAT64 */
+	(1U << DUK_HBUFFEROBJECT_ELEM_FLOAT64)
+};
+#endif  /* DUK_USE_BUFFEROBJECT_SUPPORT */
+
+#if defined(DUK_USE_BUFFEROBJECT_SUPPORT)
+/* Shared helper. */
+DUK_LOCAL duk_hbufferobject *duk__getrequire_bufobj_this(duk_context *ctx, duk_bool_t throw_flag) {
+	duk_hthread *thr;
+	duk_tval *tv;
+	duk_hbufferobject *h_this;
+
+	DUK_ASSERT(ctx != NULL);
+	thr = (duk_hthread *) ctx;
+
+	tv = duk_get_borrowed_this_tval(ctx);
+	DUK_ASSERT(tv != NULL);
+	if (DUK_TVAL_IS_OBJECT(tv)) {
+		h_this = (duk_hbufferobject *) DUK_TVAL_GET_OBJECT(tv);
+		DUK_ASSERT(h_this != NULL);
+		if (DUK_HOBJECT_IS_BUFFEROBJECT((duk_hobject *) h_this)) {
+			DUK_ASSERT_HBUFFEROBJECT_VALID(h_this);
+			return h_this;
+		}
+	}
+
+	if (throw_flag) {
+		DUK_ERROR_TYPE(thr, DUK_STR_NOT_BUFFER);
+	}
+	return NULL;
+}
+#endif  /* DUK_USE_BUFFEROBJECT_SUPPORT */
+
+#if defined(DUK_USE_BUFFEROBJECT_SUPPORT)
+/* Check that 'this' is a duk_hbufferobject and return a pointer to it. */
+DUK_LOCAL duk_hbufferobject *duk__get_bufobj_this(duk_context *ctx) {
+	return duk__getrequire_bufobj_this(ctx, 0);
+}
+#endif  /* DUK_USE_BUFFEROBJECT_SUPPORT */
+
+#if defined(DUK_USE_BUFFEROBJECT_SUPPORT)
+/* Check that 'this' is a duk_hbufferobject and return a pointer to it
+ * (NULL if not).
+ */
+DUK_LOCAL duk_hbufferobject *duk__require_bufobj_this(duk_context *ctx) {
+	return duk__getrequire_bufobj_this(ctx, 1);
+}
+#endif  /* DUK_USE_BUFFEROBJECT_SUPPORT */
+
+#if defined(DUK_USE_BUFFEROBJECT_SUPPORT)
+/* Check that value is a duk_hbufferobject and return a pointer to it. */
+DUK_LOCAL duk_hbufferobject *duk__require_bufobj_value(duk_context *ctx, duk_idx_t index) {
+	duk_hthread *thr;
+	duk_tval *tv;
+	duk_hbufferobject *h_obj;
+
+	thr = (duk_hthread *) ctx;
+
+	/* Don't accept relative indices now. */
+	DUK_ASSERT(index >= 0);
+
+	tv = duk_require_tval(ctx, index);
+	DUK_ASSERT(tv != NULL);
+	if (DUK_TVAL_IS_OBJECT(tv)) {
+		h_obj = (duk_hbufferobject *) DUK_TVAL_GET_OBJECT(tv);
+		DUK_ASSERT(h_obj != NULL);
+		if (DUK_HOBJECT_IS_BUFFEROBJECT((duk_hobject *) h_obj)) {
+			DUK_ASSERT_HBUFFEROBJECT_VALID(h_obj);
+			return h_obj;
+		}
+	}
+
+	DUK_ERROR_TYPE(thr, DUK_STR_NOT_BUFFER);
+	return NULL;  /* not reachable */
+}
+#endif  /* DUK_USE_BUFFEROBJECT_SUPPORT */
+
+DUK_LOCAL void duk__set_bufobj_buffer(duk_context *ctx, duk_hbufferobject *h_bufobj, duk_hbuffer *h_val) {
+	duk_hthread *thr;
+
+	thr = (duk_hthread *) ctx;
+	DUK_UNREF(thr);
+
+	DUK_ASSERT(ctx != NULL);
+	DUK_ASSERT(h_bufobj != NULL);
+	DUK_ASSERT(h_bufobj->buf == NULL);  /* no need to decref */
+	DUK_ASSERT(h_val != NULL);
+	DUK_ASSERT_HBUFFEROBJECT_VALID(h_bufobj);
+
+	h_bufobj->buf = h_val;
+	DUK_HBUFFER_INCREF(thr, h_val);
+	h_bufobj->length = (duk_uint_t) DUK_HBUFFER_GET_SIZE(h_val);
+	DUK_ASSERT(h_bufobj->shift == 0);
+	DUK_ASSERT(h_bufobj->elem_type == DUK_HBUFFEROBJECT_ELEM_UINT8);
+
+	DUK_ASSERT_HBUFFEROBJECT_VALID(h_bufobj);
+}
+
+#if defined(DUK_USE_BUFFEROBJECT_SUPPORT)
+DUK_LOCAL duk_hbufferobject *duk__push_arraybuffer_with_length(duk_context *ctx, duk_uint_t len) {
+	duk_hbuffer *h_val;
+	duk_hbufferobject *h_bufobj;
+
+	(void) duk_push_fixed_buffer(ctx, (duk_size_t) len);
+	h_val = (duk_hbuffer *) duk_get_hbuffer(ctx, -1);
+	DUK_ASSERT(h_val != NULL);
+
+	h_bufobj = duk_push_bufferobject_raw(ctx,
+	                                     DUK_HOBJECT_FLAG_EXTENSIBLE |
+	                                     DUK_HOBJECT_FLAG_BUFFEROBJECT |
+	                                     DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_ARRAYBUFFER),
+	                                     DUK_BIDX_ARRAYBUFFER_PROTOTYPE);
+	DUK_ASSERT(h_bufobj != NULL);
+
+	duk__set_bufobj_buffer(ctx, h_bufobj, h_val);
+	DUK_ASSERT_HBUFFEROBJECT_VALID(h_bufobj);
+
+	return h_bufobj;
+}
+#endif  /* DUK_USE_BUFFEROBJECT_SUPPORT */
+
+#if defined(DUK_USE_BUFFEROBJECT_SUPPORT)
+/* Shared offset/length coercion helper. */
+DUK_LOCAL void duk__resolve_offset_opt_length(duk_context *ctx,
+                                              duk_hbufferobject *h_bufarg,
+                                              duk_idx_t idx_offset,
+                                              duk_idx_t idx_length,
+                                              duk_uint_t *out_offset,
+                                              duk_uint_t *out_length,
+                                              duk_bool_t throw_flag) {
+	duk_hthread *thr;
+	duk_int_t offset_signed;
+	duk_int_t length_signed;
+	duk_uint_t offset;
+	duk_uint_t length;
+
+	thr = (duk_hthread *) ctx;
+	DUK_UNREF(thr);
+
+	offset_signed = duk_to_int(ctx, idx_offset);
+	if (offset_signed < 0) {
+		goto fail_range;
+	}
+	offset = (duk_uint_t) offset_signed;
+	if (offset > h_bufarg->length) {
+		goto fail_range;
+	}
+	DUK_ASSERT_DISABLE(offset >= 0);  /* unsigned */
+	DUK_ASSERT(offset <= h_bufarg->length);
+
+	if (duk_is_undefined(ctx, idx_length)) {
+		DUK_ASSERT(h_bufarg->length >= offset);
+		length = h_bufarg->length - offset;  /* >= 0 */
+	} else {
+		length_signed = duk_to_int(ctx, idx_length);
+		if (length_signed < 0) {
+			goto fail_range;
+		}
+		length = (duk_uint_t) length_signed;
+		DUK_ASSERT(h_bufarg->length >= offset);
+		if (length > h_bufarg->length - offset) {
+			/* Unlike for negative arguments, some call sites
+			 * want length to be clamped if it's positive.
+			 */
+			if (throw_flag) {
+				goto fail_range;
+			} else {
+				length = h_bufarg->length - offset;
+			}
+		}
+	}
+	DUK_ASSERT_DISABLE(length >= 0);  /* unsigned */
+	DUK_ASSERT(offset + length <= h_bufarg->length);
+
+	*out_offset = offset;
+	*out_length = length;
+	return;
+
+ fail_range:
+	DUK_ERROR_RANGE(thr, DUK_STR_INVALID_CALL_ARGS);
+}
+#endif  /* DUK_USE_BUFFEROBJECT_SUPPORT */
+
+#if defined(DUK_USE_BUFFEROBJECT_SUPPORT)
+/* Shared lenient buffer length clamping helper.  No negative indices, no
+ * element/byte shifting.
+ */
+DUK_LOCAL void duk__clamp_startend_nonegidx_noshift(duk_context *ctx,
+                                                    duk_hbufferobject *h_bufobj,
+                                                    duk_idx_t idx_start,
+                                                    duk_idx_t idx_end,
+                                                    duk_int_t *out_start_offset,
+                                                    duk_int_t *out_end_offset) {
+	duk_int_t buffer_length;
+	duk_int_t start_offset;
+	duk_int_t end_offset;
+
+	DUK_ASSERT(out_start_offset != NULL);
+	DUK_ASSERT(out_end_offset != NULL);
+
+	buffer_length = (duk_int_t) h_bufobj->length;
+
+	/* undefined coerces to zero which is correct */
+	start_offset = duk_to_int_clamped(ctx, idx_start, 0, buffer_length);
+	if (duk_is_undefined(ctx, idx_end)) {
+		end_offset = buffer_length;
+	} else {
+		end_offset = duk_to_int_clamped(ctx, idx_end, start_offset, buffer_length);
+	}
+
+	DUK_ASSERT(start_offset >= 0);
+	DUK_ASSERT(start_offset <= buffer_length);
+	DUK_ASSERT(end_offset >= 0);
+	DUK_ASSERT(end_offset <= buffer_length);
+	DUK_ASSERT(start_offset <= end_offset);
+
+	*out_start_offset = start_offset;
+	*out_end_offset = end_offset;
+}
+#endif  /* DUK_USE_BUFFEROBJECT_SUPPORT */
+
+#if defined(DUK_USE_BUFFEROBJECT_SUPPORT)
+/* Shared lenient buffer length clamping helper.  Indices are treated as
+ * element indices (though output values are byte offsets) which only
+ * really matters for TypedArray views as other buffer object have a zero
+ * shift.  Negative indices are counted from end of input slice; crossed
+ * indices are clamped to zero length; and final indices are clamped
+ * against input slice.  Used for e.g. ArrayBuffer slice().
+ */
+DUK_LOCAL void duk__clamp_startend_negidx_shifted(duk_context *ctx,
+                                                  duk_hbufferobject *h_bufobj,
+                                                  duk_idx_t idx_start,
+                                                  duk_idx_t idx_end,
+                                                  duk_int_t *out_start_offset,
+                                                  duk_int_t *out_end_offset) {
+	duk_int_t buffer_length;
+	duk_int_t start_offset;
+	duk_int_t end_offset;
+
+	DUK_ASSERT(out_start_offset != NULL);
+	DUK_ASSERT(out_end_offset != NULL);
+
+	buffer_length = (duk_int_t) h_bufobj->length;
+	buffer_length >>= h_bufobj->shift;  /* as elements */
+
+	/* Resolve start/end offset as element indices first; arguments
+	 * at idx_start/idx_end are element offsets.  Working with element
+	 * indices first also avoids potential for wrapping.
+	 */
+
+	start_offset = duk_to_int(ctx, idx_start);
+	if (start_offset < 0) {
+		start_offset = buffer_length + start_offset;
+	}
+	if (duk_is_undefined(ctx, idx_end)) {
+		end_offset = buffer_length;
+	} else {
+		end_offset = duk_to_int(ctx, idx_end);
+		if (end_offset < 0) {
+			end_offset = buffer_length + end_offset;
+		}
+	}
+	/* Note: start_offset/end_offset can still be < 0 here. */
+
+	if (start_offset < 0) {
+		start_offset = 0;
+	} else if (start_offset > buffer_length) {
+		start_offset = buffer_length;
+	}
+	if (end_offset < start_offset) {
+		end_offset = start_offset;
+	} else if (end_offset > buffer_length) {
+		end_offset = buffer_length;
+	}
+	DUK_ASSERT(start_offset >= 0);
+	DUK_ASSERT(start_offset <= buffer_length);
+	DUK_ASSERT(end_offset >= 0);
+	DUK_ASSERT(end_offset <= buffer_length);
+	DUK_ASSERT(start_offset <= end_offset);
+
+	/* Convert indices to byte offsets. */
+	start_offset <<= h_bufobj->shift;
+	end_offset <<= h_bufobj->shift;
+
+	*out_start_offset = start_offset;
+	*out_end_offset = end_offset;
+}
+#endif  /* DUK_USE_BUFFEROBJECT_SUPPORT */
+
+/*
+ *  Indexed read/write helpers (also used from outside this file)
+ */
+
+DUK_INTERNAL void duk_hbufferobject_push_validated_read(duk_context *ctx, duk_hbufferobject *h_bufobj, duk_uint8_t *p, duk_small_uint_t elem_size) {
+	duk_double_union du;
+
+	DUK_MEMCPY((void *) du.uc, (const void *) p, (size_t) elem_size);
+
+	switch (h_bufobj->elem_type) {
+	case DUK_HBUFFEROBJECT_ELEM_UINT8:
+#if defined(DUK_USE_BUFFEROBJECT_SUPPORT)
+	case DUK_HBUFFEROBJECT_ELEM_UINT8CLAMPED:
+#endif
+		duk_push_uint(ctx, (duk_uint_t) du.uc[0]);
+		break;
+#if defined(DUK_USE_BUFFEROBJECT_SUPPORT)
+	/* These are not needed when only Duktape.Buffer is supported. */
+	case DUK_HBUFFEROBJECT_ELEM_INT8:
+		duk_push_int(ctx, (duk_int_t) (duk_int8_t) du.uc[0]);
+		break;
+	case DUK_HBUFFEROBJECT_ELEM_UINT16:
+		duk_push_uint(ctx, (duk_uint_t) du.us[0]);
+		break;
+	case DUK_HBUFFEROBJECT_ELEM_INT16:
+		duk_push_int(ctx, (duk_int_t) (duk_int16_t) du.us[0]);
+		break;
+	case DUK_HBUFFEROBJECT_ELEM_UINT32:
+		duk_push_uint(ctx, (duk_uint_t) du.ui[0]);
+		break;
+	case DUK_HBUFFEROBJECT_ELEM_INT32:
+		duk_push_int(ctx, (duk_int_t) (duk_int32_t) du.ui[0]);
+		break;
+	case DUK_HBUFFEROBJECT_ELEM_FLOAT32:
+		duk_push_number(ctx, (duk_double_t) du.f[0]);
+		break;
+	case DUK_HBUFFEROBJECT_ELEM_FLOAT64:
+		duk_push_number(ctx, (duk_double_t) du.d);
+		break;
+#endif  /* DUK_USE_BUFFEROBJECT_SUPPORT */
+	default:
+		DUK_UNREACHABLE();
+	}
+}
+
+DUK_INTERNAL void duk_hbufferobject_validated_write(duk_context *ctx, duk_hbufferobject *h_bufobj, duk_uint8_t *p, duk_small_uint_t elem_size) {
+	duk_double_union du;
+
+	/* NOTE! Caller must ensure that any side effects from the
+	 * coercions below are safe.  If that cannot be guaranteed
+	 * (which is normally the case), caller must coerce the
+	 * argument using duk_to_number() before any pointer
+	 * validations; the result of duk_to_number() always coerces
+	 * without side effects here.
+	 */
+
+	switch (h_bufobj->elem_type) {
+	case DUK_HBUFFEROBJECT_ELEM_UINT8:
+		du.uc[0] = (duk_uint8_t) duk_to_uint32(ctx, -1);
+		break;
+#if defined(DUK_USE_BUFFEROBJECT_SUPPORT)
+	/* These are not needed when only Duktape.Buffer is supported. */
+	case DUK_HBUFFEROBJECT_ELEM_UINT8CLAMPED:
+		du.uc[0] = (duk_uint8_t) duk_to_uint8clamped(ctx, -1);
+		break;
+	case DUK_HBUFFEROBJECT_ELEM_INT8:
+		du.uc[0] = (duk_uint8_t) duk_to_int32(ctx, -1);
+		break;
+	case DUK_HBUFFEROBJECT_ELEM_UINT16:
+		du.us[0] = (duk_uint16_t) duk_to_uint32(ctx, -1);
+		break;
+	case DUK_HBUFFEROBJECT_ELEM_INT16:
+		du.us[0] = (duk_uint16_t) duk_to_int32(ctx, -1);
+		break;
+	case DUK_HBUFFEROBJECT_ELEM_UINT32:
+		du.ui[0] = (duk_uint32_t) duk_to_uint32(ctx, -1);
+		break;
+	case DUK_HBUFFEROBJECT_ELEM_INT32:
+		du.ui[0] = (duk_uint32_t) duk_to_int32(ctx, -1);
+		break;
+	case DUK_HBUFFEROBJECT_ELEM_FLOAT32:
+		du.f[0] = (duk_float_t) duk_to_number(ctx, -1);
+		break;
+	case DUK_HBUFFEROBJECT_ELEM_FLOAT64:
+		du.d = (duk_double_t) duk_to_number(ctx, -1);
+		break;
+#endif  /* DUK_USE_BUFFEROBJECT_SUPPORT */
+	default:
+		DUK_UNREACHABLE();
+	}
+
+	DUK_MEMCPY((void *) p, (const void *) du.uc, (size_t) elem_size);
+}
+
+/*
+ *  Duktape.Buffer: constructor
+ */
+
+DUK_INTERNAL duk_ret_t duk_bi_buffer_constructor(duk_context *ctx) {
+	duk_hthread *thr;
+	duk_size_t buf_size;
+	duk_small_int_t buf_dynamic;
+	duk_uint8_t *buf_data;
+	const duk_uint8_t *src_data;
+
+	thr = (duk_hthread *) ctx;
+	DUK_UNREF(thr);
+
+	/*
+	 *  Constructor arguments are currently somewhat compatible with
+	 *  (keep it that way if possible):
+	 *
+	 *    http://nodejs.org/api/buffer.html
+	 *
+	 *  Note that the ToBuffer() coercion (duk_to_buffer()) does NOT match
+	 *  the constructor behavior.
+	 */
+
+	buf_dynamic = duk_get_boolean(ctx, 1);  /* default to false */
+
+	switch (duk_get_type(ctx, 0)) {
+	case DUK_TYPE_NUMBER: {
+		/* new buffer of specified size */
+		buf_size = (duk_size_t) duk_to_int(ctx, 0);
+		(void) duk_push_buffer(ctx, buf_size, buf_dynamic);
+		break;
+	}
+	case DUK_TYPE_BUFFER: {
+		/* return input buffer, converted to a Duktape.Buffer object
+		 * if called as a constructor (no change if called as a
+		 * function).
+		 */
+		duk_set_top(ctx, 1);
+		break;
+	}
+	case DUK_TYPE_STRING: {
+		/* new buffer with string contents */
+		src_data = (const duk_uint8_t *) duk_get_lstring(ctx, 0, &buf_size);
+		DUK_ASSERT(src_data != NULL);  /* even for zero-length string */
+		buf_data = (duk_uint8_t *) duk_push_buffer(ctx, buf_size, buf_dynamic);
+		DUK_MEMCPY((void *) buf_data, (const void *) src_data, (size_t) buf_size);
+		break;
+	}
+	case DUK_TYPE_OBJECT: {
+		/* For all duk_hbufferobjects, get the plain buffer inside
+		 * without making a copy.  This is compatible with Duktape 1.2
+		 * but means that a slice/view information is ignored and the
+		 * full underlying buffer is returned.
+		 *
+		 * If called as a constructor, a new Duktape.Buffer object
+		 * pointing to the same plain buffer is created below.
+		 */
+		duk_hbufferobject *h_bufobj;
+		h_bufobj = (duk_hbufferobject *) duk_get_hobject(ctx, 0);
+		DUK_ASSERT(h_bufobj != NULL);
+		if (!DUK_HOBJECT_IS_BUFFEROBJECT((duk_hobject *) h_bufobj)) {
+			return DUK_RET_TYPE_ERROR;
+		}
+		if (h_bufobj->buf == NULL) {
+			return DUK_RET_TYPE_ERROR;
+		}
+		duk_push_hbuffer(ctx, h_bufobj->buf);
+		break;
+	}
+	case DUK_TYPE_NONE:
+	default: {
+		return DUK_RET_TYPE_ERROR;
+	}
+	}
+	DUK_ASSERT(duk_is_buffer(ctx, -1));
+
+	/* stack is unbalanced, but: [ <something> buf ] */
+
+	if (duk_is_constructor_call(ctx)) {
+		duk_hbufferobject *h_bufobj;
+		duk_hbuffer *h_val;
+
+		h_val = duk_get_hbuffer(ctx, -1);
+		DUK_ASSERT(h_val != NULL);
+
+		h_bufobj = duk_push_bufferobject_raw(ctx,
+		                                     DUK_HOBJECT_FLAG_EXTENSIBLE |
+		                                     DUK_HOBJECT_FLAG_BUFFEROBJECT |
+		                                     DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_BUFFER),
+		                                     DUK_BIDX_BUFFER_PROTOTYPE);
+		DUK_ASSERT(h_bufobj != NULL);
+
+		duk__set_bufobj_buffer(ctx, h_bufobj, h_val);
+
+		DUK_ASSERT_HBUFFEROBJECT_VALID(h_bufobj);
+	}
+	/* Note: unbalanced stack on purpose */
+
+	return 1;
+}
+
+/*
+ *  Node.js Buffer: constructor
+ */
+
+#if defined(DUK_USE_BUFFEROBJECT_SUPPORT)
+DUK_INTERNAL duk_ret_t duk_bi_nodejs_buffer_constructor(duk_context *ctx) {
+	/* Internal class is Object: Object.prototype.toString.call(new Buffer(0))
+	 * prints "[object Object]".
+	 */
+	duk_int_t len;
+	duk_int_t i;
+	duk_hbuffer *h_buf;
+	duk_hbufferobject *h_bufobj;
+	duk_size_t buf_size;
+
+	switch (duk_get_type(ctx, 0)) {
+	case DUK_TYPE_BUFFER: {
+		/* Custom behavior: plain buffer is used as internal buffer
+		 * without making a copy (matches Duktape.Buffer).
+		 */
+		duk_set_top(ctx, 1);  /* -> [ buffer ] */
+		break;
+	}
+	case DUK_TYPE_NUMBER: {
+		len = duk_to_int_clamped(ctx, 0, 0, DUK_INT_MAX);
+		(void) duk_push_fixed_buffer(ctx, (duk_size_t) len);
+		break;
+	}
+	case DUK_TYPE_OBJECT: {
+		duk_uint8_t *buf;
+
+		(void) duk_get_prop_string(ctx, 0, "length");
+		len = duk_to_int_clamped(ctx, -1, 0, DUK_INT_MAX);
+		duk_pop(ctx);
+		buf = (duk_uint8_t *) duk_push_fixed_buffer(ctx, (duk_size_t) len);
+		for (i = 0; i < len; i++) {
+			/* XXX: fast path for array arguments? */
+			duk_get_prop_index(ctx, 0, (duk_uarridx_t) i);
+			buf[i] = (duk_uint8_t) (duk_to_uint32(ctx, -1) & 0xffU);
+			duk_pop(ctx);
+		}
+		break;
+	}
+	case DUK_TYPE_STRING: {
+		/* ignore encoding for now */
+		duk_dup(ctx, 0);
+		(void) duk_to_buffer(ctx, -1, &buf_size);
+		break;
+	}
+	default:
+		return DUK_RET_TYPE_ERROR;
+	}
+
+	DUK_ASSERT(duk_is_buffer(ctx, -1));
+	h_buf = duk_get_hbuffer(ctx, -1);
+	DUK_ASSERT(h_buf != NULL);
+
+	h_bufobj = duk_push_bufferobject_raw(ctx,
+	                                     DUK_HOBJECT_FLAG_EXTENSIBLE |
+	                                     DUK_HOBJECT_FLAG_BUFFEROBJECT |
+	                                     DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_BUFFER),
+	                                     DUK_BIDX_NODEJS_BUFFER_PROTOTYPE);
+	DUK_ASSERT(h_bufobj != NULL);
+
+	h_bufobj->buf = h_buf;
+	DUK_HBUFFER_INCREF(thr, h_buf);
+	DUK_ASSERT(h_bufobj->offset == 0);
+	h_bufobj->length = (duk_int_t) DUK_HBUFFER_GET_SIZE(h_buf);
+	DUK_ASSERT(h_bufobj->elem_type == DUK_HBUFFEROBJECT_ELEM_UINT8);
+
+	DUK_ASSERT_HBUFFEROBJECT_VALID(h_bufobj);
+
+	return 1;
+}
+#else  /* DUK_USE_BUFFEROBJECT_SUPPORT */
+DUK_INTERNAL duk_ret_t duk_bi_nodejs_buffer_constructor(duk_context *ctx) {
+	DUK_UNREF(ctx);
+	return DUK_RET_UNSUPPORTED_ERROR;
+}
+#endif  /* DUK_USE_BUFFEROBJECT_SUPPORT */
+
+/*
+ *  ArrayBuffer, DataView, and TypedArray constructors
+ */
+
+#if defined(DUK_USE_BUFFEROBJECT_SUPPORT)
+DUK_INTERNAL duk_ret_t duk_bi_arraybuffer_constructor(duk_context *ctx) {
+	duk_hthread *thr;
+	duk_hbufferobject *h_bufobj;
+	duk_hbuffer *h_val;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+	thr = (duk_hthread *) ctx;
+	DUK_UNREF(thr);
+
+	/* XXX: function flag to make this automatic? */
+	if (!duk_is_constructor_call(ctx)) {
+		return DUK_RET_TYPE_ERROR;
+	}
+
+	if (duk_is_buffer(ctx, 0)) {
+		/* Custom behavior: plain buffer is used as internal buffer
+		 * without making a copy (matches Duktape.Buffer).
+		 */
+
+		h_val = duk_get_hbuffer(ctx, 0);
+		DUK_ASSERT(h_val != NULL);
+
+		/* XXX: accept any duk_hbufferobject type as an input also? */
+	} else {
+		duk_int_t len;
+		len = duk_to_int(ctx, 0);
+		if (len < 0) {
+			goto fail_length;
+		}
+		(void) duk_push_fixed_buffer(ctx, (duk_size_t) len);
+		h_val = (duk_hbuffer *) duk_get_hbuffer(ctx, -1);
+		DUK_ASSERT(h_val != NULL);
+
+#if !defined(DUK_USE_ZERO_BUFFER_DATA)
+		/* Khronos/ES6 requires zeroing even when DUK_USE_ZERO_BUFFER_DATA
+		 * is not set.
+		 */
+		DUK_ASSERT(!DUK_HBUFFER_HAS_DYNAMIC((duk_hbuffer *) h_val));
+		DUK_MEMZERO((void *) DUK_HBUFFER_FIXED_GET_DATA_PTR(thr->heap, h_val), (duk_size_t) len);
+#endif
+	}
+
+	h_bufobj = duk_push_bufferobject_raw(ctx,
+	                                     DUK_HOBJECT_FLAG_EXTENSIBLE |
+	                                     DUK_HOBJECT_FLAG_BUFFEROBJECT |
+	                                     DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_ARRAYBUFFER),
+	                                     DUK_BIDX_ARRAYBUFFER_PROTOTYPE);
+	DUK_ASSERT(h_bufobj != NULL);
+
+	duk__set_bufobj_buffer(ctx, h_bufobj, h_val);
+	DUK_ASSERT_HBUFFEROBJECT_VALID(h_bufobj);
+
+	return 1;
+
+ fail_length:
+	return DUK_RET_RANGE_ERROR;
+}
+#else  /* DUK_USE_BUFFEROBJECT_SUPPORT */
+DUK_INTERNAL duk_ret_t duk_bi_arraybuffer_constructor(duk_context *ctx) {
+	DUK_UNREF(ctx);
+	return DUK_RET_UNSUPPORTED_ERROR;
+}
+#endif  /* DUK_USE_BUFFEROBJECT_SUPPORT */
+
+
+/* Format of magic, bits:
+ *   0...1: elem size shift (0-3)
+ *   2...5: elem type (DUK_HBUFFEROBJECT_ELEM_xxx)
+ */
+
+#if defined(DUK_USE_BUFFEROBJECT_SUPPORT)
+DUK_INTERNAL duk_ret_t duk_bi_typedarray_constructor(duk_context *ctx) {
+	duk_hthread *thr;
+	duk_tval *tv;
+	duk_hobject *h_obj;
+	duk_hbufferobject *h_bufobj = NULL;
+	duk_hbufferobject *h_bufarr = NULL;
+	duk_hbufferobject *h_bufarg = NULL;
+	duk_hbuffer *h_val;
+	duk_small_uint_t magic;
+	duk_small_uint_t shift;
+	duk_small_uint_t elem_type;
+	duk_small_uint_t elem_size;
+	duk_small_uint_t class_num;
+	duk_small_uint_t proto_bidx;
+	duk_uint_t align_mask;
+	duk_uint_t elem_length;
+	duk_int_t elem_length_signed;
+	duk_uint_t byte_length;
+	duk_small_uint_t copy_mode;
+
+	thr = (duk_hthread *) ctx;
+	DUK_UNREF(thr);
+
+	/* XXX: function flag to make this automatic? */
+	if (!duk_is_constructor_call(ctx)) {
+		return DUK_RET_TYPE_ERROR;
+	}
+
+	/* We could fit built-in index into magic but that'd make the magic
+	 * number dependent on built-in numbering (genbuiltins.py doesn't
+	 * handle that yet).  So map both class and prototype from the
+	 * element type.
+	 */
+	magic = duk_get_current_magic(ctx);
+	shift = magic & 0x03;               /* bits 0...1: shift */
+	elem_type = (magic >> 2) & 0x0f;    /* bits 2...5: type */
+	elem_size = 1 << shift;
+	align_mask = elem_size - 1;
+	DUK_ASSERT(elem_type < sizeof(duk__buffer_proto_from_elemtype) / sizeof(duk_uint8_t));
+	proto_bidx = duk__buffer_proto_from_elemtype[elem_type];
+	DUK_ASSERT(proto_bidx < DUK_NUM_BUILTINS);
+	DUK_ASSERT(elem_type < sizeof(duk__buffer_class_from_elemtype) / sizeof(duk_uint8_t));
+	class_num = duk__buffer_class_from_elemtype[elem_type];
+
+	DUK_DD(DUK_DDPRINT("typedarray constructor, magic=%d, shift=%d, elem_type=%d, "
+	                   "elem_size=%d, proto_bidx=%d, class_num=%d",
+	                   (int) magic, (int) shift, (int) elem_type, (int) elem_size,
+	                   (int) proto_bidx, (int) class_num));
+
+	/* Argument variants.  When the argument is an ArrayBuffer a view to
+	 * the same buffer is created; otherwise a new ArrayBuffer is always
+	 * created.
+	 */
+
+	tv = duk_get_tval(ctx, 0);
+	DUK_ASSERT(tv != NULL);  /* arg count */
+	if (DUK_TVAL_IS_OBJECT(tv)) {
+		h_obj = DUK_TVAL_GET_OBJECT(tv);
+		DUK_ASSERT(h_obj != NULL);
+
+		if (DUK_HOBJECT_GET_CLASS_NUMBER(h_obj) == DUK_HOBJECT_CLASS_ARRAYBUFFER) {
+			/* ArrayBuffer: unlike any other argument variant, create
+			 * a view into the existing buffer.
+			 */
+
+			duk_int_t byte_offset_signed;
+			duk_uint_t byte_offset;
+
+			h_bufarg = (duk_hbufferobject *) h_obj;
+
+			byte_offset_signed = duk_to_int(ctx, 1);
+			if (byte_offset_signed < 0) {
+				goto fail_arguments;
+			}
+			byte_offset = (duk_uint_t) byte_offset_signed;
+			if (byte_offset > h_bufarg->length ||
+			    (byte_offset & align_mask) != 0) {
+				/* Must be >= 0 and multiple of element size. */
+				goto fail_arguments;
+			}
+			if (duk_is_undefined(ctx, 2)) {
+				DUK_ASSERT(h_bufarg->length >= byte_offset);
+				byte_length = h_bufarg->length - byte_offset;
+				if ((byte_length & align_mask) != 0) {
+					/* Must be element size multiple from
+					 * start offset to end of buffer.
+					 */
+					goto fail_arguments;
+				}
+				elem_length = (byte_length >> shift);
+			} else {
+				elem_length_signed = duk_to_int(ctx, 2);
+				if (elem_length_signed < 0) {
+					goto fail_arguments;
+				}
+				elem_length = (duk_uint_t) elem_length_signed;
+				byte_length = elem_length << shift;
+				if ((byte_length >> shift) != elem_length) {
+					/* Byte length would overflow. */
+					/* XXX: easier check with less code? */
+					goto fail_arguments;
+				}
+				DUK_ASSERT(h_bufarg->length >= byte_offset);
+				if (byte_length > h_bufarg->length - byte_offset) {
+					/* Not enough data. */
+					goto fail_arguments;
+				}
+			}
+			DUK_UNREF(elem_length);
+			DUK_ASSERT_DISABLE(byte_offset >= 0);
+			DUK_ASSERT(byte_offset <= h_bufarg->length);
+			DUK_ASSERT_DISABLE(byte_length >= 0);
+			DUK_ASSERT(byte_offset + byte_length <= h_bufarg->length);
+			DUK_ASSERT((elem_length << shift) == byte_length);
+
+			h_bufobj = duk_push_bufferobject_raw(ctx,
+			                                     DUK_HOBJECT_FLAG_EXTENSIBLE |
+			                                     DUK_HOBJECT_FLAG_BUFFEROBJECT |
+			                                     DUK_HOBJECT_CLASS_AS_FLAGS(class_num),
+			                                     proto_bidx);
+			h_val = h_bufarg->buf;
+			if (h_val == NULL) {
+				return DUK_RET_TYPE_ERROR;
+			}
+			h_bufobj->buf = h_val;
+			DUK_HBUFFER_INCREF(thr, h_val);
+			h_bufobj->offset = h_bufarg->offset + byte_offset;
+			h_bufobj->length = byte_length;
+			h_bufobj->shift = (duk_uint8_t) shift;
+			h_bufobj->elem_type = (duk_uint8_t) elem_type;
+			h_bufobj->is_view = 1;
+			DUK_ASSERT_HBUFFEROBJECT_VALID(h_bufobj);
+
+			/* Set .buffer to the argument ArrayBuffer. */
+			duk_dup(ctx, 0);
+			duk_xdef_prop_stridx(ctx, -2, DUK_STRIDX_LC_BUFFER, DUK_PROPDESC_FLAGS_NONE);
+			duk_compact(ctx, -1);
+			return 1;
+		} else if (DUK_HOBJECT_IS_BUFFEROBJECT(h_obj)) {
+			/* TypedArray (or other non-ArrayBuffer duk_hbufferobject).
+			 * Conceptually same behavior as for an Array-like argument,
+			 * with a few fast paths.
+			 */
+
+			h_bufarg = (duk_hbufferobject *) h_obj;
+			DUK_ASSERT_HBUFFEROBJECT_VALID(h_bufarg);
+			elem_length_signed = (duk_int_t) (h_bufarg->length >> h_bufarg->shift);
+			if (h_bufarg->buf == NULL) {
+				return DUK_RET_TYPE_ERROR;
+			}
+
+			/* Select copy mode.  Must take into account element
+			 * compatibility and validity of the underlying source
+			 * buffer.
+			 */
+
+			DUK_DDD(DUK_DDDPRINT("selecting copy mode for bufobj arg, "
+			                     "src byte_length=%ld, src shift=%d, "
+			                     "src/dst elem_length=%ld; "
+			                     "dst shift=%d -> dst byte_length=%ld",
+			                     (long) h_bufarg->length, (int) h_bufarg->shift,
+			                     (long) elem_length_signed, (int) shift,
+			                     (long) (elem_length_signed << shift)));
+
+			copy_mode = 2;  /* default is explicit index read/write copy */
+			DUK_ASSERT(elem_type < sizeof(duk__buffer_elemtype_copy_compatible) / sizeof(duk_uint16_t));
+			if (DUK_HBUFFEROBJECT_VALID_SLICE(h_bufarg)) {
+				if ((duk__buffer_elemtype_copy_compatible[elem_type] & (1 << h_bufarg->elem_type)) != 0) {
+					DUK_DDD(DUK_DDDPRINT("source/target are copy compatible, memcpy"));
+					DUK_ASSERT(shift == h_bufarg->shift);  /* byte sizes will match */
+					copy_mode = 0;
+				} else {
+					DUK_DDD(DUK_DDDPRINT("source/target not copy compatible but valid, fast copy"));
+					copy_mode = 1;
+				}
+			}
+		} else {
+			/* Array or Array-like */
+			elem_length_signed = (duk_int_t) duk_get_length(ctx, 0);
+			copy_mode = 2;
+		}
+	} else if (DUK_TVAL_IS_BUFFER(tv)) {
+		/* Accept plain buffer values like array initializers
+		 * (new in Duktape 1.4.0).
+		 */
+		duk_hbuffer *h_srcbuf;
+		h_srcbuf = DUK_TVAL_GET_BUFFER(tv);
+		elem_length_signed = (duk_int_t) DUK_HBUFFER_GET_SIZE(h_srcbuf);
+		copy_mode = 2;  /* XXX: could add fast path for u8 compatible views */
+	} else {
+		/* Non-object argument is simply int coerced, matches
+		 * V8 behavior (except for "null", which we coerce to
+		 * 0 but V8 TypeErrors).
+		 */
+		elem_length_signed = duk_to_int(ctx, 0);
+		copy_mode = 3;
+	}
+	if (elem_length_signed < 0) {
+		goto fail_arguments;
+	}
+	elem_length = (duk_uint_t) elem_length_signed;
+	byte_length = (duk_uint_t) (elem_length << shift);
+	if ((byte_length >> shift) != elem_length) {
+		/* Byte length would overflow. */
+		/* XXX: easier check with less code? */
+		goto fail_arguments;
+	}
+
+	DUK_DDD(DUK_DDDPRINT("elem_length=%ld, byte_length=%ld",
+	                     (long) elem_length, (long) byte_length));
+
+	/* ArrayBuffer argument is handled specially above; the rest of the
+	 * argument variants are handled by shared code below.
+	 */
+
+	/* Push a new ArrayBuffer (becomes view .buffer) */
+	h_bufarr = duk__push_arraybuffer_with_length(ctx, byte_length);
+	DUK_ASSERT(h_bufarr != NULL);
+	h_val = h_bufarr->buf;
+	DUK_ASSERT(h_val != NULL);
+
+	/* Push the resulting view object and attach the ArrayBuffer. */
+	h_bufobj = duk_push_bufferobject_raw(ctx,
+	                                     DUK_HOBJECT_FLAG_EXTENSIBLE |
+	                                     DUK_HOBJECT_FLAG_BUFFEROBJECT |
+	                                     DUK_HOBJECT_CLASS_AS_FLAGS(class_num),
+	                                     proto_bidx);
+
+	h_bufobj->buf = h_val;
+	DUK_HBUFFER_INCREF(thr, h_val);
+	DUK_ASSERT(h_bufobj->offset == 0);
+	h_bufobj->length = byte_length;
+	h_bufobj->shift = (duk_uint8_t) shift;
+	h_bufobj->elem_type = (duk_uint8_t) elem_type;
+	h_bufobj->is_view = 1;
+	DUK_ASSERT_HBUFFEROBJECT_VALID(h_bufobj);
+
+	/* Set .buffer */
+	duk_dup(ctx, -2);
+	duk_xdef_prop_stridx(ctx, -2, DUK_STRIDX_LC_BUFFER, DUK_PROPDESC_FLAGS_NONE);
+	duk_compact(ctx, -1);
+
+	/* Copy values, the copy method depends on the arguments.
+	 *
+	 * Copy mode decision may depend on the validity of the underlying
+	 * buffer of the source argument; there must be no harmful side effects
+	 * from there to here for copy_mode to still be valid.
+	 */
+	DUK_DDD(DUK_DDDPRINT("copy mode: %d", (int) copy_mode));
+	switch (copy_mode) {
+	case 0: {
+		/* Use byte copy. */
+
+		duk_uint8_t *p_src;
+		duk_uint8_t *p_dst;
+
+		DUK_ASSERT(h_bufobj != NULL);
+		DUK_ASSERT(h_bufobj->buf != NULL);
+		DUK_ASSERT(DUK_HBUFFEROBJECT_VALID_SLICE(h_bufobj));
+		DUK_ASSERT(h_bufarg != NULL);
+		DUK_ASSERT(h_bufarg->buf != NULL);
+		DUK_ASSERT(DUK_HBUFFEROBJECT_VALID_SLICE(h_bufarg));
+
+		p_dst = DUK_HBUFFEROBJECT_GET_SLICE_BASE(thr->heap, h_bufobj);
+		p_src = DUK_HBUFFEROBJECT_GET_SLICE_BASE(thr->heap, h_bufarg);
+
+		DUK_DDD(DUK_DDDPRINT("using memcpy: p_src=%p, p_dst=%p, byte_length=%ld",
+		                     (void *) p_src, (void *) p_dst, (long) byte_length));
+
+		DUK_MEMCPY((void *) p_dst, (const void *) p_src, (size_t) byte_length);
+		break;
+	}
+	case 1: {
+		/* Copy values through direct validated reads and writes. */
+
+		duk_small_uint_t src_elem_size;
+		duk_small_uint_t dst_elem_size;
+		duk_uint8_t *p_src;
+		duk_uint8_t *p_src_end;
+		duk_uint8_t *p_dst;
+
+		DUK_ASSERT(h_bufobj != NULL);
+		DUK_ASSERT(h_bufobj->buf != NULL);
+		DUK_ASSERT(DUK_HBUFFEROBJECT_VALID_SLICE(h_bufobj));
+		DUK_ASSERT(h_bufarg != NULL);
+		DUK_ASSERT(h_bufarg->buf != NULL);
+		DUK_ASSERT(DUK_HBUFFEROBJECT_VALID_SLICE(h_bufarg));
+
+		src_elem_size = 1 << h_bufarg->shift;
+		dst_elem_size = elem_size;
+
+		p_src = DUK_HBUFFEROBJECT_GET_SLICE_BASE(thr->heap, h_bufarg);
+		p_dst = DUK_HBUFFEROBJECT_GET_SLICE_BASE(thr->heap, h_bufobj);
+		p_src_end = p_src + h_bufarg->length;
+
+		DUK_DDD(DUK_DDDPRINT("using fast copy: p_src=%p, p_src_end=%p, p_dst=%p, "
+		                     "src_elem_size=%d, dst_elem_size=%d",
+		                     (void *) p_src, (void *) p_src_end, (void *) p_dst,
+		                     (int) src_elem_size, (int) dst_elem_size));
+
+		while (p_src != p_src_end) {
+			DUK_DDD(DUK_DDDPRINT("fast path per element copy loop: "
+			                     "p_src=%p, p_src_end=%p, p_dst=%p",
+			                     (void *) p_src, (void *) p_src_end, (void *) p_dst));
+			/* A validated read() is always a number, so it's write coercion
+			 * is always side effect free an won't invalidate pointers etc.
+			 */
+			duk_hbufferobject_push_validated_read(ctx, h_bufarg, p_src, src_elem_size);
+			duk_hbufferobject_validated_write(ctx, h_bufobj, p_dst, dst_elem_size);
+			duk_pop(ctx);
+			p_src += src_elem_size;
+			p_dst += dst_elem_size;
+		}
+		break;
+	}
+	case 2: {
+		/* Copy values by index reads and writes.  Let virtual
+		 * property handling take care of coercion.
+		 */
+		duk_uint_t i;
+
+		DUK_DDD(DUK_DDDPRINT("using slow copy"));
+
+		for (i = 0; i < elem_length; i++) {
+			duk_get_prop_index(ctx, 0, (duk_uarridx_t) i);
+			duk_put_prop_index(ctx, -2, (duk_uarridx_t) i);
+		}
+		break;
+	}
+	default:
+	case 3: {
+		/* No copy, leave zero bytes in the buffer.  There's no
+		 * ambiguity with Float32/Float64 because zero bytes also
+		 * represent 0.0.
+		 */
+#if !defined(DUK_USE_ZERO_BUFFER_DATA)
+		/* Khronos/ES6 requires zeroing even when DUK_USE_ZERO_BUFFER_DATA
+		 * is not set.
+		 */
+		DUK_ASSERT(!DUK_HBUFFER_HAS_DYNAMIC((duk_hbuffer *) h_val));
+		DUK_MEMZERO((void *) DUK_HBUFFER_FIXED_GET_DATA_PTR(thr->heap, h_val), (duk_size_t) byte_length);
+#endif
+
+		DUK_DDD(DUK_DDDPRINT("using no copy"));
+		break;
+	}
+	}
+
+	return 1;
+
+ fail_arguments:
+	return DUK_RET_RANGE_ERROR;
+}
+#else  /* DUK_USE_BUFFEROBJECT_SUPPORT */
+DUK_INTERNAL duk_ret_t duk_bi_typedarray_constructor(duk_context *ctx) {
+	DUK_UNREF(ctx);
+	return DUK_RET_UNSUPPORTED_ERROR;
+}
+#endif  /* DUK_USE_BUFFEROBJECT_SUPPORT */
+
+#if defined(DUK_USE_BUFFEROBJECT_SUPPORT)
+DUK_INTERNAL duk_ret_t duk_bi_dataview_constructor(duk_context *ctx) {
+	duk_hbufferobject *h_bufarg;
+	duk_hbufferobject *h_bufobj;
+	duk_hbuffer *h_val;
+	duk_uint_t offset;
+	duk_uint_t length;
+
+	/* XXX: function flag to make this automatic? */
+	if (!duk_is_constructor_call(ctx)) {
+		return DUK_RET_TYPE_ERROR;
+	}
+
+	h_bufarg = duk__require_bufobj_value(ctx, 0);
+	DUK_ASSERT(h_bufarg != NULL);
+
+	duk__resolve_offset_opt_length(ctx, h_bufarg, 1, 2, &offset, &length, 1 /*throw_flag*/);
+	DUK_ASSERT(offset <= h_bufarg->length);
+	DUK_ASSERT(offset + length <= h_bufarg->length);
+
+	h_bufobj = duk_push_bufferobject_raw(ctx,
+	                                     DUK_HOBJECT_FLAG_EXTENSIBLE |
+	                                     DUK_HOBJECT_FLAG_BUFFEROBJECT |
+	                                     DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_DATAVIEW),
+	                                     DUK_BIDX_DATAVIEW_PROTOTYPE);
+
+	h_val = h_bufarg->buf;
+	if (h_val == NULL) {
+		return DUK_RET_TYPE_ERROR;
+	}
+	h_bufobj->buf = h_val;
+	DUK_HBUFFER_INCREF(thr, h_val);
+	h_bufobj->offset = h_bufarg->offset + offset;
+	h_bufobj->length = length;
+	DUK_ASSERT(h_bufobj->shift == 0);
+	DUK_ASSERT(h_bufobj->elem_type == DUK_HBUFFEROBJECT_ELEM_UINT8);
+	h_bufobj->is_view = 1;
+
+	/* The DataView .buffer property is ordinarily set to the argument
+	 * which is an ArrayBuffer.  We accept any duk_hbufferobject as
+	 * an argument and .buffer will be set to the argument regardless
+	 * of what it is.  This may be a bit confusing if the argument
+	 * is e.g. a DataView or another TypedArray view.
+	 *
+	 * XXX: Copy .buffer property from a DataView/TypedArray argument?
+	 * Create a fresh ArrayBuffer for Duktape.Buffer and Node.js Buffer
+	 * arguments?  See: test-bug-dataview-buffer-prop.js.
+	 */
+
+	duk_dup(ctx, 0);
+	duk_xdef_prop_stridx(ctx, -2, DUK_STRIDX_LC_BUFFER, DUK_PROPDESC_FLAGS_NONE);
+	duk_compact(ctx, -1);
+
+	DUK_ASSERT_HBUFFEROBJECT_VALID(h_bufobj);
+	return 1;
+}
+#else  /* DUK_USE_BUFFEROBJECT_SUPPORT */
+DUK_INTERNAL duk_ret_t duk_bi_dataview_constructor(duk_context *ctx) {
+	DUK_UNREF(ctx);
+	return DUK_RET_UNSUPPORTED_ERROR;
+}
+#endif  /* DUK_USE_BUFFEROBJECT_SUPPORT */
+
+/*
+ *  ArrayBuffer.isView()
+ */
+
+#if defined(DUK_USE_BUFFEROBJECT_SUPPORT)
+DUK_INTERNAL duk_ret_t duk_bi_arraybuffer_isview(duk_context *ctx) {
+	duk_hobject *h_obj;
+	duk_bool_t ret = 0;
+
+	h_obj = duk_get_hobject(ctx, 0);
+	if (h_obj != NULL && DUK_HOBJECT_IS_BUFFEROBJECT(h_obj)) {
+		ret = ((duk_hbufferobject *) h_obj)->is_view;
+	}
+	duk_push_boolean(ctx, ret);
+	return 1;
+}
+#else  /* DUK_USE_BUFFEROBJECT_SUPPORT */
+DUK_INTERNAL duk_ret_t duk_bi_arraybuffer_isview(duk_context *ctx) {
+	DUK_UNREF(ctx);
+	return DUK_RET_UNSUPPORTED_ERROR;
+}
+#endif  /* DUK_USE_BUFFEROBJECT_SUPPORT */
+
+/*
+ *  Node.js Buffer: toString([encoding], [start], [end])
+ */
+
+#if defined(DUK_USE_BUFFEROBJECT_SUPPORT)
+DUK_INTERNAL duk_ret_t duk_bi_nodejs_buffer_tostring(duk_context *ctx) {
+	duk_hthread *thr;
+	duk_hbufferobject *h_this;
+	duk_int_t start_offset, end_offset;
+	duk_uint8_t *buf_slice;
+	duk_size_t slice_length;
+
+	thr = (duk_hthread *) ctx;
+	DUK_UNREF(thr);
+
+	h_this = duk__get_bufobj_this(ctx);
+	if (h_this == NULL) {
+		/* XXX: happens e.g. when evaluating: String(Buffer.prototype). */
+		duk_push_string(ctx, "[object Object]");
+		return 1;
+	}
+	DUK_ASSERT_HBUFFEROBJECT_VALID(h_this);
+
+	/* ignore encoding for now */
+
+	duk__clamp_startend_nonegidx_noshift(ctx, h_this, 1 /*idx_start*/, 2 /*idx_end*/, &start_offset, &end_offset);
+
+	slice_length = (duk_size_t) (end_offset - start_offset);
+	buf_slice = (duk_uint8_t *) duk_push_fixed_buffer(ctx, slice_length);
+	DUK_ASSERT(buf_slice != NULL);
+
+	if (h_this->buf == NULL) {
+		goto type_error;
+	}
+
+	if (DUK_HBUFFEROBJECT_VALID_BYTEOFFSET_EXCL(h_this, start_offset + slice_length)) {
+		DUK_MEMCPY((void *) buf_slice,
+		           (const void *) (DUK_HBUFFEROBJECT_GET_SLICE_BASE(thr->heap, h_this) + start_offset),
+		           (size_t) slice_length);
+	} else {
+		/* not covered, return all zeroes */
+		;
+	}
+
+	duk_to_string(ctx, -1);
+	return 1;
+
+ type_error:
+	return DUK_RET_TYPE_ERROR;
+}
+#else  /* DUK_USE_BUFFEROBJECT_SUPPORT */
+DUK_INTERNAL duk_ret_t duk_bi_nodejs_buffer_tostring(duk_context *ctx) {
+	DUK_UNREF(ctx);
+	return DUK_RET_UNSUPPORTED_ERROR;
+}
+#endif  /* DUK_USE_BUFFEROBJECT_SUPPORT */
+
+/*
+ *  Duktape.Buffer: toString(), valueOf()
+ */
+
+#if defined(DUK_USE_BUFFEROBJECT_SUPPORT)
+DUK_INTERNAL duk_ret_t duk_bi_buffer_prototype_tostring_shared(duk_context *ctx) {
+	duk_hthread *thr;
+	duk_tval *tv;
+	duk_small_int_t to_string = duk_get_current_magic(ctx);
+
+	thr = (duk_hthread *) ctx;
+	DUK_UNREF(thr);
+
+	tv = duk_get_borrowed_this_tval(ctx);
+	DUK_ASSERT(tv != NULL);
+
+	if (DUK_TVAL_IS_BUFFER(tv)) {
+		duk_hbuffer *h_buf;
+		h_buf = DUK_TVAL_GET_BUFFER(tv);
+		DUK_ASSERT(h_buf != NULL);
+		duk_push_hbuffer(ctx, h_buf);
+	} else if (DUK_TVAL_IS_OBJECT(tv)) {
+		duk_hobject *h;
+		duk_hbufferobject *h_bufobj;
+
+		/* Accept any duk_hbufferobject, though we're only normally
+		 * called for Duktape.Buffer values.
+		 */
+		h = DUK_TVAL_GET_OBJECT(tv);
+		DUK_ASSERT(h != NULL);
+		if (!DUK_HOBJECT_IS_BUFFEROBJECT(h)) {
+			DUK_DD(DUK_DDPRINT("toString/valueOf() called for a non-bufferobject object"));
+			goto type_error;
+		}
+		h_bufobj = (duk_hbufferobject *) h;
+		DUK_ASSERT_HBUFFEROBJECT_VALID(h_bufobj);
+
+		if (h_bufobj->buf == NULL) {
+			DUK_DD(DUK_DDPRINT("toString/valueOf() called for a bufferobject with NULL buf"));
+			goto type_error;
+		}
+		duk_push_hbuffer(ctx, h_bufobj->buf);
+	} else {
+		goto type_error;
+	}
+
+	if (to_string) {
+		duk_to_string(ctx, -1);
+	}
+	return 1;
+
+ type_error:
+	return DUK_RET_TYPE_ERROR;
+}
+#else  /* DUK_USE_BUFFEROBJECT_SUPPORT */
+DUK_INTERNAL duk_ret_t duk_bi_buffer_prototype_tostring_shared(duk_context *ctx) {
+	DUK_UNREF(ctx);
+	return DUK_RET_UNSUPPORTED_ERROR;
+}
+#endif  /* DUK_USE_BUFFEROBJECT_SUPPORT */
+
+/*
+ *  Node.js Buffer.prototype: toJSON()
+ */
+
+#if defined(DUK_USE_BUFFEROBJECT_SUPPORT)
+DUK_INTERNAL duk_ret_t duk_bi_nodejs_buffer_tojson(duk_context *ctx) {
+	duk_hthread *thr;
+	duk_hbufferobject *h_this;
+	duk_uint8_t *buf;
+	duk_uint_t i;
+
+	thr = (duk_hthread *) ctx;
+	DUK_UNREF(thr);
+	h_this = duk__require_bufobj_this(ctx);
+	DUK_ASSERT(h_this != NULL);
+
+	if (h_this->buf == NULL || !DUK_HBUFFEROBJECT_VALID_SLICE(h_this)) {
+		/* Serialize uncovered backing buffer as a null; doesn't
+		 * really matter as long we're memory safe.
+		 */
+		duk_push_null(ctx);
+		return 1;
+	}
+
+	duk_push_object(ctx);
+	duk_push_hstring_stridx(ctx, DUK_STRIDX_UC_BUFFER);
+	duk_put_prop_stridx(ctx, -2, DUK_STRIDX_TYPE);
+
+	duk_push_array(ctx);
+	for (i = 0; i < h_this->length; i++) {
+		/* XXX: regetting the pointer may be overkill - we're writing
+		 * to a side-effect free array here.
+		 */
+		DUK_ASSERT(h_this->buf != NULL);
+		buf = DUK_HBUFFEROBJECT_GET_SLICE_BASE(thr->heap, h_this);
+		duk_push_uint(ctx, (duk_uint_t) buf[i]);
+		duk_put_prop_index(ctx, -2, (duk_idx_t) i);
+	}
+	duk_put_prop_stridx(ctx, -2, DUK_STRIDX_DATA);
+
+	return 1;
+}
+#else  /* DUK_USE_BUFFEROBJECT_SUPPORT */
+DUK_INTERNAL duk_ret_t duk_bi_nodejs_buffer_tojson(duk_context *ctx) {
+	DUK_UNREF(ctx);
+	return DUK_RET_UNSUPPORTED_ERROR;
+}
+#endif  /* DUK_USE_BUFFEROBJECT_SUPPORT */
+
+/*
+ *  Node.js Buffer.prototype.equals()
+ *  Node.js Buffer.prototype.compare()
+ *  Node.js Buffer.compare()
+ */
+
+#if defined(DUK_USE_BUFFEROBJECT_SUPPORT)
+DUK_INTERNAL duk_ret_t duk_bi_buffer_compare_shared(duk_context *ctx) {
+	duk_hthread *thr;
+	duk_small_uint_t magic;
+	duk_hbufferobject *h_bufarg1;
+	duk_hbufferobject *h_bufarg2;
+	duk_small_int_t comp_res;
+
+	thr = (duk_hthread *) ctx;
+	DUK_UNREF(thr);
+
+	magic = duk_get_current_magic(ctx);
+	if (magic & 0x02) {
+		/* Static call style. */
+		h_bufarg1 = duk__require_bufobj_value(ctx, 0);
+		h_bufarg2 = duk__require_bufobj_value(ctx, 1);
+	} else {
+		h_bufarg1 = duk__require_bufobj_this(ctx);
+		h_bufarg2 = duk__require_bufobj_value(ctx, 0);
+	}
+	DUK_ASSERT(h_bufarg1 != NULL);
+	DUK_ASSERT(h_bufarg2 != NULL);
+
+	/* We want to compare the slice/view areas of the arguments.
+	 * If either slice/view is invalid (underlying buffer is shorter)
+	 * ensure equals() is false, but otherwise the only thing that
+	 * matters is to be memory safe.
+	 */
+
+	if (DUK_HBUFFEROBJECT_VALID_SLICE(h_bufarg1) &&
+	    DUK_HBUFFEROBJECT_VALID_SLICE(h_bufarg2)) {
+		comp_res = duk_js_data_compare((const duk_uint8_t *) DUK_HBUFFER_GET_DATA_PTR(thr->heap, h_bufarg1->buf) + h_bufarg1->offset,
+		                               (const duk_uint8_t *) DUK_HBUFFER_GET_DATA_PTR(thr->heap, h_bufarg2->buf) + h_bufarg2->offset,
+		                               (duk_size_t) h_bufarg1->length,
+		                               (duk_size_t) h_bufarg2->length);
+	} else {
+		comp_res = -1;  /* either nonzero value is ok */
+	}
+
+	if (magic & 0x01) {
+		/* compare: similar to string comparison but for buffer data. */
+		duk_push_int(ctx, comp_res);
+	} else {
+		/* equals */
+		duk_push_boolean(ctx, (comp_res == 0));
+	}
+
+	return 1;
+}
+#else  /* DUK_USE_BUFFEROBJECT_SUPPORT */
+DUK_INTERNAL duk_ret_t duk_bi_buffer_compare_shared(duk_context *ctx) {
+	DUK_UNREF(ctx);
+	return DUK_RET_UNSUPPORTED_ERROR;
+}
+#endif  /* DUK_USE_BUFFEROBJECT_SUPPORT */
+
+/*
+ *  Node.js Buffer.prototype.fill()
+ */
+
+#if defined(DUK_USE_BUFFEROBJECT_SUPPORT)
+DUK_INTERNAL duk_ret_t duk_bi_nodejs_buffer_fill(duk_context *ctx) {
+	duk_hthread *thr;
+	duk_hbufferobject *h_this;
+	const duk_uint8_t *fill_str_ptr;
+	duk_size_t fill_str_len;
+	duk_uint8_t fill_value;
+	duk_int_t fill_offset;
+	duk_int_t fill_end;
+	duk_size_t fill_length;
+	duk_uint8_t *p;
+
+	thr = (duk_hthread *) ctx;
+	DUK_UNREF(thr);
+
+	h_this = duk__require_bufobj_this(ctx);
+	DUK_ASSERT(h_this != NULL);
+	if (h_this->buf == NULL) {
+		return DUK_RET_TYPE_ERROR;
+	}
+
+	/* [ value offset end ] */
+
+	if (duk_is_string(ctx, 0)) {
+		fill_str_ptr = (const duk_uint8_t *) duk_get_lstring(ctx, 0, &fill_str_len);
+		DUK_ASSERT(fill_str_ptr != NULL);
+	} else {
+		fill_value = (duk_uint8_t) duk_to_uint32(ctx, 0);
+		fill_str_ptr = (const duk_uint8_t *) &fill_value;
+		fill_str_len = 1;
+	}
+
+	/* Fill offset handling is more lenient than in Node.js. */
+
+	duk__clamp_startend_nonegidx_noshift(ctx, h_this, 1 /*idx_start*/, 2 /*idx_end*/, &fill_offset, &fill_end);
+
+	DUK_DDD(DUK_DDDPRINT("fill: fill_value=%02x, fill_offset=%ld, fill_end=%ld, view length=%ld",
+	                     (unsigned int) fill_value, (long) fill_offset, (long) fill_end, (long) h_this->length));
+
+	DUK_ASSERT(fill_end - fill_offset >= 0);
+	DUK_ASSERT(h_this->buf != NULL);
+
+	p = (DUK_HBUFFEROBJECT_GET_SLICE_BASE(thr->heap, h_this) + fill_offset);
+	fill_length = (duk_size_t) (fill_end - fill_offset);
+	if (fill_str_len == 1) {
+		/* Handle single character fills as memset() even when
+		 * the fill data comes from a one-char argument.
+		 */
+		DUK_MEMSET((void *) p, (int) fill_str_ptr[0], (size_t) fill_length);
+	} else if (fill_str_len > 1) {
+		duk_size_t i, n, t;
+
+		for (i = 0, n = (fill_end - fill_offset), t = 0; i < n; i++) {
+			p[i] = fill_str_ptr[t++];
+			if (t >= fill_str_len) {
+				t = 0;
+			}
+		}
+	} else {
+		DUK_DDD(DUK_DDDPRINT("zero size fill pattern, ignore silently"));
+	}
+
+	/* Return the Buffer to allow chaining: b.fill(0x11).fill(0x22, 3, 5).toString() */
+	duk_push_this(ctx);
+	return 1;
+}
+#else  /* DUK_USE_BUFFEROBJECT_SUPPORT */
+DUK_INTERNAL duk_ret_t duk_bi_nodejs_buffer_fill(duk_context *ctx) {
+	DUK_UNREF(ctx);
+	return DUK_RET_UNSUPPORTED_ERROR;
+}
+#endif  /* DUK_USE_BUFFEROBJECT_SUPPORT */
+
+/*
+ *  Node.js Buffer.prototype.write(string, [offset], [length], [encoding])
+ */
+
+#if defined(DUK_USE_BUFFEROBJECT_SUPPORT)
+DUK_INTERNAL duk_ret_t duk_bi_nodejs_buffer_write(duk_context *ctx) {
+	duk_hthread *thr;
+	duk_hbufferobject *h_this;
+	duk_uint_t offset;
+	duk_uint_t length;
+	const duk_uint8_t *str_data;
+	duk_size_t str_len;
+
+	thr = (duk_hthread *) ctx;
+	DUK_UNREF(thr);
+
+	h_this = duk__require_bufobj_this(ctx);
+	DUK_ASSERT(h_this != NULL);
+
+	/* Argument must be a string, e.g. a buffer is not allowed. */
+	str_data = (const duk_uint8_t *) duk_require_lstring(ctx, 0, &str_len);
+
+	duk__resolve_offset_opt_length(ctx, h_this, 1, 2, &offset, &length, 0 /*throw_flag*/);
+	DUK_ASSERT(offset <= h_this->length);
+	DUK_ASSERT(offset + length <= h_this->length);
+
+	/* XXX: encoding is ignored now. */
+
+	if (length > str_len) {
+		length = (duk_uint_t) str_len;
+	}
+
+	if (DUK_HBUFFEROBJECT_VALID_SLICE(h_this)) {
+		/* Cannot overlap. */
+		DUK_MEMCPY((void *) (DUK_HBUFFEROBJECT_GET_SLICE_BASE(thr->heap, h_this) + offset),
+		           (const void *) str_data,
+		           (size_t) length);
+	} else {
+		DUK_DDD(DUK_DDDPRINT("write() target buffer is not covered, silent ignore"));
+	}
+
+	duk_push_uint(ctx, length);
+	return 1;
+}
+#else  /* DUK_USE_BUFFEROBJECT_SUPPORT */
+DUK_INTERNAL duk_ret_t duk_bi_nodejs_buffer_write(duk_context *ctx) {
+	DUK_UNREF(ctx);
+	return DUK_RET_UNSUPPORTED_ERROR;
+}
+#endif  /* DUK_USE_BUFFEROBJECT_SUPPORT */
+
+/*
+ *  Node.js Buffer.prototype.copy()
+ */
+
+#if defined(DUK_USE_BUFFEROBJECT_SUPPORT)
+DUK_INTERNAL duk_ret_t duk_bi_nodejs_buffer_copy(duk_context *ctx) {
+	duk_hthread *thr;
+	duk_hbufferobject *h_this;
+	duk_hbufferobject *h_bufarg;
+	duk_int_t source_length;
+	duk_int_t target_length;
+	duk_int_t target_start, source_start, source_end;
+	duk_uint_t target_ustart, source_ustart, source_uend;
+	duk_uint_t copy_size = 0;
+
+	/* [ targetBuffer targetStart sourceStart sourceEnd ] */
+
+	thr = (duk_hthread *) ctx;
+	DUK_UNREF(thr);
+
+	h_this = duk__require_bufobj_this(ctx);
+	h_bufarg = duk__require_bufobj_value(ctx, 0);
+	DUK_ASSERT(h_this != NULL);
+	DUK_ASSERT(h_bufarg != NULL);
+	source_length = (duk_int_t) h_this->length;
+	target_length = (duk_int_t) h_bufarg->length;
+
+	target_start = duk_to_int(ctx, 1);
+	source_start = duk_to_int(ctx, 2);
+	if (duk_is_undefined(ctx, 3)) {
+		source_end = source_length;
+	} else {
+		source_end = duk_to_int(ctx, 3);
+	}
+
+	DUK_DDD(DUK_DDDPRINT("checking copy args: target_start=%ld, target_length=%ld, "
+	                     "source_start=%ld, source_end=%ld, source_length=%ld",
+	                     (long) target_start, (long) h_bufarg->length,
+	                     (long) source_start, (long) source_end, (long) source_length));
+
+	/* This behavior mostly mimics Node.js now. */
+
+	if (source_start < 0 || source_end < 0 || target_start < 0) {
+		/* Negative offsets cause a RangeError. */
+		goto fail_bounds;
+	}
+	source_ustart = (duk_uint_t) source_start;
+	source_uend = (duk_uint_t) source_end;
+	target_ustart = (duk_uint_t) target_start;
+	if (source_ustart >= source_uend ||  /* crossed offsets or zero size */
+	    source_ustart >= (duk_uint_t) source_length ||  /* source out-of-bounds (but positive) */
+	    target_ustart >= (duk_uint_t) target_length) {  /* target out-of-bounds (but positive) */
+		goto silent_ignore;
+	}
+	if (source_uend >= (duk_uint_t) source_length) {
+		/* Source end clamped silently to available length. */
+		source_uend = source_length;
+	}
+	copy_size = source_uend - source_ustart;
+	if (target_ustart + copy_size > (duk_uint_t) target_length) {
+		/* Clamp to target's end if too long.
+		 *
+		 * NOTE: there's no overflow possibility in the comparison;
+		 * both target_ustart and copy_size are >= 0 and based on
+		 * values in duk_int_t range.  Adding them as duk_uint_t
+		 * values is then guaranteed not to overflow.
+		 */
+		DUK_ASSERT(target_ustart + copy_size >= target_ustart);  /* no overflow */
+		DUK_ASSERT(target_ustart + copy_size >= copy_size);  /* no overflow */
+		copy_size = (duk_uint_t) target_length - target_ustart;
+	}
+
+	DUK_DDD(DUK_DDDPRINT("making copy: target_ustart=%lu source_ustart=%lu copy_size=%lu",
+	                     (unsigned long) target_ustart, (unsigned long) source_ustart,
+	                     (unsigned long) copy_size));
+
+	DUK_ASSERT(copy_size >= 1);
+	DUK_ASSERT(source_ustart <= (duk_uint_t) source_length);
+	DUK_ASSERT(source_ustart + copy_size <= (duk_uint_t) source_length);
+	DUK_ASSERT(target_ustart <= (duk_uint_t) target_length);
+	DUK_ASSERT(target_ustart + copy_size <= (duk_uint_t) target_length);
+
+	/* Ensure copy is covered by underlying buffers. */
+	DUK_ASSERT(h_bufarg->buf != NULL);  /* length check */
+	DUK_ASSERT(h_this->buf != NULL);    /* length check */
+	if (DUK_HBUFFEROBJECT_VALID_BYTEOFFSET_EXCL(h_bufarg, target_ustart + copy_size) &&
+	    DUK_HBUFFEROBJECT_VALID_BYTEOFFSET_EXCL(h_this, source_ustart + copy_size)) {
+		/* Must use memmove() because copy area may overlap (source and target
+		 * buffer may be the same, or from different slices.
+		 */
+		DUK_MEMMOVE((void *) (DUK_HBUFFEROBJECT_GET_SLICE_BASE(thr->heap, h_bufarg) + target_ustart),
+		            (const void *) (DUK_HBUFFEROBJECT_GET_SLICE_BASE(thr->heap, h_this) + source_ustart),
+		            (size_t) copy_size);
+	} else {
+		DUK_DDD(DUK_DDDPRINT("buffer copy not covered by underlying buffer(s), ignoring"));
+	}
+
+ silent_ignore:
+	/* Return value is like write(), number of bytes written.
+	 * The return value matters because of code like:
+	 * "off += buf.copy(...)".
+         */
+	duk_push_uint(ctx, copy_size);
+	return 1;
+
+ fail_bounds:
+	return DUK_RET_RANGE_ERROR;
+}
+#else  /* DUK_USE_BUFFEROBJECT_SUPPORT */
+DUK_INTERNAL duk_ret_t duk_bi_nodejs_buffer_copy(duk_context *ctx) {
+	DUK_UNREF(ctx);
+	return DUK_RET_UNSUPPORTED_ERROR;
+}
+#endif  /* DUK_USE_BUFFEROBJECT_SUPPORT */
+
+/*
+ *  TypedArray.prototype.set()
+ *
+ *  TypedArray set() is pretty interesting to implement because:
+ *
+ *    - The source argument may be a plain array or a typedarray.  If the
+ *      source is a TypedArray, values are decoded and re-encoded into the
+ *      target (not as a plain byte copy).  This may happen even when the
+ *      element byte size is the same, e.g. integer values may be re-encoded
+ *      into floats.
+ *
+ *    - Source and target may refer to the same underlying buffer, so that
+ *      the set() operation may overlap.  The specification requires that this
+ *      must work as if a copy was made before the operation.  Note that this
+ *      is NOT a simple memmove() situation because the source and target
+ *      byte sizes may be different -- e.g. a 4-byte source (Int8Array) may
+ *      expand to a 16-byte target (Uint32Array) so that the target overlaps
+ *      the source both from beginning and the end (unlike in typical memmove).
+ *
+ *    - Even if 'buf' pointers of the source and target differ, there's no
+ *      guarantee that their memory areas don't overlap.  This may be the
+ *      case with external buffers.
+ *
+ *  Even so, it is nice to optimize for the common case:
+ *
+ *    - Source and target separate buffers or non-overlapping.
+ *
+ *    - Source and target have a compatible type so that a plain byte copy
+ *      is possible.  Note that while e.g. uint8 and int8 are compatible
+ *      (coercion one way or another doesn't change the byte representation),
+ *      e.g. int8 and uint8clamped are NOT compatible when writing int8
+ *      values into uint8clamped typedarray (-1 would clamp to 0 for instance).
+ *
+ *  See test-bi-typedarray-proto-set.js.
+ */
+
+#if defined(DUK_USE_BUFFEROBJECT_SUPPORT)
+DUK_INTERNAL duk_ret_t duk_bi_typedarray_set(duk_context *ctx) {
+	duk_hthread *thr;
+	duk_hbufferobject *h_this;
+	duk_hobject *h_obj;
+	duk_uarridx_t i, n;
+	duk_int_t offset_signed;
+	duk_uint_t offset_elems;
+	duk_uint_t offset_bytes;
+
+	thr = (duk_hthread *) ctx;
+	DUK_UNREF(thr);
+
+	h_this = duk__require_bufobj_this(ctx);
+	DUK_ASSERT(h_this != NULL);
+	DUK_ASSERT_HBUFFEROBJECT_VALID(h_this);
+
+	if (h_this->buf == NULL) {
+		DUK_DDD(DUK_DDDPRINT("source neutered, skip copy"));
+		return 0;
+	}
+
+	h_obj = duk_require_hobject(ctx, 0);
+	DUK_ASSERT(h_obj != NULL);
+
+	/* XXX: V8 throws a TypeError for negative values.  Would it
+	 * be more useful to interpret negative offsets here from the
+	 * end of the buffer too?
+	 */
+	offset_signed = duk_to_int(ctx, 1);
+	if (offset_signed < 0) {
+		return DUK_RET_TYPE_ERROR;
+	}
+	offset_elems = (duk_uint_t) offset_signed;
+	offset_bytes = offset_elems << h_this->shift;
+	if ((offset_bytes >> h_this->shift) != offset_elems) {
+		/* Byte length would overflow. */
+		/* XXX: easier check with less code? */
+		return DUK_RET_RANGE_ERROR;
+	}
+	if (offset_bytes > h_this->length) {
+		/* Equality may be OK but >length not.  Checking
+		 * this explicitly avoids some overflow cases
+		 * below.
+		 */
+		return DUK_RET_RANGE_ERROR;
+	}
+	DUK_ASSERT(offset_bytes <= h_this->length);
+
+	/* Fast path: source is a TypedArray (or any bufferobject). */
+
+	if (DUK_HOBJECT_IS_BUFFEROBJECT(h_obj)) {
+		duk_hbufferobject *h_bufarg;
+		duk_uint16_t comp_mask;
+		duk_small_int_t no_overlap = 0;
+		duk_uint_t src_length;
+		duk_uint_t dst_length;
+		duk_uint_t dst_length_elems;
+		duk_uint8_t *p_src_base;
+		duk_uint8_t *p_src_end;
+		duk_uint8_t *p_src;
+		duk_uint8_t *p_dst_base;
+		duk_uint8_t *p_dst;
+		duk_small_uint_t src_elem_size;
+		duk_small_uint_t dst_elem_size;
+
+		h_bufarg = (duk_hbufferobject *) h_obj;
+		DUK_ASSERT_HBUFFEROBJECT_VALID(h_bufarg);
+
+		if (h_bufarg->buf == NULL) {
+			DUK_DDD(DUK_DDDPRINT("target neutered, skip copy"));
+			return 0;
+		}
+
+		/* Nominal size check. */
+		src_length = h_bufarg->length;  /* bytes in source */
+		dst_length_elems = (src_length >> h_bufarg->shift);  /* elems in source and dest */
+		dst_length = dst_length_elems << h_this->shift;  /* bytes in dest */
+		if ((dst_length >> h_this->shift) != dst_length_elems) {
+			/* Byte length would overflow. */
+			/* XXX: easier check with less code? */
+			return DUK_RET_RANGE_ERROR;
+		}
+		DUK_DDD(DUK_DDDPRINT("nominal size check: src_length=%ld, dst_length=%ld",
+		                     (long) src_length, (long) dst_length));
+		DUK_ASSERT(offset_bytes <= h_this->length);
+		if (dst_length > h_this->length - offset_bytes) {
+			/* Overflow not an issue because subtraction is used on the right
+			 * side and guaranteed to be >= 0.
+			 */
+			DUK_DDD(DUK_DDDPRINT("copy exceeds target buffer nominal length"));
+			return DUK_RET_RANGE_ERROR;
+		}
+		if (!DUK_HBUFFEROBJECT_VALID_BYTEOFFSET_EXCL(h_this, offset_bytes + dst_length)) {
+			DUK_DDD(DUK_DDDPRINT("copy not covered by underlying target buffer, ignore"));
+			return 0;
+		}
+
+		p_src_base = DUK_HBUFFEROBJECT_GET_SLICE_BASE(thr->heap, h_bufarg);
+		p_dst_base = DUK_HBUFFEROBJECT_GET_SLICE_BASE(thr->heap, h_this) + offset_bytes;
+
+		/* Check actual underlying buffers for validity and that they
+		 * cover the copy.  No side effects are allowed after the check
+		 * so that the validity status doesn't change.
+		 */
+		if (!DUK_HBUFFEROBJECT_VALID_SLICE(h_this) ||
+		    !DUK_HBUFFEROBJECT_VALID_SLICE(h_bufarg)) {
+			/* The condition could be more narrow and check for the
+			 * copy area only, but there's no need for fine grained
+			 * behavior when the underlying buffer is misconfigured.
+			 */
+			DUK_DDD(DUK_DDDPRINT("source and/or target not covered by underlying buffer, skip copy"));
+			return 0;
+		}
+
+		/* We want to do a straight memory copy if possible: this is
+		 * an important operation because .set() is the TypedArray
+		 * way to copy chunks of memory.  However, because set()
+		 * conceptually works in terms of elements, not all views are
+		 * compatible with direct byte copying.
+		 *
+		 * If we do manage a direct copy, the "overlap issue" handled
+		 * below can just be solved using memmove() because the source
+		 * and destination element sizes are necessarily equal.
+		 */
+
+		DUK_ASSERT(h_this->elem_type < sizeof(duk__buffer_elemtype_copy_compatible) / sizeof(duk_uint16_t));
+		comp_mask = duk__buffer_elemtype_copy_compatible[h_this->elem_type];
+		if (comp_mask & (1 << h_bufarg->elem_type)) {
+			DUK_ASSERT(src_length == dst_length);
+
+			DUK_DDD(DUK_DDDPRINT("fast path: able to use memmove() because views are compatible"));
+			DUK_MEMMOVE((void *) p_dst_base, (const void *) p_src_base, (size_t) dst_length);
+			return 0;
+		}
+		DUK_DDD(DUK_DDDPRINT("fast path: views are not compatible with a byte copy, copy by item"));
+
+		/* We want to avoid making a copy to process set() but that's
+		 * not always possible: the source and the target may overlap
+		 * and because element sizes are different, the overlap cannot
+		 * always be handled with a memmove() or choosing the copy
+		 * direction in a certain way.  For example, if source type is
+		 * uint8 and target type is uint32, the target area may exceed
+		 * the source area from both ends!
+		 *
+		 * Note that because external buffers may point to the same
+		 * memory areas, we must ultimately make this check using
+		 * pointers.
+		 *
+		 * NOTE: careful with side effects: any side effect may cause
+		 * a buffer resize (or external buffer pointer/length update)!
+		 */
+
+		DUK_DDD(DUK_DDDPRINT("overlap check: p_src_base=%p, src_length=%ld, "
+		                     "p_dst_base=%p, dst_length=%ld",
+		                     (void *) p_src_base, (long) src_length,
+		                     (void *) p_dst_base, (long) dst_length));
+
+		if (p_src_base >= p_dst_base + dst_length ||  /* source starts after dest ends */
+		    p_src_base + src_length <= p_dst_base) {   /* source ends before dest starts */
+			no_overlap = 1;
+		}
+
+		if (!no_overlap) {
+			/* There's overlap: the desired end result is that
+			 * conceptually a copy is made to avoid "trampling"
+			 * of source data by destination writes.  We make
+			 * an actual temporary copy to handle this case.
+			 */
+			duk_uint8_t *p_src_copy;
+
+			DUK_DDD(DUK_DDDPRINT("there is overlap, make a copy of the source"));
+			p_src_copy = (duk_uint8_t *) duk_push_fixed_buffer(ctx, src_length);
+			DUK_ASSERT(p_src_copy != NULL);
+			DUK_MEMCPY((void *) p_src_copy, (const void *) p_src_base, (size_t) src_length);
+
+			p_src_base = p_src_copy;  /* use p_src_base from now on */
+		}
+		/* Value stack intentionally mixed size here. */
+
+		DUK_DDD(DUK_DDDPRINT("after overlap check: p_src_base=%p, src_length=%ld, "
+		                     "p_dst_base=%p, dst_length=%ld, valstack top=%ld",
+		                     (void *) p_src_base, (long) src_length,
+		                     (void *) p_dst_base, (long) dst_length,
+		                     (long) duk_get_top(ctx)));
+
+		/* Ready to make the copy.  We must proceed element by element
+		 * and must avoid any side effects that might cause the buffer
+		 * validity check above to become invalid.
+		 *
+		 * Although we work through the value stack here, only plain
+		 * numbers are handled which should be side effect safe.
+		 */
+
+		src_elem_size = 1 << h_bufarg->shift;
+		dst_elem_size = 1 << h_this->shift;
+		p_src = p_src_base;
+		p_dst = p_dst_base;
+		p_src_end = p_src_base + src_length;
+
+		while (p_src != p_src_end) {
+			DUK_DDD(DUK_DDDPRINT("fast path per element copy loop: "
+			                     "p_src=%p, p_src_end=%p, p_dst=%p",
+			                     (void *) p_src, (void *) p_src_end, (void *) p_dst));
+			/* A validated read() is always a number, so it's write coercion
+			 * is always side effect free an won't invalidate pointers etc.
+			 */
+			duk_hbufferobject_push_validated_read(ctx, h_bufarg, p_src, src_elem_size);
+			duk_hbufferobject_validated_write(ctx, h_this, p_dst, dst_elem_size);
+			duk_pop(ctx);
+			p_src += src_elem_size;
+			p_dst += dst_elem_size;
+		}
+
+		return 0;
+	} else {
+		/* Slow path: quite slow, but we save space by using the property code
+		 * to write coerce target values.  We don't need to worry about overlap
+		 * here because the source is not a TypedArray.
+		 *
+		 * We could use the bufferobject write coercion helper but since the
+		 * property read may have arbitrary side effects, full validity checks
+		 * would be needed for every element anyway.
+		 */
+
+		n = (duk_uarridx_t) duk_get_length(ctx, 0);
+		DUK_ASSERT(offset_bytes <= h_this->length);
+		if ((n << h_this->shift) > h_this->length - offset_bytes) {
+			/* Overflow not an issue because subtraction is used on the right
+			 * side and guaranteed to be >= 0.
+			 */
+			DUK_DDD(DUK_DDDPRINT("copy exceeds target buffer nominal length"));
+			return DUK_RET_RANGE_ERROR;
+		}
+
+		/* There's no need to check for buffer validity status for the
+		 * target here: the property access code will do that for each
+		 * element.  Moreover, if we did check the validity here, side
+		 * effects from reading the source argument might invalidate
+		 * the results anyway.
+		 */
+
+		DUK_ASSERT_TOP(ctx, 2);
+		duk_push_this(ctx);
+
+		for (i = 0; i < n; i++) {
+			duk_get_prop_index(ctx, 0, i);
+			duk_put_prop_index(ctx, 2, offset_elems + i);
+		}
+	}
+
+	return 0;
+}
+#else  /* DUK_USE_BUFFEROBJECT_SUPPORT */
+DUK_INTERNAL duk_ret_t duk_bi_typedarray_set(duk_context *ctx) {
+	DUK_UNREF(ctx);
+	return DUK_RET_UNSUPPORTED_ERROR;
+}
+#endif  /* DUK_USE_BUFFEROBJECT_SUPPORT */
+
+/*
+ *  Node.js Buffer.prototype.slice([start], [end])
+ *  ArrayBuffer.prototype.slice(begin, [end])
+ *  TypedArray.prototype.slice(begin, [end])
+ *
+ *  The API calls are almost identical; negative indices are counted from end
+ *  of buffer, and final indices are clamped (allowing crossed indices).  Main
+ *  differences:
+ *
+ *    - Copy/view behavior; Node.js .slice() and TypedArray .subarray() create
+ *      views, ArrayBuffer .slice() creates a copy
+ *
+ *    - Resulting object has a different class and prototype depending on the
+ *      call (or 'this' argument)
+ *
+ *    - TypedArray .subarray() arguments are element indices, not byte offsets
+ */
+
+#if defined(DUK_USE_BUFFEROBJECT_SUPPORT)
+DUK_INTERNAL duk_ret_t duk_bi_buffer_slice_shared(duk_context *ctx) {
+	duk_hthread *thr;
+	duk_small_int_t magic;
+	duk_small_uint_t res_class_num;
+	duk_hobject *res_proto;
+	duk_hbufferobject *h_this;
+	duk_hbufferobject *h_bufobj;
+	duk_hbuffer *h_val;
+	duk_int_t start_offset, end_offset;
+	duk_uint_t slice_length;
+
+	thr = (duk_hthread *) ctx;
+	DUK_UNREF(thr);
+
+	/* [ start end ] */
+
+	magic = duk_get_current_magic(ctx);
+	h_this = duk__require_bufobj_this(ctx);
+
+	/* Slice offsets are element (not byte) offsets, which only matters
+	 * for TypedArray views, Node.js Buffer and ArrayBuffer have shift
+	 * zero so byte and element offsets are the same.  Negative indices
+	 * are counted from end of slice, crossed indices are allowed (and
+	 * result in zero length result), and final values are clamped
+	 * against the current slice.  There's intentionally no check
+	 * against the underlying buffer here.
+	 */
+
+	duk__clamp_startend_negidx_shifted(ctx, h_this, 0 /*idx_start*/, 1 /*idx_end*/, &start_offset, &end_offset);
+	DUK_ASSERT(end_offset >= start_offset);
+	slice_length = (duk_uint_t) (end_offset - start_offset);
+
+	/* The resulting buffer object gets the same class and prototype as
+	 * the buffer in 'this', e.g. if the input is a Node.js Buffer the
+	 * result is a Node.js Buffer; if the input is a Float32Array, the
+	 * result is a Float32Array.
+	 *
+	 * For the class number this seems correct.  The internal prototype
+	 * is not so clear: if 'this' is a bufferobject with a non-standard
+	 * prototype object, that value gets copied over into the result
+	 * (instead of using the standard prototype for that object type).
+	 */
+
+	res_class_num = DUK_HOBJECT_GET_CLASS_NUMBER((duk_hobject *) h_this);
+	h_bufobj = duk_push_bufferobject_raw(ctx,
+	                                     DUK_HOBJECT_FLAG_EXTENSIBLE |
+	                                     DUK_HOBJECT_FLAG_BUFFEROBJECT |
+	                                     DUK_HOBJECT_CLASS_AS_FLAGS(res_class_num),
+	                                     DUK_BIDX_OBJECT_PROTOTYPE);  /* replaced */
+	DUK_ASSERT(h_bufobj != NULL);
+	res_proto = DUK_HOBJECT_GET_PROTOTYPE(thr->heap, (duk_hobject *) h_this);  /* may be NULL */
+	DUK_HOBJECT_SET_PROTOTYPE_UPDREF(thr, (duk_hobject *) h_bufobj, res_proto);
+
+	h_bufobj->length = slice_length;
+	h_bufobj->shift = h_this->shift;  /* inherit */
+	h_bufobj->elem_type = h_this->elem_type;  /* inherit */
+	h_bufobj->is_view = magic & 0x01;
+	DUK_ASSERT(h_bufobj->is_view == 0 || h_bufobj->is_view == 1);
+
+	h_val = h_this->buf;
+	if (h_val == NULL) {
+		return DUK_RET_TYPE_ERROR;
+	}
+
+	if (magic & 0x02) {
+		/* non-zero: make copy */
+		duk_uint8_t *p_copy;
+		duk_size_t copy_length;
+
+		p_copy = (duk_uint8_t *) duk_push_fixed_buffer(ctx, (duk_size_t) slice_length);
+		DUK_ASSERT(p_copy != NULL);
+
+		/* Copy slice, respecting underlying buffer limits; remainder
+		 * is left as zero.
+		 */
+		copy_length = DUK_HBUFFEROBJECT_CLAMP_BYTELENGTH(h_this, slice_length);
+		DUK_MEMCPY((void *) p_copy,
+		           (const void *) (DUK_HBUFFEROBJECT_GET_SLICE_BASE(thr->heap, h_this) + start_offset),
+		           copy_length);
+
+		h_val = duk_get_hbuffer(ctx, -1);
+		DUK_ASSERT(h_val != NULL);
+
+		h_bufobj->buf = h_val;
+		DUK_HBUFFER_INCREF(thr, h_val);
+		DUK_ASSERT(h_bufobj->offset == 0);
+
+		duk_pop(ctx);  /* reachable so pop OK */
+	} else {
+		h_bufobj->buf = h_val;
+		DUK_HBUFFER_INCREF(thr, h_val);
+		h_bufobj->offset = (duk_uint_t) (h_this->offset + start_offset);
+
+		/* Copy the .buffer property, needed for TypedArray.prototype.subarray().
+		 *
+		 * XXX: limit copy only for TypedArray classes specifically?
+		 */
+
+		duk_push_this(ctx);
+		if (duk_get_prop_stridx(ctx, -1, DUK_STRIDX_LC_BUFFER)) {
+			duk_xdef_prop_stridx(ctx, -3, DUK_STRIDX_LC_BUFFER, DUK_PROPDESC_FLAGS_NONE);
+			duk_pop(ctx);
+		} else {
+			duk_pop_2(ctx);
+		}
+	}
+	/* unbalanced stack on purpose */
+
+	DUK_ASSERT_HBUFFEROBJECT_VALID(h_bufobj);
+	return 1;
+}
+#else  /* DUK_USE_BUFFEROBJECT_SUPPORT */
+DUK_INTERNAL duk_ret_t duk_bi_buffer_slice_shared(duk_context *ctx) {
+	DUK_UNREF(ctx);
+	return DUK_RET_UNSUPPORTED_ERROR;
+}
+#endif  /* DUK_USE_BUFFEROBJECT_SUPPORT */
+
+/*
+ *  Node.js Buffer.isEncoding()
+ */
+
+#if defined(DUK_USE_BUFFEROBJECT_SUPPORT)
+DUK_INTERNAL duk_ret_t duk_bi_nodejs_buffer_is_encoding(duk_context *ctx) {
+	const char *encoding;
+
+	/* only accept lowercase 'utf8' now. */
+
+	encoding = duk_to_string(ctx, 0);
+	DUK_ASSERT(duk_is_string(ctx, 0));  /* guaranteed by duk_to_string() */
+	duk_push_boolean(ctx, DUK_STRCMP(encoding, "utf8") == 0);
+	return 1;
+}
+#else  /* DUK_USE_BUFFEROBJECT_SUPPORT */
+DUK_INTERNAL duk_ret_t duk_bi_nodejs_buffer_is_encoding(duk_context *ctx) {
+	DUK_UNREF(ctx);
+	return DUK_RET_UNSUPPORTED_ERROR;
+}
+#endif  /* DUK_USE_BUFFEROBJECT_SUPPORT */
+
+/*
+ *  Node.js Buffer.isBuffer()
+ */
+
+#if defined(DUK_USE_BUFFEROBJECT_SUPPORT)
+DUK_INTERNAL duk_ret_t duk_bi_nodejs_buffer_is_buffer(duk_context *ctx) {
+	duk_hthread *thr;
+	duk_tval *tv;
+	duk_hobject *h;
+	duk_hobject *h_proto;
+	duk_bool_t ret = 0;
+
+	thr = (duk_hthread *) ctx;
+
+	DUK_ASSERT(duk_get_top(ctx) >= 1);  /* nargs */
+	tv = duk_get_tval(ctx, 0);
+	DUK_ASSERT(tv != NULL);
+
+	if (DUK_TVAL_IS_OBJECT(tv)) {
+		h = DUK_TVAL_GET_OBJECT(tv);
+		DUK_ASSERT(h != NULL);
+
+		h_proto = thr->builtins[DUK_BIDX_NODEJS_BUFFER_PROTOTYPE];
+		DUK_ASSERT(h_proto != NULL);
+
+		h = DUK_HOBJECT_GET_PROTOTYPE(thr->heap, h);
+		if (h) {
+			ret = duk_hobject_prototype_chain_contains(thr, h, h_proto, 0 /*ignore_loop*/);
+		}
+	}
+
+	duk_push_boolean(ctx, ret);
+	return 1;
+}
+#else  /* DUK_USE_BUFFEROBJECT_SUPPORT */
+DUK_INTERNAL duk_ret_t duk_bi_nodejs_buffer_is_buffer(duk_context *ctx) {
+	DUK_UNREF(ctx);
+	return DUK_RET_UNSUPPORTED_ERROR;
+}
+#endif  /* DUK_USE_BUFFEROBJECT_SUPPORT */
+
+/*
+ *  Node.js Buffer.byteLength()
+ */
+
+#if defined(DUK_USE_BUFFEROBJECT_SUPPORT)
+DUK_INTERNAL duk_ret_t duk_bi_nodejs_buffer_byte_length(duk_context *ctx) {
+	const char *str;
+	duk_size_t len;
+
+	/* At the moment Buffer(<str>) will just use the string bytes as
+	 * is (ignoring encoding), so we return the string length here
+	 * unconditionally.
+	 */
+
+	str = duk_to_lstring(ctx, 0, &len);
+	DUK_UNREF(str);
+	duk_push_size_t(ctx, len);
+	return 1;
+}
+#else  /* DUK_USE_BUFFEROBJECT_SUPPORT */
+DUK_INTERNAL duk_ret_t duk_bi_nodejs_buffer_byte_length(duk_context *ctx) {
+	DUK_UNREF(ctx);
+	return DUK_RET_UNSUPPORTED_ERROR;
+}
+#endif  /* DUK_USE_BUFFEROBJECT_SUPPORT */
+
+/*
+ *  Node.js Buffer.concat()
+ */
+
+#if defined(DUK_USE_BUFFEROBJECT_SUPPORT)
+DUK_INTERNAL duk_ret_t duk_bi_nodejs_buffer_concat(duk_context *ctx) {
+	duk_hthread *thr;
+	duk_hobject *h_arg;
+	duk_int_t total_length = 0;
+	duk_hbufferobject *h_bufobj;
+	duk_hbufferobject *h_bufres;
+	duk_hbuffer *h_val;
+	duk_uint_t i, n;
+	duk_uint8_t *p;
+	duk_size_t space_left;
+	duk_size_t copy_size;
+
+	thr = (duk_hthread *) ctx;
+	DUK_UNREF(thr);
+
+	/* Node.js accepts only actual Arrays. */
+	h_arg = duk_require_hobject(ctx, 0);
+	if (DUK_HOBJECT_GET_CLASS_NUMBER(h_arg) != DUK_HOBJECT_CLASS_ARRAY) {
+		return DUK_RET_TYPE_ERROR;
+	}
+
+	/* Compute result length and validate argument buffers. */
+	n = (duk_uint_t) duk_get_length(ctx, 0);
+	for (i = 0; i < n; i++) {
+		/* Neutered checks not necessary here: neutered buffers have
+		 * zero 'length' so we'll effectively skip them.
+		 */
+		DUK_ASSERT_TOP(ctx, 2);  /* [ array totalLength ] */
+		duk_get_prop_index(ctx, 0, (duk_uarridx_t) i);  /* -> [ array totalLength buf ] */
+		h_bufobj = duk__require_bufobj_value(ctx, 2);
+		DUK_ASSERT(h_bufobj != NULL);
+		total_length += h_bufobj->length;
+		duk_pop(ctx);
+	}
+	if (n == 1) {
+		/* For the case n==1 Node.js doesn't seem to type check
+		 * the sole member but we do it before returning it.
+		 * For this case only the original buffer object is
+		 * returned (not a copy).
+		 */
+		duk_get_prop_index(ctx, 0, 0);
+		return 1;
+	}
+
+	/* User totalLength overrides a computed length, but we'll check
+	 * every copy in the copy loop.  Note that duk_to_uint() can
+	 * technically have arbitrary side effects so we need to recheck
+	 * the buffers in the copy loop.
+	 */
+	if (!duk_is_undefined(ctx, 1) && n > 0) {
+		/* For n == 0, Node.js ignores totalLength argument and
+		 * returns a zero length buffer.
+		 */
+		total_length = duk_to_int(ctx, 1);
+	}
+	if (total_length < 0) {
+		return DUK_RET_RANGE_ERROR;
+	}
+
+	h_bufres = duk_push_bufferobject_raw(ctx,
+	                                     DUK_HOBJECT_FLAG_EXTENSIBLE |
+	                                     DUK_HOBJECT_FLAG_BUFFEROBJECT |
+	                                     DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_BUFFER),
+	                                     DUK_BIDX_NODEJS_BUFFER_PROTOTYPE);
+	DUK_ASSERT(h_bufres != NULL);
+
+	p = (duk_uint8_t *) duk_push_fixed_buffer(ctx, total_length);
+	DUK_ASSERT(p != NULL);
+	space_left = total_length;
+
+	for (i = 0; i < n; i++) {
+		DUK_ASSERT_TOP(ctx, 4);  /* [ array totalLength bufres buf ] */
+
+		duk_get_prop_index(ctx, 0, (duk_uarridx_t) i);
+		h_bufobj = duk__require_bufobj_value(ctx, 4);
+		DUK_ASSERT(h_bufobj != NULL);
+
+		copy_size = h_bufobj->length;
+		if (copy_size > space_left) {
+			copy_size = space_left;
+		}
+
+		if (h_bufobj->buf != NULL &&
+		    DUK_HBUFFEROBJECT_VALID_SLICE(h_bufobj)) {
+			DUK_MEMCPY((void *) p,
+			           (const void *) DUK_HBUFFEROBJECT_GET_SLICE_BASE(thr->heap, h_bufobj),
+			           copy_size);
+		} else {
+			/* Just skip, leaving zeroes in the result. */
+			;
+		}
+		p += copy_size;
+		space_left -= copy_size;
+
+		duk_pop(ctx);
+	}
+
+	h_val = duk_get_hbuffer(ctx, -1);
+	DUK_ASSERT(h_val != NULL);
+
+	duk__set_bufobj_buffer(ctx, h_bufres, h_val);
+	DUK_ASSERT_HBUFFEROBJECT_VALID(h_bufres);
+
+	duk_pop(ctx);  /* pop plain buffer, now reachable through h_bufres */
+
+	return 1;  /* return h_bufres */
+}
+#else  /* DUK_USE_BUFFEROBJECT_SUPPORT */
+DUK_INTERNAL duk_ret_t duk_bi_nodejs_buffer_concat(duk_context *ctx) {
+	DUK_UNREF(ctx);
+	return DUK_RET_UNSUPPORTED_ERROR;
+}
+#endif  /* DUK_USE_BUFFEROBJECT_SUPPORT */
+
+/*
+ *  Shared readfield and writefield methods
+ *
+ *  The readfield/writefield methods need support for endianness and field
+ *  types.  All offsets are byte based so no offset shifting is needed.
+ */
+
+#if defined(DUK_USE_BUFFEROBJECT_SUPPORT)
+/* Format of magic, bits:
+ *   0...1: field type; 0=uint8, 1=uint16, 2=uint32, 3=float, 4=double, 5=unused, 6=unused, 7=unused
+ *       3: endianness: 0=little, 1=big
+ *       4: signed: 1=yes, 0=no
+ *       5: typedarray: 1=yes, 0=no
+ */
+#define  DUK__FLD_8BIT         0
+#define  DUK__FLD_16BIT        1
+#define  DUK__FLD_32BIT        2
+#define  DUK__FLD_FLOAT        3
+#define  DUK__FLD_DOUBLE       4
+#define  DUK__FLD_VARINT       5
+#define  DUK__FLD_BIGENDIAN    (1 << 3)
+#define  DUK__FLD_SIGNED       (1 << 4)
+#define  DUK__FLD_TYPEDARRAY   (1 << 5)
+
+/* XXX: split into separate functions for each field type? */
+DUK_INTERNAL duk_ret_t duk_bi_buffer_readfield(duk_context *ctx) {
+	duk_hthread *thr;
+	duk_small_int_t magic = (duk_small_int_t) duk_get_current_magic(ctx);
+	duk_small_int_t magic_ftype;
+	duk_small_int_t magic_bigendian;
+	duk_small_int_t magic_signed;
+	duk_small_int_t magic_typedarray;
+	duk_small_int_t endswap;
+	duk_hbufferobject *h_this;
+	duk_bool_t no_assert;
+	duk_int_t offset_signed;
+	duk_uint_t offset;
+	duk_uint_t buffer_length;
+	duk_uint_t check_length;
+	duk_uint8_t *buf;
+	duk_double_union du;
+
+	thr = (duk_hthread *) ctx;
+	DUK_UNREF(thr);
+
+	magic_ftype = magic & 0x0007;
+	magic_bigendian = magic & 0x0008;
+	magic_signed = magic & 0x0010;
+	magic_typedarray = magic & 0x0020;
+
+	h_this = duk__require_bufobj_this(ctx);
+	DUK_ASSERT(h_this != NULL);
+	buffer_length = h_this->length;
+
+	/* [ offset noAssert                 ], when ftype != DUK__FLD_VARINT */
+	/* [ offset fieldByteLength noAssert ], when ftype == DUK__FLD_VARINT */
+	/* [ offset littleEndian             ], when DUK__FLD_TYPEDARRAY (regardless of ftype) */
+
+	/* Handle TypedArray vs. Node.js Buffer arg differences */
+	if (magic_typedarray) {
+		no_assert = 0;
+#if defined(DUK_USE_INTEGER_LE)
+		endswap = !duk_to_boolean(ctx, 1);  /* 1=little endian */
+#else
+		endswap = duk_to_boolean(ctx, 1);  /* 1=little endian */
+#endif
+	} else {
+		no_assert = duk_to_boolean(ctx, (magic_ftype == DUK__FLD_VARINT) ? 2 : 1);
+#if defined(DUK_USE_INTEGER_LE)
+		endswap = magic_bigendian;
+#else
+		endswap = !magic_bigendian;
+#endif
+	}
+
+	/* Offset is coerced first to signed integer range and then to unsigned.
+	 * This ensures we can add a small byte length (1-8) to the offset in
+	 * bound checks and not wrap.
+	 */
+	offset_signed = duk_to_int(ctx, 0);
+	offset = (duk_uint_t) offset_signed;
+	if (offset_signed < 0) {
+		goto fail_bounds;
+	}
+
+	DUK_DDD(DUK_DDDPRINT("readfield, buffer_length=%ld, offset=%ld, no_assert=%d, "
+	                     "magic=%04x, magic_fieldtype=%d, magic_bigendian=%d, magic_signed=%d, "
+	                     "endswap=%d",
+	                     (long) buffer_length, (long) offset, (int) no_assert,
+	                     (unsigned int) magic, (int) magic_ftype, (int) (magic_bigendian >> 3),
+	                     (int) (magic_signed >> 4), (int) endswap));
+
+	/* Update 'buffer_length' to be the effective, safe limit which
+	 * takes into account the underlying buffer.  This value will be
+	 * potentially invalidated by any side effect.
+	 */
+	check_length = DUK_HBUFFEROBJECT_CLAMP_BYTELENGTH(h_this, buffer_length);
+	DUK_DDD(DUK_DDDPRINT("buffer_length=%ld, check_length=%ld",
+	                     (long) buffer_length, (long) check_length));
+
+	if (h_this->buf) {
+		buf = DUK_HBUFFEROBJECT_GET_SLICE_BASE(thr->heap, h_this);
+	} else {
+		/* Neutered.  We could go into the switch-case safely with
+		 * buf == NULL because check_length == 0.  To avoid scanbuild
+		 * warnings, fail directly instead.
+		 */
+		DUK_ASSERT(check_length == 0);
+		goto fail_neutered;
+	}
+	DUK_ASSERT(buf != NULL);
+
+	switch (magic_ftype) {
+	case DUK__FLD_8BIT: {
+		duk_uint8_t tmp;
+		if (offset + 1U > check_length) {
+			goto fail_bounds;
+		}
+		tmp = buf[offset];
+		if (magic_signed) {
+			duk_push_int(ctx, (duk_int_t) ((duk_int8_t) tmp));
+		} else {
+			duk_push_uint(ctx, (duk_uint_t) tmp);
+		}
+		break;
+	}
+	case DUK__FLD_16BIT: {
+		duk_uint16_t tmp;
+		if (offset + 2U > check_length) {
+			goto fail_bounds;
+		}
+		DUK_MEMCPY((void *) du.uc, (const void *) (buf + offset), 2);
+		tmp = du.us[0];
+		if (endswap) {
+			tmp = DUK_BSWAP16(tmp);
+		}
+		if (magic_signed) {
+			duk_push_int(ctx, (duk_int_t) ((duk_int16_t) tmp));
+		} else {
+			duk_push_uint(ctx, (duk_uint_t) tmp);
+		}
+		break;
+	}
+	case DUK__FLD_32BIT: {
+		duk_uint32_t tmp;
+		if (offset + 4U > check_length) {
+			goto fail_bounds;
+		}
+		DUK_MEMCPY((void *) du.uc, (const void *) (buf + offset), 4);
+		tmp = du.ui[0];
+		if (endswap) {
+			tmp = DUK_BSWAP32(tmp);
+		}
+		if (magic_signed) {
+			duk_push_int(ctx, (duk_int_t) ((duk_int32_t) tmp));
+		} else {
+			duk_push_uint(ctx, (duk_uint_t) tmp);
+		}
+		break;
+	}
+	case DUK__FLD_FLOAT: {
+		duk_uint32_t tmp;
+		if (offset + 4U > check_length) {
+			goto fail_bounds;
+		}
+		DUK_MEMCPY((void *) du.uc, (const void *) (buf + offset), 4);
+		if (endswap) {
+			tmp = du.ui[0];
+			tmp = DUK_BSWAP32(tmp);
+			du.ui[0] = tmp;
+		}
+		duk_push_number(ctx, (duk_double_t) du.f[0]);
+		break;
+	}
+	case DUK__FLD_DOUBLE: {
+		if (offset + 8U > check_length) {
+			goto fail_bounds;
+		}
+		DUK_MEMCPY((void *) du.uc, (const void *) (buf + offset), 8);
+		if (endswap) {
+			DUK_DBLUNION_BSWAP64(&du);
+		}
+		duk_push_number(ctx, (duk_double_t) du.d);
+		break;
+	}
+	case DUK__FLD_VARINT: {
+		/* Node.js Buffer variable width integer field.  We don't really
+		 * care about speed here, so aim for shortest algorithm.
+		 */
+		duk_int_t field_bytelen;
+		duk_int_t i, i_step, i_end;
+#if defined(DUK_USE_64BIT_OPS)
+		duk_int64_t tmp;
+		duk_small_uint_t shift_tmp;
+#else
+		duk_double_t tmp;
+		duk_small_int_t highbyte;
+#endif
+		const duk_uint8_t *p;
+
+		field_bytelen = duk_get_int(ctx, 1);  /* avoid side effects! */
+		if (field_bytelen < 1 || field_bytelen > 6) {
+			goto fail_field_length;
+		}
+		if (offset + (duk_uint_t) field_bytelen > check_length) {
+			goto fail_bounds;
+		}
+		p = (const duk_uint8_t *) (buf + offset);
+
+		/* Slow gathering of value using either 64-bit arithmetic
+		 * or IEEE doubles if 64-bit types not available.  Handling
+		 * of negative numbers is a bit non-obvious in both cases.
+		 */
+
+		if (magic_bigendian) {
+			/* Gather in big endian */
+			i = 0;
+			i_step = 1;
+			i_end = field_bytelen;  /* one i_step over */
+		} else {
+			/* Gather in little endian */
+			i = field_bytelen - 1;
+			i_step = -1;
+			i_end = -1;  /* one i_step over */
+		}
+
+#if defined(DUK_USE_64BIT_OPS)
+		tmp = 0;
+		do {
+			DUK_ASSERT(i >= 0 && i < field_bytelen);
+			tmp = (tmp << 8) + (duk_int64_t) p[i];
+			i += i_step;
+		} while (i != i_end);
+
+		if (magic_signed) {
+			/* Shift to sign extend. */
+			shift_tmp = 64 - (field_bytelen * 8);
+			tmp = (tmp << shift_tmp) >> shift_tmp;
+		}
+
+		duk_push_i64(ctx, tmp);
+#else
+		highbyte = p[i];
+		if (magic_signed && (highbyte & 0x80) != 0) {
+			/* 0xff => 255 - 256 = -1; 0x80 => 128 - 256 = -128 */
+			tmp = (duk_double_t) (highbyte - 256);
+		} else {
+			tmp = (duk_double_t) highbyte;
+		}
+		for (;;) {
+			i += i_step;
+			if (i == i_end) {
+				break;
+			}
+			DUK_ASSERT(i >= 0 && i < field_bytelen);
+			tmp = (tmp * 256.0) + (duk_double_t) p[i];
+		}
+
+		duk_push_number(ctx, tmp);
+#endif
+		break;
+	}
+	default: {  /* should never happen but default here */
+		goto fail_bounds;
+	}
+	}
+
+	return 1;
+
+ fail_neutered:
+ fail_field_length:
+ fail_bounds:
+	if (no_assert) {
+		/* Node.js return value for noAssert out-of-bounds reads is
+		 * usually (but not always) NaN.  Return NaN consistently.
+		 */
+		duk_push_nan(ctx);
+		return 1;
+	}
+
+	return DUK_RET_RANGE_ERROR;
+}
+#else  /* DUK_USE_BUFFEROBJECT_SUPPORT */
+DUK_INTERNAL duk_ret_t duk_bi_buffer_readfield(duk_context *ctx) {
+	DUK_UNREF(ctx);
+	return DUK_RET_UNSUPPORTED_ERROR;
+}
+#endif  /* DUK_USE_BUFFEROBJECT_SUPPORT */
+
+#if defined(DUK_USE_BUFFEROBJECT_SUPPORT)
+/* XXX: split into separate functions for each field type? */
+DUK_INTERNAL duk_ret_t duk_bi_buffer_writefield(duk_context *ctx) {
+	duk_hthread *thr;
+	duk_small_int_t magic = (duk_small_int_t) duk_get_current_magic(ctx);
+	duk_small_int_t magic_ftype;
+	duk_small_int_t magic_bigendian;
+	duk_small_int_t magic_signed;
+	duk_small_int_t magic_typedarray;
+	duk_small_int_t endswap;
+	duk_hbufferobject *h_this;
+	duk_bool_t no_assert;
+	duk_int_t offset_signed;
+	duk_uint_t offset;
+	duk_uint_t buffer_length;
+	duk_uint_t check_length;
+	duk_uint8_t *buf;
+	duk_double_union du;
+	duk_int_t nbytes = 0;
+
+	thr = (duk_hthread *) ctx;
+	DUK_UNREF(thr);
+
+	magic_ftype = magic & 0x0007;
+	magic_bigendian = magic & 0x0008;
+	magic_signed = magic & 0x0010;
+	magic_typedarray = magic & 0x0020;
+	DUK_UNREF(magic_signed);
+
+	h_this = duk__require_bufobj_this(ctx);
+	DUK_ASSERT(h_this != NULL);
+	buffer_length = h_this->length;
+
+	/* [ value  offset noAssert                 ], when ftype != DUK__FLD_VARINT */
+	/* [ value  offset fieldByteLength noAssert ], when ftype == DUK__FLD_VARINT */
+	/* [ offset value  littleEndian             ], when DUK__FLD_TYPEDARRAY (regardless of ftype) */
+
+	/* Handle TypedArray vs. Node.js Buffer arg differences */
+	if (magic_typedarray) {
+		no_assert = 0;
+#if defined(DUK_USE_INTEGER_LE)
+		endswap = !duk_to_boolean(ctx, 2);  /* 1=little endian */
+#else
+		endswap = duk_to_boolean(ctx, 2);  /* 1=little endian */
+#endif
+		duk_swap(ctx, 0, 1);  /* offset/value order different from Node.js */
+	} else {
+		no_assert = duk_to_boolean(ctx, (magic_ftype == DUK__FLD_VARINT) ? 3 : 2);
+#if defined(DUK_USE_INTEGER_LE)
+		endswap = magic_bigendian;
+#else
+		endswap = !magic_bigendian;
+#endif
+	}
+
+	/* Offset is coerced first to signed integer range and then to unsigned.
+	 * This ensures we can add a small byte length (1-8) to the offset in
+	 * bound checks and not wrap.
+	 */
+	offset_signed = duk_to_int(ctx, 1);
+	offset = (duk_uint_t) offset_signed;
+
+	/* We need 'nbytes' even for a failed offset; return value must be
+	 * (offset + nbytes) even when write fails due to invalid offset.
+	 */
+	if (magic_ftype != DUK__FLD_VARINT) {
+		DUK_ASSERT(magic_ftype >= 0 && magic_ftype < (duk_small_int_t) (sizeof(duk__buffer_nbytes_from_fldtype) / sizeof(duk_uint8_t)));
+		nbytes = duk__buffer_nbytes_from_fldtype[magic_ftype];
+	} else {
+		nbytes = duk_get_int(ctx, 2);
+		if (nbytes < 1 || nbytes > 6) {
+			goto fail_field_length;
+		}
+	}
+	DUK_ASSERT(nbytes >= 1 && nbytes <= 8);
+
+	/* Now we can check offset validity. */
+	if (offset_signed < 0) {
+		goto fail_bounds;
+	}
+
+	DUK_DDD(DUK_DDDPRINT("writefield, value=%!T, buffer_length=%ld, offset=%ld, no_assert=%d, "
+	                     "magic=%04x, magic_fieldtype=%d, magic_bigendian=%d, magic_signed=%d, "
+	                     "endswap=%d",
+	                     duk_get_tval(ctx, 0), (long) buffer_length, (long) offset, (int) no_assert,
+	                     (unsigned int) magic, (int) magic_ftype, (int) (magic_bigendian >> 3),
+	                     (int) (magic_signed >> 4), (int) endswap));
+
+	/* Coerce value to a number before computing check_length, so that
+	 * the field type specific coercion below can't have side effects
+	 * that would invalidate check_length.
+	 */
+	duk_to_number(ctx, 0);
+
+	/* Update 'buffer_length' to be the effective, safe limit which
+	 * takes into account the underlying buffer.  This value will be
+	 * potentially invalidated by any side effect.
+	 */
+	check_length = DUK_HBUFFEROBJECT_CLAMP_BYTELENGTH(h_this, buffer_length);
+	DUK_DDD(DUK_DDDPRINT("buffer_length=%ld, check_length=%ld",
+	                     (long) buffer_length, (long) check_length));
+
+	if 

<TRUNCATED>

[49/51] [partial] nifi-minifi-cpp git commit: MINIFI-183 Added civet 1.9.1 sources Added onScheduled hook Added initial two-way TLS-enabled ListenHTTP implementation

Posted by al...@apache.org.
http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/Makefile.deprecated
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/Makefile.deprecated b/thirdparty/civetweb-1.9.1/Makefile.deprecated
new file mode 100644
index 0000000..288c15b
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/Makefile.deprecated
@@ -0,0 +1,208 @@
+# This Makefile is part of Civetweb web server project,
+# https://github.com/valenok/civetweb
+#
+# Example custom build:
+# COPT="-g -O0 -DNO_SSL_DL -DUSE_LUA -llua -lcrypto -lssl" make linux
+#
+# Flags are:
+# -DHAVE_MD5              - use system md5 library (-2kb)
+# -DNDEBUG                - strip off all debug code (-5kb)
+# -DDEBUG                 - build debug version (very noisy) (+7kb)
+# -DNO_CGI                - disable CGI support (-5kb)
+# -DNO_SSL                - disable SSL functionality (-2kb)
+# -DNO_SSL_DL             - link against system libssl library (-1kb)
+# -DCONFIG_FILE=\"file\"  - use `file' as the default config file
+# -DSSL_LIB=\"libssl.so.<version>\"   - use system versioned SSL shared object
+# -DCRYPTO_LIB=\"libcrypto.so.<version>\" - use system versioned CRYPTO so
+# -DUSE_LUA               - embed Lua in Civetweb (+100kb)
+
+PROG        = civetweb
+CFLAGS      = -std=c99 -O2 -W -Wall -pedantic -pthread -pipe -Iinclude $(COPT)
+
+# To build with Lua, download and unzip Lua 5.2.3 source code into the
+# civetweb directory, and then add $(LUA_SOURCES) to CFLAGS
+LUA         = src/third_party/lua-5.2.3/src
+LUA_FLAGS   = -I$(LUA) -DLUA_COMPAT_ALL
+LUA_SOURCES = $(LUA)/lapi.c $(LUA)/lcode.c $(LUA)/lctype.c \
+              $(LUA)/ldebug.c $(LUA)/ldo.c $(LUA)/ldump.c \
+              $(LUA)/lfunc.c $(LUA)/lgc.c $(LUA)/llex.c \
+              $(LUA)/lmem.c $(LUA)/lobject.c $(LUA)/lopcodes.c \
+              $(LUA)/lparser.c $(LUA)/lstate.c $(LUA)/lstring.c \
+              $(LUA)/ltable.c $(LUA)/ltm.c $(LUA)/lundump.c \
+              $(LUA)/lvm.c $(LUA)/lzio.c $(LUA)/lauxlib.c \
+              $(LUA)/lbaselib.c $(LUA)/lbitlib.c $(LUA)/lcorolib.c \
+              $(LUA)/ldblib.c $(LUA)/liolib.c $(LUA)/lmathlib.c \
+              $(LUA)/loslib.c $(LUA)/lstrlib.c $(LUA)/ltablib.c \
+              $(LUA)/loadlib.c $(LUA)/linit.c
+LUA_WINOBJS = $(LUA_SOURCES:%.c=%.obj)
+
+ifneq ($(OS), Windows_NT)
+  LUA_FLAGS += -DLUA_USE_DLOPEN
+endif
+
+LIB_SOURCES = src/civetweb.c
+
+ALL_SOURCES = src/main.c $(LIB_SOURCES) src/third_party/sqlite3.c src/third_party/lsqlite3.c src/third_party/lfs.c \
+              $(LUA_SOURCES) $(YASSL_SOURCES)
+
+SQLITE_FLAGS = -DTHREADSAFE=1 -DSQLITE_ENABLE_FTS3 -DSQLITE_ENABLE_FTS3_PARENTHESIS
+CIVETWEB_FLAGS = -DUSE_LUA -DUSE_LUA_SQLITE3 -DUSE_LUA_FILE_SYSTEM $(COPT)
+FLAGS = $(CIVETWEB_FLAGS) $(SQLITE_FLAGS) $(LUA_FLAGS)
+
+
+# Stock windows binary builds with Lua. 
+# Yassl has a GPL license, so we will leave it out by default.
+
+ifeq ($(WITH_YASSL), 1)
+YASSL       = ../cyassl-2.4.6
+YASSL_FLAGS = -I $(YASSL) -I $(YASSL)/cyassl \
+              -D _LIB -D OPENSSL_EXTRA -D HAVE_ERRNO_H \
+              -D HAVE_GETHOSTBYNAME -D HAVE_INET_NTOA -D HAVE_LIMITS_H \
+              -D HAVE_MEMSET -D HAVE_SOCKET -D HAVE_STDDEF_H -D HAVE_STDLIB_H \
+              -D HAVE_STRING_H -D HAVE_SYS_STAT_H -D HAVE_SYS_TYPES_H
+YASSL_SOURCES = \
+  $(YASSL)/src/internal.c $(YASSL)/src/io.c $(YASSL)/src/keys.c \
+  $(YASSL)/src/ssl.c $(YASSL)/src/tls.c $(YASSL)/ctaocrypt/src/hmac.c \
+  $(YASSL)/ctaocrypt/src/random.c $(YASSL)/ctaocrypt/src/sha.c \
+  $(YASSL)/ctaocrypt/src/sha256.c $(YASSL)/ctaocrypt/src/logging.c \
+  $(YASSL)/ctaocrypt/src/error.c $(YASSL)/ctaocrypt/src/rsa.c \
+  $(YASSL)/ctaocrypt/src/des3.c $(YASSL)/ctaocrypt/src/asn.c \
+  $(YASSL)/ctaocrypt/src/coding.c $(YASSL)/ctaocrypt/src/arc4.c \
+  $(YASSL)/ctaocrypt/src/md4.c $(YASSL)/ctaocrypt/src/md5.c \
+  $(YASSL)/ctaocrypt/src/dh.c $(YASSL)/ctaocrypt/src/dsa.c \
+  $(YASSL)/ctaocrypt/src/pwdbased.c $(YASSL)/ctaocrypt/src/aes.c \
+  $(YASSL)/ctaocrypt/src/md2.c $(YASSL)/ctaocrypt/src/ripemd.c \
+  $(YASSL)/ctaocrypt/src/sha512.c $(YASSL)/src/sniffer.c \
+  $(YASSL)/ctaocrypt/src/rabbit.c $(YASSL)/ctaocrypt/src/misc.c \
+  $(YASSL)/ctaocrypt/src/tfm.c $(YASSL)/ctaocrypt/src/integer.c \
+  $(YASSL)/ctaocrypt/src/ecc.c $(YASSL)/src/ocsp.c $(YASSL)/src/crl.c \
+  $(YASSL)/ctaocrypt/src/hc128.c $(YASSL)/ctaocrypt/src/memory.c
+  
+  ALL_SOURCES += $(YASSL_SOURCES)
+  FLAGS += $(YASSL_FLAGS) -DNO_SSL_DL
+  CIVETWEB_FLAGS += -DNO_SSL_DL 
+
+else
+#  FLAGS += -DNO_SSL
+#  CIVETWEB_FLAGS += -DNO_SSL 
+endif
+
+ALL_OBJECTS = $(ALL_SOURCES:%.c=%.o)
+ALL_WINOBJS = $(ALL_SOURCES:%.c=%.obj)
+
+
+# Using Visual Studio 6.0. To build Civetweb:
+#  Set MSVC variable below to where VS 6.0 is installed on your system
+#  Run "PATH_TO_VC6\bin\nmake windows"
+MSVC = ../vc6
+#DBG = /Zi /Od
+DBG  = /DNDEBUG /O1
+CL   = $(MSVC)/bin/cl /MD /TC /nologo $(DBG) /W3 /GA /I$(MSVC)/include
+LINK = $(MSVC)/bin/link /incremental:no /libpath:$(MSVC)/lib /machine:IX86 \
+       user32.lib shell32.lib comdlg32.lib ws2_32.lib advapi32.lib
+
+all:
+	@echo "make (linux|bsd|solaris|mac|windows|mingw|cygwin)"
+
+%.obj: %.c
+	$(CL) /c $(FLAGS) /Fo$@ $<
+
+%.o: %.c
+	$(CC) -o $@ $< -c $(FLAGS) $(CFLAGS)
+
+# Lua library for Windows
+lua.lib: $(LUA_WINOBJS)
+	$(MSVC)/bin/lib /out:$@ $(LUA_WINOBJS)
+
+# To build with Lua, make sure you have Lua unpacked into src/third_party/lua-5.2.3 directory
+linux_lua: $(ALL_OBJECTS)
+	$(CC) $(ALL_OBJECTS) -o $(PROG) -ldl
+
+civetweb.o: src/mod_lua.inl
+
+# Make sure that the compiler flags come last in the compilation string.
+# If not so, this can break some on some Linux distros which use
+# "-Wl,--as-needed" turned on by default  in cc command.
+# Also, this is turned in many other distros in static linkage builds.
+linux:
+	$(CC) $(LIB_SOURCES) src/main.c -o $(PROG) -ldl $(CFLAGS)
+
+mac: bsd
+bsd:
+	$(CC) $(LIB_SOURCES) src/main.c -o $(PROG) $(CFLAGS)
+
+bsd_lua: $(ALL_OBJECTS)
+	$(CC) $(ALL_OBJECTS) -o $@
+
+solaris:
+	$(CC) $(LIB_SOURCES) src/main.c -lnsl -lsocket -o $(PROG) $(CFLAGS)
+
+lib$(PROG).a: $(ALL_OBJECTS)
+	ar cr $@ $(ALL_OBJECTS)
+
+$(PROG).lib: $(ALL_WINOBJS)
+	$(MSVC)/bin/lib /out:$@ $(ALL_WINOBJS)
+
+# For codesign to work in non-interactive mode, unlock login keychain:
+# security unlock ~/Library/Keychains/login.keychain
+# See e.g. http://lists.apple.com/archives/apple-cdsa/2008/Jan/msg00027.html
+Civetweb: $(LIB_SOURCES) src/main.c
+	$(CC) $(LIB_SOURCES) src/main.c src/third_party/lsqlite3.c src/third_party/sqlite3.c src/third_party/lfs.c \
+          -DUSE_COCOA $(CFLAGS) $(FLAGS) -mmacosx-version-min=10.4 \
+          $(YASSL_SOURCES) $(LUA_SOURCES) \
+          -framework Cocoa -ObjC -arch i386 -arch x86_64 -o Civetweb
+
+cocoa: Civetweb
+	V=`perl -lne '/define\s+CIVETWEB_VERSION\s+"(\S+)"/ and print $$1' include/civetweb.h`; DIR=dmg/Civetweb.app && rm -rf $$DIR && mkdir -p $$DIR/Contents/{MacOS,Resources} && install -m 644 resources/civetweb_*.png resources/civetweb.icns $$DIR/Contents/Resources/ && install -m 644 resources/Info.plist $$DIR/Contents/ && install -m 755 Civetweb $$DIR/Contents/MacOS/ && ln -fs /Applications dmg/ ; hdiutil create Civetweb_$$V.dmg -volname "Civetweb $$V" -srcfolder dmg -ov #; rm -rf dmg
+
+un:
+	$(CC) test/unit_test.c -o unit_test -I. -I$(LUA) $(LUA_SOURCES) \
+          $(CFLAGS) -g -O0
+	./unit_test
+
+wi:
+	$(CL) test/unit_test.c $(LUA_SOURCES) $(LUA_FLAGS) \
+          $(YASSL_SOURCES) $(YASSL_FLAGS) /I. /DNO_SSL_DL \
+          /link /libpath:$(MSVC)/lib advapi32.lib /out:unit_test.exe
+	./unit_test.exe
+
+windows: $(ALL_WINOBJS)
+	$(MSVC)/bin/rc resources/res.rc
+	$(LINK) /nologo $(ALL_WINOBJS) resources/res.res /out:$(PROG).exe
+
+# Build for Windows under MinGW
+#MINGWDBG= -DDEBUG -O0 -ggdb
+MINGWDBG= -DNDEBUG -Os
+MINGWOPT=  -W -Wall -mthreads -Wl,--subsystem,console $(MINGWDBG) -DHAVE_STDINT $(GCC_WARNINGS) $(COPT)
+mingw:
+	windres resources\res.rc resources\res.o
+	$(CC) $(MINGWOPT) $(LIB_SOURCES) -lws2_32 \
+		-shared -Wl,--out-implib=$(PROG).lib -o $(PROG).dll
+	$(CC) $(MINGWOPT) $(LIB_SOURCES) src/main.c resources\res.o \
+	-lws2_32 -ladvapi32 -lcomdlg32 -o $(PROG).exe
+
+# Build for Windows under Cygwin
+#CYGWINDBG= -DDEBUG -O0 -ggdb
+CYGWINDBG= -DNDEBUG -Os
+CYGWINOPT=  -W -Wall -mthreads -Wl,--subsystem,console $(CYGWINDBG) -DHAVE_STDINT $(GCC_WARNINGS) $(COPT)
+cygwin:
+	windres ./resources/res.rc ./resources/res.o
+	$(CC) $(CYGWINOPT) $(LIB_SOURCES) -lws2_32 \
+		-shared -Wl,--out-implib=$(PROG).lib -o $(PROG).dll
+	$(CC) $(CYGWINOPT) -Iinclude $(LIB_SOURCES) src/main.c ./resources/res.o \
+	-lws2_32 -ladvapi32 -o $(PROG).exe
+
+tests:
+	perl test/test.pl $(TEST)
+
+tarball: clean
+	F=civetweb-`perl -lne '/define\s+CIVETWEB_VERSION\s+"(\S+)"/ and print $$1' include/civetweb.h`.tgz ; cd .. && tar -czf x civetweb/{LICENSE.md,Makefile,examples,test,resources,*.[ch],*.md} && mv x civetweb/$$F
+
+release: tarball cocoa
+	wine make windows
+	V=`perl -lne '/define\s+CIVETWEB_VERSION\s+"(\S+)"/ and print $$1' include/civetweb.h`; upx civetweb.exe; cp civetweb.exe civetweb-$$V.exe; cp civetweb.exe civetweb_php_bundle/; zip -r civetweb_php_bundle_$$V.zip civetweb_php_bundle/
+
+clean:
+	rm -rf *.o *.core $(PROG) *.obj *.so $(PROG).txt *.dSYM *.tgz \
+	$(PROG).exe *.dll *.lib resources/res.o resources/res.RES *.dSYM *.zip *.pdb \
+	*.exe *.dmg $(ALL_OBJECTS) $(ALL_WINOBJS)

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/Makefile.osx
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/Makefile.osx b/thirdparty/civetweb-1.9.1/Makefile.osx
new file mode 100644
index 0000000..44260e8
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/Makefile.osx
@@ -0,0 +1,42 @@
+# 
+# Copyright (c) 2013 No Face Press, LLC
+# License http://opensource.org/licenses/mit-license.php MIT License
+#
+
+# For codesign to work in non-interactive mode, unlock login keychain:
+# security unlock ~/Library/Keychains/login.keychain
+# See e.g. http://lists.apple.com/archives/apple-cdsa/2008/Jan/msg00027.html
+
+# Civetweb features
+WITH_LUA = 1
+
+PACKAGE = Civetweb
+BUILD_DIR = out
+
+CFLAGS += -DUSE_COCOA -DENABLE_CREATE_CONFIG_FILE -mmacosx-version-min=10.4 -ObjC -arch i386 -arch x86_64
+LDFLAGS += -framework Cocoa
+
+DMG_DIR = $(BUILD_DIR)/dmg
+CONTENTS_DIR = $(DMG_DIR)/$(PACKAGE).app/Contents
+RESOURCES_DIR = $(CONTENTS_DIR)/Resources
+OSXBIN_DIR = $(CONTENTS_DIR)/MacOS
+
+CIVETWEB_VERSION = $(shell perl -lne '/define\s+CIVETWEB_VERSION\s+"(\S+)"/ and print $$1' include/civetweb.h)
+ZIPFILENAME = $(PACKAGE)-$(CIVETWEB_VERSION).zip
+
+include Makefile
+
+package: build
+	@rm -rf $(DMG_DIR)
+	install -d -m 755 $(CONTENTS_DIR) $(RESOURCES_DIR) $(OSXBIN_DIR)
+	install -m 644 resources/Info.plist $(CONTENTS_DIR)/
+	install -m 644 resources/civetweb_*.png resources/civetweb.icns $(RESOURCES_DIR)/
+	install -m 644 resources/itworks.html $(OSXBIN_DIR)/index.html
+	install -m 644 resources/civetweb_64x64.png $(OSXBIN_DIR)/
+	install -m 755 $(CPROG) $(OSXBIN_DIR)/$(PACKAGE)
+	install -m 644 docs/Installing.md $(DMG_DIR)/Installing.txt
+	install -m 644 LICENSE.md $(DMG_DIR)/License.txt
+	rm -rf $(ZIPFILENAME)
+	cd $(DMG_DIR) && zip -r ../../$(ZIPFILENAME) .
+
+.PHONY: package

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/Qt/CivetWeb.pro
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/Qt/CivetWeb.pro b/thirdparty/civetweb-1.9.1/Qt/CivetWeb.pro
new file mode 100644
index 0000000..732f82f
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/Qt/CivetWeb.pro
@@ -0,0 +1,28 @@
+TEMPLATE = app
+CONFIG += console
+CONFIG -= app_bundle
+CONFIG -= qt
+
+SOURCES += \
+    ../src/md5.inl \
+    ../src/sha1.inl \
+    ../src/handle_form.inl \
+    ../src/mod_lua.inl \
+    ../src/timer.inl \
+    ../src/civetweb.c \
+    ../src/main.c
+
+#include(deployment.pri)
+#qtcAddDeployment()
+
+HEADERS += \
+    ../include/civetweb.h
+
+INCLUDEPATH +=  \
+    ../include/
+
+LIBS += -lws2_32 -lComdlg32 -lUser32 -lShell32 -lAdvapi32
+
+
+DEFINES += USE_IPV6
+DEFINES += USE_WEBSOCKET

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/README.md
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/README.md b/thirdparty/civetweb-1.9.1/README.md
new file mode 100644
index 0000000..5150e8e
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/README.md
@@ -0,0 +1,162 @@
+![CivetWeb](https://raw.github.com/civetweb/civetweb/master/resources/civetweb_64x64.png "CivetWeb") CivetWeb
+=======
+
+**The official home of CivetWeb is [https://github.com/civetweb/civetweb](https://github.com/civetweb/civetweb)**
+
+
+Continuous integration for Linux and OSX ([Travis CI](https://travis-ci.org/civetweb/civetweb)):
+
+[![Travis Build Status](https://travis-ci.org/civetweb/civetweb.svg?branch=master)](https://travis-ci.org/civetweb/civetweb)
+
+Continuous integration for Windows ([AppVeyor](https://ci.appveyor.com/project/civetweb/civetweb)):
+
+[![Appveyor Build Status](https://ci.appveyor.com/api/projects/status/github/civetweb/civetweb?svg=true)](https://ci.appveyor.com/project/civetweb/civetweb/branch/master)
+
+Test coverage check ([coveralls](https://coveralls.io/github/civetweb/civetweb)) (currently in a setup phase):
+
+[![Coverage Status](https://coveralls.io/repos/github/civetweb/civetweb/badge.svg?branch=master)](https://coveralls.io/github/civetweb/civetweb?branch=master)
+
+Static source code analysis ([Coverity](https://scan.coverity.com/projects/5784)):
+
+[![Coverity Scan Build Status](https://scan.coverity.com/projects/5784/badge.svg)](https://scan.coverity.com/projects/5784)
+
+
+
+
+Project Mission
+-----------------
+
+Project mission is to provide easy to use, powerful, C/C++ embeddable web
+server with optional CGI, SSL and Lua support.
+CivetWeb has a MIT license so you can innovate without restrictions.
+
+CivetWeb can be used by developers as a library, to add web server functionality to an existing application.
+It can also be used by end users as a stand-alone web server. It is available as single executable, no installation is required.
+
+
+Where to find the official version?
+-----------------------------------
+
+End users can download CivetWeb at SourceForge
+[https://sourceforge.net/projects/civetweb/](https://sourceforge.net/projects/civetweb/)
+
+Developers can contribute to CivetWeb via GitHub
+[https://github.com/civetweb/civetweb](https://github.com/civetweb/civetweb)
+
+Trouble tickets should be filed on GitHub
+[https://github.com/civetweb/civetweb/issues](https://github.com/civetweb/civetweb/issues)
+
+Discussion/support group and announcements are at Google Groups
+[https://groups.google.com/d/forum/civetweb](https://groups.google.com/d/forum/civetweb)
+
+Source releases can be found on GitHub
+[https://github.com/civetweb/civetweb/releases](https://github.com/civetweb/civetweb/releases)
+
+
+Quick start documentation
+--------------------------
+
+- [docs/Installing.md](https://github.com/civetweb/civetweb/blob/master/docs/Installing.md) - Install Guide (for end users using pre-built binaries)
+- [docs/UserManual.md](https://github.com/civetweb/civetweb/blob/master/docs/UserManual.md) - End User Guide
+- [docs/Building.md](https://github.com/civetweb/civetweb/blob/master/docs/Building.md) - Building the Server (quick start guide)
+- [docs/Embedding.md](https://github.com/civetweb/civetweb/blob/master/docs/Embedding.md) - Embedding (how to add HTTP support to an existing application)
+- [docs/OpenSSL.md](https://github.com/civetweb/civetweb/blob/master/docs/OpenSSL.md) - Adding HTTPS (SSL/TLS) support using OpenSSL.
+- [API documentation](https://github.com/civetweb/civetweb/tree/master/docs/api) - Additional documentation on the civetweb application programming interface ([civetweb.h](https://github.com/civetweb/civetweb/blob/master/include/civetweb.h)).
+- [RELEASE_NOTES.md](https://github.com/civetweb/civetweb/blob/master/RELEASE_NOTES.md) - Release Notes
+- [LICENSE.md](https://github.com/civetweb/civetweb/blob/master/LICENSE.md) - Copyright License
+
+
+Overview
+--------
+
+CivetWeb keeps the balance between functionality and
+simplicity by a carefully selected list of features:
+
+- Liberal, commercial-friendly, permissive,
+  [MIT license](http://en.wikipedia.org/wiki/MIT_License)
+- Free from copy-left licenses, like GPL, because you should innovate without
+  restrictions.
+- Forked from [Mongoose](https://code.google.com/p/mongoose/) in 2013, before
+  it changed the licence from MIT to commercial + GPL. A lot of enchancements
+  have been added since that time, see
+  [RELEASE_NOTES.md](https://github.com/civetweb/civetweb/blob/master/RELEASE_NOTES.md).
+- Works on Windows, Mac, Linux, UNIX, iPhone, Android, Buildroot, and many
+  other platforms.
+- Scripting and database support (Lua scipts, Lua Server Pages, CGI + SQLite
+  database, Server side javascript).
+  This provides a ready to go, powerful web development platform in a one
+  single-click executable with **no dependencies**.
+- Support for CGI, HTTPS (SSL/TLS), SSI, HTTP digest (MD5) authorization, Websocket,
+  WEbDAV.
+- Optional support for authentication using client side X.509 certificates.
+- Resumed download, URL rewrite, file blacklist, IP-based ACL, Windows service.
+- Download speed limit based on client subnet or URI pattern.
+- Simple and clean embedding API.
+- The source is in single file to make things easy.
+- Embedding examples included.
+- HTTP client capable of sending arbitrary HTTP/HTTPS requests.
+- Websocket client functionality available (WS/WSS).
+
+
+### Optionally included software
+
+<a href="http://lua.org">
+![Lua](https://raw.github.com/civetweb/civetweb/master/resources/lua-logo.jpg "Lua Logo")
+</a>
+<a href="http://sqlite.org">
+![Sqlite3](https://raw.github.com/civetweb/civetweb/master/resources/sqlite3-logo.jpg "Sqlite3 Logo")
+</a>
+<a href="http://keplerproject.github.io/luafilesystem/">
+![LuaFileSystem](https://raw.github.com/civetweb/civetweb/master/resources/luafilesystem-logo.jpg "LuaFileSystem Logo")
+</a>
+<a href="http://lua.sqlite.org/index.cgi/index">
+![LuaSQLite3](https://raw.github.com/civetweb/civetweb/master/resources/luasqlite-logo.jpg "LuaSQLite3 Logo")
+</a>
+<a href="http://viremo.eludi.net/LuaXML/index.html">
+![LuaXML](https://raw.github.com/civetweb/civetweb/master/resources/luaxml-logo.jpg "LuaXML Logo")
+</a>
+<a href="http://duktape.org">
+![Duktape](https://raw.github.com/civetweb/civetweb/master/resources/duktape-logo.png "Duktape Logo")
+</a>
+
+
+Support
+-------
+
+This project is very easy to install and use. Please read the [documentation](https://github.com/civetweb/civetweb/blob/master/docs/)
+and have a look at the [examples] (https://github.com/civetweb/civetweb/blob/master/examples/).
+More information may be found on the [mailing list](https://groups.google.com/d/forum/civetweb).
+
+
+Contributions
+---------------
+
+Contributions are welcome provided all contributions carry the MIT license.
+
+DO NOT APPLY fixes copied from Mongoose to this project to prevent GPL tainting.
+Since 2013 CivetWeb and Mongoose are developed independently.
+By now the code base differs, so patches cannot be safely transfered in either direction.
+
+Some guidelines can be found in [docs/Contribution.md](https://github.com/civetweb/civetweb/blob/master/docs/Contribution.md).
+
+
+### Authors
+
+CivetWeb is based on the Mongoose project.  The original author of Mongoose was
+Sergey Lyubka (Copyright (c) 2004-2013 Sergey Lyubka, MIT license).
+
+However, in August 16, 2013, the [license of Mongoose has been changed](https://groups.google.com/forum/#!topic/mongoose-users/aafbOnHonkI)
+after writing and distributing the original code this project is based on.
+The license change and CivetWeb used to be mentioned on the Mongoose
+[Wikipedia](https://en.wikipedia.org/wiki/Mongoose_(web_server))
+page as well, but it's getting deleted (and added again) there every
+now and then.
+
+CivetWeb has been forked from the last MIT version of Mongoose.
+Since 2013, CivetWeb has seen many improvements from various authors
+(Copyright (c) 2013-2017 the CivetWeb developers, MIT license).
+A list of authors can be found in [CREDITS.md](https://github.com/civetweb/civetweb/blob/master/CREDITS.md).
+
+Using the CivetWeb project ensures the MIT licenses terms are applied and
+GPL cannot be imposed on any of this code, as long as it is sourced from
+here. This code will remain free with the MIT license protection.

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/RELEASE_NOTES.md
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/RELEASE_NOTES.md b/thirdparty/civetweb-1.9.1/RELEASE_NOTES.md
new file mode 100644
index 0000000..ce9b578
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/RELEASE_NOTES.md
@@ -0,0 +1,344 @@
+Release Notes v1.9.1
+===
+### Objectives: *Bug fix*
+
+Changes
+-------
+
+- Add "open website" button for pre-built Windows binaries
+- Fix for connections closed prematurely
+- Update to a new check unit test framework and remove patches required for previous version
+- Update version number
+
+
+Release Notes v1.9
+===
+### Objectives: *Read SSI client certificate information, improve windows usability, use non-blocking sockets, bug fixes*
+
+Changes
+-------
+
+- Add library init/exit functions (call is now optional, but will be required in V1.10)
+- Windows: Show system information from the tray icon
+- Windows: Bring overlaid windows to top from the tray icon
+- Add Lua background script, running independent from server state
+- Move obsolete examples into separated directory
+- Change name of CMake generated C++ library to civetweb-cpp
+- Add option to set linger timeout
+- Update Duktape and Lua (third-party code)
+- Add continuous integration tests
+- Add API documentation
+- Limit recursions in .htpasswd files
+- Fix SCRIPT_NAME for CGI directory index files (index.php)
+- Use non-blocking sockets
+- stdint.h is now required and no longer optional
+- Rewrite connection close handling
+- Rewrite mg_fopen/mg_stat
+- Enhanced tray icon menu for Windows
+- Add subprotocol management for websocket connections
+- Partially rewrite timeout handling
+- Add option keep_alive_timeout_ms
+- Improve support for absolute URIs
+- Allow some additional compiler checks (higher warning level)
+- Add option for case sensitive file names for Windows
+- Short notation for listening_ports option when using IPv4 and IPv6 ports
+- Make usage of Linux sendfile configurable
+- Optimize build matrix for Travis CI
+- Retry failing TLS/HTTPS read/write operations
+- Read client certificate information
+- Do not tolerate URIs with invalid characters
+- Fix mg_get_cookie to ignore substrings
+- Fix memory leak in form handling
+- Fix bug in timer logic (for Lua Websockets)
+- Updated version number
+
+Release Notes v1.8
+===
+### Objectives: *CMake integration and continuous integration tests, Support client certificates, bug fixes*
+
+Changes
+-------
+
+- Replace mg_upload by mg_handle_form_request
+- CGI-scripts must receive EOF if all POST data is read
+- Add API function to handle all kinds of HTML form data
+- Do not allow short file names in Windows
+- Callback when a new thread is initialized
+- Support for short lived certificates
+- Add NO_CACHING compile option
+- Update Visual Studio project files to VS2015; rename directory VS2012 to VS
+- Sec-Wesocket-Protocol must only return one protocol
+- Mark some examples and tests as obsolete
+- Remove no longer maintained test utils
+- Add some default MIME types and the mg_send_mime_file API function.
+- Client API using SSL certificates
+- Send "Cache-Control" headers
+- Add alternative to mg_upload
+- Additional configuration options
+- Fix memory leaks
+- Add API function to check available features
+- Add new interface to get listening ports
+- Add websocket client interface and encode websocket data with a simple random number
+- Support SSL client certificates
+- Add configuration options for SSL client certificates
+- Stand-alone server: Add command line option -I to display information about the system
+- Redirect stderr of CGI process to error log
+- Support absolute URI; split uri in mg_request_info to request_uri and local_uri
+- Some source code refactoring, to improve maintainability
+- Use recursive mutex for Linux
+- Allow CGI environment to grow dynamically
+- Support build for Lua 5.1 (including LuaJIT), Lua 5.2 and Lua 5.3
+- Improve examples and documentation
+- Build option CIVETWEB_SERVE_NO_FILES to disable serving static files
+- Add Server side JavaScript support (Duktape library)
+- Created a "civetweb" organization at GitHub.
+- Repository moved from https://github.com/bel2125/civetweb to https://github.com/civetweb/civetweb
+- Improved continuous integration
+- CMake support, continuous integration with Travis CI and Appveyor
+- Adapt/port unit tests to CMake/Travis/Appveyor
+- Bug fixes, including issues from static code analysis
+- Add status badges to the GitHub project main page
+- Updated version number
+
+Release Notes v1.7
+===
+### Objectives: *Examples, documentation, additional API functions, some functions rewritten, bug fixes and updates*
+
+Changes
+-------
+
+- Format source with clang_format
+- Use function 'sendfile' for Linux
+- Fix for CRAMFS in Linux
+- Fix for file modification times in Windows
+- Use SO_EXCLUSIVEADDRUSE instead of SO_REUSEADDR for Windows
+- Rewrite push/pull functions
+- Allow to use Lua as shared objects (WITH_LUA_SHARED)
+- Fixes for many warnings
+- URI specific callbacks and different timeouts for websockets
+- Add chunked transfer support
+- Update LuaFileSystem
+- Update Lua to 5.2.4
+- Fix build for MinGW-x64, TDM-GCC and clang
+- Update SQLite to 3.8.10.2
+- Fix CGI variables SCRIPT_NAME and PATH_TRANSLATED
+- Set TCP_USER_TIMEOUT to deal faster with broken connections
+- Add a Lua form handling example
+- Return more differentiated HTTP error codes
+- Add log_access callback
+- Rewrite and comment request handling function
+- Specify in detail and document return values of callback functions
+- Set names for all threads (unless NO_THREAD_NAME is defined)
+- New API functions for TCP/HTTP clients
+- Fix upload of huge files
+- Allow multiple SSL instances within one application
+- Improve API and user documentation
+- Allow to choose between static and dynamic Lua library
+- Improve unit test
+- Use temporary file name for partially uploaded files
+- Additional API functions exported to C++
+- Add a websocket client example
+- Add a websocket client API
+- Update websocket example
+- Make content length available in request_info
+- New API functions: access context, callback for create/delete, access user data
+- Upgraded Lua from 5.2.2 to 5.2.3 and finally 5.2.4
+- Integrate LuaXML (for testing purposes)
+- Fix compiler warnings
+- Updated version number
+
+Release Notes v1.6
+===
+### Objectives: *Enhance Lua support, configuration dialog for windows, new examples, bug fixes and updates*
+
+Changes
+-------
+
+- Add examples of Lua pages, scripts and websockets to the test directory (bel)
+- Add dialog to change htpasswd files for the Windows standalone server (bel)
+- Fix compiler warnings and warnings from static code analysis (Danny Al-Gaaf, jmc-, Thomas, bel, ...)
+- Add new unit tests (bel)
+- Support includes in htpasswd files (bel)
+- Add a basic option check for the standalone executable (bel)
+- Support user defined error pages (bel)
+- Method to get POST request parameters via C++ interface (bel)
+- Re-Add unit tests for Linux and Windows (jmc-, bel)
+- Allow to specify title and tray icon for the Windows standalone server (bel)
+- Fix minor memory leaks (bel)
+- Redirect all memory allocation/deallocation through mg functions which may be overwritten (bel)
+- Support Cross-Origin Resource Sharing (CORS) for static files and scripts (bel)
+- Win32: Replace dll.def file by export macros in civetweb.h (CSTAJ)
+- Base64 encode and decode functions for Lua (bel)
+- Support pre-loaded files for the Lua environment (bel)
+- Server should check the nonce for http digest access authentication (bel)
+- Hide read-only flag in file dialogs opened by the Edit Settings dialog for the Windows executable (bel)
+- Add all functions to dll.def, that are in the header (bel)
+- Added Lua extensions: send_file, get_var, get_mime_type, get_cookie, url_decode, url_encode (bel)
+- mg_set_request_handler() mod to use pattern (bel, Patch from Toni Wilk)
+- Solved, tested and documented SSL support for Windows (bel)
+- Fixed: select for Linux needs the nfds parameter set correctly (bel)
+- Add methods for returning the ports civetweb is listening on (keithel)
+- Fixes for Lua Server Pages, as described within the google groups thread. (bel)
+- Added support for plain Lua Scripts, and an example script. (bel)
+- A completely new, and more illustrative websocket example for C. (bel)
+- Websocket for Lua (bel)
+- An optional websocket_root directory, including URL rewriting (bel)
+- Update of SQLite3 to 3.8.1. (bel)
+- Add "date" header field to replies, according to the requirements of RFC 2616 (the HTTP standard), Section 14.18 (bel)
+- Fix websocket long pull (celeron55)
+- Updated API documentation (Alex Kozlov)
+- Fixed Posix locking functions for Windows (bel2125)
+- Updated version number
+
+Release Notes v1.5
+===
+### Objectives: *Bug fixes and updates, repository restoration*
+
+Changes
+-------
+
+- Corrected bad mask flag/opcode passing to websocket callback (William Greathouse)
+- Moved CEVITWEB_VERSION define into civetweb.h
+- Added new simple zip deployment build for Windows.
+- Removed windows install package build.
+- Fixes page violation in mod_lua.inl (apkbox)
+- Use C style comments to enable compiling most of civetweb with -ansi. (F-Secure Corporation)
+- Allow directories with non ASCII characters in Windows in UTF-8 encoded (bel2125)
+- Added Lua File System support (bel2125)
+- Added mongoose history back in repository thanks to (Paul Sokolovsky)
+- Fixed keep alive (bel2125)
+- Updated of MIME types (bel2125)
+- Updated lsqlite (bel2125)
+- Fixed master thread priority (bel2125)
+- Fixed IPV6 defines under Windowe (grenclave)
+- Fixed potential dead lock in connection_close() (Morgan McGuire)
+- Added WebSocket example using asynchronous server messages (William Greathouse)
+- Fixed the getcwd() warning (William Greathouse)
+- Implemented the connection_close() callback (William Greathouse)
+- Fixed support URL's in civetweb.c (Daniel Oaks)
+- Allow port number to be zero to use a random free port (F-Secure Corporation)
+- Wait for threads to finish when stopping for a clean shutdown (F-Secure Corporation)
+- More static analysis fixes against Coverity tool (F-Secure Corporation)
+- Travis automated build testing support added (Daniel Oaks)
+- Updated version numbers.
+- Added contributor credits file.
+
+Release Notes v1.4
+===
+### Objectives: *New URI handler interface, feature enhancements, C++ extensions*
+The main idea behind this release is to bring about API consistency. All changes
+are backward compatible and have been kept to a minimum.
+
+Changes
+-------
+
+- Added mg_set_request_handler() which provides a URI mapping for callbacks.
+   This is a new alternative to overriding callbacks.begin_request.
+- Externalized mg_url_encode()
+- Externalized mg_strncasecmp() for utiliy
+- Added CivetServer::getParam methods
+- Added CivetServer::urlDecode methods
+- Added CivetServer::urlEncode methods
+- Dealt with compiler warnings and some static analysis hits.
+- Added mg_get_var2() to parse repeated query variables
+- Externalized logging function cry() as mg_cry()
+- Added CivetServer::getCookie method (Hariprasad Kamath)
+- Added CivetServer::getHeader method (Hariprasad Kamath)
+- Added new basic C embedding example
+- Conformed source files to UNIX line endings for consistency.
+- Unified the coding style to improve reability.
+
+Release Notes v1.3
+===
+### Objectives: *Buildroot Integration*
+
+Changes
+-------
+
+- Made option to put initial HTMLDIR in a different place
+- Validated build without SQLITE3 large file support
+- Updated documentation
+- Updated Buildroot config example
+
+Release Notes v1.2
+===
+### Objectives: *Installation Improvements, buildroot, cross compile support*
+The objective of this release is to make installation seamless.
+
+Changes
+-------
+
+- Create an installation guide
+- Created both 32 and 64 bit windows installations
+- Added install for windows distribution
+- Added 64 bit build profiles for VS 2012.
+- Created a buildroot patch
+- Updated makefile to better support buildroot
+- Made doc root and ports configurable during the make install.
+- Updated Linux Install
+- Updated OS X Package
+- Improved install scheme with welcome web page
+
+Known Issues
+-----
+
+- The prebuilt Window's version requires [Visual C++ Redistributable for Visual Studio 2012](http://www.microsoft.com/en-us/download/details.aspx?id=30679)
+
+Release Notes v1.1
+===
+### Objectives: *Build, Documentation, License Improvements*
+The objective of this release is to establish a maintable code base, ensure MIT license rights and improve usability and documentation.
+
+Changes
+-------
+
+- Reorangized build directories to make them more intuitive
+- Added new build rules for lib and slib with option to include C++ class
+- Upgraded Lua from 5.2.1 to 5.2.2
+- Added fallback configuration file path for Linux systems.
+    + Good for having a system wide default configuration /usr/local/etc/civetweb.conf
+- Added new C++ abstraction class CivetServer
+- Added thread safety for and fixed websocket defects (Morgan McGuire)
+- Created PKGBUILD to use Arch distribution (Daniel Oaks)
+- Created new documentation on Embeddeding, Building and yaSSL (see docs/).
+- Updated License file to include all licenses.
+- Replaced MD5 implementation due to questionable license.
+     + This requires new source file md5.inl
+- Changed UNIX/OSX build to conform to common practices.
+     + Supports build, install and clean rules.
+     + Supports cross compiling
+     + Features can be chosen in make options
+- Moved Cocoa/OSX build and packaging to a separate file.
+     + This actually a second build variant for OSX.
+     + Removed yaSSL from the OSX build, not needed.
+- Added new Visual Studio projects for Windows builds.
+     + Removed Windows support from Makefiles
+     + Provided additional, examples with Lua, and another with yaSSL.
+- Changed Zombie Reaping policy to not ignore SIGCHLD.
+     + The previous method caused trouble in applciations that spawn children.
+
+Known Issues
+-----
+
+- Build support for VS6 and some other has been deprecated.
+    + This does not impact embedded programs, just the stand-alone build.
+    + The old Makefile was renamed to Makefile.deprecated.
+    + This is partcially do to lack fo testing.
+    + Need to find out what is actually in demand.
+- Build changes may impact current users.
+    + As with any change of this type, changes may impact some users.
+
+Release Notes v1.0
+===
+
+### Objectives: *MIT License Preservation, Rebranding*
+The objective of this release is to establish a version of the Mongoose software distribution that still retains the MIT license.
+
+Changes
+-------
+
+- Renamed Mongoose to Civetweb in the code and documentation.
+- Replaced copyrighted images with new images
+- Created a new code respository at https://github.com/bel2125/civetweb
+- Created a distribution site at https://sourceforge.net/projects/civetweb/
+- Basic build testing

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/VisualStudio/buildRelease.pl
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/VisualStudio/buildRelease.pl b/thirdparty/civetweb-1.9.1/VisualStudio/buildRelease.pl
new file mode 100644
index 0000000..df8db09
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/VisualStudio/buildRelease.pl
@@ -0,0 +1,71 @@
+#!/usr/bin/perl
+# 
+# Copyright (c) 2013 No Face Press, LLC
+# License http://opensource.org/licenses/mit-license.php MIT License
+#
+
+# This script builds and packages a Windows release.
+# It requires ActiveState Perl to use and is intended
+# to be run from the its directory under the 
+# VS Developer Command Prompt.
+
+# Create a Zip file
+use Archive::Zip qw( :ERROR_CODES :CONSTANTS );
+my $zip = Archive::Zip->new();
+
+my $src = "..";
+
+sub getCivetwebVersion {
+    print "Fetching CivetWeb version...\n";
+    open HEADER, "${src}/include/civetweb.h";
+    while (<HEADER>) {
+        if (m/define\s+CIVETWEB_VERSION\s+"(.+)"/) {
+            close HEADER;
+            return $1;
+        }
+    }
+    close HEADER;
+    return "UNKNOWN_VERSION";
+}
+
+my $CIVETWEB_VERSION = getCivetwebVersion();
+my $basename         = "civetweb-$CIVETWEB_VERSION";
+my $dir              = "${basename}";
+
+sub build32() {
+    print "\nBuilding Win32 Release version...\n";
+    system("msbuild /p:Configuration=Release /p:Platform=Win32 civetweb.sln");
+}
+
+sub build64() {
+    print "\nBuilding x64 Release version...\n";
+    system("msbuild /p:Configuration=Release /p:Platform=x64 civetweb.sln");
+}
+
+sub writeArchive() {
+    my $archive = "${basename}-win.zip";
+    print "Creating archive $archive ...\n";
+
+    $zip->addDirectory("${dir}/");
+
+    $zip->addFile( "${src}/LICENSE.md",            "${dir}/LICENSE.md" );
+    $zip->addFile( "${src}/README.md",             "${dir}/README.md" );
+    $zip->addFile( "${src}/resources/systray.ico", "${dir}/systray.ico" );
+    $zip->addFile( "${src}/resources/civetweb_64x64.png",
+        "${dir}/civetweb_64x64.png" );
+    $zip->addFile( "${src}/resources/itworks.html", "${dir}/index.html" );
+    $zip->addFile( "${src}/VS2012/Release/Win32/civetweb_lua.exe",
+        "${dir}/civetweb32.exe" );
+    $zip->addFile( "${src}/VS2012/Release/x64/civetweb_lua.exe",
+        "${dir}/civetweb64.exe" );
+
+    unless ( $zip->writeToFileNamed($archive) == AZ_OK ) {
+        die 'write error';
+    }
+
+}
+
+build32();
+build64();
+writeArchive();
+exit 0;

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/VisualStudio/civetweb.sln
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/VisualStudio/civetweb.sln b/thirdparty/civetweb-1.9.1/VisualStudio/civetweb.sln
new file mode 100644
index 0000000..a5dac7a
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/VisualStudio/civetweb.sln
@@ -0,0 +1,75 @@
+\ufeff
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio 14
+VisualStudioVersion = 14.0.23107.0
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "civetweb_lua", "civetweb_lua\civetweb_lua.vcxproj", "{9BE9C008-E851-42B1-A034-BD4630AE4CD6}"
+	ProjectSection(ProjectDependencies) = postProject
+		{0A11689C-DB6A-4BF6-97B2-AD32DB863FBD} = {0A11689C-DB6A-4BF6-97B2-AD32DB863FBD}
+	EndProjectSection
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "lua_lib", "lua_lib\lua_lib.vcxproj", "{8F5E5D77-D269-4665-9E27-1045DA6CF0D8}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ex_embedded_c", "ex_embedded_c\ex_embedded_c.vcxproj", "{882EC43C-2EEE-434B-A711-C844108D29C6}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "unit_test", "unit_test\unit_test.vcxproj", "{1AC4A7A6-0100-4287-97F4-B95807BE5607}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "duktape_lib", "duktape_lib\duktape_lib.vcxproj", "{0A11689C-DB6A-4BF6-97B2-AD32DB863FBD}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ex_embed_cpp", "ex_embed_cpp\ex_embed_cpp.vcxproj", "{4308C5EE-45E4-45D8-9D73-6C4E2587AD78}"
+EndProject
+Global
+	GlobalSection(SolutionConfigurationPlatforms) = preSolution
+		Debug|Win32 = Debug|Win32
+		Debug|x64 = Debug|x64
+		Release|Win32 = Release|Win32
+		Release|x64 = Release|x64
+	EndGlobalSection
+	GlobalSection(ProjectConfigurationPlatforms) = postSolution
+		{9BE9C008-E851-42B1-A034-BD4630AE4CD6}.Debug|Win32.ActiveCfg = Debug|Win32
+		{9BE9C008-E851-42B1-A034-BD4630AE4CD6}.Debug|Win32.Build.0 = Debug|Win32
+		{9BE9C008-E851-42B1-A034-BD4630AE4CD6}.Debug|x64.ActiveCfg = Debug|x64
+		{9BE9C008-E851-42B1-A034-BD4630AE4CD6}.Debug|x64.Build.0 = Debug|x64
+		{9BE9C008-E851-42B1-A034-BD4630AE4CD6}.Release|Win32.ActiveCfg = Release|Win32
+		{9BE9C008-E851-42B1-A034-BD4630AE4CD6}.Release|Win32.Build.0 = Release|Win32
+		{9BE9C008-E851-42B1-A034-BD4630AE4CD6}.Release|x64.ActiveCfg = Release|x64
+		{9BE9C008-E851-42B1-A034-BD4630AE4CD6}.Release|x64.Build.0 = Release|x64
+		{8F5E5D77-D269-4665-9E27-1045DA6CF0D8}.Debug|Win32.ActiveCfg = Debug|Win32
+		{8F5E5D77-D269-4665-9E27-1045DA6CF0D8}.Debug|Win32.Build.0 = Debug|Win32
+		{8F5E5D77-D269-4665-9E27-1045DA6CF0D8}.Debug|x64.ActiveCfg = Debug|x64
+		{8F5E5D77-D269-4665-9E27-1045DA6CF0D8}.Debug|x64.Build.0 = Debug|x64
+		{8F5E5D77-D269-4665-9E27-1045DA6CF0D8}.Release|Win32.ActiveCfg = Release|Win32
+		{8F5E5D77-D269-4665-9E27-1045DA6CF0D8}.Release|Win32.Build.0 = Release|Win32
+		{8F5E5D77-D269-4665-9E27-1045DA6CF0D8}.Release|x64.ActiveCfg = Release|x64
+		{8F5E5D77-D269-4665-9E27-1045DA6CF0D8}.Release|x64.Build.0 = Release|x64
+		{882EC43C-2EEE-434B-A711-C844108D29C6}.Debug|Win32.ActiveCfg = Debug|Win32
+		{882EC43C-2EEE-434B-A711-C844108D29C6}.Debug|Win32.Build.0 = Debug|Win32
+		{882EC43C-2EEE-434B-A711-C844108D29C6}.Debug|x64.ActiveCfg = Debug|x64
+		{882EC43C-2EEE-434B-A711-C844108D29C6}.Release|Win32.ActiveCfg = Release|Win32
+		{882EC43C-2EEE-434B-A711-C844108D29C6}.Release|Win32.Build.0 = Release|Win32
+		{882EC43C-2EEE-434B-A711-C844108D29C6}.Release|x64.ActiveCfg = Release|x64
+		{1AC4A7A6-0100-4287-97F4-B95807BE5607}.Debug|Win32.ActiveCfg = Debug|Win32
+		{1AC4A7A6-0100-4287-97F4-B95807BE5607}.Debug|Win32.Build.0 = Debug|Win32
+		{1AC4A7A6-0100-4287-97F4-B95807BE5607}.Debug|x64.ActiveCfg = Debug|Win32
+		{1AC4A7A6-0100-4287-97F4-B95807BE5607}.Release|Win32.ActiveCfg = Release|Win32
+		{1AC4A7A6-0100-4287-97F4-B95807BE5607}.Release|Win32.Build.0 = Release|Win32
+		{1AC4A7A6-0100-4287-97F4-B95807BE5607}.Release|x64.ActiveCfg = Release|Win32
+		{0A11689C-DB6A-4BF6-97B2-AD32DB863FBD}.Debug|Win32.ActiveCfg = Debug|Win32
+		{0A11689C-DB6A-4BF6-97B2-AD32DB863FBD}.Debug|Win32.Build.0 = Debug|Win32
+		{0A11689C-DB6A-4BF6-97B2-AD32DB863FBD}.Debug|x64.ActiveCfg = Debug|x64
+		{0A11689C-DB6A-4BF6-97B2-AD32DB863FBD}.Debug|x64.Build.0 = Debug|x64
+		{0A11689C-DB6A-4BF6-97B2-AD32DB863FBD}.Release|Win32.ActiveCfg = Release|Win32
+		{0A11689C-DB6A-4BF6-97B2-AD32DB863FBD}.Release|Win32.Build.0 = Release|Win32
+		{0A11689C-DB6A-4BF6-97B2-AD32DB863FBD}.Release|x64.ActiveCfg = Release|x64
+		{0A11689C-DB6A-4BF6-97B2-AD32DB863FBD}.Release|x64.Build.0 = Release|x64
+		{4308C5EE-45E4-45D8-9D73-6C4E2587AD78}.Debug|Win32.ActiveCfg = Debug|Win32
+		{4308C5EE-45E4-45D8-9D73-6C4E2587AD78}.Debug|Win32.Build.0 = Debug|Win32
+		{4308C5EE-45E4-45D8-9D73-6C4E2587AD78}.Debug|x64.ActiveCfg = Debug|x64
+		{4308C5EE-45E4-45D8-9D73-6C4E2587AD78}.Release|Win32.ActiveCfg = Release|Win32
+		{4308C5EE-45E4-45D8-9D73-6C4E2587AD78}.Release|Win32.Build.0 = Release|Win32
+		{4308C5EE-45E4-45D8-9D73-6C4E2587AD78}.Release|x64.ActiveCfg = Release|x64
+	EndGlobalSection
+	GlobalSection(SolutionProperties) = preSolution
+		HideSolutionNode = FALSE
+	EndGlobalSection
+EndGlobal

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/VisualStudio/civetweb_lua/civetweb_lua.vcxproj
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/VisualStudio/civetweb_lua/civetweb_lua.vcxproj b/thirdparty/civetweb-1.9.1/VisualStudio/civetweb_lua/civetweb_lua.vcxproj
new file mode 100644
index 0000000..2244947
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/VisualStudio/civetweb_lua/civetweb_lua.vcxproj
@@ -0,0 +1,215 @@
+\ufeff<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <ItemGroup Label="ProjectConfigurations">
+    <ProjectConfiguration Include="Debug|Win32">
+      <Configuration>Debug</Configuration>
+      <Platform>Win32</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Debug|x64">
+      <Configuration>Debug</Configuration>
+      <Platform>x64</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Release|Win32">
+      <Configuration>Release</Configuration>
+      <Platform>Win32</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Release|x64">
+      <Configuration>Release</Configuration>
+      <Platform>x64</Platform>
+    </ProjectConfiguration>
+  </ItemGroup>
+  <PropertyGroup Label="Globals">
+    <ProjectGuid>{9BE9C008-E851-42B1-A034-BD4630AE4CD6}</ProjectGuid>
+    <Keyword>Win32Proj</Keyword>
+    <RootNamespace>civetweb_lua</RootNamespace>
+  </PropertyGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>true</UseDebugLibraries>
+    <CharacterSet>MultiByte</CharacterSet>
+    <PlatformToolset>v140</PlatformToolset>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>true</UseDebugLibraries>
+    <PlatformToolset>v140</PlatformToolset>
+    <CharacterSet>MultiByte</CharacterSet>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug CONSOLE|x64'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>true</UseDebugLibraries>
+    <PlatformToolset>v110</PlatformToolset>
+    <CharacterSet>MultiByte</CharacterSet>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>false</UseDebugLibraries>
+    <WholeProgramOptimization>true</WholeProgramOptimization>
+    <CharacterSet>MultiByte</CharacterSet>
+    <PlatformToolset>v140</PlatformToolset>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>false</UseDebugLibraries>
+    <PlatformToolset>v140</PlatformToolset>
+    <WholeProgramOptimization>true</WholeProgramOptimization>
+    <CharacterSet>MultiByte</CharacterSet>
+  </PropertyGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+  <ImportGroup Label="ExtensionSettings">
+  </ImportGroup>
+  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug CONSOLE|x64'" Label="PropertySheets">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <PropertyGroup Label="UserMacros" />
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <LinkIncremental>true</LinkIncremental>
+    <OutDir>$(SolutionDir)\$(Configuration)\$(Platform)\</OutDir>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+    <LinkIncremental>true</LinkIncremental>
+    <OutDir>$(SolutionDir)\$(Configuration)\$(Platform)\</OutDir>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug CONSOLE|x64'">
+    <LinkIncremental>true</LinkIncremental>
+    <OutDir>$(SolutionDir)\$(Configuration)\$(Platform)\</OutDir>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <LinkIncremental>false</LinkIncremental>
+    <OutDir>$(SolutionDir)\$(Configuration)\$(Platform)\</OutDir>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+    <LinkIncremental>false</LinkIncremental>
+    <OutDir>$(SolutionDir)\$(Configuration)\$(Platform)\</OutDir>
+  </PropertyGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <ClCompile>
+      <PrecompiledHeader>
+      </PrecompiledHeader>
+      <WarningLevel>Level3</WarningLevel>
+      <Optimization>Disabled</Optimization>
+      <PreprocessorDefinitions>USE_DUKTAPE;USE_IPV6;LUA_COMPAT_ALL;USE_LUA;USE_LUA_SQLITE3;USE_LUA_FILE_SYSTEM;USE_WEBSOCKET;WIN32;_DEBUG;_WINDOWS;_CRT_SECURE_NO_DEPRECATE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <AdditionalIncludeDirectories>$(ProjectDir)..\..\include;$(ProjectDir)..\..\src\third_party;$(ProjectDir)..\..\src\third_party\lua-5.2.4\src;$(ProjectDir)..\..\src\third_party\duktape-1.5.2\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+    </ClCompile>
+    <Link>
+      <SubSystem>Windows</SubSystem>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+    <ClCompile>
+      <PrecompiledHeader>
+      </PrecompiledHeader>
+      <WarningLevel>Level3</WarningLevel>
+      <Optimization>Disabled</Optimization>
+      <PreprocessorDefinitions>USE_DUKTAPE;USE_IPV6;LUA_COMPAT_ALL;USE_LUA;USE_LUA_SQLITE3;USE_LUA_FILE_SYSTEM;USE_WEBSOCKET;WIN32;_DEBUG;_WINDOWS;_CRT_SECURE_NO_DEPRECATE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <AdditionalIncludeDirectories>$(ProjectDir)..\..\include;$(ProjectDir)..\..\src\third_party;$(ProjectDir)..\..\src\third_party\lua-5.2.4\src;$(ProjectDir)..\..\src\third_party\duktape-1.5.2\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+    </ClCompile>
+    <Link>
+      <SubSystem>Windows</SubSystem>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug CONSOLE|x64'">
+    <ClCompile>
+      <PrecompiledHeader>
+      </PrecompiledHeader>
+      <WarningLevel>Level3</WarningLevel>
+      <Optimization>Disabled</Optimization>
+      <PreprocessorDefinitions>LUA_COMPAT_ALL;USE_LUA;USE_LUA_SQLITE3;USE_LUA_FILE_SYSTEM;USE_WEBSOCKET;WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <AdditionalIncludeDirectories>$(ProjectDir)..\..\include;$(ProjectDir)..\..\src\third_party\lua-5.2.4\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+    </ClCompile>
+    <Link>
+      <SubSystem>Windows</SubSystem>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <ClCompile>
+      <WarningLevel>Level3</WarningLevel>
+      <PrecompiledHeader>
+      </PrecompiledHeader>
+      <Optimization>MaxSpeed</Optimization>
+      <FunctionLevelLinking>true</FunctionLevelLinking>
+      <IntrinsicFunctions>true</IntrinsicFunctions>
+      <PreprocessorDefinitions>USE_DUKTAPE;USE_IPV6;LUA_COMPAT_ALL;USE_LUA;USE_LUA_SQLITE3;USE_LUA_FILE_SYSTEM;USE_WEBSOCKET;WIN32;_WINDOWS;_CRT_SECURE_NO_DEPRECATE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <AdditionalIncludeDirectories>$(ProjectDir)..\..\include;$(ProjectDir)..\..\src\third_party;$(ProjectDir)..\..\src\third_party\lua-5.2.4\src;$(ProjectDir)..\..\src\third_party\duktape-1.5.2\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+    </ClCompile>
+    <Link>
+      <SubSystem>Windows</SubSystem>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>
+      <OptimizeReferences>true</OptimizeReferences>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+    <ClCompile>
+      <WarningLevel>Level3</WarningLevel>
+      <PrecompiledHeader>
+      </PrecompiledHeader>
+      <Optimization>MaxSpeed</Optimization>
+      <FunctionLevelLinking>true</FunctionLevelLinking>
+      <IntrinsicFunctions>true</IntrinsicFunctions>
+      <PreprocessorDefinitions>USE_DUKTAPE;USE_IPV6;LUA_COMPAT_ALL;USE_LUA;USE_LUA_SQLITE3;USE_LUA_FILE_SYSTEM;USE_WEBSOCKET;WIN32;_WINDOWS;_CRT_SECURE_NO_DEPRECATE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <AdditionalIncludeDirectories>$(ProjectDir)..\..\include;$(ProjectDir)..\..\src\third_party;$(ProjectDir)..\..\src\third_party\lua-5.2.4\src;$(ProjectDir)..\..\src\third_party\duktape-1.5.2\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+    </ClCompile>
+    <Link>
+      <SubSystem>Windows</SubSystem>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>
+      <OptimizeReferences>true</OptimizeReferences>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemGroup>
+    <Text Include="ReadMe.txt" />
+  </ItemGroup>
+  <ItemGroup>
+    <ClInclude Include="..\..\include\civetweb.h" />
+    <ClInclude Include="..\..\src\third_party\civetweb_lua.h" />
+    <ClInclude Include="..\..\src\third_party\lua-5.2.4\src\lauxlib.h" />
+    <ClInclude Include="..\..\src\third_party\lua-5.2.4\src\lua.h" />
+  </ItemGroup>
+  <ItemGroup>
+    <ClCompile Include="..\..\src\civetweb.c" />
+    <ClCompile Include="..\..\src\main.c" />
+  </ItemGroup>
+  <ItemGroup>
+    <ResourceCompile Include="..\..\resources\res.rc" />
+  </ItemGroup>
+  <ItemGroup>
+    <Image Include="..\..\resources\systray.ico" />
+  </ItemGroup>
+  <ItemGroup>
+    <ProjectReference Include="..\lua_lib\lua_lib.vcxproj">
+      <Project>{8f5e5d77-d269-4665-9e27-1045da6cf0d8}</Project>
+    </ProjectReference>
+    <ProjectReference Include="..\duktape_lib\duktape_lib.vcxproj">
+      <Project>{0A11689C-DB6A-4BF6-97B2-AD32DB863FBD}</Project>
+    </ProjectReference>
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="..\..\src\handle_form.inl" />
+    <None Include="..\..\src\md5.inl" />
+    <None Include="..\..\src\sha1.inl" />
+    <None Include="..\..\src\mod_duktape.inl" />
+    <None Include="..\..\src\mod_lua.inl" />
+    <None Include="..\..\src\timer.inl" />
+    <None Include="..\..\src\file_ops.inl" />
+  </ItemGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+  <ImportGroup Label="ExtensionTargets">
+  </ImportGroup>
+</Project>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/VisualStudio/civetweb_lua/civetweb_lua.vcxproj.filters
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/VisualStudio/civetweb_lua/civetweb_lua.vcxproj.filters b/thirdparty/civetweb-1.9.1/VisualStudio/civetweb_lua/civetweb_lua.vcxproj.filters
new file mode 100644
index 0000000..caf951c
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/VisualStudio/civetweb_lua/civetweb_lua.vcxproj.filters
@@ -0,0 +1,78 @@
+\ufeff<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <ItemGroup>
+    <Filter Include="Source Files">
+      <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
+      <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
+    </Filter>
+    <Filter Include="Header Files">
+      <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
+      <Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
+    </Filter>
+    <Filter Include="Resource Files">
+      <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
+      <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
+    </Filter>
+    <Filter Include="inl files">
+      <UniqueIdentifier>{1ef3413b-2315-48f2-ad22-57af6b4f7aca}</UniqueIdentifier>
+    </Filter>
+  </ItemGroup>
+  <ItemGroup>
+    <Text Include="ReadMe.txt" />
+  </ItemGroup>
+  <ItemGroup>
+    <ClInclude Include="..\..\include\civetweb.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+    <ClInclude Include="..\..\src\third_party\lua-5.2.4\src\lua.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+    <ClInclude Include="..\..\src\third_party\lua-5.2.4\src\lauxlib.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+    <ClInclude Include="..\..\src\third_party\civetweb_lua.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+  </ItemGroup>
+  <ItemGroup>
+    <ClCompile Include="..\..\src\civetweb.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\main.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+  </ItemGroup>
+  <ItemGroup>
+    <ResourceCompile Include="..\..\resources\res.rc">
+      <Filter>Resource Files</Filter>
+    </ResourceCompile>
+  </ItemGroup>
+  <ItemGroup>
+    <Image Include="..\..\resources\systray.ico">
+      <Filter>Resource Files</Filter>
+    </Image>
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="..\..\src\md5.inl">
+      <Filter>inl files</Filter>
+    </None>
+    <None Include="..\..\src\sha1.inl">
+      <Filter>inl files</Filter>
+    </None>
+    <None Include="..\..\src\mod_lua.inl">
+      <Filter>inl files</Filter>
+    </None>
+    <None Include="..\..\src\timer.inl">
+      <Filter>inl files</Filter>
+    </None>
+    <None Include="..\..\src\file_ops.inl">
+      <Filter>inl files</Filter>
+    </None>
+    <None Include="..\..\src\mod_duktape.inl">
+      <Filter>inl files</Filter>
+    </None>
+    <None Include="..\..\src\handle_form.inl">
+      <Filter>inl files</Filter>
+    </None>
+  </ItemGroup>
+</Project>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/VisualStudio/civetweb_yassl/civetweb_yassl.sln
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/VisualStudio/civetweb_yassl/civetweb_yassl.sln b/thirdparty/civetweb-1.9.1/VisualStudio/civetweb_yassl/civetweb_yassl.sln
new file mode 100644
index 0000000..49e36ce
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/VisualStudio/civetweb_yassl/civetweb_yassl.sln
@@ -0,0 +1,36 @@
+\ufeff
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio 2012
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "civetweb_yassl", "civetweb_yassl\civetweb_yassl.vcxproj", "{F02517CC-F896-41A2-86E4-509E55C70059}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "yassl_lib", "yassl_lib\yassl_lib.vcxproj", "{8C0C878B-BBD6-4241-BCA6-61753FFCC7F1}"
+EndProject
+Global
+	GlobalSection(SolutionConfigurationPlatforms) = preSolution
+		Debug|Win32 = Debug|Win32
+		Debug|x64 = Debug|x64
+		Release|Win32 = Release|Win32
+		Release|x64 = Release|x64
+	EndGlobalSection
+	GlobalSection(ProjectConfigurationPlatforms) = postSolution
+		{F02517CC-F896-41A2-86E4-509E55C70059}.Debug|Win32.ActiveCfg = Debug|Win32
+		{F02517CC-F896-41A2-86E4-509E55C70059}.Debug|Win32.Build.0 = Debug|Win32
+		{F02517CC-F896-41A2-86E4-509E55C70059}.Debug|x64.ActiveCfg = Debug|x64
+		{F02517CC-F896-41A2-86E4-509E55C70059}.Debug|x64.Build.0 = Debug|x64
+		{F02517CC-F896-41A2-86E4-509E55C70059}.Release|Win32.ActiveCfg = Release|Win32
+		{F02517CC-F896-41A2-86E4-509E55C70059}.Release|Win32.Build.0 = Release|Win32
+		{F02517CC-F896-41A2-86E4-509E55C70059}.Release|x64.ActiveCfg = Release|x64
+		{F02517CC-F896-41A2-86E4-509E55C70059}.Release|x64.Build.0 = Release|x64
+		{8C0C878B-BBD6-4241-BCA6-61753FFCC7F1}.Debug|Win32.ActiveCfg = Debug|Win32
+		{8C0C878B-BBD6-4241-BCA6-61753FFCC7F1}.Debug|Win32.Build.0 = Debug|Win32
+		{8C0C878B-BBD6-4241-BCA6-61753FFCC7F1}.Debug|x64.ActiveCfg = Debug|x64
+		{8C0C878B-BBD6-4241-BCA6-61753FFCC7F1}.Debug|x64.Build.0 = Debug|x64
+		{8C0C878B-BBD6-4241-BCA6-61753FFCC7F1}.Release|Win32.ActiveCfg = Release|Win32
+		{8C0C878B-BBD6-4241-BCA6-61753FFCC7F1}.Release|Win32.Build.0 = Release|Win32
+		{8C0C878B-BBD6-4241-BCA6-61753FFCC7F1}.Release|x64.ActiveCfg = Release|x64
+		{8C0C878B-BBD6-4241-BCA6-61753FFCC7F1}.Release|x64.Build.0 = Release|x64
+	EndGlobalSection
+	GlobalSection(SolutionProperties) = preSolution
+		HideSolutionNode = FALSE
+	EndGlobalSection
+EndGlobal

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/VisualStudio/civetweb_yassl/civetweb_yassl/civetweb_yassl.vcxproj
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/VisualStudio/civetweb_yassl/civetweb_yassl/civetweb_yassl.vcxproj b/thirdparty/civetweb-1.9.1/VisualStudio/civetweb_yassl/civetweb_yassl/civetweb_yassl.vcxproj
new file mode 100644
index 0000000..b9a048e
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/VisualStudio/civetweb_yassl/civetweb_yassl/civetweb_yassl.vcxproj
@@ -0,0 +1,170 @@
+\ufeff<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <ItemGroup Label="ProjectConfigurations">
+    <ProjectConfiguration Include="Debug|Win32">
+      <Configuration>Debug</Configuration>
+      <Platform>Win32</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Debug|x64">
+      <Configuration>Debug</Configuration>
+      <Platform>x64</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Release|Win32">
+      <Configuration>Release</Configuration>
+      <Platform>Win32</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Release|x64">
+      <Configuration>Release</Configuration>
+      <Platform>x64</Platform>
+    </ProjectConfiguration>
+  </ItemGroup>
+  <PropertyGroup Label="Globals">
+    <ProjectGuid>{F02517CC-F896-41A2-86E4-509E55C70059}</ProjectGuid>
+    <Keyword>Win32Proj</Keyword>
+    <RootNamespace>civetweb_yassl</RootNamespace>
+  </PropertyGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>true</UseDebugLibraries>
+    <PlatformToolset>v110</PlatformToolset>
+    <CharacterSet>MultiByte</CharacterSet>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>true</UseDebugLibraries>
+    <PlatformToolset>v110</PlatformToolset>
+    <CharacterSet>MultiByte</CharacterSet>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>false</UseDebugLibraries>
+    <PlatformToolset>v110</PlatformToolset>
+    <WholeProgramOptimization>true</WholeProgramOptimization>
+    <CharacterSet>MultiByte</CharacterSet>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>false</UseDebugLibraries>
+    <PlatformToolset>v110</PlatformToolset>
+    <WholeProgramOptimization>true</WholeProgramOptimization>
+    <CharacterSet>MultiByte</CharacterSet>
+  </PropertyGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+  <ImportGroup Label="ExtensionSettings">
+  </ImportGroup>
+  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <PropertyGroup Label="UserMacros" />
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <LinkIncremental>true</LinkIncremental>
+    <OutDir>$(SolutionDir)\$(Configuration)\$(Platform)</OutDir>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+    <LinkIncremental>true</LinkIncremental>
+    <OutDir>$(SolutionDir)\$(Configuration)\$(Platform)</OutDir>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <LinkIncremental>false</LinkIncremental>
+    <OutDir>$(SolutionDir)\$(Configuration)\$(Platform)</OutDir>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+    <LinkIncremental>false</LinkIncremental>
+    <OutDir>$(SolutionDir)\$(Configuration)\$(Platform)</OutDir>
+  </PropertyGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <ClCompile>
+      <PrecompiledHeader>
+      </PrecompiledHeader>
+      <WarningLevel>Level3</WarningLevel>
+      <Optimization>Disabled</Optimization>
+      <PreprocessorDefinitions>USE_YASSL;NO_SSL_DL;WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <AdditionalIncludeDirectories>$(ProjectDir)..\..\..\include;$(ProjectDir)..\..\..\..\cyassl-2.7.0\;$(ProjectDir)..\..\..\..\cyassl-2.7.0\cyassl\</AdditionalIncludeDirectories>
+    </ClCompile>
+    <Link>
+      <SubSystem>Windows</SubSystem>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+    <ClCompile>
+      <PrecompiledHeader>
+      </PrecompiledHeader>
+      <WarningLevel>Level3</WarningLevel>
+      <Optimization>Disabled</Optimization>
+      <PreprocessorDefinitions>USE_YASSL;NO_SSL_DL;WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <AdditionalIncludeDirectories>$(ProjectDir)..\..\..\include;$(ProjectDir)..\..\..\..\cyassl-2.7.0\;$(ProjectDir)..\..\..\..\cyassl-2.7.0\cyassl\</AdditionalIncludeDirectories>
+    </ClCompile>
+    <Link>
+      <SubSystem>Windows</SubSystem>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <ClCompile>
+      <WarningLevel>Level3</WarningLevel>
+      <PrecompiledHeader>
+      </PrecompiledHeader>
+      <Optimization>MaxSpeed</Optimization>
+      <FunctionLevelLinking>true</FunctionLevelLinking>
+      <IntrinsicFunctions>true</IntrinsicFunctions>
+      <PreprocessorDefinitions>USE_YASSL;NO_SSL_DL;WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <AdditionalIncludeDirectories>$(ProjectDir)..\..\..\include;$(ProjectDir)..\..\..\..\cyassl-2.7.0\;$(ProjectDir)..\..\..\..\cyassl-2.7.0\cyassl\</AdditionalIncludeDirectories>
+    </ClCompile>
+    <Link>
+      <SubSystem>Windows</SubSystem>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>
+      <OptimizeReferences>true</OptimizeReferences>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+    <ClCompile>
+      <WarningLevel>Level3</WarningLevel>
+      <PrecompiledHeader>
+      </PrecompiledHeader>
+      <Optimization>MaxSpeed</Optimization>
+      <FunctionLevelLinking>true</FunctionLevelLinking>
+      <IntrinsicFunctions>true</IntrinsicFunctions>
+      <PreprocessorDefinitions>USE_YASSL;NO_SSL_DL;WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <AdditionalIncludeDirectories>$(ProjectDir)..\..\..\include;$(ProjectDir)..\..\..\..\cyassl-2.7.0\;$(ProjectDir)..\..\..\..\cyassl-2.7.0\cyassl\</AdditionalIncludeDirectories>
+    </ClCompile>
+    <Link>
+      <SubSystem>Windows</SubSystem>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>
+      <OptimizeReferences>true</OptimizeReferences>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemGroup>
+    <ClInclude Include="..\..\..\include\civetweb.h" />
+  </ItemGroup>
+  <ItemGroup>
+    <ClCompile Include="..\..\..\src\civetweb.c" />
+    <ClCompile Include="..\..\..\src\main.c" />
+  </ItemGroup>
+  <ItemGroup>
+    <ResourceCompile Include="..\..\..\resources\res.rc" />
+  </ItemGroup>
+  <ItemGroup>
+    <Image Include="..\..\..\resources\systray.ico" />
+  </ItemGroup>
+  <ItemGroup>
+    <ProjectReference Include="..\yassl_lib\yassl_lib.vcxproj">
+      <Project>{8c0c878b-bbd6-4241-bca6-61753ffcc7f1}</Project>
+    </ProjectReference>
+  </ItemGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+  <ImportGroup Label="ExtensionTargets">
+  </ImportGroup>
+</Project>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/VisualStudio/civetweb_yassl/civetweb_yassl/civetweb_yassl.vcxproj.filters
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/VisualStudio/civetweb_yassl/civetweb_yassl/civetweb_yassl.vcxproj.filters b/thirdparty/civetweb-1.9.1/VisualStudio/civetweb_yassl/civetweb_yassl/civetweb_yassl.vcxproj.filters
new file mode 100644
index 0000000..1c5ee40
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/VisualStudio/civetweb_yassl/civetweb_yassl/civetweb_yassl.vcxproj.filters
@@ -0,0 +1,40 @@
+\ufeff<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <ItemGroup>
+    <Filter Include="Source Files">
+      <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
+      <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
+    </Filter>
+    <Filter Include="Header Files">
+      <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
+      <Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
+    </Filter>
+    <Filter Include="Resource Files">
+      <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
+      <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
+    </Filter>
+  </ItemGroup>
+  <ItemGroup>
+    <ClInclude Include="..\..\..\include\civetweb.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+  </ItemGroup>
+  <ItemGroup>
+    <ClCompile Include="..\..\..\src\civetweb.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\..\src\main.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+  </ItemGroup>
+  <ItemGroup>
+    <ResourceCompile Include="..\..\..\resources\res.rc">
+      <Filter>Resource Files</Filter>
+    </ResourceCompile>
+  </ItemGroup>
+  <ItemGroup>
+    <Image Include="..\..\..\resources\systray.ico">
+      <Filter>Resource Files</Filter>
+    </Image>
+  </ItemGroup>
+</Project>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/VisualStudio/civetweb_yassl/yassl_lib/yassl_lib.vcxproj
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/VisualStudio/civetweb_yassl/yassl_lib/yassl_lib.vcxproj b/thirdparty/civetweb-1.9.1/VisualStudio/civetweb_yassl/yassl_lib/yassl_lib.vcxproj
new file mode 100644
index 0000000..033b82d
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/VisualStudio/civetweb_yassl/yassl_lib/yassl_lib.vcxproj
@@ -0,0 +1,185 @@
+\ufeff<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <ItemGroup Label="ProjectConfigurations">
+    <ProjectConfiguration Include="Debug|Win32">
+      <Configuration>Debug</Configuration>
+      <Platform>Win32</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Debug|x64">
+      <Configuration>Debug</Configuration>
+      <Platform>x64</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Release|Win32">
+      <Configuration>Release</Configuration>
+      <Platform>Win32</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Release|x64">
+      <Configuration>Release</Configuration>
+      <Platform>x64</Platform>
+    </ProjectConfiguration>
+  </ItemGroup>
+  <PropertyGroup Label="Globals">
+    <ProjectGuid>{8C0C878B-BBD6-4241-BCA6-61753FFCC7F1}</ProjectGuid>
+    <Keyword>Win32Proj</Keyword>
+    <RootNamespace>yassl_lib</RootNamespace>
+  </PropertyGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
+    <ConfigurationType>StaticLibrary</ConfigurationType>
+    <UseDebugLibraries>true</UseDebugLibraries>
+    <PlatformToolset>v110</PlatformToolset>
+    <CharacterSet>MultiByte</CharacterSet>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
+    <ConfigurationType>StaticLibrary</ConfigurationType>
+    <UseDebugLibraries>true</UseDebugLibraries>
+    <PlatformToolset>v110</PlatformToolset>
+    <CharacterSet>MultiByte</CharacterSet>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
+    <ConfigurationType>StaticLibrary</ConfigurationType>
+    <UseDebugLibraries>false</UseDebugLibraries>
+    <PlatformToolset>v110</PlatformToolset>
+    <WholeProgramOptimization>true</WholeProgramOptimization>
+    <CharacterSet>MultiByte</CharacterSet>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
+    <ConfigurationType>StaticLibrary</ConfigurationType>
+    <UseDebugLibraries>false</UseDebugLibraries>
+    <PlatformToolset>v110</PlatformToolset>
+    <WholeProgramOptimization>true</WholeProgramOptimization>
+    <CharacterSet>MultiByte</CharacterSet>
+  </PropertyGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+  <ImportGroup Label="ExtensionSettings">
+  </ImportGroup>
+  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <PropertyGroup Label="UserMacros" />
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <OutDir>$(SolutionDir)\$(Configuration)\$(Platform)</OutDir>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <OutDir>$(SolutionDir)\$(Configuration)\$(Platform)</OutDir>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+    <OutDir>$(SolutionDir)\$(Configuration)\$(Platform)</OutDir>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+    <OutDir>$(SolutionDir)\$(Configuration)\$(Platform)</OutDir>
+  </PropertyGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <ClCompile>
+      <PrecompiledHeader>
+      </PrecompiledHeader>
+      <WarningLevel>Level3</WarningLevel>
+      <Optimization>Disabled</Optimization>
+      <PreprocessorDefinitions>OPENSSL_EXTRA;HAVE_ERRNO_H;HAVE_GETHOSTBYNAME;HAVE_INET_NTOA;HAVE_LIMITS_H;HAVE_MEMSET;HAVE_SOCKET;HAVE_STDDEF_H;HAVE_STDLIB_H;HAVE_STRING_H;HAVE_SYS_STAT_H;HAVE_SYS_TYPES_H;WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <AdditionalIncludeDirectories>$(ProjectDir)..\..\..\..\cyassl-2.7.0\;$(ProjectDir)..\..\..\..\cyassl-2.7.0\cyassl\</AdditionalIncludeDirectories>
+    </ClCompile>
+    <Link>
+      <SubSystem>Windows</SubSystem>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+    <ClCompile>
+      <PrecompiledHeader>
+      </PrecompiledHeader>
+      <WarningLevel>Level3</WarningLevel>
+      <Optimization>Disabled</Optimization>
+      <PreprocessorDefinitions>OPENSSL_EXTRA;HAVE_ERRNO_H;HAVE_GETHOSTBYNAME;HAVE_INET_NTOA;HAVE_LIMITS_H;HAVE_MEMSET;HAVE_SOCKET;HAVE_STDDEF_H;HAVE_STDLIB_H;HAVE_STRING_H;HAVE_SYS_STAT_H;HAVE_SYS_TYPES_H;WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <AdditionalIncludeDirectories>$(ProjectDir)..\..\..\..\cyassl-2.7.0\;$(ProjectDir)..\..\..\..\cyassl-2.7.0\cyassl\</AdditionalIncludeDirectories>
+    </ClCompile>
+    <Link>
+      <SubSystem>Windows</SubSystem>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <ClCompile>
+      <WarningLevel>Level3</WarningLevel>
+      <PrecompiledHeader>
+      </PrecompiledHeader>
+      <Optimization>MaxSpeed</Optimization>
+      <FunctionLevelLinking>true</FunctionLevelLinking>
+      <IntrinsicFunctions>true</IntrinsicFunctions>
+      <PreprocessorDefinitions>OPENSSL_EXTRA;HAVE_ERRNO_H;HAVE_GETHOSTBYNAME;HAVE_INET_NTOA;HAVE_LIMITS_H;HAVE_MEMSET;HAVE_SOCKET;HAVE_STDDEF_H;HAVE_STDLIB_H;HAVE_STRING_H;HAVE_SYS_STAT_H;HAVE_SYS_TYPES_H;WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <AdditionalIncludeDirectories>$(ProjectDir)..\..\..\..\cyassl-2.7.0\;$(ProjectDir)..\..\..\..\cyassl-2.7.0\cyassl\</AdditionalIncludeDirectories>
+    </ClCompile>
+    <Link>
+      <SubSystem>Windows</SubSystem>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>
+      <OptimizeReferences>true</OptimizeReferences>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+    <ClCompile>
+      <WarningLevel>Level3</WarningLevel>
+      <PrecompiledHeader>
+      </PrecompiledHeader>
+      <Optimization>MaxSpeed</Optimization>
+      <FunctionLevelLinking>true</FunctionLevelLinking>
+      <IntrinsicFunctions>true</IntrinsicFunctions>
+      <PreprocessorDefinitions>OPENSSL_EXTRA;HAVE_ERRNO_H;HAVE_GETHOSTBYNAME;HAVE_INET_NTOA;HAVE_LIMITS_H;HAVE_MEMSET;HAVE_SOCKET;HAVE_STDDEF_H;HAVE_STDLIB_H;HAVE_STRING_H;HAVE_SYS_STAT_H;HAVE_SYS_TYPES_H;WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <AdditionalIncludeDirectories>$(ProjectDir)..\..\..\..\cyassl-2.7.0\;$(ProjectDir)..\..\..\..\cyassl-2.7.0\cyassl\</AdditionalIncludeDirectories>
+    </ClCompile>
+    <Link>
+      <SubSystem>Windows</SubSystem>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>
+      <OptimizeReferences>true</OptimizeReferences>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemGroup>
+    <ClCompile Include="..\..\..\..\cyassl-2.7.0\ctaocrypt\src\aes.c" />
+    <ClCompile Include="..\..\..\..\cyassl-2.7.0\ctaocrypt\src\arc4.c" />
+    <ClCompile Include="..\..\..\..\cyassl-2.7.0\ctaocrypt\src\asn.c" />
+    <ClCompile Include="..\..\..\..\cyassl-2.7.0\ctaocrypt\src\coding.c" />
+    <ClCompile Include="..\..\..\..\cyassl-2.7.0\ctaocrypt\src\des3.c" />
+    <ClCompile Include="..\..\..\..\cyassl-2.7.0\ctaocrypt\src\dh.c" />
+    <ClCompile Include="..\..\..\..\cyassl-2.7.0\ctaocrypt\src\dsa.c" />
+    <ClCompile Include="..\..\..\..\cyassl-2.7.0\ctaocrypt\src\ecc.c" />
+    <ClCompile Include="..\..\..\..\cyassl-2.7.0\ctaocrypt\src\error.c" />
+    <ClCompile Include="..\..\..\..\cyassl-2.7.0\ctaocrypt\src\hc128.c" />
+    <ClCompile Include="..\..\..\..\cyassl-2.7.0\ctaocrypt\src\hmac.c" />
+    <ClCompile Include="..\..\..\..\cyassl-2.7.0\ctaocrypt\src\integer.c" />
+    <ClCompile Include="..\..\..\..\cyassl-2.7.0\ctaocrypt\src\logging.c" />
+    <ClCompile Include="..\..\..\..\cyassl-2.7.0\ctaocrypt\src\md2.c" />
+    <ClCompile Include="..\..\..\..\cyassl-2.7.0\ctaocrypt\src\md4.c" />
+    <ClCompile Include="..\..\..\..\cyassl-2.7.0\ctaocrypt\src\md5.c" />
+    <ClCompile Include="..\..\..\..\cyassl-2.7.0\ctaocrypt\src\memory.c" />
+    <ClCompile Include="..\..\..\..\cyassl-2.7.0\ctaocrypt\src\misc.c" />
+    <ClCompile Include="..\..\..\..\cyassl-2.7.0\ctaocrypt\src\pwdbased.c" />
+    <ClCompile Include="..\..\..\..\cyassl-2.7.0\ctaocrypt\src\rabbit.c" />
+    <ClCompile Include="..\..\..\..\cyassl-2.7.0\ctaocrypt\src\random.c" />
+    <ClCompile Include="..\..\..\..\cyassl-2.7.0\ctaocrypt\src\ripemd.c" />
+    <ClCompile Include="..\..\..\..\cyassl-2.7.0\ctaocrypt\src\rsa.c" />
+    <ClCompile Include="..\..\..\..\cyassl-2.7.0\ctaocrypt\src\sha.c" />
+    <ClCompile Include="..\..\..\..\cyassl-2.7.0\ctaocrypt\src\sha256.c" />
+    <ClCompile Include="..\..\..\..\cyassl-2.7.0\ctaocrypt\src\sha512.c" />
+    <ClCompile Include="..\..\..\..\cyassl-2.7.0\ctaocrypt\src\tfm.c" />
+    <ClCompile Include="..\..\..\..\cyassl-2.7.0\src\crl.c" />
+    <ClCompile Include="..\..\..\..\cyassl-2.7.0\src\internal.c" />
+    <ClCompile Include="..\..\..\..\cyassl-2.7.0\src\io.c" />
+    <ClCompile Include="..\..\..\..\cyassl-2.7.0\src\keys.c" />
+    <ClCompile Include="..\..\..\..\cyassl-2.7.0\src\ocsp.c" />
+    <ClCompile Include="..\..\..\..\cyassl-2.7.0\src\sniffer.c" />
+    <ClCompile Include="..\..\..\..\cyassl-2.7.0\src\ssl.c" />
+    <ClCompile Include="..\..\..\..\cyassl-2.7.0\src\tls.c" />
+  </ItemGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+  <ImportGroup Label="ExtensionTargets">
+  </ImportGroup>
+</Project>
\ No newline at end of file


[38/51] [partial] nifi-minifi-cpp git commit: MINIFI-183 Added civet 1.9.1 sources Added onScheduled hook Added initial two-way TLS-enabled ListenHTTP implementation

Posted by al...@apache.org.
http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/civetweb.c
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/civetweb.c b/thirdparty/civetweb-1.9.1/src/civetweb.c
new file mode 100644
index 0000000..da491b6
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/civetweb.c
@@ -0,0 +1,14894 @@
+/* Copyright (c) 2013-2017 the Civetweb developers
+ * Copyright (c) 2004-2013 Sergey Lyubka
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#if defined(_WIN32)
+#if !defined(_CRT_SECURE_NO_WARNINGS)
+#define _CRT_SECURE_NO_WARNINGS /* Disable deprecation warning in VS2005 */
+#endif
+#ifndef _WIN32_WINNT /* defined for tdm-gcc so we can use getnameinfo */
+#define _WIN32_WINNT 0x0501
+#endif
+#else
+#if defined(__GNUC__) && !defined(_GNU_SOURCE)
+#define _GNU_SOURCE /* for setgroups() */
+#endif
+#if defined(__linux__) && !defined(_XOPEN_SOURCE)
+#define _XOPEN_SOURCE 600 /* For flockfile() on Linux */
+#endif
+#ifndef _LARGEFILE_SOURCE
+#define _LARGEFILE_SOURCE /* For fseeko(), ftello() */
+#endif
+#ifndef _FILE_OFFSET_BITS
+#define _FILE_OFFSET_BITS 64 /* Use 64-bit file offsets by default */
+#endif
+#ifndef __STDC_FORMAT_MACROS
+#define __STDC_FORMAT_MACROS /* <inttypes.h> wants this for C++ */
+#endif
+#ifndef __STDC_LIMIT_MACROS
+#define __STDC_LIMIT_MACROS /* C++ wants that for INT64_MAX */
+#endif
+#ifdef __sun
+#define __EXTENSIONS__  /* to expose flockfile and friends in stdio.h */
+#define __inline inline /* not recognized on older compiler versions */
+#endif
+#endif
+
+#if defined(USE_LUA)
+#define USE_TIMERS
+#endif
+
+#if defined(_MSC_VER)
+/* 'type cast' : conversion from 'int' to 'HANDLE' of greater size */
+#pragma warning(disable : 4306)
+/* conditional expression is constant: introduced by FD_SET(..) */
+#pragma warning(disable : 4127)
+/* non-constant aggregate initializer: issued due to missing C99 support */
+#pragma warning(disable : 4204)
+/* padding added after data member */
+#pragma warning(disable : 4820)
+/* not defined as a preprocessor macro, replacing with '0' for '#if/#elif' */
+#pragma warning(disable : 4668)
+/* no function prototype given: converting '()' to '(void)' */
+#pragma warning(disable : 4255)
+/* function has been selected for automatic inline expansion */
+#pragma warning(disable : 4711)
+#endif
+
+
+/* This code uses static_assert to check some conditions.
+ * Unfortunately some compilers still do not support it, so we have a
+ * replacement function here. */
+#if defined(_MSC_VER) && (_MSC_VER >= 1600)
+#define mg_static_assert static_assert
+#elif defined(__cplusplus) && (__cplusplus >= 201103L)
+#define mg_static_assert static_assert
+#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
+#define mg_static_assert _Static_assert
+#else
+char static_assert_replacement[1];
+#define mg_static_assert(cond, txt)                                            \
+	extern char static_assert_replacement[(cond) ? 1 : -1]
+#endif
+
+mg_static_assert(sizeof(int) == 4 || sizeof(int) == 8,
+                 "int data type size check");
+mg_static_assert(sizeof(void *) == 4 || sizeof(void *) == 8,
+                 "pointer data type size check");
+mg_static_assert(sizeof(void *) >= sizeof(int), "data type size check");
+
+
+/* DTL -- including winsock2.h works better if lean and mean */
+#ifndef WIN32_LEAN_AND_MEAN
+#define WIN32_LEAN_AND_MEAN
+#endif
+
+#if defined(__SYMBIAN32__)
+#define NO_SSL /* SSL is not supported */
+#define NO_CGI /* CGI is not supported */
+#define PATH_MAX FILENAME_MAX
+#endif /* __SYMBIAN32__ */
+
+
+/* Include the header file here, so the CivetWeb interface is defined for the
+ * entire implementation, including the following forward definitions. */
+#include "civetweb.h"
+
+
+#ifndef IGNORE_UNUSED_RESULT
+#define IGNORE_UNUSED_RESULT(a) ((void)((a) && 1))
+#endif
+
+#ifndef _WIN32_WCE /* Some ANSI #includes are not available on Windows CE */
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <errno.h>
+#include <signal.h>
+#include <fcntl.h>
+#endif /* !_WIN32_WCE */
+
+
+#ifdef __clang__
+/* When using -Weverything, clang does not accept it's own headers
+ * in a release build configuration. Disable what is too much in
+ * -Weverything. */
+#pragma clang diagnostic ignored "-Wdisabled-macro-expansion"
+#endif
+
+
+#ifdef __MACH__ /* Apple OSX section */
+
+#ifdef __clang__
+/* Avoid warnings for Xopen 7.00 and higher */
+#pragma clang diagnostic ignored "-Wno-reserved-id-macro"
+#pragma clang diagnostic ignored "-Wno-keyword-macro"
+#endif
+
+#define CLOCK_MONOTONIC (1)
+#define CLOCK_REALTIME (2)
+
+#include <sys/errno.h>
+#include <sys/time.h>
+#include <mach/clock.h>
+#include <mach/mach.h>
+#include <mach/mach_time.h>
+#include <assert.h>
+
+/* clock_gettime is not implemented on OSX prior to 10.12 */
+static int
+_civet_clock_gettime(int clk_id, struct timespec *t)
+{
+	memset(t, 0, sizeof(*t));
+	if (clk_id == CLOCK_REALTIME) {
+		struct timeval now;
+		int rv = gettimeofday(&now, NULL);
+		if (rv) {
+			return rv;
+		}
+		t->tv_sec = now.tv_sec;
+		t->tv_nsec = now.tv_usec * 1000;
+		return 0;
+
+	} else if (clk_id == CLOCK_MONOTONIC) {
+		static uint64_t clock_start_time = 0;
+		static mach_timebase_info_data_t timebase_ifo = {0, 0};
+
+		uint64_t now = mach_absolute_time();
+
+		if (clock_start_time == 0) {
+			kern_return_t mach_status = mach_timebase_info(&timebase_ifo);
+#if defined(DEBUG)
+			assert(mach_status == KERN_SUCCESS);
+#else
+			/* appease "unused variable" warning for release builds */
+			(void)mach_status;
+#endif
+			clock_start_time = now;
+		}
+
+		now = (uint64_t)((double)(now - clock_start_time)
+		                 * (double)timebase_ifo.numer
+		                 / (double)timebase_ifo.denom);
+
+		t->tv_sec = now / 1000000000;
+		t->tv_nsec = now % 1000000000;
+		return 0;
+	}
+	return -1; /* EINVAL - Clock ID is unknown */
+}
+
+/* if clock_gettime is declared, then __CLOCK_AVAILABILITY will be defined */
+#ifdef __CLOCK_AVAILABILITY
+/* If we compiled with Mac OSX 10.12 or later, then clock_gettime will be
+ * declared but it may be NULL at runtime. So we need to check before using
+ * it. */
+static int
+_civet_safe_clock_gettime(int clk_id, struct timespec *t)
+{
+	if (clock_gettime) {
+		return clock_gettime(clk_id, t);
+	}
+	return _civet_clock_gettime(clk_id, t);
+}
+#define clock_gettime _civet_safe_clock_gettime
+#else
+#define clock_gettime _civet_clock_gettime
+#endif
+
+#endif
+
+
+#include <time.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <assert.h>
+#include <string.h>
+#include <ctype.h>
+#include <limits.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <stdint.h>
+
+#ifndef INT64_MAX
+#define INT64_MAX (9223372036854775807)
+#endif
+
+
+#ifndef MAX_WORKER_THREADS
+#define MAX_WORKER_THREADS (1024 * 64)
+#endif
+
+#ifndef SOCKET_TIMEOUT_QUANTUM /* in ms */
+#define SOCKET_TIMEOUT_QUANTUM (2000)
+#endif
+
+#define SHUTDOWN_RD (0)
+#define SHUTDOWN_WR (1)
+#define SHUTDOWN_BOTH (2)
+
+mg_static_assert(MAX_WORKER_THREADS >= 1,
+                 "worker threads must be a positive number");
+
+mg_static_assert(sizeof(size_t) == 4 || sizeof(size_t) == 8,
+                 "size_t data type size check");
+
+#if defined(_WIN32)                                                            \
+    && !defined(__SYMBIAN32__) /* WINDOWS / UNIX include block */
+#include <windows.h>
+#include <winsock2.h> /* DTL add for SO_EXCLUSIVE */
+#include <ws2tcpip.h>
+
+typedef const char *SOCK_OPT_TYPE;
+
+#if !defined(PATH_MAX)
+#define PATH_MAX (MAX_PATH)
+#endif
+
+#if !defined(PATH_MAX)
+#define PATH_MAX (4096)
+#endif
+
+mg_static_assert(PATH_MAX >= 1, "path length must be a positive number");
+
+#ifndef _IN_PORT_T
+#ifndef in_port_t
+#define in_port_t u_short
+#endif
+#endif
+
+#ifndef _WIN32_WCE
+#include <process.h>
+#include <direct.h>
+#include <io.h>
+#else            /* _WIN32_WCE */
+#define NO_CGI   /* WinCE has no pipes */
+#define NO_POPEN /* WinCE has no popen */
+
+typedef long off_t;
+
+#define errno ((int)(GetLastError()))
+#define strerror(x) (_ultoa(x, (char *)_alloca(sizeof(x) * 3), 10))
+#endif /* _WIN32_WCE */
+
+#define MAKEUQUAD(lo, hi)                                                      \
+	((uint64_t)(((uint32_t)(lo)) | ((uint64_t)((uint32_t)(hi))) << 32))
+#define RATE_DIFF (10000000) /* 100 nsecs */
+#define EPOCH_DIFF (MAKEUQUAD(0xd53e8000, 0x019db1de))
+#define SYS2UNIX_TIME(lo, hi)                                                  \
+	((time_t)((MAKEUQUAD((lo), (hi)) - EPOCH_DIFF) / RATE_DIFF))
+
+/* Visual Studio 6 does not know __func__ or __FUNCTION__
+ * The rest of MS compilers use __FUNCTION__, not C99 __func__
+ * Also use _strtoui64 on modern M$ compilers */
+#if defined(_MSC_VER)
+#if (_MSC_VER < 1300)
+#define STRX(x) #x
+#define STR(x) STRX(x)
+#define __func__ __FILE__ ":" STR(__LINE__)
+#define strtoull(x, y, z) ((unsigned __int64)_atoi64(x))
+#define strtoll(x, y, z) (_atoi64(x))
+#else
+#define __func__ __FUNCTION__
+#define strtoull(x, y, z) (_strtoui64(x, y, z))
+#define strtoll(x, y, z) (_strtoi64(x, y, z))
+#endif
+#endif /* _MSC_VER */
+
+#define ERRNO ((int)(GetLastError()))
+#define NO_SOCKLEN_T
+
+#if defined(_WIN64) || defined(__MINGW64__)
+#define SSL_LIB "ssleay64.dll"
+#define CRYPTO_LIB "libeay64.dll"
+#else
+#define SSL_LIB "ssleay32.dll"
+#define CRYPTO_LIB "libeay32.dll"
+#endif
+
+#define O_NONBLOCK (0)
+#ifndef W_OK
+#define W_OK (2) /* http://msdn.microsoft.com/en-us/library/1w06ktdy.aspx */
+#endif
+#if !defined(EWOULDBLOCK)
+#define EWOULDBLOCK WSAEWOULDBLOCK
+#endif /* !EWOULDBLOCK */
+#define _POSIX_
+#define INT64_FMT "I64d"
+#define UINT64_FMT "I64u"
+
+#define WINCDECL __cdecl
+#define vsnprintf_impl _vsnprintf
+#define access _access
+#define mg_sleep(x) (Sleep(x))
+
+#define pipe(x) _pipe(x, MG_BUF_LEN, _O_BINARY)
+#ifndef popen
+#define popen(x, y) (_popen(x, y))
+#endif
+#ifndef pclose
+#define pclose(x) (_pclose(x))
+#endif
+#define close(x) (_close(x))
+#define dlsym(x, y) (GetProcAddress((HINSTANCE)(x), (y)))
+#define RTLD_LAZY (0)
+#define fseeko(x, y, z) ((_lseeki64(_fileno(x), (y), (z)) == -1) ? -1 : 0)
+#define fdopen(x, y) (_fdopen((x), (y)))
+#define write(x, y, z) (_write((x), (y), (unsigned)z))
+#define read(x, y, z) (_read((x), (y), (unsigned)z))
+#define flockfile(x) (EnterCriticalSection(&global_log_file_lock))
+#define funlockfile(x) (LeaveCriticalSection(&global_log_file_lock))
+#define sleep(x) (Sleep((x)*1000))
+#define rmdir(x) (_rmdir(x))
+#define timegm(x) (_mkgmtime(x))
+
+#if !defined(fileno)
+#define fileno(x) (_fileno(x))
+#endif /* !fileno MINGW #defines fileno */
+
+typedef HANDLE pthread_mutex_t;
+typedef DWORD pthread_key_t;
+typedef HANDLE pthread_t;
+typedef struct {
+	CRITICAL_SECTION threadIdSec;
+	struct mg_workerTLS *waiting_thread; /* The chain of threads */
+} pthread_cond_t;
+
+#ifndef __clockid_t_defined
+typedef DWORD clockid_t;
+#endif
+#ifndef CLOCK_MONOTONIC
+#define CLOCK_MONOTONIC (1)
+#endif
+#ifndef CLOCK_REALTIME
+#define CLOCK_REALTIME (2)
+#endif
+
+#if defined(_MSC_VER) && (_MSC_VER >= 1900)
+#define _TIMESPEC_DEFINED
+#endif
+#ifndef _TIMESPEC_DEFINED
+struct timespec {
+	time_t tv_sec; /* seconds */
+	long tv_nsec;  /* nanoseconds */
+};
+#endif
+
+#if !defined(WIN_PTHREADS_TIME_H)
+#define MUST_IMPLEMENT_CLOCK_GETTIME
+#endif
+
+#ifdef MUST_IMPLEMENT_CLOCK_GETTIME
+#define clock_gettime mg_clock_gettime
+static int
+clock_gettime(clockid_t clk_id, struct timespec *tp)
+{
+	FILETIME ft;
+	ULARGE_INTEGER li;
+	BOOL ok = FALSE;
+	double d;
+	static double perfcnt_per_sec = 0.0;
+
+	if (tp) {
+		memset(tp, 0, sizeof(*tp));
+		if (clk_id == CLOCK_REALTIME) {
+			GetSystemTimeAsFileTime(&ft);
+			li.LowPart = ft.dwLowDateTime;
+			li.HighPart = ft.dwHighDateTime;
+			li.QuadPart -= 116444736000000000; /* 1.1.1970 in filedate */
+			tp->tv_sec = (time_t)(li.QuadPart / 10000000);
+			tp->tv_nsec = (long)(li.QuadPart % 10000000) * 100;
+			ok = TRUE;
+		} else if (clk_id == CLOCK_MONOTONIC) {
+			if (perfcnt_per_sec == 0.0) {
+				QueryPerformanceFrequency((LARGE_INTEGER *)&li);
+				perfcnt_per_sec = 1.0 / li.QuadPart;
+			}
+			if (perfcnt_per_sec != 0.0) {
+				QueryPerformanceCounter((LARGE_INTEGER *)&li);
+				d = li.QuadPart * perfcnt_per_sec;
+				tp->tv_sec = (time_t)d;
+				d -= tp->tv_sec;
+				tp->tv_nsec = (long)(d * 1.0E9);
+				ok = TRUE;
+			}
+		}
+	}
+
+	return ok ? 0 : -1;
+}
+#endif
+
+
+#define pid_t HANDLE /* MINGW typedefs pid_t to int. Using #define here. */
+
+static int pthread_mutex_lock(pthread_mutex_t *);
+static int pthread_mutex_unlock(pthread_mutex_t *);
+static void path_to_unicode(const struct mg_connection *conn,
+                            const char *path,
+                            wchar_t *wbuf,
+                            size_t wbuf_len);
+
+/* All file operations need to be rewritten to solve #246. */
+
+#include "file_ops.inl"
+
+struct mg_file;
+
+static const char *
+mg_fgets(char *buf, size_t size, struct mg_file *filep, char **p);
+
+
+/* POSIX dirent interface */
+struct dirent {
+	char d_name[PATH_MAX];
+};
+
+typedef struct DIR {
+	HANDLE handle;
+	WIN32_FIND_DATAW info;
+	struct dirent result;
+} DIR;
+
+#if defined(_WIN32) && !defined(POLLIN)
+#ifndef HAVE_POLL
+struct pollfd {
+	SOCKET fd;
+	short events;
+	short revents;
+};
+#define POLLIN (0x0300)
+#endif
+#endif
+
+/* Mark required libraries */
+#if defined(_MSC_VER)
+#pragma comment(lib, "Ws2_32.lib")
+#endif
+
+#else /* defined(_WIN32) && !defined(__SYMBIAN32__) -                          \
+         WINDOWS / UNIX include block */
+
+#include <sys/wait.h>
+#include <sys/socket.h>
+#include <sys/poll.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <sys/time.h>
+#include <sys/utsname.h>
+#include <stdint.h>
+#include <inttypes.h>
+#include <netdb.h>
+#include <netinet/tcp.h>
+typedef const void *SOCK_OPT_TYPE;
+
+#if defined(ANDROID)
+typedef unsigned short int in_port_t;
+#endif
+
+#include <pwd.h>
+#include <unistd.h>
+#include <grp.h>
+#include <dirent.h>
+#define vsnprintf_impl vsnprintf
+
+#if !defined(NO_SSL_DL) && !defined(NO_SSL)
+#include <dlfcn.h>
+#endif
+#include <pthread.h>
+#if defined(__MACH__)
+#define SSL_LIB "libssl.dylib"
+#define CRYPTO_LIB "libcrypto.dylib"
+#else
+#if !defined(SSL_LIB)
+#define SSL_LIB "libssl.so"
+#endif
+#if !defined(CRYPTO_LIB)
+#define CRYPTO_LIB "libcrypto.so"
+#endif
+#endif
+#ifndef O_BINARY
+#define O_BINARY (0)
+#endif /* O_BINARY */
+#define closesocket(a) (close(a))
+#define mg_mkdir(conn, path, mode) (mkdir(path, mode))
+#define mg_remove(conn, x) (remove(x))
+#define mg_sleep(x) (usleep((x)*1000))
+#define mg_opendir(conn, x) (opendir(x))
+#define mg_closedir(x) (closedir(x))
+#define mg_readdir(x) (readdir(x))
+#define ERRNO (errno)
+#define INVALID_SOCKET (-1)
+#define INT64_FMT PRId64
+#define UINT64_FMT PRIu64
+typedef int SOCKET;
+#define WINCDECL
+
+#if defined(__hpux)
+/* HPUX 11 does not have monotonic, fall back to realtime */
+#ifndef CLOCK_MONOTONIC
+#define CLOCK_MONOTONIC CLOCK_REALTIME
+#endif
+
+/* HPUX defines socklen_t incorrectly as size_t which is 64bit on
+ * Itanium.  Without defining _XOPEN_SOURCE or _XOPEN_SOURCE_EXTENDED
+ * the prototypes use int* rather than socklen_t* which matches the
+ * actual library expectation.  When called with the wrong size arg
+ * accept() returns a zero client inet addr and check_acl() always
+ * fails.  Since socklen_t is widely used below, just force replace
+ * their typedef with int. - DTL
+ */
+#define socklen_t int
+#endif /* hpux */
+
+#endif /* defined(_WIN32) && !defined(__SYMBIAN32__) -                         \
+          WINDOWS / UNIX include block */
+
+/* va_copy should always be a macro, C99 and C++11 - DTL */
+#ifndef va_copy
+#define va_copy(x, y) ((x) = (y))
+#endif
+
+#ifdef _WIN32
+/* Create substitutes for POSIX functions in Win32. */
+
+#if defined(__MINGW32__)
+/* Show no warning in case system functions are not used. */
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-function"
+#endif
+
+
+static CRITICAL_SECTION global_log_file_lock;
+static DWORD
+pthread_self(void)
+{
+	return GetCurrentThreadId();
+}
+
+
+static int
+pthread_key_create(
+    pthread_key_t *key,
+    void (*_ignored)(void *) /* destructor not supported for Windows */
+    )
+{
+	(void)_ignored;
+
+	if ((key != 0)) {
+		*key = TlsAlloc();
+		return (*key != TLS_OUT_OF_INDEXES) ? 0 : -1;
+	}
+	return -2;
+}
+
+
+static int
+pthread_key_delete(pthread_key_t key)
+{
+	return TlsFree(key) ? 0 : 1;
+}
+
+
+static int
+pthread_setspecific(pthread_key_t key, void *value)
+{
+	return TlsSetValue(key, value) ? 0 : 1;
+}
+
+
+static void *
+pthread_getspecific(pthread_key_t key)
+{
+	return TlsGetValue(key);
+}
+
+#if defined(__MINGW32__)
+/* Enable unused function warning again */
+#pragma GCC diagnostic pop
+#endif
+
+static struct pthread_mutex_undefined_struct *pthread_mutex_attr = NULL;
+#else
+static pthread_mutexattr_t pthread_mutex_attr;
+#endif /* _WIN32 */
+
+
+#define PASSWORDS_FILE_NAME ".htpasswd"
+#define CGI_ENVIRONMENT_SIZE (4096)
+#define MAX_CGI_ENVIR_VARS (256)
+#define MG_BUF_LEN (8192)
+
+#ifndef MAX_REQUEST_SIZE
+#define MAX_REQUEST_SIZE (16384)
+#endif
+
+mg_static_assert(MAX_REQUEST_SIZE >= 256,
+                 "request size length must be a positive number");
+
+#define ARRAY_SIZE(array) (sizeof(array) / sizeof(array[0]))
+
+
+#if defined(_WIN32_WCE)
+/* Create substitutes for POSIX functions in Win32. */
+
+#if defined(__MINGW32__)
+/* Show no warning in case system functions are not used. */
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-function"
+#endif
+
+
+static time_t
+time(time_t *ptime)
+{
+	time_t t;
+	SYSTEMTIME st;
+	FILETIME ft;
+
+	GetSystemTime(&st);
+	SystemTimeToFileTime(&st, &ft);
+	t = SYS2UNIX_TIME(ft.dwLowDateTime, ft.dwHighDateTime);
+
+	if (ptime != NULL) {
+		*ptime = t;
+	}
+
+	return t;
+}
+
+
+static struct tm *
+localtime_s(const time_t *ptime, struct tm *ptm)
+{
+	int64_t t = ((int64_t)*ptime) * RATE_DIFF + EPOCH_DIFF;
+	FILETIME ft, lft;
+	SYSTEMTIME st;
+	TIME_ZONE_INFORMATION tzinfo;
+
+	if (ptm == NULL) {
+		return NULL;
+	}
+
+	*(int64_t *)&ft = t;
+	FileTimeToLocalFileTime(&ft, &lft);
+	FileTimeToSystemTime(&lft, &st);
+	ptm->tm_year = st.wYear - 1900;
+	ptm->tm_mon = st.wMonth - 1;
+	ptm->tm_wday = st.wDayOfWeek;
+	ptm->tm_mday = st.wDay;
+	ptm->tm_hour = st.wHour;
+	ptm->tm_min = st.wMinute;
+	ptm->tm_sec = st.wSecond;
+	ptm->tm_yday = 0; /* hope nobody uses this */
+	ptm->tm_isdst =
+	    (GetTimeZoneInformation(&tzinfo) == TIME_ZONE_ID_DAYLIGHT) ? 1 : 0;
+
+	return ptm;
+}
+
+
+static struct tm *
+gmtime_s(const time_t *ptime, struct tm *ptm)
+{
+	/* FIXME(lsm): fix this. */
+	return localtime_s(ptime, ptm);
+}
+
+
+static int mg_atomic_inc(volatile int *addr);
+static struct tm tm_array[MAX_WORKER_THREADS];
+static int tm_index = 0;
+
+
+static struct tm *
+localtime(const time_t *ptime)
+{
+	int i = mg_atomic_inc(&tm_index) % (sizeof(tm_array) / sizeof(tm_array[0]));
+	return localtime_s(ptime, tm_array + i);
+}
+
+
+static struct tm *
+gmtime(const time_t *ptime)
+{
+	int i = mg_atomic_inc(&tm_index) % ARRAY_SIZE(tm_array);
+	return gmtime_s(ptime, tm_array + i);
+}
+
+
+static size_t
+strftime(char *dst, size_t dst_size, const char *fmt, const struct tm *tm)
+{
+	/* TODO: (void)mg_snprintf(NULL, dst, dst_size, "implement strftime()
+	 * for WinCE"); */
+	return 0;
+}
+
+#define _beginthreadex(psec, stack, func, prm, flags, ptid)                    \
+	(uintptr_t) CreateThread(psec, stack, func, prm, flags, ptid)
+
+#define remove(f) mg_remove(NULL, f)
+
+static int
+rename(const char *a, const char *b)
+{
+	wchar_t wa[PATH_MAX];
+	wchar_t wb[PATH_MAX];
+	path_to_unicode(NULL, a, wa, ARRAY_SIZE(wa));
+	path_to_unicode(NULL, b, wb, ARRAY_SIZE(wb));
+
+	return MoveFileW(wa, wb) ? 0 : -1;
+}
+
+struct stat {
+	int64_t st_size;
+	time_t st_mtime;
+};
+
+static int
+stat(const char *name, struct stat *st)
+{
+	wchar_t wbuf[PATH_MAX];
+	WIN32_FILE_ATTRIBUTE_DATA attr;
+	time_t creation_time, write_time;
+
+	path_to_unicode(NULL, name, wbuf, ARRAY_SIZE(wbuf));
+	memset(&attr, 0, sizeof(attr));
+
+	GetFileAttributesExW(wbuf, GetFileExInfoStandard, &attr);
+	st->st_size =
+	    (((int64_t)attr.nFileSizeHigh) << 32) + (int64_t)attr.nFileSizeLow;
+
+	write_time = SYS2UNIX_TIME(attr.ftLastWriteTime.dwLowDateTime,
+	                           attr.ftLastWriteTime.dwHighDateTime);
+	creation_time = SYS2UNIX_TIME(attr.ftCreationTime.dwLowDateTime,
+	                              attr.ftCreationTime.dwHighDateTime);
+
+	if (creation_time > write_time) {
+		st->st_mtime = creation_time;
+	} else {
+		st->st_mtime = write_time;
+	}
+	return 0;
+}
+
+#define access(x, a) 1 /* not required anyway */
+
+/* WinCE-TODO: define stat, remove, rename, _rmdir, _lseeki64 */
+/* Values from errno.h in Windows SDK (Visual Studio). */
+#define EEXIST 17
+#define EACCES 13
+#define ENOENT 2
+
+#if defined(__MINGW32__)
+/* Enable unused function warning again */
+#pragma GCC diagnostic pop
+#endif
+
+#endif /* defined(_WIN32_WCE) */
+
+
+static int
+mg_atomic_inc(volatile int *addr)
+{
+	int ret;
+#if defined(_WIN32) && !defined(__SYMBIAN32__)
+	/* Depending on the SDK, this function uses either
+	 * (volatile unsigned int *) or (volatile LONG *),
+	 * so whatever you use, the other SDK is likely to raise a warning. */
+	ret = InterlockedIncrement((volatile long *)addr);
+#elif defined(__GNUC__)                                                        \
+    && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ > 0)))
+	ret = __sync_add_and_fetch(addr, 1);
+#else
+	ret = (++(*addr));
+#endif
+	return ret;
+}
+
+
+static int
+mg_atomic_dec(volatile int *addr)
+{
+	int ret;
+#if defined(_WIN32) && !defined(__SYMBIAN32__)
+	/* Depending on the SDK, this function uses either
+	 * (volatile unsigned int *) or (volatile LONG *),
+	 * so whatever you use, the other SDK is likely to raise a warning. */
+	ret = InterlockedDecrement((volatile long *)addr);
+#elif defined(__GNUC__)                                                        \
+    && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ > 0)))
+	ret = __sync_sub_and_fetch(addr, 1);
+#else
+	ret = (--(*addr));
+#endif
+	return ret;
+}
+
+
+#if defined(MEMORY_DEBUGGING)
+static unsigned long mg_memory_debug_blockCount = 0;
+static unsigned long mg_memory_debug_totalMemUsed = 0;
+
+
+static void *
+mg_malloc_ex(size_t size, const char *file, unsigned line)
+{
+	void *data = malloc(size + sizeof(size_t));
+	void *memory = 0;
+	char mallocStr[256];
+
+	if (data) {
+		*(size_t *)data = size;
+		mg_memory_debug_totalMemUsed += size;
+		mg_memory_debug_blockCount++;
+		memory = (void *)(((char *)data) + sizeof(size_t));
+	}
+
+	sprintf(mallocStr,
+	        "MEM: %p %5lu alloc   %7lu %4lu --- %s:%u\n",
+	        memory,
+	        (unsigned long)size,
+	        mg_memory_debug_totalMemUsed,
+	        mg_memory_debug_blockCount,
+	        file,
+	        line);
+#if defined(_WIN32)
+	OutputDebugStringA(mallocStr);
+#else
+	DEBUG_TRACE("%s", mallocStr);
+#endif
+
+	return memory;
+}
+
+
+static void *
+mg_calloc_ex(size_t count, size_t size, const char *file, unsigned line)
+{
+	void *data = mg_malloc_ex(size * count, file, line);
+	if (data) {
+		memset(data, 0, size * count);
+	}
+	return data;
+}
+
+
+static void
+mg_free_ex(void *memory, const char *file, unsigned line)
+{
+	char mallocStr[256];
+	void *data = (void *)(((char *)memory) - sizeof(size_t));
+	size_t size;
+
+	if (memory) {
+		size = *(size_t *)data;
+		mg_memory_debug_totalMemUsed -= size;
+		mg_memory_debug_blockCount--;
+		sprintf(mallocStr,
+		        "MEM: %p %5lu free    %7lu %4lu --- %s:%u\n",
+		        memory,
+		        (unsigned long)size,
+		        mg_memory_debug_totalMemUsed,
+		        mg_memory_debug_blockCount,
+		        file,
+		        line);
+#if defined(_WIN32)
+		OutputDebugStringA(mallocStr);
+#else
+		DEBUG_TRACE("%s", mallocStr);
+#endif
+
+		free(data);
+	}
+}
+
+
+static void *
+mg_realloc_ex(void *memory, size_t newsize, const char *file, unsigned line)
+{
+	char mallocStr[256];
+	void *data;
+	void *_realloc;
+	size_t oldsize;
+
+	if (newsize) {
+		if (memory) {
+			data = (void *)(((char *)memory) - sizeof(size_t));
+			oldsize = *(size_t *)data;
+			_realloc = realloc(data, newsize + sizeof(size_t));
+			if (_realloc) {
+				data = _realloc;
+				mg_memory_debug_totalMemUsed -= oldsize;
+				sprintf(mallocStr,
+				        "MEM: %p %5lu r-free  %7lu %4lu --- %s:%u\n",
+				        memory,
+				        (unsigned long)oldsize,
+				        mg_memory_debug_totalMemUsed,
+				        mg_memory_debug_blockCount,
+				        file,
+				        line);
+#if defined(_WIN32)
+				OutputDebugStringA(mallocStr);
+#else
+				DEBUG_TRACE("%s", mallocStr);
+#endif
+				mg_memory_debug_totalMemUsed += newsize;
+				sprintf(mallocStr,
+				        "MEM: %p %5lu r-alloc %7lu %4lu --- %s:%u\n",
+				        memory,
+				        (unsigned long)newsize,
+				        mg_memory_debug_totalMemUsed,
+				        mg_memory_debug_blockCount,
+				        file,
+				        line);
+#if defined(_WIN32)
+				OutputDebugStringA(mallocStr);
+#else
+				DEBUG_TRACE("%s", mallocStr);
+#endif
+				*(size_t *)data = newsize;
+				data = (void *)(((char *)data) + sizeof(size_t));
+			} else {
+#if defined(_WIN32)
+				OutputDebugStringA("MEM: realloc failed\n");
+#else
+				DEBUG_TRACE("%s", "MEM: realloc failed\n");
+#endif
+				return _realloc;
+			}
+		} else {
+			data = mg_malloc_ex(newsize, file, line);
+		}
+	} else {
+		data = 0;
+		mg_free_ex(memory, file, line);
+	}
+
+	return data;
+}
+
+#define mg_malloc(a) mg_malloc_ex(a, __FILE__, __LINE__)
+#define mg_calloc(a, b) mg_calloc_ex(a, b, __FILE__, __LINE__)
+#define mg_realloc(a, b) mg_realloc_ex(a, b, __FILE__, __LINE__)
+#define mg_free(a) mg_free_ex(a, __FILE__, __LINE__)
+
+#else
+
+static __inline void *
+mg_malloc(size_t a)
+{
+	return malloc(a);
+}
+
+static __inline void *
+mg_calloc(size_t a, size_t b)
+{
+	return calloc(a, b);
+}
+
+static __inline void *
+mg_realloc(void *a, size_t b)
+{
+	return realloc(a, b);
+}
+
+static __inline void
+mg_free(void *a)
+{
+	free(a);
+}
+
+#endif
+
+
+static void mg_vsnprintf(const struct mg_connection *conn,
+                         int *truncated,
+                         char *buf,
+                         size_t buflen,
+                         const char *fmt,
+                         va_list ap);
+
+static void mg_snprintf(const struct mg_connection *conn,
+                        int *truncated,
+                        char *buf,
+                        size_t buflen,
+                        PRINTF_FORMAT_STRING(const char *fmt),
+                        ...) PRINTF_ARGS(5, 6);
+
+/* This following lines are just meant as a reminder to use the mg-functions
+ * for memory management */
+#ifdef malloc
+#undef malloc
+#endif
+#ifdef calloc
+#undef calloc
+#endif
+#ifdef realloc
+#undef realloc
+#endif
+#ifdef free
+#undef free
+#endif
+#ifdef snprintf
+#undef snprintf
+#endif
+#ifdef vsnprintf
+#undef vsnprintf
+#endif
+#define malloc DO_NOT_USE_THIS_FUNCTION__USE_mg_malloc
+#define calloc DO_NOT_USE_THIS_FUNCTION__USE_mg_calloc
+#define realloc DO_NOT_USE_THIS_FUNCTION__USE_mg_realloc
+#define free DO_NOT_USE_THIS_FUNCTION__USE_mg_free
+#define snprintf DO_NOT_USE_THIS_FUNCTION__USE_mg_snprintf
+#ifdef _WIN32 /* vsnprintf must not be used in any system, * \ \ \             \
+               * but this define only works well for Windows. */
+#define vsnprintf DO_NOT_USE_THIS_FUNCTION__USE_mg_vsnprintf
+#endif
+
+
+static pthread_key_t sTlsKey; /* Thread local storage index */
+static int sTlsInit = 0;
+static int thread_idx_max = 0;
+
+
+struct mg_workerTLS {
+	int is_master;
+	unsigned long thread_idx;
+#if defined(_WIN32) && !defined(__SYMBIAN32__)
+	HANDLE pthread_cond_helper_mutex;
+	struct mg_workerTLS *next_waiting_thread;
+#endif
+};
+
+
+#if defined(__GNUC__) || defined(__MINGW32__)
+/* Show no warning in case system functions are not used. */
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-function"
+#endif
+#if defined(__clang__)
+/* Show no warning in case system functions are not used. */
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wunused-function"
+#endif
+
+
+/* Get a unique thread ID as unsigned long, independent from the data type
+ * of thread IDs defined by the operating system API.
+ * If two calls to mg_current_thread_id  return the same value, they calls
+ * are done from the same thread. If they return different values, they are
+ * done from different threads. (Provided this function is used in the same
+ * process context and threads are not repeatedly created and deleted, but
+ * CivetWeb does not do that).
+ * This function must match the signature required for SSL id callbacks:
+ * CRYPTO_set_id_callback
+ */
+static unsigned long
+mg_current_thread_id(void)
+{
+#ifdef _WIN32
+	return GetCurrentThreadId();
+#else
+
+#ifdef __clang__
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wunreachable-code"
+/* For every compiler, either "sizeof(pthread_t) > sizeof(unsigned long)"
+ * or not, so one of the two conditions will be unreachable by construction.
+ * Unfortunately the C standard does not define a way to check this at
+ * compile time, since the #if preprocessor conditions can not use the sizeof
+ * operator as an argument. */
+#endif
+
+	if (sizeof(pthread_t) > sizeof(unsigned long)) {
+		/* This is the problematic case for CRYPTO_set_id_callback:
+		 * The OS pthread_t can not be cast to unsigned long. */
+		struct mg_workerTLS *tls =
+		    (struct mg_workerTLS *)pthread_getspecific(sTlsKey);
+		if (tls == NULL) {
+			/* SSL called from an unknown thread: Create some thread index.
+			 */
+			tls = (struct mg_workerTLS *)mg_malloc(sizeof(struct mg_workerTLS));
+			tls->is_master = -2; /* -2 means "3rd party thread" */
+			tls->thread_idx = (unsigned)mg_atomic_inc(&thread_idx_max);
+			pthread_setspecific(sTlsKey, tls);
+		}
+		return tls->thread_idx;
+	} else {
+		/* pthread_t may be any data type, so a simple cast to unsigned long
+		 * can rise a warning/error, depending on the platform.
+		 * Here memcpy is used as an anything-to-anything cast. */
+		unsigned long ret = 0;
+		pthread_t t = pthread_self();
+		memcpy(&ret, &t, sizeof(pthread_t));
+		return ret;
+	}
+
+#ifdef __clang__
+#pragma clang diagnostic pop
+#endif
+
+#endif
+}
+
+
+#if defined(__GNUC__)
+/* Show no warning in case system functions are not used. */
+#pragma GCC diagnostic pop
+#endif
+#if defined(__clang__)
+/* Show no warning in case system functions are not used. */
+#pragma clang diagnostic pop
+#endif
+
+
+#if !defined(DEBUG_TRACE)
+#if defined(DEBUG)
+static void DEBUG_TRACE_FUNC(const char *func,
+                             unsigned line,
+                             PRINTF_FORMAT_STRING(const char *fmt),
+                             ...) PRINTF_ARGS(3, 4);
+
+static void
+DEBUG_TRACE_FUNC(const char *func, unsigned line, const char *fmt, ...)
+{
+	va_list args;
+	struct timespec tsnow;
+	uint64_t nsnow;
+	static uint64_t nslast;
+
+	/* Get some operating system independent thread id */
+	unsigned long thread_id = mg_current_thread_id();
+
+	clock_gettime(CLOCK_REALTIME, &tsnow);
+	nsnow = (((uint64_t)tsnow.tv_sec) * 1000000000) + (uint64_t)tsnow.tv_nsec;
+
+	flockfile(stdout);
+	printf("*** %lu.%09lu %12" INT64_FMT " %lu %s:%u: ",
+	       (unsigned long)tsnow.tv_sec,
+	       (unsigned long)tsnow.tv_nsec,
+	       nsnow - nslast,
+	       thread_id,
+	       func,
+	       line);
+	va_start(args, fmt);
+	vprintf(fmt, args);
+	va_end(args);
+	putchar('\n');
+	fflush(stdout);
+	funlockfile(stdout);
+	nslast = nsnow;
+}
+
+#define DEBUG_TRACE(fmt, ...)                                                  \
+	DEBUG_TRACE_FUNC(__func__, __LINE__, fmt, __VA_ARGS__)
+
+#else
+#define DEBUG_TRACE(fmt, ...)                                                  \
+	do {                                                                       \
+	} while (0)
+#endif /* DEBUG */
+#endif /* DEBUG_TRACE */
+
+
+#define MD5_STATIC static
+#include "md5.inl"
+
+/* Darwin prior to 7.0 and Win32 do not have socklen_t */
+#ifdef NO_SOCKLEN_T
+typedef int socklen_t;
+#endif /* NO_SOCKLEN_T */
+#define _DARWIN_UNLIMITED_SELECT
+
+#define IP_ADDR_STR_LEN (50) /* IPv6 hex string is 46 chars */
+
+#if !defined(MSG_NOSIGNAL)
+#define MSG_NOSIGNAL (0)
+#endif
+
+#if !defined(SOMAXCONN)
+#define SOMAXCONN (100)
+#endif
+
+/* Size of the accepted socket queue */
+#if !defined(MGSQLEN)
+#define MGSQLEN (20)
+#endif
+
+
+#if defined(NO_SSL)
+typedef struct SSL SSL; /* dummy for SSL argument to push/pull */
+typedef struct SSL_CTX SSL_CTX;
+#else
+#if defined(NO_SSL_DL)
+#include <openssl/ssl.h>
+#include <openssl/err.h>
+#include <openssl/crypto.h>
+#include <openssl/x509.h>
+#include <openssl/pem.h>
+#include <openssl/engine.h>
+#include <openssl/conf.h>
+#include <openssl/dh.h>
+#else
+/* SSL loaded dynamically from DLL.
+ * I put the prototypes here to be independent from OpenSSL source
+ * installation. */
+
+typedef struct ssl_st SSL;
+typedef struct ssl_method_st SSL_METHOD;
+typedef struct ssl_ctx_st SSL_CTX;
+typedef struct x509_store_ctx_st X509_STORE_CTX;
+typedef struct x509_name X509_NAME;
+typedef struct asn1_integer ASN1_INTEGER;
+typedef struct evp_md EVP_MD;
+typedef struct x509 X509;
+
+
+#define SSL_CTRL_OPTIONS (32)
+#define SSL_CTRL_CLEAR_OPTIONS (77)
+#define SSL_CTRL_SET_ECDH_AUTO (94)
+
+#define SSL_VERIFY_NONE (0)
+#define SSL_VERIFY_PEER (1)
+#define SSL_VERIFY_FAIL_IF_NO_PEER_CERT (2)
+#define SSL_VERIFY_CLIENT_ONCE (4)
+#define SSL_OP_ALL ((long)(0x80000BFFUL))
+#define SSL_OP_NO_SSLv2 (0x01000000L)
+#define SSL_OP_NO_SSLv3 (0x02000000L)
+#define SSL_OP_NO_TLSv1 (0x04000000L)
+#define SSL_OP_NO_TLSv1_2 (0x08000000L)
+#define SSL_OP_NO_TLSv1_1 (0x10000000L)
+#define SSL_OP_SINGLE_DH_USE (0x00100000L)
+#define SSL_OP_CIPHER_SERVER_PREFERENCE (0x00400000L)
+#define SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION (0x00010000L)
+
+#define SSL_ERROR_NONE (0)
+#define SSL_ERROR_SSL (1)
+#define SSL_ERROR_WANT_READ (2)
+#define SSL_ERROR_WANT_WRITE (3)
+#define SSL_ERROR_WANT_X509_LOOKUP (4)
+#define SSL_ERROR_SYSCALL (5) /* see errno */
+#define SSL_ERROR_ZERO_RETURN (6)
+#define SSL_ERROR_WANT_CONNECT (7)
+#define SSL_ERROR_WANT_ACCEPT (8)
+
+
+struct ssl_func {
+	const char *name;  /* SSL function name */
+	void (*ptr)(void); /* Function pointer */
+};
+
+#define SSL_free (*(void (*)(SSL *))ssl_sw[0].ptr)
+#define SSL_accept (*(int (*)(SSL *))ssl_sw[1].ptr)
+#define SSL_connect (*(int (*)(SSL *))ssl_sw[2].ptr)
+#define SSL_read (*(int (*)(SSL *, void *, int))ssl_sw[3].ptr)
+#define SSL_write (*(int (*)(SSL *, const void *, int))ssl_sw[4].ptr)
+#define SSL_get_error (*(int (*)(SSL *, int))ssl_sw[5].ptr)
+#define SSL_set_fd (*(int (*)(SSL *, SOCKET))ssl_sw[6].ptr)
+#define SSL_new (*(SSL * (*)(SSL_CTX *))ssl_sw[7].ptr)
+#define SSL_CTX_new (*(SSL_CTX * (*)(SSL_METHOD *))ssl_sw[8].ptr)
+#define SSLv23_server_method (*(SSL_METHOD * (*)(void))ssl_sw[9].ptr)
+#define SSL_library_init (*(int (*)(void))ssl_sw[10].ptr)
+#define SSL_CTX_use_PrivateKey_file                                            \
+	(*(int (*)(SSL_CTX *, const char *, int))ssl_sw[11].ptr)
+#define SSL_CTX_use_certificate_file                                           \
+	(*(int (*)(SSL_CTX *, const char *, int))ssl_sw[12].ptr)
+#define SSL_CTX_set_default_passwd_cb                                          \
+	(*(void (*)(SSL_CTX *, mg_callback_t))ssl_sw[13].ptr)
+#define SSL_CTX_free (*(void (*)(SSL_CTX *))ssl_sw[14].ptr)
+#define SSL_load_error_strings (*(void (*)(void))ssl_sw[15].ptr)
+#define SSL_CTX_use_certificate_chain_file                                     \
+	(*(int (*)(SSL_CTX *, const char *))ssl_sw[16].ptr)
+#define SSLv23_client_method (*(SSL_METHOD * (*)(void))ssl_sw[17].ptr)
+#define SSL_pending (*(int (*)(SSL *))ssl_sw[18].ptr)
+#define SSL_CTX_set_verify                                                     \
+	(*(void (*)(SSL_CTX *,                                                     \
+	            int,                                                           \
+	            int (*verify_callback)(int, X509_STORE_CTX *)))ssl_sw[19].ptr)
+#define SSL_shutdown (*(int (*)(SSL *))ssl_sw[20].ptr)
+#define SSL_CTX_load_verify_locations                                          \
+	(*(int (*)(SSL_CTX *, const char *, const char *))ssl_sw[21].ptr)
+#define SSL_CTX_set_default_verify_paths (*(int (*)(SSL_CTX *))ssl_sw[22].ptr)
+#define SSL_CTX_set_verify_depth (*(void (*)(SSL_CTX *, int))ssl_sw[23].ptr)
+#define SSL_get_peer_certificate (*(X509 * (*)(SSL *))ssl_sw[24].ptr)
+#define SSL_get_version (*(const char *(*)(SSL *))ssl_sw[25].ptr)
+#define SSL_get_current_cipher (*(SSL_CIPHER * (*)(SSL *))ssl_sw[26].ptr)
+#define SSL_CIPHER_get_name                                                    \
+	(*(const char *(*)(const SSL_CIPHER *))ssl_sw[27].ptr)
+#define SSL_CTX_check_private_key (*(int (*)(SSL_CTX *))ssl_sw[28].ptr)
+#define SSL_CTX_set_session_id_context                                         \
+	(*(int (*)(SSL_CTX *, const unsigned char *, unsigned int))ssl_sw[29].ptr)
+#define SSL_CTX_ctrl (*(long (*)(SSL_CTX *, int, long, void *))ssl_sw[30].ptr)
+
+
+#define SSL_CTX_set_cipher_list                                                \
+	(*(int (*)(SSL_CTX *, const char *))ssl_sw[31].ptr)
+#define SSL_CTX_set_options(ctx, op)                                           \
+	SSL_CTX_ctrl((ctx), SSL_CTRL_OPTIONS, (op), NULL)
+#define SSL_CTX_clear_options(ctx, op)                                         \
+	SSL_CTX_ctrl((ctx), SSL_CTRL_CLEAR_OPTIONS, (op), NULL)
+#define SSL_CTX_set_ecdh_auto(ctx, onoff)                                      \
+	SSL_CTX_ctrl(ctx, SSL_CTRL_SET_ECDH_AUTO, onoff, NULL)
+
+#define X509_get_notBefore(x) ((x)->cert_info->validity->notBefore)
+#define X509_get_notAfter(x) ((x)->cert_info->validity->notAfter)
+
+
+#define CRYPTO_num_locks (*(int (*)(void))crypto_sw[0].ptr)
+#define CRYPTO_set_locking_callback                                            \
+	(*(void (*)(void (*)(int, int, const char *, int)))crypto_sw[1].ptr)
+#define CRYPTO_set_id_callback                                                 \
+	(*(void (*)(unsigned long (*)(void)))crypto_sw[2].ptr)
+#define ERR_get_error (*(unsigned long (*)(void))crypto_sw[3].ptr)
+#define ERR_error_string (*(char *(*)(unsigned long, char *))crypto_sw[4].ptr)
+#define ERR_remove_state (*(void (*)(unsigned long))crypto_sw[5].ptr)
+#define ERR_free_strings (*(void (*)(void))crypto_sw[6].ptr)
+#define ENGINE_cleanup (*(void (*)(void))crypto_sw[7].ptr)
+#define CONF_modules_unload (*(void (*)(int))crypto_sw[8].ptr)
+#define CRYPTO_cleanup_all_ex_data (*(void (*)(void))crypto_sw[9].ptr)
+#define EVP_cleanup (*(void (*)(void))crypto_sw[10].ptr)
+#define X509_free (*(void (*)(X509 *))crypto_sw[11].ptr)
+#define X509_get_subject_name (*(X509_NAME * (*)(X509 *))crypto_sw[12].ptr)
+#define X509_get_issuer_name (*(X509_NAME * (*)(X509 *))crypto_sw[13].ptr)
+#define X509_NAME_oneline                                                      \
+	(*(char *(*)(X509_NAME *, char *, int))crypto_sw[14].ptr)
+#define X509_get_serialNumber (*(ASN1_INTEGER * (*)(X509 *))crypto_sw[15].ptr)
+#define i2c_ASN1_INTEGER                                                       \
+	(*(int (*)(ASN1_INTEGER *, unsigned char **))crypto_sw[16].ptr)
+#define EVP_get_digestbyname                                                   \
+	(*(const EVP_MD *(*)(const char *))crypto_sw[17].ptr)
+#define ASN1_digest                                                            \
+	(*(int (*)(int (*)(),                                                      \
+	           const EVP_MD *,                                                 \
+	           char *,                                                         \
+	           unsigned char *,                                                \
+	           unsigned int *))crypto_sw[18].ptr)
+#define i2d_X509 (*(int (*)(X509 *, unsigned char **))crypto_sw[19].ptr)
+
+
+/* set_ssl_option() function updates this array.
+ * It loads SSL library dynamically and changes NULLs to the actual addresses
+ * of respective functions. The macros above (like SSL_connect()) are really
+ * just calling these functions indirectly via the pointer. */
+static struct ssl_func ssl_sw[] = {{"SSL_free", NULL},
+                                   {"SSL_accept", NULL},
+                                   {"SSL_connect", NULL},
+                                   {"SSL_read", NULL},
+                                   {"SSL_write", NULL},
+                                   {"SSL_get_error", NULL},
+                                   {"SSL_set_fd", NULL},
+                                   {"SSL_new", NULL},
+                                   {"SSL_CTX_new", NULL},
+                                   {"SSLv23_server_method", NULL},
+                                   {"SSL_library_init", NULL},
+                                   {"SSL_CTX_use_PrivateKey_file", NULL},
+                                   {"SSL_CTX_use_certificate_file", NULL},
+                                   {"SSL_CTX_set_default_passwd_cb", NULL},
+                                   {"SSL_CTX_free", NULL},
+                                   {"SSL_load_error_strings", NULL},
+                                   {"SSL_CTX_use_certificate_chain_file", NULL},
+                                   {"SSLv23_client_method", NULL},
+                                   {"SSL_pending", NULL},
+                                   {"SSL_CTX_set_verify", NULL},
+                                   {"SSL_shutdown", NULL},
+                                   {"SSL_CTX_load_verify_locations", NULL},
+                                   {"SSL_CTX_set_default_verify_paths", NULL},
+                                   {"SSL_CTX_set_verify_depth", NULL},
+                                   {"SSL_get_peer_certificate", NULL},
+                                   {"SSL_get_version", NULL},
+                                   {"SSL_get_current_cipher", NULL},
+                                   {"SSL_CIPHER_get_name", NULL},
+                                   {"SSL_CTX_check_private_key", NULL},
+                                   {"SSL_CTX_set_session_id_context", NULL},
+                                   {"SSL_CTX_ctrl", NULL},
+                                   {"SSL_CTX_set_cipher_list", NULL},
+                                   {NULL, NULL}};
+
+
+/* Similar array as ssl_sw. These functions could be located in different
+ * lib. */
+static struct ssl_func crypto_sw[] = {{"CRYPTO_num_locks", NULL},
+                                      {"CRYPTO_set_locking_callback", NULL},
+                                      {"CRYPTO_set_id_callback", NULL},
+                                      {"ERR_get_error", NULL},
+                                      {"ERR_error_string", NULL},
+                                      {"ERR_remove_state", NULL},
+                                      {"ERR_free_strings", NULL},
+                                      {"ENGINE_cleanup", NULL},
+                                      {"CONF_modules_unload", NULL},
+                                      {"CRYPTO_cleanup_all_ex_data", NULL},
+                                      {"EVP_cleanup", NULL},
+                                      {"X509_free", NULL},
+                                      {"X509_get_subject_name", NULL},
+                                      {"X509_get_issuer_name", NULL},
+                                      {"X509_NAME_oneline", NULL},
+                                      {"X509_get_serialNumber", NULL},
+                                      {"i2c_ASN1_INTEGER", NULL},
+                                      {"EVP_get_digestbyname", NULL},
+                                      {"ASN1_digest", NULL},
+                                      {"i2d_X509", NULL},
+                                      {NULL, NULL}};
+#endif /* NO_SSL_DL */
+#endif /* NO_SSL */
+
+
+#if !defined(NO_CACHING)
+static const char *month_names[] = {"Jan",
+                                    "Feb",
+                                    "Mar",
+                                    "Apr",
+                                    "May",
+                                    "Jun",
+                                    "Jul",
+                                    "Aug",
+                                    "Sep",
+                                    "Oct",
+                                    "Nov",
+                                    "Dec"};
+#endif /* !NO_CACHING */
+
+/* Unified socket address. For IPv6 support, add IPv6 address structure in the
+ * union u. */
+union usa {
+	struct sockaddr sa;
+	struct sockaddr_in sin;
+#if defined(USE_IPV6)
+	struct sockaddr_in6 sin6;
+#endif
+};
+
+/* Describes a string (chunk of memory). */
+struct vec {
+	const char *ptr;
+	size_t len;
+};
+
+struct mg_file_stat {
+	/* File properties filled by mg_stat: */
+	uint64_t size;
+	time_t last_modified;
+	int is_directory; /* Set to 1 if mg_stat is called for a directory */
+	int is_gzipped;   /* Set to 1 if the content is gzipped, in which
+	                   * case we need a "Content-Eencoding: gzip" header */
+	int location;     /* 0 = nowhere, 1 = on disk, 2 = in memory */
+};
+
+struct mg_file_in_memory {
+	char *p;
+	uint32_t pos;
+	char mode;
+};
+
+struct mg_file_access {
+	/* File properties filled by mg_fopen: */
+	FILE *fp;
+	/* TODO (low): Replace "membuf" implementation by a "file in memory"
+	 * support library. Use some struct mg_file_in_memory *mf; instead of
+	 * membuf char pointer. */
+	const char *membuf;
+};
+
+struct mg_file {
+	struct mg_file_stat stat;
+	struct mg_file_access access;
+};
+
+#define STRUCT_FILE_INITIALIZER                                                \
+	{                                                                          \
+		{                                                                      \
+			(uint64_t)0, (time_t)0, 0, 0, 0                                    \
+		}                                                                      \
+		,                                                                      \
+		{                                                                      \
+			(FILE *) NULL, (const char *)NULL                                  \
+		}                                                                      \
+	}
+
+/* Describes listening socket, or socket which was accept()-ed by the master
+ * thread and queued for future handling by the worker thread. */
+struct socket {
+	SOCKET sock;             /* Listening socket */
+	union usa lsa;           /* Local socket address */
+	union usa rsa;           /* Remote socket address */
+	unsigned char is_ssl;    /* Is port SSL-ed */
+	unsigned char ssl_redir; /* Is port supposed to redirect everything to SSL
+	                          * port */
+	unsigned char in_use;    /* Is valid */
+};
+
+/* NOTE(lsm): this enum shoulds be in sync with the config_options below. */
+enum {
+	CGI_EXTENSIONS,
+	CGI_ENVIRONMENT,
+	PUT_DELETE_PASSWORDS_FILE,
+	CGI_INTERPRETER,
+	PROTECT_URI,
+	AUTHENTICATION_DOMAIN,
+	SSI_EXTENSIONS,
+	THROTTLE,
+	ACCESS_LOG_FILE,
+	ENABLE_DIRECTORY_LISTING,
+	ERROR_LOG_FILE,
+	GLOBAL_PASSWORDS_FILE,
+	INDEX_FILES,
+	ENABLE_KEEP_ALIVE,
+	ACCESS_CONTROL_LIST,
+	EXTRA_MIME_TYPES,
+	LISTENING_PORTS,
+	DOCUMENT_ROOT,
+	SSL_CERTIFICATE,
+	NUM_THREADS,
+	RUN_AS_USER,
+	REWRITE,
+	HIDE_FILES,
+	REQUEST_TIMEOUT,
+	KEEP_ALIVE_TIMEOUT,
+	LINGER_TIMEOUT,
+	SSL_DO_VERIFY_PEER,
+	SSL_CA_PATH,
+	SSL_CA_FILE,
+	SSL_VERIFY_DEPTH,
+	SSL_DEFAULT_VERIFY_PATHS,
+	SSL_CIPHER_LIST,
+	SSL_PROTOCOL_VERSION,
+	SSL_SHORT_TRUST,
+
+#if defined(USE_WEBSOCKET)
+	WEBSOCKET_TIMEOUT,
+#endif
+
+	DECODE_URL,
+
+#if defined(USE_LUA)
+	LUA_PRELOAD_FILE,
+	LUA_SCRIPT_EXTENSIONS,
+	LUA_SERVER_PAGE_EXTENSIONS,
+#endif
+#if defined(USE_DUKTAPE)
+	DUKTAPE_SCRIPT_EXTENSIONS,
+#endif
+
+#if defined(USE_WEBSOCKET)
+	WEBSOCKET_ROOT,
+#endif
+#if defined(USE_LUA) && defined(USE_WEBSOCKET)
+	LUA_WEBSOCKET_EXTENSIONS,
+#endif
+
+	ACCESS_CONTROL_ALLOW_ORIGIN,
+	ERROR_PAGES,
+	CONFIG_TCP_NODELAY, /* Prepended CONFIG_ to avoid conflict with the
+                         * socket option typedef TCP_NODELAY. */
+#if !defined(NO_CACHING)
+	STATIC_FILE_MAX_AGE,
+#endif
+#if defined(__linux__)
+	ALLOW_SENDFILE_CALL,
+#endif
+#if defined(_WIN32)
+	CASE_SENSITIVE_FILES,
+#endif
+#if defined(USE_LUA)
+	LUA_BACKGROUND_SCRIPT,
+#endif
+
+	NUM_OPTIONS
+};
+
+
+/* Config option name, config types, default value */
+static struct mg_option config_options[] = {
+    {"cgi_pattern", CONFIG_TYPE_EXT_PATTERN, "**.cgi$|**.pl$|**.php$"},
+    {"cgi_environment", CONFIG_TYPE_STRING, NULL},
+    {"put_delete_auth_file", CONFIG_TYPE_FILE, NULL},
+    {"cgi_interpreter", CONFIG_TYPE_FILE, NULL},
+    {"protect_uri", CONFIG_TYPE_STRING, NULL},
+    {"authentication_domain", CONFIG_TYPE_STRING, "mydomain.com"},
+    {"ssi_pattern", CONFIG_TYPE_EXT_PATTERN, "**.shtml$|**.shtm$"},
+    {"throttle", CONFIG_TYPE_STRING, NULL},
+    {"access_log_file", CONFIG_TYPE_FILE, NULL},
+    {"enable_directory_listing", CONFIG_TYPE_BOOLEAN, "yes"},
+    {"error_log_file", CONFIG_TYPE_FILE, NULL},
+    {"global_auth_file", CONFIG_TYPE_FILE, NULL},
+    {"index_files",
+     CONFIG_TYPE_STRING,
+#ifdef USE_LUA
+     "index.xhtml,index.html,index.htm,index.lp,index.lsp,index.lua,index.cgi,"
+     "index.shtml,index.php"},
+#else
+     "index.xhtml,index.html,index.htm,index.cgi,index.shtml,index.php"},
+#endif
+    {"enable_keep_alive", CONFIG_TYPE_BOOLEAN, "no"},
+    {"access_control_list", CONFIG_TYPE_STRING, NULL},
+    {"extra_mime_types", CONFIG_TYPE_STRING, NULL},
+    {"listening_ports", CONFIG_TYPE_STRING, "8080"},
+    {"document_root", CONFIG_TYPE_DIRECTORY, NULL},
+    {"ssl_certificate", CONFIG_TYPE_FILE, NULL},
+    {"num_threads", CONFIG_TYPE_NUMBER, "50"},
+    {"run_as_user", CONFIG_TYPE_STRING, NULL},
+    {"url_rewrite_patterns", CONFIG_TYPE_STRING, NULL},
+    {"hide_files_patterns", CONFIG_TYPE_EXT_PATTERN, NULL},
+    {"request_timeout_ms", CONFIG_TYPE_NUMBER, "30000"},
+    {"keep_alive_timeout_ms", CONFIG_TYPE_NUMBER, "500"},
+    {"linger_timeout_ms", CONFIG_TYPE_NUMBER, NULL},
+    {"ssl_verify_peer", CONFIG_TYPE_BOOLEAN, "no"},
+    {"ssl_ca_path", CONFIG_TYPE_DIRECTORY, NULL},
+    {"ssl_ca_file", CONFIG_TYPE_FILE, NULL},
+    {"ssl_verify_depth", CONFIG_TYPE_NUMBER, "9"},
+    {"ssl_default_verify_paths", CONFIG_TYPE_BOOLEAN, "yes"},
+    {"ssl_cipher_list", CONFIG_TYPE_STRING, NULL},
+    {"ssl_protocol_version", CONFIG_TYPE_NUMBER, "0"},
+    {"ssl_short_trust", CONFIG_TYPE_BOOLEAN, "no"},
+#if defined(USE_WEBSOCKET)
+    {"websocket_timeout_ms", CONFIG_TYPE_NUMBER, "30000"},
+#endif
+    {"decode_url", CONFIG_TYPE_BOOLEAN, "yes"},
+
+#if defined(USE_LUA)
+    {"lua_preload_file", CONFIG_TYPE_FILE, NULL},
+    {"lua_script_pattern", CONFIG_TYPE_EXT_PATTERN, "**.lua$"},
+    {"lua_server_page_pattern", CONFIG_TYPE_EXT_PATTERN, "**.lp$|**.lsp$"},
+#endif
+#if defined(USE_DUKTAPE)
+    /* The support for duktape is still in alpha version state.
+     * The name of this config option might change. */
+    {"duktape_script_pattern", CONFIG_TYPE_EXT_PATTERN, "**.ssjs$"},
+#endif
+
+#if defined(USE_WEBSOCKET)
+    {"websocket_root", CONFIG_TYPE_DIRECTORY, NULL},
+#endif
+#if defined(USE_LUA) && defined(USE_WEBSOCKET)
+    {"lua_websocket_pattern", CONFIG_TYPE_EXT_PATTERN, "**.lua$"},
+#endif
+    {"access_control_allow_origin", CONFIG_TYPE_STRING, "*"},
+    {"error_pages", CONFIG_TYPE_DIRECTORY, NULL},
+    {"tcp_nodelay", CONFIG_TYPE_NUMBER, "0"},
+#if !defined(NO_CACHING)
+    {"static_file_max_age", CONFIG_TYPE_NUMBER, "3600"},
+#endif
+#if defined(__linux__)
+    {"allow_sendfile_call", CONFIG_TYPE_BOOLEAN, "yes"},
+#endif
+#if defined(_WIN32)
+    {"case_sensitive", CONFIG_TYPE_BOOLEAN, "no"},
+#endif
+#if defined(USE_LUA)
+    {"lua_background_script", CONFIG_TYPE_FILE, NULL},
+#endif
+
+    {NULL, CONFIG_TYPE_UNKNOWN, NULL}};
+
+/* Check if the config_options and the corresponding enum have compatible
+ * sizes. */
+mg_static_assert((sizeof(config_options) / sizeof(config_options[0]))
+                     == (NUM_OPTIONS + 1),
+                 "config_options and enum not sync");
+
+enum { REQUEST_HANDLER, WEBSOCKET_HANDLER, AUTH_HANDLER };
+
+struct mg_handler_info {
+	/* Name/Pattern of the URI. */
+	char *uri;
+	size_t uri_len;
+
+	/* handler type */
+	int handler_type;
+
+	/* Handler for http/https or authorization requests. */
+	mg_request_handler handler;
+
+	/* Handler for ws/wss (websocket) requests. */
+	mg_websocket_connect_handler connect_handler;
+	mg_websocket_ready_handler ready_handler;
+	mg_websocket_data_handler data_handler;
+	mg_websocket_close_handler close_handler;
+
+	/* accepted subprotocols for ws/wss requests. */
+	struct mg_websocket_subprotocols *subprotocols;
+
+	/* Handler for authorization requests */
+	mg_authorization_handler auth_handler;
+
+	/* User supplied argument for the handler function. */
+	void *cbdata;
+
+	/* next handler in a linked list */
+	struct mg_handler_info *next;
+};
+
+struct mg_context {
+	volatile int stop_flag;        /* Should we stop event loop */
+	SSL_CTX *ssl_ctx;              /* SSL context */
+	char *config[NUM_OPTIONS];     /* Civetweb configuration parameters */
+	struct mg_callbacks callbacks; /* User-defined callback function */
+	void *user_data;               /* User-defined data */
+	int context_type;              /* 1 = server context,
+	                                * 2 = ws/wss client context,
+	                                */
+
+	struct socket *listening_sockets;
+	struct pollfd *listening_socket_fds;
+	unsigned int num_listening_sockets;
+
+	pthread_mutex_t thread_mutex; /* Protects (max|num)_threads */
+
+#ifdef ALTERNATIVE_QUEUE
+	struct socket *client_socks;
+	void **client_wait_events;
+#else
+	struct socket queue[MGSQLEN]; /* Accepted sockets */
+	volatile int sq_head;         /* Head of the socket queue */
+	volatile int sq_tail;         /* Tail of the socket queue */
+	pthread_cond_t sq_full;       /* Signaled when socket is produced */
+	pthread_cond_t sq_empty;      /* Signaled when socket is consumed */
+#endif
+
+	pthread_t masterthreadid; /* The master thread ID */
+	unsigned int
+	    cfg_worker_threads;      /* The number of configured worker threads. */
+	pthread_t *worker_threadids; /* The worker thread IDs */
+	struct mg_connection *worker_connections; /* The connection struct, pre-
+	                                           * allocated for each worker */
+
+	time_t start_time;        /* Server start time, used for authentication */
+	uint64_t auth_nonce_mask; /* Mask for all nonce values */
+	pthread_mutex_t nonce_mutex; /* Protects nonce_count */
+	unsigned long nonce_count;   /* Used nonces, used for authentication */
+
+	char *systemName; /* What operating system is running */
+
+	/* linked list of uri handlers */
+	struct mg_handler_info *handlers;
+
+#if defined(USE_LUA) && defined(USE_WEBSOCKET)
+	/* linked list of shared lua websockets */
+	struct mg_shared_lua_websocket_list *shared_lua_websockets;
+#endif
+
+#if defined(USE_TIMERS)
+	struct ttimers *timers;
+#endif
+
+#if defined(USE_LUA)
+	void *lua_background_state;
+#endif
+};
+
+
+struct mg_connection {
+	struct mg_request_info request_info;
+	struct mg_context *ctx;
+	SSL *ssl;                 /* SSL descriptor */
+	SSL_CTX *client_ssl_ctx;  /* SSL context for client connections */
+	struct socket client;     /* Connected client */
+	time_t conn_birth_time;   /* Time (wall clock) when connection was
+	                           * established */
+	struct timespec req_time; /* Time (since system start) when the request
+	                           * was received */
+	int64_t num_bytes_sent;   /* Total bytes sent to client */
+	int64_t content_len;      /* Content-Length header value */
+	int64_t consumed_content; /* How many bytes of content have been read */
+	int is_chunked;           /* Transfer-Encoding is chunked: 0=no, 1=yes:
+	                           * data available, 2: all data read */
+	size_t chunk_remainder;   /* Unread data from the last chunk */
+	char *buf;                /* Buffer for received data */
+	char *path_info;          /* PATH_INFO part of the URL */
+
+	int must_close;       /* 1 if connection must be closed */
+	int in_error_handler; /* 1 if in handler for user defined error
+	                       * pages */
+	int handled_requests; /* Number of requests handled by this connection */
+	int buf_size;         /* Buffer size */
+	int request_len;      /* Size of the request + headers in a buffer */
+	int data_len;         /* Total size of data in a buffer */
+	int status_code;      /* HTTP reply status code, e.g. 200 */
+	int throttle;         /* Throttling, bytes/sec. <= 0 means no
+	                       * throttle */
+	time_t last_throttle_time;   /* Last time throttled data was sent */
+	int64_t last_throttle_bytes; /* Bytes sent this second */
+	pthread_mutex_t mutex;       /* Used by mg_(un)lock_connection to ensure
+	                              * atomic transmissions for websockets */
+#if defined(USE_LUA) && defined(USE_WEBSOCKET)
+	void *lua_websocket_state; /* Lua_State for a websocket connection */
+#endif
+
+	int thread_index; /* Thread index within ctx */
+};
+
+
+/* Directory entry */
+struct de {
+	struct mg_connection *conn;
+	char *file_name;
+	struct mg_file_stat file;
+};
+
+
+#if defined(USE_WEBSOCKET)
+static int is_websocket_protocol(const struct mg_connection *conn);
+#else
+#define is_websocket_protocol(conn) (0)
+#endif
+
+
+#if !defined(NO_THREAD_NAME)
+#if defined(_WIN32) && defined(_MSC_VER)
+/* Set the thread name for debugging purposes in Visual Studio
+ * http://msdn.microsoft.com/en-us/library/xcb2z8hs.aspx
+ */
+#pragma pack(push, 8)
+typedef struct tagTHREADNAME_INFO {
+	DWORD dwType;     /* Must be 0x1000. */
+	LPCSTR szName;    /* Pointer to name (in user addr space). */
+	DWORD dwThreadID; /* Thread ID (-1=caller thread). */
+	DWORD dwFlags;    /* Reserved for future use, must be zero. */
+} THREADNAME_INFO;
+#pragma pack(pop)
+
+#elif defined(__linux__)
+
+#include <sys/prctl.h>
+#include <sys/sendfile.h>
+#include <sys/eventfd.h>
+
+
+#if defined(ALTERNATIVE_QUEUE)
+
+static void *
+event_create(void)
+{
+	int ret = eventfd(0, EFD_CLOEXEC);
+	if (ret == -1) {
+		/* Linux uses -1 on error, Windows NULL. */
+		/* However, Linux does not return 0 on success either. */
+		return 0;
+	}
+	return (void *)ret;
+}
+
+
+static int
+event_wait(void *eventhdl)
+{
+	uint64_t u;
+	int s = (int)read((int)eventhdl, &u, sizeof(u));
+	if (s != sizeof(uint64_t)) {
+		/* error */
+		return 0;
+	}
+	(void)u; /* the value is not required */
+	return 1;
+}
+
+
+static int
+event_signal(void *eventhdl)
+{
+	uint64_t u = 1;
+	int s = (int)write((int)eventhdl, &u, sizeof(u));
+	if (s != sizeof(uint64_t)) {
+		/* error */
+		return 0;
+	}
+	return 1;
+}
+
+
+static void
+event_destroy(void *eventhdl)
+{
+	close((int)eventhdl);
+}
+#endif
+
+#endif
+
+
+#if !defined(__linux__) && !defined(_WIN32) && defined(ALTERNATIVE_QUEUE)
+
+struct posix_event {
+	pthread_mutex_t mutex;
+	pthread_cond_t cond;
+};
+
+
+static void *
+event_create(void)
+{
+	struct posix_event *ret = mg_malloc(sizeof(struct posix_event));
+	if (ret == 0) {
+		/* out of memory */
+		return 0;
+	}
+	if (0 != pthread_mutex_init(&(ret->mutex), NULL)) {
+		/* pthread mutex not available */
+		mg_free(ret);
+		return 0;
+	}
+	if (0 != pthread_cond_init(&(ret->cond), NULL)) {
+		/* pthread cond not available */
+		pthread_mutex_destroy(&(ret->mutex));
+		mg_free(ret);
+		return 0;
+	}
+	return (void *)ret;
+}
+
+
+static int
+event_wait(void *eventhdl)
+{
+	struct posix_event *ev = (struct posix_event *)eventhdl;
+	pthread_mutex_lock(&(ev->mutex));
+	pthread_cond_wait(&(ev->cond), &(ev->mutex));
+	pthread_mutex_unlock(&(ev->mutex));
+	return 1;
+}
+
+
+static int
+event_signal(void *eventhdl)
+{
+	struct posix_event *ev = (struct posix_event *)eventhdl;
+	pthread_mutex_lock(&(ev->mutex));
+	pthread_cond_signal(&(ev->cond));
+	pthread_mutex_unlock(&(ev->mutex));
+	return 1;
+}
+
+
+static void
+event_destroy(void *eventhdl)
+{
+	struct posix_event *ev = (struct posix_event *)eventhdl;
+	pthread_cond_destroy(&(ev->cond));
+	pthread_mutex_destroy(&(ev->mutex));
+	mg_free(ev);
+}
+#endif
+
+
+static void
+mg_set_thread_name(const char *name)
+{
+	char threadName[16 + 1]; /* 16 = Max. thread length in Linux/OSX/.. */
+
+	mg_snprintf(
+	    NULL, NULL, threadName, sizeof(threadName), "civetweb-%s", name);
+
+#if defined(_WIN32)
+#if defined(_MSC_VER)
+	/* Windows and Visual Studio Compiler */
+	__try
+	{
+		THREADNAME_INFO info;
+		info.dwType = 0x1000;
+		info.szName = threadName;
+		info.dwThreadID = ~0U;
+		info.dwFlags = 0;
+
+		RaiseException(0x406D1388,
+		               0,
+		               sizeof(info) / sizeof(ULONG_PTR),
+		               (ULONG_PTR *)&info);
+	}
+	__except(EXCEPTION_EXECUTE_HANDLER)
+	{
+	}
+#elif defined(__MINGW32__)
+/* No option known to set thread name for MinGW */
+#endif
+#elif defined(__GLIBC__)                                                       \
+    && ((__GLIBC__ > 2) || ((__GLIBC__ == 2) && (__GLIBC_MINOR__ >= 12)))
+	/* pthread_setname_np first appeared in glibc in version 2.12*/
+	(void)pthread_setname_np(pthread_self(), threadName);
+#elif defined(__linux__)
+	/* on linux we can use the old prctl function */
+	(void)prctl(PR_SET_NAME, threadName, 0, 0, 0);
+#endif
+}
+#else /* !defined(NO_THREAD_NAME) */
+void
+mg_set_thread_name(const char *threadName)
+{
+}
+#endif
+
+
+#if defined(MG_LEGACY_INTERFACE)
+const char **
+mg_get_valid_option_names(void)
+{
+	/* This function is deprecated. Use mg_get_valid_options instead. */
+	static const char *
+	    data[2 * sizeof(config_options) / sizeof(config_options[0])] = {0};
+	int i;
+
+	for (i = 0; config_options[i].name != NULL; i++) {
+		data[i * 2] = config_options[i].name;
+		data[i * 2 + 1] = config_options[i].default_value;
+	}
+
+	return data;
+}
+#endif
+
+
+const struct mg_option *
+mg_get_valid_options(void)
+{
+	return config_options;
+}
+
+
+/* Do not open file (used in is_file_in_memory) */
+#define MG_FOPEN_MODE_NONE (0)
+
+/* Open file for read only access */
+#define MG_FOPEN_MODE_READ (1)
+
+/* Open file for writing, create and overwrite */
+#define MG_FOPEN_MODE_WRITE (2)
+
+/* Open file for writing, create and append */
+#define MG_FOPEN_MODE_APPEND (4)
+
+
+/* If a file is in memory, set all "stat" members and the membuf pointer of
+ * output filep and return 1, otherwise return 0 and don't modify anything. */
+static int
+open_file_in_memory(const struct mg_connection *conn,
+                    const char *path,
+                    struct mg_file *filep,
+                    int mode)
+{
+	size_t size = 0;
+	const char *buf = NULL;
+	if (!conn) {
+		return 0;
+	}
+
+	if ((mode != MG_FOPEN_MODE_NONE) && (mode != MG_FOPEN_MODE_READ)) {
+		return 0;
+	}
+
+	if (conn->ctx->callbacks.open_file) {
+		buf = conn->ctx->callbacks.open_file(conn, path, &size);
+		if (buf != NULL) {
+			if (filep == NULL) {
+				/* This is a file in memory, but we cannot store the properties
+				 * now.
+				 * Called from "is_file_in_memory" function. */
+				return 1;
+			}
+
+			/* NOTE: override filep->size only on success. Otherwise, it might
+			 * break constructs like if (!mg_stat() || !mg_fopen()) ... */
+			filep->access.membuf = buf;
+			filep->access.fp = NULL;
+
+			/* Size was set by the callback */
+			filep->stat.size = size;
+
+			/* Assume the data may change during runtime by setting
+			 * last_modified = now */
+			filep->stat.last_modified = time(NULL);
+
+			filep->stat.is_directory = 0;
+			filep->stat.is_gzipped = 0;
+		}
+	}
+
+	return (buf != NULL);
+}
+
+
+static int
+is_file_in_memory(const struct mg_connection *conn, const char *path)
+{
+	return open_file_in_memory(conn, path, NULL, MG_FOPEN_MODE_NONE);
+}
+
+
+static int
+is_file_opened(const struct mg_file_access *fileacc)
+{
+	if (!fileacc) {
+		return 0;
+	}
+	return (fileacc->membuf != NULL) || (fileacc->fp != NULL);
+}
+
+
+static int mg_stat(const struct mg_connection *conn,
+                   const char *path,
+                   struct mg_file_stat *filep);
+
+
+/* mg_fopen will open a file either in memory or on the disk.
+ * The input parameter path is a string in UTF-8 encoding.
+ * The input parameter mode is MG_FOPEN_MODE_*
+ * On success, either fp or membuf will be set in the output
+ * struct file. All status members will also be set.
+ * The function returns 1 on success, 0 on error. */
+static int
+mg_fopen(const struct mg_connection *conn,
+         const char *path,
+         int mode,
+         struct mg_file *filep)
+{
+	int found;
+
+	if (!filep) {
+		return 0;
+	}
+	filep->access.fp = NULL;
+	filep->access.membuf = NULL;
+
+	if (!is_file_in_memory(conn, path)) {
+
+		/* filep is initialized in mg_stat: all fields with memset to,
+		* some fields like size and modification date with values */
+		found = mg_stat(conn, path, &(filep->stat));
+
+		if ((mode == MG_FOPEN_MODE_READ) && (!found)) {
+			/* file does not exist and will not be created */
+			return 0;
+		}
+
+#ifdef _WIN32
+		{
+			wchar_t wbuf[PATH_MAX];
+			path_to_unicode(conn, path, wbuf, ARRAY_SIZE(wbuf));
+			switch (mode) {
+			case MG_FOPEN_MODE_READ:
+				filep->access.fp = _wfopen(wbuf, L"rb");
+				break;
+			case MG_FOPEN_MODE_WRITE:
+				filep->access.fp = _wfopen(wbuf, L"wb");
+				break;
+			case MG_FOPEN_MODE_APPEND:
+				filep->access.fp = _wfopen(wbuf, L"ab");
+				break;
+			}
+		}
+#else
+		/* Linux et al already use unicode. No need to convert. */
+		switch (mode) {
+		case MG_FOPEN_MODE_READ:
+			filep->access.fp = fopen(path, "r");
+			break;
+		case MG_FOPEN_MODE_WRITE:
+			filep->access.fp = fopen(path, "w");
+			break;
+		case MG_FOPEN_MODE_APPEND:
+			filep->access.fp = fopen(path, "a");
+			break;
+		}
+
+#endif
+		if (!found) {
+			/* File did not exist before fopen was called.
+			 * Maybe it has been created now. Get stat info
+			 * like creation time now. */
+			found = mg_stat(conn, path, &(filep->stat));
+			(void)found;
+		}
+
+		/* file is on disk */
+		return (filep->access.fp != NULL);
+
+	} else {
+		/* is_file_in_memory returned true */
+		if (open_file_in_memory(conn, path, filep, mode)) {
+			/* file is in memory */
+			return (filep->access.membuf != NULL);
+		}
+	}
+
+	/* Open failed */
+	return 0;
+}
+
+
+/* return 0 on success, just like fclose */
+static int
+mg_fclose(struct mg_file_access *fileacc)
+{
+	int ret = -1;
+	if (fileacc != NULL) {
+		if (fileacc->fp != NULL) {
+			ret = fclose(fileacc->fp);
+		} else if (fileacc->membuf != NULL) {
+			ret = 0;
+		}
+		/* reset all members of fileacc */
+		memset(fileacc, 0, sizeof(*fileacc));
+	}
+	return ret;
+}
+
+
+static void
+mg_strlcpy(register char *dst, register const char *src, size_t n)
+{
+	for (; *src != '\0' && n > 1; n--) {
+		*dst++ = *src++;
+	}
+	*dst = '\0';
+}
+
+
+static int
+lowercase(const char *s)
+{
+	return tolower(*(const unsigned char *)s);
+}
+
+
+int
+mg_strncasecmp(const char *s1, const char *s2, size_t len)
+{
+	int diff = 0;
+
+	if (len > 0) {
+		do {
+			diff = lowercase(s1++) - lowercase(s2++);
+		} while (diff == 0 && s1[-1] != '\0' && --len > 0);
+	}
+
+	return diff;
+}
+
+
+int
+mg_strcasecmp(const char *s1, const char *s2)
+{
+	int diff;
+
+	do {
+		diff = lowercase(s1++) - lowercase(s2++);
+	} while (diff == 0 && s1[-1] != '\0');
+
+	return diff;
+}
+
+
+static char *
+mg_strndup(const char *ptr, size_t len)
+{
+	char *p;
+
+	if ((p = (char *)mg_malloc(len + 1)) != NULL) {
+		mg_strlcpy(p, ptr, len + 1);
+	}
+
+	return p;
+}
+
+
+static char *
+mg_strdup(const char *str)
+{
+	return mg_strndup(str, strlen(str));
+}
+
+
+static const char *
+mg_strcasestr(const char *big_str, const char *small_str)
+{
+	size_t i, big_len = strlen(big_str), small_len = strlen(small_str);
+
+	if (big_len >= small_len) {
+		for (i = 0; i <= (big_len - small_len); i++) {
+			if (mg_strncasecmp(big_str + i, small_str, small_len) == 0) {
+				return big_str + i;
+			}
+		}
+	}
+
+	return NULL;
+}
+
+
+/* Return null terminated string of given maximum length.
+ * Report errors if length is exceeded. */
+static void
+mg_vsnprintf(const struct mg_connection *conn,
+             int *truncated,
+             char *buf,
+             size_t buflen,
+             const char *fmt,
+             va_list ap)
+{
+	int n, ok;
+
+	if (buflen == 0) {
+		return;
+	}
+
+#ifdef __clang__
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wformat-nonliteral"
+/* Using fmt as a non-literal is intended here, since it is mostly called
+ * indirectly by mg_snprintf */
+#endif
+
+	n = (int)vsnprintf_impl(buf, buflen, fmt, ap);
+	ok = (n >= 0) && ((size_t)n < buflen);
+
+#ifdef __clang__
+#pragma clang diagnostic pop
+#endif
+
+	if (ok) {
+		if (truncated) {
+			*truncated = 0;
+		}
+	} else {
+		if (truncated) {
+			*truncated = 1;
+		}
+		mg_cry(conn,
+		       "truncating vsnprintf buffer: [%.*s]",
+		       (int)((buflen > 200) ? 200 : (buflen - 1)),
+		       buf);
+		n = (int)buflen - 1;
+	}
+	buf[n] = '\0';
+}
+
+
+static void
+mg_snprintf(const struct mg_connection *conn,
+            int *truncated,
+            char *buf,
+            size_t buflen,
+            const char *fmt,
+            ...)
+{
+	va_list ap;
+
+	va_start(ap, fmt);
+	mg_vsnprintf(conn, truncated, buf, buflen, fmt, ap);
+	va_end(ap);
+}
+
+
+static int
+get_option_index(const char *name)
+{
+	int i;
+
+	for (i = 0; config_options[i].name != NULL; i++) {
+		if (strcmp(config_options[i].name, name) == 0) {
+			return i;
+		}
+	}
+	return -1;
+}
+
+
+const char *
+mg_get_option(const struct mg_context *ctx, const char *name)
+{
+	int i;
+	if ((i = get_option_index(name)) == -1) {
+		return NULL;
+	} else if (!ctx || ctx->config[i] == NULL) {
+		return "";
+	} else {
+		return ctx->config[i];
+	}
+}
+
+
+struct mg_context *
+mg_get_context(const struct mg_connection *conn)
+{
+	return (conn == NULL) ? (struct mg_context *)NULL : (conn->ctx);
+}
+
+
+void *
+mg_get_user_data(const struct mg_context *ctx)
+{
+	return (ctx == NULL) ? NULL : ctx->user_data;
+}
+
+
+void
+mg_set_user_connection_data(struct mg_connection *conn, void *data)
+{
+	if (conn != NULL) {
+		conn->request_info.conn_data = data;
+	}
+}
+
+
+void *
+mg_get_user_connection_data(const struct mg_connection *conn)
+{
+	if (conn != NULL) {
+		return conn->request_info.conn_data;
+	}
+	return NULL;
+}
+
+
+size_t
+mg_get_ports(const struct mg_context *ctx, size_t size, int *ports, int *ssl)
+{
+	size_t i;
+	if (!ctx) {
+		return 0;
+	}
+	for (i = 0; i < size && i < ctx->num_listening_sockets; i++) {
+		ssl[i] = ctx->listening_sockets[i].is_ssl;
+		ports[i] =
+#if defined(USE_IPV6)
+		    (ctx->listening_sockets[i].lsa.sa.sa_family == AF_INET6)
+		        ? ntohs(ctx->listening_sockets[i].lsa.sin6.sin6_port)
+		        :
+#endif
+		        ntohs(ctx->listening_sockets[i].lsa.sin.sin_port);
+	}
+	return i;
+}
+
+
+int
+mg_get_server_ports(const struct mg_context *ctx,
+                    int size,
+                    struct mg_server_ports *ports)
+{
+	int i, cnt = 0;
+
+	if (size <= 0) {
+		return -1;
+	}
+	memset(ports, 0, sizeof(*ports) * (size_t)size);
+	if (!ctx) {
+		return -1;
+	}
+	if (!ctx->listening_sockets) {
+		return -1;
+	}
+
+	for (i = 0; (i < size) && (i < (int)ctx->num_listening_sockets); i++) {
+
+		ports[cnt].port =
+#if defined(USE_IPV6)
+		    (ctx->listening_sockets[i].lsa.sa.sa_family == AF_INET6)
+		        ? ntohs(ctx->listening_sockets[i].lsa.sin6.sin6_port)
+		        :
+#endif
+		        ntohs(ctx->listening_sockets[i].lsa.sin.sin_port);
+		ports[cnt].is_ssl = ctx->listening_sockets[i].is_ssl;
+		ports[cnt].is_redirect = ctx->listening_sockets[i].ssl_redir;
+
+		if (ctx->listening_sockets[i].lsa.sa.sa_family == AF_INET) {
+			/* IPv4 */
+			ports[cnt].protocol = 1;
+			cnt++;
+		} else if (ctx->listening_sockets[i].lsa.sa.sa_family == AF_INET6) {
+			/* IPv6 */
+			ports[cnt].protocol = 3;
+			cnt++;
+		}
+	}
+
+	return cnt;
+}
+
+
+static void
+sockaddr_to_string(char *buf, size_t len, const union usa *usa)
+{
+	buf[0] = '\0';
+
+	if (!usa) {
+		return;
+	}
+
+	if (usa->sa.sa_family == AF_INET) {
+		getnameinfo(&usa->sa,
+		            sizeof(usa->sin),
+		            buf,
+		            (unsigned)len,
+		            NULL,
+		            0,
+		            NI_NUMERICHOST);
+	}
+#if defined(USE_IPV6)
+	else if (usa->sa.sa_family == AF_INET6) {
+		getnameinfo(&usa->sa,
+		            sizeof(usa->sin6),
+		            buf,
+		            (unsigned)len,
+		            NULL,
+		            0,
+		            NI_NUMERICHOST);
+	}
+#endif
+}
+
+
+/* Convert time_t to a string. According to RFC2616, Sec 14.18, this must be
+ * included in all responses other than 100, 101, 5xx. */
+static void
+gmt_time_string(char *buf, size_t buf_len, time_t *t)
+{
+	struct tm *tm;
+
+	tm = ((t != NULL) ? gmtime(t) : NULL);
+	if (tm != NULL) {
+		strftime(buf, buf_len, "%a, %d %b %Y %H:%M:%S GMT", tm);
+	} else {
+		mg_strlcpy(buf, "Thu, 01 Jan 1970 00:00:00 GMT", buf_len);
+		buf[buf_len - 1] = '\0';
+	}
+}
+
+
+/* difftime for struct timespec. Return value is in seconds. */
+static double
+mg_difftimespec(const struct timespec *ts_now, const struct timespec *ts_before)
+{
+	return (double)(ts_now->tv_nsec - ts_before->tv_nsec) * 1.0E-9
+	       + (double)(ts_now->tv_sec - ts_before->tv_sec);
+}
+
+
+/* Print error message to the opened error log stream. */
+void
+mg_cry(const struct mg_connection *conn, const char *fmt, ...)
+{
+	char buf[MG_BUF_LEN], src_addr[IP_ADDR_STR_LEN];
+	va_list ap;
+	struct mg_file fi;
+	time_t timestamp;
+
+	va_start(ap, fmt);
+	IGNORE_UNUSED_RESULT(vsnprintf_impl(buf, sizeof(buf), fmt, ap));
+	va_end(ap);
+	buf[sizeof(buf) - 1] = 0;
+
+	if (!conn) {
+		puts(buf);
+		return;
+	}
+
+	/* Do not lock when getting the callback value, here and below.
+	 * I suppose this is fine, since function cannot disappear in the
+	 * same way string option can. */
+	if ((conn->ctx->callbacks.log_message == NULL)
+	    || (conn->ctx->callbacks.log_message(conn, buf) == 0)) {
+
+		if (conn->ctx->config[ERROR_LOG_FILE] != NULL) {
+			if (mg_fopen(conn,
+			             conn->ctx->config[ERROR_LOG_FILE],
+			             MG_FOPEN_MODE_APPEND,
+			             &fi) == 0) {
+				fi.access.fp = NULL;
+			}
+		} else {
+			fi.access.fp = NULL;
+		}
+
+		if (fi.access.fp != NULL) {
+			flockfile(fi.access.fp);
+			timestamp = time(NULL);
+
+			sockaddr_to_string(src_addr, sizeof(src_addr), &conn->client.rsa);
+			fprintf(fi.access.fp,
+			        "[%010lu] [error] [client %s] ",
+			        (unsigned long)timestamp,
+			        src_addr);
+
+			if (conn->request_info.request_method != NULL) {
+				fprintf(fi.access.fp,
+				        "%s %s: ",
+				        conn->request_info.request_method,
+				        conn->request_info.request_uri);
+			}
+
+			fprintf(fi.access.fp, "%s", buf);
+			fputc('\n', fi.access.fp);
+			fflush(fi.access.fp);
+			funlockfile(fi.access.fp);
+			(void)mg_fclose(&fi.access); /* Ignore errors. We can't call
+			                              * mg_cry here anyway ;-) */
+		}
+	}
+}
+
+
+/* Return fake connection structure. Used for logging, if connection
+ * is not applicable at the moment of logging. */
+static struct mg_connection *
+fc(struct mg_context *ctx)
+{
+	static struct mg_connection fake_connection;
+	fake_connection.ctx = ctx;
+	return &fake_connection;
+}
+
+
+const char *
+mg_version(void)
+{
+	return CIVETWEB_VERSION;
+}
+
+
+const struct mg_request_info *
+mg_get_request_info(const struct mg_connection *conn)
+{
+	if (!conn) {
+		return NULL;
+	}
+	return &conn->request_info;
+}
+
+
+/* Skip the characters until one of the delimiters characters found.
+ * 0-terminate resulting word. Skip the delimiter and following whitespaces.
+ * Advance pointer to buffer to the next word. Return found 0-terminated word.
+ * Delimiters can be quoted with quotechar. */
+static char *
+skip_quoted(char **buf,
+            const char *delimiters,
+            const char *whitespace,
+            char quotechar)
+{
+	char *p, *begin_word, *end_word, *end_whitespace;
+
+	begin_word = *buf;
+	end_word = begin_word + strcspn(begin_word, delimiters);
+
+	/* Check for quotechar */
+	if (end_word > begin_word) {
+		p = end_word - 1;
+		while (*p == quotechar) {
+			/* While the delimiter is quoted, look for the next delimiter. */
+			/* This happens, e.g., in calls from parse_auth_header,
+			 * if the user name contains a " character. */
+
+			/* If there is anything beyond end_word, copy it. */
+			if (*end_word != '\0') {
+				size_t end_off = strcspn(end_word + 1, delimiters);
+				memmove(p, end_word, end_off + 1);
+				p += end_off; /* p must correspond to end_word - 1 */
+				end_word += end_off + 1;
+			} else {
+				*p = '\0';
+				break;
+			}
+		}
+		for (p++; p < end_word; p++) {
+			*p = '\0';
+		}
+	}
+
+	if (*end_word == '\0') {
+		*buf = end_word;
+	} else {
+
+#if defined(__GNUC__) || defined(__MINGW32__)
+/* Disable spurious conversion warning for GCC */
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wsign-conversion"
+#endif
+
+		end_whitespace = end_word + strspn(&end_word[1], whitespace) + 1;
+
+#if defined(__GNUC__) || defined(__MINGW32__)
+#pragma GCC diagnostic pop
+#endif
+
+		for (p = end_word; p < end_whitespace; p++) {
+			*p = '\0';
+		}
+
+		*buf = end_whitespace;
+	}
+
+	return begin_word;
+}
+
+
+/* Simplified version of skip_quoted without quote char
+ * and whitespace == delimiters */
+static char *
+skip(char **buf, const char *delimiters)
+{
+	return skip_quoted(buf, delimiters, delimiters, 0);
+}
+
+
+/* Return HTTP header value, or NULL if not found. */
+static const char *
+get_header(const struct mg_request_info *ri, const char *name)
+{
+	int i;
+	if (ri) {
+		for (i = 0; i < ri->num_headers; i++) {
+			if (!mg_strcasecmp(name, ri->http_headers[i].name)) {
+				return ri->http_headers[i].value;
+			}
+		}
+	}
+
+	return NULL;
+}
+
+
+const char *
+mg_get_header(const struct mg_connection *conn, const char *name)
+{
+	if (!conn) {
+		return NULL;
+	}
+
+	return get_header(&conn->request_info, name);
+}
+
+
+/* A helper function for traversing a comma separated list of values.
+ * It returns a list pointer shifted to the next value, or NULL if the end
+ * of the list found.
+ * Value is stored in val vector. If value has form "x=y", then eq_val
+ * vector is initialized to point to the "y" part, and val vector length
+ * is adjusted to point only to "x". */
+static const char *
+next_option(const char *list, struct vec *val, struct vec *eq_val)
+{
+	int end;
+
+reparse:
+	if (val == NULL || list == NULL || *list == '\0') {
+		/* End of the list */
+		list = NULL;
+	} else {
+		/* Skip over leading LWS */
+		while (*list == ' ' || *list == '\t')
+			list++;
+
+		val->ptr = list;
+		if ((list = strchr(val->ptr, ',')) != NULL) {
+			/* Comma found. Store length and shift the list ptr */
+			val->len = ((size_t)(list - val->ptr));
+			list++;
+		} else {
+			/* This value is the last one */
+			list = val->ptr + strlen(val->ptr);
+			val->len = ((size_t)(list - val->ptr));
+		}
+
+		/* Adjust length for trailing LWS */
+		end = (int)val->len - 1;
+		while (end >= 0 && (val->ptr[end] == ' ' || val->ptr[end] == '\t'))
+			end--;
+		val->len = (size_t)(end + 1);
+
+		if (val->len == 0) {
+			/* Ignore any empty entries. */
+			goto reparse;
+		}
+
+		if (eq_val != NULL) {
+			/* Value has form "x=y", adjust pointers and lengths
+			 * so that val points to "x", and eq_val points to "y". */
+			eq_val->len = 0;
+			eq_val->ptr = (const char *)memchr(val->ptr, '=', val->len);
+			if (eq_val->ptr != NULL) {
+				eq_val->ptr++; /* Skip over '=' character */
+				eq_val->len = ((size_t)(val->ptr - eq_val->ptr)) + val->len;
+				val->len = ((size_t)(eq_val->ptr - val->ptr)) - 1;
+			}
+		}
+	}
+
+	return list;
+}
+
+/* A helper function for checking if a comma separated list of values contains
+ * the given option (case insensitvely).
+ * 'header' can be NULL, in which case false is returned. */
+static int
+header_has_option(const char *header, const char *option)
+{
+	struct vec opt_vec;
+	struct vec eq_vec;
+
+	assert(option != NULL);
+	assert(option[0] != '\0');
+
+	while ((header = next_option(header, &opt_vec, &eq_vec)) != NULL) {
+		if (mg_strncasecmp(option, opt_vec.ptr, opt_vec.len) == 0)
+			return 1;
+	}
+
+	return 0;
+}
+
+/* Perform case-insensitive match of string against pattern */
+static int
+match_prefix(const char *pattern, size_t pattern_len, const char *str)
+{
+	const char *or_str;
+	size_t i;
+	int j, len, res;
+
+	if ((or_str = (const char *)memchr(pattern, '|', pattern_len)) != NULL) {
+		res = match_prefix(pattern, (size_t)(or_str - pattern), str);
+		return (res > 0) ? res : match_prefix(or_str + 1,
+		                                      (size_t)((pattern + pattern_len)
+		                                               - (or_str + 1)),
+		                                      str);
+	}
+
+	for (i = 0, j = 0; i < pattern_len; i++, j++) {
+		if (pattern[i] == '?' && str[j] != '\0') {
+			continue;
+		} else if (pattern[i] == '$') {
+			return (str[j] == '\0') ? j : -1;
+		} else if (pattern[i] == '*') {
+			i++;
+			if (pattern[i] == '*') {
+				i++;
+				len = (int)strlen(str + j);
+			} else {
+				len = (int)strcspn(str + j, "/");
+			}
+			if (i == pattern_len) {
+				return j + len;
+			}
+			do {
+				res = match_prefix(pattern + i, pattern_len - i, str + j + len);
+			} while (res == -1 && len-- > 0);
+			return (res == -1) ? -1 : j + res + len;
+		} else if (lowercase(&pattern[i]) != lowercase(&str[j])) {
+			return -1;
+		}
+	}
+	return j;
+}
+
+
+/* HTTP 1.1 assumes keep alive if "Connection:" header is not set
+ * This function must tolerate situations when connection info is not
+ * set up, for example if request parsing failed. */
+static int
+should_keep_alive(const struct mg_connection *conn)
+{
+	if (conn != NULL) {
+		const char *http_version = conn->request_info.http_version;
+		const char *header = mg_get_header(conn, "Connection");
+		if (conn->must_close || conn->status_code == 401
+		    || mg_strcasecmp(conn->ctx->config[ENABLE_KEEP_ALIVE], "yes") != 0
+		    || (header != NULL && !header_has_option(header, "keep-alive"))
+		    || (header == NULL && http_version
+		        && 0 != strcmp(http_version, "1.1"))) {
+			return 0;
+		}
+		return 1;
+	}
+	return 0;
+}
+
+
+static int
+should_decode_url(const struct mg_connection *conn)
+{
+	if (!conn || !conn->ctx) {
+		return 0;
+	}
+
+	return (mg_strcasecmp(conn->ctx->config[DECODE_URL], "yes") == 0);
+}
+
+
+static const char *
+suggest_connection_header(const struct mg_connection *conn)
+{
+	return should_keep_alive(conn) ? "keep-alive" : "close";
+}
+
+
+static int
+send_no_cache_header(struct mg_connection *conn)
+{
+	/* Send all current and obsolete cache opt-out directives. */
+	return mg_printf(conn,
+	                 "Cache-Control: no-cache, no-store, "
+	                 "must-revalidate, private, max-age=0\r\n"
+	                 "Pragma: no-cache\r\n"
+	                 "Expires: 0\r\n");
+}
+
+
+static int
+send_static_cache_header(struct mg_connection *conn)
+{
+#if !defined(NO_CACHING)
+	/* Read the server config to check how long a file may be cached.
+	 * The configuration is in seconds. */
+	int max_age = atoi(conn->ctx->config[STATIC_FILE_MAX_AGE]);
+	if (max_age <= 0) {
+		/* 0 means "do not cache". All values <0 are reserved
+		 * and may be used differently in the future. */
+		/* If a file should not be cached, do not only send
+		 * max-age=0, but also pragmas and Expires headers. */
+		return send_no_cache_header(conn);
+	}
+
+	/* Use "Cache-Control: max-age" instead of "Expires" header.
+	 * Reason: see https://www.mnot.net/blog/2007/05/15/expires_max-age */
+	/* See also https://www.mnot.net/cache_docs/ */
+	/* According to RFC 2616, Section 14.21, caching times should not exceed
+	 * one year. A year with 365 days corresponds to 31536000 seconds, a leap
+	 * year to 31622400 seconds. For the moment, we just send whatever has
+	 * been configured, still the behavior for >1 year should be considered
+	 * as undefined. */
+	return mg_printf(conn, "Cache-Control: max-age=%u\r\n", (unsigned)max_age);
+#else  /* NO_CACHING */
+	return send_no_cache_header(conn);
+#endif /* !NO_CACHING */
+}
+
+
+static void handle_file_based_request(struct mg_connection *conn,
+                                      const char *path,
+                                      struct mg_file *filep);
+
+
+const char *
+mg_get_response_code_text(struct mg_connection *conn, int response_code)
+{
+	/* See IANA HTTP status code assignment:
+	 * http://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
+	 */
+
+	switch (response_code) {
+	/* RFC2616 Section 10.1 - Informational 1xx */
+	case 100:
+		return "Continue"; /* RFC2616 Section 10.1.1 */
+	case 101:
+		return "Switching Protocols"; /* RFC2616 Section 10.1.2 */
+	case 102:
+		return "Processing"; /* RFC2518 Section 10.1 */
+
+	/* RFC2616 Section 10.2 - Successful 2xx */
+	case 200:
+		return "OK"; /* RFC2616 Section 10.2.1 */
+	case 201:
+		return "Created"; /* RFC2616 Section 10.2.2 */
+	case 202:
+		return "Accepted"; /* RFC2616 Section 10.2.3 */
+	case 203:
+		return "Non-Authoritative Information"; /* RFC2616 Section 10.2.4 */
+	case 204:
+		return "No Content"; /* RFC2616 Section 10.2.5 */
+	case 205:
+		return "Reset Content"; /* RFC2616 Section 10.2.6 */
+	case 206:
+		return "Partial Content"; /* RFC2616 Section 10.2.7 */
+	case 207:
+		return "Multi-Status"; /* RFC2518 Section 10.2, RFC4918 Section 11.1 */
+	case 208:
+		return "Already Reported"; /* RFC5842 Section 7.1 */
+
+	case 226:
+		return "IM used"; /* RFC3229 Section 10.4.1 */
+
+	/* RFC2616 Section 10.3 - Redirection 3xx */
+	case 300:
+		return "Multiple Choices"; /* RFC2616 Section 10.3.1 */
+	case 301:
+		return "Moved Permanently"; /* RFC2616 Section 10.3.2 */
+	case 302:
+		return "Found"; /* RFC2616 Section 10.3.3 */
+	case 303:
+		return "See Other"; /* RFC2616 Section 10.3.4 */
+	case 304:
+		return "Not Modified"; /* RFC2616 Section 10.3.5 */
+	case 305:
+		return "Use Proxy"; /* RFC2616 Section 10.3.6 */
+	case 307:
+		return "Temporary Redirect"; /* RFC2616 Section 10.3.8 */
+	case 308:
+		return "Permanent Redirect"; /* RFC7238 Section 3 */
+
+	/* RFC2616 Section 10.4 - Client Error 4xx */
+	case 400:
+		return "Bad Request"; /* RFC2616 Section 10.4.1 */
+	case 401:
+		return "Unauthorized"; /* RFC2616 Section 10.4.2 */
+	case 402:
+		return "Payment Required"; /* RFC2616 Section 10.4.3 */
+	case 403:
+		return "Forbidden"; /* RFC2616 Section 10.4.4 */
+	case 404:
+		return "Not Found"; /* RFC2616 Section 10.4.5 */
+	case 405:
+		return "Method Not Allowed"; /* RFC2616 Section 10.4.6 */
+	case 406:
+		return "Not Acceptable"; /* RFC2616 Section 10.4.7 */
+	case 407:
+		return "Proxy Authentication Required"; /* RFC2616 Section 10.4.8 */
+	case 408:
+		return "Request Time-out"; /* RFC2616 Section 10.4.9 */
+	case 409:
+		return "Conflict"; /* RFC2616 Section 10.4.10 */
+	case 410:
+		return "Gone"; /* RFC2616 Section 10.4.11 */
+	case 411:
+		return "Length Required"; /* RFC2616 Section 10.4.12 */
+	case 412:
+		return "Precondition Failed"; /* RFC2616 Section 10.4.13 */
+	case 413:
+		return "Request Entity Too Large"; /* RFC2616 Section 10.4.14 */
+	case 414:
+		return "Request-URI Too Large"; /* RFC2616 Section 10.4.15 */
+	case 415:
+		return "Unsupported Media Type"; /* RFC2616 Section 10.4.16 */
+	case 416:
+		return "Requested range not satisfiable"; /* RFC2616 Section 10.4.17 */
+	case 417:
+		return "Expectation Failed"; /* RFC2616 Section 10.4.18 */
+
+	case 421:
+		return "Misdirected Request"; /* RFC7540 Section 9.1.2 */
+	case 422:
+		return "Unproccessable entity"; /* RFC2518 Section 10.3, RFC4918
+		                                 * Sect

<TRUNCATED>

[23/51] [partial] nifi-minifi-cpp git commit: MINIFI-183 Added civet 1.9.1 sources Added onScheduled hook Added initial two-way TLS-enabled ListenHTTP implementation

Posted by al...@apache.org.
http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/license.spdx
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/license.spdx b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/license.spdx
new file mode 100644
index 0000000..29a6b8d
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/license.spdx
@@ -0,0 +1,3933 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<rdf:RDF
+   xmlns:_3="http://spdx.org/rdf/terms#"
+   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+   xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
+>
+  <rdf:Description rdf:nodeID="svBMzJkP376">
+    <_3:algorithm rdf:resource="http://spdx.org/rdf/terms#checksumAlgorithm_sha1"/>
+    <_3:checksumValue>6f9134b7d1c939593043b9e0ecb308fbc745c9af</_3:checksumValue>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#Checksum"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP101">
+    <_3:licenseConcluded rdf:resource="http://spdx.org/licenses/MIT"/>
+    <_3:licenseInfoInFile rdf:resource="http://spdx.org/rdf/terms#none"/>
+    <_3:copyrightText>Copyright 2013-2016 Duktape authors (see AUTHORS.rst in the Duktape distributable)</_3:copyrightText>
+    <_3:checksum rdf:nodeID="svBMzJkP102"/>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#File"/>
+    <_3:fileName>./examples/eventloop/main.c</_3:fileName>
+    <_3:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_source"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP414">
+    <_3:algorithm rdf:resource="http://spdx.org/rdf/terms#checksumAlgorithm_sha1"/>
+    <_3:checksumValue>bd2f85dccd23b76b9cf9900b8b2b86f0bf97421b</_3:checksumValue>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#Checksum"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP415">
+    <_3:licenseConcluded rdf:resource="http://spdx.org/licenses/MIT"/>
+    <_3:licenseInfoInFile rdf:resource="http://spdx.org/rdf/terms#none"/>
+    <_3:copyrightText>Copyright 2013-2016 Duktape authors (see AUTHORS.rst in the Duktape distributable)</_3:copyrightText>
+    <_3:checksum rdf:nodeID="svBMzJkP416"/>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#File"/>
+    <_3:fileName>./src-separate/duk_initjs_min.js</_3:fileName>
+    <_3:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_source"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP321">
+    <_3:licenseConcluded rdf:resource="http://spdx.org/licenses/MIT"/>
+    <_3:licenseInfoInFile rdf:resource="http://spdx.org/rdf/terms#none"/>
+    <_3:copyrightText>Copyright 2013-2016 Duktape authors (see AUTHORS.rst in the Duktape distributable)</_3:copyrightText>
+    <_3:checksum rdf:nodeID="svBMzJkP322"/>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#File"/>
+    <_3:fileName>./src-separate/duk_internal.h</_3:fileName>
+    <_3:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_source"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP292">
+    <_3:algorithm rdf:resource="http://spdx.org/rdf/terms#checksumAlgorithm_sha1"/>
+    <_3:checksumValue>b7ee0e88e6365390db594e5e1a90c383847cfd0f</_3:checksumValue>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#Checksum"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP3">
+    <_3:created rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime">2016-12-08T20:32:53Z</_3:created>
+    <rdfs:comment></rdfs:comment>
+    <_3:licenseListVersion>1.20</_3:licenseListVersion>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#CreationInfo"/>
+    <_3:creator>Organization: duktape.org</_3:creator>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP79">
+    <_3:licenseConcluded rdf:resource="http://spdx.org/licenses/MIT"/>
+    <_3:licenseInfoInFile rdf:resource="http://spdx.org/rdf/terms#none"/>
+    <_3:copyrightText>Copyright 2013-2016 Duktape authors (see AUTHORS.rst in the Duktape distributable)</_3:copyrightText>
+    <_3:checksum rdf:nodeID="svBMzJkP80"/>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#File"/>
+    <_3:fileName>./examples/coffee/README.rst</_3:fileName>
+    <_3:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_other"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP275">
+    <_3:licenseConcluded rdf:resource="http://spdx.org/licenses/MIT"/>
+    <_3:licenseInfoInFile rdf:resource="http://spdx.org/rdf/terms#none"/>
+    <_3:copyrightText>Copyright 2013-2016 Duktape authors (see AUTHORS.rst in the Duktape distributable)</_3:copyrightText>
+    <_3:checksum rdf:nodeID="svBMzJkP276"/>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#File"/>
+    <_3:fileName>./src-separate/duk_heap_stringtable.c</_3:fileName>
+    <_3:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_source"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP360">
+    <_3:algorithm rdf:resource="http://spdx.org/rdf/terms#checksumAlgorithm_sha1"/>
+    <_3:checksumValue>d70b4083ccd3b5dac32ad07e58d3132dc3390b79</_3:checksumValue>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#Checksum"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP70">
+    <_3:algorithm rdf:resource="http://spdx.org/rdf/terms#checksumAlgorithm_sha1"/>
+    <_3:checksumValue>f051b42ff42dc8655b9e17739f7cb7cb76bdf78d</_3:checksumValue>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#Checksum"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP382">
+    <_3:algorithm rdf:resource="http://spdx.org/rdf/terms#checksumAlgorithm_sha1"/>
+    <_3:checksumValue>61db5ef1604240b33fa9e1e8825ad588076a5aef</_3:checksumValue>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#Checksum"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP365">
+    <_3:licenseConcluded rdf:resource="http://spdx.org/licenses/MIT"/>
+    <_3:licenseInfoInFile rdf:resource="http://spdx.org/rdf/terms#none"/>
+    <_3:copyrightText>Copyright 2013-2016 Duktape authors (see AUTHORS.rst in the Duktape distributable)</_3:copyrightText>
+    <_3:checksum rdf:nodeID="svBMzJkP366"/>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#File"/>
+    <_3:fileName>./src-separate/duk_debug.h</_3:fileName>
+    <_3:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_source"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP208">
+    <_3:algorithm rdf:resource="http://spdx.org/rdf/terms#checksumAlgorithm_sha1"/>
+    <_3:checksumValue>52554f56c3e3420d3643aa22f563d32a2b18be1f</_3:checksumValue>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#Checksum"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP323">
+    <_3:licenseConcluded rdf:resource="http://spdx.org/licenses/MIT"/>
+    <_3:licenseInfoInFile rdf:resource="http://spdx.org/rdf/terms#none"/>
+    <_3:copyrightText>Copyright 2013-2016 Duktape authors (see AUTHORS.rst in the Duktape distributable)</_3:copyrightText>
+    <_3:checksum rdf:nodeID="svBMzJkP324"/>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#File"/>
+    <_3:fileName>./src-separate/duk_hbufferobject_misc.c</_3:fileName>
+    <_3:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_source"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP441">
+    <_3:licenseConcluded rdf:resource="http://spdx.org/licenses/MIT"/>
+    <_3:licenseInfoInFile rdf:resource="http://spdx.org/rdf/terms#none"/>
+    <_3:copyrightText>Copyright 2013-2016 Duktape authors (see AUTHORS.rst in the Duktape distributable)</_3:copyrightText>
+    <_3:checksum rdf:nodeID="svBMzJkP442"/>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#File"/>
+    <_3:fileName>./src-separate/duk_debug_fixedbuffer.c</_3:fileName>
+    <_3:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_source"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP32">
+    <_3:algorithm rdf:resource="http://spdx.org/rdf/terms#checksumAlgorithm_sha1"/>
+    <_3:checksumValue>fb4f806e7282dd3cb2df04e228672d8b0b1b8eb4</_3:checksumValue>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#Checksum"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP289">
+    <_3:licenseConcluded rdf:resource="http://spdx.org/licenses/MIT"/>
+    <_3:licenseInfoInFile rdf:resource="http://spdx.org/rdf/terms#none"/>
+    <_3:copyrightText>Copyright 2013-2016 Duktape authors (see AUTHORS.rst in the Duktape distributable)</_3:copyrightText>
+    <_3:checksum rdf:nodeID="svBMzJkP290"/>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#File"/>
+    <_3:fileName>./src-separate/duk_heap_misc.c</_3:fileName>
+    <_3:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_source"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP383">
+    <_3:licenseConcluded rdf:resource="http://spdx.org/licenses/MIT"/>
+    <_3:licenseInfoInFile rdf:resource="http://spdx.org/rdf/terms#none"/>
+    <_3:copyrightText>Copyright 2013-2016 Duktape authors (see AUTHORS.rst in the Duktape distributable)</_3:copyrightText>
+    <_3:checksum rdf:nodeID="svBMzJkP384"/>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#File"/>
+    <_3:fileName>./src-separate/duk_api_compile.c</_3:fileName>
+    <_3:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_source"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP468">
+    <_3:algorithm rdf:resource="http://spdx.org/rdf/terms#checksumAlgorithm_sha1"/>
+    <_3:checksumValue>422984e8fc919e9f8c64d5cc4b20d7f6d15e341b</_3:checksumValue>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#Checksum"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP277">
+    <_3:licenseConcluded rdf:resource="http://spdx.org/licenses/MIT"/>
+    <_3:licenseInfoInFile rdf:resource="http://spdx.org/rdf/terms#none"/>
+    <_3:copyrightText>Copyright 2013-2016 Duktape authors (see AUTHORS.rst in the Duktape distributable)</_3:copyrightText>
+    <_3:checksum rdf:nodeID="svBMzJkP278"/>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#File"/>
+    <_3:fileName>./src-separate/duk_error_longjmp.c</_3:fileName>
+    <_3:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_source"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP258">
+    <_3:algorithm rdf:resource="http://spdx.org/rdf/terms#checksumAlgorithm_sha1"/>
+    <_3:checksumValue>d0421b2e96d2365467764d4aecc442fe543d69ad</_3:checksumValue>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#Checksum"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP462">
+    <_3:algorithm rdf:resource="http://spdx.org/rdf/terms#checksumAlgorithm_sha1"/>
+    <_3:checksumValue>1db75c875cb94e1317f095e3d78f11275c17d154</_3:checksumValue>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#Checksum"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP137">
+    <_3:licenseConcluded rdf:resource="http://spdx.org/licenses/MIT"/>
+    <_3:licenseInfoInFile rdf:resource="http://spdx.org/rdf/terms#none"/>
+    <_3:copyrightText>Copyright 2013-2016 Duktape authors (see AUTHORS.rst in the Duktape distributable)</_3:copyrightText>
+    <_3:checksum rdf:nodeID="svBMzJkP138"/>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#File"/>
+    <_3:fileName>./examples/cpp-exceptions/cpp_exceptions.cpp</_3:fileName>
+    <_3:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_other"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP180">
+    <_3:algorithm rdf:resource="http://spdx.org/rdf/terms#checksumAlgorithm_sha1"/>
+    <_3:checksumValue>23575db7cd88e42c0c3fc1630f44bf608fcec76d</_3:checksumValue>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#Checksum"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP271">
+    <_3:licenseConcluded rdf:resource="http://spdx.org/licenses/MIT"/>
+    <_3:licenseInfoInFile rdf:resource="http://spdx.org/rdf/terms#none"/>
+    <_3:copyrightText>Copyright 2013-2016 Duktape authors (see AUTHORS.rst in the Duktape distributable)</_3:copyrightText>
+    <_3:checksum rdf:nodeID="svBMzJkP272"/>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#File"/>
+    <_3:fileName>./src-separate/duk_builtins.c</_3:fileName>
+    <_3:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_source"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP417">
+    <_3:licenseConcluded rdf:resource="http://spdx.org/licenses/MIT"/>
+    <_3:licenseInfoInFile rdf:resource="http://spdx.org/rdf/terms#none"/>
+    <_3:copyrightText>Copyright 2013-2016 Duktape authors (see AUTHORS.rst in the Duktape distributable)</_3:copyrightText>
+    <_3:checksum rdf:nodeID="svBMzJkP418"/>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#File"/>
+    <_3:fileName>./src-separate/duk_api_string.c</_3:fileName>
+    <_3:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_source"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP331">
+    <_3:licenseConcluded rdf:resource="http://spdx.org/licenses/MIT"/>
+    <_3:licenseInfoInFile rdf:resource="http://spdx.org/rdf/terms#none"/>
+    <_3:copyrightText>Copyright 2013-2016 Duktape authors (see AUTHORS.rst in the Duktape distributable)</_3:copyrightText>
+    <_3:checksum rdf:nodeID="svBMzJkP332"/>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#File"/>
+    <_3:fileName>./src-separate/duk_lexer.h</_3:fileName>
+    <_3:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_source"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP327">
+    <_3:licenseConcluded rdf:resource="http://spdx.org/licenses/MIT"/>
+    <_3:licenseInfoInFile rdf:resource="http://spdx.org/rdf/terms#none"/>
+    <_3:copyrightText>Copyright 2013-2016 Duktape authors (see AUTHORS.rst in the Duktape distributable)</_3:copyrightText>
+    <_3:checksum rdf:nodeID="svBMzJkP328"/>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#File"/>
+    <_3:fileName>./src-separate/duk_bi_buffer.c</_3:fileName>
+    <_3:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_source"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP476">
+    <_3:algorithm rdf:resource="http://spdx.org/rdf/terms#checksumAlgorithm_sha1"/>
+    <_3:checksumValue>97bf0ab32255874def0bd3157bf4bb2fc731d37f</_3:checksumValue>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#Checksum"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP147">
+    <_3:licenseConcluded rdf:resource="http://spdx.org/licenses/MIT"/>
+    <_3:licenseInfoInFile rdf:resource="http://spdx.org/rdf/terms#none"/>
+    <_3:copyrightText>Copyright 2013-2016 Duktape authors (see AUTHORS.rst in the Duktape distributable)</_3:copyrightText>
+    <_3:checksum rdf:nodeID="svBMzJkP148"/>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#File"/>
+    <_3:fileName>./examples/guide/process.js</_3:fileName>
+    <_3:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_source"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP388">
+    <_3:algorithm rdf:resource="http://spdx.org/rdf/terms#checksumAlgorithm_sha1"/>
+    <_3:checksumValue>0811e545a133c3a62672e239624a0c1f11478b8d</_3:checksumValue>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#Checksum"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP214">
+    <_3:algorithm rdf:resource="http://spdx.org/rdf/terms#checksumAlgorithm_sha1"/>
+    <_3:checksumValue>742d035afe3ae16b3498926494419b74c53dfaf4</_3:checksumValue>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#Checksum"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP312">
+    <_3:algorithm rdf:resource="http://spdx.org/rdf/terms#checksumAlgorithm_sha1"/>
+    <_3:checksumValue>34b0dc439c1aeb920a1db0ac0ed20ee189069ea1</_3:checksumValue>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#Checksum"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP439">
+    <_3:licenseConcluded rdf:resource="http://spdx.org/licenses/MIT"/>
+    <_3:licenseInfoInFile rdf:resource="http://spdx.org/rdf/terms#none"/>
+    <_3:copyrightText>Copyright 2013-2016 Duktape authors (see AUTHORS.rst in the Duktape distributable)</_3:copyrightText>
+    <_3:checksum rdf:nodeID="svBMzJkP440"/>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#File"/>
+    <_3:fileName>./src-separate/duk_debug_heap.c</_3:fileName>
+    <_3:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_source"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP209">
+    <_3:licenseConcluded rdf:resource="http://spdx.org/licenses/MIT"/>
+    <_3:licenseInfoInFile rdf:resource="http://spdx.org/rdf/terms#none"/>
+    <_3:copyrightText>Copyright 2013-2016 Duktape authors (see AUTHORS.rst in the Duktape distributable)</_3:copyrightText>
+    <_3:checksum rdf:nodeID="svBMzJkP210"/>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#File"/>
+    <_3:fileName>./src-separate/duk_util_bufwriter.c</_3:fileName>
+    <_3:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_source"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP31">
+    <_3:licenseConcluded rdf:resource="http://spdx.org/licenses/MIT"/>
+    <_3:licenseInfoInFile rdf:resource="http://spdx.org/rdf/terms#none"/>
+    <_3:copyrightText>Copyright 2013-2016 Duktape authors (see AUTHORS.rst in the Duktape distributable)</_3:copyrightText>
+    <_3:checksum rdf:nodeID="svBMzJkP32"/>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#File"/>
+    <_3:fileName>./Makefile.eval</_3:fileName>
+    <_3:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_other"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP408">
+    <_3:algorithm rdf:resource="http://spdx.org/rdf/terms#checksumAlgorithm_sha1"/>
+    <_3:checksumValue>221600498f2801d0bfc71e36009f084f363e159e</_3:checksumValue>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#Checksum"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP443">
+    <_3:licenseConcluded rdf:resource="http://spdx.org/licenses/MIT"/>
+    <_3:licenseInfoInFile rdf:resource="http://spdx.org/rdf/terms#none"/>
+    <_3:copyrightText>Copyright 2013-2016 Duktape authors (see AUTHORS.rst in the Duktape distributable)</_3:copyrightText>
+    <_3:checksum rdf:nodeID="svBMzJkP444"/>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#File"/>
+    <_3:fileName>./src-separate/duk_alloc_default.c</_3:fileName>
+    <_3:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_source"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP374">
+    <_3:algorithm rdf:resource="http://spdx.org/rdf/terms#checksumAlgorithm_sha1"/>
+    <_3:checksumValue>bad7c737fdd2d5f21ac00c6936921184cd26908d</_3:checksumValue>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#Checksum"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP246">
+    <_3:algorithm rdf:resource="http://spdx.org/rdf/terms#checksumAlgorithm_sha1"/>
+    <_3:checksumValue>21e33f2c348ab084c0869d3bba530b1885464f38</_3:checksumValue>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#Checksum"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP69">
+    <_3:licenseConcluded rdf:resource="http://spdx.org/licenses/MIT"/>
+    <_3:licenseInfoInFile rdf:resource="http://spdx.org/rdf/terms#none"/>
+    <_3:copyrightText>Copyright 2013-2016 Duktape authors (see AUTHORS.rst in the Duktape distributable)</_3:copyrightText>
+    <_3:checksum rdf:nodeID="svBMzJkP70"/>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#File"/>
+    <_3:fileName>./debugger/static/webui.js</_3:fileName>
+    <_3:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_source"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP349">
+    <_3:licenseConcluded rdf:resource="http://spdx.org/licenses/MIT"/>
+    <_3:licenseInfoInFile rdf:resource="http://spdx.org/rdf/terms#none"/>
+    <_3:copyrightText>Copyright 2013-2016 Duktape authors (see AUTHORS.rst in the Duktape distributable)</_3:copyrightText>
+    <_3:checksum rdf:nodeID="svBMzJkP350"/>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#File"/>
+    <_3:fileName>./src-separate/duk_api_object.c</_3:fileName>
+    <_3:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_source"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP279">
+    <_3:licenseConcluded rdf:resource="http://spdx.org/licenses/MIT"/>
+    <_3:licenseInfoInFile rdf:resource="http://spdx.org/rdf/terms#none"/>
+    <_3:copyrightText>Copyright 2013-2016 Duktape authors (see AUTHORS.rst in the Duktape distributable)</_3:copyrightText>
+    <_3:checksum rdf:nodeID="svBMzJkP280"/>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#File"/>
+    <_3:fileName>./src-separate/duk_hstring.h</_3:fileName>
+    <_3:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_source"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP217">
+    <_3:licenseConcluded rdf:resource="http://spdx.org/licenses/MIT"/>
+    <_3:licenseInfoInFile rdf:resource="http://spdx.org/rdf/terms#none"/>
+    <_3:copyrightText>Copyright 2013-2016 Duktape authors (see AUTHORS.rst in the Duktape distributable)</_3:copyrightText>
+    <_3:checksum rdf:nodeID="svBMzJkP218"/>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#File"/>
+    <_3:fileName>./src-separate/duk_hobject_enum.c</_3:fileName>
+    <_3:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_source"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP436">
+    <_3:algorithm rdf:resource="http://spdx.org/rdf/terms#checksumAlgorithm_sha1"/>
+    <_3:checksumValue>525e80da2b6d3640fd42af0f662d7b68865d6529</_3:checksumValue>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#Checksum"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP370">
+    <_3:algorithm rdf:resource="http://spdx.org/rdf/terms#checksumAlgorithm_sha1"/>
+    <_3:checksumValue>84b33d737bba2dadfdd950adad7a96d3d88eb01d</_3:checksumValue>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#Checksum"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP53">
+    <_3:licenseConcluded rdf:resource="http://spdx.org/licenses/MIT"/>
+    <_3:licenseInfoInFile rdf:resource="http://spdx.org/rdf/terms#none"/>
+    <_3:copyrightText>Copyright 2013-2016 Duktape authors (see AUTHORS.rst in the Duktape distributable)</_3:copyrightText>
+    <_3:checksum rdf:nodeID="svBMzJkP54"/>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#File"/>
+    <_3:fileName>./debugger/Makefile</_3:fileName>
+    <_3:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_other"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP105">
+    <_3:licenseConcluded rdf:resource="http://spdx.org/licenses/MIT"/>
+    <_3:licenseInfoInFile rdf:resource="http://spdx.org/rdf/terms#none"/>
+    <_3:copyrightText>Copyright 2013-2016 Duktape authors (see AUTHORS.rst in the Duktape distributable)</_3:copyrightText>
+    <_3:checksum rdf:nodeID="svBMzJkP106"/>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#File"/>
+    <_3:fileName>./examples/eventloop/ncurses.c</_3:fileName>
+    <_3:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_source"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP341">
+    <_3:licenseConcluded rdf:resource="http://spdx.org/licenses/MIT"/>
+    <_3:licenseInfoInFile rdf:resource="http://spdx.org/rdf/terms#none"/>
+    <_3:copyrightText>Copyright 2013-2016 Duktape authors (see AUTHORS.rst in the Duktape distributable)</_3:copyrightText>
+    <_3:checksum rdf:nodeID="svBMzJkP342"/>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#File"/>
+    <_3:fileName>./src-separate/duk_error_misc.c</_3:fileName>
+    <_3:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_source"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP338">
+    <_3:algorithm rdf:resource="http://spdx.org/rdf/terms#checksumAlgorithm_sha1"/>
+    <_3:checksumValue>012bd42371c53e6c32e357201ee91c258640e546</_3:checksumValue>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#Checksum"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP253">
+    <_3:licenseConcluded rdf:resource="http://spdx.org/licenses/MIT"/>
+    <_3:licenseInfoInFile rdf:resource="http://spdx.org/rdf/terms#none"/>
+    <_3:copyrightText>Copyright 2013-2016 Duktape authors (see AUTHORS.rst in the Duktape distributable)</_3:copyrightText>
+    <_3:checksum rdf:nodeID="svBMzJkP254"/>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#File"/>
+    <_3:fileName>./src-separate/duk_js_bytecode.h</_3:fileName>
+    <_3:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_source"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP133">
+    <_3:licenseConcluded rdf:resource="http://spdx.org/licenses/MIT"/>
+    <_3:licenseInfoInFile rdf:resource="http://spdx.org/rdf/terms#none"/>
+    <_3:copyrightText>Copyright 2013-2016 Duktape authors (see AUTHORS.rst in the Duktape distributable)</_3:copyrightText>
+    <_3:checksum rdf:nodeID="svBMzJkP134"/>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#File"/>
+    <_3:fileName>./examples/eval/eval.c</_3:fileName>
+    <_3:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_source"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP305">
+    <_3:licenseConcluded rdf:resource="http://spdx.org/licenses/MIT"/>
+    <_3:licenseInfoInFile rdf:resource="http://spdx.org/rdf/terms#none"/>
+    <_3:copyrightText>Copyright 2013-2016 Duktape authors (see AUTHORS.rst in the Duktape distributable)</_3:copyrightText>
+    <_3:checksum rdf:nodeID="svBMzJkP306"/>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#File"/>
+    <_3:fileName>./src-separate/duk_util_tinyrandom.c</_3:fileName>
+    <_3:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_source"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP169">
+    <_3:licenseConcluded rdf:resource="http://spdx.org/licenses/MIT"/>
+    <_3:licenseInfoInFile rdf:resource="http://spdx.org/rdf/terms#none"/>
+    <_3:copyrightText>Copyright 2013-2016 Duktape authors (see AUTHORS.rst in the Duktape distributable)</_3:copyrightText>
+    <_3:checksum rdf:nodeID="svBMzJkP170"/>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#File"/>
+    <_3:fileName>./examples/debug-trans-socket/duk_trans_socket_windows.c</_3:fileName>
+    <_3:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_source"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP263">
+    <_3:licenseConcluded rdf:resource="http://spdx.org/licenses/MIT"/>
+    <_3:licenseInfoInFile rdf:resource="http://spdx.org/rdf/terms#none"/>
+    <_3:copyrightText>Copyright 2013-2016 Duktape authors (see AUTHORS.rst in the Duktape distributable)</_3:copyrightText>
+    <_3:checksum rdf:nodeID="svBMzJkP264"/>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#File"/>
+    <_3:fileName>./src-separate/duk_forwdecl.h</_3:fileName>
+    <_3:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_source"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP351">
+    <_3:licenseConcluded rdf:resource="http://spdx.org/licenses/MIT"/>
+    <_3:licenseInfoInFile rdf:resource="http://spdx.org/rdf/terms#none"/>
+    <_3:copyrightText>Copyright 2013-2016 Duktape authors (see AUTHORS.rst in the Duktape distributable)</_3:copyrightText>
+    <_3:checksum rdf:nodeID="svBMzJkP352"/>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#File"/>
+    <_3:fileName>./src-separate/duk_hbuffer.h</_3:fileName>
+    <_3:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_source"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP250">
+    <_3:algorithm rdf:resource="http://spdx.org/rdf/terms#checksumAlgorithm_sha1"/>
+    <_3:checksumValue>a5985c22d5e36eaced8ebc72338a38ae0b73c9ad</_3:checksumValue>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#Checksum"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP103">
+    <_3:licenseConcluded rdf:resource="http://spdx.org/licenses/MIT"/>
+    <_3:licenseInfoInFile rdf:resource="http://spdx.org/rdf/terms#none"/>
+    <_3:copyrightText>Copyright 2013-2016 Duktape authors (see AUTHORS.rst in the Duktape distributable)</_3:copyrightText>
+    <_3:checksum rdf:nodeID="svBMzJkP104"/>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#File"/>
+    <_3:fileName>./examples/eventloop/c_eventloop.js</_3:fileName>
+    <_3:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_source"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP483">
+    <_3:licenseConcluded rdf:resource="http://spdx.org/licenses/MIT"/>
+    <_3:licenseInfoInFile rdf:resource="http://spdx.org/rdf/terms#none"/>
+    <_3:copyrightText>Copyright 2013-2016 Duktape authors (see AUTHORS.rst in the Duktape distributable)</_3:copyrightText>
+    <_3:checksum rdf:nodeID="svBMzJkP484"/>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#File"/>
+    <_3:fileName>./licenses/commonjs.txt</_3:fileName>
+    <_3:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_other"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP487">
+    <_3:licenseConcluded rdf:resource="http://spdx.org/licenses/MIT"/>
+    <_3:licenseInfoInFile rdf:resource="http://spdx.org/rdf/terms#none"/>
+    <_3:copyrightText>Copyright 2013-2016 Duktape authors (see AUTHORS.rst in the Duktape distributable)</_3:copyrightText>
+    <_3:checksum rdf:nodeID="svBMzJkP488"/>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#File"/>
+    <_3:fileName>./src/duk_config.h</_3:fileName>
+    <_3:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_source"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP332">
+    <_3:algorithm rdf:resource="http://spdx.org/rdf/terms#checksumAlgorithm_sha1"/>
+    <_3:checksumValue>4edee4bb513bcff807e343902af260ed8ff72850</_3:checksumValue>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#Checksum"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP423">
+    <_3:licenseConcluded rdf:resource="http://spdx.org/licenses/MIT"/>
+    <_3:licenseInfoInFile rdf:resource="http://spdx.org/rdf/terms#none"/>
+    <_3:copyrightText>Copyright 2013-2016 Duktape authors (see AUTHORS.rst in the Duktape distributable)</_3:copyrightText>
+    <_3:checksum rdf:nodeID="svBMzJkP424"/>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#File"/>
+    <_3:fileName>./src-separate/duk_tval.c</_3:fileName>
+    <_3:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_source"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP490">
+    <_3:algorithm rdf:resource="http://spdx.org/rdf/terms#checksumAlgorithm_sha1"/>
+    <_3:checksumValue>5e427d4685c63b3e7c638c6eaac5e7df8216507f</_3:checksumValue>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#Checksum"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP107">
+    <_3:licenseConcluded rdf:resource="http://spdx.org/licenses/MIT"/>
+    <_3:licenseInfoInFile rdf:resource="http://spdx.org/rdf/terms#none"/>
+    <_3:copyrightText>Copyright 2013-2016 Duktape authors (see AUTHORS.rst in the Duktape distributable)</_3:copyrightText>
+    <_3:checksum rdf:nodeID="svBMzJkP108"/>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#File"/>
+    <_3:fileName>./examples/eventloop/socket.c</_3:fileName>
+    <_3:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_source"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP165">
+    <_3:licenseConcluded rdf:resource="http://spdx.org/licenses/MIT"/>
+    <_3:licenseInfoInFile rdf:resource="http://spdx.org/rdf/terms#none"/>
+    <_3:copyrightText>Copyright 2013-2016 Duktape authors (see AUTHORS.rst in the Duktape distributable)</_3:copyrightText>
+    <_3:checksum rdf:nodeID="svBMzJkP166"/>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#File"/>
+    <_3:fileName>./examples/cmdline/duk_cmdline.c</_3:fileName>
+    <_3:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_source"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP355">
+    <_3:licenseConcluded rdf:resource="http://spdx.org/licenses/MIT"/>
+    <_3:licenseInfoInFile rdf:resource="http://spdx.org/rdf/terms#none"/>
+    <_3:copyrightText>Copyright 2013-2016 Duktape authors (see AUTHORS.rst in the Duktape distributable)</_3:copyrightText>
+    <_3:checksum rdf:nodeID="svBMzJkP356"/>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#File"/>
+    <_3:fileName>./src-separate/duk_selftest.c</_3:fileName>
+    <_3:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_source"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP255">
+    <_3:licenseConcluded rdf:resource="http://spdx.org/licenses/MIT"/>
+    <_3:licenseInfoInFile rdf:resource="http://spdx.org/rdf/terms#none"/>
+    <_3:copyrightText>Copyright 2013-2016 Duktape authors (see AUTHORS.rst in the Duktape distributable)</_3:copyrightText>
+    <_3:checksum rdf:nodeID="svBMzJkP256"/>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#File"/>
+    <_3:fileName>./src-separate/duk_heap.h</_3:fileName>
+    <_3:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_source"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP189">
+    <_3:licenseConcluded rdf:resource="http://spdx.org/licenses/MIT"/>
+    <_3:licenseInfoInFile rdf:resource="http://spdx.org/rdf/terms#none"/>
+    <_3:copyrightText>Copyright 2013-2016 Duktape authors (see AUTHORS.rst in the Duktape distributable)</_3:copyrightText>
+    <_3:checksum rdf:nodeID="svBMzJkP190"/>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#File"/>
+    <_3:fileName>./examples/sandbox/README.rst</_3:fileName>
+    <_3:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_other"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP373">
+    <_3:licenseConcluded rdf:resource="http://spdx.org/licenses/MIT"/>
+    <_3:licenseInfoInFile rdf:resource="http://spdx.org/rdf/terms#none"/>
+    <_3:copyrightText>Copyright 2013-2016 Duktape authors (see AUTHORS.rst in the Duktape distributable)</_3:copyrightText>
+    <_3:checksum rdf:nodeID="svBMzJkP374"/>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#File"/>
+    <_3:fileName>./src-separate/duk_hbuffer_ops.c</_3:fileName>
+    <_3:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_source"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP466">
+    <_3:algorithm rdf:resource="http://spdx.org/rdf/terms#checksumAlgorithm_sha1"/>
+    <_3:checksumValue>11a7a5b6b1557adeca8a9def51cb44282f24c853</_3:checksumValue>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#Checksum"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP339">
+    <_3:licenseConcluded rdf:resource="http://spdx.org/licenses/MIT"/>
+    <_3:licenseInfoInFile rdf:resource="http://spdx.org/rdf/terms#none"/>
+    <_3:copyrightText>Copyright 2013-2016 Duktape authors (see AUTHORS.rst in the Duktape distributable)</_3:copyrightText>
+    <_3:checksum rdf:nodeID="svBMzJkP340"/>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#File"/>
+    <_3:fileName>./src-separate/duk_js_var.c</_3:fileName>
+    <_3:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_source"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP247">
+    <_3:licenseConcluded rdf:resource="http://spdx.org/licenses/MIT"/>
+    <_3:licenseInfoInFile rdf:resource="http://spdx.org/rdf/terms#none"/>
+    <_3:copyrightText>Copyright 2013-2016 Duktape authors (see AUTHORS.rst in the Duktape distributable)</_3:copyrightText>
+    <_3:checksum rdf:nodeID="svBMzJkP248"/>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#File"/>
+    <_3:fileName>./src-separate/duk_hobject_props.c</_3:fileName>
+    <_3:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_source"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP375">
+    <_3:licenseConcluded rdf:resource="http://spdx.org/licenses/MIT"/>
+    <_3:licenseInfoInFile rdf:resource="http://spdx.org/rdf/terms#none"/>
+    <_3:copyrightText>Copyright 2013-2016 Duktape authors (see AUTHORS.rst in the Duktape distributable)</_3:copyrightText>
+    <_3:checksum rdf:nodeID="svBMzJkP376"/>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#File"/>
+    <_3:fileName>./src-separate/duk_heap_hashstring.c</_3:fileName>
+    <_3:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_source"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP38">
+    <_3:algorithm rdf:resource="http://spdx.org/rdf/terms#checksumAlgorithm_sha1"/>
+    <_3:checksumValue>2e1b55e44a5845fb785dde5b8c2e24bb7bd2e1bf</_3:checksumValue>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#Checksum"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP252">
+    <_3:algorithm rdf:resource="http://spdx.org/rdf/terms#checksumAlgorithm_sha1"/>
+    <_3:checksumValue>a98ed9095834cad5b50d63cf8e659cca90e01062</_3:checksumValue>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#Checksum"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP227">
+    <_3:licenseConcluded rdf:resource="http://spdx.org/licenses/MIT"/>
+    <_3:licenseInfoInFile rdf:resource="http://spdx.org/rdf/terms#none"/>
+    <_3:copyrightText>Copyright 2013-2016 Duktape authors (see AUTHORS.rst in the Duktape distributable)</_3:copyrightText>
+    <_3:checksum rdf:nodeID="svBMzJkP228"/>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#File"/>
+    <_3:fileName>./src-separate/duk_bi_date_unix.c</_3:fileName>
+    <_3:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_source"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP290">
+    <_3:algorithm rdf:resource="http://spdx.org/rdf/terms#checksumAlgorithm_sha1"/>
+    <_3:checksumValue>467388c812411a0d2b80760983171c346d35953d</_3:checksumValue>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#Checksum"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP371">
+    <_3:licenseConcluded rdf:resource="http://spdx.org/licenses/MIT"/>
+    <_3:licenseInfoInFile rdf:resource="http://spdx.org/rdf/terms#none"/>
+    <_3:copyrightText>Copyright 2013-2016 Duktape authors (see AUTHORS.rst in the Duktape distributable)</_3:copyrightText>
+    <_3:checksum rdf:nodeID="svBMzJkP372"/>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#File"/>
+    <_3:fileName>./src-separate/duk_regexp_compiler.c</_3:fileName>
+    <_3:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_source"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP234">
+    <_3:algorithm rdf:resource="http://spdx.org/rdf/terms#checksumAlgorithm_sha1"/>
+    <_3:checksumValue>4d3ab8c2d41261b0cae627db9d536d26f72b5f8e</_3:checksumValue>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#Checksum"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP459">
+    <_3:licenseConcluded rdf:resource="http://spdx.org/licenses/MIT"/>
+    <_3:licenseInfoInFile rdf:resource="http://spdx.org/rdf/terms#none"/>
+    <_3:copyrightText>Copyright 2013-2016 Duktape authors (see AUTHORS.rst in the Duktape distributable)</_3:copyrightText>
+    <_3:checksum rdf:nodeID="svBMzJkP460"/>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#File"/>
+    <_3:fileName>./polyfills/object-prototype-definesetter.js</_3:fileName>
+    <_3:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_source"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP56">
+    <_3:algorithm rdf:resource="http://spdx.org/rdf/terms#checksumAlgorithm_sha1"/>
+    <_3:checksumValue>79dac8ea1aa08daa3c8e9b6137b8a01c8d501893</_3:checksumValue>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#Checksum"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP142">
+    <_3:algorithm rdf:resource="http://spdx.org/rdf/terms#checksumAlgorithm_sha1"/>
+    <_3:checksumValue>8aa63b553757fe1229638e978b540d7116b70274</_3:checksumValue>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#Checksum"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP325">
+    <_3:licenseConcluded rdf:resource="http://spdx.org/licenses/MIT"/>
+    <_3:licenseInfoInFile rdf:resource="http://spdx.org/rdf/terms#none"/>
+    <_3:copyrightText>Copyright 2013-2016 Duktape authors (see AUTHORS.rst in the Duktape distributable)</_3:copyrightText>
+    <_3:checksum rdf:nodeID="svBMzJkP326"/>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#File"/>
+    <_3:fileName>./src-separate/duk_js_compiler.h</_3:fileName>
+    <_3:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_source"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP354">
+    <_3:algorithm rdf:resource="http://spdx.org/rdf/terms#checksumAlgorithm_sha1"/>
+    <_3:checksumValue>32ba21f45afd4b027113eda5aba53314c3f00da9</_3:checksumValue>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#Checksum"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP45">
+    <_3:licenseConcluded rdf:resource="http://spdx.org/licenses/MIT"/>
+    <_3:licenseInfoInFile rdf:resource="http://spdx.org/rdf/terms#none"/>
+    <_3:copyrightText>Copyright 2013-2016 Duktape authors (see AUTHORS.rst in the Duktape distributable)</_3:copyrightText>
+    <_3:checksum rdf:nodeID="svBMzJkP46"/>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#File"/>
+    <_3:fileName>./debugger/duk_debug.js</_3:fileName>
+    <_3:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_source"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP342">
+    <_3:algorithm rdf:resource="http://spdx.org/rdf/terms#checksumAlgorithm_sha1"/>
+    <_3:checksumValue>c00100a35037a372ebcde740082d5bb7c7735057</_3:checksumValue>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#Checksum"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP135">
+    <_3:licenseConcluded rdf:resource="http://spdx.org/licenses/MIT"/>
+    <_3:licenseInfoInFile rdf:resource="http://spdx.org/rdf/terms#none"/>
+    <_3:copyrightText>Copyright 2013-2016 Duktape authors (see AUTHORS.rst in the Duktape distributable)</_3:copyrightText>
+    <_3:checksum rdf:nodeID="svBMzJkP136"/>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#File"/>
+    <_3:fileName>./examples/cpp-exceptions/README.rst</_3:fileName>
+    <_3:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_other"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP485">
+    <_3:licenseConcluded rdf:resource="http://spdx.org/licenses/MIT"/>
+    <_3:licenseInfoInFile rdf:resource="http://spdx.org/rdf/terms#none"/>
+    <_3:copyrightText>Copyright 2013-2016 Duktape authors (see AUTHORS.rst in the Duktape distributable)</_3:copyrightText>
+    <_3:checksum rdf:nodeID="svBMzJkP486"/>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#File"/>
+    <_3:fileName>./src/metadata.json</_3:fileName>
+    <_3:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_other"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP428">
+    <_3:algorithm rdf:resource="http://spdx.org/rdf/terms#checksumAlgorithm_sha1"/>
+    <_3:checksumValue>5bd828887b0f46810358539868398e64b622d047</_3:checksumValue>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#Checksum"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP128">
+    <_3:algorithm rdf:resource="http://spdx.org/rdf/terms#checksumAlgorithm_sha1"/>
+    <_3:checksumValue>82314b509ee3b15b393fefe747c8e0169ab39aaa</_3:checksumValue>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#Checksum"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP407">
+    <_3:licenseConcluded rdf:resource="http://spdx.org/licenses/MIT"/>
+    <_3:licenseInfoInFile rdf:resource="http://spdx.org/rdf/terms#none"/>
+    <_3:copyrightText>Copyright 2013-2016 Duktape authors (see AUTHORS.rst in the Duktape distributable)</_3:copyrightText>
+    <_3:checksum rdf:nodeID="svBMzJkP408"/>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#File"/>
+    <_3:fileName>./src-separate/duk_numconv.c</_3:fileName>
+    <_3:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_source"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP269">
+    <_3:licenseConcluded rdf:resource="http://spdx.org/licenses/MIT"/>
+    <_3:licenseInfoInFile rdf:resource="http://spdx.org/rdf/terms#none"/>
+    <_3:copyrightText>Copyright 2013-2016 Duktape authors (see AUTHORS.rst in the Duktape distributable)</_3:copyrightText>
+    <_3:checksum rdf:nodeID="svBMzJkP270"/>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#File"/>
+    <_3:fileName>./src-separate/duk_bi_date.c</_3:fileName>
+    <_3:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_source"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP440">
+    <_3:algorithm rdf:resource="http://spdx.org/rdf/terms#checksumAlgorithm_sha1"/>
+    <_3:checksumValue>23b6b54a8a35fbec735ffb332f4100a7f00557be</_3:checksumValue>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#Checksum"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP345">
+    <_3:licenseConcluded rdf:resource="http://spdx.org/licenses/MIT"/>
+    <_3:licenseInfoInFile rdf:resource="http://spdx.org/rdf/terms#none"/>
+    <_3:copyrightText>Copyright 2013-2016 Duktape authors (see AUTHORS.rst in the Duktape distributable)</_3:copyrightText>
+    <_3:checksum rdf:nodeID="svBMzJkP346"/>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#File"/>
+    <_3:fileName>./src-separate/duk_hthread.h</_3:fileName>
+    <_3:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_source"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP57">
+    <_3:licenseConcluded rdf:resource="http://spdx.org/licenses/MIT"/>
+    <_3:licenseInfoInFile rdf:resource="http://spdx.org/rdf/terms#none"/>
+    <_3:copyrightText>Copyright 2013-2016 Duktape authors (see AUTHORS.rst in the Duktape distributable)</_3:copyrightText>
+    <_3:checksum rdf:nodeID="svBMzJkP58"/>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#File"/>
+    <_3:fileName>./debugger/duk_debug_meta.json</_3:fileName>
+    <_3:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_other"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP50">
+    <_3:algorithm rdf:resource="http://spdx.org/rdf/terms#checksumAlgorithm_sha1"/>
+    <_3:checksumValue>fe251e819feb6f84c1c8169eb6921174be2b1373</_3:checksumValue>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#Checksum"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP218">
+    <_3:algorithm rdf:resource="http://spdx.org/rdf/terms#checksumAlgorithm_sha1"/>
+    <_3:checksumValue>6806426efc13e73e41899bef0aecca7eec097c18</_3:checksumValue>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#Checksum"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP433">
+    <_3:licenseConcluded rdf:resource="http://spdx.org/licenses/MIT"/>
+    <_3:licenseInfoInFile rdf:resource="http://spdx.org/rdf/terms#none"/>
+    <_3:copyrightText>Copyright 2013-2016 Duktape authors (see AUTHORS.rst in the Duktape distributable)</_3:copyrightText>
+    <_3:checksum rdf:nodeID="svBMzJkP434"/>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#File"/>
+    <_3:fileName>./src-separate/duktape.h</_3:fileName>
+    <_3:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_source"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP39">
+    <_3:licenseConcluded rdf:resource="http://spdx.org/licenses/MIT"/>
+    <_3:licenseInfoInFile rdf:resource="http://spdx.org/rdf/terms#none"/>
+    <_3:copyrightText>Copyright 2013-2016 Duktape authors (see AUTHORS.rst in the Duktape distributable)</_3:copyrightText>
+    <_3:checksum rdf:nodeID="svBMzJkP40"/>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#File"/>
+    <_3:fileName>./src-noline/duk_config.h</_3:fileName>
+    <_3:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_source"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP449">
+    <_3:licenseConcluded rdf:resource="http://spdx.org/licenses/MIT"/>
+    <_3:licenseInfoInFile rdf:resource="http://spdx.org/rdf/terms#none"/>
+    <_3:copyrightText>Copyright 2013-2016 Duktape authors (see AUTHORS.rst in the Duktape distributable)</_3:copyrightText>
+    <_3:checksum rdf:nodeID="svBMzJkP450"/>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#File"/>
+    <_3:fileName>./src-separate/duk_debug_macros.c</_3:fileName>
+    <_3:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_source"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP174">
+    <_3:algorithm rdf:resource="http://spdx.org/rdf/terms#checksumAlgorithm_sha1"/>
+    <_3:checksumValue>012eed9a677efd2062f7ed6965d5a39e9e569c25</_3:checksumValue>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#Checksum"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP198">
+    <_3:algorithm rdf:resource="http://spdx.org/rdf/terms#checksumAlgorithm_sha1"/>
+    <_3:checksumValue>8015d14ffbc7a4a4b93d654f093aa48ec17fce4e</_3:checksumValue>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#Checksum"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP117">
+    <_3:licenseConcluded rdf:resource="http://spdx.org/licenses/MIT"/>
+    <_3:licenseInfoInFile rdf:resource="http://spdx.org/rdf/terms#none"/>
+    <_3:copyrightText>Copyright 2013-2016 Duktape authors (see AUTHORS.rst in the Duktape distributable)</_3:copyrightText>
+    <_3:checksum rdf:nodeID="svBMzJkP118"/>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#File"/>
+    <_3:fileName>./examples/eventloop/curses-timers.js</_3:fileName>
+    <_3:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_source"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP8">
+    <_3:algorithm rdf:resource="http://spdx.org/rdf/terms#checksumAlgorithm_sha1"/>
+    <_3:checksumValue>fa2824f02d8a2d21f729a4e9d44557f3b39a9355</_3:checksumValue>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#Checksum"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP403">
+    <_3:licenseConcluded rdf:resource="http://spdx.org/licenses/MIT"/>
+    <_3:licenseInfoInFile rdf:resource="http://spdx.org/rdf/terms#none"/>
+    <_3:copyrightText>Copyright 2013-2016 Duktape authors (see AUTHORS.rst in the Duktape distributable)</_3:copyrightText>
+    <_3:checksum rdf:nodeID="svBMzJkP404"/>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#File"/>
+    <_3:fileName>./src-separate/duk_strings.h</_3:fileName>
+    <_3:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_source"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP183">
+    <_3:licenseConcluded rdf:resource="http://spdx.org/licenses/MIT"/>
+    <_3:licenseInfoInFile rdf:resource="http://spdx.org/rdf/terms#none"/>
+    <_3:copyrightText>Copyright 2013-2016 Duktape authors (see AUTHORS.rst in the Duktape distributable)</_3:copyrightText>
+    <_3:checksum rdf:nodeID="svBMzJkP184"/>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#File"/>
+    <_3:fileName>./examples/debug-trans-dvalue/duk_trans_dvalue.c</_3:fileName>
+    <_3:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_source"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP130">
+    <_3:algorithm rdf:resource="http://spdx.org/rdf/terms#checksumAlgorithm_sha1"/>
+    <_3:checksumValue>a8c0b54002a3a7d8c69d385e7fbcf4b70d1efc70</_3:checksumValue>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#Checksum"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP62">
+    <_3:algorithm rdf:resource="http://spdx.org/rdf/terms#checksumAlgorithm_sha1"/>
+    <_3:checksumValue>c81b68018e3d6f1b93683f7ead8761c01f2ca760</_3:checksumValue>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#Checksum"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP445">
+    <_3:licenseConcluded rdf:resource="http://spdx.org/licenses/MIT"/>
+    <_3:licenseInfoInFile rdf:resource="http://spdx.org/rdf/terms#none"/>
+    <_3:copyrightText>Copyright 2013-2016 Duktape authors (see AUTHORS.rst in the Duktape distributable)</_3:copyrightText>
+    <_3:checksum rdf:nodeID="svBMzJkP446"/>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#File"/>
+    <_3:fileName>./src-separate/duk_heap_stringcache.c</_3:fileName>
+    <_3:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_source"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP20">
+    <_3:algorithm rdf:resource="http://spdx.org/rdf/terms#checksumAlgorithm_sha1"/>
+    <_3:checksumValue>df02f8688766b929639cca4881b73cb8f745c97c</_3:checksumValue>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#Checksum"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP335">
+    <_3:licenseConcluded rdf:resource="http://spdx.org/licenses/MIT"/>
+    <_3:licenseInfoInFile rdf:resource="http://spdx.org/rdf/terms#none"/>
+    <_3:copyrightText>Copyright 2013-2016 Duktape authors (see AUTHORS.rst in the Duktape distributable)</_3:copyrightText>
+    <_3:checksum rdf:nodeID="svBMzJkP336"/>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#File"/>
+    <_3:fileName>./src-separate/duk_heap_refcount.c</_3:fileName>
+    <_3:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_source"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP298">
+    <_3:algorithm rdf:resource="http://spdx.org/rdf/terms#checksumAlgorithm_sha1"/>
+    <_3:checksumValue>59df770184e4c26b190a76f4cd035c7e661d573f</_3:checksumValue>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#Checksum"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP469">
+    <_3:licenseConcluded rdf:resource="http://spdx.org/licenses/MIT"/>
+    <_3:licenseInfoInFile rdf:resource="http://spdx.org/rdf/terms#none"/>
+    <_3:copyrightText>Copyright 2013-2016 Duktape authors (see AUTHORS.rst in the Duktape distributable)</_3:copyrightText>
+    <_3:checksum rdf:nodeID="svBMzJkP470"/>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#File"/>
+    <_3:fileName>./config/README.rst</_3:fileName>
+    <_3:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_other"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP232">
+    <_3:algorithm rdf:resource="http://spdx.org/rdf/terms#checksumAlgorithm_sha1"/>
+    <_3:checksumValue>fd24ca07cfd8fd37f3e70d10ad078ee5f149c9ce</_3:checksumValue>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#Checksum"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP29">
+    <_3:licenseConcluded rdf:resource="http://spdx.org/licenses/MIT"/>
+    <_3:licenseInfoInFile rdf:resource="http://spdx.org/rdf/terms#none"/>
+    <_3:copyrightText>Copyright 2013-2016 Duktape authors (see AUTHORS.rst in the Duktape distributable)</_3:copyrightText>
+    <_3:checksum rdf:nodeID="svBMzJkP30"/>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#File"/>
+    <_3:fileName>./Makefile.dukdebug</_3:fileName>
+    <_3:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_other"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP435">
+    <_3:licenseConcluded rdf:resource="http://spdx.org/licenses/MIT"/>
+    <_3:licenseInfoInFile rdf:resource="http://spdx.org/rdf/terms#none"/>
+    <_3:copyrightText>Copyright 2013-2016 Duktape authors (see AUTHORS.rst in the Duktape distributable)</_3:copyrightText>
+    <_3:checksum rdf:nodeID="svBMzJkP436"/>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#File"/>
+    <_3:fileName>./src-separate/duk_replacements.c</_3:fileName>
+    <_3:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_source"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP188">
+    <_3:algorithm rdf:resource="http://spdx.org/rdf/terms#checksumAlgorithm_sha1"/>
+    <_3:checksumValue>22046b9dfc552ed692193d1bf5e3d0e182111ae5</_3:checksumValue>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#Checksum"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP283">
+    <_3:licenseConcluded rdf:resource="http://spdx.org/licenses/MIT"/>
+    <_3:licenseInfoInFile rdf:resource="http://spdx.org/rdf/terms#none"/>
+    <_3:copyrightText>Copyright 2013-2016 Duktape authors (see AUTHORS.rst in the Duktape distributable)</_3:copyrightText>
+    <_3:checksum rdf:nodeID="svBMzJkP284"/>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#File"/>
+    <_3:fileName>./src-separate/duk_api_internal.h</_3:fileName>
+    <_3:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_source"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP399">
+    <_3:licenseConcluded rdf:resource="http://spdx.org/licenses/MIT"/>
+    <_3:licenseInfoInFile rdf:resource="http://spdx.org/rdf/terms#none"/>
+    <_3:copyrightText>Copyright 2013-2016 Duktape authors (see AUTHORS.rst in the Duktape distributable)</_3:copyrightText>
+    <_3:checksum rdf:nodeID="svBMzJkP400"/>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#File"/>
+    <_3:fileName>./src-separate/duk_js_executor.c</_3:fileName>
+    <_3:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_source"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP481">
+    <_3:licenseConcluded rdf:resource="http://spdx.org/licenses/MIT"/>
+    <_3:licenseInfoInFile rdf:resource="http://spdx.org/rdf/terms#none"/>
+    <_3:copyrightText>Copyright 2013-2016 Duktape authors (see AUTHORS.rst in the Duktape distributable)</_3:copyrightText>
+    <_3:checksum rdf:nodeID="svBMzJkP482"/>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#File"/>
+    <_3:fileName>./licenses/lua.txt</_3:fileName>
+    <_3:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_other"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP140">
+    <_3:algorithm rdf:resource="http://spdx.org/rdf/terms#checksumAlgorithm_sha1"/>
+    <_3:checksumValue>e023af5c2fb4b1efab74a230c552f1eb1b37fc10</_3:checksumValue>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#Checksum"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP127">
+    <_3:licenseConcluded rdf:resource="http://spdx.org/licenses/MIT"/>
+    <_3:licenseInfoInFile rdf:resource="http://spdx.org/rdf/terms#none"/>
+    <_3:copyrightText>Copyright 2013-2016 Duktape authors (see AUTHORS.rst in the Duktape distributable)</_3:copyrightText>
+    <_3:checksum rdf:nodeID="svBMzJkP128"/>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#File"/>
+    <_3:fileName>./examples/dummy-date-provider/README.rst</_3:fileName>
+    <_3:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_other"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP438">
+    <_3:algorithm rdf:resource="http://spdx.org/rdf/terms#checksumAlgorithm_sha1"/>
+    <_3:checksumValue>54a05944602f4a24864001a40d770591c6800daf</_3:checksumValue>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#Checksum"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP46">
+    <_3:algorithm rdf:resource="http://spdx.org/rdf/terms#checksumAlgorithm_sha1"/>
+    <_3:checksumValue>4e41e7165a8d6e3bd370bc4536b16835a7204cf6</_3:checksumValue>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#Checksum"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP308">
+    <_3:algorithm rdf:resource="http://spdx.org/rdf/terms#checksumAlgorithm_sha1"/>
+    <_3:checksumValue>a23d89e3ff8fe247e09338af7b38bdab41da5c3e</_3:checksumValue>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#Checksum"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP357">
+    <_3:licenseConcluded rdf:resource="http://spdx.org/licenses/MIT"/>
+    <_3:licenseInfoInFile rdf:resource="http://spdx.org/rdf/terms#none"/>
+    <_3:copyrightText>Copyright 2013-2016 Duktape authors (see AUTHORS.rst in the Duktape distributable)</_3:copyrightText>
+    <_3:checksum rdf:nodeID="svBMzJkP358"/>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#File"/>
+    <_3:fileName>./src-separate/duk_tval.h</_3:fileName>
+    <_3:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_source"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP336">
+    <_3:algorithm rdf:resource="http://spdx.org/rdf/terms#checksumAlgorithm_sha1"/>
+    <_3:checksumValue>821b268a1d4339ea2b309bdb6f527aa61bdb6b23</_3:checksumValue>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#Checksum"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP192">
+    <_3:algorithm rdf:resource="http://spdx.org/rdf/terms#checksumAlgorithm_sha1"/>
+    <_3:checksumValue>194e0bf80a1ddcc4d2d68ea6d2539656f3044f78</_3:checksumValue>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#Checksum"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP260">
+    <_3:algorithm rdf:resource="http://spdx.org/rdf/terms#checksumAlgorithm_sha1"/>
+    <_3:checksumValue>063133679b6d072efc1c27f3a510101744ffde0c</_3:checksumValue>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#Checksum"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP353">
+    <_3:licenseConcluded rdf:resource="http://spdx.org/licenses/MIT"/>
+    <_3:licenseInfoInFile rdf:resource="http://spdx.org/rdf/terms#none"/>
+    <_3:copyrightText>Copyright 2013-2016 Duktape authors (see AUTHORS.rst in the Duktape distributable)</_3:copyrightText>
+    <_3:checksum rdf:nodeID="svBMzJkP354"/>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#File"/>
+    <_3:fileName>./src-separate/duk_api_bytecode.c</_3:fileName>
+    <_3:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_source"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP186">
+    <_3:algorithm rdf:resource="http://spdx.org/rdf/terms#checksumAlgorithm_sha1"/>
+    <_3:checksumValue>5f3b6cd81be97aa687fe8b47751e68b5561d7c1b</_3:checksumValue>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#Checksum"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP68">
+    <_3:algorithm rdf:resource="http://spdx.org/rdf/terms#checksumAlgorithm_sha1"/>
+    <_3:checksumValue>ad583b87e72c08b4b44918dd1d7fce97e4950aa4</_3:checksumValue>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#Checksum"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP96">
+    <_3:algorithm rdf:resource="http://spdx.org/rdf/terms#checksumAlgorithm_sha1"/>
+    <_3:checksumValue>7e2674dd72227576375a80f6ddbb11320f5b987a</_3:checksumValue>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#Checksum"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP160">
+    <_3:algorithm rdf:resource="http://spdx.org/rdf/terms#checksumAlgorithm_sha1"/>
+    <_3:checksumValue>83b27494e6b257ab09828b0a4a1cf907686778a5</_3:checksumValue>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#Checksum"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP367">
+    <_3:licenseConcluded rdf:resource="http://spdx.org/licenses/MIT"/>
+    <_3:licenseInfoInFile rdf:resource="http://spdx.org/rdf/terms#none"/>
+    <_3:copyrightText>Copyright 2013-2016 Duktape authors (see AUTHORS.rst in the Duktape distributable)</_3:copyrightText>
+    <_3:checksum rdf:nodeID="svBMzJkP368"/>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#File"/>
+    <_3:fileName>./src-separate/duk_bi_boolean.c</_3:fileName>
+    <_3:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_source"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP42">
+    <_3:algorithm rdf:resource="http://spdx.org/rdf/terms#checksumAlgorithm_sha1"/>
+    <_3:checksumValue>829c4239ff43a1e15aa08bbbab41e7fba9207859</_3:checksumValue>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#Checksum"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP125">
+    <_3:licenseConcluded rdf:resource="http://spdx.org/licenses/MIT"/>
+    <_3:licenseInfoInFile rdf:resource="http://spdx.org/rdf/terms#none"/>
+    <_3:copyrightText>Copyright 2013-2016 Duktape authors (see AUTHORS.rst in the Duktape distributable)</_3:copyrightText>
+    <_3:checksum rdf:nodeID="svBMzJkP126"/>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#File"/>
+    <_3:fileName>./examples/eventloop/server-socket-test.js</_3:fileName>
+    <_3:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_source"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP392">
+    <_3:algorithm rdf:resource="http://spdx.org/rdf/terms#checksumAlgorithm_sha1"/>
+    <_3:checksumValue>a913f60f44a9e19cd5c31e84242db88a0868eba8</_3:checksumValue>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#Checksum"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP143">
+    <_3:licenseConcluded rdf:resource="http://spdx.org/licenses/MIT"/>
+    <_3:licenseInfoInFile rdf:resource="http://spdx.org/rdf/terms#none"/>
+    <_3:copyrightText>Copyright 2013-2016 Duktape authors (see AUTHORS.rst in the Duktape distributable)</_3:copyrightText>
+    <_3:checksum rdf:nodeID="svBMzJkP144"/>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#File"/>
+    <_3:fileName>./examples/guide/uppercase.c</_3:fileName>
+    <_3:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_source"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP282">
+    <_3:algorithm rdf:resource="http://spdx.org/rdf/terms#checksumAlgorithm_sha1"/>
+    <_3:checksumValue>786369a33cccbadc3d2efba613a43fdd638971fc</_3:checksumValue>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#Checksum"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP219">
+    <_3:licenseConcluded rdf:resource="http://spdx.org/licenses/MIT"/>
+    <_3:licenseInfoInFile rdf:resource="http://spdx.org/rdf/terms#none"/>
+    <_3:copyrightText>Copyright 2013-2016 Duktape authors (see AUTHORS.rst in the Duktape distributable)</_3:copyrightText>
+    <_3:checksum rdf:nodeID="svBMzJkP220"/>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#File"/>
+    <_3:fileName>./src-separate/duk_api_debug.c</_3:fileName>
+    <_3:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_source"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP154">
+    <_3:algorithm rdf:resource="http://spdx.org/rdf/terms#checksumAlgorithm_sha1"/>
+    <_3:checksumValue>881f1b114c9fbba139044ddcbbc5398243185d10</_3:checksumValue>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#Checksum"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP63">
+    <_3:licenseConcluded rdf:resource="http://spdx.org/licenses/MIT"/>
+    <_3:licenseInfoInFile rdf:resource="http://spdx.org/rdf/terms#none"/>
+    <_3:copyrightText>Copyright 2013-2016 Duktape authors (see AUTHORS.rst in the Duktape distributable)</_3:copyrightText>
+    <_3:checksum rdf:nodeID="svBMzJkP64"/>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#File"/>
+    <_3:fileName>./debugger/duk_opcodes.yaml</_3:fileName>
+    <_3:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_other"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP216">
+    <_3:algorithm rdf:resource="http://spdx.org/rdf/terms#checksumAlgorithm_sha1"/>
+    <_3:checksumValue>3fa5d72893eb3e1d42d07c8effc8bb1443f87dd6</_3:checksumValue>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#Checksum"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP248">
+    <_3:algorithm rdf:resource="http://spdx.org/rdf/terms#checksumAlgorithm_sha1"/>
+    <_3:checksumValue>105dd2e79d90b96b6b1ae419bff31ed6a0273af6</_3:checksumValue>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#Checksum"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP226">
+    <_3:algorithm rdf:resource="http://spdx.org/rdf/terms#checksumAlgorithm_sha1"/>
+    <_3:checksumValue>48eafa3f368fc879bfb79c2b2a30846a0b5d9b42</_3:checksumValue>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#Checksum"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP264">
+    <_3:algorithm rdf:resource="http://spdx.org/rdf/terms#checksumAlgorithm_sha1"/>
+    <_3:checksumValue>3f2b3b6b16cc969631b9980bc67aa6cc2c872048</_3:checksumValue>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#Checksum"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP313">
+    <_3:licenseConcluded rdf:resource="http://spdx.org/licenses/MIT"/>
+    <_3:licenseInfoInFile rdf:resource="http://spdx.org/rdf/terms#none"/>
+    <_3:copyrightText>Copyright 2013-2016 Duktape authors (see AUTHORS.rst in the Duktape distributable)</_3:copyrightText>
+    <_3:checksum rdf:nodeID="svBMzJkP314"/>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#File"/>
+    <_3:fileName>./src-separate/duk_error_augment.c</_3:fileName>
+    <_3:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_source"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP363">
+    <_3:licenseConcluded rdf:resource="http://spdx.org/licenses/MIT"/>
+    <_3:licenseInfoInFile rdf:resource="http://spdx.org/rdf/terms#none"/>
+    <_3:copyrightText>Copyright 2013-2016 Duktape authors (see AUTHORS.rst in the Duktape distributable)</_3:copyrightText>
+    <_3:checksum rdf:nodeID="svBMzJkP364"/>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#File"/>
+    <_3:fileName>./src-separate/duk_bi_thrower.c</_3:fileName>
+    <_3:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_source"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP122">
+    <_3:algorithm rdf:resource="http://spdx.org/rdf/terms#checksumAlgorithm_sha1"/>
+    <_3:checksumValue>6b98824e13a3d9536542b8da51d012a3d66ceec1</_3:checksumValue>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#Checksum"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP66">
+    <_3:algorithm rdf:resource="http://spdx.org/rdf/terms#checksumAlgorithm_sha1"/>
+    <_3:checksumValue>23f0401f57af7b8e4df6636637caffce6956445b</_3:checksumValue>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#Checksum"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP161">
+    <_3:licenseConcluded rdf:resource="http://spdx.org/licenses/MIT"/>
+    <_3:licenseInfoInFile rdf:resource="http://spdx.org/rdf/terms#none"/>
+    <_3:copyrightText>Copyright 2013-2016 Duktape authors (see AUTHORS.rst in the Duktape distributable)</_3:copyrightText>
+    <_3:checksum rdf:nodeID="svBMzJkP162"/>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#File"/>
+    <_3:fileName>./examples/hello/README.rst</_3:fileName>
+    <_3:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_other"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP410">
+    <_3:algorithm rdf:resource="http://spdx.org/rdf/terms#checksumAlgorithm_sha1"/>
+    <_3:checksumValue>457df68e290e23da40cac39a7cc35d6d6b4257c6</_3:checksumValue>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#Checksum"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP61">
+    <_3:licenseConcluded rdf:resource="http://spdx.org/licenses/MIT"/>
+    <_3:licenseInfoInFile rdf:resource="http://spdx.org/rdf/terms#none"/>
+    <_3:copyrightText>Copyright 2013-2016 Duktape authors (see AUTHORS.rst in the Duktape distributable)</_3:copyrightText>
+    <_3:checksum rdf:nodeID="svBMzJkP62"/>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#File"/>
+    <_3:fileName>./debugger/duk_classnames.yaml</_3:fileName>
+    <_3:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_other"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP164">
+    <_3:algorithm rdf:resource="http://spdx.org/rdf/terms#checksumAlgorithm_sha1"/>
+    <_3:checksumValue>a4e2dfaee71b2316f2c3d149b4a507250b54dd96</_3:checksumValue>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#Checksum"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP213">
+    <_3:licenseConcluded rdf:resource="http://spdx.org/licenses/MIT"/>
+    <_3:licenseInfoInFile rdf:resource="http://spdx.org/rdf/terms#none"/>
+    <_3:copyrightText>Copyright 2013-2016 Duktape authors (see AUTHORS.rst in the Duktape distributable)</_3:copyrightText>
+    <_3:checksum rdf:nodeID="svBMzJkP214"/>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#File"/>
+    <_3:fileName>./src-separate/duk_jmpbuf.h</_3:fileName>
+    <_3:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_source"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP460">
+    <_3:algorithm rdf:resource="http://spdx.org/rdf/terms#checksumAlgorithm_sha1"/>
+    <_3:checksumValue>089c395fca3cedceec09fd38d32d0c77dc8658f4</_3:checksumValue>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#Checksum"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP328">
+    <_3:algorithm rdf:resource="http://spdx.org/rdf/terms#checksumAlgorithm_sha1"/>
+    <_3:checksumValue>3f640daaa5e9d226a04fe419cb5eb1c07d06d346</_3:checksumValue>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#Checksum"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP47">
+    <_3:licenseConcluded rdf:resource="http://spdx.org/licenses/MIT"/>
+    <_3:licenseInfoInFile rdf:resource="http://spdx.org/rdf/terms#none"/>
+    <_3:copyrightText>Copyright 2013-2016 Duktape authors (see AUTHORS.rst in the Duktape distributable)</_3:copyrightText>
+    <_3:checksum rdf:nodeID="svBMzJkP48"/>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#File"/>
+    <_3:fileName>./debugger/duk_debugerrors.yaml</_3:fileName>
+    <_3:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_other"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP369">
+    <_3:licenseConcluded rdf:resource="http://spdx.org/licenses/MIT"/>
+    <_3:licenseInfoInFile rdf:resource="http://spdx.org/rdf/terms#none"/>
+    <_3:copyrightText>Copyright 2013-2016 Duktape authors (see AUTHORS.rst in the Duktape distributable)</_3:copyrightText>
+    <_3:checksum rdf:nodeID="svBMzJkP370"/>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#File"/>
+    <_3:fileName>./src-separate/duk_error_macros.c</_3:fileName>
+    <_3:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_source"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP76">
+    <_3:algorithm rdf:resource="http://spdx.org/rdf/terms#checksumAlgorithm_sha1"/>
+    <_3:checksumValue>4239a907720cf3620bd0b03eb43981e7182e305a</_3:checksumValue>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#Checksum"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP293">
+    <_3:licenseConcluded rdf:resource="http://spdx.org/licenses/MIT"/>
+    <_3:licenseInfoInFile rdf:resource="http://spdx.org/rdf/terms#none"/>
+    <_3:copyrightText>Copyright 2013-2016 Duktape authors (see AUTHORS.rst in the Duktape distributable)</_3:copyrightText>
+    <_3:checksum rdf:nodeID="svBMzJkP294"/>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#File"/>
+    <_3:fileName>./src-separate/duk_hthread_builtins.c</_3:fileName>
+    <_3:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_source"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP75">
+    <_3:licenseConcluded rdf:resource="http://spdx.org/licenses/MIT"/>
+    <_3:licenseInfoInFile rdf:resource="http://spdx.org/rdf/terms#none"/>
+    <_3:copyrightText>Copyright 2013-2016 Duktape authors (see AUTHORS.rst in the Duktape distributable)</_3:copyrightText>
+    <_3:checksum rdf:nodeID="svBMzJkP76"/>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#File"/>
+    <_3:fileName>./examples/coffee/mandel.coffee</_3:fileName>
+    <_3:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_other"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP296">
+    <_3:algorithm rdf:resource="http://spdx.org/rdf/terms#checksumAlgorithm_sha1"/>
+    <_3:checksumValue>6988aac432dcc185c2967732e21947ea0696377f</_3:checksumValue>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#Checksum"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP300">
+    <_3:algorithm rdf:resource="http://spdx.org/rdf/terms#checksumAlgorithm_sha1"/>
+    <_3:checksumValue>7b167c1ea560de7ac67e217c1fdff8912f8b677d</_3:checksumValue>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#Checksum"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP422">
+    <_3:algorithm rdf:resource="http://spdx.org/rdf/terms#checksumAlgorithm_sha1"/>
+    <_3:checksumValue>521f29841ddeb9be08ff9f7e2db06277da31bd47</_3:checksumValue>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#Checksum"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP155">
+    <_3:licenseConcluded rdf:resource="http://spdx.org/licenses/MIT"/>
+    <_3:licenseInfoInFile rdf:resource="http://spdx.org/rdf/terms#none"/>
+    <_3:copyrightText>Copyright 2013-2016 Duktape authors (see AUTHORS.rst in the Duktape distributable)</_3:copyrightText>
+    <_3:checksum rdf:nodeID="svBMzJkP156"/>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#File"/>
+    <_3:fileName>./examples/alloc-torture/duk_alloc_torture.c</_3:fileName>
+    <_3:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_source"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP157">
+    <_3:licenseConcluded rdf:resource="http://spdx.org/licenses/MIT"/>
+    <_3:licenseInfoInFile rdf:resource="http://spdx.org/rdf/terms#none"/>
+    <_3:copyrightText>Copyright 2013-2016 Duktape authors (see AUTHORS.rst in the Duktape distributable)</_3:copyrightText>
+    <_3:checksum rdf:nodeID="svBMzJkP158"/>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#File"/>
+    <_3:fileName>./examples/alloc-torture/duk_alloc_torture.h</_3:fileName>
+    <_3:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_source"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP71">
+    <_3:licenseConcluded rdf:resource="http://spdx.org/licenses/MIT"/>
+    <_3:licenseInfoInFile rdf:resource="http://spdx.org/rdf/terms#none"/>
+    <_3:copyrightText>Copyright 2013-2016 Duktape authors (see AUTHORS.rst in the Duktape distributable)</_3:copyrightText>
+    <_3:checksum rdf:nodeID="svBMzJkP72"/>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#File"/>
+    <_3:fileName>./debugger/static/index.html</_3:fileName>
+    <_3:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_other"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP356">
+    <_3:algorithm rdf:resource="http://spdx.org/rdf/terms#checksumAlgorithm_sha1"/>
+    <_3:checksumValue>93e24d8abbf79fb6a2fcd54679c476866ad6ab2a</_3:checksumValue>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#Checksum"/>
+  </rdf:Description>
+  <rdf:Description rdf:nodeID="svBMzJkP4">
+    <_3:licenseConcluded rdf:resource="http://spdx.org/licenses/MIT"/>
+    <_3:sourceInfo>Official duktape.org release built from GitHub repo https://github.com/svaarala/duktape.</_3:sourceInfo>
+    <_3:downloadLocation rdf:datatype="http://www.w3.org/2001/XMLSchema#anyURI">http://duktape.org/duktape-1.5.2.tar.xz</_3:downloadLocation>
+    <_3:licenseDeclared rdf:resource="http://spdx.org/licenses/MIT"/>
+    <_3:supplier>Organization: duktape.org</_3:supplier>
+    <_3:packageVerificationCode rdf:nodeID="svBMzJkP5"/>
+    <_3:copyrightText>Copyright 2013-2016 Duktape authors (see AUTHORS.rst in the Duktape distributable)</_3:copyrightText>
+    <rdf:type rdf:resource="http://spdx.org/rdf/terms#Package"/>
+    <_3:description>Duktape is an embeddable Javascript engine, with a focus on portability and compact footprint</_3:description>
+    <_3:licenseComments>Duktape is copyrighted by its authors and licensed under the MIT license.  MurmurHash2 is used internally, it is also under the MIT license. Duktape module loader is based on the CommonJS module loading specification (without sharing any code), CommonJS is under the MIT license.</_3:licenseComments>
+    <_3:originator>Organization: duktape.org</_3:originator>
+    <_3:hasFile rdf:nodeID="svBMzJkP127"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP101"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP21"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP337"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP55"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP91"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP413"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP321"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP129"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP139"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP473"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP357"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP419"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP451"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP95"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP115"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP79"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP275"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP191"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP261"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP23"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP353"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP267"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP427"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP119"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP205"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP335"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP211"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP19"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP149"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP319"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP367"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP265"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP441"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP385"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP289"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP175"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP277"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP125"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP471"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP229"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP143"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP415"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP137"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP219"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP37"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP429"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP485"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP63"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP295"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP301"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP231"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP89"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP35"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP349"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP297"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP271"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP171"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP467"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP393"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP417"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP331"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP291"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP185"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP327"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP313"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP147"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP363"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP97"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP49"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP409"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP41"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP243"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP151"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP439"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP213"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP379"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP131"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP333"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP47"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP369"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP209"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP273"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP31"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP73"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP293"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP389"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP27"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP281"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP259"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP75"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP443"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP287"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP383"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP317"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP69"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP155"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP157"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP279"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP215"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP217"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP71"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP83"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP199"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP53"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP105"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP341"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP195"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP347"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP253"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP133"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP305"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP169"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP465"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP303"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP187"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP489"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP351"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP109"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP103"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP9"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP17"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP395"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP381"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP431"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP343"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP481"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP251"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP421"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP189"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP405"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP299"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP487"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP93"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP463"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP67"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP423"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP329"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP107"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP165"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP111"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP355"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP223"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP483"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP387"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP255"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP453"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP391"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP7"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP249"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP241"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP197"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP263"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP177"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP397"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP245"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP113"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP475"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP59"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP247"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP375"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP437"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP173"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP163"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP411"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP373"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP371"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP65"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP459"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP461"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP257"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP325"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP43"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP45"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP51"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP457"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP365"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP167"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP479"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP233"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP135"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP377"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP309"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP235"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP207"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP339"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP237"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP407"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP269"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP13"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP307"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP123"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP221"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP345"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP323"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP57"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP193"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP77"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP433"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP39"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP401"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP161"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP283"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP227"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP445"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP425"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP117"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP203"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP403"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP447"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP183"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP87"/>
+    <_3:hasFile rdf:nodeID="svBMzJkP159"/>
+    <_

<TRUNCATED>

[32/51] [partial] nifi-minifi-cpp git commit: MINIFI-183 Added civet 1.9.1 sources Added onScheduled hook Added initial two-way TLS-enabled ListenHTTP implementation

Posted by al...@apache.org.
http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/config/duk_config.h-modular-static
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/config/duk_config.h-modular-static b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/config/duk_config.h-modular-static
new file mode 100644
index 0000000..b2b5a38
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/config/duk_config.h-modular-static
@@ -0,0 +1,3415 @@
+/*
+ *  duk_config.h configuration header generated by genconfig.py.
+ *
+ *  Git commit: cad34ae155acb0846545ca6bf2d29f9463b22bbb
+ *  Git describe: v1.5.2
+ *  Git branch: HEAD
+ *
+ *  Supported platforms:
+ *      - Mac OSX, iPhone, Darwin
+ *      - OpenBSD
+ *      - Generic BSD
+ *      - Atari ST TOS
+ *      - AmigaOS
+ *      - Windows
+ *      - Flashplayer (Crossbridge)
+ *      - QNX
+ *      - TI-Nspire
+ *      - Emscripten
+ *      - Linux
+ *      - Solaris
+ *      - Generic POSIX
+ *      - Cygwin
+ *      - Generic UNIX
+ *      - Generic fallback
+ *
+ *  Supported architectures:
+ *      - x86
+ *      - x64
+ *      - x32
+ *      - ARM 32-bit
+ *      - ARM 64-bit
+ *      - MIPS 32-bit
+ *      - MIPS 64-bit
+ *      - PowerPC 32-bit
+ *      - PowerPC 64-bit
+ *      - SPARC 32-bit
+ *      - SPARC 64-bit
+ *      - SuperH
+ *      - Motorola 68k
+ *      - Emscripten
+ *      - Generic
+ *
+ *  Supported compilers:
+ *      - Clang
+ *      - GCC
+ *      - MSVC
+ *      - Emscripten
+ *      - TinyC
+ *      - VBCC
+ *      - Bruce's C compiler
+ *      - Generic
+ *
+ */
+
+#if !defined(DUK_CONFIG_H_INCLUDED)
+#define DUK_CONFIG_H_INCLUDED
+
+/*
+ *  Intermediate helper defines
+ */
+
+/* DLL build detection */
+#if defined(DUK_OPT_DLL_BUILD)
+#define DUK_F_DLL_BUILD
+#elif defined(DUK_OPT_NO_DLL_BUILD)
+#undef DUK_F_DLL_BUILD
+#else
+/* not configured for DLL build */
+#undef DUK_F_DLL_BUILD
+#endif
+
+/* Apple OSX, iOS */
+#if defined(__APPLE__)
+#define DUK_F_APPLE
+#endif
+
+/* OpenBSD */
+#if defined(__OpenBSD__) || defined(__OpenBSD)
+#define DUK_F_OPENBSD
+#endif
+
+/* NetBSD */
+#if defined(__NetBSD__) || defined(__NetBSD)
+#define DUK_F_NETBSD
+#endif
+
+/* FreeBSD */
+#if defined(__FreeBSD__) || defined(__FreeBSD)
+#define DUK_F_FREEBSD
+#endif
+
+/* BSD variant */
+#if defined(DUK_F_FREEBSD) || defined(DUK_F_NETBSD) || defined(DUK_F_OPENBSD) || \
+    defined(__bsdi__) || defined(__DragonFly__)
+#define DUK_F_BSD
+#endif
+
+/* Atari ST TOS.  __TOS__ defined by PureC.  No platform define in VBCC
+ * apparently, so to use with VBCC user must define __TOS__ manually.
+  */
+#if defined(__TOS__)
+#define DUK_F_TOS
+#endif
+
+/* Motorola 68K.  Not defined by VBCC, so user must define one of these
+ * manually when using VBCC.
+ */
+#if defined(__m68k__) || defined(M68000) || defined(__MC68K__)
+#define DUK_F_M68K
+#endif
+
+/* AmigaOS.  Neither AMIGA nor __amigaos__ is defined on VBCC, so user must
+ * define 'AMIGA' manually when using VBCC.
+ */
+#if defined(AMIGA) || defined(__amigaos__)
+#define DUK_F_AMIGAOS
+#endif
+
+/* PowerPC */
+#if defined(__powerpc) || defined(__powerpc__) || defined(__PPC__)
+#define DUK_F_PPC
+#if defined(__PPC64__) || defined(__LP64__) || defined(_LP64)
+#define DUK_F_PPC64
+#else
+#define DUK_F_PPC32
+#endif
+#endif
+
+/* Windows, both 32-bit and 64-bit */
+#if defined(_WIN32) || defined(WIN32) || defined(_WIN64) || defined(WIN64) || \
+    defined(__WIN32__) || defined(__TOS_WIN__) || defined(__WINDOWS__)
+#define DUK_F_WINDOWS
+#if defined(_WIN64) || defined(WIN64)
+#define DUK_F_WIN64
+#else
+#define DUK_F_WIN32
+#endif
+#endif
+
+/* Flash player (e.g. Crossbridge) */
+#if defined(__FLASHPLAYER__)
+#define DUK_F_FLASHPLAYER
+#endif
+
+/* QNX */
+#if defined(__QNX__)
+#define DUK_F_QNX
+#endif
+
+/* TI-Nspire (using Ndless) */
+#if defined(_TINSPIRE)
+#define DUK_F_TINSPIRE
+#endif
+
+/* Emscripten (provided explicitly by user), improve if possible */
+#if defined(EMSCRIPTEN)
+#define DUK_F_EMSCRIPTEN
+#endif
+
+/* BCC (Bruce's C compiler): this is a "torture target" for compilation */
+#if defined(__BCC__) || defined(__BCC_VERSION__)
+#define DUK_F_BCC
+#endif
+
+/* Linux */
+#if defined(__linux) || defined(__linux__) || defined(linux)
+#define DUK_F_LINUX
+#endif
+
+/* illumos / Solaris */
+#if defined(__sun) && defined(__SVR4)
+#define DUK_F_SUN
+#endif
+
+/* POSIX */
+#if defined(__posix)
+#define DUK_F_POSIX
+#endif
+
+/* Cygwin */
+#if defined(__CYGWIN__)
+#define DUK_F_CYGWIN
+#endif
+
+/* Generic Unix (includes Cygwin) */
+#if defined(__unix) || defined(__unix__) || defined(unix) || \
+    defined(DUK_F_LINUX) || defined(DUK_F_BSD)
+#define DUK_F_UNIX
+#endif
+
+/* stdint.h not available */
+#if defined(DUK_F_WINDOWS) && defined(_MSC_VER)
+#if (_MSC_VER < 1700)
+/* VS2012+ has stdint.h, < VS2012 does not (but it's available for download). */
+#define DUK_F_NO_STDINT_H
+#endif
+#endif
+#if !defined(DUK_F_NO_STDINT_H) && (defined(DUK_F_TOS) || defined(DUK_F_BCC))
+#define DUK_F_NO_STDINT_H
+#endif
+
+/* C++ */
+#undef DUK_F_CPP
+#if defined(__cplusplus)
+#define DUK_F_CPP
+#endif
+
+/* Intel x86 (32-bit), x64 (64-bit) or x32 (64-bit but 32-bit pointers),
+ * define only one of DUK_F_X86, DUK_F_X64, DUK_F_X32.
+ * https://sites.google.com/site/x32abi/
+ */
+#if defined(__amd64__) || defined(__amd64) || \
+    defined(__x86_64__) || defined(__x86_64) || \
+    defined(_M_X64) || defined(_M_AMD64)
+#if defined(__ILP32__) || defined(_ILP32)
+#define DUK_F_X32
+#else
+#define DUK_F_X64
+#endif
+#elif defined(i386) || defined(__i386) || defined(__i386__) || \
+      defined(__i486__) || defined(__i586__) || defined(__i686__) || \
+      defined(__IA32__) || defined(_M_IX86) || defined(__X86__) || \
+      defined(_X86_) || defined(__THW_INTEL__) || defined(__I86__)
+#if defined(__LP64__) || defined(_LP64)
+/* This should not really happen, but would indicate x64. */
+#define DUK_F_X64
+#else
+#define DUK_F_X86
+#endif
+#endif
+
+/* ARM */
+#if defined(__arm__) || defined(__thumb__) || defined(_ARM) || defined(_M_ARM)
+#define DUK_F_ARM
+#if defined(__LP64__) || defined(_LP64) || defined(__arm64) || defined(__arm64__)
+#define DUK_F_ARM64
+#else
+#define DUK_F_ARM32
+#endif
+#endif
+
+/* MIPS.  Related defines: __MIPSEB__, __MIPSEL__, __mips_isa_rev, __LP64__ */
+#if defined(__mips__) || defined(mips) || defined(_MIPS_ISA) || \
+    defined(_R3000) || defined(_R4000) || defined(_R5900) || \
+    defined(_MIPS_ISA_MIPS1) || defined(_MIPS_ISA_MIPS2) || \
+    defined(_MIPS_ISA_MIPS3) || defined(_MIPS_ISA_MIPS4) || \
+    defined(__mips) || defined(__MIPS__)
+#define DUK_F_MIPS
+#if defined(__LP64__) || defined(_LP64) || defined(__mips64) || \
+    defined(__mips64__) || defined(__mips_n64)
+#define DUK_F_MIPS64
+#else
+#define DUK_F_MIPS32
+#endif
+#endif
+
+/* SPARC */
+#if defined(sparc) || defined(__sparc) || defined(__sparc__)
+#define DUK_F_SPARC
+#if defined(__LP64__) || defined(_LP64)
+#define DUK_F_SPARC64
+#else
+#define DUK_F_SPARC32
+#endif
+#endif
+
+/* SuperH */
+#if defined(__sh__) || \
+    defined(__sh1__) || defined(__SH1__) || \
+    defined(__sh2__) || defined(__SH2__) || \
+    defined(__sh3__) || defined(__SH3__) || \
+    defined(__sh4__) || defined(__SH4__) || \
+    defined(__sh5__) || defined(__SH5__)
+#define DUK_F_SUPERH
+#endif
+
+/* Clang */
+#if defined(__clang__)
+#define DUK_F_CLANG
+#endif
+
+/* C99 or above */
+#undef DUK_F_C99
+#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
+#define DUK_F_C99
+#endif
+
+/* C++11 or above */
+#undef DUK_F_CPP11
+#if defined(__cplusplus) && (__cplusplus >= 201103L)
+#define DUK_F_CPP11
+#endif
+
+/* GCC.  Clang also defines __GNUC__ so don't detect GCC if using Clang. */
+#if defined(__GNUC__) && !defined(__clang__) && !defined(DUK_F_CLANG)
+#define DUK_F_GCC
+#if defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__)
+/* Convenience, e.g. gcc 4.5.1 == 40501; http://stackoverflow.com/questions/6031819/emulating-gccs-builtin-unreachable */
+#define DUK_F_GCC_VERSION  (__GNUC__ * 10000L + __GNUC_MINOR__ * 100L + __GNUC_PATCHLEVEL__)
+#else
+#error cannot figure out gcc version
+#endif
+#endif
+
+/* MinGW.  Also GCC flags (DUK_F_GCC) are enabled now. */
+#if defined(__MINGW32__) || defined(__MINGW64__)
+#define DUK_F_MINGW
+#endif
+
+/* MSVC */
+#if defined(_MSC_VER)
+/* MSVC preprocessor defines: http://msdn.microsoft.com/en-us/library/b0084kay.aspx
+ * _MSC_FULL_VER includes the build number, but it has at least two formats, see e.g.
+ * BOOST_MSVC_FULL_VER in http://www.boost.org/doc/libs/1_52_0/boost/config/compiler/visualc.hpp
+ */
+#define DUK_F_MSVC
+#if defined(_MSC_FULL_VER)
+#if (_MSC_FULL_VER > 100000000)
+#define DUK_F_MSVC_FULL_VER _MSC_FULL_VER
+#else
+#define DUK_F_MSCV_FULL_VER (_MSC_FULL_VER * 10)
+#endif
+#endif
+#endif  /* _MSC_VER */
+
+/* TinyC */
+#if defined(__TINYC__)
+/* http://bellard.org/tcc/tcc-doc.html#SEC9 */
+#define DUK_F_TINYC
+#endif
+
+/* VBCC */
+#if defined(__VBCC__)
+#define DUK_F_VBCC
+#endif
+
+/* Atari Mint */
+#if defined(__MINT__)
+#define DUK_F_MINT
+#endif
+
+/*
+ *  Platform autodetection
+ */
+
+/* Workaround for older C++ compilers before including <inttypes.h>,
+ * see e.g.: https://sourceware.org/bugzilla/show_bug.cgi?id=15366
+ */
+#if defined(__cplusplus) && !defined(__STDC_LIMIT_MACROS)
+#define __STDC_LIMIT_MACROS
+#endif
+#if defined(__cplusplus) && !defined(__STDC_CONSTANT_MACROS)
+#define __STDC_CONSTANT_MACROS
+#endif
+
+#if defined(DUK_F_APPLE)
+/* --- Mac OSX, iPhone, Darwin --- */
+#define DUK_USE_DATE_NOW_GETTIMEOFDAY
+#define DUK_USE_DATE_TZO_GMTIME_R
+#define DUK_USE_DATE_PRS_STRPTIME
+#define DUK_USE_DATE_FMT_STRFTIME
+#include <TargetConditionals.h>
+#include <architecture/byte_order.h>
+#include <sys/param.h>
+#include <sys/time.h>
+#include <time.h>
+
+/* http://stackoverflow.com/questions/5919996/how-to-detect-reliably-mac-os-x-ios-linux-windows-in-c-preprocessor */
+#if TARGET_IPHONE_SIMULATOR
+#define DUK_USE_OS_STRING "iphone-sim"
+#elif TARGET_OS_IPHONE
+#define DUK_USE_OS_STRING "iphone"
+#elif TARGET_OS_MAC
+#define DUK_USE_OS_STRING "osx"
+#else
+#define DUK_USE_OS_STRING "osx-unknown"
+#endif
+
+/* Use _setjmp() on Apple by default, see GH-55. */
+#define DUK_JMPBUF_TYPE       jmp_buf
+#define DUK_SETJMP(jb)        _setjmp((jb))
+#define DUK_LONGJMP(jb)       _longjmp((jb), 1)
+#elif defined(DUK_F_OPENBSD)
+/* --- OpenBSD --- */
+/* http://www.monkey.org/openbsd/archive/ports/0401/msg00089.html */
+#define DUK_USE_DATE_NOW_GETTIMEOFDAY
+#define DUK_USE_DATE_TZO_GMTIME_R
+#define DUK_USE_DATE_PRS_STRPTIME
+#define DUK_USE_DATE_FMT_STRFTIME
+#include <sys/types.h>
+#include <sys/endian.h>
+#include <sys/param.h>
+#include <sys/time.h>
+#include <time.h>
+
+#define DUK_USE_OS_STRING  "openbsd"
+#elif defined(DUK_F_BSD)
+/* --- Generic BSD --- */
+#define DUK_USE_DATE_NOW_GETTIMEOFDAY
+#define DUK_USE_DATE_TZO_GMTIME_R
+#define DUK_USE_DATE_PRS_STRPTIME
+#define DUK_USE_DATE_FMT_STRFTIME
+#include <sys/types.h>
+#include <sys/endian.h>
+#include <sys/param.h>
+#include <sys/time.h>
+#include <time.h>
+
+#define DUK_USE_OS_STRING  "bsd"
+#elif defined(DUK_F_TOS)
+/* --- Atari ST TOS --- */
+#define DUK_USE_DATE_NOW_TIME
+#define DUK_USE_DATE_TZO_GMTIME
+/* no parsing (not an error) */
+#define DUK_USE_DATE_FMT_STRFTIME
+#include <time.h>
+
+#define DUK_USE_OS_STRING  "tos"
+
+/* TOS on M68K is always big endian. */
+#if !defined(DUK_USE_BYTEORDER) && defined(DUK_F_M68K)
+#define DUK_USE_BYTEORDER 3
+#endif
+#elif defined(DUK_F_AMIGAOS)
+/* --- AmigaOS --- */
+#if defined(DUK_F_M68K)
+/* AmigaOS on M68k */
+#define DUK_USE_DATE_NOW_TIME
+#define DUK_USE_DATE_TZO_GMTIME
+/* no parsing (not an error) */
+#define DUK_USE_DATE_FMT_STRFTIME
+#include <time.h>
+#elif defined(DUK_F_PPC)
+#define DUK_USE_DATE_NOW_GETTIMEOFDAY
+#define DUK_USE_DATE_TZO_GMTIME_R
+#define DUK_USE_DATE_PRS_STRPTIME
+#define DUK_USE_DATE_FMT_STRFTIME
+#include <time.h>
+#ifndef UINTPTR_MAX
+#define UINTPTR_MAX UINT_MAX
+#endif
+#else
+#error AmigaOS but not M68K/PPC, not supported now
+#endif
+
+#define DUK_USE_OS_STRING "amigaos"
+
+/* AmigaOS on M68K or PPC is always big endian. */
+#if !defined(DUK_USE_BYTEORDER) && (defined(DUK_F_M68K) || defined(DUK_F_PPC))
+#define DUK_USE_BYTEORDER 3
+#endif
+#elif defined(DUK_F_WINDOWS)
+/* --- Windows --- */
+/* Initial fix: disable secure CRT related warnings when compiling Duktape
+ * itself (must be defined before including Windows headers).  Don't define
+ * for user code including duktape.h.
+ */
+#if defined(DUK_COMPILING_DUKTAPE) && !defined(_CRT_SECURE_NO_WARNINGS)
+#define _CRT_SECURE_NO_WARNINGS
+#endif
+
+/* Windows 32-bit and 64-bit are currently the same. */
+/* MSVC does not have sys/param.h */
+#define DUK_USE_DATE_NOW_WINDOWS
+#define DUK_USE_DATE_TZO_WINDOWS
+/* Note: PRS and FMT are intentionally left undefined for now.  This means
+ * there is no platform specific date parsing/formatting but there is still
+ * the ISO 8601 standard format.
+ */
+#if defined(DUK_COMPILING_DUKTAPE)
+/* Only include when compiling Duktape to avoid polluting application build
+ * with a lot of unnecessary defines.
+ */
+#include <windows.h>
+#endif
+
+#define DUK_USE_OS_STRING "windows"
+
+/* On Windows, assume we're little endian.  Even Itanium which has a
+ * configurable endianness runs little endian in Windows.
+ */
+#if !defined(DUK_USE_BYTEORDER)
+#define DUK_USE_BYTEORDER 1
+#endif
+#elif defined(DUK_F_FLASHPLAYER)
+/* --- Flashplayer (Crossbridge) --- */
+#define DUK_USE_DATE_NOW_GETTIMEOFDAY
+#define DUK_USE_DATE_TZO_GMTIME_R
+#define DUK_USE_DATE_PRS_STRPTIME
+#define DUK_USE_DATE_FMT_STRFTIME
+#include <endian.h>
+#include <sys/param.h>
+#include <sys/time.h>
+#include <time.h>
+
+#define DUK_USE_OS_STRING "flashplayer"
+
+#if !defined(DUK_USE_BYTEORDER) && defined(DUK_F_FLASHPLAYER)
+#define DUK_USE_BYTEORDER 1
+#endif
+#elif defined(DUK_F_QNX)
+/* --- QNX --- */
+#if defined(DUK_F_QNX) && defined(DUK_COMPILING_DUKTAPE)
+/* See: /opt/qnx650/target/qnx6/usr/include/sys/platform.h */
+#define _XOPEN_SOURCE    600
+#define _POSIX_C_SOURCE  200112L
+#endif
+
+#define DUK_USE_DATE_NOW_GETTIMEOFDAY
+#define DUK_USE_DATE_TZO_GMTIME_R
+#define DUK_USE_DATE_PRS_STRPTIME
+#define DUK_USE_DATE_FMT_STRFTIME
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/time.h>
+#include <time.h>
+
+#define DUK_USE_OS_STRING "qnx"
+#elif defined(DUK_F_TINSPIRE)
+/* --- TI-Nspire --- */
+#define DUK_USE_DATE_NOW_GETTIMEOFDAY
+#define DUK_USE_DATE_TZO_GMTIME_R
+#define DUK_USE_DATE_PRS_STRPTIME
+#define DUK_USE_DATE_FMT_STRFTIME
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/time.h>
+#include <time.h>
+
+#define DUK_USE_OS_STRING "tinspire"
+#elif defined(DUK_F_EMSCRIPTEN)
+/* --- Emscripten --- */
+#if defined(DUK_COMPILING_DUKTAPE)
+#ifndef _POSIX_C_SOURCE
+#define _POSIX_C_SOURCE  200809L
+#endif
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE      /* e.g. getdate_r */
+#endif
+#ifndef _XOPEN_SOURCE
+#define _XOPEN_SOURCE    /* e.g. strptime */
+#endif
+#endif  /* DUK_COMPILING_DUKTAPE */
+
+#include <sys/types.h>
+#if defined(DUK_F_BCC)
+/* no endian.h */
+#else
+#include <endian.h>
+#endif  /* DUK_F_BCC */
+#include <sys/param.h>
+#include <sys/time.h>
+#include <time.h>
+#include <stdint.h>
+
+#define DUK_USE_DATE_NOW_GETTIMEOFDAY
+#define DUK_USE_DATE_TZO_GMTIME_R
+#define DUK_USE_DATE_PRS_STRPTIME
+#define DUK_USE_DATE_FMT_STRFTIME
+
+#define DUK_USE_OS_STRING "emscripten"
+#elif defined(DUK_F_LINUX)
+/* --- Linux --- */
+#if defined(DUK_COMPILING_DUKTAPE)
+#ifndef _POSIX_C_SOURCE
+#define _POSIX_C_SOURCE  200809L
+#endif
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE      /* e.g. getdate_r */
+#endif
+#ifndef _XOPEN_SOURCE
+#define _XOPEN_SOURCE    /* e.g. strptime */
+#endif
+#endif  /* DUK_COMPILING_DUKTAPE */
+
+#include <sys/types.h>
+#if defined(DUK_F_BCC)
+/* no endian.h or stdint.h */
+#else
+#include <endian.h>
+#include <stdint.h>
+#endif  /* DUK_F_BCC */
+#include <sys/param.h>
+#include <sys/time.h>
+#include <time.h>
+
+#define DUK_USE_DATE_NOW_GETTIMEOFDAY
+#define DUK_USE_DATE_TZO_GMTIME_R
+#define DUK_USE_DATE_PRS_STRPTIME
+#define DUK_USE_DATE_FMT_STRFTIME
+
+#define DUK_USE_OS_STRING "linux"
+#elif defined(DUK_F_SUN)
+/* --- Solaris --- */
+#define DUK_USE_DATE_NOW_GETTIMEOFDAY
+#define DUK_USE_DATE_TZO_GMTIME_R
+#define DUK_USE_DATE_PRS_STRPTIME
+#define DUK_USE_DATE_FMT_STRFTIME
+
+#include <sys/types.h>
+#include <ast/endian.h>
+#include <sys/param.h>
+#include <sys/time.h>
+#include <time.h>
+
+#define DUK_USE_OS_STRING "solaris"
+#elif defined(DUK_F_POSIX)
+/* --- Generic POSIX --- */
+#define DUK_USE_DATE_NOW_GETTIMEOFDAY
+#define DUK_USE_DATE_TZO_GMTIME_R
+#define DUK_USE_DATE_PRS_STRPTIME
+#define DUK_USE_DATE_FMT_STRFTIME
+#include <sys/types.h>
+#include <endian.h>
+#include <sys/param.h>
+#include <sys/time.h>
+#include <time.h>
+
+#define DUK_USE_OS_STRING "posix"
+#elif defined(DUK_F_CYGWIN)
+/* --- Cygwin --- */
+/* don't use strptime() for now */
+#define DUK_USE_DATE_NOW_GETTIMEOFDAY
+#define DUK_USE_DATE_TZO_GMTIME_R
+#define DUK_USE_DATE_FMT_STRFTIME
+#include <sys/types.h>
+#include <endian.h>
+#include <sys/param.h>
+#include <sys/time.h>
+#include <time.h>
+
+#define DUK_JMPBUF_TYPE       jmp_buf
+#define DUK_SETJMP(jb)        _setjmp((jb))
+#define DUK_LONGJMP(jb)       _longjmp((jb), 1)
+
+#define DUK_USE_OS_STRING "windows"
+#elif defined(DUK_F_UNIX)
+/* --- Generic UNIX --- */
+#define DUK_USE_DATE_NOW_GETTIMEOFDAY
+#define DUK_USE_DATE_TZO_GMTIME_R
+#define DUK_USE_DATE_PRS_STRPTIME
+#define DUK_USE_DATE_FMT_STRFTIME
+#include <time.h>
+#include <sys/time.h>
+#define DUK_USE_OS_STRING "unknown"
+#else
+/* --- Generic fallback --- */
+/* The most portable current time provider is time(), but it only has a
+ * one second resolution.
+ */
+#define DUK_USE_DATE_NOW_TIME
+
+/* The most portable way to figure out local time offset is gmtime(),
+ * but it's not thread safe so use with caution.
+ */
+#define DUK_USE_DATE_TZO_GMTIME
+
+/* Avoid custom date parsing and formatting for portability. */
+#undef DUK_USE_DATE_PRS_STRPTIME
+#undef DUK_USE_DATE_FMT_STRFTIME
+
+/* Rely on C89 headers only; time.h must be here. */
+#include <time.h>
+
+#define DUK_USE_OS_STRING "unknown"
+#endif  /* autodetect platform */
+
+/* Shared includes: C89 */
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdarg.h>  /* varargs */
+#include <setjmp.h>
+#include <stddef.h>  /* e.g. ptrdiff_t */
+#include <math.h>
+#include <limits.h>
+
+/* date.h is omitted, and included per platform */
+
+/* Shared includes: stdint.h is C99 */
+#if defined(DUK_F_NO_STDINT_H)
+/* stdint.h not available */
+#else
+/* Technically C99 (C++11) but found in many systems.  On some systems
+ * __STDC_LIMIT_MACROS and __STDC_CONSTANT_MACROS must be defined before
+ * including stdint.h (see above).
+ */
+#include <stdint.h>
+#endif
+
+#if defined(DUK_F_CPP)
+#include <exception>  /* std::exception */
+#endif
+
+/*
+ *  Architecture autodetection
+ */
+
+#if defined(DUK_F_X86)
+/* --- x86 --- */
+#define DUK_USE_ARCH_STRING "x86"
+#if !defined(DUK_USE_BYTEORDER)
+#define DUK_USE_BYTEORDER 1
+#endif
+/* XXX: This is technically not guaranteed because it's possible to configure
+ * an x86 to require aligned accesses with Alignment Check (AC) flag.
+ */
+#if !defined(DUK_USE_ALIGN_BY)
+#define DUK_USE_ALIGN_BY 1
+#endif
+#define DUK_USE_PACKED_TVAL
+#define DUK_F_PACKED_TVAL_PROVIDED
+#elif defined(DUK_F_X64)
+/* --- x64 --- */
+#define DUK_USE_ARCH_STRING "x64"
+#if !defined(DUK_USE_BYTEORDER)
+#define DUK_USE_BYTEORDER 1
+#endif
+/* XXX: This is technically not guaranteed because it's possible to configure
+ * an x86 to require aligned accesses with Alignment Check (AC) flag.
+ */
+#if !defined(DUK_USE_ALIGN_BY)
+#define DUK_USE_ALIGN_BY 1
+#endif
+#undef DUK_USE_PACKED_TVAL
+#define DUK_F_PACKED_TVAL_PROVIDED
+#elif defined(DUK_F_X32)
+/* --- x32 --- */
+#define DUK_USE_ARCH_STRING "x32"
+#if !defined(DUK_USE_BYTEORDER)
+#define DUK_USE_BYTEORDER 1
+#endif
+/* XXX: This is technically not guaranteed because it's possible to configure
+ * an x86 to require aligned accesses with Alignment Check (AC) flag.
+ */
+#if !defined(DUK_USE_ALIGN_BY)
+#define DUK_USE_ALIGN_BY 1
+#endif
+#define DUK_USE_PACKED_TVAL
+#define DUK_F_PACKED_TVAL_PROVIDED
+#elif defined(DUK_F_ARM32)
+/* --- ARM 32-bit --- */
+#define DUK_USE_ARCH_STRING "arm32"
+/* Byte order varies, so rely on autodetect. */
+#if !defined(DUK_USE_ALIGN_BY)
+#define DUK_USE_ALIGN_BY 4
+#endif
+#define DUK_USE_PACKED_TVAL
+#define DUK_F_PACKED_TVAL_PROVIDED
+#elif defined(DUK_F_ARM64)
+/* --- ARM 64-bit --- */
+#define DUK_USE_ARCH_STRING "arm64"
+/* Byte order varies, so rely on autodetect. */
+#if !defined(DUK_USE_ALIGN_BY)
+#define DUK_USE_ALIGN_BY 8
+#endif
+#undef DUK_USE_PACKED_TVAL
+#define DUK_F_PACKED_TVAL_PROVIDED
+#elif defined(DUK_F_MIPS32)
+/* --- MIPS 32-bit --- */
+#define DUK_USE_ARCH_STRING "mips32"
+/* MIPS byte order varies so rely on autodetection. */
+/* Based on 'make checkalign' there are no alignment requirements on
+ * Linux MIPS except for doubles, which need align by 4.  Alignment
+ * requirements vary based on target though.
+ */
+#if !defined(DUK_USE_ALIGN_BY)
+#define DUK_USE_ALIGN_BY 4
+#endif
+#define DUK_USE_PACKED_TVAL
+#define DUK_F_PACKED_TVAL_PROVIDED
+#elif defined(DUK_F_MIPS64)
+/* --- MIPS 64-bit --- */
+#define DUK_USE_ARCH_STRING "mips64"
+/* MIPS byte order varies so rely on autodetection. */
+/* Good default is a bit arbitrary because alignment requirements
+ * depend on target.  See https://github.com/svaarala/duktape/issues/102.
+ */
+#if !defined(DUK_USE_ALIGN_BY)
+#define DUK_USE_ALIGN_BY 8
+#endif
+#undef DUK_USE_PACKED_TVAL
+#define DUK_F_PACKED_TVAL_PROVIDED
+#elif defined(DUK_F_PPC32)
+/* --- PowerPC 32-bit --- */
+#define DUK_USE_ARCH_STRING "ppc32"
+#if !defined(DUK_USE_BYTEORDER)
+#define DUK_USE_BYTEORDER 3
+#endif
+#if !defined(DUK_USE_ALIGN_BY)
+#define DUK_USE_ALIGN_BY 8
+#endif
+#define DUK_USE_PACKED_TVAL
+#define DUK_F_PACKED_TVAL_PROVIDED
+#elif defined(DUK_F_PPC64)
+/* --- PowerPC 64-bit --- */
+#define DUK_USE_ARCH_STRING "ppc64"
+#if !defined(DUK_USE_BYTEORDER)
+#define DUK_USE_BYTEORDER 3
+#endif
+#if !defined(DUK_USE_ALIGN_BY)
+#define DUK_USE_ALIGN_BY 8
+#endif
+#undef DUK_USE_PACKED_TVAL
+#define DUK_F_PACKED_TVAL_PROVIDED
+#elif defined(DUK_F_SPARC32)
+/* --- SPARC 32-bit --- */
+#define DUK_USE_ARCH_STRING "sparc32"
+/* SPARC byte order varies so rely on autodetection. */
+#if !defined(DUK_USE_ALIGN_BY)
+#define DUK_USE_ALIGN_BY 8
+#endif
+#define DUK_USE_PACKED_TVAL
+#define DUK_F_PACKED_TVAL_PROVIDED
+#elif defined(DUK_F_SPARC64)
+/* --- SPARC 64-bit --- */
+#define DUK_USE_ARCH_STRING "sparc64"
+/* SPARC byte order varies so rely on autodetection. */
+#if !defined(DUK_USE_ALIGN_BY)
+#define DUK_USE_ALIGN_BY 8
+#endif
+#undef DUK_USE_PACKED_TVAL
+#define DUK_F_PACKED_TVAL_PROVIDED
+#elif defined(DUK_F_SUPERH)
+/* --- SuperH --- */
+#define DUK_USE_ARCH_STRING "sh"
+/* Byte order varies, rely on autodetection. */
+/* Based on 'make checkalign' there are no alignment requirements on
+ * Linux SH4, but align by 4 is probably a good basic default.
+ */
+#if !defined(DUK_USE_ALIGN_BY)
+#define DUK_USE_ALIGN_BY 4
+#endif
+#define DUK_USE_PACKED_TVAL
+#define DUK_F_PACKED_TVAL_PROVIDED
+#elif defined(DUK_F_M68K)
+/* --- Motorola 68k --- */
+#define DUK_USE_ARCH_STRING "m68k"
+#if !defined(DUK_USE_BYTEORDER)
+#define DUK_USE_BYTEORDER 3
+#endif
+#if !defined(DUK_USE_ALIGN_BY)
+#define DUK_USE_ALIGN_BY 8
+#endif
+#define DUK_USE_PACKED_TVAL
+#define DUK_F_PACKED_TVAL_PROVIDED
+#elif defined(DUK_F_EMSCRIPTEN)
+/* --- Emscripten --- */
+#define DUK_USE_ARCH_STRING "emscripten"
+#if !defined(DUK_USE_BYTEORDER)
+#define DUK_USE_BYTEORDER 1
+#endif
+#if !defined(DUK_USE_ALIGN_BY)
+#define DUK_USE_ALIGN_BY 8
+#endif
+#undef DUK_USE_PACKED_TVAL
+#define DUK_F_PACKED_TVAL_PROVIDED
+#else
+/* --- Generic --- */
+/* These are necessary wild guesses. */
+#define DUK_USE_ARCH_STRING "generic"
+/* Rely on autodetection for byte order, alignment, and packed tval. */
+#endif  /* autodetect architecture */
+
+/*
+ *  Compiler autodetection
+ */
+
+#if defined(DUK_F_CLANG)
+/* --- Clang --- */
+#if defined(DUK_F_C99) || defined(DUK_F_CPP11)
+/* C99 / C++11 and above: rely on va_copy() which is required. */
+#define DUK_VA_COPY(dest,src) va_copy(dest,src)
+#else
+/* Clang: assume we have __va_copy() in non-C99 mode. */
+#define DUK_VA_COPY(dest,src) __va_copy(dest,src)
+#endif
+
+#define DUK_NORETURN(decl)  decl __attribute__((noreturn))
+
+#if defined(__clang__) && defined(__has_builtin)
+#if __has_builtin(__builtin_unreachable)
+#define DUK_UNREACHABLE()  do { __builtin_unreachable(); } while (0)
+#endif
+#endif
+
+#define DUK_USE_BRANCH_HINTS
+#define DUK_LIKELY(x)    __builtin_expect((x), 1)
+#define DUK_UNLIKELY(x)  __builtin_expect((x), 0)
+
+#if defined(DUK_F_C99) || defined(DUK_F_CPP11)
+#define DUK_NOINLINE        __attribute__((noinline))
+#define DUK_INLINE          inline
+#define DUK_ALWAYS_INLINE   inline __attribute__((always_inline))
+#endif
+
+#if defined(DUK_F_DLL_BUILD) && defined(DUK_F_WINDOWS)
+/* MSVC dllexport/dllimport: appropriate __declspec depends on whether we're
+ * compiling Duktape or the application.
+ */
+#if defined(DUK_COMPILING_DUKTAPE)
+#define DUK_EXTERNAL_DECL  extern __declspec(dllexport)
+#define DUK_EXTERNAL       __declspec(dllexport)
+#else
+#define DUK_EXTERNAL_DECL  extern __declspec(dllimport)
+#define DUK_EXTERNAL       should_not_happen
+#endif
+#if defined(DUK_SINGLE_FILE)
+#define DUK_INTERNAL_DECL  static
+#define DUK_INTERNAL       static
+#else
+#define DUK_INTERNAL_DECL  extern
+#define DUK_INTERNAL       /*empty*/
+#endif
+#define DUK_LOCAL_DECL     static
+#define DUK_LOCAL          static
+#else
+#define DUK_EXTERNAL_DECL  __attribute__ ((visibility("default"))) extern
+#define DUK_EXTERNAL       __attribute__ ((visibility("default")))
+#if defined(DUK_SINGLE_FILE)
+#if (defined(DUK_F_GCC_VERSION) && DUK_F_GCC_VERSION >= 30101) || defined(DUK_F_CLANG)
+/* Minimize warnings for unused internal functions with GCC >= 3.1.1 and
+ * Clang.  Based on documentation it should suffice to have the attribute
+ * in the declaration only, but in practice some warnings are generated unless
+ * the attribute is also applied to the definition.
+ */
+#define DUK_INTERNAL_DECL  static __attribute__ ((unused))
+#define DUK_INTERNAL       static __attribute__ ((unused))
+#else
+#define DUK_INTERNAL_DECL  static
+#define DUK_INTERNAL       static
+#endif
+#else
+#if (defined(DUK_F_GCC_VERSION) && DUK_F_GCC_VERSION >= 30101) || defined(DUK_F_CLANG)
+#define DUK_INTERNAL_DECL  __attribute__ ((visibility("hidden"))) __attribute__ ((unused)) extern
+#define DUK_INTERNAL       __attribute__ ((visibility("hidden"))) __attribute__ ((unused))
+#else
+#define DUK_INTERNAL_DECL  __attribute__ ((visibility("hidden"))) extern
+#define DUK_INTERNAL       __attribute__ ((visibility("hidden")))
+#endif
+#endif
+#define DUK_LOCAL_DECL     static
+#define DUK_LOCAL          static
+#endif
+
+#if defined(DUK_F_CPP)
+#define DUK_USE_COMPILER_STRING "clang"
+#else
+#define DUK_USE_COMPILER_STRING "clang"
+#endif
+
+#undef DUK_USE_VARIADIC_MACROS
+#if defined(DUK_F_C99) || defined(DUK_F_CPP11)
+#define DUK_USE_VARIADIC_MACROS
+#endif
+
+#define DUK_USE_UNION_INITIALIZERS
+
+#undef DUK_USE_FLEX_C99
+#undef DUK_USE_FLEX_ZEROSIZE
+#undef DUK_USE_FLEX_ONESIZE
+#if defined(DUK_F_C99)
+#define DUK_USE_FLEX_C99
+#else
+#define DUK_USE_FLEX_ZEROSIZE
+#endif
+
+#undef DUK_USE_GCC_PRAGMAS
+#define DUK_USE_PACK_CLANG_ATTR
+#elif defined(DUK_F_GCC)
+/* --- GCC --- */
+#if defined(DUK_F_C99) || defined(DUK_F_CPP11)
+/* C99 / C++11 and above: rely on va_copy() which is required. */
+#define DUK_VA_COPY(dest,src) va_copy(dest,src)
+#else
+/* GCC: assume we have __va_copy() in non-C99 mode. */
+#define DUK_VA_COPY(dest,src) __va_copy(dest,src)
+#endif
+
+#if defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION >= 20500L)
+/* since gcc-2.5 */
+#define DUK_NORETURN(decl)  decl __attribute__((noreturn))
+#endif
+
+#if defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION >= 40500L)
+/* since gcc-4.5 */
+#define DUK_UNREACHABLE()  do { __builtin_unreachable(); } while (0)
+#endif
+
+#define DUK_USE_BRANCH_HINTS
+#if defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION >= 40500L)
+/* GCC: test not very accurate; enable only in relatively recent builds
+ * because of bugs in gcc-4.4 (http://lists.debian.org/debian-gcc/2010/04/msg00000.html)
+ */
+#define DUK_LIKELY(x)    __builtin_expect((x), 1)
+#define DUK_UNLIKELY(x)  __builtin_expect((x), 0)
+#endif
+
+#if (defined(DUK_F_C99) || defined(DUK_F_CPP11)) && \
+    defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION >= 30101)
+#define DUK_NOINLINE        __attribute__((noinline))
+#define DUK_INLINE          inline
+#define DUK_ALWAYS_INLINE   inline __attribute__((always_inline))
+#endif
+
+#if defined(DUK_F_DLL_BUILD) && defined(DUK_F_WINDOWS)
+/* MSVC dllexport/dllimport: appropriate __declspec depends on whether we're
+ * compiling Duktape or the application.
+ */
+#if defined(DUK_COMPILING_DUKTAPE)
+#define DUK_EXTERNAL_DECL  extern __declspec(dllexport)
+#define DUK_EXTERNAL       __declspec(dllexport)
+#else
+#define DUK_EXTERNAL_DECL  extern __declspec(dllimport)
+#define DUK_EXTERNAL       should_not_happen
+#endif
+#if defined(DUK_SINGLE_FILE)
+#define DUK_INTERNAL_DECL  static
+#define DUK_INTERNAL       static
+#else
+#define DUK_INTERNAL_DECL  extern
+#define DUK_INTERNAL       /*empty*/
+#endif
+#define DUK_LOCAL_DECL     static
+#define DUK_LOCAL          static
+#elif defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION >= 40000)
+#define DUK_EXTERNAL_DECL  __attribute__ ((visibility("default"))) extern
+#define DUK_EXTERNAL       __attribute__ ((visibility("default")))
+#if defined(DUK_SINGLE_FILE)
+#if (defined(DUK_F_GCC_VERSION) && DUK_F_GCC_VERSION >= 30101) || defined(DUK_F_CLANG)
+/* Minimize warnings for unused internal functions with GCC >= 3.1.1 and
+ * Clang.  Based on documentation it should suffice to have the attribute
+ * in the declaration only, but in practice some warnings are generated unless
+ * the attribute is also applied to the definition.
+ */
+#define DUK_INTERNAL_DECL  static __attribute__ ((unused))
+#define DUK_INTERNAL       static __attribute__ ((unused))
+#else
+#define DUK_INTERNAL_DECL  static
+#define DUK_INTERNAL       static
+#endif
+#else
+#if (defined(DUK_F_GCC_VERSION) && DUK_F_GCC_VERSION >= 30101) || defined(DUK_F_CLANG)
+#define DUK_INTERNAL_DECL  __attribute__ ((visibility("hidden"))) __attribute__ ((unused)) extern
+#define DUK_INTERNAL       __attribute__ ((visibility("hidden"))) __attribute__ ((unused))
+#else
+#define DUK_INTERNAL_DECL  __attribute__ ((visibility("hidden"))) extern
+#define DUK_INTERNAL       __attribute__ ((visibility("hidden")))
+#endif
+#endif
+#define DUK_LOCAL_DECL     static
+#define DUK_LOCAL          static
+#endif
+
+#if defined(DUK_F_MINGW)
+#if defined(DUK_F_CPP)
+#define DUK_USE_COMPILER_STRING "mingw++"
+#else
+#define DUK_USE_COMPILER_STRING "mingw"
+#endif
+#else
+#if defined(DUK_F_CPP)
+#define DUK_USE_COMPILER_STRING "g++"
+#else
+#define DUK_USE_COMPILER_STRING "gcc"
+#endif
+#endif
+
+#undef DUK_USE_VARIADIC_MACROS
+#if defined(DUK_F_C99) || (defined(DUK_F_CPP11) && defined(__GNUC__))
+#define DUK_USE_VARIADIC_MACROS
+#endif
+
+#define DUK_USE_UNION_INITIALIZERS
+
+#undef DUK_USE_FLEX_C99
+#undef DUK_USE_FLEX_ZEROSIZE
+#undef DUK_USE_FLEX_ONESIZE
+#if defined(DUK_F_C99)
+#define DUK_USE_FLEX_C99
+#else
+#define DUK_USE_FLEX_ZEROSIZE
+#endif
+
+#if defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION >= 40600)
+#define DUK_USE_GCC_PRAGMAS
+#else
+#undef DUK_USE_GCC_PRAGMAS
+#endif
+
+#define DUK_USE_PACK_GCC_ATTR
+#elif defined(DUK_F_MSVC)
+/* --- MSVC --- */
+/* http://msdn.microsoft.com/en-us/library/aa235362(VS.60).aspx */
+#define DUK_NORETURN(decl)  __declspec(noreturn) decl
+
+/* XXX: DUK_UNREACHABLE for msvc? */
+
+#undef DUK_USE_BRANCH_HINTS
+
+/* XXX: DUK_LIKELY, DUK_UNLIKELY for msvc? */
+/* XXX: DUK_NOINLINE, DUK_INLINE, DUK_ALWAYS_INLINE for msvc? */
+
+#if defined(DUK_F_DLL_BUILD) && defined(DUK_F_WINDOWS)
+/* MSVC dllexport/dllimport: appropriate __declspec depends on whether we're
+ * compiling Duktape or the application.
+ */
+#if defined(DUK_COMPILING_DUKTAPE)
+#define DUK_EXTERNAL_DECL  extern __declspec(dllexport)
+#define DUK_EXTERNAL       __declspec(dllexport)
+#else
+#define DUK_EXTERNAL_DECL  extern __declspec(dllimport)
+#define DUK_EXTERNAL       should_not_happen
+#endif
+#if defined(DUK_SINGLE_FILE)
+#define DUK_INTERNAL_DECL  static
+#define DUK_INTERNAL       static
+#else
+#define DUK_INTERNAL_DECL  extern
+#define DUK_INTERNAL       /*empty*/
+#endif
+#define DUK_LOCAL_DECL     static
+#define DUK_LOCAL          static
+#endif
+
+#if defined(DUK_F_CPP)
+#define DUK_USE_COMPILER_STRING "msvc++"
+#else
+#define DUK_USE_COMPILER_STRING "msvc"
+#endif
+
+#undef DUK_USE_VARIADIC_MACROS
+#if defined(DUK_F_C99)
+#define DUK_USE_VARIADIC_MACROS
+#elif defined(_MSC_VER) && (_MSC_VER >= 1400)
+/* VS2005+ should have variadic macros even when they're not C99. */
+#define DUK_USE_VARIADIC_MACROS
+#endif
+
+#undef DUK_USE_UNION_INITIALIZERS
+#if defined(_MSC_VER) && (_MSC_VER >= 1800)
+/* VS2013+ supports union initializers but there's a bug involving union-inside-struct:
+ * https://connect.microsoft.com/VisualStudio/feedback/details/805981
+ * The bug was fixed (at least) in VS2015 so check for VS2015 for now:
+ * https://blogs.msdn.microsoft.com/vcblog/2015/07/01/c-compiler-front-end-fixes-in-vs2015/
+ * Manually tested using VS2013, CL reports 18.00.31101, so enable for VS2013 too.
+ */
+#define DUK_USE_UNION_INITIALIZERS
+#endif
+
+#undef DUK_USE_FLEX_C99
+#undef DUK_USE_FLEX_ZEROSIZE
+#undef DUK_USE_FLEX_ONESIZE
+#if defined(DUK_F_C99)
+#define DUK_USE_FLEX_C99
+#else
+#define DUK_USE_FLEX_ZEROSIZE
+#endif
+
+#undef DUK_USE_GCC_PRAGMAS
+
+#define DUK_USE_PACK_MSVC_PRAGMA
+
+/* These have been tested from VS2008 onwards; may work in older VS versions
+ * too but not enabled by default.
+ */
+#if defined(_MSC_VER) && (_MSC_VER >= 1500)
+#define DUK_NOINLINE        __declspec(noinline)
+#define DUK_INLINE          __inline
+#define DUK_ALWAYS_INLINE   __forceinline
+#endif
+
+#if defined(_MSC_VER) && (_MSC_VER >= 1900)
+#define DUK_SNPRINTF     snprintf
+#define DUK_VSNPRINTF    vsnprintf
+#else
+/* (v)snprintf() is missing before MSVC 2015.  Note that _(v)snprintf() does
+ * NOT NUL terminate on truncation, but Duktape code never assumes that.
+ * http://stackoverflow.com/questions/2915672/snprintf-and-visual-studio-2010
+ */
+#define DUK_SNPRINTF     _snprintf
+#define DUK_VSNPRINTF    _vsnprintf
+#endif
+#elif defined(DUK_F_EMSCRIPTEN)
+/* --- Emscripten --- */
+#define DUK_NORETURN(decl)  decl __attribute__((noreturn))
+
+#if defined(__clang__) && defined(__has_builtin)
+#if __has_builtin(__builtin_unreachable)
+#define DUK_UNREACHABLE()  do { __builtin_unreachable(); } while (0)
+#endif
+#endif
+
+#define DUK_USE_BRANCH_HINTS
+#define DUK_LIKELY(x)    __builtin_expect((x), 1)
+#define DUK_UNLIKELY(x)  __builtin_expect((x), 0)
+
+#if defined(DUK_F_C99) || defined(DUK_F_CPP11)
+#define DUK_NOINLINE        __attribute__((noinline))
+#define DUK_INLINE          inline
+#define DUK_ALWAYS_INLINE   inline __attribute__((always_inline))
+#endif
+
+#define DUK_EXTERNAL_DECL  __attribute__ ((visibility("default"))) extern
+#define DUK_EXTERNAL       __attribute__ ((visibility("default")))
+#if defined(DUK_SINGLE_FILE)
+#if (defined(DUK_F_GCC_VERSION) && DUK_F_GCC_VERSION >= 30101) || defined(DUK_F_CLANG)
+/* Minimize warnings for unused internal functions with GCC >= 3.1.1 and
+ * Clang.  Based on documentation it should suffice to have the attribute
+ * in the declaration only, but in practice some warnings are generated unless
+ * the attribute is also applied to the definition.
+ */
+#define DUK_INTERNAL_DECL  static __attribute__ ((unused))
+#define DUK_INTERNAL       static __attribute__ ((unused))
+#else
+#define DUK_INTERNAL_DECL  static
+#define DUK_INTERNAL       static
+#endif
+#else
+#if (defined(DUK_F_GCC_VERSION) && DUK_F_GCC_VERSION >= 30101) || defined(DUK_F_CLANG)
+#define DUK_INTERNAL_DECL  __attribute__ ((visibility("hidden"))) __attribute__ ((unused)) extern
+#define DUK_INTERNAL       __attribute__ ((visibility("hidden"))) __attribute__ ((unused))
+#else
+#define DUK_INTERNAL_DECL  __attribute__ ((visibility("hidden"))) extern
+#define DUK_INTERNAL       __attribute__ ((visibility("hidden")))
+#endif
+#endif
+#define DUK_LOCAL_DECL     static
+#define DUK_LOCAL          static
+
+#define DUK_USE_COMPILER_STRING "emscripten"
+
+#undef DUK_USE_VARIADIC_MACROS
+#if defined(DUK_F_C99) || defined(DUK_F_CPP11)
+#define DUK_USE_VARIADIC_MACROS
+#endif
+
+#define DUK_USE_UNION_INITIALIZERS
+
+#undef DUK_USE_FLEX_C99
+#undef DUK_USE_FLEX_ZEROSIZE
+#undef DUK_USE_FLEX_ONESIZE
+#if defined(DUK_F_C99)
+#define DUK_USE_FLEX_C99
+#else
+#define DUK_USE_FLEX_ZEROSIZE
+#endif
+
+#undef DUK_USE_GCC_PRAGMAS
+#define DUK_USE_PACK_CLANG_ATTR
+#elif defined(DUK_F_TINYC)
+/* --- TinyC --- */
+#undef DUK_USE_BRANCH_HINTS
+
+#if defined(DUK_F_CPP)
+#define DUK_USE_COMPILER_STRING "tinyc++"
+#else
+#define DUK_USE_COMPILER_STRING "tinyc"
+#endif
+
+/* http://bellard.org/tcc/tcc-doc.html#SEC7 */
+#define DUK_USE_VARIADIC_MACROS
+
+#define DUK_USE_UNION_INITIALIZERS
+
+/* Most portable, wastes space */
+#define DUK_USE_FLEX_ONESIZE
+
+/* Most portable, potentially wastes space */
+#define DUK_USE_PACK_DUMMY_MEMBER
+#elif defined(DUK_F_VBCC)
+/* --- VBCC --- */
+#undef DUK_USE_BRANCH_HINTS
+
+#if defined(DUK_F_CPP)
+#define DUK_USE_COMPILER_STRING "vbcc-c++"
+#else
+#define DUK_USE_COMPILER_STRING "vbcc"
+#endif
+
+#undef DUK_USE_VARIADIC_MACROS
+#if defined(DUK_F_C99) || defined(DUK_F_CPP11)
+#define DUK_USE_VARIADIC_MACROS
+#endif
+
+/* VBCC supports C99 so check only for C99 for union initializer support.
+ * Designated union initializers would possibly work even without a C99 check.
+ */
+#undef DUK_USE_UNION_INITIALIZERS
+#if defined(DUK_F_C99)
+#define DUK_USE_UNION_INITIALIZERS
+#endif
+
+#define DUK_USE_FLEX_ZEROSIZE
+#define DUK_USE_PACK_DUMMY_MEMBER
+#elif defined(DUK_F_BCC)
+/* --- Bruce's C compiler --- */
+#undef DUK_USE_BRANCH_HINTS
+
+#if defined(DUK_F_CPP)
+#define DUK_USE_COMPILER_STRING "bcc++"
+#else
+#define DUK_USE_COMPILER_STRING "bcc"
+#endif
+
+/* Most portable */
+#undef DUK_USE_VARIADIC_MACROS
+
+/* Most portable, wastes space */
+#undef DUK_USE_UNION_INITIALIZERS
+
+/* Most portable, wastes space */
+#define DUK_USE_FLEX_ONESIZE
+
+/* Most portable, potentially wastes space */
+#define DUK_USE_PACK_DUMMY_MEMBER
+
+/* BCC, assume we're on x86. */
+#if !defined(DUK_USE_BYTEORDER)
+#define DUK_USE_BYTEORDER 1
+#endif
+#else
+/* --- Generic --- */
+#undef DUK_USE_BRANCH_HINTS
+
+#if defined(DUK_F_CPP)
+#define DUK_USE_COMPILER_STRING "generic-c++"
+#else
+#define DUK_USE_COMPILER_STRING "generic"
+#endif
+
+#undef DUK_USE_VARIADIC_MACROS
+#if defined(DUK_F_C99) || defined(DUK_F_CPP11)
+#define DUK_USE_VARIADIC_MACROS
+#endif
+
+/* C++ doesn't have standard designated union initializers ({ .foo = 1 }). */
+#undef DUK_USE_UNION_INITIALIZERS
+#if defined(DUK_F_C99)
+#define DUK_USE_UNION_INITIALIZERS
+#endif
+
+/* Most portable, wastes space */
+#define DUK_USE_FLEX_ONESIZE
+
+/* Most portable, potentially wastes space */
+#define DUK_USE_PACK_DUMMY_MEMBER
+#endif  /* autodetect compiler */
+
+/* uclibc */
+#if defined(__UCLIBC__)
+#define DUK_F_UCLIBC
+#endif
+
+/*
+ *  Wrapper typedefs and constants for integer types, also sanity check types.
+ *
+ *  C99 typedefs are quite good but not always available, and we want to avoid
+ *  forcibly redefining the C99 typedefs.  So, there are Duktape wrappers for
+ *  all C99 typedefs and Duktape code should only use these typedefs.  Type
+ *  detection when C99 is not supported is best effort and may end up detecting
+ *  some types incorrectly.
+ *
+ *  Pointer sizes are a portability problem: pointers to different types may
+ *  have a different size and function pointers are very difficult to manage
+ *  portably.
+ *
+ *  http://en.wikipedia.org/wiki/C_data_types#Fixed-width_integer_types
+ *
+ *  Note: there's an interesting corner case when trying to define minimum
+ *  signed integer value constants which leads to the current workaround of
+ *  defining e.g. -0x80000000 as (-0x7fffffffL - 1L).  See doc/code-issues.txt
+ *  for a longer discussion.
+ *
+ *  Note: avoid typecasts and computations in macro integer constants as they
+ *  can then no longer be used in macro relational expressions (such as
+ *  #if DUK_SIZE_MAX < 0xffffffffUL).  There is internal code which relies on
+ *  being able to compare DUK_SIZE_MAX against a limit.
+ */
+
+/* XXX: add feature options to force basic types from outside? */
+
+#if !defined(INT_MAX)
+#error INT_MAX not defined
+#endif
+
+/* Check that architecture is two's complement, standard C allows e.g.
+ * INT_MIN to be -2**31+1 (instead of -2**31).
+ */
+#if defined(INT_MAX) && defined(INT_MIN)
+#if INT_MAX != -(INT_MIN + 1)
+#error platform does not seem complement of two
+#endif
+#else
+#error cannot check complement of two
+#endif
+
+/* Pointer size determination based on __WORDSIZE or architecture when
+ * that's not available.
+ */
+#if defined(DUK_F_X86) || defined(DUK_F_X32) || \
+    defined(DUK_F_M68K) || defined(DUK_F_PPC32) || \
+    defined(DUK_F_BCC) || \
+    (defined(__WORDSIZE) && (__WORDSIZE == 32))
+#define DUK_F_32BIT_PTRS
+#elif defined(DUK_F_X64) || \
+      (defined(__WORDSIZE) && (__WORDSIZE == 64))
+#define DUK_F_64BIT_PTRS
+#else
+/* not sure, not needed with C99 anyway */
+#endif
+
+/* Intermediate define for 'have inttypes.h' */
+#undef DUK_F_HAVE_INTTYPES
+#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && \
+    !(defined(DUK_F_AMIGAOS) && defined(DUK_F_VBCC))
+/* vbcc + AmigaOS has C99 but no inttypes.h */
+#define DUK_F_HAVE_INTTYPES
+#elif defined(__cplusplus) && (__cplusplus >= 201103L)
+/* C++11 apparently ratified stdint.h */
+#define DUK_F_HAVE_INTTYPES
+#endif
+
+/* Basic integer typedefs and limits, preferably from inttypes.h, otherwise
+ * through automatic detection.
+ */
+#if defined(DUK_F_HAVE_INTTYPES)
+/* C99 or compatible */
+
+#define DUK_F_HAVE_64BIT
+#include <inttypes.h>
+
+typedef uint8_t duk_uint8_t;
+typedef int8_t duk_int8_t;
+typedef uint16_t duk_uint16_t;
+typedef int16_t duk_int16_t;
+typedef uint32_t duk_uint32_t;
+typedef int32_t duk_int32_t;
+typedef uint64_t duk_uint64_t;
+typedef int64_t duk_int64_t;
+typedef uint_least8_t duk_uint_least8_t;
+typedef int_least8_t duk_int_least8_t;
+typedef uint_least16_t duk_uint_least16_t;
+typedef int_least16_t duk_int_least16_t;
+typedef uint_least32_t duk_uint_least32_t;
+typedef int_least32_t duk_int_least32_t;
+typedef uint_least64_t duk_uint_least64_t;
+typedef int_least64_t duk_int_least64_t;
+typedef uint_fast8_t duk_uint_fast8_t;
+typedef int_fast8_t duk_int_fast8_t;
+typedef uint_fast16_t duk_uint_fast16_t;
+typedef int_fast16_t duk_int_fast16_t;
+typedef uint_fast32_t duk_uint_fast32_t;
+typedef int_fast32_t duk_int_fast32_t;
+typedef uint_fast64_t duk_uint_fast64_t;
+typedef int_fast64_t duk_int_fast64_t;
+typedef uintptr_t duk_uintptr_t;
+typedef intptr_t duk_intptr_t;
+typedef uintmax_t duk_uintmax_t;
+typedef intmax_t duk_intmax_t;
+
+#define DUK_UINT8_MIN         0
+#define DUK_UINT8_MAX         UINT8_MAX
+#define DUK_INT8_MIN          INT8_MIN
+#define DUK_INT8_MAX          INT8_MAX
+#define DUK_UINT_LEAST8_MIN   0
+#define DUK_UINT_LEAST8_MAX   UINT_LEAST8_MAX
+#define DUK_INT_LEAST8_MIN    INT_LEAST8_MIN
+#define DUK_INT_LEAST8_MAX    INT_LEAST8_MAX
+#define DUK_UINT_FAST8_MIN    0
+#define DUK_UINT_FAST8_MAX    UINT_FAST8_MAX
+#define DUK_INT_FAST8_MIN     INT_FAST8_MIN
+#define DUK_INT_FAST8_MAX     INT_FAST8_MAX
+#define DUK_UINT16_MIN        0
+#define DUK_UINT16_MAX        UINT16_MAX
+#define DUK_INT16_MIN         INT16_MIN
+#define DUK_INT16_MAX         INT16_MAX
+#define DUK_UINT_LEAST16_MIN  0
+#define DUK_UINT_LEAST16_MAX  UINT_LEAST16_MAX
+#define DUK_INT_LEAST16_MIN   INT_LEAST16_MIN
+#define DUK_INT_LEAST16_MAX   INT_LEAST16_MAX
+#define DUK_UINT_FAST16_MIN   0
+#define DUK_UINT_FAST16_MAX   UINT_FAST16_MAX
+#define DUK_INT_FAST16_MIN    INT_FAST16_MIN
+#define DUK_INT_FAST16_MAX    INT_FAST16_MAX
+#define DUK_UINT32_MIN        0
+#define DUK_UINT32_MAX        UINT32_MAX
+#define DUK_INT32_MIN         INT32_MIN
+#define DUK_INT32_MAX         INT32_MAX
+#define DUK_UINT_LEAST32_MIN  0
+#define DUK_UINT_LEAST32_MAX  UINT_LEAST32_MAX
+#define DUK_INT_LEAST32_MIN   INT_LEAST32_MIN
+#define DUK_INT_LEAST32_MAX   INT_LEAST32_MAX
+#define DUK_UINT_FAST32_MIN   0
+#define DUK_UINT_FAST32_MAX   UINT_FAST32_MAX
+#define DUK_INT_FAST32_MIN    INT_FAST32_MIN
+#define DUK_INT_FAST32_MAX    INT_FAST32_MAX
+#define DUK_UINT64_MIN        0
+#define DUK_UINT64_MAX        UINT64_MAX
+#define DUK_INT64_MIN         INT64_MIN
+#define DUK_INT64_MAX         INT64_MAX
+#define DUK_UINT_LEAST64_MIN  0
+#define DUK_UINT_LEAST64_MAX  UINT_LEAST64_MAX
+#define DUK_INT_LEAST64_MIN   INT_LEAST64_MIN
+#define DUK_INT_LEAST64_MAX   INT_LEAST64_MAX
+#define DUK_UINT_FAST64_MIN   0
+#define DUK_UINT_FAST64_MAX   UINT_FAST64_MAX
+#define DUK_INT_FAST64_MIN    INT_FAST64_MIN
+#define DUK_INT_FAST64_MAX    INT_FAST64_MAX
+
+#define DUK_UINTPTR_MIN       0
+#define DUK_UINTPTR_MAX       UINTPTR_MAX
+#define DUK_INTPTR_MIN        INTPTR_MIN
+#define DUK_INTPTR_MAX        INTPTR_MAX
+
+#define DUK_UINTMAX_MIN       0
+#define DUK_UINTMAX_MAX       UINTMAX_MAX
+#define DUK_INTMAX_MIN        INTMAX_MIN
+#define DUK_INTMAX_MAX        INTMAX_MAX
+
+#define DUK_SIZE_MIN          0
+#define DUK_SIZE_MAX          SIZE_MAX
+#undef DUK_SIZE_MAX_COMPUTED
+
+#else  /* C99 types */
+
+/* When C99 types are not available, we use heuristic detection to get
+ * the basic 8, 16, 32, and (possibly) 64 bit types.  The fast/least
+ * types are then assumed to be exactly the same for now: these could
+ * be improved per platform but C99 types are very often now available.
+ * 64-bit types are not available on all platforms; this is OK at least
+ * on 32-bit platforms.
+ *
+ * This detection code is necessarily a bit hacky and can provide typedefs
+ * and defines that won't work correctly on some exotic platform.
+ */
+
+#if (defined(CHAR_BIT) && (CHAR_BIT == 8)) || \
+    (defined(UCHAR_MAX) && (UCHAR_MAX == 255))
+typedef unsigned char duk_uint8_t;
+typedef signed char duk_int8_t;
+#else
+#error cannot detect 8-bit type
+#endif
+
+#if defined(USHRT_MAX) && (USHRT_MAX == 65535UL)
+typedef unsigned short duk_uint16_t;
+typedef signed short duk_int16_t;
+#elif defined(UINT_MAX) && (UINT_MAX == 65535UL)
+/* On some platforms int is 16-bit but long is 32-bit (e.g. PureC) */
+typedef unsigned int duk_uint16_t;
+typedef signed int duk_int16_t;
+#else
+#error cannot detect 16-bit type
+#endif
+
+#if defined(UINT_MAX) && (UINT_MAX == 4294967295UL)
+typedef unsigned int duk_uint32_t;
+typedef signed int duk_int32_t;
+#elif defined(ULONG_MAX) && (ULONG_MAX == 4294967295UL)
+/* On some platforms int is 16-bit but long is 32-bit (e.g. PureC) */
+typedef unsigned long duk_uint32_t;
+typedef signed long duk_int32_t;
+#else
+#error cannot detect 32-bit type
+#endif
+
+/* 64-bit type detection is a bit tricky.
+ *
+ * ULLONG_MAX is a standard define.  __LONG_LONG_MAX__ and __ULONG_LONG_MAX__
+ * are used by at least GCC (even if system headers don't provide ULLONG_MAX).
+ * Some GCC variants may provide __LONG_LONG_MAX__ but not __ULONG_LONG_MAX__.
+ *
+ * ULL / LL constants are rejected / warned about by some compilers, even if
+ * the compiler has a 64-bit type and the compiler/system headers provide an
+ * unsupported constant (ULL/LL)!  Try to avoid using ULL / LL constants.
+ * As a side effect we can only check that e.g. ULONG_MAX is larger than 32
+ * bits but can't be sure it is exactly 64 bits.  Self tests will catch such
+ * cases.
+ */
+#undef DUK_F_HAVE_64BIT
+#if !defined(DUK_F_HAVE_64BIT) && defined(ULONG_MAX)
+#if (ULONG_MAX > 4294967295UL)
+#define DUK_F_HAVE_64BIT
+typedef unsigned long duk_uint64_t;
+typedef signed long duk_int64_t;
+#endif
+#endif
+#if !defined(DUK_F_HAVE_64BIT) && defined(ULLONG_MAX)
+#if (ULLONG_MAX > 4294967295UL)
+#define DUK_F_HAVE_64BIT
+typedef unsigned long long duk_uint64_t;
+typedef signed long long duk_int64_t;
+#endif
+#endif
+#if !defined(DUK_F_HAVE_64BIT) && defined(__ULONG_LONG_MAX__)
+#if (__ULONG_LONG_MAX__ > 4294967295UL)
+#define DUK_F_HAVE_64BIT
+typedef unsigned long long duk_uint64_t;
+typedef signed long long duk_int64_t;
+#endif
+#endif
+#if !defined(DUK_F_HAVE_64BIT) && defined(__LONG_LONG_MAX__)
+#if (__LONG_LONG_MAX__ > 2147483647L)
+#define DUK_F_HAVE_64BIT
+typedef unsigned long long duk_uint64_t;
+typedef signed long long duk_int64_t;
+#endif
+#endif
+#if !defined(DUK_F_HAVE_64BIT) && \
+    (defined(DUK_F_MINGW) || defined(DUK_F_MSVC))
+/* Both MinGW and MSVC have a 64-bit type. */
+#define DUK_F_HAVE_64BIT
+typedef unsigned long duk_uint64_t;
+typedef signed long duk_int64_t;
+#endif
+#if !defined(DUK_F_HAVE_64BIT)
+/* cannot detect 64-bit type, not always needed so don't error */
+#endif
+
+typedef duk_uint8_t duk_uint_least8_t;
+typedef duk_int8_t duk_int_least8_t;
+typedef duk_uint16_t duk_uint_least16_t;
+typedef duk_int16_t duk_int_least16_t;
+typedef duk_uint32_t duk_uint_least32_t;
+typedef duk_int32_t duk_int_least32_t;
+typedef duk_uint8_t duk_uint_fast8_t;
+typedef duk_int8_t duk_int_fast8_t;
+typedef duk_uint16_t duk_uint_fast16_t;
+typedef duk_int16_t duk_int_fast16_t;
+typedef duk_uint32_t duk_uint_fast32_t;
+typedef duk_int32_t duk_int_fast32_t;
+#if defined(DUK_F_HAVE_64BIT)
+typedef duk_uint64_t duk_uint_least64_t;
+typedef duk_int64_t duk_int_least64_t;
+typedef duk_uint64_t duk_uint_fast64_t;
+typedef duk_int64_t duk_int_fast64_t;
+#endif
+#if defined(DUK_F_HAVE_64BIT)
+typedef duk_uint64_t duk_uintmax_t;
+typedef duk_int64_t duk_intmax_t;
+#else
+typedef duk_uint32_t duk_uintmax_t;
+typedef duk_int32_t duk_intmax_t;
+#endif
+
+/* Note: the funny looking computations for signed minimum 16-bit, 32-bit, and
+ * 64-bit values are intentional as the obvious forms (e.g. -0x80000000L) are
+ * -not- portable.  See code-issues.txt for a detailed discussion.
+ */
+#define DUK_UINT8_MIN         0UL
+#define DUK_UINT8_MAX         0xffUL
+#define DUK_INT8_MIN          (-0x80L)
+#define DUK_INT8_MAX          0x7fL
+#define DUK_UINT_LEAST8_MIN   0UL
+#define DUK_UINT_LEAST8_MAX   0xffUL
+#define DUK_INT_LEAST8_MIN    (-0x80L)
+#define DUK_INT_LEAST8_MAX    0x7fL
+#define DUK_UINT_FAST8_MIN    0UL
+#define DUK_UINT_FAST8_MAX    0xffUL
+#define DUK_INT_FAST8_MIN     (-0x80L)
+#define DUK_INT_FAST8_MAX     0x7fL
+#define DUK_UINT16_MIN        0UL
+#define DUK_UINT16_MAX        0xffffUL
+#define DUK_INT16_MIN         (-0x7fffL - 1L)
+#define DUK_INT16_MAX         0x7fffL
+#define DUK_UINT_LEAST16_MIN  0UL
+#define DUK_UINT_LEAST16_MAX  0xffffUL
+#define DUK_INT_LEAST16_MIN   (-0x7fffL - 1L)
+#define DUK_INT_LEAST16_MAX   0x7fffL
+#define DUK_UINT_FAST16_MIN   0UL
+#define DUK_UINT_FAST16_MAX   0xffffUL
+#define DUK_INT_FAST16_MIN    (-0x7fffL - 1L)
+#define DUK_INT_FAST16_MAX    0x7fffL
+#define DUK_UINT32_MIN        0UL
+#define DUK_UINT32_MAX        0xffffffffUL
+#define DUK_INT32_MIN         (-0x7fffffffL - 1L)
+#define DUK_INT32_MAX         0x7fffffffL
+#define DUK_UINT_LEAST32_MIN  0UL
+#define DUK_UINT_LEAST32_MAX  0xffffffffUL
+#define DUK_INT_LEAST32_MIN   (-0x7fffffffL - 1L)
+#define DUK_INT_LEAST32_MAX   0x7fffffffL
+#define DUK_UINT_FAST32_MIN   0UL
+#define DUK_UINT_FAST32_MAX   0xffffffffUL
+#define DUK_INT_FAST32_MIN    (-0x7fffffffL - 1L)
+#define DUK_INT_FAST32_MAX    0x7fffffffL
+
+/* 64-bit constants.  Since LL / ULL constants are not always available,
+ * use computed values.  These values can't be used in preprocessor
+ * comparisons; flag them as such.
+ */
+#if defined(DUK_F_HAVE_64BIT)
+#define DUK_UINT64_MIN        ((duk_uint64_t) 0)
+#define DUK_UINT64_MAX        ((duk_uint64_t) -1)
+#define DUK_INT64_MIN         ((duk_int64_t) (~(DUK_UINT64_MAX >> 1)))
+#define DUK_INT64_MAX         ((duk_int64_t) (DUK_UINT64_MAX >> 1))
+#define DUK_UINT_LEAST64_MIN  DUK_UINT64_MIN
+#define DUK_UINT_LEAST64_MAX  DUK_UINT64_MAX
+#define DUK_INT_LEAST64_MIN   DUK_INT64_MIN
+#define DUK_INT_LEAST64_MAX   DUK_INT64_MAX
+#define DUK_UINT_FAST64_MIN   DUK_UINT64_MIN
+#define DUK_UINT_FAST64_MAX   DUK_UINT64_MAX
+#define DUK_INT_FAST64_MIN    DUK_INT64_MIN
+#define DUK_INT_FAST64_MAX    DUK_INT64_MAX
+#define DUK_UINT64_MIN_COMPUTED
+#define DUK_UINT64_MAX_COMPUTED
+#define DUK_INT64_MIN_COMPUTED
+#define DUK_INT64_MAX_COMPUTED
+#define DUK_UINT_LEAST64_MIN_COMPUTED
+#define DUK_UINT_LEAST64_MAX_COMPUTED
+#define DUK_INT_LEAST64_MIN_COMPUTED
+#define DUK_INT_LEAST64_MAX_COMPUTED
+#define DUK_UINT_FAST64_MIN_COMPUTED
+#define DUK_UINT_FAST64_MAX_COMPUTED
+#define DUK_INT_FAST64_MIN_COMPUTED
+#define DUK_INT_FAST64_MAX_COMPUTED
+#endif
+
+#if defined(DUK_F_HAVE_64BIT)
+#define DUK_UINTMAX_MIN       DUK_UINT64_MIN
+#define DUK_UINTMAX_MAX       DUK_UINT64_MAX
+#define DUK_INTMAX_MIN        DUK_INT64_MIN
+#define DUK_INTMAX_MAX        DUK_INT64_MAX
+#define DUK_UINTMAX_MIN_COMPUTED
+#define DUK_UINTMAX_MAX_COMPUTED
+#define DUK_INTMAX_MIN_COMPUTED
+#define DUK_INTMAX_MAX_COMPUTED
+#else
+#define DUK_UINTMAX_MIN       0UL
+#define DUK_UINTMAX_MAX       0xffffffffUL
+#define DUK_INTMAX_MIN        (-0x7fffffffL - 1L)
+#define DUK_INTMAX_MAX        0x7fffffffL
+#endif
+
+/* This detection is not very reliable. */
+#if defined(DUK_F_32BIT_PTRS)
+typedef duk_int32_t duk_intptr_t;
+typedef duk_uint32_t duk_uintptr_t;
+#define DUK_UINTPTR_MIN       DUK_UINT32_MIN
+#define DUK_UINTPTR_MAX       DUK_UINT32_MAX
+#define DUK_INTPTR_MIN        DUK_INT32_MIN
+#define DUK_INTPTR_MAX        DUK_INT32_MAX
+#elif defined(DUK_F_64BIT_PTRS) && defined(DUK_F_HAVE_64BIT)
+typedef duk_int64_t duk_intptr_t;
+typedef duk_uint64_t duk_uintptr_t;
+#define DUK_UINTPTR_MIN       DUK_UINT64_MIN
+#define DUK_UINTPTR_MAX       DUK_UINT64_MAX
+#define DUK_INTPTR_MIN        DUK_INT64_MIN
+#define DUK_INTPTR_MAX        DUK_INT64_MAX
+#define DUK_UINTPTR_MIN_COMPUTED
+#define DUK_UINTPTR_MAX_COMPUTED
+#define DUK_INTPTR_MIN_COMPUTED
+#define DUK_INTPTR_MAX_COMPUTED
+#else
+#error cannot determine intptr type
+#endif
+
+/* SIZE_MAX may be missing so use an approximate value for it. */
+#undef DUK_SIZE_MAX_COMPUTED
+#if !defined(SIZE_MAX)
+#define DUK_SIZE_MAX_COMPUTED
+#define SIZE_MAX              ((size_t) (-1))
+#endif
+#define DUK_SIZE_MIN          0
+#define DUK_SIZE_MAX          SIZE_MAX
+
+#endif  /* C99 types */
+
+/* A few types are assumed to always exist. */
+typedef size_t duk_size_t;
+typedef ptrdiff_t duk_ptrdiff_t;
+
+/* The best type for an "all around int" in Duktape internals is "at least
+ * 32 bit signed integer" which is most convenient.  Same for unsigned type.
+ * Prefer 'int' when large enough, as it is almost always a convenient type.
+ */
+#if defined(UINT_MAX) && (UINT_MAX >= 0xffffffffUL)
+typedef int duk_int_t;
+typedef unsigned int duk_uint_t;
+#define DUK_INT_MIN           INT_MIN
+#define DUK_INT_MAX           INT_MAX
+#define DUK_UINT_MIN          0
+#define DUK_UINT_MAX          UINT_MAX
+#else
+typedef duk_int_fast32_t duk_int_t;
+typedef duk_uint_fast32_t duk_uint_t;
+#define DUK_INT_MIN           DUK_INT_FAST32_MIN
+#define DUK_INT_MAX           DUK_INT_FAST32_MAX
+#define DUK_UINT_MIN          DUK_UINT_FAST32_MIN
+#define DUK_UINT_MAX          DUK_UINT_FAST32_MAX
+#endif
+
+/* Same as 'duk_int_t' but guaranteed to be a 'fast' variant if this
+ * distinction matters for the CPU.  These types are used mainly in the
+ * executor where it might really matter.
+ */
+typedef duk_int_fast32_t duk_int_fast_t;
+typedef duk_uint_fast32_t duk_uint_fast_t;
+#define DUK_INT_FAST_MIN      DUK_INT_FAST32_MIN
+#define DUK_INT_FAST_MAX      DUK_INT_FAST32_MAX
+#define DUK_UINT_FAST_MIN     DUK_UINT_FAST32_MIN
+#define DUK_UINT_FAST_MAX     DUK_UINT_FAST32_MAX
+
+/* Small integers (16 bits or more) can fall back to the 'int' type, but
+ * have a typedef so they are marked "small" explicitly.
+ */
+typedef int duk_small_int_t;
+typedef unsigned int duk_small_uint_t;
+#define DUK_SMALL_INT_MIN     INT_MIN
+#define DUK_SMALL_INT_MAX     INT_MAX
+#define DUK_SMALL_UINT_MIN    0
+#define DUK_SMALL_UINT_MAX    UINT_MAX
+
+/* Fast variants of small integers, again for really fast paths like the
+ * executor.
+ */
+typedef duk_int_fast16_t duk_small_int_fast_t;
+typedef duk_uint_fast16_t duk_small_uint_fast_t;
+#define DUK_SMALL_INT_FAST_MIN    DUK_INT_FAST16_MIN
+#define DUK_SMALL_INT_FAST_MAX    DUK_INT_FAST16_MAX
+#define DUK_SMALL_UINT_FAST_MIN   DUK_UINT_FAST16_MIN
+#define DUK_SMALL_UINT_FAST_MAX   DUK_UINT_FAST16_MAX
+
+/* Boolean values are represented with the platform 'int'. */
+typedef duk_small_int_t duk_bool_t;
+#define DUK_BOOL_MIN              DUK_SMALL_INT_MIN
+#define DUK_BOOL_MAX              DUK_SMALL_INT_MAX
+
+/* Index values must have at least 32-bit signed range. */
+typedef duk_int_t duk_idx_t;
+#define DUK_IDX_MIN               DUK_INT_MIN
+#define DUK_IDX_MAX               DUK_INT_MAX
+
+/* Unsigned index variant. */
+typedef duk_uint_t duk_uidx_t;
+#define DUK_UIDX_MIN              DUK_UINT_MIN
+#define DUK_UIDX_MAX              DUK_UINT_MAX
+
+/* Array index values, could be exact 32 bits.
+ * Currently no need for signed duk_arridx_t.
+ */
+typedef duk_uint_t duk_uarridx_t;
+#define DUK_UARRIDX_MIN           DUK_UINT_MIN
+#define DUK_UARRIDX_MAX           DUK_UINT_MAX
+
+/* Duktape/C function return value, platform int is enough for now to
+ * represent 0, 1, or negative error code.  Must be compatible with
+ * assigning truth values (e.g. duk_ret_t rc = (foo == bar);).
+ */
+typedef duk_small_int_t duk_ret_t;
+#define DUK_RET_MIN               DUK_SMALL_INT_MIN
+#define DUK_RET_MAX               DUK_SMALL_INT_MAX
+
+/* Error codes are represented with platform int.  High bits are used
+ * for flags and such, so 32 bits are needed.
+ */
+typedef duk_int_t duk_errcode_t;
+#define DUK_ERRCODE_MIN           DUK_INT_MIN
+#define DUK_ERRCODE_MAX           DUK_INT_MAX
+
+/* Codepoint type.  Must be 32 bits or more because it is used also for
+ * internal codepoints.  The type is signed because negative codepoints
+ * are used as internal markers (e.g. to mark EOF or missing argument).
+ * (X)UTF-8/CESU-8 encode/decode take and return an unsigned variant to
+ * ensure duk_uint32_t casts back and forth nicely.  Almost everything
+ * else uses the signed one.
+ */
+typedef duk_int_t duk_codepoint_t;
+typedef duk_uint_t duk_ucodepoint_t;
+#define DUK_CODEPOINT_MIN         DUK_INT_MIN
+#define DUK_CODEPOINT_MAX         DUK_INT_MAX
+#define DUK_UCODEPOINT_MIN        DUK_UINT_MIN
+#define DUK_UCODEPOINT_MAX        DUK_UINT_MAX
+
+/* IEEE float/double typedef. */
+typedef float duk_float_t;
+typedef double duk_double_t;
+
+/* We're generally assuming that we're working on a platform with a 32-bit
+ * address space.  If DUK_SIZE_MAX is a typecast value (which is necessary
+ * if SIZE_MAX is missing), the check must be avoided because the
+ * preprocessor can't do a comparison.
+ */
+#if !defined(DUK_SIZE_MAX)
+#error DUK_SIZE_MAX is undefined, probably missing SIZE_MAX
+#elif !defined(DUK_SIZE_MAX_COMPUTED)
+#if DUK_SIZE_MAX < 0xffffffffUL
+/* On some systems SIZE_MAX can be smaller than max unsigned 32-bit value
+ * which seems incorrect if size_t is (at least) an unsigned 32-bit type.
+ * However, it doesn't seem useful to error out compilation if this is the
+ * case.
+ */
+#endif
+#endif
+
+/* Type for public API calls. */
+typedef struct duk_hthread duk_context;
+
+/* Check whether we should use 64-bit integers or not.
+ *
+ * Quite incomplete now.  Use 64-bit types if detected (C99 or other detection)
+ * unless they are known to be unreliable.  For instance, 64-bit types are
+ * available on VBCC but seem to misbehave.
+ */
+#if defined(DUK_F_HAVE_64BIT) && !defined(DUK_F_VBCC)
+#define DUK_USE_64BIT_OPS
+#else
+#undef DUK_USE_64BIT_OPS
+#endif
+
+/*
+ *  Fill-ins for platform, architecture, and compiler
+ */
+
+#if !defined(DUK_SETJMP)
+#define DUK_JMPBUF_TYPE       jmp_buf
+#define DUK_SETJMP(jb)        setjmp((jb))
+#define DUK_LONGJMP(jb)       longjmp((jb), 1)
+#endif
+
+#if 0
+/* sigsetjmp() alternative */
+#define DUK_JMPBUF_TYPE       sigjmp_buf
+#define DUK_SETJMP(jb)        sigsetjmp((jb))
+#define DUK_LONGJMP(jb)       siglongjmp((jb), 1)
+#endif
+
+typedef FILE duk_file;
+#if !defined(DUK_STDIN)
+#define DUK_STDIN       stdin
+#endif
+#if !defined(DUK_STDOUT)
+#define DUK_STDOUT      stdout
+#endif
+#if !defined(DUK_STDERR)
+#define DUK_STDERR      stderr
+#endif
+
+/* Special naming to avoid conflict with e.g. DUK_FREE() in duk_heap.h
+ * (which is unfortunately named).  May sometimes need replacement, e.g.
+ * some compilers don't handle zero length or NULL correctly in realloc().
+ */
+#if !defined(DUK_ANSI_MALLOC)
+#define DUK_ANSI_MALLOC      malloc
+#endif
+#if !defined(DUK_ANSI_REALLOC)
+#define DUK_ANSI_REALLOC     realloc
+#endif
+#if !defined(DUK_ANSI_CALLOC)
+#define DUK_ANSI_CALLOC      calloc
+#endif
+#if !defined(DUK_ANSI_FREE)
+#define DUK_ANSI_FREE        free
+#endif
+
+/* ANSI C (various versions) and some implementations require that the
+ * pointer arguments to memset(), memcpy(), and memmove() be valid values
+ * even when byte size is 0 (even a NULL pointer is considered invalid in
+ * this context).  Zero-size operations as such are allowed, as long as their
+ * pointer arguments point to a valid memory area.  The DUK_MEMSET(),
+ * DUK_MEMCPY(), and DUK_MEMMOVE() macros require this same behavior, i.e.:
+ * (1) pointers must be valid and non-NULL, (2) zero size must otherwise be
+ * allowed.  If these are not fulfilled, a macro wrapper is needed.
+ *
+ *   http://stackoverflow.com/questions/5243012/is-it-guaranteed-to-be-safe-to-perform-memcpy0-0-0
+ *   http://lists.cs.uiuc.edu/pipermail/llvmdev/2007-October/011065.html
+ *
+ * Not sure what's the required behavior when a pointer points just past the
+ * end of a buffer, which often happens in practice (e.g. zero size memmoves).
+ * For example, if allocation size is 3, the following pointer would not
+ * technically point to a valid memory byte:
+ *
+ *   <-- alloc -->
+ *   | 0 | 1 | 2 | .....
+ *                 ^-- p=3, points after last valid byte (2)
+ */
+#if !defined(DUK_MEMCPY)
+#if defined(DUK_F_UCLIBC)
+/* Old uclibcs have a broken memcpy so use memmove instead (this is overly wide
+ * now on purpose): http://lists.uclibc.org/pipermail/uclibc-cvs/2008-October/025511.html
+ */
+#define DUK_MEMCPY       memmove
+#else
+#define DUK_MEMCPY       memcpy
+#endif
+#endif
+#if !defined(DUK_MEMMOVE)
+#define DUK_MEMMOVE      memmove
+#endif
+#if !defined(DUK_MEMCMP)
+#define DUK_MEMCMP       memcmp
+#endif
+#if !defined(DUK_MEMSET)
+#define DUK_MEMSET       memset
+#endif
+#if !defined(DUK_STRLEN)
+#define DUK_STRLEN       strlen
+#endif
+#if !defined(DUK_STRCMP)
+#define DUK_STRCMP       strcmp
+#endif
+#if !defined(DUK_STRNCMP)
+#define DUK_STRNCMP      strncmp
+#endif
+#if !defined(DUK_PRINTF)
+#define DUK_PRINTF       printf
+#endif
+#if !defined(DUK_FPRINTF)
+#define DUK_FPRINTF      fprintf
+#endif
+#if !defined(DUK_SPRINTF)
+#define DUK_SPRINTF      sprintf
+#endif
+#if !defined(DUK_SNPRINTF)
+/* snprintf() is technically not part of C89 but usually available. */
+#define DUK_SNPRINTF     snprintf
+#endif
+#if !defined(DUK_VSPRINTF)
+#define DUK_VSPRINTF     vsprintf
+#endif
+#if !defined(DUK_VSNPRINTF)
+/* vsnprintf() is technically not part of C89 but usually available. */
+#define DUK_VSNPRINTF    vsnprintf
+#endif
+#if !defined(DUK_SSCANF)
+#define DUK_SSCANF       sscanf
+#endif
+#if !defined(DUK_VSSCANF)
+#define DUK_VSSCANF      vsscanf
+#endif
+#if !defined(DUK_FOPEN)
+#define DUK_FOPEN        fopen
+#endif
+#if !defined(DUK_FCLOSE)
+#define DUK_FCLOSE       fclose
+#endif
+#if !defined(DUK_FREAD)
+#define DUK_FREAD        fread
+#endif
+#if !defined(DUK_FWRITE)
+#define DUK_FWRITE       fwrite
+#endif
+#if !defined(DUK_FSEEK)
+#define DUK_FSEEK        fseek
+#endif
+#if !defined(DUK_FTELL)
+#define DUK_FTELL        ftell
+#endif
+#if !defined(DUK_FFLUSH)
+#define DUK_FFLUSH       fflush
+#endif
+#if !defined(DUK_FPUTC)
+#define DUK_FPUTC        fputc
+#endif
+#if !defined(DUK_MEMZERO)
+#define DUK_MEMZERO(p,n) DUK_MEMSET((p), 0, (n))
+#endif
+#if !defined(DUK_ABORT)
+#define DUK_ABORT        abort
+#endif
+#if !defined(DUK_EXIT)
+#define DUK_EXIT         exit
+#endif
+
+#if !defined(DUK_DOUBLE_2TO32)
+#define DUK_DOUBLE_2TO32     4294967296.0
+#endif
+#if !defined(DUK_DOUBLE_2TO31)
+#define DUK_DOUBLE_2TO31     2147483648.0
+#endif
+
+#if !defined(DUK_DOUBLE_INFINITY)
+#undef DUK_USE_COMPUTED_INFINITY
+#if defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION < 40600)
+/* GCC older than 4.6: avoid overflow warnings related to using INFINITY */
+#define DUK_DOUBLE_INFINITY  (__builtin_inf())
+#elif defined(INFINITY)
+#define DUK_DOUBLE_INFINITY  ((double) INFINITY)
+#elif !defined(DUK_F_VBCC) && !defined(DUK_F_MSVC) && !defined(DUK_F_BCC)
+#define DUK_DOUBLE_INFINITY  (1.0 / 0.0)
+#else
+/* In VBCC (1.0 / 0.0) results in a warning and 0.0 instead of infinity.
+ * Use a computed infinity (initialized when a heap is created at the
+ * latest).
+ */
+#define DUK_USE_COMPUTED_INFINITY
+#define DUK_DOUBLE_INFINITY  duk_computed_infinity
+#endif
+#endif
+
+#if !defined(DUK_DOUBLE_NAN)
+#undef DUK_USE_COMPUTED_NAN
+#if defined(NAN)
+#define DUK_DOUBLE_NAN       NAN
+#elif !defined(DUK_F_VBCC) && !defined(DUK_F_MSVC) && !defined(DUK_F_BCC)
+#define DUK_DOUBLE_NAN       (0.0 / 0.0)
+#else
+/* In VBCC (0.0 / 0.0) results in a warning and 0.0 instead of NaN.
+ * In MSVC (VS2010 Express) (0.0 / 0.0) results in a compile error.
+ * Use a computed NaN (initialized when a heap is created at the
+ * latest).
+ */
+#define DUK_USE_COMPUTED_NAN
+#define DUK_DOUBLE_NAN       duk_computed_nan
+#endif
+#endif
+
+/* Many platforms are missing fpclassify() and friends, so use replacements
+ * if necessary.  The replacement constants (FP_NAN etc) can be anything but
+ * match Linux constants now.
+ */
+#undef DUK_USE_REPL_FPCLASSIFY
+#undef DUK_USE_REPL_SIGNBIT
+#undef DUK_USE_REPL_ISFINITE
+#undef DUK_USE_REPL_ISNAN
+#undef DUK_USE_REPL_ISINF
+
+/* Complex condition broken into separate parts. */
+#undef DUK_F_USE_REPL_ALL
+#if !(defined(FP_NAN) && defined(FP_INFINITE) && defined(FP_ZERO) && \
+      defined(FP_SUBNORMAL) && defined(FP_NORMAL))
+/* Missing some obvious constants. */
+#define DUK_F_USE_REPL_ALL
+#elif defined(DUK_F_AMIGAOS) && defined(DUK_F_VBCC)
+/* VBCC is missing the built-ins even in C99 mode (perhaps a header issue). */
+#define DUK_F_USE_REPL_ALL
+#elif defined(DUK_F_AMIGAOS) && defined(DUK_F_M68K)
+/* AmigaOS + M68K seems to have math issues even when using GCC cross
+ * compilation.  Use replacements for all AmigaOS versions on M68K
+ * regardless of compiler.
+ */
+#define DUK_F_USE_REPL_ALL
+#elif defined(DUK_F_FREEBSD) && defined(DUK_F_CLANG)
+/* Placeholder fix for (detection is wider than necessary):
+ * http://llvm.org/bugs/show_bug.cgi?id=17788
+ */
+#define DUK_F_USE_REPL_ALL
+#elif defined(DUK_F_UCLIBC)
+/* At least some uclibc versions have broken floating point math.  For
+ * example, fpclassify() can incorrectly classify certain NaN formats.
+ * To be safe, use replacements.
+ */
+#define DUK_F_USE_REPL_ALL
+#endif
+
+#if defined(DUK_F_USE_REPL_ALL)
+#define DUK_USE_REPL_FPCLASSIFY
+#define DUK_USE_REPL_SIGNBIT
+#define DUK_USE_REPL_ISFINITE
+#define DUK_USE_REPL_ISNAN
+#define DUK_USE_REPL_ISINF
+#define DUK_FPCLASSIFY       duk_repl_fpclassify
+#define DUK_SIGNBIT          duk_repl_signbit
+#define DUK_ISFINITE         duk_repl_isfinite
+#define DUK_ISNAN            duk_repl_isnan
+#define DUK_ISINF            duk_repl_isinf
+#define DUK_FP_NAN           0
+#define DUK_FP_INFINITE      1
+#define DUK_FP_ZERO          2
+#define DUK_FP_SUBNORMAL     3
+#define DUK_FP_NORMAL        4
+#else
+#define DUK_FPCLASSIFY       fpclassify
+#define DUK_SIGNBIT          signbit
+#define DUK_ISFINITE         isfinite
+#define DUK_ISNAN            isnan
+#define DUK_ISINF            isinf
+#define DUK_FP_NAN           FP_NAN
+#define DUK_FP_INFINITE      FP_INFINITE
+#define DUK_FP_ZERO          FP_ZERO
+#define DUK_FP_SUBNORMAL     FP_SUBNORMAL
+#define DUK_FP_NORMAL        FP_NORMAL
+#endif
+
+#if defined(DUK_F_USE_REPL_ALL)
+#undef DUK_F_USE_REPL_ALL
+#endif
+
+/* Some math functions are C99 only.  This is also an issue with some
+ * embedded environments using uclibc where uclibc has been configured
+ * not to provide some functions.  For now, use replacements whenever
+ * using uclibc.
+ */
+#undef DUK_USE_MATH_FMIN
+#undef DUK_USE_MATH_FMAX
+#undef DUK_USE_MATH_ROUND
+#if defined(DUK_F_UCLIBC)
+/* uclibc may be missing these */
+#elif defined(DUK_F_AMIGAOS) && defined(DUK_F_VBCC)
+/* vbcc + AmigaOS may be missing these */
+#elif defined(DUK_F_MINT)
+/* mint clib is missing these */
+#elif !defined(DUK_F_C99) && !defined(DUK_F_CPP11)
+/* build is not C99 or C++11, play it safe */
+#else
+/* C99 or C++11, no known issues */
+#define DUK_USE_MATH_FMIN
+#define DUK_USE_MATH_FMAX
+#define DUK_USE_MATH_ROUND
+#endif
+
+/* These functions don't currently need replacement but are wrapped for
+ * completeness.  Because these are used as function pointers, they need
+ * to be defined as concrete C functions (not macros).
+ */
+#if !defined(DUK_FABS)
+#define DUK_FABS             fabs
+#endif
+#if !defined(DUK_FMIN)
+#define DUK_FMIN             fmin
+#endif
+#if !defined(DUK_FMAX)
+#define DUK_FMAX             fmax
+#endif
+#if !defined(DUK_FLOOR)
+#define DUK_FLOOR            floor
+#endif
+#if !defined(DUK_CEIL)
+#define DUK_CEIL             ceil
+#endif
+#if !defined(DUK_FMOD)
+#define DUK_FMOD             fmod
+#endif
+#if !defined(DUK_POW)
+#define DUK_POW              pow
+#endif
+#if !defined(DUK_ACOS)
+#define DUK_ACOS             acos
+#endif
+#if !defined(DUK_ASIN)
+#define DUK_ASIN             asin
+#endif
+#if !defined(DUK_ATAN)
+#define DUK_ATAN             atan
+#endif
+#if !defined(DUK_ATAN2)
+#define DUK_ATAN2            atan2
+#endif
+#if !defined(DUK_SIN)
+#define DUK_SIN              sin
+#endif
+#if !defined(DUK_COS)
+#define DUK_COS              cos
+#endif
+#if !defined(DUK_TAN)
+#define DUK_TAN              tan
+#endif
+#if !defined(DUK_EXP)
+#define DUK_EXP              exp
+#endif
+#if !defined(DUK_LOG)
+#define DUK_LOG              log
+#endif
+#if !defined(DUK_SQRT)
+#define DUK_SQRT             sqrt
+#endif
+
+/* NetBSD 6.0 x86 (at least) has a few problems with pow() semantics,
+ * see test-bug-netbsd-math-pow.js.  Use NetBSD specific workaround.
+ * (This might be a wider problem; if so, generalize the define name.)
+ */
+#undef DUK_USE_POW_NETBSD_WORKAROUND
+#if defined(DUK_F_NETBSD)
+#define DUK_USE_POW_NETBSD_WORKAROUND
+#endif
+
+/* Rely as little as possible on compiler behavior for NaN comparison,
+ * signed zero handling, etc.  Currently never activated but may be needed
+ * for broken compilers.
+ */
+#undef DUK_USE_PARANOID_MATH
+
+/* There was a curious bug where test-bi-date-canceling.js would fail e.g.
+ * on 64-bit Ubuntu, gcc-4.8.1, -m32, and no -std=c99.  Some date computations
+ * using doubles would be optimized which then broke some corner case tests.
+ * The problem goes away by adding 'volatile' to the datetime computations.
+ * Not sure what the actual triggering conditions are, but using this on
+ * non-C99 systems solves the known issues and has relatively little cost
+ * on other platforms.
+ */
+#undef DUK_USE_PARANOID_DATE_COMPUTATION
+#if !defined(DUK_F_C99)
+#define DUK_USE_PARANOID_DATE_COMPUTATION
+#endif
+
+/*
+ *  Byte order and double memory layout detection
+ *
+ *  Endianness detection is a major portability hassle because the macros
+ *  and headers are not standardized.  There's even variance across UNIX
+ *  platforms.  Even with "standard" headers, details like underscore count
+ *  varies between platforms, e.g. both __BYTE_ORDER and _BYTE_ORDER are used
+ *  (Crossbridge has a single underscore, for instance).
+ *
+ *  The checks below are structured with this in mind: several approaches are
+ *  used, and at the end we check if any of them worked.  This allows generic
+ *  approaches to be tried first, and platform/compiler specific hacks tried
+ *  last.  As a last resort, the user can force a specific endianness, as it's
+ *  not likely that automatic detection will work on the most exotic platforms.
+ *
+ *  Duktape supports little and big endian machines.  There's also support
+ *  for a hybrid used by some ARM machines where integers are little endian
+ *  but IEEE double values use a mixed order (12345678 -> 43218765).  This
+ *  byte order for doubles is referred to as "mixed endian".
+ */
+
+/* For custom platforms allow user to define byteorder explicitly.
+ * Since endianness headers are not standardized, this is a useful
+ * workaround for custom platforms for which endianness detection
+ * is not directly supported.  Perhaps custom hardware is used and
+ * user cannot submit upstream patches.
+ */
+#if defined(DUK_OPT_FORCE_BYTEORDER)
+#undef DUK_USE_BYTEORDER
+#if (DUK_OPT_FORCE_BYTEORDER == 1)
+#define DUK_USE_BYTEORDER 1
+#elif (DUK_OPT_FORCE_BYTEORDER == 2)
+#define DUK_USE_BYTEORDER 2
+#elif (DUK_OPT_FORCE_BYTEORDER == 3)
+#define DUK_USE_BYTEORDER 3
+#else
+#error invalid DUK_OPT_FORCE_BYTEORDER value
+#endif
+#endif  /* DUK_OPT_FORCE_BYTEORDER */
+
+/* GCC and Clang provide endianness defines as built-in predefines, with
+ * leading and trailing double underscores (e.g. __BYTE_ORDER__).  See
+ * output of "make gccpredefs" and "make clangpredefs".  Clang doesn't
+ * seem to provide __FLOAT_WORD_ORDER__; assume not mixed endian for clang.
+ * http://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html
+ */
+#if !defined(DUK_USE_BYTEORDER) && defined(__BYTE_ORDER__)
+#if defined(__ORDER_LITTLE_ENDIAN__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
+#if defined(__FLOAT_WORD_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && (__FLOAT_WORD_ORDER__ == __ORDER_LITTLE_ENDIAN__)
+#define DUK_USE_BYTEORDER 1
+#elif defined(__FLOAT_WORD_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && (__FLOAT_WORD_ORDER__ == __ORDER_BIG_ENDIAN__)
+#define DUK_USE_BYTEORDER 2
+#elif !defined(__FLOAT_WORD_ORDER__)
+/* Float word order not known, assume not a hybrid. */
+#define DUK_USE_BYTEORDER 1
+#else
+/* Byte order is little endian but cannot determine IEEE double word order. */
+#endif  /* float word order */
+#elif defined(__ORDER_BIG_ENDIAN__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
+#if defined(__FLOAT_WORD_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && (__FLOAT_WORD_ORDER__ == __ORDER_BIG_ENDIAN__)
+#define DUK_USE_BYTEORDER 3
+#elif !defined(__FLOAT_WORD_ORDER__)
+/* Float word order not known, assume not a hybrid. */
+#define DUK_USE_BYTEORDER 3
+#else
+/* Byte order is big endian but cannot determine IEEE double word order. */
+#endif  /* float word order */
+#else
+/* Cannot determine byte order; __ORDER_PDP_ENDIAN__ is related to 32-bit
+ * integer ordering and is not relevant.
+ */
+#endif  /* integer byte order */
+#endif  /* !defined(DUK_USE_BYTEORDER) && defined(__BYTE_ORDER__) */
+
+/* More or less standard endianness predefines provided by header files.
+ * The ARM hybrid case is detected by assuming that __FLOAT_WORD_ORDER
+ * will be big endian, see: http://lists.mysql.com/internals/443.
+ * On some platforms some defines may be present with an empty value which
+ * causes comparisons to fail: https://github.com/svaarala/duktape/issues/453.
+ */
+#if !defined(DUK_USE_BYTEORDER)
+#if defined(__BYTE_ORDER) && defined(__LITTLE_ENDIAN) && (__BYTE_ORDER == __LITTLE_ENDIAN) || \
+    defined(_BYTE_ORDER) && defined(_LITTLE_ENDIAN) && (_BYTE_ORDER == _LITTLE_ENDIAN) || \
+    defined(__LITTLE_ENDIAN__)
+#if defined(__FLOAT_WORD_ORDER) && defined(__LITTLE_ENDIAN) && (__FLOAT_WORD_ORDER == __LITTLE_ENDIAN) || \
+    defined(_FLOAT_WORD_ORDER) && defined(_LITTLE_ENDIAN) && (_FLOAT_WORD_ORDER == _LITTLE_ENDIAN)
+#define DUK_USE_BYTEORDER 1
+#elif defined(__FLOAT_WORD_ORDER) && defined(__BIG_ENDIAN) && (__FLOAT_WORD_ORDER == __BIG_ENDIAN) || \
+      defined(_FLOAT_WORD_ORDER) && defined(_BIG_ENDIAN) && (_FLOAT_WORD_ORDER == _BIG_ENDIAN)
+#define DUK_USE_BYTEORDER 2
+#elif !defined(__FLOAT_WORD_ORDER) && !defined(_FLOAT_WORD_ORDER)
+/* Float word order not known, assume not a hybrid. */
+#define DUK_USE_BYTEORDER 1
+#else
+/* Byte order is little endian but cannot determine IEEE double word order. */
+#endif  /* float word order */
+#elif defined(__BYTE_ORDER) && defined(__BIG_ENDIAN) && (__BYTE_ORDER == __BIG_ENDIAN) || \
+      defined(_BYTE_ORDER) && defined(_BIG_ENDIAN) && (_BYTE_ORDER == _BIG_ENDIAN) || \
+      defined(__BIG_ENDIAN__)
+#if defined(__FLOAT_WORD_ORDER) && defined(__BIG_ENDIAN) && (__FLOAT_WORD_ORDER == __BIG_ENDIAN) || \
+    defined(_FLOAT_WORD_ORDER) && defined(_BIG_ENDIAN) && (_FLOAT_WORD_ORDER == _BIG_ENDIAN)
+#define DUK_USE_BYTEORDER 3
+#elif !defined(__FLOAT_WORD_ORDER) && !defined(_FLOAT_WORD_ORDER)
+/* Float word order not known, assume not a hybrid. */
+#define DUK_USE_BYTEORDER 3
+#else
+/* Byte order is big endian but cannot determine IEEE double word order. */
+#endif  /* float word order */
+#else
+/* Cannot determine byte order. */
+#endif  /* integer byte order */
+#endif  /* !defined(DUK_USE_BYTEORDER) */
+
+/* QNX gcc cross compiler seems to define e.g. __LITTLEENDIAN__ or __BIGENDIAN__:
+ *  $ /opt/qnx650/host/linux/x86/usr/bin/i486-pc-nto-qnx6.5.0-gcc -dM -E - </dev/null | grep -ni endian
+ *  67:#define __LITTLEENDIAN__ 1
+ *  $ /opt/qnx650/host/linux/x86/usr/bin/mips-unknown-nto-qnx6.5.0-gcc -dM -E - </dev/null | grep -ni endian
+ *  81:#define __BIGENDIAN__ 1
+ *  $ /opt/qnx650/host/linux/x86/usr/bin/arm-unknown-nto-qnx6.5.0-gcc -dM -E - </dev/null | grep -ni endian
+ *  70:#define __LITTLEENDIAN__ 1
+ */
+#if !defined(DUK_USE_BYTEORDER)
+#if defined(__LITTLEENDIAN__)
+#define DUK_USE_BYTEORDER 1
+#elif defined(__BIGENDIAN__)
+#define DUK_USE_BYTEORDER 3
+#endif
+#endif
+
+/*
+ *  Alignment requirement and support for unaligned accesses
+ *
+ *  Assume unaligned accesses are not supported unless specifically allowed
+ *  in the target platform.  Some platforms may support unaligned accesses
+ *  but alignment to 4 or 8 may still be desirable.
+ */
+
+/* If not provided, use safe default for alignment. */
+#if !defined(DUK_USE_ALIGN_BY)
+#define DUK_USE_ALIGN_BY 8
+#endif
+
+/* User forced alignment to 4 or 8. */
+#if defined(DUK_OPT_FORCE_ALIGN)
+#undef DUK_USE_ALIGN_BY
+#if (DUK_OPT_FORCE_ALIGN == 4)
+#define DUK_USE_ALIGN_BY 4
+#elif (DUK_OPT_FORCE_ALIGN == 8)
+#define DUK_USE_ALIGN_BY 8
+#else
+#error invalid DUK_OPT_FORCE_ALIGN value
+#endif
+#endif
+
+/* Compiler specific hackery needed to force struct size to match aligment,
+ * see e.g. duk_hbuffer.h.
+ *
+ * http://stackoverflow.com/questions/11130109/c-struct-size-alignment
+ * http://stackoverflow.com/questions/10951039/specifying-64-bit-alignment
+ */
+#if !(defined(DUK_USE_PACK_MSVC_PRAGMA) || defined(DUK_USE_PACK_GCC_ATTR) || \
+      defined(DUK_USE_PACK_CLANG_ATTR) || defined(DUK_USE_PACK_DUMMY_MEMBER))
+#define DUK_USE_PACK_DUMMY_MEMBER
+#endif
+
+#if !defined(DUK_VA_COPY)
+/* We need va_copy() which is defined in C99 / C++11, so an awkward
+ * replacement is needed for pre-C99 / pre-C++11 environments.  This
+ * will quite likely need portability hacks for some non-C99
+ * environments.
+ */
+#if defined(DUK_F_C99) || defined(DUK_F_CPP11)
+/* C99 / C++11 and above: rely on va_copy() which is required.
+ * Omit parenthesis on macro right side on purpose to minimize differences
+ * to direct use.
+ */
+#define DUK_VA_COPY(dest,src) va_copy(dest,src)
+#else
+/* Pre-C99: va_list type is implementation dependent.  This replacement
+ * assumes it is a plain value so that a simple assignment will work.
+ * This is not the case on all platforms (it may be a single-array element,
+ * for instance).
+ */
+#define DUK_VA_COPY(dest,src) do { (dest) = (src); } while (0)
+#endif
+#endif
+
+#if !defined(DUK_MACRO_STRINGIFY)
+/* Macro hackery to convert e.g. __LINE__ to a string without formatting,
+ * see: http://stackoverflow.com/questions/240353/convert-a-preprocessor-token-to-a-string
+ */
+#define DUK_MACRO_STRINGIFY_HELPER(x)  #x
+#define DUK_MACRO_STRINGIFY(x)  DUK_MACRO_STRINGIFY_HELPER(x)
+#endif
+
+#if !defined(DUK_CAUSE_SEGFAULT)
+/* This is optionally used by panic handling to cause the program to segfault
+ * (instead of e.g. abort()) on panic.  Valgrind will then indicate the C
+ * call stack leading to the panic.
+ */
+#define DUK_CAUSE_SEGFAULT()  do { *((volatile duk_uint32_t *) NULL) = (duk_uint32_t) 0xdeadbeefUL; } while (0)
+#endif
+#if !defined(DUK_UNREF)
+/* Macro for suppressing warnings for potentially unreferenced variables.
+ * The variables can be actually unreferenced or unreferenced in some
+ * specific cases only; for instance, if a variable is only debug printed,
+ * it is unreferenced when debug printing is disabled.
+ */
+#define DUK_UNREF(x)  do { (void) (x); } while (0)
+#endif
+#if !defined(DUK_NORETURN)
+#define DUK_NORETURN(decl)  decl
+#endif
+#if !defined(DUK_UNREACHABLE)
+/* Don't know how to declare unreachable point, so don't do it; this
+ * may cause some spurious compilation warnings (e.g. "variable used
+ * uninitialized").
+ */
+#define DUK_UNREACHABLE()  do { } while (0)
+#endif
+#if !defined(DUK_LOSE_CONST)
+/* Convert any input pointer into a "void *", losing a const qualifier.
+ * This is not fully portable because casting through duk_uintptr_t may
+ * not work on all architectures (e.g. those with long, segmented pointers).
+ */
+#define DUK_LOSE_CONST(src) ((void *) (duk_uintptr_t) (src))
+#endif
+
+#if !defined(DUK_LIKELY)
+#define DUK_LIKELY(x)    (x)
+#endif
+#if !defined(DUK_UNLIKELY)
+#define DUK_UNLIKELY(x)  (x)
+#endif
+
+#if !defined(DUK_NOINLINE)
+#define DUK_NOINLINE       /*nop*/
+#endif
+#if !defined(DUK_INLINE)
+#define DUK_INLINE         /*nop*/
+#endif
+#if !defined(DUK_ALWAYS_INLINE)
+#define DUK_ALWAYS_INLINE  /*nop*/
+#endif
+
+#if !defined(DUK_EXTERNAL_DECL)
+#define DUK_EXTERNAL_DECL  extern
+#endif
+#if !defined(DUK_EXTERNAL)
+#define DUK_EXTERNAL       /*empty*/
+#endif
+#if !defined(DUK_INTERNAL_DECL)
+#if defined(DUK_SINGLE_FILE)
+#define DUK_INTERNAL_DECL  static
+#else
+#define DUK_INTERNAL_DECL  extern
+#endif
+#endif
+#if !defined(DUK_INTERNAL)
+#if defined(DUK_SINGLE_FILE)
+#define DUK_INTERNAL       static
+#else
+#define DUK_INTERNAL       /*empty*/
+#endif
+#endif
+#if !defined(DUK_LOCAL_DECL)
+#define DUK_LOCAL_DECL     static
+#endif
+#if !defined(DUK_LOCAL)
+#define DUK_LOCAL          static
+#endif
+
+#if !defined(DUK_FILE_MACRO)
+#define DUK_FILE_MACRO  __FILE__
+#endif
+#if !defined(DUK_LINE_MACRO)
+#define DUK_LINE_MACRO  __LINE__
+#endif
+#if !defined(DUK_FUNC_MACRO)
+#if defined(DUK_F_C99) || defined(DUK_F_CPP11)
+#define DUK_FUNC_MACRO  __func__
+#elif defined(__FUNCTION__)
+#define DUK_FUNC_MACRO  __FUNCTION__
+#else
+#define DUK_FUNC_MACRO  "unknown"
+#endif
+#endif
+
+#if !defined(DUK_BSWAP32)
+#define DUK_BSWAP32(x) \
+	((((duk_uint32_t) (x)) >> 24) | \
+	 ((((duk_uint32_t) (x)) >> 8) & 0xff00UL) | \
+	 ((((duk_uint32_t) (x)) << 8) & 0xff0000UL) | \
+	 (((duk_uint32_t) (x)) << 24))
+#endif
+#if !defined(DUK_BSWAP16)
+#define DUK_BSWAP16(x) \
+	((duk_uint16_t) (x) >> 8) | \
+	((duk_uint16_t) (x) << 8)
+#endif
+
+/* DUK_USE_VARIADIC_MACROS: required from compilers, so no fill-in. */
+/* DUK_USE_UNION_INITIALIZERS: required from compilers, so no fill-in. */
+
+#if !(defined(DUK_USE_FLEX_C99) || defined(DUK_USE_FLEX_ZEROSIZE) || defined(DUK_USE_FLEX_ONESIZE))
+#if defined(DUK_F_C99)
+#define DUK_USE_FLEX_C99
+#else
+#define DUK_USE_FLEX_ZEROSIZE  /* Not standard but common enough */
+#endif
+#endif
+
+#if !(defined(DUK_USE_PACK_GCC_ATTR) || defined(DUK_USE_PACK_CLANG_ATTR) || \
+      defined(DUK_USE_PACK_MSVC_PRAGMA) || defined(DUK_USE_PACK_DUMMY_MEMBER))
+#define DUK_USE_PACK_DUMMY_MEMBER
+#endif
+
+#if 0  /* not defined by default */
+#undef DUK_USE_GCC_PRAGMAS
+#endif
+
+/* Workaround for GH-323: avoid inlining control when compiling from
+ * multiple sources, as it causes compiler portability trouble.
+ */
+#if !defined(DUK_SINGLE_FILE)
+#undef DUK_NOINLINE
+#undef DUK_INLINE
+#undef DUK_ALWAYS_INLINE
+#define DUK_NOINLINE       /*nop*/
+#define DUK_INLINE         /*nop*/
+#define DUK_ALWAYS_INLINE  /*nop*/
+#endif
+
+/*
+ *  Check whether or not a packed duk_tval representation is possible.
+ *  What's basically required is that pointers are 32-bit values
+ *  (sizeof(void *) == 4).  Best effort check, not always accurate.
+ *  If guess goes wrong, crashes may result; self tests also verify
+ *  the guess.
+ */
+
+/* Explicit marker needed; may be 'defined', 'undefined, 'or 'not provided'. */
+#if !defined(DUK_F_PACKED_TVAL_PROVIDED)
+#undef DUK_F_PACKED_TVAL_POSSIBLE
+
+/* Strict C99 case: DUK_UINTPTR_MAX (= UINTPTR_MAX) should be very reliable */
+#if !defined(DUK_F_PACKED_TVAL_POSSIBLE) && defined(DUK_UINTPTR_MAX)
+#if (DUK_UINTPTR_MAX <= 0xffffffffUL)
+#define DUK_F_PACKED_TVAL_POSSIBLE
+#endif
+#endif
+
+/* Non-C99 case, still relying on DUK_UINTPTR_MAX, as long as it is not a computed value */
+#if !defined(DUK_F_PACKED_TVAL_POSSIBLE) && defined(DUK_UINTPTR_MAX) && !defined(DUK_UINTPTR_MAX_COMPUTED)
+#if (DUK_UINTPTR_MAX <= 0xffffffffUL)
+#define DUK_F_PACKED_TVAL_POSSIBLE
+#endif
+#endif
+
+/* DUK_SIZE_MAX (= SIZE_MAX) is often reliable */
+#if !defined(DUK_F_PACKED_TVAL_POSSIBLE) && defined(DUK_SIZE_MAX) && !defined(DUK_SIZE_MAX_COMPUTED)
+#if (DUK_SIZE_MAX <= 0xffffffffUL)
+#define DUK_F_PACKED_TVAL_POSSIBLE
+#endif
+#endif
+
+#undef DUK_USE_PACKED_TVAL
+#if defined(DUK_F_PACKED_TVAL_POSSIBLE)
+#define DUK_USE_PACKED_TVAL
+#endif
+
+#undef DUK_F_PACKED_TVAL_POSSIBLE
+#endif  /* DUK_F_PACKED_TVAL_PROVIDED */
+
+/* Feature option forcing. */
+#if defined(DUK_OPT_NO_PACKED_TVAL)
+#undef DUK_USE_PACKED_TVAL
+#elif defined(DUK_OPT_PACKED_TVAL)
+#undef DUK_USE_PACKED_TVAL
+#define DUK_USE_PACKED_TVAL
+#endif
+/* Object property allocation layout has implications for memory and code
+ * footprint and generated code size/speed.  The best layout also depends
+ * on whether the platform has alignment requirements or benefits from
+ * having mostly aligned accesses.
+ */
+#undef DUK_USE_HOBJECT_LAYOUT_1
+#undef DUK_USE_HOBJECT_LAYOUT_2
+#undef DUK_USE_HOBJECT_LAYOUT_3
+#if (DUK_USE_ALIGN_BY == 1)
+/* On platforms without any alignment issues, layout 1 is preferable
+ * because it compiles to slightly less code and provides direct access
+ * to property keys.
+ */
+#define DUK_USE_HOBJECT_LAYOUT_1
+#else
+/* On other platforms use layout 2, which requires some padding but
+ * is a bit more natural than layout 3 in ordering the entries.  Layout
+ * 3 is currently not used.
+ */
+#define DUK_USE_HOBJECT_LAYOUT_2
+#endif
+
+/* GCC/clang inaccurate math would break compliance and probably duk_tval,
+ * so refuse to compile.  Relax this if -ffast-math is tested to work.
+ */
+#if defined(__FAST_MATH__)
+#error __FAST_MATH__ defined, refusing to compile
+#endif
+
+/*
+ *  Autogenerated defaults
+ */
+
+#undef DUK_USE_ASSERTIONS
+#define DUK_USE_AUGMENT_ERROR_CREATE
+#define DUK_USE_AUGMENT_ERROR_THROW
+#define DUK_USE_AVOID_PLATFORM_FUNCPTRS
+#define DUK_USE_BASE64_FASTPATH
+#define DUK_USE_BROWSER_LIKE
+#define DUK_USE_BUFFEROBJECT_SUPPORT
+#undef DUK_USE_BUFLEN16
+#define DUK_USE_BUILTIN_INITJS
+#define DUK_USE_BYTECODE_DUMP_SUPPORT
+#define DUK_USE_COMMONJS_MODULES
+#define DUK_USE_COMPILER_RECLIMIT 2500
+#undef DUK_USE_CPP_EXCEPTIONS
+#undef DUK_USE_DATAPTR16
+#undef DUK_USE_DATAPTR_DEC16
+#undef DUK_USE_DATAPTR_ENC16
+#undef DUK_USE_DATE_FORMAT_STRING
+#undef DUK_USE_DATE_GET_LOCAL_TZOFFSET
+#undef DUK_USE_DATE_GET_NOW
+#undef DUK_USE_DATE_PARSE_STRING
+#undef DUK_USE_DATE_PRS_GETDATE
+#undef DUK_USE_DDDPRINT
+#undef DUK_USE_DDPRINT
+#undef DUK_USE_DEBUG
+#undef DUK_USE_DEBUGGER_DUMPHEAP
+#undef DUK_USE_DEBUGGER_FWD_LOGGING
+#undef DUK_USE_DEBUGGER_FWD_PRINTALERT
+#undef DUK_USE_DEBUGGER_INSPECT
+#undef DUK_USE_DEBUGGER_PAUSE_UNCAUGHT
+#undef DUK_USE_DEBUGGER_SUPPORT
+#define DUK_USE_DEBUGGER_THROW_NOTIFY
+#undef DUK_USE_DEBUGGER_TRANSPORT_TORTURE
+#define DUK_USE_DEBUG_BUFSIZE 65536L
+#define DUK_USE_DOUBLE_LINKED_HEAP
+#undef DUK_USE_DPRINT
+#undef DUK_USE_DPRINT_COLORS
+#undef DUK_USE_DPRINT_RDTSC
+#define DUK_USE_ERRCREATE
+#define DUK_USE_ERRTHROW
+#define DUK_USE_ES6_OBJECT_PROTO_PROPERTY
+#define DUK_USE_ES6_OBJECT_SETPROTOTYPEOF
+#define DUK_USE_ES6_PROXY
+#define DUK_USE_ES6_REGEXP_BRACES
+#define DUK_USE_ESBC_LIMITS
+#define DUK_USE_ESBC_MAX_BYTES 2147418112L
+#define DUK_USE_ESBC_MAX_LINENUMBER 2147418112L
+#undef DUK_USE_EXEC_FUN_LOCAL
+#undef DUK_USE_EXEC_I

<TRUNCATED>

[15/51] [partial] nifi-minifi-cpp git commit: MINIFI-183 Added civet 1.9.1 sources Added onScheduled hook Added initial two-way TLS-enabled ListenHTTP implementation

Posted by al...@apache.org.
http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_api_string.c
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_api_string.c b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_api_string.c
new file mode 100644
index 0000000..3f1acac
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_api_string.c
@@ -0,0 +1,331 @@
+/*
+ *  String manipulation
+ */
+
+#include "duk_internal.h"
+
+DUK_LOCAL void duk__concat_and_join_helper(duk_context *ctx, duk_idx_t count_in, duk_bool_t is_join) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_uint_t count;
+	duk_uint_t i;
+	duk_size_t idx;
+	duk_size_t len;
+	duk_hstring *h;
+	duk_uint8_t *buf;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	if (DUK_UNLIKELY(count_in <= 0)) {
+		if (count_in < 0) {
+			DUK_ERROR_API(thr, DUK_STR_INVALID_COUNT);
+			return;
+		}
+		DUK_ASSERT(count_in == 0);
+		duk_push_hstring_stridx(ctx, DUK_STRIDX_EMPTY_STRING);
+		return;
+	}
+	count = (duk_uint_t) count_in;
+
+	if (is_join) {
+		duk_size_t t1, t2, limit;
+		h = duk_to_hstring(ctx, -((duk_idx_t) count) - 1);
+		DUK_ASSERT(h != NULL);
+
+		/* A bit tricky overflow test, see doc/code-issues.rst. */
+		t1 = (duk_size_t) DUK_HSTRING_GET_BYTELEN(h);
+		t2 = (duk_size_t) (count - 1);
+		limit = (duk_size_t) DUK_HSTRING_MAX_BYTELEN;
+		if (DUK_UNLIKELY(t2 != 0 && t1 > limit / t2)) {
+			/* Combined size of separators already overflows */
+			goto error_overflow;
+		}
+		len = (duk_size_t) (t1 * t2);
+	} else {
+		len = (duk_size_t) 0;
+	}
+
+	for (i = count; i >= 1; i--) {
+		duk_size_t new_len;
+		duk_to_string(ctx, -((duk_idx_t) i));
+		h = duk_require_hstring(ctx, -((duk_idx_t) i));
+		new_len = len + (duk_size_t) DUK_HSTRING_GET_BYTELEN(h);
+
+		/* Impose a string maximum length, need to handle overflow
+		 * correctly.
+		 */
+		if (new_len < len ||  /* wrapped */
+		    new_len > (duk_size_t) DUK_HSTRING_MAX_BYTELEN) {
+			goto error_overflow;
+		}
+		len = new_len;
+	}
+
+	DUK_DDD(DUK_DDDPRINT("join/concat %lu strings, total length %lu bytes",
+	                     (unsigned long) count, (unsigned long) len));
+
+	/* use stack allocated buffer to ensure reachability in errors (e.g. intern error) */
+	buf = (duk_uint8_t *) duk_push_fixed_buffer(ctx, len);
+	DUK_ASSERT(buf != NULL);
+
+	/* [... (sep) str1 str2 ... strN buf] */
+
+	idx = 0;
+	for (i = count; i >= 1; i--) {
+		if (is_join && i != count) {
+			h = duk_require_hstring(ctx, -((duk_idx_t) count) - 2);  /* extra -1 for buffer */
+			DUK_MEMCPY(buf + idx, DUK_HSTRING_GET_DATA(h), DUK_HSTRING_GET_BYTELEN(h));
+			idx += DUK_HSTRING_GET_BYTELEN(h);
+		}
+		h = duk_require_hstring(ctx, -((duk_idx_t) i) - 1);  /* extra -1 for buffer */
+		DUK_MEMCPY(buf + idx, DUK_HSTRING_GET_DATA(h), DUK_HSTRING_GET_BYTELEN(h));
+		idx += DUK_HSTRING_GET_BYTELEN(h);
+	}
+
+	DUK_ASSERT(idx == len);
+
+	/* [... (sep) str1 str2 ... strN buf] */
+
+	/* get rid of the strings early to minimize memory use before intern */
+
+	if (is_join) {
+		duk_replace(ctx, -((duk_idx_t) count) - 2);  /* overwrite sep */
+		duk_pop_n(ctx, count);
+	} else {
+		duk_replace(ctx, -((duk_idx_t) count) - 1);  /* overwrite str1 */
+		duk_pop_n(ctx, count-1);
+	}
+
+	/* [... buf] */
+
+	(void) duk_to_string(ctx, -1);
+
+	/* [... res] */
+	return;
+
+ error_overflow:
+	DUK_ERROR_RANGE(thr, DUK_STR_CONCAT_RESULT_TOO_LONG);
+}
+
+DUK_EXTERNAL void duk_concat(duk_context *ctx, duk_idx_t count) {
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	duk__concat_and_join_helper(ctx, count, 0 /*is_join*/);
+}
+
+DUK_EXTERNAL void duk_join(duk_context *ctx, duk_idx_t count) {
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	duk__concat_and_join_helper(ctx, count, 1 /*is_join*/);
+}
+
+/* XXX: could map/decode be unified with duk_unicode_support.c code?
+ * Case conversion needs also the character surroundings though.
+ */
+
+DUK_EXTERNAL void duk_decode_string(duk_context *ctx, duk_idx_t index, duk_decode_char_function callback, void *udata) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_hstring *h_input;
+	const duk_uint8_t *p, *p_start, *p_end;
+	duk_codepoint_t cp;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	h_input = duk_require_hstring(ctx, index);
+	DUK_ASSERT(h_input != NULL);
+
+	p_start = (const duk_uint8_t *) DUK_HSTRING_GET_DATA(h_input);
+	p_end = p_start + DUK_HSTRING_GET_BYTELEN(h_input);
+	p = p_start;
+
+	for (;;) {
+		if (p >= p_end) {
+			break;
+		}
+		cp = (int) duk_unicode_decode_xutf8_checked(thr, &p, p_start, p_end);
+		callback(udata, cp);
+	}
+}
+
+DUK_EXTERNAL void duk_map_string(duk_context *ctx, duk_idx_t index, duk_map_char_function callback, void *udata) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_hstring *h_input;
+	duk_bufwriter_ctx bw_alloc;
+	duk_bufwriter_ctx *bw;
+	const duk_uint8_t *p, *p_start, *p_end;
+	duk_codepoint_t cp;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	index = duk_normalize_index(ctx, index);
+
+	h_input = duk_require_hstring(ctx, index);
+	DUK_ASSERT(h_input != NULL);
+
+	bw = &bw_alloc;
+	DUK_BW_INIT_PUSHBUF(thr, bw, DUK_HSTRING_GET_BYTELEN(h_input));  /* reasonable output estimate */
+
+	p_start = (const duk_uint8_t *) DUK_HSTRING_GET_DATA(h_input);
+	p_end = p_start + DUK_HSTRING_GET_BYTELEN(h_input);
+	p = p_start;
+
+	for (;;) {
+		/* XXX: could write output in chunks with fewer ensure calls,
+		 * but relative benefit would be small here.
+		 */
+
+		if (p >= p_end) {
+			break;
+		}
+		cp = (int) duk_unicode_decode_xutf8_checked(thr, &p, p_start, p_end);
+		cp = callback(udata, cp);
+
+		DUK_BW_WRITE_ENSURE_XUTF8(thr, bw, cp);
+	}
+
+	DUK_BW_COMPACT(thr, bw);
+	duk_to_string(ctx, -1);
+	duk_replace(ctx, index);
+}
+
+DUK_EXTERNAL void duk_substring(duk_context *ctx, duk_idx_t index, duk_size_t start_offset, duk_size_t end_offset) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_hstring *h;
+	duk_hstring *res;
+	duk_size_t start_byte_offset;
+	duk_size_t end_byte_offset;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	index = duk_require_normalize_index(ctx, index);
+	h = duk_require_hstring(ctx, index);
+	DUK_ASSERT(h != NULL);
+
+	if (end_offset >= DUK_HSTRING_GET_CHARLEN(h)) {
+		end_offset = DUK_HSTRING_GET_CHARLEN(h);
+	}
+	if (start_offset > end_offset) {
+		start_offset = end_offset;
+	}
+
+	DUK_ASSERT_DISABLE(start_offset >= 0);
+	DUK_ASSERT(start_offset <= end_offset && start_offset <= DUK_HSTRING_GET_CHARLEN(h));
+	DUK_ASSERT_DISABLE(end_offset >= 0);
+	DUK_ASSERT(end_offset >= start_offset && end_offset <= DUK_HSTRING_GET_CHARLEN(h));
+
+	/* guaranteed by string limits */
+	DUK_ASSERT(start_offset <= DUK_UINT32_MAX);
+	DUK_ASSERT(end_offset <= DUK_UINT32_MAX);
+
+	start_byte_offset = (duk_size_t) duk_heap_strcache_offset_char2byte(thr, h, (duk_uint_fast32_t) start_offset);
+	end_byte_offset = (duk_size_t) duk_heap_strcache_offset_char2byte(thr, h, (duk_uint_fast32_t) end_offset);
+
+	DUK_ASSERT(end_byte_offset >= start_byte_offset);
+	DUK_ASSERT(end_byte_offset - start_byte_offset <= DUK_UINT32_MAX);  /* guaranteed by string limits */
+
+	/* no size check is necessary */
+	res = duk_heap_string_intern_checked(thr,
+	                                     DUK_HSTRING_GET_DATA(h) + start_byte_offset,
+	                                     (duk_uint32_t) (end_byte_offset - start_byte_offset));
+
+	duk_push_hstring(ctx, res);
+	duk_replace(ctx, index);
+}
+
+/* XXX: this is quite clunky.  Add Unicode helpers to scan backwards and
+ * forwards with a callback to process codepoints?
+ */
+DUK_EXTERNAL void duk_trim(duk_context *ctx, duk_idx_t index) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_hstring *h;
+	const duk_uint8_t *p, *p_start, *p_end, *p_tmp1, *p_tmp2;  /* pointers for scanning */
+	const duk_uint8_t *q_start, *q_end;  /* start (incl) and end (excl) of trimmed part */
+	duk_codepoint_t cp;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	index = duk_require_normalize_index(ctx, index);
+	h = duk_require_hstring(ctx, index);
+	DUK_ASSERT(h != NULL);
+
+	p_start = DUK_HSTRING_GET_DATA(h);
+	p_end = p_start + DUK_HSTRING_GET_BYTELEN(h);
+
+	p = p_start;
+	while (p < p_end) {
+		p_tmp1 = p;
+		cp = (duk_codepoint_t) duk_unicode_decode_xutf8_checked(thr, &p_tmp1, p_start, p_end);
+		if (!(duk_unicode_is_whitespace(cp) || duk_unicode_is_line_terminator(cp))) {
+			break;
+		}
+		p = p_tmp1;
+	}
+	q_start = p;
+	if (p == p_end) {
+		/* entire string is whitespace */
+		q_end = p;
+		goto scan_done;
+	}
+
+	p = p_end;
+	while (p > p_start) {
+		p_tmp1 = p;
+		while (p > p_start) {
+			p--;
+			if (((*p) & 0xc0) != 0x80) {
+				break;
+			}
+		}
+		p_tmp2 = p;
+
+		cp = (duk_codepoint_t) duk_unicode_decode_xutf8_checked(thr, &p_tmp2, p_start, p_end);
+		if (!(duk_unicode_is_whitespace(cp) || duk_unicode_is_line_terminator(cp))) {
+			p = p_tmp1;
+			break;
+		}
+	}
+	q_end = p;
+
+ scan_done:
+	/* This may happen when forward and backward scanning disagree
+	 * (possible for non-extended-UTF-8 strings).
+	 */
+	if (q_end < q_start) {
+		q_end = q_start;
+	}
+
+	DUK_ASSERT(q_start >= p_start && q_start <= p_end);
+	DUK_ASSERT(q_end >= p_start && q_end <= p_end);
+	DUK_ASSERT(q_end >= q_start);
+
+	DUK_DDD(DUK_DDDPRINT("trim: p_start=%p, p_end=%p, q_start=%p, q_end=%p",
+	                     (const void *) p_start, (const void *) p_end,
+	                     (const void *) q_start, (const void *) q_end));
+
+	if (q_start == p_start && q_end == p_end) {
+		DUK_DDD(DUK_DDDPRINT("nothing was trimmed: avoid interning (hashing etc)"));
+		return;
+	}
+
+	duk_push_lstring(ctx, (const char *) q_start, (duk_size_t) (q_end - q_start));
+	duk_replace(ctx, index);
+}
+
+DUK_EXTERNAL duk_codepoint_t duk_char_code_at(duk_context *ctx, duk_idx_t index, duk_size_t char_offset) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_hstring *h;
+	duk_ucodepoint_t cp;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	h = duk_require_hstring(ctx, index);
+	DUK_ASSERT(h != NULL);
+
+	DUK_ASSERT_DISABLE(char_offset >= 0);  /* always true, arg is unsigned */
+	if (char_offset >= DUK_HSTRING_GET_CHARLEN(h)) {
+		return 0;
+	}
+
+	DUK_ASSERT(char_offset <= DUK_UINT_MAX);  /* guaranteed by string limits */
+	cp = duk_hstring_char_code_at_raw(thr, h, (duk_uint_t) char_offset);
+	return (duk_codepoint_t) cp;
+}

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_api_var.c
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_api_var.c b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_api_var.c
new file mode 100644
index 0000000..6ac790e
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_api_var.c
@@ -0,0 +1,86 @@
+/*
+ *  Variable access
+ */
+
+#include "duk_internal.h"
+
+DUK_EXTERNAL void duk_get_var(duk_context *ctx) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_activation *act;
+	duk_hstring *h_varname;
+	duk_small_int_t throw_flag = 1;  /* always throw ReferenceError for unresolvable */
+
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	h_varname = duk_require_hstring(ctx, -1);  /* XXX: tostring? */
+	DUK_ASSERT(h_varname != NULL);
+
+	act = duk_hthread_get_current_activation(thr);
+	if (act) {
+		(void) duk_js_getvar_activation(thr, act, h_varname, throw_flag);  /* -> [ ... varname val this ] */
+	} else {
+		/* Outside any activation -> look up from global. */
+		DUK_ASSERT(thr->builtins[DUK_BIDX_GLOBAL_ENV] != NULL);
+		(void) duk_js_getvar_envrec(thr, thr->builtins[DUK_BIDX_GLOBAL_ENV], h_varname, throw_flag);
+	}
+
+	/* [ ... varname val this ]  (because throw_flag == 1, always resolved) */
+
+	duk_pop(ctx);
+	duk_remove(ctx, -2);
+
+	/* [ ... val ] */
+
+	/* Return value would be pointless: because throw_flag==1, we always
+	 * throw if the identifier doesn't resolve.
+	 */
+	return;
+}
+
+DUK_EXTERNAL void duk_put_var(duk_context *ctx) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_activation *act;
+	duk_hstring *h_varname;
+	duk_tval *tv_val;
+	duk_small_int_t throw_flag;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	h_varname = duk_require_hstring(ctx, -2);  /* XXX: tostring? */
+	DUK_ASSERT(h_varname != NULL);
+
+	tv_val = duk_require_tval(ctx, -1);
+
+	throw_flag = duk_is_strict_call(ctx);
+
+	act = duk_hthread_get_current_activation(thr);
+	if (act) {
+		duk_js_putvar_activation(thr, act, h_varname, tv_val, throw_flag);  /* -> [ ... varname val this ] */
+	} else {
+		/* Outside any activation -> put to global. */
+		DUK_ASSERT(thr->builtins[DUK_BIDX_GLOBAL_ENV] != NULL);
+		duk_js_putvar_envrec(thr, thr->builtins[DUK_BIDX_GLOBAL_ENV], h_varname, tv_val, throw_flag);
+	}
+
+	/* [ ... varname val ] */
+
+	duk_pop_2(ctx);
+
+	/* [ ... ] */
+
+	return;
+}
+
+DUK_EXTERNAL duk_bool_t duk_del_var(duk_context *ctx) {
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	DUK_ERROR_UNIMPLEMENTED_DEFMSG((duk_hthread *) ctx);
+	return 0;
+}
+
+DUK_EXTERNAL duk_bool_t duk_has_var(duk_context *ctx) {
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	DUK_ERROR_UNIMPLEMENTED_DEFMSG((duk_hthread *) ctx);
+	return 0;
+}

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_bi_array.c
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_bi_array.c b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_bi_array.c
new file mode 100644
index 0000000..dfb93df
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_bi_array.c
@@ -0,0 +1,1445 @@
+/*
+ *  Array built-ins
+ *
+ *  Note that most Array built-ins are intentionally generic and work even
+ *  when the 'this' binding is not an Array instance.  To ensure this,
+ *  Array algorithms do not assume "magical" Array behavior for the "length"
+ *  property, for instance.
+ *
+ *  XXX: the "Throw" flag should be set for (almost?) all [[Put]] and
+ *  [[Delete]] operations, but it's currently false throughout.  Go through
+ *  all put/delete cases and check throw flag use.  Need a new API primitive
+ *  which allows throws flag to be specified.
+ *
+ *  XXX: array lengths above 2G won't work reliably.  There are many places
+ *  where one needs a full signed 32-bit range ([-0xffffffff, 0xffffffff],
+ *  i.e. -33- bits).  Although array 'length' cannot be written to be outside
+ *  the unsigned 32-bit range (E5.1 Section 15.4.5.1 throws a RangeError if so)
+ *  some intermediate values may be above 0xffffffff and this may not be always
+ *  correctly handled now (duk_uint32_t is not enough for all algorithms).
+ *
+ *  For instance, push() can legitimately write entries beyond length 0xffffffff
+ *  and cause a RangeError only at the end.  To do this properly, the current
+ *  push() implementation tracks the array index using a 'double' instead of a
+ *  duk_uint32_t (which is somewhat awkward).  See test-bi-array-push-maxlen.js.
+ *
+ *  On using "put" vs. "def" prop
+ *  =============================
+ *
+ *  Code below must be careful to use the appropriate primitive as it matters
+ *  for compliance.  When using "put" there may be inherited properties in
+ *  Array.prototype which cause side effects when values are written.  When
+ *  using "define" there are no such side effects, and many test262 test cases
+ *  check for this (for real world code, such side effects are very rare).
+ *  Both "put" and "define" are used in the E5.1 specification; as a rule,
+ *  "put" is used when modifying an existing array (or a non-array 'this'
+ *  binding) and "define" for setting values into a fresh result array.
+ *
+ *  Also note that Array instance 'length' should be writable, but not
+ *  enumerable and definitely not configurable: even Duktape code internally
+ *  assumes that an Array instance will always have a 'length' property.
+ *  Preventing deletion of the property is critical.
+ */
+
+#include "duk_internal.h"
+
+/* Perform an intermediate join when this many elements have been pushed
+ * on the value stack.
+ */
+#define  DUK__ARRAY_MID_JOIN_LIMIT  4096
+
+/* Shared entry code for many Array built-ins.  Note that length is left
+ * on stack (it could be popped, but that's not necessary).
+ */
+DUK_LOCAL duk_uint32_t duk__push_this_obj_len_u32(duk_context *ctx) {
+	duk_uint32_t len;
+
+	(void) duk_push_this_coercible_to_object(ctx);
+	duk_get_prop_stridx(ctx, -1, DUK_STRIDX_LENGTH);
+	len = duk_to_uint32(ctx, -1);
+
+	/* -> [ ... ToObject(this) ToUint32(length) ] */
+	return len;
+}
+
+DUK_LOCAL duk_uint32_t duk__push_this_obj_len_u32_limited(duk_context *ctx) {
+	/* Range limited to [0, 0x7fffffff] range, i.e. range that can be
+	 * represented with duk_int32_t.  Use this when the method doesn't
+	 * handle the full 32-bit unsigned range correctly.
+	 */
+	duk_uint32_t ret = duk__push_this_obj_len_u32(ctx);
+	if (DUK_UNLIKELY(ret >= 0x80000000UL)) {
+		DUK_ERROR_RANGE((duk_hthread *) ctx, DUK_STR_ARRAY_LENGTH_OVER_2G);
+	}
+	return ret;
+}
+
+/*
+ *  Constructor
+ */
+
+DUK_INTERNAL duk_ret_t duk_bi_array_constructor(duk_context *ctx) {
+	duk_idx_t nargs;
+	duk_double_t d;
+	duk_uint32_t len;
+	duk_idx_t i;
+
+	nargs = duk_get_top(ctx);
+	duk_push_array(ctx);
+
+	if (nargs == 1 && duk_is_number(ctx, 0)) {
+		/* XXX: expensive check (also shared elsewhere - so add a shared internal API call?) */
+		d = duk_get_number(ctx, 0);
+		len = duk_to_uint32(ctx, 0);
+		if (((duk_double_t) len) != d) {
+			return DUK_RET_RANGE_ERROR;
+		}
+
+		/* XXX: if 'len' is low, may want to ensure array part is kept:
+		 * the caller is likely to want a dense array.
+		 */
+		duk_push_u32(ctx, len);
+		duk_xdef_prop_stridx(ctx, -2, DUK_STRIDX_LENGTH, DUK_PROPDESC_FLAGS_W);  /* [ ToUint32(len) array ToUint32(len) ] -> [ ToUint32(len) array ] */
+		return 1;
+	}
+
+	/* XXX: optimize by creating array into correct size directly, and
+	 * operating on the array part directly; values can be memcpy()'d from
+	 * value stack directly as long as refcounts are increased.
+	 */
+	for (i = 0; i < nargs; i++) {
+		duk_dup(ctx, i);
+		duk_xdef_prop_index_wec(ctx, -2, (duk_uarridx_t) i);
+	}
+
+	duk_push_u32(ctx, (duk_uint32_t) nargs);
+	duk_xdef_prop_stridx(ctx, -2, DUK_STRIDX_LENGTH, DUK_PROPDESC_FLAGS_W);
+	return 1;
+}
+
+/*
+ *  isArray()
+ */
+
+DUK_INTERNAL duk_ret_t duk_bi_array_constructor_is_array(duk_context *ctx) {
+	duk_hobject *h;
+
+	h = duk_get_hobject_with_class(ctx, 0, DUK_HOBJECT_CLASS_ARRAY);
+	duk_push_boolean(ctx, (h != NULL));
+	return 1;
+}
+
+/*
+ *  toString()
+ */
+
+DUK_INTERNAL duk_ret_t duk_bi_array_prototype_to_string(duk_context *ctx) {
+	(void) duk_push_this_coercible_to_object(ctx);
+	duk_get_prop_stridx(ctx, -1, DUK_STRIDX_JOIN);
+
+	/* [ ... this func ] */
+	if (!duk_is_callable(ctx, -1)) {
+		/* Fall back to the initial (original) Object.toString().  We don't
+		 * currently have pointers to the built-in functions, only the top
+		 * level global objects (like "Array") so this is now done in a bit
+		 * of a hacky manner.  It would be cleaner to push the (original)
+		 * function and use duk_call_method().
+		 */
+
+		/* XXX: 'this' will be ToObject() coerced twice, which is incorrect
+		 * but should have no visible side effects.
+		 */
+		DUK_DDD(DUK_DDDPRINT("this.join is not callable, fall back to (original) Object.toString"));
+		duk_set_top(ctx, 0);
+		return duk_bi_object_prototype_to_string(ctx);  /* has access to 'this' binding */
+	}
+
+	/* [ ... this func ] */
+
+	duk_insert(ctx, -2);
+
+	/* [ ... func this ] */
+
+	DUK_DDD(DUK_DDDPRINT("calling: func=%!iT, this=%!iT",
+	                     (duk_tval *) duk_get_tval(ctx, -2),
+	                     (duk_tval *) duk_get_tval(ctx, -1)));
+	duk_call_method(ctx, 0);
+
+	return 1;
+}
+
+/*
+ *  concat()
+ */
+
+DUK_INTERNAL duk_ret_t duk_bi_array_prototype_concat(duk_context *ctx) {
+	duk_idx_t i, n;
+	duk_uarridx_t idx, idx_last;
+	duk_uarridx_t j, len;
+	duk_hobject *h;
+
+	/* XXX: the insert here is a bit expensive if there are a lot of items.
+	 * It could also be special cased in the outermost for loop quite easily
+	 * (as the element is dup()'d anyway).
+	 */
+
+	(void) duk_push_this_coercible_to_object(ctx);
+	duk_insert(ctx, 0);
+	n = duk_get_top(ctx);
+	duk_push_array(ctx);  /* -> [ ToObject(this) item1 ... itemN arr ] */
+
+	/* NOTE: The Array special behaviors are NOT invoked by duk_xdef_prop_index()
+	 * (which differs from the official algorithm).  If no error is thrown, this
+	 * doesn't matter as the length is updated at the end.  However, if an error
+	 * is thrown, the length will be unset.  That shouldn't matter because the
+	 * caller won't get a reference to the intermediate value.
+	 */
+
+	idx = 0;
+	idx_last = 0;
+	for (i = 0; i < n; i++) {
+		DUK_ASSERT_TOP(ctx, n + 1);
+
+		/* [ ToObject(this) item1 ... itemN arr ] */
+
+		duk_dup(ctx, i);
+		h = duk_get_hobject_with_class(ctx, -1, DUK_HOBJECT_CLASS_ARRAY);
+		if (!h) {
+			duk_xdef_prop_index_wec(ctx, -2, idx++);
+			idx_last = idx;
+			continue;
+		}
+
+		/* [ ToObject(this) item1 ... itemN arr item(i) ] */
+
+		/* XXX: an array can have length higher than 32 bits; this is not handled
+		 * correctly now.
+		 */
+		len = (duk_uarridx_t) duk_get_length(ctx, -1);
+		for (j = 0; j < len; j++) {
+			if (duk_get_prop_index(ctx, -1, j)) {
+				/* [ ToObject(this) item1 ... itemN arr item(i) item(i)[j] ] */
+				duk_xdef_prop_index_wec(ctx, -3, idx++);
+				idx_last = idx;
+			} else {
+				idx++;
+				duk_pop(ctx);
+#if defined(DUK_USE_NONSTD_ARRAY_CONCAT_TRAILER)
+				/* According to E5.1 Section 15.4.4.4 nonexistent trailing
+				 * elements do not affect 'length' of the result.  Test262
+				 * and other engines disagree, so update idx_last here too.
+				 */
+				idx_last = idx;
+#else
+				/* Strict standard behavior, ignore trailing elements for
+				 * result 'length'.
+				 */
+#endif
+			}
+		}
+		duk_pop(ctx);
+	}
+
+	/* The E5.1 Section 15.4.4.4 algorithm doesn't set the length explicitly
+	 * in the end, but because we're operating with an internal value which
+	 * is known to be an array, this should be equivalent.
+	 */
+	duk_push_uarridx(ctx, idx_last);
+	duk_xdef_prop_stridx(ctx, -2, DUK_STRIDX_LENGTH, DUK_PROPDESC_FLAGS_W);
+
+	DUK_ASSERT_TOP(ctx, n + 1);
+	return 1;
+}
+
+/*
+ *  join(), toLocaleString()
+ *
+ *  Note: checking valstack is necessary, but only in the per-element loop.
+ *
+ *  Note: the trivial approach of pushing all the elements on the value stack
+ *  and then calling duk_join() fails when the array contains a large number
+ *  of elements.  This problem can't be offloaded to duk_join() because the
+ *  elements to join must be handled here and have special handling.  Current
+ *  approach is to do intermediate joins with very large number of elements.
+ *  There is no fancy handling; the prefix gets re-joined multiple times.
+ */
+
+DUK_INTERNAL duk_ret_t duk_bi_array_prototype_join_shared(duk_context *ctx) {
+	duk_uint32_t len, count;
+	duk_uint32_t idx;
+	duk_small_int_t to_locale_string = duk_get_current_magic(ctx);
+	duk_idx_t valstack_required;
+
+	/* For join(), nargs is 1.  For toLocaleString(), nargs is 0 and
+	 * setting the top essentially pushes an undefined to the stack,
+	 * thus defaulting to a comma separator.
+	 */
+	duk_set_top(ctx, 1);
+	if (duk_is_undefined(ctx, 0)) {
+		duk_pop(ctx);
+		duk_push_hstring_stridx(ctx, DUK_STRIDX_COMMA);
+	} else {
+		duk_to_string(ctx, 0);
+	}
+
+	len = duk__push_this_obj_len_u32(ctx);
+
+	/* [ sep ToObject(this) len ] */
+
+	DUK_DDD(DUK_DDDPRINT("sep=%!T, this=%!T, len=%lu",
+	                     (duk_tval *) duk_get_tval(ctx, 0),
+	                     (duk_tval *) duk_get_tval(ctx, 1),
+	                     (unsigned long) len));
+
+	/* The extra (+4) is tight. */
+	valstack_required = (len >= DUK__ARRAY_MID_JOIN_LIMIT ?
+	                     DUK__ARRAY_MID_JOIN_LIMIT : len) + 4;
+	duk_require_stack(ctx, valstack_required);
+
+	duk_dup(ctx, 0);
+
+	/* [ sep ToObject(this) len sep ] */
+
+	count = 0;
+	idx = 0;
+	for (;;) {
+		if (count >= DUK__ARRAY_MID_JOIN_LIMIT ||   /* intermediate join to avoid valstack overflow */
+		    idx >= len) { /* end of loop (careful with len==0) */
+			/* [ sep ToObject(this) len sep str0 ... str(count-1) ] */
+			DUK_DDD(DUK_DDDPRINT("mid/final join, count=%ld, idx=%ld, len=%ld",
+			                     (long) count, (long) idx, (long) len));
+			duk_join(ctx, (duk_idx_t) count);  /* -> [ sep ToObject(this) len str ] */
+			duk_dup(ctx, 0);                   /* -> [ sep ToObject(this) len str sep ] */
+			duk_insert(ctx, -2);               /* -> [ sep ToObject(this) len sep str ] */
+			count = 1;
+		}
+		if (idx >= len) {
+			/* if true, the stack already contains the final result */
+			break;
+		}
+
+		duk_get_prop_index(ctx, 1, (duk_uarridx_t) idx);
+		if (duk_is_null_or_undefined(ctx, -1)) {
+			duk_pop(ctx);
+			duk_push_hstring_stridx(ctx, DUK_STRIDX_EMPTY_STRING);
+		} else {
+			if (to_locale_string) {
+				duk_to_object(ctx, -1);
+				duk_get_prop_stridx(ctx, -1, DUK_STRIDX_TO_LOCALE_STRING);
+				duk_insert(ctx, -2);  /* -> [ ... toLocaleString ToObject(val) ] */
+				duk_call_method(ctx, 0);
+				duk_to_string(ctx, -1);
+			} else {
+				duk_to_string(ctx, -1);
+			}
+		}
+
+		count++;
+		idx++;
+	}
+
+	/* [ sep ToObject(this) len sep result ] */
+
+	return 1;
+}
+
+/*
+ *  pop(), push()
+ */
+
+DUK_INTERNAL duk_ret_t duk_bi_array_prototype_pop(duk_context *ctx) {
+	duk_uint32_t len;
+	duk_uint32_t idx;
+
+	DUK_ASSERT_TOP(ctx, 0);
+	len = duk__push_this_obj_len_u32(ctx);
+	if (len == 0) {
+		duk_push_int(ctx, 0);
+		duk_put_prop_stridx(ctx, 0, DUK_STRIDX_LENGTH);
+		return 0;
+	}
+	idx = len - 1;
+
+	duk_get_prop_index(ctx, 0, (duk_uarridx_t) idx);
+	duk_del_prop_index(ctx, 0, (duk_uarridx_t) idx);
+	duk_push_u32(ctx, idx);
+	duk_put_prop_stridx(ctx, 0, DUK_STRIDX_LENGTH);
+	return 1;
+}
+
+DUK_INTERNAL duk_ret_t duk_bi_array_prototype_push(duk_context *ctx) {
+	/* Note: 'this' is not necessarily an Array object.  The push()
+	 * algorithm is supposed to work for other kinds of objects too,
+	 * so the algorithm has e.g. an explicit update for the 'length'
+	 * property which is normally "magical" in arrays.
+	 */
+
+	duk_uint32_t len;
+	duk_idx_t i, n;
+
+	n = duk_get_top(ctx);
+	len = duk__push_this_obj_len_u32(ctx);
+
+	/* [ arg1 ... argN obj length ] */
+
+	/* Technically Array.prototype.push() can create an Array with length
+	 * longer than 2^32-1, i.e. outside the 32-bit range.  The final length
+	 * is *not* wrapped to 32 bits in the specification.
+	 *
+	 * This implementation tracks length with a uint32 because it's much
+	 * more practical.
+	 *
+	 * See: test-bi-array-push-maxlen.js.
+	 */
+
+	if (len + (duk_uint32_t) n < len) {
+		DUK_D(DUK_DPRINT("Array.prototype.push() would go beyond 32-bit length, throw"));
+		return DUK_RET_RANGE_ERROR;
+	}
+
+	for (i = 0; i < n; i++) {
+		duk_dup(ctx, i);
+		duk_put_prop_index(ctx, -3, len + i);
+	}
+	len += n;
+
+	duk_push_u32(ctx, len);
+	duk_dup_top(ctx);
+	duk_put_prop_stridx(ctx, -4, DUK_STRIDX_LENGTH);
+
+	/* [ arg1 ... argN obj length new_length ] */
+	return 1;
+}
+
+/*
+ *  sort()
+ *
+ *  Currently qsort with random pivot.  This is now really, really slow,
+ *  because there is no fast path for array parts.
+ *
+ *  Signed indices are used because qsort() leaves and degenerate cases
+ *  may use a negative offset.
+ */
+
+DUK_LOCAL duk_small_int_t duk__array_sort_compare(duk_context *ctx, duk_int_t idx1, duk_int_t idx2) {
+	duk_bool_t have1, have2;
+	duk_bool_t undef1, undef2;
+	duk_small_int_t ret;
+	duk_idx_t idx_obj = 1;  /* fixed offsets in valstack */
+	duk_idx_t idx_fn = 0;
+	duk_hstring *h1, *h2;
+
+	/* Fast exit if indices are identical.  This is valid for a non-existent property,
+	 * for an undefined value, and almost always for ToString() coerced comparison of
+	 * arbitrary values (corner cases where this is not the case include e.g. a an
+	 * object with varying ToString() coercion).
+	 *
+	 * The specification does not prohibit "caching" of values read from the array, so
+	 * assuming equality for comparing an index with itself falls into the category of
+	 * "caching".
+	 *
+	 * Also, compareFn may be inconsistent, so skipping a call to compareFn here may
+	 * have an effect on the final result.  The specification does not require any
+	 * specific behavior for inconsistent compare functions, so again, this fast path
+	 * is OK.
+	 */
+
+	if (idx1 == idx2) {
+		DUK_DDD(DUK_DDDPRINT("duk__array_sort_compare: idx1=%ld, idx2=%ld -> indices identical, quick exit",
+		                     (long) idx1, (long) idx2));
+		return 0;
+	}
+
+	have1 = duk_get_prop_index(ctx, idx_obj, (duk_uarridx_t) idx1);
+	have2 = duk_get_prop_index(ctx, idx_obj, (duk_uarridx_t) idx2);
+
+	DUK_DDD(DUK_DDDPRINT("duk__array_sort_compare: idx1=%ld, idx2=%ld, have1=%ld, have2=%ld, val1=%!T, val2=%!T",
+	                     (long) idx1, (long) idx2, (long) have1, (long) have2,
+	                     (duk_tval *) duk_get_tval(ctx, -2), (duk_tval *) duk_get_tval(ctx, -1)));
+
+	if (have1) {
+		if (have2) {
+			;
+		} else {
+			ret = -1;
+			goto pop_ret;
+		}
+	} else {
+		if (have2) {
+			ret = 1;
+			goto pop_ret;
+		} else {
+			ret = 0;
+			goto pop_ret;
+		}
+	}
+
+	undef1 = duk_is_undefined(ctx, -2);
+	undef2 = duk_is_undefined(ctx, -1);
+	if (undef1) {
+		if (undef2) {
+			ret = 0;
+			goto pop_ret;
+		} else {
+			ret = 1;
+			goto pop_ret;
+		}
+	} else {
+		if (undef2) {
+			ret = -1;
+			goto pop_ret;
+		} else {
+			;
+		}
+	}
+
+	if (!duk_is_undefined(ctx, idx_fn)) {
+		duk_double_t d;
+
+		/* no need to check callable; duk_call() will do that */
+		duk_dup(ctx, idx_fn);    /* -> [ ... x y fn ] */
+		duk_insert(ctx, -3);     /* -> [ ... fn x y ] */
+		duk_call(ctx, 2);        /* -> [ ... res ] */
+
+		/* The specification is a bit vague what to do if the return
+		 * value is not a number.  Other implementations seem to
+		 * tolerate non-numbers but e.g. V8 won't apparently do a
+		 * ToNumber().
+		 */
+
+		/* XXX: best behavior for real world compatibility? */
+
+		d = duk_to_number(ctx, -1);
+		if (d < 0.0) {
+			ret = -1;
+		} else if (d > 0.0) {
+			ret = 1;
+		} else {
+			ret = 0;
+		}
+
+		duk_pop(ctx);
+		DUK_DDD(DUK_DDDPRINT("-> result %ld (from comparefn, after coercion)", (long) ret));
+		return ret;
+	}
+
+	/* string compare is the default (a bit oddly) */
+
+	h1 = duk_to_hstring(ctx, -2);
+	h2 = duk_to_hstring(ctx, -1);
+	DUK_ASSERT(h1 != NULL);
+	DUK_ASSERT(h2 != NULL);
+
+	ret = duk_js_string_compare(h1, h2);  /* retval is directly usable */
+	goto pop_ret;
+
+ pop_ret:
+	duk_pop_2(ctx);
+	DUK_DDD(DUK_DDDPRINT("-> result %ld", (long) ret));
+	return ret;
+}
+
+DUK_LOCAL void duk__array_sort_swap(duk_context *ctx, duk_int_t l, duk_int_t r) {
+	duk_bool_t have_l, have_r;
+	duk_idx_t idx_obj = 1;  /* fixed offset in valstack */
+
+	if (l == r) {
+		return;
+	}
+
+	/* swap elements; deal with non-existent elements correctly */
+	have_l = duk_get_prop_index(ctx, idx_obj, (duk_uarridx_t) l);
+	have_r = duk_get_prop_index(ctx, idx_obj, (duk_uarridx_t) r);
+
+	if (have_r) {
+		/* right exists, [[Put]] regardless whether or not left exists */
+		duk_put_prop_index(ctx, idx_obj, (duk_uarridx_t) l);
+	} else {
+		duk_del_prop_index(ctx, idx_obj, (duk_uarridx_t) l);
+		duk_pop(ctx);
+	}
+
+	if (have_l) {
+		duk_put_prop_index(ctx, idx_obj, (duk_uarridx_t) r);
+	} else {
+		duk_del_prop_index(ctx, idx_obj, (duk_uarridx_t) r);
+		duk_pop(ctx);
+	}
+}
+
+#if defined(DUK_USE_DDDPRINT)
+/* Debug print which visualizes the qsort partitioning process. */
+DUK_LOCAL void duk__debuglog_qsort_state(duk_context *ctx, duk_int_t lo, duk_int_t hi, duk_int_t pivot) {
+	char buf[4096];
+	char *ptr = buf;
+	duk_int_t i, n;
+	n = (duk_int_t) duk_get_length(ctx, 1);
+	if (n > 4000) {
+		n = 4000;
+	}
+	*ptr++ = '[';
+	for (i = 0; i < n; i++) {
+		if (i == pivot) {
+			*ptr++ = '|';
+		} else if (i == lo) {
+			*ptr++ = '<';
+		} else if (i == hi) {
+			*ptr++ = '>';
+		} else if (i >= lo && i <= hi) {
+			*ptr++ = '-';
+		} else {
+			*ptr++ = ' ';
+		}
+	}
+	*ptr++ = ']';
+	*ptr++ = '\0';
+
+	DUK_DDD(DUK_DDDPRINT("%s   (lo=%ld, hi=%ld, pivot=%ld)",
+	                     (const char *) buf, (long) lo, (long) hi, (long) pivot));
+}
+#endif
+
+DUK_LOCAL void duk__array_qsort(duk_context *ctx, duk_int_t lo, duk_int_t hi) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_int_t p, l, r;
+
+	/* The lo/hi indices may be crossed and hi < 0 is possible at entry. */
+
+	DUK_DDD(DUK_DDDPRINT("duk__array_qsort: lo=%ld, hi=%ld, obj=%!T",
+	                     (long) lo, (long) hi, (duk_tval *) duk_get_tval(ctx, 1)));
+
+	DUK_ASSERT_TOP(ctx, 3);
+
+	/* In some cases it may be that lo > hi, or hi < 0; these
+	 * degenerate cases happen e.g. for empty arrays, and in
+	 * recursion leaves.
+	 */
+
+	/* trivial cases */
+	if (hi - lo < 1) {
+		DUK_DDD(DUK_DDDPRINT("degenerate case, return immediately"));
+		return;
+	}
+	DUK_ASSERT(hi > lo);
+	DUK_ASSERT(hi - lo + 1 >= 2);
+
+	/* randomized pivot selection */
+	p = lo + (duk_util_tinyrandom_get_bits(thr, 30) % (hi - lo + 1));  /* rnd in [lo,hi] */
+	DUK_ASSERT(p >= lo && p <= hi);
+	DUK_DDD(DUK_DDDPRINT("lo=%ld, hi=%ld, chose pivot p=%ld",
+	                     (long) lo, (long) hi, (long) p));
+
+	/* move pivot out of the way */
+	duk__array_sort_swap(ctx, p, lo);
+	p = lo;
+	DUK_DDD(DUK_DDDPRINT("pivot moved out of the way: %!T", (duk_tval *) duk_get_tval(ctx, 1)));
+
+	l = lo + 1;
+	r = hi;
+	for (;;) {
+		/* find elements to swap */
+		for (;;) {
+			DUK_DDD(DUK_DDDPRINT("left scan: l=%ld, r=%ld, p=%ld",
+			                     (long) l, (long) r, (long) p));
+			if (l >= hi) {
+				break;
+			}
+			if (duk__array_sort_compare(ctx, l, p) >= 0) {  /* !(l < p) */
+				break;
+			}
+			l++;
+		}
+		for (;;) {
+			DUK_DDD(DUK_DDDPRINT("right scan: l=%ld, r=%ld, p=%ld",
+			                     (long) l, (long) r, (long) p));
+			if (r <= lo) {
+				break;
+			}
+			if (duk__array_sort_compare(ctx, p, r) >= 0) {  /* !(p < r) */
+				break;
+			}
+			r--;
+		}
+		if (l >= r) {
+			goto done;
+		}
+		DUK_ASSERT(l < r);
+
+		DUK_DDD(DUK_DDDPRINT("swap %ld and %ld", (long) l, (long) r));
+
+		duk__array_sort_swap(ctx, l, r);
+
+		DUK_DDD(DUK_DDDPRINT("after swap: %!T", (duk_tval *) duk_get_tval(ctx, 1)));
+		l++;
+		r--;
+	}
+ done:
+	/* Note that 'l' and 'r' may cross, i.e. r < l */
+	DUK_ASSERT(l >= lo && l <= hi);
+	DUK_ASSERT(r >= lo && r <= hi);
+
+	/* XXX: there's no explicit recursion bound here now.  For the average
+	 * qsort recursion depth O(log n) that's not really necessary: e.g. for
+	 * 2**32 recursion depth would be about 32 which is OK.  However, qsort
+	 * worst case recursion depth is O(n) which may be a problem.
+	 */
+
+	/* move pivot to its final place */
+	DUK_DDD(DUK_DDDPRINT("before final pivot swap: %!T", (duk_tval *) duk_get_tval(ctx, 1)));
+	duk__array_sort_swap(ctx, lo, r);
+
+#if defined(DUK_USE_DDDPRINT)
+	duk__debuglog_qsort_state(ctx, lo, hi, r);
+#endif
+
+	DUK_DDD(DUK_DDDPRINT("recurse: pivot=%ld, obj=%!T", (long) r, (duk_tval *) duk_get_tval(ctx, 1)));
+	duk__array_qsort(ctx, lo, r - 1);
+	duk__array_qsort(ctx, r + 1, hi);
+}
+
+DUK_INTERNAL duk_ret_t duk_bi_array_prototype_sort(duk_context *ctx) {
+	duk_uint32_t len;
+
+	/* XXX: len >= 0x80000000 won't work below because a signed type
+	 * is needed by qsort.
+	 */
+	len = duk__push_this_obj_len_u32_limited(ctx);
+
+	/* stack[0] = compareFn
+	 * stack[1] = ToObject(this)
+	 * stack[2] = ToUint32(length)
+	 */
+
+	if (len > 0) {
+		/* avoid degenerate cases, so that (len - 1) won't underflow */
+		duk__array_qsort(ctx, (duk_int_t) 0, (duk_int_t) (len - 1));
+	}
+
+	DUK_ASSERT_TOP(ctx, 3);
+	duk_pop(ctx);
+	return 1;  /* return ToObject(this) */
+}
+
+/*
+ *  splice()
+ */
+
+/* XXX: this compiles to over 500 bytes now, even without special handling
+ * for an array part.  Uses signed ints so does not handle full array range correctly.
+ */
+
+/* XXX: can shift() / unshift() use the same helper?
+ *   shift() is (close to?) <--> splice(0, 1)
+ *   unshift is (close to?) <--> splice(0, 0, [items])?
+ */
+
+DUK_INTERNAL duk_ret_t duk_bi_array_prototype_splice(duk_context *ctx) {
+	duk_idx_t nargs;
+	duk_uint32_t len;
+	duk_bool_t have_delcount;
+	duk_int_t item_count;
+	duk_int_t act_start;
+	duk_int_t del_count;
+	duk_int_t i, n;
+
+	DUK_UNREF(have_delcount);
+
+	nargs = duk_get_top(ctx);
+	if (nargs < 2) {
+		duk_set_top(ctx, 2);
+		nargs = 2;
+		have_delcount = 0;
+	} else {
+		have_delcount = 1;
+	}
+
+	/* XXX: len >= 0x80000000 won't work below because we need to be
+	 * able to represent -len.
+	 */
+	len = duk__push_this_obj_len_u32_limited(ctx);
+
+	act_start = duk_to_int_clamped(ctx, 0, -((duk_int_t) len), (duk_int_t) len);
+	if (act_start < 0) {
+		act_start = len + act_start;
+	}
+	DUK_ASSERT(act_start >= 0 && act_start <= (duk_int_t) len);
+
+#ifdef DUK_USE_NONSTD_ARRAY_SPLICE_DELCOUNT
+	if (have_delcount) {
+#endif
+		del_count = duk_to_int_clamped(ctx, 1, 0, len - act_start);
+#ifdef DUK_USE_NONSTD_ARRAY_SPLICE_DELCOUNT
+	} else {
+		/* E5.1 standard behavior when deleteCount is not given would be
+		 * to treat it just like if 'undefined' was given, which coerces
+		 * ultimately to 0.  Real world behavior is to splice to the end
+		 * of array, see test-bi-array-proto-splice-no-delcount.js.
+		 */
+		del_count = len - act_start;
+	}
+#endif
+
+	DUK_ASSERT(nargs >= 2);
+	item_count = (duk_int_t) (nargs - 2);
+
+	DUK_ASSERT(del_count >= 0 && del_count <= (duk_int_t) len - act_start);
+	DUK_ASSERT(del_count + act_start <= (duk_int_t) len);
+
+	/* For now, restrict result array into 32-bit length range. */
+	if (((duk_double_t) len) - ((duk_double_t) del_count) + ((duk_double_t) item_count) > (duk_double_t) DUK_UINT32_MAX) {
+		DUK_D(DUK_DPRINT("Array.prototype.splice() would go beyond 32-bit length, throw"));
+		return DUK_RET_RANGE_ERROR;
+	}
+
+	duk_push_array(ctx);
+
+	/* stack[0] = start
+	 * stack[1] = deleteCount
+	 * stack[2...nargs-1] = items
+	 * stack[nargs] = ToObject(this)               -3
+	 * stack[nargs+1] = ToUint32(length)           -2
+	 * stack[nargs+2] = result array               -1
+	 */
+
+	DUK_ASSERT_TOP(ctx, nargs + 3);
+
+	/* Step 9: copy elements-to-be-deleted into the result array */
+
+	for (i = 0; i < del_count; i++) {
+		if (duk_get_prop_index(ctx, -3, (duk_uarridx_t) (act_start + i))) {
+			duk_xdef_prop_index_wec(ctx, -2, i);  /* throw flag irrelevant (false in std alg) */
+		} else {
+			duk_pop(ctx);
+		}
+	}
+	duk_push_u32(ctx, (duk_uint32_t) del_count);
+	duk_xdef_prop_stridx(ctx, -2, DUK_STRIDX_LENGTH, DUK_PROPDESC_FLAGS_W);
+
+	/* Steps 12 and 13: reorganize elements to make room for itemCount elements */
+
+	if (item_count < del_count) {
+		/*    [ A B C D E F G H ]    rel_index = 2, del_count 3, item count 1
+		 * -> [ A B F G H ]          (conceptual intermediate step)
+		 * -> [ A B . F G H ]        (placeholder marked)
+		 *    [ A B C F G H ]        (actual result at this point, C will be replaced)
+		 */
+
+		DUK_ASSERT_TOP(ctx, nargs + 3);
+
+		n = len - del_count;
+		for (i = act_start; i < n; i++) {
+			if (duk_get_prop_index(ctx, -3, (duk_uarridx_t) (i + del_count))) {
+				duk_put_prop_index(ctx, -4, (duk_uarridx_t) (i + item_count));
+			} else {
+				duk_pop(ctx);
+				duk_del_prop_index(ctx, -3, (duk_uarridx_t) (i + item_count));
+			}
+		}
+
+		DUK_ASSERT_TOP(ctx, nargs + 3);
+
+		/* loop iterator init and limit changed from standard algorithm */
+		n = len - del_count + item_count;
+		for (i = len - 1; i >= n; i--) {
+			duk_del_prop_index(ctx, -3, (duk_uarridx_t) i);
+		}
+
+		DUK_ASSERT_TOP(ctx, nargs + 3);
+	} else if (item_count > del_count) {
+		/*    [ A B C D E F G H ]    rel_index = 2, del_count 3, item count 4
+		 * -> [ A B F G H ]          (conceptual intermediate step)
+		 * -> [ A B . . . . F G H ]  (placeholder marked)
+		 *    [ A B C D E F F G H ]  (actual result at this point)
+		 */
+
+		DUK_ASSERT_TOP(ctx, nargs + 3);
+
+		/* loop iterator init and limit changed from standard algorithm */
+		for (i = len - del_count - 1; i >= act_start; i--) {
+			if (duk_get_prop_index(ctx, -3, (duk_uarridx_t) (i + del_count))) {
+				duk_put_prop_index(ctx, -4, (duk_uarridx_t) (i + item_count));
+			} else {
+				duk_pop(ctx);
+				duk_del_prop_index(ctx, -3, (duk_uarridx_t) (i + item_count));
+			}
+		}
+
+		DUK_ASSERT_TOP(ctx, nargs + 3);
+	} else {
+		/*    [ A B C D E F G H ]    rel_index = 2, del_count 3, item count 3
+		 * -> [ A B F G H ]          (conceptual intermediate step)
+		 * -> [ A B . . . F G H ]    (placeholder marked)
+		 *    [ A B C D E F G H ]    (actual result at this point)
+		 */
+	}
+	DUK_ASSERT_TOP(ctx, nargs + 3);
+
+	/* Step 15: insert itemCount elements into the hole made above */
+
+	for (i = 0; i < item_count; i++) {
+		duk_dup(ctx, i + 2);  /* args start at index 2 */
+		duk_put_prop_index(ctx, -4, (duk_uarridx_t) (act_start + i));
+	}
+
+	/* Step 16: update length; note that the final length may be above 32 bit range
+	 * (but we checked above that this isn't the case here)
+	 */
+
+	duk_push_u32(ctx, len - del_count + item_count);
+	duk_put_prop_stridx(ctx, -4, DUK_STRIDX_LENGTH);
+
+	/* result array is already at the top of stack */
+	DUK_ASSERT_TOP(ctx, nargs + 3);
+	return 1;
+}
+
+/*
+ *  reverse()
+ */
+
+DUK_INTERNAL duk_ret_t duk_bi_array_prototype_reverse(duk_context *ctx) {
+	duk_uint32_t len;
+	duk_uint32_t middle;
+	duk_uint32_t lower, upper;
+	duk_bool_t have_lower, have_upper;
+
+	len = duk__push_this_obj_len_u32(ctx);
+	middle = len / 2;
+
+	/* If len <= 1, middle will be 0 and for-loop bails out
+	 * immediately (0 < 0 -> false).
+	 */
+
+	for (lower = 0; lower < middle; lower++) {
+		DUK_ASSERT(len >= 2);
+		DUK_ASSERT_TOP(ctx, 2);
+
+		DUK_ASSERT(len >= lower + 1);
+		upper = len - lower - 1;
+
+		have_lower = duk_get_prop_index(ctx, -2, (duk_uarridx_t) lower);
+		have_upper = duk_get_prop_index(ctx, -3, (duk_uarridx_t) upper);
+
+		/* [ ToObject(this) ToUint32(length) lowerValue upperValue ] */
+
+		if (have_upper) {
+			duk_put_prop_index(ctx, -4, (duk_uarridx_t) lower);
+		} else {
+			duk_del_prop_index(ctx, -4, (duk_uarridx_t) lower);
+			duk_pop(ctx);
+		}
+
+		if (have_lower) {
+			duk_put_prop_index(ctx, -3, (duk_uarridx_t) upper);
+		} else {
+			duk_del_prop_index(ctx, -3, (duk_uarridx_t) upper);
+			duk_pop(ctx);
+		}
+
+		DUK_ASSERT_TOP(ctx, 2);
+	}
+
+	DUK_ASSERT_TOP(ctx, 2);
+	duk_pop(ctx);  /* -> [ ToObject(this) ] */
+	return 1;
+}
+
+/*
+ *  slice()
+ */
+
+DUK_INTERNAL duk_ret_t duk_bi_array_prototype_slice(duk_context *ctx) {
+	duk_uint32_t len;
+	duk_int_t start, end;
+	duk_int_t i;
+	duk_uarridx_t idx;
+	duk_uint32_t res_length = 0;
+
+	/* XXX: len >= 0x80000000 won't work below because we need to be
+	 * able to represent -len.
+	 */
+	len = duk__push_this_obj_len_u32_limited(ctx);
+	duk_push_array(ctx);
+
+	/* stack[0] = start
+	 * stack[1] = end
+	 * stack[2] = ToObject(this)
+	 * stack[3] = ToUint32(length)
+	 * stack[4] = result array
+	 */
+
+	start = duk_to_int_clamped(ctx, 0, -((duk_int_t) len), (duk_int_t) len);
+	if (start < 0) {
+		start = len + start;
+	}
+	/* XXX: could duk_is_undefined() provide defaulting undefined to 'len'
+	 * (the upper limit)?
+	 */
+	if (duk_is_undefined(ctx, 1)) {
+		end = len;
+	} else {
+		end = duk_to_int_clamped(ctx, 1, -((duk_int_t) len), (duk_int_t) len);
+		if (end < 0) {
+			end = len + end;
+		}
+	}
+	DUK_ASSERT(start >= 0 && (duk_uint32_t) start <= len);
+	DUK_ASSERT(end >= 0 && (duk_uint32_t) end <= len);
+
+	idx = 0;
+	for (i = start; i < end; i++) {
+		DUK_ASSERT_TOP(ctx, 5);
+		if (duk_get_prop_index(ctx, 2, (duk_uarridx_t) i)) {
+			duk_xdef_prop_index_wec(ctx, 4, idx);
+			res_length = idx + 1;
+		} else {
+			duk_pop(ctx);
+		}
+		idx++;
+		DUK_ASSERT_TOP(ctx, 5);
+	}
+
+	duk_push_u32(ctx, res_length);
+	duk_xdef_prop_stridx(ctx, 4, DUK_STRIDX_LENGTH, DUK_PROPDESC_FLAGS_W);
+
+	DUK_ASSERT_TOP(ctx, 5);
+	return 1;
+}
+
+/*
+ *  shift()
+ */
+
+DUK_INTERNAL duk_ret_t duk_bi_array_prototype_shift(duk_context *ctx) {
+	duk_uint32_t len;
+	duk_uint32_t i;
+
+	len = duk__push_this_obj_len_u32(ctx);
+	if (len == 0) {
+		duk_push_int(ctx, 0);
+		duk_put_prop_stridx(ctx, 0, DUK_STRIDX_LENGTH);
+		return 0;
+	}
+
+	duk_get_prop_index(ctx, 0, 0);
+
+	/* stack[0] = object (this)
+	 * stack[1] = ToUint32(length)
+	 * stack[2] = elem at index 0 (retval)
+	 */
+
+	for (i = 1; i < len; i++) {
+		DUK_ASSERT_TOP(ctx, 3);
+		if (duk_get_prop_index(ctx, 0, (duk_uarridx_t) i)) {
+			/* fromPresent = true */
+			duk_put_prop_index(ctx, 0, (duk_uarridx_t) (i - 1));
+		} else {
+			/* fromPresent = false */
+			duk_del_prop_index(ctx, 0, (duk_uarridx_t) (i - 1));
+			duk_pop(ctx);
+		}
+	}
+	duk_del_prop_index(ctx, 0, (duk_uarridx_t) (len - 1));
+
+	duk_push_u32(ctx, (duk_uint32_t) (len - 1));
+	duk_put_prop_stridx(ctx, 0, DUK_STRIDX_LENGTH);
+
+	DUK_ASSERT_TOP(ctx, 3);
+	return 1;
+}
+
+/*
+ *  unshift()
+ */
+
+DUK_INTERNAL duk_ret_t duk_bi_array_prototype_unshift(duk_context *ctx) {
+	duk_idx_t nargs;
+	duk_uint32_t len;
+	duk_uint32_t i;
+
+	nargs = duk_get_top(ctx);
+	len = duk__push_this_obj_len_u32(ctx);
+
+	/* stack[0...nargs-1] = unshift args (vararg)
+	 * stack[nargs] = ToObject(this)
+	 * stack[nargs+1] = ToUint32(length)
+	 */
+
+	DUK_ASSERT_TOP(ctx, nargs + 2);
+
+	/* Note: unshift() may operate on indices above unsigned 32-bit range
+	 * and the final length may be >= 2**32.  However, we restrict the
+	 * final result to 32-bit range for practicality.
+	 */
+
+	if (len + (duk_uint32_t) nargs < len) {
+		DUK_D(DUK_DPRINT("Array.prototype.unshift() would go beyond 32-bit length, throw"));
+		return DUK_RET_RANGE_ERROR;
+	}
+
+	i = len;
+	while (i > 0) {
+		DUK_ASSERT_TOP(ctx, nargs + 2);
+		i--;
+		/* k+argCount-1; note that may be above 32-bit range */
+
+		if (duk_get_prop_index(ctx, -2, (duk_uarridx_t) i)) {
+			/* fromPresent = true */
+			/* [ ... ToObject(this) ToUint32(length) val ] */
+			duk_put_prop_index(ctx, -3, (duk_uarridx_t) (i + nargs));  /* -> [ ... ToObject(this) ToUint32(length) ] */
+		} else {
+			/* fromPresent = false */
+			/* [ ... ToObject(this) ToUint32(length) val ] */
+			duk_pop(ctx);
+			duk_del_prop_index(ctx, -2, (duk_uarridx_t) (i + nargs));  /* -> [ ... ToObject(this) ToUint32(length) ] */
+		}
+		DUK_ASSERT_TOP(ctx, nargs + 2);
+	}
+
+	for (i = 0; i < (duk_uint32_t) nargs; i++) {
+		DUK_ASSERT_TOP(ctx, nargs + 2);
+		duk_dup(ctx, i);  /* -> [ ... ToObject(this) ToUint32(length) arg[i] ] */
+		duk_put_prop_index(ctx, -3, (duk_uarridx_t) i);
+		DUK_ASSERT_TOP(ctx, nargs + 2);
+	}
+
+	DUK_ASSERT_TOP(ctx, nargs + 2);
+	duk_push_u32(ctx, len + nargs);
+	duk_dup_top(ctx);  /* -> [ ... ToObject(this) ToUint32(length) final_len final_len ] */
+	duk_put_prop_stridx(ctx, -4, DUK_STRIDX_LENGTH);
+	return 1;
+}
+
+/*
+ *  indexOf(), lastIndexOf()
+ */
+
+DUK_INTERNAL duk_ret_t duk_bi_array_prototype_indexof_shared(duk_context *ctx) {
+	duk_idx_t nargs;
+	duk_int_t i, len;
+	duk_int_t from_index;
+	duk_small_int_t idx_step = duk_get_current_magic(ctx);  /* idx_step is +1 for indexOf, -1 for lastIndexOf */
+
+	/* lastIndexOf() needs to be a vararg function because we must distinguish
+	 * between an undefined fromIndex and a "not given" fromIndex; indexOf() is
+	 * made vararg for symmetry although it doesn't strictly need to be.
+	 */
+
+	nargs = duk_get_top(ctx);
+	duk_set_top(ctx, 2);
+
+	/* XXX: must be able to represent -len */
+	len = (duk_int_t) duk__push_this_obj_len_u32_limited(ctx);
+	if (len == 0) {
+		goto not_found;
+	}
+
+	/* Index clamping is a bit tricky, we must ensure that we'll only iterate
+	 * through elements that exist and that the specific requirements from E5.1
+	 * Sections 15.4.4.14 and 15.4.4.15 are fulfilled; especially:
+	 *
+	 *   - indexOf: clamp to [-len,len], negative handling -> [0,len],
+	 *     if clamped result is len, for-loop bails out immediately
+	 *
+	 *   - lastIndexOf: clamp to [-len-1, len-1], negative handling -> [-1, len-1],
+	 *     if clamped result is -1, for-loop bails out immediately
+	 *
+	 * If fromIndex is not given, ToInteger(undefined) = 0, which is correct
+	 * for indexOf() but incorrect for lastIndexOf().  Hence special handling,
+	 * and why lastIndexOf() needs to be a vararg function.
+	 */
+
+	if (nargs >= 2) {
+		/* indexOf: clamp fromIndex to [-len, len]
+		 * (if fromIndex == len, for-loop terminates directly)
+		 *
+		 * lastIndexOf: clamp fromIndex to [-len - 1, len - 1]
+		 * (if clamped to -len-1 -> fromIndex becomes -1, terminates for-loop directly)
+		 */
+		from_index = duk_to_int_clamped(ctx,
+		                                1,
+		                                (idx_step > 0 ? -len : -len - 1),
+		                                (idx_step > 0 ? len : len - 1));
+		if (from_index < 0) {
+			/* for lastIndexOf, result may be -1 (mark immediate termination) */
+			from_index = len + from_index;
+		}
+	} else {
+		/* for indexOf, ToInteger(undefined) would be 0, i.e. correct, but
+		 * handle both indexOf and lastIndexOf specially here.
+		 */
+		if (idx_step > 0) {
+			from_index = 0;
+		} else {
+			from_index = len - 1;
+		}
+	}
+
+	/* stack[0] = searchElement
+	 * stack[1] = fromIndex
+	 * stack[2] = object
+	 * stack[3] = length (not needed, but not popped above)
+	 */
+
+	for (i = from_index; i >= 0 && i < len; i += idx_step) {
+		DUK_ASSERT_TOP(ctx, 4);
+
+		if (duk_get_prop_index(ctx, 2, (duk_uarridx_t) i)) {
+			DUK_ASSERT_TOP(ctx, 5);
+			if (duk_strict_equals(ctx, 0, 4)) {
+				duk_push_int(ctx, i);
+				return 1;
+			}
+		}
+
+		duk_pop(ctx);
+	}
+
+ not_found:
+	duk_push_int(ctx, -1);
+	return 1;
+}
+
+/*
+ *  every(), some(), forEach(), map(), filter()
+ */
+
+#define DUK__ITER_EVERY    0
+#define DUK__ITER_SOME     1
+#define DUK__ITER_FOREACH  2
+#define DUK__ITER_MAP      3
+#define DUK__ITER_FILTER   4
+
+/* XXX: This helper is a bit awkward because the handling for the different iteration
+ * callers is quite different.  This now compiles to a bit less than 500 bytes, so with
+ * 5 callers the net result is about 100 bytes / caller.
+ */
+
+DUK_INTERNAL duk_ret_t duk_bi_array_prototype_iter_shared(duk_context *ctx) {
+	duk_uint32_t len;
+	duk_uint32_t i;
+	duk_uarridx_t k;
+	duk_bool_t bval;
+	duk_small_int_t iter_type = duk_get_current_magic(ctx);
+	duk_uint32_t res_length = 0;
+
+	/* each call this helper serves has nargs==2 */
+	DUK_ASSERT_TOP(ctx, 2);
+
+	len = duk__push_this_obj_len_u32(ctx);
+	duk_require_callable(ctx, 0);
+	/* if thisArg not supplied, behave as if undefined was supplied */
+
+	if (iter_type == DUK__ITER_MAP || iter_type == DUK__ITER_FILTER) {
+		duk_push_array(ctx);
+	} else {
+		duk_push_undefined(ctx);
+	}
+
+	/* stack[0] = callback
+	 * stack[1] = thisArg
+	 * stack[2] = object
+	 * stack[3] = ToUint32(length)  (unused, but avoid unnecessary pop)
+	 * stack[4] = result array (or undefined)
+	 */
+
+	k = 0;  /* result index for filter() */
+	for (i = 0; i < len; i++) {
+		DUK_ASSERT_TOP(ctx, 5);
+
+		if (!duk_get_prop_index(ctx, 2, (duk_uarridx_t) i)) {
+#if defined(DUK_USE_NONSTD_ARRAY_MAP_TRAILER)
+			/* Real world behavior for map(): trailing non-existent
+			 * elements don't invoke the user callback, but are still
+			 * counted towards result 'length'.
+			 */
+			if (iter_type == DUK__ITER_MAP) {
+				res_length = i + 1;
+			}
+#else
+			/* Standard behavior for map(): trailing non-existent
+			 * elements don't invoke the user callback and are not
+			 * counted towards result 'length'.
+			 */
+#endif
+			duk_pop(ctx);
+			continue;
+		}
+
+		/* The original value needs to be preserved for filter(), hence
+		 * this funny order.  We can't re-get the value because of side
+		 * effects.
+		 */
+
+		duk_dup(ctx, 0);
+		duk_dup(ctx, 1);
+		duk_dup(ctx, -3);
+		duk_push_u32(ctx, i);
+		duk_dup(ctx, 2);  /* [ ... val callback thisArg val i obj ] */
+		duk_call_method(ctx, 3); /* -> [ ... val retval ] */
+
+		switch (iter_type) {
+		case DUK__ITER_EVERY:
+			bval = duk_to_boolean(ctx, -1);
+			if (!bval) {
+				/* stack top contains 'false' */
+				return 1;
+			}
+			break;
+		case DUK__ITER_SOME:
+			bval = duk_to_boolean(ctx, -1);
+			if (bval) {
+				/* stack top contains 'true' */
+				return 1;
+			}
+			break;
+		case DUK__ITER_FOREACH:
+			/* nop */
+			break;
+		case DUK__ITER_MAP:
+			duk_dup(ctx, -1);
+			duk_xdef_prop_index_wec(ctx, 4, (duk_uarridx_t) i);  /* retval to result[i] */
+			res_length = i + 1;
+			break;
+		case DUK__ITER_FILTER:
+			bval = duk_to_boolean(ctx, -1);
+			if (bval) {
+				duk_dup(ctx, -2);  /* orig value */
+				duk_xdef_prop_index_wec(ctx, 4, (duk_uarridx_t) k);
+				k++;
+				res_length = k;
+			}
+			break;
+		default:
+			DUK_UNREACHABLE();
+			break;
+		}
+		duk_pop_2(ctx);
+
+		DUK_ASSERT_TOP(ctx, 5);
+	}
+
+	switch (iter_type) {
+	case DUK__ITER_EVERY:
+		duk_push_true(ctx);
+		break;
+	case DUK__ITER_SOME:
+		duk_push_false(ctx);
+		break;
+	case DUK__ITER_FOREACH:
+		duk_push_undefined(ctx);
+		break;
+	case DUK__ITER_MAP:
+	case DUK__ITER_FILTER:
+		DUK_ASSERT_TOP(ctx, 5);
+		DUK_ASSERT(duk_is_array(ctx, -1));  /* topmost element is the result array already */
+		duk_push_u32(ctx, res_length);
+		duk_xdef_prop_stridx(ctx, -2, DUK_STRIDX_LENGTH, DUK_PROPDESC_FLAGS_W);
+		break;
+	default:
+		DUK_UNREACHABLE();
+		break;
+	}
+
+	return 1;
+}
+
+/*
+ *  reduce(), reduceRight()
+ */
+
+DUK_INTERNAL duk_ret_t duk_bi_array_prototype_reduce_shared(duk_context *ctx) {
+	duk_idx_t nargs;
+	duk_bool_t have_acc;
+	duk_uint32_t i, len;
+	duk_small_int_t idx_step = duk_get_current_magic(ctx);  /* idx_step is +1 for reduce, -1 for reduceRight */
+
+	/* We're a varargs function because we need to detect whether
+	 * initialValue was given or not.
+	 */
+	nargs = duk_get_top(ctx);
+	DUK_DDD(DUK_DDDPRINT("nargs=%ld", (long) nargs));
+
+	duk_set_top(ctx, 2);
+	len = duk__push_this_obj_len_u32(ctx);
+	if (!duk_is_callable(ctx, 0)) {
+		goto type_error;
+	}
+
+	/* stack[0] = callback fn
+	 * stack[1] = initialValue
+	 * stack[2] = object (coerced this)
+	 * stack[3] = length (not needed, but not popped above)
+	 * stack[4] = accumulator
+	 */
+
+	have_acc = 0;
+	if (nargs >= 2) {
+		duk_dup(ctx, 1);
+		have_acc = 1;
+	}
+	DUK_DDD(DUK_DDDPRINT("have_acc=%ld, acc=%!T",
+	                     (long) have_acc, (duk_tval *) duk_get_tval(ctx, 3)));
+
+	/* For len == 0, i is initialized to len - 1 which underflows.
+	 * The condition (i < len) will then exit the for-loop on the
+	 * first round which is correct.  Similarly, loop termination
+	 * happens by i underflowing.
+	 */
+
+	for (i = (idx_step >= 0 ? 0 : len - 1);
+	     i < len;  /* i >= 0 would always be true */
+	     i += idx_step) {
+		DUK_DDD(DUK_DDDPRINT("i=%ld, len=%ld, have_acc=%ld, top=%ld, acc=%!T",
+		                     (long) i, (long) len, (long) have_acc,
+		                     (long) duk_get_top(ctx),
+		                     (duk_tval *) duk_get_tval(ctx, 4)));
+
+		DUK_ASSERT((have_acc && duk_get_top(ctx) == 5) ||
+		           (!have_acc && duk_get_top(ctx) == 4));
+
+		if (!duk_has_prop_index(ctx, 2, (duk_uarridx_t) i)) {
+			continue;
+		}
+
+		if (!have_acc) {
+			DUK_ASSERT_TOP(ctx, 4);
+			duk_get_prop_index(ctx, 2, (duk_uarridx_t) i);
+			have_acc = 1;
+			DUK_ASSERT_TOP(ctx, 5);
+		} else {
+			DUK_ASSERT_TOP(ctx, 5);
+			duk_dup(ctx, 0);
+			duk_dup(ctx, 4);
+			duk_get_prop_index(ctx, 2, (duk_uarridx_t) i);
+			duk_push_u32(ctx, i);
+			duk_dup(ctx, 2);
+			DUK_DDD(DUK_DDDPRINT("calling reduce function: func=%!T, prev=%!T, curr=%!T, idx=%!T, obj=%!T",
+			                     (duk_tval *) duk_get_tval(ctx, -5), (duk_tval *) duk_get_tval(ctx, -4),
+			                     (duk_tval *) duk_get_tval(ctx, -3), (duk_tval *) duk_get_tval(ctx, -2),
+			                     (duk_tval *) duk_get_tval(ctx, -1)));
+			duk_call(ctx, 4);
+			DUK_DDD(DUK_DDDPRINT("-> result: %!T", (duk_tval *) duk_get_tval(ctx, -1)));
+			duk_replace(ctx, 4);
+			DUK_ASSERT_TOP(ctx, 5);
+		}
+	}
+
+	if (!have_acc) {
+		goto type_error;
+	}
+
+	DUK_ASSERT_TOP(ctx, 5);
+	return 1;
+
+ type_error:
+	return DUK_RET_TYPE_ERROR;
+}
+
+#undef DUK__ARRAY_MID_JOIN_LIMIT
+
+#undef DUK__ITER_EVERY
+#undef DUK__ITER_SOME
+#undef DUK__ITER_FOREACH
+#undef DUK__ITER_MAP
+#undef DUK__ITER_FILTER

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_bi_boolean.c
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_bi_boolean.c b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_bi_boolean.c
new file mode 100644
index 0000000..5acea6d
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_bi_boolean.c
@@ -0,0 +1,68 @@
+/*
+ *  Boolean built-ins
+ */
+
+#include "duk_internal.h"
+
+/* Shared helper to provide toString() and valueOf().  Checks 'this', gets
+ * the primitive value to stack top, and optionally coerces with ToString().
+ */
+DUK_INTERNAL duk_ret_t duk_bi_boolean_prototype_tostring_shared(duk_context *ctx) {
+	duk_tval *tv;
+	duk_hobject *h;
+	duk_small_int_t coerce_tostring = duk_get_current_magic(ctx);
+
+	/* XXX: there is room to use a shared helper here, many built-ins
+	 * check the 'this' type, and if it's an object, check its class,
+	 * then get its internal value, etc.
+	 */
+
+	duk_push_this(ctx);
+	tv = duk_get_tval(ctx, -1);
+	DUK_ASSERT(tv != NULL);
+
+	if (DUK_TVAL_IS_BOOLEAN(tv)) {
+		goto type_ok;
+	} else if (DUK_TVAL_IS_OBJECT(tv)) {
+		h = DUK_TVAL_GET_OBJECT(tv);
+		DUK_ASSERT(h != NULL);
+
+		if (DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_BOOLEAN) {
+			duk_get_prop_stridx(ctx, -1, DUK_STRIDX_INT_VALUE);
+			DUK_ASSERT(duk_is_boolean(ctx, -1));
+			goto type_ok;
+		}
+	}
+
+	return DUK_RET_TYPE_ERROR;
+
+ type_ok:
+	if (coerce_tostring) {
+		duk_to_string(ctx, -1);
+	}
+	return 1;
+}
+
+DUK_INTERNAL duk_ret_t duk_bi_boolean_constructor(duk_context *ctx) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_hobject *h_this;
+
+	DUK_UNREF(thr);
+
+	duk_to_boolean(ctx, 0);
+
+	if (duk_is_constructor_call(ctx)) {
+		/* XXX: helper; rely on Boolean.prototype as being non-writable, non-configurable */
+		duk_push_this(ctx);
+		h_this = duk_get_hobject(ctx, -1);
+		DUK_ASSERT(h_this != NULL);
+		DUK_ASSERT(DUK_HOBJECT_GET_PROTOTYPE(thr->heap, h_this) == thr->builtins[DUK_BIDX_BOOLEAN_PROTOTYPE]);
+
+		DUK_HOBJECT_SET_CLASS_NUMBER(h_this, DUK_HOBJECT_CLASS_BOOLEAN);
+
+		duk_dup(ctx, 0);  /* -> [ val obj val ] */
+		duk_xdef_prop_stridx(ctx, -2, DUK_STRIDX_INT_VALUE, DUK_PROPDESC_FLAGS_NONE);  /* XXX: proper flags? */
+	}  /* unbalanced stack */
+
+	return 1;
+}


[51/51] [partial] nifi-minifi-cpp git commit: MINIFI-183 Added civet 1.9.1 sources Added onScheduled hook Added initial two-way TLS-enabled ListenHTTP implementation

Posted by al...@apache.org.
MINIFI-183 Added civet 1.9.1 sources
           Added onScheduled hook
           Added initial two-way TLS-enabled ListenHTTP implementation

This closes #43.

Signed-off-by: Aldrin Piri <al...@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/repo
Commit: http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/commit/a9485aeb
Tree: http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/tree/a9485aeb
Diff: http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/diff/a9485aeb

Branch: refs/heads/master
Commit: a9485aeb05defe3e54b179c3b5dcc1735486abcd
Parents: 3c874a0
Author: Andrew Christianson <an...@nextcentury.com>
Authored: Mon Jan 23 12:53:27 2017 +0000
Committer: Aldrin Piri <al...@apache.org>
Committed: Wed Feb 22 15:47:02 2017 -0500

----------------------------------------------------------------------
 CMakeLists.txt                                  |     11 +-
 LICENSE                                         |     30 +-
 libminifi/CMakeLists.txt                        |      7 +-
 libminifi/include/EventDrivenSchedulingAgent.h  |      2 +-
 libminifi/include/FlowController.h              |      1 +
 libminifi/include/ListenHTTP.h                  |    116 +
 libminifi/include/ProcessContext.h              |      9 +-
 libminifi/include/ProcessSession.h              |      9 +-
 libminifi/include/ProcessSessionFactory.h       |     52 +
 libminifi/include/Processor.h                   |     17 +-
 libminifi/include/SchedulingAgent.h             |      2 +-
 libminifi/include/ThreadedSchedulingAgent.h     |      4 +-
 libminifi/include/TimerDrivenSchedulingAgent.h  |      2 +-
 libminifi/src/EventDrivenSchedulingAgent.cpp    |      4 +-
 libminifi/src/FlowController.cpp                |      6 +-
 libminifi/src/ListenHTTP.cpp                    |    395 +
 libminifi/src/ProcessSessionFactory.cpp         |     28 +
 libminifi/src/Processor.cpp                     |     24 +-
 libminifi/src/SchedulingAgent.cpp               |      4 +-
 libminifi/src/ThreadedSchedulingAgent.cpp       |     15 +-
 libminifi/src/TimerDrivenSchedulingAgent.cpp    |      4 +-
 main/CMakeLists.txt                             |      8 +-
 thirdparty/civetweb-1.9.1/.clang-format         |     32 +
 thirdparty/civetweb-1.9.1/.gitattributes        |     33 +
 thirdparty/civetweb-1.9.1/.gitignore            |    266 +
 thirdparty/civetweb-1.9.1/.travis.yml           |   1240 +
 thirdparty/civetweb-1.9.1/CMakeLists.txt        |    461 +
 thirdparty/civetweb-1.9.1/CREDITS.md            |    143 +
 thirdparty/civetweb-1.9.1/LICENSE.md            |    210 +
 thirdparty/civetweb-1.9.1/Makefile.deprecated   |    208 +
 thirdparty/civetweb-1.9.1/Makefile.osx          |     42 +
 thirdparty/civetweb-1.9.1/Qt/CivetWeb.pro       |     28 +
 thirdparty/civetweb-1.9.1/README.md             |    162 +
 thirdparty/civetweb-1.9.1/RELEASE_NOTES.md      |    344 +
 .../civetweb-1.9.1/VisualStudio/buildRelease.pl |     71 +
 .../civetweb-1.9.1/VisualStudio/civetweb.sln    |     75 +
 .../civetweb_lua/civetweb_lua.vcxproj           |    215 +
 .../civetweb_lua/civetweb_lua.vcxproj.filters   |     78 +
 .../civetweb_yassl/civetweb_yassl.sln           |     36 +
 .../civetweb_yassl/civetweb_yassl.vcxproj       |    170 +
 .../civetweb_yassl.vcxproj.filters              |     40 +
 .../civetweb_yassl/yassl_lib/yassl_lib.vcxproj  |    185 +
 .../yassl_lib/yassl_lib.vcxproj.filters         |    124 +
 .../duktape_lib/duktape_lib.vcxproj             |    156 +
 .../duktape_lib/duktape_lib.vcxproj.filters     |     30 +
 .../ex_embed_cpp/ex_embed_cpp.vcxproj           |    162 +
 .../ex_embed_cpp/ex_embed_cpp.vcxproj.filters   |     36 +
 .../ex_embedded_c/ex_embedded_c.vcxproj         |    161 +
 .../ex_embedded_c/ex_embedded_c.vcxproj.filters |     30 +
 .../ex_websocket/ex_websocket.vcxproj           |    162 +
 .../ex_websocket/ex_websocket.vcxproj.filters   |     36 +
 .../ex_websocket_client.vcxproj                 |    160 +
 .../ex_websocket_client.vcxproj.filters         |     30 +
 .../VisualStudio/lua_lib/lua_lib.vcxproj        |    191 +
 .../lua_lib/lua_lib.vcxproj.filters             |    135 +
 .../VisualStudio/unit_test/unit_test.vcxproj    |    104 +
 .../unit_test/unit_test.vcxproj.filters         |     66 +
 .../VisualStudio/upload/upload.vcxproj          |    160 +
 .../VisualStudio/upload/upload.vcxproj.filters  |     30 +
 thirdparty/civetweb-1.9.1/_config.yml           |      1 +
 thirdparty/civetweb-1.9.1/appveyor.yml          |    252 +
 thirdparty/civetweb-1.9.1/build.cmd             |    866 +
 .../ci/test/01_basic/basic_spec.lua             |     35 +
 .../01_basic_test_dir/git_keep_empty_dir        |      0
 .../ci/test/01_basic/docroot/01_basic_test_file |      0
 thirdparty/civetweb-1.9.1/ci/test/README.md     |     34 +
 thirdparty/civetweb-1.9.1/ci/test/civet.lua     |     42 +
 .../civetweb-1.9.1/ci/travis/install_rocks.sh   |     14 +
 thirdparty/civetweb-1.9.1/ci/travis/lua_env.sh  |      5 +
 thirdparty/civetweb-1.9.1/ci/travis/platform.sh |     15 +
 .../civetweb-1.9.1/ci/travis/run_ci_tests.sh    |      7 +
 .../civetweb-1.9.1/ci/travis/setup_lua.sh       |     61 +
 .../civetweb-1.9.1/cmake/AddCCompilerFlag.cmake |     38 +
 .../cmake/AddCXXCompilerFlag.cmake              |     38 +
 .../cmake/DetermineTargetArchitecture.cmake     |     47 +
 thirdparty/civetweb-1.9.1/cmake/FindLibDl.cmake |     46 +
 thirdparty/civetweb-1.9.1/cmake/FindLibM.cmake  |     47 +
 thirdparty/civetweb-1.9.1/cmake/FindLibRt.cmake |     46 +
 .../civetweb-1.9.1/cmake/FindWinSock.cmake      |    102 +
 ...2fe8888aacfe784476112edd3878256d2e30bc.patch |     31 +
 .../civetweb-1.9.1/cmake/check/patch.cmake      |     12 +
 .../civetweb-1.9.1/contrib/buildroot/Config.in  |     26 +
 .../contrib/buildroot/civetweb.mk               |     55 +
 .../distribution/arch/PKGBUILD.git.example      |     42 +
 .../distribution/arch/civetweb.service          |      9 +
 thirdparty/civetweb-1.9.1/docs/APIReference.md  |     78 +
 thirdparty/civetweb-1.9.1/docs/Building.md      |    191 +
 thirdparty/civetweb-1.9.1/docs/Contribution.md  |     10 +
 thirdparty/civetweb-1.9.1/docs/Embedding.md     |    200 +
 thirdparty/civetweb-1.9.1/docs/Installing.md    |     36 +
 thirdparty/civetweb-1.9.1/docs/OpenSSL.md       |    153 +
 thirdparty/civetweb-1.9.1/docs/README.md        |     40 +
 thirdparty/civetweb-1.9.1/docs/UserManual.md    |    708 +
 thirdparty/civetweb-1.9.1/docs/_config.yml      |      1 +
 .../civetweb-1.9.1/docs/api/client_cert.md      |     21 +
 .../civetweb-1.9.1/docs/api/mg_callbacks.md     |     60 +
 .../civetweb-1.9.1/docs/api/mg_check_feature.md |     40 +
 .../docs/api/mg_client_options.md               |     21 +
 .../docs/api/mg_close_connection.md             |     21 +
 .../docs/api/mg_connect_client.md               |     29 +
 .../docs/api/mg_connect_client_secure.md        |     30 +
 .../docs/api/mg_connect_websocket_client.md     |     36 +
 thirdparty/civetweb-1.9.1/docs/api/mg_cry.md    |     23 +
 .../civetweb-1.9.1/docs/api/mg_download.md      |     37 +
 .../docs/api/mg_form_data_handler.md            |     36 +
 .../docs/api/mg_get_builtin_mime_type.md        |     24 +
 .../civetweb-1.9.1/docs/api/mg_get_context.md   |     24 +
 .../civetweb-1.9.1/docs/api/mg_get_cookie.md    |     29 +
 .../civetweb-1.9.1/docs/api/mg_get_header.md    |     22 +
 .../civetweb-1.9.1/docs/api/mg_get_option.md    |     24 +
 .../civetweb-1.9.1/docs/api/mg_get_ports.md     |     31 +
 .../docs/api/mg_get_request_info.md             |     23 +
 .../civetweb-1.9.1/docs/api/mg_get_response.md  |     29 +
 .../docs/api/mg_get_response_code_text.md       |     25 +
 .../docs/api/mg_get_server_ports.md             |     28 +
 .../docs/api/mg_get_user_connection_data.md     |     23 +
 .../civetweb-1.9.1/docs/api/mg_get_user_data.md |     23 +
 .../docs/api/mg_get_valid_option_names.md       |     24 +
 .../docs/api/mg_get_valid_options.md            |     22 +
 .../civetweb-1.9.1/docs/api/mg_get_var.md       |     30 +
 .../civetweb-1.9.1/docs/api/mg_get_var2.md      |     31 +
 .../docs/api/mg_handle_form_request.md          |     24 +
 thirdparty/civetweb-1.9.1/docs/api/mg_header.md |     18 +
 .../docs/api/mg_lock_connection.md              |     26 +
 .../civetweb-1.9.1/docs/api/mg_lock_context.md  |     23 +
 thirdparty/civetweb-1.9.1/docs/api/mg_md5.md    |     24 +
 .../docs/api/mg_modify_passwords_file.md        |     28 +
 thirdparty/civetweb-1.9.1/docs/api/mg_option.md |     31 +
 thirdparty/civetweb-1.9.1/docs/api/mg_printf.md |     27 +
 thirdparty/civetweb-1.9.1/docs/api/mg_read.md   |     26 +
 .../civetweb-1.9.1/docs/api/mg_request_info.md  |     34 +
 .../civetweb-1.9.1/docs/api/mg_send_file.md     |     25 +
 .../docs/api/mg_send_mime_file.md               |     27 +
 .../docs/api/mg_send_mime_file2.md              |     30 +
 .../civetweb-1.9.1/docs/api/mg_server_ports.md  |     24 +
 .../docs/api/mg_set_auth_handler.md             |     30 +
 .../docs/api/mg_set_request_handler.md          |     26 +
 .../docs/api/mg_set_user_connection_data.md     |     22 +
 .../docs/api/mg_set_websocket_handler.md        |     30 +
 thirdparty/civetweb-1.9.1/docs/api/mg_start.md  |     39 +
 .../civetweb-1.9.1/docs/api/mg_start_thread.md  |     26 +
 thirdparty/civetweb-1.9.1/docs/api/mg_stop.md   |     22 +
 .../civetweb-1.9.1/docs/api/mg_store_body.md    |     24 +
 .../civetweb-1.9.1/docs/api/mg_strcasecmp.md    |     24 +
 .../civetweb-1.9.1/docs/api/mg_strncasecmp.md   |     25 +
 .../docs/api/mg_unlock_connection.md            |     27 +
 .../docs/api/mg_unlock_context.md               |     23 +
 thirdparty/civetweb-1.9.1/docs/api/mg_upload.md |     22 +
 .../civetweb-1.9.1/docs/api/mg_url_decode.md    |     27 +
 .../civetweb-1.9.1/docs/api/mg_url_encode.md    |     25 +
 .../civetweb-1.9.1/docs/api/mg_version.md       |     19 +
 .../docs/api/mg_websocket_client_write.md       |     32 +
 .../docs/api/mg_websocket_write.md              |     34 +
 thirdparty/civetweb-1.9.1/docs/api/mg_write.md  |     29 +
 thirdparty/civetweb-1.9.1/docs/yaSSL.md         |     87 +
 thirdparty/civetweb-1.9.1/examples/README.md    |      8 +
 .../examples/_obsolete/chat/chat.c              |    403 +
 .../examples/_obsolete/docroot/favicon.ico      |    Bin 0 -> 1406 bytes
 .../examples/_obsolete/docroot/index.html       |     73 +
 .../examples/_obsolete/docroot/jquery.js        |    154 +
 .../examples/_obsolete/docroot/login.html       |     43 +
 .../examples/_obsolete/docroot/logo.png         |    Bin 0 -> 1601 bytes
 .../examples/_obsolete/docroot/main.js          |    107 +
 .../examples/_obsolete/docroot/prime_numbers.lp |     46 +
 .../examples/_obsolete/docroot/style.css        |    154 +
 .../examples/_obsolete/hello/hello.c            |     53 +
 .../examples/_obsolete/lua/lua_dll.c            |     21 +
 .../examples/_obsolete/post/post.c              |     58 +
 .../examples/_obsolete/upload/upload.c          |    110 +
 .../_obsolete/websocket/WebSockCallbacks.c      |    225 +
 .../_obsolete/websocket/WebSockCallbacks.h      |     44 +
 .../examples/_obsolete/websocket/websock.htm    |     55 +
 .../examples/_obsolete/websocket/websocket.c    |     65 +
 .../_obsolete/websocket_client/ssl/server.crt   |     13 +
 .../_obsolete/websocket_client/ssl/server.csr   |     11 +
 .../_obsolete/websocket_client/ssl/server.key   |     15 +
 .../_obsolete/websocket_client/ssl/server.pem   |     28 +
 .../websocket_client/websocket_client.c         |    421 +
 .../_obsolete/ws_server/docroot/index.html      |    316 +
 .../examples/_obsolete/ws_server/ws_server.c    |    271 +
 .../examples/embedded_c/embedded_c.c            |    922 +
 .../examples/embedded_cpp/embedded_cpp.cpp      |    316 +
 thirdparty/civetweb-1.9.1/format.bat            |     33 +
 thirdparty/civetweb-1.9.1/include/CivetServer.h |    597 +
 thirdparty/civetweb-1.9.1/include/civetweb.h    |   1121 +
 thirdparty/civetweb-1.9.1/mingw.cmd             |    884 +
 thirdparty/civetweb-1.9.1/resources/Info.plist  |     21 +
 .../resources/Makefile.in-duktape               |     60 +
 .../civetweb-1.9.1/resources/Makefile.in-lua    |    148 +
 .../civetweb-1.9.1/resources/Makefile.in-os     |     22 +
 .../civetweb-1.9.1/resources/cert/client.crt    |     14 +
 .../civetweb-1.9.1/resources/cert/client.csr    |     11 +
 .../civetweb-1.9.1/resources/cert/client.key    |     15 +
 .../civetweb-1.9.1/resources/cert/client.pem    |     29 +
 .../civetweb-1.9.1/resources/cert/make_cert.bat |     22 +
 .../civetweb-1.9.1/resources/cert/make_certs    |     31 +
 .../civetweb-1.9.1/resources/cert/server.crt    |     30 +
 .../civetweb-1.9.1/resources/cert/server.csr    |     28 +
 .../civetweb-1.9.1/resources/cert/server.key    |     51 +
 .../civetweb-1.9.1/resources/cert/server.pem    |     81 +
 .../civetweb-1.9.1/resources/civetweb.conf      |     32 +
 .../civetweb-1.9.1/resources/civetweb.icns      |    Bin 0 -> 13635 bytes
 .../civetweb-1.9.1/resources/civetweb.psd       |    Bin 0 -> 9365069 bytes
 .../civetweb-1.9.1/resources/civetweb_16x16.png |    Bin 0 -> 1691 bytes
 .../resources/civetweb_16x16@2.png              |    Bin 0 -> 1624 bytes
 .../civetweb-1.9.1/resources/civetweb_22x22.png |    Bin 0 -> 1857 bytes
 .../resources/civetweb_22x22@2.png              |    Bin 0 -> 2728 bytes
 .../civetweb-1.9.1/resources/civetweb_32x32.png |    Bin 0 -> 2193 bytes
 .../resources/civetweb_32x32@2.png              |    Bin 0 -> 3923 bytes
 .../civetweb-1.9.1/resources/civetweb_64x64.png |    Bin 0 -> 3923 bytes
 .../resources/civetweb_64x64@2.png              |    Bin 0 -> 10178 bytes
 thirdparty/civetweb-1.9.1/resources/cleanup.lua |     92 +
 .../civetweb-1.9.1/resources/coverity_check.sh  |     33 +
 .../civetweb-1.9.1/resources/duktape-logo.png   |    Bin 0 -> 1741 bytes
 .../civetweb-1.9.1/resources/itworks.html       |     23 +
 .../civetweb-1.9.1/resources/jni/Android.mk     |      6 +
 .../civetweb-1.9.1/resources/lua-logo.jpg       |    Bin 0 -> 2799 bytes
 .../resources/luafilesystem-logo.jpg            |    Bin 0 -> 8209 bytes
 .../civetweb-1.9.1/resources/luasqlite-logo.jpg |    Bin 0 -> 6534 bytes
 .../civetweb-1.9.1/resources/luaxml-logo.jpg    |    Bin 0 -> 6741 bytes
 thirdparty/civetweb-1.9.1/resources/mingw.bat   |     15 +
 thirdparty/civetweb-1.9.1/resources/res.rc      |      1 +
 .../civetweb-1.9.1/resources/sqlite3-logo.jpg   |    Bin 0 -> 1673 bytes
 .../civetweb-1.9.1/resources/ssl_cert.pem       |     50 +
 thirdparty/civetweb-1.9.1/resources/systray.ico |    Bin 0 -> 15086 bytes
 thirdparty/civetweb-1.9.1/src/CMakeLists.txt    |    291 +
 thirdparty/civetweb-1.9.1/src/CivetServer.cpp   |    594 +
 thirdparty/civetweb-1.9.1/src/civetweb.c        |  14894 ++
 .../civetweb-1.9.1/src/civetweb_private_lua.h   |     11 +
 thirdparty/civetweb-1.9.1/src/file_ops.inl      |      1 +
 thirdparty/civetweb-1.9.1/src/handle_form.inl   |    810 +
 thirdparty/civetweb-1.9.1/src/main.c            |   2633 +
 thirdparty/civetweb-1.9.1/src/md5.inl           |    468 +
 thirdparty/civetweb-1.9.1/src/mod_duktape.inl   |    250 +
 thirdparty/civetweb-1.9.1/src/mod_lua.inl       |   2000 +
 thirdparty/civetweb-1.9.1/src/sha1.inl          |    323 +
 .../civetweb-1.9.1/src/third_party/LuaXML.lua   |    116 +
 .../civetweb-1.9.1/src/third_party/LuaXML_lib.c |    476 +
 .../src/third_party/civetweb_lua.h              |     73 +
 .../src/third_party/duktape-1.5.2/AUTHORS.rst   |     72 +
 .../src/third_party/duktape-1.5.2/LICENSE.txt   |     25 +
 .../third_party/duktape-1.5.2/Makefile.cmdline  |     34 +
 .../third_party/duktape-1.5.2/Makefile.codepage |      4 +
 .../third_party/duktape-1.5.2/Makefile.coffee   |      4 +
 .../third_party/duktape-1.5.2/Makefile.dukdebug |     26 +
 .../src/third_party/duktape-1.5.2/Makefile.eval |      7 +
 .../duktape-1.5.2/Makefile.eventloop            |     22 +
 .../third_party/duktape-1.5.2/Makefile.hello    |     35 +
 .../third_party/duktape-1.5.2/Makefile.jxpretty |      8 +
 .../third_party/duktape-1.5.2/Makefile.sandbox  |      7 +
 .../duktape-1.5.2/Makefile.sharedlibrary        |     71 +
 .../src/third_party/duktape-1.5.2/README.rst    |    110 +
 .../third_party/duktape-1.5.2/config/README.rst |     39 +
 .../config/duk_config.h-modular-dll             |   3415 +
 .../config/duk_config.h-modular-static          |   3415 +
 .../duktape-1.5.2/config/genconfig.py           |   1537 +
 .../config/genconfig_metadata.tar.gz            |    Bin 0 -> 71815 bytes
 .../duktape-1.5.2/debugger/README.rst           |    384 +
 .../duktape-1.5.2/debugger/duk_classnames.yaml  |     32 +
 .../duktape-1.5.2/debugger/duk_debug.js         |   2473 +
 .../duktape-1.5.2/debugger/duk_debug_meta.json  |   1497 +
 .../duktape-1.5.2/debugger/duk_debug_proxy.js   |   1029 +
 .../debugger/duk_debugcommands.yaml             |     52 +
 .../duktape-1.5.2/debugger/duk_debugerrors.yaml |      6 +
 .../duktape-1.5.2/debugger/duk_opcodes.yaml     |    658 +
 .../duktape-1.5.2/debugger/merge_debug_meta.py  |     32 +
 .../duktape-1.5.2/debugger/package.json         |     27 +
 .../duktape-1.5.2/debugger/static/index.html    |     96 +
 .../duktape-1.5.2/debugger/static/style.css     |    516 +
 .../duktape-1.5.2/debugger/static/webui.js      |    785 +
 .../duktape-1.5.2/duk_build_meta.json           |   1349 +
 .../duktape-1.5.2/examples/README.rst           |     10 +
 .../examples/alloc-hybrid/README.rst            |     10 +
 .../examples/alloc-hybrid/duk_alloc_hybrid.c    |    293 +
 .../examples/alloc-hybrid/duk_alloc_hybrid.h    |     11 +
 .../examples/alloc-logging/README.rst           |      7 +
 .../examples/alloc-logging/duk_alloc_logging.c  |    138 +
 .../examples/alloc-logging/duk_alloc_logging.h  |     10 +
 .../examples/alloc-logging/log2gnuplot.py       |     41 +
 .../examples/alloc-torture/README.rst           |     10 +
 .../examples/alloc-torture/duk_alloc_torture.c  |    182 +
 .../examples/alloc-torture/duk_alloc_torture.h  |     10 +
 .../duktape-1.5.2/examples/cmdline/README.rst   |      6 +
 .../examples/cmdline/duk_cmdline.c              |   1463 +
 .../examples/cmdline/duk_cmdline_ajduk.c        |   1008 +
 .../examples/codepage-conv/README.rst           |      8 +
 .../examples/codepage-conv/duk_codepage_conv.c  |     54 +
 .../examples/codepage-conv/duk_codepage_conv.h  |      8 +
 .../duktape-1.5.2/examples/codepage-conv/test.c |    286 +
 .../duktape-1.5.2/examples/coffee/README.rst    |     10 +
 .../examples/coffee/globals.coffee              |      7 +
 .../duktape-1.5.2/examples/coffee/hello.coffee  |      2 +
 .../duktape-1.5.2/examples/coffee/mandel.coffee |     28 +
 .../examples/cpp-exceptions/README.rst          |     29 +
 .../examples/cpp-exceptions/cpp_exceptions.cpp  |    274 +
 .../examples/debug-trans-dvalue/README.rst      |      8 +
 .../debug-trans-dvalue/duk_trans_dvalue.c       |   1239 +
 .../debug-trans-dvalue/duk_trans_dvalue.h       |    113 +
 .../examples/debug-trans-dvalue/test.c          |    236 +
 .../examples/debug-trans-socket/README.rst      |     17 +
 .../debug-trans-socket/duk_trans_socket.h       |     15 +
 .../debug-trans-socket/duk_trans_socket_unix.c  |    340 +
 .../duk_trans_socket_windows.c                  |    414 +
 .../examples/dummy-date-provider/README.rst     |      5 +
 .../dummy-date-provider/dummy_date_provider.c   |     27 +
 .../duktape-1.5.2/examples/eval/README.rst      |      5 +
 .../duktape-1.5.2/examples/eval/eval.c          |     48 +
 .../duktape-1.5.2/examples/eventloop/README.rst |     76 +
 .../examples/eventloop/basic-test.js            |     17 +
 .../examples/eventloop/c_eventloop.c            |    618 +
 .../examples/eventloop/c_eventloop.js           |    179 +
 .../examples/eventloop/client-socket-test.js    |     24 +
 .../examples/eventloop/curses-timers.js         |     79 +
 .../examples/eventloop/ecma_eventloop.js        |    466 +
 .../duktape-1.5.2/examples/eventloop/fileio.c   |     69 +
 .../duktape-1.5.2/examples/eventloop/main.c     |    256 +
 .../duktape-1.5.2/examples/eventloop/ncurses.c  |    105 +
 .../duktape-1.5.2/examples/eventloop/poll.c     |    111 +
 .../examples/eventloop/server-socket-test.js    |     34 +
 .../duktape-1.5.2/examples/eventloop/socket.c   |    286 +
 .../duktape-1.5.2/examples/guide/README.rst     |      5 +
 .../duktape-1.5.2/examples/guide/fib.js         |     16 +
 .../duktape-1.5.2/examples/guide/prime.js       |     32 +
 .../duktape-1.5.2/examples/guide/primecheck.c   |     52 +
 .../duktape-1.5.2/examples/guide/process.js     |     12 +
 .../duktape-1.5.2/examples/guide/processlines.c |     59 +
 .../duktape-1.5.2/examples/guide/uppercase.c    |     42 +
 .../duktape-1.5.2/examples/hello/README.rst     |      5 +
 .../duktape-1.5.2/examples/hello/hello.c        |     38 +
 .../duktape-1.5.2/examples/jxpretty/README.rst  |      5 +
 .../duktape-1.5.2/examples/jxpretty/jxpretty.c  |     63 +
 .../duktape-1.5.2/examples/sandbox/README.rst   |      5 +
 .../duktape-1.5.2/examples/sandbox/sandbox.c    |    252 +
 .../third_party/duktape-1.5.2/extras/README.rst |     13 +
 .../src/third_party/duktape-1.5.2/license.spdx  |   3933 +
 .../duktape-1.5.2/licenses/commonjs.txt         |      2 +
 .../third_party/duktape-1.5.2/licenses/lua.txt  |      1 +
 .../duktape-1.5.2/licenses/murmurhash2.txt      |     21 +
 .../src/third_party/duktape-1.5.2/mandel.js     |     53 +
 .../duktape-1.5.2/polyfills/console-minimal.js  |     20 +
 .../duktape-error-setter-nonwritable.js         |     20 +
 .../polyfills/duktape-error-setter-writable.js  |     19 +
 .../polyfills/duktape-isfastint.js              |     38 +
 .../duktape-1.5.2/polyfills/object-assign.js    |     45 +
 .../polyfills/object-prototype-definegetter.js  |     11 +
 .../polyfills/object-prototype-definesetter.js  |     11 +
 .../duktape-1.5.2/polyfills/performance-now.js  |     25 +
 .../duktape-1.5.2/src-noline/duk_config.h       |   3804 +
 .../duktape-1.5.2/src-noline/duktape.c          |  86570 +++++++++
 .../duktape-1.5.2/src-noline/duktape.h          |   1567 +
 .../duktape-1.5.2/src-noline/metadata.json      |    629 +
 .../src-separate/duk_alloc_default.c            |     34 +
 .../duktape-1.5.2/src-separate/duk_api_buffer.c |     73 +
 .../src-separate/duk_api_bytecode.c             |    727 +
 .../duktape-1.5.2/src-separate/duk_api_call.c   |    555 +
 .../duktape-1.5.2/src-separate/duk_api_codec.c  |    638 +
 .../src-separate/duk_api_compile.c              |    194 +
 .../duktape-1.5.2/src-separate/duk_api_debug.c  |    263 +
 .../duktape-1.5.2/src-separate/duk_api_heap.c   |    134 +
 .../src-separate/duk_api_internal.h             |    194 +
 .../src-separate/duk_api_logging.c              |     52 +
 .../duktape-1.5.2/src-separate/duk_api_memory.c |    103 +
 .../duktape-1.5.2/src-separate/duk_api_object.c |    610 +
 .../duktape-1.5.2/src-separate/duk_api_stack.c  |   4658 +
 .../duktape-1.5.2/src-separate/duk_api_string.c |    331 +
 .../duktape-1.5.2/src-separate/duk_api_var.c    |     86 +
 .../duktape-1.5.2/src-separate/duk_bi_array.c   |   1445 +
 .../duktape-1.5.2/src-separate/duk_bi_boolean.c |     68 +
 .../duktape-1.5.2/src-separate/duk_bi_buffer.c  |   2882 +
 .../duktape-1.5.2/src-separate/duk_bi_date.c    |   1728 +
 .../src-separate/duk_bi_date_unix.c             |    309 +
 .../src-separate/duk_bi_date_windows.c          |     98 +
 .../duktape-1.5.2/src-separate/duk_bi_duktape.c |    321 +
 .../duktape-1.5.2/src-separate/duk_bi_error.c   |    383 +
 .../src-separate/duk_bi_function.c              |    346 +
 .../duktape-1.5.2/src-separate/duk_bi_global.c  |   1288 +
 .../duktape-1.5.2/src-separate/duk_bi_json.c    |   3143 +
 .../duktape-1.5.2/src-separate/duk_bi_logger.c  |    300 +
 .../duktape-1.5.2/src-separate/duk_bi_math.c    |    348 +
 .../duktape-1.5.2/src-separate/duk_bi_number.c  |    240 +
 .../duktape-1.5.2/src-separate/duk_bi_object.c  |    577 +
 .../duktape-1.5.2/src-separate/duk_bi_pointer.c |     74 +
 .../duktape-1.5.2/src-separate/duk_bi_protos.h  |     69 +
 .../duktape-1.5.2/src-separate/duk_bi_proxy.c   |     66 +
 .../duktape-1.5.2/src-separate/duk_bi_regexp.c  |    209 +
 .../duktape-1.5.2/src-separate/duk_bi_string.c  |   1314 +
 .../duktape-1.5.2/src-separate/duk_bi_thread.c  |    305 +
 .../duktape-1.5.2/src-separate/duk_bi_thrower.c |     10 +
 .../duktape-1.5.2/src-separate/duk_builtins.c   |    776 +
 .../duktape-1.5.2/src-separate/duk_builtins.h   |    854 +
 .../duktape-1.5.2/src-separate/duk_config.h     |   3804 +
 .../duktape-1.5.2/src-separate/duk_debug.h      |    185 +
 .../src-separate/duk_debug_fixedbuffer.c        |     69 +
 .../duktape-1.5.2/src-separate/duk_debug_heap.c |    247 +
 .../src-separate/duk_debug_macros.c             |    144 +
 .../src-separate/duk_debug_vsnprintf.c          |   1049 +
 .../duktape-1.5.2/src-separate/duk_debugger.c   |   2773 +
 .../duktape-1.5.2/src-separate/duk_debugger.h   |    144 +
 .../duktape-1.5.2/src-separate/duk_error.h      |    439 +
 .../src-separate/duk_error_augment.c            |    567 +
 .../src-separate/duk_error_longjmp.c            |     45 +
 .../src-separate/duk_error_macros.c             |    163 +
 .../duktape-1.5.2/src-separate/duk_error_misc.c |    132 +
 .../src-separate/duk_error_throw.c              |    181 +
 .../duktape-1.5.2/src-separate/duk_exception.h  |     18 +
 .../duktape-1.5.2/src-separate/duk_forwdecl.h   |    122 +
 .../duktape-1.5.2/src-separate/duk_hbuffer.h    |    328 +
 .../src-separate/duk_hbuffer_alloc.c            |    132 +
 .../src-separate/duk_hbuffer_ops.c              |     82 +
 .../src-separate/duk_hbufferobject.h            |    133 +
 .../src-separate/duk_hbufferobject_misc.c       |     20 +
 .../src-separate/duk_hcompiledfunction.h        |    239 +
 .../duktape-1.5.2/src-separate/duk_heap.h       |    596 +
 .../duktape-1.5.2/src-separate/duk_heap_alloc.c |   1042 +
 .../src-separate/duk_heap_hashstring.c          |    120 +
 .../src-separate/duk_heap_markandsweep.c        |   1421 +
 .../src-separate/duk_heap_memory.c              |    384 +
 .../duktape-1.5.2/src-separate/duk_heap_misc.c  |     79 +
 .../src-separate/duk_heap_refcount.c            |    614 +
 .../src-separate/duk_heap_stringcache.c         |    298 +
 .../src-separate/duk_heap_stringtable.c         |   1181 +
 .../duktape-1.5.2/src-separate/duk_heaphdr.h    |    750 +
 .../src-separate/duk_hnativefunction.h          |     32 +
 .../duktape-1.5.2/src-separate/duk_hobject.h    |    926 +
 .../src-separate/duk_hobject_alloc.c            |    192 +
 .../src-separate/duk_hobject_class.c            |    132 +
 .../src-separate/duk_hobject_enum.c             |    626 +
 .../src-separate/duk_hobject_finalizer.c        |    110 +
 .../src-separate/duk_hobject_misc.c             |     52 +
 .../src-separate/duk_hobject_pc2line.c          |    250 +
 .../src-separate/duk_hobject_props.c            |   5999 +
 .../duktape-1.5.2/src-separate/duk_hstring.h    |    219 +
 .../src-separate/duk_hstring_misc.c             |     45 +
 .../duktape-1.5.2/src-separate/duk_hthread.h    |    380 +
 .../src-separate/duk_hthread_alloc.c            |     95 +
 .../src-separate/duk_hthread_builtins.c         |    836 +
 .../src-separate/duk_hthread_misc.c             |    108 +
 .../src-separate/duk_hthread_stacks.c           |    476 +
 .../src-separate/duk_initjs_min.js              |      1 +
 .../duktape-1.5.2/src-separate/duk_internal.h   |     79 +
 .../duktape-1.5.2/src-separate/duk_jmpbuf.h     |     24 +
 .../duktape-1.5.2/src-separate/duk_js.h         |     99 +
 .../src-separate/duk_js_bytecode.h              |    205 +
 .../duktape-1.5.2/src-separate/duk_js_call.c    |   2727 +
 .../src-separate/duk_js_compiler.c              |   7865 +
 .../src-separate/duk_js_compiler.h              |    227 +
 .../src-separate/duk_js_executor.c              |   4507 +
 .../duktape-1.5.2/src-separate/duk_js_ops.c     |   1370 +
 .../duktape-1.5.2/src-separate/duk_js_var.c     |   1821 +
 .../duktape-1.5.2/src-separate/duk_json.h       |     68 +
 .../duktape-1.5.2/src-separate/duk_lexer.c      |   2067 +
 .../duktape-1.5.2/src-separate/duk_lexer.h      |    432 +
 .../duktape-1.5.2/src-separate/duk_numconv.c    |   2266 +
 .../duktape-1.5.2/src-separate/duk_numconv.h    |     90 +
 .../duktape-1.5.2/src-separate/duk_regexp.h     |     82 +
 .../src-separate/duk_regexp_compiler.c          |   1072 +
 .../src-separate/duk_regexp_executor.c          |   1008 +
 .../src-separate/duk_replacements.c             |     82 +
 .../src-separate/duk_replacements.h             |     28 +
 .../duktape-1.5.2/src-separate/duk_selftest.c   |    373 +
 .../duktape-1.5.2/src-separate/duk_selftest.h   |     12 +
 .../duktape-1.5.2/src-separate/duk_strings.c    |    115 +
 .../duktape-1.5.2/src-separate/duk_strings.h    |    252 +
 .../duktape-1.5.2/src-separate/duk_tval.c       |    138 +
 .../duktape-1.5.2/src-separate/duk_tval.h       |    518 +
 .../duktape-1.5.2/src-separate/duk_unicode.h    |    267 +
 .../src-separate/duk_unicode_support.c          |   1173 +
 .../src-separate/duk_unicode_tables.c           |   6119 +
 .../duktape-1.5.2/src-separate/duk_util.h       |    530 +
 .../src-separate/duk_util_bitdecoder.c          |     70 +
 .../src-separate/duk_util_bitencoder.c          |     43 +
 .../src-separate/duk_util_bufwriter.c           |    360 +
 .../src-separate/duk_util_hashbytes.c           |     57 +
 .../src-separate/duk_util_hashprime.c           |     77 +
 .../duktape-1.5.2/src-separate/duk_util_misc.c  |    222 +
 .../src-separate/duk_util_tinyrandom.c          |     63 +
 .../duktape-1.5.2/src-separate/duktape.h        |   1567 +
 .../third_party/duktape-1.5.2/src/duk_config.h  |   3804 +
 .../src/third_party/duktape-1.5.2/src/duktape.c |  86695 +++++++++
 .../src/third_party/duktape-1.5.2/src/duktape.h |   1567 +
 .../third_party/duktape-1.5.2/src/metadata.json |    629 +
 thirdparty/civetweb-1.9.1/src/third_party/lfs.c |    900 +
 thirdparty/civetweb-1.9.1/src/third_party/lfs.h |     32 +
 .../civetweb-1.9.1/src/third_party/lsqlite3.c   |   2214 +
 .../src/third_party/lua-5.1.5/COPYRIGHT         |     34 +
 .../src/third_party/lua-5.1.5/HISTORY           |    183 +
 .../src/third_party/lua-5.1.5/INSTALL           |     99 +
 .../src/third_party/lua-5.1.5/README            |     37 +
 .../src/third_party/lua-5.1.5/doc/contents.html |    497 +
 .../src/third_party/lua-5.1.5/doc/cover.png     |    Bin 0 -> 3305 bytes
 .../src/third_party/lua-5.1.5/doc/logo.gif      |    Bin 0 -> 4232 bytes
 .../src/third_party/lua-5.1.5/doc/lua.1         |    163 +
 .../src/third_party/lua-5.1.5/doc/lua.css       |     83 +
 .../src/third_party/lua-5.1.5/doc/lua.html      |    172 +
 .../src/third_party/lua-5.1.5/doc/luac.1        |    136 +
 .../src/third_party/lua-5.1.5/doc/luac.html     |    145 +
 .../src/third_party/lua-5.1.5/doc/manual.css    |     24 +
 .../src/third_party/lua-5.1.5/doc/manual.html   |   8804 +
 .../src/third_party/lua-5.1.5/doc/readme.html   |     40 +
 .../src/third_party/lua-5.1.5/etc/README        |     37 +
 .../src/third_party/lua-5.1.5/etc/all.c         |     38 +
 .../src/third_party/lua-5.1.5/etc/lua.hpp       |      9 +
 .../src/third_party/lua-5.1.5/etc/lua.ico       |    Bin 0 -> 1078 bytes
 .../src/third_party/lua-5.1.5/etc/lua.pc        |     31 +
 .../src/third_party/lua-5.1.5/etc/luavs.bat     |     28 +
 .../src/third_party/lua-5.1.5/etc/min.c         |     39 +
 .../src/third_party/lua-5.1.5/etc/noparser.c    |     50 +
 .../src/third_party/lua-5.1.5/etc/strict.lua    |     41 +
 .../src/third_party/lua-5.1.5/src/lapi.c        |   1087 +
 .../src/third_party/lua-5.1.5/src/lapi.h        |     16 +
 .../src/third_party/lua-5.1.5/src/lauxlib.c     |    652 +
 .../src/third_party/lua-5.1.5/src/lauxlib.h     |    174 +
 .../src/third_party/lua-5.1.5/src/lbaselib.c    |    653 +
 .../src/third_party/lua-5.1.5/src/lcode.c       |    831 +
 .../src/third_party/lua-5.1.5/src/lcode.h       |     76 +
 .../src/third_party/lua-5.1.5/src/ldblib.c      |    398 +
 .../src/third_party/lua-5.1.5/src/ldebug.c      |    638 +
 .../src/third_party/lua-5.1.5/src/ldebug.h      |     33 +
 .../src/third_party/lua-5.1.5/src/ldo.c         |    519 +
 .../src/third_party/lua-5.1.5/src/ldo.h         |     57 +
 .../src/third_party/lua-5.1.5/src/ldump.c       |    164 +
 .../src/third_party/lua-5.1.5/src/lfunc.c       |    174 +
 .../src/third_party/lua-5.1.5/src/lfunc.h       |     34 +
 .../src/third_party/lua-5.1.5/src/lgc.c         |    710 +
 .../src/third_party/lua-5.1.5/src/lgc.h         |    110 +
 .../src/third_party/lua-5.1.5/src/linit.c       |     38 +
 .../src/third_party/lua-5.1.5/src/liolib.c      |    556 +
 .../src/third_party/lua-5.1.5/src/llex.c        |    463 +
 .../src/third_party/lua-5.1.5/src/llex.h        |     81 +
 .../src/third_party/lua-5.1.5/src/llimits.h     |    128 +
 .../src/third_party/lua-5.1.5/src/lmathlib.c    |    263 +
 .../src/third_party/lua-5.1.5/src/lmem.c        |     86 +
 .../src/third_party/lua-5.1.5/src/lmem.h        |     49 +
 .../src/third_party/lua-5.1.5/src/loadlib.c     |    666 +
 .../src/third_party/lua-5.1.5/src/lobject.c     |    214 +
 .../src/third_party/lua-5.1.5/src/lobject.h     |    381 +
 .../src/third_party/lua-5.1.5/src/lopcodes.c    |    102 +
 .../src/third_party/lua-5.1.5/src/lopcodes.h    |    268 +
 .../src/third_party/lua-5.1.5/src/loslib.c      |    243 +
 .../src/third_party/lua-5.1.5/src/lparser.c     |   1339 +
 .../src/third_party/lua-5.1.5/src/lparser.h     |     82 +
 .../src/third_party/lua-5.1.5/src/lstate.c      |    214 +
 .../src/third_party/lua-5.1.5/src/lstate.h      |    169 +
 .../src/third_party/lua-5.1.5/src/lstring.c     |    111 +
 .../src/third_party/lua-5.1.5/src/lstring.h     |     31 +
 .../src/third_party/lua-5.1.5/src/lstrlib.c     |    871 +
 .../src/third_party/lua-5.1.5/src/ltable.c      |    588 +
 .../src/third_party/lua-5.1.5/src/ltable.h      |     40 +
 .../src/third_party/lua-5.1.5/src/ltablib.c     |    287 +
 .../src/third_party/lua-5.1.5/src/ltm.c         |     75 +
 .../src/third_party/lua-5.1.5/src/ltm.h         |     54 +
 .../src/third_party/lua-5.1.5/src/lua.c         |    392 +
 .../src/third_party/lua-5.1.5/src/lua.h         |    388 +
 .../src/third_party/lua-5.1.5/src/luac.c        |    200 +
 .../src/third_party/lua-5.1.5/src/luaconf.h     |    763 +
 .../src/third_party/lua-5.1.5/src/lualib.h      |     53 +
 .../src/third_party/lua-5.1.5/src/lundump.c     |    227 +
 .../src/third_party/lua-5.1.5/src/lundump.h     |     36 +
 .../src/third_party/lua-5.1.5/src/lvm.c         |    767 +
 .../src/third_party/lua-5.1.5/src/lvm.h         |     36 +
 .../src/third_party/lua-5.1.5/src/lzio.c        |     82 +
 .../src/third_party/lua-5.1.5/src/lzio.h        |     67 +
 .../src/third_party/lua-5.1.5/src/print.c       |    227 +
 .../src/third_party/lua-5.1.5/test/README       |     26 +
 .../src/third_party/lua-5.1.5/test/bisect.lua   |     27 +
 .../src/third_party/lua-5.1.5/test/cf.lua       |     16 +
 .../src/third_party/lua-5.1.5/test/echo.lua     |      5 +
 .../src/third_party/lua-5.1.5/test/env.lua      |      7 +
 .../third_party/lua-5.1.5/test/factorial.lua    |     32 +
 .../src/third_party/lua-5.1.5/test/fib.lua      |     40 +
 .../src/third_party/lua-5.1.5/test/fibfor.lua   |     13 +
 .../src/third_party/lua-5.1.5/test/globals.lua  |     13 +
 .../src/third_party/lua-5.1.5/test/hello.lua    |      3 +
 .../src/third_party/lua-5.1.5/test/life.lua     |    111 +
 .../src/third_party/lua-5.1.5/test/luac.lua     |      7 +
 .../src/third_party/lua-5.1.5/test/printf.lua   |      7 +
 .../src/third_party/lua-5.1.5/test/readonly.lua |     12 +
 .../src/third_party/lua-5.1.5/test/sieve.lua    |     29 +
 .../src/third_party/lua-5.1.5/test/sort.lua     |     66 +
 .../src/third_party/lua-5.1.5/test/table.lua    |     12 +
 .../third_party/lua-5.1.5/test/trace-calls.lua  |     32 +
 .../lua-5.1.5/test/trace-globals.lua            |     38 +
 .../src/third_party/lua-5.1.5/test/xd.lua       |     14 +
 .../src/third_party/lua-5.2.4/README            |      6 +
 .../src/third_party/lua-5.2.4/doc/contents.html |    608 +
 .../src/third_party/lua-5.2.4/doc/logo.gif      |    Bin 0 -> 4232 bytes
 .../src/third_party/lua-5.2.4/doc/lua.1         |    116 +
 .../src/third_party/lua-5.2.4/doc/lua.css       |    106 +
 .../src/third_party/lua-5.2.4/doc/luac.1        |    118 +
 .../src/third_party/lua-5.2.4/doc/manual.css    |     27 +
 .../src/third_party/lua-5.2.4/doc/manual.html   |  10508 ++
 .../lua-5.2.4/doc/osi-certified-72x60.png       |    Bin 0 -> 3774 bytes
 .../src/third_party/lua-5.2.4/doc/readme.html   |    417 +
 .../src/third_party/lua-5.2.4/src/lapi.c        |   1284 +
 .../src/third_party/lua-5.2.4/src/lapi.h        |     24 +
 .../src/third_party/lua-5.2.4/src/lauxlib.c     |    959 +
 .../src/third_party/lua-5.2.4/src/lauxlib.h     |    212 +
 .../src/third_party/lua-5.2.4/src/lbaselib.c    |    458 +
 .../src/third_party/lua-5.2.4/src/lbitlib.c     |    212 +
 .../src/third_party/lua-5.2.4/src/lcode.c       |    881 +
 .../src/third_party/lua-5.2.4/src/lcode.h       |     83 +
 .../src/third_party/lua-5.2.4/src/lcorolib.c    |    155 +
 .../src/third_party/lua-5.2.4/src/lctype.c      |     52 +
 .../src/third_party/lua-5.2.4/src/lctype.h      |     95 +
 .../src/third_party/lua-5.2.4/src/ldblib.c      |    408 +
 .../src/third_party/lua-5.2.4/src/ldebug.c      |    610 +
 .../src/third_party/lua-5.2.4/src/ldebug.h      |     34 +
 .../src/third_party/lua-5.2.4/src/ldo.c         |    681 +
 .../src/third_party/lua-5.2.4/src/ldo.h         |     46 +
 .../src/third_party/lua-5.2.4/src/ldump.c       |    173 +
 .../src/third_party/lua-5.2.4/src/lfunc.c       |    161 +
 .../src/third_party/lua-5.2.4/src/lfunc.h       |     33 +
 .../src/third_party/lua-5.2.4/src/lgc.c         |   1220 +
 .../src/third_party/lua-5.2.4/src/lgc.h         |    157 +
 .../src/third_party/lua-5.2.4/src/linit.c       |     67 +
 .../src/third_party/lua-5.2.4/src/liolib.c      |    666 +
 .../src/third_party/lua-5.2.4/src/llex.c        |    530 +
 .../src/third_party/lua-5.2.4/src/llex.h        |     78 +
 .../src/third_party/lua-5.2.4/src/llimits.h     |    309 +
 .../src/third_party/lua-5.2.4/src/lmathlib.c    |    279 +
 .../src/third_party/lua-5.2.4/src/lmem.c        |     99 +
 .../src/third_party/lua-5.2.4/src/lmem.h        |     57 +
 .../src/third_party/lua-5.2.4/src/loadlib.c     |    725 +
 .../src/third_party/lua-5.2.4/src/lobject.c     |    287 +
 .../src/third_party/lua-5.2.4/src/lobject.h     |    607 +
 .../src/third_party/lua-5.2.4/src/lopcodes.c    |    107 +
 .../src/third_party/lua-5.2.4/src/lopcodes.h    |    288 +
 .../src/third_party/lua-5.2.4/src/loslib.c      |    323 +
 .../src/third_party/lua-5.2.4/src/lparser.c     |   1638 +
 .../src/third_party/lua-5.2.4/src/lparser.h     |    119 +
 .../src/third_party/lua-5.2.4/src/lstate.c      |    323 +
 .../src/third_party/lua-5.2.4/src/lstate.h      |    228 +
 .../src/third_party/lua-5.2.4/src/lstring.c     |    185 +
 .../src/third_party/lua-5.2.4/src/lstring.h     |     46 +
 .../src/third_party/lua-5.2.4/src/lstrlib.c     |   1019 +
 .../src/third_party/lua-5.2.4/src/ltable.c      |    588 +
 .../src/third_party/lua-5.2.4/src/ltable.h      |     45 +
 .../src/third_party/lua-5.2.4/src/ltablib.c     |    285 +
 .../src/third_party/lua-5.2.4/src/ltm.c         |     77 +
 .../src/third_party/lua-5.2.4/src/ltm.h         |     57 +
 .../src/third_party/lua-5.2.4/src/lua.c         |    497 +
 .../src/third_party/lua-5.2.4/src/lua.h         |    444 +
 .../src/third_party/lua-5.2.4/src/lua.hpp       |      9 +
 .../src/third_party/lua-5.2.4/src/luac.c        |    432 +
 .../src/third_party/lua-5.2.4/src/luaconf.h     |    551 +
 .../src/third_party/lua-5.2.4/src/lualib.h      |     55 +
 .../src/third_party/lua-5.2.4/src/lundump.c     |    258 +
 .../src/third_party/lua-5.2.4/src/lundump.h     |     28 +
 .../src/third_party/lua-5.2.4/src/lvm.c         |    867 +
 .../src/third_party/lua-5.2.4/src/lvm.h         |     44 +
 .../src/third_party/lua-5.2.4/src/lzio.c        |     76 +
 .../src/third_party/lua-5.2.4/src/lzio.h        |     65 +
 .../src/third_party/lua-5.3.3/README            |      6 +
 .../src/third_party/lua-5.3.3/doc/contents.html |    618 +
 .../src/third_party/lua-5.3.3/doc/index.css     |     21 +
 .../src/third_party/lua-5.3.3/doc/logo.gif      |    Bin 0 -> 4232 bytes
 .../src/third_party/lua-5.3.3/doc/lua.1         |    111 +
 .../src/third_party/lua-5.3.3/doc/lua.css       |    164 +
 .../src/third_party/lua-5.3.3/doc/luac.1        |    118 +
 .../src/third_party/lua-5.3.3/doc/manual.css    |     21 +
 .../src/third_party/lua-5.3.3/doc/manual.html   |  10910 ++
 .../lua-5.3.3/doc/osi-certified-72x60.png       |    Bin 0 -> 3774 bytes
 .../src/third_party/lua-5.3.3/doc/readme.html   |    365 +
 .../src/third_party/lua-5.3.3/src/lapi.c        |   1298 +
 .../src/third_party/lua-5.3.3/src/lapi.h        |     24 +
 .../src/third_party/lua-5.3.3/src/lauxlib.c     |   1035 +
 .../src/third_party/lua-5.3.3/src/lauxlib.h     |    256 +
 .../src/third_party/lua-5.3.3/src/lbaselib.c    |    498 +
 .../src/third_party/lua-5.3.3/src/lbitlib.c     |    233 +
 .../src/third_party/lua-5.3.3/src/lcode.c       |   1199 +
 .../src/third_party/lua-5.3.3/src/lcode.h       |     88 +
 .../src/third_party/lua-5.3.3/src/lcorolib.c    |    168 +
 .../src/third_party/lua-5.3.3/src/lctype.c      |     55 +
 .../src/third_party/lua-5.3.3/src/lctype.h      |     95 +
 .../src/third_party/lua-5.3.3/src/ldblib.c      |    456 +
 .../src/third_party/lua-5.3.3/src/ldebug.c      |    679 +
 .../src/third_party/lua-5.3.3/src/ldebug.h      |     39 +
 .../src/third_party/lua-5.3.3/src/ldo.c         |    800 +
 .../src/third_party/lua-5.3.3/src/ldo.h         |     58 +
 .../src/third_party/lua-5.3.3/src/ldump.c       |    215 +
 .../src/third_party/lua-5.3.3/src/lfunc.c       |    151 +
 .../src/third_party/lua-5.3.3/src/lfunc.h       |     61 +
 .../src/third_party/lua-5.3.3/src/lgc.c         |   1176 +
 .../src/third_party/lua-5.3.3/src/lgc.h         |    147 +
 .../src/third_party/lua-5.3.3/src/linit.c       |     68 +
 .../src/third_party/lua-5.3.3/src/liolib.c      |    768 +
 .../src/third_party/lua-5.3.3/src/llex.c        |    565 +
 .../src/third_party/lua-5.3.3/src/llex.h        |     85 +
 .../src/third_party/lua-5.3.3/src/llimits.h     |    323 +
 .../src/third_party/lua-5.3.3/src/lmathlib.c    |    407 +
 .../src/third_party/lua-5.3.3/src/lmem.c        |    100 +
 .../src/third_party/lua-5.3.3/src/lmem.h        |     69 +
 .../src/third_party/lua-5.3.3/src/loadlib.c     |    787 +
 .../src/third_party/lua-5.3.3/src/lobject.c     |    521 +
 .../src/third_party/lua-5.3.3/src/lobject.h     |    549 +
 .../src/third_party/lua-5.3.3/src/lopcodes.c    |    124 +
 .../src/third_party/lua-5.3.3/src/lopcodes.h    |    295 +
 .../src/third_party/lua-5.3.3/src/loslib.c      |    403 +
 .../src/third_party/lua-5.3.3/src/lparser.c     |   1652 +
 .../src/third_party/lua-5.3.3/src/lparser.h     |    133 +
 .../src/third_party/lua-5.3.3/src/lprefix.h     |     45 +
 .../src/third_party/lua-5.3.3/src/lstate.c      |    347 +
 .../src/third_party/lua-5.3.3/src/lstate.h      |    234 +
 .../src/third_party/lua-5.3.3/src/lstring.c     |    248 +
 .../src/third_party/lua-5.3.3/src/lstring.h     |     49 +
 .../src/third_party/lua-5.3.3/src/lstrlib.c     |   1582 +
 .../src/third_party/lua-5.3.3/src/ltable.c      |    669 +
 .../src/third_party/lua-5.3.3/src/ltable.h      |     58 +
 .../src/third_party/lua-5.3.3/src/ltablib.c     |    450 +
 .../src/third_party/lua-5.3.3/src/ltm.c         |    165 +
 .../src/third_party/lua-5.3.3/src/ltm.h         |     76 +
 .../src/third_party/lua-5.3.3/src/lua.c         |    609 +
 .../src/third_party/lua-5.3.3/src/lua.h         |    486 +
 .../src/third_party/lua-5.3.3/src/lua.hpp       |      9 +
 .../src/third_party/lua-5.3.3/src/luac.c        |    449 +
 .../src/third_party/lua-5.3.3/src/luaconf.h     |    767 +
 .../src/third_party/lua-5.3.3/src/lualib.h      |     58 +
 .../src/third_party/lua-5.3.3/src/lundump.c     |    279 +
 .../src/third_party/lua-5.3.3/src/lundump.h     |     32 +
 .../src/third_party/lua-5.3.3/src/lutf8lib.c    |    256 +
 .../src/third_party/lua-5.3.3/src/lvm.c         |   1322 +
 .../src/third_party/lua-5.3.3/src/lvm.h         |    113 +
 .../src/third_party/lua-5.3.3/src/lzio.c        |     68 +
 .../src/third_party/lua-5.3.3/src/lzio.h        |     66 +
 .../civetweb-1.9.1/src/third_party/sqlite3.c    | 155866 ++++++++++++++++
 .../civetweb-1.9.1/src/third_party/sqlite3.h    |   7831 +
 thirdparty/civetweb-1.9.1/src/timer.inl         |    213 +
 thirdparty/civetweb-1.9.1/test/.leading.dot.txt |      1 +
 thirdparty/civetweb-1.9.1/test/1000images.lua   |    199 +
 thirdparty/civetweb-1.9.1/test/100images.htm    |    160 +
 thirdparty/civetweb-1.9.1/test/CMakeLists.txt   |    224 +
 thirdparty/civetweb-1.9.1/test/HugeText.lua     |    149 +
 thirdparty/civetweb-1.9.1/test/MakefileTest.mk  |     88 +
 thirdparty/civetweb-1.9.1/test/MethodTest.xhtml |    200 +
 thirdparty/civetweb-1.9.1/test/README.md        |     25 +
 thirdparty/civetweb-1.9.1/test/ajax/echo.cgi    |      8 +
 .../civetweb-1.9.1/test/ajax/echo.cgi.old       |     73 +
 thirdparty/civetweb-1.9.1/test/ajax/echo.lp     |      9 +
 thirdparty/civetweb-1.9.1/test/ajax/echo.lua    |     35 +
 thirdparty/civetweb-1.9.1/test/ajax/jquery.js   |      4 +
 thirdparty/civetweb-1.9.1/test/ajax/test.html   |    168 +
 .../civetweb-1.9.1/test/all_build_flags.pl      |     28 +
 thirdparty/civetweb-1.9.1/test/bad.cgi          |      5 +
 thirdparty/civetweb-1.9.1/test/bad2.cgi         |      3 +
 thirdparty/civetweb-1.9.1/test/bad_page.lp      |      1 +
 thirdparty/civetweb-1.9.1/test/bad_script.lua   |      1 +
 thirdparty/civetweb-1.9.1/test/cgi_test.c       |     40 +
 thirdparty/civetweb-1.9.1/test/cgi_test.html    |     12 +
 thirdparty/civetweb-1.9.1/test/civetweb_check.h |     60 +
 thirdparty/civetweb-1.9.1/test/cors.html        |     75 +
 thirdparty/civetweb-1.9.1/test/cors.reply.html  |      7 +
 thirdparty/civetweb-1.9.1/test/cors.reply.lua   |     73 +
 thirdparty/civetweb-1.9.1/test/cors.reply.shtml |      7 +
 .../test/dir with spaces/hello.cgi              |      3 +
 thirdparty/civetweb-1.9.1/test/echo.lua         |     41 +
 thirdparty/civetweb-1.9.1/test/embed.c          |    182 +
 thirdparty/civetweb-1.9.1/test/env.cgi          |     46 +
 thirdparty/civetweb-1.9.1/test/error.lua        |     12 +
 thirdparty/civetweb-1.9.1/test/error404.htm     |     10 +
 thirdparty/civetweb-1.9.1/test/exit.lua         |     15 +
 thirdparty/civetweb-1.9.1/test/exploit.pl       |     69 +
 thirdparty/civetweb-1.9.1/test/filehandler.lua  |     93 +
 thirdparty/civetweb-1.9.1/test/form.html        |    118 +
 thirdparty/civetweb-1.9.1/test/handle_form.lua  |    123 +
 thirdparty/civetweb-1.9.1/test/hello.cgi        |      6 +
 thirdparty/civetweb-1.9.1/test/hello.shtml      |      5 +
 thirdparty/civetweb-1.9.1/test/hello.txt        |      1 +
 thirdparty/civetweb-1.9.1/test/hello_gz.txt.gz  |    Bin 0 -> 66 bytes
 .../civetweb-1.9.1/test/hello_gz_unzipped.txt   |      1 +
 thirdparty/civetweb-1.9.1/test/html_esc.lua     |     60 +
 thirdparty/civetweb-1.9.1/test/imagetest/00.png |    Bin 0 -> 566 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/01.png |    Bin 0 -> 587 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/02.png |    Bin 0 -> 701 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/03.png |    Bin 0 -> 741 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/04.png |    Bin 0 -> 622 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/05.png |    Bin 0 -> 711 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/06.png |    Bin 0 -> 748 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/07.png |    Bin 0 -> 645 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/08.png |    Bin 0 -> 759 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/09.png |    Bin 0 -> 760 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/10.png |    Bin 0 -> 584 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/11.png |    Bin 0 -> 386 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/12.png |    Bin 0 -> 529 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/13.png |    Bin 0 -> 575 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/14.png |    Bin 0 -> 451 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/15.png |    Bin 0 -> 547 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/16.png |    Bin 0 -> 600 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/17.png |    Bin 0 -> 477 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/18.png |    Bin 0 -> 597 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/19.png |    Bin 0 -> 600 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/20.png |    Bin 0 -> 700 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/21.png |    Bin 0 -> 533 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/22.png |    Bin 0 -> 514 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/23.png |    Bin 0 -> 679 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/24.png |    Bin 0 -> 564 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/25.png |    Bin 0 -> 656 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/26.png |    Bin 0 -> 694 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/27.png |    Bin 0 -> 586 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/28.png |    Bin 0 -> 695 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/29.png |    Bin 0 -> 712 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/30.png |    Bin 0 -> 736 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/31.png |    Bin 0 -> 572 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/32.png |    Bin 0 -> 682 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/33.png |    Bin 0 -> 556 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/34.png |    Bin 0 -> 612 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/35.png |    Bin 0 -> 695 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/36.png |    Bin 0 -> 739 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/37.png |    Bin 0 -> 636 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/38.png |    Bin 0 -> 747 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/39.png |    Bin 0 -> 736 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/40.png |    Bin 0 -> 623 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/41.png |    Bin 0 -> 448 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/42.png |    Bin 0 -> 560 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/43.png |    Bin 0 -> 610 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/44.png |    Bin 0 -> 441 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/45.png |    Bin 0 -> 584 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/46.png |    Bin 0 -> 632 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/47.png |    Bin 0 -> 522 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/48.png |    Bin 0 -> 634 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/49.png |    Bin 0 -> 637 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/50.png |    Bin 0 -> 709 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/51.png |    Bin 0 -> 550 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/52.png |    Bin 0 -> 661 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/53.png |    Bin 0 -> 696 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/54.png |    Bin 0 -> 587 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/55.png |    Bin 0 -> 544 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/56.png |    Bin 0 -> 718 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/57.png |    Bin 0 -> 610 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/58.png |    Bin 0 -> 721 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/59.png |    Bin 0 -> 725 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/60.png |    Bin 0 -> 751 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/61.png |    Bin 0 -> 600 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/62.png |    Bin 0 -> 710 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/63.png |    Bin 0 -> 744 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/64.png |    Bin 0 -> 631 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/65.png |    Bin 0 -> 726 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/66.png |    Bin 0 -> 584 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/67.png |    Bin 0 -> 659 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/68.png |    Bin 0 -> 766 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/69.png |    Bin 0 -> 766 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/70.png |    Bin 0 -> 640 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/71.png |    Bin 0 -> 474 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/72.png |    Bin 0 -> 584 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/73.png |    Bin 0 -> 631 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/74.png |    Bin 0 -> 517 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/75.png |    Bin 0 -> 603 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/76.png |    Bin 0 -> 650 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/77.png |    Bin 0 -> 453 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/78.png |    Bin 0 -> 653 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/79.png |    Bin 0 -> 655 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/80.png |    Bin 0 -> 759 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/81.png |    Bin 0 -> 596 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/82.png |    Bin 0 -> 714 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/83.png |    Bin 0 -> 751 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/84.png |    Bin 0 -> 634 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/85.png |    Bin 0 -> 724 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/86.png |    Bin 0 -> 766 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/87.png |    Bin 0 -> 660 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/88.png |    Bin 0 -> 579 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/89.png |    Bin 0 -> 778 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/90.png |    Bin 0 -> 756 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/91.png |    Bin 0 -> 604 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/92.png |    Bin 0 -> 716 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/93.png |    Bin 0 -> 735 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/94.png |    Bin 0 -> 634 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/95.png |    Bin 0 -> 726 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/96.png |    Bin 0 -> 763 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/97.png |    Bin 0 -> 660 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/98.png |    Bin 0 -> 776 bytes
 thirdparty/civetweb-1.9.1/test/imagetest/99.png |    Bin 0 -> 590 bytes
 thirdparty/civetweb-1.9.1/test/linux.cgi        |      9 +
 thirdparty/civetweb-1.9.1/test/linux_fail.cgi   |      4 +
 .../civetweb-1.9.1/test/linux_fail_silent.cgi   |      5 +
 .../civetweb-1.9.1/test/lua_preload_file.lua    |      7 +
 thirdparty/civetweb-1.9.1/test/main.c           |     96 +
 thirdparty/civetweb-1.9.1/test/page.lp          |     71 +
 thirdparty/civetweb-1.9.1/test/page.lua         |     71 +
 thirdparty/civetweb-1.9.1/test/page.ssjs        |     19 +
 thirdparty/civetweb-1.9.1/test/page2.lp         |     72 +
 thirdparty/civetweb-1.9.1/test/page2.lua        |     87 +
 thirdparty/civetweb-1.9.1/test/page2.ssjs       |     30 +
 thirdparty/civetweb-1.9.1/test/page3.lua        |     34 +
 thirdparty/civetweb-1.9.1/test/page3.ssjs       |     61 +
 thirdparty/civetweb-1.9.1/test/page4.lua        |    180 +
 thirdparty/civetweb-1.9.1/test/page5.lua        |      8 +
 .../civetweb-1.9.1/test/page_keep_alive.lua     |     32 +
 .../test/page_keep_alive_chunked.lua            |     66 +
 thirdparty/civetweb-1.9.1/test/passfile         |      3 +
 thirdparty/civetweb-1.9.1/test/prime.ssjs       |     36 +
 thirdparty/civetweb-1.9.1/test/private.c        |    819 +
 thirdparty/civetweb-1.9.1/test/private.h        |     28 +
 thirdparty/civetweb-1.9.1/test/private_exe.c    |     79 +
 thirdparty/civetweb-1.9.1/test/private_exe.h    |     31 +
 thirdparty/civetweb-1.9.1/test/public_func.c    |    532 +
 thirdparty/civetweb-1.9.1/test/public_func.h    |     28 +
 thirdparty/civetweb-1.9.1/test/public_server.c  |   3733 +
 thirdparty/civetweb-1.9.1/test/public_server.h  |     28 +
 thirdparty/civetweb-1.9.1/test/require_test.lua |      2 +
 .../test/resource_script_demo.lua               |    124 +
 thirdparty/civetweb-1.9.1/test/shared.c         |     48 +
 thirdparty/civetweb-1.9.1/test/shared.h         |     27 +
 thirdparty/civetweb-1.9.1/test/ssi_test.shtml   |     37 +
 .../civetweb-1.9.1/test/syntax_error.ssjs       |      7 +
 thirdparty/civetweb-1.9.1/test/test.ico         |    Bin 0 -> 1406 bytes
 thirdparty/civetweb-1.9.1/test/test.pl          |    461 +
 thirdparty/civetweb-1.9.1/test/testclient.c     |    151 +
 thirdparty/civetweb-1.9.1/test/timeout.cgi      |     12 +
 thirdparty/civetweb-1.9.1/test/timertest.c      |    348 +
 thirdparty/civetweb-1.9.1/test/timertest.h      |     28 +
 thirdparty/civetweb-1.9.1/test/websocket.lua    |    118 +
 thirdparty/civetweb-1.9.1/test/websocket.xhtml  |    117 +
 thirdparty/civetweb-1.9.1/test/windows.cgi      |      2 +
 thirdparty/civetweb-1.9.1/test/windows.cgi.cmd  |      7 +
 thirdparty/civetweb-1.9.1/test/windows_fail.cgi |      2 +
 .../civetweb-1.9.1/test/windows_fail.cgi.cmd    |      2 +
 .../civetweb-1.9.1/test/windows_fail_silent.cgi |      2 +
 .../test/windows_fail_silent.cgi.cmd            |      3 +
 thirdparty/civetweb-1.9.1/test/x.php            |      9 +
 918 files changed, 624116 insertions(+), 52 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 8eba073..7ae1f8e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -46,6 +46,9 @@ endif()
 set(CMAKE_CXX_STANDARD 11)
 set(CMAKE_CXX_STANDARD_REQUIRED ON)
 
+# Enable asan in DEBUG for compatibility with civet
+set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fsanitize=address")
+
 # Search for threads
 find_package(Threads REQUIRED)
 
@@ -56,7 +59,7 @@ else()
 set(OPENSSL_ROOT_DIR "/usr/lib/x86_64-linux-gnu")
 endif()
 
-# Include OpenSSL 
+# Include OpenSSL
 find_package (OpenSSL REQUIRED)
 if (OPENSSL_FOUND)
 	include_directories(${OPENSSL_INCLUDE_DIR})
@@ -78,6 +81,8 @@ find_package(UUID REQUIRED)
 file(GLOB SPD_SOURCES "include/spdlog/*")
 
 add_subdirectory(thirdparty/yaml-cpp-yaml-cpp-0.5.3)
+set(CIVETWEB_ENABLE_CXX ON CACHE BOOL "Enable civet C++ library")
+add_subdirectory(thirdparty/civetweb-1.9.1)
 add_subdirectory(libminifi)
 add_subdirectory(main)
 
@@ -115,7 +120,7 @@ set(CPACK_COMPONENTS_ALL bin)
 
 include(CPack)
 
-enable_testing(test) 
+enable_testing(test)
     file(GLOB LIBMINIFI_TEST_SOURCES "libminifi/test/unit/*.cpp")
     add_executable(tests ${LIBMINIFI_TEST_SOURCES} ${SPD_SOURCES})
     target_include_directories(tests PRIVATE BEFORE "thirdparty/catch")
@@ -123,5 +128,5 @@ enable_testing(test)
     target_include_directories(tests PRIVATE BEFORE ${LEVELDB_INCLUDE_DIRS})
     target_include_directories(tests PRIVATE BEFORE "include")
     target_include_directories(tests PRIVATE BEFORE "libminifi/include/")
-    target_link_libraries(tests ${CMAKE_THREAD_LIBS_INIT} ${UUID_LIBRARIES} ${LEVELDB_LIBRARIES} ${OPENSSL_LIBRARIES} minifi yaml-cpp)
+    target_link_libraries(tests ${CMAKE_THREAD_LIBS_INIT} ${UUID_LIBRARIES} ${LEVELDB_LIBRARIES} ${OPENSSL_LIBRARIES} minifi yaml-cpp c-library civetweb-cpp)
     add_test(NAME LibMinifiTests COMMAND tests)

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/LICENSE
----------------------------------------------------------------------
diff --git a/LICENSE b/LICENSE
index d72606a..64b724c 100644
--- a/LICENSE
+++ b/LICENSE
@@ -441,4 +441,32 @@ FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
 SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
 FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
-DEALINGS IN THE SOFTWARE.
\ No newline at end of file
+DEALINGS IN THE SOFTWARE.
+
+This product bundles 'CivetWeb' which is available under a MIT license.
+
+Copyright (c) 2013-2015 The CivetWeb developers (CREDITS.md)
+
+Copyright (c) 2004-2013 Sergey Lyubka
+
+Copyright (c) 2013 No Face Press, LLC (Thomas Davis)
+
+Copyright (c) 2013 F-Secure Corporation
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of
+this software and associated documentation files (the "Software"), to deal in
+the Software without restriction, including without limitation the rights to
+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+the Software, and to permit persons to whom the Software is furnished to do so,
+subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/libminifi/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/libminifi/CMakeLists.txt b/libminifi/CMakeLists.txt
index 8f77ed8..269492c 100644
--- a/libminifi/CMakeLists.txt
+++ b/libminifi/CMakeLists.txt
@@ -38,6 +38,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
 
 include_directories(../include)
 include_directories(../thirdparty/yaml-cpp-yaml-cpp-0.5.3/include)
+include_directories(../thirdparty/civetweb-1.9.1/include)
 include_directories(include)
 
 file(GLOB SOURCES "src/*.cpp")
@@ -48,6 +49,10 @@ file(GLOB SPD_SOURCES "../include/spdlog/*")
 add_library(spdlog STATIC ${SPD_SOURCES})
 add_library(minifi STATIC ${SOURCES})
 
+# Include Boost System
+find_package(Boost COMPONENTS system REQUIRED)
+target_link_libraries(minifi ${Boost_SYSTEM_LIBRARY})
+
 # Include LevelDB
 find_package (Leveldb REQUIRED)
 if (LEVELDB_FOUND)
@@ -57,7 +62,7 @@ else ()
     message( FATAL_ERROR "LevelDB was not found. Please install LevelDB" )
 endif (LEVELDB_FOUND)
 
-# Include OpenSSL 
+# Include OpenSSL
 find_package (OpenSSL REQUIRED)
 if (OPENSSL_FOUND)
 	include_directories(${OPENSSL_INCLUDE_DIR})

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/libminifi/include/EventDrivenSchedulingAgent.h
----------------------------------------------------------------------
diff --git a/libminifi/include/EventDrivenSchedulingAgent.h b/libminifi/include/EventDrivenSchedulingAgent.h
index f6e6ffb..b32f84f 100644
--- a/libminifi/include/EventDrivenSchedulingAgent.h
+++ b/libminifi/include/EventDrivenSchedulingAgent.h
@@ -42,7 +42,7 @@ public:
 	{
 	}
 	//! Run function for the thread
-	void run(Processor *processor);
+	void run(Processor *processor, ProcessContext *processContext, ProcessSessionFactory *sessionFactory);
 
 private:
 	// Prevent default copy constructor and assignment operation

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/libminifi/include/FlowController.h
----------------------------------------------------------------------
diff --git a/libminifi/include/FlowController.h b/libminifi/include/FlowController.h
index 02c39b1..561cd1b 100644
--- a/libminifi/include/FlowController.h
+++ b/libminifi/include/FlowController.h
@@ -51,6 +51,7 @@
 #include "PutFile.h"
 #include "TailFile.h"
 #include "ListenSyslog.h"
+#include "ListenHTTP.h"
 #include "ExecuteProcess.h"
 #include "AppendHostInfo.h"
 // OpenSSL related

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/libminifi/include/ListenHTTP.h
----------------------------------------------------------------------
diff --git a/libminifi/include/ListenHTTP.h b/libminifi/include/ListenHTTP.h
new file mode 100644
index 0000000..57fd967
--- /dev/null
+++ b/libminifi/include/ListenHTTP.h
@@ -0,0 +1,116 @@
+/**
+ * @file ListenHTTP.h
+ * ListenHTTP class declaration
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __LISTEN_HTTP_H__
+#define __LISTEN_HTTP_H__
+
+#include <memory>
+#include <regex>
+
+#include <CivetServer.h>
+
+#include "FlowFileRecord.h"
+#include "Processor.h"
+#include "ProcessSession.h"
+
+
+//! ListenHTTP Class
+class ListenHTTP : public Processor
+{
+public:
+
+	//! Constructor
+	/*!
+	 * Create a new processor
+	 */
+	ListenHTTP(std::string name, uuid_t uuid = NULL)
+	: Processor(name, uuid)
+	{
+		_logger = Logger::getLogger();
+	}
+	//! Destructor
+	~ListenHTTP()
+	{
+	}
+	//! Processor Name
+	static const std::string ProcessorName;
+	//! Supported Properties
+	static Property BasePath;
+	static Property Port;
+	static Property AuthorizedDNPattern;
+	static Property SSLCertificate;
+	static Property SSLCertificateAuthority;
+	static Property SSLVerifyPeer;
+	static Property SSLMinimumVersion;
+	static Property HeadersAsAttributesRegex;
+	//! Supported Relationships
+	static Relationship Success;
+
+	void onTrigger(ProcessContext *context, ProcessSession *session);
+	void initialize();
+	void onSchedule(ProcessContext *context, ProcessSessionFactory *sessionFactory);
+
+	//! HTTP request handler
+	class Handler : public CivetHandler
+	{
+	public:
+		Handler(ProcessContext *context,
+				ProcessSessionFactory *sessionFactory,
+				std::string &&authDNPattern,
+				std::string &&headersAsAttributesPattern);
+		bool handlePost(CivetServer *server, struct mg_connection *conn);
+
+	private:
+		//! Send HTTP 500 error response to client
+		void sendErrorResponse(struct mg_connection *conn);
+		//! Logger
+		Logger *_logger;
+
+		std::regex _authDNRegex;
+		std::regex _headersAsAttributesRegex;
+		ProcessContext *_processContext;
+		ProcessSessionFactory *_processSessionFactory;
+	};
+
+	//! Write callback for transferring data from HTTP request to content repo
+	class WriteCallback : public OutputStreamCallback
+	{
+	public:
+		WriteCallback(struct mg_connection *conn, const struct mg_request_info *reqInfo);
+		void process(std::ofstream *stream);
+
+	private:
+		//! Logger
+		Logger *_logger;
+
+		struct mg_connection *_conn;
+		const struct mg_request_info *_reqInfo;
+	};
+
+protected:
+
+private:
+	//! Logger
+	Logger *_logger;
+
+	std::unique_ptr<CivetServer> _server;
+	std::unique_ptr<Handler> _handler;
+};
+
+#endif

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/libminifi/include/ProcessContext.h
----------------------------------------------------------------------
diff --git a/libminifi/include/ProcessContext.h b/libminifi/include/ProcessContext.h
index 8d0bdd1..5c3288e 100644
--- a/libminifi/include/ProcessContext.h
+++ b/libminifi/include/ProcessContext.h
@@ -96,16 +96,15 @@ public:
 			_processor->yield();
 	}
 
-protected:
+	// Prevent default copy constructor and assignment operation
+	// Only support pass by reference or pointer
+	ProcessContext(const ProcessContext &parent) = delete;
+	ProcessContext &operator=(const ProcessContext &parent) = delete;
 
 private:
 
 	//! Processor
 	Processor *_processor;
-	// Prevent default copy constructor and assignment operation
-	// Only support pass by reference or pointer
-	ProcessContext(const ProcessContext &parent);
-	ProcessContext &operator=(const ProcessContext &parent);
 	//! Logger
 	Logger *_logger;
 

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/libminifi/include/ProcessSession.h
----------------------------------------------------------------------
diff --git a/libminifi/include/ProcessSession.h b/libminifi/include/ProcessSession.h
index 8dc8cc5..44032c3 100644
--- a/libminifi/include/ProcessSession.h
+++ b/libminifi/include/ProcessSession.h
@@ -96,6 +96,11 @@ public:
 	//! Import the existed file into the flow
 	void import(std::string source, FlowFileRecord *flow, bool keepSource = true, uint64_t offset = 0);
 
+	// Prevent default copy constructor and assignment operation
+	// Only support pass by reference or pointer
+	ProcessSession(const ProcessSession &parent) = delete;
+	ProcessSession &operator=(const ProcessSession &parent) = delete;
+
 protected:
 	//! FlowFiles being modified by current process session
 	std::map<std::string, FlowFileRecord *> _updatedFlowFiles;
@@ -115,10 +120,6 @@ private:
 	FlowFileRecord* cloneDuringTransfer(FlowFileRecord *parent);
 	//! ProcessContext
 	ProcessContext *_processContext;
-	// Prevent default copy constructor and assignment operation
-	// Only support pass by reference or pointer
-	ProcessSession(const ProcessSession &parent);
-	ProcessSession &operator=(const ProcessSession &parent);
 	//! Logger
 	Logger *_logger;
 	//! Provenance Report

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/libminifi/include/ProcessSessionFactory.h
----------------------------------------------------------------------
diff --git a/libminifi/include/ProcessSessionFactory.h b/libminifi/include/ProcessSessionFactory.h
new file mode 100644
index 0000000..7fc3410
--- /dev/null
+++ b/libminifi/include/ProcessSessionFactory.h
@@ -0,0 +1,52 @@
+/**
+ * @file ProcessSessionFactory.h
+ * ProcessSessionFactory class declaration
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __PROCESS_SESSION_FACTORY_H__
+#define __PROCESS_SESSION_FACTORY_H__
+
+#include <memory>
+
+#include "ProcessContext.h"
+#include "ProcessSession.h"
+
+//! ProcessSessionFactory Class
+class ProcessSessionFactory
+{
+public:
+	//! Constructor
+	/*!
+	 * Create a new process session factory
+	 */
+	explicit ProcessSessionFactory(ProcessContext *processContext) : _processContext(processContext) {}
+
+	//! Create the session
+	std::unique_ptr<ProcessSession> createSession();
+
+	// Prevent default copy constructor and assignment operation
+	// Only support pass by reference or pointer
+	ProcessSessionFactory(const ProcessSessionFactory &parent) = delete;
+	ProcessSessionFactory &operator=(const ProcessSessionFactory &parent) = delete;
+
+private:
+	//! ProcessContext
+	ProcessContext *_processContext;
+
+};
+
+#endif

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/libminifi/include/Processor.h
----------------------------------------------------------------------
diff --git a/libminifi/include/Processor.h b/libminifi/include/Processor.h
index 1bf6fcc..95f47c1 100644
--- a/libminifi/include/Processor.h
+++ b/libminifi/include/Processor.h
@@ -25,11 +25,13 @@
 #include <queue>
 #include <map>
 #include <mutex>
+#include <memory>
 #include <condition_variable>
 #include <atomic>
 #include <algorithm>
 #include <set>
 #include <chrono>
+#include <functional>
 
 #include "TimeUtil.h"
 #include "Property.h"
@@ -39,6 +41,7 @@
 //! Forwarder declaration
 class ProcessContext;
 class ProcessSession;
+class ProcessSessionFactory;
 
 //! Minimum scheduling period in Nano Second
 #define MINIMUM_SCHEDULING_NANOS 30000
@@ -137,9 +140,7 @@ public:
 	//! Check whether the processor is running
 	bool isRunning();
 	//! Set Processor Scheduled State
-	void setScheduledState(ScheduledState state) {
-		_state = state;
-	}
+	void setScheduledState(ScheduledState state);
 	//! Get Processor Scheduled State
 	ScheduledState getScheduledState(void) {
 		return _state;
@@ -281,7 +282,7 @@ public:
 	//! Get the Next RoundRobin incoming connection
 	Connection *getNextIncomingConnection();
 	//! On Trigger
-	void onTrigger();
+	void onTrigger(ProcessContext *context, ProcessSessionFactory *sessionFactory);
 	//! Block until work is available on any input connection, or the given duration elapses
 	void waitForWork(uint64_t timeoutMs);
 	//! Notify this processor that work may be available
@@ -290,10 +291,10 @@ public:
 public:
 	//! OnTrigger method, implemented by NiFi Processor Designer
 	virtual void onTrigger(ProcessContext *context, ProcessSession *session) = 0;
-	//! Initialize, over write by NiFi Process Designer
-	virtual void initialize(void) {
-		return;
-	}
+	//! Initialize, overridden by NiFi Process Designer
+	virtual void initialize() {}
+	//! Scheduled event hook, overridden by NiFi Process Designer
+	virtual void onSchedule(ProcessContext *context, ProcessSessionFactory *sessionFactory) {}
 
 protected:
 

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/libminifi/include/SchedulingAgent.h
----------------------------------------------------------------------
diff --git a/libminifi/include/SchedulingAgent.h b/libminifi/include/SchedulingAgent.h
index 2e3f6b8..1f94585 100644
--- a/libminifi/include/SchedulingAgent.h
+++ b/libminifi/include/SchedulingAgent.h
@@ -53,7 +53,7 @@ public:
 
 	}
 	//! onTrigger, return whether the yield is need
-	bool onTrigger(Processor *processor);
+	bool onTrigger(Processor *processor, ProcessContext *processContext, ProcessSessionFactory *sessionFactory);
 	//! Whether agent has work to do
 	bool hasWorkToDo(Processor *processor);
 	//! Whether the outgoing need to be backpressure

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/libminifi/include/ThreadedSchedulingAgent.h
----------------------------------------------------------------------
diff --git a/libminifi/include/ThreadedSchedulingAgent.h b/libminifi/include/ThreadedSchedulingAgent.h
index 2b14e3d..78d56f2 100644
--- a/libminifi/include/ThreadedSchedulingAgent.h
+++ b/libminifi/include/ThreadedSchedulingAgent.h
@@ -45,9 +45,9 @@ public:
 	virtual ~ThreadedSchedulingAgent()
 	{
 	}
-	
+
 	//! Run function for the thread
-	virtual void run(Processor *processor) = 0;
+	virtual void run(Processor *processor, ProcessContext *processContext, ProcessSessionFactory *sessionFactory) = 0;
 
 public:
 	//! schedule, overwritten by different DrivenTimerDrivenSchedulingAgent

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/libminifi/include/TimerDrivenSchedulingAgent.h
----------------------------------------------------------------------
diff --git a/libminifi/include/TimerDrivenSchedulingAgent.h b/libminifi/include/TimerDrivenSchedulingAgent.h
index 7fd86f6..389ccf6 100644
--- a/libminifi/include/TimerDrivenSchedulingAgent.h
+++ b/libminifi/include/TimerDrivenSchedulingAgent.h
@@ -42,7 +42,7 @@ public:
 	{
 	}
 	//! Run function for the thread
-	void run(Processor *processor);
+	void run(Processor *processor, ProcessContext *processContext, ProcessSessionFactory *sessionFactory);
 
 private:
 	// Prevent default copy constructor and assignment operation

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/libminifi/src/EventDrivenSchedulingAgent.cpp
----------------------------------------------------------------------
diff --git a/libminifi/src/EventDrivenSchedulingAgent.cpp b/libminifi/src/EventDrivenSchedulingAgent.cpp
index ed1d8ea..53bde4e 100644
--- a/libminifi/src/EventDrivenSchedulingAgent.cpp
+++ b/libminifi/src/EventDrivenSchedulingAgent.cpp
@@ -23,11 +23,11 @@
 #include "Property.h"
 #include "EventDrivenSchedulingAgent.h"
 
-void EventDrivenSchedulingAgent::run(Processor *processor)
+void EventDrivenSchedulingAgent::run(Processor *processor, ProcessContext *processContext, ProcessSessionFactory *sessionFactory)
 {
 	while (this->_running)
 	{
-		bool shouldYield = this->onTrigger(processor);
+		bool shouldYield = this->onTrigger(processor, processContext, sessionFactory);
 
 		if (processor->isYield())
 		{

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/libminifi/src/FlowController.cpp
----------------------------------------------------------------------
diff --git a/libminifi/src/FlowController.cpp b/libminifi/src/FlowController.cpp
index 5b1116f..98bf1a1 100644
--- a/libminifi/src/FlowController.cpp
+++ b/libminifi/src/FlowController.cpp
@@ -176,7 +176,7 @@ FlowControllerImpl::FlowControllerImpl(std::string name)  {
 
 			_logger->log_info("Load/Verify Client Certificate OK.");
 		}
-		
+
 	}
 	if (!path) {
 		_logger->log_error(
@@ -199,7 +199,7 @@ FlowControllerImpl::~FlowControllerImpl() {
 		delete _protocol;
 	if (NULL != _provenanceRepo)
 		delete _provenanceRepo;
-	
+
 }
 
 void FlowControllerImpl::stop(bool force) {
@@ -280,6 +280,8 @@ Processor *FlowControllerImpl::createProcessor(std::string name, uuid_t uuid) {
 		processor = new TailFile(name, uuid);
 	} else if (name == ListenSyslog::ProcessorName) {
 		processor = new ListenSyslog(name, uuid);
+	} else if (name == ListenHTTP::ProcessorName) {
+        processor = new ListenHTTP(name, uuid);
 	} else if (name == ExecuteProcess::ProcessorName) {
 		processor = new ExecuteProcess(name, uuid);
 	} else if (name == AppendHostInfo::ProcessorName) {


[50/51] [partial] nifi-minifi-cpp git commit: MINIFI-183 Added civet 1.9.1 sources Added onScheduled hook Added initial two-way TLS-enabled ListenHTTP implementation

Posted by al...@apache.org.
http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/libminifi/src/ListenHTTP.cpp
----------------------------------------------------------------------
diff --git a/libminifi/src/ListenHTTP.cpp b/libminifi/src/ListenHTTP.cpp
new file mode 100644
index 0000000..b86dad6
--- /dev/null
+++ b/libminifi/src/ListenHTTP.cpp
@@ -0,0 +1,395 @@
+/**
+ * @file ListenHTTP.cpp
+ * ListenHTTP class implementation
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include <sstream>
+#include <stdio.h>
+#include <string>
+#include <iostream>
+#include <fstream>
+#include <uuid/uuid.h>
+
+#include <CivetServer.h>
+
+#include "ListenHTTP.h"
+
+#include "TimeUtil.h"
+#include "ProcessContext.h"
+#include "ProcessSession.h"
+#include "ProcessSessionFactory.h"
+
+const std::string ListenHTTP::ProcessorName("ListenHTTP");
+
+Property ListenHTTP::BasePath("Base Path", "Base path for incoming connections", "contentListener");
+Property ListenHTTP::Port("Listening Port", "The Port to listen on for incoming connections", "");
+Property ListenHTTP::AuthorizedDNPattern("Authorized DN Pattern", "A Regular Expression to apply against the Distinguished Name of incoming connections. If the Pattern does not match the DN, the connection will be refused.", ".*");
+Property ListenHTTP::SSLCertificate("SSL Certificate", "File containing PEM-formatted file including TLS/SSL certificate and key", "");
+Property ListenHTTP::SSLCertificateAuthority("SSL Certificate Authority", "File containing trusted PEM-formatted certificates", "");
+Property ListenHTTP::SSLVerifyPeer("SSL Verify Peer", "Whether or not to verify the client's certificate (yes/no)", "no");
+Property ListenHTTP::SSLMinimumVersion("SSL Minimum Version", "Minimum TLS/SSL version allowed (SSL2, SSL3, TLS1.0, TLS1.1, TLS1.2)", "SSL2");
+Property ListenHTTP::HeadersAsAttributesRegex("HTTP Headers to receive as Attributes (Regex)", "Specifies the Regular Expression that determines the names of HTTP Headers that should be passed along as FlowFile attributes", "");
+
+Relationship ListenHTTP::Success("success", "All files are routed to success");
+
+void ListenHTTP::initialize()
+{
+	_logger->log_info("Initializing ListenHTTP");
+
+	//! Set the supported properties
+	std::set<Property> properties;
+	properties.insert(BasePath);
+	properties.insert(Port);
+	properties.insert(AuthorizedDNPattern);
+	properties.insert(SSLCertificate);
+	properties.insert(SSLCertificateAuthority);
+	properties.insert(SSLVerifyPeer);
+	properties.insert(SSLMinimumVersion);
+	properties.insert(HeadersAsAttributesRegex);
+	setSupportedProperties(properties);
+	//! Set the supported relationships
+	std::set<Relationship> relationships;
+	relationships.insert(Success);
+	setSupportedRelationships(relationships);
+}
+
+void ListenHTTP::onSchedule(ProcessContext *context, ProcessSessionFactory *sessionFactory)
+{
+
+	std::string basePath;
+
+	if (!context->getProperty(BasePath.getName(), basePath))
+	{
+		_logger->log_info("%s attribute is missing, so default value of %s will be used",
+				BasePath.getName().c_str(),
+				BasePath.getValue().c_str());
+		basePath = BasePath.getValue();
+	}
+
+	basePath.insert(0, "/");
+
+	std::string listeningPort;
+
+	if (!context->getProperty(Port.getName(), listeningPort))
+	{
+		_logger->log_error("%s attribute is missing or invalid",
+				Port.getName().c_str());
+		return;
+	}
+
+	std::string authDNPattern;
+
+	if (context->getProperty(AuthorizedDNPattern.getName(), authDNPattern) && !authDNPattern.empty())
+	{
+		_logger->log_info("ListenHTTP using %s: %s",
+				AuthorizedDNPattern.getName().c_str(),
+				authDNPattern.c_str());
+	}
+
+	std::string sslCertFile;
+
+	if (context->getProperty(SSLCertificate.getName(), sslCertFile) && !sslCertFile.empty())
+	{
+		_logger->log_info("ListenHTTP using %s: %s",
+				SSLCertificate.getName().c_str(),
+				sslCertFile.c_str());
+	}
+
+	// Read further TLS/SSL options only if TLS/SSL usage is implied by virtue of certificate value being set
+	std::string sslCertAuthorityFile;
+	std::string sslVerifyPeer;
+	std::string sslMinVer;
+
+	if (!sslCertFile.empty())
+	{
+		if (context->getProperty(SSLCertificateAuthority.getName(), sslCertAuthorityFile)
+				&& !sslCertAuthorityFile.empty())
+		{
+			_logger->log_info("ListenHTTP using %s: %s",
+					SSLCertificateAuthority.getName().c_str(),
+					sslCertAuthorityFile.c_str());
+		}
+
+		if (context->getProperty(SSLVerifyPeer.getName(), sslVerifyPeer))
+		{
+			if (sslVerifyPeer.empty() || sslVerifyPeer.compare("no") == 0)
+			{
+				_logger->log_info("ListenHTTP will not verify peers");
+			}
+			else
+			{
+				_logger->log_info("ListenHTTP will verify peers");
+			}
+		}
+		else
+		{
+			_logger->log_info("ListenHTTP will not verify peers");
+		}
+
+		if (context->getProperty(SSLMinimumVersion.getName(), sslMinVer))
+		{
+			_logger->log_info("ListenHTTP using %s: %s",
+					SSLMinimumVersion.getName().c_str(),
+					sslMinVer.c_str());
+		}
+	}
+
+	std::string headersAsAttributesPattern;
+
+	if (context->getProperty(HeadersAsAttributesRegex.getName(),headersAsAttributesPattern)
+			&& !headersAsAttributesPattern.empty())
+	{
+		_logger->log_info("ListenHTTP using %s: %s",
+				HeadersAsAttributesRegex.getName().c_str(),
+				headersAsAttributesPattern.c_str());
+	}
+
+	auto numThreads = getMaxConcurrentTasks();
+
+	_logger->log_info("ListenHTTP starting HTTP server on port %s and path %s with %d threads",
+			listeningPort.c_str(),
+			basePath.c_str(),
+			numThreads);
+
+	// Initialize web server
+	std::vector<std::string> options;
+	options.push_back("enable_keep_alive");
+	options.push_back("yes");
+	options.push_back("keep_alive_timeout_ms");
+	options.push_back("15000");
+	options.push_back("num_threads");
+	options.push_back(std::to_string(numThreads));
+
+	if (sslCertFile.empty())
+	{
+		options.push_back("listening_ports");
+		options.push_back(listeningPort);
+	}
+	else
+	{
+		listeningPort += "s";
+		options.push_back("listening_ports");
+		options.push_back(listeningPort);
+
+		options.push_back("ssl_certificate");
+		options.push_back(sslCertFile);
+
+		if (!sslCertAuthorityFile.empty())
+		{
+			options.push_back("ssl_ca_file");
+			options.push_back(sslCertAuthorityFile);
+		}
+
+		if (sslVerifyPeer.empty() || sslVerifyPeer.compare("no") == 0)
+		{
+			options.push_back("ssl_verify_peer");
+			options.push_back("no");
+		}
+		else
+		{
+			options.push_back("ssl_verify_peer");
+			options.push_back("yes");
+		}
+
+		if (sslMinVer.compare("SSL2") == 0)
+		{
+			options.push_back("ssl_protocol_version");
+			options.push_back(std::to_string(0));
+		}
+		else if (sslMinVer.compare("SSL3") == 0)
+		{
+			options.push_back("ssl_protocol_version");
+			options.push_back(std::to_string(1));
+		}
+		else if (sslMinVer.compare("TLS1.0") == 0)
+		{
+			options.push_back("ssl_protocol_version");
+			options.push_back(std::to_string(2));
+		}
+		else if (sslMinVer.compare("TLS1.1") == 0)
+		{
+			options.push_back("ssl_protocol_version");
+			options.push_back(std::to_string(3));
+		}
+		else
+		{
+			options.push_back("ssl_protocol_version");
+			options.push_back(std::to_string(4));
+		}
+	}
+
+	_server.reset(new CivetServer(options));
+	_handler.reset(new Handler(context,
+			sessionFactory,
+			std::move(authDNPattern),
+			std::move(headersAsAttributesPattern)));
+	_server->addHandler(basePath, _handler.get());
+}
+
+void ListenHTTP::onTrigger(ProcessContext *context, ProcessSession *session)
+{
+
+	FlowFileRecord *flowFile = session->get();
+
+	// Do nothing if there are no incoming files
+	if (!flowFile)
+	{
+		return;
+	}
+}
+
+ListenHTTP::Handler::Handler(ProcessContext *context,
+		ProcessSessionFactory *sessionFactory,
+		std::string &&authDNPattern,
+		std::string &&headersAsAttributesPattern)
+: _authDNRegex(std::move(authDNPattern))
+, _headersAsAttributesRegex(std::move(headersAsAttributesPattern))
+{
+	_processContext = context;
+	_processSessionFactory = sessionFactory;
+}
+
+void ListenHTTP::Handler::sendErrorResponse(struct mg_connection *conn)
+{
+	mg_printf(conn,
+			"HTTP/1.1 500 Internal Server Error\r\n"
+			"Content-Type: text/html\r\n"
+			"Content-Length: 0\r\n\r\n");
+}
+
+bool ListenHTTP::Handler::handlePost(CivetServer *server, struct mg_connection *conn)
+{
+	_logger = Logger::getLogger();
+
+	auto req_info = mg_get_request_info(conn);
+	_logger->log_info("ListenHTTP handling POST request of length %d", req_info->content_length);
+
+	// If this is a two-way TLS connection, authorize the peer against the configured pattern
+	if (req_info->is_ssl && req_info->client_cert != nullptr)
+	{
+		if (!std::regex_match(req_info->client_cert->subject, _authDNRegex))
+		{
+			mg_printf(conn,
+					"HTTP/1.1 403 Forbidden\r\n"
+					"Content-Type: text/html\r\n"
+					"Content-Length: 0\r\n\r\n");
+			_logger->log_warn("ListenHTTP client DN not authorized: %s", req_info->client_cert->subject);
+			return true;
+		}
+	}
+
+	// Always send 100 Continue, as allowed per standard to minimize client delay (https://www.w3.org/Protocols/rfc2616/rfc2616-sec8.html)
+	mg_printf(conn, "HTTP/1.1 100 Continue\r\n\r\n");
+
+	auto session = _processSessionFactory->createSession();
+	ListenHTTP::WriteCallback callback(conn, req_info);
+	auto flowFile = session->create();
+
+	if (!flowFile)
+	{
+		sendErrorResponse(conn);
+		return true;
+	}
+
+	try
+	{
+		session->write(flowFile, &callback);
+
+		// Add filename from "filename" header value (and pattern headers)
+		for (int i = 0; i < req_info->num_headers; i++)
+		{
+			auto header = &req_info->http_headers[i];
+
+			if (strcmp("filename", header->name) == 0)
+			{
+				if (!flowFile->updateAttribute("filename", header->value))
+				{
+					flowFile->addAttribute("filename", header->value);
+				}
+			}
+			else if (std::regex_match(header->name, _headersAsAttributesRegex))
+			{
+				if (!flowFile->updateAttribute(header->name, header->value))
+				{
+					flowFile->addAttribute(header->name, header->value);
+				}
+			}
+		}
+
+		session->transfer(flowFile, Success);
+		session->commit();
+	}
+	catch (std::exception &exception)
+	{
+		_logger->log_debug("ListenHTTP Caught Exception %s", exception.what());
+		sendErrorResponse(conn);
+		session->rollback();
+		throw;
+	}
+	catch (...)
+	{
+		_logger->log_debug("ListenHTTP Caught Exception Processor::onTrigger");
+		sendErrorResponse(conn);
+		session->rollback();
+		throw;
+	}
+
+	mg_printf(conn,
+			"HTTP/1.1 200 OK\r\n"
+			"Content-Type: text/html\r\n"
+			"Content-Length: 0\r\n\r\n");
+
+	return true;
+}
+
+ListenHTTP::WriteCallback::WriteCallback(struct mg_connection *conn, const struct mg_request_info *reqInfo)
+{
+	_logger = Logger::getLogger();
+	_conn = conn;
+	_reqInfo = reqInfo;
+}
+
+void ListenHTTP::WriteCallback::process(std::ofstream *stream)
+{
+	long long rlen;
+	long long nlen = 0;
+	long long tlen = _reqInfo->content_length;
+	char buf[16384];
+
+	while (nlen < tlen)
+	{
+		rlen = tlen - nlen;
+
+		if (rlen > sizeof(buf))
+		{
+			rlen = sizeof(buf);
+		}
+
+		// Read a buffer of data from client
+		rlen = mg_read(_conn, &buf[0], (size_t)rlen);
+
+		if (rlen <= 0)
+		{
+			break;
+		}
+
+		// Transfer buffer data to the output stream
+		stream->write(&buf[0], rlen);
+
+		nlen += rlen;
+	}
+}

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/libminifi/src/ProcessSessionFactory.cpp
----------------------------------------------------------------------
diff --git a/libminifi/src/ProcessSessionFactory.cpp b/libminifi/src/ProcessSessionFactory.cpp
new file mode 100644
index 0000000..a105b1c
--- /dev/null
+++ b/libminifi/src/ProcessSessionFactory.cpp
@@ -0,0 +1,28 @@
+/**
+ * @file ProcessSessionFactory.cpp
+ * ProcessSessionFactory class implementation
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "ProcessSessionFactory.h"
+
+#include <memory>
+
+std::unique_ptr<ProcessSession> ProcessSessionFactory::createSession()
+{
+	return std::unique_ptr<ProcessSession>(new ProcessSession(_processContext));
+}

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/libminifi/src/Processor.cpp
----------------------------------------------------------------------
diff --git a/libminifi/src/Processor.cpp b/libminifi/src/Processor.cpp
index 5f071b2..a683e4b 100644
--- a/libminifi/src/Processor.cpp
+++ b/libminifi/src/Processor.cpp
@@ -25,10 +25,13 @@
 #include <time.h>
 #include <chrono>
 #include <thread>
+#include <memory>
+#include <functional>
 
 #include "Processor.h"
 #include "ProcessContext.h"
 #include "ProcessSession.h"
+#include "ProcessSessionFactory.h"
 
 Processor::Processor(std::string name, uuid_t uuid)
 : _name(name)
@@ -70,6 +73,11 @@ bool Processor::isRunning()
 	return (_state == RUNNING && _activeTasks > 0);
 }
 
+void Processor::setScheduledState(ScheduledState state)
+{
+	_state = state;
+}
+
 bool Processor::setSupportedProperties(std::set<Property> properties)
 {
 	if (isRunning())
@@ -439,31 +447,25 @@ bool Processor::flowFilesOutGoingFull()
 	return false;
 }
 
-void Processor::onTrigger()
+void Processor::onTrigger(ProcessContext *context, ProcessSessionFactory *sessionFactory)
 {
-	ProcessContext *context = new ProcessContext(this);
-	ProcessSession *session = new ProcessSession(context);
+	auto session = sessionFactory->createSession();
+
 	try {
-		// Call the child onTrigger function
-		this->onTrigger(context, session);
+		// Call the virtual trigger function
+		onTrigger(context, session.get());
 		session->commit();
-		delete session;
-		delete context;
 	}
 	catch (std::exception &exception)
 	{
 		_logger->log_debug("Caught Exception %s", exception.what());
 		session->rollback();
-		delete session;
-		delete context;
 		throw;
 	}
 	catch (...)
 	{
 		_logger->log_debug("Caught Exception Processor::onTrigger");
 		session->rollback();
-		delete session;
-		delete context;
 		throw;
 	}
 }

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/libminifi/src/SchedulingAgent.cpp
----------------------------------------------------------------------
diff --git a/libminifi/src/SchedulingAgent.cpp b/libminifi/src/SchedulingAgent.cpp
index a81cd55..8e6249c 100644
--- a/libminifi/src/SchedulingAgent.cpp
+++ b/libminifi/src/SchedulingAgent.cpp
@@ -38,7 +38,7 @@ bool SchedulingAgent::hasTooMuchOutGoing(Processor *processor)
 	return processor->flowFilesOutGoingFull();
 }
 
-bool SchedulingAgent::onTrigger(Processor *processor)
+bool SchedulingAgent::onTrigger(Processor *processor, ProcessContext *processContext, ProcessSessionFactory *sessionFactory)
 {
 	if (processor->isYield())
 		return false;
@@ -59,7 +59,7 @@ bool SchedulingAgent::onTrigger(Processor *processor)
 	processor->incrementActiveTasks();
 	try
 	{
-		processor->onTrigger();
+		processor->onTrigger(processContext, sessionFactory);
 		processor->decrementActiveTask();
 	}
 	catch (Exception &exception)

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/libminifi/src/ThreadedSchedulingAgent.cpp
----------------------------------------------------------------------
diff --git a/libminifi/src/ThreadedSchedulingAgent.cpp b/libminifi/src/ThreadedSchedulingAgent.cpp
index 0338019..f7f1dbb 100644
--- a/libminifi/src/ThreadedSchedulingAgent.cpp
+++ b/libminifi/src/ThreadedSchedulingAgent.cpp
@@ -22,6 +22,10 @@
 
 #include "ThreadedSchedulingAgent.h"
 
+#include "ProcessContext.h"
+#include "ProcessSession.h"
+#include "ProcessSessionFactory.h"
+
 void ThreadedSchedulingAgent::schedule(Processor *processor)
 {
 	std::lock_guard<std::mutex> lock(_mtx);
@@ -64,11 +68,18 @@ void ThreadedSchedulingAgent::schedule(Processor *processor)
 		return;
 	}
 
+	auto processContext = std::make_shared<ProcessContext>(processor);
+	auto sessionFactory = std::make_shared<ProcessSessionFactory>(processContext.get());
+
+	processor->onSchedule(processContext.get(), sessionFactory.get());
+
 	std::vector<std::thread *> threads;
 	for (int i = 0; i < processor->getMaxConcurrentTasks(); i++)
 	{
 	    ThreadedSchedulingAgent *agent = this;
-		std::thread *thread = new std::thread([agent, processor] () { agent->run(processor); });
+		std::thread *thread = new std::thread([agent, processor, processContext, sessionFactory] () {
+			agent->run(processor, processContext.get(), sessionFactory.get());
+		});
 		thread->detach();
 		threads.push_back(thread);
 		_logger->log_info("Scheduled thread %d running for process %s", thread->get_id(),
@@ -82,7 +93,7 @@ void ThreadedSchedulingAgent::schedule(Processor *processor)
 void ThreadedSchedulingAgent::unschedule(Processor *processor)
 {
 	std::lock_guard<std::mutex> lock(_mtx);
-	
+
 	_logger->log_info("Shutting down threads for processor %s/%s",
 			processor->getName().c_str(),
 			processor->getUUIDStr().c_str());

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/libminifi/src/TimerDrivenSchedulingAgent.cpp
----------------------------------------------------------------------
diff --git a/libminifi/src/TimerDrivenSchedulingAgent.cpp b/libminifi/src/TimerDrivenSchedulingAgent.cpp
index 09b7ed6..30dc96c 100644
--- a/libminifi/src/TimerDrivenSchedulingAgent.cpp
+++ b/libminifi/src/TimerDrivenSchedulingAgent.cpp
@@ -23,11 +23,11 @@
 #include "Property.h"
 #include "TimerDrivenSchedulingAgent.h"
 
-void TimerDrivenSchedulingAgent::run(Processor *processor)
+void TimerDrivenSchedulingAgent::run(Processor *processor, ProcessContext *processContext, ProcessSessionFactory *sessionFactory)
 {
 	while (this->_running)
 	{
-		bool shouldYield = this->onTrigger(processor);
+		bool shouldYield = this->onTrigger(processor, processContext, sessionFactory);
 
 		if (processor->isYield())
 		{

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/main/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt
index e27974b..126411b 100644
--- a/main/CMakeLists.txt
+++ b/main/CMakeLists.txt
@@ -23,7 +23,7 @@ IF(POLICY CMP0048)
   CMAKE_POLICY(SET CMP0048 OLD)
 ENDIF(POLICY CMP0048)
 
-include_directories(../include ../libminifi/include ../thirdparty/yaml-cpp-yaml-cpp-0.5.3/include ../thirdparty/leveldb-1.18/include ../thirdparty/)
+include_directories(../include ../libminifi/include ../thirdparty/yaml-cpp-yaml-cpp-0.5.3/include ../thirdparty/civetweb-1.9.1/include ../thirdparty/leveldb-1.18/include ../thirdparty/)
 
 find_package(Boost REQUIRED)
 include_directories(${Boost_INCLUDE_DIRS})
@@ -39,12 +39,12 @@ endif()
 # Include UUID
 find_package(UUID REQUIRED)
 
-# Include OpenSSL 
+# Include OpenSSL
 find_package(OpenSSL REQUIRED)
 include_directories(${OPENSSL_INCLUDE_DIR})
 
-# Link against minifi, yaml-cpp, uuid, and leveldb
-target_link_libraries(minifiexe minifi yaml-cpp ${UUID_LIBRARIES} ${LEVELDB_LIBRARIES} ${OPENSSL_LIBRARIES})
+# Link against minifi, yaml-cpp, civetweb-cpp, uuid, openssl, and leveldb
+target_link_libraries(minifiexe minifi yaml-cpp c-library civetweb-cpp ${UUID_LIBRARIES} ${LEVELDB_LIBRARIES} ${OPENSSL_LIBRARIES})
 set_target_properties(minifiexe
         PROPERTIES OUTPUT_NAME minifi)
 

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/.clang-format
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/.clang-format b/thirdparty/civetweb-1.9.1/.clang-format
new file mode 100644
index 0000000..37a80d9
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/.clang-format
@@ -0,0 +1,32 @@
+# http://clang.llvm.org/docs/ClangFormatStyleOptions.html
+
+BasedOnStyle: LLVM
+
+IndentWidth: 4
+TabWidth: 4
+UseTab: ForIndentation
+ColumnLimit: 80
+
+Language: Cpp
+
+AlignAfterOpenBracket: true
+AllowAllParametersOfDeclarationOnNextLine: false
+AllowShortBlocksOnASingleLine: false
+AllowShortCaseLabelsOnASingleLine: false
+AllowShortFunctionsOnASingleLine: None
+AllowShortIfStatementsOnASingleLine: false
+AllowShortLoopsOnASingleLine: false
+AlwaysBreakAfterDefinitionReturnType: true
+BinPackArguments: false
+BinPackParameters: false
+BreakBeforeBinaryOperators: NonAssignment
+BreakBeforeBraces: Linux
+DerivePointerAlignment: false
+MaxEmptyLinesToKeep: 2
+PenaltyBreakBeforeFirstCallParameter: 100
+
+SpaceBeforeParens: ControlStatements
+SpaceInEmptyParentheses: false
+SpacesInSquareBrackets: false
+
+DisableFormat: false

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/.gitattributes
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/.gitattributes b/thirdparty/civetweb-1.9.1/.gitattributes
new file mode 100644
index 0000000..5c52867
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/.gitattributes
@@ -0,0 +1,33 @@
+# Auto detect text files and perform LF normalization
+* -text
+
+# Custom for Visual Studio
+*.cs     diff=csharp
+*.sln    merge=union
+*.csproj merge=union
+*.vbproj merge=union
+*.fsproj merge=union
+*.dbproj merge=union
+
+# Standard to msysgit
+*.doc    diff=astextplain
+*.DOC    diff=astextplain
+*.docx   diff=astextplain
+*.DOCX   diff=astextplain
+*.dot    diff=astextplain
+*.DOT    diff=astextplain
+*.pdf    diff=astextplain
+*.PDF    diff=astextplain
+*.rtf    diff=astextplain
+*.RTF    diff=astextplain
+
+# Preserver Windows specfic lines endings
+*.cmd text eol=crlf
+
+
+# Settings for github syntax highlighting
+# see https://github.com/github/linguist/blob/master/README.md
+docs/* linguist-documentation
+*.inl linguist-language=C
+*.h linguist-language=C
+include/CivetServer.h linguist-language=C++

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/.gitignore
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/.gitignore b/thirdparty/civetweb-1.9.1/.gitignore
new file mode 100644
index 0000000..7b27e8e
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/.gitignore
@@ -0,0 +1,266 @@
+
+civetweb
+civetweb_test
+libcivetweb.a
+libcivetweb.so
+*-cache
+out
+*.dmg
+*.msi
+*.exe
+*.zip
+[oO]utput
+[tT]esting
+
+*.o
+
+#################
+## CMake
+#################
+/CMakeCache.txt
+/CMakeFiles
+/mingw-builds
+
+#################
+## Eclipse
+#################
+
+*.pydevproject
+.project
+.metadata
+bin/
+tmp/
+*.tmp
+*.bak
+*.swp
+*~.nib
+local.properties
+.classpath
+.settings/
+.loadpath
+
+# External tool builders
+.externalToolBuilders/
+
+# Locally stored "Eclipse launch configurations"
+*.launch
+
+# CDT-specific
+.cproject
+
+# PDT-specific
+.buildpath
+
+
+#################
+## Visual Studio
+#################
+
+## Ignore Visual Studio temporary files, build results, and
+## files generated by popular Visual Studio add-ons.
+
+# User-specific files
+*.suo
+*.user
+*.sln.docstates
+
+# Text-mode IDE tools
+cscope.out
+tags
+
+# Build results
+
+[Dd]ebug/
+[Dd]ebug CONSOLE/
+[Rr]elease/
+x64/
+[Bb]in/
+[Oo]bj/
+
+# MSTest test Results
+[Tt]est[Rr]esult*/
+[Bb]uild[Ll]og.*
+
+*_i.c
+*_p.c
+*.ilk
+*.meta
+*.obj
+*.pch
+*.pdb
+*.pgc
+*.pgd
+*.rsp
+*.sbr
+*.tlb
+*.tli
+*.tlh
+*.tmp
+*.tmp_proj
+*.log
+*.vspscc
+*.vssscc
+.builds
+*.pidb
+*.log
+*.scc
+
+# Visual C++ cache files
+ipch/
+*.aps
+*.ncb
+*.opensdf
+*.sdf
+*.cachefile
+
+# Visual Studio profiler
+*.psess
+*.vsp
+*.vspx
+
+# Guidance Automation Toolkit
+*.gpState
+
+# ReSharper is a .NET coding add-in
+_ReSharper*/
+*.[Rr]e[Ss]harper
+
+# TeamCity is a build add-in
+_TeamCity*
+
+# DotCover is a Code Coverage Tool
+*.dotCover
+
+# NCrunch
+*.ncrunch*
+.*crunch*.local.xml
+
+# Installshield output folder
+[Ee]xpress/
+
+# DocProject is a documentation generator add-in
+DocProject/buildhelp/
+DocProject/Help/*.HxT
+DocProject/Help/*.HxC
+DocProject/Help/*.hhc
+DocProject/Help/*.hhk
+DocProject/Help/*.hhp
+DocProject/Help/Html2
+DocProject/Help/html
+
+# Click-Once directory
+publish/
+
+# Publish Web Output
+*.Publish.xml
+*.pubxml
+
+# NuGet Packages Directory
+## TODO: If you have NuGet Package Restore enabled, uncomment the next line
+#packages/
+
+# Windows Azure Build Output
+csx
+*.build.csdef
+
+# Windows Store app package directory
+AppPackages/
+
+# Others
+sql/
+*.Cache
+ClientBin/
+[Ss]tyle[Cc]op.*
+~$*
+*~
+*.dbmdl
+*.[Pp]ublish.xml
+*.pfx
+*.publishsettings
+
+# RIA/Silverlight projects
+Generated_Code/
+
+# Backup & report files from converting an old project file to a newer
+# Visual Studio version. Backup files are not needed, because we have git ;-)
+_UpgradeReport_Files/
+Backup*/
+UpgradeLog*.XML
+UpgradeLog*.htm
+
+# SQL Server files
+App_Data/*.mdf
+App_Data/*.ldf
+
+#############
+## Windows detritus
+#############
+
+# Windows image file caches
+Thumbs.db
+ehthumbs.db
+
+# Folder config file
+Desktop.ini
+
+# Recycle Bin used on file shares
+$RECYCLE.BIN/
+
+# Mac crap
+.DS_Store
+
+
+#############
+## Python
+#############
+
+*.py[co]
+
+# Packages
+*.egg
+*.egg-info
+dist/
+eggs/
+parts/
+var/
+sdist/
+develop-eggs/
+.installed.cfg
+
+# Installer logs
+pip-log.txt
+
+# Unit test / coverage reports
+.coverage
+.tox
+
+#Translations
+*.mo
+
+#Mr Developer
+.mr.developer.cfg
+
+
+##########################
+## Files created by tests
+##########################
+requests.db
+
+##########################
+## Files created by ctags
+##########################
+?tags
+?tags?
+
+##########################
+## Files created by autotools
+##########################
+*.lo
+.libs
+
+##########################
+## Travis Build Dir
+##########################
+ci/lua
+
+

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/.travis.yml
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/.travis.yml b/thirdparty/civetweb-1.9.1/.travis.yml
new file mode 100644
index 0000000..4f42ac2
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/.travis.yml
@@ -0,0 +1,1240 @@
+language: c
+
+sudo: false
+
+cache:
+  directories:
+  - $HOME/third-party
+
+
+
+osx_image: xcode8
+
+addons:
+  apt:
+    packages:
+      - cmake
+      - openssl
+      - libssl-dev
+    sources:
+      - kubuntu-backports
+
+before_install:
+  - cmake --version
+
+install:
+  - if [ "${BUILD_TYPE}" == "Coverage" -a "${TRAVIS_OS_NAME}" == "linux" ]; then
+      PATH=~/.local/bin:${PATH};
+      pip install --user --upgrade pip;
+      pip install --user cpp-coveralls;
+    fi
+
+before_script:
+  # Check some settings of the build server
+  - uname -a
+  - pwd
+  # Generate the build scripts with CMake
+  - mkdir output
+  - gcc test/cgi_test.c -o output/cgi_test.cgi
+  - cd output
+  - cmake --version
+  - cmake
+    -G "Unix Makefiles"
+    -DCMAKE_BUILD_TYPE=${BUILD_TYPE}
+    -DBUILD_SHARED_LIBS=${BUILD_SHARED}
+    "-DCIVETWEB_THIRD_PARTY_DIR=${HOME}/third-party"
+    -DCIVETWEB_ENABLE_THIRD_PARTY_OUTPUT=YES
+    -DCIVETWEB_ENABLE_SSL=${ENABLE_SSL}
+    -DCIVETWEB_DISABLE_CGI=${NO_CGI}
+    -DCIVETWEB_SERVE_NO_FILES=${NO_FILES}
+    -DCIVETWEB_ENABLE_SSL_DYNAMIC_LOADING=${ENABLE_SSL_DYNAMIC_LOADING}
+    -DCIVETWEB_ENABLE_WEBSOCKETS=${ENABLE_WEBSOCKETS}
+    -DCIVETWEB_ENABLE_CXX=${ENABLE_CXX}
+    -DCIVETWEB_ENABLE_IPV6=${ENABLE_IPV6}
+    -DCIVETWEB_ENABLE_LUA=${ENABLE_LUA}
+    -DCIVETWEB_ENABLE_LUA_SHARED=${ENABLE_LUA_SHARED}
+    -DCIVETWEB_ENABLE_DUKTAPE=${ENABLE_DUKTAPE}
+    -DCIVETWEB_DISABLE_CACHING=${NO_CACHING}
+    -DCIVETWEB_C_STANDARD=${C_STANDARD}
+    -DCIVETWEB_CXX_STANDARD=${CXX_STANDARD}
+    ..
+  - ls -la
+
+script:
+  - if [ "${MACOSX_PACKAGE}" == "1" ]; then
+      cd "${TRAVIS_BUILD_DIR}";
+      make -f Makefile.osx package;
+    else
+      CTEST_OUTPUT_ON_FAILURE=1 make all test;
+    fi
+
+# Coveralls options: https://github.com/eddyxu/cpp-coveralls/blob/master/README.md
+after_success:
+  - if [ "${BUILD_TYPE}" == "Coverage" -a "${TRAVIS_OS_NAME}" == "linux" ]; then
+      coveralls --include src --exclude src/main.c --exclude src/third_party --include include --gcov-options '\-lp' --root .. --build-root .;
+    fi
+
+
+###################################
+
+matrix:
+  fast_finish: false
+  include:
+
+  -
+    os: linux
+    compiler: clang
+    env:
+      N=ClangLinuxMinimal
+      BUILD_TYPE=Debug
+      ENABLE_SSL_DYNAMIC_LOADING=YES
+      ENABLE_CXX=NO
+      ENABLE_LUA_SHARED=NO
+      C_STANDARD=auto
+      CXX_STANDARD=auto
+      FEATURES=0
+      BUILD_SHARED=NO
+      NO_FILES=YES
+      ENABLE_SSL=NO
+      NO_CGI=YES
+      ENABLE_IPV6=NO
+      ENABLE_WEBSOCKETS=NO
+      ENABLE_LUA=NO
+      ENABLE_DUKTAPE=NO
+      NO_CACHING=NO
+
+  -
+    os: linux
+    compiler: gcc
+    env:
+      N=GCCLinuxMinimal
+      BUILD_TYPE=Release
+      ENABLE_SSL_DYNAMIC_LOADING=YES
+      ENABLE_CXX=NO
+      ENABLE_LUA_SHARED=NO
+      C_STANDARD=auto
+      CXX_STANDARD=auto
+      FEATURES=0
+      BUILD_SHARED=NO
+      NO_FILES=YES
+      ENABLE_SSL=NO
+      NO_CGI=YES
+      ENABLE_IPV6=NO
+      ENABLE_WEBSOCKETS=NO
+      ENABLE_LUA=NO
+      ENABLE_DUKTAPE=NO
+      NO_CACHING=NO
+
+  -
+    os: osx
+    compiler: clang
+    env:
+      N=ClangOSXMinimal
+      BUILD_TYPE=Release
+      ENABLE_SSL_DYNAMIC_LOADING=YES
+      ENABLE_CXX=NO
+      ENABLE_LUA_SHARED=NO
+      C_STANDARD=auto
+      CXX_STANDARD=auto
+      FEATURES=0
+      BUILD_SHARED=NO
+      NO_FILES=YES
+      ENABLE_SSL=NO
+      NO_CGI=YES
+      ENABLE_IPV6=NO
+      ENABLE_WEBSOCKETS=NO
+      ENABLE_LUA=NO
+      ENABLE_DUKTAPE=NO
+      NO_CACHING=NO
+
+  -
+    os: linux
+    compiler: clang
+    env:
+      N=ClangLinuxMinNoCache
+      BUILD_TYPE=Debug
+      ENABLE_SSL_DYNAMIC_LOADING=YES
+      ENABLE_CXX=NO
+      ENABLE_LUA_SHARED=NO
+      C_STANDARD=auto
+      CXX_STANDARD=auto
+      FEATURES=0
+      BUILD_SHARED=NO
+      NO_FILES=YES
+      ENABLE_SSL=NO
+      NO_CGI=YES
+      ENABLE_IPV6=NO
+      ENABLE_WEBSOCKETS=NO
+      ENABLE_LUA=NO
+      ENABLE_DUKTAPE=NO
+      NO_CACHING=YES
+
+  -
+    os: linux
+    compiler: clang
+    env:
+      N=ClangLinuxMax
+      BUILD_TYPE=Coverage
+      ENABLE_SSL_DYNAMIC_LOADING=YES
+      ENABLE_CXX=NO
+      ENABLE_LUA_SHARED=NO
+      C_STANDARD=auto
+      CXX_STANDARD=auto
+      FEATURES=31
+      BUILD_SHARED=NO
+      NO_FILES=NO
+      ENABLE_SSL=YES
+      NO_CGI=NO
+      ENABLE_IPV6=YES
+      ENABLE_WEBSOCKETS=YES
+      ENABLE_LUA=NO
+      ENABLE_DUKTAPE=NO
+      NO_CACHING=YES
+
+  -
+    os: linux
+    compiler: gcc
+    env:
+      N=GCCLinuxMax
+      BUILD_TYPE=Release
+      ENABLE_SSL_DYNAMIC_LOADING=YES
+      ENABLE_CXX=NO
+      ENABLE_LUA_SHARED=NO
+      C_STANDARD=auto
+      CXX_STANDARD=auto
+      FEATURES=31
+      BUILD_SHARED=NO
+      NO_FILES=NO
+      ENABLE_SSL=YES
+      NO_CGI=NO
+      ENABLE_IPV6=YES
+      ENABLE_WEBSOCKETS=YES
+      ENABLE_LUA=NO
+      ENABLE_DUKTAPE=NO
+      NO_CACHING=YES
+
+  -
+    os: osx
+    compiler: clang
+    env:
+      N=ClangOSXMax
+      BUILD_TYPE=Release
+      ENABLE_SSL_DYNAMIC_LOADING=YES
+      ENABLE_CXX=NO
+      ENABLE_LUA_SHARED=NO
+      C_STANDARD=auto
+      CXX_STANDARD=auto
+      FEATURES=31
+      BUILD_SHARED=NO
+      NO_FILES=NO
+      ENABLE_SSL=YES
+      NO_CGI=NO
+      ENABLE_IPV6=YES
+      ENABLE_WEBSOCKETS=YES
+      ENABLE_LUA=NO
+      ENABLE_DUKTAPE=NO
+      NO_CACHING=YES
+
+  -
+    os: linux
+    compiler: clang
+    env:
+      N=ClangLinuxDefault
+      BUILD_TYPE=Debug
+      ENABLE_SSL_DYNAMIC_LOADING=YES
+      ENABLE_CXX=NO
+      ENABLE_LUA_SHARED=NO
+      C_STANDARD=auto
+      CXX_STANDARD=auto
+      FEATURES=7
+      BUILD_SHARED=NO
+      NO_FILES=NO
+      ENABLE_SSL=YES
+      NO_CGI=NO
+      ENABLE_IPV6=NO
+      ENABLE_WEBSOCKETS=NO
+      ENABLE_LUA=NO
+      ENABLE_DUKTAPE=NO
+      NO_CACHING=NO
+
+  -
+    os: linux
+    compiler: gcc
+    env:
+      N=GCCLinuxDefault
+      BUILD_TYPE=Release
+      ENABLE_SSL_DYNAMIC_LOADING=YES
+      ENABLE_CXX=NO
+      ENABLE_LUA_SHARED=NO
+      C_STANDARD=auto
+      CXX_STANDARD=auto
+      FEATURES=7
+      BUILD_SHARED=NO
+      NO_FILES=NO
+      ENABLE_SSL=YES
+      NO_CGI=NO
+      ENABLE_IPV6=NO
+      ENABLE_WEBSOCKETS=NO
+      ENABLE_LUA=NO
+      ENABLE_DUKTAPE=NO
+      NO_CACHING=NO
+
+  -
+    os: osx
+    compiler: clang
+    env:
+      N=ClangOSXDefault
+      BUILD_TYPE=Release
+      ENABLE_SSL_DYNAMIC_LOADING=YES
+      ENABLE_CXX=NO
+      ENABLE_LUA_SHARED=NO
+      C_STANDARD=auto
+      CXX_STANDARD=auto
+      FEATURES=7
+      BUILD_SHARED=NO
+      NO_FILES=NO
+      ENABLE_SSL=YES
+      NO_CGI=NO
+      ENABLE_IPV6=NO
+      ENABLE_WEBSOCKETS=NO
+      ENABLE_LUA=NO
+      ENABLE_DUKTAPE=NO
+      NO_CACHING=NO
+
+  -
+    os: linux
+    compiler: clang
+    env:
+      N=ClangLinuxDefaultShared
+      BUILD_TYPE=Debug
+      ENABLE_SSL_DYNAMIC_LOADING=YES
+      ENABLE_CXX=NO
+      ENABLE_LUA_SHARED=NO
+      C_STANDARD=auto
+      CXX_STANDARD=auto
+      FEATURES=7
+      BUILD_SHARED=YES
+      NO_FILES=NO
+      ENABLE_SSL=YES
+      NO_CGI=NO
+      ENABLE_IPV6=NO
+      ENABLE_WEBSOCKETS=NO
+      ENABLE_LUA=NO
+      ENABLE_DUKTAPE=NO
+      NO_CACHING=NO
+
+  -
+    os: linux
+    compiler: gcc
+    env:
+      N=GCCLinuxDefaultShared
+      BUILD_TYPE=Release
+      ENABLE_SSL_DYNAMIC_LOADING=YES
+      ENABLE_CXX=NO
+      ENABLE_LUA_SHARED=NO
+      C_STANDARD=auto
+      CXX_STANDARD=auto
+      FEATURES=7
+      BUILD_SHARED=YES
+      NO_FILES=NO
+      ENABLE_SSL=YES
+      NO_CGI=NO
+      ENABLE_IPV6=NO
+      ENABLE_WEBSOCKETS=NO
+      ENABLE_LUA=NO
+      ENABLE_DUKTAPE=NO
+      NO_CACHING=NO
+
+  -
+    os: osx
+    compiler: clang
+    env:
+      N=ClangOSXDefaultShared
+      BUILD_TYPE=Release
+      ENABLE_SSL_DYNAMIC_LOADING=YES
+      ENABLE_CXX=NO
+      ENABLE_LUA_SHARED=NO
+      C_STANDARD=auto
+      CXX_STANDARD=auto
+      FEATURES=7
+      BUILD_SHARED=YES
+      NO_FILES=NO
+      ENABLE_SSL=YES
+      NO_CGI=NO
+      ENABLE_IPV6=NO
+      ENABLE_WEBSOCKETS=NO
+      ENABLE_LUA=NO
+      ENABLE_DUKTAPE=NO
+      NO_CACHING=NO
+
+  -
+    os: osx
+    compiler: clang
+    env:
+      N=OSX_Package
+      BUILD_TYPE=Release
+      ENABLE_SSL_DYNAMIC_LOADING=YES
+      ENABLE_CXX=NO
+      ENABLE_LUA_SHARED=NO
+      C_STANDARD=auto
+      CXX_STANDARD=auto
+      FEATURES=31
+      BUILD_SHARED=NO
+      NO_FILES=NO
+      ENABLE_SSL=YES
+      NO_CGI=NO
+      ENABLE_IPV6=YES
+      ENABLE_WEBSOCKETS=YES
+      ENABLE_LUA=NO
+      ENABLE_DUKTAPE=NO
+      NO_CACHING=NO
+      MACOSX_PACKAGE=1
+
+
+#### Now all define combinations, but only for Linux clang
+##### Generated with Lua:
+#
+#  function YN(i,b)
+#    local bits = {}
+#    while (i > 0.5) do
+#      i = math.floor(i)
+#      bits[#bits+1] = (math.mod(i, 2) == 1)
+#      i = i/2
+#    end
+#    if (bits[b]) then
+#      return "YES"
+#    end
+#    return "NO"
+#  end
+#  function INV(t)
+#    if t=="YES" then
+#      return "NO"
+#    elseif t=="NO" then
+#      return "YES"
+#    else
+#      assert("ERROR in INV!")
+#    end
+#  end
+#  for i=0,31 do
+#    if true then -- (i~=0) and (i~=7) and (i~=31) then
+#      print("  -")
+#      print("    os: linux")
+#      print("    compiler: clang")
+#      print("    env:")
+#      print("      N=C" .. tostring(i) .. "_")
+#      print("      BUILD_TYPE=Release")
+#      print("      ENABLE_SSL_DYNAMIC_LOADING=YES")
+#      print("      ENABLE_CXX=NO")
+#      print("      C_STANDARD=auto")
+#      print("      CXX_STANDARD=auto")
+#      print("      ENABLE_LUA_SHARED=NO")
+#      print("      FEATURES=" .. tostring(i))
+#      print("      BUILD_SHARED=NO")
+#      print("      NO_FILES=" .. INV(YN(i, 1)))
+#      print("      ENABLE_SSL=" .. YN(i, 2))
+#      print("      NO_CGI=" .. INV(YN(i, 3)))
+#      print("      ENABLE_IPV6=" .. YN(i, 4))
+#      print("      ENABLE_WEBSOCKETS=" .. YN(i, 5))
+#      print("      ENABLE_LUA=" .. YN(i, 6))
+#      print("      ENABLE_DUKTAPE=" .. YN(i, 7))
+#      print("      NO_CACHING=NO")
+#      print("")
+#    end
+#  end
+#
+
+  -
+    os: linux
+    compiler: clang
+    env:
+      N=C0_
+      BUILD_TYPE=Release
+      ENABLE_SSL_DYNAMIC_LOADING=YES
+      ENABLE_CXX=NO
+      C_STANDARD=auto
+      CXX_STANDARD=auto
+      ENABLE_LUA_SHARED=NO
+      FEATURES=0
+      BUILD_SHARED=NO
+      NO_FILES=YES
+      ENABLE_SSL=NO
+      NO_CGI=YES
+      ENABLE_IPV6=NO
+      ENABLE_WEBSOCKETS=NO
+      ENABLE_LUA=NO
+      ENABLE_DUKTAPE=NO
+      NO_CACHING=NO
+
+  -
+    os: linux
+    compiler: clang
+    env:
+      N=C1_
+      BUILD_TYPE=Release
+      ENABLE_SSL_DYNAMIC_LOADING=YES
+      ENABLE_CXX=NO
+      C_STANDARD=auto
+      CXX_STANDARD=auto
+      ENABLE_LUA_SHARED=NO
+      FEATURES=1
+      BUILD_SHARED=NO
+      NO_FILES=NO
+      ENABLE_SSL=NO
+      NO_CGI=YES
+      ENABLE_IPV6=NO
+      ENABLE_WEBSOCKETS=NO
+      ENABLE_LUA=NO
+      ENABLE_DUKTAPE=NO
+      NO_CACHING=NO
+
+  -
+    os: linux
+    compiler: clang
+    env:
+      N=C2_
+      BUILD_TYPE=Release
+      ENABLE_SSL_DYNAMIC_LOADING=YES
+      ENABLE_CXX=NO
+      C_STANDARD=auto
+      CXX_STANDARD=auto
+      ENABLE_LUA_SHARED=NO
+      FEATURES=2
+      BUILD_SHARED=NO
+      NO_FILES=YES
+      ENABLE_SSL=YES
+      NO_CGI=YES
+      ENABLE_IPV6=NO
+      ENABLE_WEBSOCKETS=NO
+      ENABLE_LUA=NO
+      ENABLE_DUKTAPE=NO
+      NO_CACHING=NO
+
+  -
+    os: linux
+    compiler: clang
+    env:
+      N=C3_
+      BUILD_TYPE=Release
+      ENABLE_SSL_DYNAMIC_LOADING=YES
+      ENABLE_CXX=NO
+      C_STANDARD=auto
+      CXX_STANDARD=auto
+      ENABLE_LUA_SHARED=NO
+      FEATURES=3
+      BUILD_SHARED=NO
+      NO_FILES=NO
+      ENABLE_SSL=YES
+      NO_CGI=YES
+      ENABLE_IPV6=NO
+      ENABLE_WEBSOCKETS=NO
+      ENABLE_LUA=NO
+      ENABLE_DUKTAPE=NO
+      NO_CACHING=NO
+
+  -
+    os: linux
+    compiler: clang
+    env:
+      N=C4_
+      BUILD_TYPE=Release
+      ENABLE_SSL_DYNAMIC_LOADING=YES
+      ENABLE_CXX=NO
+      C_STANDARD=auto
+      CXX_STANDARD=auto
+      ENABLE_LUA_SHARED=NO
+      FEATURES=4
+      BUILD_SHARED=NO
+      NO_FILES=YES
+      ENABLE_SSL=NO
+      NO_CGI=NO
+      ENABLE_IPV6=NO
+      ENABLE_WEBSOCKETS=NO
+      ENABLE_LUA=NO
+      ENABLE_DUKTAPE=NO
+      NO_CACHING=NO
+
+  -
+    os: linux
+    compiler: clang
+    env:
+      N=C5_
+      BUILD_TYPE=Release
+      ENABLE_SSL_DYNAMIC_LOADING=YES
+      ENABLE_CXX=NO
+      C_STANDARD=auto
+      CXX_STANDARD=auto
+      ENABLE_LUA_SHARED=NO
+      FEATURES=5
+      BUILD_SHARED=NO
+      NO_FILES=NO
+      ENABLE_SSL=NO
+      NO_CGI=NO
+      ENABLE_IPV6=NO
+      ENABLE_WEBSOCKETS=NO
+      ENABLE_LUA=NO
+      ENABLE_DUKTAPE=NO
+      NO_CACHING=NO
+
+  -
+    os: linux
+    compiler: clang
+    env:
+      N=C6_
+      BUILD_TYPE=Release
+      ENABLE_SSL_DYNAMIC_LOADING=YES
+      ENABLE_CXX=NO
+      C_STANDARD=auto
+      CXX_STANDARD=auto
+      ENABLE_LUA_SHARED=NO
+      FEATURES=6
+      BUILD_SHARED=NO
+      NO_FILES=YES
+      ENABLE_SSL=YES
+      NO_CGI=NO
+      ENABLE_IPV6=NO
+      ENABLE_WEBSOCKETS=NO
+      ENABLE_LUA=NO
+      ENABLE_DUKTAPE=NO
+      NO_CACHING=NO
+
+  -
+    os: linux
+    compiler: clang
+    env:
+      N=C7_
+      BUILD_TYPE=Release
+      ENABLE_SSL_DYNAMIC_LOADING=YES
+      ENABLE_CXX=NO
+      C_STANDARD=auto
+      CXX_STANDARD=auto
+      ENABLE_LUA_SHARED=NO
+      FEATURES=7
+      BUILD_SHARED=NO
+      NO_FILES=NO
+      ENABLE_SSL=YES
+      NO_CGI=NO
+      ENABLE_IPV6=NO
+      ENABLE_WEBSOCKETS=NO
+      ENABLE_LUA=NO
+      ENABLE_DUKTAPE=NO
+      NO_CACHING=NO
+
+  -
+    os: linux
+    compiler: clang
+    env:
+      N=C8_
+      BUILD_TYPE=Release
+      ENABLE_SSL_DYNAMIC_LOADING=YES
+      ENABLE_CXX=NO
+      C_STANDARD=auto
+      CXX_STANDARD=auto
+      ENABLE_LUA_SHARED=NO
+      FEATURES=8
+      BUILD_SHARED=NO
+      NO_FILES=YES
+      ENABLE_SSL=NO
+      NO_CGI=YES
+      ENABLE_IPV6=YES
+      ENABLE_WEBSOCKETS=NO
+      ENABLE_LUA=NO
+      ENABLE_DUKTAPE=NO
+      NO_CACHING=NO
+
+  -
+    os: linux
+    compiler: clang
+    env:
+      N=C9_
+      BUILD_TYPE=Release
+      ENABLE_SSL_DYNAMIC_LOADING=YES
+      ENABLE_CXX=NO
+      C_STANDARD=auto
+      CXX_STANDARD=auto
+      ENABLE_LUA_SHARED=NO
+      FEATURES=9
+      BUILD_SHARED=NO
+      NO_FILES=NO
+      ENABLE_SSL=NO
+      NO_CGI=YES
+      ENABLE_IPV6=YES
+      ENABLE_WEBSOCKETS=NO
+      ENABLE_LUA=NO
+      ENABLE_DUKTAPE=NO
+      NO_CACHING=NO
+
+  -
+    os: linux
+    compiler: clang
+    env:
+      N=C10_
+      BUILD_TYPE=Release
+      ENABLE_SSL_DYNAMIC_LOADING=YES
+      ENABLE_CXX=NO
+      C_STANDARD=auto
+      CXX_STANDARD=auto
+      ENABLE_LUA_SHARED=NO
+      FEATURES=10
+      BUILD_SHARED=NO
+      NO_FILES=YES
+      ENABLE_SSL=YES
+      NO_CGI=YES
+      ENABLE_IPV6=YES
+      ENABLE_WEBSOCKETS=NO
+      ENABLE_LUA=NO
+      ENABLE_DUKTAPE=NO
+      NO_CACHING=NO
+
+  -
+    os: linux
+    compiler: clang
+    env:
+      N=C11_
+      BUILD_TYPE=Release
+      ENABLE_SSL_DYNAMIC_LOADING=YES
+      ENABLE_CXX=NO
+      C_STANDARD=auto
+      CXX_STANDARD=auto
+      ENABLE_LUA_SHARED=NO
+      FEATURES=11
+      BUILD_SHARED=NO
+      NO_FILES=NO
+      ENABLE_SSL=YES
+      NO_CGI=YES
+      ENABLE_IPV6=YES
+      ENABLE_WEBSOCKETS=NO
+      ENABLE_LUA=NO
+      ENABLE_DUKTAPE=NO
+      NO_CACHING=NO
+
+  -
+    os: linux
+    compiler: clang
+    env:
+      N=C12_
+      BUILD_TYPE=Release
+      ENABLE_SSL_DYNAMIC_LOADING=YES
+      ENABLE_CXX=NO
+      C_STANDARD=auto
+      CXX_STANDARD=auto
+      ENABLE_LUA_SHARED=NO
+      FEATURES=12
+      BUILD_SHARED=NO
+      NO_FILES=YES
+      ENABLE_SSL=NO
+      NO_CGI=NO
+      ENABLE_IPV6=YES
+      ENABLE_WEBSOCKETS=NO
+      ENABLE_LUA=NO
+      ENABLE_DUKTAPE=NO
+      NO_CACHING=NO
+
+  -
+    os: linux
+    compiler: clang
+    env:
+      N=C13_
+      BUILD_TYPE=Release
+      ENABLE_SSL_DYNAMIC_LOADING=YES
+      ENABLE_CXX=NO
+      C_STANDARD=auto
+      CXX_STANDARD=auto
+      ENABLE_LUA_SHARED=NO
+      FEATURES=13
+      BUILD_SHARED=NO
+      NO_FILES=NO
+      ENABLE_SSL=NO
+      NO_CGI=NO
+      ENABLE_IPV6=YES
+      ENABLE_WEBSOCKETS=NO
+      ENABLE_LUA=NO
+      ENABLE_DUKTAPE=NO
+      NO_CACHING=NO
+
+  -
+    os: linux
+    compiler: clang
+    env:
+      N=C14_
+      BUILD_TYPE=Release
+      ENABLE_SSL_DYNAMIC_LOADING=YES
+      ENABLE_CXX=NO
+      C_STANDARD=auto
+      CXX_STANDARD=auto
+      ENABLE_LUA_SHARED=NO
+      FEATURES=14
+      BUILD_SHARED=NO
+      NO_FILES=YES
+      ENABLE_SSL=YES
+      NO_CGI=NO
+      ENABLE_IPV6=YES
+      ENABLE_WEBSOCKETS=NO
+      ENABLE_LUA=NO
+      ENABLE_DUKTAPE=NO
+      NO_CACHING=NO
+
+  -
+    os: linux
+    compiler: clang
+    env:
+      N=C15_
+      BUILD_TYPE=Release
+      ENABLE_SSL_DYNAMIC_LOADING=YES
+      ENABLE_CXX=NO
+      C_STANDARD=auto
+      CXX_STANDARD=auto
+      ENABLE_LUA_SHARED=NO
+      FEATURES=15
+      BUILD_SHARED=NO
+      NO_FILES=NO
+      ENABLE_SSL=YES
+      NO_CGI=NO
+      ENABLE_IPV6=YES
+      ENABLE_WEBSOCKETS=NO
+      ENABLE_LUA=NO
+      ENABLE_DUKTAPE=NO
+      NO_CACHING=NO
+
+  -
+    os: linux
+    compiler: clang
+    env:
+      N=C16_
+      BUILD_TYPE=Release
+      ENABLE_SSL_DYNAMIC_LOADING=YES
+      ENABLE_CXX=NO
+      C_STANDARD=auto
+      CXX_STANDARD=auto
+      ENABLE_LUA_SHARED=NO
+      FEATURES=16
+      BUILD_SHARED=NO
+      NO_FILES=YES
+      ENABLE_SSL=NO
+      NO_CGI=YES
+      ENABLE_IPV6=NO
+      ENABLE_WEBSOCKETS=YES
+      ENABLE_LUA=NO
+      ENABLE_DUKTAPE=NO
+      NO_CACHING=NO
+
+  -
+    os: linux
+    compiler: clang
+    env:
+      N=C17_
+      BUILD_TYPE=Release
+      ENABLE_SSL_DYNAMIC_LOADING=YES
+      ENABLE_CXX=NO
+      C_STANDARD=auto
+      CXX_STANDARD=auto
+      ENABLE_LUA_SHARED=NO
+      FEATURES=17
+      BUILD_SHARED=NO
+      NO_FILES=NO
+      ENABLE_SSL=NO
+      NO_CGI=YES
+      ENABLE_IPV6=NO
+      ENABLE_WEBSOCKETS=YES
+      ENABLE_LUA=NO
+      ENABLE_DUKTAPE=NO
+      NO_CACHING=NO
+
+  -
+    os: linux
+    compiler: clang
+    env:
+      N=C18_
+      BUILD_TYPE=Release
+      ENABLE_SSL_DYNAMIC_LOADING=YES
+      ENABLE_CXX=NO
+      C_STANDARD=auto
+      CXX_STANDARD=auto
+      ENABLE_LUA_SHARED=NO
+      FEATURES=18
+      BUILD_SHARED=NO
+      NO_FILES=YES
+      ENABLE_SSL=YES
+      NO_CGI=YES
+      ENABLE_IPV6=NO
+      ENABLE_WEBSOCKETS=YES
+      ENABLE_LUA=NO
+      ENABLE_DUKTAPE=NO
+      NO_CACHING=NO
+
+  -
+    os: linux
+    compiler: clang
+    env:
+      N=C19_
+      BUILD_TYPE=Release
+      ENABLE_SSL_DYNAMIC_LOADING=YES
+      ENABLE_CXX=NO
+      C_STANDARD=auto
+      CXX_STANDARD=auto
+      ENABLE_LUA_SHARED=NO
+      FEATURES=19
+      BUILD_SHARED=NO
+      NO_FILES=NO
+      ENABLE_SSL=YES
+      NO_CGI=YES
+      ENABLE_IPV6=NO
+      ENABLE_WEBSOCKETS=YES
+      ENABLE_LUA=NO
+      ENABLE_DUKTAPE=NO
+      NO_CACHING=NO
+
+  -
+    os: linux
+    compiler: clang
+    env:
+      N=C20_
+      BUILD_TYPE=Release
+      ENABLE_SSL_DYNAMIC_LOADING=YES
+      ENABLE_CXX=NO
+      C_STANDARD=auto
+      CXX_STANDARD=auto
+      ENABLE_LUA_SHARED=NO
+      FEATURES=20
+      BUILD_SHARED=NO
+      NO_FILES=YES
+      ENABLE_SSL=NO
+      NO_CGI=NO
+      ENABLE_IPV6=NO
+      ENABLE_WEBSOCKETS=YES
+      ENABLE_LUA=NO
+      ENABLE_DUKTAPE=NO
+      NO_CACHING=NO
+
+  -
+    os: linux
+    compiler: clang
+    env:
+      N=C21_
+      BUILD_TYPE=Release
+      ENABLE_SSL_DYNAMIC_LOADING=YES
+      ENABLE_CXX=NO
+      C_STANDARD=auto
+      CXX_STANDARD=auto
+      ENABLE_LUA_SHARED=NO
+      FEATURES=21
+      BUILD_SHARED=NO
+      NO_FILES=NO
+      ENABLE_SSL=NO
+      NO_CGI=NO
+      ENABLE_IPV6=NO
+      ENABLE_WEBSOCKETS=YES
+      ENABLE_LUA=NO
+      ENABLE_DUKTAPE=NO
+      NO_CACHING=NO
+
+  -
+    os: linux
+    compiler: clang
+    env:
+      N=C22_
+      BUILD_TYPE=Release
+      ENABLE_SSL_DYNAMIC_LOADING=YES
+      ENABLE_CXX=NO
+      C_STANDARD=auto
+      CXX_STANDARD=auto
+      ENABLE_LUA_SHARED=NO
+      FEATURES=22
+      BUILD_SHARED=NO
+      NO_FILES=YES
+      ENABLE_SSL=YES
+      NO_CGI=NO
+      ENABLE_IPV6=NO
+      ENABLE_WEBSOCKETS=YES
+      ENABLE_LUA=NO
+      ENABLE_DUKTAPE=NO
+      NO_CACHING=NO
+
+  -
+    os: linux
+    compiler: clang
+    env:
+      N=C23_
+      BUILD_TYPE=Release
+      ENABLE_SSL_DYNAMIC_LOADING=YES
+      ENABLE_CXX=NO
+      C_STANDARD=auto
+      CXX_STANDARD=auto
+      ENABLE_LUA_SHARED=NO
+      FEATURES=23
+      BUILD_SHARED=NO
+      NO_FILES=NO
+      ENABLE_SSL=YES
+      NO_CGI=NO
+      ENABLE_IPV6=NO
+      ENABLE_WEBSOCKETS=YES
+      ENABLE_LUA=NO
+      ENABLE_DUKTAPE=NO
+      NO_CACHING=NO
+
+  -
+    os: linux
+    compiler: clang
+    env:
+      N=C24_
+      BUILD_TYPE=Release
+      ENABLE_SSL_DYNAMIC_LOADING=YES
+      ENABLE_CXX=NO
+      C_STANDARD=auto
+      CXX_STANDARD=auto
+      ENABLE_LUA_SHARED=NO
+      FEATURES=24
+      BUILD_SHARED=NO
+      NO_FILES=YES
+      ENABLE_SSL=NO
+      NO_CGI=YES
+      ENABLE_IPV6=YES
+      ENABLE_WEBSOCKETS=YES
+      ENABLE_LUA=NO
+      ENABLE_DUKTAPE=NO
+      NO_CACHING=NO
+
+  -
+    os: linux
+    compiler: clang
+    env:
+      N=C25_
+      BUILD_TYPE=Release
+      ENABLE_SSL_DYNAMIC_LOADING=YES
+      ENABLE_CXX=NO
+      C_STANDARD=auto
+      CXX_STANDARD=auto
+      ENABLE_LUA_SHARED=NO
+      FEATURES=25
+      BUILD_SHARED=NO
+      NO_FILES=NO
+      ENABLE_SSL=NO
+      NO_CGI=YES
+      ENABLE_IPV6=YES
+      ENABLE_WEBSOCKETS=YES
+      ENABLE_LUA=NO
+      ENABLE_DUKTAPE=NO
+      NO_CACHING=NO
+
+  -
+    os: linux
+    compiler: clang
+    env:
+      N=C26_
+      BUILD_TYPE=Release
+      ENABLE_SSL_DYNAMIC_LOADING=YES
+      ENABLE_CXX=NO
+      C_STANDARD=auto
+      CXX_STANDARD=auto
+      ENABLE_LUA_SHARED=NO
+      FEATURES=26
+      BUILD_SHARED=NO
+      NO_FILES=YES
+      ENABLE_SSL=YES
+      NO_CGI=YES
+      ENABLE_IPV6=YES
+      ENABLE_WEBSOCKETS=YES
+      ENABLE_LUA=NO
+      ENABLE_DUKTAPE=NO
+      NO_CACHING=NO
+
+  -
+    os: linux
+    compiler: clang
+    env:
+      N=C27_
+      BUILD_TYPE=Release
+      ENABLE_SSL_DYNAMIC_LOADING=YES
+      ENABLE_CXX=NO
+      C_STANDARD=auto
+      CXX_STANDARD=auto
+      ENABLE_LUA_SHARED=NO
+      FEATURES=27
+      BUILD_SHARED=NO
+      NO_FILES=NO
+      ENABLE_SSL=YES
+      NO_CGI=YES
+      ENABLE_IPV6=YES
+      ENABLE_WEBSOCKETS=YES
+      ENABLE_LUA=NO
+      ENABLE_DUKTAPE=NO
+      NO_CACHING=NO
+
+  -
+    os: linux
+    compiler: clang
+    env:
+      N=C28_
+      BUILD_TYPE=Release
+      ENABLE_SSL_DYNAMIC_LOADING=YES
+      ENABLE_CXX=NO
+      C_STANDARD=auto
+      CXX_STANDARD=auto
+      ENABLE_LUA_SHARED=NO
+      FEATURES=28
+      BUILD_SHARED=NO
+      NO_FILES=YES
+      ENABLE_SSL=NO
+      NO_CGI=NO
+      ENABLE_IPV6=YES
+      ENABLE_WEBSOCKETS=YES
+      ENABLE_LUA=NO
+      ENABLE_DUKTAPE=NO
+      NO_CACHING=NO
+
+  -
+    os: linux
+    compiler: clang
+    env:
+      N=C29_
+      BUILD_TYPE=Release
+      ENABLE_SSL_DYNAMIC_LOADING=YES
+      ENABLE_CXX=NO
+      C_STANDARD=auto
+      CXX_STANDARD=auto
+      ENABLE_LUA_SHARED=NO
+      FEATURES=29
+      BUILD_SHARED=NO
+      NO_FILES=NO
+      ENABLE_SSL=NO
+      NO_CGI=NO
+      ENABLE_IPV6=YES
+      ENABLE_WEBSOCKETS=YES
+      ENABLE_LUA=NO
+      ENABLE_DUKTAPE=NO
+      NO_CACHING=NO
+
+  -
+    os: linux
+    compiler: clang
+    env:
+      N=C30_
+      BUILD_TYPE=Release
+      ENABLE_SSL_DYNAMIC_LOADING=YES
+      ENABLE_CXX=NO
+      C_STANDARD=auto
+      CXX_STANDARD=auto
+      ENABLE_LUA_SHARED=NO
+      FEATURES=30
+      BUILD_SHARED=NO
+      NO_FILES=YES
+      ENABLE_SSL=YES
+      NO_CGI=NO
+      ENABLE_IPV6=YES
+      ENABLE_WEBSOCKETS=YES
+      ENABLE_LUA=NO
+      ENABLE_DUKTAPE=NO
+      NO_CACHING=NO
+
+  -
+    os: linux
+    compiler: clang
+    env:
+      N=C31_
+      BUILD_TYPE=Release
+      ENABLE_SSL_DYNAMIC_LOADING=YES
+      ENABLE_CXX=NO
+      C_STANDARD=auto
+      CXX_STANDARD=auto
+      ENABLE_LUA_SHARED=NO
+      FEATURES=31
+      BUILD_SHARED=NO
+      NO_FILES=NO
+      ENABLE_SSL=YES
+      NO_CGI=NO
+      ENABLE_IPV6=YES
+      ENABLE_WEBSOCKETS=YES
+      ENABLE_LUA=NO
+      ENABLE_DUKTAPE=NO
+      NO_CACHING=NO
+
+### Test all build types:
+# According to CMakeLists, options are:
+# None Debug Release RelWithDebInfo MinSizeRel Coverage
+
+  -
+    os: linux
+    compiler: gcc
+    env:
+      N=GCCLinuxDefault_Debug
+      BUILD_TYPE=Debug
+      ENABLE_SSL_DYNAMIC_LOADING=YES
+      ENABLE_CXX=NO
+      ENABLE_LUA_SHARED=NO
+      C_STANDARD=auto
+      CXX_STANDARD=auto
+      FEATURES=7
+      BUILD_SHARED=NO
+      NO_FILES=NO
+      ENABLE_SSL=YES
+      NO_CGI=NO
+      ENABLE_IPV6=NO
+      ENABLE_WEBSOCKETS=NO
+      ENABLE_LUA=NO
+      ENABLE_DUKTAPE=NO
+      NO_CACHING=NO
+
+  -
+    os: linux
+    compiler: gcc
+    env:
+      N=GCCLinuxDefault_RelWithDebInfo
+      BUILD_TYPE=RelWithDebInfo
+      ENABLE_SSL_DYNAMIC_LOADING=YES
+      ENABLE_CXX=NO
+      ENABLE_LUA_SHARED=NO
+      C_STANDARD=auto
+      CXX_STANDARD=auto
+      FEATURES=7
+      BUILD_SHARED=NO
+      NO_FILES=NO
+      ENABLE_SSL=YES
+      NO_CGI=NO
+      ENABLE_IPV6=NO
+      ENABLE_WEBSOCKETS=NO
+      ENABLE_LUA=NO
+      ENABLE_DUKTAPE=NO
+      NO_CACHING=NO
+
+  -
+    os: linux
+    compiler: gcc
+    env:
+      N=GCCLinuxDefault_MinSizeRel
+      BUILD_TYPE=MinSizeRel
+      ENABLE_SSL_DYNAMIC_LOADING=YES
+      ENABLE_CXX=NO
+      ENABLE_LUA_SHARED=NO
+      C_STANDARD=auto
+      CXX_STANDARD=auto
+      FEATURES=7
+      BUILD_SHARED=NO
+      NO_FILES=NO
+      ENABLE_SSL=YES
+      NO_CGI=NO
+      ENABLE_IPV6=NO
+      ENABLE_WEBSOCKETS=NO
+      ENABLE_LUA=NO
+      ENABLE_DUKTAPE=NO
+      NO_CACHING=NO
+
+  -
+    os: linux
+    compiler: gcc
+    env:
+      N=GCCLinuxDefault_None
+      BUILD_TYPE=None
+      ENABLE_SSL_DYNAMIC_LOADING=YES
+      ENABLE_CXX=NO
+      ENABLE_LUA_SHARED=NO
+      C_STANDARD=auto
+      CXX_STANDARD=auto
+      FEATURES=7
+      BUILD_SHARED=NO
+      NO_FILES=NO
+      ENABLE_SSL=YES
+      NO_CGI=NO
+      ENABLE_IPV6=NO
+      ENABLE_WEBSOCKETS=NO
+      ENABLE_LUA=NO
+      ENABLE_DUKTAPE=NO
+      NO_CACHING=NO

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/CMakeLists.txt b/thirdparty/civetweb-1.9.1/CMakeLists.txt
new file mode 100644
index 0000000..d03c6cd
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/CMakeLists.txt
@@ -0,0 +1,461 @@
+# Determines what CMake APIs we can rely on
+cmake_minimum_required (VERSION 2.8.11)
+if (${CMAKE_VERSION} VERSION_GREATER 3.2.2)
+  cmake_policy(VERSION 3.2.2)
+endif()
+if (${CMAKE_VERSION} VERSION_GREATER 3.1 OR
+    ${CMAKE_VERSION} VERSION_EQUAL 3.1)
+  cmake_policy(SET CMP0054 NEW)
+endif()
+
+# Do not allow in source builds
+set(CMAKE_DISABLE_SOURCE_CHANGES ON)
+set(CMAKE_DISABLE_IN_SOURCE_BUILD ON)
+
+# Make sure we can import out CMake functions
+list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
+
+# Load in the needed CMake modules
+include(CheckIncludeFiles)
+include(CheckCCompilerFlag)
+include(CheckCXXCompilerFlag)
+include(AddCCompilerFlag)
+include(AddCXXCompilerFlag)
+include(DetermineTargetArchitecture)
+include(CMakeDependentOption)
+
+# Set up the project
+project (civetweb)
+set(CIVETWEB_VERSION "1.9.1" CACHE STRING "The version of the civetweb library")
+string(REGEX MATCH "([0-9]+)\\.([0-9]+)\\.([0-9]+)" CIVETWEB_VERSION_MATCH "${CIVETWEB_VERSION}")
+if ("${CIVETWEB_VERSION_MATCH}" STREQUAL "")
+  message(FATAL_ERROR "Must specify a semantic version: major.minor.patch")
+endif()
+set(CIVETWEB_VERSION_MAJOR "${CMAKE_MATCH_1}")
+set(CIVETWEB_VERSION_MINOR "${CMAKE_MATCH_2}")
+set(CIVETWEB_VERSION_PATCH "${CMAKE_MATCH_3}")
+determine_target_architecture(CIVETWEB_ARCHITECTURE)
+
+# Detect the platform reliably
+if(NOT MACOSX AND ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
+   SET(DARWIN YES)
+elseif(NOT BSD AND ${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
+    SET(FREEBSD YES)
+elseif(NOT LINUX AND ${CMAKE_SYSTEM_NAME} MATCHES "Linux")
+    SET(LINUX YES)
+endif()
+
+# C++ wrappers
+option(CIVETWEB_ENABLE_THIRD_PARTY_OUTPUT "Shows the output of third party dependency processing" OFF)
+
+# Max Request Size
+set(CIVETWEB_MAX_REQUEST_SIZE 16384 CACHE STRING
+  "The largest amount of content bytes allowed in a request")
+set_property(CACHE CIVETWEB_MAX_REQUEST_SIZE PROPERTY VALUE ${CIVETWEB_MAX_REQUEST_SIZE})
+message(STATUS "Max Request Size - ${CIVETWEB_MAX_REQUEST_SIZE}")
+
+# Thread Stack Size
+set(CIVETWEB_THREAD_STACK_SIZE 102400 CACHE STRING
+  "The stack size in bytes for each thread created")
+set_property(CACHE CIVETWEB_THREAD_STACK_SIZE PROPERTY VALUE ${CIVETWEB_THREAD_STACK_SIZE})
+message(STATUS "Thread Stack Size - ${CIVETWEB_THREAD_STACK_SIZE}")
+
+# Serve no files from the web server
+option(CIVETWEB_SERVE_NO_FILES "Configures the server to serve no static files" OFF)
+message(STATUS "Serve no static files - ${CIVETWEB_SERVE_NO_FILES}")
+
+# Serve no files from the web server
+option(CIVETWEB_DISABLE_CGI "Disables CGI, so theserver will not execute CGI scripts" OFF)
+message(STATUS "Disable CGI support - ${CIVETWEB_DISABLE_CGI}")
+
+# Disable caching
+option(CIVETWEB_DISABLE_CACHING "Disables caching, so that no timegm is used." OFF)
+message(STATUS "Disable caching support - ${CIVETWEB_DISABLE_CACHING}")
+
+# C++ wrappers
+option(CIVETWEB_ENABLE_CXX "Enables the C++ wrapper library" OFF)
+message(STATUS "C++ wrappers - ${CIVETWEB_ENABLE_CXX}")
+
+# IP Version 6
+option(CIVETWEB_ENABLE_IPV6 "Enables the IP version 6 support" OFF)
+message(STATUS "IP Version 6 - ${CIVETWEB_ENABLE_IPV6}")
+
+# Websocket support
+option(CIVETWEB_ENABLE_WEBSOCKETS "Enable websockets connections" OFF)
+message(STATUS "Websockets support - ${CIVETWEB_ENABLE_WEBSOCKETS}")
+
+# Memory debugging
+option(CIVETWEB_ENABLE_MEMORY_DEBUGGING "Enable the memory debugging features" OFF)
+message(STATUS "Memory Debugging - ${CIVETWEB_ENABLE_MEMORY_DEBUGGING}")
+
+# LUA CGI support
+option(CIVETWEB_ENABLE_LUA "Enable Lua CGIs" OFF)
+message(STATUS "Lua CGI support - ${CIVETWEB_ENABLE_LUA}")
+
+# Allow builds to complete with warnings (do not set -Werror)
+if (LINUX)
+# CivetWeb Linux support is stable: Builds must be free from warnings.
+  option(CIVETWEB_ALLOW_WARNINGS "Do not stop build if there are warnings" OFF)
+else()
+# CivetWeb Linux support for other systems is in a setup phase.
+  option(CIVETWEB_ALLOW_WARNINGS "Do not stop build if there are warnings" ON)
+endif()
+message(STATUS "Build if there are warnings - ${CIVETWEB_ALLOW_WARNINGS}")
+
+# Link to the shared LUA library
+cmake_dependent_option(
+  CIVETWEB_ENABLE_LUA_SHARED  "Link to the shared LUA system library" OFF
+ CIVETWEB_ENABLE_LUA OFF)
+if (CIVETWEB_ENABLE_LUA)
+  message(STATUS "Linking shared Lua library - ${CIVETWEB_ENABLE_LUA_SHARED}")
+endif()
+
+# Lua Third Party Settings
+if (CIVETWEB_ENABLE_LUA)
+  if (NOT CIVETWEB_ENABLE_LUA_SHARED)
+    # Lua Version
+    set(CIVETWEB_LUA_VERSION 5.2.4 CACHE STRING
+      "The version of Lua to build and include statically")
+    set_property(CACHE CIVETWEB_LUA_VERSION PROPERTY VALUE ${CIVETWEB_LUA_VERSION})
+    message(STATUS "Lua Version - ${CIVETWEB_LUA_VERSION}")
+    mark_as_advanced(CIVETWEB_LUA_VERSION)
+
+    # Lua Verification Hash
+    set(CIVETWEB_LUA_MD5_HASH 913fdb32207046b273fdb17aad70be13 CACHE STRING
+      "The hash of Lua archive to be downloaded")
+    set_property(CACHE CIVETWEB_LUA_MD5_HASH PROPERTY VALUE ${CIVETWEB_LUA_MD5_HASH})
+    mark_as_advanced(CIVETWEB_LUA_MD5_HASH)
+  endif()
+
+  # Lua Filesystem Version
+  set(CIVETWEB_LUA_FILESYSTEM_VERSION 1.6.3 CACHE STRING
+    "The version of Lua Filesystem to build and include statically")
+  set_property(CACHE CIVETWEB_LUA_FILESYSTEM_VERSION PROPERTY VALUE ${CIVETWEB_LUA_FILESYSTEM_VERSION})
+  message(STATUS "Lua Filesystem Version - ${CIVETWEB_LUA_FILESYSTEM_VERSION}")
+  mark_as_advanced(CIVETWEB_LUA_FILESYSTEM_VERSION)
+
+  # Lua Filesystem Verification Hash
+  set(CIVETWEB_LUA_FILESYSTEM_MD5_HASH d0552c7e5a082f5bb2865af63fb9dc95 CACHE STRING
+    "The hash of Lua Filesystem archive to be downloaded")
+  set_property(CACHE CIVETWEB_LUA_FILESYSTEM_MD5_HASH PROPERTY VALUE ${CIVETWEB_LUA_FILESYSTEM_MD5_HASH})
+  mark_as_advanced(CIVETWEB_LUA_FILESYSTEM_MD5_HASH)
+
+  # Lua SQLite Version
+  set(CIVETWEB_LUA_SQLITE_VERSION 0.9.3 CACHE STRING
+    "The version of Lua SQLite to build and include statically")
+  set_property(CACHE CIVETWEB_LUA_SQLITE_VERSION PROPERTY VALUE ${CIVETWEB_LUA_SQLITE_VERSION})
+  message(STATUS "Lua SQLite Version - ${CIVETWEB_LUA_SQLITE_VERSION}")
+  mark_as_advanced(CIVETWEB_LUA_SQLITE_VERSION)
+
+  # Lua SQLite Verification Hash
+  set(CIVETWEB_LUA_SQLITE_MD5_HASH 43234ae08197dfce6da02482ed14ec92 CACHE STRING
+    "The hash of Lua SQLite archive to be downloaded")
+  set_property(CACHE CIVETWEB_LUA_SQLITE_MD5_HASH PROPERTY VALUE ${CIVETWEB_LUA_SQLITE_MD5_HASH})
+  mark_as_advanced(CIVETWEB_LUA_SQLITE_MD5_HASH)
+
+  # Lua XML Version
+  set(CIVETWEB_LUA_XML_VERSION 1.8.0 CACHE STRING
+    "The version of Lua XML to build and include statically")
+  set_property(CACHE CIVETWEB_LUA_XML_VERSION PROPERTY VALUE ${CIVETWEB_LUA_XML_VERSION})
+  message(STATUS "Lua XML Version - ${CIVETWEB_LUA_XML_VERSION}")
+  mark_as_advanced(CIVETWEB_LUA_XML_VERSION)
+
+  # Lua XML Verification Hash
+  set(CIVETWEB_LUA_XML_MD5_HASH 25e4c276c5d8716af1de0c7853aec2b4 CACHE STRING
+    "The hash of Lua XML archive to be downloaded")
+  set_property(CACHE CIVETWEB_LUA_XML_MD5_HASH PROPERTY VALUE ${CIVETWEB_LUA_XML_MD5_HASH})
+  mark_as_advanced(CIVETWEB_LUA_XML_MD5_HASH)
+
+  # SQLite Version
+  set(CIVETWEB_SQLITE_VERSION 3.8.9 CACHE STRING
+    "The version of SQLite to build and include statically")
+  set_property(CACHE CIVETWEB_SQLITE_VERSION PROPERTY VALUE ${CIVETWEB_SQLITE_VERSION})
+  message(STATUS "SQLite Version - ${CIVETWEB_SQLITE_VERSION}")
+  mark_as_advanced(CIVETWEB_SQLITE_VERSION)
+
+  # SQLite Verification Hash
+  set(CIVETWEB_SQLITE_MD5_HASH 02e9c3a6daa8b8587cf6bef828c2e33f CACHE STRING
+    "The hash of SQLite archive to be downloaded")
+  set_property(CACHE CIVETWEB_SQLITE_MD5_HASH PROPERTY VALUE ${CIVETWEB_SQLITE_MD5_HASH})
+  mark_as_advanced(CIVETWEB_SQLITE_MD5_HASH)
+endif()
+
+# Duktape CGI support
+option(CIVETWEB_ENABLE_DUKTAPE "Enable Duktape CGIs" OFF)
+message(STATUS "Duktape CGI support - ${CIVETWEB_ENABLE_DUKTAPE}")
+
+# SSL support
+option(CIVETWEB_ENABLE_SSL "Enables the secure socket layer" ON)
+message(STATUS "SSL support - ${CIVETWEB_ENABLE_SSL}")
+
+# Dynamically load or link the SSL libraries
+cmake_dependent_option(
+  CIVETWEB_ENABLE_SSL_DYNAMIC_LOADING "Dynamically loads the SSL library rather than linking it" ON
+  CIVETWEB_ENABLE_SSL OFF)
+if (CIVETWEB_ENABLE_SSL)
+  message(STATUS "Dynamically load SSL libraries - ${CIVETWEB_ENABLE_SSL_DYNAMIC_LOADING}")
+endif()
+
+# Third Party Download location
+set(CIVETWEB_THIRD_PARTY_DIR "${CMAKE_BINARY_DIR}/third_party" CACHE STRING
+  "The location that third party code is downloaded, built and installed")
+set_property(CACHE CIVETWEB_THIRD_PARTY_DIR PROPERTY VALUE ${CIVETWEB_THIRD_PARTY_DIR})
+
+# Unix systems can define the dynamic library names to load
+if (CIVETWEB_ENABLE_SSL_DYNAMIC_LOADING AND NOT DARWIN AND UNIX)
+  # SSL library name
+  set(CIVETWEB_SSL_SSL_LIB "libssl.so" CACHE STRING
+    "The name of the SSL library to load")
+  set_property(CACHE CIVETWEB_SSL_SSL_LIB PROPERTY VALUE ${CIVETWEB_SSL_SSL_LIB})
+  message(STATUS "SSL Library Name - ${CIVETWEB_SSL_SSL_LIB}")
+
+  # Crytography library name
+  set(CIVETWEB_SSL_CRYPTO_LIB "libcrypto.so" CACHE STRING
+    "The name of the SSL Cryptography library to load")
+  set_property(CACHE CIVETWEB_SSL_CRYPTO_LIB PROPERTY VALUE ${CIVETWEB_SSL_CRYPTO_LIB})
+  message(STATUS "SSL Cryptography Library Name - ${CIVETWEB_SSL_CRYPTO_LIB}")
+endif()
+
+# Allow warnings in 3rd party components
+if (CIVETWEB_ENABLE_LUA OR CIVETWEB_ENABLE_DUKTAPE)
+SET(CIVETWEB_ALLOW_WARNINGS YES)
+endif()
+
+# The C and C++ standards to use
+set(CIVETWEB_C_STANDARD auto CACHE STRING
+  "The C standard to use; auto determines the latest supported by the compiler")
+set_property(CACHE CIVETWEB_C_STANDARD PROPERTY STRINGS auto c11 c99 c89)
+set(CIVETWEB_CXX_STANDARD auto CACHE STRING
+  "The C++ standard to use; auto determines the latest supported by the compiler")
+set_property(CACHE CIVETWEB_CXX_STANDARD PROPERTY STRINGS auto c++14 c++11 c++98)
+
+# Configure the linker
+if ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU")
+  find_program(GCC_AR gcc-ar)
+  if (GCC_AR)
+    set(CMAKE_AR ${GCC_AR})
+  endif()
+  find_program(GCC_RANLIB gcc-ranlib)
+  if (GCC_RANLIB)
+    set(CMAKE_RANLIB ${GCC_RANLIB})
+  endif()
+endif()
+
+# Configure the C compiler
+message(STATUS "Configuring C Compiler")
+if ("${CIVETWEB_C_STANDARD}" STREQUAL "auto")
+  add_c_compiler_flag(-std=c11)
+  if (NOT HAVE_C_FLAG_STD_C11)
+    add_c_compiler_flag(-std=c99)
+    if (NOT HAVE_C_FLAG_STD_C99)
+      add_c_compiler_flag(-std=c89)
+    endif()
+  endif()
+else()
+  add_c_compiler_flag(-std=${CIVETWEB_C_STANDARD})
+endif()
+add_c_compiler_flag(-Wall)
+add_c_compiler_flag(-Wextra)
+add_c_compiler_flag(-Wshadow)
+add_c_compiler_flag(-Wconversion)
+add_c_compiler_flag(-Wmissing-prototypes)
+add_c_compiler_flag(-Weverything)
+add_c_compiler_flag(/W4)
+add_c_compiler_flag(-Wno-padded)
+add_c_compiler_flag(/Wd4820) # padding
+add_c_compiler_flag(-Wno-unused-macros)
+add_c_compiler_flag(-Wno-format-nonliteral)
+add_c_compiler_flag(-Wparentheses)
+if (MINGW)
+  add_c_compiler_flag(-Wno-format)
+endif()
+if (NOT CIVETWEB_ALLOW_WARNINGS)
+  add_c_compiler_flag(-Werror)
+endif()
+add_c_compiler_flag(/WX)
+add_c_compiler_flag(-pedantic-errors)
+add_c_compiler_flag(-fvisibility=hidden)
+add_c_compiler_flag(-fstack-protector-strong RELEASE)
+add_c_compiler_flag(-flto RELEASE)
+add_c_compiler_flag(-fsanitize=undefined DEBUG)
+add_c_compiler_flag(-fsanitize=address DEBUG)
+if (HAVE_C_FLAG_FSANITIZE_ADDRESS)
+  add_c_compiler_flag(-static-asan DEBUG)
+endif()
+add_c_compiler_flag(-fstack-protector-all DEBUG)
+if (MINGW)
+  add_c_compiler_flag(-mwindows)
+endif()
+
+# Coverage build type
+set(CMAKE_C_FLAGS_COVERAGE "${CMAKE_C_FLAGS_DEBUG}" CACHE STRING
+    "Flags used by the C compiler during coverage builds."
+    FORCE)
+set(CMAKE_EXE_LINKER_FLAGS_COVERAGE
+    "${CMAKE_EXE_LINKER_FLAGS_DEBUG}" CACHE STRING
+    "Flags used for linking binaries during coverage builds."
+    FORCE)
+set(CMAKE_SHARED_LINKER_FLAGS_COVERAGE
+    "${CMAKE_SHARED_LINKER_FLAGS_DEBUG}" CACHE STRING
+    "Flags used by the shared libraries linker during coverage builds."
+    FORCE)
+mark_as_advanced(
+    CMAKE_CXX_FLAGS_COVERAGE
+    CMAKE_C_FLAGS_COVERAGE
+    CMAKE_EXE_LINKER_FLAGS_COVERAGE
+    CMAKE_SHARED_LINKER_FLAGS_COVERAGE)
+set(CMAKE_BUILD_TYPE "${CMAKE_BUILD_TYPE}" CACHE STRING
+    "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel Coverage."
+    FORCE)
+add_c_compiler_flag(--coverage COVERAGE)
+
+# Configure the C++ compiler
+if (CIVETWEB_ENABLE_CXX)
+  message(STATUS "Configuring C++ Compiler")
+  if ("${CIVETWEB_CXX_STANDARD}" STREQUAL "auto")
+    add_cxx_compiler_flag(-std=c++14)
+    if (NOT HAVE_CXX_FLAG_STD_CXX14)
+      add_cxx_compiler_flag(-std=c++11)
+      if (NOT HAVE_CXX_FLAG_STD_CXX11)
+        add_cxx_compiler_flag(-std=c++98)
+      endif()
+    endif()
+  else()
+    add_cxx_compiler_flag(-std=${CIVETWEB_CXX_STANDARD})
+  endif()
+  add_cxx_compiler_flag(-Wall)
+  add_cxx_compiler_flag(-Wextra)
+  add_cxx_compiler_flag(-Wshadow)
+  add_cxx_compiler_flag(-Wmissing-prototypes)
+  add_cxx_compiler_flag(-Weverything)
+  add_cxx_compiler_flag(/W4)
+  add_cxx_compiler_flag(-Wno-padded)
+  add_cxx_compiler_flag(/Wd4820) # padding
+  add_cxx_compiler_flag(-Wno-unused-macros)
+  add_cxx_compiler_flag(-Wno-format-nonliteral)
+  if (MINGW)
+    add_cxx_compiler_flag(-Wno-format)
+  endif()
+  if (NOT CIVETWEB_ALLOW_WARNINGS)
+    add_cxx_compiler_flag(-Werror)
+  endif()
+  add_cxx_compiler_flag(/WX)
+  add_cxx_compiler_flag(-pedantic-errors)
+  add_cxx_compiler_flag(-fvisibility=hidden)
+  add_cxx_compiler_flag(-fstack-protector-strong RELEASE)
+  add_cxx_compiler_flag(-flto RELEASE)
+  add_cxx_compiler_flag(-fsanitize=undefined DEBUG)
+  add_cxx_compiler_flag(-fsanitize=address DEBUG)
+  if (HAVE_CXX_FLAG_FSANITIZE_ADDRESS)
+    add_cxx_compiler_flag(-static-asan DEBUG)
+  endif()
+  add_cxx_compiler_flag(-fstack-protector-all DEBUG)
+  if (MINGW)
+    add_cxx_compiler_flag(-mwindows)
+  endif()
+  set(CMAKE_CXX_FLAGS_COVERAGE "${CMAKE_CXX_FLAGS_DEBUG}" CACHE STRING
+      "Flags used by the C++ compiler during coverage builds."
+      FORCE)
+  add_cxx_compiler_flag(--coverage COVERAGE)
+endif()
+
+# Set up the definitions
+if (${CMAKE_BUILD_TYPE} MATCHES "[Dd]ebug")
+  add_definitions(-DDEBUG)
+endif()
+if (CIVETWEB_ENABLE_IPV6)
+  add_definitions(-DUSE_IPV6)
+endif()
+if (CIVETWEB_ENABLE_WEBSOCKETS)
+  add_definitions(-DUSE_WEBSOCKET)
+endif()
+if (CIVETWEB_SERVE_NO_FILES)
+  add_definitions(-DNO_FILES)
+endif()
+if (CIVETWEB_DISABLE_CGI)
+  add_definitions(-DNO_CGI)
+endif()
+if (CIVETWEB_DISABLE_CACHING)
+  add_definitions(-DNO_CACHING)
+endif()
+if (CIVETWEB_ENABLE_LUA)
+  add_definitions(-DUSE_LUA)
+endif()
+if (CIVETWEB_ENABLE_DUKTAPE)
+  add_definitions(-DUSE_DUKTAPE)
+endif()
+if (CIVETWEB_ENABLE_MEMORY_DEBUGGING)
+  add_definitions(-DMEMORY_DEBUGGING)
+endif()
+if (NOT CIVETWEB_ENABLE_SSL)
+  add_definitions(-DNO_SSL)
+elseif (NOT CIVETWEB_ENABLE_SSL_DYNAMIC_LOADING)
+  add_definitions(-DNO_SSL_DL)
+else()
+  if(CIVETWEB_SSL_SSL_LIB)
+    add_definitions(-DSSL_LIB="${CIVETWEB_SSL_SSL_LIB}")
+  endif()
+  if(CIVETWEB_SSL_CRYPTO_LIB)
+    add_definitions(-DCRYPTO_LIB="${CIVETWEB_SSL_CRYPTO_LIB}")
+  endif()
+endif()
+add_definitions(-DUSE_STACK_SIZE=${CIVETWEB_THREAD_STACK_SIZE})
+add_definitions(-DMAX_REQUEST_SIZE=${CIVETWEB_MAX_REQUEST_SIZE})
+
+# Build the targets
+add_subdirectory(src)
+
+# Enable the testing of the library/executable
+include(CTest)
+if (BUILD_TESTING)
+  # Check unit testing framework Version
+  set(CIVETWEB_CHECK_VERSION 0.11.0 CACHE STRING
+    "The version of Check unit testing framework to build and include statically")
+  set_property(CACHE CIVETWEB_CHECK_VERSION PROPERTY VALUE ${CIVETWEB_CHECK_VERSION})
+  message(STATUS "Check Unit Testing Framework Version - ${CIVETWEB_CHECK_VERSION}")
+  mark_as_advanced(CIVETWEB_CHECK_VERSION)
+
+  # Check unit testing framework Verification Hash
+  # Hash for Check 0.10.0: 67a34c40b5bc888737f4e5ae82e9939f
+  # Hash for Check 0.11.0: 1b14ee307dca8e954a8219c34484d7c4
+  set(CIVETWEB_CHECK_MD5_HASH 1b14ee307dca8e954a8219c34484d7c4 CACHE STRING
+    "The hash of Check unit testing framework archive to be downloaded")
+  set_property(CACHE CIVETWEB_CHECK_MD5_HASH PROPERTY VALUE ${CIVETWEB_CHECK_MD5_HASH})
+  mark_as_advanced(CIVETWEB_CHECK_MD5_HASH)
+
+  # Build the testing
+  add_subdirectory(test)
+endif()
+
+# Set up CPack
+include(InstallRequiredSystemLibraries)
+set(CPACK_PACKAGE_VENDOR "civetweb Contributors")
+set(CPACK_PACKAGE_CONTACT "civetweb@github.com")
+set(CPACK_PACKAGE_VERSION_MAJOR "${CIVETWEB_VERSION_MAJOR}")
+set(CPACK_PACKAGE_VERSION_MINOR "${CIVETWEB_VERSION_MINOR}")
+set(CPACK_PACKAGE_VERSION_PATCH "${CIVETWEB_VERSION_PATCH}")
+set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "A HTTP library and server")
+set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
+set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.md")
+set(CPACK_STRIP_FILES TRUE)
+set(CPACK_PACKAGE_DEPENDS "openssl")
+if (CIVETWEB_ENABLE_LUA_SHARED)
+  set(CPACK_PACKAGE_DEPENDS "lua, ${CPACK_PACKAGE_DEPENDS}")
+endif()
+
+# RPM Packaging
+set(CPACK_RPM_PACKAGE_GROUP "Development/Libraries")
+set(CPACK_RPM_PACKAGE_LICENSE "MIT")
+set(CPACK_RPM_PACKAGE_ARCHITECTURE "${CIVETWEB_ARCHITECTURE}")
+set(CPACK_RPM_PACKAGE_REQUIRES "${CPACK_PACKAGE_DEPENDS}")
+
+# Debian Packaging
+set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "${CIVETWEB_ARCHITECTURE}")
+set(CPACK_DEBIAN_PACKAGE_HOMEPAGE "https://github.com/civetweb/civetweb")
+set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_PACKAGE_DEPENDS}")
+
+# WiX Packaging
+# TODO: www.cmake.org/cmake/help/v3.0/module/CPackWIX.html
+
+# Finalize CPack settings
+include(CPack)

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/CREDITS.md
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/CREDITS.md b/thirdparty/civetweb-1.9.1/CREDITS.md
new file mode 100644
index 0000000..b71f30a
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/CREDITS.md
@@ -0,0 +1,143 @@
+# Civetweb Contributors
+
+* Alex Kozlov
+* bel2125
+* Ben M. Ward
+* brett
+* Bjoern Petri
+* Brian Lambert
+* Brian Spratke
+* cdbishop
+* celeron55
+* Charles Olivi
+* Christian Mauderer
+* Christopher Galas
+* cjh
+* Daniel Oaks
+* Daniel Rempel
+* Danny Al-Gaaf
+* Dave Brower
+* David Arnold
+* David Loffredo
+* Dialga
+* ehlertjd
+* Eric Tsau
+* Erik Beran
+* F-Secure Corporation
+* feneuilflo
+* Fernando G. Aranda
+* Grahack
+* grenclave
+* hansipie
+* HariKamath Kamath
+* Jack
+* Jacob Skillin
+* Jan Willem Janssen
+* Jeremy Lin
+* Jim Evans
+* jmc-
+* Jochen Scheib
+* Joe Mucchiello
+* Joel Gallant
+* Johan De Taeye
+* Jordan
+* Jordan Shelley
+* Joshua Boyd
+* Joshua D. Boyd
+* kalphamon
+* Keith Kyzivat
+* Kevin Wojniak
+* Kimmo Mustonen
+* Lammert Bies
+* Lawrence
+* Li Peng
+* Lianghui
+* Maarten Fremouw
+* makrsmark
+* Mark Lakata
+* Martin Gaida
+* Mateusz Gralka
+* Matt Clarkson
+* mingodad
+* Morgan McGuire
+* Neil Jensen
+* Nick Hildebrant
+* Nigel Stewart
+* nihildeb
+* No Face Press
+* Patrick Trinkle
+* Paul Sokolovsky
+* Perttu Ahola
+* Peter Foerster
+* Philipp Friedenberger
+* Philipp Hasper
+* Red54
+* Richard Screene
+* Sage Weil
+* Sangwhan Moon
+* Saumitra Vikram
+* Scott Nations
+* shantanugadgil
+* SpaceLord
+* sunfch
+* thewaterymoon
+* Thomas Davis
+* tnoho
+* Toni Wilk
+* Ulrich Hertlein
+* Walt Steverson
+* William Greathouse
+* xtne6f
+* Yehuda Sadeh
+
+# Mongoose Contributors
+Civetweb is based on the Mongoose code.  The following users contributed to the original Mongoose release between 2010 and 2013.  This list was generated from the Mongoose GIT logs.  It does not contain contributions from the Mongoose mailing list.  There is no record for contributors prior to 2010.
+
+* Sergey Lyubka
+* Arnout Vandecappelle (Essensium/Mind)
+* Beno�t Amiaux
+* Cody Hanson
+* Colin Leitner
+* Daniel Oaks
+* Eric Bakan
+* Erik Oomen
+* Filipp Kovalev
+* Ger Hobbelt
+* Hendrik Polczynski
+* Henrique Mendon�a
+* Igor Okulist
+* Jay
+* Joe Mucchiello
+* John Safranek
+* Joseph Mainwaring
+* Jos� Miguel Gon�alves
+* KIU Shueng Chuan
+* Katerina Blinova
+* Konstantin Sorokin
+* Marin Atanasov Nikolov
+* Matt Healy
+* Miguel Morales
+* Mikhail Nikalyukin
+* MikieMorales
+* Mitch Hendrickson
+* Nigel Stewart
+* Pavel
+* Pavel Khlebovich
+* Rogerz Zhang
+* Sebastian Reinhard
+* Stefan Doehla
+* Thileepan
+* abadc0de
+* arvidn
+* bick
+* ff.feng
+* jmucchiello
+* jwang
+* lsm
+* migal
+* mlamb
+* nullable.type
+* shantanugadgil
+* tayS
+* test
+* valenok

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/LICENSE.md
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/LICENSE.md b/thirdparty/civetweb-1.9.1/LICENSE.md
new file mode 100644
index 0000000..263690e
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/LICENSE.md
@@ -0,0 +1,210 @@
+ALL LICENSES
+=====
+
+This document includes several copyright licenses for different
+aspects of the software.  Not all licenses may apply depending
+on the features chosen.
+
+
+Civetweb License
+-----
+
+### Included with all features.
+
+> Copyright (c) 2013-2015 The CivetWeb developers ([CREDITS.md](https://github.com/civetweb/civetweb/blob/master/CREDITS.md))
+>
+> Copyright (c) 2004-2013 Sergey Lyubka
+>
+> Copyright (c) 2013 No Face Press, LLC (Thomas Davis)
+>
+> Copyright (c) 2013 F-Secure Corporation
+>
+> Permission is hereby granted, free of charge, to any person obtaining a copy
+> of this software and associated documentation files (the "Software"), to deal
+> in the Software without restriction, including without limitation the rights
+> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+> copies of the Software, and to permit persons to whom the Software is
+> furnished to do so, subject to the following conditions:
+>
+> The above copyright notice and this permission notice shall be included in
+> all copies or substantial portions of the Software.
+>
+> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+> THE SOFTWARE.
+
+
+Lua License
+------
+
+### Included only if built with Lua support.
+
+http://www.lua.org/license.html
+
+> Copyright (C) 1994-2015 Lua.org, PUC-Rio.
+>
+> Permission is hereby granted, free of charge, to any person obtaining a copy
+> of this software and associated documentation files (the "Software"), to deal
+> in the Software without restriction, including without limitation the rights
+> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+> copies of the Software, and to permit persons to whom the Software is
+> furnished to do so, subject to the following conditions:
+>
+> The above copyright notice and this permission notice shall be included in
+> all copies or substantial portions of the Software.
+>
+> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+> THE SOFTWARE.
+
+
+SQLite3 License
+------
+
+### Included only if built with Lua and SQLite support.
+
+http://www.sqlite.org/copyright.html
+
+> 2001 September 15
+>
+> The author disclaims copyright to this source code.  In place of
+> a legal notice, here is a blessing:
+>
+>    May you do good and not evil.
+>    May you find forgiveness for yourself and forgive others.
+>    May you share freely, never taking more than you give.
+
+
+lsqlite3 License
+------
+
+### Included only if built with Lua and SQLite support.
+
+> Copyright (C) 2002-2013 Tiago Dionizio, Doug Currie
+> All rights reserved.
+> Author    : Tiago Dionizio <ti...@ist.utl.pt>
+> Author    : Doug Currie <do...@alum.mit.edu>
+> Library   : lsqlite3 - a SQLite 3 database binding for Lua 5
+>
+> Permission is hereby granted, free of charge, to any person obtaining a copy
+> of this software and associated documentation files (the "Software"), to deal
+> in the Software without restriction, including without limitation the rights
+> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+> copies of the Software, and to permit persons to whom the Software is
+> furnished to do so, subject to the following conditions:
+>
+> The above copyright notice and this permission notice shall be included in
+> all copies or substantial portions of the Software.
+>
+> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+> THE SOFTWARE.
+
+
+Lua File System License
+------
+
+### Included only if built with Lua support.
+
+http://keplerproject.github.io/luafilesystem/license.html
+
+> Copyright � 2003 Kepler Project.
+>
+> Permission is hereby granted, free of charge, to any person obtaining a copy
+> of this software and associated documentation files (the "Software"), to deal
+> in the Software without restriction, including without limitation the rights
+> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+> copies of the Software, and to permit persons to whom the Software is
+> furnished to do so, subject to the following conditions:
+>
+> The above copyright notice and this permission notice shall be included in
+> all copies or substantial portions of the Software.
+>
+> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+> THE SOFTWARE.
+
+
+LuaXML License
+------
+
+### Included only if built with Lua and LuaXML support.
+
+> LuaXML License
+>
+> LuaXml is licensed under the terms of the MIT license reproduced below,
+> the same as Lua itself. This means that LuaXml is free software and can be
+> used for both academic and commercial purposes at absolutely no cost.
+>
+> Copyright (C) 2007-2013 Gerald Franz, eludi.net
+>
+> Permission is hereby granted, free of charge, to any person obtaining a copy
+> of this software and associated documentation files (the "Software"), to deal
+> in the Software without restriction, including without limitation the rights
+> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+> copies of the Software, and to permit persons to whom the Software is
+> furnished to do so, subject to the following conditions:
+>
+> The above copyright notice and this permission notice shall be included in
+> all copies or substantial portions of the Software.
+>
+> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+> THE SOFTWARE.
+
+
+Duktape License
+------
+
+### Included only if built with Duktape support.
+
+https://github.com/svaarala/duktape/blob/master/LICENSE.txt
+
+> ===============
+> Duktape license
+> ===============
+> 
+> (http://opensource.org/licenses/MIT)
+> 
+> Copyright (c) 2013-2015 by Duktape authors (see AUTHORS.rst)
+>
+> Permission is hereby granted, free of charge, to any person obtaining a copy
+> of this software and associated documentation files (the "Software"), to deal
+> in the Software without restriction, including without limitation the rights
+> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+> copies of the Software, and to permit persons to whom the Software is
+> furnished to do so, subject to the following conditions:
+>
+> The above copyright notice and this permission notice shall be included in
+> all copies or substantial portions of the Software.
+>
+> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+> THE SOFTWARE.
+
+
+


[18/51] [partial] nifi-minifi-cpp git commit: MINIFI-183 Added civet 1.9.1 sources Added onScheduled hook Added initial two-way TLS-enabled ListenHTTP implementation

Posted by al...@apache.org.
http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-noline/metadata.json
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-noline/metadata.json b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-noline/metadata.json
new file mode 100644
index 0000000..56ef280
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-noline/metadata.json
@@ -0,0 +1,629 @@
+{
+    "line_map": [
+        {
+            "original_line": 1, 
+            "combined_line": 114, 
+            "original_file": "duk_internal.h"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 159, 
+            "original_file": "duk_replacements.h"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 187, 
+            "original_file": "duk_jmpbuf.h"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 211, 
+            "original_file": "duk_exception.h"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 229, 
+            "original_file": "duk_forwdecl.h"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 351, 
+            "original_file": "duk_tval.h"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 869, 
+            "original_file": "duk_builtins.h"
+        }, 
+        {
+            "original_line": 52, 
+            "combined_line": 1723, 
+            "original_file": "duk_internal.h"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 1724, 
+            "original_file": "duk_util.h"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 2254, 
+            "original_file": "duk_strings.h"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 2506, 
+            "original_file": "duk_js_bytecode.h"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 2711, 
+            "original_file": "duk_lexer.h"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 3143, 
+            "original_file": "duk_js_compiler.h"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 3370, 
+            "original_file": "duk_regexp.h"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 3452, 
+            "original_file": "duk_heaphdr.h"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 4202, 
+            "original_file": "duk_api_internal.h"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 4396, 
+            "original_file": "duk_hstring.h"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 4615, 
+            "original_file": "duk_hobject.h"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 5541, 
+            "original_file": "duk_hcompiledfunction.h"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 5780, 
+            "original_file": "duk_hnativefunction.h"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 5812, 
+            "original_file": "duk_hbufferobject.h"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 5945, 
+            "original_file": "duk_hthread.h"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 6325, 
+            "original_file": "duk_hbuffer.h"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 6653, 
+            "original_file": "duk_heap.h"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 7249, 
+            "original_file": "duk_debugger.h"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 7393, 
+            "original_file": "duk_debug.h"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 7578, 
+            "original_file": "duk_error.h"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 8017, 
+            "original_file": "duk_unicode.h"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 8284, 
+            "original_file": "duk_json.h"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 8352, 
+            "original_file": "duk_js.h"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 8451, 
+            "original_file": "duk_numconv.h"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 8541, 
+            "original_file": "duk_bi_protos.h"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 8610, 
+            "original_file": "duk_selftest.h"
+        }, 
+        {
+            "original_line": 78, 
+            "combined_line": 8622, 
+            "original_file": "duk_internal.h"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 8624, 
+            "original_file": "duk_replacements.c"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 8706, 
+            "original_file": "duk_strings.c"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 8821, 
+            "original_file": "duk_debug_macros.c"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 8965, 
+            "original_file": "duk_builtins.c"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 9741, 
+            "original_file": "duk_error_macros.c"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 9904, 
+            "original_file": "duk_unicode_support.c"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 11077, 
+            "original_file": "duk_util_misc.c"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 11299, 
+            "original_file": "duk_util_hashprime.c"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 11376, 
+            "original_file": "duk_hobject_class.c"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 11508, 
+            "original_file": "duk_alloc_default.c"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 11542, 
+            "original_file": "duk_api_buffer.c"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 11615, 
+            "original_file": "duk_api_bytecode.c"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 12342, 
+            "original_file": "duk_api_call.c"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 12897, 
+            "original_file": "duk_api_codec.c"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 13535, 
+            "original_file": "duk_api_compile.c"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 13729, 
+            "original_file": "duk_api_debug.c"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 13992, 
+            "original_file": "duk_api_heap.c"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 14126, 
+            "original_file": "duk_api_logging.c"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 14178, 
+            "original_file": "duk_api_memory.c"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 14281, 
+            "original_file": "duk_api_object.c"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 14891, 
+            "original_file": "duk_api_stack.c"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 19549, 
+            "original_file": "duk_api_string.c"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 19880, 
+            "original_file": "duk_api_var.c"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 19966, 
+            "original_file": "duk_bi_array.c"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 21411, 
+            "original_file": "duk_bi_boolean.c"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 21479, 
+            "original_file": "duk_bi_buffer.c"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 24361, 
+            "original_file": "duk_bi_date.c"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 26089, 
+            "original_file": "duk_bi_date_unix.c"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 26398, 
+            "original_file": "duk_bi_date_windows.c"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 26496, 
+            "original_file": "duk_bi_duktape.c"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 26817, 
+            "original_file": "duk_bi_error.c"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 27200, 
+            "original_file": "duk_bi_function.c"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 27546, 
+            "original_file": "duk_bi_global.c"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 28834, 
+            "original_file": "duk_bi_json.c"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 31977, 
+            "original_file": "duk_bi_logger.c"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 32277, 
+            "original_file": "duk_bi_math.c"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 32625, 
+            "original_file": "duk_bi_number.c"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 32865, 
+            "original_file": "duk_bi_object.c"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 33442, 
+            "original_file": "duk_bi_pointer.c"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 33516, 
+            "original_file": "duk_bi_proxy.c"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 33582, 
+            "original_file": "duk_bi_regexp.c"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 33791, 
+            "original_file": "duk_bi_string.c"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 35105, 
+            "original_file": "duk_bi_thread.c"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 35410, 
+            "original_file": "duk_bi_thrower.c"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 35420, 
+            "original_file": "duk_debug_fixedbuffer.c"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 35489, 
+            "original_file": "duk_debug_heap.c"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 35736, 
+            "original_file": "duk_debug_vsnprintf.c"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 36785, 
+            "original_file": "duk_debugger.c"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 39558, 
+            "original_file": "duk_error_augment.c"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 40125, 
+            "original_file": "duk_error_longjmp.c"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 40170, 
+            "original_file": "duk_error_misc.c"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 40302, 
+            "original_file": "duk_error_throw.c"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 40483, 
+            "original_file": "duk_hbuffer_alloc.c"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 40615, 
+            "original_file": "duk_hbuffer_ops.c"
+        }, 
+        {
+            "original_line": 2, 
+            "combined_line": 40698, 
+            "original_file": "duk_hbufferobject_misc.c"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 40717, 
+            "original_file": "duk_heap_alloc.c"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 41759, 
+            "original_file": "duk_heap_hashstring.c"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 41879, 
+            "original_file": "duk_heap_markandsweep.c"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 43300, 
+            "original_file": "duk_heap_memory.c"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 43684, 
+            "original_file": "duk_heap_misc.c"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 43763, 
+            "original_file": "duk_heap_refcount.c"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 44377, 
+            "original_file": "duk_heap_stringcache.c"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 44675, 
+            "original_file": "duk_heap_stringtable.c"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 45856, 
+            "original_file": "duk_hobject_alloc.c"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 46048, 
+            "original_file": "duk_hobject_enum.c"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 46674, 
+            "original_file": "duk_hobject_finalizer.c"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 46784, 
+            "original_file": "duk_hobject_misc.c"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 46836, 
+            "original_file": "duk_hobject_pc2line.c"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 47086, 
+            "original_file": "duk_hobject_props.c"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 53085, 
+            "original_file": "duk_hstring_misc.c"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 53130, 
+            "original_file": "duk_hthread_alloc.c"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 53225, 
+            "original_file": "duk_hthread_builtins.c"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 54061, 
+            "original_file": "duk_hthread_misc.c"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 54169, 
+            "original_file": "duk_hthread_stacks.c"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 54645, 
+            "original_file": "duk_js_call.c"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 57372, 
+            "original_file": "duk_js_compiler.c"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 65237, 
+            "original_file": "duk_js_executor.c"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 69744, 
+            "original_file": "duk_js_ops.c"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 71114, 
+            "original_file": "duk_js_var.c"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 72935, 
+            "original_file": "duk_lexer.c"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 75002, 
+            "original_file": "duk_numconv.c"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 77268, 
+            "original_file": "duk_regexp_compiler.c"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 78340, 
+            "original_file": "duk_regexp_executor.c"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 79348, 
+            "original_file": "duk_selftest.c"
+        }, 
+        {
+            "original_line": 2, 
+            "combined_line": 79722, 
+            "original_file": "duk_tval.c"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 79859, 
+            "original_file": "duk_unicode_tables.c"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 85978, 
+            "original_file": "duk_util_bitdecoder.c"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 86048, 
+            "original_file": "duk_util_bitencoder.c"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 86091, 
+            "original_file": "duk_util_bufwriter.c"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 86451, 
+            "original_file": "duk_util_hashbytes.c"
+        }, 
+        {
+            "original_line": 1, 
+            "combined_line": 86508, 
+            "original_file": "duk_util_tinyrandom.c"
+        }
+    ]
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_alloc_default.c
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_alloc_default.c b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_alloc_default.c
new file mode 100644
index 0000000..d882bd7
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_alloc_default.c
@@ -0,0 +1,34 @@
+/*
+ *  Default allocation functions.
+ *
+ *  Assumes behavior such as malloc allowing zero size, yielding
+ *  a NULL or a unique pointer which is a no-op for free.
+ */
+
+#include "duk_internal.h"
+
+#if defined(DUK_USE_PROVIDE_DEFAULT_ALLOC_FUNCTIONS)
+DUK_INTERNAL void *duk_default_alloc_function(void *udata, duk_size_t size) {
+	void *res;
+	DUK_UNREF(udata);
+	res = DUK_ANSI_MALLOC(size);
+	DUK_DDD(DUK_DDDPRINT("default alloc function: %lu -> %p",
+	                     (unsigned long) size, (void *) res));
+	return res;
+}
+
+DUK_INTERNAL void *duk_default_realloc_function(void *udata, void *ptr, duk_size_t newsize) {
+	void *res;
+	DUK_UNREF(udata);
+	res = DUK_ANSI_REALLOC(ptr, newsize);
+	DUK_DDD(DUK_DDDPRINT("default realloc function: %p %lu -> %p",
+	                     (void *) ptr, (unsigned long) newsize, (void *) res));
+	return res;
+}
+
+DUK_INTERNAL void duk_default_free_function(void *udata, void *ptr) {
+	DUK_DDD(DUK_DDDPRINT("default free function: %p", (void *) ptr));
+	DUK_UNREF(udata);
+	DUK_ANSI_FREE(ptr);
+}
+#endif  /* DUK_USE_PROVIDE_DEFAULT_ALLOC_FUNCTIONS */

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_api_buffer.c
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_api_buffer.c b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_api_buffer.c
new file mode 100644
index 0000000..3c12681
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_api_buffer.c
@@ -0,0 +1,73 @@
+/*
+ *  Buffer
+ */
+
+#include "duk_internal.h"
+
+DUK_EXTERNAL void *duk_resize_buffer(duk_context *ctx, duk_idx_t index, duk_size_t new_size) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_hbuffer_dynamic *h;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	h = (duk_hbuffer_dynamic *) duk_require_hbuffer(ctx, index);
+	DUK_ASSERT(h != NULL);
+
+	if (!(DUK_HBUFFER_HAS_DYNAMIC(h) && !DUK_HBUFFER_HAS_EXTERNAL(h))) {
+		DUK_ERROR_TYPE(thr, DUK_STR_WRONG_BUFFER_TYPE);
+	}
+
+	/* maximum size check is handled by callee */
+	duk_hbuffer_resize(thr, h, new_size);
+
+	return DUK_HBUFFER_DYNAMIC_GET_DATA_PTR(thr->heap, h);
+}
+
+DUK_EXTERNAL void *duk_steal_buffer(duk_context *ctx, duk_idx_t index, duk_size_t *out_size) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_hbuffer_dynamic *h;
+	void *ptr;
+	duk_size_t sz;
+
+	DUK_ASSERT(ctx != NULL);
+
+	h = (duk_hbuffer_dynamic *) duk_require_hbuffer(ctx, index);
+	DUK_ASSERT(h != NULL);
+
+	if (!(DUK_HBUFFER_HAS_DYNAMIC(h) && !DUK_HBUFFER_HAS_EXTERNAL(h))) {
+		DUK_ERROR_TYPE(thr, DUK_STR_WRONG_BUFFER_TYPE);
+	}
+
+	/* Forget the previous allocation, setting size to 0 and alloc to
+	 * NULL.  Caller is responsible for freeing the previous allocation.
+	 * Getting the allocation and clearing it is done in the same API
+	 * call to avoid any chance of a realloc.
+	 */
+	ptr = DUK_HBUFFER_DYNAMIC_GET_DATA_PTR(thr->heap, h);
+	sz = DUK_HBUFFER_DYNAMIC_GET_SIZE(h);
+	if (out_size) {
+		*out_size = sz;
+	}
+	DUK_HBUFFER_DYNAMIC_SET_DATA_PTR_NULL(thr->heap, h);
+	DUK_HBUFFER_DYNAMIC_SET_SIZE(h, 0);
+
+	return ptr;
+}
+
+DUK_EXTERNAL void duk_config_buffer(duk_context *ctx, duk_idx_t index, void *ptr, duk_size_t len) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_hbuffer_external *h;
+
+	DUK_ASSERT(ctx != NULL);
+
+	h = (duk_hbuffer_external *) duk_require_hbuffer(ctx, index);
+	DUK_ASSERT(h != NULL);
+
+	if (!DUK_HBUFFER_HAS_EXTERNAL(h)) {
+		DUK_ERROR_TYPE(thr, DUK_STR_WRONG_BUFFER_TYPE);
+	}
+	DUK_ASSERT(DUK_HBUFFER_HAS_DYNAMIC(h));
+
+	DUK_HBUFFER_EXTERNAL_SET_DATA_PTR(thr->heap, h, ptr);
+	DUK_HBUFFER_EXTERNAL_SET_SIZE(h, len);
+}

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_api_bytecode.c
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_api_bytecode.c b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_api_bytecode.c
new file mode 100644
index 0000000..bc2a295
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_api_bytecode.c
@@ -0,0 +1,727 @@
+/*
+ *  Bytecode dump/load
+ *
+ *  The bytecode load primitive is more important performance-wise than the
+ *  dump primitive.
+ *
+ *  Unlike most Duktape API calls, bytecode dump/load is not guaranteed to be
+ *  memory safe for invalid arguments - caller beware!  There's little point
+ *  in trying to achieve memory safety unless bytecode instructions are also
+ *  validated which is not easy to do with indirect register references etc.
+ */
+
+#include "duk_internal.h"
+
+#if defined(DUK_USE_BYTECODE_DUMP_SUPPORT)
+
+#define DUK__SER_MARKER  0xff
+#define DUK__SER_VERSION 0x00
+#define DUK__SER_STRING  0x00
+#define DUK__SER_NUMBER  0x01
+#define DUK__BYTECODE_INITIAL_ALLOC 256
+
+/*
+ *  Dump/load helpers, xxx_raw() helpers do no buffer checks
+ */
+
+DUK_LOCAL duk_uint8_t *duk__load_string_raw(duk_context *ctx, duk_uint8_t *p) {
+	duk_uint32_t len;
+
+	len = DUK_RAW_READ_U32_BE(p);
+	duk_push_lstring(ctx, (const char *) p, len);
+	p += len;
+	return p;
+}
+
+DUK_LOCAL duk_uint8_t *duk__load_buffer_raw(duk_context *ctx, duk_uint8_t *p) {
+	duk_uint32_t len;
+	duk_uint8_t *buf;
+
+	len = DUK_RAW_READ_U32_BE(p);
+	buf = (duk_uint8_t *) duk_push_fixed_buffer(ctx, (duk_size_t) len);
+	DUK_ASSERT(buf != NULL);
+	DUK_MEMCPY((void *) buf, (const void *) p, (size_t) len);
+	p += len;
+	return p;
+}
+
+DUK_LOCAL duk_uint8_t *duk__dump_hstring_raw(duk_uint8_t *p, duk_hstring *h) {
+	duk_size_t len;
+	duk_uint32_t tmp32;
+
+	DUK_ASSERT(h != NULL);
+
+	len = DUK_HSTRING_GET_BYTELEN(h);
+	DUK_ASSERT(len <= 0xffffffffUL);  /* string limits */
+	tmp32 = (duk_uint32_t) len;
+	DUK_RAW_WRITE_U32_BE(p, tmp32);
+	DUK_MEMCPY((void *) p,
+	           (const void *) DUK_HSTRING_GET_DATA(h),
+	           len);
+	p += len;
+	return p;
+}
+
+DUK_LOCAL duk_uint8_t *duk__dump_hbuffer_raw(duk_hthread *thr, duk_uint8_t *p, duk_hbuffer *h) {
+	duk_size_t len;
+	duk_uint32_t tmp32;
+
+	DUK_ASSERT(thr != NULL);
+	DUK_ASSERT(h != NULL);
+	DUK_UNREF(thr);
+
+	len = DUK_HBUFFER_GET_SIZE(h);
+	DUK_ASSERT(len <= 0xffffffffUL);  /* buffer limits */
+	tmp32 = (duk_uint32_t) len;
+	DUK_RAW_WRITE_U32_BE(p, tmp32);
+	DUK_MEMCPY((void *) p,
+	           (const void *) DUK_HBUFFER_GET_DATA_PTR(thr->heap, h),
+	           len);
+	p += len;
+	return p;
+}
+
+DUK_LOCAL duk_uint8_t *duk__dump_string_prop(duk_hthread *thr, duk_uint8_t *p, duk_bufwriter_ctx *bw_ctx, duk_hobject *func, duk_small_uint_t stridx) {
+	duk_hstring *h_str;
+	duk_tval *tv;
+
+	tv = duk_hobject_find_existing_entry_tval_ptr(thr->heap, (duk_hobject *) func, DUK_HTHREAD_GET_STRING(thr, stridx));
+	if (tv != NULL && DUK_TVAL_IS_STRING(tv)) {
+		h_str = DUK_TVAL_GET_STRING(tv);
+		DUK_ASSERT(h_str != NULL);
+	} else {
+		h_str = DUK_HTHREAD_STRING_EMPTY_STRING(thr);
+		DUK_ASSERT(h_str != NULL);
+	}
+	DUK_ASSERT(DUK_HSTRING_MAX_BYTELEN <= 0x7fffffffUL);  /* ensures no overflow */
+	p = DUK_BW_ENSURE_RAW(thr, bw_ctx, 4 + DUK_HSTRING_GET_BYTELEN(h_str), p);
+	p = duk__dump_hstring_raw(p, h_str);
+	return p;
+}
+
+DUK_LOCAL duk_uint8_t *duk__dump_buffer_prop(duk_hthread *thr, duk_uint8_t *p, duk_bufwriter_ctx *bw_ctx, duk_hobject *func, duk_small_uint_t stridx) {
+	duk_tval *tv;
+
+	tv = duk_hobject_find_existing_entry_tval_ptr(thr->heap, (duk_hobject *) func, DUK_HTHREAD_GET_STRING(thr, stridx));
+	if (tv != NULL && DUK_TVAL_IS_BUFFER(tv)) {
+		duk_hbuffer *h_buf;
+		h_buf = DUK_TVAL_GET_BUFFER(tv);
+		DUK_ASSERT(h_buf != NULL);
+		DUK_ASSERT(DUK_HBUFFER_MAX_BYTELEN <= 0x7fffffffUL);  /* ensures no overflow */
+		p = DUK_BW_ENSURE_RAW(thr, bw_ctx, 4 + DUK_HBUFFER_GET_SIZE(h_buf), p);
+		p = duk__dump_hbuffer_raw(thr, p, h_buf);
+	} else {
+		p = DUK_BW_ENSURE_RAW(thr, bw_ctx, 4, p);
+		DUK_RAW_WRITE_U32_BE(p, 0);
+	}
+	return p;
+}
+
+DUK_LOCAL duk_uint8_t *duk__dump_uint32_prop(duk_hthread *thr, duk_uint8_t *p, duk_bufwriter_ctx *bw_ctx, duk_hobject *func, duk_small_uint_t stridx, duk_uint32_t def_value) {
+	duk_tval *tv;
+	duk_uint32_t val;
+
+	tv = duk_hobject_find_existing_entry_tval_ptr(thr->heap, (duk_hobject *) func, DUK_HTHREAD_GET_STRING(thr, stridx));
+	if (tv != NULL && DUK_TVAL_IS_NUMBER(tv)) {
+		val = (duk_uint32_t) DUK_TVAL_GET_NUMBER(tv);
+	} else {
+		val = def_value;
+	}
+	p = DUK_BW_ENSURE_RAW(thr, bw_ctx, 4, p);
+	DUK_RAW_WRITE_U32_BE(p, val);
+	return p;
+}
+
+DUK_LOCAL duk_uint8_t *duk__dump_varmap(duk_hthread *thr, duk_uint8_t *p, duk_bufwriter_ctx *bw_ctx, duk_hobject *func) {
+	duk_tval *tv;
+
+	tv = duk_hobject_find_existing_entry_tval_ptr(thr->heap, (duk_hobject *) func, DUK_HTHREAD_STRING_INT_VARMAP(thr));
+	if (tv != NULL && DUK_TVAL_IS_OBJECT(tv)) {
+		duk_hobject *h;
+		duk_uint_fast32_t i;
+
+		h = DUK_TVAL_GET_OBJECT(tv);
+		DUK_ASSERT(h != NULL);
+
+		/* We know _Varmap only has own properties so walk property
+		 * table directly.  We also know _Varmap is dense and all
+		 * values are numbers; assert for these.  GC and finalizers
+		 * shouldn't affect _Varmap so side effects should be fine.
+		 */
+		for (i = 0; i < (duk_uint_fast32_t) DUK_HOBJECT_GET_ENEXT(h); i++) {
+			duk_hstring *key;
+			duk_tval *tv_val;
+			duk_uint32_t val;
+
+			key = DUK_HOBJECT_E_GET_KEY(thr->heap, h, i);
+			DUK_ASSERT(key != NULL);  /* _Varmap is dense */
+			DUK_ASSERT(!DUK_HOBJECT_E_SLOT_IS_ACCESSOR(thr->heap, h, i));
+			tv_val = DUK_HOBJECT_E_GET_VALUE_TVAL_PTR(thr->heap, h, i);
+			DUK_ASSERT(tv_val != NULL);
+			DUK_ASSERT(DUK_TVAL_IS_NUMBER(tv_val));  /* known to be number; in fact an integer */
+#if defined(DUK_USE_FASTINT)
+			DUK_ASSERT(DUK_TVAL_IS_FASTINT(tv_val));
+			DUK_ASSERT(DUK_TVAL_GET_FASTINT(tv_val) == (duk_int64_t) DUK_TVAL_GET_FASTINT_U32(tv_val));  /* known to be 32-bit */
+			val = DUK_TVAL_GET_FASTINT_U32(tv_val);
+#else
+			val = (duk_uint32_t) DUK_TVAL_GET_NUMBER(tv_val);
+#endif
+
+			DUK_ASSERT(DUK_HSTRING_MAX_BYTELEN <= 0x7fffffffUL);  /* ensures no overflow */
+			p = DUK_BW_ENSURE_RAW(thr, bw_ctx, 4 + DUK_HSTRING_GET_BYTELEN(key) + 4, p);
+			p = duk__dump_hstring_raw(p, key);
+			DUK_RAW_WRITE_U32_BE(p, val);
+		}
+	}
+	p = DUK_BW_ENSURE_RAW(thr, bw_ctx, 4, p);
+	DUK_RAW_WRITE_U32_BE(p, 0);  /* end of _Varmap */
+	return p;
+}
+
+DUK_LOCAL duk_uint8_t *duk__dump_formals(duk_hthread *thr, duk_uint8_t *p, duk_bufwriter_ctx *bw_ctx, duk_hobject *func) {
+	duk_tval *tv;
+
+	tv = duk_hobject_find_existing_entry_tval_ptr(thr->heap, (duk_hobject *) func, DUK_HTHREAD_STRING_INT_FORMALS(thr));
+	if (tv != NULL && DUK_TVAL_IS_OBJECT(tv)) {
+		duk_hobject *h;
+		duk_uint_fast32_t i;
+
+		h = DUK_TVAL_GET_OBJECT(tv);
+		DUK_ASSERT(h != NULL);
+
+		/* We know _Formals is dense and all entries will be in the
+		 * array part.  GC and finalizers shouldn't affect _Formals
+		 * so side effects should be fine.
+		 */
+		for (i = 0; i < (duk_uint_fast32_t) DUK_HOBJECT_GET_ASIZE(h); i++) {
+			duk_tval *tv_val;
+			duk_hstring *varname;
+
+			tv_val = DUK_HOBJECT_A_GET_VALUE_PTR(thr->heap, h, i);
+			DUK_ASSERT(tv_val != NULL);
+			if (DUK_TVAL_IS_STRING(tv_val)) {
+				/* Array is dense and contains only strings, but ASIZE may
+				 * be larger than used part and there are UNUSED entries.
+				 */
+				varname = DUK_TVAL_GET_STRING(tv_val);
+				DUK_ASSERT(varname != NULL);
+
+				DUK_ASSERT(DUK_HSTRING_MAX_BYTELEN <= 0x7fffffffUL);  /* ensures no overflow */
+				p = DUK_BW_ENSURE_RAW(thr, bw_ctx, 4 + DUK_HSTRING_GET_BYTELEN(varname), p);
+				p = duk__dump_hstring_raw(p, varname);
+			}
+		}
+	}
+	p = DUK_BW_ENSURE_RAW(thr, bw_ctx, 4, p);
+	DUK_RAW_WRITE_U32_BE(p, 0);  /* end of _Formals */
+	return p;
+}
+
+static duk_uint8_t *duk__dump_func(duk_context *ctx, duk_hcompiledfunction *func, duk_bufwriter_ctx *bw_ctx, duk_uint8_t *p) {
+	duk_hthread *thr;
+	duk_tval *tv, *tv_end;
+	duk_instr_t *ins, *ins_end;
+	duk_hobject **fn, **fn_end;
+	duk_hstring *h_str;
+	duk_uint32_t count_instr;
+	duk_uint32_t tmp32;
+	duk_uint16_t tmp16;
+	duk_double_t d;
+
+	thr = (duk_hthread *) ctx;
+	DUK_UNREF(ctx);
+	DUK_UNREF(thr);
+
+	DUK_DD(DUK_DDPRINT("dumping function %p to %p: "
+	                   "consts=[%p,%p[ (%ld bytes, %ld items), "
+	                   "funcs=[%p,%p[ (%ld bytes, %ld items), "
+	                   "code=[%p,%p[ (%ld bytes, %ld items)",
+	                   (void *) func,
+	                   (void *) p,
+	                   (void *) DUK_HCOMPILEDFUNCTION_GET_CONSTS_BASE(thr->heap, func),
+	                   (void *) DUK_HCOMPILEDFUNCTION_GET_CONSTS_END(thr->heap, func),
+	                   (long) DUK_HCOMPILEDFUNCTION_GET_CONSTS_SIZE(thr->heap, func),
+	                   (long) DUK_HCOMPILEDFUNCTION_GET_CONSTS_COUNT(thr->heap, func),
+	                   (void *) DUK_HCOMPILEDFUNCTION_GET_FUNCS_BASE(thr->heap, func),
+	                   (void *) DUK_HCOMPILEDFUNCTION_GET_FUNCS_END(thr->heap, func),
+	                   (long) DUK_HCOMPILEDFUNCTION_GET_FUNCS_SIZE(thr->heap, func),
+	                   (long) DUK_HCOMPILEDFUNCTION_GET_FUNCS_COUNT(thr->heap, func),
+	                   (void *) DUK_HCOMPILEDFUNCTION_GET_CODE_BASE(thr->heap, func),
+	                   (void *) DUK_HCOMPILEDFUNCTION_GET_CODE_END(thr->heap, func),
+	                   (long) DUK_HCOMPILEDFUNCTION_GET_CODE_SIZE(thr->heap, func),
+	                   (long) DUK_HCOMPILEDFUNCTION_GET_CODE_COUNT(thr->heap, func)));
+
+	DUK_ASSERT(DUK_USE_ESBC_MAX_BYTES <= 0x7fffffffUL);  /* ensures no overflow */
+	count_instr = (duk_uint32_t) DUK_HCOMPILEDFUNCTION_GET_CODE_COUNT(thr->heap, func);
+	p = DUK_BW_ENSURE_RAW(thr, bw_ctx, 3 * 4 + 2 * 2 + 3 * 4 + count_instr * 4, p);
+
+	/* Fixed header info. */
+	tmp32 = count_instr;
+	DUK_RAW_WRITE_U32_BE(p, tmp32);
+	tmp32 = (duk_uint32_t) DUK_HCOMPILEDFUNCTION_GET_CONSTS_COUNT(thr->heap, func);
+	DUK_RAW_WRITE_U32_BE(p, tmp32);
+	tmp32 = (duk_uint32_t) DUK_HCOMPILEDFUNCTION_GET_FUNCS_COUNT(thr->heap, func);
+	DUK_RAW_WRITE_U32_BE(p, tmp32);
+	tmp16 = func->nregs;
+	DUK_RAW_WRITE_U16_BE(p, tmp16);
+	tmp16 = func->nargs;
+	DUK_RAW_WRITE_U16_BE(p, tmp16);
+#if defined(DUK_USE_DEBUGGER_SUPPORT)
+	tmp32 = func->start_line;
+	DUK_RAW_WRITE_U32_BE(p, tmp32);
+	tmp32 = func->end_line;
+	DUK_RAW_WRITE_U32_BE(p, tmp32);
+#else
+	DUK_RAW_WRITE_U32_BE(p, 0);
+	DUK_RAW_WRITE_U32_BE(p, 0);
+#endif
+	tmp32 = ((duk_heaphdr *) func)->h_flags & DUK_HEAPHDR_FLAGS_FLAG_MASK;
+	DUK_RAW_WRITE_U32_BE(p, tmp32);
+
+	/* Bytecode instructions: endian conversion needed unless
+	 * platform is big endian.
+	 */
+	ins = DUK_HCOMPILEDFUNCTION_GET_CODE_BASE(thr->heap, func);
+	ins_end = DUK_HCOMPILEDFUNCTION_GET_CODE_END(thr->heap, func);
+	DUK_ASSERT((duk_size_t) (ins_end - ins) == (duk_size_t) count_instr);
+#if defined(DUK_USE_INTEGER_BE)
+	DUK_MEMCPY((void *) p, (const void *) ins, (size_t) (ins_end - ins));
+	p += (size_t) (ins_end - ins);
+#else
+	while (ins != ins_end) {
+		tmp32 = (duk_uint32_t) (*ins);
+		DUK_RAW_WRITE_U32_BE(p, tmp32);
+		ins++;
+	}
+#endif
+
+	/* Constants: variable size encoding. */
+	tv = DUK_HCOMPILEDFUNCTION_GET_CONSTS_BASE(thr->heap, func);
+	tv_end = DUK_HCOMPILEDFUNCTION_GET_CONSTS_END(thr->heap, func);
+	while (tv != tv_end) {
+		/* constants are strings or numbers now */
+		DUK_ASSERT(DUK_TVAL_IS_STRING(tv) ||
+		           DUK_TVAL_IS_NUMBER(tv));
+
+		if (DUK_TVAL_IS_STRING(tv)) {
+			h_str = DUK_TVAL_GET_STRING(tv);
+			DUK_ASSERT(h_str != NULL);
+			DUK_ASSERT(DUK_HSTRING_MAX_BYTELEN <= 0x7fffffffUL);  /* ensures no overflow */
+			p = DUK_BW_ENSURE_RAW(thr, bw_ctx, 1 + 4 + DUK_HSTRING_GET_BYTELEN(h_str), p),
+			*p++ = DUK__SER_STRING;
+			p = duk__dump_hstring_raw(p, h_str);
+		} else {
+			DUK_ASSERT(DUK_TVAL_IS_NUMBER(tv));
+			p = DUK_BW_ENSURE_RAW(thr, bw_ctx, 1 + 8, p);
+			*p++ = DUK__SER_NUMBER;
+			d = DUK_TVAL_GET_NUMBER(tv);
+			DUK_RAW_WRITE_DOUBLE_BE(p, d);
+		}
+		tv++;
+	}
+
+	/* Inner functions recursively. */
+	fn = (duk_hobject **) DUK_HCOMPILEDFUNCTION_GET_FUNCS_BASE(thr->heap, func);
+	fn_end = (duk_hobject **) DUK_HCOMPILEDFUNCTION_GET_FUNCS_END(thr->heap, func);
+	while (fn != fn_end) {
+		/* XXX: This causes recursion up to inner function depth
+		 * which is normally not an issue, e.g. mark-and-sweep uses
+		 * a recursion limiter to avoid C stack issues.  Avoiding
+		 * this would mean some sort of a work list or just refusing
+		 * to serialize deep functions.
+		 */
+		DUK_ASSERT(DUK_HOBJECT_IS_COMPILEDFUNCTION(*fn));
+		p = duk__dump_func(ctx, (duk_hcompiledfunction *) *fn, bw_ctx, p);
+		fn++;
+	}
+
+	/* Object extra properties.
+	 *
+	 * There are some difference between function templates and functions.
+	 * For example, function templates don't have .length and nargs is
+	 * normally used to instantiate the functions.
+	 */
+
+	p = duk__dump_uint32_prop(thr, p, bw_ctx, (duk_hobject *) func, DUK_STRIDX_LENGTH, (duk_uint32_t) func->nargs);
+	p = duk__dump_string_prop(thr, p, bw_ctx, (duk_hobject *) func, DUK_STRIDX_NAME);
+	p = duk__dump_string_prop(thr, p, bw_ctx, (duk_hobject *) func, DUK_STRIDX_FILE_NAME);
+	p = duk__dump_buffer_prop(thr, p, bw_ctx, (duk_hobject *) func, DUK_STRIDX_INT_PC2LINE);
+	p = duk__dump_varmap(thr, p, bw_ctx, (duk_hobject *) func);
+	p = duk__dump_formals(thr, p, bw_ctx, (duk_hobject *) func);
+
+	DUK_DD(DUK_DDPRINT("serialized function %p -> final pointer %p", (void *) func, (void *) p));
+
+	return p;
+}
+
+/* Load a function from bytecode.  The function object returned here must
+ * match what is created by duk_js_push_closure() with respect to its flags,
+ * properties, etc.
+ *
+ * NOTE: there are intentionally no input buffer length / bound checks.
+ * Adding them would be easy but wouldn't ensure memory safety as untrusted
+ * or broken bytecode is unsafe during execution unless the opcodes themselves
+ * are validated (which is quite complex, especially for indirect opcodes).
+ */
+
+#define DUK__ASSERT_LEFT(n) do { \
+		DUK_ASSERT((duk_size_t) (p_end - p) >= (duk_size_t) (n)); \
+	} while (0)
+
+static duk_uint8_t *duk__load_func(duk_context *ctx, duk_uint8_t *p, duk_uint8_t *p_end) {
+	duk_hthread *thr;
+	duk_hcompiledfunction *h_fun;
+	duk_hbuffer *h_data;
+	duk_size_t data_size;
+	duk_uint32_t count_instr, count_const, count_funcs;
+	duk_uint32_t n;
+	duk_uint32_t tmp32;
+	duk_small_uint_t const_type;
+	duk_uint8_t *fun_data;
+	duk_uint8_t *q;
+	duk_idx_t idx_base;
+	duk_tval *tv1;
+	duk_uarridx_t arr_idx;
+
+	/* XXX: There's some overlap with duk_js_closure() here, but
+	 * seems difficult to share code.  Ensure that the final function
+	 * looks the same as created by duk_js_closure().
+	 */
+
+	DUK_ASSERT(ctx != NULL);
+	thr = (duk_hthread *) ctx;
+
+	DUK_DD(DUK_DDPRINT("loading function, p=%p, p_end=%p", (void *) p, (void *) p_end));
+
+	DUK__ASSERT_LEFT(3 * 4);
+	count_instr = DUK_RAW_READ_U32_BE(p);
+	count_const = DUK_RAW_READ_U32_BE(p);
+	count_funcs = DUK_RAW_READ_U32_BE(p);
+
+	data_size = sizeof(duk_tval) * count_const +
+	            sizeof(duk_hobject *) * count_funcs +
+	            sizeof(duk_instr_t) * count_instr;
+
+	DUK_DD(DUK_DDPRINT("instr=%ld, const=%ld, funcs=%ld, data_size=%ld",
+	                   (long) count_instr, (long) count_const,
+	                   (long) count_const, (long) data_size));
+
+	/* Value stack is used to ensure reachability of constants and
+	 * inner functions being loaded.  Require enough space to handle
+	 * large functions correctly.
+	 */
+	duk_require_stack(ctx, 2 + count_const + count_funcs);
+	idx_base = duk_get_top(ctx);
+
+	/* Push function object, init flags etc.  This must match
+	 * duk_js_push_closure() quite carefully.
+	 */
+	duk_push_compiledfunction(ctx);
+	h_fun = duk_get_hcompiledfunction(ctx, -1);
+	DUK_ASSERT(h_fun != NULL);
+	DUK_ASSERT(DUK_HOBJECT_IS_COMPILEDFUNCTION((duk_hobject *) h_fun));
+	DUK_ASSERT(DUK_HCOMPILEDFUNCTION_GET_DATA(thr->heap, h_fun) == NULL);
+	DUK_ASSERT(DUK_HCOMPILEDFUNCTION_GET_FUNCS(thr->heap, h_fun) == NULL);
+	DUK_ASSERT(DUK_HCOMPILEDFUNCTION_GET_BYTECODE(thr->heap, h_fun) == NULL);
+
+	h_fun->nregs = DUK_RAW_READ_U16_BE(p);
+	h_fun->nargs = DUK_RAW_READ_U16_BE(p);
+#if defined(DUK_USE_DEBUGGER_SUPPORT)
+	h_fun->start_line = DUK_RAW_READ_U32_BE(p);
+	h_fun->end_line = DUK_RAW_READ_U32_BE(p);
+#else
+	p += 8;  /* skip line info */
+#endif
+
+	/* duk_hcompiledfunction flags; quite version specific */
+	tmp32 = DUK_RAW_READ_U32_BE(p);
+	DUK_HEAPHDR_SET_FLAGS((duk_heaphdr *) h_fun, tmp32);
+
+	/* standard prototype */
+	DUK_HOBJECT_SET_PROTOTYPE_UPDREF(thr, &h_fun->obj, thr->builtins[DUK_BIDX_FUNCTION_PROTOTYPE]);
+
+	/* assert just a few critical flags */
+	DUK_ASSERT(DUK_HEAPHDR_GET_TYPE((duk_heaphdr *) h_fun) == DUK_HTYPE_OBJECT);
+	DUK_ASSERT(!DUK_HOBJECT_HAS_BOUND(&h_fun->obj));
+	DUK_ASSERT(DUK_HOBJECT_HAS_COMPILEDFUNCTION(&h_fun->obj));
+	DUK_ASSERT(!DUK_HOBJECT_HAS_NATIVEFUNCTION(&h_fun->obj));
+	DUK_ASSERT(!DUK_HOBJECT_HAS_THREAD(&h_fun->obj));
+	DUK_ASSERT(!DUK_HOBJECT_HAS_EXOTIC_ARRAY(&h_fun->obj));
+	DUK_ASSERT(!DUK_HOBJECT_HAS_EXOTIC_STRINGOBJ(&h_fun->obj));
+	DUK_ASSERT(!DUK_HOBJECT_HAS_EXOTIC_ARGUMENTS(&h_fun->obj));
+
+	/* Create function 'data' buffer but don't attach it yet. */
+	fun_data = (duk_uint8_t *) duk_push_fixed_buffer(ctx, data_size);
+	DUK_ASSERT(fun_data != NULL);
+
+	/* Load bytecode instructions. */
+	DUK_ASSERT(sizeof(duk_instr_t) == 4);
+	DUK__ASSERT_LEFT(count_instr * sizeof(duk_instr_t));
+#if defined(DUK_USE_INTEGER_BE)
+	q = fun_data + sizeof(duk_tval) * count_const + sizeof(duk_hobject *) * count_funcs;
+	DUK_MEMCPY((void *) q,
+	           (const void *) p,
+	           sizeof(duk_instr_t) * count_instr);
+	p += sizeof(duk_instr_t) * count_instr;
+#else
+	q = fun_data + sizeof(duk_tval) * count_const + sizeof(duk_hobject *) * count_funcs;
+	for (n = count_instr; n > 0; n--) {
+		*((duk_instr_t *) (void *) q) = DUK_RAW_READ_U32_BE(p);
+		q += sizeof(duk_instr_t);
+	}
+#endif
+
+	/* Load constants onto value stack but don't yet copy to buffer. */
+	for (n = count_const; n > 0; n--) {
+		DUK__ASSERT_LEFT(1);
+		const_type = DUK_RAW_READ_U8(p);
+		switch (const_type) {
+		case DUK__SER_STRING: {
+			p = duk__load_string_raw(ctx, p);
+			break;
+		}
+		case DUK__SER_NUMBER: {
+			/* Important to do a fastint check so that constants are
+			 * properly read back as fastints.
+			 */
+			duk_tval tv_tmp;
+			duk_double_t val;
+			DUK__ASSERT_LEFT(8);
+			val = DUK_RAW_READ_DOUBLE_BE(p);
+			DUK_TVAL_SET_NUMBER_CHKFAST(&tv_tmp, val);
+			duk_push_tval(ctx, &tv_tmp);
+			break;
+		}
+		default: {
+			goto format_error;
+		}
+		}
+	}
+
+	/* Load inner functions to value stack, but don't yet copy to buffer. */
+	for (n = count_funcs; n > 0; n--) {
+		p = duk__load_func(ctx, p, p_end);
+		if (p == NULL) {
+			goto format_error;
+		}
+	}
+
+	/* With constants and inner functions on value stack, we can now
+	 * atomically finish the function 'data' buffer, bump refcounts,
+	 * etc.
+	 *
+	 * Here we take advantage of the value stack being just a duk_tval
+	 * array: we can just memcpy() the constants as long as we incref
+	 * them afterwards.
+	 */
+
+	h_data = (duk_hbuffer *) duk_get_hbuffer(ctx, idx_base + 1);
+	DUK_ASSERT(h_data != NULL);
+	DUK_ASSERT(!DUK_HBUFFER_HAS_DYNAMIC(h_data));
+	DUK_HCOMPILEDFUNCTION_SET_DATA(thr->heap, h_fun, h_data);
+	DUK_HBUFFER_INCREF(thr, h_data);
+
+	tv1 = duk_get_tval(ctx, idx_base + 2);  /* may be NULL if no constants or inner funcs */
+	DUK_ASSERT((count_const == 0 && count_funcs == 0) || tv1 != NULL);
+
+	q = fun_data;
+	if (count_const > 0) {
+		/* Explicit zero size check to avoid NULL 'tv1'. */
+		DUK_MEMCPY((void *) q, (const void *) tv1, sizeof(duk_tval) * count_const);
+		for (n = count_const; n > 0; n--) {
+			DUK_TVAL_INCREF_FAST(thr, (duk_tval *) (void *) q);  /* no side effects */
+			q += sizeof(duk_tval);
+		}
+		tv1 += count_const;
+	}
+
+	DUK_HCOMPILEDFUNCTION_SET_FUNCS(thr->heap, h_fun, (duk_hobject **) (void *) q);
+	for (n = count_funcs; n > 0; n--) {
+		duk_hobject *h_obj;
+
+		DUK_ASSERT(DUK_TVAL_IS_OBJECT(tv1));
+		h_obj = DUK_TVAL_GET_OBJECT(tv1);
+		DUK_ASSERT(h_obj != NULL);
+		tv1++;
+		DUK_HOBJECT_INCREF(thr, h_obj);
+
+		*((duk_hobject **) (void *) q) = h_obj;
+		q += sizeof(duk_hobject *);
+	}
+
+	DUK_HCOMPILEDFUNCTION_SET_BYTECODE(thr->heap, h_fun, (duk_instr_t *) (void *) q);
+
+	/* The function object is now reachable and refcounts are fine,
+	 * so we can pop off all the temporaries.
+	 */
+	DUK_DDD(DUK_DDDPRINT("function is reachable, reset top; func: %!iT", duk_get_tval(ctx, idx_base)));
+	duk_set_top(ctx, idx_base + 1);
+
+	/* Setup function properties. */
+	tmp32 = DUK_RAW_READ_U32_BE(p);
+	duk_push_u32(ctx, tmp32);
+	duk_xdef_prop_stridx(ctx, -2, DUK_STRIDX_LENGTH, DUK_PROPDESC_FLAGS_NONE);
+
+	p = duk__load_string_raw(ctx, p);
+	if (DUK_HOBJECT_HAS_NAMEBINDING((duk_hobject *) h_fun)) {
+		/* Original function instance/template had NAMEBINDING.
+		 * Must create a lexical environment on loading to allow
+		 * recursive functions like 'function foo() { foo(); }'.
+		 */
+		duk_hobject *proto;
+
+		proto = thr->builtins[DUK_BIDX_GLOBAL_ENV];
+		(void) duk_push_object_helper_proto(ctx,
+		                                    DUK_HOBJECT_FLAG_EXTENSIBLE |
+		                                    DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_DECENV),
+		                                    proto);
+		duk_dup(ctx, -2);                                 /* -> [ func funcname env funcname ] */
+		duk_dup(ctx, idx_base);                           /* -> [ func funcname env funcname func ] */
+		duk_xdef_prop(ctx, -3, DUK_PROPDESC_FLAGS_NONE);  /* -> [ func funcname env ] */
+		duk_xdef_prop_stridx(ctx, idx_base, DUK_STRIDX_INT_LEXENV, DUK_PROPDESC_FLAGS_WC);
+		/* since closure has NEWENV, never define DUK_STRIDX_INT_VARENV, as it
+		 * will be ignored anyway
+		 */
+	}
+	duk_xdef_prop_stridx(ctx, -2, DUK_STRIDX_NAME, DUK_PROPDESC_FLAGS_NONE);
+
+	p = duk__load_string_raw(ctx, p);
+	duk_xdef_prop_stridx(ctx, -2, DUK_STRIDX_FILE_NAME, DUK_PROPDESC_FLAGS_WC);
+
+	duk_push_object(ctx);
+	duk_dup(ctx, -2);
+	duk_xdef_prop_stridx(ctx, -2, DUK_STRIDX_CONSTRUCTOR, DUK_PROPDESC_FLAGS_WC);  /* func.prototype.constructor = func */
+	duk_compact(ctx, -1);
+	duk_xdef_prop_stridx(ctx, -2, DUK_STRIDX_PROTOTYPE, DUK_PROPDESC_FLAGS_W);
+
+	p = duk__load_buffer_raw(ctx, p);
+	duk_xdef_prop_stridx(ctx, -2, DUK_STRIDX_INT_PC2LINE, DUK_PROPDESC_FLAGS_WC);
+
+	duk_push_object(ctx);  /* _Varmap */
+	for (;;) {
+		/* XXX: awkward */
+		p = duk__load_string_raw(ctx, p);
+		if (duk_get_length(ctx, -1) == 0) {
+			duk_pop(ctx);
+			break;
+		}
+		tmp32 = DUK_RAW_READ_U32_BE(p);
+		duk_push_u32(ctx, tmp32);
+		duk_put_prop(ctx, -3);
+	}
+	duk_compact(ctx, -1);
+	duk_xdef_prop_stridx(ctx, -2, DUK_STRIDX_INT_VARMAP, DUK_PROPDESC_FLAGS_NONE);
+
+	duk_push_array(ctx);  /* _Formals */
+	for (arr_idx = 0; ; arr_idx++) {
+		/* XXX: awkward */
+		p = duk__load_string_raw(ctx, p);
+		if (duk_get_length(ctx, -1) == 0) {
+			duk_pop(ctx);
+			break;
+		}
+		duk_put_prop_index(ctx, -2, arr_idx);
+	}
+	duk_compact(ctx, -1);
+	duk_xdef_prop_stridx(ctx, -2, DUK_STRIDX_INT_FORMALS, DUK_PROPDESC_FLAGS_NONE);
+
+	/* Return with final function pushed on stack top. */
+	DUK_DD(DUK_DDPRINT("final loaded function: %!iT", duk_get_tval(ctx, -1)));
+	DUK_ASSERT_TOP(ctx, idx_base + 1);
+	return p;
+
+ format_error:
+	return NULL;
+}
+
+DUK_EXTERNAL void duk_dump_function(duk_context *ctx) {
+	duk_hthread *thr;
+	duk_hcompiledfunction *func;
+	duk_bufwriter_ctx bw_ctx_alloc;
+	duk_bufwriter_ctx *bw_ctx = &bw_ctx_alloc;
+	duk_uint8_t *p;
+
+	DUK_ASSERT(ctx != NULL);
+	thr = (duk_hthread *) ctx;
+
+	/* Bound functions don't have all properties so we'd either need to
+	 * lookup the non-bound target function or reject bound functions.
+	 * For now, bound functions are rejected.
+	 */
+	func = duk_require_hcompiledfunction(ctx, -1);
+	DUK_ASSERT(func != NULL);
+	DUK_ASSERT(!DUK_HOBJECT_HAS_BOUND(&func->obj));
+
+	/* Estimating the result size beforehand would be costly, so
+	 * start with a reasonable size and extend as needed.
+	 */
+	DUK_BW_INIT_PUSHBUF(thr, bw_ctx, DUK__BYTECODE_INITIAL_ALLOC);
+	p = DUK_BW_GET_PTR(thr, bw_ctx);
+	*p++ = DUK__SER_MARKER;
+	*p++ = DUK__SER_VERSION;
+	p = duk__dump_func(ctx, func, bw_ctx, p);
+	DUK_BW_SET_PTR(thr, bw_ctx, p);
+	DUK_BW_COMPACT(thr, bw_ctx);
+
+	DUK_DD(DUK_DDPRINT("serialized result: %!T", duk_get_tval(ctx, -1)));
+
+	duk_remove(ctx, -2);  /* [ ... func buf ] -> [ ... buf ] */
+}
+
+DUK_EXTERNAL void duk_load_function(duk_context *ctx) {
+	duk_hthread *thr;
+	duk_uint8_t *p_buf, *p, *p_end;
+	duk_size_t sz;
+
+	DUK_ASSERT(ctx != NULL);
+	thr = (duk_hthread *) ctx;
+	DUK_UNREF(ctx);
+
+	p_buf = (duk_uint8_t *) duk_require_buffer(ctx, -1, &sz);
+	DUK_ASSERT(p_buf != NULL);
+
+	/* The caller is responsible for being sure that bytecode being loaded
+	 * is valid and trusted.  Invalid bytecode can cause memory unsafe
+	 * behavior directly during loading or later during bytecode execution
+	 * (instruction validation would be quite complex to implement).
+	 *
+	 * This signature check is the only sanity check for detecting
+	 * accidental invalid inputs.  The initial 0xFF byte ensures no
+	 * ordinary string will be accepted by accident.
+	 */
+	p = p_buf;
+	p_end = p_buf + sz;
+	if (sz < 2 || p[0] != DUK__SER_MARKER || p[1] != DUK__SER_VERSION) {
+		goto format_error;
+	}
+	p += 2;
+
+	p = duk__load_func(ctx, p, p_end);
+	if (p == NULL) {
+		goto format_error;
+	}
+
+	duk_remove(ctx, -2);  /* [ ... buf func ] -> [ ... func ] */
+	return;
+
+ format_error:
+	DUK_ERROR_TYPE(thr, DUK_STR_DECODE_FAILED);
+}
+
+#undef DUK__SER_MARKER
+#undef DUK__SER_VERSION
+#undef DUK__SER_STRING
+#undef DUK__SER_NUMBER
+#undef DUK__BYTECODE_INITIAL_ALLOC
+
+#else  /* DUK_USE_BYTECODE_DUMP_SUPPORT */
+
+DUK_EXTERNAL void duk_dump_function(duk_context *ctx) {
+	DUK_ERROR_UNSUPPORTED_DEFMSG((duk_hthread *) ctx);
+}
+
+DUK_EXTERNAL void duk_load_function(duk_context *ctx) {
+	DUK_ERROR_UNSUPPORTED_DEFMSG((duk_hthread *) ctx);
+}
+
+#endif  /* DUK_USE_BYTECODE_DUMP_SUPPORT */

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_api_call.c
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_api_call.c b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_api_call.c
new file mode 100644
index 0000000..25dac14
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_api_call.c
@@ -0,0 +1,555 @@
+/*
+ *  Calls.
+ *
+ *  Protected variants should avoid ever throwing an error.
+ */
+
+#include "duk_internal.h"
+
+/* Prepare value stack for a method call through an object property.
+ * May currently throw an error e.g. when getting the property.
+ */
+DUK_LOCAL void duk__call_prop_prep_stack(duk_context *ctx, duk_idx_t normalized_obj_index, duk_idx_t nargs) {
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	DUK_DDD(DUK_DDDPRINT("duk__call_prop_prep_stack, normalized_obj_index=%ld, nargs=%ld, stacktop=%ld",
+	                     (long) normalized_obj_index, (long) nargs, (long) duk_get_top(ctx)));
+
+	/* [... key arg1 ... argN] */
+
+	/* duplicate key */
+	duk_dup(ctx, -nargs - 1);  /* Note: -nargs alone would fail for nargs == 0, this is OK */
+	duk_get_prop(ctx, normalized_obj_index);
+
+	DUK_DDD(DUK_DDDPRINT("func: %!T", (duk_tval *) duk_get_tval(ctx, -1)));
+
+	/* [... key arg1 ... argN func] */
+
+	duk_replace(ctx, -nargs - 2);
+
+	/* [... func arg1 ... argN] */
+
+	duk_dup(ctx, normalized_obj_index);
+	duk_insert(ctx, -nargs - 1);
+
+	/* [... func this arg1 ... argN] */
+}
+
+DUK_EXTERNAL void duk_call(duk_context *ctx, duk_idx_t nargs) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_small_uint_t call_flags;
+	duk_idx_t idx_func;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+	DUK_ASSERT(thr != NULL);
+
+	idx_func = duk_get_top(ctx) - nargs - 1;
+	if (idx_func < 0 || nargs < 0) {
+		/* note that we can't reliably pop anything here */
+		DUK_ERROR_API(thr, DUK_STR_INVALID_CALL_ARGS);
+	}
+
+	/* XXX: awkward; we assume there is space for this, overwrite
+	 * directly instead?
+	 */
+	duk_push_undefined(ctx);
+	duk_insert(ctx, idx_func + 1);
+
+	call_flags = 0;  /* not protected, respect reclimit, not constructor */
+
+	duk_handle_call_unprotected(thr,           /* thread */
+	                            nargs,         /* num_stack_args */
+	                            call_flags);   /* call_flags */
+}
+
+DUK_EXTERNAL void duk_call_method(duk_context *ctx, duk_idx_t nargs) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_small_uint_t call_flags;
+	duk_idx_t idx_func;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+	DUK_ASSERT(thr != NULL);
+
+	idx_func = duk_get_top(ctx) - nargs - 2;  /* must work for nargs <= 0 */
+	if (idx_func < 0 || nargs < 0) {
+		/* note that we can't reliably pop anything here */
+		DUK_ERROR_API(thr, DUK_STR_INVALID_CALL_ARGS);
+	}
+
+	call_flags = 0;  /* not protected, respect reclimit, not constructor */
+
+	duk_handle_call_unprotected(thr,           /* thread */
+	                            nargs,         /* num_stack_args */
+	                            call_flags);   /* call_flags */
+}
+
+DUK_EXTERNAL void duk_call_prop(duk_context *ctx, duk_idx_t obj_index, duk_idx_t nargs) {
+	/*
+	 *  XXX: if duk_handle_call() took values through indices, this could be
+	 *  made much more sensible.  However, duk_handle_call() needs to fudge
+	 *  the 'this' and 'func' values to handle bound function chains, which
+	 *  is now done "in-place", so this is not a trivial change.
+	 */
+
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	obj_index = duk_require_normalize_index(ctx, obj_index);  /* make absolute */
+
+	duk__call_prop_prep_stack(ctx, obj_index, nargs);
+
+	duk_call_method(ctx, nargs);
+}
+
+DUK_EXTERNAL duk_int_t duk_pcall(duk_context *ctx, duk_idx_t nargs) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_small_uint_t call_flags;
+	duk_idx_t idx_func;
+	duk_int_t rc;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+	DUK_ASSERT(thr != NULL);
+
+	idx_func = duk_get_top(ctx) - nargs - 1;  /* must work for nargs <= 0 */
+	if (idx_func < 0 || nargs < 0) {
+		/* We can't reliably pop anything here because the stack input
+		 * shape is incorrect.  So we throw an error; if the caller has
+		 * no catch point for this, a fatal error will occur.  Another
+		 * alternative would be to just return an error.  But then the
+		 * stack would be in an unknown state which might cause some
+		 * very hard to diagnose problems later on.  Also note that even
+		 * if we did not throw an error here, the underlying call handler
+		 * might STILL throw an out-of-memory error or some other internal
+		 * fatal error.
+		 */
+		DUK_ERROR_API(thr, DUK_STR_INVALID_CALL_ARGS);
+		return DUK_EXEC_ERROR;  /* unreachable */
+	}
+
+	/* awkward; we assume there is space for this */
+	duk_push_undefined(ctx);
+	duk_insert(ctx, idx_func + 1);
+
+	call_flags = 0;  /* respect reclimit, not constructor */
+
+	rc = duk_handle_call_protected(thr,           /* thread */
+	                               nargs,         /* num_stack_args */
+	                               call_flags);   /* call_flags */
+
+	return rc;
+}
+
+DUK_EXTERNAL duk_int_t duk_pcall_method(duk_context *ctx, duk_idx_t nargs) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_small_uint_t call_flags;
+	duk_idx_t idx_func;
+	duk_int_t rc;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+	DUK_ASSERT(thr != NULL);
+
+	idx_func = duk_get_top(ctx) - nargs - 2;  /* must work for nargs <= 0 */
+	if (idx_func < 0 || nargs < 0) {
+		/* See comments in duk_pcall(). */
+		DUK_ERROR_API(thr, DUK_STR_INVALID_CALL_ARGS);
+		return DUK_EXEC_ERROR;  /* unreachable */
+	}
+
+	call_flags = 0;  /* respect reclimit, not constructor */
+
+	rc = duk_handle_call_protected(thr,           /* thread */
+	                               nargs,         /* num_stack_args */
+	                               call_flags);   /* call_flags */
+
+	return rc;
+}
+
+DUK_LOCAL duk_ret_t duk__pcall_prop_raw(duk_context *ctx) {
+	duk_idx_t obj_index;
+	duk_idx_t nargs;
+
+	/* Get the original arguments.  Note that obj_index may be a relative
+	 * index so the stack must have the same top when we use it.
+	 */
+
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	obj_index = (duk_idx_t) duk_get_int(ctx, -2);
+	nargs = (duk_idx_t) duk_get_int(ctx, -1);
+	duk_pop_2(ctx);
+
+	obj_index = duk_require_normalize_index(ctx, obj_index);  /* make absolute */
+	duk__call_prop_prep_stack(ctx, obj_index, nargs);
+	duk_call_method(ctx, nargs);
+	return 1;
+}
+
+DUK_EXTERNAL duk_int_t duk_pcall_prop(duk_context *ctx, duk_idx_t obj_index, duk_idx_t nargs) {
+	/*
+	 *  Must be careful to catch errors related to value stack manipulation
+	 *  and property lookup, not just the call itself.
+	 */
+
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	duk_push_idx(ctx, obj_index);
+	duk_push_idx(ctx, nargs);
+
+	/* Inputs: explicit arguments (nargs), +1 for key, +2 for obj_index/nargs passing.
+	 * If the value stack does not contain enough args, an error is thrown; this matches
+	 * behavior of the other protected call API functions.
+	 */
+	return duk_safe_call(ctx, duk__pcall_prop_raw, nargs + 1 + 2 /*nargs*/, 1 /*nrets*/);
+}
+
+DUK_EXTERNAL duk_int_t duk_safe_call(duk_context *ctx, duk_safe_call_function func, duk_idx_t nargs, duk_idx_t nrets) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_int_t rc;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+	DUK_ASSERT(thr != NULL);
+
+	if (duk_get_top(ctx) < nargs || nrets < 0) {
+		/* See comments in duk_pcall(). */
+		DUK_ERROR_API(thr, DUK_STR_INVALID_CALL_ARGS);
+		return DUK_EXEC_ERROR;  /* unreachable */
+	}
+
+	rc = duk_handle_safe_call(thr,           /* thread */
+	                          func,          /* func */
+	                          nargs,         /* num_stack_args */
+	                          nrets);        /* num_stack_res */
+
+	return rc;
+}
+
+DUK_EXTERNAL void duk_new(duk_context *ctx, duk_idx_t nargs) {
+	/*
+	 *  There are two [[Construct]] operations in the specification:
+	 *
+	 *    - E5 Section 13.2.2: for Function objects
+	 *    - E5 Section 15.3.4.5.2: for "bound" Function objects
+	 *
+	 *  The chain of bound functions is resolved in Section 15.3.4.5.2,
+	 *  with arguments "piling up" until the [[Construct]] internal
+	 *  method is called on the final, actual Function object.  Note
+	 *  that the "prototype" property is looked up *only* from the
+	 *  final object, *before* calling the constructor.
+	 *
+	 *  Currently we follow the bound function chain here to get the
+	 *  "prototype" property value from the final, non-bound function.
+	 *  However, we let duk_handle_call() handle the argument "piling"
+	 *  when the constructor is called.  The bound function chain is
+	 *  thus now processed twice.
+	 *
+	 *  When constructing new Array instances, an unnecessary object is
+	 *  created and discarded now: the standard [[Construct]] creates an
+	 *  object, and calls the Array constructor.  The Array constructor
+	 *  returns an Array instance, which is used as the result value for
+	 *  the "new" operation; the object created before the Array constructor
+	 *  call is discarded.
+	 *
+	 *  This would be easy to fix, e.g. by knowing that the Array constructor
+	 *  will always create a replacement object and skip creating the fallback
+	 *  object in that case.
+	 *
+	 *  Note: functions called via "new" need to know they are called as a
+	 *  constructor.  For instance, built-in constructors behave differently
+	 *  depending on how they are called.
+	 */
+
+	/* XXX: merge this with duk_js_call.c, as this function implements
+	 * core semantics (or perhaps merge the two files altogether).
+	 */
+
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_hobject *proto;
+	duk_hobject *cons;
+	duk_hobject *fallback;
+	duk_idx_t idx_cons;
+	duk_small_uint_t call_flags;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	/* [... constructor arg1 ... argN] */
+
+	idx_cons = duk_require_normalize_index(ctx, -nargs - 1);
+
+	DUK_DDD(DUK_DDDPRINT("top=%ld, nargs=%ld, idx_cons=%ld",
+	                     (long) duk_get_top(ctx), (long) nargs, (long) idx_cons));
+
+	/* XXX: code duplication */
+
+	/*
+	 *  Figure out the final, non-bound constructor, to get "prototype"
+	 *  property.
+	 */
+
+	duk_dup(ctx, idx_cons);
+	for (;;) {
+		duk_tval *tv;
+		tv = DUK_GET_TVAL_NEGIDX(ctx, -1);
+		DUK_ASSERT(tv != NULL);
+
+		if (DUK_TVAL_IS_OBJECT(tv)) {
+			cons = DUK_TVAL_GET_OBJECT(tv);
+			DUK_ASSERT(cons != NULL);
+			if (!DUK_HOBJECT_IS_CALLABLE(cons) || !DUK_HOBJECT_HAS_CONSTRUCTABLE(cons)) {
+				/* Checking callability of the immediate target
+				 * is important, same for constructability.
+				 * Checking it for functions down the bound
+				 * function chain is not strictly necessary
+				 * because .bind() should normally reject them.
+				 * But it's good to check anyway because it's
+				 * technically possible to edit the bound function
+				 * chain via internal keys.
+				 */
+				goto not_constructable;
+			}
+			if (!DUK_HOBJECT_HAS_BOUND(cons)) {
+				break;
+			}
+		} else if (DUK_TVAL_IS_LIGHTFUNC(tv)) {
+			/* Lightfuncs cannot be bound. */
+			break;
+		} else {
+			/* Anything else is not constructable. */
+			goto not_constructable;
+		}
+		duk_get_prop_stridx(ctx, -1, DUK_STRIDX_INT_TARGET);  /* -> [... cons target] */
+		duk_remove(ctx, -2);                                  /* -> [... target] */
+	}
+	DUK_ASSERT(duk_is_callable(ctx, -1));
+	DUK_ASSERT(duk_is_lightfunc(ctx, -1) ||
+	           (duk_get_hobject(ctx, -1) != NULL && !DUK_HOBJECT_HAS_BOUND(duk_get_hobject(ctx, -1))));
+
+	/* [... constructor arg1 ... argN final_cons] */
+
+	/*
+	 *  Create "fallback" object to be used as the object instance,
+	 *  unless the constructor returns a replacement value.
+	 *  Its internal prototype needs to be set based on "prototype"
+	 *  property of the constructor.
+	 */
+
+	duk_push_object(ctx);  /* class Object, extensible */
+
+	/* [... constructor arg1 ... argN final_cons fallback] */
+
+	duk_get_prop_stridx(ctx, -2, DUK_STRIDX_PROTOTYPE);
+	proto = duk_get_hobject(ctx, -1);
+	if (!proto) {
+		DUK_DDD(DUK_DDDPRINT("constructor has no 'prototype' property, or value not an object "
+		                     "-> leave standard Object prototype as fallback prototype"));
+	} else {
+		DUK_DDD(DUK_DDDPRINT("constructor has 'prototype' property with object value "
+		                     "-> set fallback prototype to that value: %!iO", (duk_heaphdr *) proto));
+		fallback = duk_get_hobject(ctx, -2);
+		DUK_ASSERT(fallback != NULL);
+		DUK_HOBJECT_SET_PROTOTYPE_UPDREF(thr, fallback, proto);
+	}
+	duk_pop(ctx);
+
+	/* [... constructor arg1 ... argN final_cons fallback] */
+
+	/*
+	 *  Manipulate callstack for the call.
+	 */
+
+	duk_dup_top(ctx);
+	duk_insert(ctx, idx_cons + 1);  /* use fallback as 'this' value */
+	duk_insert(ctx, idx_cons);      /* also stash it before constructor,
+	                                 * in case we need it (as the fallback value)
+	                                 */
+	duk_pop(ctx);                   /* pop final_cons */
+
+
+	/* [... fallback constructor fallback(this) arg1 ... argN];
+	 * Note: idx_cons points to first 'fallback', not 'constructor'.
+	 */
+
+	DUK_DDD(DUK_DDDPRINT("before call, idx_cons+1 (constructor) -> %!T, idx_cons+2 (fallback/this) -> %!T, "
+	                     "nargs=%ld, top=%ld",
+	                     (duk_tval *) duk_get_tval(ctx, idx_cons + 1),
+	                     (duk_tval *) duk_get_tval(ctx, idx_cons + 2),
+	                     (long) nargs,
+	                     (long) duk_get_top(ctx)));
+
+	/*
+	 *  Call the constructor function (called in "constructor mode").
+	 */
+
+	call_flags = DUK_CALL_FLAG_CONSTRUCTOR_CALL;  /* not protected, respect reclimit, is a constructor call */
+
+	duk_handle_call_unprotected(thr,           /* thread */
+	                            nargs,         /* num_stack_args */
+	                            call_flags);   /* call_flags */
+
+	/* [... fallback retval] */
+
+	DUK_DDD(DUK_DDDPRINT("constructor call finished, fallback=%!iT, retval=%!iT",
+	                     (duk_tval *) duk_get_tval(ctx, -2),
+	                     (duk_tval *) duk_get_tval(ctx, -1)));
+
+	/*
+	 *  Determine whether to use the constructor return value as the created
+	 *  object instance or not.
+	 */
+
+	if (duk_is_object(ctx, -1)) {
+		duk_remove(ctx, -2);
+	} else {
+		duk_pop(ctx);
+	}
+
+	/*
+	 *  Augment created errors upon creation (not when they are thrown or
+	 *  rethrown).  __FILE__ and __LINE__ are not desirable here; the call
+	 *  stack reflects the caller which is correct.
+	 */
+
+#ifdef DUK_USE_AUGMENT_ERROR_CREATE
+	duk_hthread_sync_currpc(thr);
+	duk_err_augment_error_create(thr, thr, NULL, 0, 1 /*noblame_fileline*/);
+#endif
+
+	/* [... retval] */
+
+	return;
+
+ not_constructable:
+	DUK_ERROR_TYPE(thr, DUK_STR_NOT_CONSTRUCTABLE);
+}
+
+DUK_LOCAL duk_ret_t duk__pnew_helper(duk_context *ctx) {
+	duk_uint_t nargs;
+
+	nargs = duk_to_uint(ctx, -1);
+	duk_pop(ctx);
+
+	duk_new(ctx, nargs);
+	return 1;
+}
+
+DUK_EXTERNAL duk_int_t duk_pnew(duk_context *ctx, duk_idx_t nargs) {
+	duk_int_t rc;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	/* For now, just use duk_safe_call() to wrap duk_new().  We can't
+	 * simply use a protected duk_handle_call() because there's post
+	 * processing which might throw.  It should be possible to ensure
+	 * the post processing never throws (except in internal errors and
+	 * out of memory etc which are always allowed) and then remove this
+	 * wrapper.
+	 */
+
+	duk_push_uint(ctx, nargs);
+	rc = duk_safe_call(ctx, duk__pnew_helper, nargs + 2 /*nargs*/, 1 /*nrets*/);
+	return rc;
+}
+
+DUK_EXTERNAL duk_bool_t duk_is_constructor_call(duk_context *ctx) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_activation *act;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+	DUK_ASSERT(thr != NULL);
+	DUK_ASSERT_DISABLE(thr->callstack_top >= 0);
+
+	act = duk_hthread_get_current_activation(thr);
+	DUK_ASSERT(act != NULL);  /* because callstack_top > 0 */
+	return ((act->flags & DUK_ACT_FLAG_CONSTRUCT) != 0 ? 1 : 0);
+}
+
+DUK_EXTERNAL duk_bool_t duk_is_strict_call(duk_context *ctx) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_activation *act;
+
+	/* For user code this could just return 1 (strict) always
+	 * because all Duktape/C functions are considered strict,
+	 * and strict is also the default when nothing is running.
+	 * However, Duktape may call this function internally when
+	 * the current activation is an Ecmascript function, so
+	 * this cannot be replaced by a 'return 1' without fixing
+	 * the internal call sites.
+	 */
+
+	DUK_ASSERT_CTX_VALID(ctx);
+	DUK_ASSERT(thr != NULL);
+	DUK_ASSERT_DISABLE(thr->callstack_top >= 0);
+
+	act = duk_hthread_get_current_activation(thr);
+	if (act == NULL) {
+		/* Strict by default. */
+		return 1;
+	}
+	return ((act->flags & DUK_ACT_FLAG_STRICT) != 0 ? 1 : 0);
+}
+
+/*
+ *  Duktape/C function magic
+ */
+
+DUK_EXTERNAL duk_int_t duk_get_current_magic(duk_context *ctx) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_activation *act;
+	duk_hobject *func;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+	DUK_ASSERT(thr != NULL);
+	DUK_ASSERT_DISABLE(thr->callstack_top >= 0);
+
+	act = duk_hthread_get_current_activation(thr);
+	if (act) {
+		func = DUK_ACT_GET_FUNC(act);
+		if (!func) {
+			duk_tval *tv = &act->tv_func;
+			duk_small_uint_t lf_flags;
+			lf_flags = DUK_TVAL_GET_LIGHTFUNC_FLAGS(tv);
+			return (duk_int_t) DUK_LFUNC_FLAGS_GET_MAGIC(lf_flags);
+		}
+		DUK_ASSERT(func != NULL);
+
+		if (DUK_HOBJECT_IS_NATIVEFUNCTION(func)) {
+			duk_hnativefunction *nf = (duk_hnativefunction *) func;
+			return (duk_int_t) nf->magic;
+		}
+	}
+	return 0;
+}
+
+DUK_EXTERNAL duk_int_t duk_get_magic(duk_context *ctx, duk_idx_t index) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_tval *tv;
+	duk_hobject *h;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	tv = duk_require_tval(ctx, index);
+	if (DUK_TVAL_IS_OBJECT(tv)) {
+		h = DUK_TVAL_GET_OBJECT(tv);
+		DUK_ASSERT(h != NULL);
+		if (!DUK_HOBJECT_HAS_NATIVEFUNCTION(h)) {
+			goto type_error;
+		}
+		return (duk_int_t) ((duk_hnativefunction *) h)->magic;
+	} else if (DUK_TVAL_IS_LIGHTFUNC(tv)) {
+		duk_small_uint_t lf_flags = DUK_TVAL_GET_LIGHTFUNC_FLAGS(tv);
+		return (duk_int_t) DUK_LFUNC_FLAGS_GET_MAGIC(lf_flags);
+	}
+
+	/* fall through */
+ type_error:
+	DUK_ERROR_TYPE(thr, DUK_STR_UNEXPECTED_TYPE);
+	return 0;
+}
+
+DUK_EXTERNAL void duk_set_magic(duk_context *ctx, duk_idx_t index, duk_int_t magic) {
+	duk_hnativefunction *nf;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	nf = duk_require_hnativefunction(ctx, index);
+	DUK_ASSERT(nf != NULL);
+	nf->magic = (duk_int16_t) magic;
+}

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_api_codec.c
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_api_codec.c b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_api_codec.c
new file mode 100644
index 0000000..5fa0bb8
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_api_codec.c
@@ -0,0 +1,638 @@
+/*
+ *  Encoding and decoding basic formats: hex, base64.
+ *
+ *  These are in-place operations which may allow an optimized implementation.
+ *
+ *  Base-64: https://tools.ietf.org/html/rfc4648#section-4
+ */
+
+#include "duk_internal.h"
+
+/* Shared handling for encode/decode argument.  Fast path handling for
+ * buffer and string values because they're the most common.  In particular,
+ * avoid creating a temporary string or buffer when possible.
+ */
+DUK_LOCAL const duk_uint8_t *duk__prep_codec_arg(duk_context *ctx, duk_idx_t index, duk_size_t *out_len) {
+	DUK_ASSERT(duk_is_valid_index(ctx, index));  /* checked by caller */
+	if (duk_is_buffer(ctx, index)) {
+		return (const duk_uint8_t *) duk_get_buffer(ctx, index, out_len);
+	} else {
+		return (const duk_uint8_t *) duk_to_lstring(ctx, index, out_len);
+	}
+}
+
+#if defined(DUK_USE_BASE64_FASTPATH)
+DUK_LOCAL void duk__base64_encode_helper(const duk_uint8_t *src, duk_size_t srclen, duk_uint8_t *dst) {
+	duk_uint_t t;
+	duk_size_t n_full, n_full3, n_final;
+	const duk_uint8_t *src_end_fast;
+
+	n_full = srclen / 3;  /* full 3-byte -> 4-char conversions */
+	n_full3 = n_full * 3;
+	n_final = srclen - n_full3;
+	DUK_ASSERT_DISABLE(n_final >= 0);
+	DUK_ASSERT(n_final <= 2);
+
+	src_end_fast = src + n_full3;
+	while (DUK_UNLIKELY(src != src_end_fast)) {
+		t = (duk_uint_t) (*src++);
+		t = (t << 8) + (duk_uint_t) (*src++);
+		t = (t << 8) + (duk_uint_t) (*src++);
+
+		*dst++ = duk_base64_enctab[t >> 18];
+		*dst++ = duk_base64_enctab[(t >> 12) & 0x3f];
+		*dst++ = duk_base64_enctab[(t >> 6) & 0x3f];
+		*dst++ = duk_base64_enctab[t & 0x3f];
+
+#if 0  /* Tested: not faster on x64 */
+		/* aaaaaabb bbbbcccc ccdddddd */
+		dst[0] = duk_base64_enctab[(src[0] >> 2) & 0x3f];
+		dst[1] = duk_base64_enctab[((src[0] << 4) & 0x30) | ((src[1] >> 4) & 0x0f)];
+		dst[2] = duk_base64_enctab[((src[1] << 2) & 0x3f) | ((src[2] >> 6) & 0x03)];
+		dst[3] = duk_base64_enctab[src[2] & 0x3f];
+		src += 3; dst += 4;
+#endif
+	}
+
+	switch (n_final) {
+	/* case 0: nop */
+	case 1: {
+		/* XX== */
+		t = (duk_uint_t) (*src++);
+		*dst++ = duk_base64_enctab[t >> 2];           /* XXXXXX-- */
+		*dst++ = duk_base64_enctab[(t << 4) & 0x3f];  /* ------XX */
+		*dst++ = DUK_ASC_EQUALS;
+		*dst++ = DUK_ASC_EQUALS;
+		break;
+	}
+	case 2: {
+		/* XXX= */
+		t = (duk_uint_t) (*src++);
+		t = (t << 8) + (duk_uint_t) (*src++);
+		*dst++ = duk_base64_enctab[t >> 10];          /* XXXXXX-- -------- */
+		*dst++ = duk_base64_enctab[(t >> 4) & 0x3f];  /* ------XX XXXX---- */
+		*dst++ = duk_base64_enctab[(t << 2) & 0x3f];  /* -------- ----XXXX */
+		*dst++ = DUK_ASC_EQUALS;
+		break;
+	}
+	}
+}
+#else  /* DUK_USE_BASE64_FASTPATH */
+DUK_LOCAL void duk__base64_encode_helper(const duk_uint8_t *src, duk_size_t srclen, duk_uint8_t *dst) {
+	duk_small_uint_t i, snip;
+	duk_uint_t t;
+	duk_uint_fast8_t x, y;
+	const duk_uint8_t *src_end;
+
+	src_end = src + srclen;
+
+	while (src < src_end) {
+		/* read 3 bytes into 't', padded by zero */
+		snip = 4;
+		t = 0;
+		for (i = 0; i < 3; i++) {
+			t = t << 8;
+			if (src >= src_end) {
+				snip--;
+			} else {
+				t += (duk_uint_t) (*src++);
+			}
+		}
+
+		/*
+		 *  Missing bytes    snip     base64 example
+		 *    0               4         XXXX
+		 *    1               3         XXX=
+		 *    2               2         XX==
+		 */
+
+		DUK_ASSERT(snip >= 2 && snip <= 4);
+
+		for (i = 0; i < 4; i++) {
+			x = (duk_uint_fast8_t) ((t >> 18) & 0x3f);
+			t = t << 6;
+
+			/* A straightforward 64-byte lookup would be faster
+			 * and cleaner, but this is shorter.
+			 */
+			if (i >= snip) {
+				y = '=';
+			} else if (x <= 25) {
+				y = x + 'A';
+			} else if (x <= 51) {
+				y = x - 26 + 'a';
+			} else if (x <= 61) {
+				y = x - 52 + '0';
+			} else if (x == 62) {
+				y = '+';
+			} else {
+				y = '/';
+			}
+
+			*dst++ = (duk_uint8_t) y;
+		}
+	}
+}
+#endif  /* DUK_USE_BASE64_FASTPATH */
+
+#if defined(DUK_USE_BASE64_FASTPATH)
+DUK_LOCAL duk_bool_t duk__base64_decode_helper(const duk_uint8_t *src, duk_size_t srclen, duk_uint8_t *dst, duk_uint8_t **out_dst_final) {
+	duk_int_t x;
+	duk_int_t t;
+	duk_small_uint_t n_equal;
+	duk_small_uint_t n_chars;
+	const duk_uint8_t *src_end;
+	const duk_uint8_t *src_end_safe;
+
+	src_end = src + srclen;
+	src_end_safe = src_end - 4;  /* if 'src < src_end_safe', safe to read 4 bytes */
+
+	/* Innermost fast path processes 4 valid base-64 characters at a time
+	 * but bails out on whitespace, padding chars ('=') and invalid chars.
+	 * Once the slow path segment has been processed, we return to the
+	 * inner fast path again.  This handles e.g. base64 with newlines
+	 * reasonably well because the majority of a line is in the fast path.
+	 */
+	for (;;) {
+		/* Fast path, handle units with just actual encoding characters. */
+
+		while (src <= src_end_safe) {
+			/* The lookup byte is intentionally sign extended to (at least)
+			 * 32 bits and then ORed.  This ensures that is at least 1 byte
+			 * is negative, the highest bit of 't' will be set at the end
+			 * and we don't need to check every byte.
+			 */
+			DUK_DDD(DUK_DDDPRINT("fast loop: src=%p, src_end_safe=%p, src_end=%p",
+			                     (const void *) src, (const void *) src_end_safe, (const void *) src_end));
+
+			t = (duk_int_t) duk_base64_dectab[*src++];
+			t = (t << 6) | (duk_int_t) duk_base64_dectab[*src++];
+			t = (t << 6) | (duk_int_t) duk_base64_dectab[*src++];
+			t = (t << 6) | (duk_int_t) duk_base64_dectab[*src++];
+
+			if (DUK_UNLIKELY(t < 0)) {
+				DUK_DDD(DUK_DDDPRINT("fast loop unit was not clean, process one slow path unit"));
+				src -= 4;
+				break;
+			}
+
+			DUK_ASSERT(t <= 0xffffffL);
+			DUK_ASSERT((t >> 24) == 0);
+			*dst++ = (duk_uint8_t) (t >> 16);
+			*dst++ = (duk_uint8_t) ((t >> 8) & 0xff);
+			*dst++ = (duk_uint8_t) (t & 0xff);
+		}
+
+		/* Handle one slow path unit (or finish if we're done). */
+
+		n_equal = 0;
+		n_chars = 0;
+		t = 0;
+		for (;;) {
+			DUK_DDD(DUK_DDDPRINT("slow loop: src=%p, src_end=%p, n_chars=%ld, n_equal=%ld, t=%ld",
+			                     (const void *) src, (const void *) src_end, (long) n_chars, (long) n_equal, (long) t));
+
+			if (DUK_UNLIKELY(src >= src_end)) {
+				goto done;  /* two level break */
+			}
+
+			x = duk_base64_dectab[*src++];
+			if (DUK_UNLIKELY(x < 0)) {
+				if (x == -2) {
+					continue;  /* allowed ascii whitespace */
+				} else if (x == -3) {
+					n_equal++;
+					t <<= 6;
+				} else {
+					DUK_ASSERT(x == -1);
+					goto error;
+				}
+			} else {
+				DUK_ASSERT(x >= 0 && x <= 63);
+				if (n_equal > 0) {
+					/* Don't allow actual chars after equal sign. */
+					goto error;
+				}
+				t = (t << 6) + x;
+			}
+
+			if (DUK_UNLIKELY(n_chars == 3)) {
+				/* Emit 3 bytes and backtrack if there was padding.  There's
+				 * always space for the whole 3 bytes so no check needed.
+				 */
+				DUK_ASSERT(t <= 0xffffffL);
+				DUK_ASSERT((t >> 24) == 0);
+				*dst++ = (duk_uint8_t) (t >> 16);
+				*dst++ = (duk_uint8_t) ((t >> 8) & 0xff);
+				*dst++ = (duk_uint8_t) (t & 0xff);
+
+				if (DUK_UNLIKELY(n_equal > 0)) {
+					DUK_ASSERT(n_equal <= 4);
+
+					/* There may be whitespace between the equal signs. */
+					if (n_equal == 1) {
+						/* XXX= */
+						dst -= 1;
+					} else if (n_equal == 2) {
+						/* XX== */
+						dst -= 2;
+					} else {
+						goto error;  /* invalid padding */
+					}
+
+					/* Continue parsing after padding, allows concatenated,
+					 * padded base64.
+					 */
+				}
+				break;  /* back to fast loop */
+			} else {
+				n_chars++;
+			}
+		}
+	}
+ done:
+	DUK_DDD(DUK_DDDPRINT("done; src=%p, src_end=%p, n_chars=%ld",
+	                     (const void *) src, (const void *) src_end, (long) n_chars));
+
+	DUK_ASSERT(src == src_end);
+
+	if (n_chars != 0) {
+		/* Here we'd have the option of decoding unpadded base64
+		 * (e.g. "xxxxyy" instead of "xxxxyy==".  Currently not
+		 * accepted.
+		 */
+		goto error;
+	}
+
+	*out_dst_final = dst;
+	return 1;
+
+ error:
+	return 0;
+}
+#else  /* DUK_USE_BASE64_FASTPATH */
+DUK_LOCAL duk_bool_t duk__base64_decode_helper(const duk_uint8_t *src, duk_size_t srclen, duk_uint8_t *dst, duk_uint8_t **out_dst_final) {
+	duk_uint_t t;
+	duk_uint_fast8_t x, y;
+	duk_small_uint_t group_idx;
+	duk_small_uint_t n_equal;
+	const duk_uint8_t *src_end;
+
+	src_end = src + srclen;
+	t = 0;
+	group_idx = 0;
+	n_equal = 0;
+
+	while (src < src_end) {
+		x = *src++;
+
+		if (x >= 'A' && x <= 'Z') {
+			y = x - 'A' + 0;
+		} else if (x >= 'a' && x <= 'z') {
+			y = x - 'a' + 26;
+		} else if (x >= '0' && x <= '9') {
+			y = x - '0' + 52;
+		} else if (x == '+') {
+			y = 62;
+		} else if (x == '/') {
+			y = 63;
+		} else if (x == '=') {
+			/* We don't check the zero padding bytes here right now
+			 * (that they're actually zero).  This seems to be common
+			 * behavior for base-64 decoders.
+			 */
+
+			n_equal++;
+			t <<= 6;  /* shift in zeroes */
+			goto skip_add;
+		} else if (x == 0x09 || x == 0x0a || x == 0x0d || x == 0x20) {
+			/* allow basic ASCII whitespace */
+			continue;
+		} else {
+			goto error;
+		}
+
+		if (n_equal > 0) {
+			/* Don't allow mixed padding and actual chars. */
+			goto error;
+		}
+		t = (t << 6) + y;
+	 skip_add:
+
+		if (group_idx == 3) {
+			/* output 3 bytes from 't' */
+			*dst++ = (duk_uint8_t) ((t >> 16) & 0xff);
+			*dst++ = (duk_uint8_t) ((t >> 8) & 0xff);
+			*dst++ = (duk_uint8_t) (t & 0xff);
+
+			if (DUK_UNLIKELY(n_equal > 0)) {
+				/* Backtrack. */
+				DUK_ASSERT(n_equal <= 4);
+				if (n_equal == 1) {
+					dst -= 1;
+				} else if (n_equal == 2) {
+					dst -= 2;
+				} else {
+					goto error;  /* invalid padding */
+				}
+
+				/* Here we can choose either to end parsing and ignore
+				 * whatever follows, or to continue parsing in case
+				 * multiple (possibly padded) base64 strings have been
+				 * concatenated.  Currently, keep on parsing.
+				 */
+				n_equal = 0;
+			}
+
+			t = 0;
+			group_idx = 0;
+		} else {
+			group_idx++;
+		}
+	}
+
+	if (group_idx != 0) {
+		/* Here we'd have the option of decoding unpadded base64
+		 * (e.g. "xxxxyy" instead of "xxxxyy==".  Currently not
+		 * accepted.
+		 */
+		goto error;
+	}
+
+	*out_dst_final = dst;
+	return 1;
+
+ error:
+	return 0;
+}
+#endif  /* DUK_USE_BASE64_FASTPATH */
+
+DUK_EXTERNAL const char *duk_base64_encode(duk_context *ctx, duk_idx_t index) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	const duk_uint8_t *src;
+	duk_size_t srclen;
+	duk_size_t dstlen;
+	duk_uint8_t *dst;
+	const char *ret;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	/* XXX: optimize for string inputs: no need to coerce to a buffer
+	 * which makes a copy of the input.
+	 */
+
+	index = duk_require_normalize_index(ctx, index);
+	src = duk__prep_codec_arg(ctx, index, &srclen);
+	/* Note: for srclen=0, src may be NULL */
+
+	/* Computation must not wrap; this limit works for 32-bit size_t:
+	 * >>> srclen = 3221225469
+	 * >>> '%x' % ((srclen + 2) / 3 * 4)
+	 * 'fffffffc'
+	 */
+	if (srclen > 3221225469UL) {
+		goto type_error;
+	}
+	dstlen = (srclen + 2) / 3 * 4;
+	dst = (duk_uint8_t *) duk_push_fixed_buffer(ctx, dstlen);
+
+	duk__base64_encode_helper((const duk_uint8_t *) src, srclen, dst);
+
+	ret = duk_to_string(ctx, -1);
+	duk_replace(ctx, index);
+	return ret;
+
+ type_error:
+	DUK_ERROR_TYPE(thr, DUK_STR_ENCODE_FAILED);
+	return NULL;  /* never here */
+}
+
+DUK_EXTERNAL void duk_base64_decode(duk_context *ctx, duk_idx_t index) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	const duk_uint8_t *src;
+	duk_size_t srclen;
+	duk_size_t dstlen;
+	duk_uint8_t *dst;
+	duk_uint8_t *dst_final;
+	duk_bool_t retval;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	/* XXX: optimize for buffer inputs: no need to coerce to a string
+	 * which causes an unnecessary interning.
+	 */
+
+	index = duk_require_normalize_index(ctx, index);
+	src = duk__prep_codec_arg(ctx, index, &srclen);
+
+	/* Computation must not wrap, only srclen + 3 is at risk of
+	 * wrapping because after that the number gets smaller.
+	 * This limit works for 32-bit size_t:
+	 * 0x100000000 - 3 - 1 = 4294967292
+	 */
+	if (srclen > 4294967292UL) {
+		goto type_error;
+	}
+	dstlen = (srclen + 3) / 4 * 3;  /* upper limit, assuming no whitespace etc */
+	dst = (duk_uint8_t *) duk_push_dynamic_buffer(ctx, dstlen);
+	/* Note: for dstlen=0, dst may be NULL */
+
+	retval = duk__base64_decode_helper((const duk_uint8_t *) src, srclen, dst, &dst_final);
+	if (!retval) {
+		goto type_error;
+	}
+
+	/* XXX: convert to fixed buffer? */
+	(void) duk_resize_buffer(ctx, -1, (duk_size_t) (dst_final - dst));
+	duk_replace(ctx, index);
+	return;
+
+ type_error:
+	DUK_ERROR_TYPE(thr, DUK_STR_DECODE_FAILED);
+}
+
+DUK_EXTERNAL const char *duk_hex_encode(duk_context *ctx, duk_idx_t index) {
+	const duk_uint8_t *inp;
+	duk_size_t len;
+	duk_size_t i;
+	duk_uint8_t *buf;
+	const char *ret;
+#if defined(DUK_USE_HEX_FASTPATH)
+	duk_size_t len_safe;
+	duk_uint16_t *p16;
+#endif
+
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	index = duk_require_normalize_index(ctx, index);
+	inp = duk__prep_codec_arg(ctx, index, &len);
+	DUK_ASSERT(inp != NULL || len == 0);
+
+	/* Fixed buffer, no zeroing because we'll fill all the data. */
+	buf = (duk_uint8_t *) duk_push_buffer_raw(ctx, len * 2, DUK_BUF_FLAG_NOZERO /*flags*/);
+	DUK_ASSERT(buf != NULL);
+
+#if defined(DUK_USE_HEX_FASTPATH)
+	DUK_ASSERT((((duk_size_t) buf) & 0x01U) == 0);   /* pointer is aligned, guaranteed for fixed buffer */
+	p16 = (duk_uint16_t *) (void *) buf;
+	len_safe = len & ~0x03U;
+	for (i = 0; i < len_safe; i += 4) {
+		p16[0] = duk_hex_enctab[inp[i]];
+		p16[1] = duk_hex_enctab[inp[i + 1]];
+		p16[2] = duk_hex_enctab[inp[i + 2]];
+		p16[3] = duk_hex_enctab[inp[i + 3]];
+		p16 += 4;
+	}
+	for (; i < len; i++) {
+		*p16++ = duk_hex_enctab[inp[i]];
+	}
+#else  /* DUK_USE_HEX_FASTPATH */
+	for (i = 0; i < len; i++) {
+		duk_small_uint_t t;
+		t = (duk_small_uint_t) inp[i];
+		buf[i*2 + 0] = duk_lc_digits[t >> 4];
+		buf[i*2 + 1] = duk_lc_digits[t & 0x0f];
+	}
+#endif  /* DUK_USE_HEX_FASTPATH */
+
+	/* XXX: Using a string return value forces a string intern which is
+	 * not always necessary.  As a rough performance measure, hex encode
+	 * time for tests/perf/test-hex-encode.js dropped from ~35s to ~15s
+	 * without string coercion.  Change to returning a buffer and let the
+	 * caller coerce to string if necessary?
+	 */
+
+	ret = duk_to_string(ctx, -1);
+	duk_replace(ctx, index);
+	return ret;
+}
+
+DUK_EXTERNAL void duk_hex_decode(duk_context *ctx, duk_idx_t index) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	const duk_uint8_t *inp;
+	duk_size_t len;
+	duk_size_t i;
+	duk_int_t t;
+	duk_uint8_t *buf;
+#if defined(DUK_USE_HEX_FASTPATH)
+	duk_int_t chk;
+	duk_uint8_t *p;
+	duk_size_t len_safe;
+#endif
+
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	index = duk_require_normalize_index(ctx, index);
+	inp = duk__prep_codec_arg(ctx, index, &len);
+	DUK_ASSERT(inp != NULL || len == 0);
+
+	if (len & 0x01) {
+		goto type_error;
+	}
+
+	/* Fixed buffer, no zeroing because we'll fill all the data. */
+	buf = (duk_uint8_t *) duk_push_buffer_raw(ctx, len / 2, DUK_BUF_FLAG_NOZERO /*flags*/);
+	DUK_ASSERT(buf != NULL);
+
+#if defined(DUK_USE_HEX_FASTPATH)
+	p = buf;
+	len_safe = len & ~0x07U;
+	for (i = 0; i < len_safe; i += 8) {
+		t = ((duk_int_t) duk_hex_dectab_shift4[inp[i]]) |
+		    ((duk_int_t) duk_hex_dectab[inp[i + 1]]);
+		chk = t;
+		p[0] = (duk_uint8_t) t;
+		t = ((duk_int_t) duk_hex_dectab_shift4[inp[i + 2]]) |
+		    ((duk_int_t) duk_hex_dectab[inp[i + 3]]);
+		chk |= t;
+		p[1] = (duk_uint8_t) t;
+		t = ((duk_int_t) duk_hex_dectab_shift4[inp[i + 4]]) |
+		    ((duk_int_t) duk_hex_dectab[inp[i + 5]]);
+		chk |= t;
+		p[2] = (duk_uint8_t) t;
+		t = ((duk_int_t) duk_hex_dectab_shift4[inp[i + 6]]) |
+		    ((duk_int_t) duk_hex_dectab[inp[i + 7]]);
+		chk |= t;
+		p[3] = (duk_uint8_t) t;
+		p += 4;
+
+		/* Check if any lookup above had a negative result. */
+		if (DUK_UNLIKELY(chk < 0)) {
+			goto type_error;
+		}
+	}
+	for (; i < len; i += 2) {
+		t = (((duk_int_t) duk_hex_dectab[inp[i]]) << 4) |
+		    ((duk_int_t) duk_hex_dectab[inp[i + 1]]);
+		if (DUK_UNLIKELY(t < 0)) {
+			goto type_error;
+		}
+		*p++ = (duk_uint8_t) t;
+	}
+#else  /* DUK_USE_HEX_FASTPATH */
+	for (i = 0; i < len; i += 2) {
+		/* For invalid characters the value -1 gets extended to
+		 * at least 16 bits.  If either nybble is invalid, the
+		 * resulting 't' will be < 0.
+		 */
+		t = (((duk_int_t) duk_hex_dectab[inp[i]]) << 4) |
+		    ((duk_int_t) duk_hex_dectab[inp[i + 1]]);
+		if (DUK_UNLIKELY(t < 0)) {
+			goto type_error;
+		}
+		buf[i >> 1] = (duk_uint8_t) t;
+	}
+#endif  /* DUK_USE_HEX_FASTPATH */
+
+	duk_replace(ctx, index);
+	return;
+
+ type_error:
+	DUK_ERROR_TYPE(thr, DUK_STR_DECODE_FAILED);
+}
+
+DUK_EXTERNAL const char *duk_json_encode(duk_context *ctx, duk_idx_t index) {
+#ifdef DUK_USE_ASSERTIONS
+	duk_idx_t top_at_entry;
+#endif
+	const char *ret;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+#ifdef DUK_USE_ASSERTIONS
+	top_at_entry = duk_get_top(ctx);
+#endif
+
+	index = duk_require_normalize_index(ctx, index);
+	duk_bi_json_stringify_helper(ctx,
+	                             index /*idx_value*/,
+	                             DUK_INVALID_INDEX /*idx_replacer*/,
+	                             DUK_INVALID_INDEX /*idx_space*/,
+	                             0 /*flags*/);
+	DUK_ASSERT(duk_is_string(ctx, -1));
+	duk_replace(ctx, index);
+	ret = duk_get_string(ctx, index);
+
+	DUK_ASSERT(duk_get_top(ctx) == top_at_entry);
+
+	return ret;
+}
+
+DUK_EXTERNAL void duk_json_decode(duk_context *ctx, duk_idx_t index) {
+#ifdef DUK_USE_ASSERTIONS
+	duk_idx_t top_at_entry;
+#endif
+
+	DUK_ASSERT_CTX_VALID(ctx);
+#ifdef DUK_USE_ASSERTIONS
+	top_at_entry = duk_get_top(ctx);
+#endif
+
+	index = duk_require_normalize_index(ctx, index);
+	duk_bi_json_parse_helper(ctx,
+	                         index /*idx_value*/,
+	                         DUK_INVALID_INDEX /*idx_reviver*/,
+	                         0 /*flags*/);
+	duk_replace(ctx, index);
+
+	DUK_ASSERT(duk_get_top(ctx) == top_at_entry);
+}


[17/51] [partial] nifi-minifi-cpp git commit: MINIFI-183 Added civet 1.9.1 sources Added onScheduled hook Added initial two-way TLS-enabled ListenHTTP implementation

Posted by al...@apache.org.
http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_api_compile.c
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_api_compile.c b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_api_compile.c
new file mode 100644
index 0000000..38677ba
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_api_compile.c
@@ -0,0 +1,194 @@
+/*
+ *  Compilation and evaluation
+ */
+
+#include "duk_internal.h"
+
+typedef struct duk__compile_raw_args duk__compile_raw_args;
+struct duk__compile_raw_args {
+	duk_size_t src_length;  /* should be first on 64-bit platforms */
+	const duk_uint8_t *src_buffer;
+	duk_uint_t flags;
+};
+
+/* Eval is just a wrapper now. */
+DUK_EXTERNAL duk_int_t duk_eval_raw(duk_context *ctx, const char *src_buffer, duk_size_t src_length, duk_uint_t flags) {
+	duk_uint_t comp_flags;
+	duk_int_t rc;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	/* Note: strictness is *not* inherited from the current Duktape/C.
+	 * This would be confusing because the current strictness state
+	 * depends on whether we're running inside a Duktape/C activation
+	 * (= strict mode) or outside of any activation (= non-strict mode).
+	 * See tests/api/test-eval-strictness.c for more discussion.
+	 */
+
+	/* [ ... source? filename? ] (depends on flags) */
+
+	comp_flags = flags;
+	comp_flags |= DUK_COMPILE_EVAL;
+	rc = duk_compile_raw(ctx, src_buffer, src_length, comp_flags);  /* may be safe, or non-safe depending on flags */
+
+	/* [ ... closure/error ] */
+
+	if (rc != DUK_EXEC_SUCCESS) {
+		rc = DUK_EXEC_ERROR;
+		goto got_rc;
+	}
+
+	duk_push_global_object(ctx);  /* explicit 'this' binding, see GH-164 */
+
+	if (flags & DUK_COMPILE_SAFE) {
+		rc = duk_pcall_method(ctx, 0);
+	} else {
+		duk_call_method(ctx, 0);
+		rc = DUK_EXEC_SUCCESS;
+	}
+
+	/* [ ... result/error ] */
+
+ got_rc:
+	if (flags & DUK_COMPILE_NORESULT) {
+		duk_pop(ctx);
+	}
+
+	return rc;
+}
+
+/* Helper which can be called both directly and with duk_safe_call(). */
+DUK_LOCAL duk_ret_t duk__do_compile(duk_context *ctx) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk__compile_raw_args *comp_args;
+	duk_uint_t flags;
+	duk_small_uint_t comp_flags;
+	duk_hcompiledfunction *h_templ;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	/* Note: strictness is not inherited from the current Duktape/C
+	 * context.  Otherwise it would not be possible to compile
+	 * non-strict code inside a Duktape/C activation (which is
+	 * always strict now).  See tests/api/test-eval-strictness.c
+	 * for discussion.
+	 */
+
+	/* [ ... source? filename? &comp_args ] (depends on flags) */
+
+	comp_args = (duk__compile_raw_args *) duk_require_pointer(ctx, -1);
+	flags = comp_args->flags;
+	duk_pop(ctx);
+
+	/* [ ... source? filename? ] */
+
+	if (flags & DUK_COMPILE_NOFILENAME) {
+		/* Automatic filename: 'eval' or 'input'. */
+		duk_push_hstring_stridx(ctx, (flags & DUK_COMPILE_EVAL) ? DUK_STRIDX_EVAL : DUK_STRIDX_INPUT);
+	}
+
+	/* [ ... source? filename ] */
+
+	if (!comp_args->src_buffer) {
+		duk_hstring *h_sourcecode;
+
+		h_sourcecode = duk_get_hstring(ctx, -2);
+		if ((flags & DUK_COMPILE_NOSOURCE) ||  /* args incorrect */
+		    (h_sourcecode == NULL)) {          /* e.g. duk_push_string_file_raw() pushed undefined */
+			/* XXX: when this error is caused by a nonexistent
+			 * file given to duk_peval_file() or similar, the
+			 * error message is not the best possible.
+			 */
+			DUK_ERROR_API(thr, DUK_STR_NO_SOURCECODE);
+		}
+		DUK_ASSERT(h_sourcecode != NULL);
+		comp_args->src_buffer = (const duk_uint8_t *) DUK_HSTRING_GET_DATA(h_sourcecode);
+		comp_args->src_length = (duk_size_t) DUK_HSTRING_GET_BYTELEN(h_sourcecode);
+	}
+	DUK_ASSERT(comp_args->src_buffer != NULL);
+
+	/* XXX: unnecessary translation of flags */
+	comp_flags = 0;
+	if (flags & DUK_COMPILE_EVAL) {
+		comp_flags |= DUK_JS_COMPILE_FLAG_EVAL;
+	}
+	if (flags & DUK_COMPILE_FUNCTION) {
+		comp_flags |= DUK_JS_COMPILE_FLAG_EVAL |
+		              DUK_JS_COMPILE_FLAG_FUNCEXPR;
+	}
+	if (flags & DUK_COMPILE_STRICT) {
+		comp_flags |= DUK_JS_COMPILE_FLAG_STRICT;
+	}
+
+	/* [ ... source? filename ] */
+
+	duk_js_compile(thr, comp_args->src_buffer, comp_args->src_length, comp_flags);
+
+	/* [ ... source? func_template ] */
+
+	if (flags & DUK_COMPILE_NOSOURCE) {
+		;
+	} else {
+		duk_remove(ctx, -2);
+	}
+
+	/* [ ... func_template ] */
+
+	h_templ = (duk_hcompiledfunction *) duk_get_hobject(ctx, -1);
+	DUK_ASSERT(h_templ != NULL);
+	duk_js_push_closure(thr,
+	                   h_templ,
+	                   thr->builtins[DUK_BIDX_GLOBAL_ENV],
+	                   thr->builtins[DUK_BIDX_GLOBAL_ENV],
+	                   1 /*add_auto_proto*/);
+	duk_remove(ctx, -2);   /* -> [ ... closure ] */
+
+	/* [ ... closure ] */
+
+	return 1;
+}
+
+DUK_EXTERNAL duk_int_t duk_compile_raw(duk_context *ctx, const char *src_buffer, duk_size_t src_length, duk_uint_t flags) {
+	duk__compile_raw_args comp_args_alloc;
+	duk__compile_raw_args *comp_args = &comp_args_alloc;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	if ((flags & DUK_COMPILE_STRLEN) && (src_buffer != NULL)) {
+		/* String length is computed here to avoid multiple evaluation
+		 * of a macro argument in the calling side.
+		 */
+		src_length = DUK_STRLEN(src_buffer);
+	}
+
+	comp_args->src_buffer = (const duk_uint8_t *) src_buffer;
+	comp_args->src_length = src_length;
+	comp_args->flags = flags;
+	duk_push_pointer(ctx, (void *) comp_args);
+
+	/* [ ... source? filename? &comp_args ] (depends on flags) */
+
+	if (flags & DUK_COMPILE_SAFE) {
+		duk_int_t rc;
+		duk_int_t nargs;
+		duk_int_t nrets = 1;
+
+		/* Arguments can be: [ source? filename? &comp_args] so that
+		 * nargs is 1 to 3.  Call site encodes the correct nargs count
+		 * directly into flags.
+		 */
+		nargs = flags & 0x07;
+		DUK_ASSERT(nargs == (1 +
+		                     ((flags & DUK_COMPILE_NOSOURCE) ? 0 : 1) +
+		                     ((flags & DUK_COMPILE_NOFILENAME) ? 0 : 1)));
+		rc = duk_safe_call(ctx, duk__do_compile, nargs, nrets);
+
+		/* [ ... closure ] */
+		return rc;
+	}
+
+	(void) duk__do_compile(ctx);
+
+	/* [ ... closure ] */
+	return DUK_EXEC_SUCCESS;
+}

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_api_debug.c
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_api_debug.c b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_api_debug.c
new file mode 100644
index 0000000..9698b82
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_api_debug.c
@@ -0,0 +1,263 @@
+/*
+ *  Debugging related API calls
+ */
+
+#include "duk_internal.h"
+
+DUK_EXTERNAL void duk_push_context_dump(duk_context *ctx) {
+	duk_idx_t idx;
+	duk_idx_t top;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	/* We don't duk_require_stack() here now, but rely on the caller having
+	 * enough space.
+	 */
+
+	top = duk_get_top(ctx);
+	duk_push_array(ctx);
+	for (idx = 0; idx < top; idx++) {
+		duk_dup(ctx, idx);
+		duk_put_prop_index(ctx, -2, idx);
+	}
+
+	/* XXX: conversion errors should not propagate outwards.
+	 * Perhaps values need to be coerced individually?
+	 */
+	duk_bi_json_stringify_helper(ctx,
+	                             duk_get_top_index(ctx),  /*idx_value*/
+	                             DUK_INVALID_INDEX,  /*idx_replacer*/
+	                             DUK_INVALID_INDEX,  /*idx_space*/
+	                             DUK_JSON_FLAG_EXT_CUSTOM |
+	                             DUK_JSON_FLAG_ASCII_ONLY |
+	                             DUK_JSON_FLAG_AVOID_KEY_QUOTES /*flags*/);
+
+	duk_push_sprintf(ctx, "ctx: top=%ld, stack=%s", (long) top, (const char *) duk_safe_to_string(ctx, -1));
+	duk_replace(ctx, -3);  /* [ ... arr jsonx(arr) res ] -> [ ... res jsonx(arr) ] */
+	duk_pop(ctx);
+	DUK_ASSERT(duk_is_string(ctx, -1));
+}
+
+#if defined(DUK_USE_DEBUGGER_SUPPORT)
+
+DUK_EXTERNAL void duk_debugger_attach_custom(duk_context *ctx,
+                                             duk_debug_read_function read_cb,
+                                             duk_debug_write_function write_cb,
+                                             duk_debug_peek_function peek_cb,
+                                             duk_debug_read_flush_function read_flush_cb,
+                                             duk_debug_write_flush_function write_flush_cb,
+                                             duk_debug_request_function request_cb,
+                                             duk_debug_detached_function detached_cb,
+                                             void *udata) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_heap *heap;
+	const char *str;
+	duk_size_t len;
+
+	/* XXX: should there be an error or an automatic detach if
+	 * already attached?
+	 */
+
+	DUK_D(DUK_DPRINT("application called duk_debugger_attach()"));
+
+	DUK_ASSERT_CTX_VALID(ctx);
+	DUK_ASSERT(read_cb != NULL);
+	DUK_ASSERT(write_cb != NULL);
+	/* Other callbacks are optional. */
+
+	heap = thr->heap;
+	heap->dbg_read_cb = read_cb;
+	heap->dbg_write_cb = write_cb;
+	heap->dbg_peek_cb = peek_cb;
+	heap->dbg_read_flush_cb = read_flush_cb;
+	heap->dbg_write_flush_cb = write_flush_cb;
+	heap->dbg_request_cb = request_cb;
+	heap->dbg_detached_cb = detached_cb;
+	heap->dbg_udata = udata;
+	heap->dbg_have_next_byte = 0;
+
+	/* Start in paused state. */
+	heap->dbg_processing = 0;
+	heap->dbg_paused = 1;
+	heap->dbg_state_dirty = 1;
+	heap->dbg_force_restart = 0;
+	heap->dbg_step_type = 0;
+	heap->dbg_step_thread = NULL;
+	heap->dbg_step_csindex = 0;
+	heap->dbg_step_startline = 0;
+	heap->dbg_exec_counter = 0;
+	heap->dbg_last_counter = 0;
+	heap->dbg_last_time = 0.0;
+
+	/* Send version identification and flush right afterwards.  Note that
+	 * we must write raw, unframed bytes here.
+	 */
+	duk_push_sprintf(ctx, "%ld %ld %s %s\n",
+	                 (long) DUK_DEBUG_PROTOCOL_VERSION,
+	                 (long) DUK_VERSION,
+	                 (const char *) DUK_GIT_DESCRIBE,
+	                 (const char *) DUK_USE_TARGET_INFO);
+	str = duk_get_lstring(ctx, -1, &len);
+	DUK_ASSERT(str != NULL);
+	duk_debug_write_bytes(thr, (const duk_uint8_t *) str, len);
+	duk_debug_write_flush(thr);
+	duk_pop(ctx);
+}
+
+DUK_EXTERNAL void duk_debugger_detach(duk_context *ctx) {
+	duk_hthread *thr;
+
+	DUK_D(DUK_DPRINT("application called duk_debugger_detach()"));
+
+	DUK_ASSERT_CTX_VALID(ctx);
+	thr = (duk_hthread *) ctx;
+	DUK_ASSERT(thr != NULL);
+	DUK_ASSERT(thr->heap != NULL);
+
+	/* Can be called multiple times with no harm. */
+	duk_debug_do_detach(thr->heap);
+}
+
+DUK_EXTERNAL void duk_debugger_cooperate(duk_context *ctx) {
+	duk_hthread *thr;
+	duk_bool_t processed_messages;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+	thr = (duk_hthread *) ctx;
+	DUK_ASSERT(thr != NULL);
+	DUK_ASSERT(thr->heap != NULL);
+
+	if (!DUK_HEAP_IS_DEBUGGER_ATTACHED(thr->heap)) {
+		return;
+	}
+	if (thr->callstack_top > 0 || thr->heap->dbg_processing) {
+		/* Calling duk_debugger_cooperate() while Duktape is being
+		 * called into is not supported.  This is not a 100% check
+		 * but prevents any damage in most cases.
+		 */
+		return;
+	}
+
+	processed_messages = duk_debug_process_messages(thr, 1 /*no_block*/);
+	DUK_UNREF(processed_messages);
+}
+
+DUK_EXTERNAL duk_bool_t duk_debugger_notify(duk_context *ctx, duk_idx_t nvalues) {
+	duk_hthread *thr;
+	duk_idx_t top;
+	duk_idx_t idx;
+	duk_bool_t ret = 0;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+	thr = (duk_hthread *) ctx;
+	DUK_ASSERT(thr != NULL);
+	DUK_ASSERT(thr->heap != NULL);
+
+	DUK_D(DUK_DPRINT("application called duk_debugger_notify() with nvalues=%ld", (long) nvalues));
+
+	top = duk_get_top(ctx);
+	if (top < nvalues) {
+		DUK_ERROR_API(thr, "not enough stack values for notify");
+		return ret;  /* unreachable */
+	}
+	if (DUK_HEAP_IS_DEBUGGER_ATTACHED(thr->heap)) {
+		duk_debug_write_notify(thr, DUK_DBG_CMD_APPNOTIFY);
+		for (idx = top - nvalues; idx < top; idx++) {
+			duk_tval *tv = DUK_GET_TVAL_POSIDX(ctx, idx);
+			duk_debug_write_tval(thr, tv);
+		}
+		duk_debug_write_eom(thr);
+
+		/* Return non-zero (true) if we have a good reason to believe
+		 * the notify was delivered; if we're still attached at least
+		 * a transport error was not indicated by the transport write
+		 * callback.  This is not a 100% guarantee of course.
+		 */
+		if (DUK_HEAP_IS_DEBUGGER_ATTACHED(thr->heap)) {
+			ret = 1;
+		}
+	}
+	duk_pop_n(ctx, nvalues);
+	return ret;
+}
+
+DUK_EXTERNAL void duk_debugger_pause(duk_context *ctx) {
+	duk_hthread *thr;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+	thr = (duk_hthread *) ctx;
+	DUK_ASSERT(thr != NULL);
+	DUK_ASSERT(thr->heap != NULL);
+
+	DUK_D(DUK_DPRINT("application called duk_debugger_pause()"));
+
+	/* Treat like a debugger statement: ignore when not attached. */
+	if (DUK_HEAP_IS_DEBUGGER_ATTACHED(thr->heap)) {
+		DUK_HEAP_SET_PAUSED(thr->heap);
+
+		/* Pause on the next opcode executed.  This is always safe to do even
+		 * inside the debugger message loop: the interrupt counter will be reset
+		 * to its proper value when the message loop exits.
+		 */
+		thr->interrupt_init = 1;
+		thr->interrupt_counter = 0;
+	}
+}
+
+#else  /* DUK_USE_DEBUGGER_SUPPORT */
+
+DUK_EXTERNAL void duk_debugger_attach_custom(duk_context *ctx,
+                                             duk_debug_read_function read_cb,
+                                             duk_debug_write_function write_cb,
+                                             duk_debug_peek_function peek_cb,
+                                             duk_debug_read_flush_function read_flush_cb,
+                                             duk_debug_write_flush_function write_flush_cb,
+                                             duk_debug_request_function request_cb,
+                                             duk_debug_detached_function detached_cb,
+                                             void *udata) {
+	DUK_ASSERT_CTX_VALID(ctx);
+	DUK_UNREF(read_cb);
+	DUK_UNREF(write_cb);
+	DUK_UNREF(peek_cb);
+	DUK_UNREF(read_flush_cb);
+	DUK_UNREF(write_flush_cb);
+	DUK_UNREF(request_cb);
+	DUK_UNREF(detached_cb);
+	DUK_UNREF(udata);
+	DUK_ERROR_API((duk_hthread *) ctx, "no debugger support");
+}
+
+DUK_EXTERNAL void duk_debugger_detach(duk_context *ctx) {
+	DUK_ASSERT_CTX_VALID(ctx);
+	DUK_ERROR_API((duk_hthread *) ctx, "no debugger support");
+}
+
+DUK_EXTERNAL void duk_debugger_cooperate(duk_context *ctx) {
+	/* nop */
+	DUK_ASSERT_CTX_VALID(ctx);
+	DUK_UNREF(ctx);
+}
+
+DUK_EXTERNAL duk_bool_t duk_debugger_notify(duk_context *ctx, duk_idx_t nvalues) {
+	duk_idx_t top;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	top = duk_get_top(ctx);
+	if (top < nvalues) {
+		DUK_ERROR_API((duk_hthread *) ctx, "not enough stack values for notify");
+		return 0;  /* unreachable */
+	}
+
+	/* No debugger support, just pop values. */
+	duk_pop_n(ctx, nvalues);
+	return 0;
+}
+
+DUK_EXTERNAL void duk_debugger_pause(duk_context *ctx) {
+	/* Treat like debugger statement: nop */
+	DUK_ASSERT_CTX_VALID(ctx);
+	DUK_UNREF(ctx);
+}
+
+#endif  /* DUK_USE_DEBUGGER_SUPPORT */

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_api_heap.c
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_api_heap.c b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_api_heap.c
new file mode 100644
index 0000000..6cb1837
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_api_heap.c
@@ -0,0 +1,134 @@
+/*
+ *  Heap creation and destruction
+ */
+
+#include "duk_internal.h"
+
+DUK_EXTERNAL
+duk_context *duk_create_heap(duk_alloc_function alloc_func,
+                             duk_realloc_function realloc_func,
+                             duk_free_function free_func,
+                             void *heap_udata,
+                             duk_fatal_function fatal_handler) {
+	duk_heap *heap = NULL;
+	duk_context *ctx;
+
+	/* Assume that either all memory funcs are NULL or non-NULL, mixed
+	 * cases will now be unsafe.
+	 */
+
+	/* XXX: just assert non-NULL values here and make caller arguments
+	 * do the defaulting to the default implementations (smaller code)?
+	 */
+
+	if (!alloc_func) {
+		DUK_ASSERT(realloc_func == NULL);
+		DUK_ASSERT(free_func == NULL);
+#if defined(DUK_USE_PROVIDE_DEFAULT_ALLOC_FUNCTIONS)
+		alloc_func = duk_default_alloc_function;
+		realloc_func = duk_default_realloc_function;
+		free_func = duk_default_free_function;
+#else
+		DUK_D(DUK_DPRINT("no allocation functions given and no default providers"));
+		return NULL;
+#endif
+	} else {
+		DUK_ASSERT(realloc_func != NULL);
+		DUK_ASSERT(free_func != NULL);
+	}
+
+	if (!fatal_handler) {
+		fatal_handler = duk_default_fatal_handler;
+	}
+
+	DUK_ASSERT(alloc_func != NULL);
+	DUK_ASSERT(realloc_func != NULL);
+	DUK_ASSERT(free_func != NULL);
+	DUK_ASSERT(fatal_handler != NULL);
+
+	heap = duk_heap_alloc(alloc_func, realloc_func, free_func, heap_udata, fatal_handler);
+	if (!heap) {
+		return NULL;
+	}
+	ctx = (duk_context *) heap->heap_thread;
+	DUK_ASSERT(ctx != NULL);
+	DUK_ASSERT(((duk_hthread *) ctx)->heap != NULL);
+	return ctx;
+}
+
+DUK_EXTERNAL void duk_destroy_heap(duk_context *ctx) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_heap *heap;
+
+	if (!ctx) {
+		return;
+	}
+	heap = thr->heap;
+	DUK_ASSERT(heap != NULL);
+
+	duk_heap_free(heap);
+}
+
+/* XXX: better place for this */
+DUK_EXTERNAL void duk_set_global_object(duk_context *ctx) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_hobject *h_glob;
+	duk_hobject *h_prev_glob;
+	duk_hobject *h_env;
+	duk_hobject *h_prev_env;
+
+	DUK_D(DUK_DPRINT("replace global object with: %!T", duk_get_tval(ctx, -1)));
+
+	h_glob = duk_require_hobject(ctx, -1);
+	DUK_ASSERT(h_glob != NULL);
+
+	/*
+	 *  Replace global object.
+	 */
+
+	h_prev_glob = thr->builtins[DUK_BIDX_GLOBAL];
+	DUK_UNREF(h_prev_glob);
+	thr->builtins[DUK_BIDX_GLOBAL] = h_glob;
+	DUK_HOBJECT_INCREF(thr, h_glob);
+	DUK_HOBJECT_DECREF_ALLOWNULL(thr, h_prev_glob);  /* side effects, in theory (referenced by global env) */
+
+	/*
+	 *  Replace lexical environment for global scope
+	 *
+	 *  Create a new object environment for the global lexical scope.
+	 *  We can't just reset the _Target property of the current one,
+	 *  because the lexical scope is shared by other threads with the
+	 *  same (initial) built-ins.
+	 */
+
+	(void) duk_push_object_helper(ctx,
+	                              DUK_HOBJECT_FLAG_EXTENSIBLE |
+	                              DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJENV),
+	                              -1);  /* no prototype, updated below */
+
+	duk_dup(ctx, -2);
+	duk_dup(ctx, -3);
+
+	/* [ ... new_glob new_env new_glob new_glob ] */
+
+	duk_xdef_prop_stridx(thr, -3, DUK_STRIDX_INT_TARGET, DUK_PROPDESC_FLAGS_NONE);
+	duk_xdef_prop_stridx(thr, -2, DUK_STRIDX_INT_THIS, DUK_PROPDESC_FLAGS_NONE);
+
+	/* [ ... new_glob new_env ] */
+
+	h_env = duk_get_hobject(ctx, -1);
+	DUK_ASSERT(h_env != NULL);
+
+	h_prev_env = thr->builtins[DUK_BIDX_GLOBAL_ENV];
+	thr->builtins[DUK_BIDX_GLOBAL_ENV] = h_env;
+	DUK_HOBJECT_INCREF(thr, h_env);
+	DUK_HOBJECT_DECREF_ALLOWNULL(thr, h_prev_env);  /* side effects */
+	DUK_UNREF(h_env);  /* without refcounts */
+	DUK_UNREF(h_prev_env);
+
+	/* [ ... new_glob new_env ] */
+
+	duk_pop_2(ctx);
+
+	/* [ ... ] */
+}

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_api_internal.h
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_api_internal.h b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_api_internal.h
new file mode 100644
index 0000000..3e7aea6
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_api_internal.h
@@ -0,0 +1,194 @@
+/*
+ *  Internal API calls which have (stack and other) semantics similar
+ *  to the public API.
+ */
+
+#ifndef DUK_API_INTERNAL_H_INCLUDED
+#define DUK_API_INTERNAL_H_INCLUDED
+
+/* duk_push_sprintf constants */
+#define DUK_PUSH_SPRINTF_INITIAL_SIZE  256L
+#define DUK_PUSH_SPRINTF_SANITY_LIMIT  (1L * 1024L * 1024L * 1024L)
+
+/* Flag ORed to err_code to indicate __FILE__ / __LINE__ is not
+ * blamed as source of error for error fileName / lineNumber.
+ */
+#define DUK_ERRCODE_FLAG_NOBLAME_FILELINE  (1L << 24)
+
+/* Valstack resize flags */
+#define DUK_VSRESIZE_FLAG_SHRINK           (1 << 0)
+#define DUK_VSRESIZE_FLAG_COMPACT          (1 << 1)
+#define DUK_VSRESIZE_FLAG_THROW            (1 << 2)
+
+/* Current convention is to use duk_size_t for value stack sizes and global indices,
+ * and duk_idx_t for local frame indices.
+ */
+DUK_INTERNAL_DECL
+duk_bool_t duk_valstack_resize_raw(duk_context *ctx,
+                                   duk_size_t min_new_size,
+                                   duk_small_uint_t flags);
+
+#if defined(DUK_USE_VERBOSE_ERRORS) && defined(DUK_USE_PARANOID_ERRORS)
+DUK_INTERNAL_DECL const char *duk_get_type_name(duk_context *ctx, duk_idx_t index);
+#endif
+
+DUK_INTERNAL_DECL duk_tval *duk_get_tval(duk_context *ctx, duk_idx_t index);
+DUK_INTERNAL_DECL duk_tval *duk_require_tval(duk_context *ctx, duk_idx_t index);
+DUK_INTERNAL_DECL void duk_push_tval(duk_context *ctx, duk_tval *tv);
+
+/* Push the current 'this' binding; throw TypeError if binding is not object
+ * coercible (CheckObjectCoercible).
+ */
+DUK_INTERNAL_DECL void duk_push_this_check_object_coercible(duk_context *ctx);
+
+/* duk_push_this() + CheckObjectCoercible() + duk_to_object() */
+DUK_INTERNAL_DECL duk_hobject *duk_push_this_coercible_to_object(duk_context *ctx);
+
+/* duk_push_this() + CheckObjectCoercible() + duk_to_string() */
+DUK_INTERNAL_DECL duk_hstring *duk_push_this_coercible_to_string(duk_context *ctx);
+
+/* Get a borrowed duk_tval pointer to the current 'this' binding.  Caller must
+ * make sure there's an active callstack entry.  Note that the returned pointer
+ * is unstable with regards to side effects.
+ */
+DUK_INTERNAL_DECL duk_tval *duk_get_borrowed_this_tval(duk_context *ctx);
+
+/* XXX: add fastint support? */
+#define duk_push_u64(ctx,val) \
+	duk_push_number((ctx), (duk_double_t) (val))
+#define duk_push_i64(ctx,val) \
+	duk_push_number((ctx), (duk_double_t) (val))
+
+/* duk_push_(u)int() is guaranteed to support at least (un)signed 32-bit range */
+#define duk_push_u32(ctx,val) \
+	duk_push_uint((ctx), (duk_uint_t) (val))
+#define duk_push_i32(ctx,val) \
+	duk_push_int((ctx), (duk_int_t) (val))
+
+/* sometimes stack and array indices need to go on the stack */
+#define duk_push_idx(ctx,val) \
+	duk_push_int((ctx), (duk_int_t) (val))
+#define duk_push_uarridx(ctx,val) \
+	duk_push_uint((ctx), (duk_uint_t) (val))
+#define duk_push_size_t(ctx,val) \
+	duk_push_uint((ctx), (duk_uint_t) (val))  /* XXX: assumed to fit for now */
+
+DUK_INTERNAL_DECL duk_hstring *duk_get_hstring(duk_context *ctx, duk_idx_t index);
+DUK_INTERNAL_DECL duk_hobject *duk_get_hobject(duk_context *ctx, duk_idx_t index);
+DUK_INTERNAL_DECL duk_hbuffer *duk_get_hbuffer(duk_context *ctx, duk_idx_t index);
+DUK_INTERNAL_DECL duk_hthread *duk_get_hthread(duk_context *ctx, duk_idx_t index);
+DUK_INTERNAL_DECL duk_hcompiledfunction *duk_get_hcompiledfunction(duk_context *ctx, duk_idx_t index);
+DUK_INTERNAL_DECL duk_hnativefunction *duk_get_hnativefunction(duk_context *ctx, duk_idx_t index);
+
+DUK_INTERNAL_DECL duk_hobject *duk_get_hobject_with_class(duk_context *ctx, duk_idx_t index, duk_small_uint_t classnum);
+
+#if 0  /* This would be pointless: unexpected type and lightfunc would both return NULL */
+DUK_INTERNAL_DECL duk_hobject *duk_get_hobject_or_lfunc(duk_context *ctx, duk_idx_t index);
+#endif
+DUK_INTERNAL_DECL duk_hobject *duk_get_hobject_or_lfunc_coerce(duk_context *ctx, duk_idx_t index);
+
+#if 0  /*unused*/
+DUK_INTERNAL_DECL void *duk_get_voidptr(duk_context *ctx, duk_idx_t index);
+#endif
+
+DUK_INTERNAL_DECL duk_hstring *duk_to_hstring(duk_context *ctx, duk_idx_t index);
+#if defined(DUK_USE_DEBUGGER_SUPPORT)  /* only needed by debugger for now */
+DUK_INTERNAL_DECL duk_hstring *duk_safe_to_hstring(duk_context *ctx, duk_idx_t index);
+#endif
+DUK_INTERNAL_DECL void duk_to_object_class_string_top(duk_context *ctx);
+#if !defined(DUK_USE_PARANOID_ERRORS)
+DUK_INTERNAL_DECL void duk_push_hobject_class_string(duk_context *ctx, duk_hobject *h);
+#endif
+
+DUK_INTERNAL_DECL duk_int_t duk_to_int_clamped_raw(duk_context *ctx, duk_idx_t index, duk_int_t minval, duk_int_t maxval, duk_bool_t *out_clamped);  /* out_clamped=NULL, RangeError if outside range */
+DUK_INTERNAL_DECL duk_int_t duk_to_int_clamped(duk_context *ctx, duk_idx_t index, duk_int_t minval, duk_int_t maxval);
+DUK_INTERNAL_DECL duk_int_t duk_to_int_check_range(duk_context *ctx, duk_idx_t index, duk_int_t minval, duk_int_t maxval);
+#if defined(DUK_USE_BUFFEROBJECT_SUPPORT)
+DUK_INTERNAL_DECL duk_uint8_t duk_to_uint8clamped(duk_context *ctx, duk_idx_t index);
+#endif
+
+DUK_INTERNAL_DECL duk_hstring *duk_require_hstring(duk_context *ctx, duk_idx_t index);
+DUK_INTERNAL_DECL duk_hobject *duk_require_hobject(duk_context *ctx, duk_idx_t index);
+DUK_INTERNAL_DECL duk_hbuffer *duk_require_hbuffer(duk_context *ctx, duk_idx_t index);
+DUK_INTERNAL_DECL duk_hthread *duk_require_hthread(duk_context *ctx, duk_idx_t index);
+DUK_INTERNAL_DECL duk_hcompiledfunction *duk_require_hcompiledfunction(duk_context *ctx, duk_idx_t index);
+DUK_INTERNAL_DECL duk_hnativefunction *duk_require_hnativefunction(duk_context *ctx, duk_idx_t index);
+
+DUK_INTERNAL_DECL duk_hobject *duk_require_hobject_with_class(duk_context *ctx, duk_idx_t index, duk_small_uint_t classnum);
+
+DUK_INTERNAL_DECL duk_hobject *duk_require_hobject_or_lfunc(duk_context *ctx, duk_idx_t index);
+DUK_INTERNAL_DECL duk_hobject *duk_require_hobject_or_lfunc_coerce(duk_context *ctx, duk_idx_t index);
+
+DUK_INTERNAL_DECL void duk_push_hstring(duk_context *ctx, duk_hstring *h);
+DUK_INTERNAL_DECL void duk_push_hstring_stridx(duk_context *ctx, duk_small_int_t stridx);
+DUK_INTERNAL_DECL void duk_push_hobject(duk_context *ctx, duk_hobject *h);
+DUK_INTERNAL_DECL void duk_push_hbuffer(duk_context *ctx, duk_hbuffer *h);
+#define duk_push_hthread(ctx,h) \
+	duk_push_hobject((ctx), (duk_hobject *) (h))
+#define duk_push_hcompiledfunction(ctx,h) \
+	duk_push_hobject((ctx), (duk_hobject *) (h))
+#define duk_push_hnativefunction(ctx,h) \
+	duk_push_hobject((ctx), (duk_hobject *) (h))
+DUK_INTERNAL_DECL void duk_push_hobject_bidx(duk_context *ctx, duk_small_int_t builtin_idx);
+DUK_INTERNAL_DECL duk_idx_t duk_push_object_helper(duk_context *ctx, duk_uint_t hobject_flags_and_class, duk_small_int_t prototype_bidx);
+DUK_INTERNAL_DECL duk_idx_t duk_push_object_helper_proto(duk_context *ctx, duk_uint_t hobject_flags_and_class, duk_hobject *proto);
+DUK_INTERNAL_DECL duk_idx_t duk_push_object_internal(duk_context *ctx);
+DUK_INTERNAL_DECL duk_idx_t duk_push_compiledfunction(duk_context *ctx);
+DUK_INTERNAL_DECL void duk_push_c_function_noexotic(duk_context *ctx, duk_c_function func, duk_int_t nargs);
+DUK_INTERNAL_DECL void duk_push_c_function_noconstruct_noexotic(duk_context *ctx, duk_c_function func, duk_int_t nargs);
+
+DUK_INTERNAL_DECL void duk_push_string_funcptr(duk_context *ctx, duk_uint8_t *ptr, duk_size_t sz);
+DUK_INTERNAL_DECL void duk_push_lightfunc_name(duk_context *ctx, duk_tval *tv);
+DUK_INTERNAL_DECL void duk_push_lightfunc_tostring(duk_context *ctx, duk_tval *tv);
+DUK_INTERNAL_DECL duk_hbufferobject *duk_push_bufferobject_raw(duk_context *ctx, duk_uint_t hobject_flags_and_class, duk_small_int_t prototype_bidx);
+
+#if !defined(DUK_USE_PARANOID_ERRORS)
+DUK_INTERNAL_DECL const char *duk_push_string_readable(duk_context *ctx, duk_idx_t index);
+DUK_INTERNAL_DECL const char *duk_push_string_tval_readable(duk_context *ctx, duk_tval *tv);
+#endif
+
+DUK_INTERNAL_DECL duk_bool_t duk_get_prop_stridx(duk_context *ctx, duk_idx_t obj_index, duk_small_int_t stridx);     /* [] -> [val] */
+DUK_INTERNAL_DECL duk_bool_t duk_put_prop_stridx(duk_context *ctx, duk_idx_t obj_index, duk_small_int_t stridx);     /* [val] -> [] */
+DUK_INTERNAL_DECL duk_bool_t duk_del_prop_stridx(duk_context *ctx, duk_idx_t obj_index, duk_small_int_t stridx);     /* [] -> [] */
+DUK_INTERNAL_DECL duk_bool_t duk_has_prop_stridx(duk_context *ctx, duk_idx_t obj_index, duk_small_int_t stridx);     /* [] -> [] */
+
+DUK_INTERNAL_DECL duk_bool_t duk_get_prop_stridx_boolean(duk_context *ctx, duk_idx_t obj_index, duk_small_int_t stridx, duk_bool_t *out_has_prop);  /* [] -> [] */
+
+DUK_INTERNAL_DECL void duk_xdef_prop(duk_context *ctx, duk_idx_t obj_index, duk_small_uint_t desc_flags);  /* [key val] -> [] */
+DUK_INTERNAL_DECL void duk_xdef_prop_index(duk_context *ctx, duk_idx_t obj_index, duk_uarridx_t arr_index, duk_small_uint_t desc_flags);  /* [val] -> [] */
+DUK_INTERNAL_DECL void duk_xdef_prop_stridx(duk_context *ctx, duk_idx_t obj_index, duk_small_int_t stridx, duk_small_uint_t desc_flags);  /* [val] -> [] */
+DUK_INTERNAL_DECL void duk_xdef_prop_stridx_builtin(duk_context *ctx, duk_idx_t obj_index, duk_small_int_t stridx, duk_small_int_t builtin_idx, duk_small_uint_t desc_flags);  /* [] -> [] */
+DUK_INTERNAL_DECL void duk_xdef_prop_stridx_thrower(duk_context *ctx, duk_idx_t obj_index, duk_small_int_t stridx, duk_small_uint_t desc_flags);  /* [] -> [] */
+
+/* These are macros for now, but could be separate functions to reduce code
+ * footprint (check call site count before refactoring).
+ */
+#define duk_xdef_prop_wec(ctx,obj_index) \
+	duk_xdef_prop((ctx), (obj_index), DUK_PROPDESC_FLAGS_WEC)
+#define duk_xdef_prop_index_wec(ctx,obj_index,arr_index) \
+	duk_xdef_prop_index((ctx), (obj_index), (arr_index), DUK_PROPDESC_FLAGS_WEC)
+#define duk_xdef_prop_stridx_wec(ctx,obj_index,stridx) \
+	duk_xdef_prop_stridx((ctx), (obj_index), (stridx), DUK_PROPDESC_FLAGS_WEC)
+
+/* Set object 'length'. */
+DUK_INTERNAL_DECL void duk_set_length(duk_context *ctx, duk_idx_t index, duk_size_t length);
+
+/* Raw internal valstack access macros: access is unsafe so call site
+ * must have a guarantee that the index is valid.  When that is the case,
+ * using these macro results in faster and smaller code than duk_get_tval().
+ * Both 'ctx' and 'idx' are evaluted multiple times, but only for asserts.
+ */
+#define DUK_ASSERT_VALID_NEGIDX(ctx,idx) \
+	(DUK_ASSERT_EXPR((idx) < 0), DUK_ASSERT_EXPR(duk_is_valid_index((ctx), (idx))))
+#define DUK_ASSERT_VALID_POSIDX(ctx,idx) \
+	(DUK_ASSERT_EXPR((idx) >= 0), DUK_ASSERT_EXPR(duk_is_valid_index((ctx), (idx))))
+#define DUK_GET_TVAL_NEGIDX(ctx,idx) \
+	(DUK_ASSERT_VALID_NEGIDX((ctx),(idx)), ((duk_hthread *) (ctx))->valstack_top + (idx))
+#define DUK_GET_TVAL_POSIDX(ctx,idx) \
+	(DUK_ASSERT_VALID_POSIDX((ctx),(idx)), ((duk_hthread *) (ctx))->valstack_bottom + (idx))
+#define DUK_GET_HOBJECT_NEGIDX(ctx,idx) \
+	(DUK_ASSERT_VALID_NEGIDX((ctx),(idx)), DUK_TVAL_GET_OBJECT(((duk_hthread *) (ctx))->valstack_top + (idx)))
+#define DUK_GET_HOBJECT_POSIDX(ctx,idx) \
+	(DUK_ASSERT_VALID_POSIDX((ctx),(idx)), DUK_TVAL_GET_OBJECT(((duk_hthread *) (ctx))->valstack_bottom + (idx)))
+
+#endif  /* DUK_API_INTERNAL_H_INCLUDED */

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_api_logging.c
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_api_logging.c b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_api_logging.c
new file mode 100644
index 0000000..aa9784f
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_api_logging.c
@@ -0,0 +1,52 @@
+/*
+ *  Logging
+ *
+ *  Current logging primitive is a sprintf-style log which is convenient
+ *  for most C code.  Another useful primitive would be to log N arguments
+ *  from value stack (like the Ecmascript binding does).
+ */
+
+#include "duk_internal.h"
+
+DUK_EXTERNAL void duk_log_va(duk_context *ctx, duk_int_t level, const char *fmt, va_list ap) {
+	/* stridx_logfunc[] must be static to allow initializer with old compilers like BCC */
+	static const duk_uint16_t stridx_logfunc[6] = {
+		DUK_STRIDX_LC_TRACE, DUK_STRIDX_LC_DEBUG, DUK_STRIDX_LC_INFO,
+		DUK_STRIDX_LC_WARN, DUK_STRIDX_LC_ERROR, DUK_STRIDX_LC_FATAL
+	};
+
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	if (level < 0) {
+		level = 0;
+	} else if (level > (int) (sizeof(stridx_logfunc) / sizeof(duk_uint16_t)) - 1) {
+		level = (int) (sizeof(stridx_logfunc) / sizeof(duk_uint16_t)) - 1;
+	}
+
+	duk_push_hobject_bidx(ctx, DUK_BIDX_LOGGER_CONSTRUCTOR);
+	duk_get_prop_stridx(ctx, -1, DUK_STRIDX_CLOG);
+	duk_get_prop_stridx(ctx, -1, stridx_logfunc[level]);
+	duk_dup(ctx, -2);
+
+	/* [ ... Logger clog logfunc clog ] */
+
+	duk_push_vsprintf(ctx, fmt, ap);
+
+	/* [ ... Logger clog logfunc clog(=this) msg ] */
+
+	duk_call_method(ctx, 1 /*nargs*/);
+
+	/* [ ... Logger clog res ] */
+
+	duk_pop_3(ctx);
+}
+
+DUK_EXTERNAL void duk_log(duk_context *ctx, duk_int_t level, const char *fmt, ...) {
+	va_list ap;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	va_start(ap, fmt);
+	duk_log_va(ctx, level, fmt, ap);
+	va_end(ap);
+}

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_api_memory.c
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_api_memory.c b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_api_memory.c
new file mode 100644
index 0000000..f3e5b8e
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_api_memory.c
@@ -0,0 +1,103 @@
+/*
+ *  Memory calls.
+ */
+
+#include "duk_internal.h"
+
+DUK_EXTERNAL void *duk_alloc_raw(duk_context *ctx, duk_size_t size) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	return DUK_ALLOC_RAW(thr->heap, size);
+}
+
+DUK_EXTERNAL void duk_free_raw(duk_context *ctx, void *ptr) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	DUK_FREE_RAW(thr->heap, ptr);
+}
+
+DUK_EXTERNAL void *duk_realloc_raw(duk_context *ctx, void *ptr, duk_size_t size) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	return DUK_REALLOC_RAW(thr->heap, ptr, size);
+}
+
+DUK_EXTERNAL void *duk_alloc(duk_context *ctx, duk_size_t size) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	return DUK_ALLOC(thr->heap, size);
+}
+
+DUK_EXTERNAL void duk_free(duk_context *ctx, void *ptr) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	DUK_FREE(thr->heap, ptr);
+}
+
+DUK_EXTERNAL void *duk_realloc(duk_context *ctx, void *ptr, duk_size_t size) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	/*
+	 *  Note: since this is an exposed API call, there should be
+	 *  no way a mark-and-sweep could have a side effect on the
+	 *  memory allocation behind 'ptr'; the pointer should never
+	 *  be something that Duktape wants to change.
+	 *
+	 *  Thus, no need to use DUK_REALLOC_INDIRECT (and we don't
+	 *  have the storage location here anyway).
+	 */
+
+	return DUK_REALLOC(thr->heap, ptr, size);
+}
+
+DUK_EXTERNAL void duk_get_memory_functions(duk_context *ctx, duk_memory_functions *out_funcs) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_heap *heap;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+	DUK_ASSERT(out_funcs != NULL);
+	DUK_ASSERT(thr != NULL);
+	DUK_ASSERT(thr->heap != NULL);
+
+	heap = thr->heap;
+	out_funcs->alloc_func = heap->alloc_func;
+	out_funcs->realloc_func = heap->realloc_func;
+	out_funcs->free_func = heap->free_func;
+	out_funcs->udata = heap->heap_udata;
+}
+
+DUK_EXTERNAL void duk_gc(duk_context *ctx, duk_uint_t flags) {
+#ifdef DUK_USE_MARK_AND_SWEEP
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_heap *heap;
+
+	DUK_UNREF(flags);
+
+	/* NULL accepted */
+	if (!ctx) {
+		return;
+	}
+	DUK_ASSERT_CTX_VALID(ctx);
+	heap = thr->heap;
+	DUK_ASSERT(heap != NULL);
+
+	DUK_D(DUK_DPRINT("mark-and-sweep requested by application"));
+	duk_heap_mark_and_sweep(heap, 0);
+#else
+	DUK_D(DUK_DPRINT("mark-and-sweep requested by application but mark-and-sweep not enabled, ignoring"));
+	DUK_UNREF(ctx);
+	DUK_UNREF(flags);
+#endif
+}

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_api_object.c
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_api_object.c b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_api_object.c
new file mode 100644
index 0000000..46634c5
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_api_object.c
@@ -0,0 +1,610 @@
+/*
+ *  Object handling: property access and other support functions.
+ */
+
+#include "duk_internal.h"
+
+/*
+ *  Property handling
+ *
+ *  The API exposes only the most common property handling functions.
+ *  The caller can invoke Ecmascript built-ins for full control (e.g.
+ *  defineProperty, getOwnPropertyDescriptor).
+ */
+
+DUK_EXTERNAL duk_bool_t duk_get_prop(duk_context *ctx, duk_idx_t obj_index) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_tval *tv_obj;
+	duk_tval *tv_key;
+	duk_bool_t rc;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	/* Note: copying tv_obj and tv_key to locals to shield against a valstack
+	 * resize is not necessary for a property get right now.
+	 */
+
+	tv_obj = duk_require_tval(ctx, obj_index);
+	tv_key = duk_require_tval(ctx, -1);
+
+	rc = duk_hobject_getprop(thr, tv_obj, tv_key);
+	DUK_ASSERT(rc == 0 || rc == 1);
+	/* a value is left on stack regardless of rc */
+
+	duk_remove(ctx, -2);  /* remove key */
+	return rc;  /* 1 if property found, 0 otherwise */
+}
+
+DUK_EXTERNAL duk_bool_t duk_get_prop_string(duk_context *ctx, duk_idx_t obj_index, const char *key) {
+	DUK_ASSERT_CTX_VALID(ctx);
+	DUK_ASSERT(key != NULL);
+
+	obj_index = duk_require_normalize_index(ctx, obj_index);
+	duk_push_string(ctx, key);
+	return duk_get_prop(ctx, obj_index);
+}
+
+DUK_EXTERNAL duk_bool_t duk_get_prop_index(duk_context *ctx, duk_idx_t obj_index, duk_uarridx_t arr_index) {
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	obj_index = duk_require_normalize_index(ctx, obj_index);
+	duk_push_uarridx(ctx, arr_index);
+	return duk_get_prop(ctx, obj_index);
+}
+
+DUK_INTERNAL duk_bool_t duk_get_prop_stridx(duk_context *ctx, duk_idx_t obj_index, duk_small_int_t stridx) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+	DUK_ASSERT_DISABLE(stridx >= 0);
+	DUK_ASSERT(stridx < DUK_HEAP_NUM_STRINGS);
+	DUK_UNREF(thr);
+
+	obj_index = duk_require_normalize_index(ctx, obj_index);
+	duk_push_hstring(ctx, DUK_HTHREAD_GET_STRING(thr, stridx));
+	return duk_get_prop(ctx, obj_index);
+}
+
+DUK_INTERNAL duk_bool_t duk_get_prop_stridx_boolean(duk_context *ctx, duk_idx_t obj_index, duk_small_int_t stridx, duk_bool_t *out_has_prop) {
+	duk_bool_t rc;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+	DUK_ASSERT_DISABLE(stridx >= 0);
+	DUK_ASSERT(stridx < DUK_HEAP_NUM_STRINGS);
+
+	rc = duk_get_prop_stridx(ctx, obj_index, stridx);
+	if (out_has_prop) {
+		*out_has_prop = rc;
+	}
+	rc = duk_to_boolean(ctx, -1);
+	DUK_ASSERT(rc == 0 || rc == 1);
+	duk_pop(ctx);
+	return rc;
+}
+
+DUK_LOCAL duk_bool_t duk__put_prop_shared(duk_context *ctx, duk_idx_t obj_idx, duk_idx_t idx_key) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_tval *tv_obj;
+	duk_tval *tv_key;
+	duk_tval *tv_val;
+	duk_small_int_t throw_flag;
+	duk_bool_t rc;
+
+	/* Note: copying tv_obj and tv_key to locals to shield against a valstack
+	 * resize is not necessary for a property put right now (putprop protects
+	 * against it internally).
+	 */
+
+	/* Key and value indices are either (-2, -1) or (-1, -2).  Given idx_key,
+	 * idx_val is always (idx_key ^ 0x01).
+	 */
+	DUK_ASSERT((idx_key == -2 && (idx_key ^ 1) == -1) ||
+	           (idx_key == -1 && (idx_key ^ 1) == -2));
+	tv_obj = duk_require_tval(ctx, obj_idx);
+	tv_key = duk_require_tval(ctx, idx_key);
+	tv_val = duk_require_tval(ctx, idx_key ^ 1);
+	throw_flag = duk_is_strict_call(ctx);
+
+	rc = duk_hobject_putprop(thr, tv_obj, tv_key, tv_val, throw_flag);
+	DUK_ASSERT(rc == 0 || rc == 1);
+
+	duk_pop_2(ctx);  /* remove key and value */
+	return rc;  /* 1 if property found, 0 otherwise */
+}
+
+DUK_EXTERNAL duk_bool_t duk_put_prop(duk_context *ctx, duk_idx_t obj_idx) {
+	DUK_ASSERT_CTX_VALID(ctx);
+	return duk__put_prop_shared(ctx, obj_idx, -2);
+}
+
+DUK_EXTERNAL duk_bool_t duk_put_prop_string(duk_context *ctx, duk_idx_t obj_idx, const char *key) {
+	DUK_ASSERT_CTX_VALID(ctx);
+	DUK_ASSERT(key != NULL);
+
+	/* Careful here and with other duk_put_prop_xxx() helpers: the
+	 * target object and the property value may be in the same value
+	 * stack slot (unusual, but still conceptually clear).
+	 */
+	obj_idx = duk_normalize_index(ctx, obj_idx);
+	(void) duk_push_string(ctx, key);
+	return duk__put_prop_shared(ctx, obj_idx, -1);
+}
+
+DUK_EXTERNAL duk_bool_t duk_put_prop_index(duk_context *ctx, duk_idx_t obj_idx, duk_uarridx_t arr_idx) {
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	obj_idx = duk_require_normalize_index(ctx, obj_idx);
+	duk_push_uarridx(ctx, arr_idx);
+	return duk__put_prop_shared(ctx, obj_idx, -1);
+}
+
+DUK_INTERNAL duk_bool_t duk_put_prop_stridx(duk_context *ctx, duk_idx_t obj_idx, duk_small_int_t stridx) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+	DUK_ASSERT_DISABLE(stridx >= 0);
+	DUK_ASSERT(stridx < DUK_HEAP_NUM_STRINGS);
+	DUK_UNREF(thr);
+
+	obj_idx = duk_require_normalize_index(ctx, obj_idx);
+	duk_push_hstring(ctx, DUK_HTHREAD_GET_STRING(thr, stridx));
+	return duk__put_prop_shared(ctx, obj_idx, -1);
+}
+
+DUK_EXTERNAL duk_bool_t duk_del_prop(duk_context *ctx, duk_idx_t obj_index) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_tval *tv_obj;
+	duk_tval *tv_key;
+	duk_small_int_t throw_flag;
+	duk_bool_t rc;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	/* Note: copying tv_obj and tv_key to locals to shield against a valstack
+	 * resize is not necessary for a property delete right now.
+	 */
+
+	tv_obj = duk_require_tval(ctx, obj_index);
+	tv_key = duk_require_tval(ctx, -1);
+	throw_flag = duk_is_strict_call(ctx);
+
+	rc = duk_hobject_delprop(thr, tv_obj, tv_key, throw_flag);
+	DUK_ASSERT(rc == 0 || rc == 1);
+
+	duk_pop(ctx);  /* remove key */
+	return rc;
+}
+
+DUK_EXTERNAL duk_bool_t duk_del_prop_string(duk_context *ctx, duk_idx_t obj_index, const char *key) {
+	DUK_ASSERT_CTX_VALID(ctx);
+	DUK_ASSERT(key != NULL);
+
+	obj_index = duk_require_normalize_index(ctx, obj_index);
+	duk_push_string(ctx, key);
+	return duk_del_prop(ctx, obj_index);
+}
+
+DUK_EXTERNAL duk_bool_t duk_del_prop_index(duk_context *ctx, duk_idx_t obj_index, duk_uarridx_t arr_index) {
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	obj_index = duk_require_normalize_index(ctx, obj_index);
+	duk_push_uarridx(ctx, arr_index);
+	return duk_del_prop(ctx, obj_index);
+}
+
+DUK_INTERNAL duk_bool_t duk_del_prop_stridx(duk_context *ctx, duk_idx_t obj_index, duk_small_int_t stridx) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+	DUK_ASSERT_DISABLE(stridx >= 0);
+	DUK_ASSERT(stridx < DUK_HEAP_NUM_STRINGS);
+	DUK_UNREF(thr);
+
+	obj_index = duk_require_normalize_index(ctx, obj_index);
+	duk_push_hstring(ctx, DUK_HTHREAD_GET_STRING(thr, stridx));
+	return duk_del_prop(ctx, obj_index);
+}
+
+DUK_EXTERNAL duk_bool_t duk_has_prop(duk_context *ctx, duk_idx_t obj_index) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_tval *tv_obj;
+	duk_tval *tv_key;
+	duk_bool_t rc;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	/* Note: copying tv_obj and tv_key to locals to shield against a valstack
+	 * resize is not necessary for a property existence check right now.
+	 */
+
+	tv_obj = duk_require_tval(ctx, obj_index);
+	tv_key = duk_require_tval(ctx, -1);
+
+	rc = duk_hobject_hasprop(thr, tv_obj, tv_key);
+	DUK_ASSERT(rc == 0 || rc == 1);
+
+	duk_pop(ctx);  /* remove key */
+	return rc;  /* 1 if property found, 0 otherwise */
+}
+
+DUK_EXTERNAL duk_bool_t duk_has_prop_string(duk_context *ctx, duk_idx_t obj_index, const char *key) {
+	DUK_ASSERT_CTX_VALID(ctx);
+	DUK_ASSERT(key != NULL);
+
+	obj_index = duk_require_normalize_index(ctx, obj_index);
+	duk_push_string(ctx, key);
+	return duk_has_prop(ctx, obj_index);
+}
+
+DUK_EXTERNAL duk_bool_t duk_has_prop_index(duk_context *ctx, duk_idx_t obj_index, duk_uarridx_t arr_index) {
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	obj_index = duk_require_normalize_index(ctx, obj_index);
+	duk_push_uarridx(ctx, arr_index);
+	return duk_has_prop(ctx, obj_index);
+}
+
+DUK_INTERNAL duk_bool_t duk_has_prop_stridx(duk_context *ctx, duk_idx_t obj_index, duk_small_int_t stridx) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+	DUK_ASSERT_DISABLE(stridx >= 0);
+	DUK_ASSERT(stridx < DUK_HEAP_NUM_STRINGS);
+	DUK_UNREF(thr);
+
+	obj_index = duk_require_normalize_index(ctx, obj_index);
+	duk_push_hstring(ctx, DUK_HTHREAD_GET_STRING(thr, stridx));
+	return duk_has_prop(ctx, obj_index);
+}
+
+/* Define own property without inheritance looks and such.  This differs from
+ * [[DefineOwnProperty]] because special behaviors (like Array 'length') are
+ * not invoked by this method.  The caller must be careful to invoke any such
+ * behaviors if necessary.
+ */
+DUK_INTERNAL void duk_xdef_prop(duk_context *ctx, duk_idx_t obj_index, duk_small_uint_t desc_flags) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_hobject *obj;
+	duk_hstring *key;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	obj = duk_require_hobject(ctx, obj_index);
+	DUK_ASSERT(obj != NULL);
+	key = duk_to_hstring(ctx, -2);
+	DUK_ASSERT(key != NULL);
+	DUK_ASSERT(duk_require_tval(ctx, -1) != NULL);
+
+	duk_hobject_define_property_internal(thr, obj, key, desc_flags);
+
+	duk_pop(ctx);  /* pop key */
+}
+
+DUK_INTERNAL void duk_xdef_prop_index(duk_context *ctx, duk_idx_t obj_index, duk_uarridx_t arr_index, duk_small_uint_t desc_flags) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_hobject *obj;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	obj = duk_require_hobject(ctx, obj_index);
+	DUK_ASSERT(obj != NULL);
+
+	duk_hobject_define_property_internal_arridx(thr, obj, arr_index, desc_flags);
+	/* value popped by call */
+}
+
+DUK_INTERNAL void duk_xdef_prop_stridx(duk_context *ctx, duk_idx_t obj_index, duk_small_int_t stridx, duk_small_uint_t desc_flags) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_hobject *obj;
+	duk_hstring *key;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+	DUK_ASSERT_DISABLE(stridx >= 0);
+	DUK_ASSERT(stridx < DUK_HEAP_NUM_STRINGS);
+
+	obj = duk_require_hobject(ctx, obj_index);
+	DUK_ASSERT(obj != NULL);
+	key = DUK_HTHREAD_GET_STRING(thr, stridx);
+	DUK_ASSERT(key != NULL);
+	DUK_ASSERT(duk_require_tval(ctx, -1) != NULL);
+
+	duk_hobject_define_property_internal(thr, obj, key, desc_flags);
+	/* value popped by call */
+}
+
+DUK_INTERNAL void duk_xdef_prop_stridx_builtin(duk_context *ctx, duk_idx_t obj_index, duk_small_int_t stridx, duk_small_int_t builtin_idx, duk_small_uint_t desc_flags) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_hobject *obj;
+	duk_hstring *key;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+	DUK_ASSERT_DISABLE(stridx >= 0);
+	DUK_ASSERT(stridx < DUK_HEAP_NUM_STRINGS);
+	DUK_ASSERT_DISABLE(builtin_idx >= 0);
+	DUK_ASSERT(builtin_idx < DUK_NUM_BUILTINS);
+
+	obj = duk_require_hobject(ctx, obj_index);
+	DUK_ASSERT(obj != NULL);
+	key = DUK_HTHREAD_GET_STRING(thr, stridx);
+	DUK_ASSERT(key != NULL);
+
+	duk_push_hobject(ctx, thr->builtins[builtin_idx]);
+	duk_hobject_define_property_internal(thr, obj, key, desc_flags);
+	/* value popped by call */
+}
+
+/* This is a rare property helper; it sets the global thrower (E5 Section 13.2.3)
+ * setter/getter into an object property.  This is needed by the 'arguments'
+ * object creation code, function instance creation code, and Function.prototype.bind().
+ */
+
+DUK_INTERNAL void duk_xdef_prop_stridx_thrower(duk_context *ctx, duk_idx_t obj_index, duk_small_int_t stridx, duk_small_uint_t desc_flags) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_hobject *obj = duk_require_hobject(ctx, obj_index);
+	duk_hobject *thrower = thr->builtins[DUK_BIDX_TYPE_ERROR_THROWER];
+	duk_hobject_define_accessor_internal(thr, obj, DUK_HTHREAD_GET_STRING(thr, stridx), thrower, thrower, desc_flags);
+}
+
+/* Object.defineProperty() equivalent C binding. */
+DUK_EXTERNAL void duk_def_prop(duk_context *ctx, duk_idx_t obj_index, duk_uint_t flags) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_idx_t idx_base;
+	duk_hobject *obj;
+	duk_hstring *key;
+	duk_idx_t idx_value;
+	duk_hobject *get;
+	duk_hobject *set;
+	duk_uint_t is_data_desc;
+	duk_uint_t is_acc_desc;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	obj = duk_require_hobject(ctx, obj_index);
+
+	is_data_desc = flags & (DUK_DEFPROP_HAVE_VALUE | DUK_DEFPROP_HAVE_WRITABLE);
+	is_acc_desc = flags & (DUK_DEFPROP_HAVE_GETTER | DUK_DEFPROP_HAVE_SETTER);
+	if (is_data_desc && is_acc_desc) {
+		/* "Have" flags must not be conflicting so that they would
+		 * apply to both a plain property and an accessor at the same
+		 * time.
+		 */
+		goto fail_invalid_desc;
+	}
+
+	idx_base = duk_get_top_index(ctx);
+	if (flags & DUK_DEFPROP_HAVE_SETTER) {
+		duk_require_type_mask(ctx, idx_base, DUK_TYPE_MASK_UNDEFINED |
+		                                     DUK_TYPE_MASK_OBJECT |
+		                                     DUK_TYPE_MASK_LIGHTFUNC);
+		set = duk_get_hobject_or_lfunc_coerce(ctx, idx_base);
+		if (set != NULL && !DUK_HOBJECT_IS_CALLABLE(set)) {
+			goto fail_not_callable;
+		}
+		idx_base--;
+	} else {
+		set = NULL;
+	}
+	if (flags & DUK_DEFPROP_HAVE_GETTER) {
+		duk_require_type_mask(ctx, idx_base, DUK_TYPE_MASK_UNDEFINED |
+		                                     DUK_TYPE_MASK_OBJECT |
+		                                     DUK_TYPE_MASK_LIGHTFUNC);
+		get = duk_get_hobject_or_lfunc_coerce(ctx, idx_base);
+		if (get != NULL && !DUK_HOBJECT_IS_CALLABLE(get)) {
+			goto fail_not_callable;
+		}
+		idx_base--;
+	} else {
+		get = NULL;
+	}
+	if (flags & DUK_DEFPROP_HAVE_VALUE) {
+		idx_value = idx_base;
+		idx_base--;
+	} else {
+		idx_value = (duk_idx_t) -1;
+	}
+	key = duk_require_hstring(ctx, idx_base);
+
+	duk_require_valid_index(ctx, idx_base);
+
+	duk_hobject_define_property_helper(ctx,
+	                                   flags /*defprop_flags*/,
+	                                   obj,
+	                                   key,
+	                                   idx_value,
+	                                   get,
+	                                   set);
+
+	/* Clean up stack */
+
+	duk_set_top(ctx, idx_base);
+
+	/* [ ... obj ... ] */
+
+	return;
+
+ fail_invalid_desc:
+	DUK_ERROR_TYPE(thr, DUK_STR_INVALID_DESCRIPTOR);
+	return;
+
+ fail_not_callable:
+	DUK_ERROR_TYPE(thr, DUK_STR_NOT_CALLABLE);
+	return;
+}
+
+/*
+ *  Object related
+ *
+ *  Note: seal() and freeze() are accessible through Ecmascript bindings,
+ *  and are not exposed through the API.
+ */
+
+DUK_EXTERNAL void duk_compact(duk_context *ctx, duk_idx_t obj_index) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_hobject *obj;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	obj = duk_get_hobject(ctx, obj_index);
+	if (obj) {
+		/* Note: this may fail, caller should protect the call if necessary */
+		duk_hobject_compact_props(thr, obj);
+	}
+}
+
+/* XXX: the duk_hobject_enum.c stack APIs should be reworked */
+
+DUK_EXTERNAL void duk_enum(duk_context *ctx, duk_idx_t obj_index, duk_uint_t enum_flags) {
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	duk_dup(ctx, obj_index);
+	duk_require_hobject_or_lfunc_coerce(ctx, -1);
+	duk_hobject_enumerator_create(ctx, enum_flags);   /* [target] -> [enum] */
+}
+
+DUK_EXTERNAL duk_bool_t duk_next(duk_context *ctx, duk_idx_t enum_index, duk_bool_t get_value) {
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	duk_require_hobject(ctx, enum_index);
+	duk_dup(ctx, enum_index);
+	return duk_hobject_enumerator_next(ctx, get_value);
+}
+
+/*
+ *  Helpers for writing multiple properties
+ */
+
+DUK_EXTERNAL void duk_put_function_list(duk_context *ctx, duk_idx_t obj_index, const duk_function_list_entry *funcs) {
+	const duk_function_list_entry *ent = funcs;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	obj_index = duk_require_normalize_index(ctx, obj_index);
+	if (ent != NULL) {
+		while (ent->key != NULL) {
+			duk_push_c_function(ctx, ent->value, ent->nargs);
+			duk_put_prop_string(ctx, obj_index, ent->key);
+			ent++;
+		}
+	}
+}
+
+DUK_EXTERNAL void duk_put_number_list(duk_context *ctx, duk_idx_t obj_index, const duk_number_list_entry *numbers) {
+	const duk_number_list_entry *ent = numbers;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	obj_index = duk_require_normalize_index(ctx, obj_index);
+	if (ent != NULL) {
+		while (ent->key != NULL) {
+			duk_push_number(ctx, ent->value);
+			duk_put_prop_string(ctx, obj_index, ent->key);
+			ent++;
+		}
+	}
+}
+
+/*
+ *  Shortcut for accessing global object properties
+ */
+
+DUK_EXTERNAL duk_bool_t duk_get_global_string(duk_context *ctx, const char *key) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_bool_t ret;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+	DUK_ASSERT(thr->builtins[DUK_BIDX_GLOBAL] != NULL);
+
+	/* XXX: direct implementation */
+
+	duk_push_hobject(ctx, thr->builtins[DUK_BIDX_GLOBAL]);
+	ret = duk_get_prop_string(ctx, -1, key);
+	duk_remove(ctx, -2);
+	return ret;
+}
+
+DUK_EXTERNAL duk_bool_t duk_put_global_string(duk_context *ctx, const char *key) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_bool_t ret;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+	DUK_ASSERT(thr->builtins[DUK_BIDX_GLOBAL] != NULL);
+
+	/* XXX: direct implementation */
+
+	duk_push_hobject(ctx, thr->builtins[DUK_BIDX_GLOBAL]);
+	duk_insert(ctx, -2);
+	ret = duk_put_prop_string(ctx, -2, key);  /* [ ... global val ] -> [ ... global ] */
+	duk_pop(ctx);
+	return ret;
+}
+
+/*
+ *  Object prototype
+ */
+
+DUK_EXTERNAL void duk_get_prototype(duk_context *ctx, duk_idx_t index) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_hobject *obj;
+	duk_hobject *proto;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+	DUK_UNREF(thr);
+
+	obj = duk_require_hobject(ctx, index);
+	DUK_ASSERT(obj != NULL);
+
+	/* XXX: shared helper for duk_push_hobject_or_undefined()? */
+	proto = DUK_HOBJECT_GET_PROTOTYPE(thr->heap, obj);
+	if (proto) {
+		duk_push_hobject(ctx, proto);
+	} else {
+		duk_push_undefined(ctx);
+	}
+}
+
+DUK_EXTERNAL void duk_set_prototype(duk_context *ctx, duk_idx_t index) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_hobject *obj;
+	duk_hobject *proto;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	obj = duk_require_hobject(ctx, index);
+	DUK_ASSERT(obj != NULL);
+	duk_require_type_mask(ctx, -1, DUK_TYPE_MASK_UNDEFINED |
+	                               DUK_TYPE_MASK_OBJECT);
+	proto = duk_get_hobject(ctx, -1);
+	/* proto can also be NULL here (allowed explicitly) */
+
+#if defined(DUK_USE_ROM_OBJECTS)
+	if (DUK_HEAPHDR_HAS_READONLY((duk_heaphdr *) obj)) {
+		DUK_ERROR_TYPE(thr, DUK_STR_NOT_CONFIGURABLE);  /* XXX: "read only object"? */
+		return;
+	}
+#endif
+
+	DUK_HOBJECT_SET_PROTOTYPE_UPDREF(thr, obj, proto);
+
+	duk_pop(ctx);
+}
+
+/*
+ *  Object finalizer
+ */
+
+/* XXX: these could be implemented as macros calling an internal function
+ * directly.
+ * XXX: same issue as with Duktape.fin: there's no way to delete the property
+ * now (just set it to undefined).
+ */
+DUK_EXTERNAL void duk_get_finalizer(duk_context *ctx, duk_idx_t index) {
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	duk_get_prop_stridx(ctx, index, DUK_STRIDX_INT_FINALIZER);
+}
+
+DUK_EXTERNAL void duk_set_finalizer(duk_context *ctx, duk_idx_t index) {
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	duk_put_prop_stridx(ctx, index, DUK_STRIDX_INT_FINALIZER);
+}


[11/51] [partial] nifi-minifi-cpp git commit: MINIFI-183 Added civet 1.9.1 sources Added onScheduled hook Added initial two-way TLS-enabled ListenHTTP implementation

Posted by al...@apache.org.
http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_bi_json.c
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_bi_json.c b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_bi_json.c
new file mode 100644
index 0000000..d05ccd9
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_bi_json.c
@@ -0,0 +1,3143 @@
+/*
+ *  JSON built-ins.
+ *
+ *  See doc/json.rst.
+ *
+ *  Codepoints are handled as duk_uint_fast32_t to ensure that the full
+ *  unsigned 32-bit range is supported.  This matters to e.g. JX.
+ *
+ *  Input parsing doesn't do an explicit end-of-input check at all.  This is
+ *  safe: input string data is always NUL-terminated (0x00) and valid JSON
+ *  inputs never contain plain NUL characters, so that as long as syntax checks
+ *  are correct, we'll never read past the NUL.  This approach reduces code size
+ *  and improves parsing performance, but it's critical that syntax checks are
+ *  indeed correct!
+ */
+
+#include "duk_internal.h"
+
+/*
+ *  Local defines and forward declarations.
+ */
+
+#define DUK__JSON_DECSTR_BUFSIZE 128
+#define DUK__JSON_DECSTR_CHUNKSIZE 64
+#define DUK__JSON_ENCSTR_CHUNKSIZE 64
+#define DUK__JSON_STRINGIFY_BUFSIZE 128
+#define DUK__JSON_MAX_ESC_LEN 10  /* '\Udeadbeef' */
+
+DUK_LOCAL_DECL void duk__dec_syntax_error(duk_json_dec_ctx *js_ctx);
+DUK_LOCAL_DECL void duk__dec_eat_white(duk_json_dec_ctx *js_ctx);
+DUK_LOCAL_DECL duk_uint8_t duk__dec_peek(duk_json_dec_ctx *js_ctx);
+DUK_LOCAL_DECL duk_uint8_t duk__dec_get(duk_json_dec_ctx *js_ctx);
+DUK_LOCAL_DECL duk_uint8_t duk__dec_get_nonwhite(duk_json_dec_ctx *js_ctx);
+DUK_LOCAL_DECL duk_uint_fast32_t duk__dec_decode_hex_escape(duk_json_dec_ctx *js_ctx, duk_small_uint_t n);
+DUK_LOCAL_DECL void duk__dec_req_stridx(duk_json_dec_ctx *js_ctx, duk_small_uint_t stridx);
+DUK_LOCAL_DECL void duk__dec_string(duk_json_dec_ctx *js_ctx);
+#ifdef DUK_USE_JX
+DUK_LOCAL_DECL void duk__dec_plain_string(duk_json_dec_ctx *js_ctx);
+DUK_LOCAL_DECL void duk__dec_pointer(duk_json_dec_ctx *js_ctx);
+DUK_LOCAL_DECL void duk__dec_buffer(duk_json_dec_ctx *js_ctx);
+#endif
+DUK_LOCAL_DECL void duk__dec_number(duk_json_dec_ctx *js_ctx);
+DUK_LOCAL_DECL void duk__dec_objarr_entry(duk_json_dec_ctx *js_ctx);
+DUK_LOCAL_DECL void duk__dec_objarr_exit(duk_json_dec_ctx *js_ctx);
+DUK_LOCAL_DECL void duk__dec_object(duk_json_dec_ctx *js_ctx);
+DUK_LOCAL_DECL void duk__dec_array(duk_json_dec_ctx *js_ctx);
+DUK_LOCAL_DECL void duk__dec_value(duk_json_dec_ctx *js_ctx);
+DUK_LOCAL_DECL void duk__dec_reviver_walk(duk_json_dec_ctx *js_ctx);
+
+DUK_LOCAL_DECL void duk__emit_1(duk_json_enc_ctx *js_ctx, duk_uint_fast8_t ch);
+DUK_LOCAL_DECL void duk__emit_2(duk_json_enc_ctx *js_ctx, duk_uint_fast8_t ch1, duk_uint_fast8_t ch2);
+DUK_LOCAL_DECL void duk__unemit_1(duk_json_enc_ctx *js_ctx);
+DUK_LOCAL_DECL void duk__emit_hstring(duk_json_enc_ctx *js_ctx, duk_hstring *h);
+#if defined(DUK_USE_FASTINT)
+DUK_LOCAL_DECL void duk__emit_cstring(duk_json_enc_ctx *js_ctx, const char *p);
+#endif
+DUK_LOCAL_DECL void duk__emit_stridx(duk_json_enc_ctx *js_ctx, duk_small_uint_t stridx);
+DUK_LOCAL_DECL duk_uint8_t *duk__emit_esc_auto_fast(duk_json_enc_ctx *js_ctx, duk_uint_fast32_t cp, duk_uint8_t *q);
+DUK_LOCAL_DECL void duk__enc_key_autoquote(duk_json_enc_ctx *js_ctx, duk_hstring *k);
+DUK_LOCAL_DECL void duk__enc_quote_string(duk_json_enc_ctx *js_ctx, duk_hstring *h_str);
+DUK_LOCAL_DECL void duk__enc_objarr_entry(duk_json_enc_ctx *js_ctx, duk_idx_t *entry_top);
+DUK_LOCAL_DECL void duk__enc_objarr_exit(duk_json_enc_ctx *js_ctx, duk_idx_t *entry_top);
+DUK_LOCAL_DECL void duk__enc_object(duk_json_enc_ctx *js_ctx);
+DUK_LOCAL_DECL void duk__enc_array(duk_json_enc_ctx *js_ctx);
+DUK_LOCAL_DECL duk_bool_t duk__enc_value(duk_json_enc_ctx *js_ctx, duk_idx_t idx_holder);
+DUK_LOCAL_DECL duk_bool_t duk__enc_allow_into_proplist(duk_tval *tv);
+DUK_LOCAL_DECL void duk__enc_double(duk_json_enc_ctx *js_ctx);
+#if defined(DUK_USE_FASTINT)
+DUK_LOCAL_DECL void duk__enc_fastint_tval(duk_json_enc_ctx *js_ctx, duk_tval *tv);
+#endif
+#if defined(DUK_USE_JX) || defined(DUK_USE_JC)
+DUK_LOCAL_DECL void duk__enc_buffer(duk_json_enc_ctx *js_ctx, duk_hbuffer *h);
+DUK_LOCAL_DECL void duk__enc_pointer(duk_json_enc_ctx *js_ctx, void *ptr);
+DUK_LOCAL_DECL void duk__enc_bufferobject(duk_json_enc_ctx *js_ctx, duk_hbufferobject *h_bufobj);
+#endif
+DUK_LOCAL_DECL void duk__enc_newline_indent(duk_json_enc_ctx *js_ctx, duk_int_t depth);
+
+/*
+ *  Helper tables
+ */
+
+#if defined(DUK_USE_JSON_QUOTESTRING_FASTPATH)
+DUK_LOCAL const duk_uint8_t duk__json_quotestr_lookup[256] = {
+	/* 0x00 ... 0x7f: as is
+	 * 0x80: escape generically
+	 * 0x81: slow path
+	 * 0xa0 ... 0xff: backslash + one char
+	 */
+
+	0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xe2, 0xf4, 0xee, 0x80, 0xe6, 0xf2, 0x80, 0x80,
+	0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
+	0x20, 0x21, 0xa2, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
+	0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
+	0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
+	0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0xdc, 0x5d, 0x5e, 0x5f,
+	0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
+	0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x81,
+	0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81,
+	0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81,
+	0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81,
+	0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81,
+	0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81,
+	0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81,
+	0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81,
+	0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81
+};
+#else  /* DUK_USE_JSON_QUOTESTRING_FASTPATH */
+DUK_LOCAL const duk_uint8_t duk__json_quotestr_esc[14] = {
+	DUK_ASC_NUL, DUK_ASC_NUL, DUK_ASC_NUL, DUK_ASC_NUL,
+	DUK_ASC_NUL, DUK_ASC_NUL, DUK_ASC_NUL, DUK_ASC_NUL,
+	DUK_ASC_LC_B, DUK_ASC_LC_T, DUK_ASC_LC_N, DUK_ASC_NUL,
+	DUK_ASC_LC_F, DUK_ASC_LC_R
+};
+#endif  /* DUK_USE_JSON_QUOTESTRING_FASTPATH */
+
+#if defined(DUK_USE_JSON_DECSTRING_FASTPATH)
+DUK_LOCAL const duk_uint8_t duk__json_decstr_lookup[256] = {
+	/* 0x00: slow path
+	 * other: as is
+	 */
+	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+	0x20, 0x21, 0x00, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
+	0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
+	0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
+	0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0x00, 0x5d, 0x5e, 0x5f,
+	0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
+	0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
+	0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
+	0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
+	0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
+	0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
+	0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
+	0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
+	0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
+	0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
+};
+#endif  /* DUK_USE_JSON_DECSTRING_FASTPATH */
+
+#if defined(DUK_USE_JSON_EATWHITE_FASTPATH)
+DUK_LOCAL const duk_uint8_t duk__json_eatwhite_lookup[256] = {
+	/* 0x00: finish (non-white)
+	 * 0x01: continue
+	 */
+	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00,
+	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+	0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
+};
+#endif  /* DUK_USE_JSON_EATWHITE_FASTPATH */
+
+#if defined(DUK_USE_JSON_DECNUMBER_FASTPATH)
+DUK_LOCAL const duk_uint8_t duk__json_decnumber_lookup[256] = {
+	/* 0x00: finish (not part of number)
+	 * 0x01: continue
+	 */
+	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x01, 0x00,
+	0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+	0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+	0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
+};
+#endif  /* DUK_USE_JSON_DECNUMBER_FASTPATH */
+
+/*
+ *  Parsing implementation.
+ *
+ *  JSON lexer is now separate from duk_lexer.c because there are numerous
+ *  small differences making it difficult to share the lexer.
+ *
+ *  The parser here works with raw bytes directly; this works because all
+ *  JSON delimiters are ASCII characters.  Invalid xUTF-8 encoded values
+ *  inside strings will be passed on without normalization; this is not a
+ *  compliance concern because compliant inputs will always be valid
+ *  CESU-8 encodings.
+ */
+
+DUK_LOCAL void duk__dec_syntax_error(duk_json_dec_ctx *js_ctx) {
+	/* Shared handler to minimize parser size.  Cause will be
+	 * hidden, unfortunately, but we'll have an offset which
+	 * is often quite enough.
+	 */
+	DUK_ERROR_FMT1(js_ctx->thr, DUK_ERR_SYNTAX_ERROR, DUK_STR_FMT_INVALID_JSON,
+	               (long) (js_ctx->p - js_ctx->p_start));
+}
+
+DUK_LOCAL void duk__dec_eat_white(duk_json_dec_ctx *js_ctx) {
+	const duk_uint8_t *p;
+	duk_uint8_t t;
+
+	p = js_ctx->p;
+	for (;;) {
+		DUK_ASSERT(p <= js_ctx->p_end);
+		t = *p;
+
+#if defined(DUK_USE_JSON_EATWHITE_FASTPATH)
+		/* This fast path is pretty marginal in practice.
+		 * XXX: candidate for removal.
+		 */
+		DUK_ASSERT(duk__json_eatwhite_lookup[0x00] == 0x00);  /* end-of-input breaks */
+		if (duk__json_eatwhite_lookup[t] == 0) {
+			break;
+		}
+#else  /* DUK_USE_JSON_EATWHITE_FASTPATH */
+		if (!(t == 0x20 || t == 0x0a || t == 0x0d || t == 0x09)) {
+			/* NUL also comes here.  Comparison order matters, 0x20
+			 * is most common whitespace.
+			 */
+			break;
+		}
+#endif  /* DUK_USE_JSON_EATWHITE_FASTPATH */
+		p++;
+	}
+	js_ctx->p = p;
+}
+
+DUK_LOCAL duk_uint8_t duk__dec_peek(duk_json_dec_ctx *js_ctx) {
+	DUK_ASSERT(js_ctx->p <= js_ctx->p_end);
+	return *js_ctx->p;
+}
+
+DUK_LOCAL duk_uint8_t duk__dec_get(duk_json_dec_ctx *js_ctx) {
+	DUK_ASSERT(js_ctx->p <= js_ctx->p_end);
+	return *js_ctx->p++;
+}
+
+DUK_LOCAL duk_uint8_t duk__dec_get_nonwhite(duk_json_dec_ctx *js_ctx) {
+	duk__dec_eat_white(js_ctx);
+	return duk__dec_get(js_ctx);
+}
+
+/* For JX, expressing the whole unsigned 32-bit range matters. */
+DUK_LOCAL duk_uint_fast32_t duk__dec_decode_hex_escape(duk_json_dec_ctx *js_ctx, duk_small_uint_t n) {
+	duk_small_uint_t i;
+	duk_uint_fast32_t res = 0;
+	duk_uint8_t x;
+	duk_small_int_t t;
+
+	for (i = 0; i < n; i++) {
+		/* XXX: share helper from lexer; duk_lexer.c / hexval(). */
+
+		x = duk__dec_get(js_ctx);
+		DUK_DDD(DUK_DDDPRINT("decode_hex_escape: i=%ld, n=%ld, res=%ld, x=%ld",
+		                     (long) i, (long) n, (long) res, (long) x));
+
+		/* x == 0x00 (EOF) causes syntax_error */
+		DUK_ASSERT(duk_hex_dectab[0] == -1);
+		t = duk_hex_dectab[x & 0xff];
+		if (DUK_LIKELY(t >= 0)) {
+			res = (res * 16) + t;
+		} else {
+			/* catches EOF and invalid digits */
+			goto syntax_error;
+		}
+	}
+
+	DUK_DDD(DUK_DDDPRINT("final hex decoded value: %ld", (long) res));
+	return res;
+
+ syntax_error:
+	duk__dec_syntax_error(js_ctx);
+	DUK_UNREACHABLE();
+	return 0;
+}
+
+DUK_LOCAL void duk__dec_req_stridx(duk_json_dec_ctx *js_ctx, duk_small_uint_t stridx) {
+	duk_hstring *h;
+	const duk_uint8_t *p;
+	duk_uint8_t x, y;
+
+	/* First character has already been eaten and checked by the caller.
+	 * We can scan until a NUL in stridx string because no built-in strings
+	 * have internal NULs.
+	 */
+
+	DUK_ASSERT_DISABLE(stridx >= 0);  /* unsigned */
+	DUK_ASSERT(stridx < DUK_HEAP_NUM_STRINGS);
+	h = DUK_HTHREAD_GET_STRING(js_ctx->thr, stridx);
+	DUK_ASSERT(h != NULL);
+
+	p = (const duk_uint8_t *) DUK_HSTRING_GET_DATA(h) + 1;
+	DUK_ASSERT(*(js_ctx->p - 1) == *(p - 1));  /* first character has been matched */
+
+	for (;;) {
+		x = *p;
+		if (x == 0) {
+			break;
+		}
+		y = duk__dec_get(js_ctx);
+		if (x != y) {
+			/* Catches EOF of JSON input. */
+			goto syntax_error;
+		}
+		p++;
+	}
+
+	return;
+
+ syntax_error:
+	duk__dec_syntax_error(js_ctx);
+	DUK_UNREACHABLE();
+}
+
+DUK_LOCAL duk_small_int_t duk__dec_string_escape(duk_json_dec_ctx *js_ctx, duk_uint8_t **ext_p) {
+	duk_uint_fast32_t cp;
+
+	/* EOF (-1) will be cast to an unsigned value first
+	 * and then re-cast for the switch.  In any case, it
+	 * will match the default case (syntax error).
+	 */
+	cp = (duk_uint_fast32_t) duk__dec_get(js_ctx);
+	switch ((int) cp) {
+	case DUK_ASC_BACKSLASH: break;
+	case DUK_ASC_DOUBLEQUOTE: break;
+	case DUK_ASC_SLASH: break;
+	case DUK_ASC_LC_T: cp = 0x09; break;
+	case DUK_ASC_LC_N: cp = 0x0a; break;
+	case DUK_ASC_LC_R: cp = 0x0d; break;
+	case DUK_ASC_LC_F: cp = 0x0c; break;
+	case DUK_ASC_LC_B: cp = 0x08; break;
+	case DUK_ASC_LC_U: {
+		cp = duk__dec_decode_hex_escape(js_ctx, 4);
+		break;
+	}
+#ifdef DUK_USE_JX
+	case DUK_ASC_UC_U: {
+		if (js_ctx->flag_ext_custom) {
+			cp = duk__dec_decode_hex_escape(js_ctx, 8);
+		} else {
+			return 1;  /* syntax error */
+		}
+		break;
+	}
+	case DUK_ASC_LC_X: {
+		if (js_ctx->flag_ext_custom) {
+			cp = duk__dec_decode_hex_escape(js_ctx, 2);
+		} else {
+			return 1;  /* syntax error */
+		}
+		break;
+	}
+#endif  /* DUK_USE_JX */
+	default:
+		/* catches EOF (0x00) */
+		return 1;  /* syntax error */
+	}
+
+	DUK_RAW_WRITE_XUTF8(*ext_p, cp);
+
+	return 0;
+}
+
+DUK_LOCAL void duk__dec_string(duk_json_dec_ctx *js_ctx) {
+	duk_hthread *thr = js_ctx->thr;
+	duk_context *ctx = (duk_context *) thr;
+	duk_bufwriter_ctx bw_alloc;
+	duk_bufwriter_ctx *bw;
+	duk_uint8_t *q;
+
+	/* '"' was eaten by caller */
+
+	/* Note that we currently parse -bytes-, not codepoints.
+	 * All non-ASCII extended UTF-8 will encode to bytes >= 0x80,
+	 * so they'll simply pass through (valid UTF-8 or not).
+	 */
+
+	bw = &bw_alloc;
+	DUK_BW_INIT_PUSHBUF(js_ctx->thr, bw, DUK__JSON_DECSTR_BUFSIZE);
+	q = DUK_BW_GET_PTR(js_ctx->thr, bw);
+
+#if defined(DUK_USE_JSON_DECSTRING_FASTPATH)
+	for (;;) {
+		duk_small_uint_t safe;
+		duk_uint8_t b, x;
+		const duk_uint8_t *p;
+
+		/* Select a safe loop count where no output checks are
+		 * needed assuming we won't encounter escapes.  Input
+		 * bound checks are not necessary as a NUL (guaranteed)
+		 * will cause a SyntaxError before we read out of bounds.
+		 */
+
+		safe = DUK__JSON_DECSTR_CHUNKSIZE;
+
+		/* Ensure space for 1:1 output plus one escape. */
+		q = DUK_BW_ENSURE_RAW(js_ctx->thr, bw, safe + DUK_UNICODE_MAX_XUTF8_LENGTH, q);
+
+		p = js_ctx->p;  /* temp copy, write back for next loop */
+		for (;;) {
+			if (safe == 0) {
+				js_ctx->p = p;
+				break;
+			}
+			safe--;
+
+			/* End of input (NUL) goes through slow path and causes SyntaxError. */
+			DUK_ASSERT(duk__json_decstr_lookup[0] == 0x00);
+
+			b = *p++;
+			x = (duk_small_int_t) duk__json_decstr_lookup[b];
+			if (DUK_LIKELY(x != 0)) {
+				/* Fast path, decode as is. */
+				*q++ = b;
+			} else if (b == DUK_ASC_DOUBLEQUOTE) {
+				js_ctx->p = p;
+				goto found_quote;
+			} else if (b == DUK_ASC_BACKSLASH) {
+				/* We've ensured space for one escaped input; then
+				 * bail out and recheck (this makes escape handling
+				 * quite slow but it's uncommon).
+				 */
+				js_ctx->p = p;
+				if (duk__dec_string_escape(js_ctx, &q) != 0) {
+					goto syntax_error;
+				}
+				break;
+			} else {
+				js_ctx->p = p;
+				goto syntax_error;
+			}
+		}
+	}
+ found_quote:
+#else  /* DUK_USE_JSON_DECSTRING_FASTPATH */
+	for (;;) {
+		duk_uint8_t x;
+
+		q = DUK_BW_ENSURE_RAW(js_ctx->thr, bw, DUK_UNICODE_MAX_XUTF8_LENGTH, q);
+
+		x = duk__dec_get(js_ctx);
+
+		if (x == DUK_ASC_DOUBLEQUOTE) {
+			break;
+		} else if (x == DUK_ASC_BACKSLASH) {
+			if (duk__dec_string_escape(js_ctx, &q) != 0) {
+				goto syntax_error;
+			}
+		} else if (x < 0x20) {
+			/* catches EOF (NUL) */
+			goto syntax_error;
+		} else {
+			*q++ = (duk_uint8_t) x;
+		}
+	}
+#endif  /* DUK_USE_JSON_DECSTRING_FASTPATH */
+
+	DUK_BW_SETPTR_AND_COMPACT(js_ctx->thr, bw, q);
+	duk_to_string(ctx, -1);
+
+	/* [ ... str ] */
+
+	return;
+
+ syntax_error:
+	duk__dec_syntax_error(js_ctx);
+	DUK_UNREACHABLE();
+}
+
+#ifdef DUK_USE_JX
+/* Decode a plain string consisting entirely of identifier characters.
+ * Used to parse plain keys (e.g. "foo: 123").
+ */
+DUK_LOCAL void duk__dec_plain_string(duk_json_dec_ctx *js_ctx) {
+	duk_hthread *thr = js_ctx->thr;
+	duk_context *ctx = (duk_context *) thr;
+	const duk_uint8_t *p;
+	duk_small_int_t x;
+
+	/* Caller has already eaten the first char so backtrack one byte. */
+
+	js_ctx->p--;  /* safe */
+	p = js_ctx->p;
+
+	/* Here again we parse bytes, and non-ASCII UTF-8 will cause end of
+	 * parsing (which is correct except if there are non-shortest encodings).
+	 * There is also no need to check explicitly for end of input buffer as
+	 * the input is NUL padded and NUL will exit the parsing loop.
+	 *
+	 * Because no unescaping takes place, we can just scan to the end of the
+	 * plain string and intern from the input buffer.
+	 */
+
+	for (;;) {
+		x = *p;
+
+		/* There is no need to check the first character specially here
+		 * (i.e. reject digits): the caller only accepts valid initial
+		 * characters and won't call us if the first character is a digit.
+		 * This also ensures that the plain string won't be empty.
+		 */
+
+		if (!duk_unicode_is_identifier_part((duk_codepoint_t) x)) {
+			break;
+		}
+		p++;
+	}
+
+	duk_push_lstring(ctx, (const char *) js_ctx->p, (duk_size_t) (p - js_ctx->p));
+	js_ctx->p = p;
+
+	/* [ ... str ] */
+}
+#endif  /* DUK_USE_JX */
+
+#ifdef DUK_USE_JX
+DUK_LOCAL void duk__dec_pointer(duk_json_dec_ctx *js_ctx) {
+	duk_hthread *thr = js_ctx->thr;
+	duk_context *ctx = (duk_context *) thr;
+	const duk_uint8_t *p;
+	duk_small_int_t x;
+	void *voidptr;
+
+	/* Caller has already eaten the first character ('(') which we don't need. */
+
+	p = js_ctx->p;
+
+	for (;;) {
+		x = *p;
+
+		/* Assume that the native representation never contains a closing
+		 * parenthesis.
+		 */
+
+		if (x == DUK_ASC_RPAREN) {
+			break;
+		} else if (x <= 0) {
+			/* NUL term or -1 (EOF), NUL check would suffice */
+			goto syntax_error;
+		}
+		p++;
+	}
+
+	/* There is no need to NUL delimit the sscanf() call: trailing garbage is
+	 * ignored and there is always a NUL terminator which will force an error
+	 * if no error is encountered before it.  It's possible that the scan
+	 * would scan further than between [js_ctx->p,p[ though and we'd advance
+	 * by less than the scanned value.
+	 *
+	 * Because pointers are platform specific, a failure to scan a pointer
+	 * results in a null pointer which is a better placeholder than a missing
+	 * value or an error.
+	 */
+
+	voidptr = NULL;
+	(void) DUK_SSCANF((const char *) js_ctx->p, DUK_STR_FMT_PTR, &voidptr);
+	duk_push_pointer(ctx, voidptr);
+	js_ctx->p = p + 1;  /* skip ')' */
+
+	/* [ ... ptr ] */
+
+	return;
+
+ syntax_error:
+	duk__dec_syntax_error(js_ctx);
+	DUK_UNREACHABLE();
+}
+#endif  /* DUK_USE_JX */
+
+#ifdef DUK_USE_JX
+DUK_LOCAL void duk__dec_buffer(duk_json_dec_ctx *js_ctx) {
+	duk_hthread *thr = js_ctx->thr;
+	duk_context *ctx = (duk_context *) thr;
+	const duk_uint8_t *p;
+	duk_uint8_t *buf;
+	duk_size_t src_len;
+	duk_small_int_t x;
+
+	/* Caller has already eaten the first character ('|') which we don't need. */
+
+	p = js_ctx->p;
+
+	/* XXX: Would be nice to share the fast path loop from duk_hex_decode()
+	 * and avoid creating a temporary buffer.  However, there are some
+	 * differences which prevent trivial sharing:
+	 *
+	 *   - Pipe char detection
+	 *   - EOF detection
+	 *   - Unknown length of input and output
+	 *
+	 * The best approach here would be a bufwriter and a reasonaly sized
+	 * safe inner loop (e.g. 64 output bytes at a time).
+	 */
+
+	for (;;) {
+		x = *p;
+
+		/* This loop intentionally does not ensure characters are valid
+		 * ([0-9a-fA-F]) because the hex decode call below will do that.
+		 */
+		if (x == DUK_ASC_PIPE) {
+			break;
+		} else if (x <= 0) {
+			/* NUL term or -1 (EOF), NUL check would suffice */
+			goto syntax_error;
+		}
+		p++;
+	}
+
+	src_len = (duk_size_t) (p - js_ctx->p);
+	buf = (duk_uint8_t *) duk_push_fixed_buffer(ctx, src_len);
+	DUK_ASSERT(buf != NULL);
+	DUK_MEMCPY((void *) buf, (const void *) js_ctx->p, src_len);
+	duk_hex_decode(ctx, -1);
+
+	js_ctx->p = p + 1;  /* skip '|' */
+
+	/* [ ... buf ] */
+
+	return;
+
+ syntax_error:
+	duk__dec_syntax_error(js_ctx);
+	DUK_UNREACHABLE();
+}
+#endif  /* DUK_USE_JX */
+
+/* Parse a number, other than NaN or +/- Infinity */
+DUK_LOCAL void duk__dec_number(duk_json_dec_ctx *js_ctx) {
+	duk_context *ctx = (duk_context *) js_ctx->thr;
+	const duk_uint8_t *p_start;
+	const duk_uint8_t *p;
+	duk_uint8_t x;
+	duk_small_uint_t s2n_flags;
+
+	DUK_DDD(DUK_DDDPRINT("parse_number"));
+
+	p_start = js_ctx->p;
+
+	/* First pass parse is very lenient (e.g. allows '1.2.3') and extracts a
+	 * string for strict number parsing.
+	 */
+
+	p = js_ctx->p;
+	for (;;) {
+		x = *p;
+
+		DUK_DDD(DUK_DDDPRINT("parse_number: p_start=%p, p=%p, p_end=%p, x=%ld",
+		                     (const void *) p_start, (const void *) p,
+		                     (const void *) js_ctx->p_end, (long) x));
+
+#if defined(DUK_USE_JSON_DECNUMBER_FASTPATH)
+		/* This fast path is pretty marginal in practice.
+		 * XXX: candidate for removal.
+		 */
+		DUK_ASSERT(duk__json_decnumber_lookup[0x00] == 0x00);  /* end-of-input breaks */
+		if (duk__json_decnumber_lookup[x] == 0) {
+			break;
+		}
+#else  /* DUK_USE_JSON_DECNUMBER_FASTPATH */
+		if (!((x >= DUK_ASC_0 && x <= DUK_ASC_9) ||
+		      (x == DUK_ASC_PERIOD || x == DUK_ASC_LC_E ||
+		       x == DUK_ASC_UC_E || x == DUK_ASC_MINUS || x == DUK_ASC_PLUS))) {
+			/* Plus sign must be accepted for positive exponents
+			 * (e.g. '1.5e+2').  This clause catches NULs.
+			 */
+			break;
+		}
+#endif  /* DUK_USE_JSON_DECNUMBER_FASTPATH */
+		p++;  /* safe, because matched (NUL causes a break) */
+	}
+	js_ctx->p = p;
+
+	DUK_ASSERT(js_ctx->p > p_start);
+	duk_push_lstring(ctx, (const char *) p_start, (duk_size_t) (p - p_start));
+
+	s2n_flags = DUK_S2N_FLAG_ALLOW_EXP |
+	            DUK_S2N_FLAG_ALLOW_MINUS |  /* but don't allow leading plus */
+	            DUK_S2N_FLAG_ALLOW_FRAC;
+
+	DUK_DDD(DUK_DDDPRINT("parse_number: string before parsing: %!T",
+	                     (duk_tval *) duk_get_tval(ctx, -1)));
+	duk_numconv_parse(ctx, 10 /*radix*/, s2n_flags);
+	if (duk_is_nan(ctx, -1)) {
+		duk__dec_syntax_error(js_ctx);
+	}
+	DUK_ASSERT(duk_is_number(ctx, -1));
+	DUK_DDD(DUK_DDDPRINT("parse_number: final number: %!T",
+	                     (duk_tval *) duk_get_tval(ctx, -1)));
+
+	/* [ ... num ] */
+}
+
+DUK_LOCAL void duk__dec_objarr_entry(duk_json_dec_ctx *js_ctx) {
+	duk_context *ctx = (duk_context *) js_ctx->thr;
+	duk_require_stack(ctx, DUK_JSON_DEC_REQSTACK);
+
+	/* c recursion check */
+
+	DUK_ASSERT(js_ctx->recursion_depth >= 0);
+	DUK_ASSERT(js_ctx->recursion_depth <= js_ctx->recursion_limit);
+	if (js_ctx->recursion_depth >= js_ctx->recursion_limit) {
+		DUK_ERROR_RANGE((duk_hthread *) ctx, DUK_STR_JSONDEC_RECLIMIT);
+	}
+	js_ctx->recursion_depth++;
+}
+
+DUK_LOCAL void duk__dec_objarr_exit(duk_json_dec_ctx *js_ctx) {
+	/* c recursion check */
+
+	DUK_ASSERT(js_ctx->recursion_depth > 0);
+	DUK_ASSERT(js_ctx->recursion_depth <= js_ctx->recursion_limit);
+	js_ctx->recursion_depth--;
+}
+
+DUK_LOCAL void duk__dec_object(duk_json_dec_ctx *js_ctx) {
+	duk_context *ctx = (duk_context *) js_ctx->thr;
+	duk_int_t key_count;  /* XXX: a "first" flag would suffice */
+	duk_uint8_t x;
+
+	DUK_DDD(DUK_DDDPRINT("parse_object"));
+
+	duk__dec_objarr_entry(js_ctx);
+
+	duk_push_object(ctx);
+
+	/* Initial '{' has been checked and eaten by caller. */
+
+	key_count = 0;
+	for (;;) {
+		x = duk__dec_get_nonwhite(js_ctx);
+
+		DUK_DDD(DUK_DDDPRINT("parse_object: obj=%!T, x=%ld, key_count=%ld",
+		                     (duk_tval *) duk_get_tval(ctx, -1),
+		                     (long) x, (long) key_count));
+
+		/* handle comma and closing brace */
+
+		if (x == DUK_ASC_COMMA && key_count > 0) {
+			/* accept comma, expect new value */
+			x = duk__dec_get_nonwhite(js_ctx);
+		} else if (x == DUK_ASC_RCURLY) {
+			/* eat closing brace */
+			break;
+		} else if (key_count == 0) {
+			/* accept anything, expect first value (EOF will be
+			 * caught by key parsing below.
+			 */
+			;
+		} else {
+			/* catches EOF (NUL) and initial comma */
+			goto syntax_error;
+		}
+
+		/* parse key and value */
+
+		if (x == DUK_ASC_DOUBLEQUOTE) {
+			duk__dec_string(js_ctx);
+#ifdef DUK_USE_JX
+		} else if (js_ctx->flag_ext_custom &&
+		           duk_unicode_is_identifier_start((duk_codepoint_t) x)) {
+			duk__dec_plain_string(js_ctx);
+#endif
+		} else {
+			goto syntax_error;
+		}
+
+		/* [ ... obj key ] */
+
+		x = duk__dec_get_nonwhite(js_ctx);
+		if (x != DUK_ASC_COLON) {
+			goto syntax_error;
+		}
+
+		duk__dec_value(js_ctx);
+
+		/* [ ... obj key val ] */
+
+		duk_xdef_prop_wec(ctx, -3);
+
+		/* [ ... obj ] */
+
+		key_count++;
+	}
+
+	/* [ ... obj ] */
+
+	DUK_DDD(DUK_DDDPRINT("parse_object: final object is %!T",
+	                     (duk_tval *) duk_get_tval(ctx, -1)));
+
+	duk__dec_objarr_exit(js_ctx);
+	return;
+
+ syntax_error:
+	duk__dec_syntax_error(js_ctx);
+	DUK_UNREACHABLE();
+}
+
+DUK_LOCAL void duk__dec_array(duk_json_dec_ctx *js_ctx) {
+	duk_context *ctx = (duk_context *) js_ctx->thr;
+	duk_uarridx_t arr_idx;
+	duk_uint8_t x;
+
+	DUK_DDD(DUK_DDDPRINT("parse_array"));
+
+	duk__dec_objarr_entry(js_ctx);
+
+	duk_push_array(ctx);
+
+	/* Initial '[' has been checked and eaten by caller. */
+
+	arr_idx = 0;
+	for (;;) {
+		x = duk__dec_get_nonwhite(js_ctx);
+
+		DUK_DDD(DUK_DDDPRINT("parse_array: arr=%!T, x=%ld, arr_idx=%ld",
+		                     (duk_tval *) duk_get_tval(ctx, -1),
+		                     (long) x, (long) arr_idx));
+
+		/* handle comma and closing bracket */
+
+		if ((x == DUK_ASC_COMMA) && (arr_idx != 0)) {
+			/* accept comma, expect new value */
+			;
+		} else if (x == DUK_ASC_RBRACKET) {
+			/* eat closing bracket */
+			break;
+		} else if (arr_idx == 0) {
+			/* accept anything, expect first value (EOF will be
+			 * caught by duk__dec_value() below.
+			 */
+			js_ctx->p--;  /* backtrack (safe) */
+		} else {
+			/* catches EOF (NUL) and initial comma */
+			goto syntax_error;
+		}
+
+		/* parse value */
+
+		duk__dec_value(js_ctx);
+
+		/* [ ... arr val ] */
+
+		duk_xdef_prop_index_wec(ctx, -2, arr_idx);
+		arr_idx++;
+	}
+
+	/* Must set 'length' explicitly when using duk_xdef_prop_xxx() to
+	 * set the values.
+	 */
+
+	duk_set_length(ctx, -1, arr_idx);
+
+	/* [ ... arr ] */
+
+	DUK_DDD(DUK_DDDPRINT("parse_array: final array is %!T",
+	                     (duk_tval *) duk_get_tval(ctx, -1)));
+
+	duk__dec_objarr_exit(js_ctx);
+	return;
+
+ syntax_error:
+	duk__dec_syntax_error(js_ctx);
+	DUK_UNREACHABLE();
+}
+
+DUK_LOCAL void duk__dec_value(duk_json_dec_ctx *js_ctx) {
+	duk_context *ctx = (duk_context *) js_ctx->thr;
+	duk_uint8_t x;
+
+	x = duk__dec_get_nonwhite(js_ctx);
+
+	DUK_DDD(DUK_DDDPRINT("parse_value: initial x=%ld", (long) x));
+
+	/* Note: duk__dec_req_stridx() backtracks one char */
+
+	if (x == DUK_ASC_DOUBLEQUOTE) {
+		duk__dec_string(js_ctx);
+	} else if ((x >= DUK_ASC_0 && x <= DUK_ASC_9) || (x == DUK_ASC_MINUS)) {
+#ifdef DUK_USE_JX
+		if (js_ctx->flag_ext_custom && x == DUK_ASC_MINUS && duk__dec_peek(js_ctx) == DUK_ASC_UC_I) {
+			duk__dec_req_stridx(js_ctx, DUK_STRIDX_MINUS_INFINITY);  /* "-Infinity", '-' has been eaten */
+			duk_push_number(ctx, -DUK_DOUBLE_INFINITY);
+		} else {
+#else
+		{  /* unconditional block */
+#endif
+			/* We already ate 'x', so backup one byte. */
+			js_ctx->p--;  /* safe */
+			duk__dec_number(js_ctx);
+		}
+	} else if (x == DUK_ASC_LC_T) {
+		duk__dec_req_stridx(js_ctx, DUK_STRIDX_TRUE);
+		duk_push_true(ctx);
+	} else if (x == DUK_ASC_LC_F) {
+		duk__dec_req_stridx(js_ctx, DUK_STRIDX_FALSE);
+		duk_push_false(ctx);
+	} else if (x == DUK_ASC_LC_N) {
+		duk__dec_req_stridx(js_ctx, DUK_STRIDX_LC_NULL);
+		duk_push_null(ctx);
+#ifdef DUK_USE_JX
+	} else if (js_ctx->flag_ext_custom && x == DUK_ASC_LC_U) {
+		duk__dec_req_stridx(js_ctx, DUK_STRIDX_LC_UNDEFINED);
+		duk_push_undefined(ctx);
+	} else if (js_ctx->flag_ext_custom && x == DUK_ASC_UC_N) {
+		duk__dec_req_stridx(js_ctx, DUK_STRIDX_NAN);
+		duk_push_nan(ctx);
+	} else if (js_ctx->flag_ext_custom && x == DUK_ASC_UC_I) {
+		duk__dec_req_stridx(js_ctx, DUK_STRIDX_INFINITY);
+		duk_push_number(ctx, DUK_DOUBLE_INFINITY);
+	} else if (js_ctx->flag_ext_custom && x == DUK_ASC_LPAREN) {
+		duk__dec_pointer(js_ctx);
+	} else if (js_ctx->flag_ext_custom && x == DUK_ASC_PIPE) {
+		duk__dec_buffer(js_ctx);
+#endif
+	} else if (x == DUK_ASC_LCURLY) {
+		duk__dec_object(js_ctx);
+	} else if (x == DUK_ASC_LBRACKET) {
+		duk__dec_array(js_ctx);
+	} else {
+		/* catches EOF (NUL) */
+		goto syntax_error;
+	}
+
+	duk__dec_eat_white(js_ctx);
+
+	/* [ ... val ] */
+	return;
+
+ syntax_error:
+	duk__dec_syntax_error(js_ctx);
+	DUK_UNREACHABLE();
+}
+
+/* Recursive value reviver, implements the Walk() algorithm.  No C recursion
+ * check is done here because the initial parsing step will already ensure
+ * there is a reasonable limit on C recursion depth and hence object depth.
+ */
+DUK_LOCAL void duk__dec_reviver_walk(duk_json_dec_ctx *js_ctx) {
+	duk_context *ctx = (duk_context *) js_ctx->thr;
+	duk_hobject *h;
+	duk_uarridx_t i, arr_len;
+
+	DUK_DDD(DUK_DDDPRINT("walk: top=%ld, holder=%!T, name=%!T",
+	                     (long) duk_get_top(ctx),
+	                     (duk_tval *) duk_get_tval(ctx, -2),
+	                     (duk_tval *) duk_get_tval(ctx, -1)));
+
+	duk_dup_top(ctx);
+	duk_get_prop(ctx, -3);  /* -> [ ... holder name val ] */
+
+	h = duk_get_hobject(ctx, -1);
+	if (h != NULL) {
+		if (DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_ARRAY) {
+			arr_len = (duk_uarridx_t) duk_get_length(ctx, -1);
+			for (i = 0; i < arr_len; i++) {
+				/* [ ... holder name val ] */
+
+				DUK_DDD(DUK_DDDPRINT("walk: array, top=%ld, i=%ld, arr_len=%ld, holder=%!T, name=%!T, val=%!T",
+				                     (long) duk_get_top(ctx), (long) i, (long) arr_len,
+				                     (duk_tval *) duk_get_tval(ctx, -3), (duk_tval *) duk_get_tval(ctx, -2),
+				                     (duk_tval *) duk_get_tval(ctx, -1)));
+
+				/* XXX: push_uint_string / push_u32_string */
+				duk_dup_top(ctx);
+				duk_push_uint(ctx, (duk_uint_t) i);
+				duk_to_string(ctx, -1);  /* -> [ ... holder name val val ToString(i) ] */
+				duk__dec_reviver_walk(js_ctx);  /* -> [ ... holder name val new_elem ] */
+
+				if (duk_is_undefined(ctx, -1)) {
+					duk_pop(ctx);
+					duk_del_prop_index(ctx, -1, i);
+				} else {
+					/* XXX: duk_xdef_prop_index_wec() would be more appropriate
+					 * here but it currently makes some assumptions that might
+					 * not hold (e.g. that previous property is not an accessor).
+					 */
+					duk_put_prop_index(ctx, -2, i);
+				}
+			}
+		} else {
+			/* [ ... holder name val ] */
+			duk_enum(ctx, -1, DUK_ENUM_OWN_PROPERTIES_ONLY /*flags*/);
+			while (duk_next(ctx, -1 /*enum_index*/, 0 /*get_value*/)) {
+				DUK_DDD(DUK_DDDPRINT("walk: object, top=%ld, holder=%!T, name=%!T, val=%!T, enum=%!iT, obj_key=%!T",
+				                     (long) duk_get_top(ctx), (duk_tval *) duk_get_tval(ctx, -5),
+				                     (duk_tval *) duk_get_tval(ctx, -4), (duk_tval *) duk_get_tval(ctx, -3),
+				                     (duk_tval *) duk_get_tval(ctx, -2), (duk_tval *) duk_get_tval(ctx, -1)));
+
+				/* [ ... holder name val enum obj_key ] */
+				duk_dup(ctx, -3);
+				duk_dup(ctx, -2);
+
+				/* [ ... holder name val enum obj_key val obj_key ] */
+				duk__dec_reviver_walk(js_ctx);
+
+				/* [ ... holder name val enum obj_key new_elem ] */
+				if (duk_is_undefined(ctx, -1)) {
+					duk_pop(ctx);
+					duk_del_prop(ctx, -3);
+				} else {
+					/* XXX: duk_xdef_prop_index_wec() would be more appropriate
+					 * here but it currently makes some assumptions that might
+					 * not hold (e.g. that previous property is not an accessor).
+					 *
+					 * Using duk_put_prop() works incorrectly with '__proto__'
+					 * if the own property with that name has been deleted.  This
+					 * does not happen normally, but a clever reviver can trigger
+					 * that, see complex reviver case in: test-bug-json-parse-__proto__.js.
+					 */
+					duk_put_prop(ctx, -4);
+				}
+			}
+			duk_pop(ctx);  /* pop enum */
+		}
+	}
+
+	/* [ ... holder name val ] */
+
+	duk_dup(ctx, js_ctx->idx_reviver);
+	duk_insert(ctx, -4);  /* -> [ ... reviver holder name val ] */
+	duk_call_method(ctx, 2);  /* -> [ ... res ] */
+
+	DUK_DDD(DUK_DDDPRINT("walk: top=%ld, result=%!T",
+	                     (long) duk_get_top(ctx), (duk_tval *) duk_get_tval(ctx, -1)));
+}
+
+/*
+ *  Stringify implementation.
+ */
+
+#define DUK__EMIT_1(js_ctx,ch)          duk__emit_1((js_ctx), (duk_uint_fast8_t) (ch))
+#define DUK__EMIT_2(js_ctx,ch1,ch2)     duk__emit_2((js_ctx), (duk_uint_fast8_t) (ch1), (duk_uint_fast8_t) (ch2))
+#define DUK__EMIT_HSTR(js_ctx,h)        duk__emit_hstring((js_ctx), (h))
+#if defined(DUK_USE_FASTINT) || defined(DUK_USE_JX) || defined(DUK_USE_JC)
+#define DUK__EMIT_CSTR(js_ctx,p)        duk__emit_cstring((js_ctx), (p))
+#endif
+#define DUK__EMIT_STRIDX(js_ctx,i)      duk__emit_stridx((js_ctx), (i))
+#define DUK__UNEMIT_1(js_ctx)           duk__unemit_1((js_ctx))
+
+DUK_LOCAL void duk__emit_1(duk_json_enc_ctx *js_ctx, duk_uint_fast8_t ch) {
+	DUK_BW_WRITE_ENSURE_U8(js_ctx->thr, &js_ctx->bw, ch);
+}
+
+DUK_LOCAL void duk__emit_2(duk_json_enc_ctx *js_ctx, duk_uint_fast8_t ch1, duk_uint_fast8_t ch2) {
+	DUK_BW_WRITE_ENSURE_U8_2(js_ctx->thr, &js_ctx->bw, ch1, ch2);
+}
+
+DUK_LOCAL void duk__emit_hstring(duk_json_enc_ctx *js_ctx, duk_hstring *h) {
+	DUK_BW_WRITE_ENSURE_HSTRING(js_ctx->thr, &js_ctx->bw, h);
+}
+
+#if defined(DUK_USE_FASTINT) || defined(DUK_USE_JX) || defined(DUK_USE_JC)
+DUK_LOCAL void duk__emit_cstring(duk_json_enc_ctx *js_ctx, const char *str) {
+	DUK_BW_WRITE_ENSURE_CSTRING(js_ctx->thr, &js_ctx->bw, str);
+}
+#endif
+
+DUK_LOCAL void duk__emit_stridx(duk_json_enc_ctx *js_ctx, duk_small_uint_t stridx) {
+	duk_hstring *h;
+
+	DUK_ASSERT_DISABLE(stridx >= 0);  /* unsigned */
+	DUK_ASSERT(stridx < DUK_HEAP_NUM_STRINGS);
+	h = DUK_HTHREAD_GET_STRING(js_ctx->thr, stridx);
+	DUK_ASSERT(h != NULL);
+
+	DUK_BW_WRITE_ENSURE_HSTRING(js_ctx->thr, &js_ctx->bw, h);
+}
+
+DUK_LOCAL void duk__unemit_1(duk_json_enc_ctx *js_ctx) {
+	DUK_ASSERT(DUK_BW_GET_SIZE(js_ctx->thr, &js_ctx->bw) >= 1);
+	DUK_BW_ADD_PTR(js_ctx->thr, &js_ctx->bw, -1);
+}
+
+#define DUK__MKESC(nybbles,esc1,esc2)  \
+	(((duk_uint_fast32_t) (nybbles)) << 16) | \
+	(((duk_uint_fast32_t) (esc1)) << 8) | \
+	((duk_uint_fast32_t) (esc2))
+
+DUK_LOCAL duk_uint8_t *duk__emit_esc_auto_fast(duk_json_enc_ctx *js_ctx, duk_uint_fast32_t cp, duk_uint8_t *q) {
+	duk_uint_fast32_t tmp;
+	duk_small_uint_t dig;
+
+	DUK_UNREF(js_ctx);
+
+	/* Caller ensures space for at least DUK__JSON_MAX_ESC_LEN. */
+
+	/* Select appropriate escape format automatically, and set 'tmp' to a
+	 * value encoding both the escape format character and the nybble count:
+	 *
+	 *   (nybble_count << 16) | (escape_char1) | (escape_char2)
+	 */
+
+#ifdef DUK_USE_JX
+	if (DUK_LIKELY(cp < 0x100UL)) {
+		if (DUK_UNLIKELY(js_ctx->flag_ext_custom)) {
+			tmp = DUK__MKESC(2, DUK_ASC_BACKSLASH, DUK_ASC_LC_X);
+		} else {
+			tmp = DUK__MKESC(4, DUK_ASC_BACKSLASH, DUK_ASC_LC_U);
+		}
+	} else
+#endif
+	if (DUK_LIKELY(cp < 0x10000UL)) {
+		tmp = DUK__MKESC(4, DUK_ASC_BACKSLASH, DUK_ASC_LC_U);
+	} else {
+#ifdef DUK_USE_JX
+		if (DUK_LIKELY(js_ctx->flag_ext_custom)) {
+			tmp = DUK__MKESC(8, DUK_ASC_BACKSLASH, DUK_ASC_UC_U);
+		} else
+#endif
+		{
+			/* In compatible mode and standard JSON mode, output
+			 * something useful for non-BMP characters.  This won't
+			 * roundtrip but will still be more or less readable and
+			 * more useful than an error.
+			 */
+			tmp = DUK__MKESC(8, DUK_ASC_UC_U, DUK_ASC_PLUS);
+		}
+	}
+
+	*q++ = (duk_uint8_t) ((tmp >> 8) & 0xff);
+	*q++ = (duk_uint8_t) (tmp & 0xff);
+
+	tmp = tmp >> 16;
+	while (tmp > 0) {
+		tmp--;
+		dig = (duk_small_uint_t) ((cp >> (4 * tmp)) & 0x0f);
+		*q++ = duk_lc_digits[dig];
+	}
+
+	return q;
+}
+
+DUK_LOCAL void duk__enc_key_autoquote(duk_json_enc_ctx *js_ctx, duk_hstring *k) {
+	const duk_int8_t *p, *p_start, *p_end;  /* Note: intentionally signed. */
+	duk_size_t k_len;
+	duk_codepoint_t cp;
+
+	DUK_ASSERT(k != NULL);
+
+	/* Accept ASCII strings which conform to identifier requirements
+	 * as being emitted without key quotes.  Since we only accept ASCII
+	 * there's no need for actual decoding: 'p' is intentionally signed
+	 * so that bytes >= 0x80 extend to negative values and are rejected
+	 * as invalid identifier codepoints.
+	 */
+
+	if (js_ctx->flag_avoid_key_quotes) {
+		k_len = DUK_HSTRING_GET_BYTELEN(k);
+		p_start = (const duk_int8_t *) DUK_HSTRING_GET_DATA(k);
+		p_end = p_start + k_len;
+		p = p_start;
+
+		if (p == p_end) {
+			/* Zero length string is not accepted without quotes */
+			goto quote_normally;
+		}
+		cp = (duk_codepoint_t) (*p++);
+		if (DUK_UNLIKELY(!duk_unicode_is_identifier_start(cp))) {
+			goto quote_normally;
+		}
+		while (p < p_end) {
+			cp = (duk_codepoint_t) (*p++);
+			if (DUK_UNLIKELY(!duk_unicode_is_identifier_part(cp))) {
+				goto quote_normally;
+			}
+		}
+
+		/* This seems faster than emitting bytes one at a time and
+		 * then potentially rewinding.
+		 */
+		DUK__EMIT_HSTR(js_ctx, k);
+		return;
+	}
+
+ quote_normally:
+	duk__enc_quote_string(js_ctx, k);
+}
+
+/* The Quote(value) operation: quote a string.
+ *
+ * Stack policy: [ ] -> [ ].
+ */
+
+DUK_LOCAL void duk__enc_quote_string(duk_json_enc_ctx *js_ctx, duk_hstring *h_str) {
+	duk_hthread *thr = js_ctx->thr;
+	const duk_uint8_t *p, *p_start, *p_end, *p_now, *p_tmp;
+	duk_uint8_t *q;
+	duk_ucodepoint_t cp;  /* typed for duk_unicode_decode_xutf8() */
+
+	DUK_DDD(DUK_DDDPRINT("duk__enc_quote_string: h_str=%!O", (duk_heaphdr *) h_str));
+
+	DUK_ASSERT(h_str != NULL);
+	p_start = DUK_HSTRING_GET_DATA(h_str);
+	p_end = p_start + DUK_HSTRING_GET_BYTELEN(h_str);
+	p = p_start;
+
+	DUK__EMIT_1(js_ctx, DUK_ASC_DOUBLEQUOTE);
+
+	/* Encode string in small chunks, estimating the maximum expansion so that
+	 * there's no need to ensure space while processing the chunk.
+	 */
+
+	while (p < p_end) {
+		duk_size_t left, now, space;
+
+		left = (duk_size_t) (p_end - p);
+		now = (left > DUK__JSON_ENCSTR_CHUNKSIZE ?
+		       DUK__JSON_ENCSTR_CHUNKSIZE : left);
+
+		/* Maximum expansion per input byte is 6:
+		 *   - invalid UTF-8 byte causes "\uXXXX" to be emitted (6/1 = 6).
+		 *   - 2-byte UTF-8 encodes as "\uXXXX" (6/2 = 3).
+		 *   - 4-byte UTF-8 encodes as "\Uxxxxxxxx" (10/4 = 2.5).
+		 */
+		space = now * 6;
+		q = DUK_BW_ENSURE_GETPTR(thr, &js_ctx->bw, space);
+
+		p_now = p + now;
+
+		while (p < p_now) {
+#if defined(DUK_USE_JSON_QUOTESTRING_FASTPATH)
+			duk_uint8_t b;
+
+			b = duk__json_quotestr_lookup[*p++];
+			if (DUK_LIKELY(b < 0x80)) {
+				/* Most input bytes go through here. */
+				*q++ = b;
+			} else if (b >= 0xa0) {
+				*q++ = DUK_ASC_BACKSLASH;
+				*q++ = (duk_uint8_t) (b - 0x80);
+			} else if (b == 0x80) {
+				cp = (duk_ucodepoint_t) (*(p - 1));
+				q = duk__emit_esc_auto_fast(js_ctx, cp, q);
+			} else if (b == 0x7f && js_ctx->flag_ascii_only) {
+				/* 0x7F is special */
+				DUK_ASSERT(b == 0x81);
+				cp = (duk_ucodepoint_t) 0x7f;
+				q = duk__emit_esc_auto_fast(js_ctx, cp, q);
+			} else {
+				DUK_ASSERT(b == 0x81);
+				p--;
+
+				/* slow path is shared */
+#else  /* DUK_USE_JSON_QUOTESTRING_FASTPATH */
+			cp = *p;
+
+			if (DUK_LIKELY(cp <= 0x7f)) {
+				/* ascii fast path: avoid decoding utf-8 */
+				p++;
+				if (cp == 0x22 || cp == 0x5c) {
+					/* double quote or backslash */
+					*q++ = DUK_ASC_BACKSLASH;
+					*q++ = (duk_uint8_t) cp;
+				} else if (cp < 0x20) {
+					duk_uint_fast8_t esc_char;
+
+					/* This approach is a bit shorter than a straight
+					 * if-else-ladder and also a bit faster.
+					 */
+					if (cp < (sizeof(duk__json_quotestr_esc) / sizeof(duk_uint8_t)) &&
+					    (esc_char = duk__json_quotestr_esc[cp]) != 0) {
+						*q++ = DUK_ASC_BACKSLASH;
+						*q++ = (duk_uint8_t) esc_char;
+					} else {
+						q = duk__emit_esc_auto_fast(js_ctx, cp, q);
+					}
+				} else if (cp == 0x7f && js_ctx->flag_ascii_only) {
+					q = duk__emit_esc_auto_fast(js_ctx, cp, q);
+				} else {
+					/* any other printable -> as is */
+					*q++ = (duk_uint8_t) cp;
+				}
+			} else {
+				/* slow path is shared */
+#endif  /* DUK_USE_JSON_QUOTESTRING_FASTPATH */
+
+				/* slow path decode */
+
+				/* If XUTF-8 decoding fails, treat the offending byte as a codepoint directly
+				 * and go forward one byte.  This is of course very lossy, but allows some kind
+				 * of output to be produced even for internal strings which don't conform to
+				 * XUTF-8.  All standard Ecmascript strings are always CESU-8, so this behavior
+				 * does not violate the Ecmascript specification.  The behavior is applied to
+				 * all modes, including Ecmascript standard JSON.  Because the current XUTF-8
+				 * decoding is not very strict, this behavior only really affects initial bytes
+				 * and truncated codepoints.
+				 *
+				 * Another alternative would be to scan forwards to start of next codepoint
+				 * (or end of input) and emit just one replacement codepoint.
+				 */
+
+				p_tmp = p;
+				if (!duk_unicode_decode_xutf8(thr, &p, p_start, p_end, &cp)) {
+					/* Decode failed. */
+					cp = *p_tmp;
+					p = p_tmp + 1;
+				}
+
+#ifdef DUK_USE_NONSTD_JSON_ESC_U2028_U2029
+				if (js_ctx->flag_ascii_only || cp == 0x2028 || cp == 0x2029) {
+#else
+				if (js_ctx->flag_ascii_only) {
+#endif
+					q = duk__emit_esc_auto_fast(js_ctx, cp, q);
+				} else {
+					/* as is */
+					DUK_RAW_WRITE_XUTF8(q, cp);
+				}
+			}
+		}
+
+		DUK_BW_SET_PTR(thr, &js_ctx->bw, q);
+	}
+
+	DUK__EMIT_1(js_ctx, DUK_ASC_DOUBLEQUOTE);
+}
+
+/* Encode a double (checked by caller) from stack top.  Stack top may be
+ * replaced by serialized string but is not popped (caller does that).
+ */
+DUK_LOCAL void duk__enc_double(duk_json_enc_ctx *js_ctx) {
+	duk_hthread *thr;
+	duk_context *ctx;
+	duk_tval *tv;
+	duk_double_t d;
+	duk_small_int_t c;
+	duk_small_int_t s;
+	duk_small_uint_t stridx;
+	duk_small_uint_t n2s_flags;
+	duk_hstring *h_str;
+
+	DUK_ASSERT(js_ctx != NULL);
+	thr = js_ctx->thr;
+	DUK_ASSERT(thr != NULL);
+	ctx = (duk_context *) thr;
+
+	/* Caller must ensure 'tv' is indeed a double and not a fastint! */
+	tv = DUK_GET_TVAL_NEGIDX(ctx, -1);
+	DUK_ASSERT(DUK_TVAL_IS_DOUBLE(tv));
+	d = DUK_TVAL_GET_DOUBLE(tv);
+
+	c = (duk_small_int_t) DUK_FPCLASSIFY(d);
+	s = (duk_small_int_t) DUK_SIGNBIT(d);
+	DUK_UNREF(s);
+
+	if (DUK_LIKELY(!(c == DUK_FP_INFINITE || c == DUK_FP_NAN))) {
+		DUK_ASSERT(DUK_ISFINITE(d));
+
+#if defined(DUK_USE_JX) || defined(DUK_USE_JC)
+		/* Negative zero needs special handling in JX/JC because
+		 * it would otherwise serialize to '0', not '-0'.
+		 */
+		if (DUK_UNLIKELY(c == DUK_FP_ZERO && s != 0 &&
+		                 (js_ctx->flag_ext_custom_or_compatible))) {
+			duk_push_hstring_stridx(ctx, DUK_STRIDX_MINUS_ZERO);  /* '-0' */
+		} else
+#endif  /* DUK_USE_JX || DUK_USE_JC */
+		{
+			n2s_flags = 0;
+			/* [ ... number ] -> [ ... string ] */
+			duk_numconv_stringify(ctx, 10 /*radix*/, 0 /*digits*/, n2s_flags);
+		}
+		h_str = duk_to_hstring(ctx, -1);
+		DUK_ASSERT(h_str != NULL);
+		DUK__EMIT_HSTR(js_ctx, h_str);
+		return;
+	}
+
+#if defined(DUK_USE_JX) || defined(DUK_USE_JC)
+	if (!(js_ctx->flags & (DUK_JSON_FLAG_EXT_CUSTOM |
+	                       DUK_JSON_FLAG_EXT_COMPATIBLE))) {
+		stridx = DUK_STRIDX_LC_NULL;
+	} else if (c == DUK_FP_NAN) {
+		stridx = js_ctx->stridx_custom_nan;
+	} else if (s == 0) {
+		stridx = js_ctx->stridx_custom_posinf;
+	} else {
+		stridx = js_ctx->stridx_custom_neginf;
+	}
+#else
+	stridx = DUK_STRIDX_LC_NULL;
+#endif
+	DUK__EMIT_STRIDX(js_ctx, stridx);
+}
+
+#if defined(DUK_USE_FASTINT)
+/* Encode a fastint from duk_tval ptr, no value stack effects. */
+DUK_LOCAL void duk__enc_fastint_tval(duk_json_enc_ctx *js_ctx, duk_tval *tv) {
+	duk_int64_t v;
+
+	/* Fastint range is signed 48-bit so longest value is -2^47 = -140737488355328
+	 * (16 chars long), longest signed 64-bit value is -2^63 = -9223372036854775808
+	 * (20 chars long).  Alloc space for 64-bit range to be safe.
+	 */
+	duk_uint8_t buf[20 + 1];
+
+	/* Caller must ensure 'tv' is indeed a fastint! */
+	DUK_ASSERT(DUK_TVAL_IS_FASTINT(tv));
+	v = DUK_TVAL_GET_FASTINT(tv);
+
+	/* XXX: There are no format strings in duk_config.h yet, could add
+	 * one for formatting duk_int64_t.  For now, assumes "%lld" and that
+	 * "long long" type exists.  Could also rely on C99 directly but that
+	 * won't work for older MSVC.
+	 */
+	DUK_SPRINTF((char *) buf, "%lld", (long long) v);
+	DUK__EMIT_CSTR(js_ctx, (const char *) buf);
+}
+#endif
+
+#if defined(DUK_USE_JX) || defined(DUK_USE_JC)
+#if defined(DUK_USE_HEX_FASTPATH)
+DUK_LOCAL duk_uint8_t *duk__enc_buffer_data_hex(const duk_uint8_t *src, duk_size_t src_len, duk_uint8_t *dst) {
+	duk_uint8_t *q;
+	duk_uint16_t *q16;
+	duk_small_uint_t x;
+	duk_size_t i, len_safe;
+#if !defined(DUK_USE_UNALIGNED_ACCESSES_POSSIBLE)
+	duk_bool_t shift_dst;
+#endif
+
+	/* Unlike in duk_hex_encode() 'dst' is not necessarily aligned by 2.
+	 * For platforms where unaligned accesses are not allowed, shift 'dst'
+	 * ahead by 1 byte to get alignment and then DUK_MEMMOVE() the result
+	 * in place.  The faster encoding loop makes up the difference.
+	 * There's always space for one extra byte because a terminator always
+	 * follows the hex data and that's been accounted for by the caller.
+	 */
+
+#if defined(DUK_USE_UNALIGNED_ACCESSES_POSSIBLE)
+	q16 = (duk_uint16_t *) (void *) dst;
+#else
+	shift_dst = (duk_bool_t) (((duk_size_t) dst) & 0x01U);
+	if (shift_dst) {
+		DUK_DD(DUK_DDPRINT("unaligned accesses not possible, dst not aligned -> step to dst + 1"));
+		q16 = (duk_uint16_t *) (void *) (dst + 1);
+	} else {
+		DUK_DD(DUK_DDPRINT("unaligned accesses not possible, dst is aligned"));
+		q16 = (duk_uint16_t *) (void *) dst;
+	}
+	DUK_ASSERT((((duk_size_t) q16) & 0x01U) == 0);
+#endif
+
+	len_safe = src_len & ~0x03U;
+	for (i = 0; i < len_safe; i += 4) {
+		q16[0] = duk_hex_enctab[src[i]];
+		q16[1] = duk_hex_enctab[src[i + 1]];
+		q16[2] = duk_hex_enctab[src[i + 2]];
+		q16[3] = duk_hex_enctab[src[i + 3]];
+		q16 += 4;
+	}
+	q = (duk_uint8_t *) q16;
+
+#if !defined(DUK_USE_UNALIGNED_ACCESSES_POSSIBLE)
+	if (shift_dst) {
+		q--;
+		DUK_MEMMOVE((void *) dst, (const void *) (dst + 1), 2 * len_safe);
+		DUK_ASSERT(dst + 2 * len_safe == q);
+	}
+#endif
+
+	for (; i < src_len; i++) {
+		x = src[i];
+		*q++ = duk_lc_digits[x >> 4];
+		*q++ = duk_lc_digits[x & 0x0f];
+	}
+
+	return q;
+}
+#else  /* DUK_USE_HEX_FASTPATH */
+DUK_LOCAL duk_uint8_t *duk__enc_buffer_data_hex(const duk_uint8_t *src, duk_size_t src_len, duk_uint8_t *dst) {
+	const duk_uint8_t *p;
+	const duk_uint8_t *p_end;
+	duk_uint8_t *q;
+	duk_small_uint_t x;
+
+	p = src;
+	p_end = src + src_len;
+	q = dst;
+	while (p != p_end) {
+		x = *p++;
+		*q++ = duk_lc_digits[x >> 4];
+		*q++ = duk_lc_digits[x & 0x0f];
+	}
+
+	return q;
+}
+#endif  /* DUK_USE_HEX_FASTPATH */
+
+DUK_LOCAL void duk__enc_buffer_data(duk_json_enc_ctx *js_ctx, duk_uint8_t *buf_data, duk_size_t buf_len) {
+	duk_hthread *thr;
+	duk_uint8_t *q;
+	duk_size_t space;
+
+	thr = js_ctx->thr;
+
+	DUK_ASSERT(js_ctx->flag_ext_custom || js_ctx->flag_ext_compatible);  /* caller checks */
+	DUK_ASSERT(js_ctx->flag_ext_custom_or_compatible);
+
+	/* Buffer values are encoded in (lowercase) hex to make the
+	 * binary data readable.  Base64 or similar would be more
+	 * compact but less readable, and the point of JX/JC
+	 * variants is to be as useful to a programmer as possible.
+	 */
+
+	/* The #ifdef clutter here needs to handle the three cases:
+	 * (1) JX+JC, (2) JX only, (3) JC only.
+	 */
+
+	/* Note: space must cater for both JX and JC. */
+	space = 9 + buf_len * 2 + 2;
+	DUK_ASSERT(DUK_HBUFFER_MAX_BYTELEN <= 0x7ffffffeUL);
+	DUK_ASSERT((space - 2) / 2 >= buf_len);  /* overflow not possible, buffer limits */
+	q = DUK_BW_ENSURE_GETPTR(thr, &js_ctx->bw, space);
+
+#if defined(DUK_USE_JX) && defined(DUK_USE_JC)
+	if (js_ctx->flag_ext_custom)
+#endif
+#if defined(DUK_USE_JX)
+	{
+		*q++ = DUK_ASC_PIPE;
+		q = duk__enc_buffer_data_hex(buf_data, buf_len, q);
+		*q++ = DUK_ASC_PIPE;
+
+	}
+#endif
+#if defined(DUK_USE_JX) && defined(DUK_USE_JC)
+	else
+#endif
+#if defined(DUK_USE_JC)
+	{
+		DUK_ASSERT(js_ctx->flag_ext_compatible);
+		DUK_MEMCPY((void *) q, (const void *) "{\"_buf\":\"", 9);  /* len: 9 */
+		q += 9;
+		q = duk__enc_buffer_data_hex(buf_data, buf_len, q);
+		*q++ = DUK_ASC_DOUBLEQUOTE;
+		*q++ = DUK_ASC_RCURLY;
+	}
+#endif
+
+	DUK_BW_SET_PTR(thr, &js_ctx->bw, q);
+}
+
+DUK_LOCAL void duk__enc_buffer(duk_json_enc_ctx *js_ctx, duk_hbuffer *h) {
+	duk__enc_buffer_data(js_ctx,
+	                     (duk_uint8_t *) DUK_HBUFFER_GET_DATA_PTR(js_ctx->thr->heap, h),
+	                     (duk_size_t) DUK_HBUFFER_GET_SIZE(h));
+}
+#endif  /* DUK_USE_JX || DUK_USE_JC */
+
+#if defined(DUK_USE_JX) || defined(DUK_USE_JC)
+DUK_LOCAL void duk__enc_pointer(duk_json_enc_ctx *js_ctx, void *ptr) {
+	char buf[64];  /* XXX: how to figure correct size? */
+	const char *fmt;
+
+	DUK_ASSERT(js_ctx->flag_ext_custom || js_ctx->flag_ext_compatible);  /* caller checks */
+	DUK_ASSERT(js_ctx->flag_ext_custom_or_compatible);
+
+	DUK_MEMZERO(buf, sizeof(buf));
+
+	/* The #ifdef clutter here needs to handle the three cases:
+	 * (1) JX+JC, (2) JX only, (3) JC only.
+	 */
+#if defined(DUK_USE_JX) && defined(DUK_USE_JC)
+	if (js_ctx->flag_ext_custom)
+#endif
+#if defined(DUK_USE_JX)
+	{
+		fmt = ptr ? "(%p)" : "(null)";
+	}
+#endif
+#if defined(DUK_USE_JX) && defined(DUK_USE_JC)
+	else
+#endif
+#if defined(DUK_USE_JC)
+	{
+		DUK_ASSERT(js_ctx->flag_ext_compatible);
+		fmt = ptr ? "{\"_ptr\":\"%p\"}" : "{\"_ptr\":\"null\"}";
+	}
+#endif
+
+	/* When ptr == NULL, the format argument is unused. */
+	DUK_SNPRINTF(buf, sizeof(buf) - 1, fmt, ptr);  /* must not truncate */
+	DUK__EMIT_CSTR(js_ctx, buf);
+}
+#endif  /* DUK_USE_JX || DUK_USE_JC */
+
+#if defined(DUK_USE_JX) || defined(DUK_USE_JC)
+DUK_LOCAL void duk__enc_bufferobject(duk_json_enc_ctx *js_ctx, duk_hbufferobject *h_bufobj) {
+	DUK_ASSERT_HBUFFEROBJECT_VALID(h_bufobj);
+
+	if (h_bufobj->buf == NULL || !DUK_HBUFFEROBJECT_VALID_SLICE(h_bufobj)) {
+		DUK__EMIT_STRIDX(js_ctx, DUK_STRIDX_LC_NULL);
+	} else {
+		/* Handle both full and partial slice (as long as covered). */
+		duk__enc_buffer_data(js_ctx,
+		                     (duk_uint8_t *) DUK_HBUFFEROBJECT_GET_SLICE_BASE(js_ctx->thr->heap, h_bufobj),
+		                     (duk_size_t) h_bufobj->length);
+	}
+}
+#endif  /* DUK_USE_JX || DUK_USE_JC */
+
+/* Indent helper.  Calling code relies on js_ctx->recursion_depth also being
+ * directly related to indent depth.
+ */
+#if defined(DUK_USE_PREFER_SIZE)
+DUK_LOCAL void duk__enc_newline_indent(duk_json_enc_ctx *js_ctx, duk_int_t depth) {
+	DUK_ASSERT(js_ctx->h_gap != NULL);
+	DUK_ASSERT(DUK_HSTRING_GET_BYTELEN(js_ctx->h_gap) > 0);  /* caller guarantees */
+
+	DUK__EMIT_1(js_ctx, 0x0a);
+	while (depth-- > 0) {
+		DUK__EMIT_HSTR(js_ctx, js_ctx->h_gap);
+	}
+}
+#else  /* DUK_USE_PREFER_SIZE */
+DUK_LOCAL void duk__enc_newline_indent(duk_json_enc_ctx *js_ctx, duk_int_t depth) {
+	const duk_uint8_t *gap_data;
+	duk_size_t gap_len;
+	duk_size_t avail_bytes;   /* bytes of indent available for copying */
+	duk_size_t need_bytes;    /* bytes of indent still needed */
+	duk_uint8_t *p_start;
+	duk_uint8_t *p;
+
+	DUK_ASSERT(js_ctx->h_gap != NULL);
+	DUK_ASSERT(DUK_HSTRING_GET_BYTELEN(js_ctx->h_gap) > 0);  /* caller guarantees */
+
+	DUK__EMIT_1(js_ctx, 0x0a);
+	if (DUK_UNLIKELY(depth == 0)) {
+		return;
+	}
+
+	/* To handle deeper indents efficiently, make use of copies we've
+	 * already emitted.  In effect we can emit a sequence of 1, 2, 4,
+	 * 8, etc copies, and then finish the last run.  Byte counters
+	 * avoid multiply with gap_len on every loop.
+	 */
+
+	gap_data = (const duk_uint8_t *) DUK_HSTRING_GET_DATA(js_ctx->h_gap);
+	gap_len = (duk_size_t) DUK_HSTRING_GET_BYTELEN(js_ctx->h_gap);
+	DUK_ASSERT(gap_len > 0);
+
+	need_bytes = gap_len * depth;
+	p = DUK_BW_ENSURE_GETPTR(js_ctx->thr, &js_ctx->bw, need_bytes);
+	p_start = p;
+
+	DUK_MEMCPY((void *) p, (const void *) gap_data, (size_t) gap_len);
+	p += gap_len;
+	avail_bytes = gap_len;
+	DUK_ASSERT(need_bytes >= gap_len);
+	need_bytes -= gap_len;
+
+	while (need_bytes >= avail_bytes) {
+		DUK_MEMCPY((void *) p, (const void *) p_start, (size_t) avail_bytes);
+		p += avail_bytes;
+		need_bytes -= avail_bytes;
+		avail_bytes <<= 1;
+	}
+
+	DUK_ASSERT(need_bytes < avail_bytes);  /* need_bytes may be zero */
+	DUK_MEMCPY((void *) p, (const void *) p_start, (size_t) need_bytes);
+	p += need_bytes;
+	/*avail_bytes += need_bytes*/
+
+	DUK_BW_SET_PTR(js_ctx->thr, &js_ctx->bw, p);
+}
+#endif  /* DUK_USE_PREFER_SIZE */
+
+/* Shared entry handling for object/array serialization. */
+DUK_LOCAL void duk__enc_objarr_entry(duk_json_enc_ctx *js_ctx, duk_idx_t *entry_top) {
+	duk_context *ctx = (duk_context *) js_ctx->thr;
+	duk_hobject *h_target;
+	duk_uint_fast32_t i, n;
+
+	*entry_top = duk_get_top(ctx);
+
+	duk_require_stack(ctx, DUK_JSON_ENC_REQSTACK);
+
+	/* Loop check using a hybrid approach: a fixed-size visited[] array
+	 * with overflow in a loop check object.
+	 */
+
+	h_target = duk_get_hobject(ctx, -1);  /* object or array */
+	DUK_ASSERT(h_target != NULL);
+
+	n = js_ctx->recursion_depth;
+	if (DUK_UNLIKELY(n > DUK_JSON_ENC_LOOPARRAY)) {
+		n = DUK_JSON_ENC_LOOPARRAY;
+	}
+	for (i = 0; i < n; i++) {
+		if (DUK_UNLIKELY(js_ctx->visiting[i] == h_target)) {
+			DUK_DD(DUK_DDPRINT("slow path loop detect"));
+			DUK_ERROR_TYPE((duk_hthread *) ctx, DUK_STR_CYCLIC_INPUT);
+		}
+	}
+	if (js_ctx->recursion_depth < DUK_JSON_ENC_LOOPARRAY) {
+		js_ctx->visiting[js_ctx->recursion_depth] = h_target;
+	} else {
+		duk_push_sprintf(ctx, DUK_STR_FMT_PTR, (void *) h_target);
+		duk_dup_top(ctx);  /* -> [ ... voidp voidp ] */
+		if (duk_has_prop(ctx, js_ctx->idx_loop)) {
+			DUK_ERROR_TYPE((duk_hthread *) ctx, DUK_STR_CYCLIC_INPUT);
+		}
+		duk_push_true(ctx);  /* -> [ ... voidp true ] */
+		duk_put_prop(ctx, js_ctx->idx_loop);  /* -> [ ... ] */
+	}
+
+	/* C recursion check. */
+
+	DUK_ASSERT(js_ctx->recursion_depth >= 0);
+	DUK_ASSERT(js_ctx->recursion_depth <= js_ctx->recursion_limit);
+	if (js_ctx->recursion_depth >= js_ctx->recursion_limit) {
+		DUK_ERROR_RANGE((duk_hthread *) ctx, DUK_STR_JSONENC_RECLIMIT);
+	}
+	js_ctx->recursion_depth++;
+
+	DUK_DDD(DUK_DDDPRINT("shared entry finished: top=%ld, loop=%!T",
+	                     (long) duk_get_top(ctx), (duk_tval *) duk_get_tval(ctx, js_ctx->idx_loop)));
+}
+
+/* Shared exit handling for object/array serialization. */
+DUK_LOCAL void duk__enc_objarr_exit(duk_json_enc_ctx *js_ctx, duk_idx_t *entry_top) {
+	duk_context *ctx = (duk_context *) js_ctx->thr;
+	duk_hobject *h_target;
+
+	/* C recursion check. */
+
+	DUK_ASSERT(js_ctx->recursion_depth > 0);
+	DUK_ASSERT(js_ctx->recursion_depth <= js_ctx->recursion_limit);
+	js_ctx->recursion_depth--;
+
+	/* Loop check. */
+
+	h_target = duk_get_hobject(ctx, *entry_top - 1);  /* original target at entry_top - 1 */
+	DUK_ASSERT(h_target != NULL);
+
+	if (js_ctx->recursion_depth < DUK_JSON_ENC_LOOPARRAY) {
+		/* Previous entry was inside visited[], nothing to do. */
+	} else {
+		duk_push_sprintf(ctx, DUK_STR_FMT_PTR, (void *) h_target);
+		duk_del_prop(ctx, js_ctx->idx_loop);  /* -> [ ... ] */
+	}
+
+	/* Restore stack top after unbalanced code paths. */
+	duk_set_top(ctx, *entry_top);
+
+	DUK_DDD(DUK_DDDPRINT("shared entry finished: top=%ld, loop=%!T",
+	                     (long) duk_get_top(ctx), (duk_tval *) duk_get_tval(ctx, js_ctx->idx_loop)));
+}
+
+/* The JO(value) operation: encode object.
+ *
+ * Stack policy: [ object ] -> [ object ].
+ */
+DUK_LOCAL void duk__enc_object(duk_json_enc_ctx *js_ctx) {
+	duk_context *ctx = (duk_context *) js_ctx->thr;
+	duk_hstring *h_key;
+	duk_idx_t entry_top;
+	duk_idx_t idx_obj;
+	duk_idx_t idx_keys;
+	duk_bool_t emitted;
+	duk_uarridx_t arr_len, i;
+	duk_size_t prev_size;
+
+	DUK_DDD(DUK_DDDPRINT("duk__enc_object: obj=%!T", (duk_tval *) duk_get_tval(ctx, -1)));
+
+	duk__enc_objarr_entry(js_ctx, &entry_top);
+
+	idx_obj = entry_top - 1;
+
+	if (js_ctx->idx_proplist >= 0) {
+		idx_keys = js_ctx->idx_proplist;
+	} else {
+		/* XXX: would be nice to enumerate an object at specified index */
+		duk_dup(ctx, idx_obj);
+		(void) duk_hobject_get_enumerated_keys(ctx, DUK_ENUM_OWN_PROPERTIES_ONLY /*flags*/);  /* [ ... target ] -> [ ... target keys ] */
+		idx_keys = duk_require_normalize_index(ctx, -1);
+		/* leave stack unbalanced on purpose */
+	}
+
+	DUK_DDD(DUK_DDDPRINT("idx_keys=%ld, h_keys=%!T",
+	                     (long) idx_keys, (duk_tval *) duk_get_tval(ctx, idx_keys)));
+
+	/* Steps 8-10 have been merged to avoid a "partial" variable. */
+
+	DUK__EMIT_1(js_ctx, DUK_ASC_LCURLY);
+
+	/* XXX: keys is an internal object with all keys to be processed
+	 * in its (gapless) array part.  Because nobody can touch the keys
+	 * object, we could iterate its array part directly (keeping in mind
+	 * that it can be reallocated).
+	 */
+
+	arr_len = (duk_uarridx_t) duk_get_length(ctx, idx_keys);
+	emitted = 0;
+	for (i = 0; i < arr_len; i++) {
+		duk_get_prop_index(ctx, idx_keys, i);  /* -> [ ... key ] */
+
+		DUK_DDD(DUK_DDDPRINT("object property loop: holder=%!T, key=%!T",
+		                     (duk_tval *) duk_get_tval(ctx, idx_obj),
+		                     (duk_tval *) duk_get_tval(ctx, -1)));
+
+		h_key = duk_get_hstring(ctx, -1);
+		DUK_ASSERT(h_key != NULL);
+
+		prev_size = DUK_BW_GET_SIZE(js_ctx->thr, &js_ctx->bw);
+		if (DUK_UNLIKELY(js_ctx->h_gap != NULL)) {
+			duk__enc_newline_indent(js_ctx, js_ctx->recursion_depth);
+			duk__enc_key_autoquote(js_ctx, h_key);
+			DUK__EMIT_2(js_ctx, DUK_ASC_COLON, DUK_ASC_SPACE);
+		} else {
+			duk__enc_key_autoquote(js_ctx, h_key);
+			DUK__EMIT_1(js_ctx, DUK_ASC_COLON);
+		}
+
+		/* [ ... key ] */
+
+		if (DUK_UNLIKELY(duk__enc_value(js_ctx, idx_obj) == 0)) {
+			/* Value would yield 'undefined', so skip key altogether.
+			 * Side effects have already happened.
+			 */
+			DUK_BW_SET_SIZE(js_ctx->thr, &js_ctx->bw, prev_size);
+		} else {
+			DUK__EMIT_1(js_ctx, DUK_ASC_COMMA);
+			emitted = 1;
+		}
+
+		/* [ ... ] */
+	}
+
+	if (emitted) {
+		DUK_ASSERT(*((duk_uint8_t *) DUK_BW_GET_PTR(js_ctx->thr, &js_ctx->bw) - 1) == DUK_ASC_COMMA);
+		DUK__UNEMIT_1(js_ctx);  /* eat trailing comma */
+		if (DUK_UNLIKELY(js_ctx->h_gap != NULL)) {
+			DUK_ASSERT(js_ctx->recursion_depth >= 1);
+			duk__enc_newline_indent(js_ctx, js_ctx->recursion_depth - 1);
+		}
+	}
+	DUK__EMIT_1(js_ctx, DUK_ASC_RCURLY);
+
+	duk__enc_objarr_exit(js_ctx, &entry_top);
+
+	DUK_ASSERT_TOP(ctx, entry_top);
+}
+
+/* The JA(value) operation: encode array.
+ *
+ * Stack policy: [ array ] -> [ array ].
+ */
+DUK_LOCAL void duk__enc_array(duk_json_enc_ctx *js_ctx) {
+	duk_context *ctx = (duk_context *) js_ctx->thr;
+	duk_idx_t entry_top;
+	duk_idx_t idx_arr;
+	duk_bool_t emitted;
+	duk_uarridx_t i, arr_len;
+
+	DUK_DDD(DUK_DDDPRINT("duk__enc_array: array=%!T",
+	                     (duk_tval *) duk_get_tval(ctx, -1)));
+
+	duk__enc_objarr_entry(js_ctx, &entry_top);
+
+	idx_arr = entry_top - 1;
+
+	/* Steps 8-10 have been merged to avoid a "partial" variable. */
+
+	DUK__EMIT_1(js_ctx, DUK_ASC_LBRACKET);
+
+	arr_len = (duk_uarridx_t) duk_get_length(ctx, idx_arr);
+	emitted = 0;
+	for (i = 0; i < arr_len; i++) {
+		DUK_DDD(DUK_DDDPRINT("array entry loop: array=%!T, index=%ld, arr_len=%ld",
+		                     (duk_tval *) duk_get_tval(ctx, idx_arr),
+		                     (long) i, (long) arr_len));
+
+		if (DUK_UNLIKELY(js_ctx->h_gap != NULL)) {
+			DUK_ASSERT(js_ctx->recursion_depth >= 1);
+			duk__enc_newline_indent(js_ctx, js_ctx->recursion_depth);
+		}
+
+		/* XXX: duk_push_uint_string() */
+		duk_push_uint(ctx, (duk_uint_t) i);
+		duk_to_string(ctx, -1);  /* -> [ ... key ] */
+
+		/* [ ... key ] */
+
+		if (DUK_UNLIKELY(duk__enc_value(js_ctx, idx_arr) == 0)) {
+			/* Value would normally be omitted, replace with 'null'. */
+			DUK__EMIT_STRIDX(js_ctx, DUK_STRIDX_LC_NULL);
+		} else {
+			;
+		}
+
+		/* [ ... ] */
+
+		DUK__EMIT_1(js_ctx, DUK_ASC_COMMA);
+		emitted = 1;
+	}
+
+	if (emitted) {
+		DUK_ASSERT(*((duk_uint8_t *) DUK_BW_GET_PTR(js_ctx->thr, &js_ctx->bw) - 1) == DUK_ASC_COMMA);
+		DUK__UNEMIT_1(js_ctx);  /* eat trailing comma */
+		if (DUK_UNLIKELY(js_ctx->h_gap != NULL)) {
+			DUK_ASSERT(js_ctx->recursion_depth >= 1);
+			duk__enc_newline_indent(js_ctx, js_ctx->recursion_depth - 1);
+		}
+	}
+	DUK__EMIT_1(js_ctx, DUK_ASC_RBRACKET);
+
+	duk__enc_objarr_exit(js_ctx, &entry_top);
+
+	DUK_ASSERT_TOP(ctx, entry_top);
+}
+
+/* The Str(key, holder) operation.
+ *
+ * Stack policy: [ ... key ] -> [ ... ]
+ */
+DUK_LOCAL duk_bool_t duk__enc_value(duk_json_enc_ctx *js_ctx, duk_idx_t idx_holder) {
+	duk_context *ctx = (duk_context *) js_ctx->thr;
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_hobject *h_tmp;
+	duk_tval *tv;
+	duk_tval *tv_holder;
+	duk_tval *tv_key;
+	duk_small_int_t c;
+
+	DUK_DDD(DUK_DDDPRINT("duk__enc_value: idx_holder=%ld, holder=%!T, key=%!T",
+	                     (long) idx_holder, (duk_tval *) duk_get_tval(ctx, idx_holder),
+	                     (duk_tval *) duk_get_tval(ctx, -1)));
+
+	DUK_UNREF(thr);
+
+	tv_holder = DUK_GET_TVAL_POSIDX(ctx, idx_holder);
+	DUK_ASSERT(DUK_TVAL_IS_OBJECT(tv_holder));
+	tv_key = DUK_GET_TVAL_NEGIDX(ctx, -1);
+	DUK_ASSERT(DUK_TVAL_IS_STRING(tv_key));
+	(void) duk_hobject_getprop(thr, tv_holder, tv_key);
+
+	/* -> [ ... key val ] */
+
+	DUK_DDD(DUK_DDDPRINT("value=%!T", (duk_tval *) duk_get_tval(ctx, -1)));
+
+	h_tmp = duk_get_hobject_or_lfunc_coerce(ctx, -1);
+	if (h_tmp != NULL) {
+		duk_get_prop_stridx(ctx, -1, DUK_STRIDX_TO_JSON);
+		h_tmp = duk_get_hobject_or_lfunc_coerce(ctx, -1);  /* toJSON() can also be a lightfunc */
+
+		if (h_tmp != NULL && DUK_HOBJECT_IS_CALLABLE(h_tmp)) {
+			DUK_DDD(DUK_DDDPRINT("value is object, has callable toJSON() -> call it"));
+			/* XXX: duk_dup_unvalidated(ctx, -2) etc. */
+			duk_dup(ctx, -2);         /* -> [ ... key val toJSON val ] */
+			duk_dup(ctx, -4);         /* -> [ ... key val toJSON val key ] */
+			duk_call_method(ctx, 1);  /* -> [ ... key val val' ] */
+			duk_remove(ctx, -2);      /* -> [ ... key val' ] */
+		} else {
+			duk_pop(ctx);             /* -> [ ... key val ] */
+		}
+	}
+
+	/* [ ... key val ] */
+
+	DUK_DDD(DUK_DDDPRINT("value=%!T", (duk_tval *) duk_get_tval(ctx, -1)));
+
+	if (js_ctx->h_replacer) {
+		/* XXX: Here a "slice copy" would be useful. */
+		DUK_DDD(DUK_DDDPRINT("replacer is set, call replacer"));
+		duk_push_hobject(ctx, js_ctx->h_replacer);  /* -> [ ... key val replacer ] */
+		duk_dup(ctx, idx_holder);                   /* -> [ ... key val replacer holder ] */
+		duk_dup(ctx, -4);                           /* -> [ ... key val replacer holder key ] */
+		duk_dup(ctx, -4);                           /* -> [ ... key val replacer holder key val ] */
+		duk_call_method(ctx, 2);                    /* -> [ ... key val val' ] */
+		duk_remove(ctx, -2);                        /* -> [ ... key val' ] */
+	}
+
+	/* [ ... key val ] */
+
+	DUK_DDD(DUK_DDDPRINT("value=%!T", (duk_tval *) duk_get_tval(ctx, -1)));
+
+	tv = DUK_GET_TVAL_NEGIDX(ctx, -1);
+	if (DUK_TVAL_IS_OBJECT(tv)) {
+		duk_hobject *h;
+
+		h = DUK_TVAL_GET_OBJECT(tv);
+		DUK_ASSERT(h != NULL);
+
+		if (DUK_HOBJECT_IS_BUFFEROBJECT(h)) {
+#if defined(DUK_USE_JX) || defined(DUK_USE_JC)
+			duk_hbufferobject *h_bufobj;
+			h_bufobj = (duk_hbufferobject *) h;
+			DUK_ASSERT_HBUFFEROBJECT_VALID(h_bufobj);
+
+			/* Conceptually we'd extract the plain underlying buffer
+			 * or its slice and then do a type mask check below to
+			 * see if we should reject it.  Do the mask check here
+			 * instead to avoid making a copy of the buffer slice.
+			 */
+
+			if (js_ctx->mask_for_undefined & DUK_TYPE_MASK_BUFFER) {
+				DUK_DDD(DUK_DDDPRINT("-> bufferobject (-> plain buffer) will result in undefined (type mask check)"));
+				goto pop2_undef;
+			}
+			DUK_DDD(DUK_DDDPRINT("-> bufferobject won't result in undefined, encode directly"));
+			duk__enc_bufferobject(js_ctx, h_bufobj);
+			goto pop2_emitted;
+#else
+			DUK_DDD(DUK_DDDPRINT("no JX/JC support, bufferobject/buffer will always result in undefined"));
+			goto pop2_undef;
+#endif
+		} else {
+			c = (duk_small_int_t) DUK_HOBJECT_GET_CLASS_NUMBER(h);
+			switch ((int) c) {
+			case DUK_HOBJECT_CLASS_NUMBER: {
+				DUK_DDD(DUK_DDDPRINT("value is a Number object -> coerce with ToNumber()"));
+				duk_to_number(ctx, -1);
+				/* The coercion potentially invokes user .valueOf() and .toString()
+				 * but can't result in a function value because [[DefaultValue]] would
+				 * reject such a result: test-dev-json-stringify-coercion-1.js.
+				 */
+				DUK_ASSERT(!duk_is_callable(ctx, -1));
+				break;
+			}
+			case DUK_HOBJECT_CLASS_STRING: {
+				DUK_DDD(DUK_DDDPRINT("value is a String object -> coerce with ToString()"));
+				duk_to_string(ctx, -1);
+				/* Same coercion behavior as for Number. */
+				DUK_ASSERT(!duk_is_callable(ctx, -1));
+				break;
+			}
+#if defined(DUK_USE_JX) || defined(DUK_USE_JC)
+			case DUK_HOBJECT_CLASS_POINTER:
+#endif
+			case DUK_HOBJECT_CLASS_BOOLEAN: {
+				DUK_DDD(DUK_DDDPRINT("value is a Boolean/Buffer/Pointer object -> get internal value"));
+				duk_get_prop_stridx(ctx, -1, DUK_STRIDX_INT_VALUE);
+				duk_remove(ctx, -2);
+				break;
+			}
+			default: {
+				/* Normal object which doesn't get automatically coerced to a
+				 * primitive value.  Functions are checked for specially.  The
+				 * primitive value coercions for Number, String, Pointer, and
+				 * Boolean can't result in functions so suffices to check here.
+				 */
+				DUK_ASSERT(h != NULL);
+				if (DUK_HOBJECT_IS_CALLABLE(h)) {
+#if defined(DUK_USE_JX) || defined(DUK_USE_JC)
+					if (js_ctx->flags & (DUK_JSON_FLAG_EXT_CUSTOM |
+					                     DUK_JSON_FLAG_EXT_COMPATIBLE)) {
+						/* We only get here when doing non-standard JSON encoding */
+						DUK_DDD(DUK_DDDPRINT("-> function allowed, serialize to custom format"));
+						DUK_ASSERT(js_ctx->flag_ext_custom || js_ctx->flag_ext_compatible);
+						DUK__EMIT_STRIDX(js_ctx, js_ctx->stridx_custom_function);
+						goto pop2_emitted;
+					} else {
+						DUK_DDD(DUK_DDDPRINT("-> will result in undefined (function)"));
+						goto pop2_undef;
+					}
+#else  /* DUK_USE_JX || DUK_USE_JC */
+					DUK_DDD(DUK_DDDPRINT("-> will result in undefined (function)"));
+					goto pop2_undef;
+#endif  /* DUK_USE_JX || DUK_USE_JC */
+				}
+			}
+			}  /* end switch */
+		}
+	}
+
+	/* [ ... key val ] */
+
+	DUK_DDD(DUK_DDDPRINT("value=%!T", (duk_tval *) duk_get_tval(ctx, -1)));
+
+	if (duk_check_type_mask(ctx, -1, js_ctx->mask_for_undefined)) {
+		/* will result in undefined */
+		DUK_DDD(DUK_DDDPRINT("-> will result in undefined (type mask check)"));
+		goto pop2_undef;
+	}
+	tv = DUK_GET_TVAL_NEGIDX(ctx, -1);
+
+	switch (DUK_TVAL_GET_TAG(tv)) {
+#if defined(DUK_USE_JX) || defined(DUK_USE_JC)
+	/* When JX/JC not in use, the type mask above will avoid this case if needed. */
+	case DUK_TAG_UNDEFINED: {
+		DUK__EMIT_STRIDX(js_ctx, js_ctx->stridx_custom_undefined);
+		break;
+	}
+#endif
+	case DUK_TAG_NULL: {
+		DUK__EMIT_STRIDX(js_ctx, DUK_STRIDX_LC_NULL);
+		break;
+	}
+	case DUK_TAG_BOOLEAN: {
+		DUK__EMIT_STRIDX(js_ctx, DUK_TVAL_GET_BOOLEAN(tv) ?
+		                 DUK_STRIDX_TRUE : DUK_STRIDX_FALSE);
+		break;
+	}
+#if defined(DUK_USE_JX) || defined(DUK_USE_JC)
+	/* When JX/JC not in use, the type mask above will avoid this case if needed. */
+	case DUK_TAG_POINTER: {
+		duk__enc_pointer(js_ctx, DUK_TVAL_GET_POINTER(tv));
+		break;
+	}
+#endif  /* DUK_USE_JX || DUK_USE_JC */
+	case DUK_TAG_STRING: {
+		duk_hstring *h = DUK_TVAL_GET_STRING(tv);
+		DUK_ASSERT(h != NULL);
+
+		duk__enc_quote_string(js_ctx, h);
+		break;
+	}
+	case DUK_TAG_OBJECT: {
+		duk_hobject *h = DUK_TVAL_GET_OBJECT(tv);
+		DUK_ASSERT(h != NULL);
+
+		/* Function values are handled completely above (including
+		 * coercion results):
+		 */
+		DUK_ASSERT(!DUK_HOBJECT_IS_CALLABLE(h));
+
+		if (DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_ARRAY) {
+			duk__enc_array(js_ctx);
+		} else {
+			duk__enc_object(js_ctx);
+		}
+		break;
+	}
+#if defined(DUK_USE_JX) || defined(DUK_USE_JC)
+	/* When JX/JC not in use, the type mask above will avoid this case if needed. */
+	case DUK_TAG_BUFFER: {
+		duk__enc_buffer(js_ctx, DUK_TVAL_GET_BUFFER(tv));
+		break;
+	}
+#endif  /* DUK_USE_JX || DUK_USE_JC */
+	case DUK_TAG_LIGHTFUNC: {
+#if defined(DUK_USE_JX) || defined(DUK_USE_JC)
+		/* We only get here when doing non-standard JSON encoding */
+		DUK_ASSERT(js_ctx->flag_ext_custom || js_ctx->flag_ext_compatible);
+		DUK__EMIT_STRIDX(js_ctx, js_ctx->stridx_custom_function);
+#else
+		/* Standard JSON omits functions */
+		DUK_UNREACHABLE();
+#endif
+		break;
+	}
+#if defined(DUK_USE_FASTINT)
+	case DUK_TAG_FASTINT:
+		/* Number serialization has a significant impact relative to
+		 * other fast path code, so careful fast path for fastints.
+		 */
+		duk__enc_fastint_tval(js_ctx, tv);
+		break;
+#endif
+	default: {
+		/* number */
+		DUK_ASSERT(!DUK_TVAL_IS_UNUSED(tv));
+		DUK_ASSERT(DUK_TVAL_IS_NUMBER(tv));
+		/* XXX: A fast path for usual integers would be useful when
+		 * fastint support is not enabled.
+		 */
+		duk__enc_double(js_ctx);
+		break;
+	}
+	}
+
+ pop2_emitted:
+	duk_pop_2(ctx); /* [ ... key val ] -> [ ... ] */
+	return 1;  /* emitted */
+
+ pop2_undef:
+	duk_pop_2(ctx);  /* [ ... key val ] -> [ ... ] */
+	return 0;  /* not emitted */
+}
+
+/* E5 Section 15.12.3, main algorithm, step 4.b.ii steps 1-4. */
+DUK_LOCAL duk_bool_t duk__enc_allow_into_proplist(duk_tval *tv) {
+	duk_hobject *h;
+	duk_small_int_t c;
+
+	DUK_ASSERT(tv != NULL);
+	if (DUK_TVAL_IS_STRING(tv) || DUK_TVAL_IS_NUMBER(tv)) {
+		return 1;
+	} else if (DUK_TVAL_IS_OBJECT(tv)) {
+		h = DUK_TVAL_GET_OBJECT(tv);
+		DUK_ASSERT(h != NULL);
+		c = (duk_small_int_t) DUK_HOBJECT_GET_CLASS_NUMBER(h);
+		if (c == DUK_HOBJECT_CLASS_STRING || c == DUK_HOBJECT_CLASS_NUMBER) {
+			return 1;
+		}
+	}
+
+	return 0;
+}
+
+/*
+ *  JSON.stringify() fast path
+ *
+ *  Otherwise supports full JSON, JX, and JC features, but bails out on any
+ *  possible side effect which might change the value being serialized.  The
+ *  fast path can take advantage of the fact that the value being serialized
+ *  is unchanged so that we can walk directly through property tables etc.
+ */
+
+#if defined(DUK_USE_JSON_STRINGIFY_FASTPATH)
+DUK_LOCAL duk_bool_t duk__json_stringify_fast_value(duk_json_enc_ctx *js_ctx, duk_tval *tv) {
+	duk_uint_fast32_t i, n;
+
+	DUK_DDD(DUK_DDDPRINT("stringify fast: %!T", tv));
+
+	DUK_ASSERT(js_ctx != NULL);
+	DUK_ASSERT(js_ctx->thr != NULL);
+
+#if 0 /* disabled for now */
+ restart_match:
+#endif
+
+	DUK_ASSERT(tv != NULL);
+
+	switch (DUK_TVAL_GET_TAG(tv)) {
+	case DUK_TAG_UNDEFINED: {
+#if defined(DUK_USE_JX) || defined(DUK_USE_JC)
+		if (js_ctx->flag_ext_custom || js_ctx->flag_ext_compatible) {
+			DUK__EMIT_STRIDX(js_ctx, js_ctx->stridx_custom_undefined);
+			break;
+		} else {
+			goto emit_undefined;
+		}
+#else
+		goto emit_undefined;
+#endif
+	}
+	case DUK_TAG_NULL: {
+		DUK__EMIT_STRIDX(js_ctx, DUK_STRIDX_LC_NULL);
+		break;
+	}
+	case DUK_TAG_BOOLEAN: {
+		DUK__EMIT_STRIDX(js_ctx, DUK_TVAL_GET_BOOLEAN(tv) ?
+		                 DUK_STRIDX_TRUE : DUK_STRIDX_FALSE);
+		break;
+	}
+	case DUK_TAG_STRING: {
+		duk_hstring *h;
+
+		h = DUK_TVAL_GET_STRING(tv);
+		DUK_ASSERT(h != NULL);
+		duk__enc_quote_string(js_ctx, h);
+		break;
+	}
+	case DUK_TAG_OBJECT: {
+		duk_hobject *obj;
+		duk_tval *tv_val;
+		duk_bool_t emitted = 0;
+		duk_uint32_t c_bit, c_all, c_array, c_unbox, c_undef,
+		             c_func, c_bufobj, c_object;
+
+		/* For objects JSON.stringify() only looks for own, enumerable
+		 * properties which is nice for the fast path here.
+		 *
+		 * For arrays JSON.stringify() uses [[Get]] so it will actually
+		 * inherit properties during serialization!  This fast path
+		 * supports gappy arrays as long as there's no actual inherited
+		 * property (which might be a getter etc).
+		 *
+		 * Since recursion only happens for objects, we can have both
+		 * recursion and loop checks here.  We use a simple, depth-limited
+		 * loop check in the fast path because the object-based tracking
+		 * is very slow (when tested, it accounted for 50% of fast path
+		 * execution time for input data with a lot of small objects!).
+		 */
+
+		/* XXX: for real world code, could just ignore array inheritance
+		 * and only look at array own properties.
+		 */
+
+		/* We rely on a few object flag / class number relationships here,
+		 * assert for them.
+		 */
+
+		obj = DUK_TVAL_GET_OBJECT(tv);
+		DUK_ASSERT(obj != NULL);
+		DUK_ASSERT_HOBJECT_VALID(obj);
+
+		/* Once recursion depth is increased, exit path must decrease
+		 * it (though it's OK to abort the fast path).
+		 */
+
+		DUK_ASSERT(js_ctx->recursion_depth >= 0);
+		DUK_ASSERT(js_ctx->recursion_depth <= js_ctx->recursion_limit);
+		if (js_ctx->recursion_depth >= js_ctx->recursion_limit) {
+			DUK_DD(DUK_DDPRINT("fast path recursion limit"));
+			DUK_ERROR_RANGE(js_ctx->thr, DUK_STR_JSONDEC_RECLIMIT);
+		}
+
+		for (i = 0, n = (duk_uint_fast32_t) js_ctx->recursion_depth; i < n; i++) {
+			if (DUK_UNLIKELY(js_ctx->visiting[i] == obj)) {
+				DUK_DD(DUK_DDPRINT("fast path loop detect"));
+				DUK_ERROR_TYPE(js_ctx->thr, DUK_STR_CYCLIC_INPUT);
+			}
+		}
+
+		/* Guaranteed by recursion_limit setup so we don't have to
+		 * check twice.
+		 */
+		DUK_ASSERT(js_ctx->recursion_depth < DUK_JSON_ENC_LOOPARRAY);
+		js_ctx->visiting[js_ctx->recursion_depth] = obj;
+		js_ctx->recursion_depth++;
+
+		/* If object has a .toJSON() property, we can't be certain
+		 * that it wouldn't mutate any value arbitrarily, so bail
+		 * out of the fast path.
+		 *
+		 * If an object is a Proxy we also can't avoid side effects
+		 * so abandon.
+		 */
+		/* XXX: non-callable .toJSON() doesn't need to cause an abort
+		 * but does at the moment, probably not worth fixing.
+		 */
+		if (duk_hobject_hasprop_raw(js_ctx->thr, obj, DUK_HTHREAD_STRING_TO_JSON(js_ctx->thr)) ||
+		    DUK_HOBJECT_HAS_EXOTIC_PROXYOBJ(obj)) {
+			DUK_DD(DUK_DDPRINT("object has a .toJSON property or object is a Proxy, abort fast path"));
+			goto abort_fastpath;
+		}
+
+		/* We could use a switch-case for the class number but it turns out
+		 * a small if-else ladder on class masks is better.  The if-ladder
+		 * should be in order of relevancy.
+		 */
+
+		/* XXX: move masks to js_ctx? they don't change during one
+		 * fast path invocation.
+		 */
+		DUK_ASSERT(DUK_HOBJECT_CLASS_MAX <= 31);
+#if defined(DUK_USE_JX) || defined(DUK_USE_JC)
+		if (js_ctx->flag_ext_custom_or_compatible) {
+			c_all = DUK_HOBJECT_CMASK_ALL;
+			c_array = DUK_HOBJECT_CMASK_ARRAY;
+			c_unbox = DUK_HOBJECT_CMASK_NUMBER |
+			          DUK_HOBJECT_CMASK_STRING |
+			          DUK_HOBJECT_CMASK_BOOLEAN |
+			          DUK_HOBJECT_CMASK_POINTER;
+			c_func = DUK_HOBJECT_CMASK_FUNCTION;
+			c_bufobj = DUK_HOBJECT_CMASK_ALL_BUFFEROBJECTS;
+			c_undef = 0;
+			c_object = c_all & ~(c_array | c_unbox | c_func | c_bufobj | c_undef);
+		}
+		else
+#endif
+		{
+			c_all = DUK_HOBJECT_CMASK_ALL;
+			c_array = DUK_HOBJECT_CMASK_ARRAY;
+			c_unbox = DUK_HOBJECT_CMASK_NUMBER |
+			          DUK_HOBJECT_CMASK_STRING |
+			          DUK_HOBJECT_CMASK_BOOLEAN;
+			c_func = 0;
+			c_bufobj = 0;
+			c_undef = DUK_HOBJECT_CMASK_FUNCTION |
+			          DUK_HOBJECT_CMASK_POINTER |
+			          DUK_HOBJECT_CMASK_ALL_BUFFEROBJECTS;
+			c_object = c_all & ~(c_array | c_unbox | c_func | c_bufobj | c_undef);
+		}
+
+		c_bit = DUK_HOBJECT_GET_CLASS_MASK(obj);
+		if (c_bit & c_object) {
+			/* All other object types. */
+			DUK__EMIT_1(js_ctx, DUK_ASC_LCURLY);
+
+			/* A non-Array object should not have an array part in practice.
+			 * But since it is supported internally (and perhaps used at some
+			 * point), check and abandon if that's the case.
+			 */
+			if (DUK_HOBJECT_HAS_ARRAY_PART(obj)) {
+				DUK_DD(DUK_DDPRINT("non-Array object has array part, abort fast path"));
+				goto abort_fastpath;
+			}
+
+			for (i = 0; i < (duk_uint_fast32_t) DUK_HOBJECT_GET_ENEXT(obj); i++) {
+				duk_hstring *k;
+				duk_size_t prev_size;
+
+				k = DUK_HOBJECT_E_GET_KEY(js_ctx->thr->heap, obj, i);
+				if (!k) {
+					continue;
+				}
+				if (!DUK_HOBJECT_E_SLOT_IS_ENUMERABLE(js_ctx->thr->heap, obj, i)) {
+					continue;
+				}
+				if (DUK_HOBJECT_E_SLOT_IS_ACCESSOR(js_ctx->thr->heap, obj, i)) {
+					/* Getter might have arbitrary side effects,
+					 * so bail out.
+					 */
+					DUK_DD(DUK_DDPRINT("property is an accessor, abort fast path"));
+					goto abort_fastpath;
+				}
+				if (DUK_HSTRING_HAS_INTERNAL(k)) {
+					continue;
+				}
+
+				tv_val = DUK_HOBJECT_E_GET_VALUE_TVAL_PTR(js_ctx->thr->heap, obj, i);
+
+				prev_size = DUK_BW_GET_SIZE(js_ctx->thr, &js_ctx->bw);
+				if (DUK_UNLIKELY(js_ctx->h_gap != NULL)) {
+					duk__enc_newline_indent(js_ctx, js_ctx->recursion_depth);
+					duk__enc_key_autoquote(js_ctx, k);
+					DUK__EMIT_2(js_ctx, DUK_ASC_COLON, DUK_ASC_SPACE);
+				} else {
+					duk__enc_key_autoquote(js_ctx, k);
+					DUK__EMIT_1(js_ctx, DUK_ASC_COLON);
+				}
+
+				if (duk__json_stringify_fast_value(js_ctx, tv_val) == 0) {
+					DUK_DD(DUK_DDPRINT("prop value not supported, rewind key and colon"));
+					DUK_BW_SET_SIZE(js_ctx->thr, &js_ctx->bw, prev_size);
+				} else {
+					DUK__EMIT_1(js_ctx, DUK_ASC_COMMA);
+					emitted = 1;
+				}
+			}
+
+			/* If any non-Array value had enumerable virtual own
+			 * properties, they should be serialized here.  Standard
+			 * types don't.
+			 */
+
+			if (emitted) {
+				DUK_ASSERT(*((duk_uint8_t *) DUK_BW_GET_PTR(js_ctx->thr, &js_ctx->bw) - 1) == DUK_ASC_COMMA);
+				DUK__UNEMIT_1(js_ctx);  /* eat trailing comma */
+				if (DUK_UNLIKELY(js_ctx->h_gap != NULL)) {
+					DUK_ASSERT(js_ctx->recursion_depth >= 1);
+					duk__enc_newline_indent(js_ctx, js_ctx->recursion_depth - 1);
+				}
+			}
+			DUK__EMIT_1(js_ctx, DUK_ASC_RCURLY);
+		} else if (c_bit & c_array) {
+			duk_uint_fast32_t arr_len;
+			duk_uint_fast32_t asize;
+
+			DUK__EMIT_1(js_ctx, DUK_ASC_LBRACKET);
+
+			/* Assume arrays are dense in the fast path. */
+			if (!DUK_HOBJECT_HAS_ARRAY_PART(obj)) {
+				DUK_DD(DUK_DDPRINT("Array object is sparse, abort fast path"));
+				goto abort_fastpath;
+			}
+
+			arr_len = (duk_uint_fast32_t) duk_hobject_get_length(js_ctx->thr, obj);
+			asize = (duk_uint_fast32_t) DUK_HOBJECT_GET_ASIZE(obj);
+			if (arr_len > asize) {
+				/* Array length is larger than 'asize'.  This shouldn't
+				 * happen in practice.  Bail out just in case.
+				 */
+				DUK_DD(DUK_DDPRINT("arr_len > asize, abort fast path"));
+				goto abort_fastpath;
+			}
+			/* Array part may be larger than 'length'; if so, iterate
+			 * only up to array 'length'.
+			 */
+			for (i = 0; i < arr_len; i++) {
+				DUK_ASSERT(i < (duk_uint_fast32_t) DUK_HOBJECT_GET_ASIZE(obj));
+
+				tv_val = DUK_HOBJECT_A_GET_VALUE_PTR(js_ctx->thr->heap, obj, i);
+
+				if (DUK_UNLIKELY(js_ctx->h_gap != NULL)) {
+					duk__enc_newline_indent(js_ctx, js_ctx->recursion_depth);
+				}
+
+				if (DUK_UNLIKELY(DUK_TVAL_IS_UNUSED(tv_val))) {
+					/* Gap in array; check for inherited property,
+					 * bail out if one exists.  This should be enough
+					 * to support gappy arrays for all practical code.
+					 */
+					duk_hstring *h_tmp;
+					duk_bool_t has_inherited;
+
+					/* XXX: refactor into an internal helper, pretty awkward */
+					duk_push_uint((duk_context *) js_ctx->thr, (duk_uint_t) i);
+					h_tmp = duk_to_hstring((duk_context *) js_ctx->thr, -1);
+					DUK_ASSERT(h_tmp != NULL);
+					has_inherited = duk_hobject_hasprop_raw(js_ctx->thr, obj, h_tmp);
+					duk_pop((duk_context *) js_ctx->thr);
+
+					if (has_inherited) {
+						DUK_D(DUK_DPRINT("gap in array, conflicting inherited property, abort fast path"));
+						goto abort_fastpath;
+					}
+
+					/* Ordinary gap, undefined encodes to 'null' in
+					 * standard JSON (and no JX/JC support here now).
+					 */
+					DUK_D(DUK_DPRINT("gap in array, no conflicting inherited property, remain on fast path"));
+#if defined(DUK_USE_JX)
+					DUK__EMIT_STRIDX(js_ctx, js_ctx->stridx_custom_undefined);
+#else
+					DUK__EMIT_STRIDX(js_ctx, DUK_STRIDX_LC_NULL);
+#endif
+				} else {
+					if (duk__json_stringify_fast_value(js_ctx, tv_val) == 0) {
+						DUK__EMIT_STRIDX(js_ctx, DUK_STRIDX_LC_NULL);
+					}
+				}
+
+				DUK__EMIT_1(js_ctx, DUK_ASC_COMMA);
+				emitted = 1;
+			}
+
+			if (emitted) {
+				DUK_ASSERT(*((duk_uint8_t *) DUK_BW_GET_PTR(js_ctx->thr, &js_ctx->bw) - 1) == DUK_ASC_COMMA);
+				DUK__UNEMIT_1(js_ctx);  /* eat trailing comma */
+				if (DUK_UNLIKELY(js_ctx->h_gap != NULL)) {
+					DUK_ASSERT(js_ctx->recursion_depth >= 1);
+					duk__enc_newline_indent(js_ctx, js_ctx->recursion_depth - 1);
+				}
+			}
+			DUK__EMIT_1(js_ctx, DUK_ASC_RBRACKET);
+		} else if (c_bit & c_unbox) {
+			/* Certain boxed types are required to go through
+			 * automatic unboxing.  Rely on internal value being
+			 * sane (to avoid infinite recursion).
+			 */
+#if 1
+			/* The code below is incorrect if .toString() or .valueOf() have
+			 * have been overridden.  The correct approach would be to look up
+			 * the method(s) and if they resolve to the built-in function we
+			 * can safely bypass it and look up the internal value directly.
+			 * Unimplemented for now, abort fast path for boxed values.
+			 */
+			goto abort_fastpath;
+#else  /* disabled */
+			/* Disabled until fixed, see above. */
+			duk_tval *tv_internal;
+
+			DUK_DD(DUK_DDPRINT("auto unboxing in fast path"));
+
+			tv_internal = duk_hobject_get_internal_value_tval_ptr(js_ctx->thr->heap, obj);
+			DUK_ASSERT(tv_internal != NULL);
+			DUK_ASSERT(DUK_TVAL_IS_STRING(tv_internal) ||
+			           DUK_TVAL_IS_NUMBER(tv_internal) ||
+			           DUK_TVAL_IS_BOOLEAN(tv_internal) ||
+			           DUK_TVAL_IS_POINTER(tv_internal));
+
+			tv = tv_internal;
+			DUK_ASSERT(js_ctx->recursion_depth > 0);
+			js_ctx->recursion_depth--;  /* required to keep recursion depth correct */
+			goto restart_match;
+#endif  /* disabled */
+#if defined(DUK_USE_JX) || defined(DUK_USE_JC)
+		} else if (c_bit & c_func) {
+			DUK__EMIT_STRIDX(js_ctx, js_ctx->stridx_custom_function);
+		} else if (c_bit & c_bufobj) {
+			duk__enc_bufferobject(js_ctx, (duk_hbufferobject *) obj);
+#endif
+		} else {
+			DUK_ASSERT((c_bit & c_undef) != 0);
+
+			/* Must decrease recursion depth before returning. */
+			DUK_ASSERT(js_ctx->recursion_depth > 0);
+			DUK_ASSERT(js_ctx->recursion_depth <= js_ctx->recursion_limit);
+			js_ctx->recursion_depth--;
+			goto emit_undefined;
+		}
+
+		DUK_ASSERT(js_ctx->recursion_depth > 0);
+		DUK_ASSERT(js_ctx->recursion_depth <= js_ctx->recursion_limit);
+		js_ctx->recursion_depth--;
+		break;
+	}
+	case DUK_TAG_BUFFER: {
+#if defined(DUK_USE_JX) || defined(DUK_USE_JC)
+		if (js_ctx->flag_ext_custom_or_compatible) {
+			duk__enc_buffer(js_ctx, DUK_TVAL_GET_BUFFER(tv));
+			break;
+		} else {
+			goto emit_undefined;
+		}
+#else
+		goto emit_undefined;
+#endif
+	}
+	case DUK_TAG_POINTER: {
+#if defined(DUK_USE_JX) || defined(DUK_USE_JC)
+		if (js_ctx->flag_ext_custom_or_compatible) {
+			duk__enc_pointer(js_ctx, DUK_TVAL_GET_POINTER(tv));
+			break;
+		} else {
+			goto emit_undefined;
+		}
+#else
+		goto emit_undefined;
+#endif
+	}
+	case DUK_TAG_LIGHTFUNC: {
+		/* A lightfunc might also inherit a .toJSON() so just bail out. */
+		/* XXX: Could just lookup .toJSON() and continue in fast path,
+		 * as it would almost never be defined.
+		 */
+		DUK_DD(DUK_DDPRINT("value is a lightfunc, abort fast path"));
+		goto abort_fastpath;
+	}
+#if defined(DUK_USE_FASTINT)
+	case DUK_TAG_FASTINT: {
+		/* Number serialization has a significant impact relative to
+		 * other fast path code, so careful fast path for fastints.
+		 */
+		duk__enc_fastint_tval(js_ctx, tv);
+		break;
+	}
+#endif
+	default: {
+		/* XXX: A fast path for usual integers would be useful when
+		 * fastint support is not enabled.
+		 */
+		DUK_ASSERT(!DUK_TVAL_IS_UNUSED(tv));
+		DUK_ASSERT(DUK_TVAL_IS_NUMBER(tv));
+
+		/* XXX: Stack discipline is annoying, could be changed in numconv. */
+		duk_push_tval((duk_context *) js_ctx->thr, tv);
+		duk__enc_double(js_ctx);
+		duk_pop((duk_context *) js_ctx->thr);
+
+#if 0
+		/* Could also rely on native sprintf(), but it will handle
+		 * values like NaN, Infinity, -0, exponent notation etc in
+		 * a JSON-incompatible way.
+		 */
+		duk_double_t d;
+		char buf[64];
+
+		DUK_ASSERT(DUK_TVAL_IS_DOUBLE(tv));
+		d = DUK_TVAL_GET_DOUBLE(tv);
+		DUK_SPRINTF(buf, "%lg", d);
+		DUK__EMIT_CSTR(js_ctx, buf);
+#endif
+	}
+	}
+	return 1;  /* not undefined */
+
+ emit_undefined:
+	return 0;  /* value was undefined/unsupported */
+
+ abort_fastpath:
+	/* Error message doesn't matter: the error is ignored anyway. */
+	

<TRUNCATED>

[43/51] [partial] nifi-minifi-cpp git commit: MINIFI-183 Added civet 1.9.1 sources Added onScheduled hook Added initial two-way TLS-enabled ListenHTTP implementation

Posted by al...@apache.org.
http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/examples/_obsolete/docroot/jquery.js
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/examples/_obsolete/docroot/jquery.js b/thirdparty/civetweb-1.9.1/examples/_obsolete/docroot/jquery.js
new file mode 100644
index 0000000..7c24308
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/examples/_obsolete/docroot/jquery.js
@@ -0,0 +1,154 @@
+/*!
+ * jQuery JavaScript Library v1.4.2
+ * http://jquery.com/
+ *
+ * Copyright 2010, John Resig
+ * Dual licensed under the MIT or GPL Version 2 licenses.
+ * http://jquery.org/license
+ *
+ * Includes Sizzle.js
+ * http://sizzlejs.com/
+ * Copyright 2010, The Dojo Foundation
+ * Released under the MIT, BSD, and GPL Licenses.
+ *
+ * Date: Sat Feb 13 22:33:48 2010 -0500
+ */
+(function(A,w){function ma(){if(!c.isReady){try{s.documentElement.doScroll("left")}catch(a){setTimeout(ma,1);return}c.ready()}}function Qa(a,b){b.src?c.ajax({url:b.src,async:false,dataType:"script"}):c.globalEval(b.text||b.textContent||b.innerHTML||"");b.parentNode&&b.parentNode.removeChild(b)}function X(a,b,d,f,e,j){var i=a.length;if(typeof b==="object"){for(var o in b)X(a,o,b[o],f,e,d);return a}if(d!==w){f=!j&&f&&c.isFunction(d);for(o=0;o<i;o++)e(a[o],b,f?d.call(a[o],o,e(a[o],b)):d,j);return a}return i?
+e(a[0],b):w}function J(){return(new Date).getTime()}function Y(){return false}function Z(){return true}function na(a,b,d){d[0].type=a;return c.event.handle.apply(b,d)}function oa(a){var b,d=[],f=[],e=arguments,j,i,o,k,n,r;i=c.data(this,"events");if(!(a.liveFired===this||!i||!i.live||a.button&&a.type==="click")){a.liveFired=this;var u=i.live.slice(0);for(k=0;k<u.length;k++){i=u[k];i.origType.replace(O,"")===a.type?f.push(i.selector):u.splice(k--,1)}j=c(a.target).closest(f,a.currentTarget);n=0;for(r=
+j.length;n<r;n++)for(k=0;k<u.length;k++){i=u[k];if(j[n].selector===i.selector){o=j[n].elem;f=null;if(i.preType==="mouseenter"||i.preType==="mouseleave")f=c(a.relatedTarget).closest(i.selector)[0];if(!f||f!==o)d.push({elem:o,handleObj:i})}}n=0;for(r=d.length;n<r;n++){j=d[n];a.currentTarget=j.elem;a.data=j.handleObj.data;a.handleObj=j.handleObj;if(j.handleObj.origHandler.apply(j.elem,e)===false){b=false;break}}return b}}function pa(a,b){return"live."+(a&&a!=="*"?a+".":"")+b.replace(/\./g,"`").replace(/ /g,
+"&")}function qa(a){return!a||!a.parentNode||a.parentNode.nodeType===11}function ra(a,b){var d=0;b.each(function(){if(this.nodeName===(a[d]&&a[d].nodeName)){var f=c.data(a[d++]),e=c.data(this,f);if(f=f&&f.events){delete e.handle;e.events={};for(var j in f)for(var i in f[j])c.event.add(this,j,f[j][i],f[j][i].data)}}})}function sa(a,b,d){var f,e,j;b=b&&b[0]?b[0].ownerDocument||b[0]:s;if(a.length===1&&typeof a[0]==="string"&&a[0].length<512&&b===s&&!ta.test(a[0])&&(c.support.checkClone||!ua.test(a[0]))){e=
+true;if(j=c.fragments[a[0]])if(j!==1)f=j}if(!f){f=b.createDocumentFragment();c.clean(a,b,f,d)}if(e)c.fragments[a[0]]=j?f:1;return{fragment:f,cacheable:e}}function K(a,b){var d={};c.each(va.concat.apply([],va.slice(0,b)),function(){d[this]=a});return d}function wa(a){return"scrollTo"in a&&a.document?a:a.nodeType===9?a.defaultView||a.parentWindow:false}var c=function(a,b){return new c.fn.init(a,b)},Ra=A.jQuery,Sa=A.$,s=A.document,T,Ta=/^[^<]*(<[\w\W]+>)[^>]*$|^#([\w-]+)$/,Ua=/^.[^:#\[\.,]*$/,Va=/\S/,
+Wa=/^(\s|\u00A0)+|(\s|\u00A0)+$/g,Xa=/^<(\w+)\s*\/?>(?:<\/\1>)?$/,P=navigator.userAgent,xa=false,Q=[],L,$=Object.prototype.toString,aa=Object.prototype.hasOwnProperty,ba=Array.prototype.push,R=Array.prototype.slice,ya=Array.prototype.indexOf;c.fn=c.prototype={init:function(a,b){var d,f;if(!a)return this;if(a.nodeType){this.context=this[0]=a;this.length=1;return this}if(a==="body"&&!b){this.context=s;this[0]=s.body;this.selector="body";this.length=1;return this}if(typeof a==="string")if((d=Ta.exec(a))&&
+(d[1]||!b))if(d[1]){f=b?b.ownerDocument||b:s;if(a=Xa.exec(a))if(c.isPlainObject(b)){a=[s.createElement(a[1])];c.fn.attr.call(a,b,true)}else a=[f.createElement(a[1])];else{a=sa([d[1]],[f]);a=(a.cacheable?a.fragment.cloneNode(true):a.fragment).childNodes}return c.merge(this,a)}else{if(b=s.getElementById(d[2])){if(b.id!==d[2])return T.find(a);this.length=1;this[0]=b}this.context=s;this.selector=a;return this}else if(!b&&/^\w+$/.test(a)){this.selector=a;this.context=s;a=s.getElementsByTagName(a);return c.merge(this,
+a)}else return!b||b.jquery?(b||T).find(a):c(b).find(a);else if(c.isFunction(a))return T.ready(a);if(a.selector!==w){this.selector=a.selector;this.context=a.context}return c.makeArray(a,this)},selector:"",jquery:"1.4.2",length:0,size:function(){return this.length},toArray:function(){return R.call(this,0)},get:function(a){return a==null?this.toArray():a<0?this.slice(a)[0]:this[a]},pushStack:function(a,b,d){var f=c();c.isArray(a)?ba.apply(f,a):c.merge(f,a);f.prevObject=this;f.context=this.context;if(b===
+"find")f.selector=this.selector+(this.selector?" ":"")+d;else if(b)f.selector=this.selector+"."+b+"("+d+")";return f},each:function(a,b){return c.each(this,a,b)},ready:function(a){c.bindReady();if(c.isReady)a.call(s,c);else Q&&Q.push(a);return this},eq:function(a){return a===-1?this.slice(a):this.slice(a,+a+1)},first:function(){return this.eq(0)},last:function(){return this.eq(-1)},slice:function(){return this.pushStack(R.apply(this,arguments),"slice",R.call(arguments).join(","))},map:function(a){return this.pushStack(c.map(this,
+function(b,d){return a.call(b,d,b)}))},end:function(){return this.prevObject||c(null)},push:ba,sort:[].sort,splice:[].splice};c.fn.init.prototype=c.fn;c.extend=c.fn.extend=function(){var a=arguments[0]||{},b=1,d=arguments.length,f=false,e,j,i,o;if(typeof a==="boolean"){f=a;a=arguments[1]||{};b=2}if(typeof a!=="object"&&!c.isFunction(a))a={};if(d===b){a=this;--b}for(;b<d;b++)if((e=arguments[b])!=null)for(j in e){i=a[j];o=e[j];if(a!==o)if(f&&o&&(c.isPlainObject(o)||c.isArray(o))){i=i&&(c.isPlainObject(i)||
+c.isArray(i))?i:c.isArray(o)?[]:{};a[j]=c.extend(f,i,o)}else if(o!==w)a[j]=o}return a};c.extend({noConflict:function(a){A.$=Sa;if(a)A.jQuery=Ra;return c},isReady:false,ready:function(){if(!c.isReady){if(!s.body)return setTimeout(c.ready,13);c.isReady=true;if(Q){for(var a,b=0;a=Q[b++];)a.call(s,c);Q=null}c.fn.triggerHandler&&c(s).triggerHandler("ready")}},bindReady:function(){if(!xa){xa=true;if(s.readyState==="complete")return c.ready();if(s.addEventListener){s.addEventListener("DOMContentLoaded",
+L,false);A.addEventListener("load",c.ready,false)}else if(s.attachEvent){s.attachEvent("onreadystatechange",L);A.attachEvent("onload",c.ready);var a=false;try{a=A.frameElement==null}catch(b){}s.documentElement.doScroll&&a&&ma()}}},isFunction:function(a){return $.call(a)==="[object Function]"},isArray:function(a){return $.call(a)==="[object Array]"},isPlainObject:function(a){if(!a||$.call(a)!=="[object Object]"||a.nodeType||a.setInterval)return false;if(a.constructor&&!aa.call(a,"constructor")&&!aa.call(a.constructor.prototype,
+"isPrototypeOf"))return false;var b;for(b in a);return b===w||aa.call(a,b)},isEmptyObject:function(a){for(var b in a)return false;return true},error:function(a){throw a;},parseJSON:function(a){if(typeof a!=="string"||!a)return null;a=c.trim(a);if(/^[\],:{}\s]*$/.test(a.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,"@").replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,"]").replace(/(?:^|:|,)(?:\s*\[)+/g,"")))return A.JSON&&A.JSON.parse?A.JSON.parse(a):(new Function("return "+
+a))();else c.error("Invalid JSON: "+a)},noop:function(){},globalEval:function(a){if(a&&Va.test(a)){var b=s.getElementsByTagName("head")[0]||s.documentElement,d=s.createElement("script");d.type="text/javascript";if(c.support.scriptEval)d.appendChild(s.createTextNode(a));else d.text=a;b.insertBefore(d,b.firstChild);b.removeChild(d)}},nodeName:function(a,b){return a.nodeName&&a.nodeName.toUpperCase()===b.toUpperCase()},each:function(a,b,d){var f,e=0,j=a.length,i=j===w||c.isFunction(a);if(d)if(i)for(f in a){if(b.apply(a[f],
+d)===false)break}else for(;e<j;){if(b.apply(a[e++],d)===false)break}else if(i)for(f in a){if(b.call(a[f],f,a[f])===false)break}else for(d=a[0];e<j&&b.call(d,e,d)!==false;d=a[++e]);return a},trim:function(a){return(a||"").replace(Wa,"")},makeArray:function(a,b){b=b||[];if(a!=null)a.length==null||typeof a==="string"||c.isFunction(a)||typeof a!=="function"&&a.setInterval?ba.call(b,a):c.merge(b,a);return b},inArray:function(a,b){if(b.indexOf)return b.indexOf(a);for(var d=0,f=b.length;d<f;d++)if(b[d]===
+a)return d;return-1},merge:function(a,b){var d=a.length,f=0;if(typeof b.length==="number")for(var e=b.length;f<e;f++)a[d++]=b[f];else for(;b[f]!==w;)a[d++]=b[f++];a.length=d;return a},grep:function(a,b,d){for(var f=[],e=0,j=a.length;e<j;e++)!d!==!b(a[e],e)&&f.push(a[e]);return f},map:function(a,b,d){for(var f=[],e,j=0,i=a.length;j<i;j++){e=b(a[j],j,d);if(e!=null)f[f.length]=e}return f.concat.apply([],f)},guid:1,proxy:function(a,b,d){if(arguments.length===2)if(typeof b==="string"){d=a;a=d[b];b=w}else if(b&&
+!c.isFunction(b)){d=b;b=w}if(!b&&a)b=function(){return a.apply(d||this,arguments)};if(a)b.guid=a.guid=a.guid||b.guid||c.guid++;return b},uaMatch:function(a){a=a.toLowerCase();a=/(webkit)[ \/]([\w.]+)/.exec(a)||/(opera)(?:.*version)?[ \/]([\w.]+)/.exec(a)||/(msie) ([\w.]+)/.exec(a)||!/compatible/.test(a)&&/(mozilla)(?:.*? rv:([\w.]+))?/.exec(a)||[];return{browser:a[1]||"",version:a[2]||"0"}},browser:{}});P=c.uaMatch(P);if(P.browser){c.browser[P.browser]=true;c.browser.version=P.version}if(c.browser.webkit)c.browser.safari=
+true;if(ya)c.inArray=function(a,b){return ya.call(b,a)};T=c(s);if(s.addEventListener)L=function(){s.removeEventListener("DOMContentLoaded",L,false);c.ready()};else if(s.attachEvent)L=function(){if(s.readyState==="complete"){s.detachEvent("onreadystatechange",L);c.ready()}};(function(){c.support={};var a=s.documentElement,b=s.createElement("script"),d=s.createElement("div"),f="script"+J();d.style.display="none";d.innerHTML="   <link/><table></table><a href='/a' style='color:red;float:left;opacity:.55;'>a</a><input type='checkbox'/>";
+var e=d.getElementsByTagName("*"),j=d.getElementsByTagName("a")[0];if(!(!e||!e.length||!j)){c.support={leadingWhitespace:d.firstChild.nodeType===3,tbody:!d.getElementsByTagName("tbody").length,htmlSerialize:!!d.getElementsByTagName("link").length,style:/red/.test(j.getAttribute("style")),hrefNormalized:j.getAttribute("href")==="/a",opacity:/^0.55$/.test(j.style.opacity),cssFloat:!!j.style.cssFloat,checkOn:d.getElementsByTagName("input")[0].value==="on",optSelected:s.createElement("select").appendChild(s.createElement("option")).selected,
+parentNode:d.removeChild(d.appendChild(s.createElement("div"))).parentNode===null,deleteExpando:true,checkClone:false,scriptEval:false,noCloneEvent:true,boxModel:null};b.type="text/javascript";try{b.appendChild(s.createTextNode("window."+f+"=1;"))}catch(i){}a.insertBefore(b,a.firstChild);if(A[f]){c.support.scriptEval=true;delete A[f]}try{delete b.test}catch(o){c.support.deleteExpando=false}a.removeChild(b);if(d.attachEvent&&d.fireEvent){d.attachEvent("onclick",function k(){c.support.noCloneEvent=
+false;d.detachEvent("onclick",k)});d.cloneNode(true).fireEvent("onclick")}d=s.createElement("div");d.innerHTML="<input type='radio' name='radiotest' checked='checked'/>";a=s.createDocumentFragment();a.appendChild(d.firstChild);c.support.checkClone=a.cloneNode(true).cloneNode(true).lastChild.checked;c(function(){var k=s.createElement("div");k.style.width=k.style.paddingLeft="1px";s.body.appendChild(k);c.boxModel=c.support.boxModel=k.offsetWidth===2;s.body.removeChild(k).style.display="none"});a=function(k){var n=
+s.createElement("div");k="on"+k;var r=k in n;if(!r){n.setAttribute(k,"return;");r=typeof n[k]==="function"}return r};c.support.submitBubbles=a("submit");c.support.changeBubbles=a("change");a=b=d=e=j=null}})();c.props={"for":"htmlFor","class":"className",readonly:"readOnly",maxlength:"maxLength",cellspacing:"cellSpacing",rowspan:"rowSpan",colspan:"colSpan",tabindex:"tabIndex",usemap:"useMap",frameborder:"frameBorder"};var G="jQuery"+J(),Ya=0,za={};c.extend({cache:{},expando:G,noData:{embed:true,object:true,
+applet:true},data:function(a,b,d){if(!(a.nodeName&&c.noData[a.nodeName.toLowerCase()])){a=a==A?za:a;var f=a[G],e=c.cache;if(!f&&typeof b==="string"&&d===w)return null;f||(f=++Ya);if(typeof b==="object"){a[G]=f;e[f]=c.extend(true,{},b)}else if(!e[f]){a[G]=f;e[f]={}}a=e[f];if(d!==w)a[b]=d;return typeof b==="string"?a[b]:a}},removeData:function(a,b){if(!(a.nodeName&&c.noData[a.nodeName.toLowerCase()])){a=a==A?za:a;var d=a[G],f=c.cache,e=f[d];if(b){if(e){delete e[b];c.isEmptyObject(e)&&c.removeData(a)}}else{if(c.support.deleteExpando)delete a[c.expando];
+else a.removeAttribute&&a.removeAttribute(c.expando);delete f[d]}}}});c.fn.extend({data:function(a,b){if(typeof a==="undefined"&&this.length)return c.data(this[0]);else if(typeof a==="object")return this.each(function(){c.data(this,a)});var d=a.split(".");d[1]=d[1]?"."+d[1]:"";if(b===w){var f=this.triggerHandler("getData"+d[1]+"!",[d[0]]);if(f===w&&this.length)f=c.data(this[0],a);return f===w&&d[1]?this.data(d[0]):f}else return this.trigger("setData"+d[1]+"!",[d[0],b]).each(function(){c.data(this,
+a,b)})},removeData:function(a){return this.each(function(){c.removeData(this,a)})}});c.extend({queue:function(a,b,d){if(a){b=(b||"fx")+"queue";var f=c.data(a,b);if(!d)return f||[];if(!f||c.isArray(d))f=c.data(a,b,c.makeArray(d));else f.push(d);return f}},dequeue:function(a,b){b=b||"fx";var d=c.queue(a,b),f=d.shift();if(f==="inprogress")f=d.shift();if(f){b==="fx"&&d.unshift("inprogress");f.call(a,function(){c.dequeue(a,b)})}}});c.fn.extend({queue:function(a,b){if(typeof a!=="string"){b=a;a="fx"}if(b===
+w)return c.queue(this[0],a);return this.each(function(){var d=c.queue(this,a,b);a==="fx"&&d[0]!=="inprogress"&&c.dequeue(this,a)})},dequeue:function(a){return this.each(function(){c.dequeue(this,a)})},delay:function(a,b){a=c.fx?c.fx.speeds[a]||a:a;b=b||"fx";return this.queue(b,function(){var d=this;setTimeout(function(){c.dequeue(d,b)},a)})},clearQueue:function(a){return this.queue(a||"fx",[])}});var Aa=/[\n\t]/g,ca=/\s+/,Za=/\r/g,$a=/href|src|style/,ab=/(button|input)/i,bb=/(button|input|object|select|textarea)/i,
+cb=/^(a|area)$/i,Ba=/radio|checkbox/;c.fn.extend({attr:function(a,b){return X(this,a,b,true,c.attr)},removeAttr:function(a){return this.each(function(){c.attr(this,a,"");this.nodeType===1&&this.removeAttribute(a)})},addClass:function(a){if(c.isFunction(a))return this.each(function(n){var r=c(this);r.addClass(a.call(this,n,r.attr("class")))});if(a&&typeof a==="string")for(var b=(a||"").split(ca),d=0,f=this.length;d<f;d++){var e=this[d];if(e.nodeType===1)if(e.className){for(var j=" "+e.className+" ",
+i=e.className,o=0,k=b.length;o<k;o++)if(j.indexOf(" "+b[o]+" ")<0)i+=" "+b[o];e.className=c.trim(i)}else e.className=a}return this},removeClass:function(a){if(c.isFunction(a))return this.each(function(k){var n=c(this);n.removeClass(a.call(this,k,n.attr("class")))});if(a&&typeof a==="string"||a===w)for(var b=(a||"").split(ca),d=0,f=this.length;d<f;d++){var e=this[d];if(e.nodeType===1&&e.className)if(a){for(var j=(" "+e.className+" ").replace(Aa," "),i=0,o=b.length;i<o;i++)j=j.replace(" "+b[i]+" ",
+" ");e.className=c.trim(j)}else e.className=""}return this},toggleClass:function(a,b){var d=typeof a,f=typeof b==="boolean";if(c.isFunction(a))return this.each(function(e){var j=c(this);j.toggleClass(a.call(this,e,j.attr("class"),b),b)});return this.each(function(){if(d==="string")for(var e,j=0,i=c(this),o=b,k=a.split(ca);e=k[j++];){o=f?o:!i.hasClass(e);i[o?"addClass":"removeClass"](e)}else if(d==="undefined"||d==="boolean"){this.className&&c.data(this,"__className__",this.className);this.className=
+this.className||a===false?"":c.data(this,"__className__")||""}})},hasClass:function(a){a=" "+a+" ";for(var b=0,d=this.length;b<d;b++)if((" "+this[b].className+" ").replace(Aa," ").indexOf(a)>-1)return true;return false},val:function(a){if(a===w){var b=this[0];if(b){if(c.nodeName(b,"option"))return(b.attributes.value||{}).specified?b.value:b.text;if(c.nodeName(b,"select")){var d=b.selectedIndex,f=[],e=b.options;b=b.type==="select-one";if(d<0)return null;var j=b?d:0;for(d=b?d+1:e.length;j<d;j++){var i=
+e[j];if(i.selected){a=c(i).val();if(b)return a;f.push(a)}}return f}if(Ba.test(b.type)&&!c.support.checkOn)return b.getAttribute("value")===null?"on":b.value;return(b.value||"").replace(Za,"")}return w}var o=c.isFunction(a);return this.each(function(k){var n=c(this),r=a;if(this.nodeType===1){if(o)r=a.call(this,k,n.val());if(typeof r==="number")r+="";if(c.isArray(r)&&Ba.test(this.type))this.checked=c.inArray(n.val(),r)>=0;else if(c.nodeName(this,"select")){var u=c.makeArray(r);c("option",this).each(function(){this.selected=
+c.inArray(c(this).val(),u)>=0});if(!u.length)this.selectedIndex=-1}else this.value=r}})}});c.extend({attrFn:{val:true,css:true,html:true,text:true,data:true,width:true,height:true,offset:true},attr:function(a,b,d,f){if(!a||a.nodeType===3||a.nodeType===8)return w;if(f&&b in c.attrFn)return c(a)[b](d);f=a.nodeType!==1||!c.isXMLDoc(a);var e=d!==w;b=f&&c.props[b]||b;if(a.nodeType===1){var j=$a.test(b);if(b in a&&f&&!j){if(e){b==="type"&&ab.test(a.nodeName)&&a.parentNode&&c.error("type property can't be changed");
+a[b]=d}if(c.nodeName(a,"form")&&a.getAttributeNode(b))return a.getAttributeNode(b).nodeValue;if(b==="tabIndex")return(b=a.getAttributeNode("tabIndex"))&&b.specified?b.value:bb.test(a.nodeName)||cb.test(a.nodeName)&&a.href?0:w;return a[b]}if(!c.support.style&&f&&b==="style"){if(e)a.style.cssText=""+d;return a.style.cssText}e&&a.setAttribute(b,""+d);a=!c.support.hrefNormalized&&f&&j?a.getAttribute(b,2):a.getAttribute(b);return a===null?w:a}return c.style(a,b,d)}});var O=/\.(.*)$/,db=function(a){return a.replace(/[^\w\s\.\|`]/g,
+function(b){return"\\"+b})};c.event={add:function(a,b,d,f){if(!(a.nodeType===3||a.nodeType===8)){if(a.setInterval&&a!==A&&!a.frameElement)a=A;var e,j;if(d.handler){e=d;d=e.handler}if(!d.guid)d.guid=c.guid++;if(j=c.data(a)){var i=j.events=j.events||{},o=j.handle;if(!o)j.handle=o=function(){return typeof c!=="undefined"&&!c.event.triggered?c.event.handle.apply(o.elem,arguments):w};o.elem=a;b=b.split(" ");for(var k,n=0,r;k=b[n++];){j=e?c.extend({},e):{handler:d,data:f};if(k.indexOf(".")>-1){r=k.split(".");
+k=r.shift();j.namespace=r.slice(0).sort().join(".")}else{r=[];j.namespace=""}j.type=k;j.guid=d.guid;var u=i[k],z=c.event.special[k]||{};if(!u){u=i[k]=[];if(!z.setup||z.setup.call(a,f,r,o)===false)if(a.addEventListener)a.addEventListener(k,o,false);else a.attachEvent&&a.attachEvent("on"+k,o)}if(z.add){z.add.call(a,j);if(!j.handler.guid)j.handler.guid=d.guid}u.push(j);c.event.global[k]=true}a=null}}},global:{},remove:function(a,b,d,f){if(!(a.nodeType===3||a.nodeType===8)){var e,j=0,i,o,k,n,r,u,z=c.data(a),
+C=z&&z.events;if(z&&C){if(b&&b.type){d=b.handler;b=b.type}if(!b||typeof b==="string"&&b.charAt(0)==="."){b=b||"";for(e in C)c.event.remove(a,e+b)}else{for(b=b.split(" ");e=b[j++];){n=e;i=e.indexOf(".")<0;o=[];if(!i){o=e.split(".");e=o.shift();k=new RegExp("(^|\\.)"+c.map(o.slice(0).sort(),db).join("\\.(?:.*\\.)?")+"(\\.|$)")}if(r=C[e])if(d){n=c.event.special[e]||{};for(B=f||0;B<r.length;B++){u=r[B];if(d.guid===u.guid){if(i||k.test(u.namespace)){f==null&&r.splice(B--,1);n.remove&&n.remove.call(a,u)}if(f!=
+null)break}}if(r.length===0||f!=null&&r.length===1){if(!n.teardown||n.teardown.call(a,o)===false)Ca(a,e,z.handle);delete C[e]}}else for(var B=0;B<r.length;B++){u=r[B];if(i||k.test(u.namespace)){c.event.remove(a,n,u.handler,B);r.splice(B--,1)}}}if(c.isEmptyObject(C)){if(b=z.handle)b.elem=null;delete z.events;delete z.handle;c.isEmptyObject(z)&&c.removeData(a)}}}}},trigger:function(a,b,d,f){var e=a.type||a;if(!f){a=typeof a==="object"?a[G]?a:c.extend(c.Event(e),a):c.Event(e);if(e.indexOf("!")>=0){a.type=
+e=e.slice(0,-1);a.exclusive=true}if(!d){a.stopPropagation();c.event.global[e]&&c.each(c.cache,function(){this.events&&this.events[e]&&c.event.trigger(a,b,this.handle.elem)})}if(!d||d.nodeType===3||d.nodeType===8)return w;a.result=w;a.target=d;b=c.makeArray(b);b.unshift(a)}a.currentTarget=d;(f=c.data(d,"handle"))&&f.apply(d,b);f=d.parentNode||d.ownerDocument;try{if(!(d&&d.nodeName&&c.noData[d.nodeName.toLowerCase()]))if(d["on"+e]&&d["on"+e].apply(d,b)===false)a.result=false}catch(j){}if(!a.isPropagationStopped()&&
+f)c.event.trigger(a,b,f,true);else if(!a.isDefaultPrevented()){f=a.target;var i,o=c.nodeName(f,"a")&&e==="click",k=c.event.special[e]||{};if((!k._default||k._default.call(d,a)===false)&&!o&&!(f&&f.nodeName&&c.noData[f.nodeName.toLowerCase()])){try{if(f[e]){if(i=f["on"+e])f["on"+e]=null;c.event.triggered=true;f[e]()}}catch(n){}if(i)f["on"+e]=i;c.event.triggered=false}}},handle:function(a){var b,d,f,e;a=arguments[0]=c.event.fix(a||A.event);a.currentTarget=this;b=a.type.indexOf(".")<0&&!a.exclusive;
+if(!b){d=a.type.split(".");a.type=d.shift();f=new RegExp("(^|\\.)"+d.slice(0).sort().join("\\.(?:.*\\.)?")+"(\\.|$)")}e=c.data(this,"events");d=e[a.type];if(e&&d){d=d.slice(0);e=0;for(var j=d.length;e<j;e++){var i=d[e];if(b||f.test(i.namespace)){a.handler=i.handler;a.data=i.data;a.handleObj=i;i=i.handler.apply(this,arguments);if(i!==w){a.result=i;if(i===false){a.preventDefault();a.stopPropagation()}}if(a.isImmediatePropagationStopped())break}}}return a.result},props:"altKey attrChange attrName bubbles button cancelable charCode clientX clientY ctrlKey currentTarget data detail eventPhase fromElement handler keyCode layerX layerY metaKey newValue offsetX offsetY originalTarget pageX pageY prevValue relatedNode relatedTarget screenX screenY shiftKey srcElement target toElement view wheelDelta which".split(" "),
+fix:function(a){if(a[G])return a;var b=a;a=c.Event(b);for(var d=this.props.length,f;d;){f=this.props[--d];a[f]=b[f]}if(!a.target)a.target=a.srcElement||s;if(a.target.nodeType===3)a.target=a.target.parentNode;if(!a.relatedTarget&&a.fromElement)a.relatedTarget=a.fromElement===a.target?a.toElement:a.fromElement;if(a.pageX==null&&a.clientX!=null){b=s.documentElement;d=s.body;a.pageX=a.clientX+(b&&b.scrollLeft||d&&d.scrollLeft||0)-(b&&b.clientLeft||d&&d.clientLeft||0);a.pageY=a.clientY+(b&&b.scrollTop||
+d&&d.scrollTop||0)-(b&&b.clientTop||d&&d.clientTop||0)}if(!a.which&&(a.charCode||a.charCode===0?a.charCode:a.keyCode))a.which=a.charCode||a.keyCode;if(!a.metaKey&&a.ctrlKey)a.metaKey=a.ctrlKey;if(!a.which&&a.button!==w)a.which=a.button&1?1:a.button&2?3:a.button&4?2:0;return a},guid:1E8,proxy:c.proxy,special:{ready:{setup:c.bindReady,teardown:c.noop},live:{add:function(a){c.event.add(this,a.origType,c.extend({},a,{handler:oa}))},remove:function(a){var b=true,d=a.origType.replace(O,"");c.each(c.data(this,
+"events").live||[],function(){if(d===this.origType.replace(O,""))return b=false});b&&c.event.remove(this,a.origType,oa)}},beforeunload:{setup:function(a,b,d){if(this.setInterval)this.onbeforeunload=d;return false},teardown:function(a,b){if(this.onbeforeunload===b)this.onbeforeunload=null}}}};var Ca=s.removeEventListener?function(a,b,d){a.removeEventListener(b,d,false)}:function(a,b,d){a.detachEvent("on"+b,d)};c.Event=function(a){if(!this.preventDefault)return new c.Event(a);if(a&&a.type){this.originalEvent=
+a;this.type=a.type}else this.type=a;this.timeStamp=J();this[G]=true};c.Event.prototype={preventDefault:function(){this.isDefaultPrevented=Z;var a=this.originalEvent;if(a){a.preventDefault&&a.preventDefault();a.returnValue=false}},stopPropagation:function(){this.isPropagationStopped=Z;var a=this.originalEvent;if(a){a.stopPropagation&&a.stopPropagation();a.cancelBubble=true}},stopImmediatePropagation:function(){this.isImmediatePropagationStopped=Z;this.stopPropagation()},isDefaultPrevented:Y,isPropagationStopped:Y,
+isImmediatePropagationStopped:Y};var Da=function(a){var b=a.relatedTarget;try{for(;b&&b!==this;)b=b.parentNode;if(b!==this){a.type=a.data;c.event.handle.apply(this,arguments)}}catch(d){}},Ea=function(a){a.type=a.data;c.event.handle.apply(this,arguments)};c.each({mouseenter:"mouseover",mouseleave:"mouseout"},function(a,b){c.event.special[a]={setup:function(d){c.event.add(this,b,d&&d.selector?Ea:Da,a)},teardown:function(d){c.event.remove(this,b,d&&d.selector?Ea:Da)}}});if(!c.support.submitBubbles)c.event.special.submit=
+{setup:function(){if(this.nodeName.toLowerCase()!=="form"){c.event.add(this,"click.specialSubmit",function(a){var b=a.target,d=b.type;if((d==="submit"||d==="image")&&c(b).closest("form").length)return na("submit",this,arguments)});c.event.add(this,"keypress.specialSubmit",function(a){var b=a.target,d=b.type;if((d==="text"||d==="password")&&c(b).closest("form").length&&a.keyCode===13)return na("submit",this,arguments)})}else return false},teardown:function(){c.event.remove(this,".specialSubmit")}};
+if(!c.support.changeBubbles){var da=/textarea|input|select/i,ea,Fa=function(a){var b=a.type,d=a.value;if(b==="radio"||b==="checkbox")d=a.checked;else if(b==="select-multiple")d=a.selectedIndex>-1?c.map(a.options,function(f){return f.selected}).join("-"):"";else if(a.nodeName.toLowerCase()==="select")d=a.selectedIndex;return d},fa=function(a,b){var d=a.target,f,e;if(!(!da.test(d.nodeName)||d.readOnly)){f=c.data(d,"_change_data");e=Fa(d);if(a.type!=="focusout"||d.type!=="radio")c.data(d,"_change_data",
+e);if(!(f===w||e===f))if(f!=null||e){a.type="change";return c.event.trigger(a,b,d)}}};c.event.special.change={filters:{focusout:fa,click:function(a){var b=a.target,d=b.type;if(d==="radio"||d==="checkbox"||b.nodeName.toLowerCase()==="select")return fa.call(this,a)},keydown:function(a){var b=a.target,d=b.type;if(a.keyCode===13&&b.nodeName.toLowerCase()!=="textarea"||a.keyCode===32&&(d==="checkbox"||d==="radio")||d==="select-multiple")return fa.call(this,a)},beforeactivate:function(a){a=a.target;c.data(a,
+"_change_data",Fa(a))}},setup:function(){if(this.type==="file")return false;for(var a in ea)c.event.add(this,a+".specialChange",ea[a]);return da.test(this.nodeName)},teardown:function(){c.event.remove(this,".specialChange");return da.test(this.nodeName)}};ea=c.event.special.change.filters}s.addEventListener&&c.each({focus:"focusin",blur:"focusout"},function(a,b){function d(f){f=c.event.fix(f);f.type=b;return c.event.handle.call(this,f)}c.event.special[b]={setup:function(){this.addEventListener(a,
+d,true)},teardown:function(){this.removeEventListener(a,d,true)}}});c.each(["bind","one"],function(a,b){c.fn[b]=function(d,f,e){if(typeof d==="object"){for(var j in d)this[b](j,f,d[j],e);return this}if(c.isFunction(f)){e=f;f=w}var i=b==="one"?c.proxy(e,function(k){c(this).unbind(k,i);return e.apply(this,arguments)}):e;if(d==="unload"&&b!=="one")this.one(d,f,e);else{j=0;for(var o=this.length;j<o;j++)c.event.add(this[j],d,i,f)}return this}});c.fn.extend({unbind:function(a,b){if(typeof a==="object"&&
+!a.preventDefault)for(var d in a)this.unbind(d,a[d]);else{d=0;for(var f=this.length;d<f;d++)c.event.remove(this[d],a,b)}return this},delegate:function(a,b,d,f){return this.live(b,d,f,a)},undelegate:function(a,b,d){return arguments.length===0?this.unbind("live"):this.die(b,null,d,a)},trigger:function(a,b){return this.each(function(){c.event.trigger(a,b,this)})},triggerHandler:function(a,b){if(this[0]){a=c.Event(a);a.preventDefault();a.stopPropagation();c.event.trigger(a,b,this[0]);return a.result}},
+toggle:function(a){for(var b=arguments,d=1;d<b.length;)c.proxy(a,b[d++]);return this.click(c.proxy(a,function(f){var e=(c.data(this,"lastToggle"+a.guid)||0)%d;c.data(this,"lastToggle"+a.guid,e+1);f.preventDefault();return b[e].apply(this,arguments)||false}))},hover:function(a,b){return this.mouseenter(a).mouseleave(b||a)}});var Ga={focus:"focusin",blur:"focusout",mouseenter:"mouseover",mouseleave:"mouseout"};c.each(["live","die"],function(a,b){c.fn[b]=function(d,f,e,j){var i,o=0,k,n,r=j||this.selector,
+u=j?this:c(this.context);if(c.isFunction(f)){e=f;f=w}for(d=(d||"").split(" ");(i=d[o++])!=null;){j=O.exec(i);k="";if(j){k=j[0];i=i.replace(O,"")}if(i==="hover")d.push("mouseenter"+k,"mouseleave"+k);else{n=i;if(i==="focus"||i==="blur"){d.push(Ga[i]+k);i+=k}else i=(Ga[i]||i)+k;b==="live"?u.each(function(){c.event.add(this,pa(i,r),{data:f,selector:r,handler:e,origType:i,origHandler:e,preType:n})}):u.unbind(pa(i,r),e)}}return this}});c.each("blur focus focusin focusout load resize scroll unload click dblclick mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave change select submit keydown keypress keyup error".split(" "),
+function(a,b){c.fn[b]=function(d){return d?this.bind(b,d):this.trigger(b)};if(c.attrFn)c.attrFn[b]=true});A.attachEvent&&!A.addEventListener&&A.attachEvent("onunload",function(){for(var a in c.cache)if(c.cache[a].handle)try{c.event.remove(c.cache[a].handle.elem)}catch(b){}});(function(){function a(g){for(var h="",l,m=0;g[m];m++){l=g[m];if(l.nodeType===3||l.nodeType===4)h+=l.nodeValue;else if(l.nodeType!==8)h+=a(l.childNodes)}return h}function b(g,h,l,m,q,p){q=0;for(var v=m.length;q<v;q++){var t=m[q];
+if(t){t=t[g];for(var y=false;t;){if(t.sizcache===l){y=m[t.sizset];break}if(t.nodeType===1&&!p){t.sizcache=l;t.sizset=q}if(t.nodeName.toLowerCase()===h){y=t;break}t=t[g]}m[q]=y}}}function d(g,h,l,m,q,p){q=0;for(var v=m.length;q<v;q++){var t=m[q];if(t){t=t[g];for(var y=false;t;){if(t.sizcache===l){y=m[t.sizset];break}if(t.nodeType===1){if(!p){t.sizcache=l;t.sizset=q}if(typeof h!=="string"){if(t===h){y=true;break}}else if(k.filter(h,[t]).length>0){y=t;break}}t=t[g]}m[q]=y}}}var f=/((?:\((?:\([^()]+\)|[^()]+)+\)|\[(?:\[[^[\]]*\]|['"][^'"]*['"]|[^[\]'"]+)+\]|\\.|[^ >+~,(\[\\]+)+|[>+~])(\s*,\s*)?((?:.|\r|\n)*)/g,
+e=0,j=Object.prototype.toString,i=false,o=true;[0,0].sort(function(){o=false;return 0});var k=function(g,h,l,m){l=l||[];var q=h=h||s;if(h.nodeType!==1&&h.nodeType!==9)return[];if(!g||typeof g!=="string")return l;for(var p=[],v,t,y,S,H=true,M=x(h),I=g;(f.exec(""),v=f.exec(I))!==null;){I=v[3];p.push(v[1]);if(v[2]){S=v[3];break}}if(p.length>1&&r.exec(g))if(p.length===2&&n.relative[p[0]])t=ga(p[0]+p[1],h);else for(t=n.relative[p[0]]?[h]:k(p.shift(),h);p.length;){g=p.shift();if(n.relative[g])g+=p.shift();
+t=ga(g,t)}else{if(!m&&p.length>1&&h.nodeType===9&&!M&&n.match.ID.test(p[0])&&!n.match.ID.test(p[p.length-1])){v=k.find(p.shift(),h,M);h=v.expr?k.filter(v.expr,v.set)[0]:v.set[0]}if(h){v=m?{expr:p.pop(),set:z(m)}:k.find(p.pop(),p.length===1&&(p[0]==="~"||p[0]==="+")&&h.parentNode?h.parentNode:h,M);t=v.expr?k.filter(v.expr,v.set):v.set;if(p.length>0)y=z(t);else H=false;for(;p.length;){var D=p.pop();v=D;if(n.relative[D])v=p.pop();else D="";if(v==null)v=h;n.relative[D](y,v,M)}}else y=[]}y||(y=t);y||k.error(D||
+g);if(j.call(y)==="[object Array]")if(H)if(h&&h.nodeType===1)for(g=0;y[g]!=null;g++){if(y[g]&&(y[g]===true||y[g].nodeType===1&&E(h,y[g])))l.push(t[g])}else for(g=0;y[g]!=null;g++)y[g]&&y[g].nodeType===1&&l.push(t[g]);else l.push.apply(l,y);else z(y,l);if(S){k(S,q,l,m);k.uniqueSort(l)}return l};k.uniqueSort=function(g){if(B){i=o;g.sort(B);if(i)for(var h=1;h<g.length;h++)g[h]===g[h-1]&&g.splice(h--,1)}return g};k.matches=function(g,h){return k(g,null,null,h)};k.find=function(g,h,l){var m,q;if(!g)return[];
+for(var p=0,v=n.order.length;p<v;p++){var t=n.order[p];if(q=n.leftMatch[t].exec(g)){var y=q[1];q.splice(1,1);if(y.substr(y.length-1)!=="\\"){q[1]=(q[1]||"").replace(/\\/g,"");m=n.find[t](q,h,l);if(m!=null){g=g.replace(n.match[t],"");break}}}}m||(m=h.getElementsByTagName("*"));return{set:m,expr:g}};k.filter=function(g,h,l,m){for(var q=g,p=[],v=h,t,y,S=h&&h[0]&&x(h[0]);g&&h.length;){for(var H in n.filter)if((t=n.leftMatch[H].exec(g))!=null&&t[2]){var M=n.filter[H],I,D;D=t[1];y=false;t.splice(1,1);if(D.substr(D.length-
+1)!=="\\"){if(v===p)p=[];if(n.preFilter[H])if(t=n.preFilter[H](t,v,l,p,m,S)){if(t===true)continue}else y=I=true;if(t)for(var U=0;(D=v[U])!=null;U++)if(D){I=M(D,t,U,v);var Ha=m^!!I;if(l&&I!=null)if(Ha)y=true;else v[U]=false;else if(Ha){p.push(D);y=true}}if(I!==w){l||(v=p);g=g.replace(n.match[H],"");if(!y)return[];break}}}if(g===q)if(y==null)k.error(g);else break;q=g}return v};k.error=function(g){throw"Syntax error, unrecognized expression: "+g;};var n=k.selectors={order:["ID","NAME","TAG"],match:{ID:/#((?:[\w\u00c0-\uFFFF-]|\\.)+)/,
+CLASS:/\.((?:[\w\u00c0-\uFFFF-]|\\.)+)/,NAME:/\[name=['"]*((?:[\w\u00c0-\uFFFF-]|\\.)+)['"]*\]/,ATTR:/\[\s*((?:[\w\u00c0-\uFFFF-]|\\.)+)\s*(?:(\S?=)\s*(['"]*)(.*?)\3|)\s*\]/,TAG:/^((?:[\w\u00c0-\uFFFF\*-]|\\.)+)/,CHILD:/:(only|nth|last|first)-child(?:\((even|odd|[\dn+-]*)\))?/,POS:/:(nth|eq|gt|lt|first|last|even|odd)(?:\((\d*)\))?(?=[^-]|$)/,PSEUDO:/:((?:[\w\u00c0-\uFFFF-]|\\.)+)(?:\((['"]?)((?:\([^\)]+\)|[^\(\)]*)+)\2\))?/},leftMatch:{},attrMap:{"class":"className","for":"htmlFor"},attrHandle:{href:function(g){return g.getAttribute("href")}},
+relative:{"+":function(g,h){var l=typeof h==="string",m=l&&!/\W/.test(h);l=l&&!m;if(m)h=h.toLowerCase();m=0;for(var q=g.length,p;m<q;m++)if(p=g[m]){for(;(p=p.previousSibling)&&p.nodeType!==1;);g[m]=l||p&&p.nodeName.toLowerCase()===h?p||false:p===h}l&&k.filter(h,g,true)},">":function(g,h){var l=typeof h==="string";if(l&&!/\W/.test(h)){h=h.toLowerCase();for(var m=0,q=g.length;m<q;m++){var p=g[m];if(p){l=p.parentNode;g[m]=l.nodeName.toLowerCase()===h?l:false}}}else{m=0;for(q=g.length;m<q;m++)if(p=g[m])g[m]=
+l?p.parentNode:p.parentNode===h;l&&k.filter(h,g,true)}},"":function(g,h,l){var m=e++,q=d;if(typeof h==="string"&&!/\W/.test(h)){var p=h=h.toLowerCase();q=b}q("parentNode",h,m,g,p,l)},"~":function(g,h,l){var m=e++,q=d;if(typeof h==="string"&&!/\W/.test(h)){var p=h=h.toLowerCase();q=b}q("previousSibling",h,m,g,p,l)}},find:{ID:function(g,h,l){if(typeof h.getElementById!=="undefined"&&!l)return(g=h.getElementById(g[1]))?[g]:[]},NAME:function(g,h){if(typeof h.getElementsByName!=="undefined"){var l=[];
+h=h.getElementsByName(g[1]);for(var m=0,q=h.length;m<q;m++)h[m].getAttribute("name")===g[1]&&l.push(h[m]);return l.length===0?null:l}},TAG:function(g,h){return h.getElementsByTagName(g[1])}},preFilter:{CLASS:function(g,h,l,m,q,p){g=" "+g[1].replace(/\\/g,"")+" ";if(p)return g;p=0;for(var v;(v=h[p])!=null;p++)if(v)if(q^(v.className&&(" "+v.className+" ").replace(/[\t\n]/g," ").indexOf(g)>=0))l||m.push(v);else if(l)h[p]=false;return false},ID:function(g){return g[1].replace(/\\/g,"")},TAG:function(g){return g[1].toLowerCase()},
+CHILD:function(g){if(g[1]==="nth"){var h=/(-?)(\d*)n((?:\+|-)?\d*)/.exec(g[2]==="even"&&"2n"||g[2]==="odd"&&"2n+1"||!/\D/.test(g[2])&&"0n+"+g[2]||g[2]);g[2]=h[1]+(h[2]||1)-0;g[3]=h[3]-0}g[0]=e++;return g},ATTR:function(g,h,l,m,q,p){h=g[1].replace(/\\/g,"");if(!p&&n.attrMap[h])g[1]=n.attrMap[h];if(g[2]==="~=")g[4]=" "+g[4]+" ";return g},PSEUDO:function(g,h,l,m,q){if(g[1]==="not")if((f.exec(g[3])||"").length>1||/^\w/.test(g[3]))g[3]=k(g[3],null,null,h);else{g=k.filter(g[3],h,l,true^q);l||m.push.apply(m,
+g);return false}else if(n.match.POS.test(g[0])||n.match.CHILD.test(g[0]))return true;return g},POS:function(g){g.unshift(true);return g}},filters:{enabled:function(g){return g.disabled===false&&g.type!=="hidden"},disabled:function(g){return g.disabled===true},checked:function(g){return g.checked===true},selected:function(g){return g.selected===true},parent:function(g){return!!g.firstChild},empty:function(g){return!g.firstChild},has:function(g,h,l){return!!k(l[3],g).length},header:function(g){return/h\d/i.test(g.nodeName)},
+text:function(g){return"text"===g.type},radio:function(g){return"radio"===g.type},checkbox:function(g){return"checkbox"===g.type},file:function(g){return"file"===g.type},password:function(g){return"password"===g.type},submit:function(g){return"submit"===g.type},image:function(g){return"image"===g.type},reset:function(g){return"reset"===g.type},button:function(g){return"button"===g.type||g.nodeName.toLowerCase()==="button"},input:function(g){return/input|select|textarea|button/i.test(g.nodeName)}},
+setFilters:{first:function(g,h){return h===0},last:function(g,h,l,m){return h===m.length-1},even:function(g,h){return h%2===0},odd:function(g,h){return h%2===1},lt:function(g,h,l){return h<l[3]-0},gt:function(g,h,l){return h>l[3]-0},nth:function(g,h,l){return l[3]-0===h},eq:function(g,h,l){return l[3]-0===h}},filter:{PSEUDO:function(g,h,l,m){var q=h[1],p=n.filters[q];if(p)return p(g,l,h,m);else if(q==="contains")return(g.textContent||g.innerText||a([g])||"").indexOf(h[3])>=0;else if(q==="not"){h=
+h[3];l=0;for(m=h.length;l<m;l++)if(h[l]===g)return false;return true}else k.error("Syntax error, unrecognized expression: "+q)},CHILD:function(g,h){var l=h[1],m=g;switch(l){case "only":case "first":for(;m=m.previousSibling;)if(m.nodeType===1)return false;if(l==="first")return true;m=g;case "last":for(;m=m.nextSibling;)if(m.nodeType===1)return false;return true;case "nth":l=h[2];var q=h[3];if(l===1&&q===0)return true;h=h[0];var p=g.parentNode;if(p&&(p.sizcache!==h||!g.nodeIndex)){var v=0;for(m=p.firstChild;m;m=
+m.nextSibling)if(m.nodeType===1)m.nodeIndex=++v;p.sizcache=h}g=g.nodeIndex-q;return l===0?g===0:g%l===0&&g/l>=0}},ID:function(g,h){return g.nodeType===1&&g.getAttribute("id")===h},TAG:function(g,h){return h==="*"&&g.nodeType===1||g.nodeName.toLowerCase()===h},CLASS:function(g,h){return(" "+(g.className||g.getAttribute("class"))+" ").indexOf(h)>-1},ATTR:function(g,h){var l=h[1];g=n.attrHandle[l]?n.attrHandle[l](g):g[l]!=null?g[l]:g.getAttribute(l);l=g+"";var m=h[2];h=h[4];return g==null?m==="!=":m===
+"="?l===h:m==="*="?l.indexOf(h)>=0:m==="~="?(" "+l+" ").indexOf(h)>=0:!h?l&&g!==false:m==="!="?l!==h:m==="^="?l.indexOf(h)===0:m==="$="?l.substr(l.length-h.length)===h:m==="|="?l===h||l.substr(0,h.length+1)===h+"-":false},POS:function(g,h,l,m){var q=n.setFilters[h[2]];if(q)return q(g,l,h,m)}}},r=n.match.POS;for(var u in n.match){n.match[u]=new RegExp(n.match[u].source+/(?![^\[]*\])(?![^\(]*\))/.source);n.leftMatch[u]=new RegExp(/(^(?:.|\r|\n)*?)/.source+n.match[u].source.replace(/\\(\d+)/g,function(g,
+h){return"\\"+(h-0+1)}))}var z=function(g,h){g=Array.prototype.slice.call(g,0);if(h){h.push.apply(h,g);return h}return g};try{Array.prototype.slice.call(s.documentElement.childNodes,0)}catch(C){z=function(g,h){h=h||[];if(j.call(g)==="[object Array]")Array.prototype.push.apply(h,g);else if(typeof g.length==="number")for(var l=0,m=g.length;l<m;l++)h.push(g[l]);else for(l=0;g[l];l++)h.push(g[l]);return h}}var B;if(s.documentElement.compareDocumentPosition)B=function(g,h){if(!g.compareDocumentPosition||
+!h.compareDocumentPosition){if(g==h)i=true;return g.compareDocumentPosition?-1:1}g=g.compareDocumentPosition(h)&4?-1:g===h?0:1;if(g===0)i=true;return g};else if("sourceIndex"in s.documentElement)B=function(g,h){if(!g.sourceIndex||!h.sourceIndex){if(g==h)i=true;return g.sourceIndex?-1:1}g=g.sourceIndex-h.sourceIndex;if(g===0)i=true;return g};else if(s.createRange)B=function(g,h){if(!g.ownerDocument||!h.ownerDocument){if(g==h)i=true;return g.ownerDocument?-1:1}var l=g.ownerDocument.createRange(),m=
+h.ownerDocument.createRange();l.setStart(g,0);l.setEnd(g,0);m.setStart(h,0);m.setEnd(h,0);g=l.compareBoundaryPoints(Range.START_TO_END,m);if(g===0)i=true;return g};(function(){var g=s.createElement("div"),h="script"+(new Date).getTime();g.innerHTML="<a name='"+h+"'/>";var l=s.documentElement;l.insertBefore(g,l.firstChild);if(s.getElementById(h)){n.find.ID=function(m,q,p){if(typeof q.getElementById!=="undefined"&&!p)return(q=q.getElementById(m[1]))?q.id===m[1]||typeof q.getAttributeNode!=="undefined"&&
+q.getAttributeNode("id").nodeValue===m[1]?[q]:w:[]};n.filter.ID=function(m,q){var p=typeof m.getAttributeNode!=="undefined"&&m.getAttributeNode("id");return m.nodeType===1&&p&&p.nodeValue===q}}l.removeChild(g);l=g=null})();(function(){var g=s.createElement("div");g.appendChild(s.createComment(""));if(g.getElementsByTagName("*").length>0)n.find.TAG=function(h,l){l=l.getElementsByTagName(h[1]);if(h[1]==="*"){h=[];for(var m=0;l[m];m++)l[m].nodeType===1&&h.push(l[m]);l=h}return l};g.innerHTML="<a href='#'></a>";
+if(g.firstChild&&typeof g.firstChild.getAttribute!=="undefined"&&g.firstChild.getAttribute("href")!=="#")n.attrHandle.href=function(h){return h.getAttribute("href",2)};g=null})();s.querySelectorAll&&function(){var g=k,h=s.createElement("div");h.innerHTML="<p class='TEST'></p>";if(!(h.querySelectorAll&&h.querySelectorAll(".TEST").length===0)){k=function(m,q,p,v){q=q||s;if(!v&&q.nodeType===9&&!x(q))try{return z(q.querySelectorAll(m),p)}catch(t){}return g(m,q,p,v)};for(var l in g)k[l]=g[l];h=null}}();
+(function(){var g=s.createElement("div");g.innerHTML="<div class='test e'></div><div class='test'></div>";if(!(!g.getElementsByClassName||g.getElementsByClassName("e").length===0)){g.lastChild.className="e";if(g.getElementsByClassName("e").length!==1){n.order.splice(1,0,"CLASS");n.find.CLASS=function(h,l,m){if(typeof l.getElementsByClassName!=="undefined"&&!m)return l.getElementsByClassName(h[1])};g=null}}})();var E=s.compareDocumentPosition?function(g,h){return!!(g.compareDocumentPosition(h)&16)}:
+function(g,h){return g!==h&&(g.contains?g.contains(h):true)},x=function(g){return(g=(g?g.ownerDocument||g:0).documentElement)?g.nodeName!=="HTML":false},ga=function(g,h){var l=[],m="",q;for(h=h.nodeType?[h]:h;q=n.match.PSEUDO.exec(g);){m+=q[0];g=g.replace(n.match.PSEUDO,"")}g=n.relative[g]?g+"*":g;q=0;for(var p=h.length;q<p;q++)k(g,h[q],l);return k.filter(m,l)};c.find=k;c.expr=k.selectors;c.expr[":"]=c.expr.filters;c.unique=k.uniqueSort;c.text=a;c.isXMLDoc=x;c.contains=E})();var eb=/Until$/,fb=/^(?:parents|prevUntil|prevAll)/,
+gb=/,/;R=Array.prototype.slice;var Ia=function(a,b,d){if(c.isFunction(b))return c.grep(a,function(e,j){return!!b.call(e,j,e)===d});else if(b.nodeType)return c.grep(a,function(e){return e===b===d});else if(typeof b==="string"){var f=c.grep(a,function(e){return e.nodeType===1});if(Ua.test(b))return c.filter(b,f,!d);else b=c.filter(b,f)}return c.grep(a,function(e){return c.inArray(e,b)>=0===d})};c.fn.extend({find:function(a){for(var b=this.pushStack("","find",a),d=0,f=0,e=this.length;f<e;f++){d=b.length;
+c.find(a,this[f],b);if(f>0)for(var j=d;j<b.length;j++)for(var i=0;i<d;i++)if(b[i]===b[j]){b.splice(j--,1);break}}return b},has:function(a){var b=c(a);return this.filter(function(){for(var d=0,f=b.length;d<f;d++)if(c.contains(this,b[d]))return true})},not:function(a){return this.pushStack(Ia(this,a,false),"not",a)},filter:function(a){return this.pushStack(Ia(this,a,true),"filter",a)},is:function(a){return!!a&&c.filter(a,this).length>0},closest:function(a,b){if(c.isArray(a)){var d=[],f=this[0],e,j=
+{},i;if(f&&a.length){e=0;for(var o=a.length;e<o;e++){i=a[e];j[i]||(j[i]=c.expr.match.POS.test(i)?c(i,b||this.context):i)}for(;f&&f.ownerDocument&&f!==b;){for(i in j){e=j[i];if(e.jquery?e.index(f)>-1:c(f).is(e)){d.push({selector:i,elem:f});delete j[i]}}f=f.parentNode}}return d}var k=c.expr.match.POS.test(a)?c(a,b||this.context):null;return this.map(function(n,r){for(;r&&r.ownerDocument&&r!==b;){if(k?k.index(r)>-1:c(r).is(a))return r;r=r.parentNode}return null})},index:function(a){if(!a||typeof a===
+"string")return c.inArray(this[0],a?c(a):this.parent().children());return c.inArray(a.jquery?a[0]:a,this)},add:function(a,b){a=typeof a==="string"?c(a,b||this.context):c.makeArray(a);b=c.merge(this.get(),a);return this.pushStack(qa(a[0])||qa(b[0])?b:c.unique(b))},andSelf:function(){return this.add(this.prevObject)}});c.each({parent:function(a){return(a=a.parentNode)&&a.nodeType!==11?a:null},parents:function(a){return c.dir(a,"parentNode")},parentsUntil:function(a,b,d){return c.dir(a,"parentNode",
+d)},next:function(a){return c.nth(a,2,"nextSibling")},prev:function(a){return c.nth(a,2,"previousSibling")},nextAll:function(a){return c.dir(a,"nextSibling")},prevAll:function(a){return c.dir(a,"previousSibling")},nextUntil:function(a,b,d){return c.dir(a,"nextSibling",d)},prevUntil:function(a,b,d){return c.dir(a,"previousSibling",d)},siblings:function(a){return c.sibling(a.parentNode.firstChild,a)},children:function(a){return c.sibling(a.firstChild)},contents:function(a){return c.nodeName(a,"iframe")?
+a.contentDocument||a.contentWindow.document:c.makeArray(a.childNodes)}},function(a,b){c.fn[a]=function(d,f){var e=c.map(this,b,d);eb.test(a)||(f=d);if(f&&typeof f==="string")e=c.filter(f,e);e=this.length>1?c.unique(e):e;if((this.length>1||gb.test(f))&&fb.test(a))e=e.reverse();return this.pushStack(e,a,R.call(arguments).join(","))}});c.extend({filter:function(a,b,d){if(d)a=":not("+a+")";return c.find.matches(a,b)},dir:function(a,b,d){var f=[];for(a=a[b];a&&a.nodeType!==9&&(d===w||a.nodeType!==1||!c(a).is(d));){a.nodeType===
+1&&f.push(a);a=a[b]}return f},nth:function(a,b,d){b=b||1;for(var f=0;a;a=a[d])if(a.nodeType===1&&++f===b)break;return a},sibling:function(a,b){for(var d=[];a;a=a.nextSibling)a.nodeType===1&&a!==b&&d.push(a);return d}});var Ja=/ jQuery\d+="(?:\d+|null)"/g,V=/^\s+/,Ka=/(<([\w:]+)[^>]*?)\/>/g,hb=/^(?:area|br|col|embed|hr|img|input|link|meta|param)$/i,La=/<([\w:]+)/,ib=/<tbody/i,jb=/<|&#?\w+;/,ta=/<script|<object|<embed|<option|<style/i,ua=/checked\s*(?:[^=]|=\s*.checked.)/i,Ma=function(a,b,d){return hb.test(d)?
+a:b+"></"+d+">"},F={option:[1,"<select multiple='multiple'>","</select>"],legend:[1,"<fieldset>","</fieldset>"],thead:[1,"<table>","</table>"],tr:[2,"<table><tbody>","</tbody></table>"],td:[3,"<table><tbody><tr>","</tr></tbody></table>"],col:[2,"<table><tbody></tbody><colgroup>","</colgroup></table>"],area:[1,"<map>","</map>"],_default:[0,"",""]};F.optgroup=F.option;F.tbody=F.tfoot=F.colgroup=F.caption=F.thead;F.th=F.td;if(!c.support.htmlSerialize)F._default=[1,"div<div>","</div>"];c.fn.extend({text:function(a){if(c.isFunction(a))return this.each(function(b){var d=
+c(this);d.text(a.call(this,b,d.text()))});if(typeof a!=="object"&&a!==w)return this.empty().append((this[0]&&this[0].ownerDocument||s).createTextNode(a));return c.text(this)},wrapAll:function(a){if(c.isFunction(a))return this.each(function(d){c(this).wrapAll(a.call(this,d))});if(this[0]){var b=c(a,this[0].ownerDocument).eq(0).clone(true);this[0].parentNode&&b.insertBefore(this[0]);b.map(function(){for(var d=this;d.firstChild&&d.firstChild.nodeType===1;)d=d.firstChild;return d}).append(this)}return this},
+wrapInner:function(a){if(c.isFunction(a))return this.each(function(b){c(this).wrapInner(a.call(this,b))});return this.each(function(){var b=c(this),d=b.contents();d.length?d.wrapAll(a):b.append(a)})},wrap:function(a){return this.each(function(){c(this).wrapAll(a)})},unwrap:function(){return this.parent().each(function(){c.nodeName(this,"body")||c(this).replaceWith(this.childNodes)}).end()},append:function(){return this.domManip(arguments,true,function(a){this.nodeType===1&&this.appendChild(a)})},
+prepend:function(){return this.domManip(arguments,true,function(a){this.nodeType===1&&this.insertBefore(a,this.firstChild)})},before:function(){if(this[0]&&this[0].parentNode)return this.domManip(arguments,false,function(b){this.parentNode.insertBefore(b,this)});else if(arguments.length){var a=c(arguments[0]);a.push.apply(a,this.toArray());return this.pushStack(a,"before",arguments)}},after:function(){if(this[0]&&this[0].parentNode)return this.domManip(arguments,false,function(b){this.parentNode.insertBefore(b,
+this.nextSibling)});else if(arguments.length){var a=this.pushStack(this,"after",arguments);a.push.apply(a,c(arguments[0]).toArray());return a}},remove:function(a,b){for(var d=0,f;(f=this[d])!=null;d++)if(!a||c.filter(a,[f]).length){if(!b&&f.nodeType===1){c.cleanData(f.getElementsByTagName("*"));c.cleanData([f])}f.parentNode&&f.parentNode.removeChild(f)}return this},empty:function(){for(var a=0,b;(b=this[a])!=null;a++)for(b.nodeType===1&&c.cleanData(b.getElementsByTagName("*"));b.firstChild;)b.removeChild(b.firstChild);
+return this},clone:function(a){var b=this.map(function(){if(!c.support.noCloneEvent&&!c.isXMLDoc(this)){var d=this.outerHTML,f=this.ownerDocument;if(!d){d=f.createElement("div");d.appendChild(this.cloneNode(true));d=d.innerHTML}return c.clean([d.replace(Ja,"").replace(/=([^="'>\s]+\/)>/g,'="$1">').replace(V,"")],f)[0]}else return this.cloneNode(true)});if(a===true){ra(this,b);ra(this.find("*"),b.find("*"))}return b},html:function(a){if(a===w)return this[0]&&this[0].nodeType===1?this[0].innerHTML.replace(Ja,
+""):null;else if(typeof a==="string"&&!ta.test(a)&&(c.support.leadingWhitespace||!V.test(a))&&!F[(La.exec(a)||["",""])[1].toLowerCase()]){a=a.replace(Ka,Ma);try{for(var b=0,d=this.length;b<d;b++)if(this[b].nodeType===1){c.cleanData(this[b].getElementsByTagName("*"));this[b].innerHTML=a}}catch(f){this.empty().append(a)}}else c.isFunction(a)?this.each(function(e){var j=c(this),i=j.html();j.empty().append(function(){return a.call(this,e,i)})}):this.empty().append(a);return this},replaceWith:function(a){if(this[0]&&
+this[0].parentNode){if(c.isFunction(a))return this.each(function(b){var d=c(this),f=d.html();d.replaceWith(a.call(this,b,f))});if(typeof a!=="string")a=c(a).detach();return this.each(function(){var b=this.nextSibling,d=this.parentNode;c(this).remove();b?c(b).before(a):c(d).append(a)})}else return this.pushStack(c(c.isFunction(a)?a():a),"replaceWith",a)},detach:function(a){return this.remove(a,true)},domManip:function(a,b,d){function f(u){return c.nodeName(u,"table")?u.getElementsByTagName("tbody")[0]||
+u.appendChild(u.ownerDocument.createElement("tbody")):u}var e,j,i=a[0],o=[],k;if(!c.support.checkClone&&arguments.length===3&&typeof i==="string"&&ua.test(i))return this.each(function(){c(this).domManip(a,b,d,true)});if(c.isFunction(i))return this.each(function(u){var z=c(this);a[0]=i.call(this,u,b?z.html():w);z.domManip(a,b,d)});if(this[0]){e=i&&i.parentNode;e=c.support.parentNode&&e&&e.nodeType===11&&e.childNodes.length===this.length?{fragment:e}:sa(a,this,o);k=e.fragment;if(j=k.childNodes.length===
+1?(k=k.firstChild):k.firstChild){b=b&&c.nodeName(j,"tr");for(var n=0,r=this.length;n<r;n++)d.call(b?f(this[n],j):this[n],n>0||e.cacheable||this.length>1?k.cloneNode(true):k)}o.length&&c.each(o,Qa)}return this}});c.fragments={};c.each({appendTo:"append",prependTo:"prepend",insertBefore:"before",insertAfter:"after",replaceAll:"replaceWith"},function(a,b){c.fn[a]=function(d){var f=[];d=c(d);var e=this.length===1&&this[0].parentNode;if(e&&e.nodeType===11&&e.childNodes.length===1&&d.length===1){d[b](this[0]);
+return this}else{e=0;for(var j=d.length;e<j;e++){var i=(e>0?this.clone(true):this).get();c.fn[b].apply(c(d[e]),i);f=f.concat(i)}return this.pushStack(f,a,d.selector)}}});c.extend({clean:function(a,b,d,f){b=b||s;if(typeof b.createElement==="undefined")b=b.ownerDocument||b[0]&&b[0].ownerDocument||s;for(var e=[],j=0,i;(i=a[j])!=null;j++){if(typeof i==="number")i+="";if(i){if(typeof i==="string"&&!jb.test(i))i=b.createTextNode(i);else if(typeof i==="string"){i=i.replace(Ka,Ma);var o=(La.exec(i)||["",
+""])[1].toLowerCase(),k=F[o]||F._default,n=k[0],r=b.createElement("div");for(r.innerHTML=k[1]+i+k[2];n--;)r=r.lastChild;if(!c.support.tbody){n=ib.test(i);o=o==="table"&&!n?r.firstChild&&r.firstChild.childNodes:k[1]==="<table>"&&!n?r.childNodes:[];for(k=o.length-1;k>=0;--k)c.nodeName(o[k],"tbody")&&!o[k].childNodes.length&&o[k].parentNode.removeChild(o[k])}!c.support.leadingWhitespace&&V.test(i)&&r.insertBefore(b.createTextNode(V.exec(i)[0]),r.firstChild);i=r.childNodes}if(i.nodeType)e.push(i);else e=
+c.merge(e,i)}}if(d)for(j=0;e[j];j++)if(f&&c.nodeName(e[j],"script")&&(!e[j].type||e[j].type.toLowerCase()==="text/javascript"))f.push(e[j].parentNode?e[j].parentNode.removeChild(e[j]):e[j]);else{e[j].nodeType===1&&e.splice.apply(e,[j+1,0].concat(c.makeArray(e[j].getElementsByTagName("script"))));d.appendChild(e[j])}return e},cleanData:function(a){for(var b,d,f=c.cache,e=c.event.special,j=c.support.deleteExpando,i=0,o;(o=a[i])!=null;i++)if(d=o[c.expando]){b=f[d];if(b.events)for(var k in b.events)e[k]?
+c.event.remove(o,k):Ca(o,k,b.handle);if(j)delete o[c.expando];else o.removeAttribute&&o.removeAttribute(c.expando);delete f[d]}}});var kb=/z-?index|font-?weight|opacity|zoom|line-?height/i,Na=/alpha\([^)]*\)/,Oa=/opacity=([^)]*)/,ha=/float/i,ia=/-([a-z])/ig,lb=/([A-Z])/g,mb=/^-?\d+(?:px)?$/i,nb=/^-?\d/,ob={position:"absolute",visibility:"hidden",display:"block"},pb=["Left","Right"],qb=["Top","Bottom"],rb=s.defaultView&&s.defaultView.getComputedStyle,Pa=c.support.cssFloat?"cssFloat":"styleFloat",ja=
+function(a,b){return b.toUpperCase()};c.fn.css=function(a,b){return X(this,a,b,true,function(d,f,e){if(e===w)return c.curCSS(d,f);if(typeof e==="number"&&!kb.test(f))e+="px";c.style(d,f,e)})};c.extend({style:function(a,b,d){if(!a||a.nodeType===3||a.nodeType===8)return w;if((b==="width"||b==="height")&&parseFloat(d)<0)d=w;var f=a.style||a,e=d!==w;if(!c.support.opacity&&b==="opacity"){if(e){f.zoom=1;b=parseInt(d,10)+""==="NaN"?"":"alpha(opacity="+d*100+")";a=f.filter||c.curCSS(a,"filter")||"";f.filter=
+Na.test(a)?a.replace(Na,b):b}return f.filter&&f.filter.indexOf("opacity=")>=0?parseFloat(Oa.exec(f.filter)[1])/100+"":""}if(ha.test(b))b=Pa;b=b.replace(ia,ja);if(e)f[b]=d;return f[b]},css:function(a,b,d,f){if(b==="width"||b==="height"){var e,j=b==="width"?pb:qb;function i(){e=b==="width"?a.offsetWidth:a.offsetHeight;f!=="border"&&c.each(j,function(){f||(e-=parseFloat(c.curCSS(a,"padding"+this,true))||0);if(f==="margin")e+=parseFloat(c.curCSS(a,"margin"+this,true))||0;else e-=parseFloat(c.curCSS(a,
+"border"+this+"Width",true))||0})}a.offsetWidth!==0?i():c.swap(a,ob,i);return Math.max(0,Math.round(e))}return c.curCSS(a,b,d)},curCSS:function(a,b,d){var f,e=a.style;if(!c.support.opacity&&b==="opacity"&&a.currentStyle){f=Oa.test(a.currentStyle.filter||"")?parseFloat(RegExp.$1)/100+"":"";return f===""?"1":f}if(ha.test(b))b=Pa;if(!d&&e&&e[b])f=e[b];else if(rb){if(ha.test(b))b="float";b=b.replace(lb,"-$1").toLowerCase();e=a.ownerDocument.defaultView;if(!e)return null;if(a=e.getComputedStyle(a,null))f=
+a.getPropertyValue(b);if(b==="opacity"&&f==="")f="1"}else if(a.currentStyle){d=b.replace(ia,ja);f=a.currentStyle[b]||a.currentStyle[d];if(!mb.test(f)&&nb.test(f)){b=e.left;var j=a.runtimeStyle.left;a.runtimeStyle.left=a.currentStyle.left;e.left=d==="fontSize"?"1em":f||0;f=e.pixelLeft+"px";e.left=b;a.runtimeStyle.left=j}}return f},swap:function(a,b,d){var f={};for(var e in b){f[e]=a.style[e];a.style[e]=b[e]}d.call(a);for(e in b)a.style[e]=f[e]}});if(c.expr&&c.expr.filters){c.expr.filters.hidden=function(a){var b=
+a.offsetWidth,d=a.offsetHeight,f=a.nodeName.toLowerCase()==="tr";return b===0&&d===0&&!f?true:b>0&&d>0&&!f?false:c.curCSS(a,"display")==="none"};c.expr.filters.visible=function(a){return!c.expr.filters.hidden(a)}}var sb=J(),tb=/<script(.|\s)*?\/script>/gi,ub=/select|textarea/i,vb=/color|date|datetime|email|hidden|month|number|password|range|search|tel|text|time|url|week/i,N=/=\?(&|$)/,ka=/\?/,wb=/(\?|&)_=.*?(&|$)/,xb=/^(\w+:)?\/\/([^\/?#]+)/,yb=/%20/g,zb=c.fn.load;c.fn.extend({load:function(a,b,d){if(typeof a!==
+"string")return zb.call(this,a);else if(!this.length)return this;var f=a.indexOf(" ");if(f>=0){var e=a.slice(f,a.length);a=a.slice(0,f)}f="GET";if(b)if(c.isFunction(b)){d=b;b=null}else if(typeof b==="object"){b=c.param(b,c.ajaxSettings.traditional);f="POST"}var j=this;c.ajax({url:a,type:f,dataType:"html",data:b,complete:function(i,o){if(o==="success"||o==="notmodified")j.html(e?c("<div />").append(i.responseText.replace(tb,"")).find(e):i.responseText);d&&j.each(d,[i.responseText,o,i])}});return this},
+serialize:function(){return c.param(this.serializeArray())},serializeArray:function(){return this.map(function(){return this.elements?c.makeArray(this.elements):this}).filter(function(){return this.name&&!this.disabled&&(this.checked||ub.test(this.nodeName)||vb.test(this.type))}).map(function(a,b){a=c(this).val();return a==null?null:c.isArray(a)?c.map(a,function(d){return{name:b.name,value:d}}):{name:b.name,value:a}}).get()}});c.each("ajaxStart ajaxStop ajaxComplete ajaxError ajaxSuccess ajaxSend".split(" "),
+function(a,b){c.fn[b]=function(d){return this.bind(b,d)}});c.extend({get:function(a,b,d,f){if(c.isFunction(b)){f=f||d;d=b;b=null}return c.ajax({type:"GET",url:a,data:b,success:d,dataType:f})},getScript:function(a,b){return c.get(a,null,b,"script")},getJSON:function(a,b,d){return c.get(a,b,d,"json")},post:function(a,b,d,f){if(c.isFunction(b)){f=f||d;d=b;b={}}return c.ajax({type:"POST",url:a,data:b,success:d,dataType:f})},ajaxSetup:function(a){c.extend(c.ajaxSettings,a)},ajaxSettings:{url:location.href,
+global:true,type:"GET",contentType:"application/x-www-form-urlencoded",processData:true,async:true,xhr:A.XMLHttpRequest&&(A.location.protocol!=="file:"||!A.ActiveXObject)?function(){return new A.XMLHttpRequest}:function(){try{return new A.ActiveXObject("Microsoft.XMLHTTP")}catch(a){}},accepts:{xml:"application/xml, text/xml",html:"text/html",script:"text/javascript, application/javascript",json:"application/json, text/javascript",text:"text/plain",_default:"*/*"}},lastModified:{},etag:{},ajax:function(a){function b(){e.success&&
+e.success.call(k,o,i,x);e.global&&f("ajaxSuccess",[x,e])}function d(){e.complete&&e.complete.call(k,x,i);e.global&&f("ajaxComplete",[x,e]);e.global&&!--c.active&&c.event.trigger("ajaxStop")}function f(q,p){(e.context?c(e.context):c.event).trigger(q,p)}var e=c.extend(true,{},c.ajaxSettings,a),j,i,o,k=a&&a.context||e,n=e.type.toUpperCase();if(e.data&&e.processData&&typeof e.data!=="string")e.data=c.param(e.data,e.traditional);if(e.dataType==="jsonp"){if(n==="GET")N.test(e.url)||(e.url+=(ka.test(e.url)?
+"&":"?")+(e.jsonp||"callback")+"=?");else if(!e.data||!N.test(e.data))e.data=(e.data?e.data+"&":"")+(e.jsonp||"callback")+"=?";e.dataType="json"}if(e.dataType==="json"&&(e.data&&N.test(e.data)||N.test(e.url))){j=e.jsonpCallback||"jsonp"+sb++;if(e.data)e.data=(e.data+"").replace(N,"="+j+"$1");e.url=e.url.replace(N,"="+j+"$1");e.dataType="script";A[j]=A[j]||function(q){o=q;b();d();A[j]=w;try{delete A[j]}catch(p){}z&&z.removeChild(C)}}if(e.dataType==="script"&&e.cache===null)e.cache=false;if(e.cache===
+false&&n==="GET"){var r=J(),u=e.url.replace(wb,"$1_="+r+"$2");e.url=u+(u===e.url?(ka.test(e.url)?"&":"?")+"_="+r:"")}if(e.data&&n==="GET")e.url+=(ka.test(e.url)?"&":"?")+e.data;e.global&&!c.active++&&c.event.trigger("ajaxStart");r=(r=xb.exec(e.url))&&(r[1]&&r[1]!==location.protocol||r[2]!==location.host);if(e.dataType==="script"&&n==="GET"&&r){var z=s.getElementsByTagName("head")[0]||s.documentElement,C=s.createElement("script");C.src=e.url;if(e.scriptCharset)C.charset=e.scriptCharset;if(!j){var B=
+false;C.onload=C.onreadystatechange=function(){if(!B&&(!this.readyState||this.readyState==="loaded"||this.readyState==="complete")){B=true;b();d();C.onload=C.onreadystatechange=null;z&&C.parentNode&&z.removeChild(C)}}}z.insertBefore(C,z.firstChild);return w}var E=false,x=e.xhr();if(x){e.username?x.open(n,e.url,e.async,e.username,e.password):x.open(n,e.url,e.async);try{if(e.data||a&&a.contentType)x.setRequestHeader("Content-Type",e.contentType);if(e.ifModified){c.lastModified[e.url]&&x.setRequestHeader("If-Modified-Since",
+c.lastModified[e.url]);c.etag[e.url]&&x.setRequestHeader("If-None-Match",c.etag[e.url])}r||x.setRequestHeader("X-Requested-With","XMLHttpRequest");x.setRequestHeader("Accept",e.dataType&&e.accepts[e.dataType]?e.accepts[e.dataType]+", */*":e.accepts._default)}catch(ga){}if(e.beforeSend&&e.beforeSend.call(k,x,e)===false){e.global&&!--c.active&&c.event.trigger("ajaxStop");x.abort();return false}e.global&&f("ajaxSend",[x,e]);var g=x.onreadystatechange=function(q){if(!x||x.readyState===0||q==="abort"){E||
+d();E=true;if(x)x.onreadystatechange=c.noop}else if(!E&&x&&(x.readyState===4||q==="timeout")){E=true;x.onreadystatechange=c.noop;i=q==="timeout"?"timeout":!c.httpSuccess(x)?"error":e.ifModified&&c.httpNotModified(x,e.url)?"notmodified":"success";var p;if(i==="success")try{o=c.httpData(x,e.dataType,e)}catch(v){i="parsererror";p=v}if(i==="success"||i==="notmodified")j||b();else c.handleError(e,x,i,p);d();q==="timeout"&&x.abort();if(e.async)x=null}};try{var h=x.abort;x.abort=function(){x&&h.call(x);
+g("abort")}}catch(l){}e.async&&e.timeout>0&&setTimeout(function(){x&&!E&&g("timeout")},e.timeout);try{x.send(n==="POST"||n==="PUT"||n==="DELETE"?e.data:null)}catch(m){c.handleError(e,x,null,m);d()}e.async||g();return x}},handleError:function(a,b,d,f){if(a.error)a.error.call(a.context||a,b,d,f);if(a.global)(a.context?c(a.context):c.event).trigger("ajaxError",[b,a,f])},active:0,httpSuccess:function(a){try{return!a.status&&location.protocol==="file:"||a.status>=200&&a.status<300||a.status===304||a.status===
+1223||a.status===0}catch(b){}return false},httpNotModified:function(a,b){var d=a.getResponseHeader("Last-Modified"),f=a.getResponseHeader("Etag");if(d)c.lastModified[b]=d;if(f)c.etag[b]=f;return a.status===304||a.status===0},httpData:function(a,b,d){var f=a.getResponseHeader("content-type")||"",e=b==="xml"||!b&&f.indexOf("xml")>=0;a=e?a.responseXML:a.responseText;e&&a.documentElement.nodeName==="parsererror"&&c.error("parsererror");if(d&&d.dataFilter)a=d.dataFilter(a,b);if(typeof a==="string")if(b===
+"json"||!b&&f.indexOf("json")>=0)a=c.parseJSON(a);else if(b==="script"||!b&&f.indexOf("javascript")>=0)c.globalEval(a);return a},param:function(a,b){function d(i,o){if(c.isArray(o))c.each(o,function(k,n){b||/\[\]$/.test(i)?f(i,n):d(i+"["+(typeof n==="object"||c.isArray(n)?k:"")+"]",n)});else!b&&o!=null&&typeof o==="object"?c.each(o,function(k,n){d(i+"["+k+"]",n)}):f(i,o)}function f(i,o){o=c.isFunction(o)?o():o;e[e.length]=encodeURIComponent(i)+"="+encodeURIComponent(o)}var e=[];if(b===w)b=c.ajaxSettings.traditional;
+if(c.isArray(a)||a.jquery)c.each(a,function(){f(this.name,this.value)});else for(var j in a)d(j,a[j]);return e.join("&").replace(yb,"+")}});var la={},Ab=/toggle|show|hide/,Bb=/^([+-]=)?([\d+-.]+)(.*)$/,W,va=[["height","marginTop","marginBottom","paddingTop","paddingBottom"],["width","marginLeft","marginRight","paddingLeft","paddingRight"],["opacity"]];c.fn.extend({show:function(a,b){if(a||a===0)return this.animate(K("show",3),a,b);else{a=0;for(b=this.length;a<b;a++){var d=c.data(this[a],"olddisplay");
+this[a].style.display=d||"";if(c.css(this[a],"display")==="none"){d=this[a].nodeName;var f;if(la[d])f=la[d];else{var e=c("<"+d+" />").appendTo("body");f=e.css("display");if(f==="none")f="block";e.remove();la[d]=f}c.data(this[a],"olddisplay",f)}}a=0;for(b=this.length;a<b;a++)this[a].style.display=c.data(this[a],"olddisplay")||"";return this}},hide:function(a,b){if(a||a===0)return this.animate(K("hide",3),a,b);else{a=0;for(b=this.length;a<b;a++){var d=c.data(this[a],"olddisplay");!d&&d!=="none"&&c.data(this[a],
+"olddisplay",c.css(this[a],"display"))}a=0;for(b=this.length;a<b;a++)this[a].style.display="none";return this}},_toggle:c.fn.toggle,toggle:function(a,b){var d=typeof a==="boolean";if(c.isFunction(a)&&c.isFunction(b))this._toggle.apply(this,arguments);else a==null||d?this.each(function(){var f=d?a:c(this).is(":hidden");c(this)[f?"show":"hide"]()}):this.animate(K("toggle",3),a,b);return this},fadeTo:function(a,b,d){return this.filter(":hidden").css("opacity",0).show().end().animate({opacity:b},a,d)},
+animate:function(a,b,d,f){var e=c.speed(b,d,f);if(c.isEmptyObject(a))return this.each(e.complete);return this[e.queue===false?"each":"queue"](function(){var j=c.extend({},e),i,o=this.nodeType===1&&c(this).is(":hidden"),k=this;for(i in a){var n=i.replace(ia,ja);if(i!==n){a[n]=a[i];delete a[i];i=n}if(a[i]==="hide"&&o||a[i]==="show"&&!o)return j.complete.call(this);if((i==="height"||i==="width")&&this.style){j.display=c.css(this,"display");j.overflow=this.style.overflow}if(c.isArray(a[i])){(j.specialEasing=
+j.specialEasing||{})[i]=a[i][1];a[i]=a[i][0]}}if(j.overflow!=null)this.style.overflow="hidden";j.curAnim=c.extend({},a);c.each(a,function(r,u){var z=new c.fx(k,j,r);if(Ab.test(u))z[u==="toggle"?o?"show":"hide":u](a);else{var C=Bb.exec(u),B=z.cur(true)||0;if(C){u=parseFloat(C[2]);var E=C[3]||"px";if(E!=="px"){k.style[r]=(u||1)+E;B=(u||1)/z.cur(true)*B;k.style[r]=B+E}if(C[1])u=(C[1]==="-="?-1:1)*u+B;z.custom(B,u,E)}else z.custom(B,u,"")}});return true})},stop:function(a,b){var d=c.timers;a&&this.queue([]);
+this.each(function(){for(var f=d.length-1;f>=0;f--)if(d[f].elem===this){b&&d[f](true);d.splice(f,1)}});b||this.dequeue();return this}});c.each({slideDown:K("show",1),slideUp:K("hide",1),slideToggle:K("toggle",1),fadeIn:{opacity:"show"},fadeOut:{opacity:"hide"}},function(a,b){c.fn[a]=function(d,f){return this.animate(b,d,f)}});c.extend({speed:function(a,b,d){var f=a&&typeof a==="object"?a:{complete:d||!d&&b||c.isFunction(a)&&a,duration:a,easing:d&&b||b&&!c.isFunction(b)&&b};f.duration=c.fx.off?0:typeof f.duration===
+"number"?f.duration:c.fx.speeds[f.duration]||c.fx.speeds._default;f.old=f.complete;f.complete=function(){f.queue!==false&&c(this).dequeue();c.isFunction(f.old)&&f.old.call(this)};return f},easing:{linear:function(a,b,d,f){return d+f*a},swing:function(a,b,d,f){return(-Math.cos(a*Math.PI)/2+0.5)*f+d}},timers:[],fx:function(a,b,d){this.options=b;this.elem=a;this.prop=d;if(!b.orig)b.orig={}}});c.fx.prototype={update:function(){this.options.step&&this.options.step.call(this.elem,this.now,this);(c.fx.step[this.prop]||
+c.fx.step._default)(this);if((this.prop==="height"||this.prop==="width")&&this.elem.style)this.elem.style.display="block"},cur:function(a){if(this.elem[this.prop]!=null&&(!this.elem.style||this.elem.style[this.prop]==null))return this.elem[this.prop];return(a=parseFloat(c.css(this.elem,this.prop,a)))&&a>-10000?a:parseFloat(c.curCSS(this.elem,this.prop))||0},custom:function(a,b,d){function f(j){return e.step(j)}this.startTime=J();this.start=a;this.end=b;this.unit=d||this.unit||"px";this.now=this.start;
+this.pos=this.state=0;var e=this;f.elem=this.elem;if(f()&&c.timers.push(f)&&!W)W=setInterval(c.fx.tick,13)},show:function(){this.options.orig[this.prop]=c.style(this.elem,this.prop);this.options.show=true;this.custom(this.prop==="width"||this.prop==="height"?1:0,this.cur());c(this.elem).show()},hide:function(){this.options.orig[this.prop]=c.style(this.elem,this.prop);this.options.hide=true;this.custom(this.cur(),0)},step:function(a){var b=J(),d=true;if(a||b>=this.options.duration+this.startTime){this.now=
+this.end;this.pos=this.state=1;this.update();this.options.curAnim[this.prop]=true;for(var f in this.options.curAnim)if(this.options.curAnim[f]!==true)d=false;if(d){if(this.options.display!=null){this.elem.style.overflow=this.options.overflow;a=c.data(this.elem,"olddisplay");this.elem.style.display=a?a:this.options.display;if(c.css(this.elem,"display")==="none")this.elem.style.display="block"}this.options.hide&&c(this.elem).hide();if(this.options.hide||this.options.show)for(var e in this.options.curAnim)c.style(this.elem,
+e,this.options.orig[e]);this.options.complete.call(this.elem)}return false}else{e=b-this.startTime;this.state=e/this.options.duration;a=this.options.easing||(c.easing.swing?"swing":"linear");this.pos=c.easing[this.options.specialEasing&&this.options.specialEasing[this.prop]||a](this.state,e,0,1,this.options.duration);this.now=this.start+(this.end-this.start)*this.pos;this.update()}return true}};c.extend(c.fx,{tick:function(){for(var a=c.timers,b=0;b<a.length;b++)a[b]()||a.splice(b--,1);a.length||
+c.fx.stop()},stop:function(){clearInterval(W);W=null},speeds:{slow:600,fast:200,_default:400},step:{opacity:function(a){c.style(a.elem,"opacity",a.now)},_default:function(a){if(a.elem.style&&a.elem.style[a.prop]!=null)a.elem.style[a.prop]=(a.prop==="width"||a.prop==="height"?Math.max(0,a.now):a.now)+a.unit;else a.elem[a.prop]=a.now}}});if(c.expr&&c.expr.filters)c.expr.filters.animated=function(a){return c.grep(c.timers,function(b){return a===b.elem}).length};c.fn.offset="getBoundingClientRect"in s.documentElement?
+function(a){var b=this[0];if(a)return this.each(function(e){c.offset.setOffset(this,a,e)});if(!b||!b.ownerDocument)return null;if(b===b.ownerDocument.body)return c.offset.bodyOffset(b);var d=b.getBoundingClientRect(),f=b.ownerDocument;b=f.body;f=f.documentElement;return{top:d.top+(self.pageYOffset||c.support.boxModel&&f.scrollTop||b.scrollTop)-(f.clientTop||b.clientTop||0),left:d.left+(self.pageXOffset||c.support.boxModel&&f.scrollLeft||b.scrollLeft)-(f.clientLeft||b.clientLeft||0)}}:function(a){var b=
+this[0];if(a)return this.each(function(r){c.offset.setOffset(this,a,r)});if(!b||!b.ownerDocument)return null;if(b===b.ownerDocument.body)return c.offset.bodyOffset(b);c.offset.initialize();var d=b.offsetParent,f=b,e=b.ownerDocument,j,i=e.documentElement,o=e.body;f=(e=e.defaultView)?e.getComputedStyle(b,null):b.currentStyle;for(var k=b.offsetTop,n=b.offsetLeft;(b=b.parentNode)&&b!==o&&b!==i;){if(c.offset.supportsFixedPosition&&f.position==="fixed")break;j=e?e.getComputedStyle(b,null):b.currentStyle;
+k-=b.scrollTop;n-=b.scrollLeft;if(b===d){k+=b.offsetTop;n+=b.offsetLeft;if(c.offset.doesNotAddBorder&&!(c.offset.doesAddBorderForTableAndCells&&/^t(able|d|h)$/i.test(b.nodeName))){k+=parseFloat(j.borderTopWidth)||0;n+=parseFloat(j.borderLeftWidth)||0}f=d;d=b.offsetParent}if(c.offset.subtractsBorderForOverflowNotVisible&&j.overflow!=="visible"){k+=parseFloat(j.borderTopWidth)||0;n+=parseFloat(j.borderLeftWidth)||0}f=j}if(f.position==="relative"||f.position==="static"){k+=o.offsetTop;n+=o.offsetLeft}if(c.offset.supportsFixedPosition&&
+f.position==="fixed"){k+=Math.max(i.scrollTop,o.scrollTop);n+=Math.max(i.scrollLeft,o.scrollLeft)}return{top:k,left:n}};c.offset={initialize:function(){var a=s.body,b=s.createElement("div"),d,f,e,j=parseFloat(c.curCSS(a,"marginTop",true))||0;c.extend(b.style,{position:"absolute",top:0,left:0,margin:0,border:0,width:"1px",height:"1px",visibility:"hidden"});b.innerHTML="<div style='position:absolute;top:0;left:0;margin:0;border:5px solid #000;padding:0;width:1px;height:1px;'><div></div></div><table style='position:absolute;top:0;left:0;margin:0;border:5px solid #000;padding:0;width:1px;height:1px;' cellpadding='0' cellspacing='0'><tr><td></td></tr></table>";
+a.insertBefore(b,a.firstChild);d=b.firstChild;f=d.firstChild;e=d.nextSibling.firstChild.firstChild;this.doesNotAddBorder=f.offsetTop!==5;this.doesAddBorderForTableAndCells=e.offsetTop===5;f.style.position="fixed";f.style.top="20px";this.supportsFixedPosition=f.offsetTop===20||f.offsetTop===15;f.style.position=f.style.top="";d.style.overflow="hidden";d.style.position="relative";this.subtractsBorderForOverflowNotVisible=f.offsetTop===-5;this.doesNotIncludeMarginInBodyOffset=a.offsetTop!==j;a.removeChild(b);
+c.offset.initialize=c.noop},bodyOffset:function(a){var b=a.offsetTop,d=a.offsetLeft;c.offset.initialize();if(c.offset.doesNotIncludeMarginInBodyOffset){b+=parseFloat(c.curCSS(a,"marginTop",true))||0;d+=parseFloat(c.curCSS(a,"marginLeft",true))||0}return{top:b,left:d}},setOffset:function(a,b,d){if(/static/.test(c.curCSS(a,"position")))a.style.position="relative";var f=c(a),e=f.offset(),j=parseInt(c.curCSS(a,"top",true),10)||0,i=parseInt(c.curCSS(a,"left",true),10)||0;if(c.isFunction(b))b=b.call(a,
+d,e);d={top:b.top-e.top+j,left:b.left-e.left+i};"using"in b?b.using.call(a,d):f.css(d)}};c.fn.extend({position:function(){if(!this[0])return null;var a=this[0],b=this.offsetParent(),d=this.offset(),f=/^body|html$/i.test(b[0].nodeName)?{top:0,left:0}:b.offset();d.top-=parseFloat(c.curCSS(a,"marginTop",true))||0;d.left-=parseFloat(c.curCSS(a,"marginLeft",true))||0;f.top+=parseFloat(c.curCSS(b[0],"borderTopWidth",true))||0;f.left+=parseFloat(c.curCSS(b[0],"borderLeftWidth",true))||0;return{top:d.top-
+f.top,left:d.left-f.left}},offsetParent:function(){return this.map(function(){for(var a=this.offsetParent||s.body;a&&!/^body|html$/i.test(a.nodeName)&&c.css(a,"position")==="static";)a=a.offsetParent;return a})}});c.each(["Left","Top"],function(a,b){var d="scroll"+b;c.fn[d]=function(f){var e=this[0],j;if(!e)return null;if(f!==w)return this.each(function(){if(j=wa(this))j.scrollTo(!a?f:c(j).scrollLeft(),a?f:c(j).scrollTop());else this[d]=f});else return(j=wa(e))?"pageXOffset"in j?j[a?"pageYOffset":
+"pageXOffset"]:c.support.boxModel&&j.document.documentElement[d]||j.document.body[d]:e[d]}});c.each(["Height","Width"],function(a,b){var d=b.toLowerCase();c.fn["inner"+b]=function(){return this[0]?c.css(this[0],d,false,"padding"):null};c.fn["outer"+b]=function(f){return this[0]?c.css(this[0],d,false,f?"margin":"border"):null};c.fn[d]=function(f){var e=this[0];if(!e)return f==null?null:this;if(c.isFunction(f))return this.each(function(j){var i=c(this);i[d](f.call(this,j,i[d]()))});return"scrollTo"in
+e&&e.document?e.document.compatMode==="CSS1Compat"&&e.document.documentElement["client"+b]||e.document.body["client"+b]:e.nodeType===9?Math.max(e.documentElement["client"+b],e.body["scroll"+b],e.documentElement["scroll"+b],e.body["offset"+b],e.documentElement["offset"+b]):f===w?c.css(e,d):this.css(d,typeof f==="string"?f:f+"px")}});A.jQuery=A.$=c})(window);

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/examples/_obsolete/docroot/login.html
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/examples/_obsolete/docroot/login.html b/thirdparty/civetweb-1.9.1/examples/_obsolete/docroot/login.html
new file mode 100644
index 0000000..2b09f01
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/examples/_obsolete/docroot/login.html
@@ -0,0 +1,43 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
+<html xmlns="http://www.w3.org/1999/xhtml" lang="en" dir="ltr"> 
+  <!-- This file is part of the  Civetweb project,
+    http://sourceforge.net/projects/civetweb/ -->
+  <head>
+    <title>Civetweb chat: login</title>
+    <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
+    <!--
+      Note that this page is self-sufficient, it does not load any other
+      CSS or Javascript file. This is done so because only this page is
+      allowed for non-authorized users. If we want to load other files
+      from the frontend, we need to change backend code to allow those
+      for non-authorized users. See chat.c :: must_authorize() function.
+    -->
+  </head>
+
+  <script>
+    window.onload = function() {
+      // Set correct action for the login form. We assume that the SSL port
+      // is the next one to insecure one.
+      var httpsPort = location.protocol.match(/https/) ? location.port :
+        parseInt(location.port) + 1;
+      document.forms[0].action = 'https://' + location.hostname + ':' +
+        httpsPort + '/authorize';
+    };
+  </script>
+
+  <body>
+    <center>
+      <h2>Civetweb chat server login</h2>
+      <div style="max-width: 30em;">
+        Username and password can be any non-empty strings.
+      </div>
+      <br/>
+      <form>
+        <input type="text" name="user"></input><br/>
+        <input type="text" name="password"></input><br/>
+        <input type="submit" value="Login"></input>
+      </form>
+    </center>
+  </body>
+</html>

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/examples/_obsolete/docroot/logo.png
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/examples/_obsolete/docroot/logo.png b/thirdparty/civetweb-1.9.1/examples/_obsolete/docroot/logo.png
new file mode 100644
index 0000000..8a47c0a
Binary files /dev/null and b/thirdparty/civetweb-1.9.1/examples/_obsolete/docroot/logo.png differ

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/examples/_obsolete/docroot/main.js
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/examples/_obsolete/docroot/main.js b/thirdparty/civetweb-1.9.1/examples/_obsolete/docroot/main.js
new file mode 100644
index 0000000..d4af86d
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/examples/_obsolete/docroot/main.js
@@ -0,0 +1,107 @@
+// This file is part of Civetweb project,
+// http://sourceforge.net/projects/civetweb/
+
+var chat = {
+  // Backend URL, string.
+  // 'http://backend.address.com' or '' if backend is the same as frontend
+  backendUrl: '',
+  maxVisibleMessages: 10,
+  errorMessageFadeOutTimeoutMs: 2000,
+  errorMessageFadeOutTimer: null,
+  lastMessageId: 0,
+  getMessagesIntervalMs: 1000,
+};
+
+chat.normalizeText = function(text) {
+  return text.replace('<', '&lt;').replace('>', '&gt;');
+};
+
+chat.refresh = function(data) {
+
+  if (data === undefined) {
+    return;
+  }
+  
+  $.each(data, function(index, entry) {
+    var row = $('<div>').addClass('message-row').appendTo('#mml');
+    var timestamp = (new Date(entry.timestamp * 1000)).toLocaleTimeString();
+    $('<span>')
+      .addClass('message-timestamp')
+      .html('[' + timestamp + ']')
+      .prependTo(row);
+    $('<span>')
+      .addClass('message-user')
+      .addClass(entry.user ? '' : 'message-user-server')
+      .html(chat.normalizeText((entry.user || '[server]') + ':'))
+      .appendTo(row);
+    $('<span>')
+      .addClass('message-text')
+      .addClass(entry.user ? '' : 'message-text-server')
+      .html(chat.normalizeText(entry.text))
+      .appendTo(row);
+    chat.lastMessageId = Math.max(chat.lastMessageId, entry.id) + 1;
+  });
+
+  // Keep only chat.maxVisibleMessages, delete older ones.
+  while ($('#mml').children().length > chat.maxVisibleMessages) {
+    $('#mml div:first-child').remove();
+  }
+};
+
+chat.getMessages = function(enter_loop) {
+  $.ajax({
+    dataType: 'jsonp',
+    url: chat.backendUrl + '/ajax/get_messages',
+    data: {last_id: chat.lastMessageId},
+    success: chat.refresh,
+    error: function() {
+    },
+  });
+  if (enter_loop) {
+    window.setTimeout('chat.getMessages(true)', chat.getMessagesIntervalMs);
+  }
+};
+
+chat.handleMenuItemClick = function(ev) {
+  $('.menu-item').removeClass('menu-item-selected');  // Deselect menu buttons
+  $(this).addClass('menu-item-selected');  // Select clicked button
+  $('.main').addClass('hidden');  // Hide all main windows
+  $('#' + $(this).attr('name')).removeClass('hidden');  // Show main window
+};
+
+chat.showError = function(message) {
+  $('#error').html(message).fadeIn('fast');
+  window.clearTimeout(chat.errorMessageFadeOutTimer);
+  chat.errorMessageFadeOutTimer = window.setTimeout(function() {
+      $('#error').fadeOut('slow');
+  }, chat.errorMessageFadeOutTimeoutMs);
+};
+
+chat.handleMessageInput = function(ev) {
+  var input = ev.target;
+  if (ev.keyCode != 13 || !input.value)
+    return;
+  //input.disabled = true;
+  $.ajax({
+    dataType: 'jsonp',
+    url: chat.backendUrl + '/ajax/send_message',
+    data: {text: input.value},
+    success: function(ev) {
+      input.value = '';
+      input.disabled = false;
+      chat.getMessages(false);
+    },
+    error: function(ev) {
+      chat.showError('Error sending message');
+      input.disabled = false;
+    },
+  });
+};
+
+$(document).ready(function() {
+  $('.menu-item').click(chat.handleMenuItemClick);
+  $('.message-input').keypress(chat.handleMessageInput);
+  chat.getMessages(true);
+});
+
+// vim:ts=2:sw=2:et

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/examples/_obsolete/docroot/prime_numbers.lp
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/examples/_obsolete/docroot/prime_numbers.lp b/thirdparty/civetweb-1.9.1/examples/_obsolete/docroot/prime_numbers.lp
new file mode 100644
index 0000000..0c71bb8
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/examples/_obsolete/docroot/prime_numbers.lp
@@ -0,0 +1,46 @@
+HTTP/1.0 200 OK
+Content-Type: text/html
+
+<html>
+  <p>Prime numbers from 0 to 100, calculated by Lua:</p>
+ <?
+    function is_prime(n)
+      if n <= 0 then return false end
+      if n <= 2 then return true end
+      if (n % 2 == 0) then return false end
+      for i = 3, n / 2, 2 do
+        if (n % i == 0) then return false end
+      end
+      return true
+    end
+
+    for i = 1, 100 do
+      if is_prime(i) then mg.write('<span>' .. i .. '</span>&nbsp;') end
+    end
+
+ ?>
+
+ <p>Reading POST data from Lua (click submit):</p>
+ <form method="POST" ><input type="text" name="t1"/><input type="submit"></form>
+
+ <pre>
+   POST data: [<?
+      local post_data = ''
+      if mg.request_info.request_method == 'POST' then
+        post_data = mg.read()
+      end
+      mg.write(post_data)
+    ?>]
+   request method: [<? mg.write(mg.request_info.request_method) ?>]
+   IP/port: [<? mg.write(mg.request_info.remote_ip, ':',
+                         mg.request_info.remote_port) ?>]
+   URI: [<? mg.write(mg.request_info.uri) ?>]
+   HTTP version [<? mg.write(mg.request_info.http_version) ?>]
+   HEADERS:
+   <?
+     for name, value in pairs(mg.request_info.http_headers) do
+       mg.write(name, ':', value, '\n')
+     end
+   ?>
+</pre>
+</html>

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/examples/_obsolete/docroot/style.css
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/examples/_obsolete/docroot/style.css b/thirdparty/civetweb-1.9.1/examples/_obsolete/docroot/style.css
new file mode 100644
index 0000000..716351d
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/examples/_obsolete/docroot/style.css
@@ -0,0 +1,154 @@
+/*
+ * vim:ts=2:sw=2:et:ai
+ */
+
+body {
+  font: 13px Arial; margin: 0.5em 1em;
+}
+
+#logo {
+  background: url('logo.png') no-repeat ;
+  width: 160px;
+  height: 40px;
+  float: left;
+}
+
+td {
+  text-align: left;
+}
+
+#motd {
+  margin-left: 170px;
+}
+
+.infobox {
+  background: #eed;
+  padding: 1px 1em;
+}
+
+.help-message {
+  color: #aaa;
+}
+
+#middle {
+  margin: 0.5em 0;
+}
+
+#error {
+  background: #c44;
+  color: white;
+  font-weight: bold;
+}
+
+#content, .menu-item-selected, .chat-title, .chat-content {
+  background: #c3d9ff;
+}
+
+#content {
+  overflow: hidden;
+  min-height: 7em;
+  padding: 1em;
+}
+
+.chat-title {
+  padding: 1px 1ex;
+}
+
+.chat-content {
+ padding: 1ex;
+}
+
+.chat-window {
+}
+
+.message-row {
+  margin: 2px;
+  border-bottom: 1px solid #bbb;
+}
+
+.message-timestamp {
+  color: #484;
+}
+
+.message-user {
+  margin-left: 0.5em;
+  font-weight: bold;
+}
+
+.message-text {
+  margin-left: 0.5em;
+}
+
+.message-user-server {
+  color: purple;
+}
+
+.message-text-server {
+  font-style: italic;
+}
+
+.main {
+  padding: 0.5em;
+  background: #f0fcff;
+}
+
+#menu {
+  margin-top: 1em;
+  min-width: 7em;
+  float: left;
+}
+
+#footer {
+  position: fixed;
+  bottom: 0;
+  right: 0;
+  color: #ccc;
+  padding: 0.5em;
+}
+
+.section {
+  clear: both;
+}
+
+.hidden {
+  display: none;
+}
+
+.menu-item {
+  cursor: pointer;
+  padding: 0.1em 0.5em;
+}
+
+.menu-item-selected {
+  font-weight: bold;
+}
+
+.message-list {
+  min-height: 1em;
+  background: white;
+  margin: 0.5em 0;
+}
+
+.rounded {
+  border-radius: 6px;
+  -moz-border-radius: 6px;
+  -webkit-border-radius: 6px;
+}
+
+.left-rounded {
+  border-radius: 6px 0 0 6px;
+  -moz-border-radius: 6px 0 0 6px;
+  -webkit-border-radius: 6px 0 0 6px;
+}
+
+.bottom-rounded {
+  border-radius: 0 0 6px 6px;
+  -moz-border-radius: 0 0 6px 6px;
+  -webkit-border-radius: 0 0 6px 6px;
+}
+
+.top-rounded {
+  border-radius: 6px 6px 0 0;
+  -moz-border-radius: 6px 6px 0 0;
+  -webkit-border-radius: 6px 6px 0 0;
+}

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/examples/_obsolete/hello/hello.c
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/examples/_obsolete/hello/hello.c b/thirdparty/civetweb-1.9.1/examples/_obsolete/hello/hello.c
new file mode 100644
index 0000000..39253c1
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/examples/_obsolete/hello/hello.c
@@ -0,0 +1,53 @@
+#include <stdio.h>
+#include <string.h>
+#include "civetweb.h"
+
+// This function will be called by civetweb on every new request.
+static int begin_request_handler(struct mg_connection *conn)
+{
+    const struct mg_request_info *request_info = mg_get_request_info(conn);
+    char content[100];
+
+    // Prepare the message we're going to send
+    int content_length = snprintf(content, sizeof(content),
+                                  "Hello from civetweb! Remote port: %d",
+                                  request_info->remote_port);
+
+    // Send HTTP reply to the client
+    mg_printf(conn,
+              "HTTP/1.1 200 OK\r\n"
+              "Content-Type: text/plain\r\n"
+              "Content-Length: %d\r\n"        // Always set Content-Length
+              "\r\n"
+              "%s",
+              content_length, content);
+
+    // Returning non-zero tells civetweb that our function has replied to
+    // the client, and civetweb should not send client any more data.
+    return 1;
+}
+
+int main(void)
+{
+    struct mg_context *ctx;
+    struct mg_callbacks callbacks;
+
+    // List of options. Last element must be NULL.
+    const char *options[] = {"listening_ports", "8080", NULL};
+
+    // Prepare callbacks structure. We have only one callback, the rest are NULL.
+    memset(&callbacks, 0, sizeof(callbacks));
+    callbacks.begin_request = begin_request_handler;
+
+    // Start the web server.
+    ctx = mg_start(&callbacks, NULL, options);
+
+    // Wait until user hits "enter". Server is running in separate thread.
+    // Navigating to http://localhost:8080 will invoke begin_request_handler().
+    getchar();
+
+    // Stop the server.
+    mg_stop(ctx);
+
+    return 0;
+}

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/examples/_obsolete/lua/lua_dll.c
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/examples/_obsolete/lua/lua_dll.c b/thirdparty/civetweb-1.9.1/examples/_obsolete/lua/lua_dll.c
new file mode 100644
index 0000000..79e6b97
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/examples/_obsolete/lua/lua_dll.c
@@ -0,0 +1,21 @@
+#include <stdio.h>
+
+#include "lua.h"
+#include "lauxlib.h"
+
+static int smile(lua_State *L)
+{
+    (void) L;  // Unused
+    printf("%s\n", ":-)");
+    return 0;
+}
+
+int LUA_API luaopen_lua_dll(lua_State *L)
+{
+    static const struct luaL_Reg api[] = {
+        {"smile", smile},
+        {NULL, NULL},
+    };
+    luaL_openlib(L, "lua_dll", api, 0);
+    return 1;
+}

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/examples/_obsolete/post/post.c
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/examples/_obsolete/post/post.c b/thirdparty/civetweb-1.9.1/examples/_obsolete/post/post.c
new file mode 100644
index 0000000..3c5c68c
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/examples/_obsolete/post/post.c
@@ -0,0 +1,58 @@
+#include <stdio.h>
+#include <string.h>
+#include "civetweb.h"
+
+static const char *html_form =
+    "<html><body>POST example."
+    "<form method=\"POST\" action=\"/handle_post_request\">"
+    "Input 1: <input type=\"text\" name=\"input_1\" /> <br/>"
+    "Input 2: <input type=\"text\" name=\"input_2\" /> <br/>"
+    "<input type=\"submit\" />"
+    "</form></body></html>";
+
+static int begin_request_handler(struct mg_connection *conn)
+{
+    const struct mg_request_info *ri = mg_get_request_info(conn);
+    char post_data[1024], input1[sizeof(post_data)], input2[sizeof(post_data)];
+    int post_data_len;
+
+    if (!strcmp(ri->uri, "/handle_post_request")) {
+        // User has submitted a form, show submitted data and a variable value
+        post_data_len = mg_read(conn, post_data, sizeof(post_data));
+
+        // Parse form data. input1 and input2 are guaranteed to be NUL-terminated
+        mg_get_var(post_data, post_data_len, "input_1", input1, sizeof(input1));
+        mg_get_var(post_data, post_data_len, "input_2", input2, sizeof(input2));
+
+        // Send reply to the client, showing submitted form values.
+        mg_printf(conn, "HTTP/1.0 200 OK\r\n"
+                  "Content-Type: text/plain\r\n\r\n"
+                  "Submitted data: [%.*s]\n"
+                  "Submitted data length: %d bytes\n"
+                  "input_1: [%s]\n"
+                  "input_2: [%s]\n",
+                  post_data_len, post_data, post_data_len, input1, input2);
+    } else {
+        // Show HTML form.
+        mg_printf(conn, "HTTP/1.0 200 OK\r\n"
+                  "Content-Length: %d\r\n"
+                  "Content-Type: text/html\r\n\r\n%s",
+                  (int) strlen(html_form), html_form);
+    }
+    return 1;  // Mark request as processed
+}
+
+int main(void)
+{
+    struct mg_context *ctx;
+    const char *options[] = {"listening_ports", "8080", NULL};
+    struct mg_callbacks callbacks;
+
+    memset(&callbacks, 0, sizeof(callbacks));
+    callbacks.begin_request = begin_request_handler;
+    ctx = mg_start(&callbacks, NULL, options);
+    getchar();  // Wait until user hits "enter"
+    mg_stop(ctx);
+
+    return 0;
+}


[07/51] [partial] nifi-minifi-cpp git commit: MINIFI-183 Added civet 1.9.1 sources Added onScheduled hook Added initial two-way TLS-enabled ListenHTTP implementation

Posted by al...@apache.org.
http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_builtins.h
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_builtins.h b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_builtins.h
new file mode 100644
index 0000000..9bea59d
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_builtins.h
@@ -0,0 +1,854 @@
+/*
+ *  Automatically generated by genbuiltins.py, do not edit!
+ */
+
+#ifndef DUK_BUILTINS_H_INCLUDED
+#define DUK_BUILTINS_H_INCLUDED
+
+#if defined(DUK_USE_ROM_STRINGS)
+#error ROM support not enabled, rerun make_dist.py with --rom-support
+#else  /* DUK_USE_ROM_STRINGS */
+#define DUK_STRIDX_UC_UNDEFINED                                       0                              /* 'Undefined' */
+#define DUK_HEAP_STRING_UC_UNDEFINED(heap)                            DUK_HEAP_GET_STRING((heap),DUK_STRIDX_UC_UNDEFINED)
+#define DUK_HTHREAD_STRING_UC_UNDEFINED(thr)                          DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_UC_UNDEFINED)
+#define DUK_STRIDX_UC_NULL                                            1                              /* 'Null' */
+#define DUK_HEAP_STRING_UC_NULL(heap)                                 DUK_HEAP_GET_STRING((heap),DUK_STRIDX_UC_NULL)
+#define DUK_HTHREAD_STRING_UC_NULL(thr)                               DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_UC_NULL)
+#define DUK_STRIDX_UC_ARGUMENTS                                       2                              /* 'Arguments' */
+#define DUK_HEAP_STRING_UC_ARGUMENTS(heap)                            DUK_HEAP_GET_STRING((heap),DUK_STRIDX_UC_ARGUMENTS)
+#define DUK_HTHREAD_STRING_UC_ARGUMENTS(thr)                          DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_UC_ARGUMENTS)
+#define DUK_STRIDX_UC_OBJECT                                          3                              /* 'Object' */
+#define DUK_HEAP_STRING_UC_OBJECT(heap)                               DUK_HEAP_GET_STRING((heap),DUK_STRIDX_UC_OBJECT)
+#define DUK_HTHREAD_STRING_UC_OBJECT(thr)                             DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_UC_OBJECT)
+#define DUK_STRIDX_UC_FUNCTION                                        4                              /* 'Function' */
+#define DUK_HEAP_STRING_UC_FUNCTION(heap)                             DUK_HEAP_GET_STRING((heap),DUK_STRIDX_UC_FUNCTION)
+#define DUK_HTHREAD_STRING_UC_FUNCTION(thr)                           DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_UC_FUNCTION)
+#define DUK_STRIDX_ARRAY                                              5                              /* 'Array' */
+#define DUK_HEAP_STRING_ARRAY(heap)                                   DUK_HEAP_GET_STRING((heap),DUK_STRIDX_ARRAY)
+#define DUK_HTHREAD_STRING_ARRAY(thr)                                 DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_ARRAY)
+#define DUK_STRIDX_UC_STRING                                          6                              /* 'String' */
+#define DUK_HEAP_STRING_UC_STRING(heap)                               DUK_HEAP_GET_STRING((heap),DUK_STRIDX_UC_STRING)
+#define DUK_HTHREAD_STRING_UC_STRING(thr)                             DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_UC_STRING)
+#define DUK_STRIDX_UC_BOOLEAN                                         7                              /* 'Boolean' */
+#define DUK_HEAP_STRING_UC_BOOLEAN(heap)                              DUK_HEAP_GET_STRING((heap),DUK_STRIDX_UC_BOOLEAN)
+#define DUK_HTHREAD_STRING_UC_BOOLEAN(thr)                            DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_UC_BOOLEAN)
+#define DUK_STRIDX_UC_NUMBER                                          8                              /* 'Number' */
+#define DUK_HEAP_STRING_UC_NUMBER(heap)                               DUK_HEAP_GET_STRING((heap),DUK_STRIDX_UC_NUMBER)
+#define DUK_HTHREAD_STRING_UC_NUMBER(thr)                             DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_UC_NUMBER)
+#define DUK_STRIDX_DATE                                               9                              /* 'Date' */
+#define DUK_HEAP_STRING_DATE(heap)                                    DUK_HEAP_GET_STRING((heap),DUK_STRIDX_DATE)
+#define DUK_HTHREAD_STRING_DATE(thr)                                  DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_DATE)
+#define DUK_STRIDX_REG_EXP                                            10                             /* 'RegExp' */
+#define DUK_HEAP_STRING_REG_EXP(heap)                                 DUK_HEAP_GET_STRING((heap),DUK_STRIDX_REG_EXP)
+#define DUK_HTHREAD_STRING_REG_EXP(thr)                               DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_REG_EXP)
+#define DUK_STRIDX_UC_ERROR                                           11                             /* 'Error' */
+#define DUK_HEAP_STRING_UC_ERROR(heap)                                DUK_HEAP_GET_STRING((heap),DUK_STRIDX_UC_ERROR)
+#define DUK_HTHREAD_STRING_UC_ERROR(thr)                              DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_UC_ERROR)
+#define DUK_STRIDX_MATH                                               12                             /* 'Math' */
+#define DUK_HEAP_STRING_MATH(heap)                                    DUK_HEAP_GET_STRING((heap),DUK_STRIDX_MATH)
+#define DUK_HTHREAD_STRING_MATH(thr)                                  DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_MATH)
+#define DUK_STRIDX_JSON                                               13                             /* 'JSON' */
+#define DUK_HEAP_STRING_JSON(heap)                                    DUK_HEAP_GET_STRING((heap),DUK_STRIDX_JSON)
+#define DUK_HTHREAD_STRING_JSON(thr)                                  DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_JSON)
+#define DUK_STRIDX_EMPTY_STRING                                       14                             /* '' */
+#define DUK_HEAP_STRING_EMPTY_STRING(heap)                            DUK_HEAP_GET_STRING((heap),DUK_STRIDX_EMPTY_STRING)
+#define DUK_HTHREAD_STRING_EMPTY_STRING(thr)                          DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_EMPTY_STRING)
+#define DUK_STRIDX_ARRAY_BUFFER                                       15                             /* 'ArrayBuffer' */
+#define DUK_HEAP_STRING_ARRAY_BUFFER(heap)                            DUK_HEAP_GET_STRING((heap),DUK_STRIDX_ARRAY_BUFFER)
+#define DUK_HTHREAD_STRING_ARRAY_BUFFER(thr)                          DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_ARRAY_BUFFER)
+#define DUK_STRIDX_DATA_VIEW                                          16                             /* 'DataView' */
+#define DUK_HEAP_STRING_DATA_VIEW(heap)                               DUK_HEAP_GET_STRING((heap),DUK_STRIDX_DATA_VIEW)
+#define DUK_HTHREAD_STRING_DATA_VIEW(thr)                             DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_DATA_VIEW)
+#define DUK_STRIDX_INT8_ARRAY                                         17                             /* 'Int8Array' */
+#define DUK_HEAP_STRING_INT8_ARRAY(heap)                              DUK_HEAP_GET_STRING((heap),DUK_STRIDX_INT8_ARRAY)
+#define DUK_HTHREAD_STRING_INT8_ARRAY(thr)                            DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_INT8_ARRAY)
+#define DUK_STRIDX_UINT8_ARRAY                                        18                             /* 'Uint8Array' */
+#define DUK_HEAP_STRING_UINT8_ARRAY(heap)                             DUK_HEAP_GET_STRING((heap),DUK_STRIDX_UINT8_ARRAY)
+#define DUK_HTHREAD_STRING_UINT8_ARRAY(thr)                           DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_UINT8_ARRAY)
+#define DUK_STRIDX_UINT8_CLAMPED_ARRAY                                19                             /* 'Uint8ClampedArray' */
+#define DUK_HEAP_STRING_UINT8_CLAMPED_ARRAY(heap)                     DUK_HEAP_GET_STRING((heap),DUK_STRIDX_UINT8_CLAMPED_ARRAY)
+#define DUK_HTHREAD_STRING_UINT8_CLAMPED_ARRAY(thr)                   DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_UINT8_CLAMPED_ARRAY)
+#define DUK_STRIDX_INT16_ARRAY                                        20                             /* 'Int16Array' */
+#define DUK_HEAP_STRING_INT16_ARRAY(heap)                             DUK_HEAP_GET_STRING((heap),DUK_STRIDX_INT16_ARRAY)
+#define DUK_HTHREAD_STRING_INT16_ARRAY(thr)                           DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_INT16_ARRAY)
+#define DUK_STRIDX_UINT16_ARRAY                                       21                             /* 'Uint16Array' */
+#define DUK_HEAP_STRING_UINT16_ARRAY(heap)                            DUK_HEAP_GET_STRING((heap),DUK_STRIDX_UINT16_ARRAY)
+#define DUK_HTHREAD_STRING_UINT16_ARRAY(thr)                          DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_UINT16_ARRAY)
+#define DUK_STRIDX_INT32_ARRAY                                        22                             /* 'Int32Array' */
+#define DUK_HEAP_STRING_INT32_ARRAY(heap)                             DUK_HEAP_GET_STRING((heap),DUK_STRIDX_INT32_ARRAY)
+#define DUK_HTHREAD_STRING_INT32_ARRAY(thr)                           DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_INT32_ARRAY)
+#define DUK_STRIDX_UINT32_ARRAY                                       23                             /* 'Uint32Array' */
+#define DUK_HEAP_STRING_UINT32_ARRAY(heap)                            DUK_HEAP_GET_STRING((heap),DUK_STRIDX_UINT32_ARRAY)
+#define DUK_HTHREAD_STRING_UINT32_ARRAY(thr)                          DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_UINT32_ARRAY)
+#define DUK_STRIDX_FLOAT32_ARRAY                                      24                             /* 'Float32Array' */
+#define DUK_HEAP_STRING_FLOAT32_ARRAY(heap)                           DUK_HEAP_GET_STRING((heap),DUK_STRIDX_FLOAT32_ARRAY)
+#define DUK_HTHREAD_STRING_FLOAT32_ARRAY(thr)                         DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_FLOAT32_ARRAY)
+#define DUK_STRIDX_FLOAT64_ARRAY                                      25                             /* 'Float64Array' */
+#define DUK_HEAP_STRING_FLOAT64_ARRAY(heap)                           DUK_HEAP_GET_STRING((heap),DUK_STRIDX_FLOAT64_ARRAY)
+#define DUK_HTHREAD_STRING_FLOAT64_ARRAY(thr)                         DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_FLOAT64_ARRAY)
+#define DUK_STRIDX_GLOBAL                                             26                             /* 'global' */
+#define DUK_HEAP_STRING_GLOBAL(heap)                                  DUK_HEAP_GET_STRING((heap),DUK_STRIDX_GLOBAL)
+#define DUK_HTHREAD_STRING_GLOBAL(thr)                                DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_GLOBAL)
+#define DUK_STRIDX_OBJ_ENV                                            27                             /* 'ObjEnv' */
+#define DUK_HEAP_STRING_OBJ_ENV(heap)                                 DUK_HEAP_GET_STRING((heap),DUK_STRIDX_OBJ_ENV)
+#define DUK_HTHREAD_STRING_OBJ_ENV(thr)                               DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_OBJ_ENV)
+#define DUK_STRIDX_DEC_ENV                                            28                             /* 'DecEnv' */
+#define DUK_HEAP_STRING_DEC_ENV(heap)                                 DUK_HEAP_GET_STRING((heap),DUK_STRIDX_DEC_ENV)
+#define DUK_HTHREAD_STRING_DEC_ENV(thr)                               DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_DEC_ENV)
+#define DUK_STRIDX_UC_BUFFER                                          29                             /* 'Buffer' */
+#define DUK_HEAP_STRING_UC_BUFFER(heap)                               DUK_HEAP_GET_STRING((heap),DUK_STRIDX_UC_BUFFER)
+#define DUK_HTHREAD_STRING_UC_BUFFER(thr)                             DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_UC_BUFFER)
+#define DUK_STRIDX_UC_POINTER                                         30                             /* 'Pointer' */
+#define DUK_HEAP_STRING_UC_POINTER(heap)                              DUK_HEAP_GET_STRING((heap),DUK_STRIDX_UC_POINTER)
+#define DUK_HTHREAD_STRING_UC_POINTER(thr)                            DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_UC_POINTER)
+#define DUK_STRIDX_UC_THREAD                                          31                             /* 'Thread' */
+#define DUK_HEAP_STRING_UC_THREAD(heap)                               DUK_HEAP_GET_STRING((heap),DUK_STRIDX_UC_THREAD)
+#define DUK_HTHREAD_STRING_UC_THREAD(thr)                             DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_UC_THREAD)
+#define DUK_STRIDX_EVAL                                               32                             /* 'eval' */
+#define DUK_HEAP_STRING_EVAL(heap)                                    DUK_HEAP_GET_STRING((heap),DUK_STRIDX_EVAL)
+#define DUK_HTHREAD_STRING_EVAL(thr)                                  DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_EVAL)
+#define DUK_STRIDX_DEFINE_PROPERTY                                    33                             /* 'defineProperty' */
+#define DUK_HEAP_STRING_DEFINE_PROPERTY(heap)                         DUK_HEAP_GET_STRING((heap),DUK_STRIDX_DEFINE_PROPERTY)
+#define DUK_HTHREAD_STRING_DEFINE_PROPERTY(thr)                       DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_DEFINE_PROPERTY)
+#define DUK_STRIDX_VALUE                                              34                             /* 'value' */
+#define DUK_HEAP_STRING_VALUE(heap)                                   DUK_HEAP_GET_STRING((heap),DUK_STRIDX_VALUE)
+#define DUK_HTHREAD_STRING_VALUE(thr)                                 DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_VALUE)
+#define DUK_STRIDX_WRITABLE                                           35                             /* 'writable' */
+#define DUK_HEAP_STRING_WRITABLE(heap)                                DUK_HEAP_GET_STRING((heap),DUK_STRIDX_WRITABLE)
+#define DUK_HTHREAD_STRING_WRITABLE(thr)                              DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_WRITABLE)
+#define DUK_STRIDX_CONFIGURABLE                                       36                             /* 'configurable' */
+#define DUK_HEAP_STRING_CONFIGURABLE(heap)                            DUK_HEAP_GET_STRING((heap),DUK_STRIDX_CONFIGURABLE)
+#define DUK_HTHREAD_STRING_CONFIGURABLE(thr)                          DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_CONFIGURABLE)
+#define DUK_STRIDX_ENUMERABLE                                         37                             /* 'enumerable' */
+#define DUK_HEAP_STRING_ENUMERABLE(heap)                              DUK_HEAP_GET_STRING((heap),DUK_STRIDX_ENUMERABLE)
+#define DUK_HTHREAD_STRING_ENUMERABLE(thr)                            DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_ENUMERABLE)
+#define DUK_STRIDX_JOIN                                               38                             /* 'join' */
+#define DUK_HEAP_STRING_JOIN(heap)                                    DUK_HEAP_GET_STRING((heap),DUK_STRIDX_JOIN)
+#define DUK_HTHREAD_STRING_JOIN(thr)                                  DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_JOIN)
+#define DUK_STRIDX_TO_LOCALE_STRING                                   39                             /* 'toLocaleString' */
+#define DUK_HEAP_STRING_TO_LOCALE_STRING(heap)                        DUK_HEAP_GET_STRING((heap),DUK_STRIDX_TO_LOCALE_STRING)
+#define DUK_HTHREAD_STRING_TO_LOCALE_STRING(thr)                      DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_TO_LOCALE_STRING)
+#define DUK_STRIDX_VALUE_OF                                           40                             /* 'valueOf' */
+#define DUK_HEAP_STRING_VALUE_OF(heap)                                DUK_HEAP_GET_STRING((heap),DUK_STRIDX_VALUE_OF)
+#define DUK_HTHREAD_STRING_VALUE_OF(thr)                              DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_VALUE_OF)
+#define DUK_STRIDX_TO_UTC_STRING                                      41                             /* 'toUTCString' */
+#define DUK_HEAP_STRING_TO_UTC_STRING(heap)                           DUK_HEAP_GET_STRING((heap),DUK_STRIDX_TO_UTC_STRING)
+#define DUK_HTHREAD_STRING_TO_UTC_STRING(thr)                         DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_TO_UTC_STRING)
+#define DUK_STRIDX_TO_ISO_STRING                                      42                             /* 'toISOString' */
+#define DUK_HEAP_STRING_TO_ISO_STRING(heap)                           DUK_HEAP_GET_STRING((heap),DUK_STRIDX_TO_ISO_STRING)
+#define DUK_HTHREAD_STRING_TO_ISO_STRING(thr)                         DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_TO_ISO_STRING)
+#define DUK_STRIDX_TO_GMT_STRING                                      43                             /* 'toGMTString' */
+#define DUK_HEAP_STRING_TO_GMT_STRING(heap)                           DUK_HEAP_GET_STRING((heap),DUK_STRIDX_TO_GMT_STRING)
+#define DUK_HTHREAD_STRING_TO_GMT_STRING(thr)                         DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_TO_GMT_STRING)
+#define DUK_STRIDX_SOURCE                                             44                             /* 'source' */
+#define DUK_HEAP_STRING_SOURCE(heap)                                  DUK_HEAP_GET_STRING((heap),DUK_STRIDX_SOURCE)
+#define DUK_HTHREAD_STRING_SOURCE(thr)                                DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_SOURCE)
+#define DUK_STRIDX_IGNORE_CASE                                        45                             /* 'ignoreCase' */
+#define DUK_HEAP_STRING_IGNORE_CASE(heap)                             DUK_HEAP_GET_STRING((heap),DUK_STRIDX_IGNORE_CASE)
+#define DUK_HTHREAD_STRING_IGNORE_CASE(thr)                           DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_IGNORE_CASE)
+#define DUK_STRIDX_MULTILINE                                          46                             /* 'multiline' */
+#define DUK_HEAP_STRING_MULTILINE(heap)                               DUK_HEAP_GET_STRING((heap),DUK_STRIDX_MULTILINE)
+#define DUK_HTHREAD_STRING_MULTILINE(thr)                             DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_MULTILINE)
+#define DUK_STRIDX_LAST_INDEX                                         47                             /* 'lastIndex' */
+#define DUK_HEAP_STRING_LAST_INDEX(heap)                              DUK_HEAP_GET_STRING((heap),DUK_STRIDX_LAST_INDEX)
+#define DUK_HTHREAD_STRING_LAST_INDEX(thr)                            DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_LAST_INDEX)
+#define DUK_STRIDX_ESCAPED_EMPTY_REGEXP                               48                             /* '(?:)' */
+#define DUK_HEAP_STRING_ESCAPED_EMPTY_REGEXP(heap)                    DUK_HEAP_GET_STRING((heap),DUK_STRIDX_ESCAPED_EMPTY_REGEXP)
+#define DUK_HTHREAD_STRING_ESCAPED_EMPTY_REGEXP(thr)                  DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_ESCAPED_EMPTY_REGEXP)
+#define DUK_STRIDX_INDEX                                              49                             /* 'index' */
+#define DUK_HEAP_STRING_INDEX(heap)                                   DUK_HEAP_GET_STRING((heap),DUK_STRIDX_INDEX)
+#define DUK_HTHREAD_STRING_INDEX(thr)                                 DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_INDEX)
+#define DUK_STRIDX_PROTOTYPE                                          50                             /* 'prototype' */
+#define DUK_HEAP_STRING_PROTOTYPE(heap)                               DUK_HEAP_GET_STRING((heap),DUK_STRIDX_PROTOTYPE)
+#define DUK_HTHREAD_STRING_PROTOTYPE(thr)                             DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_PROTOTYPE)
+#define DUK_STRIDX_CONSTRUCTOR                                        51                             /* 'constructor' */
+#define DUK_HEAP_STRING_CONSTRUCTOR(heap)                             DUK_HEAP_GET_STRING((heap),DUK_STRIDX_CONSTRUCTOR)
+#define DUK_HTHREAD_STRING_CONSTRUCTOR(thr)                           DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_CONSTRUCTOR)
+#define DUK_STRIDX_MESSAGE                                            52                             /* 'message' */
+#define DUK_HEAP_STRING_MESSAGE(heap)                                 DUK_HEAP_GET_STRING((heap),DUK_STRIDX_MESSAGE)
+#define DUK_HTHREAD_STRING_MESSAGE(thr)                               DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_MESSAGE)
+#define DUK_STRIDX_LC_BOOLEAN                                         53                             /* 'boolean' */
+#define DUK_HEAP_STRING_LC_BOOLEAN(heap)                              DUK_HEAP_GET_STRING((heap),DUK_STRIDX_LC_BOOLEAN)
+#define DUK_HTHREAD_STRING_LC_BOOLEAN(thr)                            DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_LC_BOOLEAN)
+#define DUK_STRIDX_LC_NUMBER                                          54                             /* 'number' */
+#define DUK_HEAP_STRING_LC_NUMBER(heap)                               DUK_HEAP_GET_STRING((heap),DUK_STRIDX_LC_NUMBER)
+#define DUK_HTHREAD_STRING_LC_NUMBER(thr)                             DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_LC_NUMBER)
+#define DUK_STRIDX_LC_STRING                                          55                             /* 'string' */
+#define DUK_HEAP_STRING_LC_STRING(heap)                               DUK_HEAP_GET_STRING((heap),DUK_STRIDX_LC_STRING)
+#define DUK_HTHREAD_STRING_LC_STRING(thr)                             DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_LC_STRING)
+#define DUK_STRIDX_LC_OBJECT                                          56                             /* 'object' */
+#define DUK_HEAP_STRING_LC_OBJECT(heap)                               DUK_HEAP_GET_STRING((heap),DUK_STRIDX_LC_OBJECT)
+#define DUK_HTHREAD_STRING_LC_OBJECT(thr)                             DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_LC_OBJECT)
+#define DUK_STRIDX_LC_UNDEFINED                                       57                             /* 'undefined' */
+#define DUK_HEAP_STRING_LC_UNDEFINED(heap)                            DUK_HEAP_GET_STRING((heap),DUK_STRIDX_LC_UNDEFINED)
+#define DUK_HTHREAD_STRING_LC_UNDEFINED(thr)                          DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_LC_UNDEFINED)
+#define DUK_STRIDX_NAN                                                58                             /* 'NaN' */
+#define DUK_HEAP_STRING_NAN(heap)                                     DUK_HEAP_GET_STRING((heap),DUK_STRIDX_NAN)
+#define DUK_HTHREAD_STRING_NAN(thr)                                   DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_NAN)
+#define DUK_STRIDX_INFINITY                                           59                             /* 'Infinity' */
+#define DUK_HEAP_STRING_INFINITY(heap)                                DUK_HEAP_GET_STRING((heap),DUK_STRIDX_INFINITY)
+#define DUK_HTHREAD_STRING_INFINITY(thr)                              DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_INFINITY)
+#define DUK_STRIDX_MINUS_INFINITY                                     60                             /* '-Infinity' */
+#define DUK_HEAP_STRING_MINUS_INFINITY(heap)                          DUK_HEAP_GET_STRING((heap),DUK_STRIDX_MINUS_INFINITY)
+#define DUK_HTHREAD_STRING_MINUS_INFINITY(thr)                        DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_MINUS_INFINITY)
+#define DUK_STRIDX_MINUS_ZERO                                         61                             /* '-0' */
+#define DUK_HEAP_STRING_MINUS_ZERO(heap)                              DUK_HEAP_GET_STRING((heap),DUK_STRIDX_MINUS_ZERO)
+#define DUK_HTHREAD_STRING_MINUS_ZERO(thr)                            DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_MINUS_ZERO)
+#define DUK_STRIDX_COMMA                                              62                             /* ',' */
+#define DUK_HEAP_STRING_COMMA(heap)                                   DUK_HEAP_GET_STRING((heap),DUK_STRIDX_COMMA)
+#define DUK_HTHREAD_STRING_COMMA(thr)                                 DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_COMMA)
+#define DUK_STRIDX_SPACE                                              63                             /* ' ' */
+#define DUK_HEAP_STRING_SPACE(heap)                                   DUK_HEAP_GET_STRING((heap),DUK_STRIDX_SPACE)
+#define DUK_HTHREAD_STRING_SPACE(thr)                                 DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_SPACE)
+#define DUK_STRIDX_NEWLINE_4SPACE                                     64                             /* '\n    ' */
+#define DUK_HEAP_STRING_NEWLINE_4SPACE(heap)                          DUK_HEAP_GET_STRING((heap),DUK_STRIDX_NEWLINE_4SPACE)
+#define DUK_HTHREAD_STRING_NEWLINE_4SPACE(thr)                        DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_NEWLINE_4SPACE)
+#define DUK_STRIDX_BRACKETED_ELLIPSIS                                 65                             /* '[...]' */
+#define DUK_HEAP_STRING_BRACKETED_ELLIPSIS(heap)                      DUK_HEAP_GET_STRING((heap),DUK_STRIDX_BRACKETED_ELLIPSIS)
+#define DUK_HTHREAD_STRING_BRACKETED_ELLIPSIS(thr)                    DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_BRACKETED_ELLIPSIS)
+#define DUK_STRIDX_INVALID_DATE                                       66                             /* 'Invalid Date' */
+#define DUK_HEAP_STRING_INVALID_DATE(heap)                            DUK_HEAP_GET_STRING((heap),DUK_STRIDX_INVALID_DATE)
+#define DUK_HTHREAD_STRING_INVALID_DATE(thr)                          DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_INVALID_DATE)
+#define DUK_STRIDX_LC_ARGUMENTS                                       67                             /* 'arguments' */
+#define DUK_HEAP_STRING_LC_ARGUMENTS(heap)                            DUK_HEAP_GET_STRING((heap),DUK_STRIDX_LC_ARGUMENTS)
+#define DUK_HTHREAD_STRING_LC_ARGUMENTS(thr)                          DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_LC_ARGUMENTS)
+#define DUK_STRIDX_CALLEE                                             68                             /* 'callee' */
+#define DUK_HEAP_STRING_CALLEE(heap)                                  DUK_HEAP_GET_STRING((heap),DUK_STRIDX_CALLEE)
+#define DUK_HTHREAD_STRING_CALLEE(thr)                                DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_CALLEE)
+#define DUK_STRIDX_CALLER                                             69                             /* 'caller' */
+#define DUK_HEAP_STRING_CALLER(heap)                                  DUK_HEAP_GET_STRING((heap),DUK_STRIDX_CALLER)
+#define DUK_HTHREAD_STRING_CALLER(thr)                                DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_CALLER)
+#define DUK_STRIDX_HAS                                                70                             /* 'has' */
+#define DUK_HEAP_STRING_HAS(heap)                                     DUK_HEAP_GET_STRING((heap),DUK_STRIDX_HAS)
+#define DUK_HTHREAD_STRING_HAS(thr)                                   DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_HAS)
+#define DUK_STRIDX_GET                                                71                             /* 'get' */
+#define DUK_HEAP_STRING_GET(heap)                                     DUK_HEAP_GET_STRING((heap),DUK_STRIDX_GET)
+#define DUK_HTHREAD_STRING_GET(thr)                                   DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_GET)
+#define DUK_STRIDX_DELETE_PROPERTY                                    72                             /* 'deleteProperty' */
+#define DUK_HEAP_STRING_DELETE_PROPERTY(heap)                         DUK_HEAP_GET_STRING((heap),DUK_STRIDX_DELETE_PROPERTY)
+#define DUK_HTHREAD_STRING_DELETE_PROPERTY(thr)                       DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_DELETE_PROPERTY)
+#define DUK_STRIDX_ENUMERATE                                          73                             /* 'enumerate' */
+#define DUK_HEAP_STRING_ENUMERATE(heap)                               DUK_HEAP_GET_STRING((heap),DUK_STRIDX_ENUMERATE)
+#define DUK_HTHREAD_STRING_ENUMERATE(thr)                             DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_ENUMERATE)
+#define DUK_STRIDX_OWN_KEYS                                           74                             /* 'ownKeys' */
+#define DUK_HEAP_STRING_OWN_KEYS(heap)                                DUK_HEAP_GET_STRING((heap),DUK_STRIDX_OWN_KEYS)
+#define DUK_HTHREAD_STRING_OWN_KEYS(thr)                              DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_OWN_KEYS)
+#define DUK_STRIDX_SET_PROTOTYPE_OF                                   75                             /* 'setPrototypeOf' */
+#define DUK_HEAP_STRING_SET_PROTOTYPE_OF(heap)                        DUK_HEAP_GET_STRING((heap),DUK_STRIDX_SET_PROTOTYPE_OF)
+#define DUK_HTHREAD_STRING_SET_PROTOTYPE_OF(thr)                      DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_SET_PROTOTYPE_OF)
+#define DUK_STRIDX___PROTO__                                          76                             /* '__proto__' */
+#define DUK_HEAP_STRING___PROTO__(heap)                               DUK_HEAP_GET_STRING((heap),DUK_STRIDX___PROTO__)
+#define DUK_HTHREAD_STRING___PROTO__(thr)                             DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX___PROTO__)
+#define DUK_STRIDX_REQUIRE                                            77                             /* 'require' */
+#define DUK_HEAP_STRING_REQUIRE(heap)                                 DUK_HEAP_GET_STRING((heap),DUK_STRIDX_REQUIRE)
+#define DUK_HTHREAD_STRING_REQUIRE(thr)                               DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_REQUIRE)
+#define DUK_STRIDX_ID                                                 78                             /* 'id' */
+#define DUK_HEAP_STRING_ID(heap)                                      DUK_HEAP_GET_STRING((heap),DUK_STRIDX_ID)
+#define DUK_HTHREAD_STRING_ID(thr)                                    DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_ID)
+#define DUK_STRIDX_EXPORTS                                            79                             /* 'exports' */
+#define DUK_HEAP_STRING_EXPORTS(heap)                                 DUK_HEAP_GET_STRING((heap),DUK_STRIDX_EXPORTS)
+#define DUK_HTHREAD_STRING_EXPORTS(thr)                               DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_EXPORTS)
+#define DUK_STRIDX_FILENAME                                           80                             /* 'filename' */
+#define DUK_HEAP_STRING_FILENAME(heap)                                DUK_HEAP_GET_STRING((heap),DUK_STRIDX_FILENAME)
+#define DUK_HTHREAD_STRING_FILENAME(thr)                              DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_FILENAME)
+#define DUK_STRIDX_TO_STRING                                          81                             /* 'toString' */
+#define DUK_HEAP_STRING_TO_STRING(heap)                               DUK_HEAP_GET_STRING((heap),DUK_STRIDX_TO_STRING)
+#define DUK_HTHREAD_STRING_TO_STRING(thr)                             DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_TO_STRING)
+#define DUK_STRIDX_TO_JSON                                            82                             /* 'toJSON' */
+#define DUK_HEAP_STRING_TO_JSON(heap)                                 DUK_HEAP_GET_STRING((heap),DUK_STRIDX_TO_JSON)
+#define DUK_HTHREAD_STRING_TO_JSON(thr)                               DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_TO_JSON)
+#define DUK_STRIDX_TYPE                                               83                             /* 'type' */
+#define DUK_HEAP_STRING_TYPE(heap)                                    DUK_HEAP_GET_STRING((heap),DUK_STRIDX_TYPE)
+#define DUK_HTHREAD_STRING_TYPE(thr)                                  DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_TYPE)
+#define DUK_STRIDX_DATA                                               84                             /* 'data' */
+#define DUK_HEAP_STRING_DATA(heap)                                    DUK_HEAP_GET_STRING((heap),DUK_STRIDX_DATA)
+#define DUK_HTHREAD_STRING_DATA(thr)                                  DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_DATA)
+#define DUK_STRIDX_LENGTH                                             85                             /* 'length' */
+#define DUK_HEAP_STRING_LENGTH(heap)                                  DUK_HEAP_GET_STRING((heap),DUK_STRIDX_LENGTH)
+#define DUK_HTHREAD_STRING_LENGTH(thr)                                DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_LENGTH)
+#define DUK_STRIDX_BYTE_LENGTH                                        86                             /* 'byteLength' */
+#define DUK_HEAP_STRING_BYTE_LENGTH(heap)                             DUK_HEAP_GET_STRING((heap),DUK_STRIDX_BYTE_LENGTH)
+#define DUK_HTHREAD_STRING_BYTE_LENGTH(thr)                           DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_BYTE_LENGTH)
+#define DUK_STRIDX_BYTE_OFFSET                                        87                             /* 'byteOffset' */
+#define DUK_HEAP_STRING_BYTE_OFFSET(heap)                             DUK_HEAP_GET_STRING((heap),DUK_STRIDX_BYTE_OFFSET)
+#define DUK_HTHREAD_STRING_BYTE_OFFSET(thr)                           DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_BYTE_OFFSET)
+#define DUK_STRIDX_BYTES_PER_ELEMENT                                  88                             /* 'BYTES_PER_ELEMENT' */
+#define DUK_HEAP_STRING_BYTES_PER_ELEMENT(heap)                       DUK_HEAP_GET_STRING((heap),DUK_STRIDX_BYTES_PER_ELEMENT)
+#define DUK_HTHREAD_STRING_BYTES_PER_ELEMENT(thr)                     DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_BYTES_PER_ELEMENT)
+#define DUK_STRIDX_SET                                                89                             /* 'set' */
+#define DUK_HEAP_STRING_SET(heap)                                     DUK_HEAP_GET_STRING((heap),DUK_STRIDX_SET)
+#define DUK_HTHREAD_STRING_SET(thr)                                   DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_SET)
+#define DUK_STRIDX_STACK                                              90                             /* 'stack' */
+#define DUK_HEAP_STRING_STACK(heap)                                   DUK_HEAP_GET_STRING((heap),DUK_STRIDX_STACK)
+#define DUK_HTHREAD_STRING_STACK(thr)                                 DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_STACK)
+#define DUK_STRIDX_PC                                                 91                             /* 'pc' */
+#define DUK_HEAP_STRING_PC(heap)                                      DUK_HEAP_GET_STRING((heap),DUK_STRIDX_PC)
+#define DUK_HTHREAD_STRING_PC(thr)                                    DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_PC)
+#define DUK_STRIDX_LINE_NUMBER                                        92                             /* 'lineNumber' */
+#define DUK_HEAP_STRING_LINE_NUMBER(heap)                             DUK_HEAP_GET_STRING((heap),DUK_STRIDX_LINE_NUMBER)
+#define DUK_HTHREAD_STRING_LINE_NUMBER(thr)                           DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_LINE_NUMBER)
+#define DUK_STRIDX_INT_TRACEDATA                                      93                             /* '\xffTracedata' */
+#define DUK_HEAP_STRING_INT_TRACEDATA(heap)                           DUK_HEAP_GET_STRING((heap),DUK_STRIDX_INT_TRACEDATA)
+#define DUK_HTHREAD_STRING_INT_TRACEDATA(thr)                         DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_INT_TRACEDATA)
+#define DUK_STRIDX_NAME                                               94                             /* 'name' */
+#define DUK_HEAP_STRING_NAME(heap)                                    DUK_HEAP_GET_STRING((heap),DUK_STRIDX_NAME)
+#define DUK_HTHREAD_STRING_NAME(thr)                                  DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_NAME)
+#define DUK_STRIDX_FILE_NAME                                          95                             /* 'fileName' */
+#define DUK_HEAP_STRING_FILE_NAME(heap)                               DUK_HEAP_GET_STRING((heap),DUK_STRIDX_FILE_NAME)
+#define DUK_HTHREAD_STRING_FILE_NAME(thr)                             DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_FILE_NAME)
+#define DUK_STRIDX_LC_BUFFER                                          96                             /* 'buffer' */
+#define DUK_HEAP_STRING_LC_BUFFER(heap)                               DUK_HEAP_GET_STRING((heap),DUK_STRIDX_LC_BUFFER)
+#define DUK_HTHREAD_STRING_LC_BUFFER(thr)                             DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_LC_BUFFER)
+#define DUK_STRIDX_LC_POINTER                                         97                             /* 'pointer' */
+#define DUK_HEAP_STRING_LC_POINTER(heap)                              DUK_HEAP_GET_STRING((heap),DUK_STRIDX_LC_POINTER)
+#define DUK_HTHREAD_STRING_LC_POINTER(thr)                            DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_LC_POINTER)
+#define DUK_STRIDX_INT_VALUE                                          98                             /* '\xffValue' */
+#define DUK_HEAP_STRING_INT_VALUE(heap)                               DUK_HEAP_GET_STRING((heap),DUK_STRIDX_INT_VALUE)
+#define DUK_HTHREAD_STRING_INT_VALUE(thr)                             DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_INT_VALUE)
+#define DUK_STRIDX_INT_NEXT                                           99                             /* '\xffNext' */
+#define DUK_HEAP_STRING_INT_NEXT(heap)                                DUK_HEAP_GET_STRING((heap),DUK_STRIDX_INT_NEXT)
+#define DUK_HTHREAD_STRING_INT_NEXT(thr)                              DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_INT_NEXT)
+#define DUK_STRIDX_INT_BYTECODE                                       100                            /* '\xffBytecode' */
+#define DUK_HEAP_STRING_INT_BYTECODE(heap)                            DUK_HEAP_GET_STRING((heap),DUK_STRIDX_INT_BYTECODE)
+#define DUK_HTHREAD_STRING_INT_BYTECODE(thr)                          DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_INT_BYTECODE)
+#define DUK_STRIDX_INT_FORMALS                                        101                            /* '\xffFormals' */
+#define DUK_HEAP_STRING_INT_FORMALS(heap)                             DUK_HEAP_GET_STRING((heap),DUK_STRIDX_INT_FORMALS)
+#define DUK_HTHREAD_STRING_INT_FORMALS(thr)                           DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_INT_FORMALS)
+#define DUK_STRIDX_INT_VARMAP                                         102                            /* '\xffVarmap' */
+#define DUK_HEAP_STRING_INT_VARMAP(heap)                              DUK_HEAP_GET_STRING((heap),DUK_STRIDX_INT_VARMAP)
+#define DUK_HTHREAD_STRING_INT_VARMAP(thr)                            DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_INT_VARMAP)
+#define DUK_STRIDX_INT_LEXENV                                         103                            /* '\xffLexenv' */
+#define DUK_HEAP_STRING_INT_LEXENV(heap)                              DUK_HEAP_GET_STRING((heap),DUK_STRIDX_INT_LEXENV)
+#define DUK_HTHREAD_STRING_INT_LEXENV(thr)                            DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_INT_LEXENV)
+#define DUK_STRIDX_INT_VARENV                                         104                            /* '\xffVarenv' */
+#define DUK_HEAP_STRING_INT_VARENV(heap)                              DUK_HEAP_GET_STRING((heap),DUK_STRIDX_INT_VARENV)
+#define DUK_HTHREAD_STRING_INT_VARENV(thr)                            DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_INT_VARENV)
+#define DUK_STRIDX_INT_SOURCE                                         105                            /* '\xffSource' */
+#define DUK_HEAP_STRING_INT_SOURCE(heap)                              DUK_HEAP_GET_STRING((heap),DUK_STRIDX_INT_SOURCE)
+#define DUK_HTHREAD_STRING_INT_SOURCE(thr)                            DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_INT_SOURCE)
+#define DUK_STRIDX_INT_PC2LINE                                        106                            /* '\xffPc2line' */
+#define DUK_HEAP_STRING_INT_PC2LINE(heap)                             DUK_HEAP_GET_STRING((heap),DUK_STRIDX_INT_PC2LINE)
+#define DUK_HTHREAD_STRING_INT_PC2LINE(thr)                           DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_INT_PC2LINE)
+#define DUK_STRIDX_INT_ARGS                                           107                            /* '\xffArgs' */
+#define DUK_HEAP_STRING_INT_ARGS(heap)                                DUK_HEAP_GET_STRING((heap),DUK_STRIDX_INT_ARGS)
+#define DUK_HTHREAD_STRING_INT_ARGS(thr)                              DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_INT_ARGS)
+#define DUK_STRIDX_INT_MAP                                            108                            /* '\xffMap' */
+#define DUK_HEAP_STRING_INT_MAP(heap)                                 DUK_HEAP_GET_STRING((heap),DUK_STRIDX_INT_MAP)
+#define DUK_HTHREAD_STRING_INT_MAP(thr)                               DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_INT_MAP)
+#define DUK_STRIDX_INT_FINALIZER                                      109                            /* '\xffFinalizer' */
+#define DUK_HEAP_STRING_INT_FINALIZER(heap)                           DUK_HEAP_GET_STRING((heap),DUK_STRIDX_INT_FINALIZER)
+#define DUK_HTHREAD_STRING_INT_FINALIZER(thr)                         DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_INT_FINALIZER)
+#define DUK_STRIDX_INT_HANDLER                                        110                            /* '\xffHandler' */
+#define DUK_HEAP_STRING_INT_HANDLER(heap)                             DUK_HEAP_GET_STRING((heap),DUK_STRIDX_INT_HANDLER)
+#define DUK_HTHREAD_STRING_INT_HANDLER(thr)                           DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_INT_HANDLER)
+#define DUK_STRIDX_INT_CALLEE                                         111                            /* '\xffCallee' */
+#define DUK_HEAP_STRING_INT_CALLEE(heap)                              DUK_HEAP_GET_STRING((heap),DUK_STRIDX_INT_CALLEE)
+#define DUK_HTHREAD_STRING_INT_CALLEE(thr)                            DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_INT_CALLEE)
+#define DUK_STRIDX_INT_THREAD                                         112                            /* '\xffThread' */
+#define DUK_HEAP_STRING_INT_THREAD(heap)                              DUK_HEAP_GET_STRING((heap),DUK_STRIDX_INT_THREAD)
+#define DUK_HTHREAD_STRING_INT_THREAD(thr)                            DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_INT_THREAD)
+#define DUK_STRIDX_INT_REGBASE                                        113                            /* '\xffRegbase' */
+#define DUK_HEAP_STRING_INT_REGBASE(heap)                             DUK_HEAP_GET_STRING((heap),DUK_STRIDX_INT_REGBASE)
+#define DUK_HTHREAD_STRING_INT_REGBASE(thr)                           DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_INT_REGBASE)
+#define DUK_STRIDX_INT_TARGET                                         114                            /* '\xffTarget' */
+#define DUK_HEAP_STRING_INT_TARGET(heap)                              DUK_HEAP_GET_STRING((heap),DUK_STRIDX_INT_TARGET)
+#define DUK_HTHREAD_STRING_INT_TARGET(thr)                            DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_INT_TARGET)
+#define DUK_STRIDX_INT_THIS                                           115                            /* '\xffThis' */
+#define DUK_HEAP_STRING_INT_THIS(heap)                                DUK_HEAP_GET_STRING((heap),DUK_STRIDX_INT_THIS)
+#define DUK_HTHREAD_STRING_INT_THIS(thr)                              DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_INT_THIS)
+#define DUK_STRIDX_COMPILE                                            116                            /* 'compile' */
+#define DUK_HEAP_STRING_COMPILE(heap)                                 DUK_HEAP_GET_STRING((heap),DUK_STRIDX_COMPILE)
+#define DUK_HTHREAD_STRING_COMPILE(thr)                               DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_COMPILE)
+#define DUK_STRIDX_INPUT                                              117                            /* 'input' */
+#define DUK_HEAP_STRING_INPUT(heap)                                   DUK_HEAP_GET_STRING((heap),DUK_STRIDX_INPUT)
+#define DUK_HTHREAD_STRING_INPUT(thr)                                 DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_INPUT)
+#define DUK_STRIDX_ERR_CREATE                                         118                            /* 'errCreate' */
+#define DUK_HEAP_STRING_ERR_CREATE(heap)                              DUK_HEAP_GET_STRING((heap),DUK_STRIDX_ERR_CREATE)
+#define DUK_HTHREAD_STRING_ERR_CREATE(thr)                            DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_ERR_CREATE)
+#define DUK_STRIDX_ERR_THROW                                          119                            /* 'errThrow' */
+#define DUK_HEAP_STRING_ERR_THROW(heap)                               DUK_HEAP_GET_STRING((heap),DUK_STRIDX_ERR_THROW)
+#define DUK_HTHREAD_STRING_ERR_THROW(thr)                             DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_ERR_THROW)
+#define DUK_STRIDX_MOD_SEARCH                                         120                            /* 'modSearch' */
+#define DUK_HEAP_STRING_MOD_SEARCH(heap)                              DUK_HEAP_GET_STRING((heap),DUK_STRIDX_MOD_SEARCH)
+#define DUK_HTHREAD_STRING_MOD_SEARCH(thr)                            DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_MOD_SEARCH)
+#define DUK_STRIDX_MOD_LOADED                                         121                            /* 'modLoaded' */
+#define DUK_HEAP_STRING_MOD_LOADED(heap)                              DUK_HEAP_GET_STRING((heap),DUK_STRIDX_MOD_LOADED)
+#define DUK_HTHREAD_STRING_MOD_LOADED(thr)                            DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_MOD_LOADED)
+#define DUK_STRIDX_ENV                                                122                            /* 'env' */
+#define DUK_HEAP_STRING_ENV(heap)                                     DUK_HEAP_GET_STRING((heap),DUK_STRIDX_ENV)
+#define DUK_HTHREAD_STRING_ENV(thr)                                   DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_ENV)
+#define DUK_STRIDX_HEX                                                123                            /* 'hex' */
+#define DUK_HEAP_STRING_HEX(heap)                                     DUK_HEAP_GET_STRING((heap),DUK_STRIDX_HEX)
+#define DUK_HTHREAD_STRING_HEX(thr)                                   DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_HEX)
+#define DUK_STRIDX_BASE64                                             124                            /* 'base64' */
+#define DUK_HEAP_STRING_BASE64(heap)                                  DUK_HEAP_GET_STRING((heap),DUK_STRIDX_BASE64)
+#define DUK_HTHREAD_STRING_BASE64(thr)                                DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_BASE64)
+#define DUK_STRIDX_JX                                                 125                            /* 'jx' */
+#define DUK_HEAP_STRING_JX(heap)                                      DUK_HEAP_GET_STRING((heap),DUK_STRIDX_JX)
+#define DUK_HTHREAD_STRING_JX(thr)                                    DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_JX)
+#define DUK_STRIDX_JC                                                 126                            /* 'jc' */
+#define DUK_HEAP_STRING_JC(heap)                                      DUK_HEAP_GET_STRING((heap),DUK_STRIDX_JC)
+#define DUK_HTHREAD_STRING_JC(thr)                                    DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_JC)
+#define DUK_STRIDX_RESUME                                             127                            /* 'resume' */
+#define DUK_HEAP_STRING_RESUME(heap)                                  DUK_HEAP_GET_STRING((heap),DUK_STRIDX_RESUME)
+#define DUK_HTHREAD_STRING_RESUME(thr)                                DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_RESUME)
+#define DUK_STRIDX_FMT                                                128                            /* 'fmt' */
+#define DUK_HEAP_STRING_FMT(heap)                                     DUK_HEAP_GET_STRING((heap),DUK_STRIDX_FMT)
+#define DUK_HTHREAD_STRING_FMT(thr)                                   DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_FMT)
+#define DUK_STRIDX_RAW                                                129                            /* 'raw' */
+#define DUK_HEAP_STRING_RAW(heap)                                     DUK_HEAP_GET_STRING((heap),DUK_STRIDX_RAW)
+#define DUK_HTHREAD_STRING_RAW(thr)                                   DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_RAW)
+#define DUK_STRIDX_LC_TRACE                                           130                            /* 'trace' */
+#define DUK_HEAP_STRING_LC_TRACE(heap)                                DUK_HEAP_GET_STRING((heap),DUK_STRIDX_LC_TRACE)
+#define DUK_HTHREAD_STRING_LC_TRACE(thr)                              DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_LC_TRACE)
+#define DUK_STRIDX_LC_DEBUG                                           131                            /* 'debug' */
+#define DUK_HEAP_STRING_LC_DEBUG(heap)                                DUK_HEAP_GET_STRING((heap),DUK_STRIDX_LC_DEBUG)
+#define DUK_HTHREAD_STRING_LC_DEBUG(thr)                              DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_LC_DEBUG)
+#define DUK_STRIDX_LC_INFO                                            132                            /* 'info' */
+#define DUK_HEAP_STRING_LC_INFO(heap)                                 DUK_HEAP_GET_STRING((heap),DUK_STRIDX_LC_INFO)
+#define DUK_HTHREAD_STRING_LC_INFO(thr)                               DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_LC_INFO)
+#define DUK_STRIDX_LC_WARN                                            133                            /* 'warn' */
+#define DUK_HEAP_STRING_LC_WARN(heap)                                 DUK_HEAP_GET_STRING((heap),DUK_STRIDX_LC_WARN)
+#define DUK_HTHREAD_STRING_LC_WARN(thr)                               DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_LC_WARN)
+#define DUK_STRIDX_LC_ERROR                                           134                            /* 'error' */
+#define DUK_HEAP_STRING_LC_ERROR(heap)                                DUK_HEAP_GET_STRING((heap),DUK_STRIDX_LC_ERROR)
+#define DUK_HTHREAD_STRING_LC_ERROR(thr)                              DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_LC_ERROR)
+#define DUK_STRIDX_LC_FATAL                                           135                            /* 'fatal' */
+#define DUK_HEAP_STRING_LC_FATAL(heap)                                DUK_HEAP_GET_STRING((heap),DUK_STRIDX_LC_FATAL)
+#define DUK_HTHREAD_STRING_LC_FATAL(thr)                              DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_LC_FATAL)
+#define DUK_STRIDX_LC_N                                               136                            /* 'n' */
+#define DUK_HEAP_STRING_LC_N(heap)                                    DUK_HEAP_GET_STRING((heap),DUK_STRIDX_LC_N)
+#define DUK_HTHREAD_STRING_LC_N(thr)                                  DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_LC_N)
+#define DUK_STRIDX_LC_L                                               137                            /* 'l' */
+#define DUK_HEAP_STRING_LC_L(heap)                                    DUK_HEAP_GET_STRING((heap),DUK_STRIDX_LC_L)
+#define DUK_HTHREAD_STRING_LC_L(thr)                                  DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_LC_L)
+#define DUK_STRIDX_CLOG                                               138                            /* 'clog' */
+#define DUK_HEAP_STRING_CLOG(heap)                                    DUK_HEAP_GET_STRING((heap),DUK_STRIDX_CLOG)
+#define DUK_HTHREAD_STRING_CLOG(thr)                                  DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_CLOG)
+#define DUK_STRIDX_TO_LOG_STRING                                      139                            /* 'toLogString' */
+#define DUK_HEAP_STRING_TO_LOG_STRING(heap)                           DUK_HEAP_GET_STRING((heap),DUK_STRIDX_TO_LOG_STRING)
+#define DUK_HTHREAD_STRING_TO_LOG_STRING(thr)                         DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_TO_LOG_STRING)
+#define DUK_STRIDX_JSON_EXT_UNDEFINED                                 140                            /* '{"_undef":true}' */
+#define DUK_HEAP_STRING_JSON_EXT_UNDEFINED(heap)                      DUK_HEAP_GET_STRING((heap),DUK_STRIDX_JSON_EXT_UNDEFINED)
+#define DUK_HTHREAD_STRING_JSON_EXT_UNDEFINED(thr)                    DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_JSON_EXT_UNDEFINED)
+#define DUK_STRIDX_JSON_EXT_NAN                                       141                            /* '{"_nan":true}' */
+#define DUK_HEAP_STRING_JSON_EXT_NAN(heap)                            DUK_HEAP_GET_STRING((heap),DUK_STRIDX_JSON_EXT_NAN)
+#define DUK_HTHREAD_STRING_JSON_EXT_NAN(thr)                          DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_JSON_EXT_NAN)
+#define DUK_STRIDX_JSON_EXT_POSINF                                    142                            /* '{"_inf":true}' */
+#define DUK_HEAP_STRING_JSON_EXT_POSINF(heap)                         DUK_HEAP_GET_STRING((heap),DUK_STRIDX_JSON_EXT_POSINF)
+#define DUK_HTHREAD_STRING_JSON_EXT_POSINF(thr)                       DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_JSON_EXT_POSINF)
+#define DUK_STRIDX_JSON_EXT_NEGINF                                    143                            /* '{"_ninf":true}' */
+#define DUK_HEAP_STRING_JSON_EXT_NEGINF(heap)                         DUK_HEAP_GET_STRING((heap),DUK_STRIDX_JSON_EXT_NEGINF)
+#define DUK_HTHREAD_STRING_JSON_EXT_NEGINF(thr)                       DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_JSON_EXT_NEGINF)
+#define DUK_STRIDX_JSON_EXT_FUNCTION1                                 144                            /* '{"_func":true}' */
+#define DUK_HEAP_STRING_JSON_EXT_FUNCTION1(heap)                      DUK_HEAP_GET_STRING((heap),DUK_STRIDX_JSON_EXT_FUNCTION1)
+#define DUK_HTHREAD_STRING_JSON_EXT_FUNCTION1(thr)                    DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_JSON_EXT_FUNCTION1)
+#define DUK_STRIDX_JSON_EXT_FUNCTION2                                 145                            /* '{_func:true}' */
+#define DUK_HEAP_STRING_JSON_EXT_FUNCTION2(heap)                      DUK_HEAP_GET_STRING((heap),DUK_STRIDX_JSON_EXT_FUNCTION2)
+#define DUK_HTHREAD_STRING_JSON_EXT_FUNCTION2(thr)                    DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_JSON_EXT_FUNCTION2)
+#define DUK_STRIDX_BREAK                                              146                            /* 'break' */
+#define DUK_HEAP_STRING_BREAK(heap)                                   DUK_HEAP_GET_STRING((heap),DUK_STRIDX_BREAK)
+#define DUK_HTHREAD_STRING_BREAK(thr)                                 DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_BREAK)
+#define DUK_STRIDX_CASE                                               147                            /* 'case' */
+#define DUK_HEAP_STRING_CASE(heap)                                    DUK_HEAP_GET_STRING((heap),DUK_STRIDX_CASE)
+#define DUK_HTHREAD_STRING_CASE(thr)                                  DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_CASE)
+#define DUK_STRIDX_CATCH                                              148                            /* 'catch' */
+#define DUK_HEAP_STRING_CATCH(heap)                                   DUK_HEAP_GET_STRING((heap),DUK_STRIDX_CATCH)
+#define DUK_HTHREAD_STRING_CATCH(thr)                                 DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_CATCH)
+#define DUK_STRIDX_CONTINUE                                           149                            /* 'continue' */
+#define DUK_HEAP_STRING_CONTINUE(heap)                                DUK_HEAP_GET_STRING((heap),DUK_STRIDX_CONTINUE)
+#define DUK_HTHREAD_STRING_CONTINUE(thr)                              DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_CONTINUE)
+#define DUK_STRIDX_DEBUGGER                                           150                            /* 'debugger' */
+#define DUK_HEAP_STRING_DEBUGGER(heap)                                DUK_HEAP_GET_STRING((heap),DUK_STRIDX_DEBUGGER)
+#define DUK_HTHREAD_STRING_DEBUGGER(thr)                              DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_DEBUGGER)
+#define DUK_STRIDX_DEFAULT                                            151                            /* 'default' */
+#define DUK_HEAP_STRING_DEFAULT(heap)                                 DUK_HEAP_GET_STRING((heap),DUK_STRIDX_DEFAULT)
+#define DUK_HTHREAD_STRING_DEFAULT(thr)                               DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_DEFAULT)
+#define DUK_STRIDX_DELETE                                             152                            /* 'delete' */
+#define DUK_HEAP_STRING_DELETE(heap)                                  DUK_HEAP_GET_STRING((heap),DUK_STRIDX_DELETE)
+#define DUK_HTHREAD_STRING_DELETE(thr)                                DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_DELETE)
+#define DUK_STRIDX_DO                                                 153                            /* 'do' */
+#define DUK_HEAP_STRING_DO(heap)                                      DUK_HEAP_GET_STRING((heap),DUK_STRIDX_DO)
+#define DUK_HTHREAD_STRING_DO(thr)                                    DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_DO)
+#define DUK_STRIDX_ELSE                                               154                            /* 'else' */
+#define DUK_HEAP_STRING_ELSE(heap)                                    DUK_HEAP_GET_STRING((heap),DUK_STRIDX_ELSE)
+#define DUK_HTHREAD_STRING_ELSE(thr)                                  DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_ELSE)
+#define DUK_STRIDX_FINALLY                                            155                            /* 'finally' */
+#define DUK_HEAP_STRING_FINALLY(heap)                                 DUK_HEAP_GET_STRING((heap),DUK_STRIDX_FINALLY)
+#define DUK_HTHREAD_STRING_FINALLY(thr)                               DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_FINALLY)
+#define DUK_STRIDX_FOR                                                156                            /* 'for' */
+#define DUK_HEAP_STRING_FOR(heap)                                     DUK_HEAP_GET_STRING((heap),DUK_STRIDX_FOR)
+#define DUK_HTHREAD_STRING_FOR(thr)                                   DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_FOR)
+#define DUK_STRIDX_LC_FUNCTION                                        157                            /* 'function' */
+#define DUK_HEAP_STRING_LC_FUNCTION(heap)                             DUK_HEAP_GET_STRING((heap),DUK_STRIDX_LC_FUNCTION)
+#define DUK_HTHREAD_STRING_LC_FUNCTION(thr)                           DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_LC_FUNCTION)
+#define DUK_STRIDX_IF                                                 158                            /* 'if' */
+#define DUK_HEAP_STRING_IF(heap)                                      DUK_HEAP_GET_STRING((heap),DUK_STRIDX_IF)
+#define DUK_HTHREAD_STRING_IF(thr)                                    DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_IF)
+#define DUK_STRIDX_IN                                                 159                            /* 'in' */
+#define DUK_HEAP_STRING_IN(heap)                                      DUK_HEAP_GET_STRING((heap),DUK_STRIDX_IN)
+#define DUK_HTHREAD_STRING_IN(thr)                                    DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_IN)
+#define DUK_STRIDX_INSTANCEOF                                         160                            /* 'instanceof' */
+#define DUK_HEAP_STRING_INSTANCEOF(heap)                              DUK_HEAP_GET_STRING((heap),DUK_STRIDX_INSTANCEOF)
+#define DUK_HTHREAD_STRING_INSTANCEOF(thr)                            DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_INSTANCEOF)
+#define DUK_STRIDX_NEW                                                161                            /* 'new' */
+#define DUK_HEAP_STRING_NEW(heap)                                     DUK_HEAP_GET_STRING((heap),DUK_STRIDX_NEW)
+#define DUK_HTHREAD_STRING_NEW(thr)                                   DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_NEW)
+#define DUK_STRIDX_RETURN                                             162                            /* 'return' */
+#define DUK_HEAP_STRING_RETURN(heap)                                  DUK_HEAP_GET_STRING((heap),DUK_STRIDX_RETURN)
+#define DUK_HTHREAD_STRING_RETURN(thr)                                DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_RETURN)
+#define DUK_STRIDX_SWITCH                                             163                            /* 'switch' */
+#define DUK_HEAP_STRING_SWITCH(heap)                                  DUK_HEAP_GET_STRING((heap),DUK_STRIDX_SWITCH)
+#define DUK_HTHREAD_STRING_SWITCH(thr)                                DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_SWITCH)
+#define DUK_STRIDX_THIS                                               164                            /* 'this' */
+#define DUK_HEAP_STRING_THIS(heap)                                    DUK_HEAP_GET_STRING((heap),DUK_STRIDX_THIS)
+#define DUK_HTHREAD_STRING_THIS(thr)                                  DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_THIS)
+#define DUK_STRIDX_THROW                                              165                            /* 'throw' */
+#define DUK_HEAP_STRING_THROW(heap)                                   DUK_HEAP_GET_STRING((heap),DUK_STRIDX_THROW)
+#define DUK_HTHREAD_STRING_THROW(thr)                                 DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_THROW)
+#define DUK_STRIDX_TRY                                                166                            /* 'try' */
+#define DUK_HEAP_STRING_TRY(heap)                                     DUK_HEAP_GET_STRING((heap),DUK_STRIDX_TRY)
+#define DUK_HTHREAD_STRING_TRY(thr)                                   DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_TRY)
+#define DUK_STRIDX_TYPEOF                                             167                            /* 'typeof' */
+#define DUK_HEAP_STRING_TYPEOF(heap)                                  DUK_HEAP_GET_STRING((heap),DUK_STRIDX_TYPEOF)
+#define DUK_HTHREAD_STRING_TYPEOF(thr)                                DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_TYPEOF)
+#define DUK_STRIDX_VAR                                                168                            /* 'var' */
+#define DUK_HEAP_STRING_VAR(heap)                                     DUK_HEAP_GET_STRING((heap),DUK_STRIDX_VAR)
+#define DUK_HTHREAD_STRING_VAR(thr)                                   DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_VAR)
+#define DUK_STRIDX_CONST                                              169                            /* 'const' */
+#define DUK_HEAP_STRING_CONST(heap)                                   DUK_HEAP_GET_STRING((heap),DUK_STRIDX_CONST)
+#define DUK_HTHREAD_STRING_CONST(thr)                                 DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_CONST)
+#define DUK_STRIDX_VOID                                               170                            /* 'void' */
+#define DUK_HEAP_STRING_VOID(heap)                                    DUK_HEAP_GET_STRING((heap),DUK_STRIDX_VOID)
+#define DUK_HTHREAD_STRING_VOID(thr)                                  DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_VOID)
+#define DUK_STRIDX_WHILE                                              171                            /* 'while' */
+#define DUK_HEAP_STRING_WHILE(heap)                                   DUK_HEAP_GET_STRING((heap),DUK_STRIDX_WHILE)
+#define DUK_HTHREAD_STRING_WHILE(thr)                                 DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_WHILE)
+#define DUK_STRIDX_WITH                                               172                            /* 'with' */
+#define DUK_HEAP_STRING_WITH(heap)                                    DUK_HEAP_GET_STRING((heap),DUK_STRIDX_WITH)
+#define DUK_HTHREAD_STRING_WITH(thr)                                  DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_WITH)
+#define DUK_STRIDX_CLASS                                              173                            /* 'class' */
+#define DUK_HEAP_STRING_CLASS(heap)                                   DUK_HEAP_GET_STRING((heap),DUK_STRIDX_CLASS)
+#define DUK_HTHREAD_STRING_CLASS(thr)                                 DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_CLASS)
+#define DUK_STRIDX_ENUM                                               174                            /* 'enum' */
+#define DUK_HEAP_STRING_ENUM(heap)                                    DUK_HEAP_GET_STRING((heap),DUK_STRIDX_ENUM)
+#define DUK_HTHREAD_STRING_ENUM(thr)                                  DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_ENUM)
+#define DUK_STRIDX_EXPORT                                             175                            /* 'export' */
+#define DUK_HEAP_STRING_EXPORT(heap)                                  DUK_HEAP_GET_STRING((heap),DUK_STRIDX_EXPORT)
+#define DUK_HTHREAD_STRING_EXPORT(thr)                                DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_EXPORT)
+#define DUK_STRIDX_EXTENDS                                            176                            /* 'extends' */
+#define DUK_HEAP_STRING_EXTENDS(heap)                                 DUK_HEAP_GET_STRING((heap),DUK_STRIDX_EXTENDS)
+#define DUK_HTHREAD_STRING_EXTENDS(thr)                               DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_EXTENDS)
+#define DUK_STRIDX_IMPORT                                             177                            /* 'import' */
+#define DUK_HEAP_STRING_IMPORT(heap)                                  DUK_HEAP_GET_STRING((heap),DUK_STRIDX_IMPORT)
+#define DUK_HTHREAD_STRING_IMPORT(thr)                                DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_IMPORT)
+#define DUK_STRIDX_SUPER                                              178                            /* 'super' */
+#define DUK_HEAP_STRING_SUPER(heap)                                   DUK_HEAP_GET_STRING((heap),DUK_STRIDX_SUPER)
+#define DUK_HTHREAD_STRING_SUPER(thr)                                 DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_SUPER)
+#define DUK_STRIDX_LC_NULL                                            179                            /* 'null' */
+#define DUK_HEAP_STRING_LC_NULL(heap)                                 DUK_HEAP_GET_STRING((heap),DUK_STRIDX_LC_NULL)
+#define DUK_HTHREAD_STRING_LC_NULL(thr)                               DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_LC_NULL)
+#define DUK_STRIDX_TRUE                                               180                            /* 'true' */
+#define DUK_HEAP_STRING_TRUE(heap)                                    DUK_HEAP_GET_STRING((heap),DUK_STRIDX_TRUE)
+#define DUK_HTHREAD_STRING_TRUE(thr)                                  DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_TRUE)
+#define DUK_STRIDX_FALSE                                              181                            /* 'false' */
+#define DUK_HEAP_STRING_FALSE(heap)                                   DUK_HEAP_GET_STRING((heap),DUK_STRIDX_FALSE)
+#define DUK_HTHREAD_STRING_FALSE(thr)                                 DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_FALSE)
+#define DUK_STRIDX_IMPLEMENTS                                         182                            /* 'implements' */
+#define DUK_HEAP_STRING_IMPLEMENTS(heap)                              DUK_HEAP_GET_STRING((heap),DUK_STRIDX_IMPLEMENTS)
+#define DUK_HTHREAD_STRING_IMPLEMENTS(thr)                            DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_IMPLEMENTS)
+#define DUK_STRIDX_INTERFACE                                          183                            /* 'interface' */
+#define DUK_HEAP_STRING_INTERFACE(heap)                               DUK_HEAP_GET_STRING((heap),DUK_STRIDX_INTERFACE)
+#define DUK_HTHREAD_STRING_INTERFACE(thr)                             DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_INTERFACE)
+#define DUK_STRIDX_LET                                                184                            /* 'let' */
+#define DUK_HEAP_STRING_LET(heap)                                     DUK_HEAP_GET_STRING((heap),DUK_STRIDX_LET)
+#define DUK_HTHREAD_STRING_LET(thr)                                   DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_LET)
+#define DUK_STRIDX_PACKAGE                                            185                            /* 'package' */
+#define DUK_HEAP_STRING_PACKAGE(heap)                                 DUK_HEAP_GET_STRING((heap),DUK_STRIDX_PACKAGE)
+#define DUK_HTHREAD_STRING_PACKAGE(thr)                               DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_PACKAGE)
+#define DUK_STRIDX_PRIVATE                                            186                            /* 'private' */
+#define DUK_HEAP_STRING_PRIVATE(heap)                                 DUK_HEAP_GET_STRING((heap),DUK_STRIDX_PRIVATE)
+#define DUK_HTHREAD_STRING_PRIVATE(thr)                               DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_PRIVATE)
+#define DUK_STRIDX_PROTECTED                                          187                            /* 'protected' */
+#define DUK_HEAP_STRING_PROTECTED(heap)                               DUK_HEAP_GET_STRING((heap),DUK_STRIDX_PROTECTED)
+#define DUK_HTHREAD_STRING_PROTECTED(thr)                             DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_PROTECTED)
+#define DUK_STRIDX_PUBLIC                                             188                            /* 'public' */
+#define DUK_HEAP_STRING_PUBLIC(heap)                                  DUK_HEAP_GET_STRING((heap),DUK_STRIDX_PUBLIC)
+#define DUK_HTHREAD_STRING_PUBLIC(thr)                                DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_PUBLIC)
+#define DUK_STRIDX_STATIC                                             189                            /* 'static' */
+#define DUK_HEAP_STRING_STATIC(heap)                                  DUK_HEAP_GET_STRING((heap),DUK_STRIDX_STATIC)
+#define DUK_HTHREAD_STRING_STATIC(thr)                                DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_STATIC)
+#define DUK_STRIDX_YIELD                                              190                            /* 'yield' */
+#define DUK_HEAP_STRING_YIELD(heap)                                   DUK_HEAP_GET_STRING((heap),DUK_STRIDX_YIELD)
+#define DUK_HTHREAD_STRING_YIELD(thr)                                 DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_YIELD)
+
+#define DUK_HEAP_NUM_STRINGS                                          191
+#define DUK_STRIDX_START_RESERVED                                     146
+#define DUK_STRIDX_START_STRICT_RESERVED                              182
+#define DUK_STRIDX_END_RESERVED                                       191                            /* exclusive endpoint */
+
+/* To convert a heap stridx to a token number, subtract
+ * DUK_STRIDX_START_RESERVED and add DUK_TOK_START_RESERVED.
+ */
+#if !defined(DUK_SINGLE_FILE)
+DUK_INTERNAL_DECL const duk_uint8_t duk_strings_data[1049];
+#endif  /* !DUK_SINGLE_FILE */
+#define DUK_STRDATA_MAX_STRLEN                                        17
+#define DUK_STRDATA_DATA_LENGTH                                       1049
+#endif  /* DUK_USE_ROM_STRINGS */
+
+#if defined(DUK_USE_ROM_OBJECTS)
+#error ROM support not enabled, rerun make_dist.py with --rom-support
+#else
+DUK_INTERNAL_DECL duk_ret_t duk_bi_object_constructor(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_function_constructor(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_function_prototype(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_array_constructor(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_string_constructor(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_boolean_constructor(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_number_constructor(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_date_constructor(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_regexp_constructor(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_error_constructor_shared(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_type_error_thrower(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_proxy_constructor(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_thread_constructor(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_buffer_constructor(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_pointer_constructor(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_logger_constructor(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_arraybuffer_constructor(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_dataview_constructor(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_typedarray_constructor(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_nodejs_buffer_constructor(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_global_object_eval(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_global_object_parse_int(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_global_object_parse_float(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_global_object_is_nan(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_global_object_is_finite(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_global_object_decode_uri(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_global_object_decode_uri_component(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_global_object_encode_uri(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_global_object_encode_uri_component(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_global_object_escape(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_global_object_unescape(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_global_object_print_helper(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_global_object_require(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_object_getprototype_shared(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_object_setprototype_shared(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_object_constructor_get_own_property_descriptor(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_object_constructor_keys_shared(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_object_constructor_create(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_object_constructor_define_property(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_object_constructor_define_properties(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_object_constructor_seal_freeze_shared(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_object_constructor_prevent_extensions(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_object_constructor_is_sealed_frozen_shared(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_object_constructor_is_extensible(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_object_prototype_to_string(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_object_prototype_to_locale_string(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_object_prototype_value_of(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_object_prototype_has_own_property(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_object_prototype_is_prototype_of(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_object_prototype_property_is_enumerable(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_function_prototype_to_string(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_function_prototype_apply(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_function_prototype_call(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_function_prototype_bind(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_array_constructor_is_array(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_array_prototype_to_string(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_array_prototype_join_shared(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_array_prototype_concat(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_array_prototype_pop(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_array_prototype_push(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_array_prototype_reverse(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_array_prototype_shift(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_array_prototype_slice(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_array_prototype_sort(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_array_prototype_splice(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_array_prototype_unshift(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_array_prototype_indexof_shared(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_array_prototype_iter_shared(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_array_prototype_reduce_shared(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_string_constructor_from_char_code(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_string_prototype_to_string(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_string_prototype_char_at(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_string_prototype_char_code_at(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_string_prototype_concat(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_string_prototype_indexof_shared(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_string_prototype_locale_compare(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_string_prototype_match(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_string_prototype_replace(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_string_prototype_search(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_string_prototype_slice(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_string_prototype_split(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_string_prototype_substring(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_string_prototype_caseconv_shared(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_string_prototype_trim(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_string_prototype_substr(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_boolean_prototype_tostring_shared(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_number_prototype_to_string(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_number_prototype_to_locale_string(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_number_prototype_value_of(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_number_prototype_to_fixed(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_number_prototype_to_exponential(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_number_prototype_to_precision(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_date_constructor_parse(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_date_constructor_utc(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_date_constructor_now(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_date_prototype_tostring_shared(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_date_prototype_to_json(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_date_prototype_value_of(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_date_prototype_get_shared(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_date_prototype_get_timezone_offset(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_date_prototype_set_time(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_date_prototype_set_shared(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_regexp_prototype_exec(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_regexp_prototype_test(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_regexp_prototype_to_string(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_error_prototype_stack_getter(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_error_prototype_stack_setter(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_error_prototype_filename_getter(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_error_prototype_filename_setter(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_error_prototype_linenumber_getter(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_error_prototype_linenumber_setter(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_error_prototype_to_string(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_math_object_onearg_shared(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_math_object_twoarg_shared(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_math_object_max(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_math_object_min(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_math_object_random(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_json_object_parse(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_json_object_stringify(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_duktape_object_info(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_duktape_object_act(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_duktape_object_gc(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_duktape_object_fin(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_duktape_object_enc(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_duktape_object_dec(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_duktape_object_compact(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_thread_yield(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_thread_resume(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_thread_current(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_buffer_prototype_tostring_shared(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_pointer_prototype_tostring_shared(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_logger_prototype_fmt(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_logger_prototype_raw(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_logger_prototype_log_shared(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_arraybuffer_isview(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_buffer_slice_shared(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_buffer_readfield(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_buffer_writefield(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_typedarray_set(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_nodejs_buffer_concat(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_nodejs_buffer_is_encoding(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_nodejs_buffer_is_buffer(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_nodejs_buffer_byte_length(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_buffer_compare_shared(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_nodejs_buffer_tostring(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_nodejs_buffer_tojson(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_nodejs_buffer_fill(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_nodejs_buffer_copy(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_nodejs_buffer_write(duk_context *ctx);
+#if !defined(DUK_SINGLE_FILE)
+DUK_INTERNAL_DECL const duk_c_function duk_bi_native_functions[149];
+#endif  /* !DUK_SINGLE_FILE */
+#if defined(DUK_USE_BUILTIN_INITJS)
+#if !defined(DUK_SINGLE_FILE)
+DUK_INTERNAL_DECL const duk_uint8_t duk_initjs_data[204];
+#endif  /* !DUK_SINGLE_FILE */
+#define DUK_BUILTIN_INITJS_DATA_LENGTH                                204
+#endif  /* DUK_USE_BUILTIN_INITJS */
+#define DUK_BIDX_GLOBAL                                               0
+#define DUK_BIDX_GLOBAL_ENV                                           1
+#define DUK_BIDX_OBJECT_CONSTRUCTOR                                   2
+#define DUK_BIDX_OBJECT_PROTOTYPE                                     3
+#define DUK_BIDX_FUNCTION_CONSTRUCTOR                                 4
+#define DUK_BIDX_FUNCTION_PROTOTYPE                                   5
+#define DUK_BIDX_ARRAY_CONSTRUCTOR                                    6
+#define DUK_BIDX_ARRAY_PROTOTYPE                                      7
+#define DUK_BIDX_STRING_CONSTRUCTOR                                   8
+#define DUK_BIDX_STRING_PROTOTYPE                                     9
+#define DUK_BIDX_BOOLEAN_CONSTRUCTOR                                  10
+#define DUK_BIDX_BOOLEAN_PROTOTYPE                                    11
+#define DUK_BIDX_NUMBER_CONSTRUCTOR                                   12
+#define DUK_BIDX_NUMBER_PROTOTYPE                                     13
+#define DUK_BIDX_DATE_CONSTRUCTOR                                     14
+#define DUK_BIDX_DATE_PROTOTYPE                                       15
+#define DUK_BIDX_REGEXP_CONSTRUCTOR                                   16
+#define DUK_BIDX_REGEXP_PROTOTYPE                                     17
+#define DUK_BIDX_ERROR_CONSTRUCTOR                                    18
+#define DUK_BIDX_ERROR_PROTOTYPE                                      19
+#define DUK_BIDX_EVAL_ERROR_CONSTRUCTOR                               20
+#define DUK_BIDX_EVAL_ERROR_PROTOTYPE                                 21
+#define DUK_BIDX_RANGE_ERROR_CONSTRUCTOR                              22
+#define DUK_BIDX_RANGE_ERROR_PROTOTYPE                                23
+#define DUK_BIDX_REFERENCE_ERROR_CONSTRUCTOR                          24
+#define DUK_BIDX_REFERENCE_ERROR_PROTOTYPE                            25
+#define DUK_BIDX_SYNTAX_ERROR_CONSTRUCTOR                             26
+#define DUK_BIDX_SYNTAX_ERROR_PROTOTYPE                               27
+#define DUK_BIDX_TYPE_ERROR_CONSTRUCTOR                               28
+#define DUK_BIDX_TYPE_ERROR_PROTOTYPE                                 29
+#define DUK_BIDX_URI_ERROR_CONSTRUCTOR                                30
+#define DUK_BIDX_URI_ERROR_PROTOTYPE                                  31
+#define DUK_BIDX_MATH                                                 32
+#define DUK_BIDX_JSON                                                 33
+#define DUK_BIDX_TYPE_ERROR_THROWER                                   34
+#define DUK_BIDX_PROXY_CONSTRUCTOR                                    35
+#define DUK_BIDX_DUKTAPE                                              36
+#define DUK_BIDX_THREAD_CONSTRUCTOR                                   37
+#define DUK_BIDX_THREAD_PROTOTYPE                                     38
+#define DUK_BIDX_BUFFER_CONSTRUCTOR                                   39
+#define DUK_BIDX_BUFFER_PROTOTYPE                                     40
+#define DUK_BIDX_POINTER_CONSTRUCTOR                                  41
+#define DUK_BIDX_POINTER_PROTOTYPE                                    42
+#define DUK_BIDX_LOGGER_CONSTRUCTOR                                   43
+#define DUK_BIDX_LOGGER_PROTOTYPE                                     44
+#define DUK_BIDX_DOUBLE_ERROR                                         45
+#define DUK_BIDX_ARRAYBUFFER_CONSTRUCTOR                              46
+#define DUK_BIDX_ARRAYBUFFER_PROTOTYPE                                47
+#define DUK_BIDX_DATAVIEW_CONSTRUCTOR                                 48
+#define DUK_BIDX_DATAVIEW_PROTOTYPE                                   49
+#define DUK_BIDX_TYPEDARRAY_PROTOTYPE                                 50
+#define DUK_BIDX_INT8ARRAY_CONSTRUCTOR                                51
+#define DUK_BIDX_INT8ARRAY_PROTOTYPE                                  52
+#define DUK_BIDX_UINT8ARRAY_CONSTRUCTOR                               53
+#define DUK_BIDX_UINT8ARRAY_PROTOTYPE                                 54
+#define DUK_BIDX_UINT8CLAMPEDARRAY_CONSTRUCTOR                        55
+#define DUK_BIDX_UINT8CLAMPEDARRAY_PROTOTYPE                          56
+#define DUK_BIDX_INT16ARRAY_CONSTRUCTOR                               57
+#define DUK_BIDX_INT16ARRAY_PROTOTYPE                                 58
+#define DUK_BIDX_UINT16ARRAY_CONSTRUCTOR                              59
+#define DUK_BIDX_UINT16ARRAY_PROTOTYPE                                60
+#define DUK_BIDX_INT32ARRAY_CONSTRUCTOR                               61
+#define DUK_BIDX_INT32ARRAY_PROTOTYPE                                 62
+#define DUK_BIDX_UINT32ARRAY_CONSTRUCTOR                              63
+#define DUK_BIDX_UINT32ARRAY_PROTOTYPE                                64
+#define DUK_BIDX_FLOAT32ARRAY_CONSTRUCTOR                             65
+#define DUK_BIDX_FLOAT32ARRAY_PROTOTYPE                               66
+#define DUK_BIDX_FLOAT64ARRAY_CONSTRUCTOR                             67
+#define DUK_BIDX_FLOAT64ARRAY_PROTOTYPE                               68
+#define DUK_BIDX_NODEJS_BUFFER_CONSTRUCTOR                            69
+#define DUK_BIDX_NODEJS_BUFFER_PROTOTYPE                              70
+#define DUK_NUM_BUILTINS                                              71
+#define DUK_NUM_BIDX_BUILTINS                                         71
+#define DUK_NUM_ALL_BUILTINS                                          71
+#if defined(DUK_USE_DOUBLE_LE)
+#if !defined(DUK_SINGLE_FILE)
+DUK_INTERNAL_DECL const duk_uint8_t duk_builtins_data[3833];
+#endif  /* !DUK_SINGLE_FILE */
+#define DUK_BUILTINS_DATA_LENGTH                                      3833
+#elif defined(DUK_USE_DOUBLE_BE)
+#if !defined(DUK_SINGLE_FILE)
+DUK_INTERNAL_DECL const duk_uint8_t duk_builtins_data[3833];
+#endif  /* !DUK_SINGLE_FILE */
+#define DUK_BUILTINS_DATA_LENGTH                                      3833
+#elif defined(DUK_USE_DOUBLE_ME)
+#if !defined(DUK_SINGLE_FILE)
+DUK_INTERNAL_DECL const duk_uint8_t duk_builtins_data[3833];
+#endif  /* !DUK_SINGLE_FILE */
+#define DUK_BUILTINS_DATA_LENGTH                                      3833
+#else
+#error invalid endianness defines
+#endif
+#endif  /* DUK_USE_ROM_OBJECTS */
+#endif  /* DUK_BUILTINS_H_INCLUDED */


[47/51] [partial] nifi-minifi-cpp git commit: MINIFI-183 Added civet 1.9.1 sources Added onScheduled hook Added initial two-way TLS-enabled ListenHTTP implementation

Posted by al...@apache.org.
http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/VisualStudio/upload/upload.vcxproj
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/VisualStudio/upload/upload.vcxproj b/thirdparty/civetweb-1.9.1/VisualStudio/upload/upload.vcxproj
new file mode 100644
index 0000000..4aec14c
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/VisualStudio/upload/upload.vcxproj
@@ -0,0 +1,160 @@
+\ufeff<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <ItemGroup Label="ProjectConfigurations">
+    <ProjectConfiguration Include="Debug|Win32">
+      <Configuration>Debug</Configuration>
+      <Platform>Win32</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Debug|x64">
+      <Configuration>Debug</Configuration>
+      <Platform>x64</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Release|Win32">
+      <Configuration>Release</Configuration>
+      <Platform>Win32</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Release|x64">
+      <Configuration>Release</Configuration>
+      <Platform>x64</Platform>
+    </ProjectConfiguration>
+  </ItemGroup>
+  <ItemGroup>
+    <ClCompile Include="..\..\examples\upload\upload.c" />
+    <ClCompile Include="..\..\src\civetweb.c" />
+  </ItemGroup>
+  <ItemGroup>
+    <ClInclude Include="..\..\include\civetweb.h" />
+  </ItemGroup>
+  <PropertyGroup Label="Globals">
+    <ProjectGuid>{882EC43C-2EEE-434B-A711-C845678D29C6}</ProjectGuid>
+    <Keyword>Win32Proj</Keyword>
+    <RootNamespace>upload</RootNamespace>
+    <WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
+  </PropertyGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>true</UseDebugLibraries>
+    <PlatformToolset>v140</PlatformToolset>
+    <CharacterSet>MultiByte</CharacterSet>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>true</UseDebugLibraries>
+    <PlatformToolset>v140</PlatformToolset>
+    <CharacterSet>MultiByte</CharacterSet>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>false</UseDebugLibraries>
+    <PlatformToolset>v140</PlatformToolset>
+    <WholeProgramOptimization>true</WholeProgramOptimization>
+    <CharacterSet>MultiByte</CharacterSet>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>false</UseDebugLibraries>
+    <PlatformToolset>v140</PlatformToolset>
+    <WholeProgramOptimization>true</WholeProgramOptimization>
+    <CharacterSet>MultiByte</CharacterSet>
+  </PropertyGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+  <ImportGroup Label="ExtensionSettings">
+  </ImportGroup>
+  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <PropertyGroup Label="UserMacros" />
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <LinkIncremental>true</LinkIncremental>
+    <OutDir>$(SolutionDir)\$(Configuration)\$(Platform)\</OutDir>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+    <LinkIncremental>true</LinkIncremental>
+    <OutDir>$(SolutionDir)\$(Configuration)\$(Platform)\</OutDir>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <LinkIncremental>false</LinkIncremental>
+    <OutDir>$(SolutionDir)\$(Configuration)\$(Platform)\</OutDir>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+    <LinkIncremental>false</LinkIncremental>
+    <OutDir>$(SolutionDir)\$(Configuration)\$(Platform)\</OutDir>
+  </PropertyGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <ClCompile>
+      <PrecompiledHeader>
+      </PrecompiledHeader>
+      <WarningLevel>Level3</WarningLevel>
+      <Optimization>Disabled</Optimization>
+      <PreprocessorDefinitions>NO_FILES;WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <AdditionalIncludeDirectories>$(ProjectDir)..\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+    </ClCompile>
+    <Link>
+      <SubSystem>Console</SubSystem>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+    <ClCompile>
+      <PrecompiledHeader>
+      </PrecompiledHeader>
+      <WarningLevel>Level3</WarningLevel>
+      <Optimization>Disabled</Optimization>
+      <PreprocessorDefinitions>NO_FILES;WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <AdditionalIncludeDirectories>$(ProjectDir)..\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+    </ClCompile>
+    <Link>
+      <SubSystem>Console</SubSystem>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <ClCompile>
+      <WarningLevel>Level3</WarningLevel>
+      <PrecompiledHeader>
+      </PrecompiledHeader>
+      <Optimization>MaxSpeed</Optimization>
+      <FunctionLevelLinking>true</FunctionLevelLinking>
+      <IntrinsicFunctions>true</IntrinsicFunctions>
+      <PreprocessorDefinitions>NO_FILES;WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <AdditionalIncludeDirectories>$(ProjectDir)..\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+    </ClCompile>
+    <Link>
+      <SubSystem>Console</SubSystem>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>
+      <OptimizeReferences>true</OptimizeReferences>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+    <ClCompile>
+      <WarningLevel>Level3</WarningLevel>
+      <PrecompiledHeader>
+      </PrecompiledHeader>
+      <Optimization>MaxSpeed</Optimization>
+      <FunctionLevelLinking>true</FunctionLevelLinking>
+      <IntrinsicFunctions>true</IntrinsicFunctions>
+      <PreprocessorDefinitions>NO_FILES;WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <AdditionalIncludeDirectories>$(ProjectDir)..\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+    </ClCompile>
+    <Link>
+      <SubSystem>Console</SubSystem>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>
+      <OptimizeReferences>true</OptimizeReferences>
+    </Link>
+  </ItemDefinitionGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+  <ImportGroup Label="ExtensionTargets">
+  </ImportGroup>
+</Project>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/VisualStudio/upload/upload.vcxproj.filters
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/VisualStudio/upload/upload.vcxproj.filters b/thirdparty/civetweb-1.9.1/VisualStudio/upload/upload.vcxproj.filters
new file mode 100644
index 0000000..fb2d247
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/VisualStudio/upload/upload.vcxproj.filters
@@ -0,0 +1,30 @@
+\ufeff<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <ItemGroup>
+    <Filter Include="Source Files">
+      <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A322342A2FF}</UniqueIdentifier>
+      <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
+    </Filter>
+    <Filter Include="Header Files">
+      <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52E765}</UniqueIdentifier>
+      <Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
+    </Filter>
+    <Filter Include="Resource Files">
+      <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AA145}</UniqueIdentifier>
+      <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
+    </Filter>
+  </ItemGroup>
+  <ItemGroup>
+    <ClCompile Include="..\..\src\civetweb.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\examples\upload\upload.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+  </ItemGroup>
+  <ItemGroup>
+    <ClInclude Include="..\..\include\civetweb.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+  </ItemGroup>
+</Project>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/_config.yml
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/_config.yml b/thirdparty/civetweb-1.9.1/_config.yml
new file mode 100644
index 0000000..259a24e
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/_config.yml
@@ -0,0 +1 @@
+theme: jekyll-theme-tactile
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/appveyor.yml
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/appveyor.yml b/thirdparty/civetweb-1.9.1/appveyor.yml
new file mode 100644
index 0000000..ed21fbc
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/appveyor.yml
@@ -0,0 +1,252 @@
+version: '{build}'
+
+
+build:
+# no automatic build in script mode
+
+
+platform:
+  - x86
+  - x64
+
+
+environment:
+  enable_cxx: NO
+  enable_ssl_dynamic_loading: YES
+  enable_lua: NO
+  enable_lua_shared: NO
+  c_standard: auto
+  cxx_standard: auto
+  matrix:
+    - id: 1
+      compiler: msvc-18-seh
+      build_shared: NO
+      no_files: NO
+      enable_ipv6: NO
+      enable_ssl: YES
+      enable_websockets: YES
+      no_cgi: NO
+      no_caching: NO
+      configuration: Release
+    - id: 2
+      compiler: msvc-18-seh
+      build_shared: YES
+      no_files: NO
+      enable_ipv6: NO
+      enable_ssl: YES
+      enable_websockets: YES
+      no_cgi: NO
+      no_caching: NO
+      configuration: Release
+    - id: 3
+      compiler: msvc-18-seh
+      build_shared: YES
+      no_files: YES
+      enable_ipv6: NO
+      enable_ssl: YES
+      enable_websockets: YES
+      no_cgi: NO
+      no_caching: NO
+      configuration: Release
+    - id: 4
+      compiler: gcc-5.1.0-posix
+      build_shared: NO
+      no_files: YES
+      enable_ipv6: NO
+      enable_ssl: NO
+      enable_websockets: NO
+      no_cgi: YES
+      no_caching: YES
+      configuration: Release
+    - id: 5
+      compiler: gcc-5.1.0-posix
+      build_shared: NO
+      no_files: NO
+      enable_ipv6: YES
+      enable_ssl: YES
+      enable_websockets: YES
+      no_cgi: NO
+      no_caching: YES
+      configuration: Release
+    - id: 6
+      compiler: gcc-5.1.0-posix
+      build_shared: NO
+      no_files: NO
+      enable_ipv6: NO
+      enable_ssl: YES
+      enable_websockets: YES
+      no_cgi: NO
+      no_caching: YES
+      configuration: Release
+    - id: 7
+      compiler: gcc-5.1.0-posix
+      build_shared: YES
+      no_files: NO
+      enable_ipv6: NO
+      enable_ssl: YES
+      enable_websockets: YES
+      no_cgi: NO
+      no_caching: YES
+      configuration: Release
+    - id: 8
+      compiler: gcc-5.1.0-posix
+      build_shared: YES
+      no_files: YES
+      enable_ipv6: NO
+      enable_ssl: YES
+      enable_websockets: YES
+      no_cgi: NO
+      no_caching: YES
+      configuration: Release
+    - id: 9
+      compiler: msvc-18-seh
+      build_shared: NO
+      no_files: NO
+      enable_ipv6: YES
+      enable_ssl: YES
+      enable_websockets: YES
+      no_cgi: NO
+      no_caching: NO
+      configuration: Debug
+
+install:
+  # Derive some extra information
+  - set build_type=%configuration%
+  - for /f "tokens=1-3 delims=-" %%a in ("%compiler%") do (@set "compiler_name=%%a")
+  - for /f "tokens=1-3 delims=-" %%a in ("%compiler%") do (@set "compiler_version=%%b")
+  - for /f "tokens=1-3 delims=-" %%a in ("%compiler%") do (@set "compiler_threading=%%c")
+  - if "%platform%"=="x64" (set arch=x86_64)
+  - if "%platform%"=="x86" (set arch=i686)
+  # Download the specific version of MinGW
+  - if "%compiler_name%"=="gcc" (@set "mingw_output_folder=C:\mingw-builds")
+  - if "%compiler_name%"=="gcc" (
+      @for /f %%a in (
+        'call mingw.cmd
+          /version "%compiler_version%"
+          /arch "%arch%"
+          /threading "%compiler_threading%"
+          "%mingw_output_folder%"'
+      ) do @set "compiler_path=%%a"
+    )
+  - if "%compiler_name%"=="gcc" (@set "mingw_log_folder=%mingw_output_folder%\logs")
+  - if exist "%mingw_log_folder%" @for /f %%f in ('dir /b /oD /tc "%mingw_log_folder%"') do @set "mingw_log_file=%mingw_log_folder%\%%f"
+  - if exist "%mingw_log_file%" powershell Push-AppveyorArtifact "%mingw_log_file%" -FileName mingw-download.log
+  # Get OpenSSL
+  #
+  # OpenSSL should already be installed, according to
+  # - http://help.appveyor.com/discussions/questions/1132-openssl-installation-issues
+  # - https://github.com/appveyor/ci/issues/576
+  #
+  - cmd: set PATH=%PATH%;C:\OpenSSL-Win32;C:\OpenSSL-Win64
+  - dir C:\OpenSSL-Win32
+  - dir C:\OpenSSL-Win64
+  - path
+
+
+before_build:
+  # Remove sh.exe from the path otherwise CMake will complain:
+  # "sh.exe was found in your PATH, here: C:/Program Files/Git/usr/bin/sh.exe"
+  # and the MinGW build will not work (the Visual Studio build does not care).
+  # See http://help.appveyor.com/discussions/problems/3193-cmake-building-for-mingw-issue-with-git-shexe
+  # The entire directory containing sh.exe could be removed from the PATH environment:
+  # - set PATH=%PATH:C:\Program Files\Git\usr\bin;=%
+  # However, this will also remove all other programs in this directory from the PATH.
+  # In particular "patch" is still required.
+  # So, just rename sh.exe:
+  - ren "C:\Program Files\Git\usr\bin\sh.exe" _sh.exe
+  # Set up mingw commands
+  - if "%compiler_name%"=="gcc" (set "generator=MinGW Makefiles")
+  - if "%compiler_name%"=="gcc" (set "build=mingw32-make -j4")
+  - if "%compiler_name%"=="gcc" (set "test=mingw32-make test")
+  # MSVC specific commands
+  # Note: The minimum version officially supported for CivetWeb is VS2010. Older ones might work or not.
+  - if "%compiler_version%"=="14" (set "vs_version=8" & set "vs_year=2005")
+  - if "%compiler_version%"=="15" (set "vs_version=9" & set "vs_year=2008")
+  - if "%compiler_version%"=="16" (set "vs_version=10" & set "vs_year=2010")
+  - if "%compiler_version%"=="17" (set "vs_version=11" & set "vs_year=2012")
+  - if "%compiler_version%"=="18" (set "vs_version=12" & set "vs_year=2013")
+  - if "%compiler_version%"=="19" (set "vs_version=14" & set "vs_year=2015")
+  - if "%compiler_name%"=="msvc" (set "generator=Visual Studio %vs_version% %vs_year%")
+  - if "%compiler_name%"=="msvc" (
+      if "%platform%"=="x64" (
+        set "generator=%generator% Win64"
+      )
+    )
+  - if %compiler_version% gtr 9 (set platform=%platform:x86=Win32%)
+  - if "%compiler_name%"=="msvc" (set "msbuild_opts=/clp:OnlyErrors;OnlyWarnings /nologo /m /v:m")
+  - if "%compiler_name%"=="msvc" (set "build=msbuild %msbuild_opts% /p:Configuration=%configuration% /p:Platform=%platform% civetweb.sln")
+  - if "%compiler_name%"=="msvc" (set "test=msbuild %msbuild_opts% RUN_TESTS.vcxproj")
+  # Add the compiler path if needed
+  - if not "%compiler_path%"=="" (set "PATH=%PATH%;%compiler_path%")
+  # git bash conflicts with MinGW makefiles
+  - if "%generator%"=="MinGW Makefiles" (set "PATH=%PATH:C:\Program Files (x86)\Git\bin=%")
+  # Useful locations
+  - set "source_path=%cd%"
+  - set "output_path=%source_path%\output"
+  - set "build_path=%output_path%\build"
+  - set "install_path=%output_path%\install"
+  - set "third_party_dir=C:\third-party"
+  # Check some settings of the build server
+  - ver
+  - cd
+  - dir
+  - ipconfig /all
+  # Generate the build scripts with CMake
+  - mkdir "%build_path%"
+  - cd "%build_path%"
+  - cmake --version
+  - appveyor AddMessage -Category Information "Generating '%generator%'"
+  - cmake
+    -G "%generator%"
+    -DCMAKE_BUILD_TYPE=%build_type%
+    -DBUILD_SHARED_LIBS=%build_shared%
+    -DCIVETWEB_SERVE_NO_FILES=%no_files%
+    "-DCIVETWEB_THIRD_PARTY_DIR=%third_party_dir:\=\\%"
+    -DCIVETWEB_ENABLE_THIRD_PARTY_OUTPUT=YES
+    -DCIVETWEB_ENABLE_SSL=%enable_ssl%
+    -DCIVETWEB_DISABLE_CGI=%no_cgi%
+    -DCIVETWEB_ENABLE_SSL_DYNAMIC_LOADING=%enable_ssl_dynamic_loading%
+    -DCIVETWEB_ENABLE_WEBSOCKETS=%enable_websockets%
+    -DCIVETWEB_ENABLE_CXX=%enable_cxx%
+    -DCIVETWEB_ENABLE_LUA=%enable_lua%
+    -DCIVETWEB_ENABLE_LUA_SHARED=%enable_lua_shared%
+    -DCIVETWEB_DISABLE_CACHING=%no_caching%
+    -DCIVETWEB_C_STANDARD=%c_standard%
+    -DCIVETWEB_CXX_STANDARD=%cxx_standard%
+    "%source_path%"
+  - powershell Push-AppveyorArtifact CMakeCache.txt
+  - cd "%source_path%"
+
+build_script:
+  - cd
+  - cd "%build_path%"
+  - appveyor AddMessage -Category Information "Build command '%build%'"
+  - cmd /c "%build%"
+  - cd "%source_path%"
+
+test_script:
+  - cd "%build_path%"
+  - appveyor AddMessage -Category Information "Test command '%build%'"
+  - set CTEST_OUTPUT_ON_FAILURE=1
+  - cmd /c "%test%"
+  - cd "%source_path%"
+
+after_test:
+  - cd
+  - dir
+  - md dist
+  - if "%build_type%"=="Release" (cmake "-DCMAKE_INSTALL_PREFIX=%install_path%" -P "%build_path%/cmake_install.cmake")
+  - if "%build_type%"=="Release" (copy "%build_path%" dist\)
+  - dir dist\
+
+matrix:
+  fast_finish: false
+
+cache:
+  - C:\mingw-builds -> mingw.cmd
+  - C:\third-party -> **\CMakeLists.txt
+  - C:\ssl
+
+artifacts:
+  - path: dist\*
+

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/build.cmd
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/build.cmd b/thirdparty/civetweb-1.9.1/build.cmd
new file mode 100644
index 0000000..8ccf0e4
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/build.cmd
@@ -0,0 +1,866 @@
+:: Make sure the extensions are enabled
+@verify other 2>nul
+@setlocal EnableDelayedExpansion
+@if errorlevel 1 (
+  call :print_usage "Failed to enable extensions"
+  exit /b 1
+)
+
+::Change the code page to unicode
+@chcp 65001 1>nul 2>nul
+@if errorlevel 1 (
+  call :print_usage "Failed to change the code page to unicode"
+  exit /b 1
+)
+
+:: Set up some global variables
+@set project=civetweb
+@set "script_name=%~nx0"
+@set "script_folder=%~dp0"
+@set "script_folder=%script_folder:~0,-1%"
+@set "output_path=%script_folder%\output"
+@set "build_path=%output_path%\build"
+@set "install_path=%output_path%\install"
+@set build_shared=OFF
+@set build_type=Release
+@set dependency_path=%TEMP%\%project%-build-dependencies
+
+:: Check the command line parameters
+@set logging_level=1
+@set "options=%* "
+@if not "!options!"=="!options:/? =!" set usage="Convenience script to build %project% with CMake"
+@for %%a in (%options%) do @(
+  @set arg=%%~a
+  @set arg=!arg: =!
+  @set one=!arg:~0,1!
+  @set two=!arg:~0,2!
+  @if /i [!arg!] == [/q] set quiet=true
+  @if /i [!two!] == [/v] call :verbosity "!arg!"
+  @if /i [!arg!] == [/s] set build_shared=ON
+  @if /i [!arg!] == [/d] set build_type=Debug
+  @if /i not [!one!] == [/] (
+    if not defined generator (
+      set generator=!arg!
+    ) else (
+      set usage="Too many generators: !method! !arg!" ^
+                "There should only be one generator parameter"
+    )
+  )
+)
+@if defined quiet (
+  set logging_level=0
+)
+@if not defined generator (
+  set generator=MSVC
+)
+@if /i not [%generator%] == [MinGW] (
+  if /i not [%generator%] == [MSVC] (
+    call :print_usage "Invalid argument: %generator%"
+    exit /b 1
+  )
+)
+
+:: Set up the logging
+@set log_folder=%output_path%\logs
+@call :iso8601 timestamp
+@set log_path=%log_folder%\%timestamp%.log
+@set log_keep=10
+
+:: Only keep a certain amount of logs
+@set /a "log_keep=log_keep-1"
+@if not exist %log_folder% @mkdir %log_folder%
+@for /f "skip=%log_keep%" %%f in ('dir /b /o-D /tc %log_folder%') do @(
+  call :log 4 "Removing old log file %log_folder%\%%f"
+  del %log_folder%\%%f
+)
+
+:: Set up some more global variables
+@call :architecture arch
+@call :windows_version win_ver win_ver_major win_ver_minor win_ver_rev
+@call :script_source script_source
+@if [%script_source%] == [explorer] (
+  set /a "logging_level=logging_level+1"
+)
+
+:: Print the usage or start the script
+@set exit_code=0
+@if defined usage (
+  call :print_usage %usage%
+) else (
+  call :main
+  @if errorlevel 1 (
+    @call :log 0 "Failed to build the %project% project"
+    @set exit_code=1
+  )
+)
+
+:: Tell the user where the built files are
+@call :log 5
+@call :log 0 "The built files are available in %install_path%"
+
+:: Stop the script if the user double clicked
+@if [%script_source%] == [explorer] (
+  pause
+)
+
+@exit /b %exit_code%
+@endlocal
+@goto :eof
+
+:: -------------------------- Functions start here ----------------------------
+
+:main - Main function that performs the build
+@setlocal
+@call :log 6
+@call :log 2 "Welcome to the %project% build script"
+@call :log 6 "------------------------------------"
+@call :log 6
+@call :log 2 "This script builds the project using CMake"
+@call :log 6
+@call :log 2 "Generating %generator%..."
+@call :log 6
+@set methods=dependencies ^
+             generate ^
+             build ^
+             install
+@for %%m in (%methods%) do @(
+  call :log 3 "Excuting the '%%m' method"
+  call :log 8
+  call :%%~m
+  if errorlevel 1 (
+    call :log 0 "Failed to complete the '%%~m' dependency routine"
+    call :log 0 "View the log at %log_path%"
+    exit /b 1
+  )
+)
+@call :log 6 "------------------------------------"
+@call :log 2 "Build complete"
+@call :log 6
+@endlocal
+@goto :eof
+
+:print_usage - Prints the usage of the script
+:: %* - message to print, each argument on it's own line
+@setlocal
+@for %%a in (%*) do @echo.%%~a
+@echo.
+@echo.build [/?][/v[v...]^|/q][MinGW^|MSVC]
+@echo.
+@echo.  [MinGW^|(MSVC)]
+@echo.              Builds the library with one of the compilers
+@echo.  /s          Builds shared libraries
+@echo.  /d          Builds a debug variant of the project
+@echo.  /v          Sets the output to be more verbose
+@echo.  /v[v...]    Extra verbosity, /vv, /vvv, etc
+@echo.  /q          Quiets the output
+@echo.  /?          Shows this usage message
+@echo.
+@endlocal
+@goto :eof
+
+:dependencies - Installs any prerequisites for the build
+@setlocal EnableDelayedExpansion
+@if errorlevel 1 (
+  call :log 0 "Failed to enable extensions"
+  exit /b 1
+)
+@call :log 5
+@call :log 0 "Installing dependencies for %generator%"
+@if /i [%generator%] == [MinGW] (
+  call :mingw compiler_path
+  @if errorlevel 1 (
+    @call :log 5
+    @call :log 0 "Failed to find MinGW"
+    @exit /b 1
+  )
+  set "PATH=!compiler_path!;%PATH%"
+  @call :find_in_path gcc_executable gcc.exe
+  @if errorlevel 1 (
+    @call :log 5
+    @call :log 0 "Failed to find gcc.exe"
+    @exit /b 1
+  )
+)
+@if [%reboot_required%] equ [1] call :reboot
+@endlocal & set "PATH=%PATH%"
+@goto :eof
+
+:generate - Uses CMake to generate the build files
+@setlocal EnableDelayedExpansion
+@if errorlevel 1 (
+  call :log 0 "Failed to enable extensions"
+  exit /b 1
+)
+@call :log 5
+@call :log 0 "Generating CMake files for %generator%"
+@call :cmake cmake_executable
+@if errorlevel 1 (
+  @call :log 5
+  @call :log 0 "Need CMake to create the build files"
+  @exit /b 1
+)
+@if /i [%generator%] == [MinGW] @(
+  @set "generator_var=-G "MinGW Makefiles^""
+)
+@if /i [%generator%] == [MSVC] @(
+  rem We could figure out the correct MSVS generator here
+)
+@call :iso8601 iso8601
+@set output=%temp%\cmake-%iso8601%.log
+@if not exist %build_path% mkdir %build_path%
+@cd %build_path%
+@"%cmake_executable%" ^
+  !generator_var! ^
+  -DCMAKE_BUILD_TYPE=!build_type! ^
+  -DBUILD_SHARED_LIBS=!build_shared! ^
+  "%script_folder%" > "%output%"
+@if errorlevel 1 (
+  @call :log 5
+  @call :log 0 "Failed to generate build files with CMake"
+  @call :log_append "%output%"
+  @cd %script_folder%
+  @exit /b 1
+)
+@cd %script_folder%
+@endlocal
+@goto :eof
+
+:build - Builds the library
+@setlocal EnableDelayedExpansion
+@if errorlevel 1 (
+  call :log 0 "Failed to enable extensions"
+  exit /b 1
+)
+@call :log 5
+@call :log 0 "Building %project% with %generator%"
+@if /i [%generator%] == [MinGW] @(
+  @call :find_in_path mingw32_make_executable mingw32-make.exe
+  @if errorlevel 1 (
+    @call :log 5
+    @call :log 0 "Failed to find mingw32-make"
+    @exit /b 1
+  )
+  @set "build_command=^"!mingw32_make_executable!^" all test"
+)
+@if /i [%generator%] == [MSVC] @(
+  @call :msbuild msbuild_executable
+  @if errorlevel 1 (
+    @call :log 5
+    @call :log 0 "Failed to find MSBuild"
+    @exit /b 1
+  )
+  @set "build_command=^"!msbuild_executable!^" /m:4 /p:Configuration=%build_type% %project%.sln"
+)
+@if not defined build_command (
+  @call :log 5
+  @call :log 0 "No build command for %generator%"
+  @exit /b 1
+)
+@cd %build_path%
+@call :iso8601 iso8601
+@set output=%temp%\build-%iso8601%.log
+@call :log 7
+@call :log 2 "Build command: %build_command:"=%"
+@%build_command% > "%output%"
+@if errorlevel 1 (
+  @call :log_append "%output%"
+  @call :log 5
+  @call :log 0 "Failed to complete the build"
+  @exit /b 1
+)
+@call :log_append "%output%"
+@cd %script_folder%
+@endlocal
+@goto :eof
+
+:install - Installs the built files
+@setlocal
+@call :log 5
+@call :log 0 "Installing built files"
+@call :cmake cmake_executable
+@if errorlevel 1 (
+  @call :log 5
+  @call :log 0 "Need CMake to install the built files"
+  @exit /b 1
+)
+@call :iso8601 iso8601
+@set output=%temp%\install-%iso8601%.log
+@"%cmake_executable%" ^
+  "-DCMAKE_INSTALL_PREFIX=%install_path%" ^
+  -P "%build_path%/cmake_install.cmake" ^
+  > "%output%"
+@if errorlevel 1 (
+  @call :log_append "%output%"
+  @call :log 5
+  @call :log 0 "Failed to install the files"
+  @exit /b 1
+)
+@call :log_append "%output%"
+@endlocal
+@goto :eof
+
+:script_source - Determines if the script was ran from the cli or explorer
+:: %1 - The return variable [cli|explorer]
+@verify other 2>nul
+@setlocal EnableDelayedExpansion
+@if errorlevel 1 (
+  call :log 0 "Failed to enable extensions"
+  exit /b 1
+)
+@call :log 3 "Attempting to detect the script source"
+@echo "The invocation command was: '%cmdcmdline%'" >> %log_path%
+@for /f "tokens=1-3,*" %%a in ("%cmdcmdline%") do @(
+  set cmd=%%~a
+  set arg1=%%~b
+  set arg2=%%~c
+  set rest=%%~d
+)
+@set quote="
+@if "!arg2:~0,1!" equ "!quote!" (
+  if "!arg2:~-1!" neq "!quote!" (
+    set "arg2=!arg2:~1!"
+  )
+)
+@call :log 4 "cmd  = %cmd%"
+@call :log 4 "arg1 = %arg1%"
+@call :log 4 "arg2 = %arg2%"
+@call :log 4 "rest = %rest%"
+@call :log 4 "src  = %~f0"
+@if /i "%arg2%" == "call" (
+  set script_source=cli
+) else (
+  @if /i "%arg1%" == "/c" (
+    set script_source=explorer
+  ) else (
+    set script_source=cli
+  )
+)
+@call :log 3 "The script was invoked from %script_source%"
+@endlocal & set "%~1=%script_source%"
+@goto :eof
+
+:architecture - Finds the system architecture
+:: %1 - The return variable [x86|x86_64]
+@setlocal
+@call :log 3 "Determining the processor architecture"
+@set "key=HKLM\System\CurrentControlSet\Control\Session Manager\Environment"
+@set "var=PROCESSOR_ARCHITECTURE"
+@for /f "skip=2 tokens=2,*" %%a in ('reg query "%key%" /v "%var%"') do @set "arch=%%b"
+@if "%arch%" == "AMD64" set arch=x86_64
+@call :log 4 "arch = %arch%"
+@endlocal & set "%~1=%arch%"
+@goto :eof
+
+:md5 - Gets the MD5 checksum for a file
+:: %1 - The hash
+:: %2 - The file path
+@setlocal
+@set var=%~1
+@set file_path=%~2
+@if [%var%] == [] exit /b 1
+@if "%file_path%" == "" exit /b 1
+@if not exist "%file_path%" exit /b 1
+@for /f "skip=3 tokens=1,*" %%a in ('powershell Get-FileHash -Algorithm MD5 "'%file_path%'"') do @set hash=%%b
+@if not defined hash (
+  call :log 6
+  call :log 0 "Failed to get MD5 hash for %file_path%"
+  exit /b 1
+)
+@endlocal & set "%var%=%hash: =%"
+@goto :eof
+
+:windows_version - Checks the windows version
+:: %1 - The windows version
+:: %2 - The major version number return variable
+:: %3 - The minor version number return variable
+:: %4 - The revision version number return variable
+@setlocal
+@call :log 3 "Retrieving the Windows version"
+@for /f "tokens=2 delims=[]" %%x in ('ver') do @set win_ver=%%x
+@set win_ver=%win_ver:Version =%
+@set win_ver_major=%win_ver:~0,1%
+@set win_ver_minor=%win_ver:~2,1%
+@set win_ver_rev=%win_ver:~4%
+@call :log 4 "win_ver = %win_ver%"
+@endlocal & set "%~1=%win_ver%" ^
+          & set "%~2=%win_ver_major%" ^
+          & set "%~3=%win_ver_minor%" ^
+          & set "%~4=%win_ver_rev%"
+@goto :eof
+
+:find_in_path - Finds a program of file in the PATH
+@setlocal
+@set var=%~1
+@set file=%~2
+@if [%var%] == [] exit /b 1
+@if [%file%] == [] exit /b 1
+@call :log 3 "Searching PATH for %file%"
+@for %%x in ("%file%") do @set "file_path=%%~f$PATH:x"
+@if not defined file_path exit /b 1
+@endlocal & set "%var%=%file_path%"
+@goto :eof
+
+:administrator_check - Checks for administrator priviledges
+@setlocal
+@call :log 2 "Checking for administrator priviledges"
+@set "key=HKLM\Software\VCA\Tool Chain\Admin Check"
+@reg add "%key%" /v Elevated /t REG_DWORD /d 1 /f > nul 2>&1
+@if errorlevel 1 exit /b 1
+@reg delete "%key%" /va /f > nul 2>&1
+@endlocal
+@goto :eof
+
+:log_append - Appends another file into the current logging file
+:: %1 - the file_path to the file to concatenate
+@setlocal
+@set "file_path=%~1"
+@if [%file_path%] == [] exit /b 1
+@call :log 3 "Appending to log: %file_path%"
+@call :iso8601 iso8601
+@set "temp_log=%temp%\append-%iso8601%.log"
+@call :log 4 "Using temp file %temp_log%"
+@type "%log_path%" "%file_path%" > "%temp_log%" 2>nul
+@move /y "%temp_log%" "%log_path%" 1>nul
+@del "%file_path%" 2>nul
+@del "%temp_log%" 2>nul
+@endlocal
+@goto :eof
+
+:iso8601 - Returns the current time in ISO8601 format
+:: %1 - the return variable
+:: %2 - format [extended|basic*]
+:: iso8601 - contains the resulting timestamp
+@setlocal
+@wmic Alias /? >NUL 2>&1 || @exit /b 1
+@set "var=%~1"
+@if "%var%" == "" @exit /b 1
+@set "format=%~2"
+@if "%format%" == "" set format=basic
+@for /F "skip=1 tokens=1-6" %%g IN ('wmic Path Win32_UTCTime Get Day^,Hour^,Minute^,Month^,Second^,Year /Format:table') do @(
+  @if "%%~l"=="" goto :iso8601_done
+  @set "yyyy=%%l"
+  @set "mm=00%%j"
+  @set "dd=00%%g"
+  @set "hour=00%%h"
+  @set "minute=00%%i"
+  @set "seconds=00%%k"
+)
+:iso8601_done
+@set mm=%mm:~-2%
+@set dd=%dd:~-2%
+@set hour=%hour:~-2%
+@set minute=%minute:~-2%
+@set seconds=%seconds:~-2%
+@if /i [%format%] == [extended] (
+  set iso8601=%yyyy%-%mm%-%dd%T%hour%:%minute%:%seconds%Z
+) else (
+  if /i [%format%] == [basic] (
+    set iso8601=%yyyy%%mm%%dd%T%hour%%minute%%seconds%Z
+  ) else (
+    @exit /b 1
+  )
+)
+@set iso8601=%iso8601: =0%
+@endlocal & set %var%=%iso8601%
+@goto :eof
+
+:verbosity - Processes the verbosity parameter '/v[v...]
+:: %1 - verbosity given on the command line
+:: logging_level - set to the number of v's
+@setlocal
+@set logging_level=0
+@set verbosity=%~1
+:verbosity_loop
+@set verbosity=%verbosity:~1%
+@if not [%verbosity%] == [] @(
+  set /a "logging_level=logging_level+1"
+  goto verbosity_loop
+)
+@endlocal & set logging_level=%logging_level%
+@goto :eof
+
+:log - Logs a message, depending on verbosity
+:: %1 - level
+::       [0-4] for CLI logging
+::       [5-9] for GUI logging
+:: %2 - message to print
+@setlocal
+@set "level=%~1"
+@set "msg=%~2"
+@if "%log_folder%" == "" (
+  echo Logging was used to early in the script, log_folder isn't set yet
+  goto :eof
+)
+@if "%log_path%" == "" (
+  echo Logging was used to early in the script, log_path isn't set yet
+  goto :eof
+)
+@if not exist "%log_folder%" mkdir "%log_folder%"
+@if not exist "%log_path%" echo. 1>nul 2>"%log_path%"
+@echo.%msg% >> "%log_path%"
+@if %level% geq 5 (
+  @if [%script_source%] == [explorer] (
+    set /a "level=level-5"
+  ) else (
+    @goto :eof
+  )
+)
+@if "%logging_level%" == "" (
+  echo Logging was used to early in the script, logging_level isn't set yet
+  goto :eof
+)
+@if %logging_level% geq %level% echo.%msg% 1>&2
+@endlocal
+@goto :eof
+
+
+:start_browser - Opens the default browser to a URL
+:: %1 - the url to open
+@setlocal
+@set url=%~1
+@call :log 4 "Opening default browser: %url%"
+@start %url%
+@endlocal
+@goto :eof
+
+:find_cmake - Finds cmake on the command line or in the registry
+:: %1 - the cmake file path
+@setlocal
+@set var=%~1
+@if [%var%] == [] exit /b 1
+@call :log 6
+@call :log 6 "Finding CMake"
+@call :log 6 "--------------"
+@call :find_in_path cmake_executable cmake.exe
+@if not errorlevel 1 goto found_cmake
+@for /l %%i in (5,-1,0) do @(
+@for /l %%j in (9,-1,0) do @(
+@for /l %%k in (9,-1,0) do @(
+@for %%l in (HKCU HKLM) do @(
+@for %%m in (SOFTWARE SOFTWARE\Wow6432Node) do @(
+  @reg query "%%l\%%m\Kitware\CMake %%i.%%j.%%k" /ve > nul 2>nul
+  @if not errorlevel 1 (
+    @for /f "skip=2 tokens=2,*" %%a in ('reg query "%%l\%%m\Kitware\CMake %%i.%%j.%%k" /ve') do @(
+      @if exist "%%b\bin\cmake.exe" (
+        @set "cmake_executable=%%b\bin\cmake.exe"
+        goto found_cmake
+      )
+    )
+  )
+)))))
+@call :log 5
+@call :log 0 "Failed to find cmake"
+@exit /b 1
+:found_cmake
+@endlocal & set "%var%=%cmake_executable%"
+@goto :eof
+
+:cmake - Finds cmake and installs it if necessary
+:: %1 - the cmake file path
+@setlocal
+@set var=%~1
+@if [%var%] == [] exit /b 1
+@call :log 6
+@call :log 6 "Checking for CMake"
+@call :log 6 "------------------"
+@call :find_cmake cmake_executable cmake.exe
+@if not errorlevel 1 goto got_cmake
+@set checksum=C00267A3D3D9619A7A2E8FA4F46D7698
+@set version=3.2.2
+@call :install_nsis cmake http://www.cmake.org/files/v%version:~0,3%/cmake-%version%-win32-x86.exe %checksum%
+@if errorlevel 1 (
+  call :log 5
+  call :log 0 "Failed to install cmake"
+  @exit /b 1
+)
+@call :find_cmake cmake_executable cmake.exe
+@if not errorlevel 1 goto got_cmake
+@call :log 5
+@call :log 0 "Failed to check for cmake"
+@exit /b 1
+:got_cmake
+@endlocal & set "%var%=%cmake_executable%"
+@goto :eof
+
+:mingw - Finds MinGW, installing it if needed
+:: %1 - the compiler path that should be added to PATH
+@setlocal EnableDelayedExpansion
+@if errorlevel 1 (
+  @call :log 5
+  @call :log 0 "Failed to enable extensions"
+  @exit /b 1
+)
+@set var=%~1
+@if [%var%] == [] exit /b 1
+@call :log 6
+@call :log 6 "Checking for MinGW"
+@call :log 6 "------------------"
+@call :find_in_path gcc_executable gcc.exe
+@if not errorlevel 1 (
+  @for %%a in ("%gcc_executable%") do @set "compiler_path=%%~dpa"
+  goto got_mingw
+)
+@call :log 7
+@call :log 2 "Downloading MinGW"
+@if %logging_level% leq 1 set "logging=/q"
+@if %logging_level% gtr 1 set "logging=/v"
+@set output_path=
+@for /f %%a in ('call
+    "%script_folder%\mingw.cmd"
+    %logging%
+    /arch "%arch%"
+    "%dependency_path%"'
+) do @set "compiler_path=%%a\"
+@if not defined compiler_path (
+  @call :log_append "%output%"
+  @call :log 5
+  @call :log 0 "Failed to download MinGW"
+  @exit /b 1
+)
+:got_mingw
+@call :log 5
+@call :log 0 "Found MinGW: %compiler_path%gcc.exe"
+@endlocal & set "%var%=%compiler_path%"
+@goto :eof
+
+:msbuild - Finds MSBuild
+:: %1 - the path to MSBuild executable
+@setlocal
+@set var=%~1
+@if [%var%] == [] exit /b 1
+@call :find_in_path msbuild_executable msbuild.exe
+@if not errorlevel 1 goto got_msbuild
+@for /l %%i in (20,-1,4) do @(
+@for /l %%j in (9,-1,0) do @(
+@for %%k in (HKCU HKLM) do @(
+@for %%l in (SOFTWARE SOFTWARE\Wow6432Node) do @(
+  @reg query "%%k\%%l\Microsoft\MSBuild\%%i.%%j" /v MSBuildOverrideTasksPath > nul 2>nul
+  @if not errorlevel 1 (
+    @for /f "skip=2 tokens=2,*" %%a in ('reg query "%%k\%%l\Microsoft\MSBuild\%%i.%%j" /v MSBuildOverrideTasksPath') do @(
+      @if exist "%%bmsbuild.exe" (
+        @set "msbuild_executable=%%bmsbuild.exe"
+        goto got_msbuild
+      )
+    )
+  )
+))))
+@call :log 5
+@call :log 0 "Failed to check for MSBuild"
+@exit /b 1
+:got_msbuild
+@endlocal & set "%var%=%msbuild_executable%"
+@goto :eof
+
+:download - Downloads a file from the internet
+:: %1 - the url of the file to download
+:: %2 - the file to download to
+:: %3 - the MD5 checksum of the file (optional)
+@setlocal EnableDelayedExpansion
+@if errorlevel 1 (
+  call :print_usage "Failed to enable extensions"
+  exit /b 1
+)
+@set url=%~1
+@set file_path=%~2
+@set checksum=%~3
+@for %%a in (%file_path%) do @set dir_path=%%~dpa
+@for %%a in (%file_path%) do @set file_name=%%~nxa
+@if [%url%] == [] exit /b 1
+@if [%file_path%] == [] exit /b 1
+@if [%dir_path%] == [] exit /b 1
+@if [%file_name%] == [] exit /b 1
+@if not exist "%dir_path%" mkdir "%dir_path%"
+@call :log 1 "Downloading %url%"
+@call :iso8601 iso8601
+@set temp_path=%temp%\download-%iso8601%-%file_name%
+@call :log 3 "Using temp file %temp_path%"
+@powershell Invoke-WebRequest "%url%" -OutFile %temp_path%
+@if errorlevel 1 (
+  call :log 0 "Failed to download %url%"
+  exit /b 1
+)
+@if [%checksum%] neq [] (
+  @call :log 4 "Checking %checksum% against %temp_path%"
+  @call :md5 hash "%temp_path%"
+  if "!hash!" neq "%checksum%" (
+    call :log 0 "Failed to match checksum: %temp_path%"
+    call :log 0 "Hash    : !hash!"
+    call :log 0 "Checksum: %checksum%"
+    exit /b 1
+  ) else (
+    call :log 3 "Checksum matched: %temp_path%"
+    call :log 3 "Hash    : !hash!"
+    call :log 3 "Checksum: %checksum%"
+  )
+)
+@call :log 4 "Renaming %temp_path% to %file_path%"
+@move /y "%temp_path%" "%file_path%" 1>nul
+@endlocal
+@goto :eof
+
+:install_msi - Installs a dependency from an Microsoft Installer package (.msi)
+:: %1 - [string] name of the project to install
+:: %2 - The location of the .msi, a url must start with 'http://' or file_path
+:: %3 - The checksum of the msi (optional)
+@setlocal
+@set name=%~1
+@set file_path=%~2
+@set checksum=%~3
+@set msi=%~nx2
+@set msi_path=%dependency_path%\%msi%
+@if [%name%] == [] exit /b 1
+@if [%file_path%] == [] exit /b 1
+@if [%msi%] == [] exit /b 1
+@if [%msi_path%] == [] exit /b 1
+@for %%x in (msiexec.exe) do @set "msiexec_path=%%~f$PATH:x"
+@if "msiexec_path" == "" (
+  call :log 0 "Failed to find the Microsoft package installer (msiexec.exe)"
+  call :log 6
+  call :log 0 "Please install it from the Microsoft Download center"
+  call :log 6
+  choice /C YN /T 60 /D N /M "Would you like to go there now?"
+  if !errorlevel! equ 1 call :start_browser ^
+    "http://search.microsoft.com/DownloadResults.aspx?q=Windows+Installer"
+  exit /b 1
+)
+@call :log 6
+@call :log 1 "Installing the '%name%' dependency"
+@call :log 6 "-------------------------------------"
+@call :administrator_check
+@if errorlevel 1 (
+  call :log 0 "You must run %~nx0 in elevated mode to install '%name%'"
+  call :log 5 "Right-Click and select 'Run as Administrator'
+  call :log 0 "Install the dependency manually by running %file_path%"
+  @exit /b 740
+)
+@if [%file_path:~0,4%] == [http] (
+  if not exist "%msi_path%" (
+    call :download "%file_path%" "%msi_path%" %checksum%
+    if errorlevel 1 (
+      call :log 0 "Failed to download the %name% dependency"
+      exit /b 1
+    )
+  )
+) else (
+  call :log 2 "Copying MSI %file_path% to %msi_path%"
+  call :log 7
+  if not exist "%msi_path%" (
+    xcopy /q /y /z "%file_path%" "%msi_path%" 1>nul
+    if errorlevel 1 (
+      call :log 0 "Failed to copy the Microsoft Installer"
+      exit /b 1
+    )
+  )
+)
+@call :log 1 "Running the %msi%"
+@call :log 6
+@set msi_log=%temp%\msiexec-%timestamp%.log
+@call :log 3 "Logging to: %msi_log%"
+@msiexec /i "%msi_path%" /passive /log "%msi_log%" ALLUSERS=1
+@set msi_errorlevel=%errorlevel%
+@call :log_append "%msi_log%"
+@if %msi_errorlevel% equ 0 goto install_msi_success
+@if %msi_errorlevel% equ 3010 goto install_msi_success_reboot
+@if %msi_errorlevel% equ 1641 goto install_msi_success_reboot
+@if %msi_errorlevel% equ 3015 goto install_msi_in_progress_reboot
+@if %msi_errorlevel% equ 1615 goto install_msi_in_progress_reboot
+@call :log 0 "Microsoft Installer failed: %msi_errorlevel%"
+@call :log 0 "Install the dependency manually by running %msi_path%"
+@exit /b 1
+:install_msi_in_progress_reboot
+@call :log 0 "The installation requires a reboot to continue"
+@call :log 5
+@call :reboot
+@exit /b 1
+:install_msi_success_reboot
+@call :log 3 "The installation requires a reboot to be fully functional"
+@set reboot_required=1
+:install_msi_success
+@call :log 2 "Successfully installed %name%"
+@call :log 7
+@endlocal & set reboot_required=%reboot_required%
+@goto :eof
+
+:install_nsis - Installs a dependency from an Nullsoft Installer package (.exe)
+:: %1 - [string] name of the project to install
+:: %2 - The location of the .exe, a url must start with 'http://' or file_path
+:: %3 - The checksum of the exe (optional)
+@setlocal
+@set name=%~1
+@set file_path=%~2
+@set checksum=%~3
+@set exe=%~nx2
+@set exe_path=%dependency_path%\%exe%
+@if [%name%] == [] exit /b 1
+@if [%file_path%] == [] exit /b 1
+@if [%exe%] == [] exit /b 1
+@if [%exe_path%] == [] exit /b 1
+@call :log 6
+@call :log 1 "Installing the '%name%' dependency"
+@call :log 6 "-------------------------------------"
+@call :administrator_check
+@if errorlevel 1 (
+  call :log 0 "You must run %~nx0 in elevated mode to install '%name%'"
+  call :log 5 "Right-Click and select 'Run as Administrator'
+  call :log 0 "Install the dependency manually by running %file_path%"
+  @exit /b 740
+)
+@if [%file_path:~0,4%] == [http] (
+  if not exist "%exe_path%" (
+    call :download "%file_path%" "%exe_path%" %checksum%
+    if errorlevel 1 (
+      call :log 0 "Failed to download the %name% dependency"
+      exit /b 1
+    )
+  )
+) else (
+  call :log 2 "Copying installer %file_path% to %exe_path%"
+  call :log 7
+  if not exist "%exe_path%" (
+    xcopy /q /y /z "%file_path%" "%exe_path%" 1>nul
+    if errorlevel 1 (
+      call :log 0 "Failed to copy the Nullsoft Installer"
+      exit /b 1
+    )
+  )
+)
+@call :log 1 "Running the %exe%"
+@call :log 6
+@"%exe_path%" /S
+@set nsis_errorlevel=%errorlevel%
+@if %nsis_errorlevel% equ 0 goto install_nsis_success
+@if %nsis_errorlevel% equ 3010 goto install_nsis_success_reboot
+@if %nsis_errorlevel% equ 1641 goto install_nsis_success_reboot
+@if %nsis_errorlevel% equ 3015 goto install_nsis_in_progress_reboot
+@if %nsis_errorlevel% equ 1615 goto install_nsis_in_progress_reboot
+@call :log 0 "Nullsoft Installer failed: %nsis_errorlevel%"
+@call :log 0 "Install the dependency manually by running %exe_path%"
+@exit /b 1
+:install_nsis_in_progress_reboot
+@call :log 0 "The installation requires a reboot to continue"
+@call :log 5
+@call :reboot
+@exit /b 1
+:install_nsis_success_reboot
+@call :log 3 "The installation requires a reboot to be fully functional"
+@set reboot_required=1
+:install_nsis_success
+@call :log 2 "Successfully installed %name%"
+@call :log 7
+@endlocal & set reboot_required=%reboot_required%
+@goto :eof
+
+:reboot - Asks the user if they would like to reboot then stops the script
+@setlocal
+@call :log 6 "-------------------------------------------"
+@choice /C YN /T 60 /D N /M "The %method% requires a reboot, reboot now?"
+@set ret=%errorlevel%
+@call :log 6
+@if %ret% equ 1 (
+  @shutdown /r
+) else (
+  @call :log 0 "You will need to reboot to complete the %method%"
+  @call :log 5
+)
+@endlocal
+@goto :eof

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/ci/test/01_basic/basic_spec.lua
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/ci/test/01_basic/basic_spec.lua b/thirdparty/civetweb-1.9.1/ci/test/01_basic/basic_spec.lua
new file mode 100644
index 0000000..cf3b300
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/ci/test/01_basic/basic_spec.lua
@@ -0,0 +1,35 @@
+civet = require "ci/test/civet"
+local curl = require "cURL"
+
+describe("civetweb basic", function()
+
+  setup(function()
+    civet.start()
+  end)
+
+  teardown(function()
+    civet.stop()
+  end)
+
+
+  it("should serve a simple get request", function()
+
+    local out = ""
+    function capture(str)
+      out = out .. str
+    end
+
+    local c = curl.easy()
+      :setopt_url('http://localhost:' .. civet.port .. "/")
+      :setopt_writefunction(capture)
+      :perform()
+    :close()
+
+    --print('rescode:' .. c.getinfo(curl.INFO_RESPONSE_CODE))
+
+    assert.are.equal('Index of', string.match(out, 'Index of'))
+    assert.are.equal('01_basic_test_dir', string.match(out, '01_basic_test_dir'))
+    assert.are.equal('01_basic_test_file', string.match(out, '01_basic_test_file'))
+  end)
+
+end)

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/ci/test/01_basic/docroot/01_basic_test_dir/git_keep_empty_dir
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/ci/test/01_basic/docroot/01_basic_test_dir/git_keep_empty_dir b/thirdparty/civetweb-1.9.1/ci/test/01_basic/docroot/01_basic_test_dir/git_keep_empty_dir
new file mode 100644
index 0000000..e69de29

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/ci/test/01_basic/docroot/01_basic_test_file
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/ci/test/01_basic/docroot/01_basic_test_file b/thirdparty/civetweb-1.9.1/ci/test/01_basic/docroot/01_basic_test_file
new file mode 100644
index 0000000..e69de29

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/ci/test/README.md
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/ci/test/README.md b/thirdparty/civetweb-1.9.1/ci/test/README.md
new file mode 100644
index 0000000..fdbecbe
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/ci/test/README.md
@@ -0,0 +1,34 @@
+== Travis CI Tests
+
+Travis is a service which will build your project when you commit or get pull requests on Github.
+
+I have fixed and extended the travis configuration to build on the new sudo-less docker infrastructure.
+
+=== CI Process
+
+* On Check-in or Pull Requests clone the repo
+* Run make WITH_LUA=1 WITH_DEBUG=1 WITH_IPV6=1 WITH_WEBSOCKET=1
+* Build a standalone lua installation (seperate from civetweb or the OS)
+* Build LuaRocks in standalone installation
+* Install a few rocks into the standalone installation
+* Start the test script
+
+=== test/ci_tests/01_basic/basic_spec.lua
+
+On the initial checkin, there is only one test which demonstrates:
+
+* reliably starting civetweb server on travis infrastructure
+* waiting (polling) with lua.socket to establish the server is up and running 
+* using libcurl via lua to test that files in the specified docroot are available
+* kill the civetweb server process
+* waiting (polling) the server port to see that the server has freed it
+
+=== Adding Tests
+
+* Create a directory under ci_tests
+* Add a spec file, so now we have ci_tests/02_my_awesome_test/awesome_spec.lua
+* Any file under ci_tests which ends in _spec.lua will be automatically run
+* Check out the 'busted' and lua-curl3 docs for more info
+* https://github.com/Lua-cURL/Lua-cURLv3
+* http://olivinelabs.com/busted/
+

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/ci/test/civet.lua
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/ci/test/civet.lua b/thirdparty/civetweb-1.9.1/ci/test/civet.lua
new file mode 100644
index 0000000..19a6848
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/ci/test/civet.lua
@@ -0,0 +1,42 @@
+socket = require "socket"
+
+local civet = {}
+
+-- default params
+civet.port=12345
+civet.max_retry=100
+civet.start_delay=0.1
+
+function civet.start(docroot)
+  -- TODO: use a property
+  docroot = docroot or 'ci/test/01_basic/docroot'
+  assert(io.popen('./civetweb'
+  .. " -listening_ports " .. civet.port
+  .. " -document_root " .. docroot
+  .. " > /dev/null 2>&1 &"
+  ))
+  -- wait until the server answers
+  for i=1,civet.max_retry do
+    local s = socket.connect('127.0.0.1', civet.port)
+    if s then
+      s:close()
+      break
+    end
+    socket.select(nil, nil, civet.start_delay) -- sleep
+  end
+end
+
+function civet.stop()
+  os.execute('killall civetweb')
+  -- wait until the server port closes
+  for i=1,civet.max_retry do
+    local s = socket.connect('127.0.0.1', civet.port)
+    if not s then
+      break
+    end
+    s:close()
+    socket.select(nil, nil, civet.start_delay) -- sleep
+  end
+end
+
+return civet

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/ci/travis/install_rocks.sh
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/ci/travis/install_rocks.sh b/thirdparty/civetweb-1.9.1/ci/travis/install_rocks.sh
new file mode 100755
index 0000000..26e6f36
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/ci/travis/install_rocks.sh
@@ -0,0 +1,14 @@
+#!/bin/bash
+set -ev
+
+source ci/travis/lua_env.sh
+
+# add any rocks required for ci_tests to this list
+# lua-curl depends on a libcurl development package (i.e. libcurl4-openssl-dev)
+ROCKS=(lua-curl busted)
+
+for ROCK in ${ROCKS[*]}
+do
+  $LUAROCKS install $ROCK
+done
+

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/ci/travis/lua_env.sh
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/ci/travis/lua_env.sh b/thirdparty/civetweb-1.9.1/ci/travis/lua_env.sh
new file mode 100755
index 0000000..3bb1893
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/ci/travis/lua_env.sh
@@ -0,0 +1,5 @@
+#!/bin/bash
+
+LUAROCKS=ci/lua/bin/luarocks
+eval $($LUAROCKS path --bin)
+

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/ci/travis/platform.sh
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/ci/travis/platform.sh b/thirdparty/civetweb-1.9.1/ci/travis/platform.sh
new file mode 100755
index 0000000..4a3af0d
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/ci/travis/platform.sh
@@ -0,0 +1,15 @@
+if [ -z "$PLATFORM" ]; then
+  PLATFORM=$TRAVIS_OS_NAME;
+fi
+
+if [ "$PLATFORM" == "osx" ]; then
+  PLATFORM="macosx";
+fi
+
+if [ -z "$PLATFORM" ]; then
+  if [ "$(uname)" == "Linux" ]; then
+    PLATFORM="linux";
+  else
+    PLATFORM="macosx";
+  fi;
+fi

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/ci/travis/run_ci_tests.sh
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/ci/travis/run_ci_tests.sh b/thirdparty/civetweb-1.9.1/ci/travis/run_ci_tests.sh
new file mode 100755
index 0000000..33c55dd
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/ci/travis/run_ci_tests.sh
@@ -0,0 +1,7 @@
+#!/bin/bash
+set -ev
+
+source ci/travis/lua_env.sh
+busted -o TAP ci/test/
+
+

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/ci/travis/setup_lua.sh
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/ci/travis/setup_lua.sh b/thirdparty/civetweb-1.9.1/ci/travis/setup_lua.sh
new file mode 100755
index 0000000..0992a89
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/ci/travis/setup_lua.sh
@@ -0,0 +1,61 @@
+#! /bin/bash
+set -ev
+
+# this script installs a lua / luarocks environment in .travis/lua
+# this is necessary because travis docker architecture (the fast way)
+# does not permit sudo, and does not contain a useful lua installation
+
+# After this script is finished, you can configure your environment to
+# use it by sourcing lua_env.sh
+
+source ci/travis/platform.sh
+
+# The current versions when this script was written
+LUA_VERSION=5.2.4
+LUAROCKS_VERSION=2.2.2
+
+# directory where this script is located
+SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
+
+# civetweb base dir
+PROJECT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )"/../.. && pwd )
+
+# fetch and unpack lua src
+cd $SCRIPT_DIR
+LUA_BASE=lua-$LUA_VERSION
+rm -rf $LUA_BASE
+curl http://www.lua.org/ftp/$LUA_BASE.tar.gz | tar zx
+
+# build lua
+cd $LUA_BASE
+make $PLATFORM
+make local
+
+# mv built lua install to target Lua dir
+LUA_DIR=$PROJECT_DIR/ci/lua
+rm -rf $LUA_DIR
+mv $SCRIPT_DIR/$LUA_BASE/install $LUA_DIR
+
+# add to path required by luarocks installer
+export PATH=$LUA_DIR/bin:$PATH
+
+
+# fetch and unpack luarocks
+cd $SCRIPT_DIR
+LUAROCKS_BASE=luarocks-$LUAROCKS_VERSION
+rm -rf ${LUAROCKS_BASE}
+LUAROCKS_URL=http://luarocks.org/releases/${LUAROCKS_BASE}.tar.gz
+# -L because it's a 302 redirect
+curl -L $LUAROCKS_URL | tar xzp
+cd $LUAROCKS_BASE
+
+# build luarocks
+./configure --prefix=$LUA_DIR
+make build
+make install
+
+# cleanup source dirs
+cd $SCRIPT_DIR
+rm -rf $LUAROCKS_BASE
+rm -rf $LUA_BASE
+

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/cmake/AddCCompilerFlag.cmake
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/cmake/AddCCompilerFlag.cmake b/thirdparty/civetweb-1.9.1/cmake/AddCCompilerFlag.cmake
new file mode 100644
index 0000000..f5550fa
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/cmake/AddCCompilerFlag.cmake
@@ -0,0 +1,38 @@
+# - Adds a compiler flag if it is supported by the compiler
+#
+# This function checks that the supplied compiler flag is supported and then
+# adds it to the corresponding compiler flags
+#
+#  add_c_compiler_flag(<FLAG> [<VARIANT>])
+#
+# - Example
+#
+# include(AddCCompilerFlag)
+# add_c_compiler_flag(-Wall)
+# add_c_compiler_flag(-no-strict-aliasing RELEASE)
+# Requires CMake 2.6+
+
+if(__add_c_compiler_flag)
+  return()
+endif()
+set(__add_c_compiler_flag INCLUDED)
+
+include(CheckCCompilerFlag)
+
+function(add_c_compiler_flag FLAG)
+  string(TOUPPER "HAVE_C_FLAG_${FLAG}" SANITIZED_FLAG)
+  string(REPLACE "+" "X" SANITIZED_FLAG ${SANITIZED_FLAG})
+  string(REGEX REPLACE "[^A-Za-z_0-9]" "_" SANITIZED_FLAG ${SANITIZED_FLAG})
+  string(REGEX REPLACE "_+" "_" SANITIZED_FLAG ${SANITIZED_FLAG})
+  set(CMAKE_REQUIRED_FLAGS "${FLAG}")
+  check_c_compiler_flag("" ${SANITIZED_FLAG})
+  if(${SANITIZED_FLAG})
+    set(VARIANT ${ARGV1})
+    if(ARGV1)
+      string(REGEX REPLACE "[^A-Za-z_0-9]" "_" VARIANT "${VARIANT}")
+      string(TOUPPER "_${VARIANT}" VARIANT)
+    endif()
+    set(CMAKE_C_FLAGS${VARIANT} "${CMAKE_C_FLAGS${VARIANT}} ${FLAG}" PARENT_SCOPE)
+  endif()
+endfunction()
+

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/cmake/AddCXXCompilerFlag.cmake
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/cmake/AddCXXCompilerFlag.cmake b/thirdparty/civetweb-1.9.1/cmake/AddCXXCompilerFlag.cmake
new file mode 100644
index 0000000..5e58c6d
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/cmake/AddCXXCompilerFlag.cmake
@@ -0,0 +1,38 @@
+# - Adds a compiler flag if it is supported by the compiler
+#
+# This function checks that the supplied compiler flag is supported and then
+# adds it to the corresponding compiler flags
+#
+#  add_cxx_compiler_flag(<FLAG> [<VARIANT>])
+#
+# - Example
+#
+# include(AddCXXCompilerFlag)
+# add_cxx_compiler_flag(-Wall)
+# add_cxx_compiler_flag(-no-strict-aliasing RELEASE)
+# Requires CMake 2.6+
+
+if(__add_cxx_compiler_flag)
+  return()
+endif()
+set(__add_cxx_compiler_flag INCLUDED)
+
+include(CheckCXXCompilerFlag)
+
+function(add_cxx_compiler_flag FLAG)
+  string(TOUPPER "HAVE_CXX_FLAG_${FLAG}" SANITIZED_FLAG)
+  string(REPLACE "+" "X" SANITIZED_FLAG ${SANITIZED_FLAG})
+  string(REGEX REPLACE "[^A-Za-z_0-9]" "_" SANITIZED_FLAG ${SANITIZED_FLAG})
+  string(REGEX REPLACE "_+" "_" SANITIZED_FLAG ${SANITIZED_FLAG})
+  set(CMAKE_REQUIRED_FLAGS "${FLAG}")
+  check_cxx_compiler_flag("" ${SANITIZED_FLAG})
+  if(${SANITIZED_FLAG})
+    set(VARIANT ${ARGV1})
+    if(ARGV1)
+      string(REGEX REPLACE "[^A-Za-z_0-9]" "_" VARIANT "${VARIANT}")
+      string(TOUPPER "_${VARIANT}" VARIANT)
+    endif()
+    set(CMAKE_CXX_FLAGS${VARIANT} "${CMAKE_CXX_FLAGS${VARIANT}} ${FLAG}" PARENT_SCOPE)
+  endif()
+endfunction()
+

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/cmake/DetermineTargetArchitecture.cmake
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/cmake/DetermineTargetArchitecture.cmake b/thirdparty/civetweb-1.9.1/cmake/DetermineTargetArchitecture.cmake
new file mode 100644
index 0000000..7d18213
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/cmake/DetermineTargetArchitecture.cmake
@@ -0,0 +1,47 @@
+# - Determines the target architecture of the compilation
+#
+# This function checks the architecture that will be built by the compiler
+# and sets a variable to the architecture
+#
+#  determine_target_architecture(<OUTPUT_VAR>)
+#
+# - Example
+#
+# include(DetermineTargetArchitecture)
+# determine_target_architecture(PROJECT_NAME_ARCHITECTURE)
+
+if(__determine_target_architecture)
+  return()
+endif()
+set(__determine_target_architecture INCLUDED)
+
+function(determine_target_architecture FLAG)
+  if (MSVC)
+    if("${MSVC_C_ARCHITECTURE_ID}" STREQUAL "X86")
+      set(ARCH "i686")
+    elseif("${MSVC_C_ARCHITECTURE_ID}" STREQUAL "x64")
+      set(ARCH "x86_64")
+    elseif("${MSVC_C_ARCHITECTURE_ID}" STREQUAL "ARM")
+      set(ARCH "arm")
+    else()
+      message(FATAL_ERROR "Failed to determine the MSVC target architecture: ${MSVC_C_ARCHITECTURE_ID}")
+    endif()
+  else()
+    execute_process(
+      COMMAND ${CMAKE_C_COMPILER} -dumpmachine
+      RESULT_VARIABLE RESULT
+      OUTPUT_VARIABLE ARCH
+      ERROR_QUIET
+    )
+    if (RESULT)
+      message(FATAL_ERROR "Failed to determine target architecture triplet: ${RESULT}")
+    endif()
+    string(REGEX MATCH "([^-]+).*" ARCH_MATCH ${ARCH})
+    if (NOT CMAKE_MATCH_1 OR NOT ARCH_MATCH)
+      message(FATAL_ERROR "Failed to match the target architecture triplet: ${ARCH}")
+    endif()
+    set(ARCH ${CMAKE_MATCH_1})
+  endif()
+  message(STATUS "Target architecture - ${ARCH}")
+  set(FLAG ${ARCH} PARENT_SCOPE)
+endfunction()

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/cmake/FindLibDl.cmake
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/cmake/FindLibDl.cmake b/thirdparty/civetweb-1.9.1/cmake/FindLibDl.cmake
new file mode 100644
index 0000000..c018d92
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/cmake/FindLibDl.cmake
@@ -0,0 +1,46 @@
+#.rst:
+# FindLibDl
+# --------
+#
+# Find the native realtime includes and library.
+#
+# IMPORTED Targets
+# ^^^^^^^^^^^^^^^^
+#
+# This module defines :prop_tgt:`IMPORTED` target ``LIBDL::LIBDL``, if
+# LIBDL has been found.
+#
+# Result Variables
+# ^^^^^^^^^^^^^^^^
+#
+# This module defines the following variables:
+#
+# ::
+#
+#   LIBDL_INCLUDE_DIRS  - where to find dlfcn.h, etc.
+#   LIBDL_LIBRARIES     - List of libraries when using libdl.
+#   LIBDL_FOUND         - True if dynamic linking library found.
+#
+# Hints
+# ^^^^^
+#
+# A user may set ``LIBDL_ROOT`` to a library installation root to tell this
+# module where to look.
+
+find_path(LIBDL_INCLUDE_DIRS
+  NAMES dlfcn.h
+  PATHS ${LIBDL_ROOT}/include/
+)
+find_library(LIBDL_LIBRARIES dl)
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(LibDl DEFAULT_MSG LIBDL_LIBRARIES LIBDL_INCLUDE_DIRS)
+mark_as_advanced(LIBDL_INCLUDE_DIRS LIBDL_LIBRARIES)
+
+if(LIBDL_FOUND)
+    if(NOT TARGET LIBDL::LIBDL)
+      add_library(LIBDL::LIBDL UNKNOWN IMPORTED)
+      set_target_properties(LIBDL::LIBDL PROPERTIES
+        IMPORTED_LOCATION "${LIBDL_LIBRARIES}"
+        INTERFACE_INCLUDE_DIRECTORIES "${LIBDL_INCLUDE_DIRS}")
+    endif()
+endif()

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/cmake/FindLibM.cmake
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/cmake/FindLibM.cmake b/thirdparty/civetweb-1.9.1/cmake/FindLibM.cmake
new file mode 100644
index 0000000..9f42aa4
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/cmake/FindLibM.cmake
@@ -0,0 +1,47 @@
+#.rst:
+# FindLibM
+# --------
+#
+# Find the native realtime includes and library.
+#
+# IMPORTED Targets
+# ^^^^^^^^^^^^^^^^
+#
+# This module defines :prop_tgt:`IMPORTED` target ``LIBM::LIBM``, if
+# LIBM has been found.
+#
+# Result Variables
+# ^^^^^^^^^^^^^^^^
+#
+# This module defines the following variables:
+#
+# ::
+#
+#   LIBM_INCLUDE_DIRS  - where to find math.h, etc.
+#   LIBM_LIBRARIES     - List of libraries when using libm.
+#   LIBM_FOUND         - True if math library found.
+#
+# Hints
+# ^^^^^
+#
+# A user may set ``LIBM_ROOT`` to a math library installation root to tell this
+# module where to look.
+
+find_path(LIBM_INCLUDE_DIRS
+  NAMES math.h
+  PATHS /usr/include /usr/local/include /usr/local/bic/include
+  NO_DEFAULT_PATH
+)
+find_library(LIBM_LIBRARIES m)
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(LibM DEFAULT_MSG LIBM_LIBRARIES LIBM_INCLUDE_DIRS)
+mark_as_advanced(LIBM_INCLUDE_DIRS LIBM_LIBRARIES)
+
+if(LIBM_FOUND)
+    if(NOT TARGET LIBM::LIBM)
+      add_library(LIBM::LIBM UNKNOWN IMPORTED)
+      set_target_properties(LIBM::LIBM PROPERTIES
+        IMPORTED_LOCATION "${LIBM_LIBRARIES}"
+        INTERFACE_INCLUDE_DIRECTORIES "${LIBM_INCLUDE_DIRS}")
+    endif()
+endif()

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/cmake/FindLibRt.cmake
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/cmake/FindLibRt.cmake b/thirdparty/civetweb-1.9.1/cmake/FindLibRt.cmake
new file mode 100644
index 0000000..c496edf
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/cmake/FindLibRt.cmake
@@ -0,0 +1,46 @@
+#.rst:
+# FindLibRt
+# --------
+#
+# Find the native realtime includes and library.
+#
+# IMPORTED Targets
+# ^^^^^^^^^^^^^^^^
+#
+# This module defines :prop_tgt:`IMPORTED` target ``LIBRT::LIBRT``, if
+# LIBRT has been found.
+#
+# Result Variables
+# ^^^^^^^^^^^^^^^^
+#
+# This module defines the following variables:
+#
+# ::
+#
+#   LIBRT_INCLUDE_DIRS  - where to find time.h, etc.
+#   LIBRT_LIBRARIES     - List of libraries when using librt.
+#   LIBRT_FOUND         - True if realtime library found.
+#
+# Hints
+# ^^^^^
+#
+# A user may set ``LIBRT_ROOT`` to a realtime installation root to tell this
+# module where to look.
+
+find_path(LIBRT_INCLUDE_DIRS
+  NAMES time.h
+  PATHS ${LIBRT_ROOT}/include/
+)
+find_library(LIBRT_LIBRARIES rt)
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(LibRt DEFAULT_MSG LIBRT_LIBRARIES LIBRT_INCLUDE_DIRS)
+mark_as_advanced(LIBRT_INCLUDE_DIRS LIBRT_LIBRARIES)
+
+if(LIBRT_FOUND)
+    if(NOT TARGET LIBRT::LIBRT)
+      add_library(LIBRT::LIBRT UNKNOWN IMPORTED)
+      set_target_properties(LIBRT::LIBRT PROPERTIES
+        IMPORTED_LOCATION "${LIBRT_LIBRARIES}"
+        INTERFACE_INCLUDE_DIRECTORIES "${LIBRT_INCLUDE_DIRS}")
+    endif()
+endif()

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/cmake/FindWinSock.cmake
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/cmake/FindWinSock.cmake b/thirdparty/civetweb-1.9.1/cmake/FindWinSock.cmake
new file mode 100644
index 0000000..0bf355d
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/cmake/FindWinSock.cmake
@@ -0,0 +1,102 @@
+#.rst:
+# FindWinSock
+# --------
+#
+# Find the native realtime includes and library.
+#
+# IMPORTED Targets
+# ^^^^^^^^^^^^^^^^
+#
+# This module defines :prop_tgt:`IMPORTED` target ``WINSOCK::WINSOCK``, if
+# WINSOCK has been found.
+#
+# Result Variables
+# ^^^^^^^^^^^^^^^^
+#
+# This module defines the following variables:
+#
+# ::
+#
+#   WINSOCK_INCLUDE_DIRS  - where to find winsock.h, etc.
+#   WINSOCK_LIBRARIES     - List of libraries when using librt.
+#   WINSOCK_FOUND         - True if realtime library found.
+#
+# Hints
+# ^^^^^
+#
+# A user may set ``WINSOCK_ROOT`` to a realtime installation root to tell this
+# module where to look.
+
+macro(REMOVE_DUPLICATE_PATHS LIST_VAR)
+  set(WINSOCK_LIST "")
+  foreach(PATH IN LISTS ${LIST_VAR})
+    get_filename_component(PATH "${PATH}" REALPATH)
+    list(APPEND WINSOCK_LIST "${PATH}")
+  endforeach(PATH)
+  set(${LIST_VAR} ${WINSOCK_LIST})
+  list(REMOVE_DUPLICATES ${LIST_VAR})
+endmacro(REMOVE_DUPLICATE_PATHS)
+
+set(WINSOCK_INCLUDE_PATHS "${WINSOCK_ROOT}/include/")
+if(MINGW)
+  execute_process(
+    COMMAND ${CMAKE_C_COMPILER} -xc -E -v -
+    RESULT_VARIABLE RESULT
+    INPUT_FILE nul
+    ERROR_VARIABLE ERR
+    OUTPUT_QUIET
+  )
+  if (NOT RESULT)
+    string(FIND "${ERR}" "#include <...> search starts here:" START)
+    string(FIND "${ERR}" "End of search list." END)
+    if (NOT ${START} EQUAL -1 AND NOT ${END} EQUAL -1)
+      math(EXPR START "${START} + 36")
+      math(EXPR END "${END} - 1")
+      math(EXPR LENGTH "${END} - ${START}")
+      string(SUBSTRING "${ERR}" ${START} ${LENGTH} WINSOCK_INCLUDE_PATHS)
+      string(REPLACE "\n " ";" WINSOCK_INCLUDE_PATHS "${WINSOCK_INCLUDE_PATHS}")
+      list(REVERSE WINSOCK_INCLUDE_PATHS)
+    endif()
+  endif()
+endif()
+remove_duplicate_paths(WINSOCK_INCLUDE_PATHS)
+
+set(WINSOCK_LIBRARY_PATHS "${WINSOCK_ROOT}/lib/")
+if(MINGW)
+  execute_process(
+    COMMAND ${CMAKE_C_COMPILER} -print-search-dirs
+    RESULT_VARIABLE RESULT
+    OUTPUT_VARIABLE OUT
+    ERROR_QUIET
+  )
+  if (NOT RESULT)
+    string(REGEX MATCH "libraries: =([^\r\n]*)" OUT "${OUT}")
+    list(APPEND WINSOCK_LIBRARY_PATHS "${CMAKE_MATCH_1}")
+  endif()
+endif()
+if (${CMAKE_HOST_SYSTEM_PROCESSOR} STREQUAL "AMD64" AND ${CMAKE_SIZEOF_VOID_P} EQUAL 4)
+  list(APPEND WINSOCK_LIBRARY_PATHS "C:/Windows/SysWOW64")
+endif()
+list(APPEND WINSOCK_LIBRARY_PATHS "C:/Windows/System32")
+remove_duplicate_paths(WINSOCK_LIBRARY_PATHS)
+
+find_path(WINSOCK_INCLUDE_DIRS
+  NAMES winsock2.h
+  PATHS ${WINSOCK_INCLUDE_PATHS}
+)
+find_library(WINSOCK_LIBRARIES ws2_32
+  PATHS ${WINSOCK_LIBRARY_PATHS}
+  NO_DEFAULT_PATH
+)
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(WinSock DEFAULT_MSG WINSOCK_LIBRARIES WINSOCK_INCLUDE_DIRS)
+mark_as_advanced(WINSOCK_INCLUDE_DIRS WINSOCK_LIBRARIES)
+
+if(WINSOCK_FOUND)
+    if(NOT TARGET WINSOCK::WINSOCK)
+      add_library(WINSOCK::WINSOCK UNKNOWN IMPORTED)
+      set_target_properties(WINSOCK::WINSOCK PROPERTIES
+        IMPORTED_LOCATION "${WINSOCK_LIBRARIES}"
+        INTERFACE_INCLUDE_DIRECTORIES "${WINSOCK_INCLUDE_DIRS}")
+    endif()
+endif()

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/cmake/check/c82fe8888aacfe784476112edd3878256d2e30bc.patch
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/cmake/check/c82fe8888aacfe784476112edd3878256d2e30bc.patch b/thirdparty/civetweb-1.9.1/cmake/check/c82fe8888aacfe784476112edd3878256d2e30bc.patch
new file mode 100644
index 0000000..e16ea1f
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/cmake/check/c82fe8888aacfe784476112edd3878256d2e30bc.patch
@@ -0,0 +1,31 @@
+From c82fe8888aacfe784476112edd3878256d2e30bc Mon Sep 17 00:00:00 2001
+From: Joshua Boyd <jd...@Joshua-Boyds-Mac-mini.local>
+Date: Wed, 23 Mar 2016 17:54:41 -0400
+Subject: [PATCH] Detect missing itimerspec on OSX.
+
+Set define to compiler accordingly.
+
+This fixes cmake on osx support.
+---
+ CMakeLists.txt | 8 ++++++++
+ 1 file changed, 8 insertions(+)
+
+diff --git a/CMakeLists.txt b/CMakeLists.txt
+index e271e31..1d413e8 100644
+--- a/CMakeLists.txt
++++ b/CMakeLists.txt
+@@ -193,6 +193,14 @@ if(NOT HAVE_SYS_TIME_H)
+     endif(MSVC)
+ endif(NOT HAVE_SYS_TIME_H)
+ 
++# OSX has sys/time.h, but it still lacks itimerspec
++if(HAVE_SYS_TIME_H)
++    check_struct_member("struct itimerspec" it_value "sys/time.h" HAVE_STRUCT_ITIMERSPEC_IT_VALUE)
++    if(NOT HAVE_STRUCT_ITIMERSPEC_IT_VALUE)
++        add_definitions(-DSTRUCT_ITIMERSPEC_DEFINITION_MISSING=1)
++        set(STRUCT_ITIMERSPEC_DEFINITION_MISSING 1)
++    endif(NOT HAVE_STRUCT_ITIMERSPEC_IT_VALUE)
++endif(HAVE_SYS_TIME_H)
+ 
+ ###############################################################################
+ # Check for integer types

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/cmake/check/patch.cmake
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/cmake/check/patch.cmake b/thirdparty/civetweb-1.9.1/cmake/check/patch.cmake
new file mode 100644
index 0000000..472d392
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/cmake/check/patch.cmake
@@ -0,0 +1,12 @@
+message(STATUS "Patching check ${VERSION} ${SOURCE_DIR}")
+
+# Patch checks for MinGW
+# https://sourceforge.net/p/check/patches/53/
+set(CMAKE_LISTS_LOCATION "${SOURCE_DIR}/CMakeLists.txt")
+file(READ ${CMAKE_LISTS_LOCATION} CMAKE_LISTS)
+string(REGEX REPLACE
+  "(check_type_size\\((clock|clockid|timer)_t [A-Z_]+\\)[\r\n]+[^\r\n]+[\r\n]+[^\r\n]+[\r\n]+endif\\(NOT HAVE[A-Z_]+\\))"
+  "set(CMAKE_EXTRA_INCLUDE_FILES time.h)\n\\1\nunset(CMAKE_EXTRA_INCLUDE_FILES)"
+  CMAKE_LISTS "${CMAKE_LISTS}")
+file(WRITE ${CMAKE_LISTS_LOCATION} "${CMAKE_LISTS}")
+message(STATUS "Patched ${CMAKE_LISTS_LOCATION}")

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/contrib/buildroot/Config.in
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/contrib/buildroot/Config.in b/thirdparty/civetweb-1.9.1/contrib/buildroot/Config.in
new file mode 100644
index 0000000..2334fdf
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/contrib/buildroot/Config.in
@@ -0,0 +1,26 @@
+config BR2_PACKAGE_CIVETWEB
+	bool "civetweb"
+	depends on BR2_TOOLCHAIN_HAS_THREADS
+	help
+	  Full featured embedded web server with Lua support.
+	  
+	  https://sourceforge.net/projects/civetweb
+
+if BR2_PACKAGE_CIVETWEB
+
+config BR2_CIVETWEB_WITH_LUA
+	bool "enable Lua support"
+	# required by the bundled Sqlite3 and Lua code
+	depends on BR2_LARGEFILE
+	help
+	  Enable Lua support in Civetweb. Note that this will use a
+	  version of Lua and Sqlite bundled within the Civetweb
+	  sources, and not the packages from Buildroot.
+
+comment "Lua support requires largefile support in toolchain"
+	depends on !BR2_LARGEFILE
+
+endif
+
+comment "civetweb requires a toolchain with PTHREAD support"
+	depends on !BR2_TOOLCHAIN_HAS_THREADS

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/contrib/buildroot/civetweb.mk
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/contrib/buildroot/civetweb.mk b/thirdparty/civetweb-1.9.1/contrib/buildroot/civetweb.mk
new file mode 100644
index 0000000..b85f82b
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/contrib/buildroot/civetweb.mk
@@ -0,0 +1,55 @@
+################################################################################
+#
+# civetweb
+#
+################################################################################
+
+CIVETWEB_VERSION = 1.9
+CIVETWEB_SITE = http://github.com/civetweb/civetweb/tarball/v$(CIVETWEB_VERSION)
+CIVETWEB_LICENSE = MIT
+CIVETWEB_LICENSE_FILES = LICENSE.md
+
+CIVETWEB_CONF_OPT = TARGET_OS=LINUX
+CIVETWEB_COPT = $(TARGET_CFLAGS) -DHAVE_POSIX_FALLOCATE=0
+CIVETWEB_LDFLAGS = $(TARGET_LDFLAGS)
+CIVETWEB_SYSCONFDIR = /etc
+CIVETWEB_HTMLDIR = /var/www
+
+ifneq ($(BR2_LARGEFILE),y)
+	CIVETWEB_COPT += -DSQLITE_DISABLE_LFS
+endif
+
+ifeq ($(BR2_INET_IPV6),y)
+	CIVETWEB_CONF_OPT += WITH_IPV6=1
+endif
+
+ifeq ($(BR2_CIVETWEB_WITH_LUA),y)
+	CIVETWEB_CONF_OPT += WITH_LUA=1
+endif
+
+ifeq ($(BR2_PACKAGE_OPENSSL),y)
+	CIVETWEB_COPT += -DNO_SSL_DL -lcrypt -lssl
+	CIVETWEB_DEPENDENCIES += openssl
+else
+	CIVETWEB_COPT += -DNO_SSL
+endif
+
+define CIVETWEB_BUILD_CMDS
+	$(MAKE) CC="$(TARGET_CC)" -C $(@D) build \
+		$(CIVETWEB_CONF_OPT) \
+		COPT="$(CIVETWEB_COPT)"
+endef
+
+define CIVETWEB_INSTALL_TARGET_CMDS
+	$(MAKE) CC="$(TARGET_CC)" -C $(@D) install \
+		DOCUMENT_ROOT="$(CIVETWEB_HTMLDIR)" \
+		CONFIG_FILE2="$(CIVETWEB_SYSCONFDIR)/civetweb.conf" \
+		HTMLDIR="$(TARGET_DIR)$(CIVETWEB_HTMLDIR)" \
+		SYSCONFDIR="$(TARGET_DIR)$(CIVETWEB_SYSCONFDIR)" \
+		PREFIX="$(TARGET_DIR)/usr" \
+		$(CIVETWEB_CONF_OPT) \
+		COPT='$(CIVETWEB_COPT)'
+endef
+
+$(eval $(generic-package))
+

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/distribution/arch/PKGBUILD.git.example
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/distribution/arch/PKGBUILD.git.example b/thirdparty/civetweb-1.9.1/distribution/arch/PKGBUILD.git.example
new file mode 100644
index 0000000..7102bcb
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/distribution/arch/PKGBUILD.git.example
@@ -0,0 +1,42 @@
+# An example PKGBUILD script for Civetweb upstream, git version
+# Rename to PKGBUILD to build via makepkg
+_pkgname=civetweb
+pkgname=$_pkgname-git
+pkgver=v1.4.24.g73c40b6
+pkgrel=1
+pkgdesc="Small and quick-to-use web server; https/php/cgi support; MIT license - git development version"
+arch=('i686' 'x86_64')
+url="http://sourceforge.net/p/civetweb/"
+license=('MIT')
+groups=()
+depends=()
+makedepends=('git sed')
+optdepends=('php-cgi: for php support')
+provides=("$_pkgname")
+conflicts=("$_pkgname")
+backup=("etc/$_pkgname/$_pkgname.conf")
+source=("$_pkgname::git+https://github.com/civetweb/civetweb.git")
+md5sums=('SKIP')
+
+pkgver() {
+  cd "$srcdir/$_pkgname"
+  git describe --tags | sed 's|-|.|g'
+}
+
+build() {
+  cd "$srcdir/$_pkgname"
+  make build WITH_IPV6=1
+}
+
+package() {
+  cd "$srcdir/$_pkgname"
+  make install PREFIX="$pkgdir/usr" SYSCONFDIR="$pkgdir/etc/local/$_pkgname"
+  
+  install -Dm644 "$srcdir/$_pkgname/distribution/arch/$_pkgname.service" "$pkgdir/usr/lib/systemd/system/$_pkgname.service"
+
+  sed -i "s/^document_root [^\n]*/document_root \/srv\/http/g" "$pkgdir/etc/local/$_pkgname/$_pkgname.conf"
+  sed -i "s/^# access_log_file/access_log_file \/var\/log\/$_pkgname\/access.log/g" "$pkgdir/etc/local/$_pkgname/$_pkgname.conf"
+  sed -i "s/^# error_log_file/access_log_file \/var\/log\/$_pkgname\/error.log/g" "$pkgdir/etc/local/$_pkgname/$_pkgname.conf"
+}
+
+# vim:set ts=2 sw=2 et:

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/distribution/arch/civetweb.service
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/distribution/arch/civetweb.service b/thirdparty/civetweb-1.9.1/distribution/arch/civetweb.service
new file mode 100644
index 0000000..5327b6c
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/distribution/arch/civetweb.service
@@ -0,0 +1,9 @@
+[Unit]
+Description=Civetweb httpd
+After=syslog.target network.target remote-fs.target nss-lookup.target
+
+[Service]
+ExecStart=/usr/local/bin/civetweb /usr/local/etc/civetweb/civetweb.conf
+
+[Install]
+WantedBy=multi-user.target

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/docs/APIReference.md
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/docs/APIReference.md b/thirdparty/civetweb-1.9.1/docs/APIReference.md
new file mode 100644
index 0000000..96f5c89
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/docs/APIReference.md
@@ -0,0 +1,78 @@
+# CivetWeb API Reference
+
+CivetWeb is often used as HTTP and HTTPS library inside a larger application.
+A C API is available to integrate the CivetWeb functionality in a larger
+codebase. A C++ wrapper is also available, although it is not guaranteed
+that all functionality available through the C API can also be accessed
+from C++. This document describes the public C API. Basic usage examples of
+the API can be found in [Embedding.md](Embedding.md).
+
+## Macros
+
+| Macro | Description |
+| :--- | :--- |
+| **`CIVETWEB_VERSION`** | The current version of the website as a string with the major and minor version number seperated with a dot. For version 1.9, this string will for example have the value "1.9" |
+
+## Structures
+
+* [`struct client_cert;`](api/client_cert.md)
+* [`struct mg_client_options;`](api/mg_client_options.md)
+* [`struct mg_callbacks;`](api/mg_callbacks.md)
+* [`struct mg_form_data_handler;`](api/mg_form_data_handler.md)
+* [`struct mg_header;`](api/mg_header.md)
+* [`struct mg_option;`](api/mg_option.md)
+* [`struct mg_request_info;`](api/mg_request_info.md)
+* [`struct mg_server_ports;`](api/mg_server_ports.md)
+
+## Functions
+
+* [`mg_check_feature( feature );`](api/mg_check_feature.md)
+* [`mg_close_connection( conn );`](api/mg_close_connection.md)
+* [`mg_connect_client( host, port, use_ssl, error_buffer, error_buffer_size );`](api/mg_connect_client.md)
+* [`mg_connect_websocket_client( host, port, use_ssl, error_buffer, error_buffer_size, path, origin, data_func, close_func, user_data);`](api/mg_connect_websocket_client.md)
+* [`mg_cry( conn, fmt, ... );`](api/mg_cry.md)
+* [`mg_download( host, port, use_ssl, error_buffer, error_buffer_size, fmt, ... );`](api/mg_download.md)
+* [`mg_get_builtin_mime_type( file_name );`](api/mg_get_builtin_mime_type.md)
+* [`mg_get_context( conn );`](api/mg_get_context.md)
+* [`mg_get_cookie( cookie, var_name, buf, buf_len );`](api/mg_get_cookie.md)
+* [`mg_get_header( conn, name );`](api/mg_get_header.md)
+* [`mg_get_option( ctx, name );`](api/mg_get_option.md)
+* [`mg_get_request_info( conn );`](api/mg_get_request_info.md)
+* [`mg_get_response( conn, ebuf, ebuf_len, timeout );`](api/mg_get_response.md)
+* [`mg_get_response_code_text( conn, response_code );`](api/mg_get_response_code_text.md)
+* [`mg_get_server_ports( ctx, size, ports );`](api/mg_get_server_ports.md)
+* [`mg_get_user_connection_data( conn );`](api/mg_get_user_connection_data.md)
+* [`mg_get_user_data( ctx );`](api/mg_get_user_data.md)
+* [~~`mg_get_valid_option_names();`~~](api/mg_get_valid_option_names.md)
+* [`mg_get_valid_options();`](api/mg_get_valid_options.md)
+* [`mg_get_var( data, data_len, var_name, dst, dst_len );`](api/mg_get_var.md)
+* [`mg_get_var2( data, data_len, var_name, dst, dst_len, occurrence );`](api/mg_get_var2.md)
+* [`mg_handle_form_request( conn, fdh );`](api/mg_handle_form_request.md)
+* [`mg_lock_connection( conn );`](api/mg_lock_connection.md)
+* [`mg_lock_context( ctx );`](api/mg_lock_context.md)
+* [`mg_md5( buf, ... );`](api/mg_md5.md)
+* [`mg_modify_passwords_file( passwords_file_name, domain, user, password );`](api/mg_modify_passwords_file.md)
+* [`mg_printf( conn, fmt, ... );`](api/mg_printf.md)
+* [`mg_read( conn, buf, len );`](api/mg_read.md)
+* [`mg_send_file( conn, path );`](api/mg_send_file.md)
+* [`mg_send_mime_file( conn, path, mime_type );`](api/mg_send_mime_file.md)
+* [`mg_send_mime_file2( conn, path, mime_type, additional_headers );`](api/mg_send_mime_file2.md)
+* [`mg_set_auth_handler( ctx, uri, handler, cbdata );`](api/mg_set_auth_handler.md)
+* [`mg_set_request_handler( ctx, uri, handler, cbdata );`](api/mg_set_request_handler.md)
+* [`mg_set_user_connection_data( conn, data );`](api/mg_set_user_connection_data.md)
+* [`mg_set_websocket_handler( ctx, uri, connect_handler, ready_handler, data_handler, close_handler, cbdata );`](api/mg_set_websocket_handler.md)
+* [`mg_start( callbacks, user_data, options );`](api/mg_start.md)
+* [`mg_start_thread( f, p );`](api/mg_start_thread.md)
+* [`mg_store_body( conn, path );`](api/mg_store_body.md)
+* [`mg_stop( ctx );`](api/mg_stop.md)
+* [`mg_strcasecmp( s1, s2 );`](api/mg_strcasecmp.md)
+* [`mg_strncasecmp( s1, s2, len );`](api/mg_strncasecmp.md)
+* [`mg_unlock_connection( conn );`](api/mg_unlock_connection.md)
+* [`mg_unlock_context( ctx );`](api/mg_unlock_context.md)
+* [~~`mg_upload( conn, destination_dir );`~~](api/mg_upload.md)
+* [`mg_url_decode( src, src_len, dst, dst_len, is_form_url_encoded );`](api/mg_url_decode.md)
+* [`mg_url_encode( src, dst, dst_len );`](api/mg_url_encode.md)
+* [`mg_version();`](api/mg_version.md)
+* [`mg_websocket_client_write( conn, opcode, data, data_len );`](api/mg_websocket_client_write.md)
+* [`mg_websocket_write( conn, opcode, data, data_len );`](api/mg_websocket_write.md)
+* [`mg_write( conn, buf, len );`](api/mg_write.md)


[45/51] [partial] nifi-minifi-cpp git commit: MINIFI-183 Added civet 1.9.1 sources Added onScheduled hook Added initial two-way TLS-enabled ListenHTTP implementation

Posted by al...@apache.org.
http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/docs/api/mg_download.md
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/docs/api/mg_download.md b/thirdparty/civetweb-1.9.1/docs/api/mg_download.md
new file mode 100644
index 0000000..1dbded0
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/docs/api/mg_download.md
@@ -0,0 +1,37 @@
+# Civetweb API Reference
+
+### `mg_download( host, port, use_ssl, error_buffer, error_buffer_size, fmt, ... );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`host`**|`const char *`|The hostname or IP address of the server|
+|**`port`**|`int`|The port number on the server|
+|**`use_ssl`**|`int`|Use SSL if this value is not equal zero|
+|**`error_buffer`**|`char *`|Buffer to store an error message|
+|**`error_buffer_size`**|`size_t`|Size of the error message buffer including the terminating NUL|
+|**`fmt`**|`const char *`|Format string specifying the remote command to execute|
+|**`...`**|*various*|Parameters used in the format string|
+
+### Return Value
+
+| Type | Description |
+| :--- | :--- |
+|`struct mg_connection *`|A pointer to the connection structure if successful and NULL otherwise|
+
+### Description
+
+The `mg_download()` function is used to download data from a remote webserver. The server address can either be specified as a hostname or IP address and SSL can be used if needed. If the function succeeds, a pointer is returned to a connection structure. The connection must be closed with a call to the [`mg_close_connection()`](mg_close_connection.md) function.
+
+The format string is a format string from the `printf()` series of functions to specify the remote command. An example to get the main index page from Google is the following call:
+
+`conn = mg_download( "google.com", 80, 0, ebuf, sizeof(ebuf),
+                     "%s", "GET / HTTP/1.0\r\nHost: google.com\r\n\r\n" );`
+
+Please note that although Civetweb supports both IPv4 and IPv6 communication that IPv6 addressing is only available if it was enabled at compile time. When running an application it is possible to check if IPv6 support has been compiled in by using the [`mg_check_feature()`](md_check_feature.md) function with the parameter `USE_IPV6`.
+
+### See Also
+
+* [`mg_check_feature();`](mg_check_feature.md)
+* [`mg_close_connection();`](mg_close_connection.md)

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/docs/api/mg_form_data_handler.md
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/docs/api/mg_form_data_handler.md b/thirdparty/civetweb-1.9.1/docs/api/mg_form_data_handler.md
new file mode 100644
index 0000000..2338b72
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/docs/api/mg_form_data_handler.md
@@ -0,0 +1,36 @@
+# Civetweb API Reference
+
+### `struct mg_form_data_handler;`
+
+### Fields
+
+|Field|Description|
+|:---|:---|
+|**`field_found`**|**`int field_found( const char *key, const char *filename, char *path, size_t pathlen, void *user_data )`**;|
+||The callback function `field_found()` is called when a new field has been found. The return value of this callback is used to define how the field should be processed. The parameters contain the following information:|
+||**`key`** - The name of the field as it was named with the `name` tag in the HTML source.|
+||**`filename`** - The name of the file to upload. Please not that this parameter is only valid when the input type was set to `file`. Otherwise this parameter has the value `NULL`.|
+||**`path`** - This is an output parameter used to store the full name of the file including the path to store an incoming file at the computer. This parameter must be provided by the application to Civetweb when a form field of type `file` is found. Please not that together with setting this parameter, the callback function must return `FORM_FIELD_STORAGE_STORE`.i With any other return value the contents of the `path` buffer is ignored by Civetweb.|
+||**`pathlen`** - The length of the buffer where the output path can be stored.|
+||**`user_data`** - A pointer to the value of the field `user_data` of the structure `struct mg_form_data_handler`.|
+||The callback function `field_found()` can return the following values back to Civetweb:|
+||**`FORM_FIELD_STORAGE_SKIP`** - Ignore the field and continue with processing the next field|
+||**`FORM_FIELD_STORAGE_GET`** - Call the callback function `field_get()` to receive the form data|
+||**`FORM_FIELD_STORAGE_STORE`** - Store a file as `path` and overwrite that file if it already exists|
+||**`FORM_FIELD_STORAGE_ABORT`** - Stop parsing the request and ignore all remaining form fields|
+|**`field_get`**|**`int field_get( const char *key, const char *value, size_t valuelen, void *user_data );`**|
+|**`field_store`**|**`int field_store( const char *path, long long file_size, void *user_data );`**|
+||If the callback function `field_found()` returned `FORM_FIELD_STORAGE_STORE`, Civetweb will try to store the received data in a file. If writing the file is successful, the callback function `field_store()` is called. This function is only called after completion of a full upload, not if a file has only partly been uploaded. When only part of a file is received, Civetweb will delete that partly upload in the background and not inform the main application through this callback. The following parameters are provided in the function call:|
+||**`path`** -|
+||**`file_size`** - The path on the server where the file was stored|
+||**`user_data`** - The size of the stored file in bytes|
+|**`user_data`**|**`void *`** The value of the field `user_data` when the callback functions were registered with a call to `mg_handle_form_request();`|
+||The `user_data` field is a user supplied argument that will be passed as parameter to each of callback functions|
+
+### Description
+
+The structure `struct mg_form_data_handler` contains callback functions for handling form fields. Form fields give additional information back from a web page to the server which can be processed by these callback functions.
+
+### See Also
+
+* [`mg_handle_form_request();`](mg_handle_form_request.md)

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/docs/api/mg_get_builtin_mime_type.md
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/docs/api/mg_get_builtin_mime_type.md b/thirdparty/civetweb-1.9.1/docs/api/mg_get_builtin_mime_type.md
new file mode 100644
index 0000000..c9044ae
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/docs/api/mg_get_builtin_mime_type.md
@@ -0,0 +1,24 @@
+# Civetweb API Reference
+
+### `mg_get_builtin_mime_type( file_name );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`file_name`**|`const char *`|The name of the file for which the MIME type has to be determined|
+
+### Return Value
+
+| Type | Description |
+| :--- | :--- |
+|`const char *`|A text string describing the MIME type|
+
+### Description
+
+The function `mg_get_builtin_mime_type()` tries to determine the MIME type of a given file. If the MIME type cannot be determined, the value `text/plain` is returned. Please note that this function does not an intelligent check of the file contents. The MIME type is solely determined based on the file name extension.
+
+### See Also
+
+* [`mg_send_mime_file();`](mg_send_mime_file.md)
+* [`mg_send_mime_file2();`](mg_send_mime_file2.md)

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/docs/api/mg_get_context.md
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/docs/api/mg_get_context.md b/thirdparty/civetweb-1.9.1/docs/api/mg_get_context.md
new file mode 100644
index 0000000..ce6cb2b
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/docs/api/mg_get_context.md
@@ -0,0 +1,24 @@
+# Civetweb API Reference
+
+### `mg_get_context( conn );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`conn`**|`const struct mg_connection *`|The connection for which the context has to be returned|
+
+### Return Value
+
+| Type | Description |
+| :--- | :--- |
+|`struct mg_context *`|A pointer to the context of the given connection|
+
+### Description
+
+The function `mg_get_context()` returns the context associated with a connection.
+
+### See Also
+
+* [`mg_start();`](mg_start.md)
+* [`mg_stop();`](mg_stop.md)

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/docs/api/mg_get_cookie.md
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/docs/api/mg_get_cookie.md b/thirdparty/civetweb-1.9.1/docs/api/mg_get_cookie.md
new file mode 100644
index 0000000..a738bc0
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/docs/api/mg_get_cookie.md
@@ -0,0 +1,29 @@
+# Civetweb API Reference
+
+### `mg_get_cookie( cookie, var_name, buf, buf_len );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`cookie`**|`const char *`|The cookie name|
+|**`var_name`**|`const char *`|The variable name|
+|**`buf`**|`char *`|The buffer where to store the contents of the cookie|
+|**`buf_len`**|`size_t`|The length of the cookie buffer, including the terminating NUL|
+
+### Return Value
+
+| Type | Description |
+| :--- | :--- |
+|`int`|The length of the cookie or an error code|
+
+### Description
+
+The function `mg_get_cookie()` tries to fetch the value of a certain cookie variable. The contents will either be stored in an application provided buffer, or an error code will be returned. The destination buffer is guaranteed to be NUL terminated if the pointer of the buffer is not a NULL pointer and the size of the buffer is at least one byte.
+
+If the function succeeds, the return value of the function is the length in bytes of the cookie. The value **`-1`** is returned if the requested cookie could not be found and **`-2`** if the destination buffer is represented by a NULL pointer, is zero length or too short to store the whole cookie.
+
+### See Also
+
+* [`mg_get_var();`](mg_get_var.md)
+* [`mg_get_var2();`](mg_get_var2.md)

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/docs/api/mg_get_header.md
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/docs/api/mg_get_header.md b/thirdparty/civetweb-1.9.1/docs/api/mg_get_header.md
new file mode 100644
index 0000000..8ad1810
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/docs/api/mg_get_header.md
@@ -0,0 +1,22 @@
+# Civetweb API Reference
+
+### `mg_get_header( conn, name );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`conn`**|`struct mg_connection *`| A pointer referencing the connection |
+|**`name`**|`const char *`| The name of the request header |
+
+### Return Value
+
+| Type | Description |
+| :--- | :--- |
+|`const char *`| A pointer to the value of the request header, or NULL of no matching header count be found |
+
+### Description
+
+HTTP and HTTPS clients can send request headers to the server to provide details about the communication. These request headers can for example specify the preferred language in which the server should respond and the supported compression algorithms. The function `mg_get_header()` can be called to return the contents of a specific request header. The function will return a pointer to the value text of the header when succesful, and NULL of no matching request header from the client could be found.
+
+### See Also

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/docs/api/mg_get_option.md
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/docs/api/mg_get_option.md b/thirdparty/civetweb-1.9.1/docs/api/mg_get_option.md
new file mode 100644
index 0000000..b731dd7
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/docs/api/mg_get_option.md
@@ -0,0 +1,24 @@
+# Civetweb API Reference
+
+### `mg_get_option( ctx, name );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`ctx`**|`const struct mg_context *`| A pointer to the webserver context |
+|**`name`**|`const char *`| The name of the option to query |
+
+### Return Value
+
+| Type | Description |
+| :--- | :--- |
+|`const char *`| A pointer to the option value in text, or NULL if an error occured |
+
+### Description
+
+When starting the CivetWeb webserver, options are provided to set the wanted behaviour of the server. The options which were used during startup can be queried through the `mg_get_option()` function. Options are read-only and cannot be changed while the webserver is running. The function returns a pointer to a text string containing the value of the queried option, or NULL if an error occured. It is guaranteed however that if a valid option name is provided as a parameter to this function, that a pointer to a string is returned and not NULL. In case an option was empty or NULL during initialisation, `mg_get_option()` will return a pointer to an empty string.
+
+### See Also
+
+* [`mg_start();`](mg_start.md)

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/docs/api/mg_get_ports.md
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/docs/api/mg_get_ports.md b/thirdparty/civetweb-1.9.1/docs/api/mg_get_ports.md
new file mode 100644
index 0000000..ba492ca
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/docs/api/mg_get_ports.md
@@ -0,0 +1,31 @@
+# Civetweb API Reference
+
+### ~~`mg_get_ports( ctx, size, ports, ssl );`~~
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`ctx`**|`const struct mg_context *`||
+|**`size`**|`size_t`|The number of ports which can be stored in the buffer|
+|**`ports`**|`int *`|Buffer for storage of the port numbers|
+|**`ssl`**|`int *`|Buffer used to store if SSL is used for the ports|
+
+### Return Value
+
+| Type | Description |
+| :--- | :--- |
+|`size_t`|The number of ports stored in the buffer|
+
+### Description
+
+This function is deprecated. Use [`mg_get_server_ports()`](mg_get_server_ports.md) instead.
+
+The function `mg_get_ports()` returns a list of ports the Civetweb server is listening on. The port numbers are stored in a buffer of integers which is supplied by the calling party. The function also stores information if SSL is used on the ports. This information is stored in a second buffer which should be capable of storing the same amount of items as the ports buffer.
+
+The function returns the number of ports actually stored in the buffer.
+
+### See Also
+
+* [`struct mg_server_ports;`](mg_server_ports.md)
+* [`mg_get_server_ports();`](mg_get_server_ports.md)

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/docs/api/mg_get_request_info.md
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/docs/api/mg_get_request_info.md b/thirdparty/civetweb-1.9.1/docs/api/mg_get_request_info.md
new file mode 100644
index 0000000..2b5ac32
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/docs/api/mg_get_request_info.md
@@ -0,0 +1,23 @@
+# Civetweb API Reference
+
+### `mg_get_request_info( conn );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`conn`**|`const struct mg_connection *`|The connection for which the request info is needed|
+
+### Return Value
+
+| Type | Description |
+| :--- | :--- |
+|`const struct mg_request_info *`|Pointer to the requested info, or NULL if an error occured|
+
+### Description
+
+The function `mg_get_request_info()` returns information about the request on a given connection. This information is returned as a pointer to a [`mg_request_info`](mg_request_info.md) structure. If an error occurs, a NULL pointer is returned instead.
+
+### See Also
+
+* [`struct mg_request_info;`](mg_request_info.md)

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/docs/api/mg_get_response.md
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/docs/api/mg_get_response.md b/thirdparty/civetweb-1.9.1/docs/api/mg_get_response.md
new file mode 100644
index 0000000..3e7b727
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/docs/api/mg_get_response.md
@@ -0,0 +1,29 @@
+# Civetweb API Reference
+
+### `mg_get_response( conn, ebuf, ebuf_len, timeout );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`conn`**|`struct mg_connection *`|The connection to listen on|
+|**`ebuf`**|`char *`|Buffer to store an error message|
+|**`ebuf_len`**|`size_t`|Size of the error message buffer including the terminating NUL|
+|**`timeout`**|`int`|Time to wait for a response in milliseconds|
+
+### Return Value
+
+| Type | Description |
+| :--- | :--- |
+|`int`|Success value of the wait|
+
+### Description
+
+The function `mg_get_reponse()` wait for a response from a remote server. A return value equal or greater than zero is an indication for success, a negative value us used to signal an error condition. A timeout can be specified which lets the function return after a specified number of milliseconds, even if no data is received from the remote party. If the timeout value is negative, the function will not return until data has been read or an unrecoverable error occurs.
+
+Error messages are stored in a caller supplied error message buffer.
+
+### See Also
+
+* [`mg_connect_client();`](mg_connect_client.md)
+* [`mg_connect_client_secure();`](mg_connect_client_secure.md)

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/docs/api/mg_get_response_code_text.md
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/docs/api/mg_get_response_code_text.md b/thirdparty/civetweb-1.9.1/docs/api/mg_get_response_code_text.md
new file mode 100644
index 0000000..79ffa13
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/docs/api/mg_get_response_code_text.md
@@ -0,0 +1,25 @@
+# Civetweb API Reference
+
+### `mg_get_response_code_text( conn, response_code );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`conn`**|`struct mg_connection *`| A pointer referencing the connection |
+|**`response_code`**|`int`| Response code for which the text is queried |
+
+### Return Value
+
+| Type | Description |
+| :--- | :--- |
+|`const char *`| A pointer to a human readable text explaining the response code. |
+
+### Description
+
+The function `mg_get_response_code_text()` returns a pointer to a human readable text describing the HTTP response code which was provided as a parameter.
+
+### See Also
+
+* [`mg_get_builtin_mime_type();`](mg_get_builtin_mime_type.md)
+* [`mg_version();`](mg_version.md)

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/docs/api/mg_get_server_ports.md
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/docs/api/mg_get_server_ports.md b/thirdparty/civetweb-1.9.1/docs/api/mg_get_server_ports.md
new file mode 100644
index 0000000..323b470
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/docs/api/mg_get_server_ports.md
@@ -0,0 +1,28 @@
+# Civetweb API Reference
+
+### `mg_get_server_ports( ctx, size, ports );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`ctx`**|`const struct mg_context *`|The context for which the server ports are requested|
+|**`size`**|`int`|The size of the buffer to store the port information|
+|**`ports`**|`struct mg_server_ports *`|Buffer to store the port information|
+
+### Return Value
+
+| Type | Description |
+| :--- | :--- |
+|`int`|The actual number of ports returned, or an error condition|
+
+### Description
+
+The `mg_get_server_ports()` returns a list with server ports on which the Civetweb server is listening. The ports are returned for a given context and stored with additional information like the SSL and redirection state in a list of structures. The list of structures must be allocated by the calling routine. The size of the structure is also passed to `mg_get_server_ports()`.
+
+The function returns the number of items in the list, or a negative value if an error occured.
+
+### See Also
+
+* [~~`mg_get_ports();`~~](mg_get_ports.md)
+* [`struct mg_server_ports;`](mg_server_ports.md)

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/docs/api/mg_get_user_connection_data.md
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/docs/api/mg_get_user_connection_data.md b/thirdparty/civetweb-1.9.1/docs/api/mg_get_user_connection_data.md
new file mode 100644
index 0000000..2e24c13
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/docs/api/mg_get_user_connection_data.md
@@ -0,0 +1,23 @@
+# Civetweb API Reference
+
+### `mg_get_user_connection_data( conn );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`conn`**|`const struct mg_connection *`|The connection for which to return the user data|
+
+### Return Value
+
+| Type | Description | 
+| :--- | :--- |
+|`void *`|A pointer to the user data, or NULL if no user data was registered with the connection|
+
+### Description
+
+The function `mg_get_user_connection_data()` returns the user data associated with a connection. This user data is represented with a pointer which has been prevously registered with a call to [`mg_set_user_connection_data();`](mg_set_user_connection_data.md). With this function it is possible to pass state information between callback functions refering to a specific connection.
+
+### See Also
+
+* [`mg_set_user_connection_data();`](mg_set_user_connection_data.md)

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/docs/api/mg_get_user_data.md
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/docs/api/mg_get_user_data.md b/thirdparty/civetweb-1.9.1/docs/api/mg_get_user_data.md
new file mode 100644
index 0000000..87bbe04
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/docs/api/mg_get_user_data.md
@@ -0,0 +1,23 @@
+# Civetweb API Reference
+
+### `mg_get_user_data( ctx );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`ctx`**|`const struct mg_context *`|The context for which the user data is requested|
+
+### Return Value
+
+| Type | Description |
+| :--- | :--- |
+|`void *`||
+
+### Description
+
+The function `mg_get_user_data()` returns the user data associated with a Civetweb context. This is a pointer value which has previously been used in the call to [`mg_start()`](mg_start.md) to initialize the server context.
+
+### See Also
+
+* [`mg_start();`](mg_start.md)

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/docs/api/mg_get_valid_option_names.md
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/docs/api/mg_get_valid_option_names.md b/thirdparty/civetweb-1.9.1/docs/api/mg_get_valid_option_names.md
new file mode 100644
index 0000000..c6b43ad
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/docs/api/mg_get_valid_option_names.md
@@ -0,0 +1,24 @@
+# Civetweb API Reference
+
+### ~~`mg_get_valid_option_names();`~~
+
+### Parameters
+
+*none*
+
+### Return Value
+
+| Type | Description |
+| :--- | :--- |
+|`const char **`|An array with strings where the even elements represent the option names, and the odd element the option values The array is NULL terminated.|
+
+### Description
+
+The function `mg_get_valid_option_names()` is depricated. Use [`mg_get_valid_options()`](mg_get_valid_options.md) instead.
+
+This function returns an array with option/value pairs describing the valid configuration options for Civetweb. En element value of NULL signals the end of the list.
+
+### See Also
+
+* [`struct mg_option;`](mg_option.md)
+* [`mg_get_valid_options();`](mg_get_valid_options.md)

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/docs/api/mg_get_valid_options.md
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/docs/api/mg_get_valid_options.md b/thirdparty/civetweb-1.9.1/docs/api/mg_get_valid_options.md
new file mode 100644
index 0000000..fd6755e
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/docs/api/mg_get_valid_options.md
@@ -0,0 +1,22 @@
+# Civetweb API Reference
+
+### `mg_get_valid_options();`
+
+### Parameters
+
+*none*
+
+### Return Value
+
+| Type | Description | 
+| :--- | :--- |
+|`const struct mg_option *`|An array with all valid configuration options|
+
+### Description
+
+The function `mg_get_valid_options()` returns an array with all valid configuration options of Civetweb. Each element in the array is a structure with three fields which represent the name of the option, the value of the option and the type of the value. The array is terminated with an element for which the name is `NULL`. See for more details about this structure the documentation of [`struct mg_option`](mg_option.md).
+
+### See Also
+
+* [`struct mg_option;`](mg_option.md)
+* [`mg_start();`](mg_start.md)

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/docs/api/mg_get_var.md
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/docs/api/mg_get_var.md b/thirdparty/civetweb-1.9.1/docs/api/mg_get_var.md
new file mode 100644
index 0000000..c21c7bb
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/docs/api/mg_get_var.md
@@ -0,0 +1,30 @@
+# Civetweb API Reference
+
+### `mg_get_var( data, data_len, var_name, dst, dst_len );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`data`**|`const char *`|Encoded buffer from either POST data or the URI of a GET call|
+|**`data_len`**|`size_t`|Size of the encode buffer including the terminating NULL|
+|**`var_name`**|`const char *`|Name of the variable to search for|
+|**`dst`**|`char *`|Output buffer to store the content of the variable|
+|**`dst_len`**|`size_t`|Length of the output buffer|
+
+### Return Value
+
+| Type | Description |
+| :--- | :--- |
+|`int`|The length of the variable or an error code|
+
+### Description
+
+The function `mg_get_var()` returns the value of a variable which is passed to the server with either a POST method, or as a parameter in the URI of a GET call. The data pointer passed to the function points to a form-URI encoded buffer. This can either be POST data or the `request_info.query_string`. The name of the searched variable and a buffer to store the results are also parameters to the function.
+
+The function either returns the length of the variable when successful, **`-1`** if the variable could not be found and **`-2`** if the destination buffer is NULL, has size zero or is too small to store the resulting variable value.
+
+### See Also
+
+* [`mg_get_cookie();`](mg_get_cookie.md)
+* [`mg_get_var2();`](mg_get_var2.md)

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/docs/api/mg_get_var2.md
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/docs/api/mg_get_var2.md b/thirdparty/civetweb-1.9.1/docs/api/mg_get_var2.md
new file mode 100644
index 0000000..3a47d91
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/docs/api/mg_get_var2.md
@@ -0,0 +1,31 @@
+# Civetweb API Reference
+
+### `mg_get_var2( data, data_len, var_name, dst, dst_len, occurrence );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`data`**|`const char *`|Encoded data buffer from either POST data or a GET URI|
+|**`data_len`**|`size_t`|The size of the encoded data buffer|
+|**`var_name`**|`const char *`|The name of the variable to search for|
+|**`dst`**|`char *`|Destination buffer to store the variable content|
+|**`dst_len`**|`size_t`|The size of the destination buffer including the terminating NUL|
+|**`occurrence`**|`size_t`|The instance index of the wanted variable|
+
+### Return Value
+
+| Type | Description |
+| :--- | :--- |
+|`int`|Length of the variable contents, or an error code|
+
+### Description
+
+The function `mg_get_var2()` can be used to return the contents of a variable passed to the server as either POST data, or in the URI in a GET call. The function is somilar to [`mg_get_var()`](mg_get_var.md) but the difference is that `mg_get_var2()` can be used if the same variable is present multiple times in the data. The `occurence` parameter is used to identify which instance of the variable must be returned where **`0`** is used for the first variable with the specified name, **`1`** for the second and so on.
+
+The function returns the length of the variable content in the return buffer, **`-1`** if a variable with the specified name could not be found and **`-2`** if the pointer to the result buffer is NULL, the size of the result buffer is zero or when the result buffer is too small to contain the variable content and terminating NUL.
+
+### See Also
+
+* [`mg_get_cookie();`](mg_get_cookie.md)
+* [`mg_get_var();`](mg_get_var.md)

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/docs/api/mg_handle_form_request.md
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/docs/api/mg_handle_form_request.md b/thirdparty/civetweb-1.9.1/docs/api/mg_handle_form_request.md
new file mode 100644
index 0000000..4a1d888
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/docs/api/mg_handle_form_request.md
@@ -0,0 +1,24 @@
+# Civetweb API Reference
+
+### `mg_handle_form_request( conn, fdh );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`conn`**|`struct mg_connection *`|The connection on which form data must be processed|
+|**`fdh`**|`struct mg_form_data_handler`|Structure with callback functions to to the heavy work|
+
+### Return Value
+
+| Type | Description |
+| :--- | :--- |
+|`int`|The number of fields processed, or an error code|
+
+### Description
+
+The function `mg_handle_form_request()` processes form data on a connection. The function uses callback functions for the heavy lifting which are passed to the function as fields in a [`struct mg_form_data_handler`](mg_form_data_handler.md) structure. The number of processed fields is returned by the function, or a negative value when an error occured. I nthe situation where some fields are processed successfully (for example file downloads) and an error occurs later in the form processing, the function still returns a negative value. It is the responsibility of the calling party to do the necessary cleanup. The calling party should also do the cleanup of any files which are created, but not required anymore later.
+
+### See Also
+
+* [`struct mg_form_data_handler;`](mg_form_data_handler.md)

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/docs/api/mg_header.md
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/docs/api/mg_header.md b/thirdparty/civetweb-1.9.1/docs/api/mg_header.md
new file mode 100644
index 0000000..403dc88
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/docs/api/mg_header.md
@@ -0,0 +1,18 @@
+# Civetweb API Reference
+
+### `struct mg_header;`
+
+### Fields
+
+| Field | Type | Description |
+| :--- | :--- | :--- |
+|**`name`**|`const char *`| The name of the client request header |
+|**`value`**|`const char *`| The value of the client request header |
+
+### Description
+
+The structure `mg_header` is used as a sub-structure in the [`struct mg_request_info;`](mg_request_info.md) structure to store the name and value of one HTTP request header as sent by the client.
+
+### See Also
+
+* [`struct mg_request_info;`](mg_request_info.md)

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/docs/api/mg_lock_connection.md
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/docs/api/mg_lock_connection.md b/thirdparty/civetweb-1.9.1/docs/api/mg_lock_connection.md
new file mode 100644
index 0000000..167f922
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/docs/api/mg_lock_connection.md
@@ -0,0 +1,26 @@
+# Civetweb API Reference
+
+### `mg_lock_connection( conn );`
+
+### Parameters
+
+| Parameter | Type | Description |
+|**`conn`**|`struct mg_connection *`|The connection to retrieve a lock|
+
+### Return Value
+
+*none*
+
+### Description
+
+The function `mg_lock_connection()` is specifically for websocket connections to lock connection. Using this function in combination with [`mg_unlock_connection();`](mg_unlock_connection.md) is necessary around [`mg_write()`](mg_write.md) and [`mg_printf()`](mg_printf.md) calls if the code has server-initiated communication, as well as with communication in direct response to a message.
+
+### See Also
+
+* [`mg_lock_context();`](mg_lock_context.md)
+* [`mg_printf();`](mg_printf.md)
+* [`mg_unlock_connection();`](mg_unlock_connection.md)
+* [`mg_unlock_context();`](mg_unlock_context.md)
+* [`mg_websocket_client_write();`](mg_websocket_client_write.md)
+* [`mg_websocket_write();`](mg_websocket_write.md)
+* [`mg_write();`](mg_write.md)

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/docs/api/mg_lock_context.md
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/docs/api/mg_lock_context.md b/thirdparty/civetweb-1.9.1/docs/api/mg_lock_context.md
new file mode 100644
index 0000000..8be6bac
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/docs/api/mg_lock_context.md
@@ -0,0 +1,23 @@
+# Civetweb API Reference
+
+### `mg_lock_context( ctx );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`ctx`**|`struct mg_context *`|The context to put the lock on|
+
+### Return Value
+
+*none*
+
+### Description
+
+The function `mg_lock_context()` can be used to acquire a lock for exclusive access to resources which are shared between connection of threads. The lock is context wide. The lock must be released with a call to [`mg_unlock_context()`](mg_unlock_context.md).
+
+### See Also
+
+* [`mg_lock_connection();`](mg_lock_connection.md)
+* [`mg_unlock_connection();`](mg_unlock_connection.md)
+* [`mg_unlock_context();`](mg_unlock_context.md)

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/docs/api/mg_md5.md
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/docs/api/mg_md5.md b/thirdparty/civetweb-1.9.1/docs/api/mg_md5.md
new file mode 100644
index 0000000..067a6a2
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/docs/api/mg_md5.md
@@ -0,0 +1,24 @@
+# Civetweb API Reference
+
+### `mg_md5( buf, ... );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`buf`**|`char[33]`|Storage buffer for the calculated MD5 sum|
+|**`...`**|`char *, ...`|NULL terminated list of pointers to strings with data|
+
+### Return Value
+
+| Type | Description |
+| :--- | :--- |
+|`char *`|Pointer to the resulting MD5 string|
+
+### Description
+
+The function `mg_md5()` caluclates the MD5 checksum of a NULL terminated list of NUL terminated ASCII strings. The MD5 checksum is returned in human readable format as an MD5 string in a caller supplied buffer.
+
+The function returns a pointer to the supplied result buffer.
+
+### See Also

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/docs/api/mg_modify_passwords_file.md
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/docs/api/mg_modify_passwords_file.md b/thirdparty/civetweb-1.9.1/docs/api/mg_modify_passwords_file.md
new file mode 100644
index 0000000..5aa2069
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/docs/api/mg_modify_passwords_file.md
@@ -0,0 +1,28 @@
+# Civetweb API Reference
+
+### `mg_modify_passwords_file( passwords_file_name, domain, user, password );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`passwords_file_name`**|`const char *`|The path to the passwords file|
+|**`domain`**|`const char *`|The domain of the user record|
+|**`user`**|`const char *`|Username of the record to be added, changed or deleted|
+|**`password`**|`const char *`|Password associated with the user or NULL if the record must be deleted|
+
+### Return Value
+
+| Type | Description |
+| :--- | :--- |
+|`int`|Success or error code|
+
+### Description
+
+The function `mg_modify_passwords_file()` allows an application to manipulate .htpasswd files on the fly by adding, deleting and changing user records. This is one of the several ways to implement authentication on the server side.
+
+If the password parameter is not `NULL` an entry is added to the password file. An existing records is modified in that case. If `NULL` is used as the password the enrty is removed from the file.
+
+The function returns 1 when successful and 0 if an error occurs.
+
+### See Also

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/docs/api/mg_option.md
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/docs/api/mg_option.md b/thirdparty/civetweb-1.9.1/docs/api/mg_option.md
new file mode 100644
index 0000000..dd7f090
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/docs/api/mg_option.md
@@ -0,0 +1,31 @@
+# Civetweb API Reference
+
+### `struct mg_option;`
+
+### Fields
+
+| Field | Type | Description |
+| :--- | :--- | :--- |
+|**`name`**|`const char *`|Name of the option|
+|**`type`**|`int`|Type of the option|
+|**`default_value`**|`const char *`|Value of the option|
+
+### Description
+
+A list of valid configuration options of the Civetweb instance can be retrieved with a call to [`mg_get_valid_options()`](mg_get_valid_options.md). This function fills a list of `struct mg_option` structures where the content of each structure represents a configuration option. Each structure contains three fields. One field contains the name of the option, the second contains the value of the option and the third is an identifier used to define the type of the option and how the value contents should be interpreted.
+
+The field `type` can be one of the following values:
+
+|Value|Description|
+| :--- | :--- |
+|**`CONFIG_TYPE_UNKNOWN`**|The type of the option value is unknown|
+|**`CONFIG_TYPE_NUMBER`**|The option value is an integer|
+|**`CONFIG_TYPE_STRING`**|The option value is a number|
+|**`CONFIG_TYPE_FILE`**|The option value is a file name|
+|**`CONFIG_TYPE_DIRECTORY`**|The option value is a directory name|
+|**`CONFIG_TYPE_BOOLEAN`**|The option value is a boolean|
+|**`CONFIG_TYPE_EXT_PATTERN`**|The option value is a list of regular expression patterns|
+
+### See Also
+
+* [`mg_get_valid_options();`](mg_get_valid_options.md)

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/docs/api/mg_printf.md
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/docs/api/mg_printf.md b/thirdparty/civetweb-1.9.1/docs/api/mg_printf.md
new file mode 100644
index 0000000..8beb9c0
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/docs/api/mg_printf.md
@@ -0,0 +1,27 @@
+# Civetweb API Reference
+
+### `mg_printf( conn, fmt, ... );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`conn`**|`struct mg_connection *`|The connection over which the data must be sent|
+|**`fmt`**|`const char *`|Format string|
+|**`...`**|*various*|Parameters as specified in the format string|
+
+### Return Value
+
+| Type | Description |
+| :--- | :--- |
+|`int`|Number of bytes written or an error code|
+
+### Description
+
+The function `mg_printf()` can be used to send formatted strings over a connection. The functionality is comparable to the `printf()` family of functions in the standard C library. The function returns **0** when the connection has been closed, **-1** if an error occurred and otherwise the number of bytes written over the connection. Except for the formatting part, the `mg_printf()` function is identical to the function [`mg_write()`](mg_write.md).
+
+### See Also
+
+* [`mg_websocket_client_write();`](mg_websocket_client_write.md)
+* [`mg_websocket_write();`](mg_websocket_write.md)
+* [`mg_write();`](mg_write.md)

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/docs/api/mg_read.md
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/docs/api/mg_read.md b/thirdparty/civetweb-1.9.1/docs/api/mg_read.md
new file mode 100644
index 0000000..c7ec6c3
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/docs/api/mg_read.md
@@ -0,0 +1,26 @@
+# Civetweb API Reference
+
+### `mg_read( conn, buf, len );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`conn`**|`struct mg_connection *`| A pointer referencing the connection |
+|**`buf`**|`void *`| A pointer to the location where the received data can be stored |
+|**`len`**|`size_t`| The maximum number of bytes to be stored in the buffer |
+
+### Return Value
+
+| Type | Description |
+| :--- | :--- |
+|`int`| The number of read bytes, or a status indication |
+
+### Description
+
+The function `mg_read()` receives data over an existing connection. The data is handled as binary and is stored in a buffer whose address has been provided as a parameter. The function returns the number of read bytes when successful, the value **0** when the connection has been closed by peer and a negative value when no more data could be read from the connection.
+
+### See Also
+
+* [`mg_printf();`](mg_printf.md)
+* [`mg_write();`](mg_write.md)

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/docs/api/mg_request_info.md
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/docs/api/mg_request_info.md b/thirdparty/civetweb-1.9.1/docs/api/mg_request_info.md
new file mode 100644
index 0000000..b0689bf
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/docs/api/mg_request_info.md
@@ -0,0 +1,34 @@
+# Civetweb API Reference
+
+### `struct mg_request_info;`
+
+### Fields
+
+| Field | Type | Description |
+| :--- | :--- | :--- |
+|**`request_method`**|`const char *`| The request method used by the client for the connection this can be **GET**, **POST** or one of the other common HTTP request methods |
+|**`request_uri`**|`const char *`| The absolute or URL-encoded URI as it was sent in the request |
+|**`local_uri`**|`const char *`| The relative URL-encoded URI as it references the local resource. If the request URI does not reference a resource on the local server, this field is NULL |
+|~~`uri`~~|`const char *`| *Deprecated. Use* `local_uri` *instead* |
+|**`http_version`**|`const char *`| The HTTP version as mentioned in the client request. This can be "1.0", "1.1", etc. |
+|**`remote_user`**|`const char *`| The name of the authenticated remote user, or NULL if no authentication was used |
+|**`remote addr`**|`char[48]`| The IP address of the remote client as a string. This can either represent an IPv4 or an IPv6 address. |
+|~~`remote_ip`~~|`long`| *Deprecated. Use* `remote_addr` *instead* |
+|**`content_length`**|`long long`| The content length of the request body. This value can be -1 if no content length was provided. |
+|**`remote_port`**|`int`| The port number at the client's side |
+|**`is_ssl`**|`int`| 1 if the connection is over SSL, and 0 if it is a plain connection |
+|**`user_data`**|`void *`| A pointer to the `user_data` information which was provided as a parameter to `mg_start()`. |
+|**`conn_data`**|`void *`| A pointer to connection specific user data |
+|**`num_headers`**|`int`| The number of HTTP request headers sent by the client |
+|**`http_headers`**|`struct mg_header[64]`| Array of structures with the HTTP request headers sent by the client |
+|**`client_cert`**|`struct client_cert *`| Pointer to the client certificate information, when available |
+
+### Description
+
+The `mg_request_info` structure contains the client information of an existing connection.
+
+### See Also
+
+* [`struct client_cert;`](client_cert.md)
+* [`struct mg_header;`](mg_header.md)
+* [`mg_get_request_info();`](mg_get_request_info.md)

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/docs/api/mg_send_file.md
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/docs/api/mg_send_file.md b/thirdparty/civetweb-1.9.1/docs/api/mg_send_file.md
new file mode 100644
index 0000000..bffe075
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/docs/api/mg_send_file.md
@@ -0,0 +1,25 @@
+# Civetweb API Reference
+
+### `mg_send_file( conn, path );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`conn`**|`struct mg_connection *`|The connection over which the file must be sent|
+|**`path`**|`const char *`|The full path and filename of the file|
+
+### Return Value
+
+*none*
+
+### Description
+
+The function `mg_send_file()` sends the contents of a file over a connection to the remote peer. The function also adds the necessary HTTP headers.
+
+### See Also
+
+* [`mg_printf();`](mg_printf.md)
+* [`mg_send_mime_file();`](mg_send_mime_file.md)
+* [`mg_send_mime_file2();`](mg_send_mime_file2.md)
+* [`mg_write();`](mg_write.md)

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/docs/api/mg_send_mime_file.md
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/docs/api/mg_send_mime_file.md b/thirdparty/civetweb-1.9.1/docs/api/mg_send_mime_file.md
new file mode 100644
index 0000000..424b0dc
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/docs/api/mg_send_mime_file.md
@@ -0,0 +1,27 @@
+# Civetweb API Reference
+
+### `mg_send_mime_file( conn, path, mime_type );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`conn`**|`struct mg_connection *`|The connection over which the file must be sent|
+|**`path`**|`const char *`|The full path and filename of the file|
+|**`mime_type`**|`const char *`|The mime type of the file, or NULL for automatic detection|
+
+### Return Value
+
+*none*
+
+### Description
+
+The function `mg_send_mime_file()` sends a file over a connection including the HTTP headers. The function is similar to the [`mg_send_file()`](mg_send_file.md) with the additional functionality that the MIME type of the file can be specified. If the `mime_type` parameter is NULL, the routine will try to determine the MIME type based on the extension of the filename.
+
+### See Also
+
+* [`mg_get_builtin_mime_type();`](mg_get_builtin_mime_type.md)
+* [`mg_printf();`](mg_printf.md)
+* [`mg_send_file();`](mg_send_file.md)
+* [`mg_send_mime_file2();`](mg_send_mime_file2.md)
+* [`mg_write();`](mg_write.md)

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/docs/api/mg_send_mime_file2.md
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/docs/api/mg_send_mime_file2.md b/thirdparty/civetweb-1.9.1/docs/api/mg_send_mime_file2.md
new file mode 100644
index 0000000..1350df8
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/docs/api/mg_send_mime_file2.md
@@ -0,0 +1,30 @@
+# Civetweb API Reference
+
+### `mg_send_mime_file2( conn, path, mime_type, additional_headers );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`conn`**|`struct mg_connection *`|The connection over which the file must be sent|
+|**`path`**|`const char *`|The full path and filename of the file|
+|**`mime_type`**|`const char *`|The mime type or NULL for automatic detection|
+|**`additional_headers`**|`const char *`|Additional headers to be sent|
+
+### Return Value
+
+*none*
+
+### Description
+
+The function `mg_send_mime_file2()` can be used to send a file over a connection. The function is similar to [`mg_send_mime_file()`](mg_send_mime_file.md) with the additional functionality that user specified headers can be sent. The MIME type of the file can be specified in the function call, or will be automatically determined based on the extension of the filename if the `mime_type` parameter has the value NULL.
+
+Additional custom header fields can be added as a parameter. Please make sure that these header names begin with `X-` to prevent name clashes with other headers. If the `additional_headers` parameter is NULL, no custom headers will be added.
+
+### See Also
+
+* [`mg_get_builtin_mime_type();`](mg_get_builtin_mime_type.md)
+* [`mg_printf();`](mg_printf.md)
+* [`mg_send_file();`](mg_send_file.md)
+* [`mg_send_mime_file();`](mg_send_mime_file.md)
+* [`mg_write();`](mg_write.md)

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/docs/api/mg_server_ports.md
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/docs/api/mg_server_ports.md b/thirdparty/civetweb-1.9.1/docs/api/mg_server_ports.md
new file mode 100644
index 0000000..e969f03
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/docs/api/mg_server_ports.md
@@ -0,0 +1,24 @@
+# Civetweb API Reference
+
+### `struct mg_server_ports;`
+
+### Fields
+
+| Field | Type | Description |
+| :--- | :--- | :--- |
+|**`protocol`**|`int`|The protocol mask where `IPv4` is **1**, `IPv6` is **2** and both `IPv4` and `IPv6` is **3**|
+|**`port`**|`int`|The port number on which the service listens|
+|**`is_ssl`**|`int`|**0** for `HTTP` communication, **1** for `HTTPS`|
+|**`is_redirect`**|`int`|**1** if all requests are redirected, otherwise **0**|
+|**`_reserved1`**|`int`|Reserved for internal use|
+|**`_reserved2`**|`int`|Reserved for internal use|
+|**`_reserved3`**|`int`|Reserved for internal use|
+|**`_reserved4`**|`int`|Reserved for internal use|
+
+### Description
+
+A call to the function [`mg_get_server_ports()`](mg_get_server_ports.md) returns a list of structures with information about each running Civetweb service. These structures are of type `struct mg_server_ports` and contain the base information of each service.
+
+### See Also
+
+* [`mg_get_server_ports();`](mg_get_server_ports.md)

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/docs/api/mg_set_auth_handler.md
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/docs/api/mg_set_auth_handler.md b/thirdparty/civetweb-1.9.1/docs/api/mg_set_auth_handler.md
new file mode 100644
index 0000000..302324a
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/docs/api/mg_set_auth_handler.md
@@ -0,0 +1,30 @@
+# Civetweb API Reference
+
+### `mg_set_auth_handler( ctx, uri, handler, cbdata );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`ctx`**|`struct mg_context *`|The context on which the handler must be set|
+|**`uri`**|`const char *`|The URI for the authorization handler|
+|**`handler`**|`mg_authorization_handler`|Callback function doing the actual authorization|
+|**`cbdata`**|`void *`|Optional user data|
+
+`int mg_authorization_handler( struct mg_connection *conn, void *cbdata );`
+
+### Return Value
+
+*none*
+
+### Description
+
+The function `mg_set_auth_handler()` hooks an authorization function to an URI to check if a user is authorized to visit that URI. The check is performed by a callback function of type `mg_authorization_handler`. The callback function is passed two parameters: the current connection and a pointer to optional user defined data which was passed to `mg_set_auth_handler()` when the callback was hooked to the URI.
+
+The callback function can return **0** to deny access, and **1** to allow access.
+
+The `mg_set_auth_handler()` function is very similar in use to [`mg_set_request_handler()`](mg_set_request_handler.md).
+
+### See Also
+
+* [`mg_set_request_handler();`](mg_set_request_handler.md)

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/docs/api/mg_set_request_handler.md
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/docs/api/mg_set_request_handler.md b/thirdparty/civetweb-1.9.1/docs/api/mg_set_request_handler.md
new file mode 100644
index 0000000..95a09a0
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/docs/api/mg_set_request_handler.md
@@ -0,0 +1,26 @@
+# Civetweb API Reference
+
+### `mg_set_request_handler( ctx, uri, handler, cbdata );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`ctx`**|`struct mg_context *`|The context where the handler must be active|
+|**`uri`**|`const char *`|The URI to hook the handler on|
+|**`handler`**|`mg_request_handler`|Callback function doing the heavy lifting|
+|**`cbdata`**|`void *`|Optional user supplied data|
+
+`int mg_request_handler( struct mg_connection *conn, void *cbdata );`
+
+### Return Value
+
+*none*
+
+### Description
+
+The function `mg_set_request_handler()` hooks a callback function on a URI. That callback function is called whenever a client requests the specific URI. The callback function receives the connection information and optional user supplied data as parameters and can serve information back to the client. When the callback function does not send any information back to the client, it should return **0** to signal Civetweb that the Civetweb core should handle the request. A return value between 1 and 999 is used to tell Civetweb that the request has been handled and no further processing is necessary. The returned code is stored as the status code in the access log, it is therefore recommended, although not mandatory to return a status code which matches the state of the request.
+
+### See Also
+
+* [`mg_set_auth_handler();`](mg_set_auth_handler.md)

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/docs/api/mg_set_user_connection_data.md
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/docs/api/mg_set_user_connection_data.md b/thirdparty/civetweb-1.9.1/docs/api/mg_set_user_connection_data.md
new file mode 100644
index 0000000..dad69b8
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/docs/api/mg_set_user_connection_data.md
@@ -0,0 +1,22 @@
+# Civetweb API Reference
+
+### `mg_set_user_connection_data( conn, data );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`conn`**|`struct mg_connection *`|connection to add the user data|
+|**`data`**|`void *`|Pointer to the user data|
+
+### Return Value
+
+*none*
+
+### Description
+
+The function `mg_set_user_connection_data()` can be used to add or change the user data pointer attached to a connection. Using the value NULL in the call will remove a previously assigned user data pointer.
+
+### See Also
+
+* [`mg_get_user_connection_data();`](mg_user_connection_data.md)

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/docs/api/mg_set_websocket_handler.md
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/docs/api/mg_set_websocket_handler.md b/thirdparty/civetweb-1.9.1/docs/api/mg_set_websocket_handler.md
new file mode 100644
index 0000000..f838c81
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/docs/api/mg_set_websocket_handler.md
@@ -0,0 +1,30 @@
+# Civetweb API Reference
+
+### `mg_set_websocket_handler( ctx, uri, connect_handler, ready_handler, data_handler, close_handler, cbdata );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`ctx`**|`mg_context *`|The context in which to add the handlers|
+|**`uri`**|`const char *`|The URI for which the handlers should be activated|
+|**`connect_handler`**|`mg_websocket_connect_handler`|Handler called when a connect is signalled|
+|**`ready_handler`**|`mg_websocket_ready_handler`|Handler called when the connection is ready|
+|**`data_handler`**|`mg_websocket_data_handler`|Handler called when data is received|
+|**`close_handler`**|`mg_websocket_close_handler`|Handler called when the connection closes|
+|**`cbdata`**|`void *`|User defined data|
+
+`int mg_websocket_connect_handler( const struct mg_connection *conn, void *cbdata );`
+`int mg_websocket_ready_handler( struct mg_connection *conn, void *cbdata );`
+`int mg_websocket_data_handler( struct mg_connection *conn, int opcode, char * buf, size_t buf_len, void *cbdata );`
+`int mg_websocket_close_handler( const struct mg_connection *conn,  void *cbdata );`
+
+### Return Value
+
+*none*
+
+### Description
+
+The function `mg_set_websocket_handler()` connects callback functions to a websocket URI. The callback functions are called when a state change is detected on the URI like an incomming connection or data received from a remote peer.
+
+### See Also

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/docs/api/mg_start.md
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/docs/api/mg_start.md b/thirdparty/civetweb-1.9.1/docs/api/mg_start.md
new file mode 100644
index 0000000..c597d55
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/docs/api/mg_start.md
@@ -0,0 +1,39 @@
+# Civetweb API Reference
+
+### `mg_start( callbacks, user_data, options );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`callbacks`**|`const struct mg_callbacks *`| A structure with optional callback functions to process requests from the web server |
+|**`user_data`**|`void *`| A pointer to optional user data |
+|**`options`**|`char **`| A list of options used to initialize the web server. The list consists of an NULL terminated list of option-value string pairs. |
+
+The option list can be used to set the following options:
+
+| Option | Default | Description |
+| :--- | :--- | :--- |
+| **`cgi_environment`** | *empty* | The option `cgi_environment` can contain extra variables to be passed to the CGI script in addition to the standard environment variables. The lust must be a comma separated list of name=value pairs like this: `VARIABLE1=VALUE1,VARIABLE2=VALUE2`.|
+| **`cgi_interpreter`**| *empty* | The option `cgi_interpreter` can contain a path to an executable which will be used as a CGI interpreter for **all** CGI scripts regardless of the script file extension. If this option is not set (which is the default), CivetWeb looks at the first line of a CGI script to see if an interpreter is defined there. This first line is formatted as a shebang line as common in unix style shell scripts, but this will also work in Windows. For more information about the syntax, please see the Wikipedia page about the [shebang line](http://en.wikipedia.org/wiki/Shebang_(Unix\)).|
+| | |For example on a Windows system where both PHP and Perl CGI scripts are used, `#!/path/to/php-cgi.exe` and `#!/path/to/perl.exe` must be the first line of the respective CGI scripts. Note that the paths should be either full file paths, or file paths relative to the current working directory of the CivetWeb server. The current working directory may be dependent on the way the application is started. When started from the command line it is the directory from where the executable was called, but when starting it from a shortcut in a graphical desktop environment, it will be the directory where the executable is located, the default directory of the user or a directory mentioned in the shortcut, depending on the operating system and graphical user interface used.|
+| | |If all CGIs use the same interpreter, it is more efficient to set the option `cgi_interpreter` to the path to that executable because in that case no processing of the shebang line is necessary. When using PHP, be sure to point tot php-cgi(.exe) and not the php(.exe) executable, as the latter is a stand alone interpreter which doesn't interface over CGI with CivetWeb.
+| **`cgi_pattern`** | `**.cgi$|**.pl$|**.php$` | All files that match `cgi_pattern` are treated as CGI files. The default pattern allows CGI files to be anywhere. To restrict CGIs to a certain directory, use `/path/to/cgi-bin/**.cgi` as a pattern. Note that the full path of the local file is matched against the pattern, not the URI provided in the client request.|
+|**`put_delete_auth_file`**| *empty* | The option `put_delete_auth_file` defines the password file to be used for PUT and DELETE requests. Without a password file it is not possible to put new files to the server, or to delete existing ones. This only applies to direct HTTP requests which use the PUT and DELETE methods without server side scripting. PUT and DELETE requests might still be handled by Lua scripts and CGI pages. |
+
+### Return Value
+
+| Type | Description |
+| :--- | :--- |
+|`struct mg_context *`| A pointer to a context structure when successful, or NULL in case of failure |
+
+### Description
+
+The function `mg_start()` is the only function needed to call to initialize the webserver. After the function returns and a pointer to a context structure is provided, it is guaranteed that the server has started and is listening on the designated ports. In case of failure a NULL pointer is returned.  The behaviour of the web server is controlled by a list of callback functions and a list of options.  The callback functions can do application specific processing of events which are encountered by the webserver. If a specific callback function is set to NULL, the webserver uses their default callback routine. The options list controls how the webserver should be started and contains settings for for example the ports to listen on, the maximum number of threads created to handle requests in parallel and if settings for SSL encryption.
+
+As a side effect on Unix systems, SIGCHLD and SIGPIPE signals will be ignored. If custom processing is needed for these signals, signal handlers must be setup after the call to `mg_start()` has completed.
+
+### See Also
+
+* [`struct mg_callbacks;`](mg_callbacks.md)
+* [`mg_stop();`](mg_stop.md)

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/docs/api/mg_start_thread.md
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/docs/api/mg_start_thread.md b/thirdparty/civetweb-1.9.1/docs/api/mg_start_thread.md
new file mode 100644
index 0000000..e817226
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/docs/api/mg_start_thread.md
@@ -0,0 +1,26 @@
+# Civetweb API Reference
+
+### `mg_start_thread( func, cbdata );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`func`**|`mg_thread_func_t`|Function to start as a separate thread|
+|**`cbdata`**|`void *`|User defined data to be passed to the thread as parameter|
+
+`void mg_thread_func_t( void *cbdata );`
+
+### Return Value
+
+| Type | Description |
+| :--- | :--- |
+|`int`|Success or error code|
+
+### Description
+
+The function `mg_start_thread()` is a convenience function to create a detached thread. The function returns **0** when successful and another value if an error occured. A pointer to user supplied data can be passed which is then passed further on to the thread function as parameter.
+
+### See Also
+
+* [`mg_start();`](mg_start.md)

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/docs/api/mg_stop.md
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/docs/api/mg_stop.md b/thirdparty/civetweb-1.9.1/docs/api/mg_stop.md
new file mode 100644
index 0000000..ea0d246
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/docs/api/mg_stop.md
@@ -0,0 +1,22 @@
+# Civetweb API Reference
+
+### `mg_stop( ctx );`
+
+#### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`ctx`**|**`struct mg_context *`**| A pointer to the current webserver context |
+
+### Return Value
+
+*none*
+
+### Description
+
+The function `mg_stop()` is used to stop and cleanup a running webserver. A pointer to the context of the running webserver is provided as a parameter. The execution of this function may take some time because it waits until all threads have stopped and returns all memory to the heap. After the function returns, the location the context pointer points to is invalid. The function does not return a return value and it is therefore not possible to know if stopping the webserver succeeded or not.
+
+### See Also
+
+* [`mg_start();`](mg_start.md)
+* [`mg_start_thread();`](mg_start_thread.md)

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/docs/api/mg_store_body.md
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/docs/api/mg_store_body.md b/thirdparty/civetweb-1.9.1/docs/api/mg_store_body.md
new file mode 100644
index 0000000..4cde44a
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/docs/api/mg_store_body.md
@@ -0,0 +1,24 @@
+# Civetweb API Reference
+
+### `mg_store_body( conn, path );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`conn`**|`struct mg_connection *`|connection on which to read the data|
+|**`path`**|`const char *`|file to store the request body|
+
+### Return Value
+
+| Type | Description |
+| :--- | :--- |
+|`long long`|Number of bytes written to the file, or an error code|
+
+### Description
+
+The function `mg_store_body()` stores the body of an incoming request to a data file. The function returns the number of bytes stored in the file, or a negative value to indicate an error.
+
+### See Also
+
+* [`mg_read();`](mg_read.md)

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/docs/api/mg_strcasecmp.md
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/docs/api/mg_strcasecmp.md b/thirdparty/civetweb-1.9.1/docs/api/mg_strcasecmp.md
new file mode 100644
index 0000000..cba6b92
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/docs/api/mg_strcasecmp.md
@@ -0,0 +1,24 @@
+# Civetweb API Reference
+
+### `mg_strcasecmp( s1, s2 );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`s1`**|`const char *`|First string to compare|
+|**`s2`**|`const char *`|Second string to compare|
+
+### Return Value
+
+| Type | Description |
+| :--- | :--- |
+|`int`|Integer value with the result of the comparison|
+
+### Description
+
+The function `mg_strcasecmp()` is a helper function to compare two strings. The comparison is case insensitive. The return value is **0** if both strings are equal, less then zero if the first string is less than the second in a lexical comparison, and greater than zero if the first string is greater than the second.
+
+### See Also
+
+* [`mg_strncasecmp();`](mg_strncasecmp.md)

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/docs/api/mg_strncasecmp.md
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/docs/api/mg_strncasecmp.md b/thirdparty/civetweb-1.9.1/docs/api/mg_strncasecmp.md
new file mode 100644
index 0000000..b4affd6
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/docs/api/mg_strncasecmp.md
@@ -0,0 +1,25 @@
+# Civetweb API Reference
+
+### `mg_strncasecmp( s1, s2, len );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`s1`**|`const char *`|First string in the comparison|
+|**`s2`**|`const char *`|Second string in the comparison|
+|**`len`**|`size_t`|The maximum number of characters to compare|
+
+### Return Value
+
+| Type | Description |
+| :--- | :--- |
+|`int`|The result of the comparison|
+
+### Description
+
+The function `mg_strncasecmp()` is a helper function to compare two strings. The comparison is case insensitive and only a limited number of characters are compared. This limit is provided as third parameter in the function call. The return value is **0** if both strings are equal, less then zero if the first string is less than the second in a lexical comparison, and greater than zero if the first string is greater than the second.
+
+### See Also
+
+* [`mg_strcasecmp();`](mg_strcasecmp.md)

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/docs/api/mg_unlock_connection.md
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/docs/api/mg_unlock_connection.md b/thirdparty/civetweb-1.9.1/docs/api/mg_unlock_connection.md
new file mode 100644
index 0000000..b74138f
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/docs/api/mg_unlock_connection.md
@@ -0,0 +1,27 @@
+# Civetweb API Reference
+
+### `mg_unlock_connection( conn );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`conn`**|`struct mg_connection *`|Connection to remove the lock from|
+
+### Return Value
+
+*none*
+
+### Description
+
+The function `mg_unlock_connection()` removes the lock on a connection which was previously set with a call to [`mg_lock_connection()`](mg_lock_connection.md). Locking may be necessary when using [`mg_write()`](mg_write.md) or [`mg_printf()`](mg_printf.md) on websocket connections to prevent data corruption.
+
+### See Also
+
+* [`mg_lock_connection();`](mg_lock_connection.md)
+* [`mg_lock_context();`](mg_lock_context.md)
+* [`mg_printf();`](mg_printf.md)
+* [`mg_unlock_context();`](mg_unlock_context.md)
+* [`mg_websocket_client_write();`](mg_websocket_client_write.md)
+* [`mg_websocket_write();`](mg_websocket_write.md)
+* [`mg_write();`](mg_write.md)

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/docs/api/mg_unlock_context.md
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/docs/api/mg_unlock_context.md b/thirdparty/civetweb-1.9.1/docs/api/mg_unlock_context.md
new file mode 100644
index 0000000..a630acd
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/docs/api/mg_unlock_context.md
@@ -0,0 +1,23 @@
+# Civetweb API Reference
+
+### `mg_unlock_context( ctx );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`ctx`**|`struct mg_context *`|The context to remove the lock from|
+
+### Return Value
+
+*none*
+
+### Description
+
+The function `mg_unlock_contect()` removes a lock put previously on a context with a call to [`mg_lock_context()`](mg_lock_context.md). Locking a context may be necessary when accessing shared resources.
+
+### See Also
+
+* [`mg_lock_connection();`](mg_lock_connection.md)
+* [`mg_lock_context();`](mg_lock_context.md)
+* [`mg_unlock_connection();`](mg_unlock_connection.md)

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/docs/api/mg_upload.md
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/docs/api/mg_upload.md b/thirdparty/civetweb-1.9.1/docs/api/mg_upload.md
new file mode 100644
index 0000000..de7f1c8
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/docs/api/mg_upload.md
@@ -0,0 +1,22 @@
+# Civetweb API Reference
+
+### ~~`mg_upload( conn, destination_dir );`~~
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`conn`**|`struct mg_connection *`|Connection on which files to upload|
+|**`destination_dir`**|`const char *`|The destination directory to upload to|
+
+### Return Value
+
+| Type | Description |
+| :--- | :--- |
+|`int`|Success or error code|
+
+### Description
+
+The function `mg_upload()` is deprecated and may be removed from future releases. Use of this function is therefore highly discouraged.
+
+### See Also

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/docs/api/mg_url_decode.md
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/docs/api/mg_url_decode.md b/thirdparty/civetweb-1.9.1/docs/api/mg_url_decode.md
new file mode 100644
index 0000000..6794088
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/docs/api/mg_url_decode.md
@@ -0,0 +1,27 @@
+# Civetweb API Reference
+
+### `mg_url_decode( src, src_len, dst, dst_len, is_form_url_encoded );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`src`**|`const char *`|Source data to convert|
+|**`src_len`**|`int`|Length of the source buffer|
+|**`dst`**|`char *`|Destination buffer to store the result|
+|**`dst_len`**|`int`|Length of the destination buffer|
+|**`is_form_url_encoded`**|`int`|Not equal zero when form decoding must be used|
+
+### Return Value
+
+| Type | Description |
+| :--- | :--- |
+|`int`|The number of bytes stored in the destination buffer, or **-1** if the buffer doesn't exist or is too small|
+
+### Description
+
+The function `mg_url_decode()` Decodes a in input buffer. Both normal URIs and form URIs can be decoded. In the latter case the space character is converted to a `+` as defined in [RFC 1866](http://ftp.ics.uci.edu/pub/ietf/html/rfc1866.txt) in section 8.2.1.
+
+### See Also
+
+* [`mg_url_encode();`](mg_url_encode.md)

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/docs/api/mg_url_encode.md
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/docs/api/mg_url_encode.md b/thirdparty/civetweb-1.9.1/docs/api/mg_url_encode.md
new file mode 100644
index 0000000..465af12
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/docs/api/mg_url_encode.md
@@ -0,0 +1,25 @@
+# Civetweb API Reference
+
+### `mg_url_encode( src, dst, des_len );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`src`**|`const char *`|Input string to encode|
+|**`dst`**|`char *`|Destination buffer to store the encoded result|
+|**`dst_len`**|`size_t`|Length of the destination buffer including the terminating NUL|
+
+### Return Value
+
+| Type | Description |
+| :--- | :--- |
+|`int`|The number of characters written in the destination buffer|
+
+### Description
+
+The function `mg_url_encode()` encodes a in input buffer. Both normal URIs and form URIs can be encoded. In the latter case the space character is converted to a `+` as defined in [RFC 1866](http://ftp.ics.uci.edu/pub/ietf/html/rfc1866.txt) in section 8.2.1.
+
+### See Also
+
+* [`mg_url_decode();`](mg_url_decode.md)

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/docs/api/mg_version.md
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/docs/api/mg_version.md b/thirdparty/civetweb-1.9.1/docs/api/mg_version.md
new file mode 100644
index 0000000..a31128b
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/docs/api/mg_version.md
@@ -0,0 +1,19 @@
+# Civetweb API Reference
+
+### `mg_version();`
+
+### Parameters
+
+*none*
+
+### Return Value
+
+| Type | Description |
+| :--- | :--- |
+|`const char *`| A pointer to a text with the current CivetWeb version |
+
+### Description
+
+The function `mg_version()` can be used to return the current CivetWeb version.  The function returns a pointer to a string with the current major and minor version number separated with a dot, for example "1.9".
+
+### See Also

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/docs/api/mg_websocket_client_write.md
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/docs/api/mg_websocket_client_write.md b/thirdparty/civetweb-1.9.1/docs/api/mg_websocket_client_write.md
new file mode 100644
index 0000000..f792f4c
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/docs/api/mg_websocket_client_write.md
@@ -0,0 +1,32 @@
+# Civetweb API Reference
+
+### `mg_websocket_client_write( conn, opcode, data, data_len );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`conn`**|`struct mg_connection *`|Connection on which to send data|
+|**`opcode`**|`int`|Opcode|
+|**`data const`**|`char *`|The data to be written|
+|**`data_len`**|`size_t`|Length of the data buffer|
+
+### Return Value
+
+| Type | Description |
+| :--- | :--- |
+|`int`|Number of bytes written or an error code|
+
+### Description
+
+The function `mg_websocket_client_write()` sends data to a websocket server wrapped in a masked websocket frame. The function issues calls to [`mg_lock_connection()`](mg_lock_connection.md) and [`mg_unlock_connection()`](mg_unlock_connection.md) to ensure that the transmission is not interrupted. Interruption can happen the the application is proactively communicating and responding to a request simultaneously. This function is available only, if Civetweb is compiled with the option `-DUSE_WEBSOCKET`.
+
+The return value is the number of bytes written on success, **0** when the connection has been closed and **-1** if an error occured.
+
+### See Also
+
+* [`mg_lock_connection();`](mg_lock_connection.md)
+* [`mg_printf();`](mg_printf.md)
+* [`mg_unlock_connection();`](mg_unlock_connection.md)
+* [`mg_websocket_write();`](mg_websocket_write.md)
+* [`mg_write();`](mg_write.md)

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/docs/api/mg_websocket_write.md
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/docs/api/mg_websocket_write.md b/thirdparty/civetweb-1.9.1/docs/api/mg_websocket_write.md
new file mode 100644
index 0000000..764eebd
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/docs/api/mg_websocket_write.md
@@ -0,0 +1,34 @@
+# Civetweb API Reference
+
+### `mg_websocket_write( conn, opcode, data, data_len );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`conn`**|`struct mg_connection *`|Connection on which the data must be written|
+|**`opcode`**|`int`|Opcode|
+|**`data`**|`const char *`|Data to be written to the client|
+|**`data_len`**|`size_t`|Length of the data|
+
+### Return Value
+
+| Type | Description |
+| :--- | :--- |
+|`int`|Number of bytes written or an error code|
+
+### Description
+
+The function `mg_websocket_write()` sends data to a websocket client wrapped in a websocket frame. The function issues calls to [`mg_lock_connection()`](mg_lock_connection.md) and [`mg_unlock_connaction()`](mg_unlock_connection.md) to ensure that the transmission is not interrupted. Data corruption can otherwise happn if the application is proactively communicating and responding to a request simultaneously.
+
+The function is available only when Civetweb is compilet with the `-DUSE_WEBSOCKET` option.
+
+The function returns the number of bytes written, **0** when the connection has been closed and **-1** if an error occured.
+
+### See Also
+
+* [`mg_lock_connection();`](mg_lock_connection.md)
+* [`mg_printf();`](mg_printf.md)
+* [`mg_unlock_connection();`](mg_unlock_connection.md)
+* [`mg_websocket_client_write();`](mg_websocket_client_write.md)
+* [`mg_write();`](mg_write.md)

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/docs/api/mg_write.md
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/docs/api/mg_write.md b/thirdparty/civetweb-1.9.1/docs/api/mg_write.md
new file mode 100644
index 0000000..d501857
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/docs/api/mg_write.md
@@ -0,0 +1,29 @@
+# Civetweb API Reference
+
+### `mg_write( conn, buf, len );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`conn`**|`struct mg_connection *`| A pointer to the connection to be used to send data |
+|**`buf`**|`const void *`| A pointer to the blob of information to be sent |
+|**`len`**|`size_t`| The amount of bytes to be sent |
+
+### Return Value
+
+| Type | Description |
+| :--- | :--- |
+|`int`| An integer indicating the amount of bytes sent, or failure |
+
+### Description
+
+The function `mg_write()` can be used to send a blob of arbitrary data over a connection. The size of the data is provided as a parameter. The only length limitation on this function is `MAX_INT`, because the return value of this function will turn negative with larger blocks of data, although they may have been sent correctly. The function returns the amount of bytes sent in case of success, the value **0** when the connection has been closed, and **-1** in case of an error.
+
+### See Also
+
+* [`mg_lock_connection();`](mg_lock_connection.md)
+* [`mg_printf();`](mg_print.md)
+* [`mg_unlock_connection();`](mg_unlock_connection.md)
+* [`mg_websocket_client_write();`](mg_websocket_client_write.md)
+* [`mg_websocket_write();`](mg_websocket_write.md)

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/docs/yaSSL.md
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/docs/yaSSL.md b/thirdparty/civetweb-1.9.1/docs/yaSSL.md
new file mode 100644
index 0000000..7f2e85f
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/docs/yaSSL.md
@@ -0,0 +1,87 @@
+Adding wolfSSL (formerly CyaSSL) support
+=====
+
+In order to support SSL *HTTPS* connections in Civetweb,
+you may wish to use the GPLv2 licensed CyaSSL library.  By using this
+library, the resulting binary may have to have the GPL license unless
+you buy a commercial license from [wolfSSL](http://www.yassl.com/).
+
+*Note: The following instructions have not been checked for the most recent versions of CivetWeb and wolfSSL. Some information might be outdated.*
+
+
+Getting Started
+----
+
+- Download Cayssl at https://www.wolfssl.com (formerly http://www.yassl.com/)
+- Extract the zip file
+    - To make this seemless, extract to a directory parallel to with Civetweb is
+
+### Example Project
+
+If you download cyaSSL to cyassl-2.7.0 in a directory parallel to Civetweb, you can open the *VS/civetweb_yassl* solution in Visual Studio.
+
+Build Configuration
+----
+
+#### Required include paths for both civetweb and cyassl
+ - *cyassl_directory*\
+ - *cyassl_directory*\cyassl\
+
+#### Required civetweb preprocessor defines
+ - USE_YASSL
+ - NO_SSL_DL
+
+#### Required cySSL preprocessor defines
+ - OPENSSL_EXTRA
+ - HAVE_ERRNO_H
+ - HAVE_GETHOSTBYNAME
+ - HAVE_INET_NTOA
+ - HAVE_LIMITS_H
+ - HAVE_MEMSET
+ - HAVE_SOCKET
+ - HAVE_STDDEF_H
+ - HAVE_STDLIB_H
+ - HAVE_STRING_H
+ - HAVE_SYS_STAT_H
+ - HAVE_SYS_TYPES_H
+
+#### Required CyaSSL source files
+
+ - ctaocrypt/src/aes.c
+ - ctaocrypt/src/arc4.c
+ - ctaocrypt/src/asn.c
+ - ctaocrypt/src/coding.c
+ - ctaocrypt/src/des3.c
+ - ctaocrypt/src/dh.c
+ - ctaocrypt/src/dsa.c
+ - ctaocrypt/src/ecc.c
+ - ctaocrypt/src/error.c
+ - ctaocrypt/src/hc128.c
+ - ctaocrypt/src/hmac.c
+ - ctaocrypt/src/integer.c
+ - ctaocrypt/src/logging.c
+ - ctaocrypt/src/md2.c
+ - ctaocrypt/src/md4.c
+ - ctaocrypt/src/md5.c
+ - ctaocrypt/src/memory.c
+ - ctaocrypt/src/misc.c
+ - ctaocrypt/src/pwdbased.c
+ - ctaocrypt/src/rabbit.c
+ - ctaocrypt/src/random.c
+ - ctaocrypt/src/ripemd.c
+ - ctaocrypt/src/rsa.c
+ - ctaocrypt/src/sha.c
+ - ctaocrypt/src/sha256.c
+ - ctaocrypt/src/sha512.c
+ - ctaocrypt/src/tfm.c
+ - src/crl.c
+ - src/internal.c
+ - src/io.c
+ - src/keys.c
+ - src/ocsp.c
+ - src/sniffer.c
+ - src/ssl.c
+ - src/tls.c
+
+
+

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/examples/README.md
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/examples/README.md b/thirdparty/civetweb-1.9.1/examples/README.md
new file mode 100644
index 0000000..523c52c
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/examples/README.md
@@ -0,0 +1,8 @@
+
+Examples
+=====
+
+These examples show how to embed civetweb into a C ([embedded_c](https://github.com/civetweb/civetweb/tree/master/examples/embedded_c)) or a C++ ([embedded_cpp](https://github.com/civetweb/civetweb/tree/master/examples/embedded_cpp)) application.
+The C++ wrapper only offers a subset of the full C API, thus the C example is more complete than the C++ example.
+
+Some no longer maintained examples can be found in the ["obsolete"](https://github.com/civetweb/civetweb/tree/master/examples/_obsolete) folder. It is not guaranteed that they work in the current version - they are kept for reference, but might be removed in the future.


[39/51] [partial] nifi-minifi-cpp git commit: MINIFI-183 Added civet 1.9.1 sources Added onScheduled hook Added initial two-way TLS-enabled ListenHTTP implementation

Posted by al...@apache.org.
http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/CivetServer.cpp
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/CivetServer.cpp b/thirdparty/civetweb-1.9.1/src/CivetServer.cpp
new file mode 100644
index 0000000..d4aaea4
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/CivetServer.cpp
@@ -0,0 +1,594 @@
+/* Copyright (c) 2013-2017 the Civetweb developers
+ * Copyright (c) 2013 No Face Press, LLC
+ *
+ * License http://opensource.org/licenses/mit-license.php MIT License
+ */
+
+#include "CivetServer.h"
+
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+#include <stdexcept>
+
+#ifndef UNUSED_PARAMETER
+#define UNUSED_PARAMETER(x) (void)(x)
+#endif
+
+bool
+CivetHandler::handleGet(CivetServer *server, struct mg_connection *conn)
+{
+	UNUSED_PARAMETER(server);
+	UNUSED_PARAMETER(conn);
+	return false;
+}
+
+bool
+CivetHandler::handlePost(CivetServer *server, struct mg_connection *conn)
+{
+	UNUSED_PARAMETER(server);
+	UNUSED_PARAMETER(conn);
+	return false;
+}
+
+bool
+CivetHandler::handleHead(CivetServer *server, struct mg_connection *conn)
+{
+	UNUSED_PARAMETER(server);
+	UNUSED_PARAMETER(conn);
+	return false;
+}
+
+bool
+CivetHandler::handlePut(CivetServer *server, struct mg_connection *conn)
+{
+	UNUSED_PARAMETER(server);
+	UNUSED_PARAMETER(conn);
+	return false;
+}
+
+bool
+CivetHandler::handlePatch(CivetServer *server, struct mg_connection *conn)
+{
+	UNUSED_PARAMETER(server);
+	UNUSED_PARAMETER(conn);
+	return false;
+}
+
+bool
+CivetHandler::handleDelete(CivetServer *server, struct mg_connection *conn)
+{
+	UNUSED_PARAMETER(server);
+	UNUSED_PARAMETER(conn);
+	return false;
+}
+
+bool
+CivetHandler::handleOptions(CivetServer *server, struct mg_connection *conn)
+{
+	UNUSED_PARAMETER(server);
+	UNUSED_PARAMETER(conn);
+	return false;
+}
+
+bool
+CivetWebSocketHandler::handleConnection(CivetServer *server,
+                                        const struct mg_connection *conn)
+{
+	UNUSED_PARAMETER(server);
+	UNUSED_PARAMETER(conn);
+	return true;
+}
+
+void
+CivetWebSocketHandler::handleReadyState(CivetServer *server,
+                                        struct mg_connection *conn)
+{
+	UNUSED_PARAMETER(server);
+	UNUSED_PARAMETER(conn);
+	return;
+}
+
+bool
+CivetWebSocketHandler::handleData(CivetServer *server,
+                                  struct mg_connection *conn,
+                                  int bits,
+                                  char *data,
+                                  size_t data_len)
+{
+	UNUSED_PARAMETER(server);
+	UNUSED_PARAMETER(conn);
+	UNUSED_PARAMETER(bits);
+	UNUSED_PARAMETER(data);
+	UNUSED_PARAMETER(data_len);
+	return true;
+}
+
+void
+CivetWebSocketHandler::handleClose(CivetServer *server,
+                                   const struct mg_connection *conn)
+{
+	UNUSED_PARAMETER(server);
+	UNUSED_PARAMETER(conn);
+	return;
+}
+
+int
+CivetServer::requestHandler(struct mg_connection *conn, void *cbdata)
+{
+	const struct mg_request_info *request_info = mg_get_request_info(conn);
+	assert(request_info != NULL);
+	CivetServer *me = (CivetServer *)(request_info->user_data);
+	assert(me != NULL);
+
+	// Happens when a request hits the server before the context is saved
+	if (me->context == NULL)
+		return 0;
+
+	mg_lock_context(me->context);
+	me->connections[conn] = CivetConnection();
+	mg_unlock_context(me->context);
+
+	CivetHandler *handler = (CivetHandler *)cbdata;
+
+	if (handler) {
+		if (strcmp(request_info->request_method, "GET") == 0) {
+			return handler->handleGet(me, conn) ? 1 : 0;
+		} else if (strcmp(request_info->request_method, "POST") == 0) {
+			return handler->handlePost(me, conn) ? 1 : 0;
+		} else if (strcmp(request_info->request_method, "HEAD") == 0) {
+			return handler->handleHead(me, conn) ? 1 : 0;
+		} else if (strcmp(request_info->request_method, "PUT") == 0) {
+			return handler->handlePut(me, conn) ? 1 : 0;
+		} else if (strcmp(request_info->request_method, "DELETE") == 0) {
+			return handler->handleDelete(me, conn) ? 1 : 0;
+		} else if (strcmp(request_info->request_method, "OPTIONS") == 0) {
+			return handler->handleOptions(me, conn) ? 1 : 0;
+		} else if (strcmp(request_info->request_method, "PATCH") == 0) {
+			return handler->handlePatch(me, conn) ? 1 : 0;
+		}
+	}
+
+	return 0; // No handler found
+}
+
+int
+CivetServer::authHandler(struct mg_connection *conn, void *cbdata)
+{
+	const struct mg_request_info *request_info = mg_get_request_info(conn);
+	assert(request_info != NULL);
+	CivetServer *me = (CivetServer *)(request_info->user_data);
+	assert(me != NULL);
+
+	// Happens when a request hits the server before the context is saved
+	if (me->context == NULL)
+		return 0;
+
+	mg_lock_context(me->context);
+	me->connections[conn] = CivetConnection();
+	mg_unlock_context(me->context);
+
+	CivetAuthHandler *handler = (CivetAuthHandler *)cbdata;
+
+	if (handler) {
+		return handler->authorize(me, conn) ? 1 : 0;
+	}
+
+	return 0; // No handler found
+}
+
+int
+CivetServer::webSocketConnectionHandler(const struct mg_connection *conn,
+                                        void *cbdata)
+{
+	const struct mg_request_info *request_info = mg_get_request_info(conn);
+	assert(request_info != NULL);
+	CivetServer *me = (CivetServer *)(request_info->user_data);
+	assert(me != NULL);
+
+	// Happens when a request hits the server before the context is saved
+	if (me->context == NULL)
+		return 0;
+
+	CivetWebSocketHandler *handler = (CivetWebSocketHandler *)cbdata;
+
+	if (handler) {
+		return handler->handleConnection(me, conn) ? 0 : 1;
+	}
+
+	return 1; // No handler found, close connection
+}
+
+void
+CivetServer::webSocketReadyHandler(struct mg_connection *conn, void *cbdata)
+{
+	const struct mg_request_info *request_info = mg_get_request_info(conn);
+	assert(request_info != NULL);
+	CivetServer *me = (CivetServer *)(request_info->user_data);
+	assert(me != NULL);
+
+	// Happens when a request hits the server before the context is saved
+	if (me->context == NULL)
+		return;
+
+	CivetWebSocketHandler *handler = (CivetWebSocketHandler *)cbdata;
+
+	if (handler) {
+		handler->handleReadyState(me, conn);
+	}
+}
+
+int
+CivetServer::webSocketDataHandler(struct mg_connection *conn,
+                                  int bits,
+                                  char *data,
+                                  size_t data_len,
+                                  void *cbdata)
+{
+	const struct mg_request_info *request_info = mg_get_request_info(conn);
+	assert(request_info != NULL);
+	CivetServer *me = (CivetServer *)(request_info->user_data);
+	assert(me != NULL);
+
+	// Happens when a request hits the server before the context is saved
+	if (me->context == NULL)
+		return 0;
+
+	CivetWebSocketHandler *handler = (CivetWebSocketHandler *)cbdata;
+
+	if (handler) {
+		return handler->handleData(me, conn, bits, data, data_len) ? 1 : 0;
+	}
+
+	return 1; // No handler found
+}
+
+void
+CivetServer::webSocketCloseHandler(const struct mg_connection *conn,
+                                   void *cbdata)
+{
+	const struct mg_request_info *request_info = mg_get_request_info(conn);
+	assert(request_info != NULL);
+	CivetServer *me = (CivetServer *)(request_info->user_data);
+	assert(me != NULL);
+
+	// Happens when a request hits the server before the context is saved
+	if (me->context == NULL)
+		return;
+
+	CivetWebSocketHandler *handler = (CivetWebSocketHandler *)cbdata;
+
+	if (handler) {
+		handler->handleClose(me, conn);
+	}
+}
+
+CivetCallbacks::CivetCallbacks()
+{
+	memset(this, 0, sizeof(*this));
+}
+
+CivetServer::CivetServer(const char **options,
+                         const struct CivetCallbacks *_callbacks)
+    : context(0)
+{
+	struct CivetCallbacks callbacks;
+
+	if (_callbacks) {
+		callbacks = *_callbacks;
+		userCloseHandler = _callbacks->connection_close;
+	} else {
+		userCloseHandler = NULL;
+	}
+	callbacks.connection_close = closeHandler;
+	context = mg_start(&callbacks, this, options);
+	if (context == NULL)
+		throw CivetException("null context when constructing CivetServer. "
+		                     "Possible problem binding to port.");
+}
+
+CivetServer::CivetServer(std::vector<std::string> options,
+                         const struct CivetCallbacks *_callbacks)
+    : context(0)
+{
+	struct CivetCallbacks callbacks;
+
+	if (_callbacks) {
+		callbacks = *_callbacks;
+		userCloseHandler = _callbacks->connection_close;
+	} else {
+		userCloseHandler = NULL;
+	}
+	callbacks.connection_close = closeHandler;
+
+	std::vector<const char *> pointers(options.size());
+	for (size_t i = 0; i < options.size(); i++) {
+		pointers[i] = (options[i].c_str());
+	}
+	pointers.push_back(0);
+
+	context = mg_start(&callbacks, this, &pointers[0]);
+	if (context == NULL)
+		throw CivetException("null context when constructing CivetServer. "
+		                     "Possible problem binding to port.");
+}
+
+CivetServer::~CivetServer()
+{
+	close();
+}
+
+void
+CivetServer::closeHandler(const struct mg_connection *conn)
+{
+	const struct mg_request_info *request_info = mg_get_request_info(conn);
+	assert(request_info != NULL);
+	CivetServer *me = (CivetServer *)(request_info->user_data);
+	assert(me != NULL);
+
+	// Happens when a request hits the server before the context is saved
+	if (me->context == NULL)
+		return;
+
+	if (me->userCloseHandler)
+		me->userCloseHandler(conn);
+	mg_lock_context(me->context);
+	me->connections.erase(const_cast<struct mg_connection *>(conn));
+	mg_unlock_context(me->context);
+}
+
+void
+CivetServer::addHandler(const std::string &uri, CivetHandler *handler)
+{
+	mg_set_request_handler(context, uri.c_str(), requestHandler, handler);
+}
+
+void
+CivetServer::addWebSocketHandler(const std::string &uri,
+                                 CivetWebSocketHandler *handler)
+{
+	mg_set_websocket_handler(context,
+	                         uri.c_str(),
+	                         webSocketConnectionHandler,
+	                         webSocketReadyHandler,
+	                         webSocketDataHandler,
+	                         webSocketCloseHandler,
+	                         handler);
+}
+
+void
+CivetServer::addAuthHandler(const std::string &uri, CivetAuthHandler *handler)
+{
+	mg_set_auth_handler(context, uri.c_str(), authHandler, handler);
+}
+
+void
+CivetServer::removeHandler(const std::string &uri)
+{
+	mg_set_request_handler(context, uri.c_str(), NULL, NULL);
+}
+
+void
+CivetServer::removeWebSocketHandler(const std::string &uri)
+{
+	mg_set_websocket_handler(
+	    context, uri.c_str(), NULL, NULL, NULL, NULL, NULL);
+}
+
+void
+CivetServer::removeAuthHandler(const std::string &uri)
+{
+	mg_set_auth_handler(context, uri.c_str(), NULL, NULL);
+}
+
+void
+CivetServer::close()
+{
+	if (context) {
+		mg_stop(context);
+		context = 0;
+	}
+}
+
+int
+CivetServer::getCookie(struct mg_connection *conn,
+                       const std::string &cookieName,
+                       std::string &cookieValue)
+{
+	// Maximum cookie length as per microsoft is 4096.
+	// http://msdn.microsoft.com/en-us/library/ms178194.aspx
+	char _cookieValue[4096];
+	const char *cookie = mg_get_header(conn, "Cookie");
+	int lRead = mg_get_cookie(cookie,
+	                          cookieName.c_str(),
+	                          _cookieValue,
+	                          sizeof(_cookieValue));
+	cookieValue.clear();
+	cookieValue.append(_cookieValue);
+	return lRead;
+}
+
+const char *
+CivetServer::getHeader(struct mg_connection *conn,
+                       const std::string &headerName)
+{
+	return mg_get_header(conn, headerName.c_str());
+}
+
+void
+CivetServer::urlDecode(const char *src,
+                       std::string &dst,
+                       bool is_form_url_encoded)
+{
+	urlDecode(src, strlen(src), dst, is_form_url_encoded);
+}
+
+void
+CivetServer::urlDecode(const char *src,
+                       size_t src_len,
+                       std::string &dst,
+                       bool is_form_url_encoded)
+{
+	int i, j, a, b;
+#define HEXTOI(x) (isdigit(x) ? x - '0' : x - 'W')
+
+	dst.clear();
+	for (i = j = 0; i < (int)src_len; i++, j++) {
+		if (i < (int)src_len - 2 && src[i] == '%'
+		    && isxdigit(*(const unsigned char *)(src + i + 1))
+		    && isxdigit(*(const unsigned char *)(src + i + 2))) {
+			a = tolower(*(const unsigned char *)(src + i + 1));
+			b = tolower(*(const unsigned char *)(src + i + 2));
+			dst.push_back((char)((HEXTOI(a) << 4) | HEXTOI(b)));
+			i += 2;
+		} else if (is_form_url_encoded && src[i] == '+') {
+			dst.push_back(' ');
+		} else {
+			dst.push_back(src[i]);
+		}
+	}
+}
+
+bool
+CivetServer::getParam(struct mg_connection *conn,
+                      const char *name,
+                      std::string &dst,
+                      size_t occurrence)
+{
+	const char *formParams = NULL;
+	const struct mg_request_info *ri = mg_get_request_info(conn);
+	assert(ri != NULL);
+	CivetServer *me = (CivetServer *)(ri->user_data);
+	assert(me != NULL);
+	mg_lock_context(me->context);
+	CivetConnection &conobj = me->connections[conn];
+	mg_lock_connection(conn);
+	mg_unlock_context(me->context);
+
+	if (conobj.postData != NULL) {
+		formParams = conobj.postData;
+	} else {
+		const char *con_len_str = mg_get_header(conn, "Content-Length");
+		if (con_len_str) {
+			unsigned long con_len = atoi(con_len_str);
+			if (con_len > 0) {
+				// Add one extra character: in case the post-data is a text, it
+				// is required as 0-termination.
+				// Do not increment con_len, since the 0 terminating is not part
+				// of the content (text or binary).
+				conobj.postData = (char *)malloc(con_len + 1);
+				if (conobj.postData != NULL) {
+					// malloc may fail for huge requests
+					mg_read(conn, conobj.postData, con_len);
+					conobj.postData[con_len] = 0;
+					formParams = conobj.postData;
+					conobj.postDataLen = con_len;
+				}
+			}
+		}
+	}
+	if (formParams == NULL) {
+		// get requests do store html <form> field values in the http
+		// query_string
+		formParams = ri->query_string;
+	}
+	mg_unlock_connection(conn);
+
+	if (formParams != NULL) {
+		return getParam(formParams, strlen(formParams), name, dst, occurrence);
+	}
+
+	return false;
+}
+
+bool
+CivetServer::getParam(const char *data,
+                      size_t data_len,
+                      const char *name,
+                      std::string &dst,
+                      size_t occurrence)
+{
+	const char *p, *e, *s;
+	size_t name_len;
+
+	dst.clear();
+	if (data == NULL || name == NULL || data_len == 0) {
+		return false;
+	}
+	name_len = strlen(name);
+	e = data + data_len;
+
+	// data is "var1=val1&var2=val2...". Find variable first
+	for (p = data; p + name_len < e; p++) {
+		if ((p == data || p[-1] == '&') && p[name_len] == '='
+		    && !mg_strncasecmp(name, p, name_len) && 0 == occurrence--) {
+
+			// Point p to variable value
+			p += name_len + 1;
+
+			// Point s to the end of the value
+			s = (const char *)memchr(p, '&', (size_t)(e - p));
+			if (s == NULL) {
+				s = e;
+			}
+			assert(s >= p);
+
+			// Decode variable into destination buffer
+			urlDecode(p, (int)(s - p), dst, true);
+			return true;
+		}
+	}
+	return false;
+}
+
+void
+CivetServer::urlEncode(const char *src, std::string &dst, bool append)
+{
+	urlEncode(src, strlen(src), dst, append);
+}
+
+void
+CivetServer::urlEncode(const char *src,
+                       size_t src_len,
+                       std::string &dst,
+                       bool append)
+{
+	static const char *dont_escape = "._-$,;~()";
+	static const char *hex = "0123456789abcdef";
+
+	if (!append)
+		dst.clear();
+
+	for (; src_len > 0; src++, src_len--) {
+		if (isalnum(*(const unsigned char *)src)
+		    || strchr(dont_escape, *(const unsigned char *)src) != NULL) {
+			dst.push_back(*src);
+		} else {
+			dst.push_back('%');
+			dst.push_back(hex[(*(const unsigned char *)src) >> 4]);
+			dst.push_back(hex[(*(const unsigned char *)src) & 0xf]);
+		}
+	}
+}
+
+std::vector<int>
+CivetServer::getListeningPorts()
+{
+	std::vector<int> ports(10);
+	std::vector<int> ssl(10);
+	size_t size = mg_get_ports(context, ports.size(), &ports[0], &ssl[0]);
+	ports.resize(size);
+	ssl.resize(size);
+	return ports;
+}
+
+CivetServer::CivetConnection::CivetConnection()
+{
+	postData = NULL;
+	postDataLen = 0;
+}
+
+CivetServer::CivetConnection::~CivetConnection()
+{
+	free(postData);
+}


[28/51] [partial] nifi-minifi-cpp git commit: MINIFI-183 Added civet 1.9.1 sources Added onScheduled hook Added initial two-way TLS-enabled ListenHTTP implementation

Posted by al...@apache.org.
http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/debugger/static/style.css
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/debugger/static/style.css b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/debugger/static/style.css
new file mode 100644
index 0000000..a105947
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/debugger/static/style.css
@@ -0,0 +1,516 @@
+// http://stackoverflow.com/questions/71074/how-to-remove-firefoxs-dotted-outline-on-buttons-as-well-as-links/3844452#3844452
+:focus {
+	outline: none;
+}
+::-moz-focus-inner {
+	border: 0;
+}
+
+@keyframes pulsate {
+	from { opacity: 1; }
+	to { opacity: 0.25; }
+}
+
+#part-header {
+	background: #444444;
+	color: #ffffff;
+	font: 24pt monospace;
+	border-bottom: 2px solid #cccccc;
+	padding: 20px 0px 20px 10px;
+}
+
+/* http://css-tricks.com/snippets/css/a-guide-to-flexbox/ */
+#part-middle {
+	display: flex;
+	flex-direction: row;
+	flex-wrap: nowrap;
+	justify-content: space-between;
+	align-items: stretch;
+	align-content: stretch;
+
+	min-height: 800px;
+
+	border-top: 1px solid #ffffff;
+	padding: 8px;
+	margin-top: 2px;
+}
+#left-area {
+	flex: 0 0 11em;
+	margin-right: 20px;
+	margin-bottom: 10px;
+}
+#center-area {
+	flex: 1 1 0;
+	margin-bottom: 10px;
+}
+#right-area {
+	flex: 0 0 40em;
+	margin-left: 20px;
+	margin-bottom: 10px;
+}
+
+#part-footer {
+	clear: both;
+	border-top: 2px solid #bbbbbb;
+	background: #eeeeee;
+	color: #555555;
+	text-align: center;
+	padding-top: 12px;
+	padding-bottom: 12px;
+	line-height: 1.5;
+}
+
+#exec-status {
+	margin-top: 25px;
+	margin-bottom: 25px;
+}
+#exec-state {
+	display: inline-block;
+	vertical-align: middle;
+}
+#exec-other {
+	display: inline-block;
+	vertical-align: middle;
+	font-size: 125%;
+}
+#current-state {
+	background: #228822;
+	color: #ffffff;
+	font: 16pt;
+	padding: 6pt;
+	border: 5px solid #228822;
+	border-radius: 10px;
+	font-size: 200%;
+	font-weight: bold;
+	margin-right: 10px;
+}
+#current-state.notrunning {
+	background: #882222;
+	border: 5px solid #882222;
+	border-radius: 10px;
+	animation: pulsate 0.7s cubic-bezier(0.75, 0, 0.75, 1) infinite alternate;
+}
+#exec-other:hover {
+	text-decoration: underline;
+	color: #9999ff;
+}
+
+#left-area button {
+	display: inline-block;
+	width: 100%;
+	min-width: 8em;
+	background: #226622;
+	color: #ffffff;
+	font: 16pt sans-serif;
+	font-weight: bold;
+	text-decoration: none;
+	margin: 10px 0 0 0;
+	padding: 0.4em;
+	border: 2px solid #000000;
+	border-radius: 4px;
+}
+#left-area button a {
+	color: #ffffff;
+	text-decoration: none;
+}
+#left-area button:hover {
+	background: #55aa55;
+}
+#left-area button:disabled {
+	background: #555555;
+	color: #888888;
+}
+#left-area button:disabled a {
+	background: #555555;
+	color: #888888;
+}
+
+#pause-button.pending {
+	background: #5555ff;
+	animation: pulsate 0.2s cubic-bezier(0.75, 0, 0.75, 1) infinite alternate;
+}
+
+#attach-button {
+}
+#attach-button.enabled {
+	animation: pulsate 0.7s cubic-bezier(0.75, 0, 0.75, 1) infinite alternate;
+}
+
+.duktape-exec-line {
+	outline: 2px solid red;
+	background: #550000;
+}
+.duktape-break-line {
+	outline: 2px solid white;
+}
+
+#output {
+	font: 9pt monospace;
+	color: #000000;
+	border: 2px solid #cccccc;
+	border-radius: 5px;
+	padding: 3px;
+	height: 30ex;
+	overflow: scroll;
+	overflow-x: auto;
+	overflow-y: scroll;
+	white-space: pre;
+}
+#output .alert {
+	color: #ff0000;
+}
+/* Default color (should be overridden by level) */
+#output .log {
+	color: #00ff00;
+}
+/* Trace */
+#output .loglevel0 {
+	color: #cccccc;
+}
+/* Debug */
+#output .loglevel1 {
+	color: #cccccc;
+}
+/* Info */
+#output .loglevel2 {
+	color: #888888;
+	font-weight: bold;
+}
+/* Warn */
+#output .loglevel3 {
+	color: #ff4444;
+	font-weight: bold;
+}
+/* Error */
+#output .loglevel4 {
+	color: #ff0000;
+	font-weight: bold;
+}
+/* Fatal */
+#output .loglevel5 {
+	background: #000000;
+	color: #ff0000;
+	font-weight: bold;
+}
+#output .debugger-info {
+	color: #880000;
+	font-weight: bold;
+	font-style: italic;
+}
+#output .debugger-debug {
+	color: #888888;
+	font-weight: bold;
+	font-style: italic;
+}
+
+#callstack {
+	font: 9pt monospace;
+	color: #000000;
+	margin-top: 10px;
+	border: 2px solid #cccccc;
+	border-radius: 5px;
+	padding: 3px;
+	height: 14ex;
+	overflow: scroll;
+	overflow-x: auto;
+	overflow-y: scroll;
+	white-space: pre;
+}
+#callstack div:nth-child(2n) {
+	background: #eeeeee;
+}
+#callstack .func {
+}
+#callstack .rest {
+	float: right;
+	color: #6666ff;
+}
+#callstack .rest:hover {
+	text-decoration: underline;
+	color: #9999ff;
+}
+
+#locals {
+	font: 9pt monospace;
+	color: #000000;
+	margin-top: 10px;
+	border: 2px solid #cccccc;
+	border-radius: 5px;
+	padding: 10px;
+	height: 30ex;
+	overflow: scroll;
+	overflow-x: auto;
+	overflow-y: scroll;
+	white-space: pre;
+}
+#locals div:nth-child(2n) {
+	background: #eeeeee;
+}
+#locals .key {
+}
+#locals .value {
+	float: right;
+	color: #888888;
+}
+
+#breakpoints {
+	color: #000000;
+	margin-top: 10px;
+	border: 2px solid #cccccc;
+	border-radius: 5px;
+	padding: 3px;
+	height: 15ex;
+	overflow: scroll;
+	overflow-x: auto;
+	overflow-y: scroll;
+	white-space: pre;
+}
+#breakpoints div {
+	margin: 2px 0 2px 0;
+}
+#breakpoints div:nth-child(2n) {
+	background: #eeeeee;
+}
+#breakpoints a {
+	font: 9pt monospace;
+	color: #6666ff;
+}
+#breakpoints a:hover {
+	text-decoration: underline;
+	color: #9999ff;
+}
+.breakpoint-line {
+	clear: both;
+	padding-top: 2px;
+	padding-bottom: 2px;
+}
+#add-breakpoint-file {
+	font: 10pt monospace;
+	width: 10em;
+	padding: 5px;
+}
+#add-breakpoint-line {
+	font: 10pt monospace;
+	width: 3em;
+	margin-left: 3px;
+	padding: 5px;
+}
+#delete-all-breakpoints-button {
+	float: right;
+	font: 10pt sans-serif;
+	padding: 5px;
+	border: 1px solid #888888;
+	background: #ddffdd;
+	color: #000000;
+}
+#delete-all-breakpoints-button:hover {
+	background: #f8fff8;
+}
+#delete-all-breakpoints-button:disabled {
+	background: #dddddd;
+	color: #444444;
+}
+#add-breakpoint-button {
+	font: 10pt sans-serif;
+	margin-left: 10px;
+	padding: 5px;
+	border: 1px solid #888888;
+	background: #ddffdd;
+	color: #000000;
+}
+#add-breakpoint-button:hover {
+	background: #f8fff8;
+}
+#add-breakpoint-button:disabled {
+	background: #dddddd;
+	color: #444444;
+}
+#breakpoint-hint {
+	color: #aaaaaa;
+	font-style: italic;
+	margin-left: 10px;
+}
+.delete-breakpoint-button {
+	float: right;
+	display: inline;
+	font: 9pt sans-serif;
+	padding: 3px;
+	border: none;
+	background: none;
+	color: #6666ff;
+}
+.delete-breakpoint-button {
+	font: 9pt sans-serif;
+}
+.delete-breakpoint-button:hover {
+	text-decoration: underline;
+	color: #9999ff;
+}
+.delete-breakpoint-button:disabled {
+	color: #888888;
+}
+
+#about-dialog p {
+	margin: 10px 0 10px 0;
+}
+
+#bytecode-dialog p {
+	margin: 10px 0 10px 0;
+}
+#bytecode-dialog pre {
+	font: 10pt monospace;
+	color: #000000;
+}
+#bytecode-dialog div.highlight {
+	background: #888888;
+	color: #ffffff;
+}
+
+#eval {
+	color: #000000;
+	margin-top: 10px;
+	border: 2px solid #cccccc;
+	border-radius: 5px;
+	padding: 3px;
+	height: 30ex;
+	overflow: scroll;
+	overflow-x: auto;
+	overflow-y: scroll;
+	white-space: pre;
+}
+#eval-input {
+	display: inline;
+	font: 10pt monospace;
+	width: 20em;
+	padding: 5px;
+}
+#eval-button {
+	display: inline;
+	margin-left: 10px;
+	padding: 5px;
+	border: 1px solid #888888;
+	font: 10pt sans-serif;
+	background: #ddffdd;
+	color: #000000;
+}
+#eval-button {
+}
+#eval-button:hover {
+	background: #f8fff8;
+}
+#eval-button:disabled {
+	background: #dddddd;
+	color: #444444;
+}
+#eval-button.pending {
+	background: #5555ff;
+	animation: pulsate 0.2s cubic-bezier(0.75, 0, 0.75, 1) infinite alternate;
+}
+#eval-watch {
+	margin-left: 20px;
+	vertical-align: middle;
+}
+#eval-output {
+	font: 10pt monospace;
+	white-space: pre;
+	padding: 5px;
+	border: 1px solid #888888;
+	min-height: 4ex;
+	margin-top: 5px;
+}
+
+#varname-input {
+	font: 10pt monospace;
+	width: 10em;
+	padding: 5px;
+}
+#varvalue-input {
+	margin-left: 10px;
+	font: 10pt monospace;
+	width: 20em;
+	padding: 5px;
+}
+#getvar-button,
+#putvar-button {
+	display: inline;
+	float: right;
+	margin-left: 10px;
+	padding: 5px;
+	border: 1px solid #888888;
+	font: 10pt sans-serif;
+	background: #ddffdd;
+	color: #000000;
+}
+#getvar-button:hover,
+#putvar-button:hover {
+	background: #f8fff8;
+}
+#getvar-button:disabled,
+#putvar-button:disabled {
+	background: #dddddd;
+	color: #444444;
+}
+#var-output {
+	font: 10pt monospace;
+	white-space: pre;
+	padding: 5px;
+	border: 1px solid #888888;
+	min-height: 4ex;
+	margin-top: 5px;
+}
+
+#source-pre {
+	margin-top: 10px;
+	border: 2px solid #cccccc;
+	border-radius: 5px;
+	height: 400px;
+	overflow: scroll;
+	overflow-x: auto;
+	overflow-y: scroll;
+}
+#source-pre.running {
+	background: #eeeeee;
+	color: #888888;
+}
+#source-pre.running #source-code {
+	background: #eeeeee;
+	color: #888888;
+}
+#source-filename {
+	font-size: 125%;
+	color: #888888;
+}
+code.sourcecode {
+	counter-reset: source-line;
+}
+code.sourcecode div {
+	font: 10pt monospace;
+	padding: 2px 5px 2px 5px;
+	white-space: pre;
+	border-bottom: 1px solid #eeeeee;
+}
+code.sourcecode div:before {
+	display: inline-block;
+	content: counter(source-line);
+	counter-increment: source-line;
+	width: 4em;
+	color: #888888;
+	text-align: right;
+	margin-right: 20px;
+}
+code.sourcecode div.breakpoint:before {
+	margin-right: 0px;
+	border-right: 20px solid #ff0000;
+}
+code.sourcecode div.highlight {
+	background: #aaaaaa;
+	color: #000000;
+}
+code.sourcecode div.execution {
+	background: #000000;
+	color: #ffffff;
+}
+
+#source-select {
+	margin-top: 5px;
+}

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/debugger/static/webui.js
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/debugger/static/webui.js b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/debugger/static/webui.js
new file mode 100644
index 0000000..d400c6c
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/debugger/static/webui.js
@@ -0,0 +1,785 @@
+/*
+ *  Duktape debugger web client
+ *
+ *  Talks to the NodeJS server using socket.io.
+ *
+ *  http://unixpapa.com/js/key.html
+ */
+
+// Update interval for custom source highlighting.
+var SOURCE_UPDATE_INTERVAL = 350;
+
+// Source view
+var activeFileName = null;          // file that we want to be loaded in source view
+var activeLine = null;              // scroll to line once file has been loaded
+var activeHighlight = null;         // line that we want to highlight (if any)
+var loadedFileName = null;          // currently loaded (shown) file
+var loadedLineCount = 0;            // currently loaded file line count
+var loadedFileExecuting = false;    // true if currFileName (loosely) matches loadedFileName
+var loadedLinePending = null;       // if set, scroll loaded file to requested line
+var highlightLine = null;           // highlight line
+var sourceEditedLines = [];         // line numbers which have been modified
+                                    // (added classes etc, tracked for removing)
+var sourceUpdateInterval = null;    // timer for updating source view
+var sourceFetchXhr = null;          // current AJAX request for fetching a source file (if any)
+var forceButtonUpdate = false;      // hack to reset button states
+var bytecodeDialogOpen = false;     // bytecode dialog active
+var bytecodeIdxHighlight = null;    // index of currently highlighted line (or null)
+var bytecodeIdxInstr = 0;           // index to first line of bytecode instructions
+
+// Execution state
+var prevState = null;               // previous execution state ('paused', 'running', etc)
+var prevAttached = null;            // previous debugger attached state (true, false, null)
+var currFileName = null;            // current filename being executed
+var currFuncName = null;            // current function name being executed
+var currLine = 0;                   // current line being executed
+var currPc = 0;                     // current bytecode PC being executed
+var currState = 0;                  // current execution state ('paused', 'running', 'detached', etc)
+var currAttached = false;           // current debugger attached state (true or false)
+var currLocals = [];                // current local variables
+var currCallstack = [];             // current callstack (from top to bottom)
+var currBreakpoints = [];           // current breakpoints
+var startedRunning = 0;             // timestamp when last started running (if running)
+                                    // (used to grey out the source file if running for long enough)
+
+/*
+ *  Helpers
+ */
+
+function formatBytes(x) {
+    if (x < 1024) {
+        return String(x) + ' bytes';
+    } else if (x < 1024 * 1024) {
+        return (x / 1024).toPrecision(3) + ' kB';
+    } else {
+        return (x / (1024 * 1024)).toPrecision(3) + ' MB';
+    }
+}
+
+/*
+ *  Source view periodic update handling
+ */
+
+function doSourceUpdate() {
+    var elem;
+
+    // Remove previously added custom classes
+    sourceEditedLines.forEach(function (linenum) {
+        elem = $('#source-code div')[linenum - 1];
+        if (elem) {
+            elem.classList.remove('breakpoint');
+            elem.classList.remove('execution');
+            elem.classList.remove('highlight');
+        }
+    });
+    sourceEditedLines.length = 0;
+
+    // If we're executing the file shown, highlight current line
+    if (loadedFileExecuting) {
+        elem = $('#source-code div')[currLine - 1];
+        if (elem) {
+            sourceEditedLines.push(currLine);
+            elem.classList.add('execution');
+        }
+    }
+
+    // Add breakpoints
+    currBreakpoints.forEach(function (bp) {
+        if (bp.fileName === loadedFileName) {
+            elem = $('#source-code div')[bp.lineNumber - 1];
+            if (elem) {
+                sourceEditedLines.push(bp.lineNumber);
+                elem.classList.add('breakpoint');
+            }
+        }
+    });
+
+    if (highlightLine !== null) {
+        elem = $('#source-code div')[highlightLine - 1];
+        if (elem) {
+            sourceEditedLines.push(highlightLine);
+            elem.classList.add('highlight');
+        }
+    }
+
+    // Bytecode dialog highlight
+    if (loadedFileExecuting && bytecodeDialogOpen && bytecodeIdxHighlight !== bytecodeIdxInstr + currPc) {
+        if (typeof bytecodeIdxHighlight === 'number') {
+            $('#bytecode-preformatted div')[bytecodeIdxHighlight].classList.remove('highlight');
+        }
+        bytecodeIdxHighlight = bytecodeIdxInstr + currPc;
+        $('#bytecode-preformatted div')[bytecodeIdxHighlight].classList.add('highlight');
+    }
+
+    // If no-one requested us to scroll to a specific line, finish.
+    if (loadedLinePending == null) {
+        return;
+    }
+
+    var reqLine = loadedLinePending;
+    loadedLinePending = null;
+
+    // Scroll to requested line.  This is not very clean, so a better solution
+    // should be found:
+    // https://developer.mozilla.org/en-US/docs/Web/API/Element.scrollIntoView
+    // http://erraticdev.blogspot.fi/2011/02/jquery-scroll-into-view-plugin-with.html
+    // http://flesler.blogspot.fi/2007/10/jqueryscrollto.html
+    var tmpLine = Math.max(reqLine - 5, 0);
+    elem = $('#source-code div')[tmpLine];
+    if (elem) {
+        elem.scrollIntoView();
+    }
+}
+
+// Source is updated periodically.  Other code can also call doSourceUpdate()
+// directly if an immediate update is needed.
+sourceUpdateInterval = setInterval(doSourceUpdate, SOURCE_UPDATE_INTERVAL);
+
+/*
+ *  UI update handling when exec-status update arrives
+ */
+
+function doUiUpdate() {
+    var now = Date.now();
+
+    // Note: loadedFileName can be either from target or from server, but they
+    // must match exactly.  We could do a loose match here, but exact matches
+    // are needed for proper breakpoint handling anyway.
+    loadedFileExecuting = (loadedFileName === currFileName);
+
+    // If we just started running, store a timestamp so we can grey out the
+    // source view only if we execute long enough (i.e. we're not just
+    // stepping).
+    if (currState !== prevState && currState === 'running') {
+        startedRunning = now;
+    }
+
+    // If we just became paused, check for eval watch
+    if (currState !== prevState && currState === 'paused') {
+        if ($('#eval-watch').is(':checked')) {
+            submitEval();  // don't clear eval input
+        }
+    }
+
+    // Update current execution state
+    if (currFileName === '' && currLine === 0) {
+        $('#current-fileline').text('');
+    } else {
+        $('#current-fileline').text(String(currFileName) + ':' + String(currLine));
+    }
+    if (currFuncName === '' && currPc === 0) {
+        $('#current-funcpc').text('');
+    } else {
+        $('#current-funcpc').text(String(currFuncName) + '() pc ' + String(currPc));
+    }
+    $('#current-state').text(String(currState));
+
+    // Update buttons
+    if (currState !== prevState || currAttached !== prevAttached || forceButtonUpdate) {
+        $('#stepinto-button').prop('disabled', !currAttached || currState !== 'paused');
+        $('#stepover-button').prop('disabled', !currAttached || currState !== 'paused');
+        $('#stepout-button').prop('disabled', !currAttached || currState !== 'paused');
+        $('#resume-button').prop('disabled', !currAttached || currState !== 'paused');
+        $('#pause-button').prop('disabled', !currAttached || currState !== 'running');
+        $('#attach-button').prop('disabled', currAttached);
+        if (currAttached) {
+            $('#attach-button').removeClass('enabled');
+        } else {
+            $('#attach-button').addClass('enabled');
+        }
+        $('#detach-button').prop('disabled', !currAttached);
+        $('#eval-button').prop('disabled', !currAttached);
+        $('#add-breakpoint-button').prop('disabled', !currAttached);
+        $('#delete-all-breakpoints-button').prop('disabled', !currAttached);
+        $('.delete-breakpoint-button').prop('disabled', !currAttached);
+        $('#putvar-button').prop('disabled', !currAttached);
+        $('#getvar-button').prop('disabled', !currAttached);
+        $('#heap-dump-download-button').prop('disabled', !currAttached);
+    }
+    if (currState !== 'running' || forceButtonUpdate) {
+        // Remove pending highlight once we're no longer running.
+        $('#pause-button').removeClass('pending');
+        $('#eval-button').removeClass('pending');
+    }
+    forceButtonUpdate = false;
+
+    // Make source window grey when running for a longer time, use a small
+    // delay to avoid flashing grey when stepping.
+    if (currState === 'running' && now - startedRunning >= 500) {
+        $('#source-pre').removeClass('notrunning');
+        $('#current-state').removeClass('notrunning');
+    } else {
+        $('#source-pre').addClass('notrunning');
+        $('#current-state').addClass('notrunning');
+    }
+
+    // Force source view to match currFileName only when running or when
+    // just became paused (from running or detached).
+    var fetchSource = false;
+    if (typeof currFileName === 'string') {
+        if (currState === 'running' ||
+            (prevState !== 'paused' && currState === 'paused') ||
+            (currAttached !== prevAttached)) {
+            if (activeFileName !== currFileName) {
+                fetchSource = true;
+                activeFileName = currFileName;
+                activeLine = currLine;
+                activeHighlight = null;
+                requestSourceRefetch();
+            }
+        }
+    }
+
+    // Force line update (scrollTop) only when running or just became paused.
+    // Otherwise let user browse and scroll source files freely.
+    if (!fetchSource) {
+        if ((prevState !== 'paused' && currState === 'paused') ||
+            currState === 'running') {
+            loadedLinePending = currLine || 0;
+        }
+    }
+}
+
+/*
+ *  Init socket.io and add handlers
+ */
+
+var socket = io();  // returns a Manager
+
+setInterval(function () {
+    socket.emit('keepalive', {
+        userAgent: (navigator || {}).userAgent
+    });
+}, 30000);
+
+socket.on('connect', function () {
+    $('#socketio-info').text('connected');
+    currState = 'connected';
+
+    fetchSourceList();
+});
+socket.on('disconnect', function () {
+    $('#socketio-info').text('not connected');
+    currState = 'disconnected';
+});
+socket.on('reconnecting', function () {
+    $('#socketio-info').text('reconnecting');
+    currState = 'reconnecting';
+});
+socket.on('error', function (err) {
+    $('#socketio-info').text(err);
+});
+
+socket.on('replaced', function () {
+    // XXX: how to minimize the chance we'll further communciate with the
+    // server or reconnect to it?  socket.reconnection()?
+
+    // We'd like to window.close() here but can't (not allowed from scripts).
+    // Alert is the next best thing.
+    alert('Debugger connection replaced by a new one, do you have multiple tabs open? If so, please close this tab.');
+});
+
+socket.on('keepalive', function (msg) {
+    // Not really interesting in the UI
+    // $('#server-info').text(new Date() + ': ' + JSON.stringify(msg));
+});
+
+socket.on('basic-info', function (msg) {
+    $('#duk-version').text(String(msg.duk_version));
+    $('#duk-git-describe').text(String(msg.duk_git_describe));
+    $('#target-info').text(String(msg.target_info));
+    $('#endianness').text(String(msg.endianness));
+});
+
+socket.on('exec-status', function (msg) {
+    // Not 100% reliable if callstack has several functions of the same name
+    if (bytecodeDialogOpen && (currFileName != msg.fileName || currFuncName != msg.funcName)) {
+        socket.emit('get-bytecode', {});
+    }
+
+    currFileName = msg.fileName;
+    currFuncName = msg.funcName;
+    currLine = msg.line;
+    currPc = msg.pc;
+    currState = msg.state;
+    currAttached = msg.attached;
+
+    // Duktape now restricts execution status updates quite effectively so
+    // there's no need to rate limit UI updates now.
+
+    doUiUpdate();
+
+    prevState = currState;
+    prevAttached = currAttached;
+});
+
+// Update the "console" output based on lines sent by the server.  The server
+// rate limits these updates to keep the browser load under control.  Even
+// better would be for the client to pull this (and other stuff) on its own.
+socket.on('output-lines', function (msg) {
+    var elem = $('#output');
+    var i, n, ent;
+
+    elem.empty();
+    for (i = 0, n = msg.length; i < n; i++) {
+        ent = msg[i];
+        if (ent.type === 'print') {
+            elem.append($('<div></div>').text(ent.message));
+        } else if (ent.type === 'alert') {
+            elem.append($('<div class="alert"></div>').text(ent.message));
+        } else if (ent.type === 'log') {
+            elem.append($('<div class="log loglevel' + ent.level + '"></div>').text(ent.message));
+        } else if (ent.type === 'debugger-info') {
+            elem.append($('<div class="debugger-info"><div>').text(ent.message));
+        } else if (ent.type === 'debugger-debug') {
+            elem.append($('<div class="debugger-debug"><div>').text(ent.message));
+        } else {
+            elem.append($('<div></div>').text(ent.message));
+        }
+    }
+
+    // http://stackoverflow.com/questions/14918787/jquery-scroll-to-bottom-of-div-even-after-it-updates
+    // Stop queued animations so that we always scroll quickly to bottom
+    $('#output').stop(true);
+    $('#output').animate({ scrollTop: $('#output')[0].scrollHeight}, 1000);
+});
+
+socket.on('callstack', function (msg) {
+    var elem = $('#callstack');
+    var s1, s2, div;
+
+    currCallstack = msg.callstack;
+
+    elem.empty();
+    msg.callstack.forEach(function (e) {
+        s1 = $('<a class="rest"></a>').text(e.fileName + ':' + e.lineNumber + ' (pc ' + e.pc + ')');  // float
+        s1.on('click', function () {
+            activeFileName = e.fileName;
+            activeLine = e.lineNumber || 1;
+            activeHighlight = activeLine;
+            requestSourceRefetch();
+        });
+        s2 = $('<span class="func"></span>').text(e.funcName + '()');
+        div = $('<div></div>');
+        div.append(s1);
+        div.append(s2);
+        elem.append(div);
+    });
+});
+
+socket.on('locals', function (msg) {
+    var elem = $('#locals');
+    var s1, s2, div;
+    var i, n, e;
+
+    currLocals = msg.locals;
+
+    elem.empty();
+    for (i = 0, n = msg.locals.length; i < n; i++) {
+        e = msg.locals[i];
+        s1 = $('<span class="value"></span>').text(e.value);  // float
+        s2 = $('<span class="key"></span>').text(e.key);
+        div = $('<div></div>');
+        div.append(s1);
+        div.append(s2);
+        elem.append(div);
+    }
+});
+
+socket.on('debug-stats', function (msg) {
+    $('#debug-rx-bytes').text(formatBytes(msg.rxBytes));
+    $('#debug-rx-dvalues').text(msg.rxDvalues);
+    $('#debug-rx-messages').text(msg.rxMessages);
+    $('#debug-rx-kbrate').text((msg.rxBytesPerSec / 1024).toFixed(2));
+    $('#debug-tx-bytes').text(formatBytes(msg.txBytes));
+    $('#debug-tx-dvalues').text(msg.txDvalues);
+    $('#debug-tx-messages').text(msg.txMessages);
+    $('#debug-tx-kbrate').text((msg.txBytesPerSec / 1024).toFixed(2));
+});
+
+socket.on('breakpoints', function (msg) {
+    var elem = $('#breakpoints');
+    var div;
+    var sub;
+
+    currBreakpoints = msg.breakpoints;
+
+    elem.empty();
+
+    // First line is special
+    div = $('<div></div>');
+    sub = $('<button id="delete-all-breakpoints-button"></button>').text('Delete all breakpoints');
+    sub.on('click', function () {
+        socket.emit('delete-all-breakpoints');
+    });
+    div.append(sub);
+    sub = $('<input id="add-breakpoint-file"></input>').val('file.js');
+    div.append(sub);
+    sub = $('<span></span>').text(':');
+    div.append(sub);
+    sub = $('<input id="add-breakpoint-line"></input>').val('123');
+    div.append(sub);
+    sub = $('<button id="add-breakpoint-button"></button>').text('Add breakpoint');
+    sub.on('click', function () {
+        socket.emit('add-breakpoint', {
+            fileName: $('#add-breakpoint-file').val(),
+            lineNumber: Number($('#add-breakpoint-line').val())
+        });
+    });
+    div.append(sub);
+    sub = $('<span id="breakpoint-hint"></span>').text('or dblclick source');
+    div.append(sub);
+    elem.append(div);
+
+    // Active breakpoints follow
+    msg.breakpoints.forEach(function (bp) {
+        var div;
+        var sub;
+
+        div = $('<div class="breakpoint-line"></div>');
+        sub = $('<button class="delete-breakpoint-button"></button>').text('Delete');
+        sub.on('click', function () {
+            socket.emit('delete-breakpoint', {
+                fileName: bp.fileName,
+                lineNumber: bp.lineNumber
+            });
+        });
+        div.append(sub);
+        sub = $('<a></a>').text((bp.fileName || '?') + ':' + (bp.lineNumber || 0));
+        sub.on('click', function () {
+            activeFileName = bp.fileName || '';
+            activeLine = bp.lineNumber || 1;
+            activeHighlight = activeLine;
+            requestSourceRefetch();
+        });
+        div.append(sub);
+        elem.append(div);
+    });
+
+    forceButtonUpdate = true;
+    doUiUpdate();
+});
+
+socket.on('eval-result', function (msg) {
+    $('#eval-output').text((msg.error ? 'ERROR: ' : '') + msg.result);
+
+    // Remove eval button "pulsating" glow when we get a result
+    $('#eval-button').removeClass('pending');
+});
+
+socket.on('getvar-result', function (msg) {
+    $('#var-output').text(msg.found ? msg.result : 'NOTFOUND');
+});
+
+socket.on('bytecode', function (msg) {
+    var elem, div;
+    var div;
+
+    elem = $('#bytecode-preformatted');
+    elem.empty();
+
+    msg.preformatted.split('\n').forEach(function (line, idx) {
+        div = $('<div></div>');
+        div.text(line);
+        elem.append(div);
+    });
+
+    bytecodeIdxHighlight = null;
+    bytecodeIdxInstr = msg.idxPreformattedInstructions;
+});
+
+$('#stepinto-button').click(function () {
+    socket.emit('stepinto', {});
+});
+
+$('#stepover-button').click(function () {
+    socket.emit('stepover', {});
+});
+
+$('#stepout-button').click(function () {
+    socket.emit('stepout', {});
+});
+
+$('#pause-button').click(function () {
+    socket.emit('pause', {});
+
+    // Pause may take seconds to complete so indicate it is pending.
+    $('#pause-button').addClass('pending');
+});
+
+$('#resume-button').click(function () {
+    socket.emit('resume', {});
+});
+
+$('#attach-button').click(function () {
+    socket.emit('attach', {});
+});
+
+$('#detach-button').click(function () {
+    socket.emit('detach', {});
+});
+
+$('#about-button').click(function () {
+    $('#about-dialog').dialog('open');
+});
+
+$('#show-bytecode-button').click(function () {
+    bytecodeDialogOpen = true;
+    $('#bytecode-dialog').dialog('open');
+
+    elem = $('#bytecode-preformatted');
+    elem.empty().text('Loading bytecode...');
+
+    socket.emit('get-bytecode', {});
+});
+
+function submitEval() {
+    socket.emit('eval', { input: $('#eval-input').val() });
+
+    // Eval may take seconds to complete so indicate it is pending.
+    $('#eval-button').addClass('pending');
+}
+
+$('#eval-button').click(function () {
+    submitEval();
+    $('#eval-input').val('');
+});
+
+$('#getvar-button').click(function () {
+    socket.emit('getvar', { varname: $('#varname-input').val() });
+});
+
+$('#putvar-button').click(function () {
+    // The variable value is parsed as JSON right now, but it'd be better to
+    // also be able to parse buffer values etc.
+    var val = JSON.parse($('#varvalue-input').val());
+    socket.emit('putvar', { varname: $('#varname-input').val(), varvalue: val });
+});
+
+$('#source-code').dblclick(function (event) {
+    var target = event.target;
+    var elems = $('#source-code div');
+    var i, n;
+    var line = 0;
+
+    // XXX: any faster way; elems doesn't have e.g. indexOf()
+    for (i = 0, n = elems.length; i < n; i++) {
+        if (target === elems[i]) {
+            line = i + 1;
+        }
+    }
+
+    socket.emit('toggle-breakpoint', {
+        fileName: loadedFileName,
+        lineNumber: line
+    });
+});
+
+function setSourceText(data) {
+    var elem, div;
+
+    elem = $('#source-code');
+    elem.empty();
+    data.split('\n').forEach(function (line) {
+        div = $('<div></div>');
+        div.text(line);
+        elem.append(div);
+    });
+
+    sourceEditedLines = [];
+}
+
+function setSourceSelect(fileName) {
+    var elem;
+    var i, n, t;
+
+    if (fileName == null) {
+        $('#source-select').val('__none__');
+        return;
+    }
+
+    elem = $('#source-select option');
+    for (i = 0, n = elem.length; i < n; i++) {
+        // Exact match is required.
+        t = $(elem[i]).val();
+        if (t === fileName) {
+            $('#source-select').val(t);
+            return;
+        }
+    }
+}
+
+/*
+ *  AJAX request handling to fetch source files
+ */
+
+function requestSourceRefetch() {
+    // If previous update is pending, abort and start a new one.
+    if (sourceFetchXhr) {
+        sourceFetchXhr.abort();
+        sourceFetchXhr = null;
+    }
+
+    // Make copies of the requested file/line so that we have the proper
+    // values in case they've changed.
+    var fileName = activeFileName;
+    var lineNumber = activeLine;
+
+    // AJAX request for the source.
+    sourceFetchXhr = $.ajax({
+        type: 'POST',
+        url: '/source',
+        data: JSON.stringify({ fileName: fileName }),
+        contentType: 'application/json',
+        success: function (data, status, jqxhr) {
+            var elem;
+
+            sourceFetchXhr = null;
+
+            loadedFileName = fileName;
+            loadedLineCount = data.split('\n').length;  // XXX: ignore issue with last empty line for now
+            loadedFileExecuting = (loadedFileName === currFileName);
+            setSourceText(data);
+            setSourceSelect(fileName);
+            loadedLinePending = activeLine || 1;
+            highlightLine = activeHighlight;  // may be null
+            activeLine = null;
+            activeHighlight = null;
+            doSourceUpdate();
+
+            // XXX: hacky transition, make source change visible
+            $('#source-pre').fadeTo('fast', 0.25, function () {
+                $('#source-pre').fadeTo('fast', 1.0);
+            });
+        },
+        error: function (jqxhr, status, err) {
+            // Not worth alerting about because source fetch errors happen
+            // all the time, e.g. for dynamically evaluated code.
+
+            sourceFetchXhr = null;
+
+            // XXX: prevent retry of no-such-file by negative caching?
+            loadedFileName = fileName;
+            loadedLineCount = 1;
+            loadedFileExecuting = false;
+            setSourceText('// Cannot load source file: ' + fileName);
+            setSourceSelect(null);
+            loadedLinePending = 1;
+            activeLine = null;
+            activeHighlight = null;
+            doSourceUpdate();
+
+            // XXX: error transition here
+            $('#source-pre').fadeTo('fast', 0.25, function () {
+                $('#source-pre').fadeTo('fast', 1.0);
+            });
+        },
+        dataType: 'text'
+    });
+}
+
+/*
+ *  AJAX request for fetching the source list
+ */
+
+function fetchSourceList() {
+    $.ajax({
+        type: 'POST',
+        url: '/sourceList',
+        data: JSON.stringify({}),
+        contentType: 'application/json',
+        success: function (data, status, jqxhr) {
+            var elem = $('#source-select');
+
+            data = JSON.parse(data);
+
+            elem.empty();
+            var opt = $('<option></option>').attr({ 'value': '__none__' }).text('No source file selected');
+            elem.append(opt);
+            data.forEach(function (ent) {
+                var opt = $('<option></option>').attr({ 'value': ent }).text(ent);
+                elem.append(opt);
+            });
+            elem.change(function () {
+                activeFileName = elem.val();
+                activeLine = 1;
+                requestSourceRefetch();
+            });
+        },
+        error: function (jqxhr, status, err) {
+            // This is worth alerting about as the UI is somewhat unusable
+            // if we don't get a source list.
+
+            alert('Failed to load source list: ' + err);
+        },
+        dataType: 'text'
+    });
+}
+
+/*
+ *  Initialization
+ */
+
+$(document).ready(function () {
+    var showAbout = true;
+
+    // About dialog, shown automatically on first startup.
+    $('#about-dialog').dialog({
+        autoOpen: false,
+        hide: 'fade',  // puff
+        show: 'fade',  // slide, puff
+        width: 500,
+        height: 300
+    });
+
+    // Bytecode dialog
+    $('#bytecode-dialog').dialog({
+        autoOpen: false,
+        hide: 'fade',  // puff
+        show: 'fade',  // slide, puff
+        width: 700,
+        height: 600,
+        close: function () {
+            bytecodeDialogOpen = false;
+            bytecodeIdxHighlight = null;
+            bytecodeIdxInstr = 0;
+        }
+    });
+
+    // http://diveintohtml5.info/storage.html
+    if (typeof localStorage !== 'undefined') {
+        if (localStorage.getItem('about-shown')) {
+            showAbout = false;
+        } else {
+            localStorage.setItem('about-shown', 'yes');
+        }
+    }
+    if (showAbout) {
+        $('#about-dialog').dialog('open');
+    }
+
+    // onclick handler for exec status text
+    function loadCurrFunc() {
+        activeFileName = currFileName;
+        activeLine = currLine;
+        requestSourceRefetch();
+    }
+    $('#exec-other').on('click', loadCurrFunc);
+
+    // Enter handling for eval input
+    // https://forum.jquery.com/topic/bind-html-input-to-enter-key-keypress
+    $('#eval-input').keypress(function (event) {
+        if (event.keyCode == 13) {
+            submitEval();
+            $('#eval-input').val('');
+        }
+    });
+
+    // Eval watch handling
+    $('#eval-watch').change(function () {
+        // nop
+    });
+
+    forceButtonUpdate = true;
+    doUiUpdate();
+});

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/duk_build_meta.json
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/duk_build_meta.json b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/duk_build_meta.json
new file mode 100644
index 0000000..c2e80bb
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/duk_build_meta.json
@@ -0,0 +1,1349 @@
+{
+    "builtin_strings": [
+        "Undefined", 
+        "Null", 
+        "Arguments", 
+        "Object", 
+        "Function", 
+        "Array", 
+        "String", 
+        "Boolean", 
+        "Number", 
+        "Date", 
+        "RegExp", 
+        "Error", 
+        "Math", 
+        "JSON", 
+        "", 
+        "ArrayBuffer", 
+        "DataView", 
+        "Int8Array", 
+        "Uint8Array", 
+        "Uint8ClampedArray", 
+        "Int16Array", 
+        "Uint16Array", 
+        "Int32Array", 
+        "Uint32Array", 
+        "Float32Array", 
+        "Float64Array", 
+        "global", 
+        "ObjEnv", 
+        "DecEnv", 
+        "Buffer", 
+        "Pointer", 
+        "Thread", 
+        "eval", 
+        "defineProperty", 
+        "value", 
+        "writable", 
+        "configurable", 
+        "enumerable", 
+        "join", 
+        "toLocaleString", 
+        "valueOf", 
+        "toUTCString", 
+        "toISOString", 
+        "toGMTString", 
+        "source", 
+        "ignoreCase", 
+        "multiline", 
+        "lastIndex", 
+        "(?:)", 
+        "index", 
+        "prototype", 
+        "constructor", 
+        "message", 
+        "boolean", 
+        "number", 
+        "string", 
+        "object", 
+        "undefined", 
+        "NaN", 
+        "Infinity", 
+        "-Infinity", 
+        "-0", 
+        ",", 
+        " ", 
+        "\n    ", 
+        "[...]", 
+        "Invalid Date", 
+        "arguments", 
+        "callee", 
+        "caller", 
+        "has", 
+        "get", 
+        "deleteProperty", 
+        "enumerate", 
+        "ownKeys", 
+        "setPrototypeOf", 
+        "__proto__", 
+        "require", 
+        "id", 
+        "exports", 
+        "filename", 
+        "toString", 
+        "toJSON", 
+        "type", 
+        "data", 
+        "length", 
+        "byteLength", 
+        "byteOffset", 
+        "BYTES_PER_ELEMENT", 
+        "set", 
+        "stack", 
+        "pc", 
+        "lineNumber", 
+        "\u00ffTracedata", 
+        "name", 
+        "fileName", 
+        "buffer", 
+        "pointer", 
+        "\u00ffValue", 
+        "\u00ffNext", 
+        "\u00ffBytecode", 
+        "\u00ffFormals", 
+        "\u00ffVarmap", 
+        "\u00ffLexenv", 
+        "\u00ffVarenv", 
+        "\u00ffSource", 
+        "\u00ffPc2line", 
+        "\u00ffArgs", 
+        "\u00ffMap", 
+        "\u00ffFinalizer", 
+        "\u00ffHandler", 
+        "\u00ffCallee", 
+        "\u00ffThread", 
+        "\u00ffRegbase", 
+        "\u00ffTarget", 
+        "\u00ffThis", 
+        "compile", 
+        "input", 
+        "errCreate", 
+        "errThrow", 
+        "modSearch", 
+        "modLoaded", 
+        "env", 
+        "hex", 
+        "base64", 
+        "jx", 
+        "jc", 
+        "resume", 
+        "fmt", 
+        "raw", 
+        "trace", 
+        "debug", 
+        "info", 
+        "warn", 
+        "error", 
+        "fatal", 
+        "n", 
+        "l", 
+        "clog", 
+        "toLogString", 
+        "{\"_undef\":true}", 
+        "{\"_nan\":true}", 
+        "{\"_inf\":true}", 
+        "{\"_ninf\":true}", 
+        "{\"_func\":true}", 
+        "{_func:true}", 
+        "break", 
+        "case", 
+        "catch", 
+        "continue", 
+        "debugger", 
+        "default", 
+        "delete", 
+        "do", 
+        "else", 
+        "finally", 
+        "for", 
+        "function", 
+        "if", 
+        "in", 
+        "instanceof", 
+        "new", 
+        "return", 
+        "switch", 
+        "this", 
+        "throw", 
+        "try", 
+        "typeof", 
+        "var", 
+        "const", 
+        "void", 
+        "while", 
+        "with", 
+        "class", 
+        "enum", 
+        "export", 
+        "extends", 
+        "import", 
+        "super", 
+        "null", 
+        "true", 
+        "false", 
+        "implements", 
+        "interface", 
+        "let", 
+        "package", 
+        "private", 
+        "protected", 
+        "public", 
+        "static", 
+        "yield"
+    ], 
+    "builtin_strings_base64": [
+        "VW5kZWZpbmVk", 
+        "TnVsbA==", 
+        "QXJndW1lbnRz", 
+        "T2JqZWN0", 
+        "RnVuY3Rpb24=", 
+        "QXJyYXk=", 
+        "U3RyaW5n", 
+        "Qm9vbGVhbg==", 
+        "TnVtYmVy", 
+        "RGF0ZQ==", 
+        "UmVnRXhw", 
+        "RXJyb3I=", 
+        "TWF0aA==", 
+        "SlNPTg==", 
+        "", 
+        "QXJyYXlCdWZmZXI=", 
+        "RGF0YVZpZXc=", 
+        "SW50OEFycmF5", 
+        "VWludDhBcnJheQ==", 
+        "VWludDhDbGFtcGVkQXJyYXk=", 
+        "SW50MTZBcnJheQ==", 
+        "VWludDE2QXJyYXk=", 
+        "SW50MzJBcnJheQ==", 
+        "VWludDMyQXJyYXk=", 
+        "RmxvYXQzMkFycmF5", 
+        "RmxvYXQ2NEFycmF5", 
+        "Z2xvYmFs", 
+        "T2JqRW52", 
+        "RGVjRW52", 
+        "QnVmZmVy", 
+        "UG9pbnRlcg==", 
+        "VGhyZWFk", 
+        "ZXZhbA==", 
+        "ZGVmaW5lUHJvcGVydHk=", 
+        "dmFsdWU=", 
+        "d3JpdGFibGU=", 
+        "Y29uZmlndXJhYmxl", 
+        "ZW51bWVyYWJsZQ==", 
+        "am9pbg==", 
+        "dG9Mb2NhbGVTdHJpbmc=", 
+        "dmFsdWVPZg==", 
+        "dG9VVENTdHJpbmc=", 
+        "dG9JU09TdHJpbmc=", 
+        "dG9HTVRTdHJpbmc=", 
+        "c291cmNl", 
+        "aWdub3JlQ2FzZQ==", 
+        "bXVsdGlsaW5l", 
+        "bGFzdEluZGV4", 
+        "KD86KQ==", 
+        "aW5kZXg=", 
+        "cHJvdG90eXBl", 
+        "Y29uc3RydWN0b3I=", 
+        "bWVzc2FnZQ==", 
+        "Ym9vbGVhbg==", 
+        "bnVtYmVy", 
+        "c3RyaW5n", 
+        "b2JqZWN0", 
+        "dW5kZWZpbmVk", 
+        "TmFO", 
+        "SW5maW5pdHk=", 
+        "LUluZmluaXR5", 
+        "LTA=", 
+        "LA==", 
+        "IA==", 
+        "CiAgICA=", 
+        "Wy4uLl0=", 
+        "SW52YWxpZCBEYXRl", 
+        "YXJndW1lbnRz", 
+        "Y2FsbGVl", 
+        "Y2FsbGVy", 
+        "aGFz", 
+        "Z2V0", 
+        "ZGVsZXRlUHJvcGVydHk=", 
+        "ZW51bWVyYXRl", 
+        "b3duS2V5cw==", 
+        "c2V0UHJvdG90eXBlT2Y=", 
+        "X19wcm90b19f", 
+        "cmVxdWlyZQ==", 
+        "aWQ=", 
+        "ZXhwb3J0cw==", 
+        "ZmlsZW5hbWU=", 
+        "dG9TdHJpbmc=", 
+        "dG9KU09O", 
+        "dHlwZQ==", 
+        "ZGF0YQ==", 
+        "bGVuZ3Ro", 
+        "Ynl0ZUxlbmd0aA==", 
+        "Ynl0ZU9mZnNldA==", 
+        "QllURVNfUEVSX0VMRU1FTlQ=", 
+        "c2V0", 
+        "c3RhY2s=", 
+        "cGM=", 
+        "bGluZU51bWJlcg==", 
+        "/1RyYWNlZGF0YQ==", 
+        "bmFtZQ==", 
+        "ZmlsZU5hbWU=", 
+        "YnVmZmVy", 
+        "cG9pbnRlcg==", 
+        "/1ZhbHVl", 
+        "/05leHQ=", 
+        "/0J5dGVjb2Rl", 
+        "/0Zvcm1hbHM=", 
+        "/1Zhcm1hcA==", 
+        "/0xleGVudg==", 
+        "/1ZhcmVudg==", 
+        "/1NvdXJjZQ==", 
+        "/1BjMmxpbmU=", 
+        "/0FyZ3M=", 
+        "/01hcA==", 
+        "/0ZpbmFsaXplcg==", 
+        "/0hhbmRsZXI=", 
+        "/0NhbGxlZQ==", 
+        "/1RocmVhZA==", 
+        "/1JlZ2Jhc2U=", 
+        "/1RhcmdldA==", 
+        "/1RoaXM=", 
+        "Y29tcGlsZQ==", 
+        "aW5wdXQ=", 
+        "ZXJyQ3JlYXRl", 
+        "ZXJyVGhyb3c=", 
+        "bW9kU2VhcmNo", 
+        "bW9kTG9hZGVk", 
+        "ZW52", 
+        "aGV4", 
+        "YmFzZTY0", 
+        "ang=", 
+        "amM=", 
+        "cmVzdW1l", 
+        "Zm10", 
+        "cmF3", 
+        "dHJhY2U=", 
+        "ZGVidWc=", 
+        "aW5mbw==", 
+        "d2Fybg==", 
+        "ZXJyb3I=", 
+        "ZmF0YWw=", 
+        "bg==", 
+        "bA==", 
+        "Y2xvZw==", 
+        "dG9Mb2dTdHJpbmc=", 
+        "eyJfdW5kZWYiOnRydWV9", 
+        "eyJfbmFuIjp0cnVlfQ==", 
+        "eyJfaW5mIjp0cnVlfQ==", 
+        "eyJfbmluZiI6dHJ1ZX0=", 
+        "eyJfZnVuYyI6dHJ1ZX0=", 
+        "e19mdW5jOnRydWV9", 
+        "YnJlYWs=", 
+        "Y2FzZQ==", 
+        "Y2F0Y2g=", 
+        "Y29udGludWU=", 
+        "ZGVidWdnZXI=", 
+        "ZGVmYXVsdA==", 
+        "ZGVsZXRl", 
+        "ZG8=", 
+        "ZWxzZQ==", 
+        "ZmluYWxseQ==", 
+        "Zm9y", 
+        "ZnVuY3Rpb24=", 
+        "aWY=", 
+        "aW4=", 
+        "aW5zdGFuY2VvZg==", 
+        "bmV3", 
+        "cmV0dXJu", 
+        "c3dpdGNo", 
+        "dGhpcw==", 
+        "dGhyb3c=", 
+        "dHJ5", 
+        "dHlwZW9m", 
+        "dmFy", 
+        "Y29uc3Q=", 
+        "dm9pZA==", 
+        "d2hpbGU=", 
+        "d2l0aA==", 
+        "Y2xhc3M=", 
+        "ZW51bQ==", 
+        "ZXhwb3J0", 
+        "ZXh0ZW5kcw==", 
+        "aW1wb3J0", 
+        "c3VwZXI=", 
+        "bnVsbA==", 
+        "dHJ1ZQ==", 
+        "ZmFsc2U=", 
+        "aW1wbGVtZW50cw==", 
+        "aW50ZXJmYWNl", 
+        "bGV0", 
+        "cGFja2FnZQ==", 
+        "cHJpdmF0ZQ==", 
+        "cHJvdGVjdGVk", 
+        "cHVibGlj", 
+        "c3RhdGlj", 
+        "eWllbGQ="
+    ], 
+    "builtin_strings_info": [
+        {
+            "base64": "VW5kZWZpbmVk", 
+            "define": "DUK_STRIDX_UC_UNDEFINED", 
+            "plain": "Undefined"
+        }, 
+        {
+            "base64": "TnVsbA==", 
+            "define": "DUK_STRIDX_UC_NULL", 
+            "plain": "Null"
+        }, 
+        {
+            "base64": "QXJndW1lbnRz", 
+            "define": "DUK_STRIDX_UC_ARGUMENTS", 
+            "plain": "Arguments"
+        }, 
+        {
+            "base64": "T2JqZWN0", 
+            "define": "DUK_STRIDX_UC_OBJECT", 
+            "plain": "Object"
+        }, 
+        {
+            "base64": "RnVuY3Rpb24=", 
+            "define": "DUK_STRIDX_UC_FUNCTION", 
+            "plain": "Function"
+        }, 
+        {
+            "base64": "QXJyYXk=", 
+            "define": "DUK_STRIDX_ARRAY", 
+            "plain": "Array"
+        }, 
+        {
+            "base64": "U3RyaW5n", 
+            "define": "DUK_STRIDX_UC_STRING", 
+            "plain": "String"
+        }, 
+        {
+            "base64": "Qm9vbGVhbg==", 
+            "define": "DUK_STRIDX_UC_BOOLEAN", 
+            "plain": "Boolean"
+        }, 
+        {
+            "base64": "TnVtYmVy", 
+            "define": "DUK_STRIDX_UC_NUMBER", 
+            "plain": "Number"
+        }, 
+        {
+            "base64": "RGF0ZQ==", 
+            "define": "DUK_STRIDX_DATE", 
+            "plain": "Date"
+        }, 
+        {
+            "base64": "UmVnRXhw", 
+            "define": "DUK_STRIDX_REG_EXP", 
+            "plain": "RegExp"
+        }, 
+        {
+            "base64": "RXJyb3I=", 
+            "define": "DUK_STRIDX_UC_ERROR", 
+            "plain": "Error"
+        }, 
+        {
+            "base64": "TWF0aA==", 
+            "define": "DUK_STRIDX_MATH", 
+            "plain": "Math"
+        }, 
+        {
+            "base64": "SlNPTg==", 
+            "define": "DUK_STRIDX_JSON", 
+            "plain": "JSON"
+        }, 
+        {
+            "base64": "", 
+            "define": "DUK_STRIDX_EMPTY_STRING", 
+            "plain": ""
+        }, 
+        {
+            "base64": "QXJyYXlCdWZmZXI=", 
+            "define": "DUK_STRIDX_ARRAY_BUFFER", 
+            "plain": "ArrayBuffer"
+        }, 
+        {
+            "base64": "RGF0YVZpZXc=", 
+            "define": "DUK_STRIDX_DATA_VIEW", 
+            "plain": "DataView"
+        }, 
+        {
+            "base64": "SW50OEFycmF5", 
+            "define": "DUK_STRIDX_INT8_ARRAY", 
+            "plain": "Int8Array"
+        }, 
+        {
+            "base64": "VWludDhBcnJheQ==", 
+            "define": "DUK_STRIDX_UINT8_ARRAY", 
+            "plain": "Uint8Array"
+        }, 
+        {
+            "base64": "VWludDhDbGFtcGVkQXJyYXk=", 
+            "define": "DUK_STRIDX_UINT8_CLAMPED_ARRAY", 
+            "plain": "Uint8ClampedArray"
+        }, 
+        {
+            "base64": "SW50MTZBcnJheQ==", 
+            "define": "DUK_STRIDX_INT16_ARRAY", 
+            "plain": "Int16Array"
+        }, 
+        {
+            "base64": "VWludDE2QXJyYXk=", 
+            "define": "DUK_STRIDX_UINT16_ARRAY", 
+            "plain": "Uint16Array"
+        }, 
+        {
+            "base64": "SW50MzJBcnJheQ==", 
+            "define": "DUK_STRIDX_INT32_ARRAY", 
+            "plain": "Int32Array"
+        }, 
+        {
+            "base64": "VWludDMyQXJyYXk=", 
+            "define": "DUK_STRIDX_UINT32_ARRAY", 
+            "plain": "Uint32Array"
+        }, 
+        {
+            "base64": "RmxvYXQzMkFycmF5", 
+            "define": "DUK_STRIDX_FLOAT32_ARRAY", 
+            "plain": "Float32Array"
+        }, 
+        {
+            "base64": "RmxvYXQ2NEFycmF5", 
+            "define": "DUK_STRIDX_FLOAT64_ARRAY", 
+            "plain": "Float64Array"
+        }, 
+        {
+            "base64": "Z2xvYmFs", 
+            "define": "DUK_STRIDX_GLOBAL", 
+            "plain": "global"
+        }, 
+        {
+            "base64": "T2JqRW52", 
+            "define": "DUK_STRIDX_OBJ_ENV", 
+            "plain": "ObjEnv"
+        }, 
+        {
+            "base64": "RGVjRW52", 
+            "define": "DUK_STRIDX_DEC_ENV", 
+            "plain": "DecEnv"
+        }, 
+        {
+            "base64": "QnVmZmVy", 
+            "define": "DUK_STRIDX_UC_BUFFER", 
+            "plain": "Buffer"
+        }, 
+        {
+            "base64": "UG9pbnRlcg==", 
+            "define": "DUK_STRIDX_UC_POINTER", 
+            "plain": "Pointer"
+        }, 
+        {
+            "base64": "VGhyZWFk", 
+            "define": "DUK_STRIDX_UC_THREAD", 
+            "plain": "Thread"
+        }, 
+        {
+            "base64": "ZXZhbA==", 
+            "define": "DUK_STRIDX_EVAL", 
+            "plain": "eval"
+        }, 
+        {
+            "base64": "ZGVmaW5lUHJvcGVydHk=", 
+            "define": "DUK_STRIDX_DEFINE_PROPERTY", 
+            "plain": "defineProperty"
+        }, 
+        {
+            "base64": "dmFsdWU=", 
+            "define": "DUK_STRIDX_VALUE", 
+            "plain": "value"
+        }, 
+        {
+            "base64": "d3JpdGFibGU=", 
+            "define": "DUK_STRIDX_WRITABLE", 
+            "plain": "writable"
+        }, 
+        {
+            "base64": "Y29uZmlndXJhYmxl", 
+            "define": "DUK_STRIDX_CONFIGURABLE", 
+            "plain": "configurable"
+        }, 
+        {
+            "base64": "ZW51bWVyYWJsZQ==", 
+            "define": "DUK_STRIDX_ENUMERABLE", 
+            "plain": "enumerable"
+        }, 
+        {
+            "base64": "am9pbg==", 
+            "define": "DUK_STRIDX_JOIN", 
+            "plain": "join"
+        }, 
+        {
+            "base64": "dG9Mb2NhbGVTdHJpbmc=", 
+            "define": "DUK_STRIDX_TO_LOCALE_STRING", 
+            "plain": "toLocaleString"
+        }, 
+        {
+            "base64": "dmFsdWVPZg==", 
+            "define": "DUK_STRIDX_VALUE_OF", 
+            "plain": "valueOf"
+        }, 
+        {
+            "base64": "dG9VVENTdHJpbmc=", 
+            "define": "DUK_STRIDX_TO_UTC_STRING", 
+            "plain": "toUTCString"
+        }, 
+        {
+            "base64": "dG9JU09TdHJpbmc=", 
+            "define": "DUK_STRIDX_TO_ISO_STRING", 
+            "plain": "toISOString"
+        }, 
+        {
+            "base64": "dG9HTVRTdHJpbmc=", 
+            "define": "DUK_STRIDX_TO_GMT_STRING", 
+            "plain": "toGMTString"
+        }, 
+        {
+            "base64": "c291cmNl", 
+            "define": "DUK_STRIDX_SOURCE", 
+            "plain": "source"
+        }, 
+        {
+            "base64": "aWdub3JlQ2FzZQ==", 
+            "define": "DUK_STRIDX_IGNORE_CASE", 
+            "plain": "ignoreCase"
+        }, 
+        {
+            "base64": "bXVsdGlsaW5l", 
+            "define": "DUK_STRIDX_MULTILINE", 
+            "plain": "multiline"
+        }, 
+        {
+            "base64": "bGFzdEluZGV4", 
+            "define": "DUK_STRIDX_LAST_INDEX", 
+            "plain": "lastIndex"
+        }, 
+        {
+            "base64": "KD86KQ==", 
+            "define": "DUK_STRIDX_ESCAPED_EMPTY_REGEXP", 
+            "plain": "(?:)"
+        }, 
+        {
+            "base64": "aW5kZXg=", 
+            "define": "DUK_STRIDX_INDEX", 
+            "plain": "index"
+        }, 
+        {
+            "base64": "cHJvdG90eXBl", 
+            "define": "DUK_STRIDX_PROTOTYPE", 
+            "plain": "prototype"
+        }, 
+        {
+            "base64": "Y29uc3RydWN0b3I=", 
+            "define": "DUK_STRIDX_CONSTRUCTOR", 
+            "plain": "constructor"
+        }, 
+        {
+            "base64": "bWVzc2FnZQ==", 
+            "define": "DUK_STRIDX_MESSAGE", 
+            "plain": "message"
+        }, 
+        {
+            "base64": "Ym9vbGVhbg==", 
+            "define": "DUK_STRIDX_LC_BOOLEAN", 
+            "plain": "boolean"
+        }, 
+        {
+            "base64": "bnVtYmVy", 
+            "define": "DUK_STRIDX_LC_NUMBER", 
+            "plain": "number"
+        }, 
+        {
+            "base64": "c3RyaW5n", 
+            "define": "DUK_STRIDX_LC_STRING", 
+            "plain": "string"
+        }, 
+        {
+            "base64": "b2JqZWN0", 
+            "define": "DUK_STRIDX_LC_OBJECT", 
+            "plain": "object"
+        }, 
+        {
+            "base64": "dW5kZWZpbmVk", 
+            "define": "DUK_STRIDX_LC_UNDEFINED", 
+            "plain": "undefined"
+        }, 
+        {
+            "base64": "TmFO", 
+            "define": "DUK_STRIDX_NAN", 
+            "plain": "NaN"
+        }, 
+        {
+            "base64": "SW5maW5pdHk=", 
+            "define": "DUK_STRIDX_INFINITY", 
+            "plain": "Infinity"
+        }, 
+        {
+            "base64": "LUluZmluaXR5", 
+            "define": "DUK_STRIDX_MINUS_INFINITY", 
+            "plain": "-Infinity"
+        }, 
+        {
+            "base64": "LTA=", 
+            "define": "DUK_STRIDX_MINUS_ZERO", 
+            "plain": "-0"
+        }, 
+        {
+            "base64": "LA==", 
+            "define": "DUK_STRIDX_COMMA", 
+            "plain": ","
+        }, 
+        {
+            "base64": "IA==", 
+            "define": "DUK_STRIDX_SPACE", 
+            "plain": " "
+        }, 
+        {
+            "base64": "CiAgICA=", 
+            "define": "DUK_STRIDX_NEWLINE_4SPACE", 
+            "plain": "\n    "
+        }, 
+        {
+            "base64": "Wy4uLl0=", 
+            "define": "DUK_STRIDX_BRACKETED_ELLIPSIS", 
+            "plain": "[...]"
+        }, 
+        {
+            "base64": "SW52YWxpZCBEYXRl", 
+            "define": "DUK_STRIDX_INVALID_DATE", 
+            "plain": "Invalid Date"
+        }, 
+        {
+            "base64": "YXJndW1lbnRz", 
+            "define": "DUK_STRIDX_LC_ARGUMENTS", 
+            "plain": "arguments"
+        }, 
+        {
+            "base64": "Y2FsbGVl", 
+            "define": "DUK_STRIDX_CALLEE", 
+            "plain": "callee"
+        }, 
+        {
+            "base64": "Y2FsbGVy", 
+            "define": "DUK_STRIDX_CALLER", 
+            "plain": "caller"
+        }, 
+        {
+            "base64": "aGFz", 
+            "define": "DUK_STRIDX_HAS", 
+            "plain": "has"
+        }, 
+        {
+            "base64": "Z2V0", 
+            "define": "DUK_STRIDX_GET", 
+            "plain": "get"
+        }, 
+        {
+            "base64": "ZGVsZXRlUHJvcGVydHk=", 
+            "define": "DUK_STRIDX_DELETE_PROPERTY", 
+            "plain": "deleteProperty"
+        }, 
+        {
+            "base64": "ZW51bWVyYXRl", 
+            "define": "DUK_STRIDX_ENUMERATE", 
+            "plain": "enumerate"
+        }, 
+        {
+            "base64": "b3duS2V5cw==", 
+            "define": "DUK_STRIDX_OWN_KEYS", 
+            "plain": "ownKeys"
+        }, 
+        {
+            "base64": "c2V0UHJvdG90eXBlT2Y=", 
+            "define": "DUK_STRIDX_SET_PROTOTYPE_OF", 
+            "plain": "setPrototypeOf"
+        }, 
+        {
+            "base64": "X19wcm90b19f", 
+            "define": "DUK_STRIDX___PROTO__", 
+            "plain": "__proto__"
+        }, 
+        {
+            "base64": "cmVxdWlyZQ==", 
+            "define": "DUK_STRIDX_REQUIRE", 
+            "plain": "require"
+        }, 
+        {
+            "base64": "aWQ=", 
+            "define": "DUK_STRIDX_ID", 
+            "plain": "id"
+        }, 
+        {
+            "base64": "ZXhwb3J0cw==", 
+            "define": "DUK_STRIDX_EXPORTS", 
+            "plain": "exports"
+        }, 
+        {
+            "base64": "ZmlsZW5hbWU=", 
+            "define": "DUK_STRIDX_FILENAME", 
+            "plain": "filename"
+        }, 
+        {
+            "base64": "dG9TdHJpbmc=", 
+            "define": "DUK_STRIDX_TO_STRING", 
+            "plain": "toString"
+        }, 
+        {
+            "base64": "dG9KU09O", 
+            "define": "DUK_STRIDX_TO_JSON", 
+            "plain": "toJSON"
+        }, 
+        {
+            "base64": "dHlwZQ==", 
+            "define": "DUK_STRIDX_TYPE", 
+            "plain": "type"
+        }, 
+        {
+            "base64": "ZGF0YQ==", 
+            "define": "DUK_STRIDX_DATA", 
+            "plain": "data"
+        }, 
+        {
+            "base64": "bGVuZ3Ro", 
+            "define": "DUK_STRIDX_LENGTH", 
+            "plain": "length"
+        }, 
+        {
+            "base64": "Ynl0ZUxlbmd0aA==", 
+            "define": "DUK_STRIDX_BYTE_LENGTH", 
+            "plain": "byteLength"
+        }, 
+        {
+            "base64": "Ynl0ZU9mZnNldA==", 
+            "define": "DUK_STRIDX_BYTE_OFFSET", 
+            "plain": "byteOffset"
+        }, 
+        {
+            "base64": "QllURVNfUEVSX0VMRU1FTlQ=", 
+            "define": "DUK_STRIDX_BYTES_PER_ELEMENT", 
+            "plain": "BYTES_PER_ELEMENT"
+        }, 
+        {
+            "base64": "c2V0", 
+            "define": "DUK_STRIDX_SET", 
+            "plain": "set"
+        }, 
+        {
+            "base64": "c3RhY2s=", 
+            "define": "DUK_STRIDX_STACK", 
+            "plain": "stack"
+        }, 
+        {
+            "base64": "cGM=", 
+            "define": "DUK_STRIDX_PC", 
+            "plain": "pc"
+        }, 
+        {
+            "base64": "bGluZU51bWJlcg==", 
+            "define": "DUK_STRIDX_LINE_NUMBER", 
+            "plain": "lineNumber"
+        }, 
+        {
+            "base64": "/1RyYWNlZGF0YQ==", 
+            "define": "DUK_STRIDX_INT_TRACEDATA", 
+            "plain": "\u00ffTracedata"
+        }, 
+        {
+            "base64": "bmFtZQ==", 
+            "define": "DUK_STRIDX_NAME", 
+            "plain": "name"
+        }, 
+        {
+            "base64": "ZmlsZU5hbWU=", 
+            "define": "DUK_STRIDX_FILE_NAME", 
+            "plain": "fileName"
+        }, 
+        {
+            "base64": "YnVmZmVy", 
+            "define": "DUK_STRIDX_LC_BUFFER", 
+            "plain": "buffer"
+        }, 
+        {
+            "base64": "cG9pbnRlcg==", 
+            "define": "DUK_STRIDX_LC_POINTER", 
+            "plain": "pointer"
+        }, 
+        {
+            "base64": "/1ZhbHVl", 
+            "define": "DUK_STRIDX_INT_VALUE", 
+            "plain": "\u00ffValue"
+        }, 
+        {
+            "base64": "/05leHQ=", 
+            "define": "DUK_STRIDX_INT_NEXT", 
+            "plain": "\u00ffNext"
+        }, 
+        {
+            "base64": "/0J5dGVjb2Rl", 
+            "define": "DUK_STRIDX_INT_BYTECODE", 
+            "plain": "\u00ffBytecode"
+        }, 
+        {
+            "base64": "/0Zvcm1hbHM=", 
+            "define": "DUK_STRIDX_INT_FORMALS", 
+            "plain": "\u00ffFormals"
+        }, 
+        {
+            "base64": "/1Zhcm1hcA==", 
+            "define": "DUK_STRIDX_INT_VARMAP", 
+            "plain": "\u00ffVarmap"
+        }, 
+        {
+            "base64": "/0xleGVudg==", 
+            "define": "DUK_STRIDX_INT_LEXENV", 
+            "plain": "\u00ffLexenv"
+        }, 
+        {
+            "base64": "/1ZhcmVudg==", 
+            "define": "DUK_STRIDX_INT_VARENV", 
+            "plain": "\u00ffVarenv"
+        }, 
+        {
+            "base64": "/1NvdXJjZQ==", 
+            "define": "DUK_STRIDX_INT_SOURCE", 
+            "plain": "\u00ffSource"
+        }, 
+        {
+            "base64": "/1BjMmxpbmU=", 
+            "define": "DUK_STRIDX_INT_PC2LINE", 
+            "plain": "\u00ffPc2line"
+        }, 
+        {
+            "base64": "/0FyZ3M=", 
+            "define": "DUK_STRIDX_INT_ARGS", 
+            "plain": "\u00ffArgs"
+        }, 
+        {
+            "base64": "/01hcA==", 
+            "define": "DUK_STRIDX_INT_MAP", 
+            "plain": "\u00ffMap"
+        }, 
+        {
+            "base64": "/0ZpbmFsaXplcg==", 
+            "define": "DUK_STRIDX_INT_FINALIZER", 
+            "plain": "\u00ffFinalizer"
+        }, 
+        {
+            "base64": "/0hhbmRsZXI=", 
+            "define": "DUK_STRIDX_INT_HANDLER", 
+            "plain": "\u00ffHandler"
+        }, 
+        {
+            "base64": "/0NhbGxlZQ==", 
+            "define": "DUK_STRIDX_INT_CALLEE", 
+            "plain": "\u00ffCallee"
+        }, 
+        {
+            "base64": "/1RocmVhZA==", 
+            "define": "DUK_STRIDX_INT_THREAD", 
+            "plain": "\u00ffThread"
+        }, 
+        {
+            "base64": "/1JlZ2Jhc2U=", 
+            "define": "DUK_STRIDX_INT_REGBASE", 
+            "plain": "\u00ffRegbase"
+        }, 
+        {
+            "base64": "/1RhcmdldA==", 
+            "define": "DUK_STRIDX_INT_TARGET", 
+            "plain": "\u00ffTarget"
+        }, 
+        {
+            "base64": "/1RoaXM=", 
+            "define": "DUK_STRIDX_INT_THIS", 
+            "plain": "\u00ffThis"
+        }, 
+        {
+            "base64": "Y29tcGlsZQ==", 
+            "define": "DUK_STRIDX_COMPILE", 
+            "plain": "compile"
+        }, 
+        {
+            "base64": "aW5wdXQ=", 
+            "define": "DUK_STRIDX_INPUT", 
+            "plain": "input"
+        }, 
+        {
+            "base64": "ZXJyQ3JlYXRl", 
+            "define": "DUK_STRIDX_ERR_CREATE", 
+            "plain": "errCreate"
+        }, 
+        {
+            "base64": "ZXJyVGhyb3c=", 
+            "define": "DUK_STRIDX_ERR_THROW", 
+            "plain": "errThrow"
+        }, 
+        {
+            "base64": "bW9kU2VhcmNo", 
+            "define": "DUK_STRIDX_MOD_SEARCH", 
+            "plain": "modSearch"
+        }, 
+        {
+            "base64": "bW9kTG9hZGVk", 
+            "define": "DUK_STRIDX_MOD_LOADED", 
+            "plain": "modLoaded"
+        }, 
+        {
+            "base64": "ZW52", 
+            "define": "DUK_STRIDX_ENV", 
+            "plain": "env"
+        }, 
+        {
+            "base64": "aGV4", 
+            "define": "DUK_STRIDX_HEX", 
+            "plain": "hex"
+        }, 
+        {
+            "base64": "YmFzZTY0", 
+            "define": "DUK_STRIDX_BASE64", 
+            "plain": "base64"
+        }, 
+        {
+            "base64": "ang=", 
+            "define": "DUK_STRIDX_JX", 
+            "plain": "jx"
+        }, 
+        {
+            "base64": "amM=", 
+            "define": "DUK_STRIDX_JC", 
+            "plain": "jc"
+        }, 
+        {
+            "base64": "cmVzdW1l", 
+            "define": "DUK_STRIDX_RESUME", 
+            "plain": "resume"
+        }, 
+        {
+            "base64": "Zm10", 
+            "define": "DUK_STRIDX_FMT", 
+            "plain": "fmt"
+        }, 
+        {
+            "base64": "cmF3", 
+            "define": "DUK_STRIDX_RAW", 
+            "plain": "raw"
+        }, 
+        {
+            "base64": "dHJhY2U=", 
+            "define": "DUK_STRIDX_LC_TRACE", 
+            "plain": "trace"
+        }, 
+        {
+            "base64": "ZGVidWc=", 
+            "define": "DUK_STRIDX_LC_DEBUG", 
+            "plain": "debug"
+        }, 
+        {
+            "base64": "aW5mbw==", 
+            "define": "DUK_STRIDX_LC_INFO", 
+            "plain": "info"
+        }, 
+        {
+            "base64": "d2Fybg==", 
+            "define": "DUK_STRIDX_LC_WARN", 
+            "plain": "warn"
+        }, 
+        {
+            "base64": "ZXJyb3I=", 
+            "define": "DUK_STRIDX_LC_ERROR", 
+            "plain": "error"
+        }, 
+        {
+            "base64": "ZmF0YWw=", 
+            "define": "DUK_STRIDX_LC_FATAL", 
+            "plain": "fatal"
+        }, 
+        {
+            "base64": "bg==", 
+            "define": "DUK_STRIDX_LC_N", 
+            "plain": "n"
+        }, 
+        {
+            "base64": "bA==", 
+            "define": "DUK_STRIDX_LC_L", 
+            "plain": "l"
+        }, 
+        {
+            "base64": "Y2xvZw==", 
+            "define": "DUK_STRIDX_CLOG", 
+            "plain": "clog"
+        }, 
+        {
+            "base64": "dG9Mb2dTdHJpbmc=", 
+            "define": "DUK_STRIDX_TO_LOG_STRING", 
+            "plain": "toLogString"
+        }, 
+        {
+            "base64": "eyJfdW5kZWYiOnRydWV9", 
+            "define": "DUK_STRIDX_JSON_EXT_UNDEFINED", 
+            "plain": "{\"_undef\":true}"
+        }, 
+        {
+            "base64": "eyJfbmFuIjp0cnVlfQ==", 
+            "define": "DUK_STRIDX_JSON_EXT_NAN", 
+            "plain": "{\"_nan\":true}"
+        }, 
+        {
+            "base64": "eyJfaW5mIjp0cnVlfQ==", 
+            "define": "DUK_STRIDX_JSON_EXT_POSINF", 
+            "plain": "{\"_inf\":true}"
+        }, 
+        {
+            "base64": "eyJfbmluZiI6dHJ1ZX0=", 
+            "define": "DUK_STRIDX_JSON_EXT_NEGINF", 
+            "plain": "{\"_ninf\":true}"
+        }, 
+        {
+            "base64": "eyJfZnVuYyI6dHJ1ZX0=", 
+            "define": "DUK_STRIDX_JSON_EXT_FUNCTION1", 
+            "plain": "{\"_func\":true}"
+        }, 
+        {
+            "base64": "e19mdW5jOnRydWV9", 
+            "define": "DUK_STRIDX_JSON_EXT_FUNCTION2", 
+            "plain": "{_func:true}"
+        }, 
+        {
+            "base64": "YnJlYWs=", 
+            "define": "DUK_STRIDX_BREAK", 
+            "plain": "break"
+        }, 
+        {
+            "base64": "Y2FzZQ==", 
+            "define": "DUK_STRIDX_CASE", 
+            "plain": "case"
+        }, 
+        {
+            "base64": "Y2F0Y2g=", 
+            "define": "DUK_STRIDX_CATCH", 
+            "plain": "catch"
+        }, 
+        {
+            "base64": "Y29udGludWU=", 
+            "define": "DUK_STRIDX_CONTINUE", 
+            "plain": "continue"
+        }, 
+        {
+            "base64": "ZGVidWdnZXI=", 
+            "define": "DUK_STRIDX_DEBUGGER", 
+            "plain": "debugger"
+        }, 
+        {
+            "base64": "ZGVmYXVsdA==", 
+            "define": "DUK_STRIDX_DEFAULT", 
+            "plain": "default"
+        }, 
+        {
+            "base64": "ZGVsZXRl", 
+            "define": "DUK_STRIDX_DELETE", 
+            "plain": "delete"
+        }, 
+        {
+            "base64": "ZG8=", 
+            "define": "DUK_STRIDX_DO", 
+            "plain": "do"
+        }, 
+        {
+            "base64": "ZWxzZQ==", 
+            "define": "DUK_STRIDX_ELSE", 
+            "plain": "else"
+        }, 
+        {
+            "base64": "ZmluYWxseQ==", 
+            "define": "DUK_STRIDX_FINALLY", 
+            "plain": "finally"
+        }, 
+        {
+            "base64": "Zm9y", 
+            "define": "DUK_STRIDX_FOR", 
+            "plain": "for"
+        }, 
+        {
+            "base64": "ZnVuY3Rpb24=", 
+            "define": "DUK_STRIDX_LC_FUNCTION", 
+            "plain": "function"
+        }, 
+        {
+            "base64": "aWY=", 
+            "define": "DUK_STRIDX_IF", 
+            "plain": "if"
+        }, 
+        {
+            "base64": "aW4=", 
+            "define": "DUK_STRIDX_IN", 
+            "plain": "in"
+        }, 
+        {
+            "base64": "aW5zdGFuY2VvZg==", 
+            "define": "DUK_STRIDX_INSTANCEOF", 
+            "plain": "instanceof"
+        }, 
+        {
+            "base64": "bmV3", 
+            "define": "DUK_STRIDX_NEW", 
+            "plain": "new"
+        }, 
+        {
+            "base64": "cmV0dXJu", 
+            "define": "DUK_STRIDX_RETURN", 
+            "plain": "return"
+        }, 
+        {
+            "base64": "c3dpdGNo", 
+            "define": "DUK_STRIDX_SWITCH", 
+            "plain": "switch"
+        }, 
+        {
+            "base64": "dGhpcw==", 
+            "define": "DUK_STRIDX_THIS", 
+            "plain": "this"
+        }, 
+        {
+            "base64": "dGhyb3c=", 
+            "define": "DUK_STRIDX_THROW", 
+            "plain": "throw"
+        }, 
+        {
+            "base64": "dHJ5", 
+            "define": "DUK_STRIDX_TRY", 
+            "plain": "try"
+        }, 
+        {
+            "base64": "dHlwZW9m", 
+            "define": "DUK_STRIDX_TYPEOF", 
+            "plain": "typeof"
+        }, 
+        {
+            "base64": "dmFy", 
+            "define": "DUK_STRIDX_VAR", 
+            "plain": "var"
+        }, 
+        {
+            "base64": "Y29uc3Q=", 
+            "define": "DUK_STRIDX_CONST", 
+            "plain": "const"
+        }, 
+        {
+            "base64": "dm9pZA==", 
+            "define": "DUK_STRIDX_VOID", 
+            "plain": "void"
+        }, 
+        {
+            "base64": "d2hpbGU=", 
+            "define": "DUK_STRIDX_WHILE", 
+            "plain": "while"
+        }, 
+        {
+            "base64": "d2l0aA==", 
+            "define": "DUK_STRIDX_WITH", 
+            "plain": "with"
+        }, 
+        {
+            "base64": "Y2xhc3M=", 
+            "define": "DUK_STRIDX_CLASS", 
+            "plain": "class"
+        }, 
+        {
+            "base64": "ZW51bQ==", 
+            "define": "DUK_STRIDX_ENUM", 
+            "plain": "enum"
+        }, 
+        {
+            "base64": "ZXhwb3J0", 
+            "define": "DUK_STRIDX_EXPORT", 
+            "plain": "export"
+        }, 
+        {
+            "base64": "ZXh0ZW5kcw==", 
+            "define": "DUK_STRIDX_EXTENDS", 
+            "plain": "extends"
+        }, 
+        {
+            "base64": "aW1wb3J0", 
+            "define": "DUK_STRIDX_IMPORT", 
+            "plain": "import"
+        }, 
+        {
+            "base64": "c3VwZXI=", 
+            "define": "DUK_STRIDX_SUPER", 
+            "plain": "super"
+        }, 
+        {
+            "base64": "bnVsbA==", 
+            "define": "DUK_STRIDX_LC_NULL", 
+            "plain": "null"
+        }, 
+        {
+            "base64": "dHJ1ZQ==", 
+            "define": "DUK_STRIDX_TRUE", 
+            "plain": "true"
+        }, 
+        {
+            "base64": "ZmFsc2U=", 
+            "define": "DUK_STRIDX_FALSE", 
+            "plain": "false"
+        }, 
+        {
+            "base64": "aW1wbGVtZW50cw==", 
+            "define": "DUK_STRIDX_IMPLEMENTS", 
+            "plain": "implements"
+        }, 
+        {
+            "base64": "aW50ZXJmYWNl", 
+            "define": "DUK_STRIDX_INTERFACE", 
+            "plain": "interface"
+        }, 
+        {
+            "base64": "bGV0", 
+            "define": "DUK_STRIDX_LET", 
+            "plain": "let"
+        }, 
+        {
+            "base64": "cGFja2FnZQ==", 
+            "define": "DUK_STRIDX_PACKAGE", 
+            "plain": "package"
+        }, 
+        {
+            "base64": "cHJpdmF0ZQ==", 
+            "define": "DUK_STRIDX_PRIVATE", 
+            "plain": "private"
+        }, 
+        {
+            "base64": "cHJvdGVjdGVk", 
+            "define": "DUK_STRIDX_PROTECTED", 
+            "plain": "protected"
+        }, 
+        {
+            "base64": "cHVibGlj", 
+            "define": "DUK_STRIDX_PUBLIC", 
+            "plain": "public"
+        }, 
+        {
+            "base64": "c3RhdGlj", 
+            "define": "DUK_STRIDX_STATIC", 
+            "plain": "static"
+        }, 
+        {
+            "base64": "eWllbGQ=", 
+            "define": "DUK_STRIDX_YIELD", 
+            "plain": "yield"
+        }
+    ], 
+    "comment": "Metadata for Duktape build", 
+    "duk_version": 10502, 
+    "duk_version_string": "1.5.2", 
+    "git_describe": "v1.5.2"
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/README.rst
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/README.rst b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/README.rst
new file mode 100644
index 0000000..f254432
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/README.rst
@@ -0,0 +1,10 @@
+================
+Duktape examples
+================
+
+Examples for using Duktape.  These support user documentation and are
+intended as informative illustrations only.
+
+Examples are unmaintained and are not production quality code.  Bugs are
+not not necessarily fixed, unless the bug makes the example misleading
+as documentation.

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/alloc-hybrid/README.rst
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/alloc-hybrid/README.rst b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/alloc-hybrid/README.rst
new file mode 100644
index 0000000..ed63a13
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/alloc-hybrid/README.rst
@@ -0,0 +1,10 @@
+=====================
+Hybrid pool allocator
+=====================
+
+Example allocator that tries to satisfy memory allocations for small sizes
+from a set of fixed pools, but always falls back to malloc/realloc/free if
+a larger size is requested or the pools have been exhausted.
+
+This may be useful to reduce memory churn when the platform allocator does
+not handle allocations for a lot of small memory areas efficiently.

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/alloc-hybrid/duk_alloc_hybrid.c
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/alloc-hybrid/duk_alloc_hybrid.c b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/alloc-hybrid/duk_alloc_hybrid.c
new file mode 100644
index 0000000..9235b85
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/alloc-hybrid/duk_alloc_hybrid.c
@@ -0,0 +1,293 @@
+/*
+ *  Example memory allocator with pool allocation for small sizes and
+ *  fallback into malloc/realloc/free for larger sizes or when the pools
+ *  are exhausted.
+ *
+ *  Useful to reduce memory churn or work around a platform allocator
+ *  that doesn't handle a lot of small allocations efficiently.
+ */
+
+#include "duktape.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdint.h>
+
+/* Define to enable some debug printfs. */
+/* #define DUK_ALLOC_HYBRID_DEBUG */
+
+typedef struct {
+	size_t size;
+	int count;
+} pool_size_spec;
+
+static pool_size_spec pool_sizes[] = {
+	{ 32, 1024 },
+	{ 48, 2048 },
+	{ 64, 2048 },
+	{ 128, 2048 },
+	{ 256, 512 },
+	{ 1024, 64 },
+	{ 2048, 32 }
+};
+
+#define  NUM_POOLS  (sizeof(pool_sizes) / sizeof(pool_size_spec))
+
+/* This must fit into the smallest pool entry. */
+struct pool_free_entry;
+typedef struct pool_free_entry pool_free_entry;
+struct pool_free_entry {
+	pool_free_entry *next;
+};
+
+typedef struct {
+	pool_free_entry *free;
+	char *alloc_start;
+	char *alloc_end;
+	size_t size;
+	int count;
+} pool_header;
+
+typedef struct {
+	pool_header headers[NUM_POOLS];
+	size_t pool_max_size;
+	char *alloc_start;
+	char *alloc_end;
+} pool_state;
+
+#define ADDR_IN_STATE_ALLOC(st,p) \
+	((char *) (p) >= (st)->alloc_start && (char *) (p) < (st)->alloc_end)
+#define ADDR_IN_HEADER_ALLOC(hdr,p) \
+	((char *) (p) >= (hdr)->alloc_start && (char *) (p) < (hdr)->alloc_end)
+
+#ifdef DUK_ALLOC_HYBRID_DEBUG
+static void dump_pool_state(pool_state *st) {
+	pool_free_entry *free;
+	int free_len;
+	int i;
+
+	printf("=== Pool state: st=%p\n", (void *) st);
+	for (i = 0; i < (int) NUM_POOLS; i++) {
+		pool_header *hdr = st->headers + i;
+
+		for (free = hdr->free, free_len = 0; free != NULL; free = free->next) {
+			free_len++;
+		}
+
+		printf("[%d]: size %ld, count %ld, used %ld, free list len %ld\n",
+		       i, (long) hdr->size, (long) hdr->count,
+		       (long) (hdr->count - free_len),
+		       (long) free_len);
+	}
+}
+#else
+static void dump_pool_state(pool_state *st) {
+	(void) st;
+}
+#endif
+
+void *duk_alloc_hybrid_init(void) {
+	pool_state *st;
+	size_t total_size, max_size;
+	int i, j;
+	char *p;
+
+	st = (pool_state *) malloc(sizeof(pool_state));
+	if (!st) {
+		return NULL;
+	}
+	memset((void *) st, 0, sizeof(pool_state));
+	st->alloc_start = NULL;
+	st->alloc_end = NULL;
+
+	for (i = 0, total_size = 0, max_size = 0; i < (int) NUM_POOLS; i++) {
+#ifdef DUK_ALLOC_HYBRID_DEBUG
+		printf("Pool %d: size %ld, count %ld\n", i, (long) pool_sizes[i].size, (long) pool_sizes[i].count);
+#endif
+		total_size += pool_sizes[i].size * pool_sizes[i].count;
+		if (pool_sizes[i].size > max_size) {
+			max_size = pool_sizes[i].size;
+		}
+	}
+#ifdef DUK_ALLOC_HYBRID_DEBUG
+	printf("Total size %ld, max pool size %ld\n", (long) total_size, (long) max_size);
+#endif
+
+	st->alloc_start = (char *) malloc(total_size);
+	if (!st->alloc_start) {
+		free(st);
+		return NULL;
+	}
+	st->alloc_end = st->alloc_start + total_size;
+	st->pool_max_size = max_size;
+	memset((void *) st->alloc_start, 0, total_size);
+
+	for (i = 0, p = st->alloc_start; i < (int) NUM_POOLS; i++) {
+		pool_header *hdr = st->headers + i;
+
+		hdr->alloc_start = p;
+		hdr->alloc_end = p + pool_sizes[i].size * pool_sizes[i].count;
+		hdr->free = (pool_free_entry *) (void *) p;
+		hdr->size = pool_sizes[i].size;
+		hdr->count = pool_sizes[i].count;
+
+		for (j = 0; j < pool_sizes[i].count; j++) {
+			pool_free_entry *ent = (pool_free_entry *) (void *) p;
+			if (j == pool_sizes[i].count - 1) {
+				ent->next = (pool_free_entry *) NULL;
+			} else {
+				ent->next = (pool_free_entry *) (void *) (p + pool_sizes[i].size);
+			}
+			p += pool_sizes[i].size;
+		}
+	}
+
+	dump_pool_state(st);
+
+	/* Use 'st' as udata. */
+	return (void *) st;
+}
+
+void *duk_alloc_hybrid(void *udata, duk_size_t size) {
+	pool_state *st = (pool_state *) udata;
+	int i;
+	void *new_ptr;
+
+#if 0
+	dump_pool_state(st);
+#endif
+
+	if (size == 0) {
+		return NULL;
+	}
+	if (size > st->pool_max_size) {
+#ifdef DUK_ALLOC_HYBRID_DEBUG
+		printf("alloc fallback: %ld\n", (long) size);
+#endif
+		return malloc(size);
+	}
+
+	for (i = 0; i < (int) NUM_POOLS; i++) {
+		pool_header *hdr = st->headers + i;
+		if (hdr->size < size) {
+			continue;
+		}
+
+		if (hdr->free) {
+#if 0
+			printf("alloc from pool: %ld -> pool size %ld\n", (long) size, (long) hdr->size);
+#endif
+			new_ptr = (void *) hdr->free;
+			hdr->free = hdr->free->next;
+			return new_ptr;
+		} else {
+#ifdef DUK_ALLOC_HYBRID_DEBUG
+			printf("alloc out of pool entries: %ld -> pool size %ld\n", (long) size, (long) hdr->size);
+#endif
+			break;
+		}
+	}
+
+#ifdef DUK_ALLOC_HYBRID_DEBUG
+	printf("alloc fallback (out of pool): %ld\n", (long) size);
+#endif
+	return malloc(size);
+}
+
+void *duk_realloc_hybrid(void *udata, void *ptr, duk_size_t size) {
+	pool_state *st = (pool_state *) udata;
+	void *new_ptr;
+	int i;
+
+#if 0
+	dump_pool_state(st);
+#endif
+
+	if (ADDR_IN_STATE_ALLOC(st, ptr)) {
+		/* 'ptr' cannot be NULL. */
+		for (i = 0; i < (int) NUM_POOLS; i++) {
+			pool_header *hdr = st->headers + i;
+			if (ADDR_IN_HEADER_ALLOC(hdr, ptr)) {
+				if (size <= hdr->size) {
+					/* Still fits, no shrink support. */
+#if 0
+					printf("realloc original from pool: still fits, size %ld, pool size %ld\n",
+					       (long) size, (long) hdr->size);
+#endif
+					return ptr;
+				}
+
+				new_ptr = duk_alloc_hybrid(udata, size);
+				if (!new_ptr) {
+#ifdef DUK_ALLOC_HYBRID_DEBUG
+					printf("realloc original from pool: needed larger size, failed to alloc\n");
+#endif
+					return NULL;
+				}
+				memcpy(new_ptr, ptr, hdr->size);
+
+				((pool_free_entry *) ptr)->next = hdr->free;
+				hdr->free = (pool_free_entry *) ptr;
+#if 0
+				printf("realloc original from pool: size %ld, pool size %ld\n", (long) size, (long) hdr->size);
+#endif
+				return new_ptr;
+			}
+		}
+#ifdef DUK_ALLOC_HYBRID_DEBUG
+		printf("NEVER HERE\n");
+#endif
+		return NULL;
+	} else if (ptr != NULL) {
+		if (size == 0) {
+			free(ptr);
+			return NULL;
+		} else {
+#ifdef DUK_ALLOC_HYBRID_DEBUG
+			printf("realloc fallback: size %ld\n", (long) size);
+#endif
+			return realloc(ptr, size);
+		}
+	} else {
+#if 0
+		printf("realloc NULL ptr, call alloc: %ld\n", (long) size);
+#endif
+		return duk_alloc_hybrid(udata, size);
+	}
+}
+
+void duk_free_hybrid(void *udata, void *ptr) {
+	pool_state *st = (pool_state *) udata;
+	int i;
+
+#if 0
+	dump_pool_state(st);
+#endif
+
+	if (!ADDR_IN_STATE_ALLOC(st, ptr)) {
+		if (ptr == NULL) {
+			return;
+		}
+#if 0
+		printf("free out of pool: %p\n", (void *) ptr);
+#endif
+		free(ptr);
+		return;
+	}
+
+	for (i = 0; i < (int) NUM_POOLS; i++) {
+		pool_header *hdr = st->headers + i;
+		if (ADDR_IN_HEADER_ALLOC(hdr, ptr)) {
+			((pool_free_entry *) ptr)->next = hdr->free;
+			hdr->free = (pool_free_entry *) ptr;
+#if 0
+			printf("free from pool: %p\n", ptr);
+#endif
+			return;
+		}
+	}
+
+#ifdef DUK_ALLOC_HYBRID_DEBUG
+	printf("NEVER HERE\n");
+#endif
+}

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/alloc-hybrid/duk_alloc_hybrid.h
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/alloc-hybrid/duk_alloc_hybrid.h b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/alloc-hybrid/duk_alloc_hybrid.h
new file mode 100644
index 0000000..0d631d1
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/alloc-hybrid/duk_alloc_hybrid.h
@@ -0,0 +1,11 @@
+#ifndef DUK_ALLOC_HYBRID_H_INCLUDED
+#define DUK_ALLOC_HYBRID_H_INCLUDED
+
+#include "duktape.h"
+
+void *duk_alloc_hybrid_init(void);
+void *duk_alloc_hybrid(void *udata, duk_size_t size);
+void *duk_realloc_hybrid(void *udata, void *ptr, duk_size_t size);
+void duk_free_hybrid(void *udata, void *ptr);
+
+#endif  /* DUK_ALLOC_HYBRID_H_INCLUDED */

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/alloc-logging/README.rst
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/alloc-logging/README.rst b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/alloc-logging/README.rst
new file mode 100644
index 0000000..97c1a32
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/alloc-logging/README.rst
@@ -0,0 +1,7 @@
+======================
+Allocator with logging
+======================
+
+Example allocator that writes all memory alloc/realloc/free calls into a
+log file so that memory usage can replayed later.  This is useful to e.g.
+optimize pool sizes.

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/alloc-logging/duk_alloc_logging.c
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/alloc-logging/duk_alloc_logging.c b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/alloc-logging/duk_alloc_logging.c
new file mode 100644
index 0000000..a89babf
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/alloc-logging/duk_alloc_logging.c
@@ -0,0 +1,138 @@
+/*
+ *  Example memory allocator with machine parseable logging.
+ *
+ *  Also sizes for reallocs and frees are logged so that the memory
+ *  behavior can be essentially replayed to accurately determine e.g.
+ *  optimal pool sizes for a pooled allocator.
+ *
+ *  Allocation structure:
+ *
+ *    [ alloc_hdr | user area ]
+ *
+ *     ^           ^
+ *     |           `--- pointer returned to Duktape
+ *     `--- underlying malloc ptr
+ */
+
+#include "duktape.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdint.h>
+
+#define  ALLOC_LOG_FILE  "/tmp/duk-alloc-log.txt"
+
+typedef struct {
+	/* The double value in the union is there to ensure alignment is
+	 * good for IEEE doubles too.  In many 32-bit environments 4 bytes
+	 * would be sufficiently aligned and the double value is unnecessary.
+	 */
+	union {
+		size_t sz;
+		double d;
+	} u;
+} alloc_hdr;
+
+static FILE *log_file = NULL;
+
+static void write_log(const char *fmt, ...) {
+	va_list ap;
+
+	if (!log_file) {
+		log_file = fopen(ALLOC_LOG_FILE, "wb");
+		if (!log_file) {
+			return;
+		}
+	}
+
+	va_start(ap, fmt);
+	vfprintf(log_file, fmt, ap);
+	va_end(ap);
+}
+
+void *duk_alloc_logging(void *udata, duk_size_t size) {
+	alloc_hdr *hdr;
+	void *ret;
+
+	(void) udata;  /* Suppress warning. */
+
+	if (size == 0) {
+		write_log("A NULL %ld\n", (long) size);
+		return NULL;
+	}
+
+	hdr = (alloc_hdr *) malloc(size + sizeof(alloc_hdr));
+	if (!hdr) {
+		write_log("A FAIL %ld\n", (long) size);
+		return NULL;
+	}
+	hdr->u.sz = size;
+	ret = (void *) (hdr + 1);
+	write_log("A %p %ld\n", ret, (long) size);
+	return ret;
+}
+
+void *duk_realloc_logging(void *udata, void *ptr, duk_size_t size) {
+	alloc_hdr *hdr;
+	size_t old_size;
+	void *t;
+	void *ret;
+
+	(void) udata;  /* Suppress warning. */
+
+	/* Handle the ptr-NULL vs. size-zero cases explicitly to minimize
+	 * platform assumptions.  You can get away with much less in specific
+	 * well-behaving environments.
+	 */
+
+	if (ptr) {
+		hdr = (alloc_hdr *) (void *) ((unsigned char *) ptr - sizeof(alloc_hdr));
+		old_size = hdr->u.sz;
+
+		if (size == 0) {
+			write_log("R %p %ld NULL 0\n", ptr, (long) old_size);
+			free((void *) hdr);
+			return NULL;
+		} else {
+			t = realloc((void *) hdr, size + sizeof(alloc_hdr));
+			if (!t) {
+				write_log("R %p %ld FAIL %ld\n", ptr, (long) old_size, (long) size);
+				return NULL;
+			}
+			hdr = (alloc_hdr *) t;
+			hdr->u.sz = size;
+			ret = (void *) (hdr + 1);
+			write_log("R %p %ld %p %ld\n", ptr, (long) old_size, ret, (long) size);
+			return ret;
+		}
+	} else {
+		if (size == 0) {
+			write_log("R NULL 0 NULL 0\n");
+			return NULL;
+		} else {
+			hdr = (alloc_hdr *) malloc(size + sizeof(alloc_hdr));
+			if (!hdr) {
+				write_log("R NULL 0 FAIL %ld\n", (long) size);
+				return NULL;
+			}
+			hdr->u.sz = size;
+			ret = (void *) (hdr + 1);
+			write_log("R NULL 0 %p %ld\n", ret, (long) size);
+			return ret;
+		}
+	}
+}
+
+void duk_free_logging(void *udata, void *ptr) {
+	alloc_hdr *hdr;
+
+	(void) udata;  /* Suppress warning. */
+
+	if (!ptr) {
+		write_log("F NULL 0\n");
+		return;
+	}
+	hdr = (alloc_hdr *) (void *) ((unsigned char *) ptr - sizeof(alloc_hdr));
+	write_log("F %p %ld\n", ptr, (long) hdr->u.sz);
+	free((void *) hdr);
+}

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/alloc-logging/duk_alloc_logging.h
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/alloc-logging/duk_alloc_logging.h b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/alloc-logging/duk_alloc_logging.h
new file mode 100644
index 0000000..6700353
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/examples/alloc-logging/duk_alloc_logging.h
@@ -0,0 +1,10 @@
+#ifndef DUK_ALLOC_LOGGING_H_INCLUDED
+#define DUK_ALLOC_LOGGING_H_INCLUDED
+
+#include "duktape.h"
+
+void *duk_alloc_logging(void *udata, duk_size_t size);
+void *duk_realloc_logging(void *udata, void *ptr, duk_size_t size);
+void duk_free_logging(void *udata, void *ptr);
+
+#endif  /* DUK_ALLOC_LOGGING_H_INCLUDED */


[31/51] [partial] nifi-minifi-cpp git commit: MINIFI-183 Added civet 1.9.1 sources Added onScheduled hook Added initial two-way TLS-enabled ListenHTTP implementation

Posted by al...@apache.org.
http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/config/genconfig.py
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/config/genconfig.py b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/config/genconfig.py
new file mode 100644
index 0000000..9c99648
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/config/genconfig.py
@@ -0,0 +1,1537 @@
+#!/usr/bin/env python2
+#
+#  Process Duktape option metadata and produce various useful outputs:
+#
+#    - duk_config.h with specific or autodetected platform, compiler, and
+#      architecture; forced options; sanity checks; etc
+#    - option documentation for Duktape 1.x feature options (DUK_OPT_xxx)
+#    - option documentation for Duktape 1.x/2.x config options (DUK_USE_xxx)
+#
+#  Genconfig tries to build all outputs based on modular metadata, so that
+#  managing a large number of config options (which is hard to avoid given
+#  the wide range of targets Duktape supports) remains maintainable.
+#
+#  Genconfig does *not* try to support all exotic platforms out there.
+#  Instead, the goal is to allow the metadata to be extended, or to provide
+#  a reasonable starting point for manual duk_config.h tweaking.
+#
+#  For Duktape 1.3 release the main goal was to autogenerate a Duktape 1.2
+#  compatible "autodetect" header from legacy snippets, with other outputs
+#  being experimental.  For Duktape 1.4 duk_config.h is always created from
+#  modular sources.
+#
+
+import os
+import sys
+import re
+import json
+import yaml
+import optparse
+import tarfile
+import tempfile
+import atexit
+import shutil
+try:
+	from StringIO import StringIO
+except ImportError:
+	from io import StringIO
+
+#
+#  Globals holding scanned metadata, helper snippets, etc
+#
+
+# Metadata to scan from config files.
+use_defs = None
+use_defs_list = None
+opt_defs = None
+opt_defs_list = None
+use_tags = None
+use_tags_list = None
+tags_meta = None
+required_use_meta_keys = [
+	'define',
+	'introduced',
+	'default',
+	'tags',
+	'description'
+]
+allowed_use_meta_keys = [
+	'define',
+	'feature_enables',
+	'feature_disables',
+	'feature_snippet',
+	'feature_no_default',
+	'related_feature_defines',
+	'introduced',
+	'deprecated',
+	'removed',
+	'unused',
+	'requires',
+	'conflicts',
+	'related',
+	'default',
+	'tags',
+	'description',
+]
+required_opt_meta_keys = [
+	'define',
+	'introduced',
+	'tags',
+	'description'
+]
+allowed_opt_meta_keys = [
+	'define',
+	'introduced',
+	'deprecated',
+	'removed',
+	'unused',
+	'requires',
+	'conflicts',
+	'related',
+	'tags',
+	'description'
+]
+
+# Preferred tag order for option documentation.
+doc_tag_order = [
+	'portability',
+	'memory',
+	'lowmemory',
+	'ecmascript',
+	'execution',
+	'debugger',
+	'debug',
+	'development'
+]
+
+# Preferred tag order for generated C header files.
+header_tag_order = doc_tag_order
+
+# Helper headers snippets.
+helper_snippets = None
+
+# Assume these provides come from outside.
+assumed_provides = {
+	'DUK_SINGLE_FILE': True,         # compiling Duktape from a single source file (duktape.c) version
+	'DUK_COMPILING_DUKTAPE': True,   # compiling Duktape (not user application)
+	'DUK_CONFIG_H_INCLUDED': True,   # artifact, include guard
+}
+
+# Platform files must provide at least these (additional checks
+# in validate_platform_file()).  Fill-ins provide missing optionals.
+platform_required_provides = [
+	'DUK_USE_OS_STRING'  # must be #define'd
+]
+
+# Architecture files must provide at least these (additional checks
+# in validate_architecture_file()).  Fill-ins provide missing optionals.
+architecture_required_provides = [
+	'DUK_USE_ARCH_STRING'
+]
+
+# Compiler files must provide at least these (additional checks
+# in validate_compiler_file()).  Fill-ins provide missing optionals.
+compiler_required_provides = [
+	# Compilers need a lot of defines; missing defines are automatically
+	# filled in with defaults (which are mostly compiler independent), so
+	# the requires define list is not very large.
+
+	'DUK_USE_COMPILER_STRING',    # must be #define'd
+	'DUK_USE_BRANCH_HINTS',       # may be #undef'd, as long as provided
+	'DUK_USE_VARIADIC_MACROS',    # may be #undef'd, as long as provided
+	'DUK_USE_UNION_INITIALIZERS'  # may be #undef'd, as long as provided
+]
+
+#
+#  Miscellaneous helpers
+#
+
+def get_auto_delete_tempdir():
+	tmpdir = tempfile.mkdtemp(suffix='-genconfig')
+	def _f(dirname):
+		#print('Deleting temporary directory: %r' % dirname)
+		if os.path.isdir(dirname) and '-genconfig' in dirname:
+			shutil.rmtree(dirname)
+	atexit.register(_f, tmpdir)
+	return tmpdir
+
+def strip_comments_from_lines(lines):
+	# Not exact but close enough.  Doesn't handle string literals etc,
+	# but these are not a concrete issue for scanning preprocessor
+	# #define references.
+	#
+	# Comment contents are stripped of any DUK_ prefixed text to avoid
+	# incorrect requires/provides detection.  Other comment text is kept;
+	# in particular a "/* redefine */" comment must remain intact here.
+	# (The 'redefine' hack is not actively needed now.)
+	#
+	# Avoid Python 2.6 vs. Python 2.7 argument differences.
+
+	def censor(x):
+		return re.sub(re.compile('DUK_\w+', re.MULTILINE), 'xxx', x.group(0))
+
+	tmp = '\n'.join(lines)
+	tmp = re.sub(re.compile('/\*.*?\*/', re.MULTILINE | re.DOTALL), censor, tmp)
+	tmp = re.sub(re.compile('//.*?$', re.MULTILINE), censor, tmp)
+	return tmp.split('\n')
+
+# Header snippet representation: lines, provides defines, requires defines.
+re_line_provides = re.compile(r'^#(?:define|undef)\s+(\w+).*$')
+re_line_requires = re.compile(r'(DUK_[A-Z0-9_]+)')  # uppercase only, don't match DUK_USE_xxx for example
+class Snippet:
+	lines = None     # lines of text and/or snippets
+	provides = None  # map from define to 'True' for now
+	requires = None  # map from define to 'True' for now
+
+	def __init__(self, lines, provides=None, requires=None, autoscan_requires=True, autoscan_provides=True):
+		self.lines = []
+		if not isinstance(lines, list):
+			raise Exception('Snippet constructor must be a list (not e.g. a string): %s' % repr(lines))
+		for line in lines:
+			if isinstance(line, str):
+				self.lines.append(line)
+			elif isinstance(line, unicode):
+				self.lines.append(line.encode('utf-8'))
+			else:
+				raise Exception('invalid line: %r' % line)
+		self.provides = {}
+		if provides is not None:
+			for k in provides.keys():
+				self.provides[k] = True
+		self.requires = {}
+		if requires is not None:
+			for k in requires.keys():
+				self.requires[k] = True
+
+		stripped_lines = strip_comments_from_lines(lines)
+		# for line in stripped_lines: print(line)
+
+		for line in stripped_lines:
+			# Careful with order, snippet may self-reference its own
+			# defines in which case there's no outward dependency.
+			# (This is not 100% because the order of require/provide
+			# matters and this is not handled now.)
+			#
+			# Also, some snippets may #undef/#define another define but
+			# they don't "provide" the define as such.  Such redefinitions
+			# are marked "/* redefine */" in the snippets.  They're best
+			# avoided (and not currently needed in Duktape 1.4.0).
+
+			if autoscan_provides:
+				m = re_line_provides.match(line)
+				if m is not None and '/* redefine */' not in line and \
+					len(m.group(1)) > 0 and m.group(1)[-1] != '_':
+					# Don't allow e.g. DUK_USE_ which results from matching DUK_USE_xxx
+					#print('PROVIDES: %r' % m.group(1))
+					self.provides[m.group(1)] = True
+			if autoscan_requires:
+				matches = re.findall(re_line_requires, line)
+				for m in matches:
+					if len(m) > 0 and m[-1] == '_':
+						# Don't allow e.g. DUK_USE_ which results from matching DUK_USE_xxx
+						pass
+					elif m[:7] == 'DUK_OPT':
+						# DUK_OPT_xxx always come from outside
+						pass
+					elif m[:7] == 'DUK_USE':
+						# DUK_USE_xxx are internal and they should not be 'requirements'
+						pass
+					elif self.provides.has_key(m):
+						# Snippet provides it's own require; omit
+						pass
+					else:
+						#print('REQUIRES: %r' % m)
+						self.requires[m] = True
+
+	def fromFile(cls, filename):
+		lines = []
+		with open(filename, 'rb') as f:
+			for line in f:
+				if line[-1] == '\n':
+					line = line[:-1]
+				if line[:8] == '#snippet':
+					m = re.match(r'#snippet\s+"(.*?)"', line)
+					# XXX: better plumbing for lookup path
+					sub_fn = os.path.normpath(os.path.join(filename, '..', '..', 'header-snippets', m.group(1)))
+					#print('#snippet ' + sub_fn)
+					sn = Snippet.fromFile(sub_fn)
+					lines += sn.lines
+				else:
+					lines.append(line)
+		return Snippet(lines, autoscan_requires=True, autoscan_provides=True)
+	fromFile = classmethod(fromFile)
+
+	def merge(cls, snippets):
+		ret = Snippet([], [], [])
+		for s in snippets:
+			ret.lines += s.lines
+			for k in s.provides.keys():
+				ret.provides[k] = True
+			for k in s.requires.keys():
+				ret.requires[k] = True
+		return ret
+	merge = classmethod(merge)
+
+# Helper for building a text file from individual lines, injected files, etc.
+# Inserted values are converted to Snippets so that their provides/requires
+# information can be tracked.  When non-C outputs are created, these will be
+# bogus but ignored.
+class FileBuilder:
+	vals = None  # snippet list
+	base_dir = None
+	use_cpp_warning = False
+
+	def __init__(self, base_dir=None, use_cpp_warning=False):
+		self.vals = []
+		self.base_dir = base_dir
+		self.use_cpp_warning = use_cpp_warning
+
+	def line(self, line):
+		self.vals.append(Snippet([ line ]))
+
+	def lines(self, lines):
+		if len(lines) > 0 and lines[-1] == '\n':
+			lines = lines[:-1]  # strip last newline to avoid empty line
+		self.vals.append(Snippet(lines.split('\n')))
+
+	def empty(self):
+		self.vals.append(Snippet([ '' ]))
+
+	def rst_heading(self, title, char, doubled=False):
+		tmp = []
+		if doubled:
+			tmp.append(char * len(title))
+		tmp.append(title)
+		tmp.append(char * len(title))
+		self.vals.append(Snippet(tmp))
+
+	def snippet_relative(self, fn):
+		sn = Snippet.fromFile(os.path.join(self.base_dir, fn))
+		self.vals.append(sn)
+		return sn
+
+	def snippet_absolute(self, fn):
+		sn = Snippet.fromFile(fn)
+		self.vals.append(sn)
+		return sn
+
+	def cpp_error(self, msg):
+		# XXX: assume no newlines etc
+		self.vals.append(Snippet([ '#error %s' % msg ]))
+
+	def cpp_warning(self, msg):
+		# XXX: assume no newlines etc
+		# XXX: support compiler specific warning mechanisms
+		if self.use_cpp_warning:
+			# C preprocessor '#warning' is often supported
+			self.vals.append(Snippet([ '#warning %s' % msg ]))
+		else:
+			self.vals.append(Snippet([ '/* WARNING: %s */' % msg ]))
+
+	def cpp_warning_or_error(self, msg, is_error=True):
+		if is_error:
+			self.cpp_error(msg)
+		else:
+			self.cpp_warning(msg)
+
+	def chdr_comment_line(self, msg):
+		self.vals.append(Snippet([ '/* %s */' % msg ]))
+
+	def chdr_block_heading(self, msg):
+		lines = []
+		lines.append('')
+		lines.append('/*')
+		lines.append(' *  ' + msg)
+		lines.append(' */')
+		lines.append('')
+		self.vals.append(Snippet(lines))
+
+	def join(self):
+		tmp = []
+		for line in self.vals:
+			if not isinstance(line, object):
+				raise Exception('self.vals must be all snippets')
+			for x in line.lines:  # x is a Snippet
+				tmp.append(x)
+		return '\n'.join(tmp)
+
+	def fill_dependencies_for_snippets(self, idx_deps):
+		fill_dependencies_for_snippets(self.vals, idx_deps)
+
+# Insert missing define dependencies into index 'idx_deps' repeatedly
+# until no unsatisfied dependencies exist.  This is used to pull in
+# the required DUK_F_xxx helper defines without pulling them all in.
+# The resolution mechanism also ensures dependencies are pulled in the
+# correct order, i.e. DUK_F_xxx helpers may depend on each other (as
+# long as there are no circular dependencies).
+#
+# XXX: this can be simplified a lot
+def fill_dependencies_for_snippets(snippets, idx_deps):
+	# graph[A] = [ B, ... ] <-> B, ... provide something A requires.
+	graph = {}
+	snlist = []
+	resolved = []   # for printing only
+
+	def add(sn):
+		if sn in snlist:
+			return  # already present
+		snlist.append(sn)
+
+		to_add = []
+
+		for k in sn.requires.keys():
+			if assumed_provides.has_key(k):
+				continue
+
+			found = False
+			for sn2 in snlist:
+				if sn2.provides.has_key(k):
+					if not graph.has_key(sn):
+						graph[sn] = []
+					graph[sn].append(sn2)
+					found = True  # at least one other node provides 'k'
+
+			if not found:
+				#print('Resolving %r' % k)
+				resolved.append(k)
+
+				# Find a header snippet which provides the missing define.
+				# Some DUK_F_xxx files provide multiple defines, so we don't
+				# necessarily know the snippet filename here.
+
+				sn_req = None
+				for sn2 in helper_snippets:
+					if sn2.provides.has_key(k):
+						sn_req = sn2
+						break
+				if sn_req is None:
+					print(repr(sn.lines))
+					raise Exception('cannot resolve missing require: %r' % k)
+
+				# Snippet may have further unresolved provides; add recursively
+				to_add.append(sn_req)
+
+				if not graph.has_key(sn):
+					graph[sn] = []
+				graph[sn].append(sn_req)
+
+		for sn in to_add:
+			add(sn)
+
+	# Add original snippets.  This fills in the required nodes
+	# recursively.
+	for sn in snippets:
+		add(sn)
+
+	# Figure out fill-ins by looking for snippets not in original
+	# list and without any unserialized dependent nodes.
+	handled = {}
+	for sn in snippets:
+		handled[sn] = True
+	keepgoing = True
+	while keepgoing:
+		keepgoing = False
+		for sn in snlist:
+			if handled.has_key(sn):
+				continue
+
+			success = True
+			for dep in graph.get(sn, []):
+				if not handled.has_key(dep):
+					success = False
+			if success:
+				snippets.insert(idx_deps, sn)
+				idx_deps += 1
+				snippets.insert(idx_deps, Snippet([ '' ]))
+				idx_deps += 1
+				handled[sn] = True
+				keepgoing = True
+				break
+
+	# XXX: detect and handle loops cleanly
+	for sn in snlist:
+		if handled.has_key(sn):
+			continue
+		print('UNHANDLED KEY')
+		print('PROVIDES: %r' % sn.provides)
+		print('REQUIRES: %r' % sn.requires)
+		print('\n'.join(sn.lines))
+
+#	print(repr(graph))
+#	print(repr(snlist))
+#	print('Resolved helper defines: %r' % resolved)
+	print('Resolved %d helper defines' % len(resolved))
+
+def serialize_snippet_list(snippets):
+	ret = []
+
+	emitted_provides = {}
+	for k in assumed_provides.keys():
+		emitted_provides[k] = True
+
+	for sn in snippets:
+		ret += sn.lines
+		for k in sn.provides.keys():
+			emitted_provides[k] = True
+		for k in sn.requires.keys():
+			if not emitted_provides.has_key(k):
+				# XXX: conditional warning, happens in some normal cases
+				#print('WARNING: define %r required, not provided so far' % k)
+				pass
+
+	return '\n'.join(ret)
+
+def remove_duplicate_newlines(x):
+	ret = []
+	empty = False
+	for line in x.split('\n'):
+		if line == '':
+			if empty:
+				pass
+			else:
+				ret.append(line)
+			empty = True
+		else:
+			empty = False
+			ret.append(line)
+	return '\n'.join(ret)
+
+def scan_use_defs(dirname):
+	global use_defs, use_defs_list
+	use_defs = {}
+	use_defs_list = []
+
+	for fn in os.listdir(dirname):
+		root, ext = os.path.splitext(fn)
+		if not root.startswith('DUK_USE_') or ext != '.yaml':
+			continue
+		with open(os.path.join(dirname, fn), 'rb') as f:
+			doc = yaml.load(f)
+			if doc.get('example', False):
+				continue
+			if doc.get('unimplemented', False):
+				print('WARNING: unimplemented: %s' % fn)
+				continue
+			dockeys = doc.keys()
+			for k in dockeys:
+				if not k in allowed_use_meta_keys:
+					print('WARNING: unknown key %s in metadata file %s' % (k, fn))
+			for k in required_use_meta_keys:
+				if not k in dockeys:
+					print('WARNING: missing key %s in metadata file %s' % (k, fn))
+
+			use_defs[doc['define']] = doc
+
+	keys = use_defs.keys()
+	keys.sort()
+	for k in keys:
+		use_defs_list.append(use_defs[k])
+
+def scan_opt_defs(dirname):
+	global opt_defs, opt_defs_list
+	opt_defs = {}
+	opt_defs_list = []
+
+	for fn in os.listdir(dirname):
+		root, ext = os.path.splitext(fn)
+		if not root.startswith('DUK_OPT_') or ext != '.yaml':
+			continue
+		with open(os.path.join(dirname, fn), 'rb') as f:
+			doc = yaml.load(f)
+			if doc.get('example', False):
+				continue
+			if doc.get('unimplemented', False):
+				print('WARNING: unimplemented: %s' % fn)
+				continue
+			dockeys = doc.keys()
+			for k in dockeys:
+				if not k in allowed_opt_meta_keys:
+					print('WARNING: unknown key %s in metadata file %s' % (k, fn))
+			for k in required_opt_meta_keys:
+				if not k in dockeys:
+					print('WARNING: missing key %s in metadata file %s' % (k, fn))
+
+			opt_defs[doc['define']] = doc
+
+	keys = opt_defs.keys()
+	keys.sort()
+	for k in keys:
+		opt_defs_list.append(opt_defs[k])
+
+def scan_use_tags():
+	global use_tags, use_tags_list
+	use_tags = {}
+
+	for doc in use_defs_list:
+		for tag in doc.get('tags', []):
+			use_tags[tag] = True
+
+	use_tags_list = use_tags.keys()
+	use_tags_list.sort()
+
+def scan_tags_meta(filename):
+	global tags_meta
+
+	with open(filename, 'rb') as f:
+		tags_meta = yaml.load(f)
+
+def scan_helper_snippets(dirname):  # DUK_F_xxx snippets
+	global helper_snippets
+	helper_snippets = []
+
+	for fn in os.listdir(dirname):
+		if (fn[0:6] != 'DUK_F_'):
+			continue
+		#print('Autoscanning snippet: %s' % fn)
+		helper_snippets.append(Snippet.fromFile(os.path.join(dirname, fn)))
+
+def get_opt_defs(removed=True, deprecated=True, unused=True):
+	ret = []
+	for doc in opt_defs_list:
+		# XXX: aware of target version
+		if removed == False and doc.get('removed', None) is not None:
+			continue
+		if deprecated == False and doc.get('deprecated', None) is not None:
+			continue
+		if unused == False and doc.get('unused', False) == True:
+			continue
+		ret.append(doc)
+	return ret
+
+def get_use_defs(removed=True, deprecated=True, unused=True):
+	ret = []
+	for doc in use_defs_list:
+		# XXX: aware of target version
+		if removed == False and doc.get('removed', None) is not None:
+			continue
+		if deprecated == False and doc.get('deprecated', None) is not None:
+			continue
+		if unused == False and doc.get('unused', False) == True:
+			continue
+		ret.append(doc)
+	return ret
+
+def validate_platform_file(filename):
+	sn = Snippet.fromFile(filename)
+
+	for req in platform_required_provides:
+		if req not in sn.provides:
+			raise Exception('Platform %s is missing %s' % (filename, req))
+
+	# DUK_SETJMP, DUK_LONGJMP, DUK_JMPBUF_TYPE are optional, fill-in
+	# provides if none defined.
+
+def validate_architecture_file(filename):
+	sn = Snippet.fromFile(filename)
+
+	for req in architecture_required_provides:
+		if req not in sn.provides:
+			raise Exception('Architecture %s is missing %s' % (filename, req))
+
+	# Byte order and alignment defines are allowed to be missing,
+	# a fill-in will handle them.  This is necessary because for
+	# some architecture byte order and/or alignment may vary between
+	# targets and may be software configurable.
+
+	# XXX: require automatic detection to be signaled?
+	# e.g. define DUK_USE_ALIGN_BY -1
+	#      define DUK_USE_BYTE_ORDER -1
+
+def validate_compiler_file(filename):
+	sn = Snippet.fromFile(filename)
+
+	for req in compiler_required_provides:
+		if req not in sn.provides:
+			raise Exception('Compiler %s is missing %s' % (filename, req))
+
+def get_tag_title(tag):
+	meta = tags_meta.get(tag, None)
+	if meta is None:
+		return tag
+	else:
+		return meta.get('title', tag)
+
+def get_tag_description(tag):
+	meta = tags_meta.get(tag, None)
+	if meta is None:
+		return None
+	else:
+		return meta.get('description', None)
+
+def get_tag_list_with_preferred_order(preferred):
+	tags = []
+
+	# Preferred tags first
+	for tag in preferred:
+		if tag not in tags:
+			tags.append(tag)
+
+	# Remaining tags in alphabetic order
+	for tag in use_tags_list:
+		if tag not in tags:
+			tags.append(tag)
+
+	#print('Effective tag order: %r' % tags)
+	return tags
+
+def rst_format(text):
+	# XXX: placeholder, need to decide on markup conventions for YAML files
+	ret = []
+	for para in text.split('\n'):
+		if para == '':
+			continue
+		ret.append(para)
+	return '\n\n'.join(ret)
+
+def cint_encode(x):
+	if not isinstance(x, (int, long)):
+		raise Exception('invalid input: %r' % x)
+
+	# XXX: unsigned constants?
+	if x > 0x7fffffff or x < -0x80000000:
+		return '%dLL' % x
+	elif x > 0x7fff or x < -0x8000:
+		return '%dL' % x
+	else:
+		return '%d' % x
+
+def cstr_encode(x):
+	if isinstance(x, unicode):
+		x = x.encode('utf-8')
+	if not isinstance(x, str):
+		raise Exception('invalid input: %r' % x)
+
+	res = '"'
+	term = False
+	has_terms = False
+	for c in x:
+		if term:
+			# Avoid ambiguous hex escapes
+			res += '" "'
+			term = False
+			has_terms = True
+		o = ord(c)
+		if o < 0x20 or o > 0x7e or c in '"\\':
+			res += '\\x%02x' % o
+			term = True
+		else:
+			res += c
+	res += '"'
+
+	if has_terms:
+		res = '(' + res + ')'
+
+	return res
+
+#
+#  Autogeneration of option documentation
+#
+
+# Shared helper to generate DUK_OPT_xxx and DUK_USE_xxx documentation.
+# XXX: unfinished placeholder
+def generate_option_documentation(opts, opt_list=None, rst_title=None, include_default=False):
+	ret = FileBuilder(use_cpp_warning=opts.use_cpp_warning)
+
+	tags = get_tag_list_with_preferred_order(doc_tag_order)
+
+	title = rst_title
+	ret.rst_heading(title, '=', doubled=True)
+
+	handled = {}
+
+	for tag in tags:
+		first = True
+
+		for doc in opt_list:
+			if tag != doc['tags'][0]:  # sort under primary tag
+				continue
+			dname = doc['define']
+			desc = doc.get('description', None)
+
+			if handled.has_key(dname):
+				raise Exception('define handled twice, should not happen: %r' % dname)
+			handled[dname] = True
+
+			if first:  # emit tag heading only if there are subsections
+				ret.empty()
+				ret.rst_heading(get_tag_title(tag), '=')
+
+				tag_desc = get_tag_description(tag)
+				if tag_desc is not None:
+					ret.empty()
+					ret.line(rst_format(tag_desc))
+				first = False
+
+			ret.empty()
+			ret.rst_heading(dname, '-')
+
+			if desc is not None:
+				ret.empty()
+				ret.line(rst_format(desc))
+
+			if include_default:
+				ret.empty()
+				ret.line('Default: ``' + str(doc['default']) + '``')  # XXX: rst or other format
+
+	for doc in opt_list:
+		dname = doc['define']
+		if not handled.has_key(dname):
+			raise Exception('unhandled define (maybe missing from tags list?): %r' % dname)
+
+	ret.empty()
+	return ret.join()
+
+def generate_feature_option_documentation(opts):
+	defs = get_opt_defs()
+	return generate_option_documentation(opts, opt_list=defs, rst_title='Duktape feature options', include_default=False)
+
+def generate_config_option_documentation(opts):
+	defs = get_use_defs()
+	return generate_option_documentation(opts, opt_list=defs, rst_title='Duktape config options', include_default=True)
+
+#
+#  Helpers for duk_config.h generation
+#
+
+def get_forced_options(opts):
+	# Forced options, last occurrence wins (allows a base config file to be
+	# overridden by a more specific one).
+	forced_opts = {}
+	for val in opts.force_options_yaml:
+		doc = yaml.load(StringIO(val))
+		for k in doc.keys():
+			if use_defs.has_key(k):
+				pass  # key is known
+			else:
+				print('WARNING: option override key %s not defined in metadata, ignoring' % k)
+			forced_opts[k] = doc[k]  # shallow copy
+
+	if len(forced_opts.keys()) > 0:
+		print('Overrides: %s' % json.dumps(forced_opts))
+
+	return forced_opts
+
+# Emit a default #define / #undef for an option based on
+# a config option metadata node (parsed YAML doc).
+def emit_default_from_config_meta(ret, doc, forced_opts, undef_done):
+	defname = doc['define']
+	defval = forced_opts.get(defname, doc['default'])
+
+	# NOTE: careful with Python equality, e.g. "0 == False" is true.
+	if isinstance(defval, bool) and defval == True:
+		ret.line('#define ' + defname)
+	elif isinstance(defval, bool) and defval == False:
+		if not undef_done:
+			ret.line('#undef ' + defname)
+		else:
+			# Default value is false, and caller has emitted
+			# an unconditional #undef, so don't emit a duplicate
+			pass
+	elif isinstance(defval, (int, long)):
+		# integer value
+		ret.line('#define ' + defname + ' ' + cint_encode(defval))
+	elif isinstance(defval, (str, unicode)):
+		# verbatim value
+		ret.line('#define ' + defname + ' ' + defval)
+	elif isinstance(defval, dict):
+		if defval.has_key('verbatim'):
+			# verbatim text for the entire line
+			ret.line(defval['verbatim'])
+		elif defval.has_key('string'):
+			# C string value
+			ret.line('#define ' + defname + ' ' + cstr_encode(defval['string']))
+		else:
+			raise Exception('unsupported value for option %s: %r' % (defname, defval))
+	else:
+		raise Exception('unsupported value for option %s: %r' % (defname, defval))
+
+# Add a header snippet for detecting presence of DUK_OPT_xxx feature
+# options which will be removed in Duktape 2.x.
+def add_legacy_feature_option_checks(opts, ret):
+	ret.chdr_block_heading('Checks for legacy feature options (DUK_OPT_xxx)')
+	ret.empty()
+
+	defs = []
+	for doc in get_opt_defs():
+		if doc['define'] not in defs:
+			defs.append(doc['define'])
+	for doc in get_opt_defs():
+		for dname in doc.get('related_feature_defines', []):
+			if dname not in defs:
+				defs.append(dname)
+	defs.sort()
+
+	for optname in defs:
+		suggested = []
+		for doc in get_use_defs():
+			if optname in doc.get('related_feature_defines', []):
+				suggested.append(doc['define'])
+		ret.line('#if defined(%s)' % optname)
+		if len(suggested) > 0:
+			ret.cpp_warning_or_error('unsupported legacy feature option %s used, consider options: %s' % (optname, ', '.join(suggested)), opts.sanity_strict)
+		else:
+			ret.cpp_warning_or_error('unsupported legacy feature option %s used' % optname, opts.sanity_strict)
+		ret.line('#endif')
+
+	ret.empty()
+
+# Add a header snippet for checking consistency of DUK_USE_xxx config
+# options, e.g. inconsistent options, invalid option values.
+def add_config_option_checks(opts, ret):
+	ret.chdr_block_heading('Checks for config option consistency (DUK_USE_xxx)')
+	ret.empty()
+
+	defs = []
+	for doc in get_use_defs():
+		if doc['define'] not in defs:
+			defs.append(doc['define'])
+	defs.sort()
+
+	for optname in defs:
+		doc = use_defs[optname]
+		dname = doc['define']
+
+		# XXX: more checks
+
+		if doc.get('removed', None) is not None:
+			ret.line('#if defined(%s)' % dname)
+			ret.cpp_warning_or_error('unsupported config option used (option has been removed): %s' % dname, opts.sanity_strict)
+			ret.line('#endif')
+		elif doc.get('deprecated', None) is not None:
+			ret.line('#if defined(%s)' % dname)
+			ret.cpp_warning_or_error('unsupported config option used (option has been deprecated): %s' % dname, opts.sanity_strict)
+			ret.line('#endif')
+
+		for req in doc.get('requires', []):
+			ret.line('#if defined(%s) && !defined(%s)' % (dname, req))
+			ret.cpp_warning_or_error('config option %s requires option %s (which is missing)' % (dname, req), opts.sanity_strict)
+			ret.line('#endif')
+
+		for req in doc.get('conflicts', []):
+			ret.line('#if defined(%s) && defined(%s)' % (dname, req))
+			ret.cpp_warning_or_error('config option %s conflicts with option %s (which is also defined)' % (dname, req), opts.sanity_strict)
+			ret.line('#endif')
+
+	ret.empty()
+	ret.snippet_relative('cpp_exception_sanity.h.in')
+	ret.empty()
+
+# Add a header snippet for providing a __OVERRIDE_DEFINES__ section.
+def add_override_defines_section(opts, ret):
+	ret.empty()
+	ret.line('/*')
+	ret.line(' *  You may add overriding #define/#undef directives below for')
+	ret.line(' *  customization.  You of course cannot un-#include or un-typedef')
+	ret.line(' *  anything; these require direct changes above.')
+	ret.line(' */')
+	ret.empty()
+	ret.line('/* __OVERRIDE_DEFINES__ */')
+	ret.empty()
+
+# Add automatic DUK_OPT_XXX and DUK_OPT_NO_XXX handling for backwards
+# compatibility with Duktape 1.2 and before.
+def add_feature_option_handling(opts, ret, forced_opts, already_provided_keys):
+	ret.chdr_block_heading('Feature option handling')
+
+	for doc in get_use_defs(removed=False, deprecated=False, unused=False):
+		# If a related feature option exists, it can be used to force
+		# enable/disable the target feature.  If neither feature option
+		# (DUK_OPT_xxx or DUK_OPT_NO_xxx) is given, revert to default.
+
+		config_define = doc['define']
+
+		feature_define = None
+		feature_no_define = None
+		inverted = False
+		if doc.has_key('feature_enables'):
+			feature_define = doc['feature_enables']
+		elif doc.has_key('feature_disables'):
+			feature_define = doc['feature_disables']
+			inverted = True
+		else:
+			pass
+
+		if feature_define is not None:
+			feature_no_define = 'DUK_OPT_NO_' + feature_define[8:]
+			ret.line('#if defined(%s)' % feature_define)
+			if inverted:
+				ret.line('#undef %s' % config_define)
+			else:
+				ret.line('#define %s' % config_define)
+			ret.line('#elif defined(%s)' % feature_no_define)
+			if inverted:
+				ret.line('#define %s' % config_define)
+			else:
+				ret.line('#undef %s' % config_define)
+			ret.line('#else')
+			undef_done = False
+
+			# For some options like DUK_OPT_PACKED_TVAL the default comes
+			# from platform definition.
+			if doc.get('feature_no_default', False):
+				print('Skip default for option %s' % config_define)
+				ret.line('/* Already provided above */')
+			elif already_provided_keys.has_key(config_define):
+				# This is a fallback in case config option metadata is wrong.
+				print('Skip default for option %s (already provided but not flagged in metadata!)' % config_define)
+				ret.line('/* Already provided above */')
+			else:
+				emit_default_from_config_meta(ret, doc, forced_opts, undef_done)
+			ret.line('#endif')
+		elif doc.has_key('feature_snippet'):
+			ret.lines(doc['feature_snippet'])
+		else:
+			pass
+
+		ret.empty()
+
+	ret.empty()
+
+# Development time helper: add DUK_ACTIVE which provides a runtime C string
+# indicating what DUK_USE_xxx config options are active at run time.  This
+# is useful in genconfig development so that one can e.g. diff the active
+# run time options of two headers.  This is intended just for genconfig
+# development and is not available in normal headers.
+def add_duk_active_defines_macro(ret):
+	ret.chdr_block_heading('DUK_ACTIVE_DEFINES macro (development only)')
+
+	idx = 0
+	for doc in get_use_defs():
+		defname = doc['define']
+
+		ret.line('#if defined(%s)' % defname)
+		ret.line('#define DUK_ACTIVE_DEF%d " %s"' % (idx, defname))
+		ret.line('#else')
+		ret.line('#define DUK_ACTIVE_DEF%d ""' % idx)
+		ret.line('#endif')
+
+		idx += 1
+
+	tmp = []
+	for i in xrange(idx):
+		tmp.append('DUK_ACTIVE_DEF%d' % i)
+
+	ret.line('#define DUK_ACTIVE_DEFINES ("Active: ["' + ' '.join(tmp) + ' " ]")')
+
+#
+#  duk_config.h generation
+#
+
+# Generate a duk_config.h where platform, architecture, and compiler are
+# all either autodetected or specified by user.
+#
+# Autodetection is based on a configured list of supported platforms,
+# architectures, and compilers.  For example, platforms.yaml defines the
+# supported platforms and provides a helper define (DUK_F_xxx) to use for
+# detecting that platform, and names the header snippet to provide the
+# platform-specific definitions.  Necessary dependencies (DUK_F_xxx) are
+# automatically pulled in.
+#
+# Automatic "fill ins" are used for mandatory platform, architecture, and
+# compiler defines which have a reasonable portable default.  This reduces
+# e.g. compiler-specific define count because there are a lot compiler
+# macros which have a good default.
+def generate_duk_config_header(opts, meta_dir):
+	ret = FileBuilder(base_dir=os.path.join(meta_dir, 'header-snippets'), \
+	                  use_cpp_warning=opts.use_cpp_warning)
+
+	forced_opts = get_forced_options(opts)
+
+	platforms = None
+	with open(os.path.join(meta_dir, 'platforms.yaml'), 'rb') as f:
+		platforms = yaml.load(f)
+	architectures = None
+	with open(os.path.join(meta_dir, 'architectures.yaml'), 'rb') as f:
+		architectures = yaml.load(f)
+	compilers = None
+	with open(os.path.join(meta_dir, 'compilers.yaml'), 'rb') as f:
+		compilers = yaml.load(f)
+
+	# XXX: indicate feature option support, sanity checks enabled, etc
+	# in general summary of options, perhaps genconfig command line?
+
+	ret.line('/*')
+	ret.line(' *  duk_config.h configuration header generated by genconfig.py.')
+	ret.line(' *')
+	ret.line(' *  Git commit: %s' % opts.git_commit or 'n/a')
+	ret.line(' *  Git describe: %s' % opts.git_describe or 'n/a')
+	ret.line(' *  Git branch: %s' % opts.git_branch or 'n/a')
+	ret.line(' *')
+	if opts.platform is not None:
+		ret.line(' *  Platform: ' + opts.platform)
+	else:
+		ret.line(' *  Supported platforms:')
+		for platf in platforms['autodetect']:
+			ret.line(' *      - %s' % platf.get('name', platf.get('check')))
+	ret.line(' *')
+	if opts.architecture is not None:
+		ret.line(' *  Architecture: ' + opts.architecture)
+	else:
+		ret.line(' *  Supported architectures:')
+		for arch in architectures['autodetect']:
+			ret.line(' *      - %s' % arch.get('name', arch.get('check')))
+	ret.line(' *')
+	if opts.compiler is not None:
+		ret.line(' *  Compiler: ' + opts.compiler)
+	else:
+		ret.line(' *  Supported compilers:')
+		for comp in compilers['autodetect']:
+			ret.line(' *      - %s' % comp.get('name', comp.get('check')))
+	ret.line(' *')
+	ret.line(' */')
+	ret.empty()
+	ret.line('#if !defined(DUK_CONFIG_H_INCLUDED)')
+	ret.line('#define DUK_CONFIG_H_INCLUDED')
+	ret.empty()
+
+	ret.chdr_block_heading('Intermediate helper defines')
+
+	# DLL build affects visibility attributes on Windows but unfortunately
+	# cannot be detected automatically from preprocessor defines or such.
+	# DLL build status is hidden behind DUK_F_DLL_BUILD and there are two
+	# ways for that to be set:
+	#
+	#   - Duktape 1.3 backwards compatible DUK_OPT_DLL_BUILD
+	#   - Genconfig --dll option
+	ret.chdr_comment_line('DLL build detection')
+	ret.line('#if defined(DUK_OPT_DLL_BUILD)')
+	ret.line('#define DUK_F_DLL_BUILD')
+	ret.line('#elif defined(DUK_OPT_NO_DLL_BUILD)')
+	ret.line('#undef DUK_F_DLL_BUILD')
+	ret.line('#else')
+	if opts.dll:
+		ret.line('/* configured for DLL build */')
+		ret.line('#define DUK_F_DLL_BUILD')
+	else:
+		ret.line('/* not configured for DLL build */')
+		ret.line('#undef DUK_F_DLL_BUILD')
+	ret.line('#endif')
+	ret.empty()
+
+	idx_deps = len(ret.vals)  # position where to emit DUK_F_xxx dependencies
+
+	# Feature selection, system include, Date provider
+	# Most #include statements are here
+
+	if opts.platform is not None:
+		ret.chdr_block_heading('Platform: ' + opts.platform)
+
+		ret.snippet_relative('platform_cppextras.h.in')
+		ret.empty()
+
+		# XXX: better to lookup platforms metadata
+		include = 'platform_%s.h.in' % opts.platform
+		abs_fn = os.path.join(meta_dir, 'platforms', include)
+		validate_platform_file(abs_fn)
+		ret.snippet_absolute(abs_fn)
+	else:
+		ret.chdr_block_heading('Platform autodetection')
+
+		ret.snippet_relative('platform_cppextras.h.in')
+		ret.empty()
+
+		for idx, platf in enumerate(platforms['autodetect']):
+			check = platf.get('check', None)
+			include = platf['include']
+			abs_fn = os.path.join(meta_dir, 'platforms', include)
+
+			validate_platform_file(abs_fn)
+
+			if idx == 0:
+				ret.line('#if defined(%s)' % check)
+			else:
+				if check is None:
+					ret.line('#else')
+				else:
+					ret.line('#elif defined(%s)' % check)
+			ret.line('/* --- %s --- */' % platf.get('name', '???'))
+			ret.snippet_absolute(abs_fn)
+		ret.line('#endif  /* autodetect platform */')
+
+	ret.empty()
+	ret.snippet_relative('platform_sharedincludes.h.in')
+	ret.empty()
+
+	byteorder_provided_by_all = True  # byteorder provided by all architecture files
+	alignment_provided_by_all = True  # alignment provided by all architecture files
+	packedtval_provided_by_all = True # packed tval provided by all architecture files
+
+	if opts.architecture is not None:
+		ret.chdr_block_heading('Architecture: ' + opts.architecture)
+
+		# XXX: better to lookup architectures metadata
+		include = 'architecture_%s.h.in' % opts.architecture
+		abs_fn = os.path.join(meta_dir, 'architectures', include)
+		validate_architecture_file(abs_fn)
+		sn = ret.snippet_absolute(abs_fn)
+		if not sn.provides.get('DUK_USE_BYTEORDER', False):
+			byteorder_provided_by_all = False
+		if not sn.provides.get('DUK_USE_ALIGN_BY', False):
+			alignment_provided_by_all = False
+		if sn.provides.get('DUK_USE_PACKED_TVAL', False):
+			ret.line('#define DUK_F_PACKED_TVAL_PROVIDED')  # signal to fillin
+		else:
+			packedtval_provided_by_all = False
+	else:
+		ret.chdr_block_heading('Architecture autodetection')
+
+		for idx, arch in enumerate(architectures['autodetect']):
+			check = arch.get('check', None)
+			include = arch['include']
+			abs_fn = os.path.join(meta_dir, 'architectures', include)
+
+			validate_architecture_file(abs_fn)
+
+			if idx == 0:
+				ret.line('#if defined(%s)' % check)
+			else:
+				if check is None:
+					ret.line('#else')
+				else:
+					ret.line('#elif defined(%s)' % check)
+			ret.line('/* --- %s --- */' % arch.get('name', '???'))
+			sn = ret.snippet_absolute(abs_fn)
+			if not sn.provides.get('DUK_USE_BYTEORDER', False):
+				byteorder_provided_by_all = False
+			if not sn.provides.get('DUK_USE_ALIGN_BY', False):
+				alignment_provided_by_all = False
+			if sn.provides.get('DUK_USE_PACKED_TVAL', False):
+				ret.line('#define DUK_F_PACKED_TVAL_PROVIDED')  # signal to fillin
+			else:
+				packedtval_provided_by_all = False
+		ret.line('#endif  /* autodetect architecture */')
+
+	ret.empty()
+
+	if opts.compiler is not None:
+		ret.chdr_block_heading('Compiler: ' + opts.compiler)
+
+		# XXX: better to lookup compilers metadata
+		include = 'compiler_%s.h.in' % opts.compiler
+		abs_fn = os.path.join(meta_dir, 'compilers', include)
+		validate_compiler_file(abs_fn)
+		sn = ret.snippet_absolute(abs_fn)
+	else:
+		ret.chdr_block_heading('Compiler autodetection')
+
+		for idx, comp in enumerate(compilers['autodetect']):
+			check = comp.get('check', None)
+			include = comp['include']
+			abs_fn = os.path.join(meta_dir, 'compilers', include)
+
+			validate_compiler_file(abs_fn)
+
+			if idx == 0:
+				ret.line('#if defined(%s)' % check)
+			else:
+				if check is None:
+					ret.line('#else')
+				else:
+					ret.line('#elif defined(%s)' % check)
+			ret.line('/* --- %s --- */' % comp.get('name', '???'))
+			sn = ret.snippet_absolute(abs_fn)
+		ret.line('#endif  /* autodetect compiler */')
+
+	ret.empty()
+
+	# DUK_F_UCLIBC is special because __UCLIBC__ is provided by an #include
+	# file, so the check must happen after platform includes.  It'd be nice
+	# for this to be automatic (e.g. DUK_F_UCLIBC.h.in could indicate the
+	# dependency somehow).
+
+	ret.snippet_absolute(os.path.join(meta_dir, 'helper-snippets', 'DUK_F_UCLIBC.h.in'))
+	ret.empty()
+
+	# XXX: platform/compiler could provide types; if so, need some signaling
+	# defines like DUK_F_TYPEDEFS_DEFINED
+
+	# Number types
+	if opts.c99_types_only:
+		ret.snippet_relative('types1.h.in')
+		ret.line('/* C99 types assumed */')
+		ret.snippet_relative('types_c99.h.in')
+		ret.empty()
+	else:
+		ret.snippet_relative('types1.h.in')
+		ret.line('#if defined(DUK_F_HAVE_INTTYPES)')
+		ret.line('/* C99 or compatible */')
+		ret.empty()
+		ret.snippet_relative('types_c99.h.in')
+		ret.empty()
+		ret.line('#else  /* C99 types */')
+		ret.empty()
+		ret.snippet_relative('types_legacy.h.in')
+		ret.empty()
+		ret.line('#endif  /* C99 types */')
+		ret.empty()
+	ret.snippet_relative('types2.h.in')
+	ret.empty()
+	ret.snippet_relative('64bitops.h.in')
+	ret.empty()
+
+	# Platform, architecture, compiler fillins.  These are after all
+	# detection so that e.g. DUK_SPRINTF() can be provided by platform
+	# or compiler before trying a fill-in.
+
+	ret.chdr_block_heading('Fill-ins for platform, architecture, and compiler')
+
+	ret.snippet_relative('platform_fillins.h.in')
+	ret.empty()
+	ret.snippet_relative('architecture_fillins.h.in')
+	if not byteorder_provided_by_all:
+		ret.empty()
+		ret.snippet_relative('byteorder_fillin.h.in')
+	if not alignment_provided_by_all:
+		ret.empty()
+		ret.snippet_relative('alignment_fillin.h.in')
+	ret.empty()
+	ret.snippet_relative('compiler_fillins.h.in')
+	ret.empty()
+	ret.snippet_relative('inline_workaround.h.in')
+	ret.empty()
+	if not packedtval_provided_by_all:
+		ret.empty()
+		ret.snippet_relative('packed_tval_fillin.h.in')
+
+	# Object layout
+	ret.snippet_relative('object_layout.h.in')
+	ret.empty()
+
+	# Detect and reject 'fast math'
+	ret.snippet_relative('reject_fast_math.h.in')
+	ret.empty()
+
+	# Automatic DUK_OPT_xxx feature option handling
+	if opts.support_feature_options:
+		print('Autogenerating feature option (DUK_OPT_xxx) support')
+		tmp = Snippet(ret.join().split('\n'))
+		add_feature_option_handling(opts, ret, forced_opts, tmp.provides)
+
+	# Emit forced options.  If a corresponding option is already defined
+	# by a snippet above, #undef it first.
+
+	tmp = Snippet(ret.join().split('\n'))
+	first_forced = True
+	for doc in get_use_defs(removed=not opts.omit_removed_config_options,
+	                        deprecated=not opts.omit_deprecated_config_options,
+	                        unused=not opts.omit_unused_config_options):
+		defname = doc['define']
+
+		if not forced_opts.has_key(defname):
+			continue
+
+		if not doc.has_key('default'):
+			raise Exception('config option %s is missing default value' % defname)
+
+		if first_forced:
+			ret.chdr_block_heading('Forced options')
+			first_forced = False
+
+		undef_done = False
+		if tmp.provides.has_key(defname):
+			ret.line('#undef ' + defname)
+			undef_done = True
+
+		emit_default_from_config_meta(ret, doc, forced_opts, undef_done)
+
+	ret.empty()
+
+	# If manually-edited snippets don't #define or #undef a certain
+	# config option, emit a default value here.  This is useful to
+	# fill-in for new config options not covered by manual snippets
+	# (which is intentional).
+
+	tmp = Snippet(ret.join().split('\n'))
+	need = {}
+	for doc in get_use_defs(removed=False):
+		need[doc['define']] = True
+	for k in tmp.provides.keys():
+		if need.has_key(k):
+			del need[k]
+	need_keys = sorted(need.keys())
+
+	if len(need_keys) > 0:
+		ret.chdr_block_heading('Autogenerated defaults')
+
+		for k in need_keys:
+			#print('config option %s not covered by manual snippets, emitting default automatically' % k)
+			emit_default_from_config_meta(ret, use_defs[k], {}, False)
+
+		ret.empty()
+
+	ret.snippet_relative('custom_header.h.in')
+	ret.empty()
+
+	if len(opts.fixup_header_lines) > 0:
+		ret.chdr_block_heading('Fixups')
+		for line in opts.fixup_header_lines:
+			ret.line(line)
+		ret.empty()
+
+	add_override_defines_section(opts, ret)
+
+	# Date provider snippet is after custom header and overrides, so that
+	# the user may define e.g. DUK_USE_DATE_NOW_GETTIMEOFDAY in their
+	# custom header.
+	ret.snippet_relative('date_provider.h.in')
+	ret.empty()
+
+	ret.fill_dependencies_for_snippets(idx_deps)
+
+	if opts.emit_legacy_feature_check:
+		add_legacy_feature_option_checks(opts, ret)
+	if opts.emit_config_sanity_check:
+		add_config_option_checks(opts, ret)
+	if opts.add_active_defines_macro:
+		add_duk_active_defines_macro(ret)
+
+	# Derived defines (DUK_USE_INTEGER_LE, etc) from DUK_USE_BYTEORDER.
+	# Duktape internals currently rely on the derived defines.  This is
+	# after sanity checks because the derived defines are marked removed.
+	ret.snippet_relative('byteorder_derived.h.in')
+	ret.empty()
+
+	ret.line('#endif  /* DUK_CONFIG_H_INCLUDED */')
+	ret.empty()  # for trailing newline
+	return remove_duplicate_newlines(ret.join())
+
+#
+#  Main
+#
+
+def main():
+	# Forced options from multiple sources are gathered into a shared list
+	# so that the override order remains the same as on the command line.
+	force_options_yaml = []
+	def add_force_option_yaml(option, opt, value, parser):
+		# XXX: check that YAML parses
+		force_options_yaml.append(value)
+	def add_force_option_file(option, opt, value, parser):
+		# XXX: check that YAML parses
+		with open(value, 'rb') as f:
+			force_options_yaml.append(f.read())
+	def add_force_option_define(option, opt, value, parser):
+		tmp = value.split('=')
+		if len(tmp) == 1:
+			doc = { tmp[0]: True }
+		elif len(tmp) == 2:
+			doc = { tmp[0]: tmp[1] }
+		else:
+			raise Exception('invalid option value: %r' % value)
+		force_options_yaml.append(yaml.safe_dump(doc))
+	def add_force_option_undefine(option, opt, value, parser):
+		tmp = value.split('=')
+		if len(tmp) == 1:
+			doc = { tmp[0]: False }
+		else:
+			raise Exception('invalid option value: %r' % value)
+		force_options_yaml.append(yaml.safe_dump(doc))
+
+	fixup_header_lines = []
+	def add_fixup_header_line(option, opt, value, parser):
+		fixup_header_lines.append(value)
+	def add_fixup_header_file(option, opt, value, parser):
+		with open(value, 'rb') as f:
+			for line in f:
+				if line[-1] == '\n':
+					line = line[:-1]
+				fixup_header_lines.append(line)
+
+	commands = [
+		'duk-config-header',
+		'feature-documentation',
+		'config-documentation'
+	]
+	parser = optparse.OptionParser(
+		usage='Usage: %prog [options] COMMAND',
+		description='Generate a duk_config.h or config option documentation based on config metadata.',
+		epilog='COMMAND can be one of: ' + ', '.join(commands) + '.'
+	)
+
+	parser.add_option('--metadata', dest='metadata', default=None, help='metadata directory or metadata tar.gz file')
+	parser.add_option('--output', dest='output', default=None, help='output filename for C header or RST documentation file')
+	parser.add_option('--platform', dest='platform', default=None, help='platform (for "barebones-header" command)')
+	parser.add_option('--compiler', dest='compiler', default=None, help='compiler (for "barebones-header" command)')
+	parser.add_option('--architecture', dest='architecture', default=None, help='architecture (for "barebones-header" command)')
+	parser.add_option('--c99-types-only', dest='c99_types_only', action='store_true', default=False, help='assume C99 types, no legacy type detection')
+	parser.add_option('--dll', dest='dll', action='store_true', default=False, help='dll build of Duktape, affects symbol visibility macros especially on Windows')
+	parser.add_option('--support-feature-options', dest='support_feature_options', action='store_true', default=False, help='support DUK_OPT_xxx feature options in duk_config.h')
+	parser.add_option('--emit-legacy-feature-check', dest='emit_legacy_feature_check', action='store_true', default=False, help='emit preprocessor checks to reject legacy feature options (DUK_OPT_xxx)')
+	parser.add_option('--emit-config-sanity-check', dest='emit_config_sanity_check', action='store_true', default=False, help='emit preprocessor checks for config option consistency (DUK_OPT_xxx)')
+	parser.add_option('--omit-removed-config-options', dest='omit_removed_config_options', action='store_true', default=False, help='omit removed config options from generated headers')
+	parser.add_option('--omit-deprecated-config-options', dest='omit_deprecated_config_options', action='store_true', default=False, help='omit deprecated config options from generated headers')
+	parser.add_option('--omit-unused-config-options', dest='omit_unused_config_options', action='store_true', default=False, help='omit unused config options from generated headers')
+	parser.add_option('--add-active-defines-macro', dest='add_active_defines_macro', action='store_true', default=False, help='add DUK_ACTIVE_DEFINES macro, for development only')
+	parser.add_option('--define', type='string', dest='force_options_yaml', action='callback', callback=add_force_option_define, default=force_options_yaml, help='force #define option using a C compiler like syntax, e.g. "--define DUK_USE_DEEP_C_STACK" or "--define DUK_USE_TRACEBACK_DEPTH=10"')
+	parser.add_option('-D', type='string', dest='force_options_yaml', action='callback', callback=add_force_option_define, default=force_options_yaml, help='synonym for --define, e.g. "-DDUK_USE_DEEP_C_STACK" or "-DDUK_USE_TRACEBACK_DEPTH=10"')
+	parser.add_option('--undefine', type='string', dest='force_options_yaml', action='callback', callback=add_force_option_undefine, default=force_options_yaml, help='force #undef option using a C compiler like syntax, e.g. "--undefine DUK_USE_DEEP_C_STACK"')
+	parser.add_option('-U', type='string', dest='force_options_yaml', action='callback', callback=add_force_option_undefine, default=force_options_yaml, help='synonym for --undefine, e.g. "-UDUK_USE_DEEP_C_STACK"')
+	parser.add_option('--option-yaml', type='string', dest='force_options_yaml', action='callback', callback=add_force_option_yaml, default=force_options_yaml, help='force option(s) using inline YAML (e.g. --option-yaml "DUK_USE_DEEP_C_STACK: true")')
+	parser.add_option('--option-file', type='string', dest='force_options_yaml', action='callback', callback=add_force_option_file, default=force_options_yaml, help='YAML file(s) providing config option overrides')
+	parser.add_option('--fixup-file', type='string', dest='fixup_header_lines', action='callback', callback=add_fixup_header_file, default=fixup_header_lines, help='C header snippet file(s) to be appended to generated header, useful for manual option fixups')
+	parser.add_option('--fixup-line', type='string', dest='fixup_header_lines', action='callback', callback=add_fixup_header_line, default=fixup_header_lines, help='C header fixup line to be appended to generated header (e.g. --fixup-line "#define DUK_USE_FASTINT")')
+	parser.add_option('--sanity-warning', dest='sanity_strict', action='store_false', default=True, help='emit a warning instead of #error for option sanity check issues')
+	parser.add_option('--use-cpp-warning', dest='use_cpp_warning', action='store_true', default=False, help='emit a (non-portable) #warning when appropriate')
+	parser.add_option('--git-commit', dest='git_commit', default=None, help='git commit hash to be included in header comments')
+	parser.add_option('--git-describe', dest='git_describe', default=None, help='git describe string to be included in header comments')
+	parser.add_option('--git-branch', dest='git_branch', default=None, help='git branch string to be included in header comments')
+	(opts, args) = parser.parse_args()
+
+	meta_dir = opts.metadata
+	if opts.metadata is None:
+		if os.path.isfile(os.path.join('.', 'genconfig_metadata.tar.gz')):
+			opts.metadata = 'genconfig_metadata.tar.gz'
+		elif os.path.isdir(os.path.join('.', 'config-options')):
+			opts.metadata = '.'
+
+	if opts.metadata is not None and os.path.isdir(opts.metadata):
+		meta_dir = opts.metadata
+		metadata_src_text = 'Using metadata directory: %r' % meta_dir
+	elif opts.metadata is not None and os.path.isfile(opts.metadata) and tarfile.is_tarfile(opts.metadata):
+		meta_dir = get_auto_delete_tempdir()
+		tar = tarfile.open(name=opts.metadata, mode='r:*')
+		tar.extractall(path=meta_dir)
+		metadata_src_text = 'Using metadata tar file %r, unpacked to directory: %r' % (opts.metadata, meta_dir)
+	else:
+		raise Exception('metadata source must be a directory or a tar.gz file')
+
+	scan_helper_snippets(os.path.join(meta_dir, 'helper-snippets'))
+	scan_use_defs(os.path.join(meta_dir, 'config-options'))
+	scan_opt_defs(os.path.join(meta_dir, 'feature-options'))
+	scan_use_tags()
+	scan_tags_meta(os.path.join(meta_dir, 'tags.yaml'))
+	print('%s, scanned %d DUK_OPT_xxx, %d DUK_USE_XXX, %d helper snippets' % \
+		(metadata_src_text, len(opt_defs.keys()), len(use_defs.keys()), len(helper_snippets)))
+	#print('Tags: %r' % use_tags_list)
+
+	if len(args) == 0:
+		raise Exception('missing command')
+	cmd = args[0]
+
+	# Compatibility with Duktape 1.3
+	if cmd == 'autodetect-header':
+		cmd = 'duk-config-header'
+	if cmd == 'barebones-header':
+		cmd = 'duk-config-header'
+
+	if cmd == 'duk-config-header':
+		# Generate a duk_config.h header with platform, compiler, and
+		# architecture either autodetected (default) or specified by
+		# user.  Support for autogenerated DUK_OPT_xxx flags is also
+		# selected by user.
+		result = generate_duk_config_header(opts, meta_dir)
+		with open(opts.output, 'wb') as f:
+			f.write(result)
+	elif cmd == 'feature-documentation':
+		result = generate_feature_option_documentation(opts)
+		with open(opts.output, 'wb') as f:
+			f.write(result)
+	elif cmd == 'config-documentation':
+		result = generate_config_option_documentation(opts)
+		with open(opts.output, 'wb') as f:
+			f.write(result)
+	else:
+		raise Exception('invalid command: %r' % cmd)
+
+if __name__ == '__main__':
+	main()

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/config/genconfig_metadata.tar.gz
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/config/genconfig_metadata.tar.gz b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/config/genconfig_metadata.tar.gz
new file mode 100644
index 0000000..c34b2ef
Binary files /dev/null and b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/config/genconfig_metadata.tar.gz differ

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/debugger/README.rst
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/debugger/README.rst b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/debugger/README.rst
new file mode 100644
index 0000000..f60b350
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/debugger/README.rst
@@ -0,0 +1,384 @@
+=========================================
+Duktape debug client and JSON debug proxy
+=========================================
+
+Overview
+========
+
+Debugger web UI which connects to the Duktape command line tool or any other
+target supporting the example TCP transport (``examples/debug-trans-socket``)
+on Unix and Windows.
+
+Also provides a JSON debug proxy with a JSON mapping for the Duktape debug
+protocol.
+
+For detailed documentation of the debugger internals, see `debugger.rst`__.
+
+__ https://github.com/svaarala/duktape/blob/master/doc/debugger.rst
+
+Using the debugger web UI
+=========================
+
+Some prerequisites:
+
+* You'll need Node.js v0.10.x or newer.  Older Node.js versions don't support
+  the required packages.
+
+Compile Duktape command line tool with debugger support (for further options
+see http://wiki.duktape.org/FeatureOptions.html):
+
+* ``DUK_OPT_DEBUGGER_SUPPORT``
+
+* ``DUK_OPT_INTERRUPT_COUNTER``
+
+* ``DUK_CMDLINE_DEBUGGER_SUPPORT``
+
+The source distributable contains a Makefile to build a "duk" command with
+debugger support::
+
+    $ cd <duktape dist directory>
+    $ make -f Makefile.dukdebug
+
+The Duktape Git repo "duk" target has debugger support enabled by default::
+
+    $ make clean duk
+
+Start Duktape command line tool so that it waits for a debugger connection::
+
+    # For now we need to be in the directory containing the source files
+    # executed so that the 'fileName' properties of functions will match
+    # that on the debug client.
+
+    # Using source distributable
+    $ cd <duktape dist directory>
+    $ ./duk --debugger mandel.js
+
+    # Using Duktape Git repo
+    $ cd <duktape checkout>/tests/ecmascript/
+    $ ../../duk --debugger test-dev-mandel2-func.js
+
+Start the web UI::
+
+    # Must be in 'debugger' directory.
+
+    $ cd debugger/
+    $ make  # runs 'node duk_debug.js'
+
+Once the required packages are installed, the NodeJS debug client will be
+up and running.  Open the following in your browser and start debugging:
+
+* http://localhost:9092/
+
+The debug client automatically attaches to the debug target on startup.
+If you start the debug target later, you'll need to click "Attach" in the
+web UI.
+
+Using the JSON debug proxy
+==========================
+
+There are two JSON debug proxy implementations: one implemented in DukLuv
+and another in Node.js.
+
+DukLuv JSON proxy
+-----------------
+
+DukLuv (https://github.com/creationix/dukluv) is a small and portable event
+loop based on LibUV and Duktape with MIT license (like Duktape).  As such it's
+easy to embed in a custom debug client: you just include the DukLuv executable
+and the JSON proxy source file in your debug client.
+
+Install DukLuv:
+
+* Ensure ``cmake`` is installed
+
+* ``git clone https://github.com/creationix/dukluv.git``
+
+* ``git submodule init; git submodule update``
+
+* ``make``
+
+* Binary should appear in:
+
+  - ``./build/dukluv`` on Linux
+
+  - ``.\build\Debug\dukluv.exe`` on Windows
+
+Run the proxy::
+
+    # Using Makefile; autogenerates duk_debug_meta.json
+    # (You may need to edit DUKLUV in Makefile to point to your DukLuv)
+    $ make runproxydukluv
+
+    # Manually: see "dukluv duk_debug_proxy.js --help" for help
+    $ .../path/to/dukluv duk_debug_proxy.js
+
+Start Duktape command line (or whatever your target is)::
+
+    $ cd <duktape checkout>/tests/ecmascript/
+    $ ../../duk --debugger test-dev-mandel2-func.js
+
+Now connect to the proxy using e.g. telnet::
+
+    $ telnet localhost 9093
+
+The proxy will then connect to the target and you can start issuing commands::
+
+    $ telnet localhost 9093
+    Trying 127.0.0.1...
+    Connected to localhost.
+    Escape character is '^]'.
+    {"notify":"_TargetConnecting","args":["127.0.0.1",9091]}
+    {"notify":"_TargetConnected","args":["1 10499 v1.4.0-140-gc9a6c7c duk command built from Duktape repo"]}
+    {"notify":"Status","command":1,"args":[1,"test-dev-mandel2-func.js","global",58,0]}
+    {"request":"BasicInfo"}
+    {"reply":true,"args":[10499,"v1.4.0-140-gc9a6c7c","duk command built from Duktape repo",1]}
+    {"request":"Eval","args":["print('Hello world!'); 123;"]}
+    {"notify":"Print","command":2,"args":["Hello world!\n"]}
+    {"reply":true,"args":[0,{"type":"number","data":"405ec00000000000"}]}
+    [...]
+
+The proxy log provides dumps both JSON and dvalue binary traffic which is
+quite useful in development::
+
+    $ make runproxydukluv
+    Running Dukluv based debug proxy
+    "dukluv" duk_debug_proxy.js --log-level 2 --metadata duk_debug_meta.json
+    2016-02-17T13:59:42.308Z INF Proxy: Read proxy metadata from duk_debug_meta.json
+    2016-02-17T13:59:42.325Z INF Proxy: Listening for incoming JSON debug connection on 0.0.0.0:9093, target is 127.0.0.1:9091
+    2016-02-17T13:59:47.994Z INF Proxy: JSON proxy client connected
+    2016-02-17T13:59:47.994Z INF Proxy: Connecting to debug target at 127.0.0.1:9091
+    2016-02-17T13:59:47.994Z INF Proxy: PROXY --> CLIENT: {"notify":"_TargetConnecting","args":["127.0.0.1",9091]}
+    2016-02-17T13:59:47.994Z INF Proxy: Connected to debug target at 127.0.0.1:9091
+    2016-02-17T13:59:48.003Z INF Proxy: PROXY --> CLIENT: {"notify":"_TargetConnected","args":["1 10499 v1.4.0-140-gc9a6c7c duk command built from Duktape repo"]}
+    2016-02-17T13:59:48.003Z INF Proxy: Target handshake: {"line":"1 10499 v1.4.0-140-gc9a6c7c duk command built from Duktape repo","protocolVersion":1,"text":"10499 v1.4.0-140-gc9a6c7c duk command built from Duktape repo","dukVersion":"1","dukGitDescribe":"10499","targetString":"v1.4.0-140-gc9a6c7c"}
+    2016-02-17T13:59:48.151Z INF Proxy: PROXY <-- TARGET: |04|
+    2016-02-17T13:59:48.152Z INF Proxy: PROXY <-- TARGET: |81|
+    2016-02-17T13:59:48.152Z INF Proxy: PROXY <-- TARGET: |81|
+    2016-02-17T13:59:48.160Z INF Proxy: PROXY <-- TARGET: |78746573742d6465762d6d616e64656c322d66756e632e6a73|
+    2016-02-17T13:59:48.161Z INF Proxy: PROXY <-- TARGET: |66676c6f62616c|
+    2016-02-17T13:59:48.165Z INF Proxy: PROXY <-- TARGET: |ba|
+    2016-02-17T13:59:48.165Z INF Proxy: PROXY <-- TARGET: |80|
+    2016-02-17T13:59:48.165Z INF Proxy: PROXY <-- TARGET: |00|
+    2016-02-17T13:59:48.165Z INF Proxy: PROXY --> CLIENT: {"notify":"Status","command":1,"args":[1,"test-dev-mandel2-func.js","global",58,0]}
+    2016-02-17T13:59:51.289Z INF Proxy: PROXY <-- CLIENT: {"request":"BasicInfo"}
+    2016-02-17T13:59:51.289Z INF Proxy: PROXY --> TARGET: |01|
+    2016-02-17T13:59:51.289Z INF Proxy: PROXY --> TARGET: |90|
+    2016-02-17T13:59:51.289Z INF Proxy: PROXY --> TARGET: |00|
+    2016-02-17T13:59:51.291Z INF Proxy: PROXY <-- TARGET: |02|
+    2016-02-17T13:59:51.291Z INF Proxy: PROXY <-- TARGET: |e903|
+    2016-02-17T13:59:51.292Z INF Proxy: PROXY <-- TARGET: |7376312e342e302d3134302d6763396136633763|
+    2016-02-17T13:59:51.293Z INF Proxy: PROXY <-- TARGET: |12002364756b20636f6d6d616e64206275696c742066726f6d2044756b74617065207265706f|
+    2016-02-17T13:59:51.293Z INF Proxy: PROXY <-- TARGET: |81|
+    2016-02-17T13:59:51.293Z INF Proxy: PROXY <-- TARGET: |00|
+    2016-02-17T13:59:51.293Z INF Proxy: PROXY --> CLIENT: {"reply":true,"args":[10499,"v1.4.0-140-gc9a6c7c","duk command built from Duktape repo",1]}
+    2016-02-17T14:00:06.105Z INF Proxy: PROXY <-- CLIENT: {"request":"Eval","args":["print('Hello world!'); 123;"]}
+    2016-02-17T14:00:06.105Z INF Proxy: PROXY --> TARGET: |01|
+    2016-02-17T14:00:06.105Z INF Proxy: PROXY --> TARGET: |9e|
+    2016-02-17T14:00:06.105Z INF Proxy: PROXY --> TARGET: |7b7072696e74282748656c6c6f20776f726c642127293b203132333b|
+    2016-02-17T14:00:06.105Z INF Proxy: PROXY --> TARGET: |00|
+    2016-02-17T14:00:06.167Z INF Proxy: PROXY <-- TARGET: |04|
+    2016-02-17T14:00:06.167Z INF Proxy: PROXY <-- TARGET: |82|
+    2016-02-17T14:00:06.167Z INF Proxy: PROXY <-- TARGET: |6d48656c6c6f20776f726c64210a|
+    2016-02-17T14:00:06.168Z INF Proxy: PROXY <-- TARGET: |00|
+    2016-02-17T14:00:06.168Z INF Proxy: PROXY --> CLIENT: {"notify":"Print","command":2,"args":["Hello world!\n"]}
+    2016-02-17T14:00:06.171Z INF Proxy: PROXY <-- TARGET: |02|
+    2016-02-17T14:00:06.171Z INF Proxy: PROXY <-- TARGET: |80|
+    2016-02-17T14:00:06.173Z INF Proxy: PROXY <-- TARGET: |1a405ec00000000000|
+    2016-02-17T14:00:06.173Z INF Proxy: PROXY <-- TARGET: |00|
+    2016-02-17T14:00:06.174Z INF Proxy: PROXY --> CLIENT: {"reply":true,"args":[0,{"type":"number","data":"405ec00000000000"}]}
+    [...]
+
+Node.js JSON proxy
+------------------
+
+A Node.js-based JSON debug proxy is also provided by ``duk_debug.js``::
+
+    # Same prerequisites as for running the debug client
+    $ make runproxynodejs
+
+Start Duktape command line (or whatever your target is)::
+
+    $ cd <duktape checkout>/tests/ecmascript/
+    $ ../../duk --debugger test-dev-mandel2-func.js
+
+You can then connect to localhost:9093 and interact with the proxy.
+Here's an example session using telnet and manually typed in commands
+The ``-->`` (send) and ``<--`` (receiver) markers have been added for
+readability and are not part of the stream::
+
+    $ telnet localhost 9093
+    Trying 127.0.0.1...
+    Connected to localhost.
+    Escape character is '^]'.
+    <-- {"notify":"_TargetConnected","args":["1 10199 v1.1.0-275-gbd4d610-dirty duk command built from Duktape repo"]}
+    <-- {"notify":"Status","command":1,"args":[1,"test-dev-mandel2-func.js","global",58,0]}
+    --> {"request":"BasicInfo"}
+    <-- {"reply":true,"args":[10199,"v1.1.0-275-gbd4d610-dirty","duk command built from Duktape repo",1]}
+    --> {"request":"Eval", "args":[ "print(Math.PI)" ]}
+    <-- {"notify":"Print","command":2,"args":["3.141592653589793\n"]}
+    <-- {"reply":true,"args":[0,{"type":"undefined"}]}
+    --> {"request":"Resume"}
+    <-- {"reply":true,"args":[]}
+    <-- {"notify":"Status","command":1,"args":[0,"test-dev-mandel2-func.js","global",58,0]}
+    <-- {"notify":"Status","command":1,"args":[0,"test-dev-mandel2-func.js","global",58,0]}
+    <-- {"notify":"Print","command":2,"args":["................................................................................\n"]}
+    <-- {"notify":"Print","command":2,"args":["................................................................................\n"]}
+    <-- {"notify":"Print","command":2,"args":["................................................................................\n"]}
+    [...]
+    <-- {"notify":"_Disconnecting"}
+
+A telnet connection allows you to experiment with debug commands by simply
+copy-pasting debug commands to the telnet session.  This is useful even if
+you decide to implement the binary protocol directly.
+
+The debug target used by the proxy can be configured with ``duk_debug.js``
+command line options.
+
+Source search path
+==================
+
+The NodeJS debug client needs to be able to find source code files matching
+code running on the target ("duk" command line).  **The filenames used on the
+target and on the debug client must match exactly**, because e.g. breakpoints
+are targeted based on the 'fileName' property of Function objects.
+
+The search path can be set using the ``--source-dirs`` option given to
+``duk_debug.js``, with the default search paths including only
+``../tests/ecmascript/``.
+
+The default search path means that if a function on the target has fileName
+``foo/bar.js`` it would be loaded from (relative to the duk_debug.js working
+directory, ``debugger/``)::
+
+    ../tests/ecmascript/foo/bar.js
+
+Similarly, if the filesystem contained::
+
+    ../tests/ecmascript/baz/quux.js
+
+the web UI dropdown would show ``baz/quux.js``.  If you selected that file
+and added a breakpoint, the breakpoint fileName sent to the debug target
+would be ``baz/quux.js``.
+
+.. note:: There's much to improve in the search path.  For instance, it'd
+          be nice to add a certain path to search but exclude files based
+          on paths and patterns, etc.
+
+Architecture
+============
+
+::
+
+    +-------------------+
+    | Web browser       |  [debug UI]
+    +-------------------+
+          |
+          | http (port 9092)
+          | socket.io
+          v
+    +-------------------+
+    | duk_debug.js      |  [debug client]
+    +-------------------+
+          |          /\
+          |          ||
+          +----------||---- [example tcp transport] (port 9091)
+          |          ||     (application provides concrete transport)
+          |          ||
+          |          ||---- [debug protocol stream]
+          |          ||     (between debug client and Duktape)
+          |          ||
+    + - - | - - - - -|| - - +
+    :     v          ||     :
+   �:  +-------------||-+   :  [target]
+    :  | application || |   :
+    :  +-------------||-+   :
+    :     ^          ||     :
+    :     |          ||     :   [debug API]
+    :     +----------||-------- debug transport callbacks
+    :     |          ||     :   (read, write, peek, read/write flush)
+    :     |          ||     :   implemented by application
+    :     |          \/     :
+    :  +----------------+   :
+    :  | Duktape        |   :
+    :  +----------------+   :
+    + - - - - - - - - - - - +
+
+The debug transport is application specific:
+
+* Duktape command line ("duk") and this debug client use an **example** TCP
+  transport as a concrete example.
+
+* It is entirely up to the application to come up with the most suitable
+  transport for its environment.  Different mechanisms will be needed for
+  Wi-Fi, serial, etc.
+
+The debug protocol running inside the transport is transport independent:
+
+* The debug protocol is documented in ``doc/debugger.rst``.
+
+* This debug client provides further concrete examples and clarifications
+  on how the protocol can be used.
+
+Using a custom transport
+========================
+
+Quite possibly your target device cannot use the example TCP transport and
+you need to implement your own transport.  You'll need to implement your
+custom transport both for the target device and for the debug client.
+
+Target device
+-------------
+
+Implement the debug transport callbacks needed by ``duk_debugger_attach()``.
+
+See ``doc/debugger.rst`` for details and ``examples/debug-trans-socket``
+for example running code for a TCP transport.
+
+Debug client alternative 1: duk_debug.js + custom TCP proxy
+-----------------------------------------------------------
+
+If you don't want to change ``duk_debug.js`` you can implement a TCP proxy
+which accepts a TCP connection from ``duk_debug.js`` and then uses your
+custom transport to talk to the target::
+
+   +--------------+   TCP   +-------+   custom   +--------+
+   | duk_debug.js | ------> | proxy | ---------> | target |
+   +--------------+         +-------+            +--------+
+
+This is a straightforward option and a proxy can be used with other debug
+clients too (perhaps custom scripts talking to the target etc).
+
+You could also use netcat and implement your proxy so that it talks to
+``duk_debug.js`` using stdin/stdout.
+
+Debug client alternative 2: duk_debug.js + custom NodeJS stream
+---------------------------------------------------------------
+
+To make ``duk_debug.js`` use a custom transport you need to:
+
+* Implement your own transport as NodeJS stream.  You can add it directly to
+  ``duk_debug.js`` but it's probably easiest to use a separate module so that
+  the diff to ``duk_debug.js`` stays minimal.
+
+* Change ``duk_debug.js`` to use the custom transport instead of a TCP
+  stream.  Search for "CUSTOMTRANSPORT" in ``duk_debug.js``.
+
+See:
+
+* http://nodejs.org/api/stream.html
+
+* https://github.com/substack/stream-handbook
+
+Debug client alternative 3: custom debug client
+-----------------------------------------------
+
+You can also implement your own debug client and debug UI with support for
+your custom transport.
+
+You'll also need to implement the client part of the Duktape debugger
+protocol.  See ``doc/debugger.rst`` for the specification and ``duk_debug.js``
+for example running code which should illustrate the protocol in more detail.
+
+The JSON debug proxy allows you to implement a debug client without needing
+to implement the Duktape binary debug protocol.  The JSON protocol provides
+a roughly 1:1 mapping to the binary protocol but with an easier syntax.

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/debugger/duk_classnames.yaml
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/debugger/duk_classnames.yaml b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/debugger/duk_classnames.yaml
new file mode 100644
index 0000000..9fd5098
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/debugger/duk_classnames.yaml
@@ -0,0 +1,32 @@
+# Must match C header.
+class_names:
+  - unused
+  - Arguments
+  - Array
+  - Boolean
+  - Date
+  - Error
+  - Function
+  - JSON
+  - Math
+  - Number
+  - Object
+  - RegExp
+  - String
+  - global
+  - ObjEnv
+  - DecEnv
+  - Buffer
+  - Pointer
+  - Thread
+  - ArrayBuffer
+  - DataView
+  - Int8Array
+  - Uint8Array
+  - Uint8ClampedArray
+  - Int16Array
+  - Uint16Array
+  - Int32Array
+  - Uint32Array
+  - Float32Array
+  - Float64Array


[10/51] [partial] nifi-minifi-cpp git commit: MINIFI-183 Added civet 1.9.1 sources Added onScheduled hook Added initial two-way TLS-enabled ListenHTTP implementation

Posted by al...@apache.org.
http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_bi_logger.c
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_bi_logger.c b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_bi_logger.c
new file mode 100644
index 0000000..d2b89e5
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_bi_logger.c
@@ -0,0 +1,300 @@
+/*
+ *  Logging support
+ */
+
+#include "duk_internal.h"
+
+/* 3-letter log level strings */
+DUK_LOCAL const duk_uint8_t duk__log_level_strings[] = {
+	(duk_uint8_t) DUK_ASC_UC_T, (duk_uint8_t) DUK_ASC_UC_R, (duk_uint8_t) DUK_ASC_UC_C,
+	(duk_uint8_t) DUK_ASC_UC_D, (duk_uint8_t) DUK_ASC_UC_B, (duk_uint8_t) DUK_ASC_UC_G,
+	(duk_uint8_t) DUK_ASC_UC_I, (duk_uint8_t) DUK_ASC_UC_N, (duk_uint8_t) DUK_ASC_UC_F,
+	(duk_uint8_t) DUK_ASC_UC_W, (duk_uint8_t) DUK_ASC_UC_R, (duk_uint8_t) DUK_ASC_UC_N,
+	(duk_uint8_t) DUK_ASC_UC_E, (duk_uint8_t) DUK_ASC_UC_R, (duk_uint8_t) DUK_ASC_UC_R,
+	(duk_uint8_t) DUK_ASC_UC_F, (duk_uint8_t) DUK_ASC_UC_T, (duk_uint8_t) DUK_ASC_UC_L
+};
+
+/* Constructor */
+DUK_INTERNAL duk_ret_t duk_bi_logger_constructor(duk_context *ctx) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_idx_t nargs;
+
+	/* Calling as a non-constructor is not meaningful. */
+	if (!duk_is_constructor_call(ctx)) {
+		return DUK_RET_TYPE_ERROR;
+	}
+
+	nargs = duk_get_top(ctx);
+	duk_set_top(ctx, 1);
+
+	duk_push_this(ctx);
+
+	/* [ name this ] */
+
+	if (nargs == 0) {
+		/* Automatic defaulting of logger name from caller.  This would
+		 * work poorly with tail calls, but constructor calls are currently
+		 * never tail calls, so tail calls are not an issue now.
+		 */
+
+		if (thr->callstack_top >= 2) {
+			duk_activation *act_caller = thr->callstack + thr->callstack_top - 2;
+			duk_hobject *func_caller;
+
+			func_caller = DUK_ACT_GET_FUNC(act_caller);
+			if (func_caller) {
+				/* Stripping the filename might be a good idea
+				 * ("/foo/bar/quux.js" -> logger name "quux"),
+				 * but now used verbatim.
+				 */
+				duk_push_hobject(ctx, func_caller);
+				duk_get_prop_stridx(ctx, -1, DUK_STRIDX_FILE_NAME);
+				duk_replace(ctx, 0);
+			}
+		}
+	}
+	/* the stack is unbalanced here on purpose; we only rely on the
+	 * initial two values: [ name this ].
+	 */
+
+	if (duk_is_string(ctx, 0)) {
+		duk_dup(ctx, 0);
+		duk_put_prop_stridx(ctx, 1, DUK_STRIDX_LC_N);
+	} else {
+		/* don't set 'n' at all, inherited value is used as name */
+	}
+
+	duk_compact(ctx, 1);
+
+	return 0;  /* keep default instance */
+}
+
+/* Default function to format objects.  Tries to use toLogString() but falls
+ * back to toString().  Any errors are propagated out without catching.
+ */
+DUK_INTERNAL duk_ret_t duk_bi_logger_prototype_fmt(duk_context *ctx) {
+	if (duk_get_prop_stridx(ctx, 0, DUK_STRIDX_TO_LOG_STRING)) {
+		/* [ arg toLogString ] */
+
+		duk_dup(ctx, 0);
+		duk_call_method(ctx, 0);
+
+		/* [ arg result ] */
+		return 1;
+	}
+
+	/* [ arg undefined ] */
+	duk_pop(ctx);
+	duk_to_string(ctx, 0);
+	return 1;
+}
+
+/* Default function to write a formatted log line.  Writes to stderr,
+ * appending a newline to the log line.
+ *
+ * The argument is a buffer whose visible size contains the log message.
+ * This function should avoid coercing the buffer to a string to avoid
+ * string table traffic.
+ */
+DUK_INTERNAL duk_ret_t duk_bi_logger_prototype_raw(duk_context *ctx) {
+	const char *data;
+	duk_size_t data_len;
+
+	DUK_UNREF(ctx);
+	DUK_UNREF(data);
+	DUK_UNREF(data_len);
+
+#ifdef DUK_USE_FILE_IO
+	data = (const char *) duk_require_buffer(ctx, 0, &data_len);
+	DUK_FWRITE((const void *) data, 1, data_len, DUK_STDERR);
+	DUK_FPUTC((int) '\n', DUK_STDERR);
+	DUK_FFLUSH(DUK_STDERR);
+#else
+	/* nop */
+#endif
+	return 0;
+}
+
+/* Log frontend shared helper, magic value indicates log level.  Provides
+ * frontend functions: trace(), debug(), info(), warn(), error(), fatal().
+ * This needs to have small footprint, reasonable performance, minimal
+ * memory churn, etc.
+ */
+DUK_INTERNAL duk_ret_t duk_bi_logger_prototype_log_shared(duk_context *ctx) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_double_t now;
+	duk_small_int_t entry_lev = duk_get_current_magic(ctx);
+	duk_small_int_t logger_lev;
+	duk_int_t nargs;
+	duk_int_t i;
+	duk_size_t tot_len;
+	const duk_uint8_t *arg_str;
+	duk_size_t arg_len;
+	duk_uint8_t *buf, *p;
+	const duk_uint8_t *q;
+	duk_uint8_t date_buf[DUK_BI_DATE_ISO8601_BUFSIZE];
+	duk_size_t date_len;
+	duk_small_int_t rc;
+
+	DUK_ASSERT(entry_lev >= 0 && entry_lev <= 5);
+	DUK_UNREF(thr);
+
+	/* XXX: sanitize to printable (and maybe ASCII) */
+	/* XXX: better multiline */
+
+	/*
+	 *  Logger arguments are:
+	 *
+	 *    magic: log level (0-5)
+	 *    this: logger
+	 *    stack: plain log args
+	 *
+	 *  We want to minimize memory churn so a two-pass approach
+	 *  is used: first pass formats arguments and computes final
+	 *  string length, second pass copies strings either into a
+	 *  pre-allocated and reused buffer (short messages) or into a
+	 *  newly allocated fixed buffer.  If the backend function plays
+	 *  nice, it won't coerce the buffer to a string (and thus
+	 *  intern it).
+	 */
+
+	nargs = duk_get_top(ctx);
+
+	/* [ arg1 ... argN this ] */
+
+	/*
+	 *  Log level check
+	 */
+
+	duk_push_this(ctx);
+
+	duk_get_prop_stridx(ctx, -1, DUK_STRIDX_LC_L);
+	logger_lev = (duk_small_int_t) duk_get_int(ctx, -1);
+	if (entry_lev < logger_lev) {
+		return 0;
+	}
+	/* log level could be popped but that's not necessary */
+
+	now = DUK_USE_DATE_GET_NOW(ctx);
+	duk_bi_date_format_timeval(now, date_buf);
+	date_len = DUK_STRLEN((const char *) date_buf);
+
+	duk_get_prop_stridx(ctx, -2, DUK_STRIDX_LC_N);
+	duk_to_string(ctx, -1);
+	DUK_ASSERT(duk_is_string(ctx, -1));
+
+	/* [ arg1 ... argN this loggerLevel loggerName ] */
+
+	/*
+	 *  Pass 1
+	 */
+
+	/* Line format: <time> <entryLev> <loggerName>: <msg> */
+
+	tot_len = 0;
+	tot_len += 3 +  /* separators: space, space, colon */
+	           3 +  /* level string */
+	           date_len +  /* time */
+	           duk_get_length(ctx, -1);  /* loggerName */
+
+	for (i = 0; i < nargs; i++) {
+		/* When formatting an argument to a string, errors may happen from multiple
+		 * causes.  In general we want to catch obvious errors like a toLogString()
+		 * throwing an error, but we don't currently try to catch every possible
+		 * error.  In particular, internal errors (like out of memory or stack) are
+		 * not caught.  Also, we expect Error toString() to not throw an error.
+		 */
+		if (duk_is_object(ctx, i)) {
+			/* duk_pcall_prop() may itself throw an error, but we're content
+			 * in catching the obvious errors (like toLogString() throwing an
+			 * error).
+			 */
+			duk_push_hstring_stridx(ctx, DUK_STRIDX_FMT);
+			duk_dup(ctx, i);
+			/* [ arg1 ... argN this loggerLevel loggerName 'fmt' arg ] */
+			/* call: this.fmt(arg) */
+			rc = duk_pcall_prop(ctx, -5 /*obj_index*/, 1 /*nargs*/);
+			if (rc) {
+				/* Keep the error as the result (coercing it might fail below,
+				 * but we don't catch that now).
+				 */
+				;
+			}
+			duk_replace(ctx, i);
+		}
+		(void) duk_to_lstring(ctx, i, &arg_len);
+		tot_len++;  /* sep (even before first one) */
+		tot_len += arg_len;
+	}
+
+	/*
+	 *  Pass 2
+	 */
+
+	/* XXX: There used to be a shared log buffer here, but it was removed
+	 * when dynamic buffer spare was removed.  The problem with using
+	 * bufwriter is that, without the spare, the buffer gets passed on
+	 * as an argument to the raw() call so it'd need to be resized
+	 * (reallocated) anyway.  If raw() call convention is changed, this
+	 * could be made more efficient.
+	 */
+
+	buf = (duk_uint8_t *) duk_push_fixed_buffer(ctx, tot_len);
+	DUK_ASSERT(buf != NULL);
+	p = buf;
+
+	DUK_MEMCPY((void *) p, (const void *) date_buf, (size_t) date_len);
+	p += date_len;
+	*p++ = (duk_uint8_t) DUK_ASC_SPACE;
+
+	q = duk__log_level_strings + (entry_lev * 3);
+	DUK_MEMCPY((void *) p, (const void *) q, (size_t) 3);
+	p += 3;
+
+	*p++ = (duk_uint8_t) DUK_ASC_SPACE;
+
+	arg_str = (const duk_uint8_t *) duk_get_lstring(ctx, -2, &arg_len);
+	DUK_MEMCPY((void *) p, (const void *) arg_str, (size_t) arg_len);
+	p += arg_len;
+
+	*p++ = (duk_uint8_t) DUK_ASC_COLON;
+
+	for (i = 0; i < nargs; i++) {
+		*p++ = (duk_uint8_t) DUK_ASC_SPACE;
+
+		arg_str = (const duk_uint8_t *) duk_get_lstring(ctx, i, &arg_len);
+		DUK_ASSERT(arg_str != NULL);
+		DUK_MEMCPY((void *) p, (const void *) arg_str, (size_t) arg_len);
+		p += arg_len;
+	}
+	DUK_ASSERT(buf + tot_len == p);
+
+	/* [ arg1 ... argN this loggerLevel loggerName buffer ] */
+
+#if defined(DUK_USE_DEBUGGER_SUPPORT) && defined(DUK_USE_DEBUGGER_FWD_LOGGING)
+	/* Do debugger forwarding before raw() because the raw() function
+	 * doesn't get the log level right now.
+	 */
+	if (DUK_HEAP_IS_DEBUGGER_ATTACHED(thr->heap)) {
+		const char *log_buf;
+		duk_size_t sz_buf;
+		log_buf = (const char *) duk_get_buffer(ctx, -1, &sz_buf);
+		DUK_ASSERT(log_buf != NULL);
+		duk_debug_write_notify(thr, DUK_DBG_CMD_LOG);
+		duk_debug_write_int(thr, (duk_int32_t) entry_lev);
+		duk_debug_write_string(thr, (const char *) log_buf, sz_buf);
+		duk_debug_write_eom(thr);
+	}
+#endif
+
+	/* Call this.raw(msg); look up through the instance allows user to override
+	 * the raw() function in the instance or in the prototype for maximum
+	 * flexibility.
+	 */
+	duk_push_hstring_stridx(ctx, DUK_STRIDX_RAW);
+	duk_dup(ctx, -2);
+	/* [ arg1 ... argN this loggerLevel loggerName buffer 'raw' buffer ] */
+	duk_call_prop(ctx, -6, 1);  /* this.raw(buffer) */
+
+	return 0;
+}

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_bi_math.c
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_bi_math.c b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_bi_math.c
new file mode 100644
index 0000000..62c9341
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_bi_math.c
@@ -0,0 +1,348 @@
+/*
+ *  Math built-ins
+ */
+
+#include "duk_internal.h"
+
+#if defined(DUK_USE_MATH_BUILTIN)
+
+/*
+ *  Use static helpers which can work with math.h functions matching
+ *  the following signatures. This is not portable if any of these math
+ *  functions is actually a macro.
+ *
+ *  Typing here is intentionally 'double' wherever values interact with
+ *  the standard library APIs.
+ */
+
+typedef double (*duk__one_arg_func)(double);
+typedef double (*duk__two_arg_func)(double, double);
+
+DUK_LOCAL duk_ret_t duk__math_minmax(duk_context *ctx, duk_double_t initial, duk__two_arg_func min_max) {
+	duk_idx_t n = duk_get_top(ctx);
+	duk_idx_t i;
+	duk_double_t res = initial;
+	duk_double_t t;
+
+	/*
+	 *  Note: fmax() does not match the E5 semantics.  E5 requires
+	 *  that if -any- input to Math.max() is a NaN, the result is a
+	 *  NaN.  fmax() will return a NaN only if -both- inputs are NaN.
+	 *  Same applies to fmin().
+	 *
+	 *  Note: every input value must be coerced with ToNumber(), even
+	 *  if we know the result will be a NaN anyway: ToNumber() may have
+	 *  side effects for which even order of evaluation matters.
+	 */
+
+	for (i = 0; i < n; i++) {
+		t = duk_to_number(ctx, i);
+		if (DUK_FPCLASSIFY(t) == DUK_FP_NAN || DUK_FPCLASSIFY(res) == DUK_FP_NAN) {
+			/* Note: not normalized, but duk_push_number() will normalize */
+			res = (duk_double_t) DUK_DOUBLE_NAN;
+		} else {
+			res = (duk_double_t) min_max(res, (double) t);
+		}
+	}
+
+	duk_push_number(ctx, res);
+	return 1;
+}
+
+DUK_LOCAL double duk__fmin_fixed(double x, double y) {
+	/* fmin() with args -0 and +0 is not guaranteed to return
+	 * -0 as Ecmascript requires.
+	 */
+	if (x == 0 && y == 0) {
+		/* XXX: what's the safest way of creating a negative zero? */
+		if (DUK_SIGNBIT(x) != 0 || DUK_SIGNBIT(y) != 0) {
+			return -0.0;
+		} else {
+			return +0.0;
+		}
+	}
+#ifdef DUK_USE_MATH_FMIN
+	return DUK_FMIN(x, y);
+#else
+	return (x < y ? x : y);
+#endif
+}
+
+DUK_LOCAL double duk__fmax_fixed(double x, double y) {
+	/* fmax() with args -0 and +0 is not guaranteed to return
+	 * +0 as Ecmascript requires.
+	 */
+	if (x == 0 && y == 0) {
+		if (DUK_SIGNBIT(x) == 0 || DUK_SIGNBIT(y) == 0) {
+			return +0.0;
+		} else {
+			return -0.0;
+		}
+	}
+#ifdef DUK_USE_MATH_FMAX
+	return DUK_FMAX(x, y);
+#else
+	return (x > y ? x : y);
+#endif
+}
+
+DUK_LOCAL double duk__round_fixed(double x) {
+	/* Numbers half-way between integers must be rounded towards +Infinity,
+	 * e.g. -3.5 must be rounded to -3 (not -4).  When rounded to zero, zero
+	 * sign must be set appropriately.  E5.1 Section 15.8.2.15.
+	 *
+	 * Note that ANSI C round() is "round to nearest integer, away from zero",
+	 * which is incorrect for negative values.  Here we make do with floor().
+	 */
+
+	duk_small_int_t c = (duk_small_int_t) DUK_FPCLASSIFY(x);
+	if (c == DUK_FP_NAN || c == DUK_FP_INFINITE || c == DUK_FP_ZERO) {
+		return x;
+	}
+
+	/*
+	 *  x is finite and non-zero
+	 *
+	 *  -1.6 -> floor(-1.1) -> -2
+	 *  -1.5 -> floor(-1.0) -> -1  (towards +Inf)
+	 *  -1.4 -> floor(-0.9) -> -1
+	 *  -0.5 -> -0.0               (special case)
+	 *  -0.1 -> -0.0               (special case)
+	 *  +0.1 -> +0.0               (special case)
+	 *  +0.5 -> floor(+1.0) -> 1   (towards +Inf)
+	 *  +1.4 -> floor(+1.9) -> 1
+	 *  +1.5 -> floor(+2.0) -> 2   (towards +Inf)
+	 *  +1.6 -> floor(+2.1) -> 2
+	 */
+
+	if (x >= -0.5 && x < 0.5) {
+		/* +0.5 is handled by floor, this is on purpose */
+		if (x < 0.0) {
+			return -0.0;
+		} else {
+			return +0.0;
+		}
+	}
+
+	return DUK_FLOOR(x + 0.5);
+}
+
+DUK_LOCAL double duk__pow_fixed(double x, double y) {
+	/* The ANSI C pow() semantics differ from Ecmascript.
+	 *
+	 * E.g. when x==1 and y is +/- infinite, the Ecmascript required
+	 * result is NaN, while at least Linux pow() returns 1.
+	 */
+
+	duk_small_int_t cx, cy, sx;
+
+	DUK_UNREF(cx);
+	DUK_UNREF(sx);
+	cy = (duk_small_int_t) DUK_FPCLASSIFY(y);
+
+	if (cy == DUK_FP_NAN) {
+		goto ret_nan;
+	}
+	if (DUK_FABS(x) == 1.0 && cy == DUK_FP_INFINITE) {
+		goto ret_nan;
+	}
+#if defined(DUK_USE_POW_NETBSD_WORKAROUND)
+	/* See test-bug-netbsd-math-pow.js: NetBSD 6.0 on x86 (at least) does not
+	 * correctly handle some cases where x=+/-0.  Specific fixes to these
+	 * here.
+	 */
+	cx = (duk_small_int_t) DUK_FPCLASSIFY(x);
+	if (cx == DUK_FP_ZERO && y < 0.0) {
+		sx = (duk_small_int_t) DUK_SIGNBIT(x);
+		if (sx == 0) {
+			/* Math.pow(+0,y) should be Infinity when y<0.  NetBSD pow()
+			 * returns -Infinity instead when y is <0 and finite.  The
+			 * if-clause also catches y == -Infinity (which works even
+			 * without the fix).
+			 */
+			return DUK_DOUBLE_INFINITY;
+		} else {
+			/* Math.pow(-0,y) where y<0 should be:
+			 *   - -Infinity if y<0 and an odd integer
+			 *   - Infinity otherwise
+			 * NetBSD pow() returns -Infinity for all finite y<0.  The
+			 * if-clause also catches y == -Infinity (which works even
+			 * without the fix).
+			 */
+
+			/* fmod() return value has same sign as input (negative) so
+			 * the result here will be in the range ]-2,0], 1 indicates
+			 * odd.  If x is -Infinity, NaN is returned and the odd check
+			 * always concludes "not odd" which results in desired outcome.
+			 */
+			double tmp = DUK_FMOD(y, 2);
+			if (tmp == -1.0) {
+				return -DUK_DOUBLE_INFINITY;
+			} else {
+				/* Not odd, or y == -Infinity */
+				return DUK_DOUBLE_INFINITY;
+			}
+		}
+	}
+#endif
+	return DUK_POW(x, y);
+
+ ret_nan:
+	return DUK_DOUBLE_NAN;
+}
+
+/* Wrappers for calling standard math library methods.  These may be required
+ * on platforms where one or more of the math built-ins are defined as macros
+ * or inline functions and are thus not suitable to be used as function pointers.
+ */
+#if defined(DUK_USE_AVOID_PLATFORM_FUNCPTRS)
+DUK_LOCAL double duk__fabs(double x) {
+	return DUK_FABS(x);
+}
+DUK_LOCAL double duk__acos(double x) {
+	return DUK_ACOS(x);
+}
+DUK_LOCAL double duk__asin(double x) {
+	return DUK_ASIN(x);
+}
+DUK_LOCAL double duk__atan(double x) {
+	return DUK_ATAN(x);
+}
+DUK_LOCAL double duk__ceil(double x) {
+	return DUK_CEIL(x);
+}
+DUK_LOCAL double duk__cos(double x) {
+	return DUK_COS(x);
+}
+DUK_LOCAL double duk__exp(double x) {
+	return DUK_EXP(x);
+}
+DUK_LOCAL double duk__floor(double x) {
+	return DUK_FLOOR(x);
+}
+DUK_LOCAL double duk__log(double x) {
+	return DUK_LOG(x);
+}
+DUK_LOCAL double duk__sin(double x) {
+	return DUK_SIN(x);
+}
+DUK_LOCAL double duk__sqrt(double x) {
+	return DUK_SQRT(x);
+}
+DUK_LOCAL double duk__tan(double x) {
+	return DUK_TAN(x);
+}
+DUK_LOCAL double duk__atan2(double x, double y) {
+	return DUK_ATAN2(x, y);
+}
+#endif  /* DUK_USE_AVOID_PLATFORM_FUNCPTRS */
+
+/* order must match constants in genbuiltins.py */
+DUK_LOCAL const duk__one_arg_func duk__one_arg_funcs[] = {
+#if defined(DUK_USE_AVOID_PLATFORM_FUNCPTRS)
+	duk__fabs,
+	duk__acos,
+	duk__asin,
+	duk__atan,
+	duk__ceil,
+	duk__cos,
+	duk__exp,
+	duk__floor,
+	duk__log,
+	duk__round_fixed,
+	duk__sin,
+	duk__sqrt,
+	duk__tan
+#else
+	DUK_FABS,
+	DUK_ACOS,
+	DUK_ASIN,
+	DUK_ATAN,
+	DUK_CEIL,
+	DUK_COS,
+	DUK_EXP,
+	DUK_FLOOR,
+	DUK_LOG,
+	duk__round_fixed,
+	DUK_SIN,
+	DUK_SQRT,
+	DUK_TAN
+#endif
+};
+
+/* order must match constants in genbuiltins.py */
+DUK_LOCAL const duk__two_arg_func duk__two_arg_funcs[] = {
+#if defined(DUK_USE_AVOID_PLATFORM_FUNCPTRS)
+	duk__atan2,
+	duk__pow_fixed
+#else
+	DUK_ATAN2,
+	duk__pow_fixed
+#endif
+};
+
+DUK_INTERNAL duk_ret_t duk_bi_math_object_onearg_shared(duk_context *ctx) {
+	duk_small_int_t fun_idx = duk_get_current_magic(ctx);
+	duk__one_arg_func fun;
+
+	DUK_ASSERT(fun_idx >= 0);
+	DUK_ASSERT(fun_idx < (duk_small_int_t) (sizeof(duk__one_arg_funcs) / sizeof(duk__one_arg_func)));
+	fun = duk__one_arg_funcs[fun_idx];
+	duk_push_number(ctx, (duk_double_t) fun((double) duk_to_number(ctx, 0)));
+	return 1;
+}
+
+DUK_INTERNAL duk_ret_t duk_bi_math_object_twoarg_shared(duk_context *ctx) {
+	duk_small_int_t fun_idx = duk_get_current_magic(ctx);
+	duk__two_arg_func fun;
+
+	DUK_ASSERT(fun_idx >= 0);
+	DUK_ASSERT(fun_idx < (duk_small_int_t) (sizeof(duk__two_arg_funcs) / sizeof(duk__two_arg_func)));
+	fun = duk__two_arg_funcs[fun_idx];
+	duk_push_number(ctx, (duk_double_t) fun((double) duk_to_number(ctx, 0), (double) duk_to_number(ctx, 1)));
+	return 1;
+}
+
+DUK_INTERNAL duk_ret_t duk_bi_math_object_max(duk_context *ctx) {
+	return duk__math_minmax(ctx, -DUK_DOUBLE_INFINITY, duk__fmax_fixed);
+}
+
+DUK_INTERNAL duk_ret_t duk_bi_math_object_min(duk_context *ctx) {
+	return duk__math_minmax(ctx, DUK_DOUBLE_INFINITY, duk__fmin_fixed);
+}
+
+DUK_INTERNAL duk_ret_t duk_bi_math_object_random(duk_context *ctx) {
+	duk_push_number(ctx, (duk_double_t) duk_util_tinyrandom_get_double((duk_hthread *) ctx));
+	return 1;
+}
+
+#else  /* DUK_USE_MATH_BUILTIN */
+
+/* A stubbed built-in is useful for e.g. compilation torture testing with BCC. */
+
+DUK_INTERNAL duk_ret_t duk_bi_math_object_onearg_shared(duk_context *ctx) {
+	DUK_UNREF(ctx);
+	return DUK_RET_UNIMPLEMENTED_ERROR;
+}
+
+DUK_INTERNAL duk_ret_t duk_bi_math_object_twoarg_shared(duk_context *ctx) {
+	DUK_UNREF(ctx);
+	return DUK_RET_UNIMPLEMENTED_ERROR;
+}
+
+DUK_INTERNAL duk_ret_t duk_bi_math_object_max(duk_context *ctx) {
+	DUK_UNREF(ctx);
+	return DUK_RET_UNIMPLEMENTED_ERROR;
+}
+
+DUK_INTERNAL duk_ret_t duk_bi_math_object_min(duk_context *ctx) {
+	DUK_UNREF(ctx);
+	return DUK_RET_UNIMPLEMENTED_ERROR;
+}
+
+DUK_INTERNAL duk_ret_t duk_bi_math_object_random(duk_context *ctx) {
+	DUK_UNREF(ctx);
+	return DUK_RET_UNIMPLEMENTED_ERROR;
+}
+
+#endif  /* DUK_USE_MATH_BUILTIN */

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_bi_number.c
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_bi_number.c b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_bi_number.c
new file mode 100644
index 0000000..4b7abf5
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_bi_number.c
@@ -0,0 +1,240 @@
+/*
+ *  Number built-ins
+ */
+
+#include "duk_internal.h"
+
+DUK_LOCAL duk_double_t duk__push_this_number_plain(duk_context *ctx) {
+	duk_hobject *h;
+
+	/* Number built-in accepts a plain number or a Number object (whose
+	 * internal value is operated on).  Other types cause TypeError.
+	 */
+
+	duk_push_this(ctx);
+	if (duk_is_number(ctx, -1)) {
+		DUK_DDD(DUK_DDDPRINT("plain number value: %!T", (duk_tval *) duk_get_tval(ctx, -1)));
+		goto done;
+	}
+	h = duk_get_hobject(ctx, -1);
+	if (!h ||
+	    (DUK_HOBJECT_GET_CLASS_NUMBER(h) != DUK_HOBJECT_CLASS_NUMBER)) {
+		DUK_DDD(DUK_DDDPRINT("unacceptable this value: %!T", (duk_tval *) duk_get_tval(ctx, -1)));
+		DUK_ERROR_TYPE((duk_hthread *) ctx, "number expected");
+	}
+	duk_get_prop_stridx(ctx, -1, DUK_STRIDX_INT_VALUE);
+	DUK_ASSERT(duk_is_number(ctx, -1));
+	DUK_DDD(DUK_DDDPRINT("number object: %!T, internal value: %!T",
+	                     (duk_tval *) duk_get_tval(ctx, -2), (duk_tval *) duk_get_tval(ctx, -1)));
+	duk_remove(ctx, -2);
+
+ done:
+	return duk_get_number(ctx, -1);
+}
+
+DUK_INTERNAL duk_ret_t duk_bi_number_constructor(duk_context *ctx) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_idx_t nargs;
+	duk_hobject *h_this;
+
+	DUK_UNREF(thr);
+
+	/*
+	 *  The Number constructor uses ToNumber(arg) for number coercion
+	 *  (coercing an undefined argument to NaN).  However, if the
+	 *  argument is not given at all, +0 must be used instead.  To do
+	 *  this, a vararg function is used.
+	 */
+
+	nargs = duk_get_top(ctx);
+	if (nargs == 0) {
+		duk_push_int(ctx, 0);
+	}
+	duk_to_number(ctx, 0);
+	duk_set_top(ctx, 1);
+	DUK_ASSERT_TOP(ctx, 1);
+
+	if (!duk_is_constructor_call(ctx)) {
+		return 1;
+	}
+
+	/*
+	 *  E5 Section 15.7.2.1 requires that the constructed object
+	 *  must have the original Number.prototype as its internal
+	 *  prototype.  However, since Number.prototype is non-writable
+	 *  and non-configurable, this doesn't have to be enforced here:
+	 *  The default object (bound to 'this') is OK, though we have
+	 *  to change its class.
+	 *
+	 *  Internal value set to ToNumber(arg) or +0; if no arg given,
+	 *  ToNumber(undefined) = NaN, so special treatment is needed
+	 *  (above).  String internal value is immutable.
+	 */
+
+	/* XXX: helper */
+	duk_push_this(ctx);
+	h_this = duk_get_hobject(ctx, -1);
+	DUK_ASSERT(h_this != NULL);
+	DUK_HOBJECT_SET_CLASS_NUMBER(h_this, DUK_HOBJECT_CLASS_NUMBER);
+
+	DUK_ASSERT(DUK_HOBJECT_GET_PROTOTYPE(thr->heap, h_this) == thr->builtins[DUK_BIDX_NUMBER_PROTOTYPE]);
+	DUK_ASSERT(DUK_HOBJECT_GET_CLASS_NUMBER(h_this) == DUK_HOBJECT_CLASS_NUMBER);
+	DUK_ASSERT(DUK_HOBJECT_HAS_EXTENSIBLE(h_this));
+
+	duk_dup(ctx, 0);  /* -> [ val obj val ] */
+	duk_xdef_prop_stridx(ctx, -2, DUK_STRIDX_INT_VALUE, DUK_PROPDESC_FLAGS_NONE);
+	return 0;  /* no return value -> don't replace created value */
+}
+
+DUK_INTERNAL duk_ret_t duk_bi_number_prototype_value_of(duk_context *ctx) {
+	(void) duk__push_this_number_plain(ctx);
+	return 1;
+}
+
+DUK_INTERNAL duk_ret_t duk_bi_number_prototype_to_string(duk_context *ctx) {
+	duk_small_int_t radix;
+	duk_small_uint_t n2s_flags;
+
+	(void) duk__push_this_number_plain(ctx);
+	if (duk_is_undefined(ctx, 0)) {
+		radix = 10;
+	} else {
+		radix = (duk_small_int_t) duk_to_int_check_range(ctx, 0, 2, 36);
+	}
+	DUK_DDD(DUK_DDDPRINT("radix=%ld", (long) radix));
+
+	n2s_flags = 0;
+
+	duk_numconv_stringify(ctx,
+	                      radix /*radix*/,
+	                      0 /*digits*/,
+	                      n2s_flags /*flags*/);
+	return 1;
+}
+
+DUK_INTERNAL duk_ret_t duk_bi_number_prototype_to_locale_string(duk_context *ctx) {
+	/* XXX: just use toString() for now; permitted although not recommended.
+	 * nargs==1, so radix is passed to toString().
+	 */
+	return duk_bi_number_prototype_to_string(ctx);
+}
+
+/*
+ *  toFixed(), toExponential(), toPrecision()
+ */
+
+/* XXX: shared helper for toFixed(), toExponential(), toPrecision()? */
+
+DUK_INTERNAL duk_ret_t duk_bi_number_prototype_to_fixed(duk_context *ctx) {
+	duk_small_int_t frac_digits;
+	duk_double_t d;
+	duk_small_int_t c;
+	duk_small_uint_t n2s_flags;
+
+	frac_digits = (duk_small_int_t) duk_to_int_check_range(ctx, 0, 0, 20);
+	d = duk__push_this_number_plain(ctx);
+
+	c = (duk_small_int_t) DUK_FPCLASSIFY(d);
+	if (c == DUK_FP_NAN || c == DUK_FP_INFINITE) {
+		goto use_to_string;
+	}
+
+	if (d >= 1.0e21 || d <= -1.0e21) {
+		goto use_to_string;
+	}
+
+	n2s_flags = DUK_N2S_FLAG_FIXED_FORMAT |
+	            DUK_N2S_FLAG_FRACTION_DIGITS;
+
+	duk_numconv_stringify(ctx,
+	                      10 /*radix*/,
+	                      frac_digits /*digits*/,
+	                      n2s_flags /*flags*/);
+	return 1;
+
+ use_to_string:
+	DUK_ASSERT_TOP(ctx, 2);
+	duk_to_string(ctx, -1);
+	return 1;
+}
+
+DUK_INTERNAL duk_ret_t duk_bi_number_prototype_to_exponential(duk_context *ctx) {
+	duk_bool_t frac_undefined;
+	duk_small_int_t frac_digits;
+	duk_double_t d;
+	duk_small_int_t c;
+	duk_small_uint_t n2s_flags;
+
+	d = duk__push_this_number_plain(ctx);
+
+	frac_undefined = duk_is_undefined(ctx, 0);
+	duk_to_int(ctx, 0);  /* for side effects */
+
+	c = (duk_small_int_t) DUK_FPCLASSIFY(d);
+	if (c == DUK_FP_NAN || c == DUK_FP_INFINITE) {
+		goto use_to_string;
+	}
+
+	frac_digits = (duk_small_int_t) duk_to_int_check_range(ctx, 0, 0, 20);
+
+	n2s_flags = DUK_N2S_FLAG_FORCE_EXP |
+	           (frac_undefined ? 0 : DUK_N2S_FLAG_FIXED_FORMAT);
+
+	duk_numconv_stringify(ctx,
+	                      10 /*radix*/,
+	                      frac_digits + 1 /*leading digit + fractions*/,
+	                      n2s_flags /*flags*/);
+	return 1;
+
+ use_to_string:
+	DUK_ASSERT_TOP(ctx, 2);
+	duk_to_string(ctx, -1);
+	return 1;
+}
+
+DUK_INTERNAL duk_ret_t duk_bi_number_prototype_to_precision(duk_context *ctx) {
+	/* The specification has quite awkward order of coercion and
+	 * checks for toPrecision().  The operations below are a bit
+	 * reordered, within constraints of observable side effects.
+	 */
+
+	duk_double_t d;
+	duk_small_int_t prec;
+	duk_small_int_t c;
+	duk_small_uint_t n2s_flags;
+
+	DUK_ASSERT_TOP(ctx, 1);
+
+	d = duk__push_this_number_plain(ctx);
+	if (duk_is_undefined(ctx, 0)) {
+		goto use_to_string;
+	}
+	DUK_ASSERT_TOP(ctx, 2);
+
+	duk_to_int(ctx, 0);  /* for side effects */
+
+	c = (duk_small_int_t) DUK_FPCLASSIFY(d);
+	if (c == DUK_FP_NAN || c == DUK_FP_INFINITE) {
+		goto use_to_string;
+	}
+
+	prec = (duk_small_int_t) duk_to_int_check_range(ctx, 0, 1, 21);
+
+	n2s_flags = DUK_N2S_FLAG_FIXED_FORMAT |
+	            DUK_N2S_FLAG_NO_ZERO_PAD;
+
+	duk_numconv_stringify(ctx,
+	                      10 /*radix*/,
+	                      prec /*digits*/,
+	                      n2s_flags /*flags*/);
+	return 1;
+
+ use_to_string:
+	/* Used when precision is undefined; also used for NaN (-> "NaN"),
+	 * and +/- infinity (-> "Infinity", "-Infinity").
+	 */
+
+	DUK_ASSERT_TOP(ctx, 2);
+	duk_to_string(ctx, -1);
+	return 1;
+}

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_bi_object.c
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_bi_object.c b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_bi_object.c
new file mode 100644
index 0000000..28509ab
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_bi_object.c
@@ -0,0 +1,577 @@
+/*
+ *  Object built-ins
+ */
+
+#include "duk_internal.h"
+
+DUK_INTERNAL duk_ret_t duk_bi_object_constructor(duk_context *ctx) {
+	if (!duk_is_constructor_call(ctx) &&
+	    !duk_is_null_or_undefined(ctx, 0)) {
+		duk_to_object(ctx, 0);
+		return 1;
+	}
+
+	if (duk_is_object(ctx, 0)) {
+		return 1;
+	}
+
+	/* Pointer and buffer primitive values are treated like other
+	 * primitives values which have a fully fledged object counterpart:
+	 * promote to an object value.  Lightfuncs are coerced with
+	 * ToObject() even they could also be returned as is.
+	 */
+	if (duk_check_type_mask(ctx, 0, DUK_TYPE_MASK_STRING |
+	                                DUK_TYPE_MASK_BOOLEAN |
+	                                DUK_TYPE_MASK_NUMBER |
+	                                DUK_TYPE_MASK_POINTER |
+	                                DUK_TYPE_MASK_BUFFER |
+	                                DUK_TYPE_MASK_LIGHTFUNC)) {
+		duk_to_object(ctx, 0);
+		return 1;
+	}
+
+	duk_push_object_helper(ctx,
+	                       DUK_HOBJECT_FLAG_EXTENSIBLE |
+	                       DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJECT),
+	                       DUK_BIDX_OBJECT_PROTOTYPE);
+	return 1;
+}
+
+/* Shared helper to implement Object.getPrototypeOf and the ES6
+ * Object.prototype.__proto__ getter.
+ *
+ * http://www.ecma-international.org/ecma-262/6.0/index.html#sec-get-object.prototype.__proto__
+ */
+DUK_INTERNAL duk_ret_t duk_bi_object_getprototype_shared(duk_context *ctx) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_hobject *h;
+	duk_hobject *proto;
+
+	DUK_UNREF(thr);
+
+	/* magic: 0=getter call, 1=Object.getPrototypeOf */
+	if (duk_get_current_magic(ctx) == 0) {
+		duk_push_this_coercible_to_object(ctx);
+		duk_insert(ctx, 0);
+	}
+
+	h = duk_require_hobject_or_lfunc(ctx, 0);
+	/* h is NULL for lightfunc */
+
+	/* XXX: should the API call handle this directly, i.e. attempt
+	 * to duk_push_hobject(ctx, null) would push a null instead?
+	 * (On the other hand 'undefined' would be just as logical, but
+	 * not wanted here.)
+	 */
+
+	if (h == NULL) {
+		duk_push_hobject_bidx(ctx, DUK_BIDX_FUNCTION_PROTOTYPE);
+	} else {
+		proto = DUK_HOBJECT_GET_PROTOTYPE(thr->heap, h);
+		if (proto) {
+			duk_push_hobject(ctx, proto);
+		} else {
+			duk_push_null(ctx);
+		}
+	}
+	return 1;
+}
+
+/* Shared helper to implement ES6 Object.setPrototypeOf and
+ * Object.prototype.__proto__ setter.
+ *
+ * http://www.ecma-international.org/ecma-262/6.0/index.html#sec-get-object.prototype.__proto__
+ * http://www.ecma-international.org/ecma-262/6.0/index.html#sec-object.setprototypeof
+ */
+DUK_INTERNAL duk_ret_t duk_bi_object_setprototype_shared(duk_context *ctx) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_hobject *h_obj;
+	duk_hobject *h_new_proto;
+	duk_hobject *h_curr;
+	duk_ret_t ret_success = 1;  /* retval for success path */
+
+	/* Preliminaries for __proto__ and setPrototypeOf (E6 19.1.2.18 steps 1-4);
+	 * magic: 0=setter call, 1=Object.setPrototypeOf
+	 */
+	if (duk_get_current_magic(ctx) == 0) {
+		duk_push_this_check_object_coercible(ctx);
+		duk_insert(ctx, 0);
+		if (!duk_check_type_mask(ctx, 1, DUK_TYPE_MASK_NULL | DUK_TYPE_MASK_OBJECT)) {
+			return 0;
+		}
+
+		/* __proto__ setter returns 'undefined' on success unlike the
+		 * setPrototypeOf() call which returns the target object.
+		 */
+		ret_success = 0;
+	} else {
+		duk_require_object_coercible(ctx, 0);
+		duk_require_type_mask(ctx, 1, DUK_TYPE_MASK_NULL | DUK_TYPE_MASK_OBJECT);
+	}
+
+	h_new_proto = duk_get_hobject(ctx, 1);
+	/* h_new_proto may be NULL */
+	if (duk_is_lightfunc(ctx, 0)) {
+		if (h_new_proto == thr->builtins[DUK_BIDX_FUNCTION_PROTOTYPE]) {
+			goto skip;
+		}
+		goto fail_nonextensible;
+	}
+	h_obj = duk_get_hobject(ctx, 0);
+	if (!h_obj) {
+		goto skip;
+	}
+	DUK_ASSERT(h_obj != NULL);
+
+	/* [[SetPrototypeOf]] standard behavior, E6 9.1.2 */
+	/* TODO: implement Proxy object support here */
+
+	if (h_new_proto == DUK_HOBJECT_GET_PROTOTYPE(thr->heap, h_obj)) {
+		goto skip;
+	}
+	if (!DUK_HOBJECT_HAS_EXTENSIBLE(h_obj)) {
+		goto fail_nonextensible;
+	}
+	for (h_curr = h_new_proto; h_curr != NULL; h_curr = DUK_HOBJECT_GET_PROTOTYPE(thr->heap, h_curr)) {
+		/* Loop prevention */
+		if (h_curr == h_obj) {
+			goto fail_loop;
+		}
+	}
+	DUK_HOBJECT_SET_PROTOTYPE_UPDREF(thr, h_obj, h_new_proto);
+	/* fall thru */
+
+ skip:
+	duk_set_top(ctx, 1);
+	return ret_success;
+
+ fail_nonextensible:
+ fail_loop:
+	return DUK_RET_TYPE_ERROR;
+}
+
+DUK_INTERNAL duk_ret_t duk_bi_object_constructor_get_own_property_descriptor(duk_context *ctx) {
+	/* XXX: no need for indirect call */
+	return duk_hobject_object_get_own_property_descriptor(ctx);
+}
+
+DUK_INTERNAL duk_ret_t duk_bi_object_constructor_create(duk_context *ctx) {
+	duk_tval *tv;
+	duk_hobject *proto = NULL;
+
+	DUK_ASSERT_TOP(ctx, 2);
+
+	tv = duk_get_tval(ctx, 0);
+	DUK_ASSERT(tv != NULL);
+	if (DUK_TVAL_IS_NULL(tv)) {
+		;
+	} else if (DUK_TVAL_IS_OBJECT(tv)) {
+		proto = DUK_TVAL_GET_OBJECT(tv);
+		DUK_ASSERT(proto != NULL);
+	} else {
+		return DUK_RET_TYPE_ERROR;
+	}
+
+	(void) duk_push_object_helper_proto(ctx,
+	                                    DUK_HOBJECT_FLAG_EXTENSIBLE |
+	                                    DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJECT),
+	                                    proto);
+
+	if (!duk_is_undefined(ctx, 1)) {
+		/* [ O Properties obj ] */
+
+		duk_replace(ctx, 0);
+
+		/* [ obj Properties ] */
+
+		/* Just call the "original" Object.defineProperties() to
+		 * finish up.
+		 */
+
+		return duk_bi_object_constructor_define_properties(ctx);
+	}
+
+	/* [ O Properties obj ] */
+
+	return 1;
+}
+
+DUK_INTERNAL duk_ret_t duk_bi_object_constructor_define_property(duk_context *ctx) {
+	duk_hobject *obj;
+	duk_hstring *key;
+	duk_hobject *get;
+	duk_hobject *set;
+	duk_idx_t idx_value;
+	duk_uint_t defprop_flags;
+
+	DUK_ASSERT(ctx != NULL);
+
+	DUK_DDD(DUK_DDDPRINT("Object.defineProperty(): ctx=%p obj=%!T key=%!T desc=%!T",
+	                     (void *) ctx,
+	                     (duk_tval *) duk_get_tval(ctx, 0),
+	                     (duk_tval *) duk_get_tval(ctx, 1),
+	                     (duk_tval *) duk_get_tval(ctx, 2)));
+
+	/* [ obj key desc ] */
+
+	/* Lightfuncs are currently supported by coercing to a temporary
+	 * Function object; changes will be allowed (the coerced value is
+	 * extensible) but will be lost.
+	 */
+	obj = duk_require_hobject_or_lfunc_coerce(ctx, 0);
+	(void) duk_to_string(ctx, 1);
+	key = duk_require_hstring(ctx, 1);
+	(void) duk_require_hobject(ctx, 2);
+
+	DUK_ASSERT(obj != NULL);
+	DUK_ASSERT(key != NULL);
+	DUK_ASSERT(duk_get_hobject(ctx, 2) != NULL);
+
+	/*
+	 *  Validate and convert argument property descriptor (an Ecmascript
+	 *  object) into a set of defprop_flags and possibly property value,
+	 *  getter, and/or setter values on the value stack.
+	 *
+	 *  Lightfunc set/get values are coerced to full Functions.
+	 */
+
+	duk_hobject_prepare_property_descriptor(ctx,
+	                                        2 /*idx_desc*/,
+	                                        &defprop_flags,
+	                                        &idx_value,
+	                                        &get,
+	                                        &set);
+
+	/*
+	 *  Use Object.defineProperty() helper for the actual operation.
+	 */
+
+	duk_hobject_define_property_helper(ctx,
+	                                   defprop_flags,
+	                                   obj,
+	                                   key,
+	                                   idx_value,
+	                                   get,
+	                                   set);
+
+	/* Ignore the normalize/validate helper outputs on the value stack,
+	 * they're popped automatically.
+	 */
+
+	/*
+	 *  Return target object.
+	 */
+
+	duk_push_hobject(ctx, obj);
+	return 1;
+}
+
+DUK_INTERNAL duk_ret_t duk_bi_object_constructor_define_properties(duk_context *ctx) {
+	duk_small_uint_t pass;
+	duk_uint_t defprop_flags;
+	duk_hobject *obj;
+	duk_idx_t idx_value;
+	duk_hobject *get;
+	duk_hobject *set;
+
+	/* Lightfunc handling by ToObject() coercion. */
+	obj = duk_require_hobject_or_lfunc_coerce(ctx, 0);  /* target */
+	DUK_ASSERT(obj != NULL);
+
+	duk_to_object(ctx, 1);        /* properties object */
+
+	DUK_DDD(DUK_DDDPRINT("target=%!iT, properties=%!iT",
+	                     (duk_tval *) duk_get_tval(ctx, 0),
+	                     (duk_tval *) duk_get_tval(ctx, 1)));
+
+	/*
+	 *  Two pass approach to processing the property descriptors.
+	 *  On first pass validate and normalize all descriptors before
+	 *  any changes are made to the target object.  On second pass
+	 *  make the actual modifications to the target object.
+	 *
+	 *  Right now we'll just use the same normalize/validate helper
+	 *  on both passes, ignoring its outputs on the first pass.
+	 */
+
+	for (pass = 0; pass < 2; pass++) {
+		duk_set_top(ctx, 2);  /* -> [ hobject props ] */
+		duk_enum(ctx, 1, DUK_ENUM_OWN_PROPERTIES_ONLY /*enum_flags*/);
+
+		for (;;) {
+			duk_hstring *key;
+
+			/* [ hobject props enum(props) ] */
+
+			duk_set_top(ctx, 3);
+
+			if (!duk_next(ctx, 2, 1 /*get_value*/)) {
+				break;
+			}
+
+			DUK_DDD(DUK_DDDPRINT("-> key=%!iT, desc=%!iT",
+			                     (duk_tval *) duk_get_tval(ctx, -2),
+			                     (duk_tval *) duk_get_tval(ctx, -1)));
+
+			/* [ hobject props enum(props) key desc ] */
+
+			duk_hobject_prepare_property_descriptor(ctx,
+			                                        4 /*idx_desc*/,
+			                                        &defprop_flags,
+			                                        &idx_value,
+			                                        &get,
+			                                        &set);
+
+			/* [ hobject props enum(props) key desc value? getter? setter? ] */
+
+			if (pass == 0) {
+				continue;
+			}
+
+			key = duk_get_hstring(ctx, 3);
+			DUK_ASSERT(key != NULL);
+
+			duk_hobject_define_property_helper(ctx,
+			                                   defprop_flags,
+			                                   obj,
+			                                   key,
+			                                   idx_value,
+			                                   get,
+			                                   set);
+		}
+	}
+
+	/*
+	 *  Return target object
+	 */
+
+	duk_dup(ctx, 0);
+	return 1;
+}
+
+DUK_INTERNAL duk_ret_t duk_bi_object_constructor_seal_freeze_shared(duk_context *ctx) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_hobject *h;
+	duk_bool_t is_freeze;
+
+	h = duk_require_hobject_or_lfunc(ctx, 0);
+	if (!h) {
+		/* Lightfunc, always success. */
+		return 1;
+	}
+
+	is_freeze = (duk_bool_t) duk_get_current_magic(ctx);
+	duk_hobject_object_seal_freeze_helper(thr, h, is_freeze);
+
+	/* Sealed and frozen objects cannot gain any more properties,
+	 * so this is a good time to compact them.
+	 */
+	duk_hobject_compact_props(thr, h);
+
+	return 1;
+}
+
+DUK_INTERNAL duk_ret_t duk_bi_object_constructor_prevent_extensions(duk_context *ctx) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_hobject *h;
+
+	h = duk_require_hobject_or_lfunc(ctx, 0);
+	if (!h) {
+		/* Lightfunc, always success. */
+		return 1;
+	}
+	DUK_ASSERT(h != NULL);
+
+	DUK_HOBJECT_CLEAR_EXTENSIBLE(h);
+
+	/* A non-extensible object cannot gain any more properties,
+	 * so this is a good time to compact.
+	 */
+	duk_hobject_compact_props(thr, h);
+
+	return 1;
+}
+
+DUK_INTERNAL duk_ret_t duk_bi_object_constructor_is_sealed_frozen_shared(duk_context *ctx) {
+	duk_hobject *h;
+	duk_bool_t is_frozen;
+	duk_bool_t rc;
+
+	h = duk_require_hobject_or_lfunc(ctx, 0);
+	if (!h) {
+		duk_push_true(ctx);  /* frozen and sealed */
+	} else {
+		is_frozen = duk_get_current_magic(ctx);
+		rc = duk_hobject_object_is_sealed_frozen_helper((duk_hthread *) ctx, h, is_frozen /*is_frozen*/);
+		duk_push_boolean(ctx, rc);
+	}
+	return 1;
+}
+
+DUK_INTERNAL duk_ret_t duk_bi_object_constructor_is_extensible(duk_context *ctx) {
+	duk_hobject *h;
+
+	h = duk_require_hobject_or_lfunc(ctx, 0);
+	if (!h) {
+		duk_push_false(ctx);
+	} else {
+		duk_push_boolean(ctx, DUK_HOBJECT_HAS_EXTENSIBLE(h));
+	}
+	return 1;
+}
+
+/* Shared helper for Object.getOwnPropertyNames() and Object.keys().
+ * Magic: 0=getOwnPropertyNames, 1=Object.keys.
+ */
+DUK_INTERNAL duk_ret_t duk_bi_object_constructor_keys_shared(duk_context *ctx) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_hobject *obj;
+#if defined(DUK_USE_ES6_PROXY)
+	duk_hobject *h_proxy_target;
+	duk_hobject *h_proxy_handler;
+	duk_hobject *h_trap_result;
+	duk_uarridx_t i, len, idx;
+#endif
+	duk_small_uint_t enum_flags;
+
+	DUK_ASSERT_TOP(ctx, 1);
+	DUK_UNREF(thr);
+
+	obj = duk_require_hobject_or_lfunc_coerce(ctx, 0);
+	DUK_ASSERT(obj != NULL);
+	DUK_UNREF(obj);
+
+#if defined(DUK_USE_ES6_PROXY)
+	if (DUK_LIKELY(!duk_hobject_proxy_check(thr,
+	                                        obj,
+	                                        &h_proxy_target,
+	                                        &h_proxy_handler))) {
+		goto skip_proxy;
+	}
+
+	duk_push_hobject(ctx, h_proxy_handler);
+	if (!duk_get_prop_stridx(ctx, -1, DUK_STRIDX_OWN_KEYS)) {
+		/* Careful with reachability here: don't pop 'obj' before pushing
+		 * proxy target.
+		 */
+		DUK_DDD(DUK_DDDPRINT("no ownKeys trap, get keys of target instead"));
+		duk_pop_2(ctx);
+		duk_push_hobject(ctx, h_proxy_target);
+		duk_replace(ctx, 0);
+		DUK_ASSERT_TOP(ctx, 1);
+		goto skip_proxy;
+	}
+
+	/* [ obj handler trap ] */
+	duk_insert(ctx, -2);
+	duk_push_hobject(ctx, h_proxy_target);  /* -> [ obj trap handler target ] */
+	duk_call_method(ctx, 1 /*nargs*/);      /* -> [ obj trap_result ] */
+	h_trap_result = duk_require_hobject(ctx, -1);
+	DUK_UNREF(h_trap_result);
+
+	len = (duk_uarridx_t) duk_get_length(ctx, -1);
+	idx = 0;
+	duk_push_array(ctx);
+	for (i = 0; i < len; i++) {
+		/* [ obj trap_result res_arr ] */
+		if (duk_get_prop_index(ctx, -2, i) && duk_is_string(ctx, -1)) {
+			/* XXX: for Object.keys() we should check enumerability of key */
+			/* [ obj trap_result res_arr propname ] */
+			duk_put_prop_index(ctx, -2, idx);
+			idx++;
+		} else {
+			duk_pop(ctx);
+		}
+	}
+
+	/* XXX: missing trap result validation for non-configurable target keys
+	 * (must be present), for non-extensible target all target keys must be
+	 * present and no extra keys can be present.
+	 * http://www.ecma-international.org/ecma-262/6.0/#sec-proxy-object-internal-methods-and-internal-slots-ownpropertykeys
+	 */
+
+	/* XXX: for Object.keys() the [[OwnPropertyKeys]] result (trap result)
+	 * should be filtered so that only enumerable keys remain.  Enumerability
+	 * should be checked with [[GetOwnProperty]] on the original object
+	 * (i.e., the proxy in this case).  If the proxy has a getOwnPropertyDescriptor
+	 * trap, it should be triggered for every property.  If the proxy doesn't have
+	 * the trap, enumerability should be checked against the target object instead.
+	 * We don't do any of this now, so Object.keys() and Object.getOwnPropertyNames()
+	 * return the same result now for proxy traps.  We still do clean up the trap
+	 * result, so that Object.keys() and Object.getOwnPropertyNames() will return a
+	 * clean array of strings without gaps.
+	 */
+	return 1;
+
+ skip_proxy:
+#endif  /* DUK_USE_ES6_PROXY */
+
+	DUK_ASSERT_TOP(ctx, 1);
+
+	if (duk_get_current_magic(ctx)) {
+		/* Object.keys */
+		enum_flags = DUK_ENUM_OWN_PROPERTIES_ONLY |
+		             DUK_ENUM_NO_PROXY_BEHAVIOR;
+	} else {
+		/* Object.getOwnPropertyNames */
+		enum_flags = DUK_ENUM_INCLUDE_NONENUMERABLE |
+		             DUK_ENUM_OWN_PROPERTIES_ONLY |
+		             DUK_ENUM_NO_PROXY_BEHAVIOR;
+	}
+
+	return duk_hobject_get_enumerated_keys(ctx, enum_flags);
+}
+
+DUK_INTERNAL duk_ret_t duk_bi_object_prototype_to_string(duk_context *ctx) {
+	duk_push_this(ctx);
+	duk_to_object_class_string_top(ctx);
+	return 1;
+}
+
+DUK_INTERNAL duk_ret_t duk_bi_object_prototype_to_locale_string(duk_context *ctx) {
+	DUK_ASSERT_TOP(ctx, 0);
+	(void) duk_push_this_coercible_to_object(ctx);
+	duk_get_prop_stridx(ctx, 0, DUK_STRIDX_TO_STRING);
+	if (!duk_is_callable(ctx, 1)) {
+		return DUK_RET_TYPE_ERROR;
+	}
+	duk_dup(ctx, 0);  /* -> [ O toString O ] */
+	duk_call_method(ctx, 0);  /* XXX: call method tail call? */
+	return 1;
+}
+
+DUK_INTERNAL duk_ret_t duk_bi_object_prototype_value_of(duk_context *ctx) {
+	(void) duk_push_this_coercible_to_object(ctx);
+	return 1;
+}
+
+DUK_INTERNAL duk_ret_t duk_bi_object_prototype_is_prototype_of(duk_context *ctx) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_hobject *h_v;
+	duk_hobject *h_obj;
+
+	DUK_ASSERT_TOP(ctx, 1);
+
+	h_v = duk_get_hobject(ctx, 0);
+	if (!h_v) {
+		duk_push_false(ctx);  /* XXX: tail call: return duk_push_false(ctx) */
+		return 1;
+	}
+
+	h_obj = duk_push_this_coercible_to_object(ctx);
+	DUK_ASSERT(h_obj != NULL);
+
+	/* E5.1 Section 15.2.4.6, step 3.a, lookup proto once before compare.
+	 * Prototype loops should cause an error to be thrown.
+	 */
+	duk_push_boolean(ctx, duk_hobject_prototype_chain_contains(thr, DUK_HOBJECT_GET_PROTOTYPE(thr->heap, h_v), h_obj, 0 /*ignore_loop*/));
+	return 1;
+}
+
+DUK_INTERNAL duk_ret_t duk_bi_object_prototype_has_own_property(duk_context *ctx) {
+	return duk_hobject_object_ownprop_helper(ctx, 0 /*required_desc_flags*/);
+}
+
+DUK_INTERNAL duk_ret_t duk_bi_object_prototype_property_is_enumerable(duk_context *ctx) {
+	return duk_hobject_object_ownprop_helper(ctx, DUK_PROPDESC_FLAG_ENUMERABLE /*required_desc_flags*/);
+}

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_bi_pointer.c
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_bi_pointer.c b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_bi_pointer.c
new file mode 100644
index 0000000..340fbae
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_bi_pointer.c
@@ -0,0 +1,74 @@
+/*
+ *  Pointer built-ins
+ */
+
+#include "duk_internal.h"
+
+/*
+ *  Constructor
+ */
+
+DUK_INTERNAL duk_ret_t duk_bi_pointer_constructor(duk_context *ctx) {
+	/* XXX: this behavior is quite useless now; it would be nice to be able
+	 * to create pointer values from e.g. numbers or strings.  Numbers are
+	 * problematic on 64-bit platforms though.  Hex encoded strings?
+	 */
+	if (duk_get_top(ctx) == 0) {
+		duk_push_pointer(ctx, NULL);
+	} else {
+		duk_to_pointer(ctx, 0);
+	}
+	DUK_ASSERT(duk_is_pointer(ctx, 0));
+	duk_set_top(ctx, 1);
+
+	if (duk_is_constructor_call(ctx)) {
+		duk_push_object_helper(ctx,
+		                       DUK_HOBJECT_FLAG_EXTENSIBLE |
+		                       DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_POINTER),
+		                       DUK_BIDX_POINTER_PROTOTYPE);
+
+		/* Pointer object internal value is immutable */
+		duk_dup(ctx, 0);
+		duk_xdef_prop_stridx(ctx, -2, DUK_STRIDX_INT_VALUE, DUK_PROPDESC_FLAGS_NONE);
+	}
+	/* Note: unbalanced stack on purpose */
+
+	return 1;
+}
+
+/*
+ *  toString(), valueOf()
+ */
+
+DUK_INTERNAL duk_ret_t duk_bi_pointer_prototype_tostring_shared(duk_context *ctx) {
+	duk_tval *tv;
+	duk_small_int_t to_string = duk_get_current_magic(ctx);
+
+	duk_push_this(ctx);
+	tv = duk_require_tval(ctx, -1);
+	DUK_ASSERT(tv != NULL);
+
+	if (DUK_TVAL_IS_POINTER(tv)) {
+		/* nop */
+	} else if (DUK_TVAL_IS_OBJECT(tv)) {
+		duk_hobject *h = DUK_TVAL_GET_OBJECT(tv);
+		DUK_ASSERT(h != NULL);
+
+		/* Must be a "pointer object", i.e. class "Pointer" */
+		if (DUK_HOBJECT_GET_CLASS_NUMBER(h) != DUK_HOBJECT_CLASS_POINTER) {
+			goto type_error;
+		}
+
+		duk_get_prop_stridx(ctx, -1, DUK_STRIDX_INT_VALUE);
+	} else {
+		goto type_error;
+	}
+
+	if (to_string) {
+		duk_to_string(ctx, -1);
+	}
+	return 1;
+
+ type_error:
+	return DUK_RET_TYPE_ERROR;
+}

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_bi_protos.h
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_bi_protos.h b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_bi_protos.h
new file mode 100644
index 0000000..f9b42bc
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_bi_protos.h
@@ -0,0 +1,69 @@
+/*
+ *  Prototypes for built-in functions not automatically covered by the
+ *  header declarations emitted by genbuiltins.py.
+ */
+
+#ifndef DUK_BUILTIN_PROTOS_H_INCLUDED
+#define DUK_BUILTIN_PROTOS_H_INCLUDED
+
+/* Buffer size needed for duk_bi_date_format_timeval().
+ * Accurate value is 32 + 1 for NUL termination:
+ *   >>> len('+123456-01-23T12:34:56.123+12:34')
+ *   32
+ * Include additional space to be safe.
+ */
+#define  DUK_BI_DATE_ISO8601_BUFSIZE  48
+
+/* Maximum length of CommonJS module identifier to resolve.  Length includes
+ * both current module ID, requested (possibly relative) module ID, and a
+ * slash in between.
+ */
+#define  DUK_BI_COMMONJS_MODULE_ID_LIMIT  256
+
+/* Helpers exposed for internal use */
+DUK_INTERNAL_DECL void duk_bi_date_timeval_to_parts(duk_double_t d, duk_int_t *parts, duk_double_t *dparts, duk_small_uint_t flags);
+DUK_INTERNAL_DECL duk_double_t duk_bi_date_get_timeval_from_dparts(duk_double_t *dparts, duk_small_uint_t flags);
+DUK_INTERNAL_DECL void duk_bi_date_format_timeval(duk_double_t timeval, duk_uint8_t *out_buf);
+DUK_INTERNAL_DECL duk_bool_t duk_bi_date_is_leap_year(duk_int_t year);
+DUK_INTERNAL_DECL duk_bool_t duk_bi_date_timeval_in_valid_range(duk_double_t x);
+DUK_INTERNAL_DECL duk_bool_t duk_bi_date_year_in_valid_range(duk_double_t year);
+DUK_INTERNAL_DECL duk_bool_t duk_bi_date_timeval_in_leeway_range(duk_double_t x);
+/* Built-in providers */
+#if defined(DUK_USE_DATE_NOW_GETTIMEOFDAY)
+DUK_INTERNAL_DECL duk_double_t duk_bi_date_get_now_gettimeofday(duk_context *ctx);
+#endif
+#if defined(DUK_USE_DATE_NOW_TIME)
+DUK_INTERNAL_DECL duk_double_t duk_bi_date_get_now_time(duk_context *ctx);
+#endif
+#if defined(DUK_USE_DATE_NOW_WINDOWS)
+DUK_INTERNAL_DECL duk_double_t duk_bi_date_get_now_windows(duk_context *ctx);
+#endif
+#if defined(DUK_USE_DATE_TZO_GMTIME_R) || defined(DUK_USE_DATE_TZO_GMTIME)
+DUK_INTERNAL_DECL duk_int_t duk_bi_date_get_local_tzoffset_gmtime(duk_double_t d);
+#endif
+#if defined(DUK_USE_DATE_TZO_WINDOWS)
+DUK_INTERNAL_DECL duk_int_t duk_bi_date_get_local_tzoffset_windows(duk_double_t d);
+#endif
+#if defined(DUK_USE_DATE_PRS_STRPTIME)
+DUK_INTERNAL_DECL duk_bool_t duk_bi_date_parse_string_strptime(duk_context *ctx, const char *str);
+#endif
+#if defined(DUK_USE_DATE_PRS_GETDATE)
+DUK_INTERNAL_DECL duk_bool_t duk_bi_date_parse_string_getdate(duk_context *ctx, const char *str);
+#endif
+#if defined(DUK_USE_DATE_FMT_STRFTIME)
+DUK_INTERNAL_DECL duk_bool_t duk_bi_date_format_parts_strftime(duk_context *ctx, duk_int_t *parts, duk_int_t tzoffset, duk_small_uint_t flags);
+#endif
+
+DUK_INTERNAL_DECL
+void duk_bi_json_parse_helper(duk_context *ctx,
+                              duk_idx_t idx_value,
+                              duk_idx_t idx_reviver,
+                              duk_small_uint_t flags);
+DUK_INTERNAL_DECL
+void duk_bi_json_stringify_helper(duk_context *ctx,
+                                  duk_idx_t idx_value,
+                                  duk_idx_t idx_replacer,
+                                  duk_idx_t idx_space,
+                                  duk_small_uint_t flags);
+
+#endif  /* DUK_BUILTIN_PROTOS_H_INCLUDED */

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_bi_proxy.c
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_bi_proxy.c b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_bi_proxy.c
new file mode 100644
index 0000000..9787ec4
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_bi_proxy.c
@@ -0,0 +1,66 @@
+/*
+ *  Proxy built-in (ES6)
+ */
+
+#include "duk_internal.h"
+
+#if defined(DUK_USE_ES6_PROXY)
+DUK_INTERNAL duk_ret_t duk_bi_proxy_constructor(duk_context *ctx) {
+	duk_hobject *h_target;
+	duk_hobject *h_handler;
+
+	if (!duk_is_constructor_call(ctx)) {
+		return DUK_RET_TYPE_ERROR;
+	}
+
+	/* Reject a proxy object as the target because it would need
+	 * special handler in property lookups.  (ES6 has no such restriction)
+	 */
+	h_target = duk_require_hobject_or_lfunc_coerce(ctx, 0);
+	DUK_ASSERT(h_target != NULL);
+	if (DUK_HOBJECT_HAS_EXOTIC_PROXYOBJ(h_target)) {
+		return DUK_RET_TYPE_ERROR;
+	}
+
+	/* Reject a proxy object as the handler because it would cause
+	 * potentially unbounded recursion.  (ES6 has no such restriction)
+	 */
+	h_handler = duk_require_hobject_or_lfunc_coerce(ctx, 1);
+	DUK_ASSERT(h_handler != NULL);
+	if (DUK_HOBJECT_HAS_EXOTIC_PROXYOBJ(h_handler)) {
+		return DUK_RET_TYPE_ERROR;
+	}
+
+	/* XXX: the returned value is exotic in ES6, but we use a
+	 * simple object here with no prototype.  Without a prototype,
+	 * [[DefaultValue]] coercion fails which is abit confusing.
+	 * No callable check/handling in the current Proxy subset.
+	 */
+	(void) duk_push_object_helper_proto(ctx,
+	                                    DUK_HOBJECT_FLAG_EXTENSIBLE |
+	                                    DUK_HOBJECT_FLAG_EXOTIC_PROXYOBJ |
+	                                    DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJECT),
+	                                    NULL);
+	DUK_ASSERT_TOP(ctx, 3);
+
+	/* Make _Target and _Handler non-configurable and non-writable.
+	 * They can still be forcibly changed by C code (both user and
+	 * Duktape internal), but not by Ecmascript code.
+	 */
+
+	/* Proxy target */
+	duk_dup(ctx, 0);
+	duk_xdef_prop_stridx(ctx, -2, DUK_STRIDX_INT_TARGET, DUK_PROPDESC_FLAGS_NONE);
+
+	/* Proxy handler */
+	duk_dup(ctx, 1);
+	duk_xdef_prop_stridx(ctx, -2, DUK_STRIDX_INT_HANDLER, DUK_PROPDESC_FLAGS_NONE);
+
+	return 1;  /* replacement handler */
+}
+#else  /* DUK_USE_ES6_PROXY */
+DUK_INTERNAL duk_ret_t duk_bi_proxy_constructor(duk_context *ctx) {
+	DUK_UNREF(ctx);
+	return DUK_RET_UNSUPPORTED_ERROR;
+}
+#endif  /* DUK_USE_ES6_PROXY */

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_bi_regexp.c
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_bi_regexp.c b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_bi_regexp.c
new file mode 100644
index 0000000..2259c77
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_bi_regexp.c
@@ -0,0 +1,209 @@
+/*
+ *  RegExp built-ins
+ */
+
+#include "duk_internal.h"
+
+#ifdef DUK_USE_REGEXP_SUPPORT
+
+DUK_LOCAL void duk__get_this_regexp(duk_context *ctx) {
+	duk_hobject *h;
+
+	duk_push_this(ctx);
+	h = duk_require_hobject_with_class(ctx, -1, DUK_HOBJECT_CLASS_REGEXP);
+	DUK_ASSERT(h != NULL);
+	DUK_UNREF(h);
+	duk_insert(ctx, 0);  /* prepend regexp to valstack 0 index */
+}
+
+/* XXX: much to improve (code size) */
+DUK_INTERNAL duk_ret_t duk_bi_regexp_constructor(duk_context *ctx) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_hobject *h_pattern;
+
+	DUK_ASSERT_TOP(ctx, 2);
+	h_pattern = duk_get_hobject(ctx, 0);
+
+	if (!duk_is_constructor_call(ctx) &&
+	    h_pattern != NULL &&
+	    DUK_HOBJECT_GET_CLASS_NUMBER(h_pattern) == DUK_HOBJECT_CLASS_REGEXP &&
+	    duk_is_undefined(ctx, 1)) {
+		/* Called as a function, pattern has [[Class]] "RegExp" and
+		 * flags is undefined -> return object as is.
+		 */
+		duk_dup(ctx, 0);
+		return 1;
+	}
+
+	/* Else functionality is identical for function call and constructor
+	 * call.
+	 */
+
+	if (h_pattern != NULL &&
+	    DUK_HOBJECT_GET_CLASS_NUMBER(h_pattern) == DUK_HOBJECT_CLASS_REGEXP) {
+		if (duk_is_undefined(ctx, 1)) {
+			duk_bool_t flag_g, flag_i, flag_m;
+			duk_get_prop_stridx(ctx, 0, DUK_STRIDX_SOURCE);
+			flag_g = duk_get_prop_stridx_boolean(ctx, 0, DUK_STRIDX_GLOBAL, NULL);
+			flag_i = duk_get_prop_stridx_boolean(ctx, 0, DUK_STRIDX_IGNORE_CASE, NULL);
+			flag_m = duk_get_prop_stridx_boolean(ctx, 0, DUK_STRIDX_MULTILINE, NULL);
+
+			duk_push_sprintf(ctx, "%s%s%s",
+			                 (const char *) (flag_g ? "g" : ""),
+			                 (const char *) (flag_i ? "i" : ""),
+			                 (const char *) (flag_m ? "m" : ""));
+
+			/* [ ... pattern flags ] */
+		} else {
+			return DUK_RET_TYPE_ERROR;
+		}
+	} else {
+		if (duk_is_undefined(ctx, 0)) {
+			duk_push_string(ctx, "");
+		} else {
+			duk_dup(ctx, 0);
+			duk_to_string(ctx, -1);
+		}
+		if (duk_is_undefined(ctx, 1)) {
+			duk_push_string(ctx, "");
+		} else {
+			duk_dup(ctx, 1);
+			duk_to_string(ctx, -1);
+		}
+
+		/* [ ... pattern flags ] */
+	}
+
+	DUK_DDD(DUK_DDDPRINT("RegExp constructor/function call, pattern=%!T, flags=%!T",
+	                     (duk_tval *) duk_get_tval(ctx, -2), (duk_tval *) duk_get_tval(ctx, -1)));
+
+	/* [ ... pattern flags ] */
+
+	duk_regexp_compile(thr);
+
+	/* [ ... bytecode escaped_source ] */
+
+	duk_regexp_create_instance(thr);
+
+	/* [ ... RegExp ] */
+
+	return 1;
+}
+
+DUK_INTERNAL duk_ret_t duk_bi_regexp_prototype_exec(duk_context *ctx) {
+	duk__get_this_regexp(ctx);
+
+	/* [ regexp input ] */
+
+	duk_regexp_match((duk_hthread *) ctx);
+
+	/* [ result ] */
+
+	return 1;
+}
+
+DUK_INTERNAL duk_ret_t duk_bi_regexp_prototype_test(duk_context *ctx) {
+	duk__get_this_regexp(ctx);
+
+	/* [ regexp input ] */
+
+	/* result object is created and discarded; wasteful but saves code space */
+	duk_regexp_match((duk_hthread *) ctx);
+
+	/* [ result ] */
+
+	duk_push_boolean(ctx, (duk_is_null(ctx, -1) ? 0 : 1));
+
+	return 1;
+}
+
+DUK_INTERNAL duk_ret_t duk_bi_regexp_prototype_to_string(duk_context *ctx) {
+	duk_hstring *h_bc;
+	duk_small_int_t re_flags;
+
+#if 0
+	/* A little tricky string approach to provide the flags string.
+	 * This depends on the specific flag values in duk_regexp.h,
+	 * which needs to be asserted for.  In practice this doesn't
+	 * produce more compact code than the easier approach in use.
+	 */
+
+	const char *flag_strings = "gim\0gi\0gm\0g\0";
+	duk_uint8_t flag_offsets[8] = {
+		(duk_uint8_t) 3,   /* flags: ""    */
+		(duk_uint8_t) 10,  /* flags: "g"   */
+		(duk_uint8_t) 5,   /* flags: "i"   */
+		(duk_uint8_t) 4,   /* flags: "gi"  */
+		(duk_uint8_t) 2,   /* flags: "m"   */
+		(duk_uint8_t) 7,   /* flags: "gm"  */
+		(duk_uint8_t) 1,   /* flags: "im"  */
+		(duk_uint8_t) 0,   /* flags: "gim" */
+	};
+	DUK_ASSERT(DUK_RE_FLAG_GLOBAL == 1);
+	DUK_ASSERT(DUK_RE_FLAG_IGNORE_CASE == 2);
+	DUK_ASSERT(DUK_RE_FLAG_MULTILINE == 4);
+#endif
+
+	duk__get_this_regexp(ctx);
+
+	/* [ regexp ] */
+
+	duk_get_prop_stridx(ctx, 0, DUK_STRIDX_SOURCE);
+	duk_get_prop_stridx(ctx, 0, DUK_STRIDX_INT_BYTECODE);
+	h_bc = duk_get_hstring(ctx, -1);
+	DUK_ASSERT(h_bc != NULL);
+	DUK_ASSERT(DUK_HSTRING_GET_BYTELEN(h_bc) >= 1);
+	DUK_ASSERT(DUK_HSTRING_GET_CHARLEN(h_bc) >= 1);
+	DUK_ASSERT(DUK_HSTRING_GET_DATA(h_bc)[0] < 0x80);
+	re_flags = (duk_small_int_t) DUK_HSTRING_GET_DATA(h_bc)[0];
+
+	/* [ regexp source bytecode ] */
+
+#if 1
+	/* This is a cleaner approach and also produces smaller code than
+	 * the other alternative.  Use duk_require_string() for format
+	 * safety (although the source property should always exist).
+	 */
+	duk_push_sprintf(ctx, "/%s/%s%s%s",
+	                 (const char *) duk_require_string(ctx, -2),  /* require to be safe */
+	                 (re_flags & DUK_RE_FLAG_GLOBAL) ? "g" : "",
+	                 (re_flags & DUK_RE_FLAG_IGNORE_CASE) ? "i" : "",
+	                 (re_flags & DUK_RE_FLAG_MULTILINE) ? "m" : "");
+#else
+	/* This should not be necessary because no-one should tamper with the
+	 * regexp bytecode, but is prudent to avoid potential segfaults if that
+	 * were to happen for some reason.
+	 */
+	re_flags &= 0x07;
+	DUK_ASSERT(re_flags >= 0 && re_flags <= 7);  /* three flags */
+	duk_push_sprintf(ctx, "/%s/%s",
+	                 (const char *) duk_require_string(ctx, -2),
+	                 (const char *) (flag_strings + flag_offsets[re_flags]));
+#endif
+
+	return 1;
+}
+
+#else  /* DUK_USE_REGEXP_SUPPORT */
+
+DUK_INTERNAL duk_ret_t duk_bi_regexp_constructor(duk_context *ctx) {
+	DUK_UNREF(ctx);
+	return DUK_RET_UNSUPPORTED_ERROR;
+}
+
+DUK_INTERNAL duk_ret_t duk_bi_regexp_prototype_exec(duk_context *ctx) {
+	DUK_UNREF(ctx);
+	return DUK_RET_UNSUPPORTED_ERROR;
+}
+
+DUK_INTERNAL duk_ret_t duk_bi_regexp_prototype_test(duk_context *ctx) {
+	DUK_UNREF(ctx);
+	return DUK_RET_UNSUPPORTED_ERROR;
+}
+
+DUK_INTERNAL duk_ret_t duk_bi_regexp_prototype_to_string(duk_context *ctx) {
+	DUK_UNREF(ctx);
+	return DUK_RET_UNSUPPORTED_ERROR;
+}
+
+#endif  /* DUK_USE_REGEXP_SUPPORT */


[09/51] [partial] nifi-minifi-cpp git commit: MINIFI-183 Added civet 1.9.1 sources Added onScheduled hook Added initial two-way TLS-enabled ListenHTTP implementation

Posted by al...@apache.org.
http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_bi_string.c
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_bi_string.c b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_bi_string.c
new file mode 100644
index 0000000..bf43750
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_bi_string.c
@@ -0,0 +1,1314 @@
+/*
+ *  String built-ins
+ */
+
+/* XXX: There are several limitations in the current implementation for
+ * strings with >= 0x80000000UL characters.  In some cases one would need
+ * to be able to represent the range [-0xffffffff,0xffffffff] and so on.
+ * Generally character and byte length are assumed to fit into signed 32
+ * bits (< 0x80000000UL).  Places with issues are not marked explicitly
+ * below in all cases, look for signed type usage (duk_int_t etc) for
+ * offsets/lengths.
+ */
+
+#include "duk_internal.h"
+
+/*
+ *  Constructor
+ */
+
+DUK_INTERNAL duk_ret_t duk_bi_string_constructor(duk_context *ctx) {
+	/* String constructor needs to distinguish between an argument not given at all
+	 * vs. given as 'undefined'.  We're a vararg function to handle this properly.
+	 */
+
+	if (duk_get_top(ctx) == 0) {
+		duk_push_hstring_stridx(ctx, DUK_STRIDX_EMPTY_STRING);
+	} else {
+		duk_to_string(ctx, 0);
+	}
+	DUK_ASSERT(duk_is_string(ctx, 0));
+	duk_set_top(ctx, 1);
+
+	if (duk_is_constructor_call(ctx)) {
+		duk_push_object_helper(ctx,
+		                       DUK_HOBJECT_FLAG_EXTENSIBLE |
+		                       DUK_HOBJECT_FLAG_EXOTIC_STRINGOBJ |
+		                       DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_STRING),
+		                       DUK_BIDX_STRING_PROTOTYPE);
+
+		/* String object internal value is immutable */
+		duk_dup(ctx, 0);
+		duk_xdef_prop_stridx(ctx, -2, DUK_STRIDX_INT_VALUE, DUK_PROPDESC_FLAGS_NONE);
+	}
+	/* Note: unbalanced stack on purpose */
+
+	return 1;
+}
+
+DUK_INTERNAL duk_ret_t duk_bi_string_constructor_from_char_code(duk_context *ctx) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_bufwriter_ctx bw_alloc;
+	duk_bufwriter_ctx *bw;
+	duk_idx_t i, n;
+	duk_ucodepoint_t cp;
+
+	/* XXX: It would be nice to build the string directly but ToUint16()
+	 * coercion is needed so a generic helper would not be very
+	 * helpful (perhaps coerce the value stack first here and then
+	 * build a string from a duk_tval number sequence in one go?).
+	 */
+
+	n = duk_get_top(ctx);
+
+	bw = &bw_alloc;
+	DUK_BW_INIT_PUSHBUF(thr, bw, n);  /* initial estimate for ASCII only codepoints */
+
+	for (i = 0; i < n; i++) {
+		/* XXX: could improve bufwriter handling to write multiple codepoints
+		 * with one ensure call but the relative benefit would be quite small.
+		 */
+
+#if defined(DUK_USE_NONSTD_STRING_FROMCHARCODE_32BIT)
+		/* ToUint16() coercion is mandatory in the E5.1 specification, but
+		 * this non-compliant behavior makes more sense because we support
+		 * non-BMP codepoints.  Don't use CESU-8 because that'd create
+		 * surrogate pairs.
+		 */
+
+		cp = (duk_ucodepoint_t) duk_to_uint32(ctx, i);
+		DUK_BW_WRITE_ENSURE_XUTF8(thr, bw, cp);
+#else
+		cp = (duk_ucodepoint_t) duk_to_uint16(ctx, i);
+		DUK_BW_WRITE_ENSURE_CESU8(thr, bw, cp);
+#endif
+	}
+
+	DUK_BW_COMPACT(thr, bw);
+	duk_to_string(ctx, -1);
+	return 1;
+}
+
+/*
+ *  toString(), valueOf()
+ */
+
+DUK_INTERNAL duk_ret_t duk_bi_string_prototype_to_string(duk_context *ctx) {
+	duk_tval *tv;
+
+	duk_push_this(ctx);
+	tv = duk_require_tval(ctx, -1);
+	DUK_ASSERT(tv != NULL);
+
+	if (DUK_TVAL_IS_STRING(tv)) {
+		/* return as is */
+		return 1;
+	} else if (DUK_TVAL_IS_OBJECT(tv)) {
+		duk_hobject *h = DUK_TVAL_GET_OBJECT(tv);
+		DUK_ASSERT(h != NULL);
+
+		/* Must be a "string object", i.e. class "String" */
+		if (DUK_HOBJECT_GET_CLASS_NUMBER(h) != DUK_HOBJECT_CLASS_STRING) {
+			goto type_error;
+		}
+
+		duk_get_prop_stridx(ctx, -1, DUK_STRIDX_INT_VALUE);
+		DUK_ASSERT(duk_is_string(ctx, -1));
+
+		return 1;
+	} else {
+		goto type_error;
+	}
+
+	/* never here, but fall through */
+
+ type_error:
+	return DUK_RET_TYPE_ERROR;
+}
+
+/*
+ *  Character and charcode access
+ */
+
+DUK_INTERNAL duk_ret_t duk_bi_string_prototype_char_at(duk_context *ctx) {
+	duk_int_t pos;
+
+	/* XXX: faster implementation */
+
+	(void) duk_push_this_coercible_to_string(ctx);
+	pos = duk_to_int(ctx, 0);
+	duk_substring(ctx, -1, pos, pos + 1);
+	return 1;
+}
+
+DUK_INTERNAL duk_ret_t duk_bi_string_prototype_char_code_at(duk_context *ctx) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_int_t pos;
+	duk_hstring *h;
+	duk_bool_t clamped;
+
+	/* XXX: faster implementation */
+
+	DUK_DDD(DUK_DDDPRINT("arg=%!T", (duk_tval *) duk_get_tval(ctx, 0)));
+
+	h = duk_push_this_coercible_to_string(ctx);
+	DUK_ASSERT(h != NULL);
+
+	pos = duk_to_int_clamped_raw(ctx,
+	                             0 /*index*/,
+	                             0 /*min(incl)*/,
+	                             DUK_HSTRING_GET_CHARLEN(h) - 1 /*max(incl)*/,
+	                             &clamped /*out_clamped*/);
+	if (clamped) {
+		duk_push_number(ctx, DUK_DOUBLE_NAN);
+		return 1;
+	}
+
+	duk_push_u32(ctx, (duk_uint32_t) duk_hstring_char_code_at_raw(thr, h, pos));
+	return 1;
+}
+
+/*
+ *  substring(), substr(), slice()
+ */
+
+/* XXX: any chance of merging these three similar but still slightly
+ * different algorithms so that footprint would be reduced?
+ */
+
+DUK_INTERNAL duk_ret_t duk_bi_string_prototype_substring(duk_context *ctx) {
+	duk_hstring *h;
+	duk_int_t start_pos, end_pos;
+	duk_int_t len;
+
+	h = duk_push_this_coercible_to_string(ctx);
+	DUK_ASSERT(h != NULL);
+	len = (duk_int_t) DUK_HSTRING_GET_CHARLEN(h);
+
+	/* [ start end str ] */
+
+	start_pos = duk_to_int_clamped(ctx, 0, 0, len);
+	if (duk_is_undefined(ctx, 1)) {
+		end_pos = len;
+	} else {
+		end_pos = duk_to_int_clamped(ctx, 1, 0, len);
+	}
+	DUK_ASSERT(start_pos >= 0 && start_pos <= len);
+	DUK_ASSERT(end_pos >= 0 && end_pos <= len);
+
+	if (start_pos > end_pos) {
+		duk_int_t tmp = start_pos;
+		start_pos = end_pos;
+		end_pos = tmp;
+	}
+
+	DUK_ASSERT(end_pos >= start_pos);
+
+	duk_substring(ctx, -1, (duk_size_t) start_pos, (duk_size_t) end_pos);
+	return 1;
+}
+
+#ifdef DUK_USE_SECTION_B
+DUK_INTERNAL duk_ret_t duk_bi_string_prototype_substr(duk_context *ctx) {
+	duk_hstring *h;
+	duk_int_t start_pos, end_pos;
+	duk_int_t len;
+
+	/* Unlike non-obsolete String calls, substr() algorithm in E5.1
+	 * specification will happily coerce undefined and null to strings
+	 * ("undefined" and "null").
+	 */
+	duk_push_this(ctx);
+	h = duk_to_hstring(ctx, -1);
+	DUK_ASSERT(h != NULL);
+	len = (duk_int_t) DUK_HSTRING_GET_CHARLEN(h);
+
+	/* [ start length str ] */
+
+	/* The implementation for computing of start_pos and end_pos differs
+	 * from the standard algorithm, but is intended to result in the exactly
+	 * same behavior.  This is not always obvious.
+	 */
+
+	/* combines steps 2 and 5; -len ensures max() not needed for step 5 */
+	start_pos = duk_to_int_clamped(ctx, 0, -len, len);
+	if (start_pos < 0) {
+		start_pos = len + start_pos;
+	}
+	DUK_ASSERT(start_pos >= 0 && start_pos <= len);
+
+	/* combines steps 3, 6; step 7 is not needed */
+	if (duk_is_undefined(ctx, 1)) {
+		end_pos = len;
+	} else {
+		DUK_ASSERT(start_pos <= len);
+		end_pos = start_pos + duk_to_int_clamped(ctx, 1, 0, len - start_pos);
+	}
+	DUK_ASSERT(start_pos >= 0 && start_pos <= len);
+	DUK_ASSERT(end_pos >= 0 && end_pos <= len);
+	DUK_ASSERT(end_pos >= start_pos);
+
+	duk_substring(ctx, -1, (duk_size_t) start_pos, (duk_size_t) end_pos);
+	return 1;
+}
+#else  /* DUK_USE_SECTION_B */
+DUK_INTERNAL duk_ret_t duk_bi_string_prototype_substr(duk_context *ctx) {
+	DUK_UNREF(ctx);
+	return DUK_RET_UNSUPPORTED_ERROR;
+}
+#endif  /* DUK_USE_SECTION_B */
+
+DUK_INTERNAL duk_ret_t duk_bi_string_prototype_slice(duk_context *ctx) {
+	duk_hstring *h;
+	duk_int_t start_pos, end_pos;
+	duk_int_t len;
+
+	h = duk_push_this_coercible_to_string(ctx);
+	DUK_ASSERT(h != NULL);
+	len = (duk_int_t) DUK_HSTRING_GET_CHARLEN(h);
+
+	/* [ start end str ] */
+
+	start_pos = duk_to_int_clamped(ctx, 0, -len, len);
+	if (start_pos < 0) {
+		start_pos = len + start_pos;
+	}
+	if (duk_is_undefined(ctx, 1)) {
+		end_pos = len;
+	} else {
+		end_pos = duk_to_int_clamped(ctx, 1, -len, len);
+		if (end_pos < 0) {
+			end_pos = len + end_pos;
+		}
+	}
+	DUK_ASSERT(start_pos >= 0 && start_pos <= len);
+	DUK_ASSERT(end_pos >= 0 && end_pos <= len);
+
+	if (end_pos < start_pos) {
+		end_pos = start_pos;
+	}
+
+	DUK_ASSERT(end_pos >= start_pos);
+
+	duk_substring(ctx, -1, (duk_size_t) start_pos, (duk_size_t) end_pos);
+	return 1;
+}
+
+/*
+ *  Case conversion
+ */
+
+DUK_INTERNAL duk_ret_t duk_bi_string_prototype_caseconv_shared(duk_context *ctx) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_small_int_t uppercase = duk_get_current_magic(ctx);
+
+	(void) duk_push_this_coercible_to_string(ctx);
+	duk_unicode_case_convert_string(thr, (duk_bool_t) uppercase);
+	return 1;
+}
+
+/*
+ *  indexOf() and lastIndexOf()
+ */
+
+DUK_INTERNAL duk_ret_t duk_bi_string_prototype_indexof_shared(duk_context *ctx) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_hstring *h_this;
+	duk_hstring *h_search;
+	duk_int_t clen_this;
+	duk_int_t cpos;
+	duk_int_t bpos;
+	const duk_uint8_t *p_start, *p_end, *p;
+	const duk_uint8_t *q_start;
+	duk_int_t q_blen;
+	duk_uint8_t firstbyte;
+	duk_uint8_t t;
+	duk_small_int_t is_lastindexof = duk_get_current_magic(ctx);  /* 0=indexOf, 1=lastIndexOf */
+
+	h_this = duk_push_this_coercible_to_string(ctx);
+	DUK_ASSERT(h_this != NULL);
+	clen_this = (duk_int_t) DUK_HSTRING_GET_CHARLEN(h_this);
+
+	h_search = duk_to_hstring(ctx, 0);
+	DUK_ASSERT(h_search != NULL);
+	q_start = DUK_HSTRING_GET_DATA(h_search);
+	q_blen = (duk_int_t) DUK_HSTRING_GET_BYTELEN(h_search);
+
+	duk_to_number(ctx, 1);
+	if (duk_is_nan(ctx, 1) && is_lastindexof) {
+		/* indexOf: NaN should cause pos to be zero.
+		 * lastIndexOf: NaN should cause pos to be +Infinity
+		 * (and later be clamped to len).
+		 */
+		cpos = clen_this;
+	} else {
+		cpos = duk_to_int_clamped(ctx, 1, 0, clen_this);
+	}
+
+	/* Empty searchstring always matches; cpos must be clamped here.
+	 * (If q_blen were < 0 due to clamped coercion, it would also be
+	 * caught here.)
+	 */
+	if (q_blen <= 0) {
+		duk_push_int(ctx, cpos);
+		return 1;
+	}
+	DUK_ASSERT(q_blen > 0);
+
+	bpos = (duk_int_t) duk_heap_strcache_offset_char2byte(thr, h_this, (duk_uint32_t) cpos);
+
+	p_start = DUK_HSTRING_GET_DATA(h_this);
+	p_end = p_start + DUK_HSTRING_GET_BYTELEN(h_this);
+	p = p_start + bpos;
+
+	/* This loop is optimized for size.  For speed, there should be
+	 * two separate loops, and we should ensure that memcmp() can be
+	 * used without an extra "will searchstring fit" check.  Doing
+	 * the preconditioning for 'p' and 'p_end' is easy but cpos
+	 * must be updated if 'p' is wound back (backward scanning).
+	 */
+
+	firstbyte = q_start[0];  /* leading byte of match string */
+	while (p <= p_end && p >= p_start) {
+		t = *p;
+
+		/* For Ecmascript strings, this check can only match for
+		 * initial UTF-8 bytes (not continuation bytes).  For other
+		 * strings all bets are off.
+		 */
+
+		if ((t == firstbyte) && ((duk_size_t) (p_end - p) >= (duk_size_t) q_blen)) {
+			DUK_ASSERT(q_blen > 0);  /* no issues with memcmp() zero size, even if broken */
+			if (DUK_MEMCMP((const void *) p, (const void *) q_start, (size_t) q_blen) == 0) {
+				duk_push_int(ctx, cpos);
+				return 1;
+			}
+		}
+
+		/* track cpos while scanning */
+		if (is_lastindexof) {
+			/* when going backwards, we decrement cpos 'early';
+			 * 'p' may point to a continuation byte of the char
+			 * at offset 'cpos', but that's OK because we'll
+			 * backtrack all the way to the initial byte.
+			 */
+			if ((t & 0xc0) != 0x80) {
+				cpos--;
+			}
+			p--;
+		} else {
+			if ((t & 0xc0) != 0x80) {
+				cpos++;
+			}
+			p++;
+		}
+	}
+
+	/* Not found.  Empty string case is handled specially above. */
+	duk_push_int(ctx, -1);
+	return 1;
+}
+
+/*
+ *  replace()
+ */
+
+/* XXX: the current implementation works but is quite clunky; it compiles
+ * to almost 1,4kB of x86 code so it needs to be simplified (better approach,
+ * shared helpers, etc).  Some ideas for refactoring:
+ *
+ * - a primitive to convert a string into a regexp matcher (reduces matching
+ *   code at the cost of making matching much slower)
+ * - use replace() as a basic helper for match() and split(), which are both
+ *   much simpler
+ * - API call to get_prop and to_boolean
+ */
+
+DUK_INTERNAL duk_ret_t duk_bi_string_prototype_replace(duk_context *ctx) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_hstring *h_input;
+	duk_hstring *h_match;
+	duk_hstring *h_search;
+	duk_hobject *h_re;
+	duk_bufwriter_ctx bw_alloc;
+	duk_bufwriter_ctx *bw;
+#ifdef DUK_USE_REGEXP_SUPPORT
+	duk_bool_t is_regexp;
+	duk_bool_t is_global;
+#endif
+	duk_bool_t is_repl_func;
+	duk_uint32_t match_start_coff, match_start_boff;
+#ifdef DUK_USE_REGEXP_SUPPORT
+	duk_int_t match_caps;
+#endif
+	duk_uint32_t prev_match_end_boff;
+	const duk_uint8_t *r_start, *r_end, *r;   /* repl string scan */
+	duk_size_t tmp_sz;
+
+	DUK_ASSERT_TOP(ctx, 2);
+	h_input = duk_push_this_coercible_to_string(ctx);
+	DUK_ASSERT(h_input != NULL);
+
+	bw = &bw_alloc;
+	DUK_BW_INIT_PUSHBUF(thr, bw, DUK_HSTRING_GET_BYTELEN(h_input));  /* input size is good output starting point */
+
+	DUK_ASSERT_TOP(ctx, 4);
+
+	/* stack[0] = search value
+	 * stack[1] = replace value
+	 * stack[2] = input string
+	 * stack[3] = result buffer
+	 */
+
+	h_re = duk_get_hobject_with_class(ctx, 0, DUK_HOBJECT_CLASS_REGEXP);
+	if (h_re) {
+#ifdef DUK_USE_REGEXP_SUPPORT
+		is_regexp = 1;
+		is_global = duk_get_prop_stridx_boolean(ctx, 0, DUK_STRIDX_GLOBAL, NULL);
+
+		if (is_global) {
+			/* start match from beginning */
+			duk_push_int(ctx, 0);
+			duk_put_prop_stridx(ctx, 0, DUK_STRIDX_LAST_INDEX);
+		}
+#else  /* DUK_USE_REGEXP_SUPPORT */
+		return DUK_RET_UNSUPPORTED_ERROR;
+#endif  /* DUK_USE_REGEXP_SUPPORT */
+	} else {
+		duk_to_string(ctx, 0);
+#ifdef DUK_USE_REGEXP_SUPPORT
+		is_regexp = 0;
+		is_global = 0;
+#endif
+	}
+
+	if (duk_is_function(ctx, 1)) {
+		is_repl_func = 1;
+		r_start = NULL;
+		r_end = NULL;
+	} else {
+		duk_hstring *h_repl;
+
+		is_repl_func = 0;
+		h_repl = duk_to_hstring(ctx, 1);
+		DUK_ASSERT(h_repl != NULL);
+		r_start = DUK_HSTRING_GET_DATA(h_repl);
+		r_end = r_start + DUK_HSTRING_GET_BYTELEN(h_repl);
+	}
+
+	prev_match_end_boff = 0;
+
+	for (;;) {
+		/*
+		 *  If matching with a regexp:
+		 *    - non-global RegExp: lastIndex not touched on a match, zeroed
+		 *      on a non-match
+		 *    - global RegExp: on match, lastIndex will be updated by regexp
+		 *      executor to point to next char after the matching part (so that
+		 *      characters in the matching part are not matched again)
+		 *
+		 *  If matching with a string:
+		 *    - always non-global match, find first occurrence
+		 *
+		 *  We need:
+		 *    - The character offset of start-of-match for the replacer function
+		 *    - The byte offsets for start-of-match and end-of-match to implement
+		 *      the replacement values $&, $`, and $', and to copy non-matching
+		 *      input string portions (including header and trailer) verbatim.
+		 *
+		 *  NOTE: the E5.1 specification is a bit vague how the RegExp should
+		 *  behave in the replacement process; e.g. is matching done first for
+		 *  all matches (in the global RegExp case) before any replacer calls
+		 *  are made?  See: test-bi-string-proto-replace.js for discussion.
+		 */
+
+		DUK_ASSERT_TOP(ctx, 4);
+
+#ifdef DUK_USE_REGEXP_SUPPORT
+		if (is_regexp) {
+			duk_dup(ctx, 0);
+			duk_dup(ctx, 2);
+			duk_regexp_match(thr);  /* [ ... regexp input ] -> [ res_obj ] */
+			if (!duk_is_object(ctx, -1)) {
+				duk_pop(ctx);
+				break;
+			}
+
+			duk_get_prop_stridx(ctx, -1, DUK_STRIDX_INDEX);
+			DUK_ASSERT(duk_is_number(ctx, -1));
+			match_start_coff = duk_get_int(ctx, -1);
+			duk_pop(ctx);
+
+			duk_get_prop_index(ctx, -1, 0);
+			DUK_ASSERT(duk_is_string(ctx, -1));
+			h_match = duk_get_hstring(ctx, -1);
+			DUK_ASSERT(h_match != NULL);
+			duk_pop(ctx);  /* h_match is borrowed, remains reachable through match_obj */
+
+			if (DUK_HSTRING_GET_BYTELEN(h_match) == 0) {
+				/* This should be equivalent to match() algorithm step 8.f.iii.2:
+				 * detect an empty match and allow it, but don't allow it twice.
+				 */
+				duk_uint32_t last_index;
+
+				duk_get_prop_stridx(ctx, 0, DUK_STRIDX_LAST_INDEX);
+				last_index = (duk_uint32_t) duk_get_uint(ctx, -1);
+				DUK_DDD(DUK_DDDPRINT("empty match, bump lastIndex: %ld -> %ld",
+				                     (long) last_index, (long) (last_index + 1)));
+				duk_pop(ctx);
+				duk_push_int(ctx, last_index + 1);
+				duk_put_prop_stridx(ctx, 0, DUK_STRIDX_LAST_INDEX);
+			}
+
+			DUK_ASSERT(duk_get_length(ctx, -1) <= DUK_INT_MAX);  /* string limits */
+			match_caps = (duk_int_t) duk_get_length(ctx, -1);
+		} else {
+#else  /* DUK_USE_REGEXP_SUPPORT */
+		{  /* unconditionally */
+#endif  /* DUK_USE_REGEXP_SUPPORT */
+			const duk_uint8_t *p_start, *p_end, *p;   /* input string scan */
+			const duk_uint8_t *q_start;               /* match string */
+			duk_size_t q_blen;
+
+#ifdef DUK_USE_REGEXP_SUPPORT
+			DUK_ASSERT(!is_global);  /* single match always */
+#endif
+
+			p_start = DUK_HSTRING_GET_DATA(h_input);
+			p_end = p_start + DUK_HSTRING_GET_BYTELEN(h_input);
+			p = p_start;
+
+			h_search = duk_get_hstring(ctx, 0);
+			DUK_ASSERT(h_search != NULL);
+			q_start = DUK_HSTRING_GET_DATA(h_search);
+			q_blen = (duk_size_t) DUK_HSTRING_GET_BYTELEN(h_search);
+
+			p_end -= q_blen;  /* ensure full memcmp() fits in while */
+
+			match_start_coff = 0;
+
+			while (p <= p_end) {
+				DUK_ASSERT(p + q_blen <= DUK_HSTRING_GET_DATA(h_input) + DUK_HSTRING_GET_BYTELEN(h_input));
+				if (DUK_MEMCMP((const void *) p, (const void *) q_start, (size_t) q_blen) == 0) {
+					duk_dup(ctx, 0);
+					h_match = duk_get_hstring(ctx, -1);
+					DUK_ASSERT(h_match != NULL);
+#ifdef DUK_USE_REGEXP_SUPPORT
+					match_caps = 0;
+#endif
+					goto found;
+				}
+
+				/* track utf-8 non-continuation bytes */
+				if ((p[0] & 0xc0) != 0x80) {
+					match_start_coff++;
+				}
+				p++;
+			}
+
+			/* not found */
+			break;
+		}
+	 found:
+
+		/* stack[0] = search value
+		 * stack[1] = replace value
+		 * stack[2] = input string
+		 * stack[3] = result buffer
+		 * stack[4] = regexp match OR match string
+		 */
+
+		match_start_boff = duk_heap_strcache_offset_char2byte(thr, h_input, match_start_coff);
+
+		tmp_sz = (duk_size_t) (match_start_boff - prev_match_end_boff);
+		DUK_BW_WRITE_ENSURE_BYTES(thr, bw, DUK_HSTRING_GET_DATA(h_input) + prev_match_end_boff, tmp_sz);
+
+		prev_match_end_boff = match_start_boff + DUK_HSTRING_GET_BYTELEN(h_match);
+
+		if (is_repl_func) {
+			duk_idx_t idx_args;
+			duk_hstring *h_repl;
+
+			/* regexp res_obj is at index 4 */
+
+			duk_dup(ctx, 1);
+			idx_args = duk_get_top(ctx);
+
+#ifdef DUK_USE_REGEXP_SUPPORT
+			if (is_regexp) {
+				duk_int_t idx;
+				duk_require_stack(ctx, match_caps + 2);
+				for (idx = 0; idx < match_caps; idx++) {
+					/* match followed by capture(s) */
+					duk_get_prop_index(ctx, 4, idx);
+				}
+			} else {
+#else  /* DUK_USE_REGEXP_SUPPORT */
+			{  /* unconditionally */
+#endif  /* DUK_USE_REGEXP_SUPPORT */
+				/* match == search string, by definition */
+				duk_dup(ctx, 0);
+			}
+			duk_push_int(ctx, match_start_coff);
+			duk_dup(ctx, 2);
+
+			/* [ ... replacer match [captures] match_char_offset input ] */
+
+			duk_call(ctx, duk_get_top(ctx) - idx_args);
+			h_repl = duk_to_hstring(ctx, -1);  /* -> [ ... repl_value ] */
+			DUK_ASSERT(h_repl != NULL);
+
+			DUK_BW_WRITE_ENSURE_HSTRING(thr, bw, h_repl);
+
+			duk_pop(ctx);  /* repl_value */
+		} else {
+			r = r_start;
+
+			while (r < r_end) {
+				duk_int_t ch1;
+				duk_int_t ch2;
+#ifdef DUK_USE_REGEXP_SUPPORT
+				duk_int_t ch3;
+#endif
+				duk_size_t left;
+
+				ch1 = *r++;
+				if (ch1 != DUK_ASC_DOLLAR) {
+					goto repl_write;
+				}
+				left = r_end - r;
+
+				if (left <= 0) {
+					goto repl_write;
+				}
+
+				ch2 = r[0];
+				switch ((int) ch2) {
+				case DUK_ASC_DOLLAR: {
+					ch1 = (1 << 8) + DUK_ASC_DOLLAR;
+					goto repl_write;
+				}
+				case DUK_ASC_AMP: {
+					DUK_BW_WRITE_ENSURE_HSTRING(thr, bw, h_match);
+					r++;
+					continue;
+				}
+				case DUK_ASC_GRAVE: {
+					tmp_sz = (duk_size_t) match_start_boff;
+					DUK_BW_WRITE_ENSURE_BYTES(thr, bw, DUK_HSTRING_GET_DATA(h_input), tmp_sz);
+					r++;
+					continue;
+				}
+				case DUK_ASC_SINGLEQUOTE: {
+					duk_uint32_t match_end_boff;
+
+					/* Use match charlen instead of bytelen, just in case the input and
+					 * match codepoint encodings would have different lengths.
+					 */
+					match_end_boff = duk_heap_strcache_offset_char2byte(thr,
+					                                                    h_input,
+					                                                    match_start_coff + DUK_HSTRING_GET_CHARLEN(h_match));
+
+					tmp_sz = (duk_size_t) (DUK_HSTRING_GET_BYTELEN(h_input) - match_end_boff);
+					DUK_BW_WRITE_ENSURE_BYTES(thr, bw, DUK_HSTRING_GET_DATA(h_input) + match_end_boff, tmp_sz);
+					r++;
+					continue;
+				}
+				default: {
+#ifdef DUK_USE_REGEXP_SUPPORT
+					duk_int_t capnum, captmp, capadv;
+					/* XXX: optional check, match_caps is zero if no regexp,
+					 * so dollar will be interpreted literally anyway.
+					 */
+
+					if (!is_regexp) {
+						goto repl_write;
+					}
+
+					if (!(ch2 >= DUK_ASC_0 && ch2 <= DUK_ASC_9)) {
+						goto repl_write;
+					}
+					capnum = ch2 - DUK_ASC_0;
+					capadv = 1;
+
+					if (left >= 2) {
+						ch3 = r[1];
+						if (ch3 >= DUK_ASC_0 && ch3 <= DUK_ASC_9) {
+							captmp = capnum * 10 + (ch3 - DUK_ASC_0);
+							if (captmp < match_caps) {
+								capnum = captmp;
+								capadv = 2;
+							}
+						}
+					}
+
+					if (capnum > 0 && capnum < match_caps) {
+						DUK_ASSERT(is_regexp != 0);  /* match_caps == 0 without regexps */
+
+						/* regexp res_obj is at offset 4 */
+						duk_get_prop_index(ctx, 4, (duk_uarridx_t) capnum);
+						if (duk_is_string(ctx, -1)) {
+							duk_hstring *h_tmp_str;
+
+							h_tmp_str = duk_get_hstring(ctx, -1);
+							DUK_ASSERT(h_tmp_str != NULL);
+
+							DUK_BW_WRITE_ENSURE_HSTRING(thr, bw, h_tmp_str);
+						} else {
+							/* undefined -> skip (replaced with empty) */
+						}
+						duk_pop(ctx);
+						r += capadv;
+						continue;
+					} else {
+						goto repl_write;
+					}
+#else  /* DUK_USE_REGEXP_SUPPORT */
+					goto repl_write;  /* unconditionally */
+#endif  /* DUK_USE_REGEXP_SUPPORT */
+				}  /* default case */
+				}  /* switch (ch2) */
+
+			 repl_write:
+				/* ch1 = (r_increment << 8) + byte */
+
+				DUK_BW_WRITE_ENSURE_U8(thr, bw, (duk_uint8_t) (ch1 & 0xff));
+				r += ch1 >> 8;
+			}  /* while repl */
+		}  /* if (is_repl_func) */
+
+		duk_pop(ctx);  /* pop regexp res_obj or match string */
+
+#ifdef DUK_USE_REGEXP_SUPPORT
+		if (!is_global) {
+#else
+		{  /* unconditionally; is_global==0 */
+#endif
+			break;
+		}
+	}
+
+	/* trailer */
+	tmp_sz = (duk_size_t) (DUK_HSTRING_GET_BYTELEN(h_input) - prev_match_end_boff);
+	DUK_BW_WRITE_ENSURE_BYTES(thr, bw, DUK_HSTRING_GET_DATA(h_input) + prev_match_end_boff, tmp_sz);
+
+	DUK_ASSERT_TOP(ctx, 4);
+	DUK_BW_COMPACT(thr, bw);
+	duk_to_string(ctx, -1);
+	return 1;
+}
+
+/*
+ *  split()
+ */
+
+/* XXX: very messy now, but works; clean up, remove unused variables (nomimally
+ * used so compiler doesn't complain).
+ */
+
+DUK_INTERNAL duk_ret_t duk_bi_string_prototype_split(duk_context *ctx) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_hstring *h_input;
+	duk_hstring *h_sep;
+	duk_uint32_t limit;
+	duk_uint32_t arr_idx;
+#ifdef DUK_USE_REGEXP_SUPPORT
+	duk_bool_t is_regexp;
+#endif
+	duk_bool_t matched;  /* set to 1 if any match exists (needed for empty input special case) */
+	duk_uint32_t prev_match_end_coff, prev_match_end_boff;
+	duk_uint32_t match_start_boff, match_start_coff;
+	duk_uint32_t match_end_boff, match_end_coff;
+
+	DUK_UNREF(thr);
+
+	h_input = duk_push_this_coercible_to_string(ctx);
+	DUK_ASSERT(h_input != NULL);
+
+	duk_push_array(ctx);
+
+	if (duk_is_undefined(ctx, 1)) {
+		limit = 0xffffffffUL;
+	} else {
+		limit = duk_to_uint32(ctx, 1);
+	}
+
+	if (limit == 0) {
+		return 1;
+	}
+
+	/* If the separator is a RegExp, make a "clone" of it.  The specification
+	 * algorithm calls [[Match]] directly for specific indices; we emulate this
+	 * by tweaking lastIndex and using a "force global" variant of duk_regexp_match()
+	 * which will use global-style matching even when the RegExp itself is non-global.
+	 */
+
+	if (duk_is_undefined(ctx, 0)) {
+		/* The spec algorithm first does "R = ToString(separator)" before checking
+		 * whether separator is undefined.  Since this is side effect free, we can
+		 * skip the ToString() here.
+		 */
+		duk_dup(ctx, 2);
+		duk_put_prop_index(ctx, 3, 0);
+		return 1;
+	} else if (duk_get_hobject_with_class(ctx, 0, DUK_HOBJECT_CLASS_REGEXP) != NULL) {
+#ifdef DUK_USE_REGEXP_SUPPORT
+		duk_push_hobject_bidx(ctx, DUK_BIDX_REGEXP_CONSTRUCTOR);
+		duk_dup(ctx, 0);
+		duk_new(ctx, 1);  /* [ ... RegExp val ] -> [ ... res ] */
+		duk_replace(ctx, 0);
+		/* lastIndex is initialized to zero by new RegExp() */
+		is_regexp = 1;
+#else
+		return DUK_RET_UNSUPPORTED_ERROR;
+#endif
+	} else {
+		duk_to_string(ctx, 0);
+#ifdef DUK_USE_REGEXP_SUPPORT
+		is_regexp = 0;
+#endif
+	}
+
+	/* stack[0] = separator (string or regexp)
+	 * stack[1] = limit
+	 * stack[2] = input string
+	 * stack[3] = result array
+	 */
+
+	prev_match_end_boff = 0;
+	prev_match_end_coff = 0;
+	arr_idx = 0;
+	matched = 0;
+
+	for (;;) {
+		/*
+		 *  The specification uses RegExp [[Match]] to attempt match at specific
+		 *  offsets.  We don't have such a primitive, so we use an actual RegExp
+		 *  and tweak lastIndex.  Since the RegExp may be non-global, we use a
+		 *  special variant which forces global-like behavior for matching.
+		 */
+
+		DUK_ASSERT_TOP(ctx, 4);
+
+#ifdef DUK_USE_REGEXP_SUPPORT
+		if (is_regexp) {
+			duk_dup(ctx, 0);
+			duk_dup(ctx, 2);
+			duk_regexp_match_force_global(thr);  /* [ ... regexp input ] -> [ res_obj ] */
+			if (!duk_is_object(ctx, -1)) {
+				duk_pop(ctx);
+				break;
+			}
+			matched = 1;
+
+			duk_get_prop_stridx(ctx, -1, DUK_STRIDX_INDEX);
+			DUK_ASSERT(duk_is_number(ctx, -1));
+			match_start_coff = duk_get_int(ctx, -1);
+			match_start_boff = duk_heap_strcache_offset_char2byte(thr, h_input, match_start_coff);
+			duk_pop(ctx);
+
+			if (match_start_coff == DUK_HSTRING_GET_CHARLEN(h_input)) {
+				/* don't allow an empty match at the end of the string */
+				duk_pop(ctx);
+				break;
+			}
+
+			duk_get_prop_stridx(ctx, 0, DUK_STRIDX_LAST_INDEX);
+			DUK_ASSERT(duk_is_number(ctx, -1));
+			match_end_coff = duk_get_int(ctx, -1);
+			match_end_boff = duk_heap_strcache_offset_char2byte(thr, h_input, match_end_coff);
+			duk_pop(ctx);
+
+			/* empty match -> bump and continue */
+			if (prev_match_end_boff == match_end_boff) {
+				duk_push_int(ctx, match_end_coff + 1);
+				duk_put_prop_stridx(ctx, 0, DUK_STRIDX_LAST_INDEX);
+				duk_pop(ctx);
+				continue;
+			}
+		} else {
+#else  /* DUK_USE_REGEXP_SUPPORT */
+		{  /* unconditionally */
+#endif  /* DUK_USE_REGEXP_SUPPORT */
+			const duk_uint8_t *p_start, *p_end, *p;   /* input string scan */
+			const duk_uint8_t *q_start;               /* match string */
+			duk_size_t q_blen, q_clen;
+
+			p_start = DUK_HSTRING_GET_DATA(h_input);
+			p_end = p_start + DUK_HSTRING_GET_BYTELEN(h_input);
+			p = p_start + prev_match_end_boff;
+
+			h_sep = duk_get_hstring(ctx, 0);
+			DUK_ASSERT(h_sep != NULL);
+			q_start = DUK_HSTRING_GET_DATA(h_sep);
+			q_blen = (duk_size_t) DUK_HSTRING_GET_BYTELEN(h_sep);
+			q_clen = (duk_size_t) DUK_HSTRING_GET_CHARLEN(h_sep);
+
+			p_end -= q_blen;  /* ensure full memcmp() fits in while */
+
+			match_start_coff = prev_match_end_coff;
+
+			if (q_blen == 0) {
+				/* Handle empty separator case: it will always match, and always
+				 * triggers the check in step 13.c.iii initially.  Note that we
+				 * must skip to either end of string or start of first codepoint,
+				 * skipping over any continuation bytes!
+				 *
+				 * Don't allow an empty string to match at the end of the input.
+				 */
+
+				matched = 1;  /* empty separator can always match */
+
+				match_start_coff++;
+				p++;
+				while (p < p_end) {
+					if ((p[0] & 0xc0) != 0x80) {
+						goto found;
+					}
+					p++;
+				}
+				goto not_found;
+			}
+
+			DUK_ASSERT(q_blen > 0 && q_clen > 0);
+			while (p <= p_end) {
+				DUK_ASSERT(p + q_blen <= DUK_HSTRING_GET_DATA(h_input) + DUK_HSTRING_GET_BYTELEN(h_input));
+				DUK_ASSERT(q_blen > 0);  /* no issues with empty memcmp() */
+				if (DUK_MEMCMP((const void *) p, (const void *) q_start, (size_t) q_blen) == 0) {
+					/* never an empty match, so step 13.c.iii can't be triggered */
+					goto found;
+				}
+
+				/* track utf-8 non-continuation bytes */
+				if ((p[0] & 0xc0) != 0x80) {
+					match_start_coff++;
+				}
+				p++;
+			}
+
+		 not_found:
+			/* not found */
+			break;
+
+		 found:
+			matched = 1;
+			match_start_boff = (duk_uint32_t) (p - p_start);
+			match_end_coff = (duk_uint32_t) (match_start_coff + q_clen);  /* constrained by string length */
+			match_end_boff = (duk_uint32_t) (match_start_boff + q_blen);  /* ditto */
+
+			/* empty match (may happen with empty separator) -> bump and continue */
+			if (prev_match_end_boff == match_end_boff) {
+				prev_match_end_boff++;
+				prev_match_end_coff++;
+				continue;
+			}
+		}  /* if (is_regexp) */
+
+		/* stack[0] = separator (string or regexp)
+		 * stack[1] = limit
+		 * stack[2] = input string
+		 * stack[3] = result array
+		 * stack[4] = regexp res_obj (if is_regexp)
+		 */
+
+		DUK_DDD(DUK_DDDPRINT("split; match_start b=%ld,c=%ld, match_end b=%ld,c=%ld, prev_end b=%ld,c=%ld",
+		                     (long) match_start_boff, (long) match_start_coff,
+		                     (long) match_end_boff, (long) match_end_coff,
+		                     (long) prev_match_end_boff, (long) prev_match_end_coff));
+
+		duk_push_lstring(ctx,
+		                 (const char *) (DUK_HSTRING_GET_DATA(h_input) + prev_match_end_boff),
+		                 (duk_size_t) (match_start_boff - prev_match_end_boff));
+		duk_put_prop_index(ctx, 3, arr_idx);
+		arr_idx++;
+		if (arr_idx >= limit) {
+			goto hit_limit;
+		}
+
+#ifdef DUK_USE_REGEXP_SUPPORT
+		if (is_regexp) {
+			duk_size_t i, len;
+
+			len = duk_get_length(ctx, 4);
+			for (i = 1; i < len; i++) {
+				DUK_ASSERT(i <= DUK_UARRIDX_MAX);  /* cannot have >4G captures */
+				duk_get_prop_index(ctx, 4, (duk_uarridx_t) i);
+				duk_put_prop_index(ctx, 3, arr_idx);
+				arr_idx++;
+				if (arr_idx >= limit) {
+					goto hit_limit;
+				}
+			}
+
+			duk_pop(ctx);
+			/* lastIndex already set up for next match */
+		} else {
+#else  /* DUK_USE_REGEXP_SUPPORT */
+		{  /* unconditionally */
+#endif  /* DUK_USE_REGEXP_SUPPORT */
+			/* no action */
+		}
+
+		prev_match_end_boff = match_end_boff;
+		prev_match_end_coff = match_end_coff;
+		continue;
+	}  /* for */
+
+	/* Combined step 11 (empty string special case) and 14-15. */
+
+	DUK_DDD(DUK_DDDPRINT("split trailer; prev_end b=%ld,c=%ld",
+	                     (long) prev_match_end_boff, (long) prev_match_end_coff));
+
+	if (DUK_HSTRING_GET_CHARLEN(h_input) > 0 || !matched) {
+		/* Add trailer if:
+		 *   a) non-empty input
+		 *   b) empty input and no (zero size) match found (step 11)
+		 */
+
+		duk_push_lstring(ctx,
+		                 (const char *) DUK_HSTRING_GET_DATA(h_input) + prev_match_end_boff,
+		                 (duk_size_t) (DUK_HSTRING_GET_BYTELEN(h_input) - prev_match_end_boff));
+		duk_put_prop_index(ctx, 3, arr_idx);
+		/* No arr_idx update or limit check */
+	}
+
+	return 1;
+
+ hit_limit:
+#ifdef DUK_USE_REGEXP_SUPPORT
+	if (is_regexp) {
+		duk_pop(ctx);
+	}
+#endif
+
+	return 1;
+}
+
+/*
+ *  Various
+ */
+
+#ifdef DUK_USE_REGEXP_SUPPORT
+DUK_LOCAL void duk__to_regexp_helper(duk_context *ctx, duk_idx_t index, duk_bool_t force_new) {
+	duk_hobject *h;
+
+	/* Shared helper for match() steps 3-4, search() steps 3-4. */
+
+	DUK_ASSERT(index >= 0);
+
+	if (force_new) {
+		goto do_new;
+	}
+
+	h = duk_get_hobject_with_class(ctx, index, DUK_HOBJECT_CLASS_REGEXP);
+	if (!h) {
+		goto do_new;
+	}
+	return;
+
+ do_new:
+	duk_push_hobject_bidx(ctx, DUK_BIDX_REGEXP_CONSTRUCTOR);
+	duk_dup(ctx, index);
+	duk_new(ctx, 1);  /* [ ... RegExp val ] -> [ ... res ] */
+	duk_replace(ctx, index);
+}
+#endif  /* DUK_USE_REGEXP_SUPPORT */
+
+#ifdef DUK_USE_REGEXP_SUPPORT
+DUK_INTERNAL duk_ret_t duk_bi_string_prototype_search(duk_context *ctx) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+
+	/* Easiest way to implement the search required by the specification
+	 * is to do a RegExp test() with lastIndex forced to zero.  To avoid
+	 * side effects on the argument, "clone" the RegExp if a RegExp was
+	 * given as input.
+	 *
+	 * The global flag of the RegExp should be ignored; setting lastIndex
+	 * to zero (which happens when "cloning" the RegExp) should have an
+	 * equivalent effect.
+	 */
+
+	DUK_ASSERT_TOP(ctx, 1);
+	(void) duk_push_this_coercible_to_string(ctx);  /* at index 1 */
+	duk__to_regexp_helper(ctx, 0 /*index*/, 1 /*force_new*/);
+
+	/* stack[0] = regexp
+	 * stack[1] = string
+	 */
+
+	/* Avoid using RegExp.prototype methods, as they're writable and
+	 * configurable and may have been changed.
+	 */
+
+	duk_dup(ctx, 0);
+	duk_dup(ctx, 1);  /* [ ... re_obj input ] */
+	duk_regexp_match(thr);  /* -> [ ... res_obj ] */
+
+	if (!duk_is_object(ctx, -1)) {
+		duk_push_int(ctx, -1);
+		return 1;
+	}
+
+	duk_get_prop_stridx(ctx, -1, DUK_STRIDX_INDEX);
+	DUK_ASSERT(duk_is_number(ctx, -1));
+	return 1;
+}
+#else  /* DUK_USE_REGEXP_SUPPORT */
+DUK_INTERNAL duk_ret_t duk_bi_string_prototype_search(duk_context *ctx) {
+	DUK_UNREF(ctx);
+	return DUK_RET_UNSUPPORTED_ERROR;
+}
+#endif  /* DUK_USE_REGEXP_SUPPORT */
+
+#ifdef DUK_USE_REGEXP_SUPPORT
+DUK_INTERNAL duk_ret_t duk_bi_string_prototype_match(duk_context *ctx) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_bool_t global;
+	duk_int_t prev_last_index;
+	duk_int_t this_index;
+	duk_int_t arr_idx;
+
+	DUK_ASSERT_TOP(ctx, 1);
+	(void) duk_push_this_coercible_to_string(ctx);
+	duk__to_regexp_helper(ctx, 0 /*index*/, 0 /*force_new*/);
+	global = duk_get_prop_stridx_boolean(ctx, 0, DUK_STRIDX_GLOBAL, NULL);
+	DUK_ASSERT_TOP(ctx, 2);
+
+	/* stack[0] = regexp
+	 * stack[1] = string
+	 */
+
+	if (!global) {
+		duk_regexp_match(thr);  /* -> [ res_obj ] */
+		return 1;  /* return 'res_obj' */
+	}
+
+	/* Global case is more complex. */
+
+	/* [ regexp string ] */
+
+	duk_push_int(ctx, 0);
+	duk_put_prop_stridx(ctx, 0, DUK_STRIDX_LAST_INDEX);
+	duk_push_array(ctx);
+
+	/* [ regexp string res_arr ] */
+
+	prev_last_index = 0;
+	arr_idx = 0;
+
+	for (;;) {
+		DUK_ASSERT_TOP(ctx, 3);
+
+		duk_dup(ctx, 0);
+		duk_dup(ctx, 1);
+		duk_regexp_match(thr);  /* -> [ ... regexp string ] -> [ ... res_obj ] */
+
+		if (!duk_is_object(ctx, -1)) {
+			duk_pop(ctx);
+			break;
+		}
+
+		duk_get_prop_stridx(ctx, 0, DUK_STRIDX_LAST_INDEX);
+		DUK_ASSERT(duk_is_number(ctx, -1));
+		this_index = duk_get_int(ctx, -1);
+		duk_pop(ctx);
+
+		if (this_index == prev_last_index) {
+			this_index++;
+			duk_push_int(ctx, this_index);
+			duk_put_prop_stridx(ctx, 0, DUK_STRIDX_LAST_INDEX);
+		}
+		prev_last_index = this_index;
+
+		duk_get_prop_index(ctx, -1, 0);  /* match string */
+		duk_put_prop_index(ctx, 2, arr_idx);
+		arr_idx++;
+		duk_pop(ctx);  /* res_obj */
+	}
+
+	if (arr_idx == 0) {
+		duk_push_null(ctx);
+	}
+
+	return 1;  /* return 'res_arr' or 'null' */
+}
+#else  /* DUK_USE_REGEXP_SUPPORT */
+DUK_INTERNAL duk_ret_t duk_bi_string_prototype_match(duk_context *ctx) {
+	DUK_UNREF(ctx);
+	return DUK_RET_UNSUPPORTED_ERROR;
+}
+#endif  /* DUK_USE_REGEXP_SUPPORT */
+
+DUK_INTERNAL duk_ret_t duk_bi_string_prototype_concat(duk_context *ctx) {
+	/* duk_concat() coerces arguments with ToString() in correct order */
+	(void) duk_push_this_coercible_to_string(ctx);
+	duk_insert(ctx, 0);  /* this is relatively expensive */
+	duk_concat(ctx, duk_get_top(ctx));
+	return 1;
+}
+
+DUK_INTERNAL duk_ret_t duk_bi_string_prototype_trim(duk_context *ctx) {
+	DUK_ASSERT_TOP(ctx, 0);
+	(void) duk_push_this_coercible_to_string(ctx);
+	duk_trim(ctx, 0);
+	DUK_ASSERT_TOP(ctx, 1);
+	return 1;
+}
+
+DUK_INTERNAL duk_ret_t duk_bi_string_prototype_locale_compare(duk_context *ctx) {
+	duk_hstring *h1;
+	duk_hstring *h2;
+	duk_size_t h1_len, h2_len, prefix_len;
+	duk_small_int_t ret = 0;
+	duk_small_int_t rc;
+
+	/* The current implementation of localeCompare() is simply a codepoint
+	 * by codepoint comparison, implemented with a simple string compare
+	 * because UTF-8 should preserve codepoint ordering (assuming valid
+	 * shortest UTF-8 encoding).
+	 *
+	 * The specification requires that the return value must be related
+	 * to the sort order: e.g. negative means that 'this' comes before
+	 * 'that' in sort order.  We assume an ascending sort order.
+	 */
+
+	/* XXX: could share code with duk_js_ops.c, duk_js_compare_helper */
+
+	h1 = duk_push_this_coercible_to_string(ctx);
+	DUK_ASSERT(h1 != NULL);
+
+	h2 = duk_to_hstring(ctx, 0);
+	DUK_ASSERT(h2 != NULL);
+
+	h1_len = (duk_size_t) DUK_HSTRING_GET_BYTELEN(h1);
+	h2_len = (duk_size_t) DUK_HSTRING_GET_BYTELEN(h2);
+	prefix_len = (h1_len <= h2_len ? h1_len : h2_len);
+
+	/* Zero size compare not an issue with DUK_MEMCMP. */
+	rc = (duk_small_int_t) DUK_MEMCMP((const void *) DUK_HSTRING_GET_DATA(h1),
+	                                  (const void *) DUK_HSTRING_GET_DATA(h2),
+	                                  (size_t) prefix_len);
+
+	if (rc < 0) {
+		ret = -1;
+		goto done;
+	} else if (rc > 0) {
+		ret = 1;
+		goto done;
+	}
+
+	/* prefix matches, lengths matter now */
+	if (h1_len > h2_len) {
+		ret = 1;
+		goto done;
+	} else if (h1_len == h2_len) {
+		DUK_ASSERT(ret == 0);
+		goto done;
+	}
+	ret = -1;
+	goto done;
+
+ done:
+	duk_push_int(ctx, (duk_int_t) ret);
+	return 1;
+}

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_bi_thread.c
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_bi_thread.c b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_bi_thread.c
new file mode 100644
index 0000000..813c8a1
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_bi_thread.c
@@ -0,0 +1,305 @@
+/*
+ *  Thread builtins
+ */
+
+#include "duk_internal.h"
+
+/*
+ *  Constructor
+ */
+
+DUK_INTERNAL duk_ret_t duk_bi_thread_constructor(duk_context *ctx) {
+	duk_hthread *new_thr;
+	duk_hobject *func;
+
+	/* XXX: need a duk_require_func_or_lfunc_coerce() */
+	if (!duk_is_callable(ctx, 0)) {
+		return DUK_RET_TYPE_ERROR;
+	}
+	func = duk_require_hobject_or_lfunc_coerce(ctx, 0);
+	DUK_ASSERT(func != NULL);
+
+	duk_push_thread(ctx);
+	new_thr = (duk_hthread *) duk_get_hobject(ctx, -1);
+	DUK_ASSERT(new_thr != NULL);
+	new_thr->state = DUK_HTHREAD_STATE_INACTIVE;
+
+	/* push initial function call to new thread stack; this is
+	 * picked up by resume().
+	 */
+	duk_push_hobject((duk_context *) new_thr, func);
+
+	return 1;  /* return thread */
+}
+
+/*
+ *  Resume a thread.
+ *
+ *  The thread must be in resumable state, either (a) new thread which hasn't
+ *  yet started, or (b) a thread which has previously yielded.  This method
+ *  must be called from an Ecmascript function.
+ *
+ *  Args:
+ *    - thread
+ *    - value
+ *    - isError (defaults to false)
+ *
+ *  Note: yield and resume handling is currently asymmetric.
+ */
+
+DUK_INTERNAL duk_ret_t duk_bi_thread_resume(duk_context *ctx) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_hthread *thr_resume;
+	duk_tval *tv;
+	duk_hobject *func;
+	duk_hobject *caller_func;
+	duk_small_int_t is_error;
+
+	DUK_DDD(DUK_DDDPRINT("Duktape.Thread.resume(): thread=%!T, value=%!T, is_error=%!T",
+	                     (duk_tval *) duk_get_tval(ctx, 0),
+	                     (duk_tval *) duk_get_tval(ctx, 1),
+	                     (duk_tval *) duk_get_tval(ctx, 2)));
+
+	DUK_ASSERT(thr->state == DUK_HTHREAD_STATE_RUNNING);
+	DUK_ASSERT(thr->heap->curr_thread == thr);
+
+	thr_resume = duk_require_hthread(ctx, 0);
+	is_error = (duk_small_int_t) duk_to_boolean(ctx, 2);
+	duk_set_top(ctx, 2);
+
+	/* [ thread value ] */
+
+	/*
+	 *  Thread state and calling context checks
+	 */
+
+	if (thr->callstack_top < 2) {
+		DUK_DD(DUK_DDPRINT("resume state invalid: callstack should contain at least 2 entries (caller and Duktape.Thread.resume)"));
+		goto state_error;
+	}
+	DUK_ASSERT(DUK_ACT_GET_FUNC(thr->callstack + thr->callstack_top - 1) != NULL);  /* us */
+	DUK_ASSERT(DUK_HOBJECT_IS_NATIVEFUNCTION(DUK_ACT_GET_FUNC(thr->callstack + thr->callstack_top - 1)));
+	DUK_ASSERT(DUK_ACT_GET_FUNC(thr->callstack + thr->callstack_top - 2) != NULL);  /* caller */
+
+	caller_func = DUK_ACT_GET_FUNC(thr->callstack + thr->callstack_top - 2);
+	if (!DUK_HOBJECT_IS_COMPILEDFUNCTION(caller_func)) {
+		DUK_DD(DUK_DDPRINT("resume state invalid: caller must be Ecmascript code"));
+		goto state_error;
+	}
+
+	/* Note: there is no requirement that: 'thr->callstack_preventcount == 1'
+	 * like for yield.
+	 */
+
+	if (thr_resume->state != DUK_HTHREAD_STATE_INACTIVE &&
+	    thr_resume->state != DUK_HTHREAD_STATE_YIELDED) {
+		DUK_DD(DUK_DDPRINT("resume state invalid: target thread must be INACTIVE or YIELDED"));
+		goto state_error;
+	}
+
+	DUK_ASSERT(thr_resume->state == DUK_HTHREAD_STATE_INACTIVE ||
+	           thr_resume->state == DUK_HTHREAD_STATE_YIELDED);
+
+	/* Further state-dependent pre-checks */
+
+	if (thr_resume->state == DUK_HTHREAD_STATE_YIELDED) {
+		/* no pre-checks now, assume a previous yield() has left things in
+		 * tip-top shape (longjmp handler will assert for these).
+		 */
+	} else {
+		DUK_ASSERT(thr_resume->state == DUK_HTHREAD_STATE_INACTIVE);
+
+		if ((thr_resume->callstack_top != 0) ||
+		    (thr_resume->valstack_top - thr_resume->valstack != 1)) {
+			goto state_invalid_initial;
+		}
+		tv = &thr_resume->valstack_top[-1];
+		DUK_ASSERT(tv >= thr_resume->valstack && tv < thr_resume->valstack_top);
+		if (!DUK_TVAL_IS_OBJECT(tv)) {
+			goto state_invalid_initial;
+		}
+		func = DUK_TVAL_GET_OBJECT(tv);
+		DUK_ASSERT(func != NULL);
+		if (!DUK_HOBJECT_IS_COMPILEDFUNCTION(func)) {
+			/* Note: cannot be a bound function either right now,
+			 * this would be easy to relax though.
+			 */
+			goto state_invalid_initial;
+		}
+
+	}
+
+	/*
+	 *  The error object has been augmented with a traceback and other
+	 *  info from its creation point -- usually another thread.  The
+	 *  error handler is called here right before throwing, but it also
+	 *  runs in the resumer's thread.  It might be nice to get a traceback
+	 *  from the resumee but this is not the case now.
+	 */
+
+#if defined(DUK_USE_AUGMENT_ERROR_THROW)
+	if (is_error) {
+		DUK_ASSERT_TOP(ctx, 2);  /* value (error) is at stack top */
+		duk_err_augment_error_throw(thr);  /* in resumer's context */
+	}
+#endif
+
+#ifdef DUK_USE_DEBUG
+	if (is_error) {
+		DUK_DDD(DUK_DDDPRINT("RESUME ERROR: thread=%!T, value=%!T",
+		                     (duk_tval *) duk_get_tval(ctx, 0),
+		                     (duk_tval *) duk_get_tval(ctx, 1)));
+	} else if (thr_resume->state == DUK_HTHREAD_STATE_YIELDED) {
+		DUK_DDD(DUK_DDDPRINT("RESUME NORMAL: thread=%!T, value=%!T",
+		                     (duk_tval *) duk_get_tval(ctx, 0),
+		                     (duk_tval *) duk_get_tval(ctx, 1)));
+	} else {
+		DUK_DDD(DUK_DDDPRINT("RESUME INITIAL: thread=%!T, value=%!T",
+		                     (duk_tval *) duk_get_tval(ctx, 0),
+		                     (duk_tval *) duk_get_tval(ctx, 1)));
+	}
+#endif
+
+	thr->heap->lj.type = DUK_LJ_TYPE_RESUME;
+
+	/* lj value2: thread */
+	DUK_ASSERT(thr->valstack_bottom < thr->valstack_top);
+	DUK_TVAL_SET_TVAL_UPDREF(thr, &thr->heap->lj.value2, &thr->valstack_bottom[0]);  /* side effects */
+
+	/* lj value1: value */
+	DUK_ASSERT(thr->valstack_bottom + 1 < thr->valstack_top);
+	DUK_TVAL_SET_TVAL_UPDREF(thr, &thr->heap->lj.value1, &thr->valstack_bottom[1]);  /* side effects */
+	DUK_TVAL_CHKFAST_INPLACE(&thr->heap->lj.value1);
+
+	thr->heap->lj.iserror = is_error;
+
+	DUK_ASSERT(thr->heap->lj.jmpbuf_ptr != NULL);  /* call is from executor, so we know we have a jmpbuf */
+	duk_err_longjmp(thr);  /* execution resumes in bytecode executor */
+	return 0;  /* never here */
+
+ state_invalid_initial:
+	DUK_ERROR_TYPE(thr, "invalid initial thread state/stack");
+	return 0;  /* never here */
+
+ state_error:
+	DUK_ERROR_TYPE(thr, "invalid state");
+	return 0;  /* never here */
+}
+
+/*
+ *  Yield the current thread.
+ *
+ *  The thread must be in yieldable state: it must have a resumer, and there
+ *  must not be any yield-preventing calls (native calls and constructor calls,
+ *  currently) in the thread's call stack (otherwise a resume would not be
+ *  possible later).  This method must be called from an Ecmascript function.
+ *
+ *  Args:
+ *    - value
+ *    - isError (defaults to false)
+ *
+ *  Note: yield and resume handling is currently asymmetric.
+ */
+
+DUK_INTERNAL duk_ret_t duk_bi_thread_yield(duk_context *ctx) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_hobject *caller_func;
+	duk_small_int_t is_error;
+
+	DUK_DDD(DUK_DDDPRINT("Duktape.Thread.yield(): value=%!T, is_error=%!T",
+	                     (duk_tval *) duk_get_tval(ctx, 0),
+	                     (duk_tval *) duk_get_tval(ctx, 1)));
+
+	DUK_ASSERT(thr->state == DUK_HTHREAD_STATE_RUNNING);
+	DUK_ASSERT(thr->heap->curr_thread == thr);
+
+	is_error = (duk_small_int_t) duk_to_boolean(ctx, 1);
+	duk_set_top(ctx, 1);
+
+	/* [ value ] */
+
+	/*
+	 *  Thread state and calling context checks
+	 */
+
+	if (!thr->resumer) {
+		DUK_DD(DUK_DDPRINT("yield state invalid: current thread must have a resumer"));
+		goto state_error;
+	}
+	DUK_ASSERT(thr->resumer->state == DUK_HTHREAD_STATE_RESUMED);
+
+	if (thr->callstack_top < 2) {
+		DUK_DD(DUK_DDPRINT("yield state invalid: callstack should contain at least 2 entries (caller and Duktape.Thread.yield)"));
+		goto state_error;
+	}
+	DUK_ASSERT(DUK_ACT_GET_FUNC(thr->callstack + thr->callstack_top - 1) != NULL);  /* us */
+	DUK_ASSERT(DUK_HOBJECT_IS_NATIVEFUNCTION(DUK_ACT_GET_FUNC(thr->callstack + thr->callstack_top - 1)));
+	DUK_ASSERT(DUK_ACT_GET_FUNC(thr->callstack + thr->callstack_top - 2) != NULL);  /* caller */
+
+	caller_func = DUK_ACT_GET_FUNC(thr->callstack + thr->callstack_top - 2);
+	if (!DUK_HOBJECT_IS_COMPILEDFUNCTION(caller_func)) {
+		DUK_DD(DUK_DDPRINT("yield state invalid: caller must be Ecmascript code"));
+		goto state_error;
+	}
+
+	DUK_ASSERT(thr->callstack_preventcount >= 1);  /* should never be zero, because we (Duktape.Thread.yield) are on the stack */
+	if (thr->callstack_preventcount != 1) {
+		/* Note: the only yield-preventing call is Duktape.Thread.yield(), hence check for 1, not 0 */
+		DUK_DD(DUK_DDPRINT("yield state invalid: there must be no yield-preventing calls in current thread callstack (preventcount is %ld)",
+		                   (long) thr->callstack_preventcount));
+		goto state_error;
+	}
+
+	/*
+	 *  The error object has been augmented with a traceback and other
+	 *  info from its creation point -- usually the current thread.
+	 *  The error handler, however, is called right before throwing
+	 *  and runs in the yielder's thread.
+	 */
+
+#if defined(DUK_USE_AUGMENT_ERROR_THROW)
+	if (is_error) {
+		DUK_ASSERT_TOP(ctx, 1);  /* value (error) is at stack top */
+		duk_err_augment_error_throw(thr);  /* in yielder's context */
+	}
+#endif
+
+#ifdef DUK_USE_DEBUG
+	if (is_error) {
+		DUK_DDD(DUK_DDDPRINT("YIELD ERROR: value=%!T",
+		                     (duk_tval *) duk_get_tval(ctx, 0)));
+	} else {
+		DUK_DDD(DUK_DDDPRINT("YIELD NORMAL: value=%!T",
+		                     (duk_tval *) duk_get_tval(ctx, 0)));
+	}
+#endif
+
+	/*
+	 *  Process yield
+	 *
+	 *  After longjmp(), processing continues in bytecode executor longjmp
+	 *  handler, which will e.g. update thr->resumer to NULL.
+	 */
+
+	thr->heap->lj.type = DUK_LJ_TYPE_YIELD;
+
+	/* lj value1: value */
+	DUK_ASSERT(thr->valstack_bottom < thr->valstack_top);
+	DUK_TVAL_SET_TVAL_UPDREF(thr, &thr->heap->lj.value1, &thr->valstack_bottom[0]);  /* side effects */
+	DUK_TVAL_CHKFAST_INPLACE(&thr->heap->lj.value1);
+
+	thr->heap->lj.iserror = is_error;
+
+	DUK_ASSERT(thr->heap->lj.jmpbuf_ptr != NULL);  /* call is from executor, so we know we have a jmpbuf */
+	duk_err_longjmp(thr);  /* execution resumes in bytecode executor */
+	return 0;  /* never here */
+
+ state_error:
+	DUK_ERROR_TYPE(thr, "invalid state");
+	return 0;  /* never here */
+}
+
+DUK_INTERNAL duk_ret_t duk_bi_thread_current(duk_context *ctx) {
+	duk_push_current_thread(ctx);
+	return 1;
+}

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_bi_thrower.c
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_bi_thrower.c b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_bi_thrower.c
new file mode 100644
index 0000000..a71512a
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_bi_thrower.c
@@ -0,0 +1,10 @@
+/*
+ *  Type error thrower, E5 Section 13.2.3.
+ */
+
+#include "duk_internal.h"
+
+DUK_INTERNAL duk_ret_t duk_bi_type_error_thrower(duk_context *ctx) {
+	DUK_UNREF(ctx);
+	return DUK_RET_TYPE_ERROR;
+}


[08/51] [partial] nifi-minifi-cpp git commit: MINIFI-183 Added civet 1.9.1 sources Added onScheduled hook Added initial two-way TLS-enabled ListenHTTP implementation

Posted by al...@apache.org.
http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_builtins.c
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_builtins.c b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_builtins.c
new file mode 100644
index 0000000..5003e8b
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_builtins.c
@@ -0,0 +1,776 @@
+/*
+ *  Automatically generated by genbuiltins.py, do not edit!
+ */
+
+#include "duk_internal.h"
+
+#if defined(DUK_USE_ROM_STRINGS)
+#error ROM support not enabled, rerun make_dist.py with --rom-support
+#else  /* DUK_USE_ROM_STRINGS */
+DUK_INTERNAL const duk_uint8_t duk_strings_data[1049] = {
+79,104,209,144,168,105,6,78,182,139,90,122,8,154,140,35,103,35,117,193,73,
+5,52,116,180,104,166,135,52,189,4,98,12,27,178,156,80,211,31,161,115,150,
+64,52,221,109,24,18,68,157,24,38,67,118,36,55,73,119,151,164,140,93,18,117,
+128,153,201,228,201,205,2,250,8,196,24,232,104,82,146,40,232,193,48,118,
+168,37,147,212,54,127,113,208,70,32,194,187,68,54,127,113,208,70,32,196,
+123,68,54,127,113,209,44,12,121,7,208,70,32,194,186,134,207,236,126,219,
+160,140,65,133,246,136,108,254,199,237,186,8,196,24,87,80,217,253,159,217,
+116,17,136,48,190,209,13,159,217,253,151,65,24,131,12,233,86,224,79,236,
+254,203,160,140,65,134,116,171,112,39,246,223,105,208,70,32,193,140,183,4,
+11,55,92,20,244,141,169,186,50,11,164,109,77,208,208,165,36,79,215,185,13,
+153,34,110,204,241,32,6,66,84,11,112,200,84,52,157,124,92,242,70,120,45,64,
+186,17,22,138,38,0,172,140,19,154,84,26,145,0,86,69,17,180,97,34,0,172,132,
+75,144,215,77,221,91,132,5,147,178,156,80,211,30,160,93,9,215,21,115,119,
+169,49,75,211,138,26,101,205,222,68,157,47,78,40,105,151,55,120,204,156,
+189,56,161,166,52,157,72,136,138,65,154,232,147,162,4,136,150,81,115,66,
+208,210,37,96,148,250,134,140,151,39,212,125,255,221,125,73,80,209,146,233,
+124,93,55,79,15,34,196,230,202,113,160,166,232,157,132,148,128,98,28,46,
+114,200,6,153,180,96,73,19,74,113,67,76,103,5,36,20,211,70,140,133,67,72,
+49,245,160,235,81,212,52,168,106,39,132,253,111,80,210,161,168,158,5,245,
+191,96,31,172,15,208,23,226,190,131,232,62,131,232,11,251,127,93,245,223,
+93,251,172,234,27,80,45,3,250,14,140,19,34,65,19,81,132,108,228,97,1,107,
+33,12,32,45,100,136,206,9,12,196,155,134,69,146,100,235,226,231,146,51,194,
+72,218,48,145,4,200,119,89,189,81,49,39,72,147,235,226,233,186,120,121,58,
+226,167,90,124,93,55,107,71,137,33,68,68,130,64,206,75,189,209,156,144,84,
+44,141,3,8,137,187,178,156,80,211,26,110,242,100,230,146,120,121,8,48,76,6,
+89,26,105,157,65,196,201,213,145,166,153,212,28,76,157,113,75,34,78,62,14,
+38,73,105,228,142,136,178,48,141,152,228,73,150,83,0,148,39,137,75,67,73,
+214,209,129,36,85,190,206,32,17,6,9,128,141,3,8,130,161,100,235,64,194,24,
+52,41,73,19,189,200,108,201,19,111,181,2,232,66,239,173,37,230,157,244,56,
+153,4,225,145,27,233,93,22,1,114,62,251,80,69,128,121,247,213,146,228,109,
+79,190,212,17,35,106,125,246,78,164,68,68,111,175,23,217,45,13,33,119,208,
+68,210,38,250,192,61,91,233,80,208,45,25,36,81,190,156,13,26,201,19,239,
+162,2,214,66,31,125,153,226,64,13,27,236,72,96,130,68,62,251,48,68,196,153,
+119,217,157,18,56,156,199,161,100,42,26,250,77,36,140,122,40,144,19,34,9,
+24,246,103,139,172,150,56,125,145,1,17,29,44,112,250,183,0,100,24,200,218,
+140,228,185,130,9,19,237,190,208,73,184,146,35,68,146,163,8,50,178,99,136,
+44,89,196,2,33,70,64,208,196,67,74,226,88,17,105,73,24,186,37,40,38,5,133,
+161,89,4,183,25,115,119,86,227,118,83,138,26,103,255,223,209,106,141,25,11,
+244,95,117,56,208,159,250,223,251,250,45,52,13,250,47,186,156,104,79,253,
+111,253,253,22,144,210,253,23,221,78,52,39,254,187,254,254,139,77,67,75,
+244,95,117,56,208,159,250,239,251,250,45,22,141,23,209,125,212,227,66,127,
+235,63,239,69,163,69,247,83,141,9,255,165,12,72,5,16,64,145,10,32,76,71,64,
+156,217,161,180,34,6,64,208,198,36,78,50,20,20,92,204,50,44,147,32,134,226,
+17,114,33,202,134,129,107,192,202,232,160,180,104,166,135,52,72,40,144,213,
+33,178,152,26,34,56,163,105,44,104,146,116,139,77,43,34,98,57,38,116,72,
+179,60,93,97,206,56,52,240,242,56,163,168,34,81,57,178,153,42,228,12,182,
+58,22,66,89,19,57,68,176,74,68,35,104,195,18,239,116,102,114,94,100,104,
+228,100,49,238,140,203,42,60,145,35,104,181,146,113,161,10,80,46,68,82,24,
+245,145,132,108,228,148,54,100,137,64,34,13,100,153,222,1,40,6,33,223,20,
+84,19,34,95,23,76,130,153,6,103,208,43,64,141,41,130,104,17,112,130,44,96,
+};
+#endif  /* DUK_USE_ROM_STRINGS */
+
+#if defined(DUK_USE_ROM_OBJECTS)
+#error ROM support not enabled, rerun make_dist.py with --rom-support
+#else  /* DUK_USE_ROM_OBJECTS */
+/* native functions: 149 */
+DUK_INTERNAL const duk_c_function duk_bi_native_functions[149] = {
+	duk_bi_array_constructor,
+	duk_bi_array_constructor_is_array,
+	duk_bi_array_prototype_concat,
+	duk_bi_array_prototype_indexof_shared,
+	duk_bi_array_prototype_iter_shared,
+	duk_bi_array_prototype_join_shared,
+	duk_bi_array_prototype_pop,
+	duk_bi_array_prototype_push,
+	duk_bi_array_prototype_reduce_shared,
+	duk_bi_array_prototype_reverse,
+	duk_bi_array_prototype_shift,
+	duk_bi_array_prototype_slice,
+	duk_bi_array_prototype_sort,
+	duk_bi_array_prototype_splice,
+	duk_bi_array_prototype_to_string,
+	duk_bi_array_prototype_unshift,
+	duk_bi_arraybuffer_constructor,
+	duk_bi_arraybuffer_isview,
+	duk_bi_boolean_constructor,
+	duk_bi_boolean_prototype_tostring_shared,
+	duk_bi_buffer_compare_shared,
+	duk_bi_buffer_constructor,
+	duk_bi_buffer_prototype_tostring_shared,
+	duk_bi_buffer_readfield,
+	duk_bi_buffer_slice_shared,
+	duk_bi_buffer_writefield,
+	duk_bi_dataview_constructor,
+	duk_bi_date_constructor,
+	duk_bi_date_constructor_now,
+	duk_bi_date_constructor_parse,
+	duk_bi_date_constructor_utc,
+	duk_bi_date_prototype_get_shared,
+	duk_bi_date_prototype_get_timezone_offset,
+	duk_bi_date_prototype_set_shared,
+	duk_bi_date_prototype_set_time,
+	duk_bi_date_prototype_to_json,
+	duk_bi_date_prototype_tostring_shared,
+	duk_bi_date_prototype_value_of,
+	duk_bi_duktape_object_act,
+	duk_bi_duktape_object_compact,
+	duk_bi_duktape_object_dec,
+	duk_bi_duktape_object_enc,
+	duk_bi_duktape_object_fin,
+	duk_bi_duktape_object_gc,
+	duk_bi_duktape_object_info,
+	duk_bi_error_constructor_shared,
+	duk_bi_error_prototype_filename_getter,
+	duk_bi_error_prototype_filename_setter,
+	duk_bi_error_prototype_linenumber_getter,
+	duk_bi_error_prototype_linenumber_setter,
+	duk_bi_error_prototype_stack_getter,
+	duk_bi_error_prototype_stack_setter,
+	duk_bi_error_prototype_to_string,
+	duk_bi_function_constructor,
+	duk_bi_function_prototype,
+	duk_bi_function_prototype_apply,
+	duk_bi_function_prototype_bind,
+	duk_bi_function_prototype_call,
+	duk_bi_function_prototype_to_string,
+	duk_bi_global_object_decode_uri,
+	duk_bi_global_object_decode_uri_component,
+	duk_bi_global_object_encode_uri,
+	duk_bi_global_object_encode_uri_component,
+	duk_bi_global_object_escape,
+	duk_bi_global_object_eval,
+	duk_bi_global_object_is_finite,
+	duk_bi_global_object_is_nan,
+	duk_bi_global_object_parse_float,
+	duk_bi_global_object_parse_int,
+	duk_bi_global_object_print_helper,
+	duk_bi_global_object_require,
+	duk_bi_global_object_unescape,
+	duk_bi_json_object_parse,
+	duk_bi_json_object_stringify,
+	duk_bi_logger_constructor,
+	duk_bi_logger_prototype_fmt,
+	duk_bi_logger_prototype_log_shared,
+	duk_bi_logger_prototype_raw,
+	duk_bi_math_object_max,
+	duk_bi_math_object_min,
+	duk_bi_math_object_onearg_shared,
+	duk_bi_math_object_random,
+	duk_bi_math_object_twoarg_shared,
+	duk_bi_nodejs_buffer_byte_length,
+	duk_bi_nodejs_buffer_concat,
+	duk_bi_nodejs_buffer_constructor,
+	duk_bi_nodejs_buffer_copy,
+	duk_bi_nodejs_buffer_fill,
+	duk_bi_nodejs_buffer_is_buffer,
+	duk_bi_nodejs_buffer_is_encoding,
+	duk_bi_nodejs_buffer_tojson,
+	duk_bi_nodejs_buffer_tostring,
+	duk_bi_nodejs_buffer_write,
+	duk_bi_number_constructor,
+	duk_bi_number_prototype_to_exponential,
+	duk_bi_number_prototype_to_fixed,
+	duk_bi_number_prototype_to_locale_string,
+	duk_bi_number_prototype_to_precision,
+	duk_bi_number_prototype_to_string,
+	duk_bi_number_prototype_value_of,
+	duk_bi_object_constructor,
+	duk_bi_object_constructor_create,
+	duk_bi_object_constructor_define_properties,
+	duk_bi_object_constructor_define_property,
+	duk_bi_object_constructor_get_own_property_descriptor,
+	duk_bi_object_constructor_is_extensible,
+	duk_bi_object_constructor_is_sealed_frozen_shared,
+	duk_bi_object_constructor_keys_shared,
+	duk_bi_object_constructor_prevent_extensions,
+	duk_bi_object_constructor_seal_freeze_shared,
+	duk_bi_object_getprototype_shared,
+	duk_bi_object_prototype_has_own_property,
+	duk_bi_object_prototype_is_prototype_of,
+	duk_bi_object_prototype_property_is_enumerable,
+	duk_bi_object_prototype_to_locale_string,
+	duk_bi_object_prototype_to_string,
+	duk_bi_object_prototype_value_of,
+	duk_bi_object_setprototype_shared,
+	duk_bi_pointer_constructor,
+	duk_bi_pointer_prototype_tostring_shared,
+	duk_bi_proxy_constructor,
+	duk_bi_regexp_constructor,
+	duk_bi_regexp_prototype_exec,
+	duk_bi_regexp_prototype_test,
+	duk_bi_regexp_prototype_to_string,
+	duk_bi_string_constructor,
+	duk_bi_string_constructor_from_char_code,
+	duk_bi_string_prototype_caseconv_shared,
+	duk_bi_string_prototype_char_at,
+	duk_bi_string_prototype_char_code_at,
+	duk_bi_string_prototype_concat,
+	duk_bi_string_prototype_indexof_shared,
+	duk_bi_string_prototype_locale_compare,
+	duk_bi_string_prototype_match,
+	duk_bi_string_prototype_replace,
+	duk_bi_string_prototype_search,
+	duk_bi_string_prototype_slice,
+	duk_bi_string_prototype_split,
+	duk_bi_string_prototype_substr,
+	duk_bi_string_prototype_substring,
+	duk_bi_string_prototype_to_string,
+	duk_bi_string_prototype_trim,
+	duk_bi_thread_constructor,
+	duk_bi_thread_current,
+	duk_bi_thread_resume,
+	duk_bi_thread_yield,
+	duk_bi_type_error_thrower,
+	duk_bi_typedarray_constructor,
+	duk_bi_typedarray_set,
+};
+#if defined(DUK_USE_BUILTIN_INITJS)
+DUK_INTERNAL const duk_uint8_t duk_initjs_data[204] = {
+40,102,117,110,99,116,105,111,110,40,100,44,97,41,123,102,117,110,99,116,
+105,111,110,32,98,40,97,44,98,44,99,41,123,79,98,106,101,99,116,46,100,101,
+102,105,110,101,80,114,111,112,101,114,116,121,40,97,44,98,44,123,118,97,
+108,117,101,58,99,44,119,114,105,116,97,98,108,101,58,33,48,44,101,110,117,
+109,101,114,97,98,108,101,58,33,49,44,99,111,110,102,105,103,117,114,97,98,
+108,101,58,33,48,125,41,125,98,40,97,46,76,111,103,103,101,114,44,34,99,
+108,111,103,34,44,110,101,119,32,97,46,76,111,103,103,101,114,40,34,67,34,
+41,41,59,98,40,97,44,34,109,111,100,76,111,97,100,101,100,34,44,79,98,106,
+101,99,116,46,99,114,101,97,116,101,40,110,117,108,108,41,41,125,41,40,116,
+104,105,115,44,68,117,107,116,97,112,101,41,59,10,0,
+};
+#endif  /* DUK_USE_BUILTIN_INITJS */
+#if defined(DUK_USE_DOUBLE_LE)
+DUK_INTERNAL const duk_uint8_t duk_builtins_data[3833] = {
+105,195,75,32,3,148,52,154,248,9,26,13,128,112,105,0,240,22,20,26,95,124,6,
+152,52,137,0,120,99,74,239,129,18,70,241,191,2,98,13,79,32,42,88,210,90,2,
+240,1,50,141,37,168,76,94,216,118,69,229,203,127,44,0,84,163,73,106,21,75,
+14,236,249,98,242,229,191,150,0,46,81,164,181,14,165,151,54,94,89,119,99,
+203,23,151,45,252,176,1,146,141,37,168,93,63,59,186,97,241,23,151,45,252,
+176,1,178,141,37,168,77,79,60,50,197,229,203,127,44,0,116,163,73,106,17,86,
+148,152,188,185,111,229,128,15,148,129,198,137,36,58,166,142,91,251,212,
+243,195,44,94,92,183,242,13,79,8,45,14,91,252,121,148,52,199,120,63,72,105,
+21,240,118,128,210,237,224,245,17,165,43,224,211,55,231,207,151,148,161,70,
+145,0,31,40,107,26,2,18,138,26,228,192,142,0,16,161,174,76,9,74,26,228,192,
+158,0,8,161,174,76,10,96,2,42,26,228,192,174,0,26,161,174,76,11,96,3,74,26,
+228,192,190,0,44,161,174,76,12,96,3,202,26,228,192,206,0,70,161,169,84,14,
+202,3,255,254,32,234,0,0,0,0,0,0,7,195,248,119,0,0,0,0,0,0,3,193,252,57,
+136,1,152,32,16,194,0,166,24,6,49,0,57,138,2,12,96,18,99,128,163,32,5,153,
+40,76,94,216,118,69,229,203,127,35,41,10,165,135,118,124,177,121,114,223,
+200,203,67,169,101,205,151,150,93,216,242,197,229,203,127,35,49,11,167,231,
+119,76,62,34,242,229,191,145,154,132,212,243,195,44,94,92,183,242,51,144,
+138,180,164,197,229,203,127,35,60,6,26,0,52,208,193,226,117,215,211,15,12,
+166,146,11,67,150,255,30,77,24,58,113,64,243,92,8,27,0,68,217,130,70,212,
+19,54,224,161,185,5,77,216,44,111,65,115,126,12,28,16,100,225,156,16,32,18,
+17,195,15,46,121,100,238,232,136,136,87,12,60,185,229,141,179,126,30,136,
+100,130,233,231,59,12,228,34,66,52,243,141,167,118,158,153,80,73,9,201,151,
+30,252,153,106,210,146,118,72,150,76,184,247,228,203,86,148,152,123,246,
+240,223,187,46,238,135,132,132,229,221,143,126,76,181,105,73,61,36,75,46,
+236,123,242,101,171,74,76,61,251,120,111,221,151,119,67,226,65,178,243,199,
+135,134,83,242,66,58,238,203,207,30,30,25,81,201,5,225,203,78,238,136,163,
+208,92,59,50,242,232,138,62,0,2,38,163,19,255,255,224,142,80,192,0,20,31,
+240,14,135,103,203,210,135,45,253,55,244,243,195,44,252,205,197,0,1,18,221,
+82,0,3,24,207,151,164,254,251,168,114,223,195,47,46,158,98,101,231,143,150,
+158,29,55,242,104,68,79,62,94,147,251,238,161,203,127,12,188,186,121,157,
+135,110,94,109,100,131,99,229,151,15,76,172,168,8,89,217,16,201,151,54,157,
+217,104,114,223,195,47,46,154,114,243,102,68,19,158,92,59,27,73,6,205,203,
+46,95,89,91,74,0,3,17,225,203,47,108,187,186,69,241,211,46,238,122,119,238,
+230,216,72,70,158,116,242,225,217,151,35,81,33,26,121,198,229,191,214,93,
+205,69,0,1,134,105,231,23,199,76,187,185,233,197,179,43,73,32,154,242,249,
+230,214,80,0,31,255,193,2,38,103,110,117,24,81,115,0,78,228,0,161,208,16,
+237,24,121,207,239,186,135,45,252,50,242,233,229,188,144,221,60,232,114,
+223,211,127,79,60,50,207,204,224,72,167,14,91,248,101,229,211,204,158,113,
+119,117,219,151,150,28,91,50,184,144,40,95,224,0,15,248,64,4,20,78,129,5,
+195,195,134,207,38,232,130,99,195,179,97,201,244,19,22,157,217,14,15,130,
+135,254,0,48,125,60,224,242,229,135,200,9,1,255,12,2,162,136,112,2,112,80,
+128,0,193,177,239,221,143,15,64,35,224,152,20,144,62,27,248,3,2,9,195,175,
+61,0,231,208,126,89,123,101,229,207,40,72,32,188,244,105,205,208,40,16,94,
+123,52,227,202,22,136,39,61,252,186,6,18,13,207,134,205,56,242,134,175,65,
+250,238,231,163,78,110,129,231,208,125,59,178,101,241,63,48,25,248,0,12,47,
+102,30,125,36,238,201,151,196,252,192,103,255,255,240,92,189,178,242,242,8,
+105,4,231,191,110,80,67,80,0,24,62,109,252,162,225,199,160,16,212,0,10,7,
+183,15,0,67,80,0,56,54,109,59,58,101,228,8,106,0,9,6,229,151,39,92,121,66,
+15,192,0,97,124,178,228,235,143,45,45,57,244,116,8,63,255,255,10,39,248,0,
+195,51,114,223,182,30,140,60,161,239,201,149,248,248,31,241,0,140,80,129,
+202,10,49,128,10,35,1,6,199,163,15,40,61,32,9,10,199,163,15,40,123,242,101,
+131,210,4,144,108,123,247,99,195,210,8,250,15,167,118,76,190,39,230,131,52,
+133,236,195,207,164,157,217,50,248,159,154,12,212,0,6,27,179,126,60,59,50,
+195,223,183,134,30,89,97,9,5,219,135,166,61,16,164,131,242,203,195,102,28,
+121,97,145,6,231,151,15,44,122,33,201,5,231,179,78,60,177,8,130,243,225,
+179,79,72,148,66,121,245,197,207,167,45,59,179,197,162,23,211,124,205,253,
+242,242,135,135,158,87,240,68,122,111,153,191,30,29,153,102,111,239,151,
+148,60,60,242,191,130,23,211,125,94,28,50,242,135,135,158,87,240,128,0,196,
+122,111,153,191,30,29,153,106,240,225,151,148,60,60,242,191,132,0,6,9,211,
+150,157,177,160,131,115,235,139,159,78,81,72,10,47,248,0,3,254,40,17,138,
+48,66,136,152,64,0,66,129,48,5,27,252,88,76,216,54,47,214,131,50,172,88,31,
+255,255,255,255,255,253,239,240,153,178,103,95,173,6,101,88,176,0,64,0,0,0,
+0,0,0,3,168,0,0,0,0,0,0,31,15,241,26,19,233,201,169,38,180,91,242,103,70,
+147,58,77,75,48,0,0,0,0,0,0,60,31,226,51,162,199,131,82,77,104,183,228,206,
+141,38,116,154,150,96,0,0,0,0,0,0,120,127,128,15,248,192,70,40,0,0,0,0,0,0,
+0,0,3,10,44,68,9,216,8,20,49,130,15,211,124,109,62,50,228,95,36,55,166,248,
+190,56,111,221,151,119,77,56,118,47,18,23,211,125,14,89,113,233,231,167,
+126,230,18,5,31,252,0,224,188,48,242,231,148,116,144,58,181,33,143,127,64,
+247,111,238,56,0,127,199,2,49,72,0,0,0,0,0,0,248,127,180,81,36,4,51,166,
+248,152,122,101,167,211,150,157,217,201,2,0,3,12,233,190,166,157,185,105,
+244,229,167,118,114,64,128,1,4,228,129,0,3,137,116,223,51,126,60,59,50,196,
+195,211,45,62,156,180,238,206,72,16,0,72,151,77,243,55,227,195,179,45,77,
+59,114,211,233,203,78,236,228,129,0,5,10,73,2,0,12,21,18,4,0,28,82,35,32,
+80,74,8,62,124,189,42,105,219,148,148,16,188,249,122,70,235,179,101,156,
+184,121,15,132,0,34,29,159,47,74,181,33,198,235,179,101,156,184,121,15,132,
+0,38,17,159,47,73,187,247,116,208,62,16,0,168,94,124,189,42,212,135,55,126,
+238,154,7,194,0,23,7,207,151,164,76,61,50,143,132,0,50,21,159,47,74,181,33,
+196,195,211,40,248,64,3,96,217,242,244,137,135,200,248,64,3,161,57,242,244,
+171,82,28,76,62,71,194,0,31,8,207,151,164,141,253,121,115,31,8,0,132,47,62,
+94,149,106,67,145,191,175,46,99,225,0,17,133,103,203,210,110,157,221,122,
+101,230,62,16,1,40,110,124,189,42,212,135,55,78,238,189,50,243,31,8,0,156,
+43,62,94,148,242,227,223,187,39,49,240,128,10,67,115,229,233,86,164,58,121,
+113,239,221,147,152,248,64,5,97,249,242,244,155,167,102,205,60,242,227,223,
+187,39,49,240,128,11,68,179,229,233,86,164,57,186,118,108,211,207,46,61,
+251,178,115,31,8,0,188,71,62,94,149,52,237,203,235,126,236,179,243,102,231,
+151,161,0,32,252,242,244,169,167,110,82,34,67,249,229,233,55,78,205,154,
+121,229,199,191,118,78,100,37,0,24,137,115,203,210,173,72,115,116,236,217,
+167,158,92,123,247,100,230,66,80,1,152,87,60,189,41,229,199,191,118,78,100,
+43,224,3,80,222,121,122,85,169,14,158,92,123,247,100,230,66,190,0,55,10,
+231,151,164,221,59,186,244,203,204,133,252,0,114,27,207,47,74,181,33,205,
+211,187,175,76,188,200,95,192,7,97,28,242,244,145,191,175,46,100,51,224,3,
+208,190,121,122,85,169,14,70,254,188,185,144,207,128,15,193,249,229,233,19,
+15,76,164,37,0,32,133,115,203,210,173,72,113,48,244,202,66,80,2,24,71,60,
+189,38,239,221,211,65,10,248,1,20,47,158,94,149,106,67,155,191,119,77,4,43,
+224,4,112,190,121,122,70,235,179,101,156,184,121,16,191,128,18,67,185,229,
+233,86,164,56,221,118,108,179,151,15,34,23,240,2,88,62,124,189,44,229,195,
+200,124,32,4,208,126,121,122,89,203,135,145,9,64,9,194,145,254,0,0,255,144,
+24,100,130,14,0,16,176,2,192,129,11,33,12,1,168,193,108,96,186,48,95,32,0,
+0,0,0,0,0,0,0,56,38,95,25,113,189,18,9,211,47,62,143,100,20,95,0,20,159,
+240,0,7,252,144,162,241,2,195,66,7,11,89,204,140,197,252,229,197,226,230,
+115,3,16,69,19,64,5,43,252,0,9,255,40,16,188,33,49,123,97,217,23,151,45,
+252,131,66,7,0,20,191,240,0,39,252,176,66,240,133,82,195,187,62,88,188,185,
+111,228,26,16,56,0,166,127,128,1,63,230,2,23,132,58,150,92,217,121,101,221,
+143,44,94,92,183,242,13,8,28,0,83,127,192,0,159,243,65,11,194,23,79,206,
+238,152,124,69,229,203,127,32,208,129,192,5,59,252,0,9,255,56,16,188,33,53,
+60,240,203,23,151,45,252,131,66,7,0,20,255,240,0,39,252,240,66,240,132,85,
+165,38,47,46,91,249,6,132,14,0,31,255,228,64,98,192,105,87,20,139,10,191,5,
+64,130,76,156,197,132,1,101,91,91,187,22,176,36,8,28,201,204,160,119,156,
+253,127,33,23,115,31,193,102,79,142,202,44,15,232,34,182,84,113,95,115,248,
+52,201,241,216,176,139,0,59,148,152,85,239,47,108,254,5,66,76,1,130,212,69,
+79,178,16,148,8,61,58,52,170,49,190,202,6,105,219,251,52,245,7,49,252,22,
+157,26,85,25,64,205,59,127,102,158,160,246,63,74,7,135,23,53,2,65,48,227,
+223,205,64,160,0,48,76,60,244,238,80,40,0,20,19,15,76,59,148,10,0,7,5,195,
+211,14,230,74,72,130,99,203,167,98,129,64,1,32,120,247,243,80,40,0,44,15,
+47,142,10,5,0,6,130,230,217,191,127,37,2,128,3,192,246,111,206,160,80,0,
+136,30,220,62,19,151,160,123,116,238,79,94,129,240,223,221,73,32,0,48,110,
+88,119,100,223,181,68,16,94,91,250,238,200,160,80,0,152,31,61,59,148,10,0,
+21,4,231,199,151,69,2,128,5,192,250,97,220,160,80,0,192,127,255,128,20,23,
+134,30,92,242,164,34,19,207,167,45,59,179,233,205,229,37,129,127,255,0,0,
+191,255,128,0,63,255,197,131,246,203,203,158,157,251,160,0,0,0,0,0,65,226,
+32,3,166,156,30,53,32,249,165,131,76,223,159,62,94,70,172,114,16,176,144,
+60,56,250,19,18,5,159,25,89,32,121,180,238,42,30,129,229,221,140,164,122,7,
+147,46,50,129,232,62,61,251,120,97,199,208,156,129,83,127,0,50,250,69,3,
+252,131,32,248,250,242,229,151,119,72,240,3,254,148,0,2,168,254,0,0,255,
+167,0,33,68,88,32,0,33,64,176,2,170,254,0,0,255,169,0,33,69,220,32,0,33,67,
+184,2,172,254,0,0,255,171,8,137,144,0,0,0,0,0,0,0,128,68,73,4,195,187,126,
+226,8,4,178,16,41,164,32,147,7,136,52,193,240,0,18,17,48,124,0,8,133,76,31,
+0,3,33,147,7,192,1,8,116,193,240,0,82,127,255,132,47,65,11,137,191,174,45,
+153,98,242,229,191,144,105,4,95,47,46,91,249,32,211,185,6,94,92,183,242,65,
+163,14,236,155,52,238,206,0,85,255,192,6,13,167,157,109,57,123,136,144,31,
+245,192,3,5,231,179,78,60,163,9,0,2,10,199,248,0,3,254,192,4,32,249,242,
+244,147,187,163,129,116,128,24,66,51,229,233,87,78,238,142,5,210,0,65,8,
+207,151,164,157,221,24,182,23,72,1,140,39,62,94,149,116,238,232,197,176,
+186,64,8,97,25,242,244,147,187,163,54,66,233,0,50,132,231,203,210,174,157,
+221,25,178,23,72,1,20,43,62,94,145,182,111,195,209,155,33,116,128,17,194,
+179,229,233,27,102,252,61,27,52,23,72,1,36,31,158,94,146,119,116,112,50,
+208,3,8,71,60,189,42,233,221,209,192,203,64,8,33,28,242,244,147,187,163,22,
+195,45,0,49,132,243,203,210,174,157,221,24,182,25,104,1,12,35,158,94,146,
+119,116,102,200,101,160,6,80,158,121,122,85,211,187,163,54,67,45,0,34,133,
+115,203,210,54,205,248,122,51,100,50,208,2,56,87,60,189,35,108,223,135,163,
+102,131,45,0,36,7,255,248,1,11,50,136,132,115,235,139,15,46,88,124,140,36,
+0,4,43,79,224,139,16,0,0,0,0,0,0,60,15,192,101,253,152,0,5,109,252,17,98,0,
+0,0,0,0,0,7,129,248,12,191,181,0,0,174,63,130,44,64,0,0,0,0,0,0,240,63,1,
+151,246,224,0,21,215,240,69,136,0,0,0,0,0,0,0,8,0,50,254,228,0,2,188,254,8,
+177,0,0,0,0,0,0,0,1,0,6,95,221,128,0,87,223,193,22,32,0,0,0,0,0,0,8,32,0,
+203,251,208,0,11,3,248,34,196,0,0,0,0,0,0,1,4,0,25,127,126,0,1,97,127,4,88,
+128,0,0,0,0,0,0,32,128,3,47,240,64,0,44,79,224,139,16,0,0,0,0,0,0,8,16,0,
+101,254,24,0,5,141,252,1,96,216,247,238,199,135,162,162,33,90,121,197,221,
+143,126,77,59,179,172,146,17,167,156,46,185,179,101,228,176,65,89,77,16,
+124,123,246,240,195,203,40,162,64,0,193,255,138,5,144,158,89,112,228,171,
+39,119,71,2,232,132,114,203,135,36,157,221,28,11,164,0,66,25,203,46,28,149,
+100,238,232,197,180,200,162,233,0,1,134,114,203,135,37,89,59,186,49,109,10,
+40,186,64,2,97,124,178,225,201,39,119,70,45,166,69,23,72,0,140,47,150,92,
+57,36,238,232,197,180,40,162,233,0,25,134,114,203,135,37,89,59,186,51,101,
+50,40,186,64,0,161,156,178,225,201,86,78,238,140,217,66,138,46,144,0,168,
+95,44,184,114,73,221,209,155,41,145,69,210,0,37,11,229,151,14,73,59,186,51,
+101,10,40,186,64,6,161,124,178,225,201,27,102,252,61,38,69,23,72,0,28,47,
+150,92,57,35,108,223,135,164,40,162,233,0,11,134,114,203,135,36,77,253,113,
+108,203,50,40,186,64,1,33,156,178,225,201,19,127,92,91,50,194,138,46,144,0,
+200,87,44,184,114,85,147,187,164,200,162,237,0,5,133,114,203,135,37,89,59,
+186,66,138,46,208,0,216,79,44,184,114,73,221,210,100,81,118,128,10,194,121,
+101,195,146,78,238,144,162,139,180,0,118,21,223,150,158,153,106,201,221,
+209,192,203,33,61,249,105,233,150,78,238,142,6,90,0,33,13,239,203,79,76,
+181,100,238,232,197,180,200,163,45,0,1,134,247,229,167,166,90,178,119,116,
+98,218,20,81,150,128,4,195,59,242,211,211,44,157,221,24,182,153,20,101,160,
+2,48,206,252,180,244,203,39,119,70,45,161,69,25,104,0,204,55,191,45,61,50,
+213,147,187,163,54,83,34,140,180,0,10,27,223,150,158,153,106,201,221,209,
+155,40,81,70,90,0,21,12,239,203,79,76,178,119,116,102,202,100,81,150,128,9,
+67,59,242,211,211,44,157,221,25,178,133,20,101,160,3,80,206,252,180,244,
+203,27,102,252,61,38,69,25,104,0,28,51,191,45,61,50,198,217,191,15,72,81,
+70,90,0,23,13,239,203,79,76,177,55,245,197,179,44,200,163,45,0,4,134,247,
+229,167,166,88,155,250,226,217,150,20,81,150,128,6,66,251,242,211,211,45,
+89,59,186,76,138,51,16,0,88,95,126,90,122,101,171,39,119,72,81,70,98,0,27,
+10,239,203,79,76,178,119,116,153,20,102,32,2,176,174,252,180,244,203,39,
+119,72,81,70,98,0,58,40,173,176,82,90,4,19,54,157,155,21,217,6,203,199,174,
+29,156,197,9,7,199,191,111,12,60,178,138,20,0,6,9,143,127,15,42,208,130,
+243,217,167,30,81,132,65,123,242,211,211,42,228,0,
+};
+#elif defined(DUK_USE_DOUBLE_BE)
+DUK_INTERNAL const duk_uint8_t duk_builtins_data[3833] = {
+105,195,75,32,3,148,52,154,248,9,26,13,128,112,105,0,240,22,20,26,95,124,6,
+152,52,137,0,120,99,74,239,129,18,70,241,191,2,98,13,79,32,42,88,210,90,2,
+240,1,50,141,37,168,76,94,216,118,69,229,203,127,44,0,84,163,73,106,21,75,
+14,236,249,98,242,229,191,150,0,46,81,164,181,14,165,151,54,94,89,119,99,
+203,23,151,45,252,176,1,146,141,37,168,93,63,59,186,97,241,23,151,45,252,
+176,1,178,141,37,168,77,79,60,50,197,229,203,127,44,0,116,163,73,106,17,86,
+148,152,188,185,111,229,128,15,148,129,198,137,36,58,166,142,91,251,212,
+243,195,44,94,92,183,242,13,79,8,45,14,91,252,121,148,52,199,120,63,72,105,
+21,240,118,128,210,237,224,245,17,165,43,224,211,55,231,207,151,148,161,70,
+145,0,31,40,107,26,2,18,138,26,228,192,142,0,16,161,174,76,9,74,26,228,192,
+158,0,8,161,174,76,10,96,2,42,26,228,192,174,0,26,161,174,76,11,96,3,74,26,
+228,192,190,0,44,161,174,76,12,96,3,202,26,228,192,206,0,70,161,169,84,14,
+202,3,255,254,32,234,3,255,192,0,0,0,0,0,0,119,1,255,192,0,0,0,0,0,0,57,
+136,1,152,32,16,194,0,166,24,6,49,0,57,138,2,12,96,18,99,128,163,32,5,153,
+40,76,94,216,118,69,229,203,127,35,41,10,165,135,118,124,177,121,114,223,
+200,203,67,169,101,205,151,150,93,216,242,197,229,203,127,35,49,11,167,231,
+119,76,62,34,242,229,191,145,154,132,212,243,195,44,94,92,183,242,51,144,
+138,180,164,197,229,203,127,35,60,6,26,0,52,208,193,226,117,215,211,15,12,
+166,146,11,67,150,255,30,77,24,58,113,64,243,92,8,27,0,68,217,130,70,212,
+19,54,224,161,185,5,77,216,44,111,65,115,126,12,28,16,100,225,156,16,32,18,
+17,195,15,46,121,100,238,232,136,136,87,12,60,185,229,141,179,126,30,136,
+100,130,233,231,59,12,228,34,66,52,243,141,167,118,158,153,80,73,9,201,151,
+30,252,153,106,210,146,118,72,150,76,184,247,228,203,86,148,152,123,246,
+240,223,187,46,238,135,132,132,229,221,143,126,76,181,105,73,61,36,75,46,
+236,123,242,101,171,74,76,61,251,120,111,221,151,119,67,226,65,178,243,199,
+135,134,83,242,66,58,238,203,207,30,30,25,81,201,5,225,203,78,238,136,163,
+208,92,59,50,242,232,138,62,0,2,38,163,19,255,255,224,142,80,192,0,20,31,
+240,14,135,103,203,210,135,45,253,55,244,243,195,44,252,205,197,0,1,18,221,
+82,0,3,24,207,151,164,254,251,168,114,223,195,47,46,158,98,101,231,143,150,
+158,29,55,242,104,68,79,62,94,147,251,238,161,203,127,12,188,186,121,157,
+135,110,94,109,100,131,99,229,151,15,76,172,168,8,89,217,16,201,151,54,157,
+217,104,114,223,195,47,46,154,114,243,102,68,19,158,92,59,27,73,6,205,203,
+46,95,89,91,74,0,3,17,225,203,47,108,187,186,69,241,211,46,238,122,119,238,
+230,216,72,70,158,116,242,225,217,151,35,81,33,26,121,198,229,191,214,93,
+205,69,0,1,134,105,231,23,199,76,187,185,233,197,179,43,73,32,154,242,249,
+230,214,80,0,31,255,193,2,38,103,110,117,24,81,115,0,78,228,0,161,208,16,
+237,24,121,207,239,186,135,45,252,50,242,233,229,188,144,221,60,232,114,
+223,211,127,79,60,50,207,204,224,72,167,14,91,248,101,229,211,204,158,113,
+119,117,219,151,150,28,91,50,184,144,40,95,224,0,15,248,64,4,20,78,129,5,
+195,195,134,207,38,232,130,99,195,179,97,201,244,19,22,157,217,14,15,130,
+135,254,0,48,125,60,224,242,229,135,200,9,1,255,12,2,162,136,112,2,112,80,
+128,0,193,177,239,221,143,15,64,35,224,152,20,144,62,27,248,3,2,9,195,175,
+61,0,231,208,126,89,123,101,229,207,40,72,32,188,244,105,205,208,40,16,94,
+123,52,227,202,22,136,39,61,252,186,6,18,13,207,134,205,56,242,134,175,65,
+250,238,231,163,78,110,129,231,208,125,59,178,101,241,63,48,25,248,0,12,47,
+102,30,125,36,238,201,151,196,252,192,103,255,255,240,92,189,178,242,242,8,
+105,4,231,191,110,80,67,80,0,24,62,109,252,162,225,199,160,16,212,0,10,7,
+183,15,0,67,80,0,56,54,109,59,58,101,228,8,106,0,9,6,229,151,39,92,121,66,
+15,192,0,97,124,178,228,235,143,45,45,57,244,116,8,63,255,255,10,39,248,0,
+195,51,114,223,182,30,140,60,161,239,201,149,248,248,31,241,0,140,80,129,
+202,10,49,128,10,35,1,6,199,163,15,40,61,32,9,10,199,163,15,40,123,242,101,
+131,210,4,144,108,123,247,99,195,210,8,250,15,167,118,76,190,39,230,131,52,
+133,236,195,207,164,157,217,50,248,159,154,12,212,0,6,27,179,126,60,59,50,
+195,223,183,134,30,89,97,9,5,219,135,166,61,16,164,131,242,203,195,102,28,
+121,97,145,6,231,151,15,44,122,33,201,5,231,179,78,60,177,8,130,243,225,
+179,79,72,148,66,121,245,197,207,167,45,59,179,197,162,23,211,124,205,253,
+242,242,135,135,158,87,240,68,122,111,153,191,30,29,153,102,111,239,151,
+148,60,60,242,191,130,23,211,125,94,28,50,242,135,135,158,87,240,128,0,196,
+122,111,153,191,30,29,153,106,240,225,151,148,60,60,242,191,132,0,6,9,211,
+150,157,177,160,131,115,235,139,159,78,81,72,10,47,248,0,3,254,40,17,138,
+48,66,136,152,64,0,66,129,48,5,27,252,88,76,216,54,47,214,131,50,172,88,15,
+253,255,255,255,255,255,255,240,153,178,103,95,173,6,101,88,176,0,0,0,0,0,
+0,0,0,67,168,15,255,0,0,0,0,0,0,17,26,19,233,201,169,38,180,91,242,103,70,
+147,58,77,75,48,31,252,0,0,0,0,0,0,34,51,162,199,131,82,77,104,183,228,206,
+141,38,116,154,150,96,127,248,0,0,0,0,0,0,0,15,248,192,70,40,0,0,0,0,0,0,0,
+0,3,10,44,68,9,216,8,20,49,130,15,211,124,109,62,50,228,95,36,55,166,248,
+190,56,111,221,151,119,77,56,118,47,18,23,211,125,14,89,113,233,231,167,
+126,230,18,5,31,252,0,224,188,48,242,231,148,116,144,58,181,33,143,127,64,
+247,111,238,56,0,127,199,2,49,72,127,248,0,0,0,0,0,0,180,81,36,4,51,166,
+248,152,122,101,167,211,150,157,217,201,2,0,3,12,233,190,166,157,185,105,
+244,229,167,118,114,64,128,1,4,228,129,0,3,137,116,223,51,126,60,59,50,196,
+195,211,45,62,156,180,238,206,72,16,0,72,151,77,243,55,227,195,179,45,77,
+59,114,211,233,203,78,236,228,129,0,5,10,73,2,0,12,21,18,4,0,28,82,35,32,
+80,74,8,62,124,189,42,105,219,148,148,16,188,249,122,70,235,179,101,156,
+184,121,15,132,0,34,29,159,47,74,181,33,198,235,179,101,156,184,121,15,132,
+0,38,17,159,47,73,187,247,116,208,62,16,0,168,94,124,189,42,212,135,55,126,
+238,154,7,194,0,23,7,207,151,164,76,61,50,143,132,0,50,21,159,47,74,181,33,
+196,195,211,40,248,64,3,96,217,242,244,137,135,200,248,64,3,161,57,242,244,
+171,82,28,76,62,71,194,0,31,8,207,151,164,141,253,121,115,31,8,0,132,47,62,
+94,149,106,67,145,191,175,46,99,225,0,17,133,103,203,210,110,157,221,122,
+101,230,62,16,1,40,110,124,189,42,212,135,55,78,238,189,50,243,31,8,0,156,
+43,62,94,148,242,227,223,187,39,49,240,128,10,67,115,229,233,86,164,58,121,
+113,239,221,147,152,248,64,5,97,249,242,244,155,167,102,205,60,242,227,223,
+187,39,49,240,128,11,68,179,229,233,86,164,57,186,118,108,211,207,46,61,
+251,178,115,31,8,0,188,71,62,94,149,52,237,203,235,126,236,179,243,102,231,
+151,161,0,32,252,242,244,169,167,110,82,34,67,249,229,233,55,78,205,154,
+121,229,199,191,118,78,100,37,0,24,137,115,203,210,173,72,115,116,236,217,
+167,158,92,123,247,100,230,66,80,1,152,87,60,189,41,229,199,191,118,78,100,
+43,224,3,80,222,121,122,85,169,14,158,92,123,247,100,230,66,190,0,55,10,
+231,151,164,221,59,186,244,203,204,133,252,0,114,27,207,47,74,181,33,205,
+211,187,175,76,188,200,95,192,7,97,28,242,244,145,191,175,46,100,51,224,3,
+208,190,121,122,85,169,14,70,254,188,185,144,207,128,15,193,249,229,233,19,
+15,76,164,37,0,32,133,115,203,210,173,72,113,48,244,202,66,80,2,24,71,60,
+189,38,239,221,211,65,10,248,1,20,47,158,94,149,106,67,155,191,119,77,4,43,
+224,4,112,190,121,122,70,235,179,101,156,184,121,16,191,128,18,67,185,229,
+233,86,164,56,221,118,108,179,151,15,34,23,240,2,88,62,124,189,44,229,195,
+200,124,32,4,208,126,121,122,89,203,135,145,9,64,9,194,145,254,0,0,255,144,
+24,100,130,14,0,16,176,2,192,129,11,33,12,1,168,193,108,96,186,48,95,32,0,
+0,0,0,0,0,0,0,56,38,95,25,113,189,18,9,211,47,62,143,100,20,95,0,20,159,
+240,0,7,252,144,162,241,2,195,66,7,11,89,204,140,197,252,229,197,226,230,
+115,3,16,69,19,64,5,43,252,0,9,255,40,16,188,33,49,123,97,217,23,151,45,
+252,131,66,7,0,20,191,240,0,39,252,176,66,240,133,82,195,187,62,88,188,185,
+111,228,26,16,56,0,166,127,128,1,63,230,2,23,132,58,150,92,217,121,101,221,
+143,44,94,92,183,242,13,8,28,0,83,127,192,0,159,243,65,11,194,23,79,206,
+238,152,124,69,229,203,127,32,208,129,192,5,59,252,0,9,255,56,16,188,33,53,
+60,240,203,23,151,45,252,131,66,7,0,20,255,240,0,39,252,240,66,240,132,85,
+165,38,47,46,91,249,6,132,14,0,31,255,228,64,98,192,64,5,191,10,139,20,87,
+105,130,76,156,197,132,4,0,38,187,27,187,85,81,104,28,201,204,160,31,243,
+23,33,127,125,28,247,193,102,79,142,202,44,3,255,113,84,118,82,184,47,232,
+52,201,241,216,176,139,0,255,111,45,236,84,155,148,58,5,66,76,4,0,146,31,
+181,68,66,209,136,61,58,52,170,49,190,202,1,255,53,4,243,51,249,222,108,22,
+157,26,85,25,64,63,246,160,158,102,127,59,205,74,7,135,23,53,2,65,48,227,
+223,205,64,160,0,48,76,60,244,238,80,40,0,20,19,15,76,59,148,10,0,7,5,195,
+211,14,230,74,72,130,99,203,167,98,129,64,1,32,120,247,243,80,40,0,44,15,
+47,142,10,5,0,6,130,230,217,191,127,37,2,128,3,192,246,111,206,160,80,0,
+136,30,220,62,19,151,160,123,116,238,79,94,129,240,223,221,73,32,0,48,110,
+88,119,100,223,181,68,16,94,91,250,238,200,160,80,0,152,31,61,59,148,10,0,
+21,4,231,199,151,69,2,128,5,192,250,97,220,160,80,0,192,127,255,128,20,23,
+134,30,92,242,164,34,19,207,167,45,59,179,233,205,229,37,129,127,255,0,0,
+191,255,128,0,63,255,197,131,246,203,203,158,157,251,160,32,98,65,128,0,0,
+0,0,3,166,156,30,53,32,249,165,131,76,223,159,62,94,70,172,114,16,176,144,
+60,56,250,19,18,5,159,25,89,32,121,180,238,42,30,129,229,221,140,164,122,7,
+147,46,50,129,232,62,61,251,120,97,199,208,156,129,83,127,0,50,250,69,3,
+252,131,32,248,250,242,229,151,119,72,240,3,254,148,0,2,168,254,0,0,255,
+167,0,33,68,88,32,0,33,64,176,2,170,254,0,0,255,169,0,33,69,220,32,0,33,67,
+184,2,172,254,0,0,255,171,8,137,144,128,0,0,0,0,0,0,0,68,73,4,195,187,126,
+226,8,4,178,16,41,164,32,147,7,136,52,193,240,0,18,17,48,124,0,8,133,76,31,
+0,3,33,147,7,192,1,8,116,193,240,0,82,127,255,132,47,65,11,137,191,174,45,
+153,98,242,229,191,144,105,4,95,47,46,91,249,32,211,185,6,94,92,183,242,65,
+163,14,236,155,52,238,206,0,85,255,192,6,13,167,157,109,57,123,136,144,31,
+245,192,3,5,231,179,78,60,163,9,0,2,10,199,248,0,3,254,192,4,32,249,242,
+244,147,187,163,129,116,128,24,66,51,229,233,87,78,238,142,5,210,0,65,8,
+207,151,164,157,221,24,182,23,72,1,140,39,62,94,149,116,238,232,197,176,
+186,64,8,97,25,242,244,147,187,163,54,66,233,0,50,132,231,203,210,174,157,
+221,25,178,23,72,1,20,43,62,94,145,182,111,195,209,155,33,116,128,17,194,
+179,229,233,27,102,252,61,27,52,23,72,1,36,31,158,94,146,119,116,112,50,
+208,3,8,71,60,189,42,233,221,209,192,203,64,8,33,28,242,244,147,187,163,22,
+195,45,0,49,132,243,203,210,174,157,221,24,182,25,104,1,12,35,158,94,146,
+119,116,102,200,101,160,6,80,158,121,122,85,211,187,163,54,67,45,0,34,133,
+115,203,210,54,205,248,122,51,100,50,208,2,56,87,60,189,35,108,223,135,163,
+102,131,45,0,36,7,255,248,1,11,50,136,132,115,235,139,15,46,88,124,140,36,
+0,4,43,79,224,139,16,15,252,0,0,0,0,0,0,0,101,253,152,0,5,109,252,17,98,1,
+255,128,0,0,0,0,0,0,12,191,181,0,0,174,63,130,44,64,63,240,0,0,0,0,0,0,1,
+151,246,224,0,21,215,240,69,136,8,0,0,0,0,0,0,0,0,50,254,228,0,2,188,254,8,
+177,1,0,0,0,0,0,0,0,0,6,95,221,128,0,87,223,193,22,32,32,8,0,0,0,0,0,0,0,
+203,251,208,0,11,3,248,34,196,4,1,0,0,0,0,0,0,0,25,127,126,0,1,97,127,4,88,
+128,128,32,0,0,0,0,0,0,3,47,240,64,0,44,79,224,139,16,16,8,0,0,0,0,0,0,0,
+101,254,24,0,5,141,252,1,96,216,247,238,199,135,162,162,33,90,121,197,221,
+143,126,77,59,179,172,146,17,167,156,46,185,179,101,228,176,65,89,77,16,
+124,123,246,240,195,203,40,162,64,0,193,255,138,5,144,158,89,112,228,171,
+39,119,71,2,232,132,114,203,135,36,157,221,28,11,164,0,66,25,203,46,28,149,
+100,238,232,197,180,200,162,233,0,1,134,114,203,135,37,89,59,186,49,109,10,
+40,186,64,2,97,124,178,225,201,39,119,70,45,166,69,23,72,0,140,47,150,92,
+57,36,238,232,197,180,40,162,233,0,25,134,114,203,135,37,89,59,186,51,101,
+50,40,186,64,0,161,156,178,225,201,86,78,238,140,217,66,138,46,144,0,168,
+95,44,184,114,73,221,209,155,41,145,69,210,0,37,11,229,151,14,73,59,186,51,
+101,10,40,186,64,6,161,124,178,225,201,27,102,252,61,38,69,23,72,0,28,47,
+150,92,57,35,108,223,135,164,40,162,233,0,11,134,114,203,135,36,77,253,113,
+108,203,50,40,186,64,1,33,156,178,225,201,19,127,92,91,50,194,138,46,144,0,
+200,87,44,184,114,85,147,187,164,200,162,237,0,5,133,114,203,135,37,89,59,
+186,66,138,46,208,0,216,79,44,184,114,73,221,210,100,81,118,128,10,194,121,
+101,195,146,78,238,144,162,139,180,0,118,21,223,150,158,153,106,201,221,
+209,192,203,33,61,249,105,233,150,78,238,142,6,90,0,33,13,239,203,79,76,
+181,100,238,232,197,180,200,163,45,0,1,134,247,229,167,166,90,178,119,116,
+98,218,20,81,150,128,4,195,59,242,211,211,44,157,221,24,182,153,20,101,160,
+2,48,206,252,180,244,203,39,119,70,45,161,69,25,104,0,204,55,191,45,61,50,
+213,147,187,163,54,83,34,140,180,0,10,27,223,150,158,153,106,201,221,209,
+155,40,81,70,90,0,21,12,239,203,79,76,178,119,116,102,202,100,81,150,128,9,
+67,59,242,211,211,44,157,221,25,178,133,20,101,160,3,80,206,252,180,244,
+203,27,102,252,61,38,69,25,104,0,28,51,191,45,61,50,198,217,191,15,72,81,
+70,90,0,23,13,239,203,79,76,177,55,245,197,179,44,200,163,45,0,4,134,247,
+229,167,166,88,155,250,226,217,150,20,81,150,128,6,66,251,242,211,211,45,
+89,59,186,76,138,51,16,0,88,95,126,90,122,101,171,39,119,72,81,70,98,0,27,
+10,239,203,79,76,178,119,116,153,20,102,32,2,176,174,252,180,244,203,39,
+119,72,81,70,98,0,58,40,173,176,82,90,4,19,54,157,155,21,217,6,203,199,174,
+29,156,197,9,7,199,191,111,12,60,178,138,20,0,6,9,143,127,15,42,208,130,
+243,217,167,30,81,132,65,123,242,211,211,42,228,0,
+};
+#elif defined(DUK_USE_DOUBLE_ME)
+DUK_INTERNAL const duk_uint8_t duk_builtins_data[3833] = {
+105,195,75,32,3,148,52,154,248,9,26,13,128,112,105,0,240,22,20,26,95,124,6,
+152,52,137,0,120,99,74,239,129,18,70,241,191,2,98,13,79,32,42,88,210,90,2,
+240,1,50,141,37,168,76,94,216,118,69,229,203,127,44,0,84,163,73,106,21,75,
+14,236,249,98,242,229,191,150,0,46,81,164,181,14,165,151,54,94,89,119,99,
+203,23,151,45,252,176,1,146,141,37,168,93,63,59,186,97,241,23,151,45,252,
+176,1,178,141,37,168,77,79,60,50,197,229,203,127,44,0,116,163,73,106,17,86,
+148,152,188,185,111,229,128,15,148,129,198,137,36,58,166,142,91,251,212,
+243,195,44,94,92,183,242,13,79,8,45,14,91,252,121,148,52,199,120,63,72,105,
+21,240,118,128,210,237,224,245,17,165,43,224,211,55,231,207,151,148,161,70,
+145,0,31,40,107,26,2,18,138,26,228,192,142,0,16,161,174,76,9,74,26,228,192,
+158,0,8,161,174,76,10,96,2,42,26,228,192,174,0,26,161,174,76,11,96,3,74,26,
+228,192,190,0,44,161,174,76,12,96,3,202,26,228,192,206,0,70,161,169,84,14,
+202,3,255,254,32,234,0,0,7,195,248,0,0,0,0,119,0,0,3,193,252,0,0,0,0,57,
+136,1,152,32,16,194,0,166,24,6,49,0,57,138,2,12,96,18,99,128,163,32,5,153,
+40,76,94,216,118,69,229,203,127,35,41,10,165,135,118,124,177,121,114,223,
+200,203,67,169,101,205,151,150,93,216,242,197,229,203,127,35,49,11,167,231,
+119,76,62,34,242,229,191,145,154,132,212,243,195,44,94,92,183,242,51,144,
+138,180,164,197,229,203,127,35,60,6,26,0,52,208,193,226,117,215,211,15,12,
+166,146,11,67,150,255,30,77,24,58,113,64,243,92,8,27,0,68,217,130,70,212,
+19,54,224,161,185,5,77,216,44,111,65,115,126,12,28,16,100,225,156,16,32,18,
+17,195,15,46,121,100,238,232,136,136,87,12,60,185,229,141,179,126,30,136,
+100,130,233,231,59,12,228,34,66,52,243,141,167,118,158,153,80,73,9,201,151,
+30,252,153,106,210,146,118,72,150,76,184,247,228,203,86,148,152,123,246,
+240,223,187,46,238,135,132,132,229,221,143,126,76,181,105,73,61,36,75,46,
+236,123,242,101,171,74,76,61,251,120,111,221,151,119,67,226,65,178,243,199,
+135,134,83,242,66,58,238,203,207,30,30,25,81,201,5,225,203,78,238,136,163,
+208,92,59,50,242,232,138,62,0,2,38,163,19,255,255,224,142,80,192,0,20,31,
+240,14,135,103,203,210,135,45,253,55,244,243,195,44,252,205,197,0,1,18,221,
+82,0,3,24,207,151,164,254,251,168,114,223,195,47,46,158,98,101,231,143,150,
+158,29,55,242,104,68,79,62,94,147,251,238,161,203,127,12,188,186,121,157,
+135,110,94,109,100,131,99,229,151,15,76,172,168,8,89,217,16,201,151,54,157,
+217,104,114,223,195,47,46,154,114,243,102,68,19,158,92,59,27,73,6,205,203,
+46,95,89,91,74,0,3,17,225,203,47,108,187,186,69,241,211,46,238,122,119,238,
+230,216,72,70,158,116,242,225,217,151,35,81,33,26,121,198,229,191,214,93,
+205,69,0,1,134,105,231,23,199,76,187,185,233,197,179,43,73,32,154,242,249,
+230,214,80,0,31,255,193,2,38,103,110,117,24,81,115,0,78,228,0,161,208,16,
+237,24,121,207,239,186,135,45,252,50,242,233,229,188,144,221,60,232,114,
+223,211,127,79,60,50,207,204,224,72,167,14,91,248,101,229,211,204,158,113,
+119,117,219,151,150,28,91,50,184,144,40,95,224,0,15,248,64,4,20,78,129,5,
+195,195,134,207,38,232,130,99,195,179,97,201,244,19,22,157,217,14,15,130,
+135,254,0,48,125,60,224,242,229,135,200,9,1,255,12,2,162,136,112,2,112,80,
+128,0,193,177,239,221,143,15,64,35,224,152,20,144,62,27,248,3,2,9,195,175,
+61,0,231,208,126,89,123,101,229,207,40,72,32,188,244,105,205,208,40,16,94,
+123,52,227,202,22,136,39,61,252,186,6,18,13,207,134,205,56,242,134,175,65,
+250,238,231,163,78,110,129,231,208,125,59,178,101,241,63,48,25,248,0,12,47,
+102,30,125,36,238,201,151,196,252,192,103,255,255,240,92,189,178,242,242,8,
+105,4,231,191,110,80,67,80,0,24,62,109,252,162,225,199,160,16,212,0,10,7,
+183,15,0,67,80,0,56,54,109,59,58,101,228,8,106,0,9,6,229,151,39,92,121,66,
+15,192,0,97,124,178,228,235,143,45,45,57,244,116,8,63,255,255,10,39,248,0,
+195,51,114,223,182,30,140,60,161,239,201,149,248,248,31,241,0,140,80,129,
+202,10,49,128,10,35,1,6,199,163,15,40,61,32,9,10,199,163,15,40,123,242,101,
+131,210,4,144,108,123,247,99,195,210,8,250,15,167,118,76,190,39,230,131,52,
+133,236,195,207,164,157,217,50,248,159,154,12,212,0,6,27,179,126,60,59,50,
+195,223,183,134,30,89,97,9,5,219,135,166,61,16,164,131,242,203,195,102,28,
+121,97,145,6,231,151,15,44,122,33,201,5,231,179,78,60,177,8,130,243,225,
+179,79,72,148,66,121,245,197,207,167,45,59,179,197,162,23,211,124,205,253,
+242,242,135,135,158,87,240,68,122,111,153,191,30,29,153,102,111,239,151,
+148,60,60,242,191,130,23,211,125,94,28,50,242,135,135,158,87,240,128,0,196,
+122,111,153,191,30,29,153,106,240,225,151,148,60,60,242,191,132,0,6,9,211,
+150,157,177,160,131,115,235,139,159,78,81,72,10,47,248,0,3,254,40,17,138,
+48,66,136,152,64,0,66,129,48,5,27,252,88,76,216,54,47,214,131,50,172,88,31,
+255,253,239,255,255,255,255,240,153,178,103,95,173,6,101,88,176,0,0,0,0,0,
+64,0,0,3,168,0,0,31,15,224,0,0,0,17,26,19,233,201,169,38,180,91,242,103,70,
+147,58,77,75,48,0,0,60,31,192,0,0,0,34,51,162,199,131,82,77,104,183,228,
+206,141,38,116,154,150,96,0,0,120,127,128,0,0,0,0,15,248,192,70,40,0,0,0,0,
+0,0,0,0,3,10,44,68,9,216,8,20,49,130,15,211,124,109,62,50,228,95,36,55,166,
+248,190,56,111,221,151,119,77,56,118,47,18,23,211,125,14,89,113,233,231,
+167,126,230,18,5,31,252,0,224,188,48,242,231,148,116,144,58,181,33,143,127,
+64,247,111,238,56,0,127,199,2,49,72,0,0,248,127,0,0,0,0,180,81,36,4,51,166,
+248,152,122,101,167,211,150,157,217,201,2,0,3,12,233,190,166,157,185,105,
+244,229,167,118,114,64,128,1,4,228,129,0,3,137,116,223,51,126,60,59,50,196,
+195,211,45,62,156,180,238,206,72,16,0,72,151,77,243,55,227,195,179,45,77,
+59,114,211,233,203,78,236,228,129,0,5,10,73,2,0,12,21,18,4,0,28,82,35,32,
+80,74,8,62,124,189,42,105,219,148,148,16,188,249,122,70,235,179,101,156,
+184,121,15,132,0,34,29,159,47,74,181,33,198,235,179,101,156,184,121,15,132,
+0,38,17,159,47,73,187,247,116,208,62,16,0,168,94,124,189,42,212,135,55,126,
+238,154,7,194,0,23,7,207,151,164,76,61,50,143,132,0,50,21,159,47,74,181,33,
+196,195,211,40,248,64,3,96,217,242,244,137,135,200,248,64,3,161,57,242,244,
+171,82,28,76,62,71,194,0,31,8,207,151,164,141,253,121,115,31,8,0,132,47,62,
+94,149,106,67,145,191,175,46,99,225,0,17,133,103,203,210,110,157,221,122,
+101,230,62,16,1,40,110,124,189,42,212,135,55,78,238,189,50,243,31,8,0,156,
+43,62,94,148,242,227,223,187,39,49,240,128,10,67,115,229,233,86,164,58,121,
+113,239,221,147,152,248,64,5,97,249,242,244,155,167,102,205,60,242,227,223,
+187,39,49,240,128,11,68,179,229,233,86,164,57,186,118,108,211,207,46,61,
+251,178,115,31,8,0,188,71,62,94,149,52,237,203,235,126,236,179,243,102,231,
+151,161,0,32,252,242,244,169,167,110,82,34,67,249,229,233,55,78,205,154,
+121,229,199,191,118,78,100,37,0,24,137,115,203,210,173,72,115,116,236,217,
+167,158,92,123,247,100,230,66,80,1,152,87,60,189,41,229,199,191,118,78,100,
+43,224,3,80,222,121,122,85,169,14,158,92,123,247,100,230,66,190,0,55,10,
+231,151,164,221,59,186,244,203,204,133,252,0,114,27,207,47,74,181,33,205,
+211,187,175,76,188,200,95,192,7,97,28,242,244,145,191,175,46,100,51,224,3,
+208,190,121,122,85,169,14,70,254,188,185,144,207,128,15,193,249,229,233,19,
+15,76,164,37,0,32,133,115,203,210,173,72,113,48,244,202,66,80,2,24,71,60,
+189,38,239,221,211,65,10,248,1,20,47,158,94,149,106,67,155,191,119,77,4,43,
+224,4,112,190,121,122,70,235,179,101,156,184,121,16,191,128,18,67,185,229,
+233,86,164,56,221,118,108,179,151,15,34,23,240,2,88,62,124,189,44,229,195,
+200,124,32,4,208,126,121,122,89,203,135,145,9,64,9,194,145,254,0,0,255,144,
+24,100,130,14,0,16,176,2,192,129,11,33,12,1,168,193,108,96,186,48,95,32,0,
+0,0,0,0,0,0,0,56,38,95,25,113,189,18,9,211,47,62,143,100,20,95,0,20,159,
+240,0,7,252,144,162,241,2,195,66,7,11,89,204,140,197,252,229,197,226,230,
+115,3,16,69,19,64,5,43,252,0,9,255,40,16,188,33,49,123,97,217,23,151,45,
+252,131,66,7,0,20,191,240,0,39,252,176,66,240,133,82,195,187,62,88,188,185,
+111,228,26,16,56,0,166,127,128,1,63,230,2,23,132,58,150,92,217,121,101,221,
+143,44,94,92,183,242,13,8,28,0,83,127,192,0,159,243,65,11,194,23,79,206,
+238,152,124,69,229,203,127,32,208,129,192,5,59,252,0,9,255,56,16,188,33,53,
+60,240,203,23,151,45,252,131,66,7,0,20,255,240,0,39,252,240,66,240,132,85,
+165,38,47,46,91,249,6,132,14,0,31,255,228,64,98,192,10,191,5,64,105,87,20,
+139,130,76,156,197,132,11,22,176,36,1,101,91,91,184,28,201,204,160,33,23,
+115,31,247,156,253,127,65,102,79,142,202,44,4,113,95,115,255,232,34,182,88,
+52,201,241,216,176,139,1,239,47,108,252,59,148,152,86,5,66,76,15,178,16,
+148,1,130,212,69,72,61,58,52,170,49,190,202,4,245,7,49,254,105,219,251,52,
+22,157,26,85,25,64,158,160,246,63,205,59,127,102,74,7,135,23,53,2,65,48,
+227,223,205,64,160,0,48,76,60,244,238,80,40,0,20,19,15,76,59,148,10,0,7,5,
+195,211,14,230,74,72,130,99,203,167,98,129,64,1,32,120,247,243,80,40,0,44,
+15,47,142,10,5,0,6,130,230,217,191,127,37,2,128,3,192,246,111,206,160,80,0,
+136,30,220,62,19,151,160,123,116,238,79,94,129,240,223,221,73,32,0,48,110,
+88,119,100,223,181,68,16,94,91,250,238,200,160,80,0,152,31,61,59,148,10,0,
+21,4,231,199,151,69,2,128,5,192,250,97,220,160,80,0,192,127,255,128,20,23,
+134,30,92,242,164,34,19,207,167,45,59,179,233,205,229,37,129,127,255,0,0,
+191,255,128,0,63,255,197,131,246,203,203,158,157,251,160,0,65,226,32,0,0,0,
+0,3,166,156,30,53,32,249,165,131,76,223,159,62,94,70,172,114,16,176,144,60,
+56,250,19,18,5,159,25,89,32,121,180,238,42,30,129,229,221,140,164,122,7,
+147,46,50,129,232,62,61,251,120,97,199,208,156,129,83,127,0,50,250,69,3,
+252,131,32,248,250,242,229,151,119,72,240,3,254,148,0,2,168,254,0,0,255,
+167,0,33,68,88,32,0,33,64,176,2,170,254,0,0,255,169,0,33,69,220,32,0,33,67,
+184,2,172,254,0,0,255,171,8,137,144,0,0,0,128,0,0,0,0,68,73,4,195,187,126,
+226,8,4,178,16,41,164,32,147,7,136,52,193,240,0,18,17,48,124,0,8,133,76,31,
+0,3,33,147,7,192,1,8,116,193,240,0,82,127,255,132,47,65,11,137,191,174,45,
+153,98,242,229,191,144,105,4,95,47,46,91,249,32,211,185,6,94,92,183,242,65,
+163,14,236,155,52,238,206,0,85,255,192,6,13,167,157,109,57,123,136,144,31,
+245,192,3,5,231,179,78,60,163,9,0,2,10,199,248,0,3,254,192,4,32,249,242,
+244,147,187,163,129,116,128,24,66,51,229,233,87,78,238,142,5,210,0,65,8,
+207,151,164,157,221,24,182,23,72,1,140,39,62,94,149,116,238,232,197,176,
+186,64,8,97,25,242,244,147,187,163,54,66,233,0,50,132,231,203,210,174,157,
+221,25,178,23,72,1,20,43,62,94,145,182,111,195,209,155,33,116,128,17,194,
+179,229,233,27,102,252,61,27,52,23,72,1,36,31,158,94,146,119,116,112,50,
+208,3,8,71,60,189,42,233,221,209,192,203,64,8,33,28,242,244,147,187,163,22,
+195,45,0,49,132,243,203,210,174,157,221,24,182,25,104,1,12,35,158,94,146,
+119,116,102,200,101,160,6,80,158,121,122,85,211,187,163,54,67,45,0,34,133,
+115,203,210,54,205,248,122,51,100,50,208,2,56,87,60,189,35,108,223,135,163,
+102,131,45,0,36,7,255,248,1,11,50,136,132,115,235,139,15,46,88,124,140,36,
+0,4,43,79,224,139,16,0,0,60,15,192,0,0,0,0,101,253,152,0,5,109,252,17,98,0,
+0,7,129,248,0,0,0,0,12,191,181,0,0,174,63,130,44,64,0,0,240,63,0,0,0,0,1,
+151,246,224,0,21,215,240,69,136,0,0,0,8,0,0,0,0,0,50,254,228,0,2,188,254,8,
+177,0,0,0,1,0,0,0,0,0,6,95,221,128,0,87,223,193,22,32,0,0,8,32,0,0,0,0,0,
+203,251,208,0,11,3,248,34,196,0,0,1,4,0,0,0,0,0,25,127,126,0,1,97,127,4,88,
+128,0,0,32,128,0,0,0,0,3,47,240,64,0,44,79,224,139,16,0,0,8,16,0,0,0,0,0,
+101,254,24,0,5,141,252,1,96,216,247,238,199,135,162,162,33,90,121,197,221,
+143,126,77,59,179,172,146,17,167,156,46,185,179,101,228,176,65,89,77,16,
+124,123,246,240,195,203,40,162,64,0,193,255,138,5,144,158,89,112,228,171,
+39,119,71,2,232,132,114,203,135,36,157,221,28,11,164,0,66,25,203,46,28,149,
+100,238,232,197,180,200,162,233,0,1,134,114,203,135,37,89,59,186,49,109,10,
+40,186,64,2,97,124,178,225,201,39,119,70,45,166,69,23,72,0,140,47,150,92,
+57,36,238,232,197,180,40,162,233,0,25,134,114,203,135,37,89,59,186,51,101,
+50,40,186,64,0,161,156,178,225,201,86,78,238,140,217,66,138,46,144,0,168,
+95,44,184,114,73,221,209,155,41,145,69,210,0,37,11,229,151,14,73,59,186,51,
+101,10,40,186,64,6,161,124,178,225,201,27,102,252,61,38,69,23,72,0,28,47,
+150,92,57,35,108,223,135,164,40,162,233,0,11,134,114,203,135,36,77,253,113,
+108,203,50,40,186,64,1,33,156,178,225,201,19,127,92,91,50,194,138,46,144,0,
+200,87,44,184,114,85,147,187,164,200,162,237,0,5,133,114,203,135,37,89,59,
+186,66,138,46,208,0,216,79,44,184,114,73,221,210,100,81,118,128,10,194,121,
+101,195,146,78,238,144,162,139,180,0,118,21,223,150,158,153,106,201,221,
+209,192,203,33,61,249,105,233,150,78,238,142,6,90,0,33,13,239,203,79,76,
+181,100,238,232,197,180,200,163,45,0,1,134,247,229,167,166,90,178,119,116,
+98,218,20,81,150,128,4,195,59,242,211,211,44,157,221,24,182,153,20,101,160,
+2,48,206,252,180,244,203,39,119,70,45,161,69,25,104,0,204,55,191,45,61,50,
+213,147,187,163,54,83,34,140,180,0,10,27,223,150,158,153,106,201,221,209,
+155,40,81,70,90,0,21,12,239,203,79,76,178,119,116,102,202,100,81,150,128,9,
+67,59,242,211,211,44,157,221,25,178,133,20,101,160,3,80,206,252,180,244,
+203,27,102,252,61,38,69,25,104,0,28,51,191,45,61,50,198,217,191,15,72,81,
+70,90,0,23,13,239,203,79,76,177,55,245,197,179,44,200,163,45,0,4,134,247,
+229,167,166,88,155,250,226,217,150,20,81,150,128,6,66,251,242,211,211,45,
+89,59,186,76,138,51,16,0,88,95,126,90,122,101,171,39,119,72,81,70,98,0,27,
+10,239,203,79,76,178,119,116,153,20,102,32,2,176,174,252,180,244,203,39,
+119,72,81,70,98,0,58,40,173,176,82,90,4,19,54,157,155,21,217,6,203,199,174,
+29,156,197,9,7,199,191,111,12,60,178,138,20,0,6,9,143,127,15,42,208,130,
+243,217,167,30,81,132,65,123,242,211,211,42,228,0,
+};
+#else
+#error invalid endianness defines
+#endif
+#endif  /* DUK_USE_ROM_OBJECTS */


[21/51] [partial] nifi-minifi-cpp git commit: MINIFI-183 Added civet 1.9.1 sources Added onScheduled hook Added initial two-way TLS-enabled ListenHTTP implementation

Posted by al...@apache.org.
http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-noline/duk_config.h
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-noline/duk_config.h b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-noline/duk_config.h
new file mode 100644
index 0000000..ef62235
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-noline/duk_config.h
@@ -0,0 +1,3804 @@
+/*
+ *  duk_config.h configuration header generated by genconfig.py.
+ *
+ *  Git commit: cad34ae155acb0846545ca6bf2d29f9463b22bbb
+ *  Git describe: v1.5.2
+ *  Git branch: HEAD
+ *
+ *  Supported platforms:
+ *      - Mac OSX, iPhone, Darwin
+ *      - OpenBSD
+ *      - Generic BSD
+ *      - Atari ST TOS
+ *      - AmigaOS
+ *      - Windows
+ *      - Flashplayer (Crossbridge)
+ *      - QNX
+ *      - TI-Nspire
+ *      - Emscripten
+ *      - Linux
+ *      - Solaris
+ *      - Generic POSIX
+ *      - Cygwin
+ *      - Generic UNIX
+ *      - Generic fallback
+ *
+ *  Supported architectures:
+ *      - x86
+ *      - x64
+ *      - x32
+ *      - ARM 32-bit
+ *      - ARM 64-bit
+ *      - MIPS 32-bit
+ *      - MIPS 64-bit
+ *      - PowerPC 32-bit
+ *      - PowerPC 64-bit
+ *      - SPARC 32-bit
+ *      - SPARC 64-bit
+ *      - SuperH
+ *      - Motorola 68k
+ *      - Emscripten
+ *      - Generic
+ *
+ *  Supported compilers:
+ *      - Clang
+ *      - GCC
+ *      - MSVC
+ *      - Emscripten
+ *      - TinyC
+ *      - VBCC
+ *      - Bruce's C compiler
+ *      - Generic
+ *
+ */
+
+#if !defined(DUK_CONFIG_H_INCLUDED)
+#define DUK_CONFIG_H_INCLUDED
+
+/*
+ *  Intermediate helper defines
+ */
+
+/* DLL build detection */
+#if defined(DUK_OPT_DLL_BUILD)
+#define DUK_F_DLL_BUILD
+#elif defined(DUK_OPT_NO_DLL_BUILD)
+#undef DUK_F_DLL_BUILD
+#else
+/* not configured for DLL build */
+#undef DUK_F_DLL_BUILD
+#endif
+
+/* Apple OSX, iOS */
+#if defined(__APPLE__)
+#define DUK_F_APPLE
+#endif
+
+/* OpenBSD */
+#if defined(__OpenBSD__) || defined(__OpenBSD)
+#define DUK_F_OPENBSD
+#endif
+
+/* NetBSD */
+#if defined(__NetBSD__) || defined(__NetBSD)
+#define DUK_F_NETBSD
+#endif
+
+/* FreeBSD */
+#if defined(__FreeBSD__) || defined(__FreeBSD)
+#define DUK_F_FREEBSD
+#endif
+
+/* BSD variant */
+#if defined(DUK_F_FREEBSD) || defined(DUK_F_NETBSD) || defined(DUK_F_OPENBSD) || \
+    defined(__bsdi__) || defined(__DragonFly__)
+#define DUK_F_BSD
+#endif
+
+/* Atari ST TOS.  __TOS__ defined by PureC.  No platform define in VBCC
+ * apparently, so to use with VBCC user must define __TOS__ manually.
+  */
+#if defined(__TOS__)
+#define DUK_F_TOS
+#endif
+
+/* Motorola 68K.  Not defined by VBCC, so user must define one of these
+ * manually when using VBCC.
+ */
+#if defined(__m68k__) || defined(M68000) || defined(__MC68K__)
+#define DUK_F_M68K
+#endif
+
+/* AmigaOS.  Neither AMIGA nor __amigaos__ is defined on VBCC, so user must
+ * define 'AMIGA' manually when using VBCC.
+ */
+#if defined(AMIGA) || defined(__amigaos__)
+#define DUK_F_AMIGAOS
+#endif
+
+/* PowerPC */
+#if defined(__powerpc) || defined(__powerpc__) || defined(__PPC__)
+#define DUK_F_PPC
+#if defined(__PPC64__) || defined(__LP64__) || defined(_LP64)
+#define DUK_F_PPC64
+#else
+#define DUK_F_PPC32
+#endif
+#endif
+
+/* Windows, both 32-bit and 64-bit */
+#if defined(_WIN32) || defined(WIN32) || defined(_WIN64) || defined(WIN64) || \
+    defined(__WIN32__) || defined(__TOS_WIN__) || defined(__WINDOWS__)
+#define DUK_F_WINDOWS
+#if defined(_WIN64) || defined(WIN64)
+#define DUK_F_WIN64
+#else
+#define DUK_F_WIN32
+#endif
+#endif
+
+/* Flash player (e.g. Crossbridge) */
+#if defined(__FLASHPLAYER__)
+#define DUK_F_FLASHPLAYER
+#endif
+
+/* QNX */
+#if defined(__QNX__)
+#define DUK_F_QNX
+#endif
+
+/* TI-Nspire (using Ndless) */
+#if defined(_TINSPIRE)
+#define DUK_F_TINSPIRE
+#endif
+
+/* Emscripten (provided explicitly by user), improve if possible */
+#if defined(EMSCRIPTEN)
+#define DUK_F_EMSCRIPTEN
+#endif
+
+/* BCC (Bruce's C compiler): this is a "torture target" for compilation */
+#if defined(__BCC__) || defined(__BCC_VERSION__)
+#define DUK_F_BCC
+#endif
+
+/* Linux */
+#if defined(__linux) || defined(__linux__) || defined(linux)
+#define DUK_F_LINUX
+#endif
+
+/* illumos / Solaris */
+#if defined(__sun) && defined(__SVR4)
+#define DUK_F_SUN
+#endif
+
+/* POSIX */
+#if defined(__posix)
+#define DUK_F_POSIX
+#endif
+
+/* Cygwin */
+#if defined(__CYGWIN__)
+#define DUK_F_CYGWIN
+#endif
+
+/* Generic Unix (includes Cygwin) */
+#if defined(__unix) || defined(__unix__) || defined(unix) || \
+    defined(DUK_F_LINUX) || defined(DUK_F_BSD)
+#define DUK_F_UNIX
+#endif
+
+/* stdint.h not available */
+#if defined(DUK_F_WINDOWS) && defined(_MSC_VER)
+#if (_MSC_VER < 1700)
+/* VS2012+ has stdint.h, < VS2012 does not (but it's available for download). */
+#define DUK_F_NO_STDINT_H
+#endif
+#endif
+#if !defined(DUK_F_NO_STDINT_H) && (defined(DUK_F_TOS) || defined(DUK_F_BCC))
+#define DUK_F_NO_STDINT_H
+#endif
+
+/* C++ */
+#undef DUK_F_CPP
+#if defined(__cplusplus)
+#define DUK_F_CPP
+#endif
+
+/* Intel x86 (32-bit), x64 (64-bit) or x32 (64-bit but 32-bit pointers),
+ * define only one of DUK_F_X86, DUK_F_X64, DUK_F_X32.
+ * https://sites.google.com/site/x32abi/
+ */
+#if defined(__amd64__) || defined(__amd64) || \
+    defined(__x86_64__) || defined(__x86_64) || \
+    defined(_M_X64) || defined(_M_AMD64)
+#if defined(__ILP32__) || defined(_ILP32)
+#define DUK_F_X32
+#else
+#define DUK_F_X64
+#endif
+#elif defined(i386) || defined(__i386) || defined(__i386__) || \
+      defined(__i486__) || defined(__i586__) || defined(__i686__) || \
+      defined(__IA32__) || defined(_M_IX86) || defined(__X86__) || \
+      defined(_X86_) || defined(__THW_INTEL__) || defined(__I86__)
+#if defined(__LP64__) || defined(_LP64)
+/* This should not really happen, but would indicate x64. */
+#define DUK_F_X64
+#else
+#define DUK_F_X86
+#endif
+#endif
+
+/* ARM */
+#if defined(__arm__) || defined(__thumb__) || defined(_ARM) || defined(_M_ARM)
+#define DUK_F_ARM
+#if defined(__LP64__) || defined(_LP64) || defined(__arm64) || defined(__arm64__)
+#define DUK_F_ARM64
+#else
+#define DUK_F_ARM32
+#endif
+#endif
+
+/* MIPS.  Related defines: __MIPSEB__, __MIPSEL__, __mips_isa_rev, __LP64__ */
+#if defined(__mips__) || defined(mips) || defined(_MIPS_ISA) || \
+    defined(_R3000) || defined(_R4000) || defined(_R5900) || \
+    defined(_MIPS_ISA_MIPS1) || defined(_MIPS_ISA_MIPS2) || \
+    defined(_MIPS_ISA_MIPS3) || defined(_MIPS_ISA_MIPS4) || \
+    defined(__mips) || defined(__MIPS__)
+#define DUK_F_MIPS
+#if defined(__LP64__) || defined(_LP64) || defined(__mips64) || \
+    defined(__mips64__) || defined(__mips_n64)
+#define DUK_F_MIPS64
+#else
+#define DUK_F_MIPS32
+#endif
+#endif
+
+/* SPARC */
+#if defined(sparc) || defined(__sparc) || defined(__sparc__)
+#define DUK_F_SPARC
+#if defined(__LP64__) || defined(_LP64)
+#define DUK_F_SPARC64
+#else
+#define DUK_F_SPARC32
+#endif
+#endif
+
+/* SuperH */
+#if defined(__sh__) || \
+    defined(__sh1__) || defined(__SH1__) || \
+    defined(__sh2__) || defined(__SH2__) || \
+    defined(__sh3__) || defined(__SH3__) || \
+    defined(__sh4__) || defined(__SH4__) || \
+    defined(__sh5__) || defined(__SH5__)
+#define DUK_F_SUPERH
+#endif
+
+/* Clang */
+#if defined(__clang__)
+#define DUK_F_CLANG
+#endif
+
+/* C99 or above */
+#undef DUK_F_C99
+#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
+#define DUK_F_C99
+#endif
+
+/* C++11 or above */
+#undef DUK_F_CPP11
+#if defined(__cplusplus) && (__cplusplus >= 201103L)
+#define DUK_F_CPP11
+#endif
+
+/* GCC.  Clang also defines __GNUC__ so don't detect GCC if using Clang. */
+#if defined(__GNUC__) && !defined(__clang__) && !defined(DUK_F_CLANG)
+#define DUK_F_GCC
+#if defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__)
+/* Convenience, e.g. gcc 4.5.1 == 40501; http://stackoverflow.com/questions/6031819/emulating-gccs-builtin-unreachable */
+#define DUK_F_GCC_VERSION  (__GNUC__ * 10000L + __GNUC_MINOR__ * 100L + __GNUC_PATCHLEVEL__)
+#else
+#error cannot figure out gcc version
+#endif
+#endif
+
+/* MinGW.  Also GCC flags (DUK_F_GCC) are enabled now. */
+#if defined(__MINGW32__) || defined(__MINGW64__)
+#define DUK_F_MINGW
+#endif
+
+/* MSVC */
+#if defined(_MSC_VER)
+/* MSVC preprocessor defines: http://msdn.microsoft.com/en-us/library/b0084kay.aspx
+ * _MSC_FULL_VER includes the build number, but it has at least two formats, see e.g.
+ * BOOST_MSVC_FULL_VER in http://www.boost.org/doc/libs/1_52_0/boost/config/compiler/visualc.hpp
+ */
+#define DUK_F_MSVC
+#if defined(_MSC_FULL_VER)
+#if (_MSC_FULL_VER > 100000000)
+#define DUK_F_MSVC_FULL_VER _MSC_FULL_VER
+#else
+#define DUK_F_MSCV_FULL_VER (_MSC_FULL_VER * 10)
+#endif
+#endif
+#endif  /* _MSC_VER */
+
+/* TinyC */
+#if defined(__TINYC__)
+/* http://bellard.org/tcc/tcc-doc.html#SEC9 */
+#define DUK_F_TINYC
+#endif
+
+/* VBCC */
+#if defined(__VBCC__)
+#define DUK_F_VBCC
+#endif
+
+/* Atari Mint */
+#if defined(__MINT__)
+#define DUK_F_MINT
+#endif
+
+/*
+ *  Platform autodetection
+ */
+
+/* Workaround for older C++ compilers before including <inttypes.h>,
+ * see e.g.: https://sourceware.org/bugzilla/show_bug.cgi?id=15366
+ */
+#if defined(__cplusplus) && !defined(__STDC_LIMIT_MACROS)
+#define __STDC_LIMIT_MACROS
+#endif
+#if defined(__cplusplus) && !defined(__STDC_CONSTANT_MACROS)
+#define __STDC_CONSTANT_MACROS
+#endif
+
+#if defined(DUK_F_APPLE)
+/* --- Mac OSX, iPhone, Darwin --- */
+#define DUK_USE_DATE_NOW_GETTIMEOFDAY
+#define DUK_USE_DATE_TZO_GMTIME_R
+#define DUK_USE_DATE_PRS_STRPTIME
+#define DUK_USE_DATE_FMT_STRFTIME
+#include <TargetConditionals.h>
+#include <architecture/byte_order.h>
+#include <sys/param.h>
+#include <sys/time.h>
+#include <time.h>
+
+/* http://stackoverflow.com/questions/5919996/how-to-detect-reliably-mac-os-x-ios-linux-windows-in-c-preprocessor */
+#if TARGET_IPHONE_SIMULATOR
+#define DUK_USE_OS_STRING "iphone-sim"
+#elif TARGET_OS_IPHONE
+#define DUK_USE_OS_STRING "iphone"
+#elif TARGET_OS_MAC
+#define DUK_USE_OS_STRING "osx"
+#else
+#define DUK_USE_OS_STRING "osx-unknown"
+#endif
+
+/* Use _setjmp() on Apple by default, see GH-55. */
+#define DUK_JMPBUF_TYPE       jmp_buf
+#define DUK_SETJMP(jb)        _setjmp((jb))
+#define DUK_LONGJMP(jb)       _longjmp((jb), 1)
+#elif defined(DUK_F_OPENBSD)
+/* --- OpenBSD --- */
+/* http://www.monkey.org/openbsd/archive/ports/0401/msg00089.html */
+#define DUK_USE_DATE_NOW_GETTIMEOFDAY
+#define DUK_USE_DATE_TZO_GMTIME_R
+#define DUK_USE_DATE_PRS_STRPTIME
+#define DUK_USE_DATE_FMT_STRFTIME
+#include <sys/types.h>
+#include <sys/endian.h>
+#include <sys/param.h>
+#include <sys/time.h>
+#include <time.h>
+
+#define DUK_USE_OS_STRING  "openbsd"
+#elif defined(DUK_F_BSD)
+/* --- Generic BSD --- */
+#define DUK_USE_DATE_NOW_GETTIMEOFDAY
+#define DUK_USE_DATE_TZO_GMTIME_R
+#define DUK_USE_DATE_PRS_STRPTIME
+#define DUK_USE_DATE_FMT_STRFTIME
+#include <sys/types.h>
+#include <sys/endian.h>
+#include <sys/param.h>
+#include <sys/time.h>
+#include <time.h>
+
+#define DUK_USE_OS_STRING  "bsd"
+#elif defined(DUK_F_TOS)
+/* --- Atari ST TOS --- */
+#define DUK_USE_DATE_NOW_TIME
+#define DUK_USE_DATE_TZO_GMTIME
+/* no parsing (not an error) */
+#define DUK_USE_DATE_FMT_STRFTIME
+#include <time.h>
+
+#define DUK_USE_OS_STRING  "tos"
+
+/* TOS on M68K is always big endian. */
+#if !defined(DUK_USE_BYTEORDER) && defined(DUK_F_M68K)
+#define DUK_USE_BYTEORDER 3
+#endif
+#elif defined(DUK_F_AMIGAOS)
+/* --- AmigaOS --- */
+#if defined(DUK_F_M68K)
+/* AmigaOS on M68k */
+#define DUK_USE_DATE_NOW_TIME
+#define DUK_USE_DATE_TZO_GMTIME
+/* no parsing (not an error) */
+#define DUK_USE_DATE_FMT_STRFTIME
+#include <time.h>
+#elif defined(DUK_F_PPC)
+#define DUK_USE_DATE_NOW_GETTIMEOFDAY
+#define DUK_USE_DATE_TZO_GMTIME_R
+#define DUK_USE_DATE_PRS_STRPTIME
+#define DUK_USE_DATE_FMT_STRFTIME
+#include <time.h>
+#ifndef UINTPTR_MAX
+#define UINTPTR_MAX UINT_MAX
+#endif
+#else
+#error AmigaOS but not M68K/PPC, not supported now
+#endif
+
+#define DUK_USE_OS_STRING "amigaos"
+
+/* AmigaOS on M68K or PPC is always big endian. */
+#if !defined(DUK_USE_BYTEORDER) && (defined(DUK_F_M68K) || defined(DUK_F_PPC))
+#define DUK_USE_BYTEORDER 3
+#endif
+#elif defined(DUK_F_WINDOWS)
+/* --- Windows --- */
+/* Initial fix: disable secure CRT related warnings when compiling Duktape
+ * itself (must be defined before including Windows headers).  Don't define
+ * for user code including duktape.h.
+ */
+#if defined(DUK_COMPILING_DUKTAPE) && !defined(_CRT_SECURE_NO_WARNINGS)
+#define _CRT_SECURE_NO_WARNINGS
+#endif
+
+/* Windows 32-bit and 64-bit are currently the same. */
+/* MSVC does not have sys/param.h */
+#define DUK_USE_DATE_NOW_WINDOWS
+#define DUK_USE_DATE_TZO_WINDOWS
+/* Note: PRS and FMT are intentionally left undefined for now.  This means
+ * there is no platform specific date parsing/formatting but there is still
+ * the ISO 8601 standard format.
+ */
+#if defined(DUK_COMPILING_DUKTAPE)
+/* Only include when compiling Duktape to avoid polluting application build
+ * with a lot of unnecessary defines.
+ */
+#include <windows.h>
+#endif
+
+#define DUK_USE_OS_STRING "windows"
+
+/* On Windows, assume we're little endian.  Even Itanium which has a
+ * configurable endianness runs little endian in Windows.
+ */
+#if !defined(DUK_USE_BYTEORDER)
+#define DUK_USE_BYTEORDER 1
+#endif
+#elif defined(DUK_F_FLASHPLAYER)
+/* --- Flashplayer (Crossbridge) --- */
+#define DUK_USE_DATE_NOW_GETTIMEOFDAY
+#define DUK_USE_DATE_TZO_GMTIME_R
+#define DUK_USE_DATE_PRS_STRPTIME
+#define DUK_USE_DATE_FMT_STRFTIME
+#include <endian.h>
+#include <sys/param.h>
+#include <sys/time.h>
+#include <time.h>
+
+#define DUK_USE_OS_STRING "flashplayer"
+
+#if !defined(DUK_USE_BYTEORDER) && defined(DUK_F_FLASHPLAYER)
+#define DUK_USE_BYTEORDER 1
+#endif
+#elif defined(DUK_F_QNX)
+/* --- QNX --- */
+#if defined(DUK_F_QNX) && defined(DUK_COMPILING_DUKTAPE)
+/* See: /opt/qnx650/target/qnx6/usr/include/sys/platform.h */
+#define _XOPEN_SOURCE    600
+#define _POSIX_C_SOURCE  200112L
+#endif
+
+#define DUK_USE_DATE_NOW_GETTIMEOFDAY
+#define DUK_USE_DATE_TZO_GMTIME_R
+#define DUK_USE_DATE_PRS_STRPTIME
+#define DUK_USE_DATE_FMT_STRFTIME
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/time.h>
+#include <time.h>
+
+#define DUK_USE_OS_STRING "qnx"
+#elif defined(DUK_F_TINSPIRE)
+/* --- TI-Nspire --- */
+#define DUK_USE_DATE_NOW_GETTIMEOFDAY
+#define DUK_USE_DATE_TZO_GMTIME_R
+#define DUK_USE_DATE_PRS_STRPTIME
+#define DUK_USE_DATE_FMT_STRFTIME
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/time.h>
+#include <time.h>
+
+#define DUK_USE_OS_STRING "tinspire"
+#elif defined(DUK_F_EMSCRIPTEN)
+/* --- Emscripten --- */
+#if defined(DUK_COMPILING_DUKTAPE)
+#ifndef _POSIX_C_SOURCE
+#define _POSIX_C_SOURCE  200809L
+#endif
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE      /* e.g. getdate_r */
+#endif
+#ifndef _XOPEN_SOURCE
+#define _XOPEN_SOURCE    /* e.g. strptime */
+#endif
+#endif  /* DUK_COMPILING_DUKTAPE */
+
+#include <sys/types.h>
+#if defined(DUK_F_BCC)
+/* no endian.h */
+#else
+#include <endian.h>
+#endif  /* DUK_F_BCC */
+#include <sys/param.h>
+#include <sys/time.h>
+#include <time.h>
+#include <stdint.h>
+
+#define DUK_USE_DATE_NOW_GETTIMEOFDAY
+#define DUK_USE_DATE_TZO_GMTIME_R
+#define DUK_USE_DATE_PRS_STRPTIME
+#define DUK_USE_DATE_FMT_STRFTIME
+
+#define DUK_USE_OS_STRING "emscripten"
+#elif defined(DUK_F_LINUX)
+/* --- Linux --- */
+#if defined(DUK_COMPILING_DUKTAPE)
+#ifndef _POSIX_C_SOURCE
+#define _POSIX_C_SOURCE  200809L
+#endif
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE      /* e.g. getdate_r */
+#endif
+#ifndef _XOPEN_SOURCE
+#define _XOPEN_SOURCE    /* e.g. strptime */
+#endif
+#endif  /* DUK_COMPILING_DUKTAPE */
+
+#include <sys/types.h>
+#if defined(DUK_F_BCC)
+/* no endian.h or stdint.h */
+#else
+#include <endian.h>
+#include <stdint.h>
+#endif  /* DUK_F_BCC */
+#include <sys/param.h>
+#include <sys/time.h>
+#include <time.h>
+
+#define DUK_USE_DATE_NOW_GETTIMEOFDAY
+#define DUK_USE_DATE_TZO_GMTIME_R
+#define DUK_USE_DATE_PRS_STRPTIME
+#define DUK_USE_DATE_FMT_STRFTIME
+
+#define DUK_USE_OS_STRING "linux"
+#elif defined(DUK_F_SUN)
+/* --- Solaris --- */
+#define DUK_USE_DATE_NOW_GETTIMEOFDAY
+#define DUK_USE_DATE_TZO_GMTIME_R
+#define DUK_USE_DATE_PRS_STRPTIME
+#define DUK_USE_DATE_FMT_STRFTIME
+
+#include <sys/types.h>
+#include <ast/endian.h>
+#include <sys/param.h>
+#include <sys/time.h>
+#include <time.h>
+
+#define DUK_USE_OS_STRING "solaris"
+#elif defined(DUK_F_POSIX)
+/* --- Generic POSIX --- */
+#define DUK_USE_DATE_NOW_GETTIMEOFDAY
+#define DUK_USE_DATE_TZO_GMTIME_R
+#define DUK_USE_DATE_PRS_STRPTIME
+#define DUK_USE_DATE_FMT_STRFTIME
+#include <sys/types.h>
+#include <endian.h>
+#include <sys/param.h>
+#include <sys/time.h>
+#include <time.h>
+
+#define DUK_USE_OS_STRING "posix"
+#elif defined(DUK_F_CYGWIN)
+/* --- Cygwin --- */
+/* don't use strptime() for now */
+#define DUK_USE_DATE_NOW_GETTIMEOFDAY
+#define DUK_USE_DATE_TZO_GMTIME_R
+#define DUK_USE_DATE_FMT_STRFTIME
+#include <sys/types.h>
+#include <endian.h>
+#include <sys/param.h>
+#include <sys/time.h>
+#include <time.h>
+
+#define DUK_JMPBUF_TYPE       jmp_buf
+#define DUK_SETJMP(jb)        _setjmp((jb))
+#define DUK_LONGJMP(jb)       _longjmp((jb), 1)
+
+#define DUK_USE_OS_STRING "windows"
+#elif defined(DUK_F_UNIX)
+/* --- Generic UNIX --- */
+#define DUK_USE_DATE_NOW_GETTIMEOFDAY
+#define DUK_USE_DATE_TZO_GMTIME_R
+#define DUK_USE_DATE_PRS_STRPTIME
+#define DUK_USE_DATE_FMT_STRFTIME
+#include <time.h>
+#include <sys/time.h>
+#define DUK_USE_OS_STRING "unknown"
+#else
+/* --- Generic fallback --- */
+/* The most portable current time provider is time(), but it only has a
+ * one second resolution.
+ */
+#define DUK_USE_DATE_NOW_TIME
+
+/* The most portable way to figure out local time offset is gmtime(),
+ * but it's not thread safe so use with caution.
+ */
+#define DUK_USE_DATE_TZO_GMTIME
+
+/* Avoid custom date parsing and formatting for portability. */
+#undef DUK_USE_DATE_PRS_STRPTIME
+#undef DUK_USE_DATE_FMT_STRFTIME
+
+/* Rely on C89 headers only; time.h must be here. */
+#include <time.h>
+
+#define DUK_USE_OS_STRING "unknown"
+#endif  /* autodetect platform */
+
+/* Shared includes: C89 */
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdarg.h>  /* varargs */
+#include <setjmp.h>
+#include <stddef.h>  /* e.g. ptrdiff_t */
+#include <math.h>
+#include <limits.h>
+
+/* date.h is omitted, and included per platform */
+
+/* Shared includes: stdint.h is C99 */
+#if defined(DUK_F_NO_STDINT_H)
+/* stdint.h not available */
+#else
+/* Technically C99 (C++11) but found in many systems.  On some systems
+ * __STDC_LIMIT_MACROS and __STDC_CONSTANT_MACROS must be defined before
+ * including stdint.h (see above).
+ */
+#include <stdint.h>
+#endif
+
+#if defined(DUK_F_CPP)
+#include <exception>  /* std::exception */
+#endif
+
+/*
+ *  Architecture autodetection
+ */
+
+#if defined(DUK_F_X86)
+/* --- x86 --- */
+#define DUK_USE_ARCH_STRING "x86"
+#if !defined(DUK_USE_BYTEORDER)
+#define DUK_USE_BYTEORDER 1
+#endif
+/* XXX: This is technically not guaranteed because it's possible to configure
+ * an x86 to require aligned accesses with Alignment Check (AC) flag.
+ */
+#if !defined(DUK_USE_ALIGN_BY)
+#define DUK_USE_ALIGN_BY 1
+#endif
+#define DUK_USE_PACKED_TVAL
+#define DUK_F_PACKED_TVAL_PROVIDED
+#elif defined(DUK_F_X64)
+/* --- x64 --- */
+#define DUK_USE_ARCH_STRING "x64"
+#if !defined(DUK_USE_BYTEORDER)
+#define DUK_USE_BYTEORDER 1
+#endif
+/* XXX: This is technically not guaranteed because it's possible to configure
+ * an x86 to require aligned accesses with Alignment Check (AC) flag.
+ */
+#if !defined(DUK_USE_ALIGN_BY)
+#define DUK_USE_ALIGN_BY 1
+#endif
+#undef DUK_USE_PACKED_TVAL
+#define DUK_F_PACKED_TVAL_PROVIDED
+#elif defined(DUK_F_X32)
+/* --- x32 --- */
+#define DUK_USE_ARCH_STRING "x32"
+#if !defined(DUK_USE_BYTEORDER)
+#define DUK_USE_BYTEORDER 1
+#endif
+/* XXX: This is technically not guaranteed because it's possible to configure
+ * an x86 to require aligned accesses with Alignment Check (AC) flag.
+ */
+#if !defined(DUK_USE_ALIGN_BY)
+#define DUK_USE_ALIGN_BY 1
+#endif
+#define DUK_USE_PACKED_TVAL
+#define DUK_F_PACKED_TVAL_PROVIDED
+#elif defined(DUK_F_ARM32)
+/* --- ARM 32-bit --- */
+#define DUK_USE_ARCH_STRING "arm32"
+/* Byte order varies, so rely on autodetect. */
+#if !defined(DUK_USE_ALIGN_BY)
+#define DUK_USE_ALIGN_BY 4
+#endif
+#define DUK_USE_PACKED_TVAL
+#define DUK_F_PACKED_TVAL_PROVIDED
+#elif defined(DUK_F_ARM64)
+/* --- ARM 64-bit --- */
+#define DUK_USE_ARCH_STRING "arm64"
+/* Byte order varies, so rely on autodetect. */
+#if !defined(DUK_USE_ALIGN_BY)
+#define DUK_USE_ALIGN_BY 8
+#endif
+#undef DUK_USE_PACKED_TVAL
+#define DUK_F_PACKED_TVAL_PROVIDED
+#elif defined(DUK_F_MIPS32)
+/* --- MIPS 32-bit --- */
+#define DUK_USE_ARCH_STRING "mips32"
+/* MIPS byte order varies so rely on autodetection. */
+/* Based on 'make checkalign' there are no alignment requirements on
+ * Linux MIPS except for doubles, which need align by 4.  Alignment
+ * requirements vary based on target though.
+ */
+#if !defined(DUK_USE_ALIGN_BY)
+#define DUK_USE_ALIGN_BY 4
+#endif
+#define DUK_USE_PACKED_TVAL
+#define DUK_F_PACKED_TVAL_PROVIDED
+#elif defined(DUK_F_MIPS64)
+/* --- MIPS 64-bit --- */
+#define DUK_USE_ARCH_STRING "mips64"
+/* MIPS byte order varies so rely on autodetection. */
+/* Good default is a bit arbitrary because alignment requirements
+ * depend on target.  See https://github.com/svaarala/duktape/issues/102.
+ */
+#if !defined(DUK_USE_ALIGN_BY)
+#define DUK_USE_ALIGN_BY 8
+#endif
+#undef DUK_USE_PACKED_TVAL
+#define DUK_F_PACKED_TVAL_PROVIDED
+#elif defined(DUK_F_PPC32)
+/* --- PowerPC 32-bit --- */
+#define DUK_USE_ARCH_STRING "ppc32"
+#if !defined(DUK_USE_BYTEORDER)
+#define DUK_USE_BYTEORDER 3
+#endif
+#if !defined(DUK_USE_ALIGN_BY)
+#define DUK_USE_ALIGN_BY 8
+#endif
+#define DUK_USE_PACKED_TVAL
+#define DUK_F_PACKED_TVAL_PROVIDED
+#elif defined(DUK_F_PPC64)
+/* --- PowerPC 64-bit --- */
+#define DUK_USE_ARCH_STRING "ppc64"
+#if !defined(DUK_USE_BYTEORDER)
+#define DUK_USE_BYTEORDER 3
+#endif
+#if !defined(DUK_USE_ALIGN_BY)
+#define DUK_USE_ALIGN_BY 8
+#endif
+#undef DUK_USE_PACKED_TVAL
+#define DUK_F_PACKED_TVAL_PROVIDED
+#elif defined(DUK_F_SPARC32)
+/* --- SPARC 32-bit --- */
+#define DUK_USE_ARCH_STRING "sparc32"
+/* SPARC byte order varies so rely on autodetection. */
+#if !defined(DUK_USE_ALIGN_BY)
+#define DUK_USE_ALIGN_BY 8
+#endif
+#define DUK_USE_PACKED_TVAL
+#define DUK_F_PACKED_TVAL_PROVIDED
+#elif defined(DUK_F_SPARC64)
+/* --- SPARC 64-bit --- */
+#define DUK_USE_ARCH_STRING "sparc64"
+/* SPARC byte order varies so rely on autodetection. */
+#if !defined(DUK_USE_ALIGN_BY)
+#define DUK_USE_ALIGN_BY 8
+#endif
+#undef DUK_USE_PACKED_TVAL
+#define DUK_F_PACKED_TVAL_PROVIDED
+#elif defined(DUK_F_SUPERH)
+/* --- SuperH --- */
+#define DUK_USE_ARCH_STRING "sh"
+/* Byte order varies, rely on autodetection. */
+/* Based on 'make checkalign' there are no alignment requirements on
+ * Linux SH4, but align by 4 is probably a good basic default.
+ */
+#if !defined(DUK_USE_ALIGN_BY)
+#define DUK_USE_ALIGN_BY 4
+#endif
+#define DUK_USE_PACKED_TVAL
+#define DUK_F_PACKED_TVAL_PROVIDED
+#elif defined(DUK_F_M68K)
+/* --- Motorola 68k --- */
+#define DUK_USE_ARCH_STRING "m68k"
+#if !defined(DUK_USE_BYTEORDER)
+#define DUK_USE_BYTEORDER 3
+#endif
+#if !defined(DUK_USE_ALIGN_BY)
+#define DUK_USE_ALIGN_BY 8
+#endif
+#define DUK_USE_PACKED_TVAL
+#define DUK_F_PACKED_TVAL_PROVIDED
+#elif defined(DUK_F_EMSCRIPTEN)
+/* --- Emscripten --- */
+#define DUK_USE_ARCH_STRING "emscripten"
+#if !defined(DUK_USE_BYTEORDER)
+#define DUK_USE_BYTEORDER 1
+#endif
+#if !defined(DUK_USE_ALIGN_BY)
+#define DUK_USE_ALIGN_BY 8
+#endif
+#undef DUK_USE_PACKED_TVAL
+#define DUK_F_PACKED_TVAL_PROVIDED
+#else
+/* --- Generic --- */
+/* These are necessary wild guesses. */
+#define DUK_USE_ARCH_STRING "generic"
+/* Rely on autodetection for byte order, alignment, and packed tval. */
+#endif  /* autodetect architecture */
+
+/*
+ *  Compiler autodetection
+ */
+
+#if defined(DUK_F_CLANG)
+/* --- Clang --- */
+#if defined(DUK_F_C99) || defined(DUK_F_CPP11)
+/* C99 / C++11 and above: rely on va_copy() which is required. */
+#define DUK_VA_COPY(dest,src) va_copy(dest,src)
+#else
+/* Clang: assume we have __va_copy() in non-C99 mode. */
+#define DUK_VA_COPY(dest,src) __va_copy(dest,src)
+#endif
+
+#define DUK_NORETURN(decl)  decl __attribute__((noreturn))
+
+#if defined(__clang__) && defined(__has_builtin)
+#if __has_builtin(__builtin_unreachable)
+#define DUK_UNREACHABLE()  do { __builtin_unreachable(); } while (0)
+#endif
+#endif
+
+#define DUK_USE_BRANCH_HINTS
+#define DUK_LIKELY(x)    __builtin_expect((x), 1)
+#define DUK_UNLIKELY(x)  __builtin_expect((x), 0)
+
+#if defined(DUK_F_C99) || defined(DUK_F_CPP11)
+#define DUK_NOINLINE        __attribute__((noinline))
+#define DUK_INLINE          inline
+#define DUK_ALWAYS_INLINE   inline __attribute__((always_inline))
+#endif
+
+#if defined(DUK_F_DLL_BUILD) && defined(DUK_F_WINDOWS)
+/* MSVC dllexport/dllimport: appropriate __declspec depends on whether we're
+ * compiling Duktape or the application.
+ */
+#if defined(DUK_COMPILING_DUKTAPE)
+#define DUK_EXTERNAL_DECL  extern __declspec(dllexport)
+#define DUK_EXTERNAL       __declspec(dllexport)
+#else
+#define DUK_EXTERNAL_DECL  extern __declspec(dllimport)
+#define DUK_EXTERNAL       should_not_happen
+#endif
+#if defined(DUK_SINGLE_FILE)
+#define DUK_INTERNAL_DECL  static
+#define DUK_INTERNAL       static
+#else
+#define DUK_INTERNAL_DECL  extern
+#define DUK_INTERNAL       /*empty*/
+#endif
+#define DUK_LOCAL_DECL     static
+#define DUK_LOCAL          static
+#else
+#define DUK_EXTERNAL_DECL  __attribute__ ((visibility("default"))) extern
+#define DUK_EXTERNAL       __attribute__ ((visibility("default")))
+#if defined(DUK_SINGLE_FILE)
+#if (defined(DUK_F_GCC_VERSION) && DUK_F_GCC_VERSION >= 30101) || defined(DUK_F_CLANG)
+/* Minimize warnings for unused internal functions with GCC >= 3.1.1 and
+ * Clang.  Based on documentation it should suffice to have the attribute
+ * in the declaration only, but in practice some warnings are generated unless
+ * the attribute is also applied to the definition.
+ */
+#define DUK_INTERNAL_DECL  static __attribute__ ((unused))
+#define DUK_INTERNAL       static __attribute__ ((unused))
+#else
+#define DUK_INTERNAL_DECL  static
+#define DUK_INTERNAL       static
+#endif
+#else
+#if (defined(DUK_F_GCC_VERSION) && DUK_F_GCC_VERSION >= 30101) || defined(DUK_F_CLANG)
+#define DUK_INTERNAL_DECL  __attribute__ ((visibility("hidden"))) __attribute__ ((unused)) extern
+#define DUK_INTERNAL       __attribute__ ((visibility("hidden"))) __attribute__ ((unused))
+#else
+#define DUK_INTERNAL_DECL  __attribute__ ((visibility("hidden"))) extern
+#define DUK_INTERNAL       __attribute__ ((visibility("hidden")))
+#endif
+#endif
+#define DUK_LOCAL_DECL     static
+#define DUK_LOCAL          static
+#endif
+
+#if defined(DUK_F_CPP)
+#define DUK_USE_COMPILER_STRING "clang"
+#else
+#define DUK_USE_COMPILER_STRING "clang"
+#endif
+
+#undef DUK_USE_VARIADIC_MACROS
+#if defined(DUK_F_C99) || defined(DUK_F_CPP11)
+#define DUK_USE_VARIADIC_MACROS
+#endif
+
+#define DUK_USE_UNION_INITIALIZERS
+
+#undef DUK_USE_FLEX_C99
+#undef DUK_USE_FLEX_ZEROSIZE
+#undef DUK_USE_FLEX_ONESIZE
+#if defined(DUK_F_C99)
+#define DUK_USE_FLEX_C99
+#else
+#define DUK_USE_FLEX_ZEROSIZE
+#endif
+
+#undef DUK_USE_GCC_PRAGMAS
+#define DUK_USE_PACK_CLANG_ATTR
+#elif defined(DUK_F_GCC)
+/* --- GCC --- */
+#if defined(DUK_F_C99) || defined(DUK_F_CPP11)
+/* C99 / C++11 and above: rely on va_copy() which is required. */
+#define DUK_VA_COPY(dest,src) va_copy(dest,src)
+#else
+/* GCC: assume we have __va_copy() in non-C99 mode. */
+#define DUK_VA_COPY(dest,src) __va_copy(dest,src)
+#endif
+
+#if defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION >= 20500L)
+/* since gcc-2.5 */
+#define DUK_NORETURN(decl)  decl __attribute__((noreturn))
+#endif
+
+#if defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION >= 40500L)
+/* since gcc-4.5 */
+#define DUK_UNREACHABLE()  do { __builtin_unreachable(); } while (0)
+#endif
+
+#define DUK_USE_BRANCH_HINTS
+#if defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION >= 40500L)
+/* GCC: test not very accurate; enable only in relatively recent builds
+ * because of bugs in gcc-4.4 (http://lists.debian.org/debian-gcc/2010/04/msg00000.html)
+ */
+#define DUK_LIKELY(x)    __builtin_expect((x), 1)
+#define DUK_UNLIKELY(x)  __builtin_expect((x), 0)
+#endif
+
+#if (defined(DUK_F_C99) || defined(DUK_F_CPP11)) && \
+    defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION >= 30101)
+#define DUK_NOINLINE        __attribute__((noinline))
+#define DUK_INLINE          inline
+#define DUK_ALWAYS_INLINE   inline __attribute__((always_inline))
+#endif
+
+#if defined(DUK_F_DLL_BUILD) && defined(DUK_F_WINDOWS)
+/* MSVC dllexport/dllimport: appropriate __declspec depends on whether we're
+ * compiling Duktape or the application.
+ */
+#if defined(DUK_COMPILING_DUKTAPE)
+#define DUK_EXTERNAL_DECL  extern __declspec(dllexport)
+#define DUK_EXTERNAL       __declspec(dllexport)
+#else
+#define DUK_EXTERNAL_DECL  extern __declspec(dllimport)
+#define DUK_EXTERNAL       should_not_happen
+#endif
+#if defined(DUK_SINGLE_FILE)
+#define DUK_INTERNAL_DECL  static
+#define DUK_INTERNAL       static
+#else
+#define DUK_INTERNAL_DECL  extern
+#define DUK_INTERNAL       /*empty*/
+#endif
+#define DUK_LOCAL_DECL     static
+#define DUK_LOCAL          static
+#elif defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION >= 40000)
+#define DUK_EXTERNAL_DECL  __attribute__ ((visibility("default"))) extern
+#define DUK_EXTERNAL       __attribute__ ((visibility("default")))
+#if defined(DUK_SINGLE_FILE)
+#if (defined(DUK_F_GCC_VERSION) && DUK_F_GCC_VERSION >= 30101) || defined(DUK_F_CLANG)
+/* Minimize warnings for unused internal functions with GCC >= 3.1.1 and
+ * Clang.  Based on documentation it should suffice to have the attribute
+ * in the declaration only, but in practice some warnings are generated unless
+ * the attribute is also applied to the definition.
+ */
+#define DUK_INTERNAL_DECL  static __attribute__ ((unused))
+#define DUK_INTERNAL       static __attribute__ ((unused))
+#else
+#define DUK_INTERNAL_DECL  static
+#define DUK_INTERNAL       static
+#endif
+#else
+#if (defined(DUK_F_GCC_VERSION) && DUK_F_GCC_VERSION >= 30101) || defined(DUK_F_CLANG)
+#define DUK_INTERNAL_DECL  __attribute__ ((visibility("hidden"))) __attribute__ ((unused)) extern
+#define DUK_INTERNAL       __attribute__ ((visibility("hidden"))) __attribute__ ((unused))
+#else
+#define DUK_INTERNAL_DECL  __attribute__ ((visibility("hidden"))) extern
+#define DUK_INTERNAL       __attribute__ ((visibility("hidden")))
+#endif
+#endif
+#define DUK_LOCAL_DECL     static
+#define DUK_LOCAL          static
+#endif
+
+#if defined(DUK_F_MINGW)
+#if defined(DUK_F_CPP)
+#define DUK_USE_COMPILER_STRING "mingw++"
+#else
+#define DUK_USE_COMPILER_STRING "mingw"
+#endif
+#else
+#if defined(DUK_F_CPP)
+#define DUK_USE_COMPILER_STRING "g++"
+#else
+#define DUK_USE_COMPILER_STRING "gcc"
+#endif
+#endif
+
+#undef DUK_USE_VARIADIC_MACROS
+#if defined(DUK_F_C99) || (defined(DUK_F_CPP11) && defined(__GNUC__))
+#define DUK_USE_VARIADIC_MACROS
+#endif
+
+#define DUK_USE_UNION_INITIALIZERS
+
+#undef DUK_USE_FLEX_C99
+#undef DUK_USE_FLEX_ZEROSIZE
+#undef DUK_USE_FLEX_ONESIZE
+#if defined(DUK_F_C99)
+#define DUK_USE_FLEX_C99
+#else
+#define DUK_USE_FLEX_ZEROSIZE
+#endif
+
+#if defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION >= 40600)
+#define DUK_USE_GCC_PRAGMAS
+#else
+#undef DUK_USE_GCC_PRAGMAS
+#endif
+
+#define DUK_USE_PACK_GCC_ATTR
+#elif defined(DUK_F_MSVC)
+/* --- MSVC --- */
+/* http://msdn.microsoft.com/en-us/library/aa235362(VS.60).aspx */
+#define DUK_NORETURN(decl)  __declspec(noreturn) decl
+
+/* XXX: DUK_UNREACHABLE for msvc? */
+
+#undef DUK_USE_BRANCH_HINTS
+
+/* XXX: DUK_LIKELY, DUK_UNLIKELY for msvc? */
+/* XXX: DUK_NOINLINE, DUK_INLINE, DUK_ALWAYS_INLINE for msvc? */
+
+#if defined(DUK_F_DLL_BUILD) && defined(DUK_F_WINDOWS)
+/* MSVC dllexport/dllimport: appropriate __declspec depends on whether we're
+ * compiling Duktape or the application.
+ */
+#if defined(DUK_COMPILING_DUKTAPE)
+#define DUK_EXTERNAL_DECL  extern __declspec(dllexport)
+#define DUK_EXTERNAL       __declspec(dllexport)
+#else
+#define DUK_EXTERNAL_DECL  extern __declspec(dllimport)
+#define DUK_EXTERNAL       should_not_happen
+#endif
+#if defined(DUK_SINGLE_FILE)
+#define DUK_INTERNAL_DECL  static
+#define DUK_INTERNAL       static
+#else
+#define DUK_INTERNAL_DECL  extern
+#define DUK_INTERNAL       /*empty*/
+#endif
+#define DUK_LOCAL_DECL     static
+#define DUK_LOCAL          static
+#endif
+
+#if defined(DUK_F_CPP)
+#define DUK_USE_COMPILER_STRING "msvc++"
+#else
+#define DUK_USE_COMPILER_STRING "msvc"
+#endif
+
+#undef DUK_USE_VARIADIC_MACROS
+#if defined(DUK_F_C99)
+#define DUK_USE_VARIADIC_MACROS
+#elif defined(_MSC_VER) && (_MSC_VER >= 1400)
+/* VS2005+ should have variadic macros even when they're not C99. */
+#define DUK_USE_VARIADIC_MACROS
+#endif
+
+#undef DUK_USE_UNION_INITIALIZERS
+#if defined(_MSC_VER) && (_MSC_VER >= 1800)
+/* VS2013+ supports union initializers but there's a bug involving union-inside-struct:
+ * https://connect.microsoft.com/VisualStudio/feedback/details/805981
+ * The bug was fixed (at least) in VS2015 so check for VS2015 for now:
+ * https://blogs.msdn.microsoft.com/vcblog/2015/07/01/c-compiler-front-end-fixes-in-vs2015/
+ * Manually tested using VS2013, CL reports 18.00.31101, so enable for VS2013 too.
+ */
+#define DUK_USE_UNION_INITIALIZERS
+#endif
+
+#undef DUK_USE_FLEX_C99
+#undef DUK_USE_FLEX_ZEROSIZE
+#undef DUK_USE_FLEX_ONESIZE
+#if defined(DUK_F_C99)
+#define DUK_USE_FLEX_C99
+#else
+#define DUK_USE_FLEX_ZEROSIZE
+#endif
+
+#undef DUK_USE_GCC_PRAGMAS
+
+#define DUK_USE_PACK_MSVC_PRAGMA
+
+/* These have been tested from VS2008 onwards; may work in older VS versions
+ * too but not enabled by default.
+ */
+#if defined(_MSC_VER) && (_MSC_VER >= 1500)
+#define DUK_NOINLINE        __declspec(noinline)
+#define DUK_INLINE          __inline
+#define DUK_ALWAYS_INLINE   __forceinline
+#endif
+
+#if defined(_MSC_VER) && (_MSC_VER >= 1900)
+#define DUK_SNPRINTF     snprintf
+#define DUK_VSNPRINTF    vsnprintf
+#else
+/* (v)snprintf() is missing before MSVC 2015.  Note that _(v)snprintf() does
+ * NOT NUL terminate on truncation, but Duktape code never assumes that.
+ * http://stackoverflow.com/questions/2915672/snprintf-and-visual-studio-2010
+ */
+#define DUK_SNPRINTF     _snprintf
+#define DUK_VSNPRINTF    _vsnprintf
+#endif
+#elif defined(DUK_F_EMSCRIPTEN)
+/* --- Emscripten --- */
+#define DUK_NORETURN(decl)  decl __attribute__((noreturn))
+
+#if defined(__clang__) && defined(__has_builtin)
+#if __has_builtin(__builtin_unreachable)
+#define DUK_UNREACHABLE()  do { __builtin_unreachable(); } while (0)
+#endif
+#endif
+
+#define DUK_USE_BRANCH_HINTS
+#define DUK_LIKELY(x)    __builtin_expect((x), 1)
+#define DUK_UNLIKELY(x)  __builtin_expect((x), 0)
+
+#if defined(DUK_F_C99) || defined(DUK_F_CPP11)
+#define DUK_NOINLINE        __attribute__((noinline))
+#define DUK_INLINE          inline
+#define DUK_ALWAYS_INLINE   inline __attribute__((always_inline))
+#endif
+
+#define DUK_EXTERNAL_DECL  __attribute__ ((visibility("default"))) extern
+#define DUK_EXTERNAL       __attribute__ ((visibility("default")))
+#if defined(DUK_SINGLE_FILE)
+#if (defined(DUK_F_GCC_VERSION) && DUK_F_GCC_VERSION >= 30101) || defined(DUK_F_CLANG)
+/* Minimize warnings for unused internal functions with GCC >= 3.1.1 and
+ * Clang.  Based on documentation it should suffice to have the attribute
+ * in the declaration only, but in practice some warnings are generated unless
+ * the attribute is also applied to the definition.
+ */
+#define DUK_INTERNAL_DECL  static __attribute__ ((unused))
+#define DUK_INTERNAL       static __attribute__ ((unused))
+#else
+#define DUK_INTERNAL_DECL  static
+#define DUK_INTERNAL       static
+#endif
+#else
+#if (defined(DUK_F_GCC_VERSION) && DUK_F_GCC_VERSION >= 30101) || defined(DUK_F_CLANG)
+#define DUK_INTERNAL_DECL  __attribute__ ((visibility("hidden"))) __attribute__ ((unused)) extern
+#define DUK_INTERNAL       __attribute__ ((visibility("hidden"))) __attribute__ ((unused))
+#else
+#define DUK_INTERNAL_DECL  __attribute__ ((visibility("hidden"))) extern
+#define DUK_INTERNAL       __attribute__ ((visibility("hidden")))
+#endif
+#endif
+#define DUK_LOCAL_DECL     static
+#define DUK_LOCAL          static
+
+#define DUK_USE_COMPILER_STRING "emscripten"
+
+#undef DUK_USE_VARIADIC_MACROS
+#if defined(DUK_F_C99) || defined(DUK_F_CPP11)
+#define DUK_USE_VARIADIC_MACROS
+#endif
+
+#define DUK_USE_UNION_INITIALIZERS
+
+#undef DUK_USE_FLEX_C99
+#undef DUK_USE_FLEX_ZEROSIZE
+#undef DUK_USE_FLEX_ONESIZE
+#if defined(DUK_F_C99)
+#define DUK_USE_FLEX_C99
+#else
+#define DUK_USE_FLEX_ZEROSIZE
+#endif
+
+#undef DUK_USE_GCC_PRAGMAS
+#define DUK_USE_PACK_CLANG_ATTR
+#elif defined(DUK_F_TINYC)
+/* --- TinyC --- */
+#undef DUK_USE_BRANCH_HINTS
+
+#if defined(DUK_F_CPP)
+#define DUK_USE_COMPILER_STRING "tinyc++"
+#else
+#define DUK_USE_COMPILER_STRING "tinyc"
+#endif
+
+/* http://bellard.org/tcc/tcc-doc.html#SEC7 */
+#define DUK_USE_VARIADIC_MACROS
+
+#define DUK_USE_UNION_INITIALIZERS
+
+/* Most portable, wastes space */
+#define DUK_USE_FLEX_ONESIZE
+
+/* Most portable, potentially wastes space */
+#define DUK_USE_PACK_DUMMY_MEMBER
+#elif defined(DUK_F_VBCC)
+/* --- VBCC --- */
+#undef DUK_USE_BRANCH_HINTS
+
+#if defined(DUK_F_CPP)
+#define DUK_USE_COMPILER_STRING "vbcc-c++"
+#else
+#define DUK_USE_COMPILER_STRING "vbcc"
+#endif
+
+#undef DUK_USE_VARIADIC_MACROS
+#if defined(DUK_F_C99) || defined(DUK_F_CPP11)
+#define DUK_USE_VARIADIC_MACROS
+#endif
+
+/* VBCC supports C99 so check only for C99 for union initializer support.
+ * Designated union initializers would possibly work even without a C99 check.
+ */
+#undef DUK_USE_UNION_INITIALIZERS
+#if defined(DUK_F_C99)
+#define DUK_USE_UNION_INITIALIZERS
+#endif
+
+#define DUK_USE_FLEX_ZEROSIZE
+#define DUK_USE_PACK_DUMMY_MEMBER
+#elif defined(DUK_F_BCC)
+/* --- Bruce's C compiler --- */
+#undef DUK_USE_BRANCH_HINTS
+
+#if defined(DUK_F_CPP)
+#define DUK_USE_COMPILER_STRING "bcc++"
+#else
+#define DUK_USE_COMPILER_STRING "bcc"
+#endif
+
+/* Most portable */
+#undef DUK_USE_VARIADIC_MACROS
+
+/* Most portable, wastes space */
+#undef DUK_USE_UNION_INITIALIZERS
+
+/* Most portable, wastes space */
+#define DUK_USE_FLEX_ONESIZE
+
+/* Most portable, potentially wastes space */
+#define DUK_USE_PACK_DUMMY_MEMBER
+
+/* BCC, assume we're on x86. */
+#if !defined(DUK_USE_BYTEORDER)
+#define DUK_USE_BYTEORDER 1
+#endif
+#else
+/* --- Generic --- */
+#undef DUK_USE_BRANCH_HINTS
+
+#if defined(DUK_F_CPP)
+#define DUK_USE_COMPILER_STRING "generic-c++"
+#else
+#define DUK_USE_COMPILER_STRING "generic"
+#endif
+
+#undef DUK_USE_VARIADIC_MACROS
+#if defined(DUK_F_C99) || defined(DUK_F_CPP11)
+#define DUK_USE_VARIADIC_MACROS
+#endif
+
+/* C++ doesn't have standard designated union initializers ({ .foo = 1 }). */
+#undef DUK_USE_UNION_INITIALIZERS
+#if defined(DUK_F_C99)
+#define DUK_USE_UNION_INITIALIZERS
+#endif
+
+/* Most portable, wastes space */
+#define DUK_USE_FLEX_ONESIZE
+
+/* Most portable, potentially wastes space */
+#define DUK_USE_PACK_DUMMY_MEMBER
+#endif  /* autodetect compiler */
+
+/* uclibc */
+#if defined(__UCLIBC__)
+#define DUK_F_UCLIBC
+#endif
+
+/*
+ *  Wrapper typedefs and constants for integer types, also sanity check types.
+ *
+ *  C99 typedefs are quite good but not always available, and we want to avoid
+ *  forcibly redefining the C99 typedefs.  So, there are Duktape wrappers for
+ *  all C99 typedefs and Duktape code should only use these typedefs.  Type
+ *  detection when C99 is not supported is best effort and may end up detecting
+ *  some types incorrectly.
+ *
+ *  Pointer sizes are a portability problem: pointers to different types may
+ *  have a different size and function pointers are very difficult to manage
+ *  portably.
+ *
+ *  http://en.wikipedia.org/wiki/C_data_types#Fixed-width_integer_types
+ *
+ *  Note: there's an interesting corner case when trying to define minimum
+ *  signed integer value constants which leads to the current workaround of
+ *  defining e.g. -0x80000000 as (-0x7fffffffL - 1L).  See doc/code-issues.txt
+ *  for a longer discussion.
+ *
+ *  Note: avoid typecasts and computations in macro integer constants as they
+ *  can then no longer be used in macro relational expressions (such as
+ *  #if DUK_SIZE_MAX < 0xffffffffUL).  There is internal code which relies on
+ *  being able to compare DUK_SIZE_MAX against a limit.
+ */
+
+/* XXX: add feature options to force basic types from outside? */
+
+#if !defined(INT_MAX)
+#error INT_MAX not defined
+#endif
+
+/* Check that architecture is two's complement, standard C allows e.g.
+ * INT_MIN to be -2**31+1 (instead of -2**31).
+ */
+#if defined(INT_MAX) && defined(INT_MIN)
+#if INT_MAX != -(INT_MIN + 1)
+#error platform does not seem complement of two
+#endif
+#else
+#error cannot check complement of two
+#endif
+
+/* Pointer size determination based on __WORDSIZE or architecture when
+ * that's not available.
+ */
+#if defined(DUK_F_X86) || defined(DUK_F_X32) || \
+    defined(DUK_F_M68K) || defined(DUK_F_PPC32) || \
+    defined(DUK_F_BCC) || \
+    (defined(__WORDSIZE) && (__WORDSIZE == 32))
+#define DUK_F_32BIT_PTRS
+#elif defined(DUK_F_X64) || \
+      (defined(__WORDSIZE) && (__WORDSIZE == 64))
+#define DUK_F_64BIT_PTRS
+#else
+/* not sure, not needed with C99 anyway */
+#endif
+
+/* Intermediate define for 'have inttypes.h' */
+#undef DUK_F_HAVE_INTTYPES
+#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && \
+    !(defined(DUK_F_AMIGAOS) && defined(DUK_F_VBCC))
+/* vbcc + AmigaOS has C99 but no inttypes.h */
+#define DUK_F_HAVE_INTTYPES
+#elif defined(__cplusplus) && (__cplusplus >= 201103L)
+/* C++11 apparently ratified stdint.h */
+#define DUK_F_HAVE_INTTYPES
+#endif
+
+/* Basic integer typedefs and limits, preferably from inttypes.h, otherwise
+ * through automatic detection.
+ */
+#if defined(DUK_F_HAVE_INTTYPES)
+/* C99 or compatible */
+
+#define DUK_F_HAVE_64BIT
+#include <inttypes.h>
+
+typedef uint8_t duk_uint8_t;
+typedef int8_t duk_int8_t;
+typedef uint16_t duk_uint16_t;
+typedef int16_t duk_int16_t;
+typedef uint32_t duk_uint32_t;
+typedef int32_t duk_int32_t;
+typedef uint64_t duk_uint64_t;
+typedef int64_t duk_int64_t;
+typedef uint_least8_t duk_uint_least8_t;
+typedef int_least8_t duk_int_least8_t;
+typedef uint_least16_t duk_uint_least16_t;
+typedef int_least16_t duk_int_least16_t;
+typedef uint_least32_t duk_uint_least32_t;
+typedef int_least32_t duk_int_least32_t;
+typedef uint_least64_t duk_uint_least64_t;
+typedef int_least64_t duk_int_least64_t;
+typedef uint_fast8_t duk_uint_fast8_t;
+typedef int_fast8_t duk_int_fast8_t;
+typedef uint_fast16_t duk_uint_fast16_t;
+typedef int_fast16_t duk_int_fast16_t;
+typedef uint_fast32_t duk_uint_fast32_t;
+typedef int_fast32_t duk_int_fast32_t;
+typedef uint_fast64_t duk_uint_fast64_t;
+typedef int_fast64_t duk_int_fast64_t;
+typedef uintptr_t duk_uintptr_t;
+typedef intptr_t duk_intptr_t;
+typedef uintmax_t duk_uintmax_t;
+typedef intmax_t duk_intmax_t;
+
+#define DUK_UINT8_MIN         0
+#define DUK_UINT8_MAX         UINT8_MAX
+#define DUK_INT8_MIN          INT8_MIN
+#define DUK_INT8_MAX          INT8_MAX
+#define DUK_UINT_LEAST8_MIN   0
+#define DUK_UINT_LEAST8_MAX   UINT_LEAST8_MAX
+#define DUK_INT_LEAST8_MIN    INT_LEAST8_MIN
+#define DUK_INT_LEAST8_MAX    INT_LEAST8_MAX
+#define DUK_UINT_FAST8_MIN    0
+#define DUK_UINT_FAST8_MAX    UINT_FAST8_MAX
+#define DUK_INT_FAST8_MIN     INT_FAST8_MIN
+#define DUK_INT_FAST8_MAX     INT_FAST8_MAX
+#define DUK_UINT16_MIN        0
+#define DUK_UINT16_MAX        UINT16_MAX
+#define DUK_INT16_MIN         INT16_MIN
+#define DUK_INT16_MAX         INT16_MAX
+#define DUK_UINT_LEAST16_MIN  0
+#define DUK_UINT_LEAST16_MAX  UINT_LEAST16_MAX
+#define DUK_INT_LEAST16_MIN   INT_LEAST16_MIN
+#define DUK_INT_LEAST16_MAX   INT_LEAST16_MAX
+#define DUK_UINT_FAST16_MIN   0
+#define DUK_UINT_FAST16_MAX   UINT_FAST16_MAX
+#define DUK_INT_FAST16_MIN    INT_FAST16_MIN
+#define DUK_INT_FAST16_MAX    INT_FAST16_MAX
+#define DUK_UINT32_MIN        0
+#define DUK_UINT32_MAX        UINT32_MAX
+#define DUK_INT32_MIN         INT32_MIN
+#define DUK_INT32_MAX         INT32_MAX
+#define DUK_UINT_LEAST32_MIN  0
+#define DUK_UINT_LEAST32_MAX  UINT_LEAST32_MAX
+#define DUK_INT_LEAST32_MIN   INT_LEAST32_MIN
+#define DUK_INT_LEAST32_MAX   INT_LEAST32_MAX
+#define DUK_UINT_FAST32_MIN   0
+#define DUK_UINT_FAST32_MAX   UINT_FAST32_MAX
+#define DUK_INT_FAST32_MIN    INT_FAST32_MIN
+#define DUK_INT_FAST32_MAX    INT_FAST32_MAX
+#define DUK_UINT64_MIN        0
+#define DUK_UINT64_MAX        UINT64_MAX
+#define DUK_INT64_MIN         INT64_MIN
+#define DUK_INT64_MAX         INT64_MAX
+#define DUK_UINT_LEAST64_MIN  0
+#define DUK_UINT_LEAST64_MAX  UINT_LEAST64_MAX
+#define DUK_INT_LEAST64_MIN   INT_LEAST64_MIN
+#define DUK_INT_LEAST64_MAX   INT_LEAST64_MAX
+#define DUK_UINT_FAST64_MIN   0
+#define DUK_UINT_FAST64_MAX   UINT_FAST64_MAX
+#define DUK_INT_FAST64_MIN    INT_FAST64_MIN
+#define DUK_INT_FAST64_MAX    INT_FAST64_MAX
+
+#define DUK_UINTPTR_MIN       0
+#define DUK_UINTPTR_MAX       UINTPTR_MAX
+#define DUK_INTPTR_MIN        INTPTR_MIN
+#define DUK_INTPTR_MAX        INTPTR_MAX
+
+#define DUK_UINTMAX_MIN       0
+#define DUK_UINTMAX_MAX       UINTMAX_MAX
+#define DUK_INTMAX_MIN        INTMAX_MIN
+#define DUK_INTMAX_MAX        INTMAX_MAX
+
+#define DUK_SIZE_MIN          0
+#define DUK_SIZE_MAX          SIZE_MAX
+#undef DUK_SIZE_MAX_COMPUTED
+
+#else  /* C99 types */
+
+/* When C99 types are not available, we use heuristic detection to get
+ * the basic 8, 16, 32, and (possibly) 64 bit types.  The fast/least
+ * types are then assumed to be exactly the same for now: these could
+ * be improved per platform but C99 types are very often now available.
+ * 64-bit types are not available on all platforms; this is OK at least
+ * on 32-bit platforms.
+ *
+ * This detection code is necessarily a bit hacky and can provide typedefs
+ * and defines that won't work correctly on some exotic platform.
+ */
+
+#if (defined(CHAR_BIT) && (CHAR_BIT == 8)) || \
+    (defined(UCHAR_MAX) && (UCHAR_MAX == 255))
+typedef unsigned char duk_uint8_t;
+typedef signed char duk_int8_t;
+#else
+#error cannot detect 8-bit type
+#endif
+
+#if defined(USHRT_MAX) && (USHRT_MAX == 65535UL)
+typedef unsigned short duk_uint16_t;
+typedef signed short duk_int16_t;
+#elif defined(UINT_MAX) && (UINT_MAX == 65535UL)
+/* On some platforms int is 16-bit but long is 32-bit (e.g. PureC) */
+typedef unsigned int duk_uint16_t;
+typedef signed int duk_int16_t;
+#else
+#error cannot detect 16-bit type
+#endif
+
+#if defined(UINT_MAX) && (UINT_MAX == 4294967295UL)
+typedef unsigned int duk_uint32_t;
+typedef signed int duk_int32_t;
+#elif defined(ULONG_MAX) && (ULONG_MAX == 4294967295UL)
+/* On some platforms int is 16-bit but long is 32-bit (e.g. PureC) */
+typedef unsigned long duk_uint32_t;
+typedef signed long duk_int32_t;
+#else
+#error cannot detect 32-bit type
+#endif
+
+/* 64-bit type detection is a bit tricky.
+ *
+ * ULLONG_MAX is a standard define.  __LONG_LONG_MAX__ and __ULONG_LONG_MAX__
+ * are used by at least GCC (even if system headers don't provide ULLONG_MAX).
+ * Some GCC variants may provide __LONG_LONG_MAX__ but not __ULONG_LONG_MAX__.
+ *
+ * ULL / LL constants are rejected / warned about by some compilers, even if
+ * the compiler has a 64-bit type and the compiler/system headers provide an
+ * unsupported constant (ULL/LL)!  Try to avoid using ULL / LL constants.
+ * As a side effect we can only check that e.g. ULONG_MAX is larger than 32
+ * bits but can't be sure it is exactly 64 bits.  Self tests will catch such
+ * cases.
+ */
+#undef DUK_F_HAVE_64BIT
+#if !defined(DUK_F_HAVE_64BIT) && defined(ULONG_MAX)
+#if (ULONG_MAX > 4294967295UL)
+#define DUK_F_HAVE_64BIT
+typedef unsigned long duk_uint64_t;
+typedef signed long duk_int64_t;
+#endif
+#endif
+#if !defined(DUK_F_HAVE_64BIT) && defined(ULLONG_MAX)
+#if (ULLONG_MAX > 4294967295UL)
+#define DUK_F_HAVE_64BIT
+typedef unsigned long long duk_uint64_t;
+typedef signed long long duk_int64_t;
+#endif
+#endif
+#if !defined(DUK_F_HAVE_64BIT) && defined(__ULONG_LONG_MAX__)
+#if (__ULONG_LONG_MAX__ > 4294967295UL)
+#define DUK_F_HAVE_64BIT
+typedef unsigned long long duk_uint64_t;
+typedef signed long long duk_int64_t;
+#endif
+#endif
+#if !defined(DUK_F_HAVE_64BIT) && defined(__LONG_LONG_MAX__)
+#if (__LONG_LONG_MAX__ > 2147483647L)
+#define DUK_F_HAVE_64BIT
+typedef unsigned long long duk_uint64_t;
+typedef signed long long duk_int64_t;
+#endif
+#endif
+#if !defined(DUK_F_HAVE_64BIT) && \
+    (defined(DUK_F_MINGW) || defined(DUK_F_MSVC))
+/* Both MinGW and MSVC have a 64-bit type. */
+#define DUK_F_HAVE_64BIT
+typedef unsigned long duk_uint64_t;
+typedef signed long duk_int64_t;
+#endif
+#if !defined(DUK_F_HAVE_64BIT)
+/* cannot detect 64-bit type, not always needed so don't error */
+#endif
+
+typedef duk_uint8_t duk_uint_least8_t;
+typedef duk_int8_t duk_int_least8_t;
+typedef duk_uint16_t duk_uint_least16_t;
+typedef duk_int16_t duk_int_least16_t;
+typedef duk_uint32_t duk_uint_least32_t;
+typedef duk_int32_t duk_int_least32_t;
+typedef duk_uint8_t duk_uint_fast8_t;
+typedef duk_int8_t duk_int_fast8_t;
+typedef duk_uint16_t duk_uint_fast16_t;
+typedef duk_int16_t duk_int_fast16_t;
+typedef duk_uint32_t duk_uint_fast32_t;
+typedef duk_int32_t duk_int_fast32_t;
+#if defined(DUK_F_HAVE_64BIT)
+typedef duk_uint64_t duk_uint_least64_t;
+typedef duk_int64_t duk_int_least64_t;
+typedef duk_uint64_t duk_uint_fast64_t;
+typedef duk_int64_t duk_int_fast64_t;
+#endif
+#if defined(DUK_F_HAVE_64BIT)
+typedef duk_uint64_t duk_uintmax_t;
+typedef duk_int64_t duk_intmax_t;
+#else
+typedef duk_uint32_t duk_uintmax_t;
+typedef duk_int32_t duk_intmax_t;
+#endif
+
+/* Note: the funny looking computations for signed minimum 16-bit, 32-bit, and
+ * 64-bit values are intentional as the obvious forms (e.g. -0x80000000L) are
+ * -not- portable.  See code-issues.txt for a detailed discussion.
+ */
+#define DUK_UINT8_MIN         0UL
+#define DUK_UINT8_MAX         0xffUL
+#define DUK_INT8_MIN          (-0x80L)
+#define DUK_INT8_MAX          0x7fL
+#define DUK_UINT_LEAST8_MIN   0UL
+#define DUK_UINT_LEAST8_MAX   0xffUL
+#define DUK_INT_LEAST8_MIN    (-0x80L)
+#define DUK_INT_LEAST8_MAX    0x7fL
+#define DUK_UINT_FAST8_MIN    0UL
+#define DUK_UINT_FAST8_MAX    0xffUL
+#define DUK_INT_FAST8_MIN     (-0x80L)
+#define DUK_INT_FAST8_MAX     0x7fL
+#define DUK_UINT16_MIN        0UL
+#define DUK_UINT16_MAX        0xffffUL
+#define DUK_INT16_MIN         (-0x7fffL - 1L)
+#define DUK_INT16_MAX         0x7fffL
+#define DUK_UINT_LEAST16_MIN  0UL
+#define DUK_UINT_LEAST16_MAX  0xffffUL
+#define DUK_INT_LEAST16_MIN   (-0x7fffL - 1L)
+#define DUK_INT_LEAST16_MAX   0x7fffL
+#define DUK_UINT_FAST16_MIN   0UL
+#define DUK_UINT_FAST16_MAX   0xffffUL
+#define DUK_INT_FAST16_MIN    (-0x7fffL - 1L)
+#define DUK_INT_FAST16_MAX    0x7fffL
+#define DUK_UINT32_MIN        0UL
+#define DUK_UINT32_MAX        0xffffffffUL
+#define DUK_INT32_MIN         (-0x7fffffffL - 1L)
+#define DUK_INT32_MAX         0x7fffffffL
+#define DUK_UINT_LEAST32_MIN  0UL
+#define DUK_UINT_LEAST32_MAX  0xffffffffUL
+#define DUK_INT_LEAST32_MIN   (-0x7fffffffL - 1L)
+#define DUK_INT_LEAST32_MAX   0x7fffffffL
+#define DUK_UINT_FAST32_MIN   0UL
+#define DUK_UINT_FAST32_MAX   0xffffffffUL
+#define DUK_INT_FAST32_MIN    (-0x7fffffffL - 1L)
+#define DUK_INT_FAST32_MAX    0x7fffffffL
+
+/* 64-bit constants.  Since LL / ULL constants are not always available,
+ * use computed values.  These values can't be used in preprocessor
+ * comparisons; flag them as such.
+ */
+#if defined(DUK_F_HAVE_64BIT)
+#define DUK_UINT64_MIN        ((duk_uint64_t) 0)
+#define DUK_UINT64_MAX        ((duk_uint64_t) -1)
+#define DUK_INT64_MIN         ((duk_int64_t) (~(DUK_UINT64_MAX >> 1)))
+#define DUK_INT64_MAX         ((duk_int64_t) (DUK_UINT64_MAX >> 1))
+#define DUK_UINT_LEAST64_MIN  DUK_UINT64_MIN
+#define DUK_UINT_LEAST64_MAX  DUK_UINT64_MAX
+#define DUK_INT_LEAST64_MIN   DUK_INT64_MIN
+#define DUK_INT_LEAST64_MAX   DUK_INT64_MAX
+#define DUK_UINT_FAST64_MIN   DUK_UINT64_MIN
+#define DUK_UINT_FAST64_MAX   DUK_UINT64_MAX
+#define DUK_INT_FAST64_MIN    DUK_INT64_MIN
+#define DUK_INT_FAST64_MAX    DUK_INT64_MAX
+#define DUK_UINT64_MIN_COMPUTED
+#define DUK_UINT64_MAX_COMPUTED
+#define DUK_INT64_MIN_COMPUTED
+#define DUK_INT64_MAX_COMPUTED
+#define DUK_UINT_LEAST64_MIN_COMPUTED
+#define DUK_UINT_LEAST64_MAX_COMPUTED
+#define DUK_INT_LEAST64_MIN_COMPUTED
+#define DUK_INT_LEAST64_MAX_COMPUTED
+#define DUK_UINT_FAST64_MIN_COMPUTED
+#define DUK_UINT_FAST64_MAX_COMPUTED
+#define DUK_INT_FAST64_MIN_COMPUTED
+#define DUK_INT_FAST64_MAX_COMPUTED
+#endif
+
+#if defined(DUK_F_HAVE_64BIT)
+#define DUK_UINTMAX_MIN       DUK_UINT64_MIN
+#define DUK_UINTMAX_MAX       DUK_UINT64_MAX
+#define DUK_INTMAX_MIN        DUK_INT64_MIN
+#define DUK_INTMAX_MAX        DUK_INT64_MAX
+#define DUK_UINTMAX_MIN_COMPUTED
+#define DUK_UINTMAX_MAX_COMPUTED
+#define DUK_INTMAX_MIN_COMPUTED
+#define DUK_INTMAX_MAX_COMPUTED
+#else
+#define DUK_UINTMAX_MIN       0UL
+#define DUK_UINTMAX_MAX       0xffffffffUL
+#define DUK_INTMAX_MIN        (-0x7fffffffL - 1L)
+#define DUK_INTMAX_MAX        0x7fffffffL
+#endif
+
+/* This detection is not very reliable. */
+#if defined(DUK_F_32BIT_PTRS)
+typedef duk_int32_t duk_intptr_t;
+typedef duk_uint32_t duk_uintptr_t;
+#define DUK_UINTPTR_MIN       DUK_UINT32_MIN
+#define DUK_UINTPTR_MAX       DUK_UINT32_MAX
+#define DUK_INTPTR_MIN        DUK_INT32_MIN
+#define DUK_INTPTR_MAX        DUK_INT32_MAX
+#elif defined(DUK_F_64BIT_PTRS) && defined(DUK_F_HAVE_64BIT)
+typedef duk_int64_t duk_intptr_t;
+typedef duk_uint64_t duk_uintptr_t;
+#define DUK_UINTPTR_MIN       DUK_UINT64_MIN
+#define DUK_UINTPTR_MAX       DUK_UINT64_MAX
+#define DUK_INTPTR_MIN        DUK_INT64_MIN
+#define DUK_INTPTR_MAX        DUK_INT64_MAX
+#define DUK_UINTPTR_MIN_COMPUTED
+#define DUK_UINTPTR_MAX_COMPUTED
+#define DUK_INTPTR_MIN_COMPUTED
+#define DUK_INTPTR_MAX_COMPUTED
+#else
+#error cannot determine intptr type
+#endif
+
+/* SIZE_MAX may be missing so use an approximate value for it. */
+#undef DUK_SIZE_MAX_COMPUTED
+#if !defined(SIZE_MAX)
+#define DUK_SIZE_MAX_COMPUTED
+#define SIZE_MAX              ((size_t) (-1))
+#endif
+#define DUK_SIZE_MIN          0
+#define DUK_SIZE_MAX          SIZE_MAX
+
+#endif  /* C99 types */
+
+/* A few types are assumed to always exist. */
+typedef size_t duk_size_t;
+typedef ptrdiff_t duk_ptrdiff_t;
+
+/* The best type for an "all around int" in Duktape internals is "at least
+ * 32 bit signed integer" which is most convenient.  Same for unsigned type.
+ * Prefer 'int' when large enough, as it is almost always a convenient type.
+ */
+#if defined(UINT_MAX) && (UINT_MAX >= 0xffffffffUL)
+typedef int duk_int_t;
+typedef unsigned int duk_uint_t;
+#define DUK_INT_MIN           INT_MIN
+#define DUK_INT_MAX           INT_MAX
+#define DUK_UINT_MIN          0
+#define DUK_UINT_MAX          UINT_MAX
+#else
+typedef duk_int_fast32_t duk_int_t;
+typedef duk_uint_fast32_t duk_uint_t;
+#define DUK_INT_MIN           DUK_INT_FAST32_MIN
+#define DUK_INT_MAX           DUK_INT_FAST32_MAX
+#define DUK_UINT_MIN          DUK_UINT_FAST32_MIN
+#define DUK_UINT_MAX          DUK_UINT_FAST32_MAX
+#endif
+
+/* Same as 'duk_int_t' but guaranteed to be a 'fast' variant if this
+ * distinction matters for the CPU.  These types are used mainly in the
+ * executor where it might really matter.
+ */
+typedef duk_int_fast32_t duk_int_fast_t;
+typedef duk_uint_fast32_t duk_uint_fast_t;
+#define DUK_INT_FAST_MIN      DUK_INT_FAST32_MIN
+#define DUK_INT_FAST_MAX      DUK_INT_FAST32_MAX
+#define DUK_UINT_FAST_MIN     DUK_UINT_FAST32_MIN
+#define DUK_UINT_FAST_MAX     DUK_UINT_FAST32_MAX
+
+/* Small integers (16 bits or more) can fall back to the 'int' type, but
+ * have a typedef so they are marked "small" explicitly.
+ */
+typedef int duk_small_int_t;
+typedef unsigned int duk_small_uint_t;
+#define DUK_SMALL_INT_MIN     INT_MIN
+#define DUK_SMALL_INT_MAX     INT_MAX
+#define DUK_SMALL_UINT_MIN    0
+#define DUK_SMALL_UINT_MAX    UINT_MAX
+
+/* Fast variants of small integers, again for really fast paths like the
+ * executor.
+ */
+typedef duk_int_fast16_t duk_small_int_fast_t;
+typedef duk_uint_fast16_t duk_small_uint_fast_t;
+#define DUK_SMALL_INT_FAST_MIN    DUK_INT_FAST16_MIN
+#define DUK_SMALL_INT_FAST_MAX    DUK_INT_FAST16_MAX
+#define DUK_SMALL_UINT_FAST_MIN   DUK_UINT_FAST16_MIN
+#define DUK_SMALL_UINT_FAST_MAX   DUK_UINT_FAST16_MAX
+
+/* Boolean values are represented with the platform 'int'. */
+typedef duk_small_int_t duk_bool_t;
+#define DUK_BOOL_MIN              DUK_SMALL_INT_MIN
+#define DUK_BOOL_MAX              DUK_SMALL_INT_MAX
+
+/* Index values must have at least 32-bit signed range. */
+typedef duk_int_t duk_idx_t;
+#define DUK_IDX_MIN               DUK_INT_MIN
+#define DUK_IDX_MAX               DUK_INT_MAX
+
+/* Unsigned index variant. */
+typedef duk_uint_t duk_uidx_t;
+#define DUK_UIDX_MIN              DUK_UINT_MIN
+#define DUK_UIDX_MAX              DUK_UINT_MAX
+
+/* Array index values, could be exact 32 bits.
+ * Currently no need for signed duk_arridx_t.
+ */
+typedef duk_uint_t duk_uarridx_t;
+#define DUK_UARRIDX_MIN           DUK_UINT_MIN
+#define DUK_UARRIDX_MAX           DUK_UINT_MAX
+
+/* Duktape/C function return value, platform int is enough for now to
+ * represent 0, 1, or negative error code.  Must be compatible with
+ * assigning truth values (e.g. duk_ret_t rc = (foo == bar);).
+ */
+typedef duk_small_int_t duk_ret_t;
+#define DUK_RET_MIN               DUK_SMALL_INT_MIN
+#define DUK_RET_MAX               DUK_SMALL_INT_MAX
+
+/* Error codes are represented with platform int.  High bits are used
+ * for flags and such, so 32 bits are needed.
+ */
+typedef duk_int_t duk_errcode_t;
+#define DUK_ERRCODE_MIN           DUK_INT_MIN
+#define DUK_ERRCODE_MAX           DUK_INT_MAX
+
+/* Codepoint type.  Must be 32 bits or more because it is used also for
+ * internal codepoints.  The type is signed because negative codepoints
+ * are used as internal markers (e.g. to mark EOF or missing argument).
+ * (X)UTF-8/CESU-8 encode/decode take and return an unsigned variant to
+ * ensure duk_uint32_t casts back and forth nicely.  Almost everything
+ * else uses the signed one.
+ */
+typedef duk_int_t duk_codepoint_t;
+typedef duk_uint_t duk_ucodepoint_t;
+#define DUK_CODEPOINT_MIN         DUK_INT_MIN
+#define DUK_CODEPOINT_MAX         DUK_INT_MAX
+#define DUK_UCODEPOINT_MIN        DUK_UINT_MIN
+#define DUK_UCODEPOINT_MAX        DUK_UINT_MAX
+
+/* IEEE float/double typedef. */
+typedef float duk_float_t;
+typedef double duk_double_t;
+
+/* We're generally assuming that we're working on a platform with a 32-bit
+ * address space.  If DUK_SIZE_MAX is a typecast value (which is necessary
+ * if SIZE_MAX is missing), the check must be avoided because the
+ * preprocessor can't do a comparison.
+ */
+#if !defined(DUK_SIZE_MAX)
+#error DUK_SIZE_MAX is undefined, probably missing SIZE_MAX
+#elif !defined(DUK_SIZE_MAX_COMPUTED)
+#if DUK_SIZE_MAX < 0xffffffffUL
+/* On some systems SIZE_MAX can be smaller than max unsigned 32-bit value
+ * which seems incorrect if size_t is (at least) an unsigned 32-bit type.
+ * However, it doesn't seem useful to error out compilation if this is the
+ * case.
+ */
+#endif
+#endif
+
+/* Type for public API calls. */
+typedef struct duk_hthread duk_context;
+
+/* Check whether we should use 64-bit integers or not.
+ *
+ * Quite incomplete now.  Use 64-bit types if detected (C99 or other detection)
+ * unless they are known to be unreliable.  For instance, 64-bit types are
+ * available on VBCC but seem to misbehave.
+ */
+#if defined(DUK_F_HAVE_64BIT) && !defined(DUK_F_VBCC)
+#define DUK_USE_64BIT_OPS
+#else
+#undef DUK_USE_64BIT_OPS
+#endif
+
+/*
+ *  Fill-ins for platform, architecture, and compiler
+ */
+
+#if !defined(DUK_SETJMP)
+#define DUK_JMPBUF_TYPE       jmp_buf
+#define DUK_SETJMP(jb)        setjmp((jb))
+#define DUK_LONGJMP(jb)       longjmp((jb), 1)
+#endif
+
+#if 0
+/* sigsetjmp() alternative */
+#define DUK_JMPBUF_TYPE       sigjmp_buf
+#define DUK_SETJMP(jb)        sigsetjmp((jb))
+#define DUK_LONGJMP(jb)       siglongjmp((jb), 1)
+#endif
+
+typedef FILE duk_file;
+#if !defined(DUK_STDIN)
+#define DUK_STDIN       stdin
+#endif
+#if !defined(DUK_STDOUT)
+#define DUK_STDOUT      stdout
+#endif
+#if !defined(DUK_STDERR)
+#define DUK_STDERR      stderr
+#endif
+
+/* Special naming to avoid conflict with e.g. DUK_FREE() in duk_heap.h
+ * (which is unfortunately named).  May sometimes need replacement, e.g.
+ * some compilers don't handle zero length or NULL correctly in realloc().
+ */
+#if !defined(DUK_ANSI_MALLOC)
+#define DUK_ANSI_MALLOC      malloc
+#endif
+#if !defined(DUK_ANSI_REALLOC)
+#define DUK_ANSI_REALLOC     realloc
+#endif
+#if !defined(DUK_ANSI_CALLOC)
+#define DUK_ANSI_CALLOC      calloc
+#endif
+#if !defined(DUK_ANSI_FREE)
+#define DUK_ANSI_FREE        free
+#endif
+
+/* ANSI C (various versions) and some implementations require that the
+ * pointer arguments to memset(), memcpy(), and memmove() be valid values
+ * even when byte size is 0 (even a NULL pointer is considered invalid in
+ * this context).  Zero-size operations as such are allowed, as long as their
+ * pointer arguments point to a valid memory area.  The DUK_MEMSET(),
+ * DUK_MEMCPY(), and DUK_MEMMOVE() macros require this same behavior, i.e.:
+ * (1) pointers must be valid and non-NULL, (2) zero size must otherwise be
+ * allowed.  If these are not fulfilled, a macro wrapper is needed.
+ *
+ *   http://stackoverflow.com/questions/5243012/is-it-guaranteed-to-be-safe-to-perform-memcpy0-0-0
+ *   http://lists.cs.uiuc.edu/pipermail/llvmdev/2007-October/011065.html
+ *
+ * Not sure what's the required behavior when a pointer points just past the
+ * end of a buffer, which often happens in practice (e.g. zero size memmoves).
+ * For example, if allocation size is 3, the following pointer would not
+ * technically point to a valid memory byte:
+ *
+ *   <-- alloc -->
+ *   | 0 | 1 | 2 | .....
+ *                 ^-- p=3, points after last valid byte (2)
+ */
+#if !defined(DUK_MEMCPY)
+#if defined(DUK_F_UCLIBC)
+/* Old uclibcs have a broken memcpy so use memmove instead (this is overly wide
+ * now on purpose): http://lists.uclibc.org/pipermail/uclibc-cvs/2008-October/025511.html
+ */
+#define DUK_MEMCPY       memmove
+#else
+#define DUK_MEMCPY       memcpy
+#endif
+#endif
+#if !defined(DUK_MEMMOVE)
+#define DUK_MEMMOVE      memmove
+#endif
+#if !defined(DUK_MEMCMP)
+#define DUK_MEMCMP       memcmp
+#endif
+#if !defined(DUK_MEMSET)
+#define DUK_MEMSET       memset
+#endif
+#if !defined(DUK_STRLEN)
+#define DUK_STRLEN       strlen
+#endif
+#if !defined(DUK_STRCMP)
+#define DUK_STRCMP       strcmp
+#endif
+#if !defined(DUK_STRNCMP)
+#define DUK_STRNCMP      strncmp
+#endif
+#if !defined(DUK_PRINTF)
+#define DUK_PRINTF       printf
+#endif
+#if !defined(DUK_FPRINTF)
+#define DUK_FPRINTF      fprintf
+#endif
+#if !defined(DUK_SPRINTF)
+#define DUK_SPRINTF      sprintf
+#endif
+#if !defined(DUK_SNPRINTF)
+/* snprintf() is technically not part of C89 but usually available. */
+#define DUK_SNPRINTF     snprintf
+#endif
+#if !defined(DUK_VSPRINTF)
+#define DUK_VSPRINTF     vsprintf
+#endif
+#if !defined(DUK_VSNPRINTF)
+/* vsnprintf() is technically not part of C89 but usually available. */
+#define DUK_VSNPRINTF    vsnprintf
+#endif
+#if !defined(DUK_SSCANF)
+#define DUK_SSCANF       sscanf
+#endif
+#if !defined(DUK_VSSCANF)
+#define DUK_VSSCANF      vsscanf
+#endif
+#if !defined(DUK_FOPEN)
+#define DUK_FOPEN        fopen
+#endif
+#if !defined(DUK_FCLOSE)
+#define DUK_FCLOSE       fclose
+#endif
+#if !defined(DUK_FREAD)
+#define DUK_FREAD        fread
+#endif
+#if !defined(DUK_FWRITE)
+#define DUK_FWRITE       fwrite
+#endif
+#if !defined(DUK_FSEEK)
+#define DUK_FSEEK        fseek
+#endif
+#if !defined(DUK_FTELL)
+#define DUK_FTELL        ftell
+#endif
+#if !defined(DUK_FFLUSH)
+#define DUK_FFLUSH       fflush
+#endif
+#if !defined(DUK_FPUTC)
+#define DUK_FPUTC        fputc
+#endif
+#if !defined(DUK_MEMZERO)
+#define DUK_MEMZERO(p,n) DUK_MEMSET((p), 0, (n))
+#endif
+#if !defined(DUK_ABORT)
+#define DUK_ABORT        abort
+#endif
+#if !defined(DUK_EXIT)
+#define DUK_EXIT         exit
+#endif
+
+#if !defined(DUK_DOUBLE_2TO32)
+#define DUK_DOUBLE_2TO32     4294967296.0
+#endif
+#if !defined(DUK_DOUBLE_2TO31)
+#define DUK_DOUBLE_2TO31     2147483648.0
+#endif
+
+#if !defined(DUK_DOUBLE_INFINITY)
+#undef DUK_USE_COMPUTED_INFINITY
+#if defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION < 40600)
+/* GCC older than 4.6: avoid overflow warnings related to using INFINITY */
+#define DUK_DOUBLE_INFINITY  (__builtin_inf())
+#elif defined(INFINITY)
+#define DUK_DOUBLE_INFINITY  ((double) INFINITY)
+#elif !defined(DUK_F_VBCC) && !defined(DUK_F_MSVC) && !defined(DUK_F_BCC)
+#define DUK_DOUBLE_INFINITY  (1.0 / 0.0)
+#else
+/* In VBCC (1.0 / 0.0) results in a warning and 0.0 instead of infinity.
+ * Use a computed infinity (initialized when a heap is created at the
+ * latest).
+ */
+#define DUK_USE_COMPUTED_INFINITY
+#define DUK_DOUBLE_INFINITY  duk_computed_infinity
+#endif
+#endif
+
+#if !defined(DUK_DOUBLE_NAN)
+#undef DUK_USE_COMPUTED_NAN
+#if defined(NAN)
+#define DUK_DOUBLE_NAN       NAN
+#elif !defined(DUK_F_VBCC) && !defined(DUK_F_MSVC) && !defined(DUK_F_BCC)
+#define DUK_DOUBLE_NAN       (0.0 / 0.0)
+#else
+/* In VBCC (0.0 / 0.0) results in a warning and 0.0 instead of NaN.
+ * In MSVC (VS2010 Express) (0.0 / 0.0) results in a compile error.
+ * Use a computed NaN (initialized when a heap is created at the
+ * latest).
+ */
+#define DUK_USE_COMPUTED_NAN
+#define DUK_DOUBLE_NAN       duk_computed_nan
+#endif
+#endif
+
+/* Many platforms are missing fpclassify() and friends, so use replacements
+ * if necessary.  The replacement constants (FP_NAN etc) can be anything but
+ * match Linux constants now.
+ */
+#undef DUK_USE_REPL_FPCLASSIFY
+#undef DUK_USE_REPL_SIGNBIT
+#undef DUK_USE_REPL_ISFINITE
+#undef DUK_USE_REPL_ISNAN
+#undef DUK_USE_REPL_ISINF
+
+/* Complex condition broken into separate parts. */
+#undef DUK_F_USE_REPL_ALL
+#if !(defined(FP_NAN) && defined(FP_INFINITE) && defined(FP_ZERO) && \
+      defined(FP_SUBNORMAL) && defined(FP_NORMAL))
+/* Missing some obvious constants. */
+#define DUK_F_USE_REPL_ALL
+#elif defined(DUK_F_AMIGAOS) && defined(DUK_F_VBCC)
+/* VBCC is missing the built-ins even in C99 mode (perhaps a header issue). */
+#define DUK_F_USE_REPL_ALL
+#elif defined(DUK_F_AMIGAOS) && defined(DUK_F_M68K)
+/* AmigaOS + M68K seems to have math issues even when using GCC cross
+ * compilation.  Use replacements for all AmigaOS versions on M68K
+ * regardless of compiler.
+ */
+#define DUK_F_USE_REPL_ALL
+#elif defined(DUK_F_FREEBSD) && defined(DUK_F_CLANG)
+/* Placeholder fix for (detection is wider than necessary):
+ * http://llvm.org/bugs/show_bug.cgi?id=17788
+ */
+#define DUK_F_USE_REPL_ALL
+#elif defined(DUK_F_UCLIBC)
+/* At least some uclibc versions have broken floating point math.  For
+ * example, fpclassify() can incorrectly classify certain NaN formats.
+ * To be safe, use replacements.
+ */
+#define DUK_F_USE_REPL_ALL
+#endif
+
+#if defined(DUK_F_USE_REPL_ALL)
+#define DUK_USE_REPL_FPCLASSIFY
+#define DUK_USE_REPL_SIGNBIT
+#define DUK_USE_REPL_ISFINITE
+#define DUK_USE_REPL_ISNAN
+#define DUK_USE_REPL_ISINF
+#define DUK_FPCLASSIFY       duk_repl_fpclassify
+#define DUK_SIGNBIT          duk_repl_signbit
+#define DUK_ISFINITE         duk_repl_isfinite
+#define DUK_ISNAN            duk_repl_isnan
+#define DUK_ISINF            duk_repl_isinf
+#define DUK_FP_NAN           0
+#define DUK_FP_INFINITE      1
+#define DUK_FP_ZERO          2
+#define DUK_FP_SUBNORMAL     3
+#define DUK_FP_NORMAL        4
+#else
+#define DUK_FPCLASSIFY       fpclassify
+#define DUK_SIGNBIT          signbit
+#define DUK_ISFINITE         isfinite
+#define DUK_ISNAN            isnan
+#define DUK_ISINF            isinf
+#define DUK_FP_NAN           FP_NAN
+#define DUK_FP_INFINITE      FP_INFINITE
+#define DUK_FP_ZERO          FP_ZERO
+#define DUK_FP_SUBNORMAL     FP_SUBNORMAL
+#define DUK_FP_NORMAL        FP_NORMAL
+#endif
+
+#if defined(DUK_F_USE_REPL_ALL)
+#undef DUK_F_USE_REPL_ALL
+#endif
+
+/* Some math functions are C99 only.  This is also an issue with some
+ * embedded environments using uclibc where uclibc has been configured
+ * not to provide some functions.  For now, use replacements whenever
+ * using uclibc.
+ */
+#undef DUK_USE_MATH_FMIN
+#undef DUK_USE_MATH_FMAX
+#undef DUK_USE_MATH_ROUND
+#if defined(DUK_F_UCLIBC)
+/* uclibc may be missing these */
+#elif defined(DUK_F_AMIGAOS) && defined(DUK_F_VBCC)
+/* vbcc + AmigaOS may be missing these */
+#elif defined(DUK_F_MINT)
+/* mint clib is missing these */
+#elif !defined(DUK_F_C99) && !defined(DUK_F_CPP11)
+/* build is not C99 or C++11, play it safe */
+#else
+/* C99 or C++11, no known issues */
+#define DUK_USE_MATH_FMIN
+#define DUK_USE_MATH_FMAX
+#define DUK_USE_MATH_ROUND
+#endif
+
+/* These functions don't currently need replacement but are wrapped for
+ * completeness.  Because these are used as function pointers, they need
+ * to be defined as concrete C functions (not macros).
+ */
+#if !defined(DUK_FABS)
+#define DUK_FABS             fabs
+#endif
+#if !defined(DUK_FMIN)
+#define DUK_FMIN             fmin
+#endif
+#if !defined(DUK_FMAX)
+#define DUK_FMAX             fmax
+#endif
+#if !defined(DUK_FLOOR)
+#define DUK_FLOOR            floor
+#endif
+#if !defined(DUK_CEIL)
+#define DUK_CEIL             ceil
+#endif
+#if !defined(DUK_FMOD)
+#define DUK_FMOD             fmod
+#endif
+#if !defined(DUK_POW)
+#define DUK_POW              pow
+#endif
+#if !defined(DUK_ACOS)
+#define DUK_ACOS             acos
+#endif
+#if !defined(DUK_ASIN)
+#define DUK_ASIN             asin
+#endif
+#if !defined(DUK_ATAN)
+#define DUK_ATAN             atan
+#endif
+#if !defined(DUK_ATAN2)
+#define DUK_ATAN2            atan2
+#endif
+#if !defined(DUK_SIN)
+#define DUK_SIN              sin
+#endif
+#if !defined(DUK_COS)
+#define DUK_COS              cos
+#endif
+#if !defined(DUK_TAN)
+#define DUK_TAN              tan
+#endif
+#if !defined(DUK_EXP)
+#define DUK_EXP              exp
+#endif
+#if !defined(DUK_LOG)
+#define DUK_LOG              log
+#endif
+#if !defined(DUK_SQRT)
+#define DUK_SQRT             sqrt
+#endif
+
+/* NetBSD 6.0 x86 (at least) has a few problems with pow() semantics,
+ * see test-bug-netbsd-math-pow.js.  Use NetBSD specific workaround.
+ * (This might be a wider problem; if so, generalize the define name.)
+ */
+#undef DUK_USE_POW_NETBSD_WORKAROUND
+#if defined(DUK_F_NETBSD)
+#define DUK_USE_POW_NETBSD_WORKAROUND
+#endif
+
+/* Rely as little as possible on compiler behavior for NaN comparison,
+ * signed zero handling, etc.  Currently never activated but may be needed
+ * for broken compilers.
+ */
+#undef DUK_USE_PARANOID_MATH
+
+/* There was a curious bug where test-bi-date-canceling.js would fail e.g.
+ * on 64-bit Ubuntu, gcc-4.8.1, -m32, and no -std=c99.  Some date computations
+ * using doubles would be optimized which then broke some corner case tests.
+ * The problem goes away by adding 'volatile' to the datetime computations.
+ * Not sure what the actual triggering conditions are, but using this on
+ * non-C99 systems solves the known issues and has relatively little cost
+ * on other platforms.
+ */
+#undef DUK_USE_PARANOID_DATE_COMPUTATION
+#if !defined(DUK_F_C99)
+#define DUK_USE_PARANOID_DATE_COMPUTATION
+#endif
+
+/*
+ *  Byte order and double memory layout detection
+ *
+ *  Endianness detection is a major portability hassle because the macros
+ *  and headers are not standardized.  There's even variance across UNIX
+ *  platforms.  Even with "standard" headers, details like underscore count
+ *  varies between platforms, e.g. both __BYTE_ORDER and _BYTE_ORDER are used
+ *  (Crossbridge has a single underscore, for instance).
+ *
+ *  The checks below are structured with this in mind: several approaches are
+ *  used, and at the end we check if any of them worked.  This allows generic
+ *  approaches to be tried first, and platform/compiler specific hacks tried
+ *  last.  As a last resort, the user can force a specific endianness, as it's
+ *  not likely that automatic detection will work on the most exotic platforms.
+ *
+ *  Duktape supports little and big endian machines.  There's also support
+ *  for a hybrid used by some ARM machines where integers are little endian
+ *  but IEEE double values use a mixed order (12345678 -> 43218765).  This
+ *  byte order for doubles is referred to as "mixed endian".
+ */
+
+/* For custom platforms allow user to define byteorder explicitly.
+ * Since endianness headers are not standardized, this is a useful
+ * workaround for custom platforms for which endianness detection
+ * is not directly supported.  Perhaps custom hardware is used and
+ * user cannot submit upstream patches.
+ */
+#if defined(DUK_OPT_FORCE_BYTEORDER)
+#undef DUK_USE_BYTEORDER
+#if (DUK_OPT_FORCE_BYTEORDER == 1)
+#define DUK_USE_BYTEORDER 1
+#elif (DUK_OPT_FORCE_BYTEORDER == 2)
+#define DUK_USE_BYTEORDER 2
+#elif (DUK_OPT_FORCE_BYTEORDER == 3)
+#define DUK_USE_BYTEORDER 3
+#else
+#error invalid DUK_OPT_FORCE_BYTEORDER value
+#endif
+#endif  /* DUK_OPT_FORCE_BYTEORDER */
+
+/* GCC and Clang provide endianness defines as built-in predefines, with
+ * leading and trailing double underscores (e.g. __BYTE_ORDER__).  See
+ * output of "make gccpredefs" and "make clangpredefs".  Clang doesn't
+ * seem to provide __FLOAT_WORD_ORDER__; assume not mixed endian for clang.
+ * http://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html
+ */
+#if !defined(DUK_USE_BYTEORDER) && defined(__BYTE_ORDER__)
+#if defined(__ORDER_LITTLE_ENDIAN__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
+#if defined(__FLOAT_WORD_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && (__FLOAT_WORD_ORDER__ == __ORDER_LITTLE_ENDIAN__)
+#define DUK_USE_BYTEORDER 1
+#elif defined(__FLOAT_WORD_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && (__FLOAT_WORD_ORDER__ == __ORDER_BIG_ENDIAN__)
+#define DUK_USE_BYTEORDER 2
+#elif !defined(__FLOAT_WORD_ORDER__)
+/* Float word order not known, assume not a hybrid. */
+#define DUK_USE_BYTEORDER 1
+#else
+/* Byte order is little endian but cannot determine IEEE double word order. */
+#endif  /* float word order */
+#elif defined(__ORDER_BIG_ENDIAN__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
+#if defined(__FLOAT_WORD_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && (__FLOAT_WORD_ORDER__ == __ORDER_BIG_ENDIAN__)
+#define DUK_USE_BYTEORDER 3
+#elif !defined(__FLOAT_WORD_ORDER__)
+/* Float word order not known, assume not a hybrid. */
+#define DUK_USE_BYTEORDER 3
+#else
+/* Byte order is big endian but cannot determine IEEE double word order. */
+#endif  /* float word order */
+#else
+/* Cannot determine byte order; __ORDER_PDP_ENDIAN__ is related to 32-bit
+ * integer ordering and is not relevant.
+ */
+#endif  /* integer byte order */
+#endif  /* !defined(DUK_USE_BYTEORDER) && defined(__BYTE_ORDER__) */
+
+/* More or less standard endianness predefines provided by header files.
+ * The ARM hybrid case is detected by assuming that __FLOAT_WORD_ORDER
+ * will be big endian, see: http://lists.mysql.com/internals/443.
+ * On some platforms some defines may be present with an empty value which
+ * causes comparisons to fail: https://github.com/svaarala/duktape/issues/453.
+ */
+#if !defined(DUK_USE_BYTEORDER)
+#if defined(__BYTE_ORDER) && defined(__LITTLE_ENDIAN) && (__BYTE_ORDER == __LITTLE_ENDIAN) || \
+    defined(_BYTE_ORDER) && defined(_LITTLE_ENDIAN) && (_BYTE_ORDER == _LITTLE_ENDIAN) || \
+    defined(__LITTLE_ENDIAN__)
+#if defined(__FLOAT_WORD_ORDER) && defined(__LITTLE_ENDIAN) && (__FLOAT_WORD_ORDER == __LITTLE_ENDIAN) || \
+    defined(_FLOAT_WORD_ORDER) && defined(_LITTLE_ENDIAN) && (_FLOAT_WORD_ORDER == _LITTLE_ENDIAN)
+#define DUK_USE_BYTEORDER 1
+#elif defined(__FLOAT_WORD_ORDER) && defined(__BIG_ENDIAN) && (__FLOAT_WORD_ORDER == __BIG_ENDIAN) || \
+      defined(_FLOAT_WORD_ORDER) && defined(_BIG_ENDIAN) && (_FLOAT_WORD_ORDER == _BIG_ENDIAN)
+#define DUK_USE_BYTEORDER 2
+#elif !defined(__FLOAT_WORD_ORDER) && !defined(_FLOAT_WORD_ORDER)
+/* Float word order not known, assume not a hybrid. */
+#define DUK_USE_BYTEORDER 1
+#else
+/* Byte order is little endian but cannot determine IEEE double word order. */
+#endif  /* float word order */
+#elif defined(__BYTE_ORDER) && defined(__BIG_ENDIAN) && (__BYTE_ORDER == __BIG_ENDIAN) || \
+      defined(_BYTE_ORDER) && defined(_BIG_ENDIAN) && (_BYTE_ORDER == _BIG_ENDIAN) || \
+      defined(__BIG_ENDIAN__)
+#if defined(__FLOAT_WORD_ORDER) && defined(__BIG_ENDIAN) && (__FLOAT_WORD_ORDER == __BIG_ENDIAN) || \
+    defined(_FLOAT_WORD_ORDER) && defined(_BIG_ENDIAN) && (_FLOAT_WORD_ORDER == _BIG_ENDIAN)
+#define DUK_USE_BYTEORDER 3
+#elif !defined(__FLOAT_WORD_ORDER) && !defined(_FLOAT_WORD_ORDER)
+/* Float word order not known, assume not a hybrid. */
+#define DUK_USE_BYTEORDER 3
+#else
+/* Byte order is big endian but cannot determine IEEE double word order. */
+#endif  /* float word order */
+#else
+/* Cannot determine byte order. */
+#endif  /* integer byte order */
+#endif  /* !defined(DUK_USE_BYTEORDER) */
+
+/* QNX gcc cross compiler seems to define e.g. __LITTLEENDIAN__ or __BIGENDIAN__:
+ *  $ /opt/qnx650/host/linux/x86/usr/bin/i486-pc-nto-qnx6.5.0-gcc -dM -E - </dev/null | grep -ni endian
+ *  67:#define __LITTLEENDIAN__ 1
+ *  $ /opt/qnx650/host/linux/x86/usr/bin/mips-unknown-nto-qnx6.5.0-gcc -dM -E - </dev/null | grep -ni endian
+ *  81:#define __BIGENDIAN__ 1
+ *  $ /opt/qnx650/host/linux/x86/usr/bin/arm-unknown-nto-qnx6.5.0-gcc -dM -E - </dev/null | grep -ni endian
+ *  70:#define __LITTLEENDIAN__ 1
+ */
+#if !defined(DUK_USE_BYTEORDER)
+#if defined(__LITTLEENDIAN__)
+#define DUK_USE_BYTEORDER 1
+#elif defined(__BIGENDIAN__)
+#define DUK_USE_BYTEORDER 3
+#endif
+#endif
+
+/*
+ *  Alignment requirement and support for unaligned accesses
+ *
+ *  Assume unaligned accesses are not supported unless specifically allowed
+ *  in the target platform.  Some platforms may support unaligned accesses
+ *  but alignment to 4 or 8 may still be desirable.
+ */
+
+/* If not provided, use safe default for alignment. */
+#if !defined(DUK_USE_ALIGN_BY)
+#define DUK_USE_ALIGN_BY 8
+#endif
+
+/* User forced alignment to 4 or 8. */
+#if defined(DUK_OPT_FORCE_ALIGN)
+#undef DUK_USE_ALIGN_BY
+#if (DUK_OPT_FORCE_ALIGN == 4)
+#define DUK_USE_ALIGN_BY 4
+#elif (DUK_OPT_FORCE_ALIGN == 8)
+#define DUK_USE_ALIGN_BY 8
+#else
+#error invalid DUK_OPT_FORCE_ALIGN value
+#endif
+#endif
+
+/* Compiler specific hackery needed to force struct size to match aligment,
+ * see e.g. duk_hbuffer.h.
+ *
+ * http://stackoverflow.com/questions/11130109/c-struct-size-alignment
+ * http://stackoverflow.com/questions/10951039/specifying-64-bit-alignment
+ */
+#if !(defined(DUK_USE_PACK_MSVC_PRAGMA) || defined(DUK_USE_PACK_GCC_ATTR) || \
+      defined(DUK_USE_PACK_CLANG_ATTR) || defined(DUK_USE_PACK_DUMMY_MEMBER))
+#define DUK_USE_PACK_DUMMY_MEMBER
+#endif
+
+#if !defined(DUK_VA_COPY)
+/* We need va_copy() which is defined in C99 / C++11, so an awkward
+ * replacement is needed for pre-C99 / pre-C++11 environments.  This
+ * will quite likely need portability hacks for some non-C99
+ * environments.
+ */
+#if defined(DUK_F_C99) || defined(DUK_F_CPP11)
+/* C99 / C++11 and above: rely on va_copy() which is required.
+ * Omit parenthesis on macro right side on purpose to minimize differences
+ * to direct use.
+ */
+#define DUK_VA_COPY(dest,src) va_copy(dest,src)
+#else
+/* Pre-C99: va_list type is implementation dependent.  This replacement
+ * assumes it is a plain value so that a simple assignment will work.
+ * This is not the case on all platforms (it may be a single-array element,
+ * for instance).
+ */
+#define DUK_VA_COPY(dest,src) do { (dest) = (src); } while (0)
+#endif
+#endif
+
+#if !defined(DUK_MACRO_STRINGIFY)
+/* Macro hackery to convert e.g. __LINE__ to a string without formatting,
+ * see: http://stackoverflow.com/questions/240353/convert-a-preprocessor-token-to-a-string
+ */
+#define DUK_MACRO_STRINGIFY_HELPER(x)  #x
+#define DUK_MACRO_STRINGIFY(x)  DUK_MACRO_STRINGIFY_HELPER(x)
+#endif
+
+#if !defined(DUK_CAUSE_SEGFAULT)
+/* This is optionally used by panic handling to cause the program to segfault
+ * (instead of e.g. abort()) on panic.  Valgrind will then indicate the C
+ * call stack leading to the panic.
+ */
+#define DUK_CAUSE_SEGFAULT()  do { *((volatile duk_uint32_t *) NULL) = (duk_uint32_t) 0xdeadbeefUL; } while (0)
+#endif
+#if !defined(DUK_UNREF)
+/* Macro for suppressing warnings for potentially unreferenced variables.
+ * The variables can be actually unreferenced or unreferenced in some
+ * specific cases only; for instance, if a variable is only debug printed,
+ * it is unreferenced when debug printing is disabled.
+ */
+#define DUK_UNREF(x)  do { (void) (x); } while (0)
+#endif
+#if !defined(DUK_NORETURN)
+#define DUK_NORETURN(decl)  decl
+#endif
+#if !defined(DUK_UNREACHABLE)
+/* Don't know how to declare unreachable point, so don't do it; this
+ * may cause some spurious compilation warnings (e.g. "variable used
+ * uninitialized").
+ */
+#define DUK_UNREACHABLE()  do { } while (0)
+#endif
+#if !defined(DUK_LOSE_CONST)
+/* Convert any input pointer into a "void *", losing a const qualifier.
+ * This is not fully portable because casting through duk_uintptr_t may
+ * not work on all architectures (e.g. those with long, segmented pointers).
+ */
+#define DUK_LOSE_CONST(src) ((void *) (duk_uintptr_t) (src))
+#endif
+
+#if !defined(DUK_LIKELY)
+#define DUK_LIKELY(x)    (x)
+#endif
+#if !defined(DUK_UNLIKELY)
+#define DUK_UNLIKELY(x)  (x)
+#endif
+
+#if !defined(DUK_NOINLINE)
+#define DUK_NOINLINE       /*nop*/
+#endif
+#if !defined(DUK_INLINE)
+#define DUK_INLINE         /*nop*/
+#endif
+#if !defined(DUK_ALWAYS_INLINE)
+#define DUK_ALWAYS_INLINE  /*nop*/
+#endif
+
+#if !defined(DUK_EXTERNAL_DECL)
+#define DUK_EXTERNAL_DECL  extern
+#endif
+#if !defined(DUK_EXTERNAL)
+#define DUK_EXTERNAL       /*empty*/
+#endif
+#if !defined(DUK_INTERNAL_DECL)
+#if defined(DUK_SINGLE_FILE)
+#define DUK_INTERNAL_DECL  static
+#else
+#define DUK_INTERNAL_DECL  extern
+#endif
+#endif
+#if !defined(DUK_INTERNAL)
+#if defined(DUK_SINGLE_FILE)
+#define DUK_INTERNAL       static
+#else
+#define DUK_INTERNAL       /*empty*/
+#endif
+#endif
+#if !defined(DUK_LOCAL_DECL)
+#define DUK_LOCAL_DECL     static
+#endif
+#if !defined(DUK_LOCAL)
+#define DUK_LOCAL          static
+#endif
+
+#if !defined(DUK_FILE_MACRO)
+#define DUK_FILE_MACRO  __FILE__
+#endif
+#if !defined(DUK_LINE_MACRO)
+#define DUK_LINE_MACRO  __LINE__
+#endif
+#if !defined(DUK_FUNC_MACRO)
+#if defined(DUK_F_C99) || defined(DUK_F_CPP11)
+#define DUK_FUNC_MACRO  __func__
+#elif defined(__FUNCTION__)
+#define DUK_FUNC_MACRO  __FUNCTION__
+#else
+#define DUK_FUNC_MACRO  "unknown"
+#endif
+#endif
+
+#if !defined(DUK_BSWAP32)
+#define DUK_BSWAP32(x) \
+	((((duk_uint32_t) (x)) >> 24) | \
+	 ((((duk_uint32_t) (x)) >> 8) & 0xff00UL) | \
+	 ((((duk_uint32_t) (x)) << 8) & 0xff0000UL) | \
+	 (((duk_uint32_t) (x)) << 24))
+#endif
+#if !defined(DUK_BSWAP16)
+#define DUK_BSWAP16(x) \
+	((duk_uint16_t) (x) >> 8) | \
+	((duk_uint16_t) (x) << 8)
+#endif
+
+/* DUK_USE_VARIADIC_MACROS: required from compilers, so no fill-in. */
+/* DUK_USE_UNION_INITIALIZERS: required from compilers, so no fill-in. */
+
+#if !(defined(DUK_USE_FLEX_C99) || defined(DUK_USE_FLEX_ZEROSIZE) || defined(DUK_USE_FLEX_ONESIZE))
+#if defined(DUK_F_C99)
+#define DUK_USE_FLEX_C99
+#else
+#define DUK_USE_FLEX_ZEROSIZE  /* Not standard but common enough */
+#endif
+#endif
+
+#if !(defined(DUK_USE_PACK_GCC_ATTR) || defined(DUK_USE_PACK_CLANG_ATTR) || \
+      defined(DUK_USE_PACK_MSVC_PRAGMA) || defined(DUK_USE_PACK_DUMMY_MEMBER))
+#define DUK_USE_PACK_DUMMY_MEMBER
+#endif
+
+#if 0  /* not defined by default */
+#undef DUK_USE_GCC_PRAGMAS
+#endif
+
+/* Workaround for GH-323: avoid inlining control when compiling from
+ * multiple sources, as it causes compiler portability trouble.
+ */
+#if !defined(DUK_SINGLE_FILE)
+#undef DUK_NOINLINE
+#undef DUK_INLINE
+#undef DUK_ALWAYS_INLINE
+#define DUK_NOINLINE       /*nop*/
+#define DUK_INLINE         /*nop*/
+#define DUK_ALWAYS_INLINE  /*nop*/
+#endif
+
+/*
+ *  Check whether or not a packed duk_tval representation is possible.
+ *  What's basically required is that pointers are 32-bit values
+ *  (sizeof(void *) == 4).  Best effort check, not always accurate.
+ *  If guess goes wrong, crashes may result; self tests also verify
+ *  the guess.
+ */
+
+/* Explicit marker needed; may be 'defined', 'undefined, 'or 'not provided'. */
+#if !defined(DUK_F_PACKED_TVAL_PROVIDED)
+#undef DUK_F_PACKED_TVAL_POSSIBLE
+
+/* Strict C99 case: DUK_UINTPTR_MAX (= UINTPTR_MAX) should be very reliable */
+#if !defined(DUK_F_PACKED_TVAL_POSSIBLE) && defined(DUK_UINTPTR_MAX)
+#if (DUK_UINTPTR_MAX <= 0xffffffffUL)
+#define DUK_F_PACKED_TVAL_POSSIBLE
+#endif
+#endif
+
+/* Non-C99 case, still relying on DUK_UINTPTR_MAX, as long as it is not a computed value */
+#if !defined(DUK_F_PACKED_TVAL_POSSIBLE) && defined(DUK_UINTPTR_MAX) && !defined(DUK_UINTPTR_MAX_COMPUTED)
+#if (DUK_UINTPTR_MAX <= 0xffffffffUL)
+#define DUK_F_PACKED_TVAL_POSSIBLE
+#endif
+#endif
+
+/* DUK_SIZE_MAX (= SIZE_MAX) is often reliable */
+#if !defined(DUK_F_PACKED_TVAL_POSSIBLE) && defined(DUK_SIZE_MAX) && !defined(DUK_SIZE_MAX_COMPUTED)
+#if (DUK_SIZE_MAX <= 0xffffffffUL)
+#define DUK_F_PACKED_TVAL_POSSIBLE
+#endif
+#endif
+
+#undef DUK_USE_PACKED_TVAL
+#if defined(DUK_F_PACKED_TVAL_POSSIBLE)
+#define DUK_USE_PACKED_TVAL
+#endif
+
+#undef DUK_F_PACKED_TVAL_POSSIBLE
+#endif  /* DUK_F_PACKED_TVAL_PROVIDED */
+
+/* Feature option forcing. */
+#if defined(DUK_OPT_NO_PACKED_TVAL)
+#undef DUK_USE_PACKED_TVAL
+#elif defined(DUK_OPT_PACKED_TVAL)
+#undef DUK_USE_PACKED_TVAL
+#define DUK_USE_PACKED_TVAL
+#endif
+/* Object property allocation layout has implications for memory and code
+ * footprint and generated code size/speed.  The best layout also depends
+ * on whether the platform has alignment requirements or benefits from
+ * having mostly aligned accesses.
+ */
+#undef DUK_USE_HOBJECT_LAYOUT_1
+#undef DUK_USE_HOBJECT_LAYOUT_2
+#undef DUK_USE_HOBJECT_LAYOUT_3
+#if (DUK_USE_ALIGN_BY == 1)
+/* On platforms without any alignment issues, layout 1 is preferable
+ * because it compiles to slightly less code and provides direct access
+ * to property keys.
+ */
+#define DUK_USE_HOBJECT_LAYOUT_1
+#else
+/* On other platforms use layout 2, which requires some padding but
+ * is a bit more natural than layout 3 in ordering the entries.  Layout
+ * 3 is currently not used.
+ */
+#define DUK_USE_HOBJECT_LAYOUT_2
+#endif
+
+/* GCC/clang inaccurate math would break compliance and probably duk_tval,
+ * so refuse to compile.  Relax this if -ffast-math is tested to work.
+ */
+#if defined(__FAST_MATH__)
+#error __FAST_MATH__ defined, refusing to compile
+#endif
+
+/*
+ *  Feature option handling
+ */
+
+#if !defined(DUK_USE_ALIGN_BY)
+#if defined(DUK_OPT_FORCE_ALIGN)
+#define DUK_USE_ALIGN_BY DUK_OPT_FORCE_ALIGN
+#else
+#define DUK_USE_ALIGN_BY 8
+#endif
+#endif
+
+#if defined(DUK_OPT_ASSERTIONS)
+#define DUK_USE_ASSERTIONS
+#elif defined(DUK_OPT_NO_ASSERTIONS)
+#undef DUK_USE_ASSERTIONS
+#else
+#undef DUK_USE_ASSERTIONS
+#endif
+
+#if defined(DUK_OPT_AUGMENT_ERRORS)
+#define DUK_USE_AUGMENT_ERROR_CREATE
+#elif defined(DUK_OPT_NO_AUGMENT_ERRORS)
+#undef DUK_USE_AUGMENT_ERROR_CREATE
+#else
+#define DUK_USE_AUGMENT_ERROR_CREATE
+#endif
+
+#if defined(DUK_OPT_AUGMENT_ERRORS)
+#define DUK_USE_AUGMENT_ERROR_THROW
+#elif defined(DUK_OPT_NO_AUGMENT_ERRORS)
+#undef DUK_USE_AUGMENT_ERROR_THROW
+#else
+#define DUK_USE_AUGMENT_ERROR_THROW
+#endif
+
+#if defined(DUK_OPT_BROWSER_LIKE)
+#define DUK_USE_BROWSER_LIKE
+#elif defined(DUK_OPT_NO_BROWSER_LIKE)
+#undef DUK_USE_BROWSER_LIKE
+#else
+#define DUK_USE_BROWSER_LIKE
+#endif
+
+#if defined(DUK_OPT_BUFFEROBJECT_SUPPORT)
+#define DUK_USE_BUFFEROBJECT_SUPPORT
+#elif defined(DUK_OPT_NO_BUFFEROBJECT_SUPPORT)
+#undef DUK_USE_BUFFEROBJECT_SUPPORT
+#else
+#define DUK_USE_BUFFEROBJECT_SUPPORT
+#endif
+
+#if defined(DUK_OPT_BUFLEN16)
+#define DUK_USE_BUFLEN16
+#elif defined(DUK_OPT_NO_BUFLEN16)
+#undef DUK_USE_BUFLEN16
+#else
+#undef DUK_USE_BUFLEN16
+#endif
+
+#if defined(DUK_OPT_BYTECODE_DUMP_SUPPORT)
+#define DUK_USE_BYTECODE_DUMP_SUPPORT
+#elif defined(DUK_OPT_NO_BYTECODE_DUMP_SUPPORT)
+#undef DUK_USE_BYTECODE_DUMP_SUPPORT
+#else
+#define DUK_USE_BYTECODE_DUMP_SUPPORT
+#endif
+
+#if defined(DUK_OPT_COMMONJS_MODULES)
+#define DUK_USE_COMMONJS_MODULES
+#elif defined(DUK_OPT_NO_COMMONJS_M

<TRUNCATED>

[04/51] [partial] nifi-minifi-cpp git commit: MINIFI-183 Added civet 1.9.1 sources Added onScheduled hook Added initial two-way TLS-enabled ListenHTTP implementation

Posted by al...@apache.org.
http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_debugger.c
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_debugger.c b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_debugger.c
new file mode 100644
index 0000000..e0caff6
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_debugger.c
@@ -0,0 +1,2773 @@
+/*
+ *  Duktape debugger
+ */
+
+#include "duk_internal.h"
+
+#if defined(DUK_USE_DEBUGGER_SUPPORT)
+
+/*
+ *  Helper structs
+ */
+
+typedef union {
+	void *p;
+	duk_uint_t b[1];
+	/* Use b[] to access the size of the union, which is strictly not
+	 * correct.  Can't use fixed size unless there's feature detection
+	 * for pointer byte size.
+	 */
+} duk__ptr_union;
+
+/*
+ *  Detach handling
+ */
+
+#define DUK__SET_CONN_BROKEN(thr,reason) do { \
+		/* For now shared handler is fine. */ \
+		duk__debug_do_detach1((thr)->heap, (reason)); \
+	} while (0)
+
+DUK_LOCAL void duk__debug_do_detach1(duk_heap *heap, duk_int_t reason) {
+	/* Can be called multiple times with no harm.  Mark the transport
+	 * bad (dbg_read_cb == NULL) and clear state except for the detached
+	 * callback and the udata field.  The detached callback is delayed
+	 * to the message loop so that it can be called between messages;
+	 * this avoids corner cases related to immediate debugger reattach
+	 * inside the detached callback.
+	 */
+
+	if (heap->dbg_detaching) {
+		DUK_D(DUK_DPRINT("debugger already detaching, ignore detach1"));
+		return;
+	}
+
+	DUK_D(DUK_DPRINT("debugger transport detaching, marking transport broken"));
+
+	heap->dbg_detaching = 1;  /* prevent multiple in-progress detaches */
+
+	if (heap->dbg_write_cb != NULL) {
+		duk_hthread *thr;
+
+		thr = heap->heap_thread;
+		DUK_ASSERT(thr != NULL);
+
+		duk_debug_write_notify(thr, DUK_DBG_CMD_DETACHING);
+		duk_debug_write_int(thr, reason);
+		duk_debug_write_eom(thr);
+	}
+
+	heap->dbg_read_cb = NULL;
+	heap->dbg_write_cb = NULL;
+	heap->dbg_peek_cb = NULL;
+	heap->dbg_read_flush_cb = NULL;
+	heap->dbg_write_flush_cb = NULL;
+	heap->dbg_request_cb = NULL;
+	/* heap->dbg_detached_cb: keep */
+	/* heap->dbg_udata: keep */
+	/* heap->dbg_processing: keep on purpose to avoid debugger re-entry in detaching state */
+	heap->dbg_paused = 0;
+	heap->dbg_state_dirty = 0;
+	heap->dbg_force_restart = 0;
+	heap->dbg_step_type = 0;
+	heap->dbg_step_thread = NULL;
+	heap->dbg_step_csindex = 0;
+	heap->dbg_step_startline = 0;
+	heap->dbg_have_next_byte = 0;
+
+	/* Ensure there are no stale active breakpoint pointers.
+	 * Breakpoint list is currently kept - we could empty it
+	 * here but we'd need to handle refcounts correctly, and
+	 * we'd need a 'thr' reference for that.
+	 *
+	 * XXX: clear breakpoint on either attach or detach?
+	 */
+	heap->dbg_breakpoints_active[0] = (duk_breakpoint *) NULL;
+}
+
+DUK_LOCAL void duk__debug_do_detach2(duk_heap *heap) {
+	duk_debug_detached_function detached_cb;
+	void *detached_udata;
+
+	/* Safe to call multiple times. */
+
+	detached_cb = heap->dbg_detached_cb;
+	detached_udata = heap->dbg_udata;
+	heap->dbg_detached_cb = NULL;
+	heap->dbg_udata = NULL;
+
+	if (detached_cb) {
+		/* Careful here: state must be wiped before the call
+		 * so that we can cleanly handle a re-attach from
+		 * inside the callback.
+		 */
+		DUK_D(DUK_DPRINT("detached during message loop, delayed call to detached_cb"));
+		detached_cb(detached_udata);
+	}
+
+	heap->dbg_detaching = 0;
+}
+
+DUK_INTERNAL void duk_debug_do_detach(duk_heap *heap) {
+	duk__debug_do_detach1(heap, 0);
+	duk__debug_do_detach2(heap);
+}
+
+/* Called on a read/write error: NULL all callbacks except the detached
+ * callback so that we never accidentally call them after a read/write
+ * error has been indicated.  This is especially important for the transport
+ * I/O callbacks to fulfill guaranteed callback semantics.
+ */
+DUK_LOCAL void duk__debug_null_most_callbacks(duk_hthread *thr) {
+	duk_heap *heap;
+	heap = thr->heap;
+	DUK_D(DUK_DPRINT("transport read/write error, NULL all callbacks expected detached"));
+	heap->dbg_read_cb = NULL;
+	heap->dbg_write_cb = NULL;  /* this is especially critical to avoid another write call in detach1() */
+	heap->dbg_peek_cb = NULL;
+	heap->dbg_read_flush_cb = NULL;
+	heap->dbg_write_flush_cb = NULL;
+	heap->dbg_request_cb = NULL;
+	/* keep heap->dbg_detached_cb */
+}
+
+/*
+ *  Debug connection peek and flush primitives
+ */
+
+DUK_INTERNAL duk_bool_t duk_debug_read_peek(duk_hthread *thr) {
+	duk_heap *heap;
+
+	DUK_ASSERT(thr != NULL);
+	heap = thr->heap;
+	DUK_ASSERT(heap != NULL);
+
+	if (heap->dbg_read_cb == NULL) {
+		DUK_D(DUK_DPRINT("attempt to peek in detached state, return zero (= no data)"));
+		return 0;
+	}
+	if (heap->dbg_peek_cb == NULL) {
+		DUK_DD(DUK_DDPRINT("no peek callback, return zero (= no data)"));
+		return 0;
+	}
+
+	return (duk_bool_t) (heap->dbg_peek_cb(heap->dbg_udata) > 0);
+}
+
+DUK_INTERNAL void duk_debug_read_flush(duk_hthread *thr) {
+	duk_heap *heap;
+
+	DUK_ASSERT(thr != NULL);
+	heap = thr->heap;
+	DUK_ASSERT(heap != NULL);
+
+	if (heap->dbg_read_cb == NULL) {
+		DUK_D(DUK_DPRINT("attempt to read flush in detached state, ignore"));
+		return;
+	}
+	if (heap->dbg_read_flush_cb == NULL) {
+		DUK_DD(DUK_DDPRINT("no read flush callback, ignore"));
+		return;
+	}
+
+	heap->dbg_read_flush_cb(heap->dbg_udata);
+}
+
+DUK_INTERNAL void duk_debug_write_flush(duk_hthread *thr) {
+	duk_heap *heap;
+
+	DUK_ASSERT(thr != NULL);
+	heap = thr->heap;
+	DUK_ASSERT(heap != NULL);
+
+	if (heap->dbg_read_cb == NULL) {
+		DUK_D(DUK_DPRINT("attempt to write flush in detached state, ignore"));
+		return;
+	}
+	if (heap->dbg_write_flush_cb == NULL) {
+		DUK_DD(DUK_DDPRINT("no write flush callback, ignore"));
+		return;
+	}
+
+	heap->dbg_write_flush_cb(heap->dbg_udata);
+}
+
+/*
+ *  Debug connection skip primitives
+ */
+
+/* Skip fully. */
+DUK_INTERNAL void duk_debug_skip_bytes(duk_hthread *thr, duk_size_t length) {
+	duk_uint8_t dummy[64];
+	duk_size_t now;
+
+	DUK_ASSERT(thr != NULL);
+
+	while (length > 0) {
+		now = (length > sizeof(dummy) ? sizeof(dummy) : length);
+		duk_debug_read_bytes(thr, dummy, now);
+		length -= now;
+	}
+}
+
+DUK_INTERNAL void duk_debug_skip_byte(duk_hthread *thr) {
+	DUK_ASSERT(thr != NULL);
+
+	(void) duk_debug_read_byte(thr);
+}
+
+/*
+ *  Debug connection read primitives
+ */
+
+/* Peek ahead in the stream one byte. */
+DUK_INTERNAL uint8_t duk_debug_peek_byte(duk_hthread *thr) {
+	/* It is important not to call this if the last byte read was an EOM.
+	 * Reading ahead in this scenario would cause unnecessary blocking if
+	 * another message is not available.
+	 */
+
+	duk_uint8_t x;
+
+	x = duk_debug_read_byte(thr);
+	thr->heap->dbg_have_next_byte = 1;
+	thr->heap->dbg_next_byte = x;
+	return x;
+}
+
+/* Read fully. */
+DUK_INTERNAL void duk_debug_read_bytes(duk_hthread *thr, duk_uint8_t *data, duk_size_t length) {
+	duk_heap *heap;
+	duk_uint8_t *p;
+	duk_size_t left;
+	duk_size_t got;
+
+	DUK_ASSERT(thr != NULL);
+	heap = thr->heap;
+	DUK_ASSERT(heap != NULL);
+
+	if (heap->dbg_read_cb == NULL) {
+		DUK_D(DUK_DPRINT("attempt to read %ld bytes in detached state, return zero data", (long) length));
+		goto fail;
+	}
+
+	/* NOTE: length may be zero */
+	p = data;
+	if (length >= 1 && heap->dbg_have_next_byte) {
+		heap->dbg_have_next_byte = 0;
+		*p++ = heap->dbg_next_byte;
+	}
+	for (;;) {
+		left = (duk_size_t) ((data + length) - p);
+		if (left == 0) {
+			break;
+		}
+		DUK_ASSERT(heap->dbg_read_cb != NULL);
+		DUK_ASSERT(left >= 1);
+#if defined(DUK_USE_DEBUGGER_TRANSPORT_TORTURE)
+		left = 1;
+#endif
+		got = heap->dbg_read_cb(heap->dbg_udata, (char *) p, left);
+		if (got == 0 || got > left) {
+			DUK_D(DUK_DPRINT("connection error during read, return zero data"));
+			duk__debug_null_most_callbacks(thr);  /* avoid calling write callback in detach1() */
+			DUK__SET_CONN_BROKEN(thr, 1);
+			goto fail;
+		}
+		p += got;
+	}
+	return;
+
+ fail:
+	DUK_MEMZERO((void *) data, (size_t) length);
+}
+
+DUK_INTERNAL duk_uint8_t duk_debug_read_byte(duk_hthread *thr) {
+	duk_uint8_t x;
+
+	x = 0;  /* just in case callback is broken and won't write 'x' */
+	duk_debug_read_bytes(thr, &x, 1);
+	return x;
+}
+
+DUK_LOCAL duk_uint32_t duk__debug_read_uint32_raw(duk_hthread *thr) {
+	duk_uint8_t buf[4];
+
+	DUK_ASSERT(thr != NULL);
+
+	duk_debug_read_bytes(thr, buf, 4);
+	return ((duk_uint32_t) buf[0] << 24) |
+	       ((duk_uint32_t) buf[1] << 16) |
+	       ((duk_uint32_t) buf[2] << 8) |
+	       (duk_uint32_t) buf[3];
+}
+
+DUK_LOCAL duk_uint32_t duk__debug_read_int32_raw(duk_hthread *thr) {
+	return (duk_int32_t) duk__debug_read_uint32_raw(thr);
+}
+
+DUK_LOCAL duk_uint16_t duk__debug_read_uint16_raw(duk_hthread *thr) {
+	duk_uint8_t buf[2];
+
+	DUK_ASSERT(thr != NULL);
+
+	duk_debug_read_bytes(thr, buf, 2);
+	return ((duk_uint16_t) buf[0] << 8) |
+	       (duk_uint16_t) buf[1];
+}
+
+DUK_INTERNAL duk_int32_t duk_debug_read_int(duk_hthread *thr) {
+	duk_small_uint_t x;
+	duk_small_uint_t t;
+
+	DUK_ASSERT(thr != NULL);
+
+	x = duk_debug_read_byte(thr);
+	if (x >= 0xc0) {
+		t = duk_debug_read_byte(thr);
+		return (duk_int32_t) (((x - 0xc0) << 8) + t);
+	} else if (x >= 0x80) {
+		return (duk_int32_t) (x - 0x80);
+	} else if (x == DUK_DBG_IB_INT4) {
+		return (duk_int32_t) duk__debug_read_uint32_raw(thr);
+	}
+
+	DUK_D(DUK_DPRINT("debug connection error: failed to decode int"));
+	DUK__SET_CONN_BROKEN(thr, 1);
+	return 0;
+}
+
+DUK_LOCAL duk_hstring *duk__debug_read_hstring_raw(duk_hthread *thr, duk_uint32_t len) {
+	duk_context *ctx = (duk_context *) thr;
+	duk_uint8_t buf[31];
+	duk_uint8_t *p;
+
+	if (len <= sizeof(buf)) {
+		duk_debug_read_bytes(thr, buf, (duk_size_t) len);
+		duk_push_lstring(ctx, (const char *) buf, (duk_size_t) len);
+	} else {
+		p = (duk_uint8_t *) duk_push_fixed_buffer(ctx, (duk_size_t) len);
+		DUK_ASSERT(p != NULL);
+		duk_debug_read_bytes(thr, p, (duk_size_t) len);
+		duk_to_string(ctx, -1);
+	}
+
+	return duk_require_hstring(ctx, -1);
+}
+
+DUK_INTERNAL duk_hstring *duk_debug_read_hstring(duk_hthread *thr) {
+	duk_context *ctx = (duk_context *) thr;
+	duk_small_uint_t x;
+	duk_uint32_t len;
+
+	DUK_ASSERT(thr != NULL);
+
+	x = duk_debug_read_byte(thr);
+	if (x >= 0x60 && x <= 0x7f) {
+		/* For short strings, use a fixed temp buffer. */
+		len = (duk_uint32_t) (x - 0x60);
+	} else if (x == DUK_DBG_IB_STR2) {
+		len = (duk_uint32_t) duk__debug_read_uint16_raw(thr);
+	} else if (x == DUK_DBG_IB_STR4) {
+		len = (duk_uint32_t) duk__debug_read_uint32_raw(thr);
+	} else {
+		goto fail;
+	}
+
+	return duk__debug_read_hstring_raw(thr, len);
+
+ fail:
+	DUK_D(DUK_DPRINT("debug connection error: failed to decode int"));
+	DUK__SET_CONN_BROKEN(thr, 1);
+	duk_push_hstring_stridx(thr, DUK_STRIDX_EMPTY_STRING);  /* always push some string */
+	return duk_require_hstring(ctx, -1);
+}
+
+DUK_LOCAL duk_hbuffer *duk__debug_read_hbuffer_raw(duk_hthread *thr, duk_uint32_t len) {
+	duk_context *ctx = (duk_context *) thr;
+	duk_uint8_t *p;
+
+	p = (duk_uint8_t *) duk_push_fixed_buffer(ctx, (duk_size_t) len);
+	DUK_ASSERT(p != NULL);
+	duk_debug_read_bytes(thr, p, (duk_size_t) len);
+
+	return duk_require_hbuffer(ctx, -1);
+}
+
+DUK_LOCAL void *duk__debug_read_pointer_raw(duk_hthread *thr) {
+	duk_small_uint_t x;
+	duk__ptr_union pu;
+
+	DUK_ASSERT(thr != NULL);
+
+	x = duk_debug_read_byte(thr);
+	if (x != sizeof(pu)) {
+		goto fail;
+	}
+	duk_debug_read_bytes(thr, (duk_uint8_t *) &pu.p, sizeof(pu));
+#if defined(DUK_USE_INTEGER_LE)
+	duk_byteswap_bytes((duk_uint8_t *) pu.b, sizeof(pu));
+#endif
+	return (void *) pu.p;
+
+ fail:
+	DUK_D(DUK_DPRINT("debug connection error: failed to decode pointer"));
+	DUK__SET_CONN_BROKEN(thr, 1);
+	return (void *) NULL;
+}
+
+DUK_LOCAL duk_double_t duk__debug_read_double_raw(duk_hthread *thr) {
+	duk_double_union du;
+
+	DUK_ASSERT(sizeof(du.uc) == 8);
+	duk_debug_read_bytes(thr, (duk_uint8_t *) du.uc, sizeof(du.uc));
+	DUK_DBLUNION_DOUBLE_NTOH(&du);
+	return du.d;
+}
+
+#if 0
+DUK_INTERNAL duk_heaphdr *duk_debug_read_heapptr(duk_hthread *thr) {
+	duk_small_uint_t x;
+
+	DUK_ASSERT(thr != NULL);
+
+	x = duk_debug_read_byte(thr);
+	if (x != DUK_DBG_IB_HEAPPTR) {
+		goto fail;
+	}
+
+	return (duk_heaphdr *) duk__debug_read_pointer_raw(thr);
+
+ fail:
+	DUK_D(DUK_DPRINT("debug connection error: failed to decode heapptr"));
+	DUK__SET_CONN_BROKEN(thr, 1);
+	return NULL;
+}
+#endif
+
+DUK_INTERNAL duk_heaphdr *duk_debug_read_any_ptr(duk_hthread *thr) {
+	duk_small_uint_t x;
+
+	DUK_ASSERT(thr != NULL);
+
+	x = duk_debug_read_byte(thr);
+	switch (x) {
+	case DUK_DBG_IB_OBJECT:
+	case DUK_DBG_IB_POINTER:
+	case DUK_DBG_IB_HEAPPTR:
+		/* Accept any pointer-like value; for 'object' dvalue, read
+		 * and ignore the class number.
+		 */
+		if (x == DUK_DBG_IB_OBJECT) {
+			duk_debug_skip_byte(thr);
+		}
+		break;
+	default:
+		goto fail;
+	}
+
+	return (duk_heaphdr *) duk__debug_read_pointer_raw(thr);
+
+ fail:
+	DUK_D(DUK_DPRINT("debug connection error: failed to decode any pointer (object, pointer, heapptr)"));
+	DUK__SET_CONN_BROKEN(thr, 1);
+	return NULL;
+}
+
+DUK_INTERNAL duk_tval *duk_debug_read_tval(duk_hthread *thr) {
+	duk_context *ctx = (duk_context *) thr;
+	duk_uint8_t x;
+	duk_uint_t t;
+	duk_uint32_t len;
+
+	DUK_ASSERT(thr != NULL);
+
+	x = duk_debug_read_byte(thr);
+
+	if (x >= 0xc0) {
+		t = (duk_uint_t) (x - 0xc0);
+		t = (t << 8) + duk_debug_read_byte(thr);
+		duk_push_uint(ctx, (duk_uint_t) t);
+		goto return_ptr;
+	}
+	if (x >= 0x80) {
+		duk_push_uint(ctx, (duk_uint_t) (x - 0x80));
+		goto return_ptr;
+	}
+	if (x >= 0x60) {
+		len = (duk_uint32_t) (x - 0x60);
+		duk__debug_read_hstring_raw(thr, len);
+		goto return_ptr;
+	}
+
+	switch (x) {
+	case DUK_DBG_IB_INT4: {
+		duk_int32_t i = duk__debug_read_int32_raw(thr);
+		duk_push_i32(ctx, i);
+		break;
+	}
+	case DUK_DBG_IB_STR4: {
+		len = duk__debug_read_uint32_raw(thr);
+		duk__debug_read_hstring_raw(thr, len);
+		break;
+	}
+	case DUK_DBG_IB_STR2: {
+		len = duk__debug_read_uint16_raw(thr);
+		duk__debug_read_hstring_raw(thr, len);
+		break;
+	}
+	case DUK_DBG_IB_BUF4: {
+		len = duk__debug_read_uint32_raw(thr);
+		duk__debug_read_hbuffer_raw(thr, len);
+		break;
+	}
+	case DUK_DBG_IB_BUF2: {
+		len = duk__debug_read_uint16_raw(thr);
+		duk__debug_read_hbuffer_raw(thr, len);
+		break;
+	}
+	case DUK_DBG_IB_UNDEFINED: {
+		duk_push_undefined(ctx);
+		break;
+	}
+	case DUK_DBG_IB_NULL: {
+		duk_push_null(ctx);
+		break;
+	}
+	case DUK_DBG_IB_TRUE: {
+		duk_push_true(ctx);
+		break;
+	}
+	case DUK_DBG_IB_FALSE: {
+		duk_push_false(ctx);
+		break;
+	}
+	case DUK_DBG_IB_NUMBER: {
+		duk_double_t d;
+		d = duk__debug_read_double_raw(thr);
+		duk_push_number(ctx, d);
+		break;
+	}
+	case DUK_DBG_IB_OBJECT: {
+		duk_heaphdr *h;
+		duk_debug_skip_byte(thr);
+		h = (duk_heaphdr *) duk__debug_read_pointer_raw(thr);
+		duk_push_heapptr(thr, (void *) h);
+		break;
+	}
+	case DUK_DBG_IB_POINTER: {
+		void *ptr;
+		ptr = duk__debug_read_pointer_raw(thr);
+		duk_push_pointer(thr, ptr);
+		break;
+	}
+	case DUK_DBG_IB_LIGHTFUNC: {
+		/* XXX: Not needed for now, so not implemented.  Note that
+		 * function pointers may have different size/layout than
+		 * a void pointer.
+		 */
+		DUK_D(DUK_DPRINT("reading lightfunc values unimplemented"));
+		goto fail;
+	}
+	case DUK_DBG_IB_HEAPPTR: {
+		duk_heaphdr *h;
+		h = (duk_heaphdr *) duk__debug_read_pointer_raw(thr);
+		duk_push_heapptr(thr, (void *) h);
+		break;
+	}
+	case DUK_DBG_IB_UNUSED:  /* unused: not accepted in inbound messages */
+	default:
+		goto fail;
+	}
+
+ return_ptr:
+	return DUK_GET_TVAL_NEGIDX(thr, -1);
+
+ fail:
+	DUK_D(DUK_DPRINT("debug connection error: failed to decode tval"));
+	DUK__SET_CONN_BROKEN(thr, 1);
+	return NULL;
+}
+
+/*
+ *  Debug connection write primitives
+ */
+
+/* Write fully. */
+DUK_INTERNAL void duk_debug_write_bytes(duk_hthread *thr, const duk_uint8_t *data, duk_size_t length) {
+	duk_heap *heap;
+	const duk_uint8_t *p;
+	duk_size_t left;
+	duk_size_t got;
+
+	DUK_ASSERT(thr != NULL);
+	DUK_ASSERT(length == 0 || data != NULL);
+	heap = thr->heap;
+	DUK_ASSERT(heap != NULL);
+
+	if (heap->dbg_write_cb == NULL) {
+		DUK_D(DUK_DPRINT("attempt to write %ld bytes in detached state, ignore", (long) length));
+		return;
+	}
+	if (length == 0) {
+		/* Avoid doing an actual write callback with length == 0,
+		 * because that's reserved for a write flush.
+		 */
+		return;
+	}
+	DUK_ASSERT(data != NULL);
+
+	p = data;
+	for (;;) {
+		left = (duk_size_t) ((data + length) - p);
+		if (left == 0) {
+			break;
+		}
+		DUK_ASSERT(heap->dbg_write_cb != NULL);
+		DUK_ASSERT(left >= 1);
+#if defined(DUK_USE_DEBUGGER_TRANSPORT_TORTURE)
+		left = 1;
+#endif
+		got = heap->dbg_write_cb(heap->dbg_udata, (const char *) p, left);
+		if (got == 0 || got > left) {
+			duk__debug_null_most_callbacks(thr);  /* avoid calling write callback in detach1() */
+			DUK_D(DUK_DPRINT("connection error during write"));
+			DUK__SET_CONN_BROKEN(thr, 1);
+			return;
+		}
+		p += got;
+	}
+}
+
+DUK_INTERNAL void duk_debug_write_byte(duk_hthread *thr, duk_uint8_t x) {
+	duk_debug_write_bytes(thr, (const duk_uint8_t *) &x, 1);
+}
+
+DUK_INTERNAL void duk_debug_write_unused(duk_hthread *thr) {
+	duk_debug_write_byte(thr, DUK_DBG_IB_UNUSED);
+}
+
+DUK_INTERNAL void duk_debug_write_undefined(duk_hthread *thr) {
+	duk_debug_write_byte(thr, DUK_DBG_IB_UNDEFINED);
+}
+
+#if defined(DUK_USE_DEBUGGER_INSPECT)
+DUK_INTERNAL void duk_debug_write_null(duk_hthread *thr) {
+	duk_debug_write_byte(thr, DUK_DBG_IB_NULL);
+}
+#endif
+
+DUK_INTERNAL void duk_debug_write_boolean(duk_hthread *thr, duk_uint_t val) {
+	duk_debug_write_byte(thr, val ? DUK_DBG_IB_TRUE : DUK_DBG_IB_FALSE);
+}
+
+/* Write signed 32-bit integer. */
+DUK_INTERNAL void duk_debug_write_int(duk_hthread *thr, duk_int32_t x) {
+	duk_uint8_t buf[5];
+	duk_size_t len;
+
+	DUK_ASSERT(thr != NULL);
+
+	if (x >= 0 && x <= 0x3fL) {
+		buf[0] = (duk_uint8_t) (0x80 + x);
+		len = 1;
+	} else if (x >= 0 && x <= 0x3fffL) {
+		buf[0] = (duk_uint8_t) (0xc0 + (x >> 8));
+		buf[1] = (duk_uint8_t) (x & 0xff);
+		len = 2;
+	} else {
+		/* Signed integers always map to 4 bytes now. */
+		buf[0] = (duk_uint8_t) DUK_DBG_IB_INT4;
+		buf[1] = (duk_uint8_t) ((x >> 24) & 0xff);
+		buf[2] = (duk_uint8_t) ((x >> 16) & 0xff);
+		buf[3] = (duk_uint8_t) ((x >> 8) & 0xff);
+		buf[4] = (duk_uint8_t) (x & 0xff);
+		len = 5;
+	}
+	duk_debug_write_bytes(thr, buf, len);
+}
+
+/* Write unsigned 32-bit integer. */
+DUK_INTERNAL void duk_debug_write_uint(duk_hthread *thr, duk_uint32_t x) {
+	/* The debugger protocol doesn't support a plain integer encoding for
+	 * the full 32-bit unsigned range (only 32-bit signed).  For now,
+	 * unsigned 32-bit values simply written as signed ones.  This is not
+	 * a concrete issue except for 32-bit heaphdr fields.  Proper solutions
+	 * would be to (a) write such integers as IEEE doubles or (b) add an
+	 * unsigned 32-bit dvalue.
+	 */
+	if (x >= 0x80000000UL) {
+		DUK_D(DUK_DPRINT("writing unsigned integer 0x%08lx as signed integer",
+		                 (long) x));
+	}
+	duk_debug_write_int(thr, (duk_int32_t) x);
+}
+
+DUK_INTERNAL void duk_debug_write_strbuf(duk_hthread *thr, const char *data, duk_size_t length, duk_uint8_t marker_base) {
+	duk_uint8_t buf[5];
+	duk_size_t buflen;
+
+	DUK_ASSERT(thr != NULL);
+	DUK_ASSERT(length == 0 || data != NULL);
+
+	if (length <= 0x1fUL && marker_base == DUK_DBG_IB_STR4) {
+		/* For strings, special form for short lengths. */
+		buf[0] = (duk_uint8_t) (0x60 + length);
+		buflen = 1;
+	} else if (length <= 0xffffUL) {
+		buf[0] = (duk_uint8_t) (marker_base + 1);
+		buf[1] = (duk_uint8_t) (length >> 8);
+		buf[2] = (duk_uint8_t) (length & 0xff);
+		buflen = 3;
+	} else {
+		buf[0] = (duk_uint8_t) marker_base;
+		buf[1] = (duk_uint8_t) (length >> 24);
+		buf[2] = (duk_uint8_t) ((length >> 16) & 0xff);
+		buf[3] = (duk_uint8_t) ((length >> 8) & 0xff);
+		buf[4] = (duk_uint8_t) (length & 0xff);
+		buflen = 5;
+	}
+
+	duk_debug_write_bytes(thr, (const duk_uint8_t *) buf, buflen);
+	duk_debug_write_bytes(thr, (const duk_uint8_t *) data, length);
+}
+
+DUK_INTERNAL void duk_debug_write_string(duk_hthread *thr, const char *data, duk_size_t length) {
+	duk_debug_write_strbuf(thr, data, length, DUK_DBG_IB_STR4);
+}
+
+DUK_INTERNAL void duk_debug_write_cstring(duk_hthread *thr, const char *data) {
+	DUK_ASSERT(thr != NULL);
+
+	duk_debug_write_string(thr,
+	                       data,
+	                       data ? DUK_STRLEN(data) : 0);
+}
+
+DUK_INTERNAL void duk_debug_write_hstring(duk_hthread *thr, duk_hstring *h) {
+	DUK_ASSERT(thr != NULL);
+
+	/* XXX: differentiate null pointer from empty string? */
+	duk_debug_write_string(thr,
+	                       (h != NULL ? (const char *) DUK_HSTRING_GET_DATA(h) : NULL),
+	                       (h != NULL ? (duk_size_t) DUK_HSTRING_GET_BYTELEN(h) : 0));
+}
+
+DUK_LOCAL void duk__debug_write_hstring_safe_top(duk_hthread *thr) {
+	duk_context *ctx = (duk_context *) thr;
+	duk_debug_write_hstring(thr, duk_safe_to_hstring(ctx, -1));
+}
+
+DUK_INTERNAL void duk_debug_write_buffer(duk_hthread *thr, const char *data, duk_size_t length) {
+	duk_debug_write_strbuf(thr, data, length, DUK_DBG_IB_BUF4);
+}
+
+DUK_INTERNAL void duk_debug_write_hbuffer(duk_hthread *thr, duk_hbuffer *h) {
+	DUK_ASSERT(thr != NULL);
+
+	duk_debug_write_buffer(thr,
+	                       (h != NULL ? (const char *) DUK_HBUFFER_GET_DATA_PTR(thr->heap, h) : NULL),
+	                       (h != NULL ? (duk_size_t) DUK_HBUFFER_GET_SIZE(h) : 0));
+}
+
+DUK_LOCAL void duk__debug_write_pointer_raw(duk_hthread *thr, void *ptr, duk_uint8_t ibyte) {
+	duk_uint8_t buf[2];
+	duk__ptr_union pu;
+
+	DUK_ASSERT(thr != NULL);
+	DUK_ASSERT(sizeof(ptr) >= 1 && sizeof(ptr) <= 16);
+	/* ptr may be NULL */
+
+	buf[0] = ibyte;
+	buf[1] = sizeof(pu);
+	duk_debug_write_bytes(thr, buf, 2);
+	pu.p = (void *) ptr;
+#if defined(DUK_USE_INTEGER_LE)
+	duk_byteswap_bytes((duk_uint8_t *) pu.b, sizeof(pu));
+#endif
+	duk_debug_write_bytes(thr, (const duk_uint8_t *) &pu.p, (duk_size_t) sizeof(pu));
+}
+
+DUK_INTERNAL void duk_debug_write_pointer(duk_hthread *thr, void *ptr) {
+	duk__debug_write_pointer_raw(thr, ptr, DUK_DBG_IB_POINTER);
+}
+
+#if defined(DUK_USE_DEBUGGER_DUMPHEAP) || defined(DUK_USE_DEBUGGER_INSPECT)
+DUK_INTERNAL void duk_debug_write_heapptr(duk_hthread *thr, duk_heaphdr *h) {
+	duk__debug_write_pointer_raw(thr, (void *) h, DUK_DBG_IB_HEAPPTR);
+}
+#endif  /* DUK_USE_DEBUGGER_DUMPHEAP || DUK_USE_DEBUGGER_INSPECT */
+
+DUK_INTERNAL void duk_debug_write_hobject(duk_hthread *thr, duk_hobject *obj) {
+	duk_uint8_t buf[3];
+	duk__ptr_union pu;
+
+	DUK_ASSERT(thr != NULL);
+	DUK_ASSERT(sizeof(obj) >= 1 && sizeof(obj) <= 16);
+	DUK_ASSERT(obj != NULL);
+
+	buf[0] = DUK_DBG_IB_OBJECT;
+	buf[1] = (duk_uint8_t) DUK_HOBJECT_GET_CLASS_NUMBER(obj);
+	buf[2] = sizeof(pu);
+	duk_debug_write_bytes(thr, buf, 3);
+	pu.p = (void *) obj;
+#if defined(DUK_USE_INTEGER_LE)
+	duk_byteswap_bytes((duk_uint8_t *) pu.b, sizeof(pu));
+#endif
+	duk_debug_write_bytes(thr, (const duk_uint8_t *) &pu.p, (duk_size_t) sizeof(pu));
+}
+
+DUK_INTERNAL void duk_debug_write_tval(duk_hthread *thr, duk_tval *tv) {
+	duk_c_function lf_func;
+	duk_small_uint_t lf_flags;
+	duk_uint8_t buf[4];
+	duk_double_union du1;
+	duk_double_union du2;
+	duk_int32_t i32;
+
+	DUK_ASSERT(thr != NULL);
+	DUK_ASSERT(tv != NULL);
+
+	switch (DUK_TVAL_GET_TAG(tv)) {
+	case DUK_TAG_UNDEFINED:
+		duk_debug_write_byte(thr, DUK_DBG_IB_UNDEFINED);
+		break;
+	case DUK_TAG_UNUSED:
+		duk_debug_write_byte(thr, DUK_DBG_IB_UNUSED);
+		break;
+	case DUK_TAG_NULL:
+		duk_debug_write_byte(thr, DUK_DBG_IB_NULL);
+		break;
+	case DUK_TAG_BOOLEAN:
+		DUK_ASSERT(DUK_TVAL_GET_BOOLEAN(tv) == 0 ||
+		           DUK_TVAL_GET_BOOLEAN(tv) == 1);
+		duk_debug_write_boolean(thr, DUK_TVAL_GET_BOOLEAN(tv));
+		break;
+	case DUK_TAG_POINTER:
+		duk_debug_write_pointer(thr, (void *) DUK_TVAL_GET_POINTER(tv));
+		break;
+	case DUK_TAG_LIGHTFUNC:
+		DUK_TVAL_GET_LIGHTFUNC(tv, lf_func, lf_flags);
+		buf[0] = DUK_DBG_IB_LIGHTFUNC;
+		buf[1] = (duk_uint8_t) (lf_flags >> 8);
+		buf[2] = (duk_uint8_t) (lf_flags & 0xff);
+		buf[3] = sizeof(lf_func);
+		duk_debug_write_bytes(thr, buf, 4);
+		duk_debug_write_bytes(thr, (const duk_uint8_t *) &lf_func, sizeof(lf_func));
+		break;
+	case DUK_TAG_STRING:
+		duk_debug_write_hstring(thr, DUK_TVAL_GET_STRING(tv));
+		break;
+	case DUK_TAG_OBJECT:
+		duk_debug_write_hobject(thr, DUK_TVAL_GET_OBJECT(tv));
+		break;
+	case DUK_TAG_BUFFER:
+		duk_debug_write_hbuffer(thr, DUK_TVAL_GET_BUFFER(tv));
+		break;
+#if defined(DUK_USE_FASTINT)
+	case DUK_TAG_FASTINT:
+#endif
+	default:
+		/* Numbers are normalized to big (network) endian.  We can
+		 * (but are not required) to use integer dvalues when there's
+		 * no loss of precision.
+		 *
+		 * XXX: share check with other code; this check is slow but
+		 * reliable and doesn't require careful exponent/mantissa
+		 * mask tricks as in the fastint downgrade code.
+		 */
+		DUK_ASSERT(!DUK_TVAL_IS_UNUSED(tv));
+		DUK_ASSERT(DUK_TVAL_IS_NUMBER(tv));
+		du1.d = DUK_TVAL_GET_NUMBER(tv);
+		i32 = (duk_int32_t) du1.d;
+		du2.d = (duk_double_t) i32;
+
+		DUK_DD(DUK_DDPRINT("i32=%ld du1=%02x%02x%02x%02x%02x%02x%02x%02x "
+		                   "du2=%02x%02x%02x%02x%02x%02x%02x%02x",
+		                   (long) i32,
+		                   (unsigned int) du1.uc[0], (unsigned int) du1.uc[1],
+		                   (unsigned int) du1.uc[2], (unsigned int) du1.uc[3],
+		                   (unsigned int) du1.uc[4], (unsigned int) du1.uc[5],
+		                   (unsigned int) du1.uc[6], (unsigned int) du1.uc[7],
+		                   (unsigned int) du2.uc[0], (unsigned int) du2.uc[1],
+		                   (unsigned int) du2.uc[2], (unsigned int) du2.uc[3],
+		                   (unsigned int) du2.uc[4], (unsigned int) du2.uc[5],
+		                   (unsigned int) du2.uc[6], (unsigned int) du2.uc[7]));
+
+		if (DUK_MEMCMP((const void *) du1.uc, (const void *) du2.uc, sizeof(du1.uc)) == 0) {
+			duk_debug_write_int(thr, i32);
+		} else {
+			DUK_DBLUNION_DOUBLE_HTON(&du1);
+			duk_debug_write_byte(thr, DUK_DBG_IB_NUMBER);
+			duk_debug_write_bytes(thr, (const duk_uint8_t *) du1.uc, sizeof(du1.uc));
+		}
+	}
+}
+
+#if defined(DUK_USE_DEBUGGER_DUMPHEAP)
+/* Variant for writing duk_tvals so that any heap allocated values are
+ * written out as tagged heap pointers.
+ */
+DUK_LOCAL void duk__debug_write_tval_heapptr(duk_hthread *thr, duk_tval *tv) {
+	if (DUK_TVAL_IS_HEAP_ALLOCATED(tv)) {
+		duk_heaphdr *h = DUK_TVAL_GET_HEAPHDR(tv);
+		duk_debug_write_heapptr(thr, h);
+	} else {
+		duk_debug_write_tval(thr, tv);
+	}
+}
+#endif  /* DUK_USE_DEBUGGER_DUMPHEAP */
+
+/*
+ *  Debug connection message write helpers
+ */
+
+#if 0  /* unused */
+DUK_INTERNAL void duk_debug_write_request(duk_hthread *thr, duk_small_uint_t command) {
+	duk_debug_write_byte(thr, DUK_DBG_IB_REQUEST);
+	duk_debug_write_int(thr, command);
+}
+#endif
+
+DUK_INTERNAL void duk_debug_write_reply(duk_hthread *thr) {
+	duk_debug_write_byte(thr, DUK_DBG_IB_REPLY);
+}
+
+DUK_INTERNAL void duk_debug_write_error_eom(duk_hthread *thr, duk_small_uint_t err_code, const char *msg) {
+	/* Allow NULL 'msg' */
+	duk_debug_write_byte(thr, DUK_DBG_IB_ERROR);
+	duk_debug_write_int(thr, (duk_int32_t) err_code);
+	duk_debug_write_cstring(thr, msg);
+	duk_debug_write_eom(thr);
+}
+
+DUK_INTERNAL void duk_debug_write_notify(duk_hthread *thr, duk_small_uint_t command) {
+	duk_debug_write_byte(thr, DUK_DBG_IB_NOTIFY);
+	duk_debug_write_int(thr, command);
+}
+
+DUK_INTERNAL void duk_debug_write_eom(duk_hthread *thr) {
+	duk_debug_write_byte(thr, DUK_DBG_IB_EOM);
+
+	/* As an initial implementation, write flush after every EOM (and the
+	 * version identifier).  A better implementation would flush only when
+	 * Duktape is finished processing messages so that a flush only happens
+	 * after all outbound messages are finished on that occasion.
+	 */
+	duk_debug_write_flush(thr);
+}
+
+/*
+ *  Status message and helpers
+ */
+
+DUK_INTERNAL duk_uint_fast32_t duk_debug_curr_line(duk_hthread *thr) {
+	duk_context *ctx = (duk_context *) thr;
+	duk_activation *act;
+	duk_uint_fast32_t line;
+	duk_uint_fast32_t pc;
+
+	act = duk_hthread_get_current_activation(thr);  /* may be NULL */
+	if (act == NULL) {
+		return 0;
+	}
+
+	/* We're conceptually between two opcodes; act->pc indicates the next
+	 * instruction to be executed.  This is usually the correct pc/line to
+	 * indicate in Status.  (For the 'debugger' statement this now reports
+	 * the pc/line after the debugger statement because the debugger opcode
+	 * has already been executed.)
+	 */
+
+	pc = duk_hthread_get_act_curr_pc(thr, act);
+
+	/* XXX: this should be optimized to be a raw query and avoid valstack
+	 * operations if possible.
+	 */
+	duk_push_tval(ctx, &act->tv_func);
+	line = duk_hobject_pc2line_query(ctx, -1, pc);
+	duk_pop(ctx);
+	return line;
+}
+
+DUK_INTERNAL void duk_debug_send_status(duk_hthread *thr) {
+	duk_context *ctx = (duk_context *) thr;
+	duk_activation *act;
+
+	duk_debug_write_notify(thr, DUK_DBG_CMD_STATUS);
+	duk_debug_write_int(thr, thr->heap->dbg_paused);
+
+	DUK_ASSERT_DISABLE(thr->callstack_top >= 0);  /* unsigned */
+	if (thr->callstack_top == 0) {
+		duk_debug_write_undefined(thr);
+		duk_debug_write_undefined(thr);
+		duk_debug_write_int(thr, 0);
+		duk_debug_write_int(thr, 0);
+	} else {
+		act = thr->callstack + thr->callstack_top - 1;
+		duk_push_tval(ctx, &act->tv_func);
+		duk_get_prop_string(ctx, -1, "fileName");
+		duk__debug_write_hstring_safe_top(thr);
+		duk_get_prop_string(ctx, -2, "name");
+		duk__debug_write_hstring_safe_top(thr);
+		duk_pop_3(ctx);
+		/* Report next pc/line to be executed. */
+		duk_debug_write_uint(thr, (duk_uint32_t) duk_debug_curr_line(thr));
+		duk_debug_write_uint(thr, (duk_uint32_t) duk_hthread_get_act_curr_pc(thr, act));
+	}
+
+	duk_debug_write_eom(thr);
+}
+
+#if defined(DUK_USE_DEBUGGER_THROW_NOTIFY)
+DUK_INTERNAL void duk_debug_send_throw(duk_hthread *thr, duk_bool_t fatal) {
+	/*
+	 *  NFY <int: 5> <int: fatal> <str: msg> <str: filename> <int: linenumber> EOM
+	 */
+
+	duk_context *ctx = (duk_context *) thr;
+	duk_activation *act;
+	duk_uint32_t pc;
+
+	DUK_ASSERT(thr->valstack_top > thr->valstack);  /* At least: ... [err] */
+
+	duk_debug_write_notify(thr, DUK_DBG_CMD_THROW);
+	duk_debug_write_int(thr, fatal);
+
+	/* Report thrown value to client coerced to string */
+	duk_dup(ctx, -1);
+	duk__debug_write_hstring_safe_top(thr);
+	duk_pop(ctx);
+
+	if (duk_is_error(ctx, -1)) {
+		/* Error instance, use augmented error data directly */
+		duk_get_prop_stridx(ctx, -1, DUK_STRIDX_FILE_NAME);
+		duk__debug_write_hstring_safe_top(thr);
+		duk_get_prop_stridx(ctx, -2, DUK_STRIDX_LINE_NUMBER);
+		duk_debug_write_uint(thr, duk_get_uint(ctx, -1));
+	} else {
+		/* For anything other than an Error instance, we calculate the error
+		 * location directly from the current activation.
+		 */
+		act = thr->callstack + thr->callstack_top - 1;
+		duk_push_tval(ctx, &act->tv_func);
+		duk_get_prop_string(ctx, -1, "fileName");
+		duk__debug_write_hstring_safe_top(thr);
+		pc = duk_hthread_get_act_prev_pc(thr, act);
+		duk_debug_write_uint(thr, (duk_uint32_t) duk_hobject_pc2line_query(ctx, -2, pc));
+	}
+	duk_pop_2(ctx);  /* shared pop */
+
+	duk_debug_write_eom(thr);
+}
+#endif  /* DUK_USE_DEBUGGER_THROW_NOTIFY */
+
+/*
+ *  Debug message processing
+ */
+
+/* Skip dvalue. */
+DUK_LOCAL duk_bool_t duk__debug_skip_dvalue(duk_hthread *thr) {
+	duk_uint8_t x;
+	duk_uint32_t len;
+
+	x = duk_debug_read_byte(thr);
+
+	if (x >= 0xc0) {
+		duk_debug_skip_byte(thr);
+		return 0;
+	}
+	if (x >= 0x80) {
+		return 0;
+	}
+	if (x >= 0x60) {
+		duk_debug_skip_bytes(thr, x - 0x60);
+		return 0;
+	}
+	switch(x) {
+	case DUK_DBG_IB_EOM:
+		return 1;  /* Return 1: got EOM */
+	case DUK_DBG_IB_REQUEST:
+	case DUK_DBG_IB_REPLY:
+	case DUK_DBG_IB_ERROR:
+	case DUK_DBG_IB_NOTIFY:
+		break;
+	case DUK_DBG_IB_INT4:
+		(void) duk__debug_read_uint32_raw(thr);
+		break;
+	case DUK_DBG_IB_STR4:
+	case DUK_DBG_IB_BUF4:
+		len = duk__debug_read_uint32_raw(thr);
+		duk_debug_skip_bytes(thr, len);
+		break;
+	case DUK_DBG_IB_STR2:
+	case DUK_DBG_IB_BUF2:
+		len = duk__debug_read_uint16_raw(thr);
+		duk_debug_skip_bytes(thr, len);
+		break;
+	case DUK_DBG_IB_UNUSED:
+	case DUK_DBG_IB_UNDEFINED:
+	case DUK_DBG_IB_NULL:
+	case DUK_DBG_IB_TRUE:
+	case DUK_DBG_IB_FALSE:
+		break;
+	case DUK_DBG_IB_NUMBER:
+		duk_debug_skip_bytes(thr, 8);
+		break;
+	case DUK_DBG_IB_OBJECT:
+		duk_debug_skip_byte(thr);
+		len = duk_debug_read_byte(thr);
+		duk_debug_skip_bytes(thr, len);
+		break;
+	case DUK_DBG_IB_POINTER:
+	case DUK_DBG_IB_HEAPPTR:
+		len = duk_debug_read_byte(thr);
+		duk_debug_skip_bytes(thr, len);
+		break;
+	case DUK_DBG_IB_LIGHTFUNC:
+		duk_debug_skip_bytes(thr, 2);
+		len = duk_debug_read_byte(thr);
+		duk_debug_skip_bytes(thr, len);
+		break;
+	default:
+		goto fail;
+	}
+
+	return 0;
+
+ fail:
+	DUK__SET_CONN_BROKEN(thr, 1);
+	return 1;  /* Pretend like we got EOM */
+}
+
+/* Skip dvalues to EOM. */
+DUK_LOCAL void duk__debug_skip_to_eom(duk_hthread *thr) {
+	for (;;) {
+		if (duk__debug_skip_dvalue(thr)) {
+			break;
+		}
+	}
+}
+
+/*
+ *  Simple commands
+ */
+
+DUK_LOCAL void duk__debug_handle_basic_info(duk_hthread *thr, duk_heap *heap) {
+	DUK_UNREF(heap);
+	DUK_D(DUK_DPRINT("debug command Version"));
+
+	duk_debug_write_reply(thr);
+	duk_debug_write_int(thr, DUK_VERSION);
+	duk_debug_write_cstring(thr, DUK_GIT_DESCRIBE);
+	duk_debug_write_cstring(thr, DUK_USE_TARGET_INFO);
+#if defined(DUK_USE_DOUBLE_LE)
+	duk_debug_write_int(thr, 1);
+#elif defined(DUK_USE_DOUBLE_ME)
+	duk_debug_write_int(thr, 2);
+#elif defined(DUK_USE_DOUBLE_BE)
+	duk_debug_write_int(thr, 3);
+#else
+	duk_debug_write_int(thr, 0);
+#endif
+	duk_debug_write_int(thr, (duk_int_t) sizeof(void *));
+	duk_debug_write_eom(thr);
+}
+
+DUK_LOCAL void duk__debug_handle_trigger_status(duk_hthread *thr, duk_heap *heap) {
+	DUK_UNREF(heap);
+	DUK_D(DUK_DPRINT("debug command TriggerStatus"));
+
+	duk_debug_write_reply(thr);
+	duk_debug_write_eom(thr);
+	heap->dbg_state_dirty = 1;
+}
+
+DUK_LOCAL void duk__debug_handle_pause(duk_hthread *thr, duk_heap *heap) {
+	DUK_D(DUK_DPRINT("debug command Pause"));
+
+	DUK_HEAP_SET_PAUSED(heap);
+	duk_debug_write_reply(thr);
+	duk_debug_write_eom(thr);
+}
+
+DUK_LOCAL void duk__debug_handle_resume(duk_hthread *thr, duk_heap *heap) {
+	DUK_D(DUK_DPRINT("debug command Resume"));
+
+	DUK_HEAP_CLEAR_PAUSED(heap);
+	duk_debug_write_reply(thr);
+	duk_debug_write_eom(thr);
+}
+
+DUK_LOCAL void duk__debug_handle_step(duk_hthread *thr, duk_heap *heap, duk_int32_t cmd) {
+	duk_small_uint_t step_type;
+	duk_uint_fast32_t line;
+
+	DUK_D(DUK_DPRINT("debug command StepInto/StepOver/StepOut: %d", (int) cmd));
+
+	if (cmd == DUK_DBG_CMD_STEPINTO) {
+		step_type = DUK_STEP_TYPE_INTO;
+	} else if (cmd == DUK_DBG_CMD_STEPOVER) {
+		step_type = DUK_STEP_TYPE_OVER;
+	} else {
+		DUK_ASSERT(cmd == DUK_DBG_CMD_STEPOUT);
+		step_type = DUK_STEP_TYPE_OUT;
+	}
+
+	line = duk_debug_curr_line(thr);
+	if (line > 0) {
+		heap->dbg_paused = 0;
+		heap->dbg_step_type = step_type;
+		heap->dbg_step_thread = thr;
+		heap->dbg_step_csindex = thr->callstack_top - 1;
+		heap->dbg_step_startline = line;
+		heap->dbg_state_dirty = 1;
+	} else {
+		DUK_D(DUK_DPRINT("cannot determine current line, stepinto/stepover/stepout ignored"));
+	}
+	duk_debug_write_reply(thr);
+	duk_debug_write_eom(thr);
+}
+
+DUK_LOCAL void duk__debug_handle_list_break(duk_hthread *thr, duk_heap *heap) {
+	duk_small_int_t i;
+
+	DUK_D(DUK_DPRINT("debug command ListBreak"));
+	duk_debug_write_reply(thr);
+	for (i = 0; i < (duk_small_int_t) heap->dbg_breakpoint_count; i++) {
+		duk_debug_write_hstring(thr, heap->dbg_breakpoints[i].filename);
+		duk_debug_write_uint(thr, (duk_uint32_t) heap->dbg_breakpoints[i].line);
+	}
+	duk_debug_write_eom(thr);
+}
+
+DUK_LOCAL void duk__debug_handle_add_break(duk_hthread *thr, duk_heap *heap) {
+	duk_hstring *filename;
+	duk_uint32_t linenumber;
+	duk_small_int_t idx;
+
+	DUK_UNREF(heap);
+
+	filename = duk_debug_read_hstring(thr);
+	linenumber = (duk_uint32_t) duk_debug_read_int(thr);
+	DUK_D(DUK_DPRINT("debug command AddBreak: %!O:%ld", (duk_hobject *) filename, (long) linenumber));
+	idx = duk_debug_add_breakpoint(thr, filename, linenumber);
+	if (idx >= 0) {
+		duk_debug_write_reply(thr);
+		duk_debug_write_int(thr, (duk_int32_t) idx);
+		duk_debug_write_eom(thr);
+	} else {
+		duk_debug_write_error_eom(thr, DUK_DBG_ERR_TOOMANY, "no space for breakpoint");
+	}
+}
+
+DUK_LOCAL void duk__debug_handle_del_break(duk_hthread *thr, duk_heap *heap) {
+	duk_small_uint_t idx;
+
+	DUK_UNREF(heap);
+
+	DUK_D(DUK_DPRINT("debug command DelBreak"));
+	idx = (duk_small_uint_t) duk_debug_read_int(thr);
+	if (duk_debug_remove_breakpoint(thr, idx)) {
+		duk_debug_write_reply(thr);
+		duk_debug_write_eom(thr);
+	} else {
+		duk_debug_write_error_eom(thr, DUK_DBG_ERR_NOTFOUND, "invalid breakpoint index");
+	}
+}
+
+DUK_LOCAL void duk__debug_handle_get_var(duk_hthread *thr, duk_heap *heap) {
+	duk_context *ctx = (duk_context *) thr;
+	duk_hstring *str;
+	duk_bool_t rc;
+	duk_int32_t level;
+
+	DUK_UNREF(heap);
+	DUK_D(DUK_DPRINT("debug command GetVar"));
+
+	str = duk_debug_read_hstring(thr);  /* push to stack */
+	DUK_ASSERT(str != NULL);
+	if (duk_debug_peek_byte(thr) != DUK_DBG_IB_EOM) {
+		level = duk_debug_read_int(thr);  /* optional callstack level */
+		if (level >= 0 || -level > (duk_int32_t) thr->callstack_top) {
+			DUK_D(DUK_DPRINT("invalid callstack level for GetVar"));
+			duk_debug_write_error_eom(thr, DUK_DBG_ERR_NOTFOUND, "invalid callstack level");
+			return;
+		}
+	} else {
+		level = -1;
+	}
+
+	if (thr->callstack_top > 0) {
+		rc = duk_js_getvar_activation(thr,
+		                              thr->callstack + thr->callstack_top + level,
+		                              str,
+		                              0);
+	} else {
+		/* No activation, no variable access.  Could also pretend
+		 * we're in the global program context and read stuff off
+		 * the global object.
+		 */
+		DUK_D(DUK_DPRINT("callstack empty, no activation -> ignore getvar"));
+		rc = 0;
+	}
+
+	duk_debug_write_reply(thr);
+	if (rc) {
+		duk_debug_write_int(thr, 1);
+		DUK_ASSERT(duk_get_tval(ctx, -2) != NULL);
+		duk_debug_write_tval(thr, duk_get_tval(ctx, -2));
+	} else {
+		duk_debug_write_int(thr, 0);
+		duk_debug_write_unused(thr);
+	}
+	duk_debug_write_eom(thr);
+}
+
+DUK_LOCAL void duk__debug_handle_put_var(duk_hthread *thr, duk_heap *heap) {
+	duk_hstring *str;
+	duk_tval *tv;
+	duk_int32_t level;
+
+	DUK_UNREF(heap);
+	DUK_D(DUK_DPRINT("debug command PutVar"));
+
+	str = duk_debug_read_hstring(thr);  /* push to stack */
+	DUK_ASSERT(str != NULL);
+	tv = duk_debug_read_tval(thr);
+	if (tv == NULL) {
+		/* detached */
+		return;
+	}
+	if (duk_debug_peek_byte(thr) != DUK_DBG_IB_EOM) {
+		level = duk_debug_read_int(thr);  /* optional callstack level */
+		if (level >= 0 || -level > (duk_int32_t) thr->callstack_top) {
+			DUK_D(DUK_DPRINT("invalid callstack level for PutVar"));
+			duk_debug_write_error_eom(thr, DUK_DBG_ERR_NOTFOUND, "invalid callstack level");
+			return;
+		}
+	} else {
+		level = -1;
+	}
+
+	if (thr->callstack_top > 0) {
+		duk_js_putvar_activation(thr,
+		                         thr->callstack + thr->callstack_top + level,
+		                         str,
+		                         tv,
+		                         0);
+	} else {
+		DUK_D(DUK_DPRINT("callstack empty, no activation -> ignore putvar"));
+	}
+
+	/* XXX: Current putvar implementation doesn't have a success flag,
+	 * add one and send to debug client?
+	 */
+	duk_debug_write_reply(thr);
+	duk_debug_write_eom(thr);
+}
+
+DUK_LOCAL void duk__debug_handle_get_call_stack(duk_hthread *thr, duk_heap *heap) {
+	duk_context *ctx = (duk_context *) thr;
+	duk_hthread *curr_thr = thr;
+	duk_activation *curr_act;
+	duk_uint_fast32_t pc;
+	duk_uint_fast32_t line;
+	duk_size_t i;
+
+	DUK_ASSERT(thr != NULL);
+	DUK_UNREF(heap);
+
+	duk_debug_write_reply(thr);
+	while (curr_thr != NULL) {
+		i = curr_thr->callstack_top;
+		while (i > 0) {
+			i--;
+			curr_act = curr_thr->callstack + i;
+
+			/* PC/line semantics here are:
+			 *   - For callstack top we're conceptually between two
+			 *     opcodes and current PC indicates next line to
+			 *     execute, so report that (matches Status).
+			 *   - For other activations we're conceptually still
+			 *     executing the instruction at PC-1, so report that
+			 *     (matches error stacktrace behavior).
+			 *   - See: https://github.com/svaarala/duktape/issues/281
+			 */
+
+			/* XXX: optimize to use direct reads, i.e. avoid
+			 * value stack operations.
+			 */
+			duk_push_tval(ctx, &curr_act->tv_func);
+			duk_get_prop_stridx(ctx, -1, DUK_STRIDX_FILE_NAME);
+			duk__debug_write_hstring_safe_top(thr);
+			duk_get_prop_stridx(ctx, -2, DUK_STRIDX_NAME);
+			duk__debug_write_hstring_safe_top(thr);
+			pc = duk_hthread_get_act_curr_pc(thr, curr_act);
+			if (i != curr_thr->callstack_top - 1 && pc > 0) {
+				pc--;
+			}
+			line = duk_hobject_pc2line_query(ctx, -3, pc);
+			duk_debug_write_uint(thr, (duk_uint32_t) line);
+			duk_debug_write_uint(thr, (duk_uint32_t) pc);
+			duk_pop_3(ctx);
+		}
+		curr_thr = curr_thr->resumer;
+	}
+	/* SCANBUILD: warning about 'thr' potentially being NULL here,
+	 * warning is incorrect because thr != NULL always here.
+	 */
+	duk_debug_write_eom(thr);
+}
+
+DUK_LOCAL void duk__debug_handle_get_locals(duk_hthread *thr, duk_heap *heap) {
+	duk_context *ctx = (duk_context *) thr;
+	duk_activation *curr_act;
+	duk_int32_t level;
+	duk_hstring *varname;
+
+	DUK_UNREF(heap);
+
+	if (duk_debug_peek_byte(thr) != DUK_DBG_IB_EOM) {
+		level = duk_debug_read_int(thr);  /* optional callstack level */
+		if (level >= 0 || -level > (duk_int32_t) thr->callstack_top) {
+			DUK_D(DUK_DPRINT("invalid callstack level for GetLocals"));
+			duk_debug_write_error_eom(thr, DUK_DBG_ERR_NOTFOUND, "invalid callstack level");
+			return;
+		}
+		duk_debug_write_reply(thr);
+	} else {
+		duk_debug_write_reply(thr);
+		if (thr->callstack_top == 0) {
+			goto callstack_empty;
+		}
+		level = -1;
+	}
+
+	curr_act = thr->callstack + thr->callstack_top + level;
+
+	/* XXX: several nice-to-have improvements here:
+	 *   - Use direct reads avoiding value stack operations
+	 *   - Avoid triggering getters, indicate getter values to debug client
+	 *   - If side effects are possible, add error catching
+	 */
+
+	duk_push_tval(ctx, &curr_act->tv_func);
+	duk_get_prop_stridx(ctx, -1, DUK_STRIDX_INT_VARMAP);
+	if (duk_is_object(ctx, -1)) {
+		duk_enum(ctx, -1, 0 /*enum_flags*/);
+		while (duk_next(ctx, -1 /*enum_index*/, 0 /*get_value*/)) {
+			varname = duk_get_hstring(ctx, -1);
+			DUK_ASSERT(varname != NULL);
+
+			duk_js_getvar_activation(thr, curr_act, varname, 0 /*throw_flag*/);
+			/* [ ... func varmap enum key value this ] */
+			duk_debug_write_hstring(thr, duk_get_hstring(ctx, -3));
+			duk_debug_write_tval(thr, duk_get_tval(ctx, -2));
+			duk_pop_3(ctx);  /* -> [ ... func varmap enum ] */
+		}
+	} else {
+		DUK_D(DUK_DPRINT("varmap is not an object in GetLocals, ignore"));
+	}
+
+ callstack_empty:
+	duk_debug_write_eom(thr);
+}
+
+DUK_LOCAL void duk__debug_handle_eval(duk_hthread *thr, duk_heap *heap) {
+	duk_context *ctx = (duk_context *) thr;
+	duk_small_uint_t call_flags;
+	duk_int_t call_ret;
+	duk_small_int_t eval_err;
+	duk_int32_t level;
+
+	DUK_UNREF(heap);
+
+	DUK_D(DUK_DPRINT("debug command Eval"));
+
+	/* The eval code is executed within the lexical environment of a specified
+	 * activation.  For now, use global object eval() function, with the eval
+	 * considered a 'direct call to eval'.
+	 *
+	 * Callstack level for debug commands only affects scope -- the callstack
+	 * as seen by, e.g. Duktape.act() will be the same regardless.
+	 */
+
+	/* nargs == 2 so we can pass a callstack level to eval(). */
+	duk_push_c_function(ctx, duk_bi_global_object_eval, 2 /*nargs*/);
+	duk_push_undefined(ctx);  /* 'this' binding shouldn't matter here */
+
+	(void) duk_debug_read_hstring(thr);
+	if (duk_debug_peek_byte(thr) != DUK_DBG_IB_EOM) {
+		level = duk_debug_read_int(thr);  /* optional callstack level */
+		if (level >= 0 || -level > (duk_int32_t) thr->callstack_top) {
+			DUK_D(DUK_DPRINT("invalid callstack level for Eval"));
+			duk_debug_write_error_eom(thr, DUK_DBG_ERR_NOTFOUND, "invalid callstack level");
+			return;
+		}
+	}
+	else {
+		level = -1;
+	}
+	DUK_ASSERT(level < 0 && -level <= (duk_int32_t) thr->callstack_top);
+	duk_push_int(ctx, level - 1);  /* compensate for eval() call */
+
+	/* [ ... eval "eval" eval_input level ] */
+
+	call_flags = 0;
+	if (thr->callstack_top >= (duk_size_t) -level) {
+		duk_activation *act;
+		duk_hobject *fun;
+
+		act = thr->callstack + thr->callstack_top + level;
+		fun = DUK_ACT_GET_FUNC(act);
+		if (fun != NULL && DUK_HOBJECT_IS_COMPILEDFUNCTION(fun)) {
+			/* Direct eval requires that there's a current
+			 * activation and it is an Ecmascript function.
+			 * When Eval is executed from e.g. cooperate API
+			 * call we'll need to do an indirect eval instead.
+			 */
+			call_flags |= DUK_CALL_FLAG_DIRECT_EVAL;
+		}
+	}
+
+	call_ret = duk_handle_call_protected(thr, 2 /*num_stack_args*/, call_flags);
+
+	if (call_ret == DUK_EXEC_SUCCESS) {
+		eval_err = 0;
+		/* Use result value as is. */
+	} else {
+		/* For errors a string coerced result is most informative
+		 * right now, as the debug client doesn't have the capability
+		 * to traverse the error object.
+		 */
+		eval_err = 1;
+		duk_safe_to_string(ctx, -1);
+	}
+
+	/* [ ... result ] */
+
+	duk_debug_write_reply(thr);
+	duk_debug_write_int(thr, (duk_int32_t) eval_err);
+	DUK_ASSERT(duk_get_tval(ctx, -1) != NULL);
+	duk_debug_write_tval(thr, duk_get_tval(ctx, -1));
+	duk_debug_write_eom(thr);
+}
+
+DUK_LOCAL void duk__debug_handle_detach(duk_hthread *thr, duk_heap *heap) {
+	DUK_UNREF(heap);
+	DUK_D(DUK_DPRINT("debug command Detach"));
+
+	duk_debug_write_reply(thr);
+	duk_debug_write_eom(thr);
+
+	DUK_D(DUK_DPRINT("debug connection detached, mark broken"));
+	DUK__SET_CONN_BROKEN(thr, 0);  /* not an error */
+}
+
+DUK_LOCAL void duk__debug_handle_apprequest(duk_hthread *thr, duk_heap *heap) {
+	duk_context *ctx = (duk_context *) thr;
+	duk_idx_t old_top;
+
+	DUK_D(DUK_DPRINT("debug command AppRequest"));
+
+	old_top = duk_get_top(ctx);  /* save stack top */
+
+	if (heap->dbg_request_cb != NULL) {
+		duk_idx_t nrets;
+		duk_idx_t nvalues = 0;
+		duk_idx_t top, idx;
+
+		/* Read tvals from the message and push them onto the valstack,
+		 * then call the request callback to process the request.
+		 */
+		while (duk_debug_peek_byte(thr) != DUK_DBG_IB_EOM) {
+			duk_tval *tv;
+			if (!duk_check_stack(ctx, 1)) {
+				DUK_D(DUK_DPRINT("failed to allocate space for request dvalue(s)"));
+				goto fail;
+			}
+			tv = duk_debug_read_tval(thr);  /* push to stack */
+			if (tv == NULL) {
+				/* detached */
+				return;
+			}
+			nvalues++;
+		}
+		DUK_ASSERT(duk_get_top(ctx) == old_top + nvalues);
+
+		/* Request callback should push values for reply to client onto valstack */
+		DUK_D(DUK_DPRINT("calling into AppRequest request_cb with nvalues=%ld, old_top=%ld, top=%ld",
+		                 (long) nvalues, (long) old_top, (long) duk_get_top(ctx)));
+		nrets = heap->dbg_request_cb(ctx, heap->dbg_udata, nvalues);
+		DUK_D(DUK_DPRINT("returned from AppRequest request_cb; nvalues=%ld -> nrets=%ld, old_top=%ld, top=%ld",
+		                 (long) nvalues, (long) nrets, (long) old_top, (long) duk_get_top(ctx)));
+		if (nrets >= 0) {
+			DUK_ASSERT(duk_get_top(ctx) >= old_top + nrets);
+			if (duk_get_top(ctx) < old_top + nrets) {
+				DUK_D(DUK_DPRINT("AppRequest callback doesn't match value stack configuration, "
+				                 "top=%ld < old_top=%ld + nrets=%ld; "
+				                 "this might mean it's unsafe to continue!",
+				                 (long) duk_get_top(ctx), (long) old_top, (long) nrets));
+				goto fail;
+			}
+
+			/* Reply with tvals pushed by request callback */
+			duk_debug_write_byte(thr, DUK_DBG_IB_REPLY);
+			top = duk_get_top(ctx);
+			for (idx = top - nrets; idx < top; idx++) {
+				duk_debug_write_tval(thr, DUK_GET_TVAL_POSIDX(ctx, idx));
+			}
+			duk_debug_write_eom(thr);
+		} else {
+			DUK_ASSERT(duk_get_top(ctx) >= old_top + 1);
+			if (duk_get_top(ctx) < old_top + 1) {
+				DUK_D(DUK_DPRINT("request callback return value doesn't match value stack configuration"));
+				goto fail;
+			}
+			duk_debug_write_error_eom(thr, DUK_DBG_ERR_APPLICATION, duk_get_string(ctx, -1));
+		}
+
+		duk_set_top(ctx, old_top);  /* restore stack top */
+	} else {
+		DUK_D(DUK_DPRINT("no request callback, treat AppRequest as unsupported"));
+		duk_debug_write_error_eom(thr, DUK_DBG_ERR_UNSUPPORTED, "AppRequest unsupported by target");
+	}
+
+	return;
+
+ fail:
+	duk_set_top(ctx, old_top);  /* restore stack top */
+	DUK__SET_CONN_BROKEN(thr, 1);
+}
+
+/*
+ *  DumpHeap command
+ */
+
+#if defined(DUK_USE_DEBUGGER_DUMPHEAP)
+/* XXX: this has some overlap with object inspection; remove this and make
+ * DumpHeap return lists of heapptrs instead?
+ */
+DUK_LOCAL void duk__debug_dump_heaphdr(duk_hthread *thr, duk_heap *heap, duk_heaphdr *hdr) {
+	DUK_UNREF(heap);
+
+	duk_debug_write_heapptr(thr, hdr);
+	duk_debug_write_uint(thr, (duk_uint32_t) DUK_HEAPHDR_GET_TYPE(hdr));
+	duk_debug_write_uint(thr, (duk_uint32_t) DUK_HEAPHDR_GET_FLAGS_RAW(hdr));
+#if defined(DUK_USE_REFERENCE_COUNTING)
+	duk_debug_write_uint(thr, (duk_uint32_t) DUK_HEAPHDR_GET_REFCOUNT(hdr));
+#else
+	duk_debug_write_int(thr, (duk_int32_t) -1);
+#endif
+
+	switch (DUK_HEAPHDR_GET_TYPE(hdr)) {
+	case DUK_HTYPE_STRING: {
+		duk_hstring *h = (duk_hstring *) hdr;
+
+		duk_debug_write_uint(thr, (duk_int32_t) DUK_HSTRING_GET_BYTELEN(h));
+		duk_debug_write_uint(thr, (duk_int32_t) DUK_HSTRING_GET_CHARLEN(h));
+		duk_debug_write_uint(thr, (duk_int32_t) DUK_HSTRING_GET_HASH(h));
+		duk_debug_write_hstring(thr, h);
+		break;
+	}
+	case DUK_HTYPE_OBJECT: {
+		duk_hobject *h = (duk_hobject *) hdr;
+		duk_hstring *k;
+		duk_uint_fast32_t i;
+
+		duk_debug_write_uint(thr, (duk_uint32_t) DUK_HOBJECT_GET_CLASS_NUMBER(h));
+		duk_debug_write_heapptr(thr, (duk_heaphdr *) DUK_HOBJECT_GET_PROTOTYPE(heap, h));
+		duk_debug_write_uint(thr, (duk_uint32_t) DUK_HOBJECT_GET_ESIZE(h));
+		duk_debug_write_uint(thr, (duk_uint32_t) DUK_HOBJECT_GET_ENEXT(h));
+		duk_debug_write_uint(thr, (duk_uint32_t) DUK_HOBJECT_GET_ASIZE(h));
+		duk_debug_write_uint(thr, (duk_uint32_t) DUK_HOBJECT_GET_HSIZE(h));
+
+		for (i = 0; i < (duk_uint_fast32_t) DUK_HOBJECT_GET_ENEXT(h); i++) {
+			duk_debug_write_uint(thr, (duk_uint32_t) DUK_HOBJECT_E_GET_FLAGS(heap, h, i));
+			k = DUK_HOBJECT_E_GET_KEY(heap, h, i);
+			duk_debug_write_heapptr(thr, (duk_heaphdr *) k);
+			if (k == NULL) {
+				duk_debug_write_int(thr, 0);  /* isAccessor */
+				duk_debug_write_unused(thr);
+				continue;
+			}
+			if (DUK_HOBJECT_E_SLOT_IS_ACCESSOR(heap, h, i)) {
+				duk_debug_write_int(thr, 1);  /* isAccessor */
+				duk_debug_write_heapptr(thr, (duk_heaphdr *) DUK_HOBJECT_E_GET_VALUE_PTR(heap, h, i)->a.get);
+				duk_debug_write_heapptr(thr, (duk_heaphdr *) DUK_HOBJECT_E_GET_VALUE_PTR(heap, h, i)->a.set);
+			} else {
+				duk_debug_write_int(thr, 0);  /* isAccessor */
+
+				duk__debug_write_tval_heapptr(thr, &DUK_HOBJECT_E_GET_VALUE_PTR(heap, h, i)->v);
+			}
+		}
+
+		for (i = 0; i < (duk_uint_fast32_t) DUK_HOBJECT_GET_ASIZE(h); i++) {
+			/* Note: array dump will include elements beyond
+			 * 'length'.
+			 */
+			duk__debug_write_tval_heapptr(thr, DUK_HOBJECT_A_GET_VALUE_PTR(heap, h, i));
+		}
+		break;
+	}
+	case DUK_HTYPE_BUFFER: {
+		duk_hbuffer *h = (duk_hbuffer *) hdr;
+
+		duk_debug_write_uint(thr, (duk_uint32_t) DUK_HBUFFER_GET_SIZE(h));
+		duk_debug_write_buffer(thr, (const char *) DUK_HBUFFER_GET_DATA_PTR(heap, h), (duk_size_t) DUK_HBUFFER_GET_SIZE(h));
+		break;
+	}
+	default: {
+		DUK_D(DUK_DPRINT("invalid htype: %d", (int) DUK_HEAPHDR_GET_TYPE(hdr)));
+	}
+	}
+}
+
+DUK_LOCAL void duk__debug_dump_heap_allocated(duk_hthread *thr, duk_heap *heap) {
+	duk_heaphdr *hdr;
+
+	hdr = heap->heap_allocated;
+	while (hdr != NULL) {
+		duk__debug_dump_heaphdr(thr, heap, hdr);
+		hdr = DUK_HEAPHDR_GET_NEXT(heap, hdr);
+	}
+}
+
+#if defined(DUK_USE_STRTAB_CHAIN)
+DUK_LOCAL void duk__debug_dump_strtab_chain(duk_hthread *thr, duk_heap *heap) {
+	duk_uint_fast32_t i, j;
+	duk_strtab_entry *e;
+#if defined(DUK_USE_HEAPPTR16)
+	duk_uint16_t *lst;
+#else
+	duk_hstring **lst;
+#endif
+	duk_hstring *h;
+
+	for (i = 0; i < DUK_STRTAB_CHAIN_SIZE; i++) {
+		e = heap->strtable + i;
+		if (e->listlen > 0) {
+#if defined(DUK_USE_HEAPPTR16)
+			lst = (duk_uint16_t *) DUK_USE_HEAPPTR_DEC16(heap->heap_udata, e->u.strlist16);
+#else
+			lst = e->u.strlist;
+#endif
+			DUK_ASSERT(lst != NULL);
+
+			for (j = 0; j < e->listlen; j++) {
+#if defined(DUK_USE_HEAPPTR16)
+				h = DUK_USE_HEAPPTR_DEC16(heap->heap_udata, lst[j]);
+#else
+				h = lst[j];
+#endif
+				if (h != NULL) {
+					duk__debug_dump_heaphdr(thr, heap, (duk_heaphdr *) h);
+				}
+			}
+		} else {
+#if defined(DUK_USE_HEAPPTR16)
+			h = DUK_USE_HEAPPTR_DEC16(heap->heap_udata, e->u.str16);
+#else
+			h = e->u.str;
+#endif
+			if (h != NULL) {
+				duk__debug_dump_heaphdr(thr, heap, (duk_heaphdr *) h);
+			}
+		}
+	}
+}
+#endif  /* DUK_USE_STRTAB_CHAIN */
+
+#if defined(DUK_USE_STRTAB_PROBE)
+DUK_LOCAL void duk__debug_dump_strtab_probe(duk_hthread *thr, duk_heap *heap) {
+	duk_uint32_t i;
+	duk_hstring *h;
+
+	for (i = 0; i < heap->st_size; i++) {
+#if defined(DUK_USE_HEAPPTR16)
+		h = DUK_USE_HEAPPTR_DEC16(heap->heap_udata, heap->strtable16[i]);
+#else
+		h = heap->strtable[i];
+#endif
+		if (h == NULL || h == DUK_STRTAB_DELETED_MARKER(heap)) {
+			continue;
+		}
+
+		duk__debug_dump_heaphdr(thr, heap, (duk_heaphdr *) h);
+	}
+}
+#endif  /* DUK_USE_STRTAB_PROBE */
+
+DUK_LOCAL void duk__debug_handle_dump_heap(duk_hthread *thr, duk_heap *heap) {
+	DUK_D(DUK_DPRINT("debug command DumpHeap"));
+
+	duk_debug_write_reply(thr);
+	duk__debug_dump_heap_allocated(thr, heap);
+#if defined(DUK_USE_STRTAB_CHAIN)
+	duk__debug_dump_strtab_chain(thr, heap);
+#endif
+#if defined(DUK_USE_STRTAB_PROBE)
+	duk__debug_dump_strtab_probe(thr, heap);
+#endif
+	duk_debug_write_eom(thr);
+}
+#endif  /* DUK_USE_DEBUGGER_DUMPHEAP */
+
+DUK_LOCAL void duk__debug_handle_get_bytecode(duk_hthread *thr, duk_heap *heap) {
+	duk_activation *act;
+	duk_hcompiledfunction *fun = NULL;
+	duk_size_t i, n;
+	duk_tval *tv;
+	duk_hobject **fn;
+	duk_int32_t level = -1;
+	duk_uint8_t ibyte;
+
+	DUK_UNREF(heap);
+
+	DUK_D(DUK_DPRINT("debug command GetBytecode"));
+
+	ibyte = duk_debug_peek_byte(thr);
+	if (ibyte != DUK_DBG_IB_EOM) {
+		tv = duk_debug_read_tval(thr);
+		if (tv == NULL) {
+			/* detached */
+			return;
+		}
+		if (DUK_TVAL_IS_OBJECT(tv)) {
+			/* tentative, checked later */
+			fun = (duk_hcompiledfunction *) DUK_TVAL_GET_OBJECT(tv);
+			DUK_ASSERT(fun != NULL);
+		} else if (DUK_TVAL_IS_NUMBER(tv)) {
+			level = (duk_int32_t) DUK_TVAL_GET_NUMBER(tv);
+		} else {
+			DUK_D(DUK_DPRINT("invalid argument to GetBytecode: %!T", tv));
+			goto fail_args;
+		}
+	}
+
+	if (fun == NULL) {
+		if (level >= 0 || -level > (duk_int32_t) thr->callstack_top) {
+			DUK_D(DUK_DPRINT("invalid callstack level for GetBytecode"));
+			goto fail_level;
+		}
+		act = thr->callstack + thr->callstack_top + level;
+		fun = (duk_hcompiledfunction *) DUK_ACT_GET_FUNC(act);
+	}
+
+	if (fun == NULL || !DUK_HOBJECT_IS_COMPILEDFUNCTION((duk_hobject *) fun)) {
+		DUK_D(DUK_DPRINT("invalid argument to GetBytecode: %!O", fun));
+		goto fail_args;
+	}
+	DUK_ASSERT(fun != NULL && DUK_HOBJECT_IS_COMPILEDFUNCTION((duk_hobject *) fun));
+
+	duk_debug_write_reply(thr);
+	n = DUK_HCOMPILEDFUNCTION_GET_CONSTS_COUNT(heap, fun);
+	duk_debug_write_int(thr, (duk_int32_t) n);
+	tv = DUK_HCOMPILEDFUNCTION_GET_CONSTS_BASE(heap, fun);
+	for (i = 0; i < n; i++) {
+		duk_debug_write_tval(thr, tv);
+		tv++;
+	}
+	n = DUK_HCOMPILEDFUNCTION_GET_FUNCS_COUNT(heap, fun);
+	duk_debug_write_int(thr, (duk_int32_t) n);
+	fn = DUK_HCOMPILEDFUNCTION_GET_FUNCS_BASE(heap, fun);
+	for (i = 0; i < n; i++) {
+		duk_debug_write_hobject(thr, *fn);
+		fn++;
+	}
+	duk_debug_write_string(thr,
+	                       (const char *) DUK_HCOMPILEDFUNCTION_GET_CODE_BASE(heap, fun),
+	                       (duk_size_t) DUK_HCOMPILEDFUNCTION_GET_CODE_SIZE(heap, fun));
+	duk_debug_write_eom(thr);
+	return;
+
+ fail_args:
+	duk_debug_write_error_eom(thr, DUK_DBG_ERR_UNKNOWN, "invalid argument");
+	return;
+
+ fail_level:
+	duk_debug_write_error_eom(thr, DUK_DBG_ERR_NOTFOUND, "invalid callstack level");
+	return;
+}
+
+/*
+ *  Object inspection commands: GetHeapObjInfo, GetObjPropDesc,
+ *  GetObjPropDescRange
+ */
+
+#if defined(DUK_USE_DEBUGGER_INSPECT)
+
+#if 0 /* pruned */
+DUK_LOCAL const char * const duk__debug_getinfo_heaphdr_keys[] = {
+	"reachable",
+	"temproot",
+	"finalizable",
+	"finalized",
+	"readonly"
+	/* NULL not needed here */
+};
+DUK_LOCAL duk_uint_t duk__debug_getinfo_heaphdr_masks[] = {
+	DUK_HEAPHDR_FLAG_REACHABLE,
+	DUK_HEAPHDR_FLAG_TEMPROOT,
+	DUK_HEAPHDR_FLAG_FINALIZABLE,
+	DUK_HEAPHDR_FLAG_FINALIZED,
+	DUK_HEAPHDR_FLAG_READONLY,
+	0  /* terminator */
+};
+#endif
+DUK_LOCAL const char * const duk__debug_getinfo_hstring_keys[] = {
+#if 0
+	"arridx",
+	"internal",
+	"reserved_word",
+	"strict_reserved_word",
+	"eval_or_arguments",
+#endif
+	"extdata"
+	/* NULL not needed here */
+};
+DUK_LOCAL duk_uint_t duk__debug_getinfo_hstring_masks[] = {
+#if 0
+	DUK_HSTRING_FLAG_ARRIDX,
+	DUK_HSTRING_FLAG_INTERNAL,
+	DUK_HSTRING_FLAG_RESERVED_WORD,
+	DUK_HSTRING_FLAG_STRICT_RESERVED_WORD,
+	DUK_HSTRING_FLAG_EVAL_OR_ARGUMENTS,
+#endif
+	DUK_HSTRING_FLAG_EXTDATA,
+	0  /* terminator */
+};
+DUK_LOCAL const char * const duk__debug_getinfo_hobject_keys[] = {
+	"extensible",
+	"constructable",
+	"bound",
+	"compiledfunction",
+	"nativefunction",
+	"bufferobject",
+	"thread",
+	"array_part",
+	"strict",
+	"notail",
+	"newenv",
+	"namebinding",
+	"createargs",
+	"envrecclosed",
+	"exotic_array",
+	"exotic_stringobj",
+	"exotic_arguments",
+	"exotic_dukfunc",
+	"exotic_proxyobj"
+	/* NULL not needed here */
+};
+DUK_LOCAL duk_uint_t duk__debug_getinfo_hobject_masks[] = {
+	DUK_HOBJECT_FLAG_EXTENSIBLE,
+	DUK_HOBJECT_FLAG_CONSTRUCTABLE,
+	DUK_HOBJECT_FLAG_BOUND,
+	DUK_HOBJECT_FLAG_COMPILEDFUNCTION,
+	DUK_HOBJECT_FLAG_NATIVEFUNCTION,
+	DUK_HOBJECT_FLAG_BUFFEROBJECT,
+	DUK_HOBJECT_FLAG_THREAD,
+	DUK_HOBJECT_FLAG_ARRAY_PART,
+	DUK_HOBJECT_FLAG_STRICT,
+	DUK_HOBJECT_FLAG_NOTAIL,
+	DUK_HOBJECT_FLAG_NEWENV,
+	DUK_HOBJECT_FLAG_NAMEBINDING,
+	DUK_HOBJECT_FLAG_CREATEARGS,
+	DUK_HOBJECT_FLAG_ENVRECCLOSED,
+	DUK_HOBJECT_FLAG_EXOTIC_ARRAY,
+	DUK_HOBJECT_FLAG_EXOTIC_STRINGOBJ,
+	DUK_HOBJECT_FLAG_EXOTIC_ARGUMENTS,
+	DUK_HOBJECT_FLAG_EXOTIC_DUKFUNC,
+	DUK_HOBJECT_FLAG_EXOTIC_PROXYOBJ,
+	0  /* terminator */
+};
+DUK_LOCAL const char * const duk__debug_getinfo_hbuffer_keys[] = {
+	"dynamic",
+	"external"
+	/* NULL not needed here */
+};
+DUK_LOCAL duk_uint_t duk__debug_getinfo_hbuffer_masks[] = {
+	DUK_HBUFFER_FLAG_DYNAMIC,
+	DUK_HBUFFER_FLAG_EXTERNAL,
+	0  /* terminator */
+};
+
+DUK_LOCAL void duk__debug_getinfo_flags_key(duk_hthread *thr, const char *key) {
+	duk_debug_write_uint(thr, 0);
+	duk_debug_write_cstring(thr, key);
+}
+
+DUK_LOCAL void duk__debug_getinfo_prop_uint(duk_hthread *thr, const char *key, duk_uint_t val) {
+	duk_debug_write_uint(thr, 0);
+	duk_debug_write_cstring(thr, key);
+	duk_debug_write_uint(thr, val);
+}
+
+DUK_LOCAL void duk__debug_getinfo_prop_int(duk_hthread *thr, const char *key, duk_int_t val) {
+	duk_debug_write_uint(thr, 0);
+	duk_debug_write_cstring(thr, key);
+	duk_debug_write_int(thr, val);
+}
+
+DUK_LOCAL void duk__debug_getinfo_prop_bool(duk_hthread *thr, const char *key, duk_bool_t val) {
+	duk_debug_write_uint(thr, 0);
+	duk_debug_write_cstring(thr, key);
+	duk_debug_write_boolean(thr, val);
+}
+
+DUK_LOCAL void duk__debug_getinfo_bitmask(duk_hthread *thr, const char * const * keys, duk_uint_t *masks, duk_uint_t flags) {
+	const char *key;
+	duk_uint_t mask;
+
+	for (;;) {
+		mask = *masks++;
+		if (!mask) {
+			break;
+		}
+		key = *keys++;
+		DUK_ASSERT(key != NULL);
+
+		DUK_DD(DUK_DDPRINT("inspect bitmask: key=%s, mask=0x%08lx, flags=0x%08lx", key, (unsigned long) mask, (unsigned long) flags));
+		duk__debug_getinfo_prop_bool(thr, key, flags & mask);
+	}
+}
+
+/* Inspect a property using a virtual index into a conceptual property list
+ * consisting of (1) all array part items from [0,a_size[ (even when above
+ * .length) and (2) all entry part items from [0,e_next[.  Unused slots are
+ * indicated using dvalue 'unused'.
+ */
+DUK_LOCAL duk_bool_t duk__debug_getprop_index(duk_hthread *thr, duk_heap *heap, duk_hobject *h_obj, duk_uint_t idx) {
+	duk_uint_t a_size;
+	duk_tval *tv;
+	duk_hstring *h_key;
+	duk_hobject *h_getset;
+	duk_uint_t flags;
+
+	DUK_UNREF(heap);
+
+	a_size = DUK_HOBJECT_GET_ASIZE(h_obj);
+	if (idx < a_size) {
+		duk_debug_write_uint(thr, DUK_PROPDESC_FLAGS_WEC);
+		duk_debug_write_uint(thr, idx);
+		tv = DUK_HOBJECT_A_GET_VALUE_PTR(heap, h_obj, idx);
+		duk_debug_write_tval(thr, tv);
+		return 1;
+	}
+
+	idx -= a_size;
+	if (idx >= DUK_HOBJECT_GET_ENEXT(h_obj)) {
+		return 0;
+	}
+
+	h_key = DUK_HOBJECT_E_GET_KEY(heap, h_obj, idx);
+	if (h_key == NULL) {
+		duk_debug_write_uint(thr, 0);
+		duk_debug_write_null(thr);
+		duk_debug_write_unused(thr);
+		return 1;
+	}
+
+	flags = DUK_HOBJECT_E_GET_FLAGS(heap, h_obj, idx);
+	if (DUK_HSTRING_HAS_INTERNAL(h_key)) {
+		flags |= DUK_DBG_PROPFLAG_INTERNAL;
+	}
+	duk_debug_write_uint(thr, flags);
+	duk_debug_write_hstring(thr, h_key);
+	if (flags & DUK_PROPDESC_FLAG_ACCESSOR) {
+		h_getset = DUK_HOBJECT_E_GET_VALUE_GETTER(heap, h_obj, idx);
+		if (h_getset) {
+			duk_debug_write_hobject(thr, h_getset);
+		} else {
+			duk_debug_write_null(thr);
+		}
+		h_getset = DUK_HOBJECT_E_GET_VALUE_SETTER(heap, h_obj, idx);
+		if (h_getset) {
+			duk_debug_write_hobject(thr, h_getset);
+		} else {
+			duk_debug_write_null(thr);
+		}
+	} else {
+		tv = DUK_HOBJECT_E_GET_VALUE_TVAL_PTR(heap, h_obj, idx);
+		duk_debug_write_tval(thr, tv);
+	}
+	return 1;
+}
+
+DUK_LOCAL void duk__debug_handle_get_heap_obj_info(duk_hthread *thr, duk_heap *heap) {
+	duk_heaphdr *h;
+
+	DUK_D(DUK_DPRINT("debug command GetHeapObjInfo"));
+	DUK_UNREF(heap);
+
+	h = duk_debug_read_any_ptr(thr);
+	if (!h) {
+		duk_debug_write_error_eom(thr, DUK_DBG_ERR_UNKNOWN, "invalid target");
+		return;
+	}
+
+	duk_debug_write_reply(thr);
+
+	/* As with all inspection code, we rely on the debug client providing
+	 * a valid, non-stale pointer: there's no portable way to safely
+	 * validate the pointer here.
+	 */
+
+	duk__debug_getinfo_flags_key(thr, "heapptr");
+	duk_debug_write_heapptr(thr, h);
+
+	/* XXX: comes out as signed now */
+	duk__debug_getinfo_prop_uint(thr, "heaphdr_flags", (duk_uint_t) DUK_HEAPHDR_GET_FLAGS(h));
+	duk__debug_getinfo_prop_uint(thr, "heaphdr_type", (duk_uint_t) DUK_HEAPHDR_GET_TYPE(h));
+#if defined(DUK_USE_REFERENCE_COUNTING)
+	duk__debug_getinfo_prop_uint(thr, "refcount", (duk_uint_t) DUK_HEAPHDR_GET_REFCOUNT(h));
+#endif
+#if 0 /* pruned */
+	duk__debug_getinfo_bitmask(thr,
+	                           duk__debug_getinfo_heaphdr_keys,
+	                           duk__debug_getinfo_heaphdr_masks,
+	                           DUK_HEAPHDR_GET_FLAGS_RAW(h));
+#endif
+
+	switch (DUK_HEAPHDR_GET_TYPE(h)) {
+	case DUK_HTYPE_STRING: {
+		duk_hstring *h_str;
+
+		h_str = (duk_hstring *) h;
+		duk__debug_getinfo_bitmask(thr,
+		                           duk__debug_getinfo_hstring_keys,
+		                           duk__debug_getinfo_hstring_masks,
+		                           DUK_HEAPHDR_GET_FLAGS_RAW(h));
+		duk__debug_getinfo_prop_uint(thr, "bytelen", DUK_HSTRING_GET_BYTELEN(h_str));
+		duk__debug_getinfo_prop_uint(thr, "charlen", DUK_HSTRING_GET_CHARLEN(h_str));
+		duk__debug_getinfo_prop_uint(thr, "hash", DUK_HSTRING_GET_HASH(h_str));
+		duk__debug_getinfo_flags_key(thr, "data");
+		duk_debug_write_hstring(thr, h_str);
+		break;
+	}
+	case DUK_HTYPE_OBJECT: {
+		duk_hobject *h_obj;
+		duk_hobject *h_proto;
+
+		h_obj = (duk_hobject *) h;
+		h_proto = DUK_HOBJECT_GET_PROTOTYPE(heap, h_obj);
+
+		/* duk_hobject specific fields. */
+		duk__debug_getinfo_bitmask(thr,
+		                           duk__debug_getinfo_hobject_keys,
+		                           duk__debug_getinfo_hobject_masks,
+		                           DUK_HEAPHDR_GET_FLAGS_RAW(h));
+		duk__debug_getinfo_prop_uint(thr, "class_number", DUK_HOBJECT_GET_CLASS_NUMBER(h_obj));
+		duk__debug_getinfo_flags_key(thr, "class_name");
+		duk_debug_write_hstring(thr, DUK_HOBJECT_GET_CLASS_STRING(heap, h_obj));
+		duk__debug_getinfo_flags_key(thr, "prototype");
+		if (h_proto != NULL) {
+			duk_debug_write_hobject(thr, h_proto);
+		} else {
+			duk_debug_write_null(thr);
+		}
+		duk__debug_getinfo_flags_key(thr, "props");
+		duk_debug_write_pointer(thr, (void *) DUK_HOBJECT_GET_PROPS(heap, h_obj));
+		duk__debug_getinfo_prop_uint(thr, "e_size", (duk_uint_t) DUK_HOBJECT_GET_ESIZE(h_obj));
+		duk__debug_getinfo_prop_uint(thr, "e_next", (duk_uint_t) DUK_HOBJECT_GET_ENEXT(h_obj));
+		duk__debug_getinfo_prop_uint(thr, "a_size", (duk_uint_t) DUK_HOBJECT_GET_ASIZE(h_obj));
+		duk__debug_getinfo_prop_uint(thr, "h_size", (duk_uint_t) DUK_HOBJECT_GET_HSIZE(h_obj));
+
+		/* duk_hnativefunction specific fields. */
+		if (DUK_HOBJECT_IS_NATIVEFUNCTION(h_obj)) {
+			duk_hnativefunction *h_fun;
+			h_fun = (duk_hnativefunction *) h_obj;
+
+			duk__debug_getinfo_prop_int(thr, "nargs", h_fun->nargs);
+			duk__debug_getinfo_prop_int(thr, "magic", h_fun->magic);
+			duk__debug_getinfo_prop_bool(thr, "varargs", h_fun->magic == DUK_HNATIVEFUNCTION_NARGS_VARARGS);
+			/* Native function pointer may be different from a void pointer,
+			 * and we serialize it from memory directly now (no byte swapping etc).
+			 */
+			duk__debug_getinfo_flags_key(thr, "funcptr");
+			duk_debug_write_buffer(thr, (const char *) &h_fun->func, sizeof(h_fun->func));
+		}
+
+		if (DUK_HOBJECT_IS_COMPILEDFUNCTION(h_obj)) {
+			duk_hcompiledfunction *h_fun;
+			duk_hbuffer *h_buf;
+			h_fun = (duk_hcompiledfunction *) h_obj;
+
+			duk__debug_getinfo_prop_int(thr, "nregs", h_fun->nregs);
+			duk__debug_getinfo_prop_int(thr, "nargs", h_fun->nargs);
+			duk__debug_getinfo_prop_uint(thr, "start_line", h_fun->start_line);
+			duk__debug_getinfo_prop_uint(thr, "end_line", h_fun->end_line);
+			h_buf = (duk_hbuffer *) DUK_HCOMPILEDFUNCTION_GET_DATA(thr->heap, h_fun);
+			if (h_buf != NULL) {
+				duk__debug_getinfo_flags_key(thr, "data");
+				duk_debug_write_heapptr(thr, (duk_heaphdr *) h_buf);
+			}
+		}
+
+		if (DUK_HOBJECT_IS_THREAD(h_obj)) {
+			/* XXX: Currently no inspection of threads, e.g. value stack, call
+			 * stack, catch stack, etc.
+			 */
+			duk_hthread *h_thr;
+			h_thr = (duk_hthread *) h_obj;
+			DUK_UNREF(h_thr);
+		}
+
+		if (DUK_HOBJECT_IS_BUFFEROBJECT(h_obj)) {
+			duk_hbufferobject *h_bufobj;
+			h_bufobj = (duk_hbufferobject *) h_obj;
+
+			duk__debug_getinfo_prop_uint(thr, "slice_offset", h_bufobj->offset);
+			duk__debug_getinfo_prop_uint(thr, "slice_length", h_bufobj->length);
+			duk__debug_getinfo_prop_uint(thr, "elem_shift", (duk_uint_t) h_bufobj->shift);
+			duk__debug_getinfo_prop_uint(thr, "elem_type", (duk_uint_t) h_bufobj->elem_type);
+			duk__debug_getinfo_prop_bool(thr, "is_view", (duk_uint_t) h_bufobj->is_view);
+			if (h_bufobj->buf != NULL) {
+				duk__debug_getinfo_flags_key(thr, "buffer");
+				duk_debug_write_heapptr(thr, (duk_heaphdr *) h_bufobj->buf);
+			}
+		}
+		break;
+	}
+	case DUK_HTYPE_BUFFER: {
+		duk_hbuffer *h_buf;
+
+		h_buf = (duk_hbuffer *) h;
+		duk__debug_getinfo_bitmask(thr,
+		                           duk__debug_getinfo_hbuffer_keys,
+		                           duk__debug_getinfo_hbuffer_masks,
+		                           DUK_HEAPHDR_GET_FLAGS_RAW(h));
+		duk__debug_getinfo_prop_uint(thr, "size", (duk_uint_t) DUK_HBUFFER_GET_SIZE(h_buf));
+		duk__debug_getinfo_flags_key(thr, "dataptr");
+		duk_debug_write_pointer(thr, (void *) DUK_HBUFFER_GET_DATA_PTR(thr->heap, h_buf));
+		duk__debug_getinfo_flags_key(thr, "data");
+		duk_debug_write_hbuffer(thr, h_buf);  /* tolerates NULL h_buf */
+		break;
+	}
+	default: {
+		/* Since we already started writing the reply, just emit nothing. */
+		DUK_D(DUK_DPRINT("inspect target pointer has invalid heaphdr type"));
+	}
+	}
+
+	duk_debug_write_eom(thr);
+}
+
+DUK_LOCAL void duk__debug_handle_get_obj_prop_desc(duk_hthread *thr, duk_heap *heap) {
+	duk_heaphdr *h;
+	duk_hobject *h_obj;
+	duk_hstring *h_key;
+	duk_propdesc desc;
+
+	DUK_D(DUK_DPRINT("debug command GetObjPropDesc"));
+	DUK_UNREF(heap);
+
+	h = duk_debug_read_any_ptr(thr);
+	if (!h) {
+		duk_debug_write_error_eom(thr, DUK_DBG_ERR_UNKNOWN, "invalid target");
+		return;
+	}
+	h_key = duk_debug_read_hstring(thr);
+	if (h == NULL || DUK_HEAPHDR_GET_TYPE(h) != DUK_HTYPE_OBJECT || h_key == NULL) {
+		goto fail_args;
+	}
+	h_obj = (duk_hobject *) h;
+
+	if (duk_hobject_get_own_propdesc(thr, h_obj, h_key, &desc, 0 /*flags*/)) {
+		duk_int_t virtual_idx;
+		duk_bool_t rc;
+
+		/* To use the shared helper need the virtual index. */
+		DUK_ASSERT(desc.e_idx >= 0 || desc.a_idx >= 0);
+		virtual_idx = (desc.a_idx >= 0 ? desc.a_idx :
+		               (duk_int_t) DUK_HOBJECT_GET_ASIZE(h_obj) + desc.e_idx);
+
+		duk_debug_write_reply(thr);
+		rc = duk__debug_getprop_index(thr, heap, h_obj, (duk_uint_t) virtual_idx);
+		DUK_ASSERT(rc == 1);
+		DUK_UNREF(rc);
+		duk_debug_write_eom(thr);
+	} else {
+		duk_debug_write_error_eom(thr, DUK_DBG_ERR_NOTFOUND, "not found");
+	}
+	return;
+
+ fail_args:
+	duk_debug_write_error_eom(thr, DUK_DBG_ERR_UNKNOWN, "invalid args");
+}
+
+DUK_LOCAL void duk__debug_handle_get_obj_prop_desc_range(duk_hthread *thr, duk_heap *heap) {
+	duk_heaphdr *h;
+	duk_hobject *h_obj;
+	duk_uint_t idx, idx_start, idx_end;
+
+	DUK_D(DUK_DPRINT("debug command GetObjPropDescRange"));
+	DUK_UNREF(heap);
+
+	h = duk_debug_read_any_ptr(thr);
+	idx_start = duk_debug_read_int(thr);
+	idx_end = duk_debug_read_int(thr);
+	if (h == NULL || DUK_HEAPHDR_GET_TYPE(h) != DUK_HTYPE_OBJECT) {
+		goto fail_args;
+	}
+	h_obj = (duk_hobject *) h;
+
+	/* The index range space is conceptually the array part followed by the
+	 * entry part.  Unlike normal enumeration all slots are exposed here as
+	 * is and return 'unused' if the slots are not in active use.  In particular
+	 * the array part is included for the full a_size regardless of what the
+	 * array .length is.
+	 */
+
+	duk_debug_write_reply(thr);
+	for (idx = idx_start; idx < idx_end; idx++) {
+		if (!duk__debug_getprop_index(thr, heap, h_obj, idx)) {
+			break;
+		}
+	}
+	duk_debug_write_eom(thr);
+	return;
+
+ fail_args:
+	duk_debug_write_error_eom(thr, DUK_DBG_ERR_UNKNOWN, "invalid args");
+}
+
+#endif  /* DUK_USE_DEBUGGER_INSPECT */
+
+/*
+ *  Process incoming debug requests
+ *
+ *  Individual request handlers can push temporaries on the value stack and
+ *  rely on duk__debug_process_message() to restore the value stack top
+ *  automatically.
+ */
+
+/* Process one debug message.  Automatically restore value stack top to its
+ * entry value, so that individual message handlers don't need exact value
+ * stack handling which is convenient.
+ */
+DUK_LOCAL void duk__debug_process_message(duk_hthread *thr) {
+	duk_context *ctx = (duk_context *) thr;
+	duk_heap *heap;
+	duk_uint8_t x;
+	duk_int32_t cmd;
+	duk_idx_t entry_top;
+
+	DUK_ASSERT(thr != NULL);
+	heap = thr->heap;
+	DUK_ASSERT(heap != NULL);
+	DUK_UNREF(ctx);
+
+	entry_top = duk_get_top(ctx);
+
+	x = duk_debug_read_byte(thr);
+	switch (x) {
+	case DUK_DBG_IB_REQUEST: {
+		cmd = duk_debug_read_int(thr);
+		switch (cmd) {
+		case DUK_DBG_CMD_BASICINFO: {
+			duk__debug_handle_basic_info(thr, heap);
+			break;
+		}
+		case DUK_DBG_CMD_TRIGGERSTATUS: {
+			duk__debug_handle_trigger_status(thr, heap);
+			break;
+		}
+		case DUK_DBG_CMD_PAUSE: {
+			duk__debug_handle_pause(thr, heap);
+			break;
+		}
+		case DUK_DBG_CMD_RESUME: {
+			duk__debug_handle_resume(thr, heap);
+			break;
+		}
+		case DUK_DBG_CMD_STEPINTO:
+		case DUK_DBG_CMD_STEPOVER:
+		case DUK_DBG_CMD_STEPOUT: {
+			duk__debug_handle_step(thr, heap, cmd);
+			break;
+		}
+		case DUK_DBG_CMD_LISTBREAK: {
+			duk__debug_handle_list_break(thr, heap);
+			break;
+		}
+		case DUK_DBG_CMD_ADDBREAK: {
+			duk__debug_handle_add_break(thr, heap);
+			break;
+		}
+		case DUK_DBG_CMD_DELBREAK: {
+			duk__debug_handle_del_break(thr, heap);
+			break;
+		}
+		case DUK_DBG_CMD_GETVAR: {
+			duk__debug_handle_get_var(thr, heap);
+			break;
+		}
+		case DUK_DBG_CMD_PUTVAR: {
+			duk__debug_handle_put_var(thr, heap);
+			break;
+		}
+		case DUK_DBG_CMD_GETCALLSTACK: {
+			duk__debug_handle_get_call_stack(thr, heap);
+			break;
+		}
+		case DUK_DBG_CMD_GETLOCALS: {
+			duk__debug_handle_get_locals(thr, heap);
+			break;
+		}
+		case DUK_DBG_CMD_EVAL: {
+			duk__debug_handle_eval(thr, heap);
+			break;
+		}
+		case DUK_DBG_CMD_DETACH: {
+			/* The actual detached_cb call is postponed to message loop so
+			 * we don't need any special precautions here (just skip to EOM
+			 * on the already closed connection).
+			 */
+			duk__debug_handle_detach(thr, heap);
+			break;
+		}
+#if defined(DUK_USE_DEBUGGER_DUMPHEAP)
+		case DUK_DBG_CMD_DUMPHEAP: {
+			duk__debug_handle_dump_heap(thr, heap);
+			break;
+		}
+#endif  /* DUK_USE_DEBUGGER_DUMPHEAP */
+		case DUK_DBG_CMD_GETBYTECODE: {
+			duk__debug_handle_get_bytecode(thr, heap);
+			break;
+		}
+		case DUK_DBG_CMD_APPREQUEST: {
+			duk__debug_handle_apprequest(thr, heap);
+			break;
+		}
+#if defined(DUK_USE_DEBUGGER_INSPECT)
+		case DUK_DBG_CMD_GETHEAPOBJINFO: {
+			duk__debug_handle_get_heap_obj_info(thr, heap);
+			break;
+		}
+		case DUK_DBG_CMD_GETOBJPROPDESC: {
+			duk__debug_handle_get_obj_prop_desc(thr, heap);
+			break;
+		}
+		case DUK_DBG_CMD_GETOBJPROPDESCRANGE: {
+			duk__debug_handle_get_obj_prop_desc_range(thr, heap);
+			break;
+		}
+#endif  /* DUK_USE_DEBUGGER_INSPECT */
+		default: {
+			DUK_D(DUK_DPRINT("debug command unsupported: %d", (int) cmd));
+			duk_debug_write_error_eom(thr, DUK_DBG_ERR_UNSUPPORTED, "unsupported command");
+		}
+		}  /* switch cmd */
+		break;
+	}
+	case DUK_DBG_IB_REPLY: {
+		DUK_D(DUK_DPRINT("debug reply, skipping"));
+		break;
+	}
+	case DUK_DBG_IB_ERROR: {
+		DUK_D(DUK_DPRINT("debug error, skipping"));
+		break;
+	}
+	case DUK_DBG_IB_NOTIFY: {
+		DUK_D(DUK_DPRINT("debug notify, skipping"));
+		break;
+	}
+	default: {
+		DUK_D(DUK_DPRINT("invalid initial byte, drop connection: %d", (int) x));
+		goto fail;
+	}
+	}  /* switch initial byte */
+
+	DUK_ASSERT(duk_get_top(ctx) >= entry_top);
+	duk_set_top(ctx, entry_top);
+	duk__debug_skip_to_eom(thr);
+	return;
+
+ fail:
+	DUK_ASSERT(duk_get_top(ctx) >= entry_top);
+	duk_set_top(ctx, entry_top);
+	DUK__SET_CONN_BROKEN(thr, 1);
+	return;
+}
+
+DUK_LOCAL void duk__check_resend_status(duk_hthread *thr) {
+	if (thr->heap->dbg_read_cb != NULL && thr->heap->dbg_state_dirty) {
+		duk_debug_send_status(thr);
+		thr->heap->dbg_state_dirty = 0;
+	}
+}
+
+DUK_INTERNAL duk_bool_t duk_debug_process_messages(duk_hthread *thr, duk_bool_t no_block) {
+	duk_context *ctx = (duk_context *) thr;
+#if defined(DUK_USE_ASSERTIONS)
+	duk_idx_t entry_top;
+#endif
+	duk_bool_t retval = 0;
+
+	DUK_ASSERT(thr != NULL);
+	DUK_UNREF(ctx);
+	DUK_ASSERT(thr->heap != NULL);
+#if defined(DUK_USE_ASSERTIONS)
+	entry_top = duk_get_top(ctx);
+#endif
+
+	DUK_D(DUK_DPRINT("process debug messages: read_cb=%s, no_block=%ld, detaching=%ld, processing=%ld",
+	                 thr->heap->dbg_read_cb ? "not NULL" : "NULL", (long) no_block,
+	                 (long) thr->heap->dbg_detaching, (long) thr->heap->dbg_processing));
+	DUK_DD(DUK_DDPRINT("top at entry: %ld", (long) duk_get_top(ctx)));
+
+	/* thr->heap->dbg_detaching may be != 0 if a debugger write outside
+	 * the message loop caused a transport error and detach1() to run.
+	 */
+	DUK_ASSERT(thr->heap->dbg_detaching == 0 || thr->heap->dbg_detaching == 1);
+	DUK_ASSERT(thr->heap->dbg_processing == 0);
+	thr->heap->dbg_processing = 1;
+
+	/* Ensure dirty state causes a Status even if never process any
+	 * messages.  This is expected by the bytecode executor when in
+	 * the running state.
+	 */
+	duk__check_resend_status(thr);
+
+	for (;;) {
+		/* Process messages until we're no longer paused or we peek
+		 * and see there's nothing to read right now.
+		 */
+		DUK_DD(DUK_DDPRINT("top at loop top: %ld", (long) duk_get_top(ctx)));
+		DUK_ASSERT(thr->heap->dbg_processing == 1);
+
+		while (thr->heap->dbg_read_cb == NULL && thr->heap->dbg_detaching) {
+			/* Detach is pending; can be triggered from outside the
+			 * debugger loop (e.g. Status notify write error) or by
+			 * previous message handling.  Call detached callback
+			 * here, in a controlled state, to ensure a possible
+			 * reattach inside the detached_cb is handled correctly.
+			 *
+			 * Recheck for detach in a while loop: an immediate
+			 * reattach involves a call to duk_debugger_attach()
+			 * which writes a debugger handshake line immediately
+			 * inside the API call.  If the transport write fails
+			 * for that handshake, we can immediately end up in a
+			 * "transport broken, detaching" case several times here.
+			 * Loop back until we're either cleanly attached or
+			 * fully detached.
+			 *
+			 * NOTE: Reset dbg_processing = 1 forcibly, in case we
+			 * re-attached; duk_debugger_attach() sets dbg_processing
+			 * to 0 at the moment.
+			 */
+
+			DUK_D(DUK_DPRINT("detach pending (dbg_read_cb == NULL, dbg_detaching != 0), call detach2"));
+
+			duk__debug_do_detach2(thr->heap);
+			thr->heap->dbg_processing = 1;  /* may be set to 0 by duk_debugger_attach() inside callback */
+
+			DUK_D(DUK_DPRINT("after detach2 (and possible reattach): dbg_read_cb=%s, dbg_detaching=%ld",
+			                 thr->heap->dbg_read_cb ? "not NULL" : "NULL", (long) thr->heap->dbg_detaching));
+		}
+		DUK_ASSERT(thr->heap->dbg_detaching == 0);  /* true even with reattach */
+		DUK_ASSERT(thr->heap->dbg_processing == 1);  /* even after a detach and possible reattach */
+
+		if (thr->heap->dbg_read_cb == NULL) {
+			DUK_D(DUK_DPRINT("debug connection broken (and not detaching), stop processing messages"));
+			break;
+		}
+
+		if (!thr->heap->dbg_paused || no_block) {
+			if (!duk_debug_read_peek(thr)) {
+				/* Note: peek cannot currently trigger a detach
+				 * so the dbg_detaching == 0 assert outside the
+				 * loop is correct.
+				 */
+				DUK_D(DUK_DPRINT("processing debug message, peek indicated no data, stop processing messages"));
+				break;
+			}
+			DUK_D(DUK_DPRINT("processing debug message, peek indicated there is data, handle it"));
+		} else {
+			DUK_D(DUK_DPRINT("paused, process debug message, blocking if necessary"));
+		}
+
+		duk__check_resend_status(thr);
+		duk__debug_process_message(thr);
+		duk__check_resend_status(thr);
+
+		retval = 1;  /* processed one or more messages */
+	}
+
+	DUK_ASSERT(thr->heap->dbg_detaching == 0);
+	DUK_ASSERT(thr->heap->dbg_processing == 1);
+	thr->heap->dbg_processing = 0;
+
+	/* As an initial implementation, read flush after exiting the message
+	 * loop.  If transport is broken, this is a no-op (with debug logs).
+	 */
+	duk_debug_read_flush(thr);  /* this cannot initiate a detach */
+	DUK_ASSERT(thr->heap->dbg_detaching == 0);
+
+	DUK_DD(DUK_DDPRINT("top at exit: %ld", (long) duk_get_top(ctx)));
+
+#if defined(DUK_USE_ASSERTIONS)
+	/* Easy to get wrong, so assert for it. */
+	DUK_ASSERT(entry_top == duk_get_top(ctx));
+#endif
+
+	return retval;
+}
+
+/*
+ *  Halt execution helper
+ */
+
+/* Halt execution and enter a debugger message loop until execution is resumed
+ * by the client.  PC for the current activation may be temporarily decremented
+ * so that the "current" instruction will be shown by the client.  This helper
+ * is callable from anywhere, also outside bytecode executor.
+ */
+
+DUK_INTERNAL void duk_debug_halt_execution(duk_hthread *thr, duk_bool_t use_prev_pc) {
+	duk_activation *act;
+	duk_hcompiledfunction *fun;
+	duk_instr_t *old_pc = NULL;
+
+	DUK_ASSERT(thr != NULL);
+	DUK_ASSERT(thr->heap != NULL);
+	DUK_ASSERT(DUK_HEAP_IS_DEBUGGER_ATTACHED(thr->heap));
+	DUK_ASSERT(thr->heap->dbg_processing == 0);
+
+	DUK_HEAP_SET_PAUSED(thr->heap);
+
+	act = duk_hthread_get_current_activation(thr);
+
+	/* NOTE: act may be NULL if an error is thrown outside of any activation,
+	 * which may happen in the case of, e.g. syntax errors.
+	 */
+
+	/* Decrement PC if that was requested, this requires a PC sync. */
+	if (act != NULL) {
+		duk_hthread_sync_currpc(thr);
+		old_pc = act->curr_pc;
+		fun = (duk_hcompiledfunction *) DUK_ACT_GET_FUNC(act);
+
+		/* Short circuit if is safe: if act->curr_pc != NULL, 'fun' is
+		 * guaranteed to be a non-NULL Ecmascript function.
+		 */
+		DUK_ASSERT(act->curr_pc == NULL ||
+		           (fun != NULL && DUK_HOBJECT_IS_COMPILEDFUNCTION((duk_hobject *) fun)));
+		if (use_prev_pc &&
+		    act->curr_pc != NULL &&
+		    act->curr_pc > DUK_HCOMPILEDFUNCTION_GET_CODE_BASE(thr->heap, fun)) {
+			act->curr_pc--;
+		}
+	}
+
+	/* Process debug messages until we are no longer paused. */
+
+	/* NOTE: This is a bit fragile.  It's important to ensure that
+	 * duk_debug_process_messages() never throws an error or
+	 * act->curr_pc will never be reset.
+	 */
+
+	thr->heap->dbg_state_dirty = 1;
+	while (thr->heap->dbg_paused) {
+		DUK_ASSERT(DUK_HEAP_IS_DEBUGGER_ATTACHED(thr->heap));
+		DUK_ASSERT(thr->heap->dbg_processing);
+		duk_debug_process_messages(thr, 0 /*no_block*/);
+	}
+
+	/* XXX: Decrementing and restoring act->curr_pc works now, but if the
+	 * debugger message loop gains the ability to adjust the current PC
+	 * (e.g. a forced jump) restoring the PC here will break.  Another
+	 * approach would be to use a state flag for the "decrement 1 from
+	 * topmost activation's PC" and take it into account whenever dealing
+	 * with PC values.
+	 */
+	if (act != NULL) {
+		act->curr_pc = old_pc;  /* restore PC */
+	}
+}
+
+/*
+ *  Breakpoint management
+ */
+
+DUK_INTERNAL duk_small_int_t duk_debug_add_breakpoint(duk_hthread *thr, duk_hstring *filename, duk_uint32_t line) {
+	duk_heap *heap;
+	duk_breakpoint *b;
+
+	/* Caller must trigger recomputation of active breakpoint list.  To
+	 * ensure stale values are not used if that doesn't happen, clear the
+	 * active breakpoint list here.
+	 */
+
+	DUK_ASSERT(thr != NULL);
+	DUK_ASSERT(filename != NULL);
+	heap = thr->heap;
+	DUK_ASSERT(heap != NULL);
+
+	if (heap->dbg_breakpoint_count >= DUK_HEAP_MAX_BREAKPOINTS) {
+		DUK_D(DUK_DPRINT("failed to add breakpoint for %O:%ld, all breakpoint slots used",
+		                 (duk_heaphdr *) filename, (long) line));
+		return -1;
+	}
+	heap->dbg_breakpoints_active[0] = (duk_breakpoint *) NULL;
+	b = heap->dbg_breakpoints + (heap->dbg_breakpoint_count++);
+	b->filename = filename;
+	b->line = line;
+	DUK_HSTRING_INCREF(thr, filename);
+
+	return heap->dbg_breakpoint_count - 1;  /* index */
+}
+
+DUK_INTERNAL duk_bool_t duk_debug_remove_breakpoint(duk_hthread *thr, duk_small_uint_t breakpoint_index) {
+	duk_heap *heap;
+	duk_hstring *h;
+	duk_breakpoint *b;
+	duk_size_t move_size;
+
+	/* Caller must trigger recomputation of active breakpoint list.  To
+	 * ensure stale values are not used if that doesn't happen, clear the
+	 * active breakpoint list here.
+	 */
+
+	DUK_ASSERT(thr != NULL);
+	heap = thr->heap;
+	DUK_ASSERT(heap != NULL);
+	DUK_ASSERT(DUK_HEAP_IS_DEBUGGER_ATTACHED(thr->heap));
+	DUK_ASSERT_DISABLE(breakpoint_index >= 0);  /* unsigned */
+
+	if (breakpoint_index >= heap->dbg_breakpoint_count) {
+		DUK_D(DUK_DPRINT("invalid breakpoint index: %ld", (long) breakpoint_index));
+		return 0;
+	}
+	b = heap->dbg_breakpoints + breakpoint_index;
+
+	h = b->filename;
+	DUK_ASSERT(h != NULL);
+
+	move_size = sizeof(duk_breakpoint) * (heap->dbg_breakpoint_count - breakpoint_index - 1);
+	if (move_size > 0) {
+		DUK_MEMMOVE((void *) b,
+		            (const void *) (b + 1),
+		            (size_t) move_size);
+	}
+	heap->dbg_breakpoint_count--;
+	heap->dbg_breakpoints_active[0] = (duk_breakpoint *) NULL;
+
+	DUK_HSTRING_DECREF(thr, h);  /* side effects */
+	DUK_UNREF(h);  /* w/o refcounting */
+
+	/* Breakpoint entries above the used area are left as garbage. */
+
+	return 1;
+}
+
+#undef DUK__SET_CONN_BROKEN
+
+#else  /* DUK_USE_DEBUGGER_SUPPORT */
+
+/* No debugger support. */
+
+#endif  /* DUK_USE_DEBUGGER_SUPPORT */


[24/51] [partial] nifi-minifi-cpp git commit: MINIFI-183 Added civet 1.9.1 sources Added onScheduled hook Added initial two-way TLS-enabled ListenHTTP implementation

Posted by al...@apache.org.
http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/extras/README.rst
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/extras/README.rst b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/extras/README.rst
new file mode 100644
index 0000000..1b70160
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/extras/README.rst
@@ -0,0 +1,13 @@
+==============
+Duktape extras
+==============
+
+Extra modules and utilities.  Extras provide functionality that doesn't
+comfortably fit into the main Duktape library, perhaps for footprint or
+portability reasons, but are still useful for most users.
+
+Extras are maintained and will be bug fixed.  However, they don't have the
+same semantic versioning guarantees like the main Duktape library.  Extras
+may be dropped without warning as Duktape is versioned.  For instance, if
+an extra breaks due to Duktape changes and there is no time to fix it, the
+missing extra won't block a release and will be dropped.


[16/51] [partial] nifi-minifi-cpp git commit: MINIFI-183 Added civet 1.9.1 sources Added onScheduled hook Added initial two-way TLS-enabled ListenHTTP implementation

Posted by al...@apache.org.
http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a9485aeb/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_api_stack.c
----------------------------------------------------------------------
diff --git a/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_api_stack.c b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_api_stack.c
new file mode 100644
index 0000000..6e8ff3e
--- /dev/null
+++ b/thirdparty/civetweb-1.9.1/src/third_party/duktape-1.5.2/src-separate/duk_api_stack.c
@@ -0,0 +1,4658 @@
+/*
+ *  API calls related to general value stack manipulation: resizing the value
+ *  stack, pushing and popping values, type checking and reading values,
+ *  coercing values, etc.
+ *
+ *  Also contains internal functions (such as duk_get_tval()), defined
+ *  in duk_api_internal.h, with semantics similar to the public API.
+ */
+
+/* XXX: repetition of stack pre-checks -> helper or macro or inline */
+/* XXX: shared api error strings, and perhaps even throw code for rare cases? */
+
+#include "duk_internal.h"
+
+/*
+ *  Forward declarations
+ */
+
+DUK_LOCAL_DECL duk_idx_t duk__push_c_function_raw(duk_context *ctx, duk_c_function func, duk_idx_t nargs, duk_uint_t flags);
+
+/*
+ *  Global state for working around missing variadic macros
+ */
+
+#ifndef DUK_USE_VARIADIC_MACROS
+DUK_EXTERNAL const char *duk_api_global_filename = NULL;
+DUK_EXTERNAL duk_int_t duk_api_global_line = 0;
+#endif
+
+/*
+ *  Misc helpers
+ */
+
+/* Check that there's room to push one value. */
+#if defined(DUK_USE_VALSTACK_UNSAFE)
+/* Faster but value stack overruns are memory unsafe. */
+#define DUK__CHECK_SPACE() do { \
+		DUK_ASSERT(!(thr->valstack_top >= thr->valstack_end)); \
+	} while (0)
+#else
+#define DUK__CHECK_SPACE() do { \
+		if (DUK_UNLIKELY(thr->valstack_top >= thr->valstack_end)) { \
+			DUK_ERROR_API(thr, DUK_STR_PUSH_BEYOND_ALLOC_STACK); \
+		} \
+	} while (0)
+#endif
+
+DUK_LOCAL_DECL duk_heaphdr *duk__get_tagged_heaphdr_raw(duk_context *ctx, duk_idx_t index, duk_uint_t tag);
+
+DUK_LOCAL duk_int_t duk__api_coerce_d2i(duk_context *ctx, duk_idx_t index, duk_bool_t require) {
+	duk_hthread *thr;
+	duk_tval *tv;
+	duk_small_int_t c;
+	duk_double_t d;
+
+	thr = (duk_hthread *) ctx;
+
+	tv = duk_get_tval(ctx, index);
+	if (tv == NULL) {
+		goto error_notnumber;
+	}
+
+	/*
+	 *  Special cases like NaN and +/- Infinity are handled explicitly
+	 *  because a plain C coercion from double to int handles these cases
+	 *  in undesirable ways.  For instance, NaN may coerce to INT_MIN
+	 *  (not zero), and INT_MAX + 1 may coerce to INT_MIN (not INT_MAX).
+	 *
+	 *  This double-to-int coercion differs from ToInteger() because it
+	 *  has a finite range (ToInteger() allows e.g. +/- Infinity).  It
+	 *  also differs from ToInt32() because the INT_MIN/INT_MAX clamping
+	 *  depends on the size of the int type on the platform.  In particular,
+	 *  on platforms with a 64-bit int type, the full range is allowed.
+	 */
+
+#if defined(DUK_USE_FASTINT)
+	if (DUK_TVAL_IS_FASTINT(tv)) {
+		duk_int64_t t = DUK_TVAL_GET_FASTINT(tv);
+#if (DUK_INT_MAX <= 0x7fffffffL)
+		/* Clamping only necessary for 32-bit ints. */
+		if (t < DUK_INT_MIN) {
+			t = DUK_INT_MIN;
+		} else if (t > DUK_INT_MAX) {
+			t = DUK_INT_MAX;
+		}
+#endif
+		return (duk_int_t) t;
+	}
+#endif
+
+	if (DUK_TVAL_IS_NUMBER(tv)) {
+		d = DUK_TVAL_GET_NUMBER(tv);
+		c = (duk_small_int_t) DUK_FPCLASSIFY(d);
+		if (c == DUK_FP_NAN) {
+			return 0;
+		} else if (d < (duk_double_t) DUK_INT_MIN) {
+			/* covers -Infinity */
+			return DUK_INT_MIN;
+		} else if (d > (duk_double_t) DUK_INT_MAX) {
+			/* covers +Infinity */
+			return DUK_INT_MAX;
+		} else {
+			/* coerce towards zero */
+			return (duk_int_t) d;
+		}
+	}
+
+ error_notnumber:
+
+	if (require) {
+		DUK_ERROR_REQUIRE_TYPE_INDEX(thr, index, "number", DUK_STR_NOT_NUMBER);
+		/* not reachable */
+	}
+	return 0;
+}
+
+DUK_LOCAL duk_uint_t duk__api_coerce_d2ui(duk_context *ctx, duk_idx_t index, duk_bool_t require) {
+	duk_hthread *thr;
+	duk_tval *tv;
+	duk_small_int_t c;
+	duk_double_t d;
+
+	/* Same as above but for unsigned int range. */
+
+	thr = (duk_hthread *) ctx;
+
+	tv = duk_get_tval(ctx, index);
+	if (tv == NULL) {
+		goto error_notnumber;
+	}
+
+#if defined(DUK_USE_FASTINT)
+	if (DUK_TVAL_IS_FASTINT(tv)) {
+		duk_int64_t t = DUK_TVAL_GET_FASTINT(tv);
+		if (t < 0) {
+			t = 0;
+		}
+#if (DUK_UINT_MAX <= 0xffffffffUL)
+		/* Clamping only necessary for 32-bit ints. */
+		else if (t > DUK_UINT_MAX) {
+			t = DUK_UINT_MAX;
+		}
+#endif
+		return (duk_uint_t) t;
+	}
+#endif
+
+	if (DUK_TVAL_IS_NUMBER(tv)) {
+		d = DUK_TVAL_GET_NUMBER(tv);
+		c = (duk_small_int_t) DUK_FPCLASSIFY(d);
+		if (c == DUK_FP_NAN) {
+			return 0;
+		} else if (d < 0.0) {
+			/* covers -Infinity */
+			return (duk_uint_t) 0;
+		} else if (d > (duk_double_t) DUK_UINT_MAX) {
+			/* covers +Infinity */
+			return (duk_uint_t) DUK_UINT_MAX;
+		} else {
+			/* coerce towards zero */
+			return (duk_uint_t) d;
+		}
+	}
+
+ error_notnumber:
+
+	if (require) {
+		DUK_ERROR_REQUIRE_TYPE_INDEX(thr, index, "number", DUK_STR_NOT_NUMBER);
+		/* not reachable */
+	}
+	return 0;
+}
+
+/*
+ *  Stack index validation/normalization and getting a stack duk_tval ptr.
+ *
+ *  These are called by many API entrypoints so the implementations must be
+ *  fast and "inlined".
+ *
+ *  There's some repetition because of this; keep the functions in sync.
+ */
+
+DUK_EXTERNAL duk_idx_t duk_normalize_index(duk_context *ctx, duk_idx_t index) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_uidx_t vs_size;
+	duk_uidx_t uindex;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+	DUK_ASSERT(DUK_INVALID_INDEX < 0);
+
+	/* Care must be taken to avoid pointer wrapping in the index
+	 * validation.  For instance, on a 32-bit platform with 8-byte
+	 * duk_tval the index 0x20000000UL would wrap the memory space
+	 * once.
+	 */
+
+	/* Assume value stack sizes (in elements) fits into duk_idx_t. */
+	DUK_ASSERT(thr->valstack_top >= thr->valstack_bottom);
+	vs_size = (duk_uidx_t) (thr->valstack_top - thr->valstack_bottom);
+	DUK_ASSERT_DISABLE(vs_size >= 0);  /* unsigned */
+
+	if (index < 0) {
+		uindex = vs_size + (duk_uidx_t) index;
+	} else {
+		/* since index non-negative */
+		DUK_ASSERT(index != DUK_INVALID_INDEX);
+		uindex = (duk_uidx_t) index;
+	}
+
+	/* DUK_INVALID_INDEX won't be accepted as a valid index. */
+	DUK_ASSERT(vs_size + (duk_uidx_t) DUK_INVALID_INDEX >= vs_size);
+
+	if (DUK_LIKELY(uindex < vs_size)) {
+		return (duk_idx_t) uindex;
+	}
+	return DUK_INVALID_INDEX;
+}
+
+DUK_EXTERNAL duk_idx_t duk_require_normalize_index(duk_context *ctx, duk_idx_t index) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_uidx_t vs_size;
+	duk_uidx_t uindex;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+	DUK_ASSERT(DUK_INVALID_INDEX < 0);
+
+	DUK_ASSERT(thr->valstack_top >= thr->valstack_bottom);
+	vs_size = (duk_uidx_t) (thr->valstack_top - thr->valstack_bottom);
+	DUK_ASSERT_DISABLE(vs_size >= 0);  /* unsigned */
+
+	if (index < 0) {
+		uindex = vs_size + (duk_uidx_t) index;
+	} else {
+		DUK_ASSERT(index != DUK_INVALID_INDEX);
+		uindex = (duk_uidx_t) index;
+	}
+
+	/* DUK_INVALID_INDEX won't be accepted as a valid index. */
+	DUK_ASSERT(vs_size + (duk_uidx_t) DUK_INVALID_INDEX >= vs_size);
+
+	if (DUK_LIKELY(uindex < vs_size)) {
+		return (duk_idx_t) uindex;
+	}
+	DUK_ERROR_API_INDEX(thr, index);
+	return 0;  /* unreachable */
+}
+
+DUK_INTERNAL duk_tval *duk_get_tval(duk_context *ctx, duk_idx_t index) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_uidx_t vs_size;
+	duk_uidx_t uindex;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+	DUK_ASSERT(DUK_INVALID_INDEX < 0);
+
+	DUK_ASSERT(thr->valstack_top >= thr->valstack_bottom);
+	vs_size = (duk_uidx_t) (thr->valstack_top - thr->valstack_bottom);
+	DUK_ASSERT_DISABLE(vs_size >= 0);  /* unsigned */
+
+	if (index < 0) {
+		uindex = vs_size + (duk_uidx_t) index;
+	} else {
+		DUK_ASSERT(index != DUK_INVALID_INDEX);
+		uindex = (duk_uidx_t) index;
+	}
+
+	/* DUK_INVALID_INDEX won't be accepted as a valid index. */
+	DUK_ASSERT(vs_size + (duk_uidx_t) DUK_INVALID_INDEX >= vs_size);
+
+	if (DUK_LIKELY(uindex < vs_size)) {
+		return thr->valstack_bottom + uindex;
+	}
+	return NULL;
+}
+
+DUK_INTERNAL duk_tval *duk_require_tval(duk_context *ctx, duk_idx_t index) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_uidx_t vs_size;
+	duk_uidx_t uindex;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+	DUK_ASSERT(DUK_INVALID_INDEX < 0);
+
+	DUK_ASSERT(thr->valstack_top >= thr->valstack_bottom);
+	vs_size = (duk_uidx_t) (thr->valstack_top - thr->valstack_bottom);
+	DUK_ASSERT_DISABLE(vs_size >= 0);  /* unsigned */
+
+	/* Use unsigned arithmetic to optimize comparison. */
+	if (index < 0) {
+		uindex = vs_size + (duk_uidx_t) index;
+	} else {
+		DUK_ASSERT(index != DUK_INVALID_INDEX);
+		uindex = (duk_uidx_t) index;
+	}
+
+	/* DUK_INVALID_INDEX won't be accepted as a valid index. */
+	DUK_ASSERT(vs_size + (duk_uidx_t) DUK_INVALID_INDEX >= vs_size);
+
+	if (DUK_LIKELY(uindex < vs_size)) {
+		return thr->valstack_bottom + uindex;
+	}
+	DUK_ERROR_API_INDEX(thr, index);
+	return NULL;
+}
+
+/* Non-critical. */
+DUK_EXTERNAL duk_bool_t duk_is_valid_index(duk_context *ctx, duk_idx_t index) {
+	DUK_ASSERT_CTX_VALID(ctx);
+	DUK_ASSERT(DUK_INVALID_INDEX < 0);
+
+	return (duk_normalize_index(ctx, index) >= 0);
+}
+
+/* Non-critical. */
+DUK_EXTERNAL void duk_require_valid_index(duk_context *ctx, duk_idx_t index) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+	DUK_ASSERT(DUK_INVALID_INDEX < 0);
+
+	if (duk_normalize_index(ctx, index) < 0) {
+		DUK_ERROR_API_INDEX(thr, index);
+		return;  /* unreachable */
+	}
+}
+
+/*
+ *  Value stack top handling
+ */
+
+DUK_EXTERNAL duk_idx_t duk_get_top(duk_context *ctx) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	return (duk_idx_t) (thr->valstack_top - thr->valstack_bottom);
+}
+
+/* Set stack top within currently allocated range, but don't reallocate.
+ * This is performance critical especially for call handling, so whenever
+ * changing, profile and look at generated code.
+ */
+DUK_EXTERNAL void duk_set_top(duk_context *ctx, duk_idx_t index) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_uidx_t vs_size;
+	duk_uidx_t vs_limit;
+	duk_uidx_t uindex;
+	duk_tval *tv;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+	DUK_ASSERT(DUK_INVALID_INDEX < 0);
+
+	DUK_ASSERT(thr->valstack_top >= thr->valstack_bottom);
+	DUK_ASSERT(thr->valstack_end >= thr->valstack_bottom);
+	vs_size = (duk_uidx_t) (thr->valstack_top - thr->valstack_bottom);
+	vs_limit = (duk_uidx_t) (thr->valstack_end - thr->valstack_bottom);
+
+	if (index < 0) {
+		/* Negative indices are always within allocated stack but
+		 * must not go below zero index.
+		 */
+		uindex = vs_size + (duk_uidx_t) index;
+	} else {
+		/* Positive index can be higher than valstack top but must
+		 * not go above allocated stack (equality is OK).
+		 */
+		uindex = (duk_uidx_t) index;
+	}
+
+	/* DUK_INVALID_INDEX won't be accepted as a valid index. */
+	DUK_ASSERT(vs_size + (duk_uidx_t) DUK_INVALID_INDEX >= vs_size);
+	DUK_ASSERT(vs_size + (duk_uidx_t) DUK_INVALID_INDEX >= vs_limit);
+
+#if defined(DUK_USE_VALSTACK_UNSAFE)
+	DUK_ASSERT(uindex <= vs_limit);
+	DUK_UNREF(vs_limit);
+#else
+	if (DUK_UNLIKELY(uindex > vs_limit)) {
+		DUK_ERROR_API_INDEX(thr, index);
+		return;  /* unreachable */
+	}
+#endif
+	DUK_ASSERT(uindex <= vs_limit);
+
+	/* Handle change in value stack top.  Respect value stack
+	 * initialization policy: 'undefined' above top.  Note that
+	 * DECREF may cause a side effect that reallocates valstack,
+	 * so must relookup after DECREF.
+	 */
+
+	if (uindex >= vs_size) {
+		/* Stack size increases or stays the same. */
+#if defined(DUK_USE_ASSERTIONS)
+		duk_uidx_t count;
+
+		count = uindex - vs_size;
+		while (count != 0) {
+			count--;
+			tv = thr->valstack_top + count;
+			DUK_ASSERT(DUK_TVAL_IS_UNDEFINED(tv));
+		}
+#endif
+		thr->valstack_top = thr->valstack_bottom + uindex;
+	} else {
+		/* Stack size decreases. */
+#if defined(DUK_USE_REFERENCE_COUNTING)
+		duk_uidx_t count;
+
+		count = vs_size - uindex;
+		DUK_ASSERT(count > 0);
+		while (count > 0) {
+			count--;
+			tv = --thr->valstack_top;  /* tv -> value just before prev top value; must relookup */
+			DUK_ASSERT(tv >= thr->valstack_bottom);
+			DUK_TVAL_SET_UNDEFINED_UPDREF(thr, tv);  /* side effects */
+		}
+#else  /* DUK_USE_REFERENCE_COUNTING */
+		duk_uidx_t count;
+		duk_tval *tv_end;
+
+		count = vs_size - uindex;
+		tv = thr->valstack_top;
+		tv_end = tv - count;
+		DUK_ASSERT(tv > tv_end);
+		do {
+			tv--;
+			DUK_TVAL_SET_UNDEFINED(tv);
+		} while (tv != tv_end);
+		thr->valstack_top = tv_end;
+#endif  /* DUK_USE_REFERENCE_COUNTING */
+	}
+}
+
+DUK_EXTERNAL duk_idx_t duk_get_top_index(duk_context *ctx) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_idx_t ret;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	ret = ((duk_idx_t) (thr->valstack_top - thr->valstack_bottom)) - 1;
+	if (DUK_UNLIKELY(ret < 0)) {
+		/* Return invalid index; if caller uses this without checking
+		 * in another API call, the index won't map to a valid stack
+		 * entry.
+		 */
+		return DUK_INVALID_INDEX;
+	}
+	return ret;
+}
+
+DUK_EXTERNAL duk_idx_t duk_require_top_index(duk_context *ctx) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_idx_t ret;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	ret = ((duk_idx_t) (thr->valstack_top - thr->valstack_bottom)) - 1;
+	if (DUK_UNLIKELY(ret < 0)) {
+		DUK_ERROR_API_INDEX(thr, -1);
+		return 0;  /* unreachable */
+	}
+	return ret;
+}
+
+/*
+ *  Value stack resizing.
+ *
+ *  This resizing happens above the current "top": the value stack can be
+ *  grown or shrunk, but the "top" is not affected.  The value stack cannot
+ *  be resized to a size below the current "top".
+ *
+ *  The low level reallocation primitive must carefully recompute all value
+ *  stack pointers, and must also work if ALL pointers are NULL.  The resize
+ *  is quite tricky because the valstack realloc may cause a mark-and-sweep,
+ *  which may run finalizers.  Running finalizers may resize the valstack
+ *  recursively (the same value stack we're working on).  So, after realloc
+ *  returns, we know that the valstack "top" should still be the same (there
+ *  should not be live values above the "top"), but its underlying size and
+ *  pointer may have changed.
+ */
+
+/* XXX: perhaps refactor this to allow caller to specify some parameters, or
+ * at least a 'compact' flag which skips any spare or round-up .. useful for
+ * emergency gc.
+ */
+
+DUK_LOCAL duk_bool_t duk__resize_valstack(duk_context *ctx, duk_size_t new_size) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_ptrdiff_t old_bottom_offset;
+	duk_ptrdiff_t old_top_offset;
+	duk_ptrdiff_t old_end_offset_post;
+#ifdef DUK_USE_DEBUG
+	duk_ptrdiff_t old_end_offset_pre;
+	duk_tval *old_valstack_pre;
+	duk_tval *old_valstack_post;
+#endif
+	duk_tval *new_valstack;
+	duk_size_t new_alloc_size;
+	duk_tval *p;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+	DUK_ASSERT(thr != NULL);
+	DUK_ASSERT(thr->valstack_bottom >= thr->valstack);
+	DUK_ASSERT(thr->valstack_top >= thr->valstack_bottom);
+	DUK_ASSERT(thr->valstack_end >= thr->valstack_top);
+	DUK_ASSERT((duk_size_t) (thr->valstack_top - thr->valstack) <= new_size);  /* can't resize below 'top' */
+	DUK_ASSERT(new_size <= thr->valstack_max);  /* valstack limit caller has check, prevents wrapping */
+	DUK_ASSERT(new_size <= DUK_SIZE_MAX / sizeof(duk_tval));  /* specific assert for wrapping */
+
+	/* get pointer offsets for tweaking below */
+	old_bottom_offset = (((duk_uint8_t *) thr->valstack_bottom) - ((duk_uint8_t *) thr->valstack));
+	old_top_offset = (((duk_uint8_t *) thr->valstack_top) - ((duk_uint8_t *) thr->valstack));
+#ifdef DUK_USE_DEBUG
+	old_end_offset_pre = (((duk_uint8_t *) thr->valstack_end) - ((duk_uint8_t *) thr->valstack));  /* not very useful, used for debugging */
+	old_valstack_pre = thr->valstack;
+#endif
+
+	/* Allocate a new valstack.
+	 *
+	 * Note: cannot use a plain DUK_REALLOC() because a mark-and-sweep may
+	 * invalidate the original thr->valstack base pointer inside the realloc
+	 * process.  See doc/memory-management.rst.
+	 */
+
+	new_alloc_size = sizeof(duk_tval) * new_size;
+	new_valstack = (duk_tval *) DUK_REALLOC_INDIRECT(thr->heap, duk_hthread_get_valstack_ptr, (void *) thr, new_alloc_size);
+	if (!new_valstack) {
+		/* Because new_size != 0, if condition doesn't need to be
+		 * (new_valstack != NULL || new_size == 0).
+		 */
+		DUK_ASSERT(new_size != 0);
+		DUK_D(DUK_DPRINT("failed to resize valstack to %lu entries (%lu bytes)",
+		                 (unsigned long) new_size, (unsigned long) new_alloc_size));
+		return 0;
+	}
+
+	/* Note: the realloc may have triggered a mark-and-sweep which may
+	 * have resized our valstack internally.  However, the mark-and-sweep
+	 * MUST NOT leave the stack bottom/top in a different state.  Particular
+	 * assumptions and facts:
+	 *
+	 *   - The thr->valstack pointer may be different after realloc,
+	 *     and the offset between thr->valstack_end <-> thr->valstack
+	 *     may have changed.
+	 *   - The offset between thr->valstack_bottom <-> thr->valstack
+	 *     and thr->valstack_top <-> thr->valstack MUST NOT have changed,
+	 *     because mark-and-sweep must adhere to a strict stack policy.
+	 *     In other words, logical bottom and top MUST NOT have changed.
+	 *   - All values above the top are unreachable but are initialized
+	 *     to UNDEFINED, up to the post-realloc valstack_end.
+	 *   - 'old_end_offset' must be computed after realloc to be correct.
+	 */
+
+	DUK_ASSERT((((duk_uint8_t *) thr->valstack_bottom) - ((duk_uint8_t *) thr->valstack)) == old_bottom_offset);
+	DUK_ASSERT((((duk_uint8_t *) thr->valstack_top) - ((duk_uint8_t *) thr->valstack)) == old_top_offset);
+
+	/* success, fixup pointers */
+	old_end_offset_post = (((duk_uint8_t *) thr->valstack_end) - ((duk_uint8_t *) thr->valstack));  /* must be computed after realloc */
+#ifdef DUK_USE_DEBUG
+	old_valstack_post = thr->valstack;
+#endif
+	thr->valstack = new_valstack;
+	thr->valstack_end = new_valstack + new_size;
+#if !defined(DUK_USE_PREFER_SIZE)
+	thr->valstack_size = new_size;
+#endif
+	thr->valstack_bottom = (duk_tval *) (void *) ((duk_uint8_t *) new_valstack + old_bottom_offset);
+	thr->valstack_top = (duk_tval *) (void *) ((duk_uint8_t *) new_valstack + old_top_offset);
+
+	DUK_ASSERT(thr->valstack_bottom >= thr->valstack);
+	DUK_ASSERT(thr->valstack_top >= thr->valstack_bottom);
+	DUK_ASSERT(thr->valstack_end >= thr->valstack_top);
+
+	/* useful for debugging */
+#ifdef DUK_USE_DEBUG
+	if (old_end_offset_pre != old_end_offset_post) {
+		DUK_D(DUK_DPRINT("valstack was resized during valstack_resize(), probably by mark-and-sweep; "
+		                 "end offset changed: %lu -> %lu",
+		                 (unsigned long) old_end_offset_pre,
+		                 (unsigned long) old_end_offset_post));
+	}
+	if (old_valstack_pre != old_valstack_post) {
+		DUK_D(DUK_DPRINT("valstack pointer changed during valstack_resize(), probably by mark-and-sweep: %p -> %p",
+		                 (void *) old_valstack_pre,
+		                 (void *) old_valstack_post));
+	}
+#endif
+
+	DUK_DD(DUK_DDPRINT("resized valstack to %lu elements (%lu bytes), bottom=%ld, top=%ld, "
+	                   "new pointers: start=%p end=%p bottom=%p top=%p",
+	                   (unsigned long) new_size, (unsigned long) new_alloc_size,
+	                   (long) (thr->valstack_bottom - thr->valstack),
+	                   (long) (thr->valstack_top - thr->valstack),
+	                   (void *) thr->valstack, (void *) thr->valstack_end,
+	                   (void *) thr->valstack_bottom, (void *) thr->valstack_top));
+
+	/* Init newly allocated slots (only). */
+	p = (duk_tval *) (void *) ((duk_uint8_t *) thr->valstack + old_end_offset_post);
+	while (p < thr->valstack_end) {
+		/* Never executed if new size is smaller. */
+		DUK_TVAL_SET_UNDEFINED(p);
+		p++;
+	}
+
+	/* Assert for value stack initialization policy. */
+#if defined(DUK_USE_ASSERTIONS)
+	p = thr->valstack_top;
+	while (p < thr->valstack_end) {
+		DUK_ASSERT(DUK_TVAL_IS_UNDEFINED(p));
+		p++;
+	}
+#endif
+
+	return 1;
+}
+
+DUK_INTERNAL
+duk_bool_t duk_valstack_resize_raw(duk_context *ctx,
+                                   duk_size_t min_new_size,
+                                   duk_small_uint_t flags) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_size_t old_size;
+	duk_size_t new_size;
+	duk_bool_t is_shrink = 0;
+	duk_small_uint_t shrink_flag = (flags & DUK_VSRESIZE_FLAG_SHRINK);
+	duk_small_uint_t compact_flag = (flags & DUK_VSRESIZE_FLAG_COMPACT);
+	duk_small_uint_t throw_flag = (flags & DUK_VSRESIZE_FLAG_THROW);
+
+	DUK_DDD(DUK_DDDPRINT("check valstack resize: min_new_size=%lu, curr_size=%ld, curr_top=%ld, "
+	                     "curr_bottom=%ld, shrink=%d, compact=%d, throw=%d",
+	                     (unsigned long) min_new_size,
+	                     (long) (thr->valstack_end - thr->valstack),
+	                     (long) (thr->valstack_top - thr->valstack),
+	                     (long) (thr->valstack_bottom - thr->valstack),
+	                     (int) shrink_flag, (int) compact_flag, (int) throw_flag));
+
+	DUK_ASSERT_CTX_VALID(ctx);
+	DUK_ASSERT(thr != NULL);
+	DUK_ASSERT(thr->valstack_bottom >= thr->valstack);
+	DUK_ASSERT(thr->valstack_top >= thr->valstack_bottom);
+	DUK_ASSERT(thr->valstack_end >= thr->valstack_top);
+
+#if defined(DUK_USE_PREFER_SIZE)
+	old_size = (duk_size_t) (thr->valstack_end - thr->valstack);
+#else
+	DUK_ASSERT((duk_size_t) (thr->valstack_end - thr->valstack) == thr->valstack_size);
+	old_size = thr->valstack_size;
+#endif
+
+	if (min_new_size <= old_size) {
+		is_shrink = 1;
+		if (!shrink_flag ||
+		    old_size - min_new_size < DUK_VALSTACK_SHRINK_THRESHOLD) {
+			DUK_DDD(DUK_DDDPRINT("no need to grow or shrink valstack"));
+			return 1;
+		}
+	}
+
+	new_size = min_new_size;
+	if (!compact_flag) {
+		if (is_shrink) {
+			/* shrink case; leave some spare */
+			new_size += DUK_VALSTACK_SHRINK_SPARE;
+		}
+
+		/* round up roughly to next 'grow step' */
+		new_size = (new_size / DUK_VALSTACK_GROW_STEP + 1) * DUK_VALSTACK_GROW_STEP;
+	}
+
+	DUK_DD(DUK_DDPRINT("want to %s valstack: %lu -> %lu elements (min_new_size %lu)",
+	                   (const char *) (new_size > old_size ? "grow" : "shrink"),
+	                   (unsigned long) old_size, (unsigned long) new_size,
+	                   (unsigned long) min_new_size));
+
+	if (new_size > thr->valstack_max) {
+		/* Note: may be triggered even if minimal new_size would not reach the limit,
+		 * plan limit accordingly (taking DUK_VALSTACK_GROW_STEP into account).
+		 */
+		if (throw_flag) {
+			DUK_ERROR_RANGE(thr, DUK_STR_VALSTACK_LIMIT);
+		} else {
+			return 0;
+		}
+	}
+
+	/*
+	 *  When resizing the valstack, a mark-and-sweep may be triggered for
+	 *  the allocation of the new valstack.  If the mark-and-sweep needs
+	 *  to use our thread for something, it may cause *the same valstack*
+	 *  to be resized recursively.  This happens e.g. when mark-and-sweep
+	 *  finalizers are called.  This is taken into account carefully in
+	 *  duk__resize_valstack().
+	 *
+	 *  'new_size' is known to be <= valstack_max, which ensures that
+	 *  size_t and pointer arithmetic won't wrap in duk__resize_valstack().
+	 */
+
+	if (!duk__resize_valstack(ctx, new_size)) {
+		if (is_shrink) {
+			DUK_DD(DUK_DDPRINT("valstack resize failed, but is a shrink, ignore"));
+			return 1;
+		}
+
+		DUK_DD(DUK_DDPRINT("valstack resize failed"));
+
+		if (throw_flag) {
+			DUK_ERROR_ALLOC_DEFMSG(thr);
+		} else {
+			return 0;
+		}
+	}
+
+	DUK_DDD(DUK_DDDPRINT("valstack resize successful"));
+	return 1;
+}
+
+DUK_EXTERNAL duk_bool_t duk_check_stack(duk_context *ctx, duk_idx_t extra) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_size_t min_new_size;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+	DUK_ASSERT(thr != NULL);
+
+	if (DUK_UNLIKELY(extra < 0)) {
+		/* Clamping to zero makes the API more robust to calling code
+		 * calculation errors.
+		 */
+		extra = 0;
+	}
+
+	min_new_size = (thr->valstack_top - thr->valstack) + extra + DUK_VALSTACK_INTERNAL_EXTRA;
+	return duk_valstack_resize_raw(ctx,
+	                               min_new_size,         /* min_new_size */
+	                               0 /* no shrink */ |   /* flags */
+	                               0 /* no compact */ |
+	                               0 /* no throw */);
+}
+
+DUK_EXTERNAL void duk_require_stack(duk_context *ctx, duk_idx_t extra) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_size_t min_new_size;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+	DUK_ASSERT(thr != NULL);
+
+	if (DUK_UNLIKELY(extra < 0)) {
+		/* Clamping to zero makes the API more robust to calling code
+		 * calculation errors.
+		 */
+		extra = 0;
+	}
+
+	min_new_size = (thr->valstack_top - thr->valstack) + extra + DUK_VALSTACK_INTERNAL_EXTRA;
+	(void) duk_valstack_resize_raw(ctx,
+	                               min_new_size,  /* min_new_size */
+	                               0 /* no shrink */ |   /* flags */
+	                               0 /* no compact */ |
+	                               DUK_VSRESIZE_FLAG_THROW);
+}
+
+DUK_EXTERNAL duk_bool_t duk_check_stack_top(duk_context *ctx, duk_idx_t top) {
+	duk_size_t min_new_size;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	if (DUK_UNLIKELY(top < 0)) {
+		/* Clamping to zero makes the API more robust to calling code
+		 * calculation errors.
+		 */
+		top = 0;
+	}
+
+	min_new_size = top + DUK_VALSTACK_INTERNAL_EXTRA;
+	return duk_valstack_resize_raw(ctx,
+	                               min_new_size,  /* min_new_size */
+	                               0 /* no shrink */ |   /* flags */
+	                               0 /* no compact */ |
+	                               0 /* no throw */);
+}
+
+DUK_EXTERNAL void duk_require_stack_top(duk_context *ctx, duk_idx_t top) {
+	duk_size_t min_new_size;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	if (DUK_UNLIKELY(top < 0)) {
+		/* Clamping to zero makes the API more robust to calling code
+		 * calculation errors.
+		 */
+		top = 0;
+	}
+
+	min_new_size = top + DUK_VALSTACK_INTERNAL_EXTRA;
+	(void) duk_valstack_resize_raw(ctx,
+	                               min_new_size,  /* min_new_size */
+	                               0 /* no shrink */ |   /* flags */
+	                               0 /* no compact */ |
+	                               DUK_VSRESIZE_FLAG_THROW);
+}
+
+/*
+ *  Basic stack manipulation: swap, dup, insert, replace, etc
+ */
+
+DUK_EXTERNAL void duk_swap(duk_context *ctx, duk_idx_t index1, duk_idx_t index2) {
+	duk_tval *tv1;
+	duk_tval *tv2;
+	duk_tval tv_tmp;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	tv1 = duk_require_tval(ctx, index1);
+	DUK_ASSERT(tv1 != NULL);
+	tv2 = duk_require_tval(ctx, index2);
+	DUK_ASSERT(tv2 != NULL);
+
+	/* If tv1==tv2 this is a NOP, no check is needed */
+	DUK_TVAL_SET_TVAL(&tv_tmp, tv1);
+	DUK_TVAL_SET_TVAL(tv1, tv2);
+	DUK_TVAL_SET_TVAL(tv2, &tv_tmp);
+}
+
+DUK_EXTERNAL void duk_swap_top(duk_context *ctx, duk_idx_t index) {
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	duk_swap(ctx, index, -1);
+}
+
+DUK_EXTERNAL void duk_dup(duk_context *ctx, duk_idx_t from_index) {
+	duk_hthread *thr;
+	duk_tval *tv_from;
+	duk_tval *tv_to;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+	thr = (duk_hthread *) ctx;
+	DUK__CHECK_SPACE();
+
+	tv_from = duk_require_tval(ctx, from_index);
+	tv_to = thr->valstack_top++;
+	DUK_ASSERT(tv_from != NULL);
+	DUK_ASSERT(tv_to != NULL);
+	DUK_TVAL_SET_TVAL(tv_to, tv_from);
+	DUK_TVAL_INCREF(thr, tv_to);  /* no side effects */
+}
+
+DUK_EXTERNAL void duk_dup_top(duk_context *ctx) {
+	duk_hthread *thr;
+	duk_tval *tv_from;
+	duk_tval *tv_to;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+	thr = (duk_hthread *) ctx;
+	DUK__CHECK_SPACE();
+
+	if (thr->valstack_top - thr->valstack_bottom <= 0) {
+		DUK_ERROR_API_INDEX(thr, -1);
+		return;  /* unreachable */
+	}
+	tv_from = thr->valstack_top - 1;
+	tv_to = thr->valstack_top++;
+	DUK_ASSERT(tv_from != NULL);
+	DUK_ASSERT(tv_to != NULL);
+	DUK_TVAL_SET_TVAL(tv_to, tv_from);
+	DUK_TVAL_INCREF(thr, tv_to);  /* no side effects */
+}
+
+DUK_EXTERNAL void duk_insert(duk_context *ctx, duk_idx_t to_index) {
+	duk_tval *p;
+	duk_tval *q;
+	duk_tval tv_tmp;
+	duk_size_t nbytes;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	p = duk_require_tval(ctx, to_index);
+	DUK_ASSERT(p != NULL);
+	q = duk_require_tval(ctx, -1);
+	DUK_ASSERT(q != NULL);
+
+	DUK_ASSERT(q >= p);
+
+	/*              nbytes
+	 *           <--------->
+	 *    [ ... | p | x | x | q ]
+	 * => [ ... | q | p | x | x ]
+	 */
+
+	nbytes = (duk_size_t) (((duk_uint8_t *) q) - ((duk_uint8_t *) p));  /* Note: 'q' is top-1 */
+
+	DUK_DDD(DUK_DDDPRINT("duk_insert: to_index=%ld, p=%p, q=%p, nbytes=%lu",
+	                     (long) to_index, (void *) p, (void *) q, (unsigned long) nbytes));
+
+	/* No net refcount changes. */
+
+	if (nbytes > 0) {
+		DUK_TVAL_SET_TVAL(&tv_tmp, q);
+		DUK_ASSERT(nbytes > 0);
+		DUK_MEMMOVE((void *) (p + 1), (const void *) p, (size_t) nbytes);
+		DUK_TVAL_SET_TVAL(p, &tv_tmp);
+	} else {
+		/* nop: insert top to top */
+		DUK_ASSERT(nbytes == 0);
+		DUK_ASSERT(p == q);
+	}
+}
+
+DUK_EXTERNAL void duk_replace(duk_context *ctx, duk_idx_t to_index) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_tval *tv1;
+	duk_tval *tv2;
+	duk_tval tv_tmp;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	tv1 = duk_require_tval(ctx, -1);
+	DUK_ASSERT(tv1 != NULL);
+	tv2 = duk_require_tval(ctx, to_index);
+	DUK_ASSERT(tv2 != NULL);
+
+	/* For tv1 == tv2, both pointing to stack top, the end result
+	 * is same as duk_pop(ctx).
+	 */
+	DUK_TVAL_SET_TVAL(&tv_tmp, tv2);
+	DUK_TVAL_SET_TVAL(tv2, tv1);
+	DUK_TVAL_SET_UNDEFINED(tv1);
+	thr->valstack_top--;
+	DUK_TVAL_DECREF(thr, &tv_tmp);  /* side effects */
+}
+
+DUK_EXTERNAL void duk_copy(duk_context *ctx, duk_idx_t from_index, duk_idx_t to_index) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_tval *tv1;
+	duk_tval *tv2;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+	DUK_UNREF(thr);  /* w/o refcounting */
+
+	tv1 = duk_require_tval(ctx, from_index);
+	DUK_ASSERT(tv1 != NULL);
+	tv2 = duk_require_tval(ctx, to_index);
+	DUK_ASSERT(tv2 != NULL);
+
+	/* For tv1 == tv2, this is a no-op (no explicit check needed). */
+	DUK_TVAL_SET_TVAL_UPDREF(thr, tv2, tv1);  /* side effects */
+}
+
+DUK_EXTERNAL void duk_remove(duk_context *ctx, duk_idx_t index) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_tval *p;
+	duk_tval *q;
+#ifdef DUK_USE_REFERENCE_COUNTING
+	duk_tval tv_tmp;
+#endif
+	duk_size_t nbytes;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	p = duk_require_tval(ctx, index);
+	DUK_ASSERT(p != NULL);
+	q = duk_require_tval(ctx, -1);
+	DUK_ASSERT(q != NULL);
+
+	DUK_ASSERT(q >= p);
+
+	/*              nbytes            zero size case
+	 *           <--------->
+	 *    [ ... | p | x | x | q ]     [ ... | p==q ]
+	 * => [ ... | x | x | q ]         [ ... ]
+	 */
+
+#ifdef DUK_USE_REFERENCE_COUNTING
+	/* use a temp: decref only when valstack reachable values are correct */
+	DUK_TVAL_SET_TVAL(&tv_tmp, p);
+#endif
+
+	nbytes = (duk_size_t) (((duk_uint8_t *) q) - ((duk_uint8_t *) p));  /* Note: 'q' is top-1 */
+	DUK_MEMMOVE((void *) p, (const void *) (p + 1), (size_t) nbytes);  /* zero size not an issue: pointers are valid */
+
+	DUK_TVAL_SET_UNDEFINED(q);
+	thr->valstack_top--;
+
+#ifdef DUK_USE_REFERENCE_COUNTING
+	DUK_TVAL_DECREF(thr, &tv_tmp);  /* side effects */
+#endif
+}
+
+/*
+ *  Stack slice primitives
+ */
+
+DUK_EXTERNAL void duk_xcopymove_raw(duk_context *to_ctx, duk_context *from_ctx, duk_idx_t count, duk_bool_t is_copy) {
+	duk_hthread *to_thr = (duk_hthread *) to_ctx;
+	duk_hthread *from_thr = (duk_hthread *) from_ctx;
+	void *src;
+	duk_size_t nbytes;
+	duk_tval *p;
+	duk_tval *q;
+
+	/* XXX: several pointer comparison issues here */
+
+	DUK_ASSERT_CTX_VALID(to_ctx);
+	DUK_ASSERT_CTX_VALID(from_ctx);
+	DUK_ASSERT(to_ctx != NULL);
+	DUK_ASSERT(from_ctx != NULL);
+
+	if (to_ctx == from_ctx) {
+		DUK_ERROR_API(to_thr, DUK_STR_INVALID_CONTEXT);
+		return;
+	}
+	if ((count < 0) ||
+	    (count > (duk_idx_t) to_thr->valstack_max)) {
+		/* Maximum value check ensures 'nbytes' won't wrap below. */
+		DUK_ERROR_API(to_thr, DUK_STR_INVALID_COUNT);
+		return;
+	}
+
+	nbytes = sizeof(duk_tval) * count;
+	if (nbytes == 0) {
+		return;
+	}
+	DUK_ASSERT(to_thr->valstack_top <= to_thr->valstack_end);
+	if ((duk_size_t) ((duk_uint8_t *) to_thr->valstack_end - (duk_uint8_t *) to_thr->valstack_top) < nbytes) {
+		DUK_ERROR_API(to_thr, DUK_STR_PUSH_BEYOND_ALLOC_STACK);
+	}
+	src = (void *) ((duk_uint8_t *) from_thr->valstack_top - nbytes);
+	if (src < (void *) from_thr->valstack_bottom) {
+		DUK_ERROR_API(to_thr, DUK_STR_INVALID_COUNT);
+	}
+
+	/* copy values (no overlap even if to_ctx == from_ctx; that's not
+	 * allowed now anyway)
+	 */
+	DUK_ASSERT(nbytes > 0);
+	DUK_MEMCPY((void *) to_thr->valstack_top, (const void *) src, (size_t) nbytes);
+
+	p = to_thr->valstack_top;
+	to_thr->valstack_top = (duk_tval *) (void *) (((duk_uint8_t *) p) + nbytes);
+
+	if (is_copy) {
+		/* Incref copies, keep originals. */
+		q = to_thr->valstack_top;
+		while (p < q) {
+			DUK_TVAL_INCREF(to_thr, p);  /* no side effects */
+			p++;
+		}
+	} else {
+		/* No net refcount change. */
+		p = from_thr->valstack_top;
+		q = (duk_tval *) (void *) (((duk_uint8_t *) p) - nbytes);
+		from_thr->valstack_top = q;
+
+		while (p > q) {
+			p--;
+			DUK_TVAL_SET_UNDEFINED(p);
+			/* XXX: fast primitive to set a bunch of values to UNDEFINED */
+		}
+	}
+}
+
+/*
+ *  Get/require
+ */
+
+DUK_EXTERNAL void duk_require_undefined(duk_context *ctx, duk_idx_t index) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_tval *tv;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	tv = duk_get_tval(ctx, index);
+	if (tv && DUK_TVAL_IS_UNDEFINED(tv)) {
+		return;
+	}
+	DUK_ERROR_REQUIRE_TYPE_INDEX(thr, index, "undefined", DUK_STR_NOT_UNDEFINED);
+	return;  /* not reachable */
+}
+
+DUK_EXTERNAL void duk_require_null(duk_context *ctx, duk_idx_t index) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_tval *tv;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	tv = duk_get_tval(ctx, index);
+	if (tv && DUK_TVAL_IS_NULL(tv)) {
+		return;
+	}
+	DUK_ERROR_REQUIRE_TYPE_INDEX(thr, index, "null", DUK_STR_NOT_NULL);
+	return;  /* not reachable */
+}
+
+DUK_EXTERNAL duk_bool_t duk_get_boolean(duk_context *ctx, duk_idx_t index) {
+	duk_bool_t ret = 0;  /* default: false */
+	duk_tval *tv;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	tv = duk_get_tval(ctx, index);
+	if (tv && DUK_TVAL_IS_BOOLEAN(tv)) {
+		ret = DUK_TVAL_GET_BOOLEAN(tv);
+	}
+
+	DUK_ASSERT(ret == 0 || ret == 1);
+	return ret;
+}
+
+DUK_EXTERNAL duk_bool_t duk_require_boolean(duk_context *ctx, duk_idx_t index) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_tval *tv;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	tv = duk_get_tval(ctx, index);
+	if (tv && DUK_TVAL_IS_BOOLEAN(tv)) {
+		duk_bool_t ret = DUK_TVAL_GET_BOOLEAN(tv);
+		DUK_ASSERT(ret == 0 || ret == 1);
+		return ret;
+	}
+	DUK_ERROR_REQUIRE_TYPE_INDEX(thr, index, "boolean", DUK_STR_NOT_BOOLEAN);
+	return 0;  /* not reachable */
+}
+
+DUK_EXTERNAL duk_double_t duk_get_number(duk_context *ctx, duk_idx_t index) {
+	duk_double_union ret;
+	duk_tval *tv;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	ret.d = DUK_DOUBLE_NAN;  /* default: NaN */
+	tv = duk_get_tval(ctx, index);
+	if (tv && DUK_TVAL_IS_NUMBER(tv)) {
+		ret.d = DUK_TVAL_GET_NUMBER(tv);
+	}
+
+	/*
+	 *  Number should already be in NaN-normalized form, but let's
+	 *  normalize anyway.
+	 */
+
+	DUK_DBLUNION_NORMALIZE_NAN_CHECK(&ret);
+	return ret.d;
+}
+
+DUK_EXTERNAL duk_double_t duk_require_number(duk_context *ctx, duk_idx_t index) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_tval *tv;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	tv = duk_get_tval(ctx, index);
+	if (tv && DUK_TVAL_IS_NUMBER(tv)) {
+		duk_double_union ret;
+		ret.d = DUK_TVAL_GET_NUMBER(tv);
+
+		/*
+		 *  Number should already be in NaN-normalized form,
+		 *  but let's normalize anyway.
+		 */
+
+		DUK_DBLUNION_NORMALIZE_NAN_CHECK(&ret);
+		return ret.d;
+	}
+	DUK_ERROR_REQUIRE_TYPE_INDEX(thr, index, "number", DUK_STR_NOT_NUMBER);
+	return DUK_DOUBLE_NAN;  /* not reachable */
+}
+
+DUK_EXTERNAL duk_int_t duk_get_int(duk_context *ctx, duk_idx_t index) {
+	/* Custom coercion for API */
+	DUK_ASSERT_CTX_VALID(ctx);
+	return (duk_int_t) duk__api_coerce_d2i(ctx, index, 0 /*require*/);
+}
+
+DUK_EXTERNAL duk_uint_t duk_get_uint(duk_context *ctx, duk_idx_t index) {
+	/* Custom coercion for API */
+	DUK_ASSERT_CTX_VALID(ctx);
+	return (duk_uint_t) duk__api_coerce_d2ui(ctx, index, 0 /*require*/);
+}
+
+DUK_EXTERNAL duk_int_t duk_require_int(duk_context *ctx, duk_idx_t index) {
+	/* Custom coercion for API */
+	DUK_ASSERT_CTX_VALID(ctx);
+	return (duk_int_t) duk__api_coerce_d2i(ctx, index, 1 /*require*/);
+}
+
+DUK_EXTERNAL duk_uint_t duk_require_uint(duk_context *ctx, duk_idx_t index) {
+	/* Custom coercion for API */
+	DUK_ASSERT_CTX_VALID(ctx);
+	return (duk_uint_t) duk__api_coerce_d2ui(ctx, index, 1 /*require*/);
+}
+
+DUK_EXTERNAL const char *duk_get_lstring(duk_context *ctx, duk_idx_t index, duk_size_t *out_len) {
+	const char *ret;
+	duk_tval *tv;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	/* default: NULL, length 0 */
+	ret = NULL;
+	if (out_len) {
+		*out_len = 0;
+	}
+
+	tv = duk_get_tval(ctx, index);
+	if (tv && DUK_TVAL_IS_STRING(tv)) {
+		/* Here we rely on duk_hstring instances always being zero
+		 * terminated even if the actual string is not.
+		 */
+		duk_hstring *h = DUK_TVAL_GET_STRING(tv);
+		DUK_ASSERT(h != NULL);
+		ret = (const char *) DUK_HSTRING_GET_DATA(h);
+		if (out_len) {
+			*out_len = DUK_HSTRING_GET_BYTELEN(h);
+		}
+	}
+
+	return ret;
+}
+
+DUK_EXTERNAL const char *duk_require_lstring(duk_context *ctx, duk_idx_t index, duk_size_t *out_len) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	const char *ret;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	/* Note: this check relies on the fact that even a zero-size string
+	 * has a non-NULL pointer.
+	 */
+	ret = duk_get_lstring(ctx, index, out_len);
+	if (ret) {
+		return ret;
+	}
+	DUK_ERROR_REQUIRE_TYPE_INDEX(thr, index, "string", DUK_STR_NOT_STRING);
+	return NULL;  /* not reachable */
+}
+
+DUK_EXTERNAL const char *duk_get_string(duk_context *ctx, duk_idx_t index) {
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	return duk_get_lstring(ctx, index, NULL);
+}
+
+DUK_EXTERNAL const char *duk_require_string(duk_context *ctx, duk_idx_t index) {
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	return duk_require_lstring(ctx, index, NULL);
+}
+
+DUK_EXTERNAL void *duk_get_pointer(duk_context *ctx, duk_idx_t index) {
+	duk_tval *tv;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	tv = duk_get_tval(ctx, index);
+	if (tv && DUK_TVAL_IS_POINTER(tv)) {
+		void *p = DUK_TVAL_GET_POINTER(tv);  /* may be NULL */
+		return (void *) p;
+	}
+
+	return NULL;
+}
+
+DUK_EXTERNAL void *duk_require_pointer(duk_context *ctx, duk_idx_t index) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_tval *tv;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	/* Note: here we must be wary of the fact that a pointer may be
+	 * valid and be a NULL.
+	 */
+	tv = duk_get_tval(ctx, index);
+	if (tv && DUK_TVAL_IS_POINTER(tv)) {
+		void *p = DUK_TVAL_GET_POINTER(tv);  /* may be NULL */
+		return (void *) p;
+	}
+	DUK_ERROR_REQUIRE_TYPE_INDEX(thr, index, "pointer", DUK_STR_NOT_POINTER);
+	return NULL;  /* not reachable */
+}
+
+#if 0  /*unused*/
+DUK_INTERNAL void *duk_get_voidptr(duk_context *ctx, duk_idx_t index) {
+	duk_tval *tv;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	tv = duk_get_tval(ctx, index);
+	if (tv && DUK_TVAL_IS_HEAP_ALLOCATED(tv)) {
+		duk_heaphdr *h = DUK_TVAL_GET_HEAPHDR(tv);
+		DUK_ASSERT(h != NULL);
+		return (void *) h;
+	}
+
+	return NULL;
+}
+#endif
+
+DUK_LOCAL void *duk__get_buffer_helper(duk_context *ctx, duk_idx_t index, duk_size_t *out_size, duk_bool_t throw_flag) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_tval *tv;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+	DUK_UNREF(thr);
+
+	if (out_size != NULL) {
+		*out_size = 0;
+	}
+
+	tv = duk_get_tval(ctx, index);
+	if (tv && DUK_TVAL_IS_BUFFER(tv)) {
+		duk_hbuffer *h = DUK_TVAL_GET_BUFFER(tv);
+		DUK_ASSERT(h != NULL);
+		if (out_size) {
+			*out_size = DUK_HBUFFER_GET_SIZE(h);
+		}
+		return (void *) DUK_HBUFFER_GET_DATA_PTR(thr->heap, h);  /* may be NULL (but only if size is 0) */
+	}
+
+	if (throw_flag) {
+		DUK_ERROR_REQUIRE_TYPE_INDEX(thr, index, "buffer", DUK_STR_NOT_BUFFER);
+	}
+	return NULL;
+}
+
+DUK_EXTERNAL void *duk_get_buffer(duk_context *ctx, duk_idx_t index, duk_size_t *out_size) {
+	return duk__get_buffer_helper(ctx, index, out_size, 0 /*throw_flag*/);
+}
+
+DUK_EXTERNAL void *duk_require_buffer(duk_context *ctx, duk_idx_t index, duk_size_t *out_size) {
+	return duk__get_buffer_helper(ctx, index, out_size, 1 /*throw_flag*/);
+}
+
+DUK_LOCAL void *duk__get_buffer_data_helper(duk_context *ctx, duk_idx_t index, duk_size_t *out_size, duk_bool_t throw_flag) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_tval *tv;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+	DUK_UNREF(thr);
+
+	if (out_size != NULL) {
+		*out_size = 0;
+	}
+
+	tv = duk_get_tval(ctx, index);
+	if (tv == NULL) {
+		goto fail;
+	}
+
+	if (DUK_TVAL_IS_BUFFER(tv)) {
+		duk_hbuffer *h = DUK_TVAL_GET_BUFFER(tv);
+		DUK_ASSERT(h != NULL);
+		if (out_size) {
+			*out_size = DUK_HBUFFER_GET_SIZE(h);
+		}
+		return (void *) DUK_HBUFFER_GET_DATA_PTR(thr->heap, h);  /* may be NULL (but only if size is 0) */
+	} else if (DUK_TVAL_IS_OBJECT(tv)) {
+		duk_hobject *h = DUK_TVAL_GET_OBJECT(tv);
+		DUK_ASSERT(h != NULL);
+		if (DUK_HOBJECT_IS_BUFFEROBJECT(h)) {
+			/* XXX: this is probably a useful shared helper: for a
+			 * duk_hbufferobject, get a validated buffer pointer/length.
+			 */
+			duk_hbufferobject *h_bufobj = (duk_hbufferobject *) h;
+			DUK_ASSERT_HBUFFEROBJECT_VALID(h_bufobj);
+
+			if (h_bufobj->buf != NULL &&
+			    DUK_HBUFFEROBJECT_VALID_SLICE(h_bufobj)) {
+				duk_uint8_t *p;
+
+				p = (duk_uint8_t *) DUK_HBUFFER_GET_DATA_PTR(thr->heap, h_bufobj->buf);
+				if (out_size != NULL) {
+					*out_size = (duk_size_t) h_bufobj->length;
+				}
+				return (void *) (p + h_bufobj->offset);
+			}
+			/* if slice not fully valid, treat as error */
+		}
+	}
+
+ fail:
+	if (throw_flag) {
+		DUK_ERROR_REQUIRE_TYPE_INDEX(thr, index, "buffer", DUK_STR_NOT_BUFFER);
+	}
+	return NULL;
+}
+
+DUK_EXTERNAL void *duk_get_buffer_data(duk_context *ctx, duk_idx_t index, duk_size_t *out_size) {
+	return duk__get_buffer_data_helper(ctx, index, out_size, 0 /*throw_flag*/);
+}
+
+DUK_EXTERNAL void *duk_require_buffer_data(duk_context *ctx, duk_idx_t index, duk_size_t *out_size) {
+	return duk__get_buffer_data_helper(ctx, index, out_size, 1 /*throw_flag*/);
+}
+
+/* Raw helper for getting a value from the stack, checking its tag.
+ * The tag cannot be a number because numbers don't have an internal
+ * tag in the packed representation.
+ */
+
+DUK_LOCAL duk_heaphdr *duk__get_tagged_heaphdr_raw(duk_context *ctx, duk_idx_t index, duk_uint_t tag) {
+	duk_tval *tv;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	tv = duk_get_tval(ctx, index);
+	if (tv && (DUK_TVAL_GET_TAG(tv) == tag)) {
+		duk_heaphdr *ret;
+		ret = DUK_TVAL_GET_HEAPHDR(tv);
+		DUK_ASSERT(ret != NULL);  /* tagged null pointers should never occur */
+		return ret;
+	}
+
+	return (duk_heaphdr *) NULL;
+}
+
+DUK_INTERNAL duk_hstring *duk_get_hstring(duk_context *ctx, duk_idx_t index) {
+	return (duk_hstring *) duk__get_tagged_heaphdr_raw(ctx, index, DUK_TAG_STRING);
+}
+
+DUK_INTERNAL duk_hstring *duk_require_hstring(duk_context *ctx, duk_idx_t index) {
+	duk_heaphdr *h;
+	h = duk__get_tagged_heaphdr_raw(ctx, index, DUK_TAG_STRING);
+	if (h == NULL) {
+		DUK_ERROR_REQUIRE_TYPE_INDEX(ctx, index, "string", DUK_STR_NOT_STRING);
+	}
+	return (duk_hstring *) h;
+}
+
+DUK_INTERNAL duk_hobject *duk_get_hobject(duk_context *ctx, duk_idx_t index) {
+	return (duk_hobject *) duk__get_tagged_heaphdr_raw(ctx, index, DUK_TAG_OBJECT);
+}
+
+DUK_INTERNAL duk_hobject *duk_require_hobject(duk_context *ctx, duk_idx_t index) {
+	duk_heaphdr *h;
+	h = duk__get_tagged_heaphdr_raw(ctx, index, DUK_TAG_OBJECT);
+	if (h == NULL) {
+		DUK_ERROR_REQUIRE_TYPE_INDEX(ctx, index, "object", DUK_STR_NOT_OBJECT);
+	}
+	return (duk_hobject *) h;
+}
+
+DUK_INTERNAL duk_hbuffer *duk_get_hbuffer(duk_context *ctx, duk_idx_t index) {
+	return (duk_hbuffer *) duk__get_tagged_heaphdr_raw(ctx, index, DUK_TAG_BUFFER);
+}
+
+DUK_INTERNAL duk_hbuffer *duk_require_hbuffer(duk_context *ctx, duk_idx_t index) {
+	duk_heaphdr *h;
+	h = duk__get_tagged_heaphdr_raw(ctx, index, DUK_TAG_BUFFER);
+	if (h == NULL) {
+		DUK_ERROR_REQUIRE_TYPE_INDEX(ctx, index, "buffer", DUK_STR_NOT_BUFFER);
+	}
+	return (duk_hbuffer *) h;
+}
+
+DUK_INTERNAL duk_hthread *duk_get_hthread(duk_context *ctx, duk_idx_t index) {
+	duk_hobject *h = (duk_hobject *) duk__get_tagged_heaphdr_raw(ctx, index, DUK_TAG_OBJECT);
+	if (h != NULL && !DUK_HOBJECT_IS_THREAD(h)) {
+		h = NULL;
+	}
+	return (duk_hthread *) h;
+}
+
+DUK_INTERNAL duk_hthread *duk_require_hthread(duk_context *ctx, duk_idx_t index) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_hobject *h = (duk_hobject *) duk__get_tagged_heaphdr_raw(ctx, index, DUK_TAG_OBJECT);
+	if (!(h != NULL && DUK_HOBJECT_IS_THREAD(h))) {
+		DUK_ERROR_REQUIRE_TYPE_INDEX(thr, index, "thread", DUK_STR_NOT_THREAD);
+	}
+	return (duk_hthread *) h;
+}
+
+DUK_INTERNAL duk_hcompiledfunction *duk_get_hcompiledfunction(duk_context *ctx, duk_idx_t index) {
+	duk_hobject *h = (duk_hobject *) duk__get_tagged_heaphdr_raw(ctx, index, DUK_TAG_OBJECT);
+	if (h != NULL && !DUK_HOBJECT_IS_COMPILEDFUNCTION(h)) {
+		h = NULL;
+	}
+	return (duk_hcompiledfunction *) h;
+}
+
+DUK_INTERNAL duk_hcompiledfunction *duk_require_hcompiledfunction(duk_context *ctx, duk_idx_t index) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_hobject *h = (duk_hobject *) duk__get_tagged_heaphdr_raw(ctx, index, DUK_TAG_OBJECT);
+	if (!(h != NULL && DUK_HOBJECT_IS_COMPILEDFUNCTION(h))) {
+		DUK_ERROR_REQUIRE_TYPE_INDEX(thr, index, "compiledfunction", DUK_STR_NOT_COMPILEDFUNCTION);
+	}
+	return (duk_hcompiledfunction *) h;
+}
+
+DUK_INTERNAL duk_hnativefunction *duk_get_hnativefunction(duk_context *ctx, duk_idx_t index) {
+	duk_hobject *h = (duk_hobject *) duk__get_tagged_heaphdr_raw(ctx, index, DUK_TAG_OBJECT);
+	if (h != NULL && !DUK_HOBJECT_IS_NATIVEFUNCTION(h)) {
+		h = NULL;
+	}
+	return (duk_hnativefunction *) h;
+}
+
+DUK_INTERNAL duk_hnativefunction *duk_require_hnativefunction(duk_context *ctx, duk_idx_t index) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_hobject *h = (duk_hobject *) duk__get_tagged_heaphdr_raw(ctx, index, DUK_TAG_OBJECT);
+	if (!(h != NULL && DUK_HOBJECT_IS_NATIVEFUNCTION(h))) {
+		DUK_ERROR_REQUIRE_TYPE_INDEX(thr, index, "nativefunction", DUK_STR_NOT_NATIVEFUNCTION);
+	}
+	return (duk_hnativefunction *) h;
+}
+
+DUK_EXTERNAL duk_c_function duk_get_c_function(duk_context *ctx, duk_idx_t index) {
+	duk_tval *tv;
+	duk_hobject *h;
+	duk_hnativefunction *f;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	tv = duk_get_tval(ctx, index);
+	if (!tv) {
+		return NULL;
+	}
+	if (!DUK_TVAL_IS_OBJECT(tv)) {
+		return NULL;
+	}
+	h = DUK_TVAL_GET_OBJECT(tv);
+	DUK_ASSERT(h != NULL);
+
+	if (!DUK_HOBJECT_IS_NATIVEFUNCTION(h)) {
+		return NULL;
+	}
+	DUK_ASSERT(DUK_HOBJECT_HAS_NATIVEFUNCTION(h));
+	f = (duk_hnativefunction *) h;
+
+	return f->func;
+}
+
+DUK_EXTERNAL duk_c_function duk_require_c_function(duk_context *ctx, duk_idx_t index) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_c_function ret;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	ret = duk_get_c_function(ctx, index);
+	if (!ret) {
+		DUK_ERROR_REQUIRE_TYPE_INDEX(thr, index, "nativefunction", DUK_STR_NOT_NATIVEFUNCTION);
+	}
+	return ret;
+}
+
+DUK_EXTERNAL void duk_require_function(duk_context *ctx, duk_idx_t index) {
+	if (!duk_is_function(ctx, index)) {
+		DUK_ERROR_REQUIRE_TYPE_INDEX((duk_hthread *) ctx, index, "function", DUK_STR_NOT_FUNCTION);
+	}
+}
+
+DUK_EXTERNAL duk_context *duk_get_context(duk_context *ctx, duk_idx_t index) {
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	return (duk_context *) duk_get_hthread(ctx, index);
+}
+
+DUK_EXTERNAL duk_context *duk_require_context(duk_context *ctx, duk_idx_t index) {
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	return (duk_context *) duk_require_hthread(ctx, index);
+}
+
+DUK_EXTERNAL void *duk_get_heapptr(duk_context *ctx, duk_idx_t index) {
+	duk_tval *tv;
+	void *ret;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	tv = duk_get_tval(ctx, index);
+	if (tv && DUK_TVAL_IS_HEAP_ALLOCATED(tv)) {
+		ret = (void *) DUK_TVAL_GET_HEAPHDR(tv);
+		DUK_ASSERT(ret != NULL);
+		return ret;
+	}
+
+	return (void *) NULL;
+}
+
+DUK_EXTERNAL void *duk_require_heapptr(duk_context *ctx, duk_idx_t index) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_tval *tv;
+	void *ret;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	tv = duk_require_tval(ctx, index);
+	DUK_ASSERT(tv != NULL);
+	if (DUK_TVAL_IS_HEAP_ALLOCATED(tv)) {
+		ret = (void *) DUK_TVAL_GET_HEAPHDR(tv);
+		DUK_ASSERT(ret != NULL);
+		return ret;
+	}
+
+	DUK_ERROR_REQUIRE_TYPE_INDEX(thr, index, "heapobject", DUK_STR_UNEXPECTED_TYPE);
+	return (void *) NULL;  /* not reachable */
+}
+
+#if 0
+/* This would be pointless: we'd return NULL for both lightfuncs and
+ * unexpected types.
+ */
+DUK_INTERNAL duk_hobject *duk_get_hobject_or_lfunc(duk_context *ctx, duk_idx_t index) {
+}
+#endif
+
+/* Useful for internal call sites where we either expect an object (function)
+ * or a lightfunc.  Accepts an object (returned as is) or a lightfunc (coerced
+ * to an object).  Return value is NULL if value is neither an object nor a
+ * lightfunc.
+ */
+DUK_INTERNAL duk_hobject *duk_get_hobject_or_lfunc_coerce(duk_context *ctx, duk_idx_t index) {
+	duk_tval *tv;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	tv = duk_require_tval(ctx, index);
+	DUK_ASSERT(tv != NULL);
+	if (DUK_TVAL_IS_OBJECT(tv)) {
+		return DUK_TVAL_GET_OBJECT(tv);
+	} else if (DUK_TVAL_IS_LIGHTFUNC(tv)) {
+		duk_to_object(ctx, index);
+		return duk_require_hobject(ctx, index);
+	}
+
+	return NULL;
+}
+
+/* Useful for internal call sites where we either expect an object (function)
+ * or a lightfunc.  Returns NULL for a lightfunc.
+ */
+DUK_INTERNAL duk_hobject *duk_require_hobject_or_lfunc(duk_context *ctx, duk_idx_t index) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_tval *tv;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	tv = duk_require_tval(ctx, index);
+	DUK_ASSERT(tv != NULL);
+	if (DUK_TVAL_IS_OBJECT(tv)) {
+		return DUK_TVAL_GET_OBJECT(tv);
+	} else if (DUK_TVAL_IS_LIGHTFUNC(tv)) {
+		return NULL;
+	}
+	DUK_ERROR_REQUIRE_TYPE_INDEX(thr, index, "object", DUK_STR_NOT_OBJECT);
+	return NULL;  /* not reachable */
+}
+
+/* Useful for internal call sites where we either expect an object (function)
+ * or a lightfunc.  Accepts an object (returned as is) or a lightfunc (coerced
+ * to an object).  Return value is never NULL.
+ */
+DUK_INTERNAL duk_hobject *duk_require_hobject_or_lfunc_coerce(duk_context *ctx, duk_idx_t index) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_tval *tv;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	tv = duk_require_tval(ctx, index);
+	if (DUK_TVAL_IS_OBJECT(tv)) {
+		return DUK_TVAL_GET_OBJECT(tv);
+	} else if (DUK_TVAL_IS_LIGHTFUNC(tv)) {
+		duk_to_object(ctx, index);
+		return duk_require_hobject(ctx, index);
+	}
+	DUK_ERROR_REQUIRE_TYPE_INDEX(thr, index, "object", DUK_STR_NOT_OBJECT);
+	return NULL;  /* not reachable */
+}
+
+DUK_INTERNAL duk_hobject *duk_get_hobject_with_class(duk_context *ctx, duk_idx_t index, duk_small_uint_t classnum) {
+	duk_hobject *h;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+	DUK_ASSERT_DISABLE(classnum >= 0);  /* unsigned */
+	DUK_ASSERT(classnum <= DUK_HOBJECT_CLASS_MAX);
+
+	h = (duk_hobject *) duk__get_tagged_heaphdr_raw(ctx, index, DUK_TAG_OBJECT);
+	if (h != NULL && DUK_HOBJECT_GET_CLASS_NUMBER(h) != classnum) {
+		h = NULL;
+	}
+	return h;
+}
+
+DUK_INTERNAL duk_hobject *duk_require_hobject_with_class(duk_context *ctx, duk_idx_t index, duk_small_uint_t classnum) {
+	duk_hthread *thr;
+	duk_hobject *h;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+	DUK_ASSERT_DISABLE(classnum >= 0);  /* unsigned */
+	DUK_ASSERT(classnum <= DUK_HOBJECT_CLASS_MAX);
+	thr = (duk_hthread *) ctx;
+
+	h = (duk_hobject *) duk__get_tagged_heaphdr_raw(ctx, index, DUK_TAG_OBJECT);
+	if (!(h != NULL && DUK_HOBJECT_GET_CLASS_NUMBER(h) == classnum)) {
+		duk_hstring *h_class;
+		h_class = DUK_HTHREAD_GET_STRING(thr, DUK_HOBJECT_CLASS_NUMBER_TO_STRIDX(classnum));
+		DUK_UNREF(h_class);
+
+		DUK_ERROR_REQUIRE_TYPE_INDEX(thr, index, (const char *) DUK_HSTRING_GET_DATA(h_class), DUK_STR_UNEXPECTED_TYPE);
+	}
+	return h;
+}
+
+DUK_EXTERNAL duk_size_t duk_get_length(duk_context *ctx, duk_idx_t index) {
+	duk_tval *tv;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	tv = duk_get_tval(ctx, index);
+	if (!tv) {
+		return 0;
+	}
+
+	switch (DUK_TVAL_GET_TAG(tv)) {
+	case DUK_TAG_UNDEFINED:
+	case DUK_TAG_NULL:
+	case DUK_TAG_BOOLEAN:
+	case DUK_TAG_POINTER:
+		return 0;
+	case DUK_TAG_STRING: {
+		duk_hstring *h = DUK_TVAL_GET_STRING(tv);
+		DUK_ASSERT(h != NULL);
+		return (duk_size_t) DUK_HSTRING_GET_CHARLEN(h);
+	}
+	case DUK_TAG_OBJECT: {
+		duk_hobject *h = DUK_TVAL_GET_OBJECT(tv);
+		DUK_ASSERT(h != NULL);
+		return (duk_size_t) duk_hobject_get_length((duk_hthread *) ctx, h);
+	}
+	case DUK_TAG_BUFFER: {
+		duk_hbuffer *h = DUK_TVAL_GET_BUFFER(tv);
+		DUK_ASSERT(h != NULL);
+		return (duk_size_t) DUK_HBUFFER_GET_SIZE(h);
+	}
+	case DUK_TAG_LIGHTFUNC: {
+		duk_small_uint_t lf_flags;
+		lf_flags = DUK_TVAL_GET_LIGHTFUNC_FLAGS(tv);
+		return (duk_size_t) DUK_LFUNC_FLAGS_GET_LENGTH(lf_flags);
+	}
+#if defined(DUK_USE_FASTINT)
+	case DUK_TAG_FASTINT:
+#endif
+	default:
+		/* number */
+		DUK_ASSERT(!DUK_TVAL_IS_UNUSED(tv));
+		DUK_ASSERT(DUK_TVAL_IS_NUMBER(tv));
+		return 0;
+	}
+
+	DUK_UNREACHABLE();
+}
+
+DUK_INTERNAL void duk_set_length(duk_context *ctx, duk_idx_t index, duk_size_t length) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_hobject *h;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	h = duk_get_hobject(ctx, index);
+	if (!h) {
+		return;
+	}
+
+	duk_hobject_set_length(thr, h, (duk_uint32_t) length);  /* XXX: typing */
+}
+
+/*
+ *  Conversions and coercions
+ *
+ *  The conversion/coercions are in-place operations on the value stack.
+ *  Some operations are implemented here directly, while others call a
+ *  helper in duk_js_ops.c after validating arguments.
+ */
+
+/* E5 Section 8.12.8 */
+
+DUK_LOCAL duk_bool_t duk__defaultvalue_coerce_attempt(duk_context *ctx, duk_idx_t index, duk_small_int_t func_stridx) {
+	if (duk_get_prop_stridx(ctx, index, func_stridx)) {
+		/* [ ... func ] */
+		if (duk_is_callable(ctx, -1)) {
+			duk_dup(ctx, index);         /* -> [ ... func this ] */
+			duk_call_method(ctx, 0);     /* -> [ ... retval ] */
+			if (duk_is_primitive(ctx, -1)) {
+				duk_replace(ctx, index);
+				return 1;
+			}
+			/* [ ... retval ]; popped below */
+		}
+	}
+	duk_pop(ctx);  /* [ ... func/retval ] -> [ ... ] */
+	return 0;
+}
+
+DUK_EXTERNAL void duk_to_defaultvalue(duk_context *ctx, duk_idx_t index, duk_int_t hint) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_hobject *obj;
+	/* inline initializer for coercers[] is not allowed by old compilers like BCC */
+	duk_small_int_t coercers[2];
+
+	DUK_ASSERT_CTX_VALID(ctx);
+	DUK_ASSERT(thr != NULL);
+
+	coercers[0] = DUK_STRIDX_VALUE_OF;
+	coercers[1] = DUK_STRIDX_TO_STRING;
+
+	index = duk_require_normalize_index(ctx, index);
+	obj = duk_require_hobject_or_lfunc(ctx, index);
+
+	if (hint == DUK_HINT_NONE) {
+		if (obj != NULL && DUK_HOBJECT_GET_CLASS_NUMBER(obj) == DUK_HOBJECT_CLASS_DATE) {
+			hint = DUK_HINT_STRING;
+		} else {
+			hint = DUK_HINT_NUMBER;
+		}
+	}
+
+	if (hint == DUK_HINT_STRING) {
+		coercers[0] = DUK_STRIDX_TO_STRING;
+		coercers[1] = DUK_STRIDX_VALUE_OF;
+	}
+
+	if (duk__defaultvalue_coerce_attempt(ctx, index, coercers[0])) {
+		return;
+	}
+
+	if (duk__defaultvalue_coerce_attempt(ctx, index, coercers[1])) {
+		return;
+	}
+
+	DUK_ERROR_TYPE(thr, DUK_STR_DEFAULTVALUE_COERCE_FAILED);
+}
+
+DUK_EXTERNAL void duk_to_undefined(duk_context *ctx, duk_idx_t index) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_tval *tv;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+	DUK_UNREF(thr);
+
+	tv = duk_require_tval(ctx, index);
+	DUK_ASSERT(tv != NULL);
+	DUK_TVAL_SET_UNDEFINED_UPDREF(thr, tv);  /* side effects */
+}
+
+DUK_EXTERNAL void duk_to_null(duk_context *ctx, duk_idx_t index) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_tval *tv;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+	DUK_UNREF(thr);
+
+	tv = duk_require_tval(ctx, index);
+	DUK_ASSERT(tv != NULL);
+	DUK_TVAL_SET_NULL_UPDREF(thr, tv);  /* side effects */
+}
+
+/* E5 Section 9.1 */
+DUK_EXTERNAL void duk_to_primitive(duk_context *ctx, duk_idx_t index, duk_int_t hint) {
+	DUK_ASSERT_CTX_VALID(ctx);
+	DUK_ASSERT(hint == DUK_HINT_NONE || hint == DUK_HINT_NUMBER || hint == DUK_HINT_STRING);
+
+	index = duk_require_normalize_index(ctx, index);
+
+	if (!duk_check_type_mask(ctx, index, DUK_TYPE_MASK_OBJECT |
+	                                     DUK_TYPE_MASK_LIGHTFUNC)) {
+		/* everything except object stay as is */
+		return;
+	}
+	duk_to_defaultvalue(ctx, index, hint);
+}
+
+/* E5 Section 9.2 */
+DUK_EXTERNAL duk_bool_t duk_to_boolean(duk_context *ctx, duk_idx_t index) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_tval *tv;
+	duk_bool_t val;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+	DUK_UNREF(thr);
+
+	index = duk_require_normalize_index(ctx, index);
+
+	tv = duk_require_tval(ctx, index);
+	DUK_ASSERT(tv != NULL);
+
+	val = duk_js_toboolean(tv);
+	DUK_ASSERT(val == 0 || val == 1);
+
+	/* Note: no need to re-lookup tv, conversion is side effect free */
+	DUK_ASSERT(tv != NULL);
+	DUK_TVAL_SET_BOOLEAN_UPDREF(thr, tv, val);  /* side effects */
+	return val;
+}
+
+DUK_EXTERNAL duk_double_t duk_to_number(duk_context *ctx, duk_idx_t index) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_tval *tv;
+	duk_double_t d;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	tv = duk_require_tval(ctx, index);
+	DUK_ASSERT(tv != NULL);
+	/* XXX: fastint? */
+	d = duk_js_tonumber(thr, tv);
+
+	/* Note: need to re-lookup because ToNumber() may have side effects */
+	tv = duk_require_tval(ctx, index);
+	DUK_TVAL_SET_NUMBER_UPDREF(thr, tv, d);  /* side effects */
+	return d;
+}
+
+/* XXX: combine all the integer conversions: they share everything
+ * but the helper function for coercion.
+ */
+
+typedef duk_double_t (*duk__toint_coercer)(duk_hthread *thr, duk_tval *tv);
+
+DUK_LOCAL duk_double_t duk__to_int_uint_helper(duk_context *ctx, duk_idx_t index, duk__toint_coercer coerce_func) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_tval *tv;
+	duk_double_t d;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	tv = duk_require_tval(ctx, index);
+	DUK_ASSERT(tv != NULL);
+	d = coerce_func(thr, tv);
+
+	/* XXX: fastint? */
+
+	/* Relookup in case coerce_func() has side effects, e.g. ends up coercing an object */
+	tv = duk_require_tval(ctx, index);
+	DUK_TVAL_SET_NUMBER_UPDREF(thr, tv, d);  /* side effects */
+	return d;
+}
+
+DUK_EXTERNAL duk_int_t duk_to_int(duk_context *ctx, duk_idx_t index) {
+	/* Value coercion (in stack): ToInteger(), E5 Section 9.4
+	 * API return value coercion: custom
+	 */
+	DUK_ASSERT_CTX_VALID(ctx);
+	(void) duk__to_int_uint_helper(ctx, index, duk_js_tointeger);
+	return (duk_int_t) duk__api_coerce_d2i(ctx, index, 0 /*require*/);
+}
+
+DUK_EXTERNAL duk_uint_t duk_to_uint(duk_context *ctx, duk_idx_t index) {
+	/* Value coercion (in stack): ToInteger(), E5 Section 9.4
+	 * API return value coercion: custom
+	 */
+	DUK_ASSERT_CTX_VALID(ctx);
+	(void) duk__to_int_uint_helper(ctx, index, duk_js_tointeger);
+	return (duk_uint_t) duk__api_coerce_d2ui(ctx, index, 0 /*require*/);
+}
+
+DUK_EXTERNAL duk_int32_t duk_to_int32(duk_context *ctx, duk_idx_t index) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_tval *tv;
+	duk_int32_t ret;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	tv = duk_require_tval(ctx, index);
+	DUK_ASSERT(tv != NULL);
+	ret = duk_js_toint32(thr, tv);
+
+	/* Relookup in case coerce_func() has side effects, e.g. ends up coercing an object */
+	tv = duk_require_tval(ctx, index);
+	DUK_TVAL_SET_FASTINT_I32_UPDREF(thr, tv, ret);  /* side effects */
+	return ret;
+}
+
+DUK_EXTERNAL duk_uint32_t duk_to_uint32(duk_context *ctx, duk_idx_t index) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_tval *tv;
+	duk_uint32_t ret;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	tv = duk_require_tval(ctx, index);
+	DUK_ASSERT(tv != NULL);
+	ret = duk_js_touint32(thr, tv);
+
+	/* Relookup in case coerce_func() has side effects, e.g. ends up coercing an object */
+	tv = duk_require_tval(ctx, index);
+	DUK_TVAL_SET_FASTINT_U32_UPDREF(thr, tv, ret);  /* side effects */
+	return ret;
+}
+
+DUK_EXTERNAL duk_uint16_t duk_to_uint16(duk_context *ctx, duk_idx_t index) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_tval *tv;
+	duk_uint16_t ret;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	tv = duk_require_tval(ctx, index);
+	DUK_ASSERT(tv != NULL);
+	ret = duk_js_touint16(thr, tv);
+
+	/* Relookup in case coerce_func() has side effects, e.g. ends up coercing an object */
+	tv = duk_require_tval(ctx, index);
+	DUK_TVAL_SET_FASTINT_U32_UPDREF(thr, tv, ret);  /* side effects */
+	return ret;
+}
+
+#if defined(DUK_USE_BUFFEROBJECT_SUPPORT)
+/* Special coercion for Uint8ClampedArray. */
+DUK_INTERNAL duk_uint8_t duk_to_uint8clamped(duk_context *ctx, duk_idx_t index) {
+	duk_double_t d;
+	duk_double_t t;
+	duk_uint8_t ret;
+
+	/* XXX: Simplify this algorithm, should be possible to come up with
+	 * a shorter and faster algorithm by inspecting IEEE representation
+	 * directly.
+	 */
+
+	d = duk_to_number(ctx, index);
+	if (d <= 0.0) {
+		return 0;
+	} else if (d >= 255) {
+		return 255;
+	} else if (DUK_ISNAN(d)) {
+		/* Avoid NaN-to-integer coercion as it is compiler specific. */
+		return 0;
+	}
+
+	t = d - DUK_FLOOR(d);
+	if (t == 0.5) {
+		/* Exact halfway, round to even. */
+		ret = (duk_uint8_t) d;
+		ret = (ret + 1) & 0xfe;  /* Example: d=3.5, t=0.5 -> ret = (3 + 1) & 0xfe = 4 & 0xfe = 4
+		                          * Example: d=4.5, t=0.5 -> ret = (4 + 1) & 0xfe = 5 & 0xfe = 4
+		                          */
+	} else {
+		/* Not halfway, round to nearest. */
+		ret = (duk_uint8_t) (d + 0.5);
+	}
+	return ret;
+}
+#endif  /* DUK_USE_BUFFEROBJECT_SUPPORT */
+
+DUK_EXTERNAL const char *duk_to_lstring(duk_context *ctx, duk_idx_t index, duk_size_t *out_len) {
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	(void) duk_to_string(ctx, index);
+	return duk_require_lstring(ctx, index, out_len);
+}
+
+DUK_LOCAL duk_ret_t duk__safe_to_string_raw(duk_context *ctx) {
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	duk_to_string(ctx, -1);
+	return 1;
+}
+
+DUK_EXTERNAL const char *duk_safe_to_lstring(duk_context *ctx, duk_idx_t index, duk_size_t *out_len) {
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	index = duk_require_normalize_index(ctx, index);
+
+	/* We intentionally ignore the duk_safe_call() return value and only
+	 * check the output type.  This way we don't also need to check that
+	 * the returned value is indeed a string in the success case.
+	 */
+
+	duk_dup(ctx, index);
+	(void) duk_safe_call(ctx, duk__safe_to_string_raw, 1 /*nargs*/, 1 /*nrets*/);
+	if (!duk_is_string(ctx, -1)) {
+		/* Error: try coercing error to string once. */
+		(void) duk_safe_call(ctx, duk__safe_to_string_raw, 1 /*nargs*/, 1 /*nrets*/);
+		if (!duk_is_string(ctx, -1)) {
+			/* Double error */
+			duk_pop(ctx);
+			duk_push_hstring_stridx(ctx, DUK_STRIDX_UC_ERROR);
+		} else {
+			;
+		}
+	} else {
+		;
+	}
+	DUK_ASSERT(duk_is_string(ctx, -1));
+	DUK_ASSERT(duk_get_string(ctx, -1) != NULL);
+
+	duk_replace(ctx, index);
+	return duk_get_lstring(ctx, index, out_len);
+}
+
+#if defined(DUK_USE_DEBUGGER_SUPPORT)  /* only needed by debugger for now */
+DUK_INTERNAL duk_hstring *duk_safe_to_hstring(duk_context *ctx, duk_idx_t index) {
+	(void) duk_safe_to_string(ctx, index);
+	DUK_ASSERT(duk_is_string(ctx, index));
+	DUK_ASSERT(duk_get_hstring(ctx, index) != NULL);
+	return duk_get_hstring(ctx, index);
+}
+#endif
+
+/* Coerce top into Object.prototype.toString() output. */
+DUK_INTERNAL void duk_to_object_class_string_top(duk_context *ctx) {
+	duk_hthread *thr;
+	duk_uint_t typemask;
+	duk_hstring *h_strclass;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+	thr = (duk_hthread *) ctx;
+	DUK_UNREF(thr);
+
+	typemask = duk_get_type_mask(ctx, -1);
+	if (typemask & DUK_TYPE_MASK_UNDEFINED) {
+		h_strclass = DUK_HTHREAD_STRING_UC_UNDEFINED(thr);
+	} else if (typemask & DUK_TYPE_MASK_NULL) {
+		h_strclass = DUK_HTHREAD_STRING_UC_NULL(thr);
+	} else {
+		duk_hobject *h_obj;
+
+		duk_to_object(ctx, -1);
+		h_obj = duk_get_hobject(ctx, -1);
+		DUK_ASSERT(h_obj != NULL);
+
+		h_strclass = DUK_HOBJECT_GET_CLASS_STRING(thr->heap, h_obj);
+	}
+	DUK_ASSERT(h_strclass != NULL);
+
+	duk_pop(ctx);
+	duk_push_sprintf(ctx, "[object %s]", (const char *) DUK_HSTRING_GET_DATA(h_strclass));
+}
+
+#if !defined(DUK_USE_PARANOID_ERRORS)
+DUK_INTERNAL void duk_push_hobject_class_string(duk_context *ctx, duk_hobject *h) {
+	duk_hthread *thr;
+	duk_hstring *h_strclass;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+	DUK_ASSERT(h != NULL);
+	thr = (duk_hthread *) ctx;
+	DUK_UNREF(thr);
+
+	h_strclass = DUK_HOBJECT_GET_CLASS_STRING(thr->heap, h);
+	DUK_ASSERT(h_strclass != NULL);
+	duk_push_sprintf(ctx, "[object %s]", (const char *) DUK_HSTRING_GET_DATA(h_strclass));
+}
+#endif  /* !DUK_USE_PARANOID_ERRORS */
+
+/* XXX: other variants like uint, u32 etc */
+DUK_INTERNAL duk_int_t duk_to_int_clamped_raw(duk_context *ctx, duk_idx_t index, duk_int_t minval, duk_int_t maxval, duk_bool_t *out_clamped) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_tval *tv;
+	duk_tval tv_tmp;
+	duk_double_t d, dmin, dmax;
+	duk_int_t res;
+	duk_bool_t clamped = 0;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	tv = duk_require_tval(ctx, index);
+	DUK_ASSERT(tv != NULL);
+	d = duk_js_tointeger(thr, tv);  /* E5 Section 9.4, ToInteger() */
+
+	dmin = (duk_double_t) minval;
+	dmax = (duk_double_t) maxval;
+
+	if (d < dmin) {
+		clamped = 1;
+		res = minval;
+		d = dmin;
+	} else if (d > dmax) {
+		clamped = 1;
+		res = maxval;
+		d = dmax;
+	} else {
+		res = (duk_int_t) d;
+	}
+	DUK_UNREF(d);  /* SCANBUILD: with suitable dmin/dmax limits 'd' is unused */
+	/* 'd' and 'res' agree here */
+
+	/* Relookup in case duk_js_tointeger() ends up e.g. coercing an object. */
+	tv = duk_get_tval(ctx, index);
+	DUK_ASSERT(tv != NULL);  /* not popped by side effect */
+	DUK_TVAL_SET_TVAL(&tv_tmp, tv);
+#if defined(DUK_USE_FASTINT)
+#if (DUK_INT_MAX <= 0x7fffffffL)
+	DUK_TVAL_SET_FASTINT_I32(tv, res);
+#else
+	/* Clamping needed if duk_int_t is 64 bits. */
+	if (res >= DUK_FASTINT_MIN && res <= DUK_FASTINT_MAX) {
+		DUK_TVAL_SET_FASTINT(tv, res);
+	} else {
+		DUK_TVAL_SET_NUMBER(tv, d);
+	}
+#endif
+#else
+	DUK_TVAL_SET_NUMBER(tv, d);  /* no need to incref */
+#endif
+	DUK_TVAL_DECREF(thr, &tv_tmp);  /* side effects */
+
+	if (out_clamped) {
+		*out_clamped = clamped;
+	} else {
+		/* coerced value is updated to value stack even when RangeError thrown */
+		if (clamped) {
+			DUK_ERROR_RANGE(thr, DUK_STR_NUMBER_OUTSIDE_RANGE);
+		}
+	}
+
+	return res;
+}
+
+DUK_INTERNAL duk_int_t duk_to_int_clamped(duk_context *ctx, duk_idx_t index, duk_idx_t minval, duk_idx_t maxval) {
+	duk_bool_t dummy;
+	return duk_to_int_clamped_raw(ctx, index, minval, maxval, &dummy);
+}
+
+DUK_INTERNAL duk_int_t duk_to_int_check_range(duk_context *ctx, duk_idx_t index, duk_int_t minval, duk_int_t maxval) {
+	return duk_to_int_clamped_raw(ctx, index, minval, maxval, NULL);  /* out_clamped==NULL -> RangeError if outside range */
+}
+
+DUK_EXTERNAL const char *duk_to_string(duk_context *ctx, duk_idx_t index) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_tval *tv;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+	DUK_UNREF(thr);
+
+	index = duk_require_normalize_index(ctx, index);
+
+	tv = duk_require_tval(ctx, index);
+	DUK_ASSERT(tv != NULL);
+
+	switch (DUK_TVAL_GET_TAG(tv)) {
+	case DUK_TAG_UNDEFINED: {
+		duk_push_hstring_stridx(ctx, DUK_STRIDX_LC_UNDEFINED);
+		break;
+	}
+	case DUK_TAG_NULL: {
+		duk_push_hstring_stridx(ctx, DUK_STRIDX_LC_NULL);
+		break;
+	}
+	case DUK_TAG_BOOLEAN: {
+		if (DUK_TVAL_GET_BOOLEAN(tv)) {
+			duk_push_hstring_stridx(ctx, DUK_STRIDX_TRUE);
+		} else {
+			duk_push_hstring_stridx(ctx, DUK_STRIDX_FALSE);
+		}
+		break;
+	}
+	case DUK_TAG_STRING: {
+		/* nop */
+		goto skip_replace;
+	}
+	case DUK_TAG_OBJECT: {
+		duk_to_primitive(ctx, index, DUK_HINT_STRING);
+		return duk_to_string(ctx, index);  /* Note: recursive call */
+	}
+	case DUK_TAG_BUFFER: {
+		duk_hbuffer *h = DUK_TVAL_GET_BUFFER(tv);
+
+		/* Note: this allows creation of internal strings. */
+
+		DUK_ASSERT(h != NULL);
+		duk_push_lstring(ctx,
+		                 (const char *) DUK_HBUFFER_GET_DATA_PTR(thr->heap, h),
+		                 (duk_size_t) DUK_HBUFFER_GET_SIZE(h));
+		break;
+	}
+	case DUK_TAG_POINTER: {
+		void *ptr = DUK_TVAL_GET_POINTER(tv);
+		if (ptr != NULL) {
+			duk_push_sprintf(ctx, DUK_STR_FMT_PTR, (void *) ptr);
+		} else {
+			/* Represent a null pointer as 'null' to be consistent with
+			 * the JX format variant.  Native '%p' format for a NULL
+			 * pointer may be e.g. '(nil)'.
+			 */
+			duk_push_hstring_stridx(ctx, DUK_STRIDX_LC_NULL);
+		}
+		break;
+	}
+	case DUK_TAG_LIGHTFUNC: {
+		/* Should match Function.prototype.toString() */
+		duk_push_lightfunc_tostring(ctx, tv);
+		break;
+	}
+#if defined(DUK_USE_FASTINT)
+	case DUK_TAG_FASTINT:
+#endif
+	default: {
+		/* number */
+		DUK_ASSERT(!DUK_TVAL_IS_UNUSED(tv));
+		DUK_ASSERT(DUK_TVAL_IS_NUMBER(tv));
+		duk_push_tval(ctx, tv);
+		duk_numconv_stringify(ctx,
+		                      10 /*radix*/,
+		                      0 /*precision:shortest*/,
+		                      0 /*force_exponential*/);
+		break;
+	}
+	}
+
+	duk_replace(ctx, index);
+
+ skip_replace:
+	return duk_require_string(ctx, index);
+}
+
+DUK_INTERNAL duk_hstring *duk_to_hstring(duk_context *ctx, duk_idx_t index) {
+	duk_hstring *ret;
+	DUK_ASSERT_CTX_VALID(ctx);
+	duk_to_string(ctx, index);
+	ret = duk_get_hstring(ctx, index);
+	DUK_ASSERT(ret != NULL);
+	return ret;
+}
+
+DUK_EXTERNAL void *duk_to_buffer_raw(duk_context *ctx, duk_idx_t index, duk_size_t *out_size, duk_uint_t mode) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_hbuffer *h_buf;
+	const duk_uint8_t *src_data;
+	duk_size_t src_size;
+	duk_uint8_t *dst_data;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+	DUK_UNREF(thr);
+
+	index = duk_require_normalize_index(ctx, index);
+
+	h_buf = duk_get_hbuffer(ctx, index);
+	if (h_buf != NULL) {
+		/* Buffer is kept as is, with the fixed/dynamic nature of the
+		 * buffer only changed if requested.  An external buffer
+		 * is converted into a non-external dynamic buffer in a
+		 * duk_to_dynamic_buffer() call.
+		 */
+		duk_uint_t tmp;
+		duk_uint8_t *tmp_ptr;
+
+		tmp_ptr = (duk_uint8_t *) DUK_HBUFFER_GET_DATA_PTR(thr->heap, h_buf);
+		src_data = (const duk_uint8_t *) tmp_ptr;
+		src_size = DUK_HBUFFER_GET_SIZE(h_buf);
+
+		tmp = (DUK_HBUFFER_HAS_DYNAMIC(h_buf) ? DUK_BUF_MODE_DYNAMIC : DUK_BUF_MODE_FIXED);
+		if ((tmp == mode && !DUK_HBUFFER_HAS_EXTERNAL(h_buf)) ||
+		    mode == DUK_BUF_MODE_DONTCARE) {
+			/* Note: src_data may be NULL if input is a zero-size
+			 * dynamic buffer.
+			 */
+			dst_data = tmp_ptr;
+			goto skip_copy;
+		}
+	} else {
+		/* Non-buffer value is first ToString() coerced, then converted
+		 * to a buffer (fixed buffer is used unless a dynamic buffer is
+		 * explicitly requested).
+		 */
+
+		src_data = (const duk_uint8_t *) duk_to_lstring(ctx, index, &src_size);
+	}
+
+	dst_data = (duk_uint8_t *) duk_push_buffer(ctx, src_size, (mode == DUK_BUF_MODE_DYNAMIC) /*dynamic*/);
+	if (DUK_LIKELY(src_size > 0)) {
+		/* When src_size == 0, src_data may be NULL (if source
+		 * buffer is dynamic), and dst_data may be NULL (if
+		 * target buffer is dynamic).  Avoid zero-size memcpy()
+		 * with an invalid pointer.
+		 */
+		DUK_MEMCPY((void *) dst_data, (const void *) src_data, (size_t) src_size);
+	}
+	duk_replace(ctx, index);
+ skip_copy:
+
+	if (out_size) {
+		*out_size = src_size;
+	}
+	return dst_data;
+}
+
+DUK_EXTERNAL void *duk_to_pointer(duk_context *ctx, duk_idx_t index) {
+	duk_tval *tv;
+	void *res;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	index = duk_require_normalize_index(ctx, index);
+
+	tv = duk_require_tval(ctx, index);
+	DUK_ASSERT(tv != NULL);
+
+	switch (DUK_TVAL_GET_TAG(tv)) {
+	case DUK_TAG_UNDEFINED:
+	case DUK_TAG_NULL:
+	case DUK_TAG_BOOLEAN:
+		res = NULL;
+		break;
+	case DUK_TAG_POINTER:
+		res = DUK_TVAL_GET_POINTER(tv);
+		break;
+	case DUK_TAG_STRING:
+	case DUK_TAG_OBJECT:
+	case DUK_TAG_BUFFER:
+		/* Heap allocated: return heap pointer which is NOT useful
+		 * for the caller, except for debugging.
+		 */
+		res = (void *) DUK_TVAL_GET_HEAPHDR(tv);
+		break;
+	case DUK_TAG_LIGHTFUNC:
+		/* Function pointers do not always cast correctly to void *
+		 * (depends on memory and segmentation model for instance),
+		 * so they coerce to NULL.
+		 */
+		res = NULL;
+		break;
+#if defined(DUK_USE_FASTINT)
+	case DUK_TAG_FASTINT:
+#endif
+	default:
+		/* number */
+		DUK_ASSERT(!DUK_TVAL_IS_UNUSED(tv));
+		DUK_ASSERT(DUK_TVAL_IS_NUMBER(tv));
+		res = NULL;
+		break;
+	}
+
+	duk_push_pointer(ctx, res);
+	duk_replace(ctx, index);
+	return res;
+}
+
+DUK_EXTERNAL void duk_to_object(duk_context *ctx, duk_idx_t index) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_tval *tv;
+	duk_uint_t flags = 0;   /* shared flags for a subset of types */
+	duk_small_int_t proto = 0;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	index = duk_require_normalize_index(ctx, index);
+
+	tv = duk_require_tval(ctx, index);
+	DUK_ASSERT(tv != NULL);
+
+	switch (DUK_TVAL_GET_TAG(tv)) {
+	case DUK_TAG_UNDEFINED:
+	case DUK_TAG_NULL: {
+		DUK_ERROR_TYPE(thr, DUK_STR_NOT_OBJECT_COERCIBLE);
+		break;
+	}
+	case DUK_TAG_BOOLEAN: {
+		flags = DUK_HOBJECT_FLAG_EXTENSIBLE |
+		        DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_BOOLEAN);
+		proto = DUK_BIDX_BOOLEAN_PROTOTYPE;
+		goto create_object;
+	}
+	case DUK_TAG_STRING: {
+		flags = DUK_HOBJECT_FLAG_EXTENSIBLE |
+		        DUK_HOBJECT_FLAG_EXOTIC_STRINGOBJ |
+		        DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_STRING);
+		proto = DUK_BIDX_STRING_PROTOTYPE;
+		goto create_object;
+	}
+	case DUK_TAG_OBJECT: {
+		/* nop */
+		break;
+	}
+	case DUK_TAG_BUFFER: {
+		/* A plain buffer coerces to a Duktape.Buffer because it's the
+		 * object counterpart of the plain buffer value.  But it might
+		 * still make more sense to produce an ArrayBuffer here?
+		 */
+
+		duk_hbufferobject *h_bufobj;
+		duk_hbuffer *h_val;
+
+		h_val = DUK_TVAL_GET_BUFFER(tv);
+		DUK_ASSERT(h_val != NULL);
+
+		h_bufobj = duk_push_bufferobject_raw(ctx,
+		                                     DUK_HOBJECT_FLAG_EXTENSIBLE |
+		                                     DUK_HOBJECT_FLAG_BUFFEROBJECT |
+		                                     DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_BUFFER),
+		                                     DUK_BIDX_BUFFER_PROTOTYPE);
+		DUK_ASSERT(h_bufobj != NULL);
+		DUK_ASSERT(DUK_HOBJECT_HAS_EXTENSIBLE((duk_hobject *) h_bufobj));
+		DUK_ASSERT(DUK_HOBJECT_IS_BUFFEROBJECT((duk_hobject *) h_bufobj));
+
+		h_bufobj->buf = h_val;
+		DUK_HBUFFER_INCREF(thr, h_val);
+		DUK_ASSERT(h_bufobj->offset == 0);
+		h_bufobj->length = (duk_uint_t) DUK_HBUFFER_GET_SIZE(h_val);
+		DUK_ASSERT(h_bufobj->shift == 0);
+		DUK_ASSERT(h_bufobj->elem_type == DUK_HBUFFEROBJECT_ELEM_UINT8);
+
+		DUK_ASSERT_HBUFFEROBJECT_VALID(h_bufobj);
+		goto replace_value;
+	}
+	case DUK_TAG_POINTER: {
+		flags = DUK_HOBJECT_FLAG_EXTENSIBLE |
+		        DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_POINTER);
+		proto = DUK_BIDX_POINTER_PROTOTYPE;
+		goto create_object;
+	}
+	case DUK_TAG_LIGHTFUNC: {
+		/* Lightfunc coerces to a Function instance with concrete
+		 * properties.  Since 'length' is virtual for Duktape/C
+		 * functions, don't need to define that.
+		 *
+		 * The result is made extensible to mimic what happens to
+		 * strings:
+		 *   > Object.isExtensible(Object('foo'))
+		 *   true
+		 */
+		duk_small_uint_t lf_flags;
+		duk_idx_t nargs;
+		duk_small_uint_t lf_len;
+		duk_c_function func;
+		duk_hnativefunction *nf;
+
+		DUK_TVAL_GET_LIGHTFUNC(tv, func, lf_flags);
+
+		nargs = (duk_idx_t) DUK_LFUNC_FLAGS_GET_NARGS(lf_flags);
+		if (nargs == DUK_LFUNC_NARGS_VARARGS) {
+			nargs = (duk_idx_t) DUK_VARARGS;
+		}
+		flags = DUK_HOBJECT_FLAG_EXTENSIBLE |
+		        DUK_HOBJECT_FLAG_CONSTRUCTABLE |
+		        DUK_HOBJECT_FLAG_NATIVEFUNCTION |
+	                DUK_HOBJECT_FLAG_NEWENV |
+	                DUK_HOBJECT_FLAG_STRICT |
+	                DUK_HOBJECT_FLAG_NOTAIL |
+			/* DUK_HOBJECT_FLAG_EXOTIC_DUKFUNC: omitted here intentionally */
+	                DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_FUNCTION);
+		(void) duk__push_c_function_raw(ctx, func, nargs, flags);
+
+		lf_len = DUK_LFUNC_FLAGS_GET_LENGTH(lf_flags);
+		if ((duk_idx_t) lf_len != nargs) {
+			/* Explicit length is only needed if it differs from 'nargs'. */
+			duk_push_int(ctx, (duk_int_t) lf_len);
+			duk_xdef_prop_stridx(ctx, -2, DUK_STRIDX_LENGTH, DUK_PROPDESC_FLAGS_NONE);
+		}
+		duk_push_lightfunc_name(ctx, tv);
+		duk_xdef_prop_stridx(ctx, -2, DUK_STRIDX_NAME, DUK_PROPDESC_FLAGS_NONE);
+
+		nf = duk_get_hnativefunction(ctx, -1);
+		DUK_ASSERT(nf != NULL);
+		nf->magic = (duk_int16_t) DUK_LFUNC_FLAGS_GET_MAGIC(lf_flags);
+
+		/* Enable DUKFUNC exotic behavior once properties are set up. */
+		DUK_HOBJECT_SET_EXOTIC_DUKFUNC((duk_hobject *) nf);
+		goto replace_value;
+	}
+#if defined(DUK_USE_FASTINT)
+	case DUK_TAG_FASTINT:
+#endif
+	default: {
+		DUK_ASSERT(!DUK_TVAL_IS_UNUSED(tv));
+		DUK_ASSERT(DUK_TVAL_IS_NUMBER(tv));
+		flags = DUK_HOBJECT_FLAG_EXTENSIBLE |
+		               DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_NUMBER);
+		proto = DUK_BIDX_NUMBER_PROTOTYPE;
+		goto create_object;
+	}
+	}
+	return;
+
+ create_object:
+	(void) duk_push_object_helper(ctx, flags, proto);
+
+	/* Note: Boolean prototype's internal value property is not writable,
+	 * but duk_xdef_prop_stridx() disregards the write protection.  Boolean
+	 * instances are immutable.
+	 *
+	 * String and buffer special behaviors are already enabled which is not
+	 * ideal, but a write to the internal value is not affected by them.
+	 */
+	duk_dup(ctx, index);
+	duk_xdef_prop_stridx(ctx, -2, DUK_STRIDX_INT_VALUE, DUK_PROPDESC_FLAGS_NONE);
+
+ replace_value:
+	duk_replace(ctx, index);
+}
+
+/*
+ *  Type checking
+ */
+
+DUK_LOCAL duk_bool_t duk__tag_check(duk_context *ctx, duk_idx_t index, duk_small_uint_t tag) {
+	duk_tval *tv;
+
+	tv = duk_get_tval(ctx, index);
+	if (!tv) {
+		return 0;
+	}
+	return (DUK_TVAL_GET_TAG(tv) == tag);
+}
+
+DUK_LOCAL duk_bool_t duk__obj_flag_any_default_false(duk_context *ctx, duk_idx_t index, duk_uint_t flag_mask) {
+	duk_hobject *obj;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	obj = duk_get_hobject(ctx, index);
+	if (obj) {
+		return (DUK_HEAPHDR_CHECK_FLAG_BITS((duk_heaphdr *) obj, flag_mask) ? 1 : 0);
+	}
+	return 0;
+}
+
+DUK_EXTERNAL duk_int_t duk_get_type(duk_context *ctx, duk_idx_t index) {
+	duk_tval *tv;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	tv = duk_get_tval(ctx, index);
+	if (!tv) {
+		return DUK_TYPE_NONE;
+	}
+	switch (DUK_TVAL_GET_TAG(tv)) {
+	case DUK_TAG_UNDEFINED:
+		return DUK_TYPE_UNDEFINED;
+	case DUK_TAG_NULL:
+		return DUK_TYPE_NULL;
+	case DUK_TAG_BOOLEAN:
+		return DUK_TYPE_BOOLEAN;
+	case DUK_TAG_STRING:
+		return DUK_TYPE_STRING;
+	case DUK_TAG_OBJECT:
+		return DUK_TYPE_OBJECT;
+	case DUK_TAG_BUFFER:
+		return DUK_TYPE_BUFFER;
+	case DUK_TAG_POINTER:
+		return DUK_TYPE_POINTER;
+	case DUK_TAG_LIGHTFUNC:
+		return DUK_TYPE_LIGHTFUNC;
+#if defined(DUK_USE_FASTINT)
+	case DUK_TAG_FASTINT:
+#endif
+	default:
+		/* Note: number has no explicit tag (in 8-byte representation) */
+		DUK_ASSERT(!DUK_TVAL_IS_UNUSED(tv));
+		DUK_ASSERT(DUK_TVAL_IS_NUMBER(tv));
+		return DUK_TYPE_NUMBER;
+	}
+	DUK_UNREACHABLE();
+}
+
+#if defined(DUK_USE_VERBOSE_ERRORS) && defined(DUK_USE_PARANOID_ERRORS)
+DUK_LOCAL const char *duk__type_names[] = {
+	"none",
+	"undefined",
+	"null",
+	"boolean",
+	"number",
+	"string",
+	"object",
+	"buffer",
+	"pointer",
+	"lightfunc"
+};
+
+DUK_INTERNAL const char *duk_get_type_name(duk_context *ctx, duk_idx_t index) {
+	duk_int_t type_tag;
+
+	type_tag = duk_get_type(ctx, index);
+	DUK_ASSERT(type_tag >= DUK_TYPE_MIN && type_tag <= DUK_TYPE_MAX);
+	DUK_ASSERT(DUK_TYPE_MIN == 0 && sizeof(duk__type_names) / sizeof(const char *) == DUK_TYPE_MAX + 1);
+
+	return duk__type_names[type_tag];
+}
+#endif
+
+DUK_EXTERNAL duk_bool_t duk_check_type(duk_context *ctx, duk_idx_t index, duk_int_t type) {
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	return (duk_get_type(ctx, index) == type) ? 1 : 0;
+}
+
+DUK_EXTERNAL duk_uint_t duk_get_type_mask(duk_context *ctx, duk_idx_t index) {
+	duk_tval *tv;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	tv = duk_get_tval(ctx, index);
+	if (!tv) {
+		return DUK_TYPE_MASK_NONE;
+	}
+	switch (DUK_TVAL_GET_TAG(tv)) {
+	case DUK_TAG_UNDEFINED:
+		return DUK_TYPE_MASK_UNDEFINED;
+	case DUK_TAG_NULL:
+		return DUK_TYPE_MASK_NULL;
+	case DUK_TAG_BOOLEAN:
+		return DUK_TYPE_MASK_BOOLEAN;
+	case DUK_TAG_STRING:
+		return DUK_TYPE_MASK_STRING;
+	case DUK_TAG_OBJECT:
+		return DUK_TYPE_MASK_OBJECT;
+	case DUK_TAG_BUFFER:
+		return DUK_TYPE_MASK_BUFFER;
+	case DUK_TAG_POINTER:
+		return DUK_TYPE_MASK_POINTER;
+	case DUK_TAG_LIGHTFUNC:
+		return DUK_TYPE_MASK_LIGHTFUNC;
+#if defined(DUK_USE_FASTINT)
+	case DUK_TAG_FASTINT:
+#endif
+	default:
+		/* Note: number has no explicit tag (in 8-byte representation) */
+		DUK_ASSERT(!DUK_TVAL_IS_UNUSED(tv));
+		DUK_ASSERT(DUK_TVAL_IS_NUMBER(tv));
+		return DUK_TYPE_MASK_NUMBER;
+	}
+	DUK_UNREACHABLE();
+}
+
+DUK_EXTERNAL duk_bool_t duk_check_type_mask(duk_context *ctx, duk_idx_t index, duk_uint_t mask) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	if (duk_get_type_mask(ctx, index) & mask) {
+		return 1;
+	}
+	if (mask & DUK_TYPE_MASK_THROW) {
+		DUK_ERROR_TYPE(thr, DUK_STR_UNEXPECTED_TYPE);
+		DUK_UNREACHABLE();
+	}
+	return 0;
+}
+
+DUK_EXTERNAL duk_bool_t duk_is_undefined(duk_context *ctx, duk_idx_t index) {
+	DUK_ASSERT_CTX_VALID(ctx);
+	return duk__tag_check(ctx, index, DUK_TAG_UNDEFINED);
+}
+
+DUK_EXTERNAL duk_bool_t duk_is_null(duk_context *ctx, duk_idx_t index) {
+	DUK_ASSERT_CTX_VALID(ctx);
+	return duk__tag_check(ctx, index, DUK_TAG_NULL);
+}
+
+DUK_EXTERNAL duk_bool_t duk_is_null_or_undefined(duk_context *ctx, duk_idx_t index) {
+	duk_tval *tv;
+	duk_small_uint_t tag;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	tv = duk_get_tval(ctx, index);
+	if (!tv) {
+		return 0;
+	}
+	tag = DUK_TVAL_GET_TAG(tv);
+	return (tag == DUK_TAG_UNDEFINED) || (tag == DUK_TAG_NULL);
+}
+
+DUK_EXTERNAL duk_bool_t duk_is_boolean(duk_context *ctx, duk_idx_t index) {
+	DUK_ASSERT_CTX_VALID(ctx);
+	return duk__tag_check(ctx, index, DUK_TAG_BOOLEAN);
+}
+
+DUK_EXTERNAL duk_bool_t duk_is_number(duk_context *ctx, duk_idx_t index) {
+	duk_tval *tv;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	/*
+	 *  Number is special because it doesn't have a specific
+	 *  tag in the 8-byte representation.
+	 */
+
+	/* XXX: shorter version for 12-byte representation? */
+
+	tv = duk_get_tval(ctx, index);
+	if (!tv) {
+		return 0;
+	}
+	return DUK_TVAL_IS_NUMBER(tv);
+}
+
+DUK_EXTERNAL duk_bool_t duk_is_nan(duk_context *ctx, duk_idx_t index) {
+	/* XXX: This will now return false for non-numbers, even though they would
+	 * coerce to NaN (as a general rule).  In particular, duk_get_number()
+	 * returns a NaN for non-numbers, so should this function also return
+	 * true for non-numbers?
+	 */
+
+	duk_tval *tv;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	tv = duk_get_tval(ctx, index);
+	if (!tv || !DUK_TVAL_IS_NUMBER(tv)) {
+		return 0;
+	}
+	return DUK_ISNAN(DUK_TVAL_GET_NUMBER(tv));
+}
+
+DUK_EXTERNAL duk_bool_t duk_is_string(duk_context *ctx, duk_idx_t index) {
+	DUK_ASSERT_CTX_VALID(ctx);
+	return duk__tag_check(ctx, index, DUK_TAG_STRING);
+}
+
+DUK_EXTERNAL duk_bool_t duk_is_object(duk_context *ctx, duk_idx_t index) {
+	DUK_ASSERT_CTX_VALID(ctx);
+	return duk__tag_check(ctx, index, DUK_TAG_OBJECT);
+}
+
+DUK_EXTERNAL duk_bool_t duk_is_buffer(duk_context *ctx, duk_idx_t index) {
+	DUK_ASSERT_CTX_VALID(ctx);
+	return duk__tag_check(ctx, index, DUK_TAG_BUFFER);
+}
+
+DUK_EXTERNAL duk_bool_t duk_is_pointer(duk_context *ctx, duk_idx_t index) {
+	DUK_ASSERT_CTX_VALID(ctx);
+	return duk__tag_check(ctx, index, DUK_TAG_POINTER);
+}
+
+DUK_EXTERNAL duk_bool_t duk_is_lightfunc(duk_context *ctx, duk_idx_t index) {
+	DUK_ASSERT_CTX_VALID(ctx);
+	return duk__tag_check(ctx, index, DUK_TAG_LIGHTFUNC);
+}
+
+DUK_EXTERNAL duk_bool_t duk_is_array(duk_context *ctx, duk_idx_t index) {
+	duk_hobject *obj;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	obj = duk_get_hobject(ctx, index);
+	if (obj) {
+		return (DUK_HOBJECT_GET_CLASS_NUMBER(obj) == DUK_HOBJECT_CLASS_ARRAY ? 1 : 0);
+	}
+	return 0;
+}
+
+DUK_EXTERNAL duk_bool_t duk_is_function(duk_context *ctx, duk_idx_t index) {
+	duk_tval *tv;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	tv = duk_get_tval(ctx, index);
+	if (tv && DUK_TVAL_IS_LIGHTFUNC(tv)) {
+		return 1;
+	}
+	return duk__obj_flag_any_default_false(ctx,
+	                                       index,
+	                                       DUK_HOBJECT_FLAG_COMPILEDFUNCTION |
+	                                       DUK_HOBJECT_FLAG_NATIVEFUNCTION |
+	                                       DUK_HOBJECT_FLAG_BOUND);
+}
+
+DUK_EXTERNAL duk_bool_t duk_is_c_function(duk_context *ctx, duk_idx_t index) {
+	DUK_ASSERT_CTX_VALID(ctx);
+	return duk__obj_flag_any_default_false(ctx,
+	                                       index,
+	                                       DUK_HOBJECT_FLAG_NATIVEFUNCTION);
+}
+
+DUK_EXTERNAL duk_bool_t duk_is_ecmascript_function(duk_context *ctx, duk_idx_t index) {
+	DUK_ASSERT_CTX_VALID(ctx);
+	return duk__obj_flag_any_default_false(ctx,
+	                                       index,
+	                                       DUK_HOBJECT_FLAG_COMPILEDFUNCTION);
+}
+
+DUK_EXTERNAL duk_bool_t duk_is_bound_function(duk_context *ctx, duk_idx_t index) {
+	DUK_ASSERT_CTX_VALID(ctx);
+	return duk__obj_flag_any_default_false(ctx,
+	                                       index,
+	                                       DUK_HOBJECT_FLAG_BOUND);
+}
+
+DUK_EXTERNAL duk_bool_t duk_is_thread(duk_context *ctx, duk_idx_t index) {
+	DUK_ASSERT_CTX_VALID(ctx);
+	return duk__obj_flag_any_default_false(ctx,
+	                                       index,
+	                                       DUK_HOBJECT_FLAG_THREAD);
+}
+
+DUK_EXTERNAL duk_bool_t duk_is_fixed_buffer(duk_context *ctx, duk_idx_t index) {
+	duk_tval *tv;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	tv = duk_get_tval(ctx, index);
+	if (tv && DUK_TVAL_IS_BUFFER(tv)) {
+		duk_hbuffer *h = DUK_TVAL_GET_BUFFER(tv);
+		DUK_ASSERT(h != NULL);
+		return (DUK_HBUFFER_HAS_DYNAMIC(h) ? 0 : 1);
+	}
+	return 0;
+}
+
+DUK_EXTERNAL duk_bool_t duk_is_dynamic_buffer(duk_context *ctx, duk_idx_t index) {
+	duk_tval *tv;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	tv = duk_get_tval(ctx, index);
+	if (tv && DUK_TVAL_IS_BUFFER(tv)) {
+		duk_hbuffer *h = DUK_TVAL_GET_BUFFER(tv);
+		DUK_ASSERT(h != NULL);
+		return (DUK_HBUFFER_HAS_DYNAMIC(h) && !DUK_HBUFFER_HAS_EXTERNAL(h) ? 1 : 0);
+	}
+	return 0;
+}
+
+DUK_EXTERNAL duk_bool_t duk_is_external_buffer(duk_context *ctx, duk_idx_t index) {
+	duk_tval *tv;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	tv = duk_get_tval(ctx, index);
+	if (tv && DUK_TVAL_IS_BUFFER(tv)) {
+		duk_hbuffer *h = DUK_TVAL_GET_BUFFER(tv);
+		DUK_ASSERT(h != NULL);
+		return (DUK_HBUFFER_HAS_DYNAMIC(h) && DUK_HBUFFER_HAS_EXTERNAL(h) ? 1 : 0);
+	}
+	return 0;
+}
+
+DUK_EXTERNAL duk_errcode_t duk_get_error_code(duk_context *ctx, duk_idx_t index) {
+	duk_hthread *thr = (duk_hthread *) ctx;
+	duk_hobject *h;
+	duk_uint_t sanity;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+
+	h = duk_get_hobject(ctx, index);
+
+	sanity = DUK_HOBJECT_PROTOTYPE_CHAIN_SANITY;
+	do {
+		if (!h) {
+			return DUK_ERR_NONE;
+		}
+		if (h == thr->builtins[DUK_BIDX_EVAL_ERROR_PROTOTYPE]) {
+			return DUK_ERR_EVAL_ERROR;
+		}
+		if (h == thr->builtins[DUK_BIDX_RANGE_ERROR_PROTOTYPE]) {
+			return DUK_ERR_RANGE_ERROR;
+		}
+		if (h == thr->builtins[DUK_BIDX_REFERENCE_ERROR_PROTOTYPE]) {
+			return DUK_ERR_REFERENCE_ERROR;
+		}
+		if (h == thr->builtins[DUK_BIDX_SYNTAX_ERROR_PROTOTYPE]) {
+			return DUK_ERR_SYNTAX_ERROR;
+		}
+		if (h == thr->builtins[DUK_BIDX_TYPE_ERROR_PROTOTYPE]) {
+			return DUK_ERR_TYPE_ERROR;
+		}
+		if (h == thr->builtins[DUK_BIDX_URI_ERROR_PROTOTYPE]) {
+			return DUK_ERR_URI_ERROR;
+		}
+		if (h == thr->builtins[DUK_BIDX_ERROR_PROTOTYPE]) {
+			return DUK_ERR_ERROR;
+		}
+
+		h = DUK_HOBJECT_GET_PROTOTYPE(thr->heap, h);
+	} while (--sanity > 0);
+
+	return DUK_ERR_NONE;
+}
+
+/*
+ *  Pushers
+ */
+
+DUK_INTERNAL void duk_push_tval(duk_context *ctx, duk_tval *tv) {
+	duk_hthread *thr;
+	duk_tval *tv_slot;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+	DUK_ASSERT(tv != NULL);
+	thr = (duk_hthread *) ctx;
+	DUK__CHECK_SPACE();
+	tv_slot = thr->valstack_top++;
+	DUK_TVAL_SET_TVAL(tv_slot, tv);
+	DUK_TVAL_INCREF(thr, tv);  /* no side effects */
+}
+
+DUK_EXTERNAL void duk_push_undefined(duk_context *ctx) {
+	duk_hthread *thr;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+	thr = (duk_hthread *) ctx;
+	DUK__CHECK_SPACE();
+
+	/* Because value stack init policy is 'undefined above top',
+	 * we don't need to write, just assert.
+	 */
+	thr->valstack_top++;
+	DUK_ASSERT(DUK_TVAL_IS_UNDEFINED(thr->valstack_top - 1));
+}
+
+DUK_EXTERNAL void duk_push_null(duk_context *ctx) {
+	duk_hthread *thr;
+	duk_tval *tv_slot;
+
+	DUK_ASSERT_CTX_VALID(ctx);
+	thr = (duk_hthread *) ctx;
+	DUK__CHECK_SPACE();
+	tv_slot = thr->valstack_top++;
+	D

<TRUNCATED>