<commit_before>/*
 * inliner.c
 * Copyright © 2007 <NAME> <<EMAIL>>
 *
 * Distributed under terms of the MIT license.
 */

#include <ngx_config.h>
#include <ngx_core.h>
#include <ngx_http.h>


ngx_buf_t* nfi_inline_getbuf(ngx_http_request_t *r,
		const ngx_str_t const * path, ngx_int_t mode)
{
	size_t root_len;
	ngx_str_t resolved;
	ngx_buf_t *buf;
	ngx_file_t *bfile;
	ngx_file_info_t bfileinfo;

	ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
			"http nfi_inline_getbuf path: \"%V\"", path);

	ngx_memcpy(
			ngx_http_map_uri_to_path(r, &resolved, &root_len, path->len),
			path->data, path->len);

	ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
			"nfi_inline_getbuf resolved: \"%V\"", &resolved);

	/*
	 * Append final '\0' so we can use it to call ngx_file_info() below.
	 *
	 * If stat() fails, we know the file does *not* exist. We also check
	 * whether the file is readable. Note that if the file exists and is
	 * readable, the file info will be in the kernel inode cache so we
	 * do not incur in a lot of overhead by retrieving the information
	 * first.
	 */
	resolved.data[resolved.len] = '\0';

	if (ngx_file_info(resolved.data, &bfileinfo) != 0) {
		ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, ngx_errno,
				"nfi_inline_getbuf no file stats");
		return NULL;
	}

	if (!ngx_is_file(&bfileinfo) ||           /* we read regular files... */
			!(ngx_file_access(&bfileinfo) & 0444) /* ...which can be read...  */
			|| ngx_is_link(&bfileinfo))           /* ...and are not symlinks. */
		return NULL;

	bfile = ngx_pcalloc(r->pool, sizeof(ngx_file_t));
	if (bfile == NULL)
		return NULL;
<commit_msg>Simplified an expression a bit<commit_after>/*
 * inliner.c
 * Copyright © 2007 <NAME> <<EMAIL>.es>
 *
 * Distributed under terms of the MIT license.
 */

#include <ngx_config.h>
#include <ngx_core.h>
#include <ngx_http.h>


ngx_buf_t* nfi_inline_getbuf(ngx_http_request_t *r,
		const ngx_str_t const * path, ngx_int_t mode)
{
	size_t root_len;
	u_char *pos;
	ngx_str_t resolved;
	ngx_buf_t *buf;
	ngx_file_t *bfile;
	ngx_file_info_t bfileinfo;

	ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
			"http nfi_inline_getbuf path: \"%V\"", path);

	/*
	 * TODO: We do not handle absolute paths in configuration file yet.
	 */
	pos = ngx_http_map_uri_to_path(r, &resolved, &root_len, path->len);
	ngx_memcpy(pos, path->data, path->len);

	ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
			"nfi_inline_getbuf resolved: \"%V\"", &resolved);

	/*
	 * Append final '\0' so we can use it to call ngx_file_info() below.
	 *
	 * If stat() fails, we know the file does *not* exist. We also check
	 * whether the file is readable. Note that if the file exists and is
	 * readable, the file info will be in the kernel inode cache so we
	 * do not incur in a lot of overhead by retrieving the information
	 * first.
	 */
	resolved.data[resolved.len] = '\0';

	if (ngx_file_info(resolved.data, &bfileinfo) != 0) {
		ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, ngx_errno,
				"nfi_inline_getbuf no file stats");
		return NULL;
	}

	if (!ngx_is_file(&bfileinfo) ||           /* we read regular files... */
			!(ngx_file_access(&bfileinfo) & 0444) /* ...which can be read...  */
			|| ngx_is_link(&bfileinfo))           /* ...and are not symlinks. */
		return NULL;

	bfile = ngx_pcalloc(r->pool, sizeof(ngx_file_t));
	if (bfile == NULL)
		return NULL;

{'fraction_non_alphanumeric': 0.1341142020497804, 'fraction_numerical': 0.009370424597364568, 'mean_word_length': 3.718232044198895, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 35, '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': '3970372', 'n_tokens_mistral': 1405, 'n_tokens_neox': 1306, 'n_words': 352}