25#include <SystemConfiguration/SystemConfiguration.h>
26#include <Foundation/NSPathUtilities.h>
31#include <com/sun/star/beans/Optional.hpp>
32#include <com/sun/star/uno/XComponentContext.hpp>
34#include <rtl/ustrbuf.hxx>
36#include <osl/diagnose.h>
57bool GetProxySetting(ServiceType
sType,
char *host,
size_t hostSize, UInt16 *port)
60 CFDictionaryRef proxyDict;
61 CFNumberRef enableNum;
67 proxyDict = SCDynamicStoreCopyProxies(
nullptr);
72 CFStringRef proxiesEnable;
73 CFStringRef proxiesProxy;
74 CFStringRef proxiesPort;
78 case sHTTP : proxiesEnable = kSCPropNetProxiesHTTPEnable;
79 proxiesProxy = kSCPropNetProxiesHTTPProxy;
80 proxiesPort = kSCPropNetProxiesHTTPPort;
82 case sHTTPS: proxiesEnable = kSCPropNetProxiesHTTPSEnable;
83 proxiesProxy = kSCPropNetProxiesHTTPSProxy;
84 proxiesPort = kSCPropNetProxiesHTTPSPort;
86 default: proxiesEnable = kSCPropNetProxiesFTPEnable;
87 proxiesProxy = kSCPropNetProxiesFTPProxy;
88 proxiesPort = kSCPropNetProxiesFTPPort;
92 enableNum =
static_cast<CFNumberRef
>(CFDictionaryGetValue( proxyDict,
95 result = (enableNum !=
nullptr) && (CFGetTypeID(enableNum) == CFNumberGetTypeID());
98 result = CFNumberGetValue(enableNum, kCFNumberIntType, &enable) && (enable != 0);
103 hostStr =
static_cast<CFStringRef
>(CFDictionaryGetValue( proxyDict,
106 result = (hostStr !=
nullptr) && (CFGetTypeID(hostStr) == CFStringGetTypeID());
110 result = CFStringGetCString(hostStr, host,
static_cast<CFIndex
>(hostSize), kCFStringEncodingASCII);
115 portNum =
static_cast<CFNumberRef
>(CFDictionaryGetValue( proxyDict,
118 result = (portNum !=
nullptr) && (CFGetTypeID(portNum) == CFNumberGetTypeID());
122 CFRelease(proxyDict);
127 result = CFNumberGetValue(portNum, kCFNumberIntType, &portInt);
130 *port =
static_cast<UInt16
>(portInt);
133 CFRelease(proxyDict);
157 CFIndex nStringLen = CFStringGetLength(sOrig)+1;
160 char sBuffer[nStringLen];
162 CFStringGetCString(sOrig, sBuffer, nStringLen, kCFStringEncodingASCII);
166 return OUString::createFromAscii(sBuffer);
177 OUStringBuffer
aBuf( nLen+1 );
178 aBuf.setLength( nLen );
181 return aBuf.makeStringAndClear();
185 OUString
const &, css::uno::Any
const &)
187 throw css::lang::IllegalArgumentException(
188 "setPropertyValue not supported",
193 OUString
const & PropertyName)
195 if ( PropertyName ==
"WorkPathVariable" )
198 NSArray* pPaths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask,
true );
199 if( pPaths && [pPaths
count] > 0 )
201 aDocDir =
GetOUString( [pPaths objectAtIndex: 0] );
204 if( aDocDir.getLength() > 0 &&
205 osl_getFileURLFromSystemPath( aDocDir.pData, &aDocURL.pData ) == osl_File_E_None )
207 return css::uno::Any(
208 css::beans::Optional< css::uno::Any >(
209 true, css::uno::Any( aDocURL ) ) );
213 SAL_WARN(
"shell",
"user documents list contains empty file path or conversion failed" );
218 SAL_WARN(
"shell",
"Got nil or empty list of user document directories" );
220 return css::uno::Any(css::beans::Optional< css::uno::Any >());
221 }
else if ( PropertyName ==
"ooInetFTPProxyName" )
223 char host[MAXHOSTNAMELEN];
227 retVal = GetProxySetting(sFTP, host, 100, &port);
231 auto const Server = OUString::createFromAscii( host );
232 if(
Server.getLength() > 0 )
234 return css::uno::Any(
235 css::beans::Optional< css::uno::Any >(
239 return css::uno::Any(css::beans::Optional< css::uno::Any >());
240 }
else if ( PropertyName ==
"ooInetFTPProxyPort" )
242 char host[MAXHOSTNAMELEN];
246 retVal = GetProxySetting(sFTP, host, 100, &port);
248 if (retVal && port > 0)
250 return css::uno::Any(
251 css::beans::Optional< css::uno::Any >(
252 true,
uno::Any( sal_Int32(port) ) ) );
254 return css::uno::Any(css::beans::Optional< css::uno::Any >());
255 }
else if ( PropertyName ==
"ooInetHTTPProxyName" )
257 char host[MAXHOSTNAMELEN];
261 retVal = GetProxySetting(sHTTP, host, 100, &port);
265 auto const Server = OUString::createFromAscii( host );
266 if(
Server.getLength() > 0 )
268 return css::uno::Any(
269 css::beans::Optional< css::uno::Any >(
273 return css::uno::Any(css::beans::Optional< css::uno::Any >());
274 }
else if ( PropertyName ==
"ooInetHTTPProxyPort" )
276 char host[MAXHOSTNAMELEN];
280 retVal = GetProxySetting(sHTTP, host, 100, &port);
282 if (retVal && port > 0)
284 return css::uno::Any(
285 css::beans::Optional< css::uno::Any >(
286 true,
uno::Any( sal_Int32(port) ) ) );
288 return css::uno::Any(css::beans::Optional< css::uno::Any >());
289 }
else if ( PropertyName ==
"ooInetHTTPSProxyName" )
291 char host[MAXHOSTNAMELEN];
295 retVal = GetProxySetting(sHTTPS, host, 100, &port);
299 auto const Server = OUString::createFromAscii( host );
300 if(
Server.getLength() > 0 )
302 return css::uno::Any(
303 css::beans::Optional< css::uno::Any >(
307 return css::uno::Any(css::beans::Optional< css::uno::Any >());
308 }
else if ( PropertyName ==
"ooInetHTTPSProxyPort" )
310 char host[MAXHOSTNAMELEN];
314 retVal = GetProxySetting(sHTTPS, host, 100, &port);
316 if (retVal && port > 0)
318 return css::uno::Any(
319 css::beans::Optional< css::uno::Any >(
320 true,
uno::Any( sal_Int32(port) ) ) );
322 return css::uno::Any(css::beans::Optional< css::uno::Any >());
323 }
else if ( PropertyName ==
"ooInetProxyType" )
326 return css::uno::Any(
327 css::beans::Optional< css::uno::Any >(
329 }
else if ( PropertyName ==
"ooInetNoProxy" )
331 OUString aProxyBypassList;
333 CFArrayRef rExceptionsList;
334 CFDictionaryRef rProxyDict = SCDynamicStoreCopyProxies(
nullptr);
337 rExceptionsList =
nullptr;
339 rExceptionsList =
static_cast<CFArrayRef
>(CFDictionaryGetValue(rProxyDict, kSCPropNetProxiesExceptionsList));
343 for (CFIndex
idx = 0;
idx < CFArrayGetCount(rExceptionsList);
idx++)
345 CFStringRef rException =
static_cast<CFStringRef
>(CFArrayGetValueAtIndex(rExceptionsList,
idx));
348 aProxyBypassList +=
";";
355 CFRelease(rProxyDict);
358 if( aProxyBypassList.getLength() > 0 )
360 return css::uno::Any(
361 css::beans::Optional< css::uno::Any >(
365 return css::uno::Any(css::beans::Optional< css::uno::Any >());
367 throw css::beans::UnknownPropertyException(
368 PropertyName, getXWeak());
374 return "com.sun.star.comp.configuration.backend.MacOSXBackend";
384 return {
"com.sun.star.configuration.backend.MacOSXBackend" };
387extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
389 css::uno::XComponentContext* , css::uno::Sequence<css::uno::Any>
const&)
virtual OUString SAL_CALL getImplementationName() override
virtual ~MacOSXBackend() override
Destructor.
virtual sal_Bool SAL_CALL supportsService(const OUString &aServiceName) override
virtual uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual void SAL_CALL setPropertyValue(OUString const &, css::uno::Any const &) override
MacOSXBackend()
Service constructor from a service factory.
virtual css::uno::Any SAL_CALL getPropertyValue(OUString const &PropertyName) override
#define SAL_WARN(area, stream)
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * shell_MacOSXBackend_get_implementation(css::uno::XComponentContext *, css::uno::Sequence< css::uno::Any > const &)
static OUString CFStringToOUString(const CFStringRef sOrig)
static OUString GetOUString(NSString *pStr)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)