// File: 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 %rbp
movq %rsp, %rbp
subq $0x250, %rsp            # imm = 0x250
movq %rdi, -0x248(%rbp)
movq %rdi, %rax
movq %rax, -0x240(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq -0x18(%rbp), %rsi
addq $0xb8, %rsi
leaq -0x118(%rbp), %rdi
callq 0x2e3a0
movl $0x0, -0x11c(%rbp)
movq -0x20(%rbp), %rsi
leaq -0x90(%rbp), %rdx
leaq -0x140(%rbp), %rdi
leaq -0x11c(%rbp), %rcx
callq 0x4cd00
jmp 0xefb1
movl -0x11c(%rbp), %ecx
leaq -0x170(%rbp), %rdi
leaq -0x140(%rbp), %rsi
movl $0x1, %edx
callq 0x32290
jmp 0xefd1
leaq -0x140(%rbp), %rdi
leaq -0x170(%rbp), %rsi
callq 0x97e0
leaq -0x170(%rbp), %rdi
callq 0x9c98
jmp 0xf0a9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x148(%rbp)
movl %eax, -0x14c(%rbp)
jmp 0xf297
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x148(%rbp)
movl %eax, -0x14c(%rbp)
movl -0x14c(%rbp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0xf28b
movq -0x148(%rbp), %rdi
callq 0x92a0
movq -0x248(%rbp), %rdi
movq %rax, -0x178(%rbp)
leaq -0x90(%rbp), %rdx
movl $0x194, %esi            # imm = 0x194
callq 0x636c0
jmp 0xf05e
movl $0x1, -0x17c(%rbp)
callq 0x9a40
jmp 0xf088
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x148(%rbp)
movl %eax, -0x14c(%rbp)
callq 0x9a40
jmp 0xf0a4
jmp 0xf263
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x148(%rbp)
movl %eax, -0x14c(%rbp)
jmp 0xf28b
jmp 0xf28b
movq -0x248(%rbp), %rdi
movb $0x0, -0x17d(%rbp)
leaq -0x90(%rbp), %rdx
movl $0xc8, %esi
callq 0x636c0
jmp 0xf0ca
leaq -0x1a0(%rbp), %rdi
leaq -0x140(%rbp), %rsi
callq 0x92c0
jmp 0xf0df
leaq -0x1a0(%rbp), %rdi
callq 0x92b0
movq %rax, %rdi
leaq -0x230(%rbp), %rsi
callq 0x9c10
cmpl $0x0, %eax
jne 0xf1f5
movl -0x218(%rbp), %eax
andl $0xf000, %eax           # imm = 0xF000
cmpl $0x8000, %eax           # imm = 0x8000
jne 0xf1f5
leaq -0x1a0(%rbp), %rdi
callq 0x92b0
movq %rax, %rdi
callq 0x9330
cmpl $0x0, %eax
jne 0xf1de
movq -0x248(%rbp), %rdi
movl $0xcc, %esi
callq 0x64560
jmp 0xf149
jmp 0xf1f3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x148(%rbp)
movl %eax, -0x14c(%rbp)
jmp 0xf180
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x148(%rbp)
movl %eax, -0x14c(%rbp)
leaq -0x1a0(%rbp), %rdi
callq 0x9c98
movl -0x14c(%rbp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0xf255
movq -0x148(%rbp), %rdi
callq 0x92a0
movq -0x248(%rbp), %rdi
movq %rax, -0x238(%rbp)
movl $0x1f4, %esi            # imm = 0x1F4
callq 0x64560
jmp 0xf1b9
callq 0x9a40
jmp 0xf1c0
jmp 0xf1c2
movb $0x1, -0x17d(%rbp)
movl $0x1, -0x17c(%rbp)
testb $0x1, -0x17d(%rbp)
jne 0xf253
jmp 0xf247
movq -0x248(%rbp), %rdi
movl $0xca, %esi
callq 0x64560
jmp 0xf1f1
jmp 0xf1f3
jmp 0xf20a
movq -0x248(%rbp), %rdi
movl $0x194, %esi            # imm = 0x194
callq 0x64560
jmp 0xf208
jmp 0xf20a
leaq -0x1a0(%rbp), %rdi
callq 0x9c98
jmp 0xf1c2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x148(%rbp)
movl %eax, -0x14c(%rbp)
callq 0x9a40
jmp 0xf245
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x148(%rbp)
movl %eax, -0x14c(%rbp)
jmp 0xf255
jmp 0xf255
movq -0x248(%rbp), %rdi
callq 0x634e0
jmp 0xf263
movq -0x248(%rbp), %rdi
callq 0x634e0
jmp 0xf28b
leaq -0x140(%rbp), %rdi
callq 0x9c98
leaq -0x118(%rbp), %rdi
callq 0x2efd0
movq -0x240(%rbp), %rax
addq $0x250, %rsp            # imm = 0x250
popq %rbp
retq
leaq -0x140(%rbp), %rdi
callq 0x9c98
leaq -0x118(%rbp), %rdi
callq 0x2efd0
movq -0x148(%rbp), %rdi
callq 0x9af0
movq %rax, %rdi
callq 0xaa90
nopw (%rax,%rax)