2014-01-14 01:58:14 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include "mongoose.h"
|
|
|
|
|
2014-01-25 04:49:57 +08:00
|
|
|
static int auth_handler(struct mg_connection *conn) {
|
|
|
|
int result = 0; // Not authorized
|
|
|
|
FILE *fp;
|
2014-01-14 01:58:14 +08:00
|
|
|
|
|
|
|
// To populate passwords file, do
|
|
|
|
// mongoose -A my_passwords.txt mydomain.com admin admin
|
2014-01-25 04:49:57 +08:00
|
|
|
if ((fp = fopen("my_passwords.txt", "r")) != NULL) {
|
|
|
|
result = mg_authorize_digest(conn, fp);
|
2014-01-14 01:58:14 +08:00
|
|
|
fclose(fp);
|
|
|
|
}
|
|
|
|
|
2014-01-25 04:49:57 +08:00
|
|
|
return result;
|
2014-01-14 01:58:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(void) {
|
|
|
|
struct mg_server *server = mg_create_server(NULL);
|
|
|
|
mg_set_option(server, "listening_port", "8080");
|
2014-01-25 04:49:57 +08:00
|
|
|
mg_set_option(server, "document_root", ".");
|
|
|
|
mg_set_auth_handler(server, auth_handler);
|
2014-01-14 01:58:14 +08:00
|
|
|
|
|
|
|
printf("Starting on port %s\n", mg_get_option(server, "listening_port"));
|
|
|
|
for (;;) {
|
|
|
|
mg_poll_server(server, 1000);
|
|
|
|
}
|
|
|
|
mg_destroy_server(&server);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|