// File: /workspace/github_cpp_makefile_star2_O1/mbourand[P]webserv/srcs/Methods/DeleteMethod.cpp
// Function: DeleteMethod::process(Request const&, ConfigContext const&, ServerSocket const&)
Response DeleteMethod::process(const Request& request, const ConfigContext& config, const ServerSocket&)
{
	URL url(request._url._path);
	int base_depth = 0;
	std::string realPath = config.rootPath(url._path, base_depth);
	try
	{
		realPath = ft::simplify_path(realPath, true, base_depth);
	}
	catch (std::exception& e)
	{
		return Response(404, url._path);
	}
	Response response(200, url._path);
	try
	{
		std::string file_path = realPath;
		struct stat	file_stats;
		if (lstat(file_path.c_str(), &file_stats) == 0 && S_ISREG(file_stats.st_mode))
		{
			if (unlink(file_path.c_str()) == 0)
				response.setCode(204);
			else
				response.setCode(202);
		}
		else
			response.setCode(404);
	}
	catch (std::exception& e)
	{
		response.setCode(500);
	}
	return (response);
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x1c8, %rsp            # imm = 0x1C8
movq %rcx, %r14
movq %rdi, %rbx
leaq 0xb8(%rdx), %rsi
leaq 0xd8(%rsp), %rdi
callq 0x1b1b6
leaq 0x4(%rsp), %rcx
movl $0x0, (%rcx)
leaq 0x160(%rsp), %r15
leaq 0x8(%rsp), %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x2bd04
movl 0x4(%rsp), %ecx
leaq 0x48(%rsp), %rdi
leaq 0x8(%rsp), %rsi
movl $0x1, %edx
callq 0x1d582
leaq 0x8(%rsp), %rdi
leaq 0x48(%rsp), %r14
movq %r14, %rsi
callq 0x7590
movq (%r14), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0xa03f
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x74b0
movq %rbx, %rdi
movl $0xc8, %esi
movq %r15, %rdx
callq 0x37384
leaq 0x38(%rsp), %r12
movq %r12, -0x10(%r12)
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
addq %rsi, %rdx
leaq 0x28(%rsp), %rdi
callq 0x8a8a
movq 0x28(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0x78e0
movl $0x194, %esi            # imm = 0x194
testl %eax, %eax
jne 0xa0b0
movl $0xf000, %eax           # imm = 0xF000
andl 0x60(%rsp), %eax
cmpl $0x8000, %eax           # imm = 0x8000
jne 0xa0b0
movq 0x28(%rsp), %rdi
callq 0x7240
xorl %ecx, %ecx
testl %eax, %eax
sete %cl
leal 0xca(,%rcx,2), %esi
movq %rbx, %rdi
callq 0x37f1c
movq 0x28(%rsp), %rdi
cmpq %r12, %rdi
je 0xa0cf
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x74b0
leaq 0x18(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xa0ea
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x74b0
leaq 0xd8(%rsp), %rdi
callq 0x1bb28
movq %rbx, %rax
addq $0x1c8, %rsp            # imm = 0x1C8
popq %rbx
popq %r12
popq %r14
popq %r15
retq
movq %rdx, %r15
movq %rax, %r14
movq 0x28(%rsp), %rdi
cmpq %r12, %rdi
je 0xa12e
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x74b0
jmp 0xa12e
movq %rdx, %r15
movq %rax, %r14
cmpl $0x1, %r15d
jne 0xa160
movq %r14, %rdi
callq 0x7210
movq %rbx, %rdi
movl $0x1f4, %esi            # imm = 0x1F4
callq 0x37f1c
callq 0x7780
jmp 0xa0cf
movq %rax, %r14
jmp 0xa160
movq %rax, %r14
callq 0x7780
movq %rbx, %rdi
callq 0x371c6
jmp 0xa16d
movq %rax, %r14
leaq 0x18(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xa1cb
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x74b0
jmp 0xa1cb
movq %rax, %r14
cmpl $0x1, %edx
jne 0xa16d
movq %r14, %rdi
callq 0x7210
movq %rbx, %rdi
movl $0x194, %esi            # imm = 0x194
movq %r15, %rdx
callq 0x37384
callq 0x7780
jmp 0xa0cf
jmp 0xa16a
movq %rax, %r14
callq 0x7780
jmp 0xa16d
movq %rax, %rdi
callq 0x96cc
movq %rax, %r14
leaq 0xd8(%rsp), %rdi
callq 0x1bb28
movq %r14, %rdi
callq 0x7810