mirror of
https://github.com/kakwa/uts-server
synced 2025-01-10 05:34:29 +01:00
pass context to the logging function
This commit is contained in:
parent
355d32c585
commit
63739e858f
@ -2,8 +2,9 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stddef.h> /* for offsetof() macro */
|
#include <stddef.h> /* for offsetof() macro */
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <openssl/ts.h>
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint64_t query_counter;
|
uint64_t query_counter;
|
||||||
|
TS_RESP_CTX *resp_ctx;
|
||||||
} rfc3161_context;
|
} rfc3161_context;
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
#include "context.h"
|
#include "utils.h"
|
||||||
|
#include "rfc3161.h"
|
||||||
|
|
||||||
int http_server_start();
|
int http_server_start();
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include "utils.h"
|
|
||||||
#include <sys/syslog.h>
|
#include <sys/syslog.h>
|
||||||
#include <openssl/bio.h>
|
#include <openssl/bio.h>
|
||||||
#include <openssl/err.h>
|
#include <openssl/err.h>
|
||||||
|
@ -1,2 +1,4 @@
|
|||||||
|
#include "context.h"
|
||||||
|
|
||||||
void skeleton_daemon();
|
void skeleton_daemon();
|
||||||
void logger(int priority, char *fmt, ...);
|
void logger(rfc3161_context *ct, int priority, char *fmt, ...);
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
#include <argp.h>
|
#include <argp.h>
|
||||||
#include <sys/syslog.h>
|
#include <sys/syslog.h>
|
||||||
#include "utils.h"
|
|
||||||
#include "rfc3161.h"
|
#include "rfc3161.h"
|
||||||
#include "http.h"
|
#include "http.h"
|
||||||
|
|
||||||
|
@ -12,41 +12,38 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <sys/syslog.h>
|
#include <sys/syslog.h>
|
||||||
#include "utils.h"
|
#include "http.h"
|
||||||
#include "context.h"
|
|
||||||
#include "rfc3161.h"
|
|
||||||
|
|
||||||
void log_request_debug(const struct mg_request_info *request_info,
|
void log_request_debug(const struct mg_request_info *request_info,
|
||||||
int request_id) {
|
int request_id, void *context) {
|
||||||
for (int i = 0; i < request_info->num_headers; i++) {
|
for (int i = 0; i < request_info->num_headers; i++) {
|
||||||
logger(LOG_DEBUG, "Request[%d], Header[%s]: %s\n", request_id,
|
logger(context, LOG_DEBUG, "Request[%d], Header[%s]: %s\n", request_id,
|
||||||
request_info->http_headers[i].name,
|
request_info->http_headers[i].name,
|
||||||
request_info->http_headers[i].value);
|
request_info->http_headers[i].value);
|
||||||
}
|
}
|
||||||
logger(LOG_DEBUG, "Request[%d], request_method: %s\n", request_id,
|
logger(context, LOG_DEBUG, "Request[%d], request_method: %s\n", request_id,
|
||||||
request_info->request_method);
|
request_info->request_method);
|
||||||
logger(LOG_DEBUG, "Request[%d], request_uri: %s\n", request_id,
|
logger(context, LOG_DEBUG, "Request[%d], request_uri: %s\n", request_id,
|
||||||
request_info->request_uri);
|
request_info->request_uri);
|
||||||
logger(LOG_DEBUG, "Request[%d], local_uri: %s\n", request_id,
|
logger(context, LOG_DEBUG, "Request[%d], local_uri: %s\n", request_id,
|
||||||
request_info->local_uri);
|
request_info->local_uri);
|
||||||
logger(LOG_DEBUG, "Request[%d], http_version: %s\n", request_id,
|
logger(context, LOG_DEBUG, "Request[%d], http_version: %s\n", request_id,
|
||||||
request_info->http_version);
|
request_info->http_version);
|
||||||
logger(LOG_DEBUG, "Request[%d], query_string: %s\n", request_id,
|
logger(context, LOG_DEBUG, "Request[%d], query_string: %s\n", request_id,
|
||||||
request_info->query_string);
|
request_info->query_string);
|
||||||
logger(LOG_DEBUG, "Request[%d], remote_addr: %s\n", request_id,
|
logger(context, LOG_DEBUG, "Request[%d], remote_addr: %s\n", request_id,
|
||||||
request_info->remote_addr);
|
request_info->remote_addr);
|
||||||
logger(LOG_DEBUG, "Request[%d], is_ssl: %d\n", request_id,
|
logger(context, LOG_DEBUG, "Request[%d], is_ssl: %d\n", request_id,
|
||||||
request_info->is_ssl);
|
request_info->is_ssl);
|
||||||
logger(LOG_DEBUG, "Request[%d], content_length: %d\n", request_id,
|
logger(context, LOG_DEBUG, "Request[%d], content_length: %d\n", request_id,
|
||||||
request_info->content_length);
|
request_info->content_length);
|
||||||
logger(LOG_DEBUG, "Request[%d], remote_port: %d\n", request_id,
|
logger(context, LOG_DEBUG, "Request[%d], remote_port: %d\n", request_id,
|
||||||
request_info->remote_port);
|
request_info->remote_port);
|
||||||
}
|
}
|
||||||
|
|
||||||
// This function will be called by civetweb on every new request.
|
// This function will be called by civetweb on every new request.
|
||||||
static int begin_request_handler(struct mg_connection *conn) {
|
static int begin_request_handler(struct mg_connection *conn) {
|
||||||
const struct mg_request_info *request_info = mg_get_request_info(conn);
|
const struct mg_request_info *request_info = mg_get_request_info(conn);
|
||||||
log_request_debug(request_info, 0);
|
|
||||||
|
|
||||||
mg_printf(conn,
|
mg_printf(conn,
|
||||||
"HTTP/1.1 200 OK\r\n"
|
"HTTP/1.1 200 OK\r\n"
|
||||||
@ -65,7 +62,9 @@ int rfc3161_handler(struct mg_connection *conn, void *context) {
|
|||||||
const struct mg_request_info *request_info = mg_get_request_info(conn);
|
const struct mg_request_info *request_info = mg_get_request_info(conn);
|
||||||
rfc3161_context *ct = (rfc3161_context *)context;
|
rfc3161_context *ct = (rfc3161_context *)context;
|
||||||
int ret;
|
int ret;
|
||||||
log_request_debug(request_info, ct->query_counter);
|
ct->query_counter++;
|
||||||
|
uint64_t query_id = ct->query_counter;
|
||||||
|
log_request_debug(request_info, query_id, ct);
|
||||||
|
|
||||||
bool is_tsq = 0;
|
bool is_tsq = 0;
|
||||||
|
|
||||||
@ -98,8 +97,6 @@ int rfc3161_handler(struct mg_connection *conn, void *context) {
|
|||||||
"uts-server, a simple RFC 3161 timestamp server");
|
"uts-server, a simple RFC 3161 timestamp server");
|
||||||
}
|
}
|
||||||
|
|
||||||
ct->query_counter++;
|
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,8 +5,8 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <syslog.h>
|
#include <syslog.h>
|
||||||
#include "utils.h"
|
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
#include "context.h"
|
||||||
|
|
||||||
void skeleton_daemon() {
|
void skeleton_daemon() {
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
@ -59,7 +59,7 @@ void skeleton_daemon() {
|
|||||||
openlog("firstdaemon", LOG_PID, LOG_DAEMON);
|
openlog("firstdaemon", LOG_PID, LOG_DAEMON);
|
||||||
}
|
}
|
||||||
|
|
||||||
void logger(int priority, char *fmt, ...) {
|
void logger(rfc3161_context *ct, int priority, char *fmt, ...) {
|
||||||
FILE *stream;
|
FILE *stream;
|
||||||
char *out;
|
char *out;
|
||||||
size_t len;
|
size_t len;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user