mirror of
https://github.com/kakwa/uts-server
synced 2024-12-04 23:15:54 +01:00
add handling of NULL strings in logs
replace NULL char * by const char * "<undef>" in log messages as printf("%s", NULL) behavior is not formalized.
This commit is contained in:
parent
d3b0a2a99c
commit
84e015ec26
@ -16,6 +16,7 @@ void log_hex(rfc3161_context *ct, int priority, char *id,
|
||||
int set_params(rfc3161_context *ct, char *conf_file, char *conf_wd);
|
||||
static char *rand_string(char *str, size_t size);
|
||||
void free_uts_context(rfc3161_context *ct);
|
||||
const char *null_undef(const char * in);
|
||||
|
||||
// some global variable to handle signals
|
||||
int g_uts_sig_up;
|
||||
|
@ -54,20 +54,20 @@ void log_request_debug(const struct mg_request_info *request_info,
|
||||
for (int i = 0; i < request_info->num_headers; i++) {
|
||||
uts_logger(context, LOG_DEBUG, "Request[%s], Header[%s]: %s",
|
||||
request_id, request_info->http_headers[i].name,
|
||||
request_info->http_headers[i].value);
|
||||
null_undef(request_info->http_headers[i].value));
|
||||
}
|
||||
uts_logger(context, LOG_DEBUG, "Request[%s], request_method: %s",
|
||||
request_id, request_info->request_method);
|
||||
request_id, null_undef(request_info->request_method));
|
||||
uts_logger(context, LOG_DEBUG, "Request[%s], request_uri: %s", request_id,
|
||||
request_info->request_uri);
|
||||
null_undef(request_info->request_uri));
|
||||
uts_logger(context, LOG_DEBUG, "Request[%s], local_uri: %s", request_id,
|
||||
request_info->local_uri);
|
||||
null_undef(request_info->local_uri));
|
||||
uts_logger(context, LOG_DEBUG, "Request[%s], http_version: %s", request_id,
|
||||
request_info->http_version);
|
||||
null_undef(request_info->http_version));
|
||||
uts_logger(context, LOG_DEBUG, "Request[%s], query_string: %s", request_id,
|
||||
request_info->query_string);
|
||||
null_undef(request_info->query_string));
|
||||
uts_logger(context, LOG_DEBUG, "Request[%s], remote_addr: %s", request_id,
|
||||
request_info->remote_addr);
|
||||
null_undef(request_info->remote_addr));
|
||||
uts_logger(context, LOG_DEBUG, "Request[%s], is_ssl: %d", request_id,
|
||||
request_info->is_ssl);
|
||||
uts_logger(context, LOG_DEBUG, "Request[%s], content_length: %d",
|
||||
@ -97,9 +97,10 @@ void log_request(const struct mg_request_info *request_info, char *request_id,
|
||||
uts_logger(context, LOG_INFO, "Request[%s], remote_addr[%s] ssl[%d] "
|
||||
"uri[%s] http_resp_code[%d] duration[%d us] "
|
||||
"user-agent[%s] content-type[%s]",
|
||||
request_id, request_info->remote_addr, request_info->is_ssl,
|
||||
request_info->local_uri, response_code, timer, user_agent,
|
||||
content_type);
|
||||
request_id, null_undef(request_info->remote_addr),
|
||||
request_info->is_ssl, null_undef(request_info->local_uri),
|
||||
response_code, timer, null_undef(user_agent),
|
||||
null_undef(content_type));
|
||||
}
|
||||
|
||||
// This function will be called by civetweb on every new request.
|
||||
|
@ -202,6 +202,12 @@ void uts_logger(rfc3161_context *ct, int priority, char *fmt, ...) {
|
||||
free(out);
|
||||
}
|
||||
|
||||
const char *null_undef(const char * in){
|
||||
if(in == NULL)
|
||||
return "<undef>";
|
||||
return in;
|
||||
}
|
||||
|
||||
// OpenSSL file openner (use for opening the configuration file
|
||||
static BIO *bio_open_default(rfc3161_context *ct, const char *filename,
|
||||
int format) {
|
||||
@ -281,7 +287,7 @@ int set_params(rfc3161_context *ct, char *conf_file, char *conf_wd) {
|
||||
if (value == NULL) {
|
||||
uts_logger(ct, LOG_NOTICE,
|
||||
"configuration param['%s'] not set, using default: '%s'",
|
||||
name, default_value);
|
||||
name, null_undef(default_value));
|
||||
value = default_value;
|
||||
}
|
||||
switch (type) {
|
||||
@ -307,11 +313,11 @@ int set_params(rfc3161_context *ct, char *conf_file, char *conf_wd) {
|
||||
if (value == NULL) {
|
||||
uts_logger(ct, LOG_NOTICE,
|
||||
"configuration param['%s'] not set, using default: '%s'",
|
||||
name, default_value);
|
||||
name, null_undef(default_value));
|
||||
value = default_value;
|
||||
}
|
||||
uts_logger(ct, LOG_DEBUG, "configuration param['%s'] = '%s'", name,
|
||||
value);
|
||||
null_undef(value));
|
||||
switch (type) {
|
||||
// if it's an http (civetweb) option, put it in the http_options buffer
|
||||
// like civetweb is expected it.
|
||||
|
Loading…
Reference in New Issue
Block a user