Skip to content

Commit

Permalink
minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Polina Balazhy committed Feb 6, 2022
1 parent e222959 commit f52d6f4
Show file tree
Hide file tree
Showing 18 changed files with 69 additions and 59 deletions.
13 changes: 7 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ OBJS = $(OBJDIR)/*.o
all: $(LIBMX) $(UTILSLIB) $(CJSON) $(SQLITE) $(SERVER) $(CLIENT)

$(LIBMX):
make -sC $(LIBMX_DIR)
# make -sC $(LIBMX_DIR)

$(UTILSLIB):
make -sC $(UTILSLIB_DIR)

$(CJSON):
make -sC $(CJSON_DIR)
# make -sC $(CJSON_DIR)

$(SQLITE):
make -sC $(SQLITE_DIR)
# make -sC $(SQLITE_DIR)

$(SERVER):
make -sC $(SERVER_DIR)
Expand All @@ -41,6 +41,7 @@ $(CLIENT):
make -sC $(CLIENT_DIR)

font:
@mkdir -p ${HOME}/Library/Fonts
@cp client/data/fonts/Poppins/* ${HOME}/Library/Fonts/

clean:
Expand All @@ -51,9 +52,9 @@ uninstall:
make -sC $(SERVER_DIR) $@
make -sC $(CLIENT_DIR) $@
make -sC $(UTILSLIB_DIR) $@
make -sC $(LIBMX_DIR) $@
make -sC $(CJSON_DIR) $@
make -sC $(SQLITE_DIR) $@
# make -sC $(LIBMX_DIR) $@
# make -sC $(CJSON_DIR) $@
# make -sC $(SQLITE_DIR) $@
make clean
rm -f $(UCHAT)

Expand Down
6 changes: 3 additions & 3 deletions client/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
CC = clang
CFLAGS = -std=gnu11 -pthread -g
# CFLAGS = -std=gnu11 -pthread -g
# -Wall -Wextra -Werror -Wpedantic
# CFLAGS = -std=c11 -Wall -Wextra -Werror -Wpedantic -pthread -g
CFLAGS = -std=c11 -Wall -Wextra -Werror -Wpedantic -pthread -g

UTIL_DIRS = data/avatars
OBJDIR = obj
Expand Down Expand Up @@ -31,7 +31,7 @@ LIB_FLAGS = -lmx -lcjson -lsqlite3 -lssl -lcrypto\
-L$(UTILSLIB_DIR) $(UTILSLIB_NAME)\
-L$(LIBMX_DIR) $(LIBMX_NAME)\
-L$(CJSON_DIR) $(CJSON_NAME)\
# -L$(SSL_FILES) -I$(SSL_INC_FILES)
-L$(SSL_FILES) -I$(SSL_INC_FILES)

all: $(UCHAT)

Expand Down
6 changes: 3 additions & 3 deletions client/src/gui/build_change_avatar_window.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ void change_avatar_btn_click(GtkWidget *widget, gpointer data) {
GtkWidget *toplevel = gtk_widget_get_toplevel(widget);
(void)data;

GtkWidget *path_field = get_widget_by_name_r(toplevel, "path_field");
GtkWidget *path_notify_label = get_widget_by_name_r(toplevel, "path_notify_label");
// GtkWidget *path_field = get_widget_by_name_r(toplevel, "path_field");
// GtkWidget *path_notify_label = get_widget_by_name_r(toplevel, "path_notify_label");

char *new_avatar = (char*)gtk_entry_get_text(GTK_ENTRY(path_field));
// char *new_avatar = (char*)gtk_entry_get_text(GTK_ENTRY(path_field));

// handle_update_user_image(new_avatar);
// usleep(4000000);
Expand Down
8 changes: 8 additions & 0 deletions client/src/gui/handle_response_code.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ void handle_signup_response_code(int response_code, GtkWidget *signup_notify_lab
case R_USR_EXISTS:
set_notify_error_style(signup_notify_label, get_response_str(R_USR_EXISTS));
break;

case R_NAME_LEN_INVALID:
set_notify_error_style(signup_notify_label, get_response_str(R_NAME_LEN_INVALID));
break;

case R_PASS_LEN_INVALID:
set_notify_error_style(signup_notify_label, get_response_str(R_PASS_LEN_INVALID));
break;

default:
break;
Expand Down
16 changes: 8 additions & 8 deletions client/src/request_handlers/get_user_image.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ void recv_image_from_server(int *socket, unsigned char **buffer, size_t length)
}
}

static char* get_file_path_for(int user_id) {
// static char* get_file_path_for(int user_id) {

char* id_str = mx_itoa(user_id);
char* file_name = mx_strnew(mx_strlen(AVATAR_PATH) + mx_strlen(id_str) + 9);
mx_strcat(file_name, AVATAR_PATH);
mx_strcat(file_name, id_str);
mx_strcat(file_name, "_user.png");
return file_name;
// char* id_str = mx_itoa(user_id);
// char* file_name = mx_strnew(mx_strlen(AVATAR_PATH) + mx_strlen(id_str) + 9);
// mx_strcat(file_name, AVATAR_PATH);
// mx_strcat(file_name, id_str);
// mx_strcat(file_name, "_user.png");
// return file_name;

}
// }

// t_response_code handle_get_user_image(int user_id, char** avatar_path) {

Expand Down
4 changes: 2 additions & 2 deletions libraries/cjson/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ INC_FILES = $(wildcard $(INC_DIR)/*.h)

CC = clang

CFLAGS = -std=gnu11 -Wall -Wextra -Werror -Wpedantic
# CFLAGS = -std=c11 -Wall -Wextra -Werror -Wpedantic
# CFLAGS = -std=gnu11 -Wall -Wextra -Werror -Wpedantic
CFLAGS = -std=c11 -Wall -Wextra -Werror -Wpedantic

all: $(NAME)

Expand Down
4 changes: 2 additions & 2 deletions libraries/libmx/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
CC = clang
CFLAGS = -std=gnu11 -Wall -Wextra -Werror -Wpedantic
# CFLAGS = -std=c11 -Wall -Wextra -Werror -Wpedantic
# CFLAGS = -std=gnu11 -Wall -Wextra -Werror -Wpedantic
CFLAGS = -std=c11 -Wall -Wextra -Werror -Wpedantic

OBJDIR = obj
SRCDIR = src
Expand Down
4 changes: 2 additions & 2 deletions libraries/sqlite/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ OBJ_FILES = $(addprefix $(OBJ_DIR)/, $(notdir $(SRC_FILES:%.c=%.o)))
INC_FILES = $(wildcard $(INC_DIR)/*.h)

CC = clang
CFLAGS = -std=gnu11 -Wall -Wextra -Werror -Wpedantic
# CFLAGS = -std=c11 -Wall -Wextra -Werror -Wpedantic
# CFLAGS = -std=gnu11 -Wall -Wextra -Werror -Wpedantic
CFLAGS = -std=c11 -Wall -Wextra -Werror -Wpedantic

all: $(NAME)

Expand Down
6 changes: 3 additions & 3 deletions server/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
CC = clang
CFLAGS = -std=gnu11 -pthread -g
# CFLAGS = -std=gnu11 -pthread -g
# -Wall -Wextra -Werror -Wpedantic
# CFLAGS = -std=c11 -Wall -Wextra -Werror -Wpedantic -pthread -g
CFLAGS = -std=c11 -Wall -Wextra -Werror -Wpedantic -pthread -g

OBJDIR = obj
SRCDIR = src src/api src/server_utils src/database
Expand All @@ -28,7 +28,7 @@ LIB_FLAGS = -lmx -lcjson -lsqlite3 -lssl -lcrypto \
-L$(UTILSLIB_DIR) $(UTILSLIB_NAME) \
-L$(LIBMX_DIR) $(LIBMX_NAME) \
-L$(CJSON_DIR) $(CJSON_NAME) \
# -L$(SSL_FILES) -I$(SSL_INC_FILES)
-L$(SSL_FILES) -I$(SSL_INC_FILES)

all: $(UCHAT)

Expand Down
8 changes: 4 additions & 4 deletions server/src/api/handle_create_chat.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ void handle_create_chat(const cJSON* chat_info, t_server_utils* utils) {
return;
}

// if (!is_strlen_valid(chat_name->valuestring, MIN_NAME_INPUT_LEN, MAX_NAME_INPUT_LEN)) {
// send_server_response(utils->ssl, R_NAME_LEN_INVALID, REQ_CREATE_CHAT);
// return;
// }
if (!is_strlen_valid(chat_name->valuestring, MIN_NAME_INPUT_LEN, MAX_NAME_INPUT_LEN)) {
send_server_response(utils->ssl, R_NAME_LEN_INVALID, REQ_CREATE_CHAT);
return;
}

if (!is_user_name_format_valid(chat_name->valuestring)) {
send_server_response(utils->ssl, R_NAME_FORMAT_INVALID, REQ_CREATE_CHAT);
Expand Down
4 changes: 2 additions & 2 deletions server/src/api/handle_delete_chat.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ t_response_code db_delete_chat(const char* chat_name, int chat_id) {

}

int db_delete_member(int chat_id, t_server_utils* utils) {
int db_delete_member(int chat_id) {

char query[QUERY_LEN];
sprintf(query, "DELETE FROM `members` WHERE `chat_id` = '%d'", chat_id);
Expand Down Expand Up @@ -71,7 +71,7 @@ void handle_delete_chat(const cJSON* chat_info, t_server_utils* utils) {
return;
}

if (db_delete_member(chat_id, utils) != 0) {
if (db_delete_member(chat_id) != 0) {
send_server_response(utils->ssl, R_DB_FAILURE, REQ_DELETE_CHAT);
return;
}
Expand Down
8 changes: 4 additions & 4 deletions server/src/api/handle_edit_chat.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ void handle_edit_chat(const cJSON* chat_info, t_server_utils* utils) {
return;
}

// if (!is_strlen_valid(chat_name->valuestring, MIN_NAME_INPUT_LEN, MAX_NAME_INPUT_LEN)) {
// send_server_response(utils->ssl, R_NAME_LEN_INVALID, REQ_EDIT_CHAT);
// return;
// }
if (!is_strlen_valid(new_name->valuestring, MIN_NAME_INPUT_LEN, MAX_NAME_INPUT_LEN)) {
send_server_response(utils->ssl, R_NAME_LEN_INVALID, REQ_EDIT_CHAT);
return;
}

if (!is_user_name_format_valid(new_name->valuestring)) {
send_server_response(utils->ssl, R_NAME_FORMAT_INVALID, REQ_EDIT_CHAT);
Expand Down
16 changes: 8 additions & 8 deletions server/src/api/handle_edit_login_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ void handle_edit_username(const cJSON* user_info, t_server_utils* utils) {
return;
}

// if (!is_strlen_valid(new_name->valuestring, MIN_NAME_INPUT_LEN, MAX_NAME_INPUT_LEN)) {
// send_server_response(utils->ssl, R_NAME_LEN_INVALID, REQ_EDIT_USERNAME);
// return;
// }
if (!is_strlen_valid(new_name->valuestring, MIN_NAME_INPUT_LEN, MAX_NAME_INPUT_LEN)) {
send_server_response(utils->ssl, R_NAME_LEN_INVALID, REQ_EDIT_USERNAME);
return;
}

if (!is_user_name_format_valid(new_name->valuestring)) {
send_server_response(utils->ssl, R_NAME_FORMAT_INVALID, REQ_EDIT_USERNAME);
Expand Down Expand Up @@ -84,10 +84,10 @@ void handle_edit_password(const cJSON* pass_info, t_server_utils* utils) {
return;
}

// if (!is_strlen_valid(new_pass->valuestring, MIN_PASS_INPUT_LEN, MAX_PASS_INPUT_LEN)) {
// send_server_response(utils->ssl, R_PASS_LEN_INVALID, REQ_EDIT_PASSWORD);
// return;
// }
if (!is_strlen_valid(new_pass->valuestring, MIN_PASS_INPUT_LEN, MAX_PASS_INPUT_LEN)) {
send_server_response(utils->ssl, R_PASS_LEN_INVALID, REQ_EDIT_PASSWORD);
return;
}

if ((error_code = db_modify_password(utils->user->user_id, new_pass->valuestring)) != R_SUCCESS) {
send_server_response(utils->ssl, error_code, REQ_EDIT_PASSWORD);
Expand Down
4 changes: 2 additions & 2 deletions server/src/api/handle_last_msg_id.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "../../inc/server.h"

t_response_code get_last_msg_id(const cJSON* chat_info, t_server_utils* utils, int* last_msg_id) {
t_response_code get_last_msg_id(const cJSON* chat_info, int* last_msg_id) {

const cJSON *chat_id = cJSON_GetObjectItemCaseSensitive(chat_info, "chat_id");
if (!cJSON_IsNumber(chat_id)) {
Expand Down Expand Up @@ -33,7 +33,7 @@ void handle_last_msg_id(const cJSON* chat_info, t_server_utils* utils) {
}
int last_msg_id = -1;
int error_code = 0;
if ((error_code = get_last_msg_id(chat_info, utils, &last_msg_id)) != R_SUCCESS) {
if ((error_code = get_last_msg_id(chat_info, &last_msg_id)) != R_SUCCESS) {
send_server_response(utils->ssl, error_code, REQ_LAST_MSG_ID);
return;
}
Expand Down
14 changes: 7 additions & 7 deletions server/src/api/handle_usr_signup.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ t_response_code db_add_user(const cJSON* user_info) {
return R_USR_EXISTS;
}

// if (!is_strlen_valid(user_name->valuestring, MIN_NAME_INPUT_LEN, MAX_NAME_INPUT_LEN)) {
// return R_NAME_LEN_INVALID;
// }
// if (!is_strlen_valid(user_password->valuestring, MIN_PASS_INPUT_LEN, MAX_PASS_INPUT_LEN)) {
// return R_PASS_LEN_INVALID;
// }

if (!is_strlen_valid(user_name->valuestring, MIN_NAME_INPUT_LEN, MAX_NAME_INPUT_LEN)) {
return R_NAME_LEN_INVALID;
}
if (!is_user_name_format_valid(user_name->valuestring)) {
return R_NAME_FORMAT_INVALID;
}

if (!is_strlen_valid(user_password->valuestring, MIN_PASS_INPUT_LEN, MAX_PASS_INPUT_LEN)) {
return R_PASS_LEN_INVALID;
}

char query[QUERY_LEN];
sprintf(query, "INSERT INTO `users` (`username`, `password`, `avatar_color`) VALUES('%s', '%s', '%d')",
Expand Down
2 changes: 1 addition & 1 deletion server/src/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ int main(int argc, char *argv[]) {
int client_socket;
socklen_t address_size = sizeof(struct sockaddr_in);

// daemon_init();
daemon_init();

SSL_CTX *ctx = NULL;
SSL *ssl = NULL;
Expand Down
4 changes: 2 additions & 2 deletions utils/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
CC = clang
CFLAGS = -std=gnu11 -Wall -Wextra -Werror -Wpedantic
# CFLAGS = -std=c11 -Wall -Wextra -Werror -Wpedantic
# CFLAGS = -std=gnu11 -Wall -Wextra -Werror -Wpedantic
CFLAGS = -std=c11 -Wall -Wextra -Werror -Wpedantic

OBJDIR = obj
SRCDIR = src src/db_lists
Expand Down
1 change: 1 addition & 0 deletions utils/inc/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <errno.h>
#include <regex.h>
#include <stdio.h>

// #include "base64.h"
#include "db_types.h"
Expand Down

0 comments on commit f52d6f4

Please sign in to comment.