Compare commits
No commits in common. "fcad98059315f908ff1b69e416ec3661a098bb44" and "c9c21105f63e4ed385a38c6d39dae657d4535316" have entirely different histories.
fcad980593
...
c9c21105f6
4 changed files with 7 additions and 19 deletions
|
@ -7,7 +7,6 @@ A simple HTTP/1.1 server written in C.
|
||||||
Usage:
|
Usage:
|
||||||
-p <port> | --port <port>
|
-p <port> | --port <port>
|
||||||
--config=<config_file>
|
--config=<config_file>
|
||||||
--disable-peer-addr-print
|
|
||||||
|
|
||||||
## Before Compiling
|
## Before Compiling
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,6 @@ void print_usage(void) {
|
||||||
puts("Usage:");
|
puts("Usage:");
|
||||||
puts(" -p <port> | --port <port>");
|
puts(" -p <port> | --port <port>");
|
||||||
puts(" --config=<config_file>");
|
puts(" --config=<config_file>");
|
||||||
puts(" --disable-peer-addr-print");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Args parse_args(int argc, char **argv) {
|
Args parse_args(int argc, char **argv) {
|
||||||
|
@ -46,8 +45,6 @@ Args parse_args(int argc, char **argv) {
|
||||||
++argv;
|
++argv;
|
||||||
} else if (strncmp(argv[0], "--config=", 9) == 0 && strlen(argv[0]) > 9) {
|
} else if (strncmp(argv[0], "--config=", 9) == 0 && strlen(argv[0]) > 9) {
|
||||||
args.config_file = argv[0] + 9;
|
args.config_file = argv[0] + 9;
|
||||||
} else if (strcmp(argv[0], "--disable-peer-addr-print") == 0) {
|
|
||||||
args.flags |= 1;
|
|
||||||
} else {
|
} else {
|
||||||
puts("ERROR: Invalid args!\n");
|
puts("ERROR: Invalid args!\n");
|
||||||
print_usage();
|
print_usage();
|
||||||
|
|
|
@ -18,8 +18,6 @@
|
||||||
#define SEODISPARATE_COM_C_SIMPLE_HTTP_ARG_PARSE_H_
|
#define SEODISPARATE_COM_C_SIMPLE_HTTP_ARG_PARSE_H_
|
||||||
|
|
||||||
typedef struct Args {
|
typedef struct Args {
|
||||||
// xxxx xxx0 - enable peer addr print.
|
|
||||||
// xxxx xxx1 - disable peer addr print.
|
|
||||||
unsigned short flags;
|
unsigned short flags;
|
||||||
unsigned short port;
|
unsigned short port;
|
||||||
// Does not need to be free'd, this should point to a string in argv.
|
// Does not need to be free'd, this should point to a string in argv.
|
||||||
|
|
|
@ -47,7 +47,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
const Args args = parse_args(argc, argv);
|
Args args = parse_args(argc, argv);
|
||||||
|
|
||||||
if (!args.config_file) {
|
if (!args.config_file) {
|
||||||
fprintf(stderr, "ERROR Config file not specified!\n");
|
fprintf(stderr, "ERROR Config file not specified!\n");
|
||||||
|
@ -110,7 +110,6 @@ int main(int argc, char **argv) {
|
||||||
printf("WARNING: accept: errno %d\n", errno);
|
printf("WARNING: accept: errno %d\n", errno);
|
||||||
} else if (ret >= 0) {
|
} else if (ret >= 0) {
|
||||||
// Received connection, handle it.
|
// Received connection, handle it.
|
||||||
if ((args.flags & 1) == 0) {
|
|
||||||
printf("Peer connected: addr is ");
|
printf("Peer connected: addr is ");
|
||||||
for (unsigned int idx = 0; idx < 16; ++idx) {
|
for (unsigned int idx = 0; idx < 16; ++idx) {
|
||||||
if (idx % 2 == 0 && idx > 0) {
|
if (idx % 2 == 0 && idx > 0) {
|
||||||
|
@ -119,9 +118,6 @@ int main(int argc, char **argv) {
|
||||||
printf("%02x", peer_info.sin6_addr.s6_addr[idx]);
|
printf("%02x", peer_info.sin6_addr.s6_addr[idx]);
|
||||||
}
|
}
|
||||||
puts("");
|
puts("");
|
||||||
} else {
|
|
||||||
printf("Peer connected.\n");
|
|
||||||
}
|
|
||||||
int connection_fd = ret;
|
int connection_fd = ret;
|
||||||
read_ret = read(connection_fd, recv_buf, C_SIMPLE_HTTP_RECV_BUF_SIZE);
|
read_ret = read(connection_fd, recv_buf, C_SIMPLE_HTTP_RECV_BUF_SIZE);
|
||||||
if (read_ret < 0) {
|
if (read_ret < 0) {
|
||||||
|
@ -132,7 +128,6 @@ int main(int argc, char **argv) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// DEBUG print received buf.
|
// DEBUG print received buf.
|
||||||
#ifndef NDEBUG
|
|
||||||
for (unsigned int idx = 0;
|
for (unsigned int idx = 0;
|
||||||
idx < C_SIMPLE_HTTP_RECV_BUF_SIZE && idx < read_ret;
|
idx < C_SIMPLE_HTTP_RECV_BUF_SIZE && idx < read_ret;
|
||||||
++idx) {
|
++idx) {
|
||||||
|
@ -144,7 +139,6 @@ int main(int argc, char **argv) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
puts("");
|
puts("");
|
||||||
#endif
|
|
||||||
|
|
||||||
size_t response_size = 0;
|
size_t response_size = 0;
|
||||||
enum C_SIMPLE_HTTP_ResponseCode response_code;
|
enum C_SIMPLE_HTTP_ResponseCode response_code;
|
||||||
|
|
Loading…
Reference in a new issue