digest_auth.c
Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <string.h>
00003 #include "mongoose.h"
00004 
00005 static int ev_handler(struct mg_connection *conn, enum mg_event ev) {
00006 
00007   if (ev == MG_AUTH) {
00008     int result = MG_FALSE; // Not authorized
00009     FILE *fp;
00010 
00011     // To populate passwords file, do
00012     // mongoose -A my_passwords.txt mydomain.com admin admin
00013     if ((fp = fopen("my_passwords.txt", "r")) != NULL) {
00014       result = mg_authorize_digest(conn, fp);
00015       fclose(fp);
00016     }
00017 
00018     return result;
00019   }
00020 
00021   return MG_FALSE;
00022 }
00023 
00024 int main(void) {
00025   struct mg_server *server = mg_create_server(NULL, ev_handler);
00026   mg_set_option(server, "listening_port", "8080");
00027   mg_set_option(server, "document_root", ".");
00028 
00029   printf("Starting on port %s\n", mg_get_option(server, "listening_port"));
00030   for (;;) {
00031     mg_poll_server(server, 1000);
00032   }
00033   mg_destroy_server(&server);
00034 
00035   return 0;
00036 }


rc_visard_driver
Author(s): Heiko Hirschmueller , Christian Emmerich , Felix Ruess
autogenerated on Thu Jun 6 2019 20:43:02