diff options
Diffstat (limited to 'src/analysis/db/client.c')
-rw-r--r-- | src/analysis/db/client.c | 44 |
1 files changed, 35 insertions, 9 deletions
diff --git a/src/analysis/db/client.c b/src/analysis/db/client.c index 9252ccc..2bfa978 100644 --- a/src/analysis/db/client.c +++ b/src/analysis/db/client.c @@ -31,7 +31,6 @@ #include <string.h> #include <unistd.h> #include <openssl/err.h> -#include <openssl/ssl.h> #include <i18n.h> @@ -682,6 +681,7 @@ static void *g_hub_client_update(GHubClient *client) uint32_t command; /* Commande de la requête */ DBError error; /* Bilan d'une commande passée */ GDbCollection *collec; /* Collection visée au final */ + uint8_t tmp8; /* Valeur sur 8 bits */ char *msg; /* Message d'erreur à imprimer */ /** @@ -740,6 +740,8 @@ static void *g_hub_client_update(GHubClient *client) status = ssl_recv_packed_buffer(&in_pbuf, client->tls_fd); if (!status) goto gdcu_bad_exchange; + next_command: + status = extract_packed_buffer(&in_pbuf, &command, sizeof(uint32_t), true); if (!status) goto gdcu_bad_exchange; @@ -785,11 +787,18 @@ static void *g_hub_client_update(GHubClient *client) break; case DBC_SET_ALL_ITEMS: - client->can_get_updates = true; + + status = extract_packed_buffer(&in_pbuf, &tmp8, sizeof(uint8_t), true); + if (!status) goto gdcu_bad_exchange; + + client->can_get_updates = (tmp8 == 0x1); break; } + if (has_more_data_in_packed_buffer(&in_pbuf)) + goto next_command; + continue; gdcu_bad_exchange: @@ -882,11 +891,25 @@ void g_hub_client_stop(GHubClient *client) * * ******************************************************************************/ -int g_hub_client_get_fd(GHubClient *client) +SSL *g_hub_client_get_ssl_fd(GHubClient *client) { + SSL *result; /* Canal à retourner */ +#ifndef NDEBUG + int ret; /* Validation de transmission */ +#endif + g_mutex_lock(&client->sending_lock); - return client->fd; + result = client->tls_fd; + +#ifndef NDEBUG + ret = SSL_up_ref(result); + assert(ret == 1); +#else + SSL_up_ref(result); +#endif + + return result; } @@ -894,6 +917,7 @@ int g_hub_client_get_fd(GHubClient *client) /****************************************************************************** * * * Paramètres : client = client pour les accès distants à manipuler. * +* tls_fd = canal de communication SSL. * * * * Description : Marque le canal de communication comme disponible. * * * @@ -903,10 +927,12 @@ int g_hub_client_get_fd(GHubClient *client) * * ******************************************************************************/ -void g_hub_client_put_fd(GHubClient *client) +void g_hub_client_put_ssl_fd(GHubClient *client, SSL *tls_fd) { g_mutex_unlock(&client->sending_lock); + SSL_free(tls_fd); + } @@ -927,13 +953,13 @@ bool g_hub_client_save(GHubClient *client) bool result; /* Bilan partiel à remonter */ int sent; /* Quantité de données traitées*/ - g_hub_client_get_fd(client); + g_hub_client_get_ssl_fd(client); sent = SSL_write(client->tls_fd, (uint32_t []) { htobe32(DBC_SAVE) }, sizeof(uint32_t)); result = (sent == sizeof(uint32_t)); - g_hub_client_put_fd(client); + g_hub_client_put_ssl_fd(client, client->tls_fd); return result; @@ -960,14 +986,14 @@ bool g_hub_client_set_last_active(GHubClient *client, timestamp_t timestamp) init_packed_buffer(&out_pbuf); - g_hub_client_get_fd(client); + g_hub_client_get_ssl_fd(client); result = extend_packed_buffer(&out_pbuf, (uint32_t []) { DBC_SET_LAST_ACTIVE }, sizeof(uint32_t), true); if (result) result = pack_timestamp(×tamp, &out_pbuf); - g_hub_client_put_fd(client); + g_hub_client_put_ssl_fd(client, client->tls_fd); if (result) result = ssl_send_packed_buffer(&out_pbuf, client->tls_fd); |