开发者

Embedding Mongoose Web Server in C++

I just embedded the Mongoose Web Server into my C++ dll (just a single header and recommended in most of the stack overflow threads) and I have it up and running properly with the very minimal example code.

However, I am having a rough time finding any sort of tutorials, examples, etc. on configuring the very basic necessities of a web server. I need to figure out the following...

1) How to allow directory browsing

2 Is it possible to restrict download speeds on the files?

3) Is it possible to have a dynamic list of开发者_JS百科 IPs addresses allowed to download files?

4) How to allow the download of specific file extensions (.bz2 in this case) ANSWERED

5) How to bind to a specific IP Address ANSWERED

Most of the information I have found is in regards to using the pre-compiled binary release, so I am a bit stumped right now. Any help would be fantastic!


1) "enable_directory_listing" option

2) Not built into Mongoose (at least not the version I have, which is about 6 months old). [EDIT:] Newer versions of Mongoose support throttling download speed. From the manual...

Limit download speed for clients. throttle is a comma-separated list of key=value pairs, where key could be:

*                   limit speed for all connections
x.x.x.x/mask        limit speed for specified subnet
uri_prefix_pattern  limit speed for given URIs

The value is a floating-point number of bytes per second, optionally followed by a k or m character, meaning kilobytes and megabytes respectively. A limit of 0 means unlimited rate. The last matching rule wins. Examples:

*=1k,10.0.0.0/8=0   limit all accesses to 1 kilobyte per second,
                    but give connections from 10.0.0.0/8 subnet
                    unlimited speed

/downloads/=5k      limit accesses to all URIs in `/downloads/` to
                    5 kilobytes per secods. All other accesses are unlimited

3) "access_control_list" option. In the code accept_new_connection calls check_acl that compares the client's IP to a list of IPs to accept and/or ignore. From the manual...

Specify access control list (ACL). ACL is a comma separated list of IP subnets, each subnet is prepended by '-' or '+' sign. Plus means allow, minus means deny. If subnet mask is omitted, like "-1.2.3.4", then it means single IP address. Mask may vary from 0 to 32 inclusive. On each request, full list is traversed, and last match wins. Default setting is to allow all. For example, to allow only 192.168/16 subnet to connect, run "mongoose -0.0.0.0/0,+192.168/16". Default: ""

http://code.google.com/p/mongoose/wiki/MongooseManual


Of course as soon as I give up and post, I find most of the answers were right in front of my face. Here is the options for them...

const char *options[] =
{
    "document_root", "C:/",
    "listening_ports", "127.0.0.1:8080",
    "extra_mime_types", ".bz2=plain/text",
    NULL
};

However, I am still not sure how to make enable directory browsing. Right now, my callback function is just the basic one out of the example (as seen below). What would I need to do to get it so the files are listed?

static void *callback(enum mg_event event, struct mg_connection *conn, const struct mg_request_info *request_info)
{
    if (event == MG_NEW_REQUEST)
    {
        // Echo requested URI back to the client
        mg_printf(conn, "HTTP/1.1 200 OK\r\n"
            "Content-Type: text/plain\r\n\r\n"
            "%s", request_info->uri);

        return "";  // Mark as processed
    }
    else
    {
        return NULL;
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜