<commit_before>/**
 *    Copyright(c) 2016 rryqszq4
 *
 *
 */

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

#include "php/php_ngx.h"

#include "ngx_http_php_module.h"
#include "ngx_http_php_directive.h"
#include "ngx_http_php_handler.h"

// http init
static ngx_int_t ngx_http_php_init(ngx_conf_t *cf);
static ngx_int_t ngx_http_php_handler_init(ngx_http_core_main_conf_t *cmcf, ngx_http_php_main_conf_t *pmcf);

static void *ngx_http_php_create_main_conf(ngx_conf_t *cf);
static char *ngx_http_php_init_main_conf(ngx_conf_t *cf, void *conf);

static void *ngx_http_php_create_loc_conf(ngx_conf_t *cf);
static char *ngx_http_php_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child); 

// function init
static ngx_int_t ngx_http_php_init_worker(ngx_cycle_t *cycle);
static void ngx_http_php_exit_worker(ngx_cycle_t *cycle);

static ngx_command_t ngx_http_php_commands[] = {

	{ngx_string("php_ini_path"),
	 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
	 ngx_http_php_ini_path,
	 NGX_HTTP_MAIN_CONF_OFFSET,
	 0,
	 NULL
	},

	{ngx_string("php_init_code"),
	 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
	 ngx_http_php_init_inline_phase,
	 NGX_HTTP_MAIN_CONF_OFFSET,
	 0,
	 NULL
	},

	{ngx_string("php_init_file"),
	 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
	 ngx_http_php_init_file_phase,
	 NGX_HTTP_MAIN_CONF_OFFSET,
	 0,
	 NULL
	},

	{ngx_string("php_rewrite_handler"),
	 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
	 	|NGX_CONF_TAKE1,
	 ngx_http_php_rewrite_phase,
	 NGX_HTTP_LOC_CONF_OFFSET,
	 0,
	 ngx_http_php_rewrite_file_handler
	},

	{ngx_string("php_rewrite_handler_code"),
	 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
	 	|NGX_CONF_TAKE1,
	 ngx_http_php_rewrite_inline_phase,
	 NGX_HTTP_LOC_CONF_OFFSET,
	 0,
	 ngx_http_php_rewrite_inline_handler
	},

	{ngx_string("php_access_handler"),
	 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
	 	|NGX_CONF_TAKE1,
	 ngx_http_php_access_phase,
	 NGX_HTTP_LOC_CONF_OFFSET,
	 0,
	 ngx_http_php_access_file_handler
	},

	{ngx_string("php_access_handler_code"),
	 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
	 	|NGX_CONF_TAKE1,
	 ngx_http_php_access_inline_phase,
	 NGX_HTTP_LOC_CONF_OFFSET,
	 0,
	 ngx_http_php_access_inline_handler
	},

	{ngx_string("php_content_handler"),
	 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
	 	|NGX_CONF_TAKE1,
	 ngx_http_php_content_phase,
	 NGX_HTTP_LOC_CONF_OFFSET,
	 0,
	 ngx_http_php_content_file_handler
	},

	{ngx_string("php_content_handler_code"),
	 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
	 	|NGX_CONF_TAKE1,
	 ngx_http_php_content_inline_phase,
	 NGX_HTTP_LOC_CONF_OFFSET,
	 0,
	 ngx_http_php_content_inline_handler
	},

	ngx_null_command
};

static ngx_http_module_t ngx_http_php_module_ctx = {
	NULL,                          /* preconfiguration */
	ngx_http_php_init,             /* postconfiguration */

	ngx_http_php_create_main_conf, /* create main configuration */
	ngx_http_php_init_main_conf,   /* init main configuration */

	NULL,                          /* create server configuration */
	NULL,                          /* merge server configuration */

	ngx_http_php_create_loc_conf,  /* create location configuration */
	ngx_http_php_merge_loc_conf    /* merge location configuration */

};


ngx_module_t ngx_http_php_module = {
	NGX_MODULE_V1,
	&ngx_http_php_module_ctx,    /* module context */
	ngx_http_php_commands,       /* module directives */
	NGX_HTTP_MODULE,               /* module type */
	NULL,                          /* init master */
	NULL,                          /* init module */
	ngx_http_php_init_worker,      /* init process */
	NULL,                          /* init thread */
	NULL,                          /* exit thread */
	ngx_http_php_exit_worker,      /* exit process */
	NULL,                          /* exit master */
	NGX_MODULE_V1_PADDING
};

static ngx_int_t 
ngx_http_php_init(ngx_conf_t *cf)
{
	ngx_http_core_main_conf_t *cmcf;
	ngx_http_php_main_conf_t *pmcf;

	cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);
	pmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_php_module);

	ngx_php_request = NULL;

	if (ngx_http_php_handler_init(cmcf, pmcf) != NGX_OK){
		return NGX_ERROR;
	}

	return NGX_OK;
}

static ngx_int_t 
ngx_http_php_handler_init(ngx_http_core_main_conf_t *cmcf, ngx_http_php_main_conf_t *pmcf)
{
	ngx_int_t i;
	ngx_http_handler_pt *h;
	ngx_http_phases phase;
	ngx_http_phases phases[] = {
		NGX_HTTP_REWRITE_PHASE,
		NGX_HTTP_ACCESS_PHASE,
		NGX_HTTP_CONTENT_PHASE,
	};
	ngx_int_t phases_c;

	phases_c = sizeof(phases) / sizeof(ngx_http_phases);
	for (i = 0; i < phases_c; i++){
		phase = phases[i];
		switch (phase){
			case NGX_HTTP_REWRITE_PHASE:
				if (pmcf->enabled_rewrite_handler){
					h = ngx_array_push(&cmcf->phases[phase].handlers);
					if (h == NULL){
						return NGX_ERROR;
					}
					*h = ngx_http_php_rewrite_handler;
				}
				break;
			case NGX_HTTP_ACCESS_PHASE:
				if (pmcf->enabled_access_handler){
					h = ngx_array_push(&cmcf->phases[phase].handlers);
					if (h == NULL){
						return NGX_ERROR;
					}
					*h = ngx_http_php_access_handler;
				}
			case NGX_HTTP_CONTENT_PHASE:<commit_msg>[src] bugfix: miss break<commit_after>/**
 *    Copyright(c) 2016 rryqszq4
 *
 *
 */

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

#include "php/php_ngx.h"

#include "ngx_http_php_module.h"
#include "ngx_http_php_directive.h"
#include "ngx_http_php_handler.h"

// http init
static ngx_int_t ngx_http_php_init(ngx_conf_t *cf);
static ngx_int_t ngx_http_php_handler_init(ngx_http_core_main_conf_t *cmcf, ngx_http_php_main_conf_t *pmcf);

static void *ngx_http_php_create_main_conf(ngx_conf_t *cf);
static char *ngx_http_php_init_main_conf(ngx_conf_t *cf, void *conf);

static void *ngx_http_php_create_loc_conf(ngx_conf_t *cf);
static char *ngx_http_php_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child); 

// function init
static ngx_int_t ngx_http_php_init_worker(ngx_cycle_t *cycle);
static void ngx_http_php_exit_worker(ngx_cycle_t *cycle);

static ngx_command_t ngx_http_php_commands[] = {

	{ngx_string("php_ini_path"),
	 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
	 ngx_http_php_ini_path,
	 NGX_HTTP_MAIN_CONF_OFFSET,
	 0,
	 NULL
	},

	{ngx_string("php_init_code"),
	 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
	 ngx_http_php_init_inline_phase,
	 NGX_HTTP_MAIN_CONF_OFFSET,
	 0,
	 NULL
	},

	{ngx_string("php_init_file"),
	 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
	 ngx_http_php_init_file_phase,
	 NGX_HTTP_MAIN_CONF_OFFSET,
	 0,
	 NULL
	},

	{ngx_string("php_rewrite_handler"),
	 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
	 	|NGX_CONF_TAKE1,
	 ngx_http_php_rewrite_phase,
	 NGX_HTTP_LOC_CONF_OFFSET,
	 0,
	 ngx_http_php_rewrite_file_handler
	},

	{ngx_string("php_rewrite_handler_code"),
	 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
	 	|NGX_CONF_TAKE1,
	 ngx_http_php_rewrite_inline_phase,
	 NGX_HTTP_LOC_CONF_OFFSET,
	 0,
	 ngx_http_php_rewrite_inline_handler
	},

	{ngx_string("php_access_handler"),
	 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
	 	|NGX_CONF_TAKE1,
	 ngx_http_php_access_phase,
	 NGX_HTTP_LOC_CONF_OFFSET,
	 0,
	 ngx_http_php_access_file_handler
	},

	{ngx_string("php_access_handler_code"),
	 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
	 	|NGX_CONF_TAKE1,
	 ngx_http_php_access_inline_phase,
	 NGX_HTTP_LOC_CONF_OFFSET,
	 0,
	 ngx_http_php_access_inline_handler
	},

	{ngx_string("php_content_handler"),
	 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
	 	|NGX_CONF_TAKE1,
	 ngx_http_php_content_phase,
	 NGX_HTTP_LOC_CONF_OFFSET,
	 0,
	 ngx_http_php_content_file_handler
	},

	{ngx_string("php_content_handler_code"),
	 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
	 	|NGX_CONF_TAKE1,
	 ngx_http_php_content_inline_phase,
	 NGX_HTTP_LOC_CONF_OFFSET,
	 0,
	 ngx_http_php_content_inline_handler
	},

	ngx_null_command
};

static ngx_http_module_t ngx_http_php_module_ctx = {
	NULL,                          /* preconfiguration */
	ngx_http_php_init,             /* postconfiguration */

	ngx_http_php_create_main_conf, /* create main configuration */
	ngx_http_php_init_main_conf,   /* init main configuration */

	NULL,                          /* create server configuration */
	NULL,                          /* merge server configuration */

	ngx_http_php_create_loc_conf,  /* create location configuration */
	ngx_http_php_merge_loc_conf    /* merge location configuration */

};


ngx_module_t ngx_http_php_module = {
	NGX_MODULE_V1,
	&ngx_http_php_module_ctx,    /* module context */
	ngx_http_php_commands,       /* module directives */
	NGX_HTTP_MODULE,               /* module type */
	NULL,                          /* init master */
	NULL,                          /* init module */
	ngx_http_php_init_worker,      /* init process */
	NULL,                          /* init thread */
	NULL,                          /* exit thread */
	ngx_http_php_exit_worker,      /* exit process */
	NULL,                          /* exit master */
	NGX_MODULE_V1_PADDING
};

static ngx_int_t 
ngx_http_php_init(ngx_conf_t *cf)
{
	ngx_http_core_main_conf_t *cmcf;
	ngx_http_php_main_conf_t *pmcf;

	cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);
	pmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_php_module);

	ngx_php_request = NULL;

	if (ngx_http_php_handler_init(cmcf, pmcf) != NGX_OK){
		return NGX_ERROR;
	}

	return NGX_OK;
}

static ngx_int_t 
ngx_http_php_handler_init(ngx_http_core_main_conf_t *cmcf, ngx_http_php_main_conf_t *pmcf)
{
	ngx_int_t i;
	ngx_http_handler_pt *h;
	ngx_http_phases phase;
	ngx_http_phases phases[] = {
		NGX_HTTP_REWRITE_PHASE,
		NGX_HTTP_ACCESS_PHASE,
		NGX_HTTP_CONTENT_PHASE,
	};
	ngx_int_t phases_c;

	phases_c = sizeof(phases) / sizeof(ngx_http_phases);
	for (i = 0; i < phases_c; i++){
		phase = phases[i];
		switch (phase){
			case NGX_HTTP_REWRITE_PHASE:
				if (pmcf->enabled_rewrite_handler){
					h = ngx_array_push(&cmcf->phases[phase].handlers);
					if (h == NULL){
						return NGX_ERROR;
					}
					*h = ngx_http_php_rewrite_handler;
				}
				break;
			case NGX_HTTP_ACCESS_PHASE:
				if (pmcf->enabled_access_handler){
					h = ngx_array_push(&cmcf->phases[phase].handlers);
					if (h == NULL){
						return NGX_ERROR;
					}
					*h = ngx_http_php_access_handler;
				}
				break;
			case NGX_HTTP_CONTENT_PHASE:
{'fraction_non_alphanumeric': 0.08820224719101123, 'fraction_numerical': 0.0048689138576779025, 'mean_word_length': 4.4634271099744245, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 21, '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': '4089446', 'n_tokens_mistral': 4819, 'n_tokens_neox': 4440, 'n_words': 563}