summaryrefslogtreecommitdiff
path: root/src/analysis/db/items/comment.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/analysis/db/items/comment.c')
-rw-r--r--src/analysis/db/items/comment.c92
1 files changed, 45 insertions, 47 deletions
diff --git a/src/analysis/db/items/comment.c b/src/analysis/db/items/comment.c
index c021e44..15d541b 100644
--- a/src/analysis/db/items/comment.c
+++ b/src/analysis/db/items/comment.c
@@ -36,7 +36,6 @@
#include "../collection-int.h"
#include "../item-int.h"
#include "../../human/asm/lang.h"
-#include "../../../common/io.h"
#include "../../../common/extstr.h"
#include "../../../glibext/linegen-int.h"
@@ -97,10 +96,10 @@ static void g_db_comment_finalize(GDbComment *);
static gint g_db_comment_cmp(GDbComment *, GDbComment *, bool);
/* Importe la définition d'un commentaire dans un flux réseau. */
-static bool g_db_comment_recv_from_fd(GDbComment *, int, int);
+static bool g_db_comment_unpack(GDbComment *, packed_buffer *);
/* Exporte la définition d'un commentaire dans un flux réseau. */
-static bool g_db_comment_send_to_fd(const GDbComment *, int, int);
+static bool g_db_comment_pack(const GDbComment *, packed_buffer *);
/* Construit la description humaine d'un commentaire. */
static void g_db_comment_build_label(GDbComment *);
@@ -227,8 +226,8 @@ static void g_db_comment_class_init(GDbCommentClass *klass)
item->cmp = (cmp_db_item_fc)g_db_comment_cmp;
- item->recv = (recv_db_item_fc)g_db_comment_recv_from_fd;
- item->send = (send_db_item_fc)g_db_comment_send_to_fd;
+ item->unpack = (unpack_db_item_fc)g_db_comment_unpack;
+ item->pack = (pack_db_item_fc)g_db_comment_pack;
item->build_label = (build_item_label_fc)g_db_comment_build_label;
item->apply = (run_item_fc)g_db_comment_apply;
@@ -443,8 +442,7 @@ static gint g_db_comment_cmp(GDbComment *a, GDbComment *b, bool with)
/******************************************************************************
* *
* Paramètres : comment = commentaire avec informations sont à charger. [OUT]*
-* fd = flux ouvert en lecture pour l'importation. *
-* flags = éventuelles options d'envoi supplémentaires. *
+* pbuf = paquet de données où venir inscrire les infos. *
* *
* Description : Importe la définition d'un commentaire dans un flux réseau. *
* *
@@ -454,37 +452,39 @@ static gint g_db_comment_cmp(GDbComment *a, GDbComment *b, bool with)
* *
******************************************************************************/
-static bool g_db_comment_recv_from_fd(GDbComment *comment, int fd, int flags)
+static bool g_db_comment_unpack(GDbComment *comment, packed_buffer *pbuf)
{
- bool status; /* Bilan d'opération initiale */
- uint32_t val32; /* Valeur sur 32 bits */
- uint8_t val8; /* Valeur sur 8 bits */
-
- status = G_DB_ITEM_CLASS(g_db_comment_parent_class)->recv(G_DB_ITEM(comment), fd, flags);
- if (!status) return false;
-
- if (!recv_vmpa(&comment->addr, fd, flags))
- return false;
+ bool result; /* Bilan à retourner */
+ uint32_t tmp32; /* Valeur sur 32 bits */
+ uint8_t tmp8; /* Valeur sur 8 bits */
- status = safe_recv(fd, &val32, sizeof(uint32_t), MSG_WAITALL | flags);
- if (!status) return false;
-
- comment->flags = be32toh(val32);
+ result = G_DB_ITEM_CLASS(g_db_comment_parent_class)->unpack(G_DB_ITEM(comment), pbuf);
- if (!recv_rle_string(&comment->text, fd, flags))
- return false;
+ if (result)
+ result = unpack_vmpa(&comment->addr, pbuf);
- status = safe_recv(fd, &val8, sizeof(uint8_t), MSG_WAITALL | flags);
- if (!status) return false;
+ if (result)
+ {
+ result = extend_packed_buffer(pbuf, &tmp32, sizeof(uint32_t), true);
+ comment->flags = tmp32;
+ }
- comment->inlined = val8;
+ if (result)
+ result = unpack_rle_string(&comment->text, pbuf);
- status = safe_recv(fd, &val8, sizeof(uint8_t), MSG_WAITALL | flags);
- if (!status) return false;
+ if (result)
+ {
+ result = extend_packed_buffer(pbuf, &tmp8, sizeof(uint8_t), true);
+ comment->inlined = tmp8;
+ }
- comment->repeatable = val8;
+ if (result)
+ {
+ result = extend_packed_buffer(pbuf, &tmp8, sizeof(uint8_t), true);
+ comment->repeatable = tmp8;
+ }
- return true;
+ return result;
}
@@ -492,8 +492,7 @@ static bool g_db_comment_recv_from_fd(GDbComment *comment, int fd, int flags)
/******************************************************************************
* *
* Paramètres : comment = informations à sauvegarder. *
-* 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 commentaire dans un flux réseau. *
* *
@@ -503,29 +502,28 @@ static bool g_db_comment_recv_from_fd(GDbComment *comment, int fd, int flags)
* *
******************************************************************************/
-static bool g_db_comment_send_to_fd(const GDbComment *comment, int fd, int flags)
+static bool g_db_comment_pack(const GDbComment *comment, packed_buffer *pbuf)
{
- bool status; /* Bilan d'opération initiale */
+ bool result; /* Bilan à retourner */
- status = G_DB_ITEM_CLASS(g_db_comment_parent_class)->send(G_DB_ITEM(comment), fd, MSG_MORE | flags);
- if (!status) return false;
+ result = G_DB_ITEM_CLASS(g_db_comment_parent_class)->pack(G_DB_ITEM(comment), pbuf);
- if (!send_vmpa(&comment->addr, fd, MSG_MORE | flags))
- return false;
+ if (result)
+ result = pack_vmpa(&comment->addr, pbuf);
- status = safe_send(fd, (uint32_t []) { htobe32(comment->flags) }, sizeof(uint32_t), MSG_MORE | flags);
- if (!status) return false;
+ if (result)
+ result = extend_packed_buffer(pbuf, (uint32_t []) { comment->flags }, sizeof(uint32_t), true);
- if (!send_rle_string(&comment->text, fd, MSG_MORE | flags))
- return false;
+ if (result)
+ result = pack_rle_string(&comment->text, pbuf);
- status = safe_send(fd, (uint8_t []) { (uint8_t)comment->inlined }, sizeof(uint8_t), MSG_MORE | flags);
- if (!status) return false;
+ if (result)
+ result = extend_packed_buffer(pbuf, (uint8_t []) { comment->inlined }, sizeof(uint8_t), true);
- status = safe_send(fd, (uint8_t []) { (uint8_t)comment->repeatable }, sizeof(uint8_t), flags);
- if (!status) return false;
+ if (result)
+ result = extend_packed_buffer(pbuf, (uint8_t []) { comment->repeatable }, sizeof(uint8_t), true);
- return true;
+ return result;
}