mirror of
https://github.com/php-gnupg/php-gnupg.git
synced 2026-01-11 19:09:35 +00:00
Remove compatibility with PHP 7.1 and older (#63)
It means minimal PHP version is 7.2
This commit is contained in:
parent
4b9160b94d
commit
5081dab5fc
9 changed files with 517 additions and 550 deletions
3
NEWS.md
3
NEWS.md
|
|
@ -2,6 +2,9 @@
|
|||
|
||||
List of all features for the release
|
||||
|
||||
## 1.6.0
|
||||
- Removed compatibility with PHP 7.1 and older.
|
||||
|
||||
## 1.5.4
|
||||
- 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
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ Of course PHP has to be installed too. The minimal version that is supported is
|
|||
|
||||
#### PECL
|
||||
|
||||
This extension is available on PECL.
|
||||
This extension is available on PECL.
|
||||
|
||||
```
|
||||
$ sudo pecl install gnupg
|
||||
|
|
@ -23,12 +23,11 @@ $ sudo pecl install gnupg
|
|||
|
||||
#### Manual Installation
|
||||
|
||||
It's important to have a git installed as it's necessary for recursive fetch of
|
||||
[phpc](https://github.com/bukka/phpc).
|
||||
It's important to have a git installed
|
||||
|
||||
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
|
||||
|
|
|
|||
|
|
@ -2,6 +2,9 @@
|
|||
|
||||
This document lists backward incompatible change in the extension
|
||||
|
||||
## 1.6.0
|
||||
- minimal PHP version bumped to 7.2
|
||||
|
||||
## 1.5.0
|
||||
- no backward incompatible changes
|
||||
|
||||
|
|
|
|||
|
|
@ -25,65 +25,72 @@
|
|||
#include "zend_exceptions.h"
|
||||
#include "php_gnupg.h"
|
||||
#include "php_gnupg_keylistiterator.h"
|
||||
#include "phpc/phpc.h"
|
||||
#include "php_gnupg_compat.h"
|
||||
|
||||
static int le_gnupg_keylistiterator;
|
||||
|
||||
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 */
|
||||
#define GNUPG_GET_ITERATOR() \
|
||||
zval *this = getThis(); \
|
||||
PHPC_THIS_DECLARE(gnupg_keylistiterator) = NULL; \
|
||||
gnupg_keylistiterator_object *intern = NULL; \
|
||||
do { \
|
||||
if (this) { \
|
||||
PHPC_THIS_FETCH_FROM_ZVAL(gnupg_keylistiterator, this); \
|
||||
if (!PHPC_THIS) { \
|
||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid or unitialized gnupg object"); \
|
||||
intern = Z_GNUPG_KEYLISTITERATOR_P(this); \
|
||||
if (!intern) { \
|
||||
php_error_docref(NULL, E_WARNING, "Invalid or unitialized gnupg_keylistiterator object"); \
|
||||
RETURN_FALSE; \
|
||||
} \
|
||||
} \
|
||||
} while (0)
|
||||
/* }}} */
|
||||
|
||||
/* {{{ free gnupg_keylistiterator */
|
||||
PHPC_OBJ_HANDLER_FREE(gnupg_keylistiterator)
|
||||
/* {{{ gnupg_keylistiterator_object_free */
|
||||
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_key_release(PHPC_THIS->gpgkey);
|
||||
gpgme_release(PHPC_THIS->ctx);
|
||||
if (PHPC_THIS->pattern) {
|
||||
efree(PHPC_THIS->pattern);
|
||||
gpgme_op_keylist_end(intern->ctx);
|
||||
gpgme_key_release(intern->gpgkey);
|
||||
gpgme_release(intern->ctx);
|
||||
if (intern->pattern) {
|
||||
efree(intern->pattern);
|
||||
}
|
||||
|
||||
PHPC_OBJ_HANDLER_FREE_DESTROY();
|
||||
zend_object_std_dtor(&intern->std);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ create_ex gnupg_keylistiterator */
|
||||
PHPC_OBJ_HANDLER_CREATE_EX(gnupg_keylistiterator)
|
||||
/* {{{ gnupg_keylistiterator_object_create */
|
||||
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_new(&intern->ctx);
|
||||
intern->err = 0;
|
||||
intern->gpgkey = NULL;
|
||||
intern->pattern = NULL;
|
||||
|
||||
gpgme_new(&PHPC_THIS->ctx);
|
||||
PHPC_THIS->err = 0;
|
||||
PHPC_THIS->gpgkey = NULL;
|
||||
PHPC_THIS->pattern = NULL;
|
||||
zend_object_std_init(&intern->std, ce);
|
||||
object_properties_init(&intern->std, ce);
|
||||
intern->std.handlers = &gnupg_keylistiterator_handlers;
|
||||
|
||||
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 */
|
||||
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
|
||||
|
||||
|
||||
/* {{{ method list gnupg_keylistiterator */
|
||||
static zend_function_entry gnupg_keylistiterator_methods[] = {
|
||||
PHP_ME(gnupg_keylistiterator, __construct, arginfo_gnupg_void_iterator_method, ZEND_ACC_PUBLIC)
|
||||
static const zend_function_entry gnupg_keylistiterator_methods[] = {
|
||||
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, key, arginfo_gnupg_key, 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, 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;
|
||||
|
||||
/* init class */
|
||||
INIT_CLASS_ENTRY(ce, "gnupg_keylistiterator", gnupg_keylistiterator_methods);
|
||||
PHPC_CLASS_SET_HANDLER_CREATE(ce, gnupg_keylistiterator);
|
||||
gnupg_keylistiterator_class_entry = PHPC_CLASS_REGISTER(ce);
|
||||
PHPC_OBJ_INIT_HANDLERS(gnupg_keylistiterator);
|
||||
PHPC_OBJ_SET_HANDLER_OFFSET(gnupg_keylistiterator);
|
||||
PHPC_OBJ_SET_HANDLER_FREE(gnupg_keylistiterator);
|
||||
ce.create_object = gnupg_keylistiterator_object_create;
|
||||
gnupg_keylistiterator_class_entry = zend_register_internal_class(&ce);
|
||||
|
||||
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);
|
||||
|
||||
|
|
@ -144,17 +151,17 @@ int _gnupg_keylistiterator_init(INIT_FUNC_ARGS)
|
|||
PHP_METHOD(gnupg_keylistiterator, __construct)
|
||||
{
|
||||
char *pattern = NULL;
|
||||
phpc_str_size_t pattern_len;
|
||||
size_t pattern_len;
|
||||
|
||||
int args = ZEND_NUM_ARGS();
|
||||
|
||||
GNUPG_GET_ITERATOR();
|
||||
|
||||
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;
|
||||
}
|
||||
PHPC_THIS->pattern = estrdup(pattern);
|
||||
intern->pattern = estrdup(pattern);
|
||||
}
|
||||
}
|
||||
/* }}} */
|
||||
|
|
@ -164,7 +171,7 @@ PHP_METHOD(gnupg_keylistiterator, current)
|
|||
{
|
||||
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();
|
||||
|
||||
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();
|
||||
|
||||
if (PHPC_THIS->gpgkey){
|
||||
gpgme_key_release(PHPC_THIS->gpgkey);
|
||||
if (intern->gpgkey) {
|
||||
gpgme_key_release(intern->gpgkey);
|
||||
}
|
||||
|
||||
if ((PHPC_THIS->err = gpgme_op_keylist_next(PHPC_THIS->ctx, &PHPC_THIS->gpgkey))) {
|
||||
gpgme_key_release(PHPC_THIS->gpgkey);
|
||||
PHPC_THIS->gpgkey = NULL;
|
||||
if ((intern->err = gpgme_op_keylist_next(intern->ctx, &intern->gpgkey))) {
|
||||
gpgme_key_release(intern->gpgkey);
|
||||
intern->gpgkey = NULL;
|
||||
}
|
||||
RETURN_TRUE;
|
||||
}
|
||||
|
|
@ -199,11 +206,11 @@ PHP_METHOD(gnupg_keylistiterator, rewind)
|
|||
{
|
||||
GNUPG_GET_ITERATOR();
|
||||
|
||||
if ((PHPC_THIS->err = gpgme_op_keylist_start(
|
||||
PHPC_THIS->ctx, PHPC_THIS->pattern ? PHPC_THIS->pattern : "", 0)) != GPG_ERR_NO_ERROR){
|
||||
zend_throw_exception(zend_ce_exception, (char *)gpg_strerror(PHPC_THIS->err), 1 TSRMLS_CC);
|
||||
if ((intern->err = gpgme_op_keylist_start(
|
||||
intern->ctx, intern->pattern ? intern->pattern : "", 0)) != GPG_ERR_NO_ERROR) {
|
||||
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_TRUE;
|
||||
|
|
@ -211,11 +218,11 @@ PHP_METHOD(gnupg_keylistiterator, rewind)
|
|||
/* }}} */
|
||||
|
||||
/* {{{ proto bool valid() */
|
||||
PHP_METHOD(gnupg_keylistiterator,valid)
|
||||
PHP_METHOD(gnupg_keylistiterator, valid)
|
||||
{
|
||||
GNUPG_GET_ITERATOR();
|
||||
|
||||
if (PHPC_THIS->gpgkey != NULL) {
|
||||
if (intern->gpgkey != NULL) {
|
||||
RETURN_TRUE;
|
||||
} else {
|
||||
RETURN_FALSE;
|
||||
|
|
|
|||
30
php_gnupg.h
30
php_gnupg.h
|
|
@ -1,4 +1,5 @@
|
|||
/*
|
||||
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| PECL :: gnupg |
|
||||
+--------------------------------------------------------------------+
|
||||
|
|
@ -26,24 +27,27 @@ extern zend_module_entry gnupg_module_entry;
|
|||
#define PHP_GNUPG_API
|
||||
#endif
|
||||
|
||||
#include <gpgme.h>
|
||||
|
||||
#ifdef ZTS
|
||||
#include "TSRM.h"
|
||||
#endif
|
||||
|
||||
#include <gpgme.h>
|
||||
#include "phpc/phpc.h"
|
||||
|
||||
PHPC_OBJ_STRUCT_BEGIN(gnupg)
|
||||
/* Object structure */
|
||||
typedef struct _gnupg_object {
|
||||
gpgme_ctx_t ctx;
|
||||
gpgme_error_t err;
|
||||
int errormode;
|
||||
char* errortxt;
|
||||
int signmode;
|
||||
gpgme_key_t *encryptkeys;
|
||||
unsigned int encrypt_size;
|
||||
int encrypt_size;
|
||||
gpgme_sig_mode_t signmode;
|
||||
HashTable *signkeys;
|
||||
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_MSHUTDOWN_FUNCTION(gnupg);
|
||||
|
|
@ -73,7 +77,9 @@ PHP_FUNCTION(gnupg_addsignkey);
|
|||
PHP_FUNCTION(gnupg_addencryptkey);
|
||||
PHP_FUNCTION(gnupg_adddecryptkey);
|
||||
PHP_FUNCTION(gnupg_deletekey);
|
||||
#if GPGME_VERSION_NUMBER < 0x020000 /* GPGME < 2.0.0 */
|
||||
PHP_FUNCTION(gnupg_gettrustlist);
|
||||
#endif
|
||||
PHP_FUNCTION(gnupg_listsignatures);
|
||||
PHP_FUNCTION(gnupg_seterrormode);
|
||||
|
||||
|
|
@ -93,4 +99,4 @@ PHP_FUNCTION(gnupg_seterrormode);
|
|||
* End:
|
||||
* vim600: noet sw=4 ts=4 fdm=marker
|
||||
* vim<600: noet sw=4 ts=4
|
||||
*/
|
||||
*/
|
||||
38
php_gnupg_compat.h
Normal file
38
php_gnupg_compat.h
Normal 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 */
|
||||
|
|
@ -15,46 +15,26 @@
|
|||
#ifndef 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 "phpc/phpc.h"
|
||||
|
||||
#define gnupg_keylistiterator_init() _gnupg_keylistiterator_init(INIT_FUNC_ARGS_PASSTHRU)
|
||||
extern int _gnupg_keylistiterator_init(INIT_FUNC_ARGS);
|
||||
|
||||
PHPC_OBJ_STRUCT_BEGIN(gnupg_keylistiterator)
|
||||
typedef struct _gnupg_keylistiterator_object {
|
||||
gpgme_ctx_t ctx;
|
||||
gpgme_error_t err;
|
||||
gpgme_key_t gpgkey;
|
||||
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, current);
|
||||
PHP_METHOD(gnupg_keylistiterator, key);
|
||||
PHP_METHOD(gnupg_keylistiterator, next);
|
||||
PHP_METHOD(gnupg_keylistiterator, rewind);
|
||||
PHP_METHOD(gnupg_keylistiterator, key);
|
||||
PHP_METHOD(gnupg_keylistiterator, valid);
|
||||
|
||||
#ifdef ZTS
|
||||
#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 */
|
||||
|
||||
#endif /* PHP_GNUPG_KEYLISTITERATOR_H */
|
||||
|
||||
/*
|
||||
* Local variables:
|
||||
|
|
|
|||
1
phpc
1
phpc
|
|
@ -1 +0,0 @@
|
|||
Subproject commit 5dede0948d20a027536afb983d2f1eba07977c78
|
||||
Loading…
Add table
Add a link
Reference in a new issue