diff options
| author | Cyrille Bagard <nocbos@gmail.com> | 2017-02-28 18:58:57 (GMT) | 
|---|---|---|
| committer | Cyrille Bagard <nocbos@gmail.com> | 2017-02-28 18:58:57 (GMT) | 
| commit | 027305c2447b05de2c576e3f5ee32ced400f439f (patch) | |
| tree | 96f35ddcd87129f3c4ccec69e8fa0216654215c9 /src/analysis/db/misc | |
| parent | 7d153f7d3a32a66d3eaf5199d396debbe3b675f5 (diff) | |
Defined abstract packed buffers to transfert data.
Diffstat (limited to 'src/analysis/db/misc')
| -rw-r--r-- | src/analysis/db/misc/rlestr.c | 56 | ||||
| -rw-r--r-- | src/analysis/db/misc/rlestr.h | 5 | ||||
| -rw-r--r-- | src/analysis/db/misc/timestamp.c | 31 | ||||
| -rw-r--r-- | src/analysis/db/misc/timestamp.h | 5 | 
4 files changed, 38 insertions, 59 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;  } diff --git a/src/analysis/db/misc/rlestr.h b/src/analysis/db/misc/rlestr.h index 01f37e6..be76f17 100644 --- a/src/analysis/db/misc/rlestr.h +++ b/src/analysis/db/misc/rlestr.h @@ -30,6 +30,7 @@  #include <sys/types.h> +#include "../../../common/packed.h"  #include "../../../common/sqlite.h" @@ -66,10 +67,10 @@ void unset_rle_string(rle_string *);  int cmp_rle_string(const rle_string *, const rle_string *);  /* Importe la définition d'une chaîne de caractères. */ -bool recv_rle_string(rle_string *, int, int); +bool unpack_rle_string(rle_string *, packed_buffer *);  /* Exporte la définition d'une chaîne de caractères. */ -bool send_rle_string(const rle_string *, int, int); +bool pack_rle_string(const rle_string *, packed_buffer *); diff --git a/src/analysis/db/misc/timestamp.c b/src/analysis/db/misc/timestamp.c index 6c7a47f..aa9f758 100644 --- a/src/analysis/db/misc/timestamp.c +++ b/src/analysis/db/misc/timestamp.c @@ -24,15 +24,11 @@  #include "timestamp.h" -#include <endian.h>  #include <malloc.h>  #include <sqlite3.h>  #include <time.h> -#include "../../../common/io.h" - -  /******************************************************************************  *                                                                             * @@ -117,8 +113,7 @@ int cmp_timestamp(const timestamp_t *t1, const timestamp_t *t2)  /******************************************************************************  *                                                                             *  *  Paramètres  : timestamp = informations à constituer. [OUT]                 * -*                fd        = flux ouvert en lecture pour l'importation.       * -*                flags     = éventuelles options de réception supplémentaires.* +*                pbuf      = paquet de données où venir puiser les infos.     *  *                                                                             *  *  Description : Importe la définition d'un horodatage.                       *  *                                                                             * @@ -128,17 +123,13 @@ int cmp_timestamp(const timestamp_t *t1, const timestamp_t *t2)  *                                                                             *  ******************************************************************************/ -bool recv_timestamp(timestamp_t *timestamp, int fd, int flags) +bool unpack_timestamp(timestamp_t *timestamp, packed_buffer *pbuf)  { -    uint64_t val64;                         /* Valeur sur 64 bits          */ -    bool status;                            /* Bilan d'une opération       */ +    bool result;                            /* Bilan à retourner           */ -    status = safe_recv(fd, &val64, sizeof(uint64_t), MSG_WAITALL | flags); -    if (!status) return false; +    result = extract_packed_buffer(pbuf, (uint64_t *)timestamp, sizeof(uint64_t), true); -    *timestamp = be64toh(val64); - -    return true; +    return result;  } @@ -146,8 +137,7 @@ bool recv_timestamp(timestamp_t *timestamp, int fd, int flags)  /******************************************************************************  *                                                                             *  *  Paramètres  : timestamp = informations à sauvegarer.                       * -*                fd        = flux ouvert en écriture pour l'exportation.      * -*                flags     = éventuelles options d'envoi supplémentaires.     * +*                pbuf      = paquet de données où venir inscrire les infos.   *  *                                                                             *  *  Description : Exporte la définition d'un horodatage.                       *  *                                                                             * @@ -157,14 +147,13 @@ bool recv_timestamp(timestamp_t *timestamp, int fd, int flags)  *                                                                             *  ******************************************************************************/ -bool send_timestamp(const timestamp_t *timestamp, int fd, int flags) +bool pack_timestamp(const timestamp_t *timestamp, packed_buffer *pbuf)  { -    bool status;                            /* Bilan d'une opération       */ +    bool result;                            /* Bilan à retourner           */ -    status = safe_send(fd, (uint64_t []) { htobe64(*timestamp) }, sizeof(uint64_t), flags); -    if (!status) return false; +    result = extend_packed_buffer(pbuf, (uint64_t *)timestamp, sizeof(uint64_t), true); -    return true; +    return result;  } diff --git a/src/analysis/db/misc/timestamp.h b/src/analysis/db/misc/timestamp.h index 5d4f2f1..14a1fb5 100644 --- a/src/analysis/db/misc/timestamp.h +++ b/src/analysis/db/misc/timestamp.h @@ -29,6 +29,7 @@  #include <stdint.h> +#include "../../../common/packed.h"  #include "../../../common/sqlite.h" @@ -52,10 +53,10 @@ bool timestamp_is_younger(timestamp_t, timestamp_t);  int cmp_timestamp(const timestamp_t *, const timestamp_t *);  /* Importe la définition d'un horodatage. */ -bool recv_timestamp(timestamp_t *, int, int); +bool unpack_timestamp(timestamp_t *, packed_buffer *);  /* Exporte la définition d'un horodatage. */ -bool send_timestamp(const timestamp_t *, int, int); +bool pack_timestamp(const timestamp_t *, packed_buffer *);  | 
