<commit_before>
#include "Handler.h"
#include <iostream>

Handler::Handler()
{
    clients = new Clients();
    requests = new Requests();
};

int Handler::CallExtensionArgs(char * output, int outputSize, const char *function, const char **args, int argsCnt)
{
    if (argsCnt <= 0)
        return 2;
    
    Output *op = Output::Create();
    int rC = 2;

    if (strcmp(function, "addClient") == 0)
    {
        std::map<std::string, std::string> params = parseArgs(args, argsCnt);
        rC = clients->AddClient(op, params);
    }
    else if (strcmp(function, "removeClient") == 0)
    {
        int id = A3URLCommon::StrToInt(std::string(args[0]));
        rC = clients->RemoveClient(op, id);
    }
    else if (strcmp(function, "setClientParams") == 0)
    {
        std::map<std::string, std::string> params = parseArgs(args, argsCnt);
        int id = A3URLCommon::StrToInt(params["#clientid"]);
        params.erase(params.find("#clientid"));
        rC = clients->SetParameters(op, id, params);
    }
    else if (strcmp(function, "setClientHeaders") == 0)
    {
        std::map<std::string, std::string> params = parseArgs(args, argsCnt);
        int id = A3URLCommon::StrToInt(params["#clientid"]);
        params.erase(params.find("#clientid"));
        std::vector<std::string> headers;
        for (std::map<std::string, std::string>::iterator it = params.begin(); it != params.end(); ++it)
            headers.push_back(it->first);

        rC = clients->SetHeaders(op, id, headers);
    }
    else if (strcmp(function, "sendRequest") == 0)
    {
        std::map<std::string, std::string> params = parseArgs(args, argsCnt);
        int cID = A3URLCommon::StrToInt(params["#clientid"]);

        if (cID > 0)
        {
            Clients::Client cli;
            if (clients->GetClient(cID, &cli))
            {
                std::map<std::string, std::string> nParams;
                nParams = A3URLCommon::MergeStringMaps(cli.Parameters, params);
                rC = requests->AddRequest(op, nParams, cli.Headers);
            }
        }
        else
        {
            rC = requests->AddRequest(op, params);
        }
    }
    else if (strcmp(function, "getRequestResult") == 0)
    {
        int id = A3URLCommon::StrToInt(std::string(args[0]));
        rC = requests->GetResult(op, id);
    }
    
    op->WriteBufFlush(output, outputSize);
    
    delete op;
    return rC;
};

std::map<std::string, std::string> Handler::parseArgs(const char **args, int argsCnt)
{
    std::map<std::string, std::string> params;
    
    for (int x = 0; x < argsCnt; x++)
    {
        std::string param(args[x]);

        if (param.size() > 0)
        {
            A3URLCommon::StrUnqoute(&param);
            size_t i = param.find("=");

            if (i != std::string::npos)
                params[param.substr(0, i)] = param.substr(i + 1, param.length() - i);
            else
                params[param] = std::string("");
        }
    }

    return params;
};
<commit_msg>Changed function names<commit_after>
#include "Handler.h"
#include <iostream>

Handler::Handler()
{
    clients = new Clients();
    requests = new Requests();
};

int Handler::CallExtensionArgs(char * output, int outputSize, const char *function, const char **args, int argsCnt)
{
    if (argsCnt <= 0)
        return 2;
    
    Output *op = Output::Create();
    int rC = 2;

    if (strcmp(function, "ADDCLI") == 0)
    {
        std::map<std::string, std::string> params = parseArgs(args, argsCnt);
        rC = clients->AddClient(op, params);
    }
    else if (strcmp(function, "REMCLI") == 0)
    {
        int id = A3URLCommon::StrToInt(std::string(args[0]));
        rC = clients->RemoveClient(op, id);
    }
    else if (strcmp(function, "SETCLIP") == 0)
    {
        std::map<std::string, std::string> params = parseArgs(args, argsCnt);
        int id = A3URLCommon::StrToInt(params["#clientid"]);
        params.erase(params.find("#clientid"));
        rC = clients->SetParameters(op, id, params);
    }
    else if (strcmp(function, "SETCLIH") == 0)
    {
        std::map<std::string, std::string> params = parseArgs(args, argsCnt);
        int id = A3URLCommon::StrToInt(params["#clientid"]);
        params.erase(params.find("#clientid"));
        std::vector<std::string> headers;
        for (std::map<std::string, std::string>::iterator it = params.begin(); it != params.end(); ++it)
            headers.push_back(it->first);

        rC = clients->SetHeaders(op, id, headers);
    }
    else if (strcmp(function, "SENDRQ") == 0)
    {
        std::map<std::string, std::string> params = parseArgs(args, argsCnt);
        int cID = A3URLCommon::StrToInt(params["#clientid"]);

        if (cID > 0)
        {
            Clients::Client cli;
            if (clients->GetClient(cID, &cli))
            {
                std::map<std::string, std::string> nParams;
                nParams = A3URLCommon::MergeStringMaps(cli.Parameters, params);
                rC = requests->AddRequest(op, nParams, cli.Headers);
            }
        }
        else
        {
            rC = requests->AddRequest(op, params);
        }
    }
    else if (strcmp(function, "GETRQ") == 0)
    {
        int id = A3URLCommon::StrToInt(std::string(args[0]));
        rC = requests->GetResult(op, id);
    }
    
    op->WriteBufFlush(output, outputSize);
    
    delete op;
    return rC;
};

std::map<std::string, std::string> Handler::parseArgs(const char **args, int argsCnt)
{
    std::map<std::string, std::string> params;
    
    for (int x = 0; x < argsCnt; x++)
    {
        std::string param(args[x]);

        if (param.size() > 0)
        {
            A3URLCommon::StrUnqoute(&param);
            size_t i = param.find("=");

            if (i != std::string::npos)
                params[param.substr(0, i)] = param.substr(i + 1, param.length() - i);
            else
                params[param] = std::string("");
        }
    }

    return params;
};

{'fraction_non_alphanumeric': 0.16563493391333445, 'fraction_numerical': 0.007696168646478166, 'mean_word_length': 2.398521887436043, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 47, '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': '1949085', 'n_tokens_mistral': 1989, 'n_tokens_neox': 1953, 'n_words': 398}