// File: 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
subq $0x1e0, %rsp            # imm = 0x1E0
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x158(%rbp)
movq -0x10(%rbp), %rdi
callq 0x8d70
movl (%rax), %esi
leaq -0xd8(%rbp), %rdi
callq 0xf4b0
leaq -0xf8(%rbp), %rdi
callq 0x5770
movq -0x158(%rbp), %rsi
movl $0x0, -0xfc(%rbp)
addq $0x208, %rsi            # imm = 0x208
leaq -0xfc(%rbp), %rdi
callq 0x121d0
jmp 0xbc97
movq -0x158(%rbp), %rdi
addq $0x208, %rdi            # imm = 0x208
leaq 0x17545(%rip), %rcx     # 0x231f1
xorl %eax, %eax
movl %eax, %esi
movl $0x9, %edx
callq 0x5710
movl %eax, -0x15c(%rbp)
jmp 0xbcc2
movl -0x15c(%rbp), %eax
cmpl $0x0, %eax
jne 0xbf84
movq -0x158(%rbp), %rdi
addq $0x208, %rdi            # imm = 0x208
callq 0x5240
movq %rax, %rdi
callq 0x12310
movq %rax, -0x168(%rbp)
jmp 0xbcf5
movq -0x168(%rbp), %rax
cmpq $0x3, %rax
je 0xbdb7
movl $0x10, %edi
callq 0x5290
movq -0x158(%rbp), %rdi
movq %rax, -0x178(%rbp)
addq $0x208, %rdi            # imm = 0x208
callq 0x5240
movq %rax, %rsi
leaq 0x173e0(%rip), %rdi     # 0x23114
leaq 0x1768f(%rip), %rdx     # 0x233ca
callq 0x12260
movq %rax, -0x170(%rbp)
jmp 0xbd49
movq -0x170(%rbp), %rsi
movq -0x178(%rbp), %rdi
callq 0x5830
jmp 0xbd5e
movq -0x178(%rbp), %rdi
movq 0x25284(%rip), %rsi     # 0x30ff0
movq 0x25255(%rip), %rdx     # 0x30fc8
callq 0x58a0
jmp 0xc426
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x108(%rbp)
movl %eax, -0x10c(%rbp)
jmp 0xc402
movq -0x178(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x108(%rbp)
movl %eax, -0x10c(%rbp)
callq 0x53f0
jmp 0xc402
movq -0x158(%rbp), %rdi
addq $0x208, %rdi            # imm = 0x208
movq %rdi, -0x188(%rbp)
callq 0x53b0
movq -0x188(%rbp), %rdi
movq %rax, %rsi
decq %rsi
movb $0x0, -0x131(%rbp)
movb $0x0, -0x133(%rbp)
movb $0x0, -0x134(%rbp)
leaq 0x17316(%rip), %rcx     # 0x23110
movl $0x1, %edx
callq 0x5710
movl %eax, -0x17c(%rbp)
jmp 0xbe0c
movl -0x17c(%rbp), %eax
cmpl $0x0, %eax
jne 0xbe6f
movq -0x158(%rbp), %rdi
addq $0x208, %rdi            # imm = 0x208
movq %rdi, -0x198(%rbp)
callq 0x53b0
movq -0x198(%rbp), %rdi
movq %rax, %rsi
decq %rsi
movl $0x1, %edx
callq 0x5130
movq %rax, -0x190(%rbp)
jmp 0xbe51
movq -0x190(%rbp), %rsi
leaq -0x130(%rbp), %rdi
callq 0x5250
jmp 0xbe66
movb $0x1, -0x131(%rbp)
jmp 0xbea9
leaq -0x132(%rbp), %rdi
movq %rdi, -0x1a0(%rbp)
callq 0x58f0
movq -0x1a0(%rbp), %rdx
movb $0x1, -0x133(%rbp)
xorl %eax, %eax
movl %eax, %esi
leaq -0x130(%rbp), %rdi
callq 0x63e0
jmp 0xbea2
movb $0x1, -0x134(%rbp)
testb $0x1, -0x134(%rbp)
jne 0xbeb4
jmp 0xbec0
leaq -0x130(%rbp), %rdi
callq 0x5a08
testb $0x1, -0x133(%rbp)
jne 0xbecb
jmp 0xbed7
leaq -0x132(%rbp), %rdi
callq 0x55c0
testb $0x1, -0x131(%rbp)
jne 0xbee2
jmp 0xbeee
leaq -0x130(%rbp), %rdi
callq 0x5a08
movq -0x158(%rbp), %rdi
addq $0x208, %rdi            # imm = 0x208
callq 0x123e0
movq %rax, -0x1a8(%rbp)
jmp 0xbf0a
movq -0x1a8(%rbp), %rsi
leaq -0xf8(%rbp), %rdi
callq 0x5060
jmp 0xbf1f
leaq 0x177e6(%rip), %rcx     # 0x2370c
xorl %eax, %eax
movl %eax, %esi
leaq -0xf8(%rbp), %rdi
movl $0x8, %edx
callq 0x5340
jmp 0xbf3d
jmp 0xbf84
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x108(%rbp)
movl %eax, -0x10c(%rbp)
testb $0x1, -0x133(%rbp)
jne 0xbf5c
jmp 0xbf68
leaq -0x132(%rbp), %rdi
callq 0x55c0
testb $0x1, -0x131(%rbp)
jne 0xbf73
jmp 0xbf7f
leaq -0x130(%rbp), %rdi
callq 0x5a08
jmp 0xc402
jmp 0xbf86
cmpl $0x0, -0xfc(%rbp)
jle 0xc3b7
movq -0x158(%rbp), %rdi
movq %rdi, %rsi
addq $0x208, %rsi            # imm = 0x208
callq 0x50f0
jmp 0xbfab
movq -0x158(%rbp), %rdi
addq $0x208, %rdi            # imm = 0x208
callq 0x12130
jmp 0xbfc0
movq -0x158(%rbp), %rsi
addq $0x208, %rsi            # imm = 0x208
leaq -0xfc(%rbp), %rdi
callq 0x121d0
jmp 0xbfdc
movq -0x158(%rbp), %rdi
addq $0x208, %rdi            # imm = 0x208
leaq 0x17154(%rip), %rcx     # 0x23145
xorl %eax, %eax
movl %eax, %esi
movl $0xd, %edx
callq 0x5710
movl %eax, -0x1ac(%rbp)
jmp 0xc007
movl -0x1ac(%rbp), %eax
cmpl $0x0, %eax
jne 0xc046
movq -0x158(%rbp), %rcx
movl $0xd, -0x138(%rbp)
addq $0x208, %rcx            # imm = 0x208
leaq -0xd8(%rbp), %rdi
xorl %esi, %esi
leaq -0x138(%rbp), %rdx
callq 0xf970
jmp 0xc041
jmp 0xc3b2
movq -0x158(%rbp), %rdi
addq $0x208, %rdi            # imm = 0x208
leaq 0x17114(%rip), %rcx     # 0x2316f
xorl %eax, %eax
movl %eax, %esi
movl $0x6, %edx
callq 0x5710
movl %eax, -0x1b0(%rbp)
jmp 0xc071
movl -0x1b0(%rbp), %eax
cmpl $0x0, %eax
jne 0xc0b3
movq -0x158(%rbp), %rcx
movl $0x6, -0x13c(%rbp)
addq $0x208, %rcx            # imm = 0x208
leaq -0xd8(%rbp), %rdi
movl $0x1, %esi
leaq -0x13c(%rbp), %rdx
callq 0xf970
jmp 0xc0ae
jmp 0xc3b0
movq -0x158(%rbp), %rdi
addq $0x208, %rdi            # imm = 0x208
leaq 0x1708b(%rip), %rcx     # 0x23153
xorl %eax, %eax
movl %eax, %esi
movl $0xc, %edx
callq 0x5710
movl %eax, -0x1b4(%rbp)
jmp 0xc0de
movl -0x1b4(%rbp), %eax
cmpl $0x0, %eax
jne 0xc120
movq -0x158(%rbp), %rcx
movl $0xc, -0x140(%rbp)
addq $0x208, %rcx            # imm = 0x208
leaq -0xd8(%rbp), %rdi
movl $0x2, %esi
leaq -0x140(%rbp), %rdx
callq 0xf970
jmp 0xc11b
jmp 0xc3ae
movq -0x158(%rbp), %rdi
addq $0x208, %rdi            # imm = 0x208
leaq 0x1702b(%rip), %rcx     # 0x23160
xorl %eax, %eax
movl %eax, %esi
movl $0x5, %edx
callq 0x5710
movl %eax, -0x1b8(%rbp)
jmp 0xc14b
movl -0x1b8(%rbp), %eax
cmpl $0x0, %eax
jne 0xc18d
movq -0x158(%rbp), %rcx
movl $0x5, -0x144(%rbp)
addq $0x208, %rcx            # imm = 0x208
leaq -0xd8(%rbp), %rdi
movl $0x3, %esi
leaq -0x144(%rbp), %rdx
callq 0xf970
jmp 0xc188
jmp 0xc3ac
movq -0x158(%rbp), %rdi
addq $0x208, %rdi            # imm = 0x208
leaq 0x16fc4(%rip), %rcx     # 0x23166
xorl %eax, %eax
movl %eax, %esi
movl $0x4, %edx
callq 0x5710
movl %eax, -0x1bc(%rbp)
jmp 0xc1b8
movl -0x1bc(%rbp), %eax
cmpl $0x0, %eax
jne 0xc1fa
movq -0x158(%rbp), %rcx
movl $0x4, -0x148(%rbp)
addq $0x208, %rcx            # imm = 0x208
leaq -0xd8(%rbp), %rdi
movl $0x4, %esi
leaq -0x148(%rbp), %rdx
callq 0xf970
jmp 0xc1f5
jmp 0xc3aa
movq -0x158(%rbp), %rdi
addq $0x208, %rdi            # imm = 0x208
leaq 0x16f5c(%rip), %rcx     # 0x2316b
xorl %eax, %eax
movl %eax, %esi
movl $0xa, %edx
callq 0x5710
movl %eax, -0x1c0(%rbp)
jmp 0xc225
movl -0x1c0(%rbp), %eax
cmpl $0x0, %eax
jne 0xc267
movq -0x158(%rbp), %rcx
movl $0xa, -0x14c(%rbp)
addq $0x208, %rcx            # imm = 0x208
leaq -0xd8(%rbp), %rdi
movl $0x5, %esi
leaq -0x14c(%rbp), %rdx
callq 0xf970
jmp 0xc262
jmp 0xc3a8
movq -0x158(%rbp), %rdi
addq $0x208, %rdi            # imm = 0x208
leaq 0x16efa(%rip), %rcx     # 0x23176
xorl %eax, %eax
movl %eax, %esi
movl $0x9, %edx
callq 0x5710
movl %eax, -0x1c4(%rbp)
jmp 0xc292
movl -0x1c4(%rbp), %eax
cmpl $0x0, %eax
jne 0xc2d4
movq -0x158(%rbp), %rcx
movl $0x9, -0x150(%rbp)
addq $0x208, %rcx            # imm = 0x208
leaq -0xd8(%rbp), %rdi
movl $0x6, %esi
leaq -0x150(%rbp), %rdx
callq 0xf970
jmp 0xc2cf
jmp 0xc3a6
movq -0x158(%rbp), %rdi
addq $0x208, %rdi            # imm = 0x208
leaq 0x16e29(%rip), %rcx     # 0x23112
xorl %eax, %eax
movl %eax, %esi
movl $0x1, %edx
callq 0x5710
movl %eax, -0x1c8(%rbp)
jmp 0xc2ff
movl -0x1c8(%rbp), %eax
cmpl $0x0, %eax
jne 0xc30f
jmp 0xbf86
movl $0x10, %edi
callq 0x5290
movq -0x158(%rbp), %rdi
movq %rax, -0x1d8(%rbp)
addq $0x208, %rdi            # imm = 0x208
callq 0x5240
movq %rax, %rsi
leaq 0x16dd7(%rip), %rdi     # 0x23114
leaq 0x16e3c(%rip), %rdx     # 0x23180
callq 0x12260
movq %rax, -0x1d0(%rbp)
jmp 0xc352
movq -0x1d0(%rbp), %rsi
movq -0x1d8(%rbp), %rdi
callq 0x5830
jmp 0xc367
movq -0x1d8(%rbp), %rdi
movq 0x24c7b(%rip), %rsi     # 0x30ff0
movq 0x24c4c(%rip), %rdx     # 0x30fc8
callq 0x58a0
jmp 0xc426
movq -0x1d8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x108(%rbp)
movl %eax, -0x10c(%rbp)
callq 0x53f0
jmp 0xc402
jmp 0xc3a8
jmp 0xc3aa
jmp 0xc3ac
jmp 0xc3ae
jmp 0xc3b0
jmp 0xc3b2
jmp 0xbf86
movq -0x158(%rbp), %rdi
movl 0x228(%rdi), %eax
decl %eax
movl %eax, 0x228(%rdi)
leaq -0xd8(%rbp), %rsi
leaq -0xf8(%rbp), %rdx
callq 0xc430
jmp 0xc3e1
leaq -0xf8(%rbp), %rdi
callq 0x5a08
leaq -0xd8(%rbp), %rdi
callq 0xf810
addq $0x1e0, %rsp            # imm = 0x1E0
popq %rbp
retq
leaq -0xf8(%rbp), %rdi
callq 0x5a08
leaq -0xd8(%rbp), %rdi
callq 0xf810
movq -0x108(%rbp), %rdi
callq 0x58e0
nopw %cs:(%rax,%rax)