DOESN'T COMPILE - Started working on adding message to stack

master
Aadhavan Srinivasan 2 years ago
parent df9a05a56e
commit ad70f43da9

@ -11,6 +11,7 @@
#include "easysock.h" #include "easysock.h"
#include "file_helpers.h" #include "file_helpers.h"
#include "message_helpers.h" #include "message_helpers.h"
#include "stack.h"
#define BUFFER_SIZE 10000 #define BUFFER_SIZE 10000
#define MAX_CONNECTIONS 100 #define MAX_CONNECTIONS 100
@ -34,16 +35,21 @@ int main() {
socklen_t temp_addrlen; socklen_t temp_addrlen;
fd_set read_fd_set; fd_set read_fd_set;
int conn_sockets[MAX_CONNECTIONS] = {-1}; int conn_sockets[MAX_CONNECTIONS] = {-1};
User* to_user[MAX_CONNECTIONS] = {NULL}; User* to_user[MAX_CONNECTIONS] = {NULL};
User* from_user[MAX_CONNECTIONS] = {NULL}; User* from_user[MAX_CONNECTIONS] = {NULL};
FD_ZERO(&read_fd_set); FD_ZERO(&read_fd_set); char buffer[BUFFER_SIZE];
char buffer[BUFFER_SIZE]; char data[DATA_SIZE];
char data[DATA_SIZE];
num_users = num_of_lines("user_file.txt"); num_users = num_of_lines("user_file.txt");
users = create_user_list("user_file.txt"); users = create_user_list("user_file.txt");
Stack* message_stack[num_users];
for (int i=0;i < num_users; i++) {
message_stack[i] = new_stack(10);
}
struct sockaddr addr_struct; struct sockaddr addr_struct;
int server_sock = create_local(4,'T',"127.0.0.1",30000,&addr_struct); int server_sock = create_local(4,'T',"127.0.0.1",30000,&addr_struct);
conn_sockets[0] = server_sock; conn_sockets[0] = server_sock;
@ -107,13 +113,18 @@ int main() {
} }
} }
char* message = fetch_message_string(data); char* message_string = fetch_message_string(data);
if (message == NULL) { if (message_string == NULL) {
printf("Invalid message.\n"); printf("Invalid message.\n");
return -10; return -10;
} }
printf("Your message is: %s\n",message); printf("Your message is: %s\n",message_string);
Message message = new_message(message_string,from_user[i],to_user[i]);
stack_push( message_stack[user_to_index(to_user[i])],message );
close(conn_sockets[i]); close(conn_sockets[i]);
@ -192,3 +203,24 @@ User* fetch_user(char* username) {
return NULL; return NULL;
} }
int user_to_index(User* user) {
int index = 0;
for (int i=0;i < num_users; i++) {
if (user_equals(users[i],user) == true) {
index = i;
break;
}
}
return index;
}
bool user_equals(User* this, User* other) {
if (( strcmp(this->username,other->username) == 0 ) && ( strcmp(this->password,other->password) == 0 )) {
return true;
} else {
return false;
}
}

Loading…
Cancel
Save