// File: /workspace/github_cpp_makefile_star2_O2/JianjiaoSQ[P]MyPoorWebServer/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"); // 该函数返回 str1 中第一个不在字符串 str2 中出现的字符下标。

    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) // 比较参数 s1 和  s2 字符串前n个字符
    {
        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
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x3d4d(%rip), %rsi      # 0x822f
movq %r14, %rdi
callq 0x3620
movq %rax, 0xd08(%rbx)
pushq $0x2
popq %rbp
testq %rax, %rax
je 0x45d2
movq %rax, %rcx
incq %rcx
movq %rcx, 0xd08(%rbx)
movb $0x0, (%rax)
leaq 0x3d1e(%rip), %rsi      # 0x8232
movq %r14, %rdi
callq 0x3400
testl %eax, %eax
je 0x454b
leaq 0x3d0f(%rip), %rsi      # 0x8236
movq %r14, %rdi
callq 0x3400
testl %eax, %eax
jne 0x45d2
movl $0x1, 0xc3c(%rbx)
pushq $0x1
popq %rax
movl $0xde4, %ecx            # imm = 0xDE4
jmp 0x4552
xorl %eax, %eax
movl $0xc3c, %ecx            # imm = 0xC3C
movl %eax, (%rbx,%rcx)
movq 0xd08(%rbx), %r14
leaq 0x3ccc(%rip), %r15      # 0x822f
movq %r14, %rdi
movq %r15, %rsi
callq 0x3150
addq %rax, %r14
movq %r14, 0xd08(%rbx)
movq %r14, %rdi
movq %r15, %rsi
callq 0x3620
movq %rax, 0xd10(%rbx)
testq %rax, %rax
je 0x45d2
movq %rax, %rcx
incq %rcx
movq %rcx, 0xd10(%rbx)
movb $0x0, (%rax)
movq 0xd10(%rbx), %r14
leaq 0x3c82(%rip), %rsi      # 0x822f
movq %r14, %rdi
callq 0x3150
addq %rax, %r14
movq %r14, 0xd10(%rbx)
leaq 0x3c75(%rip), %rsi      # 0x823b
movq %r14, %rdi
callq 0x3400
testl %eax, %eax
je 0x45df
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movq 0xd08(%rbx), %r14
leaq 0x3c57(%rip), %rsi      # 0x8244
pushq $0x7
popq %rdx
movq %r14, %rdi
callq 0x34d0
testl %eax, %eax
jne 0x461c
addq $0x7, %r14
movq %r14, 0xd08(%rbx)
pushq $0x2f
popq %rsi
movq %r14, %rdi
callq 0x3130
movq %rax, %r14
movq %rax, 0xd08(%rbx)
leaq 0x3c29(%rip), %rsi      # 0x824c
pushq $0x8
popq %rdx
movq %r14, %rdi
callq 0x34d0
testl %eax, %eax
jne 0x4652
addq $0x8, %r14
movq %r14, 0xd08(%rbx)
pushq $0x2f
popq %rsi
movq %r14, %rdi
callq 0x3130
movq %rax, %r14
movq %rax, 0xd08(%rbx)
testq %r14, %r14
je 0x45d2
cmpb $0x2f, (%r14)
jne 0x45d2
movq %r14, %rdi
callq 0x3160
cmpq $0x1, %rax
jne 0x4692
movq %r14, %rdi
callq 0x3160
movabsq $0x74682e656764756a, %rcx # imm = 0x74682E656764756A
movq %rcx, (%r14,%rax)
movl $0x6c6d74, 0x7(%r14,%rax) # imm = 0x6C6D74
movl $0x1, 0xc38(%rbx)
xorl %ebp, %ebp
jmp 0x45d2
nop