Advertisement
Guest User

Libcurl i windows, plik H

a guest
Jan 23rd, 2018
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.93 KB | None | 0 0
  1.  
  2. #ifndef AOU_CURLMANAGER_H
  3. #define AOU_CURLMANAGER_H
  4.  
  5. #include <System/Exceptions.h>
  6. #include <curl/curl.h>
  7. #include <map>
  8. #include <string>
  9.  
  10.  
  11. namespace aou {
  12.     namespace exc {
  13.         //--------------------------------------------------------------------
  14.         class CURLInitFailed : public aou::exc::Exception{
  15.         public:
  16.             CURLInitFailed();
  17.             virtual ~CURLInitFailed() = default;
  18.         };
  19.         //--------------------------------------------------------------------
  20.         class CURLDownloadFileFailed : public aou::exc::Exception {
  21.         public:
  22.             CURLDownloadFileFailed(const std::string& desc);
  23.             virtual ~CURLDownloadFileFailed() = default;
  24.         };
  25.         //--------------------------------------------------------------------
  26.         class CURLUploadFileFailed : public aou::exc::Exception {
  27.         public:
  28.             CURLUploadFileFailed(const std::string& exc);
  29.             virtual ~CURLUploadFileFailed() = default;
  30.         };
  31.         //--------------------------------------------------------------------
  32.     }
  33.     enum CURLOperationType {
  34.         NONE,
  35.         DOWNLOAD_FILE,
  36.         UPLOAD_FILE,
  37.     };
  38.     //--------------------------------------------------------------------
  39.     struct FTPServer {
  40.         std::string url;
  41.         std::string login;
  42.         std::string pass;
  43.     };
  44.     //--------------------------------------------------------------------
  45.     class CURLManager {
  46.     private:
  47.         CURLManager();
  48.     public:
  49.         virtual ~CURLManager();
  50.  
  51.         static CURLManager& GetInstance();
  52.        
  53.         virtual void DownloadFileFromHTTP(const std::string& url, const std::string& to_file);
  54.         virtual void UploadFileToFTP(const std::string& ftp_server_id, const std::string& directory_in_ftp_server, const std::string& from_file);
  55.         virtual void AddFTPServer(const std::string & ftp_server_id, const FTPServer& ftp_server);
  56.         virtual void EraseFTPServer(const std::string& ftp_server_id);
  57.         virtual const FTPServer& GetFTPServer(const std::string& ftp_server_id);
  58.        
  59.        
  60.         inline CURL* GetCURLState() const;
  61.         inline CURLOperationType GetLastOperationType() const {
  62.             return last_operation_type;
  63.         }
  64.     private:
  65.         virtual void ResetCURLOptionsIfNessesaryAndUpdateLastOperationTypeEnum(CURLOperationType this_operation_type);
  66.  
  67.         //curl functions
  68.         static size_t curlfunction_write_data(void *ptr, size_t size, size_t nmemb, FILE *stream);
  69.         static size_t curlfunction_read_data(void *ptr, size_t size, size_t nmemb, FILE *stream);
  70.         /*
  71.          * Member data
  72.          */
  73.         CURL* curl_state = nullptr;
  74.         CURLOperationType last_operation_type = NONE;;
  75.         std::map<std::string, FTPServer> ftp_servers;
  76.     };
  77.     //--------------------------------------------------------------------
  78. }
  79.  
  80. #endif /* AOU_CURLMANAGER_H */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement