diff --git a/inc/utils.h b/inc/utils.h index 961936d..e2a9e87 100644 --- a/inc/utils.h +++ b/inc/utils.h @@ -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; diff --git a/src/lib/http.c b/src/lib/http.c index e43ea64..9565411 100644 --- a/src/lib/http.c +++ b/src/lib/http.c @@ -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. diff --git a/src/lib/utils.c b/src/lib/utils.c index 6699cb2..6bb717e 100644 --- a/src/lib/utils.c +++ b/src/lib/utils.c @@ -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 ""; + 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.