CVS update: php31/os/nt
| From: | shane | Date: | Tue, 15 Sep 1998 01:34:27 +0000 |
| Subject: | CVS update: php31/os/nt | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-1075@lists.php.net to get a copy of this message | ||
Date: Monday September 14, 1998 @ 21:34
Author: shane
Update of /repository/php31/os/nt
In directory asf:/u2/tmp/cvs-serv27176/os/nt
Modified Files:
registry.c
Log Message:
registry now gets cached.
Index: php31/os/nt/registry.c
diff -c php31/os/nt/registry.c:1.6 php31/os/nt/registry.c:1.7
*** php31/os/nt/registry.c:1.6 Mon Sep 14 12:56:33 1998
--- php31/os/nt/registry.c Mon Sep 14 21:34:26 1998
***************
*** 5,11 ****
--- 5,14 ----
#include "registry.h"
#include "winutil.h"
#include "dl.h"
+ #include "time.h"
+ void *reg_mutex;
+
static struct {
char * name;
HKEY hkey;
***************
*** 16,22 ****
{ "HKEY_USERS", HKEY_USERS }
};
! function_entry php3_win32_functions[] = {
{"registry_open", php3_win32_reg_open, NULL},
{"registry_read", php3_win32_reg_read, NULL},
{"registry_read_key", php3_win32_reg_read_key, NULL},
--- 19,25 ----
{ "HKEY_USERS", HKEY_USERS }
};
! function_entry php3_registry_functions[] = {
{"registry_open", php3_win32_reg_open, NULL},
{"registry_read", php3_win32_reg_read, NULL},
{"registry_read_key", php3_win32_reg_read_key, NULL},
***************
*** 26,43 ****
{NULL, NULL, NULL}
};
php3_module_entry php3_win32_reg_module_entry = {
! "Win32 Registry (Read Only)", php3_win32_functions, NULL, NULL, NULL, NULL, NULL,
STANDARD_MODULE_PROPERTIES
};
int _php3_win32_reg_init(INLINE_TLS_VOID)
{
- /*called from module startup*/
GLOBAL(registry_le_hkey) = _register_list_destructors(NULL, NULL, 0);
return SUCCESS;
}
PHPAPI BYTE *_php3_win32_reg_read(char *value_name,DWORD *dwType){
int i,found;
char *root, *path, *key_name, *p;
--- 29,47 ----
{NULL, NULL, NULL}
};
+
php3_module_entry php3_win32_reg_module_entry = {
! "Win32 Registry (Read Only)", php3_registry_functions, NULL, NULL, NULL, NULL, NULL,
STANDARD_MODULE_PROPERTIES
};
int _php3_win32_reg_init(INLINE_TLS_VOID)
{
GLOBAL(registry_le_hkey) = _register_list_destructors(NULL, NULL, 0);
return SUCCESS;
}
+
PHPAPI BYTE *_php3_win32_reg_read(char *value_name,DWORD *dwType){
int i,found;
char *root, *path, *key_name, *p;
***************
*** 515,521 ****
if (_php3_win32_reg_read_value(pRegKey, key, &dwSize, &dwType, pbuffer, &dwbSize
_INLINE_TLS)) {
if (dwType == REG_SZ) {
! #if 1
{
char buf[10];
snprintf(buf,10," (%u) = ",dwSize);
--- 519,525 ----
if (_php3_win32_reg_read_value(pRegKey, key, &dwSize, &dwType, pbuffer, &dwbSize
_INLINE_TLS)) {
if (dwType == REG_SZ) {
! #if 0
{
char buf[10];
snprintf(buf,10," (%u) = ",dwSize);
***************
*** 598,608 ****
}
-
/*******************************************************\
* The following functions handle per server direcive
* cacheing
\*******************************************************/
/*******************************************************\
--- 602,738 ----
}
/*******************************************************\
* The following functions handle per server direcive
* cacheing
\*******************************************************/
+ struct _reg_entry{
+ BYTE *name;
+ BYTE *value;
+ struct _reg_entry *next;
+ };
+
+ struct _reg_cache{
+ char *directory;
+ long updated;
+ char *include_path;
+ struct _reg_entry *vars;
+ struct _reg_cache *next;
+ };
+
+ struct _reg_cache *_reg_head;
+
+
+ int _reg_cache_dir_config(struct _reg_cache *regentry){
+ RegKey *pRegKey;
+ DWORD dwSize, dwbSize, dwType, i;
+ BYTE *key, *pbuffer;
+ struct _reg_entry *var=NULL;
+ TLS_VARS;
+
+ if (pRegKey = _php3_win32_reg_open(regentry->directory _INLINE_TLS)) {
+ /* ok default keys exist */
+
+ /* need to time stamp our registry read, so that if the
+ registry changes, we can re-read that information, thus
+ avioding a server restart to re-read the registry.
+ */
+ regentry->updated=time(NULL);
+
+ for (i=0;i < pRegKey->dwcValues; i++){
+
+ /* allocate memory for keynames and values. */
+ var=malloc(sizeof(struct _reg_entry));
+ dwSize = (pRegKey->dwcMaxValueName+1);
+ key=emalloc(dwSize);
+ dwbSize = (pRegKey->dwcMaxValueData+1);
+ pbuffer=emalloc(dwbSize);
+
+ if (_php3_win32_reg_read_value(pRegKey, key, &dwSize, &dwType, pbuffer, &dwbSize
_INLINE_TLS)) {
+ var->name=strdup(key);
+ var->value=strdup(pbuffer);
+ var->next=regentry->vars;
+ regentry->vars=var;
+ var=NULL;
+ }
+ efree(key);
+ key=NULL;
+ efree(pbuffer);
+ pbuffer=NULL;
+ }
+ _php3_win32_reg_close(pRegKey _INLINE_TLS);
+ return 1;
+ }
+ return 0;
+ }
+
+ struct _reg_cache *_reg_insert_cache_entry(char *dir){
+ struct _reg_cache *entry = malloc(sizeof(struct _reg_cache));
+
+ entry->next=NULL;
+ entry->vars=NULL;
+ entry->directory=strdup(dir);
+ entry->include_path=NULL;
+ if (!_reg_head) {
+ _reg_head = entry;
+ } else {
+ entry->next=_reg_head;
+ _reg_head=entry;
+ }
+ return entry;
+ }
+
+ struct _reg_cache *_reg_get_cached_dir(char *dir){
+ struct _reg_cache *entry=_reg_head;
+
+ /* we want to lock now, so we can add new cache entries as we hit them*/
+ PHP3_MUTEX_LOCK(reg_mutex);
+ while(entry){
+ if (!stricmp(dir,entry->directory)) {
+
+ /* FIXME we need to compare timestamps so see if
+ we need to reload this registry cache */
+ PHP3_MUTEX_UNLOCK(reg_mutex);
+ return entry;
+ }
+ entry=entry->next;
+ }
+ /* no match, lets add it now */
+ entry=_reg_insert_cache_entry(dir);
+
+ /* lets retrieve registry settings */
+ _reg_cache_dir_config(entry);
+
+ PHP3_MUTEX_UNLOCK(reg_mutex);
+ return entry;
+ }
+
+ void _reg_del_cache_entry(struct _reg_cache *regcache){
+ struct _reg_entry *tmp,*var=regcache->vars;
+
+ while (var) {
+ if (var->name) free(var->name);
+ if (var->value) free(var->value);
+ tmp=var->next;
+ free(var);
+ var=tmp;
+ }
+ if (regcache->include_path) free(regcache->include_path);
+ free(regcache);
+ }
+
+ void _reg_clear_cache(void){
+ struct _reg_cache *next;
+
+
+ PHP3_MUTEX_LOCK(reg_mutex);
+ while(_reg_head){
+ next=_reg_head->next;
+ _reg_del_cache_entry(_reg_head);
+ _reg_head=next;
+ }
+ PHP3_MUTEX_UNLOCK(reg_mutex);
+ }
/*******************************************************\
***************
*** 610,616 ****
* and per directory directives
\*******************************************************/
! void _reg_set_server_var(BYTE *name, BYTE *value INLINE_TLS){
int i=0;
#define AC_REGISTRY_TABLE
--- 740,747 ----
* and per directory directives
\*******************************************************/
! /* this function reads the cache and sets the php3_ini structure */
! void _reg_set_server_var(struct _reg_entry *entry, struct _reg_cache *cached_dir INLINE_TLS){
int i=0;
#define AC_REGISTRY_TABLE
***************
*** 619,645 ****
#undef AC_REGISTRY_TABLE
while(php3_reg_vars[i].name){
! if(!stricmp(name,php3_reg_vars[i].name) &&
(php3_reg_vars[i].user_modify == AC_YES ||
(php3_reg_vars[i].user_modify == AC_NO_SAFEMODE &&
!php3_ini_master.safe_mode))){
switch (php3_reg_vars[i].type) {
case AC_LONG:
! (*(DWORD *)php3_reg_vars[i].address) = atol(value);
break;
case AC_STRING:
! if (stricmp(php3_reg_vars[i].name,"include_path")) {
! (*(char **)php3_reg_vars[i].address) = estrdup(value);
} else {
! int size=strlen(GLOBAL(php3_ini)->include_path)+strlen(value)+2;
! BYTE *temp=emalloc(size);
!
! snprintf(temp, size, "%s;%s", value, GLOBAL(php3_ini)->include_path);
! (*(char **)php3_reg_vars[i].address) = temp;
}
break;
default:
break;
}
}
--- 750,782 ----
#undef AC_REGISTRY_TABLE
while(php3_reg_vars[i].name){
! if(!stricmp(entry->name,php3_reg_vars[i].name) &&
(php3_reg_vars[i].user_modify == AC_YES ||
(php3_reg_vars[i].user_modify == AC_NO_SAFEMODE &&
!php3_ini_master.safe_mode))){
switch (php3_reg_vars[i].type) {
case AC_LONG:
! (*(DWORD *)php3_reg_vars[i].address) = atoi(entry->value);
! return;
break;
case AC_STRING:
! if (!stricmp(php3_reg_vars[i].name,"include_path")) {
! if (!cached_dir->include_path) {
! int size=strlen(GLOBAL(php3_ini)->include_path)+strlen(entry->value)+2;
! BYTE *temp=malloc(size);
!
! snprintf(temp, size, "%s;%s", entry->value,
GLOBAL(php3_ini)->include_path);
! cached_dir->include_path=temp;
! }
! (*(char **)php3_reg_vars[i].address)=cached_dir->include_path;
} else {
! (*(char **)php3_reg_vars[i].address) = entry->value;
}
+ return;
break;
default:
+ return;
break;
}
}
***************
*** 648,676 ****
}
void _reg_get_server_config(char *server INLINE_TLS){
! RegKey *pRegKey;
char regkey[1024];
- DWORD dwSize, dwbSize, dwType, i;
- BYTE *key, *pbuffer;
snprintf(regkey, 1024, "%s%s", PHP_REG_KEY, server);
! if (pRegKey = _php3_win32_reg_open(regkey _INLINE_TLS)) {
! /* ok default keys exist */
! for (i=0;i < pRegKey->dwcValues; i++){
! /* allocate memory for keynames and values. */
! dwSize = (pRegKey->dwcMaxValueName+1);
! key=emalloc(dwSize);
! dwbSize = (pRegKey->dwcMaxValueData+1);
! pbuffer=emalloc(dwbSize);
! if (_php3_win32_reg_read_value(pRegKey, key, &dwSize, &dwType, pbuffer, &dwbSize
_INLINE_TLS)) {
! _reg_set_server_var(key, pbuffer _INLINE_TLS);
! }
! efree(key);
! key = NULL;
! efree(pbuffer);
! pbuffer = NULL;
}
- _php3_win32_reg_close(pRegKey _INLINE_TLS);
}
}
--- 785,801 ----
}
void _reg_get_server_config(char *server INLINE_TLS){
! struct _reg_entry *var;
! struct _reg_cache *cached_dir;
char regkey[1024];
snprintf(regkey, 1024, "%s%s", PHP_REG_KEY, server);
! if (cached_dir = _reg_get_cached_dir(regkey)) {
! var=cached_dir->vars;
! while (var){
! _reg_set_server_var(var, cached_dir _INLINE_TLS);
! var=var->next;
}
}
}
***************
*** 695,717 ****
}
}
- /* FIXME not finished here on down. */
-
- void _reg_free_server_config(INLINE_TLS_VOID) {
- char *server=NULL;
- int i;
- #define AC_REGISTRY_TABLE
- #include "automated_configuration_definitions.h"
- #include "automated_configuration.h"
- #undef AC_REGISTRY_TABLE
-
- while(php3_reg_vars[i].name){
- if(php3_reg_vars[i].value){
- if(php3_reg_vars[i].value->strval){
- efree(php3_reg_vars[i].value->strval);
- }
- efree(php3_reg_vars[i].value);
- }
- }
- }
--- 820,823 ----
--
PHP Development Mailing List http://www.php.net/
To unsubscribe send an empty message to php-dev-unsubscribe@lists.php.net
For help: php-dev-help@lists.php.net