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