dnsapi: Implement DnsNameCompare_{A,W}.
[wine/gsoc_dplay.git] / dlls / dnsapi / name.c
blobc4da7280424624af854a19bf4f92eedf8f739a19
1 /*
2 * DNS support
4 * Copyright (C) 2006 Matthew Kehrer
5 * Copyright (C) 2006 Hans Leidekker
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "wine/debug.h"
23 #include "wine/unicode.h"
25 #include <stdarg.h>
27 #include "windef.h"
28 #include "winbase.h"
29 #include "winerror.h"
30 #include "winnls.h"
31 #include "windns.h"
33 #include "dnsapi.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(dnsapi);
37 /******************************************************************************
38 * DnsNameCompare_A [DNSAPI.@]
41 BOOL WINAPI DnsNameCompare_A( LPSTR name1, LPSTR name2 )
43 BOOL ret;
44 LPWSTR name1W, name2W;
46 TRACE( "(%s,%s)\n", debugstr_a(name1), debugstr_a(name2) );
48 name1W = dns_strdup_aw( name1 );
49 name2W = dns_strdup_aw( name2 );
51 ret = DnsNameCompare_W( name1W, name2W );
53 dns_free( name1W );
54 dns_free( name2W );
56 return ret;
59 /******************************************************************************
60 * DnsNameCompare_W [DNSAPI.@]
63 BOOL WINAPI DnsNameCompare_W( LPWSTR name1, LPWSTR name2 )
65 WCHAR *p, *q;
67 TRACE( "(%s,%s)\n", debugstr_w(name1), debugstr_w(name2) );
69 if (!name1 && !name2) return TRUE;
70 if (!name1 || !name2) return FALSE;
72 p = name1 + lstrlenW( name1 ) - 1;
73 q = name2 + lstrlenW( name2 ) - 1;
75 while (*p == '.' && p >= name1) p--;
76 while (*q == '.' && q >= name2) q--;
78 if (p - name1 != q - name2) return FALSE;
80 while (name1 <= p)
82 if (toupperW( *name1 ) != toupperW( *name2 ))
83 return FALSE;
85 name1++;
86 name2++;
88 return TRUE;