<commit_before>/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "fcgid_bucket.h"
#include "fcgid_protocol.h"
#include "fcgid_bridge.h"

#define FCGID_FEED_LEN 8192
static apr_status_t fcgid_feed_data(fcgid_bucket_ctx * ctx,
                                    apr_bucket_alloc_t * bucketalloc,
                                    char **buffer, apr_size_t * bufferlen)
{
    server_rec *s = ctx->ipc.request->server;
    apr_status_t rv;

    if (!ctx->buffer) {
        *buffer = apr_bucket_alloc(FCGID_FEED_LEN, bucketalloc);

        *bufferlen = FCGID_FEED_LEN;
        if ((rv =
             proc_read_ipc(&ctx->ipc, *buffer,
                           bufferlen)) != APR_SUCCESS) {
            ctx->has_error = 1;
            apr_bucket_free(*buffer);
            return rv;
        }

        ctx->buffer =
            apr_bucket_heap_create(*buffer, FCGID_FEED_LEN,
                                   apr_bucket_free, bucketalloc);
        if (*bufferlen != FCGID_FEED_LEN) {
            apr_bucket *buckettmp;

            apr_bucket_split(ctx->buffer, *bufferlen);
            buckettmp = APR_BUCKET_NEXT(ctx->buffer);
            apr_bucket_delete(buckettmp);
        }
    } else {
        apr_bucket_read(ctx->buffer, (const char **) buffer, bufferlen,
                        APR_BLOCK_READ);
    }
    return APR_SUCCESS;
}

static void fcgid_ignore_bytes(fcgid_bucket_ctx * ctx,
                               apr_size_t ignorebyte)
{
    apr_bucket *buckettmp;

    if (ignorebyte == ctx->buffer->length) {
        apr_bucket_destroy(ctx->buffer);
        ctx->buffer = NULL;
    } else {
        apr_bucket_split(ctx->buffer, ignorebyte);
        buckettmp = ctx->buffer;
        ctx->buffer = APR_BUCKET_NEXT(ctx->buffer);
        apr_bucket_delete(buckettmp);
    }
}

static apr_status_t fcgid_header_bucket_read(apr_bucket * b,
                                             const char **str,
                                             apr_size_t * len,
                                             apr_read_type_e block)
{
    fcgid_bucket_ctx *ctx = (fcgid_bucket_ctx *) b->data;
    server_rec *s = ctx->ipc.request->server;
    apr_status_t rv;
    apr_size_t hasread, bodysize;
    FCGI_Header header;
    apr_bucket *curbucket = b;

    /* Keep reading until I get a fastcgi header */
    hasread = 0;
    while (hasread < sizeof(header)) {
        char *buffer;
        apr_size_t bufferlen, putsize;

        /* Feed some data if necessary */
        if ((rv =
             fcgid_feed_data(ctx, b->list, &buffer,<commit_msg>axe unused variables left behind by r816367<commit_after>/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "fcgid_bucket.h"
#include "fcgid_protocol.h"
#include "fcgid_bridge.h"

#define FCGID_FEED_LEN 8192
static apr_status_t fcgid_feed_data(fcgid_bucket_ctx * ctx,
                                    apr_bucket_alloc_t * bucketalloc,
                                    char **buffer, apr_size_t * bufferlen)
{
    apr_status_t rv;

    if (!ctx->buffer) {
        *buffer = apr_bucket_alloc(FCGID_FEED_LEN, bucketalloc);

        *bufferlen = FCGID_FEED_LEN;
        if ((rv =
             proc_read_ipc(&ctx->ipc, *buffer,
                           bufferlen)) != APR_SUCCESS) {
            ctx->has_error = 1;
            apr_bucket_free(*buffer);
            return rv;
        }

        ctx->buffer =
            apr_bucket_heap_create(*buffer, FCGID_FEED_LEN,
                                   apr_bucket_free, bucketalloc);
        if (*bufferlen != FCGID_FEED_LEN) {
            apr_bucket *buckettmp;

            apr_bucket_split(ctx->buffer, *bufferlen);
            buckettmp = APR_BUCKET_NEXT(ctx->buffer);
            apr_bucket_delete(buckettmp);
        }
    } else {
        apr_bucket_read(ctx->buffer, (const char **) buffer, bufferlen,
                        APR_BLOCK_READ);
    }
    return APR_SUCCESS;
}

static void fcgid_ignore_bytes(fcgid_bucket_ctx * ctx,
                               apr_size_t ignorebyte)
{
    apr_bucket *buckettmp;

    if (ignorebyte == ctx->buffer->length) {
        apr_bucket_destroy(ctx->buffer);
        ctx->buffer = NULL;
    } else {
        apr_bucket_split(ctx->buffer, ignorebyte);
        buckettmp = ctx->buffer;
        ctx->buffer = APR_BUCKET_NEXT(ctx->buffer);
        apr_bucket_delete(buckettmp);
    }
}

static apr_status_t fcgid_header_bucket_read(apr_bucket * b,
                                             const char **str,
                                             apr_size_t * len,
                                             apr_read_type_e block)
{
    fcgid_bucket_ctx *ctx = (fcgid_bucket_ctx *) b->data;
    apr_status_t rv;
    apr_size_t hasread, bodysize;
    FCGI_Header header;
    apr_bucket *curbucket = b;

    /* Keep reading until I get a fastcgi header */
    hasread = 0;
    while (hasread < sizeof(header)) {
        char *buffer;
        apr_size_t bufferlen, putsize;

        /* Feed some data if necessary */
        if ((rv =
             fcgid_feed_data(ctx, b->list, &buffer,
{'fraction_non_alphanumeric': 0.0852099817407182, 'fraction_numerical': 0.003956177723676202, 'mean_word_length': 2.1107430194036914, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '638296', 'n_tokens_mistral': 1950, 'n_tokens_neox': 1927, 'n_words': 513}