Removed mongoose due to restricted license and webserver wip till code is restructured (nw)

This commit is contained in:
Miodrag Milanovic 2015-11-04 18:55:36 +01:00
parent 2a067f08a4
commit b6707c3bb5
102 changed files with 2 additions and 12527 deletions

View File

@ -1,16 +0,0 @@
Copyright (c) 2004-2013 Sergey Lyubka <valenok@gmail.com>
Copyright (c) 2013-2015 Cesanta Software Limited
All rights reserved
This code is dual-licensed: you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2 as
published by the Free Software Foundation. For the terms of this
license, see <http://www.gnu.org/licenses>.
You are free to use this code under the terms of the GNU General
Public License, but WITHOUT ANY WARRANTY; without even the implied
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
Alternatively, you can license this code under a commercial
license, as set out in <http://cesanta.com/>.

View File

@ -1,78 +0,0 @@
# <img src="http://cesanta.com/images/mongoose_logo.png" width="64" height="64"> Mongoose Web Server
[![Join the chat at https://gitter.im/cesanta/mongoose](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/cesanta/mongoose?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
Mongoose is the most easy to use web server on the planet. A web server of choice for Web developers (PHP, Ruby, Python, etc) and Web designers.
Mongoose is built on top of Libmongoose embedded library, which can turn
anything into a web server in 5 minutes worth of effort and few lines of code.
Libmongoose is used to serve Web GUI on embedded devices, implement RESTful
services, RPC frameworks (e.g. JSON-RPC), handle telemetry data exchange, and
perform many other tasks in various different industries including aerospace,
manufacturing, finance, research, automotive, gaming, IT.
* [Mailing list](http://groups.google.com/group/mongoose-users)
* [Downloads](http://cesanta.com/products.shtml)
* [Documentation](http://cesanta.com/docs.shtml)
Check out Fossa - our [embedded multi-protocol library](https://github.com/cesanta/fossa) with TCP,UDP,HTTP,Websocket,MQTT,DNS support, designed for Internet Of Things!
# Features
- Works on Windows, Mac, UNIX/Linux, iPhone, Android eCos, QNX
and many other platforms
- CGI, SSI, SSL, Digest auth, Websocket, WEbDAV, Resumed download,
URL rewrite, file blacklist
- Custom error pages, Virtual hosts, IP-based ACL, Windows service,
HTTP/HTTPS client
- Simple and clean
[embedding API](https://github.com/cesanta/mongoose/blob/master/mongoose.h).
The source is in single
[mongoose.c](https://github.com/cesanta/mongoose/blob/master/mongoose.c) file
to make embedding easy
- Extremely lightweight, has a core of under 40kB and tiny runtime footprint
- Asynchronous, non-blocking core supporting single- or multi-threaded usage
- On the market since 2004 with over 1 million cumulative downloads
- Stable, mature and tested, has several man-years invested
in continuous improvement and refinement
# Screenshots
Download, double-click to start, run browser -- that's all!
![shot1](http://cesanta.com/images/tut_sharing/tut1.png)
![shot2](http://cesanta.com/images/tut_sharing/tut2.png)
![shot3](http://cesanta.com/images/tut_sharing/tut3.png)
![shot4](http://cesanta.com/images/tut_sharing/tut4.png)
# Contributions
People who have agreed to the
[Cesanta CLA](http://cesanta.com/contributors_la.html)
can make contributions. Note that the CLA isn't a copyright
_assigment_ but rather a copyright _license_.
You retain the copyright on your contributions.
# Licensing
Mongoose is released under commercial and
[GNU GPL v.2](http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) open
source licenses. The GPLv2 open source License does not generally permit
incorporating this software into non-open source programs.
For those customers who do not wish to comply with the GPLv2 open
source license requirements,
[Cesanta](http://cesanta.com) offers a full,
royalty-free commercial license and professional support
without any of the GPL restrictions.
# Other products by Cesanta
- [Fossa](http://github.com/cesanta/fossa) - Multi-protocol networking library
- [SSL Wrapper](https://github.com/cesanta/ssl_wrapper) - application to
secure network communications
- [Frozen](https://github.com/cesanta/frozen) - JSON parser and generator
- [SLRE](https://github.com/cesanta/slre) - Super Light Regular Expression
library
- [V7](https://github.com/cesanta/v7) - Embedded JavaScript engine

View File

@ -1,249 +0,0 @@
# Mongoose API Reference
struct mg_server *mg_create_server(void *server_param, mg_handler_t handler);
Creates web server instance. Returns opaque instance pointer, or NULL if
there is not enough memory. `server_param`: Could be any pointer, or NULL.
This pointer will be passed
to the callback functions as `struct mg_connection::server_param` field.
A common use case is to pass `this` pointer of the C++ wrapper class
as `user_param`, to let the callback get the pointer to the C++ object.
Note that this function doesn't make the
server instance to serve. Serving is done by `mg_poll_server()` function.
Mongoose has single-threaded, event-driven, asynchronous, non-blocking core.
When server instance is created, it contains an information about
the configuration and the state of each connection.
Server instance is capable on listening on only one port. After creation,
`struct mg_server` has a list
of active connections and configuration parameters.
Side-effect: on UNIX, `mg_create_server()` ignores SIGPIPE signals. If custom
processing is required SIGPIPE, signal handler must be set up after
calling `mg_create_server()`.
Important: Mongoose does not install `SIGCHLD` handler. If CGI is used,
`SIGCHLD` handler must be set up to reap CGI zombie processes.
void mg_destroy_server(struct mg_server **server);
Deallocates web server instance, closes all pending connections, and makes
server pointer a NULL pointer.
const char mg_set_option(struct mg_server *server, const char *name,
const char *value);
Sets a particular server option. Note that at least one option,
`listening_port`, must be specified. To serve static files, `document_root`
must be specified too. If `document_root` option is left unset, Mongoose
will not access filesystem at all. `mg_set_option()` returns NULL if option was
set successfully, otherwise it returns human-readable error string. It is
allowed to call `mg_set_option()` by the same thread that does
`mg_poll_server()` (Mongoose thread) and change server configuration while it
is serving, in between `mg_poll_server()` calls.
int mg_poll_server(struct mg_server *server, int milliseconds);
Performs one iteration of IO loop by iterating over all
active connections, performing `select()` syscall on all sockets with a timeout
of `milliseconds`. When `select()` returns, Mongoose
does an IO for each socket that has data to be sent or received. Application
code must call `mg_poll_server()` in a loop. It is an error to have more then
one thread calling `mg_poll_server()`, `mg_set_option()` or any other function
that take `struct mg_server *` parameter. Mongoose does not
mutex-protect `struct mg_server *`, therefore only single thread
(Mongoose thread) should make Mongoose calls.
`mg_poll_server()` calls user-specified event handler when certain events
occur. Sequence of events for the accepted connection is this:
* `MG_AUTH` - Mongoose asks whether this connection is authorized. If event
handler returns `MG_FALSE`, then Mongoose does not serve the request but
sends authorization request to the client. If `MG_TRUE` is returned,
then Mongoose continues on with the request.
* `MG_REQUEST` - Mongoose asks event handler to serve the request. If
event handler serves the request by sending a reply,
it should return `MG_TRUE`. Otherwise,
it should return `MG_FALSE` which tells Mongoose that request is not
served and Mongoose should serve it. For example, event handler might
choose to serve only RESTful API requests with URIs that start with
certain prefix, and let Mongoose serve all static files.
If event handler decides to serve the request, but doesn't have
all the data at the moment, it should return `MG_MORE`. That tells
Mongoose to keep the connection open after callback returns.
`mg_connection::connection_param` pointer is a placeholder to keep
user-specific data. For example, handler could decide to open a DB
connection and store DB connection handle in `connection_param`.
* `MG_POLL` is sent to every connection on every iteration of
`mg_poll_server()`. Event handler should return `MG_FALSE` to ignore
this event. If event handler returns `MG_TRUE`, then Mongoose assumes
that event handler has finished sending data, and Mongoose will
close the connection.
* `MG_HTTP_ERROR` sent when Mongoose is about to send HTTP error back
to the client. Event handler can choose to send a reply itself, in which
case event handler must return `MG_TRUE`. Otherwise, event handler must
return `MG_FALSE`.
* `MG_CLOSE` is sent when the connection is closed. This event is used
to cleanup per-connection state stored in `connection_param`
if it was allocated. Event handler return value is ignored.
Sequence of events for the client connection is this:
* `MG_CONNECT` sent when Mongoose has connected to the remote host.
This event is sent to the connection initiated by `mg_connect()` call.
Connection status is held in `mg_connection::status_code`: if zero,
then connection was successful, otherwise connection was not established.
User should send a request upon successful connection.
Event handler should return `MG_TRUE` if connection was successful and
HTTP request has been sent. Otherwise, it should send `MG_FALSE`.
* `MG_REPLY` is sent when response has been received from the remote host.
If event handler sends another request, then it should return `MG_TRUE`.
Otherwise it should return `MG_FALSE` and Mongoose will close the connection.
* `MG_CLOSE` same as for the accepted connection.
When mongoose buffers in HTTP request and successfully parses it, it sends
`MG_REQUEST` event for GET requests immediately. For POST requests,
Mongoose delays the call until the whole POST request is buffered in memory.
POST data is available to the callback as `struct mg_connection::content`,
and POST data length is in `struct mg_connection::content_len`.
Note that websocket connections are treated the same way. Mongoose buffers
websocket frame in memory, and calls event handler when frame is fully
buffered. Frame data is available `struct mg_connection::content`, and
data length is in `struct mg_connection::content_len`, i.e. very similar to
the POST request. `struct mg_connection::is_websocket` flag indicates
whether the request is websocket or not. Also, for websocket requests,
there is `struct mg_connection::wsbits` field which contains first byte
of the websocket frame which URI handler can examine. Note that to
reply to the websocket client, `mg_websocket_write()` should be used.
To reply to the plain HTTP client, `mg_write_data()` should be used.
Return value: number of active connections.
const char **mg_get_valid_option_names(void);
Returns a NULL-terminated array of option names and their default values.
There are two entries per option in an array: an option name followed by a
default value. A default value could be NULL. A NULL name indicates an end
of the array.
const char *mg_get_option(const struct mg_server *server, const char *name);
Returns the value of particular configuration parameter. 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.
void mg_wakeup_server_ex(struct mg_server *, mg_handler_t func,
const char *fmt, ...);
Sends string message to a server. Function `func` is called for every active
connection. String message is passed in `struct mg_connection::callback_param`.
This function is designed to push data to the connected clients, and
can be called from any thread. There is a limitation on the length of
the message, currently at 8 kilobytes.
void mg_send_status(struct mg_connection *, int status_code);
void mg_send_header(struct mg_connection *, const char *name,
const char *value);
void mg_send_data(struct mg_connection *, const void *data, int data_len);
void mg_printf_data(struct mg_connection *, const char *format, ...);
These functions are used to construct a response to the client. HTTP response
consists of three parts: a status line, zero or more HTTP headers,
a response body. Mongoose provides functions for all three parts:
* `mg_send_status()` is used to create status line. This function can be
called zero or once. If `mg_send_status()` is not called, then Mongoose
will send status 200 (success) implicitly.
* `mg_send_header()` adds HTTP header to the response. This function could
be called zero or more times.
* `mg_send_data()` and `mg_printf_data()` are used to send data to the
client. Note that Mongoose adds `Transfer-Encoding: chunked` header
implicitly, and sends data in chunks. Therefore, it is not necessary to
set `Content-Length` header. Note that `mg_send_data()` and
`mg_printf_data()` do not send data immediately. Instead, they spool
data in memory, and Mongoose sends that data later after URI handler
returns. If data to be sent is huge, an URI handler might
send data in pieces by saving state in
`struct mg_connection::connection_param` variable and returning `0`. Then
Mongoose will call a handler repeatedly after each socket write.
<!-- -->
void mg_send_file(struct mg_connection *, const char *path);
Tells Mongoose to serve given file. Mongoose handles file according to
it's extensions, i.e. Mongoose will invoke CGI script if `path` has CGI
extension, it'll render SSI file if `path` has SSI extension, etc. If `path`
points to a directory, Mongoose will show directory listing. If this function
is used, no calls to `mg_send*` or `mg_printf*` functions must be made, and
event handler must return `MG_MORE`.
size_t mg_websocket_write(struct mg_connection* conn, int opcode,
const char *data, size_t data_len);
size_t mg_websocket_printf(struct mg_connection* conn, int opcode,
const char *fmt, ...);
Similar to `mg_write()` and `mg_printf()`, but wraps the data into a
websocket frame with a given websocket `opcode`.
const char *mg_get_header(const struct mg_connection *, const char *name);
Get the value of particular HTTP header. This is a helper function.
It traverses http_headers array, and if the header is present in the array,
returns its value. If it is not present, NULL is returned.
int mg_get_var(const struct mg_connection *conn, const char *var_name,
char *buf, size_t buf_len);
Gets HTTP form variable. Both POST buffer and query string are inspected.
Form variable is url-decoded and written to the buffer. On success, this
function returns the length of decoded variable. On error, -1 is returned if
variable not found, and -2 is returned if destination buffer is too small
to hold the variable. Destination buffer is guaranteed to be
'\0' - terminated if it is not NULL or zero length.
int mg_parse_header(const char *hdr, const char *var_name, char *buf,
size_t buf_size);
This function parses HTTP header and fetches given variable's value in a buffer.
A header should be like `x=123, y=345, z="other value"`. This function is
designed to parse Cookie headers, Authorization headers, and similar. Returns
the length of the fetched value, or 0 if variable not found.
int mg_modify_passwords_file(const char *passwords_file_name,
const char *domain,
const char *user,
const char *password);
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.
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.
int mg_parse_multipart(const char *buf, int buf_len,
char *var_name, int var_name_len,
char *file_name, int file_name_len,
const char **data, int *data_len);
Parses a buffer that contains multipart form data. Stores chunk name
in a `var_name` buffer. If chunk is an uploaded file, then `file_name`
will have a file name. `data` and `data_len` will point to the chunk data.
Returns number of bytes to skip to the next chunk.
struct mg_connection *mg_connect(struct mg_server *server,
const char *host, int port, int use_ssl);
Create connection to the remote host. Returns `NULL` on error, non-null
if the connection has been scheduled for connection. Upon a connection,
Mongoose will send `MG_CONNECT` event to the event handler.

View File

@ -1,27 +0,0 @@
# Mongoose Build on Android
This is a small guide to help you run mongoose 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 dont need root access to run mongoose on Android.
- Clone Mongoose Git repo
- 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/mongoose`
That should generate mongoose/lib/armeabi/mongoose
- Using the adb tool (you need to have Android SDK installed for that),
push the generated mongoose binary to `/data/local` folder on device.
- From adb shell, navigate to `/data/local` and execute `./mongoose`.
- 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](http://cesanta.com/images/android_build.png)
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 mongoose in Android
Java applications.
- TODO: A Java application that interacts with the native binary or a
shared library.

View File

@ -1,34 +0,0 @@
How To Create Basic Website With Mongoose
===========================================
## 1. Create a directory which will contain your website files. For example, on drive `C:\`, create a directory called `my_website`:
![screenshot](http://cesanta.com/images/tut_basic/tut1.png)
## 2. Inside `my_website` directory, create a new file called "index". This will be the default web page shown when the website is visited.
![screenshot](http://cesanta.com/images/tut_basic/tut2.png)
## 3. Open index file with your favorite editor (for example, Notepad) and enter some HTML code:
![screenshot](http://cesanta.com/images/tut_basic/tut3.png)
## 4. Save this file as `index.html`:
![screenshot](http://cesanta.com/images/tut_basic/tut4.png)
## 5. Download Mongoose executable from http://cesanta.com/mongoose.shtml and copy the executable inside `my_website` directory:
![screenshot](http://cesanta.com/images/tut_basic/tut5.png)
## 6. Double-click mongoose executable. An icon will appear on a system tray in the bottom right corner of the desktop:
![screenshot](http://cesanta.com/images/tut_basic/tut6.png)
## 7. Click on the mongoose icon and choose "Go to my address" menu:
![screenshot](http://cesanta.com/images/tut_basic/tut7.png)
## 8. A browser will popup displaying `index.html` file. Now, you can expand your website by adding more content.
![screenshot](http://cesanta.com/images/tut_basic/tut8.png)

View File

@ -1,173 +0,0 @@
# Mongoose Embedding Guide
Embedding Mongoose is done in two steps:
1. Copy
[mongoose.c](https://raw.github.com/cesanta/mongoose/master/mongoose.c) and
[mongoose.h](https://raw.github.com/cesanta/mongoose/master/mongoose.h)
to your application's source tree and include them in the build.
2. Somewhere in the application code, call `mg_create_server()` to create
a server, configure it with `mg_set_option()` and loop with
`mg_poll_server()` until done. Call `mg_destroy_server()` to cleanup.
Here's a minimal application `app.c` that embeds mongoose:
#include "mongoose.h"
int main(void) {
struct mg_server *server = mg_create_server(NULL, NULL);
mg_set_option(server, "document_root", "."); // Serve current directory
mg_set_option(server, "listening_port", "8080"); // Open port 8080
for (;;) {
mg_poll_server(server, 1000); // Infinite loop, Ctrl-C to stop
}
mg_destroy_server(&server);
return 0;
}
To compile it, put `mongoose.c`, `mongoose.h` and `app.c` into one
folder, start terminal on UNIX or Visual Studio command line prompt on Windows,
and run the following command:
cc app.c mongoose.c -pthread -o app # on Unix
cl.exe app.c mongoose.c /TC /MD # on Windows
When run, this simple application opens port 8080 and serves static files,
CGI files and lists directory content in the current working directory.
It is possible to generate HTML page content. Mongoose can call user-defined
function when certain events occur.
That function is called _an event handler_, and it is the second parameter
to `mg_create_server()` function. Here is the example event handler function:
int event_handler(struct mg_connection *conn, enum mg_event ev) {
switch (ev) {
case MG_AUTH: return MG_TRUE;
default: return MG_FALSE;
}
}
Event handler is called by Mongoose with `struct mg_connection *`
pointer and an event number. `struct mg_connection *conn`
has all information about the request: HTTP headers, POST or websocket
data buffer, etcetera. `enum mg_event ev` tells which exactly event is sent.
For each event, an event handler returns a value which tells Mongoose how
to behave.
The sequence of events for every connection is this:
* `MG_AUTH` - Mongoose asks whether this connection is authorized. If event
handler returns `MG_FALSE`, then Mongoose does not serve the request but
sends authorization request to the client. If `MG_TRUE` is returned,
then Mongoose continues on with the request.
* `MG_REQUEST` - Mongoose asks event handler to serve the request. If
event handler serves the request by sending a reply,
it should return `MG_TRUE`. Otherwise,
it should return `MG_FALSE` which tells Mongoose that request is not
served and Mongoose should serve it. For example, event handler might
choose to serve only RESTful API requests with URIs that start with
certain prefix, and let Mongoose serve all static files.
If event handler decides to serve the request, but doesn't have
all the data at the moment, it should return `MG_MORE`. That tells
Mongoose to keep the connection open after callback returns.
`mg_connection::connection_param` pointer is a placeholder to keep
user-specific data. For example, handler could decide to open a DB
connection and store DB connection handle in `connection_param`.
* `MG_POLL` is sent to every connection on every iteration of
`mg_poll_server()`. Event handler should return `MG_FALSE` to ignore
this event. If event handler returns `MG_TRUE`, then Mongoose assumes
that event handler has finished sending data, and Mongoose will
close the connection.
* `MG_HTTP_ERROR` sent when Mongoose is about to send HTTP error back
to the client. Event handler can choose to send a reply itself, in which
case event handler must return `MG_TRUE`. Otherwise, event handler must
return `MG_FALSE`
* `MG_CLOSE` is sent when the connection is closed. This event is used
to cleanup per-connection state stored in `connection_param`
if it was allocated.
Let's extend our minimal application example and
create an URI that will be served by user's C code. The app will handle
`/hello` URI by showing a hello message. So, when app is run,
http://127.0.0.1:8080/hello will say hello, and here's the code:
#include <string.h>
#include "mongoose.h"
static int event_handler(struct mg_connection *conn, enum mg_event ev) {
if (ev == MG_AUTH) {
return MG_TRUE; // Authorize all requests
} else if (ev == MG_REQUEST && !strcmp(conn->uri, "/hello")) {
mg_printf_data(conn, "%s", "Hello world");
return MG_TRUE; // Mark as processed
} else {
return MG_FALSE; // Rest of the events are not processed
}
}
int main(void) {
struct mg_server *server = mg_create_server(NULL, event_handler);
mg_set_option(server, "document_root", ".");
mg_set_option(server, "listening_port", "8080");
for (;;) {
mg_poll_server(server, 1000); // Infinite loop, Ctrl-C to stop
}
mg_destroy_server(&server);
return 0;
}
## Example code
Mongoose source code contains number of examples, located in the
[examples](https://github.com/cesanta/mongoose/blob/master/examples/) directory.
To build any example, go to the respective directory and run `make`.
## Compilation flags
Below is the list of compilation flags that enable or disable certain
features. By default, some features are enabled, and could be disabled
by setting appropriate `NO_*` flag. Features that are disabled by default
could be enabled by setting appropriate `USE_*` flag. Bare bones Mongoose
is quite small, about 30 kilobytes of compiled x86 code. Each feature adds
a couple of kilobytes to the executable size, and also has some runtime penalty.
Note that some flags start with `NS_` prefix. This is because Mongoose uses
[Net Skeleton](http://github.com/cesanta/net_skeleton) as a low-level
networking engine. If user code has `#include <net_skeleton.h>`, then
all Net Skeleton functions will be available too.
-DMONGOOSE_NO_AUTH Disable MD5 authorization support
-DMONGOOSE_NO_CGI Disable CGI support
-DMONGOOSE_NO_DAV Disable WebDAV support
(PUT, DELETE, MKCOL, PROPFIND methods)
-DMONGOOSE_NO_DIRECTORY_LISTING Disable directory listing
-DMONGOOSE_NO_FILESYSTEM Disables all file IO, serving from memory only
-DMONGOOSE_NO_LOGGING Disable access/error logging
-DMONGOOSE_ENABLE_THREADS Enable mg_start_thread() function
-DMONGOOSE_NO_WEBSOCKET Disable WebSocket support
-DMONGOOSE_NO_USER No concept of a user on used platform.
(Platform does not provide getpwnam, setgid or setuid)
-DMONGOOSE_USE_IDLE_TIMEOUT_SECONDS=X Idle connection timeout, default is 30
-DMONGOOSE_USE_LUA Enable Lua scripting
-DMONGOOSE_USE_LUA_SQLITE3 Enable sqlite3 binding for Lua
-DMONGOOSE_USE_POST_SIZE_LIMIT=X POST requests larger than X will be
rejected, not set by default
-DMONGOOSE_USE_EXTRA_HTTP_HEADERS=X Append X to the HTTP headers
for static files, empty by default
-DNS_ENABLE_DEBUG Enables debug messages on stdout, very noisy
-DNS_ENABLE_SSL Enable SSL
-DNS_ENABLE_IPV6 Enable IPv6 support
-DNS_ENABLE_HEXDUMP Enables hexdump of sent and received traffic
-DNS_STACK_SIZE=X Sets stack size to X for ns_start_thread()
-DNS_DISABLE_THREADS Disable threads support
-DNS_DISABLE_SOCKETPAIR For systems without loopback interface
-DMONGOOSE_SEND_NS_EVENTS Send Net Skeleton events to the event handler
in addition to the Mongoose events

View File

@ -1,45 +0,0 @@
# Mongoose FAQ
## My Antivirus Software reports Mongoose as a security threat
Mongoose doesn't contain any malicious logic. Antivirus reports a
[false positive](http://en.wikipedia.org/wiki/Type_I_and_type_II_errors#False_positive_error).
This is when certain byte sequence in Mongoose accidentally matches
virus signature in the Antivirus database.
## Download page doesn't work
Please make sure Javascript is enabled in your browser, and that the
antivirus software is not blocking the download.
## MacOS message: "Mongoose.app is damaged and cant be opened. You should move it to the Trash"
This happens on newer MacOS systems. The reason for the message
is the fact Mongoose.app is not digitally signed.
Mongoose download procedure changes the app on the fly by injecting
user information in the binary, making any prior digital signature void.
Open "System Preferences" -> "Security" and set "Allow apps downloaded from"
to "Anywhere". Revert the settings once Mongoose is installed.
## 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,
correct interpreter is `php-cgi.exe` (`php-cgi` on UNIX). Solution: specify
full path to the PHP interpreter, e.g.:
mongoose -cgi_interpreter /full/path/to/php-cgi
## Mongoose fails to start
If Mongoose exits immediately when run, this
usually indicates a syntax error in the configuration file
(named `mongoose.conf` by default) or the command-line arguments.
Syntax checking is omitted from Mongoose 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 Mongoose to use `__stdcall` convention, add `/Gz` compilation
flag to the Visual Studio project settings.

View File

@ -1,18 +0,0 @@
How To Share Files With Mongoose
===========================================
## 1. Download Mongoose executable from http://cesanta.com/mongoose.shtml and copy the executable inside the directory you want to share:
![screenshot](http://cesanta.com/images/tut_sharing/tut1.png)
## 2. Double-click mongoose executable. A browser will start automatically, an icon will appear on a system tray in the bottom right corner of the desktop:
![screenshot](http://cesanta.com/images/tut_sharing/tut2.png)
## 3. Click on the mongoose icon
![screenshot](http://cesanta.com/images/tut_sharing/tut3.png)
## 4. Click on "Go to my address" to launch a browser locally. Or, to access a folder from another machine, launch a browser and type in the URL:
![screenshot](http://cesanta.com/images/tut_sharing/tut4.png)

View File

@ -1,44 +0,0 @@
# Mongoose Internals
Mongoose has single-threaded, event-driven, asynchronous, non-blocking core.
`mg_create_server()` creates a web server instance. An instance is a container
for the config options and list of active connections. To do the actual
serving, user must call `mg_poll_server()`, which iterates over all
active connections, performing `select()` syscall on all sockets with a
timeout of specified number of milliseconds. When `select()` returns, Mongoose
does an IO for each socket that has data to be sent or received. Application
code must call `mg_poll_server()` in a loop.
Mongoose server instance is designed to be used by a single thread.
It is an error to have more then
one thread calling `mg_poll_server()`, `mg_set_option()` or any other function
that take `struct mg_server *` parameter. Mongoose does not
mutex-protect `struct mg_server *`, therefore the best practice is
to call server management functions from the same thread (an IO thread).
On a multi-core systems, many server instances can be created, sharing the
same listening socket and managed by separate threads (see [multi_threaded.c](https://github.com/cesanta/mongoose/blob/master/examples/multi_threaded.c))
example.
It is an error to pass and store `struct mg_connection *` pointers for
later use to send data. The reason is that they can be invalidated by the
next `mg_poll_server()` call. For such a task,
there is `mg_iterate_over_connections()` API
exists, which sends a callback function to the IO thread, then IO thread
calls specified function for all active connection.
When mongoose buffers in HTTP request and successfully parses it, it calls
appropriate URI handler immediately for GET requests. For POST requests,
Mongoose delays the call until the whole POST request is buffered in memory.
POST data is available to the callback as `struct mg_connection::content`,
and POST data length is in `struct mg_connection::content_len`.
Note that websocket connections are treated the same way. Mongoose buffers
websocket frame in memory, and calls URI handler when frame is fully
buffered. Frame data is available `struct mg_connection::content`, and
data length is in `struct mg_connection::content_len`, i.e. very similar to
the POST request. `struct mg_connection::is_websocket` flag indicates
whether the request is websocket or not. Also, for websocket requests,
there is `struct mg_connection::wsbits` field which contains first byte
of the websocket frame which URI handler can examine. Note that to
reply to the websocket client, `mg_websocket_write()` should be used.
To reply to the plain HTTP client, `mg_write()` should be used.

View File

@ -1,154 +0,0 @@
# Mongoose Configuration Options
### 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 Mongoose
web server, the ACL is a comma separated list of IP subnets, where each
subnet is prepended 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. Example: `$ mongoose -access_control_list -0.0.0.0/0,+192.168/16` to deny all acccesses except those from `192.168/16` subnet. Note that if the option is set, then all accesses are forbidden
by default. Thus in a previous example, `-0.0.0.0` part is not necessary.
For example, `$mongoose access_control_list +10.0.0.0/8`
means disallow all, allow subnet 10/8 only.
To learn more about subnet masks, see the
[Wikipedia page on Subnetwork](http://en.wikipedia.org/wiki/Subnetwork)
Default: not set, all accesses are allowed.
### access\_log\_file
Path to a file for access logs. Either full path, or relative to the
mongoose executable. Default: not set, no query logging is done.
### auth_domain
Authorization realm used in `.htpasswd` authorization. Default: `mydomain.com`
### cgi_interpreter
Path to an executable to be used use as an interpreter for __all__ CGI scripts
regardless script extension. Default: not set, Mongoose looks at
[shebang line](http://en.wikipedia.org/wiki/Shebang_(Unix\).
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 directory where mongoose executable is located.
If all CGIs use the same interpreter, for example they are all PHP, then
`cgi_interpreter` option can be set to the path to `php-cgi.exe` executable and
shebang line in the CGI scripts can be omitted.
**Note**: PHP scripts must use `php-cgi.exe`, not `php.exe`.
### cgi_pattern
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 a pattern. Note that **full file path** is
matched against the pattern, not the URI.
When Mongoose starts CGI program, it creates new environment for it (in
contrast, usually child program inherits the environment from parent). Several
environment variables however are inherited from Mongoose's environment,
they are: `PATH`, `TMP`, `TEMP`, `TMPDIR`, `PERLLIB`, `MONGOOSE_CGI`. On UNIX
it is also `LD_LIBRARY_PATH`. On Windows it is also `COMSPEC`, `SYSTEMROOT`,
`SystemDrive`, `ProgramFiles`, `ProgramFiles(x86)`, `CommonProgramFiles(x86)`.
Default: `**.cgi$|**.pl$|**.php$`
### dav\_auth\_file
Authentication file for WebDAV mutation requests: `PUT`, `DELETE`, `MKCOL`.
The format of that file is the same as for the `.htpasswd` file
used for digest authentication. It can be created and managed by
`mongoose -A` command. Default: not set, WebDAV mutations are disallowed.
### document_root
A directory to serve. Default: current working directory.
### enable\_directory\_listing
Enable directory listing, either `yes` or `no`. Default: `yes`.
### enable\_proxy
Enable proxy functionality, either `yes` or `no`. If set to `yes`, then
browsers can be configured to use Mongoose as a proxy. Default: `no`.
### extra\_mime\_types
Extra mime types to recognize, in form `extension1=type1,extension2=type2,...`.
Extension must include dot. Example:
`mongoose -extra_mime_types .cpp=plain/text,.java=plain/text`. Default: not set.
### global\_auth\_file
Path to a global passwords file, either full path or relative to the mongoose
executable. If set, per-directory `.htpasswd` files are ignored,
and all requests are authorised against that file. Use `mongoose -A` to
manage passwords, or third party utilities like
[htpasswd-generator](http://www.askapache.com/online-tools/htpasswd-generator).
Default: not set, per-directory `.htpasswd` files are respected.
### 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 name, e.g.
`mongoose -hide_files_patterns secret.txt|even_more_secret.txt`. Default:
not set.
### index_files
Comma-separated list of files to be treated as directory index
files. Default: `index.html,index.htm,index.cgi,index.shtml,index.php`
### listening_port
Port to listen on. Port could be prepended by the specific IP address to bind
to, e.g. `mongoose -listening_port 127.0.0.1:8080`. Otherwise Mongoose
will bind to all addresses. To enable SSL, build Mongoose with
`-DNS_ENABLE_SSL` compilation option, and specify `listening_port` as
`ssl://PORT:SSL_CERTIFICATE.PEM`. Example SSL listener:
`mongoose -listening_port ssl://8043:ssl_cert.pem`. Note that PEM file should
be in PEM format, and must have both certificate and private key in it,
concatenated together. More than one listening port can be specified,
separated by comma,
for example `mongoose -listening_port 8080,8000`. Default: 8080.
### run\_as\_user
Switch to given user credentials after startup. UNIX-only. This option is
required when mongoose needs to bind on privileged port on UNIX, e.g.
$ sudo mongoose -listening_port 80 -run_as_user nobody
Default: not set.
### url\_rewrites
Comma-separated list of URL rewrites in the form of
`uri_pattern=file_or_directory_path`. When Mongoose receives the 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 mongoose patterns, is a prefix pattern. If `uri_pattern`
is a number, then it is treated as HTTP error code, and `file_or_directory_path`
should be an URI to redirect to. Mongoose will issue `302` temporary redirect
to the specified URI with following parameters:
`?code=HTTP_ERROR_CODE&orig_uri=ORIGINAL_URI&query_string=QUERY_STRING`.
If `uri_pattern` starts with `@` symbol, then Mongoose compares
it with the `HOST` header of the request. If they are equal, Mongoose sets
document root to `file_or_directory_path`, implementing virtual hosts support.
Examples:
# Redirect all accesses to `.doc` files to a special script
mongoose -url_rewrites **.doc$=/path/to/cgi-bin/handle_doc.cgi
# Implement user home directories support
mongoose -url_rewrites /~joe/=/home/joe/,/~bill=/home/bill/
# Redirect 404 errors to a specific error page
mongoose -url_rewrites 404=/cgi-bin/error.cgi
# Virtual hosts example: serve foo.com domain from different directory
mongoose -url_rewrites @foo.com=/var/www/foo.com
Default: not set.

View File

@ -1,49 +0,0 @@
How To Create A PHP Website With Mongoose
===========================================
## 1. Create a directory which will contain your website files. For example, on drive `C:\`, create a directory called `my_website`:
![screenshot](http://cesanta.com/images/tut_php/tut1.png)
## 2. Inside `my_website` directory, create a new file called "index". This will be the default web page shown when the website is visited.
![screenshot](http://cesanta.com/images/tut_php/tut2.png)
## 3. Open index file with your favorite editor (for example, Notepad) and enter some HTML / PHP code:
![screenshot](http://cesanta.com/images/tut_php/tut3.png)
## 4. Save this file as `index.php`:
![screenshot](http://cesanta.com/images/tut_php/tut4.png)
## 5. Download Mongoose executable from http://cesanta.com/mongoose.shtml and copy the executable inside `my_website` directory:
![screenshot](http://cesanta.com/images/tut_php/tut5.png)
## 6. Double-click mongoose executable. An icon will appear on a system tray in the bottom right corner of the desktop:
![screenshot](http://cesanta.com/images/tut_php/tut6.png)
## 7. Download PHP 5.3 zip (do NOT download PHP 5.5 cause you might have missing DLLs problem) from http://windows.php.net/download and extract it to `C:\php5` directory:
![screenshot](http://cesanta.com/images/tut_php/tut7.png)
## 8. Click on the mongoose icon and choose "Edit Settings" menu.:
![screenshot](http://cesanta.com/images/tut_php/tut8.png)
## 9. A settings dialog will appear. Click on `cgi_interpreter` button:
![screenshot](http://cesanta.com/images/tut_php/tut9.png)
## 10. Choose `C:\php5\php-cgi.exe` and click "Save Settings":
![screenshot](http://cesanta.com/images/tut_php/tut10.png)
## 11. Click on the mongoose icon and choose "Go to my address" menu:
![screenshot](http://cesanta.com/images/tut_php/tut11.png)
## 12. A browser will popup displaying `index.php`.
![screenshot](http://cesanta.com/images/tut_php/tut12.png)

View File

@ -1,218 +0,0 @@
# Mongoose Release Notes
## Release 5.6, 2015-03-17
Changes in Libmongoose library:
- Added `-dav_root` configuration option that gives an ability to mount
a different root directory (not document_root)
- Fixes for build under Win23 and MinGW
- Bugfix: Double dots removal
- Bugfix: final chunked response double-send
- Fixed compilation in 64-bit environments
- Added OS/2 compatibility
- Added `getaddrinfo()` call and `NS_ENABLE_GETADDRINFO`
- Various SSL-related fixes
- Added integer overflow protection in `iobuf_append()` and `deliver_websocket_frame()`
- Fixed NetBSD build
- Enabled `NS_ENABLE_IPV6` build for Visual Studio 2008+
- Enhanced comma detection in `parse_header()`
- Fixed unchanged memory accesses on ARM
- Added ability to use custom memory allocator through NS_MALLOC, NS_FREE, NS_REALLOC
Changes in Mongoose binary:
- Added `-start_browser` option to disable automatic browser launch
- Added experimental SSL support. To listen on HTTPS port, use `ssl://PORT:SSL_CERT` format. For example, to listen on HTTP port 8080 and HTTPS port 8043, use `-listening_port 8080,ssl://8043:ssl_cert.pem`
## Release 5.5, October 28 2014
Changes in Libmongoose library:
- Added new API function: `mg_forward()` for proxying functionality
- Added new API function: `mg_send_file_data()` for sending file data
- Added new utility API functions: `mg_mmap() and mg_munmap()`
- Changed the way SSL settings are handled: removed `ssl_certificate` and
`ssl_ca_certificate` options, and instead made `listening_port` accept
`ssl://PORT:SSL_CERT:CA_CERT` notation
- Added ability to listen on multiple ports, see `listening_port` documentation
- Added `enable_proxy` option
- Added [cookie_authentication](https://github.com/cesanta/mongoose/tree/master/examples/cookie_authentication) example
- Added [websocket\_ssl\_proxy](https://github.com/cesanta/mongoose/tree/master/examples/websocket_ssl_proxy) example
- Added [http_client](https://github.com/cesanta/mongoose/tree/master/examples/http_client) example
- Increased default 'idle connection' timeout from 30 to 300 seconds
- Fixed MinGW build
- Refactored all examples, put each in it's own directory with dedicated build
- Many smaller bugfixed, including SSL, CGI, API, proxy, etc
Changes in pre-compiled binaries:
- Support for multiple listening ports
- Fixed CGI handling for scripts that specify interpreter in the hashbang line
## Release 5.4, July 28 2014
Changes in Libmongoose library:
- Added `hexdump_file` option for low-level request/reply debugging
- Added `mg_template()` API function for generating HTML pages from
templates with expansions
- Fixed `struct mg_connection::local_ip` handling, `mg_set_option()`
behavior with NULL values
- Added `mg_send_file()` call to send arbitrary file to the client
- Added `mg_terminate_ssl()` for SSL termination functionality
- Added HTTP proxy support, `enable_proxy` config option
- Added `mg_next()` for iterating over existing active connections
- Added client-side SSL auth, `ssl_ca_certificate` option
- Added `mg_wakeup_server_ex()` for pushing messages to existing connections
- Added `MG_WS_HANDSHAKE` and `MG_WS_CONNECT` events that are sent on
Websocket handshake is connection establishment, respectively
- Removed server-side Lua support
- Filesystem access, reading from socket/SSL performance improvements
- DAV PROPFIND memory leak fixed
- Added `big_upload.c` and enhanced `upload.c` example
- Added `proxy.c` example that demonstrates proxy functionality and SSE pushes
- Added `websocket2.c` example that shows simple web chat implementation
over websockets
- Various minor fixes
Changes in pre-compiled binaries:
- Created HTML administration console
- When server is started, browser is started automatically
- Fixed directory listing bug when directory contains `#` character
- Removed built-in Lua Server Pages in the binary, and instead
added Mongoose + Lua developer bundle which has Lua Server Pages support.
That also solves external Lua modules loading problem.
## Release 5.3, March 10 2014
Changes in Libmongoose library:
* Moved to the evented API. Updated API documentation is at
http://cesanta.com/docs/Embed.shtml
http://cesanta.com/docs/API.shtml
* Added `MG_LUA` event for exporting custom variables to the Lua environment
* Added virtual hosts capability, see `url_rewrites` option description at
http://cesanta.com/docs/Options.shtml
* Added mjpg serving example
* Cleaned up and documented HTTP client API, with unit tests
* Added `mg_wakeup_server()` to awaken `mg_poll_server()`
from another thread
* Moved Mongoose IO core to [https://github.com/cesanta/net_skeleton](Net Skeleton)
* Added connection hexdump functionality for developers
* Bug fixes
Changes in pre-compiled binaries:
* New awesome Mongoose logos by our designer Katrin - thanks Katrin!
Check them out at http://cesanta.com/products.shtml
* Added Lua Server Pages support to the free version, quick intro is at
http://cesanta.com/docs/Lua.shtml
* Added quick "Set shared directory" menu item to set `document_root`
* Added SSI support to the Pro version
* Removed SSL support from the Pro version
## Release 5.2, Feb 1 2014
* Windows binary made fully UNICODE aware. In previous versions,
the presence of non-ASCII chars in document root, CGI script name,
or directory name might have broken Mongoose as stand-alone
or as Windows service. Now Mongoose works with non-ASCII paths properly.
Internally, Mongoose uses UTF8 encoding. When making WinAPI calls,
mongoose converts UTF8 strings to wide chars and calls UNICODE API.
* Enhanced authorization API by providing `mg_set_auth_handler()` and
`mg_authorize_digest()`
* Removed `mg_add_uri_handler()`, added `mg_set_request_handler()`.
There is only oneURI handler that handles all requests, just like in 4.x.
The reason for this change is to provide an ability to catch all URIs,
and at the same time signal Mongoose to continue handling specific URIs.
* Added `mg_parse_multipart()` API for file uploads.
Note that the restriction on uploading huge files still exists,
and will be eliminated in the next release.
* Allowing mongoose to bind to port 0, in which case it'll bind to any
random unused port.
* Moved `idle_timeout_ms` run-time option to compile-time flag
* Added asynchronous HTTP client, not documented yet. Documentation and
examples are coming in the next couple of weeks. Async Websocket client
is scheduled for the next release. See usage examples at `unit_test.c`
* Windows and MacOS pre-built binaries are now split to free and paid ones,
paid binaries include CGI, SSL, Lua, Sqlite, support and updates.
Linux pre-built binary includes all functionality and is free, and will
continue to be free. Source code for Windows and MacOS GUI is closed.
Disclaimer: source code for the command line stand-alone server,
as well as Mongoose library itself, will never be closed.
* Multiple bug fixes and minor enhancements
## Release 5.1, Jan 10 2014
* CGI-related bugs where fixed, primarily for Windows platform
* Bugs on Windows related to UNICODE support were fixed
* Added a feature to support "error pages" through redirect.
Done using `-url_redirects` option, details are on
http://cesanta.com/docs/Options.shtml
## Release 5.0, Jan 6 2014
* Internal core has been changed from blocking, thread-per-connection to
non-blocking, asynchronous, one thread for all.
* API modification for server creation and response creation. That allowed
keep-alive support for dynamic requests, boosting the embedded performance
to 100+ thousands requests per second on a single core
(as measured on my development MacBook laptop)
* Unified handling of POST requests and Websocket requests by putting a
payload into `conn->content`, `conn->content_len` attributes.
That simplified user code and eliminated the need of `mg_read()`,
since mongoose buffers all data prior to calling the callback
* keep-alive support is the default
* Dropped SSI support and throttling support
* Several configuration parameters are gone:
* `cgi_environment` (replaced with MONGOOSE_CGI),
* `protect_uri` (not useful)
* `ssi_pattern` (SSI support is gone)
* `throttle` (throttling support is gone)
* `error_log_file` (not used)
* `enable_keep_alive` (enabled by default)
* `listening_ports` (renamed to listening_port)
* `num_threads` (core has changed to single thread)
* `put_delete_auth_file` (renamed to dav_auth_file)
* `authentication_domain` (renamed to auth_domain)
* Due to the async, non-blocking nature of the core, few restrictions
are now in place:
* user callbacks must not block
* POST and Websocket data are now buffered, and cannot be huge
* mongoose is now capable on listening on only one port
## Release 4.1, Oct 2013
## Release 4.0, Oct 2013
## Release 3.8, Sep 2013
## Release 3.7, Feb 2 2013
* Added "redirect to SSL port" functionality, e.g. if you specify
`-listening_ports 8080r,8043s`
then all requests to HTTP port 8080 will be redirected to HTTPS port 8043
* Added `mg_download()` API, an HTTP client interface!
* Lua server pages now must output HTTP headers -- full control for Lua
* Added pre-built binary for MacOS, with initial GUI support
* API change: got rid of events, moved to struct `mg_callbacks`
* Bugfixes, thanks to contributors
## Release 3.7, Jan 18 2013
* Fixed source code archive (main.c was missing)
* Extended Windows GUI functionality:
* Added "Start browser" systray popup menu item
* Enhanced configuration editor
* Renamed config options:
* `put_delete_passwords_file` -> `put_delete_auth_file`
* `global_passwords_file` -> `global_auth_file`
* `select()` changed to `poll()`, to avoid big file descriptor
`FD_SET` problem on UNIX
* Couple of bugfixes, thanks to contributors
Earlier release notes could be found by searching
[Mongoose mailing list](https://groups.google.com/forum/#!forum/mongoose-users)

View File

@ -1,70 +0,0 @@
# Mongoose SSL guide
SSL is a protocol that makes web communication secure. To enable SSL
in mongoose, 2 steps are required:
1. Create valid SSL certificate file
2. Append SSL certificate file path to the `listening_ports` option
Below is the `mongoose.conf` file snippet for typical SSL setup:
document_root www_root # Serve files in www_root directory
listening_ports 80,443:cert.pem # Listen on ports 80 and 443
## How to create SSL certificate file
SSL certificate file is a text file that must contain at least two
sections:
1. A private key
2. A certificate
Both sections should be chunks of text in PEM format. When PEM file is
opened in a text editor, it looks like this:
-----BEGIN RSA PRIVATE KEY-----
MIIEogIBAAKCAQEAwONaLOP7EdegqjRuQKSDXzvHmFMZfBufjhELhNjo5KsL4ieH
hYN0Zii2yTb63jGxKY6gH1R/r9dL8kXaJmcZrfSa3AgywnteJWg=
-----END RSA PRIVATE KEY-----
-----BEGIN CERTIFICATE-----
MIIDBjCCAe4CCQCX05m0b053QzANBgkqhkiG9w0BAQQFADBFMQswCQYDVQQGEwJB
SEGI4JSxV56lYg==
-----END CERTIFICATE-----
Two aforementioned sections are clearly seen. Typically, those section
are bigger then in the example shown. The text between the `BEGIN` and
`END` is the text representation of binary data, a private key and a
certificate. Therefore, in order to create a certificate file,
* private key must be converted to PEM format
* certificate must be converted to PEM format
* those two should be concatenated into a single file
If the certificate chain in used, a chain file also needs to be
converted into PEM format and appended to the certificate file.
## How SSL works
SSL is a protocol that can encrypt communication between two parties. If third
party observes all messages passed by, it would be very
hard for the third party (though not impossible) to decrypt the communication.
The idea is based on so-called public key encryption. Communicating parties
have two keys: a public key and a private key. A public key is advertised
to everybody, and it is contained in a certificate. A private key is kept
secret. Security algorithm works in a way that anybody can encrypt
a message using public key, and only private key can decrypt it.
This is why web server needs both private key and certificate: private key
is used to decrypt incoming messages, and certificate is used to tell the
public key to the other party. When communication starts, parties exchange
their public keys, and keep private keys to themselves. Man-in-the-middle
who observes the communication is unable to decrypt the messages cause
private keys are required for decryption.
Encryption algorithms are built on top of hard mathematical problem, which
makes it very expensive for man-in-the-middle to compute private keys.
For example, RSA algorithm is based on a mathematical problem of factorization.
It is easy to generate two very large prime numbers `P` and `Q` and make
a product `P * Q`. But given a product, it is very hard to recover these
two prime numbers - this is called factorization.

View File

@ -1,86 +0,0 @@
# Mongoose User Guide
Mongoose is small and easy to use web server built on top of
mongoose library. It is designed with maximum simplicity in mind. For example,
to share any directory, just drop mongoose executable in that directory,
double-click it (on UNIX, run it from shell) 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.
On Windows and Mac, Mongoose iconifies itself to the system tray when started.
Right-click on the icon to pop up a menu, where it is possible to stop
mongoose, or configure it.
On UNIX, `mongoose` is a command line utility. Running `mongoose` in
terminal, optionally followed by configuration parameters
(`mongoose [OPTIONS]`) or configuration file name
(`mongoose [config_file_name]`) starts the
web server:
$ mongoose -document_root /var/www # Running mongoose with cmdline options
$ mongoose /etc/my_config.txt # Running mongoose with config file
$ mongoose # Running with no parameters. This will
# serve current directory on port 8080
Mongoose does not detach from terminal. Pressing `Ctrl-C` keys
stops the server.
When started, mongoose first searches for the configuration file.
If configuration file is specified explicitly in the command line, then
specified configuration file is used.
Otherwise, mongoose would search for file `mongoose.conf` in the same directory
where binary is located, and use it. Configuration file can be absent.
Configuration file is a sequence of lines, each line containing
command line argument name and it's value. Empty lines and lines beginning
with `#` are ignored. Here is the example of `mongoose.conf` file:
# This is a comment
document_root C:\www
listening_port 80
ssl_certificate C:\mongoose\ssl_cert.pem
Command line arguments are highest priority and can override
configuration file settings. For example, if `mongoose.conf` has line
`document_root /var/www`, and mongoose has been started as
`mongoose -document_root /etc`, then `/etc` directory will be used as
document root.
Note that configuration options on the command line must start with `-`,
and their names are the same as in the config file. Exampli gratia,
the following two setups are equivalent:
$ mongoose -listening_port 1234 -document_root /var/www
$ cat > mongoose.conf
listening_ports 1234
document_root /var/www
^D
$ mongoose
Mongoose can also be used to modify `.htpasswd` passwords file:
$ mongoose -A .htpasswd mydomain.com user_name user_password
Unlike other web servers, mongoose does not require CGI scripts be located in
a special directory. CGI scripts can be anywhere. CGI (and SSI) files are
recognized by the file name pattern. Mongoose 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:
# Pattern Meaning
**.cgi$ Any string that ends with .cgi
/foo Any string that begins with /foo
**a$|**b$ Any string that ends with a or b
To restrict CGI files only to `/cgi-bin/` directory, use this setting:
$ mongoose -cgi_pattern /cgi-bin/*.cgi # Emulate /cgi-bin/ restriction

View File

@ -1 +0,0 @@
*.exe

View File

@ -1,20 +0,0 @@
# Copyright (c) 2014 Cesanta Software
# All rights reserved
SUBDIRS = $(sort $(filter-out csharp/, $(dir $(wildcard */))))
X = $(SUBDIRS)
ifdef WINDIR
# appending the Winsock2 library at the end of the compiler
# invocation
CFLAGS_EXTRA += -lws2_32
endif
.PHONY: $(SUBDIRS)
all: $(SUBDIRS)
$(SUBDIRS):
@$(MAKE) CFLAGS_EXTRA="$(CFLAGS_EXTRA)" -C $@
clean:
for d in $(SUBDIRS) ; do $(MAKE) -C $$d clean ; done

View File

@ -1,21 +0,0 @@
# Copyright (c) 2014 Cesanta Software
# All rights reserved
PROG = array_vars
CFLAGS = -W -Wall -I../.. -pthread -g -O0 $(CFLAGS_EXTRA)
SOURCES = $(PROG).c ../../mongoose.c
all: $(PROG)
run: $(PROG)
./$(PROG)
$(PROG): $(SOURCES) Makefile
$(CC) -o $(PROG) $(SOURCES) $(CFLAGS)
win:
wine cl $(SOURCES) /MD /nologo /DNDEBUG /O1 /I../.. /Fe$(PROG).exe
wine $(PROG).exe
clean:
rm -rf $(PROG) *.exe *.dSYM *.obj *.exp .*o *.lib *.gc*

View File

@ -1,45 +0,0 @@
// Copyright (c) 2014 Cesanta Software
// All rights reserved
//
// This example demostrates how to use array get variables using mg_get_n_var
// $Date: 2014-09-09 22:20:23 UTC $
#include <stdio.h>
#include <string.h>
#include "mongoose.h"
static int ev_handler(struct mg_connection *conn, enum mg_event ev) {
switch (ev) {
case MG_AUTH: return MG_TRUE;
case MG_REQUEST:
{
mg_printf_data(conn, "Hello! Requested URI is [%s] ", conn->uri);
char buffer[1024];
int i, ret;
for(i=0; (ret = mg_get_var_n(conn, "foo[]", buffer, 1024, i)) > 0; i++)
mg_printf_data(conn, "\nfoo[%d] = %s", i, buffer);
return MG_TRUE;
}
default: return MG_FALSE;
}
}
int main(void) {
struct mg_server *server;
// Create and configure the server
server = mg_create_server(NULL, ev_handler);
mg_set_option(server, "listening_port", "8080");
// Serve request. Hit Ctrl-C to terminate the program
printf("Starting on port %s\n", mg_get_option(server, "listening_port"));
for (;;) {
mg_poll_server(server, 1000);
}
// Cleanup, and free server instance
mg_destroy_server(&server);
return 0;
}

View File

@ -1,12 +0,0 @@
# Copyright (c) 2014 Cesanta Software
# All rights reserved
PROG = big_upload
CFLAGS = -W -Wall -pthread -I../.. -g -O0 $(CFLAGS_EXTRA)
SOURCES = $(PROG).c ../../mongoose.c
$(PROG): $(SOURCES)
$(CC) -o $(PROG) $(SOURCES) $(CFLAGS)
clean:
rm -rf $(PROG) *.exe *.dSYM *.obj *.exp .*o *.lib

View File

@ -1,84 +0,0 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "mongoose.h"
static int handle_request(struct mg_connection *conn) {
if (strcmp(conn->uri, "/upload") == 0) {
FILE *fp = (FILE *) conn->connection_param;
if (fp != NULL) {
fwrite(conn->content, 1, conn->content_len, fp); // Write last bits
mg_printf(conn, "HTTP/1.1 200 OK\r\n"
"Content-Type: text/plain\r\n"
"Connection: close\r\n\r\n"
"Written %ld of POST data to a temp file:\n\n",
(long) ftell(fp));
// Temp file will be destroyed after fclose(), do something with the
// data here -- for example, parse it and extract uploaded files.
// As an example, we just echo the whole POST buffer back to the client.
rewind(fp);
mg_send_file_data(conn, fileno(fp));
return MG_MORE; // Tell Mongoose reply is not completed yet
} else {
mg_printf_data(conn, "%s", "Had no data to write...");
return MG_TRUE; // Tell Mongoose we're done with this request
}
} else {
mg_printf_data(conn, "%s",
"<html><body>Upload example."
"<form method=\"POST\" action=\"/upload\" "
" enctype=\"multipart/form-data\">"
"<input type=\"file\" name=\"file\" /> <br/>"
"<input type=\"submit\" value=\"Upload\" />"
"</form></body></html>");
return MG_TRUE; // Tell mongoose to close this connection
}
}
// Mongoose sends MG_RECV for every received POST chunk.
// When last POST chunk is received, Mongoose sends MG_REQUEST, then MG_CLOSE.
static int handle_recv(struct mg_connection *conn) {
FILE *fp = (FILE *) conn->connection_param;
// Open temporary file where we going to write data
if (fp == NULL && ((conn->connection_param = fp = tmpfile())) == NULL) {
return -1; // Close connection on error
}
// Return number of bytes written to a temporary file: that is how many
// bytes we want to discard from the receive buffer
return fwrite(conn->content, 1, conn->content_len, fp);
}
// Make sure we free all allocated resources
static int handle_close(struct mg_connection *conn) {
if (conn->connection_param != NULL) {
fclose((FILE *) conn->connection_param);
conn->connection_param = NULL;
}
return MG_TRUE;
}
static int ev_handler(struct mg_connection *conn, enum mg_event ev) {
switch (ev) {
case MG_AUTH: return MG_TRUE;
case MG_REQUEST: return handle_request(conn);
case MG_RECV: return handle_recv(conn);
case MG_CLOSE: return handle_close(conn);
default: return MG_FALSE;
}
}
int main(void) {
struct mg_server *server = mg_create_server(NULL, ev_handler);
mg_set_option(server, "listening_port", "8080");
printf("Starting on port %s\n", mg_get_option(server, "listening_port"));
for (;;) {
mg_poll_server(server, 1000);
}
mg_destroy_server(&server);
return 0;
}

View File

@ -1,12 +0,0 @@
# Copyright (c) 2014 Cesanta Software
# All rights reserved
PROG = cookie_auth
CFLAGS = -W -Wall -I../.. -pthread -g -O0 $(CFLAGS_EXTRA)
SOURCES = $(PROG).c ../../mongoose.c
$(PROG): $(SOURCES)
$(CC) -o $(PROG) $(SOURCES) $(CFLAGS)
clean:
rm -rf $(PROG) *.exe *.dSYM *.obj *.exp .*o *.lib

View File

@ -1,97 +0,0 @@
// Copyright (c) 2014 Cesanta Software
// All rights reserved
#include <stdio.h>
#include <string.h>
#include <time.h>
#include "mongoose.h"
static const char *s_login_uri = "/login.html";
static const char *s_secret = ":-)"; // Must be known only to server
static void generate_ssid(const char *user_name, const char *expiration_date,
char *ssid, size_t ssid_size) {
char hash[33];
mg_md5(hash, user_name, ":", expiration_date, ":", s_secret, NULL);
snprintf(ssid, ssid_size, "%s|%s|%s", user_name, expiration_date, hash);
}
static int check_auth(struct mg_connection *conn) {
char ssid[100], calculated_ssid[100], name[100], expire[100];
// Always authenticate requests to login page
if (strcmp(conn->uri, s_login_uri) == 0) {
return MG_TRUE;
}
// Look for session ID in the Cookie.
// That session ID can be validated against the database that stores
// current active sessions.
mg_parse_header(mg_get_header(conn, "Cookie"), "ssid", ssid, sizeof(ssid));
if (sscanf(ssid, "%[^|]|%[^|]|", name, expire) == 2) {
generate_ssid(name, expire, calculated_ssid, sizeof(calculated_ssid));
if (strcmp(ssid, calculated_ssid) == 0) {
return MG_TRUE; // Authenticate
}
}
// Auth failed, do NOT authenticate, redirect to login page
mg_printf(conn, "HTTP/1.1 302 Moved\r\nLocation: %s\r\n\r\n", s_login_uri);
return MG_FALSE;
}
static int check_login_form_submission(struct mg_connection *conn) {
char name[100], password[100], ssid[100], expire[100], expire_epoch[100];
mg_get_var(conn, "name", name, sizeof(name));
mg_get_var(conn, "password", password, sizeof(password));
// A real authentication mechanism should be employed here.
// Also, the whole site should be served through HTTPS.
if (strcmp(name, "Joe") == 0 && strcmp(password, "Doe") == 0) {
// Generate expiry date
time_t t = time(NULL) + 3600; // Valid for 1 hour
snprintf(expire_epoch, sizeof(expire_epoch), "%lu", (unsigned long) t);
strftime(expire, sizeof(expire), "%a, %d %b %Y %H:%M:%S GMT", gmtime(&t));
generate_ssid(name, expire_epoch, ssid, sizeof(ssid));
// Set "session id" cookie, there could be some data encoded in it.
mg_printf(conn,
"HTTP/1.1 302 Moved\r\n"
"Set-Cookie: ssid=%s; expire=\"%s\"; http-only; HttpOnly;\r\n"
"Content-Length: 0\r\n"
"Location: /\r\n\r\n",
ssid, expire);
return MG_TRUE;
}
return MG_FALSE;
}
static int serve_request(struct mg_connection *conn) {
if (strcmp(conn->uri, s_login_uri) == 0 &&
strcmp(conn->request_method, "POST") == 0) {
return check_login_form_submission(conn);
}
return MG_FALSE; // Serve files in the document_root
}
static int ev_handler(struct mg_connection *conn, enum mg_event ev) {
switch (ev) {
case MG_AUTH: return check_auth(conn);
case MG_REQUEST: return serve_request(conn);
default: return MG_FALSE;
}
}
int main(void) {
struct mg_server *server = mg_create_server(NULL, ev_handler);
mg_set_option(server, "listening_port", "8080");
mg_set_option(server, "document_root", ".");
printf("Starting on port %s\n", mg_get_option(server, "listening_port"));
for (;;) {
mg_poll_server(server, 1000);
}
mg_destroy_server(&server);
return 0;
}

View File

@ -1,33 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>WebSocket Test</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style type="text/css">
body {
background-color: #cde; margin: 0;
padding: 0; font: 14px Helvetica, Arial, sans-serif;
}
* { outline: none; }
div.content {
width: 800px; margin: 2em auto; padding: 20px 50px;
background-color: #fff; border-radius: 1em;
}
label { display: inline-block; min-width: 7em; }
input { border: 1px solid #ccc; padding: 0.4em; margin: 0 0 10px 0; }
a:link, a:visited { color: #69c; text-decoration: none; }
@media (max-width: 700px) {
body { background-color: #fff; }
div.content {
width: auto; margin: 0 auto; border-radius: 0; padding: 1em;
}
}
</style>
<body>
<div class="content">
<h1>Mongoose Cookie Base Authentication</h1>
<p>This is an index page. Authentication succeeded.</p>
</body>
</html>

View File

@ -1,44 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>WebSocket Test</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style type="text/css">
body {
background-color: #cde; margin: 0;
padding: 0; font: 14px Helvetica, Arial, sans-serif;
}
* { outline: none; }
div.content {
width: 800px; margin: 2em auto; padding: 20px 50px;
background-color: #fff; border-radius: 1em;
}
label { display: inline-block; min-width: 7em; }
input { border: 1px solid #ccc; padding: 0.4em; margin: 0 0 10px 0; }
a:link, a:visited { color: #69c; text-decoration: none; }
@media (max-width: 700px) {
body { background-color: #fff; }
div.content {
width: auto; margin: 0 auto; border-radius: 0; padding: 1em;
}
}
</style>
<body>
<div class="content">
<h1>Mongoose Cookie Based Authentication</h1>
<p>Use name "Joe", password "Doe" to login.</p>
<form method="POST">
<div>
<label>Name:</label>
<input type="text" name="name"/>
</div><div>
<label>Password:</label>
<input type="password" name="password"/>
</div><div>
<input type="submit" value="Login"/>
</div>
</form>
</body>
</html>

View File

@ -1,43 +0,0 @@
// This file is part of mongoose web server project,
// https://github.com/cesanta/mongoose
using System;
public class Program {
static private int EventHandler(IntPtr conn_ptr, int ev) {
MongooseConnection conn = (MongooseConnection)
System.Runtime.InteropServices.Marshal.PtrToStructure(
conn_ptr , typeof(MongooseConnection));
if (ev == 102) {
// MG_AUTH
return 1;
} else if (ev == 103) {
// MG_REQUEST
Mongoose.send_data(conn_ptr, "Hello from C#!\n");
Mongoose.send_data(conn_ptr, "URI: " + conn.uri + "\n");
Mongoose.send_data(conn_ptr, "HTTP Headers:\n");
for (int i = 0; i < conn.num_headers; i++) {
IntPtr name = conn.http_headers[i].name;
IntPtr val = conn.http_headers[i].value;
System.Runtime.InteropServices.Marshal.PtrToStringAnsi(name);
Mongoose.send_data(conn_ptr, " " +
System.Runtime.InteropServices.Marshal.PtrToStringAnsi(name) + ": " +
System.Runtime.InteropServices.Marshal.PtrToStringAnsi(val) + "\n");
}
return 1;
}
return 0;
}
static void Main() {
Mongoose web_server = new Mongoose(".", "9001",
new MongooseEventHandler(EventHandler));
Console.WriteLine("Mongoose started, press Ctrl-C to exit.");
for (;;) {
web_server.poll(1000);
}
}
}

View File

@ -1,68 +0,0 @@
// This file is part of mongoose web server project,
// https://github.com/cesanta/mongoose
using System;
using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Sequential)] public struct MongooseHeader {
[MarshalAs(UnmanagedType.LPTStr)] public IntPtr name;
[MarshalAs(UnmanagedType.LPTStr)] public IntPtr value;
};
// mongoose.h :: struct mg_connection
[StructLayout(LayoutKind.Sequential)] public struct MongooseConnection {
[MarshalAs(UnmanagedType.LPTStr)] public string request_method;
[MarshalAs(UnmanagedType.LPTStr)] public string uri;
[MarshalAs(UnmanagedType.LPTStr)] public string http_version;
[MarshalAs(UnmanagedType.LPTStr)] public string query_string;
[MarshalAs(UnmanagedType.ByValArray,SizeConst=48)] public char[] remote_ip;
[MarshalAs(UnmanagedType.LPTStr)] public string local_ip;
[MarshalAs(UnmanagedType.U2)] public short remote_port;
[MarshalAs(UnmanagedType.U2)] public short local_port;
[MarshalAs(UnmanagedType.SysInt)] public int num_headers;
[MarshalAs(UnmanagedType.ByValArray,SizeConst=30)]
public MongooseHeader[] http_headers;
[MarshalAs(UnmanagedType.LPTStr)] public IntPtr content;
[MarshalAs(UnmanagedType.SysInt)] public int content_len;
[MarshalAs(UnmanagedType.SysInt)] public int is_websocket;
[MarshalAs(UnmanagedType.SysInt)] public int status_code;
[MarshalAs(UnmanagedType.SysInt)] public int wsbits;
};
public delegate int MongooseEventHandler(IntPtr c, int ev);
public class Mongoose {
public const string dll_ = "mongoose";
private IntPtr server_;
[DllImport(dll_)] private static extern IntPtr
mg_create_server(IntPtr user_data, MongooseEventHandler eh);
[DllImport(dll_)] private static extern int
mg_poll_server(IntPtr server, int milli);
[DllImport(dll_)] private static extern IntPtr
mg_set_option(IntPtr server, string name, string value);
[DllImport(dll_)] public static extern int
mg_send_data(IntPtr conn, string data, int length);
public Mongoose(string document_root,
string listening_port,
MongooseEventHandler event_handler) {
server_ = mg_create_server(IntPtr.Zero, event_handler);
mg_set_option(server_, "document_root", document_root);
mg_set_option(server_, "listening_port", listening_port);
}
public static int send_data(IntPtr conn, string data) {
return mg_send_data(conn, data, data.Length);
}
public void poll(int milli) {
mg_poll_server(server_, milli);
}
// TODO: add destructor and call mg_destroy_server()
}

View File

@ -1,12 +0,0 @@
# Copyright (c) 2014 Cesanta Software
# All rights reserved
PROG = digest_auth
CFLAGS = -W -Wall -I../.. -pthread -g -O0 $(CFLAGS_EXTRA)
SOURCES = $(PROG).c ../../mongoose.c
$(PROG): $(SOURCES)
$(CC) -o $(PROG) $(SOURCES) $(CFLAGS)
clean:
rm -rf $(PROG) *.exe *.dSYM *.obj *.exp .*o *.lib

View File

@ -1,36 +0,0 @@
#include <stdio.h>
#include <string.h>
#include "mongoose.h"
static int ev_handler(struct mg_connection *conn, enum mg_event ev) {
if (ev == MG_AUTH) {
int result = MG_FALSE; // Not authorized
FILE *fp;
// To populate passwords file, do
// mongoose -A my_passwords.txt mydomain.com admin admin
if ((fp = fopen("my_passwords.txt", "r")) != NULL) {
result = mg_authorize_digest(conn, fp);
fclose(fp);
}
return result;
}
return MG_FALSE;
}
int main(void) {
struct mg_server *server = mg_create_server(NULL, ev_handler);
mg_set_option(server, "listening_port", "8080");
mg_set_option(server, "document_root", ".");
printf("Starting on port %s\n", mg_get_option(server, "listening_port"));
for (;;) {
mg_poll_server(server, 1000);
}
mg_destroy_server(&server);
return 0;
}

View File

@ -1,20 +0,0 @@
# Copyright (c) 2014 Cesanta Software
# All rights reserved
PROG = file_upload
CFLAGS = -W -Wall -I../.. -pthread -g -O0 $(CFLAGS_EXTRA)
SOURCES = $(PROG).c ../../mongoose.c
all: $(PROG)
run: $(PROG)
./$(PROG)
$(PROG): $(SOURCES) Makefile
$(CC) -o $(PROG) $(SOURCES) $(CFLAGS)
win:
wine cl $(SOURCES) /MD /nologo /DNDEBUG /O1 /I../.. /Fe$(PROG).exe
clean:
rm -rf $(PROG) *.exe *.dSYM *.obj *.exp .*o *.lib *.gc*

View File

@ -1,61 +0,0 @@
// Copyright (c) 2004-2012 Sergey Lyubka
// This file is a part of mongoose project, http://github.com/valenok/mongoose
#include <stdio.h>
#include <string.h>
#include "mongoose.h"
static int send_index_page(struct mg_connection *conn) {
const char *data;
int data_len, n1, n2;
char var_name[100], file_name[100];
mg_printf_data(conn, "%s",
"<html><body>Upload example."
"<form method=\"POST\" action=\"/handle_post_request\" "
" enctype=\"multipart/form-data\">"
"<input type=\"file\" name=\"file1\" /> <br/>"
"<input type=\"file\" name=\"file2\" /> <br/>"
"<input type=\"submit\" value=\"Upload\" />"
"</form>");
n1 = n2 = 0;
while ((n2 = mg_parse_multipart(conn->content + n1, conn->content_len - n1,
var_name, sizeof(var_name), file_name,
sizeof(file_name), &data, &data_len)) > 0) {
mg_printf_data(conn, "var: %s, file_name: %s, size: %d bytes<br>",
var_name, file_name, data_len);
n1 += n2;
}
mg_printf_data(conn, "%s", "</body></html>");
return MG_TRUE;
}
static int ev_handler(struct mg_connection *conn, enum mg_event ev) {
switch (ev) {
case MG_AUTH: return MG_TRUE;
case MG_REQUEST: return send_index_page(conn);
default: return MG_FALSE;
}
}
int main(void) {
struct mg_server *server;
// Create and configure the server
server = mg_create_server(NULL, ev_handler);
mg_set_option(server, "listening_port", "8080");
// Serve request. Hit Ctrl-C to terminate the program
printf("Starting on port %s\n", mg_get_option(server, "listening_port"));
for (;;) {
mg_poll_server(server, 1000);
}
// Cleanup, and free server instance
mg_destroy_server(&server);
return 0;
}

View File

@ -1,12 +0,0 @@
# Copyright (c) 2014 Cesanta Software
# All rights reserved
PROG = form_submit
CFLAGS = -W -Wall -I../.. -pthread -g -O0 $(CFLAGS_EXTRA)
SOURCES = $(PROG).c ../../mongoose.c
$(PROG): $(SOURCES)
$(CC) -o $(PROG) $(SOURCES) $(CFLAGS)
clean:
rm -rf $(PROG) *.exe *.dSYM *.obj *.exp .*o *.lib

View File

@ -1,62 +0,0 @@
#include <stdio.h>
#include <string.h>
#include "mongoose.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 void send_reply(struct mg_connection *conn) {
char var1[500], var2[500];
if (strcmp(conn->uri, "/handle_post_request") == 0) {
// User has submitted a form, show submitted data and a variable value
// Parse form data. var1 and var2 are guaranteed to be NUL-terminated
mg_get_var(conn, "input_1", var1, sizeof(var1));
mg_get_var(conn, "input_2", var2, sizeof(var2));
// Send reply to the client, showing submitted form values.
// POST data is in conn->content, data length is in conn->content_len
mg_send_header(conn, "Content-Type", "text/plain");
mg_printf_data(conn,
"Submitted data: [%.*s]\n"
"Submitted data length: %d bytes\n"
"input_1: [%s]\n"
"input_2: [%s]\n",
conn->content_len, conn->content,
conn->content_len, var1, var2);
} else {
// Show HTML form.
mg_send_data(conn, html_form, strlen(html_form));
}
}
static int ev_handler(struct mg_connection *conn, enum mg_event ev) {
if (ev == MG_REQUEST) {
send_reply(conn);
return MG_TRUE;
} else if (ev == MG_AUTH) {
return MG_TRUE;
} else {
return MG_FALSE;
}
}
int main(void) {
struct mg_server *server = mg_create_server(NULL, ev_handler);
mg_set_option(server, "listening_port", "8080");
printf("Starting on port %s\n", mg_get_option(server, "listening_port"));
for (;;) {
mg_poll_server(server, 1000);
}
mg_destroy_server(&server);
return 0;
}

View File

@ -1,21 +0,0 @@
# Copyright (c) 2014 Cesanta Software
# All rights reserved
PROG = hello_world
CFLAGS = -W -Wall -I../.. -pthread -g -O0 $(CFLAGS_EXTRA)
SOURCES = $(PROG).c ../../mongoose.c
all: $(PROG)
run: $(PROG)
./$(PROG)
$(PROG): $(SOURCES) Makefile
$(CC) -o $(PROG) $(SOURCES) $(CFLAGS)
win:
wine cl $(SOURCES) /MD /nologo /DNDEBUG /O1 /I../.. /Fe$(PROG).exe
wine $(PROG).exe
clean:
rm -rf $(PROG) *.exe *.dSYM *.obj *.exp .*o *.lib *.gc*

View File

@ -1,38 +0,0 @@
// Copyright (c) 2014 Cesanta Software
// All rights reserved
//
// This example demostrates basic use of Mongoose embedded web server.
// $Date: 2014-09-09 22:20:23 UTC $
#include <stdio.h>
#include <string.h>
#include "mongoose.h"
static int ev_handler(struct mg_connection *conn, enum mg_event ev) {
switch (ev) {
case MG_AUTH: return MG_TRUE;
case MG_REQUEST:
mg_printf_data(conn, "Hello! Requested URI is [%s]", conn->uri);
return MG_TRUE;
default: return MG_FALSE;
}
}
int main(void) {
struct mg_server *server;
// Create and configure the server
server = mg_create_server(NULL, ev_handler);
mg_set_option(server, "listening_port", "8080");
// Serve request. Hit Ctrl-C to terminate the program
printf("Starting on port %s\n", mg_get_option(server, "listening_port"));
for (;;) {
mg_poll_server(server, 1000);
}
// Cleanup, and free server instance
mg_destroy_server(&server);
return 0;
}

View File

@ -1,12 +0,0 @@
# Copyright (c) 2014 Cesanta Software
# All rights reserved
PROG = http_client
CFLAGS = -W -Wall -I../.. -pthread -g -O0 $(CFLAGS_EXTRA)
SOURCES = $(PROG).c ../../mongoose.c
unix: $(SOURCES)
$(CC) -o $(PROG) $(SOURCES) $(CFLAGS)
clean:
rm -rf $(PROG) *.exe *.dSYM *.obj *.exp *.o *.lib

View File

@ -1,82 +0,0 @@
// Copyright (c) 2014 Cesanta Software
// All rights reserved
//
// This example demostrates how to connect to the remote Web server,
// download data, process it and send back a reply.
#include <signal.h>
#include <stdlib.h>
#include "mongoose.h"
static int s_received_signal = 0;
static struct mg_server *s_server = NULL;
static const char *s_remote_addr = "glosbe.com:80";
static void signal_handler(int sig_num) {
signal(sig_num, signal_handler);
s_received_signal = sig_num;
}
static int ev_handler(struct mg_connection *conn, enum mg_event ev) {
struct mg_connection *client, *orig;
switch (ev) {
case MG_AUTH:
return MG_TRUE;
case MG_CONNECT:
// Send request to the remote host.
// TODO(lsm): handle connect error here.
mg_printf(conn, "GET %s HTTP/1.0\r\nHost: %s\r\n\r\n",
"/gapi/translate?from=eng&dest=fra&format=json&phrase=cat",
s_remote_addr);
return MG_TRUE;
case MG_REPLY:
// Send reply to the original connection
orig = (struct mg_connection *) conn->connection_param;
mg_send_status(orig, conn->status_code);
mg_send_header(orig, "Content-Type", "text/plain");
mg_send_data(orig, conn->content, conn->content_len);
mg_send_data(orig, "", 0); // Last chunk: mark the end of reply
// Disconnect connections
orig->connection_param = NULL;
conn->connection_param = NULL;
return MG_TRUE;
case MG_REQUEST:
if ((client = mg_connect(s_server, s_remote_addr)) != NULL) {
// Interconnect requests
client->connection_param = conn;
conn->connection_param = client;
return MG_MORE;
} else {
mg_printf_data(conn, "%s", "cannot send API request");
return MG_TRUE;
}
default:
return MG_FALSE;
}
}
int main(void) {
s_server = mg_create_server(NULL, ev_handler);
mg_set_option(s_server, "listening_port", "8080");
// Setup signal handlers
signal(SIGTERM, signal_handler);
signal(SIGINT, signal_handler);
printf("Listening on port %s\n", mg_get_option(s_server, "listening_port"));
while (s_received_signal == 0) {
mg_poll_server(s_server, 1000);
}
mg_destroy_server(&s_server);
printf("Existing on signal %d\n", s_received_signal);
return EXIT_SUCCESS;
}

View File

@ -1,12 +0,0 @@
# Copyright (c) 2014 Cesanta Software
# All rights reserved
PROG = mjpg_streamer
CFLAGS = -W -Wall -I../.. -pthread -g -O0 $(CFLAGS_EXTRA)
SOURCES = $(PROG).c ../../mongoose.c
$(PROG): $(SOURCES)
$(CC) -o $(PROG) $(SOURCES) $(CFLAGS)
clean:
rm -rf $(PROG) *.exe *.dSYM *.obj *.exp .*o *.lib

View File

@ -1,105 +0,0 @@
#include <sys/stat.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include "mongoose.h"
static void send_file(struct mg_connection *conn, const char *path) {
char buf[1024];
struct stat st;
int n;
FILE *fp;
if (stat(path, &st) == 0 && (fp = fopen(path, "rb")) != NULL) {
mg_printf(conn, "--w00t\r\nContent-Type: image/jpeg\r\n"
"Content-Length: %lu\r\n\r\n", (unsigned long) st.st_size);
while ((n = fread(buf, 1, sizeof(buf), fp)) > 0) {
mg_write(conn, buf, n);
}
fclose(fp);
mg_write(conn, "\r\n", 2);
}
}
struct conn_state {
int file_index;
time_t last_poll;
};
static int ev_handler(struct mg_connection *conn, enum mg_event ev) {
const char **file_names = (const char **) conn->server_param;
struct conn_state *state;
time_t now = time(NULL);
switch (ev) {
case MG_AUTH:
return MG_TRUE;
case MG_REQUEST:
if (strcmp(conn->uri, "/stream") != 0) {
mg_send_header(conn, "Content-Type", "text/html");
mg_printf_data(conn, "%s",
"Go to <a href=/stream>/stream</a> for MJPG stream");
return MG_TRUE;
}
mg_printf(conn, "%s",
"HTTP/1.0 200 OK\r\n" "Cache-Control: no-cache\r\n"
"Pragma: no-cache\r\nExpires: Thu, 01 Dec 1994 16:00:00 GMT\r\n"
"Connection: close\r\nContent-Type: multipart/x-mixed-replace; "
"boundary=--w00t\r\n\r\n");
send_file(conn, file_names[0]);
state = (struct conn_state *) malloc(sizeof(*state));
conn->connection_param = state;
state->file_index = 1; // First file is already sent
state->last_poll = time(NULL);
return MG_MORE;
case MG_POLL:
state = (struct conn_state *) conn->connection_param;
if (state != NULL && now > state->last_poll) {
if (file_names[state->file_index] != NULL) {
send_file(conn, file_names[state->file_index]);
state->file_index++;
if (file_names[state->file_index] == NULL) {
return MG_TRUE; // No more images, close connection
}
}
state->last_poll = now;
}
return MG_FALSE;
case MG_CLOSE:
free(conn->connection_param);
conn->connection_param = NULL;
return MG_FALSE;
default:
return MG_FALSE;
}
}
int main(int argc, char *argv[]) {
struct mg_server *server;
if (argc < 3) {
printf("Usage: %s image1.jpg image2.jpg ...\n", argv[0]);
return 1;
}
server = mg_create_server(&argv[1], ev_handler);
mg_set_option(server, "listening_port", "8080");
printf("Starting on port %s\n", mg_get_option(server, "listening_port"));
for (;;) {
mg_poll_server(server, 1000);
}
mg_destroy_server(&server);
return 0;
}

View File

@ -1,12 +0,0 @@
# Copyright (c) 2014 Cesanta Software
# All rights reserved
PROG = multi_threaded_server
CFLAGS = -W -Wall -I../.. -pthread -g -O0 -DMONGOOSE_ENABLE_THREADS $(CFLAGS_EXTRA)
SOURCES = $(PROG).c ../../mongoose.c
$(PROG): $(SOURCES)
$(CC) -o $(PROG) $(SOURCES) $(CFLAGS)
clean:
rm -rf $(PROG) *.exe *.dSYM *.obj *.exp .*o *.lib

View File

@ -1,40 +0,0 @@
#include "mongoose.h"
// Start a browser and hit refresh couple of times. The replies will
// come from both server instances.
static int ev_handler(struct mg_connection *conn, enum mg_event ev) {
if (ev == MG_REQUEST) {
mg_send_header(conn, "Content-Type", "text/plain");
mg_printf_data(conn, "This is a reply from server instance # %s",
(char *) conn->server_param);
return MG_TRUE;
} else if (ev == MG_AUTH) {
return MG_TRUE;
} else {
return MG_FALSE;
}
}
static void *serve(void *server) {
for (;;) mg_poll_server((struct mg_server *) server, 1000);
return NULL;
}
int main(void) {
struct mg_server *server1, *server2;
server1 = mg_create_server((void *) "1", ev_handler);
server2 = mg_create_server((void *) "2", ev_handler);
// Make both server1 and server2 listen on the same sockets
mg_set_option(server1, "listening_port", "8080");
mg_copy_listeners(server1, server2);
// server1 goes to separate thread, server 2 runs in main thread.
// IMPORTANT: NEVER LET DIFFERENT THREADS HANDLE THE SAME SERVER.
mg_start_thread(serve, server1);
mg_start_thread(serve, server2);
getchar();
return 0;
}

View File

@ -1,13 +0,0 @@
# Copyright (c) 2014 Cesanta Software
# All rights reserved
PROG = proxy_server
FLAGS = -I../.. -DNS_ENABLE_SSL
CFLAGS = -W -Wall -g -O0 -pthread -lssl -DMONGOOSE_ENABLE_THREADS $(FLAGS) $(CFLAGS_EXTRA)
SOURCES = $(PROG).c ../../mongoose.c
unix: $(SOURCES)
$(CC) -o $(PROG) $(SOURCES) $(CFLAGS)
clean:
rm -rf $(PROG) *.exe *.dSYM *.obj *.exp .*o *.lib

View File

@ -1,202 +0,0 @@
// Copyright (c) 2014 Cesanta Software Limited
// All rights reserved
//
// To build and run this example:
// git clone https://github.com/cesanta/net_skeleton.git
// git clone https://github.com/cesanta/mongoose.git
// cd mongoose/examples
// make proxy
// ./proxy
//
// Configure your browser to use localhost:2014 as a proxy for all protocols
// Then, navigate to https://cesanta.com
#include <sys/stat.h>
#include <signal.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#ifdef _WIN32
#define sleep(x) Sleep((x) * 1000)
#else
#include <unistd.h>
#endif
#include "mongoose.h"
static int s_received_signal = 0;
static struct mg_server *s_server = NULL;
#define SSE_CONNECTION ((void *) 1)
static void elog(int do_exit, const char *fmt, ...) {
va_list ap;
va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
va_end(ap);
fputc('\n', stderr);
if (do_exit) exit(EXIT_FAILURE);
}
static void signal_handler(int sig_num) {
signal(sig_num, signal_handler);
s_received_signal = sig_num;
}
static int sse_push(struct mg_connection *conn, enum mg_event ev) {
if (ev == MG_POLL && conn->connection_param == SSE_CONNECTION) {
mg_printf(conn, "data: %s\r\n\r\n", (const char *) conn->callback_param);
}
return MG_TRUE;
}
static void *sse_pusher_thread_func(void *param) {
while (s_received_signal == 0) {
mg_wakeup_server_ex(s_server, sse_push, "%lu %s",
(unsigned long) time(NULL), (const char *) param);
sleep(1);
}
return NULL;
}
// Return: 1 if regular file, 2 if directory, 0 if not found
static int exists(const char *path) {
struct stat st;
return stat(path, &st) != 0 ? 0 : S_ISDIR(st.st_mode) == 0 ? 1 : 2;
}
// Return: 1 if regular file, 2 if directory, 0 if not found
static int is_local_file(const char *uri, char *path, size_t path_len) {
snprintf(path, path_len, "%s/%s",
mg_get_option(s_server, "document_root"), uri);
return exists(path);
}
static int try_to_serve_locally(struct mg_connection *conn) {
char path[500], buf[2000];
int n, res;
FILE *fp = NULL;
if ((res = is_local_file(conn->uri, path, sizeof(path))) == 2) {
strncat(path, "/index.html", sizeof(path) - strlen(path) - 1);
res = exists(path);
printf("PATH: [%s]\n", path);
}
if (res == 0) return MG_FALSE;
if ((fp = fopen(path, "rb")) != NULL) {
printf("Serving [%s] locally \n", path);
mg_send_header(conn, "Connection", "close");
mg_send_header(conn, "Content-Type", mg_get_mime_type(path, "text/plain"));
while ((n = fread(buf, 1, sizeof(buf), fp)) > 0) {
mg_send_data(conn, buf, n);
}
mg_send_data(conn, "", 0);
fclose(fp);
}
return fp == NULL ? MG_FALSE : MG_TRUE;
}
static int is_resource_present_locally(const char *uri) {
char path[500];
return is_local_file(uri, path, sizeof(path)) || strcmp(uri, "/api/sse") == 0;
}
static int proxy_event_handler(struct mg_connection *conn, enum mg_event ev) {
static const char target_url[] = "http://cesanta.com";
static int target_url_size = sizeof(target_url) - 1;
const char *host;
switch (ev) {
case MG_REQUEST:
host = mg_get_header(conn, "Host");
printf("[%s] [%s] [%s]\n", conn->request_method, conn->uri,
host == NULL ? "" : host);
if (strstr(conn->uri, "/qqq") != NULL) s_received_signal = SIGTERM;
// Proxied HTTPS requests use "CONNECT foo.com:443"
// Proxied HTTP requests use "GET http://..... "
// Serve requests for target_url from the local FS.
if (memcmp(conn->uri, target_url, target_url_size) == 0 &&
is_resource_present_locally(conn->uri + target_url_size)) {
conn->uri += target_url_size; // Leave only path in the URI
}
if (strcmp(conn->uri, "/api/sse") == 0) {
conn->connection_param = SSE_CONNECTION;
mg_printf(conn, "%s", "HTTP/1.0 200 OK\r\n"
"Content-Type: text/event-stream\r\n"
"Cache-Control: no-cache\r\n\r\n");
return MG_MORE;
}
if (host != NULL && strstr(host, "cesanta") != NULL) {
return try_to_serve_locally(conn);
}
// Enable man-in-the-middle SSL mode for oracle.com
if (!strcmp(conn->request_method, "CONNECT") &&
!strcmp(host, "oracle.com")) {
mg_terminate_ssl(conn, "ssl_cert.pem"); // MUST return MG_MORE after
return MG_MORE;
}
return MG_FALSE;
case MG_AUTH:
return MG_TRUE;
default:
return MG_FALSE;
}
}
static void setopt(struct mg_server *s, const char *opt, const char *val) {
const char *err_msg = mg_set_option(s, opt, val);
if (err_msg != NULL) {
elog(1, "Error setting [%s]: [%s]", opt, err_msg);
}
}
int main(int argc, char *argv[]) {
const char *port = "2014", *dump = NULL, *root = "proxy_web_root";
int i;
// Parse command line options
for (i = 1; i < argc; i++) {
if (strcmp(argv[i], "-port") == 0 && i + 1 < argc) {
port = argv[++i];
} else if (strcmp(argv[i], "-root") == 0 && i + 1 < argc) {
root = argv[++i];
} else if (strcmp(argv[i], "-dump") == 0 && i + 1 < argc) {
dump = argv[++i];
} else {
elog(1, "Usage: %s [-cert FILE] [-ca_cert FILE] [-port PORT]", argv[0]);
}
}
signal(SIGTERM, signal_handler);
signal(SIGINT, signal_handler);
// Create and configure proxy server
s_server = mg_create_server(NULL, &proxy_event_handler);
setopt(s_server, "enable_proxy", "yes");
setopt(s_server, "document_root", root);
setopt(s_server, "listening_port", port);
setopt(s_server, "hexdump_file", dump);
// Start two SSE pushing threads
mg_start_thread(sse_pusher_thread_func, (void *) "sse_pusher_thread_1");
mg_start_thread(sse_pusher_thread_func, (void *) "sse_pusher_thread_2");
// Start serving in the main thread
printf("Starting on port %s\n", mg_get_option(s_server, "listening_port"));
while (s_received_signal == 0) {
mg_poll_server(s_server, 1000);
}
printf("Existing on signal %d\n", s_received_signal);
mg_destroy_server(&s_server);
return EXIT_SUCCESS;
}

View File

@ -1,23 +0,0 @@
<html>
<head>
<title>App1 Index</title>
<style>
img { height: 40px; }
</style>
</head>
<body>
<h1>App1 index page. Served locally from the the proxy server filesystem</h1>
<p>image that references non-existent local resource. Forwarded to
the 'real' proxy target:</p>
<img src="http://cesanta.com/images/logo.png" />
<p>Google logo via HTTPS (external resource, served by remote host):</p>
<img src="https://www.google.ie/images/srpr/logo11w.png" />
<p>Same image via HTTP:</p>
<img src="http://www.google.ie/images/srpr/logo11w.png" />
</body>
</html>

View File

@ -1,37 +0,0 @@
<html>
<head>
<title>App2 Index</title>
<meta charset="utf-8">
<script>
window.onload = function() {
// Using secure websocket connection, wss://
var ws = new WebSocket('wss://echo.websocket.org');
var div = document.getElementById('events');
ws.onmessage = function(ev) {
var el = document.createElement('div');
el.innerHTML = 'websocket message: ' + ev.data;
div.appendChild(el);
// Keep only last 5 messages in the list
while (div.childNodes.length > 5) div.removeChild(div.firstChild);
};
// Send random stuff to the websocket connection periodically.
// websocket server much echo that stuff back.
window.setInterval(function() {
var d = new Date();
ws.send(d.toString());
}, 1000);
};
</script>
</head>
<body>
<h1>App2 index page. Served locally from the
the proxy's filesystem.</h1>
<p>
Following div shows proxy forwarding of websocket connection, served by
ws://echo.websocket.org:
</p>
<div id="events"></div>
</body>
</html>

View File

@ -1,29 +0,0 @@
<html>
<head>
<title> proxy index </title>
<script type="text/javascript">
window.onload = function() {
var es = new EventSource("/api/sse");
var div = document.getElementById('events');
es.onmessage = function(ev) {
var el = document.createElement('div');
el.innerHTML = 'sse message: ' + ev.data;
div.appendChild(el);
// Keep only last 5 messages in the list
while (div.childNodes.length > 5) div.removeChild(div.firstChild);
};
};
</script>
</head>
<body>
<h1> proxy index page.</h1>
<ul>
<li><a href="app1">App1</a> - App1 root</li>
<li><a href="app2">App2</a> - App2 root</li>
</ul>
<h2>SSE pushes, done by separate threads at random times:</h2>
<div id="events"></div>
</body>
</html>

View File

@ -1,50 +0,0 @@
-----BEGIN RSA PRIVATE KEY-----
MIIEogIBAAKCAQEAwONaLOP7EdegqjRuQKSDXzvHmFMZfBufjhELhNjo5KsL4ieH
hMSGCcSV6y32hzhqR5lvTViaQez+xhc58NZRu+OUgEhodRBW/vAOjpz/xdMz5HaC
EhP3E9W1pkitVseS8B5rrgJo1BfCGai1fPav1nutPq2Kj7vM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AOCAQEAW4yZdqpB
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-----

View File

@ -1,12 +0,0 @@
# Copyright (c) 2014 Cesanta Software
# All rights reserved
PROG = restful_api
CFLAGS = -W -Wall -I../.. -pthread -g -O0 $(CFLAGS_EXTRA)
SOURCES = $(PROG).c ../../mongoose.c
$(PROG): $(SOURCES)
$(CC) -o $(PROG) $(SOURCES) $(CFLAGS)
clean:
rm -rf $(PROG) *.exe *.dSYM *.obj *.exp .*o *.lib

View File

@ -1,66 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>RESTful API demo</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style type="text/css">
* { outline: none; font: 16px/1.4 Helvetica, Arial, sans-serif; }
body {
background-color: #cde; margin: 0;
padding: 0; font: 16px/1.4 Helvetica, Arial, sans-serif;
}
div.content {
width: 800px; margin: 2em auto; padding: 20px 50px;
background-color: #fff; border-radius: 1em;
}
label { display: inline-block; min-width: 7em; }
input { border: 1px solid #ccc; padding: 0.2em; }
a:link, a:visited { color: #69c; text-decoration: none; }
@media (max-width: 700px) {
body { background-color: #fff; }
div.content { width: auto; margin: 0 auto; padding: 1em; }
}
</style>
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script language="javascript" type="text/javascript">
jQuery(function() {
$(document).on('keyup', '#n1, #n2', function() {
$.ajax({
url: '/api/sum',
method: 'POST',
dataType: 'json',
data: { n1: $('#n1').val(), n2: $('#n2').val() },
success: function(json) {
$('#result').html(json.result);
}
});
});
});
</script>
</head>
<body>
<div class="content">
<h1>RESTful API demo.</h1>
<p>
This page demonstrates how Mongoose web server could be used to implement
RESTful APIs. Enter numbers below, and press Submit. Browser will send
two numbers to <tt>/api/sum</tt> URI, Mongoose calclulates the sum of
two and returns the result.
</p>
<div>
<label>Number 1:</label> <input type="text" id="n1" />
</div><div>
<label>Number 2:</label> <input type="text" id="n2" />
</div><div>
<label>Result:</label> <span id="result">&nbsp;</span>
</div><div>
</div>
</body>
</html>

View File

@ -1,51 +0,0 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "mongoose.h"
static const char *s_no_cache_header =
"Cache-Control: max-age=0, post-check=0, "
"pre-check=0, no-store, no-cache, must-revalidate\r\n";
static void handle_restful_call(struct mg_connection *conn) {
char n1[100], n2[100];
// Get form variables
mg_get_var(conn, "n1", n1, sizeof(n1));
mg_get_var(conn, "n2", n2, sizeof(n2));
mg_printf_data(conn, "{ \"result\": %lf }", strtod(n1, NULL) + strtod(n2, NULL));
}
static int ev_handler(struct mg_connection *conn, enum mg_event ev) {
switch (ev) {
case MG_AUTH: return MG_TRUE;
case MG_REQUEST:
if (!strcmp(conn->uri, "/api/sum")) {
handle_restful_call(conn);
return MG_TRUE;
}
mg_send_file(conn, "index.html", s_no_cache_header);
return MG_MORE;
default: return MG_FALSE;
}
}
int main(void) {
struct mg_server *server;
// Create and configure the server
server = mg_create_server(NULL, ev_handler);
mg_set_option(server, "listening_port", "8000");
// Serve request. Hit Ctrl-C to terminate the program
printf("Starting on port %s\n", mg_get_option(server, "listening_port"));
for (;;) {
mg_poll_server(server, 1000);
}
// Cleanup, and free server instance
mg_destroy_server(&server);
return 0;
}

View File

@ -1,21 +0,0 @@
# Copyright (c) 2014 Cesanta Software
# All rights reserved
PROG = send_file
CFLAGS = -W -Wall -I../.. -pthread -g -O0 $(CFLAGS_EXTRA)
SOURCES = $(PROG).c ../../mongoose.c
all: $(PROG)
run: $(PROG)
./$(PROG)
$(PROG): $(SOURCES) Makefile
$(CC) -o $(PROG) $(SOURCES) $(CFLAGS)
win:
wine cl $(SOURCES) /MD /nologo /DNDEBUG /O1 /I../.. /Fe$(PROG).exe
wine $(PROG).exe
clean:
rm -rf $(PROG) *.exe *.dSYM *.obj *.exp .*o *.lib *.gc*

View File

@ -1,27 +0,0 @@
// Copyright (c) 2014 Cesanta Software
// All rights reserved
//
// This example demostrates how to send arbitrary files to the client.
#include "mongoose.h"
static int ev_handler(struct mg_connection *conn, enum mg_event ev) {
switch (ev) {
case MG_REQUEST:
mg_send_file(conn, "send_file.c", NULL); // Also could be a dir, or CGI
return MG_MORE; // It is important to return MG_MORE after mg_send_file!
case MG_AUTH: return MG_TRUE;
default: return MG_FALSE;
}
}
int main(void) {
struct mg_server *server = mg_create_server(NULL, ev_handler);
mg_set_option(server, "listening_port", "8080");
printf("Starting on port %s\n", mg_get_option(server, "listening_port"));
for (;;) mg_poll_server(server, 1000);
mg_destroy_server(&server);
return 0;
}

View File

@ -1,30 +0,0 @@
# Copyright (c) 2014 Cesanta Software
# All rights reserved
PROG = web_server
CFLAGS = -W -Wall -I../.. -g -O0 $(CFLAGS_EXTRA)
SOURCES = $(PROG).c ../../mongoose.c
OPENSSL_FLAGS = -DNS_ENABLE_SSL -lssl
# PolarSSL paths and flags
POLARSSL_PATH = /usr/local
POLARSSLCOMPAT_PATH = ./../../../polar
SOURCES_POLAR = $(SOURCES) $(POLARSSLCOMPAT_PATH)/polarssl_compat.c
INCDIR_POLAR = -I$(POLARSSLCOMPAT_PATH) -I$(POLARSSL_PATH)/include
LDFLAGS_POLAR = -L$(POLARSSL_PATH)/lib -lmbedtls
CFLAGS_POLAR = $(CFLAGS) $(INCDIR_POLAR) -DNS_ENABLE_SSL
$(PROG): $(SOURCES)
$(CC) -o $(PROG) $(SOURCES) $(CFLAGS)
$(PROG).exe: $(SOURCES)
cl -Fo $(PROG) $(SOURCES) -nologo -MD -I../..
openssl:
$(CC) -o $(PROG) $(SOURCES) $(CFLAGS) $(OPENSSL_FLAGS)
polarssl:
$(CC) -o $(PROG) $(SOURCES_POLAR) $(LDFLAGS_POLAR) $(CFLAGS_POLAR)
clean:
rm -rf $(PROG) *.exe *.dSYM *.obj *.exp .*o *.lib

View File

@ -1,46 +0,0 @@
-----BEGIN CERTIFICATE-----
MIIC+zCCAeOgAwIBAgIJAPhB8jbL+G82MA0GCSqGSIb3DQEBCwUAMBQxEjAQBgNV
BAMMCTEyNy4wLjAuMTAeFw0xNTAzMDYxMjQzMzNaFw0yNTAzMDMxMjQzMzNaMBQx
EjAQBgNVBAMMCTEyNy4wLjAuMTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC
ggEBALi3b3daMgzUEROKob1Caf68i+//cTRkPdBJv2cOBak21CdQzY0Nvx73GLzf
5TKB347BCHNbYRKGJXDbYdmFp20/WeBHkY7RS3Ad2Q5lzyx66u9PxNx7hJIiqBgF
58VU+E3o/I+o8QNIoOT+wtCiq3Nwkp+zGBJmS32rzMEV9bcKxSzMrkfRhF+XAREd
DwM9vfPg6WRb/b+vv06uvVwcw390RprLautGfBdaRddVYkIAKJGRRTqZAvTRFW1J
FcIVOxlN+iA7qP7xjr3tUP78qMmlu0MXsHrUR2cgfveZK2sdUW5G804yHsU5sC8l
FbtLKMEOyLsk2bEIScOXgum7g2sCAwEAAaNQME4wHQYDVR0OBBYEFHtLzUqAsXkH
Il8S5sMhJuVhRJLdMB8GA1UdIwQYMBaAFHtLzUqAsXkHIl8S5sMhJuVhRJLdMAwG
A1UdEwQFMAMBAf8wDQYJKoZIhvcNAQELBQADggEBAEzHc0AOr+qs0OF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BVqgQbIYjO8ldldxZ8YIyJDVF+9e/uBBwu6jBIIsEQKBgQDspEHCyyuh4LG+7BbZ
eXlsfCxPTM6K9w31ZwHAwRtAuGqrOrE+pFJG9CEsFZbAI1aOGmZZdjexuSMcOlXl
TIVJTQHoFtoGEsanYEXO4O1t02Ab/DCYSpXusXUraRBRPpsTC77Sh5mxLUNd23d9
NhnDBuwChAmC+IYexjkXeqPYFwKBgQDH08PEd+2PVo4MD8UVKUlEcgoyCr6ESiyp
HfYyhhfd5x3DbZLoKCkunDfBs/hakQk8DA2nn4tl4ZjfmzXmX0EBx+E5YTdYshW7
ZcjN5x64B5PEOAR/NZA6agNlp3XGXXXgX+gnN6pgE49eVU22nZ4G+QBKD6NcCviB
LBPUxMbvzQKBgHgZYRqonGtaqzsXfP1AjmSFnMNeWtDiU95BOf2Gw/sT3WcrsXr2
UJ+cFR3XkxvOk4YpVdp/igKT0ILqBGAMdvTdtWMB/gLpEpMt5B/7veRoS7XIRy1z
ZSawP6QZfWOOX4vKAT29/j2SmEcRNFKC245EfBFGy8EBuqfxuFX3MyJfAoGBAJ0y
tjsErVmpma1baosvI3g4zlR3p1CimWehLmCopHXorr1iocMIdP0535L+ZU258y3N
vaA0HpFTW9PsYgaMwLMJ7uAY3lVkIzx84e849i2HqHMgLkl0dbW+WFXL2xblxylv
yU2wuNNED/EB4lTawcpycAvTKYvrBXt4lVE4S9exAoGAGl6vZV3zyw4jpIw4uDfk
LTPYUrghFDDGKExyeOnC/W9pqR2veqzfBz02C3jqwhewoqgAcnNc2sg0rJmM+6Oz
Z2mmGZTHO9xR++7+W7e8AkQBbS6TB8a+7yNcM4USLP+b9sX5N+8gFhFs9tG7j/no
G44qLsJ/yve7/QsOA37uEMs=
-----END PRIVATE KEY-----

View File

@ -1,490 +0,0 @@
// Copyright (c) 2004-2013 Sergey Lyubka
// Copyright (c) 2013-2014 Cesanta Software Limited
#undef UNICODE // Use ANSI WinAPI functions
#undef _UNICODE // Use multibyte encoding on Windows
#define _MBCS // Use multibyte encoding on Windows
#define _WIN32_WINNT 0x500 // Enable MIIM_BITMAP
#define _CRT_SECURE_NO_WARNINGS // Disable deprecation warning in VS2005
#define _XOPEN_SOURCE 600 // For PATH_MAX on linux
#undef WIN32_LEAN_AND_MEAN // Let windows.h always include winsock2.h
#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <string.h>
#include <errno.h>
#include <limits.h>
#include <stddef.h>
#include <stdarg.h>
#include <ctype.h>
#include <time.h>
#include "mongoose.h"
#ifdef _WIN32
#include <windows.h>
#include <direct.h> // For chdir()
#include <winsvc.h>
#include <shlobj.h>
#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
#ifndef sleep
#define sleep(x) Sleep((x) * 1000)
#endif
#define abs_path(rel, abs, abs_size) _fullpath((abs), (rel), (abs_size))
#define SIGCHLD 0
typedef struct _stat file_stat_t;
#define stat(x, y) _stat((x), (y))
#else
typedef struct stat file_stat_t;
#include <sys/wait.h>
#include <unistd.h>
#ifdef IOS
#include <ifaddrs.h>
#endif
#define DIRSEP '/'
#define __cdecl
#define abs_path(rel, abs, abs_size) realpath((rel), (abs))
#endif // _WIN32
#define MAX_OPTIONS 100
#define MAX_CONF_FILE_LINE_SIZE (8 * 1024)
#ifndef MVER
#define MVER MONGOOSE_VERSION
#endif
static int exit_flag;
static char server_name[50]; // Set by init_server_name()
static char s_config_file[PATH_MAX]; // Set by process_command_line_arguments
static struct mg_server *server; // Set by start_mongoose()
static const char *s_default_document_root = ".";
static const char *s_default_listening_port = "8080";
static char **s_argv = { NULL };
static void set_options(char *argv[]);
#if !defined(CONFIG_FILE)
#define CONFIG_FILE "mongoose.conf"
#endif /* !CONFIG_FILE */
static void __cdecl signal_handler(int sig_num) {
// Reinstantiate signal handler
signal(sig_num, signal_handler);
#ifndef _WIN32
// Do not do the trick with ignoring SIGCHLD, cause not all OSes (e.g. QNX)
// reap zombies if SIGCHLD is ignored. On QNX, for example, waitpid()
// fails if SIGCHLD is ignored, making system() non-functional.
if (sig_num == SIGCHLD) {
do {} while (waitpid(-1, &sig_num, WNOHANG) > 0);
} else
#endif
{ exit_flag = sig_num; }
}
static void vnotify(const char *fmt, va_list ap, int must_exit) {
vfprintf(stderr, fmt, ap);
fputc('\n', stderr);
if (must_exit) {
exit(EXIT_FAILURE);
}
}
static void notify(const char *fmt, ...) {
va_list ap;
va_start(ap, fmt);
vnotify(fmt, ap, 0);
va_end(ap);
}
static void die(const char *fmt, ...) {
va_list ap;
va_start(ap, fmt);
vnotify(fmt, ap, 1);
va_end(ap);
}
static void show_usage_and_exit(void) {
const char **names;
int i;
fprintf(stderr, "Mongoose version %s (c) Sergey Lyubka, built on %s\n",
MVER, __DATE__);
fprintf(stderr, "Usage:\n");
#if !defined(MONGOOSE_NO_AUTH) && !defined(MONGOOSE_NO_FILESYSTEM)
fprintf(stderr, " mongoose -A <htpasswd_file> <realm> <user> <passwd>\n");
#endif
fprintf(stderr, " mongoose [config_file]\n");
fprintf(stderr, " mongoose [-option value ...]\n");
fprintf(stderr, "\nOPTIONS:\n");
names = mg_get_valid_option_names();
for (i = 0; names[i] != NULL; i += 2) {
fprintf(stderr, " -%s %s\n",
names[i], names[i + 1] == NULL ? "<empty>" : names[i + 1]);
}
exit(EXIT_FAILURE);
}
#define EV_HANDLER NULL
static char *sdup(const char *str) {
char *p;
if ((p = (char *) malloc(strlen(str) + 1)) != NULL) {
strcpy(p, str);
}
return p;
}
static void set_option(char **options, const char *name, const char *value) {
int i;
for (i = 0; i < MAX_OPTIONS - 3; i++) {
if (options[i] == NULL) {
options[i] = sdup(name);
options[i + 1] = sdup(value);
options[i + 2] = NULL;
break;
} else if (!strcmp(options[i], name)) {
free(options[i + 1]);
options[i + 1] = sdup(value);
break;
}
}
if (i == MAX_OPTIONS - 3) {
die("%s", "Too many options specified");
}
}
static void process_command_line_arguments(char *argv[], char **options) {
char line[MAX_CONF_FILE_LINE_SIZE], opt[sizeof(line)], val[sizeof(line)],
*p, cpath[PATH_MAX];
FILE *fp = NULL;
size_t i, cmd_line_opts_start = 1, line_no = 0;
// Should we use a config file ?
if (argv[1] != NULL && argv[1][0] != '-') {
snprintf(cpath, sizeof(cpath), "%s", argv[1]);
cmd_line_opts_start = 2;
} else if ((p = strrchr(argv[0], DIRSEP)) == NULL) {
// No command line flags specified. Look where binary lives
snprintf(cpath, sizeof(cpath), "%s", CONFIG_FILE);
} else {
snprintf(cpath, sizeof(cpath), "%.*s%c%s",
(int) (p - argv[0]), argv[0], DIRSEP, CONFIG_FILE);
}
abs_path(cpath, s_config_file, sizeof(s_config_file));
fp = fopen(s_config_file, "r");
// If config file was set in command line and open failed, die
if (cmd_line_opts_start == 2 && fp == NULL) {
die("Cannot open config file %s: %s", s_config_file, strerror(errno));
}
// Load config file settings first
if (fp != NULL) {
fprintf(stderr, "Loading config file %s\n", s_config_file);
// Loop over the lines in config file
while (fgets(line, sizeof(line), fp) != NULL) {
line_no++;
// Ignore empty lines and comments
for (i = 0; isspace(* (unsigned char *) &line[i]); ) i++;
if (line[i] == '#' || line[i] == '\0') {
continue;
}
if (sscanf(line, "%s %[^\r\n#]", opt, val) != 2) {
printf("%s: line %d is invalid, ignoring it:\n %s",
s_config_file, (int) line_no, line);
} else {
set_option(options, opt, val);
}
}
fclose(fp);
}
// 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();
}
set_option(options, &argv[i][1], argv[i + 1]);
}
}
}
static void init_server_name(void) {
const char *descr = "";
snprintf(server_name, sizeof(server_name), "Mongoose web server v.%s%s",
MVER, descr);
}
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 char *get_option(char **options, const char *option_name) {
int i;
for (i = 0; options[i] != NULL; i++)
if (!strcmp(options[i], option_name))
return options[i + 1];
return NULL;
}
static void *serving_thread_func(void *param) {
struct mg_server *srv = (struct mg_server *) param;
while (exit_flag == 0) {
mg_poll_server(srv, 1000);
}
return NULL;
}
static int path_exists(const char *path, int is_dir) {
file_stat_t st;
return path == NULL || (stat(path, &st) == 0 &&
((S_ISDIR(st.st_mode) ? 1 : 0) == is_dir));
}
static void verify_existence(char **options, const char *name, int is_dir) {
const char *path = get_option(options, name);
if (!path_exists(path, is_dir)) {
notify("Invalid path for %s: [%s]: (%s). Make sure that path is either "
"absolute, or it is relative to mongoose executable.",
name, path, strerror(errno));
}
}
static void set_absolute_path(char *options[], const char *option_name) {
char path[PATH_MAX], abs[PATH_MAX], *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 mongoose executable lives
// be the relative directory for everything.
// Extract mongoose executable directory into path.
if ((p = strrchr(s_config_file, DIRSEP)) == NULL) {
getcwd(path, sizeof(path));
} else {
snprintf(path, sizeof(path), "%.*s", (int) (p - s_config_file),
s_config_file);
}
strncat(path, "/", sizeof(path) - 1);
strncat(path, option_value, sizeof(path) - 1);
// Absolutize the path, and set the option
abs_path(path, abs, sizeof(abs));
set_option(options, option_name, abs);
}
}
#if !defined(MONGOOSE_NO_AUTH) && !defined(MONGOOSE_NO_FILESYSTEM)
int modify_passwords_file(const char *fname, const char *domain,
const char *user, const char *pass) {
int found;
char line[512], u[512], d[512], ha1[33], tmp[PATH_MAX];
FILE *fp, *fp2;
found = 0;
fp = fp2 = NULL;
// Regard empty password as no password - remove user record.
if (pass != NULL && pass[0] == '\0') {
pass = NULL;
}
(void) snprintf(tmp, sizeof(tmp), "%s.tmp", fname);
// Create the file if does not exist
if ((fp = fopen(fname, "a+")) != NULL) {
fclose(fp);
}
// Open the given file and temporary file
if ((fp = fopen(fname, "r")) == NULL) {
return 0;
} else if ((fp2 = fopen(tmp, "w+")) == NULL) {
fclose(fp);
return 0;
}
// Copy the stuff to temporary file
while (fgets(line, sizeof(line), fp) != NULL) {
if (sscanf(line, "%[^:]:%[^:]:%*s", u, d) != 2) {
continue;
}
if (!strcmp(u, user) && !strcmp(d, domain)) {
found++;
if (pass != NULL) {
mg_md5(ha1, user, ":", domain, ":", pass, NULL);
fprintf(fp2, "%s:%s:%s\n", user, domain, ha1);
}
} else {
fprintf(fp2, "%s", line);
}
}
// If new user, just add it
if (!found && pass != NULL) {
mg_md5(ha1, user, ":", domain, ":", pass, NULL);
fprintf(fp2, "%s:%s:%s\n", user, domain, ha1);
}
// Close files
fclose(fp);
fclose(fp2);
// Put the temp file in place of real file
remove(fname);
rename(tmp, fname);
return 1;
}
#endif
static void start_mongoose(int argc, char *argv[]) {
s_argv = argv;
if ((server = mg_create_server(NULL, EV_HANDLER)) == NULL) {
die("%s", "Failed to start Mongoose.");
}
#if !defined(MONGOOSE_NO_AUTH) && !defined(MONGOOSE_NO_FILESYSTEM)
// Edit passwords file if -A option is specified
if (argc > 1 && !strcmp(argv[1], "-A")) {
if (argc != 6) {
show_usage_and_exit();
}
exit(modify_passwords_file(argv[2], argv[3], argv[4], argv[5]) ?
EXIT_SUCCESS : EXIT_FAILURE);
}
#endif
// Show usage if -h or --help options are specified
if (argc == 2 && (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help"))) {
show_usage_and_exit();
}
set_options(argv);
}
static void set_options(char *argv[]) {
char *options[MAX_OPTIONS];
int i;
options[0] = NULL;
set_option(options, "document_root", s_default_document_root);
set_option(options, "listening_port", s_default_listening_port);
// Update config based on command line arguments
process_command_line_arguments(argv, options);
// Make sure we have absolute paths for files and directories
// https://github.com/valenok/mongoose/issues/181
set_absolute_path(options, "document_root");
set_absolute_path(options, "dav_auth_file");
set_absolute_path(options, "cgi_interpreter");
set_absolute_path(options, "access_log_file");
set_absolute_path(options, "global_auth_file");
set_absolute_path(options, "ssl_certificate");
if (!path_exists(get_option(options, "document_root"), 1)) {
set_option(options, "document_root", s_default_document_root);
set_absolute_path(options, "document_root");
notify("Setting document_root to [%s]",
mg_get_option(server, "document_root"));
}
// Make extra verification for certain options
verify_existence(options, "document_root", 1);
verify_existence(options, "cgi_interpreter", 0);
verify_existence(options, "ssl_certificate", 0);
for (i = 0; options[i] != NULL; i += 2) {
const char *msg = mg_set_option(server, options[i], options[i + 1]);
if (msg != NULL) {
notify("Failed to set option [%s] to [%s]: %s",
options[i], options[i + 1], msg);
if (!strcmp(options[i], "listening_port")) {
mg_set_option(server, "listening_port", s_default_listening_port);
notify("Setting %s to [%s]", options[i], s_default_listening_port);
}
}
free(options[i]);
free(options[i + 1]);
}
// Change current working directory to document root. This way,
// scripts can use relative paths.
chdir(mg_get_option(server, "document_root"));
#if 0
// Add an ability to pass listening socket to mongoose
{
const char *env = getenv("MONGOOSE_LISTENING_SOCKET");
if (env != NULL && atoi(env) > 0 ) {
mg_set_listening_socket(server, atoi(env));
}
}
#endif
// Setup signal handler: quit on Ctrl-C
signal(SIGTERM, signal_handler);
signal(SIGINT, signal_handler);
#ifndef _WIN32
signal(SIGCHLD, signal_handler);
#endif
}
int main(int argc, char *argv[]) {
init_server_name();
start_mongoose(argc, argv);
printf("%s serving [%s] on port %s\n",
server_name, mg_get_option(server, "document_root"),
mg_get_option(server, "listening_port"));
fflush(stdout); // Needed, Windows terminals might not be line-buffered
serving_thread_func(server);
printf("Exiting on signal %d ...", exit_flag);
fflush(stdout);
mg_destroy_server(&server);
printf("%s\n", " done.");
return EXIT_SUCCESS;
}

View File

@ -1,12 +0,0 @@
# Copyright (c) 2014 Cesanta Software
# All rights reserved
PROG = websocket_chat
CFLAGS = -W -Wall -I../.. -pthread -g -O0 $(CFLAGS_EXTRA)
SOURCES = $(PROG).c ../../mongoose.c
$(PROG): $(SOURCES)
$(CC) -o $(PROG) $(SOURCES) $(CFLAGS)
clean:
rm -rf $(PROG) *.exe *.dSYM *.obj *.exp .*o *.lib

View File

@ -1,98 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>WebSocket Test</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style type="text/css">
body {
background-color: #cde; margin: 0;
padding: 0; font: 14px Helvetica, Arial, sans-serif;
}
div.content {
width: 800px; margin: 2em auto; padding: 20px 50px;
background-color: #fff; border-radius: 1em;
}
#messages {
border: 2px solid #fec; border-radius: 1em;
height: 10em; overflow: scroll; padding: 0.5em 1em;
}
a:link, a:visited { color: #69c; text-decoration: none; }
@media (max-width: 700px) {
body { background-color: #fff; }
div.content {
width: auto; margin: 0 auto; border-radius: 0;
padding: 1em;
}
}
</style>
<script language="javascript" type="text/javascript">
var rooms = [];
var ws = new WebSocket('ws://' + location.host + '/ws');
if (!window.console) { window.console = { log: function() {} } };
ws.onopen = function(ev) { console.log(ev); };
ws.onerror = function(ev) { console.log(ev); };
ws.onclose = function(ev) { console.log(ev); };
ws.onmessage = function(ev) {
console.log(ev);
var m = (ev.data || '').match(/^(\S+) (.+)/);
if (m[1] == 'id') {
document.getElementById('my_id').innerText = m[2];
} else if (m[1] == 'msg') {
var div = document.createElement('div');
div.innerHTML = m[2];
document.getElementById('messages').appendChild(div);
}
};
window.onload = function() {
document.getElementById('send_button').onclick = function(ev) {
var msg = document.getElementById('send_input').value;
ws.send('msg ' + msg);
};
document.getElementById('room_sel').onchange = function(ev) {
var roomName = this.value || '?';
ws.send('join ' + roomName);
};
};
</script>
</head>
<body>
<div class="content">
<h1>Websocket PubSub Demonstration</h1>
<p>
This page demonstrates how Mongoose web server could be used to implement
<a href="http://en.wikipedia.org/wiki/Publish%E2%80%93subscribe_pattern">
publishsubscribe pattern</a>. Open this page in several browser
windows. Each window initiates persistent
<a href="http://en.wikipedia.org/wiki/WebSocket">WebSocket</a>
connection with Mongoose, making each browser window a websocket client.
Join a room, send messages, and see messages sent by other clients.
</p>
<p>
My ID: <b><span id="my_id"></b></span>
</p>
<p>
Join room: <select id="room_sel">
<option value="">-- select room -- </option>
<option>A</option>
<option>B</option>
</select>
</p>
<div id="messages">
</div>
<p>
<input type="text" id="send_input" />
<button id="send_button">Send Message</button>
</p>
</div>
</body>
</html>

View File

@ -1,83 +0,0 @@
// Copyright (c) 2013-2014 Cesanta Software Limited
// $Date: 2014-09-09 17:07:55 UTC $
#include <string.h>
#include <time.h>
#include <signal.h>
#include <stdlib.h>
#include "mongoose.h"
static int s_signal_received = 0;
static struct mg_server *s_server = NULL;
// Data associated with each websocket connection
struct conn_data {
int room;
};
static void signal_handler(int sig_num) {
signal(sig_num, signal_handler); // Reinstantiate signal handler
s_signal_received = sig_num;
}
static void handle_websocket_message(struct mg_connection *conn) {
struct conn_data *d = (struct conn_data *) conn->connection_param;
struct mg_connection *c;
printf("[%.*s]\n", (int) conn->content_len, conn->content);
if (conn->content_len > 5 && !memcmp(conn->content, "join ", 5)) {
// Client joined new room
d->room = conn->content[5];
} else if (conn->content_len > 4 && !memcmp(conn->content, "msg ", 4) &&
d->room != 0 && d->room != '?') {
// Client has sent a message. Push this message to all clients
// that are subscribed to the same room as client
for (c = mg_next(s_server, NULL); c != NULL; c = mg_next(s_server, c)) {
struct conn_data *d2 = (struct conn_data *) c->connection_param;
if (!c->is_websocket || d2->room != d->room) continue;
mg_websocket_printf(c, WEBSOCKET_OPCODE_TEXT, "msg %c %p %.*s",
(char) d->room, conn,
conn->content_len - 4, conn->content + 4);
}
}
}
static int ev_handler(struct mg_connection *conn, enum mg_event ev) {
switch (ev) {
case MG_REQUEST:
if (conn->is_websocket) {
handle_websocket_message(conn);
return MG_TRUE;
} else {
mg_send_file(conn, "index.html", NULL); // Return MG_MORE after!
return MG_MORE;
}
case MG_WS_CONNECT:
// New websocket connection. Send connection ID back to the client.
conn->connection_param = calloc(1, sizeof(struct conn_data));
mg_websocket_printf(conn, WEBSOCKET_OPCODE_TEXT, "id %p", conn);
return MG_FALSE;
case MG_CLOSE:
free(conn->connection_param);
return MG_TRUE;
case MG_AUTH:
return MG_TRUE;
default:
return MG_FALSE;
}
}
int main(void) {
s_server = mg_create_server(NULL, ev_handler);
mg_set_option(s_server, "listening_port", "8080");
signal(SIGTERM, signal_handler);
signal(SIGINT, signal_handler);
printf("Started on port %s\n", mg_get_option(s_server, "listening_port"));
while (s_signal_received == 0) {
mg_poll_server(s_server, 100);
}
mg_destroy_server(&s_server);
return 0;
}

View File

@ -1,12 +0,0 @@
# Copyright (c) 2014 Cesanta Software
# All rights reserved
PROG = websocket_echo_server
CFLAGS = -W -Wall -I../.. -pthread -g -O0 $(CFLAGS_EXTRA)
SOURCES = $(PROG).c ../../mongoose.c
$(PROG): $(SOURCES)
$(CC) -o $(PROG) $(SOURCES) $(CFLAGS)
clean:
rm -rf $(PROG) *.exe *.dSYM *.obj *.exp .*o *.lib

View File

@ -1,46 +0,0 @@
<!DOCTYPE html>
<meta charset="utf-8" />
<title>WebSocket Test</title>
<script language="javascript" type="text/javascript">
var out = function(message) {
var div = document.createElement('div');
div.innerHTML = message;
document.getElementById('output').appendChild(div);
};
window.onload = function() {
var url = 'ws://' + location.host + '/ws';
var num_messages = 0;
websocket = new WebSocket(url);
websocket.onopen = function(ev) {
out('CONNECTED');
var msg = 'Не всё подчиняется разуму. Но всё подчиняется упорству. ';
out('SENT: ' + msg);
websocket.send(msg);
};
websocket.onclose = function(ev) {
out('DISCONNECTED');
};
websocket.onmessage = function(ev) {
if (!ev.data) {
out('<span style="color: blue;">PING... </span>');
} else {
out('<span style="color: blue;">RESPONSE: ' + ev.data + ' </span>');
num_messages++;
}
if (num_messages > 3) {
websocket.send('exit');
}
};
websocket.onerror = function(ev) {
out('<span style="color: red; ">ERROR: </span> ' + ev.data);
};
};
</script>
<style> div {font: small Verdana; } </style>
<h2>Mongoose WebSocket Test</h2>
<div id="output"></div>
</html>

View File

@ -1,61 +0,0 @@
// Copyright (c) 2013-2014 Cesanta Software Limited
// $Date: 2014-09-09 17:07:55 UTC $
#include <string.h>
#include <time.h>
#include "mongoose.h"
static void push_message(struct mg_server *server, time_t current_time) {
struct mg_connection *c;
char buf[20];
int len = sprintf(buf, "%lu", (unsigned long) current_time);
// Iterate over all connections, and push current time message to websocket ones.
for (c = mg_next(server, NULL); c != NULL; c = mg_next(server, c)) {
if (c->is_websocket) {
mg_websocket_write(c, 1, buf, len);
}
}
}
static int send_reply(struct mg_connection *conn) {
if (conn->is_websocket) {
// This handler is called for each incoming websocket frame, one or more
// times for connection lifetime.
// Echo websocket data back to the client.
mg_websocket_write(conn, 1, conn->content, conn->content_len);
return conn->content_len == 4 && !memcmp(conn->content, "exit", 4) ?
MG_FALSE : MG_TRUE;
} else {
mg_send_file(conn, "index.html", NULL);
return MG_MORE;
}
}
static int ev_handler(struct mg_connection *conn, enum mg_event ev) {
switch (ev) {
case MG_AUTH: return MG_TRUE;
case MG_REQUEST: return send_reply(conn);
default: return MG_FALSE;
}
}
int main(void) {
struct mg_server *server = mg_create_server(NULL, ev_handler);
time_t current_timer = 0, last_timer = time(NULL);
mg_set_option(server, "listening_port", "8080");
printf("Started on port %s\n", mg_get_option(server, "listening_port"));
for (;;) {
mg_poll_server(server, 100);
current_timer = time(NULL);
if (current_timer - last_timer > 0) {
last_timer = current_timer;
push_message(server, current_timer);
}
}
mg_destroy_server(&server);
return 0;
}

View File

@ -1,27 +0,0 @@
# Copyright (c) 2014 Cesanta Software
# All rights reserved
PROG = ws_ssl
CFLAGS = -W -Wall -I../.. -I. -pthread -g -O0 -DMONGOOSE_ENABLE_THREADS -DNS_ENABLE_SSL -DSSL_WRAPPER_USE_AS_LIBRARY $(CFLAGS_EXTRA)
LDFLAGS = -lssl
SOURCES = ws_ssl.c ../../mongoose.c ssl_wrapper.c
# PolarSSL paths and flags
POLARSSL_PATH = /usr/local
POLARSSLCOMPAT_PATH = ./../../../polar
SOURCES_POLAR = $(SOURCES) $(POLARSSLCOMPAT_PATH)/polarssl_compat.c
INCDIR_POLAR = -I$(POLARSSLCOMPAT_PATH) -I$(POLARSSL_PATH)/include
LDFLAGS_POLAR = -L$(POLARSSL_PATH)/lib -lmbedtls
CFLAGS_POLAR = $(CFLAGS) $(INCDIR_POLAR)
#
all: $(PROG)
$(PROG): $(SOURCES)
$(CC) -o $(PROG) $(SOURCES) $(LDFLAGS) $(CFLAGS)
polarssl: $(SOURCES_POLAR)
$(CC) -o $(PROG) $(SOURCES_POLAR) $(LDFLAGS_POLAR) $(CFLAGS_POLAR)
clean:
rm -rf $(PROG) *.exe *.dSYM *.obj *.exp .*o *.lib

View File

@ -1,49 +0,0 @@
-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEAwizPnrCx+/kPSdEeSJFLDXrBH+cSQsSLrCm99G1hCjzqSlIk
1BhkZMEHxBaiVLky4+M/nwhjwwRHI10h6U2Or3tbPLv7z94cPf+uCx1aF7TE3Fm3
6YnDk+CjrYVFN5GRPGOPPdFxGoc+vFvQJyAAimvchnS1ZoEQFvermwzOnKspA6gc
Px+7wnOeju9TyJuDr5ngtDXFnkcpkBNPxz3En4MJY4xJiaueafh9pIES2vSl7uP0
J/qot9v2rdiL7nt1H1vwseeEkZhQ+NLB5e2z4psyktJcwDX7wQ6j7JnKfHeP+ixO
TUORgV4foBMVOqo//Guo92Q5HoLNK77V0y4+ZQIDAQABAoIBAGEsx+LlDs3JQQty
KjOq8uKWElyC6bKcZkIMydGvg6b6AU6ceW3jnyqFJ/vMUAUSghNmQQq3yiVo2Kks
DLKTa9sKYwisE0NeJsgoUtOhJttCTlrwU4f+t/AjtgY68f7zTLnqIV+Ql4ftM0pU
sIFEFMExZbWsZrQb1w+Hd0wrRqNEbSOfSjHeigvuw1T3GH2tSBUTGTpcoewCzy7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ZhVq
rXzVt7QV8dO0nStMjKK5omrtEAhVnASk7w1tFHkpBF1rqXGoo9ML40RnFZ+E5zqi
iZtzp+NzzLnEnWMNs+fJpPJ96P0kbq2bQzuSBcUynq0=
-----END CERTIFICATE-----

View File

@ -1,253 +0,0 @@
// Copyright (c) 2014 Cesanta Software Limited
// All rights reserved
//
// This software is dual-licensed: you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2 as
// published by the Free Software Foundation. For the terms of this
// license, see <http://www.gnu.org/licenses/>.
//
// You are free to use this software under the terms of the GNU General
// Public License, but WITHOUT ANY WARRANTY; without even the implied
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU General Public License for more details.
//
// Alternatively, you can license this software under a commercial
// license, as set out in <http://cesanta.com/>.
//
// $Date: 2014-09-28 05:04:41 UTC $
#ifndef NS_SKELETON_HEADER_INCLUDED
#define NS_SKELETON_HEADER_INCLUDED
#define NS_SKELETON_VERSION "2.1.0"
#undef UNICODE // Use ANSI WinAPI functions
#undef _UNICODE // Use multibyte encoding on Windows
#define _MBCS // Use multibyte encoding on Windows
#define _INTEGRAL_MAX_BITS 64 // Enable _stati64() on Windows
#define _CRT_SECURE_NO_WARNINGS // Disable deprecation warning in VS2005+
#undef WIN32_LEAN_AND_MEAN // Let windows.h always include winsock2.h
#define _XOPEN_SOURCE 600 // For flockfile() on Linux
#define __STDC_FORMAT_MACROS // <inttypes.h> wants this for C++
#define __STDC_LIMIT_MACROS // C++ wants that for INT64_MAX
#ifndef _LARGEFILE_SOURCE
#define _LARGEFILE_SOURCE // Enable fseeko() and ftello() functions
#endif
#define _FILE_OFFSET_BITS 64 // Enable 64-bit file offsets
#ifdef _MSC_VER
#pragma warning (disable : 4127) // FD_SET() emits warning, disable it
#pragma warning (disable : 4204) // missing c99 support
#endif
#include <sys/types.h>
#include <sys/stat.h>
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <signal.h>
#ifdef _WIN32
#ifdef _MSC_VER
#pragma comment(lib, "ws2_32.lib") // Linking with winsock library
#endif
#include <windows.h>
#include <process.h>
#ifndef EINPROGRESS
#define EINPROGRESS WSAEINPROGRESS
#endif
#ifndef EWOULDBLOCK
#define EWOULDBLOCK WSAEWOULDBLOCK
#endif
#ifndef __func__
#define STRX(x) #x
#define STR(x) STRX(x)
#define __func__ __FILE__ ":" STR(__LINE__)
#endif
#ifndef va_copy
#define va_copy(x,y) x = y
#endif // MINGW #defines va_copy
#define snprintf _snprintf
#define vsnprintf _vsnprintf
#define sleep(x) Sleep((x) * 1000)
#define to64(x) _atoi64(x)
typedef int socklen_t;
typedef unsigned char uint8_t;
typedef unsigned int uint32_t;
typedef unsigned short uint16_t;
typedef unsigned __int64 uint64_t;
typedef __int64 int64_t;
typedef SOCKET sock_t;
typedef struct _stati64 ns_stat_t;
#ifndef S_ISDIR
#define S_ISDIR(x) ((x) & _S_IFDIR)
#endif
#else
#include <errno.h>
#include <fcntl.h>
#include <netdb.h>
#include <pthread.h>
#include <stdarg.h>
#include <unistd.h>
#include <arpa/inet.h> // For inet_pton() when NS_ENABLE_IPV6 is defined
#include <netinet/in.h>
#include <sys/socket.h>
#include <sys/select.h>
#define closesocket(x) close(x)
#define __cdecl
#define INVALID_SOCKET (-1)
#define to64(x) strtoll(x, NULL, 10)
typedef int sock_t;
typedef struct stat ns_stat_t;
#endif
#ifdef NS_ENABLE_DEBUG
#define DBG(x) do { printf("%-20s ", __func__); printf x; putchar('\n'); \
fflush(stdout); } while(0)
#else
#define DBG(x)
#endif
#ifndef ARRAY_SIZE
#define ARRAY_SIZE(array) (sizeof(array) / sizeof(array[0]))
#endif
#ifdef NS_ENABLE_SSL
#ifdef __APPLE__
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
#include <openssl/ssl.h>
#else
typedef void *SSL;
typedef void *SSL_CTX;
#endif
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
union socket_address {
struct sockaddr sa;
struct sockaddr_in sin;
#ifdef NS_ENABLE_IPV6
struct sockaddr_in6 sin6;
#else
struct sockaddr sin6;
#endif
};
// Describes chunk of memory
struct ns_str {
const char *p;
size_t len;
};
// IO buffers interface
struct iobuf {
char *buf;
size_t len;
size_t size;
};
void iobuf_init(struct iobuf *, size_t initial_size);
void iobuf_free(struct iobuf *);
size_t iobuf_append(struct iobuf *, const void *data, size_t data_size);
void iobuf_remove(struct iobuf *, size_t data_size);
void iobuf_resize(struct iobuf *, size_t new_size);
// Callback function (event handler) prototype, must be defined by user.
// Net skeleton will call event handler, passing events defined above.
struct ns_connection;
typedef void (*ns_callback_t)(struct ns_connection *, int event_num, void *evp);
// Events. Meaning of event parameter (evp) is given in the comment.
#define NS_POLL 0 // Sent to each connection on each call to ns_mgr_poll()
#define NS_ACCEPT 1 // New connection accept()-ed. union socket_address *addr
#define NS_CONNECT 2 // connect() succeeded or failed. int *success_status
#define NS_RECV 3 // Data has benn received. int *num_bytes
#define NS_SEND 4 // Data has been written to a socket. int *num_bytes
#define NS_CLOSE 5 // Connection is closed. NULL
struct ns_mgr {
struct ns_connection *active_connections;
const char *hexdump_file; // Debug hexdump file path
sock_t ctl[2]; // Socketpair for mg_wakeup()
void *user_data; // User data
};
struct ns_connection {
struct ns_connection *next, *prev; // ns_mgr::active_connections linkage
struct ns_connection *listener; // Set only for accept()-ed connections
struct ns_mgr *mgr;
sock_t sock; // Socket
union socket_address sa; // Peer address
struct iobuf recv_iobuf; // Received data
struct iobuf send_iobuf; // Data scheduled for sending
SSL *ssl;
SSL_CTX *ssl_ctx;
void *user_data; // User-specific data
void *proto_data; // Application protocol-specific data
time_t last_io_time; // Timestamp of the last socket IO
ns_callback_t callback; // Event handler function
unsigned int flags;
#define NSF_FINISHED_SENDING_DATA (1 << 0)
#define NSF_BUFFER_BUT_DONT_SEND (1 << 1)
#define NSF_SSL_HANDSHAKE_DONE (1 << 2)
#define NSF_CONNECTING (1 << 3)
#define NSF_CLOSE_IMMEDIATELY (1 << 4)
#define NSF_WANT_READ (1 << 5)
#define NSF_WANT_WRITE (1 << 6)
#define NSF_LISTENING (1 << 7)
#define NSF_UDP (1 << 8)
#define NSF_USER_1 (1 << 20)
#define NSF_USER_2 (1 << 21)
#define NSF_USER_3 (1 << 22)
#define NSF_USER_4 (1 << 23)
#define NSF_USER_5 (1 << 24)
#define NSF_USER_6 (1 << 25)
};
void ns_mgr_init(struct ns_mgr *, void *user_data);
void ns_mgr_free(struct ns_mgr *);
time_t ns_mgr_poll(struct ns_mgr *, int milli);
void ns_broadcast(struct ns_mgr *, ns_callback_t, void *, size_t);
struct ns_connection *ns_next(struct ns_mgr *, struct ns_connection *);
struct ns_connection *ns_add_sock(struct ns_mgr *, sock_t,
ns_callback_t, void *);
struct ns_connection *ns_bind(struct ns_mgr *, const char *,
ns_callback_t, void *);
struct ns_connection *ns_connect(struct ns_mgr *, const char *,
ns_callback_t, void *);
int ns_send(struct ns_connection *, const void *buf, int len);
int ns_printf(struct ns_connection *, const char *fmt, ...);
int ns_vprintf(struct ns_connection *, const char *fmt, va_list ap);
// Utility functions
void *ns_start_thread(void *(*f)(void *), void *p);
int ns_socketpair(sock_t [2]);
int ns_socketpair2(sock_t [2], int sock_type); // SOCK_STREAM or SOCK_DGRAM
void ns_set_close_on_exec(sock_t);
void ns_sock_to_str(sock_t sock, char *buf, size_t len, int flags);
int ns_hexdump(const void *buf, int len, char *dst, int dst_len);
int ns_avprintf(char **buf, size_t size, const char *fmt, va_list ap);
int ns_resolve(const char *domain_name, char *ip_addr_buf, size_t buf_len);
#ifdef __cplusplus
}
#endif // __cplusplus
#endif // NS_SKELETON_HEADER_INCLUDED

View File

@ -1,123 +0,0 @@
// Copyright (c) 2014 Cesanta Software Limited
// All rights reserved
//
// This software is dual-licensed: you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2 as
// published by the Free Software Foundation. For the terms of this
// license, see <http://www.gnu.org/licenses/>.
//
// You are free to use this software under the terms of the GNU General
// Public License, but WITHOUT ANY WARRANTY; without even the implied
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU General Public License for more details.
//
// Alternatively, you can license this software under a commercial
// license, as set out in <http://cesanta.com/products.html>.
//
// $Date$
#include "net_skeleton.h"
#include "ssl_wrapper.h"
static void ev_handler(struct ns_connection *nc, int ev, void *p) {
const char *target_addr = (const char *) nc->mgr->user_data;
struct ns_connection *pc = (struct ns_connection *) nc->user_data;
struct iobuf *io = &nc->recv_iobuf;
(void) p;
switch (ev) {
case NS_ACCEPT:
// Create a connection to the target, and interlink both connections
nc->user_data = ns_connect(nc->mgr, target_addr, ev_handler, nc);
if (nc->user_data == NULL) {
nc->flags |= NSF_CLOSE_IMMEDIATELY;
}
break;
case NS_CLOSE:
// If either connection closes, unlink them and shedule closing
if (pc != NULL) {
pc->flags |= NSF_FINISHED_SENDING_DATA;
pc->user_data = NULL;
}
nc->user_data = NULL;
break;
case NS_RECV:
// Forward arrived data to the other connection, and discard from buffer
if (pc != NULL) {
ns_send(pc, io->buf, io->len);
iobuf_remove(io, io->len);
}
break;
default:
break;
}
}
void *ssl_wrapper_init(const char *local_addr, const char *target_addr,
const char **err_msg) {
struct ns_mgr *mgr = (struct ns_mgr *) calloc(1, sizeof(mgr[0]));
*err_msg = NULL;
if (mgr == NULL) {
*err_msg = "malloc failed";
} else {
ns_mgr_init(mgr, (void *) target_addr);
if (ns_bind(mgr, local_addr, ev_handler, NULL) == NULL) {
*err_msg = "ns_bind() failed: bad listening_port";
ns_mgr_free(mgr);
free(mgr);
mgr = NULL;
}
}
return mgr;
}
void ssl_wrapper_serve(void *param, volatile int *quit) {
struct ns_mgr *mgr = (struct ns_mgr *) param;
while (*quit == 0) {
ns_mgr_poll(mgr, 1000);
}
ns_mgr_free(mgr);
free(mgr);
}
#ifndef SSL_WRAPPER_USE_AS_LIBRARY
static int s_received_signal = 0;
static void signal_handler(int sig_num) {
signal(sig_num, signal_handler);
s_received_signal = sig_num;
}
static void show_usage_and_exit(const char *prog) {
fprintf(stderr, "Usage: %s <listening_address> <target_address>\n", prog);
exit(EXIT_FAILURE);
}
int main(int argc, char *argv[]) {
void *wrapper;
const char *err_msg;
if (argc != 3) {
show_usage_and_exit(argv[0]);
}
// Setup signal handlers
signal(SIGTERM, signal_handler);
signal(SIGINT, signal_handler);
signal(SIGPIPE, SIG_IGN);
if ((wrapper = ssl_wrapper_init(argv[1], argv[2], &err_msg)) == NULL) {
fprintf(stderr, "Error: %s\n", err_msg);
exit(EXIT_FAILURE);
}
ssl_wrapper_serve(wrapper, &s_received_signal);
return EXIT_SUCCESS;
}
#endif // SSL_WRAPPER_USE_AS_LIBRARY

View File

@ -1,34 +0,0 @@
// Copyright (c) 2014 Cesanta Software Limited
// All rights reserved
//
// This software is dual-licensed: you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2 as
// published by the Free Software Foundation. For the terms of this
// license, see <http://www.gnu.org/licenses/>.
//
// You are free to use this software under the terms of the GNU General
// Public License, but WITHOUT ANY WARRANTY; without even the implied
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU General Public License for more details.
//
// Alternatively, you can license this software under a commercial
// license, as set out in <http://cesanta.com/products.html>.
//
// $Date$
#ifndef SSL_WRAPPER_HEADER_INCLUDED
#define SSL_WRAPPER_HEADER_INCLUDED
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
void *ssl_wrapper_init(const char *listen_addr, const char *target_addr,
const char **err_msg);
void ssl_wrapper_serve(void *, volatile int *stop_marker);
#ifdef __cplusplus
}
#endif // __cplusplus
#endif // SSL_WRAPPER_HEADER_INCLUDED

View File

@ -1,182 +0,0 @@
// Copyright (c) 2014 Cesanta Software
// All rights reserved
//
// This example demostrates proxying of WebSocket traffic, regardless of the
// protocol (ws:// or wss://).
// To use this example:
// 1. configure your browser to use a proxy on port 2014
// 2. import certs/ws1_ca.pem and certs/ws2_ca.pem into the trusted
// certificates list on your browser
// 3. make && ./ws_ssl
// 4. Point your browser to http://ws_ssl.com
// A page with 4 sections should appear, showing websocket echoes
#include "net_skeleton.h"
#include "mongoose.h"
#include "ssl_wrapper.h"
#define S1_PEM "certs/ws1_server.pem"
#define C1_PEM "certs/ws1_client.pem"
#define CA1_PEM "certs/ws1_ca.pem"
#define S2_PEM "certs/ws2_server.pem"
#define C2_PEM "certs/ws2_client.pem"
#define CA2_PEM "certs/ws2_ca.pem"
struct config {
const char *uri;
const char *wrapper_server_addr;
const char *wrapper_client_addr;
const char *target_addr;
};
static struct config s_wrappers[] = {
{
"ws1:80",
"tcp://127.0.0.1:7001",
"tcp://127.0.0.1:7001",
"tcp://127.0.0.1:9001"
},
{
"ws1:443",
"ssl://127.0.0.1:7002:" S1_PEM,
"tcp://127.0.0.1:7002",
"tcp://127.0.0.1:9001"
},
{
"ws2:80",
"tcp://127.0.0.1:7003",
"tcp://127.0.0.1:7003",
"ssl://127.0.0.1:9002:" C2_PEM ":" CA2_PEM
},
{
"ws2:443",
"ssl://127.0.0.1:7004:" S2_PEM,
"tcp://127.0.0.1:7004",
"ssl://127.0.0.1:9002:" C2_PEM ":" CA2_PEM
},
};
static int s_received_signal = 0;
static void signal_handler(int sig_num) {
signal(sig_num, signal_handler);
s_received_signal = sig_num;
}
static int ev_handler(struct mg_connection *conn, enum mg_event ev) {
int i;
switch (ev) {
case MG_AUTH:
return MG_TRUE;
case MG_REQUEST:
printf("==> [%s] [%s]\n", conn->request_method, conn->uri);
if (strcmp(conn->request_method, "CONNECT") == 0) {
// Iterate over configured wrappers, see if we can use one of them
for (i = 0; i < (int) ARRAY_SIZE(s_wrappers); i++) {
if (strcmp(conn->uri, s_wrappers[i].uri) == 0) {
mg_forward(conn, s_wrappers[i].wrapper_client_addr);
return MG_MORE;
}
}
// No suitable wrappers found. Disallow that CONNECT request.
mg_send_status(conn, 405);
return MG_TRUE;
}
// Not a CONNECT request, serve HTML file.
mg_send_file(conn, "ws_ssl.html", NULL);
return MG_MORE;
default:
return MG_FALSE;
}
}
static int ws_handler(struct mg_connection *conn, enum mg_event ev) {
switch (ev) {
case MG_AUTH:
return MG_TRUE;
case MG_REQUEST:
if (conn->is_websocket) {
// Simple websocket echo server
mg_websocket_write(conn, WEBSOCKET_OPCODE_TEXT,
conn->content, conn->content_len);
} else {
mg_printf_data(conn, "%s", "websocket connection expected");
}
return MG_TRUE;
default:
return MG_FALSE;
}
}
static void *serve_thread_func(void *param) {
struct mg_server *server = (struct mg_server *) param;
printf("Listening on port %s\n", mg_get_option(server, "listening_port"));
while (s_received_signal == 0) {
mg_poll_server(server, 1000);
}
mg_destroy_server(&server);
return NULL;
}
static void *wrapper_thread_func(void *param) {
struct config *c = (struct config *) param;
const char *err_msg;
void *wrapper;
wrapper = ssl_wrapper_init(c->wrapper_server_addr, c->target_addr, &err_msg);
if (wrapper == NULL) {
fprintf(stderr, "Error: %s\n", err_msg);
exit(EXIT_FAILURE);
}
//((struct ns_mgr *) wrapper)->hexdump_file = "/dev/stderr";
ssl_wrapper_serve(wrapper, &s_received_signal);
return NULL;
}
int main(void) {
struct mg_server *proxy_server = mg_create_server(NULL, ev_handler);
struct mg_server *ws1_server = mg_create_server(NULL, ws_handler);
struct mg_server *ws2_server = mg_create_server(NULL, ws_handler);
size_t i;
((struct ns_mgr *) proxy_server)->hexdump_file = "/dev/stderr";
// Configure proxy server to listen on port 2014
mg_set_option(proxy_server, "listening_port", "2014");
//mg_set_option(proxy_server, "enable_proxy", "yes");
// Configure two websocket echo servers:
// ws1 is WS, listening on 9001
// ws2 is WSS, listening on 9002
// Note that HTML page thinks that ws1 is WSS, and ws2 is WS,
// where in reality it is vice versa and proxy server makes the decision.
mg_set_option(ws1_server, "listening_port", "tcp://127.0.0.1:9001");
mg_set_option(ws2_server, "listening_port",
"ssl://127.0.0.1:9002:" S2_PEM ":" CA2_PEM);
// Setup signal handlers
signal(SIGTERM, signal_handler);
signal(SIGINT, signal_handler);
// Start SSL wrappers, each in it's own thread
for (i = 0; i < ARRAY_SIZE(s_wrappers); i++) {
ns_start_thread(wrapper_thread_func, &s_wrappers[i]);
}
// Start websocket servers in separate threads
mg_start_thread(serve_thread_func, ws1_server);
mg_start_thread(serve_thread_func, ws2_server);
// Finally, start proxy server in this thread: this call blocks
serve_thread_func(proxy_server);
printf("Existing on signal %d\n", s_received_signal);
return EXIT_SUCCESS;
}

View File

@ -1,50 +0,0 @@
<html>
<head>
<title>Websocket Proxy SSL Test</title>
<meta charset="utf-8">
<script>
window.onload = function() {
var protocols = ['ws://', 'wss://'];
var websocketServers = ['ws1', 'ws2'];
//protocols = ['wss://'];
//websocketServers = ['ws1']
var createWebsocketConnection = function(proto, server) {
var conn = new WebSocket(proto + server);
var div = document.createElement('div');
var h2 = document.createElement('h2');
h2.innerHTML = 'Connection to ' + proto + server;
document.body.appendChild(h2);
document.body.appendChild(div);
conn.onmessage = function(ev) {
var el = document.createElement('div');
el.innerHTML = 'websocket message: ' + ev.data;
div.appendChild(el);
// Keep only last 5 messages in the list
while (div.childNodes.length > 5) div.removeChild(div.firstChild);
};
// Send some string to the websocket connection periodically.
// websocket server much echo it back.
window.setInterval(function() { conn.send(Math.random()); }, 1000);
};
for (var i = 0; i < protocols.length; i++) {
for (var j = 0; j < websocketServers.length; j++) {
createWebsocketConnection(protocols[i], websocketServers[j]);
}
}
};
</script>
<style>
body > div {
border: 1px solid #ccc; background: #f0f0f0; padding: 0 1em;
margin: 0 2em; min-height: 4em; max-width: 40em;
}
</style>
</head>
<body>
</body>
</html>

View File

@ -1,8 +0,0 @@
LOCAL_PATH := $(call my-dir)/..
include $(CLEAR_VARS)
LOCAL_CFLAGS := -std=c99 -O2 -W -Wall -pthread -pipe $(COPT)
LOCAL_MODULE := mongoose
LOCAL_SRC_FILES := examples/web_server/web_server.c mongoose.c
include $(BUILD_EXECUTABLE)

File diff suppressed because it is too large Load Diff

View File

@ -1,158 +0,0 @@
// Copyright (c) 2004-2013 Sergey Lyubka <valenok@gmail.com>
// Copyright (c) 2013-2014 Cesanta Software Limited
// All rights reserved
//
// This software is dual-licensed: you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2 as
// published by the Free Software Foundation. For the terms of this
// license, see <http://www.gnu.org/licenses/>.
//
// You are free to use this software under the terms of the GNU General
// Public License, but WITHOUT ANY WARRANTY; without even the implied
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU General Public License for more details.
//
// Alternatively, you can license this software under a commercial
// license, as set out in <http://cesanta.com/>.
#ifndef MONGOOSE_HEADER_INCLUDED
#define MONGOOSE_HEADER_INCLUDED
#define MONGOOSE_VERSION "5.6"
#include <stdarg.h> // required for va_list
#include <stdio.h> // required for FILE
#include <stddef.h> // required for size_t
#include <sys/types.h> // required for time_t
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
// This structure contains information about HTTP request.
struct mg_connection {
const char *request_method; // "GET", "POST", etc
const char *uri; // URL-decoded URI
const char *http_version; // E.g. "1.0", "1.1"
const char *query_string; // URL part after '?', not including '?', or NULL
char remote_ip[48]; // Max IPv6 string length is 45 characters
char local_ip[48]; // Local IP address
unsigned short remote_port; // Client's port
unsigned short local_port; // Local port number
int num_headers; // Number of HTTP headers
struct mg_header {
const char *name; // HTTP header name
const char *value; // HTTP header value
} http_headers[30];
char *content; // POST (or websocket message) data, or NULL
size_t content_len; // Data length
int is_websocket; // Connection is a websocket connection
int status_code; // HTTP status code for HTTP error handler
int wsbits; // First byte of the websocket frame
void *server_param; // Parameter passed to mg_create_server()
void *connection_param; // Placeholder for connection-specific data
void *callback_param;
};
struct mg_server; // Opaque structure describing server instance
enum mg_result { MG_FALSE, MG_TRUE, MG_MORE };
enum mg_event {
MG_POLL = 100, // If callback returns MG_TRUE connection closes
// after all of data is sent
MG_CONNECT, // If callback returns MG_FALSE, connect fails
MG_AUTH, // If callback returns MG_FALSE, authentication fails
MG_REQUEST, // If callback returns MG_FALSE, Mongoose continues with req
MG_REPLY, // If callback returns MG_FALSE, Mongoose closes connection
MG_RECV, // Mongoose has received POST data chunk.
// Callback should return a number of bytes to discard from
// the receive buffer, or -1 to close the connection.
MG_CLOSE, // Connection is closed, callback return value is ignored
MG_WS_HANDSHAKE, // New websocket connection, handshake request
MG_WS_CONNECT, // New websocket connection established
MG_HTTP_ERROR // If callback returns MG_FALSE, Mongoose continues with err
};
typedef int (*mg_handler_t)(struct mg_connection *, enum mg_event);
// Websocket 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
};
// Server management functions
struct mg_server *mg_create_server(void *server_param, mg_handler_t handler);
void mg_destroy_server(struct mg_server **);
const char *mg_set_option(struct mg_server *, const char *opt, const char *val);
time_t mg_poll_server(struct mg_server *, int milliseconds);
const char **mg_get_valid_option_names(void);
const char *mg_get_option(const struct mg_server *server, const char *name);
void mg_copy_listeners(struct mg_server *from, struct mg_server *to);
struct mg_connection *mg_next(struct mg_server *, struct mg_connection *);
void mg_wakeup_server(struct mg_server *);
void mg_wakeup_server_ex(struct mg_server *, mg_handler_t, const char *, ...);
struct mg_connection *mg_connect(struct mg_server *, const char *);
// Connection management functions
void mg_send_status(struct mg_connection *, int status_code);
void mg_send_header(struct mg_connection *, const char *name, const char *val);
size_t mg_send_data(struct mg_connection *, const void *data, int data_len);
size_t mg_printf_data(struct mg_connection *, const char *format, ...);
size_t mg_vprintf_data(struct mg_connection *, const char *format, va_list ap);
size_t mg_write(struct mg_connection *, const void *buf, size_t len);
size_t mg_printf(struct mg_connection *conn, const char *fmt, ...);
size_t mg_vprintf(struct mg_connection *conn, const char *fmt, va_list ap);
size_t mg_websocket_write(struct mg_connection *, int opcode,
const char *data, size_t data_len);
size_t mg_websocket_printf(struct mg_connection* conn, int opcode,
const char *fmt, ...);
void mg_send_file(struct mg_connection *, const char *path, const char *);
void mg_send_file_data(struct mg_connection *, int fd);
const char *mg_get_header(const struct mg_connection *, const char *name);
const char *mg_get_mime_type(const char *name, const char *default_mime_type);
int mg_get_var(const struct mg_connection *conn, const char *var_name,
char *buf, size_t buf_len);
int mg_get_var_n(const struct mg_connection *conn, const char *var_name,
char *buf, size_t buf_len, int n);
int mg_parse_header(const char *hdr, const char *var_name, char *buf, size_t);
int mg_parse_multipart(const char *buf, int buf_len,
char *var_name, int var_name_len,
char *file_name, int file_name_len,
const char **data, int *data_len);
// Utility functions
void *mg_start_thread(void *(*func)(void *), void *param);
char *mg_md5(char buf[33], ...);
int mg_authorize_digest(struct mg_connection *c, FILE *fp);
size_t mg_url_encode(const char *src, size_t s_len, char *dst, size_t dst_len);
int mg_url_decode(const char *src, size_t src_len, char *dst, size_t dst_len, int);
int mg_terminate_ssl(struct mg_connection *c, const char *cert);
int mg_forward(struct mg_connection *c, const char *addr);
void *mg_mmap(FILE *fp, size_t size);
void mg_munmap(void *p, size_t size);
// Templates support
struct mg_expansion {
const char *keyword;
void (*handler)(struct mg_connection *);
};
void mg_template(struct mg_connection *, const char *text,
struct mg_expansion *expansions);
#ifdef __cplusplus
}
#endif // __cplusplus
#endif // MONGOOSE_HEADER_INCLUDED

View File

@ -1,53 +0,0 @@
# This program is used to embed arbitrary data into a C binary. It takes
# a list of files as an input, and produces a .c data file that contains
# contents of all these files as collection of char arrays.
#
# Usage: perl <this_file> <file1> [file2, ...] > embedded_data.c
foreach my $i (0 .. $#ARGV) {
open FD, '<:raw', $ARGV[$i] or die "Cannot open $ARGV[$i]: $!\n";
printf("static const unsigned char v%d[] = {", $i);
my $byte;
my $j = 0;
while (read(FD, $byte, 1)) {
if (($j % 12) == 0) {
print "\n";
}
printf ' %#04x,', ord($byte);
$j++;
}
print " 0x00\n};\n";
close FD;
}
print <<EOS;
#include <stddef.h>
#include <string.h>
static const struct embedded_file {
const char *name;
const unsigned char *data;
size_t size;
} embedded_files[] = {
EOS
foreach my $i (0 .. $#ARGV) {
print " {\"$ARGV[$i]\", v$i, sizeof(v$i) - 1},\n";
}
print <<EOS;
{NULL, NULL, 0}
};
const char *find_embedded_file(const char *name, size_t *size) {
const struct embedded_file *p;
for (p = embedded_files; p->name != NULL; p++) {
if (!strcmp(p->name, name)) {
if (size != NULL) { *size = p->size; }
return (const char *) p->data;
}
}
return NULL;
}
EOS

View File

@ -1,21 +0,0 @@
# Copyright (c) 2014 Cesanta Software
# All rights reserved
PROG = unit_test
PROF_FLAGS = -fprofile-arcs -ftest-coverage -g -O0 -DGUI
CFLAGS = -W -Wall -pthread -I.. $(PROF_FLAGS) $(CFLAGS_EXTRA)
SOURCES = $(PROG).c
all: $(PROG)
./$(PROG)
gcov -b $(PROG).c | egrep '^(File|Lines)'
$(PROG): $(SOURCES) Makefile ../mongoose.c clean
$(CC) -o $(PROG) $(SOURCES) $(CFLAGS) -ldl -lssl
win:
wine cl $(SOURCES) /MD /nologo /DNDEBUG /O1 /Fe$(PROG).exe
wine $(PROG).exe
clean:
rm -rf $(PROG) *.exe *.dSYM *.obj *.exp .*o *.lib *.gc*

View File

@ -1,533 +0,0 @@
// Unit test for the mongoose web server.
// g++ -W -Wall -pedantic -g unit_test.c -lssl && ./a.out
// cl unit_test.c /MD
#ifndef _WIN32
#define NS_ENABLE_IPV6
#define NS_ENABLE_SSL
#endif
#define MONGOOSE_POST_SIZE_LIMIT 999
// USE_* definitions must be made before #include "mongoose.c" !
#include "../mongoose.c"
#define FAIL(str, line) do { \
printf("Fail on line %d: [%s]\n", line, str); \
return str; \
} while (0)
#define ASSERT(expr) do { \
static_num_tests++; \
if (!(expr)) FAIL(#expr, __LINE__); \
} while (0)
#define RUN_TEST(test) do { const char *msg = test(); \
if (msg) return msg; } while (0)
#define HTTP_PORT "45772"
#define LISTENING_ADDR "127.0.0.1:" HTTP_PORT
static int static_num_tests = 0;
#if 0
// Connects to host:port, and sends formatted request to it. Returns
// malloc-ed reply and reply length, or NULL on error. Reply contains
// everything including headers, not just the message body.
static char *wget(const char *host, int port, int *len, const char *fmt, ...) {
char buf[2000], *reply = NULL;
int request_len, reply_size = 0, n, sock = -1;
struct sockaddr_in sin;
struct hostent *he = NULL;
va_list ap;
if (host != NULL &&
(he = gethostbyname(host)) != NULL &&
(sock = socket(PF_INET, SOCK_STREAM, 0)) != -1) {
sin.sin_family = AF_INET;
sin.sin_port = htons((uint16_t) port);
sin.sin_addr = * (struct in_addr *) he->h_addr_list[0];
if (connect(sock, (struct sockaddr *) &sin, sizeof(sin)) == 0) {
// Format and send the request.
va_start(ap, fmt);
request_len = vsnprintf(buf, sizeof(buf), fmt, ap);
va_end(ap);
while (request_len > 0 && (n = send(sock, buf, request_len, 0)) > 0) {
request_len -= n;
}
if (request_len == 0) {
*len = 0;
while ((n = recv(sock, buf, sizeof(buf), 0)) > 0) {
if (*len + n > reply_size) {
// Leak possible
reply = (char *) realloc(reply, reply_size + sizeof(buf));
reply_size += sizeof(buf);
}
if (reply != NULL) {
memcpy(reply + *len, buf, n);
*len += n;
}
}
}
closesocket(sock);
}
}
return reply;
}
#endif
static char *read_file(const char *path, int *size) {
FILE *fp;
struct stat st;
char *data = NULL;
if ((fp = fopen(path, "rb")) != NULL && !fstat(fileno(fp), &st)) {
*size = (int) st.st_size;
data = (char *) malloc(*size);
fread(data, 1, *size, fp);
fclose(fp);
}
return data;
}
static const char *test_parse_http_message() {
struct mg_connection ri;
char req1[] = "GET / HTTP/1.1\r\n\r\n";
char req2[] = "BLAH / HTTP/1.1\r\n\r\n";
char req3[] = "GET / HTTP/1.1\r\nBah\r\n";
char req4[] = "GET / HTTP/1.1\r\nA: foo bar\r\nB: bar\r\nbaz\r\n\r\n";
char req5[] = "GET / HTTP/1.1\r\n\r\n";
char req6[] = "G";
char req7[] = " blah ";
char req8[] = " HTTP/1.1 200 OK \n\n";
char req9[] = "HTTP/1.1 200 OK\r\nConnection: close\r\n\r\n";
ASSERT(get_request_len("\r\n", 3) == -1);
ASSERT(get_request_len("\r\n", 2) == 0);
ASSERT(get_request_len("GET", 3) == 0);
ASSERT(get_request_len("\n\n", 2) == 2);
ASSERT(get_request_len("\n\r\n", 3) == 3);
ASSERT(get_request_len("\xdd\xdd", 2) == 0);
ASSERT(get_request_len("\xdd\x03", 2) == -1);
ASSERT(get_request_len(req3, sizeof(req3) - 1) == 0);
ASSERT(get_request_len(req6, sizeof(req6) - 1) == 0);
ASSERT(get_request_len(req7, sizeof(req7) - 1) == 0);
ASSERT(parse_http_message(req9, sizeof(req9) - 1, &ri) == sizeof(req9) - 1);
ASSERT(ri.num_headers == 1);
ASSERT(parse_http_message(req1, sizeof(req1) - 1, &ri) == sizeof(req1) - 1);
ASSERT(strcmp(ri.http_version, "1.1") == 0);
ASSERT(ri.num_headers == 0);
ASSERT(parse_http_message(req2, sizeof(req2) - 1, &ri) == (size_t) ~0);
ASSERT(parse_http_message(req6, 0, &ri) == (size_t) ~0);
ASSERT(parse_http_message(req8, sizeof(req8) - 1, &ri) == sizeof(req8) - 1);
// TODO(lsm): Fix this. Header value may span multiple lines.
ASSERT(parse_http_message(req4, sizeof(req4) - 1, &ri) == sizeof(req4) - 1);
ASSERT(strcmp(ri.http_version, "1.1") == 0);
ASSERT(ri.num_headers == 3);
ASSERT(strcmp(ri.http_headers[0].name, "A") == 0);
ASSERT(strcmp(ri.http_headers[0].value, "foo bar") == 0);
ASSERT(strcmp(ri.http_headers[1].name, "B") == 0);
ASSERT(strcmp(ri.http_headers[1].value, "bar") == 0);
ASSERT(strcmp(ri.http_headers[2].name, "baz\r\n\r") == 0);
ASSERT(strcmp(ri.http_headers[2].value, "") == 0);
ASSERT(parse_http_message(req5, sizeof(req5) - 1, &ri) == sizeof(req5) - 1);
ASSERT(strcmp(ri.request_method, "GET") == 0);
ASSERT(strcmp(ri.http_version, "1.1") == 0);
return NULL;
}
static const char *test_should_keep_alive(void) {
struct mg_connection conn;
char req1[] = "GET / HTTP/1.1\r\n\r\n";
char req2[] = "GET / HTTP/1.0\r\n\r\n";
char req3[] = "GET / HTTP/1.1\r\nConnection: close\r\n\r\n";
char req4[] = "GET / HTTP/1.1\r\nConnection: keep-alive\r\n\r\n";
memset(&conn, 0, sizeof(conn));
ASSERT(parse_http_message(req1, sizeof(req1) - 1, &conn) == sizeof(req1) - 1);
ASSERT(should_keep_alive(&conn) != 0);
parse_http_message(req2, sizeof(req2) - 1, &conn);
ASSERT(should_keep_alive(&conn) == 0);
parse_http_message(req3, sizeof(req3) - 1, &conn);
ASSERT(should_keep_alive(&conn) == 0);
parse_http_message(req4, sizeof(req4) - 1, &conn);
ASSERT(should_keep_alive(&conn) != 0);
return NULL;
}
static const char *test_match_prefix(void) {
ASSERT(mg_match_prefix("/api", 4, "/api") == 4);
ASSERT(mg_match_prefix("/a/", 3, "/a/b/c") == 3);
ASSERT(mg_match_prefix("/a/", 3, "/ab/c") == -1);
ASSERT(mg_match_prefix("/blog/", 6, "/") == -1);
ASSERT(mg_match_prefix("/*/", 3, "/ab/c") == 4);
ASSERT(mg_match_prefix("**", 2, "/a/b/c") == 6);
ASSERT(mg_match_prefix("/*", 2, "/a/b/c") == 2);
ASSERT(mg_match_prefix("*/*", 3, "/a/b/c") == 2);
ASSERT(mg_match_prefix("**/", 3, "/a/b/c") == 5);
ASSERT(mg_match_prefix("**.foo|**.bar", 13, "a.bar") == 5);
ASSERT(mg_match_prefix("a|b|cd", 6, "cdef") == 2);
ASSERT(mg_match_prefix("a|b|c?", 6, "cdef") == 2);
ASSERT(mg_match_prefix("a|?|cd", 6, "cdef") == 1);
ASSERT(mg_match_prefix("/a/**.cgi", 9, "/foo/bar/x.cgi") == -1);
ASSERT(mg_match_prefix("/a/**.cgi", 9, "/a/bar/x.cgi") == 12);
ASSERT(mg_match_prefix("**/", 3, "/a/b/c") == 5);
ASSERT(mg_match_prefix("**/$", 4, "/a/b/c") == -1);
ASSERT(mg_match_prefix("**/$", 4, "/a/b/") == 5);
ASSERT(mg_match_prefix("$", 1, "") == 0);
ASSERT(mg_match_prefix("$", 1, "x") == -1);
ASSERT(mg_match_prefix("*$", 2, "x") == 1);
ASSERT(mg_match_prefix("/$", 2, "/") == 1);
ASSERT(mg_match_prefix("**/$", 4, "/a/b/c") == -1);
ASSERT(mg_match_prefix("**/$", 4, "/a/b/") == 5);
ASSERT(mg_match_prefix("*", 1, "/hello/") == 0);
ASSERT(mg_match_prefix("**.a$|**.b$", 11, "/a/b.b/") == -1);
ASSERT(mg_match_prefix("**.a$|**.b$", 11, "/a/b.b") == 6);
ASSERT(mg_match_prefix("**.a$|**.b$", 11, "/a/B.A") == 6);
ASSERT(mg_match_prefix("**o$", 4, "HELLO") == 5);
return NULL;
}
static const char *test_remove_double_dots() {
struct { char before[30], after[30]; } data[] = {
{"////a", "/a"},
{"/.....", "/....."},
{"/......", "/......"},
{"...", "..."},
{"/...///", "/.../"},
{"/a...///", "/a.../"},
{"/.x", "/.x"},
{"/\\", "/"},
{"/a\\", "/a\\"},
{"/a\\\\...", "/a\\..."},
{"foo/x..y/././y/../../..", "foo/x..y/y/"},
{"foo/..x", "foo/..x"},
};
size_t i;
for (i = 0; i < ARRAY_SIZE(data); i++) {
remove_double_dots_and_double_slashes(data[i].before);
ASSERT(strcmp(data[i].before, data[i].after) == 0);
}
return NULL;
}
static const char *test_get_var(void) {
static const char *data = "a=1&&b=2&d&=&c=3%20&e=&k=aa&a=23";
static const char *data2 = "q=&st=2012%2F11%2F13+17%3A05&et=&team_id=";
char buf[20];
ASSERT(get_var(data, strlen(data), "a", buf, sizeof(buf), 0) == 1);
ASSERT(buf[0] == '1' && buf[1] == '\0');
ASSERT(get_var(data, strlen(data), "a", buf, sizeof(buf), 1) == 2);
ASSERT(strcmp(buf, "23") == 0);
ASSERT(get_var(data, strlen(data), "b", buf, sizeof(buf), 0) == 1);
ASSERT(buf[0] == '2' && buf[1] == '\0');
ASSERT(get_var(data, strlen(data), "c", buf, sizeof(buf), 0) == 2);
ASSERT(buf[0] == '3' && buf[1] == ' ' && buf[2] == '\0');
ASSERT(get_var(data, strlen(data), "e", buf, sizeof(buf), 0) == 0);
ASSERT(buf[0] == '\0');
ASSERT(get_var(data, strlen(data), "d", buf, sizeof(buf), 0) == -1);
ASSERT(get_var(data, strlen(data), "c", buf, 2, 0) == -2);
ASSERT(get_var(data, strlen(data), "x", NULL, 10, 0) == -2);
ASSERT(get_var(data, strlen(data), "x", buf, 0, 0) == -2);
ASSERT(get_var(data2, strlen(data2), "st", buf, 16, 0) == -2);
ASSERT(get_var(data2, strlen(data2), "st", buf, 17, 0) == 16);
return NULL;
}
static const char *test_url_decode(void) {
char buf[100];
ASSERT(mg_url_decode("foo", 3, buf, 3, 0) == -1); // No space for \0
ASSERT(mg_url_decode("foo", 3, buf, 4, 0) == 3);
ASSERT(strcmp(buf, "foo") == 0);
ASSERT(mg_url_decode("a+", 2, buf, sizeof(buf), 0) == 2);
ASSERT(strcmp(buf, "a+") == 0);
ASSERT(mg_url_decode("a+", 2, buf, sizeof(buf), 1) == 2);
ASSERT(strcmp(buf, "a ") == 0);
ASSERT(mg_url_decode("%61", 1, buf, sizeof(buf), 1) == 1);
printf("[%s]\n", buf);
ASSERT(strcmp(buf, "%") == 0);
ASSERT(mg_url_decode("%61", 2, buf, sizeof(buf), 1) == 2);
ASSERT(strcmp(buf, "%6") == 0);
ASSERT(mg_url_decode("%61", 3, buf, sizeof(buf), 1) == 1);
ASSERT(strcmp(buf, "a") == 0);
return NULL;
}
static const char *test_url_encode(void) {
char buf[100];
ASSERT(mg_url_encode("", 0, buf, sizeof(buf)) == 0);
ASSERT(buf[0] == '\0');
ASSERT(mg_url_encode("foo", 3, buf, sizeof(buf)) == 3);
ASSERT(strcmp(buf, "foo") == 0);
ASSERT(mg_url_encode("f o", 3, buf, sizeof(buf)) == 5);
ASSERT(strcmp(buf, "f%20o") == 0);
return NULL;
}
static const char *test_to64(void) {
ASSERT(to64("0") == 0);
ASSERT(to64("") == 0);
ASSERT(to64("123") == 123);
ASSERT(to64("-34") == -34);
ASSERT(to64("3566626116") == 3566626116);
return NULL;
}
static const char *test_base64_encode(void) {
const char *in[] = {"a", "ab", "abc", "abcd", NULL};
const char *out[] = {"YQ==", "YWI=", "YWJj", "YWJjZA=="};
char buf[100];
int i;
for (i = 0; in[i] != NULL; i++) {
base64_encode((unsigned char *) in[i], strlen(in[i]), buf);
ASSERT(!strcmp(buf, out[i]));
}
return NULL;
}
static const char *test_mg_parse_header(void) {
const char *str = "xx=1 kl yy, ert=234 kl=123, uri=\"/?name=x,y\", "
"ii=\"12\\\"34\" zz='aa bb',tt=2,gf=\"xx d=1234";
char buf[20];
ASSERT(mg_parse_header(str, "yy", buf, sizeof(buf)) == 0);
ASSERT(mg_parse_header(str, "ert", buf, sizeof(buf)) == 3);
ASSERT(strcmp(buf, "234") == 0);
ASSERT(mg_parse_header(str, "ert", buf, 2) == 0);
ASSERT(mg_parse_header(str, "ert", buf, 3) == 0);
ASSERT(mg_parse_header(str, "ert", buf, 4) == 3);
ASSERT(mg_parse_header(str, "gf", buf, sizeof(buf)) == 0);
ASSERT(mg_parse_header(str, "zz", buf, sizeof(buf)) == 5);
ASSERT(strcmp(buf, "aa bb") == 0);
ASSERT(mg_parse_header(str, "d", buf, sizeof(buf)) == 4);
ASSERT(strcmp(buf, "1234") == 0);
buf[0] = 'x';
ASSERT(mg_parse_header(str, "MMM", buf, sizeof(buf)) == 0);
ASSERT(buf[0] == '\0');
ASSERT(mg_parse_header(str, "kl", buf, sizeof(buf)) == 3);
ASSERT(strcmp(buf, "123") == 0);
ASSERT(mg_parse_header(str, "xx", buf, sizeof(buf)) == 1);
ASSERT(strcmp(buf, "1") == 0);
ASSERT(mg_parse_header(str, "ii", buf, sizeof(buf)) == 5);
ASSERT(strcmp(buf, "12\"34") == 0);
ASSERT(mg_parse_header(str, "tt", buf, sizeof(buf)) == 1);
ASSERT(strcmp(buf, "2") == 0);
ASSERT(mg_parse_header(str, "uri", buf, sizeof(buf)) == 10);
return NULL;
}
static const char *test_next_option(void) {
const char *p, *list = "x/8,/y**=1;2k,z";
struct vec a, b;
int i;
ASSERT(next_option(NULL, &a, &b) == NULL);
for (i = 0, p = list; (p = next_option(p, &a, &b)) != NULL; i++) {
ASSERT(i != 0 || (a.ptr == list && a.len == 3 && b.len == 0));
ASSERT(i != 1 || (a.ptr == list + 4 && a.len == 4 && b.ptr == list + 9 &&
b.len == 4));
ASSERT(i != 2 || (a.ptr == list + 14 && a.len == 1 && b.len == 0));
}
return NULL;
}
static int evh1(struct mg_connection *conn, enum mg_event ev) {
char *buf = (char *) conn->connection_param;
int result = MG_FALSE;
switch (ev) {
case MG_CONNECT:
mg_printf(conn, "GET %s HTTP/1.0\r\n\r\n",
buf[0] == '1' ? "/cb1" : "/non_exist");
result = MG_TRUE;
break;
case MG_HTTP_ERROR:
mg_printf(conn, "HTTP/1.0 404 NF\r\n\r\nERR: %d", conn->status_code);
result = MG_TRUE;
break;
case MG_REQUEST:
if (!strcmp(conn->uri, "/cb1")) {
mg_printf(conn, "HTTP/1.0 200 OK\r\n\r\n%s %s %s",
(char *) conn->server_param,
buf == NULL ? "?" : "!", conn->remote_ip);
result = MG_TRUE;
}
break;
case MG_REPLY:
if (buf != NULL) {
sprintf(buf + 1, "%.*s", (int) conn->content_len, conn->content);
}
break;
case MG_AUTH:
result = MG_TRUE;
break;
default:
break;
}
return result;
}
static const char *test_server(void) {
char buf1[100] = "1", buf2[100] = "2";
struct mg_server *server = mg_create_server((void *) "foo", evh1);
struct mg_connection *conn;
ASSERT(server != NULL);
ASSERT(mg_set_option(server, "listening_port", LISTENING_ADDR) == NULL);
ASSERT(mg_set_option(server, "document_root", ".") == NULL);
ASSERT((conn = mg_connect(server, "127.0.0.1:" HTTP_PORT)) != NULL);
conn->connection_param = buf1;
ASSERT((conn = mg_connect(server, "127.0.0.1:" HTTP_PORT)) != NULL);
conn->connection_param = buf2;
{ int i; for (i = 0; i < 50; i++) mg_poll_server(server, 1); }
ASSERT(strcmp(buf1, "1foo ? 127.0.0.1") == 0);
ASSERT(strcmp(buf2, "2ERR: 404") == 0);
ASSERT(strcmp(static_config_options[URL_REWRITES * 2], "url_rewrites") == 0);
mg_destroy_server(&server);
ASSERT(server == NULL);
return NULL;
}
#define DISP "Content-Disposition: form/data; "
#define CRLF "\r\n"
#define BOUNDARY "--xyz"
static const char *test_parse_multipart(void) {
char a[100], b[100];
const char *p;
static const char f1[] = BOUNDARY CRLF DISP "name=f1" CRLF CRLF
"some_content" CRLF BOUNDARY CRLF
BOUNDARY CRLF DISP "name=f2; filename=\"foo bar.txt\"" CRLF CRLF
"another_content" CRLF BOUNDARY CRLF
"--" CRLF;
int n, n2, len, f1_len = sizeof(f1) - 1;
ASSERT(mg_parse_multipart("", 0, a, sizeof(a), b, sizeof(b), &p, &len) == 0);
ASSERT(mg_parse_multipart("a", 1, a, sizeof(a), b, sizeof(b), &p, &len) == 0);
ASSERT((n = mg_parse_multipart(f1, f1_len, a, sizeof(a),
b, sizeof(b), &p, &len)) > 0);
ASSERT(len == 12);
ASSERT(memcmp(p, "some_content", len) == 0);
ASSERT(strcmp(a, "f1") == 0);
ASSERT(b[0] == '\0');
ASSERT((n2 = mg_parse_multipart(f1 + n, f1_len - n, a, sizeof(a),
b, sizeof(b), &p, &len)) > 0);
ASSERT(len == 15);
ASSERT(memcmp(p, "another_content", len) == 0);
ASSERT(strcmp(a, "f2") == 0);
ASSERT(strcmp(b, "foo bar.txt") == 0);
ASSERT((n2 = mg_parse_multipart(f1 + n + n2, f1_len - (n + n2), a, sizeof(a),
b, sizeof(b), &p, &len)) == 0);
return NULL;
}
static int evh2(struct mg_connection *conn, enum mg_event ev) {
char *file_data, *cp = (char *) conn->connection_param;
int file_size, result = MG_FALSE;
switch (ev) {
case MG_AUTH:
result = MG_TRUE;
break;
case MG_CONNECT:
mg_printf(conn, "GET /%s HTTP/1.0\r\n\r\n", cp);
result = MG_TRUE;
break;
case MG_REQUEST:
break;
case MG_REPLY:
file_data = read_file("unit_test.c", &file_size);
sprintf(cp, "%d %s", (size_t) file_size == conn->content_len &&
memcmp(file_data, conn->content, file_size) == 0 ? 1 : 0,
conn->query_string == NULL ? "?" : conn->query_string);
free(file_data);
break;
default:
break;
}
return result;
}
static const char *test_mg_set_option(void) {
struct mg_server *server = mg_create_server(NULL, NULL);
ASSERT(mg_set_option(server, "listening_port", "0") == NULL);
ASSERT(mg_get_option(server, "listening_port")[0] != '\0');
mg_destroy_server(&server);
return NULL;
}
static const char *test_rewrites(void) {
char buf1[100] = "xx", addr[50];
struct mg_server *server = mg_create_server(NULL, evh2);
struct mg_connection *conn;
const char *port;
ASSERT(mg_set_option(server, "listening_port", "0") == NULL);
ASSERT(mg_set_option(server, "document_root", ".") == NULL);
ASSERT(mg_set_option(server, "url_rewrites", "/xx=unit_test.c") == NULL);
ASSERT((port = mg_get_option(server, "listening_port")) != NULL);
snprintf(addr, sizeof(addr), "127.0.0.1:%s", port);
ASSERT((conn = mg_connect(server, addr)) != NULL);
conn->connection_param = buf1;
{ int i; for (i = 0; i < 50; i++) mg_poll_server(server, 1); }
ASSERT(strcmp(buf1, "1 ?") == 0);
mg_destroy_server(&server);
return NULL;
}
static const char *run_all_tests(void) {
RUN_TEST(test_should_keep_alive);
RUN_TEST(test_match_prefix);
RUN_TEST(test_remove_double_dots);
RUN_TEST(test_parse_http_message);
RUN_TEST(test_to64);
RUN_TEST(test_url_decode);
RUN_TEST(test_url_encode);
RUN_TEST(test_base64_encode);
RUN_TEST(test_mg_parse_header);
RUN_TEST(test_get_var);
RUN_TEST(test_next_option);
RUN_TEST(test_parse_multipart);
RUN_TEST(test_mg_set_option);
RUN_TEST(test_server);
RUN_TEST(test_rewrites);
return NULL;
}
int __cdecl main(void) {
const char *fail_msg = run_all_tests();
printf("%s, tests run: %d\n", fail_msg ? "FAIL" : "PASS", static_num_tests);
return fail_msg == NULL ? EXIT_SUCCESS : EXIT_FAILURE;
}

View File

@ -460,46 +460,6 @@ project "lsqlite3"
MAME_DIR .. "3rdparty/lsqlite3/lsqlite3.c",
}
--------------------------------------------------
-- mongoose library objects
--------------------------------------------------
project "mongoose"
uuid "ff05b529-2b6f-4166-9dff-5fe2aef89c40"
kind "StaticLib"
configuration { "vs*" }
buildoptions {
"/wd4996", -- warning C4996: 'function': was declared deprecated
"/wd4100", -- warning C4100: 'xxx' : unreferenced formal parameter
"/wd4245", -- warning C4245: 'conversion' : conversion from 'type1' to 'type2', signed/unsigned mismatch
"/wd4267", -- warning C4267: 'var' : conversion from 'size_t' to 'type', possible loss of data
"/wd4244", -- warning C4244: 'argument' : conversion from 'xxx' to 'xxx', possible loss of data
}
configuration { "vs2015" }
buildoptions {
"/wd4456", -- warning C4456: declaration of 'xxx' hides previous local declaration
}
configuration { }
options {
"ForceCPP",
}
defines {
"MONGOOSE_ENABLE_THREADS",
"NS_STACK_SIZE=0"
}
includedirs {
MAME_DIR .. "3rdparty/mongoose",
}
files {
MAME_DIR .. "3rdparty/mongoose/mongoose.c",
}
--------------------------------------------------
-- jsoncpp library objects
--------------------------------------------------

View File

@ -245,8 +245,6 @@ files {
MAME_DIR .. "src/emu/debug/textbuf.h",
MAME_DIR .. "src/emu/profiler.c",
MAME_DIR .. "src/emu/profiler.h",
MAME_DIR .. "src/emu/webengine.c",
MAME_DIR .. "src/emu/webengine.h",
MAME_DIR .. "src/emu/sound/filter.c",
MAME_DIR .. "src/emu/sound/filter.h",
MAME_DIR .. "src/devices/sound/flt_vol.c",

View File

@ -116,7 +116,6 @@ end
"lua",
"lsqlite3",
"jsoncpp",
"mongoose",
}
if _OPTIONS["with-bundled-zlib"] then

View File

@ -1931,8 +1931,6 @@ void device_debug::instruction_hook(offs_t curpc)
// flush any pending updates before waiting again
machine.debug_view().flush_osd_updates();
machine.manager().web()->serve();
// clear the memory modified flag and wait
global->memory_modified = false;
if (machine.debug_flags & DEBUG_FLAG_OSD_ENABLED)

View File

@ -185,10 +185,6 @@ const options_entry emu_options::s_option_entries[] =
{ OPTION_AUTOBOOT_COMMAND ";ab", NULL, OPTION_STRING, "command to execute after machine boot" },
{ OPTION_AUTOBOOT_DELAY, "2", OPTION_INTEGER, "timer delay in sec to trigger command execution on autoboot" },
{ OPTION_AUTOBOOT_SCRIPT ";script", NULL, OPTION_STRING, "lua script to execute after machine boot" },
{ OPTION_HTTP, "0", OPTION_BOOLEAN, "enable local http server" },
{ OPTION_HTTP_PORT, "8080", OPTION_STRING, "http server listener port" },
{ OPTION_HTTP_PATH, "web", OPTION_STRING, "path to web files" },
{ OPTION_CONSOLE, "0", OPTION_BOOLEAN, "enable emulator LUA console" },
{ NULL }
};

View File

@ -189,11 +189,6 @@ enum
#define OPTION_AUTOBOOT_DELAY "autoboot_delay"
#define OPTION_AUTOBOOT_SCRIPT "autoboot_script"
#define OPTION_HTTP "http"
#define OPTION_HTTP_PORT "http_port"
#define OPTION_HTTP_PATH "http_path"
#define OPTION_CONSOLE "console"
//**************************************************************************
// TYPE DEFINITIONS
//**************************************************************************
@ -366,11 +361,6 @@ public:
int autoboot_delay() const { return int_value(OPTION_AUTOBOOT_DELAY); }
const char *autoboot_script() const { return value(OPTION_AUTOBOOT_SCRIPT); }
bool http() const { return bool_value(OPTION_HTTP); }
const char *http_port() const { return value(OPTION_HTTP_PORT); }
const char *http_path() const { return value(OPTION_HTTP_PATH); }
bool console() const { return bool_value(OPTION_CONSOLE); }
// FIXME: Couriersud: This should be in image_device_exit
void remove_device_options();

View File

@ -17,7 +17,6 @@
#include "osdepend.h"
#include "drivenum.h"
#include "ui/ui.h"
#include "mongoose/mongoose.h"
//**************************************************************************
// LUA ENGINE
@ -862,13 +861,14 @@ void lua_engine::serve_lua()
} while (1);
}
/*
static void *serve_lua(void *param)
{
lua_engine *engine = (lua_engine *)param;
engine->serve_lua();
return NULL;
}
*/
//-------------------------------------------------
// lua_engine - constructor
@ -1025,7 +1025,6 @@ void lua_engine::initialize()
void lua_engine::start_console()
{
mg_start_thread(::serve_lua, this);
}
//-------------------------------------------------

View File

@ -393,8 +393,6 @@ int running_machine::run(bool firstrun)
js_set_main_loop(this);
#endif
manager().web()->serve();
// execute CPUs if not paused
if (!m_paused)
m_scheduler.timeslice();

View File

@ -117,7 +117,6 @@ machine_manager* machine_manager::instance()
machine_manager::machine_manager(emu_options &options,osd_interface &osd)
: m_osd(osd),
m_options(options),
m_web(options),
m_new_driver_pending(NULL),
m_machine(NULL)
{
@ -155,8 +154,6 @@ void machine_manager::schedule_new_driver(const game_driver &driver)
void machine_manager::update_machine()
{
m_lua.set_machine(m_machine);
m_web.set_machine(m_machine);
if (m_machine!=NULL) m_web.push_message("update_machine");
}
/*-------------------------------------------------
@ -175,9 +172,6 @@ int machine_manager::execute()
int error = MAMERR_NONE;
m_lua.initialize();
if (m_options.console()) {
m_lua.start_console();
}
while (error == MAMERR_NONE && !exit_pending)
{
m_new_driver_pending = NULL;

View File

@ -18,8 +18,6 @@
#include <time.h>
#include "webengine.h"
class osd_interface;
//**************************************************************************
@ -89,7 +87,6 @@ public:
osd_interface &osd() const;
emu_options &options() const { return m_options; }
web_engine *web() { return &m_web; }
lua_engine *lua() { return &m_lua; }
running_machine *machine() { return m_machine; }
@ -105,7 +102,6 @@ private:
osd_interface & m_osd; // reference to OSD system
emu_options & m_options; // reference to options
web_engine m_web;
lua_engine m_lua;
const game_driver * m_new_driver_pending; // pointer to the next pending driver

View File

@ -374,7 +374,6 @@ void ui_manager::display_startup_screens(bool first_time, bool show_disclaimer)
// loop while we have a handler
while (m_handler_callback != handler_ingame && !machine().scheduled_event_pending() && !ui_menu::stack_has_special_main_menu())
{
machine().manager().web()->serve();
machine().video().frame_update();
}

View File

@ -1,545 +0,0 @@
// license:BSD-3-Clause
// copyright-holders:Miodrag Milanovic
/***************************************************************************
webengine.c
Handle MAME internal web server.
***************************************************************************/
#include "mongoose/mongoose.h"
#include "jsoncpp/include/json/json.h"
#include "emu.h"
#include "emuopts.h"
#include "ui/ui.h"
#include "webengine.h"
#include "lua.hpp"
#include "osdepend.h"
//**************************************************************************
// WEB ENGINE
//**************************************************************************
char* websanitize_statefilename ( char* unsanitized )
{
// It's important that we remove any dangerous characters from any filename
// we receive from a web client. This can be a serious security hole.
// As MAME/MESS policy is lowercase filenames, also lowercase it.
char* sanitized = new char[64];
int insertpoint =0;
char charcompare;
while (*unsanitized != 0)
{
charcompare = *unsanitized;
// ASCII 48-57 are 0-9
// ASCII 97-122 are lowercase A-Z
if ((charcompare >= 48 && charcompare <= 57) || (charcompare >= 97 && charcompare <= 122))
{
sanitized[insertpoint] = charcompare;
insertpoint++;
sanitized[insertpoint] = '\0'; // Make sure we're null-terminated.
}
// ASCII 65-90 are uppercase A-Z. These need to be lowercased.
if (charcompare >= 65 && charcompare <= 90)
{
sanitized[insertpoint] = tolower(charcompare); // Lowercase it
insertpoint++;
sanitized[insertpoint] = '\0'; // Make sure we're null-terminated.
}
unsanitized++;
}
return (sanitized);
}
int web_engine::json_game_handler(struct mg_connection *conn)
{
Json::Value data;
data["name"] = m_machine->system().name;
data["description"] = m_machine->system().description;
data["year"] = m_machine->system().year;
data["manufacturer"] = m_machine->system().manufacturer;
data["parent"] = m_machine->system().parent;
data["source_file"] = m_machine->system().source_file;
data["flags"] = m_machine->system().flags;
data["ispaused"] = m_machine->paused();
Json::FastWriter writer;
std::string json = writer.write(data);
// Send HTTP reply to the client
mg_printf(conn,
"HTTP/1.1 200 OK\r\n"
"Content-Type: application/json\r\n"
"Content-Length: %d\r\n" // Always set Content-Length
"\r\n"
"%s",
(int)json.length(), json.c_str());
// Returning non-zero tells mongoose that our function has replied to
// the client, and mongoose should not send client any more data.
return MG_TRUE;
}
int web_engine::json_slider_handler(struct mg_connection *conn)
{
const slider_state *curslider;
std::string tempstring;
Json::Value array(Json::arrayValue);
// add all sliders
for (curslider = machine().ui().get_slider_list(); curslider != NULL; curslider = curslider->next)
{
INT32 curval = (*curslider->update)(machine(), curslider->arg, &tempstring, SLIDER_NOCHANGE);
Json::Value data;
data["description"] = curslider->description;
data["minval"] = curslider->minval;
data["maxval"] = curslider->maxval;
data["defval"] = curslider->defval;
data["incval"] = curslider->incval;
data["curval"] = curval;
array.append(data);
}
// add all sliders
for (curslider = (slider_state*)machine().osd().get_slider_list(); curslider != NULL; curslider = curslider->next)
{
INT32 curval = (*curslider->update)(machine(), curslider->arg, &tempstring, SLIDER_NOCHANGE);
Json::Value data;
data["description"] = curslider->description;
data["minval"] = curslider->minval;
data["maxval"] = curslider->maxval;
data["defval"] = curslider->defval;
data["incval"] = curslider->incval;
data["curval"] = curval;
array.append(data);
}
Json::FastWriter writer;
std::string json = writer.write(array);
// Send HTTP reply to the client
mg_printf(conn,
"HTTP/1.1 200 OK\r\n"
"Content-Type: application/json\r\n"
"Content-Length: %d\r\n" // Always set Content-Length
"\r\n"
"%s",
(int)json.length(), json.c_str());
return MG_TRUE;
}
void reg_string(struct lua_State *L, const char *name, const char *val) {
lua_pushstring(L, name);
lua_pushstring(L, val);
lua_rawset(L, -3);
}
void reg_int(struct lua_State *L, const char *name, int val) {
lua_pushstring(L, name);
lua_pushinteger(L, val);
lua_rawset(L, -3);
}
void reg_function(struct lua_State *L, const char *name,
lua_CFunction func, struct mg_connection *conn) {
lua_pushstring(L, name);
lua_pushlightuserdata(L, conn);
lua_pushcclosure(L, func, 1);
lua_rawset(L, -3);
}
static int lua_write(lua_State *L) {
int i, num_args;
const char *str;
size_t size;
struct mg_connection *conn = (struct mg_connection *)
lua_touserdata(L, lua_upvalueindex(1));
num_args = lua_gettop(L);
for (i = 1; i <= num_args; i++) {
if (lua_isstring(L, i)) {
str = lua_tolstring(L, i, &size);
mg_send_data(conn, str, size);
}
}
return 0;
}
static int lua_header(lua_State *L) {
struct mg_connection *conn = (struct mg_connection *)
lua_touserdata(L, lua_upvalueindex(1));
const char *header = luaL_checkstring(L,1);
const char *value = luaL_checkstring(L,2);
mg_send_header(conn, header, value);
return 0;
}
static void prepare_lua_environment(struct mg_connection *ri, lua_State *L) {
extern void luaL_openlibs(lua_State *);
int i;
luaL_openlibs(L);
if (ri == NULL) return;
// Register mg module
lua_newtable(L);
reg_function(L, "write", lua_write, ri);
reg_function(L, "header", lua_header, ri);
// Export request_info
lua_pushstring(L, "request_info");
lua_newtable(L);
reg_string(L, "request_method", ri->request_method);
reg_string(L, "uri", ri->uri);
reg_string(L, "http_version", ri->http_version);
reg_string(L, "query_string", ri->query_string);
reg_string(L, "remote_ip", ri->remote_ip);
reg_int(L, "remote_port", ri->remote_port);
reg_string(L, "local_ip", ri->local_ip);
reg_int(L, "local_port", ri->local_port);
lua_pushstring(L, "content");
lua_pushlstring(L, ri->content == NULL ? "" : ri->content, ri->content_len);
lua_rawset(L, -3);
reg_int(L, "num_headers", ri->num_headers);
lua_pushstring(L, "http_headers");
lua_newtable(L);
for (i = 0; i < ri->num_headers; i++) {
reg_string(L, ri->http_headers[i].name, ri->http_headers[i].value);
}
lua_rawset(L, -3);
lua_rawset(L, -3);
lua_setglobal(L, "mg");
}
static void lsp(struct mg_connection *conn, const char *p, int len, lua_State *L) {
int i, j, pos = 0;
for (i = 0; i < len; i++) {
if (p[i] == '<' && p[i + 1] == '?') {
for (j = i + 1; j < len ; j++) {
if (p[j] == '?' && p[j + 1] == '>') {
if (i-pos!=0) mg_send_data(conn, p + pos, i - pos);
if (luaL_loadbuffer(L, p + (i + 2), j - (i + 2), "") == 0) {
lua_pcall(L, 0, LUA_MULTRET, 0);
}
pos = j + 2;
i = pos - 1;
break;
}
}
}
}
if (i > pos) {
mg_send_data(conn, p + pos, i - pos);
}
}
static int filename_endswith(const char *str, const char *suffix)
{
if (!str || !suffix)
return 0;
size_t lenstr = strlen(str);
size_t lensuffix = strlen(suffix);
if (lensuffix > lenstr)
return 0;
return strncmp(str + lenstr - lensuffix, suffix, lensuffix) == 0;
}
// This function will be called by mongoose on every new request.
int web_engine::begin_request_handler(struct mg_connection *conn)
{
std::string file_path = std::string(mg_get_option(m_server, "document_root")).append(PATH_SEPARATOR).append(conn->uri);
if (filename_endswith(file_path.c_str(), ".lp"))
{
FILE *fp = NULL;
if ((fp = fopen(file_path.c_str(), "rb")) != NULL) {
fseek (fp, 0, SEEK_END);
size_t size = ftell(fp);
fseek (fp, 0, SEEK_SET);
char *data = (char*)mg_mmap(fp,size);
lua_State *L = luaL_newstate();
prepare_lua_environment(conn, L);
lsp(conn, data, (int) size, L);
if (L != NULL) lua_close(L);
mg_munmap(data,size);
fclose(fp);
return MG_TRUE;
} else {
return MG_FALSE;
}
}
else if (!strncmp(conn->uri, "/json/",6))
{
if (!strcmp(conn->uri, "/json/game"))
{
return json_game_handler(conn);
}
if (!strcmp(conn->uri, "/json/slider"))
{
return json_slider_handler(conn);
}
}
else if (!strncmp(conn->uri, "/keypost",8))
{
// Is there any sane way to determine the length of the buffer before getting it?
// A request for a way was previously filed with the mongoose devs,
// but it looks like it was never implemented.
// For now, we'll allow a paste buffer of 32k.
// To-do: Send an error if the paste is too big?
char cmd_val[32768];
int pastelength = mg_get_var(conn, "val", cmd_val, sizeof(cmd_val));
if (pastelength > 0) {
machine().ioport().natkeyboard().post_utf8(cmd_val);
}
// Send HTTP reply to the client
mg_printf(conn,
"HTTP/1.1 200 OK\r\n"
"Content-Type: text/plain\r\n"
"Content-Length: 2\r\n" // Always set Content-Length
"\r\n"
"OK");
// Returning non-zero tells mongoose that our function has replied to
// the client, and mongoose should not send client any more data.
return MG_TRUE;
}
else if (!strncmp(conn->uri, "/keyupload",8))
{
char *upload_data;
int data_length, ofs = 0;
char var_name[100], file_name[255];
while ((ofs = mg_parse_multipart(conn->content + ofs, conn->content_len - ofs, var_name, sizeof(var_name), file_name, sizeof(file_name), (const char **)&upload_data, &data_length)) > 0) {
mg_printf_data(conn, "File: %s, size: %d bytes", file_name, data_length);
}
// That upload_data contains more than we need. It also has the headers.
// We'll need to strip it down to just what we want.
if ((&data_length > 0) && (sizeof(file_name) > 0))
{
// MSVC doesn't yet support variable-length arrays, so chop the string the old-fashioned way
upload_data[data_length] = '\0';
// Now paste the stripped down paste_data..
machine().ioport().natkeyboard().post_utf8(upload_data);
}
return MG_TRUE;
}
else if (!strncmp(conn->uri, "/cmd",4))
{
char cmd_name[64];
mg_get_var(conn, "name", cmd_name, sizeof(cmd_name));
if(!strcmp(cmd_name,"softreset"))
{
m_machine->schedule_soft_reset();
}
else if(!strcmp(cmd_name,"hardreset"))
{
m_machine->schedule_hard_reset();
}
else if(!strcmp(cmd_name,"exit"))
{
m_machine->schedule_exit();
}
else if(!strcmp(cmd_name,"togglepause"))
{
if (m_machine->paused())
m_machine->resume();
else
m_machine->pause();
}
else if(!strcmp(cmd_name,"savestate"))
{
char cmd_val[64];
mg_get_var(conn, "val", cmd_val, sizeof(cmd_val));
char *filename = websanitize_statefilename(cmd_val);
m_machine->schedule_save(filename);
}
else if(!strcmp(cmd_name,"loadstate"))
{
char cmd_val[64];
mg_get_var(conn, "val", cmd_val, sizeof(cmd_val));
char *filename = cmd_val;
m_machine->schedule_load(filename);
}
else if(!strcmp(cmd_name,"loadauto"))
{
// This is here to just load the autosave and only the autosave.
m_machine->schedule_load("auto");
}
// Send HTTP reply to the client
mg_printf(conn,
"HTTP/1.1 200 OK\r\n"
"Content-Type: text/plain\r\n"
"Content-Length: 2\r\n" // Always set Content-Length
"\r\n"
"OK");
// Returning non-zero tells mongoose that our function has replied to
// the client, and mongoose should not send client any more data.
return MG_TRUE;
}
else if (!strncmp(conn->uri, "/slider",7))
{
char cmd_id[64];
char cmd_val[64];
mg_get_var(conn, "id", cmd_id, sizeof(cmd_id));
mg_get_var(conn, "val", cmd_val, sizeof(cmd_val));
int cnt = 0;
int id = atoi(cmd_id);
const slider_state *curslider;
for (curslider = machine().ui().get_slider_list(); curslider != NULL; curslider = curslider->next)
{
if (cnt==id)
(*curslider->update)(machine(), curslider->arg, NULL, atoi(cmd_val));
cnt++;
}
for (curslider = (slider_state*)machine().osd().get_slider_list(); curslider != NULL; curslider = curslider->next)
{
if (cnt==id)
(*curslider->update)(machine(), curslider->arg, NULL, atoi(cmd_val));
cnt++;
}
// Send HTTP reply to the client
mg_printf(conn,
"HTTP/1.1 200 OK\r\n"
"Content-Type: text/plain\r\n"
"Content-Length: 2\r\n" // Always set Content-Length
"\r\n"
"OK");
// Returning non-zero tells mongoose that our function has replied to
// the client, and mongoose should not send client any more data.
return MG_TRUE;
}
else if (!strncmp(conn->uri, "/screenshot.png",15))
{
screen_device_iterator iter(m_machine->root_device());
screen_device *screen = iter.first();
if (screen == NULL)
{
return 0;
}
std::string fname("screenshot.png");
emu_file file(m_machine->options().snapshot_directory(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS);
file_error filerr = file.open(fname.c_str());
if (filerr != FILERR_NONE)
{
return 0;
}
m_machine->video().save_snapshot(screen, file);
std::string fullpath(file.fullpath());
file.close();
mg_send_header(conn, "Cache-Control", "no-cache, no-store, must-revalidate");
mg_send_header(conn, "Pragma", "no-cache");
mg_send_header(conn, "Expires", "0");
mg_send_file(conn, fullpath.c_str(), NULL);
return MG_MORE; // It is important to return MG_MORE after mg_send_file!
}
return 0;
}
static int ev_handler(struct mg_connection *conn, enum mg_event ev) {
if (ev == MG_REQUEST) {
if (conn->is_websocket) {
// This handler is called for each incoming websocket frame, one or more
// times for connection lifetime.
// Echo websocket data back to the client.
return conn->content_len == 4 && !memcmp(conn->content, "exit", 4) ? MG_FALSE : MG_TRUE;
} else {
web_engine *engine = static_cast<web_engine *>(conn->server_param);
return engine->begin_request_handler(conn);
}
} else if (ev== MG_WS_CONNECT) {
// New websocket connection. Send connection ID back to the client.
mg_websocket_printf(conn, WEBSOCKET_OPCODE_TEXT, "update_machine");
return MG_FALSE;
} else if (ev == MG_AUTH) {
return MG_TRUE;
} else {
return MG_FALSE;
}
}
//-------------------------------------------------
// web_engine - constructor
//-------------------------------------------------
web_engine::web_engine(emu_options &options)
: m_options(options),
m_machine(NULL),
m_server(NULL),
//m_lastupdatetime(0),
m_exiting_core(false),
m_http(m_options.http())
{
if (m_http) {
m_server = mg_create_server(this, ev_handler);
mg_set_option(m_server, "listening_port", options.http_port());
mg_set_option(m_server, "document_root", options.http_path());
}
}
//-------------------------------------------------
// ~web_engine - destructor
//-------------------------------------------------
web_engine::~web_engine()
{
if (m_http)
close();
}
//-------------------------------------------------
// close - close and cleanup of lua engine
//-------------------------------------------------
void web_engine::close()
{
m_exiting_core = 1;
// Cleanup, and free server instance
mg_destroy_server(&m_server);
}
void web_engine::serve()
{
if (m_http) mg_poll_server(m_server, 0);
}
void web_engine::push_message(const char *message)
{
struct mg_connection *c;
if (m_server!=NULL) {
// Iterate over all connections, and push current time message to websocket ones.
for (c = mg_next(m_server, NULL); c != NULL; c = mg_next(m_server, c)) {
if (c->is_websocket) {
mg_websocket_write(c, 1, message, strlen(message));
}
}
}
}

View File

@ -1,48 +0,0 @@
// license:BSD-3-Clause
// copyright-holders:Miodrag Milanovic
/***************************************************************************
webengine.h
Handle MAME internal web server.
***************************************************************************/
#pragma once
#ifndef __WEB_ENGINE_H__
#define __WEB_ENGINE_H__
struct mg_server; // Handle for the HTTP server itself
struct mg_connection; // Handle for the individual connection
class web_engine
{
public:
// construction/destruction
web_engine(emu_options &options);
~web_engine();
void serve();
void push_message(const char *message);
void close();
void set_machine(running_machine *machine) { m_machine = machine; }
int begin_request_handler(struct mg_connection *conn);
protected:
// getters
running_machine &machine() const { return *m_machine; }
int json_game_handler(struct mg_connection *conn);
int json_slider_handler(struct mg_connection *conn);
private:
// internal state
emu_options & m_options;
running_machine * m_machine;
struct mg_server * m_server;
//osd_ticks_t m_lastupdatetime;
bool m_exiting_core;
bool m_http;
};
#endif /* __web_engine_H__ */

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.8 KiB

File diff suppressed because one or more lines are too long

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 25 KiB

View File

@ -1,917 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="expires" content="-1">
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<title>MAME</title>
<link rel="shortcut icon" href="favicon.ico">
<link rel="stylesheet" href="css/jquery.mobile.css">
<!-- jQuery and jQuery Mobile -->
<script src="js/jquery.js"></script>
<script src="js/jquery.mobile.js"></script>
</head>
<body>
<script language="javascript" type="text/javascript">
function updateStatusBar(connectionStatus, isPaused, driverText) {
if (connectionStatus) {
// Update every page's connection statusbar.
$("td#main_statusbar_connectionstatus").html(connectionStatus);
$("td#command_statusbar_connectionstatus").html(connectionStatus);
$("td#option_statusbar_connectionstatus").html(connectionStatus);
$("td#slider_statusbar_connectionstatus").html(connectionStatus);
$("td#driver_statusbar_connectionstatus").html(connectionStatus);
$("td#image_statusbar_connectionstatus").html(connectionStatus);
$("td#info_statusbar_connectionstatus").html(connectionStatus);
$("td#logs_statusbar_connectionstatus").html(connectionStatus);
}
if (isPaused) {
// Update every page's running/paused statusbar.
$("td#main_statusbar_ispaused").html(isPaused);
$("td#command_statusbar_ispaused").html(isPaused);
$("td#option_statusbar_ispaused").html(isPaused);
$("td#slider_statusbar_ispaused").html(isPaused);
$("td#driver_statusbar_ispaused").html(isPaused);
$("td#image_statusbar_ispaused").html(isPaused);
$("td#info_statusbar_ispaused").html(isPaused);
$("td#logs_statusbar_ispaused").html(isPaused);
}
if (driverText) {
// Update every page's running driver statusbar.
$("td#main_statusbar_runningdriver").html(driverText);
$("td#command_statusbar_runningdriver").html(driverText);
$("td#option_statusbar_runningdriver").html(driverText);
$("td#slider_statusbar_runningdriver").html(driverText);
$("td#driver_statusbar_runningdriver").html(driverText);
$("td#image_statusbar_runningdriver").html(driverText);
$("td#info_statusbar_runningdriver").html(driverText);
$("td#logs_statusbar_runningdriver").html(driverText);
}
}
function takeScreenshot()
{
// First, we need to generate a random number to make absolutely sure we bypass browser caching.
var random=Math.floor(Math.random()*999999999)
$("#screenshot").html('<img height="240" width="320" src="/screenshot.png?cachebreaker='+random.toString()+'"/>');
// Navigate back to home so we can see the screenshot.
window.location.hash='#mainmenu';
}
function executeCommands(command)
{
$.ajax({
url: "/cmd?name="+command,
cache: false,
dataType: "text",
success: function(data) {
},
error: function (request, status, error) { alert(status + ", " + error); }
});
if (command !== 'exit') {
startWebSocket();
} else {
updateStatusBar('<b style="color: red;">Disconnected</b>','Exited','No Driver');
}
}
function executeHardReset()
{
executeCommands("hardreset");
startWebSocket();
$('.ui-dialog').dialog('close');
}
function executeSoftReset()
{
executeCommands("softreset");
startWebSocket();
$('.ui-dialog').dialog('close');
}
function executeExit()
{
executeCommands("exit");
$('.ui-dialog').dialog('close');
}
function executeSlider()
{
$.ajax({
url: "/json/slider",
cache: false,
dataType: "json",
success: function(data) {
var items = [];
for (var i in data) {
items.push('<label for="slider-mini-'+i+'">'+data[i].description +':</label>');
items.push('<input type="range" name="slider-mini-'+i+'" id="slider-mini-'+i+'" value="'+data[i].curval+'" min="'+data[i].minval+'" max="'+data[i].maxval+'" step=="'+data[i].incval+'" data-highlight="true" data-mini="true" />');
}
$('#sliders').html('');
$('#sliders').append(items.join('')).trigger('create');
for (var i in data) {
$('#slider-mini-' + i).bind( "slidestop", function(event, ui) { setSliderValue($(this).attr('id').replace('slider-mini-',''),$(this).slider().val()); });
}
},
error: function (request, status, error) { alert(status + ", " + error); }
});
window.location.hash='#slidermenu'; // Just making sure we're on the slider screen.
}
function setSliderValue(id,val)
{
$.ajax({
url: "/slider?id="+id+"&val="+val,
cache: false,
dataType: "text",
success: function(data) {
},
error: function (request, status, error) { alert(status + ", " + error); }
});
}
function startWebSocket() {
var docbase = window.location.href.toString().split('#')[0]; // We strip the fragment from the URL using split.
var url = docbase.replace("http://","ws://");
websocket = new WebSocket(url);
websocket.onopen = function(ev) {
updateStatusBar('<b style="color: green;">Connected</b>','','');
};
websocket.onclose = function(ev) {
updateStatusBar('<b style="color: red;">Disconnected</b>','','');
};
websocket.onmessage = function(ev) {
if (ev.data=='update_machine')
{
$.ajax({
url: "json/game",
cache: false,
dataType: "json",
success: function(data) {
var maindesc_name = [];
var maindesc_description = [];
var maindesc_year = [];
var maindesc_manufacturer = [];
var maindesc_parent = [];
var maindesc_sourcefile = [];
var statusbar_ispaused = [];
var statusbar_runningdriver = [];
if(data.ispaused) {
statusbar_ispaused.push('<b style="color: red; ">Paused</b>');
} else {
statusbar_ispaused.push('<b style="color: green; ">Running</b>');
}
if(data.name =='__empty') {
statusbar_runningdriver.push('No driver');
} else {
statusbar_runningdriver.push(data.description + ' [' + data.manufacturer+']');
}
maindesc_name.push(data.name);
maindesc_description.push(data.description);
maindesc_year.push(data.year);
maindesc_manufacturer.push(data.manufacturer);
maindesc_parent.push(data.parent);
maindesc_sourcefile.push(data.source_file);
$("#maindesc_name").html(maindesc_name.join(''));
$("#maindesc_description").html(maindesc_description.join(''));
$("#maindesc_year").html(maindesc_year.join(''));
$("#maindesc_manufacturer").html(maindesc_manufacturer.join(''));
$("#maindesc_parent").html(maindesc_parent.join(''));
$("#maindesc_sourcefile").html(maindesc_sourcefile.join(''));
// Now, actually update the status bar..
updateStatusBar('',statusbar_ispaused.join(''),statusbar_runningdriver.join(''));
takeScreenshot();
},
error: function (request, status, error) { alert(status + ", " + error); }
});
}
};
websocket.onerror = function(ev) {
updateStatusBar('<b style="color: red; ">Error</b>',' ',' ');
};
}
window.onload = function() {
startWebSocket();
};
$(document).ready(function() {
$( '#pasteTextForm' ).submit(function( event )
{
$.ajax({
url: "/keypost",
type:'POST',
data:
{
val: pasteText.value
},
success: function(msg)
{
}
});
event.preventDefault(); // This prevents it trying to load a /keypost page after doing the Ajax post.
});
});
</script>
<!-- This begins the MAIN MENU page ------------------------------------------------------------------->
<div data-role="page" id="mainmenu">
<div data-theme="a" data-role="header">
<div style="width: 100%; height: 120px; position: relative;">
<img src="images/logo-mame-small.png" alt="image" style="position: absolute; top: 50%; left: 50%; margin-left: -158px; margin-top: -50px">
</div>
<a data-role="button" href="#mainmenu" data-icon="home" data-iconpos="left" class="ui-btn-right">Home</a>
<div data-role="navbar" data-iconpos="top">
<ul>
<li>
<a href="#drivermenumenu" data-transition="fade" data-icon="bars">Driver</a>
</li>
<li>
<a href="#optionmenu" data-transition="fade" data-icon="gear">Options</a>
</li>
<li>
<a href="#imagemenu" data-transition="fade" data-icon="grid">Image</a>
</li>
<li>
<a href="#commandmenu" data-transition="fade" data-icon="star">Commands</a>
</li>
</ul>
</div>
</div>
<div data-role="content" id="mainmenucontent">
<table style="tablelayout: auto; width: 100%" border="0">
<tr>
<td style="padding: 0px; vertical-align:top; width: 1px"><div id="screenshot"><img height="240" width="320" src="/screenshot.png"></div></td>
<td style="padding: 0px; vertical-align:top">
<table border="0"><div id="drivertext"></div>
<tr>
<th style="text-align:left;">Name</th>
<td><div id="maindesc_name"></div></td>
</tr>
<tr>
<th style="text-align:left;">Description</th>
<td><div id="maindesc_description"></div></td>
</tr>
<tr>
<th style="text-align:left;">Year</th>
<td><div id="maindesc_year"></div></td>
</tr>
<tr>
<th style="text-align:left;">Manufacturer</th>
<td><div id="maindesc_manufacturer"></div></td>
</tr>
<tr>
<th style="text-align:left;">Parent</th>
<td><div id="maindesc_parent"></div></td>
</tr>
<tr>
<th style="text-align:left;">Source File</th>
<td><div id="maindesc_sourcefile"></div></td>
</tr>
</table>
</td>
</tr>
</table>
</div>
<div data-theme="a" data-role="footer" data-position="fixed">
<div data-role="navbar" data-iconpos="top">
<ul>
<li>
<a href="#infomenu" data-transition="fade" data-icon="info">Info</a>
</li>
<li>
<a href="#logsmenu" data-transition="fade" data-icon="check">Logs</a>
</li>
<li>
<a href="javascript:takeScreenshot();" data-transition="fade" data-icon="search">Screenshot</a>
</li>
<li>
<a href="javascript:startWebSocket();" data-transition="fade" data-icon="refresh">Reconnect</a>
</li>
</ul>
</div>
<h3>
<table style="tablelayout: fixed; width: 100%; height: 10px; border-collapse:collapse;" border="0">
<tr>
<td style="width: 10%; padding: 0px;" id="main_statusbar_connectionstatus"></td>
<td style="width: 10%; padding: 0px;" id="main_statusbar_ispaused"></td>
<td style="width: 80%; padding: 0px;" id="main_statusbar_runningdriver"></td>
</tr>
</table>
</h3>
</div>
</div>
<!-- This begins the COMMAND MENU page ------------------------------------------------------------------->
<div data-role="page" id="commandmenu">
<div data-theme="a" data-role="header">
<div style="width: 100%; height: 120px; position: relative;">
<img src="images/logo-mame-small.png" alt="image" style="position: absolute; top: 50%; left: 50%; margin-left: -158px; margin-top: -50px">
</div>
<a data-role="button" href="#mainmenu" data-icon="home" data-iconpos="left" class="ui-btn-right">Home</a>
<div data-role="navbar" data-iconpos="top">
<ul>
<li>
<a href="#drivermenumenu" data-transition="fade" data-icon="bars">Driver</a>
</li>
<li>
<a href="#optionmenu" data-transition="fade" data-icon="gear">Options</a>
</li>
<li>
<a href="#imagemenu" data-transition="fade" data-icon="grid">Image</a>
</li>
<li>
<a href="#mainmenu" data-transition="fade" data-icon="home">Main Menu</a>
</li>
</ul>
</div>
</div>
<div data-role="content" id="menu_commandmenu">
<h2>Savestate Control</h2>
<div class="ui-grid-a">
<div class="ui-block-a"><a href="#savestatepanel" data-transition="fade" data-role="button">Save State</a></div>
<div class="ui-block-b"><a href="#loadstatepanel" data-transition="fade" data-role="button">Load State</a></div>
</div>
<h2>Paste/Upload Text</h2>
<div class="ui-grid-a">
<div class="ui-block-a"><a href="#pastepanel" data-transition="fade" data-role="button">Paste Text</a></div>
<div class="ui-block-b"><a href="#uploadpastepanel" data-transition="fade" data-role="button">Upload Text</a></div>
</div>
<h2>Execution Control</h2>
<div class="ui-grid-a">
<div class="ui-block-a"><a href="#dialogConfirmSoftReset" data-rel="dialog" data-role="button">Soft reset</a></div>
<div class="ui-block-b"><a href="#dialogConfirmHardReset" data-rel="dialog" data-role="button">Hard reset</a></div>
</div>
<div class="ui-grid-a">
<div class="ui-block-b"><a href="javascript:executeCommands('togglepause');" data-role="button">Toggle Pause</a></div>
<div class="ui-block-b"><a href="#dialogConfirmExit" data-rel="dialog" data-role="button">Exit</a></div>
</div>
</div>
<div data-theme="a" data-role="footer" data-position="fixed">
<div data-role="navbar" data-iconpos="top">
<ul>
<li>
<a href="#infomenu" data-transition="fade" data-icon="info">Info</a>
</li>
<li>
<a href="#logsmenu" data-transition="fade" data-icon="check">Logs</a>
</li>
<li>
<a href="javascript:takeScreenshot();" data-transition="fade" data-icon="search">Screenshot</a>
</li>
<li>
<a href="javascript:startWebSocket();" data-transition="fade" data-icon="refresh">Reconnect</a>
</li>
</ul>
</div>
<h3>
<table style="tablelayout: fixed; width: 100%; height: 10px; border-collapse:collapse;" border="0">
<tr>
<td style="width: 10%; padding: 0px;" id="command_statusbar_connectionstatus"></td>
<td style="width: 10%; padding: 0px;" id="command_statusbar_ispaused"></td>
<td style="width: 80%; padding: 0px;" id="command_statusbar_runningdriver"></td>
</tr>
</table>
</h3>
</div>
<!-- This begins the Save State panel -------------------------------------------------------->
<div data-role="panel" id="savestatepanel" data-position="left" data-display="overlay" data-theme="a">
<h3>Select position to save to</h3><br>
<!-- Yes, it's a little ugly. I could redo this more cleanly with a little javascript, but not right now. -->
<div data-role="controlgroup" data-type="horizontal">
<a href="" data-rel="close" data-role="button">Cancel</a>
<a href="javascript:executeCommands('savestate&val=auto');" data-role="button">Auto Slot</a>
</div>
<div data-role="controlgroup" data-type="horizontal">
<a href="javascript:executeCommands('savestate&val=0');" data-role="button">0</a>
<a href="javascript:executeCommands('savestate&val=1');" data-role="button">1</a>
<a href="javascript:executeCommands('savestate&val=2');" data-role="button">2</a>
<a href="javascript:executeCommands('savestate&val=3');" data-role="button">3</a>
</div>
<div data-role="controlgroup" data-type="horizontal">
<a href="javascript:executeCommands('savestate&val=4');" data-role="button">4</a>
<a href="javascript:executeCommands('savestate&val=5');" data-role="button">5</a>
<a href="javascript:executeCommands('savestate&val=6');" data-role="button">6</a>
<a href="javascript:executeCommands('savestate&val=7');" data-role="button">7</a>
</div>
<div data-role="controlgroup" data-type="horizontal">
<a href="javascript:executeCommands('savestate&val=8');" data-role="button">8</a>
<a href="javascript:executeCommands('savestate&val=9');" data-role="button">9</a>
<a href="javascript:executeCommands('savestate&val=a');" data-role="button">A</a>
<a href="javascript:executeCommands('savestate&val=b');" data-role="button">B</a>
</div>
<div data-role="controlgroup" data-type="horizontal">
<a href="javascript:executeCommands('savestate&val=c');" data-role="button">C</a>
<a href="javascript:executeCommands('savestate&val=d');" data-role="button">D</a>
<a href="javascript:executeCommands('savestate&val=e');" data-role="button">E</a>
<a href="javascript:executeCommands('savestate&val=f');" data-role="button">F</a>
</div>
<div data-role="controlgroup" data-type="horizontal">
<a href="javascript:executeCommands('savestate&val=g');" data-role="button">G</a>
<a href="javascript:executeCommands('savestate&val=h');" data-role="button">H</a>
<a href="javascript:executeCommands('savestate&val=i');" data-role="button">I</a>
<a href="javascript:executeCommands('savestate&val=j');" data-role="button">J</a>
</div>
<div data-role="controlgroup" data-type="horizontal">
<a href="javascript:executeCommands('savestate&val=k');" data-role="button">K</a>
<a href="javascript:executeCommands('savestate&val=l');" data-role="button">L</a>
<a href="javascript:executeCommands('savestate&val=m');" data-role="button">M</a>
<a href="javascript:executeCommands('savestate&val=n');" data-role="button">N</a>
</div>
<div data-role="controlgroup" data-type="horizontal">
<a href="javascript:executeCommands('savestate&val=o');" data-role="button">O</a>
<a href="javascript:executeCommands('savestate&val=p');" data-role="button">P</a>
<a href="javascript:executeCommands('savestate&val=q');" data-role="button">Q</a>
<a href="javascript:executeCommands('savestate&val=r');" data-role="button">R</a>
</div>
<div data-role="controlgroup" data-type="horizontal">
<a href="javascript:executeCommands('savestate&val=s');" data-role="button">S</a>
<a href="javascript:executeCommands('savestate&val=t');" data-role="button">T</a>
<a href="javascript:executeCommands('savestate&val=u');" data-role="button">U</a>
<a href="javascript:executeCommands('savestate&val=v');" data-role="button">V</a>
</div>
<div data-role="controlgroup" data-type="horizontal">
<a href="javascript:executeCommands('savestate&val=w');" data-role="button">W</a>
<a href="javascript:executeCommands('savestate&val=x');" data-role="button">X</a>
<a href="javascript:executeCommands('savestate&val=y');" data-role="button">Y</a>
<a href="javascript:executeCommands('savestate&val=z');" data-role="button">Z</a>
</div>
<!-- This is here to prevent webkit from trying to put the last row of states under the bottom menu on small screens like phone-->
<br><br><br><br><br>
</div>
<!-- This begins the Load State panel -------------------------------------------------------->
<div data-role="panel" id="loadstatepanel" data-position="left" data-display="overlay" data-theme="a">
<h3>Select position to load from</h3><br>
<!-- Yes, it's a little ugly. I could redo this more cleanly with a little javascript, but not right now. -->
<div data-role="controlgroup" data-type="horizontal">
<a href="" data-rel="close" data-role="button">Cancel</a>
<a href="javascript:executeCommands('loadstate&val=auto');" data-role="button">Auto Slot</a>
</div>
<div data-role="controlgroup" data-type="horizontal">
<a href="javascript:executeCommands('loadstate&val=0');" data-role="button">0</a>
<a href="javascript:executeCommands('loadstate&val=1');" data-role="button">1</a>
<a href="javascript:executeCommands('loadstate&val=2');" data-role="button">2</a>
<a href="javascript:executeCommands('loadstate&val=3');" data-role="button">3</a>
</div>
<div data-role="controlgroup" data-type="horizontal">
<a href="javascript:executeCommands('loadstate&val=4');" data-role="button">4</a>
<a href="javascript:executeCommands('loadstate&val=5');" data-role="button">5</a>
<a href="javascript:executeCommands('loadstate&val=6');" data-role="button">6</a>
<a href="javascript:executeCommands('loadstate&val=7');" data-role="button">7</a>
</div>
<div data-role="controlgroup" data-type="horizontal">
<a href="javascript:executeCommands('loadstate&val=8');" data-role="button">8</a>
<a href="javascript:executeCommands('loadstate&val=9');" data-role="button">9</a>
<a href="javascript:executeCommands('loadstate&val=a');" data-role="button">A</a>
<a href="javascript:executeCommands('loadstate&val=b');" data-role="button">B</a>
</div>
<div data-role="controlgroup" data-type="horizontal">
<a href="javascript:executeCommands('loadstate&val=c');" data-role="button">C</a>
<a href="javascript:executeCommands('loadstate&val=d');" data-role="button">D</a>
<a href="javascript:executeCommands('loadstate&val=e');" data-role="button">E</a>
<a href="javascript:executeCommands('loadstate&val=f');" data-role="button">F</a>
</div>
<div data-role="controlgroup" data-type="horizontal">
<a href="javascript:executeCommands('loadstate&val=g');" data-role="button">G</a>
<a href="javascript:executeCommands('loadstate&val=h');" data-role="button">H</a>
<a href="javascript:executeCommands('loadstate&val=i');" data-role="button">I</a>
<a href="javascript:executeCommands('loadstate&val=j');" data-role="button">J</a>
</div>
<div data-role="controlgroup" data-type="horizontal">
<a href="javascript:executeCommands('loadstate&val=k');" data-role="button">K</a>
<a href="javascript:executeCommands('loadstate&val=l');" data-role="button">L</a>
<a href="javascript:executeCommands('loadstate&val=m');" data-role="button">M</a>
<a href="javascript:executeCommands('loadstate&val=n');" data-role="button">N</a>
</div>
<div data-role="controlgroup" data-type="horizontal">
<a href="javascript:executeCommands('loadstate&val=o');" data-role="button">O</a>
<a href="javascript:executeCommands('loadstate&val=p');" data-role="button">P</a>
<a href="javascript:executeCommands('loadstate&val=q');" data-role="button">Q</a>
<a href="javascript:executeCommands('loadstate&val=r');" data-role="button">R</a>
</div>
<div data-role="controlgroup" data-type="horizontal">
<a href="javascript:executeCommands('loadstate&val=s');" data-role="button">S</a>
<a href="javascript:executeCommands('loadstate&val=t');" data-role="button">T</a>
<a href="javascript:executeCommands('loadstate&val=u');" data-role="button">U</a>
<a href="javascript:executeCommands('loadstate&val=v');" data-role="button">V</a>
</div>
<div data-role="controlgroup" data-type="horizontal">
<a href="javascript:executeCommands('loadstate&val=w');" data-role="button">W</a>
<a href="javascript:executeCommands('loadstate&val=x');" data-role="button">X</a>
<a href="javascript:executeCommands('loadstate&val=y');" data-role="button">Y</a>
<a href="javascript:executeCommands('loadstate&val=z');" data-role="button">Z</a>
</div>
<!-- This is here to prevent webkit from trying to put the last row of states under the bottom menu on small screens like phone-->
<br><br><br><br><br>
</div>
<!-- This begins the Paste Text panel -------------------------------------------------------->
<div data-role="panel" id="pastepanel" data-position="left" data-display="overlay" data-theme="a">
<h4>Paste Text to Keyboard</h4>
<form id="pasteTextForm" action="#pastepanel" method="post">
<div data-role="controlgroup" data-type="horizontal">
<a href="" data-rel="close" data-role="button">Exit</a>
<input type="submit" value="Send">
<input type="reset" value="Clear">
</div>
<br>
<textarea id="pasteText" name="val"></textarea>
</form>
<!-- This is here to prevent webkit from trying to put the last row of states under the bottom menu on small screens like phone-->
<br><br><br><br><br>
</div>
<!-- This begins the Upload Text panel -------------------------------------------------------->
<div data-role="panel" id="uploadpastepanel" data-position="left" data-display="overlay" data-theme="a">
<h4>Upload Text to Keyboard</h4>
<form method="post" action="/keyupload" enctype="multipart/form-data" target="uploadpastelog" data-ajax="false">
<!-- note that we can't do file uploads via Ajax -->
<div data-role="controlgroup" data-type="horizontal">
<a href="" data-rel="close" data-role="button">Exit</a>
<input type="submit" value="Upload" />
</div>
<input type="file" name="file" /> <br/>
</form>
<!-- This is here to prevent webkit from trying to put the last row of states under the bottom menu on small screens like phone-->
<br><br><br><br><br>
</div>
</div>
<!-- This begins the SLIDERS page ------------------------------------------------------------------->
<div data-role="page" id="slidermenu">
<div data-theme="a" data-role="header">
<div style="width: 100%; height: 120px; position: relative;">
<img src="images/logo-mame-small.png" alt="image" style="position: absolute; top: 50%; left: 50%; margin-left: -158px; margin-top: -50px">
</div>
<a data-role="button" href="#mainmenu" data-icon="home" data-iconpos="left" class="ui-btn-right">Home</a>
<div data-role="navbar" data-iconpos="top">
<ul>
<li>
<a href="#drivermenumenu" data-transition="fade" data-icon="bars">Driver</a>
</li>
<li>
<a href="#optionmenu" data-transition="fade" data-icon="gear">Options</a>
</li>
<li>
<a href="#imagemenu" data-transition="fade" data-icon="grid">Image</a>
</li>
<li>
<a href="#commandmenu" data-transition="fade" data-icon="star">Commands</a>
</li>
</ul>
</div>
</div>
<div data-role="content" id="sliders">
</div>
<div data-theme="a" data-role="footer" data-position="fixed">
<div data-role="navbar" data-iconpos="top">
<ul>
<li>
<a href="#infomenu" data-transition="fade" data-icon="info">Info</a>
</li>
<li>
<a href="#logsmenu" data-transition="fade" data-icon="check">Logs</a>
</li>
<li>
<a href="javascript:takeScreenshot();" data-transition="fade" data-icon="search">Screenshot</a>
</li>
<li>
<a href="javascript:startWebSocket();" data-transition="fade" data-icon="refresh">Reconnect</a>
</li>
</ul>
</div>
<h3>
<table style="tablelayout: fixed; width: 100%; height: 10px; border-collapse:collapse;" border="0">
<tr>
<td style="width: 10%; padding: 0px;" id="option_statusbar_connectionstatus"></td>
<td style="width: 10%; padding: 0px;" id="option_statusbar_ispaused"></td>
<td style="width: 80%; padding: 0px;" id="option_statusbar_runningdriver"></td>
</tr>
</table>
</h3>
</div>
</div>
<!-- This begins the OPTION MENU page ------------------------------------------------------------------->
<div data-role="page" id="optionmenu">
<div data-theme="a" data-role="header">
<div style="width: 100%; height: 120px; position: relative;">
<img src="images/logo-mame-small.png" alt="image" style="position: absolute; top: 50%; left: 50%; margin-left: -158px; margin-top: -50px">
</div>
<a data-role="button" href="#mainmenu" data-icon="home" data-iconpos="left" class="ui-btn-right">Home</a>
<div data-role="navbar" data-iconpos="top">
<ul>
<li>
<a href="#drivermenumenu" data-transition="fade" data-icon="bars">Driver</a>
</li>
<li>
<a href="#mainmenu" data-transition="fade" data-icon="home">Main Menu</a>
</li>
<li>
<a href="#imagemenu" data-transition="fade" data-icon="grid">Image</a>
</li>
<li>
<a href="#commandmenu" data-transition="fade" data-icon="star">Commands</a>
</li>
</ul>
</div>
</div>
<div data-role="content" id="menu_optionmenu">
<a href="javascript:executeSlider();" data-role="button">Sliders</a>
</div>
<div data-theme="a" data-role="footer" data-position="fixed">
<div data-role="navbar" data-iconpos="top">
<ul>
<li>
<a href="#infomenu" data-transition="fade" data-icon="info">Info</a>
</li>
<li>
<a href="#logsmenu" data-transition="fade" data-icon="check">Logs</a>
</li>
<li>
<a href="javascript:takeScreenshot();" data-transition="fade" data-icon="search">Screenshot</a>
</li>
<li>
<a href="javascript:startWebSocket();" data-transition="fade" data-icon="refresh">Reconnect</a>
</li>
</ul>
</div>
<h3>
<table style="tablelayout: fixed; width: 100%; height: 10px; border-collapse:collapse;" border="0">
<tr>
<td style="width: 10%; padding: 0px;" id="slider_statusbar_connectionstatus"></td>
<td style="width: 10%; padding: 0px;" id="slider_statusbar_ispaused"></td>
<td style="width: 80%; padding: 0px;" id="slider_statusbar_runningdriver"></td>
</tr>
</table>
</h3>
</div>
</div>
<!-- This begins the DRIVER MENU page ------------------------------------------------------------------->
<div data-role="page" id="drivermenu">
<div data-theme="a" data-role="header">
<div style="width: 100%; height: 120px; position: relative;">
<img src="images/logo-mame-small.png" alt="image" style="position: absolute; top: 50%; left: 50%; margin-left: -158px; margin-top: -50px">
</div>
<a data-role="button" href="#mainmenu" data-icon="home" data-iconpos="left" class="ui-btn-right">Home</a>
<div data-role="navbar" data-iconpos="top">
<ul>
<li>
<a href="#mainmenu" data-transition="fade" data-icon="home">Main Menu</a>
</li>
<li>
<a href="#optionmenu" data-transition="fade" data-icon="gear">Options</a>
</li>
<li>
<a href="#imagemenu" data-transition="fade" data-icon="grid">Image</a>
</li>
<li>
<a href="#commandmenu" data-transition="fade" data-icon="star">Commands</a>
</li>
</ul>
</div>
</div>
<div data-role="content" id="drivermenucontent">
</div>
<div data-theme="a" data-role="footer" data-position="fixed">
<div data-role="navbar" data-iconpos="top">
<ul>
<li>
<a href="#infomenu" data-transition="fade" data-icon="info">Info</a>
</li>
<li>
<a href="#logsmenu" data-transition="fade" data-icon="check">Logs</a>
</li>
<li>
<a href="javascript:takeScreenshot();" data-transition="fade" data-icon="search">Screenshot</a>
</li>
<li>
<a href="javascript:startWebSocket();" data-transition="fade" data-icon="refresh">Reconnect</a>
</li>
</ul>
</div>
<h3>
<table style="tablelayout: fixed; width: 100%; height: 10px; border-collapse:collapse;" border="0">
<tr>
<td style="width: 10%; padding: 0px;" id="driver_statusbar_connectionstatus"></td>
<td style="width: 10%; padding: 0px;" id="driver_statusbar_ispaused"></td>
<td style="width: 80%; padding: 0px;" id="driver_statusbar_runningdriver"></td>
</tr>
</table>
</h3>
</div>
</div>
<!-- This begins the IMAGE MENU page ------------------------------------------------------------------->
<div data-role="page" id="imagemenu">
<div data-theme="a" data-role="header">
<div style="width: 100%; height: 120px; position: relative;">
<img src="images/logo-mame-small.png" alt="image" style="position: absolute; top: 50%; left: 50%; margin-left: -158px; margin-top: -50px">
</div>
<a data-role="button" href="#mainmenu" data-icon="home" data-iconpos="left" class="ui-btn-right">Home</a>
<div data-role="navbar" data-iconpos="top">
<ul>
<li>
<a href="#drivermenu" data-transition="fade" data-icon="bars">Driver</a>
</li>
<li>
<a href="#optionmenu" data-transition="fade" data-icon="gear">Options</a>
</li>
<li>
<a href="#mainmenu" data-transition="fade" data-icon="home">Main Menu</a>
</li>
<li>
<a href="#commandmenu" data-transition="fade" data-icon="star">Commands</a>
</li>
</ul>
</div>
</div>
<div data-role="content" id="imagemenucontent">
</div>
<div data-theme="a" data-role="footer" data-position="fixed">
<div data-role="navbar" data-iconpos="top">
<ul>
<li>
<a href="#infomenu" data-transition="fade" data-icon="info">Info</a>
</li>
<li>
<a href="#logsmenu" data-transition="fade" data-icon="check">Logs</a>
</li>
<li>
<a href="javascript:takeScreenshot();" data-transition="fade" data-icon="search">Screenshot</a>
</li>
<li>
<a href="javascript:startWebSocket();" data-transition="fade" data-icon="refresh">Reconnect</a>
</li>
</ul>
</div>
<h3>
<table style="tablelayout: fixed; width: 100%; height: 10px; border-collapse:collapse;" border="0">
<tr>
<td style="width: 10%; padding: 0px;" id="image_statusbar_connectionstatus"></td>
<td style="width: 10%; padding: 0px;" id="image_statusbar_ispaused"></td>
<td style="width: 80%; padding: 0px;" id="image_statusbar_runningdriver"></td>
</tr>
</table>
</h3>
</div>
</div>
<!-- This begins the INFO MENU page ------------------------------------------------------------------->
<div data-role="page" id="infomenu">
<div data-theme="a" data-role="header">
<div style="width: 100%; height: 120px; position: relative;">
<img src="images/logo-mame-small.png" alt="image" style="position: absolute; top: 50%; left: 50%; margin-left: -158px; margin-top: -50px">
</div>
<a data-role="button" href="#mainmenu" data-icon="home" data-iconpos="left" class="ui-btn-right">Home</a>
<div data-role="navbar" data-iconpos="top">
<ul>
<li>
<a href="#drivermenu" data-transition="fade" data-icon="bars">Driver</a>
</li>
<li>
<a href="#optionmenu" data-transition="fade" data-icon="gear">Options</a>
</li>
<li>
<a href="#imagemenu" data-transition="fade" data-icon="grid">Image</a>
</li>
<li>
<a href="#commandmenu" data-transition="fade" data-icon="star">Commands</a>
</li>
</ul>
</div>
</div>
<div data-role="content" id="infomenucontent">
</div>
<div data-theme="a" data-role="footer" data-position="fixed">
<div data-role="navbar" data-iconpos="top">
<ul>
<li>
<a href="#mainmenu" data-transition="fade" data-icon="home">Main Menu</a>
</li>
<li>
<a href="#logsmenu" data-transition="fade" data-icon="check">Logs</a>
</li>
<li>
<a href="javascript:takeScreenshot();" data-transition="fade" data-icon="search">Screenshot</a>
</li>
<li>
<a href="javascript:startWebSocket();" data-transition="fade" data-icon="refresh">Reconnect</a>
</li>
</ul>
</div>
<h3>
<table style="tablelayout: fixed; width: 100%; height: 10px; border-collapse:collapse;" border="0">
<tr>
<td style="width: 10%; padding: 0px;" id="info_statusbar_connectionstatus"></td>
<td style="width: 10%; padding: 0px;" id="info_statusbar_ispaused"></td>
<td style="width: 80%; padding: 0px;" id="info_statusbar_runningdriver"></td>
</tr>
</table>
</h3>
</div>
</div>
<!-- This begins the LOGS MENU page ------------------------------------------------------------------->
<div data-role="page" id="logsmenu">
<div data-theme="a" data-role="header">
<div style="width: 100%; height: 120px; position: relative;">
<img src="images/logo-mame-small.png" alt="image" style="position: absolute; top: 50%; left: 50%; margin-left: -158px; margin-top: -50px">
</div>
<a data-role="button" href="#mainmenu" data-icon="home" data-iconpos="left" class="ui-btn-right">Home</a>
<div data-role="navbar" data-iconpos="top">
<ul>
<li>
<a href="#drivermenu" data-transition="fade" data-icon="bars">Driver</a>
</li>
<li>
<a href="#optionmenu" data-transition="fade" data-icon="gear">Options</a>
</li>
<li>
<a href="#imagemenu" data-transition="fade" data-icon="grid">Image</a>
</li>
<li>
<a href="#commandmenu" data-transition="fade" data-icon="star">Commands</a>
</li>
</ul>
</div>
</div>
<div data-role="content" id="logsmenucontent">
<p>Paste Upload Log</p> <!-- Yeah, this'll need reworking later. Still considering how this will work in the end. -->
<iframe name="uploadpastelog" width="250" height="250"></iframe>
</div>
<div data-theme="a" data-role="footer" data-position="fixed">
<div data-role="navbar" data-iconpos="top">
<ul>
<li>
<a href="#infomenu" data-transition="fade" data-icon="info">Info</a>
</li>
<li>
<a href="#mainmenu" data-transition="fade" data-icon="home">Main Menu</a>
</li>
<li>
<a href="javascript:takeScreenshot();" data-transition="fade" data-icon="search">Screenshot</a>
</li>
<li>
<a href="javascript:startWebSocket();" data-transition="fade" data-icon="refresh">Reconnect</a>
</li>
</ul>
</div>
<h3>
<table style="tablelayout: fixed; width: 100%; height: 10px; border-collapse:collapse;" border="0">
<tr>
<td style="width: 10%; padding: 0px;" id="logs_statusbar_connectionstatus"></td>
<td style="width: 10%; padding: 0px;" id="logs_statusbar_ispaused"></td>
<td style="width: 80%; padding: 0px;" id="logs_statusbar_runningdriver"></td>
</tr>
</table>
</h3>
</div>
</div>
<!-- This begins the EXIT dialog ---------------------------------------------------------------------->
<div data-role="dialog" id="dialogConfirmExit">
<div data-role="header">
<h1>Confirm: Exit emulator?</h1>
</div>
<a href="javascript:executeExit();" data-theme="a" data-role="button">Yes</a>
<a href="javascript:$('.ui-dialog').dialog('close');" data-role="button">Cancel</a>
</div>
<!-- This begins the HARD RESET dialog ---------------------------------------------------------------->
<div data-role="page" data-close-btn="none" id="dialogConfirmHardReset">
<div data-role="header">
<h1>Confirm: Hard Reset?</h1>
</div>
<a href="javascript:executeHardReset();" data-theme="a" data-role="button">Yes</a>
<a href="javascript:$('.ui-dialog').dialog('close');" data-role="button">Cancel</a>
</div>
<!-- This begins the SOFT RESET dialog ---------------------------------------------------------------->
<div data-role="page" data-close-btn="none" id="dialogConfirmSoftReset">
<div data-role="header">
<h1>Confirm: Soft Reset?</h1>
</div>
<a href="javascript:executeSoftReset();" data-theme="a" data-role="button">Yes</a>
<a href="javascript:$('.ui-dialog').dialog('close');" data-role="button">Cancel</a>
</div>
</body>
</html>

Some files were not shown because too many files have changed in this diff Show More