From 0ecc100b14a4caae91698ad6b0ce42e8734126df Mon Sep 17 00:00:00 2001
From: Cyrille Bagard <nocbos@gmail.com>
Date: Sat, 19 Oct 2019 15:17:52 +0200
Subject: Reorganized code.

---
 src/analysis/db/client.c | 53 +++++++++++++++++++++++++++++++++++++++---------
 1 file changed, 43 insertions(+), 10 deletions(-)

diff --git a/src/analysis/db/client.c b/src/analysis/db/client.c
index 2cab655..77dafea 100644
--- a/src/analysis/db/client.c
+++ b/src/analysis/db/client.c
@@ -116,6 +116,9 @@ static void *g_hub_client_update(GHubClient *);
 /* Met à jour la liste des instantanés courants. */
 static bool g_hub_client_update_snapshots(GHubClient *, packed_buffer *);
 
+/* Met à jour l'identifiant de l'instantané courant. */
+static bool g_hub_client_update_current_snapshot(GHubClient *, packed_buffer *);
+
 /* Identifie le canal de communication pour envois au serveur. */
 static SSL *g_hub_client_get_ssl_fd(GHubClient *);
 
@@ -728,7 +731,6 @@ static void *g_hub_client_update(GHubClient *client)
     DBError error;                          /* Bilan d'une commande passée */
     GDbCollection *collec;                  /* Collection visée au final   */
     uint8_t tmp8;                           /* Valeur sur 8 bits           */
-    snapshot_id_t id;                       /* Identifiant d'instantané    */
     char *msg;                              /* Message d'erreur à imprimer */
 
     /**
@@ -870,16 +872,9 @@ static void *g_hub_client_update(GHubClient *client)
 
                 case DBC_CUR_SNAPSHOT_UPDATED:
 
-                    status = unpack_snapshot_id(&id, &in_pbuf);
+                    status = g_hub_client_update_current_snapshot(client, &in_pbuf);
                     if (!status) goto gdcu_bad_exchange;
 
-                    g_mutex_lock(&client->cur_lock);
-
-                    copy_snapshot_id(&client->current, &id);
-                    client->has_current = true;
-
-                    g_mutex_unlock(&client->cur_lock);
-
                     break;
 
                 case DBC_SET_CUR_SNAPSHOT:
@@ -928,7 +923,7 @@ static void *g_hub_client_update(GHubClient *client)
 *                                                                             *
 *  Description : Met à jour la liste des instantanés courants.                *
 *                                                                             *
-*  Retour      : true si la liste retournée est valide, false sinon.          *
+*  Retour      : true si l'opération s'est déroulée sans encombre, ou false.  *
 *                                                                             *
 *  Remarques   : -                                                            *
 *                                                                             *
@@ -1000,6 +995,44 @@ static bool g_hub_client_update_snapshots(GHubClient *client, packed_buffer *pbu
 /******************************************************************************
 *                                                                             *
 *  Paramètres  : client = client pour les accès distants à manipuler.         *
+*                pbuf   = données présentes à traiter.                        *
+*                                                                             *
+*  Description : Met à jour l'identifiant de l'instantané courant.            *
+*                                                                             *
+*  Retour      : true si l'opération s'est déroulée sans encombre, ou false.  *
+*                                                                             *
+*  Remarques   : -                                                            *
+*                                                                             *
+******************************************************************************/
+
+static bool g_hub_client_update_current_snapshot(GHubClient *client, packed_buffer *pbuf)
+{
+    bool result;                            /* Validité à retourner        */
+    snapshot_id_t id;                       /* Identifiant d'instantané    */
+
+    setup_empty_snapshot_id(&id);
+
+    result = unpack_snapshot_id(&id, pbuf);
+
+    if (result)
+    {
+        g_mutex_lock(&client->cur_lock);
+
+        copy_snapshot_id(&client->current, &id);
+        client->has_current = true;
+
+        g_mutex_unlock(&client->cur_lock);
+
+    }
+
+    return result;
+
+}
+
+
+/******************************************************************************
+*                                                                             *
+*  Paramètres  : client = client pour les accès distants à manipuler.         *
 *                                                                             *
 *  Description : Arrête la connexion à la base de données.                    *
 *                                                                             *
-- 
cgit v0.11.2-87-g4458