From 02417a11bf9658cef2c4d6820d3cacdf0e50ba2e Mon Sep 17 00:00:00 2001 From: Philipp Schafft Date: Sat, 5 Mar 2022 20:25:01 +0000 Subject: [PATCH 1/4] Feature: Added report XML helper for boolean values --- src/reportxml_helper.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/reportxml_helper.h b/src/reportxml_helper.h index a9f12a61..772a5173 100644 --- a/src/reportxml_helper.h +++ b/src/reportxml_helper.h @@ -17,6 +17,7 @@ void reportxml_helper_add_value(reportxml_node_t *parent, const char *type, cons #define reportxml_helper_add_value_string(parent,member,str) reportxml_helper_add_value((parent), "string", (member), (str)) #define reportxml_helper_add_value_enum(parent,member,str) reportxml_helper_add_value((parent), "enum", (member), (str)) +#define reportxml_helper_add_value_boolean(parent,member,value) reportxml_helper_add_value((parent), "boolean", (member), (value) ? "true" : "false") void reportxml_helper_add_value_int(reportxml_node_t *parent, const char *member, long long int val); void reportxml_helper_add_text(reportxml_node_t *parent, const char *definition, const char *text); From d30efd5842ea15557ad34e500873a385ea711c70 Mon Sep 17 00:00:00 2001 From: Philipp Schafft Date: Sat, 5 Mar 2022 20:30:32 +0000 Subject: [PATCH 2/4] Update: Do not report state=set when report XML value's value is NULL --- src/reportxml.c | 2 +- src/reportxml_helper.c | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/reportxml.c b/src/reportxml.c index 59b035a6..b2d52f35 100644 --- a/src/reportxml.c +++ b/src/reportxml.c @@ -134,7 +134,7 @@ static const struct nodeattr __attr_relative[1] = {{"relative", "iso static const struct nodeattr __attr_name[1] = {{"name", "CDATA", NULL, 1, NULL, {NULL}}}; static const struct nodeattr __attr_member[1] = {{"member", "CDATA", NULL, 0, NULL, {NULL}}}; static const struct nodeattr __attr_value[1] = {{"value", "CDATA", NULL, 0, NULL, {NULL}}}; -static const struct nodeattr __attr_state[1] = {{"state", NULL, "set", 1, NULL, {"declared", "set", "uninitialized", "missing", NULL}}}; +static const struct nodeattr __attr_state[1] = {{"state", NULL, "set", 1, NULL, {"declared", "set", "unset", "uninitialized", "missing", NULL}}}; static const struct nodeattr __attr_href[1] = {{"href", "URI", NULL, 0, NULL, {NULL}}}; static const struct nodeattr __attr_application[1] = {{"application", "URI", NULL, 1, NULL, {NULL}}}; static const struct nodeattr __attr__action_type[1] = {{"type", NULL, NULL, 1, NULL, {"retry", "choice", "see-other", "authenticate", "pay", "change-protocol", "slow-down", "ask-user", "ask-admin", "bug", NULL}}}; diff --git a/src/reportxml_helper.c b/src/reportxml_helper.c index f5ab5132..7a490cce 100644 --- a/src/reportxml_helper.c +++ b/src/reportxml_helper.c @@ -27,7 +27,11 @@ void reportxml_helper_add_value(reportxml_node_t *parent, const char *type, cons reportxml_node_set_attribute(value, "type", type); if (member) reportxml_node_set_attribute(value, "member", member); - reportxml_node_set_attribute(value, "value", str); + if (str) { + reportxml_node_set_attribute(value, "value", str); + } else { + reportxml_node_set_attribute(value, "state", "unset"); + } reportxml_node_add_child(parent, value); refobject_unref(value); } From 4210ab31db80576edd2dd06398c343b75c10c4e5 Mon Sep 17 00:00:00 2001 From: Philipp Schafft Date: Fri, 11 Mar 2022 11:31:43 +0000 Subject: [PATCH 3/4] Feature: Added reportxml_helper_add_value_flag() --- src/reportxml_helper.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/reportxml_helper.h b/src/reportxml_helper.h index 772a5173..470e37c9 100644 --- a/src/reportxml_helper.h +++ b/src/reportxml_helper.h @@ -18,6 +18,7 @@ void reportxml_helper_add_value(reportxml_node_t *parent, const char *type, cons #define reportxml_helper_add_value_string(parent,member,str) reportxml_helper_add_value((parent), "string", (member), (str)) #define reportxml_helper_add_value_enum(parent,member,str) reportxml_helper_add_value((parent), "enum", (member), (str)) #define reportxml_helper_add_value_boolean(parent,member,value) reportxml_helper_add_value((parent), "boolean", (member), (value) ? "true" : "false") +#define reportxml_helper_add_value_flag(parent,member,value) reportxml_helper_add_value((parent), "flag", (member), (value) ? "true" : "false") void reportxml_helper_add_value_int(reportxml_node_t *parent, const char *member, long long int val); void reportxml_helper_add_text(reportxml_node_t *parent, const char *definition, const char *text); From 13fadf2b5bd86f530deb14925e8ef279897f9d05 Mon Sep 17 00:00:00 2001 From: Philipp Schafft Date: Sun, 6 Mar 2022 17:34:34 +0000 Subject: [PATCH 4/4] Update: Split client_get_reportxml() report generation into client_get_empty_reportxml(), and client_add_empty_incident() --- src/client.c | 53 +++++++++++++++++++++++++++++++--------------------- src/client.h | 2 ++ 2 files changed, 34 insertions(+), 21 deletions(-) diff --git a/src/client.c b/src/client.c index 89c71f0b..f9eead46 100644 --- a/src/client.c +++ b/src/client.c @@ -794,34 +794,45 @@ reportxml_t *client_get_reportxml(const char *state_definition, const char *stat } if (!report) { - reportxml_node_t *rootnode, *incidentnode, *statenode; - - report = refobject_new(reportxml_t); - rootnode = reportxml_get_root_node(report); - incidentnode = reportxml_node_new(REPORTXML_NODE_TYPE_INCIDENT, NULL, NULL, NULL); - statenode = reportxml_node_new(REPORTXML_NODE_TYPE_STATE, NULL, state_definition, state_akindof); - - if (state_text) { - reportxml_node_t *textnode; - - textnode = reportxml_node_new(REPORTXML_NODE_TYPE_TEXT, NULL, NULL, NULL); - reportxml_node_set_content(textnode, state_text); - reportxml_node_add_child(statenode, textnode); - refobject_unref(textnode); - } - - reportxml_node_add_child(incidentnode, statenode); - reportxml_node_add_child(rootnode, incidentnode); - refobject_unref(statenode); - refobject_unref(incidentnode); - refobject_unref(rootnode); + report = client_get_empty_reportxml(); + refobject_unref(client_add_empty_incident(report, state_definition, state_akindof, state_text)); } + return report; +} + +reportxml_t *client_get_empty_reportxml(void) +{ + reportxml_t *report = refobject_new(reportxml_t); + client_get_reportxml__add_basic_stats(report); return report; } +reportxml_node_t *client_add_empty_incident(reportxml_t *report, const char *state_definition, const char *state_akindof, const char *state_text) +{ + reportxml_node_t *rootnode = reportxml_get_root_node(report); + reportxml_node_t *incidentnode = reportxml_node_new(REPORTXML_NODE_TYPE_INCIDENT, NULL, NULL, NULL); + reportxml_node_t *statenode = reportxml_node_new(REPORTXML_NODE_TYPE_STATE, NULL, state_definition, state_akindof);; + + if (state_text) { + reportxml_node_t *textnode; + + textnode = reportxml_node_new(REPORTXML_NODE_TYPE_TEXT, NULL, NULL, NULL); + reportxml_node_set_content(textnode, state_text); + reportxml_node_add_child(statenode, textnode); + refobject_unref(textnode); + } + + reportxml_node_add_child(incidentnode, statenode); + reportxml_node_add_child(rootnode, incidentnode); + refobject_unref(statenode); + refobject_unref(rootnode); + + return incidentnode; +} + admin_format_t client_get_admin_format_by_content_negotiation(client_t *client) { const char *pref; diff --git a/src/client.h b/src/client.h index 26049f0b..bd99d4a1 100644 --- a/src/client.h +++ b/src/client.h @@ -165,6 +165,8 @@ void client_send_redirect(client_t *client, const char *uuid, int status, const void client_send_reportxml(client_t *client, reportxml_t *report, document_domain_t domain, const char *xsl, admin_format_t admin_format_hint, int status, const char *location); void client_send_buffer(client_t *client, int status, const char *mediatype, const char *charset, const char *buffer, ssize_t len, const char *extra_headers); reportxml_t *client_get_reportxml(const char *state_definition, const char *state_akindof, const char *state_text); +reportxml_t *client_get_empty_reportxml(void); +reportxml_node_t *client_add_empty_incident(reportxml_t *report, const char *state_definition, const char *state_akindof, const char *state_text); admin_format_t client_get_admin_format_by_content_negotiation(client_t *client); int client_send_bytes (client_t *client, const void *buf, unsigned len); int client_read_bytes (client_t *client, void *buf, unsigned len);