From 4498a11ab5273f0783cb3f7ad1ddeea3f35d50c1 Mon Sep 17 00:00:00 2001 From: Andrew Pamment Date: Sun, 21 Aug 2016 08:01:23 +1000 Subject: [PATCH] add www logging --- bbs.h | 1 + main.c | 2 +- www.c | 11 +++++++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/bbs.h b/bbs.h index 0e6951c..a5eb0c7 100644 --- a/bbs.h +++ b/bbs.h @@ -227,6 +227,7 @@ extern void chomp(char *string); #if defined(ENABLE_WWW) extern void www_init(); +extern void *www_logger(void * cls, const char * uri, struct MHD_Connection *con); extern void www_request_completed(void *cls, struct MHD_Connection *connection, void **con_cls, enum MHD_RequestTerminationCode toe); extern int www_handler(void * cls, struct MHD_Connection * connection, const char * url, const char * method, const char * version, const char * upload_data, size_t * upload_data_size, void ** ptr); extern char *www_email_summary(struct user_record *user); diff --git a/main.c b/main.c index f80ee29..2530d72 100644 --- a/main.c +++ b/main.c @@ -697,7 +697,7 @@ void server(int port) { #if defined(ENABLE_WWW) if (conf.www_server && conf.www_path != NULL) { www_init(); - www_daemon = MHD_start_daemon(MHD_USE_SELECT_INTERNALLY, conf.www_port, NULL, NULL, &www_handler, NULL, MHD_OPTION_NOTIFY_COMPLETED, &www_request_completed, NULL, MHD_OPTION_END); + www_daemon = MHD_start_daemon(MHD_USE_SELECT_INTERNALLY, conf.www_port, NULL, NULL, &www_handler, NULL, MHD_OPTION_NOTIFY_COMPLETED, &www_request_completed, NULL, MHD_OPTION_URI_LOG_CALLBACK, &www_logger, NULL, MHD_OPTION_END); } #endif diff --git a/www.c b/www.c index 37c250f..2c1ace7 100644 --- a/www.c +++ b/www.c @@ -6,6 +6,8 @@ #include #include #include +#include +#include #include "bbs.h" #define GET 1 @@ -14,6 +16,7 @@ #define POSTBUFFERSIZE 65536 extern struct bbs_config conf; +extern char *ipaddress; struct mime_type { char *ext; @@ -33,6 +36,13 @@ struct connection_info_s { struct MHD_PostProcessor *pp; }; +void *www_logger(void * cls, const char * uri, struct MHD_Connection *con) { + struct sockaddr_in *so = (struct sockaddr_in *)MHD_get_connection_info(con, MHD_CONNECTION_INFO_CLIENT_ADDRESS)->client_addr; + ipaddress = strdup(inet_ntoa(so->sin_addr)); + dolog("%s", uri); + return NULL; +} + void www_request_completed(void *cls, struct MHD_Connection *connection, void **con_cls, enum MHD_RequestTerminationCode toe) { struct connection_info_s *con_info = *con_cls; int i; @@ -66,6 +76,7 @@ void www_request_completed(void *cls, struct MHD_Connection *connection, void ** free(con_info->url); free(con_info); + free(ipaddress); } static int iterate_post (void *coninfo_cls, enum MHD_ValueKind kind, const char *key, const char *filename, const char *content_type, const char *transfer_encoding, const char *data, uint64_t off, size_t size) {