mirror of
https://github.com/kakwa/uts-server
synced 2025-01-10 05:34:29 +01:00
better handling of error codes
This commit is contained in:
parent
bf2fc90e30
commit
1135fefb79
@ -134,10 +134,10 @@ int rfc3161_handler(struct mg_connection *conn, void *context) {
|
|||||||
log_hex(ct, LOG_DEBUG, "query hexdump content", (unsigned char *)query,
|
log_hex(ct, LOG_DEBUG, "query hexdump content", (unsigned char *)query,
|
||||||
request_info->content_length);
|
request_info->content_length);
|
||||||
|
|
||||||
int ts_resp = create_response(ct, query, query_len, ct->ts_ctx,
|
resp_code = create_response(ct, query, query_len, ct->ts_ctx,
|
||||||
&content_length, &content, &serial_id);
|
&content_length, &content, &serial_id);
|
||||||
if (ts_resp) {
|
switch (resp_code) {
|
||||||
resp_code = 200;
|
case 200:
|
||||||
mg_printf(conn,
|
mg_printf(conn,
|
||||||
"HTTP/1.1 200 OK\r\n"
|
"HTTP/1.1 200 OK\r\n"
|
||||||
"Content-Type: application/timestamp-reply\r\n"
|
"Content-Type: application/timestamp-reply\r\n"
|
||||||
@ -147,8 +147,16 @@ int rfc3161_handler(struct mg_connection *conn, void *context) {
|
|||||||
mg_write(conn, content, content_length);
|
mg_write(conn, content, content_length);
|
||||||
log_hex(ct, LOG_DEBUG, "response hexdump content", content,
|
log_hex(ct, LOG_DEBUG, "response hexdump content", content,
|
||||||
content_length);
|
content_length);
|
||||||
} else {
|
break;
|
||||||
resp_code = 500;
|
case 400:
|
||||||
|
mg_printf(conn,
|
||||||
|
"HTTP/1.1 400 Bad Request\r\n"
|
||||||
|
"Content-Type: text/plain\r\n"
|
||||||
|
"Content-Length: 12\r\n" // Always set Content-Length
|
||||||
|
"\r\n"
|
||||||
|
"client error");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
mg_printf(conn,
|
mg_printf(conn,
|
||||||
"HTTP/1.1 500 Internal Server Error\r\n"
|
"HTTP/1.1 500 Internal Server Error\r\n"
|
||||||
"Content-Type: text/plain\r\n"
|
"Content-Type: text/plain\r\n"
|
||||||
|
@ -263,44 +263,44 @@ end:
|
|||||||
uts_logger(ct, LOG_INFO,
|
uts_logger(ct, LOG_INFO,
|
||||||
"timestamp request granted (response serial '%s...')",
|
"timestamp request granted (response serial '%s...')",
|
||||||
*serial_id);
|
*serial_id);
|
||||||
ret = 1;
|
ret = 200;
|
||||||
break;
|
break;
|
||||||
case TS_STATUS_GRANTED_WITH_MODS:
|
case TS_STATUS_GRANTED_WITH_MODS:
|
||||||
uts_logger(ct, LOG_NOTICE, "timestamp request granted with "
|
uts_logger(ct, LOG_NOTICE, "timestamp request granted with "
|
||||||
"modification (response serial '%s...')",
|
"modification (response serial '%s...')",
|
||||||
*serial_id);
|
*serial_id);
|
||||||
ret = 1;
|
ret = 200;
|
||||||
break;
|
break;
|
||||||
case TS_STATUS_REJECTION:
|
case TS_STATUS_REJECTION:
|
||||||
uts_logger(ct, LOG_WARNING,
|
uts_logger(ct, LOG_WARNING,
|
||||||
"timestamp request rejected (response serial '%s...')",
|
"timestamp request rejected (response serial '%s...')",
|
||||||
*serial_id);
|
*serial_id);
|
||||||
ret = 0;
|
ret = 400;
|
||||||
break;
|
break;
|
||||||
case TS_STATUS_WAITING:
|
case TS_STATUS_WAITING:
|
||||||
uts_logger(ct, LOG_NOTICE,
|
uts_logger(ct, LOG_NOTICE,
|
||||||
"timestamp request waiting (response serial '%s...')",
|
"timestamp request waiting (response serial '%s...')",
|
||||||
*serial_id);
|
*serial_id);
|
||||||
ret = 0;
|
ret = 400;
|
||||||
break;
|
break;
|
||||||
case TS_STATUS_REVOCATION_WARNING:
|
case TS_STATUS_REVOCATION_WARNING:
|
||||||
uts_logger(
|
uts_logger(
|
||||||
ct, LOG_WARNING,
|
ct, LOG_WARNING,
|
||||||
"timestamp request revocation warning (response serial '%s...')",
|
"timestamp request revocation warning (response serial '%s...')",
|
||||||
*serial_id);
|
*serial_id);
|
||||||
ret = 0;
|
ret = 200;
|
||||||
break;
|
break;
|
||||||
case TS_STATUS_REVOCATION_NOTIFICATION:
|
case TS_STATUS_REVOCATION_NOTIFICATION:
|
||||||
uts_logger(ct, LOG_NOTICE, "timestamp request revovation notification "
|
uts_logger(ct, LOG_NOTICE, "timestamp request revovation notification "
|
||||||
"(response serial '%s...')",
|
"(response serial '%s...')",
|
||||||
*serial_id);
|
*serial_id);
|
||||||
ret = 0;
|
ret = 500;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
uts_logger(ct, LOG_ERR,
|
uts_logger(ct, LOG_ERR,
|
||||||
"unknown error code '%d' (response serial '%s...')", status,
|
"unknown error code '%d' (response serial '%s...')", status,
|
||||||
*serial_id);
|
*serial_id);
|
||||||
ret = 0;
|
ret = 500;
|
||||||
}
|
}
|
||||||
|
|
||||||
// log the openssl errors
|
// log the openssl errors
|
||||||
|
Loading…
x
Reference in New Issue
Block a user