Skip to content

Commit

Permalink
Merge pull request #43 from mantidproject/feature/10371_osx_proxy_issue
Browse files Browse the repository at this point in the history
Feature/10371 osx proxy issue
  • Loading branch information
martyngigg committed Nov 4, 2014
2 parents 7c6863b + ccf42a2 commit 590fa0d
Show file tree
Hide file tree
Showing 10 changed files with 2,418 additions and 1,584 deletions.
20 changes: 17 additions & 3 deletions Code/Mantid/Framework/Kernel/CMakeLists.txt
Expand Up @@ -11,8 +11,8 @@ set ( SRC_FILES
src/ConfigService.cpp
src/DataItem.cpp
src/DateAndTime.cpp
src/DateValidator.cpp
src/DateTimeValidator.cpp
src/DateValidator.cpp
src/DeltaEMode.cpp
src/DirectoryValidator.cpp
src/DiskBuffer.cpp
Expand Down Expand Up @@ -65,6 +65,7 @@ set ( SRC_FILES
src/PropertyManager.cpp
src/PropertyManagerOwner.cpp
src/PropertyWithValue.cpp
src/ProxyInfo.cpp
src/PseudoRandomNumberGenerator.cpp
src/Quat.cpp
src/ReadLock.cpp
Expand Down Expand Up @@ -129,8 +130,8 @@ set ( INC_FILES
inc/MantidKernel/DataItem.h
inc/MantidKernel/DataService.h
inc/MantidKernel/DateAndTime.h
inc/MantidKernel/DateValidator.h
inc/MantidKernel/DateTimeValidator.h
inc/MantidKernel/DateValidator.h
inc/MantidKernel/DeltaEMode.h
inc/MantidKernel/DirectoryValidator.h
inc/MantidKernel/DiskBuffer.h
Expand Down Expand Up @@ -185,6 +186,7 @@ set ( INC_FILES
inc/MantidKernel/MultiThreaded.h
inc/MantidKernel/NDPseudoRandomNumberGenerator.h
inc/MantidKernel/NDRandomNumberGenerator.h
inc/MantidKernel/NetworkProxy.h
inc/MantidKernel/NeutronAtom.h
inc/MantidKernel/NexusDescriptor.h
inc/MantidKernel/NullValidator.h
Expand All @@ -197,6 +199,7 @@ set ( INC_FILES
inc/MantidKernel/PropertyManager.h
inc/MantidKernel/PropertyManagerOwner.h
inc/MantidKernel/PropertyWithValue.h
inc/MantidKernel/ProxyInfo.h
inc/MantidKernel/PseudoRandomNumberGenerator.h
inc/MantidKernel/QuasiRandomNumberSequence.h
inc/MantidKernel/Quat.h
Expand Down Expand Up @@ -310,6 +313,7 @@ set ( TEST_FILES
PropertyManagerTest.h
PropertyTest.h
PropertyWithValueTest.h
ProxyInfoTest.h
QuatTest.h
ReadLockTest.h
RebinHistogramTest.h
Expand Down Expand Up @@ -344,6 +348,16 @@ set ( TEST_FILES
WriteLockTest.h
)

if ( ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
LIST( APPEND SRC_FILES src/NetworkProxyOSX.cpp )
SET( NETWORK_LIBRARIES "-framework SystemConfiguration" "-framework CoreFoundation" "-framework CoreServices")
elseif (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
LIST( APPEND SRC_FILES src/NetworkProxyWin.cpp )
SET( NETWORK_LIBRARIES Winhttp )
else()
LIST( APPEND SRC_FILES src/NetworkProxyLinux.cpp )
endif()

if(UNITY_BUILD)
include(UnityBuild)
enable_unity_build(Kernel SRC_FILES SRC_UNITY_IGNORE_FILES 10)
Expand All @@ -362,7 +376,7 @@ set_target_properties ( Kernel PROPERTIES OUTPUT_NAME MantidKernel
# Add to the 'Framework' group in VS
set_property ( TARGET Kernel PROPERTY FOLDER "MantidFramework" )

target_link_libraries ( Kernel ${MANTIDLIBS} ${GSL_LIBRARIES} ${NEXUS_LIBRARIES} )
target_link_libraries ( Kernel ${MANTIDLIBS} ${GSL_LIBRARIES} ${NEXUS_LIBRARIES} ${NETWORK_LIBRARIES} )
if ( WIN32 )
target_link_libraries ( Kernel Psapi.lib ) # For memory usage queries
endif()
Expand Down
59 changes: 59 additions & 0 deletions Code/Mantid/Framework/Kernel/inc/MantidKernel/NetworkProxy.h
@@ -0,0 +1,59 @@
#ifndef MANTID_KERNEL_NETWORKPROXY_H_
#define MANTID_KERNEL_NETWORKPROXY_H_

#include "MantidKernel/System.h"
#include "MantidKernel/ProxyInfo.h"
#include "MantidKernel/Logger.h"


namespace Mantid
{
namespace Kernel
{

/** NetworkProxy : Network proxy utility for getting network proxy information.
Copyright © 2014 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory
This file is part of Mantid.
Mantid is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
Mantid is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
File change history is stored at: <https://github.com/mantidproject/mantid>
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class DLLExport NetworkProxy
{
public:
/// Constructor
NetworkProxy();

/// Get http proxy information.
ProxyInfo getHttpProxy(const std::string& targetURLString);

/// Destructor
virtual ~NetworkProxy();

private:

/// Logger object
Mantid::Kernel::Logger m_logger;

};


} // namespace Kernel
} // namespace Mantid

#endif /* MANTID_KERNEL_NETWORKPROXY_H_ */
58 changes: 58 additions & 0 deletions Code/Mantid/Framework/Kernel/inc/MantidKernel/ProxyInfo.h
@@ -0,0 +1,58 @@
#ifndef MANTID_KERNEL_PROXYINFO_H_
#define MANTID_KERNEL_PROXYINFO_H_

#include "MantidKernel/System.h"
#include <string>

namespace Mantid
{
namespace Kernel
{

/** ProxyInfo : Container for carrying around network proxy information
Copyright &copy; 2014 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory
This file is part of Mantid.
Mantid is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
Mantid is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
File change history is stored at: <https://github.com/mantidproject/mantid>
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class DLLExport ProxyInfo
{
private:
std::string m_host;
int m_port;
bool m_isHttpProxy;
bool m_isEmptyProxy;

public:
virtual ~ProxyInfo();
ProxyInfo();
ProxyInfo(const ProxyInfo& other);
ProxyInfo& operator=(const ProxyInfo& other);
ProxyInfo(const std::string& host, const int port, const bool isHttpProxy);
std::string host() const;
int port() const;
bool isHttpProxy() const;
bool emptyProxy() const;

};

} // namespace Kernel
} // namespace Mantid

#endif /* MANTID_KERNEL_PROXYINFO_H_ */
40 changes: 40 additions & 0 deletions Code/Mantid/Framework/Kernel/src/NetworkProxyLinux.cpp
@@ -0,0 +1,40 @@
#include "MantidKernel/NetworkProxy.h"
#include <Poco/URI.h>

namespace Mantid
{
namespace Kernel
{

//----------------------------------------------------------------------------------------------
/** Constructor
*/
NetworkProxy::NetworkProxy() :
m_logger("network_proxy_logger_generic")
{
}

//----------------------------------------------------------------------------------------------
/** Destructor
*/
NetworkProxy::~NetworkProxy()
{
}

ProxyInfo NetworkProxy::getHttpProxy(const std::string&)
{
ProxyInfo proxyInfo; // NoProxy.
char * proxy_var = getenv("http_proxy");
if (proxy_var == 0)
proxy_var = getenv("HTTP_PROXY");

if (proxy_var != 0)
{
Poco::URI uri_p(proxy_var);
proxyInfo = ProxyInfo(uri_p.getHost(), uri_p.getPort(), true /*http proxy*/);
}
return proxyInfo;
}

} // namespace Kernel
} // namespace Mantid

0 comments on commit 590fa0d

Please sign in to comment.