[Openvas-commits] r8059 - in trunk/openvas-manager: . src

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Thu Jun 17 11:49:42 CEST 2010


Author: mattm
Date: 2010-06-17 11:49:37 +0200 (Thu, 17 Jun 2010)
New Revision: 8059

Modified:
   trunk/openvas-manager/ChangeLog
   trunk/openvas-manager/src/manage.h
   trunk/openvas-manager/src/manage_sql.c
   trunk/openvas-manager/src/omp.c
Log:
	* src/manage_sql.c (create_note): Add note return arg.

	* src/manage.h: Update headers accordingly.

	* src/omp.c (omp_xml_handle_end_element): In CLIENT_CREATE_NOTE include
	ID in response.

Modified: trunk/openvas-manager/ChangeLog
===================================================================
--- trunk/openvas-manager/ChangeLog	2010-06-17 09:27:43 UTC (rev 8058)
+++ trunk/openvas-manager/ChangeLog	2010-06-17 09:49:37 UTC (rev 8059)
@@ -1,5 +1,14 @@
 2010-06-17  Matthew Mundell <matthew.mundell at greenbone.net>
 
+	* src/manage_sql.c (create_note): Add note return arg.
+
+	* src/manage.h: Update header accordingly.
+
+	* src/omp.c (omp_xml_handle_end_element): In CLIENT_CREATE_NOTE include
+	ID in response.
+
+2010-06-17  Matthew Mundell <matthew.mundell at greenbone.net>
+
 	* src/omp.c (XML_OK_CREATED_ID): Drop create prefix.
 	(omp_xml_handle_end_element): In CLIENT_CREATE_AGENT add create prefix.
 

Modified: trunk/openvas-manager/src/manage.h
===================================================================
--- trunk/openvas-manager/src/manage.h	2010-06-17 09:27:43 UTC (rev 8058)
+++ trunk/openvas-manager/src/manage.h	2010-06-17 09:49:37 UTC (rev 8059)
@@ -1156,12 +1156,15 @@
 
 int
 create_note (const char*, const char*, const char*, const char*, const char*,
-             task_t, result_t);
+             task_t, result_t, note_t*);
 
 int
 delete_note (note_t);
 
 int
+note_uuid (note_t, char **);
+
+int
 modify_note (note_t, const char*, const char*, const char*, const char*,
              task_t, result_t);
 

Modified: trunk/openvas-manager/src/manage_sql.c
===================================================================
--- trunk/openvas-manager/src/manage_sql.c	2010-06-17 09:27:43 UTC (rev 8058)
+++ trunk/openvas-manager/src/manage_sql.c	2010-06-17 09:49:37 UTC (rev 8059)
@@ -13031,16 +13031,16 @@
  * @param[in]  threat      Threat to apply note to, "" or NULL for any threat.
  * @param[in]  task        Task to apply note to, 0 for any task.
  * @param[in]  result      Result to apply note to, 0 for any result.
+ * @param[out] note        Created note.
  *
  * @return 0 success, -1 error.
  */
 int
 create_note (const char* nvt, const char* text, const char* hosts,
              const char* port, const char* threat, task_t task,
-             result_t result)
+             result_t result, note_t *note)
 {
   gchar *quoted_text, *quoted_hosts, *quoted_port, *quoted_threat;
-  char *uuid;
 
   if (nvt == NULL)
     return -1;
@@ -13053,10 +13053,6 @@
       && strcmp (threat, "Debug") && strcmp (threat, ""))
     return -1;
 
-  uuid = openvas_uuid_make ();
-  if (uuid == NULL)
-    return -1;
-
   quoted_text = sql_insert (text);
   quoted_hosts = sql_insert (hosts);
   quoted_port = sql_insert (port);
@@ -13067,9 +13063,8 @@
        " (uuid, owner, nvt, creation_time, modification_time, text, hosts,"
        "  port, threat, task, result)"
        " VALUES"
-       " ('%s', (SELECT ROWID FROM users WHERE users.uuid = '%s'),"
+       " (make_uuid (), (SELECT ROWID FROM users WHERE users.uuid = '%s'),"
        "  '%s', %i, %i, %s, %s, %s, %s, %llu, %llu);",
-       uuid,
        current_credentials.uuid,
        nvt,
        time (NULL),
@@ -13081,12 +13076,14 @@
        task,
        result);
 
-  free (uuid);
   g_free (quoted_text);
   g_free (quoted_hosts);
   g_free (quoted_port);
   g_free (quoted_threat);
 
+  if (note)
+    *note = sqlite3_last_insert_rowid (task_db);
+
   return 0;
 }
 
@@ -13105,6 +13102,23 @@
 }
 
 /**
+ * @brief Return the UUID of a note.
+ *
+ * @param[in]   note  Note.
+ * @param[out]  id    Pointer to a newly allocated string.
+ *
+ * @return 0.
+ */
+int
+note_uuid (note_t note, char ** id)
+{
+  *id = sql_string (0, 0,
+                    "SELECT uuid FROM notes WHERE ROWID = %llu;",
+                    note);
+  return 0;
+}
+
+/**
  * @brief Modify a note.
  *
  * @param[in]  note        Note.

Modified: trunk/openvas-manager/src/omp.c
===================================================================
--- trunk/openvas-manager/src/omp.c	2010-06-17 09:27:43 UTC (rev 8058)
+++ trunk/openvas-manager/src/omp.c	2010-06-17 09:49:37 UTC (rev 8059)
@@ -10389,6 +10389,7 @@
         {
           task_t task = 0;
           result_t result = 0;
+          note_t new_note;
 
           assert (strcasecmp ("CREATE_NOTE", element_name) == 0);
 
@@ -10432,11 +10433,18 @@
                                     create_note_data->port,
                                     create_note_data->threat,
                                     task,
-                                    result))
+                                    result,
+                                    &new_note))
             {
               case 0:
-                SENDF_TO_CLIENT_OR_FAIL (XML_OK_CREATED ("create_note"));
-                break;
+                {
+                  char *uuid;
+                  note_uuid (new_note, &uuid);
+                  SENDF_TO_CLIENT_OR_FAIL (XML_OK_CREATED_ID ("create_note"),
+                                           uuid);
+                  free (uuid);
+                  break;
+                }
               case -1:
                 SEND_TO_CLIENT_OR_FAIL
                  (XML_INTERNAL_ERROR ("create_note"));



More information about the Openvas-commits mailing list