djumbai/libs/protocol/protocol.h
2024-05-11 12:39:00 +01:00

36 lines
895 B
C

#ifndef PROTOCOL_H
#define PROTOCOL_H
#include <limits.h>
#include <stdint.h>
#include <string.h>
#include <time.h>
#define VERSION 1
#define MAX_CONTENT_SIZE (PIPE_BUF - sizeof(struct MessageHeader))
#define MESSAGE_SIZE (sizeof(struct Message))
typedef struct MessageHeader {
// The protocol's version
unsigned int version;
// The sender is a user
unsigned int sender;
// Flag indicating if the receiver is a group
unsigned int isgroup;
// The receiver is either a user or a group
unsigned int receiver;
// The message was sent at this timestamp
time_t timestamp;
} message_header;
typedef struct Message {
// The message's header
message_header header;
// The buffer holding the message
char content[MAX_CONTENT_SIZE];
} message;
int new_message(message *m, unsigned int sender, unsigned int isgroup, unsigned int receiver, char *content);
#endif // !PROTOCOL_H