mirror of
https://github.com/php-gnupg/php-gnupg.git
synced 2024-11-22 06:27:08 +00:00
split the iterator into separate file
generic code cleanup updated package-xmls
This commit is contained in:
parent
6bacc28bb6
commit
af81003551
7 changed files with 321 additions and 211 deletions
6
README
6
README
|
@ -41,6 +41,9 @@ Notes
|
|||
- This extension is class based
|
||||
No "global" constants are defined. Only class constants
|
||||
|
||||
- To specify a custom location of you keyring, simply store the path in the enviroment-variable GNUPGHOME
|
||||
This should make it easy, to use this extension with the apache-user.
|
||||
|
||||
SIG_MODE_NORMAL
|
||||
SIG_MODE_DETACH
|
||||
SIG_MODE_CLEAR
|
||||
|
@ -126,12 +129,13 @@ Methods
|
|||
- array verify(string text [, string &plaintext])
|
||||
verifies the given clearsigned text and returns information about the result in an array
|
||||
if plaintext is passed, it is filled with the plaintext (the text without signature)
|
||||
currently only cleartext-signatures are supported
|
||||
|
||||
- string decrypt(string enctext)
|
||||
decrypts the given enctext
|
||||
|
||||
- string encryptsign(string text)
|
||||
encrypts and signs the given text with the keys, whicih are set with setencryptkey and setsignerkey
|
||||
encrypts and signs the given text with the keys, which are set with setencryptkey and setsignerkey
|
||||
|
||||
- array decryptverify(string text, string &plaintext)
|
||||
verifies the given clearsigned text and returns information about the result in an array
|
||||
|
|
213
gnupg.c
213
gnupg.c
|
@ -12,7 +12,7 @@
|
|||
| obtain it through the world-wide-web, please send a note to |
|
||||
| license@php.net so we can mail you a copy immediately. |
|
||||
+----------------------------------------------------------------------+
|
||||
| Author: Thilo Raufeisen |
|
||||
| Author: Thilo Raufeisen <traufeisen@php.net> |
|
||||
+----------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
|
@ -25,16 +25,14 @@
|
|||
#include "php.h"
|
||||
#include "php_ini.h"
|
||||
#include "ext/standard/info.h"
|
||||
#include "zend_interfaces.h"
|
||||
#include "php_gnupg.h"
|
||||
#include "php_gnupg_keylistiterator.h"
|
||||
|
||||
static int le_gnupg;
|
||||
static int le_gnupg_keylistiterator;
|
||||
|
||||
static zend_object_handlers gnupg_object_handlers;
|
||||
static zend_object_handlers gnupg_keylistiterator_object_handlers;
|
||||
|
||||
/* {{{ macros */
|
||||
/* {{{ defs */
|
||||
#define GNUPG_FROM_OBJECT(intern, object){ \
|
||||
ze_gnupg_object *obj = (ze_gnupg_object*) zend_object_store_get_object(object TSRMLS_CC); \
|
||||
intern = obj->gnupg_ptr; \
|
||||
|
@ -43,14 +41,6 @@ static zend_object_handlers gnupg_keylistiterator_object_handlers;
|
|||
RETURN_FALSE; \
|
||||
} \
|
||||
}
|
||||
#define GNUPG_GET_ITERATOR(intern, object){ \
|
||||
ze_gnupg_keylistiterator_object *obj = (ze_gnupg_keylistiterator_object*) zend_object_store_get_object(object TSRMLS_CC); \
|
||||
intern = obj->gnupg_keylistiterator_ptr; \
|
||||
if(!intern){ \
|
||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid or unitialized gnupg iterator object"); \
|
||||
RETURN_FALSE; \
|
||||
}\
|
||||
}
|
||||
#define GNUPG_ERROR(intern, this){ \
|
||||
zend_update_property_string(Z_OBJCE_P(this), this, "error", 5, (char*)gpg_strerror(intern->err) TSRMLS_DC); \
|
||||
RETURN_FALSE; \
|
||||
|
@ -90,27 +80,6 @@ static void gnupg_object_free_storage(void *object TSRMLS_DC){
|
|||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ free_iterator_storage */
|
||||
static void gnupg_keylistiterator_object_free_storage(void *object TSRMLS_DC){
|
||||
ze_gnupg_keylistiterator_object *intern = (ze_gnupg_keylistiterator_object *) object;
|
||||
if(!intern){
|
||||
return;
|
||||
}
|
||||
if(intern->gnupg_keylistiterator_ptr){
|
||||
gpgme_op_keylist_end(intern->gnupg_keylistiterator_ptr->ctx);
|
||||
gpgme_key_release(intern->gnupg_keylistiterator_ptr->gpgkey);
|
||||
gpgme_release(intern->gnupg_keylistiterator_ptr->ctx);
|
||||
zval_dtor(&intern->gnupg_keylistiterator_ptr->pattern);
|
||||
efree(intern->gnupg_keylistiterator_ptr);
|
||||
}
|
||||
if(intern->zo.properties){
|
||||
zend_hash_destroy(intern->zo.properties);
|
||||
FREE_HASHTABLE(intern->zo.properties);
|
||||
}
|
||||
efree(intern);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ objects_new */
|
||||
zend_object_value gnupg_objects_new(zend_class_entry *class_type TSRMLS_DC){
|
||||
ze_gnupg_object *intern;
|
||||
|
@ -145,66 +114,24 @@ zend_object_value gnupg_objects_new(zend_class_entry *class_type TSRMLS_DC){
|
|||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ keylistiterator_objects_new */
|
||||
zend_object_value gnupg_keylistiterator_objects_new(zend_class_entry *class_type TSRMLS_DC){
|
||||
ze_gnupg_keylistiterator_object *intern;
|
||||
zval *tmp;
|
||||
zend_object_value retval;
|
||||
gnupg_keylistiterator_object *gnupg_keylistiterator_ptr;
|
||||
gpgme_ctx_t ctx;
|
||||
|
||||
intern = emalloc(sizeof(ze_gnupg_keylistiterator_object));
|
||||
intern->zo.ce = class_type;
|
||||
intern->zo.in_get = 0;
|
||||
intern->zo.in_set = 0;
|
||||
intern->zo.properties = NULL;
|
||||
|
||||
ALLOC_HASHTABLE(intern->zo.properties);
|
||||
zend_hash_init(intern->zo.properties, 0, NULL, ZVAL_PTR_DTOR, 0);
|
||||
zend_hash_copy(intern->zo.properties, &class_type->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *));
|
||||
retval.handle = zend_objects_store_put(intern,NULL,(zend_objects_free_object_storage_t) gnupg_keylistiterator_object_free_storage,NULL TSRMLS_CC);
|
||||
retval.handlers = (zend_object_handlers *) & gnupg_keylistiterator_object_handlers;
|
||||
|
||||
gpgme_new(&ctx);
|
||||
gnupg_keylistiterator_ptr = emalloc(sizeof(gnupg_keylistiterator_object));
|
||||
gnupg_keylistiterator_ptr->ctx = ctx;
|
||||
|
||||
intern->gnupg_keylistiterator_ptr = gnupg_keylistiterator_ptr;
|
||||
|
||||
return retval;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ methodlist gnupg */
|
||||
static zend_function_entry gnupg_methods[] = {
|
||||
PHP_ME_MAPPING(keyinfo, gnupg_keyinfo, NULL)
|
||||
PHP_ME_MAPPING(verify, gnupg_verify, NULL)
|
||||
PHP_ME_MAPPING(getError, gnupg_geterror, NULL)
|
||||
PHP_ME_MAPPING(setpassphrase, gnupg_setpassphrase, NULL)
|
||||
PHP_ME_MAPPING(setsignerkey, gnupg_setsignerkey, NULL)
|
||||
PHP_ME_MAPPING(clearsignerkey, gnupg_clearsignerkey, NULL)
|
||||
PHP_ME_MAPPING(setencryptkey, gnupg_setencryptkey, NULL)
|
||||
PHP_ME_MAPPING(setarmor, gnupg_setarmor, NULL)
|
||||
PHP_ME_MAPPING(encrypt, gnupg_encrypt, NULL)
|
||||
PHP_ME_MAPPING(decrypt, gnupg_decrypt, NULL)
|
||||
PHP_ME_MAPPING(export, gnupg_export, NULL)
|
||||
PHP_ME_MAPPING(getprotocol, gnupg_getprotocol, NULL)
|
||||
PHP_ME_MAPPING(setsignmode, gnupg_setsignmode, NULL)
|
||||
PHP_ME_MAPPING(sign, gnupg_sign, NULL)
|
||||
PHP_ME_MAPPING(encryptsign, gnupg_encryptsign, NULL)
|
||||
PHP_ME_MAPPING(decryptverify, gnupg_decryptverify, NULL)
|
||||
{NULL, NULL, NULL}
|
||||
};
|
||||
/* }}} */
|
||||
|
||||
/* {{{ methodlist gnupg_keylistiterator */
|
||||
static zend_function_entry gnupg_keylistiterator_methods[] = {
|
||||
PHP_ME_MAPPING(__construct, gnupg_keylistiterator_construct, NULL)
|
||||
PHP_ME_MAPPING(current, gnupg_keylistiterator_current, NULL)
|
||||
PHP_ME_MAPPING(key, gnupg_keylistiterator_key, NULL)
|
||||
PHP_ME_MAPPING(next, gnupg_keylistiterator_next, NULL)
|
||||
PHP_ME_MAPPING(rewind, gnupg_keylistiterator_rewind, NULL)
|
||||
PHP_ME_MAPPING(valid, gnupg_keylistiterator_valid, NULL)
|
||||
ZEND_ME(gnupg, keyinfo, NULL, ZEND_ACC_PUBLIC)
|
||||
ZEND_ME(gnupg, verify, NULL, ZEND_ACC_PUBLIC)
|
||||
ZEND_ME(gnupg, geterror, NULL, ZEND_ACC_PUBLIC)
|
||||
ZEND_ME(gnupg, setpassphrase, NULL, ZEND_ACC_PUBLIC)
|
||||
ZEND_ME(gnupg, setsignerkey, NULL, ZEND_ACC_PUBLIC)
|
||||
ZEND_ME(gnupg, clearsignerkey, NULL, ZEND_ACC_PUBLIC)
|
||||
ZEND_ME(gnupg, setencryptkey, NULL, ZEND_ACC_PUBLIC)
|
||||
ZEND_ME(gnupg, setarmor, NULL, ZEND_ACC_PUBLIC)
|
||||
ZEND_ME(gnupg, encrypt, NULL, ZEND_ACC_PUBLIC)
|
||||
ZEND_ME(gnupg, decrypt, NULL, ZEND_ACC_PUBLIC)
|
||||
ZEND_ME(gnupg, export, NULL, ZEND_ACC_PUBLIC)
|
||||
ZEND_ME(gnupg, getprotocol, NULL, ZEND_ACC_PUBLIC)
|
||||
ZEND_ME(gnupg, setsignmode, NULL, ZEND_ACC_PUBLIC)
|
||||
ZEND_ME(gnupg, sign, NULL, ZEND_ACC_PUBLIC)
|
||||
ZEND_ME(gnupg, encryptsign, NULL, ZEND_ACC_PUBLIC)
|
||||
ZEND_ME(gnupg, decryptverify, NULL, ZEND_ACC_PUBLIC)
|
||||
{NULL, NULL, NULL}
|
||||
};
|
||||
/* }}} */
|
||||
|
@ -240,11 +167,11 @@ zend_module_entry gnupg_module_entry = {
|
|||
NULL,
|
||||
PHP_MINIT(gnupg),
|
||||
PHP_MSHUTDOWN(gnupg),
|
||||
NULL, /* Replace with NULL if there's nothing to do at request start */
|
||||
NULL, /* Replace with NULL if there's nothing to do at request end */
|
||||
NULL,
|
||||
NULL,
|
||||
PHP_MINFO(gnupg),
|
||||
#if ZEND_MODULE_API_NO >= 20010901
|
||||
"0.1", /* Replace with version number for your extension */
|
||||
"0.2",
|
||||
#endif
|
||||
STANDARD_MODULE_PROPERTIES
|
||||
};
|
||||
|
@ -269,15 +196,9 @@ PHP_MINIT_FUNCTION(gnupg)
|
|||
memcpy(&gnupg_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
|
||||
le_gnupg = zend_register_list_destructors_ex(NULL, NULL, "ctx", module_number);
|
||||
|
||||
INIT_CLASS_ENTRY(ce, "gnupg_keylistiterator", gnupg_keylistiterator_methods);
|
||||
|
||||
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_DC, 1, zend_ce_iterator);
|
||||
|
||||
if (SUCCESS != gnupg_keylistiterator_init()){
|
||||
return FAILURE;
|
||||
}
|
||||
|
||||
register_gnupgProperties(TSRMLS_CC);
|
||||
gnupg_declare_long_constant("SIG_MODE_NORMAL", GPGME_SIG_MODE_NORMAL TSRMLS_DC);
|
||||
|
@ -755,11 +676,11 @@ PHP_FUNCTION(gnupg_encryptsign){
|
|||
}
|
||||
sign_result = gpgme_op_sign_result (intern->ctx);
|
||||
userret = gpgme_data_release_and_get_mem(out,&ret_size);
|
||||
gpgme_data_release (in);
|
||||
free (out);
|
||||
if(ret_size < 1){
|
||||
RETURN_FALSE;
|
||||
}
|
||||
gpgme_data_release (in);
|
||||
free (out);
|
||||
RETURN_STRINGL (userret,ret_size,1);
|
||||
}
|
||||
/* }}} */
|
||||
|
@ -858,9 +779,12 @@ PHP_FUNCTION(gnupg_decrypt){
|
|||
result = gpgme_op_decrypt_result (intern->ctx);
|
||||
|
||||
userret = gpgme_data_release_and_get_mem(out,&ret_size);
|
||||
RETURN_STRINGL (userret,ret_size,1);
|
||||
gpgme_data_release (in);
|
||||
free (out);
|
||||
if(ret_size < 1){
|
||||
RETURN_FALSE;
|
||||
}
|
||||
RETURN_STRINGL (userret,ret_size,1);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
|
@ -956,81 +880,6 @@ PHP_FUNCTION(gnupg_export){
|
|||
}
|
||||
/* }}} */
|
||||
|
||||
PHP_FUNCTION(gnupg_keylistiterator_construct){
|
||||
zval *pattern;
|
||||
gnupg_keylistiterator_object *intern;
|
||||
zval *this = getThis();
|
||||
|
||||
int args = ZEND_NUM_ARGS();
|
||||
|
||||
GNUPG_GET_ITERATOR(intern, this);
|
||||
|
||||
if(args > 0){
|
||||
if (zend_parse_parameters(args TSRMLS_CC, "|z", &pattern) == FAILURE){
|
||||
return;
|
||||
}
|
||||
intern->pattern = *pattern;
|
||||
zval_copy_ctor(&intern->pattern);
|
||||
}else{
|
||||
convert_to_string(&intern->pattern);
|
||||
}
|
||||
}
|
||||
PHP_FUNCTION(gnupg_keylistiterator_current){
|
||||
zval *this = getThis();
|
||||
gnupg_keylistiterator_object *intern;
|
||||
GNUPG_GET_ITERATOR(intern, this);
|
||||
RETURN_STRING(intern->gpgkey->uids[0].uid,1);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(gnupg_keylistiterator_key){
|
||||
zval *this = getThis();
|
||||
gnupg_keylistiterator_object *intern;
|
||||
GNUPG_GET_ITERATOR(intern, this);
|
||||
RETURN_STRING(intern->gpgkey->subkeys[0].fpr,1);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(gnupg_keylistiterator_next){
|
||||
zval *this = getThis();
|
||||
gnupg_keylistiterator_object *intern;
|
||||
gpgme_error_t err;
|
||||
GNUPG_GET_ITERATOR(intern, this);
|
||||
|
||||
if(err = gpgme_op_keylist_next(intern->ctx, &intern->gpgkey)){
|
||||
gpgme_key_release(intern->gpgkey);
|
||||
intern->gpgkey = NULL;
|
||||
}
|
||||
RETURN_TRUE;
|
||||
}
|
||||
|
||||
PHP_FUNCTION(gnupg_keylistiterator_rewind){
|
||||
zval *this = getThis();
|
||||
gnupg_keylistiterator_object *intern;
|
||||
gpgme_error_t err;
|
||||
GNUPG_GET_ITERATOR(intern, this);
|
||||
|
||||
if((err = gpgme_op_keylist_start(intern->ctx, Z_STRVAL(intern->pattern), 0)) != GPG_ERR_NO_ERROR){
|
||||
zend_throw_exception(zend_exception_get_default(),gpg_strerror(err),1 TSRMLS_CC);
|
||||
}
|
||||
if((err = gpgme_op_keylist_next(intern->ctx, &intern->gpgkey))!=GPG_ERR_NO_ERROR){
|
||||
RETURN_FALSE;
|
||||
}
|
||||
RETURN_TRUE;
|
||||
}
|
||||
|
||||
PHP_FUNCTION(gnupg_keylistiterator_valid){
|
||||
zval *this = getThis();
|
||||
gnupg_keylistiterator_object *intern;
|
||||
|
||||
GNUPG_GET_ITERATOR(intern, this);
|
||||
|
||||
if(intern->gpgkey!=NULL){
|
||||
RETURN_TRUE;
|
||||
}else{
|
||||
RETURN_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Local variables:
|
||||
* tab-width: 4
|
||||
|
|
196
gnupg_keylistiterator.c
Normal file
196
gnupg_keylistiterator.c
Normal file
|
@ -0,0 +1,196 @@
|
|||
/*
|
||||
+----------------------------------------------------------------------+
|
||||
| PHP Version 5 |
|
||||
+----------------------------------------------------------------------+
|
||||
| Copyright (c) 1997-2004 The PHP Group |
|
||||
+----------------------------------------------------------------------+
|
||||
| This source file is subject to version 3.0 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_0.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: Thilo Raufeisen <traufeisen@php.net> |
|
||||
+----------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "php.h"
|
||||
#include "php_ini.h"
|
||||
#include "ext/standard/info.h"
|
||||
#include "zend_interfaces.h"
|
||||
#include "php_gnupg.h"
|
||||
#include "php_gnupg_keylistiterator.h"
|
||||
|
||||
static int le_gnupg_keylistiterator;
|
||||
|
||||
static zend_object_handlers gnupg_keylistiterator_object_handlers;
|
||||
|
||||
/* {{{ defs */
|
||||
|
||||
#define GNUPG_GET_ITERATOR() \
|
||||
gnupg_keylistiterator_object *intern; \
|
||||
ze_gnupg_keylistiterator_object *obj = (ze_gnupg_keylistiterator_object*) zend_object_store_get_object(getThis() TSRMLS_CC); \
|
||||
intern = obj->gnupg_keylistiterator_ptr; \
|
||||
if(!intern){ \
|
||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid or unitialized gnupg iterator object"); \
|
||||
RETURN_FALSE; \
|
||||
}
|
||||
|
||||
/* }}} */
|
||||
|
||||
/* {{{ free_iterator_storage */
|
||||
static void gnupg_keylistiterator_object_free_storage(void *object TSRMLS_DC){
|
||||
ze_gnupg_keylistiterator_object *intern = (ze_gnupg_keylistiterator_object *) object;
|
||||
if(!intern){
|
||||
return;
|
||||
}
|
||||
if(intern->gnupg_keylistiterator_ptr){
|
||||
gpgme_op_keylist_end(intern->gnupg_keylistiterator_ptr->ctx);
|
||||
gpgme_key_release(intern->gnupg_keylistiterator_ptr->gpgkey);
|
||||
gpgme_release(intern->gnupg_keylistiterator_ptr->ctx);
|
||||
zval_dtor(&intern->gnupg_keylistiterator_ptr->pattern);
|
||||
efree(intern->gnupg_keylistiterator_ptr);
|
||||
}
|
||||
if(intern->zo.properties){
|
||||
zend_hash_destroy(intern->zo.properties);
|
||||
FREE_HASHTABLE(intern->zo.properties);
|
||||
}
|
||||
efree(intern);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ keylistiterator_objects_new */
|
||||
zend_object_value gnupg_keylistiterator_objects_new(zend_class_entry *class_type TSRMLS_DC){
|
||||
ze_gnupg_keylistiterator_object *intern;
|
||||
zend_object_value retval;
|
||||
gnupg_keylistiterator_object *gnupg_keylistiterator_ptr;
|
||||
gpgme_ctx_t ctx;
|
||||
|
||||
intern = emalloc(sizeof(ze_gnupg_keylistiterator_object));
|
||||
intern->zo.ce = class_type;
|
||||
intern->zo.in_get = 0;
|
||||
intern->zo.in_set = 0;
|
||||
intern->zo.properties = NULL;
|
||||
retval.handle = zend_objects_store_put(intern,NULL,(zend_objects_free_object_storage_t) gnupg_keylistiterator_object_free_storage,NULL TSRMLS_CC);
|
||||
retval.handlers = (zend_object_handlers *) & gnupg_keylistiterator_object_handlers;
|
||||
|
||||
gpgme_new(&ctx);
|
||||
gnupg_keylistiterator_ptr = emalloc(sizeof(gnupg_keylistiterator_object));
|
||||
gnupg_keylistiterator_ptr->ctx = ctx;
|
||||
|
||||
intern->gnupg_keylistiterator_ptr = gnupg_keylistiterator_ptr;
|
||||
|
||||
return retval;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ methodlist gnupg_keylistiterator */
|
||||
static zend_function_entry gnupg_keylistiterator_methods[] = {
|
||||
ZEND_ME(gnupg_keylistiterator, __construct, NULL, ZEND_ACC_PUBLIC)
|
||||
ZEND_ME(gnupg_keylistiterator, current, NULL, ZEND_ACC_PUBLIC)
|
||||
ZEND_ME(gnupg_keylistiterator, key, NULL, ZEND_ACC_PUBLIC)
|
||||
ZEND_ME(gnupg_keylistiterator, next, NULL, ZEND_ACC_PUBLIC)
|
||||
ZEND_ME(gnupg_keylistiterator, rewind, NULL, ZEND_ACC_PUBLIC)
|
||||
ZEND_ME(gnupg_keylistiterator, valid, NULL, ZEND_ACC_PUBLIC)
|
||||
{NULL, NULL, NULL}
|
||||
};
|
||||
/* }}} */
|
||||
|
||||
/* {{{ _gnupg_keylistiterator_init
|
||||
*/
|
||||
int _gnupg_keylistiterator_init(INIT_FUNC_ARGS)
|
||||
{
|
||||
zend_class_entry ce;
|
||||
|
||||
INIT_CLASS_ENTRY(ce, "gnupg_keylistiterator", gnupg_keylistiterator_methods);
|
||||
|
||||
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_DC, 1, zend_ce_iterator);
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
|
||||
PHP_FUNCTION(gnupg_keylistiterator___construct){
|
||||
zval *pattern;
|
||||
|
||||
int args = ZEND_NUM_ARGS();
|
||||
|
||||
GNUPG_GET_ITERATOR();
|
||||
|
||||
if(args > 0){
|
||||
if (zend_parse_parameters(args TSRMLS_CC, "|z", &pattern) == FAILURE){
|
||||
return;
|
||||
}
|
||||
intern->pattern = *pattern;
|
||||
zval_copy_ctor(&intern->pattern);
|
||||
}else{
|
||||
convert_to_string(&intern->pattern);
|
||||
}
|
||||
}
|
||||
PHP_FUNCTION(gnupg_keylistiterator_current){
|
||||
GNUPG_GET_ITERATOR();
|
||||
|
||||
RETURN_STRING(intern->gpgkey->uids[0].uid,1);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(gnupg_keylistiterator_key){
|
||||
GNUPG_GET_ITERATOR();
|
||||
|
||||
RETURN_STRING(intern->gpgkey->subkeys[0].fpr,1);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(gnupg_keylistiterator_next){
|
||||
GNUPG_GET_ITERATOR();
|
||||
|
||||
if(intern->err = gpgme_op_keylist_next(intern->ctx, &intern->gpgkey)){
|
||||
gpgme_key_release(intern->gpgkey);
|
||||
intern->gpgkey = NULL;
|
||||
}
|
||||
RETURN_TRUE;
|
||||
}
|
||||
|
||||
PHP_FUNCTION(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(),gpg_strerror(intern->err),1 TSRMLS_CC);
|
||||
}
|
||||
if((intern->err = gpgme_op_keylist_next(intern->ctx, &intern->gpgkey))!=GPG_ERR_NO_ERROR){
|
||||
RETURN_FALSE;
|
||||
}
|
||||
RETURN_TRUE;
|
||||
}
|
||||
|
||||
PHP_FUNCTION(gnupg_keylistiterator_valid){
|
||||
GNUPG_GET_ITERATOR();
|
||||
|
||||
if(intern->gpgkey!=NULL){
|
||||
RETURN_TRUE;
|
||||
}else{
|
||||
RETURN_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 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
|
||||
*/
|
|
@ -16,7 +16,7 @@ So you can sign, encrypt, verify directly from php
|
|||
</maintainers>
|
||||
<release>
|
||||
<version>0.2</version>
|
||||
<date>2005-10-09</date>
|
||||
<date>2005-10-10</date>
|
||||
<license>PHP License</license>
|
||||
<state>beta</state>
|
||||
<notes>added keylistiterator, encryptsign and decryptverify
|
||||
|
@ -30,7 +30,9 @@ So you can sign, encrypt, verify directly from php
|
|||
<file role="doc" name="README"/>
|
||||
<file role="src" name="config.m4"/>
|
||||
<file role="src" name="php_gnupg.h"/>
|
||||
<file role="src" name="php_gnupg_keylistiterator.h" />
|
||||
<file role="src" name="gnupg.c"/>
|
||||
<file role="src" name="gnupg_keylistiterator.c" />
|
||||
<file role="doc" name="examples/main.php"/>
|
||||
<file role="doc" name="examples/clearsign.php"/>
|
||||
<file role="doc" name="examples/verify.php"/>
|
||||
|
@ -43,7 +45,7 @@ So you can sign, encrypt, verify directly from php
|
|||
<changelog>
|
||||
<release>
|
||||
<version>0.2</version>
|
||||
<date>2005-10-09</date>
|
||||
<date>2005-10-10</date>
|
||||
<state>beta</state>
|
||||
<notes>added keylistiterator, encryptsign and decryptverify</notes>
|
||||
</release>
|
||||
|
|
|
@ -16,8 +16,8 @@ So you can sign, encrypt, verify directly from php
|
|||
<email>traufeisen@php.net</email>
|
||||
<active>yes</active>
|
||||
</lead>
|
||||
<date>2005-10-09</date>
|
||||
<time>17:39:05</time>
|
||||
<date>2005-10-10</date>
|
||||
<time>19:34:14</time>
|
||||
<version>
|
||||
<release>0.2</release>
|
||||
<api>0.2</api>
|
||||
|
@ -44,8 +44,10 @@ So you can sign, encrypt, verify directly from php
|
|||
<file name="config.m4" role="src" />
|
||||
<file name="EXPERIMENTAL" role="doc" />
|
||||
<file name="gnupg.c" role="src" />
|
||||
<file name="gnupg_keylistiterator.c" role="src" />
|
||||
<file name="LICENSE" role="doc" />
|
||||
<file name="php_gnupg.h" role="src" />
|
||||
<file name="php_gnupg_keylistiterator.h" role="src" />
|
||||
<file name="README" role="doc" />
|
||||
</dir> <!-- / -->
|
||||
</contents>
|
||||
|
@ -71,7 +73,7 @@ So you can sign, encrypt, verify directly from php
|
|||
<release>beta</release>
|
||||
<api>beta</api>
|
||||
</stability>
|
||||
<date>2005-10-09</date>
|
||||
<date>2005-10-10</date>
|
||||
<license uri="http://www.php.net/license">PHP License</license>
|
||||
<notes>added keylistiterator, encryptsign and decryptverify
|
||||
</notes>
|
||||
|
|
21
php_gnupg.h
21
php_gnupg.h
|
@ -22,7 +22,6 @@
|
|||
#define PHP_GNUPG_H
|
||||
|
||||
extern zend_module_entry gnupg_module_entry;
|
||||
extern zend_module_entry gnupg_keyiterator_module_entry;
|
||||
#define phpext_gnupg_ptr &gnupg_module_entry
|
||||
|
||||
#ifdef PHP_WIN32
|
||||
|
@ -50,20 +49,7 @@ typedef struct _ze_gnupg_object{
|
|||
gnupg_object *gnupg_ptr;
|
||||
} ze_gnupg_object;
|
||||
|
||||
typedef struct _gnupg_keylistiterator_object{
|
||||
gpgme_ctx_t ctx;
|
||||
gpgme_error_t err;
|
||||
gpgme_key_t gpgkey;
|
||||
zval pattern;
|
||||
} gnupg_keylistiterator_object;
|
||||
|
||||
typedef struct _ze_gnupg_keylistiterator_object{
|
||||
zend_object zo;
|
||||
gnupg_keylistiterator_object *gnupg_keylistiterator_ptr;
|
||||
} ze_gnupg_keylistiterator_object;
|
||||
|
||||
zend_class_entry *gnupg_class_entry;
|
||||
zend_class_entry *gnupg_keylistiterator_class_entry;
|
||||
|
||||
PHP_MINIT_FUNCTION(gnupg);
|
||||
PHP_MSHUTDOWN_FUNCTION(gnupg);
|
||||
|
@ -87,13 +73,6 @@ PHP_FUNCTION(gnupg_decrypt);
|
|||
PHP_FUNCTION(gnupg_decryptverify);
|
||||
PHP_FUNCTION(gnupg_export);
|
||||
|
||||
PHP_FUNCTION(gnupg_keylistiterator_construct);
|
||||
PHP_FUNCTION(gnupg_keylistiterator_current);
|
||||
PHP_FUNCTION(gnupg_keylistiterator_next);
|
||||
PHP_FUNCTION(gnupg_keylistiterator_rewind);
|
||||
PHP_FUNCTION(gnupg_keylistiterator_key);
|
||||
PHP_FUNCTION(gnupg_keylistiterator_valid);
|
||||
|
||||
#ifdef ZTS
|
||||
#define GNUPG_G(v) TSRMG(gnupg_globals_id, zend_gnupg_globals *, v)
|
||||
#else
|
||||
|
|
78
php_gnupg_keylistiterator.h
Normal file
78
php_gnupg_keylistiterator.h
Normal file
|
@ -0,0 +1,78 @@
|
|||
/*
|
||||
+----------------------------------------------------------------------+
|
||||
| PHP Version 5 |
|
||||
+----------------------------------------------------------------------+
|
||||
| Copyright (c) 1997-2004 The PHP Group |
|
||||
+----------------------------------------------------------------------+
|
||||
| This source file is subject to version 3.0 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_0.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: Thilo Raufeisen |
|
||||
+----------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
#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>
|
||||
|
||||
#define gnupg_keylistiterator_init() _gnupg_keylistiterator_init(INIT_FUNC_ARGS_PASSTHRU)
|
||||
extern int _gnupg_keylistiterator_init(INIT_FUNC_ARGS);
|
||||
|
||||
typedef struct _gnupg_keylistiterator_object{
|
||||
gpgme_ctx_t ctx;
|
||||
gpgme_error_t err;
|
||||
gpgme_key_t gpgkey;
|
||||
zval pattern;
|
||||
} gnupg_keylistiterator_object;
|
||||
|
||||
typedef struct _ze_gnupg_keylistiterator_object{
|
||||
zend_object zo;
|
||||
gnupg_keylistiterator_object *gnupg_keylistiterator_ptr;
|
||||
} ze_gnupg_keylistiterator_object;
|
||||
|
||||
zend_class_entry *gnupg_keylistiterator_class_entry;
|
||||
|
||||
PHP_FUNCTION(gnupg_keylistiterator___construct);
|
||||
PHP_FUNCTION(gnupg_keylistiterator_current);
|
||||
PHP_FUNCTION(gnupg_keylistiterator_next);
|
||||
PHP_FUNCTION(gnupg_keylistiterator_rewind);
|
||||
PHP_FUNCTION(gnupg_keylistiterator_key);
|
||||
PHP_FUNCTION(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 */
|
||||
|
||||
|
||||
/*
|
||||
* 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
|
||||
*/
|
Loading…
Reference in a new issue