[Openvas-commits] r12210 - in trunk/gsa: . src src/html

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Tue Nov 29 14:08:30 CET 2011


Author: mattm
Date: 2011-11-29 14:08:29 +0100 (Tue, 29 Nov 2011)
New Revision: 12210

Modified:
   trunk/gsa/ChangeLog
   trunk/gsa/src/gsad_omp.c
   trunk/gsa/src/html/omp.xsl
Log:
	Get the delete icons working on the result details page, for delta
	results.

	* src/gsad_omp.c (REQUIRE2): New macro.
	(get_result): Add the delta case.
	(delete_note_omp, delete_override_omp): Make param errors a bit nicer.
	Pass the delta params through to get_result.

	* src/html/omp.xsl (note-detailed-delete-params)
	(override-detailed-delete-params): Remove report_id.
	(note-detailed, override-detailed): Add delta handling to the get_result
	case.
	(get_result): Match get_reports_response too, because the delta result
	detail uses this.
	(get_delta_result): Add a result loop with a "commands_respons" prefix for
	the result details page.

Modified: trunk/gsa/ChangeLog
===================================================================
--- trunk/gsa/ChangeLog	2011-11-29 12:15:11 UTC (rev 12209)
+++ trunk/gsa/ChangeLog	2011-11-29 13:08:29 UTC (rev 12210)
@@ -1,3 +1,22 @@
+2011-11-29  Matthew Mundell <matthew.mundell at greenbone.net>
+
+	Get the delete icons working on the result details page, for delta
+	results.
+
+	* src/gsad_omp.c (REQUIRE2): New macro.
+	(get_result): Add the delta case.
+	(delete_note_omp, delete_override_omp): Make param errors a bit nicer.
+	Pass the delta params through to get_result.
+
+	* src/html/omp.xsl (note-detailed-delete-params)
+	(override-detailed-delete-params): Remove report_id.
+	(note-detailed, override-detailed): Add delta handling to the get_result
+	case.
+	(get_result): Match get_reports_response too, because the delta result
+	detail uses this.
+	(get_delta_result): Add a result loop with a "commands_respons" prefix for
+	the result details page.
+
 2011-11-28  Matthew Mundell <matthew.mundell at greenbone.net>
 
 	* src/html/omp.xsl (note-detailed-delete-params, note-detailed)

Modified: trunk/gsa/src/gsad_omp.c
===================================================================
--- trunk/gsa/src/gsad_omp.c	2011-11-29 12:15:11 UTC (rev 12209)
+++ trunk/gsa/src/gsad_omp.c	2011-11-29 13:08:29 UTC (rev 12210)
@@ -8444,6 +8444,16 @@
                          "\" was NULL.",                              \
                          "/omp?cmd=get_tasks")
 
+#define REQUIRE2(arg, backurl)                                        \
+  if (arg == NULL)                                                    \
+    return gsad_message (credentials,                                 \
+                         "Internal error", __FUNCTION__, __LINE__,    \
+                         "An internal error occurred."                \
+                         " Diagnostics: Required parameter \""        \
+                         G_STRINGIFY (arg)                            \
+                         "\" was NULL.",                              \
+                         backurl)
+
 /**
  * @brief Get one result, XSL transform the result.
  *
@@ -8519,9 +8529,14 @@
                              "/omp?cmd=get_results");
     }
 
-  xml = g_string_new ("<get_result>");
+  if (delta_report_id)
+    xml = g_string_new ("<get_delta_result>");
+  else
+    xml = g_string_new ("<get_result>");
 
+
   g_string_append_printf (xml,
+                          "<result id=\"%s\"/>"
                           "<task id=\"%s\"><name>%s</name></task>"
                           "<report id=\"%s\"/>"
                           "<delta><report id=\"%s\"/></delta>"
@@ -8546,6 +8561,7 @@
                           "<order>%s</order>"
                           "</field>"
                           "</sort>",
+                          result_id,
                           task_id,
                           task_name,
                           report_id,
@@ -8565,25 +8581,57 @@
 
   /* Get the result. */
 
-  if (openvas_server_sendf (&session,
-                            "<commands>"
-                            "%s"
-                            "<get_results"
-                            " result_id=\"%s\""
-                            " task_id=\"%s\""
-                            " apply_overrides=\"%s\""
-                            " overrides=\"%s\""
-                            " overrides_details=\"1\""
-                            " notes=\"1\""
-                            " notes_details=\"1\"/>"
-                            "</commands>",
-                            commands ? commands : "",
-                            result_id,
-                            task_id,
-                            apply_overrides,
-                            apply_overrides)
-      == -1)
+  if (delta_report_id)
     {
+      if (openvas_server_sendf (&session,
+                                "<commands>"
+                                "%s"
+                                "<get_reports"
+                                " report_id=\"%s\""
+                                " delta_report_id=\"%s\""
+                                " result_id=\"%s\""
+                                " apply_overrides=\"%s\""
+                                " overrides=\"%s\""
+                                " overrides_details=\"1\""
+                                " notes=\"1\""
+                                " notes_details=\"1\"/>"
+                                "</commands>",
+                                commands ? commands : "",
+                                report_id,
+                                delta_report_id,
+                                result_id,
+                                apply_overrides,
+                                apply_overrides)
+          == -1)
+        {
+          g_string_free (xml, TRUE);
+          openvas_server_close (socket, session);
+          return gsad_message (credentials,
+                               "Internal error", __FUNCTION__, __LINE__,
+                               "An internal error occurred while getting a result. "
+                               "Diagnostics: Failure to send command to manager daemon.",
+                               "/omp?cmd=get_results");
+        }
+    }
+  else if (openvas_server_sendf (&session,
+                                 "<commands>"
+                                 "%s"
+                                 "<get_results"
+                                 " result_id=\"%s\""
+                                 " task_id=\"%s\""
+                                 " apply_overrides=\"%s\""
+                                 " overrides=\"%s\""
+                                 " overrides_details=\"1\""
+                                 " notes=\"1\""
+                                 " notes_details=\"1\"/>"
+                                 "</commands>",
+                                 commands ? commands : "",
+                                 result_id,
+                                 task_id,
+                                 apply_overrides,
+                                 apply_overrides)
+           == -1)
+    {
       g_string_free (xml, TRUE);
       openvas_server_close (socket, session);
       return gsad_message (credentials,
@@ -8606,7 +8654,10 @@
 
   /* Cleanup, and return transformed XML. */
 
-  g_string_append (xml, "</get_result>");
+  if (delta_report_id)
+    g_string_append (xml, "</get_delta_result>");
+  else
+    g_string_append (xml, "</get_result>");
   openvas_server_close (socket, session);
   return xsl_transform_omp (credentials, g_string_free (xml, FALSE));
 }
@@ -9406,13 +9457,8 @@
   next = params_value (params, "next");
   note_id = params_value (params, "note_id");
 
-  if ((next == NULL) || (note_id == NULL))
-    return gsad_message (credentials,
-                         "Internal error", __FUNCTION__, __LINE__,
-                         "An internal error occurred while deleting a note. "
-                         "The note remains intact. "
-                         "Diagnostics: Required parameter was NULL.",
-                         "/omp?cmd=get_notes");
+  REQUIRE (next);
+  REQUIRE (note_id);
 
   if (strcmp (next, "get_report") == 0)
     {
@@ -9487,7 +9533,7 @@
       const char *sort_field, *sort_order, *levels, *notes, *overrides;
       const char *result_hosts_only, *search_phrase, *min_cvss_base, *task_id;
       const char *task_name, *result_id, *first_result, *max_results;
-      const char *report_id;
+      const char *report_id, *delta_report_id, *delta_states;
       gchar *extra;
       char *ret;
 
@@ -9495,6 +9541,8 @@
       first_result = params_value (params, "first_result");
       max_results = params_value (params, "max_results");
       result_id = params_value (params, "result_id");
+      delta_report_id = params_value (params, "delta_report_id");
+      delta_states = params_value (params, "delta_states");
       task_id = params_value (params, "task_id");
 
       overrides = params_value (params, "overrides");
@@ -9536,27 +9584,23 @@
       sort_field = params_value (params, "sort_field");
       sort_order = params_value (params, "sort_order");
 
+      REQUIRE2 (task_name, "/omp?cmd=get_notes");
+      REQUIRE2 (first_result, "/omp?cmd=get_notes");
+      REQUIRE2 (max_results, "/omp?cmd=get_notes");
+      REQUIRE2 (result_id, "/omp?cmd=get_notes");
+
       if (sscanf (first_result, "%u", &first) != 1)
         first_result = "1";
 
       if (sscanf (max_results, "%u", &max) != 1)
         max_results = G_STRINGIFY (RESULTS_PER_PAGE);
 
-      if (task_name == NULL || first_result == NULL || max_results == NULL
-          || result_id == NULL)
-        return gsad_message (credentials,
-                             "Internal error", __FUNCTION__, __LINE__,
-                             "An internal error occurred while deleting a note. "
-                             "The note remains intact. "
-                             "Diagnostics: Required parameter was NULL.",
-                             "/omp?cmd=get_notes");
-
       extra = g_strdup_printf ("<delete_note note_id=\"%s\"/>", note_id);
       ret = get_result (credentials, result_id, task_id, task_name,
                         overrides, extra, report_id, first_result,
                         max_results, levels, search_phrase, notes,
                         overrides, min_cvss_base, result_hosts_only,
-                        sort_field, sort_order, NULL, NULL);
+                        sort_field, sort_order, delta_report_id, delta_states);
       g_free (extra);
       return ret;
     }
@@ -10906,6 +10950,7 @@
       const char *sort_field, *sort_order, *levels, *notes, *overrides;
       const char *result_hosts_only, *search_phrase, *min_cvss_base, *task_id;
       const char *task_name, *result_id, *first_result, *max_results, *report_id;
+      const char *delta_report_id, *delta_states;
       gchar *extra;
       char *ret;
 
@@ -10913,6 +10958,8 @@
       first_result = params_value (params, "first_result");
       max_results = params_value (params, "max_results");
       result_id = params_value (params, "result_id");
+      delta_report_id = params_value (params, "delta_report_id");
+      delta_states = params_value (params, "delta_states");
       task_id = params_value (params, "task_id");
 
       overrides = params_value (params, "overrides");
@@ -10960,23 +11007,18 @@
       if (sscanf (max_results, "%u", &max) != 1)
         max_results = G_STRINGIFY (RESULTS_PER_PAGE);
 
-      if (task_name == NULL || first_result == NULL || max_results == NULL
-          || result_id == NULL)
-        return gsad_message (credentials,
-                             "Internal error", __FUNCTION__, __LINE__,
-                             "An internal error occurred while deleting an override. "
-                             "The override remains intact. "
-                             "Diagnostics: Required parameter was NULL.",
-                             "/omp?cmd=get_overrides");
+      REQUIRE (task_name);
+      REQUIRE (first_result);
+      REQUIRE (max_results);
+      REQUIRE (result_id);
 
-
       extra = g_strdup_printf ("<delete_override override_id=\"%s\"/>",
                                       override_id);
       ret = get_result (credentials, result_id, task_id, task_name,
                         overrides, extra, report_id, first_result,
                         max_results, levels, search_phrase, notes,
                         overrides, min_cvss_base, result_hosts_only,
-                        sort_field, sort_order, NULL, NULL);
+                        sort_field, sort_order, delta_report_id, delta_states);
       g_free (extra);
       return ret;
     }

Modified: trunk/gsa/src/html/omp.xsl
===================================================================
--- trunk/gsa/src/html/omp.xsl	2011-11-29 12:15:11 UTC (rev 12209)
+++ trunk/gsa/src/html/omp.xsl	2011-11-29 13:08:29 UTC (rev 12210)
@@ -11601,7 +11601,6 @@
 
 <xsl:template name="note-detailed-delete-params">
   <xsl:param name="base" select="."/>
-  <input type="hidden" name="report_id" value="{$base/@id}"/>
   <input type="hidden" name="first_result" value="{$base/results/@start}"/>
   <input type="hidden" name="max_results" value="{$base/results/@max}"/>
   <input type="hidden" name="levels" value="{$base/filters/text()}"/>
@@ -11650,27 +11649,48 @@
                    name="Delete" value="Delete" title="Delete"/>
             <xsl:choose>
               <xsl:when test="$next='get_result'">
-                <input type="hidden" name="result_id" value="{../../@id}"/>
-                <input type="hidden" name="task_id" value="{../../../../../../task/@id}"/>
-                <input type="hidden" name="name" value="{../../../../../../task/name}"/>
-                <input type="hidden" name="apply_overrides" value="{../../../../../../filters/apply_overrides}"/>
 
-                <input type="hidden" name="report_id" value="{../../../../../../report/@id}"/>
-                <input type="hidden" name="first_result" value="{../../../../../../results/@start}"/>
-                <input type="hidden" name="max_results" value="{../../../../../../results/@max}"/>
-                <input type="hidden" name="levels" value="{../../../../../../filters/text()}"/>
-                <input type="hidden" name="sort_field" value="{../../../../../../sort/field/text()}"/>
-                <input type="hidden" name="sort_order" value="{../../../../../../sort/field/order}"/>
-                <input type="hidden" name="search_phrase" value="{../../../../../../filters/phrase}"/>
-                <input type="hidden" name="min_cvss_base" value="{../../../../../../filters/min_cvss_base}"/>
-                <input type="hidden" name="apply_min_cvss_base" value="{number (string-length (../../../../../../filters/min_cvss_base) &gt; 0)}"/>
-                <input type="hidden" name="notes" value="{../../../../../../filters/notes}"/>
-                <input type="hidden" name="overrides" value="{../../../../../../filters/apply_overrides}"/>
-                <input type="hidden" name="result_hosts_only" value="{../../../../../../filters/result_hosts_only}"/>
+                <xsl:choose>
+                  <xsl:when test="$delta = 1">
+                    <input type="hidden" name="report_id" value="{../../../../../@id}"/>
+                    <input type="hidden" name="result_id" value="{../../@id}"/>
+                    <input type="hidden" name="task_id" value="{../../../../task/@id}"/>
+                    <input type="hidden" name="name" value="{../../../../task/name}"/>
+                    <input type="hidden" name="apply_overrides" value="{../../../../filters/apply_overrides}"/>
+                    <xsl:call-template name="override-detailed-delete-params">
+                      <xsl:with-param name="base" select="../../../../."/>
+                    </xsl:call-template>
+                    <input type="hidden" name="delta_report_id" value="{../../../../delta/report/@id}"/>
+                    <input type="hidden" name="delta_states" value="{../../../../filters/delta/text()}"/>
+                  </xsl:when>
+                  <xsl:when test="$delta = 2">
+                    <input type="hidden" name="report_id" value="{../../../../../@id}"/>
+                    <input type="hidden" name="result_id" value="{../../../@id}"/>
+                    <input type="hidden" name="task_id" value="{../../../../../task/@id}"/>
+                    <input type="hidden" name="name" value="{../../../../../task/name}"/>
+                    <input type="hidden" name="apply_overrides" value="{../../../../../filters/apply_overrides}"/>
+                    <xsl:call-template name="override-detailed-delete-params">
+                      <xsl:with-param name="base" select="../../../../../."/>
+                    </xsl:call-template>
+                    <input type="hidden" name="delta_report_id" value="{../../../../../delta/report/@id}"/>
+                    <input type="hidden" name="delta_states" value="{../../../../../filters/delta/text()}"/>
+                  </xsl:when>
+                  <xsl:otherwise>
+                    <input type="hidden" name="report_id" value="{../../../../../../report/@id}"/>
+                    <input type="hidden" name="result_id" value="{../../@id}"/>
+                    <input type="hidden" name="task_id" value="{../../../../../../task/@id}"/>
+                    <input type="hidden" name="name" value="{../../../../../../task/name}"/>
+                    <input type="hidden" name="apply_overrides" value="{../../../../../../filters/apply_overrides}"/>
+                    <xsl:call-template name="note-detailed-delete-params">
+                      <xsl:with-param name="base" select="../../../../../../."/>
+                    </xsl:call-template>
+                  </xsl:otherwise>
+                </xsl:choose>
               </xsl:when>
               <xsl:otherwise>
                 <xsl:choose>
                   <xsl:when test="$delta = 1">
+                    <input type="hidden" name="report_id" value="{../../../../@id}"/>
                     <xsl:call-template name="note-detailed-delete-params">
                       <xsl:with-param name="base" select="../../../../."/>
                     </xsl:call-template>
@@ -11678,6 +11698,7 @@
                     <input type="hidden" name="delta_states" value="{../../../../filters/delta/text()}"/>
                   </xsl:when>
                   <xsl:when test="$delta = 2">
+                    <input type="hidden" name="report_id" value="{../../../../../@id}"/>
                     <xsl:call-template name="note-detailed-delete-params">
                       <xsl:with-param name="base" select="../../../../../."/>
                     </xsl:call-template>
@@ -11685,6 +11706,7 @@
                     <input type="hidden" name="delta_states" value="{../../../../../filters/delta/text()}"/>
                   </xsl:when>
                   <xsl:otherwise>
+                    <input type="hidden" name="report_id" value="{../../../../@id}"/>
                     <xsl:call-template name="note-detailed-delete-params">
                       <xsl:with-param name="base" select="../../../../."/>
                     </xsl:call-template>
@@ -11737,7 +11759,6 @@
 
 <xsl:template name="override-detailed-delete-params">
   <xsl:param name="base" select="."/>
-  <input type="hidden" name="report_id" value="{$base/@id}"/>
   <input type="hidden" name="first_result" value="{$base/results/@start}"/>
   <input type="hidden" name="max_results" value="{$base/results/@max}"/>
   <input type="hidden" name="levels" value="{$base/filters/text()}"/>
@@ -11796,27 +11817,47 @@
                    name="Delete" value="Delete" title="Delete"/>
             <xsl:choose>
               <xsl:when test="$next='get_result'">
-                <input type="hidden" name="result_id" value="{../../@id}"/>
-                <input type="hidden" name="task_id" value="{../../../../../../task/@id}"/>
-                <input type="hidden" name="name" value="{../../../../../../task/name}"/>
-                <input type="hidden" name="apply_overrides" value="{../../../../../../filters/apply_overrides}"/>
-
-                <input type="hidden" name="report_id" value="{../../../../../../report/@id}"/>
-                <input type="hidden" name="first_result" value="{../../../../../../results/@start}"/>
-                <input type="hidden" name="max_results" value="{../../../../../../results/@max}"/>
-                <input type="hidden" name="levels" value="{../../../../../../filters/text()}"/>
-                <input type="hidden" name="sort_field" value="{../../../../../../sort/field/text()}"/>
-                <input type="hidden" name="sort_order" value="{../../../../../../sort/field/order}"/>
-                <input type="hidden" name="search_phrase" value="{../../../../../../filters/phrase}"/>
-                <input type="hidden" name="min_cvss_base" value="{../../../../../../filters/min_cvss_base}"/>
-                <input type="hidden" name="apply_min_cvss_base" value="{number (string-length (../../../../../../filters/min_cvss_base) &gt; 0)}"/>
-                <input type="hidden" name="notes" value="{../../../../../../filters/notes}"/>
-                <input type="hidden" name="overrides" value="{../../../../../../filters/apply_overrides}"/>
-                <input type="hidden" name="result_hosts_only" value="{../../../../../../filters/result_hosts_only}"/>
+                <xsl:choose>
+                  <xsl:when test="$delta = 1">
+                    <input type="hidden" name="report_id" value="{../../../../../@id}"/>
+                    <input type="hidden" name="result_id" value="{../../@id}"/>
+                    <input type="hidden" name="task_id" value="{../../../../task/@id}"/>
+                    <input type="hidden" name="name" value="{../../../../task/name}"/>
+                    <input type="hidden" name="apply_overrides" value="{../../../../filters/apply_overrides}"/>
+                    <xsl:call-template name="override-detailed-delete-params">
+                      <xsl:with-param name="base" select="../../../../."/>
+                    </xsl:call-template>
+                    <input type="hidden" name="delta_report_id" value="{../../../../delta/report/@id}"/>
+                    <input type="hidden" name="delta_states" value="{../../../../filters/delta/text()}"/>
+                  </xsl:when>
+                  <xsl:when test="$delta = 2">
+                    <input type="hidden" name="report_id" value="{../../../../../@id}"/>
+                    <input type="hidden" name="result_id" value="{../../../@id}"/>
+                    <input type="hidden" name="task_id" value="{../../../../../task/@id}"/>
+                    <input type="hidden" name="name" value="{../../../../../task/name}"/>
+                    <input type="hidden" name="apply_overrides" value="{../../../../../filters/apply_overrides}"/>
+                    <xsl:call-template name="override-detailed-delete-params">
+                      <xsl:with-param name="base" select="../../../../../."/>
+                    </xsl:call-template>
+                    <input type="hidden" name="delta_report_id" value="{../../../../../delta/report/@id}"/>
+                    <input type="hidden" name="delta_states" value="{../../../../../filters/delta/text()}"/>
+                  </xsl:when>
+                  <xsl:otherwise>
+                    <input type="hidden" name="report_id" value="{../../../../@id}"/>
+                    <input type="hidden" name="result_id" value="{../../@id}"/>
+                    <input type="hidden" name="task_id" value="{../../../../../../task/@id}"/>
+                    <input type="hidden" name="name" value="{../../../../../../task/name}"/>
+                    <input type="hidden" name="apply_overrides" value="{../../../../../../filters/apply_overrides}"/>
+                    <xsl:call-template name="override-detailed-delete-params">
+                      <xsl:with-param name="base" select="../../../../../../."/>
+                    </xsl:call-template>
+                  </xsl:otherwise>
+                </xsl:choose>
               </xsl:when>
               <xsl:otherwise>
                 <xsl:choose>
                   <xsl:when test="$delta = 1">
+                    <input type="hidden" name="report_id" value="{../../../../../@id}"/>
                     <xsl:call-template name="override-detailed-delete-params">
                       <xsl:with-param name="base" select="../../../../."/>
                     </xsl:call-template>
@@ -11824,6 +11865,7 @@
                     <input type="hidden" name="delta_states" value="{../../../../filters/delta/text()}"/>
                   </xsl:when>
                   <xsl:when test="$delta = 2">
+                    <input type="hidden" name="report_id" value="{../../../../../@id}"/>
                     <xsl:call-template name="override-detailed-delete-params">
                       <xsl:with-param name="base" select="../../../../../."/>
                     </xsl:call-template>
@@ -11831,6 +11873,7 @@
                     <input type="hidden" name="delta_states" value="{../../../../../filters/delta/text()}"/>
                   </xsl:when>
                   <xsl:otherwise>
+                    <input type="hidden" name="report_id" value="{../../../../@id}"/>
                     <xsl:call-template name="override-detailed-delete-params">
                       <xsl:with-param name="base" select="../../../../."/>
                     </xsl:call-template>
@@ -12384,6 +12427,7 @@
   <xsl:apply-templates select="gsad_msg"/>
   <xsl:apply-templates select="get_results_response"/>
   <xsl:apply-templates select="commands_response/get_results_response"/>
+  <xsl:apply-templates select="commands_response/get_reports_response"/>
 </xsl:template>
 
 <xsl:template match="get_delta_result">
@@ -12391,6 +12435,13 @@
   <xsl:variable name="task_id" select="task/@id"/>
   <xsl:variable name="task_name" select="task/name"/>
   <xsl:apply-templates select="gsad_msg"/>
+  <xsl:for-each select="commands_response/get_reports_response/report/report/results/result[@id=$result_id]">
+    <xsl:call-template name="result-details">
+      <xsl:with-param name="delta" select="1"/>
+      <xsl:with-param name="task_id" select="$task_id"/>
+      <xsl:with-param name="task_name" select="$task_name"/>
+    </xsl:call-template>
+  </xsl:for-each>
   <xsl:for-each select="get_reports_response/report/report/results/result[@id=$result_id]">
     <xsl:call-template name="result-details">
       <xsl:with-param name="delta" select="1"/>



More information about the Openvas-commits mailing list