// File: /workspace/github_c_makefile_star2_O1/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 0x9638
movq %r15, %rdi
movl $0x20, %esi
callq 0x8100
testq %rax, %rax
je 0x8e1f
movq %rax, %r15
incq %r15
movq %r15, %rdi
movl $0x20, %esi
callq 0x8100
testq %rax, %rax
je 0x8e0c
movb $0x0, (%rax)
movq %r15, %rdi
callq 0x84b0
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 0x9638
leaq 0x70295(%rip), %rsi     # 0x790d1
movl $0x12, %edx
movq %r15, %rdi
callq 0x83b0
movl %eax, %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
testl %ecx, %ecx
je 0x8ea4
leaq 0x70289(%rip), %rsi     # 0x790e4
leaq -0x100020(%rbp), %rdi
movl $0xf, %edx
callq 0x83b0
testl %eax, %eax
jne 0x8ea8
leaq -0x100020(%rbp), %rdi
movl $0x20, %esi
callq 0x8100
testq %rax, %rax
jne 0x8e9c
leaq -0x100020(%rbp), %rdi
movl $0x3a, %esi
callq 0x8100
testq %rax, %rax
je 0x8ea8
movq %rax, %rdi
callq 0x84b0
movl %eax, 0x4(%r14)
cmpw $0xa0d, -0x100020(%rbp) # imm = 0xA0D
jne 0x8e0c
movl $0xffffff38, %eax       # imm = 0xFFFFFF38
addl (%r14), %eax
cmpl $0x63, %eax
ja 0x8f28
leaq 0x8e0cd(%rip), %r15     # 0x96f98
movq %r15, %rdi
callq 0x8440
movl $0x300000, %edi         # imm = 0x300000
callq 0x83e0
movq %rax, 0x8(%r14)
movl $0x300000, %edx         # imm = 0x300000
movq %rax, %rdi
xorl %esi, %esi
callq 0x8160
movq %r15, %rdi
callq 0x81f0
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 0x8f40
movq 0x8(%r14), %rsi
movl %ebx, %edi
movl $0x300000, %edx         # imm = 0x300000
callq 0x9624
jmp 0x8f30
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 0x9638
cmpw $0xa0d, -0x100020(%rbp) # imm = 0xA0D
je 0x8f4a
movb -0x100020(%rbp), %cl
movq %r15, %rax
cmpb $0xd, %cl
je 0x8f99
movq %r15, %rax
leal -0x30(%rcx), %edx
cmpb $0xa, %dl
jb 0x8f8e
movzbl %cl, %ecx
addl $-0x41, %ecx
cmpl $0x25, %ecx
ja 0x8fad
btq %rcx, %r12
jae 0x8fad
movb 0x1(%rax), %cl
incq %rax
cmpb $0xd, %cl
jne 0x8f75
cmpb $0xa, 0x1(%rax)
jne 0x8fad
movq %r15, %rdi
callq 0x901c
testl %eax, %eax
jne 0x8f4a
jmp 0x8f30
movq 0x8(%r14), %rdi
movq %r15, %rsi
callq 0x8520
movl $0x100000, %edx         # imm = 0x100000
movq %r15, %rdi
xorl %esi, %esi
callq 0x8160
jmp 0x8f4a