mirror of
https://github.com/kakwa/uts-server
synced 2025-01-09 21:24:29 +01:00
adding a context which will be passed from query to query
This commit is contained in:
parent
74f07cbd0e
commit
355d32c585
9
inc/context.h
Normal file
9
inc/context.h
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stddef.h> /* for offsetof() macro */
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint64_t query_counter;
|
||||||
|
} rfc3161_context;
|
@ -1 +1,3 @@
|
|||||||
|
#include "context.h"
|
||||||
|
|
||||||
int http_server_start();
|
int http_server_start();
|
||||||
|
@ -11,8 +11,10 @@
|
|||||||
#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 "utils.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) {
|
||||||
@ -61,8 +63,9 @@ static int begin_request_handler(struct mg_connection *conn) {
|
|||||||
int rfc3161_handler(struct mg_connection *conn, void *context) {
|
int rfc3161_handler(struct mg_connection *conn, void *context) {
|
||||||
/* Handler may access the request info using mg_get_request_info */
|
/* Handler may access the request info using mg_get_request_info */
|
||||||
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;
|
||||||
int ret;
|
int ret;
|
||||||
log_request_debug(request_info, 42);
|
log_request_debug(request_info, ct->query_counter);
|
||||||
|
|
||||||
bool is_tsq = 0;
|
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");
|
"uts-server, a simple RFC 3161 timestamp server");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ct->query_counter++;
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,11 +113,12 @@ int http_server_start() {
|
|||||||
// Prepare callbacks structure. We have only one callback, the rest are
|
// Prepare callbacks structure. We have only one callback, the rest are
|
||||||
// NULL.
|
// NULL.
|
||||||
memset(&callbacks, 0, sizeof(callbacks));
|
memset(&callbacks, 0, sizeof(callbacks));
|
||||||
callbacks.begin_request = begin_request_handler;
|
//callbacks.begin_request = begin_request_handler;
|
||||||
|
|
||||||
// Start the web server.
|
// Start the web server.
|
||||||
ctx = mg_start(&callbacks, NULL, options);
|
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.
|
// Wait until user hits "enter". Server is running in separate thread.
|
||||||
// Navigating to http://localhost:8080 will invoke begin_request_handler().
|
// Navigating to http://localhost:8080 will invoke begin_request_handler().
|
||||||
@ -120,6 +126,7 @@ int http_server_start() {
|
|||||||
|
|
||||||
// Stop the server.
|
// Stop the server.
|
||||||
mg_stop(ctx);
|
mg_stop(ctx);
|
||||||
|
free(ct);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user