// File: luigix25[P]SSLP/client_files/client.cpp
// Function: cmd_upload()
bool cmd_upload(){
	string filename;
	cin >> setw(MAX_FILENAME_LENGTH) >> filename;

	//clears the overflow, if any
	pulisci_buff();

	string path(CLIENT_PATH);
	fstream tmp(path + filename);
	if(!tmp.good()){
		cout << "File Does not exists!" << endl;
		return true;								//not a protocol error
	}
	/*else {
		//cout << "il file esiste" << endl;
	}*/

	if(!send_command(UPLOAD_COMMAND)) return false;

	EncryptManager em;
	Chunk c;
	c.setPlainText((char*)filename.c_str(),false);		//i don't need to free memory
	c.size = filename.size()+1;							//fine stringa

	EncryptedChunk ec;

	if(!em.EncryptUpdate(ec,c)) return false;
	if(!em.EncryptFinal(ec))	return false;


	if(!sendDataHMAC(server_socket,ec.getCipherText(),ec.size)) return false;
	
	if(!SendFile(path,server_socket,filename,CLIENT_PRIVKEY_PATH,true)){
		cout << "[ERROR] sendFile failed" << endl;
		return false;
	}
	else {
		cout << "[LOG] sendFile correct" << endl;
		return true;
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x330, %rsp            # imm = 0x330
leaq -0x28(%rbp), %rdi
callq 0x4780
movl $0x64, %edi
callq 0x7830
movl %eax, -0x2dc(%rbp)
jmp 0x5946
movl -0x2dc(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %esi
movq 0xd677(%rip), %rdi      # 0x12fd0
callq 0x44d0
movq %rax, -0x2e8(%rbp)
jmp 0x5967
movq -0x2e8(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x46b0
jmp 0x5979
callq 0x50b0
jmp 0x5980
leaq -0x61(%rbp), %rdi
movq %rdi, -0x2f0(%rbp)
callq 0x4910
movq -0x2f0(%rbp), %rdx
leaq 0x87e5(%rip), %rsi      # 0xe183
leaq -0x60(%rbp), %rdi
callq 0x76e0
jmp 0x59a9
leaq -0x61(%rbp), %rdi
callq 0x4530
leaq -0x298(%rbp), %rdi
leaq -0x60(%rbp), %rsi
leaq -0x28(%rbp), %rdx
callq 0x7850
jmp 0x59c8
movl $0x8, %edi
movl $0x10, %esi
callq 0x78d0
movl %eax, -0x2f4(%rbp)
jmp 0x59df
movl -0x2f4(%rbp), %edx
leaq -0x278(%rbp), %rdi
leaq -0x298(%rbp), %rsi
callq 0x4870
jmp 0x59fa
leaq -0x298(%rbp), %rdi
callq 0x42b0
movq -0x278(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x278(%rbp,%rax), %rdi
callq 0x4890
movb %al, -0x2f5(%rbp)
jmp 0x5a26
movb -0x2f5(%rbp), %al
testb $0x1, %al
jne 0x5ae4
jmp 0x5a36
movq 0xd57b(%rip), %rdi      # 0x12fb8
leaq 0x8756(%rip), %rsi      # 0xe19a
callq 0x44a0
movq %rax, -0x300(%rbp)
jmp 0x5a52
movq -0x300(%rbp), %rdi
movq 0xd548(%rip), %rsi      # 0x12fa8
callq 0x4500
jmp 0x5a67
movb $0x1, -0x1(%rbp)
movl $0x1, -0x29c(%rbp)
jmp 0x5d70
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x5db1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x61(%rbp), %rdi
callq 0x4530
jmp 0x5db1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x5da8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x298(%rbp), %rdi
callq 0x42b0
jmp 0x5da8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x5d9c
movl $0x3, %edi
callq 0x5290
movb %al, -0x301(%rbp)
jmp 0x5af6
movb -0x301(%rbp), %al
testb $0x1, %al
jne 0x5b15
jmp 0x5b02
movb $0x0, -0x1(%rbp)
movl $0x1, -0x29c(%rbp)
jmp 0x5d70
leaq -0x2a8(%rbp), %rdi
callq 0xa300
jmp 0x5b23
leaq -0x2c0(%rbp), %rdi
callq 0xd6b0
jmp 0x5b31
leaq -0x28(%rbp), %rdi
callq 0x41e0
movq %rax, %rsi
leaq -0x2c0(%rbp), %rdi
xorl %edx, %edx
callq 0xd7a0
jmp 0x5b4d
leaq -0x28(%rbp), %rdi
callq 0x4350
incl %eax
movl %eax, -0x2b0(%rbp)
leaq -0x2d8(%rbp), %rdi
callq 0xd860
jmp 0x5b6c
leaq -0x2a8(%rbp), %rdi
leaq -0x2d8(%rbp), %rsi
leaq -0x2c0(%rbp), %rdx
callq 0xa490
movb %al, -0x302(%rbp)
jmp 0x5b8e
movb -0x302(%rbp), %al
testb $0x1, %al
jne 0x5bec
jmp 0x5b9a
movb $0x0, -0x1(%rbp)
movl $0x1, -0x29c(%rbp)
jmp 0x5d30
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x5d62
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x5d56
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x2d8(%rbp), %rdi
callq 0xd880
jmp 0x5d56
leaq -0x2a8(%rbp), %rdi
leaq -0x2d8(%rbp), %rsi
callq 0xa550
movb %al, -0x303(%rbp)
jmp 0x5c07
movb -0x303(%rbp), %al
testb $0x1, %al
jne 0x5c26
jmp 0x5c13
movb $0x0, -0x1(%rbp)
movl $0x1, -0x29c(%rbp)
jmp 0x5d30
leaq -0x2d8(%rbp), %rdi
callq 0xd970
movq %rax, -0x310(%rbp)
jmp 0x5c3b
movq -0x310(%rbp), %rsi
movl -0x2c8(%rbp), %edx
leaq 0xd9d1(%rip), %rdi      # 0x13620
callq 0x87a0
movb %al, -0x311(%rbp)
jmp 0x5c5c
movb -0x311(%rbp), %al
testb $0x1, %al
jne 0x5c7b
jmp 0x5c68
movb $0x0, -0x1(%rbp)
movl $0x1, -0x29c(%rbp)
jmp 0x5d30
leaq 0xd99e(%rip), %rsi      # 0x13620
leaq 0x8527(%rip), %rcx      # 0xe1b0
leaq -0x60(%rbp), %rdi
leaq -0x28(%rbp), %rdx
movl $0x1, %r8d
callq 0xb460
movb %al, -0x312(%rbp)
jmp 0x5ca4
movb -0x312(%rbp), %al
testb $0x1, %al
jne 0x5cf1
jmp 0x5cb0
movq 0xd301(%rip), %rdi      # 0x12fb8
leaq 0x850a(%rip), %rsi      # 0xe1c8
callq 0x44a0
movq %rax, -0x320(%rbp)
jmp 0x5ccc
movq -0x320(%rbp), %rdi
movq 0xd2ce(%rip), %rsi      # 0x12fa8
callq 0x4500
jmp 0x5ce1
movb $0x0, -0x1(%rbp)
movl $0x1, -0x29c(%rbp)
jmp 0x5d30
movq 0xd2c0(%rip), %rdi      # 0x12fb8
leaq 0x84e1(%rip), %rsi      # 0xe1e0
callq 0x44a0
movq %rax, -0x328(%rbp)
jmp 0x5d0d
movq -0x328(%rbp), %rdi
movq 0xd28d(%rip), %rsi      # 0x12fa8
callq 0x4500
jmp 0x5d22
movb $0x1, -0x1(%rbp)
movl $0x1, -0x29c(%rbp)
leaq -0x2d8(%rbp), %rdi
callq 0xd880
leaq -0x2c0(%rbp), %rdi
callq 0xd6d0
leaq -0x2a8(%rbp), %rdi
callq 0xa3d0
jmp 0x5d70
leaq -0x2c0(%rbp), %rdi
callq 0xd6d0
leaq -0x2a8(%rbp), %rdi
callq 0xa3d0
jmp 0x5d9c
leaq -0x278(%rbp), %rdi
callq 0x40f0
leaq -0x60(%rbp), %rdi
callq 0x42b0
leaq -0x28(%rbp), %rdi
callq 0x42b0
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x330, %rsp            # imm = 0x330
popq %rbp
retq
leaq -0x278(%rbp), %rdi
callq 0x40f0
leaq -0x60(%rbp), %rdi
callq 0x42b0
leaq -0x28(%rbp), %rdi
callq 0x42b0
movq -0x38(%rbp), %rdi
callq 0x4900
nopw %cs:(%rax,%rax)