Re: [PHP4BETA] proposed fopen_wrappers generalization / patch v.2
[email protected] (Hartmut Holzgraefe) Wed, 07 Jun 2000 20:58:15 +0200
| Newsgroups | php.version4 |
|---|---|
| Organization | SIX Offene Systeme GmbH |
| Message-ID | <[email protected]> |
Andi Gutmans wrote:
>
> It definitely sounds good but can you describe it in a bit more detail? :)
>
Well, i'll try to remember the steps i took so far:
1) the function doing fopen wrapping was one big ugly piece
containing code for simple fopen, for HTTP and FTP protocol
initiation on sockets and the PHP special cases for
stdin/stdout/stderr
all in one
i devided this one in a master function figuring out url type
with plain old fopen as fallback and one function for each
of the URL types 'http:', 'ftp:' and 'php:'
no problem so far
2) i added support for local 'file:/path' URLs by just stripping of
the 'file:' prefix for local files and generating a warning
if 'file://hostname/path' was used
still no problem, although i temporarily borke it later on
3) experimental stage: here i built a simple array of structs that
mapped URL type names against pointers to handler functions,
initialized it staticly and changed the if/else if/else cascade
into a comparison loop over this array
after refreshing my knowledge about how to declare function pointers
and pointers to function pointers this was looking very good
4) doing the right thing: after proof of concept in step 3) i converted
the static array into "HashTable fopen_url_wrappers_hash;",
added the following functions:
- int php_init_fopen_wrappers(void);
- int php_shutdown_fopen_wrappers(void);
- PHPAPI int php_register_url_wrapper(char *protocol, FILE *
(*wrapper)(...));
- PHPAPI int php_unregister_url_wrapper(char *protocol);
and called the init & shutdown functions in the appropriate places in
main.c
php_init_fopen_wrappers() will register the default handlers
for ftp:, http: and php:
extension modules may register additional handlers using the
register/unregister
pair of function
a simple dummy module will register itself for 'test:' URLs and will
treat them
like 'file:' URLs by just trying an fopen() on the supplied path
thats what is there as of now
I didn't do a checkin yet as i am not sure about the follwing issues:
- Did i really get those HashTable functions right?
- Where is the best place for the init/shutdown functions?
Currently they are in php_module_startup/shutdown
immediately before php_startup_internal_extensions() /
after php_config_ini_shutdown()?
- What should happen if two modules try to register a wrapper for
the same URL type ?
i have tried it so far with linux and solaris, cgi and apxs,
'test:'-module staticly linked in, without problems
now this is almost as long as the patch itself ... :)
--
Hartmut Holzgraefe [email protected] http://www.six.de