// File: /workspace/github_cpp_makefile_star2_O1/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 $0x1e8, %rsp            # imm = 0x1E8
movq %rcx, %r8
movq %rsi, %rbp
movq %rdi, %r14
leaq 0x25c55(%rip), %rax     # 0x4dca0
movq %rax, (%rdi)
leaq 0x8(%rdi), %rbx
movq %rbx, 0x10(%rdi)
movq %rbx, 0x8(%rdi)
xorl %eax, %eax
movq %rax, 0x18(%rdi)
leaq 0x20(%rdi), %rcx
movq %rcx, (%rsp)
leaq 0x28(%rdi), %rcx
movl %eax, 0x28(%rdi)
movq %rax, 0x30(%rdi)
movq %rcx, 0x38(%rdi)
movq %rcx, 0x90(%rsp)
movq %rcx, 0x40(%rdi)
movq %rax, 0x48(%rdi)
leaq 0x50(%rdi), %rcx
movq %rcx, 0x58(%rdi)
movq %rcx, 0x88(%rsp)
movq %rcx, 0x50(%rdi)
movq %rax, 0x60(%rdi)
leaq 0x70(%rdi), %rcx
movl %eax, 0x70(%rdi)
movq %rax, 0x78(%rdi)
movq %rcx, 0x80(%rdi)
movq %rcx, 0x88(%rdi)
movq %rax, 0x90(%rdi)
leaq 0x98(%rdi), %rcx
movq %rcx, 0xa0(%rdi)
movq %rcx, 0xa8(%rsp)
movq %rcx, 0x98(%rdi)
movq %rax, 0xa8(%rdi)
leaq 0xb0(%rdi), %rcx
movq %rcx, 0xb8(%rdi)
movq %rcx, 0xa0(%rsp)
movq %rcx, 0xb0(%rdi)
movq %rax, 0xc0(%rdi)
leaq 0xd0(%rdi), %rcx
movl %eax, 0xd0(%rdi)
movq %rax, 0xd8(%rdi)
movq %rcx, 0xe0(%rdi)
movq %rcx, 0xe8(%rdi)
movq %rax, 0xf0(%rdi)
leaq 0xf8(%rdi), %rcx
movq %rcx, 0x100(%rdi)
movq %rcx, 0x98(%rsp)
movq %rcx, 0xf8(%rdi)
movq %rax, 0x108(%rdi)
movb $0x0, 0x110(%rdi)
movq %r8, 0xb0(%rsp)
movq %r8, %rsi
callq 0x28b54
cmpq $0x0, 0x8(%rbp)
je 0x28701
xorl %r13d, %r13d
leaq 0x28(%rsp), %r12
leaq 0xd0(%rsp), %r15
movl $0x2, %ecx
movq %rbp, %rdi
leaq 0x136cb(%rip), %rsi     # 0x3b860
movq %r13, %rdx
callq 0x77a0
cmpq $-0x1, %rax
je 0x28701
movq %rax, %r13
movq (%rbp), %rax
movzbl (%rax,%r13), %eax
cmpl $0x23, %eax
je 0x281bd
cmpl $0xa, %eax
jne 0x281de
movq %rbp, %rdi
movl $0xa, %esi
movq %r13, %rdx
callq 0x75c0
movq %rax, %r13
incq %r13
cmpq 0x8(%rbp), %r13
jb 0x28186
jmp 0x28701
movl $0x2, %ecx
movq %rbp, %rdi
leaq 0x13673(%rip), %rsi     # 0x3b860
movq %r13, %rdx
callq 0x76c0
subq %r13, %rax
movq %r12, %rdi
movq %rbp, %rsi
movq %r13, %rdx
movq %rax, %rcx
callq 0x74d0
movq %r12, %rax
movq (%rbx), %r12
movq %rax, 0xd0(%rsp)
cmpq %rbx, %r12
je 0x28231
movq %r15, %rdi
movq %r12, %rsi
callq 0x2d6b6
testb %al, %al
jne 0x28231
movq (%r12), %r12
jmp 0x28217
cmpq %rbx, %r12
je 0x2888a
movq (%rsp), %rdi
leaq 0x28(%rsp), %r12
movq %r12, %rsi
callq 0x2d6e8
cmpq 0x90(%rsp), %rax
je 0x28274
movq %r12, %rsi
movq (%rsp), %r12
movq %r12, %rdi
callq 0x2d6e8
movq %r12, %rdi
movq %rax, %rsi
callq 0x2d772
leaq 0x28(%rsp), %r12
movq 0x30(%rsp), %rdx
addq %r13, %rdx
movl $0x2, %ecx
movq %rbp, %rdi
leaq 0x135d5(%rip), %rsi     # 0x3b860
callq 0x77a0
movq %rax, %r13
movq %rbp, %rdi
movl $0xa, %esi
movq %rax, %rdx
callq 0x75c0
subq %r13, %rax
leaq 0x68(%rsp), %rdi
movq %rbp, %rsi
movq %r13, %rdx
movq %rax, %rcx
callq 0x74d0
cmpq $0x0, 0x70(%rsp)
je 0x28853
movq %r12, %rdi
leaq 0x14c1b(%rip), %rsi     # 0x3ceea
callq 0x7180
testl %eax, %eax
je 0x2845e
movq %r12, %rdi
leaq 0x14a5d(%rip), %rsi     # 0x3cd43
callq 0x7180
testl %eax, %eax
je 0x28524
movq %r12, %rdi
leaq 0x14a52(%rip), %rsi     # 0x3cd4f
callq 0x7180
testl %eax, %eax
je 0x28536
movq %r12, %rdi
leaq 0x14a46(%rip), %rsi     # 0x3cd5a
callq 0x7180
testl %eax, %eax
je 0x28629
movq %r12, %rdi
leaq 0x14a39(%rip), %rsi     # 0x3cd64
callq 0x7180
testl %eax, %eax
je 0x28638
movq %r12, %rdi
leaq 0x14a32(%rip), %rsi     # 0x3cd74
callq 0x7180
testl %eax, %eax
je 0x28647
movq %r12, %rdi
leaq 0x14a23(%rip), %rsi     # 0x3cd7c
callq 0x7180
testl %eax, %eax
je 0x28656
movq %r12, %rdi
leaq 0x14a19(%rip), %rsi     # 0x3cd89
callq 0x7180
testl %eax, %eax
je 0x28665
movq %rbp, %rdi
movl $0xa, %esi
movq %r13, %rdx
callq 0x75c0
subq %r13, %rax
leaq 0x48(%rsp), %rdi
movq %rbp, %rsi
movq %r13, %rdx
movq %rax, %rcx
callq 0x74d0
cmpq $0x0, 0x50(%rsp)
leaq 0x8(%rsp), %rcx
je 0x28945
leaq 0x18(%rsp), %rax
movq %rax, 0x8(%rsp)
movq %rcx, %rdi
leaq 0x13498(%rip), %rsi     # 0x3b860
leaq 0x13493(%rip), %rdx     # 0x3b862
callq 0x80f4
leaq 0xb8(%rsp), %rdi
leaq 0x48(%rsp), %rsi
leaq 0x8(%rsp), %rdx
callq 0x1c232
movq %r15, %rdi
movq %r12, %rsi
leaq 0xb8(%rsp), %r12
movq %r12, %rdx
callq 0x2d0d0
movq (%rsp), %rdi
movq %r15, %rsi
callq 0x2d7f4
movq %r15, %rdi
callq 0x2c244
movq %r12, %rdi
callq 0x96d8
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x28439
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x74b0
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0x28672
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x74b0
jmp 0x28672
movl $0x3, %ecx
movq %rbp, %rdi
leaq 0x1341e(%rip), %rsi     # 0x3b88b
movq %r13, %rdx
callq 0x76c0
subq %r13, %rax
leaq 0x48(%rsp), %rdi
movq %rbp, %rsi
movq %r13, %rdx
movq %rax, %rcx
callq 0x74d0
movq 0x50(%rsp), %rdx
addq %r13, %rdx
movl $0x2, %ecx
movq %rbp, %rdi
leaq 0x133be(%rip), %r12     # 0x3b860
movq %r12, %rsi
callq 0x77a0
movq (%rbp), %rcx
cmpb $0x7b, (%rcx,%rax)
jne 0x288c1
incq %rax
movl $0x2, %ecx
movq %rbp, %rdi
movq %r12, %rsi
movq %rax, %rdx
callq 0x77a0
movq %rax, %r13
movq (%rbp), %rax
cmpb $0xa, (%rax,%r13)
jne 0x288df
movq 0x8(%rbp), %rdx
movq $-0x1, %rcx
cmpq %r13, %rdx
jbe 0x2854b
movl $0x1, %edi
movq %r13, %rsi
movb (%rax,%rsi), %r8b
xorl %r9d, %r9d
cmpb $0x7b, %r8b
sete %r9b
addq %r9, %rdi
xorl %r9d, %r9d
cmpb $0x7d, %r8b
sete %r9b
subq %r9, %rdi
je 0x28548
incq %rsi
cmpq %rsi, %rdx
jne 0x284f8
jmp 0x2854b
movq %r14, %rdi
leaq 0x68(%rsp), %rsi
callq 0x28cb2
jmp 0x28672
movq %r14, %rdi
leaq 0x68(%rsp), %rsi
callq 0x28dcc
jmp 0x28672
movq %rsi, %rcx
leaq 0x8(%rsp), %r12
subq %r13, %rcx
addq $-0x2, %rcx
movq %r12, %rdi
movq %rbp, %rsi
movq %r13, %rdx
callq 0x74d0
movq %r15, %rdi
movq %r12, %rsi
leaq 0x48(%rsp), %rdx
movq %r14, %rcx
callq 0x2802a
movq 0x88(%rsp), %r12
movq %r12, %rdi
movq %r15, %rsi
callq 0x2d7b0
movq %rax, %rdi
movq %r12, %rsi
callq 0x7090
incq 0x60(%r14)
movq %r15, %rdi
callq 0x27d28
movq 0x10(%rsp), %rax
addq %rax, %r13
addq $0x2, %r13
movq %rbp, %rdi
movl $0xa, %esi
movq %r13, %rdx
callq 0x75c0
cmpq $-0x1, %rax
je 0x285e2
movq %rbp, %rdi
movl $0xa, %esi
movq %r13, %rdx
callq 0x75c0
movq %rax, %r13
incq %r13
movl $0x3, %r12d
jmp 0x285e8
movl $0x2, %r12d
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x28604
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x74b0
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0x286a9
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x74b0
jmp 0x286a9
movq %r14, %rdi
leaq 0x68(%rsp), %rsi
callq 0x2906e
jmp 0x28672
movq %r14, %rdi
leaq 0x68(%rsp), %rsi
callq 0x291e6
jmp 0x28672
movq %r14, %rdi
leaq 0x68(%rsp), %rsi
callq 0x2935c
jmp 0x28672
movq %r14, %rdi
leaq 0x68(%rsp), %rsi
callq 0x296bc
jmp 0x28672
movq %r14, %rdi
leaq 0x68(%rsp), %rsi
callq 0x29914
movq %rbp, %rdi
movl $0xa, %esi
movq %r13, %rdx
callq 0x75c0
cmpq $-0x1, %rax
je 0x286a3
movq %rbp, %rdi
movl $0xa, %esi
movq %r13, %rdx
callq 0x75c0
movq %rax, %r13
incq %r13
xorl %r12d, %r12d
jmp 0x286a9
movl $0x2, %r12d
movq 0x68(%rsp), %rdi
leaq 0x78(%rsp), %rax
cmpq %rax, %rdi
je 0x286c5
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x74b0
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x286e1
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x74b0
testl %r12d, %r12d
je 0x286f7
cmpl $0x3, %r12d
leaq 0x28(%rsp), %r12
je 0x281d3
jmp 0x28701
leaq 0x28(%rsp), %r12
jmp 0x281d3
movq (%rbx), %r12
cmpq %rbx, %r12
je 0x2872a
leaq 0x14684(%rip), %r15     # 0x3cd94
leaq 0x10(%r12), %rdi
movq %r15, %rsi
callq 0x7180
testl %eax, %eax
je 0x2872a
movq (%r12), %r12
cmpq %rbx, %r12
jne 0x28710
cmpq %rbx, %r12
je 0x28775
leaq 0xe0(%rsp), %r13
movq %r13, -0x10(%r13)
leaq 0x14652(%rip), %rsi     # 0x3cd94
leaq 0x14651(%rip), %rdx     # 0x3cd9a
leaq 0xd0(%rsp), %rdi
callq 0x80f4
leaq 0xd0(%rsp), %rsi
movq (%rsp), %rdi
callq 0x2d6e8
cmpq 0x90(%rsp), %rax
sete %bpl
jmp 0x28777
xorl %ebp, %ebp
cmpq %rbx, %r12
movq (%rsp), %r15
je 0x287a1
leaq 0xe0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x287a1
movq 0xe0(%rsp), %rsi
incq %rsi
callq 0x74b0
testb %bpl, %bpl
jne 0x28911
movq %r14, %rdi
callq 0x29ae8
movq %r14, %rdi
movq 0xb0(%rsp), %rsi
callq 0x29e7e
movq %r14, %rdi
callq 0x2a136
movq %r14, %rdi
callq 0x2a3c8
movq %r14, %rdi
callq 0x2a75e
leaq 0x38(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x1459e(%rip), %rsi     # 0x3cd89
leaq 0x145a1(%rip), %rdx     # 0x3cd93
leaq 0x28(%rsp), %rdi
callq 0x80f4
leaq 0x28(%rsp), %rsi
movq %r15, %rdi
callq 0x2c26c
movq (%rax), %rdi
addq $0x10, %rdi
leaq 0x12584(%rip), %rsi     # 0x3ad9b
callq 0x7180
movl %eax, %ebp
movq 0x28(%rsp), %rdi
cmpq %r12, %rdi
je 0x28835
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x74b0
testl %ebp, %ebp
je 0x28841
movq %r14, %rdi
callq 0x2a8f2
addq $0x1e8, %rsp            # imm = 0x1E8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x10, %edi
callq 0x7260
movq %rax, %r12
leaq 0x13004(%rip), %rsi     # 0x3b86b
movq %rax, %rdi
callq 0x78c0
movq 0x25752(%rip), %rsi     # 0x4dfc8
movq 0x25733(%rip), %rdx     # 0x4dfb0
movq %r12, %rdi
callq 0x77d0
jmp 0x28977
movl $0x10, %edi
callq 0x7260
movq %rax, %r12
leaq 0x14452(%rip), %rsi     # 0x3ccf0
movq %rax, %rdi
callq 0x78c0
movq 0x2571b(%rip), %rsi     # 0x4dfc8
movq 0x256fc(%rip), %rdx     # 0x4dfb0
movq %r12, %rdi
callq 0x77d0
jmp 0x28977
movl $0x10, %edi
callq 0x7260
movq %rax, %r12
leaq 0x1443c(%rip), %rsi     # 0x3cd11
movq %rax, %rdi
callq 0x78c0
jmp 0x288fb
movl $0x10, %edi
callq 0x7260
movq %rax, %r12
leaq 0x14439(%rip), %rsi     # 0x3cd2c
movq %rax, %rdi
callq 0x78c0
movq 0x256c6(%rip), %rsi     # 0x4dfc8
movq 0x256a7(%rip), %rdx     # 0x4dfb0
movq %r12, %rdi
callq 0x77d0
movl $0x10, %edi
callq 0x7260
movq %rax, %r12
leaq 0x14476(%rip), %rsi     # 0x3cd9b
movq %rax, %rdi
callq 0x78c0
movq 0x25694(%rip), %rsi     # 0x4dfc8
movq 0x25675(%rip), %rdx     # 0x4dfb0
movq %r12, %rdi
callq 0x77d0
jmp 0x28977
movl $0x10, %edi
callq 0x7260
movq %rax, %r12
leaq 0x12f12(%rip), %rsi     # 0x3b86b
movq %rax, %rdi
callq 0x78c0
movq 0x25660(%rip), %rsi     # 0x4dfc8
movq 0x25641(%rip), %rdx     # 0x4dfb0
movq %r12, %rdi
callq 0x77d0
jmp 0x28a46
jmp 0x289c3
movq %rax, %r15
leaq 0xd0(%rsp), %rdi
callq 0x2c244
jmp 0x28993
movq %rax, %r15
leaq 0xb8(%rsp), %rdi
callq 0x96d8
jmp 0x28a26
jmp 0x28a23
jmp 0x28a46
jmp 0x28a87
movq %rax, %r15
movq %r12, %rdi
callq 0x7390
jmp 0x28ad2
jmp 0x289c3
movq %rax, %r15
movq %r12, %rdi
callq 0x7390
jmp 0x28a49
movq %rax, %r15
movq 0xd0(%rsp), %rdi
cmpq %r13, %rdi
je 0x28ad2
movq 0xe0(%rsp), %rsi
jmp 0x28ac3
jmp 0x28acf
movq %rax, %r15
movq 0x28(%rsp), %rdi
cmpq %r12, %rdi
jne 0x28abe
jmp 0x28ad2
jmp 0x28acf
movq %rax, %r15
leaq 0xd0(%rsp), %rdi
callq 0x27d28
jmp 0x28a26
movq %rax, %r15
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x28a49
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x74b0
jmp 0x28a49
jmp 0x28a46
movq %rax, %r15
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0x28a8a
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x74b0
jmp 0x28a8a
jmp 0x28a87
jmp 0x28aac
movq %rax, %r15
movq %r12, %rdi
callq 0x7390
jmp 0x28aaf
jmp 0x28a87
movq %rax, %r15
movq %r12, %rdi
callq 0x7390
jmp 0x28a8a
movq %rax, %r15
movq 0x68(%rsp), %rdi
leaq 0x78(%rsp), %rax
cmpq %rax, %rdi
je 0x28aaf
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x74b0
jmp 0x28aaf
jmp 0x28aac
jmp 0x28aac
movq %rax, %r15
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x28ad2
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x74b0
jmp 0x28ad2
jmp 0x28acf
movq %rax, %r15
leaq 0xc8(%r14), %r12
movq 0x98(%rsp), %rdi
callq 0x96d8
movq %r12, %rdi
callq 0x2c448
movq 0xa0(%rsp), %r13
movq (%r13), %rdi
cmpq %r13, %rdi
je 0x28b14
movq (%rdi), %r12
movl $0x18, %esi
callq 0x74b0
movq %r12, %rdi
cmpq %r13, %r12
jne 0x28aff
addq $0x68, %r14
movq 0xa8(%rsp), %rdi
callq 0x96d8
movq %r14, %rdi
callq 0x2c4da
movq 0x88(%rsp), %rdi
callq 0x2c552
movq (%rsp), %rdi
callq 0x2c58a
movq %rbx, %rdi
callq 0x96d8
movq %r15, %rdi
callq 0x7810
nop