add www logging

This commit is contained in:
Andrew Pamment 2016-08-21 08:01:23 +10:00
parent 19440f3654
commit 4498a11ab5
3 changed files with 13 additions and 1 deletions

1
bbs.h
View File

@ -227,6 +227,7 @@ extern void chomp(char *string);
#if defined(ENABLE_WWW) #if defined(ENABLE_WWW)
extern void www_init(); 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 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 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); extern char *www_email_summary(struct user_record *user);

2
main.c
View File

@ -697,7 +697,7 @@ void server(int port) {
#if defined(ENABLE_WWW) #if defined(ENABLE_WWW)
if (conf.www_server && conf.www_path != NULL) { if (conf.www_server && conf.www_path != NULL) {
www_init(); 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 #endif

11
www.c
View File

@ -6,6 +6,8 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
#include <b64/cdecode.h> #include <b64/cdecode.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include "bbs.h" #include "bbs.h"
#define GET 1 #define GET 1
@ -14,6 +16,7 @@
#define POSTBUFFERSIZE 65536 #define POSTBUFFERSIZE 65536
extern struct bbs_config conf; extern struct bbs_config conf;
extern char *ipaddress;
struct mime_type { struct mime_type {
char *ext; char *ext;
@ -33,6 +36,13 @@ struct connection_info_s {
struct MHD_PostProcessor *pp; 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) { 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; struct connection_info_s *con_info = *con_cls;
int i; int i;
@ -66,6 +76,7 @@ void www_request_completed(void *cls, struct MHD_Connection *connection, void **
free(con_info->url); free(con_info->url);
free(con_info); 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) { 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) {