// File: /workspace/github_cpp_makefile_star2_O2/mbourand[P]webserv/srcs/Config/ConfigContext.cpp
// Function: ConfigContext::ConfigContext(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, ConfigContext const*)
ConfigContext::ConfigContext(const std::string& raw, const std::string& name, const ConfigContext* parent)
	: _autoIndex(false)
{
	handle_parent_and_directives(parent, name);

	for (size_t i = 0; i < raw.size();)
	{
		// On skip les whitepsaces en début de ligne
		i = raw.find_first_not_of(" \t", i);
		if (i == std::string::npos)
			break;

		// Si la ligne est vide ou que c'est un commentaire, on skip la ligne
		if (raw[i] == '\n' || raw[i] == '#')
		{
			i = raw.find('\n', i) + 1;
			continue;
		}

		// On récupère le nom de la directive, par exemple : "server_name" ou "root", etc.
		std::string directive_name = raw.substr(i, raw.find_first_of(" \t", i) - i);
		if (!ft::contains(_directive_names, directive_name))
			throw std::invalid_argument("Unknown directive name in config");

		// Pour empêcher une directive d'apparaître deux fois dans le même context
		if (_params.find(directive_name) != _params.end())
			_params.erase(_params.find(directive_name));

		i += directive_name.size();
		i = raw.find_first_not_of(" \t", i);

		std::string directive_value = raw.substr(i, raw.find('\n', i) - i);
		if (directive_value.empty())
			throw std::invalid_argument("Empty directive value in config");

		if (directive_name == "location")
		{
			// On récupère le chemin de la location (juste après le nom de la directive)
			std::string location_name = raw.substr(i, raw.find_first_of(" \t\n", i) - i);
			i += location_name.size();
			i = raw.find_first_not_of(" \t", i);

			// Si il n'y a pas d'accolate ouvrante, la config est invalide
			if (raw[i] != '{')
				throw std::invalid_argument("Bad curly braces in config");
			i = raw.find_first_not_of(" \t", i + 1);

			// Si il n'y a pas de retour à la ligne après les espaces, la config est invalide
			if (raw[i] != '\n')
				throw std::invalid_argument("Bad new line in config");

			// On récupère le contenu du fichier qui concerne la location
			std::string location_raw = raw.substr(i, find_closing_bracket(raw, i) - i - 2);
			_childs.push_back(ConfigContext(location_raw, location_name, this));
			i += location_raw.size() + 2;
			if (raw.find('\n', i) == std::string::npos)
				break;
			i = raw.find('\n', i) + 1;
			continue;
		}
		else if (directive_name == "server_name")
			parse_server_name(directive_value);
		else if (directive_name == "error_page")
			parse_error_page(directive_value);
		else if (directive_name == "autoindex")
			parse_autoindex(directive_value);
		else if (directive_name == "disable_methods")
			parse_methods(directive_value);
		else if (directive_name == "cgi_ext")
			parse_cgi_ext(directive_value);
		else if (directive_name == "uploads_exts")
			parse_uploads_exts(directive_value);
		else if (directive_name == "auth_basic")
			parse_auth_basic(directive_value);
		else
		{
			std::string directive_value = raw.substr(i, raw.find('\n', i) - i);
			if (directive_value.size() == 0)
				throw std::invalid_argument("Empty directive value in config");
			_params.insert(std::make_pair(directive_name, ft::split(directive_value, " \t")));
		}
		if (raw.find('\n', i) == std::string::npos)
			break;
		i = raw.find('\n', i) + 1;
	}
	if (ft::contains(_directive_names, "listen") && _params.find("listen") == _params.end())
		throw std::invalid_argument("No listen in config");
	set_uploads_default();
	set_root_default(parent);
	set_max_body_size_default();
	set_cgi_dir_default();
	set_auth_basic_default();
	if (_params["auth_basic"].front() != "")
		set_auth_basic_user_file_default();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x208, %rsp            # imm = 0x208
movq %rdi, %r14
leaq 0x23917(%rip), %rax     # 0x42cb8
movq %rax, (%rdi)
leaq 0x8(%rdi), %rbp
movq %rbp, 0x10(%rdi)
movq %rbp, 0x8(%rdi)
andq $0x0, 0x18(%rdi)
leaq 0x28(%rdi), %rax
andl $0x0, 0x28(%rdi)
andq $0x0, 0x30(%rdi)
movq %rax, 0x38(%rdi)
movq %rax, 0x50(%rsp)
movq %rax, 0x40(%rdi)
andq $0x0, 0x48(%rdi)
leaq 0x50(%rdi), %rax
movq %rax, 0x58(%rdi)
movq %rax, 0x40(%rsp)
movq %rax, 0x50(%rdi)
andq $0x0, 0x60(%rdi)
leaq 0x70(%rdi), %rax
andl $0x0, 0x70(%rdi)
andq $0x0, 0x78(%rdi)
movq %rax, 0x80(%rdi)
movq %rax, 0x88(%rdi)
andq $0x0, 0x90(%rdi)
leaq 0x98(%rdi), %rax
movq %rax, 0xa0(%rdi)
movq %rax, 0xa8(%rsp)
movq %rax, 0x98(%rdi)
andq $0x0, 0xa8(%rdi)
movq %rsi, %r12
leaq 0xb0(%rdi), %rax
movq %rax, 0xb8(%rdi)
movq %rax, 0xa0(%rsp)
movq %rax, 0xb0(%rdi)
andq $0x0, 0xc0(%rdi)
leaq 0xd0(%rdi), %rax
andl $0x0, 0xd0(%rdi)
andq $0x0, 0xd8(%rdi)
movq %rax, 0xe0(%rdi)
movq %rax, 0xe8(%rdi)
andq $0x0, 0xf0(%rdi)
leaq 0x20(%rdi), %rax
movq %rax, 0x8(%rsp)
leaq 0xf8(%rdi), %rax
movq %rax, 0x100(%rdi)
movq %rax, 0x98(%rsp)
movq %rax, 0xf8(%rdi)
andq $0x0, 0x108(%rdi)
movb $0x0, 0x110(%rdi)
movq %rcx, 0xb0(%rsp)
movq %rcx, %rsi
movq %rbp, 0x38(%rsp)
movq %rdi, 0x48(%rsp)
callq 0x1fcb0
xorl %r13d, %r13d
leaq 0xe335(%rip), %r15      # 0x2d814
cmpq 0x8(%r12), %r13
jae 0x1f952
movq %r12, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x7330
cmpq $-0x1, %rax
je 0x1f952
movq %rax, %r13
movq (%r12), %rax
movzbl (%rax,%r13), %eax
cmpl $0x23, %eax
je 0x1f518
cmpl $0xa, %eax
jne 0x1f52e
movq %r12, %rdi
pushq $0xa
popq %rsi
movq %r13, %rdx
callq 0x7650
movq %rax, %r13
incq %r13
jmp 0x1f4df
movq %r12, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x72b0
subq %r13, %rax
leaq 0x58(%rsp), %rbx
movq %rbx, %rdi
movq %r12, %rsi
movq %r13, %rdx
movq %rax, %rcx
callq 0x7540
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x21df4
testb %al, %al
je 0x1fa46
movq 0x8(%rsp), %rdi
leaq 0x58(%rsp), %rsi
callq 0x233e6
cmpq 0x50(%rsp), %rax
je 0x1f59a
movq 0x8(%rsp), %rdi
leaq 0x58(%rsp), %rsi
callq 0x233e6
movq 0x8(%rsp), %rdi
movq %rax, %rsi
callq 0x2345c
movq 0x60(%rsp), %rdx
addq %r13, %rdx
movq %r12, %rdi
movq %r15, %rsi
callq 0x7330
movq %rax, %r13
movq %r12, %rdi
pushq $0xa
popq %rsi
movq %rax, %rdx
callq 0x7650
subq %r13, %rax
leaq 0x18(%rsp), %rdi
movq %r12, %rsi
movq %r13, %rdx
movq %rax, %rcx
callq 0x7540
cmpq $0x0, 0x20(%rsp)
leaq 0x58(%rsp), %rbx
je 0x1fa7b
movq %rbx, %rdi
leaq 0xf890(%rip), %rsi      # 0x2ee7f
callq 0x91b7
testb %al, %al
je 0x1f742
movq %r12, %rdi
leaq 0xe239(%rip), %rsi      # 0x2d83f
movq %r13, %rdx
callq 0x72b0
subq %r13, %rax
leaq 0x78(%rsp), %rdi
movq %r12, %rsi
movq %r13, %rdx
movq %rax, %rcx
callq 0x7540
movq 0x80(%rsp), %rdx
addq %r13, %rdx
movq %r12, %rdi
movq %r15, %rsi
callq 0x7330
movq (%r12), %rcx
cmpb $0x7b, (%rcx,%rax)
pushq $0xa
popq %rbp
jne 0x1fab0
incq %rax
movq %r12, %rdi
movq %r15, %rsi
movq %rax, %rdx
callq 0x7330
movq %rax, %r13
movq (%r12), %rax
cmpb $0xa, (%rax,%r13)
jne 0x1facc
movq %r12, %rsi
movq %r13, %rdx
callq 0x1fd7e
subq %r13, %rax
leaq -0x2(%rax), %rcx
leaq 0xb8(%rsp), %r14
movq %r14, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x7540
leaq 0xf0(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
leaq 0x78(%rsp), %rdx
movq 0x48(%rsp), %r14
movq %r14, %rcx
callq 0x1f386
movq 0x40(%rsp), %rdi
movq %rbx, %rsi
callq 0x21e0e
movq %rbx, %rdi
callq 0x1f0f0
movq 0xc0(%rsp), %rax
addq %rax, %r13
addq $0x2, %r13
movq %r12, %rdi
movl %ebp, %esi
movq %r13, %rdx
callq 0x7650
movl %ebp, %esi
movq %rax, %rbp
cmpq $-0x1, %rax
je 0x1f703
movq %r12, %rdi
movq %r13, %rdx
callq 0x7650
movq %rax, %r13
incq %r13
leaq 0xb8(%rsp), %rdi
callq 0x79b8
leaq 0x78(%rsp), %rdi
callq 0x79b8
leaq 0x18(%rsp), %rdi
callq 0x79b8
leaq 0x58(%rsp), %rdi
callq 0x79b8
cmpq $-0x1, %rbp
movq 0x38(%rsp), %rbp
jne 0x1f4df
jmp 0x1f952
movq %rbx, %rdi
leaq 0xf58c(%rip), %rsi      # 0x2ecd8
callq 0x91b7
testb %al, %al
je 0x1f767
movq %r14, %rdi
leaq 0x18(%rsp), %rsi
callq 0x1fdbc
jmp 0x1f8f9
movq %rbx, %rdi
leaq 0xf573(%rip), %rsi      # 0x2ece4
callq 0x91b7
testb %al, %al
je 0x1f78c
movq %r14, %rdi
leaq 0x18(%rsp), %rsi
callq 0x1fe88
jmp 0x1f8f9
movq %rbx, %rdi
leaq 0xf559(%rip), %rsi      # 0x2ecef
callq 0x91b7
testb %al, %al
je 0x1f7b1
movq %r14, %rdi
leaq 0x18(%rsp), %rsi
callq 0x20044
jmp 0x1f8f9
movq %rbx, %rdi
leaq 0xf53e(%rip), %rsi      # 0x2ecf9
callq 0x91b7
testb %al, %al
je 0x1f7d6
movq %r14, %rdi
leaq 0x18(%rsp), %rsi
callq 0x2016a
jmp 0x1f8f9
movq %rbx, %rdi
leaq 0xf529(%rip), %rsi      # 0x2ed09
callq 0x91b7
testb %al, %al
je 0x1f7fb
movq %r14, %rdi
leaq 0x18(%rsp), %rsi
callq 0x202b6
jmp 0x1f8f9
movq %rbx, %rdi
leaq 0xf50c(%rip), %rsi      # 0x2ed11
callq 0x91b7
testb %al, %al
je 0x1f820
movq %r14, %rdi
leaq 0x18(%rsp), %rsi
callq 0x2052c
jmp 0x1f8f9
movq %rbx, %rdi
leaq 0xf4f4(%rip), %rsi      # 0x2ed1e
callq 0x91b7
testb %al, %al
je 0x1f845
movq %r14, %rdi
leaq 0x18(%rsp), %rsi
callq 0x2069a
jmp 0x1f8f9
movq %r12, %rdi
pushq $0xa
popq %rsi
movq %r13, %rdx
callq 0x7650
subq %r13, %rax
leaq 0x78(%rsp), %rdi
movq %r12, %rsi
movq %r13, %rdx
movq %rax, %rcx
callq 0x7540
cmpq $0x0, 0x80(%rsp)
je 0x1fb2e
leaq 0xb8(%rsp), %rdi
movq %rdi, %rbx
movq %r15, %rsi
leaq 0x17(%rsp), %rdx
callq 0x8032
leaq 0xd8(%rsp), %r15
movq %r15, %rdi
leaq 0x78(%rsp), %rsi
movq %rbx, %rdx
callq 0x16f10
leaq 0xf0(%rsp), %rbx
movq %rbx, %rdi
leaq 0x58(%rsp), %rsi
movq %r15, %rdx
callq 0x22cb4
movq 0x8(%rsp), %rdi
movq %rbx, %rsi
callq 0x2352e
movq %rbx, %rdi
callq 0x21e1a
leaq 0xd8(%rsp), %rdi
callq 0x8f64
leaq 0xb8(%rsp), %rdi
callq 0x79b8
leaq 0x78(%rsp), %rdi
callq 0x79b8
movq %r12, %rdi
pushq $0xa
popq %r15
movl %r15d, %esi
movq %r13, %rdx
callq 0x7650
cmpq $-0x1, %rax
je 0x1f93e
movq %r12, %rdi
movl %r15d, %esi
movq %r13, %rdx
callq 0x7650
movq %rax, %r13
incq %r13
leaq 0x18(%rsp), %rdi
callq 0x79b8
leaq 0x58(%rsp), %rdi
callq 0x79b8
jmp 0x1f4d8
leaq 0x18(%rsp), %rdi
callq 0x79b8
leaq 0x58(%rsp), %rdi
callq 0x79b8
leaq 0xf3d0(%rip), %rsi      # 0x2ed29
movq %rbp, %rdi
callq 0x21e30
testb %al, %al
je 0x1f9ab
leaq 0xf3bd(%rip), %rsi      # 0x2ed29
leaq 0xf0(%rsp), %rdi
leaq 0x58(%rsp), %rdx
callq 0x8032
leaq 0xf0(%rsp), %rsi
movq 0x8(%rsp), %rdi
callq 0x233e6
movq %rax, %rbx
leaq 0xf0(%rsp), %rdi
callq 0x79b8
cmpq 0x50(%rsp), %rbx
je 0x1fafc
movq %r14, %rdi
callq 0x207f4
movq %r14, %rdi
movq 0xb0(%rsp), %rsi
callq 0x20a40
movq %r14, %rdi
callq 0x20c46
movq %r14, %rdi
callq 0x20e10
movq %r14, %rdi
callq 0x2105c
leaq 0xf33c(%rip), %rsi      # 0x2ed1e
leaq 0xf0(%rsp), %rdi
leaq 0x58(%rsp), %rdx
callq 0x8032
leaq 0xf0(%rsp), %rsi
movq 0x8(%rsp), %rdi
callq 0x21e4a
movq (%rax), %rdi
addq $0x10, %rdi
leaq 0xd33b(%rip), %rsi      # 0x2cd4f
callq 0x8f4f
movl %eax, %ebx
leaq 0xf0(%rsp), %rdi
callq 0x79b8
testb %bl, %bl
je 0x1fa34
movq %r14, %rdi
callq 0x2113c
addq $0x208, %rsp            # imm = 0x208
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x10
popq %rdi
callq 0x7290
movq %rax, %r15
leaq 0xf22d(%rip), %rsi      # 0x2ec85
movq %rax, %rdi
callq 0x7910
movq 0x23561(%rip), %rsi     # 0x42fc8
movq 0x23542(%rip), %rdx     # 0x42fb0
movq %r15, %rdi
callq 0x7830
jmp 0x1fb5e
pushq $0x10
popq %rdi
callq 0x7290
movq %rax, %r15
leaq 0xdd92(%rip), %rsi      # 0x2d81f
movq %rax, %rdi
callq 0x7910
movq 0x2352c(%rip), %rsi     # 0x42fc8
movq 0x2350d(%rip), %rdx     # 0x42fb0
movq %r15, %rdi
callq 0x7830
jmp 0x1fb5e
pushq $0x10
popq %rdi
callq 0x7290
movq %rax, %r15
leaq 0xf1e4(%rip), %rsi      # 0x2eca6
movq %rax, %rdi
callq 0x7910
jmp 0x1fae6
pushq $0x10
popq %rdi
callq 0x7290
movq %rax, %r15
leaq 0xf1e3(%rip), %rsi      # 0x2ecc1
movq %rax, %rdi
callq 0x7910
movq 0x234db(%rip), %rsi     # 0x42fc8
movq 0x234bc(%rip), %rdx     # 0x42fb0
movq %r15, %rdi
callq 0x7830
pushq $0x10
popq %rdi
callq 0x7290
movq %rax, %r15
leaq 0xf222(%rip), %rsi      # 0x2ed30
movq %rax, %rdi
callq 0x7910
movq 0x234ab(%rip), %rsi     # 0x42fc8
movq 0x2348c(%rip), %rdx     # 0x42fb0
movq %r15, %rdi
callq 0x7830
jmp 0x1fb5e
pushq $0x10
popq %rdi
callq 0x7290
movq %rax, %r15
leaq 0xdcdf(%rip), %rsi      # 0x2d81f
movq %rax, %rdi
callq 0x7910
movq 0x23479(%rip), %rsi     # 0x42fc8
movq 0x2345a(%rip), %rdx     # 0x42fb0
movq %r15, %rdi
callq 0x7830
jmp 0x1fbef
jmp 0x1fbba
movq %rax, %rbx
leaq 0xf0(%rsp), %rdi
callq 0x21e1a
jmp 0x1fb7a
movq %rax, %rbx
leaq 0xd8(%rsp), %rdi
callq 0x8f64
jmp 0x1fbde
jmp 0x1fbdb
jmp 0x1fbef
jmp 0x1fc00
movq %rax, %rbx
movq %r15, %rdi
callq 0x73d0
jmp 0x1fc43
jmp 0x1fba6
jmp 0x1fc31
movq %rax, %rbx
leaq 0xf0(%rsp), %rdi
jmp 0x1fc3e
jmp 0x1fc31
jmp 0x1fbba
movq %rax, %rbx
movq %r15, %rdi
callq 0x73d0
jmp 0x1fbf2
jmp 0x1fc00
movq %rax, %rbx
leaq 0xf0(%rsp), %rdi
callq 0x1f0f0
jmp 0x1fbde
movq %rax, %rbx
leaq 0xb8(%rsp), %rdi
callq 0x79b8
jmp 0x1fbf2
jmp 0x1fbef
movq %rax, %rbx
leaq 0x78(%rsp), %rdi
callq 0x79b8
jmp 0x1fc10
jmp 0x1fc00
movq %rax, %rbx
jmp 0x1fc10
movq %rax, %rbx
movq %r15, %rdi
callq 0x73d0
leaq 0x18(%rsp), %rdi
callq 0x79b8
jmp 0x1fc39
jmp 0x1fc36
movq %rax, %rbx
movq %r15, %rdi
callq 0x73d0
jmp 0x1fc39
jmp 0x1fc36
jmp 0x1fc36
jmp 0x1fc31
movq %rax, %rbx
jmp 0x1fc43
movq %rax, %rbx
leaq 0x58(%rsp), %rdi
callq 0x79b8
movq 0x48(%rsp), %r14
leaq 0xc8(%r14), %r15
addq $0x68, %r14
movq 0x98(%rsp), %rdi
callq 0x8f64
movq %r15, %rdi
callq 0x21fa4
movq 0xa0(%rsp), %rdi
callq 0x2201e
movq 0xa8(%rsp), %rdi
callq 0x8f64
movq %r14, %rdi
callq 0x22048
movq 0x40(%rsp), %rdi
callq 0x220ac
movq 0x8(%rsp), %rdi
callq 0x220e2
movq 0x38(%rsp), %rdi
callq 0x8f64
movq %rbx, %rdi
callq 0x7860