3 #import <Foundation/Foundation.h>
4 #import <SystemConfiguration/SCDynamicStoreCopySpecific.h>
7 DXPrint(NSString* format, ...)
10 va_start(args, format);
11 NSString* string = [[NSString alloc] initWithFormat:format arguments:args];
13 fputs([string UTF8String], stdout);
20 NSDictionary* proxies;
24 printUnset(NSString* env)
26 DXPrint(@"unset %@\n", env);
30 printProxy(NSDictionary* proxies, NSString* proto)
33 NSString* env = [[proto lowercaseString] stringByAppendingString:@"_proxy"];
35 key = [proto stringByAppendingString:@"Enable"];
36 NSNumber* enabled = [proxies objectForKey:key];
37 if(enabled == nil || [enabled intValue] != 1) {
42 key = [proto stringByAppendingString:@"Proxy"];
43 id host = [proxies objectForKey:key];
49 key = [proto stringByAppendingString:@"Port"];
50 id port = [proxies objectForKey:key];
56 NSString* uriPrefix = nil;
57 if(![proto isEqual:@"SOCKS"]) {
58 uriPrefix = @"http://";
60 uriPrefix = @"socks://";
63 DXPrint(@"export %@='%@%@:%@'\n", env, uriPrefix, host, port);
68 printExceptions(NSDictionary* proxies)
70 id exceptions = [proxies objectForKey:@"ExceptionsList"];
71 if(exceptions == nil || ![exceptions isKindOfClass:[NSArray class]] || !proxyFound) {
72 printUnset(@"no_proxy");
76 DXPrint(@"export no_proxy='%@'\n", [exceptions componentsJoinedByString:@","]);
82 NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
84 proxies = (NSDictionary*)SCDynamicStoreCopyProxies(nil);
86 printProxy(proxies, @"HTTP");
87 printProxy(proxies, @"HTTPS");
88 printProxy(proxies, @"FTP");
89 printProxy(proxies, @"SOCKS");
90 printExceptions(proxies);