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> |
|
2013-07-08 14:11:30 +00:00
|
|
|
| Copyright (c) 2013, Jim Jagielski <jimjag@php.net> |
|
2016-05-22 17:52:23 +00:00
|
|
|
| Copyright (c) 2016, Jakub Zelenka <bukka@php.net> |
|
2005-11-29 20:54:36 +00:00
|
|
|
+--------------------------------------------------------------------+
|
2005-10-10 17:37:19 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2016-05-22 17:52:23 +00:00
|
|
|
#include <stddef.h>
|
2005-10-18 12:40:03 +00:00
|
|
|
|
2016-05-22 17:52:23 +00:00
|
|
|
#include "php.h"
|
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"
|
2016-05-22 17:52:23 +00:00
|
|
|
#include "phpc/phpc.h"
|
2005-10-10 17:37:19 +00:00
|
|
|
|
|
|
|
static int le_gnupg_keylistiterator;
|
|
|
|
|
2016-05-22 17:52:23 +00:00
|
|
|
static zend_class_entry *gnupg_keylistiterator_class_entry;
|
2005-10-10 17:37:19 +00:00
|
|
|
|
2016-05-22 17:52:23 +00:00
|
|
|
PHPC_OBJ_DEFINE_HANDLER_VAR(gnupg_keylistiterator);
|
|
|
|
|
|
|
|
/* {{{ GNUPG_GET_ITERATOR */
|
2005-10-10 17:37:19 +00:00
|
|
|
#define GNUPG_GET_ITERATOR() \
|
2016-05-22 17:52:23 +00:00
|
|
|
zval *this = getThis(); \
|
|
|
|
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)
|
2005-10-10 17:37:19 +00:00
|
|
|
/* }}} */
|
|
|
|
|
2016-05-22 17:52:23 +00:00
|
|
|
/* {{{ free gnupg_keylistiterator */
|
|
|
|
PHPC_OBJ_HANDLER_FREE(gnupg_keylistiterator)
|
|
|
|
{
|
|
|
|
PHPC_OBJ_HANDLER_FREE_INIT(gnupg_keylistiterator);
|
2015-12-27 06:44:02 +00:00
|
|
|
|
2016-05-22 17:52:23 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
PHPC_OBJ_HANDLER_FREE_DESTROY();
|
2005-10-10 17:37:19 +00:00
|
|
|
}
|
|
|
|
|
2016-05-22 17:52:23 +00:00
|
|
|
/* {{{ create_ex gnupg_keylistiterator */
|
|
|
|
PHPC_OBJ_HANDLER_CREATE_EX(gnupg_keylistiterator)
|
|
|
|
{
|
|
|
|
PHPC_OBJ_HANDLER_CREATE_EX_INIT(gnupg_keylistiterator);
|
2005-10-10 17:37:19 +00:00
|
|
|
|
2016-05-22 17:52:23 +00:00
|
|
|
gpgme_check_version(NULL);
|
2015-12-27 06:44:02 +00:00
|
|
|
|
2016-05-22 17:52:23 +00:00
|
|
|
gpgme_new(&PHPC_THIS->ctx);
|
|
|
|
PHPC_THIS->err = 0;
|
|
|
|
PHPC_THIS->gpgkey = NULL;
|
|
|
|
PHPC_THIS->pattern = NULL;
|
2005-10-10 17:37:19 +00:00
|
|
|
|
2016-05-22 17:52:23 +00:00
|
|
|
PHPC_OBJ_HANDLER_CREATE_EX_RETURN(gnupg_keylistiterator);
|
2005-10-10 17:37:19 +00:00
|
|
|
}
|
|
|
|
|
2016-05-22 17:52:23 +00:00
|
|
|
/* {{{ create gnupg_keylistiterator */
|
|
|
|
PHPC_OBJ_HANDLER_CREATE(gnupg_keylistiterator)
|
|
|
|
{
|
|
|
|
PHPC_OBJ_HANDLER_CREATE_RETURN(gnupg_keylistiterator);
|
|
|
|
}
|
|
|
|
|
2021-01-03 15:15:01 +00:00
|
|
|
|
|
|
|
/* {{{ arginfo for gnupg void iterator method */
|
|
|
|
ZEND_BEGIN_ARG_INFO_EX(arginfo_gnupg_void_iterator_method, 0, 0, 0)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
/* }}} */
|
|
|
|
|
2016-05-22 17:52:23 +00:00
|
|
|
/* {{{ method list gnupg_keylistiterator */
|
2005-10-10 17:37:19 +00:00
|
|
|
static zend_function_entry gnupg_keylistiterator_methods[] = {
|
2021-01-03 15:15:01 +00:00
|
|
|
PHP_ME(gnupg_keylistiterator, __construct, arginfo_gnupg_void_iterator_method, ZEND_ACC_PUBLIC)
|
|
|
|
PHP_ME(gnupg_keylistiterator, current, arginfo_gnupg_void_iterator_method, ZEND_ACC_PUBLIC)
|
|
|
|
PHP_ME(gnupg_keylistiterator, key, arginfo_gnupg_void_iterator_method, ZEND_ACC_PUBLIC)
|
|
|
|
PHP_ME(gnupg_keylistiterator, next, arginfo_gnupg_void_iterator_method, ZEND_ACC_PUBLIC)
|
|
|
|
PHP_ME(gnupg_keylistiterator, rewind, arginfo_gnupg_void_iterator_method, ZEND_ACC_PUBLIC)
|
|
|
|
PHP_ME(gnupg_keylistiterator, valid, arginfo_gnupg_void_iterator_method, ZEND_ACC_PUBLIC)
|
2016-05-22 17:52:23 +00:00
|
|
|
PHPC_FE_END
|
2005-10-10 17:37:19 +00:00
|
|
|
};
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ _gnupg_keylistiterator_init
|
|
|
|
*/
|
|
|
|
int _gnupg_keylistiterator_init(INIT_FUNC_ARGS)
|
|
|
|
{
|
2015-12-27 06:44:02 +00:00
|
|
|
zend_class_entry ce;
|
|
|
|
|
2016-05-22 17:52:23 +00:00
|
|
|
/* init class */
|
2005-10-10 17:37:19 +00:00
|
|
|
INIT_CLASS_ENTRY(ce, "gnupg_keylistiterator", gnupg_keylistiterator_methods);
|
2016-05-22 17:52:23 +00:00
|
|
|
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);
|
2015-12-27 06:44:02 +00:00
|
|
|
|
2016-05-22 17:52:23 +00:00
|
|
|
zend_class_implements(gnupg_keylistiterator_class_entry TSRMLS_CC, 1, zend_ce_iterator);
|
2015-12-27 06:44:02 +00:00
|
|
|
|
2016-05-22 17:52:23 +00:00
|
|
|
le_gnupg_keylistiterator = zend_register_list_destructors_ex(NULL, NULL, "ctx_keylistiterator", module_number);
|
2015-12-27 06:44:02 +00:00
|
|
|
|
2005-10-10 17:37:19 +00:00
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2016-05-22 17:52:23 +00:00
|
|
|
/* {{{ proto __contruct(string $pattern)
|
|
|
|
* constructs keylistiterator with supplied pattern
|
|
|
|
*/
|
|
|
|
PHP_METHOD(gnupg_keylistiterator, __construct)
|
|
|
|
{
|
|
|
|
char *pattern = NULL;
|
|
|
|
phpc_str_size_t pattern_len;
|
2005-10-10 17:37:19 +00:00
|
|
|
|
|
|
|
int args = ZEND_NUM_ARGS();
|
|
|
|
|
|
|
|
GNUPG_GET_ITERATOR();
|
|
|
|
|
2016-05-22 17:52:23 +00:00
|
|
|
if (args > 0) {
|
|
|
|
if (zend_parse_parameters(args TSRMLS_CC, "|s", &pattern, &pattern_len) == FAILURE) {
|
2005-10-10 17:37:19 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-05-22 17:52:23 +00:00
|
|
|
PHPC_THIS->pattern = estrdup(pattern);
|
2005-10-10 17:37:19 +00:00
|
|
|
}
|
|
|
|
}
|
2016-05-22 17:52:23 +00:00
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ proto string current() */
|
2021-01-03 15:15:01 +00:00
|
|
|
PHP_METHOD(gnupg_keylistiterator, current)
|
2016-05-22 17:52:23 +00:00
|
|
|
{
|
2005-10-10 17:37:19 +00:00
|
|
|
GNUPG_GET_ITERATOR();
|
2015-12-27 06:44:02 +00:00
|
|
|
|
2016-05-22 17:52:23 +00:00
|
|
|
PHPC_CSTR_RETURN(PHPC_THIS->gpgkey->uids[0].uid);
|
2005-10-10 17:37:19 +00:00
|
|
|
}
|
2016-05-22 17:52:23 +00:00
|
|
|
/* }}} */
|
2005-10-10 17:37:19 +00:00
|
|
|
|
2016-05-22 17:52:23 +00:00
|
|
|
/* {{{ proto string key() */
|
2021-01-03 15:15:01 +00:00
|
|
|
PHP_METHOD(gnupg_keylistiterator, key)
|
2016-05-22 17:52:23 +00:00
|
|
|
{
|
|
|
|
GNUPG_GET_ITERATOR();
|
2015-12-27 06:44:02 +00:00
|
|
|
|
2016-05-22 17:52:23 +00:00
|
|
|
PHPC_CSTR_RETURN(PHPC_THIS->gpgkey->subkeys[0].fpr);
|
2005-10-10 17:37:19 +00:00
|
|
|
}
|
2016-05-22 17:52:23 +00:00
|
|
|
/* }}} */
|
2005-10-10 17:37:19 +00:00
|
|
|
|
2016-05-22 17:52:23 +00:00
|
|
|
/* {{{ proto bool next() */
|
2021-01-03 15:15:01 +00:00
|
|
|
PHP_METHOD(gnupg_keylistiterator, next)
|
2016-05-22 17:52:23 +00:00
|
|
|
{
|
2005-10-10 17:37:19 +00:00
|
|
|
GNUPG_GET_ITERATOR();
|
|
|
|
|
2016-05-22 17:52:23 +00:00
|
|
|
if (PHPC_THIS->gpgkey){
|
|
|
|
gpgme_key_release(PHPC_THIS->gpgkey);
|
2005-11-10 20:24:27 +00:00
|
|
|
}
|
|
|
|
|
2016-05-22 17:52:23 +00:00
|
|
|
if ((PHPC_THIS->err = gpgme_op_keylist_next(PHPC_THIS->ctx, &PHPC_THIS->gpgkey))) {
|
|
|
|
gpgme_key_release(PHPC_THIS->gpgkey);
|
|
|
|
PHPC_THIS->gpgkey = NULL;
|
2005-10-10 17:37:19 +00:00
|
|
|
}
|
|
|
|
RETURN_TRUE;
|
|
|
|
}
|
2016-05-22 17:52:23 +00:00
|
|
|
/* }}} */
|
2005-10-10 17:37:19 +00:00
|
|
|
|
2016-05-22 17:52:23 +00:00
|
|
|
/* {{{ proto bool rewind() */
|
2021-01-03 15:15:01 +00:00
|
|
|
PHP_METHOD(gnupg_keylistiterator, rewind)
|
2016-05-22 17:52:23 +00:00
|
|
|
{
|
2005-10-10 17:37:19 +00:00
|
|
|
GNUPG_GET_ITERATOR();
|
|
|
|
|
2016-05-22 17:52:23 +00:00
|
|
|
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);
|
2005-10-10 17:37:19 +00:00
|
|
|
}
|
2016-05-22 17:52:23 +00:00
|
|
|
if ((PHPC_THIS->err = gpgme_op_keylist_next(PHPC_THIS->ctx, &PHPC_THIS->gpgkey)) != GPG_ERR_NO_ERROR){
|
2005-10-10 17:37:19 +00:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
RETURN_TRUE;
|
|
|
|
}
|
2016-05-22 17:52:23 +00:00
|
|
|
/* }}} */
|
2005-10-10 17:37:19 +00:00
|
|
|
|
2016-05-22 17:52:23 +00:00
|
|
|
/* {{{ proto bool valid() */
|
|
|
|
PHP_METHOD(gnupg_keylistiterator,valid)
|
|
|
|
{
|
2005-10-10 17:37:19 +00:00
|
|
|
GNUPG_GET_ITERATOR();
|
|
|
|
|
2016-05-22 17:52:23 +00:00
|
|
|
if (PHPC_THIS->gpgkey != NULL) {
|
2005-10-10 17:37:19 +00:00
|
|
|
RETURN_TRUE;
|
2016-05-22 17:52:23 +00:00
|
|
|
} else {
|
2005-10-10 17:37:19 +00:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
}
|
2016-05-22 17:52:23 +00:00
|
|
|
/* }}} */
|
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
|
|
|
|
*/
|