gdi32: Re-create the brush bits only when the ROP has really changed.
[wine/multimedia.git] / dlls / dnsapi / record.c
blobae313166f67234df7c05ceabe84b25d8346cb2f4
1 /*
2 * DNS support
4 * Copyright (C) 2006 Hans Leidekker
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "config.h"
22 #include "wine/port.h"
23 #include "wine/debug.h"
25 #include <stdarg.h>
26 #include <string.h>
27 #include <sys/types.h>
29 #ifdef HAVE_NETINET_IN_H
30 # include <netinet/in.h>
31 #endif
32 #ifdef HAVE_ARPA_NAMESER_H
33 # include <arpa/nameser.h>
34 #endif
35 #ifdef HAVE_RESOLV_H
36 # include <resolv.h>
37 #endif
39 #include "windef.h"
40 #include "winbase.h"
41 #include "winnls.h"
42 #include "windns.h"
44 #include "dnsapi.h"
46 WINE_DEFAULT_DEBUG_CHANNEL(dnsapi);
48 const char *dns_type_to_str( unsigned short type )
50 switch (type)
52 #define X(x) case (x): return #x;
53 X(DNS_TYPE_ZERO)
54 X(DNS_TYPE_A)
55 X(DNS_TYPE_NS)
56 X(DNS_TYPE_MD)
57 X(DNS_TYPE_MF)
58 X(DNS_TYPE_CNAME)
59 X(DNS_TYPE_SOA)
60 X(DNS_TYPE_MB)
61 X(DNS_TYPE_MG)
62 X(DNS_TYPE_MR)
63 X(DNS_TYPE_NULL)
64 X(DNS_TYPE_WKS)
65 X(DNS_TYPE_PTR)
66 X(DNS_TYPE_HINFO)
67 X(DNS_TYPE_MINFO)
68 X(DNS_TYPE_MX)
69 X(DNS_TYPE_TEXT)
70 X(DNS_TYPE_RP)
71 X(DNS_TYPE_AFSDB)
72 X(DNS_TYPE_X25)
73 X(DNS_TYPE_ISDN)
74 X(DNS_TYPE_RT)
75 X(DNS_TYPE_NSAP)
76 X(DNS_TYPE_NSAPPTR)
77 X(DNS_TYPE_SIG)
78 X(DNS_TYPE_KEY)
79 X(DNS_TYPE_PX)
80 X(DNS_TYPE_GPOS)
81 X(DNS_TYPE_AAAA)
82 X(DNS_TYPE_LOC)
83 X(DNS_TYPE_NXT)
84 X(DNS_TYPE_EID)
85 X(DNS_TYPE_NIMLOC)
86 X(DNS_TYPE_SRV)
87 X(DNS_TYPE_ATMA)
88 X(DNS_TYPE_NAPTR)
89 X(DNS_TYPE_KX)
90 X(DNS_TYPE_CERT)
91 X(DNS_TYPE_A6)
92 X(DNS_TYPE_DNAME)
93 X(DNS_TYPE_SINK)
94 X(DNS_TYPE_OPT)
95 X(DNS_TYPE_UINFO)
96 X(DNS_TYPE_UID)
97 X(DNS_TYPE_GID)
98 X(DNS_TYPE_UNSPEC)
99 X(DNS_TYPE_ADDRS)
100 X(DNS_TYPE_TKEY)
101 X(DNS_TYPE_TSIG)
102 X(DNS_TYPE_IXFR)
103 X(DNS_TYPE_AXFR)
104 X(DNS_TYPE_MAILB)
105 X(DNS_TYPE_MAILA)
106 X(DNS_TYPE_ANY)
107 X(DNS_TYPE_WINS)
108 X(DNS_TYPE_WINSR)
109 #undef X
110 default: { static char tmp[7]; sprintf( tmp, "0x%04x", type ); return tmp; }
114 static int dns_strcmpX( LPCVOID str1, LPCVOID str2, BOOL wide )
116 if (wide)
117 return lstrcmpiW( str1, str2 );
118 else
119 return lstrcmpiA( str1, str2 );
122 /******************************************************************************
123 * DnsRecordCompare [DNSAPI.@]
126 BOOL WINAPI DnsRecordCompare( PDNS_RECORD r1, PDNS_RECORD r2 )
128 BOOL wide;
129 unsigned int i;
131 TRACE( "(%p,%p)\n", r1, r2 );
133 if (r1->wType != r2->wType ||
134 r1->wDataLength != r2->wDataLength ||
135 r1->Flags.DW != r2->Flags.DW ||
136 r1->dwReserved != r2->dwReserved) return FALSE;
138 wide = (r1->Flags.S.CharSet == DnsCharSetUnicode) ? TRUE : FALSE;
139 if (dns_strcmpX( r1->pName, r2->pName, wide )) return FALSE;
141 switch (r1->wType)
143 case DNS_TYPE_A:
145 if (r1->Data.A.IpAddress != r2->Data.A.IpAddress) return FALSE;
146 break;
148 case DNS_TYPE_SOA:
150 if (r1->Data.SOA.dwSerialNo != r2->Data.SOA.dwSerialNo ||
151 r1->Data.SOA.dwRefresh != r2->Data.SOA.dwRefresh ||
152 r1->Data.SOA.dwRetry != r2->Data.SOA.dwRetry ||
153 r1->Data.SOA.dwExpire != r2->Data.SOA.dwExpire ||
154 r1->Data.SOA.dwDefaultTtl != r2->Data.SOA.dwDefaultTtl)
155 return FALSE;
156 if (dns_strcmpX( r1->Data.SOA.pNamePrimaryServer,
157 r2->Data.SOA.pNamePrimaryServer, wide ) ||
158 dns_strcmpX( r1->Data.SOA.pNameAdministrator,
159 r2->Data.SOA.pNameAdministrator, wide ))
160 return FALSE;
161 break;
163 case DNS_TYPE_PTR:
164 case DNS_TYPE_NS:
165 case DNS_TYPE_CNAME:
166 case DNS_TYPE_MB:
167 case DNS_TYPE_MD:
168 case DNS_TYPE_MF:
169 case DNS_TYPE_MG:
170 case DNS_TYPE_MR:
172 if (dns_strcmpX( r1->Data.PTR.pNameHost,
173 r2->Data.PTR.pNameHost, wide )) return FALSE;
174 break;
176 case DNS_TYPE_MINFO:
177 case DNS_TYPE_RP:
179 if (dns_strcmpX( r1->Data.MINFO.pNameMailbox,
180 r2->Data.MINFO.pNameMailbox, wide ) ||
181 dns_strcmpX( r1->Data.MINFO.pNameErrorsMailbox,
182 r2->Data.MINFO.pNameErrorsMailbox, wide ))
183 return FALSE;
184 break;
186 case DNS_TYPE_MX:
187 case DNS_TYPE_AFSDB:
188 case DNS_TYPE_RT:
190 if (r1->Data.MX.wPreference != r2->Data.MX.wPreference)
191 return FALSE;
192 if (dns_strcmpX( r1->Data.MX.pNameExchange,
193 r2->Data.MX.pNameExchange, wide ))
194 return FALSE;
195 break;
197 case DNS_TYPE_HINFO:
198 case DNS_TYPE_ISDN:
199 case DNS_TYPE_TEXT:
200 case DNS_TYPE_X25:
202 if (r1->Data.TXT.dwStringCount != r2->Data.TXT.dwStringCount)
203 return FALSE;
204 for (i = 0; i < r1->Data.TXT.dwStringCount; i++)
206 if (dns_strcmpX( r1->Data.TXT.pStringArray[i],
207 r2->Data.TXT.pStringArray[i], wide ))
208 return FALSE;
210 break;
212 case DNS_TYPE_NULL:
214 if (r1->Data.Null.dwByteCount != r2->Data.Null.dwByteCount)
215 return FALSE;
216 if (memcmp( r1->Data.Null.Data,
217 r2->Data.Null.Data, r1->Data.Null.dwByteCount ))
218 return FALSE;
219 break;
221 case DNS_TYPE_AAAA:
223 for (i = 0; i < sizeof(IP6_ADDRESS)/sizeof(DWORD); i++)
225 if (r1->Data.AAAA.Ip6Address.IP6Dword[i] !=
226 r2->Data.AAAA.Ip6Address.IP6Dword[i]) return FALSE;
228 break;
230 case DNS_TYPE_KEY:
232 if (r1->Data.KEY.wFlags != r2->Data.KEY.wFlags ||
233 r1->Data.KEY.chProtocol != r2->Data.KEY.chProtocol ||
234 r1->Data.KEY.chAlgorithm != r2->Data.KEY.chAlgorithm)
235 return FALSE;
236 if (memcmp( r1->Data.KEY.Key, r2->Data.KEY.Key,
237 r1->wDataLength - sizeof(DNS_KEY_DATA) + 1 ))
238 return FALSE;
239 break;
241 case DNS_TYPE_SIG:
243 if (dns_strcmpX( r1->Data.SIG.pNameSigner,
244 r2->Data.SIG.pNameSigner, wide ))
245 return FALSE;
246 if (r1->Data.SIG.wTypeCovered != r2->Data.SIG.wTypeCovered ||
247 r1->Data.SIG.chAlgorithm != r2->Data.SIG.chAlgorithm ||
248 r1->Data.SIG.chLabelCount != r2->Data.SIG.chLabelCount ||
249 r1->Data.SIG.dwOriginalTtl != r2->Data.SIG.dwOriginalTtl ||
250 r1->Data.SIG.dwExpiration != r2->Data.SIG.dwExpiration ||
251 r1->Data.SIG.dwTimeSigned != r2->Data.SIG.dwTimeSigned ||
252 r1->Data.SIG.wKeyTag != r2->Data.SIG.wKeyTag)
253 return FALSE;
254 if (memcmp( r1->Data.SIG.Signature, r2->Data.SIG.Signature,
255 r1->wDataLength - sizeof(DNS_SIG_DATAA) + 1 ))
256 return FALSE;
257 break;
259 case DNS_TYPE_ATMA:
261 if (r1->Data.ATMA.AddressType != r2->Data.ATMA.AddressType)
262 return FALSE;
263 for (i = 0; i < DNS_ATMA_MAX_ADDR_LENGTH; i++)
265 if (r1->Data.ATMA.Address[i] != r2->Data.ATMA.Address[i])
266 return FALSE;
268 break;
270 case DNS_TYPE_NXT:
272 if (dns_strcmpX( r1->Data.NXT.pNameNext,
273 r2->Data.NXT.pNameNext, wide )) return FALSE;
274 if (r1->Data.NXT.wNumTypes != r2->Data.NXT.wNumTypes) return FALSE;
275 if (memcmp( r1->Data.NXT.wTypes, r2->Data.NXT.wTypes,
276 r1->wDataLength - sizeof(DNS_NXT_DATAA) + sizeof(WORD) ))
277 return FALSE;
278 break;
280 case DNS_TYPE_SRV:
282 if (dns_strcmpX( r1->Data.SRV.pNameTarget,
283 r2->Data.SRV.pNameTarget, wide )) return FALSE;
284 if (r1->Data.SRV.wPriority != r2->Data.SRV.wPriority ||
285 r1->Data.SRV.wWeight != r2->Data.SRV.wWeight ||
286 r1->Data.SRV.wPort != r2->Data.SRV.wPort)
287 return FALSE;
288 break;
290 case DNS_TYPE_TKEY:
292 if (dns_strcmpX( r1->Data.TKEY.pNameAlgorithm,
293 r2->Data.TKEY.pNameAlgorithm, wide ))
294 return FALSE;
295 if (r1->Data.TKEY.dwCreateTime != r2->Data.TKEY.dwCreateTime ||
296 r1->Data.TKEY.dwExpireTime != r2->Data.TKEY.dwExpireTime ||
297 r1->Data.TKEY.wMode != r2->Data.TKEY.wMode ||
298 r1->Data.TKEY.wError != r2->Data.TKEY.wError ||
299 r1->Data.TKEY.wKeyLength != r2->Data.TKEY.wKeyLength ||
300 r1->Data.TKEY.wOtherLength != r2->Data.TKEY.wOtherLength ||
301 r1->Data.TKEY.cAlgNameLength != r2->Data.TKEY.cAlgNameLength ||
302 r1->Data.TKEY.bPacketPointers != r2->Data.TKEY.bPacketPointers)
303 return FALSE;
305 /* FIXME: ignoring pAlgorithmPacket field */
306 if (memcmp( r1->Data.TKEY.pKey, r2->Data.TKEY.pKey,
307 r1->Data.TKEY.wKeyLength ) ||
308 memcmp( r1->Data.TKEY.pOtherData, r2->Data.TKEY.pOtherData,
309 r1->Data.TKEY.wOtherLength )) return FALSE;
310 break;
312 case DNS_TYPE_TSIG:
314 if (dns_strcmpX( r1->Data.TSIG.pNameAlgorithm,
315 r2->Data.TSIG.pNameAlgorithm, wide ))
316 return FALSE;
317 if (r1->Data.TSIG.i64CreateTime != r2->Data.TSIG.i64CreateTime ||
318 r1->Data.TSIG.wFudgeTime != r2->Data.TSIG.wFudgeTime ||
319 r1->Data.TSIG.wOriginalXid != r2->Data.TSIG.wOriginalXid ||
320 r1->Data.TSIG.wError != r2->Data.TSIG.wError ||
321 r1->Data.TSIG.wSigLength != r2->Data.TSIG.wSigLength ||
322 r1->Data.TSIG.wOtherLength != r2->Data.TSIG.wOtherLength ||
323 r1->Data.TSIG.cAlgNameLength != r2->Data.TSIG.cAlgNameLength ||
324 r1->Data.TSIG.bPacketPointers != r2->Data.TSIG.bPacketPointers)
325 return FALSE;
327 /* FIXME: ignoring pAlgorithmPacket field */
328 if (memcmp( r1->Data.TSIG.pSignature, r2->Data.TSIG.pSignature,
329 r1->Data.TSIG.wSigLength ) ||
330 memcmp( r1->Data.TSIG.pOtherData, r2->Data.TSIG.pOtherData,
331 r1->Data.TSIG.wOtherLength )) return FALSE;
332 break;
334 case DNS_TYPE_WINS:
336 if (r1->Data.WINS.dwMappingFlag != r2->Data.WINS.dwMappingFlag ||
337 r1->Data.WINS.dwLookupTimeout != r2->Data.WINS.dwLookupTimeout ||
338 r1->Data.WINS.dwCacheTimeout != r2->Data.WINS.dwCacheTimeout ||
339 r1->Data.WINS.cWinsServerCount != r2->Data.WINS.cWinsServerCount)
340 return FALSE;
341 if (memcmp( r1->Data.WINS.WinsServers, r2->Data.WINS.WinsServers,
342 r1->wDataLength - sizeof(DNS_WINS_DATA) + sizeof(IP4_ADDRESS) ))
343 return FALSE;
344 break;
346 case DNS_TYPE_WINSR:
348 if (r1->Data.WINSR.dwMappingFlag != r2->Data.WINSR.dwMappingFlag ||
349 r1->Data.WINSR.dwLookupTimeout != r2->Data.WINSR.dwLookupTimeout ||
350 r1->Data.WINSR.dwCacheTimeout != r2->Data.WINSR.dwCacheTimeout)
351 return FALSE;
352 if (dns_strcmpX( r1->Data.WINSR.pNameResultDomain,
353 r2->Data.WINSR.pNameResultDomain, wide ))
354 return FALSE;
355 break;
357 default:
358 FIXME( "unknown type: %s\n", dns_type_to_str( r1->wType ) );
359 return FALSE;
361 return TRUE;
364 static LPVOID dns_strcpyX( LPCVOID src, DNS_CHARSET in, DNS_CHARSET out )
366 switch (in)
368 case DnsCharSetUnicode:
370 switch (out)
372 case DnsCharSetUnicode: return dns_strdup_w( src );
373 case DnsCharSetUtf8: return dns_strdup_wu( src );
374 case DnsCharSetAnsi: return dns_strdup_wa( src );
375 default:
376 WARN( "unhandled target charset: %d\n", out );
377 break;
379 break;
381 case DnsCharSetUtf8:
382 switch (out)
384 case DnsCharSetUnicode: return dns_strdup_uw( src );
385 case DnsCharSetUtf8: return dns_strdup_u( src );
386 case DnsCharSetAnsi: return dns_strdup_ua( src );
387 default:
388 WARN( "unhandled target charset: %d\n", out );
389 break;
391 break;
392 case DnsCharSetAnsi:
393 switch (out)
395 case DnsCharSetUnicode: return dns_strdup_aw( src );
396 case DnsCharSetUtf8: return dns_strdup_au( src );
397 case DnsCharSetAnsi: return dns_strdup_a( src );
398 default:
399 WARN( "unhandled target charset: %d\n", out );
400 break;
402 break;
403 default:
404 WARN( "unhandled source charset: %d\n", in );
405 break;
407 return NULL;
410 /******************************************************************************
411 * DnsRecordCopyEx [DNSAPI.@]
414 PDNS_RECORD WINAPI DnsRecordCopyEx( PDNS_RECORD src, DNS_CHARSET in, DNS_CHARSET out )
416 DNS_RECORD *dst;
417 unsigned int i, size;
419 TRACE( "(%p,%d,%d)\n", src, in, out );
421 size = FIELD_OFFSET(DNS_RECORD, Data) + src->wDataLength;
422 dst = heap_alloc_zero( size );
423 if (!dst) return NULL;
425 memcpy( dst, src, size );
427 if (src->Flags.S.CharSet == DnsCharSetUtf8 ||
428 src->Flags.S.CharSet == DnsCharSetAnsi ||
429 src->Flags.S.CharSet == DnsCharSetUnicode) in = src->Flags.S.CharSet;
431 dst->Flags.S.CharSet = out;
432 dst->pName = dns_strcpyX( src->pName, in, out );
433 if (!dst->pName) goto error;
435 switch (src->wType)
437 case DNS_TYPE_HINFO:
438 case DNS_TYPE_ISDN:
439 case DNS_TYPE_TEXT:
440 case DNS_TYPE_X25:
442 for (i = 0; i < src->Data.TXT.dwStringCount; i++)
444 dst->Data.TXT.pStringArray[i] =
445 dns_strcpyX( src->Data.TXT.pStringArray[i], in, out );
447 if (!dst->Data.TXT.pStringArray[i])
449 while (i > 0) heap_free( dst->Data.TXT.pStringArray[--i] );
450 goto error;
453 break;
455 case DNS_TYPE_MINFO:
456 case DNS_TYPE_RP:
458 dst->Data.MINFO.pNameMailbox =
459 dns_strcpyX( src->Data.MINFO.pNameMailbox, in, out );
460 if (!dst->Data.MINFO.pNameMailbox) goto error;
462 dst->Data.MINFO.pNameErrorsMailbox =
463 dns_strcpyX( src->Data.MINFO.pNameErrorsMailbox, in, out );
464 if (!dst->Data.MINFO.pNameErrorsMailbox)
466 heap_free( dst->Data.MINFO.pNameMailbox );
467 goto error;
469 break;
471 case DNS_TYPE_AFSDB:
472 case DNS_TYPE_RT:
473 case DNS_TYPE_MX:
475 dst->Data.MX.pNameExchange =
476 dns_strcpyX( src->Data.MX.pNameExchange, in, out );
477 if (!dst->Data.MX.pNameExchange) goto error;
478 break;
480 case DNS_TYPE_NXT:
482 dst->Data.NXT.pNameNext =
483 dns_strcpyX( src->Data.NXT.pNameNext, in, out );
484 if (!dst->Data.NXT.pNameNext) goto error;
485 break;
487 case DNS_TYPE_CNAME:
488 case DNS_TYPE_MB:
489 case DNS_TYPE_MD:
490 case DNS_TYPE_MF:
491 case DNS_TYPE_MG:
492 case DNS_TYPE_MR:
493 case DNS_TYPE_NS:
494 case DNS_TYPE_PTR:
496 dst->Data.PTR.pNameHost =
497 dns_strcpyX( src->Data.PTR.pNameHost, in, out );
498 if (!dst->Data.PTR.pNameHost) goto error;
499 break;
501 case DNS_TYPE_SIG:
503 dst->Data.SIG.pNameSigner =
504 dns_strcpyX( src->Data.SIG.pNameSigner, in, out );
505 if (!dst->Data.SIG.pNameSigner) goto error;
506 break;
508 case DNS_TYPE_SOA:
510 dst->Data.SOA.pNamePrimaryServer =
511 dns_strcpyX( src->Data.SOA.pNamePrimaryServer, in, out );
512 if (!dst->Data.SOA.pNamePrimaryServer) goto error;
514 dst->Data.SOA.pNameAdministrator =
515 dns_strcpyX( src->Data.SOA.pNameAdministrator, in, out );
516 if (!dst->Data.SOA.pNameAdministrator)
518 heap_free( dst->Data.SOA.pNamePrimaryServer );
519 goto error;
521 break;
523 case DNS_TYPE_SRV:
525 dst->Data.SRV.pNameTarget =
526 dns_strcpyX( src->Data.SRV.pNameTarget, in, out );
527 if (!dst->Data.SRV.pNameTarget) goto error;
528 break;
530 default:
531 break;
533 return dst;
535 error:
536 heap_free( dst->pName );
537 heap_free( dst );
538 return NULL;
541 /******************************************************************************
542 * DnsRecordListFree [DNSAPI.@]
545 VOID WINAPI DnsRecordListFree( PDNS_RECORD list, DNS_FREE_TYPE type )
547 DNS_RECORD *r, *next;
548 unsigned int i;
550 TRACE( "(%p,%d)\n", list, type );
552 if (!list) return;
554 switch (type)
556 case DnsFreeRecordList:
558 for (r = list; (list = r); r = next)
560 heap_free( r->pName );
562 switch (r->wType)
564 case DNS_TYPE_HINFO:
565 case DNS_TYPE_ISDN:
566 case DNS_TYPE_TEXT:
567 case DNS_TYPE_X25:
569 for (i = 0; i < r->Data.TXT.dwStringCount; i++)
570 heap_free( r->Data.TXT.pStringArray[i] );
572 break;
574 case DNS_TYPE_MINFO:
575 case DNS_TYPE_RP:
577 heap_free( r->Data.MINFO.pNameMailbox );
578 heap_free( r->Data.MINFO.pNameErrorsMailbox );
579 break;
581 case DNS_TYPE_AFSDB:
582 case DNS_TYPE_RT:
583 case DNS_TYPE_MX:
585 heap_free( r->Data.MX.pNameExchange );
586 break;
588 case DNS_TYPE_NXT:
590 heap_free( r->Data.NXT.pNameNext );
591 break;
593 case DNS_TYPE_CNAME:
594 case DNS_TYPE_MB:
595 case DNS_TYPE_MD:
596 case DNS_TYPE_MF:
597 case DNS_TYPE_MG:
598 case DNS_TYPE_MR:
599 case DNS_TYPE_NS:
600 case DNS_TYPE_PTR:
602 heap_free( r->Data.PTR.pNameHost );
603 break;
605 case DNS_TYPE_SIG:
607 heap_free( r->Data.SIG.pNameSigner );
608 break;
610 case DNS_TYPE_SOA:
612 heap_free( r->Data.SOA.pNamePrimaryServer );
613 heap_free( r->Data.SOA.pNameAdministrator );
614 break;
616 case DNS_TYPE_SRV:
618 heap_free( r->Data.SRV.pNameTarget );
619 break;
621 default:
622 break;
625 next = r->pNext;
626 heap_free( r );
628 break;
630 case DnsFreeFlat:
631 case DnsFreeParsedMessageFields:
633 FIXME( "unhandled free type: %d\n", type );
634 break;
636 default:
637 WARN( "unknown free type: %d\n", type );
638 break;
642 /******************************************************************************
643 * DnsFree [DNSAPI.@]
646 void WINAPI DnsFree( PVOID data, DNS_FREE_TYPE type )
648 DnsRecordListFree( data, type );
651 /******************************************************************************
652 * DnsRecordSetCompare [DNSAPI.@]
655 BOOL WINAPI DnsRecordSetCompare( PDNS_RECORD set1, PDNS_RECORD set2,
656 PDNS_RECORD *diff1, PDNS_RECORD *diff2 )
658 BOOL ret = TRUE;
659 DNS_RECORD *r, *t, *u;
660 DNS_RRSET rr1, rr2;
662 TRACE( "(%p,%p,%p,%p)\n", set1, set2, diff1, diff2 );
664 if (!set1 && !set2) return FALSE;
666 if (diff1) *diff1 = NULL;
667 if (diff2) *diff2 = NULL;
669 if (set1 && !set2)
671 if (diff1) *diff1 = DnsRecordSetCopyEx( set1, 0, set1->Flags.S.CharSet );
672 return FALSE;
674 if (!set1 && set2)
676 if (diff2) *diff2 = DnsRecordSetCopyEx( set2, 0, set2->Flags.S.CharSet );
677 return FALSE;
680 DNS_RRSET_INIT( rr1 );
681 DNS_RRSET_INIT( rr2 );
683 for (r = set1; r; r = r->pNext)
685 for (t = set2; t; t = t->pNext)
687 u = DnsRecordCopyEx( r, r->Flags.S.CharSet, t->Flags.S.CharSet );
688 if (!u) goto error;
690 if (!DnsRecordCompare( t, u ))
692 DNS_RRSET_ADD( rr1, u );
693 ret = FALSE;
695 else DnsRecordListFree( u, DnsFreeRecordList );
699 for (t = set2; t; t = t->pNext)
701 for (r = set1; r; r = r->pNext)
703 u = DnsRecordCopyEx( t, t->Flags.S.CharSet, r->Flags.S.CharSet );
704 if (!u) goto error;
706 if (!DnsRecordCompare( r, u ))
708 DNS_RRSET_ADD( rr2, u );
709 ret = FALSE;
711 else DnsRecordListFree( u, DnsFreeRecordList );
715 DNS_RRSET_TERMINATE( rr1 );
716 DNS_RRSET_TERMINATE( rr2 );
718 if (diff1) *diff1 = rr1.pFirstRR;
719 else DnsRecordListFree( rr1.pFirstRR, DnsFreeRecordList );
721 if (diff2) *diff2 = rr2.pFirstRR;
722 else DnsRecordListFree( rr2.pFirstRR, DnsFreeRecordList );
724 return ret;
726 error:
727 DNS_RRSET_TERMINATE( rr1 );
728 DNS_RRSET_TERMINATE( rr2 );
730 DnsRecordListFree( rr1.pFirstRR, DnsFreeRecordList );
731 DnsRecordListFree( rr2.pFirstRR, DnsFreeRecordList );
733 return FALSE;
736 /******************************************************************************
737 * DnsRecordSetCopyEx [DNSAPI.@]
740 PDNS_RECORD WINAPI DnsRecordSetCopyEx( PDNS_RECORD src_set, DNS_CHARSET in, DNS_CHARSET out )
742 DNS_RRSET dst_set;
743 DNS_RECORD *src, *dst;
745 TRACE( "(%p,%d,%d)\n", src_set, in, out );
747 DNS_RRSET_INIT( dst_set );
749 for (src = src_set; (src_set = src); src = src_set->pNext)
751 dst = DnsRecordCopyEx( src, in, out );
752 if (!dst)
754 DNS_RRSET_TERMINATE( dst_set );
755 DnsRecordListFree( dst_set.pFirstRR, DnsFreeRecordList );
756 return NULL;
758 DNS_RRSET_ADD( dst_set, dst );
761 DNS_RRSET_TERMINATE( dst_set );
762 return dst_set.pFirstRR;
765 /******************************************************************************
766 * DnsRecordSetDetach [DNSAPI.@]
769 PDNS_RECORD WINAPI DnsRecordSetDetach( PDNS_RECORD set )
771 DNS_RECORD *r, *s;
773 TRACE( "(%p)\n", set );
775 for (r = set; (set = r); r = set->pNext)
777 if (r->pNext && !r->pNext->pNext)
779 s = r->pNext;
780 r->pNext = NULL;
781 return s;
784 return NULL;