// File: 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
movq %rsp, %rbp
subq $0x9e0, %rsp            # imm = 0x9E0
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x8e8(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x4055b0
movq -0x10(%rbp), %rdi
movq (%rdi), %rax
movq 0x20(%rax), %rax
xorl %ecx, %ecx
movl %ecx, %esi
callq *%rax
jmp 0x40a89a
movq $0x0, -0x78(%rbp)
movq $0x0, -0x80(%rbp)
movb $0x1, -0x81(%rbp)
testb $0x1, -0x81(%rbp)
je 0x40acfd
movq -0x80(%rbp), %rax
incq %rax
movq %rax, -0x80(%rbp)
movq -0x10(%rbp), %rdi
movq -0x80(%rbp), %rsi
movq (%rdi), %rax
movq 0x20(%rax), %rax
callq *%rax
jmp 0x40a8dc
movq -0x10(%rbp), %rdi
callq 0x410000
movb %al, -0x8e9(%rbp)
jmp 0x40a8ed
movb -0x8e9(%rbp), %al
movb %al, -0x82(%rbp)
movsbl -0x82(%rbp), %eax
cmpl $0xd, %eax
je 0x40a940
movq -0x80(%rbp), %rax
incq %rax
movq %rax, -0x900(%rbp)
movq -0x10(%rbp), %rdi
movq (%rdi), %rax
movq 0x38(%rax), %rax
callq *%rax
movq %rax, -0x8f8(%rbp)
jmp 0x40a929
movq -0x900(%rbp), %rax
movq -0x8f8(%rbp), %rcx
cmpq %rcx, %rax
jne 0x40acf8
movq -0x80(%rbp), %rax
subq -0x78(%rbp), %rax
movq %rax, -0x90(%rbp)
cmpq $0x0, -0x90(%rbp)
jne 0x40a976
movb $0x0, -0x81(%rbp)
jmp 0x40a8b1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x40b3bd
movq -0x90(%rbp), %rdi
addq $0x1, %rdi
callq 0x51a280
movq %rax, -0x98(%rbp)
cmpq $0x0, -0x98(%rbp)
jne 0x40ab42
movq $0x668b40, %rdi         # imm = 0x668B40
leaq 0x1d0877(%rip), %rsi    # 0x5db220
callq 0x49dd60
movq %rax, -0x908(%rbp)
jmp 0x40a9b7
movb $0x0, -0x111(%rbp)
movb $0x0, -0x113(%rbp)
movb $0x1, %al
testb $0x1, %al
jne 0x40a9cd
jmp 0x40aa0b
movq -0x8e8(%rbp), %rsi
movq (%rsi), %rax
movq 0x8(%rax), %rax
leaq -0x110(%rbp), %rdi
callq *%rax
jmp 0x40a9e6
movb $0x1, -0x111(%rbp)
leaq -0xd8(%rbp), %rsi
leaq 0x1d0c75(%rip), %rdx    # 0x5db670
leaq -0xb8(%rbp), %rdi
callq 0x405d00
jmp 0x40aa09
jmp 0x40aa43
leaq -0x112(%rbp), %rdi
movq %rdi, -0x910(%rbp)
callq 0x435b90
movq -0x910(%rbp), %rdx
movb $0x1, -0x113(%rbp)
leaq 0x1f5f6f(%rip), %rsi    # 0x6009a2
leaq -0xb8(%rbp), %rdi
callq 0x407e60
jmp 0x40aa41
jmp 0x40aa43
movq -0x908(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
callq 0x4b05e0
movq %rax, -0x918(%rbp)
jmp 0x40aa5f
movq -0x918(%rbp), %rdi
leaq 0x1d0663(%rip), %rsi    # 0x5db0d0
callq 0x49dd60
movq %rax, -0x920(%rbp)
jmp 0x40aa7b
movq -0x920(%rbp), %rdi
movq $0x49d640, %rsi         # imm = 0x49D640
callq 0x49c850
jmp 0x40aa90
leaq -0xb8(%rbp), %rdi
callq 0x4adc60
testb $0x1, -0x113(%rbp)
jne 0x40aaa7
jmp 0x40aab3
leaq -0x112(%rbp), %rdi
callq 0x435bb0
testb $0x1, -0x111(%rbp)
jne 0x40aabe
jmp 0x40aaca
leaq -0x110(%rbp), %rdi
callq 0x405650
movl $0x1, -0x118(%rbp)
jmp 0x40b36d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x40ab26
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x40ab0d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x4adc60
testb $0x1, -0x113(%rbp)
jne 0x40ab18
jmp 0x40ab24
leaq -0x112(%rbp), %rdi
callq 0x435bb0
jmp 0x40ab26
testb $0x1, -0x111(%rbp)
jne 0x40ab31
jmp 0x40ab3d
leaq -0x110(%rbp), %rdi
callq 0x405650
jmp 0x40b3bd
movq -0x10(%rbp), %rdi
movq -0x78(%rbp), %rsi
movq (%rdi), %rax
movq 0x20(%rax), %rax
callq *%rax
jmp 0x40ab55
movq -0x10(%rbp), %rdi
movq -0x98(%rbp), %rsi
movq -0x90(%rbp), %rdx
xorl %eax, %eax
movl %eax, %ecx
callq 0x40ff80
jmp 0x40ab72
movq -0x98(%rbp), %rax
movq -0x90(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movq -0x98(%rbp), %rsi
leaq -0x170(%rbp), %rdi
callq 0x417c40
jmp 0x40ab99
leaq 0x1d0aef(%rip), %rsi    # 0x5db68f
leaq -0x1c8(%rbp), %rdi
callq 0x417c40
jmp 0x40abae
leaq 0x1d9853(%rip), %rsi    # 0x5e4408
leaq -0x220(%rbp), %rdi
callq 0x417c40
jmp 0x40abc3
leaq -0x170(%rbp), %rdi
leaq -0x1c8(%rbp), %rsi
leaq -0x220(%rbp), %rdx
callq 0x4185f0
jmp 0x40abdf
leaq -0x220(%rbp), %rdi
callq 0x405650
leaq -0x1c8(%rbp), %rdi
callq 0x405650
leaq -0x278(%rbp), %rdi
leaq -0x170(%rbp), %rsi
callq 0x417f20
jmp 0x40ac0c
leaq -0x60(%rbp), %rdi
leaq -0x278(%rbp), %rsi
callq 0x40b430
jmp 0x40ac1e
leaq -0x278(%rbp), %rdi
callq 0x405650
movq -0x98(%rbp), %rdi
callq 0x51a5c0
movq -0x80(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rax
movq %rax, -0x930(%rbp)
movq -0x10(%rbp), %rdi
movq (%rdi), %rax
movq 0x38(%rax), %rax
callq *%rax
movq %rax, -0x928(%rbp)
jmp 0x40ac63
movq -0x930(%rbp), %rax
movq -0x928(%rbp), %rcx
cmpq %rcx, %rax
setl %al
andb $0x1, %al
movb %al, -0x81(%rbp)
leaq -0x170(%rbp), %rdi
callq 0x405650
jmp 0x40acf8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x40ace7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x40acc1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x220(%rbp), %rdi
callq 0x405650
leaq -0x1c8(%rbp), %rdi
callq 0x405650
jmp 0x40ace7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x278(%rbp), %rdi
callq 0x405650
leaq -0x170(%rbp), %rdi
callq 0x405650
jmp 0x40b3bd
jmp 0x40a8b1
movq $0x668c60, %rdi         # imm = 0x668C60
leaq 0x1d0386(%rip), %rsi    # 0x5db091
callq 0x49dd60
movq %rax, -0x938(%rbp)
jmp 0x40ad19
movq -0x938(%rbp), %rdi
leaq 0x1f5c7b(%rip), %rsi    # 0x6009a2
callq 0x49dd60
movq %rax, -0x940(%rbp)
jmp 0x40ad35
movq -0x940(%rbp), %rdi
leaq 0x1d038d(%rip), %rsi    # 0x5db0d0
callq 0x49dd60
movq %rax, -0x948(%rbp)
jmp 0x40ad51
movq -0x948(%rbp), %rdi
movq $0x49d640, %rsi         # imm = 0x49D640
callq 0x49c850
jmp 0x40ad66
movq $0x0, -0x280(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x40b460
movq %rax, -0x950(%rbp)
jmp 0x40ad83
movq -0x950(%rbp), %rax
movq %rax, -0x288(%rbp)
movq -0x280(%rbp), %rax
cmpq -0x288(%rbp), %rax
jge 0x40ae88
movq $0x668c60, %rdi         # imm = 0x668C60
leaq 0x1d02de(%rip), %rsi    # 0x5db091
callq 0x49dd60
movq %rax, -0x958(%rbp)
jmp 0x40adc1
movb $0x1, %al
testb $0x1, %al
jne 0x40adc9
jmp 0x40ade4
movq -0x280(%rbp), %rdx
leaq -0x2e0(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x40b480
jmp 0x40ade2
jmp 0x40adfb
leaq 0x1f5bb7(%rip), %rsi    # 0x6009a2
leaq -0x2e0(%rbp), %rdi
callq 0x417c40
jmp 0x40adf9
jmp 0x40adfb
movq -0x958(%rbp), %rdi
leaq -0x2a8(%rbp), %rsi
callq 0x4b05e0
movq %rax, -0x960(%rbp)
jmp 0x40ae17
movq -0x960(%rbp), %rdi
leaq 0x1d02ab(%rip), %rsi    # 0x5db0d0
callq 0x49dd60
movq %rax, -0x968(%rbp)
jmp 0x40ae33
movq -0x968(%rbp), %rdi
movq $0x49d640, %rsi         # imm = 0x49D640
callq 0x49c850
jmp 0x40ae48
leaq -0x2e0(%rbp), %rdi
callq 0x405650
movq -0x280(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x280(%rbp)
jmp 0x40ad91
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x2e0(%rbp), %rdi
callq 0x405650
jmp 0x40b3bd
movq $0x668c60, %rdi         # imm = 0x668C60
leaq 0x1d01fb(%rip), %rsi    # 0x5db091
callq 0x49dd60
movq %rax, -0x970(%rbp)
jmp 0x40aea4
movq -0x970(%rbp), %rdi
leaq 0x1f5af0(%rip), %rsi    # 0x6009a2
callq 0x49dd60
movq %rax, -0x978(%rbp)
jmp 0x40aec0
movq -0x978(%rbp), %rdi
leaq 0x1d0202(%rip), %rsi    # 0x5db0d0
callq 0x49dd60
movq %rax, -0x980(%rbp)
jmp 0x40aedc
movq -0x980(%rbp), %rdi
movq $0x49d640, %rsi         # imm = 0x49D640
callq 0x49c850
jmp 0x40aef1
xorl %eax, %eax
movl %eax, %edx
leaq -0x340(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x40b480
jmp 0x40af07
leaq 0x1d1a80(%rip), %rsi    # 0x5dc98e
leaq -0x398(%rbp), %rdi
callq 0x417c40
jmp 0x40af1c
leaq -0x340(%rbp), %rdi
leaq -0x398(%rbp), %rsi
callq 0x418680
movq %rax, -0x988(%rbp)
jmp 0x40af38
leaq -0x398(%rbp), %rdi
callq 0x405650
leaq -0x340(%rbp), %rdi
callq 0x405650
movq -0x988(%rbp), %rax
movq %rax, -0x2e8(%rbp)
movq -0x2e8(%rbp), %rdi
callq 0x40b460
movq %rax, -0x990(%rbp)
jmp 0x40af73
movq -0x990(%rbp), %rax
cmpq $0x2, %rax
jge 0x40b1e6
movq $0x668b40, %rdi         # imm = 0x668B40
leaq 0x1d028e(%rip), %rsi    # 0x5db220
callq 0x49dd60
movq %rax, -0x998(%rbp)
jmp 0x40afa0
movb $0x0, -0x411(%rbp)
movb $0x0, -0x413(%rbp)
movb $0x1, %al
testb $0x1, %al
jne 0x40afb6
jmp 0x40aff4
movq -0x8e8(%rbp), %rsi
movq (%rsi), %rax
movq 0x8(%rax), %rax
leaq -0x410(%rbp), %rdi
callq *%rax
jmp 0x40afcf
movb $0x1, -0x411(%rbp)
leaq -0x3d8(%rbp), %rsi
leaq 0x1d06e8(%rip), %rdx    # 0x5db6cc
leaq -0x3b8(%rbp), %rdi
callq 0x405d00
jmp 0x40aff2
jmp 0x40b02c
leaq -0x412(%rbp), %rdi
movq %rdi, -0x9a0(%rbp)
callq 0x435b90
movq -0x9a0(%rbp), %rdx
movb $0x1, -0x413(%rbp)
leaq 0x1f5986(%rip), %rsi    # 0x6009a2
leaq -0x3b8(%rbp), %rdi
callq 0x407e60
jmp 0x40b02a
jmp 0x40b02c
movq -0x998(%rbp), %rdi
leaq -0x3b8(%rbp), %rsi
callq 0x4b05e0
movq %rax, -0x9a8(%rbp)
jmp 0x40b048
movq -0x9a8(%rbp), %rdi
leaq 0x1d007a(%rip), %rsi    # 0x5db0d0
callq 0x49dd60
movq %rax, -0x9b0(%rbp)
jmp 0x40b064
movq -0x9b0(%rbp), %rdi
movq $0x49d640, %rsi         # imm = 0x49D640
callq 0x49c850
jmp 0x40b079
leaq -0x3b8(%rbp), %rdi
callq 0x4adc60
testb $0x1, -0x413(%rbp)
jne 0x40b090
jmp 0x40b09c
leaq -0x412(%rbp), %rdi
callq 0x435bb0
testb $0x1, -0x411(%rbp)
jne 0x40b0a7
jmp 0x40b0b3
leaq -0x410(%rbp), %rdi
callq 0x405650
movq $0x667c28, %rsi         # imm = 0x667C28
leaq -0x4d0(%rbp), %rdi
callq 0x41fd30
jmp 0x40b0c8
movq -0x8e8(%rbp), %rdi
leaq -0x4d0(%rbp), %rsi
callq 0x412820
jmp 0x40b0dd
movq -0x2e8(%rbp), %rax
movq %rax, -0x9b8(%rbp)
cmpq $0x0, %rax
je 0x40b10e
movq -0x9b8(%rbp), %rdi
callq 0x405700
movq -0x9b8(%rbp), %rdi
movl $0x50, %esi
callq 0x433cf0
movl $0x1, -0x118(%rbp)
leaq -0x4d0(%rbp), %rdi
callq 0x41fee0
jmp 0x40b36d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x40b14f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x398(%rbp), %rdi
callq 0x405650
leaq -0x340(%rbp), %rdi
callq 0x405650
jmp 0x40b3bd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x40b1ad
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x40b194
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x3b8(%rbp), %rdi
callq 0x4adc60
testb $0x1, -0x413(%rbp)
jne 0x40b19f
jmp 0x40b1ab
leaq -0x412(%rbp), %rdi
callq 0x435bb0
jmp 0x40b1ad
testb $0x1, -0x411(%rbp)
jne 0x40b1b8
jmp 0x40b1c4
leaq -0x410(%rbp), %rdi
callq 0x405650
jmp 0x40b3bd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x4d0(%rbp), %rdi
callq 0x41fee0
jmp 0x40b3bd
leaq -0x610(%rbp), %rdi
callq 0x40b4d0
jmp 0x40b1f4
movq -0x2e8(%rbp), %rdi
addq $0x38, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x40b580
movq %rax, -0x9c0(%rbp)
jmp 0x40b211
movq -0x9c0(%rbp), %rsi
leaq -0x5d8(%rbp), %rdi
callq 0x4180d0
jmp 0x40b226
movq -0x2e8(%rbp), %rdi
addq $0x38, %rdi
movl $0x1, %esi
callq 0x40b580
movq %rax, -0x9c8(%rbp)
jmp 0x40b244
movq -0x9c8(%rbp), %rsi
leaq -0x580(%rbp), %rdi
callq 0x4180d0
jmp 0x40b259
movq -0x2e8(%rbp), %rdi
callq 0x40b460
movq %rax, -0x9d0(%rbp)
jmp 0x40b26e
movq -0x9d0(%rbp), %rax
cmpq $0x2, %rax
jle 0x40b2c1
movq -0x2e8(%rbp), %rdi
addq $0x38, %rdi
movl $0x2, %esi
callq 0x40b580
movq %rax, -0x9d8(%rbp)
jmp 0x40b299
movq -0x9d8(%rbp), %rsi
leaq -0x528(%rbp), %rdi
callq 0x4180d0
jmp 0x40b2ae
jmp 0x40b2c1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x40b3b1
movq -0x2e8(%rbp), %rax
movq %rax, -0x9e0(%rbp)
cmpq $0x0, %rax
je 0x40b2f2
movq -0x9e0(%rbp), %rdi
callq 0x405700
movq -0x9e0(%rbp), %rdi
movl $0x50, %esi
callq 0x433cf0
leaq -0x8e0(%rbp), %rdi
leaq -0x610(%rbp), %rsi
callq 0x40b5c0
jmp 0x40b307
movq -0x8e8(%rbp), %rdx
movq $0x667890, %rsi         # imm = 0x667890
leaq -0x7a0(%rbp), %rdi
leaq -0x8e0(%rbp), %rcx
callq 0x40bb60
jmp 0x40b32a
leaq -0x8e0(%rbp), %rdi
callq 0x40b6a0
movq -0x8e8(%rbp), %rdi
leaq -0x7a0(%rbp), %rsi
callq 0x412820
jmp 0x40b34b
leaq -0x7a0(%rbp), %rdi
callq 0x40bbd0
leaq -0x610(%rbp), %rdi
callq 0x40b6a0
movl $0x0, -0x118(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x405700
addq $0x9e0, %rsp            # imm = 0x9E0
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x8e0(%rbp), %rdi
callq 0x40b6a0
jmp 0x40b3b1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x7a0(%rbp), %rdi
callq 0x40bbd0
leaq -0x610(%rbp), %rdi
callq 0x40b6a0
leaq -0x60(%rbp), %rdi
callq 0x405700
movq -0x68(%rbp), %rdi
callq 0x4deb40
nop