fix: groupID wrong type, function headers
This commit is contained in:
parent
a81b245852
commit
f372af3cc3
1 changed files with 132 additions and 132 deletions
|
@ -1,11 +1,14 @@
|
||||||
|
#include <dirent.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
|
||||||
#include <dirent.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <sys/types.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
void displayMessagesFromSender(char *senderDir);
|
||||||
|
void displayMessage(char *senderDir, char *filename);
|
||||||
|
|
||||||
void displayHeader() {
|
void displayHeader() {
|
||||||
printf("╭━━━╮╱╱╱╱╱╱╭╮\n");
|
printf("╭━━━╮╱╱╱╱╱╱╭╮\n");
|
||||||
|
@ -21,7 +24,8 @@ void displayHeader() {
|
||||||
void displayAllMessages(uid_t userID) {
|
void displayAllMessages(uid_t userID) {
|
||||||
char userDir[256];
|
char userDir[256];
|
||||||
sprintf(userDir, "/djumbai/user/%d/mailbox", userID); // Construct user directory path
|
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;
|
DIR *dir;
|
||||||
struct dirent *entry;
|
struct dirent *entry;
|
||||||
|
|
||||||
|
@ -34,7 +38,8 @@ void displayAllMessages(uid_t userID) {
|
||||||
}
|
}
|
||||||
|
|
||||||
while ((entry = readdir(dir)) != NULL) {
|
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];
|
char senderDir[256];
|
||||||
sprintf(senderDir, "%s/%s", userDir, entry->d_name); // Construct sender directory path
|
sprintf(senderDir, "%s/%s", userDir, entry->d_name); // Construct sender directory path
|
||||||
displayMessagesFromSender(senderDir);
|
displayMessagesFromSender(senderDir);
|
||||||
|
@ -44,9 +49,7 @@ void displayAllMessages(uid_t userID) {
|
||||||
closedir(dir);
|
closedir(dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void displayGroupMessages(gid_t groupID) {
|
||||||
|
|
||||||
void displayGroupMessages(uid_t groupID) {
|
|
||||||
char groupDir[256];
|
char groupDir[256];
|
||||||
sprintf(groupDir, "/djumbai/group/%d/mailbox", groupID);
|
sprintf(groupDir, "/djumbai/group/%d/mailbox", groupID);
|
||||||
DIR *dir;
|
DIR *dir;
|
||||||
|
@ -61,7 +64,8 @@ void displayGroupMessages(uid_t groupID) {
|
||||||
}
|
}
|
||||||
|
|
||||||
while ((entry = readdir(dir)) != NULL) {
|
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];
|
char senderDir[256];
|
||||||
sprintf(senderDir, "%s/%s", groupDir, entry->d_name); // Construct sender directory path
|
sprintf(senderDir, "%s/%s", groupDir, entry->d_name); // Construct sender directory path
|
||||||
displayMessagesFromSender(senderDir);
|
displayMessagesFromSender(senderDir);
|
||||||
|
@ -71,9 +75,6 @@ void displayGroupMessages(uid_t groupID) {
|
||||||
closedir(dir);
|
closedir(dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void displayMessagesFromSender(char *senderDir) {
|
void displayMessagesFromSender(char *senderDir) {
|
||||||
char *senderName = strrchr(senderDir, '/'); // Find the last occurrence of '/'
|
char *senderName = strrchr(senderDir, '/'); // Find the last occurrence of '/'
|
||||||
if (senderName == NULL) {
|
if (senderName == NULL) {
|
||||||
|
@ -102,8 +103,6 @@ void displayMessagesFromSender(char *senderDir) {
|
||||||
closedir(dir);
|
closedir(dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void displayMessage(char *senderDir, char *filename) {
|
void displayMessage(char *senderDir, char *filename) {
|
||||||
char filepath[256];
|
char filepath[256];
|
||||||
sprintf(filepath, "%s/%s", senderDir, filename);
|
sprintf(filepath, "%s/%s", senderDir, filename);
|
||||||
|
@ -126,7 +125,7 @@ void displayMessage(char *senderDir, char *filename) {
|
||||||
int main() {
|
int main() {
|
||||||
int choice;
|
int choice;
|
||||||
char sender[20];
|
char sender[20];
|
||||||
char groupID[20];
|
char group[20];
|
||||||
|
|
||||||
displayHeader();
|
displayHeader();
|
||||||
|
|
||||||
|
@ -156,7 +155,8 @@ int main() {
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
printf("Enter groupID: ");
|
printf("Enter groupID: ");
|
||||||
scanf("%s", groupID);
|
scanf("%s", group);
|
||||||
|
gid_t groupID = atoi(group);
|
||||||
displayGroupMessages(groupID);
|
displayGroupMessages(groupID);
|
||||||
printf("Group messages functionality is not implemented yet.\n");
|
printf("Group messages functionality is not implemented yet.\n");
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in a new issue