// File: /workspace/github_c_makefile_star2_O1/enzo1982[P]smooth/classes/io/drivers/driver_https.cpp
// Function: smooth::IO::DriverHTTPS::DriverHTTPS(smooth::String const&, int, smooth::String const&, int, smooth::String const&, smooth::String const&)
S::IO::DriverHTTPS::DriverHTTPS(const String &proxy, Int httpPort, const String &hostName, Int port, const String &uname, const String &passwd) : Driver()
{
	closeStream = False;

	stream	    = -1;
	size	    = -1;

	if (hostName.Length() > 255) { lastError = IO_ERROR_BADPARAM; return; }

	/* Open TCP/IP socket.
	 */
	stream = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);

	if (stream == (unsigned) (~0)) { lastError = IO_ERROR_UNEXPECTED; return; }

	closeStream = True;

	/* Get proxy hostname.
	 */
	hostent		*host = gethostbyname(proxy);

	if (host == NIL) { Close(); lastError = IO_ERROR_UNEXPECTED; return; }

	/* Connect to proxy.
	 */
	sockaddr_in	 saddr;

	saddr.sin_family = AF_INET;
	saddr.sin_addr	 = *((in_addr *) *host->h_addr_list);
	saddr.sin_port	 = htons((short) httpPort);

	memset(&saddr.sin_zero, 0, sizeof(saddr.sin_zero));

	if (connect(stream, (sockaddr *) &saddr, sizeof(struct sockaddr)) == -1) { Close(); lastError = IO_ERROR_UNEXPECTED; return; }

	/* Send connect request.
	 */
	String	 connect = String("CONNECT ").Append(hostName).Append(":").Append(String::FromInt(port)).Append(" HTTP/1.1\n");

	if (uname != NIL) connect.Append("Proxy-authentication: Basic ").Append(String(String(uname).Append(":").Append(passwd)).EncodeBase64()).Append("\n");

	connect.Append("\n");

	if (send(stream, (char *) connect, connect.Length(), 0) < connect.Length()) { Close(); lastError = IO_ERROR_UNEXPECTED; return; }

	/* Receive answer.
	 */
	String	 answer;
	char	 c[2] = { 0, 0 };

	while (!(answer.EndsWith("\n\n") || answer.EndsWith("\r\n\r\n")))
	{
		if (recv(stream, c, 1, 0) <= 0) { Close(); lastError = IO_ERROR_UNEXPECTED; return; }

		answer.Append(c);
	}

	/* Check if connect attempt was successful.
	 */
	if (answer.SubString(9, 3) != "200") { Close(); lastError = IO_ERROR_UNEXPECTED; return; }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %r9, %r14
movl %r8d, %ebp
movq %rcx, %r15
movl %edx, %r12d
movq %rsi, %r13
movq %rdi, %rbx
callq 0x58560
movq 0xcb959(%rip), %rax     # 0x16cc40
addq $0x10, %rax
movq %rax, (%rbx)
movb $0x0, 0x3c(%rbx)
movl $0xffffffff, 0x38(%rbx) # imm = 0xFFFFFFFF
movq $-0x1, 0x8(%rbx)
movq %r15, %rdi
callq 0x57180
cmpl $0x100, %eax            # imm = 0x100
jl 0xa131c
movl $0x2, 0x18(%rbx)
jmp 0xa16e9
movl $0x2, %edi
movl $0x1, %esi
movl $0x6, %edx
callq 0x56660
movl %eax, 0x38(%rbx)
cmpl $-0x1, %eax
je 0xa15cb
movb $0x1, 0x3c(%rbx)
movq %r13, %rdi
callq 0x585e0
movq %rax, %rdi
callq 0x56530
testq %rax, %rax
je 0xa15b7
leaq 0xa8(%rsp), %rsi
movw $0x2, (%rsi)
movq 0x18(%rax), %rax
movq (%rax), %rax
movl (%rax), %eax
rolw $0x8, %r12w
movl %eax, 0x4(%rsi)
movw %r12w, 0x2(%rsi)
movq $0x0, 0x8(%rsi)
movl 0x38(%rbx), %edi
movl $0x10, %edx
callq 0x56230
cmpl $-0x1, %eax
je 0xa15c2
leaq 0x714b0(%rip), %rsi     # 0x112851
movq %rsp, %rdi
callq 0x579f0
movq %rsp, %rdi
movq %r15, %rsi
callq 0x562f0
movq %rax, %r15
leaq 0x52d29(%rip), %rsi     # 0xf40e7
leaq 0x18(%rsp), %rdi
callq 0x579f0
leaq 0x18(%rsp), %rsi
movq %r15, %rdi
callq 0x562f0
movq %rax, %r15
movslq %ebp, %rsi
leaq 0x30(%rsp), %rdi
callq 0x56cf0
leaq 0x30(%rsp), %rsi
movq %r15, %rdi
callq 0x562f0
movq %rax, %r15
leaq 0x7145e(%rip), %rsi     # 0x11285a
leaq 0x48(%rsp), %rdi
callq 0x579f0
leaq 0x48(%rsp), %rsi
movq %r15, %rdi
callq 0x562f0
leaq 0x60(%rsp), %rdi
movq %rax, %rsi
callq 0x570b0
leaq 0x48(%rsp), %rdi
callq 0x59200
leaq 0x30(%rsp), %rdi
callq 0x59200
leaq 0x18(%rsp), %rdi
callq 0x59200
movq %rsp, %rdi
callq 0x59200
movq %r14, %rdi
xorl %esi, %esi
callq 0x56bd0
testb %al, %al
je 0xa1541
leaq 0x71406(%rip), %rsi     # 0x112865
movq %rsp, %rdi
callq 0x579f0
leaq 0x60(%rsp), %rdi
movq %rsp, %rsi
callq 0x562f0
movq %rax, %r15
leaq 0x48(%rsp), %rdi
movq %r14, %rsi
callq 0x570b0
leaq 0x52c5c(%rip), %rsi     # 0xf40e7
leaq 0x90(%rsp), %rdi
callq 0x579f0
leaq 0x48(%rsp), %rdi
leaq 0x90(%rsp), %rsi
callq 0x562f0
movq 0xf0(%rsp), %rsi
movq %rax, %rdi
callq 0x562f0
leaq 0x30(%rsp), %rdi
movq %rax, %rsi
callq 0x570b0
leaq 0x18(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x55860
leaq 0x18(%rsp), %rsi
movq %r15, %rdi
callq 0x562f0
movq %rax, %r14
leaq 0x71396(%rip), %rsi     # 0x112883
leaq 0x78(%rsp), %rdi
callq 0x579f0
leaq 0x78(%rsp), %rsi
movq %r14, %rdi
callq 0x562f0
leaq 0x78(%rsp), %rdi
callq 0x59200
leaq 0x18(%rsp), %rdi
callq 0x59200
leaq 0x30(%rsp), %rdi
callq 0x59200
leaq 0x90(%rsp), %rdi
callq 0x59200
leaq 0x48(%rsp), %rdi
callq 0x59200
movq %rsp, %rdi
callq 0x59200
leaq 0x7133b(%rip), %rsi     # 0x112883
movq %rsp, %rdi
callq 0x579f0
leaq 0x60(%rsp), %rdi
movq %rsp, %rsi
callq 0x562f0
movq %rsp, %rdi
callq 0x59200
movl 0x38(%rbx), %ebp
leaq 0x60(%rsp), %rdi
callq 0x585e0
movq %rax, %r14
leaq 0x60(%rsp), %rdi
callq 0x57180
movslq %eax, %rdx
movl %ebp, %edi
movq %r14, %rsi
xorl %ecx, %ecx
callq 0x56130
movq %rax, %r14
leaq 0x60(%rsp), %rdi
callq 0x57180
cltq
cmpq %rax, %r14
jge 0xa15d7
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x38(%rax)
movl $0x3, 0x18(%rbx)
jmp 0xa16df
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x38(%rax)
jmp 0xa15cb
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x38(%rax)
movl $0x3, 0x18(%rbx)
jmp 0xa16e9
movq %rsp, %rdi
xorl %esi, %esi
callq 0x58e20
leaq 0x48(%rsp), %r13
movw $0x0, (%r13)
leaq 0x18(%rsp), %r12
leaq 0x30(%rsp), %r14
movq %r12, %rdi
leaq 0x71281(%rip), %rsi     # 0x112882
callq 0x579f0
movq %rsp, %rdi
movq %r12, %rsi
callq 0x58b10
movl %eax, %r15d
movb $0x1, %bpl
testb %al, %al
jne 0xa163a
movq %r14, %rbp
movq %r14, %rdi
leaq 0x71b8e(%rip), %rsi     # 0x1131b6
callq 0x579f0
movq %rsp, %rdi
movq %rbp, %rsi
callq 0x58b10
movl %eax, %ebp
testb %r15b, %r15b
jne 0xa1647
movq %r14, %rdi
callq 0x59200
movq %r12, %rdi
callq 0x59200
testb %bpl, %bpl
jne 0xa168e
movl 0x38(%rbx), %edi
movl $0x1, %edx
movq %r13, %rsi
xorl %ecx, %ecx
callq 0x582d0
testq %rax, %rax
jle 0xa16c7
movq %r12, %rdi
movq %r13, %rsi
callq 0x579f0
movq %rsp, %rdi
movq %r12, %rsi
callq 0x562f0
movq %r12, %rdi
callq 0x59200
jmp 0xa15f7
leaq 0x18(%rsp), %rdi
movq %rsp, %rsi
movl $0x9, %edx
movl $0x3, %ecx
callq 0x58f50
leaq 0x711d9(%rip), %rsi     # 0x112885
leaq 0x18(%rsp), %rdi
callq 0x590a0
movl %eax, %ebp
leaq 0x18(%rsp), %rdi
callq 0x59200
testb %bpl, %bpl
je 0xa16d7
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x38(%rax)
movl $0x3, 0x18(%rbx)
movq %rsp, %rdi
callq 0x59200
leaq 0x60(%rsp), %rdi
callq 0x59200
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xa17c9
jmp 0xa17c4
jmp 0xa17c4
jmp 0xa17b7
movq %rax, %r14
leaq 0x78(%rsp), %rdi
callq 0x59200
jmp 0xa1723
jmp 0xa1720
movq %rax, %r14
leaq 0x18(%rsp), %rdi
callq 0x59200
jmp 0xa1732
movq %rax, %r14
leaq 0x30(%rsp), %rdi
callq 0x59200
jmp 0xa176a
movq %rax, %r14
jmp 0xa1777
jmp 0xa17c4
jmp 0xa17c4
jmp 0xa17b7
jmp 0xa17c4
jmp 0xa17b7
jmp 0xa174f
movq %rax, %r14
jmp 0xa178b
jmp 0xa1756
movq %rax, %r14
jmp 0xa1795
jmp 0xa175d
movq %rax, %r14
jmp 0xa179f
jmp 0xa17ea
movq %rax, %r14
leaq 0x90(%rsp), %rdi
callq 0x59200
leaq 0x48(%rsp), %rdi
jmp 0xa17d1
movq %rax, %r14
leaq 0x48(%rsp), %rdi
callq 0x59200
leaq 0x30(%rsp), %rdi
callq 0x59200
leaq 0x18(%rsp), %rdi
callq 0x59200
movq %rsp, %rdi
jmp 0xa17e3
jmp 0xa17ea
movq %rax, %r14
leaq 0x30(%rsp), %rdi
callq 0x59200
jmp 0xa17cc
jmp 0xa17c9
movq %rax, %r14
jmp 0xa17de
jmp 0xa17ea
jmp 0xa17c4
jmp 0xa17c9
jmp 0xa17c4
movq %rax, %r14
jmp 0xa17d6
movq %rax, %r14
leaq 0x18(%rsp), %rdi
callq 0x59200
movq %rsp, %rdi
callq 0x59200
leaq 0x60(%rsp), %rdi
callq 0x59200
jmp 0xa17ed
movq %rax, %r14
movq %rbx, %rdi
callq 0x56c30
movq %r14, %rdi
callq 0x57090
nop