|
|
|
@ -93,6 +93,8 @@ int main() {
|
|
|
|
|
strcat(data, buffer);
|
|
|
|
|
}
|
|
|
|
|
strcat(data,"\0");
|
|
|
|
|
|
|
|
|
|
if (strcmp(strtok(data," \r\n"), "SENDING") == 0) {
|
|
|
|
|
if (from_user[i] == NULL) {
|
|
|
|
|
from_user[i] = fetch_user(fetch_from_string(data,"IAM"));
|
|
|
|
|
if (from_user[i] == NULL) {
|
|
|
|
@ -133,7 +135,51 @@ int main() {
|
|
|
|
|
|
|
|
|
|
printf("Message has been pushed onto stack for %s\n",to_user[i]->username);
|
|
|
|
|
|
|
|
|
|
} else if (strcmp(strtok(buffer," \r\n"), "SENDING") == 0) {
|
|
|
|
|
|
|
|
|
|
if (from_user[i] == NULL) {
|
|
|
|
|
from_user[i] = fetch_user(fetch_from_string(data,"IAM"));
|
|
|
|
|
if (from_user[i] == NULL) {
|
|
|
|
|
printf("Please identify yourself.\n");
|
|
|
|
|
close(conn_sockets[i]);
|
|
|
|
|
continue;
|
|
|
|
|
} else {
|
|
|
|
|
printf("You are %s\n",from_user[i]->username);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int num_of_messages;
|
|
|
|
|
char* num_of_messages_string = fetch_from_string(data,"GETLAST");
|
|
|
|
|
|
|
|
|
|
if (num_of_messages_string == NULL) {
|
|
|
|
|
printf("Invalid GET request.\n");
|
|
|
|
|
return -30;
|
|
|
|
|
} else {
|
|
|
|
|
if (strstr(num_of_messages_string,"ALL") == 0) {
|
|
|
|
|
num_of_messages = stack_size(message_stack[user_to_index(from_user[i])]);
|
|
|
|
|
} else {
|
|
|
|
|
num_of_messages = atoi(num_of_messages_string);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (num_of_messages > stack_size(message_stack[user_to_index(from_user[i])])) {
|
|
|
|
|
num_of_messages = stack_size(message_stack[user_to_index(from_user[i])]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int i=0;i<num_of_messages;i++) {
|
|
|
|
|
Message* message = stack_pop(message_stack[user_to_index(from_user[i])]);
|
|
|
|
|
printf("You have a message from %s"
|
|
|
|
|
", sent at %s"
|
|
|
|
|
": \"%s\"\n",
|
|
|
|
|
message->sender->username,
|
|
|
|
|
asctime(message->timeinfo),
|
|
|
|
|
message->text);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
printf("You are not sending or receiving.\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
close(conn_sockets[i]);
|
|
|
|
|
|
|
|
|
|