// File: /workspace/github_cpp_makefile_star2_O1/llefranc[P]42_webserv/srcs/parser/FileParser.cpp
// Function: FileParser::newLocation(ServerInfo&)
void FileParser::newLocation(ServerInfo &srv)
{
	Location n_loc(srv.getPort());
	std::string uri;
	int brack = 0;

	bracketRegulator(brack, _buf);

	// Processing of the first line of location
	if (!_buf.compare(0, 9, "location ")){
		
		// **check validity of the line**	
		if (numberOfWords(_buf.c_str()) != 3)
			throw std::runtime_error(errParseMessage("error line : ", _buf.c_str(), "\n"));
		
		// **get the locaton name without whitespaces**
		(!_buf.compare(_buf.size() - 1, 1, "{")) ? _buf.erase(_buf.size() - 1, 1) : 0;
		uri = *wsTrim(_buf);
		uri.replace(0, 8, "");
	}
	
	// Processing of the location block
	while (brack > 0)
	{
		std::getline(_file, _buf);
		cleanLineFromSpaces(_buf);
		bracketRegulator(brack, _buf);

		if (!_buf.compare(0, 13, "allow_method "))
			n_loc.setLocation(METHO, 13, _buf);
		else if (!_buf.compare(0, 6, "index "))
			n_loc.setLocation(IDX, 6, _buf);
		else if (!_buf.compare(0, 12, "upload_path "))
			n_loc.setLocation(STORE, 12, _buf);
		else if (!_buf.compare(0, 5, "root "))
			n_loc.setLocation(ROOT, 5, _buf);
		else if (!_buf.compare(0, 4, "cgi "))
			n_loc.setLocation(CGI_EXE, 4, _buf);
		else if (!_buf.compare(0, 10, "autoindex "))
			n_loc.setLocation(AUTOIDX, 10, _buf);
		else if (!_buf.compare(0, 9, "redirect "))
			n_loc.setLocation(REDIRECT, 9, _buf);
		else if (!_buf.compare(0, 1, "}")) continue;
		else throw std::runtime_error(errParseMessage("error line : ", _buf.c_str(), ". Wrong input in block location\n"));
	}
	_bracket--;
	addNewLocationToMap(&n_loc, uri);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
movq %rdi, %rbx
movq %rsi, %rdi
callq 0x5bae
movl (%rax), %esi
leaq -0x138(%rbp), %rdi
callq 0x8870
leaq -0x40(%rbp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq -0x30(%rbp), %rdi
movl $0x0, (%rdi)
leaq 0x208(%rbx), %r14
movq %r14, %rsi
callq 0x9f09
leaq 0xdd81(%rip), %rcx      # 0x1520d
movl $0x9, %edx
movq %r14, %rdi
xorl %esi, %esi
callq 0x4510
testl %eax, %eax
jne 0x7550
movq (%r14), %rdi
callq 0x9ffe
cmpq $0x3, %rax
jne 0x77fa
movq 0x210(%rbx), %rsi
decq %rsi
leaq 0xdc66(%rip), %rcx      # 0x1512c
movl $0x1, %edx
movq %r14, %rdi
callq 0x4510
testl %eax, %eax
jne 0x783e
movq 0x210(%rbx), %rsi
decq %rsi
movl $0x1, %edx
movq %r14, %rdi
callq 0x40d0
leaq -0x60(%rbp), %r15
movq %r15, -0x10(%r15)
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
leaq -0x70(%rbp), %rdi
callq 0x67a2
movq -0x70(%rbp), %rdi
cmpq %r15, %rdi
je 0x7522
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x43e0
movq %r14, %rdi
callq 0xa0c9
leaq -0x50(%rbp), %rdi
movq %rax, %rsi
callq 0x4240
leaq 0xe1c4(%rip), %rcx      # 0x15701
leaq -0x50(%rbp), %rdi
movl $0x8, %edx
xorl %esi, %esi
xorl %r8d, %r8d
callq 0x4440
cmpl $0x0, -0x30(%rbp)
jle 0x777a
leaq -0x30(%rbp), %r15
leaq 0xdbfc(%rip), %r12      # 0x15161
leaq -0x2c(%rbp), %r13
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x43b0
movsbl %al, %edx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4740
movq %r14, %rdi
callq 0x9ea4
movq %r15, %rdi
movq %r14, %rsi
callq 0x9f09
movl $0xd, %edx
movq %r14, %rdi
xorl %esi, %esi
movq %r12, %rcx
callq 0x4510
testl %eax, %eax
je 0x768f
movl $0x6, %edx
movq %r14, %rdi
xorl %esi, %esi
leaq 0xdbc2(%rip), %rcx      # 0x1518b
callq 0x4510
testl %eax, %eax
je 0x76af
movl $0xc, %edx
movq %r14, %rdi
xorl %esi, %esi
leaq 0xdb88(%rip), %rcx      # 0x1516f
callq 0x4510
testl %eax, %eax
je 0x76d2
movl $0x5, %edx
movq %r14, %rdi
xorl %esi, %esi
leaq 0xdb77(%rip), %rcx      # 0x1517c
callq 0x4510
testl %eax, %eax
je 0x76f2
movl $0x4, %edx
movq %r14, %rdi
xorl %esi, %esi
leaq 0xdb5f(%rip), %rcx      # 0x15182
callq 0x4510
testl %eax, %eax
je 0x7712
movl $0xa, %edx
movq %r14, %rdi
xorl %esi, %esi
leaq 0xdb46(%rip), %rcx      # 0x15187
callq 0x4510
testl %eax, %eax
je 0x7732
movl $0x9, %edx
movq %r14, %rdi
xorl %esi, %esi
leaq 0xdb33(%rip), %rcx      # 0x15192
callq 0x4510
testl %eax, %eax
je 0x7752
movl $0x1, %edx
movq %r14, %rdi
xorl %esi, %esi
leaq 0xdab1(%rip), %rcx      # 0x1512e
callq 0x4510
testl %eax, %eax
je 0x7770
jmp 0x77ca
movl $0xd, -0x2c(%rbp)
leaq -0x138(%rbp), %rdi
xorl %esi, %esi
movq %r13, %rdx
movq %r14, %rcx
callq 0x8c76
jmp 0x7770
movl $0x6, -0x2c(%rbp)
leaq -0x138(%rbp), %rdi
movl $0x1, %esi
movq %r13, %rdx
movq %r14, %rcx
callq 0x8c76
jmp 0x7770
movl $0xc, -0x2c(%rbp)
leaq -0x138(%rbp), %rdi
movl $0x2, %esi
movq %r13, %rdx
movq %r14, %rcx
callq 0x8c76
jmp 0x7770
movl $0x5, -0x2c(%rbp)
leaq -0x138(%rbp), %rdi
movl $0x3, %esi
movq %r13, %rdx
movq %r14, %rcx
callq 0x8c76
jmp 0x7770
movl $0x4, -0x2c(%rbp)
leaq -0x138(%rbp), %rdi
movl $0x4, %esi
movq %r13, %rdx
movq %r14, %rcx
callq 0x8c76
jmp 0x7770
movl $0xa, -0x2c(%rbp)
leaq -0x138(%rbp), %rdi
movl $0x5, %esi
movq %r13, %rdx
movq %r14, %rcx
callq 0x8c76
jmp 0x7770
movl $0x9, -0x2c(%rbp)
leaq -0x138(%rbp), %rdi
movl $0x6, %esi
movq %r13, %rdx
movq %r14, %rcx
callq 0x8c76
cmpl $0x0, -0x30(%rbp)
jg 0x7569
decl 0x228(%rbx)
leaq -0x138(%rbp), %rsi
leaq -0x50(%rbp), %rdx
movq %rbx, %rdi
callq 0x78a4
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x77ac
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x43e0
leaq -0x138(%rbp), %rdi
callq 0x8b9e
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x10, %edi
callq 0x41f0
movq %rax, %r15
movq (%r14), %rsi
leaq 0xd94f(%rip), %rdi      # 0x15130
leaq 0xd9b4(%rip), %rdx      # 0x1519c
callq 0x9f70
movq %r15, %rdi
movq %rax, %rsi
callq 0x4620
jmp 0x7828
movl $0x10, %edi
callq 0x41f0
movq %rax, %r15
movq (%r14), %rsi
leaq 0xd91f(%rip), %rdi      # 0x15130
leaq 0xdba7(%rip), %rdx      # 0x153bf
callq 0x9f70
movq %r15, %rdi
movq %rax, %rsi
callq 0x4620
movq 0x157b9(%rip), %rsi     # 0x1cfe8
movq 0x15782(%rip), %rdx     # 0x1cfb8
movq %r15, %rdi
callq 0x46a0
leaq -0x60(%rbp), %rax
movq %rax, -0x10(%rax)
leaq 0xd80c(%rip), %rdi      # 0x15059
callq 0x42c0
jmp 0x7858
jmp 0x7873
jmp 0x7873
movq %rax, %rbx
movq %r15, %rdi
callq 0x42e0
jmp 0x7876
jmp 0x7873
jmp 0x7873
jmp 0x7873
jmp 0x7873
jmp 0x7873
jmp 0x7873
jmp 0x7873
movq %rax, %rbx
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x788f
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x43e0
leaq -0x138(%rbp), %rdi
callq 0x8b9e
movq %rbx, %rdi
callq 0x46d0
nop