Remove logging and add CI

main
Clément FRÉVILLE 2 years ago
parent c128927730
commit 97b53d7f7c

@ -0,0 +1,9 @@
kind: pipeline
type: docker
name: default
steps:
- name: build
image: gcc:13
commands:
- make

@ -20,6 +20,10 @@ int open_server(int port) {
perror("Cannot create socket"); perror("Cannot create socket");
return -1; return -1;
} }
if (setsockopt(serverSocket, SOL_SOCKET, SO_REUSEADDR, &(int){1},
sizeof(int)) == -1) {
perror("reuseaddr");
}
struct sockaddr_in address; struct sockaddr_in address;
memset(&address, 0, sizeof(address)); memset(&address, 0, sizeof(address));
address.sin_family = AF_INET; address.sin_family = AF_INET;
@ -52,7 +56,8 @@ SSL_CTX *init_ssl_ctx(void) {
"methods available, cannot enable TLS compression.\n"); "methods available, cannot enable TLS compression.\n");
} else { } else {
for (int i = 0; i < sk_SSL_COMP_num(s); i++) { for (int i = 0; i < sk_SSL_COMP_num(s); i++) {
const char *name = SSL_COMP_get_name(sk_SSL_COMP_value(s, i)); const SSL_COMP *comp = sk_SSL_COMP_value(s, i);
const char *name = SSL_COMP_get_name(comp);
printf("Found compression method: %s\n", name); printf("Found compression method: %s\n", name);
} }
} }
@ -100,20 +105,8 @@ int load_certificates(SSL_CTX *ctx, const char *cert_file,
} }
int handle_request(SSL *ssl, int fd) { int handle_request(SSL *ssl, int fd) {
const COMP_METHOD *comp = SSL_get_current_compression(ssl);
if (comp == NULL) {
printf("No compression\n");
} else {
const char *name = COMP_get_name(comp);
if (name == NULL) {
fprintf(stderr, "Cannot get compression name!\n");
} else {
printf("Compression: %s\n", name);
}
}
char buf[BUF_LEN]; char buf[BUF_LEN];
int sd, bytes; int bytes;
char output[] = "HTTP/1.1 200 OK\r\nContent-Length: 13\r\nContent-Type: " char output[] = "HTTP/1.1 200 OK\r\nContent-Length: 13\r\nContent-Type: "
"text/plain\r\n\r\nHello World!\n"; "text/plain\r\n\r\nHello World!\n";
@ -132,13 +125,11 @@ int handle_request(SSL *ssl, int fd) {
bytes = SSL_read(ssl, buf, sizeof(buf)); bytes = SSL_read(ssl, buf, sizeof(buf));
if (bytes > 0) { if (bytes > 0) {
buf[bytes] = 0; buf[bytes] = 0;
printf("Client msg: \"%s", buf);
SSL_write(ssl, output, strlen(output)); SSL_write(ssl, output, strlen(output));
} else { } else {
ERR_print_errors_fp(stderr); ERR_print_errors_fp(stderr);
} }
} }
sd = SSL_get_fd(ssl);
SSL_free(ssl); SSL_free(ssl);
return 0; return 0;
} }
@ -180,8 +171,7 @@ int main(int argc, char **argv) {
socklen_t len = sizeof(addr); socklen_t len = sizeof(addr);
SSL *ssl; SSL *ssl;
int client = accept(server, (struct sockaddr *)&addr, int client = accept(server, (struct sockaddr *)&addr, &len);
&len);
printf("Connection: %s:%d\n", inet_ntoa(addr.sin_addr), printf("Connection: %s:%d\n", inet_ntoa(addr.sin_addr),
ntohs(addr.sin_port)); ntohs(addr.sin_port));
ssl = SSL_new(ctx); ssl = SSL_new(ctx);

Loading…
Cancel
Save