// File: /workspace/github_c_makefile_star2_O0/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
subq $0x100030, %rsp         # imm = 0x100030
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x100030(%rbp)
leaq -0x100010(%rbp), %rdi
xorl %esi, %esi
movl $0x100000, %edx         # imm = 0x100000
callq 0x8160
movq -0x100030(%rbp), %rax
movq $0x0, -0x100018(%rbp)
movq $0x0, -0x100020(%rbp)
movl $0x0, -0x100024(%rbp)
movl $0x0, 0x4(%rax)
movl -0xc(%rbp), %edi
leaq -0x100010(%rbp), %rsi
movl $0x400, %edx            # imm = 0x400
callq 0xa330
leaq -0x100010(%rbp), %rdi
leaq 0x9fa47(%rip), %rsi     # 0xa8db7
callq 0x8090
movq %rax, -0x100018(%rbp)
cmpq $0x0, %rax
je 0x93e8
movq -0x100018(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x100018(%rbp)
movq -0x100018(%rbp), %rdi
leaq 0x9fa15(%rip), %rsi     # 0xa8db7
callq 0x8090
movq %rax, -0x100020(%rbp)
cmpq $0x0, %rax
je 0x93d5
movq -0x100020(%rbp), %rax
movb $0x0, (%rax)
movq -0x100018(%rbp), %rdi
callq 0x8480
movl %eax, %ecx
movq -0x100030(%rbp), %rax
movl %ecx, (%rax)
leaq -0x100010(%rbp), %rdi
xorl %esi, %esi
movl $0x100000, %edx         # imm = 0x100000
callq 0x8160
jmp 0x93ea
movl -0xc(%rbp), %edi
leaq -0x100010(%rbp), %rsi
movl $0x100000, %edx         # imm = 0x100000
callq 0xa330
leaq -0x100010(%rbp), %rdi
leaq 0x98cd7(%rip), %rsi     # 0xa20e3
movl $0x12, %edx
callq 0x8380
cmpl $0x0, %eax
jne 0x942e
movq -0x100030(%rbp), %rax
movl $0xffffffff, 0x4(%rax)  # imm = 0xFFFFFFFF
jmp 0x94c3
leaq -0x100010(%rbp), %rdi
leaq 0x98cba(%rip), %rsi     # 0xa20f6
movl $0xf, %edx
callq 0x8380
cmpl $0x0, %eax
jne 0x94c1
leaq -0x100010(%rbp), %rdi
leaq 0x9f95e(%rip), %rsi     # 0xa8db7
callq 0x8090
movq %rax, -0x100018(%rbp)
cmpq $0x0, %rax
je 0x9485
movq -0x100018(%rbp), %rdi
callq 0x8480
movl %eax, %ecx
movq -0x100030(%rbp), %rax
movl %ecx, 0x4(%rax)
jmp 0x94bf
leaq -0x100010(%rbp), %rdi
leaq 0xa0d28(%rip), %rsi     # 0xaa1bb
callq 0x8090
movq %rax, -0x100018(%rbp)
cmpq $0x0, %rax
je 0x94bd
movq -0x100018(%rbp), %rdi
callq 0x8480
movl %eax, %ecx
movq -0x100030(%rbp), %rax
movl %ecx, 0x4(%rax)
jmp 0x94bf
jmp 0x94c1
jmp 0x94c3
leaq -0x100010(%rbp), %rdi
leaq 0x98ba4(%rip), %rsi     # 0xa2075
movl $0x2, %edx
callq 0x8150
cmpl $0x0, %eax
jne 0x94e2
jmp 0x94fa
leaq -0x100010(%rbp), %rdi
xorl %esi, %esi
movl $0x100000, %edx         # imm = 0x100000
callq 0x8160
jmp 0x93ea
movq -0x100030(%rbp), %rax
movl (%rax), %eax
movl $0x64, %ecx
cltd
idivl %ecx
cmpl $0x2, %eax
jne 0x9552
leaq 0xbab31(%rip), %rdi     # 0xc4048
callq 0x8410
movl $0x300000, %edi         # imm = 0x300000
callq 0x83b0
movq %rax, %rcx
movq -0x100030(%rbp), %rax
movq %rcx, 0x8(%rax)
movq 0x8(%rax), %rdi
xorl %esi, %esi
movl $0x300000, %edx         # imm = 0x300000
callq 0x8160
leaq 0xbaafd(%rip), %rdi     # 0xc4048
callq 0x81f0
jmp 0x9566
movq -0x100030(%rbp), %rax
movq $0x0, 0x8(%rax)
jmp 0x963b
leaq -0x100010(%rbp), %rdi
xorl %esi, %esi
movl $0x100000, %edx         # imm = 0x100000
callq 0x8160
movq -0x100030(%rbp), %rax
cmpl $0x0, 0x4(%rax)
jg 0x9620
jmp 0x958c
movl -0xc(%rbp), %edi
leaq -0x100010(%rbp), %rsi
movl $0x100000, %edx         # imm = 0x100000
callq 0xa330
leaq -0x100010(%rbp), %rdi
leaq 0x98ac7(%rip), %rsi     # 0xa2075
movl $0x2, %edx
callq 0x8150
cmpl $0x0, %eax
jne 0x95bf
jmp 0x958c
leaq -0x100010(%rbp), %rdi
callq 0x9250
cmpl $0x0, %eax
je 0x95ef
leaq -0x100010(%rbp), %rdi
callq 0x96f0
movl %eax, -0x100024(%rbp)
cmpl $0x0, -0x100024(%rbp)
jne 0x95ed
jmp 0x961e
jmp 0x958c
movq -0x100030(%rbp), %rax
movq 0x8(%rax), %rdi
leaq -0x100010(%rbp), %rsi
callq 0x84f0
leaq -0x100010(%rbp), %rdi
xorl %esi, %esi
movl $0x100000, %edx         # imm = 0x100000
callq 0x8160
jmp 0x958c
jmp 0x963b
movq -0x100030(%rbp), %rax
movl -0xc(%rbp), %edi
movq 0x8(%rax), %rsi
movl 0x4(%rax), %ecx
movl $0x300000, %edx         # imm = 0x300000
callq 0xa2d0
addq $0x100030, %rsp         # imm = 0x100030
popq %rbp
retq
nopw %cs:(%rax,%rax)