/**************************************************************************
@param pChHostName: [output]Get system proxy host name
@param pChPort: [output]Get system proxy port
@param iProxyType:[input]ProxyType: 1(HTTP);2(HTTPS);....
**************************************************************************/
bool MacGetProxyHostNameAndPort(int iProxyType, char *pChHostName, char *pChPort)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; bool bRet = false;
NSDictionary *proxyConfiguration = NSMakeCollectable([(NSDictionary*) SCDynamicStoreCopyProxies(NULL) autorelease]); if (!proxyConfiguration)
{
[pool release];
return bRet;
} //Init proxy type
NSString *nsStrProxyEnable = nil;
NSString *nsStrProxyHostName = nil;
NSString *nsStrProxyPort = nil;
if ( == iProxyType)
{
nsStrProxyEnable = (NSString*)[proxyConfiguration objectForKey:@"HTTPSEnable"];
nsStrProxyHostName = (NSString*)[proxyConfiguration objectForKey:@"HTTPSProxy"];
nsStrProxyPort = [NSString stringWithFormat:@"%d", [[proxyConfiguration objectForKey:@"HTTPSPort"] intValue]];
}
else
{
nsStrProxyEnable = (NSString*)[proxyConfiguration objectForKey:@"HTTPEnable"];
nsStrProxyHostName = (NSString*)[proxyConfiguration objectForKey:@"HTTPProxy"];
nsStrProxyPort = [NSString stringWithFormat:@"%d", [[proxyConfiguration objectForKey:@"HTTPPort"] intValue]];
} int iProxyEnable = [nsStrProxyEnable intValue];
if ( == iProxyEnable)
{
const char *pHostName = [nsStrProxyHostName UTF8String];
int iLen = [nsStrProxyHostName length];
memset(pChHostName, , );
memcpy(pChHostName, pHostName, iLen); const char *pPort = [nsStrProxyPort UTF8String];
iLen = [nsStrProxyPort length];
memset(pChPort, , );
memcpy(pChPort, pPort, iLen);
bRet = true;
} [pool drain];
return bRet;
}