// File: yckwong[P]tinywebserver/http/http_conn.cpp
// Function: http_conn::parse_request_line(char*)
http_conn::HTTP_CODE http_conn::parse_request_line(char *text)
{
    m_url = strpbrk(text, " \t");
    if (!m_url)
    {
        return BAD_REQUEST;
    }
    *m_url++ = '\0';
    char *method = text;
    if (strcasecmp(method, "GET") == 0)
        m_method = GET;
    else if (strcasecmp(method, "POST") == 0)
    {
        m_method = POST;
        cgi = 1;
    }
    else
        return BAD_REQUEST;
    m_url += strspn(m_url, " \t");
    m_version = strpbrk(m_url, " \t");
    if (!m_version)
        return BAD_REQUEST;
    *m_version++ = '\0';
    m_version += strspn(m_version, " \t");
    if (strcasecmp(m_version, "HTTP/1.1") != 0)
        return BAD_REQUEST;
    if (strncasecmp(m_url, "http://", 7) == 0)
    {
        m_url += 7;
        m_url = strchr(m_url, '/');
    }

    if (strncasecmp(m_url, "https://", 8) == 0)
    {
        m_url += 8;
        m_url = strchr(m_url, '/');
    }

    if (!m_url || m_url[0] != '/')
        return BAD_REQUEST;
    //当url为/时，显示判断界面
    if (strlen(m_url) == 1)
        strcat(m_url, "judge.html");
    m_check_state = CHECK_STATE_HEADER;
    return NO_REQUEST;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x18(%rbp), %rdi
leaq 0x9add(%rip), %rsi      # 0x10240
callq 0x47c0
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0xd08(%rax)
cmpq $0x0, 0xd08(%rax)
jne 0x678c
movl $0x2, -0x4(%rbp)
jmp 0x69f5
movq -0x28(%rbp), %rcx
movq 0xd08(%rcx), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, 0xd08(%rcx)
movb $0x0, (%rax)
movq -0x18(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rdi
leaq 0x9a88(%rip), %rsi      # 0x10243
callq 0x4530
cmpl $0x0, %eax
jne 0x67d5
movq -0x28(%rbp), %rax
movl $0x0, 0xc3c(%rax)
jmp 0x6812
movq -0x20(%rbp), %rdi
leaq 0x9a67(%rip), %rsi      # 0x10247
callq 0x4530
cmpl $0x0, %eax
jne 0x6804
movq -0x28(%rbp), %rax
movl $0x1, 0xc3c(%rax)
movl $0x1, 0xde4(%rax)
jmp 0x6810
movl $0x2, -0x4(%rbp)
jmp 0x69f5
jmp 0x6812
movq -0x28(%rbp), %rax
movq 0xd08(%rax), %rdi
leaq 0x9a1c(%rip), %rsi      # 0x10240
callq 0x41a0
movq %rax, %rcx
movq -0x28(%rbp), %rax
addq 0xd08(%rax), %rcx
movq %rcx, 0xd08(%rax)
movq 0xd08(%rax), %rdi
leaq 0x99f4(%rip), %rsi      # 0x10240
callq 0x47c0
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0xd10(%rax)
cmpq $0x0, 0xd10(%rax)
jne 0x6875
movl $0x2, -0x4(%rbp)
jmp 0x69f5
movq -0x28(%rbp), %rax
movq 0xd10(%rax), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, 0xd10(%rax)
movb $0x0, (%rcx)
movq 0xd10(%rax), %rdi
leaq 0x99a1(%rip), %rsi      # 0x10240
callq 0x41a0
movq %rax, %rcx
movq -0x28(%rbp), %rax
addq 0xd10(%rax), %rcx
movq %rcx, 0xd10(%rax)
movq 0xd10(%rax), %rdi
leaq 0x9985(%rip), %rsi      # 0x1024c
callq 0x4530
cmpl $0x0, %eax
je 0x68dd
movl $0x2, -0x4(%rbp)
jmp 0x69f5
movq -0x28(%rbp), %rax
movq 0xd08(%rax), %rdi
leaq 0x9966(%rip), %rsi      # 0x10255
movl $0x7, %edx
callq 0x4630
cmpl $0x0, %eax
jne 0x6933
movq -0x28(%rbp), %rax
movq 0xd08(%rax), %rcx
addq $0x7, %rcx
movq %rcx, 0xd08(%rax)
movq 0xd08(%rax), %rdi
movl $0x2f, %esi
callq 0x4170
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0xd08(%rax)
movq -0x28(%rbp), %rax
movq 0xd08(%rax), %rdi
leaq 0x9918(%rip), %rsi      # 0x1025d
movl $0x8, %edx
callq 0x4630
cmpl $0x0, %eax
jne 0x6989
movq -0x28(%rbp), %rax
movq 0xd08(%rax), %rcx
addq $0x8, %rcx
movq %rcx, 0xd08(%rax)
movq 0xd08(%rax), %rdi
movl $0x2f, %esi
callq 0x4170
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0xd08(%rax)
movq -0x28(%rbp), %rax
cmpq $0x0, 0xd08(%rax)
je 0x69aa
movq -0x28(%rbp), %rax
movq 0xd08(%rax), %rax
movsbl (%rax), %eax
cmpl $0x2f, %eax
je 0x69b3
movl $0x2, -0x4(%rbp)
jmp 0x69f5
movq -0x28(%rbp), %rax
movq 0xd08(%rax), %rdi
callq 0x41c0
cmpq $0x1, %rax
jne 0x69e0
movq -0x28(%rbp), %rax
movq 0xd08(%rax), %rdi
leaq 0x988b(%rip), %rsi      # 0x10266
callq 0x47f0
movq -0x28(%rbp), %rax
movl $0x1, 0xc38(%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nop