1999-04-21 22:49:16 +00:00
|
|
|
|
/*
|
|
|
|
|
+----------------------------------------------------------------------+
|
1999-07-16 13:13:16 +00:00
|
|
|
|
| PHP version 4.0 |
|
1999-04-21 22:49:16 +00:00
|
|
|
|
+----------------------------------------------------------------------+
|
2000-01-01 01:32:05 +00:00
|
|
|
|
| Copyright (c) 1997, 1998, 1999, 2000 The PHP Group |
|
1999-04-21 22:49:16 +00:00
|
|
|
|
+----------------------------------------------------------------------+
|
2000-02-19 23:21:46 +00:00
|
|
|
|
| This source file is subject to version 2.01 of the PHP license, |
|
1999-07-16 13:13:16 +00:00
|
|
|
|
| that is bundled with this package in the file LICENSE, and is |
|
|
|
|
|
| available at through the world-wide-web at |
|
2000-02-19 23:21:46 +00:00
|
|
|
|
| http://www.php.net/license/2_01.txt. |
|
1999-07-16 13:13:16 +00:00
|
|
|
|
| If you did not receive a copy of the PHP license and are unable to |
|
|
|
|
|
| obtain it through the world-wide-web, please send a note to |
|
|
|
|
|
| license@php.net so we can mail you a copy immediately. |
|
1999-04-21 22:49:16 +00:00
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
|
| Authors: Stig S<EFBFBD>ther Bakken <ssb@guardian.no> |
|
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/* $Id$ */
|
|
|
|
|
|
|
|
|
|
#define IS_EXT_MODULE
|
2000-05-02 00:44:35 +00:00
|
|
|
|
#if defined(COMPILE_DL) || defined(COMPILE_DL_DAV)
|
1999-04-21 22:49:16 +00:00
|
|
|
|
# if PHP_31
|
|
|
|
|
# include "../phpdl.h"
|
|
|
|
|
# else
|
|
|
|
|
# include "dl/phpdl.h"
|
|
|
|
|
# endif
|
|
|
|
|
#endif
|
|
|
|
|
#include "php.h"
|
1999-12-04 19:19:57 +00:00
|
|
|
|
#include "php_dav.h"
|
1999-04-21 22:49:16 +00:00
|
|
|
|
|
|
|
|
|
#if defined(THREAD_SAFE) && !PHP_31
|
|
|
|
|
# undef THREAD_SAFE
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#if HAVE_MOD_DAV
|
|
|
|
|
|
|
|
|
|
# include "mod_dav.h"
|
2000-04-05 22:30:19 +00:00
|
|
|
|
#include "ext/standard/info.h"
|
1999-04-21 22:49:16 +00:00
|
|
|
|
|
|
|
|
|
/* {{{ thread safety stuff */
|
|
|
|
|
|
|
|
|
|
# ifdef THREAD_SAFE
|
|
|
|
|
# define DAV_GLOBAL(a) phpdav_globals->a
|
|
|
|
|
# define DAV_TLS_VARS phpdav_global_struct *phpdav_globals = TlsGetValue(PHPDAVTls);
|
|
|
|
|
|
|
|
|
|
void *phpdav_mutex;
|
|
|
|
|
DWORD PHPDAVTls;
|
|
|
|
|
static int numthreads=0;
|
|
|
|
|
|
|
|
|
|
typedef struct phpdav_global_struct {
|
1999-12-17 21:13:15 +00:00
|
|
|
|
phpdav_module php_dav_module;
|
1999-04-21 22:49:16 +00:00
|
|
|
|
} phpdav_global_struct;
|
|
|
|
|
|
|
|
|
|
# else /* !defined(THREAD_SAFE) */
|
|
|
|
|
# define DAV_GLOBAL(a) a
|
|
|
|
|
# define DAV_TLS_VARS
|
|
|
|
|
|
1999-12-17 21:13:15 +00:00
|
|
|
|
phpdav_module php_dav_module;
|
1999-04-21 22:49:16 +00:00
|
|
|
|
|
|
|
|
|
# endif /* defined(THREAD_SAFE) */
|
|
|
|
|
|
1999-12-17 21:13:15 +00:00
|
|
|
|
# define DAV_HANDLER(a) DAV_GLOBAL(php_dav_module).a##_handler
|
1999-04-21 22:49:16 +00:00
|
|
|
|
# define DAV_SET_HANDLER(a,b) \
|
1999-12-17 21:13:15 +00:00
|
|
|
|
dav_set_handler(&DAV_GLOBAL(php_dav_module).a##_handler,(b))
|
1999-04-21 22:49:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* }}} */
|
|
|
|
|
/* {{{ dynamically loadable module stuff */
|
|
|
|
|
|
2000-05-02 00:44:35 +00:00
|
|
|
|
#if defined(COMPILE_DL) || defined(COMPILE_DL_DAV)
|
2000-05-02 00:30:36 +00:00
|
|
|
|
ZEND_GET_MODULE(phpdav)
|
1999-04-21 22:49:16 +00:00
|
|
|
|
# endif /* COMPILE_DL */
|
|
|
|
|
|
|
|
|
|
/* }}} */
|
|
|
|
|
/* {{{ function prototypes */
|
|
|
|
|
|
1999-12-17 21:13:15 +00:00
|
|
|
|
PHP_MINIT_FUNCTION(phpdav);
|
|
|
|
|
PHP_MSHUTDOWN_FUNCTION(phpdav);
|
|
|
|
|
PHP_RSHUTDOWN_FUNCTION(phpdav);
|
|
|
|
|
PHP_MINFO_FUNCTION(phpdav);
|
1999-04-21 22:49:16 +00:00
|
|
|
|
|
|
|
|
|
/* }}} */
|
|
|
|
|
/* {{{ extension definition structures */
|
|
|
|
|
|
|
|
|
|
function_entry phpdav_functions[] = {
|
|
|
|
|
PHP_FE(dav_set_mkcol_handlers, NULL)
|
|
|
|
|
{NULL, NULL, NULL}
|
|
|
|
|
};
|
|
|
|
|
|
1999-12-17 20:55:31 +00:00
|
|
|
|
zend_module_entry phpdav_module_entry = {
|
2000-03-06 18:44:01 +00:00
|
|
|
|
"dav", /* extension name */
|
1999-04-21 22:49:16 +00:00
|
|
|
|
phpdav_functions, /* extension function list */
|
1999-12-17 21:13:15 +00:00
|
|
|
|
PHP_MINIT(phpdav), /* extension-wide startup function */
|
|
|
|
|
PHP_MSHUTDOWN(phpdav), /* extension-wide shutdown function */
|
|
|
|
|
NULL, /* per-request startup function */
|
|
|
|
|
PHP_RSHUTDOWN(phpdav), /* per-request shutdown function */
|
|
|
|
|
PHP_MINFO(phpdav), /* information function */
|
1999-04-21 22:49:16 +00:00
|
|
|
|
STANDARD_MODULE_PROPERTIES
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* }}} */
|
|
|
|
|
/* {{{ startup, shutdown and info functions */
|
|
|
|
|
|
1999-12-17 21:13:15 +00:00
|
|
|
|
PHP_MINIT_FUNCTION(phpdav)
|
1999-04-21 22:49:16 +00:00
|
|
|
|
{
|
|
|
|
|
#if defined(THREAD_SAFE)
|
|
|
|
|
phpdav_global_struct *phpdav_globals;
|
2000-02-26 03:20:55 +00:00
|
|
|
|
PHP_MUTEX_ALLOC(phpdav_mutex);
|
|
|
|
|
PHP_MUTEX_LOCK(phpdav_mutex);
|
1999-04-21 22:49:16 +00:00
|
|
|
|
numthreads++;
|
|
|
|
|
if (numthreads==1){
|
|
|
|
|
if (!PHP3_TLS_PROC_STARTUP(PHPDAVTls)){
|
2000-02-26 03:20:55 +00:00
|
|
|
|
PHP_MUTEX_UNLOCK(phpdav_mutex);
|
|
|
|
|
PHP_MUTEX_FREE(phpdav_mutex);
|
1999-04-21 22:49:16 +00:00
|
|
|
|
return FAILURE;
|
|
|
|
|
}
|
|
|
|
|
}
|
2000-02-26 03:20:55 +00:00
|
|
|
|
PHP_MUTEX_UNLOCK(phdpav_mutex);
|
1999-04-21 22:49:16 +00:00
|
|
|
|
if(!PHP3_TLS_THREAD_INIT(PHPDAVTls,phpdav_globals,phpdav_global_struct)){
|
2000-02-26 03:20:55 +00:00
|
|
|
|
PHP_MUTEX_FREE(phpdav_mutex);
|
1999-04-21 22:49:16 +00:00
|
|
|
|
return FAILURE;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
return SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1999-12-17 21:13:15 +00:00
|
|
|
|
PHP_MSHUTDOWN_FUNCTION(phpdav)
|
1999-04-21 22:49:16 +00:00
|
|
|
|
{
|
|
|
|
|
DAV_TLS_VARS;
|
|
|
|
|
#ifdef THREAD_SAFE
|
|
|
|
|
PHP3_TLS_THREAD_FREE(phpdav_globals);
|
2000-02-26 03:20:55 +00:00
|
|
|
|
PHP_MUTEX_LOCK(phpdav_mutex);
|
1999-04-21 22:49:16 +00:00
|
|
|
|
numthreads--;
|
|
|
|
|
if (numthreads < 1) {
|
|
|
|
|
PHP3_TLS_PROC_SHUTDOWN(PHPDAVTls);
|
2000-02-26 03:20:55 +00:00
|
|
|
|
PHP_MUTEX_UNLOCK(phpdav_mutex);
|
|
|
|
|
PHP_MUTEX_FREE(phpdav_mutex);
|
1999-04-21 22:49:16 +00:00
|
|
|
|
return SUCCESS;
|
|
|
|
|
}
|
2000-02-26 03:20:55 +00:00
|
|
|
|
PHP_MUTEX_UNLOCK(phpdav_mutex);
|
1999-04-21 22:49:16 +00:00
|
|
|
|
#endif
|
|
|
|
|
return SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1999-12-17 21:13:15 +00:00
|
|
|
|
PHP_RSHUTDOWN_FUNCTION(phpdav)
|
1999-04-21 22:49:16 +00:00
|
|
|
|
{
|
|
|
|
|
if (DAV_HANDLER(mkcol_test)) {
|
|
|
|
|
efree(DAV_HANDLER(mkcol_test));
|
|
|
|
|
}
|
|
|
|
|
if (DAV_HANDLER(mkcol_create)) {
|
|
|
|
|
efree(DAV_HANDLER(mkcol_create));
|
|
|
|
|
}
|
|
|
|
|
return SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1999-12-17 21:13:15 +00:00
|
|
|
|
PHP_MINFO_FUNCTION(phpdav);
|
1999-04-21 22:49:16 +00:00
|
|
|
|
{
|
2000-04-05 22:30:19 +00:00
|
|
|
|
php_info_print_table_start();
|
|
|
|
|
php_info_print_table_row(2, "DAV Support", "enabled");
|
|
|
|
|
php_info_print_table_end();
|
1999-04-21 22:49:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* {{{ extension-internal functions */
|
|
|
|
|
|
|
|
|
|
/* {{{ dav_set_handler() */
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
dav_set_handler(char **nameBufp, pval *data)
|
|
|
|
|
{
|
|
|
|
|
if (data->value.str.len > 0) {
|
|
|
|
|
if (*nameBufp != NULL) {
|
|
|
|
|
efree(*nameBufp);
|
|
|
|
|
}
|
|
|
|
|
*nameBufp = php3i_pval_strdup(data);
|
|
|
|
|
} else {
|
|
|
|
|
if (*nameBufp != NULL) {
|
|
|
|
|
efree(*nameBufp);
|
|
|
|
|
}
|
|
|
|
|
*nameBufp = NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* }}} */
|
|
|
|
|
/* {{{ dav_call_handler() */
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
dav_call_handler(char *funcName, int argc, pval **argv)
|
|
|
|
|
{
|
|
|
|
|
if (funcName) {
|
|
|
|
|
pval *retval, *func;
|
|
|
|
|
int i, ret;
|
|
|
|
|
HashTable *function_table;
|
|
|
|
|
|
|
|
|
|
func = php3i_string_pval(funcName);
|
1999-12-26 21:21:33 +00:00
|
|
|
|
ALLOC_ZVAL(retval);
|
1999-04-21 22:49:16 +00:00
|
|
|
|
function_table = php3i_get_function_table();
|
|
|
|
|
if (call_user_function(function_table, NULL, func, retval, argc, argv) == FAILURE) {
|
|
|
|
|
php3tls_pval_destructor(retval);
|
|
|
|
|
efree(retval);
|
|
|
|
|
return HTTP_INTERNAL_SERVER_ERROR;
|
|
|
|
|
}
|
|
|
|
|
php3tls_pval_destructor(func);
|
|
|
|
|
efree(func);
|
|
|
|
|
for (i = 0; i < argc; i++) {
|
|
|
|
|
php3tls_pval_destructor(argv[i]);
|
|
|
|
|
efree(argv[i]);
|
|
|
|
|
}
|
|
|
|
|
convert_to_long(retval);
|
|
|
|
|
ret = retval->value.lval;
|
|
|
|
|
efree(retval);
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
return DECLINED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
|
int phpdav_mkcol_test_handler(request_rec *r)
|
|
|
|
|
{
|
|
|
|
|
pval *arg;
|
|
|
|
|
|
|
|
|
|
if (DAV_HANDLER(mkcol_test) == NULL) {
|
|
|
|
|
return DECLINED;
|
|
|
|
|
}
|
|
|
|
|
arg = php3i_string_pval(r->filename);
|
|
|
|
|
return dav_call_handler(DAV_HANDLER(mkcol_test), 1, &arg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int phpdav_mkcol_create_handler(request_rec *r)
|
|
|
|
|
{
|
|
|
|
|
pval *arg;
|
|
|
|
|
|
|
|
|
|
if (DAV_HANDLER(mkcol_create) == NULL) {
|
|
|
|
|
return DECLINED;
|
|
|
|
|
}
|
|
|
|
|
arg = php3i_string_pval(r->filename);
|
|
|
|
|
return dav_call_handler(DAV_HANDLER(mkcol_create), 1, &arg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
|
/************************* EXTENSION FUNCTIONS *************************/
|
|
|
|
|
|
2000-02-22 15:48:43 +00:00
|
|
|
|
/* {{{ proto void dav_set_mkcol_handlers(string test, string create)
|
1999-04-21 22:49:16 +00:00
|
|
|
|
Sets the function to test whether a DAV collection exists for MKCOL */
|
|
|
|
|
PHP_FUNCTION(dav_set_mkcol_handlers)
|
|
|
|
|
{
|
|
|
|
|
pval *test, *create;
|
|
|
|
|
DAV_TLS_VARS;
|
|
|
|
|
|
|
|
|
|
if (ARG_COUNT(ht) != 2 || getParameters(ht, 2, &test, &create) == FAILURE) {
|
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
|
}
|
|
|
|
|
DAV_SET_HANDLER(mkcol_test, test);
|
|
|
|
|
DAV_SET_HANDLER(mkcol_create, create);
|
|
|
|
|
RETVAL_TRUE;
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Local variables:
|
|
|
|
|
* tab-width: 4
|
|
|
|
|
* c-basic-offset: 4
|
|
|
|
|
* End:
|
|
|
|
|
*/
|