<commit_before>#include    <ndk.h>


typedef struct {
    ngx_http_script_code_pt     code;
    void                       *func;
} ndk_set_var_code_t;


typedef struct {
    ngx_http_script_code_pt     code;
    void                       *func;
    size_t                      size;
} ndk_set_var_size_code_t;


typedef struct {
    ngx_http_script_code_pt     code;
    void                       *func;
    void                       *data;
} ndk_set_var_data_code_t;


typedef struct {
    ngx_http_script_code_pt     code;
    void                       *func;
    size_t                      size;
    void                       *data;
} ndk_set_var_size_data_code_t;


typedef struct {
    ngx_int_t                        index;
    ngx_str_t                       *value;
    ngx_http_variable_t             *v;
    ngx_conf_t                      *cf;
    ndk_http_rewrite_loc_conf_t     *rlcf;
} ndk_set_var_info_t;


static void     ndk_set_var_code           (ngx_http_script_engine_t *e);
static void     ndk_set_var_hash_code      (ngx_http_script_engine_t *e);
static void     ndk_set_var_value_code     (ngx_http_script_engine_t *e);


static ngx_inline void
ndk_set_var_code_finalize(ngx_http_script_engine_t *e, ngx_int_t rc,
                                ngx_http_variable_value_t *v, ngx_str_t *str)
{
    switch (rc) {

    case NGX_OK:

        v->data = str->data;
        v->len = str->len;
        v->valid = 1;
        v->no_cacheable = 0;
        v->not_found = 0;

        ngx_log_debug1(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0,
                        "http script value (post filter): \"%v\"", v);
        break;

    case NGX_DECLINED:

        v->valid = 0;
        v->not_found = 1;
        v->no_cacheable = 1;
        break;

    case NGX_ERROR:

        e->ip = ndk_http_script_exit;
        e->status = NGX_HTTP_INTERNAL_SERVER_ERROR;
        break;
    }
}



static void
ndk_set_var_code(ngx_http_script_engine_t *e)
{
    ngx_int_t                    rc;
    ngx_str_t                    str;
    ngx_http_variable_value_t   *v;
    ndk_set_var_code_t          *sv;
    ndk_set_var_pt               func;

    sv = (ndk_set_var_code_t *) e->ip;

    e->ip += sizeof(ndk_set_var_code_t);

    v = e->sp++;

    func = sv->func;

    rc = func(e->request, &str);

    ndk_set_var_code_finalize(e, rc, v, &str);
}


static void
ndk_set_var_data_code(ngx_http_script_engine_t *e)
{
    ngx_int_t                    rc;
    ngx_str_t                    str;
    ngx_http_variable_value_t   *v;
    ndk_set_var_data_code_t     *svd;
    ndk_set_var_data_pt          func;

    svd = (ndk_set_var_data_code_t *) e->ip;

    e->ip += sizeof(ndk_set_var_data_code_t);

    v = e->sp++;

    func = svd->func;

    rc = func(e->request, &str, svd->data);

    ndk_set_var_code_finalize(e, rc, v, &str);
}


static void
ndk_set_var_value_code(ngx_http_script_engine_t *e)
{
    ngx_int_t                    rc;
    ngx_str_t                    str;
    ngx_http_variable_value_t   *v;
    ndk_set_var_code_t          *sv;
    ndk_set_var_value_pt         func;

    sv = (ndk_set_var_code_t *) e->ip;

    e->ip += sizeof(ndk_set_var_code_t);

    v = e->sp - 1;

    func = sv->func;

    rc = func(e->request, &str, v);

    ndk_set_var_code_finalize(e, rc, v, &str);
}


static void
ndk_set_var_value_data_code(ngx_http_script_engine_t *e)
{
    ngx_int_t                    rc;
    ngx_str_t                    str;
    ngx_http_variable_value_t   *v;
    ndk_set_var_data_code_t     *svd;
    ndk_set_var_value_data_pt    func;

    svd = (ndk_set_var_data_code_t *) e->ip;

    e->ip += sizeof(ndk_set_var_data_code_t);

    v = e->sp - 1;

    func = svd->func;

    rc = func(e->request, &str, v, svd->data);

    ndk_set_var_code_finalize(e, rc, v, &str);
}


static void
ndk_set_var_multi_value_code(ngx_http_script_engine_t *e)
{
    ngx_int_t                    rc;
    ngx_str_t                    str;
    ngx_http_variable_value_t   *v;
    ndk_set_var_size_code_t     *svs;
    ndk_set_var_value_pt         func;

    svs = (ndk_set_var_size_code_t *) e->ip;

    e->ip += sizeof(ndk_set_var_size_code_t);

    v = e->sp - svs->size;
    e->sp = v + 1;

    func = svs->func;

    rc = func(e->request, &str, v);

    ndk_set_var_code_finalize(e, rc, v, &str);
}


static void
ndk_set_var_multi_value_data_code(ngx_http_script_engine_t *e)
{
    ngx_int_t                        rc;
    ngx_str_t                        str;
    ngx_http_variable_value_t       *v;
    ndk_set_var_size_data_code_t    *svsd;
    ndk_set_var_value_data_pt        func;

    svsd = (ndk_set_var_size_data_code_t *) e->ip;

    e->ip += sizeof(ndk_set_var_size_data_code_t);

    v = e->sp - svsd->size;
    e->sp = v + 1;

    func = svsd->func;

    rc = func(e->request, &str, v, svsd->data);

    ndk_set_var_code_finalize(e, rc, v, &str);
}


static void
ndk_set_var_hash_code(ngx_http_script_engine_t *e)
{
    u_char                      *p;
    ngx_http_variable_value_t   *v;
    ndk_set_var_size_code_t     *svs;
    ndk_set_var_hash_pt          func;

    svs = (ndk_set_var_size_code_t *) e->ip;

    e->ip += sizeof(ndk_set_var_size_code_t);

    p = ngx_palloc(e->request->pool, svs->size);
    if (p == NULL) {
        e->ip = ndk_http_script_exit;
        e->status = NGX_HTTP_INTERNAL_SERVER_ERROR;
        return;
    }

    v = e->sp - 1;

    func = svs->func;

    func(p, (char *) v->data, v->len);

    v->data = (u_char *) p;
    v->len = svs->size;
<commit_msg>fixed the warnings from the MinGW C compiler (warning C4152: nonstandard extension, function/data pointer conversion in expression). thanks <NAME> for the report.<commit_after>#include    <ndk.h>


typedef struct {
    ngx_http_script_code_pt     code;
    void                       *func;
} ndk_set_var_code_t;


typedef struct {
    ngx_http_script_code_pt     code;
    void                       *func;
    size_t                      size;
} ndk_set_var_size_code_t;


typedef struct {
    ngx_http_script_code_pt     code;
    void                       *func;
    void                       *data;
} ndk_set_var_data_code_t;


typedef struct {
    ngx_http_script_code_pt     code;
    void                       *func;
    size_t                      size;
    void                       *data;
} ndk_set_var_size_data_code_t;


typedef struct {
    ngx_int_t                        index;
    ngx_str_t                       *value;
    ngx_http_variable_t             *v;
    ngx_conf_t                      *cf;
    ndk_http_rewrite_loc_conf_t     *rlcf;
} ndk_set_var_info_t;


static void     ndk_set_var_code           (ngx_http_script_engine_t *e);
static void     ndk_set_var_hash_code      (ngx_http_script_engine_t *e);
static void     ndk_set_var_value_code     (ngx_http_script_engine_t *e);


static ngx_inline void
ndk_set_var_code_finalize(ngx_http_script_engine_t *e, ngx_int_t rc,
                                ngx_http_variable_value_t *v, ngx_str_t *str)
{
    switch (rc) {

    case NGX_OK:

        v->data = str->data;
        v->len = str->len;
        v->valid = 1;
        v->no_cacheable = 0;
        v->not_found = 0;

        ngx_log_debug1(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0,
                        "http script value (post filter): \"%v\"", v);
        break;

    case NGX_DECLINED:

        v->valid = 0;
        v->not_found = 1;
        v->no_cacheable = 1;
        break;

    case NGX_ERROR:

        e->ip = ndk_http_script_exit;
        e->status = NGX_HTTP_INTERNAL_SERVER_ERROR;
        break;
    }
}



static void
ndk_set_var_code(ngx_http_script_engine_t *e)
{
    ngx_int_t                    rc;
    ngx_str_t                    str;
    ngx_http_variable_value_t   *v;
    ndk_set_var_code_t          *sv;
    ndk_set_var_pt               func;

    sv = (ndk_set_var_code_t *) e->ip;

    e->ip += sizeof(ndk_set_var_code_t);

    v = e->sp++;

    func = (ndk_set_var_pt) sv->func;

    rc = func(e->request, &str);

    ndk_set_var_code_finalize(e, rc, v, &str);
}


static void
ndk_set_var_data_code(ngx_http_script_engine_t *e)
{
    ngx_int_t                    rc;
    ngx_str_t                    str;
    ngx_http_variable_value_t   *v;
    ndk_set_var_data_code_t     *svd;
    ndk_set_var_data_pt          func;

    svd = (ndk_set_var_data_code_t *) e->ip;

    e->ip += sizeof(ndk_set_var_data_code_t);

    v = e->sp++;

    func = (ndk_set_var_data_pt) svd->func;

    rc = func(e->request, &str, svd->data);

    ndk_set_var_code_finalize(e, rc, v, &str);
}


static void
ndk_set_var_value_code(ngx_http_script_engine_t *e)
{
    ngx_int_t                    rc;
    ngx_str_t                    str;
    ngx_http_variable_value_t   *v;
    ndk_set_var_code_t          *sv;
    ndk_set_var_value_pt         func;

    sv = (ndk_set_var_code_t *) e->ip;

    e->ip += sizeof(ndk_set_var_code_t);

    v = e->sp - 1;

    func = (ndk_set_var_value_pt) sv->func;

    rc = func(e->request, &str, v);

    ndk_set_var_code_finalize(e, rc, v, &str);
}


static void
ndk_set_var_value_data_code(ngx_http_script_engine_t *e)
{
    ngx_int_t                    rc;
    ngx_str_t                    str;
    ngx_http_variable_value_t   *v;
    ndk_set_var_data_code_t     *svd;
    ndk_set_var_value_data_pt    func;

    svd = (ndk_set_var_data_code_t *) e->ip;

    e->ip += sizeof(ndk_set_var_data_code_t);

    v = e->sp - 1;

    func = (ndk_set_var_value_data_pt) svd->func;

    rc = func(e->request, &str, v, svd->data);

    ndk_set_var_code_finalize(e, rc, v, &str);
}


static void
ndk_set_var_multi_value_code(ngx_http_script_engine_t *e)
{
    ngx_int_t                    rc;
    ngx_str_t                    str;
    ngx_http_variable_value_t   *v;
    ndk_set_var_size_code_t     *svs;
    ndk_set_var_value_pt         func;

    svs = (ndk_set_var_size_code_t *) e->ip;

    e->ip += sizeof(ndk_set_var_size_code_t);

    v = e->sp - svs->size;
    e->sp = v + 1;

    func = (ndk_set_var_value_pt) svs->func;

    rc = func(e->request, &str, v);

    ndk_set_var_code_finalize(e, rc, v, &str);
}


static void
ndk_set_var_multi_value_data_code(ngx_http_script_engine_t *e)
{
    ngx_int_t                        rc;
    ngx_str_t                        str;
    ngx_http_variable_value_t       *v;
    ndk_set_var_size_data_code_t    *svsd;
    ndk_set_var_value_data_pt        func;

    svsd = (ndk_set_var_size_data_code_t *) e->ip;

    e->ip += sizeof(ndk_set_var_size_data_code_t);

    v = e->sp - svsd->size;
    e->sp = v + 1;

    func = (ndk_set_var_value_data_pt) svsd->func;

    rc = func(e->request, &str, v, svsd->data);

    ndk_set_var_code_finalize(e, rc, v, &str);
}


static void
ndk_set_var_hash_code(ngx_http_script_engine_t *e)
{
    u_char                      *p;
    ngx_http_variable_value_t   *v;
    ndk_set_var_size_code_t     *svs;
    ndk_set_var_hash_pt          func;

    svs = (ndk_set_var_size_code_t *) e->ip;

    e->ip += sizeof(ndk_set_var_size_code_t);

    p = ngx_palloc(e->request->pool, svs->size);
    if (p == NULL) {
        e->ip = ndk_http_script_exit;
        e->status = NGX_HTTP_INTERNAL_SERVER_ERROR;
        return;
    }

    v = e->sp - 1;

    func = (ndk_set_var_hash_pt) svs->func;

    func(p, (char *) v->data, v->len);

    v->data = (u_char *) p;
    v->len = svs->size;

{'fraction_non_alphanumeric': 0.10093277015135516, 'fraction_numerical': 0.0026399155227032735, 'mean_word_length': 1.9798112218143682, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 138, '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': '7613988', 'n_tokens_mistral': 4747, 'n_tokens_neox': 4507, 'n_words': 742}