forked from bcosorg/bcos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DfsHttpClient.h
100 lines (76 loc) · 1.75 KB
/
DfsHttpClient.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#pragma once
#include <curl/curl.h>
#include <string.h>
#include <stdlib.h>
#include <string>
using std::string;
namespace dev
{
namespace rpc
{
namespace fs
{
//eg. size_t write_data(void *ptr, size_t size, size_t nmemb, void *cls)
typedef size_t (*Callback_write_data)(void*, size_t, size_t, void *cls);
typedef struct JzBuffer{
int compacity;
int size;
char* data;
} JzBuffer;
typedef struct JzRequestInfo {
string method;
string module;//must be "fs" now
string version;
string container_id;
string file_id;
string filename;
string filepath;
string filehash;
string host;//host:port
int port;
void *user_data;
CURL *curl;
JzRequestInfo(){
filepath = "";
filehash = "";
method = "";
module = "fs";
version = "v1";
container_id = "files";
file_id = "";
filename = "";
host = "";
port = 0;
user_data = NULL;
curl = NULL;
}
} JzRequestInfo;
class DfsHttpClient
{
public:
DfsHttpClient();
virtual ~DfsHttpClient();
public:
//init the curl components
void init(const JzRequestInfo& req_info);
//fill upload data and request to URL
int request(const string& upload_data);
int getRespCode() const {return m_resp_code;};
int getErrorCode() const {return m_error_code;};
const string& getMethod() const {return m_ReqInfo.method;}
int parseRspJson(const string& json);
public:
virtual int fillUserData(JzRequestInfo& req_info)=0;
virtual int endRequest()=0;
virtual size_t handle_recv_data(void *ptr, size_t size, size_t nmemb, void *cls)=0;
protected:
bool m_Inited;
int m_resp_code;
int m_error_code;
string m_strError;
public:
JzRequestInfo m_ReqInfo;
};
}
}
}