Mercurial > mplayer.hg
annotate loader/registry.c @ 24616:cb9e7a138b6e
r21897: Rephrase mga_vid section.
r21930: gcc_bug++;
r22129: Link to the mencoder-users list for mencoder stuff
r22140: vp6vfw.dll appears to no longer crash under Linux.
author | kraymer |
---|---|
date | Thu, 27 Sep 2007 21:53:57 +0000 |
parents | 13dcc81c0013 |
children | 3cd1d60e7225 |
rev | line source |
---|---|
15166
f5537cc95b02
Mark modified imported files as such to comply with GPL ¡ø2a.
diego
parents:
9965
diff
changeset
|
1 /* |
18783 | 2 * Modified for use with MPlayer, detailed changelog at |
3 * http://svn.mplayerhq.hu/mplayer/trunk/ | |
15166
f5537cc95b02
Mark modified imported files as such to comply with GPL ¡ø2a.
diego
parents:
9965
diff
changeset
|
4 * $Id$ |
f5537cc95b02
Mark modified imported files as such to comply with GPL ¡ø2a.
diego
parents:
9965
diff
changeset
|
5 */ |
f5537cc95b02
Mark modified imported files as such to comply with GPL ¡ø2a.
diego
parents:
9965
diff
changeset
|
6 |
3465 | 7 #include "config.h" |
21261
a2e02e6b6379
Rename config.h --> debug.h and include config.h explicitly.
diego
parents:
18889
diff
changeset
|
8 #include "debug.h" |
1 | 9 |
10 #include <stdio.h> | |
1307
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
340
diff
changeset
|
11 #include <stdlib.h> |
1 | 12 #include <fcntl.h> |
1307
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
340
diff
changeset
|
13 #include <unistd.h> |
1 | 14 #include <pwd.h> |
15 #include <sys/types.h> | |
16 | |
7386 | 17 #include "wine/winbase.h" |
18 #include "wine/winreg.h" | |
19 #include "wine/winnt.h" | |
20 #include "wine/winerror.h" | |
1 | 21 |
3465 | 22 #include "ext.h" |
23 #include "registry.h" | |
1307
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
340
diff
changeset
|
24 |
128 | 25 //#undef TRACE |
26 //#define TRACE printf | |
3128 | 27 |
18889
e60c8c7399d2
get_path as const, patch by Stefan Huehner, stefan AT huehner-org
reynaldo
parents:
18878
diff
changeset
|
28 extern char *get_path ( const char * ); |
3134 | 29 |
4384 | 30 // ...can be set before init_registry() call |
31 char* regpathname = NULL; | |
3134 | 32 |
4384 | 33 static char* localregpathname = NULL; |
3134 | 34 |
35 typedef struct reg_handle_s | |
36 { | |
37 int handle; | |
38 char* name; | |
39 struct reg_handle_s* next; | |
40 struct reg_handle_s* prev; | |
41 } reg_handle_t; | |
42 | |
1 | 43 struct reg_value |
44 { | |
45 int type; | |
46 char* name; | |
47 int len; | |
48 char* value; | |
49 }; | |
50 | |
3134 | 51 static struct reg_value* regs = NULL; |
52 static int reg_size; | |
53 static reg_handle_t* head = NULL; | |
1 | 54 |
55 #define DIR -25 | |
56 | |
1307
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
340
diff
changeset
|
57 static void create_registry(void); |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
340
diff
changeset
|
58 static void open_registry(void); |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
340
diff
changeset
|
59 static void save_registry(void); |
3128 | 60 static void init_registry(void); |
1 | 61 |
62 | |
1307
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
340
diff
changeset
|
63 static void create_registry(void){ |
1 | 64 if(regs) |
65 { | |
66 printf("Logic error: create_registry() called with existing registry\n"); | |
67 save_registry(); | |
68 return; | |
3128 | 69 } |
18878 | 70 regs=malloc(3*sizeof(struct reg_value)); |
1 | 71 regs[0].type=regs[1].type=DIR; |
18878 | 72 regs[0].name=malloc(5); |
1 | 73 strcpy(regs[0].name, "HKLM"); |
18878 | 74 regs[1].name=malloc(5); |
1 | 75 strcpy(regs[1].name, "HKCU"); |
76 regs[0].value=regs[1].value=NULL; | |
77 regs[0].len=regs[1].len=0; | |
78 reg_size=2; | |
3134 | 79 head = 0; |
1 | 80 save_registry(); |
81 } | |
3134 | 82 |
1307
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
340
diff
changeset
|
83 static void open_registry(void) |
1 | 84 { |
85 int fd; | |
86 int i; | |
3128 | 87 unsigned int len; |
1 | 88 if(regs) |
89 { | |
90 printf("Multiple open_registry(>\n"); | |
91 return; | |
92 } | |
3134 | 93 fd = open(localregpathname, O_RDONLY); |
3128 | 94 if (fd == -1) |
1 | 95 { |
96 printf("Creating new registry\n"); | |
97 create_registry(); | |
98 return; | |
3128 | 99 } |
1 | 100 read(fd, ®_size, 4); |
18878 | 101 regs=malloc(reg_size*sizeof(struct reg_value)); |
3134 | 102 head = 0; |
1 | 103 for(i=0; i<reg_size; i++) |
104 { | |
105 read(fd,®s[i].type,4); | |
106 read(fd,&len,4); | |
18878 | 107 regs[i].name=malloc(len+1); |
1 | 108 if(regs[i].name==0) |
109 { | |
110 reg_size=i+1; | |
111 goto error; | |
112 } | |
113 read(fd, regs[i].name, len); | |
114 regs[i].name[len]=0; | |
115 read(fd,®s[i].len,4); | |
18878 | 116 regs[i].value=malloc(regs[i].len+1); |
1 | 117 if(regs[i].value==0) |
118 { | |
3134 | 119 free(regs[i].name); |
1 | 120 reg_size=i+1; |
121 goto error; | |
122 } | |
123 read(fd, regs[i].value, regs[i].len); | |
124 regs[i].value[regs[i].len]=0; | |
125 } | |
126 error: | |
127 close(fd); | |
128 return; | |
129 } | |
130 | |
1307
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
340
diff
changeset
|
131 static void save_registry(void) |
1 | 132 { |
3128 | 133 int fd, i; |
134 if (!regs) | |
135 init_registry(); | |
3134 | 136 fd = open(localregpathname, O_WRONLY | O_CREAT, 00666); |
3128 | 137 if (fd == -1) |
1 | 138 { |
3128 | 139 printf("Failed to open registry file '%s' for writing.\n", |
3134 | 140 localregpathname); |
3128 | 141 return; |
1 | 142 } |
143 write(fd, ®_size, 4); | |
144 for(i=0; i<reg_size; i++) | |
145 { | |
3128 | 146 unsigned len=strlen(regs[i].name); |
1 | 147 write(fd, ®s[i].type, 4); |
148 write(fd, &len, 4); | |
149 write(fd, regs[i].name, len); | |
150 write(fd, ®s[i].len, 4); | |
151 write(fd, regs[i].value, regs[i].len); | |
152 } | |
153 close(fd); | |
154 } | |
3134 | 155 |
156 void free_registry(void) | |
157 { | |
158 reg_handle_t* t = head; | |
159 while (t) | |
160 { | |
161 reg_handle_t* f = t; | |
162 if (t->name) | |
163 free(t->name); | |
164 t=t->prev; | |
165 free(f); | |
166 } | |
167 head = 0; | |
168 if (regs) | |
169 { | |
170 int i; | |
171 for(i=0; i<reg_size; i++) | |
172 { | |
173 free(regs[i].name); | |
174 free(regs[i].value); | |
175 } | |
176 free(regs); | |
177 regs = 0; | |
178 } | |
3465 | 179 |
180 if (localregpathname && localregpathname != regpathname) | |
3134 | 181 free(localregpathname); |
3465 | 182 localregpathname = 0; |
3134 | 183 } |
184 | |
185 | |
1 | 186 static reg_handle_t* find_handle_by_name(const char* name) |
187 { | |
188 reg_handle_t* t; | |
189 for(t=head; t; t=t->prev) | |
190 { | |
191 if(!strcmp(t->name, name)) | |
192 { | |
193 return t; | |
194 } | |
195 } | |
196 return 0; | |
197 } | |
198 static struct reg_value* find_value_by_name(const char* name) | |
199 { | |
200 int i; | |
201 for(i=0; i<reg_size; i++) | |
202 if(!strcmp(regs[i].name, name)) | |
203 return regs+i; | |
204 return 0; | |
205 } | |
206 static reg_handle_t* find_handle(int handle) | |
207 { | |
208 reg_handle_t* t; | |
209 for(t=head; t; t=t->prev) | |
210 { | |
211 if(t->handle==handle) | |
212 { | |
213 return t; | |
214 } | |
215 } | |
216 return 0; | |
3128 | 217 } |
1 | 218 static int generate_handle() |
219 { | |
7386 | 220 static unsigned int zz=249; |
1 | 221 zz++; |
222 while((zz==HKEY_LOCAL_MACHINE) || (zz==HKEY_CURRENT_USER)) | |
223 zz++; | |
224 return zz; | |
225 } | |
226 | |
227 static reg_handle_t* insert_handle(long handle, const char* name) | |
228 { | |
229 reg_handle_t* t; | |
18878 | 230 t=malloc(sizeof(reg_handle_t)); |
1 | 231 if(head==0) |
232 { | |
233 t->prev=0; | |
234 } | |
235 else | |
236 { | |
237 head->next=t; | |
238 t->prev=head; | |
239 } | |
240 t->next=0; | |
18878 | 241 t->name=malloc(strlen(name)+1); |
1 | 242 strcpy(t->name, name); |
243 t->handle=handle; | |
244 head=t; | |
245 return t; | |
246 } | |
247 static char* build_keyname(long key, const char* subkey) | |
248 { | |
249 char* full_name; | |
250 reg_handle_t* t; | |
251 if((t=find_handle(key))==0) | |
252 { | |
253 TRACE("Invalid key\n"); | |
254 return NULL; | |
255 } | |
256 if(subkey==NULL) | |
257 subkey="<default>"; | |
18878 | 258 full_name=malloc(strlen(t->name)+strlen(subkey)+10); |
1 | 259 strcpy(full_name, t->name); |
260 strcat(full_name, "\\"); | |
261 strcat(full_name, subkey); | |
262 return full_name; | |
263 } | |
1307
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
340
diff
changeset
|
264 static struct reg_value* insert_reg_value(int handle, const char* name, int type, const void* value, int len) |
1 | 265 { |
266 struct reg_value* v; | |
267 char* fullname; | |
268 if((fullname=build_keyname(handle, name))==NULL) | |
269 { | |
270 TRACE("Invalid handle\n"); | |
271 return NULL; | |
272 } | |
273 | |
274 if((v=find_value_by_name(fullname))==0) | |
275 //creating new value in registry | |
276 { | |
277 if(regs==0) | |
278 create_registry(); | |
279 regs=(struct reg_value*)realloc(regs, sizeof(struct reg_value)*(reg_size+1)); | |
3134 | 280 //regs=(struct reg_value*)my_realloc(regs, sizeof(struct reg_value)*(reg_size+1)); |
1 | 281 v=regs+reg_size; |
282 reg_size++; | |
283 } | |
284 else | |
285 //replacing old one | |
286 { | |
3134 | 287 free(v->value); |
288 free(v->name); | |
1 | 289 } |
7386 | 290 TRACE("RegInsert '%s' %p v:%d len:%d\n", name, value, *(int*)value, len); |
1 | 291 v->type=type; |
292 v->len=len; | |
18878 | 293 v->value=malloc(len); |
1 | 294 memcpy(v->value, value, len); |
18878 | 295 v->name=malloc(strlen(fullname)+1); |
1 | 296 strcpy(v->name, fullname); |
3134 | 297 free(fullname); |
1 | 298 save_registry(); |
299 return v; | |
300 } | |
301 | |
1307
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
340
diff
changeset
|
302 static void init_registry(void) |
1 | 303 { |
3128 | 304 TRACE("Initializing registry\n"); |
305 // can't be free-ed - it's static and probably thread | |
306 // unsafe structure which is stored in glibc | |
307 | |
3465 | 308 regpathname = get_path("registry"); |
309 localregpathname = regpathname; | |
3128 | 310 |
1 | 311 open_registry(); |
312 insert_handle(HKEY_LOCAL_MACHINE, "HKLM"); | |
313 insert_handle(HKEY_CURRENT_USER, "HKCU"); | |
314 } | |
3128 | 315 |
1 | 316 static reg_handle_t* find_handle_2(long key, const char* subkey) |
317 { | |
318 char* full_name; | |
319 reg_handle_t* t; | |
320 if((t=find_handle(key))==0) | |
321 { | |
322 TRACE("Invalid key\n"); | |
323 return (reg_handle_t*)-1; | |
324 } | |
325 if(subkey==NULL) | |
326 return t; | |
18878 | 327 full_name=malloc(strlen(t->name)+strlen(subkey)+10); |
1 | 328 strcpy(full_name, t->name); |
329 strcat(full_name, "\\"); | |
330 strcat(full_name, subkey); | |
331 t=find_handle_by_name(full_name); | |
332 free(full_name); | |
333 return t; | |
334 } | |
335 | |
9965 | 336 long __stdcall RegOpenKeyExA(long key, const char* subkey, long reserved, long access, int* newkey) |
1 | 337 { |
338 char* full_name; | |
339 reg_handle_t* t; | |
340 struct reg_value* v; | |
341 TRACE("Opening key %s\n", subkey); | |
3128 | 342 |
1 | 343 if(!regs) |
344 init_registry() | |
3128 | 345 ; |
1 | 346 /* t=find_handle_2(key, subkey); |
3128 | 347 |
1 | 348 if(t==0) |
349 return -1; | |
350 | |
351 if(t==(reg_handle_t*)-1) | |
352 return -1; | |
3128 | 353 */ |
354 full_name=build_keyname(key, subkey); | |
1 | 355 if(!full_name) |
356 return -1; | |
3128 | 357 TRACE("Opening key Fullname %s\n", full_name); |
358 v=find_value_by_name(full_name); | |
1 | 359 |
360 t=insert_handle(generate_handle(), full_name); | |
361 *newkey=t->handle; | |
362 free(full_name); | |
3128 | 363 |
1 | 364 return 0; |
3128 | 365 } |
9965 | 366 long __stdcall RegCloseKey(long key) |
1 | 367 { |
7386 | 368 reg_handle_t *handle; |
369 if(key==(long)HKEY_LOCAL_MACHINE) | |
1 | 370 return 0; |
7386 | 371 if(key==(long)HKEY_CURRENT_USER) |
1 | 372 return 0; |
373 handle=find_handle(key); | |
374 if(handle==0) | |
375 return 0; | |
376 if(handle->prev) | |
377 handle->prev->next=handle->next; | |
378 if(handle->next) | |
379 handle->next->prev=handle->prev; | |
380 if(handle->name) | |
381 free(handle->name); | |
382 if(handle==head) | |
383 head=head->prev; | |
384 free(handle); | |
385 return 1; | |
3128 | 386 } |
387 | |
9965 | 388 long __stdcall RegQueryValueExA(long key, const char* value, int* reserved, int* type, int* data, int* count) |
1 | 389 { |
7386 | 390 struct reg_value* t; |
391 char* c; | |
392 TRACE("Querying value %s\n", value); | |
393 if(!regs) | |
394 init_registry(); | |
3465 | 395 |
7386 | 396 c=build_keyname(key, value); |
397 if (!c) | |
398 return 1; | |
399 t=find_value_by_name(c); | |
400 free(c); | |
401 if (t==0) | |
402 return 2; | |
403 if (type) | |
404 *type=t->type; | |
405 if (data) | |
406 { | |
407 memcpy(data, t->value, (t->len<*count)?t->len:*count); | |
408 TRACE("returning %d bytes: %d\n", t->len, *(int*)data); | |
409 } | |
410 if(*count<t->len) | |
411 { | |
412 *count=t->len; | |
413 return ERROR_MORE_DATA; | |
1 | 414 } |
415 else | |
416 { | |
7386 | 417 *count=t->len; |
418 } | |
1 | 419 return 0; |
3128 | 420 } |
9965 | 421 long __stdcall RegCreateKeyExA(long key, const char* name, long reserved, |
3128 | 422 void* classs, long options, long security, |
423 void* sec_attr, int* newkey, int* status) | |
1 | 424 { |
7386 | 425 reg_handle_t* t; |
426 char* fullname; | |
427 struct reg_value* v; | |
428 // TRACE("Creating/Opening key %s\n", name); | |
429 if(!regs) | |
430 init_registry(); | |
3465 | 431 |
7386 | 432 fullname=build_keyname(key, name); |
433 if (!fullname) | |
434 return 1; | |
435 TRACE("Creating/Opening key %s\n", fullname); | |
436 v=find_value_by_name(fullname); | |
437 if(v==0) | |
438 { | |
439 int qw=45708; | |
440 v=insert_reg_value(key, name, DIR, &qw, 4); | |
441 if (status) *status=REG_CREATED_NEW_KEY; | |
442 // return 0; | |
443 } | |
1 | 444 |
7386 | 445 t=insert_handle(generate_handle(), fullname); |
446 *newkey=t->handle; | |
447 free(fullname); | |
448 return 0; | |
1 | 449 } |
1416 | 450 |
3128 | 451 /* |
452 LONG RegEnumValue( | |
453 HKEY hKey, // handle to key to query | |
454 DWORD dwIndex, // index of value to query | |
455 LPTSTR lpValueName, // address of buffer for value string | |
456 LPDWORD lpcbValueName, // address for size of value buffer | |
457 LPDWORD lpReserved, // reserved | |
458 LPDWORD lpType, // address of buffer for type code | |
459 LPBYTE lpData, // address of buffer for value data | |
460 LPDWORD lpcbData // address for size of data buffer | |
461 ); | |
462 */ | |
463 | |
9965 | 464 long __stdcall RegEnumValueA(HKEY hkey, DWORD index, LPSTR value, LPDWORD val_count, |
1416 | 465 LPDWORD reserved, LPDWORD type, LPBYTE data, LPDWORD count) |
466 { | |
3128 | 467 // currenly just made to support MSZH & ZLIB |
468 //printf("Reg Enum 0x%x %d %s %d data: %p %d %d >%s<\n", hkey, index, | |
469 // value, *val_count, data, *count, reg_size, data); | |
470 reg_handle_t* t = find_handle(hkey); | |
471 if (t && index < 10) | |
1416 | 472 { |
3128 | 473 struct reg_value* v=find_value_by_name(t->name); |
474 if (v) | |
1416 | 475 { |
3128 | 476 memcpy(data, v->value, (v->len < *count) ? v->len : *count); |
477 if(*count < v->len) | |
478 *count = v->len; | |
479 if (type) | |
1416 | 480 *type = v->type; |
481 //printf("Found handle %s\n", v->name); | |
3128 | 482 return 0; |
1416 | 483 } |
484 } | |
3128 | 485 return ERROR_NO_MORE_ITEMS; |
1416 | 486 } |
487 | |
9965 | 488 long __stdcall RegSetValueExA(long key, const char* name, long v1, long v2, const void* data, long size) |
1 | 489 { |
490 char* c; | |
7386 | 491 TRACE("Request to set value %s %d\n", name, *(const int*)data); |
1 | 492 if(!regs) |
3465 | 493 init_registry(); |
494 | |
1 | 495 c=build_keyname(key, name); |
496 if(c==NULL) | |
497 return 1; | |
498 insert_reg_value(key, name, v2, data, size); | |
499 free(c); | |
500 return 0; | |
3128 | 501 } |
3465 | 502 |
9965 | 503 long __stdcall RegEnumKeyExA(HKEY hKey, DWORD dwIndex, LPSTR lpName, LPDWORD lpcbName, |
3465 | 504 LPDWORD lpReserved, LPSTR lpClass, LPDWORD lpcbClass, |
505 LPFILETIME lpftLastWriteTime) | |
506 { | |
507 return ERROR_NO_MORE_ITEMS; | |
508 } |