]> granicus.if.org Git - php/commitdiff
add an interface for registering storage modules at run-time.
authorSascha Schumann <sas@php.net>
Thu, 3 May 2001 15:48:49 +0000 (15:48 +0000)
committerSascha Schumann <sas@php.net>
Thu, 3 May 2001 15:48:49 +0000 (15:48 +0000)
ext/session/mod_mm.c
ext/session/modules.c [deleted file]
ext/session/php_session.h
ext/session/session.c

index ba647f34e18d23f77508e1a0ebf3f6e065d418cf..d6a20f9b382c025521b8bbf21882f1eae43dfeeb 100644 (file)
@@ -211,6 +211,7 @@ PHP_GINIT_FUNCTION(ps_mm)
                ps_mm_instance = NULL;
                return FAILURE;
        }
+       php_session_register_module(&ps_mod_mm);
        return SUCCESS;
 }
 
diff --git a/ext/session/modules.c b/ext/session/modules.c
deleted file mode 100644 (file)
index f866a42..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-/*
- * To add a PHP session module, #include its header file and 
- * add a ps_xxx_ptr in the struct...
- */
-
-#include "mod_files.h"
-#include "mod_mm.h"
-#include "mod_user.h"
-
-static ps_module *ps_modules[] = {
-       ps_files_ptr,
-       ps_mm_ptr,
-       ps_user_ptr,
-};
-
index 874d5e271485960c50ca30872798bb2a2f5003e5..c11624cbbf5b18af2e782959964426d36f9b0d07 100644 (file)
@@ -169,6 +169,8 @@ void session_adapt_url(const char *, size_t, char **, size_t *);
 void php_set_session_var(char *name, size_t namelen, zval *state_val PSLS_DC);
 int php_get_session_var(char *name, size_t namelen, zval ***state_var PLS_DC PSLS_DC ELS_DC);
 
+int php_session_register_module(ps_module *);
+
 int php_session_register_serializer(const char *name,
                int (*encode)(PS_SERIALIZER_ENCODE_ARGS),
                int (*decode)(PS_SERIALIZER_DECODE_ARGS));
index f9e2c4d3aea174c4f0260c1ac7e60f4f4898b30a..c55a12c342745e2029203f707223f2f0b4654b60 100644 (file)
 #include "ext/standard/php_rand.h"                   /* for RAND_MAX */
 #include "ext/standard/info.h"
 
-#include "modules.c"
-
 #include "ext/standard/php_smart_str.h"
 
+#include "mod_files.h"
+#include "mod_user.h"
+
 function_entry session_functions[] = {
        PHP_FE(session_name, NULL)
        PHP_FE(session_module_name, NULL)
@@ -131,6 +132,13 @@ static ps_serializer ps_serializers[MAX_SERIALIZERS + 1] = {
        PS_SERIALIZER_ENTRY(php_binary)
 };
 
+#define MAX_MODULES 10
+
+static ps_module *ps_modules[MAX_MODULES + 1] = {
+       ps_files_ptr,
+       ps_user_ptr
+};
+
 int php_session_register_serializer(const char *name, 
                int (*encode)(PS_SERIALIZER_ENCODE_ARGS),
                int (*decode)(PS_SERIALIZER_DECODE_ARGS))
@@ -152,6 +160,21 @@ int php_session_register_serializer(const char *name,
        return ret;
 }
 
+int php_session_register_module(ps_module *ptr)
+{
+       int ret = -1;
+       int i;
+
+       for (i = 0; i < MAX_MODULES; i++) {
+               if (!ps_modules[i]) {
+                       ps_modules[i] = ptr;
+                       ret = 0;
+                       break;
+               }       
+       }
+       
+       return ret;
+}
 
 PHP_MINIT_FUNCTION(session);
 PHP_RINIT_FUNCTION(session);
@@ -713,9 +736,9 @@ static ps_module *_php_find_ps_module(char *name PSLS_DC)
 {
        ps_module *ret = NULL;
        ps_module **mod;
-       ps_module **end = ps_modules + (sizeof(ps_modules)/sizeof(ps_module*));
+       int i;
 
-       for (mod = ps_modules; mod < end; mod++)
+       for (i = 0, mod = ps_modules; i < MAX_MODULES; i++, mod++)
                if (*mod && !strcasecmp(name, (*mod)->name)) {
                        ret = *mod;
                        break;