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: /vol/cvsroot/parser/inc/ms_http_helper.hpp,v $
00012  * @(#)$Revision: 1.19 $
00013  * @(#)$Date: 2016/07/29 10:18:37 $
00014 ##############################################################################
00015  */
00016 
00017 #if !defined(MS_HTTP_HELPER_HPP_)
00018 #define MS_HTTP_HELPER_HPP_
00019 
00020 #ifdef _WIN32
00021 #pragma warning(disable:4251)   // Don't want all classes to be exported
00022 #pragma warning(disable:4786)   // Debug symbols too long
00023 #   ifndef _MATRIX_USE_STATIC_LIB
00024 #       ifdef MS_MASCOTRESFILE_EXPORTS
00025 #           define MS_MASCOTRESFILE_API __declspec(dllexport)
00026 #       else
00027 #           define MS_MASCOTRESFILE_API __declspec(dllimport)
00028 #       endif
00029 #   else
00030 #       define MS_MASCOTRESFILE_API
00031 #   endif
00032 #else
00033 #   define MS_MASCOTRESFILE_API
00034 #endif
00035 
00036 #include <string>
00037 
00038 class LocalHelper;
00039 
00040 namespace matrix_science
00041 {
00047     class ms_connection_settings;
00048     class ms_http_helper_handles;
00049     class ms_http_helper_progress;
00050     class ms_http_helper_proxy_list;
00051 
00053 
00063     class MS_MASCOTRESFILE_API ms_http_helper :
00064         public ms_errors
00065     {
00066         public:
00068 
00071             enum FileMode
00072             {
00073                 FM_binary, 
00074                 FM_text  
00075             };
00076 
00077 #ifdef _WIN32
00078 
00079             static void yieldToCom();
00080 #endif            
00081 
00083             bool getProxyConfig(std::vector<std::string> &proxyServers, std::vector<std::string> &proxyUsernames, std::vector<std::string> &proxyPasswords);
00084 
00085 #ifndef SWIG
00086 
00087             ms_http_helper();
00088 
00090             ms_http_helper(const ms_http_helper & copy);
00091 
00093             const ms_http_helper & operator =(const ms_http_helper & copy);
00094 #endif
00095             void copyFrom(const ms_http_helper * right);
00096 
00098             ms_http_helper(
00099                     const std::string & baseUrl,
00100                     const ms_connection_settings & settings);
00101                     
00103             ~ms_http_helper();
00104 
00106             const std::string & baseUrl() const;
00107             
00109             const ms_connection_settings & connectionSettings() const;
00110 
00112             ms_http_helper_return httpGetString(
00113                     const std::string & action,
00114                     std::string & httpGETString);
00115 
00117             ms_http_helper_return httpPostFile(
00118                     const std::string & action,
00119                     const std::string & httpHeader,
00120                     const std::string & prologue,
00121                     const std::string & filename,
00122                     const std::string & epilogue,
00123                     ms_http_helper_handles & handles,
00124                     ms_http_helper_progress & progress);
00125 
00127             ms_http_helper_return httpGetFile(
00128                     const std::string & action,
00129                     const std::string & filename,
00130                     ms_http_helper_progress & progress,
00131                     FileMode fileMode = FM_binary);
00132 
00134             ms_http_helper_return httpBufferedOpen(const std::string & action);
00135 
00137             ms_http_helper_return httpBufferedGetString(
00138                     std::string & httpBuffer,
00139                     unsigned long requiredSize );
00140 
00142             ms_http_helper_return httpBufferedClose();
00143 
00145             ms_http_helper_return httpGetHeader(const std::string & action, std::string & httpHeaderInfo);
00146 
00148             static std::string getHeaderValue(const std::string &name, const std::string & header);
00149 
00150         private:
00151             
00152 #ifndef _WIN32
00153             bool analyseCurlResult(void * pVoidCurl, ms_http_helper_return & returnCode, std::string & performError, char * errorBuffer = NULL, std::vector< std::pair<int, std::string> > * pProxyErrors = NULL);
00154             void * performCurlAndCheckHttpsCertificate(void * pVoidCurl, std::string & certificateError, std::string & systemCertPath, std::string & userCertPath, bool bCheckCertificate = true);
00155 #endif // _WIN32
00156 
00157             const std::string completeUrl(const std::string & action) const;
00158 
00159             ms_http_helper_return httpGetLocal(
00160                     const std::string & action,
00161                     std::string & strResult,
00162                     const std::string & filename,
00163                     FileMode fileMode,
00164                     ms_http_helper_progress & progress);
00165 
00166             ms_http_helper_return httpOpenLocal(const std::string & action, bool bHeaderOnly = false);
00167 
00168             ms_http_helper_return httpGetNextLocal(
00169                     std::string & buffer,
00170                     unsigned long requiredSize );
00171 
00172             ms_http_helper_return curlOpenLocal(const std::string & action);
00173 
00174             ms_http_helper_return curlGetNextLocal(
00175                     std::string & buffer,
00176                     unsigned long requiredSize);
00177 
00178             ms_http_helper_return closeLocal();
00179 
00180             bool determineProxy();
00181 
00182             std::string baseUrl_;
00183             ms_connection_settings connectionSettings_;
00184 
00185             // autoproxy detect cache
00186             ms_http_helper_proxy_list * proxyList_;
00187 
00188             LocalHelper * localHelper_; 
00189 
00190     };
00191      // end of http_client_group
00193 } // namespace matrix_science
00194 
00195 #endif // MS_HTTP_HELPER_HPP_
Copyright © 2016 Matrix Science Ltd.  All Rights Reserved. Generated on Fri Jun 2 2017 01:44:51