// File: /workspace/github_cpp_makefile_star2_O3/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 0x5bb6
movl (%rax), %esi
leaq -0x138(%rbp), %rdi
callq 0x88a0
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 0x9f80
leaq 0xdd3d(%rip), %rcx      # 0x1520d
movl $0x9, %edx
movq %r14, %rdi
xorl %esi, %esi
callq 0x4510
testl %eax, %eax
jne 0x7594
movq (%r14), %rdi
callq 0xa075
cmpq $0x3, %rax
jne 0x783e
movq 0x210(%rbx), %rsi
decq %rsi
leaq 0xdc22(%rip), %rcx      # 0x1512c
movl $0x1, %edx
movq %r14, %rdi
callq 0x4510
testl %eax, %eax
jne 0x7882
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 0x67e2
movq -0x70(%rbp), %rdi
cmpq %r15, %rdi
je 0x7566
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x43e0
movq %r14, %rdi
callq 0xa150
leaq -0x50(%rbp), %rdi
movq %rax, %rsi
callq 0x4240
leaq 0xe180(%rip), %rcx      # 0x15701
leaq -0x50(%rbp), %rdi
movl $0x8, %edx
xorl %esi, %esi
xorl %r8d, %r8d
callq 0x4440
cmpl $0x0, -0x30(%rbp)
jle 0x77be
leaq -0x30(%rbp), %r15
leaq 0xdbb8(%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 0x9f0c
movq %r15, %rdi
movq %r14, %rsi
callq 0x9f80
movl $0xd, %edx
movq %r14, %rdi
xorl %esi, %esi
movq %r12, %rcx
callq 0x4510
testl %eax, %eax
je 0x76d3
movl $0x6, %edx
movq %r14, %rdi
xorl %esi, %esi
leaq 0xdb7e(%rip), %rcx      # 0x1518b
callq 0x4510
testl %eax, %eax
je 0x76f3
movl $0xc, %edx
movq %r14, %rdi
xorl %esi, %esi
leaq 0xdb44(%rip), %rcx      # 0x1516f
callq 0x4510
testl %eax, %eax
je 0x7716
movl $0x5, %edx
movq %r14, %rdi
xorl %esi, %esi
leaq 0xdb33(%rip), %rcx      # 0x1517c
callq 0x4510
testl %eax, %eax
je 0x7736
movl $0x4, %edx
movq %r14, %rdi
xorl %esi, %esi
leaq 0xdb1b(%rip), %rcx      # 0x15182
callq 0x4510
testl %eax, %eax
je 0x7756
movl $0xa, %edx
movq %r14, %rdi
xorl %esi, %esi
leaq 0xdb02(%rip), %rcx      # 0x15187
callq 0x4510
testl %eax, %eax
je 0x7776
movl $0x9, %edx
movq %r14, %rdi
xorl %esi, %esi
leaq 0xdaef(%rip), %rcx      # 0x15192
callq 0x4510
testl %eax, %eax
je 0x7796
movl $0x1, %edx
movq %r14, %rdi
xorl %esi, %esi
leaq 0xda6d(%rip), %rcx      # 0x1512e
callq 0x4510
testl %eax, %eax
je 0x77b4
jmp 0x780e
movl $0xd, -0x2c(%rbp)
leaq -0x138(%rbp), %rdi
xorl %esi, %esi
movq %r13, %rdx
movq %r14, %rcx
callq 0x8ca6
jmp 0x77b4
movl $0x6, -0x2c(%rbp)
leaq -0x138(%rbp), %rdi
movl $0x1, %esi
movq %r13, %rdx
movq %r14, %rcx
callq 0x8ca6
jmp 0x77b4
movl $0xc, -0x2c(%rbp)
leaq -0x138(%rbp), %rdi
movl $0x2, %esi
movq %r13, %rdx
movq %r14, %rcx
callq 0x8ca6
jmp 0x77b4
movl $0x5, -0x2c(%rbp)
leaq -0x138(%rbp), %rdi
movl $0x3, %esi
movq %r13, %rdx
movq %r14, %rcx
callq 0x8ca6
jmp 0x77b4
movl $0x4, -0x2c(%rbp)
leaq -0x138(%rbp), %rdi
movl $0x4, %esi
movq %r13, %rdx
movq %r14, %rcx
callq 0x8ca6
jmp 0x77b4
movl $0xa, -0x2c(%rbp)
leaq -0x138(%rbp), %rdi
movl $0x5, %esi
movq %r13, %rdx
movq %r14, %rcx
callq 0x8ca6
jmp 0x77b4
movl $0x9, -0x2c(%rbp)
leaq -0x138(%rbp), %rdi
movl $0x6, %esi
movq %r13, %rdx
movq %r14, %rcx
callq 0x8ca6
cmpl $0x0, -0x30(%rbp)
jg 0x75ad
decl 0x228(%rbx)
leaq -0x138(%rbp), %rsi
leaq -0x50(%rbp), %rdx
movq %rbx, %rdi
callq 0x78e8
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x77f0
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x43e0
leaq -0x138(%rbp), %rdi
callq 0x8bce
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 0xd90b(%rip), %rdi      # 0x15130
leaq 0xd970(%rip), %rdx      # 0x1519c
callq 0x9fe7
movq %r15, %rdi
movq %rax, %rsi
callq 0x4620
jmp 0x786c
movl $0x10, %edi
callq 0x41f0
movq %rax, %r15
movq (%r14), %rsi
leaq 0xd8db(%rip), %rdi      # 0x15130
leaq 0xdb63(%rip), %rdx      # 0x153bf
callq 0x9fe7
movq %r15, %rdi
movq %rax, %rsi
callq 0x4620
movq 0x15775(%rip), %rsi     # 0x1cfe8
movq 0x1573e(%rip), %rdx     # 0x1cfb8
movq %r15, %rdi
callq 0x46a0
leaq -0x60(%rbp), %rax
movq %rax, -0x10(%rax)
leaq 0xd7c8(%rip), %rdi      # 0x15059
callq 0x42c0
jmp 0x789c
jmp 0x78b7
jmp 0x78b7
movq %rax, %rbx
movq %r15, %rdi
callq 0x42e0
jmp 0x78ba
jmp 0x78b7
jmp 0x78b7
jmp 0x78b7
jmp 0x78b7
jmp 0x78b7
jmp 0x78b7
jmp 0x78b7
movq %rax, %rbx
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x78d3
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x43e0
leaq -0x138(%rbp), %rdi
callq 0x8bce
movq %rbx, %rdi
callq 0x46d0
nop