// File: /workspace/github_c_makefile_star2_O3/shifengbin[P]bishe/HTTP/./HTTP.cpp
// Function: HTTP::HTTP(int)
HTTP::HTTP( int fd )
{
	char buf[1024*1024] = { 0 };
	char *temp = NULL;
	char *next = NULL;
	int n = 0;
	this->header.length = 0;
	SockTool::readLine( fd, buf ,1024 );
	//get http state
	if ( ( temp = strstr( buf , " ")) != NULL )
	{
		temp++;
		if ( (next = strstr( temp , " ")) != NULL )
		{
			*next = '\0';
			this->header.state = atoi( temp );
		}
		//----debug---
//		puts(buf);
		memset( buf, 0 , sizeof(buf));
	}
	//get other of http header
	for(;;)
        {
                SockTool::readLine( fd , buf , sizeof(buf) );
		if ( !strncasecmp( buf , "Transfer-Encoding:",strlen("Transfer-Encoding:")) )
		{
			this->header.length = -1;
		}
		else if ( !strncasecmp( buf , "Content-Length:",strlen("Content-Length:")) )
		{
			if ( (temp = strstr( buf , " ")) != NULL )
			{
				this->header.length = atoi( temp );
			}
			else if ( (temp = strstr( buf , ":")) != NULL )
			{
				this->header.length = atoi( temp );
			}
		}
		//---debug---
//		puts(buf);
                if ( !strncmp(buf,"\r\n",2) )
                {
                        break;
                }
                memset( buf , 0 , sizeof( buf ));
        }
	if ( this->header.state/100 == 2 )
	{
		pthread_mutex_lock(&lock);
		this->body = (char *)malloc( BODYSIZE );
		memset( this->body , 0 , BODYSIZE);
		pthread_mutex_unlock(&lock);
	}
	else
	{
		this->body = NULL;
		return;
	}
	memset( buf, 0 , sizeof(buf));
	if( this->header.length <= 0 )
	{
        	for( ;; )
        	{
                	SockTool::readLine( fd, buf , sizeof(buf) );
			if ( !strncmp(buf, "\r\n",2) )
			{
				continue;
			}
			if ( isHex(buf) )
			{
				n = hex2i(buf);
				if ( n == 0 )
				{
					break;
				}
				continue;
			}
			strcat( this->body , buf );
			memset(buf ,0, sizeof(buf));
/*                	if ( (temp = strstr( buf , "\r")) != NULL )
                	{
                        	*temp = '\0';
                	}
                	n = hex2i(buf) + 2;
			//---debug---
			printf("Length:%s=%d\n",buf,n);

                	if ( n == 2 )
                	{
                        	break;
                	}
//			SockTool::readLine( fd , buf , sizeof(buf) );
			memset( buf, 0 , sizeof( buf ));
                	SockTool::readN(fd , buf , sizeof( buf ),n );
                	if ( (temp = strstr( buf , "\r")) != NULL ) 
			{
                        	*temp = '\0';
                	}
			//---debug---
			printf("BUF:\n%s\n",buf);
                	strcat( this->body , buf);
                	memset( buf , 0 , sizeof( buf ));*/
        	}

	}
	else
	{
		SockTool::readN(fd , this->body , BODYSIZE ,this->header.length );
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x100000, %rsp         # imm = 0x100000
movl %esi, %ebx
movq %rdi, %r14
leaq -0x100020(%rbp), %r15
movl $0x100000, %edx         # imm = 0x100000
movq %r15, %rdi
xorl %esi, %esi
callq 0x8160
movl $0x0, 0x4(%r14)
movl %ebx, %edi
movq %r15, %rsi
movl $0x400, %edx            # imm = 0x400
callq 0x964c
movq %r15, %rdi
movl $0x20, %esi
callq 0x8100
testq %rax, %rax
je 0x8e33
movq %rax, %r15
incq %r15
movq %r15, %rdi
movl $0x20, %esi
callq 0x8100
testq %rax, %rax
je 0x8e20
movb $0x0, (%rax)
movq %r15, %rdi
callq 0x84c0
movl %eax, (%r14)
leaq -0x100020(%rbp), %rdi
movl $0x100000, %edx         # imm = 0x100000
xorl %esi, %esi
callq 0x8160
leaq -0x100020(%rbp), %r15
movl %ebx, %edi
movq %r15, %rsi
movl $0x100000, %edx         # imm = 0x100000
callq 0x964c
leaq 0x6e281(%rip), %rsi     # 0x770d1
movl $0x12, %edx
movq %r15, %rdi
callq 0x83c0
movl %eax, %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
testl %ecx, %ecx
je 0x8eb8
leaq 0x6e275(%rip), %rsi     # 0x770e4
leaq -0x100020(%rbp), %rdi
movl $0xf, %edx
callq 0x83c0
testl %eax, %eax
jne 0x8ebc
leaq -0x100020(%rbp), %rdi
movl $0x20, %esi
callq 0x8100
testq %rax, %rax
jne 0x8eb0
leaq -0x100020(%rbp), %rdi
movl $0x3a, %esi
callq 0x8100
testq %rax, %rax
je 0x8ebc
movq %rax, %rdi
callq 0x84c0
movl %eax, 0x4(%r14)
cmpw $0xa0d, -0x100020(%rbp) # imm = 0xA0D
jne 0x8e20
movl $0xffffff38, %eax       # imm = 0xFFFFFF38
addl (%r14), %eax
cmpl $0x63, %eax
ja 0x8f32
leaq 0x8c0c9(%rip), %r15     # 0x94fa8
movq %r15, %rdi
callq 0x8450
movl $0x1, %edi
movl $0x300000, %esi         # imm = 0x300000
callq 0x8190
movq %rax, 0x8(%r14)
movq %r15, %rdi
callq 0x8200
leaq -0x100020(%rbp), %r15
movl $0x100000, %edx         # imm = 0x100000
movq %r15, %rdi
xorl %esi, %esi
callq 0x8160
movl 0x4(%r14), %ecx
testl %ecx, %ecx
jle 0x8f4a
movq 0x8(%r14), %rsi
movl %ebx, %edi
movl $0x300000, %edx         # imm = 0x300000
callq 0x9638
jmp 0x8f3a
movq $0x0, 0x8(%r14)
addq $0x100000, %rsp         # imm = 0x100000
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movabsq $0x3f0000003f, %r12     # imm = 0x3F0000003F
movl %ebx, %edi
movq %r15, %rsi
movl $0x100000, %edx         # imm = 0x100000
callq 0x964c
movzwl -0x100020(%rbp), %ecx
cmpl $0xa0d, %ecx            # imm = 0xA0D
je 0x8f54
movq %r15, %rax
cmpb $0xd, %cl
je 0x8fa1
movq %r15, %rax
leal -0x30(%rcx), %edx
cmpb $0xa, %dl
jb 0x8f96
movzbl %cl, %ecx
addl $-0x41, %ecx
cmpl $0x25, %ecx
ja 0x8fb5
btq %rcx, %r12
jae 0x8fb5
movb 0x1(%rax), %cl
incq %rax
cmpb $0xd, %cl
jne 0x8f7d
cmpb $0xa, 0x1(%rax)
jne 0x8fb5
movq %r15, %rdi
callq 0x9024
testl %eax, %eax
jne 0x8f54
jmp 0x8f3a
movq 0x8(%r14), %rdi
movq %r15, %rsi
callq 0x8530
movl $0x100000, %edx         # imm = 0x100000
movq %r15, %rdi
xorl %esi, %esi
callq 0x8160
jmp 0x8f54