// File: /workspace/github_c_makefile_star2_O2/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 %rbx
subq $0x100008, %rsp         # imm = 0x100008
movl %esi, %ebx
movq %rdi, %r14
leaq -0x100020(%rbp), %r15
movl $0x100000, %edx         # imm = 0x100000
movq %r15, %rdi
xorl %esi, %esi
callq 0x8160
andl $0x0, 0x4(%r14)
movl %ebx, %edi
movq %r15, %rsi
movl $0x400, %edx            # imm = 0x400
callq 0x959e
pushq $0x20
popq %rsi
movq %r15, %rdi
callq 0x8100
testq %rax, %rax
je 0x8d88
movq %rax, %r15
incq %r15
pushq $0x20
popq %rsi
movq %r15, %rdi
callq 0x8100
testq %rax, %rax
je 0x8d75
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 0x959e
leaq 0x5f32c(%rip), %rsi     # 0x680d1
pushq $0x12
popq %rdx
movq %r15, %rdi
callq 0x83c0
movl %eax, %ecx
pushq $-0x1
popq %rax
testl %ecx, %ecx
je 0x8e03
leaq 0x5f324(%rip), %rsi     # 0x680e4
leaq -0x100020(%rbp), %rdi
pushq $0xf
popq %rdx
callq 0x83c0
testl %eax, %eax
jne 0x8e07
leaq -0x100020(%rbp), %rdi
pushq $0x20
popq %rsi
callq 0x8100
testq %rax, %rax
jne 0x8dfb
leaq -0x100020(%rbp), %rdi
pushq $0x3a
popq %rsi
callq 0x8100
testq %rax, %rax
je 0x8e07
movq %rax, %rdi
callq 0x84c0
movl %eax, 0x4(%r14)
cmpw $0xa0d, -0x100020(%rbp) # imm = 0xA0D
jne 0x8d75
movl $0xffffff38, %eax       # imm = 0xFFFFFF38
addl (%r14), %eax
cmpl $0x63, %eax
ja 0x8e78
leaq 0x7d17e(%rip), %r15     # 0x85fa8
movq %r15, %rdi
callq 0x8450
pushq $0x1
popq %rdi
movl $0x300000, %esi         # imm = 0x300000
callq 0x8190
movq %rax, 0x8(%r14)
movq %r15, %rdi
callq 0x8200
leaq -0x100020(%rbp), %rdi
movl $0x100000, %edx         # imm = 0x100000
xorl %esi, %esi
callq 0x8160
movl 0x4(%r14), %ecx
testl %ecx, %ecx
jle 0x8e8b
movq 0x8(%r14), %rsi
movl %ebx, %edi
movl $0x300000, %edx         # imm = 0x300000
callq 0x958a
jmp 0x8e7d
andq $0x0, 0x8(%r14)
addq $0x100008, %rsp         # imm = 0x100008
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
leaq -0x100020(%rbp), %r15
movl %ebx, %edi
movq %r15, %rsi
movl $0x100000, %edx         # imm = 0x100000
callq 0x959e
cmpw $0xa0d, -0x100020(%rbp) # imm = 0xA0D
je 0x8e92
movq %r15, %rdi
callq 0x8cbc
testl %eax, %eax
je 0x8ec6
movq %r15, %rdi
callq 0x8f38
testl %eax, %eax
jne 0x8e92
jmp 0x8e7d
movq 0x8(%r14), %rdi
movq %r15, %rsi
callq 0x8530
movl $0x100000, %edx         # imm = 0x100000
movq %r15, %rdi
xorl %esi, %esi
callq 0x8160
jmp 0x8e92
nop