ntdll: Avoid inter-process APCs when called for the process itself.
[wine/multimedia.git] / dlls / dnsapi / record.c
blobeaba46a068f7cecd1dbd421331dbcfd71cfbb34d
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 "winerror.h"
42 #include "winnls.h"
43 #include "windns.h"
45 #include "dnsapi.h"
47 WINE_DEFAULT_DEBUG_CHANNEL(dnsapi);
49 const char *dns_type_to_str( unsigned short type )
51 switch (type)
53 #define X(x) case (x): return #x;
54 X(DNS_TYPE_ZERO)
55 X(DNS_TYPE_A)
56 X(DNS_TYPE_NS)
57 X(DNS_TYPE_MD)
58 X(DNS_TYPE_MF)
59 X(DNS_TYPE_CNAME)
60 X(DNS_TYPE_SOA)
61 X(DNS_TYPE_MB)
62 X(DNS_TYPE_MG)
63 X(DNS_TYPE_MR)
64 X(DNS_TYPE_NULL)
65 X(DNS_TYPE_WKS)
66 X(DNS_TYPE_PTR)
67 X(DNS_TYPE_HINFO)
68 X(DNS_TYPE_MINFO)
69 X(DNS_TYPE_MX)
70 X(DNS_TYPE_TEXT)
71 X(DNS_TYPE_RP)
72 X(DNS_TYPE_AFSDB)
73 X(DNS_TYPE_X25)
74 X(DNS_TYPE_ISDN)
75 X(DNS_TYPE_RT)
76 X(DNS_TYPE_NSAP)
77 X(DNS_TYPE_NSAPPTR)
78 X(DNS_TYPE_SIG)
79 X(DNS_TYPE_KEY)
80 X(DNS_TYPE_PX)
81 X(DNS_TYPE_GPOS)
82 X(DNS_TYPE_AAAA)
83 X(DNS_TYPE_LOC)
84 X(DNS_TYPE_NXT)
85 X(DNS_TYPE_EID)
86 X(DNS_TYPE_NIMLOC)
87 X(DNS_TYPE_SRV)
88 X(DNS_TYPE_ATMA)
89 X(DNS_TYPE_NAPTR)
90 X(DNS_TYPE_KX)
91 X(DNS_TYPE_CERT)
92 X(DNS_TYPE_A6)
93 X(DNS_TYPE_DNAME)
94 X(DNS_TYPE_SINK)
95 X(DNS_TYPE_OPT)
96 X(DNS_TYPE_UINFO)
97 X(DNS_TYPE_UID)
98 X(DNS_TYPE_GID)
99 X(DNS_TYPE_UNSPEC)
100 X(DNS_TYPE_ADDRS)
101 X(DNS_TYPE_TKEY)
102 X(DNS_TYPE_TSIG)
103 X(DNS_TYPE_IXFR)
104 X(DNS_TYPE_AXFR)
105 X(DNS_TYPE_MAILB)
106 X(DNS_TYPE_MAILA)
107 X(DNS_TYPE_ANY)
108 X(DNS_TYPE_WINS)
109 X(DNS_TYPE_WINSR)
110 #undef X
111 default: { static char tmp[7]; sprintf( tmp, "0x%04x", type ); return tmp; }
115 static int dns_strcmpX( LPCVOID str1, LPCVOID str2, BOOL wide )
117 if (wide)
118 return lstrcmpiW( str1, str2 );
119 else
120 return lstrcmpiA( str1, str2 );
123 /******************************************************************************
124 * DnsRecordCompare [DNSAPI.@]
127 BOOL WINAPI DnsRecordCompare( PDNS_RECORD r1, PDNS_RECORD r2 )
129 BOOL wide;
130 unsigned int i;
132 TRACE( "(%p,%p)\n", r1, r2 );
134 if (r1->wType != r2->wType ||
135 r1->wDataLength != r2->wDataLength ||
136 r1->Flags.DW != r2->Flags.DW ||
137 r1->dwReserved != r2->dwReserved) return FALSE;
139 wide = (r1->Flags.S.CharSet == DnsCharSetUnicode) ? TRUE : FALSE;
140 if (dns_strcmpX( r1->pName, r2->pName, wide )) return FALSE;
142 switch (r1->wType)
144 case DNS_TYPE_A:
146 if (r1->Data.A.IpAddress != r2->Data.A.IpAddress) return FALSE;
147 break;
149 case DNS_TYPE_SOA:
151 if (r1->Data.SOA.dwSerialNo != r2->Data.SOA.dwSerialNo ||
152 r1->Data.SOA.dwRefresh != r2->Data.SOA.dwRefresh ||
153 r1->Data.SOA.dwRetry != r2->Data.SOA.dwRetry ||
154 r1->Data.SOA.dwExpire != r2->Data.SOA.dwExpire ||
155 r1->Data.SOA.dwDefaultTtl != r2->Data.SOA.dwDefaultTtl)
156 return FALSE;
157 if (dns_strcmpX( r1->Data.SOA.pNamePrimaryServer,
158 r2->Data.SOA.pNamePrimaryServer, wide ) ||
159 dns_strcmpX( r1->Data.SOA.pNameAdministrator,
160 r2->Data.SOA.pNameAdministrator, wide ))
161 return FALSE;
162 break;
164 case DNS_TYPE_PTR:
165 case DNS_TYPE_NS:
166 case DNS_TYPE_CNAME:
167 case DNS_TYPE_MB:
168 case DNS_TYPE_MD:
169 case DNS_TYPE_MF:
170 case DNS_TYPE_MG:
171 case DNS_TYPE_MR:
173 if (dns_strcmpX( r1->Data.PTR.pNameHost,
174 r2->Data.PTR.pNameHost, wide )) return FALSE;
175 break;
177 case DNS_TYPE_MINFO:
178 case DNS_TYPE_RP:
180 if (dns_strcmpX( r1->Data.MINFO.pNameMailbox,
181 r2->Data.MINFO.pNameMailbox, wide ) ||
182 dns_strcmpX( r1->Data.MINFO.pNameErrorsMailbox,
183 r2->Data.MINFO.pNameErrorsMailbox, wide ))
184 return FALSE;
185 break;
187 case DNS_TYPE_MX:
188 case DNS_TYPE_AFSDB:
189 case DNS_TYPE_RT:
191 if (r1->Data.MX.wPreference != r2->Data.MX.wPreference)
192 return FALSE;
193 if (dns_strcmpX( r1->Data.MX.pNameExchange,
194 r2->Data.MX.pNameExchange, wide ))
195 return FALSE;
196 break;
198 case DNS_TYPE_HINFO:
199 case DNS_TYPE_ISDN:
200 case DNS_TYPE_TEXT:
201 case DNS_TYPE_X25:
203 if (r1->Data.TXT.dwStringCount != r2->Data.TXT.dwStringCount)
204 return FALSE;
205 for (i = 0; i < r1->Data.TXT.dwStringCount; i++)
207 if (dns_strcmpX( r1->Data.TXT.pStringArray[i],
208 r2->Data.TXT.pStringArray[i], wide ))
209 return FALSE;
211 break;
213 case DNS_TYPE_NULL:
215 if (r1->Data.Null.dwByteCount != r2->Data.Null.dwByteCount)
216 return FALSE;
217 if (memcmp( r1->Data.Null.Data,
218 r2->Data.Null.Data, r1->Data.Null.dwByteCount ))
219 return FALSE;
220 break;
222 case DNS_TYPE_AAAA:
224 for (i = 0; i < sizeof(IP6_ADDRESS)/sizeof(DWORD); i++)
226 if (r1->Data.AAAA.Ip6Address.IP6Dword[i] !=
227 r2->Data.AAAA.Ip6Address.IP6Dword[i]) return FALSE;
229 break;
231 case DNS_TYPE_KEY:
233 if (r1->Data.KEY.wFlags != r2->Data.KEY.wFlags ||
234 r1->Data.KEY.chProtocol != r2->Data.KEY.chProtocol ||
235 r1->Data.KEY.chAlgorithm != r2->Data.KEY.chAlgorithm)
236 return FALSE;
237 if (memcmp( r1->Data.KEY.Key, r2->Data.KEY.Key,
238 r1->wDataLength - sizeof(DNS_KEY_DATA) + 1 ))
239 return FALSE;
240 break;
242 case DNS_TYPE_SIG:
244 if (dns_strcmpX( r1->Data.SIG.pNameSigner,
245 r2->Data.SIG.pNameSigner, wide ))
246 return FALSE;
247 if (r1->Data.SIG.wTypeCovered != r2->Data.SIG.wTypeCovered ||
248 r1->Data.SIG.chAlgorithm != r2->Data.SIG.chAlgorithm ||
249 r1->Data.SIG.chLabelCount != r2->Data.SIG.chLabelCount ||
250 r1->Data.SIG.dwOriginalTtl != r2->Data.SIG.dwOriginalTtl ||
251 r1->Data.SIG.dwExpiration != r2->Data.SIG.dwExpiration ||
252 r1->Data.SIG.dwTimeSigned != r2->Data.SIG.dwTimeSigned ||
253 r1->Data.SIG.wKeyTag != r2->Data.SIG.wKeyTag)
254 return FALSE;
255 if (memcmp( r1->Data.SIG.Signature, r2->Data.SIG.Signature,
256 r1->wDataLength - sizeof(DNS_SIG_DATAA) + 1 ))
257 return FALSE;
258 break;
260 case DNS_TYPE_ATMA:
262 if (r1->Data.ATMA.AddressType != r2->Data.ATMA.AddressType)
263 return FALSE;
264 for (i = 0; i < DNS_ATMA_MAX_ADDR_LENGTH; i++)
266 if (r1->Data.ATMA.Address[i] != r2->Data.ATMA.Address[i])
267 return FALSE;
269 break;
271 case DNS_TYPE_NXT:
273 if (dns_strcmpX( r1->Data.NXT.pNameNext,
274 r2->Data.NXT.pNameNext, wide )) return FALSE;
275 if (r1->Data.NXT.wNumTypes != r2->Data.NXT.wNumTypes) return FALSE;
276 if (memcmp( r1->Data.NXT.wTypes, r2->Data.NXT.wTypes,
277 r1->wDataLength - sizeof(DNS_NXT_DATAA) + sizeof(WORD) ))
278 return FALSE;
279 break;
281 case DNS_TYPE_SRV:
283 if (dns_strcmpX( r1->Data.SRV.pNameTarget,
284 r2->Data.SRV.pNameTarget, wide )) return FALSE;
285 if (r1->Data.SRV.wPriority != r2->Data.SRV.wPriority ||
286 r1->Data.SRV.wWeight != r2->Data.SRV.wWeight ||
287 r1->Data.SRV.wPort != r2->Data.SRV.wPort)
288 return FALSE;
289 break;
291 case DNS_TYPE_TKEY:
293 if (dns_strcmpX( r1->Data.TKEY.pNameAlgorithm,
294 r2->Data.TKEY.pNameAlgorithm, wide ))
295 return FALSE;
296 if (r1->Data.TKEY.dwCreateTime != r2->Data.TKEY.dwCreateTime ||
297 r1->Data.TKEY.dwExpireTime != r2->Data.TKEY.dwExpireTime ||
298 r1->Data.TKEY.wMode != r2->Data.TKEY.wMode ||
299 r1->Data.TKEY.wError != r2->Data.TKEY.wError ||
300 r1->Data.TKEY.wKeyLength != r2->Data.TKEY.wKeyLength ||
301 r1->Data.TKEY.wOtherLength != r2->Data.TKEY.wOtherLength ||
302 r1->Data.TKEY.cAlgNameLength != r2->Data.TKEY.cAlgNameLength ||
303 r1->Data.TKEY.bPacketPointers != r2->Data.TKEY.bPacketPointers)
304 return FALSE;
306 /* FIXME: ignoring pAlgorithmPacket field */
307 if (memcmp( r1->Data.TKEY.pKey, r2->Data.TKEY.pKey,
308 r1->Data.TKEY.wKeyLength ) ||
309 memcmp( r1->Data.TKEY.pOtherData, r2->Data.TKEY.pOtherData,
310 r1->Data.TKEY.wOtherLength )) return FALSE;
311 break;
313 case DNS_TYPE_TSIG:
315 if (dns_strcmpX( r1->Data.TSIG.pNameAlgorithm,
316 r2->Data.TSIG.pNameAlgorithm, wide ))
317 return FALSE;
318 if (r1->Data.TSIG.i64CreateTime != r2->Data.TSIG.i64CreateTime ||
319 r1->Data.TSIG.wFudgeTime != r2->Data.TSIG.wFudgeTime ||
320 r1->Data.TSIG.wOriginalXid != r2->Data.TSIG.wOriginalXid ||
321 r1->Data.TSIG.wError != r2->Data.TSIG.wError ||
322 r1->Data.TSIG.wSigLength != r2->Data.TSIG.wSigLength ||
323 r1->Data.TSIG.wOtherLength != r2->Data.TSIG.wOtherLength ||
324 r1->Data.TSIG.cAlgNameLength != r2->Data.TSIG.cAlgNameLength ||
325 r1->Data.TSIG.bPacketPointers != r2->Data.TSIG.bPacketPointers)
326 return FALSE;
328 /* FIXME: ignoring pAlgorithmPacket field */
329 if (memcmp( r1->Data.TSIG.pSignature, r2->Data.TSIG.pSignature,
330 r1->Data.TSIG.wSigLength ) ||
331 memcmp( r1->Data.TSIG.pOtherData, r2->Data.TSIG.pOtherData,
332 r1->Data.TSIG.wOtherLength )) return FALSE;
333 break;
335 case DNS_TYPE_WINS:
337 if (r1->Data.WINS.dwMappingFlag != r2->Data.WINS.dwMappingFlag ||
338 r1->Data.WINS.dwLookupTimeout != r2->Data.WINS.dwLookupTimeout ||
339 r1->Data.WINS.dwCacheTimeout != r2->Data.WINS.dwCacheTimeout ||
340 r1->Data.WINS.cWinsServerCount != r2->Data.WINS.cWinsServerCount)
341 return FALSE;
342 if (memcmp( r1->Data.WINS.WinsServers, r2->Data.WINS.WinsServers,
343 r1->wDataLength - sizeof(DNS_WINS_DATA) + sizeof(IP4_ADDRESS) ))
344 return FALSE;
345 break;
347 case DNS_TYPE_WINSR:
349 if (r1->Data.WINSR.dwMappingFlag != r2->Data.WINSR.dwMappingFlag ||
350 r1->Data.WINSR.dwLookupTimeout != r2->Data.WINSR.dwLookupTimeout ||
351 r1->Data.WINSR.dwCacheTimeout != r2->Data.WINSR.dwCacheTimeout)
352 return FALSE;
353 if (dns_strcmpX( r1->Data.WINSR.pNameResultDomain,
354 r2->Data.WINSR.pNameResultDomain, wide ))
355 return FALSE;
356 break;
358 default:
359 FIXME( "unknown type: %s\n", dns_type_to_str( r1->wType ) );
360 return FALSE;
362 return TRUE;
365 static LPVOID dns_strcpyX( LPCVOID src, DNS_CHARSET in, DNS_CHARSET out )
367 switch (in)
369 case DnsCharSetUnicode:
371 switch (out)
373 case DnsCharSetUnicode: return dns_strdup_w( src );
374 case DnsCharSetUtf8: return dns_strdup_wu( src );
375 case DnsCharSetAnsi: return dns_strdup_wa( src );
376 default:
377 WARN( "unhandled target charset: %d\n", out );
378 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 case DnsCharSetAnsi:
392 switch (out)
394 case DnsCharSetUnicode: return dns_strdup_aw( src );
395 case DnsCharSetUtf8: return dns_strdup_au( src );
396 case DnsCharSetAnsi: return dns_strdup_a( src );
397 default:
398 WARN( "unhandled target charset: %d\n", out );
399 break;
401 default:
402 WARN( "unhandled source charset: %d\n", in );
403 break;
405 return NULL;
408 /******************************************************************************
409 * DnsRecordCopyEx [DNSAPI.@]
412 PDNS_RECORD WINAPI DnsRecordCopyEx( PDNS_RECORD src, DNS_CHARSET in, DNS_CHARSET out )
414 DNS_RECORD *dst;
415 unsigned int i, size;
417 TRACE( "(%p,%d,%d)\n", src, in, out );
419 size = FIELD_OFFSET(DNS_RECORD, Data) + src->wDataLength;
420 dst = dns_zero_alloc( size );
421 if (!dst) return NULL;
423 memcpy( dst, src, size );
425 if (src->Flags.S.CharSet == DnsCharSetUtf8 ||
426 src->Flags.S.CharSet == DnsCharSetAnsi ||
427 src->Flags.S.CharSet == DnsCharSetUnicode) in = src->Flags.S.CharSet;
429 dst->Flags.S.CharSet = out;
430 dst->pName = dns_strcpyX( src->pName, in, out );
431 if (!dst->pName) goto error;
433 switch (src->wType)
435 case DNS_TYPE_HINFO:
436 case DNS_TYPE_ISDN:
437 case DNS_TYPE_TEXT:
438 case DNS_TYPE_X25:
440 for (i = 0; i < src->Data.TXT.dwStringCount; i++)
442 dst->Data.TXT.pStringArray[i] =
443 dns_strcpyX( src->Data.TXT.pStringArray[i], in, out );
445 if (!dst->Data.TXT.pStringArray[i])
447 for (--i; i >= 0; i--)
448 dns_free( dst->Data.TXT.pStringArray[i] );
449 goto error;
452 break;
454 case DNS_TYPE_MINFO:
455 case DNS_TYPE_RP:
457 dst->Data.MINFO.pNameMailbox =
458 dns_strcpyX( src->Data.MINFO.pNameMailbox, in, out );
459 if (!dst->Data.MINFO.pNameMailbox) goto error;
461 dst->Data.MINFO.pNameErrorsMailbox =
462 dns_strcpyX( src->Data.MINFO.pNameErrorsMailbox, in, out );
463 if (!dst->Data.MINFO.pNameErrorsMailbox)
465 dns_free( dst->Data.MINFO.pNameMailbox );
466 goto error;
468 break;
470 case DNS_TYPE_AFSDB:
471 case DNS_TYPE_RT:
472 case DNS_TYPE_MX:
474 dst->Data.MX.pNameExchange =
475 dns_strcpyX( src->Data.MX.pNameExchange, in, out );
476 if (!dst->Data.MX.pNameExchange) goto error;
477 break;
479 case DNS_TYPE_NXT:
481 dst->Data.NXT.pNameNext =
482 dns_strcpyX( src->Data.NXT.pNameNext, in, out );
483 if (!dst->Data.NXT.pNameNext) goto error;
484 break;
486 case DNS_TYPE_CNAME:
487 case DNS_TYPE_MB:
488 case DNS_TYPE_MD:
489 case DNS_TYPE_MF:
490 case DNS_TYPE_MG:
491 case DNS_TYPE_MR:
492 case DNS_TYPE_NS:
493 case DNS_TYPE_PTR:
495 dst->Data.PTR.pNameHost =
496 dns_strcpyX( src->Data.PTR.pNameHost, in, out );
497 if (!dst->Data.PTR.pNameHost) goto error;
498 break;
500 case DNS_TYPE_SIG:
502 dst->Data.SIG.pNameSigner =
503 dns_strcpyX( src->Data.SIG.pNameSigner, in, out );
504 if (!dst->Data.SIG.pNameSigner) goto error;
505 break;
507 case DNS_TYPE_SOA:
509 dst->Data.SOA.pNamePrimaryServer =
510 dns_strcpyX( src->Data.SOA.pNamePrimaryServer, in, out );
511 if (!dst->Data.SOA.pNamePrimaryServer) goto error;
513 dst->Data.SOA.pNameAdministrator =
514 dns_strcpyX( src->Data.SOA.pNameAdministrator, in, out );
515 if (!dst->Data.SOA.pNameAdministrator)
517 dns_free( dst->Data.SOA.pNamePrimaryServer );
518 goto error;
520 break;
522 case DNS_TYPE_SRV:
524 dst->Data.SRV.pNameTarget =
525 dns_strcpyX( src->Data.SRV.pNameTarget, in, out );
526 if (!dst->Data.SRV.pNameTarget) goto error;
527 break;
529 default:
530 break;
532 return dst;
534 error:
535 dns_free( dst->pName );
536 dns_free( dst );
537 return NULL;
540 /******************************************************************************
541 * DnsRecordListFree [DNSAPI.@]
544 void WINAPI DnsRecordListFree( PDNS_RECORD list, DNS_FREE_TYPE type )
546 DNS_RECORD *r, *next;
547 unsigned int i;
549 TRACE( "(%p,%d)\n", list, type );
551 if (!list) return;
553 switch (type)
555 case DnsFreeRecordList:
557 for (r = list; (list = r); r = next)
559 dns_free( r->pName );
561 switch (r->wType)
563 case DNS_TYPE_HINFO:
564 case DNS_TYPE_ISDN:
565 case DNS_TYPE_TEXT:
566 case DNS_TYPE_X25:
568 for (i = 0; i < r->Data.TXT.dwStringCount; i++)
569 dns_free( r->Data.TXT.pStringArray[i] );
571 break;
573 case DNS_TYPE_MINFO:
574 case DNS_TYPE_RP:
576 dns_free( r->Data.MINFO.pNameMailbox );
577 dns_free( r->Data.MINFO.pNameErrorsMailbox );
578 break;
580 case DNS_TYPE_AFSDB:
581 case DNS_TYPE_RT:
582 case DNS_TYPE_MX:
584 dns_free( r->Data.MX.pNameExchange );
585 break;
587 case DNS_TYPE_NXT:
589 dns_free( r->Data.NXT.pNameNext );
590 break;
592 case DNS_TYPE_CNAME:
593 case DNS_TYPE_MB:
594 case DNS_TYPE_MD:
595 case DNS_TYPE_MF:
596 case DNS_TYPE_MG:
597 case DNS_TYPE_MR:
598 case DNS_TYPE_NS:
599 case DNS_TYPE_PTR:
601 dns_free( r->Data.PTR.pNameHost );
602 break;
604 case DNS_TYPE_SIG:
606 dns_free( r->Data.SIG.pNameSigner );
607 break;
609 case DNS_TYPE_SOA:
611 dns_free( r->Data.SOA.pNamePrimaryServer );
612 dns_free( r->Data.SOA.pNameAdministrator );
613 break;
615 case DNS_TYPE_SRV:
617 dns_free( r->Data.SRV.pNameTarget );
618 break;
620 default:
621 break;
624 next = r->pNext;
625 dns_free( r );
627 break;
629 case DnsFreeFlat:
630 case DnsFreeParsedMessageFields:
632 FIXME( "unhandled free type: %d\n", type );
633 break;
635 default:
636 WARN( "unknown free type: %d\n", type );
637 break;
641 /******************************************************************************
642 * DnsRecordSetCompare [DNSAPI.@]
645 BOOL WINAPI DnsRecordSetCompare( PDNS_RECORD set1, PDNS_RECORD set2,
646 PDNS_RECORD *diff1, PDNS_RECORD *diff2 )
648 BOOL ret = TRUE;
649 DNS_RECORD *r, *s1, *s2, *t, *u;
650 DNS_RRSET rr1, rr2;
652 TRACE( "(%p,%p,%p,%p)\n", set1, set2, diff1, diff2 );
654 if (!set1 && !set2) return FALSE;
656 if (diff1) *diff1 = NULL;
657 if (diff2) *diff2 = NULL;
659 if (set1 && !set2)
661 if (diff1) *diff1 = DnsRecordSetCopyEx( set1, 0, set1->Flags.S.CharSet );
662 return FALSE;
664 if (!set1 && set2)
666 if (diff2) *diff2 = DnsRecordSetCopyEx( set2, 0, set2->Flags.S.CharSet );
667 return FALSE;
670 DNS_RRSET_INIT( rr1 );
671 DNS_RRSET_INIT( rr2 );
673 for (r = s1 = set1; (s1 = r); r = r->pNext)
675 for (t = s2 = set2; (s2 = t); t = t->pNext)
677 u = DnsRecordCopyEx( r, r->Flags.S.CharSet, t->Flags.S.CharSet );
678 if (!u) goto error;
680 if (!DnsRecordCompare( t, u ))
682 DNS_RRSET_ADD( rr1, u );
683 ret = FALSE;
685 else dns_free( u );
689 for (t = s2 = set2; (s2 = t); t = t->pNext)
691 for (r = s1 = set1; (s1 = r); r = r->pNext)
693 u = DnsRecordCopyEx( t, t->Flags.S.CharSet, r->Flags.S.CharSet );
694 if (!u) goto error;
696 if (!DnsRecordCompare( r, u ))
698 DNS_RRSET_ADD( rr2, u );
699 ret = FALSE;
701 else dns_free( u );
705 DNS_RRSET_TERMINATE( rr1 );
706 DNS_RRSET_TERMINATE( rr2 );
708 if (diff1) *diff1 = rr1.pFirstRR;
709 if (diff2) *diff2 = rr2.pFirstRR;
711 return ret;
713 error:
714 DNS_RRSET_TERMINATE( rr1 );
715 DNS_RRSET_TERMINATE( rr2 );
717 DnsRecordListFree( rr1.pFirstRR, DnsFreeRecordList );
718 DnsRecordListFree( rr2.pFirstRR, DnsFreeRecordList );
720 return FALSE;
723 /******************************************************************************
724 * DnsRecordSetCopyEx [DNSAPI.@]
727 PDNS_RECORD WINAPI DnsRecordSetCopyEx( PDNS_RECORD src_set, DNS_CHARSET in, DNS_CHARSET out )
729 DNS_RRSET dst_set;
730 DNS_RECORD *src, *dst;
732 TRACE( "(%p,%d,%d)\n", src_set, in, out );
734 DNS_RRSET_INIT( dst_set );
736 for (src = src_set; (src_set = src); src = src_set->pNext)
738 dst = DnsRecordCopyEx( src, in, out );
739 if (!dst)
741 DNS_RRSET_TERMINATE( dst_set );
742 DnsRecordListFree( dst_set.pFirstRR, DnsFreeRecordList );
743 return NULL;
745 DNS_RRSET_ADD( dst_set, dst );
748 DNS_RRSET_TERMINATE( dst_set );
749 return dst_set.pFirstRR;
752 /******************************************************************************
753 * DnsRecordSetDetach [DNSAPI.@]
756 PDNS_RECORD WINAPI DnsRecordSetDetach( PDNS_RECORD set )
758 DNS_RECORD *r, *s;
760 TRACE( "(%p)\n", set );
762 for (r = set; (set = r); r = set->pNext)
764 if (r->pNext && !r->pNext->pNext)
766 s = r->pNext;
767 r->pNext = NULL;
768 return s;
771 return NULL;