<commit_before>int main()
{
    return 0;

}<commit_msg>Implement otp_dec<commit_after>#include "cipher_lib.h"
#include <stdlib.h>
#include <stdio.h>
#include <sys/socket.h>
#include "server_lib.h"

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-noreturn"


int portNumber = 8080;
char buffer[BUFSIZ];
int keyBuffer[BUFSIZ];
int msgBuffer[BUFSIZ];
int resultBuffer[BUFSIZ];

const char *usage = "Usage: otd_dec_d [port #]\n";

void *handleClientDecryption(void *_clientFd) {
    int clientFd = (int) _clientFd;
    ssize_t receiveLength;
    ssize_t sendSuccess;
    size_t keyLength;
    size_t msgLength;

    while (1) {
        // Read the key and msg lengths
        receiveLength = recv(clientFd, buffer, sizeof(int) * 2, 0);
        if (!receiveLength)
            return NULL;
        keyLength = (size_t) buffer[0];
        msgLength = (size_t) buffer[1];
        receiveLength = 0;
        while (receiveLength < keyLength)
            receiveLength += recv(clientFd, buffer + receiveLength, keyLength - receiveLength, 0);
        buffer[keyLength] = '\0';
        encode(keyBuffer, buffer);
        receiveLength = 0;
        while (receiveLength < msgLength)
            receiveLength += recv(clientFd, buffer + receiveLength, msgLength - receiveLength, 0);
        buffer[msgLength] = '\0';
        encode(msgBuffer, buffer);
        decrypt(resultBuffer, msgBuffer, keyBuffer, (int) msgLength);
        decode(buffer, resultBuffer, (int) msgLength);
        sendSuccess = send(clientFd, buffer, msgLength, 0);
        if (!sendSuccess)
            return NULL;
    }

    return NULL;
}

int main(int argc, char *argv[]) {

    /* --- Read port from arguments or print usage -- */
    if (argc < 2 || atoi(argv[1]) == 0) {
        printf("%s", usage);
        return 1;
    } else {
        portNumber = atoi(argv[1]);
    }

    return startServer("otp_dec_d", portNumber, handleClientDecryption);
}

#pragma clang diagnostic pop
{'fraction_non_alphanumeric': 0.12227295788939624, 'fraction_numerical': 0.011161846778285134, 'mean_word_length': 2.9204771371769382, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 6, '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': '1293874', 'n_tokens_mistral': 646, 'n_tokens_neox': 620, 'n_words': 165}