[Openvas-commits] r5640 - in trunk/openvas-libraries: . omp

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Tue Oct 20 11:50:45 CEST 2009


Author: felix
Date: 2009-10-20 11:50:45 +0200 (Tue, 20 Oct 2009)
New Revision: 5640

Modified:
   trunk/openvas-libraries/ChangeLog
   trunk/openvas-libraries/omp/omp.c
   trunk/openvas-libraries/omp/omp.h
Log:
Moved omp related functions from openvas-client/openvas/comm.c module.

* omp/omp.c (omp_get_nvt_all, omp_get_nvt_feed_checksum,
omp_get_rules_503, omp_get_dependencies_503):
New. Moved from openvas-client/openvas/comm.c.

* omp/omp.h: Added protos for new methods.


Modified: trunk/openvas-libraries/ChangeLog
===================================================================
--- trunk/openvas-libraries/ChangeLog	2009-10-20 09:37:56 UTC (rev 5639)
+++ trunk/openvas-libraries/ChangeLog	2009-10-20 09:50:45 UTC (rev 5640)
@@ -1,3 +1,13 @@
+2009-10-20  Felix Wolfsteller <felix.wolfsteller at intevation.de>
+
+	Moved omp related functions from openvas-client/openvas/comm.c module.
+
+	* omp/omp.c (omp_get_nvt_all, omp_get_nvt_feed_checksum,
+	omp_get_rules_503, omp_get_dependencies_503):
+	New. Moved from openvas-client/openvas/comm.c.
+
+	* omp/omp.h: Added protos for new methods.
+
 2009-10-19  Matthew Mundell <matthew.mundell at intevation.de>
 
 	* omp/xml.c (compare_entities): Continue to the rest of the comparisons

Modified: trunk/openvas-libraries/omp/omp.c
===================================================================
--- trunk/openvas-libraries/omp/omp.c	2009-10-20 09:37:56 UTC (rev 5639)
+++ trunk/openvas-libraries/omp/omp.c	2009-10-20 09:50:45 UTC (rev 5640)
@@ -491,7 +491,173 @@
   return check_response (session);
 }
 
+
 /**
+ * @brief Issue an OMP \<get_nvt_all\/\> command and wait for the response.
+ *
+ * @param[in]  session   Session to the server.
+ * @param[out] response  Entity containing the response, must be freed.
+ *
+ * @return 0 in case of success. -1 otherwise (e.g. invalid session).
+ */
+int
+omp_get_nvt_all (gnutls_session_t* session, entity_t* response)
+{
+  while (1)
+    {
+      const char* status;
+
+      if (openvas_server_send (session, "<get_nvt_all/>"))
+        return -1;
+
+      *response = NULL;
+      if (read_entity (session, response)) return -1;
+
+      status = entity_attribute (*response, "status");
+      if (status == NULL)
+        {
+          free_entity (*response);
+          return -1;
+        }
+      if (strlen (status) == 0)
+        {
+          free_entity (*response);
+          return -1;
+        }
+      char first = status[0];
+      if (first == '2') return 0;
+      if (strlen (status) == 3 && strcmp (status, "503") == 0)
+        {
+          sleep (1);
+          continue;
+        }
+      free_entity (*response);
+      return -1;
+    }
+}
+
+/**
+ * @brief Issue an OMP \<get_nvt_feed_checksum algoithm=md5/\> command and
+ * @brief wait for the response.
+ *
+ * @param[in]  session   Session to the server.
+ * @param[out] response  Entity containing the response, must be freed.
+ *
+ * @return 0 in case of success. -1 otherwise (e.g. invalid session).
+ */
+int
+omp_get_nvt_feed_checksum (gnutls_session_t* session, entity_t* response)
+{
+  while (1)
+    {
+      const char* status;
+
+      if (openvas_server_send (session,
+                               "<get_nvt_feed_checksum algorithm=\"md5\"/>"))
+        return -1;
+
+      *response = NULL;
+      if (read_entity (session, response)) return -1;
+
+      status = entity_attribute (*response, "status");
+      if (status == NULL)
+        {
+          free_entity (*response);
+          return -1;
+        }
+      if (strlen (status) == 0)
+        {
+          free_entity (*response);
+          return -1;
+        }
+      char first = status[0];
+      if (first == '2') return 0;
+      if (strlen (status) == 3 && strcmp (status, "503") == 0)
+        {
+          sleep (0.5);
+          continue;
+        }
+      free_entity (*response);
+      return -1;
+    }
+}
+
+/* caller must free return */
+int
+omp_get_rules_503 (gnutls_session_t* session, entity_t* response)
+{
+  while (1)
+    {
+      const char* status;
+
+      if (openvas_server_send (session, "<get_rules/>"))
+        return -1;
+
+      *response = NULL;
+      if (read_entity (session, response)) return -1;
+
+      status = entity_attribute (*response, "status");
+      if (status == NULL)
+        {
+          free_entity (*response);
+          return -1;
+        }
+      if (strlen (status) == 0)
+        {
+          free_entity (*response);
+          return -1;
+        }
+      char first = status[0];
+      if (first == '2') return 0;
+      if (strlen (status) == 3 && strcmp (status, "503") == 0)
+        {
+          sleep (0.5);
+          continue;
+        }
+      free_entity (*response);
+      return -1;
+    }
+}
+
+/* caller must free return */
+int
+omp_get_dependencies_503 (gnutls_session_t* session, entity_t* response)
+{
+  while (1)
+    {
+      const char* status;
+
+      if (openvas_server_send (session, "<get_dependencies/>"))
+        return -1;
+
+      *response = NULL;
+      if (read_entity (session, response)) return -1;
+
+      status = entity_attribute (*response, "status");
+      if (status == NULL)
+        {
+          free_entity (*response);
+          return -1;
+        }
+      if (strlen (status) == 0)
+        {
+          free_entity (*response);
+          return -1;
+        }
+      char first = status[0];
+      if (first == '2') return 0;
+      if (strlen (status) == 3 && strcmp (status, "503") == 0)
+        {
+          sleep (0.5);
+          continue;
+        }
+      free_entity (*response);
+      return -1;
+    }
+}
+
+
+/**
  * @brief Wait for a task to start running on the server.
  *
  * @param[in]  session  Pointer to GNUTLS session.

Modified: trunk/openvas-libraries/omp/omp.h
===================================================================
--- trunk/openvas-libraries/omp/omp.h	2009-10-20 09:37:56 UTC (rev 5639)
+++ trunk/openvas-libraries/omp/omp.h	2009-10-20 09:50:45 UTC (rev 5640)
@@ -32,6 +32,18 @@
 omp_task_status (entity_t status_response);
 
 int
+omp_get_nvt_all (gnutls_session_t* session, entity_t* response);
+
+int
+omp_get_nvt_feed_checksum (gnutls_session_t* session, entity_t* response);
+
+int
+omp_get_rules_503 (gnutls_session_t* session, entity_t* response);
+
+int
+omp_get_dependencies_503 (gnutls_session_t* session, entity_t* response);
+
+int
 omp_authenticate (gnutls_session_t* session,
               const char* username,
               const char* password);



More information about the Openvas-commits mailing list