4 This file is part of avahi.
6 avahi is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as
8 published by the Free Software Foundation; either version 2.1 of the
9 License, or (at your option) any later version.
11 avahi is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
14 Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with avahi; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
26 #include <sys/types.h>
30 #include <avahi-common/gccmacro.h>
33 static void hexdump(const void* p, size_t size) {
37 printf("Dumping %u bytes from %p:\n", size, p);
42 for (i = 0; i < 16; i++) {
44 printf("%02x ", c[i]);
49 for (i = 0; i < 16; i++) {
51 printf("%c", c[i] >= 32 && c[i] < 127 ? c[i] : '.');
68 int main(AVAHI_GCC_UNUSED int argc, AVAHI_GCC_UNUSED char *argv[]) {
75 TXTRecordCreate(&ref, 0, NULL);
77 hexdump(TXTRecordGetBytesPtr(&ref), TXTRecordGetLength(&ref));
79 TXTRecordSetValue(&ref, "foo", 7, "lennart");
80 hexdump(TXTRecordGetBytesPtr(&ref), TXTRecordGetLength(&ref));
82 TXTRecordSetValue(&ref, "waldo", 5, "rocks");
83 hexdump(TXTRecordGetBytesPtr(&ref), TXTRecordGetLength(&ref));
85 TXTRecordSetValue(&ref, "quux", 9, "the_house");
86 hexdump(TXTRecordGetBytesPtr(&ref), TXTRecordGetLength(&ref));
88 TXTRecordSetValue(&ref, "yeah", 0, NULL);
89 hexdump(TXTRecordGetBytesPtr(&ref), TXTRecordGetLength(&ref));
91 TXTRecordSetValue(&ref, "waldo", 6, "rocked");
92 hexdump(TXTRecordGetBytesPtr(&ref), TXTRecordGetLength(&ref));
94 TXTRecordRemoveValue(&ref, "foo");
95 hexdump(TXTRecordGetBytesPtr(&ref), TXTRecordGetLength(&ref));
97 TXTRecordRemoveValue(&ref, "waldo");
98 hexdump(TXTRecordGetBytesPtr(&ref), TXTRecordGetLength(&ref));
100 TXTRecordSetValue(&ref, "kawumm", 6, "bloerb");
101 hexdump(TXTRecordGetBytesPtr(&ref), TXTRecordGetLength(&ref));
103 TXTRecordSetValue(&ref, "one", 1, "1");
104 hexdump(TXTRecordGetBytesPtr(&ref), TXTRecordGetLength(&ref));
106 TXTRecordSetValue(&ref, "two", 1, "2");
107 hexdump(TXTRecordGetBytesPtr(&ref), TXTRecordGetLength(&ref));
109 TXTRecordSetValue(&ref, "three", 1, "3");
110 hexdump(TXTRecordGetBytesPtr(&ref), TXTRecordGetLength(&ref));
112 assert(TXTRecordContainsKey(TXTRecordGetLength(&ref), TXTRecordGetBytesPtr(&ref), "two"));
113 assert(!TXTRecordContainsKey(TXTRecordGetLength(&ref), TXTRecordGetBytesPtr(&ref), "four"));
115 r = TXTRecordGetValuePtr(TXTRecordGetLength(&ref), TXTRecordGetBytesPtr(&ref), "kawumm", &l);
119 assert(TXTRecordGetCount(TXTRecordGetLength(&ref), TXTRecordGetBytesPtr(&ref)) == 6);
121 TXTRecordGetItemAtIndex(TXTRecordGetLength(&ref), TXTRecordGetBytesPtr(&ref), 2, sizeof(k), k, &l, &p);
123 fprintf(stderr, "key=<%s>\n", k);
127 assert(TXTRecordGetItemAtIndex(TXTRecordGetLength(&ref), TXTRecordGetBytesPtr(&ref), 20, sizeof(k), k, &l, &p) == kDNSServiceErr_Invalid);
129 TXTRecordDeallocate(&ref);