// File: /workspace/github_cpp_makefile_star2_O2/enbock[P]Warp10Server/warp10server/src/Network/WebConnection.cpp
// Function: Warp10::Network::WebConnection::decodeBuffer(u::ByteArray*)
void WebConnection::decodeBuffer(ByteArray* buffer)
{
	Vector<String> header;
	buffer->position(0);
	int64 startPosition = 0, position = 0;
	bool continueRead = true;
	// read header
	while (continueRead) {
		position++;
		buffer->position(position);
		char byte = buffer->readByte();
		if (byte == 0x0D || position + 1 == buffer->length()) {
			int64 length = position - startPosition ;
			if (length == 0) {
				// end of header
				continueRead = false;
				continue;
			}
			char* line = (char*)malloc(length + 1);
			if (!line) {
				error(
					className() + "::decodeBuffer: Out of memory."
				);
				return;
			}
			buffer->position(startPosition);
			buffer->readBytes(line, length, 0);
			line[length] = 0x00; // end byte
			String headerLine = String(line);
			headerLine.replace("\r", "_");
			header.push(headerLine);
			free(line);
			startPosition = position + 2;
			continueRead = startPosition < buffer->length();
		}
	}

#ifndef NDEBUG
	trace("");
	for(int64 i = 0, l = header.length(); i < l; i++) trace(header[i]);
	trace("");
#endif

	Vector<String>* commandParts = ((String)header[0]).explode(" ");

	if (commandParts->length() < 2) {
		error(className() + "::decodeBuffer: Invalid request.");
		
		u::Network::Event close(u::Network::Event::CLOSE);
		dispatchEvent(&close);
		delete commandParts;
		return;
	}
	
	WebRequest request;
	request.method = commandParts->at(0);
	request.resource = commandParts->at(1);
	if(commandParts->length() > 2)
		request.protocol = commandParts->at(2);
	delete commandParts;

	WebEvent requestEvent(WebEvent::REQUEST, this, request);
	dispatchEvent(&requestEvent);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x5d8, %rsp            # imm = 0x5D8
movq %rsi, %rbx
movq %rdi, (%rsp)
leaq 0x18(%rsp), %rdi
callq 0x4050a6
movq (%rbx), %rax
movq %rbx, %rdi
xorl %esi, %esi
callq *0x20(%rax)
movb $0x1, %r14b
pushq $0x1
popq %rsi
movq $0x0, 0x8(%rsp)
leaq 0x440(%rsp), %rbp
leaq 0x3e8(%rsp), %r12
movq %rbx, 0x10(%rsp)
testb $0x1, %r14b
je 0x407367
movq (%rbx), %rax
movq %rbx, %rdi
movq %rsi, %r15
callq *0x20(%rax)
movq %rbx, %rdi
callq 0x4096b0
cmpb $0xd, %al
je 0x407250
movq 0x10(%rsp), %rdi
movq (%rdi), %rax
callq *0x38(%rax)
leaq 0x1(%r15), %rcx
movb $0x1, %r14b
cmpq %rax, %rcx
jne 0x407357
movq %r15, %r13
subq 0x8(%rsp), %r13
jne 0x407265
movq %r15, %rsi
xorl %r14d, %r14d
jmp 0x40735a
leaq 0x1(%r13), %rdi
callq 0x506090
testq %rax, %rax
je 0x407679
movq %rax, %r14
movq 0x10(%rsp), %rbx
movq (%rbx), %rax
movq %rbx, %rdi
movq 0x8(%rsp), %rsi
callq *0x20(%rax)
movq %rbx, %rdi
movq %r14, %rsi
movq %r13, %rdx
xorl %ecx, %ecx
callq 0x40966e
movq %r14, %rax
subq 0x8(%rsp), %rax
movb $0x0, (%rax,%r15)
leaq 0x68(%rsp), %rdi
movq %r14, %rsi
callq 0x40c908
leaq 0x390(%rsp), %rdi
leaq 0x1c00df(%rip), %rsi    # 0x5c73a5
callq 0x40c908
movq %rbp, %r13
movq %rbp, %rdi
leaq 0x1c8550(%rip), %rsi    # 0x5cf828
callq 0x40c908
leaq 0x68(%rsp), %rdi
leaq 0x390(%rsp), %rbx
movq %rbx, %rsi
movq %r13, %rdx
callq 0x40ceb4
movq %r13, %rdi
callq 0x4050e8
movq %rbx, %rdi
callq 0x4050e8
movq %r12, %rdi
leaq 0x68(%rsp), %rsi
callq 0x40cb38
leaq 0x50(%rsp), %rdi
movq %r12, %rbx
movq %r12, %rsi
callq 0x407998
movq %rbx, %rdi
callq 0x4050e8
movq %r14, %rdi
callq 0x5063d0
movq 0x10(%rsp), %rdi
movq (%rdi), %rax
callq *0x38(%rax)
leaq 0x2(%r15), %rdx
movq %rdx, 0x8(%rsp)
cmpq %rax, %rdx
setl %r14b
leaq 0x68(%rsp), %rdi
callq 0x4050e8
movq %r15, %rsi
incq %rsi
movq 0x10(%rsp), %rbx
jmp 0x407213
movq $0x64ec20, %rdi         # imm = 0x64EC20
leaq 0x1bfd1c(%rip), %rsi    # 0x5c7091
callq 0x489b70
leaq 0x1e4a41(%rip), %rsi    # 0x5ebdc2
movq %rax, %rdi
callq 0x489b70
leaq 0x1bfd1b(%rip), %rsi    # 0x5c70ab
movq %rax, %rdi
callq 0x489b70
movq %rax, %rdi
callq 0x489450
leaq 0x18(%rsp), %rcx
movq 0x40(%rcx), %rax
subq 0x38(%rcx), %rax
pushq $0x58
popq %rcx
cqto
idivq %rcx
movq %rax, %r14
xorl %r12d, %r12d
testq %rax, %rax
cmovleq %r12, %r14
leaq 0x1bfcc8(%rip), %rbp    # 0x5c7091
leaq 0x68(%rsp), %rbx
leaq 0x1bfcd6(%rip), %r15    # 0x5c70ab
cmpq %r12, %r14
je 0x40742c
movq $0x64ec20, %rdi         # imm = 0x64EC20
movq %rbp, %rsi
callq 0x489b70
movq %rax, %r13
movq %rbx, %rdi
leaq 0x18(%rsp), %rsi
movq %r12, %rdx
callq 0x40781a
movq %r13, %rdi
leaq 0xa0(%rsp), %rsi
callq 0x49c3f0
movq %rax, %rdi
movq %r15, %rsi
callq 0x489b70
movq %rax, %rdi
callq 0x489450
movq %rbx, %rdi
callq 0x4050e8
incq %r12
jmp 0x4073d5
movq $0x64ec20, %rdi         # imm = 0x64EC20
leaq 0x1bfc57(%rip), %rsi    # 0x5c7091
callq 0x489b70
leaq 0x1e497c(%rip), %rsi    # 0x5ebdc2
movq %rax, %rdi
callq 0x489b70
leaq 0x1bfc56(%rip), %rsi    # 0x5c70ab
movq %rax, %rdi
callq 0x489b70
movq %rax, %rdi
callq 0x489450
leaq 0x68(%rsp), %rdi
leaq 0x18(%rsp), %rsi
xorl %edx, %edx
callq 0x40781a
leaq 0x1c0a27(%rip), %rsi    # 0x5c7ea4
leaq 0x338(%rsp), %rdi
callq 0x40c908
leaq 0x68(%rsp), %rdi
leaq 0x338(%rsp), %rsi
callq 0x40cf12
movq %rax, %r14
leaq 0x338(%rsp), %rdi
callq 0x4050e8
leaq 0x68(%rsp), %rdi
callq 0x4050e8
movq 0x40(%r14), %rax
subq 0x38(%r14), %rax
cmpq $0xaf, %rax
jg 0x40758a
movq $0x64eb00, %rdi         # imm = 0x64EB00
leaq 0x1bfc7b(%rip), %rsi    # 0x5c7153
callq 0x489b70
movq %rax, %rbx
movq (%rsp), %rsi
movq (%rsi), %rax
leaq 0x68(%rsp), %rdi
callq *0x8(%rax)
leaq 0xa0(%rsp), %rsi
leaq 0x1bfea9(%rip), %rdx    # 0x5c73a7
leaq 0x1f8(%rsp), %rdi
callq 0x405349
leaq 0x1f8(%rsp), %rsi
movq %rbx, %rdi
callq 0x49c3f0
leaq 0x1bfb89(%rip), %rsi    # 0x5c70ab
movq %rax, %rdi
callq 0x489b70
movq %rax, %rdi
callq 0x489450
leaq 0x1f8(%rsp), %rdi
callq 0x499a70
leaq 0x68(%rsp), %rdi
callq 0x4050e8
movq $0x64dbe8, %rsi         # imm = 0x64DBE8
leaq 0x68(%rsp), %rdi
callq 0x40ffe2
leaq 0x68(%rsp), %rsi
movq (%rsp), %rdi
callq 0x40ad2c
movq %r14, %rdi
callq 0x405148
pushq $0x50
popq %rsi
movq %r14, %rdi
callq 0x41fb60
leaq 0x68(%rsp), %rdi
callq 0x4100e2
jmp 0x4076f8
leaq 0x1f8(%rsp), %rdi
callq 0x40783a
movq %r14, %rbx
addq $0x38, %rbx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x4078b4
leaq 0x230(%rsp), %rdi
movq %rax, %rsi
callq 0x40cbf6
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0x4078b4
leaq 0x288(%rsp), %rdi
movq %rax, %rsi
callq 0x40cbf6
movq 0x40(%r14), %rax
subq 0x38(%r14), %rax
cmpq $0xb1, %rax
jl 0x4075fe
pushq $0x2
popq %rsi
movq %rbx, %rdi
callq 0x4078b4
leaq 0x2e0(%rsp), %rdi
movq %rax, %rsi
callq 0x40cbf6
movq %r14, %rdi
callq 0x405148
pushq $0x50
popq %rsi
movq %r14, %rdi
callq 0x41fb60
leaq 0x498(%rsp), %rdi
leaq 0x1f8(%rsp), %rsi
callq 0x4078d2
movq $0x64d850, %rsi         # imm = 0x64D850
leaq 0x68(%rsp), %rdi
leaq 0x498(%rsp), %rcx
movq (%rsp), %rbx
movq %rbx, %rdx
callq 0x407b52
leaq 0x498(%rsp), %rdi
callq 0x407960
leaq 0x68(%rsp), %rsi
movq %rbx, %rdi
callq 0x40ad2c
leaq 0x68(%rsp), %rdi
callq 0x407b88
leaq 0x1f8(%rsp), %rdi
callq 0x407960
jmp 0x4076f8
movq $0x64eb00, %rdi         # imm = 0x64EB00
leaq 0x1bfacc(%rip), %rsi    # 0x5c7153
callq 0x489b70
movq %rax, %rbx
movq (%rsp), %rsi
movq (%rsi), %rax
leaq 0x68(%rsp), %rdi
callq *0x8(%rax)
leaq 0x1bfce1(%rip), %rdx    # 0x5c7386
leaq 0x1f8(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
callq 0x405349
leaq 0x1f8(%rsp), %rsi
movq %rbx, %rdi
callq 0x49c3f0
leaq 0x1bf9da(%rip), %rsi    # 0x5c70ab
movq %rax, %rdi
callq 0x489b70
movq %rax, %rdi
callq 0x489450
leaq 0x1f8(%rsp), %rdi
callq 0x499a70
leaq 0x68(%rsp), %rdi
callq 0x4050e8
leaq 0x18(%rsp), %rdi
callq 0x405148
addq $0x5d8, %rsp            # imm = 0x5D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x4077e5
jmp 0x4077e0
jmp 0x4077e0
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
callq 0x407b88
jmp 0x407792
movq %rax, %rbx
leaq 0x498(%rsp), %rdi
callq 0x407960
jmp 0x407792
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
callq 0x4100e2
jmp 0x4077f2
jmp 0x40778f
jmp 0x4077e0
jmp 0x4077e5
jmp 0x4077e0
jmp 0x4077e0
jmp 0x4077e0
movq %rax, %rbx
leaq 0x338(%rsp), %rdi
jmp 0x4077cf
jmp 0x4077e5
jmp 0x4077e0
jmp 0x40777d
jmp 0x4077e0
movq %rax, %rbx
leaq 0x1f8(%rsp), %rdi
callq 0x499a70
jmp 0x4077e8
movq %rax, %rbx
leaq 0x1f8(%rsp), %rdi
callq 0x407960
jmp 0x4077f2
jmp 0x4077e0
jmp 0x4077e0
movq %rax, %rbx
jmp 0x4077ba
movq %rax, %rbx
leaq 0x440(%rsp), %rdi
callq 0x4050e8
leaq 0x390(%rsp), %rdi
jmp 0x4077cf
movq %rax, %rbx
leaq 0x3e8(%rsp), %rdi
callq 0x4050e8
jmp 0x4077e8
jmp 0x4077e0
jmp 0x4077e0
jmp 0x4077e0
jmp 0x4077e0
jmp 0x4077e5
movq %rax, %rbx
jmp 0x4077f2
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
callq 0x4050e8
leaq 0x18(%rsp), %rdi
callq 0x405148
movq %rbx, %rdi
callq 0x4ca950