diff options
author | 2015-01-10 13:30:30 +0100 | |
---|---|---|
committer | 2015-01-10 13:30:30 +0100 | |
commit | 8556d0cdf7058be2c519bd4d8e7006ea9e913527 (patch) | |
tree | 09594058dc17564b4ff3c106581d0856cf69c2d5 /3rdparty/mongoose/examples/digest_authentication/digest_auth.c | |
parent | 61f7cd05dfed932dd1be927608a4989c187cc737 (diff) |
Added integral source of mongoose (nw)
Diffstat (limited to '3rdparty/mongoose/examples/digest_authentication/digest_auth.c')
-rw-r--r-- | 3rdparty/mongoose/examples/digest_authentication/digest_auth.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/3rdparty/mongoose/examples/digest_authentication/digest_auth.c b/3rdparty/mongoose/examples/digest_authentication/digest_auth.c new file mode 100644 index 00000000000..18835c729c7 --- /dev/null +++ b/3rdparty/mongoose/examples/digest_authentication/digest_auth.c @@ -0,0 +1,36 @@ +#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; +} |