From b1078dfe98659a06f14b39f812e4463e8be234be Mon Sep 17 00:00:00 2001
From: Philippe PITTOLI
Date: Tue, 9 Oct 2018 13:20:26 +0200
Subject: [PATCH] renaming msg.[ch] in message.[ch]
---
core-test/app/communication-client.c | 2 +-
core/communication.h | 2 +-
core/{msg.c => message.c} | 2 +-
core/{msg.h => message.h} | 0
pong/app/pong.c | 2 +-
pubsub/lib/msg.c | 132 ---------------------------
pubsub/lib/msg.h | 21 -----
pubsub/lib/pubsub.h | 2 +-
pubsub/lib/pubsubd.c | 2 +-
pubsub/lib/pubsubd.h | 4 +-
pubsub/tests/msg.c | 2 +-
remote/app/remotec.c | 2 +-
remote/lib/{msg.c => message.c} | 2 +-
remote/lib/{msg.h => message.h} | 0
remote/lib/remotec.c | 2 +-
remote/lib/remotec.h | 2 +-
remote/lib/remoted.c | 2 +-
remote/lib/remoted.h | 4 +-
18 files changed, 16 insertions(+), 169 deletions(-)
rename core/{msg.c => message.c} (99%)
rename core/{msg.h => message.h} (100%)
delete mode 100644 pubsub/lib/msg.c
delete mode 100644 pubsub/lib/msg.h
rename remote/lib/{msg.c => message.c} (99%)
rename remote/lib/{msg.h => message.h} (100%)
diff --git a/core-test/app/communication-client.c b/core-test/app/communication-client.c
index c1760c4..bb894f3 100644
--- a/core-test/app/communication-client.c
+++ b/core-test/app/communication-client.c
@@ -2,7 +2,7 @@
#include
#include
-#include "../../core/msg.h"
+#include "../../core/message.h"
#include "../../core/error.h"
#include "../../core/communication.h"
diff --git a/core/communication.h b/core/communication.h
index ee09d8f..7fdd90c 100644
--- a/core/communication.h
+++ b/core/communication.h
@@ -5,7 +5,7 @@
#include
#include
#include // error numbers
-#include "msg.h"
+#include "message.h"
#include "client.h"
diff --git a/core/msg.c b/core/message.c
similarity index 99%
rename from core/msg.c
rename to core/message.c
index 59bac05..e823ccb 100644
--- a/core/msg.c
+++ b/core/message.c
@@ -1,4 +1,4 @@
-#include "msg.h"
+#include "message.h"
#include "error.h"
#include "usocket.h"
diff --git a/core/msg.h b/core/message.h
similarity index 100%
rename from core/msg.h
rename to core/message.h
diff --git a/pong/app/pong.c b/pong/app/pong.c
index d782551..39196c8 100644
--- a/pong/app/pong.c
+++ b/pong/app/pong.c
@@ -3,7 +3,7 @@
#include
#include
-#include "../../core/msg.h"
+#include "../../core/message.h"
#include "../../core/error.h"
#include "../../core/communication.h"
diff --git a/pubsub/lib/msg.c b/pubsub/lib/msg.c
deleted file mode 100644
index 5d06e10..0000000
--- a/pubsub/lib/msg.c
+++ /dev/null
@@ -1,132 +0,0 @@
-#include
-#include
-#include
-
-#include "msg.h"
-#include "../../core/error.h"
-
-void pubsub_message_serialize (const struct pubsub_msg *msg, char **data, size_t *len)
-{
- if (msg == NULL) {
- handle_err ("pubsub_message_serialize", "msg == NULL");
- return;
- }
-
- if (data == NULL) {
- handle_err ("pubsub_message_serialize", "data == NULL");
- return;
- }
-
- if (*data != NULL) {
- handle_err ("pubsub_message_serialize", "*data != NULL");
- return;
- }
-
- if (len == NULL) {
- handle_err ("pubsub_message_serialize", "len == NULL");
- return;
- }
-
- // buflen = pubsub msg type (1) + 2* size_t (16) + chan+data
- size_t buflen = 1 + 2 * sizeof (size_t) + msg->chanlen + msg->datalen;
-
- if (buflen > BUFSIZ) {
- handle_err ("pubsub_message_serialize", "chanlen + datalen too high");
- return;
- }
-
- char *buf = malloc (buflen);
- memset (buf, 0, buflen);
-
- size_t offset = 0;
-
- // msg type
- buf[offset++] = msg->type;
-
- // chan
- memcpy (buf + offset, &msg->chanlen, sizeof (size_t));
- offset += sizeof (size_t);
- memcpy (buf + offset, msg->chan, msg->chanlen);
- offset += msg->chanlen;
-
- // data
- memcpy (buf + offset, &msg->datalen, sizeof (size_t));
- offset += sizeof (size_t);
- memcpy (buf + offset, msg->data, msg->datalen);
- offset += msg->datalen;
-
- *data = buf;
- *len = buflen;
-}
-
-void pubsub_message_unserialize (struct pubsub_msg *msg, const char *buf, size_t mlen)
-{
- if (msg == NULL) {
- handle_err ("pubsub_message_unserialize", "msg == NULL");
- return;
- }
-
- pubsub_message_free (msg);
-
- if (mlen > BUFSIZ) {
- handle_err ("pubsub_message_unserialize", "mlen > BUFSIZ");
- return;
- }
-
- size_t offset = 0;
-
- // msg type
- msg->type = buf[offset++];
-
- // chan
- memcpy (&msg->chanlen, buf + offset, sizeof (size_t));
- if (msg->chanlen > BUFSIZ) {
- handle_err ("pubsub_message_unserialize", "chanlen > BUFSIZ");
- return;
- }
- msg->chan = malloc (msg->chanlen);
- memset (msg->chan, 0, msg->chanlen);
- offset += sizeof (size_t);
- memcpy (msg->chan, buf + offset, msg->chanlen);
- offset += msg->chanlen;
-
- // data
- memcpy (&msg->datalen, buf + offset, sizeof (size_t));
- if (msg->datalen > BUFSIZ) {
- handle_err ("pubsub_message_unserialize", "datalen > BUFSIZ");
- return;
- }
- msg->data = malloc (msg->datalen);
- memset (msg->data, 0, msg->datalen);
- offset += sizeof (size_t);
- memcpy (msg->data, buf + offset, msg->datalen);
- offset += msg->datalen;
-}
-
-void pubsub_message_free (struct pubsub_msg *msg)
-{
- if (msg == NULL) {
- handle_err ("pubsub_message_free", "msg == NULL");
- return;
- }
-
- if (msg->chan) {
- free (msg->chan);
- msg->chan = NULL;
- }
- if (msg->data) {
- free (msg->data);
- msg->data = NULL;
- }
-}
-
-void pubsub_message_print (const struct pubsub_msg *msg)
-{
- if (msg == NULL) {
- handle_err ("pubsub_message_print", "msg == NULL");
- return;
- }
-
- printf ("msg: type=%d chan=%s, data=%s\n"
- , msg->type, msg->chan, msg->data);
-}
diff --git a/pubsub/lib/msg.h b/pubsub/lib/msg.h
deleted file mode 100644
index 8154fff..0000000
--- a/pubsub/lib/msg.h
+++ /dev/null
@@ -1,21 +0,0 @@
-#ifndef __PUBSUB_MSG_H__
-#define __PUBSUB_MSG_H__
-
-#define PUBSUB_MSG_TYPE_SUB 1
-#define PUBSUB_MSG_TYPE_UNSUB 2
-#define PUBSUB_MSG_TYPE_PUB 3
-
-struct pubsub_msg {
- unsigned char type; // message type : alert, notification, …
- char *chan;
- size_t chanlen;
- char *data;
- size_t datalen;
-};
-
-void pubsub_message_serialize (const struct pubsub_msg *msg, char **data, size_t *len);
-void pubsub_message_unserialize (struct pubsub_msg *msg, const char *data, size_t len);
-void pubsub_message_free (struct pubsub_msg *msg);
-void pubsub_message_print (const struct pubsub_msg *msg);
-
-#endif
diff --git a/pubsub/lib/pubsub.h b/pubsub/lib/pubsub.h
index 0ae8c10..4f26f17 100644
--- a/pubsub/lib/pubsub.h
+++ b/pubsub/lib/pubsub.h
@@ -5,7 +5,7 @@
#include "../../core/client.h"
#include "../../core/queue.h"
-#include "msg.h"
+#include "message.h"
enum subscriber_action {PUBSUB_QUIT = 1, PUBSUB_PUB, PUBSUB_SUB, PUBSUB_BOTH};
diff --git a/pubsub/lib/pubsubd.c b/pubsub/lib/pubsubd.c
index ef8ec84..7122f61 100644
--- a/pubsub/lib/pubsubd.c
+++ b/pubsub/lib/pubsubd.c
@@ -1,5 +1,5 @@
#include "../../core/communication.h"
-#include "../../core/msg.h"
+#include "../../core/message.h"
#include "../../core/client.h"
#include "../../core/utils.h"
#include "../../core/error.h"
diff --git a/pubsub/lib/pubsubd.h b/pubsub/lib/pubsubd.h
index a8a4ac8..b63e9f6 100644
--- a/pubsub/lib/pubsubd.h
+++ b/pubsub/lib/pubsubd.h
@@ -3,8 +3,8 @@
// #include "../../core/pubsub.h"
#include "../../core/client.h"
-#include "../../core/msg.h"
-#include "msg.h"
+#include "../../core/message.h"
+#include "message.h"
#include "channels.h"
#define PUBSUBD_SERVICE_NAME "pubsubd"
diff --git a/pubsub/tests/msg.c b/pubsub/tests/msg.c
index 380bd30..df053d3 100644
--- a/pubsub/tests/msg.c
+++ b/pubsub/tests/msg.c
@@ -2,7 +2,7 @@
#include
#include
-#include "../lib/msg.h"
+#include "../lib/message.h"
#include "../../core/error.h"
#include "../../core/utils.h"
diff --git a/remote/app/remotec.c b/remote/app/remotec.c
index 5957779..5b55ee3 100644
--- a/remote/app/remotec.c
+++ b/remote/app/remotec.c
@@ -2,7 +2,7 @@
#include "../../core/error.h"
#include "../lib/remoted.h"
#include "../lib/remotec.h"
-#include "../lib/msg.h"
+#include "../lib/message.h"
#include
#include
diff --git a/remote/lib/msg.c b/remote/lib/message.c
similarity index 99%
rename from remote/lib/msg.c
rename to remote/lib/message.c
index e69beae..3c5b6e6 100644
--- a/remote/lib/msg.c
+++ b/remote/lib/message.c
@@ -2,7 +2,7 @@
#include
#include
-#include "msg.h"
+#include "message.h"
#include "../../core/error.h"
void remote_message_serialize (const struct remoted_msg *msg, char **data, size_t *len)
diff --git a/remote/lib/msg.h b/remote/lib/message.h
similarity index 100%
rename from remote/lib/msg.h
rename to remote/lib/message.h
diff --git a/remote/lib/remotec.c b/remote/lib/remotec.c
index 30bcdd3..e197b2e 100644
--- a/remote/lib/remotec.c
+++ b/remote/lib/remotec.c
@@ -1,6 +1,6 @@
#include "../../core/communication.h"
#include "../../core/error.h"
-#include "msg.h"
+#include "message.h"
#include "remotec.h"
#include "remoted.h"
#include
diff --git a/remote/lib/remotec.h b/remote/lib/remotec.h
index ee18291..551a6b7 100644
--- a/remote/lib/remotec.h
+++ b/remote/lib/remotec.h
@@ -2,7 +2,7 @@
#define __REMOTEC_H__
#include "../../core/client.h"
-#include "../../core/msg.h"
+#include "../../core/message.h"
#include "remoted.h"
/* TODO */
diff --git a/remote/lib/remoted.c b/remote/lib/remoted.c
index 61c2e67..d4c0d78 100644
--- a/remote/lib/remoted.c
+++ b/remote/lib/remoted.c
@@ -1,5 +1,5 @@
#include "../../core/communication.h"
-#include "../../core/msg.h"
+#include "../../core/message.h"
#include "../../core/client.h"
#include "../../core/utils.h"
#include "../../core/error.h"
diff --git a/remote/lib/remoted.h b/remote/lib/remoted.h
index 81f4b29..4f49039 100644
--- a/remote/lib/remoted.h
+++ b/remote/lib/remoted.h
@@ -2,8 +2,8 @@
#define __REMOTED_H__
#include "../../core/client.h"
-#include "../../core/msg.h"
-#include "msg.h"
+#include "../../core/message.h"
+#include "message.h"
#define REMOTED_SERVICE_NAME "remoted"