diff options
Diffstat (limited to 'src/analysis/db/client.c')
-rw-r--r-- | src/analysis/db/client.c | 51 |
1 files changed, 49 insertions, 2 deletions
diff --git a/src/analysis/db/client.c b/src/analysis/db/client.c index 25fe64d..24198f6 100644 --- a/src/analysis/db/client.c +++ b/src/analysis/db/client.c @@ -68,6 +68,7 @@ struct _GDbClient char *desc; /* Description du lien */ GMutex sending_lock; /* Concurrence des envois */ + bool can_get_updates; /* Réception de maj possibles ?*/ GThread *update; /* Procédure de traitement */ }; @@ -519,6 +520,8 @@ static bool g_db_client_start_common(GDbClient *client, char *desc) } + client->can_get_updates = false; + client->update = g_thread_try_new("cdb_client", (GThreadFunc)g_db_client_update, client, NULL); if (client->update == NULL) { @@ -571,16 +574,44 @@ static bool g_db_client_start_common(GDbClient *client, char *desc) static void *g_db_client_update(GDbClient *client) { + packed_buffer out_pbuf; /* Tampon d'émission */ + bool status; /* Bilan d'une opération */ struct pollfd fds; /* Surveillance des flux */ packed_buffer in_pbuf; /* Tampon de réception */ int ret; /* Bilan d'un appel */ uint32_t tmp32; /* Valeur sur 32 bits */ - bool status; /* Bilan d'une opération */ uint32_t command; /* Commande de la requête */ DBError error; /* Bilan d'une commande passée */ GDbCollection *collec; /* Collection visée au final */ char *msg; /* Message d'erreur à imprimer */ + /** + * Avant toute chose, on demande un stage d'actualisation ! + */ + + init_packed_buffer(&out_pbuf); + + status = extend_packed_buffer(&out_pbuf, (uint32_t []) { DBC_GET_ALL_ITEMS }, sizeof(uint32_t), true); + if (!status) + { + exit_packed_buffer(&out_pbuf); + goto exit; + } + + status = ssl_send_packed_buffer(&out_pbuf, client->tls_fd); + if (!status) + { + log_simple_message(LMT_INFO, _("Failed to get all updates")); + exit_packed_buffer(&out_pbuf); + goto exit; + } + + exit_packed_buffer(&out_pbuf); + + /** + * Phase d'écoute continue... + */ + fds.fd = client->fd; fds.events = POLLIN | POLLPRI; @@ -631,11 +662,25 @@ static void *g_db_client_update(GDbClient *client) collec = find_collection_in_list(client->collections, tmp32); if (collec == NULL) goto gdcu_bad_exchange; - status = g_db_collection_unpack(collec, &in_pbuf, NULL); + if (client->can_get_updates) + status = g_db_collection_unpack(collec, &in_pbuf, NULL); + else + status = _g_db_collection_unpack(collec, &in_pbuf, (DBAction []) { 0 }, NULL); + if (!status) goto gdcu_bad_exchange; break; + case DBC_GET_ALL_ITEMS: + log_variadic_message(LMT_INFO, + _("This command is not available on this side: 0x%08x"), command); + goto gdcu_bad_exchange; + break; + + case DBC_SET_ALL_ITEMS: + client->can_get_updates = true; + break; + } continue; @@ -654,6 +699,8 @@ static void *g_db_client_update(GDbClient *client) } + exit: + g_db_client_stop(client); exit_packed_buffer(&in_pbuf); |