ReactOS  0.4.14-dev-614-gbfd8a84
name.c
Go to the documentation of this file.
1 /*
2  * IAssemblyName implementation
3  *
4  * Copyright 2012 Hans Leidekker for CodeWeavers
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.
10  *
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.
15  *
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
19  */
20 
21 #include <stdarg.h>
22 #ifdef __REACTOS__
23 #include <wchar.h>
24 #endif
25 
26 #define COBJMACROS
27 
28 #include "windef.h"
29 #include "winbase.h"
30 #include "ole2.h"
31 #include "winsxs.h"
32 
33 #include "wine/debug.h"
34 #include "sxs_private.h"
35 
37 
38 struct name
39 {
47 };
48 
49 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};
50 static const WCHAR tokenW[] = {'p','u','b','l','i','c','K','e','y','T','o','k','e','n',0};
51 static const WCHAR typeW[] = {'t','y','p','e',0};
52 static const WCHAR versionW[] = {'v','e','r','s','i','o','n',0};
53 
54 static inline struct name *impl_from_IAssemblyName( IAssemblyName *iface )
55 {
56  return CONTAINING_RECORD( iface, struct name, IAssemblyName_iface );
57 }
58 
60  IAssemblyName *iface,
61  REFIID riid,
62  void **obj )
63 {
64  struct name *name = impl_from_IAssemblyName( iface );
65 
66  TRACE("%p, %s, %p\n", name, debugstr_guid(riid), obj);
67 
68  *obj = NULL;
69 
70  if (IsEqualIID( riid, &IID_IUnknown ) ||
71  IsEqualIID( riid, &IID_IAssemblyName ))
72  {
73  IAssemblyName_AddRef( iface );
74  *obj = name;
75  return S_OK;
76  }
77 
78  return E_NOINTERFACE;
79 }
80 
82  IAssemblyName *iface )
83 {
84  struct name *name = impl_from_IAssemblyName( iface );
85  return InterlockedIncrement( &name->refs );
86 }
87 
89 {
90  struct name *name = impl_from_IAssemblyName( iface );
92 
93  if (!refs)
94  {
95  TRACE("destroying %p\n", name);
96  HeapFree( GetProcessHeap(), 0, name->name );
97  HeapFree( GetProcessHeap(), 0, name->arch );
99  HeapFree( GetProcessHeap(), 0, name->type );
101  HeapFree( GetProcessHeap(), 0, name );
102  }
103  return refs;
104 }
105 
107  IAssemblyName *iface,
108  DWORD id,
110  DWORD size )
111 {
112  FIXME("%p, %d, %p, %d\n", iface, id, property, size);
113  return E_NOTIMPL;
114 }
115 
117  IAssemblyName *iface,
118  DWORD id,
119  LPVOID buffer,
120  LPDWORD buflen )
121 {
122  FIXME("%p, %d, %p, %p\n", iface, id, buffer, buflen);
123  return E_NOTIMPL;
124 }
125 
127  IAssemblyName *iface )
128 {
129  FIXME("%p\n", iface);
130  return E_NOTIMPL;
131 }
132 
134  IAssemblyName *iface,
136  LPDWORD buflen,
137  DWORD flags )
138 {
139  static const WCHAR fmtW[] = {',','%','s','=','\"','%','s','\"',0};
140  struct name *name = impl_from_IAssemblyName( iface );
141  WCHAR version[30];
142  unsigned int len;
143 
144  TRACE("%p, %p, %p, 0x%08x\n", iface, buffer, buflen, flags);
145 
146  if (!buflen || flags) return E_INVALIDARG;
147 
148  len = lstrlenW( name->name ) + 1;
149  if (name->arch) len += lstrlenW( archW ) + lstrlenW( name->arch ) + 4;
150  if (name->token) len += lstrlenW( tokenW ) + lstrlenW( name->token ) + 4;
151  if (name->type) len += lstrlenW( typeW ) + lstrlenW( name->type ) + 4;
152  if (name->version) len += lstrlenW( versionW ) + lstrlenW( version ) + 4;
153  if (len > *buflen)
154  {
155  *buflen = len;
157  }
158  lstrcpyW( buffer, name->name );
159  len = lstrlenW( buffer );
160  if (name->arch) len += swprintf( buffer + len, fmtW, archW, name->arch );
161  if (name->token) len += swprintf( buffer + len, fmtW, tokenW, name->token );
162  if (name->type) len += swprintf( buffer + len, fmtW, typeW, name->type );
163  if (name->version) len += swprintf( buffer + len, fmtW, versionW, name->version );
164  return S_OK;
165 }
166 
168  IAssemblyName *iface,
169  REFIID riid,
170  IUnknown *pUnkReserved1,
171  IUnknown *pUnkReserved2,
172  LPCOLESTR szReserved,
173  LONGLONG llReserved,
175  DWORD cbReserved,
176  LPVOID *ppReserved )
177 {
178  FIXME("%p, %s, %p, %p, %s, %s, %p, %d, %p\n", iface,
179  debugstr_guid(riid), pUnkReserved1, pUnkReserved2,
180  debugstr_w(szReserved), wine_dbgstr_longlong(llReserved),
181  pvReserved, cbReserved, ppReserved);
182  return E_NOTIMPL;
183 }
184 
186 {
187  struct name *name = impl_from_IAssemblyName( iface );
188 
189  switch (id)
190  {
191  case NAME_ATTR_ID_NAME: return name->name;
192  case NAME_ATTR_ID_ARCH: return name->arch;
193  case NAME_ATTR_ID_TOKEN: return name->token;
194  case NAME_ATTR_ID_TYPE: return name->type;
195  case NAME_ATTR_ID_VERSION: return name->version;
196  default:
197  ERR("unhandled name attribute %u\n", id);
198  break;
199  }
200  return NULL;
201 }
202 
204  IAssemblyName *iface,
205  LPDWORD buflen,
206  WCHAR *buffer )
207 {
208  const WCHAR *name;
209  int len;
210 
211  TRACE("%p, %p, %p\n", iface, buflen, buffer);
212 
213  if (!buflen || !buffer) return E_INVALIDARG;
214 
216  len = lstrlenW( name ) + 1;
217  if (len > *buflen)
218  {
219  *buflen = len;
221  }
222  lstrcpyW( buffer, name );
223  *buflen = len + 3;
224  return S_OK;
225 }
226 
227 static HRESULT parse_version( WCHAR *version, DWORD *high, DWORD *low )
228 {
229  WORD ver[4];
230  WCHAR *p, *q;
231  unsigned int i;
232 
233  memset( ver, 0, sizeof(ver) );
234  for (i = 0, p = version; i < 4; i++)
235  {
236  if (!*p) break;
237  q = wcschr( p, '.' );
238  if (q) *q = 0;
239  ver[i] = wcstol( p, NULL, 10 );
240  if (!q && i < 3) break;
241  p = q + 1;
242  }
243  *high = (ver[0] << 16) + ver[1];
244  *low = (ver[2] << 16) + ver[3];
245  return S_OK;
246 }
247 
249  IAssemblyName *iface,
250  LPDWORD high,
251  LPDWORD low )
252 {
253  struct name *name = impl_from_IAssemblyName( iface );
254  WCHAR *version;
255  HRESULT hr;
256 
257  TRACE("%p, %p, %p\n", iface, high, low);
258 
260  if (!(version = strdupW( name->version ))) return E_OUTOFMEMORY;
261  hr = parse_version( version, high, low );
263  return hr;
264 }
265 
269  DWORD flags )
270 {
271  FIXME("%p, %p, 0x%08x\n", name1, name2, flags);
272  return E_NOTIMPL;
273 }
274 
276  IAssemblyName *iface,
277  IAssemblyName **name )
278 {
279  FIXME("%p, %p\n", iface, name);
280  return E_NOTIMPL;
281 }
282 
283 static const IAssemblyNameVtbl name_vtbl =
284 {
286  name_AddRef,
287  name_Release,
293  name_GetName,
295  name_IsEqual,
296  name_Clone
297 };
298 
299 static WCHAR *parse_value( const WCHAR *str, unsigned int *len )
300 {
301  WCHAR *ret;
302  const WCHAR *p = str;
303 
304  if (*p++ != '\"') return NULL;
305  while (*p && *p != '\"') p++;
306  if (!*p) return NULL;
307 
308  *len = p - str;
309  if (!(ret = HeapAlloc( GetProcessHeap(), 0, *len * sizeof(WCHAR) ))) return NULL;
310  memcpy( ret, str + 1, (*len - 1) * sizeof(WCHAR) );
311  ret[*len - 1] = 0;
312  return ret;
313 }
314 
315 static HRESULT parse_displayname( struct name *name, const WCHAR *displayname )
316 {
317  const WCHAR *p, *q;
318  unsigned int len;
319 
320  p = q = displayname;
321  while (*q && *q != ',') q++;
322  len = q - p;
323  if (!(name->name = HeapAlloc( GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR) ))) return E_OUTOFMEMORY;
324  memcpy( name->name, p, len * sizeof(WCHAR) );
325  name->name[len] = 0;
326  if (!*q) return S_OK;
327 
328  for (;;)
329  {
330  p = ++q;
331  while (*q && *q != '=') q++;
332  if (!*q) return E_INVALIDARG;
333  len = q - p;
334  if (len == ARRAY_SIZE(archW) - 1 && !memcmp( p, archW, len * sizeof(WCHAR) ))
335  {
336  p = ++q;
337  if (!(name->arch = parse_value( p, &len ))) return E_INVALIDARG;
338  q += len;
339  }
340  else if (len == ARRAY_SIZE(tokenW) - 1 && !memcmp( p, tokenW, len * sizeof(WCHAR) ))
341  {
342  p = ++q;
343  if (!(name->token = parse_value( p, &len ))) return E_INVALIDARG;
344  q += len;
345  }
346  else if (len == ARRAY_SIZE(typeW) - 1 && !memcmp( p, typeW, len * sizeof(WCHAR) ))
347  {
348  p = ++q;
349  if (!(name->type = parse_value( p, &len ))) return E_INVALIDARG;
350  q += len;
351  }
352  else if (len == ARRAY_SIZE(versionW) - 1 && !memcmp( p, versionW, len * sizeof(WCHAR) ))
353  {
354  p = ++q;
355  if (!(name->version = parse_value( p, &len ))) return E_INVALIDARG;
356  q += len;
357  }
359  while (*q && *q != ',') q++;
360  if (!*q) break;
361  }
362  return S_OK;
363 }
364 
365 /******************************************************************
366  * CreateAssemblyNameObject (SXS.@)
367  */
369  LPASSEMBLYNAME *obj,
371  DWORD flags,
372  LPVOID reserved )
373 {
374  struct name *name;
375  HRESULT hr;
376 
377  TRACE("%p, %s, 0x%08x, %p\n", obj, debugstr_w(assembly), flags, reserved);
378 
379  if (!obj) return E_INVALIDARG;
380 
381  *obj = NULL;
383  return E_INVALIDARG;
384 
385  if (!(name = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*name) )))
386  return E_OUTOFMEMORY;
387 
389  name->refs = 1;
390 
392  if (hr != S_OK)
393  {
394  HeapFree( GetProcessHeap(), 0, name->name );
395  HeapFree( GetProcessHeap(), 0, name->arch );
396  HeapFree( GetProcessHeap(), 0, name->token );
397  HeapFree( GetProcessHeap(), 0, name->type );
399  HeapFree( GetProcessHeap(), 0, name );
400  return hr;
401  }
403  return S_OK;
404 }
static HRESULT WINAPI name_Finalize(IAssemblyName *iface)
Definition: name.c:126
static HRESULT WINAPI name_QueryInterface(IAssemblyName *iface, REFIID riid, void **obj)
Definition: name.c:59
#define REFIID
Definition: guiddef.h:118
#define E_NOINTERFACE
Definition: winerror.h:2364
#define HRESULT_FROM_WIN32(x)
Definition: winerror.h:92
WCHAR * token
Definition: name.c:44
const WCHAR * get_name_attribute(IAssemblyName *iface, enum name_attr_id id)
Definition: name.c:185
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
WCHAR * version
Definition: name.c:46
HRESULT hr
Definition: shlfolder.c:183
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
static HRESULT WINAPI name_Reserved(IAssemblyName *iface, REFIID riid, IUnknown *pUnkReserved1, IUnknown *pUnkReserved2, LPCOLESTR szReserved, LONGLONG llReserved, LPVOID pvReserved, DWORD cbReserved, LPVOID *ppReserved)
Definition: name.c:167
#define ERROR_SXS_INVALID_ASSEMBLY_IDENTITY_ATTRIBUTE_NAME
Definition: winerror.h:2221
static WCHAR * strdupW(const WCHAR *src)
Definition: main.c:92
REFIID riid
Definition: precomp.h:44
static const WCHAR typeW[]
Definition: name.c:51
HRESULT WINAPI CreateAssemblyNameObject(LPASSEMBLYNAME *obj, LPCWSTR assembly, DWORD flags, LPVOID reserved)
Definition: name.c:368
static ULONG WINAPI name_Release(IAssemblyName *iface)
Definition: name.c:88
static HRESULT WINAPI name_GetProperty(IAssemblyName *iface, DWORD id, LPVOID buffer, LPDWORD buflen)
Definition: name.c:116
GLuint buffer
Definition: glext.h:5915
IAssemblyName IAssemblyName_iface
Definition: name.c:40
_Check_return_ long __cdecl wcstol(_In_z_ const wchar_t *_Str, _Out_opt_ _Deref_post_z_ wchar_t **_EndPtr, _In_ int _Radix)
WCHAR * type
Definition: name.c:45
static WCHAR name1[]
Definition: record.c:34
static LPOLESTR
Definition: stg_prop.c:27
#define lstrlenW
Definition: compat.h:415
static ULONG WINAPI name_AddRef(IAssemblyName *iface)
Definition: name.c:81
LPCSTR name
Definition: name.c:34
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
long LONG
Definition: pedump.c:60
static HRESULT WINAPI name_GetName(IAssemblyName *iface, LPDWORD buflen, WCHAR *buffer)
Definition: name.c:203
#define debugstr_w
Definition: kernel32.h:32
#define FIXME(fmt,...)
Definition: debug.h:110
r reserved
Definition: btrfs.c:2865
static HRESULT WINAPI name_Clone(IAssemblyName *iface, IAssemblyName **name)
Definition: name.c:275
static const WCHAR archW[]
Definition: name.c:49
#define E_INVALIDARG
Definition: ddrawi.h:101
const WCHAR * str
smooth NULL
Definition: ftsmooth.c:416
static const WCHAR version[]
Definition: asmname.c:66
static HRESULT WINAPI name_SetProperty(IAssemblyName *iface, DWORD id, LPVOID property, DWORD size)
Definition: name.c:106
#define debugstr_guid
Definition: kernel32.h:35
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
static struct name * impl_from_IAssemblyName(IAssemblyName *iface)
Definition: name.c:54
int64_t LONGLONG
Definition: typedefs.h:66
#define TRACE(s)
Definition: solgame.cpp:4
GLsizeiptr size
Definition: glext.h:5919
#define GetProcessHeap()
Definition: compat.h:403
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
_CONST_RETURN wchar_t *__cdecl wcschr(_In_z_ const wchar_t *_Str, wchar_t _Ch)
static HRESULT WINAPI name_IsEqual(IAssemblyName *name1, IAssemblyName *name2, DWORD flags)
Definition: name.c:266
__wchar_t WCHAR
Definition: xmlstorage.h:180
LONG HRESULT
Definition: typedefs.h:77
static LPCSTR DWORD void * pvReserved
Definition: str.c:196
const GUID IID_IUnknown
static WCHAR * parse_value(const WCHAR *str, unsigned int *len)
Definition: name.c:299
#define swprintf(buf, format,...)
Definition: sprintf.c:56
#define WINAPI
Definition: msvc.h:6
unsigned short WORD
Definition: ntddk_ex.h:93
unsigned long DWORD
Definition: ntddk_ex.h:95
GLdouble GLdouble GLdouble GLdouble q
Definition: gl.h:2063
LONG refs
Definition: name.c:41
WCHAR * arch
Definition: name.c:43
GLbitfield flags
Definition: glext.h:7161
int ret
#define InterlockedDecrement
Definition: armddk.h:52
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
GLenum GLsizei len
Definition: glext.h:6722
WINE_DEFAULT_DEBUG_CHANNEL(sxs)
name_attr_id
Definition: sxs_private.h:21
static HRESULT parse_version(WCHAR *version, DWORD *high, DWORD *low)
Definition: name.c:227
#define ERR(fmt,...)
Definition: debug.h:109
#define S_OK
Definition: intsafe.h:59
#define InterlockedIncrement
Definition: armddk.h:53
#define lstrcpyW
Definition: compat.h:414
#define ARRAY_SIZE(a)
Definition: main.h:24
#define E_NOTIMPL
Definition: ddrawi.h:99
static const IAssemblyNameVtbl name_vtbl
Definition: name.c:283
static HRESULT parse_displayname(struct name *name, const WCHAR *displayname)
Definition: name.c:315
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
#define ERROR_NOT_FOUND
Definition: winerror.h:690
static HRESULT WINAPI name_GetVersion(IAssemblyName *iface, LPDWORD high, LPDWORD low)
Definition: name.c:248
Definition: name.c:38
static HRESULT WINAPI name_GetDisplayName(IAssemblyName *iface, LPOLESTR buffer, LPDWORD buflen, DWORD flags)
Definition: name.c:133
uint32_t * LPDWORD
Definition: typedefs.h:57
unsigned int ULONG
Definition: retypes.h:1
static __inline const char * wine_dbgstr_longlong(ULONGLONG ll)
Definition: compat.h:41
static WCHAR name2[]
Definition: record.c:35
static const WCHAR tokenW[]
Definition: name.c:50
GLfloat GLfloat p
Definition: glext.h:8902
#define memset(x, y, z)
Definition: compat.h:39
static const WCHAR versionW[]
Definition: name.c:52
#define HeapFree(x, y, z)
Definition: compat.h:402
#define IsEqualIID(riid1, riid2)
Definition: guiddef.h:95
WCHAR * name
Definition: name.c:42
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10