]> git.ipfire.org Git - thirdparty/cups.git/blame - tools/testbtmm.c
Mirror fix from trunk.
[thirdparty/cups.git] / tools / testbtmm.c
CommitLineData
a29fd7dd
MS
1/*
2 * Simple test program that lists the Back to My Mac domains on a Mac.
3 *
4 * Compile with:
5 *
6 * clang -o testbtmm -g testbtmm.c -framework SystemConfiguration -framework CoreFoundation
7 */
8
9#include <stdio.h>
10#include <CoreFoundation/CoreFoundation.h>
11#include <SystemConfiguration/SystemConfiguration.h>
12
13
14/*
15 * 'dnssdAddAlias()' - Add a DNS-SD alias name.
16 */
17
18static void
19show_domain(const void *key, /* I - Key */
20 const void *value, /* I - Value (domain) */
21 void *context) /* I - Unused */
22{
23 char valueStr[1024]; /* Domain string */
24
25
26 (void)key;
27 (void)context;
28
29 if (CFGetTypeID((CFStringRef)value) == CFStringGetTypeID() &&
30 CFStringGetCString((CFStringRef)value, valueStr, sizeof(valueStr),
31 kCFStringEncodingUTF8))
32 printf("Back to My Mac domain: \"%s\"\n", valueStr);
33 else
34 puts("Bad Back to My Mac domain in dynamic store.");
35}
36
37
38int
39main(void)
40{
41 SCDynamicStoreRef sc; /* Context for dynamic store */
42 CFDictionaryRef btmm; /* Back-to-My-Mac domains */
43
44
45 sc = SCDynamicStoreCreate(kCFAllocatorDefault, CFSTR("cups"), NULL, NULL);
46
47 if (!sc)
48 {
49 puts("Unable to open dynamic store.");
50 exit(1);
51 }
52
53 btmm = SCDynamicStoreCopyValue(sc, CFSTR("Setup:/Network/BackToMyMac"));
54 if (btmm && CFGetTypeID(btmm) == CFDictionaryGetTypeID())
55 {
56 printf("%d Back to My Mac domains.\n", (int)CFDictionaryGetCount(btmm));
57 CFDictionaryApplyFunction(btmm, show_domain, NULL);
58 }
59 else if (btmm)
60 puts("Bad Back to My Mac data in dynamic store.");
61 else
62 puts("No Back to My Mac domains.");
63
64 return (1);
65}