Skip to content

Commit

Permalink
fix: use snsprintf in views
Browse files Browse the repository at this point in the history
  • Loading branch information
araujo88 committed Jul 19, 2024
1 parent f9b1969 commit 84f8afe
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/views.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ void root_view(void *client_socket)
content = "Hello world!";
printf("[%s] - ", current_date);
printf("\033[0;32mHTTP/1.1 200 OK\033[0m\n");
sprintf(server_message, "HTTP/1.1 200 OK\nDate: %s\nContent-Type: text/html\nContent-Length: %ld\n\n%s", current_date, strlen(content), content);
snprintf(server_message, sizeof(server_message), "HTTP/1.1 200 OK\nDate: %s\nContent-Type: text/html\nContent-Length: %ld\n\n%s", current_date, strlen(content), content);
send(*(int *)client_socket, server_message, strlen(server_message), 0);
}

Expand All @@ -32,7 +32,7 @@ void get_users_view(void *client_socket)

printf("[%s] - ", current_date);
printf("\033[0;32mHTTP/1.1 200 OK\033[0m\n");
sprintf(server_message, "HTTP/1.1 200 OK\nDate: %s\nContent-Type: application/json\nContent-Length: %ld\n\n%s", current_date, strlen(content), content);
snprintf(server_message, sizeof(server_message), "HTTP/1.1 200 OK\nDate: %s\nContent-Type: application/json\nContent-Length: %ld\n\n%s", current_date, strlen(content), content);
send(*(int *)client_socket, server_message, strlen(server_message), 0);
}

Expand All @@ -51,7 +51,7 @@ void get_user_view(void *client_socket, unsigned int id)

printf("[%s] - ", current_date);
printf("\033[0;32mHTTP/1.1 200 OK\033[0m\n");
sprintf(server_message, "HTTP/1.1 200 OK\nDate: %s\nContent-Type: application/json\nContent-Length: %ld\n\n%s", current_date, strlen(content), content);
snprintf(server_message, sizeof(server_message), "HTTP/1.1 200 OK\nDate: %s\nContent-Type: application/json\nContent-Length: %ld\n\n%s", current_date, strlen(content), content);
send(*(int *)client_socket, server_message, strlen(server_message), 0);
}

Expand All @@ -70,7 +70,7 @@ void delete_user_view(void *client_socket, unsigned int id)

printf("[%s] - ", current_date);
printf("\033[0;32mHTTP/1.1 200 OK\033[0m\n");
sprintf(server_message, "HTTP/1.1 200 OK\nDate: %s\nContent-Type: application/json\nContent-Length: %ld\n\n%s", current_date, strlen(content), content);
snprintf(server_message, sizeof(server_message), "HTTP/1.1 200 OK\nDate: %s\nContent-Type: application/json\nContent-Length: %ld\n\n%s", current_date, strlen(content), content);
send(*(int *)client_socket, server_message, strlen(server_message), 0);
}

Expand All @@ -89,7 +89,7 @@ void update_user_view(void *client_socket, unsigned int id, char struct_string[N

printf("[%s] - ", current_date);
printf("\033[0;32mHTTP/1.1 200 OK\033[0m\n");
sprintf(server_message, "HTTP/1.1 200 OK\nDate: %s\nContent-Type: application/json\nContent-Length: %ld\n\n%s", current_date, strlen(content), content);
snprintf(server_message, sizeof(server_message), "HTTP/1.1 200 OK\nDate: %s\nContent-Type: application/json\nContent-Length: %ld\n\n%s", current_date, strlen(content), content);
send(*(int *)client_socket, server_message, strlen(server_message), 0);
}

Expand All @@ -108,7 +108,7 @@ void create_user_view(void *client_socket, char struct_string[NUM_COLS][STR_LEN]

printf("[%s] - ", current_date);
printf("\033[0;32mHTTP/1.1 201 Created\033[0m\n");
sprintf(server_message, "HTTP/1.1 201 Created\nDate: %s\nContent-Type: application/json\nContent-Length: %ld\n\n%s", current_date, strlen(content), content);
snprintf(server_message, sizeof(server_message), "HTTP/1.1 201 Created\nDate: %s\nContent-Type: application/json\nContent-Length: %ld\n\n%s", current_date, strlen(content), content);
send(*(int *)client_socket, server_message, strlen(server_message), 0);
}

Expand All @@ -124,6 +124,6 @@ void error_not_found(void *client_socket)
content = "<html><h1>Error 404 - not found</h1></html>";
printf("[%s] - ", current_date);
printf("\033[0;31mHTTP/1.1 404 Not Found\033[0m\n");
sprintf(server_message, "HTTP/1.1 404 Not Found\nDate: %s\nContent-Type: text/html\nContent-Length: %ld\n\n%s", current_date, strlen(content), content);
snprintf(server_message, sizeof(server_message), "HTTP/1.1 404 Not Found\nDate: %s\nContent-Type: text/html\nContent-Length: %ld\n\n%s", current_date, strlen(content), content);
send(*(int *)client_socket, server_message, strlen(server_message), 0);
}

0 comments on commit 84f8afe

Please sign in to comment.