// File: cqbqdd11519[P]DockerClient/docker.cpp
// Function: Docker::requestAndParse(Method, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, unsigned int, rapidjson::GenericDocument<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator>, rapidjson::CrtAllocator>&, bool)
JSON_DOCUMENT Docker::requestAndParse(Method method, const std::string& path, unsigned success_code, JSON_DOCUMENT& param, bool isReturnJson){
    std::string readBuffer;
    std::string paramString;
    std::string method_str;
    struct curl_slist *headers = nullptr;
    const char *paramChar;
    switch(method){
        case GET:
            method_str = "GET";
            break;
        case POST:
            method_str = "POST";
            break;
        case DELETE:
            method_str = "DELETE";
            break;
        case PUT:
            method_str = "PUT";
            break;
        default:
            method_str = "GET";
    }

    curl = curl_easy_init();
    if(!curl){
        std::cout << "error while initiating curl" << std::endl;
        curl_global_cleanup();
        exit(1);
    }
    rapidjson::StringBuffer buffer;
    buffer.Clear();
    rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
    param.Accept(writer);
    paramString = std::string(buffer.GetString());
    paramChar = paramString.c_str();
    if(isReturnJson)
        headers = curl_slist_append(headers, "Accept: application/json");
    headers = curl_slist_append(headers, "Content-Type: application/json");

    //std::cout << "HOST_PATH : " << (host_uri + path) << std::endl;

    if(!is_remote)
        curl_easy_setopt(curl, CURLOPT_UNIX_SOCKET_PATH, "/var/run/docker.sock");
    curl_easy_setopt(curl, CURLOPT_URL, (host_uri + path).c_str());
    curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, method_str.c_str());
    curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
    curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer);
    if(method == POST){
        curl_easy_setopt(curl, CURLOPT_POSTFIELDS, paramChar);
        curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, strlen(paramChar));
    }

    res = curl_easy_perform(curl);
    if(res != CURLE_OK)
        fprintf(stderr, "curl_easy_perform() failed: %s\n",
            curl_easy_strerror(res));
    unsigned status = 0;
    curl_easy_getinfo (curl, CURLINFO_RESPONSE_CODE, &status);
    curl_easy_cleanup(curl);

    const char* buf = readBuffer.c_str();
    JSON_DOCUMENT doc(rapidjson::kObjectType);
    if(status == success_code || status == 200){
        doc.AddMember("success", true, doc.GetAllocator());

        JSON_VALUE dataString;
        dataString.SetString(readBuffer.c_str(), doc.GetAllocator());

        doc.AddMember("data", dataString, doc.GetAllocator());
    }else{
        JSON_DOCUMENT resp(&doc.GetAllocator());
        resp.Parse(buf);

        doc.AddMember("success", false, doc.GetAllocator());
        doc.AddMember("code", status, doc.GetAllocator());
        doc.AddMember("data", resp, doc.GetAllocator());
    }
    curl_slist_free_all(headers);
    return doc;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x310, %rsp            # imm = 0x310
movq %rdi, -0x268(%rbp)
movq %rdi, %rax
movq %rax, -0x260(%rbp)
movb 0x10(%rbp), %al
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq %rcx, -0x20(%rbp)
movl %r8d, -0x24(%rbp)
movq %r9, -0x30(%rbp)
andb $0x1, %al
movb %al, -0x31(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x258(%rbp)
leaq -0x58(%rbp), %rdi
callq 0xeeb0
leaq -0x78(%rbp), %rdi
callq 0xeeb0
leaq -0x98(%rbp), %rdi
callq 0xeeb0
movq $0x0, -0xa0(%rbp)
movl -0x14(%rbp), %eax
movq %rax, -0x250(%rbp)
subq $0x3, %rax
ja 0x1128d
movq -0x250(%rbp), %rax
leaq 0xcdef(%rip), %rcx      # 0x1e000
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0xcf8e(%rip), %rsi      # 0x1e1af
leaq -0x98(%rbp), %rdi
callq 0xee30
jmp 0x1122f
jmp 0x112a4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
jmp 0x11a40
leaq 0xcf64(%rip), %rsi      # 0x1e1b3
leaq -0x98(%rbp), %rdi
callq 0xee30
jmp 0x1125d
jmp 0x112a4
leaq 0xcf52(%rip), %rsi      # 0x1e1b8
leaq -0x98(%rbp), %rdi
callq 0xee30
jmp 0x11274
jmp 0x112a4
leaq 0xcf42(%rip), %rsi      # 0x1e1bf
leaq -0x98(%rbp), %rdi
callq 0xee30
jmp 0x1128b
jmp 0x112a4
leaq 0xcf1b(%rip), %rsi      # 0x1e1af
leaq -0x98(%rbp), %rdi
callq 0xee30
jmp 0x112a2
jmp 0x112a4
callq 0xed50
movq %rax, -0x270(%rbp)
jmp 0x112b2
movq -0x258(%rbp), %rax
movq -0x270(%rbp), %rcx
movq %rcx, 0x28(%rax)
cmpq $0x0, 0x28(%rax)
jne 0x1130d
movq 0x15cce(%rip), %rdi     # 0x26fa0
leaq 0xceea(%rip), %rsi      # 0x1e1c3
callq 0xe990
movq %rax, -0x278(%rbp)
jmp 0x112e7
movq -0x278(%rbp), %rdi
movq 0x15c83(%rip), %rsi     # 0x26f78
callq 0xea70
jmp 0x112fc
callq 0xe2d0
jmp 0x11303
movl $0x1, %edi
callq 0xec90
xorl %eax, %eax
movl %eax, %esi
leaq -0xe8(%rbp), %rdi
movl $0x100, %edx            # imm = 0x100
callq 0xf340
jmp 0x11324
leaq -0xe8(%rbp), %rdi
callq 0xe4c0
jmp 0x11332
xorl %eax, %eax
movl %eax, %edx
leaq -0x128(%rbp), %rdi
leaq -0xe8(%rbp), %rsi
movl $0x20, %ecx
callq 0xf250
jmp 0x11350
movq -0x30(%rbp), %rdi
leaq -0x128(%rbp), %rsi
callq 0xf400
jmp 0x11362
leaq -0xe8(%rbp), %rdi
callq 0xeab0
movq %rax, -0x280(%rbp)
jmp 0x11377
leaq -0x149(%rbp), %rdi
movq %rdi, -0x288(%rbp)
callq 0xf300
movq -0x280(%rbp), %rsi
movq -0x288(%rbp), %rdx
leaq -0x148(%rbp), %rdi
callq 0xee50
jmp 0x113a6
leaq -0x78(%rbp), %rdi
leaq -0x148(%rbp), %rsi
callq 0xeca0
leaq -0x148(%rbp), %rdi
callq 0xe5d0
leaq -0x149(%rbp), %rdi
callq 0xeac0
leaq -0x78(%rbp), %rdi
callq 0xe360
movq %rax, -0xa8(%rbp)
testb $0x1, -0x31(%rbp)
je 0x11461
movq -0xa0(%rbp), %rdi
leaq 0xcded(%rip), %rsi      # 0x1e1df
callq 0xed00
movq %rax, -0x290(%rbp)
jmp 0x11400
movq -0x290(%rbp), %rax
movq %rax, -0xa0(%rbp)
jmp 0x11461
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
jmp 0x11a34
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
jmp 0x11a28
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
leaq -0x149(%rbp), %rdi
callq 0xeac0
jmp 0x11a28
movq -0xa0(%rbp), %rdi
leaq 0xcd89(%rip), %rsi      # 0x1e1f8
callq 0xed00
movq %rax, -0x298(%rbp)
jmp 0x1147d
movq -0x258(%rbp), %rax
movq -0x298(%rbp), %rcx
movq %rcx, -0xa0(%rbp)
testb $0x1, 0x20(%rax)
jne 0x114ba
movq -0x258(%rbp), %rax
movq 0x28(%rax), %rdi
leaq 0xcd6d(%rip), %rdx      # 0x1e217
xorl %eax, %eax
movl $0x27f7, %esi           # imm = 0x27F7
callq 0xec10
jmp 0x114b8
jmp 0x114ba
movq -0x258(%rbp), %rsi
movq 0x28(%rsi), %rax
movq %rax, -0x2a0(%rbp)
movq -0x20(%rbp), %rdx
leaq -0x170(%rbp), %rdi
callq 0xf490
jmp 0x114de
leaq -0x170(%rbp), %rdi
callq 0xe360
movq -0x2a0(%rbp), %rdi
movq %rax, %rdx
xorl %eax, %eax
movl $0x2712, %esi           # imm = 0x2712
callq 0xec10
jmp 0x11502
leaq -0x170(%rbp), %rdi
callq 0xe5d0
movq -0x258(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x2a8(%rbp)
leaq -0x98(%rbp), %rdi
callq 0xe360
movq -0x2a8(%rbp), %rdi
movq %rax, %rdx
xorl %eax, %eax
movl $0x2734, %esi           # imm = 0x2734
callq 0xec10
jmp 0x11544
movq -0x258(%rbp), %rax
movq 0x28(%rax), %rdi
movq -0xa0(%rbp), %rdx
xorl %eax, %eax
movl $0x2727, %esi           # imm = 0x2727
callq 0xec10
jmp 0x11564
movq -0x258(%rbp), %rax
movq 0x28(%rax), %rdi
movq 0x159da(%rip), %rdx     # 0x26f50
xorl %eax, %eax
movl $0x4e2b, %esi           # imm = 0x4E2B
callq 0xec10
jmp 0x11584
movq -0x258(%rbp), %rax
movq 0x28(%rax), %rdi
xorl %eax, %eax
movl $0x2711, %esi           # imm = 0x2711
leaq -0x58(%rbp), %rdx
callq 0xec10
jmp 0x115a1
cmpl $0x1, -0x14(%rbp)
jne 0x11622
movq -0x258(%rbp), %rax
movq 0x28(%rax), %rdi
movq -0xa8(%rbp), %rdx
xorl %eax, %eax
movl $0x271f, %esi           # imm = 0x271F
callq 0xec10
jmp 0x115c7
movq -0x258(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x2b0(%rbp)
movq -0xa8(%rbp), %rdi
callq 0xe390
movq -0x2b0(%rbp), %rdi
movq %rax, %rdx
xorl %eax, %eax
movl $0x3c, %esi
callq 0xec10
jmp 0x115fd
jmp 0x11622
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
leaq -0x170(%rbp), %rdi
callq 0xe5d0
jmp 0x11a28
movq -0x258(%rbp), %rax
movq 0x28(%rax), %rdi
callq 0xedc0
movl %eax, -0x2b4(%rbp)
jmp 0x1163a
movq -0x258(%rbp), %rax
movl -0x2b4(%rbp), %ecx
movl %ecx, 0x30(%rax)
cmpl $0x0, 0x30(%rax)
je 0x11695
movq -0x258(%rbp), %rax
movq 0x1594a(%rip), %rcx     # 0x26fa8
movq (%rcx), %rcx
movq %rcx, -0x2c8(%rbp)
movl 0x30(%rax), %edi
callq 0xef40
movq %rax, -0x2c0(%rbp)
jmp 0x11679
movq -0x2c0(%rbp), %rdx
movq -0x2c8(%rbp), %rdi
leaq 0xcb9e(%rip), %rsi      # 0x1e22c
movb $0x0, %al
callq 0xef20
movq -0x258(%rbp), %rax
movl $0x0, -0x174(%rbp)
movq 0x28(%rax), %rdi
xorl %eax, %eax
movl $0x200002, %esi         # imm = 0x200002
leaq -0x174(%rbp), %rdx
callq 0xe590
jmp 0x116bf
movq -0x258(%rbp), %rax
movq 0x28(%rax), %rdi
callq 0xecd0
jmp 0x116d1
leaq -0x58(%rbp), %rdi
callq 0xe360
movq -0x268(%rbp), %rdi
movq %rax, -0x180(%rbp)
movb $0x0, -0x181(%rbp)
xorl %eax, %eax
movl %eax, %r8d
movl $0x3, %esi
movl $0x400, %ecx            # imm = 0x400
movq %r8, %rdx
callq 0xe1e0
jmp 0x11708
movl -0x174(%rbp), %eax
cmpl -0x24(%rbp), %eax
je 0x11723
cmpl $0xc8, -0x174(%rbp)
jne 0x1184f
leaq 0xcb22(%rip), %rsi      # 0x1e24c
leaq -0x198(%rbp), %rdi
callq 0xe630
movq -0x268(%rbp), %rdi
callq 0xe5c0
movq %rax, -0x2d0(%rbp)
jmp 0x1174b
movq -0x2d0(%rbp), %rcx
movq -0x268(%rbp), %rdi
leaq -0x198(%rbp), %rsi
movl $0x1, %edx
callq 0xf3c0
jmp 0x1176c
leaq -0x1a8(%rbp), %rdi
callq 0xf390
leaq -0x58(%rbp), %rdi
callq 0xe360
movq -0x268(%rbp), %rdi
movq %rax, -0x2e0(%rbp)
callq 0xe5c0
movq %rax, -0x2d8(%rbp)
jmp 0x1179d
movq -0x2d8(%rbp), %rdx
movq -0x2e0(%rbp), %rsi
leaq -0x1a8(%rbp), %rdi
callq 0xe7b0
jmp 0x117b9
leaq 0xca94(%rip), %rsi      # 0x1e254
leaq -0x1b8(%rbp), %rdi
callq 0xe330
movq -0x268(%rbp), %rdi
callq 0xe5c0
movq %rax, -0x2e8(%rbp)
jmp 0x117e1
movq -0x2e8(%rbp), %rcx
movq -0x268(%rbp), %rdi
leaq -0x1b8(%rbp), %rsi
leaq -0x1a8(%rbp), %rdx
callq 0xe940
jmp 0x11804
leaq -0x1a8(%rbp), %rdi
callq 0xef70
jmp 0x119ac
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
jmp 0x11a1c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
leaq -0x1a8(%rbp), %rdi
callq 0xef70
jmp 0x11a1c
movq -0x268(%rbp), %rdi
callq 0xe5c0
movq %rax, -0x2f0(%rbp)
jmp 0x11864
movq -0x2f0(%rbp), %rsi
xorl %eax, %eax
movl %eax, %ecx
leaq -0x218(%rbp), %rdi
movl $0x400, %edx            # imm = 0x400
callq 0xf370
jmp 0x11882
movq -0x180(%rbp), %rsi
leaq -0x218(%rbp), %rdi
callq 0xe100
jmp 0x11897
leaq 0xc9ae(%rip), %rsi      # 0x1e24c
leaq -0x228(%rbp), %rdi
callq 0xe630
movq -0x268(%rbp), %rdi
callq 0xe5c0
movq %rax, -0x2f8(%rbp)
jmp 0x118bf
movq -0x2f8(%rbp), %rcx
movq -0x268(%rbp), %rdi
leaq -0x228(%rbp), %rsi
xorl %edx, %edx
callq 0xf3c0
jmp 0x118dd
leaq 0xc975(%rip), %rsi      # 0x1e259
leaq -0x238(%rbp), %rdi
callq 0xe330
movq -0x268(%rbp), %rdi
movl -0x174(%rbp), %eax
movl %eax, -0x304(%rbp)
callq 0xe5c0
movq %rax, -0x300(%rbp)
jmp 0x11911
movq -0x300(%rbp), %rcx
movl -0x304(%rbp), %edx
movq -0x268(%rbp), %rdi
leaq -0x238(%rbp), %rsi
callq 0xefb0
jmp 0x11933
leaq 0xc91a(%rip), %rsi      # 0x1e254
leaq -0x248(%rbp), %rdi
callq 0xe330
movq -0x268(%rbp), %rdi
callq 0xe5c0
movq %rax, -0x310(%rbp)
jmp 0x1195b
movq -0x310(%rbp), %rcx
movq -0x268(%rbp), %rdi
leaq -0x248(%rbp), %rsi
leaq -0x218(%rbp), %rdx
callq 0xe940
jmp 0x1197e
leaq -0x218(%rbp), %rdi
callq 0xf590
jmp 0x119ac
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
leaq -0x218(%rbp), %rdi
callq 0xf590
jmp 0x11a1c
movq -0xa0(%rbp), %rdi
callq 0xe250
jmp 0x119ba
movb $0x1, -0x181(%rbp)
testb $0x1, -0x181(%rbp)
jne 0x119d6
movq -0x268(%rbp), %rdi
callq 0xf590
leaq -0x128(%rbp), %rdi
callq 0xe970
leaq -0xe8(%rbp), %rdi
callq 0xe220
leaq -0x98(%rbp), %rdi
callq 0xe5d0
leaq -0x78(%rbp), %rdi
callq 0xe5d0
leaq -0x58(%rbp), %rdi
callq 0xe5d0
movq -0x260(%rbp), %rax
addq $0x310, %rsp            # imm = 0x310
popq %rbp
retq
movq -0x268(%rbp), %rdi
callq 0xf590
leaq -0x128(%rbp), %rdi
callq 0xe970
leaq -0xe8(%rbp), %rdi
callq 0xe220
leaq -0x98(%rbp), %rdi
callq 0xe5d0
leaq -0x78(%rbp), %rdi
callq 0xe5d0
leaq -0x58(%rbp), %rdi
callq 0xe5d0
movq -0xb0(%rbp), %rdi
callq 0xf2f0
nopw (%rax,%rax)