Obsolete
/
libipc-old
Archived
3
0
Fork 0

renaming msg.[ch] in message.[ch]

more_to_read
Philippe PITTOLI 2018-10-09 13:20:26 +02:00
parent ce7351458b
commit b1078dfe98
18 changed files with 16 additions and 169 deletions

View File

@ -2,7 +2,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "../../core/msg.h" #include "../../core/message.h"
#include "../../core/error.h" #include "../../core/error.h"
#include "../../core/communication.h" #include "../../core/communication.h"

View File

@ -5,7 +5,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <errno.h> // error numbers #include <errno.h> // error numbers
#include "msg.h" #include "message.h"
#include "client.h" #include "client.h"

View File

@ -1,4 +1,4 @@
#include "msg.h" #include "message.h"
#include "error.h" #include "error.h"
#include "usocket.h" #include "usocket.h"

View File

@ -3,7 +3,7 @@
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include "../../core/msg.h" #include "../../core/message.h"
#include "../../core/error.h" #include "../../core/error.h"
#include "../../core/communication.h" #include "../../core/communication.h"

View File

@ -1,132 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#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);
}

View File

@ -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

View File

@ -5,7 +5,7 @@
#include "../../core/client.h" #include "../../core/client.h"
#include "../../core/queue.h" #include "../../core/queue.h"
#include "msg.h" #include "message.h"
enum subscriber_action {PUBSUB_QUIT = 1, PUBSUB_PUB, PUBSUB_SUB, PUBSUB_BOTH}; enum subscriber_action {PUBSUB_QUIT = 1, PUBSUB_PUB, PUBSUB_SUB, PUBSUB_BOTH};

View File

@ -1,5 +1,5 @@
#include "../../core/communication.h" #include "../../core/communication.h"
#include "../../core/msg.h" #include "../../core/message.h"
#include "../../core/client.h" #include "../../core/client.h"
#include "../../core/utils.h" #include "../../core/utils.h"
#include "../../core/error.h" #include "../../core/error.h"

View File

@ -3,8 +3,8 @@
// #include "../../core/pubsub.h" // #include "../../core/pubsub.h"
#include "../../core/client.h" #include "../../core/client.h"
#include "../../core/msg.h" #include "../../core/message.h"
#include "msg.h" #include "message.h"
#include "channels.h" #include "channels.h"
#define PUBSUBD_SERVICE_NAME "pubsubd" #define PUBSUBD_SERVICE_NAME "pubsubd"

View File

@ -2,7 +2,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "../lib/msg.h" #include "../lib/message.h"
#include "../../core/error.h" #include "../../core/error.h"
#include "../../core/utils.h" #include "../../core/utils.h"

View File

@ -2,7 +2,7 @@
#include "../../core/error.h" #include "../../core/error.h"
#include "../lib/remoted.h" #include "../lib/remoted.h"
#include "../lib/remotec.h" #include "../lib/remotec.h"
#include "../lib/msg.h" #include "../lib/message.h"
#include <stdlib.h> #include <stdlib.h>
#include <pthread.h> #include <pthread.h>

View File

@ -2,7 +2,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "msg.h" #include "message.h"
#include "../../core/error.h" #include "../../core/error.h"
void remote_message_serialize (const struct remoted_msg *msg, char **data, size_t *len) void remote_message_serialize (const struct remoted_msg *msg, char **data, size_t *len)

View File

@ -1,6 +1,6 @@
#include "../../core/communication.h" #include "../../core/communication.h"
#include "../../core/error.h" #include "../../core/error.h"
#include "msg.h" #include "message.h"
#include "remotec.h" #include "remotec.h"
#include "remoted.h" #include "remoted.h"
#include <stdio.h> #include <stdio.h>

View File

@ -2,7 +2,7 @@
#define __REMOTEC_H__ #define __REMOTEC_H__
#include "../../core/client.h" #include "../../core/client.h"
#include "../../core/msg.h" #include "../../core/message.h"
#include "remoted.h" #include "remoted.h"
/* TODO */ /* TODO */

View File

@ -1,5 +1,5 @@
#include "../../core/communication.h" #include "../../core/communication.h"
#include "../../core/msg.h" #include "../../core/message.h"
#include "../../core/client.h" #include "../../core/client.h"
#include "../../core/utils.h" #include "../../core/utils.h"
#include "../../core/error.h" #include "../../core/error.h"

View File

@ -2,8 +2,8 @@
#define __REMOTED_H__ #define __REMOTED_H__
#include "../../core/client.h" #include "../../core/client.h"
#include "../../core/msg.h" #include "../../core/message.h"
#include "msg.h" #include "message.h"
#define REMOTED_SERVICE_NAME "remoted" #define REMOTED_SERVICE_NAME "remoted"