mirror of
https://github.com/kakwa/uts-server
synced 2025-07-04 20:47:09 +02:00
adding a context which will be passed from query to query
This commit is contained in:
parent
b27d676148
commit
c982c6b405
3 changed files with 22 additions and 4 deletions
|
@ -11,8 +11,10 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
#include "utils.h"
|
||||
#include <sys/syslog.h>
|
||||
#include "utils.h"
|
||||
#include "context.h"
|
||||
#include "rfc3161.h"
|
||||
|
||||
void log_request_debug(const struct mg_request_info *request_info,
|
||||
int request_id) {
|
||||
|
@ -61,8 +63,9 @@ static int begin_request_handler(struct mg_connection *conn) {
|
|||
int rfc3161_handler(struct mg_connection *conn, void *context) {
|
||||
/* Handler may access the request info using mg_get_request_info */
|
||||
const struct mg_request_info *request_info = mg_get_request_info(conn);
|
||||
rfc3161_context *ct = (rfc3161_context *)context;
|
||||
int ret;
|
||||
log_request_debug(request_info, 42);
|
||||
log_request_debug(request_info, ct->query_counter);
|
||||
|
||||
bool is_tsq = 0;
|
||||
|
||||
|
@ -95,6 +98,8 @@ int rfc3161_handler(struct mg_connection *conn, void *context) {
|
|||
"uts-server, a simple RFC 3161 timestamp server");
|
||||
}
|
||||
|
||||
ct->query_counter++;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -108,11 +113,12 @@ int http_server_start() {
|
|||
// Prepare callbacks structure. We have only one callback, the rest are
|
||||
// NULL.
|
||||
memset(&callbacks, 0, sizeof(callbacks));
|
||||
callbacks.begin_request = begin_request_handler;
|
||||
//callbacks.begin_request = begin_request_handler;
|
||||
|
||||
// Start the web server.
|
||||
ctx = mg_start(&callbacks, NULL, options);
|
||||
mg_set_request_handler(ctx, "/", rfc3161_handler, (void *)NULL);
|
||||
rfc3161_context *ct = (rfc3161_context *)calloc(1, sizeof(rfc3161_context));
|
||||
mg_set_request_handler(ctx, "/", rfc3161_handler, (void *)ct);
|
||||
|
||||
// Wait until user hits "enter". Server is running in separate thread.
|
||||
// Navigating to http://localhost:8080 will invoke begin_request_handler().
|
||||
|
@ -120,6 +126,7 @@ int http_server_start() {
|
|||
|
||||
// Stop the server.
|
||||
mg_stop(ctx);
|
||||
free(ct);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue