Commit eb8452a6 authored by Ondrej Sury's avatar Ondrej Sury

Imported Upstream version 1.4.0~b1

parent 2675c022
This diff is collapsed.
RADIUS
Michael Bretterklieber, The FreeBSD Project http://www.freebsd.org
\ No newline at end of file
Michael Bretterklieber, The FreeBSD Project http://www.freebsd.org
RFC3576 support
Gabriel Blanchard <gabe@teksavvy.com>
Copyright (c) 2003, Michael Bretterklieber <michael@bretterklieber.com>
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The names of the authors may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// $Id$
// vim:ft=javascript
ARG_WITH("radius", "Radius Support", "no");
if (PHP_RADIUS == "yes") {
EXTENSION("radius", "radius.c radlib.c radlib_compat.c");
AC_DEFINE('HAVE_RADIUS', 1, 'Have Radius support', false);
}
/*
+----------------------------------------------------------------------+
| Compatibility macros for different PHP versions |
+----------------------------------------------------------------------+
| Copyright (c) 2015 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 |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Francois Laupretre <francois@tekwire.net> |
+----------------------------------------------------------------------+
*/
#ifndef _COMPAT_H
#define _COMPAT_H
#define PECL_COMPAT_VERSION 1.2
#include <stdio.h>
#include <assert.h>
#include <fcntl.h>
#include "php.h"
#include "zend.h"
#include "zend_extensions.h"
#include "zend_API.h"
#define PHP_5_0_X_API_NO 220040412
#define PHP_5_1_X_API_NO 220051025
#define PHP_5_2_X_API_NO 220060519
#define PHP_5_3_X_API_NO 220090626
#define PHP_5_4_X_API_NO 220100525
#define PHP_5_5_X_API_NO 220121212
#define PHP_5_6_X_API_NO 220131226
#if PHP_MAJOR_VERSION >= 7
# define PHP_7
#endif
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#if HAVE_STRING_H
# include <string.h>
#endif
#ifdef HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif
#ifdef PHP_WIN32
# include "win32/time.h"
#elif defined(NETWARE)
# include <sys/timeval.h>
# include <sys/time.h>
#else
# include <sys/time.h>
#endif
#ifdef HAVE_SYS_RESOURCE_H
# include <sys/resource.h>
#endif
#ifdef HAVE_STDARG_H
#include <stdarg.h>
#endif
#ifdef HAVE_STDLIB_H
# include <stdlib.h>
#endif
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#ifdef HAVE_SYS_STAT_H
# include <sys/stat.h>
#endif
#ifdef PHP_WIN32
#include <win32/php_stdint.h>
#else
#include <inttypes.h>
#endif
#if ZEND_EXTENSION_API_NO >= PHP_5_6_X_API_NO
#include "zend_virtual_cwd.h"
#else
#include "TSRM/tsrm_virtual_cwd.h"
#endif
#ifdef PHP_7
#include "Zend/zend_portability.h"
#endif
/*-- Include submodules */
#include "src/misc.h"
#include "src/zend_string.h"
#include "src/zend_hash.h"
#include "src/zend_API.h"
#include "src/zend_resource.h"
#endif /* _COMPAT_H */
/*
+----------------------------------------------------------------------+
| Compatibility between PHP versions |
+----------------------------------------------------------------------+
| Copyright (c) 2015 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 |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Francois Laupretre <francois@tekwire.net> |
+----------------------------------------------------------------------+
*/
#ifndef __PECL_COMPAT_MISC_H
#define __PECL_COMPAT_MISC_H 1
#ifdef PHP_7
/*============================================================================*/
typedef zend_string * OPENED_PATH_PTR; /* Type of stream opened_path argument */
typedef size_t COMPAT_ARG_SIZE_T; /* Size of string arguments */
typedef zend_long COMPAT_ARG_LONG_T; /* Type of long (integer) arguments */
#define compat_zval_ptr_dtor(zp) zval_ptr_dtor(zp)
#else
/*== PHP 5 ===================================================================*/
typedef char * OPENED_PATH_PTR;
typedef off_t zend_off_t;
typedef int COMPAT_ARG_SIZE_T;
typedef long COMPAT_ARG_LONG_T;
typedef long zend_long;
#define compat_zval_ptr_dtor(zp) zval_dtor(zp)
#endif
/*============================================================================*/
#ifndef MIN
# define MIN(a,b) (((a) < (b)) ? (a) : (b))
#endif
#ifndef MAX
# define MAX(a,b) (((a) > (b)) ? (a) : (b))
#endif
/*---------------------------------------------------------------*/
/* (Taken from pcre/pcrelib/internal.h) */
/* To cope with SunOS4 and other systems that lack memmove() but have bcopy(),
define a macro for memmove() if HAVE_MEMMOVE is false, provided that HAVE_BCOPY
is set. Otherwise, include an emulating function for those systems that have
neither (there are some non-Unix environments where this is the case). This
assumes that all calls to memmove are moving strings upwards in store,
which is the case in this extension. */
#if ! HAVE_MEMMOVE
# ifdef memmove
# undef memmove /* some systems may have a macro */
# endif
# if HAVE_BCOPY
# define memmove(a, b, c) bcopy(b, a, c)
# else
static void *my_memmove(unsigned char *dest, const unsigned char *src,
size_t n)
{
int i;
dest += n;
src += n;
for (i = 0; i < n; ++i)
*(--dest) = *(--src);
}
# define memmove(a, b, c) my_memmove(a, b, c)
# endif /* not HAVE_BCOPY */
#endif /* not HAVE_MEMMOVE */
#ifdef _AIX
# undef PHP_SHLIB_SUFFIX
# define PHP_SHLIB_SUFFIX "a"
#endif
#ifndef ZVAL_IS_ARRAY
#define ZVAL_IS_ARRAY(zp) (Z_TYPE_P((zp))==IS_ARRAY)
#endif
#ifndef ZVAL_IS_STRING
#define ZVAL_IS_STRING(zp) (Z_TYPE_P((zp))==IS_STRING)
#endif
#ifndef ZVAL_IS_LONG
#define ZVAL_IS_LONG(zp) (Z_TYPE_P((zp))==IS_LONG)
#endif
#ifndef ZVAL_IS_BOOL
#define ZVAL_IS_BOOL(zp) (Z_TYPE_P((zp))==IS_BOOL)
#endif
#ifndef INIT_ZVAL
#define INIT_ZVAL(z) memset(&z, 0, sizeof(z))
#endif
#ifndef ZVAL_UNDEF
#define ZVAL_UNDEF(z) INIT_ZVAL(*(z))
#endif
#ifndef MAKE_STD_ZVAL
#define MAKE_STD_ZVAL(zp) { zp = emalloc(sizeof(zval)); INIT_ZVAL(*zp); }
#endif
#ifndef ALLOC_INIT_ZVAL
#define ALLOC_INIT_ZVAL(zp) MAKE_STD_ZVAL(zp)
#endif
#ifndef ZEND_ASSUME
#if defined(ZEND_WIN32) && !defined(__clang__)
# define ZEND_ASSUME(c) __assume(c)
#else
# define ZEND_ASSUME(c)
#endif
#endif
#ifndef ZEND_ASSERT
#if ZEND_DEBUG
# define ZEND_ASSERT(c) assert(c)
#else
# define ZEND_ASSERT(c) ZEND_ASSUME(c)
#endif
#endif
#ifndef EMPTY_SWITCH_DEFAULT_CASE
/* Only use this macro if you know for sure that all of the switches values
are covered by its case statements */
#if ZEND_DEBUG
# define EMPTY_SWITCH_DEFAULT_CASE() default: ZEND_ASSERT(0); break;
#else
# define EMPTY_SWITCH_DEFAULT_CASE() default: ZEND_ASSUME(0); break;
#endif
#endif
#ifndef ZEND_IGNORE_VALUE
#if defined(__GNUC__) && __GNUC__ >= 4
# define ZEND_IGNORE_VALUE(x) (({ __typeof__ (x) __x = (x); (void) __x; }))
#else
# define ZEND_IGNORE_VALUE(x) ((void) (x))
#endif
#endif
#if PHP_API_VERSION >= 20100412
typedef size_t PHP_ESCAPE_HTML_ENTITIES_SIZE;
#else
typedef int PHP_ESCAPE_HTML_ENTITIES_SIZE;
#endif
/* Avoid a warning when compiling stream wrapper declarations for
openfile/opendir/url_stat */
#if ZEND_EXTENSION_API_NO >= PHP_5_6_X_API_NO
# define COMPAT_STREAM_CONST_DECL const
#else
# define COMPAT_STREAM_CONST_DECL
#endif
#ifndef ZEND_MODULE_GLOBALS_ACCESSOR
# ifdef ZTS
# define ZEND_MODULE_GLOBALS_ACCESSOR(module_name, v) \
TSRMG(module_name##_globals_id, zend_##module_name##_globals *, v)
# else
# define ZEND_MODULE_GLOBALS_ACCESSOR(module_name, v) \
(module_name##_globals.v)
# endif
#endif
#ifndef ZEND_MODULE_GLOBALS_BULK
# ifdef ZTS
# define ZEND_MODULE_GLOBALS_BULK(module_name) \
((zend_##module_name##_globals *) \
(*((void ***) tsrm_ls))[module_name##_globals_id - 1])
# else
# define ZEND_MODULE_GLOBALS_BULK(module_name) \
(&module_name##_globals)
# endif
#endif
#ifndef ZEND_TSRMLS_CACHE_DEFINE
# define ZEND_TSRMLS_CACHE_DEFINE()
#endif
#ifndef ZEND_TSRMLS_CACHE_UPDATE
# define ZEND_TSRMLS_CACHE_UPDATE()
#endif
#ifndef PHP_FE_END
# define PHP_FE_END { NULL, NULL, NULL }
#endif
#ifndef ZEND_MOD_END
/* for php < 5.3.7 */
# define ZEND_MOD_END {NULL, NULL, NULL}
#endif
/*============================================================================*/
/* Duplicate a memory buffer */
/* Supports zero size (allocates 1 byte) */
static zend_always_inline void *_compat_dup(const void *ptr, size_t size, int persistent)
{
char *p;
if (!ptr) return NULL;
if (size) {
p = pemalloc(size, persistent);
memmove(p, ptr, size);
} else {
p = pemalloc(1,persistent);
(*p) = '\0'; /* Ensures deterministic behavior */
}
return p;
}
/*---------------------------------------------------------------*/
/* Duplicate a string and set terminating null.
Input string does not have to be null-terminated */
static zend_always_inline void *_compat_dup_str(const void *ptr, size_t size, int persistent)
{
char *p;
if (!ptr) return NULL;
p = pemalloc(size + 1, persistent);
if (size) memmove(p, ptr, size);
p[size] = '\0';
return p;
}
/*-----------------------------------------------------*/
/* Fatal error - display message and abort process */
static zend_always_inline void compat_unsupported(char *msg)
{
php_error(E_CORE_ERROR, "This feature is not supported in this environment : %s", msg);
exit(1);
}
/*============================================================================*/
#endif /* __PECL_COMPAT_MISC_H */
/*
+----------------------------------------------------------------------+
| Compatibility macros for different PHP versions |
+----------------------------------------------------------------------+
| Copyright (c) 2016 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 |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Adam Harvey <aharvey@php.net> |
+----------------------------------------------------------------------+
*/
#ifndef _COMPAT_ZEND_API_H
#define _COMPAT_ZEND_API_H
#ifdef PHP_7
/*============================================================================*/
#else
/*== PHP 5 ===================================================================*/
/*
* Many string-related macros used to take duplicate parameters, which
* specified whether the string should be duplicated or not. In practice,
* almost all code used 1, so PHP 7 always duplicates.
*
* This header redefines the relevant macros to match PHP 7.
*/
#undef ZVAL_STRING
#define ZVAL_STRING(z, s) do { \
const char *__s = (s); \
zval *__z = (z); \
Z_STRLEN_P(__z) = strlen(__s); \
Z_STRVAL_P(__z) = estrndup(__s, Z_STRLEN_P(__z)); \
Z_TYPE_P(__z) = IS_STRING; \
} while (0)
#undef ZVAL_STRINGL
#define ZVAL_STRINGL(z, s, l) do { \
const char *__s = (s); \
int __l = (l); \
zval *__z = (z); \
Z_STRLEN_P(__z) = __l; \
Z_STRVAL_P(__z) = estrndup(__s, __l); \
Z_TYPE_P(__z) = IS_STRING; \
} while (0)
#undef RETVAL_STRING
#define RETVAL_STRING(s) ZVAL_STRING(return_value, (s))
#undef RETVAL_STRINGL
#define RETVAL_STRINGL(s, l) ZVAL_STRINGL(return_value, (s), (l))
#undef RETURN_STRING
#define RETURN_STRING(s) { RETVAL_STRING(s); return; }
#undef RETURN_STRINGL
#define RETURN_STRINGL(s, l) { RETVAL_STRINGL(s, l); return; }
#undef add_assoc_string
#define add_assoc_string(__arg, __key, __str) add_assoc_string_ex(__arg, __key, strlen(__key)+1, __str, 1)
#undef add_assoc_stringl
#define add_assoc_stringl(__arg, __key, __str, __len) add_assoc_stringl_ex(__arg, __key, strlen(__key)+1, __str, __len, 1)
#endif /* PHP_7 */
/*============================================================================*/
#endif /* _COMPAT_ZEND_API_H */
This diff is collapsed.
/*
+----------------------------------------------------------------------+
| Compatibility macros for different PHP versions |
+----------------------------------------------------------------------+
| Copyright (c) 2016 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 |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Adam Harvey <aharvey@php.net> |
+----------------------------------------------------------------------+
*/
#ifndef _COMPAT_ZEND_RESOURCE_H
#define _COMPAT_ZEND_RESOURCE_H
/*
* The PHP 5 and PHP 7 resource APIs use the same function names for mutually
* incompatible functions, which is unfortunate. A simple version of the PHP 5
* macro API can be implemented on top of the PHP 7 API, but not vice versa
* (since, for example, zend_register_resource() in PHP 5 also sets the zval,
* which is a separate action in PHP 7).
*
* Instead of using preprocessor trickery to try to mangle things into a sane
* API, I've implemented a minimal API that supports basic resource handling
* and delegates appropriately on both versions.
*
* Destructors should be registered using the normal
* zend_register_list_destructors() or zend_register_list_destructors_ex()
* functions. The destructor function should take a "zend_resource *" (there is
* an appropriate typedef in the PHP 5 section to make this work); as only a
* subset of fields are available across PHP versions, this should be treated
* as this struct in effect:
*
* typedef struct {
* void *ptr;
* int type;
* } zend_resource;
*
* Accessing other fields will likely result in compilation errors and/or
* segfaults.
*/
/**
* Deletes the resource.
*
* On PHP 5, this is equivalent to zend_list_delete(Z_LVAL_P(zv)).
* On PHP 7, this is equivalent to zend_list_close(Z_RES_P(zv)).
*
* @param zv The IS_RESOURCE zval to delete.
*/
static void compat_zend_delete_resource(const zval *zv TSRMLS_DC);
/**
* Fetches the resource.
*
* This API does not support the default ID that's possible with the PHP 5
* zend_fetch_resource() API, and will always set that value to -1.
*
* @param zv The IS_RESOURCE zval to fetch.
* @param rsrc_type_name The type name to use in error messages.
* @param rsrc_type The resource type ID.
* @return A void pointer to the resource, which needs to be typecast, or NULL
* on error.
*/
static void *compat_zend_fetch_resource(zval *zv, const char *rsrc_type_name, int rsrc_type TSRMLS_DC);
/**
* Registers a new resource.
*
* @param zv The zval to set to IS_RESOURCE with the new resource value.
* @param ptr A void pointer to the resource.
* @param rsrc_type The resource type ID.
*/
static void compat_zend_register_resource(zval *zv, void *ptr, int rsrc_type TSRMLS_DC);
#ifdef PHP_7
/*============================================================================*/
static void compat_zend_delete_resource(const zval *zv TSRMLS_DC)
{
if (IS_RESOURCE != Z_TYPE_P(zv)) {
return;
}
zend_list_close(Z_RES_P(zv));
}
static void *compat_zend_fetch_resource(zval *zv, const char *rsrc_type_name, int rsrc_type TSRMLS_DC)
{
if (IS_RESOURCE != Z_TYPE_P(zv)) {
return NULL;
}
return zend_fetch_resource(Z_RES_P(zv), rsrc_type_name, rsrc_type);
}
static void compat_zend_register_resource(zval *zv, void *ptr, int rsrc_type TSRMLS_DC)
{
ZVAL_RES(zv, zend_register_resource(ptr, rsrc_type));
}
#else
/*== PHP 5 ===================================================================*/
/* Used for destructors. */
typedef zend_rsrc_list_entry zend_resource;
static void compat_zend_delete_resource(const zval *zv TSRMLS_DC)
{
if (IS_RESOURCE != Z_TYPE_P(zv)) {
return;
}
zend_list_delete(Z_LVAL_P(zv));
}
static void *compat_zend_fetch_resource(zval *zv, const char *rsrc_type_name, int rsrc_type TSRMLS_DC)
{
#if ZEND_MODULE_API_NO >= 20100412
return zend_fetch_resource(&zv TSRMLS_CC, -1, rsrc_type_name, NULL, 1, rsrc_type);
#else
return zend_fetch_resource(&zv TSRMLS_CC, -1, (char *)rsrc_type_name, NULL, 1, rsrc_type);
#endif
}
static void compat_zend_register_resource(zval *zv, void *ptr, int rsrc_type TSRMLS_DC)
{
ZEND_REGISTER_RESOURCE(zv, ptr, rsrc_type);
}
#endif /* PHP_7 */
/*============================================================================*/
#endif /* _COMPAT_ZEND_RESOURCE_H */
/*
+----------------------------------------------------------------------+
| zend_string compatibility layer for PHP 5 & 7 |
+----------------------------------------------------------------------+
| Copyright (c) 2005-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 |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Francois Laupretre <francois@tekwire.net> |
+----------------------------------------------------------------------+
*/
#ifndef _COMPAT_ZEND_STRING_H
#define _COMPAT_ZEND_STRING_H
#ifdef PHP_7
/*============================================================================*/
#include "zend_string.h"
#ifndef ZSTR_IS_PERSISTENT
# define ZSTR_IS_PERSISTENT(s) (GC_FLAGS(s) & IS_STR_PERSISTENT)
#endif
#else
/*============================================================================*/
/*---- zend_string for PHP 5 ----*/
struct _zend_string {
int persistent;
int hash_is_set; /* needed because computed hash may be null */
zend_ulong h; /* hash value */
uint32_t refcount;
size_t len;
char val[1];
};
typedef struct _zend_string zend_string;
/* Shortcuts */
#define ZSTR_VAL(zstr) (zstr)->val
#define ZSTR_LEN(zstr) (zstr)->len
#define ZSTR_H(zstr) (zstr)->h
#define ZSTR_HASH(zstr) zend_string_hash_val(zstr)
#define _ZSTR_HEADER_SIZE XtOffsetOf(zend_string, val)
#define _ZSTR_STRUCT_SIZE(len) (_ZSTR_HEADER_SIZE + len + 1)
#define ZSTR_IS_PERSISTENT(s) (s->persistent)
/*---------*/
static zend_always_inline uint32_t zend_string_refcount(zend_string *s)
{
return (s->refcount);
}
/*---------*/
static zend_always_inline uint32_t zend_string_addref(zend_string *s)
{
return ++(s->refcount);
}
/*---------*/
static zend_always_inline uint32_t zend_string_delref(zend_string *s)
{
return --(s->refcount);
}
/*---------*/
static zend_always_inline zend_ulong zend_string_hash_val(zend_string *s)
{
char c, *p;