Matrix Science header

ms_http_helper.hpp

00001 /*
00002 ##############################################################################
00003 # file: ms_http_helper.hpp                                                          #
00004 # 'msparser' toolkit                                                         #
00005 # Provides functions for an HTTP link (eg to a Mascot server)                #
00006 ##############################################################################
00007 # COPYRIGHT NOTICE                                                           #
00008 # Copyright 1998-2013 Matrix Science Limited  All Rights Reserved.           #
00009 #                                                                            #
00010 ##############################################################################
00011  * @(#)$Source: parser/inc/ms_http_helper.hpp $
00012  * @(#)$Revision: 1b450440f9c97e1e41d0fc6016a27d68951d4532 | MSPARSER_REL_2_8_1-0-gea32989045 $
00013  * @(#)$Date: 2018-07-30 16:23:53 +0100 $
00014 ##############################################################################
00015  */
00016 
00017 #if !defined(MS_HTTP_HELPER_HPP_)
00018 #define MS_HTTP_HELPER_HPP_
00019 
00020 #ifdef _WIN32
00021 #ifdef __MINGW__
00022 // No ATL or MFC support -- use curl
00023 #else
00024 #define USE_ATL
00025 #endif
00026 #endif
00027 
00028 #include <string>
00029 
00030 class LocalHelper;
00031 
00032 namespace matrix_science
00033 {
00039     class ms_connection_settings;
00040     class ms_http_helper_handles;
00041     class ms_http_helper_progress;
00042     class ms_http_helper_proxy_list;
00043 
00045 
00055     class MS_MASCOTRESFILE_API ms_http_helper :
00056         public ms_errors
00057     {
00058         public:
00060 
00063             enum FileMode
00064             {
00065                 FM_binary, 
00066                 FM_text  
00067             };
00068 
00069 #ifdef USE_ATL
00070 
00071             static void yieldToCom();
00072 #endif            
00073 
00075             bool getProxyConfig(std::vector<std::string> &proxyServers, std::vector<std::string> &proxyUsernames, std::vector<std::string> &proxyPasswords);
00076 
00077 #ifndef SWIG
00078 
00079             ms_http_helper();
00080 
00082             ms_http_helper(const ms_http_helper & copy);
00083 
00085             const ms_http_helper & operator =(const ms_http_helper & copy);
00086 #endif
00087             void copyFrom(const ms_http_helper * right);
00088 
00090             ms_http_helper(
00091                     const std::string & baseUrl,
00092                     const ms_connection_settings & settings);
00093                     
00095             ~ms_http_helper();
00096 
00098             const std::string & baseUrl() const;
00099             
00101             const ms_connection_settings & connectionSettings() const;
00102 #ifndef SWIG
00103 
00104             ms_http_helper_return httpGetString(const std::string & action, std::string & httpGETString);
00105 #else // SWIG Multiple return values
00106             ms_http_helper_return httpGetString(const std::string & action, std::string & OUTPUT);
00107 #endif
00108 
00109             ms_http_helper_return httpPostFile(
00110                     const std::string & action,
00111                     const std::string & httpHeader,
00112                     const std::string & prologue,
00113                     const std::string & filename,
00114                     const std::string & epilogue,
00115                     ms_http_helper_handles & handles,
00116                     ms_http_helper_progress & progress);
00117 
00119             ms_http_helper_return httpGetFile(
00120                     const std::string & action,
00121                     const std::string & filename,
00122                     ms_http_helper_progress & progress,
00123                     FileMode fileMode = FM_binary);
00124 
00126             ms_http_helper_return httpBufferedOpen(const std::string & action);
00127 #ifndef SWIG
00128 
00129             ms_http_helper_return httpBufferedGetString(std::string & httpBuffer, unsigned long requiredSize );
00130 
00132             ms_http_helper_return httpGetHeader(const std::string & action, std::string & httpHeaderInfo);
00133 #else // SWIG Multiple return values
00134             ms_http_helper_return httpBufferedGetString(std::string & OUTPUT, unsigned long requiredSize);
00135             ms_http_helper_return httpGetHeader(const std::string & action, std::string & OUTPUT);
00136 #endif
00137 
00138             ms_http_helper_return httpBufferedClose();
00139 
00140 
00142             static std::string getHeaderValue(const std::string &name, const std::string & header);
00143 
00144         private:
00145             
00146 #ifndef USE_ATL
00147             bool analyseCurlResult(void * pVoidCurl, ms_http_helper_return & returnCode, std::string & performError, char * errorBuffer = NULL, std::vector< std::pair<int, std::string> > * pProxyErrors = NULL);
00148             void * performCurlAndCheckHttpsCertificate(void * pVoidCurl, std::string & certificateError, std::string & systemCertPath, std::string & userCertPath, bool bCheckCertificate = true);
00149 #endif // USE_ATL
00150 
00151             const std::string completeUrl(const std::string & action) const;
00152 
00153             ms_http_helper_return httpGetLocal(
00154                     const std::string & action,
00155                     std::string & strResult,
00156                     const std::string & filename,
00157                     FileMode fileMode,
00158                     ms_http_helper_progress & progress);
00159 
00160             ms_http_helper_return httpOpenLocal(const std::string & action, bool bHeaderOnly = false);
00161 
00162             ms_http_helper_return httpGetNextLocal(
00163                     std::string & buffer,
00164                     unsigned long requiredSize );
00165 
00166             ms_http_helper_return curlOpenLocal(const std::string & action);
00167 
00168             ms_http_helper_return curlGetNextLocal(
00169                     std::string & buffer,
00170                     unsigned long requiredSize);
00171 
00172             ms_http_helper_return closeLocal();
00173 
00174             bool determineProxy();
00175 
00176             std::string baseUrl_;
00177             ms_connection_settings connectionSettings_;
00178 
00179             // autoproxy detect cache
00180             ms_http_helper_proxy_list * proxyList_;
00181 
00182             LocalHelper * localHelper_; 
00183 
00184     };
00185      // end of http_client_group
00187 } // namespace matrix_science
00188 
00189 #endif // MS_HTTP_HELPER_HPP_

Copyright © 2022 Matrix Science Ltd.  All Rights Reserved. Generated on Thu Mar 31 2022 01:12:29