// File: /workspace/github_c_makefile_star2_O2/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 0x59850
movq 0xc55f9(%rip), %rax     # 0x161c40
addq $0x10, %rax
movq %rax, (%rbx)
movb $0x0, 0x3c(%rbx)
orl $-0x1, 0x38(%rbx)
orq $-0x1, 0x8(%rbx)
movq %r15, %rdi
callq 0x58370
cmpl $0x100, %eax            # imm = 0x100
jl 0x9c676
movl $0x2, 0x18(%rbx)
jmp 0x9ca30
pushq $0x2
popq %rdi
pushq $0x1
popq %rsi
pushq $0x6
popq %rdx
callq 0x57780
movl %eax, 0x38(%rbx)
cmpl $-0x1, %eax
je 0x9c91a
movb $0x1, 0x3c(%rbx)
movq %r13, %rdi
callq 0x598d0
movq %rax, %rdi
callq 0x57640
testq %rax, %rax
je 0x9c906
leaq 0xa8(%rsp), %rsi
movw $0x2, (%rsi)
movq 0x18(%rax), %rax
movq (%rax), %rax
movl (%rax), %eax
movl %eax, 0x4(%rsi)
rolw $0x8, %r12w
movw %r12w, 0x2(%rsi)
andq $0x0, 0x8(%rsi)
movl 0x38(%rbx), %edi
pushq $0x10
popq %rdx
callq 0x57320
cmpl $-0x1, %eax
je 0x9c911
leaq 0x65205(%rip), %rsi     # 0x1018f5
movq %rsp, %rdi
callq 0x58c40
movq %rsp, %rdi
movq %r15, %rsi
callq 0x573e0
movq %rax, %r15
leaq 0x469c1(%rip), %rsi     # 0xe30ce
leaq 0x18(%rsp), %rdi
callq 0x58c40
leaq 0x18(%rsp), %rsi
movq %r15, %rdi
callq 0x573e0
movq %rax, %r15
movslq %ebp, %rsi
leaq 0x30(%rsp), %rdi
callq 0x57e80
leaq 0x30(%rsp), %rsi
movq %r15, %rdi
callq 0x573e0
movq %rax, %r15
leaq 0x651b3(%rip), %rsi     # 0x1018fe
leaq 0x48(%rsp), %rdi
callq 0x58c40
leaq 0x48(%rsp), %rsi
movq %r15, %rdi
callq 0x573e0
leaq 0x60(%rsp), %rdi
movq %rax, %rsi
callq 0x58280
leaq 0x48(%rsp), %rdi
callq 0x5a588
leaq 0x30(%rsp), %rdi
callq 0x5a588
leaq 0x18(%rsp), %rdi
callq 0x5a588
movq %rsp, %rdi
callq 0x5a588
movq %r14, %rdi
xorl %esi, %esi
callq 0x57d40
testb %al, %al
je 0x9c890
leaq 0x6515b(%rip), %rsi     # 0x101909
movq %rsp, %rdi
callq 0x58c40
leaq 0x60(%rsp), %rdi
movq %rsp, %rsi
callq 0x573e0
movq %rax, %r15
leaq 0x48(%rsp), %rdi
movq %r14, %rsi
callq 0x58280
leaq 0x468f4(%rip), %rsi     # 0xe30ce
leaq 0x90(%rsp), %rdi
callq 0x58c40
leaq 0x48(%rsp), %rdi
leaq 0x90(%rsp), %rsi
callq 0x573e0
movq 0xf0(%rsp), %rsi
movq %rax, %rdi
callq 0x573e0
leaq 0x30(%rsp), %rdi
movq %rax, %rsi
callq 0x58280
leaq 0x18(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x568c0
leaq 0x18(%rsp), %rsi
movq %r15, %rdi
callq 0x573e0
movq %rax, %r14
leaq 0x650eb(%rip), %rsi     # 0x101927
leaq 0x78(%rsp), %rdi
callq 0x58c40
leaq 0x78(%rsp), %rsi
movq %r14, %rdi
callq 0x573e0
leaq 0x78(%rsp), %rdi
callq 0x5a588
leaq 0x18(%rsp), %rdi
callq 0x5a588
leaq 0x30(%rsp), %rdi
callq 0x5a588
leaq 0x90(%rsp), %rdi
callq 0x5a588
leaq 0x48(%rsp), %rdi
callq 0x5a588
movq %rsp, %rdi
callq 0x5a588
leaq 0x65090(%rip), %rsi     # 0x101927
movq %rsp, %rdi
callq 0x58c40
leaq 0x60(%rsp), %rdi
movq %rsp, %rsi
callq 0x573e0
movq %rsp, %rdi
callq 0x5a588
movl 0x38(%rbx), %ebp
leaq 0x60(%rsp), %rdi
callq 0x598d0
movq %rax, %r14
leaq 0x60(%rsp), %rdi
callq 0x58370
movslq %eax, %rdx
movl %ebp, %edi
movq %r14, %rsi
xorl %ecx, %ecx
callq 0x57220
movq %rax, %r14
leaq 0x60(%rsp), %rdi
callq 0x58370
cltq
cmpq %rax, %r14
jge 0x9c926
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x38(%rax)
movl $0x3, 0x18(%rbx)
jmp 0x9ca26
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x38(%rax)
jmp 0x9c91a
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x38(%rax)
movl $0x3, 0x18(%rbx)
jmp 0x9ca30
movq %rsp, %rdi
xorl %esi, %esi
callq 0x5a180
leaq 0x48(%rsp), %r14
andw $0x0, (%r14)
leaq 0x18(%rsp), %r12
movq %rsp, %r13
leaq 0x30(%rsp), %rbp
movq %r12, %rdi
leaq 0x64fd5(%rip), %rsi     # 0x101926
callq 0x58c40
movq %r13, %rdi
movq %r12, %rsi
callq 0x59e50
testb %al, %al
jne 0x9c9cf
movq %rbp, %rdi
leaq 0x658e7(%rip), %rsi     # 0x102256
callq 0x58c40
movq %r13, %rdi
movq %rbp, %rsi
callq 0x59e50
movl %eax, %r15d
movq %rbp, %rdi
callq 0x5a588
movq %r12, %rdi
callq 0x5a588
testb %r15b, %r15b
jne 0x9c9d9
movl 0x38(%rbx), %edi
movq %r14, %rsi
pushq $0x1
popq %rdx
xorl %ecx, %ecx
callq 0x59580
testq %rax, %rax
jle 0x9ca0e
movq %r12, %rdi
movq %r14, %rsi
callq 0x58c40
movq %r13, %rdi
movq %r12, %rsi
callq 0x573e0
movq %r12, %rdi
callq 0x5a588
jmp 0x9c947
leaq 0x18(%rsp), %rdi
callq 0x5a588
leaq 0x18(%rsp), %rdi
movq %rsp, %rsi
pushq $0x9
popq %rdx
pushq $0x3
popq %rcx
callq 0x5a2c0
leaq 0x64f36(%rip), %rsi     # 0x101929
leaq 0x18(%rsp), %rdi
callq 0x5a420
movl %eax, %ebp
leaq 0x18(%rsp), %rdi
callq 0x5a588
testb %bpl, %bpl
je 0x9ca1e
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x38(%rax)
movl $0x3, 0x18(%rbx)
movq %rsp, %rdi
callq 0x5a588
leaq 0x60(%rsp), %rdi
callq 0x5a588
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x9cb21
jmp 0x9cb12
jmp 0x9cb21
jmp 0x9cb0d
movq %rax, %r14
leaq 0x78(%rsp), %rdi
callq 0x5a588
jmp 0x9ca6a
jmp 0x9ca67
movq %rax, %r14
leaq 0x18(%rsp), %rdi
callq 0x5a588
jmp 0x9ca79
movq %rax, %r14
leaq 0x30(%rsp), %rdi
callq 0x5a588
jmp 0x9caba
movq %rax, %r14
jmp 0x9cac7
jmp 0x9cb21
jmp 0x9cb21
jmp 0x9cb0d
jmp 0x9cb21
jmp 0x9cb0d
jmp 0x9ca9f
movq %rax, %r14
jmp 0x9cadb
jmp 0x9caa6
movq %rax, %r14
jmp 0x9cae5
jmp 0x9caad
movq %rax, %r14
jmp 0x9caef
jmp 0x9cb3a
movq %rax, %r14
leaq 0x90(%rsp), %rdi
callq 0x5a588
leaq 0x48(%rsp), %rdi
jmp 0x9cb1a
movq %rax, %r14
leaq 0x48(%rsp), %rdi
callq 0x5a588
leaq 0x30(%rsp), %rdi
callq 0x5a588
leaq 0x18(%rsp), %rdi
callq 0x5a588
movq %rsp, %rdi
jmp 0x9cb31
jmp 0x9cb3a
jmp 0x9cb21
jmp 0x9cb12
jmp 0x9cb21
movq %rax, %r14
leaq 0x30(%rsp), %rdi
callq 0x5a588
jmp 0x9cb15
jmp 0x9cb12
movq %rax, %r14
jmp 0x9cb2c
movq %rax, %r14
leaq 0x18(%rsp), %rdi
callq 0x5a588
jmp 0x9cb24
movq %rax, %r14
movq %rsp, %rdi
callq 0x5a588
leaq 0x60(%rsp), %rdi
callq 0x5a588
jmp 0x9cb3d
jmp 0x9cb3a
movq %rax, %r14
movq %rbx, %rdi
callq 0x57db0
movq %r14, %rdi
callq 0x58260
nop