fix-build-warnings
This commit is contained in:
1 parent
05dc4c299f
commit
903a4268aa
7 files changed
+17
-25
No files matched your search
@@ -1,5 +1,7 @@
|
||||
cmake_minimum_required(VERSION 3.6)
|
||||
project(smol)
|
||||
set(CMAKE_C_FLAGS "-Wall")
|
||||
|
||||
add_executable(
|
||||
smol
|
||||
src/smol.c
|
||||
|
||||
@@ -3,6 +3,7 @@ STRIP=strip
|
||||
BIN=build
|
||||
SRC=src
|
||||
PREFIX=/usr
|
||||
CFLAGS=-Wall
|
||||
|
||||
default: all
|
||||
|
||||
@@ -11,16 +12,16 @@ all: build
|
||||
build: smol smol-pthreads smol-http smol-http-pthreads
|
||||
|
||||
smol:
|
||||
$(CC) -o $(BIN)/smol $(SRC)/smol.c -lcrypto -lssl
|
||||
$(CC) -o $(BIN)/smol $(SRC)/smol.c -lcrypto -lssl $(CFLAGS)
|
||||
|
||||
smol-pthreads:
|
||||
$(CC) -o $(BIN)/smol-pthreads $(SRC)/smol-pthreads.c -lcrypto -lssl
|
||||
$(CC) -o $(BIN)/smol-pthreads $(SRC)/smol-pthreads.c -lcrypto -lssl $(CFLAGS)
|
||||
|
||||
smol-http:
|
||||
$(CC) -o $(BIN)/smol-http $(SRC)/smol-http.c
|
||||
$(CC) -o $(BIN)/smol-http $(SRC)/smol-http.c $(CFLAGS)
|
||||
|
||||
smol-http-pthreads:
|
||||
$(CC) -o $(BIN)/smol-http-pthreads $(SRC)/smol-http-pthreads.c
|
||||
$(CC) -o $(BIN)/smol-http-pthreads $(SRC)/smol-http-pthreads.c $(CFLAGS)
|
||||
|
||||
clean:
|
||||
if [ -d $(BIN) ]; then rm -rv $(BIN);mkdir -pv $(BIN);fi
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
project('smol', 'c')
|
||||
project('smol', 'c', default_options: 'c_args=-Wall')
|
||||
deps = dependency('openssl')
|
||||
executable(
|
||||
'smol',
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
#define PORT 8081
|
||||
#define BUFFER_SIZE 512
|
||||
#define MAX_PATH 128
|
||||
#define MAX_PATH 512
|
||||
#define ROOT_DIR "."
|
||||
|
||||
typedef struct handle_request_data {
|
||||
@@ -66,10 +66,8 @@ static void list_files(int ssl, char *directory) {
|
||||
while ((entry = readdir(dir)) && pos < sizeof(buf) - 100) {
|
||||
if (!strcmp(entry->d_name, ".")) continue;
|
||||
if (!strcmp(entry->d_name, "..") && !strcmp(directory, ROOT_DIR)) continue;
|
||||
struct stat st;
|
||||
char path[MAX_PATH];
|
||||
snprintf(path, sizeof(path), "%s/%s", directory, entry->d_name);
|
||||
// if (stat(path, &st) < 0 || S_ISDIR(st.st_mode)) continue;
|
||||
pos += snprintf(buf + pos, sizeof(buf) - pos,
|
||||
"<li><a href=\"/%s/%s\">%s</a></li>", directory, entry->d_name, entry->d_name);
|
||||
}
|
||||
@@ -83,7 +81,7 @@ void *handle_request(void *param) {
|
||||
handle_request_data *param_data = (handle_request_data*)param;
|
||||
int ssl = param_data->socket;
|
||||
char *req = param_data->req;
|
||||
char method[8], path[MAX_PATH], proto[8];
|
||||
char method[8], path[MAX_PATH-2], proto[8];
|
||||
if (sscanf(req, "%7s %127s %7s", method, path, proto) != 3) {
|
||||
send_response(ssl, "400 Bad Request", "text/plain", "Bad Request", 11);
|
||||
close(ssl);
|
||||
@@ -203,7 +201,6 @@ int main() {
|
||||
pthread_attr_t attr;
|
||||
pthread_attr_init(&attr);
|
||||
pthread_create(&tid, &attr, handle_request, &data);
|
||||
// pthread_join(tid, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-6
@@ -9,7 +9,7 @@
|
||||
|
||||
#define PORT 8081
|
||||
#define BUFFER_SIZE 512
|
||||
#define MAX_PATH 128
|
||||
#define MAX_PATH 512
|
||||
#define ROOT_DIR "."
|
||||
|
||||
static const struct { const char *ext; const char *type; } mime_types[] = {
|
||||
@@ -60,10 +60,8 @@ static void list_files(int ssl, char *directory) {
|
||||
while ((entry = readdir(dir)) && pos < sizeof(buf) - 100) {
|
||||
if (!strcmp(entry->d_name, ".")) continue;
|
||||
if (!strcmp(entry->d_name, "..") && !strcmp(directory, ROOT_DIR)) continue;
|
||||
struct stat st;
|
||||
char path[MAX_PATH];
|
||||
snprintf(path, sizeof(path), "%s/%s", directory, entry->d_name);
|
||||
// if (stat(path, &st) < 0 || S_ISDIR(st.st_mode)) continue;
|
||||
pos += snprintf(buf + pos, sizeof(buf) - pos,
|
||||
"<li><a href=\"/%s/%s\">%s</a></li>", directory, entry->d_name, entry->d_name);
|
||||
}
|
||||
@@ -74,7 +72,7 @@ static void list_files(int ssl, char *directory) {
|
||||
}
|
||||
|
||||
static void handle_request(int ssl, char *req) {
|
||||
char method[8], path[MAX_PATH], proto[8];
|
||||
char method[8], path[MAX_PATH-2], proto[8];
|
||||
if (sscanf(req, "%7s %127s %7s", method, path, proto) != 3) {
|
||||
send_response(ssl, "400 Bad Request", "text/plain", "Bad Request", 11);
|
||||
return;
|
||||
@@ -180,8 +178,6 @@ int main() {
|
||||
buf[n] = '\0';
|
||||
handle_request(client_sock, buf);
|
||||
}
|
||||
|
||||
// close(client_sock);
|
||||
}
|
||||
|
||||
close(sock);
|
||||
|
||||
+3
-5
@@ -12,7 +12,7 @@
|
||||
|
||||
#define PORT 8081
|
||||
#define BUFFER_SIZE 512
|
||||
#define MAX_PATH 128
|
||||
#define MAX_PATH 512
|
||||
#define ROOT_DIR "."
|
||||
|
||||
typedef struct handle_request_data {
|
||||
@@ -69,7 +69,6 @@ static void list_files(SSL *ssl, char *directory) {
|
||||
while ((entry = readdir(dir)) && pos < sizeof(buf) - 100) {
|
||||
if (!strcmp(entry->d_name, ".")) continue;
|
||||
if (!strcmp(entry->d_name, "..") && !strcmp(directory, ROOT_DIR)) continue;
|
||||
struct stat st;
|
||||
char path[MAX_PATH];
|
||||
snprintf(path, sizeof(path), "%s/%s", directory, entry->d_name);
|
||||
pos += snprintf(buf + pos, sizeof(buf) - pos,
|
||||
@@ -86,7 +85,7 @@ void *handle_request(void *param) {
|
||||
int client_sock = param_data->socket;
|
||||
SSL *ssl = param_data->ssl;
|
||||
char *req = param_data->req;
|
||||
char method[8], path[MAX_PATH], proto[8];
|
||||
char method[8], path[MAX_PATH-2], proto[8];
|
||||
if (sscanf(req, "%7s %127s %7s", method, path, proto) != 3) {
|
||||
send_response(ssl, "400 Bad Request", "text/plain", "Bad Request", 11);
|
||||
SSL_shutdown(ssl);
|
||||
@@ -129,12 +128,11 @@ void *handle_request(void *param) {
|
||||
|
||||
char file_path[MAX_PATH];
|
||||
snprintf(file_path, sizeof(file_path), "%s/%s", ROOT_DIR, path[0] == '/' ? path + 1 : path);
|
||||
if (file_path[0] == "." && file_path[1] == "/") {
|
||||
if (file_path[0] == '.' && file_path[1] == '/') {
|
||||
for (int i = 2; i < MAX_PATH -1; i++) {
|
||||
file_path[i-2] = file_path[i];
|
||||
}
|
||||
}
|
||||
https://localhost:8081/home/tola/Pictures/home/tola/Pictures/wallpaper/3d-tech.jpg
|
||||
struct stat st;
|
||||
if (stat(file_path, &st) < 0 || S_ISDIR(st.st_mode)) {
|
||||
if (S_ISDIR(st.st_mode)) {
|
||||
|
||||
+2
-4
@@ -11,7 +11,7 @@
|
||||
|
||||
#define PORT 8081
|
||||
#define BUFFER_SIZE 512
|
||||
#define MAX_PATH 128
|
||||
#define MAX_PATH 512
|
||||
#define ROOT_DIR "."
|
||||
|
||||
static const struct { const char *ext; const char *type; } mime_types[] = {
|
||||
@@ -62,10 +62,8 @@ static void list_files(SSL *ssl, char *directory) {
|
||||
while ((entry = readdir(dir)) && pos < sizeof(buf) - 100) {
|
||||
if (!strcmp(entry->d_name, ".")) continue;
|
||||
if (!strcmp(entry->d_name, "..") && !strcmp(directory, ROOT_DIR)) continue;
|
||||
struct stat st;
|
||||
char path[MAX_PATH];
|
||||
snprintf(path, sizeof(path), "%s/%s", directory, entry->d_name);
|
||||
// if (stat(path, &st) < 0 || S_ISDIR(st.st_mode)) continue;
|
||||
pos += snprintf(buf + pos, sizeof(buf) - pos,
|
||||
"<li><a href=\"/%s/%s\">%s</a></li>", directory, entry->d_name, entry->d_name);
|
||||
}
|
||||
@@ -76,7 +74,7 @@ static void list_files(SSL *ssl, char *directory) {
|
||||
}
|
||||
|
||||
static void handle_request(SSL *ssl, char *req) {
|
||||
char method[8], path[MAX_PATH], proto[8];
|
||||
char method[8], path[MAX_PATH-2], proto[8];
|
||||
if (sscanf(req, "%7s %127s %7s", method, path, proto) != 3) {
|
||||
send_response(ssl, "400 Bad Request", "text/plain", "Bad Request", 11);
|
||||
return;
|
||||
|
||||
Reference in new issue
Block a user