More stuff done
This commit is contained in:
parent
da345fc422
commit
897c8150a5
4 changed files with 147 additions and 12 deletions
|
|
@ -1,3 +1,62 @@
|
|||
int main(){
|
||||
#include "../../libs/communication/communication.h"
|
||||
#include "../../libs/protocol/protocol.h"
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int main() {
|
||||
|
||||
unsigned char buffer[MESSAGE_SIZE];
|
||||
read(0, buffer, MESSAGE_SIZE);
|
||||
message msg;
|
||||
deserialize_message(buffer, MESSAGE_SIZE, &msg);
|
||||
|
||||
if (msg.header.isgroup) {
|
||||
const char *directory_format = "/opt/djumbai/group/%d/";
|
||||
char group_path[50];
|
||||
sprintf(group_path, directory_format, msg.header.receiver);
|
||||
char message_box_path[70];
|
||||
sprintf(message_box_path, group_path, "message_box/");
|
||||
|
||||
struct stat st;
|
||||
if (stat(group_path, &st) == -1) {
|
||||
// Directory doesn't exist, so create it
|
||||
if (mkdir(group_path, 0070) == -1) {
|
||||
perror("mkdir");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
if (stat(message_box_path, &st) == -1) {
|
||||
// Directory doesn't exist, so create it
|
||||
if (mkdir(message_box_path, 0070) == -1) {
|
||||
perror("mkdir");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
chroot(message_box_path);
|
||||
//Do the rest
|
||||
} else {
|
||||
|
||||
// struct stat st;
|
||||
// if (stat(user_path, &st) == -1) {
|
||||
// // Directory doesn't exist, so create it
|
||||
// if (mkdir(user_path, 0700) == -1) {
|
||||
// perror("mkdir");
|
||||
// return EXIT_FAILURE;
|
||||
// }
|
||||
// }
|
||||
// if (stat(message_box_path, &st) == -1) {
|
||||
// // Directory doesn't exist, so create it
|
||||
// if (mkdir(message_box_path, 0700) == -1) {
|
||||
// perror("mkdir");
|
||||
// return EXIT_FAILURE;
|
||||
// }
|
||||
// }
|
||||
// chroot(message_box_path);
|
||||
//
|
||||
// Message receiver is a user
|
||||
// Write to the user's mailbox
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue