mirror of
https://github.com/php-gnupg/php-gnupg.git
synced 2024-11-23 23:07:10 +00:00
Port gnupg_keylistiterator to use phpc
This commit is contained in:
parent
bc85cdf849
commit
643bcd1ecf
4 changed files with 125 additions and 111 deletions
4
gnupg.c
4
gnupg.c
|
@ -172,7 +172,7 @@ PHPC_OBJ_HANDLER_CREATE_EX(gnupg)
|
|||
PHPC_OBJ_HANDLER_CREATE_EX_RETURN(gnupg);
|
||||
}
|
||||
|
||||
/* {{{ create gnupg_object */
|
||||
/* {{{ create gnupg */
|
||||
PHPC_OBJ_HANDLER_CREATE(gnupg)
|
||||
{
|
||||
PHPC_OBJ_HANDLER_CREATE_RETURN(gnupg);
|
||||
|
@ -302,7 +302,7 @@ PHP_MINIT_FUNCTION(gnupg)
|
|||
{
|
||||
zend_class_entry ce;
|
||||
|
||||
/* init classes */
|
||||
/* init class */
|
||||
INIT_CLASS_ENTRY(ce, "gnupg", gnupg_methods);
|
||||
PHPC_CLASS_SET_HANDLER_CREATE(ce, gnupg);
|
||||
gnupg_class_entry = PHPC_CLASS_REGISTER(ce);
|
||||
|
|
|
@ -8,76 +8,83 @@
|
|||
+--------------------------------------------------------------------+
|
||||
| Copyright (c) 2006, Thilo Raufeisen <traufeisen@php.net> |
|
||||
| Copyright (c) 2013, Jim Jagielski <jimjag@php.net> |
|
||||
| Copyright (c) 2016, Jakub Zelenka <bukka@php.net> |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "php.h"
|
||||
#include <stddef.h>
|
||||
|
||||
#include "php.h"
|
||||
#include "php_ini.h"
|
||||
#include "ext/standard/info.h"
|
||||
#include "zend_interfaces.h"
|
||||
#include "zend_exceptions.h"
|
||||
#include "php_gnupg.h"
|
||||
#include "php_gnupg_keylistiterator.h"
|
||||
#include "phpc/phpc.h"
|
||||
|
||||
static int le_gnupg_keylistiterator;
|
||||
|
||||
static zend_object_handlers gnupg_keylistiterator_object_handlers;
|
||||
static zend_class_entry *gnupg_keylistiterator_class_entry;
|
||||
|
||||
/* {{{ defs */
|
||||
PHPC_OBJ_DEFINE_HANDLER_VAR(gnupg_keylistiterator);
|
||||
|
||||
/* {{{ GNUPG_GET_ITERATOR */
|
||||
#define GNUPG_GET_ITERATOR() \
|
||||
zval *this = getThis(); \
|
||||
gnupg_keylistiterator_object *intern = NULL; \
|
||||
if(this){ \
|
||||
intern = Z_KEYLISTITERATORO_P(getThis() TSRMLS_CC); \
|
||||
if(!intern){ \
|
||||
PHPC_THIS_DECLARE(gnupg_keylistiterator) = 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"); \
|
||||
RETURN_FALSE; \
|
||||
} \
|
||||
} \
|
||||
} while (0)
|
||||
/* }}} */
|
||||
|
||||
/* {{{ free gnupg_keylistiterator */
|
||||
PHPC_OBJ_HANDLER_FREE(gnupg_keylistiterator)
|
||||
{
|
||||
PHPC_OBJ_HANDLER_FREE_INIT(gnupg_keylistiterator);
|
||||
|
||||
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);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ free_iterator_storage */
|
||||
static void gnupg_keylistiterator_dtor(zend_object *z_obj TSRMLS_DC){
|
||||
gnupg_keylistiterator_object *intern;
|
||||
intern = keylistiterator_object_from_obj(z_obj);
|
||||
|
||||
gpgme_op_keylist_end(intern->ctx);
|
||||
gpgme_key_release(intern->gpgkey);
|
||||
gpgme_release(intern->ctx);
|
||||
/*
|
||||
zval_dtor(&intern->pattern);
|
||||
*/
|
||||
zend_object_std_dtor(&intern->zo);
|
||||
efree(intern);
|
||||
PHPC_OBJ_HANDLER_FREE_DESTROY();
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ keylistiterator_objects_new */
|
||||
static zend_object* gnupg_keylistiterator_objects_new(zend_class_entry *class_type TSRMLS_DC){
|
||||
gnupg_keylistiterator_object *intern;
|
||||
gpgme_ctx_t ctx;
|
||||
|
||||
intern = ecalloc(1, sizeof(gnupg_keylistiterator_object) + zend_object_properties_size(class_type));
|
||||
|
||||
zend_object_std_init(&intern->zo, class_type);
|
||||
object_properties_init(&intern->zo, class_type);
|
||||
intern->zo.handlers = &gnupg_keylistiterator_object_handlers;
|
||||
/* {{{ create_ex gnupg_keylistiterator */
|
||||
PHPC_OBJ_HANDLER_CREATE_EX(gnupg_keylistiterator)
|
||||
{
|
||||
PHPC_OBJ_HANDLER_CREATE_EX_INIT(gnupg_keylistiterator);
|
||||
|
||||
gpgme_check_version(NULL);
|
||||
gpgme_new(&ctx);
|
||||
intern->ctx = ctx;
|
||||
return &intern->zo;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ methodlist gnupg_keylistiterator */
|
||||
gpgme_new(&PHPC_THIS->ctx);
|
||||
PHPC_THIS->err = 0;
|
||||
PHPC_THIS->gpgkey = NULL;
|
||||
PHPC_THIS->pattern = NULL;
|
||||
|
||||
PHPC_OBJ_HANDLER_CREATE_EX_RETURN(gnupg_keylistiterator);
|
||||
}
|
||||
|
||||
/* {{{ create gnupg_keylistiterator */
|
||||
PHPC_OBJ_HANDLER_CREATE(gnupg_keylistiterator)
|
||||
{
|
||||
PHPC_OBJ_HANDLER_CREATE_RETURN(gnupg_keylistiterator);
|
||||
}
|
||||
|
||||
/* {{{ method list gnupg_keylistiterator */
|
||||
static zend_function_entry gnupg_keylistiterator_methods[] = {
|
||||
PHP_ME(gnupg_keylistiterator, __construct, NULL, ZEND_ACC_PUBLIC)
|
||||
PHP_ME(gnupg_keylistiterator, current, NULL, ZEND_ACC_PUBLIC)
|
||||
|
@ -85,7 +92,7 @@ static zend_function_entry gnupg_keylistiterator_methods[] = {
|
|||
PHP_ME(gnupg_keylistiterator, next, NULL, ZEND_ACC_PUBLIC)
|
||||
PHP_ME(gnupg_keylistiterator, rewind, NULL, ZEND_ACC_PUBLIC)
|
||||
PHP_ME(gnupg_keylistiterator, valid, NULL, ZEND_ACC_PUBLIC)
|
||||
{NULL, NULL, NULL}
|
||||
PHPC_FE_END
|
||||
};
|
||||
/* }}} */
|
||||
|
||||
|
@ -95,84 +102,106 @@ 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);
|
||||
|
||||
zend_class_implements(gnupg_keylistiterator_class_entry TSRMLS_CC, 1, zend_ce_iterator);
|
||||
|
||||
ce.create_object = gnupg_keylistiterator_objects_new;
|
||||
gnupg_keylistiterator_class_entry = zend_register_internal_class(&ce TSRMLS_CC);
|
||||
memcpy(&gnupg_keylistiterator_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
|
||||
le_gnupg_keylistiterator = zend_register_list_destructors_ex(NULL, NULL, "ctx_keylistiterator", module_number);
|
||||
|
||||
zend_class_implements (gnupg_keylistiterator_class_entry TSRMLS_CC, 1, zend_ce_iterator);
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
|
||||
PHP_METHOD(gnupg_keylistiterator,__construct){
|
||||
zval *pattern = NULL;
|
||||
/* {{{ proto __contruct(string $pattern)
|
||||
* constructs keylistiterator with supplied pattern
|
||||
*/
|
||||
PHP_METHOD(gnupg_keylistiterator, __construct)
|
||||
{
|
||||
char *pattern = NULL;
|
||||
phpc_str_size_t pattern_len;
|
||||
|
||||
int args = ZEND_NUM_ARGS();
|
||||
|
||||
GNUPG_GET_ITERATOR();
|
||||
|
||||
if(args > 0){
|
||||
if (zend_parse_parameters(args TSRMLS_CC, "|z", &pattern) == FAILURE){
|
||||
if (args > 0) {
|
||||
if (zend_parse_parameters(args TSRMLS_CC, "|s", &pattern, &pattern_len) == FAILURE) {
|
||||
return;
|
||||
}
|
||||
intern->pattern = *pattern;
|
||||
zval_copy_ctor(&intern->pattern);
|
||||
}else{
|
||||
ZVAL_EMPTY_STRING(&intern->pattern);
|
||||
PHPC_THIS->pattern = estrdup(pattern);
|
||||
}
|
||||
}
|
||||
PHP_METHOD(gnupg_keylistiterator,current){
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto string current() */
|
||||
PHP_METHOD(gnupg_keylistiterator,current)
|
||||
{
|
||||
GNUPG_GET_ITERATOR();
|
||||
|
||||
RETURN_STRING(intern->gpgkey->uids[0].uid);
|
||||
PHPC_CSTR_RETURN(PHPC_THIS->gpgkey->uids[0].uid);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
PHP_METHOD(gnupg_keylistiterator,key){
|
||||
/* {{{ proto string key() */
|
||||
PHP_METHOD(gnupg_keylistiterator,key)
|
||||
{
|
||||
GNUPG_GET_ITERATOR();
|
||||
|
||||
RETURN_STRING(intern->gpgkey->subkeys[0].fpr);
|
||||
PHPC_CSTR_RETURN(PHPC_THIS->gpgkey->subkeys[0].fpr);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
PHP_METHOD(gnupg_keylistiterator,next){
|
||||
/* {{{ proto bool next() */
|
||||
PHP_METHOD(gnupg_keylistiterator,next)
|
||||
{
|
||||
GNUPG_GET_ITERATOR();
|
||||
|
||||
if(intern->gpgkey){
|
||||
gpgme_key_release(intern->gpgkey);
|
||||
if (PHPC_THIS->gpgkey){
|
||||
gpgme_key_release(PHPC_THIS->gpgkey);
|
||||
}
|
||||
|
||||
if((intern->err = gpgme_op_keylist_next(intern->ctx, &intern->gpgkey))){
|
||||
gpgme_key_release(intern->gpgkey);
|
||||
intern->gpgkey = NULL;
|
||||
if ((PHPC_THIS->err = gpgme_op_keylist_next(PHPC_THIS->ctx, &PHPC_THIS->gpgkey))) {
|
||||
gpgme_key_release(PHPC_THIS->gpgkey);
|
||||
PHPC_THIS->gpgkey = NULL;
|
||||
}
|
||||
RETURN_TRUE;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
PHP_METHOD(gnupg_keylistiterator,rewind){
|
||||
/* {{{ proto bool rewind() */
|
||||
PHP_METHOD(gnupg_keylistiterator,rewind)
|
||||
{
|
||||
GNUPG_GET_ITERATOR();
|
||||
|
||||
if((intern->err = gpgme_op_keylist_start(intern->ctx, Z_STRVAL(intern->pattern), 0)) != GPG_ERR_NO_ERROR){
|
||||
zend_throw_exception(zend_exception_get_default(TSRMLS_C),(char *)gpg_strerror(intern->err),1 TSRMLS_CC);
|
||||
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_exception_get_default(TSRMLS_C), (char *)gpg_strerror(PHPC_THIS->err), 1 TSRMLS_CC);
|
||||
}
|
||||
if((intern->err = gpgme_op_keylist_next(intern->ctx, &intern->gpgkey))!=GPG_ERR_NO_ERROR){
|
||||
if ((PHPC_THIS->err = gpgme_op_keylist_next(PHPC_THIS->ctx, &PHPC_THIS->gpgkey)) != GPG_ERR_NO_ERROR){
|
||||
RETURN_FALSE;
|
||||
}
|
||||
RETURN_TRUE;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
PHP_METHOD(gnupg_keylistiterator,valid){
|
||||
/* {{{ proto bool valid() */
|
||||
PHP_METHOD(gnupg_keylistiterator,valid)
|
||||
{
|
||||
GNUPG_GET_ITERATOR();
|
||||
|
||||
if(intern->gpgkey!=NULL){
|
||||
if (PHPC_THIS->gpgkey != NULL) {
|
||||
RETURN_TRUE;
|
||||
}else{
|
||||
} else {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/*
|
||||
* Local variables:
|
||||
|
|
|
@ -8,11 +8,10 @@
|
|||
+--------------------------------------------------------------------+
|
||||
| Copyright (c) 2006, Thilo Raufeisen <traufeisen@php.net> |
|
||||
| Copyright (c) 2013, Jim Jagielski <jimjag@php.net> |
|
||||
| Copyright (c) 2016, Jakub Zelenka <bukka@php.net> |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
#ifndef PHP_GNUPG_H
|
||||
#define PHP_GNUPG_H
|
||||
|
||||
|
|
|
@ -8,11 +8,10 @@
|
|||
+--------------------------------------------------------------------+
|
||||
| Copyright (c) 2006, Thilo Raufeisen <traufeisen@php.net> |
|
||||
| Copyright (c) 2013, Jim Jagielski <jimjag@php.net> |
|
||||
| Copyright (c) 2016, Jakub Zelenka <bukka@php.net> |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
#ifndef PHP_GNUPG_KEYLISTITERATOR_H
|
||||
#define PHP_GNUPG_KEYLISTITERATOR_H
|
||||
|
||||
|
@ -29,29 +28,17 @@ extern zend_module_entry gnupg_keyiterator_module_entry;
|
|||
#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);
|
||||
|
||||
typedef struct _gnupg_keylistiterator_object{
|
||||
PHPC_OBJ_STRUCT_BEGIN(gnupg_keylistiterator)
|
||||
gpgme_ctx_t ctx;
|
||||
gpgme_error_t err;
|
||||
gpgme_key_t gpgkey;
|
||||
zval pattern;
|
||||
zend_object zo;
|
||||
} gnupg_keylistiterator_object;
|
||||
|
||||
static zend_class_entry *gnupg_keylistiterator_class_entry;
|
||||
|
||||
static inline gnupg_keylistiterator_object *keylistiterator_object_from_obj(zend_object *obj) /* {{{ */ {
|
||||
return (gnupg_keylistiterator_object*)((char*)(obj) - XtOffsetOf(gnupg_keylistiterator_object, zo));
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
static inline gnupg_keylistiterator_object *Z_KEYLISTITERATORO_P(zval *zv) /* {{{ */ {
|
||||
return keylistiterator_object_from_obj(Z_OBJ_P((zv)));
|
||||
}
|
||||
/* }}} */
|
||||
char *pattern;
|
||||
PHPC_OBJ_STRUCT_END()
|
||||
|
||||
PHP_METHOD(gnupg_keylistiterator, __construct);
|
||||
PHP_METHOD(gnupg_keylistiterator, current);
|
||||
|
@ -60,7 +47,6 @@ 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
|
||||
|
|
Loading…
Reference in a new issue