diff --git a/src/gmp_get.c b/src/gmp_get.c index 3cd3d5bc2..83938f7cf 100644 --- a/src/gmp_get.c +++ b/src/gmp_get.c @@ -406,7 +406,17 @@ send_get_common (const char *type, get_data_t *get, iterator_t *iterator, buffer_xml_append_printf (buffer, ""); } - tag_type = get->subtype ? get->subtype : get->type; + if (strcmp (type, "config") == 0) + tag_type = (strcmp (config_iterator_usage_type (iterator), "policy") == 0) + ? "policy" + : "config"; + else if (strcmp (type, "task") == 0) + tag_type = (strcmp (task_iterator_usage_type (iterator), "audit") == 0) + ? "audit" + : "task"; + else + tag_type = get->subtype ? get->subtype : get->type; + tag_count = resource_tag_count (tag_type, get_iterator_resource (iterator), 1); diff --git a/src/manage_sql.c b/src/manage_sql.c index e59f2fd45..c0f2833bd 100644 --- a/src/manage_sql.c +++ b/src/manage_sql.c @@ -29673,7 +29673,10 @@ print_report_xml_start (report_t report, report_t delta, task_t task, if (report) { - int tag_count = resource_tag_count ("report", report, 1); + const char *report_type = (strcmp (tsk_usage_type, "audit") == 0) + ? "audit_report" + : "report"; + int tag_count = resource_tag_count (report_type, report, 1); if (tag_count) { @@ -29751,7 +29754,11 @@ print_report_xml_start (report_t report, report_t delta, task_t task, target_t target; gchar *progress_xml; iterator_t tags; - int task_tag_count = resource_tag_count ("task", task, 1); + + const char *task_type = (strcmp (tsk_usage_type, "audit") == 0) + ? "audit" + : "task"; + int task_tag_count = resource_tag_count (task_type, task, 1); tsk_name = task_name (task); @@ -58183,24 +58190,35 @@ int resource_tag_count (const char* type, resource_t resource, int active_only) { int ret; + const char *parent_type; assert (type); assert (resource); + if (type_is_report_subtype (type)) + parent_type = "report"; + else if (type_is_task_subtype (type)) + parent_type = "task"; + else if (type_is_config_subtype (type)) + parent_type = "config"; + else + parent_type = type; + ret = sql_int ("SELECT count (id)" - " FROM tags" - " WHERE resource_type = '%s'" - " AND EXISTS" - " (SELECT * FROM tag_resources" - " WHERE tag = tags.id" - " AND resource = %llu" - " AND resource_location = %d" - " AND tags.resource_type = tag_resources.resource_type)" - " %s;", - type, - resource, - LOCATION_TABLE, - active_only ? "AND active=1": ""); + " FROM tags" + " WHERE resource_type = '%s'" + " AND EXISTS" + " (SELECT * FROM tag_resources" + " WHERE tag = tags.id" + " AND resource = %llu" + " AND resource_location = %d" + " AND tag_resources.resource_type = '%s')" + " %s;", + type, + resource, + LOCATION_TABLE, + parent_type, + active_only ? "AND active=1": ""); return ret; }