summaryrefslogtreecommitdiff
path: root/src/analysis/db/misc/rlestr.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/analysis/db/misc/rlestr.c')
-rw-r--r--src/analysis/db/misc/rlestr.c56
1 files changed, 22 insertions, 34 deletions
diff --git a/src/analysis/db/misc/rlestr.c b/src/analysis/db/misc/rlestr.c
index 2f06542..39e2d99 100644
--- a/src/analysis/db/misc/rlestr.c
+++ b/src/analysis/db/misc/rlestr.c
@@ -24,15 +24,11 @@
#include "rlestr.h"
-#include <endian.h>
#include <malloc.h>
#include <sqlite3.h>
#include <string.h>
-#include "../../../common/io.h"
-
-
/******************************************************************************
* *
@@ -162,9 +158,8 @@ int cmp_rle_string(const rle_string *s1, const rle_string *s2)
/******************************************************************************
* *
-* Paramètres : str = informations à constituer. [OUT] *
-* fd = flux ouvert en lecture pour l'importation. *
-* flags = éventuelles options de réception supplémentaires. *
+* Paramètres : str = informations à constituer. [OUT] *
+* pbuf = paquet de données où venir puiser les infos. *
* *
* Description : Importe la définition d'une chaîne de caractères. *
* *
@@ -174,44 +169,41 @@ int cmp_rle_string(const rle_string *s1, const rle_string *s2)
* *
******************************************************************************/
-bool recv_rle_string(rle_string *str, int fd, int flags)
+bool unpack_rle_string(rle_string *str, packed_buffer *pbuf)
{
- uint32_t val32; /* Valeur sur 32 bits */
- bool status; /* Bilan d'une opération */
+ bool result; /* Bilan à retourner */
+ uint32_t tmp32; /* Valeur sur 32 bits */
str->data = NULL;
str->length = 0;
- status = safe_recv(fd, &val32, sizeof(uint32_t), MSG_WAITALL | flags);
- if (!status) return false;
+ result = extract_packed_buffer(pbuf, &tmp32, sizeof(uint32_t), true);
- str->length = be32toh(val32);
+ str->length = tmp32;
- if (str->length > 0)
+ if (result && str->length > 0)
{
str->data = (char *)malloc(str->length + 1);
- status = safe_recv(fd, str->data, str->length + 1, MSG_WAITALL | flags);
- if (!status)
- {
+ result = extract_packed_buffer(pbuf, str->data, str->length + 1, false);
+
+ if (!result)
unset_rle_string(str);
- return false;
- }
- str->data[str->length] = '\0';
+ else
+ str->data[str->length] = '\0';
}
- return true;
+ return result;
}
/******************************************************************************
* *
-* Paramètres : str = informations à sauvegarer. *
-* fd = flux ouvert en écriture pour l'exportation. *
-* flags = éventuelles options d'envoi supplémentaires. *
+* Paramètres : str = informations à sauvegarer. *
+* pbuf = paquet de données où venir inscrire les infos. *
* *
* Description : Exporte la définition d'une chaîne de caractères. *
* *
@@ -221,20 +213,16 @@ bool recv_rle_string(rle_string *str, int fd, int flags)
* *
******************************************************************************/
-bool send_rle_string(const rle_string *str, int fd, int flags)
+bool pack_rle_string(const rle_string *str, packed_buffer *pbuf)
{
- bool status; /* Bilan d'une opération */
+ bool result; /* Bilan à retourner */
- status = safe_send(fd, (uint32_t []) { htobe32(str->length) }, sizeof(uint32_t), MSG_MORE | flags);
- if (!status) return false;
+ result = extend_packed_buffer(pbuf, (uint32_t []) { str->length }, sizeof(uint32_t), true);
- if (str->length > 0)
- {
- status = safe_send(fd, str->data, str->length + 1, flags);
- if (!status) return false;
- }
+ if (result && str->length > 0)
+ result = extend_packed_buffer(pbuf, str->data, str->length + 1, false);
- return true;
+ return result;
}