ReactOS 0.4.15-dev-7788-g1ad9096
register.c
Go to the documentation of this file.
1/*
2 * Generation of dll registration scripts
3 *
4 * Copyright 2010 Alexandre Julliard
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 "config.h"
22#include "wine/port.h"
23
24#include <stdio.h>
25#include <stdlib.h>
26#ifdef HAVE_UNISTD_H
27# include <unistd.h>
28#endif
29#include <string.h>
30#include <ctype.h>
31
32#include "widl.h"
33#include "utils.h"
34#include "parser.h"
35#include "header.h"
36#include "typegen.h"
37#ifndef __REACTOS__
38#include "typelib.h"
39#endif
40
41static int indent;
42
43static const char *format_uuid( const UUID *uuid )
44{
45 static char buffer[40];
46 sprintf( buffer, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
47 uuid->Data1, uuid->Data2, uuid->Data3,
48 uuid->Data4[0], uuid->Data4[1], uuid->Data4[2], uuid->Data4[3],
49 uuid->Data4[4], uuid->Data4[5], uuid->Data4[6], uuid->Data4[7] );
50 return buffer;
51}
52
53static const char *get_coclass_threading( const type_t *class )
54{
55 static const char * const models[] =
56 {
57 NULL,
58 "Apartment", /* THREADING_APARTMENT */
59 "Neutral", /* THREADING_NEUTRAL */
60 "Single", /* THREADING_SINGLE */
61 "Free", /* THREADING_FREE */
62 "Both", /* THREADING_BOTH */
63 };
64 return models[get_attrv( class->attrs, ATTR_THREADING )];
65}
66
67static const type_t *find_ps_factory( const statement_list_t *stmts )
68{
69 const statement_t *stmt;
70
71 if (stmts) LIST_FOR_EACH_ENTRY( stmt, stmts, const statement_t, entry )
72 {
73 if (stmt->type == STMT_TYPE)
74 {
75 const type_t *type = stmt->u.type;
76 if (type_get_type(type) == TYPE_COCLASS && !strcmp( type->name, "PSFactoryBuffer" ))
77 return type;
78 }
79 }
80 return NULL;
81}
82
83static void write_interface( const type_t *iface, const type_t *ps_factory )
84{
85 const UUID *uuid = get_attrp( iface->attrs, ATTR_UUID );
86 const UUID *ps_uuid = get_attrp( ps_factory->attrs, ATTR_UUID );
87
88 if (!uuid) return;
89 if (!is_object( iface )) return;
90 if (!type_iface_get_inherit(iface)) /* special case for IUnknown */
91 {
92 put_str( indent, "'%s' = s '%s'\n", format_uuid( uuid ), iface->name );
93 return;
94 }
95 if (is_local( iface->attrs )) return;
96 put_str( indent, "'%s' = s '%s'\n", format_uuid( uuid ), iface->name );
97 put_str( indent, "{\n" );
98 indent++;
99 put_str( indent, "NumMethods = s %u\n", count_methods( iface ));
100 put_str( indent, "ProxyStubClsid32 = s '%s'\n", format_uuid( ps_uuid ));
101 indent--;
102 put_str( indent, "}\n" );
103}
104
105static void write_interfaces( const statement_list_t *stmts, const type_t *ps_factory )
106{
107 const statement_t *stmt;
108
109 if (stmts) LIST_FOR_EACH_ENTRY( stmt, stmts, const statement_t, entry )
110 {
111 if (stmt->type == STMT_TYPE && type_get_type( stmt->u.type ) == TYPE_INTERFACE)
112 write_interface( stmt->u.type, ps_factory );
113 }
114}
115
116static void write_typelib_interface( const type_t *iface, const typelib_t *typelib )
117{
118 const UUID *typelib_uuid = get_attrp( typelib->attrs, ATTR_UUID );
119 const UUID *uuid = get_attrp( iface->attrs, ATTR_UUID );
120 unsigned int version = get_attrv( typelib->attrs, ATTR_VERSION );
121
122 if (!uuid) return;
123 if (!is_object( iface )) return;
124 if (!is_attr( iface->attrs, ATTR_OLEAUTOMATION ) && !is_attr( iface->attrs, ATTR_DISPINTERFACE ))
125 return;
126 put_str( indent, "'%s' = s '%s'\n", format_uuid( uuid ), iface->name );
127 put_str( indent, "{\n" );
128 indent++;
129 put_str( indent, "ProxyStubClsid = s '{00020424-0000-0000-C000-000000000046}'\n" );
130 put_str( indent, "ProxyStubClsid32 = s '{00020424-0000-0000-C000-000000000046}'\n" );
131 if (version)
132 put_str( indent, "TypeLib = s '%s' { val Version = s '%u.%u' }\n",
134 else
135 put_str( indent, "TypeLib = s '%s'", format_uuid( typelib_uuid ));
136 indent--;
137 put_str( indent, "}\n" );
138}
139
141{
142 const statement_t *stmt;
143
144 if (typelib->stmts) LIST_FOR_EACH_ENTRY( stmt, typelib->stmts, const statement_t, entry )
145 {
146 if (stmt->type == STMT_TYPE && type_get_type( stmt->u.type ) == TYPE_INTERFACE)
148 }
149}
150
151static int write_coclass( const type_t *class, const typelib_t *typelib )
152{
153 const UUID *uuid = get_attrp( class->attrs, ATTR_UUID );
154 const char *descr = get_attrp( class->attrs, ATTR_HELPSTRING );
155 const char *progid = get_attrp( class->attrs, ATTR_PROGID );
156 const char *vi_progid = get_attrp( class->attrs, ATTR_VIPROGID );
157 const char *threading = get_coclass_threading( class );
158 unsigned int version = get_attrv( class->attrs, ATTR_VERSION );
159
160 if (!uuid) return 0;
161 if (typelib && !threading && !progid) return 0;
162 if (!descr) descr = class->name;
163
164 put_str( indent, "'%s' = s '%s'\n", format_uuid( uuid ), descr );
165 put_str( indent++, "{\n" );
166 if (threading) put_str( indent, "InprocServer32 = s '%%MODULE%%' { val ThreadingModel = s '%s' }\n",
167 threading );
168 if (progid) put_str( indent, "ProgId = s '%s'\n", progid );
169 if (typelib)
170 {
171 const UUID *typelib_uuid = get_attrp( typelib->attrs, ATTR_UUID );
172 put_str( indent, "TypeLib = s '%s'\n", format_uuid( typelib_uuid ));
173 if (!version) version = get_attrv( typelib->attrs, ATTR_VERSION );
174 }
175 if (version) put_str( indent, "Version = s '%u.%u'\n", MAJORVERSION(version), MINORVERSION(version) );
176 if (vi_progid) put_str( indent, "VersionIndependentProgId = s '%s'\n", vi_progid );
177 put_str( --indent, "}\n" );
178 return 1;
179}
180
181static void write_coclasses( const statement_list_t *stmts, const typelib_t *typelib )
182{
183 const statement_t *stmt;
184
185 if (stmts) LIST_FOR_EACH_ENTRY( stmt, stmts, const statement_t, entry )
186 {
187 if (stmt->type == STMT_TYPE)
188 {
189 const type_t *type = stmt->u.type;
191 }
192 }
193}
194
195static int write_progid( const type_t *class )
196{
197 const UUID *uuid = get_attrp( class->attrs, ATTR_UUID );
198 const char *descr = get_attrp( class->attrs, ATTR_HELPSTRING );
199 const char *progid = get_attrp( class->attrs, ATTR_PROGID );
200 const char *vi_progid = get_attrp( class->attrs, ATTR_VIPROGID );
201
202 if (!uuid) return 0;
203 if (!descr) descr = class->name;
204
205 if (progid)
206 {
207 put_str( indent, "'%s' = s '%s'\n", progid, descr );
208 put_str( indent++, "{\n" );
209 put_str( indent, "CLSID = s '%s'\n", format_uuid( uuid ) );
210 put_str( --indent, "}\n" );
211 }
212 if (vi_progid)
213 {
214 put_str( indent, "'%s' = s '%s'\n", vi_progid, descr );
215 put_str( indent++, "{\n" );
216 put_str( indent, "CLSID = s '%s'\n", format_uuid( uuid ) );
217 if (progid && strcmp( progid, vi_progid )) put_str( indent, "CurVer = s '%s'\n", progid );
218 put_str( --indent, "}\n" );
219 }
220 return 1;
221}
222
223static void write_progids( const statement_list_t *stmts )
224{
225 const statement_t *stmt;
226
227 if (stmts) LIST_FOR_EACH_ENTRY( stmt, stmts, const statement_t, entry )
228 {
229 if (stmt->type == STMT_TYPE)
230 {
231 const type_t *type = stmt->u.type;
233 }
234 }
235}
236
238{
239 const type_t *ps_factory;
240
241 if (!do_regscript) return;
242 if (do_everything && !need_proxy_file( stmts )) return;
243
245
246 put_str( indent, "HKCR\n" );
247 put_str( indent++, "{\n" );
248
249 put_str( indent, "NoRemove Interface\n" );
250 put_str( indent++, "{\n" );
251 ps_factory = find_ps_factory( stmts );
252 if (ps_factory) write_interfaces( stmts, ps_factory );
253 put_str( --indent, "}\n" );
254
255 put_str( indent, "NoRemove CLSID\n" );
256 put_str( indent++, "{\n" );
257 write_coclasses( stmts, NULL );
258 put_str( --indent, "}\n" );
259
260 write_progids( stmts );
261 put_str( --indent, "}\n" );
262
263 if (strendswith( regscript_name, ".res" )) /* create a binary resource file */
264 {
265 add_output_to_resources( "WINE_REGISTRY", regscript_token );
267 }
268 else
269 {
270 FILE *f = fopen( regscript_name, "w" );
271 if (!f) error( "Could not open %s for output\n", regscript_name );
273 error( "Failed to write to %s\n", regscript_name );
274 if (fclose( f ))
275 error( "Failed to write to %s\n", regscript_name );
276 }
277}
278
279#ifndef __REACTOS__
281{
282 const statement_t *stmt;
283 unsigned int count = 0;
284
285 if (!do_typelib) return;
286 if (stmts) LIST_FOR_EACH_ENTRY( stmt, stmts, const statement_t, entry )
287 {
288 if (stmt->type != STMT_LIBRARY) continue;
289 if (count && !strendswith( typelib_name, ".res" ))
290 error( "Cannot store multiple typelibs into %s\n", typelib_name );
291 else
292 {
293 if (do_old_typelib)
294 create_sltg_typelib( stmt->u.lib );
295 else
296 create_msft_typelib( stmt->u.lib );
297 }
298 count++;
299 }
301}
302#endif
303
305{
306 const UUID *typelib_uuid = get_attrp( typelib->attrs, ATTR_UUID );
307 const char *descr = get_attrp( typelib->attrs, ATTR_HELPSTRING );
308 const expr_t *lcid_expr = get_attrp( typelib->attrs, ATTR_LIBLCID );
309 unsigned int version = get_attrv( typelib->attrs, ATTR_VERSION );
310 unsigned int flags = 0;
311 char id_part[12] = "";
312#ifndef __REACTOS__
313 char *resname = typelib_name;
314#endif
315 expr_t *expr;
316
317 if (is_attr( typelib->attrs, ATTR_RESTRICTED )) flags |= 1; /* LIBFLAG_FRESTRICTED */
318 if (is_attr( typelib->attrs, ATTR_CONTROL )) flags |= 2; /* LIBFLAG_FCONTROL */
319 if (is_attr( typelib->attrs, ATTR_HIDDEN )) flags |= 4; /* LIBFLAG_FHIDDEN */
320
321 put_str( indent, "HKCR\n" );
322 put_str( indent++, "{\n" );
323
324 put_str( indent, "NoRemove Typelib\n" );
325 put_str( indent++, "{\n" );
326 put_str( indent, "NoRemove '%s'\n", format_uuid( typelib_uuid ));
327 put_str( indent++, "{\n" );
328 put_str( indent, "'%u.%u' = s '%s'\n",
330 put_str( indent++, "{\n" );
331 expr = get_attrp( typelib->attrs, ATTR_ID );
332#ifdef __REACTOS__
333 if (expr)
334 sprintf(id_part, "\\%d", expr->cval);
335#else
336 if (expr)
337 {
338 sprintf(id_part, "\\%d", expr->cval);
339 resname = xmalloc( strlen(typelib_name) + 20 );
340 sprintf(resname, "%s\\%d", typelib_name, expr->cval);
341 }
342#endif
343 put_str( indent, "'%x' { %s = s '%%MODULE%%%s' }\n",
344 lcid_expr ? lcid_expr->cval : 0, pointer_size == 8 ? "win64" : "win32", id_part );
345 put_str( indent, "FLAGS = s '%u'\n", flags );
346 put_str( --indent, "}\n" );
347 put_str( --indent, "}\n" );
348 put_str( --indent, "}\n" );
349
350 put_str( indent, "NoRemove Interface\n" );
351 put_str( indent++, "{\n" );
353 put_str( --indent, "}\n" );
354
355 put_str( indent, "NoRemove CLSID\n" );
356 put_str( indent++, "{\n" );
358 put_str( --indent, "}\n" );
359
360 write_progids( typelib->stmts );
361 put_str( --indent, "}\n" );
362#ifdef __REACTOS__
363 add_output_to_resources( "WINE_REGISTRY", typelib_name );
364#else
365 add_output_to_resources( "WINE_REGISTRY", resname );
366#endif
367}
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
static ITypeLib * typelib
Definition: apps.c:108
const WCHAR * class
Definition: main.c:68
void * xmalloc(int size)
Definition: uimain.c:747
#define ATTR_HIDDEN
Definition: fat.h:160
Definition: list.h:37
#define NULL
Definition: types.h:112
static const WCHAR version[]
Definition: asmname.c:66
#define progid(str)
Definition: exdisp.idl:31
#define vi_progid(str)
Definition: exdisp.idl:32
#define threading(model)
Definition: exdisp.idl:30
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLuint buffer
Definition: glext.h:5915
GLfloat f
Definition: glext.h:7540
GLbitfield flags
Definition: glext.h:7161
int need_proxy_file(const statement_list_t *stmts)
Definition: proxy.c:809
int count_methods(const type_t *iface)
Definition: proxy.c:465
_Check_return_ _CRTIMP FILE *__cdecl fopen(_In_z_ const char *_Filename, _In_z_ const char *_Mode)
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
_Check_return_opt_ _CRTIMP size_t __cdecl fwrite(_In_reads_bytes_(_Size *_Count) const void *_Str, _In_ size_t _Size, _In_ size_t _Count, _Inout_ FILE *_File)
Definition: msctf.idl:550
uint32_t entry
Definition: isohybrid.c:63
#define error(str)
Definition: mkdosfs.c:1605
#define sprintf(buf, format,...)
Definition: sprintf.c:55
#define LIST_FOR_EACH_ENTRY(elem, list, type, field)
Definition: list.h:198
const char * descr
Definition: boot.c:45
int is_local(const attr_list_t *a)
Definition: header.c:938
int is_attr(const attr_list_t *list, enum attr_type t)
Definition: header.c:99
unsigned int get_attrv(const attr_list_t *list, enum attr_type t)
Definition: header.c:115
void * get_attrp(const attr_list_t *list, enum attr_type t)
Definition: header.c:107
int is_object(const type_t *iface)
Definition: header.c:928
void output_typelib_regscript(const typelib_t *typelib)
Definition: register.c:304
static const type_t * find_ps_factory(const statement_list_t *stmts)
Definition: register.c:67
static int write_progid(const type_t *class)
Definition: register.c:195
static void write_interfaces(const statement_list_t *stmts, const type_t *ps_factory)
Definition: register.c:105
static void write_coclasses(const statement_list_t *stmts, const typelib_t *typelib)
Definition: register.c:181
void write_regscript(const statement_list_t *stmts)
Definition: register.c:237
static void write_progids(const statement_list_t *stmts)
Definition: register.c:223
static int write_coclass(const type_t *class, const typelib_t *typelib)
Definition: register.c:151
static int indent
Definition: register.c:41
static void write_typelib_interfaces(const typelib_t *typelib)
Definition: register.c:140
static const char * format_uuid(const UUID *uuid)
Definition: register.c:43
static void write_interface(const type_t *iface, const type_t *ps_factory)
Definition: register.c:83
void write_typelib_regscript(const statement_list_t *stmts)
Definition: register.c:280
static void write_typelib_interface(const type_t *iface, const typelib_t *typelib)
Definition: register.c:116
static const char * get_coclass_threading(const type_t *class)
Definition: register.c:53
int create_msft_typelib(typelib_t *typelib)
Definition: write_msft.c:2657
int create_sltg_typelib(typelib_t *typelib)
Definition: write_sltg.c:1831
size_t output_buffer_pos
Definition: utils.c:253
void add_output_to_resources(const char *type, const char *name)
Definition: utils.c:307
void flush_output_resources(const char *name)
Definition: utils.c:341
int strendswith(const char *str, const char *end)
Definition: utils.c:238
void put_str(int indent, const char *format,...)
Definition: utils.c:423
void init_output_buffer(void)
Definition: utils.c:272
#define MINORVERSION(version)
Definition: utils.h:76
#define MAJORVERSION(version)
Definition: utils.h:75
int cval
Definition: widltypes.h:319
statement_type_t type
Definition: parser.h:124
typelib_t * lib
Definition: widltypes.h:540
union _statement_t::@5025 u
attr_list_t * attrs
Definition: widltypes.h:422
const char * name
Definition: widltypes.h:419
Definition: query.h:87
static enum type_type type_get_type(const type_t *type)
Definition: typetree.h:68
static type_t * type_iface_get_inherit(const type_t *type)
Definition: typetree.h:158
int do_regscript
Definition: widl.c:122
char * typelib_name
Definition: widl.c:139
unsigned int pointer_size
Definition: widl.c:158
int do_everything
Definition: widl.c:114
char * regscript_name
Definition: widl.c:147
int do_typelib
Definition: widl.c:117
int do_old_typelib
Definition: widl.c:118
char * regscript_token
Definition: widl.c:148
@ TYPE_COCLASS
Definition: widltypes.h:410
@ TYPE_INTERFACE
Definition: widltypes.h:412
@ ATTR_VIPROGID
Definition: widltypes.h:170
@ ATTR_OLEAUTOMATION
Definition: widltypes.h:135
@ ATTR_UUID
Definition: widltypes.h:166
@ ATTR_THREADING
Definition: widltypes.h:161
@ ATTR_VERSION
Definition: widltypes.h:169
@ ATTR_CONTROL
Definition: widltypes.h:86
@ ATTR_LIBLCID
Definition: widltypes.h:122
@ ATTR_RESTRICTED
Definition: widltypes.h:153
@ ATTR_ID
Definition: widltypes.h:112
@ ATTR_DISPINTERFACE
Definition: widltypes.h:94
@ ATTR_PROGID
Definition: widltypes.h:143
@ ATTR_HELPSTRING
Definition: widltypes.h:108
@ STMT_TYPE
Definition: widltypes.h:242
@ STMT_LIBRARY
Definition: widltypes.h:240