From cfccc8f05c8b2cb586d9df90a6fb2ac746e017ef Mon Sep 17 00:00:00 2001 From: Bram Matthys Date: Fri, 6 Aug 2021 09:24:24 +0200 Subject: [PATCH] Add $client.servername. Also add json_string_possibly_null() which is a wrapper that will return a 'null' JSON object for null strings and otherwise a string object for non-NULL. It seems by default this is not the case which is a bit annoying. Maybe we should re-wrap all code to use this. We'll see. The problem is when this is not done, then a $variable won't be expanded and would show up like literally "$variable" as if the variable was never passed on. --- src/log.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/log.c b/src/log.c index bad61bfd0..f50714226 100644 --- a/src/log.c +++ b/src/log.c @@ -32,6 +32,13 @@ long log_to_snomask(LogLevel loglevel, char *subsystem, char *event_id); void do_unreal_log_internal(LogLevel loglevel, char *subsystem, char *event_id, Client *client, int expand_msg, char *msg, va_list vl); +json_t *json_string_possibly_null(char *s) +{ + if (s) + return json_string(s); + return json_null(); +} + LogType log_type_stringtoval(char *str) { if (!strcmp(str, "json")) @@ -226,7 +233,7 @@ void json_expand_client(json_t *j, char *key, Client *client, int detail) else json_object_set_new(child, "host", json_string(GetIP(client))); - json_object_set_new(child, "ip", json_string(GetIP(client))); + json_object_set_new(child, "ip", json_string_possibly_null(client->ip)); if (client->user) { @@ -242,6 +249,9 @@ void json_expand_client(json_t *j, char *key, Client *client, int detail) if (*client->info) json_object_set_new(child, "info", json_string(client->info)); + if (client->srvptr && client->srvptr->name) + json_object_set_new(child, "servername", json_string(client->srvptr->name)); + if (IsLoggedIn(client)) json_object_set_new(child, "account", json_string(client->user->svid)); }