diff --git a/config.m4 b/config.m4 index 3389e5c..62508bb 100644 --- a/config.m4 +++ b/config.m4 @@ -2,7 +2,7 @@ dnl $Id$ dnl config.m4 for extension gnupg PHP_ARG_WITH(gnupg, for gnupg support, -[ --with-gnupg[=DIR] Include gnupg support]) +[ --with-gnupg[=dir] Include gnupg support]) if test "$PHP_GNUPG" != "no"; then SEARCH_PATH="/usr/local/include /usr/include /usr/local/include/gpgme/ /usr/include/gpgme/" diff --git a/gnupg.c b/gnupg.c index 692143a..ab718fd 100644 --- a/gnupg.c +++ b/gnupg.c @@ -6,7 +6,7 @@ | modification, are permitted provided that the conditions mentioned | | in the accompanying LICENSE file are met. | +--------------------------------------------------------------------+ - | Copyright (c) 2005, Thilo Raufeisen | + | Copyright (c) 2006, Thilo Raufeisen | +--------------------------------------------------------------------+ */ @@ -27,24 +27,26 @@ static int le_gnupg; -#define PHP_GNUPG_VERSION "0.7beta" +#define PHP_GNUPG_VERSION "1.1" #ifdef ZEND_ENGINE_2 static zend_object_handlers gnupg_object_handlers; #endif /* {{{ defs */ +#ifdef ZEND_ENGINE_2 + #define GNUPG_GETOBJ() \ - zval *this = getThis(); \ - gnupg_object *intern; \ - zval *res; \ - if(this){ \ - intern = (gnupg_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; \ - } \ - } + zval *this = getThis(); \ + gnupg_object *intern; \ + zval *res; \ + if(this){ \ + intern = (gnupg_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; \ + } \ + } #define GNUPG_ERR(error) \ if(intern){ \ @@ -61,7 +63,26 @@ static zend_object_handlers gnupg_object_handlers; }else{ \ php_error_docref(NULL TSRMLS_CC, E_WARNING, (char*)error); \ } \ - RETVAL_FALSE; + if(return_value){ \ + RETVAL_FALSE; \ + } +#else +#define GNUPG_ERR(error) \ + if(intern && intern->errormode!=1) { \ + intern->errortxt = (char*)error; \ + }else{ \ + php_error_docref(NULL TSRMLS_CC, E_WARNING, (char*)error); \ + } \ + if(return_value){ \ + RETVAL_FALSE; \ + } + +#define GNUPG_GETOBJ() \ + zval *this = NULL; \ + zval *res; \ + gnupg_object *intern; + +#endif /* }}} */ /* {{{ free encryptkeys */ @@ -196,7 +217,24 @@ static zend_function_entry gnupg_methods[] = { ZEND_ME(gnupg, seterrormode, NULL, ZEND_ACC_PUBLIC) {NULL, NULL, NULL} }; +/* }}} */ + +/* {{{ class constants */ +static void gnupg_declare_long_constant(const char *const_name, long value TSRMLS_DC){ +#if PHP_MAJOR_VERSION > 5 || PHP_MINOR_VERSION >= 1 + zend_declare_class_constant_long(gnupg_class_entry, (char*)const_name, strlen(const_name), value TSRMLS_CC); +#else + zval *constant = malloc(sizeof(*constant)); + ZVAL_LONG(constant,value); + INIT_PZVAL(constant); + zend_hash_update(&gnupg_class_entry->constants_table, (char*)const_name, strlen(const_name)+1, &constant, sizeof(zval*), NULL); +#endif +} +/* }}} */ + #endif /* ZEND_ENGINE_2 */ + +/* {{{ functionlist gnupg */ static zend_function_entry gnupg_functions[] = { PHP_FE(gnupg_init, NULL) PHP_FE(gnupg_keyinfo, NULL) @@ -226,20 +264,6 @@ static zend_function_entry gnupg_functions[] = { }; /* }}} */ -/* {{{ class constants */ -static void gnupg_declare_long_constant(const char *const_name, long value TSRMLS_DC){ -#if PHP_MAJOR_VERSION > 5 || PHP_MINOR_VERSION >= 1 - zend_declare_class_constant_long(gnupg_class_entry, (char*)const_name, strlen(const_name), value TSRMLS_CC); -#else - zval *constant = malloc(sizeof(*constant)); - ZVAL_LONG(constant,value); - INIT_PZVAL(constant); - zend_hash_update(&gnupg_class_entry->constants_table, (char*)const_name, strlen(const_name)+1, &constant, sizeof(zval*), NULL); -#endif - -} -/* }}} */ - /* {{{ gnupg_module_entry */ zend_module_entry gnupg_module_entry = { @@ -359,9 +383,10 @@ gpgme_error_t passphrase_cb (gnupg_object *intern, const char *uid_hint, const c char uid[16]; int idx; char *passphrase = NULL; + zval *return_value = NULL; if(last_was_bad){ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Incorrent passphrase"); + GNUPG_ERR("Incorrent passphrase"); return 1; } for(idx=0;idx<16;idx++){ @@ -369,11 +394,11 @@ gpgme_error_t passphrase_cb (gnupg_object *intern, const char *uid_hint, const c } uid[16] = '\0'; if(zend_hash_find(intern->signkeys,(char *) uid,17,(void **) &passphrase)==FAILURE){ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "no passphrase set"); + GNUPG_ERR("no passphrase set"); return 1; } if(!passphrase){ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "no passphrase set"); + GNUPG_ERR("no passphrase set"); return 1; } @@ -386,9 +411,10 @@ gpgme_error_t passphrase_decrypt_cb (gnupg_object *intern, const char *uid_hint, char uid[16]; int idx; char *passphrase = NULL; + zval *return_value = NULL; if(last_was_bad){ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Incorrent passphrase"); + GNUPG_ERR("Incorrent passphrase"); return 1; } for(idx=0;idx<16;idx++){ @@ -396,11 +422,11 @@ gpgme_error_t passphrase_decrypt_cb (gnupg_object *intern, const char *uid_hint, } uid[16] = '\0'; if(zend_hash_find(intern->decryptkeys,(char *) uid,17,(void **) &passphrase)==FAILURE){ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "no passphrase set"); + GNUPG_ERR("no passphrase set"); return 1; } if(!passphrase){ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "no passphrase set"); + GNUPG_ERR("no passphrase set"); return 1; } write (fd, passphrase, strlen(passphrase)); @@ -880,9 +906,12 @@ PHP_FUNCTION(gnupg_sign){ return; } if((intern->err = gpgme_op_sign(intern->ctx, in, out, intern->signmode))!=GPG_ERR_NO_ERROR){ - GNUPG_ERR("data signing failed"); + if(!intern->errortxt){ + GNUPG_ERR("data signing failed"); + } gpgme_data_release(in); gpgme_data_release(out); + RETVAL_FALSE; return; } result = gpgme_op_sign_result (intern->ctx); @@ -1015,9 +1044,12 @@ PHP_FUNCTION(gnupg_encryptsign){ return; } if((intern->err = gpgme_op_encrypt_sign(intern->ctx, intern->encryptkeys, GPGME_ENCRYPT_ALWAYS_TRUST, in, out))!=GPG_ERR_NO_ERROR){ - GNUPG_ERR("encrypt-sign failed"); + if(!intern->errortxt){ + GNUPG_ERR("encrypt-sign failed"); + } gpgme_data_release(in); gpgme_data_release(out); + RETVAL_FALSE; return; } @@ -1096,7 +1128,7 @@ PHP_FUNCTION(gnupg_verify){ }else{ /* no separate signature was passed * so we assume that it is a clearsigned message - * text no becomes the signature + * text now becomes the signature * creating the text-databuffer is still needed */ if((intern->err = gpgme_data_new_from_mem (&gpgme_sig, text, text_len, 0))!=GPG_ERR_NO_ERROR){ @@ -1169,9 +1201,12 @@ PHP_FUNCTION(gnupg_decrypt){ return; } if((intern->err = gpgme_op_decrypt (intern->ctx, in, out))!=GPG_ERR_NO_ERROR){ - GNUPG_ERR("decrypt failed"); + if(!intern->errortxt){ + GNUPG_ERR("decrypt failed"); + } gpgme_data_release(in); gpgme_data_release(out); + RETVAL_FALSE; return; } result = gpgme_op_decrypt_result (intern->ctx); @@ -1233,9 +1268,12 @@ PHP_FUNCTION(gnupg_decryptverify){ return; } if((intern->err = gpgme_op_decrypt_verify (intern->ctx, in, out))!=GPG_ERR_NO_ERROR){ - GNUPG_ERR("decrypt-verify failed"); + if(!intern->errortxt){ + GNUPG_ERR("decrypt-verify failed"); + } gpgme_data_release(in); gpgme_data_release(out); + RETVAL_FALSE; return; } userret = gpgme_data_release_and_get_mem(out,&ret_size); diff --git a/gnupg_keylistiterator.c b/gnupg_keylistiterator.c index 55a37f6..6228b48 100644 --- a/gnupg_keylistiterator.c +++ b/gnupg_keylistiterator.c @@ -6,7 +6,7 @@ | modification, are permitted provided that the conditions mentioned | | in the accompanying LICENSE file are met. | +--------------------------------------------------------------------+ - | Copyright (c) 2005, Thilo Raufeisen | + | Copyright (c) 2006, Thilo Raufeisen | +--------------------------------------------------------------------+ */ diff --git a/package.xml b/package.xml index 8cffa16..d65c3af 100644 --- a/package.xml +++ b/package.xml @@ -14,11 +14,12 @@ - 1.0 - 2005-12-29 + 1.1 + 2006-03-16 BSD, revised stable - bump to stable + improved PHP4 compatibility +passphrase-errors now takes care of the errormode @@ -43,6 +44,13 @@ + + 1.1 + 2006-03-16 + stable + improved PHP4 compatibility +passphrase-errors now takes care of the errormode + 1.0 2005-12-29 diff --git a/package2.xml b/package2.xml index 7a0243f..a53ae4f 100644 --- a/package2.xml +++ b/package2.xml @@ -15,18 +15,19 @@ http://pear.php.net/dtd/package-2.0.xsd"> traufeisen@php.net yes - 2005-12-29 - + 2006-03-16 + - 1.0 - 1.0 + 1.1 + 1.1 stable stable BSD, revised - bump to stable + improved PHP4 compatibility +passphrase-errors now takes care of the errormode @@ -64,6 +65,21 @@ http://pear.php.net/dtd/package-2.0.xsd"> gnupg + + + 1.1 + 1.1 + + + stable + stable + + 2006-03-16 + BSD, revised + improved PHP4 compatibility +passphrase-errors now takes care of the errormode + + 1.0 diff --git a/php_gnupg.h b/php_gnupg.h index a785b4c..07e4515 100644 --- a/php_gnupg.h +++ b/php_gnupg.h @@ -6,7 +6,7 @@ | modification, are permitted provided that the conditions mentioned | | in the accompanying LICENSE file are met. | +--------------------------------------------------------------------+ - | Copyright (c) 2005, Thilo Raufeisen | + | Copyright (c) 2006, Thilo Raufeisen | +--------------------------------------------------------------------+ */ diff --git a/php_gnupg_keylistiterator.h b/php_gnupg_keylistiterator.h index eda055c..43a77a2 100644 --- a/php_gnupg_keylistiterator.h +++ b/php_gnupg_keylistiterator.h @@ -6,7 +6,7 @@ | modification, are permitted provided that the conditions mentioned | | in the accompanying LICENSE file are met. | +--------------------------------------------------------------------+ - | Copyright (c) 2005, Thilo Raufeisen | + | Copyright (c) 2006, Thilo Raufeisen | +--------------------------------------------------------------------+ */