X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libs%2Floader%2Fregistry.c;h=8620cb1c89b4acc35e09fdb3a30b322a27083bd1;hb=6ee1e193fd896ab9a4729fde14f009d9ce629815;hp=2505bf2a8f9b33ee640a1ed0d1cb58b135545936;hpb=3305b049e7f587b23359a1c9047fb5763d19c1dc;p=vlc diff --git a/libs/loader/registry.c b/libs/loader/registry.c index 2505bf2a8f..8620cb1c89 100644 --- a/libs/loader/registry.c +++ b/libs/loader/registry.c @@ -54,18 +54,18 @@ static char* localregpathname = NULL; typedef struct reg_handle_s { - int handle; - char* name; - struct reg_handle_s* next; - struct reg_handle_s* prev; + int handle; + char* name; + struct reg_handle_s* next; + struct reg_handle_s* prev; } reg_handle_t; struct reg_value { - int type; - char* name; - int len; - char* value; + int type; + char* name; + int len; + char* value; }; static struct reg_value* regs = NULL; @@ -83,9 +83,9 @@ static void init_registry(void); static void create_registry(void){ if(regs) { - printf("Logic error: create_registry() called with existing registry\n"); - save_registry(); - return; + printf("Logic error: create_registry() called with existing registry\n"); + save_registry(); + return; } regs=(struct reg_value*)malloc(3*sizeof(struct reg_value)); regs[0].type=regs[1].type=DIR; @@ -102,75 +102,75 @@ static void create_registry(void){ static void open_registry(void) { - int fd; - int i; - unsigned int len; - if(regs) - { - printf("Multiple open_registry(>\n"); - return; - } - fd = open(localregpathname, O_RDONLY); - if (fd == -1) - { - printf("Creating new registry\n"); - create_registry(); - return; - } - read(fd, ®_size, 4); - regs=(struct reg_value*)malloc(reg_size*sizeof(struct reg_value)); - head = 0; - for(i=0; i\n"); + return; + } + fd = open(localregpathname, O_RDONLY); + if (fd == -1) + { + printf("Creating new registry\n"); + create_registry(); + return; + } + read(fd, ®_size, 4); + regs=(struct reg_value*)malloc(reg_size*sizeof(struct reg_value)); + head = 0; + for(i=0; iname) - free(t->name); - t=t->prev; + free(t->name); + t=t->prev; free(f); } head = 0; if (regs) { int i; - for(i=0; iprev) - { - if(!strcmp(t->name, name)) - { - return t; - } - } - return 0; + reg_handle_t* t; + for(t=head; t; t=t->prev) + { + if(!strcmp(t->name, name)) + { + return t; + } + } + return 0; } static struct reg_value* find_value_by_name(const char* name) { - int i; - for(i=0; iprev) - { - if(t->handle==handle) - { - return t; - } - } - return 0; + reg_handle_t* t; + for(t=head; t; t=t->prev) + { + if(t->handle==handle) + { + return t; + } + } + return 0; } static int generate_handle() { - static unsigned int zz=249; - zz++; - while((zz==HKEY_LOCAL_MACHINE) || (zz==HKEY_CURRENT_USER)) - zz++; - return zz; + static unsigned int zz=249; + zz++; + while((zz==HKEY_LOCAL_MACHINE) || (zz==HKEY_CURRENT_USER)) + zz++; + return zz; } static reg_handle_t* insert_handle(long handle, const char* name) { - reg_handle_t* t; - t=(reg_handle_t*)malloc(sizeof(reg_handle_t)); - if(head==0) - { - t->prev=0; - } - else - { - head->next=t; - t->prev=head; - } - t->next=0; - t->name=(char*)malloc(strlen(name)+1); - strcpy(t->name, name); - t->handle=handle; - head=t; - return t; + reg_handle_t* t; + t=(reg_handle_t*)malloc(sizeof(reg_handle_t)); + if(head==0) + { + t->prev=0; + } + else + { + head->next=t; + t->prev=head; + } + t->next=0; + t->name=(char*)malloc(strlen(name)+1); + strcpy(t->name, name); + t->handle=handle; + head=t; + return t; } static char* build_keyname(long key, const char* subkey) { - char* full_name; - reg_handle_t* t; - if((t=find_handle(key))==0) - { - TRACE("Invalid key\n"); - return NULL; - } - if(subkey==NULL) - subkey=""; - full_name=(char*)malloc(strlen(t->name)+strlen(subkey)+10); - strcpy(full_name, t->name); - strcat(full_name, "\\"); - strcat(full_name, subkey); - return full_name; + char* full_name; + reg_handle_t* t; + if((t=find_handle(key))==0) + { + TRACE("Invalid key\n"); + return NULL; + } + if(subkey==NULL) + subkey=""; + full_name=(char*)malloc(strlen(t->name)+strlen(subkey)+10); + strcpy(full_name, t->name); + strcat(full_name, "\\"); + strcat(full_name, subkey); + return full_name; } static struct reg_value* insert_reg_value(int handle, const char* name, int type, const void* value, int len) { - reg_handle_t* t; - struct reg_value* v; - char* fullname; - if((fullname=build_keyname(handle, name))==NULL) - { - TRACE("Invalid handle\n"); - return NULL; - } - - if((v=find_value_by_name(fullname))==0) - //creating new value in registry - { - if(regs==0) - create_registry(); - regs=(struct reg_value*)realloc(regs, sizeof(struct reg_value)*(reg_size+1)); - //regs=(struct reg_value*)my_realloc(regs, sizeof(struct reg_value)*(reg_size+1)); - v=regs+reg_size; - reg_size++; - } - else - //replacing old one - { - free(v->value); - free(v->name); - } - TRACE("RegInsert '%s' %p v:%d len:%d\n", name, value, *(int*)value, len); - v->type=type; - v->len=len; - v->value=(char*)malloc(len); - memcpy(v->value, value, len); - v->name=(char*)malloc(strlen(fullname)+1); - strcpy(v->name, fullname); + reg_handle_t* t; + struct reg_value* v; + char* fullname; + if((fullname=build_keyname(handle, name))==NULL) + { + TRACE("Invalid handle\n"); + return NULL; + } + + if((v=find_value_by_name(fullname))==0) + //creating new value in registry + { + if(regs==0) + create_registry(); + regs=(struct reg_value*)realloc(regs, sizeof(struct reg_value)*(reg_size+1)); + //regs=(struct reg_value*)my_realloc(regs, sizeof(struct reg_value)*(reg_size+1)); + v=regs+reg_size; + reg_size++; + } + else + //replacing old one + { + free(v->value); + free(v->name); + } + TRACE("RegInsert '%s' %p v:%d len:%d\n", name, value, *(int*)value, len); + v->type=type; + v->len=len; + v->value=(char*)malloc(len); + memcpy(v->value, value, len); + v->name=(char*)malloc(strlen(fullname)+1); + strcpy(v->name, fullname); free(fullname); - save_registry(); - return v; + save_registry(); + return v; } static void init_registry(void) { - TRACE("Initializing registry\n"); - // can't be free-ed - it's static and probably thread - // unsafe structure which is stored in glibc + TRACE("Initializing registry\n"); + // can't be free-ed - it's static and probably thread + // unsafe structure which is stored in glibc #ifdef MPLAYER - regpathname = get_path("registry"); - localregpathname = regpathname; + regpathname = get_path("registry"); + localregpathname = regpathname; #else - // regpathname is an external pointer + // regpathname is an external pointer // - // registry.c is holding its own internal pointer - // localregpathname - which is being allocate/deallocated + // registry.c is holding its own internal pointer + // localregpathname - which is being allocate/deallocated - if (localregpathname == 0) - { + if (localregpathname == 0) + { const char* pthn = regpathname; - if (!regpathname) - { - // avifile - for now reading data from user's home - struct passwd* pwent; - pwent = getpwuid(geteuid()); + if (!regpathname) + { + // avifile - for now reading data from user's home + struct passwd* pwent; + pwent = getpwuid(geteuid()); pthn = pwent->pw_dir; - } + } - localregpathname = (char*)malloc(strlen(pthn)+20); - strcpy(localregpathname, pthn); - strcat(localregpathname, "/.registry"); - } + localregpathname = (char*)malloc(strlen(pthn)+20); + strcpy(localregpathname, pthn); + strcat(localregpathname, "/.registry"); + } #endif - open_registry(); - insert_handle(HKEY_LOCAL_MACHINE, "HKLM"); - insert_handle(HKEY_CURRENT_USER, "HKCU"); + open_registry(); + insert_handle(HKEY_LOCAL_MACHINE, "HKLM"); + insert_handle(HKEY_CURRENT_USER, "HKCU"); } static reg_handle_t* find_handle_2(long key, const char* subkey) { - char* full_name; - reg_handle_t* t; - if((t=find_handle(key))==0) - { - TRACE("Invalid key\n"); - return (reg_handle_t*)-1; - } - if(subkey==NULL) - return t; - full_name=(char*)malloc(strlen(t->name)+strlen(subkey)+10); - strcpy(full_name, t->name); - strcat(full_name, "\\"); - strcat(full_name, subkey); - t=find_handle_by_name(full_name); - free(full_name); - return t; + char* full_name; + reg_handle_t* t; + if((t=find_handle(key))==0) + { + TRACE("Invalid key\n"); + return (reg_handle_t*)-1; + } + if(subkey==NULL) + return t; + full_name=(char*)malloc(strlen(t->name)+strlen(subkey)+10); + strcpy(full_name, t->name); + strcat(full_name, "\\"); + strcat(full_name, subkey); + t=find_handle_by_name(full_name); + free(full_name); + return t; } long __stdcall RegOpenKeyExA(long key, const char* subkey, long reserved, long access, int* newkey) @@ -387,13 +387,13 @@ long __stdcall RegOpenKeyExA(long key, const char* subkey, long reserved, long a if(!regs) init_registry() ; -/* t=find_handle_2(key, subkey); +/* t=find_handle_2(key, subkey); - if(t==0) - return -1; + if(t==0) + return -1; - if(t==(reg_handle_t*)-1) - return -1; + if(t==(reg_handle_t*)-1) + return -1; */ full_name=build_keyname(key, subkey); if(!full_name) @@ -411,20 +411,20 @@ long __stdcall RegCloseKey(long key) { reg_handle_t *handle; if(key==(long)HKEY_LOCAL_MACHINE) - return 0; + return 0; if(key==(long)HKEY_CURRENT_USER) - return 0; + return 0; handle=find_handle(key); if(handle==0) - return 0; + return 0; if(handle->prev) - handle->prev->next=handle->next; + handle->prev->next=handle->next; if(handle->next) - handle->next->prev=handle->prev; + handle->next->prev=handle->prev; if(handle->name) - free(handle->name); + free(handle->name); if(handle==head) - head=head->prev; + head=head->prev; free(handle); return 1; } @@ -435,55 +435,55 @@ long __stdcall RegQueryValueExA(long key, const char* value, int* reserved, int* char* c; TRACE("Querying value %s\n", value); if(!regs) - init_registry(); + init_registry(); c=build_keyname(key, value); if (!c) - return 1; + return 1; t=find_value_by_name(c); free(c); if (t==0) - return 2; + return 2; if (type) - *type=t->type; + *type=t->type; if (data) { - memcpy(data, t->value, (t->len<*count)?t->len:*count); - TRACE("returning %d bytes: %d\n", t->len, *(int*)data); + memcpy(data, t->value, (t->len<*count)?t->len:*count); + TRACE("returning %d bytes: %d\n", t->len, *(int*)data); } if(*countlen) { - *count=t->len; - return ERROR_MORE_DATA; + *count=t->len; + return ERROR_MORE_DATA; } else { - *count=t->len; + *count=t->len; } return 0; } long __stdcall RegCreateKeyExA(long key, const char* name, long reserved, - void* classs, long options, long security, - void* sec_attr, int* newkey, int* status) + void* classs, long options, long security, + void* sec_attr, int* newkey, int* status) { reg_handle_t* t; char* fullname; struct reg_value* v; // TRACE("Creating/Opening key %s\n", name); if(!regs) - init_registry(); + init_registry(); fullname=build_keyname(key, name); if (!fullname) - return 1; + return 1; TRACE("Creating/Opening key %s\n", fullname); v=find_value_by_name(fullname); if(v==0) { - int qw=45708; - v=insert_reg_value(key, name, DIR, &qw, 4); - if (status) *status=REG_CREATED_NEW_KEY; - // return 0; + int qw=45708; + v=insert_reg_value(key, name, DIR, &qw, 4); + if (status) *status=REG_CREATED_NEW_KEY; + // return 0; } t=insert_handle(generate_handle(), fullname); @@ -506,7 +506,7 @@ LONG RegEnumValue( */ long __stdcall RegEnumValueA(HKEY hkey, DWORD index, LPSTR value, LPDWORD val_count, - LPDWORD reserved, LPDWORD type, LPBYTE data, LPDWORD count) + LPDWORD reserved, LPDWORD type, LPBYTE data, LPDWORD count) { // currenly just made to support MSZH & ZLIB //printf("Reg Enum 0x%x %d %s %d data: %p %d %d >%s<\n", hkey, index, @@ -514,17 +514,17 @@ long __stdcall RegEnumValueA(HKEY hkey, DWORD index, LPSTR value, LPDWORD val_co reg_handle_t* t = find_handle(hkey); if (t && index < 10) { - struct reg_value* v=find_value_by_name(t->name); - if (v) - { - memcpy(data, v->value, (v->len < *count) ? v->len : *count); - if(*count < v->len) - *count = v->len; - if (type) - *type = v->type; - //printf("Found handle %s\n", v->name); - return 0; - } + struct reg_value* v=find_value_by_name(t->name); + if (v) + { + memcpy(data, v->value, (v->len < *count) ? v->len : *count); + if(*count < v->len) + *count = v->len; + if (type) + *type = v->type; + //printf("Found handle %s\n", v->name); + return 0; + } } return ERROR_NO_MORE_ITEMS; } @@ -535,19 +535,19 @@ long __stdcall RegSetValueExA(long key, const char* name, long v1, long v2, cons char* c; TRACE("Request to set value %s %d\n", name, *(const int*)data); if(!regs) - init_registry(); + init_registry(); c=build_keyname(key, name); if(c==NULL) - return 1; + return 1; insert_reg_value(key, name, v2, data, size); free(c); return 0; } long __stdcall RegEnumKeyExA(HKEY hKey, DWORD dwIndex, LPSTR lpName, LPDWORD lpcbName, - LPDWORD lpReserved, LPSTR lpClass, LPDWORD lpcbClass, - LPFILETIME lpftLastWriteTime) + LPDWORD lpReserved, LPSTR lpClass, LPDWORD lpcbClass, + LPFILETIME lpftLastWriteTime) { return ERROR_NO_MORE_ITEMS; }