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

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Thu Sep 29 08:17:50 CEST 2011


Author: mattm
Date: 2011-09-29 08:17:47 +0200 (Thu, 29 Sep 2011)
New Revision: 11711

Modified:
   trunk/gsa/ChangeLog
   trunk/gsa/src/gsad.c
   trunk/gsa/src/gsad_omp.c
   trunk/gsa/src/gsad_omp.h
Log:
	* src/gsad.c (user_set_timezone): New function.
	(exec_omp_post): Update timezone after save_my_settings.

	* src/gsad_omp.c (save_my_settings): Add timezone return arg.

	* src/gsad_omp.h: Update header accordingly.

Modified: trunk/gsa/ChangeLog
===================================================================
--- trunk/gsa/ChangeLog	2011-09-28 18:33:21 UTC (rev 11710)
+++ trunk/gsa/ChangeLog	2011-09-29 06:17:47 UTC (rev 11711)
@@ -1,3 +1,12 @@
+2011-09-29  Matthew Mundell <matthew.mundell at greenbone.net>
+
+	* src/gsad.c (user_set_timezone): New function.
+	(exec_omp_post): Update timezone after save_my_settings.
+
+	* src/gsad_omp.c (save_my_settings): Add timezone return arg.
+
+	* src/gsad_omp.h: Update header accordingly.
+
 2011-09-28  Matthew Mundell <matthew.mundell at greenbone.net>
 
 	Add editing of My Settings.

Modified: trunk/gsa/src/gsad.c
===================================================================
--- trunk/gsa/src/gsad.c	2011-09-28 18:33:21 UTC (rev 11710)
+++ trunk/gsa/src/gsad.c	2011-09-29 06:17:47 UTC (rev 11711)
@@ -339,6 +339,38 @@
 }
 
 /**
+ * @brief Get a user.
+ *
+ * If a user is returned, it's up to the caller to release the user.
+ *
+ * @param[in]   name      User name.
+ * @param[in]   timezone  Timezone.
+ *
+ * @return 0 ok, 1 failed to find user.
+ */
+int
+user_set_timezone (const gchar *name, const gchar *timezone)
+{
+  int index, ret;
+  ret = 1;
+  g_mutex_lock (mutex);
+  for (index = 0; index < users->len; index++)
+    {
+      user_t *item;
+      item = (user_t*) g_ptr_array_index (users, index);
+      if (strcmp (item->username, name) == 0)
+        {
+          g_free (item->timezone);
+          item->timezone = g_strdup (timezone);
+          ret = 0;
+          break;
+        }
+    }
+  g_mutex_unlock (mutex);
+  return ret;
+}
+
+/**
  * @brief Release a user_t returned by user_add or user_find.
  *
  * @param[in]  user  User.
@@ -1334,7 +1366,15 @@
   ELSE (save_config_family)
   ELSE (save_config_nvt)
   ELSE (save_lsc_credential)
-  ELSE (save_my_settings)
+  else if (!strcmp (cmd, "save_my_settings"))
+    {
+      const char *timezone;
+      con_info->response = save_my_settings_omp (credentials, con_info->params,
+                                                 &timezone);
+      if (timezone)
+        /* credentials->timezone set in save_my_settings_omp before XSLT. */
+        user_set_timezone (credentials->username, timezone);
+    }
   ELSE (save_note)
   ELSE (save_override)
   ELSE (save_report_format)

Modified: trunk/gsa/src/gsad_omp.c
===================================================================
--- trunk/gsa/src/gsad_omp.c	2011-09-28 18:33:21 UTC (rev 11710)
+++ trunk/gsa/src/gsad_omp.c	2011-09-29 06:17:47 UTC (rev 11711)
@@ -13865,18 +13865,21 @@
  *
  * @param[in]  credentials  Credentials of user issuing the action.
  * @param[in]  params       Request parameters.
+ * @param[out] timezone     Timezone.
  *
  * @return Result of XSL transformation.
  */
 char *
-save_my_settings_omp (credentials_t * credentials, params_t *params)
+save_my_settings_omp (credentials_t * credentials, params_t *params,
+                      const char **timezone)
 {
   int socket;
   gnutls_session_t session;
   gchar *html;
-  const char *text;
+  const char *text, *status;
   gchar *text_64;
   GString *xml;
+  entity_t entity;
 
   if (params_value (params, "text") == NULL)
     return edit_my_settings (credentials, params,
@@ -13924,7 +13927,8 @@
 
   xml = g_string_new ("");
 
-  if (read_string (&session, &xml))
+  entity = NULL;
+  if (read_entity_and_string (&session, &entity, &xml))
     {
       g_string_free (xml, TRUE);
       openvas_server_close (socket, session);
@@ -13935,6 +13939,17 @@
                            "/omp?cmd=get_my_settings");
     }
 
+  status = entity_attribute (entity, "status");
+  if (status && (strlen (status) > 0) && (status[0] == '2'))
+    {
+      g_free (credentials->timezone);
+      credentials->timezone = g_strdup (text);
+      *timezone = text;
+    }
+  else
+    *timezone = NULL;
+
+  free_entity (entity);
   openvas_server_close (socket, session);
   return get_my_settings (credentials, params, g_string_free (xml, FALSE));
 }

Modified: trunk/gsa/src/gsad_omp.h
===================================================================
--- trunk/gsa/src/gsad_omp.h	2011-09-28 18:33:21 UTC (rev 11710)
+++ trunk/gsa/src/gsad_omp.h	2011-09-29 06:17:47 UTC (rev 11711)
@@ -161,7 +161,7 @@
 
 char * edit_my_settings_omp (credentials_t *, params_t *);
 char * get_my_settings_omp (credentials_t *, params_t *);
-char * save_my_settings_omp (credentials_t *, params_t *);
+char * save_my_settings_omp (credentials_t *, params_t *, const char **);
 
 int authenticate_omp (const gchar *, const gchar *, gchar **, gchar **);
 



More information about the Openvas-commits mailing list