// File: /workspace/github_cpp_makefile_star2_O3/guoxuanhan[P]NetServer/httpsession.cpp
// Function: HttpSession::PraseHttpRequest(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&, _HttpRequestContext&)
bool HttpSession::PraseHttpRequest(std::string &msg, HttpRequestContext &httprequestcontext)
{
    //std::cout << "HttpServer::HttpParser" << std::endl;
    std::string crlf("\r\n"), crlfcrlf("\r\n\r\n");
    size_t prev = 0, next = 0, pos_colon;
    std::string key, value;

    bool praseresult = false;
    //以下解析可以改成状态机，解决一次收Http报文不完整问题
    //prase http request line
    if ((next = msg.find(crlf, prev)) != std::string::npos)
    {
        std::string first_line(msg.substr(prev, next - prev));
        prev = next;
        std::stringstream sstream(first_line);
        sstream >> (httprequestcontext.method);
        sstream >> (httprequestcontext.url);
        sstream >> (httprequestcontext.version);
    }
    else
    {
        std::cout << "msg" << msg << std::endl;
        std::cout << "Error in httpPraser: http_request_line isn't complete!" << std::endl;
        praseresult = false;
        msg.clear();
        return praseresult;
        //可以临时存起来，凑齐了再解析
    }
    //prase http request header
    size_t pos_crlfcrlf = 0;
    if (( pos_crlfcrlf = msg.find(crlfcrlf, prev)) != std::string::npos)
    {
        while (prev != pos_crlfcrlf)
        {
            next = msg.find(crlf, prev + 2);
            pos_colon = msg.find(":", prev + 2);
            key = msg.substr(prev + 2, pos_colon - prev-2);
            value = msg.substr(pos_colon + 2, next-pos_colon-2);
            prev = next;
            httprequestcontext.header.insert(std::pair<std::string, std::string>(key, value));
        }
    }
    else
    {
        std::cout << "Error in httpPraser: http_request_header isn't complete!" << std::endl;
        praseresult = false;
        msg.clear();
        return praseresult;
    }
    //prase http request body
    httprequestcontext.body = msg.substr(pos_crlfcrlf + 4);
    praseresult = true;
    msg.clear();
    return praseresult;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x248, %rsp            # imm = 0x248
movq %rdx, %rbp
movq %rsi, %rbx
leaq 0x20(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x7e1d(%rip), %rsi      # 0x10a4c
leaq 0x7e18(%rip), %rdx      # 0x10a4e
leaq 0x10(%rsp), %rdi
callq 0x6112
leaq 0x50(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x7df9(%rip), %rsi      # 0x10a4a
leaq 0x7df6(%rip), %rdx      # 0x10a4e
leaq 0x40(%rsp), %rdi
callq 0x6112
leaq 0x70(%rsp), %rcx
movq %rcx, -0x10(%rcx)
xorl %eax, %eax
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
leaq 0x90(%rsp), %rcx
movq %rcx, -0x10(%rcx)
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rcx
movq %rbx, %rdi
xorl %edx, %edx
callq 0x4590
cmpq $-0x1, %rax
movq %rbx, (%rsp)
je 0x8f0a
leaq 0xa0(%rsp), %rdi
movq %rbx, %rsi
xorl %edx, %edx
movq %rax, %rbx
movq %rax, %rcx
callq 0x4360
leaq 0xc0(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
movl $0x18, %edx
callq 0x4500
leaq 0xc0(%rsp), %rdi
movq %rbp, %rsi
callq 0x4420
leaq 0x20(%rbp), %rsi
leaq 0xc0(%rsp), %rdi
callq 0x4420
leaq 0x40(%rbp), %rsi
leaq 0xc0(%rsp), %rdi
callq 0x4420
movq 0xf286(%rip), %rsi      # 0x17f98
leaq 0xc0(%rsp), %rdi
callq 0x4290
leaq 0x140(%rsp), %rdi
callq 0x4110
leaq 0xb0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x8d42
callq 0x4310
movq 0x40(%rsp), %rsi
movq 0x48(%rsp), %rcx
movq (%rsp), %rdi
movq %rbx, %rdx
callq 0x4590
cmpq $-0x1, %rax
je 0x8fab
movq %rax, %r14
movq %rbp, 0x8(%rsp)
cmpq %rax, %rbx
je 0x8ea8
leaq 0xd0(%rsp), %r15
movq 0x8(%rsp), %rax
addq $0x60, %rax
movq %rax, 0x30(%rsp)
movq %r14, 0x38(%rsp)
movq (%rsp), %rbp
movq %r15, %r14
leaq 0x2(%rbx), %r15
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rcx
movq %rbp, %rdi
movq %r15, %rdx
callq 0x4590
movq %rax, %r12
movl $0x1, %ecx
movq %rbp, %rdi
leaq 0x8616(%rip), %rsi      # 0x113d6
movq %r15, %rdx
callq 0x4590
movq %rax, %r13
movq %rax, %rcx
subq %rbx, %rcx
leaq 0xc0(%rsp), %rbx
addq $-0x2, %rcx
movq %rbx, %rdi
movq %rbp, %rsi
movq %r15, %rdx
callq 0x4360
leaq 0x60(%rsp), %rdi
movq %rbx, %rsi
callq 0x4400
movq 0xc0(%rsp), %rdi
movq %r14, %r15
cmpq %r14, %rdi
je 0x8e0d
callq 0x4310
movq %r12, %rcx
subq %r13, %rcx
addq $0x2, %r13
addq $-0x2, %rcx
movq %rbx, %rdi
movq %rbp, %rsi
movq %r13, %rdx
callq 0x4360
leaq 0x80(%rsp), %r13
movq %r13, %rdi
movq %rbx, %rsi
callq 0x4400
movq 0xc0(%rsp), %rdi
cmpq %r15, %rdi
movq 0x38(%rsp), %r14
je 0x8e53
callq 0x4310
movq %rbx, %rdi
leaq 0x60(%rsp), %rsi
movq %r13, %rdx
callq 0xa7d0
movq 0x30(%rsp), %rdi
movq %rbx, %rsi
callq 0xa9c2
movq 0xe0(%rsp), %rdi
leaq 0xf0(%rsp), %rax
cmpq %rax, %rdi
je 0x8e8a
callq 0x4310
movq 0xc0(%rsp), %rdi
cmpq %r15, %rdi
je 0x8e9c
callq 0x4310
movq %r12, %rbx
cmpq %r14, %r12
jne 0x8d92
addq $0x4, %r14
leaq 0xc0(%rsp), %rdi
movq (%rsp), %rsi
movq %r14, %rdx
movq $-0x1, %rcx
callq 0x4360
movq 0x8(%rsp), %rdi
addq $0x90, %rdi
leaq 0xc0(%rsp), %r14
movq %r14, %rsi
callq 0x4400
movq (%r14), %rdi
leaq 0xd0(%rsp), %rax
cmpq %rax, %rdi
leaq 0x20(%rsp), %r15
leaq 0x50(%rsp), %r12
je 0x8f02
callq 0x4310
movb $0x1, %bpl
jmp 0x8ff3
movq 0xf0a7(%rip), %rdi      # 0x17fb8
leaq 0x7b37(%rip), %rsi      # 0x10a4f
movl $0x3, %edx
callq 0x43a0
movq (%rsp), %rax
movq (%rax), %rsi
movq 0x8(%rax), %rdx
movq 0xf084(%rip), %rdi      # 0x17fb8
callq 0x43a0
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x4320
movsbl %al, %esi
movq %r14, %rdi
callq 0x4030
movq %rax, %rdi
callq 0x4240
movq 0xf04e(%rip), %r14      # 0x17fb8
leaq 0x7ae2(%rip), %rsi      # 0x10a53
movl $0x36, %edx
movq %r14, %rdi
callq 0x43a0
movq (%r14), %rax
addq -0x18(%rax), %r14
movq %r14, %rdi
movl $0xa, %esi
callq 0x4320
movsbl %al, %esi
movq 0xf01c(%rip), %rdi      # 0x17fb8
callq 0x4030
movq %rax, %rdi
callq 0x4240
jmp 0x8ff1
movq 0xf006(%rip), %r14      # 0x17fb8
leaq 0x7ad1(%rip), %rsi      # 0x10a8a
movl $0x38, %edx
movq %r14, %rdi
callq 0x43a0
movq (%r14), %rax
addq -0x18(%rax), %r14
movq %r14, %rdi
movl $0xa, %esi
callq 0x4320
movsbl %al, %esi
movq 0xefd4(%rip), %rdi      # 0x17fb8
callq 0x4030
movq %rax, %rdi
callq 0x4240
xorl %ebp, %ebp
movq (%rsp), %rax
movq $0x0, 0x8(%rax)
movq (%rax), %rax
movb $0x0, (%rax)
movq 0x80(%rsp), %rdi
leaq 0x90(%rsp), %rax
cmpq %rax, %rdi
je 0x901f
callq 0x4310
movq 0x60(%rsp), %rdi
leaq 0x70(%rsp), %rax
cmpq %rax, %rdi
je 0x9033
callq 0x4310
movq 0x40(%rsp), %rdi
cmpq %r12, %rdi
je 0x9042
callq 0x4310
movq 0x10(%rsp), %rdi
cmpq %r15, %rdi
je 0x9051
callq 0x4310
movl %ebp, %eax
addq $0x248, %rsp            # imm = 0x248
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x90ba
movq %rax, %rbx
jmp 0x909c
jmp 0x90ba
jmp 0x90ba
movq %rax, %rbx
jmp 0x9111
movq %rax, %rbx
movq 0xef16(%rip), %rsi      # 0x17f98
leaq 0xc0(%rsp), %rdi
callq 0x4290
leaq 0x140(%rsp), %rdi
callq 0x4110
leaq 0xb0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x90cf
callq 0x4310
jmp 0x90cf
jmp 0x90ba
jmp 0x90ba
jmp 0x90ba
movq %rax, %rbx
jmp 0x90cf
movq %rax, %rbx
leaq 0xc0(%rsp), %rdi
callq 0xa82e
movq 0x80(%rsp), %rdi
leaq 0x90(%rsp), %rax
cmpq %rax, %rdi
je 0x90e9
callq 0x4310
movq 0x60(%rsp), %rdi
leaq 0x70(%rsp), %rax
cmpq %rax, %rdi
je 0x90fd
callq 0x4310
movq 0x40(%rsp), %rdi
leaq 0x50(%rsp), %rax
cmpq %rax, %rdi
je 0x9111
callq 0x4310
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x9125
callq 0x4310
movq %rbx, %rdi
callq 0x45a0
nop