diff --git a/httpd/Makefile b/httpd/Makefile index cf0ef94..204e10d 100644 --- a/httpd/Makefile +++ b/httpd/Makefile @@ -3,7 +3,7 @@ CFLAGS = -std=c99 -Werror -Wall -Wextra -Wvla -pedantic LDFLAGS = LDLIBS = -LDFLAGS_DBG = -g +CFLAGS_DBG = -g ASAN_DBG_FLAGS = -fsanitize=address UTILS_SRCS = src/utils/string/string.c @@ -22,8 +22,14 @@ $(TARGET): $(OBJS) check: dash tests/run.sh -debug: LDFLAGS += LDFLAGS_DBG -debug: +debug: CFLAGS += $(CFLAGS_DBG) +debug: $(OBJS) + $(CC) -o $(TARGET) $(OBJS) $(LDFLAGS) $(LDLIBS) + + +asan: CFLAGS += $(CFLAGS_DBG) +asan: LDFLAGS += $(ASAN_DBG_FLAGS) +asan: $(OBJS) $(CC) -o $(TARGET) $(OBJS) $(LDFLAGS) $(LDLIBS) clean: diff --git a/httpd/httpd b/httpd/httpd new file mode 100755 index 0000000..7281946 Binary files /dev/null and b/httpd/httpd differ diff --git a/httpd/src/config/config.c b/httpd/src/config/config.c index 274ed30..b19effb 100644 --- a/httpd/src/config/config.c +++ b/httpd/src/config/config.c @@ -28,10 +28,25 @@ static void print_help(char *program_name) { - printf("Usage: %s [OPTION]\n", program_name); + printf("Usage: %s [OPTIONS]..\n", program_name); puts(""); } +// Just to reduce the number of lines inside handle_opt to not +static int parse_daemon_arg(struct config *cfg) +{ + if (strcmp(optarg, "start") == 0) + cfg->daemon = START; + else if (strcmp(optarg, "stop") == 0) + cfg->daemon = STOP; + else if (strcmp(optarg, "restart") == 0) + cfg->daemon = RESTART; + else + return ARG_INVALID; + + return ARG_VALID; +} + // Returns 0 if argument is valid, otherwise static int handle_opt(char **argv, char opt, struct config *cfg) { @@ -52,15 +67,7 @@ static int handle_opt(char **argv, char opt, struct config *cfg) { // Daemon case 'd': - if (strcmp(optarg, "start") == 0) - cfg->daemon = START; - else if (strcmp(optarg, "stop") == 0) - cfg->daemon = STOP; - else if (strcmp(optarg, "restart") == 0) - cfg->daemon = RESTART; - else - return ARG_INVALID; - return ARG_VALID; + return parse_daemon_arg(cfg); // Server name case 's': @@ -143,16 +150,18 @@ struct config *parse_configuration(int argc, char *argv[]) } char opt; - int optindex; - while ((opt = getopt_long(argc, argv, "*", options, &optindex)) != -1) + // int optindex; + while ((opt = getopt_long(argc, argv, "dhspirl:", options, NULL)) != -1) { int err = handle_opt(argv, opt, config); if (err != ARG_VALID) { if (err == ARG_INVALID) - printf("%s: Invalid argument '%s'", argv[0], argv[optindex]); + // printf("%s: Invalid argument '%s'\n", argv[0], + // argv[optindex]); + printf("%s: Invalid argument\n", argv[0]); if (err == ARG_NOT_IMPLEMENTED) - printf("%s: This function is not implemented", argv[0]); + printf("%s: This function is not implemented\n", argv[0]); free(config->servers); free(config); diff --git a/httpd/src/main.c b/httpd/src/main.c index 58fe692..7bbca8b 100644 --- a/httpd/src/main.c +++ b/httpd/src/main.c @@ -1,4 +1,8 @@ -int main(void) +#include "config/config.h" + +int main(int argc, char **argv) { + // struct config *config = parse_configuration(argc, argv); + parse_configuration(argc, argv); return 0; }