summaryrefslogtreecommitdiff
path: root/src/analysis/db/client.c
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2019-10-13 23:24:57 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2019-10-13 23:24:57 (GMT)
commitf439711a77e0719e7f1dcf4b5c5511157986c918 (patch)
treecac0cf37be2676fcf2dc958f9d9fd2fadea20653 /src/analysis/db/client.c
parent986125d4c2d8b049017b6d0770f16b9058076165 (diff)
Retrieved the current snapshot identifier from servers.
Diffstat (limited to 'src/analysis/db/client.c')
-rw-r--r--src/analysis/db/client.c112
1 files changed, 112 insertions, 0 deletions
diff --git a/src/analysis/db/client.c b/src/analysis/db/client.c
index 4c525e1..3372c74 100644
--- a/src/analysis/db/client.c
+++ b/src/analysis/db/client.c
@@ -76,6 +76,12 @@ struct _GHubClient
bool can_get_updates; /* Réception de maj possibles ?*/
GThread *update; /* Procédure de traitement */
+
+
+
+ snapshot_id_t current; /* Instantané courant */
+ bool has_current; /* Validité de l'identifiant */
+
};
/* Description de client à l'écoute (classe) */
@@ -162,6 +168,8 @@ static void g_hub_client_init(GHubClient *client)
client->tls_fd = NULL;
client->desc = NULL;
+ client->has_current = false;
+
}
@@ -686,6 +694,7 @@ 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 */
/**
@@ -694,6 +703,13 @@ static void *g_hub_client_update(GHubClient *client)
init_packed_buffer(&out_pbuf);
+ status = extend_packed_buffer(&out_pbuf, (uint32_t []) { DBC_GET_CUR_SNAPSHOT }, sizeof(uint32_t), true);
+ if (!status)
+ {
+ exit_packed_buffer(&out_pbuf);
+ goto exit;
+ }
+
status = extend_packed_buffer(&out_pbuf, (uint32_t []) { DBC_GET_ALL_ITEMS }, sizeof(uint32_t), true);
if (!status)
{
@@ -798,6 +814,28 @@ static void *g_hub_client_update(GHubClient *client)
client->can_get_updates = (tmp8 == 0x1);
break;
+ case DBC_GET_CUR_SNAPSHOT:
+ log_variadic_message(LMT_INFO,
+ _("This command is not available on this side: 0x%08x"), command);
+ goto gdcu_bad_exchange;
+ break;
+
+ case DBC_CUR_SNAPSHOT_UPDATED:
+
+ status = unpack_snapshot_id(&id, &in_pbuf);
+ if (!status) goto gdcu_bad_exchange;
+
+ copy_snapshot_id(&client->current, &id);
+ client->has_current = true;
+
+ break;
+
+ case DBC_SET_CUR_SNAPSHOT:
+ log_variadic_message(LMT_INFO,
+ _("This command is not available on this side: 0x%08x"), command);
+ goto gdcu_bad_exchange;
+ break;
+
}
if (has_more_data_in_packed_buffer(&in_pbuf))
@@ -1092,3 +1130,77 @@ bool g_hub_client_set_last_active(GHubClient *client, timestamp_t timestamp)
return result;
}
+
+
+/******************************************************************************
+* *
+* Paramètres : client = client pour les accès distants à manipuler. *
+* id = identifiant d'instantané à renseigner. [OUT] *
+* *
+* Description : Fournit l'identifiant de l'instantané courant. *
+* *
+* Retour : true si l'identifiant retourné est valide, false sinon. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool g_hub_client_get_current_snapshot(GHubClient *client, snapshot_id_t *id)
+{
+ bool result; /* Validité à retourner */
+
+ result = client->has_current;
+
+ if (result)
+ copy_snapshot_id(id, &client->current);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : client = client pour les accès distants à manipuler. *
+* id = identifiant d'instantané à activer. *
+* *
+* Description : Définit l'identifiant de l'instantané courant. *
+* *
+* Retour : true si la commande a bien été envoyée, false sinon. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool g_hub_client_set_current_snapshot(GHubClient *client, const snapshot_id_t *id)
+{
+ bool result; /* Bilan partiel à remonter */
+ packed_buffer out_pbuf; /* Tampon d'émission */
+ SSL *tls_fd; /* Canal de communication SSL */
+
+ init_packed_buffer(&out_pbuf);
+
+ tls_fd = g_hub_client_get_ssl_fd(client);
+
+ if (tls_fd == NULL)
+ result = false;
+
+ else
+ {
+ result = extend_packed_buffer(&out_pbuf, (uint32_t []) { DBC_SET_CUR_SNAPSHOT }, sizeof(uint32_t), true);
+
+ if (result)
+ result = pack_snapshot_id(id, &out_pbuf);
+
+ if (result)
+ result = ssl_send_packed_buffer(&out_pbuf, tls_fd);
+
+ g_hub_client_put_ssl_fd(client, tls_fd);
+
+ }
+
+ exit_packed_buffer(&out_pbuf);
+
+ return result;
+
+}