2 * IAssemblyName implementation
4 * Copyright 2012 Hans Leidekker for CodeWeavers
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
30 #include "wine/debug.h"
31 #include "sxs_private.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(sxs
);
37 IAssemblyName IAssemblyName_iface
;
46 static const WCHAR archW
[] = {'p','r','o','c','e','s','s','o','r','A','r','c','h','i','t','e','c','t','u','r','e',0};
47 static const WCHAR tokenW
[] = {'p','u','b','l','i','c','K','e','y','T','o','k','e','n',0};
48 static const WCHAR typeW
[] = {'t','y','p','e',0};
49 static const WCHAR versionW
[] = {'v','e','r','s','i','o','n',0};
51 static inline struct name
*impl_from_IAssemblyName( IAssemblyName
*iface
)
53 return CONTAINING_RECORD( iface
, struct name
, IAssemblyName_iface
);
56 static HRESULT WINAPI
name_QueryInterface(
61 struct name
*name
= impl_from_IAssemblyName( iface
);
63 TRACE("%p, %s, %p\n", name
, debugstr_guid(riid
), obj
);
67 if (IsEqualIID( riid
, &IID_IUnknown
) ||
68 IsEqualIID( riid
, &IID_IAssemblyName
))
70 IAssemblyName_AddRef( iface
);
78 static ULONG WINAPI
name_AddRef(
79 IAssemblyName
*iface
)
81 struct name
*name
= impl_from_IAssemblyName( iface
);
82 return InterlockedIncrement( &name
->refs
);
85 static ULONG WINAPI
name_Release( IAssemblyName
*iface
)
87 struct name
*name
= impl_from_IAssemblyName( iface
);
88 ULONG refs
= InterlockedDecrement( &name
->refs
);
92 TRACE("destroying %p\n", name
);
93 HeapFree( GetProcessHeap(), 0, name
->name
);
94 HeapFree( GetProcessHeap(), 0, name
->arch
);
95 HeapFree( GetProcessHeap(), 0, name
->token
);
96 HeapFree( GetProcessHeap(), 0, name
->type
);
97 HeapFree( GetProcessHeap(), 0, name
->version
);
98 HeapFree( GetProcessHeap(), 0, name
);
103 static HRESULT WINAPI
name_SetProperty(
104 IAssemblyName
*iface
,
109 FIXME("%p, %d, %p, %d\n", iface
, id
, property
, size
);
113 static HRESULT WINAPI
name_GetProperty(
114 IAssemblyName
*iface
,
119 FIXME("%p, %d, %p, %p\n", iface
, id
, buffer
, buflen
);
123 static HRESULT WINAPI
name_Finalize(
124 IAssemblyName
*iface
)
126 FIXME("%p\n", iface
);
130 static HRESULT WINAPI
name_GetDisplayName(
131 IAssemblyName
*iface
,
136 static const WCHAR fmtW
[] = {',','%','s','=','\"','%','s','\"',0};
137 struct name
*name
= impl_from_IAssemblyName( iface
);
141 TRACE("%p, %p, %p, 0x%08x\n", iface
, buffer
, buflen
, flags
);
143 if (!buflen
|| flags
) return E_INVALIDARG
;
145 len
= lstrlenW( name
->name
) + 1;
146 if (name
->arch
) len
+= lstrlenW( archW
) + lstrlenW( name
->arch
) + 4;
147 if (name
->token
) len
+= lstrlenW( tokenW
) + lstrlenW( name
->token
) + 4;
148 if (name
->type
) len
+= lstrlenW( typeW
) + lstrlenW( name
->type
) + 4;
149 if (name
->version
) len
+= lstrlenW( versionW
) + lstrlenW( version
) + 4;
153 return HRESULT_FROM_WIN32( ERROR_INSUFFICIENT_BUFFER
);
155 lstrcpyW( buffer
, name
->name
);
156 len
= lstrlenW( buffer
);
157 if (name
->arch
) len
+= swprintf( buffer
+ len
, *buflen
- len
, fmtW
, archW
, name
->arch
);
158 if (name
->token
) len
+= swprintf( buffer
+ len
, *buflen
- len
, fmtW
, tokenW
, name
->token
);
159 if (name
->type
) len
+= swprintf( buffer
+ len
, *buflen
- len
, fmtW
, typeW
, name
->type
);
160 if (name
->version
) len
+= swprintf( buffer
+ len
, *buflen
- len
, fmtW
, versionW
, name
->version
);
164 static HRESULT WINAPI
name_Reserved(
165 IAssemblyName
*iface
,
167 IUnknown
*pUnkReserved1
,
168 IUnknown
*pUnkReserved2
,
169 LPCOLESTR szReserved
,
175 FIXME("%p, %s, %p, %p, %s, %s, %p, %d, %p\n", iface
,
176 debugstr_guid(riid
), pUnkReserved1
, pUnkReserved2
,
177 debugstr_w(szReserved
), wine_dbgstr_longlong(llReserved
),
178 pvReserved
, cbReserved
, ppReserved
);
182 const WCHAR
*get_name_attribute( IAssemblyName
*iface
, enum name_attr_id id
)
184 struct name
*name
= impl_from_IAssemblyName( iface
);
188 case NAME_ATTR_ID_NAME
: return name
->name
;
189 case NAME_ATTR_ID_ARCH
: return name
->arch
;
190 case NAME_ATTR_ID_TOKEN
: return name
->token
;
191 case NAME_ATTR_ID_TYPE
: return name
->type
;
192 case NAME_ATTR_ID_VERSION
: return name
->version
;
194 ERR("unhandled name attribute %u\n", id
);
200 static HRESULT WINAPI
name_GetName(
201 IAssemblyName
*iface
,
208 TRACE("%p, %p, %p\n", iface
, buflen
, buffer
);
210 if (!buflen
|| !buffer
) return E_INVALIDARG
;
212 name
= get_name_attribute( iface
, NAME_ATTR_ID_NAME
);
213 len
= lstrlenW( name
) + 1;
217 return HRESULT_FROM_WIN32( ERROR_INSUFFICIENT_BUFFER
);
219 lstrcpyW( buffer
, name
);
224 static HRESULT
parse_version( WCHAR
*version
, DWORD
*high
, DWORD
*low
)
230 memset( ver
, 0, sizeof(ver
) );
231 for (i
= 0, p
= version
; i
< 4; i
++)
234 q
= wcschr( p
, '.' );
236 ver
[i
] = wcstol( p
, NULL
, 10 );
237 if (!q
&& i
< 3) break;
240 *high
= (ver
[0] << 16) + ver
[1];
241 *low
= (ver
[2] << 16) + ver
[3];
245 static HRESULT WINAPI
name_GetVersion(
246 IAssemblyName
*iface
,
250 struct name
*name
= impl_from_IAssemblyName( iface
);
254 TRACE("%p, %p, %p\n", iface
, high
, low
);
256 if (!name
->version
) return HRESULT_FROM_WIN32( ERROR_NOT_FOUND
);
257 if (!(version
= strdupW( name
->version
))) return E_OUTOFMEMORY
;
258 hr
= parse_version( version
, high
, low
);
259 HeapFree( GetProcessHeap(), 0, version
);
263 static HRESULT WINAPI
name_IsEqual(
264 IAssemblyName
*name1
,
265 IAssemblyName
*name2
,
268 FIXME("%p, %p, 0x%08x\n", name1
, name2
, flags
);
272 static HRESULT WINAPI
name_Clone(
273 IAssemblyName
*iface
,
274 IAssemblyName
**name
)
276 FIXME("%p, %p\n", iface
, name
);
280 static const IAssemblyNameVtbl name_vtbl
=
296 static WCHAR
*parse_value( const WCHAR
*str
, unsigned int *len
)
299 const WCHAR
*p
= str
;
301 if (*p
++ != '\"') return NULL
;
302 while (*p
&& *p
!= '\"') p
++;
303 if (!*p
) return NULL
;
306 if (!(ret
= HeapAlloc( GetProcessHeap(), 0, *len
* sizeof(WCHAR
) ))) return NULL
;
307 memcpy( ret
, str
+ 1, (*len
- 1) * sizeof(WCHAR
) );
312 static HRESULT
parse_displayname( struct name
*name
, const WCHAR
*displayname
)
318 while (*q
&& *q
!= ',') q
++;
320 if (!(name
->name
= HeapAlloc( GetProcessHeap(), 0, (len
+ 1) * sizeof(WCHAR
) ))) return E_OUTOFMEMORY
;
321 memcpy( name
->name
, p
, len
* sizeof(WCHAR
) );
323 if (!*q
) return S_OK
;
328 while (*q
&& *q
!= '=') q
++;
329 if (!*q
) return E_INVALIDARG
;
331 if (len
== ARRAY_SIZE(archW
) - 1 && !memcmp( p
, archW
, len
* sizeof(WCHAR
) ))
334 if (!(name
->arch
= parse_value( p
, &len
))) return E_INVALIDARG
;
337 else if (len
== ARRAY_SIZE(tokenW
) - 1 && !memcmp( p
, tokenW
, len
* sizeof(WCHAR
) ))
340 if (!(name
->token
= parse_value( p
, &len
))) return E_INVALIDARG
;
343 else if (len
== ARRAY_SIZE(typeW
) - 1 && !memcmp( p
, typeW
, len
* sizeof(WCHAR
) ))
346 if (!(name
->type
= parse_value( p
, &len
))) return E_INVALIDARG
;
349 else if (len
== ARRAY_SIZE(versionW
) - 1 && !memcmp( p
, versionW
, len
* sizeof(WCHAR
) ))
352 if (!(name
->version
= parse_value( p
, &len
))) return E_INVALIDARG
;
355 else return HRESULT_FROM_WIN32( ERROR_SXS_INVALID_ASSEMBLY_IDENTITY_ATTRIBUTE_NAME
);
356 while (*q
&& *q
!= ',') q
++;
362 /******************************************************************
363 * CreateAssemblyNameObject (SXS.@)
365 HRESULT WINAPI
CreateAssemblyNameObject(
374 TRACE("%p, %s, 0x%08x, %p\n", obj
, debugstr_w(assembly
), flags
, reserved
);
376 if (!obj
) return E_INVALIDARG
;
379 if (!assembly
|| !assembly
[0] || flags
!= CANOF_PARSE_DISPLAY_NAME
)
382 if (!(name
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*name
) )))
383 return E_OUTOFMEMORY
;
385 name
->IAssemblyName_iface
.lpVtbl
= &name_vtbl
;
388 hr
= parse_displayname( name
, assembly
);
391 HeapFree( GetProcessHeap(), 0, name
->name
);
392 HeapFree( GetProcessHeap(), 0, name
->arch
);
393 HeapFree( GetProcessHeap(), 0, name
->token
);
394 HeapFree( GetProcessHeap(), 0, name
->type
);
395 HeapFree( GetProcessHeap(), 0, name
->version
);
396 HeapFree( GetProcessHeap(), 0, name
);
399 *obj
= &name
->IAssemblyName_iface
;