helly           Tue Nov  6 11:50:52 2007 UTC

  Added files:                 (Branch: PHP_5_3)
    /php-src/main/streams       glob_wrapper.c php_stream_glob_wrapper.h 

  Modified files:              
    /php-src    configure.in 
  Log:
  - MFH glob stream wrapper (part 1)
  
http://cvs.php.net/viewvc.cgi/php-src/configure.in?r1=1.579.2.52.2.77.2.5&r2=1.579.2.52.2.77.2.6&diff_format=u
Index: php-src/configure.in
diff -u php-src/configure.in:1.579.2.52.2.77.2.5 
php-src/configure.in:1.579.2.52.2.77.2.6
--- php-src/configure.in:1.579.2.52.2.77.2.5    Fri Oct  5 15:00:05 2007
+++ php-src/configure.in        Tue Nov  6 11:50:51 2007
@@ -1,4 +1,4 @@
-## $Id: configure.in,v 1.579.2.52.2.77.2.5 2007/10/05 15:00:05 jani Exp $ -*- 
autoconf -*-
+## $Id: configure.in,v 1.579.2.52.2.77.2.6 2007/11/06 11:50:51 helly Exp $ -*- 
autoconf -*-
 dnl ## Process this file with autoconf to produce a configure script.
 
 divert(1)
@@ -11,7 +11,7 @@
 dnl ## libraries and so on.
 
 dnl ## In diversion 3 we check for compile-time options to the PHP
-dnl ## core and how to deal with different system dependencies.
+dnl ## core and how to deal with different system dependencies. 
 dnl ## This includes whether debugging or short tags are enabled
 dnl ## and the default behaviour of php.ini options.
 dnl ## This is also where an SAPI interface is selected (choosing between
@@ -270,7 +270,7 @@
 divert(3)
 
 dnl ## In diversion 3 we check for compile-time options to the PHP
-dnl ## core and how to deal with different system dependencies.
+dnl ## core and how to deal with different system dependencies. 
 dnl ## This includes whether debugging or short tags are enabled
 dnl ## and the default behaviour of php.ini options.
 
@@ -1302,7 +1302,8 @@
        output.c getopt.c)
 
 PHP_ADD_SOURCES(main/streams, streams.c cast.c memory.c filter.c \
-       plain_wrapper.c userspace.c transports.c xp_socket.c mmap.c)
+       plain_wrapper.c userspace.c transports.c xp_socket.c mmap.c \
+       glob_wrapper.c)
 
 PHP_ADD_SOURCES(/main, internal_functions.c,, sapi)
 

http://cvs.php.net/viewvc.cgi/php-src/main/streams/glob_wrapper.c?view=markup&rev=1.1
Index: php-src/main/streams/glob_wrapper.c
+++ php-src/main/streams/glob_wrapper.c
/*
   +----------------------------------------------------------------------+
   | PHP Version 5                                                        |
   +----------------------------------------------------------------------+
   | Copyright (c) 1997-2007 The PHP Group                                |
   +----------------------------------------------------------------------+
   | This source file is subject to version 3.01 of the PHP license,      |
   | that is bundled with this package in the file LICENSE, and is        |
   | available through the world-wide-web at the following url:           |
   | http://www.php.net/license/3_01.txt                                  |
   | 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          |
   | [EMAIL PROTECTED] so we can mail you a copy immediately.               |
   +----------------------------------------------------------------------+
   | Authors: Marcus Boerger <[EMAIL PROTECTED]>                              |
   +----------------------------------------------------------------------+
 */

/* $Id: glob_wrapper.c,v 1.1 2007/03/03 20:41:12 helly Exp $ */

#include "php.h"
#include "php_streams_int.h"

#ifdef HAVE_GLOB
# ifndef PHP_WIN32
#  include <glob.h>
# else
#  include "win32/glob.h"
# endif
#endif

#ifndef GLOB_ONLYDIR
#define GLOB_ONLYDIR (1<<30)
#define GLOB_FLAGMASK (~GLOB_ONLYDIR)
#else
#define GLOB_FLAGMASK (~0)
#endif

typedef struct {
        glob_t   glob;
        size_t   index;
        int      flags;
        char     *path;
        size_t   path_len;
} glob_s_t;

PHPAPI char* _php_glob_stream_get_path(php_stream *stream, int copy, int *plen 
STREAMS_DC TSRMLS_DC) /* {{{ */
{
        glob_s_t *pglob = (glob_s_t *)stream->abstract;
        
        if (pglob && pglob->path) {
                if (plen) {
                        *plen = pglob->path_len;
                }
                if (copy) {
                        return estrndup(pglob->path, pglob->path_len);
                } else {
                        return pglob->path;
                }
        } else {
                if (plen) {
                        *plen = 0;
                }
                return NULL;
        }
}
/* }}} */

static void php_glob_stream_path_split(glob_s_t *pglob, char *path, int 
get_path, char **p_file TSRMLS_DC) /* {{{ */
{
        char *pos, *gpath = path;

        if ((pos = strrchr(path, '/')) != NULL) {
                path = pos+1;
        }
#if defined(PHP_WIN32) || defined(NETWARE)
        if ((pos = strrchr(path, '\\')) != NULL) {
        if (pos != NULL) {
                path = pos+1;
        }
#endif

        *p_file = path;

        if (get_path) {
                if (pglob->path) {
                        efree(pglob->path);
                }
                pglob->path_len = path - gpath;
                pglob->path = estrndup(gpath, pglob->path_len);
        }
}
/* }}} */

static size_t php_glob_stream_read(php_stream *stream, char *buf, size_t count 
TSRMLS_DC) /* {{{ */
{
        glob_s_t *pglob = (glob_s_t *)stream->abstract;
        php_stream_dirent *ent = (php_stream_dirent*)buf;
        char *path;

        /* avoid problems if someone mis-uses the stream */
        if (count == sizeof(php_stream_dirent) && pglob) {
                if (pglob->index < pglob->glob.gl_pathc) {
                        php_glob_stream_path_split(pglob, 
pglob->glob.gl_pathv[pglob->index++], pglob->flags & GLOB_APPEND, &path 
TSRMLS_CC);
                        PHP_STRLCPY(ent->d_name, path, sizeof(ent->d_name), 
strlen(path));
                        return sizeof(php_stream_dirent);
                }
                pglob->index = pglob->glob.gl_pathc;
                if (pglob->path) {
                        efree(pglob->path);
                        pglob->path = NULL;
                }
        }

        return 0;
}
/* }}} */

static int php_glob_stream_close(php_stream *stream, int close_handle 
TSRMLS_DC)  /* {{{ */
{
        glob_s_t *pglob = (glob_s_t *)stream->abstract;

        if (pglob) {
                pglob->index = 0;
                globfree(&pglob->glob);
                if (pglob->path) {
                        efree(pglob->path);
                }
        }
        efree(stream->abstract);
        return 0;
}
/* {{{ */

static int php_glob_stream_rewind(php_stream *stream, off_t offset, int whence, 
off_t *newoffs TSRMLS_DC) /* {{{ */
{
        glob_s_t *pglob = (glob_s_t *)stream->abstract;

        if (pglob) {
                pglob->index = 0;
                if (pglob->path) {
                        efree(pglob->path);
                        pglob->path = NULL;
                }
        }
        return 0;
}
/* }}} */

static php_stream_ops   php_glob_stream_ops = {
        NULL, php_glob_stream_read,
        php_glob_stream_close, NULL,
        "glob",
        php_glob_stream_rewind,
        NULL, /* cast */
        NULL, /* stat */
        NULL  /* set_option */
};

 /* {{{ php_glob_stream_opener */
static php_stream *php_glob_stream_opener(php_stream_wrapper *wrapper, char 
*path, char *mode,
                int options, char **opened_path, php_stream_context *context 
STREAMS_DC TSRMLS_DC)
{
        glob_s_t *pglob;
        int ret;
        char *tmp;

        if (((options & STREAM_DISABLE_OPEN_BASEDIR) == 0) && 
php_check_open_basedir(path TSRMLS_CC)) {
                return NULL;
        }

        if (!strncmp(path, "glob://", sizeof("glob://")-1)) {
                path += sizeof("glob://")-1;
                if (opened_path) {
                        *opened_path = estrdup(path);
                }
        }

        pglob = ecalloc(sizeof(*pglob), 1);
        
        if (0 != (ret = glob(path, pglob->flags & GLOB_FLAGMASK, NULL, 
&pglob->glob))) {
#ifdef GLOB_NOMATCH
                if (GLOB_NOMATCH != ret)
#endif
                {
                        efree(pglob);
                        return NULL;
                }
        }

#ifdef GLOB_APPEND
        if ((pglob->flags & GLOB_APPEND) == 0)
#endif
        {
                if (pglob->glob.gl_pathc) {
                        php_glob_stream_path_split(pglob, 
pglob->glob.gl_pathv[0], 1, &tmp TSRMLS_CC);
                } else {
                        php_glob_stream_path_split(pglob, path, 1, &tmp 
TSRMLS_CC);
                }
        }

        return php_stream_alloc(&php_glob_stream_ops, pglob, 0, mode);
}
/* }}} */

static php_stream_wrapper_ops php_glob_stream_wrapper_ops = {
        NULL,
        NULL,
        NULL,
        NULL,
        php_glob_stream_opener,
        "glob",
        NULL,
        NULL,
        NULL,
        NULL
};

php_stream_wrapper php_glob_stream_wrapper = {
        &php_glob_stream_wrapper_ops,
        NULL,
        0
};

/*
 * Local variables:
 * tab-width: 4
 * c-basic-offset: 4
 * End:
 * vim600: noet sw=4 ts=4 fdm=marker
 * vim<600: noet sw=4 ts=4
 */

http://cvs.php.net/viewvc.cgi/php-src/main/streams/php_stream_glob_wrapper.h?view=markup&rev=1.1
Index: php-src/main/streams/php_stream_glob_wrapper.h
+++ php-src/main/streams/php_stream_glob_wrapper.h
/*
   +----------------------------------------------------------------------+
   | PHP Version 5                                                        |
   +----------------------------------------------------------------------+
   | Copyright (c) 1997-2007 The PHP Group                                |
   +----------------------------------------------------------------------+
   | This source file is subject to version 3.01 of the PHP license,      |
   | that is bundled with this package in the file LICENSE, and is        |
   | available through the world-wide-web at the following url:           |
   | http://www.php.net/license/3_01.txt                                  |
   | 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          |
   | [EMAIL PROTECTED] so we can mail you a copy immediately.               |
   +----------------------------------------------------------------------+
   | Author: Marcus Boerger <[EMAIL PROTECTED]>                               |
   +----------------------------------------------------------------------+
 */

/* $Id: php_stream_glob_wrapper.h,v 1.1 2007/03/03 20:41:12 helly Exp $ */

PHPAPI extern php_stream_wrapper php_glob_stream_wrapper;

BEGIN_EXTERN_C()

PHPAPI char* _php_glob_stream_get_path(php_stream *stream, int copy, int *plen 
STREAMS_DC TSRMLS_DC);
#define php_glob_stream_get_path(stream, copy, plen)    
_php_glob_stream_get_path((stream), (copy), (plen) STREAMS_CC TSRMLS_CC)

END_EXTERN_C()

/*
 * Local variables:
 * tab-width: 4
 * c-basic-offset: 4
 * End:
 * vim600: sw=4 ts=4 fdm=marker
 * vim<600: sw=4 ts=4
 */

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to