iFun Engine API  1.0.0-b6053
Great Technology for Great Games
curl.h
Go to the documentation of this file.
1 // Copyright (C) 2013-2020 iFunFactory Inc. All Rights Reserved.
2 //
3 // This work is confidential and proprietary to iFunFactory Inc. and
4 // must not be used, disclosed, copied, or distributed without the prior
5 // consent of iFunFactory Inc.
6 
9 #ifndef INCLUDE_FUNAPI_NETWORK_CURL_H_
10 #define INCLUDE_FUNAPI_NETWORK_CURL_H_
11 
12 #include <curl/curl.h>
13 #include <funapi/common/json.h>
15 #include <funapi/types.h>
16 
17 
18 namespace fun {
19 
20 class FUNAPI_DLL_VISIBILITY Curl : private boost::noncopyable {
21  public:
22  class Impl;
23 
24  typedef function<void(CURLcode, const string &error_desc)> CompleteCallback;
25 
26  Curl();
27 
28  CURL *easy_handle() const;
29 
30  void set_complete_callback(const CompleteCallback &cb);
31 
32  bool GetVerbose() const;
33  void SetVerbose(bool on);
34 
35  void SetTimeout(size_t timeout_in_ms);
36 
37  CURLcode GetResultCode() const;
38  const char *GetErrorBuffer() const;
39 
40  CURLcode Request();
41  void RequestAsync();
42 
43  private:
44  Ptr<Impl> impl_;
45 };
46 
47 
48 class FUNAPI_DLL_VISIBILITY CurlHttp : private boost::noncopyable {
49  public:
50  class Impl;
51 
52  typedef function<void(CURLcode, const string &error_desc)> CompleteCallback;
53  typedef function<void(void *, size_t)> HeaderReceiveCallback;
54  typedef function<void(void *, size_t)> PayloadReceiveCallback;
55 
56  CurlHttp();
57 
58  CURL *easy_handle() const;
59 
60  void set_complete_callback(const CompleteCallback &cb);
61  void set_header_receive_callback(const HeaderReceiveCallback &cb);
62  void set_payload_receive_callback(const PayloadReceiveCallback &cb);
63 
64  bool GetVerbose() const;
65  void SetVerbose(bool on);
66  void SetTimeout(size_t timeout_in_ms);
67 
68  CURLcode GetResultCode() const;
69  const string &GetResult() const;
70  const char *GetErrorBuffer() const;
71 
72  const string &GetUrl() const;
73 
74  void SetUrl(const string &url);
75  void SetUserAgent(const string &user_agent);
76  void SetHeader(const http::Header &header);
77 
78  void SetGet();
79 
80  void SetPost(const Ptr<const string> &data);
81  void SetPost(const curl_httppost *data);
82  void SetPost(const Json &data);
83 
84  void SetPut(const Ptr<const string> &data);
85  void SetPut(const Json &data);
86 
87  void SetDelete(const Ptr<const string> &data);
88  void SetDelete(const Json &data);
89 
90  CURLcode Request();
91  void RequestAsync();
92 
93  private:
94  Ptr<Impl> impl_;
95 };
96 
97 } // namespace fun
98 
99 #endif // INCLUDE_FUNAPI_NETWORK_CURL_H_
Definition: curl.h:20
std::multimap< string, string, impl::util::CaseInsensitiveLess > Header
Datastructure to hold http header fields.
Definition: http_util.h:23
Definition: json.h:18
Definition: curl.h:48
Definition: json.h:27