fix: groupID wrong type, function headers

This commit is contained in:
Tiago Sousa 2024-05-12 23:04:01 +01:00
parent a81b245852
commit f372af3cc3
Signed by: tiago
SSH key fingerprint: SHA256:odOD9vln9U7qNe1R8o3UCbE3jkQCkr5/q5mgd5hwua0

View file

@ -1,11 +1,14 @@
#include <dirent.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <dirent.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <time.h>
#include <unistd.h>
void displayMessagesFromSender(char *senderDir);
void displayMessage(char *senderDir, char *filename);
void displayHeader() {
printf("╭━━━╮╱╱╱╱╱╱╭╮\n");
@ -21,7 +24,8 @@ void displayHeader() {
void displayAllMessages(uid_t userID) {
char userDir[256];
sprintf(userDir, "/djumbai/user/%d/mailbox", userID); // Construct user directory path
// sprintf(userDir, "/mnt/e/Desktop/CSI/djumbai/test/%d/mailbox", userID); // TODO MUDAR ESTE PATH
// sprintf(userDir, "/mnt/e/Desktop/CSI/djumbai/test/%d/mailbox", userID); // TODO MUDAR ESTE
// PATH
DIR *dir;
struct dirent *entry;
@ -34,7 +38,8 @@ void displayAllMessages(uid_t userID) {
}
while ((entry = readdir(dir)) != NULL) {
if (entry->d_type == DT_DIR && strcmp(entry->d_name, ".") != 0 && strcmp(entry->d_name, "..") != 0) {
if (entry->d_type == DT_DIR && strcmp(entry->d_name, ".") != 0 &&
strcmp(entry->d_name, "..") != 0) {
char senderDir[256];
sprintf(senderDir, "%s/%s", userDir, entry->d_name); // Construct sender directory path
displayMessagesFromSender(senderDir);
@ -44,9 +49,7 @@ void displayAllMessages(uid_t userID) {
closedir(dir);
}
void displayGroupMessages(uid_t groupID) {
void displayGroupMessages(gid_t groupID) {
char groupDir[256];
sprintf(groupDir, "/djumbai/group/%d/mailbox", groupID);
DIR *dir;
@ -61,7 +64,8 @@ void displayGroupMessages(uid_t groupID) {
}
while ((entry = readdir(dir)) != NULL) {
if (entry->d_type == DT_DIR && strcmp(entry->d_name, ".") != 0 && strcmp(entry->d_name, "..") != 0) {
if (entry->d_type == DT_DIR && strcmp(entry->d_name, ".") != 0 &&
strcmp(entry->d_name, "..") != 0) {
char senderDir[256];
sprintf(senderDir, "%s/%s", groupDir, entry->d_name); // Construct sender directory path
displayMessagesFromSender(senderDir);
@ -71,9 +75,6 @@ void displayGroupMessages(uid_t groupID) {
closedir(dir);
}
void displayMessagesFromSender(char *senderDir) {
char *senderName = strrchr(senderDir, '/'); // Find the last occurrence of '/'
if (senderName == NULL) {
@ -102,8 +103,6 @@ void displayMessagesFromSender(char *senderDir) {
closedir(dir);
}
void displayMessage(char *senderDir, char *filename) {
char filepath[256];
sprintf(filepath, "%s/%s", senderDir, filename);
@ -126,7 +125,7 @@ void displayMessage(char *senderDir, char *filename) {
int main() {
int choice;
char sender[20];
char groupID[20];
char group[20];
displayHeader();
@ -156,7 +155,8 @@ int main() {
break;
case 3:
printf("Enter groupID: ");
scanf("%s", groupID);
scanf("%s", group);
gid_t groupID = atoi(group);
displayGroupMessages(groupID);
printf("Group messages functionality is not implemented yet.\n");
break;