From 19898f967231b65962f0a9354fa86814aa130ed0 Mon Sep 17 00:00:00 2001 From: mike Date: Mon, 7 May 2012 22:37:44 +0000 Subject: [PATCH] Add small test program to list btmm domains. git-svn-id: svn+ssh://src.apple.com/svn/cups/cups.org/trunk@10454 7a7537e8-13f0-0310-91df-b6672ffda945 --- tools/testbtmm.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 tools/testbtmm.c diff --git a/tools/testbtmm.c b/tools/testbtmm.c new file mode 100644 index 0000000000..bd6379f84a --- /dev/null +++ b/tools/testbtmm.c @@ -0,0 +1,65 @@ +/* + * Simple test program that lists the Back to My Mac domains on a Mac. + * + * Compile with: + * + * clang -o testbtmm -g testbtmm.c -framework SystemConfiguration -framework CoreFoundation + */ + +#include +#include +#include + + +/* + * 'dnssdAddAlias()' - Add a DNS-SD alias name. + */ + +static void +show_domain(const void *key, /* I - Key */ + const void *value, /* I - Value (domain) */ + void *context) /* I - Unused */ +{ + char valueStr[1024]; /* Domain string */ + + + (void)key; + (void)context; + + if (CFGetTypeID((CFStringRef)value) == CFStringGetTypeID() && + CFStringGetCString((CFStringRef)value, valueStr, sizeof(valueStr), + kCFStringEncodingUTF8)) + printf("Back to My Mac domain: \"%s\"\n", valueStr); + else + puts("Bad Back to My Mac domain in dynamic store."); +} + + +int +main(void) +{ + SCDynamicStoreRef sc; /* Context for dynamic store */ + CFDictionaryRef btmm; /* Back-to-My-Mac domains */ + + + sc = SCDynamicStoreCreate(kCFAllocatorDefault, CFSTR("cups"), NULL, NULL); + + if (!sc) + { + puts("Unable to open dynamic store."); + exit(1); + } + + btmm = SCDynamicStoreCopyValue(sc, CFSTR("Setup:/Network/BackToMyMac")); + if (btmm && CFGetTypeID(btmm) == CFDictionaryGetTypeID()) + { + printf("%d Back to My Mac domains.\n", (int)CFDictionaryGetCount(btmm)); + CFDictionaryApplyFunction(btmm, show_domain, NULL); + } + else if (btmm) + puts("Bad Back to My Mac data in dynamic store."); + else + puts("No Back to My Mac domains."); + + return (1); +} -- 2.47.3