2 This file is part of avahi.
4 avahi is free software; you can redistribute it and/or modify it
5 under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 2.1 of the
7 License, or (at your option) any later version.
9 avahi is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
12 Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with avahi; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
24 #include <sys/types.h>
28 #include <avahi-common/gccmacro.h>
31 static void hexdump(const void* p, size_t size) {
35 printf("Dumping %zu bytes from %p:\n", size, p);
40 for (i = 0; i < 16; i++) {
42 printf("%02x ", c[i]);
47 for (i = 0; i < 16; i++) {
49 printf("%c", c[i] >= 32 && c[i] < 127 ? c[i] : '.');
66 int main(AVAHI_GCC_UNUSED int argc, AVAHI_GCC_UNUSED char *argv[]) {
73 TXTRecordCreate(&ref, 0, NULL);
75 hexdump(TXTRecordGetBytesPtr(&ref), TXTRecordGetLength(&ref));
77 TXTRecordSetValue(&ref, "foo", 7, "lennart");
78 hexdump(TXTRecordGetBytesPtr(&ref), TXTRecordGetLength(&ref));
80 TXTRecordSetValue(&ref, "waldo", 5, "rocks");
81 hexdump(TXTRecordGetBytesPtr(&ref), TXTRecordGetLength(&ref));
83 TXTRecordSetValue(&ref, "quux", 9, "the_house");
84 hexdump(TXTRecordGetBytesPtr(&ref), TXTRecordGetLength(&ref));
86 TXTRecordSetValue(&ref, "yeah", 0, NULL);
87 hexdump(TXTRecordGetBytesPtr(&ref), TXTRecordGetLength(&ref));
89 TXTRecordSetValue(&ref, "waldo", 6, "rocked");
90 hexdump(TXTRecordGetBytesPtr(&ref), TXTRecordGetLength(&ref));
92 TXTRecordRemoveValue(&ref, "foo");
93 hexdump(TXTRecordGetBytesPtr(&ref), TXTRecordGetLength(&ref));
95 TXTRecordRemoveValue(&ref, "waldo");
96 hexdump(TXTRecordGetBytesPtr(&ref), TXTRecordGetLength(&ref));
98 TXTRecordSetValue(&ref, "kawumm", 6, "bloerb");
99 hexdump(TXTRecordGetBytesPtr(&ref), TXTRecordGetLength(&ref));
101 TXTRecordSetValue(&ref, "one", 1, "1");
102 hexdump(TXTRecordGetBytesPtr(&ref), TXTRecordGetLength(&ref));
104 TXTRecordSetValue(&ref, "two", 1, "2");
105 hexdump(TXTRecordGetBytesPtr(&ref), TXTRecordGetLength(&ref));
107 TXTRecordSetValue(&ref, "three", 1, "3");
108 hexdump(TXTRecordGetBytesPtr(&ref), TXTRecordGetLength(&ref));
110 assert(TXTRecordContainsKey(TXTRecordGetLength(&ref), TXTRecordGetBytesPtr(&ref), "two"));
111 assert(!TXTRecordContainsKey(TXTRecordGetLength(&ref), TXTRecordGetBytesPtr(&ref), "four"));
113 r = TXTRecordGetValuePtr(TXTRecordGetLength(&ref), TXTRecordGetBytesPtr(&ref), "kawumm", &l);
117 assert(TXTRecordGetCount(TXTRecordGetLength(&ref), TXTRecordGetBytesPtr(&ref)) == 6);
119 TXTRecordGetItemAtIndex(TXTRecordGetLength(&ref), TXTRecordGetBytesPtr(&ref), 2, sizeof(k), k, &l, &p);
121 fprintf(stderr, "key=<%s>\n", k);
125 assert(TXTRecordGetItemAtIndex(TXTRecordGetLength(&ref), TXTRecordGetBytesPtr(&ref), 20, sizeof(k), k, &l, &p) == kDNSServiceErr_Invalid);
127 TXTRecordDeallocate(&ref);