<commit_before>/*  mod_lily.c
    This is an apache binding for the Lily language. */
#include <ctype.h>

#include "httpd.h"
#include "http_config.h"
#include "http_protocol.h"
#include "ap_config.h"
#include "util_script.h"

#include "lily_alloc.h"
#include "lily_parser.h"
#include "lily_lexer.h"
#include "lily_utf8.h"
#include "lily_cls_hash.h"

#include "lily_api_dynaload.h"
#include "lily_api_value.h"
#include "lily_api_options.h"

struct table_bind_data {
    lily_parse_state *parser;
    lily_symtab *symtab;
    request_rec *r;
    int ok;
    lily_hash_val *hash_val;
    char *sipkey;
};

lily_value *bind_tainted_of(lily_parse_state *parser, lily_value *input)
{
    lily_instance_val *iv = lily_new_instance_val();
    iv->values = lily_malloc(1 * sizeof(lily_value *));
    iv->instance_id = SYM_CLASS_TAINTED;
    iv->values[0] = input;
    lily_value *result = lily_new_empty_value();
    lily_move_instance_f(MOVE_DEREF_NO_GC, result, iv);
    return result;
}

static int bind_table_entry(void *data, const char *key, const char *value)
{
    /* Don't allow anything to become a string that has invalid utf-8, because
       Lily's string type assumes valid utf-8. */
    if (lily_is_valid_utf8(key) == 0 ||
        lily_is_valid_utf8(value) == 0)
        return TRUE;

    struct table_bind_data *d = data;

    lily_value *elem_key = lily_new_string(key);
    lily_value *elem_raw_value = lily_new_string(value);
    lily_value *elem_value = bind_tainted_of(d->parser, elem_raw_value);

    lily_hash_add_unique(d->parser->vm, d->hash_val, elem_key, elem_value);
    return TRUE;
}

static void bind_table_as(lily_parse_state *parser, request_rec *r,
        apr_table_t *table, char *name, lily_foreign_tie *tie)
{
    lily_move_hash_f(MOVE_DEREF_NO_GC, &tie->data, lily_new_hash_val());

    struct table_bind_data data;
    data.parser = parser;
    data.symtab = parser->symtab;
    data.r = r;
    data.ok = 1;
    data.hash_val = tie->data.value.hash;
    data.sipkey = parser->vm->sipkey;
    apr_table_do(bind_table_entry, &data, table, NULL);
}

static void bind_post(lily_parse_state *parser, request_rec *r,
        lily_foreign_tie *tie)
{
    lily_move_hash_f(MOVE_DEREF_NO_GC, &tie->data, lily_new_hash_val());
    lily_hash_val *hash_val = tie->data.value.hash;

    apr_array_header_t *pairs;
    apr_off_t len;
    apr_size_t size;
    char *buffer;<commit_msg>Remove some junk from mod_lily.c's source.<commit_after>/*  mod_lily.c
    This is an apache binding for the Lily language. */
#include "httpd.h"
#include "http_config.h"
#include "http_protocol.h"
#include "ap_config.h"
#include "util_script.h"

#include "lily_alloc.h"
#include "lily_parser.h"
#include "lily_utf8.h"
#include "lily_cls_hash.h"

#include "lily_api_dynaload.h"
#include "lily_api_value.h"
#include "lily_api_options.h"

struct table_bind_data {
    lily_parse_state *parser;
    request_rec *r;
    int ok;
    lily_hash_val *hash_val;
    char *sipkey;
};

lily_value *bind_tainted_of(lily_parse_state *parser, lily_value *input)
{
    lily_instance_val *iv = lily_new_instance_val();
    iv->values = lily_malloc(1 * sizeof(lily_value *));
    iv->instance_id = SYM_CLASS_TAINTED;
    iv->values[0] = input;
    lily_value *result = lily_new_empty_value();
    lily_move_instance_f(MOVE_DEREF_NO_GC, result, iv);
    return result;
}

static int bind_table_entry(void *data, const char *key, const char *value)
{
    /* Don't allow anything to become a string that has invalid utf-8, because
       Lily's string type assumes valid utf-8. */
    if (lily_is_valid_utf8(key) == 0 ||
        lily_is_valid_utf8(value) == 0)
        return TRUE;

    struct table_bind_data *d = data;

    lily_value *elem_key = lily_new_string(key);
    lily_value *elem_raw_value = lily_new_string(value);
    lily_value *elem_value = bind_tainted_of(d->parser, elem_raw_value);

    lily_hash_add_unique(d->parser->vm, d->hash_val, elem_key, elem_value);
    return TRUE;
}

static void bind_table_as(lily_parse_state *parser, request_rec *r,
        apr_table_t *table, char *name, lily_foreign_tie *tie)
{
    lily_move_hash_f(MOVE_DEREF_NO_GC, &tie->data, lily_new_hash_val());

    struct table_bind_data data;
    data.parser = parser;
    data.r = r;
    data.ok = 1;
    data.hash_val = tie->data.value.hash;
    data.sipkey = parser->vm->sipkey;
    apr_table_do(bind_table_entry, &data, table, NULL);
}

static void bind_post(lily_parse_state *parser, request_rec *r,
        lily_foreign_tie *tie)
{
    lily_move_hash_f(MOVE_DEREF_NO_GC, &tie->data, lily_new_hash_val());
    lily_hash_val *hash_val = tie->data.value.hash;

    apr_array_header_t *pairs;
    apr_off_t len;
    apr_size_t size;
    char *buffer;
{'fraction_non_alphanumeric': 0.11548223350253807, 'fraction_numerical': 0.004230118443316413, 'mean_word_length': 4.140217391304348, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 31, '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': '5785264', 'n_tokens_mistral': 1886, 'n_tokens_neox': 1868, 'n_words': 370}