2005-10-10 17:37:19 +00:00
|
|
|
/*
|
2005-11-29 20:54:36 +00:00
|
|
|
+--------------------------------------------------------------------+
|
|
|
|
| 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. |
|
|
|
|
+--------------------------------------------------------------------+
|
2006-03-16 15:52:43 +00:00
|
|
|
| Copyright (c) 2006, Thilo Raufeisen <traufeisen@php.net> |
|
2005-11-29 20:54:36 +00:00
|
|
|
+--------------------------------------------------------------------+
|
2005-10-10 17:37:19 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* $Id$ */
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "php.h"
|
2005-10-18 12:40:03 +00:00
|
|
|
|
|
|
|
#ifdef ZEND_ENGINE_2
|
|
|
|
|
2005-10-10 17:37:19 +00:00
|
|
|
#include "php_ini.h"
|
|
|
|
#include "ext/standard/info.h"
|
|
|
|
#include "zend_interfaces.h"
|
2012-01-29 02:38:33 +00:00
|
|
|
#include "zend_exceptions.h"
|
2005-10-10 17:37:19 +00:00
|
|
|
#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() \
|
2005-11-10 20:24:27 +00:00
|
|
|
zval *this = getThis(); \
|
2005-10-10 17:37:19 +00:00
|
|
|
gnupg_keylistiterator_object *intern; \
|
2005-11-10 20:24:27 +00:00
|
|
|
if(this){ \
|
|
|
|
intern = (gnupg_keylistiterator_object*) zend_object_store_get_object(getThis() TSRMLS_CC); \
|
|
|
|
if(!intern){ \
|
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid or unitialized gnupg object"); \
|
|
|
|
RETURN_FALSE; \
|
|
|
|
} \
|
|
|
|
}
|
2005-10-10 17:37:19 +00:00
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ free_iterator_storage */
|
2005-11-10 20:24:27 +00:00
|
|
|
static void gnupg_keylistiterator_dtor(gnupg_keylistiterator_object *intern TSRMLS_DC){
|
2005-10-10 17:37:19 +00:00
|
|
|
if(!intern){
|
|
|
|
return;
|
|
|
|
}
|
2005-11-10 20:24:27 +00:00
|
|
|
gpgme_op_keylist_end(intern->ctx);
|
|
|
|
gpgme_key_release(intern->gpgkey);
|
|
|
|
gpgme_release(intern->ctx);
|
|
|
|
/*
|
|
|
|
zval_dtor(&intern->pattern);
|
|
|
|
*/
|
2005-10-10 17:37:19 +00:00
|
|
|
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){
|
2005-11-10 20:24:27 +00:00
|
|
|
gnupg_keylistiterator_object *intern;
|
2005-10-10 17:37:19 +00:00
|
|
|
zend_object_value retval;
|
|
|
|
gpgme_ctx_t ctx;
|
|
|
|
|
2005-11-10 20:24:27 +00:00
|
|
|
intern = emalloc(sizeof(gnupg_keylistiterator_object));
|
2005-10-10 17:37:19 +00:00
|
|
|
intern->zo.ce = class_type;
|
|
|
|
intern->zo.properties = NULL;
|
2005-11-10 20:24:27 +00:00
|
|
|
retval.handle = zend_objects_store_put(intern,NULL,(zend_objects_free_object_storage_t) gnupg_keylistiterator_dtor,NULL TSRMLS_CC);
|
2005-10-10 17:37:19 +00:00
|
|
|
retval.handlers = (zend_object_handlers *) & gnupg_keylistiterator_object_handlers;
|
|
|
|
|
|
|
|
gpgme_new(&ctx);
|
2005-11-10 20:24:27 +00:00
|
|
|
intern->ctx = ctx;
|
2005-10-10 17:37:19 +00:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ methodlist gnupg_keylistiterator */
|
|
|
|
static zend_function_entry gnupg_keylistiterator_methods[] = {
|
2006-11-03 12:38:35 +00:00
|
|
|
PHP_ME(gnupg_keylistiterator, __construct, NULL, ZEND_ACC_PUBLIC)
|
|
|
|
PHP_ME(gnupg_keylistiterator, current, NULL, ZEND_ACC_PUBLIC)
|
|
|
|
PHP_ME(gnupg_keylistiterator, key, NULL, ZEND_ACC_PUBLIC)
|
|
|
|
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)
|
2005-10-10 17:37:19 +00:00
|
|
|
{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);
|
|
|
|
|
2005-11-12 18:35:08 +00:00
|
|
|
zend_class_implements (gnupg_keylistiterator_class_entry TSRMLS_CC, 1, zend_ce_iterator);
|
2005-10-10 17:37:19 +00:00
|
|
|
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
2006-11-03 12:38:35 +00:00
|
|
|
PHP_METHOD(gnupg_keylistiterator,__construct){
|
2005-10-10 17:37:19 +00:00
|
|
|
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{
|
2005-11-10 20:24:27 +00:00
|
|
|
ZVAL_EMPTY_STRING(&intern->pattern);
|
2005-10-10 17:37:19 +00:00
|
|
|
}
|
|
|
|
}
|
2006-11-03 12:38:35 +00:00
|
|
|
PHP_METHOD(gnupg_keylistiterator,current){
|
2005-10-10 17:37:19 +00:00
|
|
|
GNUPG_GET_ITERATOR();
|
|
|
|
|
|
|
|
RETURN_STRING(intern->gpgkey->uids[0].uid,1);
|
|
|
|
}
|
|
|
|
|
2006-11-03 12:38:35 +00:00
|
|
|
PHP_METHOD(gnupg_keylistiterator,key){
|
2005-10-10 17:37:19 +00:00
|
|
|
GNUPG_GET_ITERATOR();
|
|
|
|
|
|
|
|
RETURN_STRING(intern->gpgkey->subkeys[0].fpr,1);
|
|
|
|
}
|
|
|
|
|
2006-11-03 12:38:35 +00:00
|
|
|
PHP_METHOD(gnupg_keylistiterator,next){
|
2005-10-10 17:37:19 +00:00
|
|
|
GNUPG_GET_ITERATOR();
|
|
|
|
|
2005-11-10 20:24:27 +00:00
|
|
|
if(intern->gpgkey){
|
|
|
|
gpgme_key_release(intern->gpgkey);
|
|
|
|
}
|
|
|
|
|
2012-01-29 02:38:33 +00:00
|
|
|
if((intern->err = gpgme_op_keylist_next(intern->ctx, &intern->gpgkey))){
|
2005-10-10 17:37:19 +00:00
|
|
|
gpgme_key_release(intern->gpgkey);
|
|
|
|
intern->gpgkey = NULL;
|
|
|
|
}
|
|
|
|
RETURN_TRUE;
|
|
|
|
}
|
|
|
|
|
2006-11-03 12:38:35 +00:00
|
|
|
PHP_METHOD(gnupg_keylistiterator,rewind){
|
2005-10-10 17:37:19 +00:00
|
|
|
GNUPG_GET_ITERATOR();
|
|
|
|
|
|
|
|
if((intern->err = gpgme_op_keylist_start(intern->ctx, Z_STRVAL(intern->pattern), 0)) != GPG_ERR_NO_ERROR){
|
2012-01-29 02:38:33 +00:00
|
|
|
zend_throw_exception(zend_exception_get_default(TSRMLS_C),gpg_strerror(intern->err),1 TSRMLS_CC);
|
2005-10-10 17:37:19 +00:00
|
|
|
}
|
|
|
|
if((intern->err = gpgme_op_keylist_next(intern->ctx, &intern->gpgkey))!=GPG_ERR_NO_ERROR){
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
RETURN_TRUE;
|
|
|
|
}
|
|
|
|
|
2006-11-03 12:38:35 +00:00
|
|
|
PHP_METHOD(gnupg_keylistiterator,valid){
|
2005-10-10 17:37:19 +00:00
|
|
|
GNUPG_GET_ITERATOR();
|
|
|
|
|
|
|
|
if(intern->gpgkey!=NULL){
|
|
|
|
RETURN_TRUE;
|
|
|
|
}else{
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
}
|
2005-10-18 12:40:03 +00:00
|
|
|
#endif /* ZEND_ENGINE_2 */
|
2005-10-10 17:37:19 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
*/
|