<commit_before>#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>

#include <openssl/ssl.h>
#include "kahoot.h"

typedef struct {
    SSL_CTX* context;
    SSL* conn;
    struct sockaddr_in addr;
    struct hostent* serv;
    int sockfd;
} req;

void setup_openssl(void) {
    SSL_load_error_strings();
    SSL_library_init();
};

req* init_request(void) {
    req* request;
    request = malloc(sizeof(req)); // Allocate a request on the heap
    request->sockfd = socket(AF_INET, SOCK_STREAM, 0);
    request->context = SSL_CTX_new(SSLv23_client_method());
    request->conn = SSL_new(request->context);
    SSL_set_fd(request->conn, request->sockfd);
    request->serv = gethostbyname(KAHOOT_HOST_URI);
    request->addr.sin_family = AF_INET;
   bcopy((char*)request->serv->h_addr,
   (char*)&request->addr.sin_addr.s_addr,
   request->serv->h_length);

    request->addr.sin_port = htons(KAHOOT_SSL_PORT);
    return request;
};
void request_connect(req* request) {
    connect(request->sockfd, 
    (struct sockaddr *) &request->addr,
    sizeof(request->addr));
};
int request_write_str(req* request, char* msg) {
    int res = 0;
    res = SSL_write(request->conn, msg, strlen(msg));
    return res;
};
int request_read(req* request, char* buffer, int len) {
    return SSL_read(request->conn, buffer, len);
};<commit_msg>Change SSL context to global<commit_after>#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>

#include <openssl/ssl.h>
#include "kahoot.h"

typedef struct {
    SSL* conn;
    struct sockaddr_in addr;
    struct hostent* serv;
    int sockfd;
} req;
SSL_CTX* ssl_context;

void setup_openssl(void) {
    SSL_load_error_strings();
    SSL_library_init();
    ssl_context = SSL_CTX_new(SSLv23_client_method());
};

req* init_request(void) {
    req* request;
    request = malloc(sizeof(req)); // Allocate a request on the heap
    request->sockfd = socket(AF_INET, SOCK_STREAM, 0);
    request->conn = SSL_new(ssl_context);
    SSL_set_fd(request->conn, request->sockfd);
    request->serv = gethostbyname(KAHOOT_HOST_URI);
    request->addr.sin_family = AF_INET;
   bcopy((char*)request->serv->h_addr,
   (char*)&request->addr.sin_addr.s_addr,
   request->serv->h_length);

    request->addr.sin_port = htons(KAHOOT_SSL_PORT);
    return request;
};
void request_connect(req* request) {
    connect(request->sockfd, 
    (struct sockaddr *) &request->addr,
    sizeof(request->addr));
};
int request_write_str(req* request, char* msg) {
    int res = 0;
    res = SSL_write(request->conn, msg, strlen(msg));
    return res;
};
int request_read(req* request, char* buffer, int len) {
    return SSL_read(request->conn, buffer, len);
};
{'fraction_non_alphanumeric': 0.15039668851328045, 'fraction_numerical': 0.0027595722662987236, 'mean_word_length': 4.244122965641953, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 57, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4482257', 'n_tokens_mistral': 1068, 'n_tokens_neox': 1046, 'n_words': 214}