<commit_before>/*
 * Copyright (c) 2005, 2006 by KoanLogic s.r.l. <http://www.koanlogic.com>
 * All rights reserved.
 *
 * This file is part of KLone, and as such it is subject to the license stated
 * in the LICENSE file which you have received as part of this distribution.
 *
 * $Id: broker.c,v 1.12 2006/04/06 14:50:03 tat Exp $
 */

#include "klone_conf.h"
#include <u/libu.h>
#include <klone/supplier.h>
#include <klone/broker.h>
#include <klone/request.h>

enum { AVAIL_SUP_COUNT = 2 }; /* number of existing supplier types */

extern supplier_t sup_emb;
extern supplier_t sup_fs;

struct broker_s
{
    supplier_t *sup_list[AVAIL_SUP_COUNT + 1];
};

int broker_is_valid_uri(broker_t *b, const char *buf, size_t len)
{
    int i;
    time_t mtime;

    dbg_goto_if (b == NULL, notfound);
    dbg_goto_if (buf == NULL, notfound);
    
    for(i = 0; b->sup_list[i]; ++i)
        if(b->sup_list[i]->is_valid_uri(buf, len, &mtime))
            return 1; /* found */

notfound:
    return 0;
}

int broker_serve(broker_t *b, request_t *rq, response_t *rs)
{
    const char *file_name;
    int i, rc = HTTP_STATUS_NOT_FOUND;
    time_t mtime, ims;

    dbg_err_if (b == NULL);
    dbg_err_if (rq == NULL);
    dbg_err_if (rs == NULL);
    
    file_name = request_get_resolved_filename(rq);
    for(i = 0; b->sup_list[i]; ++i)
    {   
        if(b->sup_list[i]->is_valid_uri(file_name, strlen(file_name), &mtime) )
        {
            ims = request_get_if_modified_since(rq);
            if(ims && ims >= mtime)
            {
                response_set_status(rs, HTTP_STATUS_NOT_MODIFIED); 
                dbg_err_if(response_print_header(rs));
            } else {
                dbg_err_if(b->sup_list[i]->serve(rq, rs));
                if(response_get_status(rs) != HTTP_STATUS_OK)
                    return response_get_status(rs);
            }

            return 0; /* page successfully served */
        }
    }

    response_set_status(rs, HTTP_STATUS_NOT_FOUND); 

err:
    return HTTP_STATUS_NOT_FOUND; /* page not found */
}
<commit_msg>[klone] 404 err log message<commit_after>/*
 * Copyright (c) 2005, 2006 by KoanLogic s.r.l. <http://www.koanlogic.com>
 * All rights reserved.
 *
 * This file is part of KLone, and as such it is subject to the license stated
 * in the LICENSE file which you have received as part of this distribution.
 *
 * $Id: broker.c,v 1.13 2006/05/27 17:16:18 tat Exp $
 */

#include "klone_conf.h"
#include <u/libu.h>
#include <klone/supplier.h>
#include <klone/broker.h>
#include <klone/request.h>

enum { AVAIL_SUP_COUNT = 2 }; /* number of existing supplier types */

extern supplier_t sup_emb;
extern supplier_t sup_fs;

struct broker_s
{
    supplier_t *sup_list[AVAIL_SUP_COUNT + 1];
};

int broker_is_valid_uri(broker_t *b, const char *buf, size_t len)
{
    int i;
    time_t mtime;

    dbg_goto_if (b == NULL, notfound);
    dbg_goto_if (buf == NULL, notfound);
    
    for(i = 0; b->sup_list[i]; ++i)
        if(b->sup_list[i]->is_valid_uri(buf, len, &mtime))
            return 1; /* found */

notfound:
    return 0;
}

int broker_serve(broker_t *b, request_t *rq, response_t *rs)
{
    const char *file_name;
    int i, rc = HTTP_STATUS_NOT_FOUND;
    time_t mtime, ims;

    dbg_err_if (b == NULL);
    dbg_err_if (rq == NULL);
    dbg_err_if (rs == NULL);
    
    file_name = request_get_resolved_filename(rq);
    for(i = 0; b->sup_list[i]; ++i)
    {   
        if(b->sup_list[i]->is_valid_uri(file_name, strlen(file_name), &mtime) )
        {
            ims = request_get_if_modified_since(rq);
            if(ims && ims >= mtime)
            {
                response_set_status(rs, HTTP_STATUS_NOT_MODIFIED); 
                dbg_err_if(response_print_header(rs));
            } else {
                dbg_err_if(b->sup_list[i]->serve(rq, rs));
                if(response_get_status(rs) >= 400)
                    return response_get_status(rs);
            }

            return 0; /* page successfully served */
        }
    }

    response_set_status(rs, HTTP_STATUS_NOT_FOUND); 
    warn("404, file not found: %s", request_get_filename(rq));

err:
    return HTTP_STATUS_NOT_FOUND; /* page not found */
}

{'fraction_non_alphanumeric': 0.12679083094555874, 'fraction_numerical': 0.017430754536771727, 'mean_word_length': 2.608096468561585, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 32, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '7180583', 'n_tokens_mistral': 1621, 'n_tokens_neox': 1515, 'n_words': 356}