Remove compatibility with PHP 7.1 and older

It means minimal PHP version is 7.2
This commit is contained in:
Jakub Zelenka 2025-12-06 17:17:49 +01:00
parent 4b9160b94d
commit eff707d7da
No known key found for this signature in database
GPG key ID: 1C0779DC5C0A9DE4
9 changed files with 517 additions and 550 deletions

View file

@ -2,6 +2,9 @@
List of all features for the release List of all features for the release
## 1.6.0
- Removed compatibility with PHP 7.1 and older.
## 1.5.4 ## 1.5.4
- Fixed GH-57: PHP 8.5 build failure due to usage of removed zend_exception_get_default() - Fixed GH-57: PHP 8.5 build failure due to usage of removed zend_exception_get_default()
- Fixed GH-59: Failure to build with gpgme >= 2.0.0 due to romoved trustlist - Fixed GH-59: Failure to build with gpgme >= 2.0.0 due to romoved trustlist

View file

@ -23,12 +23,11 @@ $ sudo pecl install gnupg
#### Manual Installation #### Manual Installation
It's important to have a git installed as it's necessary for recursive fetch of It's important to have a git installed
[phpc](https://github.com/bukka/phpc).
First clone recursively the repository First clone the repository
``` ```
git clone --recursive https://github.com/php-gnupg/php-gnupg.git git clone https://github.com/php-gnupg/php-gnupg.git
``` ```
Then go to the created directory and compile the extension. The PHP development package has to be Then go to the created directory and compile the extension. The PHP development package has to be

View file

@ -2,6 +2,9 @@
This document lists backward incompatible change in the extension This document lists backward incompatible change in the extension
## 1.6.0
- minimal PHP version bumped to 7.2
## 1.5.0 ## 1.5.0
- no backward incompatible changes - no backward incompatible changes

822
gnupg.c

File diff suppressed because it is too large Load diff

View file

@ -25,65 +25,72 @@
#include "zend_exceptions.h" #include "zend_exceptions.h"
#include "php_gnupg.h" #include "php_gnupg.h"
#include "php_gnupg_keylistiterator.h" #include "php_gnupg_keylistiterator.h"
#include "phpc/phpc.h" #include "php_gnupg_compat.h"
static int le_gnupg_keylistiterator; static int le_gnupg_keylistiterator;
static zend_class_entry *gnupg_keylistiterator_class_entry; static zend_class_entry *gnupg_keylistiterator_class_entry;
static zend_object_handlers gnupg_keylistiterator_handlers;
PHPC_OBJ_DEFINE_HANDLER_VAR(gnupg_keylistiterator); /* Helper macro to get object from zend_object */
static inline gnupg_keylistiterator_object *gnupg_keylistiterator_from_obj(zend_object *obj)
{
return (gnupg_keylistiterator_object *)((char *)(obj) - XtOffsetOf(gnupg_keylistiterator_object, std));
}
#define Z_GNUPG_KEYLISTITERATOR_P(zv) gnupg_keylistiterator_from_obj(Z_OBJ_P(zv))
/* {{{ GNUPG_GET_ITERATOR */ /* {{{ GNUPG_GET_ITERATOR */
#define GNUPG_GET_ITERATOR() \ #define GNUPG_GET_ITERATOR() \
zval *this = getThis(); \ zval *this = getThis(); \
PHPC_THIS_DECLARE(gnupg_keylistiterator) = NULL; \ gnupg_keylistiterator_object *intern = NULL; \
do { \ do { \
if (this) { \ if (this) { \
PHPC_THIS_FETCH_FROM_ZVAL(gnupg_keylistiterator, this); \ intern = Z_GNUPG_KEYLISTITERATOR_P(this); \
if (!PHPC_THIS) { \ if (!intern) { \
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid or unitialized gnupg object"); \ php_error_docref(NULL, E_WARNING, "Invalid or unitialized gnupg_keylistiterator object"); \
RETURN_FALSE; \ RETURN_FALSE; \
} \ } \
} \ } \
} while (0) } while (0)
/* }}} */ /* }}} */
/* {{{ free gnupg_keylistiterator */ /* {{{ gnupg_keylistiterator_object_free */
PHPC_OBJ_HANDLER_FREE(gnupg_keylistiterator) static void gnupg_keylistiterator_object_free(zend_object *object)
{ {
PHPC_OBJ_HANDLER_FREE_INIT(gnupg_keylistiterator); gnupg_keylistiterator_object *intern = gnupg_keylistiterator_from_obj(object);
gpgme_op_keylist_end(PHPC_THIS->ctx); gpgme_op_keylist_end(intern->ctx);
gpgme_key_release(PHPC_THIS->gpgkey); gpgme_key_release(intern->gpgkey);
gpgme_release(PHPC_THIS->ctx); gpgme_release(intern->ctx);
if (PHPC_THIS->pattern) { if (intern->pattern) {
efree(PHPC_THIS->pattern); efree(intern->pattern);
} }
PHPC_OBJ_HANDLER_FREE_DESTROY(); zend_object_std_dtor(&intern->std);
} }
/* }}} */
/* {{{ create_ex gnupg_keylistiterator */ /* {{{ gnupg_keylistiterator_object_create */
PHPC_OBJ_HANDLER_CREATE_EX(gnupg_keylistiterator) static zend_object *gnupg_keylistiterator_object_create(zend_class_entry *ce)
{ {
PHPC_OBJ_HANDLER_CREATE_EX_INIT(gnupg_keylistiterator); gnupg_keylistiterator_object *intern;
intern = ecalloc(1, sizeof(gnupg_keylistiterator_object) + zend_object_properties_size(ce));
gpgme_check_version(NULL); gpgme_check_version(NULL);
gpgme_new(&intern->ctx);
intern->err = 0;
intern->gpgkey = NULL;
intern->pattern = NULL;
gpgme_new(&PHPC_THIS->ctx); zend_object_std_init(&intern->std, ce);
PHPC_THIS->err = 0; object_properties_init(&intern->std, ce);
PHPC_THIS->gpgkey = NULL; intern->std.handlers = &gnupg_keylistiterator_handlers;
PHPC_THIS->pattern = NULL;
PHPC_OBJ_HANDLER_CREATE_EX_RETURN(gnupg_keylistiterator); return &intern->std;
} }
/* }}} */
/* {{{ create gnupg_keylistiterator */
PHPC_OBJ_HANDLER_CREATE(gnupg_keylistiterator)
{
PHPC_OBJ_HANDLER_CREATE_RETURN(gnupg_keylistiterator);
}
/* {{{ arginfo for gnupg void iterator method */ /* {{{ arginfo for gnupg void iterator method */
ZEND_BEGIN_ARG_INFO_EX(arginfo_gnupg_void_iterator_method, 0, 0, 0) ZEND_BEGIN_ARG_INFO_EX(arginfo_gnupg_void_iterator_method, 0, 0, 0)
@ -103,34 +110,34 @@ ZEND_END_ARG_INFO()
#define arginfo_gnupg_rewind arginfo_gnupg_next #define arginfo_gnupg_rewind arginfo_gnupg_next
/* {{{ method list gnupg_keylistiterator */ /* {{{ method list gnupg_keylistiterator */
static zend_function_entry gnupg_keylistiterator_methods[] = { static const zend_function_entry gnupg_keylistiterator_methods[] = {
PHP_ME(gnupg_keylistiterator, __construct, arginfo_gnupg_void_iterator_method, ZEND_ACC_PUBLIC) PHP_ME(gnupg_keylistiterator, __construct, arginfo_gnupg_void_iterator_method, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
PHP_ME(gnupg_keylistiterator, current, arginfo_gnupg_current, ZEND_ACC_PUBLIC) PHP_ME(gnupg_keylistiterator, current, arginfo_gnupg_current, ZEND_ACC_PUBLIC)
PHP_ME(gnupg_keylistiterator, key, arginfo_gnupg_key, ZEND_ACC_PUBLIC) PHP_ME(gnupg_keylistiterator, key, arginfo_gnupg_key, ZEND_ACC_PUBLIC)
PHP_ME(gnupg_keylistiterator, next, arginfo_gnupg_next, ZEND_ACC_PUBLIC) PHP_ME(gnupg_keylistiterator, next, arginfo_gnupg_next, ZEND_ACC_PUBLIC)
PHP_ME(gnupg_keylistiterator, rewind, arginfo_gnupg_rewind, ZEND_ACC_PUBLIC) PHP_ME(gnupg_keylistiterator, rewind, arginfo_gnupg_rewind, ZEND_ACC_PUBLIC)
PHP_ME(gnupg_keylistiterator, valid, arginfo_gnupg_valid, ZEND_ACC_PUBLIC) PHP_ME(gnupg_keylistiterator, valid, arginfo_gnupg_valid, ZEND_ACC_PUBLIC)
PHPC_FE_END PHP_FE_END
}; };
/* }}} */ /* }}} */
/* {{{ _gnupg_keylistiterator_init /* {{{ gnupg_keylistiterator_init
*/ */
int _gnupg_keylistiterator_init(INIT_FUNC_ARGS) int gnupg_keylistiterator_init(INIT_FUNC_ARGS)
{ {
zend_class_entry ce; zend_class_entry ce;
/* init class */ /* init class */
INIT_CLASS_ENTRY(ce, "gnupg_keylistiterator", gnupg_keylistiterator_methods); INIT_CLASS_ENTRY(ce, "gnupg_keylistiterator", gnupg_keylistiterator_methods);
PHPC_CLASS_SET_HANDLER_CREATE(ce, gnupg_keylistiterator); ce.create_object = gnupg_keylistiterator_object_create;
gnupg_keylistiterator_class_entry = PHPC_CLASS_REGISTER(ce); gnupg_keylistiterator_class_entry = zend_register_internal_class(&ce);
PHPC_OBJ_INIT_HANDLERS(gnupg_keylistiterator);
PHPC_OBJ_SET_HANDLER_OFFSET(gnupg_keylistiterator);
PHPC_OBJ_SET_HANDLER_FREE(gnupg_keylistiterator);
zend_class_implements(gnupg_keylistiterator_class_entry TSRMLS_CC, 1, zend_ce_iterator); memcpy(&gnupg_keylistiterator_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
gnupg_keylistiterator_handlers.offset = XtOffsetOf(gnupg_keylistiterator_object, std);
gnupg_keylistiterator_handlers.free_obj = gnupg_keylistiterator_object_free;
zend_class_implements(gnupg_keylistiterator_class_entry, 1, zend_ce_iterator);
le_gnupg_keylistiterator = zend_register_list_destructors_ex(NULL, NULL, "ctx_keylistiterator", module_number); le_gnupg_keylistiterator = zend_register_list_destructors_ex(NULL, NULL, "ctx_keylistiterator", module_number);
@ -144,17 +151,17 @@ int _gnupg_keylistiterator_init(INIT_FUNC_ARGS)
PHP_METHOD(gnupg_keylistiterator, __construct) PHP_METHOD(gnupg_keylistiterator, __construct)
{ {
char *pattern = NULL; char *pattern = NULL;
phpc_str_size_t pattern_len; size_t pattern_len;
int args = ZEND_NUM_ARGS(); int args = ZEND_NUM_ARGS();
GNUPG_GET_ITERATOR(); GNUPG_GET_ITERATOR();
if (args > 0) { if (args > 0) {
if (zend_parse_parameters(args TSRMLS_CC, "|s", &pattern, &pattern_len) == FAILURE) { if (zend_parse_parameters(args, "|s", &pattern, &pattern_len) == FAILURE) {
return; return;
} }
PHPC_THIS->pattern = estrdup(pattern); intern->pattern = estrdup(pattern);
} }
} }
/* }}} */ /* }}} */
@ -164,7 +171,7 @@ PHP_METHOD(gnupg_keylistiterator, current)
{ {
GNUPG_GET_ITERATOR(); GNUPG_GET_ITERATOR();
PHPC_CSTR_RETURN(PHPC_THIS->gpgkey->uids[0].uid); RETURN_STRING(intern->gpgkey->uids[0].uid);
} }
/* }}} */ /* }}} */
@ -173,7 +180,7 @@ PHP_METHOD(gnupg_keylistiterator, key)
{ {
GNUPG_GET_ITERATOR(); GNUPG_GET_ITERATOR();
PHPC_CSTR_RETURN(PHPC_THIS->gpgkey->subkeys[0].fpr); RETURN_STRING(intern->gpgkey->subkeys[0].fpr);
} }
/* }}} */ /* }}} */
@ -182,13 +189,13 @@ PHP_METHOD(gnupg_keylistiterator, next)
{ {
GNUPG_GET_ITERATOR(); GNUPG_GET_ITERATOR();
if (PHPC_THIS->gpgkey){ if (intern->gpgkey) {
gpgme_key_release(PHPC_THIS->gpgkey); gpgme_key_release(intern->gpgkey);
} }
if ((PHPC_THIS->err = gpgme_op_keylist_next(PHPC_THIS->ctx, &PHPC_THIS->gpgkey))) { if ((intern->err = gpgme_op_keylist_next(intern->ctx, &intern->gpgkey))) {
gpgme_key_release(PHPC_THIS->gpgkey); gpgme_key_release(intern->gpgkey);
PHPC_THIS->gpgkey = NULL; intern->gpgkey = NULL;
} }
RETURN_TRUE; RETURN_TRUE;
} }
@ -199,11 +206,11 @@ PHP_METHOD(gnupg_keylistiterator, rewind)
{ {
GNUPG_GET_ITERATOR(); GNUPG_GET_ITERATOR();
if ((PHPC_THIS->err = gpgme_op_keylist_start( if ((intern->err = gpgme_op_keylist_start(
PHPC_THIS->ctx, PHPC_THIS->pattern ? PHPC_THIS->pattern : "", 0)) != GPG_ERR_NO_ERROR){ intern->ctx, intern->pattern ? intern->pattern : "", 0)) != GPG_ERR_NO_ERROR) {
zend_throw_exception(zend_ce_exception, (char *)gpg_strerror(PHPC_THIS->err), 1 TSRMLS_CC); zend_throw_exception(zend_ce_exception, (char *)gpgme_strerror(intern->err), 1);
} }
if ((PHPC_THIS->err = gpgme_op_keylist_next(PHPC_THIS->ctx, &PHPC_THIS->gpgkey)) != GPG_ERR_NO_ERROR){ if ((intern->err = gpgme_op_keylist_next(intern->ctx, &intern->gpgkey)) != GPG_ERR_NO_ERROR) {
RETURN_FALSE; RETURN_FALSE;
} }
RETURN_TRUE; RETURN_TRUE;
@ -211,11 +218,11 @@ PHP_METHOD(gnupg_keylistiterator, rewind)
/* }}} */ /* }}} */
/* {{{ proto bool valid() */ /* {{{ proto bool valid() */
PHP_METHOD(gnupg_keylistiterator,valid) PHP_METHOD(gnupg_keylistiterator, valid)
{ {
GNUPG_GET_ITERATOR(); GNUPG_GET_ITERATOR();
if (PHPC_THIS->gpgkey != NULL) { if (intern->gpgkey != NULL) {
RETURN_TRUE; RETURN_TRUE;
} else { } else {
RETURN_FALSE; RETURN_FALSE;

View file

@ -1,4 +1,5 @@
/*
/*
+--------------------------------------------------------------------+ +--------------------------------------------------------------------+
| PECL :: gnupg | | PECL :: gnupg |
+--------------------------------------------------------------------+ +--------------------------------------------------------------------+
@ -26,24 +27,27 @@ extern zend_module_entry gnupg_module_entry;
#define PHP_GNUPG_API #define PHP_GNUPG_API
#endif #endif
#include <gpgme.h>
#ifdef ZTS #ifdef ZTS
#include "TSRM.h" #include "TSRM.h"
#endif #endif
#include <gpgme.h> /* Object structure */
#include "phpc/phpc.h" typedef struct _gnupg_object {
PHPC_OBJ_STRUCT_BEGIN(gnupg)
gpgme_ctx_t ctx; gpgme_ctx_t ctx;
gpgme_error_t err;
int errormode;
char* errortxt;
int signmode;
gpgme_key_t *encryptkeys; gpgme_key_t *encryptkeys;
unsigned int encrypt_size; int encrypt_size;
gpgme_sig_mode_t signmode;
HashTable *signkeys; HashTable *signkeys;
HashTable *decryptkeys; HashTable *decryptkeys;
PHPC_OBJ_STRUCT_END() gpgme_error_t err;
char *errortxt;
int errormode;
zend_object std;
} gnupg_object;
/* The actual structure is defined in gnupg.c to keep it encapsulated */
PHP_MINIT_FUNCTION(gnupg); PHP_MINIT_FUNCTION(gnupg);
PHP_MSHUTDOWN_FUNCTION(gnupg); PHP_MSHUTDOWN_FUNCTION(gnupg);
@ -73,7 +77,9 @@ PHP_FUNCTION(gnupg_addsignkey);
PHP_FUNCTION(gnupg_addencryptkey); PHP_FUNCTION(gnupg_addencryptkey);
PHP_FUNCTION(gnupg_adddecryptkey); PHP_FUNCTION(gnupg_adddecryptkey);
PHP_FUNCTION(gnupg_deletekey); PHP_FUNCTION(gnupg_deletekey);
#if GPGME_VERSION_NUMBER < 0x020000 /* GPGME < 2.0.0 */
PHP_FUNCTION(gnupg_gettrustlist); PHP_FUNCTION(gnupg_gettrustlist);
#endif
PHP_FUNCTION(gnupg_listsignatures); PHP_FUNCTION(gnupg_listsignatures);
PHP_FUNCTION(gnupg_seterrormode); PHP_FUNCTION(gnupg_seterrormode);

38
php_gnupg_compat.h Normal file
View file

@ -0,0 +1,38 @@
/*
+--------------------------------------------------------------------+
| PECL :: gnupg |
+--------------------------------------------------------------------+
| Redistribution and use in source and binary forms, with or without |
| modification, are permitted provided that the conditions mentioned |
| in the accompanying LICENSE file are met. |
+--------------------------------------------------------------------+
| Copyright (c) 2025, Jakub Zelenka <bukka@php.net> |
+--------------------------------------------------------------------+
*/
#ifndef PHP_GNUPG_COMPAT_H
#define PHP_GNUPG_COMPAT_H
/* ZEND_ACC_CTOR and ZEND_ACC_DTOR removed in PHP 7.4 */
#ifndef ZEND_ACC_CTOR
#define ZEND_ACC_CTOR 0
#endif
#ifndef ZEND_ACC_DTOR
#define ZEND_ACC_DTOR 0
#endif
/* zend_function_entry constness added in PHP 7.4 */
#if PHP_VERSION_ID < 70400
#define GNUPG_FUNCTION_ENTRY zend_function_entry
#else
#define GNUPG_FUNCTION_ENTRY const zend_function_entry
#endif
/* object handlers comparison name changed in PHP 8.0 */
#if PHP_VERSION_ID < 80000
#define GNUPG_COMPARE_HANDLER_NAME compare_objects
#else
#define GNUPG_COMPARE_HANDLER_NAME compare
#endif
#endif /* PHP_GNUPG_COMPAT_H */

View file

@ -15,46 +15,26 @@
#ifndef PHP_GNUPG_KEYLISTITERATOR_H #ifndef PHP_GNUPG_KEYLISTITERATOR_H
#define PHP_GNUPG_KEYLISTITERATOR_H #define PHP_GNUPG_KEYLISTITERATOR_H
extern zend_module_entry gnupg_keyiterator_module_entry;
#ifdef PHP_WIN32
#define PHP_GNUPG_API __declspec(dllexport)
#else
#define PHP_GNUPG_API
#endif
#ifdef ZTS
#include "TSRM.h"
#endif
#include <gpgme.h> #include <gpgme.h>
#include "phpc/phpc.h"
#define gnupg_keylistiterator_init() _gnupg_keylistiterator_init(INIT_FUNC_ARGS_PASSTHRU) typedef struct _gnupg_keylistiterator_object {
extern int _gnupg_keylistiterator_init(INIT_FUNC_ARGS);
PHPC_OBJ_STRUCT_BEGIN(gnupg_keylistiterator)
gpgme_ctx_t ctx; gpgme_ctx_t ctx;
gpgme_error_t err; gpgme_error_t err;
gpgme_key_t gpgkey; gpgme_key_t gpgkey;
char *pattern; char *pattern;
PHPC_OBJ_STRUCT_END() zend_object std;
} gnupg_keylistiterator_object;
int gnupg_keylistiterator_init(INIT_FUNC_ARGS);
PHP_METHOD(gnupg_keylistiterator, __construct); PHP_METHOD(gnupg_keylistiterator, __construct);
PHP_METHOD(gnupg_keylistiterator, current); PHP_METHOD(gnupg_keylistiterator, current);
PHP_METHOD(gnupg_keylistiterator, key);
PHP_METHOD(gnupg_keylistiterator, next); PHP_METHOD(gnupg_keylistiterator, next);
PHP_METHOD(gnupg_keylistiterator, rewind); PHP_METHOD(gnupg_keylistiterator, rewind);
PHP_METHOD(gnupg_keylistiterator, key);
PHP_METHOD(gnupg_keylistiterator, valid); PHP_METHOD(gnupg_keylistiterator, valid);
#ifdef ZTS #endif /* PHP_GNUPG_KEYLISTITERATOR_H */
#define GNUPG_G(v) TSRMG(gnupg_globals_id, zend_gnupg_globals *, v)
#else
#define GNUPG_G(v) (gnupg_globals.v)
#endif
#endif /* PHP_GNUPG_H */
/* /*
* Local variables: * Local variables:

1
phpc

@ -1 +0,0 @@
Subproject commit 5dede0948d20a027536afb983d2f1eba07977c78